5224
|
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/bridge-net-device.h"
|
|
33 |
|
|
34 |
namespace ns3 {
|
|
35 |
|
|
36 |
typedef std::map<Ipv4Address, Ptr<NixVector> > NixMap_t;
|
|
37 |
typedef std::map<Ipv4Address, Ptr<Ipv4Route> > Ipv4RouteMap_t;
|
|
38 |
|
|
39 |
class Ipv4NixVectorRouting : public Ipv4RoutingProtocol
|
|
40 |
{
|
|
41 |
public:
|
|
42 |
Ipv4NixVectorRouting ();
|
|
43 |
~Ipv4NixVectorRouting ();
|
|
44 |
/**
|
|
45 |
* @brief The Interface ID of the Global Router interface.
|
|
46 |
*
|
|
47 |
* @see Object::GetObject ()
|
|
48 |
*/
|
|
49 |
static TypeId GetTypeId (void);
|
|
50 |
/**
|
|
51 |
* @brief Set the Node pointer of the node for which this
|
|
52 |
* routing protocol is to be placed
|
|
53 |
*
|
|
54 |
* @param node Node pointer
|
|
55 |
*/
|
|
56 |
void SetNode (Ptr<Node>);
|
|
57 |
|
|
58 |
/**
|
|
59 |
* @brief Called when run-time link topology change occurs
|
|
60 |
* which iterates through the node list and flushes any
|
|
61 |
* nix vector caches
|
|
62 |
*
|
|
63 |
*/
|
|
64 |
void FlushGlobalNixRoutingCache (void);
|
|
65 |
|
|
66 |
private:
|
|
67 |
/* flushes the cache which stores nix-vector based on
|
|
68 |
* destination IP */
|
|
69 |
void FlushNixCache (void);
|
|
70 |
|
|
71 |
/* flushes the cache which stores the Ipv4 route
|
|
72 |
* based on the destination IP */
|
|
73 |
void FlushIpv4RouteCache (void);
|
|
74 |
|
|
75 |
/* upon a run-time topology change caches are
|
|
76 |
* flushed and the total number of neighbors is
|
|
77 |
* reset to zero */
|
|
78 |
void ResetTotalNeighbors (void);
|
|
79 |
|
|
80 |
/* takes in the source node and dest IP and calls GetNodeByIp,
|
|
81 |
* BFS, and BuildNixVector to finally return the built
|
|
82 |
* nix-vector */
|
|
83 |
Ptr<NixVector> GetNixVector (Ptr<Node>, Ipv4Address);
|
|
84 |
|
|
85 |
/* checks the cache based on dest IP for the nix-vector */
|
|
86 |
Ptr<NixVector> GetNixVectorInCache (Ipv4Address);
|
|
87 |
|
|
88 |
/* checks the cache based on dest IP for the Ipv4Route */
|
|
89 |
Ptr<Ipv4Route> GetIpv4RouteInCache (Ipv4Address);
|
|
90 |
|
|
91 |
/* given a net-device returns all the adjacent net-devices,
|
|
92 |
* essentially getting the neighbors on that channel */
|
|
93 |
void GetAdjacentNetDevices (Ptr<NetDevice>, Ptr<Channel>, NetDeviceContainer &);
|
|
94 |
|
|
95 |
/* iterates through the node list and finds the one
|
|
96 |
* corresponding to the given Ipv4Address */
|
|
97 |
Ptr<Node> GetNodeByIp (Ipv4Address);
|
|
98 |
|
|
99 |
/* Recurses the parent vector, created by BFS and actually builds the nixvector */
|
|
100 |
bool BuildNixVector (const std::vector< Ptr<Node> > & parentVector, uint32_t source, uint32_t dest, Ptr<NixVector> nixVector);
|
|
101 |
|
|
102 |
/* special variation of BuildNixVector for when a node is sending to itself */
|
|
103 |
bool BuildNixVectorLocal (Ptr<NixVector> nixVector);
|
|
104 |
|
|
105 |
/* simple iterates through the nodes net-devices and determines
|
|
106 |
* how many neighbors it has */
|
|
107 |
uint32_t FindTotalNeighbors (void);
|
|
108 |
|
|
109 |
/* determine if the netdevice is bridged */
|
|
110 |
Ptr<BridgeNetDevice> NetDeviceIsBridged (Ptr<NetDevice> nd) const;
|
|
111 |
|
|
112 |
|
|
113 |
/* Nix index is with respect to the neighbors. The net-device index must be
|
|
114 |
* derived from this */
|
|
115 |
uint32_t FindNetDeviceForNixIndex (uint32_t nodeIndex, Ipv4Address & gatewayIp);
|
|
116 |
|
|
117 |
/* Breadth first search algorithm
|
|
118 |
* Param1: Vector containing all nodes in the graph
|
|
119 |
* Param2: Source Node
|
|
120 |
* Param3: Dest Node
|
|
121 |
* Param4: (returned) Parent vector for retracing routes
|
|
122 |
* Returns: false if dest not found, true o.w.
|
|
123 |
*/
|
|
124 |
bool BFS (uint32_t numberOfNodes,
|
|
125 |
Ptr<Node> source,
|
|
126 |
Ptr<Node> dest,
|
|
127 |
std::vector< Ptr<Node> > & parentVector);
|
|
128 |
|
|
129 |
void DoDispose (void);
|
|
130 |
|
|
131 |
/* From Ipv4RoutingProtocol */
|
|
132 |
virtual Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header, uint32_t oif, Socket::SocketErrno &sockerr);
|
|
133 |
virtual bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
|
|
134 |
UnicastForwardCallback ucb, MulticastForwardCallback mcb,
|
|
135 |
LocalDeliverCallback lcb, ErrorCallback ecb);
|
|
136 |
virtual void NotifyInterfaceUp (uint32_t interface);
|
|
137 |
virtual void NotifyInterfaceDown (uint32_t interface);
|
|
138 |
virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);
|
|
139 |
virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address);
|
|
140 |
virtual void SetIpv4 (Ptr<Ipv4> ipv4);
|
|
141 |
|
|
142 |
|
|
143 |
/* cache stores nix-vectors based on destination ip */
|
|
144 |
NixMap_t m_nixCache;
|
|
145 |
|
|
146 |
/* cache stores Ipv4Routes based on destination ip */
|
|
147 |
Ipv4RouteMap_t m_ipv4RouteCache;
|
|
148 |
|
|
149 |
Ptr<Ipv4> m_ipv4;
|
|
150 |
Ptr<Node> m_node;
|
|
151 |
|
|
152 |
/* total neighbors used for nix-vector to determine
|
|
153 |
* number of bits */
|
|
154 |
uint32_t m_totalNeighbors;
|
|
155 |
};
|
|
156 |
} // namepace ns3
|
|
157 |
#endif
|