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 
53 {
54 #ifdef NS3_CLICK
55 public:
56  // Allow test cases to access private members
57  friend class ClickTrivialTest;
58  friend class ClickIfidFromNameTest;
59  friend class ClickIpMacAddressFromNameTest;
60 
61  static TypeId GetTypeId (void);
62 
64  virtual ~Ipv4ClickRouting ();
65 
66 protected:
67  virtual void DoStart (void);
68 
69 public:
70  virtual void DoDispose ();
71 
76  void SetClickFile (std::string clickfile);
77 
82  void SetNodeName (std::string name);
83 
88  void SetClickRoutingTableElement (std::string name);
89 
96  std::string ReadHandler (std::string elementName, std::string handlerName);
97 
105  int WriteHandler (std::string elementName, std::string handlerName, std::string writeString);
106 
111  void SetPromisc (int ifid);
112 
113 
114 private:
115  simclick_node_t *m_simNode;
116 
120  static std::map < simclick_node_t *, Ptr<Ipv4ClickRouting> > m_clickInstanceFromSimNode;
121 
122 public:
128  static Ptr<Ipv4ClickRouting> GetClickInstanceFromSimNode (simclick_node_t *simnode);
129 
130 public:
136  int GetInterfaceId (const char *ifname);
137 
143  std::string GetIpAddressFromInterfaceId (int ifid);
144 
150  std::string GetIpPrefixFromInterfaceId (int ifid);
151 
157  std::string GetMacAddressFromInterfaceId (int ifid);
158 
163  std::string GetNodeName ();
164 
169  bool IsInterfaceReady (int ifid);
170 
175  virtual void SetIpv4 (Ptr<Ipv4> ipv4);
176 
177 private:
181  void AddSimNodeToClickMapping ();
182 
186  struct timeval GetTimevalFromNow () const;
187 
191  void RunClickEvent ();
192 
193 public:
198  void HandleScheduleFromClick (const struct timeval *when);
199 
207  void HandlePacketFromClick (int ifid, int type, const unsigned char *data, int len);
208 
216  void SendPacketToClick (int ifid, int type, const unsigned char *data, int len);
217 
224  void Send (Ptr<Packet> p, Ipv4Address src, Ipv4Address dest);
225 
232  void Receive (Ptr<Packet> p, Mac48Address receiverAddr, Mac48Address dest);
233 
234  // From Ipv4RoutingProtocol
235  virtual Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr);
236  virtual bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
239  virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const;
240  virtual void NotifyInterfaceUp (uint32_t interface);
241  virtual void NotifyInterfaceDown (uint32_t interface);
242  virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
243  virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address);
244 
245 private:
246  std::string m_clickFile;
247  std::string m_nodeName;
248  std::string m_clickRoutingTableElement;
249 
250 
251  std::map < std::string, uint32_t > m_ifaceIdFromName;
252  std::map < std::string, Address > m_ifaceMacFromName;
253  std::map < std::string, Ipv4Address > m_ifaceAddrFromName;
254  bool m_clickInitialised;
255  bool m_nonDefaultName;
256 
257  Ptr<Ipv4> m_ipv4;
258 #endif /* NS3_CLICK */
259 };
260 
261 } // namespace ns3
262 
263 #endif /* IPV4_CLICK_ROUTING_H */