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  uint32_t size)
239 {
241  UpdateMode (station);
242  NS_ASSERT (station->m_txrate < GetNSupported (station));
243  uint32_t rateIndex;
244  if (station->m_longRetry < 4)
245  {
246  rateIndex = station->m_txrate;
247  }
248  else if (station->m_longRetry < 6)
249  {
250  if (station->m_txrate > 0)
251  {
252  rateIndex = station->m_txrate - 1;
253  }
254  else
255  {
256  rateIndex = station->m_txrate;
257  }
258  }
259  else if (station->m_longRetry < 8)
260  {
261  if (station->m_txrate > 1)
262  {
263  rateIndex = station->m_txrate - 2;
264  }
265  else
266  {
267  rateIndex = station->m_txrate;
268  }
269  }
270  else
271  {
272  if (station->m_txrate > 2)
273  {
274  rateIndex = station->m_txrate - 3;
275  }
276  else
277  {
278  rateIndex = station->m_txrate;
279  }
280  }
281  uint32_t channelWidth = GetChannelWidth (station);
282  if (channelWidth > 20 && channelWidth != 22)
283  {
284  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
285  channelWidth = 20;
286  }
287  return WifiTxVector (GetSupported (station, rateIndex), GetDefaultTxPowerLevel (), GetLongRetryCount (station), false, 1, 0, channelWidth, GetAggregation (station), false);
288 }
289 
292 {
294  uint32_t channelWidth = GetChannelWidth (station);
295  if (channelWidth > 20 && channelWidth != 22)
296  {
297  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
298  channelWidth = 20;
299  }
300  UpdateMode (station);
302  return WifiTxVector (GetSupported (station, 0), GetDefaultTxPowerLevel (), GetShortRetryCount (station), false, 1, 0, channelWidth, GetAggregation (station), false);
303 }
304 
305 bool
307 {
308  return false;
309 }
310 
311 } //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
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
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 bool IsLowLatency(void) const
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:97
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
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:223
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.
virtual WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, uint32_t size)
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:826
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.