OSPFArea.h

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2006 Andras Babos and Andras Varga
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU Lesser General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU Lesser General Public License
00015 // along with this program; if not, see <http://www.gnu.org/licenses/>.
00016 //
00017 
00018 #ifndef __INET_OSPFAREA_H
00019 #define __INET_OSPFAREA_H
00020 
00021 #include <vector>
00022 #include <map>
00023 #include "OSPFcommon.h"
00024 #include "OSPFInterface.h"
00025 #include "LSA.h"
00026 #include "OSPFRoutingTableEntry.h"
00027 
00028 namespace OSPF {
00029 
00030 class Router;
00031 
00032 class Area : public cPolymorphic {
00033 private:
00034     AreaID                                                  areaID;
00035     std::map<IPv4AddressRange, bool, IPv4AddressRange_Less> advertiseAddressRanges;
00036     std::vector<IPv4AddressRange>                           areaAddressRanges;
00037     std::vector<Interface*>                                 associatedInterfaces;
00038     std::vector<HostRouteParameters>                        hostRoutes;
00039     std::map<LinkStateID, RouterLSA*>                       routerLSAsByID;
00040     std::vector<RouterLSA*>                                 routerLSAs;
00041     std::map<LinkStateID, NetworkLSA*>                      networkLSAsByID;
00042     std::vector<NetworkLSA*>                                networkLSAs;
00043     std::map<LSAKeyType, SummaryLSA*, LSAKeyType_Less>      summaryLSAsByID;
00044     std::vector<SummaryLSA*>                                summaryLSAs;
00045     bool                                                    transitCapability;
00046     bool                                                    externalRoutingCapability;
00047     Metric                                                  stubDefaultCost;
00048     RouterLSA*                                              spfTreeRoot;
00049 
00050     Router*                                                 parentRouter;
00051 public:
00052             Area(AreaID id = BackboneAreaID);
00053     virtual ~Area(void);
00054 
00055     void                SetAreaID                       (AreaID areaId)                                 { areaID = areaId; }
00056     AreaID              GetAreaID                       (void) const                                    { return areaID; }
00057     void                AddAddressRange                 (IPv4AddressRange addressRange, bool advertise) { areaAddressRanges.push_back(addressRange); advertiseAddressRanges[addressRange] = advertise; }
00058     unsigned int        GetAddressRangeCount            (void) const                                    { return areaAddressRanges.size(); }
00059     IPv4AddressRange    GetAddressRange                 (unsigned int index) const                      { return areaAddressRanges[index]; }
00060     void                AddHostRoute                    (HostRouteParameters& hostRouteParameters)      { hostRoutes.push_back(hostRouteParameters); }
00061     void                SetTransitCapability            (bool transit)                                  { transitCapability = transit; }
00062     bool                GetTransitCapability            (void) const                                    { return transitCapability; }
00063     void                SetExternalRoutingCapability    (bool flooded)                                  { externalRoutingCapability = flooded; }
00064     bool                GetExternalRoutingCapability    (void) const                                    { return externalRoutingCapability; }
00065     void                SetStubDefaultCost              (Metric cost)                                   { stubDefaultCost = cost; }
00066     Metric              GetStubDefaultCost              (void) const                                    { return stubDefaultCost; }
00067     void                SetSPFTreeRoot                  (RouterLSA* root)                               { spfTreeRoot = root; }
00068     RouterLSA*          GetSPFTreeRoot                  (void)                                          { return spfTreeRoot; }
00069     const RouterLSA*    GetSPFTreeRoot                  (void) const                                    { return spfTreeRoot; }
00070 
00071     void                SetRouter                       (Router* router)                                { parentRouter = router; }
00072     Router*             GetRouter                       (void)                                          { return parentRouter; }
00073     const Router*       GetRouter                       (void) const                                    { return parentRouter; }
00074 
00075     unsigned long       GetRouterLSACount               (void) const                                    { return routerLSAs.size(); }
00076     RouterLSA*          GetRouterLSA                    (unsigned long i)                               { return routerLSAs[i]; }
00077     const RouterLSA*    GetRouterLSA                    (unsigned long i) const                         { return routerLSAs[i]; }
00078     unsigned long       GetNetworkLSACount              (void) const                                    { return networkLSAs.size(); }
00079     NetworkLSA*         GetNetworkLSA                   (unsigned long i)                               { return networkLSAs[i]; }
00080     const NetworkLSA*   GetNetworkLSA                   (unsigned long i) const                         { return networkLSAs[i]; }
00081     unsigned long       GetSummaryLSACount              (void) const                                    { return summaryLSAs.size(); }
00082     SummaryLSA*         GetSummaryLSA                   (unsigned long i)                               { return summaryLSAs[i]; }
00083     const SummaryLSA*   GetSummaryLSA                   (unsigned long i) const                         { return summaryLSAs[i]; }
00084 
00085     bool                ContainsAddress                     (IPv4Address address) const;
00086     bool                HasAddressRange                     (IPv4AddressRange addressRange) const;
00087     IPv4AddressRange    GetContainingAddressRange           (IPv4AddressRange addressRange, bool* advertise = NULL) const;
00088     void                AddInterface                        (Interface* intf);
00089     Interface*          GetInterface                        (unsigned char ifIndex);
00090     Interface*          GetInterface                        (IPv4Address address);
00091     bool                HasVirtualLink                      (AreaID withTransitArea) const;
00092     Interface*          FindVirtualLink                     (RouterID routerID);
00093 
00094     bool                InstallRouterLSA                    (OSPFRouterLSA* lsa);
00095     bool                InstallNetworkLSA                   (OSPFNetworkLSA* lsa);
00096     bool                InstallSummaryLSA                   (OSPFSummaryLSA* lsa);
00097     RouterLSA*          FindRouterLSA                       (LinkStateID linkStateID);
00098     const RouterLSA*    FindRouterLSA                       (LinkStateID linkStateID) const;
00099     NetworkLSA*         FindNetworkLSA                      (LinkStateID linkStateID);
00100     const NetworkLSA*   FindNetworkLSA                      (LinkStateID linkStateID) const;
00101     SummaryLSA*         FindSummaryLSA                      (LSAKeyType lsaKey);
00102     const SummaryLSA*   FindSummaryLSA                      (LSAKeyType lsaKey) const;
00103     void                AgeDatabase                         (void);
00104     bool                HasAnyNeighborInStates              (int states) const;
00105     void                RemoveFromAllRetransmissionLists    (LSAKeyType lsaKey);
00106     bool                IsOnAnyRetransmissionList           (LSAKeyType lsaKey) const;
00107     bool                FloodLSA                            (OSPFLSA* lsa, Interface* intf = NULL, Neighbor* neighbor = NULL);
00108     bool                IsLocalAddress                      (IPv4Address address) const;
00109     RouterLSA*          OriginateRouterLSA                  (void);
00110     NetworkLSA*         OriginateNetworkLSA                 (const Interface* intf);
00111     SummaryLSA*         OriginateSummaryLSA                 (const RoutingTableEntry* entry,
00112                                                              const std::map<LSAKeyType, bool, LSAKeyType_Less>& originatedLSAs,
00113                                                              SummaryLSA*& lsaToReoriginate);
00114     void                CalculateShortestPathTree           (std::vector<RoutingTableEntry*>& newRoutingTable);
00115     void                CalculateInterAreaRoutes            (std::vector<RoutingTableEntry*>& newRoutingTable);
00116     void                ReCheckSummaryLSAs                  (std::vector<RoutingTableEntry*>& newRoutingTable);
00117 
00118     void        info(char* buffer);
00119     std::string detailedInfo(void) const;
00120 
00121 private:
00122     SummaryLSA*             OriginateSummaryLSA                     (const OSPF::SummaryLSA* summaryLSA);
00123     bool                    HasLink                                 (OSPFLSA* fromLSA, OSPFLSA* toLSA) const;
00124     std::vector<NextHop>*   CalculateNextHops                       (OSPFLSA* destination, OSPFLSA* parent) const;
00125     std::vector<NextHop>*   CalculateNextHops                       (Link& destination, OSPFLSA* parent) const;
00126 
00127     LinkStateID             GetUniqueLinkStateID                    (IPv4AddressRange destination,
00128                                                                      Metric destinationCost,
00129                                                                      SummaryLSA*& lsaToReoriginate) const;
00130 
00131     bool                    FindSameOrWorseCostRoute                (const std::vector<OSPF::RoutingTableEntry*>& newRoutingTable,
00132                                                                      const OSPF::SummaryLSA&                      currentLSA,
00133                                                                      unsigned short                               currentCost,
00134                                                                      bool&                                        destinationInRoutingTable,
00135                                                                      std::list<OSPF::RoutingTableEntry*>&         sameOrWorseCost) const;
00136 
00137     RoutingTableEntry*      CreateRoutingTableEntryFromSummaryLSA   (const OSPF::SummaryLSA&        summaryLSA,
00138                                                                      unsigned short                 entryCost,
00139                                                                      const OSPF::RoutingTableEntry& borderRouterEntry) const;
00140 };
00141 
00142 } // namespace OSPF
00143 
00144 inline std::ostream& operator<< (std::ostream& ostr, OSPF::Area& area)
00145 {
00146     ostr << area.detailedInfo();
00147     return ostr;
00148 }
00149 
00150 #endif // __INET_OSPFAREA_H
00151