src/internet-stack/tcp-header.h
changeset 3260 8c0ab08144e6
parent 3132 b0b0abb911cd
child 3266 1ae7df5cf87b
equal deleted inserted replaced
3259:43b3f8ecd86d 3260:8c0ab08144e6
       
     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/sequence-number.h"
       
    30 
       
    31 namespace ns3 {
       
    32 
       
    33 class TcpHeader : public Header 
       
    34 {
       
    35 public:
       
    36   TcpHeader ();
       
    37   virtual ~TcpHeader ();
       
    38 
       
    39   /**
       
    40    * \brief Enable checksum calculation for TCP (XXX currently has no effect)
       
    41    */
       
    42   static void EnableChecksums (void);
       
    43 //Setters
       
    44   /**
       
    45    * \param port The source port for this TcpHeader
       
    46    */
       
    47   void SetSourcePort (uint16_t port);
       
    48   /**
       
    49    * \param port the destination port for this TcpHeader
       
    50    */
       
    51   void SetDestinationPort (uint16_t port);
       
    52   /**
       
    53    * \param sequenceNumber the sequence number for this TcpHeader
       
    54    */
       
    55   void SetSequenceNumber (SequenceNumber sequenceNumber);
       
    56   /**
       
    57    * \param ackNumber the ACK number for this TcpHeader
       
    58    */
       
    59   void SetAckNumber (SequenceNumber ackNumber);
       
    60   /**
       
    61    * \param length the length of this TcpHeader
       
    62    */
       
    63   void SetLength (uint8_t length);
       
    64   /**
       
    65    * \param flags the flags for this TcpHeader
       
    66    */
       
    67   void SetFlags (uint8_t flags);
       
    68   /**
       
    69    * \param windowSize the window size for this TcpHeader
       
    70    */
       
    71   void SetWindowSize (uint16_t windowSize);
       
    72   /**
       
    73    * \param checksum the checksum for this TcpHeader
       
    74    */
       
    75   void SetChecksum (uint16_t checksum);
       
    76   /**
       
    77    * \param urgentPointer the urgent pointer for this TcpHeader
       
    78    */
       
    79   void SetUrgentPointer (uint16_t urgentPointer);
       
    80 
       
    81 
       
    82 //Getters
       
    83   /**
       
    84    * \return The source port for this TcpHeader
       
    85    */
       
    86   uint16_t GetSourcePort () const;
       
    87   /**
       
    88    * \return the destination port for this TcpHeader
       
    89    */
       
    90   uint16_t GetDestinationPort () const;
       
    91   /**
       
    92    * \return the sequence number for this TcpHeader
       
    93    */
       
    94   SequenceNumber GetSequenceNumber () const;
       
    95   /**
       
    96    * \return the ACK number for this TcpHeader
       
    97    */
       
    98   SequenceNumber GetAckNumber () const;
       
    99   /**
       
   100    * \return the length of this TcpHeader
       
   101    */
       
   102   uint8_t  GetLength () const;
       
   103   /**
       
   104    * \return the flags for this TcpHeader
       
   105    */
       
   106   uint8_t  GetFlags () const;
       
   107   /**
       
   108    * \return the window size for this TcpHeader
       
   109    */
       
   110   uint16_t GetWindowSize () const;
       
   111   /**
       
   112    * \return the checksum for this TcpHeader
       
   113    */
       
   114   uint16_t GetChecksum () const;
       
   115   /**
       
   116    * \return the urgent pointer for this TcpHeader
       
   117    */
       
   118   uint16_t GetUrgentPointer () const;
       
   119 
       
   120   /**
       
   121    * \param source the ip source to use in the underlying
       
   122    *        ip packet.
       
   123    * \param destination the ip destination to use in the
       
   124    *        underlying ip packet.
       
   125    * \param protocol the protocol number to use in the underlying
       
   126    *        ip packet.
       
   127    *
       
   128    * If you want to use tcp checksums, you should call this
       
   129    * method prior to adding the header to a packet.
       
   130    */
       
   131   void InitializeChecksum (Ipv4Address source, 
       
   132                            Ipv4Address destination,
       
   133                            uint8_t protocol);
       
   134 
       
   135   typedef enum { NONE = 0, FIN = 1, SYN = 2, RST = 4, PSH = 8, ACK = 16, 
       
   136     URG = 32} Flags_t;
       
   137 
       
   138   static TypeId GetTypeId (void);
       
   139   virtual TypeId GetInstanceTypeId (void) const;
       
   140   virtual void Print (std::ostream &os) const;
       
   141   virtual uint32_t GetSerializedSize (void) const;
       
   142   virtual void Serialize (Buffer::Iterator start) const;
       
   143   virtual uint32_t Deserialize (Buffer::Iterator start);
       
   144 
       
   145 private:
       
   146   uint16_t m_sourcePort;
       
   147   uint16_t m_destinationPort;
       
   148   uint32_t m_sequenceNumber;
       
   149   uint32_t m_ackNumber;
       
   150   uint8_t m_length; // really a uint4_t
       
   151   uint8_t m_flags;      // really a uint6_t
       
   152   uint16_t m_windowSize;
       
   153   uint16_t m_checksum;
       
   154   uint16_t m_urgentPointer;
       
   155 
       
   156   static bool m_calcChecksum;
       
   157 };
       
   158 
       
   159 }; // namespace ns3
       
   160 
       
   161 #endif /* TCP_HEADER */