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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Kirill Andreev <andreev@iitp.ru>
7 */
8
9#include "airtime-metric.h"
10
11#include "ns3/wifi-phy.h"
12
13namespace ns3
14{
15namespace dot11s
16{
18
21{
22 static TypeId tid =
23 TypeId("ns3::dot11s::AirtimeLinkMetricCalculator")
25 .SetGroupName("Mesh")
26 .AddConstructor<AirtimeLinkMetricCalculator>()
27 .AddAttribute("TestLength",
28 "Number of bytes in test frame (a constant 1024 in the standard)",
29 UintegerValue(1024),
32 .AddAttribute("Dot11MetricTid",
33 "TID used to calculate metric (data rate)",
37 return tid;
38}
39
43
44void
52
53void
55{
56 m_testFrame = Create<Packet>(testLength + 6 /*Mesh header*/ + 36 /*802.11 header*/);
57}
58
62{
63 /* Airtime link metric is defined in Section 13.9 of 802.11-2012 as:
64 *
65 * airtime = (O + Bt/r) / (1 - frame error rate), where
66 * o -- the PHY dependent channel access which includes frame headers, training sequences,
67 * access protocol frames, etc.
68 * bt -- the test packet length in bits (8192 by default),
69 * r -- the current bitrate of the packet,
70 *
71 * Final result is expressed in units of 0.01 Time Unit = 10.24 us (as required by 802.11s
72 * draft)
73 */
74 NS_ASSERT(!peerAddress.IsGroup());
75 // obtain current rate:
76 WifiMode mode = mac->GetWifiRemoteStationManager()
77 ->GetDataTxVector(m_testHeader, mac->GetWifiPhy()->GetChannelWidth())
78 .GetMode();
79 // obtain frame error rate:
80 double failAvg = mac->GetWifiRemoteStationManager()->GetInfo(peerAddress).GetFrameErrorRate();
81 if (failAvg == 1)
82 {
83 // Return max metric value when frame error rate equals to 1
84 return (uint32_t)0xffffffff;
85 }
86 NS_ASSERT(failAvg < 1.0);
87 WifiTxVector txVector;
88 txVector.SetMode(mode);
90 // calculate metric
91 uint32_t metric =
92 (uint32_t)((double)(/*Overhead + payload*/
93 // DIFS + SIFS + AckTxTime = 2 * SIFS + 2 * SLOT + AckTxTime
94 2 * mac->GetWifiPhy()->GetSifs() + 2 * mac->GetWifiPhy()->GetSlot() +
95 mac->GetWifiPhy()->GetAckTxTime() +
96 mac->GetWifiPhy()->CalculateTxDuration(m_testFrame->GetSize(),
97 txVector,
98 mac->GetWifiPhy()->GetPhyBand()))
99 .GetMicroSeconds() /
100 (10.24 * (1.0 - failAvg)));
101 return metric;
102}
103} // namespace dot11s
104} // namespace ns3
an EUI-48 address
bool IsGroup() const
A base class which provides memory management and object aggregation.
Definition object.h:78
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition packet.h:850
Smart pointer class similar to boost::intrusive_ptr.
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Hold an unsigned integer type.
Definition uinteger.h:34
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:40
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:55
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
@ WIFI_PREAMBLE_LONG
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition uinteger.h:35
@ WIFI_MAC_DATA