A Discrete-Event Network Simulator
API
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 
33 namespace ns3
34 {
35 
36 class Packet;
37 class NetDevice;
38 class Ipv4Interface;
39 class Ipv4Address;
40 class Ipv4Header;
41 class Ipv4RoutingTableEntry;
42 class Ipv4Route;
43 class Node;
44 class Socket;
45 class Ipv4RawSocketImpl;
46 class IpL4Protocol;
47 class Icmpv4L4Protocol;
48 
62 class Ipv4L3ClickProtocol : public Ipv4
63 {
64  public:
70  static TypeId GetTypeId();
71 
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 
89  Ipv4Address SourceAddressSelection(uint32_t interface, Ipv4Address dest) override;
90 
97  void SetDefaultTtl(uint8_t ttl);
98 
109  void Send(Ptr<Packet> packet,
110  Ipv4Address source,
111  Ipv4Address destination,
112  uint8_t protocol,
113  Ptr<Ipv4Route> route) override;
114 
123  void SendWithHeader(Ptr<Packet> packet, Ipv4Header ipHeader, Ptr<Ipv4Route> route) override;
124 
132  void SendDown(Ptr<Packet> packet, int ifid);
133 
143  void Receive(Ptr<NetDevice> device,
145  uint16_t protocol,
146  const Address& from,
147  const Address& to,
148  NetDevice::PacketType packetType);
149 
156  void LocalDeliver(Ptr<const Packet> p, const Ipv4Header& ip, uint32_t iif);
157 
163  Ptr<Ipv4Interface> GetInterface(uint32_t i) const;
164 
170  uint32_t AddIpv4Interface(Ptr<Ipv4Interface> interface);
171 
176  void SetNode(Ptr<Node> node);
177 
183 
187  void SetupLoopback();
188 
193  Ptr<Socket> CreateRawSocket() override;
194 
199  void DeleteRawSocket(Ptr<Socket> socket) override;
200 
201  // functions defined in base class Ipv4
202  void SetRoutingProtocol(Ptr<Ipv4RoutingProtocol> routingProtocol) override;
204 
205  Ptr<NetDevice> GetNetDevice(uint32_t i) override;
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;
212  int32_t GetInterfaceForDevice(Ptr<const NetDevice> device) 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 
238  void SetPromisc(uint32_t i);
239 
240  protected:
241  void DoDispose() override;
247  void NotifyNewAggregate() override;
248 
249  private:
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 
282  typedef std::vector<Ptr<Ipv4Interface>> Ipv4InterfaceList;
283 
287  typedef std::map<Ptr<const NetDevice>, uint32_t> Ipv4InterfaceReverseContainer;
288 
293 
297  typedef std::pair<int, int32_t> L4ListKey_t;
298 
302  typedef std::map<L4ListKey_t, Ptr<IpL4Protocol>> L4List_t;
303 
305  bool m_ipForward;
311  uint8_t m_defaultTtl;
312  uint16_t m_identification;
313 
315 
322 
324 
325  std::vector<bool> m_promiscDeviceList;
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
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:82
address
Definition: first.py:47
Every class exported by the ns3 library is enclosed in the ns3 namespace.
#define list