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