A Discrete-Event Network Simulator
QKDNetSim v2.0 (NS-3 v3.41) @ (+)
API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 "ipv4-header.h"
24 
25 #include "ns3/header.h"
26 #include "ns3/ptr.h"
27 
28 #include <stdint.h>
29 
30 namespace ns3
31 {
32 
33 class Packet;
34 
42 class Icmpv4Header : public Header
43 {
44  public:
48  enum Type_e
49  {
54  };
55 
59  void EnableChecksum();
60 
65  void SetType(uint8_t type);
66 
71  void SetCode(uint8_t code);
72 
77  uint8_t GetType() const;
82  uint8_t GetCode() const;
83 
88  static TypeId GetTypeId();
89  Icmpv4Header();
90  ~Icmpv4Header() override;
91 
92  TypeId GetInstanceTypeId() const override;
93  uint32_t GetSerializedSize() const override;
94  void Serialize(Buffer::Iterator start) const override;
95  uint32_t Deserialize(Buffer::Iterator start) override;
96  void Print(std::ostream& os) const override;
97 
98  private:
99  uint8_t m_type;
100  uint8_t m_code;
102 };
103 
109 class Icmpv4Echo : public Header
110 {
111  public:
116  void SetIdentifier(uint16_t id);
121  void SetSequenceNumber(uint16_t seq);
131  uint16_t GetIdentifier() const;
136  uint16_t GetSequenceNumber() const;
141  uint32_t GetDataSize() const;
147  uint32_t GetData(uint8_t payload[]) const;
148 
153  static TypeId GetTypeId();
154  Icmpv4Echo();
155  ~Icmpv4Echo() override;
156  TypeId GetInstanceTypeId() const override;
157  uint32_t GetSerializedSize() const override;
158  void Serialize(Buffer::Iterator start) const override;
159  uint32_t Deserialize(Buffer::Iterator start) override;
160  void Print(std::ostream& os) const override;
161 
162  private:
163  uint16_t m_identifier;
164  uint16_t m_sequence;
165  uint8_t* m_data;
166  uint32_t m_dataSize;
167 };
168 
175 {
176  public:
181  {
188  };
189 
194  static TypeId GetTypeId();
197 
202  void SetNextHopMtu(uint16_t mtu);
207  uint16_t GetNextHopMtu() const;
208 
218  void SetHeader(Ipv4Header header);
219 
224  void GetData(uint8_t payload[8]) const;
229  Ipv4Header GetHeader() const;
230 
231  private:
232  TypeId GetInstanceTypeId() const override;
233  uint32_t GetSerializedSize() const override;
234  void Serialize(Buffer::Iterator start) const override;
235  uint32_t Deserialize(Buffer::Iterator start) override;
236  void Print(std::ostream& os) const override;
237 
238  private:
239  uint16_t m_nextHopMtu;
241  uint8_t m_data[8];
242 };
243 
250 {
251  public:
256  {
259  };
260 
270  void SetHeader(Ipv4Header header);
271 
276  void GetData(uint8_t payload[8]) const;
281  Ipv4Header GetHeader() const;
282 
287  static TypeId GetTypeId();
289  ~Icmpv4TimeExceeded() override;
290  TypeId GetInstanceTypeId() const override;
291  uint32_t GetSerializedSize() const override;
292  void Serialize(Buffer::Iterator start) const override;
293  uint32_t Deserialize(Buffer::Iterator start) override;
294  void Print(std::ostream& os) const override;
295 
296  private:
298  uint8_t m_data[8];
299 };
300 
301 } // namespace ns3
302 
303 #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:175
Ipv4Header m_header
carried IPv4 header
Definition: icmpv4.h:240
uint16_t GetNextHopMtu() const
Get the next hop MTU.
Definition: icmpv4.cc:331
uint16_t m_nextHopMtu
next hop MTU
Definition: icmpv4.h:239
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:181
static TypeId GetTypeId()
Get ICMP type.
Definition: icmpv4.cc:303
uint8_t m_data[8]
carried data
Definition: icmpv4.h:241
void Print(std::ostream &os) const override
Definition: icmpv4.cc:412
ICMP Echo header.
Definition: icmpv4.h:110
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:163
uint16_t m_sequence
sequence number
Definition: icmpv4.h:164
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:165
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:166
uint16_t GetSequenceNumber() const
Get the Echo sequence number.
Definition: icmpv4.cc:193
Base class for all the ICMP packet headers.
Definition: icmpv4.h:43
Type_e
ICMP type code.
Definition: icmpv4.h:49
@ ICMPV4_TIME_EXCEEDED
Definition: icmpv4.h:53
@ ICMPV4_DEST_UNREACH
Definition: icmpv4.h:51
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:101
void SetType(uint8_t type)
Set ICMP type.
Definition: icmpv4.cc:116
uint8_t m_code
ICMP code.
Definition: icmpv4.h:100
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:99
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:250
Ipv4Header m_header
carried IPv4 header
Definition: icmpv4.h:297
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:256
uint8_t m_data[8]
carried data
Definition: icmpv4.h:298
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:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t data[writeSize]