A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
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-phy.h"
23
24
namespace
ns3
{
25
namespace
dot11s {
26
NS_OBJECT_ENSURE_REGISTERED
(
AirtimeLinkMetricCalculator
);
27
28
TypeId
29
AirtimeLinkMetricCalculator::GetTypeId
()
30
{
31
static
TypeId
tid =
TypeId
(
"ns3::dot11s::AirtimeLinkMetricCalculator"
)
32
.
SetParent
<
Object
> ()
33
.SetGroupName (
"Mesh"
)
34
.AddConstructor<
AirtimeLinkMetricCalculator
> ()
35
.AddAttribute (
"TestLength"
,
36
"Number of bytes in test frame (a constant 1024 in the standard)"
,
37
UintegerValue
(1024),
38
MakeUintegerAccessor
(
39
&
AirtimeLinkMetricCalculator::SetTestLength
),
40
MakeUintegerChecker<uint16_t> (1)
41
)
42
.AddAttribute (
"Dot11MetricTid"
,
43
"TID used to calculate metric (data rate)"
,
44
UintegerValue
(0),
45
MakeUintegerAccessor
(
46
&
AirtimeLinkMetricCalculator::SetHeaderTid
),
47
MakeUintegerChecker<uint8_t> (0)
48
)
49
;
50
return
tid;
51
}
52
AirtimeLinkMetricCalculator::AirtimeLinkMetricCalculator
()
53
{
54
}
55
void
56
AirtimeLinkMetricCalculator::SetHeaderTid
(uint8_t tid)
57
{
58
m_testHeader
.
SetType
(
WIFI_MAC_DATA
);
59
m_testHeader
.
SetDsFrom
();
60
m_testHeader
.
SetDsTo
();
61
m_testHeader
.
SetQosTid
(tid);
62
}
63
void
64
AirtimeLinkMetricCalculator::SetTestLength
(uint16_t testLength)
65
{
66
m_testFrame
= Create<Packet> (testLength + 6
/*Mesh header*/
+ 36
/*802.11 header*/
);
67
}
68
uint32_t
69
AirtimeLinkMetricCalculator::CalculateMetric
(
Mac48Address
peerAddress,
Ptr<MeshWifiInterfaceMac>
mac
)
70
{
71
/* Airtime link metric is defined in Section 13.9 of 802.11-2012 as:
72
*
73
* airtime = (O + Bt/r) / (1 - frame error rate), where
74
* o -- the PHY dependent channel access which includes frame headers, training sequences,
75
* access protocol frames, etc.
76
* bt -- the test packet length in bits (8192 by default),
77
* r -- the current bitrate of the packet,
78
*
79
* Final result is expressed in units of 0.01 Time Unit = 10.24 us (as required by 802.11s draft)
80
*/
81
NS_ASSERT
(!peerAddress.
IsGroup
());
82
//obtain current rate:
83
WifiMode
mode =
mac
->GetWifiRemoteStationManager ()->GetDataTxVector (
m_testHeader
).GetMode();
84
//obtain frame error rate:
85
double
failAvg =
mac
->GetWifiRemoteStationManager ()->GetInfo (peerAddress).GetFrameErrorRate ();
86
if
(failAvg == 1)
87
{
88
// Return max metric value when frame error rate equals to 1
89
return
(uint32_t) 0xffffffff;
90
}
91
NS_ASSERT
(failAvg < 1.0);
92
WifiTxVector
txVector;
93
txVector.
SetMode
(mode);
94
txVector.
SetPreambleType
(
WIFI_PREAMBLE_LONG
);
95
//calculate metric
96
uint32_t metric = (uint32_t)((
double
)(
/*Overhead + payload*/
97
//DIFS + SIFS + AckTxTime = 2 * SIFS + 2 * SLOT + AckTxTime
98
2 *
mac
->GetWifiPhy ()->GetSifs () + 2 *
mac
->GetWifiPhy ()->GetSlot ()
99
+
mac
->GetWifiPhy ()->GetAckTxTime ()
100
+
mac
->GetWifiPhy ()->CalculateTxDuration (
m_testFrame
->
GetSize
(), txVector,
mac
->GetWifiPhy ()->GetPhyBand())
101
).GetMicroSeconds () / (10.24 * (1.0 - failAvg)));
102
return
metric;
103
}
104
}
// namespace dot11s
105
}
// namespace ns3
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:59
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition:
object-base.h:45
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:67
ns3::Mac48Address::IsGroup
bool IsGroup(void) const
Definition:
mac48-address.cc:164
ns3::Packet::GetSize
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition:
packet.h:852
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::WifiMacHeader::SetDsTo
void SetDsTo(void)
Set the To DS bit in the Frame Control field.
Definition:
wifi-mac-header.cc:96
airtime-metric.h
ns3::Mac48Address
an EUI-48 address
Definition:
mac48-address.h:44
ns3::WifiTxVector::SetMode
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
Definition:
wifi-tx-vector.cc:226
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:71
third.mac
mac
Definition:
third.py:99
ns3::dot11s::AirtimeLinkMetricCalculator::SetHeaderTid
void SetHeaderTid(uint8_t tid)
Set header TID from the Dot11MetricTid attribute.
Definition:
airtime-metric.cc:56
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition:
type-id.cc:923
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition:
ptr.h:74
ns3::WifiMode
represent a single transmission mode
Definition:
wifi-mode.h:48
ns3::Object
A base class which provides memory management and object aggregation.
Definition:
object.h:88
ns3::dot11s::AirtimeLinkMetricCalculator::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition:
airtime-metric.cc:29
ns3::dot11s::AirtimeLinkMetricCalculator
Airtime link metric calculator.
Definition:
airtime-metric.h:42
ns3::WIFI_PREAMBLE_LONG
@ WIFI_PREAMBLE_LONG
Definition:
wifi-phy-common.h:69
ns3::WIFI_MAC_DATA
@ WIFI_MAC_DATA
Definition:
wifi-mac-header.h:62
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:64
ns3::WifiMacHeader::SetType
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:132
ns3::UintegerValue
Hold an unsigned integer type.
Definition:
uinteger.h:44
ns3::dot11s::AirtimeLinkMetricCalculator::AirtimeLinkMetricCalculator
AirtimeLinkMetricCalculator()
Definition:
airtime-metric.cc:52
ns3::dot11s::AirtimeLinkMetricCalculator::m_testFrame
Ptr< Packet > m_testFrame
test frame
Definition:
airtime-metric.h:79
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:45
ns3::WifiMacHeader::SetQosTid
void SetQosTid(uint8_t tid)
Set the TID for the QoS header.
Definition:
wifi-mac-header.cc:352
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:69
ns3::WifiTxVector::SetPreambleType
void SetPreambleType(WifiPreamble preamble)
Sets the preamble type.
Definition:
wifi-tx-vector.cc:248
ns3::dot11s::AirtimeLinkMetricCalculator::m_testHeader
WifiMacHeader m_testHeader
test header
Definition:
airtime-metric.h:80
ns3::WifiMacHeader::SetDsFrom
void SetDsFrom(void)
Set the From DS bit in the Frame Control field.
Definition:
wifi-mac-header.cc:84
src
mesh
model
dot11s
airtime-metric.cc
Generated on Fri Oct 1 2021 17:03:26 for ns-3 by
1.8.20