A Discrete-Event Network Simulator
API
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 "ns3/log.h"
22#include "ns3/simulator.h"
23#include "onoe-wifi-manager.h"
24#include "ns3/wifi-tx-vector.h"
25
26#define Min(a,b) ((a < b) ? a : b)
27
28namespace ns3 {
29
30NS_LOG_COMPONENT_DEFINE ("OnoeWifiManager");
31
39{
48 uint8_t m_txrate;
49};
50
52
55{
56 static TypeId tid = TypeId ("ns3::OnoeWifiManager")
58 .SetGroupName ("Wifi")
59 .AddConstructor<OnoeWifiManager> ()
60 .AddAttribute ("UpdatePeriod",
61 "The interval between decisions about rate control changes",
62 TimeValue (Seconds (1.0)),
65 .AddAttribute ("RaiseThreshold", "Attempt to raise the rate if we hit that threshold",
66 UintegerValue (10),
68 MakeUintegerChecker<uint32_t> ())
69 .AddAttribute ("AddCreditThreshold", "Add credit threshold",
70 UintegerValue (10),
72 MakeUintegerChecker<uint32_t> ())
73 .AddTraceSource ("Rate",
74 "Traced value for rate changes (b/s)",
76 "ns3::TracedValueCallback::Uint64")
77 ;
78 return tid;
79}
80
83 m_currentRate (0)
84{
85 NS_LOG_FUNCTION (this);
86}
87
89{
90 NS_LOG_FUNCTION (this);
91}
92
93void
95{
96 NS_LOG_FUNCTION (this);
97 if (GetHtSupported ())
98 {
99 NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HT rates");
100 }
101 if (GetVhtSupported ())
102 {
103 NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support VHT rates");
104 }
105 if (GetHeSupported ())
106 {
107 NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HE rates");
108 }
109}
110
113{
114 NS_LOG_FUNCTION (this);
117 station->m_rateBlocked = false;
118 station->m_shortRetry = 0;
119 station->m_longRetry = 0;
120 station->m_tx_ok = 0;
121 station->m_tx_err = 0;
122 station->m_tx_retr = 0;
123 station->m_tx_upper = 0;
124 station->m_txrate = 0;
125 return station;
126}
127
128void
130{
131 NS_LOG_FUNCTION (this << station << rxSnr << txMode);
132}
133
134void
136{
137 NS_LOG_FUNCTION (this << st);
138 OnoeWifiRemoteStation *station = static_cast<OnoeWifiRemoteStation*> (st);
139 station->m_shortRetry++;
140 station->m_rateBlocked = true; // do not change rate for retransmission
141}
142
143void
145{
146 NS_LOG_FUNCTION (this << st);
147 OnoeWifiRemoteStation *station = static_cast<OnoeWifiRemoteStation*> (st);
148 station->m_longRetry++;
149 station->m_rateBlocked = true; // do not change rate for retransmission
150}
151
152void
153OnoeWifiManager::DoReportRtsOk (WifiRemoteStation *st, double ctsSnr, WifiMode ctsMode, double rtsSnr)
154{
155 NS_LOG_FUNCTION (this << st << ctsSnr << ctsMode << rtsSnr);
156 OnoeWifiRemoteStation *station = static_cast<OnoeWifiRemoteStation*> (st);
157 station->m_rateBlocked = true; // do not change rate
158}
159
160void
162 double dataSnr, uint16_t dataChannelWidth, uint8_t dataNss)
163{
164 NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr << dataChannelWidth << +dataNss);
165 OnoeWifiRemoteStation *station = static_cast<OnoeWifiRemoteStation*> (st);
166 UpdateRetry (station);
167 station->m_tx_ok++;
168 station->m_rateBlocked = false; // we can change the rate for next packet
169}
170
171void
173{
174 NS_LOG_FUNCTION (this << st);
175 OnoeWifiRemoteStation *station = static_cast<OnoeWifiRemoteStation*> (st);
176 UpdateRetry (station);
177 station->m_tx_err++;
178 station->m_rateBlocked = false; // we can change the rate for next packet
179}
180
181void
183{
184 NS_LOG_FUNCTION (this << st);
185 OnoeWifiRemoteStation *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 << station);
195 station->m_tx_retr += station->m_shortRetry + station->m_longRetry;
196 station->m_shortRetry = 0;
197 station->m_longRetry = 0;
198}
199
200void
202{
203 NS_LOG_FUNCTION (this << station);
204 if (Simulator::Now () < station->m_nextModeUpdate || station->m_rateBlocked)
205 {
206 return;
207 }
214 int dir = 0, enough;
215 uint8_t nrate;
216 enough = (station->m_tx_ok + station->m_tx_err >= 10);
217
218 /* no packet reached -> down */
219 if (station->m_tx_err > 0 && station->m_tx_ok == 0)
220 {
221 dir = -1;
222 }
223
224 /* all packets needs retry in average -> down */
225 if (enough && station->m_tx_ok < station->m_tx_retr)
226 {
227 dir = -1;
228 }
229
230 /* no error and less than rate_raise% of packets need retry -> up */
231 if (enough && station->m_tx_err == 0
232 && station->m_tx_retr < (station->m_tx_ok * m_addCreditThreshold) / 100)
233 {
234 dir = 1;
235 }
236
237 NS_LOG_DEBUG (this << " ok " << station->m_tx_ok << " err " << station->m_tx_err << " retr " << station->m_tx_retr <<
238 " upper " << station->m_tx_upper << " dir " << dir);
239
240 nrate = station->m_txrate;
241 switch (dir)
242 {
243 case 0:
244 if (enough && station->m_tx_upper > 0)
245 {
246 station->m_tx_upper--;
247 }
248 break;
249 case -1:
250 if (nrate > 0)
251 {
252 nrate--;
253 }
254 station->m_tx_upper = 0;
255 break;
256 case 1:
257 /* raise rate if we hit rate_raise_threshold */
258 if (++station->m_tx_upper < m_raiseThreshold)
259 {
260 break;
261 }
262 station->m_tx_upper = 0;
263 if (nrate + 1 < GetNSupported (station))
264 {
265 nrate++;
266 }
267 break;
268 }
269
270 if (nrate != station->m_txrate)
271 {
272 NS_ASSERT (nrate < GetNSupported (station));
273 station->m_txrate = nrate;
274 station->m_tx_ok = station->m_tx_err = station->m_tx_retr = station->m_tx_upper = 0;
275 }
276 else if (enough)
277 {
278 station->m_tx_ok = station->m_tx_err = station->m_tx_retr = 0;
279 }
280
281}
282
285{
286 NS_LOG_FUNCTION (this << st);
287 OnoeWifiRemoteStation *station = static_cast<OnoeWifiRemoteStation*> (st);
288 UpdateMode (station);
289 NS_ASSERT (station->m_txrate < GetNSupported (station));
290 uint8_t rateIndex;
291 if (station->m_longRetry < 4)
292 {
293 rateIndex = station->m_txrate;
294 }
295 else if (station->m_longRetry < 6)
296 {
297 if (station->m_txrate > 0)
298 {
299 rateIndex = station->m_txrate - 1;
300 }
301 else
302 {
303 rateIndex = station->m_txrate;
304 }
305 }
306 else if (station->m_longRetry < 8)
307 {
308 if (station->m_txrate > 1)
309 {
310 rateIndex = station->m_txrate - 2;
311 }
312 else
313 {
314 rateIndex = station->m_txrate;
315 }
316 }
317 else
318 {
319 if (station->m_txrate > 2)
320 {
321 rateIndex = station->m_txrate - 3;
322 }
323 else
324 {
325 rateIndex = station->m_txrate;
326 }
327 }
328 uint16_t channelWidth = GetChannelWidth (station);
329 if (channelWidth > 20 && channelWidth != 22)
330 {
331 channelWidth = 20;
332 }
333 WifiMode mode = GetSupported (station, rateIndex);
334 uint64_t rate = mode.GetDataRate (channelWidth);
335 if (m_currentRate != rate)
336 {
337 NS_LOG_DEBUG ("New datarate: " << rate);
338 m_currentRate = rate;
339 }
340 return WifiTxVector (mode, GetDefaultTxPowerLevel (), GetPreambleForTransmission (mode.GetModulationClass (), GetShortPreambleEnabled ()), 800, 1, 1, 0, channelWidth, GetAggregation (station));
341}
342
345{
346 NS_LOG_FUNCTION (this << st);
347 OnoeWifiRemoteStation *station = static_cast<OnoeWifiRemoteStation*> (st);
348 uint16_t channelWidth = GetChannelWidth (station);
349 if (channelWidth > 20 && channelWidth != 22)
350 {
351 channelWidth = 20;
352 }
353 UpdateMode (station);
354 WifiMode mode;
355 if (GetUseNonErpProtection () == false)
356 {
357 mode = GetSupported (station, 0);
358 }
359 else
360 {
361 mode = GetNonErpSupported (station, 0);
362 }
363 return WifiTxVector (mode, GetDefaultTxPowerLevel (), GetPreambleForTransmission (mode.GetModulationClass (), GetShortPreambleEnabled ()), 800, 1, 1, 0, channelWidth, GetAggregation (station));
364}
365
366} //namespace ns3
an implementation of the rate control algorithm developed by Atsushi Onoe
static TypeId GetTypeId(void)
Get the type ID.
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station) override
void UpdateRetry(OnoeWifiRemoteStation *station)
Update the number of retry (both short and long).
Time m_updatePeriod
update period
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.
void DoInitialize(void) override
Initialize() implementation.
uint32_t m_addCreditThreshold
add credit threshold
uint32_t m_raiseThreshold
raise threshold
void DoReportDataFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
WifiRemoteStation * DoCreateStation(void) const override
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(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
AttributeValue implementation for Time.
Definition: nstime.h:1308
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
Hold an unsigned integer type.
Definition: uinteger.h:44
represent a single transmission mode
Definition: wifi-mode.h:48
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:177
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:114
hold a list of per-remote-station state.
uint16_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
bool GetVhtSupported(void) const
Return whether the device has VHT capability support enabled.
uint8_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
bool GetUseNonErpProtection(void) const
Return whether the device supports protection of non-ERP stations.
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
WifiMode GetNonErpSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether non-ERP mode associated with the specified station at the specified index.
bool GetShortPreambleEnabled(void) const
Return whether the device uses short PHY preambles.
bool GetHeSupported(void) const
Return whether the device has HE capability support enabled.
WifiMode GetSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether mode associated with the specified station at the specified index.
bool GetHtSupported(void) const
Return whether the device has HT 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:67
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition: nstime.h:1309
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:45
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#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:45
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
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.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:536
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