OSPF::Area Class Reference

#include <OSPFArea.h>

List of all members.

Public Member Functions

 Area (AreaID id=BackboneAreaID)
virtual ~Area (void)
void SetAreaID (AreaID areaId)
AreaID GetAreaID (void) const
void AddAddressRange (IPv4AddressRange addressRange, bool advertise)
unsigned int GetAddressRangeCount (void) const
IPv4AddressRange GetAddressRange (unsigned int index) const
void AddHostRoute (HostRouteParameters &hostRouteParameters)
void SetTransitCapability (bool transit)
bool GetTransitCapability (void) const
void SetExternalRoutingCapability (bool flooded)
bool GetExternalRoutingCapability (void) const
void SetStubDefaultCost (Metric cost)
Metric GetStubDefaultCost (void) const
void SetSPFTreeRoot (RouterLSA *root)
RouterLSAGetSPFTreeRoot (void)
const RouterLSAGetSPFTreeRoot (void) const
void SetRouter (Router *router)
RouterGetRouter (void)
const RouterGetRouter (void) const
unsigned long GetRouterLSACount (void) const
RouterLSAGetRouterLSA (unsigned long i)
const RouterLSAGetRouterLSA (unsigned long i) const
unsigned long GetNetworkLSACount (void) const
NetworkLSAGetNetworkLSA (unsigned long i)
const NetworkLSAGetNetworkLSA (unsigned long i) const
unsigned long GetSummaryLSACount (void) const
SummaryLSAGetSummaryLSA (unsigned long i)
const SummaryLSAGetSummaryLSA (unsigned long i) const
bool ContainsAddress (IPv4Address address) const
bool HasAddressRange (IPv4AddressRange addressRange) const
IPv4AddressRange GetContainingAddressRange (IPv4AddressRange addressRange, bool *advertise=NULL) const
void AddInterface (Interface *intf)
InterfaceGetInterface (unsigned char ifIndex)
InterfaceGetInterface (IPv4Address address)
bool HasVirtualLink (AreaID withTransitArea) const
InterfaceFindVirtualLink (RouterID routerID)
bool InstallRouterLSA (OSPFRouterLSA *lsa)
bool InstallNetworkLSA (OSPFNetworkLSA *lsa)
bool InstallSummaryLSA (OSPFSummaryLSA *lsa)
RouterLSAFindRouterLSA (LinkStateID linkStateID)
const RouterLSAFindRouterLSA (LinkStateID linkStateID) const
NetworkLSAFindNetworkLSA (LinkStateID linkStateID)
const NetworkLSAFindNetworkLSA (LinkStateID linkStateID) const
SummaryLSAFindSummaryLSA (LSAKeyType lsaKey)
const SummaryLSAFindSummaryLSA (LSAKeyType lsaKey) const
void AgeDatabase (void)
bool AnyNeighborInStates (int states) const
void RemoveFromAllRetransmissionLists (LSAKeyType lsaKey)
bool IsOnAnyRetransmissionList (LSAKeyType lsaKey) const
bool FloodLSA (OSPFLSA *lsa, Interface *intf=NULL, Neighbor *neighbor=NULL)
bool IsLocalAddress (IPv4Address address) const
RouterLSAOriginateRouterLSA (void)
NetworkLSAOriginateNetworkLSA (const Interface *intf)
SummaryLSAOriginateSummaryLSA (const RoutingTableEntry *entry, const std::map< LSAKeyType, bool, LSAKeyType_Less > &originatedLSAs, SummaryLSA *&lsaToReoriginate)
void CalculateShortestPathTree (std::vector< RoutingTableEntry * > &newRoutingTable)
void CalculateInterAreaRoutes (std::vector< RoutingTableEntry * > &newRoutingTable)
void ReCheckSummaryLSAs (std::vector< RoutingTableEntry * > &newRoutingTable)
void info (char *buffer)
std::string detailedInfo (void) const

Private Member Functions

SummaryLSAOriginateSummaryLSA (const OSPF::SummaryLSA *summaryLSA)
bool HasLink (OSPFLSA *fromLSA, OSPFLSA *toLSA) const
std::vector< NextHop > * CalculateNextHops (OSPFLSA *destination, OSPFLSA *parent) const
std::vector< NextHop > * CalculateNextHops (Link &destination, OSPFLSA *parent) const
LinkStateID GetUniqueLinkStateID (IPv4AddressRange destination, Metric destinationCost, SummaryLSA *&lsaToReoriginate) const
bool FindSameOrWorseCostRoute (const std::vector< OSPF::RoutingTableEntry * > &newRoutingTable, const OSPF::SummaryLSA &currentLSA, unsigned short currentCost, bool &destinationInRoutingTable, std::list< OSPF::RoutingTableEntry * > &sameOrWorseCost) const
RoutingTableEntryCreateRoutingTableEntryFromSummaryLSA (const OSPF::SummaryLSA &summaryLSA, unsigned short entryCost, const OSPF::RoutingTableEntry &borderRouterEntry) const

Private Attributes

AreaID areaID
std::map< IPv4AddressRange,
bool, IPv4AddressRange_Less
advertiseAddressRanges
std::vector< IPv4AddressRangeareaAddressRanges
std::vector< Interface * > associatedInterfaces
std::vector< HostRouteParametershostRoutes
std::map< LinkStateID, RouterLSA * > routerLSAsByID
std::vector< RouterLSA * > routerLSAs
std::map< LinkStateID, NetworkLSA * > networkLSAsByID
std::vector< NetworkLSA * > networkLSAs
std::map< LSAKeyType, SummaryLSA *,
LSAKeyType_Less
summaryLSAsByID
std::vector< SummaryLSA * > summaryLSAs
bool transitCapability
bool externalRoutingCapability
Metric stubDefaultCost
RouterLSAspfTreeRoot
RouterparentRouter


Constructor & Destructor Documentation

OSPF::Area::Area ( AreaID  id = BackboneAreaID  ) 

00008                              :
00009     areaID (id),
00010     transitCapability (false),
00011     externalRoutingCapability (true),
00012     stubDefaultCost (1),
00013     spfTreeRoot (NULL),
00014     parentRouter (NULL)
00015 {
00016 }

OSPF::Area::~Area ( void   )  [virtual]

00019 {
00020     int interfaceNum = associatedInterfaces.size ();
00021     for (int i = 0; i < interfaceNum; i++) {
00022         delete (associatedInterfaces[i]);
00023     }
00024     long lsaCount = routerLSAs.size ();
00025     for (long j = 0; j < lsaCount; j++) {
00026         delete routerLSAs[j];
00027     }
00028     routerLSAs.clear ();
00029     lsaCount = networkLSAs.size ();
00030     for (long k = 0; k < lsaCount; k++) {
00031         delete networkLSAs[k];
00032     }
00033     networkLSAs.clear ();
00034     lsaCount = summaryLSAs.size ();
00035     for (long m = 0; m < lsaCount; m++) {
00036         delete summaryLSAs[m];
00037     }
00038     summaryLSAs.clear ();
00039 }


Member Function Documentation

void OSPF::Area::AddAddressRange ( IPv4AddressRange  addressRange,
bool  advertise 
) [inline]

00040 { areaAddressRanges.push_back (addressRange); advertiseAddressRanges[addressRange] = advertise; }

void OSPF::Area::AddHostRoute ( HostRouteParameters hostRouteParameters  )  [inline]

00043 { hostRoutes.push_back (hostRouteParameters); }

void OSPF::Area::AddInterface ( Interface intf  ) 

00042 {
00043     intf->SetArea (this);
00044     associatedInterfaces.push_back (intf);
00045 }

void OSPF::Area::AgeDatabase ( void   ) 

