|
INET Framework for OMNeT++/OMNEST
|
00001 // 00002 // Copyright (C) 2006 Andras Babos and Andras Varga 00003 // 00004 // This program is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public License 00006 // as published by the Free Software Foundation; either version 2 00007 // of the License, or (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU Lesser General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU Lesser General Public License 00015 // along with this program; if not, see <http://www.gnu.org/licenses/>. 00016 // 00017 00018 #include "LinkStateRequestHandler.h" 00019 #include "OSPFNeighbor.h" 00020 #include "OSPFRouter.h" 00021 #include <vector> 00022 00023 OSPF::LinkStateRequestHandler::LinkStateRequestHandler(OSPF::Router* containingRouter) : 00024 OSPF::IMessageHandler(containingRouter) 00025 { 00026 } 00027 00028 void OSPF::LinkStateRequestHandler::ProcessPacket(OSPFPacket* packet, OSPF::Interface* intf, OSPF::Neighbor* neighbor) 00029 { 00030 router->GetMessageHandler()->PrintEvent("Link State Request packet received", intf, neighbor); 00031 00032 OSPF::Neighbor::NeighborStateType neighborState = neighbor->GetState(); 00033 00034 if ((neighborState == OSPF::Neighbor::ExchangeState) || 00035 (neighborState == OSPF::Neighbor::LoadingState) || 00036 (neighborState == OSPF::Neighbor::FullState)) 00037 { 00038 OSPFLinkStateRequestPacket* lsRequestPacket = check_and_cast<OSPFLinkStateRequestPacket*> (packet); 00039 00040 unsigned long requestCount = lsRequestPacket->getRequestsArraySize(); 00041 bool error = false; 00042 std::vector<OSPFLSA*> lsas; 00043 00044 EV << " Processing packet contents:\n"; 00045 00046 for (unsigned long i = 0; i < requestCount; i++) { 00047 LSARequest& request = lsRequestPacket->getRequests(i); 00048 OSPF::LSAKeyType lsaKey; 00049 char addressString[16]; 00050 00051 EV << " LSARequest: type=" 00052 << request.lsType 00053 << ", LSID=" 00054 << AddressStringFromULong(addressString, sizeof(addressString), request.linkStateID) 00055 << ", advertisingRouter=" 00056 << AddressStringFromULong(addressString, sizeof(addressString), request.advertisingRouter.getInt()) 00057 << "\n"; 00058 00059 lsaKey.linkStateID = request.linkStateID; 00060 lsaKey.advertisingRouter = request.advertisingRouter.getInt(); 00061 00062 OSPFLSA* lsaInDatabase = router->FindLSA(static_cast<LSAType> (request.lsType), lsaKey, intf->GetArea()->GetAreaID()); 00063 00064 if (lsaInDatabase != NULL) { 00065 lsas.push_back(lsaInDatabase); 00066 } else { 00067 error = true; 00068 neighbor->ProcessEvent(OSPF::Neighbor::BadLinkStateRequest); 00069 break; 00070 } 00071 } 00072 00073 if (!error) { 00074 int updatesCount = lsas.size(); 00075 int ttl = (intf->GetType() == OSPF::Interface::Virtual) ? VIRTUAL_LINK_TTL : 1; 00076 OSPF::MessageHandler* messageHandler = router->GetMessageHandler(); 00077 00078 for (int j = 0; j < updatesCount; j++) { 00079 OSPFLinkStateUpdatePacket* updatePacket = intf->CreateUpdatePacket(lsas[j]); 00080 if (updatePacket != NULL) { 00081 if (intf->GetType() == OSPF::Interface::Broadcast) { 00082 if ((intf->GetState() == OSPF::Interface::DesignatedRouterState) || 00083 (intf->GetState() == OSPF::Interface::BackupState) || 00084 (intf->GetDesignatedRouter() == OSPF::NullDesignatedRouterID)) 00085 { 00086 messageHandler->SendPacket(updatePacket, OSPF::AllSPFRouters, intf->GetIfIndex(), ttl); 00087 } else { 00088 messageHandler->SendPacket(updatePacket, OSPF::AllDRouters, intf->GetIfIndex(), ttl); 00089 } 00090 } else { 00091 if (intf->GetType() == OSPF::Interface::PointToPoint) { 00092 messageHandler->SendPacket(updatePacket, OSPF::AllSPFRouters, intf->GetIfIndex(), ttl); 00093 } else { 00094 messageHandler->SendPacket(updatePacket, neighbor->GetAddress(), intf->GetIfIndex(), ttl); 00095 } 00096 } 00097 00098 } 00099 } 00100 // These update packets should not be placed on retransmission lists 00101 } 00102 } 00103 }