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/buffer.h"
27 #include "ns3/tcp-socket-factory.h"
28 #include "ns3/ipv4-address.h"
29 #include "ns3/ipv6-address.h"
30 #include "ns3/sequence-number.h"
31 
32 namespace ns3 {
33 
43 class TcpHeader : public Header
44 {
45 public:
46  TcpHeader ();
47  virtual ~TcpHeader ();
48 
54  void EnableChecksums (void);
55 //Setters
59  void SetSourcePort (uint16_t port);
63  void SetDestinationPort (uint16_t port);
67  void SetSequenceNumber (SequenceNumber32 sequenceNumber);
71  void SetAckNumber (SequenceNumber32 ackNumber);
75  void SetLength (uint8_t length);
79  void SetFlags (uint8_t flags);
83  void SetWindowSize (uint16_t windowSize);
87  void SetUrgentPointer (uint16_t urgentPointer);
88 
89 
90 //Getters
94  uint16_t GetSourcePort () const;
98  uint16_t GetDestinationPort () const;
110  uint8_t GetLength () const;
114  uint8_t GetFlags () const;
118  uint16_t GetWindowSize () const;
122  uint16_t GetUrgentPointer () const;
123 
138  void InitializeChecksum (Ipv4Address source,
139  Ipv4Address destination,
140  uint8_t protocol);
141 
156  void InitializeChecksum (Ipv6Address source,
157  Ipv6Address destination,
158  uint8_t protocol);
159 
174  void InitializeChecksum (Address source,
175  Address destination,
176  uint8_t protocol);
177 
181  typedef enum { NONE = 0, FIN = 1, SYN = 2, RST = 4, PSH = 8, ACK = 16,
182  URG = 32, ECE = 64, CWR = 128} Flags_t;
183 
188  static TypeId GetTypeId (void);
189  virtual TypeId GetInstanceTypeId (void) const;
190  virtual void Print (std::ostream &os) const;
191  virtual uint32_t GetSerializedSize (void) const;
192  virtual void Serialize (Buffer::Iterator start) const;
193  virtual uint32_t Deserialize (Buffer::Iterator start);
194 
199  bool IsChecksumOk (void) const;
200 
201 private:
207  uint16_t CalculateHeaderChecksum (uint16_t size) const;
208  uint16_t m_sourcePort;
209  uint16_t m_destinationPort;
212  uint8_t m_length;
213  uint8_t m_flags;
214  uint16_t m_windowSize;
215  uint16_t m_urgentPointer;
216 
219  uint8_t m_protocol;
220 
223 };
224 
225 } // namespace ns3
226 
227 #endif /* TCP_HEADER */
Protocol header serialization and deserialization.
Definition: header.h:42
uint16_t GetDestinationPort() const
Definition: tcp-header.cc:93
SequenceNumber32 GetSequenceNumber() const
Definition: tcp-header.cc:97
void InitializeChecksum(Ipv4Address source, Ipv4Address destination, uint8_t protocol)
Initialize the TCP checksum.
Definition: tcp-header.cc:123
uint8_t GetFlags() const
Definition: tcp-header.cc:109
SequenceNumber32 GetAckNumber() const
Definition: tcp-header.cc:101
Address m_source
Source IP address.
Definition: tcp-header.h:217
uint16_t m_destinationPort
Destination port.
Definition: tcp-header.h:209
bool m_calcChecksum
Flag to calculate checksum.
Definition: tcp-header.h:221
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:215
void SetSequenceNumber(SequenceNumber32 sequenceNumber)
Definition: tcp-header.cc:64
uint16_t GetWindowSize() const
Definition: tcp-header.cc:113
virtual TypeId GetInstanceTypeId(void) const
Definition: tcp-header.cc:211
uint16_t CalculateHeaderChecksum(uint16_t size) const
Calculate the header checksum.
Definition: tcp-header.cc:153
bool m_goodChecksum
Flag to indicate that checksum is correct.
Definition: tcp-header.h:222
void SetDestinationPort(uint16_t port)
Definition: tcp-header.cc:60
void SetFlags(uint8_t flags)
Definition: tcp-header.cc:76
uint16_t m_windowSize
Window size.
Definition: tcp-header.h:214
uint16_t m_sourcePort
Source port.
Definition: tcp-header.h:208
Header for the Transmission Control Protocol.
Definition: tcp-header.h:43
void SetSourcePort(uint16_t port)
Definition: tcp-header.cc:56
Flags_t
TCP flag field values.
Definition: tcp-header.h:181
virtual ~TcpHeader()
Definition: tcp-header.cc:46
Address m_destination
Destination IP address.
Definition: tcp-header.h:218
void SetUrgentPointer(uint16_t urgentPointer)
Definition: tcp-header.cc:84
virtual uint32_t GetSerializedSize(void) const
Definition: tcp-header.cc:257
uint8_t GetLength() const
Definition: tcp-header.cc:105
uint8_t m_protocol
Protocol number.
Definition: tcp-header.h:219
virtual uint32_t Deserialize(Buffer::Iterator start)
Definition: tcp-header.cc:284
uint16_t m_urgentPointer
Urgent pointer.
Definition: tcp-header.h:215
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:211
uint8_t m_flags
Flags (really a uint6_t)
Definition: tcp-header.h:213
uint8_t m_length
Length (really a uint4_t)
Definition: tcp-header.h:212
void SetAckNumber(SequenceNumber32 ackNumber)
Definition: tcp-header.cc:68
uint16_t GetSourcePort() const
Definition: tcp-header.cc:89
void SetLength(uint8_t length)
Definition: tcp-header.cc:72
bool IsChecksumOk(void) const
Is the TCP checksum correct ?
Definition: tcp-header.cc:196
void EnableChecksums(void)
Enable checksum calculation for TCP.
Definition: tcp-header.cc:51
void SetWindowSize(uint16_t windowSize)
Definition: tcp-header.cc:80
a unique identifier for an interface.
Definition: type-id.h:49
uint16_t GetUrgentPointer() const
Definition: tcp-header.cc:117
virtual void Serialize(Buffer::Iterator start) const
Definition: tcp-header.cc:261
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-header.cc:202
SequenceNumber32 m_sequenceNumber
Sequence number.
Definition: tcp-header.h:210