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 (peerAddress, &m_testHeader, m_testFrame).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  mac->GetPifs () + mac->GetSlot () + mac->GetEifsNoDifs () + //DIFS + SIFS + AckTxTime = PIFS + SLOT + EifsNoDifs
98  mac->GetWifiPhy ()->CalculateTxDuration (m_testFrame->GetSize (), txVector, mac->GetWifiPhy ()->GetFrequency())
99  ).GetMicroSeconds () / (10.24 * (1.0 - failAvg)));
100  return metric;
101 }
102 } // namespace dot11s
103 } // namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:831
#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
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:97
Hold an unsigned integer type.
Definition: uinteger.h:44
mac
Definition: third.py:92
void SetQosTid(uint8_t tid)
Set the TID for the QoS header.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
an EUI-48 address
Definition: mac48-address.h:43
bool IsGroup(void) const
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
void SetType(WifiMacType type, bool resetToDsFromDs=true)
Set Type/Subtype values with the correct values depending on the given type.
void SetDsTo(void)
Set the To DS bit in the Frame Control field.
void SetDsFrom(void)
Set the From DS bit in the Frame Control field.
A base class which provides memory management and object aggregation.
Definition: object.h:87
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
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915