00328 {
00329     long            lsaCount            = routerLSAs.size ();
00330     bool            rebuildRoutingTable = false;
00331     long            i;
00332 
00333     for (i = 0; i < lsaCount; i++) {
00334         unsigned short   lsAge          = routerLSAs[i]->getHeader ().getLsAge ();
00335         bool             selfOriginated = (routerLSAs[i]->getHeader ().getAdvertisingRouter ().getInt () == parentRouter->GetRouterID ());
00336         bool             unreachable    = parentRouter->DestinationIsUnreachable (routerLSAs[i]);
00337         OSPF::RouterLSA* lsa            = routerLSAs[i];
00338 
00339         if ((selfOriginated && (lsAge < (LS_REFRESH_TIME - 1))) || (!selfOriginated && (lsAge < (MAX_AGE - 1)))) {
00340             lsa->getHeader ().setLsAge (lsAge + 1);
00341             if ((lsAge + 1) % CHECK_AGE == 0) {
00342                 if (!lsa->ValidateLSChecksum ()) {
00343                     EV << "Invalid LS checksum. Memory error detected!\n";
00344                 }
00345             }
00346             lsa->IncrementInstallTime ();
00347         }
00348         if (selfOriginated && (lsAge == (LS_REFRESH_TIME - 1))) {
00349             if (unreachable) {
00350                 lsa->getHeader ().setLsAge (MAX_AGE);
00351                 FloodLSA (lsa);
00352                 lsa->IncrementInstallTime ();
00353             } else {
00354                 long sequenceNumber = lsa->getHeader ().getLsSequenceNumber ();
00355                 if (sequenceNumber == MAX_SEQUENCE_NUMBER) {
00356                     lsa->getHeader ().setLsAge (MAX_AGE);
00357                     FloodLSA (lsa);
00358                     lsa->IncrementInstallTime ();
00359                 } else {
00360                     OSPF::RouterLSA* newLSA = OriginateRouterLSA ();
00361 
00362                     newLSA->getHeader ().setLsSequenceNumber (sequenceNumber + 1);
00363                     newLSA->getHeader ().setLsChecksum (0);    // TODO: calculate correct LS checksum
00364                     rebuildRoutingTable |= lsa->Update (newLSA);
00365                     delete newLSA;
00366 
00367                     FloodLSA (lsa);
00368                 }
00369             }
00370         }
00371         if (!selfOriginated && (lsAge == MAX_AGE - 1)) {
00372             lsa->getHeader ().setLsAge (MAX_AGE);
00373             FloodLSA (lsa);
00374             lsa->IncrementInstallTime ();
00375         }
00376         if (lsAge == MAX_AGE) {
00377             OSPF::LSAKeyType lsaKey;
00378 
00379             lsaKey.linkStateID = lsa->getHeader ().getLinkStateID ();
00380             lsaKey.advertisingRouter = lsa->getHeader ().getAdvertisingRouter ().getInt ();
00381 
00382             if (!IsOnAnyRetransmissionList (lsaKey) &&
00383                 !AnyNeighborInStates (OSPF::Neighbor::ExchangeState | OSPF::Neighbor::LoadingState))
00384             {
00385                 if (!selfOriginated || unreachable) {
00386                     routerLSAsByID.erase (lsa->getHeader ().getLinkStateID ());
00387                     delete lsa;
00388                     routerLSAs[i] = NULL;
00389                     rebuildRoutingTable = true;
00390                 } else {
00391                     OSPF::RouterLSA* newLSA              = OriginateRouterLSA ();
00392                     long             sequenceNumber      = lsa->getHeader ().getLsSequenceNumber ();
00393 
00394                     newLSA->getHeader ().setLsSequenceNumber ((sequenceNumber == MAX_SEQUENCE_NUMBER) ? INITIAL_SEQUENCE_NUMBER : sequenceNumber + 1);
00395                     newLSA->getHeader ().setLsChecksum (0);    // TODO: calculate correct LS checksum
00396                     rebuildRoutingTable |= lsa->Update (newLSA);
00397                     delete newLSA;
00398 
00399                     FloodLSA (lsa);
00400                 }
00401             }
00402         }
00403     }
00404 
00405     std::vector<RouterLSA*>::iterator routerIt = routerLSAs.begin ();
00406     while (routerIt != routerLSAs.end ()) {
00407         if ((*routerIt) == NULL) {
00408             routerIt = routerLSAs.erase (routerIt);
00409         } else {
00410             routerIt++;
00411         }
00412     }
00413 
00414     lsaCount = networkLSAs.size ();
00415     for (i = 0; i < lsaCount; i++) {
00416         unsigned short    lsAge          = networkLSAs[i]->getHeader ().getLsAge ();
00417         bool              unreachable    = parentRouter->DestinationIsUnreachable (networkLSAs[i]);
00418         OSPF::NetworkLSA* lsa            = networkLSAs[i];
00419         OSPF::Interface*  localIntf      = GetInterface (IPv4AddressFromULong (lsa->getHeader ().getLinkStateID ()));
00420         bool              selfOriginated = false;
00421 
00422         if ((localIntf != NULL) &&
00423             (localIntf->GetState () == OSPF::Interface::DesignatedRouterState) &&
00424             (localIntf->GetNeighborCount () > 0) &&
00425             (localIntf->AnyNeighborInStates (OSPF::Neighbor::FullState)))
00426         {
00427             selfOriginated = true;
00428         }
00429 
00430         if ((selfOriginated && (lsAge < (LS_REFRESH_TIME - 1))) || (!selfOriginated && (lsAge < (MAX_AGE - 1)))) {
00431             lsa->getHeader ().setLsAge (lsAge + 1);
00432             if ((lsAge + 1) % CHECK_AGE == 0) {
00433                 if (!lsa->ValidateLSChecksum ()) {
00434                     EV << "Invalid LS checksum. Memory error detected!\n";
00435                 }
00436             }
00437             lsa->IncrementInstallTime ();
00438         }
00439         if (selfOriginated && (lsAge == (LS_REFRESH_TIME - 1))) {
00440             if (unreachable) {
00441                 lsa->getHeader ().setLsAge (MAX_AGE);
00442                 FloodLSA (lsa);
00443                 lsa->IncrementInstallTime ();
00444             } else {
00445                 long sequenceNumber = lsa->getHeader ().getLsSequenceNumber ();
00446                 if (sequenceNumber == MAX_SEQUENCE_NUMBER) {
00447                     lsa->getHeader ().setLsAge (MAX_AGE);
00448                     FloodLSA (lsa);
00449                     lsa->IncrementInstallTime ();
00450                 } else {
00451                     OSPF::NetworkLSA* newLSA = OriginateNetworkLSA (localIntf);
00452 
00453                     if (newLSA != NULL) {
00454                         newLSA->getHeader ().setLsSequenceNumber (sequenceNumber + 1);
00455                         newLSA->getHeader ().setLsChecksum (0);    // TODO: calculate correct LS checksum
00456                         rebuildRoutingTable |= lsa->Update (newLSA);
00457                         delete newLSA;
00458                     } else {    // no neighbors on the network -> old NetworkLSA must be flushed
00459                         lsa->getHeader ().setLsAge (MAX_AGE);
00460                         lsa->IncrementInstallTime ();
00461                     }
00462 
00463                     FloodLSA (lsa);
00464                 }
00465             }
00466         }
00467         if (!selfOriginated && (lsAge == MAX_AGE - 1)) {
00468             lsa->getHeader ().setLsAge (MAX_AGE);
00469             FloodLSA (lsa);
00470             lsa->IncrementInstallTime ();
00471         }
00472         if (lsAge == MAX_AGE) {
00473             OSPF::LSAKeyType lsaKey;
00474 
00475             lsaKey.linkStateID = lsa->getHeader ().getLinkStateID ();
00476             lsaKey.advertisingRouter = lsa->getHeader ().getAdvertisingRouter ().getInt ();
00477 
00478             if (!IsOnAnyRetransmissionList (lsaKey) &&
00479                 !AnyNeighborInStates (OSPF::Neighbor::ExchangeState | OSPF::Neighbor::LoadingState))
00480             {
00481                 if (!selfOriginated || unreachable) {
00482                     networkLSAsByID.erase (lsa->getHeader ().getLinkStateID ());
00483                     delete lsa;
00484                     networkLSAs[i] = NULL;
00485                     rebuildRoutingTable = true;
00486                 } else {
00487                     OSPF::NetworkLSA* newLSA              = OriginateNetworkLSA (localIntf);
00488                     long              sequenceNumber      = lsa->getHeader ().getLsSequenceNumber ();
00489 
00490                     if (newLSA != NULL) {
00491                         newLSA->getHeader ().setLsSequenceNumber ((sequenceNumber == MAX_SEQUENCE_NUMBER) ? INITIAL_SEQUENCE_NUMBER : sequenceNumber + 1);
00492                         newLSA->getHeader ().setLsChecksum (0);    // TODO: calculate correct LS checksum
00493                         rebuildRoutingTable |= lsa->Update (newLSA);
00494                         delete newLSA;
00495 
00496                         FloodLSA (lsa);
00497                     } else {    // no neighbors on the network -> old NetworkLSA must be deleted
00498                         delete networkLSAs[i];
00499                     }
00500                 }
00501             }
00502         }
00503     }
00504 
00505     std::vector<NetworkLSA*>::iterator networkIt = networkLSAs.begin ();
00506     while (networkIt != networkLSAs.end ()) {
00507         if ((*networkIt) == NULL) {
00508             networkIt = networkLSAs.erase (networkIt);
00509         } else {
00510             networkIt++;
00511         }
00512     }
00513 
00514     lsaCount = summaryLSAs.size ();
00515     for (i = 0; i < lsaCount; i++) {
00516         unsigned short    lsAge          = summaryLSAs[i]->getHeader ().getLsAge ();
00517         bool              selfOriginated = (summaryLSAs[i]->getHeader ().getAdvertisingRouter ().getInt () == parentRouter->GetRouterID ());
00518         bool              unreachable    = parentRouter->DestinationIsUnreachable (summaryLSAs[i]);
00519         OSPF::SummaryLSA* lsa            = summaryLSAs[i];
00520 
00521         if ((selfOriginated && (lsAge < (LS_REFRESH_TIME - 1))) || (!selfOriginated && (lsAge < (MAX_AGE - 1)))) {
00522             lsa->getHeader ().setLsAge (lsAge + 1);
00523             if ((lsAge + 1) % CHECK_AGE == 0) {
00524                 if (!lsa->ValidateLSChecksum ()) {
00525                     EV << "Invalid LS checksum. Memory error detected!\n";
00526                 }
00527             }
00528             lsa->IncrementInstallTime ();
00529         }
00530         if (selfOriginated && (lsAge == (LS_REFRESH_TIME - 1))) {
00531             if (unreachable) {
00532                 lsa->getHeader ().setLsAge (MAX_AGE);
00533                 FloodLSA (lsa);
00534                 lsa->IncrementInstallTime ();
00535             } else {
00536                 long sequenceNumber = lsa->getHeader ().getLsSequenceNumber ();
00537                 if (sequenceNumber == MAX_SEQUENCE_NUMBER) {
00538                     lsa->getHeader ().setLsAge (MAX_AGE);
00539                     FloodLSA (lsa);
00540                     lsa->IncrementInstallTime ();
00541                 } else {
00542                     OSPF::SummaryLSA* newLSA = OriginateSummaryLSA (lsa);
00543 
00544                     if (newLSA != NULL) {
00545                         newLSA->getHeader ().setLsSequenceNumber (sequenceNumber + 1);
00546                         newLSA->getHeader ().setLsChecksum (0);    // TODO: calculate correct LS checksum
00547                         rebuildRoutingTable |= lsa->Update (newLSA);
00548                         delete newLSA;
00549 
00550                         FloodLSA (lsa);
00551                     } else {
00552                         lsa->getHeader ().setLsAge (MAX_AGE);
00553                         FloodLSA (lsa);
00554                         lsa->IncrementInstallTime ();
00555                     }
00556                 }
00557             }
00558         }
00559         if (!selfOriginated && (lsAge == MAX_AGE - 1)) {
00560             lsa->getHeader ().setLsAge (MAX_AGE);
00561             FloodLSA (lsa);
00562             lsa->IncrementInstallTime ();
00563         }
00564         if (lsAge == MAX_AGE) {
00565             OSPF::LSAKeyType lsaKey;
00566 
00567             lsaKey.linkStateID = lsa->getHeader ().getLinkStateID ();
00568             lsaKey.advertisingRouter = lsa->getHeader ().getAdvertisingRouter ().getInt ();
00569 
00570             if (!IsOnAnyRetransmissionList (lsaKey) &&
00571                 !AnyNeighborInStates (OSPF::Neighbor::ExchangeState | OSPF::Neighbor::LoadingState))
00572             {
00573                 if (!selfOriginated || unreachable) {
00574                     summaryLSAsByID.erase (lsaKey);
00575                     delete lsa;
00576                     summaryLSAs[i] = NULL;
00577                     rebuildRoutingTable = true;
00578                 } else {
00579                     OSPF::SummaryLSA* newLSA = OriginateSummaryLSA (lsa);
00580                     if (newLSA != NULL) {
00581                         long sequenceNumber = lsa->getHeader ().getLsSequenceNumber ();
00582 
00583                         newLSA->getHeader ().setLsSequenceNumber ((sequenceNumber == MAX_SEQUENCE_NUMBER) ? INITIAL_SEQUENCE_NUMBER : sequenceNumber + 1);
00584                         newLSA->getHeader ().setLsChecksum (0);    // TODO: calculate correct LS checksum
00585                         rebuildRoutingTable |= lsa->Update (newLSA);
00586                         delete newLSA;
00587 
00588                         FloodLSA (lsa);
00589                     } else {
00590                         summaryLSAsByID.erase (lsaKey);
00591                         delete lsa;
00592                         summaryLSAs[i] = NULL;
00593                         rebuildRoutingTable = true;
00594                     }
00595                 }
00596             }
00597         }
00598     }
00599 
00600     std::vector<SummaryLSA*>::iterator summaryIt = summaryLSAs.begin ();
00601     while (summaryIt != summaryLSAs.end ()) {
00602         if ((*summaryIt) == NULL) {
00603             summaryIt = summaryLSAs.erase (summaryIt);
00604         } else {
00605             summaryIt++;
00606         }
00607     }
00608 
00609     long interfaceCount = associatedInterfaces.size ();
00610     for (long m = 0; m < interfaceCount; m++) {
00611         associatedInterfaces[m]->AgeTransmittedLSALists ();
00612     }
00613 
00614     if (rebuildRoutingTable) {
00615         parentRouter->RebuildRoutingTable ();
00616     }
00617 }

