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 
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;
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 
172  uint8_t m_protocol;
173 
177 };
178 
179 } // namespace ns3
180 
181 #endif /* TCP_HEADER */