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 "ns3/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 ()), 800, 1, 1, 0, channelWidth, GetAggregation (station));
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 ()), 800, 1, 1, 0, channelWidth, GetAggregation (station));
364  return rtsTxVector;
365 }
366 
367 } //namespace ns3
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
ns3::WifiRemoteStationManager::GetDefaultTxPowerLevel
uint8_t GetDefaultTxPowerLevel(void) const
Definition: wifi-remote-station-manager.cc:1206
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::OnoeWifiManager::DoReportFinalDataFailed
void DoReportFinalDataFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
Definition: onoe-wifi-manager.cc:182
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
NS_ASSERT
#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
ns3::MakeTimeChecker
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:533
ns3::WifiRemoteStationManager::GetUseNonErpProtection
bool GetUseNonErpProtection(void) const
Return whether the device supports protection of non-ERP stations.
Definition: wifi-remote-station-manager.cc:1051
ns3::OnoeWifiManager::m_addCreditThreshold
uint32_t m_addCreditThreshold
add credit threshold
Definition: onoe-wifi-manager.h:88
ns3::Simulator::Now
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::OnoeWifiManager::m_raiseThreshold
uint32_t m_raiseThreshold
raise threshold
Definition: onoe-wifi-manager.h:89
onoe-wifi-manager.h
ns3::WifiRemoteStationManager::GetSupported
WifiMode GetSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether mode associated with the specified station at the specified index.
Definition: wifi-remote-station-manager.cc:1635
ns3::WifiMode::GetModulationClass
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:159
ns3::OnoeWifiRemoteStation::m_tx_retr
uint32_t m_tx_retr
transmit retry
Definition: onoe-wifi-manager.cc:46
ns3::WifiRemoteStationManager
hold a list of per-remote-station state.
Definition: wifi-remote-station-manager.h:121
ns3::WifiRemoteStationManager::GetHtSupported
bool GetHtSupported(void) const
Return whether the device has HT capability support enabled.
Definition: wifi-remote-station-manager.cc:232
ns3::WifiRemoteStationManager::GetVhtSupported
bool GetVhtSupported(void) const
Return whether the device has VHT capability support enabled.
Definition: wifi-remote-station-manager.cc:244
ns3::OnoeWifiManager::DoReportFinalRtsFailed
void DoReportFinalRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
Definition: onoe-wifi-manager.cc:172
ns3::WifiRemoteStationManager::GetNSupported
uint8_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
Definition: wifi-remote-station-manager.cc:1743
ns3::WifiTxVector
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
Definition: wifi-tx-vector.h:71
dir
std::string dir
Definition: tcp-bbr-example.cc:66
ns3::OnoeWifiManager::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition: onoe-wifi-manager.cc:54
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
ns3::WifiRemoteStationManager::GetShortPreambleEnabled
bool GetShortPreambleEnabled(void) const
Return whether the device uses short PHY preambles.
Definition: wifi-remote-station-manager.cc:226
ns3::MakeTraceSourceAccessor
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Definition: trace-source-accessor.h:202
ns3::OnoeWifiManager::~OnoeWifiManager
virtual ~OnoeWifiManager()
Definition: onoe-wifi-manager.cc:88
ns3::OnoeWifiManager::DoReportDataOk
void DoReportDataOk(WifiRemoteStation *station, double ackSnr, WifiMode ackMode, double dataSnr, uint16_t dataChannelWidth, uint8_t dataNss) override
This method is a pure virtual method that must be implemented by the sub-class.
Definition: onoe-wifi-manager.cc:161
ns3::OnoeWifiRemoteStation::m_tx_ok
uint32_t m_tx_ok
transmit OK
Definition: onoe-wifi-manager.cc:44
NS_FATAL_ERROR
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
ns3::OnoeWifiRemoteStation::m_tx_err
uint32_t m_tx_err
transmit error
Definition: onoe-wifi-manager.cc:45
ns3::OnoeWifiManager::UpdateRetry
void UpdateRetry(OnoeWifiRemoteStation *station)
Update the number of retry (both short and long).
Definition: onoe-wifi-manager.cc:192
ns3::OnoeWifiRemoteStation::m_txrate
uint8_t m_txrate
transmit rate
Definition: onoe-wifi-manager.cc:48
ns3::WifiMode
represent a single transmission mode
Definition: wifi-mode.h:48
ns3::OnoeWifiRemoteStation::m_shortRetry
uint32_t m_shortRetry
short retry
Definition: onoe-wifi-manager.cc:42
ns3::OnoeWifiManager::UpdateMode
void UpdateMode(OnoeWifiRemoteStation *station)
Update the mode.
Definition: onoe-wifi-manager.cc:201
ns3::OnoeWifiManager::DoInitialize
void DoInitialize(void) override
Initialize() implementation.
Definition: onoe-wifi-manager.cc:94
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::OnoeWifiManager::OnoeWifiManager
OnoeWifiManager()
Definition: onoe-wifi-manager.cc:81
ns3::OnoeWifiManager::DoGetRtsTxVector
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station) override
Definition: onoe-wifi-manager.cc:343
ns3::OnoeWifiManager::DoCreateStation
WifiRemoteStation * DoCreateStation(void) const override
Definition: onoe-wifi-manager.cc:112
ns3::OnoeWifiRemoteStation::m_longRetry
uint32_t m_longRetry
long retry
Definition: onoe-wifi-manager.cc:43
ns3::OnoeWifiManager::m_currentRate
TracedValue< uint64_t > m_currentRate
Trace rate changes.
Definition: onoe-wifi-manager.h:91
ns3::OnoeWifiManager::DoReportRxOk
void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode) override
This method is a pure virtual method that must be implemented by the sub-class.
Definition: onoe-wifi-manager.cc:129
ns3::OnoeWifiRemoteStation::m_nextModeUpdate
Time m_nextModeUpdate
next mode update
Definition: onoe-wifi-manager.cc:40
ns3::GetPreambleForTransmission
WifiPreamble GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble)
Return the preamble to be used for the transmission.
Definition: wifi-phy-common.cc:87
ns3::WifiRemoteStation
hold per-remote-station state.
Definition: wifi-remote-station-manager.h:62
ns3::WifiRemoteStationManager::GetAggregation
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
Definition: wifi-remote-station-manager.cc:1707
ns3::OnoeWifiRemoteStation::m_tx_upper
uint32_t m_tx_upper
transmit upper
Definition: onoe-wifi-manager.cc:47
NS_LOG_DEBUG
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
ns3::OnoeWifiRemoteStation
hold per-remote-station state for ONOE Wifi manager.
Definition: onoe-wifi-manager.cc:39
ns3::OnoeWifiManager::DoGetDataTxVector
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station) override
Definition: onoe-wifi-manager.cc:284
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
ns3::WifiRemoteStationManager::GetNonErpSupported
WifiMode GetNonErpSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether non-ERP mode associated with the specified station at the specified index.
Definition: wifi-remote-station-manager.cc:1649
ns3::OnoeWifiRemoteStation::m_rateBlocked
bool m_rateBlocked
whether the rate cannot be changed
Definition: onoe-wifi-manager.cc:41
ns3::OnoeWifiManager::DoReportDataFailed
void DoReportDataFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
Definition: onoe-wifi-manager.cc:144
ns3::TimeValue
AttributeValue implementation for Time.
Definition: nstime.h:1353
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition: log-macros-enabled.h:244
ns3::UintegerValue
Hold an unsigned integer type.
Definition: uinteger.h:44
ns3::WifiRemoteStationManager::GetChannelWidth
uint16_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
Definition: wifi-remote-station-manager.cc:1683
ns3::WifiMode::GetDataRate
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:100
ns3::MakeUintegerAccessor
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
ns3::OnoeWifiManager::DoReportRtsOk
void DoReportRtsOk(WifiRemoteStation *station, double ctsSnr, WifiMode ctsMode, double rtsSnr) override
This method is a pure virtual method that must be implemented by the sub-class.
Definition: onoe-wifi-manager.cc:153
ns3::OnoeWifiManager
an implementation of the rate control algorithm developed by Atsushi Onoe
Definition: onoe-wifi-manager.h:47
ns3::OnoeWifiManager::DoReportRtsFailed
void DoReportRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
Definition: onoe-wifi-manager.cc:135
ns3::OnoeWifiManager::m_updatePeriod
Time m_updatePeriod
update period
Definition: onoe-wifi-manager.h:87
ns3::WifiRemoteStationManager::GetHeSupported
bool GetHeSupported(void) const
Return whether the device has HE capability support enabled.
Definition: wifi-remote-station-manager.cc:256
ns3::MakeTimeAccessor
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:1354