bool OSPF::Area::AnyNeighborInStates ( int  states  )  const

00620 {
00621     long interfaceCount = associatedInterfaces.size ();
00622     for (long i = 0; i < interfaceCount; i++) {
00623         if (associatedInterfaces[i]->AnyNeighborInStates (states)) {
00624             return true;
00625         }
00626     }
00627     return false;
00628 }

void OSPF::Area::CalculateInterAreaRoutes ( std::vector< RoutingTableEntry * > &  newRoutingTable  ) 

std::vector< OSPF::NextHop > * OSPF::Area::CalculateNextHops ( Link destination,
OSPFLSA parent 
) const [private]

01926 {
01927     std::vector<OSPF::NextHop>* hops = new std::vector<OSPF::NextHop>;
01928     unsigned long                i;
01929 
01930     OSPF::RouterLSA* routerLSA = check_and_cast<OSPF::RouterLSA*> (parent);
01931     if (routerLSA != spfTreeRoot) {
01932         unsigned int nextHopCount = routerLSA->GetNextHopCount ();
01933         for (i = 0; i < nextHopCount; i++) {
01934             hops->push_back (routerLSA->GetNextHop (i));
01935         }
01936         return hops;
01937     } else {
01938         unsigned long interfaceNum = associatedInterfaces.size ();
01939         for (i = 0; i < interfaceNum; i++) {
01940             OSPF::Interface::OSPFInterfaceType intfType = associatedInterfaces[i]->GetType ();
01941 
01942             if ((intfType == OSPF::Interface::PointToPoint) ||
01943                 ((intfType == OSPF::Interface::Virtual) &&
01944                  (associatedInterfaces[i]->GetState () > OSPF::Interface::LoopbackState)))
01945             {
01946                 OSPF::Neighbor* neighbor = (associatedInterfaces[i]->GetNeighborCount () > 0) ? associatedInterfaces[i]->GetNeighbor (0) : NULL;
01947                 if (neighbor != NULL) {
01948                     OSPF::IPv4Address neighborAddress = neighbor->GetAddress ();
01949                     if (((neighborAddress != OSPF::NullIPv4Address) &&
01950                          (ULongFromIPv4Address (neighborAddress) == destination.getLinkID ().getInt ())) ||
01951                         ((neighborAddress == OSPF::NullIPv4Address) &&
01952                          (ULongFromIPv4Address (associatedInterfaces[i]->GetAddressRange ().address) == destination.getLinkID ().getInt ()) &&
01953                          (ULongFromIPv4Address (associatedInterfaces[i]->GetAddressRange ().mask) == destination.getLinkData ())))
01954                     {
01955                         NextHop nextHop;
01956                         nextHop.ifIndex           = associatedInterfaces[i]->GetIfIndex ();
01957                         nextHop.hopAddress        = neighborAddress;
01958                         nextHop.advertisingRouter = parentRouter->GetRouterID ();
01959                         hops->push_back (nextHop);
01960                         break;
01961                     }
01962                 }
01963             }
01964             if ((intfType == OSPF::Interface::Broadcast) ||
01965                 (intfType == OSPF::Interface::NBMA))
01966             {
01967                 if ((destination.getLinkID ().getInt () == ULongFromIPv4Address (associatedInterfaces[i]->GetAddressRange ().address & associatedInterfaces[i]->GetAddressRange ().mask)) &&
01968                     (destination.getLinkData () == ULongFromIPv4Address (associatedInterfaces[i]->GetAddressRange ().mask)))
01969                 {
01970                     NextHop nextHop;
01971                     nextHop.ifIndex           = associatedInterfaces[i]->GetIfIndex ();
01972                     nextHop.hopAddress        = IPv4AddressFromULong (destination.getLinkID ().getInt ());
01973                     nextHop.advertisingRouter = parentRouter->GetRouterID ();
01974                     hops->push_back (nextHop);
01975                     break;
01976                 }
01977             }
01978             if (intfType == OSPF::Interface::PointToMultiPoint) {
01979                 if (destination.getType () == StubLink) {
01980                     if (destination.getLinkID ().getInt () == ULongFromIPv4Address (associatedInterfaces[i]->GetAddressRange ().address)) {
01981                         // The link contains the router's own interface address and a full mask,
01982                         // so we insert a next hop pointing to the interface itself. Kind of pointless, but
01983                         // not much else we could do...
01984                         // TODO: check what other OSPF implementations do in this situation
01985                         NextHop nextHop;
01986                         nextHop.ifIndex           = associatedInterfaces[i]->GetIfIndex ();
01987                         nextHop.hopAddress        = associatedInterfaces[i]->GetAddressRange ().address;
01988                         nextHop.advertisingRouter = parentRouter->GetRouterID ();
01989                         hops->push_back (nextHop);
01990                         break;
01991                     }
01992                 }
01993                 if (destination.getType () == PointToPointLink) {
01994                     OSPF::Neighbor* neighbor = associatedInterfaces[i]->GetNeighborByID (destination.getLinkID ().getInt ());
01995                     if (neighbor != NULL) {
01996                         NextHop nextHop;
01997                         nextHop.ifIndex           = associatedInterfaces[i]->GetIfIndex ();
01998                         nextHop.hopAddress        = neighbor->GetAddress ();
01999                         nextHop.advertisingRouter = parentRouter->GetRouterID ();
02000                         hops->push_back (nextHop);
02001                         break;
02002                     }
02003                 }
02004             }
02005             // next hops for virtual links are generated later, after examining transit areas' SummaryLSAs
02006         }
02007 
02008         if (hops->size () == 0) {
02009             unsigned long hostRouteCount = hostRoutes.size ();
02010             for (i = 0; i < hostRouteCount; i++) {
02011                 if ((destination.getLinkID ().getInt () == ULongFromIPv4Address (hostRoutes[i].address)) &&
02012                     (destination.getLinkData () == 0xFFFFFFFF))
02013                 {
02014                     NextHop nextHop;
02015                     nextHop.ifIndex           = hostRoutes[i].ifIndex;
02016                     nextHop.hopAddress        = hostRoutes[i].address;
02017                     nextHop.advertisingRouter = parentRouter->GetRouterID ();
02018                     hops->push_back (nextHop);
02019                     break;
02020                 }
02021             }
02022         }
02023     }
02024 
02025     return hops;
02026 }

std::vector< OSPF::NextHop > * OSPF::Area::CalculateNextHops ( OSPFLSA destination,
OSPFLSA parent 
) const [private]

