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
amrr-wifi-manager.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2003,2007 INRIA
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
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19
*/
20
21
#include "
amrr-wifi-manager.h
"
22
#include "ns3/simulator.h"
23
#include "ns3/log.h"
24
#include "ns3/uinteger.h"
25
#include "ns3/double.h"
26
27
#define Min(a,b) ((a < b) ? a : b)
28
29
NS_LOG_COMPONENT_DEFINE
(
"AmrrWifiRemoteStation"
);
30
31
namespace
ns3 {
32
33
struct
AmrrWifiRemoteStation
:
public
WifiRemoteStation
34
{
35
Time
m_nextModeUpdate
;
36
uint32_t
m_tx_ok
;
37
uint32_t
m_tx_err
;
38
uint32_t
m_tx_retr
;
39
uint32_t
m_retry
;
40
uint32_t
m_txrate
;
41
uint32_t
m_successThreshold
;
42
uint32_t
m_success
;
43
bool
m_recovery
;
44
};
45
46
47
NS_OBJECT_ENSURE_REGISTERED
(
AmrrWifiManager
);
48
49
TypeId
50
AmrrWifiManager::GetTypeId
(
void
)
51
{
52
static
TypeId
tid =
TypeId
(
"ns3::AmrrWifiManager"
)
53
.
SetParent
<
WifiRemoteStationManager
> ()
54
.AddConstructor<AmrrWifiManager> ()
55
.AddAttribute (
"UpdatePeriod"
,
56
"The interval between decisions about rate control changes"
,
57
TimeValue
(Seconds (1.0)),
58
MakeTimeAccessor (&
AmrrWifiManager::m_updatePeriod
),
59
MakeTimeChecker
())
60
.AddAttribute (
"FailureRatio"
,
61
"Ratio of minimum erroneous transmissions needed to switch to a lower rate"
,
62
DoubleValue
(1.0 / 3.0),
63
MakeDoubleAccessor (&
AmrrWifiManager::m_failureRatio
),
64
MakeDoubleChecker<double> (0.0, 1.0))
65
.AddAttribute (
"SuccessRatio"
,
66
"Ratio of maximum erroneous transmissions needed to switch to a higher rate"
,
67
DoubleValue
(1.0 / 10.0),
68
MakeDoubleAccessor (&
AmrrWifiManager::m_successRatio
),
69
MakeDoubleChecker<double> (0.0, 1.0))
70
.AddAttribute (
"MaxSuccessThreshold"
,
71
"Maximum number of consecutive success periods needed to switch to a higher rate"
,
72
UintegerValue
(10),
73
MakeUintegerAccessor (&
AmrrWifiManager::m_maxSuccessThreshold
),
74
MakeUintegerChecker<uint32_t> ())
75
.AddAttribute (
"MinSuccessThreshold"
,
76
"Minimum number of consecutive success periods needed to switch to a higher rate"
,
77
UintegerValue
(1),
78
MakeUintegerAccessor (&
AmrrWifiManager::m_minSuccessThreshold
),
79
MakeUintegerChecker<uint32_t> ())
80
;
81
return
tid;
82
}
83
84
AmrrWifiManager::AmrrWifiManager
()
85
{
86
NS_LOG_FUNCTION
(
this
);
87
}
88
89
WifiRemoteStation
*
90
AmrrWifiManager::DoCreateStation
(
void
)
const
91
{
92
NS_LOG_FUNCTION
(
this
);
93
AmrrWifiRemoteStation
*station =
new
AmrrWifiRemoteStation
();
94
station->
m_nextModeUpdate
=
Simulator::Now
() +
m_updatePeriod
;
95
station->
m_tx_ok
= 0;
96
station->
m_tx_err
= 0;
97
station->
m_tx_retr
= 0;
98
station->
m_retry
= 0;
99
station->
m_txrate
= 0;
100
station->
m_successThreshold
=
m_minSuccessThreshold
;
101
station->
m_success
= 0;
102
station->
m_recovery
=
false
;
103
return
station;
104
}
105
106
107
void
108
AmrrWifiManager::DoReportRxOk
(
WifiRemoteStation
*station,
109
double
rxSnr,
WifiMode
txMode)
110
{
111
NS_LOG_FUNCTION
(
this
<< station << rxSnr << txMode);
112
}
113
void
114
AmrrWifiManager::DoReportRtsFailed
(
WifiRemoteStation
*station)
115
{
116
NS_LOG_FUNCTION
(
this
<< station);
117
}
118
void
119
AmrrWifiManager::DoReportDataFailed
(
WifiRemoteStation
*st)
120
{
121
NS_LOG_FUNCTION
(
this
<< st);
122
AmrrWifiRemoteStation
*station = (
AmrrWifiRemoteStation
*)st;
123
station->
m_retry
++;
124
station->
m_tx_retr
++;
125
}
126
void
127
AmrrWifiManager::DoReportRtsOk
(
WifiRemoteStation
*st,
128
double
ctsSnr,
WifiMode
ctsMode,
double
rtsSnr)
129
{
130
NS_LOG_FUNCTION
(
this
<< st << ctsSnr << ctsMode << rtsSnr);
131
}
132
void
133
AmrrWifiManager::DoReportDataOk
(
WifiRemoteStation
*st,
134
double
ackSnr,
WifiMode
ackMode,
double
dataSnr)
135
{
136
NS_LOG_FUNCTION
(
this
<< st << ackSnr << ackMode << dataSnr);
137
AmrrWifiRemoteStation
*station = (
AmrrWifiRemoteStation
*)st;
138
station->
m_retry
= 0;
139
station->
m_tx_ok
++;
140
}
141
void
142
AmrrWifiManager::DoReportFinalRtsFailed
(
WifiRemoteStation
*station)
143
{
144
NS_LOG_FUNCTION
(
this
<< station);
145
}
146
void
147
AmrrWifiManager::DoReportFinalDataFailed
(
WifiRemoteStation
*st)
148
{
149
NS_LOG_FUNCTION
(
this
<< st);
150
AmrrWifiRemoteStation
*station = (
AmrrWifiRemoteStation
*)st;
151
station->
m_retry
= 0;
152
station->
m_tx_err
++;
153
}
154
bool
155
AmrrWifiManager::IsMinRate
(
AmrrWifiRemoteStation
*station)
const
156
{
157
NS_LOG_FUNCTION
(
this
<< station);
158
return
(station->
m_txrate
== 0);
159
}
160
bool
161
AmrrWifiManager::IsMaxRate
(
AmrrWifiRemoteStation
*station)
const
162
{
163
NS_LOG_FUNCTION
(
this
<< station);
164
NS_ASSERT
(station->
m_txrate
+ 1 <=
GetNSupported
(station));
165
return
(station->
m_txrate
+ 1 ==
GetNSupported
(station));
166
}
167
bool
168
AmrrWifiManager::IsSuccess
(
AmrrWifiRemoteStation
*station)
const
169
{
170
NS_LOG_FUNCTION
(
this
<< station);
171
return
(station->
m_tx_retr
+ station->
m_tx_err
) < station->
m_tx_ok
*
m_successRatio
;
172
}
173
bool
174
AmrrWifiManager::IsFailure
(
AmrrWifiRemoteStation
*station)
const
175
{
176
NS_LOG_FUNCTION
(
this
<< station);
177
return
(station->
m_tx_retr
+ station->
m_tx_err
) > station->
m_tx_ok
*
m_failureRatio
;
178
}
179
bool
180
AmrrWifiManager::IsEnough
(
AmrrWifiRemoteStation
*station)
const
181
{
182
NS_LOG_FUNCTION
(
this
<< station);
183
return
(station->
m_tx_retr
+ station->
m_tx_err
+ station->
m_tx_ok
) > 10;
184
}
185
void
186
AmrrWifiManager::ResetCnt
(
AmrrWifiRemoteStation
*station)
187
{
188
NS_LOG_FUNCTION
(
this
<< station);
189
station->
m_tx_ok
= 0;
190
station->
m_tx_err
= 0;
191
station->
m_tx_retr
= 0;
192
}
193
void
194
AmrrWifiManager::IncreaseRate
(
AmrrWifiRemoteStation
*station)
195
{
196
NS_LOG_FUNCTION
(
this
<< station);
197
station->
m_txrate
++;
198
NS_ASSERT
(station->
m_txrate
<
GetNSupported
(station));
199
}
200
void
201
AmrrWifiManager::DecreaseRate
(
AmrrWifiRemoteStation
*station)
202
{
203
NS_LOG_FUNCTION
(
this
<< station);
204
station->
m_txrate
--;
205
}
206
207
void
208
AmrrWifiManager::UpdateMode
(
AmrrWifiRemoteStation
*station)
209
{
210
NS_LOG_FUNCTION
(
this
<< station);
211
if
(
Simulator::Now
() < station->
m_nextModeUpdate
)
212
{
213
return
;
214
}
215
station->
m_nextModeUpdate
=
Simulator::Now
() +
m_updatePeriod
;
216
NS_LOG_DEBUG
(
"Update"
);
217
218
bool
needChange =
false
;
219
220
if
(
IsSuccess
(station) &&
IsEnough
(station))
221
{
222
station->
m_success
++;
223
NS_LOG_DEBUG
(
"++ success="
<< station->
m_success
<<
" successThreshold="
<< station->
m_successThreshold
<<
224
" tx_ok="
<< station->
m_tx_ok
<<
" tx_err="
<< station->
m_tx_err
<<
" tx_retr="
<< station->
m_tx_retr
<<
225
" rate="
<< station->
m_txrate
<<
" n-supported-rates="
<<
GetNSupported
(station));
226
if
(station->
m_success
>= station->
m_successThreshold
227
&& !
IsMaxRate
(station))
228
{
229
station->
m_recovery
=
true
;
230
station->
m_success
= 0;
231
IncreaseRate
(station);
232
needChange =
true
;
233
}
234
else
235
{
236
station->
m_recovery
=
false
;
237
}
238
}
239
else
if
(
IsFailure
(station))
240
{
241
station->
m_success
= 0;
242
NS_LOG_DEBUG
(
"-- success="
<< station->
m_success
<<
" successThreshold="
<< station->
m_successThreshold
<<
243
" tx_ok="
<< station->
m_tx_ok
<<
" tx_err="
<< station->
m_tx_err
<<
" tx_retr="
<< station->
m_tx_retr
<<
244
" rate="
<< station->
m_txrate
<<
" n-supported-rates="
<<
GetNSupported
(station));
245
if
(!
IsMinRate
(station))
246
{
247
if
(station->
m_recovery
)
248
{
249
station->
m_successThreshold
*= 2;
250
station->
m_successThreshold
= std::min (station->
m_successThreshold
,
251
m_maxSuccessThreshold
);
252
}
253
else
254
{
255
station->
m_successThreshold
=
m_minSuccessThreshold
;
256
}
257
station->
m_recovery
=
false
;
258
DecreaseRate
(station);
259
needChange =
true
;
260
}
261
else
262
{
263
station->
m_recovery
=
false
;
264
}
265
}
266
if
(
IsEnough
(station) || needChange)
267
{
268
NS_LOG_DEBUG
(
"Reset"
);
269
ResetCnt
(station);
270
}
271
}
272
WifiTxVector
273
AmrrWifiManager::DoGetDataTxVector
(
WifiRemoteStation
*st, uint32_t size)
274
{
275
NS_LOG_FUNCTION
(
this
<< st << size);
276
AmrrWifiRemoteStation
*station = (
AmrrWifiRemoteStation
*)st;
277
UpdateMode
(station);
278
NS_ASSERT
(station->
m_txrate
<
GetNSupported
(station));
279
uint32_t rateIndex;
280
if
(station->
m_retry
< 1)
281
{
282
rateIndex = station->
m_txrate
;
283
}
284
else
if
(station->
m_retry
< 2)
285
{
286
if
(station->
m_txrate
> 0)
287
{
288
rateIndex = station->
m_txrate
- 1;
289
}
290
else
291
{
292
rateIndex = station->
m_txrate
;
293
}
294
}
295
else
if
(station->
m_retry
< 3)
296
{
297
if
(station->
m_txrate
> 1)
298
{
299
rateIndex = station->
m_txrate
- 2;
300
}
301
else
302
{
303
rateIndex = station->
m_txrate
;
304
}
305
}
306
else
307
{
308
if
(station->
m_txrate
> 2)
309
{
310
rateIndex = station->
m_txrate
- 3;
311
}
312
else
313
{
314
rateIndex = station->
m_txrate
;
315
}
316
}
317
318
return
WifiTxVector
(
GetSupported
(station, rateIndex),
GetDefaultTxPowerLevel
(),
GetLongRetryCount
(station),
GetShortGuardInterval
(station),
Min
(
GetNumberOfReceiveAntennas
(station),
GetNumberOfTransmitAntennas
()),
GetNumberOfTransmitAntennas
(station),
GetStbc
(station));
319
}
320
WifiTxVector
321
AmrrWifiManager::DoGetRtsTxVector
(
WifiRemoteStation
*st)
322
{
323
NS_LOG_FUNCTION
(
this
<< st);
324
AmrrWifiRemoteStation
*station = (
AmrrWifiRemoteStation
*)st;
325
UpdateMode
(station);
327
return
WifiTxVector
(
GetSupported
(station, 0),
GetDefaultTxPowerLevel
(),
GetLongRetryCount
(station),
GetShortGuardInterval
(station),
Min
(
GetNumberOfReceiveAntennas
(station),
GetNumberOfTransmitAntennas
()),
GetNumberOfTransmitAntennas
(station),
GetStbc
(station));
328
}
329
330
331
bool
332
AmrrWifiManager::IsLowLatency
(
void
)
const
333
{
334
NS_LOG_FUNCTION
(
this
);
335
return
true
;
336
}
337
338
}
// namespace ns3
src
wifi
model
amrr-wifi-manager.cc
Generated on Fri Aug 30 2013 01:43:04 for ns-3 by
1.8.1.2