A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ipv4-header.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2005 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 #ifndef IPV4_HEADER_H
22 #define IPV4_HEADER_H
23 
24 #include "ns3/header.h"
25 #include "ns3/ipv4-address.h"
26 
27 namespace ns3 {
31 class Ipv4Header : public Header
32 {
33 public:
37  Ipv4Header ();
41  void EnableChecksum (void);
45  void SetPayloadSize (uint16_t size);
51  void SetIdentification (uint16_t identification);
55  void SetTos (uint8_t tos);
64  enum DscpType
65  {
66  DscpDefault = 0x00,
67 
68  CS1 = 0x20,
69  AF11 = 0x28,
70  AF12 = 0x30,
71  AF13 = 0x38,
72 
73  CS2 = 0x40,
74  AF21 = 0x48,
75  AF22 = 0x50,
76  AF23 = 0x58,
77 
78  CS3 = 0x60,
79  AF31 = 0x68,
80  AF32 = 0x70,
81  AF33 = 0x78,
82 
83  CS4 = 0x80,
84  AF41 = 0x88,
85  AF42 = 0x90,
86  AF43 = 0x98,
87 
88  CS5 = 0xA0,
89  EF = 0xB8,
90 
91  CS6 = 0xC0,
92  CS7 = 0xE0
93 
94  };
99  void SetDscp (DscpType dscp);
100 
105  enum EcnType
106  {
107  NotECT = 0x00,
108  ECT1 = 0x01,
109  ECT0 = 0x02,
110  CE = 0x03
111  };
116  void SetEcn (EcnType ecn);
120  void SetMoreFragments (void);
124  void SetLastFragment (void);
128  void SetDontFragment (void);
132  void SetMayFragment (void);
139  void SetFragmentOffset (uint16_t offsetBytes);
143  void SetTtl (uint8_t ttl);
147  void SetProtocol (uint8_t num);
151  void SetSource (Ipv4Address source);
155  void SetDestination (Ipv4Address destination);
159  uint16_t GetPayloadSize (void) const;
163  uint16_t GetIdentification (void) const;
167  uint8_t GetTos (void) const;
171  DscpType GetDscp (void) const;
175  std::string DscpTypeToString (DscpType dscp) const;
179  EcnType GetEcn (void) const;
183  std::string EcnTypeToString (EcnType ecn) const;
187  bool IsLastFragment (void) const;
191  bool IsDontFragment (void) const;
195  uint16_t GetFragmentOffset (void) const;
199  uint8_t GetTtl (void) const;
203  uint8_t GetProtocol (void) const;
207  Ipv4Address GetSource (void) const;
211  Ipv4Address GetDestination (void) const;
212 
219  bool IsChecksumOk (void) const;
220 
221  static TypeId GetTypeId (void);
222  virtual TypeId GetInstanceTypeId (void) const;
223  virtual void Print (std::ostream &os) const;
224  virtual uint32_t GetSerializedSize (void) const;
225  virtual void Serialize (Buffer::Iterator start) const;
226  virtual uint32_t Deserialize (Buffer::Iterator start);
227 private:
228 
229  enum FlagsE {
230  DONT_FRAGMENT = (1<<0),
231  MORE_FRAGMENTS = (1<<1)
232  };
233 
235 
236  uint16_t m_payloadSize;
238  uint32_t m_tos : 8; //Also used as DSCP + ECN value
239  uint32_t m_ttl : 8;
240  uint32_t m_protocol : 8;
241  uint32_t m_flags : 3;
245  uint16_t m_checksum;
247  uint16_t m_headerSize;
248 };
249 
250 } // namespace ns3
251 
252 
253 #endif /* IPV4_HEADER_H */