A Discrete-Event Network Simulator
API
tcp-header.h
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2007 Georgia Tech Research Corporation
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Raj Bhattacharjea <raj.b@gatech.edu>
19 */
20
21#ifndef TCP_HEADER_H
22#define TCP_HEADER_H
23
24#include <stdint.h>
25#include "ns3/header.h"
26#include "ns3/tcp-option.h"
27#include "ns3/buffer.h"
28#include "ns3/tcp-socket-factory.h"
29#include "ns3/ipv4-address.h"
30#include "ns3/ipv6-address.h"
31#include "ns3/sequence-number.h"
32
33namespace ns3 {
34
44class TcpHeader : public Header
45{
46public:
47 TcpHeader ();
48 virtual ~TcpHeader ();
49
50 typedef std::list< Ptr<const TcpOption> > TcpOptionList;
51
59 friend std::ostream& operator<< (std::ostream& os, TcpHeader const & tc);
60
76 static std::string FlagsToString (uint8_t flags, const std::string& delimiter = "|");
77
83 void EnableChecksums (void);
84
85//Setters
86
91 void SetSourcePort (uint16_t port);
92
97 void SetDestinationPort (uint16_t port);
98
103 void SetSequenceNumber (SequenceNumber32 sequenceNumber);
104
109 void SetAckNumber (SequenceNumber32 ackNumber);
110
115 void SetFlags (uint8_t flags);
116
121 void SetWindowSize (uint16_t windowSize);
122
127 void SetUrgentPointer (uint16_t urgentPointer);
128
129//Getters
130
135 uint16_t GetSourcePort () const;
136
141 uint16_t GetDestinationPort () const;
142
148
154
163 uint8_t GetLength () const;
164
169 uint8_t GetFlags () const;
170
175 uint16_t GetWindowSize () const;
176
181 uint16_t GetUrgentPointer () const;
182
188 Ptr<const TcpOption> GetOption (uint8_t kind) const;
189
194 const TcpOptionList& GetOptionList (void) const;
195
200 uint8_t GetOptionLength () const;
201
206 uint8_t GetMaxOptionLength () const;
207
213 bool HasOption (uint8_t kind) const;
214
221
236 void InitializeChecksum (const Ipv4Address &source,
237 const Ipv4Address &destination,
238 uint8_t protocol);
239
254 void InitializeChecksum (const Ipv6Address &source,
255 const Ipv6Address &destination,
256 uint8_t protocol);
257
272 void InitializeChecksum (const Address &source,
273 const Address &destination,
274 uint8_t protocol);
275
279 typedef enum
280 {
281 NONE = 0,
282 FIN = 1,
283 SYN = 2,
284 RST = 4,
285 PSH = 8,
286 ACK = 16,
287 URG = 32,
288 ECE = 64,
289 CWR = 128
291
296 static TypeId GetTypeId (void);
297 virtual TypeId GetInstanceTypeId (void) const;
298 virtual void Print (std::ostream &os) const;
299 virtual uint32_t GetSerializedSize (void) const;
300 virtual void Serialize (Buffer::Iterator start) const;
302
307 bool IsChecksumOk (void) const;
308
315 friend bool operator== (const TcpHeader &lhs, const TcpHeader &rhs);
316
317private:
323 uint16_t CalculateHeaderChecksum (uint16_t size) const;
324
333 uint8_t CalculateHeaderLength () const;
334
335 uint16_t m_sourcePort;
339 uint8_t m_length;
340 uint8_t m_flags;
341 uint16_t m_windowSize;
343
346 uint8_t m_protocol;
347
350
351 static const uint8_t m_maxOptionsLen = 40;
353 uint8_t m_optionsLen;
354};
355
356} // namespace ns3
357
358#endif /* TCP_HEADER */
a polymophic address class
Definition: address.h:91
iterator in a Buffer instance
Definition: buffer.h:99
Protocol header serialization and deserialization.
Definition: header.h:43
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
Describes an IPv6 address.
Definition: ipv6-address.h:50
Header for the Transmission Control Protocol.
Definition: tcp-header.h:45
uint16_t m_urgentPointer
Urgent pointer.
Definition: tcp-header.h:342
void SetUrgentPointer(uint16_t urgentPointer)
Set the urgent pointer.
Definition: tcp-header.cc:125
Address m_source
Source IP address.
Definition: tcp-header.h:344
virtual void Serialize(Buffer::Iterator start) const
Definition: tcp-header.cc:315
void SetDestinationPort(uint16_t port)
Set the destination port.
Definition: tcp-header.cc:95
void SetSequenceNumber(SequenceNumber32 sequenceNumber)
Set the sequence Number.
Definition: tcp-header.cc:101
virtual uint32_t GetSerializedSize(void) const
Definition: tcp-header.cc:309
uint8_t m_optionsLen
Tcp options length.
Definition: tcp-header.h:353
SequenceNumber32 GetSequenceNumber() const
Get the sequence number.
Definition: tcp-header.cc:143
friend bool operator==(const TcpHeader &lhs, const TcpHeader &rhs)
Comparison operator.
Definition: tcp-header.cc:527
uint8_t GetLength() const
Get the length in words.
Definition: tcp-header.cc:155
uint8_t GetMaxOptionLength() const
Get maximum option length.
Definition: tcp-header.cc:167
uint16_t m_sourcePort
Source port.
Definition: tcp-header.h:335
uint16_t GetDestinationPort() const
Get the destination port.
Definition: tcp-header.cc:137
uint8_t CalculateHeaderLength() const
Calculates the header length (in words)
Definition: tcp-header.cc:445
uint8_t m_length
Length (really a uint4_t) in words.
Definition: tcp-header.h:339
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-header.cc:270
friend std::ostream & operator<<(std::ostream &os, TcpHeader const &tc)
Print a TCP header into an output stream.
Definition: tcp-header.cc:541
virtual void Print(std::ostream &os) const
Definition: tcp-header.cc:287
static const uint8_t m_maxOptionsLen
Maximum options length.
Definition: tcp-header.h:351
Ptr< const TcpOption > GetOption(uint8_t kind) const
Get the option specified.
Definition: tcp-header.cc:495
Flags_t
TCP flag field values.
Definition: tcp-header.h:280
@ URG
Urgent.
Definition: tcp-header.h:287
@ NONE
No flags.
Definition: tcp-header.h:281
void SetFlags(uint8_t flags)
Set flags of the header.
Definition: tcp-header.cc:113
void SetWindowSize(uint16_t windowSize)
Set the window size.
Definition: tcp-header.cc:119
bool m_calcChecksum
Flag to calculate checksum.
Definition: tcp-header.h:348
uint16_t GetWindowSize() const
Get the window size.
Definition: tcp-header.cc:179
void InitializeChecksum(const Ipv4Address &source, const Ipv4Address &destination, uint8_t protocol)
Initialize the TCP checksum.
Definition: tcp-header.cc:191
Address m_destination
Destination IP address.
Definition: tcp-header.h:345
uint8_t m_protocol
Protocol number.
Definition: tcp-header.h:346
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition: tcp-header.cc:281
uint8_t GetOptionLength() const
Get the total length of appended options.
Definition: tcp-header.cc:161
SequenceNumber32 m_sequenceNumber
Sequence number.
Definition: tcp-header.h:337
uint16_t CalculateHeaderChecksum(uint16_t size) const
Calculate the header checksum.
Definition: tcp-header.cc:221
bool AppendOption(Ptr< const TcpOption > option)
Append an option to the TCP header.
Definition: tcp-header.cc:463
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:55
bool IsChecksumOk(void) const
Is the TCP checksum correct ?
Definition: tcp-header.cc:264
const TcpOptionList & GetOptionList(void) const
Get the list of option in this header.
Definition: tcp-header.cc:489
uint16_t m_windowSize
Window size.
Definition: tcp-header.h:341
bool HasOption(uint8_t kind) const
Check if the header has the option specified.
Definition: tcp-header.cc:511
bool m_goodChecksum
Flag to indicate that checksum is correct.
Definition: tcp-header.h:349
std::list< Ptr< const TcpOption > > TcpOptionList
List of TcpOption.
Definition: tcp-header.h:50
virtual uint32_t Deserialize(Buffer::Iterator start)
Definition: tcp-header.cc:360
uint16_t GetSourcePort() const
Get the source port.
Definition: tcp-header.cc:131
void SetSourcePort(uint16_t port)
Set the source port.
Definition: tcp-header.cc:89
SequenceNumber32 m_ackNumber
ACK number.
Definition: tcp-header.h:338
void SetAckNumber(SequenceNumber32 ackNumber)
Set the ACK number.
Definition: tcp-header.cc:107
uint16_t GetUrgentPointer() const
Get the urgent pointer.
Definition: tcp-header.cc:185
uint8_t GetFlags() const
Get the flags.
Definition: tcp-header.cc:173
SequenceNumber32 GetAckNumber() const
Get the ACK number.
Definition: tcp-header.cc:149
void EnableChecksums(void)
Enable checksum calculation for TCP.
Definition: tcp-header.cc:83
uint8_t m_flags
Flags (really a uint6_t)
Definition: tcp-header.h:340
uint16_t m_destinationPort
Destination port.
Definition: tcp-header.h:336
TcpOptionList m_options
TcpOption present in the header.
Definition: tcp-header.h:352
virtual ~TcpHeader()
Definition: tcp-header.cc:50
a unique identifier for an interface.
Definition: type-id.h:59
uint16_t port
Definition: dsdv-manet.cc:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.
def start()
Definition: core.py:1852