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
aarfcd-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) 2004,2005,2006 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: Federico Maguolo <maguolof@dei.unipd.it>
19
*/
20
21
#include "
aarfcd-wifi-manager.h
"
22
#include "ns3/assert.h"
23
#include "ns3/log.h"
24
#include "ns3/simulator.h"
25
#include "ns3/boolean.h"
26
#include "ns3/double.h"
27
#include "ns3/uinteger.h"
28
#include <algorithm>
29
30
#define Min(a,b) ((a < b) ? a : b)
31
#define Max(a,b) ((a > b) ? a : b)
32
33
NS_LOG_COMPONENT_DEFINE
(
"Aarfcd"
);
34
35
namespace
ns3 {
36
37
struct
AarfcdWifiRemoteStation
:
public
WifiRemoteStation
38
{
39
uint32_t
m_timer
;
40
uint32_t
m_success
;
41
uint32_t
m_failed
;
42
bool
m_recovery
;
43
bool
m_justModifyRate
;
44
uint32_t
m_retry
;
45
46
uint32_t
m_successThreshold
;
47
uint32_t
m_timerTimeout
;
48
49
uint32_t
m_rate
;
50
bool
m_rtsOn
;
51
uint32_t
m_rtsWnd
;
52
uint32_t
m_rtsCounter
;
53
bool
m_haveASuccess
;
54
};
55
56
NS_OBJECT_ENSURE_REGISTERED
(
AarfcdWifiManager
);
57
58
TypeId
59
AarfcdWifiManager::GetTypeId
(
void
)
60
{
61
static
TypeId
tid =
TypeId
(
"ns3::AarfcdWifiManager"
)
62
.
SetParent
<
WifiRemoteStationManager
> ()
63
.AddConstructor<AarfcdWifiManager> ()
64
.AddAttribute (
"SuccessK"
,
"Multiplication factor for the success threshold in the AARF algorithm."
,
65
DoubleValue
(2.0),
66
MakeDoubleAccessor (&
AarfcdWifiManager::m_successK
),
67
MakeDoubleChecker<double> ())
68
.AddAttribute (
"TimerK"
,
69
"Multiplication factor for the timer threshold in the AARF algorithm."
,
70
DoubleValue
(2.0),
71
MakeDoubleAccessor (&
AarfcdWifiManager::m_timerK
),
72
MakeDoubleChecker<double> ())
73
.AddAttribute (
"MaxSuccessThreshold"
,
74
"Maximum value of the success threshold in the AARF algorithm."
,
75
UintegerValue
(60),
76
MakeUintegerAccessor (&
AarfcdWifiManager::m_maxSuccessThreshold
),
77
MakeUintegerChecker<uint32_t> ())
78
.AddAttribute (
"MinTimerThreshold"
,
79
"The minimum value for the 'timer' threshold in the AARF algorithm."
,
80
UintegerValue
(15),
81
MakeUintegerAccessor (&
AarfcdWifiManager::m_minTimerThreshold
),
82
MakeUintegerChecker<uint32_t> ())
83
.AddAttribute (
"MinSuccessThreshold"
,
84
"The minimum value for the success threshold in the AARF algorithm."
,
85
UintegerValue
(10),
86
MakeUintegerAccessor (&
AarfcdWifiManager::m_minSuccessThreshold
),
87
MakeUintegerChecker<uint32_t> ())
88
.AddAttribute (
"MinRtsWnd"
,
89
"Minimum value for Rts window of Aarf-CD"
,
90
UintegerValue
(1),
91
MakeUintegerAccessor (&
AarfcdWifiManager::m_minRtsWnd
),
92
MakeUintegerChecker<uint32_t> ())
93
.AddAttribute (
"MaxRtsWnd"
,
94
"Maximum value for Rts window of Aarf-CD"
,
95
UintegerValue
(40),
96
MakeUintegerAccessor (&
AarfcdWifiManager::m_maxRtsWnd
),
97
MakeUintegerChecker<uint32_t> ())
98
.AddAttribute (
"TurnOffRtsAfterRateDecrease"
,
99
"If true the RTS mechanism will be turned off when the rate will be decreased"
,
100
BooleanValue
(
true
),
101
MakeBooleanAccessor (&
AarfcdWifiManager::m_turnOffRtsAfterRateDecrease
),
102
MakeBooleanChecker ())
103
.AddAttribute (
"TurnOnRtsAfterRateIncrease"
,
104
"If true the RTS mechanism will be turned on when the rate will be increased"
,
105
BooleanValue
(
true
),
106
MakeBooleanAccessor (&
AarfcdWifiManager::m_turnOnRtsAfterRateIncrease
),
107
MakeBooleanChecker ())
108
;
109
return
tid;
110
}
111
AarfcdWifiManager::AarfcdWifiManager
()
112
:
WifiRemoteStationManager
()
113
{
114
}
115
AarfcdWifiManager::~AarfcdWifiManager
()
116
{
117
}
118
WifiRemoteStation
*
119
AarfcdWifiManager::DoCreateStation
(
void
)
const
120
{
121
AarfcdWifiRemoteStation
*station =
new
AarfcdWifiRemoteStation
();
122
123
// aarf fields below
124
station->
m_successThreshold
=
m_minSuccessThreshold
;
125
station->
m_timerTimeout
=
m_minTimerThreshold
;
126
station->
m_rate
= 0;
127
station->
m_success
= 0;
128
station->
m_failed
= 0;
129
station->
m_recovery
=
false
;
130
station->
m_retry
= 0;
131
station->
m_timer
= 0;
132
133
// aarf-cd specific fields below
134
station->
m_rtsOn
=
false
;
135
station->
m_rtsWnd
=
m_minRtsWnd
;
136
station->
m_rtsCounter
= 0;
137
station->
m_justModifyRate
=
true
;
138
station->
m_haveASuccess
=
false
;
139
140
return
station;
141
}
142
143
void
144
AarfcdWifiManager::DoReportRtsFailed
(
WifiRemoteStation
*station)
145
{
146
}
156
void
157
AarfcdWifiManager::DoReportDataFailed
(
WifiRemoteStation
*st)
158
{
159
160
AarfcdWifiRemoteStation
*station = (
AarfcdWifiRemoteStation
*)st;
161
station->
m_timer
++;
162
station->
m_failed
++;
163
station->
m_retry
++;
164
station->
m_success
= 0;
165
166
if
(!station->
m_rtsOn
)
167
{
168
TurnOnRts
(station);
169
if
(!station->
m_justModifyRate
&& !station->
m_haveASuccess
)
170
{
171
IncreaseRtsWnd
(station);
172
}
173
else
174
{
175
ResetRtsWnd
(station);
176
}
177
station->
m_rtsCounter
= station->
m_rtsWnd
;
178
if
(station->
m_retry
>= 2)
179
{
180
station->
m_timer
= 0;
181
}
182
}
183
else
if
(station->
m_recovery
)
184
{
185
NS_ASSERT
(station->
m_retry
>= 1);
186
station->
m_justModifyRate
=
false
;
187
station->
m_rtsCounter
= station->
m_rtsWnd
;
188
if
(station->
m_retry
== 1)
189
{
190
// need recovery fallback
191
if
(
m_turnOffRtsAfterRateDecrease
)
192
{
193
TurnOffRts
(station);
194
}
195
station->
m_justModifyRate
=
true
;
196
station->
m_successThreshold
= (int)(
Min
(station->
m_successThreshold
*
m_successK
,
197
m_maxSuccessThreshold
));
198
station->
m_timerTimeout
= (int)(
Max
(station->
m_timerTimeout
*
m_timerK
,
199
m_minSuccessThreshold
));
200
if
(station->
m_rate
!= 0)
201
{
202
station->
m_rate
--;
203
}
204
}
205
station->
m_timer
= 0;
206
}
207
else
208
{
209
NS_ASSERT
(station->
m_retry
>= 1);
210
station->
m_justModifyRate
=
false
;
211
station->
m_rtsCounter
= station->
m_rtsWnd
;
212
if
(((station->
m_retry
- 1) % 2) == 1)
213
{
214
// need normal fallback
215
if
(
m_turnOffRtsAfterRateDecrease
)
216
{
217
TurnOffRts
(station);
218
}
219
station->
m_justModifyRate
=
true
;
220
station->
m_timerTimeout
=
m_minTimerThreshold
;
221
station->
m_successThreshold
=
m_minSuccessThreshold
;
222
if
(station->
m_rate
!= 0)
223
{
224
station->
m_rate
--;
225
}
226
}
227
if
(station->
m_retry
>= 2)
228
{
229
station->
m_timer
= 0;
230
}
231
}
232
CheckRts
(station);
233
}
234
void
235
AarfcdWifiManager::DoReportRxOk
(
WifiRemoteStation
*station,
236
double
rxSnr,
WifiMode
txMode)
237
{
238
}
239
void
240
AarfcdWifiManager::DoReportRtsOk
(
WifiRemoteStation
*st,
241
double
ctsSnr,
WifiMode
ctsMode,
double
rtsSnr)
242
{
243
AarfcdWifiRemoteStation
*station = (
AarfcdWifiRemoteStation
*) st;
244
NS_LOG_DEBUG
(
"station="
<< station <<
" rts ok"
);
245
station->
m_rtsCounter
--;
246
}
247
void
248
AarfcdWifiManager::DoReportDataOk
(
WifiRemoteStation
*st,
249
double
ackSnr,
WifiMode
ackMode,
double
dataSnr)
250
{
251
AarfcdWifiRemoteStation
*station = (
AarfcdWifiRemoteStation
*) st;
252
station->
m_timer
++;
253
station->
m_success
++;
254
station->
m_failed
= 0;
255
station->
m_recovery
=
false
;
256
station->
m_retry
= 0;
257
station->
m_justModifyRate
=
false
;
258
station->
m_haveASuccess
=
true
;
259
NS_LOG_DEBUG
(
"station="
<< station <<
" data ok success="
<< station->
m_success
<<
", timer="
<< station->
m_timer
);
260
if
((station->
m_success
== station->
m_successThreshold
261
|| station->
m_timer
== station->
m_timerTimeout
)
262
&& (station->
m_rate
< (
GetNSupported
(station) - 1)))
263
{
264
NS_LOG_DEBUG
(
"station="
<< station <<
" inc rate"
);
265
station->
m_rate
++;
266
station->
m_timer
= 0;
267
station->
m_success
= 0;
268
station->
m_recovery
=
true
;
269
station->
m_justModifyRate
=
true
;
270
if
(
m_turnOnRtsAfterRateIncrease
)
271
{
272
TurnOnRts
(station);
273
ResetRtsWnd
(station);
274
station->
m_rtsCounter
= station->
m_rtsWnd
;
275
}
276
}
277
CheckRts
(station);
278
}
279
void
280
AarfcdWifiManager::DoReportFinalRtsFailed
(
WifiRemoteStation
*station)
281
{
282
}
283
void
284
AarfcdWifiManager::DoReportFinalDataFailed
(
WifiRemoteStation
*station)
285
{
286
}
287
288
WifiMode
289
AarfcdWifiManager::DoGetDataMode
(
WifiRemoteStation
*st, uint32_t size)
290
{
291
AarfcdWifiRemoteStation
*station = (
AarfcdWifiRemoteStation
*) st;
292
return
GetSupported
(station, station->
m_rate
);
293
}
294
WifiMode
295
AarfcdWifiManager::DoGetRtsMode
(
WifiRemoteStation
*st)
296
{
297
// XXX: we could/should implement the Aarf algorithm for
298
// RTS only by picking a single rate within the BasicRateSet.
299
AarfcdWifiRemoteStation
*station = (
AarfcdWifiRemoteStation
*) st;
300
return
GetSupported
(station, 0);
301
}
302
303
bool
304
AarfcdWifiManager::DoNeedRts
(
WifiRemoteStation
*st,
305
Ptr<const Packet>
packet,
bool
normally)
306
{
307
AarfcdWifiRemoteStation
*station = (
AarfcdWifiRemoteStation
*) st;
308
NS_LOG_INFO
(
""
<< station <<
" rate="
<< station->
m_rate
<<
" rts="
<< (station->
m_rtsOn
?
"RTS"
:
"BASIC"
) <<
309
" rtsCounter="
<< station->
m_rtsCounter
);
310
return
station->
m_rtsOn
;
311
}
312
313
bool
314
AarfcdWifiManager::IsLowLatency
(
void
)
const
315
{
316
return
true
;
317
}
318
319
void
320
AarfcdWifiManager::CheckRts
(
AarfcdWifiRemoteStation
*station)
321
{
322
if
(station->
m_rtsCounter
== 0 && station->
m_rtsOn
)
323
{
324
TurnOffRts
(station);
325
}
326
}
327
328
void
329
AarfcdWifiManager::TurnOffRts
(
AarfcdWifiRemoteStation
*station)
330
{
331
station->
m_rtsOn
=
false
;
332
station->
m_haveASuccess
=
false
;
333
}
334
335
void
336
AarfcdWifiManager::TurnOnRts
(
AarfcdWifiRemoteStation
*station)
337
{
338
station->
m_rtsOn
=
true
;
339
}
340
341
void
342
AarfcdWifiManager::IncreaseRtsWnd
(
AarfcdWifiRemoteStation
*station)
343
{
344
if
(station->
m_rtsWnd
==
m_maxRtsWnd
)
345
{
346
return
;
347
}
348
349
station->
m_rtsWnd
*= 2;
350
if
(station->
m_rtsWnd
>
m_maxRtsWnd
)
351
{
352
station->
m_rtsWnd
=
m_maxRtsWnd
;
353
}
354
}
355
356
void
357
AarfcdWifiManager::ResetRtsWnd
(
AarfcdWifiRemoteStation
*station)
358
{
359
station->
m_rtsWnd
=
m_minRtsWnd
;
360
}
361
362
363
}
// namespace ns3
src
wifi
model
aarfcd-wifi-manager.cc
Generated on Tue Oct 9 2012 16:45:48 for ns-3 by
1.8.1.2