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  .AddAttribute ( "Dot11sMeshHeaderLength",
50  "Length of the mesh header",
51  UintegerValue (6),
52  MakeUintegerAccessor (
54  MakeUintegerChecker<uint16_t> (0)
55  )
56  ;
57  return tid;
58 }
60  m_overheadNanosec (0)
61 {
62 }
63 void
65 {
69  m_testHeader.SetQosTid (tid);
70 }
71 void
73 {
74  m_testFrame = Create<Packet> (testLength + 6 /*Mesh header*/ + 36 /*802.11 header*/);
75 }
76 uint32_t
78 {
79  /* Airtime link metric is defined in 11B.10 of 802.11s Draft D3.0 as:
80  *
81  * airtime = (O + Bt/r) / (1 - frame error rate), where
82  * o -- the PHY dependent channel access which includes frame headers, training sequences,
83  * access protocol frames, etc.
84  * bt -- the test packet length in bits (8192 by default),
85  * r -- the current bitrate of the packet,
86  *
87  * Final result is expressed in units of 0.01 Time Unit = 10.24 us (as required by 802.11s draft)
88  */
89  NS_ASSERT (!peerAddress.IsGroup ());
90  //obtain current rate:
91  WifiMode mode = mac->GetWifiRemoteStationManager ()->GetDataTxVector (peerAddress, &m_testHeader, m_testFrame, m_testFrame->GetSize ()).GetMode();
92  //obtain frame error rate:
93  double failAvg = mac->GetWifiRemoteStationManager ()->GetInfo (peerAddress).GetFrameErrorRate ();
94  if (failAvg == 1)
95  {
96  // Retrun max metric value when frame error rate equals to 1
97  return (uint32_t)0xffffffff;
98  }
99  NS_ASSERT (failAvg < 1.0);
100  WifiTxVector txVector;
101  txVector.SetMode (mode);
102  //calculate metric
103  uint32_t metric = (uint32_t)((double)( /*Overhead + payload*/
104  mac->GetPifs () + mac->GetSlot () + mac->GetEifsNoDifs () + //DIFS + SIFS + AckTxTime = PIFS + SLOT + EifsNoDifs
106  ).GetMicroSeconds () / (10.24 * (1.0 - failAvg)));
107  return metric;
108 }
109 } // namespace dot11s
110 } // namespace ns3