author | Ghada Badawy <gbadawy@gmail.com> |
Tue, 13 Aug 2013 22:05:25 -0700 | |
changeset 10139 | 17a71cd49da3 |
parent 7386 | 2310ed220a61 |
child 10218 | 97da49da2d6c |
permissions | -rw-r--r-- |
4947 | 1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
5129 | 2 |
/* |
4947 | 3 |
* Copyright (c) 2009 IITP RAS |
5129 | 4 |
* |
4947 | 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 |
|
5129 | 17 |
* |
4947 | 18 |
* Authors: Kirill Andreev <andreev@iitp.ru> |
19 |
*/ |
|
20 |
||
4946
f97e16db1d79
Added airtime link metric. packet error rate is not done yet
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
21 |
#include "airtime-metric.h" |
f97e16db1d79
Added airtime link metric. packet error rate is not done yet
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
22 |
#include "ns3/wifi-remote-station-manager.h" |
f97e16db1d79
Added airtime link metric. packet error rate is not done yet
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
23 |
#include "ns3/wifi-mode.h" |
10139 | 24 |
#include "ns3/wifi-tx-vector.h" |
25 |
||
5132
aee541a30256
Restored newline at namespace
Kirill Andreev <andreev@iitp.ru>
parents:
5129
diff
changeset
|
26 |
namespace ns3 { |
aee541a30256
Restored newline at namespace
Kirill Andreev <andreev@iitp.ru>
parents:
5129
diff
changeset
|
27 |
namespace dot11s { |
5042 | 28 |
NS_OBJECT_ENSURE_REGISTERED (AirtimeLinkMetricCalculator); |
5040 | 29 |
TypeId |
30 |
AirtimeLinkMetricCalculator::GetTypeId () |
|
31 |
{ |
|
32 |
static TypeId tid = TypeId ("ns3::dot11s::AirtimeLinkMetricCalculator") |
|
33 |
.SetParent<Object> () |
|
34 |
.AddConstructor<AirtimeLinkMetricCalculator> () |
|
5165 | 35 |
.AddAttribute ( "TestLength", |
5129 | 36 |
"Rate should be estimated using test length.", |
6674
52f8688d6d01
Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents:
6673
diff
changeset
|
37 |
UintegerValue (1024), |
52f8688d6d01
Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents:
6673
diff
changeset
|
38 |
MakeUintegerAccessor ( |
52f8688d6d01
Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents:
6673
diff
changeset
|
39 |
&AirtimeLinkMetricCalculator::SetTestLength), |
52f8688d6d01
Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents:
6673
diff
changeset
|
40 |
MakeUintegerChecker<uint16_t> (1) |
52f8688d6d01
Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents:
6673
diff
changeset
|
41 |
) |
6069
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
42 |
.AddAttribute ( "Dot11MetricTid", |
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
43 |
"TID used to calculate metric (data rate)", |
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
44 |
UintegerValue (0), |
5129 | 45 |
MakeUintegerAccessor ( |
6674
52f8688d6d01
Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents:
6673
diff
changeset
|
46 |
&AirtimeLinkMetricCalculator::SetHeaderTid), |
6069
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
47 |
MakeUintegerChecker<uint8_t> (0) |
6674
52f8688d6d01
Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents:
6673
diff
changeset
|
48 |
) |
5165 | 49 |
.AddAttribute ( "Dot11sMeshHeaderLength", |
5129 | 50 |
"Length of the mesh header", |
51 |
UintegerValue (6), |
|
52 |
MakeUintegerAccessor ( |
|
6674
52f8688d6d01
Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents:
6673
diff
changeset
|
53 |
&AirtimeLinkMetricCalculator::m_meshHeaderLength), |
5129 | 54 |
MakeUintegerChecker<uint16_t> (0) |
6674
52f8688d6d01
Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents:
6673
diff
changeset
|
55 |
) |
52f8688d6d01
Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents:
6673
diff
changeset
|
56 |
; |
5040 | 57 |
return tid; |
5129 | 58 |
} |
5828
9959ba75ba25
Mesh:Dot11s: fixed airtime metric
Kirill Andreev <andreev@iitp.ru>
parents:
5446
diff
changeset
|
59 |
AirtimeLinkMetricCalculator::AirtimeLinkMetricCalculator () : |
9959ba75ba25
Mesh:Dot11s: fixed airtime metric
Kirill Andreev <andreev@iitp.ru>
parents:
5446
diff
changeset
|
60 |
m_overheadNanosec (0) |
6069
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
61 |
{ |
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
62 |
} |
5828
9959ba75ba25
Mesh:Dot11s: fixed airtime metric
Kirill Andreev <andreev@iitp.ru>
parents:
5446
diff
changeset
|
63 |
void |
6069
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
64 |
AirtimeLinkMetricCalculator::SetHeaderTid (uint8_t tid) |
5828
9959ba75ba25
Mesh:Dot11s: fixed airtime metric
Kirill Andreev <andreev@iitp.ru>
parents:
5446
diff
changeset
|
65 |
{ |
6069
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
66 |
m_testHeader.SetDsFrom (); |
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
67 |
m_testHeader.SetDsTo (); |
6098
b0e661ced163
Mesh: fixed valgrind errors
Kirill Andreev <andreev@iitp.ru>
parents:
6082
diff
changeset
|
68 |
m_testHeader.SetTypeData (); |
6069
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
69 |
m_testHeader.SetQosTid (tid); |
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
70 |
} |
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
71 |
void |
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
72 |
AirtimeLinkMetricCalculator::SetTestLength (uint16_t testLength) |
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
73 |
{ |
6674
52f8688d6d01
Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents:
6673
diff
changeset
|
74 |
m_testFrame = Create<Packet> (testLength + 6 /*Mesh header*/ + 36 /*802.11 header*/); |
5828
9959ba75ba25
Mesh:Dot11s: fixed airtime metric
Kirill Andreev <andreev@iitp.ru>
parents:
5446
diff
changeset
|
75 |
} |
4946
f97e16db1d79
Added airtime link metric. packet error rate is not done yet
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
76 |
uint32_t |
5129 | 77 |
AirtimeLinkMetricCalculator::CalculateMetric (Mac48Address peerAddress, Ptr<MeshWifiInterfaceMac> mac) |
4946
f97e16db1d79
Added airtime link metric. packet error rate is not done yet
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
78 |
{ |
5063 | 79 |
/* Airtime link metric is defined in 11B.10 of 802.11s Draft D3.0 as: |
5129 | 80 |
* |
6069
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
81 |
* airtime = (O + Bt/r) / (1 - frame error rate), where |
5129 | 82 |
* o -- the PHY dependent channel access which includes frame headers, training sequences, |
83 |
* access protocol frames, etc. |
|
84 |
* bt -- the test packet length in bits (8192 by default), |
|
5063 | 85 |
* r -- the current bitrate of the packet, |
5129 | 86 |
* |
5063 | 87 |
* Final result is expressed in units of 0.01 Time Unit = 10.24 us (as required by 802.11s draft) |
88 |
*/ |
|
6069
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
89 |
NS_ASSERT (!peerAddress.IsGroup ()); |
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
90 |
//obtain current rate: |
10139 | 91 |
WifiMode mode = mac->GetWifiRemoteStationManager ()->GetDataTxVector (peerAddress, &m_testHeader, m_testFrame, m_testFrame->GetSize ()).GetMode(); |
6069
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
92 |
//obtain frame error rate: |
6673
ec22aa763e2d
Bug 978: Consolidate Wi-Fi MAC high functionality
Dean Armstrong <deanarm@gmail.com>
parents:
6098
diff
changeset
|
93 |
double failAvg = mac->GetWifiRemoteStationManager ()->GetInfo (peerAddress).GetFrameErrorRate (); |
7298
46338d126f2f
Mesh: Bug 1033 - airtime-metric: fixed
Kirill Andreev <andreev@telum.ru>
parents:
6882
diff
changeset
|
94 |
if (failAvg == 1) |
46338d126f2f
Mesh: Bug 1033 - airtime-metric: fixed
Kirill Andreev <andreev@telum.ru>
parents:
6882
diff
changeset
|
95 |
{ |
46338d126f2f
Mesh: Bug 1033 - airtime-metric: fixed
Kirill Andreev <andreev@telum.ru>
parents:
6882
diff
changeset
|
96 |
// Retrun max metric value when frame error rate equals to 1 |
46338d126f2f
Mesh: Bug 1033 - airtime-metric: fixed
Kirill Andreev <andreev@telum.ru>
parents:
6882
diff
changeset
|
97 |
return (uint32_t)0xffffffff; |
46338d126f2f
Mesh: Bug 1033 - airtime-metric: fixed
Kirill Andreev <andreev@telum.ru>
parents:
6882
diff
changeset
|
98 |
} |
6069
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
99 |
NS_ASSERT (failAvg < 1.0); |
10139 | 100 |
WifiTxVector txVector; |
101 |
txVector.SetMode (mode); |
|
6069
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
102 |
//calculate metric |
6674
52f8688d6d01
Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents:
6673
diff
changeset
|
103 |
uint32_t metric = (uint32_t)((double)( /*Overhead + payload*/ |
52f8688d6d01
Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents:
6673
diff
changeset
|
104 |
mac->GetPifs () + mac->GetSlot () + mac->GetEifsNoDifs () + //DIFS + SIFS + AckTxTime = PIFS + SLOT + EifsNoDifs |
10139 | 105 |
mac->GetWifiPhy ()->CalculateTxDuration (m_testFrame->GetSize (), txVector, WIFI_PREAMBLE_LONG) |
6674
52f8688d6d01
Bug 978: Run check-style.py on files touched in the reorganisation
Dean Armstrong <deanarm@gmail.com>
parents:
6673
diff
changeset
|
106 |
).GetMicroSeconds () / (10.24 * (1.0 - failAvg))); |
6069
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
107 |
return metric; |
4946
f97e16db1d79
Added airtime link metric. packet error rate is not done yet
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
108 |
} |
7386
2310ed220a61
standardize ns-3 namespace declaration format
Vedran Miletić <rivanvx@gmail.com>
parents:
7298
diff
changeset
|
109 |
} // namespace dot11s |
2310ed220a61
standardize ns-3 namespace declaration format
Vedran Miletić <rivanvx@gmail.com>
parents:
7298
diff
changeset
|
110 |
} // namespace ns3 |