A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
tcp-header.h
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 
52  void EnableChecksums (void);
53 //Setters
57  void SetSourcePort (uint16_t port);
61  void SetDestinationPort (uint16_t port);
65  void SetSequenceNumber (SequenceNumber32 sequenceNumber);
69  void SetAckNumber (SequenceNumber32 ackNumber);
73  void SetLength (uint8_t length);
77  void SetFlags (uint8_t flags);
81  void SetWindowSize (uint16_t windowSize);
85  void SetUrgentPointer (uint16_t urgentPointer);
86 
87 
88 //Getters
92  uint16_t GetSourcePort () const;
96  uint16_t GetDestinationPort () const;
108  uint8_t GetLength () const;
112  uint8_t GetFlags () const;
116  uint16_t GetWindowSize () const;
120  uint16_t GetUrgentPointer () const;
121 
133  void InitializeChecksum (Ipv4Address source,
134  Ipv4Address destination,
135  uint8_t protocol);
136  void InitializeChecksum (Ipv6Address source,
137  Ipv6Address destination,
138  uint8_t protocol);
139  void InitializeChecksum (Address source,
140  Address destination,
141  uint8_t protocol);
142 
143  typedef enum { NONE = 0, FIN = 1, SYN = 2, RST = 4, PSH = 8, ACK = 16,
144  URG = 32, ECE = 64, CWR = 128} Flags_t;
145 
146  static TypeId GetTypeId (void);
147  virtual TypeId GetInstanceTypeId (void) const;
148  virtual void Print (std::ostream &os) const;
149  virtual uint32_t GetSerializedSize (void) const;
150  virtual void Serialize (Buffer::Iterator start) const;
151  virtual uint32_t Deserialize (Buffer::Iterator start);
152 
157  bool IsChecksumOk (void) const;
158 
159 private:
160  uint16_t CalculateHeaderChecksum (uint16_t size) const;
161  uint16_t m_sourcePort;
162  uint16_t m_destinationPort;
163  SequenceNumber32 m_sequenceNumber;
164  SequenceNumber32 m_ackNumber;
165  uint8_t m_length; // really a uint4_t
166  uint8_t m_flags; // really a uint6_t
167  uint16_t m_windowSize;
168  uint16_t m_urgentPointer;
169 
170  Address m_source;
171  Address m_destination;
172  uint8_t m_protocol;
173 
174  uint16_t m_initialChecksum;
175  bool m_calcChecksum;
176  bool m_goodChecksum;
177 };
178 
179 } // namespace ns3
180 
181 #endif /* TCP_HEADER */
Protocol header serialization and deserialization.
Definition: header.h:42
uint16_t GetDestinationPort() const
Definition: tcp-header.cc:92
SequenceNumber32 GetSequenceNumber() const
Definition: tcp-header.cc:96
void InitializeChecksum(Ipv4Address source, Ipv4Address destination, uint8_t protocol)
Definition: tcp-header.cc:122
uint8_t GetFlags() const
Definition: tcp-header.cc:108
SequenceNumber32 GetAckNumber() const
Definition: tcp-header.cc:100
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:214
void SetSequenceNumber(SequenceNumber32 sequenceNumber)
Definition: tcp-header.cc:63
uint16_t GetWindowSize() const
Definition: tcp-header.cc:112
virtual TypeId GetInstanceTypeId(void) const
Definition: tcp-header.cc:210
void SetDestinationPort(uint16_t port)
Definition: tcp-header.cc:59
void SetFlags(uint8_t flags)
Definition: tcp-header.cc:75
Header for the Transmission Control Protocol.
Definition: tcp-header.h:43
void SetSourcePort(uint16_t port)
Definition: tcp-header.cc:55
void SetUrgentPointer(uint16_t urgentPointer)
Definition: tcp-header.cc:83
virtual uint32_t GetSerializedSize(void) const
Definition: tcp-header.cc:256
uint8_t GetLength() const
Definition: tcp-header.cc:104
virtual uint32_t Deserialize(Buffer::Iterator start)
Definition: tcp-header.cc:283
Describes an IPv6 address.
Definition: ipv6-address.h:44
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
void SetAckNumber(SequenceNumber32 ackNumber)
Definition: tcp-header.cc:67
uint16_t GetSourcePort() const
Definition: tcp-header.cc:88
void SetLength(uint8_t length)
Definition: tcp-header.cc:71
bool IsChecksumOk(void) const
Is the TCP checksum correct ?
Definition: tcp-header.cc:195
void EnableChecksums(void)
Enable checksum calculation for TCP (XXX currently has no effect)
Definition: tcp-header.cc:50
void SetWindowSize(uint16_t windowSize)
Definition: tcp-header.cc:79
a unique identifier for an interface.
Definition: type-id.h:44
uint16_t GetUrgentPointer() const
Definition: tcp-header.cc:116
virtual void Serialize(Buffer::Iterator start) const
Definition: tcp-header.cc:260