Added airtime link metric. packet error rate is not done yet

This commit is contained in:
Kirill Andreev
2009-04-08 12:55:03 +04:00
parent 95cc866cc3
commit 38d5a32df1
7 changed files with 66 additions and 5 deletions

View File

@@ -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<MeshWifiInterfaceMac> mac)
{
WifiRemoteStation * station = mac->GetStationManager ()->Lookup(peerAddress);
Ptr<Packet> test_frame = Create<Packet> (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

View File

@@ -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<MeshWifiInterfaceMac> 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

View File

@@ -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> node)
device->SetMac (mac);
device->SetPhy (phy);
device->SetRemoteStationManager (manager);
Ptr<AirtimeLinkMetricCalculator> metric = Create <AirtimeLinkMetricCalculator> ();
mac->SetLinkMetricCallback (MakeCallback(&AirtimeLinkMetricCalculator::CalculateMetric, metric));
/*
if (channel > 0)
mac->SwitchFrequencyChannel (channel);

View File

@@ -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<Mac48Address, uint32_t>::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 "<<m_address<<"Accepted preq from address"<<from<<", preq:"<<preq);
NS_LOG_UNCOND("I am "<<m_address<<"Accepted preq from address"<<from<<", preq:"<<preq);
//check if can answer:
std::vector<Ptr<DestinationAddressUnit> > destinations = preq.GetDestinationList ();
for (std::vector<Ptr<DestinationAddressUnit> >::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
{

View File

@@ -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')

View File

@@ -598,7 +598,20 @@ MeshWifiInterfaceMac::Receive (Ptr<Packet> 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<uint32_t, Mac48Address, Ptr<MeshWifiInterfaceMac> > cb)
{
m_linkMetricCallback = cb;
}
Ptr<WifiRemoteStationManager>
MeshWifiInterfaceMac::GetStationManager()
{
return m_stationManager;
}
} // namespace ns3

View File

@@ -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<uint32_t, Mac48Address, Ptr<MeshWifiInterfaceMac> > cb);
uint32_t GetLinkMetric(Mac48Address peerAddress);
Ptr<WifiRemoteStationManager> GetStationManager ();
///\}
private:
/// Frame receive handler
void Receive (Ptr<Packet> packet, WifiMacHeader const *hdr);
@@ -215,6 +220,7 @@ private:
typedef std::vector< Ptr<MeshWifiInterfaceMacPlugin> > PluginList;
/// List of all installed plugins
PluginList m_plugins;
Callback<uint32_t, Mac48Address, Ptr<MeshWifiInterfaceMac> > m_linkMetricCallback;
};
} // namespace ns3