A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
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
13
namespace
ns3
14
{
15
namespace
dot11s
16
{
17
NS_OBJECT_ENSURE_REGISTERED
(
AirtimeLinkMetricCalculator
);
18
19
TypeId
20
AirtimeLinkMetricCalculator::GetTypeId
()
21
{
22
static
TypeId
tid =
23
TypeId
(
"ns3::dot11s::AirtimeLinkMetricCalculator"
)
24
.
SetParent
<
Object
>()
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),
30
MakeUintegerAccessor
(&
AirtimeLinkMetricCalculator::SetTestLength
),
31
MakeUintegerChecker<uint16_t>
(1))
32
.AddAttribute(
"Dot11MetricTid"
,
33
"TID used to calculate metric (data rate)"
,
34
UintegerValue
(0),
35
MakeUintegerAccessor
(&
AirtimeLinkMetricCalculator::SetHeaderTid
),
36
MakeUintegerChecker<uint8_t>
(0));
37
return
tid;
38
}
39
40
AirtimeLinkMetricCalculator::AirtimeLinkMetricCalculator
()
41
{
42
}
43
44
void
45
AirtimeLinkMetricCalculator::SetHeaderTid
(uint8_t tid)
46
{
47
m_testHeader
.
SetType
(
WIFI_MAC_DATA
);
48
m_testHeader
.
SetDsFrom
();
49
m_testHeader
.
SetDsTo
();
50
m_testHeader
.
SetQosTid
(tid);
51
}
52
53
void
54
AirtimeLinkMetricCalculator::SetTestLength
(uint16_t testLength)
55
{
56
m_testFrame
=
Create<Packet>
(testLength + 6
/*Mesh header*/
+ 36
/*802.11 header*/
);
57
}
58
59
uint32_t
60
AirtimeLinkMetricCalculator::CalculateMetric
(
Mac48Address
peerAddress,
61
Ptr<MeshWifiInterfaceMac>
mac)
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);
89
txVector.
SetPreambleType
(
WIFI_PREAMBLE_LONG
);
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
airtime-metric.h
ns3::Mac48Address
an EUI-48 address
Definition
mac48-address.h:35
ns3::Mac48Address::IsGroup
bool IsGroup() const
Definition
mac48-address.cc:137
ns3::Object
A base class which provides memory management and object aggregation.
Definition
object.h:78
ns3::Packet::GetSize
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition
packet.h:850
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
ns3::TypeId
a unique identifier for an interface.
Definition
type-id.h:48
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition
type-id.cc:1001
ns3::UintegerValue
Hold an unsigned integer type.
Definition
uinteger.h:34
ns3::WifiMacHeader::SetType
virtual void SetType(WifiMacType type, bool resetToDsFromDs=true)
Set Type/Subtype values with the correct values depending on the given type.
Definition
wifi-mac-header.cc:104
ns3::WifiMacHeader::SetQosTid
void SetQosTid(uint8_t tid)
Set the TID for the QoS header.
Definition
wifi-mac-header.cc:341
ns3::WifiMacHeader::SetDsFrom
void SetDsFrom()
Set the From DS bit in the Frame Control field.
Definition
wifi-mac-header.cc:56
ns3::WifiMacHeader::SetDsTo
void SetDsTo()
Set the To DS bit in the Frame Control field.
Definition
wifi-mac-header.cc:68
ns3::WifiMode
represent a single transmission mode
Definition
wifi-mode.h:40
ns3::WifiTxVector
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
Definition
wifi-tx-vector.h:101
ns3::WifiTxVector::SetMode
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
Definition
wifi-tx-vector.cc:273
ns3::WifiTxVector::SetPreambleType
void SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
Definition
wifi-tx-vector.cc:295
ns3::dot11s::AirtimeLinkMetricCalculator
Airtime link metric calculator.
Definition
airtime-metric.h:35
ns3::dot11s::AirtimeLinkMetricCalculator::m_testFrame
Ptr< Packet > m_testFrame
test frame
Definition
airtime-metric.h:73
ns3::dot11s::AirtimeLinkMetricCalculator::CalculateMetric
uint32_t CalculateMetric(Mac48Address peerAddress, Ptr< MeshWifiInterfaceMac > mac)
Airtime link metric is defined in Section 13.9 of IEEE 802.11-2012 as:
Definition
airtime-metric.cc:60
ns3::dot11s::AirtimeLinkMetricCalculator::SetHeaderTid
void SetHeaderTid(uint8_t tid)
Set header TID from the Dot11MetricTid attribute.
Definition
airtime-metric.cc:45
ns3::dot11s::AirtimeLinkMetricCalculator::m_testHeader
WifiMacHeader m_testHeader
test header
Definition
airtime-metric.h:74
ns3::dot11s::AirtimeLinkMetricCalculator::AirtimeLinkMetricCalculator
AirtimeLinkMetricCalculator()
Definition
airtime-metric.cc:40
ns3::dot11s::AirtimeLinkMetricCalculator::SetTestLength
void SetTestLength(uint16_t testLength)
Set number of bytes in test frame (a constant 1024 in the standard)
Definition
airtime-metric.cc:54
ns3::dot11s::AirtimeLinkMetricCalculator::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition
airtime-metric.cc:20
uint32_t
NS_ASSERT
#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
ns3::MakeUintegerChecker
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition
uinteger.h:85
ns3::MakeUintegerAccessor
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition
uinteger.h:35
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition
object-base.h:35
ns3::Create
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition
ptr.h:436
ns3::WIFI_PREAMBLE_LONG
@ WIFI_PREAMBLE_LONG
Definition
wifi-phy-common.h:179
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::WIFI_MAC_DATA
@ WIFI_MAC_DATA
Definition
wifi-mac-header.h:62
src
mesh
model
dot11s
airtime-metric.cc
Generated on Tue Dec 10 2024 18:20:45 for ns-3 by
1.11.0