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