A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
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 {
28
NS_OBJECT_ENSURE_REGISTERED
(
AirtimeLinkMetricCalculator
)
29
;
30
31
TypeId
32
AirtimeLinkMetricCalculator::GetTypeId
()
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 (
41
&
AirtimeLinkMetricCalculator::SetTestLength
),
42
MakeUintegerChecker<uint16_t> (1)
43
)
44
.AddAttribute (
"Dot11MetricTid"
,
45
"TID used to calculate metric (data rate)"
,
46
UintegerValue
(0),
47
MakeUintegerAccessor (
48
&
AirtimeLinkMetricCalculator::SetHeaderTid
),
49
MakeUintegerChecker<uint8_t> (0)
50
)
51
;
52
return
tid;
53
}
54
AirtimeLinkMetricCalculator::AirtimeLinkMetricCalculator
()
55
{
56
}
57
void
58
AirtimeLinkMetricCalculator::SetHeaderTid
(uint8_t tid)
59
{
60
m_testHeader
.
SetDsFrom
();
61
m_testHeader
.
SetDsTo
();
62
m_testHeader
.
SetTypeData
();
63
m_testHeader
.
SetQosTid
(tid);
64
}
65
void
66
AirtimeLinkMetricCalculator::SetTestLength
(uint16_t testLength)
67
{
68
m_testFrame
= Create<Packet> (testLength + 6
/*Mesh header*/
+ 36
/*802.11 header*/
);
69
}
70
uint32_t
71
AirtimeLinkMetricCalculator::CalculateMetric
(
Mac48Address
peerAddress,
Ptr<MeshWifiInterfaceMac>
mac)
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
ns3::Ptr
smart pointer class similar to boost::intrusive_ptr
Definition:
ptr.h:59
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:47
NS_ASSERT
#define NS_ASSERT(condition)
Definition:
assert.h:64
ns3::NS_OBJECT_ENSURE_REGISTERED
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
ns3::Packet::GetSize
uint32_t GetSize(void) const
Definition:
packet.h:650
ns3::dot11s::AirtimeLinkMetricCalculator::SetHeaderTid
void SetHeaderTid(uint8_t tid)
Definition:
airtime-metric.cc:58
ns3::dot11s::AirtimeLinkMetricCalculator::CalculateMetric
uint32_t CalculateMetric(Mac48Address peerAddress, Ptr< MeshWifiInterfaceMac > mac)
Definition:
airtime-metric.cc:71
ns3::WifiMode
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition:
wifi-mode.h:91
ns3::dot11s::AirtimeLinkMetricCalculator::AirtimeLinkMetricCalculator
AirtimeLinkMetricCalculator()
Definition:
airtime-metric.cc:54
ns3::UintegerValue
Hold an unsigned integer type.
Definition:
uinteger.h:46
ns3::dot11s::AirtimeLinkMetricCalculator
Airtime link metric calculator.
Definition:
airtime-metric.h:41
ns3::WifiMacHeader::SetQosTid
void SetQosTid(uint8_t tid)
Set the TID for the QoS header.
Definition:
wifi-mac-header.cc:358
ns3::dot11s::AirtimeLinkMetricCalculator::GetTypeId
static TypeId GetTypeId()
Definition:
airtime-metric.cc:32
ns3::dot11s::AirtimeLinkMetricCalculator::SetTestLength
void SetTestLength(uint16_t testLength)
Definition:
airtime-metric.cc:66
ns3::Mac48Address::IsGroup
bool IsGroup(void) const
Definition:
mac48-address.cc:159
ns3::WIFI_PREAMBLE_LONG
Definition:
wifi-preamble.h:31
ns3::Mac48Address
an EUI-48 address
Definition:
mac48-address.h:41
ns3::WifiTxVector::SetMode
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
Definition:
wifi-tx-vector.cc:78
airtime-metric.h
ns3::dot11s::AirtimeLinkMetricCalculator::m_testFrame
Ptr< Packet > m_testFrame
Definition:
airtime-metric.h:50
ns3::WifiMacHeader::SetTypeData
void SetTypeData(void)
Set Type/Subtype values for a data packet with no subtype equal to 0.
Definition:
wifi-mac-header.cc:146
ns3::WifiMacHeader::SetDsTo
void SetDsTo(void)
Set the To DS bit in the Frame Control field.
Definition:
wifi-mac-header.cc:72
ns3::WifiMacHeader::SetDsFrom
void SetDsFrom(void)
Set the From DS bit in the Frame Control field.
Definition:
wifi-mac-header.cc:62
ns3::Object
a base class which provides memory management and object aggregation
Definition:
object.h:63
ns3::dot11s::AirtimeLinkMetricCalculator::m_testHeader
WifiMacHeader m_testHeader
Definition:
airtime-metric.h:51
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:49
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Definition:
type-id.cc:611
src
mesh
model
dot11s
airtime-metric.cc
Generated on Sat Apr 19 2014 14:07:03 for ns-3 by
1.8.6