A Discrete-Event Network Simulator
API
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
40class ClickTrivialTest;
41class ClickIfidFromNameTest;
42class ClickIpMacAddressFromNameTest;
43
44namespace ns3 {
45
51class UniformRandomVariable;
52
59{
60#ifdef NS3_CLICK
61public:
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 (void);
68
70 virtual ~Ipv4ClickRouting ();
71
72 Ptr<UniformRandomVariable> GetRandomVariable (void);
73protected:
74 virtual void DoInitialize (void);
75
76public:
77 virtual void DoDispose ();
78
83 void SetClickFile (std::string clickfile);
84
89 void SetDefines (std::map<std::string, std::string> defines);
90
95 void SetNodeName (std::string name);
96
101 void SetClickRoutingTableElement (std::string name);
102
109 std::string ReadHandler (std::string elementName, std::string handlerName);
110
118 int WriteHandler (std::string elementName, std::string handlerName, std::string writeString);
119
124 void SetPromisc (int ifid);
125
126
127private:
128 simclick_node_t *m_simNode;
129
133 static std::map < simclick_node_t *, Ptr<Ipv4ClickRouting> > m_clickInstanceFromSimNode;
134
135public:
141 static Ptr<Ipv4ClickRouting> GetClickInstanceFromSimNode (simclick_node_t *simnode);
142
143public:
148 std::map<std::string, std::string> GetDefines (void);
149
155 int GetInterfaceId (const char *ifname);
156
162 std::string GetIpAddressFromInterfaceId (int ifid);
163
169 std::string GetIpPrefixFromInterfaceId (int ifid);
170
176 std::string GetMacAddressFromInterfaceId (int ifid);
177
182 std::string GetNodeName ();
183
188 bool IsInterfaceReady (int ifid);
189
194 virtual void SetIpv4 (Ptr<Ipv4> ipv4);
195
196private:
200 void AddSimNodeToClickMapping ();
201
205 struct timeval GetTimevalFromNow () const;
206
210 void RunClickEvent ();
211
212public:
217 void HandleScheduleFromClick (const struct timeval *when);
218
226 void HandlePacketFromClick (int ifid, int type, const unsigned char *data, int len);
227
235 void SendPacketToClick (int ifid, int type, const unsigned char *data, int len);
236
243 void Send (Ptr<Packet> p, Ipv4Address src, Ipv4Address dest);
244
251 void Receive (Ptr<Packet> p, Mac48Address receiverAddr, Mac48Address dest);
252
253 // From Ipv4RoutingProtocol
254 virtual Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr);
255 virtual bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
258 virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream, Time::Unit unit = Time::S) const;
259 virtual void NotifyInterfaceUp (uint32_t interface);
260 virtual void NotifyInterfaceDown (uint32_t interface);
261 virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
263
264private:
265 std::string m_clickFile;
266 std::map < std::string, std::string > m_defines;
267 std::string m_nodeName;
268 std::string m_clickRoutingTableElement;
269
270
271 std::map < std::string, uint32_t > m_ifaceIdFromName;
272 std::map < std::string, Address > m_ifaceMacFromName;
273 std::map < std::string, Ipv4Address > m_ifaceAddrFromName;
274 bool m_clickInitialised;
275 bool m_nonDefaultName;
276
277 Ptr<Ipv4> m_ipv4;
279#endif /* NS3_CLICK */
280};
281
282} // namespace ns3
283
284#endif /* IPV4_CLICK_ROUTING_H */
Callback template class.
Definition: callback.h:1279
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
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
static TypeId GetTypeId(void)
Get the type ID.
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.
virtual void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)=0
virtual void SetIpv4(Ptr< Ipv4 > ipv4)=0
an EUI-48 address
Definition: mac48-address.h:44
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
virtual void DoInitialize(void)
Initialize() implementation.
Definition: object.cc:353
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:109
@ S
second
Definition: nstime.h:114
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:55
address
Definition: first.py:44
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t data[writeSize]