A Discrete-Event Network Simulator
API
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);
56 public:
65  enum DscpType
66  {
67  DscpDefault = 0x00,
68 
69  // Prefixed with "DSCP" to avoid name clash (bug 1723)
70  DSCP_CS1 = 0x08, // octal 010
71  DSCP_AF11 = 0x0A, // octal 012
72  DSCP_AF12 = 0x0C, // octal 014
73  DSCP_AF13 = 0x0E, // octal 016
74 
75  DSCP_CS2 = 0x10, // octal 020
76  DSCP_AF21 = 0x12, // octal 022
77  DSCP_AF22 = 0x14, // octal 024
78  DSCP_AF23 = 0x16, // octal 026
79 
80  DSCP_CS3 = 0x18, // octal 030
81  DSCP_AF31 = 0x1A, // octal 032
82  DSCP_AF32 = 0x1C, // octal 034
83  DSCP_AF33 = 0x1E, // octal 036
84 
85  DSCP_CS4 = 0x20, // octal 040
86  DSCP_AF41 = 0x22, // octal 042
87  DSCP_AF42 = 0x24, // octal 044
88  DSCP_AF43 = 0x26, // octal 046
89 
90  DSCP_CS5 = 0x28, // octal 050
91  DSCP_EF = 0x2E, // octal 056
92 
93  DSCP_CS6 = 0x30, // octal 060
94  DSCP_CS7 = 0x38 // octal 070
95 
96  };
101  void SetDscp (DscpType dscp);
102 
107  enum EcnType
108  {
109  // Prefixed with "ECN" to avoid name clash (bug 1723)
110  ECN_NotECT = 0x00,
111  ECN_ECT1 = 0x01,
112  ECN_ECT0 = 0x02,
113  ECN_CE = 0x03
114  };
119  void SetEcn (EcnType ecn);
123  void SetMoreFragments (void);
127  void SetLastFragment (void);
131  void SetDontFragment (void);
135  void SetMayFragment (void);
142  void SetFragmentOffset (uint16_t offsetBytes);
146  void SetTtl (uint8_t ttl);
150  void SetProtocol (uint8_t num);
154  void SetSource (Ipv4Address source);
158  void SetDestination (Ipv4Address destination);
162  uint16_t GetPayloadSize (void) const;
166  uint16_t GetIdentification (void) const;
170  uint8_t GetTos (void) const;
174  DscpType GetDscp (void) const;
179  std::string DscpTypeToString (DscpType dscp) const;
183  EcnType GetEcn (void) const;
188  std::string EcnTypeToString (EcnType ecn) const;
192  bool IsLastFragment (void) const;
196  bool IsDontFragment (void) const;
200  uint16_t GetFragmentOffset (void) const;
204  uint8_t GetTtl (void) const;
208  uint8_t GetProtocol (void) const;
212  Ipv4Address GetSource (void) const;
216  Ipv4Address GetDestination (void) const;
217 
224  bool IsChecksumOk (void) const;
225 
230  static TypeId GetTypeId (void);
231  virtual TypeId GetInstanceTypeId (void) const;
232  virtual void Print (std::ostream &os) const;
233  virtual uint32_t GetSerializedSize (void) const;
234  virtual void Serialize (Buffer::Iterator start) const;
235  virtual uint32_t Deserialize (Buffer::Iterator start);
236 private:
237 
239  enum FlagsE {
240  DONT_FRAGMENT = (1<<0),
241  MORE_FRAGMENTS = (1<<1)
242  };
243 
245 
246  uint16_t m_payloadSize;
247  uint16_t m_identification;
248  uint32_t m_tos : 8;
249  uint32_t m_ttl : 8;
250  uint32_t m_protocol : 8;
251  uint32_t m_flags : 3;
252  uint16_t m_fragmentOffset;
255  uint16_t m_checksum;
257  uint16_t m_headerSize;
258 };
259 
260 } // namespace ns3
261 
262 
263 #endif /* IPV4_HEADER_H */
Protocol header serialization and deserialization.
Definition: header.h:42
void SetSource(Ipv4Address source)
Definition: ipv4-header.cc:285
void SetPayloadSize(uint16_t size)
Definition: ipv4-header.cc:56
uint16_t GetPayloadSize(void) const
Definition: ipv4-header.cc:62
uint32_t m_ttl
TTL.
Definition: ipv4-header.h:249
void SetDestination(Ipv4Address destination)
Definition: ipv4-header.cc:298
uint32_t m_flags
flags
Definition: ipv4-header.h:251
uint16_t m_identification
identification
Definition: ipv4-header.h:247
DscpType
DiffServ Code Points Code Points defined in Assured Forwarding (AF) RFC 2597 Expedited Forwarding (EF...
Definition: ipv4-header.h:65
Ipv4Address m_destination
destination address
Definition: ipv4-header.h:254
def start()
Definition: core.py:1482
Ipv4Address GetDestination(void) const
Definition: ipv4-header.cc:304
uint8_t GetProtocol(void) const
Definition: ipv4-header.cc:272
uint16_t GetIdentification(void) const
Definition: ipv4-header.cc:69
uint16_t m_headerSize
IP header size.
Definition: ipv4-header.h:257
bool IsDontFragment(void) const
Definition: ipv4-header.cc:231
void SetFragmentOffset(uint16_t offsetBytes)
The offset is measured in bytes for the packet start.
Definition: ipv4-header.cc:238
Ipv4Address GetSource(void) const
Definition: ipv4-header.cc:291
void SetProtocol(uint8_t num)
Definition: ipv4-header.cc:278
uint32_t m_tos
TOS, also used as DSCP + ECN value.
Definition: ipv4-header.h:248
std::string DscpTypeToString(DscpType dscp) const
Definition: ipv4-header.cc:113
void SetDontFragment(void)
Don't fragment this packet: if you need to anyway, drop it.
Definition: ipv4-header.cc:219
iterator in a Buffer instance
Definition: buffer.h:98
static TypeId GetTypeId(void)
Get the type ID.
Definition: ipv4-header.cc:319
Packet header for IPv4.
Definition: ipv4-header.h:31
void SetLastFragment(void)
This packet is the last packet of a fragmented ipv4 packet.
Definition: ipv4-header.cc:206
bool m_goodChecksum
true if checksum is correct
Definition: ipv4-header.h:256
DscpType GetDscp(void) const
Definition: ipv4-header.cc:105
Ipv4Header()
Construct a null IPv4 header.
Definition: ipv4-header.cc:33
void EnableChecksum(void)
Enable checksum calculation for this header.
Definition: ipv4-header.cc:49
void SetDscp(DscpType dscp)
Set DSCP Field.
Definition: ipv4-header.cc:89
void SetIdentification(uint16_t identification)
Definition: ipv4-header.cc:75
void SetMayFragment(void)
If you need to fragment this packet, you can do it.
Definition: ipv4-header.cc:225
uint16_t m_fragmentOffset
Fragment offset.
Definition: ipv4-header.h:252
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint16_t m_checksum
checksum
Definition: ipv4-header.h:255
void SetMoreFragments(void)
This packet is not the last packet of a fragmented ipv4 packet.
Definition: ipv4-header.cc:200
bool IsLastFragment(void) const
Definition: ipv4-header.cc:212
void SetTos(uint8_t tos)
Definition: ipv4-header.cc:82
virtual void Print(std::ostream &os) const
Definition: ipv4-header.cc:335
Ipv4Address m_source
source address
Definition: ipv4-header.h:253
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition: ipv4-header.cc:329
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
FlagsE
flags related to IP fragmentation
Definition: ipv4-header.h:239
uint16_t GetFragmentOffset(void) const
Definition: ipv4-header.cc:246
uint32_t m_protocol
Protocol.
Definition: ipv4-header.h:250
void SetEcn(EcnType ecn)
Set ECN Field.
Definition: ipv4-header.cc:97
void SetTtl(uint8_t ttl)
Definition: ipv4-header.cc:259
virtual void Serialize(Buffer::Iterator start) const
Definition: ipv4-header.cc:383
bool IsChecksumOk(void) const
Definition: ipv4-header.cc:312
bool m_calcChecksum
true if the checksum must be calculated
Definition: ipv4-header.h:244
uint8_t GetTtl(void) const
Definition: ipv4-header.cc:265
uint8_t GetTos(void) const
Definition: ipv4-header.cc:194
uint16_t m_payloadSize
payload size
Definition: ipv4-header.h:246
std::string EcnTypeToString(EcnType ecn) const
Definition: ipv4-header.cc:175
virtual uint32_t GetSerializedSize(void) const
Definition: ipv4-header.cc:375
a unique identifier for an interface.
Definition: type-id.h:58
EcnType GetEcn(void) const
Definition: ipv4-header.cc:167
EcnType
ECN Type defined in RFC 3168
Definition: ipv4-header.h:107
virtual uint32_t Deserialize(Buffer::Iterator start)
Definition: ipv4-header.cc:423