Nix-vector routing protocol. More...
#include "nix-vector-routing.h"
Public Member Functions | |
NixVectorRouting () | |
~NixVectorRouting () | |
void | FlushGlobalNixRoutingCache () const |
Called when run-time link topology change occurs which iterates through the node list and flushes any nix vector caches. | |
void | PrintRoutingPath (Ptr< Node > source, IpAddress dest, Ptr< OutputStreamWrapper > stream, Time::Unit unit) const |
Print the Routing Path according to Nix Routing. | |
void | SetNode (Ptr< Node > node) |
Set the Node pointer of the node for which this routing protocol is to be placed. | |
Static Public Member Functions | |
static TypeId | GetTypeId () |
The Interface ID of the Global Router interface. | |
Private Types | |
typedef Callback< void, Ptr< const Packet >, const IpHeader &, Socket::SocketErrno > | ErrorCallback |
Callback for routing errors (e.g., no route found) | |
using | Ip = typename std::conditional_t<IsIpv4, Ipv4, Ipv6> |
Alias for Ipv4 and Ipv6 classes. | |
using | IpAddress = typename std::conditional_t<IsIpv4, Ipv4Address, Ipv6Address> |
Alias for Ipv4Address and Ipv6Address classes. | |
using | IpAddressHash = typename std::conditional_t<IsIpv4, Ipv4AddressHash, Ipv6AddressHash> |
Alias for Ipv4AddressHash and Ipv6AddressHash classes. | |
typedef std::unordered_map< IpAddress, ns3::Ptr< ns3::Node >, IpAddressHash > | IpAddressToNodeMap |
Mapping of IP address to ns-3 node. | |
using | IpHeader = typename std::conditional_t<IsIpv4, Ipv4Header, Ipv6Header> |
Alias for Ipv4Header and Ipv6Header classes. | |
using | IpInterface = typename std::conditional_t<IsIpv4, Ipv4Interface, Ipv6Interface> |
Alias for Ipv4Interface and Ipv6Interface classes. | |
using | IpInterfaceAddress |
Alias for Ipv4InterfaceAddress and Ipv6InterfaceAddress classes. | |
using | IpL3Protocol = typename std::conditional_t<IsIpv4, Ipv4L3Protocol, Ipv6L3Protocol> |
Alias for Ipv4L3Protocol and Ipv4L3Protocol classes. | |
using | IpRoute = typename std::conditional_t<IsIpv4, Ipv4Route, Ipv6Route> |
Alias for Ipv4Route and Ipv6Route classes. | |
typedef std::map< IpAddress, Ptr< IpRoute > > | IpRouteMap_t |
Map of IpAddress to IpRoute. | |
typedef Callback< void, Ptr< const Packet >, const IpHeader &, uint32_t > | LocalDeliverCallback |
Callback for packets to be locally delivered. | |
typedef std::conditional_t< IsIpv4, MulticastForwardCallbackv4, MulticastForwardCallbackv6 > | MulticastForwardCallback |
Callback for multicast packets to be forwarded. | |
typedef Callback< void, Ptr< Ipv4MulticastRoute >, Ptr< const Packet >, const IpHeader & > | MulticastForwardCallbackv4 |
Callback for IPv4 multicast packets to be forwarded. | |
typedef Callback< void, Ptr< const NetDevice >, Ptr< Ipv6MulticastRoute >, Ptr< const Packet >, const IpHeader & > | MulticastForwardCallbackv6 |
Callback for IPv6 multicast packets to be forwarded. | |
typedef std::unordered_map< Ptr< NetDevice >, Ptr< IpInterface > > | NetDeviceToIpInterfaceMap |
Mapping of Ptr<NetDevice> to Ptr<IpInterface>. | |
typedef std::map< IpAddress, Ptr< NixVector > > | NixMap_t |
Map of IpAddress to NixVector. | |
typedef std::conditional_t< IsIpv4, UnicastForwardCallbackv4, UnicastForwardCallbackv6 > | UnicastForwardCallback |
Callback for unicast packets to be forwarded. | |
typedef Callback< void, Ptr< IpRoute >, Ptr< const Packet >, const IpHeader & > | UnicastForwardCallbackv4 |
Callback for IPv4 unicast packets to be forwarded. | |
typedef Callback< void, Ptr< const NetDevice >, Ptr< IpRoute >, Ptr< const Packet >, const IpHeader & > | UnicastForwardCallbackv6 |
Callback for IPv6 unicast packets to be forwarded. | |
Private Member Functions | |
bool | BFS (uint32_t numberOfNodes, Ptr< Node > source, Ptr< Node > dest, std::vector< Ptr< Node > > &parentVector, Ptr< NetDevice > oif) const |
Breadth first search algorithm. | |
void | BuildIpAddressToNodeMap () const |
Build map from IP Address to Node for faster lookup. | |
bool | BuildNixVector (const std::vector< Ptr< Node > > &parentVector, uint32_t source, uint32_t dest, Ptr< NixVector > nixVector) const |
Recurses the T vector, created by BFS and actually builds the nixvector. | |
void | CheckCacheStateAndFlush () const |
Flushes routing caches if required. | |
void | DoDispose () |
void | DoInitialize () |
uint32_t | FindNetDeviceForNixIndex (Ptr< Node > node, uint32_t nodeIndex, IpAddress &gatewayIp) const |
Nix index is with respect to the neighbors. | |
uint32_t | FindTotalNeighbors (Ptr< Node > node) const |
Simply iterates through the nodes net-devices and determines how many neighbors the node has. | |
void | FlushIpRouteCache () const |
Flushes the cache which stores the Ip route based on the destination IP. | |
void | FlushNixCache () const |
Flushes the cache which stores nix-vector based on destination IP. | |
void | GetAdjacentNetDevices (Ptr< NetDevice > netDevice, Ptr< Channel > channel, NetDeviceContainer &netDeviceContainer) const |
Given a net-device returns all the adjacent net-devices, essentially getting the neighbors on that channel. | |
Ptr< IpInterface > | GetInterfaceByNetDevice (Ptr< NetDevice > netDevice) const |
Iterates through the node list and finds the one corresponding to the given IpAddress. | |
Ptr< IpRoute > | GetIpRouteInCache (IpAddress address) |
Checks the cache based on dest IP for the IpRoute. | |
Ptr< NixVector > | GetNixVector (Ptr< Node > source, IpAddress dest, Ptr< NetDevice > oif) const |
Takes in the source node and dest IP and calls GetNodeByIp, BFS, accounting for any output interface specified, and finally BuildNixVector to return the built nix-vector. | |
Ptr< NixVector > | GetNixVectorInCache (const IpAddress &address, bool &foundInCache) const |
Checks the cache based on dest IP for the nix-vector. | |
Ptr< Node > | GetNodeByIp (IpAddress dest) const |
Iterates through the node list and finds the one corresponding to the given IpAddress. | |
Ptr< BridgeNetDevice > | NetDeviceIsBridged (Ptr< NetDevice > nd) const |
Determine if the NetDevice is bridged. | |
virtual void | NotifyAddAddress (uint32_t interface, IpInterfaceAddress address) |
virtual void | NotifyAddRoute (IpAddress dst, Ipv6Prefix mask, IpAddress nextHop, uint32_t interface, IpAddress prefixToUse=IpAddress::GetZero()) |
Notify a new route. | |
virtual void | NotifyInterfaceDown (uint32_t interface) |
virtual void | NotifyInterfaceUp (uint32_t interface) |
virtual void | NotifyRemoveAddress (uint32_t interface, IpInterfaceAddress address) |
virtual void | NotifyRemoveRoute (IpAddress dst, Ipv6Prefix mask, IpAddress nextHop, uint32_t interface, IpAddress prefixToUse=IpAddress::GetZero()) |
Notify route removing. | |
virtual void | PrintRoutingTable (Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const |
Print the Routing Table entries. | |
void | ResetTotalNeighbors () |
Upon a run-time topology change caches are flushed and the total number of neighbors is reset to zero. | |
virtual bool | RouteInput (Ptr< const Packet > p, const IpHeader &header, Ptr< const NetDevice > idev, const UnicastForwardCallback &ucb, const MulticastForwardCallback &mcb, const LocalDeliverCallback &lcb, const ErrorCallback &ecb) |
Route an input packet (to be forwarded or locally delivered) | |
virtual Ptr< IpRoute > | RouteOutput (Ptr< Packet > p, const IpHeader &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr) |
Query routing cache for an existing route, for an outbound packet. | |
virtual void | SetIpv4 (Ptr< Ip > ipv4) |
Typically, invoked directly or indirectly from ns3::Ipv4::SetRoutingProtocol. | |
virtual void | SetIpv6 (Ptr< Ip > ipv6) |
Typically, invoked directly or indirectly from ns3::Ipv6::SetRoutingProtocol. | |
Private Attributes | |
Ptr< Ip > | m_ip |
IP object. | |
IpRouteMap_t | m_ipRouteCache |
Cache stores IpRoutes based on destination ip. | |
NixMap_t | m_nixCache |
Cache stores nix-vectors based on destination ip. | |
Ptr< Node > | m_node |
Node object. | |
uint32_t | m_totalNeighbors |
Total neighbors used for nix-vector to determine number of bits. | |
Static Private Attributes | |
static uint32_t | g_epoch = 1 |
Nix Epoch, incremented each time a flush is performed. | |
static IpAddressToNodeMap | g_ipAddressToNodeMap |
Address to node map. | |
static bool | g_isCacheDirty = false |
Flag to mark when caches are dirty and need to be flushed. | |
static NetDeviceToIpInterfaceMap | g_netdeviceToIpInterfaceMap |
NetDevice pointer to IpInterface pointer map. | |
static constexpr bool | IsIpv4 = std::is_same_v<Ipv4RoutingProtocol, T> |
Alias for determining whether the parent is Ipv4RoutingProtocol or Ipv6RoutingProtocol. | |
Nix-vector routing protocol.
Definition at line 58 of file nix-vector-routing.h.
|
private |
Callback for routing errors (e.g., no route found)
Definition at line 313 of file nix-vector-routing.h.
|
private |
Alias for Ipv4 and Ipv6 classes.
Definition at line 66 of file nix-vector-routing.h.
|
private |
Alias for Ipv4Address and Ipv6Address classes.
Definition at line 69 of file nix-vector-routing.h.
|
private |
Alias for Ipv4AddressHash and Ipv6AddressHash classes.
Definition at line 75 of file nix-vector-routing.h.
|
private |
Mapping of IP address to ns-3 node.
Used to avoid linear searching of nodes/devices to find a node in GetNodeByIp() method. NIX vector routing assumes IP addresses are unique so mapping can be done without duplication.
Definition at line 502 of file nix-vector-routing.h.
|
private |
Alias for Ipv4Header and Ipv6Header classes.
Definition at line 78 of file nix-vector-routing.h.
|
private |
Alias for Ipv4Interface and Ipv6Interface classes.
Definition at line 85 of file nix-vector-routing.h.
|
private |
Alias for Ipv4InterfaceAddress and Ipv6InterfaceAddress classes.
Definition at line 81 of file nix-vector-routing.h.
|
private |
Alias for Ipv4L3Protocol and Ipv4L3Protocol classes.
Definition at line 88 of file nix-vector-routing.h.
|
private |
Alias for Ipv4Route and Ipv6Route classes.
Definition at line 72 of file nix-vector-routing.h.
|
private |
Map of IpAddress to IpRoute.
Definition at line 278 of file nix-vector-routing.h.
|
private |
Callback for packets to be locally delivered.
Definition at line 310 of file nix-vector-routing.h.
|
private |
Callback for multicast packets to be forwarded.
Definition at line 307 of file nix-vector-routing.h.
|
private |
Callback for IPv4 multicast packets to be forwarded.
Definition at line 294 of file nix-vector-routing.h.
|
private |
Callback for IPv6 multicast packets to be forwarded.
Definition at line 302 of file nix-vector-routing.h.
|
private |
Mapping of Ptr<NetDevice> to Ptr<IpInterface>.
Definition at line 506 of file nix-vector-routing.h.
|
private |
Map of IpAddress to NixVector.
Definition at line 276 of file nix-vector-routing.h.
|
private |
Callback for unicast packets to be forwarded.
Definition at line 290 of file nix-vector-routing.h.
|
private |
Callback for IPv4 unicast packets to be forwarded.
Definition at line 282 of file nix-vector-routing.h.
|
private |
Callback for IPv6 unicast packets to be forwarded.
Definition at line 286 of file nix-vector-routing.h.
ns3::NixVectorRouting< T >::NixVectorRouting | ( | ) |
Definition at line 68 of file nix-vector-routing.cc.
References NS_LOG_FUNCTION_NOARGS.
ns3::NixVectorRouting< T >::~NixVectorRouting | ( | ) |
Definition at line 75 of file nix-vector-routing.cc.
References NS_LOG_FUNCTION_NOARGS.
|
private |
Breadth first search algorithm.
[in] | numberOfNodes | total number of nodes |
[in] | source | Source Node |
[in] | dest | Destination Node |
[out] | parentVector | Parent vector for retracing routes |
[in] | oif | specific output interface to use from source node, if not null |
Definition at line 1113 of file nix-vector-routing.cc.
References ns3::NetDeviceContainer::Begin(), ns3::NetDeviceContainer::End(), NS_LOG_FUNCTION, and NS_LOG_LOGIC.
|
private |
Build map from IP Address to Node for faster lookup.
Definition at line 451 of file nix-vector-routing.cc.
References ns3::NodeList::Begin(), ns3::DynamicCast(), ns3::NodeList::End(), NS_ABORT_MSG_IF, NS_LOG_FUNCTION_NOARGS, and NS_LOG_LOGIC.
|
private |
Recurses the T vector, created by BFS and actually builds the nixvector.
[in] | parentVector | Parent vector for retracing routes |
[in] | source | Source Node index |
[in] | dest | Destination Node index |
[out] | nixVector | the NixVector to be used for routing |
Definition at line 273 of file nix-vector-routing.cc.
References ns3::NetDeviceContainer::Begin(), ns3::NetDeviceContainer::End(), ns3::NetDeviceContainer::GetN(), NS_LOG_FUNCTION, and NS_LOG_LOGIC.
|
private |
Flushes routing caches if required.
Definition at line 1410 of file nix-vector-routing.cc.
|
private |
Definition at line 118 of file nix-vector-routing.cc.
References NS_LOG_FUNCTION_NOARGS.
|
private |
Definition at line 104 of file nix-vector-routing.cc.
References NS_LOG_FUNCTION.
|
private |
Nix index is with respect to the neighbors.
The net-device index must be derived from this
[in] | node | the current node under consideration |
[in] | nodeIndex | Nix Node index |
[out] | gatewayIp | IP address of the gateway |
Definition at line 638 of file nix-vector-routing.cc.
References ns3::NetDeviceContainer::Get(), ns3::NetDeviceContainer::GetN(), and NS_LOG_FUNCTION.
|
private |
Simply iterates through the nodes net-devices and determines how many neighbors the node has.
[in] | node | node pointer |
Definition at line 561 of file nix-vector-routing.cc.
References ns3::NetDeviceContainer::GetN(), and NS_LOG_FUNCTION.
template void ns3::NixVectorRouting< T >::FlushGlobalNixRoutingCache | ( | ) | const |
Called when run-time link topology change occurs which iterates through the node list and flushes any nix vector caches.
const
is used here due to need to potentially flush the cache in const methods such as PrintRoutingTable. Caches are stored in mutable variables and flushed in const methods. Definition at line 139 of file nix-vector-routing.cc.
References ns3::NodeList::Begin(), ns3::NodeList::End(), NS_LOG_FUNCTION_NOARGS, and NS_LOG_LOGIC.
|
private |
Flushes the cache which stores the Ip route based on the destination IP.
Definition at line 172 of file nix-vector-routing.cc.
References NS_LOG_FUNCTION_NOARGS.
|
private |
Flushes the cache which stores nix-vector based on destination IP.
Definition at line 164 of file nix-vector-routing.cc.
References NS_LOG_FUNCTION_NOARGS.
|
private |
Given a net-device returns all the adjacent net-devices, essentially getting the neighbors on that channel.
[in] | netDevice | the NetDevice attached to the channel. |
[in] | channel | the channel to check |
[out] | netDeviceContainer | the NetDeviceContainer of the NetDevices in the channel. |
Definition at line 350 of file nix-vector-routing.cc.
References ns3::NetDeviceContainer::Add(), ns3::Ipv6InterfaceAddress::LINKLOCAL, NS_LOG_FUNCTION, and NS_LOG_LOGIC.
|
private |
Iterates through the node list and finds the one corresponding to the given IpAddress.
netDevice | NetDevice pointer |
Definition at line 534 of file nix-vector-routing.cc.
References NS_LOG_ERROR.
|
private |
Checks the cache based on dest IP for the IpRoute.
address | Address to check |
Definition at line 254 of file nix-vector-routing.cc.
References NS_LOG_FUNCTION, and NS_LOG_LOGIC.
|
private |
Takes in the source node and dest IP and calls GetNodeByIp, BFS, accounting for any output interface specified, and finally BuildNixVector to return the built nix-vector.
source | Source node |
dest | Destination node address |
oif | Preferred output interface |
Definition at line 180 of file nix-vector-routing.cc.
References ns3::Create(), ns3::NodeList::GetNNodes(), NS_LOG_DEBUG, NS_LOG_ERROR, and NS_LOG_FUNCTION.
|
private |
Checks the cache based on dest IP for the nix-vector.
Definition at line 233 of file nix-vector-routing.cc.
References NS_LOG_FUNCTION, and NS_LOG_LOGIC.
|
private |
Iterates through the node list and finds the one corresponding to the given IpAddress.
dest | destination node IP |
Definition at line 505 of file nix-vector-routing.cc.
References NS_LOG_ERROR, and NS_LOG_FUNCTION.
|
static |
The Interface ID of the Global Router interface.
Definition at line 49 of file nix-vector-routing.cc.
References ns3::TypeId::SetParent().
|
private |
Determine if the NetDevice is bridged.
nd | the NetDevice to check |
Definition at line 595 of file nix-vector-routing.cc.
References nDevices, NS_ABORT_MSG_UNLESS, NS_LOG_FUNCTION, and NS_LOG_LOGIC.
|
privatevirtual |
interface | the index of the interface we are being notified about |
address | a new address being added to an interface |
Definition at line 1077 of file nix-vector-routing.cc.
|
privatevirtual |
Notify a new route.
dst | destination address |
mask | destination mask |
nextHop | nextHop for this destination |
interface | output interface |
prefixToUse | prefix to use as source with this route |
Definition at line 1091 of file nix-vector-routing.cc.
|
privatevirtual |
interface | the index of the interface we are being notified about |
Definition at line 1070 of file nix-vector-routing.cc.
|
privatevirtual |
interface | the index of the interface we are being notified about |
Definition at line 1063 of file nix-vector-routing.cc.
|
privatevirtual |
interface | the index of the interface we are being notified about |
address | a new address being added to an interface |
Definition at line 1084 of file nix-vector-routing.cc.
|
privatevirtual |
Notify route removing.
dst | destination address |
mask | destination mask |
nextHop | nextHop for this destination |
interface | output interface |
prefixToUse | prefix to use as source with this route |
Definition at line 1102 of file nix-vector-routing.cc.
template void ns3::NixVectorRouting< T >::PrintRoutingPath | ( | Ptr< Node > | source, |
IpAddress | dest, | ||
Ptr< OutputStreamWrapper > | stream, | ||
Time::Unit | unit ) const |
Print the Routing Path according to Nix Routing.
source | Source node |
dest | Destination node address |
stream | The ostream the Routing path is printed to |
unit | the time unit to be used in the report |
Definition at line 1275 of file nix-vector-routing.cc.
References ns3::Time::As(), ns3::Now(), NS_LOG_ERROR, NS_LOG_FUNCTION, and NS_LOG_LOGIC.
|
privatevirtual |
Print the Routing Table entries.
stream | The ostream the Routing table is printed to |
unit | The time unit to be used in the report |
Definition at line 988 of file nix-vector-routing.cc.
References ns3::Time::As(), ns3::Names::FindName(), ns3::Now(), and NS_LOG_FUNCTION_NOARGS.
|
private |
Upon a run-time topology change caches are flushed and the total number of neighbors is reset to zero.
|
privatevirtual |
Route an input packet (to be forwarded or locally delivered)
p | received packet |
header | input parameter used to form a search key for a route |
idev | Pointer to ingress network device |
ucb | Callback for the case in which the packet is to be forwarded as unicast |
mcb | Callback for the case in which the packet is to be forwarded as multicast |
lcb | Callback for the case in which the packet is to be locally delivered |
ecb | Callback to call if there is an error in forwarding |
Definition at line 856 of file nix-vector-routing.cc.
References ns3::Create(), ns3::Socket::ERROR_NOROUTETOHOST, ns3::Callback< R, UArgs >::IsNull(), NS_ASSERT, NS_LOG_FUNCTION, and NS_LOG_LOGIC.
|
privatevirtual |
Query routing cache for an existing route, for an outbound packet.
p | packet to be routed. Note that this method may modify the packet. Callers may also pass in a null pointer. |
header | input parameter (used to form key to search for the route) |
oif | Output interface Netdevice. May be zero, or may be bound via socket options to a particular output interface. |
sockerr | Output parameter; socket errno |
Definition at line 686 of file nix-vector-routing.cc.
References ns3::Create(), ns3::DynamicCast(), ns3::Socket::ERROR_NOROUTETOHOST, ns3::Socket::ERROR_NOTERROR, ns3::Ipv6Address::GetZero(), NS_ASSERT_MSG, NS_LOG_DEBUG, NS_LOG_ERROR, NS_LOG_FUNCTION, and NS_LOG_LOGIC.
|
privatevirtual |
Typically, invoked directly or indirectly from ns3::Ipv4::SetRoutingProtocol.
ipv4 | the ipv4 object this routing protocol is being associated with |
Definition at line 82 of file nix-vector-routing.cc.
References NS_ASSERT, and NS_LOG_DEBUG.
|
privatevirtual |
Typically, invoked directly or indirectly from ns3::Ipv6::SetRoutingProtocol.
ipv6 | the ipv6 object this routing protocol is being associated with |
Definition at line 93 of file nix-vector-routing.cc.
References NS_ASSERT, and NS_LOG_DEBUG.
template void ns3::NixVectorRouting< T >::SetNode | ( | Ptr< Node > | node | ) |
Set the Node pointer of the node for which this routing protocol is to be placed.
node | Node pointer |
Definition at line 130 of file nix-vector-routing.cc.
References NS_LOG_FUNCTION_NOARGS.
|
staticprivate |
Nix Epoch, incremented each time a flush is performed.
Definition at line 481 of file nix-vector-routing.h.
|
staticprivate |
Address to node map.
Definition at line 503 of file nix-vector-routing.h.
|
staticprivate |
Flag to mark when caches are dirty and need to be flushed.
Used for lazy cleanup of caches when there are many topology changes.
Definition at line 476 of file nix-vector-routing.h.
|
staticprivate |
NetDevice pointer to IpInterface pointer map.
Definition at line 508 of file nix-vector-routing.h.
|
staticconstexprprivate |
Alias for determining whether the parent is Ipv4RoutingProtocol or Ipv6RoutingProtocol.
Definition at line 63 of file nix-vector-routing.h.
|
private |
IP object.
Definition at line 489 of file nix-vector-routing.h.
|
mutableprivate |
Cache stores IpRoutes based on destination ip.
Definition at line 487 of file nix-vector-routing.h.
|
mutableprivate |
Cache stores nix-vectors based on destination ip.
Definition at line 484 of file nix-vector-routing.h.
|
private |
Node object.
Definition at line 490 of file nix-vector-routing.h.
|
private |
Total neighbors used for nix-vector to determine number of bits.
Definition at line 493 of file nix-vector-routing.h.