A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv4-l3-click-protocol.h
Go to the documentation of this file.
1//
2// Copyright (c) 2006 Georgia Tech Research Corporation
3//
4// SPDX-License-Identifier: GPL-2.0-only
5//
6// Author: George F. Riley <riley@ece.gatech.edu>
7// Author: Lalith Suresh <suresh.lalith@gmail.com>
8//
9
10#ifndef IPV4_L3_CLICK_PROTOCOL_H
11#define IPV4_L3_CLICK_PROTOCOL_H
12
13#include "ns3/deprecated.h"
14#include "ns3/ipv4-interface.h"
15#include "ns3/ipv4-routing-protocol.h"
16#include "ns3/ipv4.h"
17#include "ns3/log.h"
18#include "ns3/net-device.h"
19#include "ns3/packet.h"
20#include "ns3/traced-callback.h"
21
22namespace ns3
23{
24
25class Packet;
26class NetDevice;
27class Ipv4Interface;
28class Ipv4Address;
29class Ipv4Header;
31class Ipv4Route;
32class Node;
33class Socket;
35class IpL4Protocol;
37
38/**
39 * @brief Implement the Ipv4 layer specifically for Click nodes
40 * to allow a clean integration of Click.
41 * @ingroup click
42 *
43 * This is code is mostly repeated from the Ipv4L3Protocol implementation.
44 * Changes include:
45 * - A stripped down version of Send().
46 * - A stripped down version of Receive().
47 * - A public version of LocalDeliver().
48 * - Modifications to AddInterface().
49 */
50
52{
53 public:
54 /**
55 * Get Type ID.
56 *
57 * @return The type ID.
58 */
59 static TypeId GetTypeId();
60
61 /**
62 * Protocol number for Ipv4 L3 (0x0800).
63 */
64 static const uint16_t PROT_NUMBER;
65
67 ~Ipv4L3ClickProtocol() override;
68
69 void Insert(Ptr<IpL4Protocol> protocol) override;
70 void Insert(Ptr<IpL4Protocol> protocol, uint32_t interfaceIndex) override;
71
72 void Remove(Ptr<IpL4Protocol> protocol) override;
73 void Remove(Ptr<IpL4Protocol> protocol, uint32_t interfaceIndex) override;
74
75 Ptr<IpL4Protocol> GetProtocol(int protocolNumber) const override;
76 Ptr<IpL4Protocol> GetProtocol(int protocolNumber, int32_t interfaceIndex) const override;
77
79
80 /**
81 * @param ttl default ttl to use
82 *
83 * When we need to send an ipv4 packet, we use this default
84 * ttl value.
85 */
86 void SetDefaultTtl(uint8_t ttl);
87
88 /**
89 * @param packet packet to send
90 * @param source source address of packet
91 * @param destination address of packet
92 * @param protocol number of packet
93 * @param route route entry
94 *
95 * Higher-level layers call this method to send a packet
96 * to Click
97 */
98 void Send(Ptr<Packet> packet,
99 Ipv4Address source,
100 Ipv4Address destination,
101 uint8_t protocol,
102 Ptr<Ipv4Route> route) override;
103
104 /**
105 * @param packet packet to send
106 * @param ipHeader IP Header
107 * @param route route entry
108 *
109 * Higher-level layers call this method to send a packet with IPv4 Header
110 * (Intend to be used with IpHeaderInclude attribute.)
111 */
112 void SendWithHeader(Ptr<Packet> packet, Ipv4Header ipHeader, Ptr<Ipv4Route> route) override;
113
114 /**
115 * @param packet packet to send down the stack
116 * @param ifid interface to be used for sending down packet
117 *
118 * Ipv4ClickRouting calls this method to send a packet further
119 * down the stack
120 */
121 void SendDown(Ptr<Packet> packet, int ifid);
122
123 /**
124 * Lower layer calls this method to send a packet to Click
125 * @param device network device
126 * @param p the packet
127 * @param protocol protocol value
128 * @param from address of the correspondent
129 * @param to address of the destination
130 * @param packetType type of the packet
131 */
132 void Receive(Ptr<NetDevice> device,
134 uint16_t protocol,
135 const Address& from,
136 const Address& to,
137 NetDevice::PacketType packetType);
138
139 /**
140 * Ipv4ClickRouting calls this to locally deliver a packet
141 * @param p the packet
142 * @param ip The Ipv4Header of the packet
143 * @param iif The interface on which the packet was received
144 */
145 void LocalDeliver(Ptr<const Packet> p, const Ipv4Header& ip, uint32_t iif);
146
147 /**
148 * Get a pointer to the i'th Ipv4Interface
149 * @param i index of interface, pointer to which is to be returned
150 * @returns Pointer to the i'th Ipv4Interface if any.
151 */
153
154 /**
155 * Adds an Ipv4Interface to the interfaces list
156 * @param interface Pointer to the Ipv4Interface to be added
157 * @returns Index of the device which was added
158 */
160
161 /**
162 * Calls m_node = node and sets up Loopback if needed
163 * @param node Pointer to the node
164 */
165 void SetNode(Ptr<Node> node);
166
167 /**
168 * Returns the Icmpv4L4Protocol for the node
169 * @returns Icmpv4L4Protocol instance of the node
170 */
172
173 /**
174 * Sets up a Loopback device
175 */
176 void SetupLoopback();
177
178 /**
179 * Creates a raw-socket
180 * @returns Pointer to the created socket
181 */
182 Ptr<Socket> CreateRawSocket() override;
183
184 /**
185 * Deletes a particular raw socket
186 * @param socket Pointer of socket to be deleted
187 */
188 void DeleteRawSocket(Ptr<Socket> socket) override;
189
190 // functions defined in base class Ipv4
191 void SetRoutingProtocol(Ptr<Ipv4RoutingProtocol> routingProtocol) override;
193
195
196 uint32_t AddInterface(Ptr<NetDevice> device) override;
197 uint32_t GetNInterfaces() const override;
198
199 int32_t GetInterfaceForAddress(Ipv4Address addr) const override;
200 int32_t GetInterfaceForPrefix(Ipv4Address addr, Ipv4Mask mask) const override;
202 bool IsDestinationAddress(Ipv4Address address, uint32_t iif) const override;
203
204 bool AddAddress(uint32_t i, Ipv4InterfaceAddress address) override;
205 Ipv4InterfaceAddress GetAddress(uint32_t interfaceIndex, uint32_t addressIndex) const override;
206 uint32_t GetNAddresses(uint32_t interface) const override;
207 bool RemoveAddress(uint32_t interfaceIndex, uint32_t addressIndex) override;
208 bool RemoveAddress(uint32_t interfaceIndex, Ipv4Address address) override;
210 Ipv4Address dst,
212
213 void SetMetric(uint32_t i, uint16_t metric) override;
214 uint16_t GetMetric(uint32_t i) const override;
215 uint16_t GetMtu(uint32_t i) const override;
216 bool IsUp(uint32_t i) const override;
217 void SetUp(uint32_t i) override;
218 void SetDown(uint32_t i) override;
219 bool IsForwarding(uint32_t i) const override;
220 void SetForwarding(uint32_t i, bool val) override;
221
222 /**
223 * Sets an interface to run on promiscuous mode.
224 *
225 * @param i Interface ID.
226 */
227 void SetPromisc(uint32_t i);
228
229 protected:
230 void DoDispose() override;
231 /**
232 * This function will notify other components connected to the node that a new stack member is
233 * now connected This will be used to notify Layer 3 protocol of layer 4 protocol stack to
234 * connect them together.
235 */
236 void NotifyNewAggregate() override;
237
238 private:
239 /**
240 * Build IPv4 header.
241 *
242 * @param source IPv4 source address.
243 * @param destination IPv4 destination address.
244 * @param protocol Protocol.
245 * @param payloadSize Payload size.
246 * @param ttl Time To Live (TTL).
247 * @param mayFragment Whether the packet can be fragmented or not.
248 * @return The IPv4 header.
249 */
251 Ipv4Address destination,
252 uint8_t protocol,
253 uint16_t payloadSize,
254 uint8_t ttl,
255 bool mayFragment);
256
257 void SetIpForward(bool forward) override;
258 bool GetIpForward() const override;
259
260 /** @copydoc Ipv4::SetWeakEsModel */
261 NS_DEPRECATED_3_41("Use SetStrongEndSystemModel instead")
262 void SetWeakEsModel(bool model) override;
263 /** @copydoc Ipv4::GetWeakEsModel */
264 NS_DEPRECATED_3_41("Use GetStrongEndSystemModel instead")
265 bool GetWeakEsModel() const override;
266
267 void SetStrongEndSystemModel(bool model) override;
268 bool GetStrongEndSystemModel() const override;
269
270 /**
271 * @brief List of IPv4 interfaces.
272 */
274
275 /**
276 * @brief Container of NetDevices registered to IPv4 and their interface indexes.
277 */
279
280 /**
281 * @brief List of sockets.
282 */
284
285 /**
286 * @brief Container of the IPv4 L4 keys: protocol number, interface index
287 */
288 typedef std::pair<int, int32_t> L4ListKey_t;
289
290 /**
291 * @brief Container of the IPv4 L4 instances.
292 */
294
295 Ptr<Ipv4RoutingProtocol> m_routingProtocol; //!< IPv4 routing protocol
296 bool m_ipForward; //!< Whether IP forwarding is enabled
297 bool m_strongEndSystemModel; //!< Whether to use Strong End System Model
298 L4List_t m_protocols; //!< List of IPv4 L4 protocols
299 Ipv4InterfaceList m_interfaces; //!< List of interfaces
301 m_reverseInterfacesContainer; //!< Container of NetDevice / Interface index associations
302 uint8_t m_defaultTtl; //!< Default TTL
303 uint16_t m_identification; //!< Identification
304
305 Ptr<Node> m_node; //!< Node
306
307 /** @todo Remove; this TracedCallback is never invoked. */
309 /** @todo Remove: this TracedCallback is never invoked. */
311 /** @todo This TracedCallback is invoked but not accessible. */
313
314 SocketList m_sockets; //!< List of sockets
315
316 std::vector<bool> m_promiscDeviceList; //!< List of promiscuous devices
317};
318
319} // namespace ns3
320
321#endif /* IPV4_L3_CLICK_ROUTING_H */
a polymophic address class
Definition address.h:90
This is the implementation of the ICMP protocol as described in RFC 792.
L4 Protocol abstract base class.
Ipv4 addresses are stored in host order in this class.
Packet header for IPv4.
Definition ipv4-header.h:23
Ipv4()
Definition ipv4.cc:65
a class to store IPv4 address information on an interface
The IPv4 representation of a network interface.
L4List_t m_protocols
List of IPv4 L4 protocols.
void SetPromisc(uint32_t i)
Sets an interface to run on promiscuous mode.
uint32_t AddIpv4Interface(Ptr< Ipv4Interface > interface)
Adds an Ipv4Interface to the interfaces list.
Ipv4Header BuildHeader(Ipv4Address source, Ipv4Address destination, uint8_t protocol, uint16_t payloadSize, uint8_t ttl, bool mayFragment)
Build IPv4 header.
std::vector< Ptr< Ipv4Interface > > Ipv4InterfaceList
List of IPv4 interfaces.
bool GetIpForward() const override
Get the IP forwarding state.
std::list< Ptr< Ipv4RawSocketImpl > > SocketList
List of sockets.
std::pair< int, int32_t > L4ListKey_t
Container of the IPv4 L4 keys: protocol number, interface index.
Ptr< Ipv4Interface > GetInterface(uint32_t i) const
Get a pointer to the i'th Ipv4Interface.
Ipv4InterfaceReverseContainer m_reverseInterfacesContainer
Container of NetDevice / Interface index associations.
TracedCallback< const Ipv4Header &, Ptr< const Packet >, uint32_t > m_localDeliverTrace
void LocalDeliver(Ptr< const Packet > p, const Ipv4Header &ip, uint32_t iif)
Ipv4ClickRouting calls this to locally deliver a packet.
bool RemoveAddress(uint32_t interfaceIndex, uint32_t addressIndex) override
Remove the address at addressIndex on named interface.
void Receive(Ptr< NetDevice > device, Ptr< const Packet > p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType)
Lower layer calls this method to send a packet to Click.
SocketList m_sockets
List of sockets.
bool IsForwarding(uint32_t i) const override
uint32_t GetNAddresses(uint32_t interface) const override
uint16_t GetMtu(uint32_t i) const override
Ptr< Ipv4RoutingProtocol > m_routingProtocol
IPv4 routing protocol.
std::vector< bool > m_promiscDeviceList
List of promiscuous devices.
Ptr< Socket > CreateRawSocket() override
Creates a raw-socket.
static TypeId GetTypeId()
Get Type ID.
void Remove(Ptr< IpL4Protocol > protocol) override
int32_t GetInterfaceForDevice(Ptr< const NetDevice > device) const override
std::map< L4ListKey_t, Ptr< IpL4Protocol > > L4List_t
Container of the IPv4 L4 instances.
std::map< Ptr< const NetDevice >, uint32_t > Ipv4InterfaceReverseContainer
Container of NetDevices registered to IPv4 and their interface indexes.
void SetIpForward(bool forward) override
Set or unset the IP forwarding state.
TracedCallback< const Ipv4Header &, Ptr< const Packet >, uint32_t > m_sendOutgoingTrace
void SetStrongEndSystemModel(bool model) override
Set or unset the Strong End System Model.
void SetUp(uint32_t i) override
Ptr< Ipv4RoutingProtocol > GetRoutingProtocol() const override
Get the routing protocol to be used by this Ipv4 stack.
void SetupLoopback()
Sets up a Loopback device.
void SetMetric(uint32_t i, uint16_t metric) override
Ipv4Address SourceAddressSelection(uint32_t interface, Ipv4Address dest) override
Choose the source address to use with destination address.
Ipv4InterfaceList m_interfaces
List of interfaces.
void NotifyNewAggregate() override
This function will notify other components connected to the node that a new stack member is now conne...
Ipv4InterfaceAddress GetAddress(uint32_t interfaceIndex, uint32_t addressIndex) const override
Because addresses can be removed, the addressIndex is not guaranteed to be static across calls to thi...
uint32_t GetNInterfaces() const override
void Send(Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol, Ptr< Ipv4Route > route) override
bool IsUp(uint32_t i) const override
Ptr< NetDevice > GetNetDevice(uint32_t i) override
int32_t GetInterfaceForAddress(Ipv4Address addr) const override
Return the interface number of the interface that has been assigned the specified IP address.
void Insert(Ptr< IpL4Protocol > protocol) override
void SetDown(uint32_t i) override
bool m_strongEndSystemModel
Whether to use Strong End System Model.
Ptr< IpL4Protocol > GetProtocol(int protocolNumber) const override
void SetWeakEsModel(bool model) override
Set or unset the Weak Es Model.
bool AddAddress(uint32_t i, Ipv4InterfaceAddress address) override
uint32_t AddInterface(Ptr< NetDevice > device) override
void SetNode(Ptr< Node > node)
Calls m_node = node and sets up Loopback if needed.
void DoDispose() override
Destructor implementation.
void DeleteRawSocket(Ptr< Socket > socket) override
Deletes a particular raw socket.
static const uint16_t PROT_NUMBER
Protocol number for Ipv4 L3 (0x0800).
uint16_t m_identification
Identification.
uint16_t GetMetric(uint32_t i) const override
bool IsDestinationAddress(Ipv4Address address, uint32_t iif) const override
Determine whether address and interface corresponding to received packet can be accepted for local de...
void SendDown(Ptr< Packet > packet, int ifid)
Ptr< Icmpv4L4Protocol > GetIcmp() const
Returns the Icmpv4L4Protocol for the node.
bool GetWeakEsModel() const override
Get the Weak Es Model status.
void SendWithHeader(Ptr< Packet > packet, Ipv4Header ipHeader, Ptr< Ipv4Route > route) override
bool GetStrongEndSystemModel() const override
Get the Strong End System Model status.
void SetRoutingProtocol(Ptr< Ipv4RoutingProtocol > routingProtocol) override
Register a new routing protocol to be used by this Ipv4 stack.
bool m_ipForward
Whether IP forwarding is enabled.
int32_t GetInterfaceForPrefix(Ipv4Address addr, Ipv4Mask mask) const override
Return the interface number of first interface found that has an Ipv4 address within the prefix speci...
void SetForwarding(uint32_t i, bool val) override
TracedCallback< const Ipv4Header &, Ptr< const Packet >, uint32_t > m_unicastForwardTrace
Ipv4Address SelectSourceAddress(Ptr< const NetDevice > device, Ipv4Address dst, Ipv4InterfaceAddress::InterfaceAddressScope_e scope) override
Return the first primary source address with scope less than or equal to the requested scope,...
a class to represent an Ipv4 address mask
IPv4 route cache entry (similar to Linux struct rtable)
Definition ipv4-route.h:31
Abstract base class for IPv4 routing protocols.
A record of an IPv4 routing table entry for Ipv4GlobalRouting and Ipv4StaticRouting.
Network layer to device interface.
Definition net-device.h:87
PacketType
Packet types are used as they are in Linux.
Definition net-device.h:289
A network Node.
Definition node.h:46
network packets
Definition packet.h:228
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:66
A low-level Socket API based loosely on the BSD Socket API.
Definition socket.h:57
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition type-id.h:49
STL class.
#define NS_DEPRECATED_3_41(msg)
Tag for things deprecated in version ns-3.41.
Definition deprecated.h:119
Every class exported by the ns3 library is enclosed in the ns3 namespace.
STL namespace.
#define list