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 <map>
25 
26 #include "ns3/channel.h"
27 #include "ns3/node-container.h"
28 #include "ns3/node-list.h"
29 #include "ns3/net-device-container.h"
30 #include "ns3/ipv4-routing-protocol.h"
31 #include "ns3/ipv4-route.h"
32 #include "ns3/nix-vector.h"
33 #include "ns3/bridge-net-device.h"
34 
35 namespace ns3 {
36 
41 typedef std::map<Ipv4Address, Ptr<NixVector> > NixMap_t;
46 typedef std::map<Ipv4Address, Ptr<Ipv4Route> > Ipv4RouteMap_t;
47 
53 {
54 public:
62  static TypeId GetTypeId (void);
69  void SetNode (Ptr<Node> node);
70 
81  void FlushGlobalNixRoutingCache (void) const;
82 
83 private:
84 
85  /* flushes the cache which stores nix-vector based on
86  * destination IP */
87  void FlushNixCache (void) const;
88 
89  /* flushes the cache which stores the Ipv4 route
90  * based on the destination IP */
91  void FlushIpv4RouteCache (void) const;
92 
93  /* upon a run-time topology change caches are
94  * flushed and the total number of neighbors is
95  * reset to zero */
96  void ResetTotalNeighbors (void);
97 
98  /* takes in the source node and dest IP and calls GetNodeByIp,
99  * BFS, accounting for any output interface specified, and finally
100  * BuildNixVector to return the built nix-vector */
102 
103  /* checks the cache based on dest IP for the nix-vector */
105 
106  /* checks the cache based on dest IP for the Ipv4Route */
108 
109  /* given a net-device returns all the adjacent net-devices,
110  * essentially getting the neighbors on that channel */
112 
113  /* iterates through the node list and finds the one
114  * corresponding to the given Ipv4Address */
116 
117  /* Recurses the parent vector, created by BFS and actually builds the nixvector */
118  bool BuildNixVector (const std::vector< Ptr<Node> > & parentVector, uint32_t source, uint32_t dest, Ptr<NixVector> nixVector);
119 
120  /* special variation of BuildNixVector for when a node is sending to itself */
121  bool BuildNixVectorLocal (Ptr<NixVector> nixVector);
122 
123  /* simple iterates through the nodes net-devices and determines
124  * how many neighbors it has */
125  uint32_t FindTotalNeighbors (void);
126 
127  /* determine if the netdevice is bridged */
129 
130 
131  /* Nix index is with respect to the neighbors. The net-device index must be
132  * derived from this */
133  uint32_t FindNetDeviceForNixIndex (uint32_t nodeIndex, Ipv4Address & gatewayIp);
134 
135  /* Breadth first search algorithm
136  * Param1: total number of nodes
137  * Param2: Source Node
138  * Param3: Dest Node
139  * Param4: (returned) Parent vector for retracing routes
140  * Param5: specific output interface to use from source node, if not null
141  * Returns: false if dest not found, true o.w.
142  */
143  bool BFS (uint32_t numberOfNodes,
144  Ptr<Node> source,
145  Ptr<Node> dest,
146  std::vector< Ptr<Node> > & parentVector,
147  Ptr<NetDevice> oif);
148 
149  void DoDispose (void);
150 
151  /* From Ipv4RoutingProtocol */
152  virtual Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr);
153  virtual bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
156  virtual void NotifyInterfaceUp (uint32_t interface);
157  virtual void NotifyInterfaceDown (uint32_t interface);
158  virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
159  virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address);
160  virtual void SetIpv4 (Ptr<Ipv4> ipv4);
161  virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const;
162 
163  /*
164  * Flushes routing caches if required.
165  */
166  void CheckCacheStateAndFlush (void) const;
167 
168  /*
169  * Flag to mark when caches are dirty and need to be flushed.
170  * Used for lazy cleanup of caches when there are many topology changes.
171  */
172  static bool g_isCacheDirty;
173 
174  /* Cache stores nix-vectors based on destination ip */
175  mutable NixMap_t m_nixCache;
176 
177  /* Cache stores Ipv4Routes based on destination ip */
178  mutable Ipv4RouteMap_t m_ipv4RouteCache;
179 
182 
183  /* Total neighbors used for nix-vector to determine
184  * number of bits */
186 };
187 } // namespace ns3
188 
189 #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...
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
Callback template class.
Definition: callback.h:1176
bool BuildNixVectorLocal(Ptr< NixVector > nixVector)
void DoDispose(void)
Destructor implementation.
std::map< Ipv4Address, Ptr< NixVector > > NixMap_t
Map of Ipv4Address to NixVector.
uint32_t FindNetDeviceForNixIndex(uint32_t nodeIndex, Ipv4Address &gatewayIp)
Ptr< NixVector > GetNixVector(Ptr< Node >, Ipv4Address, Ptr< NetDevice >)
Ptr< NixVector > GetNixVectorInCache(Ipv4Address)
Packet header for IPv4.
Definition: ipv4-header.h:33
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.
Ptr< Node > GetNodeByIp(Ipv4Address)
holds a vector of ns3::NetDevice pointers
Ptr< BridgeNetDevice > NetDeviceIsBridged(Ptr< NetDevice > nd) const
static TypeId GetTypeId(void)
The Interface ID of the Global Router interface.
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.
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)
void GetAdjacentNetDevices(Ptr< NetDevice >, Ptr< Channel >, NetDeviceContainer &)
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)
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
a class to store IPv4 address information on an interface
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.
tuple address
Definition: first.py:37
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
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream) const
Print the Routing Table entries.
Ptr< Ipv4Route > GetIpv4RouteInCache(Ipv4Address)
bool BFS(uint32_t numberOfNodes, Ptr< Node > source, Ptr< Node > dest, std::vector< Ptr< Node > > &parentVector, Ptr< NetDevice > oif)