A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ipv4-nix-vector-routing.h
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 
40 typedef std::map<Ipv4Address, Ptr<NixVector> > NixMap_t;
44 typedef std::map<Ipv4Address, Ptr<Ipv4Route> > Ipv4RouteMap_t;
45 
50 {
51 public:
59  static TypeId GetTypeId (void);
66  void SetNode (Ptr<Node> node);
67 
74  void FlushGlobalNixRoutingCache (void);
75 
76 private:
77  /* flushes the cache which stores nix-vector based on
78  * destination IP */
79  void FlushNixCache (void);
80 
81  /* flushes the cache which stores the Ipv4 route
82  * based on the destination IP */
83  void FlushIpv4RouteCache (void);
84 
85  /* upon a run-time topology change caches are
86  * flushed and the total number of neighbors is
87  * reset to zero */
88  void ResetTotalNeighbors (void);
89 
90  /* takes in the source node and dest IP and calls GetNodeByIp,
91  * BFS, accounting for any output interface specified, and finally
92  * BuildNixVector to return the built nix-vector */
94 
95  /* checks the cache based on dest IP for the nix-vector */
96  Ptr<NixVector> GetNixVectorInCache (Ipv4Address);
97 
98  /* checks the cache based on dest IP for the Ipv4Route */
99  Ptr<Ipv4Route> GetIpv4RouteInCache (Ipv4Address);
100 
101  /* given a net-device returns all the adjacent net-devices,
102  * essentially getting the neighbors on that channel */
103  void GetAdjacentNetDevices (Ptr<NetDevice>, Ptr<Channel>, NetDeviceContainer &);
104 
105  /* iterates through the node list and finds the one
106  * corresponding to the given Ipv4Address */
107  Ptr<Node> GetNodeByIp (Ipv4Address);
108 
109  /* Recurses the parent vector, created by BFS and actually builds the nixvector */
110  bool BuildNixVector (const std::vector< Ptr<Node> > & parentVector, uint32_t source, uint32_t dest, Ptr<NixVector> nixVector);
111 
112  /* special variation of BuildNixVector for when a node is sending to itself */
113  bool BuildNixVectorLocal (Ptr<NixVector> nixVector);
114 
115  /* simple iterates through the nodes net-devices and determines
116  * how many neighbors it has */
117  uint32_t FindTotalNeighbors (void);
118 
119  /* determine if the netdevice is bridged */
120  Ptr<BridgeNetDevice> NetDeviceIsBridged (Ptr<NetDevice> nd) const;
121 
122 
123  /* Nix index is with respect to the neighbors. The net-device index must be
124  * derived from this */
125  uint32_t FindNetDeviceForNixIndex (uint32_t nodeIndex, Ipv4Address & gatewayIp);
126 
127  /* Breadth first search algorithm
128  * Param1: total number of nodes
129  * Param2: Source Node
130  * Param3: Dest Node
131  * Param4: (returned) Parent vector for retracing routes
132  * Param5: specific output interface to use from source node, if not null
133  * Returns: false if dest not found, true o.w.
134  */
135  bool BFS (uint32_t numberOfNodes,
136  Ptr<Node> source,
137  Ptr<Node> dest,
138  std::vector< Ptr<Node> > & parentVector,
139  Ptr<NetDevice> oif);
140 
141  void DoDispose (void);
142 
143  /* From Ipv4RoutingProtocol */
144  virtual Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<NetDevice> oif, Socket::SocketErrno &sockerr);
145  virtual bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
148  virtual void NotifyInterfaceUp (uint32_t interface);
149  virtual void NotifyInterfaceDown (uint32_t interface);
150  virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
151  virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address);
152  virtual void SetIpv4 (Ptr<Ipv4> ipv4);
153  virtual void PrintRoutingTable (Ptr<OutputStreamWrapper> stream) const;
154 
155 
156  /* cache stores nix-vectors based on destination ip */
157  NixMap_t m_nixCache;
158 
159  /* cache stores Ipv4Routes based on destination ip */
160  Ipv4RouteMap_t m_ipv4RouteCache;
161 
162  Ptr<Ipv4> m_ipv4;
163  Ptr<Node> m_node;
164 
165  /* total neighbors used for nix-vector to determine
166  * number of bits */
167  uint32_t m_totalNeighbors;
168 };
169 } // namespace ns3
170 
171 #endif /* IPV4_NIX_VECTOR_ROUTING_H */
Callback template class.
Definition: callback.h:369
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...
holds a vector of ns3::NetDevice pointers
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)
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.
virtual void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)
a unique identifier for an interface.
Definition: type-id.h:44
std::map< Ipv4Address, Ptr< Ipv4Route > > Ipv4RouteMap_t
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream) const
Print the Routing Table entries.
std::map< Ipv4Address, Ptr< NixVector > > NixMap_t