1.1 --- a/src/routing/olsr/olsr-routing-protocol.cc Fri Oct 30 10:23:40 2009 -0700
1.2 +++ b/src/routing/olsr/olsr-routing-protocol.cc Sun Nov 01 22:47:04 2009 +0000
1.3 @@ -552,7 +552,23 @@
1.4 }
1.5 }
1.6
1.7 - NS_LOG_DEBUG ("Size of N2: " << N2.size ());
1.8 +#ifdef NS3_LOG_ENABLE
1.9 + {
1.10 + std::ostringstream os;
1.11 + os << "[";
1.12 + for (TwoHopNeighborSet::const_iterator iter = N2.begin ();
1.13 + iter != N2.end (); iter++)
1.14 + {
1.15 + TwoHopNeighborSet::const_iterator next = iter;
1.16 + next++;
1.17 + os << iter->neighborMainAddr << "->" << iter->twoHopNeighborAddr;
1.18 + if (next != N2.end ())
1.19 + os << ", ";
1.20 + }
1.21 + os << "]";
1.22 + NS_LOG_DEBUG ("N2: " << os.str ());
1.23 + }
1.24 +#endif //NS3_LOG_ENABLE
1.25
1.26 // 1. Start with an MPR set made of all members of N with
1.27 // N_willingness equal to WILL_ALWAYS
1.28 @@ -584,31 +600,38 @@
1.29 // 3. Add to the MPR set those nodes in N, which are the *only*
1.30 // nodes to provide reachability to a node in N2.
1.31 std::set<Ipv4Address> coveredTwoHopNeighbors;
1.32 - for (TwoHopNeighborSet::iterator twoHopNeigh = N2.begin (); twoHopNeigh != N2.end (); twoHopNeigh++)
1.33 + for (TwoHopNeighborSet::const_iterator twoHopNeigh = N2.begin (); twoHopNeigh != N2.end (); twoHopNeigh++)
1.34 {
1.35 - NeighborSet::const_iterator onlyNeighbor = N.end ();
1.36 -
1.37 - for (NeighborSet::const_iterator neighbor = N.begin ();
1.38 - neighbor != N.end (); neighbor++)
1.39 + bool onlyOne = true;
1.40 + // try to find another neighbor that can reach twoHopNeigh->twoHopNeighborAddr
1.41 + for (TwoHopNeighborSet::const_iterator otherTwoHopNeigh = N2.begin (); otherTwoHopNeigh != N2.end (); otherTwoHopNeigh++)
1.42 {
1.43 - if (neighbor->neighborMainAddr == twoHopNeigh->neighborMainAddr)
1.44 + if (otherTwoHopNeigh->twoHopNeighborAddr == twoHopNeigh->twoHopNeighborAddr
1.45 + && otherTwoHopNeigh->neighborMainAddr != twoHopNeigh->neighborMainAddr)
1.46 {
1.47 - if (onlyNeighbor == N.end ())
1.48 + onlyOne = false;
1.49 + break;
1.50 + }
1.51 + }
1.52 + if (onlyOne)
1.53 + {
1.54 + NS_LOG_LOGIC ("Neighbor " << twoHopNeigh->neighborMainAddr
1.55 + << " is the only that can reach 2-hop neigh. "
1.56 + << twoHopNeigh->twoHopNeighborAddr
1.57 + << " => select as MPR.");
1.58 +
1.59 + mprSet.insert (twoHopNeigh->neighborMainAddr);
1.60 +
1.61 + // take note of all the 2-hop neighbors reachable by the newly elected MPR
1.62 + for (TwoHopNeighborSet::const_iterator otherTwoHopNeigh = N2.begin ();
1.63 + otherTwoHopNeigh != N2.end (); otherTwoHopNeigh++)
1.64 + {
1.65 + if (otherTwoHopNeigh->neighborMainAddr == twoHopNeigh->neighborMainAddr)
1.66 {
1.67 - onlyNeighbor = neighbor;
1.68 - }
1.69 - else
1.70 - {
1.71 - onlyNeighbor = N.end ();
1.72 - break;
1.73 + coveredTwoHopNeighbors.insert (otherTwoHopNeigh->twoHopNeighborAddr);
1.74 }
1.75 }
1.76 }
1.77 - if (onlyNeighbor != N.end ())
1.78 - {
1.79 - mprSet.insert (onlyNeighbor->neighborMainAddr);
1.80 - coveredTwoHopNeighbors.insert (twoHopNeigh->twoHopNeighborAddr);
1.81 - }
1.82 }
1.83 // Remove the nodes from N2 which are now covered by a node in the MPR set.
1.84 for (TwoHopNeighborSet::iterator twoHopNeigh = N2.begin ();
1.85 @@ -616,6 +639,7 @@
1.86 {
1.87 if (coveredTwoHopNeighbors.find (twoHopNeigh->twoHopNeighborAddr) != coveredTwoHopNeighbors.end ())
1.88 {
1.89 + NS_LOG_LOGIC ("2-hop neigh. " << twoHopNeigh->twoHopNeighborAddr << " is already covered by an MPR.");
1.90 twoHopNeigh = N2.erase (twoHopNeigh);
1.91 }
1.92 else
1.93 @@ -628,6 +652,26 @@
1.94 // least one node in the MPR set:
1.95 while (N2.begin () != N2.end ())
1.96 {
1.97 +
1.98 +#ifdef NS3_LOG_ENABLE
1.99 + {
1.100 + std::ostringstream os;
1.101 + os << "[";
1.102 + for (TwoHopNeighborSet::const_iterator iter = N2.begin ();
1.103 + iter != N2.end (); iter++)
1.104 + {
1.105 + TwoHopNeighborSet::const_iterator next = iter;
1.106 + next++;
1.107 + os << iter->neighborMainAddr << "->" << iter->twoHopNeighborAddr;
1.108 + if (next != N2.end ())
1.109 + os << ", ";
1.110 + }
1.111 + os << "]";
1.112 + NS_LOG_DEBUG ("Step 4 iteration: N2=" << os.str ());
1.113 + }
1.114 +#endif //NS3_LOG_ENABLE
1.115 +
1.116 +
1.117 // 4.1. For each node in N, calculate the reachability, i.e., the
1.118 // number of nodes in N2 which are not yet covered by at
1.119 // least one node in the MPR set, and which are reachable