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 "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 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  uint32_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 }
85 
87 {
88 }
89 
92 {
95  station->m_shortRetry = 0;
96  station->m_longRetry = 0;
97  station->m_tx_ok = 0;
98  station->m_tx_err = 0;
99  station->m_tx_retr = 0;
100  station->m_tx_upper = 0;
101  station->m_txrate = 0;
102  return station;
103 }
104 
105 void
107  double rxSnr, WifiMode txMode)
108 {
109 }
110 
111 void
113 {
115  station->m_shortRetry++;
116 }
117 
118 void
120 {
122  station->m_longRetry++;
123 }
124 
125 void
127  double ctsSnr, WifiMode ctsMode, double rtsSnr)
128 {
129 }
130 
131 void
133  double ackSnr, WifiMode ackMode, double dataSnr)
134 {
136  UpdateRetry (station);
137  station->m_tx_ok++;
138 }
139 
140 void
142 {
144  UpdateRetry (station);
145  station->m_tx_err++;
146 }
147 
148 void
150 {
152  UpdateRetry (station);
153  station->m_tx_err++;
154 }
155 
156 void
158 {
159  station->m_tx_retr += station->m_shortRetry + station->m_longRetry;
160  station->m_shortRetry = 0;
161  station->m_longRetry = 0;
162 }
163 
164 void
166 {
167  if (Simulator::Now () < station->m_nextModeUpdate)
168  {
169  return;
170  }
177  int dir = 0, enough;
178  uint32_t nrate;
179  enough = (station->m_tx_ok + station->m_tx_err >= 10);
180 
181  /* no packet reached -> down */
182  if (station->m_tx_err > 0 && station->m_tx_ok == 0)
183  {
184  dir = -1;
185  }
186 
187  /* all packets needs retry in average -> down */
188  if (enough && station->m_tx_ok < station->m_tx_retr)
189  {
190  dir = -1;
191  }
192 
193  /* no error and less than rate_raise% of packets need retry -> up */
194  if (enough && station->m_tx_err == 0
195  && station->m_tx_retr < (station->m_tx_ok * m_addCreditThreshold) / 100)
196  {
197  dir = 1;
198  }
199 
200  NS_LOG_DEBUG (this << " ok " << station->m_tx_ok << " err " << station->m_tx_err << " retr " << station->m_tx_retr <<
201  " upper " << station->m_tx_upper << " dir " << dir);
202 
203  nrate = station->m_txrate;
204  switch (dir)
205  {
206  case 0:
207  if (enough && station->m_tx_upper > 0)
208  {
209  station->m_tx_upper--;
210  }
211  break;
212  case -1:
213  if (nrate > 0)
214  {
215  nrate--;
216  }
217  station->m_tx_upper = 0;
218  break;
219  case 1:
220  /* raise rate if we hit rate_raise_threshold */
221  if (++station->m_tx_upper < m_raiseThreshold)
222  {
223  break;
224  }
225  station->m_tx_upper = 0;
226  if (nrate + 1 < GetNSupported (station))
227  {
228  nrate++;
229  }
230  break;
231  }
232 
233  if (nrate != station->m_txrate)
234  {
235  NS_ASSERT (nrate < GetNSupported (station));
236  station->m_txrate = nrate;
237  station->m_tx_ok = station->m_tx_err = station->m_tx_retr = station->m_tx_upper = 0;
238  }
239  else if (enough)
240  {
241  station->m_tx_ok = station->m_tx_err = station->m_tx_retr = 0;
242  }
243 
244 }
245 
248 {
250  UpdateMode (station);
251  NS_ASSERT (station->m_txrate < GetNSupported (station));
252  uint32_t rateIndex;
253  if (station->m_longRetry < 4)
254  {
255  rateIndex = station->m_txrate;
256  }
257  else if (station->m_longRetry < 6)
258  {
259  if (station->m_txrate > 0)
260  {
261  rateIndex = station->m_txrate - 1;
262  }
263  else
264  {
265  rateIndex = station->m_txrate;
266  }
267  }
268  else if (station->m_longRetry < 8)
269  {
270  if (station->m_txrate > 1)
271  {
272  rateIndex = station->m_txrate - 2;
273  }
274  else
275  {
276  rateIndex = station->m_txrate;
277  }
278  }
279  else
280  {
281  if (station->m_txrate > 2)
282  {
283  rateIndex = station->m_txrate - 3;
284  }
285  else
286  {
287  rateIndex = station->m_txrate;
288  }
289  }
290  uint32_t channelWidth = GetChannelWidth (station);
291  if (channelWidth > 20 && channelWidth != 22)
292  {
293  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
294  channelWidth = 20;
295  }
296  WifiMode mode = GetSupported (station, rateIndex);
297  if (m_currentRate != mode.GetDataRate (channelWidth))
298  {
299  NS_LOG_DEBUG ("New datarate: " << mode.GetDataRate (channelWidth));
300  m_currentRate = mode.GetDataRate (channelWidth);
301  }
302  return WifiTxVector (mode, GetDefaultTxPowerLevel (), GetLongRetryCount (station), GetPreambleForTransmission (mode, GetAddress (st)), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
303 }
304 
307 {
309  uint32_t channelWidth = GetChannelWidth (station);
310  if (channelWidth > 20 && channelWidth != 22)
311  {
312  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
313  channelWidth = 20;
314  }
315  UpdateMode (station);
316  WifiTxVector rtsTxVector;
317  WifiMode mode;
318  if (GetUseNonErpProtection () == false)
319  {
320  mode = GetSupported (station, 0);
321  }
322  else
323  {
324  mode = GetNonErpSupported (station, 0);
325  }
326  rtsTxVector = WifiTxVector (mode, GetDefaultTxPowerLevel (), GetShortRetryCount (station), GetPreambleForTransmission (mode, GetAddress (st)), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
327  return rtsTxVector;
328 }
329 
330 bool
332 {
333  return false;
334 }
335 
336 void
338 {
339  //HT is not supported by this algorithm.
340  if (enable)
341  {
342  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HT rates");
343  }
344 }
345 
346 void
348 {
349  //VHT is not supported by this algorithm.
350  if (enable)
351  {
352  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support VHT rates");
353  }
354 }
355 
356 void
358 {
359  //HE is not supported by this algorithm.
360  if (enable)
361  {
362  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HE rates");
363  }
364 }
365 
366 } //namespace ns3
uint32_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
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
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
bool GetUseNonErpProtection(void) const
Return whether the device supports protection of non-ERP stations.
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:201
void SetVhtSupported(bool enable)
Enable or disable VHT capability support.
bool IsLowLatency(void) const
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)
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.
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
WifiMode GetSupported(const WifiRemoteStation *station, uint32_t i) const
Return whether mode associated with the specified station at the specified index. ...
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:1055
Hold an unsigned integer type.
Definition: uinteger.h:44
WifiMode GetNonErpSupported(const WifiRemoteStation *station, uint32_t i) const
Return whether non-ERP mode associated with the specified station at the specified index...
WifiPreamble GetPreambleForTransmission(WifiMode mode, Mac48Address dest)
Return the preamble to be used for the transmission.
uint64_t GetDataRate(uint8_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:143
uint8_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
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.
Mac48Address GetAddress(const WifiRemoteStation *station) const
Return the address of the station.
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.
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:1056
uint32_t m_txrate
transmit rate
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:249
Time m_nextModeUpdate
next mode update
WifiRemoteStation * DoCreateStation(void) const
uint32_t GetLongRetryCount(const WifiRemoteStation *station) const
Return the long retry limit of the given station.
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.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:269
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:993
Time m_updatePeriod
update period
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)
uint32_t GetShortRetryCount(const WifiRemoteStation *station) const
Return the short retry limit of the given station.
uint32_t m_raiseThreshold
raise threshold
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:914
hold per-remote-station state.
TracedValue< uint64_t > m_currentRate
Trace rate changes.
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.