A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
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 "ns3/buffer.h"
24
#include "ns3/header.h"
25
#include "ns3/ipv4-address.h"
26
#include "ns3/ipv6-address.h"
27
#include "ns3/sequence-number.h"
28
#include "ns3/tcp-option.h"
29
#include "ns3/tcp-socket-factory.h"
30
31
#include <stdint.h>
32
33
namespace
ns3
34
{
35
45
class
TcpHeader
:
public
Header
46
{
47
public
:
48
TcpHeader
();
49
~TcpHeader
()
override
;
50
51
typedef
std::list<Ptr<const TcpOption>>
TcpOptionList
;
52
60
friend
std::ostream&
operator<<
(std::ostream& os,
const
TcpHeader
& tc);
61
77
static
std::string
FlagsToString
(uint8_t flags,
const
std::string& delimiter =
"|"
);
78
84
void
EnableChecksums
();
85
86
// Setters
87
92
void
SetSourcePort
(uint16_t
port
);
93
98
void
SetDestinationPort
(uint16_t
port
);
99
104
void
SetSequenceNumber
(
SequenceNumber32
sequenceNumber);
105
110
void
SetAckNumber
(
SequenceNumber32
ackNumber);
111
116
void
SetFlags
(uint8_t flags);
117
122
void
SetWindowSize
(uint16_t windowSize);
123
128
void
SetUrgentPointer
(uint16_t urgentPointer);
129
130
// Getters
131
136
uint16_t
GetSourcePort
()
const
;
137
142
uint16_t
GetDestinationPort
()
const
;
143
148
SequenceNumber32
GetSequenceNumber
()
const
;
149
154
SequenceNumber32
GetAckNumber
()
const
;
155
164
uint8_t
GetLength
()
const
;
165
170
uint8_t
GetFlags
()
const
;
171
176
uint16_t
GetWindowSize
()
const
;
177
182
uint16_t
GetUrgentPointer
()
const
;
183
189
Ptr<const TcpOption>
GetOption
(uint8_t kind)
const
;
190
195
const
TcpOptionList
&
GetOptionList
()
const
;
196
201
uint8_t
GetOptionLength
()
const
;
202
207
uint8_t
GetMaxOptionLength
()
const
;
208
214
bool
HasOption
(uint8_t kind)
const
;
215
221
bool
AppendOption
(
Ptr<const TcpOption>
option);
222
237
void
InitializeChecksum
(
const
Ipv4Address
& source,
238
const
Ipv4Address
& destination,
239
uint8_t protocol);
240
255
void
InitializeChecksum
(
const
Ipv6Address
& source,
256
const
Ipv6Address
& destination,
257
uint8_t protocol);
258
273
void
InitializeChecksum
(
const
Address
& source,
const
Address
& destination, uint8_t protocol);
274
278
enum
Flags_t
279
{
280
NONE
= 0,
281
FIN
= 1,
282
SYN
= 2,
283
RST
= 4,
284
PSH
= 8,
285
ACK
= 16,
286
URG
= 32,
287
ECE
= 64,
288
CWR
= 128
289
};
290
295
static
TypeId
GetTypeId
();
296
TypeId
GetInstanceTypeId
()
const override
;
297
void
Print
(std::ostream& os)
const override
;
298
uint32_t
GetSerializedSize
()
const override
;
299
void
Serialize
(
Buffer::Iterator
start)
const override
;
300
uint32_t
Deserialize
(
Buffer::Iterator
start)
override
;
301
306
bool
IsChecksumOk
()
const
;
307
314
friend
bool
operator==
(
const
TcpHeader
& lhs,
const
TcpHeader
& rhs);
315
316
private
:
322
uint16_t
CalculateHeaderChecksum
(uint16_t size)
const
;
323
332
uint8_t
CalculateHeaderLength
()
const
;
333
334
uint16_t
m_sourcePort
;
335
uint16_t
m_destinationPort
;
336
SequenceNumber32
m_sequenceNumber
;
337
SequenceNumber32
m_ackNumber
;
338
uint8_t
m_length
;
339
uint8_t
m_flags
;
340
uint16_t
m_windowSize
;
341
uint16_t
m_urgentPointer
;
342
343
Address
m_source
;
344
Address
m_destination
;
345
uint8_t
m_protocol
;
346
347
bool
m_calcChecksum
;
348
bool
m_goodChecksum
;
349
350
static
const
uint8_t
m_maxOptionsLen
= 40;
351
TcpOptionList
m_options
;
352
uint8_t
m_optionsLen
;
353
};
354
355
}
// namespace ns3
356
357
#endif
/* TCP_HEADER */
ns3::Address
a polymophic address class
Definition:
address.h:100
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition:
buffer.h:100
ns3::Header
Protocol header serialization and deserialization.
Definition:
header.h:44
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
Smart pointer class similar to boost::intrusive_ptr.
Definition:
ptr.h:78
ns3::SequenceNumber< uint32_t, int32_t >
ns3::TcpHeader
Header for the Transmission Control Protocol.
Definition:
tcp-header.h:46
ns3::TcpHeader::m_urgentPointer
uint16_t m_urgentPointer
Urgent pointer.
Definition:
tcp-header.h:341
ns3::TcpHeader::SetUrgentPointer
void SetUrgentPointer(uint16_t urgentPointer)
Set the urgent pointer.
Definition:
tcp-header.cc:119
ns3::TcpHeader::m_source
Address m_source
Source IP address.
Definition:
tcp-header.h:343
ns3::TcpHeader::Print
void Print(std::ostream &os) const override
Definition:
tcp-header.cc:278
ns3::TcpHeader::SetDestinationPort
void SetDestinationPort(uint16_t port)
Set the destination port.
Definition:
tcp-header.cc:89
ns3::TcpHeader::SetSequenceNumber
void SetSequenceNumber(SequenceNumber32 sequenceNumber)
Set the sequence Number.
Definition:
tcp-header.cc:95
ns3::TcpHeader::m_optionsLen
uint8_t m_optionsLen
Tcp options length.
Definition:
tcp-header.h:352
ns3::TcpHeader::GetSequenceNumber
SequenceNumber32 GetSequenceNumber() const
Get the sequence number.
Definition:
tcp-header.cc:137
ns3::TcpHeader::operator==
friend bool operator==(const TcpHeader &lhs, const TcpHeader &rhs)
Comparison operator.
Definition:
tcp-header.cc:518
ns3::TcpHeader::GetLength
uint8_t GetLength() const
Get the length in words.
Definition:
tcp-header.cc:149
ns3::TcpHeader::GetMaxOptionLength
uint8_t GetMaxOptionLength() const
Get maximum option length.
Definition:
tcp-header.cc:161
ns3::TcpHeader::m_sourcePort
uint16_t m_sourcePort
Source port.
Definition:
tcp-header.h:334
ns3::TcpHeader::GetDestinationPort
uint16_t GetDestinationPort() const
Get the destination port.
Definition:
tcp-header.cc:131
ns3::TcpHeader::TcpOptionList
std::list< Ptr< const TcpOption > > TcpOptionList
List of TcpOption.
Definition:
tcp-header.h:51
ns3::TcpHeader::CalculateHeaderLength
uint8_t CalculateHeaderLength() const
Calculates the header length (in words)
Definition:
tcp-header.cc:436
ns3::TcpHeader::m_length
uint8_t m_length
Length (really a uint4_t) in words.
Definition:
tcp-header.h:338
ns3::TcpHeader::m_maxOptionsLen
static const uint8_t m_maxOptionsLen
Maximum options length.
Definition:
tcp-header.h:350
ns3::TcpHeader::Deserialize
uint32_t Deserialize(Buffer::Iterator start) override
Definition:
tcp-header.cc:351
ns3::TcpHeader::GetOption
Ptr< const TcpOption > GetOption(uint8_t kind) const
Get the option specified.
Definition:
tcp-header.cc:486
ns3::TcpHeader::Flags_t
Flags_t
TCP flag field values.
Definition:
tcp-header.h:279
ns3::TcpHeader::URG
@ URG
Urgent.
Definition:
tcp-header.h:286
ns3::TcpHeader::ACK
@ ACK
Ack.
Definition:
tcp-header.h:285
ns3::TcpHeader::PSH
@ PSH
Push.
Definition:
tcp-header.h:284
ns3::TcpHeader::CWR
@ CWR
CWR.
Definition:
tcp-header.h:288
ns3::TcpHeader::SYN
@ SYN
SYN.
Definition:
tcp-header.h:282
ns3::TcpHeader::ECE
@ ECE
ECE.
Definition:
tcp-header.h:287
ns3::TcpHeader::RST
@ RST
Reset.
Definition:
tcp-header.h:283
ns3::TcpHeader::NONE
@ NONE
No flags.
Definition:
tcp-header.h:280
ns3::TcpHeader::FIN
@ FIN
FIN.
Definition:
tcp-header.h:281
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:528
ns3::TcpHeader::SetFlags
void SetFlags(uint8_t flags)
Set flags of the header.
Definition:
tcp-header.cc:107
ns3::TcpHeader::SetWindowSize
void SetWindowSize(uint16_t windowSize)
Set the window size.
Definition:
tcp-header.cc:113
ns3::TcpHeader::GetSerializedSize
uint32_t GetSerializedSize() const override
Definition:
tcp-header.cc:300
ns3::TcpHeader::GetOptionList
const TcpOptionList & GetOptionList() const
Get the list of option in this header.
Definition:
tcp-header.cc:480
ns3::TcpHeader::m_calcChecksum
bool m_calcChecksum
Flag to calculate checksum.
Definition:
tcp-header.h:347
ns3::TcpHeader::GetWindowSize
uint16_t GetWindowSize() const
Get the window size.
Definition:
tcp-header.cc:173
ns3::TcpHeader::InitializeChecksum
void InitializeChecksum(const Ipv4Address &source, const Ipv4Address &destination, uint8_t protocol)
Initialize the TCP checksum.
Definition:
tcp-header.cc:185
ns3::TcpHeader::TcpHeader
TcpHeader()
Definition:
tcp-header.cc:38
ns3::TcpHeader::m_destination
Address m_destination
Destination IP address.
Definition:
tcp-header.h:344
ns3::TcpHeader::~TcpHeader
~TcpHeader() override
Definition:
tcp-header.cc:53
ns3::TcpHeader::m_protocol
uint8_t m_protocol
Protocol number.
Definition:
tcp-header.h:345
ns3::TcpHeader::GetOptionLength
uint8_t GetOptionLength() const
Get the total length of appended options.
Definition:
tcp-header.cc:155
ns3::TcpHeader::m_sequenceNumber
SequenceNumber32 m_sequenceNumber
Sequence number.
Definition:
tcp-header.h:336
ns3::TcpHeader::CalculateHeaderChecksum
uint16_t CalculateHeaderChecksum(uint16_t size) const
Calculate the header checksum.
Definition:
tcp-header.cc:213
ns3::TcpHeader::AppendOption
bool AppendOption(Ptr< const TcpOption > option)
Append an option to the TCP header.
Definition:
tcp-header.cc:454
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:58
ns3::TcpHeader::GetInstanceTypeId
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition:
tcp-header.cc:272
ns3::TcpHeader::m_windowSize
uint16_t m_windowSize
Window size.
Definition:
tcp-header.h:340
ns3::TcpHeader::HasOption
bool HasOption(uint8_t kind) const
Check if the header has the option specified.
Definition:
tcp-header.cc:502
ns3::TcpHeader::m_goodChecksum
bool m_goodChecksum
Flag to indicate that checksum is correct.
Definition:
tcp-header.h:348
ns3::TcpHeader::Serialize
void Serialize(Buffer::Iterator start) const override
Definition:
tcp-header.cc:306
ns3::TcpHeader::GetSourcePort
uint16_t GetSourcePort() const
Get the source port.
Definition:
tcp-header.cc:125
ns3::TcpHeader::SetSourcePort
void SetSourcePort(uint16_t port)
Set the source port.
Definition:
tcp-header.cc:83
ns3::TcpHeader::m_ackNumber
SequenceNumber32 m_ackNumber
ACK number.
Definition:
tcp-header.h:337
ns3::TcpHeader::EnableChecksums
void EnableChecksums()
Enable checksum calculation for TCP.
Definition:
tcp-header.cc:77
ns3::TcpHeader::SetAckNumber
void SetAckNumber(SequenceNumber32 ackNumber)
Set the ACK number.
Definition:
tcp-header.cc:101
ns3::TcpHeader::GetUrgentPointer
uint16_t GetUrgentPointer() const
Get the urgent pointer.
Definition:
tcp-header.cc:179
ns3::TcpHeader::GetFlags
uint8_t GetFlags() const
Get the flags.
Definition:
tcp-header.cc:167
ns3::TcpHeader::GetAckNumber
SequenceNumber32 GetAckNumber() const
Get the ACK number.
Definition:
tcp-header.cc:143
ns3::TcpHeader::m_flags
uint8_t m_flags
Flags (really a uint6_t)
Definition:
tcp-header.h:339
ns3::TcpHeader::IsChecksumOk
bool IsChecksumOk() const
Is the TCP checksum correct ?
Definition:
tcp-header.cc:256
ns3::TcpHeader::m_destinationPort
uint16_t m_destinationPort
Destination port.
Definition:
tcp-header.h:335
ns3::TcpHeader::m_options
TcpOptionList m_options
TcpOption present in the header.
Definition:
tcp-header.h:351
ns3::TcpHeader::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition:
tcp-header.cc:262
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:59
uint32_t
port
uint16_t port
Definition:
dsdv-manet.cc:44
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
internet
model
tcp-header.h
Generated on Sun Jul 2 2023 18:21:41 for ns-3 by
1.9.6