01798 {
01799     std::vector<OSPF::NextHop>* hops = new std::vector<OSPF::NextHop>;
01800     unsigned long               i, j;
01801 
01802     OSPF::RouterLSA* routerLSA = dynamic_cast<OSPF::RouterLSA*> (parent);
01803     if (routerLSA != NULL) {
01804         if (routerLSA != spfTreeRoot) {
01805             unsigned int nextHopCount = routerLSA->GetNextHopCount ();
01806             for (i = 0; i < nextHopCount; i++) {
01807                 hops->push_back (routerLSA->GetNextHop (i));
01808             }
01809             return hops;
01810         } else {
01811             OSPF::RouterLSA* destinationRouterLSA = dynamic_cast<OSPF::RouterLSA*> (destination);
01812             if (destinationRouterLSA != NULL) {
01813                 unsigned long interfaceNum   = associatedInterfaces.size ();
01814                 for (i = 0; i < interfaceNum; i++) {
01815                     OSPF::Interface::OSPFInterfaceType intfType = associatedInterfaces[i]->GetType ();
01816                     if ((intfType == OSPF::Interface::PointToPoint) ||
01817                         ((intfType == OSPF::Interface::Virtual) &&
01818                          (associatedInterfaces[i]->GetState () > OSPF::Interface::LoopbackState)))
01819                     {
01820                         OSPF::Neighbor* ptpNeighbor = associatedInterfaces[i]->GetNeighbor (0);
01821                         if (ptpNeighbor != NULL) {
01822                             if (ptpNeighbor->GetNeighborID () == destinationRouterLSA->getHeader ().getLinkStateID ()) {
01823                                 NextHop nextHop;
01824                                 nextHop.ifIndex           = associatedInterfaces[i]->GetIfIndex ();
01825                                 nextHop.hopAddress        = ptpNeighbor->GetAddress ();
01826                                 nextHop.advertisingRouter = destinationRouterLSA->getHeader ().getAdvertisingRouter ().getInt ();
01827                                 hops->push_back (nextHop);
01828                                 break;
01829                             }
01830                         }
01831                     }
01832                     if (intfType == OSPF::Interface::PointToMultiPoint) {
01833                         OSPF::Neighbor* ptmpNeighbor = associatedInterfaces[i]->GetNeighborByID (destinationRouterLSA->getHeader ().getLinkStateID ());
01834                         if (ptmpNeighbor != NULL) {
01835                             unsigned int   linkCount = destinationRouterLSA->getLinksArraySize ();
01836                             OSPF::RouterID rootID    = parentRouter->GetRouterID ();
01837                             for (j = 0; j < linkCount; j++) {
01838                                 Link& link = destinationRouterLSA->getLinks (j);
01839                                 if (link.getLinkID () == rootID) {
01840                                     NextHop nextHop;
01841                                     nextHop.ifIndex           = associatedInterfaces[i]->GetIfIndex ();
01842                                     nextHop.hopAddress        = IPv4AddressFromULong (link.getLinkData ());
01843                                     nextHop.advertisingRouter = destinationRouterLSA->getHeader ().getAdvertisingRouter ().getInt ();
01844                                     hops->push_back (nextHop);
01845                                 }
01846                             }
01847                             break;
01848                         }
01849                     }
01850                 }
01851             } else {
01852                 OSPF::NetworkLSA* destinationNetworkLSA = dynamic_cast<OSPF::NetworkLSA*> (destination);
01853                 if (destinationNetworkLSA != NULL) {
01854                     OSPF::IPv4Address networkDesignatedRouter = IPv4AddressFromULong (destinationNetworkLSA->getHeader ().getLinkStateID ());
01855                     unsigned long     interfaceNum            = associatedInterfaces.size ();
01856                     for (i = 0; i < interfaceNum; i++) {
01857                         OSPF::Interface::OSPFInterfaceType intfType = associatedInterfaces[i]->GetType ();
01858                         if (((intfType == OSPF::Interface::Broadcast) ||
01859                              (intfType == OSPF::Interface::NBMA)) &&
01860                             (associatedInterfaces[i]->GetDesignatedRouter ().ipInterfaceAddress == networkDesignatedRouter))
01861                         {
01862                             OSPF::IPv4AddressRange range = associatedInterfaces[i]->GetAddressRange ();
01863                             NextHop                nextHop;
01864 
01865                             nextHop.ifIndex           = associatedInterfaces[i]->GetIfIndex ();
01866                             nextHop.hopAddress        = (range.address & range.mask);
01867                             nextHop.advertisingRouter = destinationNetworkLSA->getHeader ().getAdvertisingRouter ().getInt ();
01868                             hops->push_back (nextHop);
01869                         }
01870                     }
01871                 }
01872             }
01873         }
01874     } else {
01875         OSPF::NetworkLSA* networkLSA = dynamic_cast<OSPF::NetworkLSA*> (parent);
01876         if (networkLSA != NULL) {
01877             if (networkLSA->GetParent () != spfTreeRoot) {
01878                 unsigned int nextHopCount = networkLSA->GetNextHopCount ();
01879                 for (i = 0; i < nextHopCount; i++) {
01880                     hops->push_back (networkLSA->GetNextHop (i));
01881                 }
01882                 return hops;
01883             } else {
01884                 unsigned long parentLinkStateID = parent->getHeader ().getLinkStateID ();
01885 
01886                 OSPF::RouterLSA* destinationRouterLSA = dynamic_cast<OSPF::RouterLSA*> (destination);
01887                 if (destinationRouterLSA != NULL) {
01888                     OSPF::RouterID destinationRouterID = destinationRouterLSA->getHeader ().getLinkStateID ();
01889                     unsigned int   linkCount           = destinationRouterLSA->getLinksArraySize ();
01890                     for (i = 0; i < linkCount; i++) {
01891                         Link&   link = destinationRouterLSA->getLinks (i);
01892                         NextHop nextHop;
01893 
01894                         if (((link.getType () == TransitLink) &&
01895                              (link.getLinkID ().getInt () == parentLinkStateID)) ||
01896                             ((link.getType () == StubLink) &&
01897                              ((link.getLinkID ().getInt () & link.getLinkData ()) == (parentLinkStateID & networkLSA->getNetworkMask ().getInt ()))))
01898                         {
01899                             unsigned long interfaceNum   = associatedInterfaces.size ();
01900                             for (j = 0; j < interfaceNum; j++) {
01901                                 OSPF::Interface::OSPFInterfaceType intfType = associatedInterfaces[j]->GetType ();
01902                                 if (((intfType == OSPF::Interface::Broadcast) ||
01903                                      (intfType == OSPF::Interface::NBMA)) &&
01904                                     (associatedInterfaces[j]->GetDesignatedRouter ().ipInterfaceAddress == IPv4AddressFromULong (parentLinkStateID)))
01905                                 {
01906                                     OSPF::Neighbor* nextHopNeighbor = associatedInterfaces[j]->GetNeighborByID (destinationRouterID);
01907                                     if (nextHopNeighbor != NULL) {
01908                                         nextHop.ifIndex           = associatedInterfaces[j]->GetIfIndex ();
01909                                         nextHop.hopAddress        = nextHopNeighbor->GetAddress ();
01910                                         nextHop.advertisingRouter = destinationRouterLSA->getHeader ().getAdvertisingRouter ().getInt ();
01911                                         hops->push_back (nextHop);
01912                                     }
01913                                 }
01914                             }
01915                         }
01916                     }
01917                 }
01918             }
01919         }
01920     }
01921 
01922     return hops;
01923 }

void OSPF::Area::CalculateShortestPathTree ( std::vector< RoutingTableEntry * > &  newRoutingTable  ) 

bool OSPF::Area::ContainsAddress ( IPv4Address  address  )  const

00101 {
00102     int addressRangeNum = areaAddressRanges.size ();
00103     for (int i = 0; i < addressRangeNum; i++) {
00104         if ((areaAddressRanges[i].address & areaAddressRanges[i].mask) == (address & areaAddressRanges[i].mask)) {
00105             return true;
00106         }
00107     }
00108     return false;
00109 }

OSPF::RoutingTableEntry * OSPF::Area::CreateRoutingTableEntryFromSummaryLSA ( const OSPF::SummaryLSA summaryLSA,
unsigned short  entryCost,
const OSPF::RoutingTableEntry borderRouterEntry 
) const [private]

Returns a new RoutingTableEntry based on the input SummaryLSA, with the input cost and the borderRouterEntry's next hops.

02156 {
02157     OSPF::IPv4AddressRange destination;
02158 
02159     destination.address = IPv4AddressFromULong (summaryLSA.getHeader ().getLinkStateID ());
02160     destination.mask    = IPv4AddressFromULong (summaryLSA.getNetworkMask ().getInt ());
02161 
02162     OSPF::RoutingTableEntry* newEntry = new OSPF::RoutingTableEntry;
02163 
02164     if (summaryLSA.getHeader ().getLsType () == SummaryLSA_NetworksType) {
02165         newEntry->SetDestinationID (ULongFromIPv4Address (destination.address & destination.mask));
02166         newEntry->SetAddressMask (ULongFromIPv4Address (destination.mask));
02167         newEntry->SetDestinationType (OSPF::RoutingTableEntry::NetworkDestination);
02168     } else {
02169         newEntry->SetDestinationID (ULongFromIPv4Address (destination.address));
02170         newEntry->SetAddressMask (0xFFFFFFFF);
02171         newEntry->SetDestinationType (OSPF::RoutingTableEntry::ASBoundaryRouterDestination);
02172     }
02173     newEntry->SetArea (areaID);
02174     newEntry->SetPathType (OSPF::RoutingTableEntry::InterArea);
02175     newEntry->SetCost (entryCost);
02176     newEntry->SetOptionalCapabilities (summaryLSA.getHeader ().getLsOptions ());
02177     newEntry->SetLinkStateOrigin (&summaryLSA);
02178 
02179     unsigned int nextHopCount = borderRouterEntry.GetNextHopCount ();
02180     for (unsigned int j = 0; j < nextHopCount; j++) {
02181         newEntry->AddNextHop (borderRouterEntry.GetNextHop (j));
02182     }
02183 
02184     return newEntry;
02185 }

std::string OSPF::Area::detailedInfo ( void   )  const

00056 {
00057     std::stringstream out;
00058     char addressString[16];
00059     int i;
00060     out << "\n    areaID: " << AddressStringFromULong (addressString, 16, areaID) << ", ";
00061     out << "transitCapability: " << (transitCapability ? "true" : "false") << ", ";
00062     out << "externalRoutingCapability: " << (externalRoutingCapability ? "true" : "false") << ", ";
00063     out << "stubDefaultCost: " << stubDefaultCost << "\n";
00064     int addressRangeNum = areaAddressRanges.size ();
00065     for (i = 0; i < addressRangeNum; i++) {
00066         out << "    addressRanges[" << i << "]: ";
00067         out << AddressStringFromIPv4Address (addressString, 16, areaAddressRanges[i].address);
00068         out << "/" << AddressStringFromIPv4Address (addressString, 16, areaAddressRanges[i].mask) << "\n";
00069     }
00070     int interfaceNum = associatedInterfaces.size ();
00071     for (i = 0; i < interfaceNum; i++) {
00072         out << "    interface[" << i << "]: addressRange: ";
00073         out << AddressStringFromIPv4Address (addressString, 16, associatedInterfaces[i]->GetAddressRange ().address);
00074         out << "/" << AddressStringFromIPv4Address (addressString, 16, associatedInterfaces[i]->GetAddressRange ().mask) << "\n";
00075     }
00076 
00077     out << "\n";
00078     out << "    Database:\n";
00079     out << "      RouterLSAs:\n";
00080     long lsaCount = routerLSAs.size ();
00081     for (i = 0; i < lsaCount; i++) {
00082         out << "        " << *routerLSAs[i] << "\n";
00083     }
00084     out << "      NetworkLSAs:\n";
00085     lsaCount = networkLSAs.size ();
00086     for (i = 0; i < lsaCount; i++) {
00087         out << "        " << *networkLSAs[i] << "\n";
00088     }
00089     out << "      SummaryLSAs:\n";
00090     lsaCount = summaryLSAs.size ();
00091     for (i = 0; i < lsaCount; i++) {
00092         out << "        " << *summaryLSAs[i] << "\n";
00093     }
00094 
00095     out << "--------------------------------------------------------------------------------";
00096 
00097     return out.str();
00098 }

const OSPF::NetworkLSA * OSPF::Area::FindNetworkLSA ( LinkStateID  linkStateID  )  const

00298 {
00299     std::map<OSPF::LinkStateID, OSPF::NetworkLSA*>::const_iterator lsaIt = networkLSAsByID.find (linkStateID);
00300     if (lsaIt != networkLSAsByID.end ()) {
00301         return lsaIt->second;
00302     } else {
00303         return NULL;
00304     }
00305 }

OSPF::NetworkLSA * OSPF::Area::FindNetworkLSA ( LinkStateID  linkStateID  ) 

00288 {
00289     std::map<OSPF::LinkStateID, OSPF::NetworkLSA*>::iterator lsaIt = networkLSAsByID.find (linkStateID);
00290     if (lsaIt != networkLSAsByID.end ()) {
00291         return lsaIt->second;
00292     } else {
00293         return NULL;
00294     }
00295 }

const OSPF::RouterLSA * OSPF::Area::FindRouterLSA ( LinkStateID  linkStateID  )  const

00278 {
00279     std::map<OSPF::LinkStateID, OSPF::RouterLSA*>::const_iterator lsaIt = routerLSAsByID.find (linkStateID);
00280     if (lsaIt != routerLSAsByID.end ()) {
00281         return lsaIt->second;
00282     } else {
00283         return NULL;
00284     }
00285 }

OSPF::RouterLSA * OSPF::Area::FindRouterLSA ( LinkStateID  linkStateID  ) 

