A Discrete-Event Network Simulator
API
icmpv4.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 INRIA
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18  */
19 
20 #ifndef ICMPV4_H
21 #define ICMPV4_H
22 
23 #include "ns3/header.h"
24 #include "ns3/ipv4-header.h"
25 #include "ns3/ptr.h"
26 
27 #include <stdint.h>
28 
29 namespace ns3
30 {
31 
32 class Packet;
33 
41 class Icmpv4Header : public Header
42 {
43  public:
47  enum Type_e
48  {
53  };
54 
58  void EnableChecksum();
59 
64  void SetType(uint8_t type);
65 
70  void SetCode(uint8_t code);
71 
76  uint8_t GetType() const;
81  uint8_t GetCode() const;
82 
87  static TypeId GetTypeId();
88  Icmpv4Header();
89  ~Icmpv4Header() override;
90 
91  TypeId GetInstanceTypeId() const override;
92  uint32_t GetSerializedSize() const override;
93  void Serialize(Buffer::Iterator start) const override;
94  uint32_t Deserialize(Buffer::Iterator start) override;
95  void Print(std::ostream& os) const override;
96 
97  private:
98  uint8_t m_type;
99  uint8_t m_code;
101 };
102 
108 class Icmpv4Echo : public Header
109 {
110  public:
115  void SetIdentifier(uint16_t id);
120  void SetSequenceNumber(uint16_t seq);
130  uint16_t GetIdentifier() const;
135  uint16_t GetSequenceNumber() const;
140  uint32_t GetDataSize() const;
146  uint32_t GetData(uint8_t payload[]) const;
147 
152  static TypeId GetTypeId();
153  Icmpv4Echo();
154  ~Icmpv4Echo() override;
155  TypeId GetInstanceTypeId() const override;
156  uint32_t GetSerializedSize() const override;
157  void Serialize(Buffer::Iterator start) const override;
158  uint32_t Deserialize(Buffer::Iterator start) override;
159  void Print(std::ostream& os) const override;
160 
161  private:
162  uint16_t m_identifier;
163  uint16_t m_sequence;
164  uint8_t* m_data;
165  uint32_t m_dataSize;
166 };
167 
174 {
175  public:
180  {
187  };
188 
193  static TypeId GetTypeId();
196 
201  void SetNextHopMtu(uint16_t mtu);
206  uint16_t GetNextHopMtu() const;
207 
217  void SetHeader(Ipv4Header header);
218 
223  void GetData(uint8_t payload[8]) const;
228  Ipv4Header GetHeader() const;
229 
230  private:
231  TypeId GetInstanceTypeId() const override;
232  uint32_t GetSerializedSize() const override;
233  void Serialize(Buffer::Iterator start) const override;
234  uint32_t Deserialize(Buffer::Iterator start) override;
235  void Print(std::ostream& os) const override;
236 
237  private:
238  uint16_t m_nextHopMtu;
240  uint8_t m_data[8];
241 };
242 
249 {
250  public:
255  {
258  };
259 
269  void SetHeader(Ipv4Header header);
270 
275  void GetData(uint8_t payload[8]) const;
280  Ipv4Header GetHeader() const;
281 
286  static TypeId GetTypeId();
288  ~Icmpv4TimeExceeded() override;
289  TypeId GetInstanceTypeId() const override;
290  uint32_t GetSerializedSize() const override;
291  void Serialize(Buffer::Iterator start) const override;
292  uint32_t Deserialize(Buffer::Iterator start) override;
293  void Print(std::ostream& os) const override;
294 
295  private:
297  uint8_t m_data[8];
298 };
299 
300 } // namespace ns3
301 
302 #endif /* ICMPV4_H */
iterator in a Buffer instance
Definition: buffer.h:100
Protocol header serialization and deserialization.
Definition: header.h:44
virtual uint32_t Deserialize(Buffer::Iterator start)=0
Deserialize the object from a buffer iterator.
ICMP Destination Unreachable header.
Definition: icmpv4.h:174
Ipv4Header m_header
carried IPv4 header
Definition: icmpv4.h:239
uint16_t GetNextHopMtu() const
Get the next hop MTU.
Definition: icmpv4.cc:331
uint16_t m_nextHopMtu
next hop MTU
Definition: icmpv4.h:238
Ipv4Header GetHeader() const
Get the ICMP carried IPv4 header.
Definition: icmpv4.cc:359
void GetData(uint8_t payload[8]) const
Get the ICMP carried data.
Definition: icmpv4.cc:352
void SetNextHopMtu(uint16_t mtu)
Set the next hop MTU.
Definition: icmpv4.cc:324
void Serialize(Buffer::Iterator start) const override
Definition: icmpv4.cc:384
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: icmpv4.cc:370
uint32_t GetSerializedSize() const override
Definition: icmpv4.cc:377
void SetHeader(Ipv4Header header)
Set the ICMP carried IPv4 header.
Definition: icmpv4.cc:345
void SetData(Ptr< const Packet > data)
Set the ICMP carried data.
Definition: icmpv4.cc:338
~Icmpv4DestinationUnreachable() override
Definition: icmpv4.cc:365
ErrorDestinationUnreachable_e
ICMP error code : Destination Unreachable.
Definition: icmpv4.h:180
static TypeId GetTypeId()
Get ICMP type.
Definition: icmpv4.cc:303
uint8_t m_data[8]
carried data
Definition: icmpv4.h:240
void Print(std::ostream &os) const override
Definition: icmpv4.cc:412
ICMP Echo header.
Definition: icmpv4.h:109
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: icmpv4.cc:246
void Print(std::ostream &os) const override
Definition: icmpv4.cc:289
uint16_t m_identifier
identifier
Definition: icmpv4.h:162
uint16_t m_sequence
sequence number
Definition: icmpv4.h:163
uint32_t GetData(uint8_t payload[]) const
Get the Echo data.
Definition: icmpv4.cc:207
void SetIdentifier(uint16_t id)
Set the Echo identifier.
Definition: icmpv4.cc:150
void SetData(Ptr< const Packet > data)
Set the Echo data.
Definition: icmpv4.cc:164
uint32_t GetSerializedSize() const override
Definition: icmpv4.cc:253
uint16_t GetIdentifier() const
Get the Echo identifier.
Definition: icmpv4.cc:186
void Serialize(Buffer::Iterator start) const override
Definition: icmpv4.cc:260
~Icmpv4Echo() override
Definition: icmpv4.cc:237
static TypeId GetTypeId()
Get ICMP type.
Definition: icmpv4.cc:215
uint8_t * m_data
data
Definition: icmpv4.h:164
void SetSequenceNumber(uint16_t seq)
Set the Echo sequence number.
Definition: icmpv4.cc:157
uint32_t GetDataSize() const
Get the Echo data size.
Definition: icmpv4.cc:200
uint32_t m_dataSize
data size
Definition: icmpv4.h:165
uint16_t GetSequenceNumber() const
Get the Echo sequence number.
Definition: icmpv4.cc:193
Base class for all the ICMP packet headers.
Definition: icmpv4.h:42
Type_e
ICMP type code.
Definition: icmpv4.h:48
@ ICMPV4_TIME_EXCEEDED
Definition: icmpv4.h:52
@ ICMPV4_DEST_UNREACH
Definition: icmpv4.h:50
void SetCode(uint8_t code)
Set ICMP code.
Definition: icmpv4.cc:123
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: icmpv4.cc:67
bool m_calcChecksum
true if checksum is calculated
Definition: icmpv4.h:100
void SetType(uint8_t type)
Set ICMP type.
Definition: icmpv4.cc:116
uint8_t m_code
ICMP code.
Definition: icmpv4.h:99
void EnableChecksum()
Enables ICMP Checksum calculation.
Definition: icmpv4.cc:60
void Print(std::ostream &os) const override
Definition: icmpv4.cc:109
uint8_t m_type
ICMP type.
Definition: icmpv4.h:98
static TypeId GetTypeId()
Get the type ID.
Definition: icmpv4.cc:37
uint8_t GetCode() const
Get ICMP code.
Definition: icmpv4.cc:137
uint8_t GetType() const
Get ICMP type.
Definition: icmpv4.cc:130
uint32_t GetSerializedSize() const override
Definition: icmpv4.cc:74
~Icmpv4Header() override
Definition: icmpv4.cc:54
void Serialize(Buffer::Iterator start) const override
Definition: icmpv4.cc:81
ICMP Time Exceeded header.
Definition: icmpv4.h:249
Ipv4Header m_header
carried IPv4 header
Definition: icmpv4.h:296
Ipv4Header GetHeader() const
Get the ICMP carried IPv4 header.
Definition: icmpv4.cc:476
void SetHeader(Ipv4Header header)
Set the ICMP carried IPv4 header.
Definition: icmpv4.cc:462
uint32_t GetSerializedSize() const override
Definition: icmpv4.cc:495
void GetData(uint8_t payload[8]) const
Get the ICMP carried data.
Definition: icmpv4.cc:469
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: icmpv4.cc:488
void Serialize(Buffer::Iterator start) const override
Definition: icmpv4.cc:502
ErrorTimeExceeded_e
ICMP error code : Time Exceeded.
Definition: icmpv4.h:255
uint8_t m_data[8]
carried data
Definition: icmpv4.h:297
static TypeId GetTypeId()
Get ICMP type.
Definition: icmpv4.cc:434
void SetData(Ptr< const Packet > data)
Get the ICMP carried data.
Definition: icmpv4.cc:455
~Icmpv4TimeExceeded() override
Definition: icmpv4.cc:482
void Print(std::ostream &os) const override
Definition: icmpv4.cc:528
Packet header for IPv4.
Definition: ipv4-header.h:34
a unique identifier for an interface.
Definition: type-id.h:60
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t data[writeSize]