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 * 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
30namespace ns3
31{
32
33class Packet;
34
35/**
36 * \ingroup icmp
37 *
38 * \brief Base class for all the ICMP packet headers.
39 *
40 * This header is the common part in all the ICMP packets.
41 */
42class Icmpv4Header : public Header
43{
44 public:
45 /**
46 * ICMP type code.
47 */
48 enum Type_e
49 {
54 };
55
56 /**
57 * Enables ICMP Checksum calculation
58 */
59 void EnableChecksum();
60
61 /**
62 * Set ICMP type
63 * \param type the ICMP type
64 */
65 void SetType(uint8_t type);
66
67 /**
68 * Set ICMP code
69 * \param code the ICMP code
70 */
71 void SetCode(uint8_t code);
72
73 /**
74 * Get ICMP type
75 * \returns the ICMP type
76 */
77 uint8_t GetType() const;
78 /**
79 * Get ICMP code
80 * \returns the ICMP code
81 */
82 uint8_t GetCode() const;
83
84 /**
85 * \brief Get the type ID.
86 * \return the object TypeId
87 */
88 static TypeId GetTypeId();
90 ~Icmpv4Header() override;
91
92 TypeId GetInstanceTypeId() const override;
93 uint32_t GetSerializedSize() const override;
94 void Serialize(Buffer::Iterator start) const override;
96 void Print(std::ostream& os) const override;
97
98 private:
99 uint8_t m_type; //!< ICMP type
100 uint8_t m_code; //!< ICMP code
101 bool m_calcChecksum; //!< true if checksum is calculated
102};
103
104/**
105 * \ingroup icmp
106 *
107 * \brief ICMP Echo header
108 */
109class Icmpv4Echo : public Header
110{
111 public:
112 /**
113 * \brief Set the Echo identifier
114 * \param id the identifier
115 */
116 void SetIdentifier(uint16_t id);
117 /**
118 * \brief Set the Echo sequence number
119 * \param seq the sequence number
120 */
121 void SetSequenceNumber(uint16_t seq);
122 /**
123 * \brief Set the Echo data
124 * \param data the data
125 */
127 /**
128 * \brief Get the Echo identifier
129 * \returns the identifier
130 */
131 uint16_t GetIdentifier() const;
132 /**
133 * \brief Get the Echo sequence number
134 * \returns the sequence number
135 */
136 uint16_t GetSequenceNumber() const;
137 /**
138 * \brief Get the Echo data size
139 * \returns the data size
140 */
141 uint32_t GetDataSize() const;
142 /**
143 * \brief Get the Echo data
144 * \param payload the data (filled)
145 * \returns the data length
146 */
147 uint32_t GetData(uint8_t payload[]) const;
148
149 /**
150 * Get ICMP type
151 * \returns the ICMP type
152 */
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; //!< identifier
164 uint16_t m_sequence; //!< sequence number
165 uint8_t* m_data; //!< data
166 uint32_t m_dataSize; //!< data size
167};
168
169/**
170 * \ingroup icmp
171 *
172 * \brief ICMP Destination Unreachable header
173 */
175{
176 public:
177 /**
178 * ICMP error code : Destination Unreachable
179 */
181 {
188 };
189
190 /**
191 * Get ICMP type
192 * \returns the ICMP type
193 */
194 static TypeId GetTypeId();
197
198 /**
199 * \brief Set the next hop MTU
200 * \param mtu the MTU
201 */
202 void SetNextHopMtu(uint16_t mtu);
203 /**
204 * \brief Get the next hop MTU
205 * \returns the MTU
206 */
207 uint16_t GetNextHopMtu() const;
208
209 /**
210 * \brief Set the ICMP carried data
211 * \param data the data
212 */
214 /**
215 * \brief Set the ICMP carried IPv4 header
216 * \param header the header
217 */
218 void SetHeader(Ipv4Header header);
219
220 /**
221 * \brief Get the ICMP carried data
222 * \param payload the data (filled)
223 */
224 void GetData(uint8_t payload[8]) const;
225 /**
226 * \brief Get the ICMP carried IPv4 header
227 * \returns the header
228 */
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; //!< next hop MTU
240 Ipv4Header m_header; //!< carried IPv4 header
241 uint8_t m_data[8]; //!< carried data
242};
243
244/**
245 * \ingroup icmp
246 *
247 * \brief ICMP Time Exceeded header
248 */
250{
251 public:
252 /**
253 * \brief ICMP error code : Time Exceeded
254 */
256 {
259 };
260
261 /**
262 * \brief Get the ICMP carried data
263 * \param data the data
264 */
266 /**
267 * \brief Set the ICMP carried IPv4 header
268 * \param header the header
269 */
270 void SetHeader(Ipv4Header header);
271
272 /**
273 * \brief Get the ICMP carried data
274 * \param payload the data (filled)
275 */
276 void GetData(uint8_t payload[8]) const;
277 /**
278 * \brief Get the ICMP carried IPv4 header
279 * \returns the header
280 */
281 Ipv4Header GetHeader() const;
282
283 /**
284 * Get ICMP type
285 * \returns the ICMP type
286 */
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:
297 Ipv4Header m_header; //!< carried IPv4 header
298 uint8_t m_data[8]; //!< carried data
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
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
uint32_t Deserialize(Buffer::Iterator start) override
Definition: icmpv4.cc:396
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
uint32_t Deserialize(Buffer::Iterator start) override
Definition: icmpv4.cc:269
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
uint32_t Deserialize(Buffer::Iterator start) override
Definition: icmpv4.cc:99
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
uint32_t Deserialize(Buffer::Iterator start) override
Definition: icmpv4.cc:513
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
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
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]