A Discrete-Event Network Simulator
API
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 
28 namespace ns3
29 {
30 
31 NS_LOG_COMPONENT_DEFINE("OnoeWifiManager");
32 
40 {
43  uint32_t m_shortRetry;
44  uint32_t m_longRetry;
45  uint32_t m_tx_ok;
46  uint32_t m_tx_err;
47  uint32_t m_tx_retr;
48  uint32_t m_tx_upper;
49  uint8_t m_txrate;
50 };
51 
53 
54 TypeId
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 
96 void
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);
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 
131 void
133 {
134  NS_LOG_FUNCTION(this << station << rxSnr << txMode);
135 }
136 
137 void
139 {
140  NS_LOG_FUNCTION(this << st);
141  OnoeWifiRemoteStation* station = static_cast<OnoeWifiRemoteStation*>(st);
142  station->m_shortRetry++;
143  station->m_rateBlocked = true; // do not change rate for retransmission
144 }
145 
146 void
148 {
149  NS_LOG_FUNCTION(this << st);
150  OnoeWifiRemoteStation* station = static_cast<OnoeWifiRemoteStation*>(st);
151  station->m_longRetry++;
152  station->m_rateBlocked = true; // do not change rate for retransmission
153 }
154 
155 void
157  double ctsSnr,
158  WifiMode ctsMode,
159  double rtsSnr)
160 {
161  NS_LOG_FUNCTION(this << st << ctsSnr << ctsMode << rtsSnr);
162  OnoeWifiRemoteStation* station = static_cast<OnoeWifiRemoteStation*>(st);
163  station->m_rateBlocked = true; // do not change rate
164 }
165 
166 void
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  OnoeWifiRemoteStation* 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 
181 void
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 
191 void
193 {
194  NS_LOG_FUNCTION(this << st);
195  OnoeWifiRemoteStation* 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 
201 void
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 
210 void
212 {
213  NS_LOG_FUNCTION(this << station);
214  if (Simulator::Now() < station->m_nextModeUpdate || station->m_rateBlocked)
215  {
216  return;
217  }
224  int dir = 0;
225  int enough;
226  uint8_t nrate;
227  enough = (station->m_tx_ok + station->m_tx_err >= 10);
228 
229  /* no packet reached -> down */
230  if (station->m_tx_err > 0 && station->m_tx_ok == 0)
231  {
232  dir = -1;
233  }
234 
235  /* all packets needs retry in average -> down */
236  if (enough && station->m_tx_ok < station->m_tx_retr)
237  {
238  dir = -1;
239  }
240 
241  /* no error and less than rate_raise% of packets need retry -> up */
242  if (enough && station->m_tx_err == 0 &&
243  station->m_tx_retr < (station->m_tx_ok * m_addCreditThreshold) / 100)
244  {
245  dir = 1;
246  }
247 
248  NS_LOG_DEBUG(this << " ok " << station->m_tx_ok << " err " << station->m_tx_err << " retr "
249  << station->m_tx_retr << " upper " << station->m_tx_upper << " dir " << dir);
250 
251  nrate = station->m_txrate;
252  switch (dir)
253  {
254  case 0:
255  if (enough && station->m_tx_upper > 0)
256  {
257  station->m_tx_upper--;
258  }
259  break;
260  case -1:
261  if (nrate > 0)
262  {
263  nrate--;
264  }
265  station->m_tx_upper = 0;
266  break;
267  case 1:
268  /* raise rate if we hit rate_raise_threshold */
269  if (++station->m_tx_upper < m_raiseThreshold)
270  {
271  break;
272  }
273  station->m_tx_upper = 0;
274  if (nrate + 1 < GetNSupported(station))
275  {
276  nrate++;
277  }
278  break;
279  }
280 
281  if (nrate != station->m_txrate)
282  {
283  NS_ASSERT(nrate < GetNSupported(station));
284  station->m_txrate = nrate;
285  station->m_tx_ok = station->m_tx_err = station->m_tx_retr = station->m_tx_upper = 0;
286  }
287  else if (enough)
288  {
289  station->m_tx_ok = station->m_tx_err = station->m_tx_retr = 0;
290  }
291 }
292 
295 {
296  NS_LOG_FUNCTION(this << st << allowedWidth);
297  OnoeWifiRemoteStation* station = static_cast<OnoeWifiRemoteStation*>(st);
298  UpdateMode(station);
299  NS_ASSERT(station->m_txrate < GetNSupported(station));
300  uint8_t rateIndex;
301  if (station->m_longRetry < 4)
302  {
303  rateIndex = station->m_txrate;
304  }
305  else if (station->m_longRetry < 6)
306  {
307  if (station->m_txrate > 0)
308  {
309  rateIndex = station->m_txrate - 1;
310  }
311  else
312  {
313  rateIndex = station->m_txrate;
314  }
315  }
316  else if (station->m_longRetry < 8)
317  {
318  if (station->m_txrate > 1)
319  {
320  rateIndex = station->m_txrate - 2;
321  }
322  else
323  {
324  rateIndex = station->m_txrate;
325  }
326  }
327  else
328  {
329  if (station->m_txrate > 2)
330  {
331  rateIndex = station->m_txrate - 3;
332  }
333  else
334  {
335  rateIndex = station->m_txrate;
336  }
337  }
338  uint16_t channelWidth = GetChannelWidth(station);
339  if (channelWidth > 20 && channelWidth != 22)
340  {
341  channelWidth = 20;
342  }
343  WifiMode mode = GetSupported(station, rateIndex);
344  uint64_t rate = mode.GetDataRate(channelWidth);
345  if (m_currentRate != rate)
346  {
347  NS_LOG_DEBUG("New datarate: " << rate);
348  m_currentRate = rate;
349  }
350  return WifiTxVector(
351  mode,
354  800,
355  1,
356  1,
357  0,
358  channelWidth,
359  GetAggregation(station));
360 }
361 
364 {
365  NS_LOG_FUNCTION(this << st);
366  OnoeWifiRemoteStation* station = static_cast<OnoeWifiRemoteStation*>(st);
367  uint16_t channelWidth = GetChannelWidth(station);
368  if (channelWidth > 20 && channelWidth != 22)
369  {
370  channelWidth = 20;
371  }
372  UpdateMode(station);
373  WifiMode mode;
374  if (GetUseNonErpProtection() == false)
375  {
376  mode = GetSupported(station, 0);
377  }
378  else
379  {
380  mode = GetNonErpSupported(station, 0);
381  }
382  return WifiTxVector(
383  mode,
386  800,
387  1,
388  1,
389  0,
390  channelWidth,
391  GetAggregation(station));
392 }
393 
394 } // 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:199
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
AttributeValue implementation for Time.
Definition: nstime.h:1423
a unique identifier for an interface.
Definition: type-id.h:60
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
Hold an unsigned integer type.
Definition: uinteger.h:45
represent a single transmission mode
Definition: wifi-mode.h:50
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 AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: nstime.h:1424
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
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:1336
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:535
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