A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
33 namespace ns3 {
34 
44 class TcpHeader : public Header
45 {
46 public:
47  TcpHeader ();
48  virtual ~TcpHeader ();
49 
55  void EnableChecksums (void);
56 
57 //Setters
58 
63  void SetSourcePort (uint16_t port);
64 
69  void SetDestinationPort (uint16_t port);
70 
75  void SetSequenceNumber (SequenceNumber32 sequenceNumber);
76 
81  void SetAckNumber (SequenceNumber32 ackNumber);
82 
87  void SetFlags (uint8_t flags);
88 
93  void SetWindowSize (uint16_t windowSize);
94 
99  void SetUrgentPointer (uint16_t urgentPointer);
100 
101 //Getters
102 
107  uint16_t GetSourcePort () const;
108 
113  uint16_t GetDestinationPort () const;
114 
120 
126 
135  uint8_t GetLength () const;
136 
141  uint8_t GetFlags () const;
142 
147  uint16_t GetWindowSize () const;
148 
153  uint16_t GetUrgentPointer () const;
154 
160  Ptr<TcpOption> GetOption (uint8_t kind) const;
161 
167  bool HasOption (uint8_t kind) const;
168 
173  bool AppendOption (Ptr<TcpOption> option);
174 
189  void InitializeChecksum (Ipv4Address source,
190  Ipv4Address destination,
191  uint8_t protocol);
192 
207  void InitializeChecksum (Ipv6Address source,
208  Ipv6Address destination,
209  uint8_t protocol);
210 
225  void InitializeChecksum (Address source,
226  Address destination,
227  uint8_t protocol);
228 
232  typedef enum
233  {
234  NONE = 0,
235  FIN = 1,
236  SYN = 2,
237  RST = 4,
238  PSH = 8,
239  ACK = 16,
240  URG = 32,
241  ECE = 64,
242  CWR = 128
243  } Flags_t;
244 
249  static TypeId GetTypeId (void);
250  virtual TypeId GetInstanceTypeId (void) const;
251  virtual void Print (std::ostream &os) const;
252  virtual uint32_t GetSerializedSize (void) const;
253  virtual void Serialize (Buffer::Iterator start) const;
254  virtual uint32_t Deserialize (Buffer::Iterator start);
255 
260  bool IsChecksumOk (void) const;
261 
262  friend bool operator== (const TcpHeader &lhs, const TcpHeader &rhs);
263 
264 private:
270  uint16_t CalculateHeaderChecksum (uint16_t size) const;
271 
280  uint8_t CalculateHeaderLength () const;
281 
282  uint16_t m_sourcePort;
283  uint16_t m_destinationPort;
286  uint8_t m_length;
287  uint8_t m_flags;
288  uint16_t m_windowSize;
289  uint16_t m_urgentPointer;
290 
293  uint8_t m_protocol;
294 
297 
298 
299  typedef std::list< Ptr<TcpOption> > TcpOptionList;
301  uint8_t m_optionsLen;
302  static const uint8_t m_maxOptionsLen = 40;
303 };
304 
305 } // namespace ns3
306 
307 #endif /* TCP_HEADER */
Protocol header serialization and deserialization.
Definition: header.h:42
uint16_t GetDestinationPort() const
Get the destination port.
Definition: tcp-header.cc:109
SequenceNumber32 GetSequenceNumber() const
Get the sequence number.
Definition: tcp-header.cc:115
void InitializeChecksum(Ipv4Address source, Ipv4Address destination, uint8_t protocol)
Initialize the TCP checksum.
Definition: tcp-header.cc:151
uint8_t GetFlags() const
Get the flags.
Definition: tcp-header.cc:133
SequenceNumber32 GetAckNumber() const
Get the ACK number.
Definition: tcp-header.cc:121
static const uint8_t m_maxOptionsLen
Maximum options length.
Definition: tcp-header.h:302
Address m_source
Source IP address.
Definition: tcp-header.h:291
uint16_t m_destinationPort
Destination port.
Definition: tcp-header.h:283
uint8_t CalculateHeaderLength() const
Calculates the header length (in words)
Definition: tcp-header.cc:435
bool m_calcChecksum
Flag to calculate checksum.
Definition: tcp-header.h:295
uint16_t port
Definition: dsdv-manet.cc:44
iterator in a Buffer instance
Definition: buffer.h:98
a polymophic address class
Definition: address.h:86
virtual void Print(std::ostream &os) const
Definition: tcp-header.cc:246
bool AppendOption(Ptr< TcpOption > option)
Append an option to the TCP header.
Definition: tcp-header.cc:453
void SetSequenceNumber(SequenceNumber32 sequenceNumber)
Set the sequence Number.
Definition: tcp-header.cc:73
uint16_t GetWindowSize() const
Get the window size.
Definition: tcp-header.cc:139
std::list< Ptr< TcpOption > > TcpOptionList
List of TcpOption.
Definition: tcp-header.h:299
virtual TypeId GetInstanceTypeId(void) const
Definition: tcp-header.cc:240
uint16_t CalculateHeaderChecksum(uint16_t size) const
Calculate the header checksum.
Definition: tcp-header.cc:181
bool m_goodChecksum
Flag to indicate that checksum is correct.
Definition: tcp-header.h:296
void SetDestinationPort(uint16_t port)
Set the destination port.
Definition: tcp-header.cc:67
void SetFlags(uint8_t flags)
Set flags of the header.
Definition: tcp-header.cc:85
uint16_t m_windowSize
Window size.
Definition: tcp-header.h:288
uint16_t m_sourcePort
Source port.
Definition: tcp-header.h:282
uint8_t m_optionsLen
Tcp options length.
Definition: tcp-header.h:301
Header for the Transmission Control Protocol.
Definition: tcp-header.h:44
void SetSourcePort(uint16_t port)
Set the source port.
Definition: tcp-header.cc:61
Flags_t
TCP flag field values.
Definition: tcp-header.h:232
virtual ~TcpHeader()
Definition: tcp-header.cc:50
Address m_destination
Destination IP address.
Definition: tcp-header.h:292
void SetUrgentPointer(uint16_t urgentPointer)
Set the urgent pointer.
Definition: tcp-header.cc:97
virtual uint32_t GetSerializedSize(void) const
Definition: tcp-header.cc:302
uint8_t GetLength() const
Get the length in words.
Definition: tcp-header.cc:127
uint8_t m_protocol
Protocol number.
Definition: tcp-header.h:293
Ptr< TcpOption > GetOption(uint8_t kind) const
Get the option specified.
Definition: tcp-header.cc:479
virtual uint32_t Deserialize(Buffer::Iterator start)
Definition: tcp-header.cc:353
uint16_t m_urgentPointer
Urgent pointer.
Definition: tcp-header.h:289
Describes an IPv6 address.
Definition: ipv6-address.h:46
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
SequenceNumber32 m_ackNumber
ACK number.
Definition: tcp-header.h:285
uint8_t m_flags
Flags (really a uint6_t)
Definition: tcp-header.h:287
uint8_t m_length
Length (really a uint4_t) in words.
Definition: tcp-header.h:286
friend bool operator==(const TcpHeader &lhs, const TcpHeader &rhs)
Definition: tcp-header.cc:511
void SetAckNumber(SequenceNumber32 ackNumber)
Set the ACK number.
Definition: tcp-header.cc:79
uint16_t GetSourcePort() const
Get the source port.
Definition: tcp-header.cc:103
bool IsChecksumOk(void) const
Is the TCP checksum correct ?
Definition: tcp-header.cc:224
void EnableChecksums(void)
Enable checksum calculation for TCP.
Definition: tcp-header.cc:55
TcpOptionList m_options
TcpOption present in the header.
Definition: tcp-header.h:300
bool HasOption(uint8_t kind) const
Check if the header has the option specified.
Definition: tcp-header.cc:495
void SetWindowSize(uint16_t windowSize)
Set the window size.
Definition: tcp-header.cc:91
a unique identifier for an interface.
Definition: type-id.h:49
uint16_t GetUrgentPointer() const
Get the urgent pointer.
Definition: tcp-header.cc:145
virtual void Serialize(Buffer::Iterator start) const
Definition: tcp-header.cc:308
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-header.cc:230
SequenceNumber32 m_sequenceNumber
Sequence number.
Definition: tcp-header.h:284