A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
66 class SPFVertex
67 {
68 public:
77  enum VertexType {
81  };
82 
97  SPFVertex();
98 
116 
125  ~SPFVertex();
126 
137  VertexType GetVertexType (void) const;
138 
149  void SetVertexType (VertexType type);
150 
165  Ipv4Address GetVertexId (void) const;
166 
182  void SetVertexId (Ipv4Address id);
183 
196  GlobalRoutingLSA* GetLSA (void) const;
197 
212  void SetLSA (GlobalRoutingLSA* lsa);
213 
235  uint32_t GetDistanceFromRoot (void) const;
236 
256  void SetDistanceFromRoot (uint32_t distance);
257 
300  void SetRootExitDirection (Ipv4Address nextHop, int32_t id = SPF_INFINITY);
301 
302  typedef std::pair<Ipv4Address, int32_t> NodeExit_t;
303 
353  NodeExit_t GetRootExitDirection (uint32_t i) const;
373  void MergeRootExitDirections (const SPFVertex* vertex);
381  void InheritAllRootExitDirections (const SPFVertex* vertex);
386  uint32_t GetNRootExitDirections () const;
387 
408  SPFVertex* GetParent (uint32_t i = 0) const;
409 
429  void SetParent (SPFVertex* parent);
437  void MergeParent (const SPFVertex* v);
438 
459  uint32_t GetNChildren (void) const;
460 
488  SPFVertex* GetChild (uint32_t n) const;
489 
517  uint32_t AddChild (SPFVertex* child);
518 
526  void SetVertexProcessed (bool value);
527 
535  bool IsVertexProcessed (void) const;
536 
543  void ClearVertexProcessed (void);
544 
545 private:
550  int32_t m_rootOif;
552  typedef std::list< NodeExit_t > ListOfNodeExit_t;
554  typedef std::list<SPFVertex*> ListOfSPFVertex_t;
558 
563  SPFVertex (SPFVertex& v);
564 
570 
578  friend std::ostream& operator<< (std::ostream& os, const SPFVertex::ListOfSPFVertex_t& vs);
579 };
580 
595 {
596 public:
605 
615 
630  void Insert (Ipv4Address addr, GlobalRoutingLSA* lsa);
631 
647  GlobalRoutingLSA* GetLSA (Ipv4Address addr) const;
662 
675  void Initialize ();
676 
689  GlobalRoutingLSA* GetExtLSA (uint32_t index) const;
697  uint32_t GetNumExtLSAs () const;
698 
699 
700 private:
701  typedef std::map<Ipv4Address, GlobalRoutingLSA*> LSDBMap_t;
702  typedef std::pair<Ipv4Address, GlobalRoutingLSA*> LSDBPair_t;
703 
705  std::vector<GlobalRoutingLSA*> m_extdatabase;
706 
712 
718 };
719 
732 {
733 public:
735  virtual ~GlobalRouteManagerImpl ();
745  virtual void DeleteGlobalRoutes ();
746 
752  virtual void BuildGlobalRoutingDatabase ();
753 
759  virtual void InitializeRoutes ();
760 
766 
772  void DebugSPFCalculate (Ipv4Address root);
773 
774 private:
781 
788 
791 
802  bool CheckForStubNode (Ipv4Address root);
803 
810  void SPFCalculate (Ipv4Address root);
811 
821  void SPFProcessStubs (SPFVertex* v);
822 
829  void ProcessASExternals (SPFVertex* v, GlobalRoutingLSA* extlsa);
830 
852  void SPFNext (SPFVertex* v, CandidateQueue& candidate);
853 
868  GlobalRoutingLinkRecord* l, uint32_t distance);
869 
884  void SPFVertexAddParent (SPFVertex* v);
885 
906  GlobalRoutingLinkRecord* prev_link);
907 
930  void SPFIntraAddRouter (SPFVertex* v);
931 
937  void SPFIntraAddTransit (SPFVertex* v);
938 
946 
953  void SPFAddASExternal (GlobalRoutingLSA *extlsa, SPFVertex *v);
954 
968  Ipv4Mask amask = Ipv4Mask ("255.255.255.255"));
969 };
970 
971 } // namespace ns3
972 
973 #endif /* GLOBAL_ROUTE_MANAGER_IMPL_H */
int32_t FindOutgoingInterfaceId(Ipv4Address a, Ipv4Mask amask=Ipv4Mask("255.255.255.255"))
Return the interface number corresponding to a given IP address and mask.
GlobalRoutingLSA * GetLSAByLinkData(Ipv4Address addr) const
Look up the Link State Advertisement associated with the given link state ID (address).
ListOfSPFVertex_t m_parents
parent list
void SPFAddASExternal(GlobalRoutingLSA *extlsa, SPFVertex *v)
Add an external route to the routing tables.
uint32_t m_distanceFromRoot
Distance from root node.
virtual void DeleteGlobalRoutes()
Delete all static routes on all nodes that have a GlobalRouterInterface.
const uint32_t SPF_INFINITY
"infinite" distance between nodes
void SetParent(SPFVertex *parent)
Set the pointer to the SPFVector that is the parent of "this" SPFVertex.
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:222
~SPFVertex()
Destroy an SPFVertex (Shortest Path First Vertex).
void SPFIntraAddRouter(SPFVertex *v)
Add a host route to the routing tables.
GlobalRouteManagerLSDB * m_lsdb
the Link State DataBase (LSDB) of the Global Route Manager
void ProcessASExternals(SPFVertex *v, GlobalRoutingLSA *extlsa)
Process Autonomous Systems (AS) External LSA.
uint32_t GetNumExtLSAs() const
Get the number of External Link State Advertisements.
std::list< SPFVertex * > ListOfSPFVertex_t
container of SPFVertexes
void SPFIntraAddStub(GlobalRoutingLinkRecord *l, SPFVertex *v)
Add a stub to the routing tables.
VertexType m_vertexType
Vertex type.
void InheritAllRootExitDirections(const SPFVertex *vertex)
Inherit all root exit directions from a given vertex to 'this' vertex.
void SPFProcessStubs(SPFVertex *v)
Process Stub nodes.
void MergeParent(const SPFVertex *v)
Merge the Parent list from the v into this vertex.
std::vector< GlobalRoutingLSA * > m_extdatabase
database of External Link State Advertisements
LSDBMap_t m_database
database of IPv4 addresses / Link State Advertisements
Vertex used in shortest path first (SPF) computations.
GlobalRoutingLinkRecord * SPFGetNextLink(SPFVertex *v, SPFVertex *w, GlobalRoutingLinkRecord *prev_link)
Search for a link between two vertexes.
SPFVertex()
Construct an empty ("uninitialized") SPFVertex (Shortest Path First Vertex).
friend std::ostream & operator<<(std::ostream &os, const SPFVertex::ListOfSPFVertex_t &vs)
Stream insertion operator.
GlobalRoutingLSA * m_lsa
Link State Advertisement.
void SetDistanceFromRoot(uint32_t distance)
Set the distance from the root vertex to "this" SPFVertex object.
A global router implementation.
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...
ListOfNodeExit_t m_ecmpRootExits
store the multiple root's exits for supporting ECMP
A Candidate Queue used in static routing.
a Link State Advertisement (LSA) for a router, used in global routing.
ListOfSPFVertex_t m_children
Children list.
uint32_t GetNChildren(void) const
Get the number of children of "this" SPFVertex.
std::pair< Ipv4Address, int32_t > NodeExit_t
IPv4 / interface container for exit nodes.
std::pair< Ipv4Address, GlobalRoutingLSA * > LSDBPair_t
pair of IPv4 addresses / Link State Advertisements
GlobalRoutingLSA * GetExtLSA(uint32_t index) const
Look up the External Link State Advertisement associated with the given index.
void Initialize()
Set all LSA flags to an initialized state, for SPF computation.
~GlobalRouteManagerLSDB()
Destroy an empty Global Router Manager Link State Database.
Global routing protocol for IP version 4 stacks.
GlobalRouteManagerLSDB & operator=(GlobalRouteManagerLSDB &lsdb)
The SPFVertex copy assignment operator is disallowed.
void DebugSPFCalculate(Ipv4Address root)
Debugging routine; call the core SPF from the unit tests.
std::list< NodeExit_t > ListOfNodeExit_t
container of Exit nodes
uint32_t GetDistanceFromRoot(void) const
Get the distance from the root vertex to "this" SPFVertex object.
void SPFIntraAddTransit(SPFVertex *v)
Add a transit to the routing tables.
SPFVertex & operator=(SPFVertex &v)
The SPFVertex copy assignment operator is disallowed.
virtual void InitializeRoutes()
Compute routes using a Dijkstra SPF computation and populate per-node forwarding tables.
int32_t m_rootOif
root Output Interface
GlobalRoutingLSA * GetLSA(void) const
Get the Global Router Link State Advertisement returned by the Global Router represented by this SPFV...
void SetVertexType(VertexType type)
Set the Vertex Type field of a SPFVertex object.
Ipv4Address m_vertexId
Vertex ID.
void DebugUseLsdb(GlobalRouteManagerLSDB *)
Debugging routine; allow client code to supply a pre-built LSDB.
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 SetLSA(GlobalRoutingLSA *lsa)
Set the Global Router Link State Advertisement returned by the Global Router represented by this SPFV...
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 SetVertexId(Ipv4Address id)
Set the Vertex ID field of a SPFVertex object.
GlobalRoutingLSA * GetLSA(Ipv4Address addr) const
Look up the Link State Advertisement associated with the given link state ID (address).
void Insert(Ipv4Address addr, GlobalRoutingLSA *lsa)
Insert an IP address / Link State Advertisement pair into the Link State Database.
bool CheckForStubNode(Ipv4Address root)
Test if a node is a stub, from an OSPF sense.
void MergeRootExitDirections(const SPFVertex *vertex)
Merge into 'this' vertex the list of exit directions from another vertex.
Vertex representing a router in the topology.
uint32_t GetNRootExitDirections() const
Get the number of exit directions from root for reaching 'this' vertex.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
Ipv4Address m_nextHop
next hop
SPFVertex * GetParent(uint32_t i=0) const
Get a pointer to the SPFVector that is the parent of "this" SPFVertex.
NodeExit_t GetRootExitDirection() const
Obtain a pair indicating the exit direction from the root.
std::map< Ipv4Address, GlobalRoutingLSA * > LSDBMap_t
container of IPv4 addresses / Link State Advertisements
void ClearVertexProcessed(void)
Clear the value of the VertexProcessed flag.
VertexType GetVertexType(void) const
Get the Vertex Type field of a SPFVertex object.
void SPFCalculate(Ipv4Address root)
Calculate the shortest path first (SPF) tree.
bool m_vertexProcessed
Flag to note whether vertex has been processed in stage two of SPF computation.
The Link State DataBase (LSDB) of the Global Route Manager.
void SetVertexProcessed(bool value)
Set the value of the VertexProcessed flag.
VertexType
Enumeration of the possible types of SPFVertex objects.
virtual void BuildGlobalRoutingDatabase()
Build the routing database by gathering Link State Advertisements from each node exporting a GlobalRo...
SPFVertex * m_spfroot
the root node
GlobalRouteManagerLSDB()
Construct an empty Global Router Manager Link State Database.
bool IsVertexProcessed(void) const
Check the value of the VertexProcessed flag.
Vertex representing a network in the topology.
Ipv4Address GetVertexId(void) const
Get the Vertex ID field of a SPFVertex object.
GlobalRouteManagerImpl & operator=(GlobalRouteManagerImpl &srmi)
Global Route Manager Implementation assignment operator is disallowed.
SPFVertex * GetChild(uint32_t n) const
Get a borrowed SPFVertex pointer to the specified child of "this" SPFVertex.
void SPFVertexAddParent(SPFVertex *v)
Adds a vertex to the list of children in each of its parents.
uint32_t AddChild(SPFVertex *child)
Get a borrowed SPFVertex pointer to the specified child of "this" SPFVertex.