A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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 <map>
30#include <string>
31#include <sys/time.h>
32#include <sys/types.h>
33
34class ClickTrivialTest;
35class ClickIfidFromNameTest;
36class ClickIpMacAddressFromNameTest;
37// These are in #include <click/simclick.h>,
38// here we just need a forward declaration.
39struct simclick_node;
40typedef struct simclick_node simclick_node_t;
41
42namespace ns3
43{
44
51class UniformRandomVariable;
52
59{
60#ifdef NS3_CLICK
61 public:
62 // Allow test cases to access private members
63 friend class ::ClickTrivialTest;
64 friend class ::ClickIfidFromNameTest;
65 friend class ::ClickIpMacAddressFromNameTest;
66
67 static TypeId GetTypeId();
68
70 ~Ipv4ClickRouting() override;
71
72 Ptr<UniformRandomVariable> GetRandomVariable();
73
74 protected:
75 void DoInitialize() override;
76
77 public:
78 void DoDispose() override;
79
84 void SetClickFile(std::string clickfile);
85
90 void SetDefines(std::map<std::string, std::string> defines);
91
96 void SetNodeName(std::string name);
97
102 void SetClickRoutingTableElement(std::string name);
103
110 std::string ReadHandler(std::string elementName, std::string handlerName);
111
119 int WriteHandler(std::string elementName, std::string handlerName, std::string writeString);
120
125 void SetPromisc(int ifid);
126
127 private:
128 simclick_node_t* m_simNode;
129
134 static std::map<simclick_node_t*, Ptr<Ipv4ClickRouting>> m_clickInstanceFromSimNode;
135
136 public:
144 static Ptr<Ipv4ClickRouting> GetClickInstanceFromSimNode(simclick_node_t* simnode);
145
146 public:
151 std::map<std::string, std::string> GetDefines();
152
158 int GetInterfaceId(const char* ifname);
159
165 std::string GetIpAddressFromInterfaceId(int ifid);
166
172 std::string GetIpPrefixFromInterfaceId(int ifid);
173
179 std::string GetMacAddressFromInterfaceId(int ifid);
180
185 std::string GetNodeName();
186
191 bool IsInterfaceReady(int ifid);
192
197 void SetIpv4(Ptr<Ipv4> ipv4) override;
198
199 private:
204 void AddSimNodeToClickMapping();
205
209 struct timeval GetTimevalFromNow() const;
210
214 void RunClickEvent();
215
216 public:
221 void HandleScheduleFromClick(const struct timeval* when);
222
230 void HandlePacketFromClick(int ifid, int type, const unsigned char* data, int len);
231
239 void SendPacketToClick(int ifid, int type, const unsigned char* data, int len);
240
247 void Send(Ptr<Packet> p, Ipv4Address src, Ipv4Address dest);
248
255 void Receive(Ptr<Packet> p, Mac48Address receiverAddr, Mac48Address dest);
256
257 // From Ipv4RoutingProtocol
259 const Ipv4Header& header,
260 Ptr<NetDevice> oif,
261 Socket::SocketErrno& sockerr) override;
263 const Ipv4Header& header,
265 const UnicastForwardCallback& ucb,
266 const MulticastForwardCallback& mcb,
267 const LocalDeliverCallback& lcb,
268 const ErrorCallback& ecb) override;
270 Time::Unit unit = Time::S) const override;
271 void NotifyInterfaceUp(uint32_t interface) override;
272 void NotifyInterfaceDown(uint32_t interface) override;
273 void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address) override;
274 void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address) override;
275
276 private:
277 std::string m_clickFile;
278 std::map<std::string, std::string> m_defines;
279 std::string m_nodeName;
280 std::string m_clickRoutingTableElement;
281
282 std::map<std::string, uint32_t> m_ifaceIdFromName;
283 std::map<std::string, Address> m_ifaceMacFromName;
284 std::map<std::string, Ipv4Address> m_ifaceAddrFromName;
285 bool m_clickInitialised;
286 bool m_nonDefaultName;
287
288 Ptr<Ipv4> m_ipv4;
290#endif /* NS3_CLICK */
291};
292
293} // namespace ns3
294
295#endif /* IPV4_CLICK_ROUTING_H */
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
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, const UnicastForwardCallback &ucb, const MulticastForwardCallback &mcb, const LocalDeliverCallback &lcb, const 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
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
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:59
static void Send(Ptr< NetDevice > dev, int level, std::string emuMode)
Definition: fd-emu-send.cc:54
struct simclick_node simclick_node_t
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t data[writeSize]