00268 {
00269     std::map<OSPF::LinkStateID, OSPF::RouterLSA*>::iterator lsaIt = routerLSAsByID.find (linkStateID);
00270     if (lsaIt != routerLSAsByID.end ()) {
00271         return lsaIt->second;
00272     } else {
00273         return NULL;
00274     }
00275 }

bool OSPF::Area::FindSameOrWorseCostRoute ( const std::vector< OSPF::RoutingTableEntry * > &  newRoutingTable,
const OSPF::SummaryLSA summaryLSA,
unsigned short  currentCost,
bool &  destinationInRoutingTable,
std::list< OSPF::RoutingTableEntry * > &  sameOrWorseCost 
) const [private]

Browse through the newRoutingTable looking for entries describing the same destination as the currentLSA. If a cheaper route is found then skip this LSA (return true), else note those which are of equal or worse cost than the currentCost.

02095 {
02096     destinationInRoutingTable = false;
02097     sameOrWorseCost.clear ();
02098 
02099     long                   routeCount = newRoutingTable.size ();
02100     OSPF::IPv4AddressRange destination;
02101 
02102     destination.address = IPv4AddressFromULong (summaryLSA.getHeader ().getLinkStateID ());
02103     destination.mask    = IPv4AddressFromULong (summaryLSA.getNetworkMask ().getInt ());
02104 
02105     for (long j = 0; j < routeCount; j++) {
02106         OSPF::RoutingTableEntry* routingEntry  = newRoutingTable[j];
02107         bool                     foundMatching = false;
02108 
02109         if (summaryLSA.getHeader ().getLsType () == SummaryLSA_NetworksType) {
02110             if ((routingEntry->GetDestinationType () == OSPF::RoutingTableEntry::NetworkDestination) &&
02111                 (ULongFromIPv4Address (destination.address & destination.mask) == routingEntry->GetDestinationID ().getInt ()))
02112             {
02113                 foundMatching = true;
02114             }
02115         } else {
02116             if ((((routingEntry->GetDestinationType () & OSPF::RoutingTableEntry::AreaBorderRouterDestination) != 0) ||
02117                  ((routingEntry->GetDestinationType () & OSPF::RoutingTableEntry::ASBoundaryRouterDestination) != 0)) &&
02118                 (ULongFromIPv4Address (destination.address) == routingEntry->GetDestinationID ().getInt ()))
02119             {
02120                 foundMatching = true;
02121             }
02122         }
02123 
02124         if (foundMatching) {
02125             destinationInRoutingTable = true;
02126 
02127             /* If the matching entry is an IntraArea route (intra-area paths are
02128                 * always preferred to other paths of any cost), or it's a cheaper InterArea
02129                 * route, then skip this LSA.
02130                 */
02131             if ((routingEntry->GetPathType () == OSPF::RoutingTableEntry::IntraArea) ||
02132                 ((routingEntry->GetPathType () == OSPF::RoutingTableEntry::InterArea) &&
02133                  (routingEntry->GetCost () < currentCost)))
02134             {
02135                 return true;
02136             } else {
02137                 // if it's an other InterArea path
02138                 if ((routingEntry->GetPathType () == OSPF::RoutingTableEntry::InterArea) &&
02139                     (routingEntry->GetCost () >= currentCost))
02140                 {
02141                     sameOrWorseCost.push_back (routingEntry);
02142                 }   // else it's external -> same as if not in the table
02143             }
02144         }
02145     }
02146     return false;
02147 }

const OSPF::SummaryLSA * OSPF::Area::FindSummaryLSA ( LSAKeyType  lsaKey  )  const

00318 {
00319     std::map<OSPF::LSAKeyType, OSPF::SummaryLSA*, OSPF::LSAKeyType_Less>::const_iterator lsaIt = summaryLSAsByID.find (lsaKey);
00320     if (lsaIt != summaryLSAsByID.end ()) {
00321         return lsaIt->second;
00322     } else {
00323         return NULL;
00324     }
00325 }

OSPF::SummaryLSA * OSPF::Area::FindSummaryLSA ( LSAKeyType  lsaKey  ) 

00308 {
00309     std::map<OSPF::LSAKeyType, OSPF::SummaryLSA*, OSPF::LSAKeyType_Less>::iterator lsaIt = summaryLSAsByID.find (lsaKey);
00310     if (lsaIt != summaryLSAsByID.end ()) {
00311         return lsaIt->second;
00312     } else {
00313         return NULL;
00314     }
00315 }

OSPF::Interface * OSPF::Area::FindVirtualLink ( RouterID  routerID  ) 

00191 {
00192     int interfaceNum = associatedInterfaces.size ();
00193     for (int i = 0; i < interfaceNum; i++) {
00194         if ((associatedInterfaces[i]->GetType () == OSPF::Interface::Virtual) &&
00195             (associatedInterfaces[i]->GetNeighborByID (routerID) != NULL))
00196         {
00197             return associatedInterfaces[i];
00198         }
00199     }
00200     return NULL;
00201 }

bool OSPF::Area::FloodLSA ( OSPFLSA lsa,
Interface intf = NULL,
Neighbor neighbor = NULL 
)

00650 {
00651     bool floodedBackOut  = false;
00652     long interfaceCount = associatedInterfaces.size ();
00653 
00654     for (long i = 0; i < interfaceCount; i++) {
00655         if (associatedInterfaces[i]->FloodLSA (lsa, intf, neighbor)) {
00656             floodedBackOut = true;
00657         }
00658     }
00659 
00660     return floodedBackOut;
00661 }

IPv4AddressRange OSPF::Area::GetAddressRange ( unsigned int  index  )  const [inline]

00042 { return areaAddressRanges[index]; }

unsigned int OSPF::Area::GetAddressRangeCount ( void   )  const [inline]

00041 { return areaAddressRanges.size (); }

AreaID OSPF::Area::GetAreaID ( void   )  const [inline]

00039 { return areaID; }

OSPF::IPv4AddressRange OSPF::Area::GetContainingAddressRange ( IPv4AddressRange  addressRange,
bool *  advertise = NULL 
) const

00125 {
00126     int addressRangeNum = areaAddressRanges.size ();
00127     for (int i = 0; i < addressRangeNum; i++) {
00128         if ((areaAddressRanges[i].address & areaAddressRanges[i].mask) == (addressRange.address & areaAddressRanges[i].mask)) {
00129             if (advertise != NULL) {
00130                 std::map<OSPF::IPv4AddressRange, bool, OSPF::IPv4AddressRange_Less>::const_iterator rangeIt = advertiseAddressRanges.find (areaAddressRanges[i]);
00131                 if (rangeIt != advertiseAddressRanges.end ()) {
00132                     *advertise = rangeIt->second;
00133                 } else {
00134                     *advertise = true;
00135                 }
00136             }
00137             return areaAddressRanges[i];
00138         }
00139     }
00140     if (advertise != NULL) {
00141         *advertise =  false;
00142     }
00143     return NullIPv4AddressRange;
00144 }

bool OSPF::Area::GetExternalRoutingCapability ( void   )  const [inline]

00047 { return externalRoutingCapability; }

OSPF::Interface * OSPF::Area::GetInterface ( IPv4Address  address  ) 

00160 {
00161     int interfaceNum = associatedInterfaces.size ();
00162     for (int i = 0; i < interfaceNum; i++) {
00163         if ((associatedInterfaces[i]->GetType () != OSPF::Interface::Virtual) &&
00164             (associatedInterfaces[i]->GetAddressRange ().address == address))
00165         {
00166             return associatedInterfaces[i];
00167         }
00168     }
00169     return NULL;
00170 }

OSPF::Interface * OSPF::Area::GetInterface ( unsigned char  ifIndex  ) 

00147 {
00148     int interfaceNum = associatedInterfaces.size ();
00149     for (int i = 0; i < interfaceNum; i++) {
00150         if ((associatedInterfaces[i]->GetType () != OSPF::Interface::Virtual) &&
00151             (associatedInterfaces[i]->GetIfIndex () == ifIndex))
00152         {
00153             return associatedInterfaces[i];
00154         }
00155     }
00156     return NULL;
00157 }

const NetworkLSA* OSPF::Area::GetNetworkLSA ( unsigned long  i  )  const [inline]

00063 { return networkLSAs[i]; }

NetworkLSA* OSPF::Area::GetNetworkLSA ( unsigned long  i  )  [inline]

00062 { return networkLSAs[i]; }

unsigned long OSPF::Area::GetNetworkLSACount ( void   )  const [inline]

00061 { return networkLSAs.size (); }

const Router* OSPF::Area::GetRouter ( void   )  const [inline]

00056 { return parentRouter; }

Router* OSPF::Area::GetRouter ( void   )  [inline]

00055 { return parentRouter; }

const RouterLSA* OSPF::Area::GetRouterLSA ( unsigned long  i  )  const [inline]

00060 { return routerLSAs[i]; }

RouterLSA* OSPF::Area::GetRouterLSA ( unsigned long  i  )  [inline]

00059 { return routerLSAs[i]; }

unsigned long OSPF::Area::GetRouterLSACount ( void   )  const [inline]

00058 { return routerLSAs.size (); }

const RouterLSA* OSPF::Area::GetSPFTreeRoot ( void   )  const [inline]

00052 { return spfTreeRoot; }

RouterLSA* OSPF::Area::GetSPFTreeRoot ( void   )  [inline]

00051 { return spfTreeRoot; }

Metric OSPF::Area::GetStubDefaultCost ( void   )  const [inline]

00049 { return stubDefaultCost; }

const SummaryLSA* OSPF::Area::GetSummaryLSA ( unsigned long  i  )  const [inline]

00066 { return summaryLSAs[i]; }

SummaryLSA* OSPF::Area::GetSummaryLSA ( unsigned long  i  )  [inline]

00065 { return summaryLSAs[i]; }

unsigned long OSPF::Area::GetSummaryLSACount ( void   )  const [inline]

00064 { return summaryLSAs.size (); }

bool OSPF::Area::GetTransitCapability ( void   )  const [inline]

00045 { return transitCapability; }

OSPF::LinkStateID OSPF::Area::GetUniqueLinkStateID ( OSPF::IPv4AddressRange  destination,
OSPF::Metric  destinationCost,
OSPF::SummaryLSA *&  lsaToReoriginate 
) const [private]

