A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
onoe-wifi-manager.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2003,2007 INRIA
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 */
19
20#include "onoe-wifi-manager.h"
21
22#include "ns3/log.h"
23#include "ns3/simulator.h"
24#include "ns3/wifi-tx-vector.h"
25
26#define Min(a, b) ((a < b) ? a : b)
27
28namespace ns3
29{
30
31NS_LOG_COMPONENT_DEFINE("OnoeWifiManager");
32
33/**
34 * \brief hold per-remote-station state for ONOE Wifi manager.
35 *
36 * This struct extends from WifiRemoteStation struct to hold additional
37 * information required by the ONOE Wifi manager
38 */
40{
41 Time m_nextModeUpdate; ///< next mode update
42 bool m_rateBlocked; ///< whether the rate cannot be changed
43 uint32_t m_shortRetry; ///< short retry
44 uint32_t m_longRetry; ///< long retry
45 uint32_t m_tx_ok; ///< transmit OK
46 uint32_t m_tx_err; ///< transmit error
47 uint32_t m_tx_retr; ///< transmit retry
48 uint32_t m_tx_upper; ///< transmit upper
49 uint8_t m_txrate; ///< transmit rate
50};
51
53
56{
57 static TypeId tid =
58 TypeId("ns3::OnoeWifiManager")
60 .SetGroupName("Wifi")
61 .AddConstructor<OnoeWifiManager>()
62 .AddAttribute("UpdatePeriod",
63 "The interval between decisions about rate control changes",
64 TimeValue(Seconds(1.0)),
67 .AddAttribute("RaiseThreshold",
68 "Attempt to raise the rate if we hit that threshold",
69 UintegerValue(10),
71 MakeUintegerChecker<uint32_t>())
72 .AddAttribute("AddCreditThreshold",
73 "Add credit threshold",
74 UintegerValue(10),
76 MakeUintegerChecker<uint32_t>())
77 .AddTraceSource("Rate",
78 "Traced value for rate changes (b/s)",
80 "ns3::TracedValueCallback::Uint64");
81 return tid;
82}
83
86 m_currentRate(0)
87{
88 NS_LOG_FUNCTION(this);
89}
90
92{
93 NS_LOG_FUNCTION(this);
94}
95
96void
98{
99 NS_LOG_FUNCTION(this);
100 if (GetHtSupported())
101 {
102 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HT rates");
103 }
104 if (GetVhtSupported())
105 {
106 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support VHT rates");
107 }
108 if (GetHeSupported())
109 {
110 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HE rates");
111 }
112}
113
116{
117 NS_LOG_FUNCTION(this);
118 auto station = new OnoeWifiRemoteStation();
119 station->m_nextModeUpdate = Simulator::Now() + m_updatePeriod;
120 station->m_rateBlocked = false;
121 station->m_shortRetry = 0;
122 station->m_longRetry = 0;
123 station->m_tx_ok = 0;
124 station->m_tx_err = 0;
125 station->m_tx_retr = 0;
126 station->m_tx_upper = 0;
127 station->m_txrate = 0;
128 return station;
129}
130
131void
133{
134 NS_LOG_FUNCTION(this << station << rxSnr << txMode);
135}
136
137void
139{
140 NS_LOG_FUNCTION(this << st);
141 auto station = static_cast<OnoeWifiRemoteStation*>(st);
142 station->m_shortRetry++;
143 station->m_rateBlocked = true; // do not change rate for retransmission
144}
145
146void
148{
149 NS_LOG_FUNCTION(this << st);
150 auto station = static_cast<OnoeWifiRemoteStation*>(st);
151 station->m_longRetry++;
152 station->m_rateBlocked = true; // do not change rate for retransmission
153}
154
155void
157 double ctsSnr,
158 WifiMode ctsMode,
159 double rtsSnr)
160{
161 NS_LOG_FUNCTION(this << st << ctsSnr << ctsMode << rtsSnr);
162 auto station = static_cast<OnoeWifiRemoteStation*>(st);
163 station->m_rateBlocked = true; // do not change rate
164}
165
166void
168 double ackSnr,
169 WifiMode ackMode,
170 double dataSnr,
171 uint16_t dataChannelWidth,
172 uint8_t dataNss)
173{
174 NS_LOG_FUNCTION(this << st << ackSnr << ackMode << dataSnr << dataChannelWidth << +dataNss);
175 auto station = static_cast<OnoeWifiRemoteStation*>(st);
176 UpdateRetry(station);
177 station->m_tx_ok++;
178 station->m_rateBlocked = false; // we can change the rate for next packet
179}
180
181void
183{
184 NS_LOG_FUNCTION(this << st);
185 auto station = static_cast<OnoeWifiRemoteStation*>(st);
186 UpdateRetry(station);
187 station->m_tx_err++;
188 station->m_rateBlocked = false; // we can change the rate for next packet
189}
190
191void
193{
194 NS_LOG_FUNCTION(this << st);
195 auto station = static_cast<OnoeWifiRemoteStation*>(st);
196 UpdateRetry(station);
197 station->m_tx_err++;
198 station->m_rateBlocked = false; // we can change the rate for next packet
199}
200
201void
203{
204 NS_LOG_FUNCTION(this << station);
205 station->m_tx_retr += station->m_shortRetry + station->m_longRetry;
206 station->m_shortRetry = 0;
207 station->m_longRetry = 0;
208}
209
210void
212{
213 NS_LOG_FUNCTION(this << station);
214 if (Simulator::Now() < station->m_nextModeUpdate || station->m_rateBlocked)
215 {
216 return;
217 }
219 /**
220 * The following 20 lines of code were copied from the Onoe
221 * rate control kernel module used in the madwifi driver.
222 */
223
224 int dir = 0;
225 uint8_t nrate;
226 bool enough = (station->m_tx_ok + station->m_tx_err >= 10);
227
228 /* no packet reached -> down */
229 if (station->m_tx_err > 0 && station->m_tx_ok == 0)
230 {
231 dir = -1;
232 }
233
234 /* all packets needs retry in average -> down */
235 if (enough && station->m_tx_ok < station->m_tx_retr)
236 {
237 dir = -1;
238 }
239
240 /* no error and less than rate_raise% of packets need retry -> up */
241 if (enough && station->m_tx_err == 0 &&
242 station->m_tx_retr < (station->m_tx_ok * m_addCreditThreshold) / 100)
243 {
244 dir = 1;
245 }
246
247 NS_LOG_DEBUG(this << " ok " << station->m_tx_ok << " err " << station->m_tx_err << " retr "
248 << station->m_tx_retr << " upper " << station->m_tx_upper << " dir " << dir);
249
250 nrate = station->m_txrate;
251 switch (dir)
252 {
253 case 0:
254 if (enough && station->m_tx_upper > 0)
255 {
256 station->m_tx_upper--;
257 }
258 break;
259 case -1:
260 if (nrate > 0)
261 {
262 nrate--;
263 }
264 station->m_tx_upper = 0;
265 break;
266 case 1:
267 /* raise rate if we hit rate_raise_threshold */
268 if (++station->m_tx_upper < m_raiseThreshold)
269 {
270 break;
271 }
272 station->m_tx_upper = 0;
273 if (nrate + 1 < GetNSupported(station))
274 {
275 nrate++;
276 }
277 break;
278 }
279
280 if (nrate != station->m_txrate)
281 {
282 NS_ASSERT(nrate < GetNSupported(station));
283 station->m_txrate = nrate;
284 station->m_tx_ok = station->m_tx_err = station->m_tx_retr = station->m_tx_upper = 0;
285 }
286 else if (enough)
287 {
288 station->m_tx_ok = station->m_tx_err = station->m_tx_retr = 0;
289 }
290}
291
294{
295 NS_LOG_FUNCTION(this << st << allowedWidth);
296 auto station = static_cast<OnoeWifiRemoteStation*>(st);
297 UpdateMode(station);
298 NS_ASSERT(station->m_txrate < GetNSupported(station));
299 uint8_t rateIndex;
300 if (station->m_longRetry < 4)
301 {
302 rateIndex = station->m_txrate;
303 }
304 else if (station->m_longRetry < 6)
305 {
306 if (station->m_txrate > 0)
307 {
308 rateIndex = station->m_txrate - 1;
309 }
310 else
311 {
312 rateIndex = station->m_txrate;
313 }
314 }
315 else if (station->m_longRetry < 8)
316 {
317 if (station->m_txrate > 1)
318 {
319 rateIndex = station->m_txrate - 2;
320 }
321 else
322 {
323 rateIndex = station->m_txrate;
324 }
325 }
326 else
327 {
328 if (station->m_txrate > 2)
329 {
330 rateIndex = station->m_txrate - 3;
331 }
332 else
333 {
334 rateIndex = station->m_txrate;
335 }
336 }
337 uint16_t channelWidth = GetChannelWidth(station);
338 if (channelWidth > 20 && channelWidth != 22)
339 {
340 channelWidth = 20;
341 }
342 WifiMode mode = GetSupported(station, rateIndex);
343 uint64_t rate = mode.GetDataRate(channelWidth);
344 if (m_currentRate != rate)
345 {
346 NS_LOG_DEBUG("New datarate: " << rate);
347 m_currentRate = rate;
348 }
349 return WifiTxVector(
350 mode,
353 800,
354 1,
355 1,
356 0,
357 channelWidth,
358 GetAggregation(station));
359}
360
363{
364 NS_LOG_FUNCTION(this << st);
365 auto station = static_cast<OnoeWifiRemoteStation*>(st);
366 uint16_t channelWidth = GetChannelWidth(station);
367 if (channelWidth > 20 && channelWidth != 22)
368 {
369 channelWidth = 20;
370 }
371 UpdateMode(station);
372 WifiMode mode;
374 {
375 mode = GetSupported(station, 0);
376 }
377 else
378 {
379 mode = GetNonErpSupported(station, 0);
380 }
381 return WifiTxVector(
382 mode,
385 800,
386 1,
387 1,
388 0,
389 channelWidth,
390 GetAggregation(station));
391}
392
393} // namespace ns3
an implementation of the rate control algorithm developed by Atsushi Onoe
WifiRemoteStation * DoCreateStation() const override
void DoInitialize() override
Initialize() implementation.
void UpdateRetry(OnoeWifiRemoteStation *station)
Update the number of retry (both short and long).
Time m_updatePeriod
update period
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, uint16_t allowedWidth) override
void DoReportRtsOk(WifiRemoteStation *station, double ctsSnr, WifiMode ctsMode, double rtsSnr) override
This method is a pure virtual method that must be implemented by the sub-class.
void DoReportDataOk(WifiRemoteStation *station, double ackSnr, WifiMode ackMode, double dataSnr, uint16_t dataChannelWidth, uint8_t dataNss) override
This method is a pure virtual method that must be implemented by the sub-class.
TracedValue< uint64_t > m_currentRate
Trace rate changes.
void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode) override
This method is a pure virtual method that must be implemented by the sub-class.
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station) override
void DoReportRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
void DoReportFinalRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
uint32_t m_addCreditThreshold
add credit threshold
uint32_t m_raiseThreshold
raise threshold
static TypeId GetTypeId()
Get the type ID.
void DoReportDataFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
void DoReportFinalDataFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
void UpdateMode(OnoeWifiRemoteStation *station)
Update the mode.
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
AttributeValue implementation for Time.
Definition: nstime.h:1413
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
Hold an unsigned integer type.
Definition: uinteger.h:45
represent a single transmission mode
Definition: wifi-mode.h:51
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:185
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:122
hold a list of per-remote-station state.
uint16_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
uint8_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
bool GetHtSupported() const
Return whether the device has HT capability support enabled.
WifiMode GetNonErpSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether non-ERP mode associated with the specified station at the specified index.
bool GetUseNonErpProtection() const
Return whether the device supports protection of non-ERP stations.
bool GetVhtSupported() const
Return whether the device has VHT capability support enabled.
bool GetShortPreambleEnabled() const
Return whether the device uses short PHY preambles.
WifiMode GetSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether mode associated with the specified station at the specified index.
bool GetHeSupported() const
Return whether the device has HE capability support enabled.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition: nstime.h:1434
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition: nstime.h:1414
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:46
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
WifiPreamble GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble)
Return the preamble to be used for the transmission.
hold per-remote-station state for ONOE Wifi manager.
uint32_t m_tx_retr
transmit retry
uint32_t m_shortRetry
short retry
uint8_t m_txrate
transmit rate
bool m_rateBlocked
whether the rate cannot be changed
Time m_nextModeUpdate
next mode update
uint32_t m_longRetry
long retry
uint32_t m_tx_ok
transmit OK
uint32_t m_tx_upper
transmit upper
uint32_t m_tx_err
transmit error
hold per-remote-station state.
std::string dir