#include <MessageHandler.h>
Inheritance diagram for OSPF::MessageHandler:
Public Member Functions | |
MessageHandler (Router *containingRouter, cSimpleModule *containingModule) | |
void | MessageReceived (cMessage *message) |
void | HandleTimer (OSPFTimer *timer) |
void | ProcessPacket (OSPFPacket *packet, Interface *unused1=NULL, Neighbor *unused2=NULL) |
void | SendPacket (OSPFPacket *packet, IPv4Address destination, int outputIfIndex, short ttl=1) |
void | ClearTimer (OSPFTimer *timer) |
void | StartTimer (OSPFTimer *timer, simtime_t delay) |
void | PrintEvent (const char *eventString, const Interface *onInterface=NULL, const Neighbor *forNeighbor=NULL) const |
void | PrintHelloPacket (const OSPFHelloPacket *helloPacket, IPv4Address destination, int outputIfIndex) const |
void | PrintDatabaseDescriptionPacket (const OSPFDatabaseDescriptionPacket *ddPacket, IPv4Address destination, int outputIfIndex) const |
void | PrintLinkStateRequestPacket (const OSPFLinkStateRequestPacket *requestPacket, IPv4Address destination, int outputIfIndex) const |
void | PrintLinkStateUpdatePacket (const OSPFLinkStateUpdatePacket *updatePacket, IPv4Address destination, int outputIfIndex) const |
void | PrintLinkStateAcknowledgementPacket (const OSPFLinkStateAcknowledgementPacket *ackPacket, IPv4Address destination, int outputIfIndex) const |
bool | AuthenticatePacket (OSPFPacket *packet) |
Private Attributes | |
cSimpleModule * | ospfModule |
HelloHandler | helloHandler |
DatabaseDescriptionHandler | ddHandler |
LinkStateRequestHandler | lsRequestHandler |
LinkStateUpdateHandler | lsUpdateHandler |
LinkStateAcknowledgementHandler | lsAckHandler |
|
00004 : 00005 OSPF::IMessageHandler (containingRouter), 00006 ospfModule (containingModule), 00007 helloHandler (containingRouter), 00008 ddHandler (containingRouter), 00009 lsRequestHandler (containingRouter), 00010 lsUpdateHandler (containingRouter), 00011 lsAckHandler (containingRouter) 00012 { 00013 }
|
|
00047 { return true; }
|
|
00317 { 00318 ospfModule->cancelEvent (timer); 00319 }
|
|
00032 { 00033 switch (timer->getTimerKind ()) { 00034 case InterfaceHelloTimer: 00035 { 00036 OSPF::Interface* intf; 00037 if (! (intf = reinterpret_cast <OSPF::Interface*> (timer->contextPointer ()))) { 00038 // should not reach this point 00039 EV << "Discarding invalid InterfaceHelloTimer.\n"; 00040 delete timer; 00041 } else { 00042 PrintEvent ("Hello Timer expired", intf); 00043 intf->ProcessEvent (OSPF::Interface::HelloTimer); 00044 } 00045 } 00046 break; 00047 case InterfaceWaitTimer: 00048 { 00049 OSPF::Interface* intf; 00050 if (! (intf = reinterpret_cast <OSPF::Interface*> (timer->contextPointer ()))) { 00051 // should not reach this point 00052 EV << "Discarding invalid InterfaceWaitTimer.\n"; 00053 delete timer; 00054 } else { 00055 PrintEvent ("Wait Timer expired", intf); 00056 intf->ProcessEvent (OSPF::Interface::WaitTimer); 00057 } 00058 } 00059 break; 00060 case InterfaceAcknowledgementTimer: 00061 { 00062 OSPF::Interface* intf; 00063 if (! (intf = reinterpret_cast <OSPF::Interface*> (timer->contextPointer ()))) { 00064 // should not reach this point 00065 EV << "Discarding invalid InterfaceAcknowledgementTimer.\n"; 00066 delete timer; 00067 } else { 00068 PrintEvent ("Acknowledgement Timer expired", intf); 00069 intf->ProcessEvent (OSPF::Interface::AcknowledgementTimer); 00070 } 00071 } 00072 break; 00073 case NeighborInactivityTimer: 00074 { 00075 OSPF::Neighbor* neighbor; 00076 if (! (neighbor = reinterpret_cast <OSPF::Neighbor*> (timer->contextPointer ()))) { 00077 // should not reach this point 00078 EV << "Discarding invalid NeighborInactivityTimer.\n"; 00079 delete timer; 00080 } else { 00081 PrintEvent ("Inactivity Timer expired", neighbor->GetInterface (), neighbor); 00082 neighbor->ProcessEvent (OSPF::Neighbor::InactivityTimer); 00083 } 00084 } 00085 break; 00086 case NeighborPollTimer: 00087 { 00088 OSPF::Neighbor* neighbor; 00089 if (! (neighbor = reinterpret_cast <OSPF::Neighbor*> (timer->contextPointer ()))) { 00090 // should not reach this point 00091 EV << "Discarding invalid NeighborInactivityTimer.\n"; 00092 delete timer; 00093 } else { 00094 PrintEvent ("Poll Timer expired", neighbor->GetInterface (), neighbor); 00095 neighbor->ProcessEvent (OSPF::Neighbor::PollTimer); 00096 } 00097 } 00098 break; 00099 case NeighborDDRetransmissionTimer: 00100 { 00101 OSPF::Neighbor* neighbor; 00102 if (! (neighbor = reinterpret_cast <OSPF::Neighbor*> (timer->contextPointer ()))) { 00103 // should not reach this point 00104 EV << "Discarding invalid NeighborDDRetransmissionTimer.\n"; 00105 delete timer; 00106 } else { 00107 PrintEvent ("Database Description Retransmission Timer expired", neighbor->GetInterface (), neighbor); 00108 neighbor->ProcessEvent (OSPF::Neighbor::DDRetransmissionTimer); 00109 } 00110 } 00111 break; 00112 case NeighborUpdateRetransmissionTimer: 00113 { 00114 OSPF::Neighbor* neighbor; 00115 if (! (neighbor = reinterpret_cast <OSPF::Neighbor*> (timer->contextPointer ()))) { 00116 // should not reach this point 00117 EV << "Discarding invalid NeighborUpdateRetransmissionTimer.\n"; 00118 delete timer; 00119 } else { 00120 PrintEvent ("Update Retransmission Timer expired", neighbor->GetInterface (), neighbor); 00121 neighbor->ProcessEvent (OSPF::Neighbor::UpdateRetransmissionTimer); 00122 } 00123 } 00124 break; 00125 case NeighborRequestRetransmissionTimer: 00126 { 00127 OSPF::Neighbor* neighbor; 00128 if (! (neighbor = reinterpret_cast <OSPF::Neighbor*> (timer->contextPointer ()))) { 00129 // should not reach this point 00130 EV << "Discarding invalid NeighborRequestRetransmissionTimer.\n"; 00131 delete timer; 00132 } else { 00133 PrintEvent ("Request Retransmission Timer expired", neighbor->GetInterface (), neighbor); 00134 neighbor->ProcessEvent (OSPF::Neighbor::RequestRetransmissionTimer); 00135 } 00136 } 00137 break; 00138 case DatabaseAgeTimer: 00139 { 00140 PrintEvent ("Ageing the database"); 00141 router->AgeDatabase (); 00142 } 00143 break; 00144 default: break; 00145 } 00146 }
|
|
00016 { 00017 if (message->isSelfMessage ()) { 00018 HandleTimer (check_and_cast<OSPFTimer*> (message)); 00019 } else { 00020 OSPFPacket* packet = check_and_cast<OSPFPacket*> (message); 00021 EV << "Received packet: (" << packet->className () << ")" << packet->name() << "\n"; 00022 if (packet->getRouterID () == router->GetRouterID ()) { 00023 EV << "This packet is from ourselves, discarding.\n"; 00024 delete message; 00025 } else { 00026 ProcessPacket (packet); 00027 } 00028 } 00029 }
|
|
00392 { 00393 char addressString[16]; 00394 EV << "Sending Database Description packet to " 00395 << AddressStringFromIPv4Address (addressString, sizeof (addressString), destination) 00396 << " on interface[" 00397 << outputIfIndex 00398 << "] with contents:\n"; 00399 00400 const OSPFDDOptions& ddOptions = ddPacket->getDdOptions (); 00401 EV << " ddOptions=" 00402 << ((ddOptions.I_Init) ? "I " : "_ ") 00403 << ((ddOptions.M_More) ? "M " : "_ ") 00404 << ((ddOptions.MS_MasterSlave) ? "MS" : "__") 00405 << "\n"; 00406 EV << " seqNumber=" 00407 << ddPacket->getDdSequenceNumber () 00408 << "\n"; 00409 EV << " LSA headers:\n"; 00410 00411 unsigned int lsaCount = ddPacket->getLsaHeadersArraySize (); 00412 for (unsigned int i = 0; i < lsaCount; i++) { 00413 EV << " "; 00414 PrintLSAHeader (ddPacket->getLsaHeaders (i)); 00415 EV << "\n"; 00416 } 00417 }
|
|
00327 { 00328 EV << eventString; 00329 if ((onInterface != NULL) || (forNeighbor != NULL)) { 00330 EV << ": "; 00331 } 00332 if (forNeighbor != NULL) { 00333 char addressString[16]; 00334 EV << "neighbor[" 00335 << AddressStringFromULong (addressString, sizeof (addressString), forNeighbor->GetNeighborID ()) 00336 << "] (state: " 00337 << forNeighbor->GetStateString (forNeighbor->GetState ()) 00338 << "); "; 00339 } 00340 if (onInterface != NULL) { 00341 EV << "interface[" 00342 << static_cast <short> (onInterface->GetIfIndex ()) 00343 << "] "; 00344 switch (onInterface->GetType ()) { 00345 case OSPF::Interface::PointToPoint: EV << "(PointToPoint)"; 00346 break; 00347 case OSPF::Interface::Broadcast: EV << "(Broadcast)"; 00348 break; 00349 case OSPF::Interface::NBMA: EV << "(NBMA).\n"; 00350 break; 00351 case OSPF::Interface::PointToMultiPoint: EV << "(PointToMultiPoint)"; 00352 break; 00353 case OSPF::Interface::Virtual: EV << "(Virtual)"; 00354 break; 00355 default: EV << "(Unknown)"; 00356 } 00357 EV << " (state: " 00358 << onInterface->GetStateString (onInterface->GetState ()) 00359 << ")"; 00360 } 00361 EV << ".\n"; 00362 }
|
|
00365 { 00366 char addressString[16]; 00367 EV << "Sending Hello packet to " 00368 << AddressStringFromIPv4Address (addressString, sizeof (addressString), destination) 00369 << " on interface[" 00370 << outputIfIndex 00371 << "] with contents:\n"; 00372 EV << " netMask=" 00373 << AddressStringFromULong (addressString, sizeof (addressString), helloPacket->getNetworkMask ().getInt ()) 00374 << "\n"; 00375 EV << " DR=" 00376 << AddressStringFromULong (addressString, sizeof (addressString), helloPacket->getDesignatedRouter ().getInt ()) 00377 << "\n"; 00378 EV << " BDR=" 00379 << AddressStringFromULong (addressString, sizeof (addressString), helloPacket->getBackupDesignatedRouter ().getInt ()) 00380 << "\n"; 00381 EV << " neighbors:\n"; 00382 00383 unsigned int neighborCount = helloPacket->getNeighborArraySize (); 00384 for (unsigned int i = 0; i < neighborCount; i++) { 00385 EV << " " 00386 << AddressStringFromULong (addressString, sizeof (addressString), helloPacket->getNeighbor (i).getInt ()) 00387 << "\n"; 00388 } 00389 }
|
|
00546 { 00547 char addressString[16]; 00548 EV << "Sending Link State Acknowledgement packet to " 00549 << AddressStringFromIPv4Address (addressString, sizeof (addressString), destination) 00550 << " on interface[" 00551 << outputIfIndex 00552 << "] with acknowledgements:\n"; 00553 00554 unsigned int lsaCount = ackPacket->getLsaHeadersArraySize (); 00555 for (unsigned int i = 0; i < lsaCount; i++) { 00556 EV << " "; 00557 PrintLSAHeader (ackPacket->getLsaHeaders (i)); 00558 EV << "\n"; 00559 } 00560 }
|
|
00420 { 00421 char addressString[16]; 00422 EV << "Sending Link State Request packet to " 00423 << AddressStringFromIPv4Address (addressString, sizeof (addressString), destination) 00424 << " on interface[" 00425 << outputIfIndex 00426 << "] with requests:\n"; 00427 00428 unsigned int requestCount = requestPacket->getRequestsArraySize (); 00429 for (unsigned int i = 0; i < requestCount; i++) { 00430 const LSARequest& request = requestPacket->getRequests(i); 00431 EV << " type=" 00432 << request.lsType 00433 << ", LSID=" 00434 << AddressStringFromULong (addressString, sizeof (addressString), request.linkStateID); 00435 EV << ", advertisingRouter=" 00436 << AddressStringFromULong (addressString, sizeof (addressString), request.advertisingRouter.getInt ()) 00437 << "\n"; 00438 } 00439 }
|
|
00442 { 00443 char addressString[16]; 00444 EV << "Sending Link State Update packet to " 00445 << AddressStringFromIPv4Address (addressString, sizeof (addressString), destination) 00446 << " on interface[" 00447 << outputIfIndex 00448 << "] with updates:\n"; 00449 00450 unsigned int i = 0; 00451 unsigned int updateCount = updatePacket->getRouterLSAsArraySize (); 00452 00453 for (i = 0; i < updateCount; i++) { 00454 const OSPFRouterLSA& lsa = updatePacket->getRouterLSAs(i); 00455 EV << " "; 00456 PrintLSAHeader (lsa.getHeader ()); 00457 EV << "\n"; 00458 00459 EV << " bits=" 00460 << ((lsa.getV_VirtualLinkEndpoint ()) ? "V " : "_ ") 00461 << ((lsa.getE_ASBoundaryRouter ()) ? "E " : "_ ") 00462 << ((lsa.getB_AreaBorderRouter ()) ? "B" : "_") 00463 << "\n"; 00464 EV << " links:\n"; 00465 00466 unsigned int linkCount = lsa.getLinksArraySize (); 00467 for (unsigned int j = 0; j < linkCount; j++) { 00468 const Link& link = lsa.getLinks (j); 00469 EV << " ID=" 00470 << AddressStringFromULong (addressString, sizeof (addressString), link.getLinkID ().getInt ()) 00471 << ","; 00472 EV << " data=" 00473 << AddressStringFromULong (addressString, sizeof (addressString), link.getLinkData ()) 00474 << ", type="; 00475 switch (link.getType ()) { 00476 case PointToPointLink: EV << "PointToPoint"; break; 00477 case TransitLink: EV << "Transit"; break; 00478 case StubLink: EV << "Stub"; break; 00479 case VirtualLink: EV << "Virtual"; break; 00480 default: EV << "Unknown"; break; 00481 } 00482 EV << ", cost=" 00483 << link.getLinkCost () 00484 << "\n"; 00485 } 00486 } 00487 00488 updateCount = updatePacket->getNetworkLSAsArraySize (); 00489 for (i = 0; i < updateCount; i++) { 00490 const OSPFNetworkLSA& lsa = updatePacket->getNetworkLSAs(i); 00491 EV << " "; 00492 PrintLSAHeader (lsa.getHeader ()); 00493 EV << "\n"; 00494 00495 EV << " netMask=" 00496 << AddressStringFromULong (addressString, sizeof (addressString), lsa.getNetworkMask ().getInt ()) 00497 << "\n"; 00498 EV << " attachedRouters:\n"; 00499 00500 unsigned int routerCount = lsa.getAttachedRoutersArraySize (); 00501 for (unsigned int j = 0; j < routerCount; j++) { 00502 EV << " " 00503 << AddressStringFromULong (addressString, sizeof (addressString), lsa.getAttachedRouters (j).getInt ()) 00504 << "\n"; 00505 } 00506 } 00507 00508 updateCount = updatePacket->getSummaryLSAsArraySize (); 00509 for (i = 0; i < updateCount; i++) { 00510 const OSPFSummaryLSA& lsa = updatePacket->getSummaryLSAs(i); 00511 EV << " "; 00512 PrintLSAHeader (lsa.getHeader ()); 00513 EV << "\n"; 00514 00515 EV << " netMask=" 00516 << AddressStringFromULong (addressString, sizeof (addressString), lsa.getNetworkMask ().getInt ()) 00517 << "\n"; 00518 EV << " cost=" 00519 << lsa.getRouteCost () 00520 << "\n"; 00521 } 00522 00523 updateCount = updatePacket->getAsExternalLSAsArraySize (); 00524 for (i = 0; i < updateCount; i++) { 00525 const OSPFASExternalLSA& lsa = updatePacket->getAsExternalLSAs(i); 00526 EV << " "; 00527 PrintLSAHeader (lsa.getHeader ()); 00528 EV << "\n"; 00529 00530 const OSPFASExternalLSAContents& contents = lsa.getContents (); 00531 EV << " netMask=" 00532 << AddressStringFromULong (addressString, sizeof (addressString), contents.getNetworkMask ().getInt ()) 00533 << "\n"; 00534 EV << " bits=" 00535 << ((contents.getE_ExternalMetricType ()) ? "E\n" : "_\n"); 00536 EV << " cost=" 00537 << contents.getRouteCost () 00538 << "\n"; 00539 EV << " forward=" 00540 << AddressStringFromULong (addressString, sizeof (addressString), contents.getForwardingAddress ().getInt ()) 00541 << "\n"; 00542 } 00543 }
|
|
00149 { 00150 // packet version must be OSPF version 2 00151 if (packet->getVersion () == 2) { 00152 IPControlInfo* controlInfo = check_and_cast<IPControlInfo *> (packet->controlInfo ()); 00153 int interfaceId = controlInfo->interfaceId (); 00154 OSPF::AreaID areaID = packet->getAreaID ().getInt (); 00155 OSPF::Area* area = router->GetArea (areaID); 00156 00157 if (area != NULL) { 00158 // packet Area ID must either match the Area ID of the receiving interface or... 00159 OSPF::Interface* intf = area->GetInterface (interfaceId); 00160 00161 if (intf == NULL) { 00162 // it must be the backbone area and... 00163 if (areaID == BackboneAreaID) { 00164 if (router->GetAreaCount () > 1) { 00165 // it must be a virtual link and the source router's router ID must be the endpoint of this virtual link and... 00166 intf = area->FindVirtualLink (packet->getRouterID ().getInt ()); 00167 00168 if (intf != NULL) { 00169 OSPF::Area* virtualLinkTransitArea = router->GetArea (intf->GetTransitAreaID ()); 00170 00171 if (virtualLinkTransitArea != NULL) { 00172 // the receiving interface must attach to the virtual link's configured transit area 00173 OSPF::Interface* virtualLinkInterface = virtualLinkTransitArea->GetInterface (interfaceId); 00174 00175 if (virtualLinkInterface == NULL) { 00176 intf = NULL; 00177 } 00178 } else { 00179 intf = NULL; 00180 } 00181 } 00182 } 00183 } 00184 } 00185 if (intf != NULL) { 00186 unsigned long destinationAddress = controlInfo->destAddr ().getInt (); 00187 unsigned long allDRouters = ULongFromIPv4Address (OSPF::AllDRouters); 00188 OSPF::Interface::InterfaceStateType interfaceState = intf->GetState (); 00189 00190 // if destination address is AllDRouters the receiving interface must be in DesignatedRouter or Backup state 00191 if ( 00192 ((destinationAddress == allDRouters) && 00193 ( 00194 (interfaceState == OSPF::Interface::DesignatedRouterState) || 00195 (interfaceState == OSPF::Interface::BackupState) 00196 ) 00197 ) || 00198 (destinationAddress != allDRouters) 00199 ) 00200 { 00201 // packet authentication 00202 if (AuthenticatePacket (packet)) { 00203 OSPFPacketType packetType = static_cast<OSPFPacketType> (packet->getType ()); 00204 OSPF::Neighbor* neighbor = NULL; 00205 00206 // all packets except HelloPackets are sent only along adjacencies, so a Neighbor must exist 00207 if (packetType != HelloPacket) { 00208 switch (intf->GetType ()) { 00209 case OSPF::Interface::Broadcast: 00210 case OSPF::Interface::NBMA: 00211 case OSPF::Interface::PointToMultiPoint: 00212 neighbor = intf->GetNeighborByAddress (IPv4AddressFromULong (controlInfo->srcAddr ().getInt ())); 00213 break; 00214 case OSPF::Interface::PointToPoint: 00215 case OSPF::Interface::Virtual: 00216 neighbor = intf->GetNeighborByID (packet->getRouterID ().getInt ()); 00217 break; 00218 default: break; 00219 } 00220 } 00221 switch (packetType) { 00222 case HelloPacket: 00223 helloHandler.ProcessPacket (packet, intf); 00224 break; 00225 case DatabaseDescriptionPacket: 00226 if (neighbor != NULL) { 00227 ddHandler.ProcessPacket (packet, intf, neighbor); 00228 } 00229 break; 00230 case LinkStateRequestPacket: 00231 if (neighbor != NULL) { 00232 lsRequestHandler.ProcessPacket (packet, intf, neighbor); 00233 } 00234 break; 00235 case LinkStateUpdatePacket: 00236 if (neighbor != NULL) { 00237 lsUpdateHandler.ProcessPacket (packet, intf, neighbor); 00238 } 00239 break; 00240 case LinkStateAcknowledgementPacket: 00241 if (neighbor != NULL) { 00242 lsAckHandler.ProcessPacket (packet, intf, neighbor); 00243 } 00244 break; 00245 default: break; 00246 } 00247 } 00248 } 00249 } 00250 } 00251 } 00252 delete packet; 00253 }
|
|
00256 { 00257 IPControlInfo *ipControlInfo = new IPControlInfo (); 00258 ipControlInfo->setProtocol (IP_PROT_OSPF); 00259 ipControlInfo->setDestAddr (ULongFromIPv4Address (destination)); 00260 ipControlInfo->setTimeToLive (ttl); 00261 ipControlInfo->setInterfaceId (outputIfIndex); 00262 00263 packet->setControlInfo (ipControlInfo); 00264 switch (packet->getType ()) { 00265 case HelloPacket: 00266 { 00267 packet->setKind (HelloPacket); 00268 packet->setName ("OSPF_HelloPacket"); 00269 00270 OSPFHelloPacket* helloPacket = check_and_cast<OSPFHelloPacket*> (packet); 00271 PrintHelloPacket (helloPacket, destination, outputIfIndex); 00272 } 00273 break; 00274 case DatabaseDescriptionPacket: 00275 { 00276 packet->setKind (DatabaseDescriptionPacket); 00277 packet->setName ("OSPF_DDPacket"); 00278 00279 OSPFDatabaseDescriptionPacket* ddPacket = check_and_cast<OSPFDatabaseDescriptionPacket*> (packet); 00280 PrintDatabaseDescriptionPacket (ddPacket, destination, outputIfIndex); 00281 } 00282 break; 00283 case LinkStateRequestPacket: 00284 { 00285 packet->setKind (LinkStateRequestPacket); 00286 packet->setName ("OSPF_LSReqPacket"); 00287 00288 OSPFLinkStateRequestPacket* requestPacket = check_and_cast<OSPFLinkStateRequestPacket*> (packet); 00289 PrintLinkStateRequestPacket (requestPacket, destination, outputIfIndex); 00290 } 00291 break; 00292 case LinkStateUpdatePacket: 00293 { 00294 packet->setKind (LinkStateUpdatePacket); 00295 packet->setName ("OSPF_LSUpdPacket"); 00296 00297 OSPFLinkStateUpdatePacket* updatePacket = check_and_cast<OSPFLinkStateUpdatePacket*> (packet); 00298 PrintLinkStateUpdatePacket (updatePacket, destination, outputIfIndex); 00299 } 00300 break; 00301 case LinkStateAcknowledgementPacket: 00302 { 00303 packet->setKind (LinkStateAcknowledgementPacket); 00304 packet->setName ("OSPF_LSAckPacket"); 00305 00306 OSPFLinkStateAcknowledgementPacket* ackPacket = check_and_cast<OSPFLinkStateAcknowledgementPacket*> (packet); 00307 PrintLinkStateAcknowledgementPacket (ackPacket, destination, outputIfIndex); 00308 } 00309 break; 00310 default: break; 00311 } 00312 00313 ospfModule->send (packet,"to_ip"); 00314 }
|
|
00322 { 00323 ospfModule->scheduleAt (ospfModule->simTime () + delay, timer); 00324 }
|
|
|
|
|
|
|
|
|
|
|
|
|