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