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
rraa-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 "
rraa-wifi-manager.h
"
22
#include "ns3/assert.h"
23
#include "ns3/log.h"
24
#include "ns3/boolean.h"
25
#include "ns3/double.h"
26
#include "ns3/uinteger.h"
27
#include "ns3/simulator.h"
28
29
#define Min(a,b) ((a < b) ? a : b)
30
31
NS_LOG_COMPONENT_DEFINE
(
"RraaWifiManager"
);
32
33
namespace
ns3 {
34
35
struct
RraaWifiRemoteStation
:
public
WifiRemoteStation
36
{
37
uint32_t
m_counter
;
38
uint32_t
m_failed
;
39
uint32_t
m_rtsWnd
;
40
uint32_t
m_rtsCounter
;
41
Time
m_lastReset
;
42
bool
m_rtsOn
;
43
bool
m_lastFrameFail
;
44
bool
m_initialized
;
45
46
uint32_t
m_rate
;
47
};
48
49
NS_OBJECT_ENSURE_REGISTERED
(
RraaWifiManager
);
50
51
TypeId
52
RraaWifiManager::GetTypeId
(
void
)
53
{
54
static
TypeId
tid =
TypeId
(
"ns3::RraaWifiManager"
)
55
.
SetParent
<
WifiRemoteStationManager
> ()
56
.AddConstructor<RraaWifiManager> ()
57
.AddAttribute (
"Basic"
,
58
"If true the RRAA-BASIC algorithm will be used, otherwise the RRAA wil be used"
,
59
BooleanValue
(
false
),
60
MakeBooleanAccessor (&
RraaWifiManager::m_basic
),
61
MakeBooleanChecker ())
62
.AddAttribute (
"Timeout"
,
63
"Timeout for the RRAA BASIC loss estimaton block (s)"
,
64
TimeValue
(Seconds (0.05)),
65
MakeTimeAccessor (&
RraaWifiManager::m_timeout
),
66
MakeTimeChecker
())
67
.AddAttribute (
"ewndFor54mbps"
,
68
"ewnd parameter for 54 Mbs data mode"
,
69
UintegerValue
(40),
70
MakeUintegerAccessor (&
RraaWifiManager::m_ewndfor54
),
71
MakeUintegerChecker<uint32_t> ())
72
.AddAttribute (
"ewndFor48mbps"
,
73
"ewnd parameter for 48 Mbs data mode"
,
74
UintegerValue
(40),
75
MakeUintegerAccessor (&
RraaWifiManager::m_ewndfor48
),
76
MakeUintegerChecker<uint32_t> ())
77
.AddAttribute (
"ewndFor36mbps"
,
78
"ewnd parameter for 36 Mbs data mode"
,
79
UintegerValue
(40),
80
MakeUintegerAccessor (&
RraaWifiManager::m_ewndfor36
),
81
MakeUintegerChecker<uint32_t> ())
82
.AddAttribute (
"ewndFor24mbps"
,
83
"ewnd parameter for 24 Mbs data mode"
,
84
UintegerValue
(40),
85
MakeUintegerAccessor (&
RraaWifiManager::m_ewndfor24
),
86
MakeUintegerChecker<uint32_t> ())
87
.AddAttribute (
"ewndFor18mbps"
,
88
"ewnd parameter for 18 Mbs data mode"
,
89
UintegerValue
(20),
90
MakeUintegerAccessor (&
RraaWifiManager::m_ewndfor18
),
91
MakeUintegerChecker<uint32_t> ())
92
.AddAttribute (
"ewndFor12mbps"
,
93
"ewnd parameter for 12 Mbs data mode"
,
94
UintegerValue
(20),
95
MakeUintegerAccessor (&
RraaWifiManager::m_ewndfor12
),
96
MakeUintegerChecker<uint32_t> ())
97
.AddAttribute (
"ewndFor9mbps"
,
98
"ewnd parameter for 9 Mbs data mode"
,
99
UintegerValue
(10),
100
MakeUintegerAccessor (&
RraaWifiManager::m_ewndfor9
),
101
MakeUintegerChecker<uint32_t> ())
102
.AddAttribute (
"ewndFor6mbps"
,
103
"ewnd parameter for 6 Mbs data mode"
,
104
UintegerValue
(6),
105
MakeUintegerAccessor (&
RraaWifiManager::m_ewndfor6
),
106
MakeUintegerChecker<uint32_t> ())
107
.AddAttribute (
"poriFor48mbps"
,
108
"Pori parameter for 48 Mbs data mode"
,
109
DoubleValue
(0.047),
110
MakeDoubleAccessor (&
RraaWifiManager::m_porifor48
),
111
MakeDoubleChecker<double> ())
112
.AddAttribute (
"poriFor36mbps"
,
113
"Pori parameter for 36 Mbs data mode"
,
114
DoubleValue
(0.115),
115
MakeDoubleAccessor (&
RraaWifiManager::m_porifor36
),
116
MakeDoubleChecker<double> ())
117
.AddAttribute (
"poriFor24mbps"
,
118
"Pori parameter for 24 Mbs data mode"
,
119
DoubleValue
(0.1681),
120
MakeDoubleAccessor (&
RraaWifiManager::m_porifor24
),
121
MakeDoubleChecker<double> ())
122
.AddAttribute (
"poriFor18mbps"
,
123
"Pori parameter for 18 Mbs data mode"
,
124
DoubleValue
(0.1325),
125
MakeDoubleAccessor (&
RraaWifiManager::m_porifor18
),
126
MakeDoubleChecker<double> ())
127
.AddAttribute (
"poriFor12mbps"
,
128
"Pori parameter for 12 Mbs data mode"
,
129
DoubleValue
(0.1861),
130
MakeDoubleAccessor (&
RraaWifiManager::m_porifor12
),
131
MakeDoubleChecker<double> ())
132
.AddAttribute (
"poriFor9mbps"
,
133
"Pori parameter for 9 Mbs data mode"
,
134
DoubleValue
(0.1434),
135
MakeDoubleAccessor (&
RraaWifiManager::m_porifor9
),
136
MakeDoubleChecker<double> ())
137
.AddAttribute (
"poriFor6mbps"
,
138
"Pori parameter for 6 Mbs data mode"
,
139
DoubleValue
(0.5),
140
MakeDoubleAccessor (&
RraaWifiManager::m_porifor6
),
141
MakeDoubleChecker<double> ())
142
.AddAttribute (
"pmtlFor54mbps"
,
143
"Pmtl parameter for 54 Mbs data mode"
,
144
DoubleValue
(0.094),
145
MakeDoubleAccessor (&
RraaWifiManager::m_pmtlfor54
),
146
MakeDoubleChecker<double> ())
147
.AddAttribute (
"pmtlFor48mbps"
,
148
"Pmtl parameter for 48 Mbs data mode"
,
149
DoubleValue
(0.23),
150
MakeDoubleAccessor (&
RraaWifiManager::m_pmtlfor48
),
151
MakeDoubleChecker<double> ())
152
.AddAttribute (
"pmtlFor36mbps"
,
153
"Pmtl parameter for 36 Mbs data mode"
,
154
DoubleValue
(0.3363),
155
MakeDoubleAccessor (&
RraaWifiManager::m_pmtlfor36
),
156
MakeDoubleChecker<double> ())
157
.AddAttribute (
"pmtlFor24mbps"
,
158
"Pmtl parameter for 24 Mbs data mode"
,
159
DoubleValue
(0.265),
160
MakeDoubleAccessor (&
RraaWifiManager::m_pmtlfor24
),
161
MakeDoubleChecker<double> ())
162
.AddAttribute (
"pmtlFor18mbps"
,
163
"Pmtl parameter for 18 Mbs data mode"
,
164
DoubleValue
(0.3722),
165
MakeDoubleAccessor (&
RraaWifiManager::m_pmtlfor18
),
166
MakeDoubleChecker<double> ())
167
.AddAttribute (
"pmtlFor12mbps"
,
168
"Pmtl parameter for 12 Mbs data mode"
,
169
DoubleValue
(0.2868),
170
MakeDoubleAccessor (&
RraaWifiManager::m_pmtlfor12
),
171
MakeDoubleChecker<double> ())
172
.AddAttribute (
"pmtlFor9mbps"
,
173
"Pmtl parameter for 9 Mbs data mode"
,
174
DoubleValue
(0.3932),
175
MakeDoubleAccessor (&
RraaWifiManager::m_pmtlfor9
),
176
MakeDoubleChecker<double> ())
177
;
178
return
tid;
179
}
180
181
182
RraaWifiManager::RraaWifiManager
()
183
{
184
}
185
RraaWifiManager::~RraaWifiManager
()
186
{
187
}
188
189
190
WifiRemoteStation
*
191
RraaWifiManager::DoCreateStation
(
void
)
const
192
{
193
RraaWifiRemoteStation
*station =
new
RraaWifiRemoteStation
();
194
station->
m_initialized
=
false
;
195
station->
m_rtsWnd
= 0;
196
station->
m_rtsCounter
= 0;
197
station->
m_rtsOn
=
false
;
198
station->
m_lastFrameFail
=
false
;
199
return
station;
200
}
201
202
void
203
RraaWifiManager::ResetCountersBasic
(
RraaWifiRemoteStation
*station)
204
{
205
if
(!station->
m_initialized
)
206
{
207
station->
m_rate
=
GetMaxRate
(station);
208
station->
m_initialized
=
true
;
209
}
210
station->
m_failed
= 0;
211
station->
m_counter
=
GetThresholds
(station, station->
m_rate
).
ewnd
;
212
station->
m_lastReset
=
Simulator::Now
();
213
}
214
215
uint32_t
216
RraaWifiManager::GetMaxRate
(
RraaWifiRemoteStation
*station)
217
{
218
return
GetNSupported
(station) - 1;
219
}
220
uint32_t
221
RraaWifiManager::GetMinRate
(
RraaWifiRemoteStation
*station)
222
{
223
return
0;
224
}
225
226
227
void
228
RraaWifiManager::DoReportRtsFailed
(
WifiRemoteStation
*st)
229
{
230
}
231
232
void
233
RraaWifiManager::DoReportDataFailed
(
WifiRemoteStation
*st)
234
{
235
RraaWifiRemoteStation
*station = (
RraaWifiRemoteStation
*) st;
236
station->
m_lastFrameFail
=
true
;
237
CheckTimeout
(station);
238
station->
m_counter
--;
239
station->
m_failed
++;
240
RunBasicAlgorithm
(station);
241
}
242
void
243
RraaWifiManager::DoReportRxOk
(
WifiRemoteStation
*st,
244
double
rxSnr,
WifiMode
txMode)
245
{
246
}
247
void
248
RraaWifiManager::DoReportRtsOk
(
WifiRemoteStation
*st,
249
double
ctsSnr,
WifiMode
ctsMode,
double
rtsSnr)
250
{
251
NS_LOG_DEBUG
(
"self="
<< st <<
" rts ok"
);
252
}
253
void
254
RraaWifiManager::DoReportDataOk
(
WifiRemoteStation
*st,
255
double
ackSnr,
WifiMode
ackMode,
double
dataSnr)
256
{
257
RraaWifiRemoteStation
*station = (
RraaWifiRemoteStation
*) st;
258
station->
m_lastFrameFail
=
false
;
259
CheckTimeout
(station);
260
station->
m_counter
--;
261
RunBasicAlgorithm
(station);
262
}
263
void
264
RraaWifiManager::DoReportFinalRtsFailed
(
WifiRemoteStation
*st)
265
{
266
}
267
void
268
RraaWifiManager::DoReportFinalDataFailed
(
WifiRemoteStation
*st)
269
{
270
}
271
272
WifiTxVector
273
RraaWifiManager::DoGetDataTxVector
(
WifiRemoteStation
*st,
274
uint32_t size)
275
{
276
RraaWifiRemoteStation
*station = (
RraaWifiRemoteStation
*) st;
277
if
(!station->
m_initialized
)
278
{
279
ResetCountersBasic
(station);
280
}
281
return
WifiTxVector
(
GetSupported
(station, station->
m_rate
),
GetDefaultTxPowerLevel
(),
GetLongRetryCount
(station),
GetShortGuardInterval
(station),
Min
(
GetNumberOfReceiveAntennas
(station),
GetNumberOfTransmitAntennas
()),
GetNumberOfTransmitAntennas
(station),
GetStbc
(station));
282
}
283
WifiTxVector
284
RraaWifiManager::DoGetRtsTxVector
(
WifiRemoteStation
*st)
285
{
286
return
WifiTxVector
(
GetSupported
(st, 0),
GetDefaultTxPowerLevel
(),
GetShortRetryCount
(st),
GetShortGuardInterval
(st),
Min
(
GetNumberOfReceiveAntennas
(st),
GetNumberOfTransmitAntennas
()),
GetNumberOfTransmitAntennas
(st),
GetStbc
(st));
287
}
288
289
bool
290
RraaWifiManager::DoNeedRts
(
WifiRemoteStation
*st,
291
Ptr<const Packet>
packet,
bool
normally)
292
{
293
RraaWifiRemoteStation
*station = (
RraaWifiRemoteStation
*) st;
294
if
(
m_basic
)
295
{
296
return
normally;
297
}
298
ARts
(station);
299
return
station->
m_rtsOn
;
300
}
301
302
void
303
RraaWifiManager::CheckTimeout
(
RraaWifiRemoteStation
*station)
304
{
305
Time
d =
Simulator::Now
() - station->
m_lastReset
;
306
if
(station->
m_counter
== 0 || d >
m_timeout
)
307
{
308
ResetCountersBasic
(station);
309
}
310
}
311
312
void
313
RraaWifiManager::RunBasicAlgorithm
(
RraaWifiRemoteStation
*station)
314
{
315
ThresholdsItem
thresholds =
GetThresholds
(station, station->
m_rate
);
316
double
ploss = (double) station->
m_failed
/ (
double
) thresholds.
ewnd
;
317
if
(station->
m_counter
== 0
318
|| ploss > thresholds.
pmtl
)
319
{
320
if
(station->
m_rate
>
GetMinRate
(station)
321
&& ploss > thresholds.
pmtl
)
322
{
323
station->
m_rate
--;
324
}
325
else
if
(station->
m_rate
<
GetMaxRate
(station)
326
&& ploss < thresholds.
pori
)
327
{
328
station->
m_rate
++;
329
}
330
ResetCountersBasic
(station);
331
}
332
}
333
334
void
335
RraaWifiManager::ARts
(
RraaWifiRemoteStation
*station)
336
{
337
if
(!station->
m_rtsOn
338
&& station->
m_lastFrameFail
)
339
{
340
station->
m_rtsWnd
++;
341
station->
m_rtsCounter
= station->
m_rtsWnd
;
342
}
343
else
if
((station->
m_rtsOn
&& station->
m_lastFrameFail
)
344
|| (!station->
m_rtsOn
&& !station->
m_lastFrameFail
))
345
{
346
station->
m_rtsWnd
= station->
m_rtsWnd
/ 2;
347
station->
m_rtsCounter
= station->
m_rtsWnd
;
348
}
349
if
(station->
m_rtsCounter
> 0)
350
{
351
station->
m_rtsOn
=
true
;
352
station->
m_rtsCounter
--;
353
}
354
else
355
{
356
station->
m_rtsOn
=
false
;
357
}
358
}
359
360
struct
RraaWifiManager::ThresholdsItem
361
RraaWifiManager
::GetThresholds (RraaWifiRemoteStation *station,
362
uint32_t rate) const
363
{
364
WifiMode
mode =
GetSupported
(station, rate);
365
return
GetThresholds
(mode);
366
}
367
368
struct
RraaWifiManager::ThresholdsItem
369
RraaWifiManager
::GetThresholds (WifiMode mode) const
370
{
371
switch
(mode.GetDataRate () / 1000000)
372
{
373
case
54:
374
{
375
ThresholdsItem
mode54 = {
376
54000000,
377
0.0,
378
m_pmtlfor54
,
379
m_ewndfor54
380
};
381
return
mode54;
382
}
break
;
383
case
48:
384
{
385
ThresholdsItem
mode48 = {
386
48000000,
387
m_porifor48
,
388
m_pmtlfor48
,
389
m_ewndfor48
390
};
391
return
mode48;
392
}
break
;
393
case
36:
394
{
395
ThresholdsItem
mode36 = {
396
36000000,
397
m_porifor36
,
398
m_pmtlfor36
,
399
m_ewndfor36
400
};
401
return
mode36;
402
}
break
;
403
case
24:
404
{
405
ThresholdsItem
mode24 = {
406
24000000,
407
m_porifor24
,
408
m_pmtlfor24
,
409
m_ewndfor24
410
};
411
return
mode24;
412
}
break
;
413
case
18:
414
{
415
ThresholdsItem
mode18 = {
416
18000000,
417
m_porifor18
,
418
m_pmtlfor18
,
419
m_ewndfor18
420
};
421
return
mode18;
422
}
break
;
423
case
12:
424
{
425
ThresholdsItem
mode12 = {
426
12000000,
427
m_porifor12
,
428
m_pmtlfor12
,
429
m_ewndfor12
430
};
431
return
mode12;
432
}
break
;
433
case
9:
434
{
435
ThresholdsItem
mode9 = {
436
9000000,
437
m_porifor9
,
438
m_pmtlfor9
,
439
m_ewndfor9
440
};
441
return
mode9;
442
}
break
;
443
case
6:
444
{
445
ThresholdsItem
mode6 = {
446
6000000,
447
m_porifor6
,
448
1.0,
449
m_ewndfor6
450
};
451
return
mode6;
452
}
break
;
453
}
454
NS_ASSERT_MSG
(
false
,
"Thresholds for an unknown mode are asked ("
<< mode <<
")"
);
455
return
ThresholdsItem
();
456
}
457
458
bool
459
RraaWifiManager::IsLowLatency
(
void
)
const
460
{
461
return
true
;
462
}
463
464
}
// namespace ns3
src
wifi
model
rraa-wifi-manager.cc
Generated on Fri Aug 30 2013 01:43:05 for ns-3 by
1.8.1.2