A Discrete-Event Network Simulator
API
ipv4-nix-vector-routing.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 The Georgia Institute of Technology
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: Josh Pelkey <jpelkey@gatech.edu>
19  */
20 
21 #ifndef IPV4_NIX_VECTOR_ROUTING_H
22 #define IPV4_NIX_VECTOR_ROUTING_H
23 
24 #include "ns3/channel.h"
25 #include "ns3/node-container.h"
26 #include "ns3/node-list.h"
27 #include "ns3/net-device-container.h"
28 #include "ns3/ipv4-routing-protocol.h"
29 #include "ns3/ipv4-route.h"
30 #include "ns3/nix-vector.h"
31 #include "ns3/bridge-net-device.h"
32 #include "ns3/nstime.h"
33 
34 #include <map>
35 #include <unordered_map>
36 
37 namespace ns3 {
38 
50 typedef std::map<Ipv4Address, Ptr<NixVector> > NixMap_t;
55 typedef std::map<Ipv4Address, Ptr<Ipv4Route> > Ipv4RouteMap_t;
56 
62 {
63 public:
71  static TypeId GetTypeId (void);
78  void SetNode (Ptr<Node> node);
79 
90  void FlushGlobalNixRoutingCache (void) const;
91 
92 private:
93 
98  void FlushNixCache (void) const;
99 
104  void FlushIpv4RouteCache (void) const;
105 
111  void ResetTotalNeighbors (void);
112 
124 
131 
138 
146  void GetAdjacentNetDevices (Ptr<NetDevice> netDevice, Ptr<Channel> channel, NetDeviceContainer & netDeviceContainer);
147 
155 
164  bool BuildNixVector (const std::vector< Ptr<Node> > & parentVector, uint32_t source, uint32_t dest, Ptr<NixVector> nixVector);
165 
171  bool BuildNixVectorLocal (Ptr<NixVector> nixVector);
172 
178  uint32_t FindTotalNeighbors (void);
179 
186 
187 
195  uint32_t FindNetDeviceForNixIndex (uint32_t nodeIndex, Ipv4Address & gatewayIp);
196 
206  bool BFS (uint32_t numberOfNodes,
207  Ptr<Node> source,
208  Ptr<Node> dest,
209  std::vector< Ptr<Node> > & parentVector,
210  Ptr<NetDevice> oif);
211 
212  void DoDispose (void);
213 
214  /* From Ipv4RoutingProtocol */
215  virtual Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr);
216  virtual bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
219  virtual void NotifyInterfaceUp (uint32_t interface);
220  virtual void NotifyInterfaceDown (uint32_t interface);
221  virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
222  virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address);
223  virtual void SetIpv4 (Ptr<Ipv4> ipv4);
224  virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream, Time::Unit unit = Time::S) const;
225 
229  void CheckCacheStateAndFlush (void) const;
230 
234  void BuildIpv4AddressToNodeMap (void);
235 
240  static bool g_isCacheDirty;
241 
244 
247 
250 
253 
254 
259  {
265  size_t operator() (const Ipv4Address &address) const
266  {
267  return std::hash<uint32_t>()(address.Get ());
268  }
269  };
270 
278  typedef std::unordered_map<Ipv4Address, ns3::Ptr<ns3::Node>, Ipv4AddressHash > Ipv4AddressToNodeMap;
280 };
281 } // namespace ns3
282 
283 #endif /* IPV4_NIX_VECTOR_ROUTING_H */
void FlushGlobalNixRoutingCache(void) const
Called when run-time link topology change occurs which iterates through the node list and flushes any...
Callback template class.
Definition: callback.h:1278
size_t operator()(const Ipv4Address &address) const
operator ()
bool BuildNixVectorLocal(Ptr< NixVector > nixVector)
Special variation of BuildNixVector for when a node is sending to itself.
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const
Print the Routing Table entries.
void DoDispose(void)
Destructor implementation.
Ptr< Ipv4 > m_ipv4
IPv4 object.
void FlushIpv4RouteCache(void) const
Flushes the cache which stores the Ipv4 route based on the destination IP.
std::map< Ipv4Address, Ptr< NixVector > > NixMap_t
Map of Ipv4Address to NixVector.
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
uint32_t FindNetDeviceForNixIndex(uint32_t nodeIndex, Ipv4Address &gatewayIp)
Nix index is with respect to the neighbors.
uint32_t FindTotalNeighbors(void)
Simple iterates through the nodes net-devices and determines how many neighbors it has...
channel
Definition: third.py:92
void FlushNixCache(void) const
Flushes the cache which stores nix-vector based on destination IP.
void GetAdjacentNetDevices(Ptr< NetDevice > netDevice, Ptr< Channel > channel, NetDeviceContainer &netDeviceContainer)
Given a net-device returns all the adjacent net-devices, essentially getting the neighbors on that ch...
Packet header for IPv4.
Definition: ipv4-header.h:33
Ptr< Node > m_node
Node object.
void SetNode(Ptr< Node > node)
Set the Node pointer of the node for which this routing protocol is to be placed. ...
Nix-vector routing protocol.
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:109
holds a vector of ns3::NetDevice pointers
std::unordered_map< Ipv4Address, ns3::Ptr< ns3::Node >, Ipv4AddressHash > Ipv4AddressToNodeMap
Mapping of IPv4 address to ns-3 node.
Ptr< Ipv4Route > GetIpv4RouteInCache(Ipv4Address address)
Checks the cache based on dest IP for the Ipv4Route.
static TypeId GetTypeId(void)
The Interface ID of the Global Router interface.
Ptr< BridgeNetDevice > NetDeviceIsBridged(Ptr< NetDevice > nd) const
Determine if the NetDevice is bridged.
virtual void NotifyInterfaceDown(uint32_t interface)
virtual void NotifyInterfaceUp(uint32_t interface)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
address
Definition: first.py:44
NixMap_t m_nixCache
Cache stores nix-vectors based on destination ip.
static bool g_isCacheDirty
Flag to mark when caches are dirty and need to be flushed.
void ResetTotalNeighbors(void)
Upon a run-time topology change caches are flushed and the total number of neighbors is reset to zero...
virtual void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address)
bool BuildNixVector(const std::vector< Ptr< Node > > &parentVector, uint32_t source, uint32_t dest, Ptr< NixVector > nixVector)
Recurses the parent vector, created by BFS and actually builds the nixvector.
Ptr< NixVector > GetNixVectorInCache(Ipv4Address address)
Checks the cache based on dest IP for the nix-vector.
virtual Ptr< Ipv4Route > RouteOutput(Ptr< Packet > p, const Ipv4Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr)
Query routing cache for an existing route, for an outbound packet.
virtual void SetIpv4(Ptr< Ipv4 > ipv4)
uint32_t m_totalNeighbors
Total neighbors used for nix-vector to determine number of bits.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
a class to store IPv4 address information on an interface
void BuildIpv4AddressToNodeMap(void)
Build map from IPv4 Address to Node for faster lookup.
Ipv4RouteMap_t m_ipv4RouteCache
Cache stores Ipv4Routes based on destination ip.
virtual bool RouteInput(Ptr< const Packet > p, const Ipv4Header &header, Ptr< const NetDevice > idev, UnicastForwardCallback ucb, MulticastForwardCallback mcb, LocalDeliverCallback lcb, ErrorCallback ecb)
Route an input packet (to be forwarded or locally delivered)
Abstract base class for IPv4 routing protocols.
Ptr< NixVector > GetNixVector(Ptr< Node > source, Ipv4Address dest, Ptr< NetDevice > oif)
Takes in the source node and dest IP and calls GetNodeByIp, BFS, accounting for any output interface ...
second
Definition: nstime.h:115
void CheckCacheStateAndFlush(void) const
Flushes routing caches if required.
std::map< Ipv4Address, Ptr< Ipv4Route > > Ipv4RouteMap_t
Map of Ipv4Address to Ipv4Route.
virtual void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)
a unique identifier for an interface.
Definition: type-id.h:58
Ptr< Node > GetNodeByIp(Ipv4Address dest)
Iterates through the node list and finds the one corresponding to the given Ipv4Address.
static Ipv4AddressToNodeMap g_ipv4AddressToNodeMap
bool BFS(uint32_t numberOfNodes, Ptr< Node > source, Ptr< Node > dest, std::vector< Ptr< Node > > &parentVector, Ptr< NetDevice > oif)
Breadth first search algorithm.