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 ("OnoeWifiRemoteStation");
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  ;
73  return tid;
74 }
75 
77 {
78 }
79 
82 {
85  station->m_shortRetry = 0;
86  station->m_longRetry = 0;
87  station->m_tx_ok = 0;
88  station->m_tx_err = 0;
89  station->m_tx_retr = 0;
90  station->m_tx_upper = 0;
91  station->m_txrate = 0;
92  return station;
93 }
94 
95 void
97  double rxSnr, WifiMode txMode)
98 {
99 }
100 
101 void
103 {
105  station->m_shortRetry++;
106 }
107 
108 void
110 {
112  station->m_longRetry++;
113 }
114 
115 void
117  double ctsSnr, WifiMode ctsMode, double rtsSnr)
118 {
119 }
120 
121 void
123  double ackSnr, WifiMode ackMode, double dataSnr)
124 {
126  UpdateRetry (station);
127  station->m_tx_ok++;
128 }
129 
130 void
132 {
134  UpdateRetry (station);
135  station->m_tx_err++;
136 }
137 
138 void
140 {
142  UpdateRetry (station);
143  station->m_tx_err++;
144 }
145 
146 void
148 {
149  station->m_tx_retr += station->m_shortRetry + station->m_longRetry;
150  station->m_shortRetry = 0;
151  station->m_longRetry = 0;
152 }
153 
154 void
156 {
157  if (Simulator::Now () < station->m_nextModeUpdate)
158  {
159  return;
160  }
167  int dir = 0, enough;
168  uint32_t nrate;
169  enough = (station->m_tx_ok + station->m_tx_err >= 10);
170 
171  /* no packet reached -> down */
172  if (station->m_tx_err > 0 && station->m_tx_ok == 0)
173  {
174  dir = -1;
175  }
176 
177  /* all packets needs retry in average -> down */
178  if (enough && station->m_tx_ok < station->m_tx_retr)
179  {
180  dir = -1;
181  }
182 
183  /* no error and less than rate_raise% of packets need retry -> up */
184  if (enough && station->m_tx_err == 0
185  && station->m_tx_retr < (station->m_tx_ok * m_addCreditThreshold) / 100)
186  {
187  dir = 1;
188  }
189 
190  NS_LOG_DEBUG (this << " ok " << station->m_tx_ok << " err " << station->m_tx_err << " retr " << station->m_tx_retr <<
191  " upper " << station->m_tx_upper << " dir " << dir);
192 
193  nrate = station->m_txrate;
194  switch (dir)
195  {
196  case 0:
197  if (enough && station->m_tx_upper > 0)
198  {
199  station->m_tx_upper--;
200  }
201  break;
202  case -1:
203  if (nrate > 0)
204  {
205  nrate--;
206  }
207  station->m_tx_upper = 0;
208  break;
209  case 1:
210  /* raise rate if we hit rate_raise_threshold */
211  if (++station->m_tx_upper < m_raiseThreshold)
212  {
213  break;
214  }
215  station->m_tx_upper = 0;
216  if (nrate + 1 < GetNSupported (station))
217  {
218  nrate++;
219  }
220  break;
221  }
222 
223  if (nrate != station->m_txrate)
224  {
225  NS_ASSERT (nrate < GetNSupported (station));
226  station->m_txrate = nrate;
227  station->m_tx_ok = station->m_tx_err = station->m_tx_retr = station->m_tx_upper = 0;
228  }
229  else if (enough)
230  {
231  station->m_tx_ok = station->m_tx_err = station->m_tx_retr = 0;
232  }
233 
234 }
235 
238 {
240  UpdateMode (station);
241  NS_ASSERT (station->m_txrate < GetNSupported (station));
242  uint32_t rateIndex;
243  if (station->m_longRetry < 4)
244  {
245  rateIndex = station->m_txrate;
246  }
247  else if (station->m_longRetry < 6)
248  {
249  if (station->m_txrate > 0)
250  {
251  rateIndex = station->m_txrate - 1;
252  }
253  else
254  {
255  rateIndex = station->m_txrate;
256  }
257  }
258  else if (station->m_longRetry < 8)
259  {
260  if (station->m_txrate > 1)
261  {
262  rateIndex = station->m_txrate - 2;
263  }
264  else
265  {
266  rateIndex = station->m_txrate;
267  }
268  }
269  else
270  {
271  if (station->m_txrate > 2)
272  {
273  rateIndex = station->m_txrate - 3;
274  }
275  else
276  {
277  rateIndex = station->m_txrate;
278  }
279  }
280  uint32_t channelWidth = GetChannelWidth (station);
281  if (channelWidth > 20 && channelWidth != 22)
282  {
283  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
284  channelWidth = 20;
285  }
286  return WifiTxVector (GetSupported (station, rateIndex), GetDefaultTxPowerLevel (), GetLongRetryCount (station), false, 1, 0, channelWidth, GetAggregation (station), false);
287 }
288 
291 {
293  uint32_t channelWidth = GetChannelWidth (station);
294  if (channelWidth > 20 && channelWidth != 22)
295  {
296  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
297  channelWidth = 20;
298  }
299  UpdateMode (station);
300  WifiTxVector rtsTxVector;
301  if (GetUseNonErpProtection () == false)
302  {
303  rtsTxVector = WifiTxVector (GetSupported (station, 0), GetDefaultTxPowerLevel (), GetShortRetryCount (station), false, 1, 0, channelWidth, GetAggregation (station), false);
304  }
305  else
306  {
307  rtsTxVector = WifiTxVector (GetNonErpSupported (station, 0), GetDefaultTxPowerLevel (), GetShortRetryCount (station), false, 1, 0, channelWidth, GetAggregation (station), false);
308  }
309  return rtsTxVector;
310 }
311 
312 bool
314 {
315  return false;
316 }
317 
318 void
320 {
321  //HT is not supported by this algorithm.
322  if (enable)
323  {
324  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HT rates");
325  }
326 }
327 
328 void
330 {
331  //VHT is not supported by this algorithm.
332  if (enable)
333  {
334  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support VHT rates");
335  }
336 }
337 
338 } //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
virtual 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:44
bool GetUseNonErpProtection(void) const
Return whether the device supports protection of non-ERP stations.
virtual 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)
#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
virtual void SetVhtSupported(bool enable)
Enable or disable VHT capability support.
virtual bool IsLowLatency(void) const
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
virtual 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:99
static TypeId GetTypeId(void)
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 AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:446
AttributeValue implementation for Time.
Definition: nstime.h:957
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...
virtual 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.
virtual void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode)
This method is a pure virtual method that must be implemented by the sub-class.
virtual void DoReportFinalDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
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:958
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:224
virtual WifiRemoteStation * DoCreateStation(void) const
uint32_t GetLongRetryCount(const WifiRemoteStation *station) const
Return the long retry limit of the given station.
virtual 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:236
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
virtual WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)
uint32_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
uint32_t GetShortRetryCount(const WifiRemoteStation *station) const
Return the short retry limit of the given station.
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
virtual 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:904
hold per-remote-station state.
virtual void DoReportDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.