A Discrete-Event Network Simulator
API
airtime-metric.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 IITP RAS
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Authors: Kirill Andreev <andreev@iitp.ru>
19  */
20 
21 #include "airtime-metric.h"
22 #include "ns3/wifi-phy.h"
23 
24 namespace ns3 {
25 namespace dot11s {
27 
28 TypeId
30 {
31  static TypeId tid = TypeId ("ns3::dot11s::AirtimeLinkMetricCalculator")
32  .SetParent<Object> ()
33  .SetGroupName ("Mesh")
34  .AddConstructor<AirtimeLinkMetricCalculator> ()
35  .AddAttribute ( "TestLength",
36  "Number of bytes in test frame (a constant 1024 in the standard)",
37  UintegerValue (1024),
40  MakeUintegerChecker<uint16_t> (1)
41  )
42  .AddAttribute ( "Dot11MetricTid",
43  "TID used to calculate metric (data rate)",
44  UintegerValue (0),
47  MakeUintegerChecker<uint8_t> (0)
48  )
49  ;
50  return tid;
51 }
53 {
54 }
55 void
57 {
61  m_testHeader.SetQosTid (tid);
62 }
63 void
65 {
66  m_testFrame = Create<Packet> (testLength + 6 /*Mesh header*/ + 36 /*802.11 header*/);
67 }
68 uint32_t
70 {
71  /* Airtime link metric is defined in Section 13.9 of 802.11-2012 as:
72  *
73  * airtime = (O + Bt/r) / (1 - frame error rate), where
74  * o -- the PHY dependent channel access which includes frame headers, training sequences,
75  * access protocol frames, etc.
76  * bt -- the test packet length in bits (8192 by default),
77  * r -- the current bitrate of the packet,
78  *
79  * Final result is expressed in units of 0.01 Time Unit = 10.24 us (as required by 802.11s draft)
80  */
81  NS_ASSERT (!peerAddress.IsGroup ());
82  //obtain current rate:
83  WifiMode mode = mac->GetWifiRemoteStationManager ()->GetDataTxVector (m_testHeader).GetMode();
84  //obtain frame error rate:
85  double failAvg = mac->GetWifiRemoteStationManager ()->GetInfo (peerAddress).GetFrameErrorRate ();
86  if (failAvg == 1)
87  {
88  // Return max metric value when frame error rate equals to 1
89  return (uint32_t) 0xffffffff;
90  }
91  NS_ASSERT (failAvg < 1.0);
92  WifiTxVector txVector;
93  txVector.SetMode (mode);
95  //calculate metric
96  uint32_t metric = (uint32_t)((double)( /*Overhead + payload*/
97  //DIFS + SIFS + AckTxTime = 2 * SIFS + 2 * SLOT + AckTxTime
98  2 * mac->GetWifiPhy ()->GetSifs () + 2 * mac->GetWifiPhy ()->GetSlot ()
99  + mac->GetWifiPhy ()->GetAckTxTime ()
100  + mac->GetWifiPhy ()->CalculateTxDuration (m_testFrame->GetSize (), txVector, mac->GetWifiPhy ()->GetPhyBand())
101  ).GetMicroSeconds () / (10.24 * (1.0 - failAvg)));
102  return metric;
103 }
104 } // namespace dot11s
105 } // namespace ns3
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
NS_ASSERT
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:67
ns3::Mac48Address::IsGroup
bool IsGroup(void) const
Definition: mac48-address.cc:164
ns3::Packet::GetSize
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:852
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::WifiMacHeader::SetDsTo
void SetDsTo(void)
Set the To DS bit in the Frame Control field.
Definition: wifi-mac-header.cc:96
airtime-metric.h
ns3::Mac48Address
an EUI-48 address
Definition: mac48-address.h:44
ns3::WifiTxVector::SetMode
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
Definition: wifi-tx-vector.cc:226
ns3::WifiTxVector
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
Definition: wifi-tx-vector.h:71
third.mac
mac
Definition: third.py:99
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
ns3::WifiMode
represent a single transmission mode
Definition: wifi-mode.h:48
ns3::Object
A base class which provides memory management and object aggregation.
Definition: object.h:88
ns3::WIFI_PREAMBLE_LONG
@ WIFI_PREAMBLE_LONG
Definition: wifi-phy-common.h:69
ns3::WIFI_MAC_DATA
@ WIFI_MAC_DATA
Definition: wifi-mac-header.h:62
ns3::WifiMacHeader::SetType
void SetType(WifiMacType type, bool resetToDsFromDs=true)
Set Type/Subtype values with the correct values depending on the given type.
Definition: wifi-mac-header.cc:132
ns3::UintegerValue
Hold an unsigned integer type.
Definition: uinteger.h:44
ns3::MakeUintegerAccessor
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: uinteger.h:45
ns3::WifiMacHeader::SetQosTid
void SetQosTid(uint8_t tid)
Set the TID for the QoS header.
Definition: wifi-mac-header.cc:352
ns3::WifiTxVector::SetPreambleType
void SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
Definition: wifi-tx-vector.cc:248
ns3::WifiMacHeader::SetDsFrom
void SetDsFrom(void)
Set the From DS bit in the Frame Control field.
Definition: wifi-mac-header.cc:84