A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
global-route-manager-impl.h
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"
33 #include "global-router-interface.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  typedef std::pair<Ipv4Address, int32_t> NodeExit_t;
342  void SetRootExitDirection (SPFVertex::NodeExit_t exit);
351  NodeExit_t GetRootExitDirection (uint32_t i) const;
361  NodeExit_t GetRootExitDirection () const;
371  void MergeRootExitDirections (const SPFVertex* vertex);
379  void InheritAllRootExitDirections (const SPFVertex* vertex);
384  uint32_t GetNRootExitDirections () const;
385 
406  SPFVertex* GetParent (uint32_t i = 0) const;
407 
427  void SetParent (SPFVertex* parent);
435  void MergeParent (const SPFVertex* v);
436 
457  uint32_t GetNChildren (void) const;
458 
486  SPFVertex* GetChild (uint32_t n) const;
487 
515  uint32_t AddChild (SPFVertex* child);
516 
524  void SetVertexProcessed (bool value);
525 
533  bool IsVertexProcessed (void) const;
534 
535  void ClearVertexProcessed (void);
536 
537 private:
538  VertexType m_vertexType;
539  Ipv4Address m_vertexId;
540  GlobalRoutingLSA* m_lsa;
541  uint32_t m_distanceFromRoot;
542  int32_t m_rootOif;
543  Ipv4Address m_nextHop;
544  typedef std::list< NodeExit_t > ListOfNodeExit_t;
546  ListOfNodeExit_t m_ecmpRootExits;
547  typedef std::list<SPFVertex*> ListOfSPFVertex_t;
548  ListOfSPFVertex_t m_parents;
549  ListOfSPFVertex_t m_children;
550  bool m_vertexProcessed;
551 
556  SPFVertex (SPFVertex& v);
557 
563 
564  //friend std::ostream& operator<< (std::ostream& os, const ListOfIf_t& ifs);
565  //friend std::ostream& operator<< (std::ostream& os, const ListOfAddr_t& addrs);
566  friend std::ostream& operator<< (std::ostream& os, const SPFVertex::ListOfSPFVertex_t& vs);
567 };
568 
583 {
584 public:
593 
603 
618  void Insert (Ipv4Address addr, GlobalRoutingLSA* lsa);
619 
635  GlobalRoutingLSA* GetLSA (Ipv4Address addr) const;
650 
663  void Initialize ();
664 
665  GlobalRoutingLSA* GetExtLSA (uint32_t index) const;
666  uint32_t GetNumExtLSAs () const;
667 
668 
669 private:
670  typedef std::map<Ipv4Address, GlobalRoutingLSA*> LSDBMap_t;
671  typedef std::pair<Ipv4Address, GlobalRoutingLSA*> LSDBPair_t;
672 
673  LSDBMap_t m_database;
674  std::vector<GlobalRoutingLSA*> m_extdatabase;
675 
681 
687 };
688 
701 {
702 public:
704  virtual ~GlobalRouteManagerImpl ();
714  virtual void DeleteGlobalRoutes ();
715 
721  virtual void BuildGlobalRoutingDatabase ();
722 
728  virtual void InitializeRoutes ();
729 
735 
740  void DebugSPFCalculate (Ipv4Address root);
741 
742 private:
749 
756 
757  SPFVertex* m_spfroot;
758  GlobalRouteManagerLSDB* m_lsdb;
759  bool CheckForStubNode (Ipv4Address root);
760  void SPFCalculate (Ipv4Address root);
761  void SPFProcessStubs (SPFVertex* v);
762  void ProcessASExternals (SPFVertex* v, GlobalRoutingLSA* extlsa);
763  void SPFNext (SPFVertex*, CandidateQueue&);
764  int SPFNexthopCalculation (SPFVertex* v, SPFVertex* w,
765  GlobalRoutingLinkRecord* l, uint32_t distance);
766  void SPFVertexAddParent (SPFVertex* v);
767  GlobalRoutingLinkRecord* SPFGetNextLink (SPFVertex* v, SPFVertex* w,
768  GlobalRoutingLinkRecord* prev_link);
769  void SPFIntraAddRouter (SPFVertex* v);
770  void SPFIntraAddTransit (SPFVertex* v);
771  void SPFIntraAddStub (GlobalRoutingLinkRecord *l, SPFVertex* v);
772  void SPFAddASExternal (GlobalRoutingLSA *extlsa, SPFVertex *v);
773  int32_t FindOutgoingInterfaceId (Ipv4Address a,
774  Ipv4Mask amask = Ipv4Mask ("255.255.255.255"));
775 };
776 
777 } // namespace ns3
778 
779 #endif /* GLOBAL_ROUTE_MANAGER_IMPL_H */
GlobalRoutingLSA * GetLSAByLinkData(Ipv4Address addr) const
Look up the Link State Advertisement associated with the given link state ID (address). This is a variation of the GetLSA call to allow the LSA to be found by matching addr with the LinkData field of the TransitNetwork link record.
virtual void DeleteGlobalRoutes()
Delete all static routes on all nodes that have a GlobalRouterInterface.
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:210
~SPFVertex()
Destroy an SPFVertex (Shortest Path First Vertex).
void InheritAllRootExitDirections(const SPFVertex *vertex)
Inherit all root exit directions from a given vertex to 'this' vertex.
void MergeParent(const SPFVertex *v)
Merge the Parent list from the v into this vertex.
Vertex used in shortest path first (SPF) computations. See RFC 2328, Section 16.
SPFVertex()
Construct an empty ("uninitialized") SPFVertex (Shortest Path First Vertex).
void SetDistanceFromRoot(uint32_t distance)
Set the distance from the root vertex to "this" SPFVertex object.
A global router implementation.
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.
uint32_t GetNChildren(void) const
Get the number of children of "this" SPFVertex.
void Initialize()
Set all LSA flags to an initialized state, for SPF computation.
~GlobalRouteManagerLSDB()
Destroy an empty Global Router Manager Link State Database.
GlobalRouteManagerLSDB & operator=(GlobalRouteManagerLSDB &lsdb)
The SPFVertex copy assignment operator is disallowed. There's no need for it and a compiler provided ...
void DebugSPFCalculate(Ipv4Address root)
Debugging routine; call the core SPF from the unit tests.
uint32_t GetDistanceFromRoot(void) const
Get the distance from the root vertex to "this" SPFVertex object.
SPFVertex & operator=(SPFVertex &v)
The SPFVertex copy assignment operator is disallowed. There's no need for it and a compiler provided ...
virtual void InitializeRoutes()
Compute routes using a Dijkstra SPF computation and populate per-node forwarding tables.
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.
void DebugUseLsdb(GlobalRouteManagerLSDB *)
Debugging routine; allow client code to supply a pre-built LSDB.
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.
void MergeRootExitDirections(const SPFVertex *vertex)
Merge into 'this' vertex the list of exit directions from another vertex.
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
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.
VertexType GetVertexType(void) const
Get the Vertex Type field of a SPFVertex object.
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...
GlobalRouteManagerLSDB()
Construct an empty Global Router Manager Link State Database.
bool IsVertexProcessed(void) const
Check the value of the VertexProcessed flag.
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. There's no need for it and a c...
SPFVertex * GetChild(uint32_t n) const
Get a borrowed SPFVertex pointer to the specified child of "this" SPFVertex.
uint32_t AddChild(SPFVertex *child)
Get a borrowed SPFVertex pointer to the specified child of "this" SPFVertex.