INET Framework for OMNeT++/OMNEST
ansaLinkStateRequestHandler6.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 "ansaOspfNeighbor6.h"
00017 #include "ansaOspfRouter6.h"
00018 
00019 #include "ansaLinkStateRequestHandler6.h"
00020 
00021 AnsaOspf6::LinkStateRequestHandler::LinkStateRequestHandler(AnsaOspf6::Router* containingRouter) :
00022    AnsaOspf6::IMessageHandler(containingRouter) {
00023 }
00024 
00025 void AnsaOspf6::LinkStateRequestHandler::ProcessPacket(OspfPacket6* packet,
00026       AnsaOspf6::Interface* intf, AnsaOspf6::Neighbor* neighbor) {
00027 
00028    router->GetMessageHandler()->PrintEvent("Link State Request packet received", intf, neighbor);
00029 
00030    AnsaOspf6::Neighbor::NeighborStateType neighborState = neighbor->GetState();
00031 
00032    if ((neighborState == AnsaOspf6::Neighbor::ExchangeState) || (neighborState
00033          == AnsaOspf6::Neighbor::LoadingState) || (neighborState == AnsaOspf6::Neighbor::FullState)){
00034       OspfLinkStateRequestPacket6* lsRequestPacket = check_and_cast<OspfLinkStateRequestPacket6*> (packet);
00035 
00036       unsigned long requestCount = lsRequestPacket->getRequestsArraySize();
00037       bool error = false;
00038       std::vector<OspfLsa6*> lsas;
00039 
00040       EV<< "  Processing packet contents:\n";
00041 
00042       for (unsigned long i = 0; i < requestCount; i++){
00043          OspfLsaRequest6& request = lsRequestPacket->getRequests(i);
00044          AnsaOspf6::LsaKeyType6 lsaKey;
00045          char addressString[16];
00046 
00047          EV << "    LSARequest: type="
00048          << request.lsType
00049          << ", LSID="
00050          << request.linkStateID
00051          << ", advertisingRouter="
00052          << IPAddress(request.advertisingRouter) << endl;
00053 
00054          lsaKey.linkStateID = request.linkStateID;
00055          lsaKey.advertisingRouter = request.advertisingRouter;
00056 
00057          OspfLsa6* lsaInDatabase = router->FindLSA(static_cast<LsaType6> (request.lsType), lsaKey, intf->GetArea()->GetAreaID());
00058 
00059          if (lsaInDatabase != NULL){
00060             lsas.push_back(lsaInDatabase);
00061          }else{
00062             error = true;
00063             neighbor->ProcessEvent(AnsaOspf6::Neighbor::BadLinkStateRequest);
00064             break;
00065          }
00066       }
00067 
00068       if (!error){
00069          int updatesCount = lsas.size();
00070          int ttl          = (intf->GetType() == AnsaOspf6::Interface::Virtual) ? VIRTUAL_LINK_TTL : 1;
00071          AnsaOspf6::MessageHandler* messageHandler = router->GetMessageHandler();
00072 
00073          for (int j = 0; j < updatesCount; j++) {
00074             OspfLinkStateUpdatePacket6* updatePacket = intf->CreateUpdatePacket(lsas[j]);
00075             if (updatePacket != NULL) {
00076                if (intf->GetType() == AnsaOspf6::Interface::Broadcast) {
00077                   if ((intf->GetState() == AnsaOspf6::Interface::DesignatedRouterState) ||
00078                         (intf->GetState() == AnsaOspf6::Interface::BackupState) ||
00079                         (intf->GetDesignatedRouter() == AnsaOspf6::NullDesignatedRouterID))
00080                   {
00081                      messageHandler->SendPacket(updatePacket, AnsaOspf6::AllSPFRouters, intf->GetIfIndex(), ttl);
00082                   }else{
00083                      messageHandler->SendPacket(updatePacket, AnsaOspf6::AllDRouters, intf->GetIfIndex(), ttl);
00084                   }
00085                }else{
00086                   if (intf->GetType() == AnsaOspf6::Interface::PointToPoint) {
00087                      messageHandler->SendPacket(updatePacket, AnsaOspf6::AllSPFRouters, intf->GetIfIndex(), ttl);
00088                   }else{
00089                      messageHandler->SendPacket(updatePacket, neighbor->GetAddress(), intf->GetIfIndex(), ttl);
00090                   }
00091                }
00092 
00093             }
00094          }
00095       }
00096    }
00097 }