A Discrete-Event Network Simulator
API
ipv4-l3-click-protocol.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 //
3 // Copyright (c) 2006 Georgia Tech Research Corporation
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License version 2 as
7 // published by the Free Software Foundation;
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 //
18 // Author: George F. Riley <riley@ece.gatech.edu>
19 // Author: Lalith Suresh <suresh.lalith@gmail.com>
20 //
21 
22 #ifndef IPV4_L3_CLICK_PROTOCOL_H
23 #define IPV4_L3_CLICK_PROTOCOL_H
24 
25 #include "ns3/ipv4.h"
26 #include "ns3/net-device.h"
27 #include "ns3/packet.h"
28 #include "ns3/ipv4-routing-protocol.h"
29 #include "ns3/traced-callback.h"
30 #include "ns3/ipv4-interface.h"
31 #include "ns3/log.h"
32 
33 namespace ns3 {
34 
35 class Packet;
36 class NetDevice;
37 class Ipv4Interface;
38 class Ipv4Address;
39 class Ipv4Header;
40 class Ipv4RoutingTableEntry;
41 class Ipv4Route;
42 class Node;
43 class Socket;
44 class Ipv4RawSocketImpl;
45 class IpL4Protocol;
46 class Icmpv4L4Protocol;
47 
61 class Ipv4L3ClickProtocol : public Ipv4
62 {
63 #ifdef NS3_CLICK
64 public:
65  static TypeId GetTypeId (void);
66 
70  static const uint16_t PROT_NUMBER;
71 
73  virtual ~Ipv4L3ClickProtocol ();
74 
75  virtual void Insert (Ptr<IpL4Protocol> protocol);
76  virtual void Insert (Ptr<IpL4Protocol> protocol, uint32_t interfaceIndex);
77 
78  virtual void Remove (Ptr<IpL4Protocol> protocol);
79  virtual void Remove (Ptr<IpL4Protocol> protocol, uint32_t interfaceIndex);
80 
81  virtual Ptr<IpL4Protocol> GetProtocol (int protocolNumber) const;
82  virtual Ptr<IpL4Protocol> GetProtocol (int protocolNumber, int32_t interfaceIndex) const;
83 
84  virtual Ipv4Address SourceAddressSelection (uint32_t interface, Ipv4Address dest);
85 
92  void SetDefaultTtl (uint8_t ttl);
93 
104  void Send (Ptr<Packet> packet, Ipv4Address source,
105  Ipv4Address destination, uint8_t protocol, Ptr<Ipv4Route> route);
106 
115  void SendWithHeader (Ptr<Packet> packet, Ipv4Header ipHeader, Ptr<Ipv4Route> route);
116 
124  void SendDown (Ptr<Packet> packet, int ifid);
125 
135  void Receive ( Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol, const Address &from,
136  const Address &to, NetDevice::PacketType packetType);
137 
144  void LocalDeliver (Ptr<const Packet> p, Ipv4Header const&ip, uint32_t iif);
145 
151  Ptr<Ipv4Interface> GetInterface (uint32_t i) const;
152 
158  uint32_t AddIpv4Interface (Ptr<Ipv4Interface> interface);
159 
164  void SetNode (Ptr<Node> node);
165 
170  Ptr<Icmpv4L4Protocol> GetIcmp (void) const;
171 
175  void SetupLoopback (void);
176 
182 
187  void DeleteRawSocket (Ptr<Socket> socket);
188 
189  // functions defined in base class Ipv4
190  void SetRoutingProtocol (Ptr<Ipv4RoutingProtocol> routingProtocol);
192 
193  Ptr<NetDevice> GetNetDevice (uint32_t i);
194 
195  uint32_t AddInterface (Ptr<NetDevice> device);
196  uint32_t GetNInterfaces (void) const;
197 
198  int32_t GetInterfaceForAddress (Ipv4Address addr) const;
199  int32_t GetInterfaceForPrefix (Ipv4Address addr, Ipv4Mask mask) const;
200  int32_t GetInterfaceForDevice (Ptr<const NetDevice> device) const;
201  bool IsDestinationAddress (Ipv4Address address, uint32_t iif) const;
202 
203  bool AddAddress (uint32_t i, Ipv4InterfaceAddress address);
204  Ipv4InterfaceAddress GetAddress (uint32_t interfaceIndex, uint32_t addressIndex) const;
205  uint32_t GetNAddresses (uint32_t interface) const;
206  bool RemoveAddress (uint32_t interfaceIndex, uint32_t addressIndex);
207  bool RemoveAddress (uint32_t interfaceIndex, Ipv4Address address);
210 
211  void SetMetric (uint32_t i, uint16_t metric);
212  uint16_t GetMetric (uint32_t i) const;
213  uint16_t GetMtu (uint32_t i) const;
214  bool IsUp (uint32_t i) const;
215  void SetUp (uint32_t i);
216  void SetDown (uint32_t i);
217  bool IsForwarding (uint32_t i) const;
218  void SetForwarding (uint32_t i, bool val);
219  void SetPromisc (uint32_t i);
220 protected:
221  virtual void DoDispose (void);
226  virtual void NotifyNewAggregate ();
227 
228 private:
229  Ipv4Header BuildHeader (
230  Ipv4Address source,
231  Ipv4Address destination,
232  uint8_t protocol,
233  uint16_t payloadSize,
234  uint8_t ttl,
235  bool mayFragment);
236 
237  virtual void SetIpForward (bool forward);
238  virtual bool GetIpForward (void) const;
239  virtual void SetWeakEsModel (bool model);
240  virtual bool GetWeakEsModel (void) const;
241 
242  typedef std::vector<Ptr<Ipv4Interface> > Ipv4InterfaceList;
246  typedef std::map<Ptr<const NetDevice>, uint32_t > Ipv4InterfaceReverseContainer;
247  typedef std::list<Ptr<Ipv4RawSocketImpl> > SocketList;
251  typedef std::pair<int, int32_t> L4ListKey_t;
255  typedef std::map<L4ListKey_t, Ptr<IpL4Protocol> > L4List_t;
256 
257  Ptr<Ipv4RoutingProtocol> m_routingProtocol;
258  bool m_ipForward;
259  bool m_weakEsModel;
260  L4List_t m_protocols;
261  Ipv4InterfaceList m_interfaces;
262  Ipv4InterfaceReverseContainer m_reverseInterfacesContainer;
263  uint8_t m_defaultTtl;
264  uint16_t m_identification;
265 
266  Ptr<Node> m_node;
267 
269  TracedCallback<const Ipv4Header &, Ptr<const Packet>, uint32_t> m_sendOutgoingTrace;
271  TracedCallback<const Ipv4Header &, Ptr<const Packet>, uint32_t> m_unicastForwardTrace;
273  TracedCallback<const Ipv4Header &, Ptr<const Packet>, uint32_t> m_localDeliverTrace;
274 
275  SocketList m_sockets;
276 
277  std::vector<bool> m_promiscDeviceList;
278 
279 #endif /* NS3_CLICK */
280 };
281 
282 } // namespace ns3
283 
284 #endif /* IPV4_L3_CLICK_ROUTING_H */
static TypeId GetTypeId(void)
Get the type ID.
Definition: ipv4.cc:34
virtual uint32_t AddInterface(Ptr< NetDevice > device)=0
virtual int32_t GetInterfaceForPrefix(Ipv4Address address, Ipv4Mask mask) const =0
Return the interface number of first interface found that has an Ipv4 address within the prefix speci...
virtual void SetWeakEsModel(bool model)=0
Set or unset the Weak Es Model.
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:263
Forward calls to a chain of Callback.
virtual Ipv4Address SourceAddressSelection(uint32_t interface, Ipv4Address dest)=0
Choose the source address to use with destination address.
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
virtual Ptr< NetDevice > GetNetDevice(uint32_t interface)=0
virtual void SetForwarding(uint32_t interface, bool val)=0
virtual Ptr< Ipv4RoutingProtocol > GetRoutingProtocol(void) const =0
Get the routing protocol to be used by this Ipv4 stack.
a polymophic address class
Definition: address.h:90
virtual bool IsDestinationAddress(Ipv4Address address, uint32_t iif) const =0
Determine whether address and interface corresponding to received packet can be accepted for local de...
Packet header for IPv4.
Definition: ipv4-header.h:33
virtual bool GetIpForward(void) const =0
Get the IP forwarding state.
virtual void DeleteRawSocket(Ptr< Socket > socket)=0
Deletes a particular raw socket.
virtual Ptr< IpL4Protocol > GetProtocol(int protocolNumber) const =0
virtual void SetUp(uint32_t interface)=0
virtual uint16_t GetMetric(uint32_t interface) const =0
virtual void SendWithHeader(Ptr< Packet > packet, Ipv4Header ipHeader, Ptr< Ipv4Route > route)=0
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:76
virtual bool GetWeakEsModel(void) const =0
Get the Weak Es Model status.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual bool IsForwarding(uint32_t interface) const =0
address
Definition: first.py:37
Implement the Ipv4 layer specifically for Click nodes to allow a clean integration of Click...
virtual uint16_t GetMtu(uint32_t interface) const =0
virtual void Send(Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol, Ptr< Ipv4Route > route)=0
virtual Ptr< Socket > CreateRawSocket(void)=0
Creates a raw socket.
virtual bool IsUp(uint32_t interface) const =0
virtual void SetIpForward(bool forward)=0
Set or unset the IP forwarding state.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
virtual void Insert(Ptr< IpL4Protocol > protocol)=0
a class to store IPv4 address information on an interface
virtual Ipv4InterfaceAddress GetAddress(uint32_t interface, uint32_t addressIndex) const =0
Because addresses can be removed, the addressIndex is not guaranteed to be static across calls to thi...
virtual uint32_t GetNAddresses(uint32_t interface) const =0
virtual Ipv4Address SelectSourceAddress(Ptr< const NetDevice > device, Ipv4Address dst, Ipv4InterfaceAddress::InterfaceAddressScope_e scope)=0
Return the first primary source address with scope less than or equal to the requested scope...
virtual void SetMetric(uint32_t interface, uint16_t metric)=0
virtual int32_t GetInterfaceForDevice(Ptr< const NetDevice > device) const =0
virtual bool AddAddress(uint32_t interface, Ipv4InterfaceAddress address)=0
virtual int32_t GetInterfaceForAddress(Ipv4Address address) const =0
Return the interface number of the interface that has been assigned the specified IP address...
virtual void SetDown(uint32_t interface)=0
virtual void NotifyNewAggregate(void)
Notify all Objects aggregated to this one of a new Object being aggregated.
Definition: object.cc:325
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:296
virtual bool RemoveAddress(uint32_t interface, uint32_t addressIndex)=0
Remove the address at addressIndex on named interface.
a unique identifier for an interface.
Definition: type-id.h:58
virtual uint32_t GetNInterfaces(void) const =0
virtual void SetRoutingProtocol(Ptr< Ipv4RoutingProtocol > routingProtocol)=0
Register a new routing protocol to be used by this Ipv4 stack.
virtual void Remove(Ptr< IpL4Protocol > protocol)=0