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
TypeId
30
AirtimeLinkMetricCalculator::GetTypeId
()
31
{
32
static
TypeId
tid =
TypeId
(
"ns3::dot11s::AirtimeLinkMetricCalculator"
)
33
.
SetParent
<
Object
> ()
34
.AddConstructor<AirtimeLinkMetricCalculator> ()
35
.AddAttribute (
"TestLength"
,
36
"Rate should be estimated using test length."
,
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
.
SetDsFrom
();
59
m_testHeader
.
SetDsTo
();
60
m_testHeader
.
SetTypeData
();
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 11B.10 of 802.11s Draft D3.0 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 (peerAddress, &
m_testHeader
,
m_testFrame
,
m_testFrame
->
GetSize
()).GetMode();
84
//obtain frame error rate:
85
double
failAvg = mac->GetWifiRemoteStationManager ()->GetInfo (peerAddress).GetFrameErrorRate ();
86
if
(failAvg == 1)
87
{
88
// Retrun 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
//calculate metric
95
uint32_t metric = (uint32_t)((
double
)(
/*Overhead + payload*/
96
mac->GetPifs () + mac->GetSlot () + mac->GetEifsNoDifs () +
//DIFS + SIFS + AckTxTime = PIFS + SLOT + EifsNoDifs
97
mac->GetWifiPhy ()->CalculateTxDuration (
m_testFrame
->
GetSize
(), txVector,
WIFI_PREAMBLE_LONG
)
98
).GetMicroSeconds () / (10.24 * (1.0 - failAvg)));
99
return
metric;
100
}
101
}
// namespace dot11s
102
}
// namespace ns3
ns3::Ptr
smart pointer class similar to boost::intrusive_ptr
Definition:
ptr.h:59
ns3::WifiTxVector
Definition:
wifi-tx-vector.h:47
NS_ASSERT
#define NS_ASSERT(condition)
Definition:
assert.h:64
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:56
ns3::dot11s::AirtimeLinkMetricCalculator::CalculateMetric
uint32_t CalculateMetric(Mac48Address peerAddress, Ptr< MeshWifiInterfaceMac > mac)
Definition:
airtime-metric.cc:69
ns3::dot11s::NS_OBJECT_ENSURE_REGISTERED
NS_OBJECT_ENSURE_REGISTERED(AirtimeLinkMetricCalculator)
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:52
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)
Definition:
wifi-mac-header.cc:357
ns3::dot11s::AirtimeLinkMetricCalculator::GetTypeId
static TypeId GetTypeId()
Definition:
airtime-metric.cc:30
ns3::dot11s::AirtimeLinkMetricCalculator::SetTestLength
void SetTestLength(uint16_t testLength)
Definition:
airtime-metric.cc:64
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)
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)
Definition:
wifi-mac-header.cc:145
ns3::WifiMacHeader::SetDsTo
void SetDsTo(void)
Definition:
wifi-mac-header.cc:71
ns3::WifiMacHeader::SetDsFrom
void SetDsFrom(void)
Definition:
wifi-mac-header.cc:61
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:610
src
mesh
model
dot11s
airtime-metric.cc
Generated on Sat Nov 16 2013 12:55:33 for ns-3 by
1.8.5