@@ -75,8 +75,8 @@ Ospfv2Interface::~Ospfv2Interface()
7575 if (previousState)
7676 delete previousState;
7777 delete state;
78- for (uint32_t i = 0 ; i < neighboringRouters. size (); i++ )
79- delete neighboringRouters[i] ;
78+ for (auto item : neighboringRouters)
79+ delete item ;
8080}
8181
8282const char *Ospfv2Interface::getTypeString (Ospfv2InterfaceType intfType)
@@ -163,9 +163,8 @@ void Ospfv2Interface::reset()
163163 messageHandler->clearTimer (acknowledgementTimer);
164164 designatedRouter = NULL_DESIGNATEDROUTERID ;
165165 backupDesignatedRouter = NULL_DESIGNATEDROUTERID ;
166- long neighborCount = neighboringRouters.size ();
167- for (long i = 0 ; i < neighborCount; i++) {
168- neighboringRouters[i]->processEvent (Neighbor::KILL_NEIGHBOR );
166+ for (auto neighbor : neighboringRouters) {
167+ neighbor->processEvent (Neighbor::KILL_NEIGHBOR );
169168 }
170169}
171170
@@ -196,10 +195,9 @@ void Ospfv2Interface::sendHelloPacket(Ipv4Address destination, short ttl)
196195 helloPacket->setRouterDeadInterval (routerDeadInterval);
197196 helloPacket->setDesignatedRouter (designatedRouter.ipInterfaceAddress );
198197 helloPacket->setBackupDesignatedRouter (backupDesignatedRouter.ipInterfaceAddress );
199- long neighborCount = neighboringRouters.size ();
200- for (long j = 0 ; j < neighborCount; j++) {
201- if (neighboringRouters[j]->getState () >= Neighbor::INIT_STATE ) {
202- neighbors.push_back (neighboringRouters[j]->getAddress ());
198+ for (auto neighbor : neighboringRouters) {
199+ if (neighbor->getState () >= Neighbor::INIT_STATE ) {
200+ neighbors.push_back (neighbor->getAddress ());
203201 }
204202 }
205203 unsigned int initedNeighborCount = neighbors.size ();
@@ -310,8 +308,8 @@ const char *Ospfv2Interface::getStateString(Ospfv2Interface::Ospfv2InterfaceStat
310308
311309bool Ospfv2Interface::hasAnyNeighborInStates (int states) const
312310{
313- for (uint32_t i = 0 ; i < neighboringRouters. size (); i++ ) {
314- Neighbor::NeighborStateType neighborState = neighboringRouters[i] ->getState ();
311+ for (auto item : neighboringRouters) {
312+ Neighbor::NeighborStateType neighborState = item ->getState ();
315313 if (neighborState & states)
316314 return true ;
317315 }
@@ -320,14 +318,14 @@ bool Ospfv2Interface::hasAnyNeighborInStates(int states) const
320318
321319void Ospfv2Interface::removeFromAllRetransmissionLists (LsaKeyType lsaKey)
322320{
323- for (uint32_t i = 0 ; i < neighboringRouters. size (); i++ )
324- neighboringRouters[i] ->removeFromRetransmissionList (lsaKey);
321+ for (auto item : neighboringRouters)
322+ item ->removeFromRetransmissionList (lsaKey);
325323}
326324
327325bool Ospfv2Interface::isOnAnyRetransmissionList (LsaKeyType lsaKey) const
328326{
329- for (uint32_t i = 0 ; i < neighboringRouters. size (); i++ ) {
330- if (neighboringRouters[i] ->isLinkStateRequestListEmpty (lsaKey))
327+ for (auto item : neighboringRouters) {
328+ if (item ->isLinkStateRequestListEmpty (lsaKey))
331329 return true ;
332330 }
333331 return false ;
@@ -358,36 +356,35 @@ bool Ospfv2Interface::floodLsa(const Ospfv2Lsa *lsa, Ospfv2Interface *intf, Neig
358356 )
359357 )
360358 {
361- long neighborCount = neighboringRouters.size ();
362359 bool lsaAddedToRetransmissionList = false ;
363360 LinkStateId linkStateID = lsa->getHeader ().getLinkStateID ();
364361 LsaKeyType lsaKey;
365362
366363 lsaKey.linkStateID = linkStateID;
367364 lsaKey.advertisingRouter = lsa->getHeader ().getAdvertisingRouter ();
368365
369- for (long i = 0 ; i < neighborCount; i++ ) { // (1)
370- if (neighboringRouters[i] ->getState () < Neighbor::EXCHANGE_STATE ) { // (1) (a)
366+ for (auto curNeighbor : neighboringRouters ) { // (1)
367+ if (curNeighbor ->getState () < Neighbor::EXCHANGE_STATE ) { // (1) (a)
371368 continue ;
372369 }
373- if (neighboringRouters[i] ->getState () < Neighbor::FULL_STATE ) { // (1) (b)
374- Ospfv2LsaHeader *requestLSAHeader = neighboringRouters[i] ->findOnRequestList (lsaKey);
370+ if (curNeighbor ->getState () < Neighbor::FULL_STATE ) { // (1) (b)
371+ Ospfv2LsaHeader *requestLSAHeader = curNeighbor ->findOnRequestList (lsaKey);
375372 if (requestLSAHeader != nullptr ) {
376373 // operator< and operator== on OSPFLSAHeaders determines which one is newer(less means older)
377374 if (lsa->getHeader () < (*requestLSAHeader)) {
378375 continue ;
379376 }
380377 if (operator ==(lsa->getHeader (), (*requestLSAHeader))) {
381- neighboringRouters[i] ->removeFromRequestList (lsaKey);
378+ curNeighbor ->removeFromRequestList (lsaKey);
382379 continue ;
383380 }
384- neighboringRouters[i] ->removeFromRequestList (lsaKey);
381+ curNeighbor ->removeFromRequestList (lsaKey);
385382 }
386383 }
387- if (neighbor == neighboringRouters[i] ) { // (1) (c)
384+ if (neighbor == curNeighbor ) { // (1) (c)
388385 continue ;
389386 }
390- neighboringRouters[i] ->addToRetransmissionList (lsa); // (1) (d)
387+ curNeighbor ->addToRetransmissionList (lsa); // (1) (d)
391388 lsaAddedToRetransmissionList = true ;
392389 }
393390 if (lsaAddedToRetransmissionList) { // (2)
@@ -409,10 +406,10 @@ bool Ospfv2Interface::floodLsa(const Ospfv2Lsa *lsa, Ospfv2Interface *intf, Neig
409406 (designatedRouter == NULL_DESIGNATEDROUTERID ))
410407 {
411408 messageHandler->sendPacket (updatePacket, Ipv4Address::ALL_OSPF_ROUTERS_MCAST , this , ttl);
412- for (long k = 0 ; k < neighborCount; k++ ) {
413- neighboringRouters[k] ->addToTransmittedLSAList (lsaKey);
414- if (!neighboringRouters[k] ->isUpdateRetransmissionTimerActive ()) {
415- neighboringRouters[k] ->startUpdateRetransmissionTimer ();
409+ for (auto item : neighboringRouters ) {
410+ item ->addToTransmittedLSAList (lsaKey);
411+ if (!item ->isUpdateRetransmissionTimerActive ()) {
412+ item ->startUpdateRetransmissionTimer ();
416413 }
417414 }
418415 }
@@ -437,20 +434,20 @@ bool Ospfv2Interface::floodLsa(const Ospfv2Lsa *lsa, Ospfv2Interface *intf, Neig
437434 else {
438435 if (interfaceType == Ospfv2Interface::POINTTOPOINT ) {
439436 messageHandler->sendPacket (updatePacket, Ipv4Address::ALL_OSPF_ROUTERS_MCAST , this , ttl);
440- if (neighborCount > 0 ) {
437+ if (!neighboringRouters. empty () ) {
441438 neighboringRouters[0 ]->addToTransmittedLSAList (lsaKey);
442439 if (!neighboringRouters[0 ]->isUpdateRetransmissionTimerActive ()) {
443440 neighboringRouters[0 ]->startUpdateRetransmissionTimer ();
444441 }
445442 }
446443 }
447444 else {
448- for (long m = 0 ; m < neighborCount; m++ ) {
449- if (neighboringRouters[m] ->getState () >= Neighbor::EXCHANGE_STATE ) {
450- messageHandler->sendPacket (updatePacket, neighboringRouters[m] ->getAddress (), this , ttl);
451- neighboringRouters[m] ->addToTransmittedLSAList (lsaKey);
452- if (!neighboringRouters[m] ->isUpdateRetransmissionTimerActive ()) {
453- neighboringRouters[m] ->startUpdateRetransmissionTimer ();
445+ for (auto item : neighboringRouters ) {
446+ if (item ->getState () >= Neighbor::EXCHANGE_STATE ) {
447+ messageHandler->sendPacket (updatePacket, item ->getAddress (), this , ttl);
448+ item ->addToTransmittedLSAList (lsaKey);
449+ if (!item ->isUpdateRetransmissionTimerActive ()) {
450+ item ->startUpdateRetransmissionTimer ();
454451 }
455452 }
456453 }
@@ -538,10 +535,9 @@ void Ospfv2Interface::addDelayedAcknowledgement(const Ospfv2LsaHeader& lsaHeader
538535 }
539536 }
540537 else {
541- long neighborCount = neighboringRouters.size ();
542- for (long i = 0 ; i < neighborCount; i++) {
543- if (neighboringRouters[i]->getState () >= Neighbor::EXCHANGE_STATE ) {
544- delayedAcknowledgements[neighboringRouters[i]->getAddress ()].push_back (lsaHeader);
538+ for (auto item : neighboringRouters) {
539+ if (item->getState () >= Neighbor::EXCHANGE_STATE ) {
540+ delayedAcknowledgements[item->getAddress ()].push_back (lsaHeader);
545541 }
546542 }
547543 }
@@ -613,9 +609,8 @@ void Ospfv2Interface::sendDelayedAcknowledgements()
613609
614610void Ospfv2Interface::ageTransmittedLsaLists ()
615611{
616- long neighborCount = neighboringRouters.size ();
617- for (long i = 0 ; i < neighborCount; i++) {
618- neighboringRouters[i]->ageTransmittedLSAList ();
612+ for (auto item : neighboringRouters) {
613+ item->ageTransmittedLSAList ();
619614 }
620615}
621616
0 commit comments