Returns a link state ID for the input destination. If this router hasn't originated a Summary LSA for the input destination then the function returs the destination address as link state ID. If it has originated a Summary LSA for the input destination then the function checks which LSA would contain the longer netmask. If the two masks are equal then this means thet we're updating an LSA already in the database, so the function returns the destination address as link state ID. If the input destination netmask is longer then the one already in the database, then the returned link state ID is the input destination address ORed together with the inverse of the input destination mask. If the input destination netmask is shorter, then the Summary LSA already in the database has to be replaced by the current destination. In this case the lsaToReoriginate parameter is filled with a copy of the Summary LSA in the database with it's mask replaced by the destination mask and the cost replaced by the input destination cost; the returned link state ID is the input destination address ORed together with the inverse of the mask stored in the Summary LSA in the database. This means that if the lsaToReoriginate parameter is not NULL on return then another lookup in the database is needed with the same LSAKey as used here (input destination address and the router's own routerID) and the resulting Summary LSA's link state ID should be changed to the one returned by this function.

00978 {
00979     if (lsaToReoriginate != NULL) {
00980         delete lsaToReoriginate;
00981         lsaToReoriginate = NULL;
00982     }
00983 
00984     OSPF::LSAKeyType lsaKey;
00985 
00986     lsaKey.linkStateID = ULongFromIPv4Address (destination.address);
00987     lsaKey.advertisingRouter = parentRouter->GetRouterID ();
00988 
00989     const OSPF::SummaryLSA* foundLSA = FindSummaryLSA (lsaKey);
00990 
00991     if (foundLSA == NULL) {
00992         return lsaKey.linkStateID;
00993     } else {
00994         OSPF::IPv4Address existingMask = IPv4AddressFromULong (foundLSA->getNetworkMask ().getInt ());
00995 
00996         if (destination.mask == existingMask) {
00997             return lsaKey.linkStateID;
00998         } else {
00999             if (destination.mask >= existingMask) {
01000                 return (lsaKey.linkStateID | (~(ULongFromIPv4Address (destination.mask))));
01001             } else {
01002                 OSPF::SummaryLSA* summaryLSA = new OSPF::SummaryLSA (*foundLSA);
01003 
01004                 long sequenceNumber = summaryLSA->getHeader ().getLsSequenceNumber ();
01005 
01006                 summaryLSA->getHeader ().setLsAge (0);
01007                 summaryLSA->getHeader ().setLsSequenceNumber ((sequenceNumber == MAX_SEQUENCE_NUMBER) ? INITIAL_SEQUENCE_NUMBER : sequenceNumber + 1);
01008                 summaryLSA->setNetworkMask (ULongFromIPv4Address (destination.mask));
01009                 summaryLSA->setRouteCost (destinationCost);
01010                 summaryLSA->getHeader ().setLsChecksum (0);    // TODO: calculate correct LS checksum
01011 
01012                 lsaToReoriginate = summaryLSA;
01013 
01014                 return (lsaKey.linkStateID | (~(ULongFromIPv4Address (existingMask))));
01015             }
01016         }
01017     }
01018 }

bool OSPF::Area::HasAddressRange ( IPv4AddressRange  addressRange  )  const

00112 {
00113     int addressRangeNum = areaAddressRanges.size ();
00114     for (int i = 0; i < addressRangeNum; i++) {
00115         if ((areaAddressRanges[i].address == addressRange.address) &&
00116             (areaAddressRanges[i].mask == addressRange.mask))
00117         {
00118             return true;
00119         }
00120     }
00121     return false;
00122 }

bool OSPF::Area::HasLink ( OSPFLSA fromLSA,
OSPFLSA toLSA 
) const [private]

02029 {
02030     unsigned int i;
02031 
02032     OSPF::RouterLSA* fromRouterLSA = dynamic_cast<OSPF::RouterLSA*> (fromLSA);
02033     if (fromRouterLSA != NULL) {
02034         unsigned int     linkCount   = fromRouterLSA->getLinksArraySize ();
02035         OSPF::RouterLSA* toRouterLSA = dynamic_cast<OSPF::RouterLSA*> (toLSA);
02036         if (toRouterLSA != NULL) {
02037             for (i = 0; i < linkCount; i++) {
02038                 Link&    link     = fromRouterLSA->getLinks (i);
02039                 LinkType linkType = static_cast<LinkType> (link.getType ());
02040 
02041                 if (((linkType == PointToPointLink) ||
02042                      (linkType == VirtualLink)) &&
02043                     (link.getLinkID ().getInt () == toRouterLSA->getHeader ().getLinkStateID ()))
02044                 {
02045                     return true;
02046                 }
02047             }
02048         } else {
02049             OSPF::NetworkLSA* toNetworkLSA = dynamic_cast<OSPF::NetworkLSA*> (toLSA);
02050             if (toNetworkLSA != NULL) {
02051                 for (i = 0; i < linkCount; i++) {
02052                     Link&    link     = fromRouterLSA->getLinks (i);
02053 
02054                     if ((link.getType () == TransitLink) &&
02055                         (link.getLinkID ().getInt () == toNetworkLSA->getHeader ().getLinkStateID ()))
02056                     {
02057                         return true;
02058                     }
02059                     if ((link.getType () == StubLink) &&
02060                         ((link.getLinkID ().getInt () & link.getLinkData ()) == (toNetworkLSA->getHeader ().getLinkStateID () & toNetworkLSA->getNetworkMask ().getInt ())))
02061                     {
02062                         return true;
02063                     }
02064                 }
02065             }
02066         }
02067     } else {
02068         OSPF::NetworkLSA* fromNetworkLSA = dynamic_cast<OSPF::NetworkLSA*> (fromLSA);
02069         if (fromNetworkLSA != NULL) {
02070             unsigned int     routerCount   = fromNetworkLSA->getAttachedRoutersArraySize ();
02071             OSPF::RouterLSA* toRouterLSA = dynamic_cast<OSPF::RouterLSA*> (toLSA);
02072             if (toRouterLSA != NULL) {
02073                 for (i = 0; i < routerCount; i++) {
02074                     if (fromNetworkLSA->getAttachedRouters (i).getInt () == toRouterLSA->getHeader ().getLinkStateID ()) {
02075                         return true;
02076                     }
02077                 }
02078             }
02079         }
02080     }
02081 
02082     return false;
02083 }

bool OSPF::Area::HasVirtualLink ( AreaID  withTransitArea  )  const

00173 {
00174     if ((areaID != OSPF::BackboneAreaID) || (withTransitArea == OSPF::BackboneAreaID)) {
00175         return false;
00176     }
00177 
00178     int interfaceNum = associatedInterfaces.size ();
00179     for (int i = 0; i < interfaceNum; i++) {
00180         if ((associatedInterfaces[i]->GetType () == OSPF::Interface::Virtual) &&
00181             (associatedInterfaces[i]->GetTransitAreaID () == withTransitArea))
00182         {
00183             return true;
00184         }
00185     }
00186     return false;
00187 }

void OSPF::Area::info ( char *  buffer  ) 

00048 {
00049     std::stringstream out;
00050     char areaString[16];
00051     out << "areaID: " << AddressStringFromULong (areaString, 16, areaID);
00052     strcpy(buffer, out.str().c_str());
00053 }

bool OSPF::Area::InstallNetworkLSA ( OSPFNetworkLSA lsa  ) 

00224 {
00225     OSPF::LinkStateID linkStateID = lsa->getHeader ().getLinkStateID ();
00226     std::map<OSPF::LinkStateID, OSPF::NetworkLSA*>::iterator lsaIt = networkLSAsByID.find (linkStateID);
00227     if (lsaIt != networkLSAsByID.end ()) {
00228         OSPF::LSAKeyType lsaKey;
00229 
00230         lsaKey.linkStateID = lsa->getHeader ().getLinkStateID ();
00231         lsaKey.advertisingRouter = lsa->getHeader ().getAdvertisingRouter ().getInt ();
00232 
00233         RemoveFromAllRetransmissionLists (lsaKey);
00234         return lsaIt->second->Update (lsa);
00235     } else {
00236         OSPF::NetworkLSA* lsaCopy = new OSPF::NetworkLSA (*lsa);
00237         networkLSAsByID[linkStateID] = lsaCopy;
00238         networkLSAs.push_back (lsaCopy);
00239         return true;
00240     }
00241 }

bool OSPF::Area::InstallRouterLSA ( OSPFRouterLSA lsa  ) 

00204 {
00205     OSPF::LinkStateID linkStateID = lsa->getHeader ().getLinkStateID ();
00206     std::map<OSPF::LinkStateID, OSPF::RouterLSA*>::iterator lsaIt = routerLSAsByID.find (linkStateID);
00207     if (lsaIt != routerLSAsByID.end ()) {
00208         OSPF::LSAKeyType lsaKey;
00209 
00210         lsaKey.linkStateID = lsa->getHeader ().getLinkStateID ();
00211         lsaKey.advertisingRouter = lsa->getHeader ().getAdvertisingRouter ().getInt ();
00212 
00213         RemoveFromAllRetransmissionLists (lsaKey);
00214         return lsaIt->second->Update (lsa);
00215     } else {
00216         OSPF::RouterLSA* lsaCopy = new OSPF::RouterLSA (*lsa);
00217         routerLSAsByID[linkStateID] = lsaCopy;
00218         routerLSAs.push_back (lsaCopy);
00219         return true;
00220     }
00221 }

bool OSPF::Area::InstallSummaryLSA ( OSPFSummaryLSA lsa  ) 

00244 {
00245     OSPF::LSAKeyType lsaKey;
00246 
00247     lsaKey.linkStateID = lsa->getHeader ().getLinkStateID ();
00248     lsaKey.advertisingRouter = lsa->getHeader ().getAdvertisingRouter ().getInt ();
00249 
00250     std::map<OSPF::LSAKeyType, OSPF::SummaryLSA*, OSPF::LSAKeyType_Less>::iterator lsaIt = summaryLSAsByID.find (lsaKey);
00251     if (lsaIt != summaryLSAsByID.end ()) {
00252         OSPF::LSAKeyType lsaKey;
00253 
00254         lsaKey.linkStateID = lsa->getHeader ().getLinkStateID ();
00255         lsaKey.advertisingRouter = lsa->getHeader ().getAdvertisingRouter ().getInt ();
00256 
00257         RemoveFromAllRetransmissionLists (lsaKey);
00258         return lsaIt->second->Update (lsa);
00259     } else {
00260         OSPF::SummaryLSA* lsaCopy = new OSPF::SummaryLSA (*lsa);
00261         summaryLSAsByID[lsaKey] = lsaCopy;
00262         summaryLSAs.push_back (lsaCopy);
00263         return true;
00264     }
00265 }

bool OSPF::Area::IsLocalAddress ( IPv4Address  address  )  const

00664 {
00665     long interfaceCount = associatedInterfaces.size ();
00666     for (long i = 0; i < interfaceCount; i++) {
00667         if (associatedInterfaces[i]->GetAddressRange ().address == address) {
00668             return true;
00669         }
00670     }
00671     return false;
00672 }

bool OSPF::Area::IsOnAnyRetransmissionList ( LSAKeyType  lsaKey  )  const

