A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
77  void FlushGlobalNixRoutingCache (void);
78 
79 private:
80  /* flushes the cache which stores nix-vector based on
81  * destination IP */
82  void FlushNixCache (void);
83 
84  /* flushes the cache which stores the Ipv4 route
85  * based on the destination IP */
86  void FlushIpv4RouteCache (void);
87 
88  /* upon a run-time topology change caches are
89  * flushed and the total number of neighbors is
90  * reset to zero */
91  void ResetTotalNeighbors (void);
92 
93  /* takes in the source node and dest IP and calls GetNodeByIp,
94  * BFS, accounting for any output interface specified, and finally
95  * BuildNixVector to return the built nix-vector */
97 
98  /* checks the cache based on dest IP for the nix-vector */
100 
101  /* checks the cache based on dest IP for the Ipv4Route */
103 
104  /* given a net-device returns all the adjacent net-devices,
105  * essentially getting the neighbors on that channel */
107 
108  /* iterates through the node list and finds the one
109  * corresponding to the given Ipv4Address */
111 
112  /* Recurses the parent vector, created by BFS and actually builds the nixvector */
113  bool BuildNixVector (const std::vector< Ptr<Node> > & parentVector, uint32_t source, uint32_t dest, Ptr<NixVector> nixVector);
114 
115  /* special variation of BuildNixVector for when a node is sending to itself */
116  bool BuildNixVectorLocal (Ptr<NixVector> nixVector);
117 
118  /* simple iterates through the nodes net-devices and determines
119  * how many neighbors it has */
120  uint32_t FindTotalNeighbors (void);
121 
122  /* determine if the netdevice is bridged */
124 
125 
126  /* Nix index is with respect to the neighbors. The net-device index must be
127  * derived from this */
128  uint32_t FindNetDeviceForNixIndex (uint32_t nodeIndex, Ipv4Address & gatewayIp);
129 
130  /* Breadth first search algorithm
131  * Param1: total number of nodes
132  * Param2: Source Node
133  * Param3: Dest Node
134  * Param4: (returned) Parent vector for retracing routes
135  * Param5: specific output interface to use from source node, if not null
136  * Returns: false if dest not found, true o.w.
137  */
138  bool BFS (uint32_t numberOfNodes,
139  Ptr<Node> source,
140  Ptr<Node> dest,
141  std::vector< Ptr<Node> > & parentVector,
142  Ptr<NetDevice> oif);
143 
144  void DoDispose (void);
145 
146  /* From Ipv4RoutingProtocol */
147  virtual Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr);
148  virtual bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
151  virtual void NotifyInterfaceUp (uint32_t interface);
152  virtual void NotifyInterfaceDown (uint32_t interface);
153  virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
154  virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address);
155  virtual void SetIpv4 (Ptr<Ipv4> ipv4);
156  virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const;
157 
158 
159  /* cache stores nix-vectors based on destination ip */
161 
162  /* cache stores Ipv4Routes based on destination ip */
164 
167 
168  /* total neighbors used for nix-vector to determine
169  * number of bits */
171 };
172 } // namespace ns3
173 
174 #endif /* IPV4_NIX_VECTOR_ROUTING_H */
Callback template class.
Definition: callback.h:920
bool BuildNixVectorLocal(Ptr< NixVector > nixVector)
void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
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)
Ptr< NixVector > GetNixVector(Ptr< Node >, Ipv4Address, Ptr< NetDevice >)
Ptr< NixVector > GetNixVectorInCache(Ipv4Address)
Packet header for IPv4.
Definition: ipv4-header.h:31
void SetNode(Ptr< Node > node)
Set the Node pointer of the node for which this routing protocol is to be placed. ...
void FlushGlobalNixRoutingCache(void)
Called when run-time link topology change occurs which iterates through the node list and flushes any...
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)
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:38
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:49
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)