10#ifndef GLOBAL_ROUTE_MANAGER_IMPL_H
11#define GLOBAL_ROUTE_MANAGER_IMPL_H
19#include "ns3/ipv4-address.h"
20#include "ns3/ipv4-routing-helper.h"
21#include "ns3/object.h"
73 static_assert(std::is_same_v<T, Ipv4Manager> || std::is_same_v<T, Ipv6Manager>,
74 "T must be either Ipv4Manager or Ipv6Manager In SPFVertex");
77 static constexpr bool IsIpv4 = std::is_same_v<Ipv4Manager, T>;
80 using IpManager =
typename std::conditional_t<IsIpv4, Ipv4Manager, Ipv6Manager>;
83 using Ip =
typename std::conditional_t<IsIpv4, Ipv4, Ipv6>;
86 using IpAddress =
typename std::conditional_t<IsIpv4, Ipv4Address, Ipv6Address>;
89 using IpRoute =
typename std::conditional_t<IsIpv4, Ipv4Route, Ipv6Route>;
92 using IpHeader =
typename std::conditional_t<IsIpv4, Ipv4Header, Ipv6Header>;
96 typename std::conditional_t<IsIpv4, Ipv4InterfaceAddress, Ipv6InterfaceAddress>;
100 typename std::conditional_t<IsIpv4, Ipv4RoutingTableEntry, Ipv6RoutingTableEntry>;
103 using IpMaskOrPrefix =
typename std::conditional_t<IsIpv4, Ipv4Mask, Ipv6Prefix>;
331 typedef std::pair<IpAddress, int32_t>
601 for (
auto iter = vs.begin(); iter != vs.end();)
603 os << (*iter)->m_vertexId;
604 if (++iter != vs.end())
634 static_assert(std::is_same_v<T, Ipv4Manager> || std::is_same_v<T, Ipv6Manager>,
635 "T must be either Ipv4Manager or Ipv6Manager In GlobalRouteManagerLSDB");
637 static constexpr bool IsIpv4 = std::is_same_v<Ipv4Manager, T>;
640 using IpManager =
typename std::conditional_t<IsIpv4, Ipv4Manager, Ipv6Manager>;
643 using Ip =
typename std::conditional_t<IsIpv4, Ipv4, Ipv6>;
646 using IpAddress =
typename std::conditional_t<IsIpv4, Ipv4Address, Ipv6Address>;
649 using IpRoute =
typename std::conditional_t<IsIpv4, Ipv4Route, Ipv6Route>;
652 using IpHeader =
typename std::conditional_t<IsIpv4, Ipv4Header, Ipv6Header>;
656 typename std::conditional_t<IsIpv4, Ipv4InterfaceAddress, Ipv6InterfaceAddress>;
660 typename std::conditional_t<IsIpv4, Ipv4RoutingTableEntry, Ipv6RoutingTableEntry>;
663 using IpMaskOrPrefix =
typename std::conditional_t<IsIpv4, Ipv4Mask, Ipv6Prefix>;
765 typedef std::map<IpAddress, GlobalRoutingLSA<IpManager>*>
767 typedef std::pair<IpAddress, GlobalRoutingLSA<IpManager>*>
771 std::vector<GlobalRoutingLSA<IpManager>*>
790 std::is_same_v<T, Ipv4Manager> || std::is_same_v<T, Ipv6Manager>,
791 "T must be either Ipv4Manager or Ipv6Manager when calling GlobalRouteManagerImpl");
793 static constexpr bool IsIpv4 = std::is_same_v<Ipv4Manager, T>;
796 using Ip =
typename std::conditional_t<IsIpv4, Ipv4, Ipv6>;
799 using IpManager =
typename std::conditional_t<IsIpv4, Ipv4Manager, Ipv6Manager>;
802 using IpAddress =
typename std::conditional_t<IsIpv4, Ipv4Address, Ipv6Address>;
805 using IpRoute =
typename std::conditional_t<IsIpv4, Ipv4Route, Ipv6Route>;
808 using IpHeader =
typename std::conditional_t<IsIpv4, Ipv4Header, Ipv6Header>;
812 typename std::conditional_t<IsIpv4, Ipv4InterfaceAddress, Ipv6InterfaceAddress>;
816 typename std::conditional_t<IsIpv4, Ipv4RoutingTableEntry, Ipv6RoutingTableEntry>;
819 using IpMaskOrPrefix =
typename std::conditional_t<IsIpv4, Ipv4Mask, Ipv6Prefix>;
822 using IpListRouting =
typename std::conditional_t<IsIpv4, Ipv4ListRouting, Ipv6ListRouting>;
825 using IpL3Protocol =
typename std::conditional_t<IsIpv4, Ipv4L3Protocol, Ipv6L3Protocol>;
829 typename std::conditional_t<IsIpv4, Ipv4RoutingProtocol, Ipv6RoutingProtocol>;
A Candidate Queue used in routing calculations.
void SPFProcessStubs(SPFVertex< T > *v)
Process Stub nodes.
typename std::conditional_t< IsIpv4, Ipv4Manager, Ipv6Manager > IpManager
Alias for Ipv4Manager and Ipv6Manager classes.
typename std::conditional_t< IsIpv4, Ipv4InterfaceAddress, Ipv6InterfaceAddress > IpInterfaceAddress
Alias for Ipv4InterfaceAddress and Ipv6InterfaceAddress classes.
int32_t FindOutgoingInterfaceId(IpAddress a, IpMaskOrPrefix amask=IpMaskOrPrefix::GetOnes())
Return the interface number corresponding to a given IP address and mask.
typename std::conditional_t< IsIpv4, Ipv4Route, Ipv6Route > IpRoute
Alias for Ipv4Route and Ipv6Route classes.
void SPFIntraAddTransit(SPFVertex< T > *v)
Add a transit to the routing tables.
typename std::conditional_t< IsIpv4, Ipv4L3Protocol, Ipv6L3Protocol > IpL3Protocol
Alias for Ipv4l3Protocol and Ipv6l3Protocol classes.
GlobalRouteManagerImpl & operator=(const GlobalRouteManagerImpl &)=delete
void SPFIntraAddStub(GlobalRoutingLinkRecord< IpManager > *l, SPFVertex< T > *v)
Add a stub to the routing tables.
void DebugSPFCalculate(IpAddress root)
Debugging routine; call the core SPF from the unit tests.
virtual void BuildGlobalRoutingDatabase()
Build the routing database by gathering Link State Advertisements from each node exporting a GlobalRo...
void PrintRoute(Ptr< Node > sourceNode, Ptr< Node > dest, Ptr< OutputStreamWrapper > stream, bool nodeIdLookup, Time::Unit unit)
prints the path from this node to the destination node at a particular time.
typename std::conditional_t< IsIpv4, Ipv4ListRouting, Ipv6ListRouting > IpListRouting
Alias for Ipv4ListRouting and Ipv6ListRouting classes.
GlobalRoutingLinkRecord< IpManager > * SPFGetNextLink(SPFVertex< T > *v, SPFVertex< T > *w, GlobalRoutingLinkRecord< IpManager > *prev_link)
Search for a link between two vertices.
void SPFCalculate(IpAddress root)
Calculate the shortest path first (SPF) tree.
void SPFNext(SPFVertex< T > *v, CandidateQueue< T > &candidate)
Examine the links in v's LSA and update the list of candidates with any vertices not already on the l...
GlobalRouteManagerImpl(const GlobalRouteManagerImpl &)=delete
void InitializeRouters()
initialize all nodes as routers.
int SPFNexthopCalculation(SPFVertex< T > *v, SPFVertex< T > *w, GlobalRoutingLinkRecord< IpManager > *l, uint32_t distance)
Calculate nexthop from root through V (parent) to vertex W (destination) with given distance from roo...
virtual void InitializeRoutes()
Compute routes using a Dijkstra SPF computation and populate per-node forwarding tables.
Ptr< Node > GetNodeByIp(const IpAddress &source)
given IP it iterates through the node list to find the node associated with the ip
virtual void DeleteGlobalRoutes()
Delete all static routes on all nodes that have a GlobalRouterInterface.
GlobalRouteManagerLSDB< IpManager > * m_lsdb
the Link State DataBase (LSDB) of the Global Route Manager
void SPFVertexAddParent(SPFVertex< T > *v)
Adds a vertex to the list of children in each of its parents.
void SPFIntraAddRouter(SPFVertex< T > *v)
Add a host route to the routing tables.
SPFVertex< T > * m_spfroot
the root node
void DebugUseLsdb(GlobalRouteManagerLSDB< T > *lsdb)
Debugging routine; allow client code to supply a pre-built LSDB.
void SPFAddASExternal(GlobalRoutingLSA< IpManager > *extlsa, SPFVertex< T > *v)
Add an external route to the routing tables.
static constexpr bool IsIpv4
Alias for determining whether the parent is Ipv4RoutingProtocol or Ipv6RoutingProtocol.
virtual ~GlobalRouteManagerImpl()
bool CheckForStubNode(IpAddress root)
Test if a node is a stub, from an OSPF sense.
typename std::conditional_t< IsIpv4, Ipv4RoutingTableEntry, Ipv6RoutingTableEntry > IpRoutingTableEntry
Alias for Ipv4RoutingTableEntry and Ipv6RoutingTableEntry classes.
typename std::conditional_t< IsIpv4, Ipv4Mask, Ipv6Prefix > IpMaskOrPrefix
Alias for Ipv4Mask And Ipv6Prefix.
typename std::conditional_t< IsIpv4, Ipv4RoutingProtocol, Ipv6RoutingProtocol > IpRoutingProtocol
Alias for Ipv4RoutingProtocol and Ipv6RoutingProtocol classes.
GlobalRouting< IpRoutingProtocol > IpGlobalRouting
Alias for Ipv4GlobalRouting and Ipv6GlobalRouting classes.
bool ValidateSourceNodeHasIpAddress(Ptr< Ip > ip)
Is used by PrintRoute() to check if the source node has an ipv4 address.
Ptr< IpGlobalRouting > GetGlobalRoutingForNode(Ptr< Node > node)
Is used by PrintRoute() to get the global routing protocol associated with it or returns nullptr if n...
bool IsOnSameSubnet(Ptr< Ip > ipCurrentNode, IpAddress dest)
Is used by PrintRoute() to check if the destination is on the same subnet as the source node.
typename std::conditional_t< IsIpv4, Ipv4Header, Ipv6Header > IpHeader
Alias for Ipv4Header and Ipv6Header classes.
bool IsLocalDelivery(Ptr< Ip > ip, IpAddress dest)
Is used by PrintRoute() to check if the destination is on the source node itself.
typename std::conditional_t< IsIpv4, Ipv4, Ipv6 > Ip
Alias for Ipv4 and Ipv6 classes.
typename std::conditional_t< IsIpv4, Ipv4Address, Ipv6Address > IpAddress
Alias for Ipv4Address and Ipv6Address classes.
void ProcessASExternals(SPFVertex< T > *v, GlobalRoutingLSA< IpManager > *extlsa)
Process Autonomous Systems (AS) External LSA.
The Link State DataBase (LSDB) of the Global Route Manager.
typename std::conditional_t< IsIpv4, Ipv4InterfaceAddress, Ipv6InterfaceAddress > IpInterfaceAddress
Alias for Ipv4InterfaceAddress and Ipv6InterfaceAddress classes.
std::pair< IpAddress, GlobalRoutingLSA< IpManager > * > LSDBPair_t
pair of IPv4 addresses / Link State Advertisements
std::map< IpAddress, GlobalRoutingLSA< IpManager > * > LSDBMap_t
container of IPv4 addresses / Link State Advertisements
GlobalRoutingLSA< IpManager > * GetLSA(IpAddress addr) const
Look up the Link State Advertisement associated with the given link state ID (address).
~GlobalRouteManagerLSDB()
Destroy an empty Global Router Manager Link State Database.
GlobalRoutingLSA< IpManager > * GetExtLSA(uint32_t index) const
Look up the External Link State Advertisement associated with the given index.
GlobalRouteManagerLSDB(const GlobalRouteManagerLSDB &)=delete
GlobalRouteManagerLSDB & operator=(const GlobalRouteManagerLSDB &)=delete
uint32_t GetNumExtLSAs() const
Get the number of External Link State Advertisements.
typename std::conditional_t< IsIpv4, Ipv4Header, Ipv6Header > IpHeader
Alias for Ipv4Header and Ipv6Header classes.
typename std::conditional_t< IsIpv4, Ipv4Mask, Ipv6Prefix > IpMaskOrPrefix
Alias for Ipv4Mask And Ipv6Prefix.
void Initialize()
Set all LSA flags to an initialized state, for SPF computation.
GlobalRoutingLSA< IpManager > * GetLSAByLinkData(IpAddress addr) const
Look up the Link State Advertisement associated with the given link state ID (address).
typename std::conditional_t< IsIpv4, Ipv4RoutingTableEntry, Ipv6RoutingTableEntry > IpRoutingTableEntry
Alias for Ipv4RoutingTableEntry and Ipv6RoutingTableEntry classes.
LSDBMap_t m_database
database of IPv4 addresses / Link State Advertisements
std::vector< GlobalRoutingLSA< IpManager > * > m_extdatabase
database of External Link State Advertisements
typename std::conditional_t< IsIpv4, Ipv4, Ipv6 > Ip
Alias for Ipv4 and Ipv6 classes.
typename std::conditional_t< IsIpv4, Ipv4Route, Ipv6Route > IpRoute
Alias for Ipv4Route and Ipv6Route classes.
typename std::conditional_t< IsIpv4, Ipv4Address, Ipv6Address > IpAddress
Alias for Ipv4Address and Ipv6Address classes.
GlobalRouteManagerLSDB()
Construct an empty Global Router Manager Link State Database.
static constexpr bool IsIpv4
Alias for determining whether the parent is Ipv4RoutingProtocol or Ipv6RoutingProtocol.
void Insert(IpAddress addr, GlobalRoutingLSA< IpManager > *lsa)
Insert an IP address / Link State Advertisement pair into the Link State Database.
typename std::conditional_t< IsIpv4, Ipv4Manager, Ipv6Manager > IpManager
Alias for Ipv4Manager and Ipv6Manager classes.
Global routing protocol for IPv4 stacks.
a Link State Advertisement (LSA) for a router, used in global routing.
A single link record for a link state advertisement.
Smart pointer class similar to boost::intrusive_ptr.
Vertex used in shortest path first (SPF) computations.
bool m_vertexProcessed
Flag to note whether vertex has been processed in stage two of SPF computation.
SPFVertex & operator=(const SPFVertex &)=delete
VertexType m_vertexType
Vertex type.
SPFVertex * GetParent(uint32_t i=0) const
Get a pointer to the SPFVector that is the parent of "this" SPFVertex.
SPFVertex()
Construct an empty ("uninitialized") SPFVertex (Shortest Path First Vertex).
IpAddress GetVertexId() const
Get the Vertex ID field of a SPFVertex object.
SPFVertex< T > * GetChild(uint32_t n) const
Get a borrowed SPFVertex pointer to the specified child of "this" SPFVertex.
~SPFVertex()
Destroy an SPFVertex (Shortest Path First Vertex).
uint32_t m_distanceFromRoot
Distance from root node.
VertexType
Enumeration of the possible types of SPFVertex objects.
@ VertexNetwork
Vertex representing a network in the topology.
@ VertexUnknown
Uninitialized Link Record.
@ VertexRouter
Vertex representing a router in the topology.
void InheritAllRootExitDirections(const SPFVertex< T > *vertex)
Inherit all root exit directions from a given vertex to 'this' vertex.
GlobalRoutingLSA< IpManager > * m_lsa
Link State Advertisement.
void SetRootExitDirection(IpAddress nextHop, int32_t id=SPF_INFINITY)
Set the IP address and outgoing interface index that should be used to begin forwarding packets from ...
void SetVertexId(IpAddress id)
Set the Vertex ID field of a SPFVertex object.
uint32_t GetDistanceFromRoot() const
Get the distance from the root vertex to "this" SPFVertex object.
typename std::conditional_t< IsIpv4, Ipv4, Ipv6 > Ip
Alias for Ipv4 and Ipv6 classes.
IpAddress m_nextHop
next hop
typename std::conditional_t< IsIpv4, Ipv4Route, Ipv6Route > IpRoute
Alias for Ipv4Route and Ipv6Route classes.
bool IsVertexProcessed() const
Check the value of the VertexProcessed flag.
void SetDistanceFromRoot(uint32_t distance)
Set the distance from the root vertex to "this" SPFVertex object.
typename std::conditional_t< IsIpv4, Ipv4RoutingTableEntry, Ipv6RoutingTableEntry > IpRoutingTableEntry
Alias for Ipv4RoutingTableEntry and Ipv6RoutingTableEntry classes.
void SetRootExitDirection(SPFVertex::NodeExit_t exit)
Set the IP address and outgoing interface index that should be used to begin forwarding packets from ...
typename std::conditional_t< IsIpv4, Ipv4Manager, Ipv6Manager > IpManager
Alias for Ipv4Manager and Ipv6Manager classes.
ListOfNodeExit_t m_ecmpRootExits
store the multiple root's exits for supporting ECMP
Ptr< Node > m_node
node pointer corresponding to the this Vertex
void SetVertexType(VertexType type)
Set the Vertex Type field of a SPFVertex object.
typename std::conditional_t< IsIpv4, Ipv4Address, Ipv6Address > IpAddress
Alias for Ipv4Address and Ipv6Address classes.
uint32_t AddChild(SPFVertex< T > *child)
Get a borrowed SPFVertex pointer to the specified child of "this" SPFVertex.
uint32_t GetNChildren() const
Get the number of children of "this" SPFVertex.
typename std::conditional_t< IsIpv4, Ipv4Header, Ipv6Header > IpHeader
Alias for Ipv4Header and Ipv6Header classes.
int32_t m_rootOif
root Output Interface
std::list< SPFVertex< T > * > ListOfSPFVertex_t
container of SPFVertex items
uint32_t GetNRootExitDirections() const
Get the number of exit directions from root for reaching 'this' vertex.
void SetLSA(GlobalRoutingLSA< IpManager > *lsa)
Set the Global Router Link State Advertisement returned by the Global Router represented by this SPFV...
void MergeParent(const SPFVertex< T > *v)
Merge the Parent list from the v into this vertex.
GlobalRoutingLSA< T > * GetLSA() const
Get the Global Router Link State Advertisement returned by the Global Router represented by this SPFV...
friend std::ostream & operator<<(std::ostream &os, const typename SPFVertex< T >::ListOfSPFVertex_t &vs)
Stream insertion operator.
void MergeRootExitDirections(const SPFVertex< T > *vertex)
Merge into 'this' vertex the list of exit directions from another vertex.
void SetVertexProcessed(bool value)
Set the value of the VertexProcessed flag.
static constexpr bool IsIpv4
Alias for determining whether the parent is Ipv4RoutingProtocol or Ipv6RoutingProtocol.
std::list< NodeExit_t > ListOfNodeExit_t
container of Exit nodes
VertexType GetVertexType() const
Get the Vertex Type field of a SPFVertex object.
typename std::conditional_t< IsIpv4, Ipv4InterfaceAddress, Ipv6InterfaceAddress > IpInterfaceAddress
Alias for Ipv4InterfaceAddress and Ipv6InterfaceAddress classes.
SPFVertex(const SPFVertex &)=delete
void ClearVertexProcessed()
Clear the value of the VertexProcessed flag.
IpAddress m_vertexId
Vertex ID.
NodeExit_t GetRootExitDirection() const
Obtain a pair indicating the exit direction from the root.
std::pair< IpAddress, int32_t > NodeExit_t
IPv4 / interface container for exit nodes.
typename std::conditional_t< IsIpv4, Ipv4Mask, Ipv6Prefix > IpMaskOrPrefix
Alias for Ipv4Mask And Ipv6Prefix.
void SetParent(SPFVertex< T > *parent)
Set the pointer to the SPFVector that is the parent of "this" SPFVertex.
ListOfSPFVertex_t m_parents
parent list
Ptr< Node > GetNode() const
Get the node pointer corresponding to this Vertex.
ListOfSPFVertex_t m_children
Children list.
Unit
The unit to use to interpret a number representing time.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
const uint32_t SPF_INFINITY
"infinite" distance between nodes