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  ;
30 
31 TypeId
33 {
34  static TypeId tid = TypeId ("ns3::dot11s::AirtimeLinkMetricCalculator")
35  .SetParent<Object> ()
36  .AddConstructor<AirtimeLinkMetricCalculator> ()
37  .AddAttribute ( "TestLength",
38  "Rate should be estimated using test length.",
39  UintegerValue (1024),
40  MakeUintegerAccessor (
42  MakeUintegerChecker<uint16_t> (1)
43  )
44  .AddAttribute ( "Dot11MetricTid",
45  "TID used to calculate metric (data rate)",
46  UintegerValue (0),
47  MakeUintegerAccessor (
49  MakeUintegerChecker<uint8_t> (0)
50  )
51  ;
52  return tid;
53 }
55 {
56 }
57 void
59 {
63  m_testHeader.SetQosTid (tid);
64 }
65 void
67 {
68  m_testFrame = Create<Packet> (testLength + 6 /*Mesh header*/ + 36 /*802.11 header*/);
69 }
70 uint32_t
72 {
73  /* Airtime link metric is defined in 11B.10 of 802.11s Draft D3.0 as:
74  *
75  * airtime = (O + Bt/r) / (1 - frame error rate), where
76  * o -- the PHY dependent channel access which includes frame headers, training sequences,
77  * access protocol frames, etc.
78  * bt -- the test packet length in bits (8192 by default),
79  * r -- the current bitrate of the packet,
80  *
81  * Final result is expressed in units of 0.01 Time Unit = 10.24 us (as required by 802.11s draft)
82  */
83  NS_ASSERT (!peerAddress.IsGroup ());
84  //obtain current rate:
85  WifiMode mode = mac->GetWifiRemoteStationManager ()->GetDataTxVector (peerAddress, &m_testHeader, m_testFrame, m_testFrame->GetSize ()).GetMode();
86  //obtain frame error rate:
87  double failAvg = mac->GetWifiRemoteStationManager ()->GetInfo (peerAddress).GetFrameErrorRate ();
88  if (failAvg == 1)
89  {
90  // Retrun max metric value when frame error rate equals to 1
91  return (uint32_t)0xffffffff;
92  }
93  NS_ASSERT (failAvg < 1.0);
94  WifiTxVector txVector;
95  txVector.SetMode (mode);
96  //calculate metric
97  uint32_t metric = (uint32_t)((double)( /*Overhead + payload*/
98  mac->GetPifs () + mac->GetSlot () + mac->GetEifsNoDifs () + //DIFS + SIFS + AckTxTime = PIFS + SLOT + EifsNoDifs
99  mac->GetWifiPhy ()->CalculateTxDuration (m_testFrame->GetSize (), txVector, WIFI_PREAMBLE_LONG)
100  ).GetMicroSeconds () / (10.24 * (1.0 - failAvg)));
101  return metric;
102 }
103 } // namespace dot11s
104 } // namespace ns3
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
#define NS_ASSERT(condition)
Definition: assert.h:64
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
uint32_t GetSize(void) const
Definition: packet.h:650
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)
Set the TID for the QoS header.
bool IsGroup(void) const
an EUI-48 address
Definition: mac48-address.h:41
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
void SetTypeData(void)
Set Type/Subtype values for a data packet with no subtype equal to 0.
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:63
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611