INET Framework for OMNeT++/OMNEST
ansaOspfArea6.cc
Go to the documentation of this file.
00001 //
00002 // This program is free software: you can redistribute it and/or modify
00003 // it under the terms of the GNU Lesser General Public License as published by
00004 // the Free Software Foundation, either version 3 of the License, or
00005 // (at your option) any later version.
00006 // 
00007 // This program is distributed in the hope that it will be useful,
00008 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00009 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010 // GNU Lesser General Public License for more details.
00011 // 
00012 // You should have received a copy of the GNU Lesser General Public License
00013 // along with this program.  If not, see http://www.gnu.org/licenses/.
00014 // 
00015 
00016 #include "ansaOspfArea6.h"
00017 #include "ansaOspfRouter6.h"
00018 
00019 
00020 AnsaOspf6::Area::Area(AnsaOspf6::AreaID id) :
00021       areaID(id),
00022       transitCapability(false),
00023       externalRoutingCapability(true),
00024       stubDefaultCost(1),
00025       spfTreeRoot(NULL),
00026       parentRouter(NULL){
00027 
00028    //
00029 }
00030 
00031 AnsaOspf6::Area::~Area(void) {
00032    int interfaceNum = associatedInterfaces.size();
00033    for (int i = 0; i < interfaceNum; i++){
00034       delete (associatedInterfaces[i]);
00035    }
00036 
00037 
00038    long lsaCount = routerLSAs.size();
00039    for (long j = 0; j < lsaCount; j++){
00040       delete routerLSAs[j];
00041    }
00042    routerLSAs.clear();
00043 
00044    lsaCount = networkLSAs.size();
00045    for (long k = 0; k < lsaCount; k++){
00046       delete networkLSAs[k];
00047    }
00048    networkLSAs.clear();
00049 
00050    lsaCount = interAreaPrefixLSAs.size();
00051    for (long k = 0; k < lsaCount; k++){
00052       delete interAreaPrefixLSAs[k];
00053    }
00054    interAreaPrefixLSAs.clear();
00055 
00056    lsaCount = interAreaRouterLSAs.size();
00057    for (long k = 0; k < lsaCount; k++){
00058       delete interAreaRouterLSAs[k];
00059    }
00060    interAreaRouterLSAs.clear();
00061 
00062    lsaCount = intraAreaPrefixLSAs.size();
00063    for (long k = 0; k < lsaCount; k++){
00064       delete intraAreaPrefixLSAs[k];
00065    }
00066    intraAreaPrefixLSAs.clear();
00067 }
00068 
00069 void AnsaOspf6::Area::AddInterface(AnsaOspf6::Interface* intf) {
00070    intf->SetArea(this);
00071    associatedInterfaces.push_back(intf);
00072 }
00073 
00074 Interface* AnsaOspf6::Area::GetInterfaceByIndex(unsigned int index) {
00075    if (index < associatedInterfaces.size()){
00076       return associatedInterfaces[index];
00077    }else{
00078       return NULL;
00079    }
00080 }
00081 
00082 void AnsaOspf6::Area::info(char *buffer) {
00083    std::stringstream out;
00084    char areaString[16];
00085    out << "areaID: " << areaID;
00086    strcpy(buffer, out.str().c_str());
00087 }
00088 
00089 std::string AnsaOspf6::Area::detailedInfo(void) const {
00090    std::stringstream out;
00091    char addressString[16];
00092    int i;
00093    out << "\n    areaID: " << areaID << ", ";
00094    out << "transitCapability: " << (transitCapability ? "true" : "false") << ", ";
00095    out << "externalRoutingCapability: " << (externalRoutingCapability ? "true" : "false") << ", ";
00096    out << "stubDefaultCost: " << stubDefaultCost << "\n";
00097    int addressPrefixNum = areaAddressPrefixes.size();
00098    for (i = 0; i < addressPrefixNum; i++) {
00099       out << "    addressPrefix[" << i << "]: ";
00100       out << areaAddressPrefixes[i].address;
00101       out << "/" << areaAddressPrefixes[i].prefixLen << "\n";
00102    }
00103    int interfaceNum = associatedInterfaces.size();
00104    for (i = 0; i < interfaceNum; i++) {
00105       out << "    interface[" << i << "]: link-local address: ";
00106       out << associatedInterfaces[i]->GetInterfaceAddress() << "\n";
00107    }
00108 
00109    out << "\n";
00110    out << "    Database:\n";
00111    out << "      RouterLSAs:\n";
00112    long lsaCount = routerLSAs.size();
00113    for (i = 0; i < lsaCount; i++) {
00114       out << "        " << *routerLSAs[i] << "\n";
00115    }
00116    out << "      NetworkLSAs:\n";
00117    lsaCount = networkLSAs.size();
00118    for (i = 0; i < lsaCount; i++) {
00119       out << "        " << *networkLSAs[i] << "\n";
00120    }
00121 
00122    out << "      InterAreaPrefixLSAs:\n";
00123    lsaCount = interAreaPrefixLSAs.size();
00124    for (i = 0; i < lsaCount; i++) {
00125       out << "        " << *interAreaPrefixLSAs[i] << "\n";
00126    }
00127 
00128    out << "      InterAreaRouterLSAs:\n";
00129    lsaCount = interAreaRouterLSAs.size();
00130    for (i = 0; i < lsaCount; i++) {
00131       out << "        " << *interAreaRouterLSAs[i] << "\n";
00132    }
00133 
00134    out << "      IntraAreaPrefixLSAs:\n";
00135    lsaCount = intraAreaPrefixLSAs.size();
00136    for (i = 0; i < lsaCount; i++) {
00137       out << "        " << *intraAreaPrefixLSAs[i] << "\n";
00138    }
00139 
00140    out << "--------------------------------------------------------------------------------";
00141 
00142    return out.str();
00143 }
00144 
00145 bool AnsaOspf6::Area::ContainsAddress(IPv6Address address) const {
00146    int addressPrefixesNum = areaAddressPrefixes.size();
00147    for (int i = 0; i < addressPrefixesNum; i++){
00148       if (address.matches(areaAddressPrefixes[i].address, areaAddressPrefixes[i].prefixLen)){
00149          return true;
00150       }
00151    }
00152    return false;
00153 }
00154 
00155 bool AnsaOspf6::Area::HasAddressPrefix(AnsaOspf6::IPv6AddressPrefix addressPrefix) const {
00156    int addressPrefixesNum = areaAddressPrefixes.size();
00157    for (int i = 0; i < addressPrefixesNum; i++){
00158       if (areaAddressPrefixes[i] == addressPrefix){
00159          return true;
00160       }
00161    }
00162    return false;
00163 }
00164 
00165 AnsaOspf6::IPv6AddressPrefix AnsaOspf6::Area::GetContainingAddressRange(AnsaOspf6::IPv6AddressPrefix addressPrefix, bool* advertise) const {
00166    int addressPrefixesNum = areaAddressPrefixes.size();
00167    for (int i = 0; i < addressPrefixesNum; i++){
00168       if ((addressPrefix == areaAddressPrefixes[i]) && (advertise != NULL)){
00169          std::map<AnsaOspf6::IPv6AddressPrefix, bool, AnsaOspf6::IPv6AddressPrefix_Less>::const_iterator prefixIt;
00170          prefixIt = advertiseAddressPrefixes.find(areaAddressPrefixes[i]);
00171          if (prefixIt != advertiseAddressPrefixes.end()){
00172             *advertise = prefixIt->second;
00173          }else{
00174             *advertise = true;
00175          }
00176          return areaAddressPrefixes[i];
00177       }
00178    }
00179    if (advertise != NULL){
00180       *advertise = false;
00181    }
00182    return AnsaOspf6::NullAddressPrefix;
00183 }
00184 
00185 AnsaOspf6::Interface* AnsaOspf6::Area::GetInterface(unsigned char ifIndex) {
00186    int interfaceNum = associatedInterfaces.size();
00187    for (int i = 0; i < interfaceNum; i++){
00188       if ((associatedInterfaces[i]->GetType() != AnsaOspf6::Interface::Virtual)
00189             && (associatedInterfaces[i]->GetIfIndex() == ifIndex)){
00190          return associatedInterfaces[i];
00191       }
00192    }
00193    return NULL;
00194 }
00195 
00196 AnsaOspf6::Interface* AnsaOspf6::Area::GetInterface(IPv6Address address) {
00197    int interfaceNum = associatedInterfaces.size();
00198    for (int i = 0; i < interfaceNum; i++){
00199       if (  (associatedInterfaces[i]->GetType() != AnsaOspf6::Interface::Virtual)
00200          && (associatedInterfaces[i]->GetInterfaceAddress() == address)){
00201          return associatedInterfaces[i];
00202       }
00203    }
00204    return NULL;
00205 }
00206 
00207 bool AnsaOspf6::Area::HasVirtualLink(AnsaOspf6::AreaID withTransitArea) const {
00208    if ((areaID != AnsaOspf6::BackboneAreaID) || (withTransitArea == AnsaOspf6::BackboneAreaID)){
00209       return false;
00210    }
00211 
00212    int interfaceNum = associatedInterfaces.size();
00213    for (int i = 0; i < interfaceNum; i++){
00214       if (  (associatedInterfaces[i]->GetType() == AnsaOspf6::Interface::Virtual)
00215          && (associatedInterfaces[i]->GetTransitAreaID() == withTransitArea)){
00216          return true;
00217       }
00218    }
00219    return false;
00220 }
00221 
00222 AnsaOspf6::Interface* AnsaOspf6::Area::FindVirtualLink(AnsaOspf6::RouterID routerID) {
00223    int interfaceNum = associatedInterfaces.size();
00224    for (int i = 0; i < interfaceNum; i++){
00225       if (  (associatedInterfaces[i]->GetType() == AnsaOspf6::Interface::Virtual)
00226          && (associatedInterfaces[i]->GetNeighborByID(routerID) != NULL)){
00227          return associatedInterfaces[i];
00228       }
00229    }
00230    return NULL;
00231 }
00232 
00233 
00234 bool AnsaOspf6::Area::InstallRouterLSA(OspfRouterLsa6* lsa){
00235    AnsaOspf6::LinkStateID linkStateID = lsa->getHeader().getLinkStateID();
00236    std::map<AnsaOspf6::LinkStateID, AnsaOspf6::RouterLsa*>::iterator lsaIt = routerLSAsByID.find(linkStateID);
00237    if (lsaIt != routerLSAsByID.end()){
00238       AnsaOspf6::LsaKeyType6 lsaKey;
00239 
00240       lsaKey.linkStateID = lsa->getHeader().getLinkStateID();
00241       lsaKey.advertisingRouter = lsa->getHeader().getAdvertisingRouter();
00242 
00243       RemoveFromAllRetransmissionLists(lsaKey);
00244       return lsaIt->second->Update(lsa);
00245    } else {
00246       AnsaOspf6::RouterLsa* lsaCopy = new AnsaOspf6::RouterLsa(*lsa);
00247       routerLSAsByID[linkStateID] = lsaCopy;
00248       routerLSAs.push_back(lsaCopy);
00249       return true;
00250    }
00251 }
00252 
00253 
00254 bool AnsaOspf6::Area::InstallNetworkLSA(OspfNetworkLsa6* lsa){
00255     AnsaOspf6::LinkStateID linkStateID = lsa->getHeader().getLinkStateID();
00256     std::map<AnsaOspf6::LinkStateID, AnsaOspf6::NetworkLsa*>::iterator lsaIt = networkLSAsByID.find(linkStateID);
00257     if (lsaIt != networkLSAsByID.end()) {
00258         AnsaOspf6::LsaKeyType6 lsaKey;
00259 
00260         lsaKey.linkStateID = lsa->getHeader().getLinkStateID();
00261         lsaKey.advertisingRouter = lsa->getHeader().getAdvertisingRouter();
00262 
00263         RemoveFromAllRetransmissionLists(lsaKey);
00264         return lsaIt->second->Update(lsa);
00265     } else {
00266         AnsaOspf6::NetworkLsa* lsaCopy = new AnsaOspf6::NetworkLsa(*lsa);
00267         networkLSAsByID[linkStateID] = lsaCopy;
00268         networkLSAs.push_back(lsaCopy);
00269         return true;
00270     }
00271 }
00272 
00273 bool AnsaOspf6::Area::InstallInterAreaPrefixLSA(OspfInterAreaPrefixLsa6* lsa){
00274    AnsaOspf6::LinkStateID linkStateID = lsa->getHeader().getLinkStateID();
00275    std::map<AnsaOspf6::LinkStateID, AnsaOspf6::InterAreaPrefixLsa*>::iterator lsaIt = interAreaPrefixLSAsByID.find(linkStateID);
00276    if (lsaIt != interAreaPrefixLSAsByID.end()) {
00277        AnsaOspf6::LsaKeyType6 lsaKey;
00278 
00279        lsaKey.linkStateID = lsa->getHeader().getLinkStateID();
00280        lsaKey.advertisingRouter = lsa->getHeader().getAdvertisingRouter();
00281 
00282        RemoveFromAllRetransmissionLists(lsaKey);
00283        return lsaIt->second->Update(lsa);
00284    } else {
00285        AnsaOspf6::InterAreaPrefixLsa* lsaCopy = new AnsaOspf6::InterAreaPrefixLsa(*lsa);
00286        interAreaPrefixLSAsByID[linkStateID] = lsaCopy;
00287        interAreaPrefixLSAs.push_back(lsaCopy);
00288        return true;
00289    }
00290 }
00291 
00292 bool AnsaOspf6::Area::InstallInterAreaRouterLSA(OspfInterAreaRouterLsa6* lsa){
00293    AnsaOspf6::LinkStateID linkStateID = lsa->getHeader().getLinkStateID();
00294    std::map<AnsaOspf6::LinkStateID, AnsaOspf6::InterAreaRouterLsa*>::iterator lsaIt = interAreaRouterLSAsByID.find(linkStateID);
00295    if (lsaIt != interAreaRouterLSAsByID.end()) {
00296        AnsaOspf6::LsaKeyType6 lsaKey;
00297 
00298        lsaKey.linkStateID = lsa->getHeader().getLinkStateID();
00299        lsaKey.advertisingRouter = lsa->getHeader().getAdvertisingRouter();
00300 
00301        RemoveFromAllRetransmissionLists(lsaKey);
00302        return lsaIt->second->Update(lsa);
00303    } else {
00304        AnsaOspf6::InterAreaRouterLsa* lsaCopy = new AnsaOspf6::InterAreaRouterLsa(*lsa);
00305        interAreaRouterLSAsByID[linkStateID] = lsaCopy;
00306        interAreaRouterLSAs.push_back(lsaCopy);
00307        return true;
00308    }
00309 }
00310 
00311 bool AnsaOspf6::Area::InstallIntraAreaPrefixLSA(OspfIntraAreaPrefixLsa6* lsa){
00312    AnsaOspf6::LinkStateID linkStateID = lsa->getHeader().getLinkStateID();
00313    std::map<AnsaOspf6::LinkStateID, AnsaOspf6::IntraAreaPrefixLsa*>::iterator lsaIt = intraAreaPrefixLSAsByID.find(linkStateID);
00314    if (lsaIt != intraAreaPrefixLSAsByID.end()) {
00315        AnsaOspf6::LsaKeyType6 lsaKey;
00316 
00317        lsaKey.linkStateID = lsa->getHeader().getLinkStateID();
00318        lsaKey.advertisingRouter = lsa->getHeader().getAdvertisingRouter();
00319 
00320        RemoveFromAllRetransmissionLists(lsaKey);
00321        return lsaIt->second->Update(lsa);
00322    } else {
00323        AnsaOspf6::IntraAreaPrefixLsa* lsaCopy = new AnsaOspf6::IntraAreaPrefixLsa(*lsa);
00324        intraAreaPrefixLSAsByID[linkStateID] = lsaCopy;
00325        intraAreaPrefixLSAs.push_back(lsaCopy);
00326        return true;
00327    }
00328 }
00329 
00330 
00331 AnsaOspf6::RouterLsa* AnsaOspf6::Area::FindRouterLSA(AnsaOspf6::LinkStateID linkStateID){
00332    std::map<AnsaOspf6::LinkStateID, AnsaOspf6::RouterLsa*>::iterator lsaIt = routerLSAsByID.find(linkStateID);
00333    if (lsaIt != routerLSAsByID.end()){
00334       return lsaIt->second;
00335    }else{
00336       return NULL;
00337    }
00338 }
00339 
00340 const AnsaOspf6::RouterLsa* AnsaOspf6::Area::FindRouterLSA(AnsaOspf6::LinkStateID linkStateID) const {
00341    return FindRouterLSA(linkStateID);
00342 }
00343 
00344 AnsaOspf6::NetworkLsa* AnsaOspf6::Area::FindNetworkLSA(AnsaOspf6::LinkStateID linkStateID){
00345    std::map<AnsaOspf6::LinkStateID, AnsaOspf6::NetworkLsa*>::iterator lsaIt = networkLSAsByID.find(linkStateID);
00346    if (lsaIt != networkLSAsByID.end()) {
00347       return lsaIt->second;
00348    } else {
00349       return NULL;
00350    }
00351 }
00352 
00353 const AnsaOspf6::NetworkLsa* AnsaOspf6::Area::FindNetworkLSA(AnsaOspf6::LinkStateID linkStateID) const {
00354    return FindNetworkLSA(linkStateID);
00355 }
00356 
00357 AnsaOspf6::InterAreaPrefixLsa* AnsaOspf6::Area::FindInterAreaPrefixLSA(AnsaOspf6::LinkStateID linkStateID){
00358    std::map<AnsaOspf6::LinkStateID, AnsaOspf6::InterAreaPrefixLsa*>::iterator lsaIt = interAreaPrefixLSAsByID.find(linkStateID);
00359    if (lsaIt != interAreaPrefixLSAsByID.end()) {
00360       return lsaIt->second;
00361    } else {
00362       return NULL;
00363    }
00364 }
00365 
00366 const AnsaOspf6::InterAreaPrefixLsa* AnsaOspf6::Area::FindInterAreaPrefixLSA(AnsaOspf6::LinkStateID linkStateID) const {
00367    return FindInterAreaPrefixLSA(linkStateID);
00368 }
00369 
00370 AnsaOspf6::InterAreaRouterLsa* AnsaOspf6::Area::FindInterAreaRouterLSA(AnsaOspf6::LinkStateID linkStateID){
00371    std::map<AnsaOspf6::LinkStateID, AnsaOspf6::InterAreaRouterLsa*>::iterator lsaIt = interAreaRouterLSAsByID.find(linkStateID);
00372    if (lsaIt != interAreaRouterLSAsByID.end()) {
00373       return lsaIt->second;
00374    } else {
00375       return NULL;
00376    }
00377 }
00378 
00379 const AnsaOspf6::InterAreaRouterLsa* AnsaOspf6::Area::FindInterAreaRouterLSA(AnsaOspf6::LinkStateID linkStateID) const {
00380    return FindInterAreaRouterLSA(linkStateID);
00381 }
00382 
00383 AnsaOspf6::IntraAreaPrefixLsa* AnsaOspf6::Area::FindIntraAreaPrefixLSA(AnsaOspf6::LinkStateID linkStateID){
00384    std::map<AnsaOspf6::LinkStateID, AnsaOspf6::IntraAreaPrefixLsa*>::iterator lsaIt = intraAreaPrefixLSAsByID.find(linkStateID);
00385    if (lsaIt != intraAreaPrefixLSAsByID.end()) {
00386       return lsaIt->second;
00387    } else {
00388       return NULL;
00389    }
00390 }
00391 
00392 const AnsaOspf6::IntraAreaPrefixLsa* AnsaOspf6::Area::FindIntraAreaPrefixLSA(AnsaOspf6::LinkStateID linkStateID) const {
00393    return FindIntraAreaPrefixLSA(linkStateID);
00394 }
00395 
00396 
00397 void AnsaOspf6::Area::RemoveParentFromRoutingInfo(OspfLsa6* parent) {
00398 
00399    long lsaCount = routerLSAs.size();
00400    long i;
00401 
00402    for (i = 0; i < lsaCount; i++){
00403       if (routerLSAs[i] != NULL){
00404          AnsaOspf6::RouterLsa* routerLSA = routerLSAs[i];
00405          AnsaOspf6::RoutingInfo* routingInfo = check_and_cast<AnsaOspf6::RoutingInfo*> (routerLSA);
00406 
00407          if (routingInfo->GetParent() == parent)
00408             routingInfo->SetParent(NULL);
00409       }
00410    }
00411 
00412    lsaCount = networkLSAs.size();
00413 
00414    for (i = 0; i < lsaCount; i++){
00415       if (networkLSAs[i] != NULL){
00416          AnsaOspf6::NetworkLsa* networkLSA = networkLSAs[i];
00417          AnsaOspf6::RoutingInfo* routingInfo = check_and_cast<AnsaOspf6::RoutingInfo*> (networkLSA);
00418 
00419          if (routingInfo->GetParent() == parent)
00420             routingInfo->SetParent(NULL);
00421       }
00422    }
00423 
00424    lsaCount = interAreaPrefixLSAs.size();
00425 
00426    for (i = 0; i < lsaCount; i++){
00427       if (interAreaPrefixLSAs[i] != NULL){
00428          AnsaOspf6::InterAreaPrefixLsa* interAreaPrefixLSA = interAreaPrefixLSAs[i];
00429          AnsaOspf6::RoutingInfo* routingInfo = check_and_cast<AnsaOspf6::RoutingInfo*> (interAreaPrefixLSA);
00430 
00431          if (routingInfo->GetParent() == parent)
00432             routingInfo->SetParent(NULL);
00433       }
00434    }
00435 
00436    lsaCount = interAreaRouterLSAs.size();
00437 
00438    for (i = 0; i < lsaCount; i++){
00439       if (interAreaRouterLSAs[i] != NULL){
00440          AnsaOspf6::InterAreaRouterLsa* interAreaRouterLSA = interAreaRouterLSAs[i];
00441          AnsaOspf6::RoutingInfo* routingInfo = check_and_cast<AnsaOspf6::RoutingInfo*> (interAreaRouterLSA);
00442 
00443          if (routingInfo->GetParent() == parent)
00444             routingInfo->SetParent(NULL);
00445       }
00446    }
00447 
00448    lsaCount = intraAreaPrefixLSAs.size();
00449 
00450    for (i = 0; i < lsaCount; i++){
00451       if (intraAreaPrefixLSAs[i] != NULL){
00452          AnsaOspf6::IntraAreaPrefixLsa* intraAreaPrefixLSA = intraAreaPrefixLSAs[i];
00453          AnsaOspf6::RoutingInfo* routingInfo = check_and_cast<AnsaOspf6::RoutingInfo*> (intraAreaPrefixLSA);
00454 
00455          if (routingInfo->GetParent() == parent)
00456             routingInfo->SetParent(NULL);
00457       }
00458    }
00459 }
00460 
00461 
00462 void AnsaOspf6::Area::AgeDatabase(void) {
00463    /*
00464    bool rebuildRoutingTable = false;
00465    long i;
00466 
00467    RouterID routerId = GetRouter()->GetRouterID();
00468    EV << IPAddress(routerId);
00469 
00470    long lsaCount = routerLSAs.size();
00471    for (i = 0; i < lsaCount; i++){
00472       unsigned short lsAge = routerLSAs[i]->getHeader().getLsAge();
00473       bool selfOriginated = (routerLSAs[i]->getHeader().getAdvertisingRouter() == parentRouter->GetRouterID());
00474       bool unreachable = parentRouter->IsDestinationUnreachable(routerLSAs[i]);
00475       AnsaOspf6::RouterLsa* lsa = routerLSAs[i];
00476 
00477       unsigned int linkCount = lsa->getLinksArraySize();
00478       for (unsigned int j = 0; j < linkCount; j++) {
00479          const Link6& link = lsa->getLinks(j);
00480          printLsaLink(link, ev.getOStream());
00481         }
00482 
00483         if (   (selfOriginated && (lsAge < (LS_REFRESH_TIME - 1)))
00484             || (!selfOriginated && (lsAge < (MAX_AGE - 1)))) {
00485             lsa->getHeader().setLsAge(lsAge + 1);
00486             lsa->IncrementInstallTime();
00487         }
00488 
00489         if (selfOriginated && (lsAge == (LS_REFRESH_TIME - 1))){
00490            if (unreachable) {
00491               lsa->getHeader().setLsAge(MAX_AGE);
00492               FloodLSA(lsa);
00493               lsa->IncrementInstallTime();
00494            }else{
00495               long sequenceNumber = lsa->getHeader().getLsSequenceNumber();
00496               if (sequenceNumber == MAX_SEQUENCE_NUMBER) {
00497                  lsa->getHeader().setLsAge(MAX_AGE);
00498                  FloodLSA(lsa);
00499                  lsa->IncrementInstallTime();
00500               }else{
00501                  AnsaOspf6::RouterLsa* newLSA = OriginateRouterLSA();
00502 
00503                  newLSA->getHeader().setLsSequenceNumber(sequenceNumber + 1);
00504                  rebuildRoutingTable |= lsa->Update(newLSA);
00505                  delete newLSA;
00506 
00507                  FloodLSA(lsa);
00508               }
00509            }
00510         }
00511 
00512         if (!selfOriginated && (lsAge == MAX_AGE - 1)) {
00513            lsa->getHeader().setLsAge(MAX_AGE);
00514            FloodLSA(lsa);
00515            lsa->IncrementInstallTime();
00516         }
00517 
00518         if (lsAge == MAX_AGE) {
00519            AnsaOspf6::LsaKeyType6 lsaKey;
00520 
00521            lsaKey.linkStateID = lsa->getHeader().getLinkStateID();
00522            lsaKey.advertisingRouter = lsa->getHeader().getAdvertisingRouter();
00523 
00524            if (   !IsOnAnyRetransmissionList(lsaKey)
00525               &&  !HasAnyNeighborInStates(AnsaOspf6::Neighbor::ExchangeState | AnsaOspf6::Neighbor::LoadingState)){
00526 
00527               if (!selfOriginated || unreachable) {
00528                  routerLSAsByID.erase(lsa->getHeader().getLinkStateID());
00529                  delete lsa;
00530                  routerLSAs[i] = NULL;
00531                  rebuildRoutingTable = true;
00532               }else{
00533                  AnsaOspf6::RouterLsa* newLSA = OriginateRouterLSA();
00534                  long sequenceNumber = lsa->getHeader().getLsSequenceNumber();
00535 
00536                  newLSA->getHeader().setLsSequenceNumber((sequenceNumber == MAX_SEQUENCE_NUMBER) ? INITIAL_SEQUENCE_NUMBER : sequenceNumber + 1);
00537                  rebuildRoutingTable |= lsa->Update(newLSA);
00538                  delete newLSA;
00539 
00540                  FloodLSA(lsa);
00541               }
00542            }
00543         }
00544    }
00545 
00546 
00547     std::vector<RouterLsa*>::iterator routerIt = routerLSAs.begin();
00548     while (routerIt != routerLSAs.end()) {
00549        if ((*routerIt) == NULL) {
00550           routerIt = routerLSAs.erase(routerIt);
00551        }else{
00552           routerIt++;
00553        }
00554     }
00555 
00556     lsaCount = networkLSAs.size();
00557     for (i = 0; i < lsaCount; i++) {
00558         unsigned short    lsAge          = networkLSAs[i]->getHeader().getLsAge();
00559         bool              unreachable    = parentRouter->IsDestinationUnreachable(networkLSAs[i]);
00560         AnsaOspf6::NetworkLSA* lsa            = networkLSAs[i];
00561         AnsaOspf6::Interface*  localIntf      = GetInterface(IPv4AddressFromULong(lsa->getHeader().getLinkStateID()));
00562         bool              selfOriginated = false;
00563 
00564 
00565         if ((localIntf != NULL) &&
00566             (localIntf->GetState() == AnsaOspf6::Interface::DesignatedRouterState) &&
00567             (localIntf->GetNeighborCount() > 0) &&
00568             (localIntf->HasAnyNeighborInStates(AnsaOspf6::Neighbor::FullState)))
00569         {
00570             selfOriginated = true;
00571         }
00572 
00573         if ((selfOriginated && (lsAge < (LS_REFRESH_TIME - 1))) || (!selfOriginated && (lsAge < (MAX_AGE - 1)))) {
00574             lsa->getHeader().setLsAge(lsAge + 1);
00575             if ((lsAge + 1) % CHECK_AGE == 0) {
00576                 if (!lsa->ValidateLSChecksum()) {
00577                     EV << "Invalid LS checksum. Memory error detected!\n";
00578                 }
00579             }
00580             lsa->IncrementInstallTime();
00581         }
00582         if (selfOriginated && (lsAge == (LS_REFRESH_TIME - 1))) {
00583             if (unreachable) {
00584                 lsa->getHeader().setLsAge(MAX_AGE);
00585                 FloodLSA(lsa);
00586                 lsa->IncrementInstallTime();
00587             } else {
00588                 long sequenceNumber = lsa->getHeader().getLsSequenceNumber();
00589                 if (sequenceNumber == MAX_SEQUENCE_NUMBER) {
00590                     lsa->getHeader().setLsAge(MAX_AGE);
00591                     FloodLSA(lsa);
00592                     lsa->IncrementInstallTime();
00593                 } else {
00594                     AnsaOspf6::NetworkLSA* newLSA = OriginateNetworkLSA(localIntf);
00595 
00596                     if (newLSA != NULL) {
00597                         newLSA->getHeader().setLsSequenceNumber(sequenceNumber + 1);
00598                         newLSA->getHeader().setLsChecksum(0);    // TODO: calculate correct LS checksum
00599                         rebuildRoutingTable |= lsa->Update(newLSA);
00600                         delete newLSA;
00601                     } else {    // no neighbors on the network -> old NetworkLSA must be flushed
00602                         lsa->getHeader().setLsAge(MAX_AGE);
00603                         lsa->IncrementInstallTime();
00604                     }
00605 
00606                     FloodLSA(lsa);
00607                 }
00608             }
00609         }
00610         if (!selfOriginated && (lsAge == MAX_AGE - 1)) {
00611             lsa->getHeader().setLsAge(MAX_AGE);
00612             FloodLSA(lsa);
00613             lsa->IncrementInstallTime();
00614         }
00615         if (lsAge == MAX_AGE) {
00616             AnsaOspf6::LSAKeyType lsaKey;
00617 
00618             lsaKey.linkStateID = lsa->getHeader().getLinkStateID();
00619             lsaKey.advertisingRouter = lsa->getHeader().getAdvertisingRouter().getInt();
00620 
00621             if (!IsOnAnyRetransmissionList(lsaKey) &&
00622                 !HasAnyNeighborInStates(AnsaOspf6::Neighbor::ExchangeState | AnsaOspf6::Neighbor::LoadingState))
00623             {
00624                 if (!selfOriginated || unreachable) {
00625                     networkLSAsByID.erase(lsa->getHeader().getLinkStateID());
00626                     RemoveParentFromRoutingInfo(check_and_cast<OSPFLSA*> (lsa));
00627                     delete lsa;
00628                     networkLSAs[i] = NULL;
00629                     rebuildRoutingTable = true;
00630                 } else {
00631                     AnsaOspf6::NetworkLSA* newLSA              = OriginateNetworkLSA(localIntf);
00632                     long              sequenceNumber      = lsa->getHeader().getLsSequenceNumber();
00633 
00634                     if (newLSA != NULL) {
00635                         newLSA->getHeader().setLsSequenceNumber((sequenceNumber == MAX_SEQUENCE_NUMBER) ? INITIAL_SEQUENCE_NUMBER : sequenceNumber + 1);
00636                         newLSA->getHeader().setLsChecksum(0);    // TODO: calculate correct LS checksum
00637                         rebuildRoutingTable |= lsa->Update(newLSA);
00638                         delete newLSA;
00639 
00640                         FloodLSA(lsa);
00641                     } else {    // no neighbors on the network -> old NetworkLSA must be deleted
00642                         delete networkLSAs[i];
00643                     }
00644                 }
00645             }
00646         }
00647     }
00648     std::vector<NetworkLSA*>::iterator networkIt = networkLSAs.begin();
00649     while (networkIt != networkLSAs.end()) {
00650         if ((*networkIt) == NULL) {
00651             networkIt = networkLSAs.erase(networkIt);
00652         } else {
00653             networkIt++;
00654         }
00655     }
00656 
00657     lsaCount = summaryLSAs.size();
00658     for (i = 0; i < lsaCount; i++) {
00659         unsigned short    lsAge          = summaryLSAs[i]->getHeader().getLsAge();
00660         bool              selfOriginated = (summaryLSAs[i]->getHeader().getAdvertisingRouter().getInt() == parentRouter->GetRouterID());
00661         bool              unreachable    = parentRouter->IsDestinationUnreachable(summaryLSAs[i]);
00662         AnsaOspf6::SummaryLSA* lsa            = summaryLSAs[i];
00663 
00664 
00665         if ((selfOriginated && (lsAge < (LS_REFRESH_TIME - 1))) || (!selfOriginated && (lsAge < (MAX_AGE - 1)))) {
00666             lsa->getHeader().setLsAge(lsAge + 1);
00667             if ((lsAge + 1) % CHECK_AGE == 0) {
00668                 if (!lsa->ValidateLSChecksum()) {
00669                     EV << "Invalid LS checksum. Memory error detected!\n";
00670                 }
00671             }
00672             lsa->IncrementInstallTime();
00673         }
00674         if (selfOriginated && (lsAge == (LS_REFRESH_TIME - 1))) {
00675             if (unreachable) {
00676                 lsa->getHeader().setLsAge(MAX_AGE);
00677                 FloodLSA(lsa);
00678                 lsa->IncrementInstallTime();
00679             } else {
00680                 long sequenceNumber = lsa->getHeader().getLsSequenceNumber();
00681                 if (sequenceNumber == MAX_SEQUENCE_NUMBER) {
00682                     lsa->getHeader().setLsAge(MAX_AGE);
00683                     FloodLSA(lsa);
00684                     lsa->IncrementInstallTime();
00685                 } else {
00686                     AnsaOspf6::SummaryLSA* newLSA = OriginateSummaryLSA(lsa);
00687 
00688                     if (newLSA != NULL) {
00689                         newLSA->getHeader().setLsSequenceNumber(sequenceNumber + 1);
00690                         newLSA->getHeader().setLsChecksum(0);    // TODO: calculate correct LS checksum
00691                         rebuildRoutingTable |= lsa->Update(newLSA);
00692                         delete newLSA;
00693 
00694                         FloodLSA(lsa);
00695                     } else {
00696                         lsa->getHeader().setLsAge(MAX_AGE);
00697                         FloodLSA(lsa);
00698                         lsa->IncrementInstallTime();
00699                     }
00700                 }
00701             }
00702         }
00703         if (!selfOriginated && (lsAge == MAX_AGE - 1)) {
00704             lsa->getHeader().setLsAge(MAX_AGE);
00705             FloodLSA(lsa);
00706             lsa->IncrementInstallTime();
00707         }
00708         if (lsAge == MAX_AGE) {
00709             AnsaOspf6::LSAKeyType lsaKey;
00710 
00711             lsaKey.linkStateID = lsa->getHeader().getLinkStateID();
00712             lsaKey.advertisingRouter = lsa->getHeader().getAdvertisingRouter().getInt();
00713 
00714             if (!IsOnAnyRetransmissionList(lsaKey) &&
00715                 !HasAnyNeighborInStates(AnsaOspf6::Neighbor::ExchangeState | AnsaOspf6::Neighbor::LoadingState))
00716             {
00717                 if (!selfOriginated || unreachable) {
00718                     summaryLSAsByID.erase(lsaKey);
00719                     delete lsa;
00720                     summaryLSAs[i] = NULL;
00721                     rebuildRoutingTable = true;
00722                 } else {
00723                     AnsaOspf6::SummaryLSA* newLSA = OriginateSummaryLSA(lsa);
00724                     if (newLSA != NULL) {
00725                         long sequenceNumber = lsa->getHeader().getLsSequenceNumber();
00726 
00727                         newLSA->getHeader().setLsSequenceNumber((sequenceNumber == MAX_SEQUENCE_NUMBER) ? INITIAL_SEQUENCE_NUMBER : sequenceNumber + 1);
00728                         newLSA->getHeader().setLsChecksum(0);    // TODO: calculate correct LS checksum
00729                         rebuildRoutingTable |= lsa->Update(newLSA);
00730                         delete newLSA;
00731 
00732                         FloodLSA(lsa);
00733                     } else {
00734                         summaryLSAsByID.erase(lsaKey);
00735                         delete lsa;
00736                         summaryLSAs[i] = NULL;
00737                         rebuildRoutingTable = true;
00738                     }
00739                 }
00740             }
00741         }
00742     }
00743 
00744     std::vector<SummaryLSA*>::iterator summaryIt = summaryLSAs.begin();
00745     while (summaryIt != summaryLSAs.end()) {
00746         if ((*summaryIt) == NULL) {
00747             summaryIt = summaryLSAs.erase(summaryIt);
00748         } else {
00749             summaryIt++;
00750         }
00751     }
00752 
00753 
00754     long interfaceCount = associatedInterfaces.size();
00755     for (long m = 0; m < interfaceCount; m++) {
00756         associatedInterfaces[m]->AgeTransmittedLSALists();
00757     }
00758 
00759     if (rebuildRoutingTable) {
00760         parentRouter->RebuildRoutingTable();
00761     }
00762     */
00763 }
00764 
00765 
00766 bool AnsaOspf6::Area::HasAnyNeighborInStates(int states) const {
00767    long interfaceCount = associatedInterfaces.size();
00768    for (long i = 0; i < interfaceCount; i++){
00769       if (associatedInterfaces[i]->HasAnyNeighborInStates(states)){
00770          return true;
00771       }
00772    }
00773    return false;
00774 }
00775 
00776 void AnsaOspf6::Area::RemoveFromAllRetransmissionLists(AnsaOspf6::LsaKeyType6 lsaKey) {
00777    long interfaceCount = associatedInterfaces.size();
00778    for (long i = 0; i < interfaceCount; i++){
00779       associatedInterfaces[i]->RemoveFromAllRetransmissionLists(lsaKey);
00780    }
00781 }
00782 
00783 bool AnsaOspf6::Area::IsOnAnyRetransmissionList(AnsaOspf6::LsaKeyType6 lsaKey) const {
00784    long interfaceCount = associatedInterfaces.size();
00785    for (long i = 0; i < interfaceCount; i++){
00786       if (associatedInterfaces[i]->IsOnAnyRetransmissionList(lsaKey)){
00787          return true;
00788       }
00789    }
00790    return false;
00791 }
00792 
00793 bool AnsaOspf6::Area::FloodLSA(OspfLsa6* lsa, AnsaOspf6::Interface* intf, AnsaOspf6::Neighbor* neighbor){
00794    bool floodedBackOut  = false;
00795    long interfaceCount = associatedInterfaces.size();
00796 
00797    for (long i = 0; i < interfaceCount; i++) {
00798       if (associatedInterfaces[i]->FloodLSA(lsa, intf, neighbor)) {
00799          floodedBackOut = true;
00800       }
00801    }
00802 
00803    return floodedBackOut;
00804 }
00805 
00806 
00807 AnsaOspf6::RouterLsa* AnsaOspf6::Area::OriginateRouterLSA(void){
00808 
00809 }
00810 
00811 AnsaOspf6::NetworkLsa* AnsaOspf6::Area::OriginateNetworkLSA(const AnsaOspf6::Interface* intf){
00812 
00813 }