diff --git a/src/devices/mesh/dot11s/hwmp-protocol-mac.cc b/src/devices/mesh/dot11s/hwmp-protocol-mac.cc index fc8986a27..45ee23260 100644 --- a/src/devices/mesh/dot11s/hwmp-protocol-mac.cc +++ b/src/devices/mesh/dot11s/hwmp-protocol-mac.cc @@ -170,43 +170,9 @@ HwmpProtocolMac::UpdateOutcomingFrame (Ptr packet, WifiMacHeader & heade void HwmpProtocolMac::SendPreq(IePreq preq) { - m_preqQueue.push_back (preq); - SendOnePreq (); -} -void -HwmpProtocolMac::RequestDestination (Mac48Address dst, uint32_t originator_seqno, uint32_t dst_seqno) -{ - for(std::vector::iterator i = m_preqQueue.begin (); i != m_preqQueue.end (); i ++) - if(i->MayAddAddress(m_protocol->GetAddress ())) - { - i->AddDestinationAddressElement (m_protocol->GetDoFlag(), m_protocol->GetRfFlag(), dst, dst_seqno); - return; - } - IePreq preq; - //fill PREQ: - preq.SetHopcount (0); - preq.SetTTL (m_protocol->GetMaxTtl ()); - preq.SetPreqID (m_protocol->GetNextPreqId ()); - preq.SetOriginatorAddress (m_protocol->GetAddress ()); - preq.SetOriginatorSeqNumber (originator_seqno); - preq.SetLifetime (m_protocol->GetActivePathLifetime ()); - preq.AddDestinationAddressElement (m_protocol->GetDoFlag (), m_protocol->GetRfFlag (), dst, dst_seqno); - m_preqQueue.push_back (preq); - //set iterator position to my preq: - SendOnePreq (); -} -void -HwmpProtocolMac::SendOnePreq () -{ - if(m_preqTimer.IsRunning ()) - return; - if (m_preqQueue.size () == 0) - return; - //reschedule sending PREQ - NS_ASSERT (!m_preqTimer.IsRunning()); - m_preqTimer = Simulator::Schedule (m_protocol->GetPreqMinInterval (), &HwmpProtocolMac::SendOnePreq, this); - Ptr packet = Create (); - packet->AddHeader(m_preqQueue[0]); + NS_LOG_FUNCTION_NOARGS (); + Ptr packet = Create (); + packet->AddHeader(preq); //Action header: WifiMeshActionHeader actionHdr; WifiMeshActionHeader::ActionValue action; @@ -230,12 +196,41 @@ HwmpProtocolMac::SendOnePreq () m_stats.txMgtBytes += packet->GetSize (); m_parent->SendManagementFrame(packet, hdr); } - //erase queue - m_preqQueue.erase (m_preqQueue.begin()); +} +void +HwmpProtocolMac::RequestDestination (Mac48Address dst, uint32_t originator_seqno, uint32_t dst_seqno) +{ + NS_LOG_FUNCTION_NOARGS (); + if(m_myPreq.GetDestCount () == 0) + { + m_myPreq.SetHopcount (0); + m_myPreq.SetTTL (m_protocol->GetMaxTtl ()); + m_myPreq.SetPreqID (m_protocol->GetNextPreqId ()); + m_myPreq.SetOriginatorAddress (m_protocol->GetAddress ()); + m_myPreq.SetOriginatorSeqNumber (originator_seqno); + m_myPreq.SetLifetime (m_protocol->GetActivePathLifetime ()); + } + m_myPreq.AddDestinationAddressElement (m_protocol->GetDoFlag(), m_protocol->GetRfFlag(), dst, dst_seqno); + SendMyPreq (); +} +void +HwmpProtocolMac::SendMyPreq () +{ + NS_LOG_FUNCTION_NOARGS (); + if(m_preqTimer.IsRunning ()) + return; + if(m_myPreq.GetDestCount () == 0) + return; + //reschedule sending PREQ + NS_ASSERT (!m_preqTimer.IsRunning()); + m_preqTimer = Simulator::Schedule (m_protocol->GetPreqMinInterval (), &HwmpProtocolMac::SendMyPreq, this); + SendPreq (m_myPreq); + m_myPreq.ClearDestinationAddressElements (); } void HwmpProtocolMac::SendOnePerr() { + NS_LOG_FUNCTION_NOARGS (); if(m_perrTimer.IsRunning ()) return; if(m_myPerr.receivers.size () >= m_protocol->GetUnicastPerrThreshold ()) @@ -275,6 +270,7 @@ HwmpProtocolMac::SendOnePerr() void HwmpProtocolMac::SendPrep (IePrep prep, Mac48Address receiver) { + NS_LOG_FUNCTION_NOARGS (); //Create packet Ptr packet = Create (); packet->AddHeader(prep); @@ -301,6 +297,7 @@ HwmpProtocolMac::SendPrep (IePrep prep, Mac48Address receiver) void HwmpProtocolMac::SendPerr(IePerr perr, std::vector receivers) { + NS_LOG_FUNCTION_NOARGS (); m_myPerr.perr.Merge(perr); for(unsigned int i = 0; i < receivers.size (); i ++) { diff --git a/src/devices/mesh/dot11s/hwmp-protocol-mac.h b/src/devices/mesh/dot11s/hwmp-protocol-mac.h index 97c37a757..defd108a0 100644 --- a/src/devices/mesh/dot11s/hwmp-protocol-mac.h +++ b/src/devices/mesh/dot11s/hwmp-protocol-mac.h @@ -23,6 +23,7 @@ #define HWMP_STATE_H #include "ns3/mesh-wifi-interface-mac-plugin.h" +#include "ie-dot11s-preq.h" #include "ie-dot11s-perr.h" namespace ns3 { @@ -73,7 +74,7 @@ private: //\} /// Sends one PREQ when PreqMinInterval after last PREQ expires (if any PREQ exists in rhe queue) - void SendOnePreq (); + void SendMyPreq (); void SendOnePerr (); /// \return metric to HWMP protocol, needed only by metrics to add //peer as routing entry @@ -87,10 +88,10 @@ private: uint32_t m_ifIndex; Ptr m_protocol; - ///\name PREQ queue and PREQ timer: + ///\name my PREQ and PREQ timer: //\{ - EventId m_preqTimer; - std::vector m_preqQueue; + EventId m_preqTimer; + IePreq m_myPreq; //\} ///\name PERR timer and stored path error //\{ diff --git a/src/devices/mesh/dot11s/ie-dot11s-preq.cc b/src/devices/mesh/dot11s/ie-dot11s-preq.cc index c095f97d4..54d37fda1 100644 --- a/src/devices/mesh/dot11s/ie-dot11s-preq.cc +++ b/src/devices/mesh/dot11s/ie-dot11s-preq.cc @@ -355,7 +355,7 @@ IePreq::DelDestinationAddressElement (Mac48Address dest_address) } } void -IePreq::ClearDestinationAddressElement () +IePreq::ClearDestinationAddressElements () { int i; for (std::vector >::iterator j = m_destinations.begin (); j != m_destinations.end(); j++) @@ -363,6 +363,7 @@ IePreq::ClearDestinationAddressElement () for (i = 0; i < m_destCount; i ++) m_destinations.pop_back (); m_destinations.clear (); + m_destCount = 0; } bool operator== (const DestinationAddressUnit & a, const DestinationAddressUnit & b) { diff --git a/src/devices/mesh/dot11s/ie-dot11s-preq.h b/src/devices/mesh/dot11s/ie-dot11s-preq.h index cb7cf9c19..f5c93695f 100644 --- a/src/devices/mesh/dot11s/ie-dot11s-preq.h +++ b/src/devices/mesh/dot11s/ie-dot11s-preq.h @@ -64,20 +64,30 @@ class IePreq : public WifiInformationElement public: IePreq (); ~IePreq (); + /** + * Add a destination address unit: flags, destination and sequence + * number + */ void AddDestinationAddressElement ( bool doFlag, bool rfFlag, Mac48Address dest_address, uint32_t dest_seq_number ); + /// Delete a destination address unit by destination void DelDestinationAddressElement (Mac48Address dest_address); - void ClearDestinationAddressElement (); + /// Clear PREQ: remove all destinations + void ClearDestinationAddressElements (); + /// Get all destinations, which are stored in PREQ: std::vector > GetDestinationList (); + /// SetProper flags which indicate that PREQ is unicast void SetUnicastPreq (); /* * \brief In proactive case: need we send PREP */ void SetNeedNotPrep (); + ///\name Setters for fields: + ///\{ void SetHopcount (uint8_t hopcount); void SetTTL (uint8_t ttl); void SetPreqID (uint32_t id); @@ -86,7 +96,9 @@ public: void SetLifetime (uint32_t lifetime); void SetMetric (uint32_t metric); void SetDestCount (uint8_t dest_count); - + ///\} + ///\name Getters for fields: + ///\{ bool IsUnicastPreq () const; bool IsNeedNotPrep () const; uint8_t GetHopCount () const; @@ -97,6 +109,8 @@ public: uint32_t GetLifetime () const; uint32_t GetMetric () const; uint8_t GetDestCount () const; + ///\} + /// Handle TTL and Metric: void DecrementTtl (); void IncrementMetric (uint32_t metric); /*