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// 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: George F. Riley <riley@ece.gatech.edu>
18// Author: Lalith Suresh <suresh.lalith@gmail.com>
19//
20
21#ifndef IPV4_L3_CLICK_PROTOCOL_H
22#define IPV4_L3_CLICK_PROTOCOL_H
23
24#include "ns3/deprecated.h"
25#include "ns3/ipv4-interface.h"
26#include "ns3/ipv4-routing-protocol.h"
27#include "ns3/ipv4.h"
28#include "ns3/log.h"
29#include "ns3/net-device.h"
30#include "ns3/packet.h"
31#include "ns3/traced-callback.h"
32
33namespace ns3
34{
35
36class Packet;
37class NetDevice;
38class Ipv4Interface;
39class Ipv4Address;
40class Ipv4Header;
41class Ipv4RoutingTableEntry;
42class Ipv4Route;
43class Node;
44class Socket;
45class Ipv4RawSocketImpl;
46class IpL4Protocol;
47class Icmpv4L4Protocol;
48
49/**
50 * \brief Implement the Ipv4 layer specifically for Click nodes
51 * to allow a clean integration of Click.
52 * \ingroup click
53 *
54 * This is code is mostly repeated from the Ipv4L3Protocol implementation.
55 * Changes include:
56 * - A stripped down version of Send().
57 * - A stripped down version of Receive().
58 * - A public version of LocalDeliver().
59 * - Modifications to AddInterface().
60 */
61
63{
64 public:
65 /**
66 * Get Type ID.
67 *
68 * \return The type ID.
69 */
70 static TypeId GetTypeId();
71
72 /**
73 * Protocol number for Ipv4 L3 (0x0800).
74 */
75 static const uint16_t PROT_NUMBER;
76
78 ~Ipv4L3ClickProtocol() override;
79
80 void Insert(Ptr<IpL4Protocol> protocol) override;
81 void Insert(Ptr<IpL4Protocol> protocol, uint32_t interfaceIndex) override;
82
83 void Remove(Ptr<IpL4Protocol> protocol) override;
84 void Remove(Ptr<IpL4Protocol> protocol, uint32_t interfaceIndex) override;
85
86 Ptr<IpL4Protocol> GetProtocol(int protocolNumber) const override;
87 Ptr<IpL4Protocol> GetProtocol(int protocolNumber, int32_t interfaceIndex) const override;
88
90
91 /**
92 * \param ttl default ttl to use
93 *
94 * When we need to send an ipv4 packet, we use this default
95 * ttl value.
96 */
97 void SetDefaultTtl(uint8_t ttl);
98
99 /**
100 * \param packet packet to send
101 * \param source source address of packet
102 * \param destination address of packet
103 * \param protocol number of packet
104 * \param route route entry
105 *
106 * Higher-level layers call this method to send a packet
107 * to Click
108 */
109 void Send(Ptr<Packet> packet,
110 Ipv4Address source,
111 Ipv4Address destination,
112 uint8_t protocol,
113 Ptr<Ipv4Route> route) override;
114
115 /**
116 * \param packet packet to send
117 * \param ipHeader IP Header
118 * \param route route entry
119 *
120 * Higher-level layers call this method to send a packet with IPv4 Header
121 * (Intend to be used with IpHeaderInclude attribute.)
122 */
123 void SendWithHeader(Ptr<Packet> packet, Ipv4Header ipHeader, Ptr<Ipv4Route> route) override;
124
125 /**
126 * \param packet packet to send down the stack
127 * \param ifid interface to be used for sending down packet
128 *
129 * Ipv4ClickRouting calls this method to send a packet further
130 * down the stack
131 */
132 void SendDown(Ptr<Packet> packet, int ifid);
133
134 /**
135 * Lower layer calls this method to send a packet to Click
136 * \param device network device
137 * \param p the packet
138 * \param protocol protocol value
139 * \param from address of the correspondent
140 * \param to address of the destination
141 * \param packetType type of the packet
142 */
143 void Receive(Ptr<NetDevice> device,
145 uint16_t protocol,
146 const Address& from,
147 const Address& to,
148 NetDevice::PacketType packetType);
149
150 /**
151 * Ipv4ClickRouting calls this to locally deliver a packet
152 * \param p the packet
153 * \param ip The Ipv4Header of the packet
154 * \param iif The interface on which the packet was received
155 */
156 void LocalDeliver(Ptr<const Packet> p, const Ipv4Header& ip, uint32_t iif);
157
158 /**
159 * Get a pointer to the i'th Ipv4Interface
160 * \param i index of interface, pointer to which is to be returned
161 * \returns Pointer to the i'th Ipv4Interface if any.
162 */
164
165 /**
166 * Adds an Ipv4Interface to the interfaces list
167 * \param interface Pointer to the Ipv4Interface to be added
168 * \returns Index of the device which was added
169 */
171
172 /**
173 * Calls m_node = node and sets up Loopback if needed
174 * \param node Pointer to the node
175 */
176 void SetNode(Ptr<Node> node);
177
178 /**
179 * Returns the Icmpv4L4Protocol for the node
180 * \returns Icmpv4L4Protocol instance of the node
181 */
183
184 /**
185 * Sets up a Loopback device
186 */
187 void SetupLoopback();
188
189 /**
190 * Creates a raw-socket
191 * \returns Pointer to the created socket
192 */
193 Ptr<Socket> CreateRawSocket() override;
194
195 /**
196 * Deletes a particular raw socket
197 * \param socket Pointer of socket to be deleted
198 */
199 void DeleteRawSocket(Ptr<Socket> socket) override;
200
201 // functions defined in base class Ipv4
202 void SetRoutingProtocol(Ptr<Ipv4RoutingProtocol> routingProtocol) override;
204
206
207 uint32_t AddInterface(Ptr<NetDevice> device) override;
208 uint32_t GetNInterfaces() const override;
209
210 int32_t GetInterfaceForAddress(Ipv4Address addr) const override;
211 int32_t GetInterfaceForPrefix(Ipv4Address addr, Ipv4Mask mask) const override;
213 bool IsDestinationAddress(Ipv4Address address, uint32_t iif) const override;
214
215 bool AddAddress(uint32_t i, Ipv4InterfaceAddress address) override;
216 Ipv4InterfaceAddress GetAddress(uint32_t interfaceIndex, uint32_t addressIndex) const override;
217 uint32_t GetNAddresses(uint32_t interface) const override;
218 bool RemoveAddress(uint32_t interfaceIndex, uint32_t addressIndex) override;
219 bool RemoveAddress(uint32_t interfaceIndex, Ipv4Address address) override;
221 Ipv4Address dst,
223
224 void SetMetric(uint32_t i, uint16_t metric) override;
225 uint16_t GetMetric(uint32_t i) const override;
226 uint16_t GetMtu(uint32_t i) const override;
227 bool IsUp(uint32_t i) const override;
228 void SetUp(uint32_t i) override;
229 void SetDown(uint32_t i) override;
230 bool IsForwarding(uint32_t i) const override;
231 void SetForwarding(uint32_t i, bool val) override;
232
233 /**
234 * Sets an interface to run on promiscuous mode.
235 *
236 * \param i Interface ID.
237 */
238 void SetPromisc(uint32_t i);
239
240 protected:
241 void DoDispose() override;
242 /**
243 * This function will notify other components connected to the node that a new stack member is
244 * now connected This will be used to notify Layer 3 protocol of layer 4 protocol stack to
245 * connect them together.
246 */
247 void NotifyNewAggregate() override;
248
249 private:
250 /**
251 * Build IPv4 header.
252 *
253 * \param source IPv4 source address.
254 * \param destination IPv4 destination address.
255 * \param protocol Protocol.
256 * \param payloadSize Payload size.
257 * \param ttl Time To Live (TTL).
258 * \param mayFragment Whether the packet can be fragmented or not.
259 * \return The IPv4 header.
260 */
262 Ipv4Address destination,
263 uint8_t protocol,
264 uint16_t payloadSize,
265 uint8_t ttl,
266 bool mayFragment);
267
268 void SetIpForward(bool forward) override;
269 bool GetIpForward() const override;
270
271 NS_DEPRECATED_3_41("Use SetStrongEndSystemModel instead")
272 void SetWeakEsModel(bool model) override;
274 bool GetWeakEsModel() const override;
275
276 void SetStrongEndSystemModel(bool model) override;
277 bool GetStrongEndSystemModel() const override;
278
279 /**
280 * \brief List of IPv4 interfaces.
281 */
283
284 /**
285 * \brief Container of NetDevices registered to IPv4 and their interface indexes.
286 */
288
289 /**
290 * \brief List of sockets.
291 */
293
294 /**
295 * \brief Container of the IPv4 L4 keys: protocol number, interface index
296 */
297 typedef std::pair<int, int32_t> L4ListKey_t;
298
299 /**
300 * \brief Container of the IPv4 L4 instances.
301 */
303
304 Ptr<Ipv4RoutingProtocol> m_routingProtocol; //!< IPv4 routing protocol
305 bool m_ipForward; //!< Whether IP forwarding is enabled
306 bool m_strongEndSystemModel; //!< Whether to use Strong End System Model
307 L4List_t m_protocols; //!< List of IPv4 L4 protocols
308 Ipv4InterfaceList m_interfaces; //!< List of interfaces
310 m_reverseInterfacesContainer; //!< Container of NetDevice / Interface index associations
311 uint8_t m_defaultTtl; //!< Default TTL
312 uint16_t m_identification; //!< Identification
313
314 Ptr<Node> m_node; //!< Node
315
316 /** \todo Remove; this TracedCallback is never invoked. */
318 /** \todo Remove: this TracedCallback is never invoked. */
320 /** \todo This TracedCallback is invoked but not accessible. */
322
323 SocketList m_sockets; //!< List of sockets
324
325 std::vector<bool> m_promiscDeviceList; //!< List of promiscuous devices
326};
327
328} // namespace ns3
329
330#endif /* IPV4_L3_CLICK_ROUTING_H */
a polymophic address class
Definition: address.h:101
L4 Protocol abstract base class.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Packet header for IPv4.
Definition: ipv4-header.h:34
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:80
a class to store IPv4 address information on an interface
The IPv4 representation of a network interface.
Implement the Ipv4 layer specifically for Click nodes to allow a clean integration of Click.
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.
uint8_t m_defaultTtl
Default TTL.
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
Definition: ipv4-address.h:257
Abstract base class for IPv4 routing protocols.
Network layer to device interface.
Definition: net-device.h:98
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:300
A network Node.
Definition: node.h:57
network packets
Definition: packet.h:239
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:59
#define NS_DEPRECATED_3_41(msg)
Tag for things deprecated in version ns-3.41.
Definition: deprecated.h:109
Every class exported by the ns3 library is enclosed in the ns3 namespace.
STL namespace.
#define list