A Discrete-Event Network Simulator
API
ipv4-click-routing.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010 Lalith Suresh
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 * Authors: Lalith Suresh <suresh.lalith@gmail.com>
18 */
19
20#ifndef IPV4_CLICK_ROUTING_H
21#define IPV4_CLICK_ROUTING_H
22
23#include "ns3/ipv4-routing-protocol.h"
24#include "ns3/ipv4.h"
25#include "ns3/object.h"
26#include "ns3/packet.h"
27#include "ns3/test.h"
28
29#include <sys/time.h>
30#include <sys/types.h>
31
32#ifdef NS3_CLICK
33#include <click/simclick.h>
34#endif
35
36#include <map>
37#include <string>
38
39class ClickTrivialTest;
40class ClickIfidFromNameTest;
41class ClickIpMacAddressFromNameTest;
42
43namespace ns3
44{
45
52class UniformRandomVariable;
53
60{
61#ifdef NS3_CLICK
62 public:
63 // Allow test cases to access private members
64 friend class ::ClickTrivialTest;
65 friend class ::ClickIfidFromNameTest;
66 friend class ::ClickIpMacAddressFromNameTest;
67
68 static TypeId GetTypeId();
69
71 ~Ipv4ClickRouting() override;
72
73 Ptr<UniformRandomVariable> GetRandomVariable();
74
75 protected:
76 void DoInitialize() override;
77
78 public:
79 void DoDispose() override;
80
85 void SetClickFile(std::string clickfile);
86
91 void SetDefines(std::map<std::string, std::string> defines);
92
97 void SetNodeName(std::string name);
98
103 void SetClickRoutingTableElement(std::string name);
104
111 std::string ReadHandler(std::string elementName, std::string handlerName);
112
120 int WriteHandler(std::string elementName, std::string handlerName, std::string writeString);
121
126 void SetPromisc(int ifid);
127
128 private:
129 simclick_node_t* m_simNode;
130
135 static std::map<simclick_node_t*, Ptr<Ipv4ClickRouting>> m_clickInstanceFromSimNode;
136
137 public:
145 static Ptr<Ipv4ClickRouting> GetClickInstanceFromSimNode(simclick_node_t* simnode);
146
147 public:
152 std::map<std::string, std::string> GetDefines();
153
159 int GetInterfaceId(const char* ifname);
160
166 std::string GetIpAddressFromInterfaceId(int ifid);
167
173 std::string GetIpPrefixFromInterfaceId(int ifid);
174
180 std::string GetMacAddressFromInterfaceId(int ifid);
181
186 std::string GetNodeName();
187
192 bool IsInterfaceReady(int ifid);
193
198 void SetIpv4(Ptr<Ipv4> ipv4) override;
199
200 private:
205 void AddSimNodeToClickMapping();
206
210 struct timeval GetTimevalFromNow() const;
211
215 void RunClickEvent();
216
217 public:
222 void HandleScheduleFromClick(const struct timeval* when);
223
231 void HandlePacketFromClick(int ifid, int type, const unsigned char* data, int len);
232
240 void SendPacketToClick(int ifid, int type, const unsigned char* data, int len);
241
248 void Send(Ptr<Packet> p, Ipv4Address src, Ipv4Address dest);
249
256 void Receive(Ptr<Packet> p, Mac48Address receiverAddr, Mac48Address dest);
257
258 // From Ipv4RoutingProtocol
260 const Ipv4Header& header,
261 Ptr<NetDevice> oif,
262 Socket::SocketErrno& sockerr) override;
264 const Ipv4Header& header,
269 ErrorCallback ecb) override;
271 Time::Unit unit = Time::S) const override;
272 void NotifyInterfaceUp(uint32_t interface) override;
273 void NotifyInterfaceDown(uint32_t interface) override;
274 void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address) override;
276
277 private:
278 std::string m_clickFile;
279 std::map<std::string, std::string> m_defines;
280 std::string m_nodeName;
281 std::string m_clickRoutingTableElement;
282
283 std::map<std::string, uint32_t> m_ifaceIdFromName;
284 std::map<std::string, Address> m_ifaceMacFromName;
285 std::map<std::string, Ipv4Address> m_ifaceAddrFromName;
286 bool m_clickInitialised;
287 bool m_nonDefaultName;
288
289 Ptr<Ipv4> m_ipv4;
291#endif /* NS3_CLICK */
292};
293
294} // namespace ns3
295
296#endif /* IPV4_CLICK_ROUTING_H */
Callback template class.
Definition: callback.h:443
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:43
Class to allow a node to use Click for external routing.
Packet header for IPv4.
Definition: ipv4-header.h:34
a class to store IPv4 address information on an interface
Abstract base class for IPv4 routing protocols.
virtual void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address)=0
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, Time::Unit unit=Time::S) const =0
Print the Routing Table entries.
virtual void NotifyInterfaceDown(uint32_t interface)=0
virtual void NotifyInterfaceUp(uint32_t interface)=0
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.
static TypeId GetTypeId()
Get the type ID.
virtual void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)=0
virtual void SetIpv4(Ptr< Ipv4 > ipv4)=0
an EUI-48 address
Definition: mac48-address.h:46
virtual void DoInitialize()
Initialize() implementation.
Definition: object.cc:360
virtual void DoDispose()
Destructor implementation.
Definition: object.cc:353
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:84
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:111
@ S
second
Definition: nstime.h:116
a unique identifier for an interface.
Definition: type-id.h:60
static void Send(Ptr< NetDevice > dev, int level, std::string emuMode)
Definition: fd-emu-send.cc:54
address
Definition: first.py:40
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t data[writeSize]