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 "wifi-tx-vector.h"
25 
26 #define Min(a,b) ((a < b) ? a : b)
27 
28 namespace ns3 {
29 
30 NS_LOG_COMPONENT_DEFINE ("OnoeWifiManager");
31 
39 {
41  uint32_t m_shortRetry;
42  uint32_t m_longRetry;
43  uint32_t m_tx_ok;
44  uint32_t m_tx_err;
45  uint32_t m_tx_retr;
46  uint32_t m_tx_upper;
47  uint8_t m_txrate;
48 };
49 
51 
52 TypeId
54 {
55  static TypeId tid = TypeId ("ns3::OnoeWifiManager")
57  .SetGroupName ("Wifi")
58  .AddConstructor<OnoeWifiManager> ()
59  .AddAttribute ("UpdatePeriod",
60  "The interval between decisions about rate control changes",
61  TimeValue (Seconds (1.0)),
63  MakeTimeChecker ())
64  .AddAttribute ("RaiseThreshold", "Attempt to raise the rate if we hit that threshold",
65  UintegerValue (10),
67  MakeUintegerChecker<uint32_t> ())
68  .AddAttribute ("AddCreditThreshold", "Add credit threshold",
69  UintegerValue (10),
71  MakeUintegerChecker<uint32_t> ())
72  .AddTraceSource ("Rate",
73  "Traced value for rate changes (b/s)",
75  "ns3::TracedValueCallback::Uint64")
76  ;
77  return tid;
78 }
79 
82  m_currentRate (0)
83 {
84  NS_LOG_FUNCTION (this);
85 }
86 
88 {
89  NS_LOG_FUNCTION (this);
90 }
91 
94 {
95  NS_LOG_FUNCTION (this);
98  station->m_shortRetry = 0;
99  station->m_longRetry = 0;
100  station->m_tx_ok = 0;
101  station->m_tx_err = 0;
102  station->m_tx_retr = 0;
103  station->m_tx_upper = 0;
104  station->m_txrate = 0;
105  return station;
106 }
107 
108 void
110 {
111  NS_LOG_FUNCTION (this << station << rxSnr << txMode);
112 }
113 
114 void
116 {
117  NS_LOG_FUNCTION (this << st);
119  station->m_shortRetry++;
120 }
121 
122 void
124 {
125  NS_LOG_FUNCTION (this << st);
127  station->m_longRetry++;
128 }
129 
130 void
131 OnoeWifiManager::DoReportRtsOk (WifiRemoteStation *station, double ctsSnr, WifiMode ctsMode, double rtsSnr)
132 {
133  NS_LOG_FUNCTION (this << station << ctsSnr << ctsMode << rtsSnr);
134 }
135 
136 void
137 OnoeWifiManager::DoReportDataOk (WifiRemoteStation *st, double ackSnr, WifiMode ackMode, double dataSnr)
138 {
139  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
141  UpdateRetry (station);
142  station->m_tx_ok++;
143 }
144 
145 void
147 {
148  NS_LOG_FUNCTION (this << st);
150  UpdateRetry (station);
151  station->m_tx_err++;
152 }
153 
154 void
156 {
157  NS_LOG_FUNCTION (this << st);
159  UpdateRetry (station);
160  station->m_tx_err++;
161 }
162 
163 void
165 {
166  NS_LOG_FUNCTION (this << station);
167  station->m_tx_retr += station->m_shortRetry + station->m_longRetry;
168  station->m_shortRetry = 0;
169  station->m_longRetry = 0;
170 }
171 
172 void
174 {
175  NS_LOG_FUNCTION (this << station);
176  if (Simulator::Now () < station->m_nextModeUpdate)
177  {
178  return;
179  }
186  int dir = 0, enough;
187  uint8_t nrate;
188  enough = (station->m_tx_ok + station->m_tx_err >= 10);
189 
190  /* no packet reached -> down */
191  if (station->m_tx_err > 0 && station->m_tx_ok == 0)
192  {
193  dir = -1;
194  }
195 
196  /* all packets needs retry in average -> down */
197  if (enough && station->m_tx_ok < station->m_tx_retr)
198  {
199  dir = -1;
200  }
201 
202  /* no error and less than rate_raise% of packets need retry -> up */
203  if (enough && station->m_tx_err == 0
204  && station->m_tx_retr < (station->m_tx_ok * m_addCreditThreshold) / 100)
205  {
206  dir = 1;
207  }
208 
209  NS_LOG_DEBUG (this << " ok " << station->m_tx_ok << " err " << station->m_tx_err << " retr " << station->m_tx_retr <<
210  " upper " << station->m_tx_upper << " dir " << dir);
211 
212  nrate = station->m_txrate;
213  switch (dir)
214  {
215  case 0:
216  if (enough && station->m_tx_upper > 0)
217  {
218  station->m_tx_upper--;
219  }
220  break;
221  case -1:
222  if (nrate > 0)
223  {
224  nrate--;
225  }
226  station->m_tx_upper = 0;
227  break;
228  case 1:
229  /* raise rate if we hit rate_raise_threshold */
230  if (++station->m_tx_upper < m_raiseThreshold)
231  {
232  break;
233  }
234  station->m_tx_upper = 0;
235  if (nrate + 1 < GetNSupported (station))
236  {
237  nrate++;
238  }
239  break;
240  }
241 
242  if (nrate != station->m_txrate)
243  {
244  NS_ASSERT (nrate < GetNSupported (station));
245  station->m_txrate = nrate;
246  station->m_tx_ok = station->m_tx_err = station->m_tx_retr = station->m_tx_upper = 0;
247  }
248  else if (enough)
249  {
250  station->m_tx_ok = station->m_tx_err = station->m_tx_retr = 0;
251  }
252 
253 }
254 
257 {
258  NS_LOG_FUNCTION (this << st);
260  UpdateMode (station);
261  NS_ASSERT (station->m_txrate < GetNSupported (station));
262  uint8_t rateIndex;
263  if (station->m_longRetry < 4)
264  {
265  rateIndex = station->m_txrate;
266  }
267  else if (station->m_longRetry < 6)
268  {
269  if (station->m_txrate > 0)
270  {
271  rateIndex = station->m_txrate - 1;
272  }
273  else
274  {
275  rateIndex = station->m_txrate;
276  }
277  }
278  else if (station->m_longRetry < 8)
279  {
280  if (station->m_txrate > 1)
281  {
282  rateIndex = station->m_txrate - 2;
283  }
284  else
285  {
286  rateIndex = station->m_txrate;
287  }
288  }
289  else
290  {
291  if (station->m_txrate > 2)
292  {
293  rateIndex = station->m_txrate - 3;
294  }
295  else
296  {
297  rateIndex = station->m_txrate;
298  }
299  }
300  uint16_t channelWidth = GetChannelWidth (station);
301  if (channelWidth > 20 && channelWidth != 22)
302  {
303  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
304  channelWidth = 20;
305  }
306  WifiMode mode = GetSupported (station, rateIndex);
307  if (m_currentRate != mode.GetDataRate (channelWidth))
308  {
309  NS_LOG_DEBUG ("New datarate: " << mode.GetDataRate (channelWidth));
310  m_currentRate = mode.GetDataRate (channelWidth);
311  }
312  return WifiTxVector (mode, GetDefaultTxPowerLevel (), GetPreambleForTransmission (mode, GetAddress (st)), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
313 }
314 
317 {
318  NS_LOG_FUNCTION (this << st);
320  uint16_t channelWidth = GetChannelWidth (station);
321  if (channelWidth > 20 && channelWidth != 22)
322  {
323  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
324  channelWidth = 20;
325  }
326  UpdateMode (station);
327  WifiTxVector rtsTxVector;
328  WifiMode mode;
329  if (GetUseNonErpProtection () == false)
330  {
331  mode = GetSupported (station, 0);
332  }
333  else
334  {
335  mode = GetNonErpSupported (station, 0);
336  }
337  rtsTxVector = WifiTxVector (mode, GetDefaultTxPowerLevel (), GetPreambleForTransmission (mode, GetAddress (st)), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
338  return rtsTxVector;
339 }
340 
341 bool
343 {
344  return false;
345 }
346 
347 void
349 {
350  //HT is not supported by this algorithm.
351  if (enable)
352  {
353  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HT rates");
354  }
355 }
356 
357 void
359 {
360  //VHT is not supported by this algorithm.
361  if (enable)
362  {
363  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support VHT rates");
364  }
365 }
366 
367 void
369 {
370  //HE is not supported by this algorithm.
371  if (enable)
372  {
373  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HE rates");
374  }
375 }
376 
377 } //namespace ns3
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
void SetHtSupported(bool enable)
Enable or disable HT capability support.
an implementation of the rate control algorithm developed by Atsushi Onoe
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
uint8_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
uint32_t m_tx_ok
transmit ok
uint32_t m_tx_err
transmit error
void DoReportRtsOk(WifiRemoteStation *station, double ctsSnr, WifiMode ctsMode, double rtsSnr)
This method is a pure virtual method that must be implemented by the sub-class.
void UpdateMode(OnoeWifiRemoteStation *station)
Update the mode.
#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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
void SetVhtSupported(bool enable)
Enable or disable VHT capability support.
uint32_t m_tx_retr
transmit retr
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station)
WifiMode GetSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether mode associated with the specified station at the specified index. ...
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:97
uint32_t m_shortRetry
short retry
static TypeId GetTypeId(void)
Get the type ID.
void UpdateRetry(OnoeWifiRemoteStation *station)
Update the number of retry (both short and long).
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:446
uint32_t m_longRetry
long retry
AttributeValue implementation for Time.
Definition: nstime.h:1076
Hold an unsigned integer type.
Definition: uinteger.h:44
WifiPreamble GetPreambleForTransmission(WifiMode mode, Mac48Address dest)
Return the preamble to be used for the transmission.
uint32_t m_tx_upper
transmit upper
void DoReportFinalRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
hold a list of per-remote-station state.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode)
This method is a pure virtual method that must be implemented by the sub-class.
void DoReportFinalDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
Mac48Address GetAddress(const WifiRemoteStation *station) const
Return the address of the station.
WifiMode GetNonErpSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether non-ERP mode associated with the specified station at the specified index...
void SetHeSupported(bool enable)
Enable or disable HE capability support.
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:1077
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:249
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
Time m_nextModeUpdate
next mode update
void DoReportRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
hold per-remote-station state for ONOE Wifi manager.
bool GetUseNonErpProtection(void) const
Return whether the device supports protection of non-ERP stations.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:270
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1014
Time m_updatePeriod
update period
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)
bool IsLowLatency(void) const
uint32_t m_raiseThreshold
raise threshold
WifiRemoteStation * DoCreateStation(void) const
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:45
a unique identifier for an interface.
Definition: type-id.h:58
void DoReportDataOk(WifiRemoteStation *station, double ackSnr, WifiMode ackMode, double dataSnr)
This method is a pure virtual method that must be implemented by the sub-class.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
uint8_t m_txrate
transmit rate
hold per-remote-station state.
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:156
TracedValue< uint64_t > m_currentRate
Trace rate changes.
uint16_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
uint32_t m_addCreditThreshold
add credit threshold
void DoReportDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.