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
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
58{
59 public:
60 // Allow test cases to access private members
61 friend class ::ClickTrivialTest;
62 friend class ::ClickIfidFromNameTest;
63 friend class ::ClickIpMacAddressFromNameTest;
64
70 static TypeId GetTypeId();
71
74 ~Ipv4ClickRouting() override;
75
82
83 protected:
84 void DoInitialize() override;
85
86 public:
87 void DoDispose() override;
88
93 void SetClickFile(std::string clickfile);
94
99 void SetDefines(std::map<std::string, std::string> defines);
100
105 void SetNodeName(std::string name);
106
111 void SetClickRoutingTableElement(std::string name);
112
120 std::string ReadHandler(std::string elementName, std::string handlerName);
121
130 int WriteHandler(std::string elementName, std::string handlerName, std::string writeString);
131
136 void SetPromisc(int ifid);
137
138 private:
141
146 static std::map<simclick_node_t*, Ptr<Ipv4ClickRouting>> m_clickInstanceFromSimNode;
147
148 public:
157
158 public:
163 std::map<std::string, std::string> GetDefines();
164
170 int GetInterfaceId(const char* ifname);
171
177 std::string GetIpAddressFromInterfaceId(int ifid);
178
184 std::string GetIpPrefixFromInterfaceId(int ifid);
185
191 std::string GetMacAddressFromInterfaceId(int ifid);
192
197 std::string GetNodeName();
198
204 bool IsInterfaceReady(int ifid);
205
210 void SetIpv4(Ptr<Ipv4> ipv4) override;
211
212 private:
218
223 struct timeval GetTimevalFromNow() const;
224
228 void RunClickEvent();
229
230 public:
235 void HandleScheduleFromClick(const struct timeval* when);
236
244 void HandlePacketFromClick(int ifid, int type, const unsigned char* data, int len);
245
253 void SendPacketToClick(int ifid, int type, const unsigned char* data, int len);
254
261 void Send(Ptr<Packet> p, Ipv4Address src, Ipv4Address dest);
262
269 void Receive(Ptr<Packet> p, Mac48Address receiverAddr, Mac48Address dest);
270
271 // From Ipv4RoutingProtocol
273 const Ipv4Header& header,
274 Ptr<NetDevice> oif,
275 Socket::SocketErrno& sockerr) override;
277 const Ipv4Header& header,
279 const UnicastForwardCallback& ucb,
280 const MulticastForwardCallback& mcb,
281 const LocalDeliverCallback& lcb,
282 const ErrorCallback& ecb) override;
284 Time::Unit unit = Time::S) const override;
285 void NotifyInterfaceUp(uint32_t interface) override;
286 void NotifyInterfaceDown(uint32_t interface) override;
287 void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address) override;
288 void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address) override;
289
290 private:
291 std::string m_clickFile;
292 std::map<std::string, std::string> m_defines;
293 std::string m_nodeName;
295
298
301};
302
303} // namespace ns3
304
305#endif /* IPV4_CLICK_ROUTING_H */
Click interface ID from name test.
Click IP MAC address from name test.
Click trivial test.
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.
void SetDefines(std::map< std::string, std::string > defines)
Click defines to be used by the node's Click Instance.
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) override
Route an input packet (to be forwarded or locally delivered)
std::string GetIpAddressFromInterfaceId(int ifid)
Provides for SIMCLICK_IPADDR_FROM_NAME.
void RunClickEvent()
This method has to be scheduled every time Click calls SIMCLICK_SCHEDULE.
Ipv4ClickRouting()
Constructor.
simclick_node_t * m_simNode
Pointer to the simclick node.
bool IsInterfaceReady(int ifid)
Provides for SIMCLICK_IF_READY.
int WriteHandler(std::string elementName, std::string handlerName, std::string writeString)
Write Handler interface for a node's Click Elements.
void AddSimNodeToClickMapping()
Used internally in DoInitialize () to Add a mapping to m_clickInstanceFromSimNode mapping.
bool m_clickInitialised
Whether click has been initialized.
void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address) override
void SetPromisc(int ifid)
Sets an interface to run on promiscuous mode.
void DoDispose() override
Destructor implementation.
std::string m_nodeName
Name of the node.
void DoInitialize() override
Initialize() implementation.
std::string GetMacAddressFromInterfaceId(int ifid)
Provides for SIMCLICK_MACADDR_FROM_NAME.
void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address) override
bool m_nonDefaultName
Whether a non-default name has been set.
void Send(Ptr< Packet > p, Ipv4Address src, Ipv4Address dest)
Allow a higher layer to send data through Click.
Ptr< Ipv4 > m_ipv4
Pointer to the IPv4 object.
void NotifyInterfaceDown(uint32_t interface) override
struct timeval GetTimevalFromNow() const
Get current simulation time as a timeval.
std::map< std::string, std::string > GetDefines()
Provides for SIMCLICK_GET_DEFINES.
Ptr< Ipv4Route > RouteOutput(Ptr< Packet > p, const Ipv4Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr) override
Query routing cache for an existing route, for an outbound packet.
void SetClickFile(std::string clickfile)
Click configuration file to be used by the node's Click Instance.
Ptr< UniformRandomVariable > m_random
Uniform random variable.
int GetInterfaceId(const char *ifname)
Provides for SIMCLICK_IFID_FROM_NAME.
void SetIpv4(Ptr< Ipv4 > ipv4) override
Set the Ipv4 instance to be used.
std::map< std::string, std::string > m_defines
Defines for .click configuration file parsing.
void SendPacketToClick(int ifid, int type, const unsigned char *data, int len)
Sends a packet to Click.
static Ptr< Ipv4ClickRouting > GetClickInstanceFromSimNode(simclick_node_t *simnode)
Allows the Click service methods, which reside outside Ipv4ClickRouting, to get the required Ipv4Clic...
void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const override
Print the Routing Table entries.
std::string m_clickFile
Name of .click configuration file.
std::string ReadHandler(std::string elementName, std::string handlerName)
Read Handler interface for a node's Click Elements.
static TypeId GetTypeId()
Get type ID.
void HandleScheduleFromClick(const struct timeval *when)
Schedules simclick_click_run to run at the given time.
static std::map< simclick_node_t *, Ptr< Ipv4ClickRouting > > m_clickInstanceFromSimNode
Provide a mapping between the node reference used by Click and the corresponding Ipv4ClickRouting ins...
std::string GetIpPrefixFromInterfaceId(int ifid)
Provides for SIMCLICK_IPPREFIX_FROM_NAME.
void HandlePacketFromClick(int ifid, int type, const unsigned char *data, int len)
Receives a packet from Click.
void SetClickRoutingTableElement(std::string name)
Name of the routing table element being used by Click.
void SetNodeName(std::string name)
Name of the node as to be used by Click.
Ptr< UniformRandomVariable > GetRandomVariable()
Get the uniform random variable.
void Receive(Ptr< Packet > p, Mac48Address receiverAddr, Mac48Address dest)
Allow a lower layer to send data to Click.
std::string GetNodeName()
Provides for SIMCLICK_GET_NODE_NAME.
void NotifyInterfaceUp(uint32_t interface) override
std::string m_clickRoutingTableElement
Name of the routing table element.
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.
an EUI-48 address
Definition: mac48-address.h:46
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
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
struct simclick_node simclick_node_t
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t data[writeSize]