A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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-remote-station-manager.h"
23 #include "ns3/wifi-mode.h"
24 #include "ns3/wifi-tx-vector.h"
25 
26 namespace ns3 {
27 namespace dot11s {
29 TypeId
31 {
32  static TypeId tid = TypeId ("ns3::dot11s::AirtimeLinkMetricCalculator")
33  .SetParent<Object> ()
34  .AddConstructor<AirtimeLinkMetricCalculator> ()
35  .AddAttribute ( "TestLength",
36  "Rate should be estimated using test length.",
37  UintegerValue (1024),
38  MakeUintegerAccessor (
40  MakeUintegerChecker<uint16_t> (1)
41  )
42  .AddAttribute ( "Dot11MetricTid",
43  "TID used to calculate metric (data rate)",
44  UintegerValue (0),
45  MakeUintegerAccessor (
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 11B.10 of 802.11s Draft D3.0 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, m_testFrame->GetSize ()).GetMode();
84  //obtain frame error rate:
85  double failAvg = mac->GetWifiRemoteStationManager ()->GetInfo (peerAddress).GetFrameErrorRate ();
86  if (failAvg == 1)
87  {
88  // Retrun 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);
94  //calculate metric
95  uint32_t metric = (uint32_t)((double)( /*Overhead + payload*/
96  mac->GetPifs () + mac->GetSlot () + mac->GetEifsNoDifs () + //DIFS + SIFS + AckTxTime = PIFS + SLOT + EifsNoDifs
97  mac->GetWifiPhy ()->CalculateTxDuration (m_testFrame->GetSize (), txVector, WIFI_PREAMBLE_LONG)
98  ).GetMicroSeconds () / (10.24 * (1.0 - failAvg)));
99  return metric;
100 }
101 } // namespace dot11s
102 } // namespace ns3
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
#define NS_ASSERT(condition)
Definition: assert.h:64
uint32_t GetSize(void) const
Definition: packet.h:650
NS_OBJECT_ENSURE_REGISTERED(AirtimeLinkMetricCalculator)
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:91
Hold an unsigned integer type.
Definition: uinteger.h:46
void SetQosTid(uint8_t tid)
bool IsGroup(void) const
an EUI-48 address
Definition: mac48-address.h:41
void SetMode(WifiMode mode)
a base class which provides memory management and object aggregation
Definition: object.h:63
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610