A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ipv4-click-routing.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2010 Lalith Suresh
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  * Authors: Lalith Suresh <suresh.lalith@gmail.com>
19  */
20 
21 #ifndef IPV4_CLICK_ROUTING_H
22 #define IPV4_CLICK_ROUTING_H
23 
24 #include "ns3/object.h"
25 #include "ns3/packet.h"
26 #include "ns3/ipv4.h"
27 #include "ns3/ipv4-routing-protocol.h"
28 #include "ns3/test.h"
29 
30 #include <sys/time.h>
31 #include <sys/types.h>
32 
33 #ifdef NS3_CLICK
34 #include <click/simclick.h>
35 #endif
36 
37 #include <map>
38 #include <string>
39 
40 namespace ns3 {
41 
47 class UniformRandomVariable;
48 
55 {
56 #ifdef NS3_CLICK
57 public:
58  // Allow test cases to access private members
59  friend class ClickTrivialTest;
60  friend class ClickIfidFromNameTest;
61  friend class ClickIpMacAddressFromNameTest;
62 
63  static TypeId GetTypeId (void);
64 
66  virtual ~Ipv4ClickRouting ();
67 
68  Ptr<UniformRandomVariable> GetRandomVariable (void);
69 protected:
70  virtual void DoInitialize (void);
71 
72 public:
73  virtual void DoDispose ();
74 
79  void SetClickFile (std::string clickfile);
80 
85  void SetDefines (std::map<std::string, std::string> defines);
86 
91  void SetNodeName (std::string name);
92 
97  void SetClickRoutingTableElement (std::string name);
98 
105  std::string ReadHandler (std::string elementName, std::string handlerName);
106 
114  int WriteHandler (std::string elementName, std::string handlerName, std::string writeString);
115 
120  void SetPromisc (int ifid);
121 
122 
123 private:
124  simclick_node_t *m_simNode;
125 
129  static std::map < simclick_node_t *, Ptr<Ipv4ClickRouting> > m_clickInstanceFromSimNode;
130 
131 public:
137  static Ptr<Ipv4ClickRouting> GetClickInstanceFromSimNode (simclick_node_t *simnode);
138 
139 public:
144  std::map<std::string, std::string> GetDefines (void);
145 
151  int GetInterfaceId (const char *ifname);
152 
158  std::string GetIpAddressFromInterfaceId (int ifid);
159 
165  std::string GetIpPrefixFromInterfaceId (int ifid);
166 
172  std::string GetMacAddressFromInterfaceId (int ifid);
173 
178  std::string GetNodeName ();
179 
184  bool IsInterfaceReady (int ifid);
185 
190  virtual void SetIpv4 (Ptr<Ipv4> ipv4);
191 
192 private:
196  void AddSimNodeToClickMapping ();
197 
201  struct timeval GetTimevalFromNow () const;
202 
206  void RunClickEvent ();
207 
208 public:
213  void HandleScheduleFromClick (const struct timeval *when);
214 
222  void HandlePacketFromClick (int ifid, int type, const unsigned char *data, int len);
223 
231  void SendPacketToClick (int ifid, int type, const unsigned char *data, int len);
232 
239  void Send (Ptr<Packet> p, Ipv4Address src, Ipv4Address dest);
240 
247  void Receive (Ptr<Packet> p, Mac48Address receiverAddr, Mac48Address dest);
248 
249  // From Ipv4RoutingProtocol
250  virtual Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr);
251  virtual bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
254  virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const;
255  virtual void NotifyInterfaceUp (uint32_t interface);
256  virtual void NotifyInterfaceDown (uint32_t interface);
257  virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
258  virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address);
259 
260 private:
261  std::string m_clickFile;
262  std::map < std::string, std::string > m_defines;
263  std::string m_nodeName;
264  std::string m_clickRoutingTableElement;
265 
266 
267  std::map < std::string, uint32_t > m_ifaceIdFromName;
268  std::map < std::string, Address > m_ifaceMacFromName;
269  std::map < std::string, Ipv4Address > m_ifaceAddrFromName;
270  bool m_clickInitialised;
271  bool m_nonDefaultName;
272 
273  Ptr<Ipv4> m_ipv4;
275 #endif /* NS3_CLICK */
276 };
277 
278 } // namespace ns3
279 
280 #endif /* IPV4_CLICK_ROUTING_H */
virtual void SetIpv4(Ptr< Ipv4 > ipv4)=0
Callback template class.
Definition: callback.h:920
virtual void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address)=0
virtual void NotifyInterfaceUp(uint32_t interface)=0
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: object.cc:336
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
Packet header for IPv4.
Definition: ipv4-header.h:31
virtual void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)=0
uint8_t data[writeSize]
Class to allow a node to use Click for external routing.
virtual bool RouteInput(Ptr< const Packet > p, const Ipv4Header &header, Ptr< const NetDevice > idev, UnicastForwardCallback ucb, MulticastForwardCallback mcb, LocalDeliverCallback lcb, ErrorCallback ecb)=0
Route an input packet (to be forwarded or locally delivered)
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream) const =0
Print the Routing Table entries.
an EUI-48 address
Definition: mac48-address.h:41
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
a class to store IPv4 address information on an interface
Abstract base class for IPv4 routing protocols.
virtual Ptr< Ipv4Route > RouteOutput(Ptr< Packet > p, const Ipv4Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr)=0
Query routing cache for an existing route, for an outbound packet.
tuple address
Definition: first.py:37
static TypeId GetTypeId(void)
Get the type ID.
a unique identifier for an interface.
Definition: type-id.h:49
virtual void NotifyInterfaceDown(uint32_t interface)=0
virtual void DoInitialize(void)
This method is called only once by Object::Initialize.
Definition: object.cc:343