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 {
42  uint32_t m_shortRetry;
43  uint32_t m_longRetry;
44  uint32_t m_tx_ok;
45  uint32_t m_tx_err;
46  uint32_t m_tx_retr;
47  uint32_t m_tx_upper;
48  uint8_t m_txrate;
49 };
50 
52 
53 TypeId
55 {
56  static TypeId tid = TypeId ("ns3::OnoeWifiManager")
58  .SetGroupName ("Wifi")
59  .AddConstructor<OnoeWifiManager> ()
60  .AddAttribute ("UpdatePeriod",
61  "The interval between decisions about rate control changes",
62  TimeValue (Seconds (1.0)),
64  MakeTimeChecker ())
65  .AddAttribute ("RaiseThreshold", "Attempt to raise the rate if we hit that threshold",
66  UintegerValue (10),
68  MakeUintegerChecker<uint32_t> ())
69  .AddAttribute ("AddCreditThreshold", "Add credit threshold",
70  UintegerValue (10),
72  MakeUintegerChecker<uint32_t> ())
73  .AddTraceSource ("Rate",
74  "Traced value for rate changes (b/s)",
76  "ns3::TracedValueCallback::Uint64")
77  ;
78  return tid;
79 }
80 
83  m_currentRate (0)
84 {
85  NS_LOG_FUNCTION (this);
86 }
87 
89 {
90  NS_LOG_FUNCTION (this);
91 }
92 
93 void
95 {
96  NS_LOG_FUNCTION (this);
97  if (GetHtSupported ())
98  {
99  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HT rates");
100  }
101  if (GetVhtSupported ())
102  {
103  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support VHT rates");
104  }
105  if (GetHeSupported ())
106  {
107  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HE rates");
108  }
109 }
110 
113 {
114  NS_LOG_FUNCTION (this);
117  station->m_rateBlocked = false;
118  station->m_shortRetry = 0;
119  station->m_longRetry = 0;
120  station->m_tx_ok = 0;
121  station->m_tx_err = 0;
122  station->m_tx_retr = 0;
123  station->m_tx_upper = 0;
124  station->m_txrate = 0;
125  return station;
126 }
127 
128 void
130 {
131  NS_LOG_FUNCTION (this << station << rxSnr << txMode);
132 }
133 
134 void
136 {
137  NS_LOG_FUNCTION (this << st);
138  OnoeWifiRemoteStation *station = static_cast<OnoeWifiRemoteStation*> (st);
139  station->m_shortRetry++;
140  station->m_rateBlocked = true; // do not change rate for retransmission
141 }
142 
143 void
145 {
146  NS_LOG_FUNCTION (this << st);
147  OnoeWifiRemoteStation *station = static_cast<OnoeWifiRemoteStation*> (st);
148  station->m_longRetry++;
149  station->m_rateBlocked = true; // do not change rate for retransmission
150 }
151 
152 void
153 OnoeWifiManager::DoReportRtsOk (WifiRemoteStation *st, double ctsSnr, WifiMode ctsMode, double rtsSnr)
154 {
155  NS_LOG_FUNCTION (this << st << ctsSnr << ctsMode << rtsSnr);
156  OnoeWifiRemoteStation *station = static_cast<OnoeWifiRemoteStation*> (st);
157  station->m_rateBlocked = true; // do not change rate
158 }
159 
160 void
162  double dataSnr, uint16_t dataChannelWidth, uint8_t dataNss)
163 {
164  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr << dataChannelWidth << +dataNss);
165  OnoeWifiRemoteStation *station = static_cast<OnoeWifiRemoteStation*> (st);
166  UpdateRetry (station);
167  station->m_tx_ok++;
168  station->m_rateBlocked = false; // we can change the rate for next packet
169 }
170 
171 void
173 {
174  NS_LOG_FUNCTION (this << st);
175  OnoeWifiRemoteStation *station = static_cast<OnoeWifiRemoteStation*> (st);
176  UpdateRetry (station);
177  station->m_tx_err++;
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 << station);
195  station->m_tx_retr += station->m_shortRetry + station->m_longRetry;
196  station->m_shortRetry = 0;
197  station->m_longRetry = 0;
198 }
199 
200 void
202 {
203  NS_LOG_FUNCTION (this << station);
204  if (Simulator::Now () < station->m_nextModeUpdate || station->m_rateBlocked)
205  {
206  return;
207  }
214  int dir = 0, enough;
215  uint8_t nrate;
216  enough = (station->m_tx_ok + station->m_tx_err >= 10);
217 
218  /* no packet reached -> down */
219  if (station->m_tx_err > 0 && station->m_tx_ok == 0)
220  {
221  dir = -1;
222  }
223 
224  /* all packets needs retry in average -> down */
225  if (enough && station->m_tx_ok < station->m_tx_retr)
226  {
227  dir = -1;
228  }
229 
230  /* no error and less than rate_raise% of packets need retry -> up */
231  if (enough && station->m_tx_err == 0
232  && station->m_tx_retr < (station->m_tx_ok * m_addCreditThreshold) / 100)
233  {
234  dir = 1;
235  }
236 
237  NS_LOG_DEBUG (this << " ok " << station->m_tx_ok << " err " << station->m_tx_err << " retr " << station->m_tx_retr <<
238  " upper " << station->m_tx_upper << " dir " << dir);
239 
240  nrate = station->m_txrate;
241  switch (dir)
242  {
243  case 0:
244  if (enough && station->m_tx_upper > 0)
245  {
246  station->m_tx_upper--;
247  }
248  break;
249  case -1:
250  if (nrate > 0)
251  {
252  nrate--;
253  }
254  station->m_tx_upper = 0;
255  break;
256  case 1:
257  /* raise rate if we hit rate_raise_threshold */
258  if (++station->m_tx_upper < m_raiseThreshold)
259  {
260  break;
261  }
262  station->m_tx_upper = 0;
263  if (nrate + 1 < GetNSupported (station))
264  {
265  nrate++;
266  }
267  break;
268  }
269 
270  if (nrate != station->m_txrate)
271  {
272  NS_ASSERT (nrate < GetNSupported (station));
273  station->m_txrate = nrate;
274  station->m_tx_ok = station->m_tx_err = station->m_tx_retr = station->m_tx_upper = 0;
275  }
276  else if (enough)
277  {
278  station->m_tx_ok = station->m_tx_err = station->m_tx_retr = 0;
279  }
280 
281 }
282 
285 {
286  NS_LOG_FUNCTION (this << st);
287  OnoeWifiRemoteStation *station = static_cast<OnoeWifiRemoteStation*> (st);
288  UpdateMode (station);
289  NS_ASSERT (station->m_txrate < GetNSupported (station));
290  uint8_t rateIndex;
291  if (station->m_longRetry < 4)
292  {
293  rateIndex = station->m_txrate;
294  }
295  else if (station->m_longRetry < 6)
296  {
297  if (station->m_txrate > 0)
298  {
299  rateIndex = station->m_txrate - 1;
300  }
301  else
302  {
303  rateIndex = station->m_txrate;
304  }
305  }
306  else if (station->m_longRetry < 8)
307  {
308  if (station->m_txrate > 1)
309  {
310  rateIndex = station->m_txrate - 2;
311  }
312  else
313  {
314  rateIndex = station->m_txrate;
315  }
316  }
317  else
318  {
319  if (station->m_txrate > 2)
320  {
321  rateIndex = station->m_txrate - 3;
322  }
323  else
324  {
325  rateIndex = station->m_txrate;
326  }
327  }
328  uint16_t channelWidth = GetChannelWidth (station);
329  if (channelWidth > 20 && channelWidth != 22)
330  {
331  channelWidth = 20;
332  }
333  WifiMode mode = GetSupported (station, rateIndex);
334  if (m_currentRate != mode.GetDataRate (channelWidth))
335  {
336  NS_LOG_DEBUG ("New datarate: " << mode.GetDataRate (channelWidth));
337  m_currentRate = mode.GetDataRate (channelWidth);
338  }
339  return WifiTxVector (mode, GetDefaultTxPowerLevel (), GetPreambleForTransmission (mode.GetModulationClass (), GetShortPreambleEnabled (), UseGreenfieldForDestination (GetAddress (st))), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
340 }
341 
344 {
345  NS_LOG_FUNCTION (this << st);
346  OnoeWifiRemoteStation *station = static_cast<OnoeWifiRemoteStation*> (st);
347  uint16_t channelWidth = GetChannelWidth (station);
348  if (channelWidth > 20 && channelWidth != 22)
349  {
350  channelWidth = 20;
351  }
352  UpdateMode (station);
353  WifiTxVector rtsTxVector;
354  WifiMode mode;
355  if (GetUseNonErpProtection () == false)
356  {
357  mode = GetSupported (station, 0);
358  }
359  else
360  {
361  mode = GetNonErpSupported (station, 0);
362  }
363  rtsTxVector = WifiTxVector (mode, GetDefaultTxPowerLevel (), GetPreambleForTransmission (mode.GetModulationClass (), GetShortPreambleEnabled (), UseGreenfieldForDestination (GetAddress (st))), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
364  return rtsTxVector;
365 }
366 
367 } //namespace ns3
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
bool GetVhtSupported(void) const
Return whether the device has VHT capability support enabled.
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.
void DoReportDataOk(WifiRemoteStation *station, double ackSnr, WifiMode ackMode, double dataSnr, uint16_t dataChannelWidth, uint8_t dataNss)
This method is a pure virtual method that must be implemented by the sub-class.
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.
bool GetHeSupported(void) const
Return whether the device has HE capability support enabled.
#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
void DoInitialize(void)
Initialize() implementation.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
uint32_t m_tx_retr
transmit retry
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station)
WifiPreamble GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble, bool useGreenfield)
Return the preamble to be used for the transmission.
Definition: wifi-utils.cc:128
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.
bool GetShortPreambleEnabled(void) const
Return whether the device uses short PHY preambles.
uint32_t m_longRetry
long retry
AttributeValue implementation for Time.
Definition: nstime.h:1124
Hold an unsigned integer type.
Definition: uinteger.h:44
bool GetHtSupported(void) const
Return whether the device has HT capability support enabled.
uint32_t m_tx_upper
transmit upper
std::string dir
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.
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:463
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.
bool UseGreenfieldForDestination(Mac48Address dest) const
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...
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:1125
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
Time m_nextModeUpdate
next mode update
bool m_rateBlocked
whether the rate cannot be changed
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:273
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1062
Time m_updatePeriod
update period
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:449
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
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
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:119
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.