A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
global-router-interface.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_ROUTER_INTERFACE_H
23 #define GLOBAL_ROUTER_INTERFACE_H
24 
25 #include <stdint.h>
26 #include <list>
27 #include "ns3/object.h"
28 #include "ns3/ptr.h"
29 #include "ns3/node.h"
30 #include "ns3/channel.h"
31 #include "ns3/ipv4-address.h"
32 #include "ns3/net-device-container.h"
33 #include "ns3/bridge-net-device.h"
34 #include "ns3/global-route-manager.h"
35 #include "ns3/ipv4-routing-table-entry.h"
36 
37 namespace ns3 {
38 
39 class GlobalRouter;
40 class Ipv4GlobalRouting;
41 
50 {
51 public:
52  friend class GlobalRoutingLSA;
60  enum LinkType {
61  Unknown = 0,
66  };
67 
76 
89  LinkType linkType,
90  Ipv4Address linkId,
91  Ipv4Address linkData,
92  uint16_t metric);
93 
100 
112  Ipv4Address GetLinkId (void) const;
113 
125  void SetLinkId (Ipv4Address addr);
126 
138  Ipv4Address GetLinkData (void) const;
139 
151  void SetLinkData (Ipv4Address addr);
152 
162  LinkType GetLinkType (void) const;
163 
173  void SetLinkType (LinkType linkType);
174 
186  uint16_t GetMetric (void) const;
187 
199  void SetMetric (uint16_t metric);
200 
201 private:
213 
223  Ipv4Address m_linkData; // for links to RouterLSA,
224 
230 
240  uint16_t m_metric;
241 };
242 
252 {
253 public:
258  enum LSType {
259  Unknown = 0,
265  };
271  enum SPFStatus {
275  };
283 
293  GlobalRoutingLSA(SPFStatus status, Ipv4Address linkStateId,
294  Ipv4Address advertisingRtr);
295 
305 
312 
326 
337  void CopyLinkRecords (const GlobalRoutingLSA& lsa);
338 
345  uint32_t AddLinkRecord (GlobalRoutingLinkRecord* lr);
346 
352  uint32_t GetNLinkRecords (void) const;
353 
360  GlobalRoutingLinkRecord* GetLinkRecord (uint32_t n) const;
361 
366  void ClearLinkRecords (void);
367 
374  bool IsEmpty (void) const;
375 
380  void Print (std::ostream &os) const;
381 
385  LSType GetLSType (void) const;
389  void SetLSType (LSType typ);
390 
399  Ipv4Address GetLinkStateId (void) const;
400 
408  void SetLinkStateId (Ipv4Address addr);
409 
418  Ipv4Address GetAdvertisingRouter (void) const;
419 
429 
435 
442  Ipv4Mask GetNetworkLSANetworkMask (void) const;
443 
450  uint32_t AddAttachedRouter (Ipv4Address addr);
451 
457  uint32_t GetNAttachedRouters (void) const;
458 
465  Ipv4Address GetAttachedRouter (uint32_t n) const;
466 
473  SPFStatus GetStatus (void) const;
474 
480  void SetStatus (SPFStatus status);
481 
486  Ptr<Node> GetNode (void) const;
487 
492  void SetNode (Ptr<Node> node);
493 
494 private:
508 
517 
521  typedef std::list<GlobalRoutingLinkRecord*> ListOfLinkRecords_t;
522 
534 
539 
543  typedef std::list<Ipv4Address> ListOfAttachedRouters_t;
544 
554 
562  uint32_t m_node_id;
563 };
564 
572 std::ostream& operator<< (std::ostream& os, GlobalRoutingLSA& lsa);
573 
583 class GlobalRouter : public Object
584 {
585 public:
590  static TypeId GetTypeId (void);
591 
595  GlobalRouter ();
596 
602 
608 
618  Ipv4Address GetRouterId (void) const;
619 
637  uint32_t DiscoverLSAs (void);
638 
652  uint32_t GetNumLSAs (void) const;
653 
674  bool GetLSA (uint32_t n, GlobalRoutingLSA &lsa) const;
675 
683  void InjectRoute (Ipv4Address network, Ipv4Mask networkMask);
684 
690  uint32_t GetNInjectedRoutes (void);
691 
699 
711  void RemoveInjectedRoute (uint32_t i);
712 
722  bool WithdrawRoute (Ipv4Address network, Ipv4Mask networkMask);
723 
724 private:
725  virtual ~GlobalRouter ();
726 
730  void ClearLSAs (void);
731 
742 
757  bool FindInterfaceForDevice (Ptr<Node> node, Ptr<NetDevice> nd, uint32_t &index) const;
758 
771  Ipv4Address FindDesignatedRouterForLink (Ptr<NetDevice> ndLocal, bool allowRecursion) const;
772 
785  bool AnotherRouterOnLink (Ptr<NetDevice> nd, bool allowRecursion) const;
786 
795 
804 
813 
821 
829 
837 
838 
839  typedef std::list<GlobalRoutingLSA*> ListOfLSAs_t;
841 
844 
845  typedef std::list<Ipv4RoutingTableEntry *> InjectedRoutes;
846  typedef std::list<Ipv4RoutingTableEntry *>::const_iterator InjectedRoutesCI;
847  typedef std::list<Ipv4RoutingTableEntry *>::iterator InjectedRoutesI;
849 
850  // inherited from Object
851  virtual void DoDispose (void);
852 
857 
862 };
863 
864 } // namespace ns3
865 
866 #endif /* GLOBAL_ROUTER_INTERFACE_H */
void SetRoutingProtocol(Ptr< Ipv4GlobalRouting > routing)
Set the specific Global Routing Protocol to be used.
LSType GetLSType(void) const
Return the LSType field of the LSA.
Ptr< Ipv4GlobalRouting > GetRoutingProtocol(void)
Get the specific Global Routing Protocol used.
GlobalRoutingLinkRecord * GetLinkRecord(uint32_t n) const
Return a pointer to the specified Global Routing Link Record.
std::list< GlobalRoutingLSA * > ListOfLSAs_t
container for the GlobalRoutingLSAs
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
~GlobalRoutingLSA()
Destroy an existing Global Routing Link State Advertisement.
Ipv4Address m_advertisingRtr
The Advertising Router is defined by the OSPF spec.
Ipv4RoutingTableEntry * GetInjectedRoute(uint32_t i)
Return the injected route indexed by i.
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:210
std::list< Ipv4RoutingTableEntry * >::const_iterator InjectedRoutesCI
Const Iterator to container of Ipv4RoutingTableEntry.
static TypeId GetTypeId(void)
Get the type ID.
bool WithdrawRoute(Ipv4Address network, Ipv4Mask networkMask)
Withdraw a route from the global unicast routing table.
bool FindInterfaceForDevice(Ptr< Node > node, Ptr< NetDevice > nd, uint32_t &index) const
Given a node and a net device, find an IPV4 interface index that corresponds to that net device...
uint32_t DiscoverLSAs(void)
Walk the connected channels, discover the adjacent routers and build the associated number of Global ...
Ipv4Address FindDesignatedRouterForLink(Ptr< NetDevice > ndLocal, bool allowRecursion) const
Finds a designated router.
void SetAdvertisingRouter(Ipv4Address rtr)
Set the Advertising Router as defined by the OSPF spec.
LSType m_lsType
The type of the LSA.
uint32_t AddLinkRecord(GlobalRoutingLinkRecord *lr)
Add a given Global Routing Link Record to the LSA.
GlobalRouter & operator=(GlobalRouter &sr)
Global Router assignment operator is disallowed.
Ipv4Mask m_networkLSANetworkMask
Each Network LSA contains the network mask of the attached network.
bool GetLSA(uint32_t n, GlobalRoutingLSA &lsa) const
Get a Global Routing Link State Advertisements that this router has said that it can export...
uint32_t GetNInjectedRoutes(void)
Get the number of injected routes that have been added to the routing table.
void ProcessSingleBroadcastLink(Ptr< NetDevice > nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c)
Process a single broadcast link.
uint32_t AddAttachedRouter(Ipv4Address addr)
Add an attached router to the list in the NetworkLSA.
InjectedRoutes m_injectedRoutes
Routes we are exporting.
Ipv4Mask GetNetworkLSANetworkMask(void) const
For a Network LSA, get the Network Mask field that precedes the list of attached routers.
void SetNode(Ptr< Node > node)
Set the Node pointer of the node that originated this LSA.
void ProcessBridgedBroadcastLink(Ptr< NetDevice > nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c)
Process a bridged broadcast link.
Ipv4Address GetAdvertisingRouter(void) const
Get the Advertising Router as defined by the OSPF spec.
void ClearLinkRecords(void)
Release all of the Global Routing Link Records present in the Global Routing Link State Advertisement...
LSType
corresponds to LS type field of RFC 2328 OSPF LSA header
Ptr< Ipv4GlobalRouting > m_routingProtocol
the Ipv4GlobalRouting in use
A record of an IPv4 routing table entry for Ipv4GlobalRouting and Ipv4StaticRouting.
a Link State Advertisement (LSA) for a router, used in global routing.
void InjectRoute(Ipv4Address network, Ipv4Mask networkMask)
Inject a route to be circulated to other routers as an external route.
void ClearLSAs(void)
Clear list of LSAs.
holds a vector of ns3::NetDevice pointers
void SetLSType(LSType typ)
Set the LS type field of the LSA.
void Print(std::ostream &os) const
Print the contents of the Global Routing Link State Advertisement and any Global Routing Link Records...
std::list< Ipv4Address > ListOfAttachedRouters_t
A convenience typedef to avoid too much writers cramp.
void RemoveInjectedRoute(uint32_t i)
Withdraw a route from the global unicast routing table.
SPFStatus GetStatus(void) const
Get the SPF status of the advertisement.
SPFStatus m_status
This is a tristate flag used internally in the SPF computation to mark if an SPFVertex (a data struct...
Vertex is in the SPF candidate queue.
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:43
void SetStatus(SPFStatus status)
Set the SPF status of the advertisement.
uint32_t GetNAttachedRouters(void) const
Return the number of attached routers listed in the NetworkLSA.
uint32_t GetNLinkRecords(void) const
Return the number of Global Routing Link Records in the LSA.
ListOfLSAs_t m_LSAs
database of GlobalRoutingLSAs
std::list< Ipv4RoutingTableEntry * > InjectedRoutes
container of Ipv4RoutingTableEntry
An interface aggregated to a node to provide global routing info.
Ipv4Address m_routerId
router ID (its IPv4 address)
Ptr< BridgeNetDevice > NetDeviceIsBridged(Ptr< NetDevice > nd) const
Decide whether or not a given net device is being bridged by a BridgeNetDevice.
Ipv4Address m_linkStateId
The Link State ID is defined by the OSPF spec.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
void CopyLinkRecords(const GlobalRoutingLSA &lsa)
Copy any Global Routing Link Records in a given Global Routing Link State Advertisement to the curren...
GlobalRoutingLSA & operator=(const GlobalRoutingLSA &lsa)
Assignment operator for a Global Routing Link State Advertisement.
void SetNetworkLSANetworkMask(Ipv4Mask mask)
For a Network LSA, set the Network Mask field that precedes the list of attached routers.
bool AnotherRouterOnLink(Ptr< NetDevice > nd, bool allowRecursion) const
Checks for the presence of another router on the NetDevice.
SPFStatus
Enumeration of the possible values of the status flag in the Routing Link State Advertisements.
uint32_t GetNumLSAs(void) const
Get the Number of Global Routing Link State Advertisements that this router can export.
GlobalRouter()
Create a Global Router class.
Ipv4Address GetRouterId(void) const
Get the Router ID associated with this Global Router.
Ipv4Address GetAttachedRouter(uint32_t n) const
Return an Ipv4Address corresponding to the specified attached router.
Ptr< Node > GetNode(void) const
Get the Node pointer of the node that originated this LSA.
void BuildNetworkLSAs(NetDeviceContainer c)
Build one NetworkLSA for each net device talking to a network that we are the designated router for...
ListOfAttachedRouters_t m_attachedRouters
Each Network LSA contains a list of attached routers.
bool IsEmpty(void) const
Check to see if the list of Global Routing Link Records present in the Global Routing Link State Adve...
a base class which provides memory management and object aggregation
Definition: object.h:63
Ptr< NetDevice > GetAdjacent(Ptr< NetDevice > nd, Ptr< Channel > ch) const
Link through the given channel and find the net device that's on the other end.
std::list< GlobalRoutingLinkRecord * > ListOfLinkRecords_t
A convenience typedef to avoid too much writers cramp.
GlobalRoutingLSA()
Create a blank Global Routing Link State Advertisement.
void ProcessPointToPointLink(Ptr< NetDevice > ndLocal, GlobalRoutingLSA *pLSA)
Process a point to point link.
ListOfLinkRecords_t m_linkRecords
Each Link State Advertisement contains a number of Link Records that describe the kinds of links that...
a unique identifier for an interface.
Definition: type-id.h:49
void SetLinkStateId(Ipv4Address addr)
Set the Link State ID is defined by the OSPF spec.
Ipv4Address GetLinkStateId(void) const
Get the Link State ID as defined by the OSPF spec.
std::list< Ipv4RoutingTableEntry * >::iterator InjectedRoutesI
Iterator to container of Ipv4RoutingTableEntry.
void ProcessBroadcastLink(Ptr< NetDevice > nd, GlobalRoutingLSA *pLSA, NetDeviceContainer &c)
Process a generic broadcast link.