diff --git a/src/devices/mesh/dot11s/airtime-metric.cc b/src/devices/mesh/dot11s/airtime-metric.cc new file mode 100644 index 000000000..98905cd63 --- /dev/null +++ b/src/devices/mesh/dot11s/airtime-metric.cc @@ -0,0 +1,17 @@ +#include "airtime-metric.h" +#include "ns3/wifi-remote-station-manager.h" +#include "ns3/wifi-mode.h" +namespace ns3 { +namespace dot11s { +uint32_t +AirtimeLinkMetricCalculator::CalculateMetric(Mac48Address peerAddress, Ptr mac) +{ + WifiRemoteStation * station = mac->GetStationManager ()->Lookup(peerAddress); + Ptr test_frame = Create (1024); + uint32_t rate = station->GetDataMode(test_frame, 1024+36).GetDataRate (); + uint32_t payload_nanosec = (uint32_t)((double)(1024*8) / ((double)rate)*1e9); + uint32_t metric = (uint32_t)(((double)(payload_nanosec + overhead*1000))/102.4); + return metric; +} +} //namespace dot11s +} //namespace ns3 diff --git a/src/devices/mesh/dot11s/airtime-metric.h b/src/devices/mesh/dot11s/airtime-metric.h new file mode 100644 index 000000000..89104ece4 --- /dev/null +++ b/src/devices/mesh/dot11s/airtime-metric.h @@ -0,0 +1,21 @@ +#ifndef AIRTIME_METRIC_H +#define AIRTIME_METRIC_H +#include "ns3/mesh-wifi-interface-mac.h" +namespace ns3 { +namespace dot11s { +class AirtimeLinkMetricCalculator : public RefCountBase +{ + public: + friend class MeshWifiInterfaceMac; + uint32_t CalculateMetric(Mac48Address peerAddress, Ptr mac); + private: + ///\Microseconds of overhead: + static const uint32_t overhead = + 34 //DIFS + +9*2 //SIFS + +16*2//Preamble + +24; //Ack duration +}; +} //namespace dot11s +} //namespace ns3 +#endif diff --git a/src/devices/mesh/dot11s/dot11s-helper.cc b/src/devices/mesh/dot11s/dot11s-helper.cc index c70231b76..5eb305167 100644 --- a/src/devices/mesh/dot11s/dot11s-helper.cc +++ b/src/devices/mesh/dot11s/dot11s-helper.cc @@ -29,6 +29,7 @@ #include "ns3/wifi-remote-station-manager.h" #include "ns3/mesh-wifi-interface-mac.h" #include "ns3/aarf-wifi-manager.h" +#include "airtime-metric.h" namespace ns3 { namespace dot11s { @@ -80,6 +81,8 @@ MeshWifiHelper::CreateInterface (const WifiPhyHelper &phyHelper, Ptr node) device->SetMac (mac); device->SetPhy (phy); device->SetRemoteStationManager (manager); + Ptr metric = Create (); + mac->SetLinkMetricCallback (MakeCallback(&AirtimeLinkMetricCalculator::CalculateMetric, metric)); /* if (channel > 0) mac->SwitchFrequencyChannel (channel); diff --git a/src/devices/mesh/dot11s/hwmp-protocol.cc b/src/devices/mesh/dot11s/hwmp-protocol.cc index b9c88fa90..39006ec68 100644 --- a/src/devices/mesh/dot11s/hwmp-protocol.cc +++ b/src/devices/mesh/dot11s/hwmp-protocol.cc @@ -291,7 +291,7 @@ HwmpProtocol::ForwardUnicast(uint32_t sourceIface, const Mac48Address source, c void HwmpProtocol::ReceivePreq (IePreq preq, Mac48Address from, uint32_t interface, uint32_t metric) { - preq.IncrementMetric (1); + preq.IncrementMetric (metric); //acceptance cretirea: std::map::const_iterator i = m_lastHwmpSeqno.find (preq.GetOriginatorAddress()); if (i == m_lastHwmpSeqno.end ()) @@ -314,7 +314,7 @@ HwmpProtocol::ReceivePreq (IePreq preq, Mac48Address from, uint32_t interface, u m_lastHwmpSeqno[preq.GetOriginatorAddress ()] = preq.GetOriginatorSeqNumber(); m_lastHwmpMetric[preq.GetOriginatorAddress ()] = preq.GetMetric(); } - NS_LOG_DEBUG("I am "< > destinations = preq.GetDestinationList (); for (std::vector >::const_iterator i = destinations.begin (); i != destinations.end(); i++) @@ -528,8 +528,8 @@ HwmpProtocol::PeerLinkStatus(Mac48Address meshPointAddress, Mac48Address peerAdd HwmpRtable::LookupResult result = m_rtable->LookupReactive(meshPointAddress); HwmpPluginMap::const_iterator i = m_interfaces.find(interface); NS_ASSERT(i != m_interfaces.end ()); - if(result.retransmitter == Mac48Address::GetBroadcast ()) - m_rtable->AddReactivePath(meshPointAddress, peerAddress, interface, 1, Seconds (0), i->second->GetLinkMetric(peerAddress)); + //if(result.retransmitter == Mac48Address::GetBroadcast ()) + // m_rtable->AddReactivePath(meshPointAddress, peerAddress, interface, 1, Seconds (0), i->second->GetLinkMetric(peerAddress)); } else { diff --git a/src/devices/mesh/dot11s/wscript b/src/devices/mesh/dot11s/wscript index 2188a0a1b..f4dfa8d19 100644 --- a/src/devices/mesh/dot11s/wscript +++ b/src/devices/mesh/dot11s/wscript @@ -18,6 +18,7 @@ def build(bld): 'hwmp-rtable.cc', 'hwmp-mac-plugin.cc', 'hwmp-protocol.cc', + 'airtime-metric.cc', 'dot11s-helper.cc', ] headers = bld.new_task_gen('ns3header') diff --git a/src/devices/mesh/mesh-wifi-interface-mac.cc b/src/devices/mesh/mesh-wifi-interface-mac.cc index 27508fe27..6877c86d0 100644 --- a/src/devices/mesh/mesh-wifi-interface-mac.cc +++ b/src/devices/mesh/mesh-wifi-interface-mac.cc @@ -598,7 +598,20 @@ MeshWifiInterfaceMac::Receive (Ptr packet, WifiMacHeader const *hdr) uint32_t MeshWifiInterfaceMac::GetLinkMetric (Mac48Address peerAddress) { - return 1; + uint32_t metric = 1; + if(!m_linkMetricCallback.IsNull ()) + metric = m_linkMetricCallback(peerAddress, this); + return metric; +} +void +MeshWifiInterfaceMac::SetLinkMetricCallback (Callback > cb) +{ + m_linkMetricCallback = cb; +} +Ptr +MeshWifiInterfaceMac::GetStationManager() +{ + return m_stationManager; } } // namespace ns3 diff --git a/src/devices/mesh/mesh-wifi-interface-mac.h b/src/devices/mesh/mesh-wifi-interface-mac.h index 8648c85cf..5acdaa8bc 100644 --- a/src/devices/mesh/mesh-wifi-interface-mac.h +++ b/src/devices/mesh/mesh-wifi-interface-mac.h @@ -146,7 +146,12 @@ public: bool CheckSupportedRates(SupportedRates rates) const; /// \return list of supported bitrates SupportedRates GetSupportedRates () const; + ///\ name Metric Calculation routines: + ///\{ + void SetLinkMetricCallback(Callback > cb); uint32_t GetLinkMetric(Mac48Address peerAddress); + Ptr GetStationManager (); + ///\} private: /// Frame receive handler void Receive (Ptr packet, WifiMacHeader const *hdr); @@ -215,6 +220,7 @@ private: typedef std::vector< Ptr > PluginList; /// List of all installed plugins PluginList m_plugins; + Callback > m_linkMetricCallback; }; } // namespace ns3