From 3bb49b6aa42aa58a8ea4234b3a4e6245ed6d8b43 Mon Sep 17 00:00:00 2001 From: Kirill Andreev Date: Tue, 3 Nov 2009 12:50:18 +0300 Subject: [PATCH] Mesh: fixed updating routing information in HWMP, fixed precursor list in routing table --- src/devices/mesh/dot11s/dot11s-test-suite.cc | 4 +- src/devices/mesh/dot11s/hwmp-protocol.cc | 56 ++++++++++---------- src/devices/mesh/dot11s/hwmp-rtable.cc | 46 ++++------------ src/devices/mesh/dot11s/hwmp-rtable.h | 12 +++-- src/devices/mesh/dot11s/ie-dot11s-prep.cc | 1 + src/devices/mesh/dot11s/ie-dot11s-preq.cc | 18 +++---- src/devices/mesh/dot11s/ie-dot11s-rann.cc | 12 ++--- 7 files changed, 65 insertions(+), 84 deletions(-) diff --git a/src/devices/mesh/dot11s/dot11s-test-suite.cc b/src/devices/mesh/dot11s/dot11s-test-suite.cc index 6bea5c65d..5499d866a 100644 --- a/src/devices/mesh/dot11s/dot11s-test-suite.cc +++ b/src/devices/mesh/dot11s/dot11s-test-suite.cc @@ -174,9 +174,9 @@ HwmpRtableTest::TestPrecursorAdd () { for (std::vector::const_iterator i = precursors.begin (); i != precursors.end (); i++) { - table->AddPrecursor (dst, iface, *i); + table->AddPrecursor (dst, iface, *i, Seconds (100)); // Check that duplicates are filtered - table->AddPrecursor (dst, iface, *i); + table->AddPrecursor (dst, iface, *i, Seconds (100)); } } diff --git a/src/devices/mesh/dot11s/hwmp-protocol.cc b/src/devices/mesh/dot11s/hwmp-protocol.cc index acc60136f..33f005124 100644 --- a/src/devices/mesh/dot11s/hwmp-protocol.cc +++ b/src/devices/mesh/dot11s/hwmp-protocol.cc @@ -415,15 +415,18 @@ HwmpProtocol::ReceivePreq (IePreq preq, Mac48Address from, uint32_t interface, M } } } - m_hwmpSeqnoMetricDatabase[preq.GetOriginatorAddress ()] = std::make_pair (preq.GetOriginatorSeqNumber (), preq.GetMetric ()); - + m_hwmpSeqnoMetricDatabase[preq.GetOriginatorAddress ()] = + std::make_pair (preq.GetOriginatorSeqNumber (), preq.GetMetric ()); NS_LOG_DEBUG("I am " << GetAddress () << "Accepted preq from address" << from << ", preq:" << preq); std::vector > destinations = preq.GetDestinationList (); //Add reactive path to originator: if ( - ((m_rtable->LookupReactive (preq.GetOriginatorAddress ())).retransmitter == Mac48Address::GetBroadcast ()) || - ((m_rtable->LookupReactive (preq.GetOriginatorAddress ())).metric > preq.GetMetric ()) + ((int32_t)(i->second.first - preq.GetOriginatorSeqNumber ()) < 0) || + ( + (m_rtable->LookupReactive (preq.GetOriginatorAddress ()).retransmitter == Mac48Address::GetBroadcast ()) || + (m_rtable->LookupReactive (preq.GetOriginatorAddress ()).metric > preq.GetMetric ()) ) + ) { m_rtable->AddReactivePath ( preq.GetOriginatorAddress (), @@ -432,13 +435,12 @@ HwmpProtocol::ReceivePreq (IePreq preq, Mac48Address from, uint32_t interface, M preq.GetMetric (), MicroSeconds (preq.GetLifetime () * 1024), preq.GetOriginatorSeqNumber () - ); + ); ReactivePathResolved (preq.GetOriginatorAddress ()); } - //Add reactive path for precursor: if ( - ((m_rtable->LookupReactive (fromMp)).retransmitter == Mac48Address::GetBroadcast ()) || - ((m_rtable->LookupReactive (fromMp)).metric > preq.GetMetric ()) + (m_rtable->LookupReactive (fromMp).retransmitter == Mac48Address::GetBroadcast ()) || + (m_rtable->LookupReactive (fromMp).metric > metric) ) { m_rtable->AddReactivePath ( @@ -477,15 +479,6 @@ HwmpProtocol::ReceivePreq (IePreq preq, Mac48Address from, uint32_t interface, M preq.GetOriginatorSeqNumber () ); ProactivePathResolved (); - m_rtable->AddReactivePath ( - preq.GetOriginatorAddress (), - from, - interface, - preq.GetMetric (), - MicroSeconds (preq.GetLifetime () * 1024), - preq.GetOriginatorSeqNumber () - ); - ReactivePathResolved (preq.GetOriginatorAddress ()); } if (!preq.IsNeedNotPrep ()) { @@ -493,7 +486,7 @@ HwmpProtocol::ReceivePreq (IePreq preq, Mac48Address from, uint32_t interface, M GetAddress (), preq.GetOriginatorAddress (), from, - preq.GetMetric (), + (uint32_t)0, preq.GetOriginatorSeqNumber (), GetNextHwmpSeqno (), preq.GetLifetime (), @@ -523,9 +516,6 @@ HwmpProtocol::ReceivePreq (IePreq preq, Mac48Address from, uint32_t interface, M if ((! ((*i)->IsDo ())) && (result.retransmitter != Mac48Address::GetBroadcast ())) { //have a valid information and can answer - //!NB: If there is information from peer - set lifetime as - //we have got from PREQ, and set the rest lifetime of the - //route if the information is correct uint32_t lifetime = result.lifetime.GetMicroSeconds () / 1024; if ((lifetime > 0) && ((int32_t)(result.seqnum - (*i)->GetDestSeqNumber ()) >= 0)) { @@ -539,6 +529,8 @@ HwmpProtocol::ReceivePreq (IePreq preq, Mac48Address from, uint32_t interface, M lifetime, interface ); + m_rtable->AddPrecursor ((*i)->GetDestinationAddress (), interface, from, + MicroSeconds (preq.GetLifetime () * 1024)); if ((*i)->IsRf ()) { (*i)->SetFlags (true, false, (*i)->IsUsn ()); //DO = 1, RF = 0 @@ -579,29 +571,35 @@ HwmpProtocol::ReceivePrep (IePrep prep, Mac48Address from, uint32_t interface, M //Now add a path to destination and add precursor to source NS_LOG_DEBUG ("I am " << GetAddress () << ", received prep from " << prep.GetOriginatorAddress () << ", receiver was:" << from); HwmpRtable::LookupResult result = m_rtable->LookupReactive (prep.GetDestinationAddress ()); - //Add a reactive path only if it is better than existing: + //Add a reactive path only if seqno is fresher or it improves the + //metric if ( - ((m_rtable->LookupReactive (prep.GetOriginatorAddress ())).retransmitter == Mac48Address::GetBroadcast ()) || - ((m_rtable->LookupReactive (prep.GetOriginatorAddress ())).metric > prep.GetMetric ()) + (((int32_t)(i->second.first - prep.GetOriginatorSeqNumber ()) < 0)) || + ( + ((m_rtable->LookupReactive (prep.GetOriginatorAddress ())).retransmitter == Mac48Address::GetBroadcast ()) || + ((m_rtable->LookupReactive (prep.GetOriginatorAddress ())).metric > prep.GetMetric ()) ) + ) { m_rtable->AddReactivePath ( prep.GetOriginatorAddress (), from, interface, prep.GetMetric (), - MicroSeconds(prep.GetLifetime () * 1024), + MicroSeconds (prep.GetLifetime () * 1024), prep.GetOriginatorSeqNumber ()); - m_rtable->AddPrecursor (prep.GetDestinationAddress (), interface, from); + m_rtable->AddPrecursor (prep.GetDestinationAddress (), interface, from, + MicroSeconds (prep.GetLifetime () * 1024)); if (result.retransmitter != Mac48Address::GetBroadcast ()) { - m_rtable->AddPrecursor (prep.GetOriginatorAddress (), interface, result.retransmitter); + m_rtable->AddPrecursor (prep.GetOriginatorAddress (), interface, result.retransmitter, + result.lifetime); } ReactivePathResolved (prep.GetOriginatorAddress ()); } if ( ((m_rtable->LookupReactive (fromMp)).retransmitter == Mac48Address::GetBroadcast ()) || - ((m_rtable->LookupReactive (fromMp)).metric > prep.GetMetric ()) + ((m_rtable->LookupReactive (fromMp)).metric > metric) ) { m_rtable->AddReactivePath ( @@ -669,7 +667,7 @@ HwmpProtocol::SendPrep ( prep.SetDestinationAddress (dst); prep.SetDestinationSeqNumber (destinationSN); prep.SetLifetime (lifetime); - prep.SetMetric (0); + prep.SetMetric (initMetric); prep.SetOriginatorAddress (src); prep.SetOriginatorSeqNumber (originatorDsn); HwmpProtocolMacMap::const_iterator prep_sender = m_interfaces.find (interface); diff --git a/src/devices/mesh/dot11s/hwmp-rtable.cc b/src/devices/mesh/dot11s/hwmp-rtable.cc index 9830ba399..2f236d8d3 100644 --- a/src/devices/mesh/dot11s/hwmp-rtable.cc +++ b/src/devices/mesh/dot11s/hwmp-rtable.cc @@ -84,11 +84,12 @@ HwmpRtable::AddProactivePath (uint32_t metric, Mac48Address root, Mac48Address r } void HwmpRtable::AddPrecursor (Mac48Address destination, uint32_t precursorInterface, - Mac48Address precursorAddress) + Mac48Address precursorAddress, Time lifetime) { - std::pair precursor; - precursor.first = precursorInterface; - precursor.second = precursorAddress; + Precursor precursor; + precursor.interface = precursorInterface; + precursor.address = precursorAddress; + precursor.whenExpire = Simulator::Now () + lifetime; std::map::iterator i = m_routes.find (destination); if (i != m_routes.end ()) { @@ -97,9 +98,10 @@ HwmpRtable::AddPrecursor (Mac48Address destination, uint32_t precursorInterface, { //NB: Only one active route may exist, so do not check //interface ID, just address - if (i->second.precursors[j].second == precursorAddress) + if (i->second.precursors[j].address == precursorAddress) { should_add = false; + i->second.precursors[j].whenExpire = precursor.whenExpire; break; } } @@ -108,17 +110,6 @@ HwmpRtable::AddPrecursor (Mac48Address destination, uint32_t precursorInterface, i->second.precursors.push_back (precursor); } } - if (m_root.root == destination) - { - for (unsigned int j = 0; j < m_root.precursors.size (); j++) - { - if (m_root.precursors[j].second == precursorAddress) - { - return; - } - } - } - m_root.precursors.push_back (precursor); } void HwmpRtable::DeleteProactivePath () @@ -221,27 +212,12 @@ HwmpRtable::GetPrecursors (Mac48Address destination) std::map::iterator route = m_routes.find (destination); if (route != m_routes.end ()) { - for (unsigned int i = 0; i < route->second.precursors.size (); i++) + for (std::vector::const_iterator i = route->second.precursors.begin (); + i != route->second.precursors.end (); i++) { - retval.push_back (route->second.precursors[i]); - } - } - if (m_root.root == destination) - { - for (unsigned int i = 0; i < m_root.precursors.size (); i++) - { - bool should_add = true; - for (unsigned int j = 0; j < retval.size (); j++) + if (i->whenExpire > Simulator::Now ()) { - if (retval[j].second == m_root.precursors[i].second) - { - should_add = false; - break; - } - } - if (should_add) - { - retval.push_back (m_root.precursors[i]); + retval.push_back (std::make_pair(i->interface, i->address)); } } } diff --git a/src/devices/mesh/dot11s/hwmp-rtable.h b/src/devices/mesh/dot11s/hwmp-rtable.h index a22e980f5..6997ea9bc 100644 --- a/src/devices/mesh/dot11s/hwmp-rtable.h +++ b/src/devices/mesh/dot11s/hwmp-rtable.h @@ -85,7 +85,7 @@ public: Time lifetime, uint32_t seqnum ); - void AddPrecursor (Mac48Address destination, uint32_t precursorInterface, Mac48Address precursorAddress); + void AddPrecursor (Mac48Address destination, uint32_t precursorInterface, Mac48Address precursorAddress, Time lifetime); PrecursorList GetPrecursors (Mac48Address destination); void DeleteProactivePath (); void DeleteProactivePath (Mac48Address root); @@ -109,6 +109,12 @@ public: private: /// Route found in reactive mode + struct Precursor + { + Mac48Address address; + uint32_t interface; + Time whenExpire; + }; struct ReactiveRoute { Mac48Address retransmitter; @@ -116,7 +122,7 @@ private: uint32_t metric; Time whenExpire; uint32_t seqnum; - std::vector > precursors; + std::vector precursors; }; /// Route fond in proactive mode struct ProactiveRoute @@ -127,7 +133,7 @@ private: uint32_t metric; Time whenExpire; uint32_t seqnum; - std::vector > precursors; + std::vector precursors; }; /// List of routes diff --git a/src/devices/mesh/dot11s/ie-dot11s-prep.cc b/src/devices/mesh/dot11s/ie-dot11s-prep.cc index dd58053cf..6eb4b7dee 100644 --- a/src/devices/mesh/dot11s/ie-dot11s-prep.cc +++ b/src/devices/mesh/dot11s/ie-dot11s-prep.cc @@ -135,6 +135,7 @@ void IePrep::DecrementTtl () { m_ttl--; + m_hopcount ++; } void diff --git a/src/devices/mesh/dot11s/ie-dot11s-preq.cc b/src/devices/mesh/dot11s/ie-dot11s-preq.cc index 40e749f06..55b9403fd 100644 --- a/src/devices/mesh/dot11s/ie-dot11s-preq.cc +++ b/src/devices/mesh/dot11s/ie-dot11s-preq.cc @@ -317,17 +317,17 @@ void IePreq::Print (std::ostream &os) const { os << std::endl << "" << std::endl; - os << " originator address = " << m_originatorAddress << "std::endl"; - os << " TTL = " << (uint16_t) m_ttl << "std::endl"; - os << " hop count = " << (uint16_t) m_hopCount << "std::endl"; - os << " metric = " << m_metric << "std::endl"; - os << " seqno = " << m_originatorSeqNumber << "std::endl"; - os << " lifetime = " << m_lifetime << "std::endl"; - os << " preq ID = " << m_preqId << "std::endl"; - os << " Destinations are:std::endl"; + os << " originator address = " << m_originatorAddress << std::endl; + os << " TTL = " << (uint16_t) m_ttl << std::endl; + os << " hop count = " << (uint16_t) m_hopCount << std::endl; + os << " metric = " << m_metric << std::endl; + os << " seqno = " << m_originatorSeqNumber << std::endl; + os << " lifetime = " << m_lifetime << std::endl; + os << " preq ID = " << m_preqId << std::endl; + os << " Destinations are:" << std::endl; for (int j = 0; j < m_destCount; j++) { - os << " " << m_destinations[j]->GetDestinationAddress () << "std::endl"; + os << " " << m_destinations[j]->GetDestinationAddress () << std::endl; } os << "" << std::endl; } diff --git a/src/devices/mesh/dot11s/ie-dot11s-rann.cc b/src/devices/mesh/dot11s/ie-dot11s-rann.cc index 8b5ad2887..ea1bc9279 100644 --- a/src/devices/mesh/dot11s/ie-dot11s-rann.cc +++ b/src/devices/mesh/dot11s/ie-dot11s-rann.cc @@ -152,12 +152,12 @@ void IeRann::Print (std::ostream &os) const { os << std::endl << "" << std::endl; - os << " flags = " << (int) m_flags << "std::endl"; - os << " hop count = " << (int) m_hopcount << "std::endl"; - os << " TTL = " << (int) m_ttl << "std::endl"; - os << " originator address = " << m_originatorAddress << "std::endl"; - os << " dst seq. number = " << m_destSeqNumber << "std::endl"; - os << " metric = " << m_metric << "std::endl"; + os << " flags = " << (int) m_flags << std::endl; + os << " hop count = " << (int) m_hopcount << std::endl; + os << " TTL = " << (int) m_ttl << std::endl; + os << " originator address = " << m_originatorAddress << std::endl; + os << " dst seq. number = " << m_destSeqNumber << std::endl; + os << " metric = " << m_metric << std::endl; os << "" << std::endl; }