A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
icmpv4.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8
9#ifndef ICMPV4_H
10#define ICMPV4_H
11
12#include "ipv4-header.h"
13
14#include "ns3/header.h"
15#include "ns3/ptr.h"
16
17#include <stdint.h>
18
19namespace ns3
20{
21
22class Packet;
23
24/**
25 * \ingroup icmp
26 *
27 * \brief Base class for all the ICMP packet headers.
28 *
29 * This header is the common part in all the ICMP packets.
30 */
31class Icmpv4Header : public Header
32{
33 public:
34 /**
35 * ICMP type code.
36 */
44
45 /**
46 * Enables ICMP Checksum calculation
47 */
48 void EnableChecksum();
49
50 /**
51 * Set ICMP type
52 * \param type the ICMP type
53 */
54 void SetType(uint8_t type);
55
56 /**
57 * Set ICMP code
58 * \param code the ICMP code
59 */
60 void SetCode(uint8_t code);
61
62 /**
63 * Get ICMP type
64 * \returns the ICMP type
65 */
66 uint8_t GetType() const;
67 /**
68 * Get ICMP code
69 * \returns the ICMP code
70 */
71 uint8_t GetCode() const;
72
73 /**
74 * \brief Get the type ID.
75 * \return the object TypeId
76 */
77 static TypeId GetTypeId();
79 ~Icmpv4Header() override;
80
81 TypeId GetInstanceTypeId() const override;
82 uint32_t GetSerializedSize() const override;
83 void Serialize(Buffer::Iterator start) const override;
85 void Print(std::ostream& os) const override;
86
87 private:
88 uint8_t m_type; //!< ICMP type
89 uint8_t m_code; //!< ICMP code
90 bool m_calcChecksum; //!< true if checksum is calculated
91};
92
93/**
94 * \ingroup icmp
95 *
96 * \brief ICMP Echo header
97 */
98class Icmpv4Echo : public Header
99{
100 public:
101 /**
102 * \brief Set the Echo identifier
103 * \param id the identifier
104 */
105 void SetIdentifier(uint16_t id);
106 /**
107 * \brief Set the Echo sequence number
108 * \param seq the sequence number
109 */
110 void SetSequenceNumber(uint16_t seq);
111 /**
112 * \brief Set the Echo data
113 * \param data the data
114 */
116 /**
117 * \brief Get the Echo identifier
118 * \returns the identifier
119 */
120 uint16_t GetIdentifier() const;
121 /**
122 * \brief Get the Echo sequence number
123 * \returns the sequence number
124 */
125 uint16_t GetSequenceNumber() const;
126 /**
127 * \brief Get the Echo data size
128 * \returns the data size
129 */
130 uint32_t GetDataSize() const;
131 /**
132 * \brief Get the Echo data
133 * \param payload the data (filled)
134 * \returns the data length
135 */
136 uint32_t GetData(uint8_t payload[]) const;
137
138 /**
139 * Get ICMP type
140 * \returns the ICMP type
141 */
142 static TypeId GetTypeId();
143 Icmpv4Echo();
144 ~Icmpv4Echo() override;
145 TypeId GetInstanceTypeId() const override;
146 uint32_t GetSerializedSize() const override;
147 void Serialize(Buffer::Iterator start) const override;
148 uint32_t Deserialize(Buffer::Iterator start) override;
149 void Print(std::ostream& os) const override;
150
151 private:
152 uint16_t m_identifier; //!< identifier
153 uint16_t m_sequence; //!< sequence number
154 uint8_t* m_data; //!< data
155 uint32_t m_dataSize; //!< data size
156};
157
158/**
159 * \ingroup icmp
160 *
161 * \brief ICMP Destination Unreachable header
162 */
164{
165 public:
166 /**
167 * ICMP error code : Destination Unreachable
168 */
178
179 /**
180 * Get ICMP type
181 * \returns the ICMP type
182 */
183 static TypeId GetTypeId();
186
187 /**
188 * \brief Set the next hop MTU
189 * \param mtu the MTU
190 */
191 void SetNextHopMtu(uint16_t mtu);
192 /**
193 * \brief Get the next hop MTU
194 * \returns the MTU
195 */
196 uint16_t GetNextHopMtu() const;
197
198 /**
199 * \brief Set the ICMP carried data
200 * \param data the data
201 */
203 /**
204 * \brief Set the ICMP carried IPv4 header
205 * \param header the header
206 */
207 void SetHeader(Ipv4Header header);
208
209 /**
210 * \brief Get the ICMP carried data
211 * \param payload the data (filled)
212 */
213 void GetData(uint8_t payload[8]) const;
214 /**
215 * \brief Get the ICMP carried IPv4 header
216 * \returns the header
217 */
218 Ipv4Header GetHeader() const;
219
220 private:
221 TypeId GetInstanceTypeId() const override;
222 uint32_t GetSerializedSize() const override;
223 void Serialize(Buffer::Iterator start) const override;
224 uint32_t Deserialize(Buffer::Iterator start) override;
225 void Print(std::ostream& os) const override;
226
227 private:
228 uint16_t m_nextHopMtu; //!< next hop MTU
229 Ipv4Header m_header; //!< carried IPv4 header
230 uint8_t m_data[8]; //!< carried data
231};
232
233/**
234 * \ingroup icmp
235 *
236 * \brief ICMP Time Exceeded header
237 */
239{
240 public:
241 /**
242 * \brief ICMP error code : Time Exceeded
243 */
249
250 /**
251 * \brief Get the ICMP carried data
252 * \param data the data
253 */
255 /**
256 * \brief Set the ICMP carried IPv4 header
257 * \param header the header
258 */
259 void SetHeader(Ipv4Header header);
260
261 /**
262 * \brief Get the ICMP carried data
263 * \param payload the data (filled)
264 */
265 void GetData(uint8_t payload[8]) const;
266 /**
267 * \brief Get the ICMP carried IPv4 header
268 * \returns the header
269 */
270 Ipv4Header GetHeader() const;
271
272 /**
273 * Get ICMP type
274 * \returns the ICMP type
275 */
276 static TypeId GetTypeId();
278 ~Icmpv4TimeExceeded() override;
279 TypeId GetInstanceTypeId() const override;
280 uint32_t GetSerializedSize() const override;
281 void Serialize(Buffer::Iterator start) const override;
282 uint32_t Deserialize(Buffer::Iterator start) override;
283 void Print(std::ostream& os) const override;
284
285 private:
286 Ipv4Header m_header; //!< carried IPv4 header
287 uint8_t m_data[8]; //!< carried data
288};
289
290} // namespace ns3
291
292#endif /* ICMPV4_H */
iterator in a Buffer instance
Definition buffer.h:89
Protocol header serialization and deserialization.
Definition header.h:33
ICMP Destination Unreachable header.
Definition icmpv4.h:164
Ipv4Header m_header
carried IPv4 header
Definition icmpv4.h:229
uint16_t GetNextHopMtu() const
Get the next hop MTU.
Definition icmpv4.cc:320
uint16_t m_nextHopMtu
next hop MTU
Definition icmpv4.h:228
Ipv4Header GetHeader() const
Get the ICMP carried IPv4 header.
Definition icmpv4.cc:348
void GetData(uint8_t payload[8]) const
Get the ICMP carried data.
Definition icmpv4.cc:341
void SetNextHopMtu(uint16_t mtu)
Set the next hop MTU.
Definition icmpv4.cc:313
uint32_t Deserialize(Buffer::Iterator start) override
Definition icmpv4.cc:385
void Serialize(Buffer::Iterator start) const override
Definition icmpv4.cc:373
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition icmpv4.cc:359
uint32_t GetSerializedSize() const override
Definition icmpv4.cc:366
void SetHeader(Ipv4Header header)
Set the ICMP carried IPv4 header.
Definition icmpv4.cc:334
void SetData(Ptr< const Packet > data)
Set the ICMP carried data.
Definition icmpv4.cc:327
ErrorDestinationUnreachable_e
ICMP error code : Destination Unreachable.
Definition icmpv4.h:170
static TypeId GetTypeId()
Get ICMP type.
Definition icmpv4.cc:292
uint8_t m_data[8]
carried data
Definition icmpv4.h:230
void Print(std::ostream &os) const override
Definition icmpv4.cc:401
ICMP Echo header.
Definition icmpv4.h:99
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition icmpv4.cc:235
void Print(std::ostream &os) const override
Definition icmpv4.cc:278
uint16_t m_identifier
identifier
Definition icmpv4.h:152
uint16_t m_sequence
sequence number
Definition icmpv4.h:153
uint32_t GetData(uint8_t payload[]) const
Get the Echo data.
Definition icmpv4.cc:196
void SetIdentifier(uint16_t id)
Set the Echo identifier.
Definition icmpv4.cc:139
void SetData(Ptr< const Packet > data)
Set the Echo data.
Definition icmpv4.cc:153
uint32_t GetSerializedSize() const override
Definition icmpv4.cc:242
uint32_t Deserialize(Buffer::Iterator start) override
Definition icmpv4.cc:258
uint16_t GetIdentifier() const
Get the Echo identifier.
Definition icmpv4.cc:175
void Serialize(Buffer::Iterator start) const override
Definition icmpv4.cc:249
~Icmpv4Echo() override
Definition icmpv4.cc:226
static TypeId GetTypeId()
Get ICMP type.
Definition icmpv4.cc:204
uint8_t * m_data
data
Definition icmpv4.h:154
void SetSequenceNumber(uint16_t seq)
Set the Echo sequence number.
Definition icmpv4.cc:146
uint32_t GetDataSize() const
Get the Echo data size.
Definition icmpv4.cc:189
uint32_t m_dataSize
data size
Definition icmpv4.h:155
uint16_t GetSequenceNumber() const
Get the Echo sequence number.
Definition icmpv4.cc:182
Base class for all the ICMP packet headers.
Definition icmpv4.h:32
Type_e
ICMP type code.
Definition icmpv4.h:38
void SetCode(uint8_t code)
Set ICMP code.
Definition icmpv4.cc:112
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition icmpv4.cc:56
uint32_t Deserialize(Buffer::Iterator start) override
Definition icmpv4.cc:88
bool m_calcChecksum
true if checksum is calculated
Definition icmpv4.h:90
void SetType(uint8_t type)
Set ICMP type.
Definition icmpv4.cc:105
uint8_t m_code
ICMP code.
Definition icmpv4.h:89
void EnableChecksum()
Enables ICMP Checksum calculation.
Definition icmpv4.cc:49
void Print(std::ostream &os) const override
Definition icmpv4.cc:98
uint8_t m_type
ICMP type.
Definition icmpv4.h:88
static TypeId GetTypeId()
Get the type ID.
Definition icmpv4.cc:26
uint8_t GetCode() const
Get ICMP code.
Definition icmpv4.cc:126
uint8_t GetType() const
Get ICMP type.
Definition icmpv4.cc:119
uint32_t GetSerializedSize() const override
Definition icmpv4.cc:63
~Icmpv4Header() override
Definition icmpv4.cc:43
void Serialize(Buffer::Iterator start) const override
Definition icmpv4.cc:70
ICMP Time Exceeded header.
Definition icmpv4.h:239
uint32_t Deserialize(Buffer::Iterator start) override
Definition icmpv4.cc:502
Ipv4Header m_header
carried IPv4 header
Definition icmpv4.h:286
Ipv4Header GetHeader() const
Get the ICMP carried IPv4 header.
Definition icmpv4.cc:465
void SetHeader(Ipv4Header header)
Set the ICMP carried IPv4 header.
Definition icmpv4.cc:451
uint32_t GetSerializedSize() const override
Definition icmpv4.cc:484
void GetData(uint8_t payload[8]) const
Get the ICMP carried data.
Definition icmpv4.cc:458
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition icmpv4.cc:477
void Serialize(Buffer::Iterator start) const override
Definition icmpv4.cc:491
ErrorTimeExceeded_e
ICMP error code : Time Exceeded.
Definition icmpv4.h:245
uint8_t m_data[8]
carried data
Definition icmpv4.h:287
static TypeId GetTypeId()
Get ICMP type.
Definition icmpv4.cc:423
void SetData(Ptr< const Packet > data)
Get the ICMP carried data.
Definition icmpv4.cc:444
~Icmpv4TimeExceeded() override
Definition icmpv4.cc:471
void Print(std::ostream &os) const override
Definition icmpv4.cc:517
Packet header for IPv4.
Definition ipv4-header.h:23
Smart pointer class similar to boost::intrusive_ptr.
a unique identifier for an interface.
Definition type-id.h:48
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t data[writeSize]