A Discrete-Event Network Simulator
API
global-route-manager-impl.h
Go to the documentation of this file.
1 /*
2  * Copyright 2007 University of Washington
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Authors: Craig Dowell (craigdo@ee.washington.edu)
18  * Tom Henderson (tomhend@u.washington.edu)
19  */
20 
21 #ifndef GLOBAL_ROUTE_MANAGER_IMPL_H
22 #define GLOBAL_ROUTE_MANAGER_IMPL_H
23 
25 
26 #include "ns3/ipv4-address.h"
27 #include "ns3/object.h"
28 #include "ns3/ptr.h"
29 
30 #include <list>
31 #include <map>
32 #include <queue>
33 #include <stdint.h>
34 #include <vector>
35 
36 namespace ns3
37 {
38 
39 const uint32_t SPF_INFINITY = 0xffffffff;
40 
41 class CandidateQueue;
42 class Ipv4GlobalRouting;
43 
70 class SPFVertex
71 {
72  public:
81  {
85  };
86 
100  SPFVertex();
101 
118 
126  ~SPFVertex();
127 
128  // Delete copy constructor and assignment operator to avoid misuse
129  SPFVertex(const SPFVertex&) = delete;
130  SPFVertex& operator=(const SPFVertex&) = delete;
131 
141  VertexType GetVertexType() const;
142 
153 
167  Ipv4Address GetVertexId() const;
168 
183  void SetVertexId(Ipv4Address id);
184 
196  GlobalRoutingLSA* GetLSA() const;
197 
211  void SetLSA(GlobalRoutingLSA* lsa);
212 
233  uint32_t GetDistanceFromRoot() const;
234 
253  void SetDistanceFromRoot(uint32_t distance);
254 
296  void SetRootExitDirection(Ipv4Address nextHop, int32_t id = SPF_INFINITY);
297 
298  typedef std::pair<Ipv4Address, int32_t>
300 
349  NodeExit_t GetRootExitDirection(uint32_t i) const;
369  void MergeRootExitDirections(const SPFVertex* vertex);
377  void InheritAllRootExitDirections(const SPFVertex* vertex);
382  uint32_t GetNRootExitDirections() const;
383 
403  SPFVertex* GetParent(uint32_t i = 0) const;
404 
423  void SetParent(SPFVertex* parent);
431  void MergeParent(const SPFVertex* v);
432 
452  uint32_t GetNChildren() const;
453 
480  SPFVertex* GetChild(uint32_t n) const;
481 
508  uint32_t AddChild(SPFVertex* child);
509 
517  void SetVertexProcessed(bool value);
518 
526  bool IsVertexProcessed() const;
527 
534  void ClearVertexProcessed();
535 
536  private:
541  int32_t m_rootOif;
543  typedef std::list<NodeExit_t> ListOfNodeExit_t;
545  typedef std::list<SPFVertex*> ListOfSPFVertex_t;
550 
558  friend std::ostream& operator<<(std::ostream& os, const SPFVertex::ListOfSPFVertex_t& vs);
559 };
560 
575 {
576  public:
584 
593 
594  // Delete copy constructor and assignment operator to avoid misuse
597 
611  void Insert(Ipv4Address addr, GlobalRoutingLSA* lsa);
612 
627  GlobalRoutingLSA* GetLSA(Ipv4Address addr) const;
641 
653  void Initialize();
654 
666  GlobalRoutingLSA* GetExtLSA(uint32_t index) const;
673  uint32_t GetNumExtLSAs() const;
674 
675  private:
676  typedef std::map<Ipv4Address, GlobalRoutingLSA*>
678  typedef std::pair<Ipv4Address, GlobalRoutingLSA*>
680 
682  std::vector<GlobalRoutingLSA*>
684 };
685 
698 {
699  public:
701  virtual ~GlobalRouteManagerImpl();
702 
703  // Delete copy constructor and assignment operator to avoid misuse
706 
714  virtual void DeleteGlobalRoutes();
715 
720  virtual void BuildGlobalRoutingDatabase();
721 
726  virtual void InitializeRoutes();
727 
733 
738  void DebugSPFCalculate(Ipv4Address root);
739 
740  private:
743 
754  bool CheckForStubNode(Ipv4Address root);
755 
762  void SPFCalculate(Ipv4Address root);
763 
773  void SPFProcessStubs(SPFVertex* v);
774 
782 
804  void SPFNext(SPFVertex* v, CandidateQueue& candidate);
805 
820  SPFVertex* w,
822  uint32_t distance);
823 
838  void SPFVertexAddParent(SPFVertex* v);
839 
860  SPFVertex* w,
861  GlobalRoutingLinkRecord* prev_link);
862 
885  void SPFIntraAddRouter(SPFVertex* v);
886 
892  void SPFIntraAddTransit(SPFVertex* v);
893 
901 
908  void SPFAddASExternal(GlobalRoutingLSA* extlsa, SPFVertex* v);
909 
922  int32_t FindOutgoingInterfaceId(Ipv4Address a, Ipv4Mask amask = Ipv4Mask("255.255.255.255"));
923 };
924 
925 } // namespace ns3
926 
927 #endif /* GLOBAL_ROUTE_MANAGER_IMPL_H */
A Candidate Queue used in routing calculations.
A global router implementation.
void SPFCalculate(Ipv4Address root)
Calculate the shortest path first (SPF) tree.
void SPFAddASExternal(GlobalRoutingLSA *extlsa, SPFVertex *v)
Add an external route to the routing tables.
void ProcessASExternals(SPFVertex *v, GlobalRoutingLSA *extlsa)
Process Autonomous Systems (AS) External LSA.
virtual void InitializeRoutes()
Compute routes using a Dijkstra SPF computation and populate per-node forwarding tables.
void SPFProcessStubs(SPFVertex *v)
Process Stub nodes.
virtual void BuildGlobalRoutingDatabase()
Build the routing database by gathering Link State Advertisements from each node exporting a GlobalRo...
GlobalRoutingLinkRecord * SPFGetNextLink(SPFVertex *v, SPFVertex *w, GlobalRoutingLinkRecord *prev_link)
Search for a link between two vertices.
int32_t FindOutgoingInterfaceId(Ipv4Address a, Ipv4Mask amask=Ipv4Mask("255.255.255.255"))
Return the interface number corresponding to a given IP address and mask.
virtual void DeleteGlobalRoutes()
Delete all static routes on all nodes that have a GlobalRouterInterface.
GlobalRouteManagerLSDB * m_lsdb
the Link State DataBase (LSDB) of the Global Route Manager
bool CheckForStubNode(Ipv4Address root)
Test if a node is a stub, from an OSPF sense.
void DebugUseLsdb(GlobalRouteManagerLSDB *lsdb)
Debugging routine; allow client code to supply a pre-built LSDB.
SPFVertex * m_spfroot
the root node
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...
void DebugSPFCalculate(Ipv4Address root)
Debugging routine; call the core SPF from the unit tests.
void SPFIntraAddTransit(SPFVertex *v)
Add a transit to the routing tables.
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...
void SPFIntraAddStub(GlobalRoutingLinkRecord *l, SPFVertex *v)
Add a stub to the routing tables.
GlobalRouteManagerImpl(const GlobalRouteManagerImpl &)=delete
GlobalRouteManagerImpl & operator=(const GlobalRouteManagerImpl &)=delete
void SPFIntraAddRouter(SPFVertex *v)
Add a host route to the routing tables.
void SPFVertexAddParent(SPFVertex *v)
Adds a vertex to the list of children in each of its parents.
The Link State DataBase (LSDB) of the Global Route Manager.
std::map< Ipv4Address, GlobalRoutingLSA * > LSDBMap_t
container of IPv4 addresses / Link State Advertisements
void Initialize()
Set all LSA flags to an initialized state, for SPF computation.
std::pair< Ipv4Address, GlobalRoutingLSA * > LSDBPair_t
pair of IPv4 addresses / Link State Advertisements
~GlobalRouteManagerLSDB()
Destroy an empty Global Router Manager Link State Database.
uint32_t GetNumExtLSAs() const
Get the number of External Link State Advertisements.
GlobalRoutingLSA * GetLSA(Ipv4Address addr) const
Look up the Link State Advertisement associated with the given link state ID (address).
std::vector< GlobalRoutingLSA * > m_extdatabase
database of External Link State Advertisements
void Insert(Ipv4Address addr, GlobalRoutingLSA *lsa)
Insert an IP address / Link State Advertisement pair into the Link State Database.
LSDBMap_t m_database
database of IPv4 addresses / Link State Advertisements
GlobalRouteManagerLSDB & operator=(const GlobalRouteManagerLSDB &)=delete
GlobalRouteManagerLSDB(const GlobalRouteManagerLSDB &)=delete
GlobalRoutingLSA * GetExtLSA(uint32_t index) const
Look up the External Link State Advertisement associated with the given index.
GlobalRouteManagerLSDB()
Construct an empty Global Router Manager Link State Database.
GlobalRoutingLSA * GetLSAByLinkData(Ipv4Address addr) const
Look up the Link State Advertisement associated with the given link state ID (address).
a Link State Advertisement (LSA) for a router, used in global routing.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Global routing protocol for IPv4 stacks.
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:257
Vertex used in shortest path first (SPF) computations.
Ipv4Address GetVertexId() const
Get the Vertex ID field of a SPFVertex object.
SPFVertex & operator=(const SPFVertex &)=delete
std::pair< Ipv4Address, int32_t > NodeExit_t
IPv4 / interface container for exit nodes.
GlobalRoutingLSA * GetLSA() const
Get the Global Router Link State Advertisement returned by the Global Router represented by this SPFV...
Ipv4Address m_nextHop
next hop
void SetVertexId(Ipv4Address id)
Set the Vertex ID field of a SPFVertex object.
void MergeParent(const SPFVertex *v)
Merge the Parent list from the v into this vertex.
VertexType
Enumeration of the possible types of SPFVertex objects.
@ VertexNetwork
Vertex representing a network in the topology.
@ VertexRouter
Vertex representing a router in the topology.
@ VertexUnknown
Uninitialized Link Record.
void InheritAllRootExitDirections(const SPFVertex *vertex)
Inherit all root exit directions from a given vertex to 'this' vertex.
void SetDistanceFromRoot(uint32_t distance)
Set the distance from the root vertex to "this" SPFVertex object.
SPFVertex * GetChild(uint32_t n) const
Get a borrowed SPFVertex pointer to the specified child of "this" SPFVertex.
VertexType GetVertexType() const
Get the Vertex Type field of a SPFVertex object.
bool IsVertexProcessed() const
Check the value of the VertexProcessed flag.
void SetParent(SPFVertex *parent)
Set the pointer to the SPFVector that is the parent of "this" SPFVertex.
void MergeRootExitDirections(const SPFVertex *vertex)
Merge into 'this' vertex the list of exit directions from another vertex.
std::list< SPFVertex * > ListOfSPFVertex_t
container of SPFVertexes
uint32_t GetDistanceFromRoot() const
Get the distance from the root vertex to "this" SPFVertex object.
GlobalRoutingLSA * m_lsa
Link State Advertisement.
~SPFVertex()
Destroy an SPFVertex (Shortest Path First Vertex).
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 ...
void SetVertexProcessed(bool value)
Set the value of the VertexProcessed flag.
std::list< NodeExit_t > ListOfNodeExit_t
container of Exit nodes
void SetVertexType(VertexType type)
Set the Vertex Type field of a SPFVertex object.
void SetLSA(GlobalRoutingLSA *lsa)
Set the Global Router Link State Advertisement returned by the Global Router represented by this SPFV...
uint32_t GetNRootExitDirections() const
Get the number of exit directions from root for reaching 'this' vertex.
int32_t m_rootOif
root Output Interface
friend std::ostream & operator<<(std::ostream &os, const SPFVertex::ListOfSPFVertex_t &vs)
Stream insertion operator.
uint32_t m_distanceFromRoot
Distance from root node.
void ClearVertexProcessed()
Clear the value of the VertexProcessed flag.
bool m_vertexProcessed
Flag to note whether vertex has been processed in stage two of SPF computation.
SPFVertex(const SPFVertex &)=delete
uint32_t GetNChildren() const
Get the number of children of "this" SPFVertex.
Ipv4Address m_vertexId
Vertex ID.
uint32_t AddChild(SPFVertex *child)
Get a borrowed SPFVertex pointer to the specified child of "this" SPFVertex.
NodeExit_t GetRootExitDirection() const
Obtain a pair indicating the exit direction from the root.
ListOfNodeExit_t m_ecmpRootExits
store the multiple root's exits for supporting ECMP
SPFVertex * GetParent(uint32_t i=0) const
Get a pointer to the SPFVector that is the parent of "this" SPFVertex.
ListOfSPFVertex_t m_children
Children list.
VertexType m_vertexType
Vertex type.
ListOfSPFVertex_t m_parents
parent list
SPFVertex()
Construct an empty ("uninitialized") SPFVertex (Shortest Path First Vertex).
Every class exported by the ns3 library is enclosed in the ns3 namespace.
const uint32_t SPF_INFINITY
"infinite" distance between nodes