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 static constexpr uint8_t PROT_NUMBER = 1; //!< ICMP protocol number (see \RFC{792})
45
47 ~Icmpv4L4Protocol() override;
48
49 /**
50 * @brief Set the node the protocol is associated with.
51 * @param node the node
52 */
53 void SetNode(Ptr<Node> node);
54
55 /**
56 * Get the protocol number
57 * @returns the protocol number
58 */
59 static uint16_t GetStaticProtocolNumber();
60
61 /**
62 * Get the protocol number
63 * @returns the protocol number
64 */
65 int GetProtocolNumber() const override;
66
67 /**
68 * @brief Receive method.
69 * @param p the packet
70 * @param header the IPv4 header
71 * @param incomingInterface the interface from which the packet is coming
72 * @returns the receive status
73 */
75 const Ipv4Header& header,
76 Ptr<Ipv4Interface> incomingInterface) override;
77
78 /**
79 * @brief Receive method.
80 * @param p the packet
81 * @param header the IPv6 header
82 * @param incomingInterface the interface from which the packet is coming
83 * @returns the receive status
84 */
86 const Ipv6Header& header,
87 Ptr<Ipv6Interface> incomingInterface) override;
88
89 /**
90 * @brief Send a Destination Unreachable - Fragmentation needed ICMP error
91 * @param header the original IP header
92 * @param orgData the original packet
93 * @param nextHopMtu the next hop MTU
94 */
96 Ptr<const Packet> orgData,
97 uint16_t nextHopMtu);
98
99 /**
100 * @brief Send a Time Exceeded ICMP error
101 * @param header the original IP header
102 * @param orgData the original packet
103 * @param isFragment true if the opcode must be FRAGMENT_REASSEMBLY
104 */
105 void SendTimeExceededTtl(Ipv4Header header, Ptr<const Packet> orgData, bool isFragment);
106
107 /**
108 * @brief Send a Time Exceeded ICMP error
109 * @param header the original IP header
110 * @param orgData the original packet
111 */
113
114 // From IpL4Protocol
117 // From IpL4Protocol
120
121 protected:
122 /*
123 * This function will notify other components connected to the node that a new stack member is
124 * now connected This will be used to notify Layer 3 protocol of layer 4 protocol stack to
125 * connect them together.
126 */
127 void NotifyNewAggregate() override;
128
129 private:
130 /**
131 * @brief Handles an incoming ICMP Echo packet
132 * @param p the packet
133 * @param header the IP header
134 * @param source the source address
135 * @param destination the destination address
136 * @param tos the type of service
137 */
138 void HandleEcho(Ptr<Packet> p,
139 Icmpv4Header header,
140 Ipv4Address source,
141 Ipv4Address destination,
142 uint8_t tos);
143 /**
144 * @brief Handles an incoming ICMP Destination Unreachable packet
145 * @param p the packet
146 * @param header the IP header
147 * @param source the source address
148 * @param destination the destination address
149 */
151 Icmpv4Header header,
152 Ipv4Address source,
153 Ipv4Address destination);
154 /**
155 * @brief Handles an incoming ICMP Time Exceeded packet
156 * @param p the packet
157 * @param icmp the ICMP header
158 * @param source the source address
159 * @param destination the destination address
160 */
162 Icmpv4Header icmp,
163 Ipv4Address source,
164 Ipv4Address destination);
165 /**
166 * @brief Send an ICMP Destination Unreachable packet
167 *
168 * @param header the original IP header
169 * @param orgData the original packet
170 * @param code the ICMP code
171 * @param nextHopMtu the next hop MTU
172 */
173 void SendDestUnreach(Ipv4Header header,
174 Ptr<const Packet> orgData,
175 uint8_t code,
176 uint16_t nextHopMtu);
177 /**
178 * @brief Send a generic ICMP packet
179 *
180 * @param packet the packet
181 * @param dest the destination
182 * @param type the ICMP type
183 * @param code the ICMP code
184 */
185 void SendMessage(Ptr<Packet> packet, Ipv4Address dest, uint8_t type, uint8_t code);
186 /**
187 * @brief Send a generic ICMP packet
188 *
189 * @param packet the packet
190 * @param source the source
191 * @param dest the destination
192 * @param type the ICMP type
193 * @param code the ICMP code
194 * @param route the route to be used
195 */
196 void SendMessage(Ptr<Packet> packet,
197 Ipv4Address source,
198 Ipv4Address dest,
199 uint8_t type,
200 uint8_t code,
201 Ptr<Ipv4Route> route);
202 /**
203 * @brief Forward the message to an L4 protocol
204 *
205 * @param source the source
206 * @param icmp the ICMP header
207 * @param info info data (e.g., the target MTU)
208 * @param ipHeader the IP header carried by ICMP
209 * @param payload payload chunk carried by ICMP
210 */
211 void Forward(Ipv4Address source,
212 Icmpv4Header icmp,
213 uint32_t info,
214 Ipv4Header ipHeader,
215 const uint8_t payload[8]);
216
217 void DoDispose() override;
218
219 Ptr<Node> m_node; //!< the node this protocol is associated with
221};
222
223} // namespace ns3
224
225#endif /* ICMPV4_L4_PROTOCOL_H */
Base class for all the ICMP packet headers.
Definition icmpv4.h:32
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.
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.
RxStatus
Rx status codes.
Ipv4 addresses are stored in host order in this class.
Packet header for IPv4.
Definition ipv4-header.h:23
Packet header for IPv6.
Definition ipv6-header.h:24
Smart pointer class similar to boost::intrusive_ptr.
a unique identifier for an interface.
Definition type-id.h:49
Every class exported by the ns3 library is enclosed in the ns3 namespace.