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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@cutebugs.net>
7 */
8
9#ifndef ICMPV4_L4_PROTOCOL_H
10#define ICMPV4_L4_PROTOCOL_H
11
12#include "icmpv4.h"
13#include "ip-l4-protocol.h"
14
15#include "ns3/ipv4-address.h"
16
17namespace ns3
18{
19
20class Node;
21class Ipv4Interface;
22class Ipv4Route;
23
24/**
25 * @ingroup ipv4
26 * @defgroup icmp ICMP protocol and associated headers.
27 */
28
29/**
30 * @ingroup icmp
31 *
32 * @brief This is the implementation of the ICMP protocol as
33 * described in \RFC{792}.
34 */
36{
37 public:
38 /**
39 * @brief Get the type ID.
40 * @return the object TypeId
41 */
42 static TypeId GetTypeId();
43
44 NS_DEPRECATED_3_49("Use the numbers in iana-intenernet-protocols-numbers.h instead")
45 static constexpr uint8_t PROT_NUMBER = 1; //!< ICMP protocol number (see \RFC{792})
46
48 ~Icmpv4L4Protocol() override;
49
50 /**
51 * @brief Set the node the protocol is associated with.
52 * @param node the node
53 */
54 void SetNode(Ptr<Node> node);
55
56 /**
57 * Get the protocol number
58 * @returns the protocol number
59 */
60 static uint16_t GetStaticProtocolNumber();
61
62 /**
63 * Get the protocol number
64 * @returns the protocol number
65 */
66 int GetProtocolNumber() const override;
67
68 /**
69 * @brief Receive method.
70 * @param p the packet
71 * @param header the IPv4 header
72 * @param incomingInterface the interface from which the packet is coming
73 * @returns the receive status
74 */
76 const Ipv4Header& header,
77 Ptr<Ipv4Interface> incomingInterface) override;
78
79 /**
80 * @brief Receive method.
81 * @param p the packet
82 * @param header the IPv6 header
83 * @param incomingInterface the interface from which the packet is coming
84 * @returns the receive status
85 */
87 const Ipv6Header& header,
88 Ptr<Ipv6Interface> incomingInterface) override;
89
90 /**
91 * @brief Send a Destination Unreachable - Fragmentation needed ICMP error
92 * @param header the original IP header
93 * @param orgData the original packet
94 * @param nextHopMtu the next hop MTU
95 */
97 Ptr<const Packet> orgData,
98 uint16_t nextHopMtu);
99
100 /**
101 * @brief Send a Time Exceeded ICMP error
102 * @param header the original IP header
103 * @param orgData the original packet
104 * @param isFragment true if the opcode must be FRAGMENT_REASSEMBLY
105 */
106 void SendTimeExceededTtl(Ipv4Header header, Ptr<const Packet> orgData, bool isFragment);
107
108 /**
109 * @brief Send a Time Exceeded ICMP error
110 * @param header the original IP header
111 * @param orgData the original packet
112 */
113 void SendDestUnreachPort(Ipv4Header header, Ptr<const Packet> orgData);
114
115 /**
116 * @brief Send a Destination Unreachable (network unreachable) ICMP error.
117 *
118 * Used when a router has no route to forward a datagram (see @issueid{825}).
119 *
120 * @param header the original IP header
121 * @param orgData the original packet
122 */
123 void SendDestUnreachNetwork(Ipv4Header header, Ptr<const Packet> orgData);
124
125 // From IpL4Protocol
128 // From IpL4Protocol
131
132 protected:
133 /*
134 * This function will notify other components connected to the node that a new stack member is
135 * now connected This will be used to notify Layer 3 protocol of layer 4 protocol stack to
136 * connect them together.
137 */
138 void NotifyNewAggregate() override;
139
140 private:
141 /**
142 * @brief Handles an incoming ICMP Echo packet
143 * @param p the packet
144 * @param header the IP header
145 * @param source the source address
146 * @param destination the destination address
147 * @param tos the type of service
148 */
149 void HandleEcho(Ptr<Packet> p,
150 Icmpv4Header header,
151 Ipv4Address source,
152 Ipv4Address destination,
153 uint8_t tos);
154 /**
155 * @brief Handles an incoming ICMP Destination Unreachable packet
156 * @param p the packet
157 * @param header the IP header
158 * @param source the source address
159 * @param destination the destination address
160 */
162 Icmpv4Header header,
163 Ipv4Address source,
164 Ipv4Address destination);
165 /**
166 * @brief Handles an incoming ICMP Time Exceeded packet
167 * @param p the packet
168 * @param icmp the ICMP header
169 * @param source the source address
170 * @param destination the destination address
171 */
173 Icmpv4Header icmp,
174 Ipv4Address source,
175 Ipv4Address destination);
176 /**
177 * @brief Send an ICMP Destination Unreachable packet
178 *
179 * @param header the original IP header
180 * @param orgData the original packet
181 * @param code the ICMP code
182 * @param nextHopMtu the next hop MTU
183 */
184 void SendDestUnreach(Ipv4Header header,
185 Ptr<const Packet> orgData,
186 uint8_t code,
187 uint16_t nextHopMtu);
188 /**
189 * @brief Send a generic ICMP packet
190 *
191 * @param packet the packet
192 * @param dest the destination
193 * @param type the ICMP type
194 * @param code the ICMP code
195 */
196 void SendMessage(Ptr<Packet> packet, Ipv4Address dest, uint8_t type, uint8_t code);
197 /**
198 * @brief Send a generic ICMP packet
199 *
200 * @param packet the packet
201 * @param source the source
202 * @param dest the destination
203 * @param type the ICMP type
204 * @param code the ICMP code
205 * @param route the route to be used
206 */
207 void SendMessage(Ptr<Packet> packet,
208 Ipv4Address source,
209 Ipv4Address dest,
210 uint8_t type,
211 uint8_t code,
212 Ptr<Ipv4Route> route);
213 /**
214 * @brief Forward the message to an L4 protocol
215 *
216 * @param source the source
217 * @param icmp the ICMP header
218 * @param info info data (e.g., the target MTU)
219 * @param ipHeader the IP header carried by ICMP
220 * @param payload payload chunk carried by ICMP
221 */
222 void Forward(Ipv4Address source,
223 Icmpv4Header icmp,
224 uint32_t info,
225 Ipv4Header ipHeader,
226 const uint8_t payload[8]);
227
228 void DoDispose() override;
229
230 Ptr<Node> m_node; //!< the node this protocol is associated with
231 IpL4Protocol::DownTargetCallback m_downTarget; //!< callback to Ipv4::Send
232};
233
234} // namespace ns3
235
236#endif /* ICMPV4_L4_PROTOCOL_H */
Base class for all the ICMP packet headers.
Definition icmpv4.h:32
void SendDestUnreachNetwork(Ipv4Header header, Ptr< const Packet > orgData)
Send a Destination Unreachable (network unreachable) ICMP error.
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.
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.
static constexpr uint8_t PROT_NUMBER
ICMP protocol number (see RFC 792).
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.
Callback< void, Ptr< Packet >, Ipv4Address, Ipv4Address, uint8_t, Ptr< Ipv4Route > > DownTargetCallback
callback to send packets over IPv4
Callback< void, Ptr< Packet >, Ipv6Address, Ipv6Address, uint8_t, Ptr< Ipv6Route > > DownTargetCallback6
callback to send packets over IPv6
RxStatus
Rx status codes.
Ipv4 addresses are stored in host order in this class.
Packet header for IPv4.
Definition ipv4-header.h:23
The IPv4 representation of a network interface.
IPv4 route cache entry (similar to Linux struct rtable).
Definition ipv4-route.h:31
Packet header for IPv6.
Definition ipv6-header.h:24
The IPv6 representation of a network interface.
A network Node.
Definition node.h:46
network packets
Definition packet.h:228
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
a unique identifier for an interface.
Definition type-id.h:50
#define NS_DEPRECATED_3_49(msg)
Tag for things deprecated in version ns-3.49.
Definition deprecated.h:91
Every class exported by the ns3 library is enclosed in the ns3 namespace.
#define private