From 487668dfcbf0a81b00d8934e76f5d6cbba02627b Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Mon, 3 Mar 2008 15:02:33 +0000 Subject: [PATCH 1/4] Small OLSR memory optimisation. --HG-- extra : transplant_source : %E6%259%28%DE%B7f%1C%ED%B0%26%98%A6%0A%FD%DF9%F4U%12 --- src/routing/olsr/olsr-agent-impl.cc | 57 +++++++++++++++-------------- src/routing/olsr/olsr-agent-impl.h | 12 +++--- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/src/routing/olsr/olsr-agent-impl.cc b/src/routing/olsr/olsr-agent-impl.cc index d8b7ecf76..72c99546c 100644 --- a/src/routing/olsr/olsr-agent-impl.cc +++ b/src/routing/olsr/olsr-agent-impl.cc @@ -1115,7 +1115,9 @@ AgentImpl::ProcessTc (const olsr::MessageHeader &msg, // Schedules topology tuple deletion m_events.Track (Simulator::Schedule (DELAY (topologyTuple.expirationTime), &AgentImpl::TopologyTupleTimerExpire, - this, topologyTuple)); + this, + topologyTuple.destAddr, + topologyTuple.lastAddr)); } } @@ -1190,7 +1192,7 @@ AgentImpl::ProcessMid (const olsr::MessageHeader &msg, NS_LOG_LOGIC ("New IfaceAssoc added: " << tuple); // Schedules iface association tuple deletion Simulator::Schedule (DELAY (tuple.time), - &AgentImpl::IfaceAssocTupleTimerExpire, this, tuple); + &AgentImpl::IfaceAssocTupleTimerExpire, this, tuple.ifaceAddr); } } @@ -1286,7 +1288,8 @@ AgentImpl::ForwardDefault (olsr::MessageHeader olsrMessage, AddDuplicateTuple (newDup); // Schedule dup tuple deletion Simulator::Schedule (OLSR_DUP_HOLD_TIME, - &AgentImpl::DupTupleTimerExpire, this, newDup); + &AgentImpl::DupTupleTimerExpire, this, + newDup.address, newDup.sequenceNumber); } } @@ -1670,7 +1673,8 @@ AgentImpl::LinkSensing (const olsr::MessageHeader &msg, { LinkTupleAdded (*link_tuple, hello.willingness); m_events.Track (Simulator::Schedule (DELAY (std::min (link_tuple->time, link_tuple->symTime)), - &AgentImpl::LinkTupleTimerExpire, this, *link_tuple)); + &AgentImpl::LinkTupleTimerExpire, this, + link_tuple->neighborIfaceAddr)); } NS_LOG_DEBUG ("@" << now.GetSeconds () << ": Olsr node " << m_mainAddress << ": LinkSensing END"); @@ -1769,7 +1773,8 @@ AgentImpl::PopulateTwoHopNeighborSet (const olsr::MessageHeader &msg, // Schedules nb2hop tuple deletion m_events.Track (Simulator::Schedule (DELAY (new_nb2hop_tuple.expirationTime), &AgentImpl::Nb2hopTupleTimerExpire, this, - new_nb2hop_tuple)); + new_nb2hop_tuple.neighborMainAddr, + new_nb2hop_tuple.twoHopNeighborAddr)); } else { @@ -1839,7 +1844,7 @@ AgentImpl::PopulateMprSelectorSet (const olsr::MessageHeader &msg, m_events.Track (Simulator::Schedule (DELAY (mprsel_tuple.expirationTime), &AgentImpl::MprSelTupleTimerExpire, this, - mprsel_tuple)); + mprsel_tuple.mainAddr)); } else { @@ -2261,10 +2266,10 @@ AgentImpl::MidTimerExpire () /// \param tuple The tuple which has expired. /// void -AgentImpl::DupTupleTimerExpire (DuplicateTuple tuple_) +AgentImpl::DupTupleTimerExpire (Ipv4Address address, uint16_t sequenceNumber) { DuplicateTuple *tuple = - m_state.FindDuplicateTuple (tuple_.address, tuple_.sequenceNumber); + m_state.FindDuplicateTuple (address, sequenceNumber); if (tuple == NULL) { return; @@ -2277,7 +2282,7 @@ AgentImpl::DupTupleTimerExpire (DuplicateTuple tuple_) { m_events.Track (Simulator::Schedule (DELAY (tuple->expirationTime), &AgentImpl::DupTupleTimerExpire, this, - *tuple)); + address, sequenceNumber)); } } @@ -2293,12 +2298,12 @@ AgentImpl::DupTupleTimerExpire (DuplicateTuple tuple_) /// \param e The event which has expired. /// void -AgentImpl::LinkTupleTimerExpire (LinkTuple tuple_) +AgentImpl::LinkTupleTimerExpire (Ipv4Address neighborIfaceAddr) { Time now = Simulator::Now (); // the tuple parameter may be a stale copy; get a newer version from m_state - LinkTuple *tuple = m_state.FindLinkTuple (tuple_.neighborIfaceAddr); + LinkTuple *tuple = m_state.FindLinkTuple (neighborIfaceAddr); if (tuple == NULL) { return; @@ -2316,13 +2321,13 @@ AgentImpl::LinkTupleTimerExpire (LinkTuple tuple_) m_events.Track (Simulator::Schedule (DELAY (tuple->time), &AgentImpl::LinkTupleTimerExpire, this, - *tuple)); + neighborIfaceAddr)); } else { m_events.Track (Simulator::Schedule (DELAY (std::min (tuple->time, tuple->symTime)), &AgentImpl::LinkTupleTimerExpire, this, - *tuple)); + neighborIfaceAddr)); } } @@ -2334,11 +2339,10 @@ AgentImpl::LinkTupleTimerExpire (LinkTuple tuple_) /// \param e The event which has expired. /// void -AgentImpl::Nb2hopTupleTimerExpire (TwoHopNeighborTuple tuple_) +AgentImpl::Nb2hopTupleTimerExpire (Ipv4Address neighborMainAddr, Ipv4Address twoHopNeighborAddr) { TwoHopNeighborTuple *tuple; - tuple = m_state.FindTwoHopNeighborTuple (tuple_.neighborMainAddr, - tuple_.twoHopNeighborAddr); + tuple = m_state.FindTwoHopNeighborTuple (neighborMainAddr, twoHopNeighborAddr); if (tuple == NULL) { return; @@ -2351,7 +2355,7 @@ AgentImpl::Nb2hopTupleTimerExpire (TwoHopNeighborTuple tuple_) { m_events.Track (Simulator::Schedule (DELAY (tuple->expirationTime), &AgentImpl::Nb2hopTupleTimerExpire, - this, *tuple)); + this, neighborMainAddr, twoHopNeighborAddr)); } } @@ -2363,9 +2367,9 @@ AgentImpl::Nb2hopTupleTimerExpire (TwoHopNeighborTuple tuple_) /// \param e The event which has expired. /// void -AgentImpl::MprSelTupleTimerExpire (MprSelectorTuple tuple_) +AgentImpl::MprSelTupleTimerExpire (Ipv4Address mainAddr) { - MprSelectorTuple *tuple = m_state.FindMprSelectorTuple (tuple_.mainAddr); + MprSelectorTuple *tuple = m_state.FindMprSelectorTuple (mainAddr); if (tuple == NULL) { return; @@ -2378,7 +2382,7 @@ AgentImpl::MprSelTupleTimerExpire (MprSelectorTuple tuple_) { m_events.Track (Simulator::Schedule (DELAY (tuple->expirationTime), &AgentImpl::MprSelTupleTimerExpire, - this, *tuple)); + this, mainAddr)); } } @@ -2390,10 +2394,9 @@ AgentImpl::MprSelTupleTimerExpire (MprSelectorTuple tuple_) /// \param e The event which has expired. /// void -AgentImpl::TopologyTupleTimerExpire (TopologyTuple tuple_) +AgentImpl::TopologyTupleTimerExpire (Ipv4Address destAddr, Ipv4Address lastAddr) { - TopologyTuple *tuple = m_state.FindTopologyTuple (tuple_.destAddr, - tuple_.lastAddr); + TopologyTuple *tuple = m_state.FindTopologyTuple (destAddr, lastAddr); if (tuple == NULL) { return; @@ -2406,7 +2409,7 @@ AgentImpl::TopologyTupleTimerExpire (TopologyTuple tuple_) { m_events.Track (Simulator::Schedule (DELAY (tuple->expirationTime), &AgentImpl::TopologyTupleTimerExpire, - this, *tuple)); + this, tuple->destAddr, tuple->lastAddr)); } } @@ -2416,9 +2419,9 @@ AgentImpl::TopologyTupleTimerExpire (TopologyTuple tuple_) /// \param e The event which has expired. /// void -AgentImpl::IfaceAssocTupleTimerExpire (IfaceAssocTuple tuple_) +AgentImpl::IfaceAssocTupleTimerExpire (Ipv4Address ifaceAddr) { - IfaceAssocTuple *tuple = m_state.FindIfaceAssocTuple (tuple_.ifaceAddr); + IfaceAssocTuple *tuple = m_state.FindIfaceAssocTuple (ifaceAddr); if (tuple == NULL) { return; @@ -2431,7 +2434,7 @@ AgentImpl::IfaceAssocTupleTimerExpire (IfaceAssocTuple tuple_) { m_events.Track (Simulator::Schedule (DELAY (tuple->time), &AgentImpl::IfaceAssocTupleTimerExpire, - this, *tuple)); + this, ifaceAddr)); } } diff --git a/src/routing/olsr/olsr-agent-impl.h b/src/routing/olsr/olsr-agent-impl.h index 4891c4d45..b220f0814 100644 --- a/src/routing/olsr/olsr-agent-impl.h +++ b/src/routing/olsr/olsr-agent-impl.h @@ -114,13 +114,13 @@ protected: Timer m_midTimer; void MidTimerExpire (); - void DupTupleTimerExpire (DuplicateTuple tuple); + void DupTupleTimerExpire (Ipv4Address address, uint16_t sequenceNumber); bool m_linkTupleTimerFirstTime; - void LinkTupleTimerExpire (LinkTuple tuple); - void Nb2hopTupleTimerExpire (TwoHopNeighborTuple tuple); - void MprSelTupleTimerExpire (MprSelectorTuple tuple); - void TopologyTupleTimerExpire (TopologyTuple tuple); - void IfaceAssocTupleTimerExpire (IfaceAssocTuple tuple); + void LinkTupleTimerExpire (Ipv4Address neighborIfaceAddr); + void Nb2hopTupleTimerExpire (Ipv4Address neighborMainAddr, Ipv4Address twoHopNeighborAddr); + void MprSelTupleTimerExpire (Ipv4Address mainAddr); + void TopologyTupleTimerExpire (Ipv4Address destAddr, Ipv4Address lastAddr); + void IfaceAssocTupleTimerExpire (Ipv4Address ifaceAddr); void IncrementAnsn (); From 0f90174f48665ab7eeb2bbe6102e2107a805bbd8 Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Thu, 6 Mar 2008 19:14:52 +0000 Subject: [PATCH 2/4] OLSR optimization: avoid doing routing table computation if no local DB changed after receiving a OLSR packet. --HG-- extra : transplant_source : %EA%FD%15L%AE%A6%BF%1BV%2A%27s%17%F2%0B%F8%AAn_2 --- src/routing/olsr/olsr-agent-impl.cc | 8 +++++++- src/routing/olsr/olsr-state.cc | 17 ++++++++++++++++- src/routing/olsr/olsr-state.h | 21 +++++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/routing/olsr/olsr-agent-impl.cc b/src/routing/olsr/olsr-agent-impl.cc index 72c99546c..4bf74910f 100644 --- a/src/routing/olsr/olsr-agent-impl.cc +++ b/src/routing/olsr/olsr-agent-impl.cc @@ -350,6 +350,8 @@ AgentImpl::RecvOlsr (Ptr socket, m_rxPacketTrace (olsrPacketHeader, messages); + m_state.SetModified (false); + for (MessageList::const_iterator messageIter = messages.begin (); messageIter != messages.end (); messageIter++) { @@ -446,7 +448,11 @@ AgentImpl::RecvOlsr (Ptr socket, } // After processing all OLSR messages, we must recompute the routing table - RoutingTableComputation (); + if (m_state.GetModified ()) + { + RoutingTableComputation (); + m_state.SetModified (false); + } } /// diff --git a/src/routing/olsr/olsr-state.cc b/src/routing/olsr/olsr-state.cc index a4ee3d892..b44dd8a82 100644 --- a/src/routing/olsr/olsr-state.cc +++ b/src/routing/olsr/olsr-state.cc @@ -127,6 +127,7 @@ OlsrState::EraseNeighborTuple (const NeighborTuple &tuple) if (*it == tuple) { m_neighborSet.erase (it); + m_modified = true; break; } } @@ -141,6 +142,7 @@ OlsrState::EraseNeighborTuple (const Ipv4Address &mainAddr) if (it->neighborMainAddr == mainAddr) { it = m_neighborSet.erase (it); + m_modified = true; break; } } @@ -156,6 +158,7 @@ OlsrState::InsertNeighborTuple (NeighborTuple const &tuple) { // Update it *it = tuple; + m_modified = true; return; } } @@ -189,6 +192,7 @@ OlsrState::EraseTwoHopNeighborTuple (const TwoHopNeighborTuple &tuple) if (*it == tuple) { m_twoHopNeighborSet.erase(it); + m_modified = true; break; } } @@ -206,6 +210,7 @@ OlsrState::EraseTwoHopNeighborTuples (const Ipv4Address &neighborMainAddr, { it = m_twoHopNeighborSet.erase (it); it--; // FIXME: is this correct in the case 'it' pointed to the first element? + m_modified = true; } } } @@ -219,13 +224,16 @@ OlsrState::EraseTwoHopNeighborTuples (const Ipv4Address &neighborMainAddr) if (it->neighborMainAddr == neighborMainAddr) { it = m_twoHopNeighborSet.erase (it); it--; + m_modified = true; } } } void -OlsrState::InsertTwoHopNeighborTuple (TwoHopNeighborTuple const &tuple){ +OlsrState::InsertTwoHopNeighborTuple (TwoHopNeighborTuple const &tuple) +{ m_twoHopNeighborSet.push_back (tuple); + m_modified = true; } /********** MPR Set Manipulation **********/ @@ -323,6 +331,7 @@ OlsrState::EraseLinkTuple (const LinkTuple &tuple) if (*it == tuple) { m_linkSet.erase (it); + m_modified = true; break; } } @@ -332,6 +341,7 @@ LinkTuple& OlsrState::InsertLinkTuple (LinkTuple const &tuple) { m_linkSet.push_back (tuple); + m_modified = true; return m_linkSet.back (); } @@ -371,6 +381,7 @@ OlsrState::EraseTopologyTuple(const TopologyTuple &tuple) if (*it == tuple) { m_topologySet.erase (it); + m_modified = true; break; } } @@ -386,6 +397,7 @@ OlsrState::EraseOlderTopologyTuples (const Ipv4Address &lastAddr, uint16_t ansn) { it = m_topologySet.erase (it); it--; + m_modified = true; } } } @@ -394,6 +406,7 @@ void OlsrState::InsertTopologyTuple (TopologyTuple const &tuple) { m_topologySet.push_back (tuple); + m_modified = true; } /********** Interface Association Set Manipulation **********/ @@ -431,6 +444,7 @@ OlsrState::EraseIfaceAssocTuple (const IfaceAssocTuple &tuple) if (*it == tuple) { m_ifaceAssocSet.erase (it); + m_modified = true; break; } } @@ -440,6 +454,7 @@ void OlsrState::InsertIfaceAssocTuple (const IfaceAssocTuple &tuple) { m_ifaceAssocSet.push_back (tuple); + m_modified = true; } std::vector diff --git a/src/routing/olsr/olsr-state.h b/src/routing/olsr/olsr-state.h index efebc810b..45ec80770 100644 --- a/src/routing/olsr/olsr-state.h +++ b/src/routing/olsr/olsr-state.h @@ -46,8 +46,29 @@ protected: DuplicateSet m_duplicateSet; ///< Duplicate Set (RFC 3626, section 3.4). IfaceAssocSet m_ifaceAssocSet; ///< Interface Association Set (RFC 3626, section 4.1). +// m_modified is set to true when any of the following databases is modified: +// - the link set, +// - the neighbor set, +// - the 2-hop neighbor set, +// - the topology set, +// - the Multiple Interface Association Information Base, + bool m_modified; + public: + OlsrState () + : m_modified (false) + {} + + bool GetModified () const + { + return m_modified; + } + void SetModified (bool modified) + { + m_modified = modified; + } + // MPR selector const MprSelectorSet & GetMprSelectors () const { From 0ae404d50de28f29807a48f12f9b15418e16f0e6 Mon Sep 17 00:00:00 2001 From: Guillaume Vu-Brugier Date: Fri, 7 Mar 2008 11:36:33 -0800 Subject: [PATCH 3/4] store length type field in ethernet packets in network order. --- src/node/ethernet-header.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/node/ethernet-header.cc b/src/node/ethernet-header.cc index ce2241f50..ec0d4a420 100644 --- a/src/node/ethernet-header.cc +++ b/src/node/ethernet-header.cc @@ -149,7 +149,7 @@ EthernetHeader::Serialize (Buffer::Iterator start) const } WriteTo (i, m_destination); WriteTo (i, m_source); - i.WriteU16 (m_lengthType); + i.WriteHtonU16 (m_lengthType); } uint32_t EthernetHeader::Deserialize (Buffer::Iterator start) @@ -163,7 +163,7 @@ EthernetHeader::Deserialize (Buffer::Iterator start) ReadFrom (i, m_destination); ReadFrom (i, m_source); - m_lengthType = i.ReadU16 (); + m_lengthType = i.ReadNtohU16 (); return GetSerializedSize (); } From 9420df81207816a96d110fcdffa08e3b0e6f9245 Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Thu, 13 Mar 2008 19:00:30 +0000 Subject: [PATCH 4/4] OLSR: fix default willingness value, cleanup and fix the MPR computation algorithm. --HG-- extra : transplant_source : di%E7B5%AE%9F%C6%B5D%CB%25%3D%D5%2A-%CC%07M%E0 --- src/routing/olsr/olsr-agent-impl.cc | 253 +++++++++++++--------------- src/routing/olsr/olsr-state.cc | 10 +- src/routing/olsr/olsr-state.h | 3 +- 3 files changed, 124 insertions(+), 142 deletions(-) diff --git a/src/routing/olsr/olsr-agent-impl.cc b/src/routing/olsr/olsr-agent-impl.cc index 4bf74910f..f7af599d6 100644 --- a/src/routing/olsr/olsr-agent-impl.cc +++ b/src/routing/olsr/olsr-agent-impl.cc @@ -182,7 +182,7 @@ AgentImpl::AgentImpl (Ptr node) m_helloInterval = OLSR_HELLO_INTERVAL; m_tcInterval = OLSR_TC_INTERVAL; m_midInterval = OLSR_MID_INTERVAL; - m_willingness = OLSR_WILL_ALWAYS; + m_willingness = OLSR_WILL_DEFAULT; m_linkTupleTimerFirstTime = true; @@ -488,17 +488,19 @@ AgentImpl::MprComputation() { // MPR computation should be done for each interface. See section 8.3.1 // (RFC 3626) for details. + MprSet mprSet; - m_state.ClearMprSet (); // N is the subset of neighbors of the node, which are // neighbor "of the interface I" NeighborSet N; - for (NeighborSet::const_iterator it = m_state.GetNeighbors ().begin(); - it != m_state.GetNeighbors ().end (); it++) + for (NeighborSet::const_iterator neighbor = m_state.GetNeighbors ().begin(); + neighbor != m_state.GetNeighbors ().end (); neighbor++) { - if ((*it).status == NeighborTuple::STATUS_SYM) // I think that we need this check - N.push_back (*it); + if (neighbor->status == NeighborTuple::STATUS_SYM) // I think that we need this check + { + N.push_back (*neighbor); + } } // N2 is the set of 2-hop neighbors reachable from "the interface @@ -508,123 +510,122 @@ AgentImpl::MprComputation() // (iii) all the symmetric neighbors: the nodes for which there exists a symmetric // link to this node on some interface. TwoHopNeighborSet N2; - for (TwoHopNeighborSet::const_iterator it = m_state.GetTwoHopNeighbors ().begin (); - it != m_state.GetTwoHopNeighbors ().end (); it++) + for (TwoHopNeighborSet::const_iterator twoHopNeigh = m_state.GetTwoHopNeighbors ().begin (); + twoHopNeigh != m_state.GetTwoHopNeighbors ().end (); twoHopNeigh++) { - TwoHopNeighborTuple const &twoHopNeigh = *it; - bool ok = true; - const NeighborTuple *nb_tuple = m_state.FindSymNeighborTuple (twoHopNeigh.neighborMainAddr); - if (nb_tuple == NULL) + // excluding: + // (ii) the node performing the computation + if (twoHopNeigh->twoHopNeighborAddr == m_mainAddress) { - ok = false; + continue; } - else + + // excluding: + // (i) the nodes only reachable by members of N with willingness WILL_NEVER + bool ok = false; + for (NeighborSet::const_iterator neigh = N.begin (); + neigh != N.end (); neigh++) { - nb_tuple = m_state.FindNeighborTuple (twoHopNeigh.neighborMainAddr, OLSR_WILL_NEVER); - if (nb_tuple != NULL) + if (neigh->neighborMainAddr == twoHopNeigh->neighborMainAddr) + { + if (neigh->willingness == OLSR_WILL_NEVER) + { + ok = false; + break; + } + else + { + ok = true; + break; + } + } + } + if (!ok) + { + continue; + } + + // excluding: + // (iii) all the symmetric neighbors: the nodes for which there exists a symmetric + // link to this node on some interface. + for (NeighborSet::const_iterator neigh = N.begin (); + neigh != N.end (); neigh++) + { + if (neigh->neighborMainAddr == twoHopNeigh->twoHopNeighborAddr) { ok = false; - } - else - { - nb_tuple = m_state.FindSymNeighborTuple (twoHopNeigh.neighborMainAddr); - if (nb_tuple != NULL) - ok = false; + break; } } if (ok) - N2.push_back (twoHopNeigh); + { + N2.push_back (*twoHopNeigh); + } } - + // 1. Start with an MPR set made of all members of N with // N_willingness equal to WILL_ALWAYS - for (NeighborSet::const_iterator it = N.begin (); it != N.end (); it++) + for (NeighborSet::const_iterator neighbor = N.begin (); neighbor != N.end (); neighbor++) { - NeighborTuple const &nb_tuple = *it; - if (nb_tuple.willingness == OLSR_WILL_ALWAYS) - m_state.InsertMprAddress (nb_tuple.neighborMainAddr); + if (neighbor->willingness == OLSR_WILL_ALWAYS) + { + mprSet.insert (neighbor->neighborMainAddr); + // (not in RFC but I think is needed: remove the 2-hop + // neighbors reachable by the MPR from N2) + for (TwoHopNeighborSet::iterator twoHopNeigh = N2.begin (); + twoHopNeigh != N2.end (); twoHopNeigh++) + { + if (twoHopNeigh->neighborMainAddr == neighbor->neighborMainAddr) + { + twoHopNeigh = N2.erase (twoHopNeigh); + twoHopNeigh--; + } + } + } } // 2. Calculate D(y), where y is a member of N, for all nodes in N. - // We will do this later. - // FIXME + // (we do this later) // 3. Add to the MPR set those nodes in N, which are the *only* - // nodes to provide reachability to a node in N2. Remove the - // nodes from N2 which are now covered by a node in the MPR set. - MprSet foundset; - std::set deleted_addrs; - for (TwoHopNeighborSet::iterator it = N2.begin (); it != N2.end (); it++) + // nodes to provide reachability to a node in N2. + std::set coveredTwoHopNeighbors; + for (TwoHopNeighborSet::iterator twoHopNeigh = N2.begin (); twoHopNeigh != N2.end (); twoHopNeigh++) { - TwoHopNeighborTuple const &nb2hop_tuple1 = *it; - - MprSet::const_iterator pos = foundset.find (nb2hop_tuple1.twoHopNeighborAddr); - if (pos != foundset.end ()) - continue; - - bool found = false; - for (NeighborSet::const_iterator it2 = N.begin (); - it2 != N.end (); it2++) + NeighborSet::const_iterator onlyNeighbor = N.end (); + + for (NeighborSet::const_iterator neighbor = N.begin (); + neighbor != N.end (); neighbor++) { - if ((*it2).neighborMainAddr == nb2hop_tuple1.neighborMainAddr) { - found = true; - break; - } - } - if (!found) - continue; - - found = false; - for (TwoHopNeighborSet::const_iterator it2 = it + 1; - it2 != N2.end (); it2++) - { - TwoHopNeighborTuple const &nb2hop_tuple2 = *it2; - if (nb2hop_tuple1.twoHopNeighborAddr == nb2hop_tuple2.twoHopNeighborAddr) + if (neighbor->neighborMainAddr == twoHopNeigh->neighborMainAddr) { - foundset.insert (nb2hop_tuple1.twoHopNeighborAddr); - found = true; - break; - } - } - if (!found) - { - m_state.InsertMprAddress (nb2hop_tuple1.neighborMainAddr); - - for (TwoHopNeighborSet::iterator it2 = it + 1; it2 != N2.end (); it2++) - { - TwoHopNeighborTuple const &nb2hop_tuple2 = *it2; - if (nb2hop_tuple1.neighborMainAddr == nb2hop_tuple2.neighborMainAddr) + if (onlyNeighbor == N.end ()) { - deleted_addrs.insert (nb2hop_tuple2.twoHopNeighborAddr); - it2 = N2.erase (it2); - it2--; + onlyNeighbor = neighbor; } - } - it = N2.erase (it); - it--; - } - - for (std::set::iterator it2 = deleted_addrs.begin (); - it2 != deleted_addrs.end (); - it2++) - { - for (TwoHopNeighborSet::iterator it3 = N2.begin (); - it3 != N2.end (); - it3++) - { - if ((*it3).twoHopNeighborAddr == *it2) + else { - it3 = N2.erase (it3); - it3--; - // I have to reset the external iterator because it - // may have been invalidated by the latter deletion - it = N2.begin (); - it--; + onlyNeighbor = N.end (); + break; } } } - deleted_addrs.clear (); + if (onlyNeighbor != N.end ()) + { + mprSet.insert (onlyNeighbor->neighborMainAddr); + coveredTwoHopNeighbors.insert (twoHopNeigh->twoHopNeighborAddr); + } + } + // Remove the nodes from N2 which are now covered by a node in the MPR set. + for (TwoHopNeighborSet::iterator twoHopNeigh = N2.begin (); + twoHopNeigh != N2.end (); twoHopNeigh++) + { + if (coveredTwoHopNeighbors.find (twoHopNeigh->twoHopNeighborAddr) != coveredTwoHopNeighbors.end ()) + { + twoHopNeigh = N2.erase (twoHopNeigh); + twoHopNeigh--; + } } // 4. While there exist nodes in N2 which are not covered by at @@ -664,33 +665,33 @@ AgentImpl::MprComputation() for (std::set::iterator it = rs.begin (); it != rs.end (); it++) { int r = *it; - if (r > 0) + if (r == 0) { - for (std::vector::iterator it2 = reachability[r].begin (); - it2 != reachability[r].end (); - it2++) + continue; + } + for (std::vector::iterator it2 = reachability[r].begin (); + it2 != reachability[r].end (); it2++) + { + const NeighborTuple *nb_tuple = *it2; + if (max == NULL || nb_tuple->willingness > max->willingness) { - const NeighborTuple *nb_tuple = *it2; - if (max == NULL || nb_tuple->willingness > max->willingness) + max = nb_tuple; + max_r = r; + } + else if (nb_tuple->willingness == max->willingness) + { + if (r > max_r) { max = nb_tuple; max_r = r; } - else if (nb_tuple->willingness == max->willingness) + else if (r == max_r) { - if (r > max_r) + if (Degree (*nb_tuple) > Degree (*max)) { max = nb_tuple; max_r = r; } - else if (r == max_r) - { - if (Degree (*nb_tuple) > Degree (*max)) - { - max = nb_tuple; - max_r = r; - } - } } } } @@ -698,33 +699,21 @@ AgentImpl::MprComputation() if (max != NULL) { - m_state.InsertMprAddress (max->neighborMainAddr); - std::set nb2hop_addrs; - for (TwoHopNeighborSet::iterator it = N2.begin (); - it != N2.end (); it++) + mprSet.insert (max->neighborMainAddr); + for (TwoHopNeighborSet::iterator twoHopNeigh = N2.begin (); + twoHopNeigh != N2.end (); twoHopNeigh++) { - TwoHopNeighborTuple const &nb2hop_tuple = *it; - if (nb2hop_tuple.neighborMainAddr == max->neighborMainAddr) + if (twoHopNeigh->neighborMainAddr == max->neighborMainAddr) { - nb2hop_addrs.insert (nb2hop_tuple.twoHopNeighborAddr); - it = N2.erase (it); - it--; - } - } - for (TwoHopNeighborSet::iterator it = N2.begin (); - it != N2.end (); it++) - { - TwoHopNeighborTuple const &nb2hop_tuple = *it; - std::set::iterator it2 = - nb2hop_addrs.find (nb2hop_tuple.twoHopNeighborAddr); - if (it2 != nb2hop_addrs.end ()) - { - it = N2.erase (it); - it--; + twoHopNeigh = N2.erase (twoHopNeigh); + twoHopNeigh--; } } } } + + m_state.SetMprSet (mprSet); + } /// diff --git a/src/routing/olsr/olsr-state.cc b/src/routing/olsr/olsr-state.cc index b44dd8a82..545407a4b 100644 --- a/src/routing/olsr/olsr-state.cc +++ b/src/routing/olsr/olsr-state.cc @@ -246,15 +246,9 @@ OlsrState::FindMprAddress (Ipv4Address const &addr) } void -OlsrState::InsertMprAddress (Ipv4Address const & addr) +OlsrState::SetMprSet (MprSet mprSet) { - m_mprSet.insert (addr); -} - -void -OlsrState::ClearMprSet () -{ - m_mprSet.clear (); + m_mprSet = mprSet; } /********** Duplicate Set Manipulation **********/ diff --git a/src/routing/olsr/olsr-state.h b/src/routing/olsr/olsr-state.h index 45ec80770..3b74e219b 100644 --- a/src/routing/olsr/olsr-state.h +++ b/src/routing/olsr/olsr-state.h @@ -115,8 +115,7 @@ public: // MPR bool FindMprAddress (const Ipv4Address &address); - void InsertMprAddress (const Ipv4Address &address); - void ClearMprSet (); + void SetMprSet (MprSet mprSet); // Duplicate DuplicateTuple* FindDuplicateTuple (const Ipv4Address &address,