00639 {
00640     long interfaceCount = associatedInterfaces.size ();
00641     for (long i = 0; i < interfaceCount; i++) {
00642         if (associatedInterfaces[i]->IsOnAnyRetransmissionList (lsaKey)) {
00643             return true;
00644         }
00645     }
00646     return false;
00647 }

OSPF::NetworkLSA * OSPF::Area::OriginateNetworkLSA ( const Interface intf  ) 

00916 {
00917     if (intf->AnyNeighborInStates (OSPF::Neighbor::FullState)) {
00918         OSPF::NetworkLSA* networkLSA      = new OSPF::NetworkLSA;
00919         OSPFLSAHeader&   lsaHeader        = networkLSA->getHeader ();
00920         long             neighborCount    = intf->GetNeighborCount ();
00921         OSPFOptions      lsOptions;
00922 
00923         lsaHeader.setLsAge (0);
00924         memset (&lsOptions, 0, sizeof (OSPFOptions));
00925         lsOptions.E_ExternalRoutingCapability = externalRoutingCapability;
00926         lsaHeader.setLsOptions (lsOptions);
00927         lsaHeader.setLsType (NetworkLSAType);
00928         lsaHeader.setLinkStateID (ULongFromIPv4Address (intf->GetAddressRange ().address));
00929         lsaHeader.setAdvertisingRouter (parentRouter->GetRouterID ());
00930         lsaHeader.setLsSequenceNumber (INITIAL_SEQUENCE_NUMBER);
00931 
00932         networkLSA->setNetworkMask (ULongFromIPv4Address (intf->GetAddressRange ().mask));
00933 
00934         for (long j = 0; j < neighborCount; j++) {
00935             const OSPF::Neighbor* neighbor = intf->GetNeighbor (j);
00936             if (neighbor->GetState () == OSPF::Neighbor::FullState) {
00937                 unsigned short netIndex = networkLSA->getAttachedRoutersArraySize ();
00938                 networkLSA->setAttachedRoutersArraySize (netIndex + 1);
00939                 networkLSA->setAttachedRouters (netIndex, neighbor->GetNeighborID ());
00940             }
00941         }
00942         unsigned short netIndex = networkLSA->getAttachedRoutersArraySize ();
00943         networkLSA->setAttachedRoutersArraySize (netIndex + 1);
00944         networkLSA->setAttachedRouters (netIndex, parentRouter->GetRouterID ());
00945 
00946         lsaHeader.setLsChecksum (0);    // TODO: calculate correct LS checksum
00947 
00948         return networkLSA;
00949     } else {
00950         return NULL;
00951     }
00952 }

OSPF::RouterLSA * OSPF::Area::OriginateRouterLSA ( void   ) 

00675 {
00676     OSPF::RouterLSA* routerLSA      = new OSPF::RouterLSA;
00677     OSPFLSAHeader&   lsaHeader      = routerLSA->getHeader ();
00678     long             interfaceCount = associatedInterfaces.size ();
00679     OSPFOptions      lsOptions;
00680     long             i;
00681 
00682     lsaHeader.setLsAge (0);
00683     memset (&lsOptions, 0, sizeof (OSPFOptions));
00684     lsOptions.E_ExternalRoutingCapability = externalRoutingCapability;
00685     lsaHeader.setLsOptions (lsOptions);
00686     lsaHeader.setLsType (RouterLSAType);
00687     lsaHeader.setLinkStateID (parentRouter->GetRouterID ());
00688     lsaHeader.setAdvertisingRouter (parentRouter->GetRouterID ());
00689     lsaHeader.setLsSequenceNumber (INITIAL_SEQUENCE_NUMBER);
00690 
00691     routerLSA->setB_AreaBorderRouter (parentRouter->GetAreaCount () > 1);
00692     routerLSA->setE_ASBoundaryRouter ((externalRoutingCapability && parentRouter->GetASBoundaryRouter ()) ? true : false);
00693     OSPF::Area* backbone = parentRouter->GetArea (OSPF::BackboneAreaID);
00694     routerLSA->setV_VirtualLinkEndpoint ((backbone == NULL) ? false : backbone->HasVirtualLink (areaID));
00695 
00696     routerLSA->setNumberOfLinks (0);
00697     routerLSA->setLinksArraySize (0);
00698     for (i = 0; i < interfaceCount; i++) {
00699         OSPF::Interface* intf = associatedInterfaces[i];
00700 
00701         if (intf->GetState () == OSPF::Interface::DownState) {
00702             continue;
00703         }
00704         if ((intf->GetState () == OSPF::Interface::LoopbackState) &&
00705             ((intf->GetType () != OSPF::Interface::PointToPoint) ||
00706              (intf->GetAddressRange ().address != OSPF::NullIPv4Address)))
00707         {
00708             Link stubLink;
00709             stubLink.setType (StubLink);
00710             stubLink.setLinkID (ULongFromIPv4Address (intf->GetAddressRange ().address));
00711             stubLink.setLinkData (0xFFFFFFFF);
00712             stubLink.setLinkCost (0);
00713             stubLink.setNumberOfTOS (0);
00714             stubLink.setTosDataArraySize (0);
00715 
00716             unsigned short linkIndex = routerLSA->getLinksArraySize ();
00717             routerLSA->setLinksArraySize (linkIndex + 1);
00718             routerLSA->setNumberOfLinks (linkIndex + 1);
00719             routerLSA->setLinks (linkIndex, stubLink);
00720         }
00721         if (intf->GetState () > OSPF::Interface::LoopbackState) {
00722             switch (intf->GetType ()) {
00723                 case OSPF::Interface::PointToPoint:
00724                     {
00725                         OSPF::Neighbor* neighbor = (intf->GetNeighborCount () > 0) ? intf->GetNeighbor (0) : NULL;
00726                         if (neighbor != NULL) {
00727                             if (neighbor->GetState () == OSPF::Neighbor::FullState) {
00728                                 Link link;
00729                                 link.setType (PointToPointLink);
00730                                 link.setLinkID (neighbor->GetNeighborID ());
00731                                 if (intf->GetAddressRange ().address != OSPF::NullIPv4Address) {
00732                                     link.setLinkData (ULongFromIPv4Address (intf->GetAddressRange ().address));
00733                                 } else {
00734                                     link.setLinkData (intf->GetIfIndex ());
00735                                 }
00736                                 link.setLinkCost (intf->GetOutputCost ());
00737                                 link.setNumberOfTOS (0);
00738                                 link.setTosDataArraySize (0);
00739 
00740                                 unsigned short linkIndex = routerLSA->getLinksArraySize ();
00741                                 routerLSA->setLinksArraySize (linkIndex + 1);
00742                                 routerLSA->setNumberOfLinks (linkIndex + 1);
00743                                 routerLSA->setLinks (linkIndex, link);
00744                             }
00745                             if (intf->GetState () == OSPF::Interface::PointToPointState) {
00746                                 if (neighbor->GetAddress () != OSPF::NullIPv4Address) {
00747                                     Link stubLink;
00748                                     stubLink.setType (StubLink);
00749                                     stubLink.setLinkID (ULongFromIPv4Address (neighbor->GetAddress ()));
00750                                     stubLink.setLinkData (0xFFFFFFFF);
00751                                     stubLink.setLinkCost (intf->GetOutputCost ());
00752                                     stubLink.setNumberOfTOS (0);
00753                                     stubLink.setTosDataArraySize (0);
00754 
00755                                     unsigned short linkIndex = routerLSA->getLinksArraySize ();
00756                                     routerLSA->setLinksArraySize (linkIndex + 1);
00757                                     routerLSA->setNumberOfLinks (linkIndex + 1);
00758                                     routerLSA->setLinks (linkIndex, stubLink);
00759                                 } else {
00760                                     if (ULongFromIPv4Address (intf->GetAddressRange ().mask) != 0xFFFFFFFF) {
00761                                         Link stubLink;
00762                                         stubLink.setType (StubLink);
00763                                         stubLink.setLinkID (ULongFromIPv4Address (intf->GetAddressRange ().address &
00764                                                                                   intf->GetAddressRange ().mask));
00765                                         stubLink.setLinkData (ULongFromIPv4Address (intf->GetAddressRange ().mask));
00766                                         stubLink.setLinkCost (intf->GetOutputCost ());
00767                                         stubLink.setNumberOfTOS (0);
00768                                         stubLink.setTosDataArraySize (0);
00769 
00770                                         unsigned short linkIndex = routerLSA->getLinksArraySize ();
00771                                         routerLSA->setLinksArraySize (linkIndex + 1);
00772                                         routerLSA->setNumberOfLinks (linkIndex + 1);
00773                                         routerLSA->setLinks (linkIndex, stubLink);
00774                                     }
00775                                 }
00776                             }
00777                         }
00778                     }
00779                     break;
00780                 case OSPF::Interface::Broadcast:
00781                 case OSPF::Interface::NBMA:
00782                     {
00783                         if (intf->GetState () == OSPF::Interface::WaitingState) {
00784                             Link stubLink;
00785                             stubLink.setType (StubLink);
00786                             stubLink.setLinkID (ULongFromIPv4Address (intf->GetAddressRange ().address &
00787                                                                       intf->GetAddressRange ().mask));
00788                             stubLink.setLinkData (ULongFromIPv4Address (intf->GetAddressRange ().mask));
00789                             stubLink.setLinkCost (intf->GetOutputCost ());
00790                             stubLink.setNumberOfTOS (0);
00791                             stubLink.setTosDataArraySize (0);
00792 
00793                             unsigned short linkIndex = routerLSA->getLinksArraySize ();
00794                             routerLSA->setLinksArraySize (linkIndex + 1);
00795                             routerLSA->setNumberOfLinks (linkIndex + 1);
00796                             routerLSA->setLinks (linkIndex, stubLink);
00797                         } else {
00798                             OSPF::Neighbor* dRouter = intf->GetNeighborByAddress (intf->GetDesignatedRouter ().ipInterfaceAddress);
00799                             if (((dRouter != NULL) && (dRouter->GetState () == OSPF::Neighbor::FullState)) ||
00800                                 ((intf->GetDesignatedRouter ().routerID == parentRouter->GetRouterID ()) &&
00801                                  (intf->AnyNeighborInStates (OSPF::Neighbor::FullState))))
00802                             {
00803                                 Link link;
00804                                 link.setType (TransitLink);
00805                                 link.setLinkID (ULongFromIPv4Address (intf->GetDesignatedRouter ().ipInterfaceAddress));
00806                                 link.setLinkData (ULongFromIPv4Address (intf->GetAddressRange ().address));
00807                                 link.setLinkCost (intf->GetOutputCost ());
00808                                 link.setNumberOfTOS (0);
00809                                 link.setTosDataArraySize (0);
00810 
00811                                 unsigned short linkIndex = routerLSA->getLinksArraySize ();
00812                                 routerLSA->setLinksArraySize (linkIndex + 1);
00813                                 routerLSA->setNumberOfLinks (linkIndex + 1);
00814                                 routerLSA->setLinks (linkIndex, link);
00815                             } else {
00816                                 Link stubLink;
00817                                 stubLink.setType (StubLink);
00818                                 stubLink.setLinkID (ULongFromIPv4Address (intf->GetAddressRange ().address &
00819                                                                           intf->GetAddressRange ().mask));
00820                                 stubLink.setLinkData (ULongFromIPv4Address (intf->GetAddressRange ().mask));
00821                                 stubLink.setLinkCost (intf->GetOutputCost ());
00822                                 stubLink.setNumberOfTOS (0);
00823                                 stubLink.setTosDataArraySize (0);
00824 
00825                                 unsigned short linkIndex = routerLSA->getLinksArraySize ();
00826                                 routerLSA->setLinksArraySize (linkIndex + 1);
00827                                 routerLSA->setNumberOfLinks (linkIndex + 1);
00828                                 routerLSA->setLinks (linkIndex, stubLink);
00829                             }
00830                         }
00831                     }
00832                     break;
00833                 case OSPF::Interface::Virtual:
00834                     {
00835                         OSPF::Neighbor* neighbor = (intf->GetNeighborCount () > 0) ? intf->GetNeighbor (0) : NULL;
00836                         if ((neighbor != NULL) && (neighbor->GetState () == OSPF::Neighbor::FullState)) {
00837                             Link link;
00838                             link.setType (VirtualLink);
00839                             link.setLinkID (neighbor->GetNeighborID ());
00840                             link.setLinkData (ULongFromIPv4Address (intf->GetAddressRange ().address));
00841                             link.setLinkCost (intf->GetOutputCost ());
00842                             link.setNumberOfTOS (0);
00843                             link.setTosDataArraySize (0);
00844 
00845                             unsigned short linkIndex = routerLSA->getLinksArraySize ();
00846                             routerLSA->setLinksArraySize (linkIndex + 1);
00847                             routerLSA->setNumberOfLinks (linkIndex + 1);
00848                             routerLSA->setLinks (linkIndex, link);
00849                         }
00850                     }
00851                     break;
00852                 case OSPF::Interface::PointToMultiPoint:
00853                     {
00854                         Link stubLink;
00855                         stubLink.setType (StubLink);
00856                         stubLink.setLinkID (ULongFromIPv4Address (intf->GetAddressRange ().address));
00857                         stubLink.setLinkData (0xFFFFFFFF);
00858                         stubLink.setLinkCost (0);
00859                         stubLink.setNumberOfTOS (0);
00860                         stubLink.setTosDataArraySize (0);
00861 
00862                         unsigned short linkIndex = routerLSA->getLinksArraySize ();
00863                         routerLSA->setLinksArraySize (linkIndex + 1);
00864                         routerLSA->setNumberOfLinks (linkIndex + 1);
00865                         routerLSA->setLinks (linkIndex, stubLink);
00866 
00867                         long neighborCount = intf->GetNeighborCount ();
00868                         for (long i = 0; i < neighborCount; i++) {
00869                             OSPF::Neighbor* neighbor = intf->GetNeighbor (i);
00870                             if (neighbor->GetState () == OSPF::Neighbor::FullState) {
00871                                 Link link;
00872                                 link.setType (PointToPointLink);
00873                                 link.setLinkID (neighbor->GetNeighborID ());
00874                                 link.setLinkData (ULongFromIPv4Address (intf->GetAddressRange ().address));
00875                                 link.setLinkCost (intf->GetOutputCost ());
00876                                 link.setNumberOfTOS (0);
00877                                 link.setTosDataArraySize (0);
00878 
00879                                 unsigned short linkIndex = routerLSA->getLinksArraySize ();
00880                                 routerLSA->setLinksArraySize (linkIndex + 1);
00881                                 routerLSA->setNumberOfLinks (linkIndex + 1);
00882                                 routerLSA->setLinks (linkIndex, stubLink);
00883                             }
00884                         }
00885                     }
00886                     break;
00887                 default: break;
00888             }
00889         }
00890     }
00891 
00892     long hostRouteCount = hostRoutes.size ();
00893     for (i = 0; i < hostRouteCount; i++) {
00894         Link stubLink;
00895         stubLink.setType (StubLink);
00896         stubLink.setLinkID (ULongFromIPv4Address (hostRoutes[i].address));
00897         stubLink.setLinkData (0xFFFFFFFF);
00898         stubLink.setLinkCost (hostRoutes[i].linkCost);
00899         stubLink.setNumberOfTOS (0);
00900         stubLink.setTosDataArraySize (0);
00901 
00902         unsigned short linkIndex = routerLSA->getLinksArraySize ();
00903         routerLSA->setLinksArraySize (linkIndex + 1);
00904         routerLSA->setNumberOfLinks (linkIndex + 1);
00905         routerLSA->setLinks (linkIndex, stubLink);
00906     }
00907 
00908     lsaHeader.setLsChecksum (0);    // TODO: calculate correct LS checksum
00909 
00910     routerLSA->SetSource (OSPF::LSATrackingInfo::Originated);
00911 
00912     return routerLSA;
00913 }

