View | Details | Raw Unified | Return to bug 740
Collapse All | Expand All

(-)a/src/routing/olsr/olsr-routing-protocol.cc (-25 / +36 lines)
 Lines 464-469    Link Here 
464
  return degree;
464
  return degree;
465
}
465
}
466
466
467
namespace {
468
///
469
/// \brief Remove all covered 2-hop neighbors from N2 set. This is a helper function used by MprComputation algorithm.
470
///
471
void 
472
CoverTwoHopNeighbors (Ipv4Address neighborMainAddr, TwoHopNeighborSet & N2)
473
{
474
  // first gather all 2-hop neighbors to be removed
475
  std::set<Ipv4Address> toRemove;
476
  for (TwoHopNeighborSet::iterator twoHopNeigh = N2.begin (); twoHopNeigh != N2.end (); twoHopNeigh ++)
477
    {
478
      if (twoHopNeigh->neighborMainAddr == neighborMainAddr)
479
        {
480
          toRemove.insert (twoHopNeigh->twoHopNeighborAddr);
481
        }
482
    }
483
  // Now remove all matching records from N2
484
  for (TwoHopNeighborSet::iterator twoHopNeigh = N2.begin (); twoHopNeigh != N2.end (); )
485
    {
486
      if (toRemove.find (twoHopNeigh->twoHopNeighborAddr) != toRemove.end ())
487
        {
488
          twoHopNeigh = N2.erase (twoHopNeigh);
489
        }
490
      else
491
        {
492
          twoHopNeigh ++;
493
        }
494
    }
495
}
496
} // anonymous namespace
497
467
///
498
///
468
/// \brief Computates MPR set of a node following RFC 3626 hints.
499
/// \brief Computates MPR set of a node following RFC 3626 hints.
469
///
500
///
 Lines 577-594    Link Here 
577
          mprSet.insert (neighbor->neighborMainAddr);
608
          mprSet.insert (neighbor->neighborMainAddr);
578
          // (not in RFC but I think is needed: remove the 2-hop
609
          // (not in RFC but I think is needed: remove the 2-hop
579
          // neighbors reachable by the MPR from N2)
610
          // neighbors reachable by the MPR from N2)
580
          for (TwoHopNeighborSet::iterator twoHopNeigh = N2.begin ();
611
          CoverTwoHopNeighbors (neighbor->neighborMainAddr, N2);
581
               twoHopNeigh != N2.end (); )
582
            {
583
              if (twoHopNeigh->neighborMainAddr == neighbor->neighborMainAddr)
584
                {
585
                  twoHopNeigh = N2.erase (twoHopNeigh);
586
                }
587
              else
588
                {
589
                  twoHopNeigh++;
590
                }
591
            }
592
        }
612
        }
593
    }
613
    }
594
  
614
  
 Lines 637-642    Link Here 
637
    {
657
    {
638
      if (coveredTwoHopNeighbors.find (twoHopNeigh->twoHopNeighborAddr) != coveredTwoHopNeighbors.end ())
658
      if (coveredTwoHopNeighbors.find (twoHopNeigh->twoHopNeighborAddr) != coveredTwoHopNeighbors.end ())
639
        {
659
        {
660
          // This works correctly only because it is known that twoHopNeigh is reachable by exactly one neighbor, 
661
          // so only one record in N2 exists for each of them. This record is erased here.
640
          NS_LOG_LOGIC ("2-hop neigh. " << twoHopNeigh->twoHopNeighborAddr << " is already covered by an MPR.");
662
          NS_LOG_LOGIC ("2-hop neigh. " << twoHopNeigh->twoHopNeighborAddr << " is already covered by an MPR.");
641
          twoHopNeigh = N2.erase (twoHopNeigh);
663
          twoHopNeigh = N2.erase (twoHopNeigh);
642
        }
664
        }
 Lines 742-760    Link Here 
742
      if (max != NULL)
764
      if (max != NULL)
743
        {
765
        {
744
          mprSet.insert (max->neighborMainAddr);
766
          mprSet.insert (max->neighborMainAddr);
745
          // Remove the nodes from N2 which are now covered by a node in the MPR set.
767
          CoverTwoHopNeighbors (max->neighborMainAddr, N2);
746
          for (TwoHopNeighborSet::iterator twoHopNeigh = N2.begin (); twoHopNeigh != N2.end (); )
768
          NS_LOG_LOGIC (N2.size () << " 2-hop neighbors left to cover!");           
747
            {
748
              if (coveredTwoHopNeighbors.find (twoHopNeigh->twoHopNeighborAddr) != coveredTwoHopNeighbors.end ())
749
                {
750
                  NS_LOG_LOGIC ("2-hop neigh. " << twoHopNeigh->twoHopNeighborAddr << " is already covered by an MPR.");
751
                  twoHopNeigh = N2.erase (twoHopNeigh);
752
                }
753
              else
754
                {
755
                  twoHopNeigh++;
756
                }
757
            }
758
        }
769
        }
759
    }
770
    }
760
771

Return to bug 740