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
namespace
ns3 {
25
namespace
dot11s {
26
NS_OBJECT_ENSURE_REGISTERED
(
AirtimeLinkMetricCalculator
);
27
TypeId
28
AirtimeLinkMetricCalculator::GetTypeId
()
29
{
30
static
TypeId
tid =
TypeId
(
"ns3::dot11s::AirtimeLinkMetricCalculator"
)
31
.
SetParent
<
Object
> ()
32
.AddConstructor<AirtimeLinkMetricCalculator> ()
33
.AddAttribute (
"TestLength"
,
34
"Rate should be estimated using test length."
,
35
UintegerValue
(1024),
36
MakeUintegerAccessor (
37
&
AirtimeLinkMetricCalculator::SetTestLength
),
38
MakeUintegerChecker<uint16_t> (1)
39
)
40
.AddAttribute (
"Dot11MetricTid"
,
41
"TID used to calculate metric (data rate)"
,
42
UintegerValue
(0),
43
MakeUintegerAccessor (
44
&
AirtimeLinkMetricCalculator::SetHeaderTid
),
45
MakeUintegerChecker<uint8_t> (0)
46
)
47
.AddAttribute (
"Dot11sMeshHeaderLength"
,
48
"Length of the mesh header"
,
49
UintegerValue
(6),
50
MakeUintegerAccessor (
51
&
AirtimeLinkMetricCalculator::m_meshHeaderLength
),
52
MakeUintegerChecker<uint16_t> (0)
53
)
54
;
55
return
tid;
56
}
57
AirtimeLinkMetricCalculator::AirtimeLinkMetricCalculator
() :
58
m_overheadNanosec (0)
59
{
60
}
61
void
62
AirtimeLinkMetricCalculator::SetHeaderTid
(uint8_t tid)
63
{
64
m_testHeader
.
SetDsFrom
();
65
m_testHeader
.
SetDsTo
();
66
m_testHeader
.
SetTypeData
();
67
m_testHeader
.
SetQosTid
(tid);
68
}
69
void
70
AirtimeLinkMetricCalculator::SetTestLength
(uint16_t testLength)
71
{
72
m_testFrame
= Create<Packet> (testLength + 6
/*Mesh header*/
+ 36
/*802.11 header*/
);
73
}
74
uint32_t
75
AirtimeLinkMetricCalculator::CalculateMetric
(
Mac48Address
peerAddress,
Ptr<MeshWifiInterfaceMac>
mac)
76
{
77
/* Airtime link metric is defined in 11B.10 of 802.11s Draft D3.0 as:
78
*
79
* airtime = (O + Bt/r) / (1 - frame error rate), where
80
* o -- the PHY dependent channel access which includes frame headers, training sequences,
81
* access protocol frames, etc.
82
* bt -- the test packet length in bits (8192 by default),
83
* r -- the current bitrate of the packet,
84
*
85
* Final result is expressed in units of 0.01 Time Unit = 10.24 us (as required by 802.11s draft)
86
*/
87
NS_ASSERT
(!peerAddress.
IsGroup
());
88
//obtain current rate:
89
WifiMode
mode = mac->
GetWifiRemoteStationManager
()->
GetDataMode
(peerAddress, &
m_testHeader
,
m_testFrame
,
m_testFrame
->
GetSize
());
90
//obtain frame error rate:
91
double
failAvg = mac->
GetWifiRemoteStationManager
()->
GetInfo
(peerAddress).
GetFrameErrorRate
();
92
if
(failAvg == 1)
93
{
94
// Retrun max metric value when frame error rate equals to 1
95
return
(uint32_t)0xffffffff;
96
}
97
NS_ASSERT
(failAvg < 1.0);
98
//calculate metric
99
uint32_t metric = (uint32_t)((
double
)(
/*Overhead + payload*/
100
mac->
GetPifs
() + mac->
GetSlot
() + mac->
GetEifsNoDifs
() +
//DIFS + SIFS + AckTxTime = PIFS + SLOT + EifsNoDifs
101
mac->
GetWifiPhy
()->
CalculateTxDuration
(
m_testFrame
->
GetSize
(), mode,
WIFI_PREAMBLE_LONG
)
102
).GetMicroSeconds () / (10.24 * (1.0 - failAvg)));
103
return
metric;
104
}
105
}
// namespace dot11s
106
}
// namespace ns3
src
mesh
model
dot11s
airtime-metric.cc
Generated on Tue Oct 9 2012 16:45:41 for ns-3 by
1.8.1.2