A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
icmpv4-l4-protocol.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@cutebugs.net>
18 */
19
20#ifndef ICMPV4_L4_PROTOCOL_H
21#define ICMPV4_L4_PROTOCOL_H
22
23#include "icmpv4.h"
24#include "ip-l4-protocol.h"
25
26#include "ns3/ipv4-address.h"
27
28namespace ns3
29{
30
31class Node;
32class Ipv4Interface;
33class Ipv4Route;
34
35/**
36 * \ingroup ipv4
37 * \defgroup icmp ICMP protocol and associated headers.
38 */
39
40/**
41 * \ingroup icmp
42 *
43 * \brief This is the implementation of the ICMP protocol as
44 * described in \RFC{792}.
45 */
47{
48 public:
49 /**
50 * \brief Get the type ID.
51 * \return the object TypeId
52 */
53 static TypeId GetTypeId();
54 static const uint8_t PROT_NUMBER; //!< ICMP protocol number (0x1)
55
57 ~Icmpv4L4Protocol() override;
58
59 /**
60 * \brief Set the node the protocol is associated with.
61 * \param node the node
62 */
63 void SetNode(Ptr<Node> node);
64
65 /**
66 * Get the protocol number
67 * \returns the protocol number
68 */
69 static uint16_t GetStaticProtocolNumber();
70
71 /**
72 * Get the protocol number
73 * \returns the protocol number
74 */
75 int GetProtocolNumber() const override;
76
77 /**
78 * \brief Receive method.
79 * \param p the packet
80 * \param header the IPv4 header
81 * \param incomingInterface the interface from which the packet is coming
82 * \returns the receive status
83 */
85 const Ipv4Header& header,
86 Ptr<Ipv4Interface> incomingInterface) override;
87
88 /**
89 * \brief Receive method.
90 * \param p the packet
91 * \param header the IPv6 header
92 * \param incomingInterface the interface from which the packet is coming
93 * \returns the receive status
94 */
96 const Ipv6Header& header,
97 Ptr<Ipv6Interface> incomingInterface) override;
98
99 /**
100 * \brief Send a Destination Unreachable - Fragmentation needed ICMP error
101 * \param header the original IP header
102 * \param orgData the original packet
103 * \param nextHopMtu the next hop MTU
104 */
106 Ptr<const Packet> orgData,
107 uint16_t nextHopMtu);
108
109 /**
110 * \brief Send a Time Exceeded ICMP error
111 * \param header the original IP header
112 * \param orgData the original packet
113 * \param isFragment true if the opcode must be FRAGMENT_REASSEMBLY
114 */
115 void SendTimeExceededTtl(Ipv4Header header, Ptr<const Packet> orgData, bool isFragment);
116
117 /**
118 * \brief Send a Time Exceeded ICMP error
119 * \param header the original IP header
120 * \param orgData the original packet
121 */
123
124 // From IpL4Protocol
127 // From IpL4Protocol
130
131 protected:
132 /*
133 * This function will notify other components connected to the node that a new stack member is
134 * now connected This will be used to notify Layer 3 protocol of layer 4 protocol stack to
135 * connect them together.
136 */
137 void NotifyNewAggregate() override;
138
139 private:
140 /**
141 * \brief Handles an incoming ICMP Echo packet
142 * \param p the packet
143 * \param header the IP header
144 * \param source the source address
145 * \param destination the destination address
146 * \param tos the type of service
147 */
148 void HandleEcho(Ptr<Packet> p,
149 Icmpv4Header header,
150 Ipv4Address source,
151 Ipv4Address destination,
152 uint8_t tos);
153 /**
154 * \brief Handles an incoming ICMP Destination Unreachable packet
155 * \param p the packet
156 * \param header the IP header
157 * \param source the source address
158 * \param destination the destination address
159 */
161 Icmpv4Header header,
162 Ipv4Address source,
163 Ipv4Address destination);
164 /**
165 * \brief Handles an incoming ICMP Time Exceeded packet
166 * \param p the packet
167 * \param icmp the ICMP header
168 * \param source the source address
169 * \param destination the destination address
170 */
172 Icmpv4Header icmp,
173 Ipv4Address source,
174 Ipv4Address destination);
175 /**
176 * \brief Send an ICMP Destination Unreachable packet
177 *
178 * \param header the original IP header
179 * \param orgData the original packet
180 * \param code the ICMP code
181 * \param nextHopMtu the next hop MTU
182 */
183 void SendDestUnreach(Ipv4Header header,
184 Ptr<const Packet> orgData,
185 uint8_t code,
186 uint16_t nextHopMtu);
187 /**
188 * \brief Send a generic ICMP packet
189 *
190 * \param packet the packet
191 * \param dest the destination
192 * \param type the ICMP type
193 * \param code the ICMP code
194 */
195 void SendMessage(Ptr<Packet> packet, Ipv4Address dest, uint8_t type, uint8_t code);
196 /**
197 * \brief Send a generic ICMP packet
198 *
199 * \param packet the packet
200 * \param source the source
201 * \param dest the destination
202 * \param type the ICMP type
203 * \param code the ICMP code
204 * \param route the route to be used
205 */
206 void SendMessage(Ptr<Packet> packet,
207 Ipv4Address source,
208 Ipv4Address dest,
209 uint8_t type,
210 uint8_t code,
211 Ptr<Ipv4Route> route);
212 /**
213 * \brief Forward the message to an L4 protocol
214 *
215 * \param source the source
216 * \param icmp the ICMP header
217 * \param info info data (e.g., the target MTU)
218 * \param ipHeader the IP header carried by ICMP
219 * \param payload payload chunk carried by ICMP
220 */
221 void Forward(Ipv4Address source,
222 Icmpv4Header icmp,
223 uint32_t info,
224 Ipv4Header ipHeader,
225 const uint8_t payload[8]);
226
227 void DoDispose() override;
228
229 Ptr<Node> m_node; //!< the node this protocol is associated with
231};
232
233} // namespace ns3
234
235#endif /* ICMPV4_L4_PROTOCOL_H */
Base class for all the ICMP packet headers.
Definition: icmpv4.h:43
This is the implementation of the ICMP protocol as described in RFC 792.
void SetDownTarget6(IpL4Protocol::DownTargetCallback6 cb) override
This method allows a caller to set the current down target callback set for this L4 protocol (IPv6 ca...
Ptr< Node > m_node
the node this protocol is associated with
void SendTimeExceededTtl(Ipv4Header header, Ptr< const Packet > orgData, bool isFragment)
Send a Time Exceeded ICMP error.
static const uint8_t PROT_NUMBER
ICMP protocol number (0x1)
void SetDownTarget(IpL4Protocol::DownTargetCallback cb) override
This method allows a caller to set the current down target callback set for this L4 protocol (IPv4 ca...
void HandleEcho(Ptr< Packet > p, Icmpv4Header header, Ipv4Address source, Ipv4Address destination, uint8_t tos)
Handles an incoming ICMP Echo packet.
void SendDestUnreach(Ipv4Header header, Ptr< const Packet > orgData, uint8_t code, uint16_t nextHopMtu)
Send an ICMP Destination Unreachable packet.
void DoDispose() override
Destructor implementation.
IpL4Protocol::DownTargetCallback6 GetDownTarget6() const override
This method allows a caller to get the current down target callback set for this L4 protocol (IPv6 ca...
static TypeId GetTypeId()
Get the type ID.
void SetNode(Ptr< Node > node)
Set the node the protocol is associated with.
void SendDestUnreachPort(Ipv4Header header, Ptr< const Packet > orgData)
Send a Time Exceeded ICMP error.
static uint16_t GetStaticProtocolNumber()
Get the protocol number.
IpL4Protocol::RxStatus Receive(Ptr< Packet > p, const Ipv4Header &header, Ptr< Ipv4Interface > incomingInterface) override
Receive method.
IpL4Protocol::DownTargetCallback GetDownTarget() const override
This method allows a caller to get the current down target callback set for this L4 protocol (IPv4 ca...
void NotifyNewAggregate() override
Notify all Objects aggregated to this one of a new Object being aggregated.
void HandleTimeExceeded(Ptr< Packet > p, Icmpv4Header icmp, Ipv4Address source, Ipv4Address destination)
Handles an incoming ICMP Time Exceeded packet.
IpL4Protocol::DownTargetCallback m_downTarget
callback to Ipv4::Send
void SendDestUnreachFragNeeded(Ipv4Header header, Ptr< const Packet > orgData, uint16_t nextHopMtu)
Send a Destination Unreachable - Fragmentation needed ICMP error.
void SendMessage(Ptr< Packet > packet, Ipv4Address dest, uint8_t type, uint8_t code)
Send a generic ICMP packet.
void HandleDestUnreach(Ptr< Packet > p, Icmpv4Header header, Ipv4Address source, Ipv4Address destination)
Handles an incoming ICMP Destination Unreachable packet.
int GetProtocolNumber() const override
Get the protocol number.
void Forward(Ipv4Address source, Icmpv4Header icmp, uint32_t info, Ipv4Header ipHeader, const uint8_t payload[8])
Forward the message to an L4 protocol.
L4 Protocol abstract base class.
RxStatus
Rx status codes.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Packet header for IPv4.
Definition: ipv4-header.h:34
Packet header for IPv6.
Definition: ipv6-header.h:35
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.