A Discrete-Event Network Simulator
API
global-route-manager-impl.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright 2007 University of Washington
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: Craig Dowell (craigdo@ee.washington.edu)
19  * Tom Henderson (tomhend@u.washington.edu)
20  */
21 
22 #ifndef GLOBAL_ROUTE_MANAGER_IMPL_H
23 #define GLOBAL_ROUTE_MANAGER_IMPL_H
24 
25 #include <stdint.h>
26 #include <list>
27 #include <queue>
28 #include <map>
29 #include <vector>
30 #include "ns3/object.h"
31 #include "ns3/ptr.h"
32 #include "ns3/ipv4-address.h"
34 
35 namespace ns3 {
36 
37 const uint32_t SPF_INFINITY = 0xffffffff;
38 
39 class CandidateQueue;
40 class Ipv4GlobalRouting;
41 
68 class SPFVertex
69 {
70 public:
78  enum VertexType {
82  };
83 
97  SPFVertex();
98 
115 
123  ~SPFVertex();
124 
134  VertexType GetVertexType (void) const;
135 
145  void SetVertexType (VertexType type);
146 
160  Ipv4Address GetVertexId (void) const;
161 
176  void SetVertexId (Ipv4Address id);
177 
189  GlobalRoutingLSA* GetLSA (void) const;
190 
204  void SetLSA (GlobalRoutingLSA* lsa);
205 
226  uint32_t GetDistanceFromRoot (void) const;
227 
246  void SetDistanceFromRoot (uint32_t distance);
247 
289  void SetRootExitDirection (Ipv4Address nextHop, int32_t id = SPF_INFINITY);
290 
291  typedef std::pair<Ipv4Address, int32_t> NodeExit_t;
292 
341  NodeExit_t GetRootExitDirection (uint32_t i) const;
361  void MergeRootExitDirections (const SPFVertex* vertex);
369  void InheritAllRootExitDirections (const SPFVertex* vertex);
374  uint32_t GetNRootExitDirections () const;
375 
395  SPFVertex* GetParent (uint32_t i = 0) const;
396 
415  void SetParent (SPFVertex* parent);
423  void MergeParent (const SPFVertex* v);
424 
444  uint32_t GetNChildren (void) const;
445 
472  SPFVertex* GetChild (uint32_t n) const;
473 
500  uint32_t AddChild (SPFVertex* child);
501 
509  void SetVertexProcessed (bool value);
510 
518  bool IsVertexProcessed (void) const;
519 
526  void ClearVertexProcessed (void);
527 
528 private:
533  int32_t m_rootOif;
535  typedef std::list< NodeExit_t > ListOfNodeExit_t;
537  typedef std::list<SPFVertex*> ListOfSPFVertex_t;
541 
548 
556 
564  friend std::ostream& operator<< (std::ostream& os, const SPFVertex::ListOfSPFVertex_t& vs);
565 };
566 
581 {
582 public:
590 
599 
613  void Insert (Ipv4Address addr, GlobalRoutingLSA* lsa);
614 
629  GlobalRoutingLSA* GetLSA (Ipv4Address addr) const;
643 
655  void Initialize ();
656 
668  GlobalRoutingLSA* GetExtLSA (uint32_t index) const;
675  uint32_t GetNumExtLSAs () const;
676 
677 
678 private:
679  typedef std::map<Ipv4Address, GlobalRoutingLSA*> LSDBMap_t;
680  typedef std::pair<Ipv4Address, GlobalRoutingLSA*> LSDBPair_t;
681 
683  std::vector<GlobalRoutingLSA*> m_extdatabase;
684 
691 
699 };
700 
713 {
714 public:
716  virtual ~GlobalRouteManagerImpl ();
724  virtual void DeleteGlobalRoutes ();
725 
730  virtual void BuildGlobalRoutingDatabase ();
731 
736  virtual void InitializeRoutes ();
737 
743 
748  void DebugSPFCalculate (Ipv4Address root);
749 
750 private:
759 
769 
772 
783  bool CheckForStubNode (Ipv4Address root);
784 
791  void SPFCalculate (Ipv4Address root);
792 
802  void SPFProcessStubs (SPFVertex* v);
803 
810  void ProcessASExternals (SPFVertex* v, GlobalRoutingLSA* extlsa);
811 
833  void SPFNext (SPFVertex* v, CandidateQueue& candidate);
834 
849  GlobalRoutingLinkRecord* l, uint32_t distance);
850 
865  void SPFVertexAddParent (SPFVertex* v);
866 
887  GlobalRoutingLinkRecord* prev_link);
888 
911  void SPFIntraAddRouter (SPFVertex* v);
912 
918  void SPFIntraAddTransit (SPFVertex* v);
919 
927 
934  void SPFAddASExternal (GlobalRoutingLSA *extlsa, SPFVertex *v);
935 
949  Ipv4Mask amask = Ipv4Mask ("255.255.255.255"));
950 };
951 
952 } // namespace ns3
953 
954 #endif /* GLOBAL_ROUTE_MANAGER_IMPL_H */
ns3::GlobalRouteManagerLSDB::GlobalRouteManagerLSDB
GlobalRouteManagerLSDB(GlobalRouteManagerLSDB &lsdb)
GlobalRouteManagerLSDB copy construction is disallowed.
ns3::GlobalRouteManagerImpl::SPFIntraAddTransit
void SPFIntraAddTransit(SPFVertex *v)
Add a transit to the routing tables.
Definition: global-route-manager-impl.cc:2074
ns3::SPFVertex::ClearVertexProcessed
void ClearVertexProcessed(void)
Clear the value of the VertexProcessed flag.
Definition: global-route-manager-impl.cc:406
ns3::SPFVertex::MergeParent
void MergeParent(const SPFVertex *v)
Merge the Parent list from the v into this vertex.
Definition: global-route-manager-impl.cc:262
ns3::SPFVertex::SetVertexProcessed
void SetVertexProcessed(bool value)
Set the value of the VertexProcessed flag.
Definition: global-route-manager-impl.cc:392
ns3::GlobalRouteManagerImpl::SPFAddASExternal
void SPFAddASExternal(GlobalRoutingLSA *extlsa, SPFVertex *v)
Add an external route to the routing tables.
Definition: global-route-manager-impl.cc:1541
ns3::GlobalRouteManagerImpl::DeleteGlobalRoutes
virtual void DeleteGlobalRoutes()
Delete all static routes on all nodes that have a GlobalRouterInterface.
Definition: global-route-manager-impl.cc:568
ns3::SPFVertex::SetVertexId
void SetVertexId(Ipv4Address id)
Set the Vertex ID field of a SPFVertex object.
Definition: global-route-manager-impl.cc:191
ns3::GlobalRouteManagerImpl::InitializeRoutes
virtual void InitializeRoutes()
Compute routes using a Dijkstra SPF computation and populate per-node forwarding tables.
Definition: global-route-manager-impl.cc:695
ns3::SPFVertex::GetLSA
GlobalRoutingLSA * GetLSA(void) const
Get the Global Router Link State Advertisement returned by the Global Router represented by this SPFV...
Definition: global-route-manager-impl.cc:212
ns3::SPFVertex::GetNRootExitDirections
uint32_t GetNRootExitDirections() const
Get the number of exit directions from root for reaching 'this' vertex.
Definition: global-route-manager-impl.cc:351
ns3::CandidateQueue
A Candidate Queue used in routing calculations.
Definition: candidate-queue.h:52
ns3::SPFVertex::SPFVertex
SPFVertex(SPFVertex &v)
The SPFVertex copy construction is disallowed.
ns3::GlobalRouteManagerLSDB::GetExtLSA
GlobalRoutingLSA * GetExtLSA(uint32_t index) const
Look up the External Link State Advertisement associated with the given index.
Definition: global-route-manager-impl.cc:477
ns3::SPFVertex::m_rootOif
int32_t m_rootOif
root Output Interface
Definition: global-route-manager-impl.h:533
ns3::SPFVertex::SetRootExitDirection
void SetRootExitDirection(Ipv4Address nextHop, int32_t id=SPF_INFINITY)
Set the IP address and outgoing interface index that should be used to begin forwarding packets from ...
Definition: global-route-manager-impl.cc:277
ns3::GlobalRouteManagerImpl::ProcessASExternals
void ProcessASExternals(SPFVertex *v, GlobalRoutingLSA *extlsa)
Process Autonomous Systems (AS) External LSA.
Definition: global-route-manager-impl.cc:1507
ns3::SPFVertex::SetLSA
void SetLSA(GlobalRoutingLSA *lsa)
Set the Global Router Link State Advertisement returned by the Global Router represented by this SPFV...
Definition: global-route-manager-impl.cc:205
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::SPF_INFINITY
const uint32_t SPF_INFINITY
"infinite" distance between nodes
Definition: global-route-manager-impl.h:37
ns3::GlobalRouteManagerImpl::SPFIntraAddRouter
void SPFIntraAddRouter(SPFVertex *v)
Add a host route to the routing tables.
Definition: global-route-manager-impl.cc:1929
ns3::SPFVertex::m_children
ListOfSPFVertex_t m_children
Children list.
Definition: global-route-manager-impl.h:539
ns3::GlobalRouteManagerImpl::m_lsdb
GlobalRouteManagerLSDB * m_lsdb
the Link State DataBase (LSDB) of the Global Route Manager
Definition: global-route-manager-impl.h:771
ns3::GlobalRoutingLSA
a Link State Advertisement (LSA) for a router, used in global routing.
Definition: global-router-interface.h:254
ns3::SPFVertex::GetRootExitDirection
NodeExit_t GetRootExitDirection() const
Obtain a pair indicating the exit direction from the root.
Definition: global-route-manager-impl.cc:311
ns3::GlobalRouteManagerLSDB::GetNumExtLSAs
uint32_t GetNumExtLSAs() const
Get the number of External Link State Advertisements.
Definition: global-route-manager-impl.cc:484
ns3::SPFVertex::GetVertexId
Ipv4Address GetVertexId(void) const
Get the Vertex ID field of a SPFVertex object.
Definition: global-route-manager-impl.cc:198
ns3::SPFVertex::VertexRouter
@ VertexRouter
Vertex representing a router in the topology.
Definition: global-route-manager-impl.h:80
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
ns3::GlobalRouteManagerLSDB::LSDBPair_t
std::pair< Ipv4Address, GlobalRoutingLSA * > LSDBPair_t
pair of IPv4 addresses / Link State Advertisements
Definition: global-route-manager-impl.h:680
ns3::SPFVertex::ListOfNodeExit_t
std::list< NodeExit_t > ListOfNodeExit_t
container of Exit nodes
Definition: global-route-manager-impl.h:535
ns3::SPFVertex::m_parents
ListOfSPFVertex_t m_parents
parent list
Definition: global-route-manager-impl.h:538
ns3::GlobalRouteManagerImpl::DebugUseLsdb
void DebugUseLsdb(GlobalRouteManagerLSDB *lsdb)
Debugging routine; allow client code to supply a pre-built LSDB.
Definition: global-route-manager-impl.cc:557
ns3::GlobalRouteManagerLSDB
The Link State DataBase (LSDB) of the Global Route Manager.
Definition: global-route-manager-impl.h:581
ns3::SPFVertex::SetDistanceFromRoot
void SetDistanceFromRoot(uint32_t distance)
Set the distance from the root vertex to "this" SPFVertex object.
Definition: global-route-manager-impl.cc:219
ns3::GlobalRouteManagerImpl::SPFGetNextLink
GlobalRoutingLinkRecord * SPFGetNextLink(SPFVertex *v, SPFVertex *w, GlobalRoutingLinkRecord *prev_link)
Search for a link between two vertices.
Definition: global-route-manager-impl.cc:1168
ns3::GlobalRouteManagerImpl::SPFCalculate
void SPFCalculate(Ipv4Address root)
Calculate the shortest path first (SPF) tree.
Definition: global-route-manager-impl.cc:1341
ns3::SPFVertex::GetDistanceFromRoot
uint32_t GetDistanceFromRoot(void) const
Get the distance from the root vertex to "this" SPFVertex object.
Definition: global-route-manager-impl.cc:226
ns3::GlobalRouteManagerImpl::m_spfroot
SPFVertex * m_spfroot
the root node
Definition: global-route-manager-impl.h:770
ns3::GlobalRouteManagerImpl::~GlobalRouteManagerImpl
virtual ~GlobalRouteManagerImpl()
Definition: global-route-manager-impl.cc:547
ns3::SPFVertex::operator=
SPFVertex & operator=(SPFVertex &v)
The SPFVertex copy assignment operator is disallowed.
ns3::GlobalRouteManagerLSDB::~GlobalRouteManagerLSDB
~GlobalRouteManagerLSDB()
Destroy an empty Global Router Manager Link State Database.
Definition: global-route-manager-impl.cc:430
ns3::Ipv4GlobalRouting
Global routing protocol for IPv4 stacks.
Definition: ipv4-global-routing.h:72
ns3::SPFVertex::ListOfSPFVertex_t
std::list< SPFVertex * > ListOfSPFVertex_t
container of SPFVertexes
Definition: global-route-manager-impl.h:537
ns3::SPFVertex::m_lsa
GlobalRoutingLSA * m_lsa
Link State Advertisement.
Definition: global-route-manager-impl.h:531
ns3::GlobalRouteManagerImpl::operator=
GlobalRouteManagerImpl & operator=(GlobalRouteManagerImpl &srmi)
Global Route Manager Implementation assignment operator is disallowed.
ns3::GlobalRouteManagerImpl::DebugSPFCalculate
void DebugSPFCalculate(Ipv4Address root)
Debugging routine; call the core SPF from the unit tests.
Definition: global-route-manager-impl.cc:1246
ns3::GlobalRouteManagerLSDB::LSDBMap_t
std::map< Ipv4Address, GlobalRoutingLSA * > LSDBMap_t
container of IPv4 addresses / Link State Advertisements
Definition: global-route-manager-impl.h:679
ns3::SPFVertex::InheritAllRootExitDirections
void InheritAllRootExitDirections(const SPFVertex *vertex)
Inherit all root exit directions from a given vertex to 'this' vertex.
Definition: global-route-manager-impl.cc:335
ns3::GlobalRouteManagerLSDB::m_database
LSDBMap_t m_database
database of IPv4 addresses / Link State Advertisements
Definition: global-route-manager-impl.h:682
ns3::SPFVertex::GetVertexType
VertexType GetVertexType(void) const
Get the Vertex Type field of a SPFVertex object.
Definition: global-route-manager-impl.cc:184
ns3::SPFVertex::m_nextHop
Ipv4Address m_nextHop
next hop
Definition: global-route-manager-impl.h:534
ns3::GlobalRouteManagerLSDB::GlobalRouteManagerLSDB
GlobalRouteManagerLSDB()
Construct an empty Global Router Manager Link State Database.
Definition: global-route-manager-impl.cc:422
ns3::GlobalRouteManagerImpl::SPFVertexAddParent
void SPFVertexAddParent(SPFVertex *v)
Adds a vertex to the list of children in each of its parents.
Definition: global-route-manager-impl.cc:2192
ns3::GlobalRouteManagerImpl::GlobalRouteManagerImpl
GlobalRouteManagerImpl(GlobalRouteManagerImpl &srmi)
GlobalRouteManagerImpl copy construction is disallowed.
ns3::SPFVertex::VertexNetwork
@ VertexNetwork
Vertex representing a network in the topology.
Definition: global-route-manager-impl.h:81
ns3::GlobalRouteManagerLSDB::Initialize
void Initialize()
Set all LSA flags to an initialized state, for SPF computation.
Definition: global-route-manager-impl.cc:451
ns3::GlobalRouteManagerImpl::SPFNexthopCalculation
int SPFNexthopCalculation(SPFVertex *v, SPFVertex *w, GlobalRoutingLinkRecord *l, uint32_t distance)
Calculate nexthop from root through V (parent) to vertex W (destination) with given distance from roo...
Definition: global-route-manager-impl.cc:980
ns3::SPFVertex::~SPFVertex
~SPFVertex()
Destroy an SPFVertex (Shortest Path First Vertex).
Definition: global-route-manager-impl.cc:125
ns3::GlobalRouteManagerImpl::SPFNext
void SPFNext(SPFVertex *v, CandidateQueue &candidate)
Examine the links in v's LSA and update the list of candidates with any vertices not already on the l...
Definition: global-route-manager-impl.cc:746
ns3::SPFVertex::m_vertexType
VertexType m_vertexType
Vertex type.
Definition: global-route-manager-impl.h:529
ns3::GlobalRouteManagerLSDB::GetLSA
GlobalRoutingLSA * GetLSA(Ipv4Address addr) const
Look up the Link State Advertisement associated with the given link state ID (address).
Definition: global-route-manager-impl.cc:491
ns3::SPFVertex::NodeExit_t
std::pair< Ipv4Address, int32_t > NodeExit_t
IPv4 / interface container for exit nodes.
Definition: global-route-manager-impl.h:291
ns3::GlobalRouteManagerImpl::CheckForStubNode
bool CheckForStubNode(Ipv4Address root)
Test if a node is a stub, from an OSPF sense.
Definition: global-route-manager-impl.cc:1259
ns3::GlobalRouteManagerImpl
A global router implementation.
Definition: global-route-manager-impl.h:713
ns3::GlobalRouteManagerImpl::SPFProcessStubs
void SPFProcessStubs(SPFVertex *v)
Process Stub nodes.
Definition: global-route-manager-impl.cc:1668
ns3::GlobalRouteManagerLSDB::operator=
GlobalRouteManagerLSDB & operator=(GlobalRouteManagerLSDB &lsdb)
The SPFVertex copy assignment operator is disallowed.
ns3::GlobalRouteManagerImpl::GlobalRouteManagerImpl
GlobalRouteManagerImpl()
Definition: global-route-manager-impl.cc:539
ns3::SPFVertex::IsVertexProcessed
bool IsVertexProcessed(void) const
Check the value of the VertexProcessed flag.
Definition: global-route-manager-impl.cc:399
ns3::SPFVertex::m_ecmpRootExits
ListOfNodeExit_t m_ecmpRootExits
store the multiple root's exits for supporting ECMP
Definition: global-route-manager-impl.h:536
ns3::SPFVertex::MergeRootExitDirections
void MergeRootExitDirections(const SPFVertex *vertex)
Merge into 'this' vertex the list of exit directions from another vertex.
Definition: global-route-manager-impl.cc:320
ns3::SPFVertex::GetParent
SPFVertex * GetParent(uint32_t i=0) const
Get a pointer to the SPFVector that is the parent of "this" SPFVertex.
Definition: global-route-manager-impl.cc:243
ns3::GlobalRouteManagerImpl::SPFIntraAddStub
void SPFIntraAddStub(GlobalRoutingLinkRecord *l, SPFVertex *v)
Add a stub to the routing tables.
Definition: global-route-manager-impl.cc:1702
ns3::Ipv4Mask
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:256
ns3::SPFVertex::AddChild
uint32_t AddChild(SPFVertex *child)
Get a borrowed SPFVertex pointer to the specified child of "this" SPFVertex.
Definition: global-route-manager-impl.cc:384
ns3::SPFVertex::m_vertexId
Ipv4Address m_vertexId
Vertex ID.
Definition: global-route-manager-impl.h:530
ns3::SPFVertex::m_distanceFromRoot
uint32_t m_distanceFromRoot
Distance from root node.
Definition: global-route-manager-impl.h:532
ns3::SPFVertex::VertexUnknown
@ VertexUnknown
Uninitialized Link Record.
Definition: global-route-manager-impl.h:79
ns3::SPFVertex::VertexType
VertexType
Enumeration of the possible types of SPFVertex objects.
Definition: global-route-manager-impl.h:78
ns3::SPFVertex::SetVertexType
void SetVertexType(VertexType type)
Set the Vertex Type field of a SPFVertex object.
Definition: global-route-manager-impl.cc:177
ns3::SPFVertex::SPFVertex
SPFVertex()
Construct an empty ("uninitialized") SPFVertex (Shortest Path First Vertex).
Definition: global-route-manager-impl.cc:87
ns3::GlobalRouteManagerImpl::BuildGlobalRoutingDatabase
virtual void BuildGlobalRoutingDatabase()
Build the routing database by gathering Link State Advertisements from each node exporting a GlobalRo...
Definition: global-route-manager-impl.cc:612
ns3::SPFVertex::SetParent
void SetParent(SPFVertex *parent)
Set the pointer to the SPFVector that is the parent of "this" SPFVertex.
Definition: global-route-manager-impl.cc:233
ns3::GlobalRouteManagerLSDB::GetLSAByLinkData
GlobalRoutingLSA * GetLSAByLinkData(Ipv4Address addr) const
Look up the Link State Advertisement associated with the given link state ID (address).
Definition: global-route-manager-impl.cc:509
ns3::SPFVertex::m_vertexProcessed
bool m_vertexProcessed
Flag to note whether vertex has been processed in stage two of SPF computation.
Definition: global-route-manager-impl.h:540
ns3::SPFVertex
Vertex used in shortest path first (SPF) computations.
Definition: global-route-manager-impl.h:69
ns3::SPFVertex::GetNChildren
uint32_t GetNChildren(void) const
Get the number of children of "this" SPFVertex.
Definition: global-route-manager-impl.cc:358
sample-rng-plot.n
n
Definition: sample-rng-plot.py:37
ns3::GlobalRouteManagerLSDB::Insert
void Insert(Ipv4Address addr, GlobalRoutingLSA *lsa)
Insert an IP address / Link State Advertisement pair into the Link State Database.
Definition: global-route-manager-impl.cc:463
ns3::SPFVertex::GetChild
SPFVertex * GetChild(uint32_t n) const
Get a borrowed SPFVertex pointer to the specified child of "this" SPFVertex.
Definition: global-route-manager-impl.cc:365
ns3::SPFVertex::operator<<
friend std::ostream & operator<<(std::ostream &os, const SPFVertex::ListOfSPFVertex_t &vs)
Stream insertion operator.
Definition: global-route-manager-impl.cc:61
ns3::GlobalRouteManagerLSDB::m_extdatabase
std::vector< GlobalRoutingLSA * > m_extdatabase
database of External Link State Advertisements
Definition: global-route-manager-impl.h:683
ns3::GlobalRouteManagerImpl::FindOutgoingInterfaceId
int32_t FindOutgoingInterfaceId(Ipv4Address a, Ipv4Mask amask=Ipv4Mask("255.255.255.255"))
Return the interface number corresponding to a given IP address and mask.
Definition: global-route-manager-impl.cc:1842
global-router-interface.h