author | Kirill Andreev <andreev@iitp.ru> |
Thu, 25 Feb 2010 14:57:20 +0100 | |
changeset 6069 | c21754b56036 |
parent 6064 | ddec96840ebd |
child 6071 | 6a25c600c450 |
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" |
5132
aee541a30256
Restored newline at namespace
Kirill Andreev <andreev@iitp.ru>
parents:
5129
diff
changeset
|
24 |
namespace ns3 { |
aee541a30256
Restored newline at namespace
Kirill Andreev <andreev@iitp.ru>
parents:
5129
diff
changeset
|
25 |
namespace dot11s { |
5042 | 26 |
NS_OBJECT_ENSURE_REGISTERED (AirtimeLinkMetricCalculator); |
5040 | 27 |
TypeId |
28 |
AirtimeLinkMetricCalculator::GetTypeId () |
|
29 |
{ |
|
30 |
static TypeId tid = TypeId ("ns3::dot11s::AirtimeLinkMetricCalculator") |
|
31 |
.SetParent<Object> () |
|
32 |
.AddConstructor<AirtimeLinkMetricCalculator> () |
|
5165 | 33 |
.AddAttribute ( "TestLength", |
5129 | 34 |
"Rate should be estimated using test length.", |
35 |
UintegerValue (1024), |
|
36 |
MakeUintegerAccessor ( |
|
6069
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
37 |
&AirtimeLinkMetricCalculator::SetTestLength), |
5129 | 38 |
MakeUintegerChecker<uint16_t> (1) |
39 |
) |
|
6069
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
40 |
.AddAttribute ( "Dot11MetricTid", |
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
41 |
"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
|
42 |
UintegerValue (0), |
5129 | 43 |
MakeUintegerAccessor ( |
6069
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
44 |
&AirtimeLinkMetricCalculator::SetHeaderTid), |
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
45 |
MakeUintegerChecker<uint8_t> (0) |
5129 | 46 |
) |
5165 | 47 |
.AddAttribute ( "Dot11sMeshHeaderLength", |
5129 | 48 |
"Length of the mesh header", |
49 |
UintegerValue (6), |
|
50 |
MakeUintegerAccessor ( |
|
51 |
&AirtimeLinkMetricCalculator::m_meshHeaderLength), |
|
52 |
MakeUintegerChecker<uint16_t> (0) |
|
53 |
) |
|
54 |
; |
|
5040 | 55 |
return tid; |
5129 | 56 |
} |
5828
9959ba75ba25
Mesh:Dot11s: fixed airtime metric
Kirill Andreev <andreev@iitp.ru>
parents:
5446
diff
changeset
|
57 |
AirtimeLinkMetricCalculator::AirtimeLinkMetricCalculator () : |
9959ba75ba25
Mesh:Dot11s: fixed airtime metric
Kirill Andreev <andreev@iitp.ru>
parents:
5446
diff
changeset
|
58 |
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
|
59 |
{ |
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
60 |
} |
5828
9959ba75ba25
Mesh:Dot11s: fixed airtime metric
Kirill Andreev <andreev@iitp.ru>
parents:
5446
diff
changeset
|
61 |
void |
6069
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
62 |
AirtimeLinkMetricCalculator::SetHeaderTid (uint8_t tid) |
5828
9959ba75ba25
Mesh:Dot11s: fixed airtime metric
Kirill Andreev <andreev@iitp.ru>
parents:
5446
diff
changeset
|
63 |
{ |
6069
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
64 |
m_testHeader.SetDsFrom (); |
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
65 |
m_testHeader.SetDsTo (); |
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
66 |
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
|
67 |
} |
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
68 |
void |
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
69 |
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
|
70 |
{ |
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
71 |
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
|
72 |
} |
4946
f97e16db1d79
Added airtime link metric. packet error rate is not done yet
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
73 |
uint32_t |
5129 | 74 |
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
|
75 |
{ |
5063 | 76 |
/* Airtime link metric is defined in 11B.10 of 802.11s Draft D3.0 as: |
5129 | 77 |
* |
6069
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
78 |
* airtime = (O + Bt/r) / (1 - frame error rate), where |
5129 | 79 |
* o -- the PHY dependent channel access which includes frame headers, training sequences, |
80 |
* access protocol frames, etc. |
|
81 |
* bt -- the test packet length in bits (8192 by default), |
|
5063 | 82 |
* r -- the current bitrate of the packet, |
5129 | 83 |
* |
5063 | 84 |
* Final result is expressed in units of 0.01 Time Unit = 10.24 us (as required by 802.11s draft) |
85 |
*/ |
|
6069
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
86 |
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
|
87 |
//obtain current rate: |
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
88 |
WifiMode mode = mac->GetStationManager ()->GetDataMode (peerAddress, &m_testHeader, m_testFrame, m_testFrame->GetSize ()); |
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
89 |
//obtain frame error rate: |
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
90 |
double failAvg = mac->GetStationManager ()->Lookup (peerAddress, &m_testHeader)->m_state->m_info.GetFrameErrorRate (); |
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
91 |
NS_ASSERT (failAvg < 1.0); |
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
92 |
//calculate metric |
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
93 |
uint32_t metric = (uint32_t)((double)(/*Overhead + payload*/ |
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
94 |
mac->GetPifs () + mac->GetSlot () + mac->GetEifsNoDifs () + //DIFS + SIFS + AckTxTime = PIFS + SLOT + EifsNoDifs |
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
95 |
mac->GetWifiPhy () ->CalculateTxDuration (m_testFrame->GetSize (), mode, WIFI_PREAMBLE_LONG) |
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
96 |
).GetMicroSeconds () / (10.24 * (1.0 - failAvg))); |
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
97 |
std::cout << "pure overhead is " << (uint32_t)((double)(/*Overhead + payload*/ |
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
98 |
mac->GetPifs () + mac->GetSlot () + mac->GetEifsNoDifs () |
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
99 |
).GetMicroSeconds ()/10.24) << "\n"; |
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
100 |
std::cout << "mode is:" << mode.GetDataRate () << "\n"; |
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
101 |
std::cout << "Metric is :" << metric << "\n"; |
c21754b56036
change airtime metric to work with new wifi remote station manager
Kirill Andreev <andreev@iitp.ru>
parents:
6064
diff
changeset
|
102 |
return metric; |
4946
f97e16db1d79
Added airtime link metric. packet error rate is not done yet
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
103 |
} |
f97e16db1d79
Added airtime link metric. packet error rate is not done yet
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
104 |
} //namespace dot11s |
f97e16db1d79
Added airtime link metric. packet error rate is not done yet
Kirill Andreev <andreev@iitp.ru>
parents:
diff
changeset
|
105 |
} //namespace ns3 |