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 */
iterator in a Buffer instance
Definition: buffer.h:99
Protocol header serialization and deserialization.
Definition: header.h:43
virtual uint32_t Deserialize(Buffer::Iterator start)=0
Deserialize the object from a buffer iterator.
ICMP Destination Unreachable header.
Definition: icmpv4.h:173
Ipv4Header m_header
carried IPv4 header
Definition: icmpv4.h:236
uint16_t m_nextHopMtu
next hop MTU
Definition: icmpv4.h:235
static TypeId GetTypeId(void)
Get ICMP type.
Definition: icmpv4.cc:280
void GetData(uint8_t payload[8]) const
Get the ICMP carried data.
Definition: icmpv4.cc:326
Ipv4Header GetHeader(void) const
Get the ICMP carried IPv4 header.
Definition: icmpv4.cc:332
void SetNextHopMtu(uint16_t mtu)
Set the next hop MTU.
Definition: icmpv4.cc:301
uint16_t GetNextHopMtu(void) const
Get the next hop MTU.
Definition: icmpv4.cc:307
void SetHeader(Ipv4Header header)
Set the ICMP carried IPv4 header.
Definition: icmpv4.cc:320
virtual void Serialize(Buffer::Iterator start) const
Definition: icmpv4.cc:355
virtual void Print(std::ostream &os) const
Definition: icmpv4.cc:382
void SetData(Ptr< const Packet > data)
Set the ICMP carried data.
Definition: icmpv4.cc:314
ErrorDestinationUnreachable_e
ICMP error code : Destination Unreachable.
Definition: icmpv4.h:178
virtual uint32_t GetSerializedSize(void) const
Definition: icmpv4.cc:349
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:237
ICMP Echo header.
Definition: icmpv4.h:108
uint16_t GetSequenceNumber(void) const
Get the Echo sequence number.
Definition: icmpv4.cc:179
uint16_t m_identifier
identifier
Definition: icmpv4.h:161
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
void SetIdentifier(uint16_t id)
Set the Echo identifier.
Definition: icmpv4.cc:140
void SetData(Ptr< const Packet > data)
Set the Echo data.
Definition: icmpv4.cc:152
virtual void Serialize(Buffer::Iterator start) const
Definition: icmpv4.cc:239
virtual ~Icmpv4Echo()
Definition: icmpv4.cc:219
uint16_t GetIdentifier(void) const
Get the Echo identifier.
Definition: icmpv4.cc:173
uint32_t GetDataSize(void) const
Get the Echo data size.
Definition: icmpv4.cc:185
virtual void Print(std::ostream &os) const
Definition: icmpv4.cc:266
static TypeId GetTypeId(void)
Get ICMP type.
Definition: icmpv4.cc:198
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition: icmpv4.cc:227
uint8_t * m_data
data
Definition: icmpv4.h:163
void SetSequenceNumber(uint16_t seq)
Set the Echo sequence number.
Definition: icmpv4.cc:146
virtual uint32_t GetSerializedSize(void) const
Definition: icmpv4.cc:233
uint32_t m_dataSize
data size
Definition: icmpv4.h:164
Base class for all the ICMP packet headers.
Definition: icmpv4.h:41
virtual void Print(std::ostream &os) const
Definition: icmpv4.cc:102
Type_e
ICMP type code.
Definition: icmpv4.h:47
@ ICMPV4_TIME_EXCEEDED
Definition: icmpv4.h:51
@ ICMPV4_DEST_UNREACH
Definition: icmpv4.h:49
void SetCode(uint8_t code)
Set ICMP code.
Definition: icmpv4.cc:115
bool m_calcChecksum
true if checksum is calculated
Definition: icmpv4.h:99
void SetType(uint8_t type)
Set ICMP type.
Definition: icmpv4.cc:109
uint8_t m_code
ICMP code.
Definition: icmpv4.h:98
uint8_t m_type
ICMP type.
Definition: icmpv4.h:97
uint8_t GetType(void) const
Get ICMP type.
Definition: icmpv4.cc:121
virtual ~Icmpv4Header()
Definition: icmpv4.cc:52
virtual void Serialize(Buffer::Iterator start) const
Definition: icmpv4.cc:75
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition: icmpv4.cc:63
static TypeId GetTypeId(void)
Get the type ID.
Definition: icmpv4.cc:36
virtual uint32_t GetSerializedSize(void) const
Definition: icmpv4.cc:69
void EnableChecksum(void)
Enables ICMP Checksum calculation.
Definition: icmpv4.cc:57
uint8_t GetCode(void) const
Get ICMP code.
Definition: icmpv4.cc:127
ICMP Time Exceeded header.
Definition: icmpv4.h:247
Ipv4Header m_header
carried IPv4 header
Definition: icmpv4.h:294
virtual void Print(std::ostream &os) const
Definition: icmpv4.cc:493
virtual ~Icmpv4TimeExceeded()
Definition: icmpv4.cc:451
Ipv4Header GetHeader(void) const
Get the ICMP carried IPv4 header.
Definition: icmpv4.cc:444
void SetHeader(Ipv4Header header)
Set the ICMP carried IPv4 header.
Definition: icmpv4.cc:432
static TypeId GetTypeId(void)
Get ICMP type.
Definition: icmpv4.cc:404
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition: icmpv4.cc:456
void GetData(uint8_t payload[8]) const
Get the ICMP carried data.
Definition: icmpv4.cc:438
virtual uint32_t GetSerializedSize(void) const
Definition: icmpv4.cc:462
virtual void Serialize(Buffer::Iterator start) const
Definition: icmpv4.cc:468
ErrorTimeExceeded_e
ICMP error code : Time Exceeded.
Definition: icmpv4.h:253
uint8_t m_data[8]
carried data
Definition: icmpv4.h:295
void SetData(Ptr< const Packet > data)
Get the ICMP carried data.
Definition: icmpv4.cc:426
Packet header for IPv4.
Definition: ipv4-header.h:34
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.
def start()
Definition: core.py:1853
uint8_t data[writeSize]