A Discrete-Event Network Simulator
API
icmpv4.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008 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 ICMPV4_H
22 #define ICMPV4_H
23 
24 #include "ns3/header.h"
25 #include "ns3/ptr.h"
26 #include "ns3/ipv4-header.h"
27 #include <stdint.h>
28 
29 namespace ns3 {
30 
31 class Packet;
32 
40 class Icmpv4Header : public Header
41 {
42 public:
43 
47  enum Type_e {
52  };
53 
57  void EnableChecksum (void);
58 
63  void SetType (uint8_t type);
64 
69  void SetCode (uint8_t code);
70 
75  uint8_t GetType (void) const;
80  uint8_t GetCode (void) const;
81 
86  static TypeId GetTypeId (void);
87  Icmpv4Header ();
88  virtual ~Icmpv4Header ();
89 
90  virtual TypeId GetInstanceTypeId (void) const;
91  virtual uint32_t GetSerializedSize (void) const;
92  virtual void Serialize (Buffer::Iterator start) const;
93  virtual uint32_t Deserialize (Buffer::Iterator start);
94  virtual void Print (std::ostream &os) const;
95 
96 private:
97  uint8_t m_type;
98  uint8_t m_code;
100 };
101 
107 class Icmpv4Echo : public Header
108 {
109 public:
114  void SetIdentifier (uint16_t id);
119  void SetSequenceNumber (uint16_t seq);
129  uint16_t GetIdentifier (void) const;
134  uint16_t GetSequenceNumber (void) const;
139  uint32_t GetDataSize (void) const;
145  uint32_t GetData (uint8_t payload[]) const;
146 
147 
152  static TypeId GetTypeId (void);
153  Icmpv4Echo ();
154  virtual ~Icmpv4Echo ();
155  virtual TypeId GetInstanceTypeId (void) const;
156  virtual uint32_t GetSerializedSize (void) const;
157  virtual void Serialize (Buffer::Iterator start) const;
158  virtual uint32_t Deserialize (Buffer::Iterator start);
159  virtual void Print (std::ostream &os) const;
160 private:
161  uint16_t m_identifier;
162  uint16_t m_sequence;
163  uint8_t *m_data;
164  uint32_t m_dataSize;
165 };
166 
173 {
174 public:
185  };
186 
191  static TypeId GetTypeId (void);
194 
199  void SetNextHopMtu (uint16_t mtu);
204  uint16_t GetNextHopMtu (void) const;
205 
215  void SetHeader (Ipv4Header header);
216 
221  void GetData (uint8_t payload[8]) const;
226  Ipv4Header GetHeader (void) const;
227 
228 private:
229  virtual TypeId GetInstanceTypeId (void) const;
230  virtual uint32_t GetSerializedSize (void) const;
231  virtual void Serialize (Buffer::Iterator start) const;
232  virtual uint32_t Deserialize (Buffer::Iterator start);
233  virtual void Print (std::ostream &os) const;
234 private:
235  uint16_t m_nextHopMtu;
237  uint8_t m_data[8];
238 };
239 
240 
247 {
248 public:
253  {
256  };
257 
267  void SetHeader (Ipv4Header header);
268 
273  void GetData (uint8_t payload[8]) const;
278  Ipv4Header GetHeader (void) const;
279 
284  static TypeId GetTypeId (void);
286  virtual ~Icmpv4TimeExceeded ();
287  virtual TypeId GetInstanceTypeId (void) const;
288  virtual uint32_t GetSerializedSize (void) const;
289  virtual void Serialize (Buffer::Iterator start) const;
290  virtual uint32_t Deserialize (Buffer::Iterator start);
291  virtual void Print (std::ostream &os) const;
292 
293 private:
295  uint8_t m_data[8];
296 };
297 
298 } // namespace ns3
299 
300 #endif /* ICMPV4_H */
Protocol header serialization and deserialization.
Definition: header.h:42
virtual void Print(std::ostream &os) const
Definition: icmpv4.cc:102
void SetType(uint8_t type)
Set ICMP type.
Definition: icmpv4.cc:109
ErrorDestinationUnreachable_e
ICMP error code : Destination Unreachable.
Definition: icmpv4.h:178
Ipv4Header GetHeader(void) const
Get the ICMP carried IPv4 header.
Definition: icmpv4.cc:332
void SetHeader(Ipv4Header header)
Set the ICMP carried IPv4 header.
Definition: icmpv4.cc:320
uint16_t m_sequence
sequence number
Definition: icmpv4.h:162
uint32_t GetData(uint8_t payload[]) const
Get the Echo data.
Definition: icmpv4.cc:191
uint32_t GetDataSize(void) const
Get the Echo data size.
Definition: icmpv4.cc:185
ICMP Time Exceeded header.
Definition: icmpv4.h:246
void SetData(Ptr< const Packet > data)
Set the ICMP carried data.
Definition: icmpv4.cc:314
def start()
Definition: core.py:1844
static TypeId GetTypeId(void)
Get ICMP type.
Definition: icmpv4.cc:198
virtual void Print(std::ostream &os) const
Definition: icmpv4.cc:493
virtual uint32_t Deserialize(Buffer::Iterator start)
Definition: icmpv4.cc:479
uint8_t m_code
ICMP code.
Definition: icmpv4.h:98
static TypeId GetTypeId(void)
Get the type ID.
Definition: icmpv4.cc:36
void GetData(uint8_t payload[8]) const
Get the ICMP carried data.
Definition: icmpv4.cc:326
virtual void Serialize(Buffer::Iterator start) const
Definition: icmpv4.cc:468
virtual uint32_t Deserialize(Buffer::Iterator start)
Definition: icmpv4.cc:93
virtual void Print(std::ostream &os) const
Definition: icmpv4.cc:382
virtual ~Icmpv4Header()
Definition: icmpv4.cc:52
Base class for all the ICMP packet headers.
Definition: icmpv4.h:40
iterator in a Buffer instance
Definition: buffer.h:98
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition: icmpv4.cc:227
void SetCode(uint8_t code)
Set ICMP code.
Definition: icmpv4.cc:115
Packet header for IPv4.
Definition: ipv4-header.h:33
virtual void Print(std::ostream &os) const
Definition: icmpv4.cc:266
uint16_t m_nextHopMtu
next hop MTU
Definition: icmpv4.h:235
virtual uint32_t GetSerializedSize(void) const
Definition: icmpv4.cc:462
uint32_t m_dataSize
data size
Definition: icmpv4.h:164
void EnableChecksum(void)
Enables ICMP Checksum calculation.
Definition: icmpv4.cc:57
virtual uint32_t GetSerializedSize(void) const
Definition: icmpv4.cc:349
virtual void Serialize(Buffer::Iterator start) const
Definition: icmpv4.cc:239
static TypeId GetTypeId(void)
Get ICMP type.
Definition: icmpv4.cc:280
uint8_t data[writeSize]
uint8_t GetType(void) const
Get ICMP type.
Definition: icmpv4.cc:121
Ipv4Header m_header
carried IPv4 header
Definition: icmpv4.h:294
Type_e
ICMP type code.
Definition: icmpv4.h:47
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition: icmpv4.cc:343
uint8_t m_data[8]
carried data
Definition: icmpv4.h:295
void SetHeader(Ipv4Header header)
Set the ICMP carried IPv4 header.
Definition: icmpv4.cc:432
virtual uint32_t GetSerializedSize(void) const
Definition: icmpv4.cc:233
void SetData(Ptr< const Packet > data)
Get the ICMP carried data.
Definition: icmpv4.cc:426
void SetNextHopMtu(uint16_t mtu)
Set the next hop MTU.
Definition: icmpv4.cc:301
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ipv4Header m_header
carried IPv4 header
Definition: icmpv4.h:236
Ipv4Header GetHeader(void) const
Get the ICMP carried IPv4 header.
Definition: icmpv4.cc:444
virtual ~Icmpv4Echo()
Definition: icmpv4.cc:219
virtual void Serialize(Buffer::Iterator start) const
Definition: icmpv4.cc:355
ICMP Echo header.
Definition: icmpv4.h:107
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition: icmpv4.cc:456
virtual uint32_t Deserialize(Buffer::Iterator start)
Definition: icmpv4.cc:367
virtual uint32_t GetSerializedSize(void) const
Definition: icmpv4.cc:69
ErrorTimeExceeded_e
ICMP error code : Time Exceeded.
Definition: icmpv4.h:252
void SetData(Ptr< const Packet > data)
Set the Echo data.
Definition: icmpv4.cc:152
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition: icmpv4.cc:63
uint16_t GetSequenceNumber(void) const
Get the Echo sequence number.
Definition: icmpv4.cc:179
uint16_t GetNextHopMtu(void) const
Get the next hop MTU.
Definition: icmpv4.cc:307
virtual ~Icmpv4TimeExceeded()
Definition: icmpv4.cc:451
uint16_t m_identifier
identifier
Definition: icmpv4.h:161
virtual void Serialize(Buffer::Iterator start) const
Definition: icmpv4.cc:75
uint16_t GetIdentifier(void) const
Get the Echo identifier.
Definition: icmpv4.cc:173
ICMP Destination Unreachable header.
Definition: icmpv4.h:172
void SetSequenceNumber(uint16_t seq)
Set the Echo sequence number.
Definition: icmpv4.cc:146
void GetData(uint8_t payload[8]) const
Get the ICMP carried data.
Definition: icmpv4.cc:438
virtual uint32_t Deserialize(Buffer::Iterator start)
Definition: icmpv4.cc:247
static TypeId GetTypeId(void)
Get ICMP type.
Definition: icmpv4.cc:404
uint8_t m_data[8]
carried data
Definition: icmpv4.h:237
uint8_t GetCode(void) const
Get ICMP code.
Definition: icmpv4.cc:127
a unique identifier for an interface.
Definition: type-id.h:58
void SetIdentifier(uint16_t id)
Set the Echo identifier.
Definition: icmpv4.cc:140
bool m_calcChecksum
true if checksum is calculated
Definition: icmpv4.h:99
uint8_t * m_data
data
Definition: icmpv4.h:163
uint8_t m_type
ICMP type.
Definition: icmpv4.h:97