INET Framework for OMNeT++/OMNEST
AnsaOSPFArea.h
Go to the documentation of this file.
00001 #ifndef __INET_OSPFAREA_H
00002 #define __INET_OSPFAREA_H
00003 
00004 #include <vector>
00005 #include <map>
00006 #include "AnsaOSPFcommon.h"
00007 #include "AnsaOSPFInterface.h"
00008 #include "AnsaLSA.h"
00009 #include "AnsaOSPFRoutingTableEntry.h"
00010 
00011 namespace AnsaOSPF {
00012 
00013 class Router;
00014 
00015 class Area : public cPolymorphic {
00016 private:
00017     AreaID                                                  areaID;
00018     std::map<IPv4AddressRange, bool, IPv4AddressRange_Less> advertiseAddressRanges;
00019     std::vector<IPv4AddressRange>                           areaAddressRanges;
00020     std::vector<Interface*>                                 associatedInterfaces;
00021     std::vector<HostRouteParameters>                        hostRoutes;
00022     std::map<LinkStateID, RouterLSA*>                       routerLSAsByID;
00023     std::vector<RouterLSA*>                                 routerLSAs;
00024     std::map<LinkStateID, NetworkLSA*>                      networkLSAsByID;
00025     std::vector<NetworkLSA*>                                networkLSAs;
00026     std::map<LSAKeyType, SummaryLSA*, LSAKeyType_Less>      summaryLSAsByID;
00027     std::vector<SummaryLSA*>                                summaryLSAs;
00028     bool                                                    transitCapability;
00029     bool                                                    externalRoutingCapability;
00030     Metric                                                  stubDefaultCost;
00031     RouterLSA*                                              spfTreeRoot;
00032 
00033     Router*                                                 parentRouter;
00034 public:
00035             Area(AreaID id = BackboneAreaID);
00036     virtual ~Area(void);
00037 
00038     void                SetAreaID                       (AreaID areaId)                                 { areaID = areaId; }
00039     AreaID              GetAreaID                       (void) const                                    { return areaID; }
00040     void                AddAddressRange                 (IPv4AddressRange addressRange, bool advertise) { areaAddressRanges.push_back(addressRange); advertiseAddressRanges[addressRange] = advertise; }
00041     unsigned int        GetAddressRangeCount            (void) const                                    { return areaAddressRanges.size(); }
00042     IPv4AddressRange    GetAddressRange                 (unsigned int index) const                      { return areaAddressRanges[index]; }
00043     void                AddHostRoute                    (HostRouteParameters& hostRouteParameters)      { hostRoutes.push_back(hostRouteParameters); }
00044     void                SetTransitCapability            (bool transit)                                  { transitCapability = transit; }
00045     bool                GetTransitCapability            (void) const                                    { return transitCapability; }
00046     void                SetExternalRoutingCapability    (bool flooded)                                  { externalRoutingCapability = flooded; }
00047     bool                GetExternalRoutingCapability    (void) const                                    { return externalRoutingCapability; }
00048     void                SetStubDefaultCost              (Metric cost)                                   { stubDefaultCost = cost; }
00049     Metric              GetStubDefaultCost              (void) const                                    { return stubDefaultCost; }
00050     void                SetSPFTreeRoot                  (RouterLSA* root)                               { spfTreeRoot = root; }
00051     RouterLSA*          GetSPFTreeRoot                  (void)                                          { return spfTreeRoot; }
00052     const RouterLSA*    GetSPFTreeRoot                  (void) const                                    { return spfTreeRoot; }
00053 
00054     void                SetRouter                       (Router* router)                                { parentRouter = router; }
00055     Router*             GetRouter                       (void)                                          { return parentRouter; }
00056     const Router*       GetRouter                       (void) const                                    { return parentRouter; }
00057 
00058     unsigned long       GetRouterLSACount               (void) const                                    { return routerLSAs.size(); }
00059     RouterLSA*          GetRouterLSA                    (unsigned long i)                               { return routerLSAs[i]; }
00060     const RouterLSA*    GetRouterLSA                    (unsigned long i) const                         { return routerLSAs[i]; }
00061     unsigned long       GetNetworkLSACount              (void) const                                    { return networkLSAs.size(); }
00062     NetworkLSA*         GetNetworkLSA                   (unsigned long i)                               { return networkLSAs[i]; }
00063     const NetworkLSA*   GetNetworkLSA                   (unsigned long i) const                         { return networkLSAs[i]; }
00064     unsigned long       GetSummaryLSACount              (void) const                                    { return summaryLSAs.size(); }
00065     SummaryLSA*         GetSummaryLSA                   (unsigned long i)                               { return summaryLSAs[i]; }
00066     const SummaryLSA*   GetSummaryLSA                   (unsigned long i) const                         { return summaryLSAs[i]; }
00067 
00068     bool                ContainsAddress                     (IPv4Address address) const;
00069     bool                HasAddressRange                     (IPv4AddressRange addressRange) const;
00070     IPv4AddressRange    GetContainingAddressRange           (IPv4AddressRange addressRange, bool* advertise = NULL) const;
00071     void                AddInterface                        (Interface* intf);
00072     Interface*          GetInterface                        (unsigned char ifIndex);
00073     Interface*          GetInterface                        (IPv4Address address);
00074     bool                HasVirtualLink                      (AreaID withTransitArea) const;
00075     Interface*          FindVirtualLink                     (RouterID routerID);
00076 
00077     bool                InstallRouterLSA                    (OSPFRouterLSA* lsa);
00078     bool                InstallNetworkLSA                   (OSPFNetworkLSA* lsa);
00079     bool                InstallSummaryLSA                   (OSPFSummaryLSA* lsa);
00080     RouterLSA*          FindRouterLSA                       (LinkStateID linkStateID);
00081     const RouterLSA*    FindRouterLSA                       (LinkStateID linkStateID) const;
00082     NetworkLSA*         FindNetworkLSA                      (LinkStateID linkStateID);
00083     const NetworkLSA*   FindNetworkLSA                      (LinkStateID linkStateID) const;
00084     SummaryLSA*         FindSummaryLSA                      (LSAKeyType lsaKey);
00085     const SummaryLSA*   FindSummaryLSA                      (LSAKeyType lsaKey) const;
00086     void                AgeDatabase                         (void);
00087     void                RemoveParentFromRoutingInfo     (OSPFLSA* parent);   // fixing crash after broadcast interface goes down
00088     bool                HasAnyNeighborInStates              (int states) const;
00089     void                RemoveFromAllRetransmissionLists    (LSAKeyType lsaKey);
00090     bool                IsOnAnyRetransmissionList           (LSAKeyType lsaKey) const;
00091     bool                FloodLSA                            (OSPFLSA* lsa, Interface* intf = NULL, Neighbor* neighbor = NULL);
00092     bool                IsLocalAddress                      (IPv4Address address) const;
00093     RouterLSA*          OriginateRouterLSA                  (void);
00094     NetworkLSA*         OriginateNetworkLSA                 (const Interface* intf);
00095     SummaryLSA*         OriginateSummaryLSA                 (const RoutingTableEntry* entry,
00096                                                              const std::map<LSAKeyType, bool, LSAKeyType_Less>& originatedLSAs,
00097                                                              SummaryLSA*& lsaToReoriginate);
00098     void                CalculateShortestPathTree           (std::vector<RoutingTableEntry*>& newRoutingTable);
00099     void                CalculateInterAreaRoutes            (std::vector<RoutingTableEntry*>& newRoutingTable);
00100     void                ReCheckSummaryLSAs                  (std::vector<RoutingTableEntry*>& newRoutingTable);
00101 
00102     void        info(char* buffer);
00103     std::string detailedInfo(void) const;
00104 
00105 private:
00106     SummaryLSA*             OriginateSummaryLSA                     (const AnsaOSPF::SummaryLSA* summaryLSA);
00107     bool                    HasLink                                 (OSPFLSA* fromLSA, OSPFLSA* toLSA) const;
00108     std::vector<NextHop>*   CalculateNextHops                       (OSPFLSA* destination, OSPFLSA* parent) const;
00109     std::vector<NextHop>*   CalculateNextHops                       (Link& destination, OSPFLSA* parent) const;
00110 
00111     LinkStateID             GetUniqueLinkStateID                    (IPv4AddressRange destination,
00112                                                                      Metric destinationCost,
00113                                                                      SummaryLSA*& lsaToReoriginate) const;
00114 
00115     bool                    FindSameOrWorseCostRoute                (const std::vector<AnsaOSPF::RoutingTableEntry*>& newRoutingTable,
00116                                                                      const AnsaOSPF::SummaryLSA&                      currentLSA,
00117                                                                      unsigned short                               currentCost,
00118                                                                      bool&                                        destinationInRoutingTable,
00119                                                                      std::list<AnsaOSPF::RoutingTableEntry*>&         sameOrWorseCost) const;
00120 
00121     RoutingTableEntry*      CreateRoutingTableEntryFromSummaryLSA   (const AnsaOSPF::SummaryLSA&        summaryLSA,
00122                                                                      unsigned short                 entryCost,
00123                                                                      const AnsaOSPF::RoutingTableEntry& borderRouterEntry) const;
00124 };
00125 
00126 } // namespace AnsaOSPF
00127 
00128 inline std::ostream& operator<< (std::ostream& ostr, AnsaOSPF::Area& area)
00129 {
00130     ostr << area.detailedInfo();
00131     return ostr;
00132 }
00133 
00134 #endif // __INET_OSPFAREA_H
00135