A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
tcp-header.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2007 Georgia Tech Research Corporation
3
*
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation;
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
*
17
* Author: Raj Bhattacharjea <raj.b@gatech.edu>
18
*/
19
20
#ifndef TCP_HEADER_H
21
#define TCP_HEADER_H
22
23
#include "
tcp-option.h
"
24
#include "
tcp-socket-factory.h
"
25
26
#include "ns3/buffer.h"
27
#include "ns3/header.h"
28
#include "ns3/ipv4-address.h"
29
#include "ns3/ipv6-address.h"
30
#include "ns3/sequence-number.h"
31
32
#include <stdint.h>
33
34
namespace
ns3
35
{
36
46
class
TcpHeader
:
public
Header
47
{
48
public
:
49
typedef
std::list<Ptr<const TcpOption>>
TcpOptionList
;
50
58
friend
std::ostream&
operator<<
(std::ostream& os,
const
TcpHeader
& tc);
59
75
static
std::string
FlagsToString
(uint8_t flags,
const
std::string& delimiter =
"|"
);
76
82
void
EnableChecksums
();
83
84
// Setters
85
90
void
SetSourcePort
(uint16_t
port
);
91
96
void
SetDestinationPort
(uint16_t
port
);
97
102
void
SetSequenceNumber
(
SequenceNumber32
sequenceNumber);
103
108
void
SetAckNumber
(
SequenceNumber32
ackNumber);
109
114
void
SetFlags
(uint8_t flags);
115
120
void
SetWindowSize
(uint16_t windowSize);
121
126
void
SetUrgentPointer
(uint16_t urgentPointer);
127
128
// Getters
129
134
uint16_t
GetSourcePort
()
const
;
135
140
uint16_t
GetDestinationPort
()
const
;
141
146
SequenceNumber32
GetSequenceNumber
()
const
;
147
152
SequenceNumber32
GetAckNumber
()
const
;
153
162
uint8_t
GetLength
()
const
;
163
168
uint8_t
GetFlags
()
const
;
169
174
uint16_t
GetWindowSize
()
const
;
175
180
uint16_t
GetUrgentPointer
()
const
;
181
187
Ptr<const TcpOption>
GetOption
(uint8_t kind)
const
;
188
193
const
TcpOptionList
&
GetOptionList
()
const
;
194
199
uint8_t
GetOptionLength
()
const
;
200
205
uint8_t
GetMaxOptionLength
()
const
;
206
212
bool
HasOption
(uint8_t kind)
const
;
213
219
bool
AppendOption
(
Ptr<const TcpOption>
option);
220
235
void
InitializeChecksum
(
const
Ipv4Address
& source,
236
const
Ipv4Address
& destination,
237
uint8_t protocol);
238
253
void
InitializeChecksum
(
const
Ipv6Address
& source,
254
const
Ipv6Address
& destination,
255
uint8_t protocol);
256
271
void
InitializeChecksum
(
const
Address
& source,
const
Address
& destination, uint8_t protocol);
272
276
enum
Flags_t
277
{
278
NONE
= 0,
279
FIN
= 1,
280
SYN
= 2,
281
RST
= 4,
282
PSH
= 8,
283
ACK
= 16,
284
URG
= 32,
285
ECE
= 64,
286
CWR
= 128
287
};
288
293
static
TypeId
GetTypeId
();
294
TypeId
GetInstanceTypeId
()
const override
;
295
void
Print
(std::ostream& os)
const override
;
296
uint32_t
GetSerializedSize
()
const override
;
297
void
Serialize
(
Buffer::Iterator
start
)
const override
;
298
uint32_t
Deserialize
(
Buffer::Iterator
start
)
override
;
299
304
bool
IsChecksumOk
()
const
;
305
312
friend
bool
operator==
(
const
TcpHeader
& lhs,
const
TcpHeader
& rhs);
313
314
private
:
320
uint16_t
CalculateHeaderChecksum
(uint16_t size)
const
;
321
330
uint8_t
CalculateHeaderLength
()
const
;
331
332
uint16_t
m_sourcePort
{0};
333
uint16_t
m_destinationPort
{0};
334
SequenceNumber32
m_sequenceNumber
{0};
335
SequenceNumber32
m_ackNumber
{0};
336
uint8_t
m_length
{5};
337
uint8_t
m_flags
{0};
338
uint16_t
m_windowSize
{0xffff};
339
uint16_t
m_urgentPointer
{0};
340
341
Address
m_source
;
342
Address
m_destination
;
343
uint8_t
m_protocol
{6};
344
345
bool
m_calcChecksum
{
false
};
346
bool
m_goodChecksum
{
true
};
347
348
static
const
uint8_t
m_maxOptionsLen
= 40;
349
TcpOptionList
m_options
;
350
uint8_t
m_optionsLen
{0};
351
};
352
353
}
// namespace ns3
354
355
#endif
/* TCP_HEADER */
ns3::Address
a polymophic address class
Definition:
address.h:101
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition:
buffer.h:100
ns3::Header
Protocol header serialization and deserialization.
Definition:
header.h:44
ns3::Header::Deserialize
virtual uint32_t Deserialize(Buffer::Iterator start)=0
Deserialize the object from a buffer iterator.
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition:
ipv4-address.h:42
ns3::Ipv6Address
Describes an IPv6 address.
Definition:
ipv6-address.h:49
ns3::Ptr< const TcpOption >
ns3::SequenceNumber< uint32_t, int32_t >
ns3::TcpHeader
Header for the Transmission Control Protocol.
Definition:
tcp-header.h:47
ns3::TcpHeader::m_urgentPointer
uint16_t m_urgentPointer
Urgent pointer.
Definition:
tcp-header.h:339
ns3::TcpHeader::SetUrgentPointer
void SetUrgentPointer(uint16_t urgentPointer)
Set the urgent pointer.
Definition:
tcp-header.cc:100
ns3::TcpHeader::m_source
Address m_source
Source IP address.
Definition:
tcp-header.h:341
ns3::TcpHeader::Print
void Print(std::ostream &os) const override
Definition:
tcp-header.cc:259
ns3::TcpHeader::SetDestinationPort
void SetDestinationPort(uint16_t port)
Set the destination port.
Definition:
tcp-header.cc:70
ns3::TcpHeader::SetSequenceNumber
void SetSequenceNumber(SequenceNumber32 sequenceNumber)
Set the sequence Number.
Definition:
tcp-header.cc:76
ns3::TcpHeader::m_optionsLen
uint8_t m_optionsLen
Tcp options length.
Definition:
tcp-header.h:350
ns3::TcpHeader::operator<<
friend std::ostream & operator<<(std::ostream &os, const TcpHeader &tc)
Print a TCP header into an output stream.
Definition:
tcp-header.cc:502
ns3::TcpHeader::GetSequenceNumber
SequenceNumber32 GetSequenceNumber() const
Get the sequence number.
Definition:
tcp-header.cc:118
ns3::TcpHeader::operator==
friend bool operator==(const TcpHeader &lhs, const TcpHeader &rhs)
Comparison operator.
Definition:
tcp-header.cc:492
ns3::TcpHeader::GetLength
uint8_t GetLength() const
Get the length in words.
Definition:
tcp-header.cc:130
ns3::TcpHeader::GetMaxOptionLength
uint8_t GetMaxOptionLength() const
Get maximum option length.
Definition:
tcp-header.cc:142
ns3::TcpHeader::m_sourcePort
uint16_t m_sourcePort
Source port.
Definition:
tcp-header.h:332
ns3::TcpHeader::GetDestinationPort
uint16_t GetDestinationPort() const
Get the destination port.
Definition:
tcp-header.cc:112
ns3::TcpHeader::TcpOptionList
std::list< Ptr< const TcpOption > > TcpOptionList
List of TcpOption.
Definition:
tcp-header.h:49
ns3::TcpHeader::CalculateHeaderLength
uint8_t CalculateHeaderLength() const
Calculates the header length (in words)
Definition:
tcp-header.cc:415
ns3::TcpHeader::m_length
uint8_t m_length
Length (really a uint4_t) in words.
Definition:
tcp-header.h:336
ns3::TcpHeader::m_maxOptionsLen
static const uint8_t m_maxOptionsLen
Maximum options length.
Definition:
tcp-header.h:348
ns3::TcpHeader::GetOption
Ptr< const TcpOption > GetOption(uint8_t kind) const
Get the option specified.
Definition:
tcp-header.cc:464
ns3::TcpHeader::Flags_t
Flags_t
TCP flag field values.
Definition:
tcp-header.h:277
ns3::TcpHeader::URG
@ URG
Urgent.
Definition:
tcp-header.h:284
ns3::TcpHeader::ACK
@ ACK
Ack.
Definition:
tcp-header.h:283
ns3::TcpHeader::PSH
@ PSH
Push.
Definition:
tcp-header.h:282
ns3::TcpHeader::CWR
@ CWR
CWR.
Definition:
tcp-header.h:286
ns3::TcpHeader::SYN
@ SYN
SYN.
Definition:
tcp-header.h:280
ns3::TcpHeader::ECE
@ ECE
ECE.
Definition:
tcp-header.h:285
ns3::TcpHeader::RST
@ RST
Reset.
Definition:
tcp-header.h:281
ns3::TcpHeader::NONE
@ NONE
No flags.
Definition:
tcp-header.h:278
ns3::TcpHeader::FIN
@ FIN
FIN.
Definition:
tcp-header.h:279
ns3::TcpHeader::SetFlags
void SetFlags(uint8_t flags)
Set flags of the header.
Definition:
tcp-header.cc:88
ns3::TcpHeader::SetWindowSize
void SetWindowSize(uint16_t windowSize)
Set the window size.
Definition:
tcp-header.cc:94
ns3::TcpHeader::GetSerializedSize
uint32_t GetSerializedSize() const override
Definition:
tcp-header.cc:279
ns3::TcpHeader::GetOptionList
const TcpOptionList & GetOptionList() const
Get the list of option in this header.
Definition:
tcp-header.cc:458
ns3::TcpHeader::m_calcChecksum
bool m_calcChecksum
Flag to calculate checksum.
Definition:
tcp-header.h:345
ns3::TcpHeader::GetWindowSize
uint16_t GetWindowSize() const
Get the window size.
Definition:
tcp-header.cc:154
ns3::TcpHeader::InitializeChecksum
void InitializeChecksum(const Ipv4Address &source, const Ipv4Address &destination, uint8_t protocol)
Initialize the TCP checksum.
Definition:
tcp-header.cc:166
ns3::TcpHeader::m_destination
Address m_destination
Destination IP address.
Definition:
tcp-header.h:342
ns3::TcpHeader::m_protocol
uint8_t m_protocol
Protocol number.
Definition:
tcp-header.h:343
ns3::TcpHeader::GetOptionLength
uint8_t GetOptionLength() const
Get the total length of appended options.
Definition:
tcp-header.cc:136
ns3::TcpHeader::m_sequenceNumber
SequenceNumber32 m_sequenceNumber
Sequence number.
Definition:
tcp-header.h:334
ns3::TcpHeader::CalculateHeaderChecksum
uint16_t CalculateHeaderChecksum(uint16_t size) const
Calculate the header checksum.
Definition:
tcp-header.cc:194
ns3::TcpHeader::AppendOption
bool AppendOption(Ptr< const TcpOption > option)
Append an option to the TCP header.
Definition:
tcp-header.cc:432
ns3::TcpHeader::FlagsToString
static std::string FlagsToString(uint8_t flags, const std::string &delimiter="|")
Converts an integer into a human readable list of Tcp flags.
Definition:
tcp-header.cc:39
ns3::TcpHeader::GetInstanceTypeId
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition:
tcp-header.cc:253
ns3::TcpHeader::m_windowSize
uint16_t m_windowSize
Window size.
Definition:
tcp-header.h:338
ns3::TcpHeader::HasOption
bool HasOption(uint8_t kind) const
Check if the header has the option specified.
Definition:
tcp-header.cc:478
ns3::TcpHeader::m_goodChecksum
bool m_goodChecksum
Flag to indicate that checksum is correct.
Definition:
tcp-header.h:346
ns3::TcpHeader::Serialize
void Serialize(Buffer::Iterator start) const override
Definition:
tcp-header.cc:285
ns3::TcpHeader::GetSourcePort
uint16_t GetSourcePort() const
Get the source port.
Definition:
tcp-header.cc:106
ns3::TcpHeader::SetSourcePort
void SetSourcePort(uint16_t port)
Set the source port.
Definition:
tcp-header.cc:64
ns3::TcpHeader::m_ackNumber
SequenceNumber32 m_ackNumber
ACK number.
Definition:
tcp-header.h:335
ns3::TcpHeader::EnableChecksums
void EnableChecksums()
Enable checksum calculation for TCP.
Definition:
tcp-header.cc:58
ns3::TcpHeader::SetAckNumber
void SetAckNumber(SequenceNumber32 ackNumber)
Set the ACK number.
Definition:
tcp-header.cc:82
ns3::TcpHeader::GetUrgentPointer
uint16_t GetUrgentPointer() const
Get the urgent pointer.
Definition:
tcp-header.cc:160
ns3::TcpHeader::GetFlags
uint8_t GetFlags() const
Get the flags.
Definition:
tcp-header.cc:148
ns3::TcpHeader::GetAckNumber
SequenceNumber32 GetAckNumber() const
Get the ACK number.
Definition:
tcp-header.cc:124
ns3::TcpHeader::m_flags
uint8_t m_flags
Flags (really a uint6_t)
Definition:
tcp-header.h:337
ns3::TcpHeader::IsChecksumOk
bool IsChecksumOk() const
Is the TCP checksum correct ?
Definition:
tcp-header.cc:237
ns3::TcpHeader::m_destinationPort
uint16_t m_destinationPort
Destination port.
Definition:
tcp-header.h:333
ns3::TcpHeader::m_options
TcpOptionList m_options
TcpOption present in the header.
Definition:
tcp-header.h:349
ns3::TcpHeader::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition:
tcp-header.cc:243
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:59
port
uint16_t port
Definition:
dsdv-manet.cc:44
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
two-ray-to-three-gpp-ch-calibration.start
start
Definition:
two-ray-to-three-gpp-ch-calibration.py:520
tcp-option.h
tcp-socket-factory.h
src
internet
model
tcp-header.h
Generated on Sun Mar 3 2024 17:10:59 for ns-3 by
1.9.1