OSPF::SummaryLSA * OSPF::Area::OriginateSummaryLSA ( const OSPF::SummaryLSA summaryLSA  )  [private]

01279 {
01280     const std::map<OSPF::LSAKeyType, bool, OSPF::LSAKeyType_Less> emptyMap;
01281     OSPF::SummaryLSA*                                             dontReoriginate = NULL;
01282 
01283     const OSPFLSAHeader& lsaHeader   = summaryLSA->getHeader ();
01284     unsigned long   entryCount = parentRouter->GetRoutingTableEntryCount ();
01285 
01286     for (unsigned long i = 0; i < entryCount; i++) {
01287         const OSPF::RoutingTableEntry* entry = parentRouter->GetRoutingTableEntry (i);
01288 
01289         if ((lsaHeader.getLsType () == SummaryLSA_ASBoundaryRoutersType) &&
01290             ((((entry->GetDestinationType () & OSPF::RoutingTableEntry::AreaBorderRouterDestination) != 0) ||
01291               ((entry->GetDestinationType () & OSPF::RoutingTableEntry::ASBoundaryRouterDestination) != 0)) &&
01292              ((entry->GetDestinationID ().getInt () == lsaHeader.getLinkStateID ()) &&
01293               (entry->GetAddressMask () == summaryLSA->getNetworkMask ()))))
01294         {
01295             OSPF::SummaryLSA* returnLSA = OriginateSummaryLSA (entry, emptyMap, dontReoriginate);
01296             if (dontReoriginate != NULL) {
01297                 delete dontReoriginate;
01298             }
01299             return returnLSA;
01300         }
01301 
01302         unsigned long lsaMask = summaryLSA->getNetworkMask ().getInt ();
01303 
01304         if ((lsaHeader.getLsType () == SummaryLSA_NetworksType) &&
01305             (entry->GetDestinationType () == OSPF::RoutingTableEntry::NetworkDestination) &&
01306             (entry->GetAddressMask ().getInt () == lsaMask) &&
01307             (entry->GetDestinationID ().getInt () & lsaMask == lsaHeader.getLinkStateID () & lsaMask))
01308         {
01309             OSPF::SummaryLSA* returnLSA = OriginateSummaryLSA (entry, emptyMap, dontReoriginate);
01310             if (dontReoriginate != NULL) {
01311                 delete dontReoriginate;
01312             }
01313             return returnLSA;
01314         }
01315     }
01316 
01317     return NULL;
01318 }

SummaryLSA* OSPF::Area::OriginateSummaryLSA ( const RoutingTableEntry entry,
const std::map< LSAKeyType, bool, LSAKeyType_Less > &  originatedLSAs,
SummaryLSA *&  lsaToReoriginate 
)

void OSPF::Area::ReCheckSummaryLSAs ( std::vector< RoutingTableEntry * > &  newRoutingTable  ) 

void OSPF::Area::RemoveFromAllRetransmissionLists ( LSAKeyType  lsaKey  ) 

00631 {
00632     long interfaceCount = associatedInterfaces.size ();
00633     for (long i = 0; i < interfaceCount; i++) {
00634         associatedInterfaces[i]->RemoveFromAllRetransmissionLists (lsaKey);
00635     }
00636 }

void OSPF::Area::SetAreaID ( AreaID  areaId  )  [inline]

00038 { areaID = areaId; }

void OSPF::Area::SetExternalRoutingCapability ( bool  flooded  )  [inline]

00046 { externalRoutingCapability = flooded; }

void OSPF::Area::SetRouter ( Router router  )  [inline]

00054 { parentRouter = router; }

void OSPF::Area::SetSPFTreeRoot ( RouterLSA root  )  [inline]

00050 { spfTreeRoot = root; }

void OSPF::Area::SetStubDefaultCost ( Metric  cost  )  [inline]

00048 { stubDefaultCost = cost; }

void OSPF::Area::SetTransitCapability ( bool  transit  )  [inline]

00044 { transitCapability = transit; }


Member Data Documentation

std::map<IPv4AddressRange, bool, IPv4AddressRange_Less> OSPF::Area::advertiseAddressRanges [private]

std::vector<IPv4AddressRange> OSPF::Area::areaAddressRanges [private]

AreaID OSPF::Area::areaID [private]

std::vector<Interface*> OSPF::Area::associatedInterfaces [private]

bool OSPF::Area::externalRoutingCapability [private]

std::vector<HostRouteParameters> OSPF::Area::hostRoutes [private]

std::vector<NetworkLSA*> OSPF::Area::networkLSAs [private]

std::map<LinkStateID, NetworkLSA*> OSPF::Area::networkLSAsByID [private]

Router* OSPF::Area::parentRouter [private]

std::vector<RouterLSA*> OSPF::Area::routerLSAs [private]

std::map<LinkStateID, RouterLSA*> OSPF::Area::routerLSAsByID [private]

RouterLSA* OSPF::Area::spfTreeRoot [private]

Metric OSPF::Area::stubDefaultCost [private]

std::vector<SummaryLSA*> OSPF::Area::summaryLSAs [private]

std::map<LSAKeyType, SummaryLSA*, LSAKeyType_Less> OSPF::Area::summaryLSAsByID [private]

bool OSPF::Area::transitCapability [private]


The documentation for this class was generated from the following files:
Generated on Wed Apr 4 13:20:25 2007 for INET Framework for OMNeT++/OMNEST by  doxygen 1.4.7