A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
85  void Insert (Ptr<IpL4Protocol> protocol);
86 
95  Ptr<IpL4Protocol> GetProtocol (int protocolNumber) const;
96 
103  void SetDefaultTtl (uint8_t ttl);
104 
115  void Send (Ptr<Packet> packet, Ipv4Address source,
116  Ipv4Address destination, uint8_t protocol, Ptr<Ipv4Route> route);
117 
126  void SendWithHeader (Ptr<Packet> packet, Ipv4Header ipHeader, Ptr<Ipv4Route> route);
127 
135  void SendDown (Ptr<Packet> packet, int ifid);
136 
146  void Receive ( Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol, const Address &from,
147  const Address &to, NetDevice::PacketType packetType);
148 
155  void LocalDeliver (Ptr<const Packet> p, Ipv4Header const&ip, uint32_t iif);
156 
162  Ptr<Ipv4Interface> GetInterface (uint32_t i) const;
163 
169  uint32_t AddIpv4Interface (Ptr<Ipv4Interface> interface);
170 
175  void SetNode (Ptr<Node> node);
176 
181  Ptr<Icmpv4L4Protocol> GetIcmp (void) const;
182 
186  void SetupLoopback (void);
187 
193 
198  void DeleteRawSocket (Ptr<Socket> socket);
199 
200  // functions defined in base class Ipv4
201  void SetRoutingProtocol (Ptr<Ipv4RoutingProtocol> routingProtocol);
203 
204  Ptr<NetDevice> GetNetDevice (uint32_t i);
205 
206  uint32_t AddInterface (Ptr<NetDevice> device);
207  uint32_t GetNInterfaces (void) const;
208 
209  int32_t GetInterfaceForAddress (Ipv4Address addr) const;
210  int32_t GetInterfaceForPrefix (Ipv4Address addr, Ipv4Mask mask) const;
211  int32_t GetInterfaceForDevice (Ptr<const NetDevice> device) const;
212  bool IsDestinationAddress (Ipv4Address address, uint32_t iif) const;
213 
214  bool AddAddress (uint32_t i, Ipv4InterfaceAddress address);
215  Ipv4InterfaceAddress GetAddress (uint32_t interfaceIndex, uint32_t addressIndex) const;
216  uint32_t GetNAddresses (uint32_t interface) const;
217  bool RemoveAddress (uint32_t interfaceIndex, uint32_t addressIndex);
218  bool RemoveAddress (uint32_t interfaceIndex, Ipv4Address address);
221 
222  void SetMetric (uint32_t i, uint16_t metric);
223  uint16_t GetMetric (uint32_t i) const;
224  uint16_t GetMtu (uint32_t i) const;
225  bool IsUp (uint32_t i) const;
226  void SetUp (uint32_t i);
227  void SetDown (uint32_t i);
228  bool IsForwarding (uint32_t i) const;
229  void SetForwarding (uint32_t i, bool val);
230  void SetPromisc (uint32_t i);
231 protected:
232  virtual void DoDispose (void);
237  virtual void NotifyNewAggregate ();
238 
239 private:
240  Ipv4Header BuildHeader (
241  Ipv4Address source,
242  Ipv4Address destination,
243  uint8_t protocol,
244  uint16_t payloadSize,
245  uint8_t ttl,
246  bool mayFragment);
247 
248  virtual void SetIpForward (bool forward);
249  virtual bool GetIpForward (void) const;
250  virtual void SetWeakEsModel (bool model);
251  virtual bool GetWeakEsModel (void) const;
252 
253  typedef std::vector<Ptr<Ipv4Interface> > Ipv4InterfaceList;
254  typedef std::list<Ptr<Ipv4RawSocketImpl> > SocketList;
255  typedef std::list<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  uint8_t m_defaultTtl;
263  uint16_t m_identification;
264 
265  Ptr<Node> m_node;
266 
267  TracedCallback<const Ipv4Header &, Ptr<const Packet>, uint32_t> m_sendOutgoingTrace;
268  TracedCallback<const Ipv4Header &, Ptr<const Packet>, uint32_t> m_unicastForwardTrace;
269  TracedCallback<const Ipv4Header &, Ptr<const Packet>, uint32_t> m_localDeliverTrace;
270 
271  SocketList m_sockets;
272 
273  std::vector<bool> m_promiscDeviceList;
274 
275 #endif /* NS3_CLICK */
276 };
277 
278 } // namespace ns3
279 
280 #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:222
forward calls to a chain of CallbackAn ns3::TracedCallback has almost exactly the same API as a norma...
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: object.cc:335
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:86
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:31
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
virtual void NotifyNewAggregate(void)
This method is invoked whenever two sets of objects are aggregated together.
Definition: object.cc:314
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.
virtual bool IsForwarding(uint32_t interface) const =0
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:38
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
tuple address
Definition: first.py:37
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:274
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:49
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.