|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
26 #ifndef NIX_VECTOR_ROUTING_H
27 #define NIX_VECTOR_ROUTING_H
29 #include "ns3/channel.h"
30 #include "ns3/node-container.h"
31 #include "ns3/node-list.h"
32 #include "ns3/net-device-container.h"
33 #include "ns3/ipv4-routing-protocol.h"
34 #include "ns3/ipv4-route.h"
35 #include "ns3/ipv6-route.h"
36 #include "ns3/ipv6-routing-protocol.h"
37 #include "ns3/nix-vector.h"
38 #include "ns3/bridge-net-device.h"
39 #include "ns3/nstime.h"
40 #include "ns3/ipv4-interface.h"
41 #include "ns3/ipv6-interface.h"
42 #include "ns3/ipv4-l3-protocol.h"
43 #include "ns3/ipv6-l3-protocol.h"
46 #include <unordered_map>
67 class NixVectorRouting :
public std::enable_if<std::is_same<Ipv4RoutingProtocol, T>::value || std::is_same<Ipv6RoutingProtocol, T>::value, T>::type
70 using IsIpv4 = std::is_same <Ipv4RoutingProtocol, T>;
73 using Ip =
typename std::conditional <IsIpv4::value, Ipv4, Ipv6>::type;
76 using IpAddress =
typename std::conditional<IsIpv4::value, Ipv4Address, Ipv6Address>::type;
79 using IpRoute =
typename std::conditional<IsIpv4::value, Ipv4Route, Ipv6Route>::type;
82 using IpAddressHash =
typename std::conditional<IsIpv4::value, Ipv4AddressHash, Ipv6AddressHash>::type;
85 using IpHeader =
typename std::conditional<IsIpv4::value, Ipv4Header, Ipv6Header>::type;
88 using IpInterfaceAddress =
typename std::conditional<IsIpv4::value, Ipv4InterfaceAddress, Ipv6InterfaceAddress>::type;
91 using IpInterface =
typename std::conditional<IsIpv4::value, Ipv4Interface, Ipv6Interface>::type;
94 using IpL3Protocol =
typename std::conditional<IsIpv4::value, Ipv4L3Protocol, Ipv6L3Protocol>::type;
264 bool BFS (uint32_t numberOfNodes,
283 typedef std::map<IpAddress, Ptr<NixVector> >
NixMap_t;
294 typedef typename std::conditional<IsIpv4::value, UnicastForwardCallbackv4, UnicastForwardCallbackv6>::type
UnicastForwardCallback;
303 typedef typename std::conditional<IsIpv4::value, MulticastForwardCallbackv4, MulticastForwardCallbackv6>::type
MulticastForwardCallback;
holds a vector of ns3::NetDevice pointers
a unique identifier for an interface.
Callback< void, Ptr< const Packet >, const IpHeader &, Socket::SocketErrno > ErrorCallback
Callback for routing errors (e.g., no route found)
uint32_t FindNetDeviceForNixIndex(Ptr< Node > node, uint32_t nodeIndex, IpAddress &gatewayIp) const
Nix index is with respect to the neighbors.
virtual void NotifyAddRoute(IpAddress dst, Ipv6Prefix mask, IpAddress nextHop, uint32_t interface, IpAddress prefixToUse=IpAddress::GetZero())
Notify a new route.
void ResetTotalNeighbors(void)
Upon a run-time topology change caches are flushed and the total number of neighbors is reset to zero...
static IpAddressToNodeMap g_ipAddressToNodeMap
Address to node map.
std::map< IpAddress, Ptr< NixVector > > NixMap_t
Map of IpAddress to NixVector.
Ptr< IpInterface > GetInterfaceByNetDevice(Ptr< NetDevice > netDevice) const
Iterates through the node list and finds the one corresponding to the given IpAddress.
IpRouteMap_t m_ipRouteCache
Cache stores IpRoutes based on destination ip.
SocketErrno
Enumeration of the possible errors returned by a socket.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< void, Ptr< const NetDevice >, Ptr< Ipv6MulticastRoute >, Ptr< const Packet >, const IpHeader & > MulticastForwardCallbackv6
Callback for IPv6 multicast packets to be forwarded.
uint32_t m_totalNeighbors
Total neighbors used for nix-vector to determine number of bits.
Ptr< Node > GetNodeByIp(IpAddress dest) const
Iterates through the node list and finds the one corresponding to the given IpAddress.
void SetNode(Ptr< Node > node)
Set the Node pointer of the node for which this routing protocol is to be placed.
typename std::conditional< IsIpv4::value, Ipv4AddressHash, Ipv6AddressHash >::type IpAddressHash
Alias for Ipv4AddressHash and Ipv6AddressHash classes.
Ptr< NixVector > GetNixVectorInCache(const IpAddress &address, bool &foundInCache) const
Checks the cache based on dest IP for the nix-vector.
virtual void NotifyAddAddress(uint32_t interface, IpInterfaceAddress address)
typename std::conditional< IsIpv4::value, Ipv4L3Protocol, Ipv6L3Protocol >::type IpL3Protocol
Alias for Ipv4L3Protocol and Ipv4L3Protocol classes.
virtual void NotifyRemoveAddress(uint32_t interface, IpInterfaceAddress address)
virtual void SetIpv4(Ptr< Ip > ipv4)
Typically, invoked directly or indirectly from ns3::Ipv4::SetRoutingProtocol.
void CheckCacheStateAndFlush(void) const
Flushes routing caches if required.
void FlushGlobalNixRoutingCache(void) const
Called when run-time link topology change occurs which iterates through the node list and flushes any...
void FlushIpRouteCache(void) const
Flushes the cache which stores the Ip route based on the destination IP.
static NetDeviceToIpInterfaceMap g_netdeviceToIpInterfaceMap
NetDevice pointer to IpInterface pointer map.
typename std::conditional< IsIpv4::value, Ipv4Interface, Ipv6Interface >::type IpInterface
Alias for Ipv4Interface and Ipv6Interface classes.
virtual void NotifyRemoveRoute(IpAddress dst, Ipv6Prefix mask, IpAddress nextHop, uint32_t interface, IpAddress prefixToUse=IpAddress::GetZero())
Notify route removing.
virtual bool RouteInput(Ptr< const Packet > p, const IpHeader &header, Ptr< const NetDevice > idev, UnicastForwardCallback ucb, MulticastForwardCallback mcb, LocalDeliverCallback lcb, ErrorCallback ecb)
Route an input packet (to be forwarded or locally delivered)
Ptr< BridgeNetDevice > NetDeviceIsBridged(Ptr< NetDevice > nd) const
Determine if the NetDevice is bridged.
std::unordered_map< IpAddress, ns3::Ptr< ns3::Node >, IpAddressHash > IpAddressToNodeMap
Mapping of IP address to ns-3 node.
std::conditional< IsIpv4::value, UnicastForwardCallbackv4, UnicastForwardCallbackv6 >::type UnicastForwardCallback
Callback for unicast packets to be forwarded.
std::conditional< IsIpv4::value, MulticastForwardCallbackv4, MulticastForwardCallbackv6 >::type MulticastForwardCallback
Callback for multicast packets to be forwarded.
std::unordered_map< Ptr< NetDevice >, Ptr< IpInterface > > NetDeviceToIpInterfaceMap
Mapping of Ptr<NetDevice> to Ptr<IpInterface>.
std::is_same< Ipv4RoutingProtocol, T > IsIpv4
Alias for determining whether the parent is Ipv4RoutingProtocol or Ipv6RoutingProtocol.
typename std::conditional< IsIpv4::value, Ipv4, Ipv6 >::type Ip
Alias for Ipv4 and Ipv6 classes.
Nix-vector routing protocol.
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.
Callback< void, Ptr< Ipv4MulticastRoute >, Ptr< const Packet >, const IpHeader & > MulticastForwardCallbackv4
Callback for IPv4 multicast packets to be forwarded.
typename std::conditional< IsIpv4::value, Ipv4Header, Ipv6Header >::type IpHeader
Alias for Ipv4Header and Ipv6Header classes.
void BuildIpAddressToNodeMap(void) const
Build map from IP Address to Node for faster lookup.
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 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 ch...
static bool g_isCacheDirty
Flag to mark when caches are dirty and need to be flushed.
void PrintRoutingPath(Ptr< Node > source, IpAddress dest, Ptr< OutputStreamWrapper > stream, Time::Unit unit) const
Print the Routing Path according to Nix Routing.
uint32_t FindTotalNeighbors(Ptr< Node > node) const
Simply iterates through the nodes net-devices and determines how many neighbors the node has.
static TypeId GetTypeId(void)
The Interface ID of the Global Router interface.
Ptr< Node > m_node
Node object.
typename std::conditional< IsIpv4::value, Ipv4Address, Ipv6Address >::type IpAddress
Alias for Ipv4Address and Ipv6Address classes.
std::map< IpAddress, Ptr< IpRoute > > IpRouteMap_t
Map of IpAddress to IpRoute.
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.
Callback< void, Ptr< const NetDevice >, Ptr< IpRoute >, Ptr< const Packet >, const IpHeader & > UnicastForwardCallbackv6
Callback for IPv6 unicast packets to be forwarded.
NixVectorRouting< Ipv4RoutingProtocol > Ipv4NixVectorRouting
Create the typedef Ipv4NixVectorRouting with T as Ipv4RoutingProtocol.
NixVectorRouting< Ipv6RoutingProtocol > Ipv6NixVectorRouting
Create the typedef Ipv6NixVectorRouting with T as Ipv6RoutingProtocol.
Callback< void, Ptr< IpRoute >, Ptr< const Packet >, const IpHeader & > UnicastForwardCallbackv4
Callback for IPv4 unicast packets to be forwarded.
typename std::conditional< IsIpv4::value, Ipv4InterfaceAddress, Ipv6InterfaceAddress >::type IpInterfaceAddress
Alias for Ipv4InterfaceAddress and Ipv6InterfaceAddress classes.
NixMap_t m_nixCache
Cache stores nix-vectors based on destination ip.
virtual void SetIpv6(Ptr< Ip > ipv6)
Typically, invoked directly or indirectly from ns3::Ipv6::SetRoutingProtocol.
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S) const
Print the Routing Table entries.
void FlushNixCache(void) const
Flushes the cache which stores nix-vector based on destination IP.
typename std::conditional< IsIpv4::value, Ipv4Route, Ipv6Route >::type IpRoute
Alias for Ipv4Route and Ipv6Route classes.
Describes an IPv6 prefix.
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 ...
virtual void NotifyInterfaceDown(uint32_t interface)
Callback< void, Ptr< const Packet >, const IpHeader &, uint32_t > LocalDeliverCallback
Callback for packets to be locally delivered.
virtual void NotifyInterfaceUp(uint32_t interface)
Unit
The unit to use to interpret a number representing time.
Ptr< IpRoute > GetIpRouteInCache(IpAddress address)
Checks the cache based on dest IP for the IpRoute.
bool BuildNixVectorLocal(Ptr< NixVector > nixVector)
Special variation of BuildNixVector for when a node is sending to itself.