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
onoe-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 "
onoe-wifi-manager.h
"
22
#include "ns3/simulator.h"
23
#include "ns3/log.h"
24
#include "ns3/uinteger.h"
25
26
#define Min(a,b) ((a < b) ? a : b)
27
28
NS_LOG_COMPONENT_DEFINE
(
"OnoeWifiRemoteStation"
);
29
30
namespace
ns3 {
31
32
struct
OnoeWifiRemoteStation
:
public
WifiRemoteStation
33
{
34
Time
m_nextModeUpdate
;
35
uint32_t
m_shortRetry
;
36
uint32_t
m_longRetry
;
37
uint32_t
m_tx_ok
;
38
uint32_t
m_tx_err
;
39
uint32_t
m_tx_retr
;
40
uint32_t
m_tx_upper
;
41
uint32_t
m_txrate
;
42
};
43
44
45
NS_OBJECT_ENSURE_REGISTERED
(
OnoeWifiManager
);
46
47
TypeId
48
OnoeWifiManager::GetTypeId
(
void
)
49
{
50
static
TypeId
tid =
TypeId
(
"ns3::OnoeWifiManager"
)
51
.
SetParent
<
WifiRemoteStationManager
> ()
52
.AddConstructor<OnoeWifiManager> ()
53
.AddAttribute (
"UpdatePeriod"
,
54
"The interval between decisions about rate control changes"
,
55
TimeValue
(Seconds (1.0)),
56
MakeTimeAccessor (&
OnoeWifiManager::m_updatePeriod
),
57
MakeTimeChecker
())
58
.AddAttribute (
"RaiseThreshold"
,
"Attempt to raise the rate if we hit that threshold"
,
59
UintegerValue
(10),
60
MakeUintegerAccessor (&
OnoeWifiManager::m_raiseThreshold
),
61
MakeUintegerChecker<uint32_t> ())
62
.AddAttribute (
"AddCreditThreshold"
,
"Add credit threshold"
,
63
UintegerValue
(10),
64
MakeUintegerAccessor (&
OnoeWifiManager::m_addCreditThreshold
),
65
MakeUintegerChecker<uint32_t> ())
66
;
67
return
tid;
68
}
69
70
OnoeWifiManager::OnoeWifiManager
()
71
{
72
}
73
WifiRemoteStation
*
74
OnoeWifiManager::DoCreateStation
(
void
)
const
75
{
76
OnoeWifiRemoteStation
*station =
new
OnoeWifiRemoteStation
();
77
station->
m_nextModeUpdate
=
Simulator::Now
() +
m_updatePeriod
;
78
station->
m_shortRetry
= 0;
79
station->
m_longRetry
= 0;
80
station->
m_tx_ok
= 0;
81
station->
m_tx_err
= 0;
82
station->
m_tx_retr
= 0;
83
station->
m_tx_upper
= 0;
84
station->
m_txrate
= 0;
85
return
station;
86
}
87
void
88
OnoeWifiManager::DoReportRxOk
(
WifiRemoteStation
*station,
89
double
rxSnr,
WifiMode
txMode)
90
{
91
}
92
void
93
OnoeWifiManager::DoReportRtsFailed
(
WifiRemoteStation
*st)
94
{
95
OnoeWifiRemoteStation
*station = (
OnoeWifiRemoteStation
*)st;
96
station->
m_shortRetry
++;
97
}
98
void
99
OnoeWifiManager::DoReportDataFailed
(
WifiRemoteStation
*st)
100
{
101
OnoeWifiRemoteStation
*station = (
OnoeWifiRemoteStation
*)st;
102
station->
m_longRetry
++;
103
}
104
void
105
OnoeWifiManager::DoReportRtsOk
(
WifiRemoteStation
*station,
106
double
ctsSnr,
WifiMode
ctsMode,
double
rtsSnr)
107
{
108
}
109
void
110
OnoeWifiManager::DoReportDataOk
(
WifiRemoteStation
*st,
111
double
ackSnr,
WifiMode
ackMode,
double
dataSnr)
112
{
113
OnoeWifiRemoteStation
*station = (
OnoeWifiRemoteStation
*)st;
114
UpdateRetry
(station);
115
station->
m_tx_ok
++;
116
}
117
void
118
OnoeWifiManager::DoReportFinalRtsFailed
(
WifiRemoteStation
*st)
119
{
120
OnoeWifiRemoteStation
*station = (
OnoeWifiRemoteStation
*)st;
121
UpdateRetry
(station);
122
station->
m_tx_err
++;
123
}
124
void
125
OnoeWifiManager::DoReportFinalDataFailed
(
WifiRemoteStation
*st)
126
{
127
OnoeWifiRemoteStation
*station = (
OnoeWifiRemoteStation
*)st;
128
UpdateRetry
(station);
129
station->
m_tx_err
++;
130
}
131
void
132
OnoeWifiManager::UpdateRetry
(
OnoeWifiRemoteStation
*station)
133
{
134
station->
m_tx_retr
+= station->
m_shortRetry
+ station->
m_longRetry
;
135
station->
m_shortRetry
= 0;
136
station->
m_longRetry
= 0;
137
}
138
void
139
OnoeWifiManager::UpdateMode
(
OnoeWifiRemoteStation
*station)
140
{
141
if
(
Simulator::Now
() < station->
m_nextModeUpdate
)
142
{
143
return
;
144
}
145
station->
m_nextModeUpdate
=
Simulator::Now
() +
m_updatePeriod
;
151
int
dir = 0, enough;
152
uint32_t nrate;
153
enough = (station->
m_tx_ok
+ station->
m_tx_err
>= 10);
154
155
/* no packet reached -> down */
156
if
(station->
m_tx_err
> 0 && station->
m_tx_ok
== 0)
157
{
158
dir = -1;
159
}
160
161
/* all packets needs retry in average -> down */
162
if
(enough && station->
m_tx_ok
< station->
m_tx_retr
)
163
{
164
dir = -1;
165
}
166
167
/* no error and less than rate_raise% of packets need retry -> up */
168
if
(enough && station->
m_tx_err
== 0
169
&& station->
m_tx_retr
< (station->
m_tx_ok
*
m_addCreditThreshold
) / 100)
170
{
171
dir = 1;
172
}
173
174
NS_LOG_DEBUG
(
this
<<
" ok "
<< station->
m_tx_ok
<<
" err "
<< station->
m_tx_err
<<
" retr "
<< station->
m_tx_retr
<<
175
" upper "
<< station->
m_tx_upper
<<
" dir "
<< dir);
176
177
nrate = station->
m_txrate
;
178
switch
(dir)
179
{
180
case
0:
181
if
(enough && station->
m_tx_upper
> 0)
182
{
183
station->
m_tx_upper
--;
184
}
185
break
;
186
case
-1:
187
if
(nrate > 0)
188
{
189
nrate--;
190
}
191
station->
m_tx_upper
= 0;
192
break
;
193
case
1:
194
/* raise rate if we hit rate_raise_threshold */
195
if
(++station->
m_tx_upper
<
m_raiseThreshold
)
196
{
197
break
;
198
}
199
station->
m_tx_upper
= 0;
200
if
(nrate + 1 <
GetNSupported
(station))
201
{
202
nrate++;
203
}
204
break
;
205
}
206
207
if
(nrate != station->
m_txrate
)
208
{
209
NS_ASSERT
(nrate <
GetNSupported
(station));
210
station->
m_txrate
= nrate;
211
station->
m_tx_ok
= station->
m_tx_err
= station->
m_tx_retr
= station->
m_tx_upper
= 0;
212
}
213
else
if
(enough)
214
{
215
station->
m_tx_ok
= station->
m_tx_err
= station->
m_tx_retr
= 0;
216
}
217
218
}
219
220
WifiTxVector
221
OnoeWifiManager::DoGetDataTxVector
(
WifiRemoteStation
*st,
222
uint32_t size)
223
{
224
OnoeWifiRemoteStation
*station = (
OnoeWifiRemoteStation
*)st;
225
UpdateMode
(station);
226
NS_ASSERT
(station->
m_txrate
<
GetNSupported
(station));
227
uint32_t rateIndex;
228
if
(station->
m_longRetry
< 4)
229
{
230
rateIndex = station->
m_txrate
;
231
}
232
else
if
(station->
m_longRetry
< 6)
233
{
234
if
(station->
m_txrate
> 0)
235
{
236
rateIndex = station->
m_txrate
- 1;
237
}
238
else
239
{
240
rateIndex = station->
m_txrate
;
241
}
242
}
243
else
if
(station->
m_longRetry
< 8)
244
{
245
if
(station->
m_txrate
> 1)
246
{
247
rateIndex = station->
m_txrate
- 2;
248
}
249
else
250
{
251
rateIndex = station->
m_txrate
;
252
}
253
}
254
else
255
{
256
if
(station->
m_txrate
> 2)
257
{
258
rateIndex = station->
m_txrate
- 3;
259
}
260
else
261
{
262
rateIndex = station->
m_txrate
;
263
}
264
}
265
return
WifiTxVector
(
GetSupported
(station, rateIndex),
GetDefaultTxPowerLevel
(),
GetLongRetryCount
(station),
GetShortGuardInterval
(station),
Min
(
GetNumberOfReceiveAntennas
(station),
GetNumberOfTransmitAntennas
()),
GetNumberOfTransmitAntennas
(station),
GetStbc
(station));
266
}
267
WifiTxVector
268
OnoeWifiManager::DoGetRtsTxVector
(
WifiRemoteStation
*st)
269
{
270
OnoeWifiRemoteStation
*station = (
OnoeWifiRemoteStation
*)st;
271
UpdateMode
(station);
273
return
WifiTxVector
(
GetSupported
(station, 0),
GetDefaultTxPowerLevel
(),
GetShortRetryCount
(station),
GetShortGuardInterval
(station),
Min
(
GetNumberOfReceiveAntennas
(station),
GetNumberOfTransmitAntennas
()),
GetNumberOfTransmitAntennas
(station),
GetStbc
(station));
274
}
275
276
bool
277
OnoeWifiManager::IsLowLatency
(
void
)
const
278
{
279
return
false
;
280
}
281
282
}
// namespace ns3
src
wifi
model
onoe-wifi-manager.cc
Generated on Fri Aug 30 2013 01:43:05 for ns-3 by
1.8.1.2