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 
92 void
94 {
95  NS_LOG_FUNCTION (this);
96  if (GetHtSupported ())
97  {
98  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HT rates");
99  }
100  if (GetVhtSupported ())
101  {
102  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support VHT rates");
103  }
104  if (GetHeSupported ())
105  {
106  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HE rates");
107  }
108 }
109 
112 {
113  NS_LOG_FUNCTION (this);
116  station->m_shortRetry = 0;
117  station->m_longRetry = 0;
118  station->m_tx_ok = 0;
119  station->m_tx_err = 0;
120  station->m_tx_retr = 0;
121  station->m_tx_upper = 0;
122  station->m_txrate = 0;
123  return station;
124 }
125 
126 void
128 {
129  NS_LOG_FUNCTION (this << station << rxSnr << txMode);
130 }
131 
132 void
134 {
135  NS_LOG_FUNCTION (this << st);
137  station->m_shortRetry++;
138 }
139 
140 void
142 {
143  NS_LOG_FUNCTION (this << st);
145  station->m_longRetry++;
146 }
147 
148 void
149 OnoeWifiManager::DoReportRtsOk (WifiRemoteStation *station, double ctsSnr, WifiMode ctsMode, double rtsSnr)
150 {
151  NS_LOG_FUNCTION (this << station << ctsSnr << ctsMode << rtsSnr);
152 }
153 
154 void
155 OnoeWifiManager::DoReportDataOk (WifiRemoteStation *st, double ackSnr, WifiMode ackMode, double dataSnr)
156 {
157  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
159  UpdateRetry (station);
160  station->m_tx_ok++;
161 }
162 
163 void
165 {
166  NS_LOG_FUNCTION (this << st);
168  UpdateRetry (station);
169  station->m_tx_err++;
170 }
171 
172 void
174 {
175  NS_LOG_FUNCTION (this << st);
177  UpdateRetry (station);
178  station->m_tx_err++;
179 }
180 
181 void
183 {
184  NS_LOG_FUNCTION (this << station);
185  station->m_tx_retr += station->m_shortRetry + station->m_longRetry;
186  station->m_shortRetry = 0;
187  station->m_longRetry = 0;
188 }
189 
190 void
192 {
193  NS_LOG_FUNCTION (this << station);
194  if (Simulator::Now () < station->m_nextModeUpdate)
195  {
196  return;
197  }
204  int dir = 0, enough;
205  uint8_t nrate;
206  enough = (station->m_tx_ok + station->m_tx_err >= 10);
207 
208  /* no packet reached -> down */
209  if (station->m_tx_err > 0 && station->m_tx_ok == 0)
210  {
211  dir = -1;
212  }
213 
214  /* all packets needs retry in average -> down */
215  if (enough && station->m_tx_ok < station->m_tx_retr)
216  {
217  dir = -1;
218  }
219 
220  /* no error and less than rate_raise% of packets need retry -> up */
221  if (enough && station->m_tx_err == 0
222  && station->m_tx_retr < (station->m_tx_ok * m_addCreditThreshold) / 100)
223  {
224  dir = 1;
225  }
226 
227  NS_LOG_DEBUG (this << " ok " << station->m_tx_ok << " err " << station->m_tx_err << " retr " << station->m_tx_retr <<
228  " upper " << station->m_tx_upper << " dir " << dir);
229 
230  nrate = station->m_txrate;
231  switch (dir)
232  {
233  case 0:
234  if (enough && station->m_tx_upper > 0)
235  {
236  station->m_tx_upper--;
237  }
238  break;
239  case -1:
240  if (nrate > 0)
241  {
242  nrate--;
243  }
244  station->m_tx_upper = 0;
245  break;
246  case 1:
247  /* raise rate if we hit rate_raise_threshold */
248  if (++station->m_tx_upper < m_raiseThreshold)
249  {
250  break;
251  }
252  station->m_tx_upper = 0;
253  if (nrate + 1 < GetNSupported (station))
254  {
255  nrate++;
256  }
257  break;
258  }
259 
260  if (nrate != station->m_txrate)
261  {
262  NS_ASSERT (nrate < GetNSupported (station));
263  station->m_txrate = nrate;
264  station->m_tx_ok = station->m_tx_err = station->m_tx_retr = station->m_tx_upper = 0;
265  }
266  else if (enough)
267  {
268  station->m_tx_ok = station->m_tx_err = station->m_tx_retr = 0;
269  }
270 
271 }
272 
275 {
276  NS_LOG_FUNCTION (this << st);
278  UpdateMode (station);
279  NS_ASSERT (station->m_txrate < GetNSupported (station));
280  uint8_t rateIndex;
281  if (station->m_longRetry < 4)
282  {
283  rateIndex = station->m_txrate;
284  }
285  else if (station->m_longRetry < 6)
286  {
287  if (station->m_txrate > 0)
288  {
289  rateIndex = station->m_txrate - 1;
290  }
291  else
292  {
293  rateIndex = station->m_txrate;
294  }
295  }
296  else if (station->m_longRetry < 8)
297  {
298  if (station->m_txrate > 1)
299  {
300  rateIndex = station->m_txrate - 2;
301  }
302  else
303  {
304  rateIndex = station->m_txrate;
305  }
306  }
307  else
308  {
309  if (station->m_txrate > 2)
310  {
311  rateIndex = station->m_txrate - 3;
312  }
313  else
314  {
315  rateIndex = station->m_txrate;
316  }
317  }
318  uint16_t channelWidth = GetChannelWidth (station);
319  if (channelWidth > 20 && channelWidth != 22)
320  {
321  channelWidth = 20;
322  }
323  WifiMode mode = GetSupported (station, rateIndex);
324  if (m_currentRate != mode.GetDataRate (channelWidth))
325  {
326  NS_LOG_DEBUG ("New datarate: " << mode.GetDataRate (channelWidth));
327  m_currentRate = mode.GetDataRate (channelWidth);
328  }
329  return WifiTxVector (mode, GetDefaultTxPowerLevel (), GetPreambleForTransmission (mode.GetModulationClass (), GetShortPreambleEnabled (), UseGreenfieldForDestination (GetAddress (st))), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
330 }
331 
334 {
335  NS_LOG_FUNCTION (this << st);
337  uint16_t channelWidth = GetChannelWidth (station);
338  if (channelWidth > 20 && channelWidth != 22)
339  {
340  channelWidth = 20;
341  }
342  UpdateMode (station);
343  WifiTxVector rtsTxVector;
344  WifiMode mode;
345  if (GetUseNonErpProtection () == false)
346  {
347  mode = GetSupported (station, 0);
348  }
349  else
350  {
351  mode = GetNonErpSupported (station, 0);
352  }
353  rtsTxVector = WifiTxVector (mode, GetDefaultTxPowerLevel (), GetPreambleForTransmission (mode.GetModulationClass (), GetShortPreambleEnabled (), UseGreenfieldForDestination (GetAddress (st))), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
354  return rtsTxVector;
355 }
356 
357 bool
359 {
360  return false;
361 }
362 
363 } //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.
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:204
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)
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. ...
std::string dir
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
bool GetShortPreambleEnabled(void) const
Return whether the device uses short PLCP 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
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:494
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:193
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:272
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1062
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:150
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.