A Discrete-Event Network Simulator
API
aarf-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) 2004,2005,2006 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 "aarf-wifi-manager.h"
23 #include "wifi-tx-vector.h"
24 
25 #define Min(a,b) ((a < b) ? a : b)
26 #define Max(a,b) ((a > b) ? a : b)
27 
28 namespace ns3 {
29 
30 NS_LOG_COMPONENT_DEFINE ("AarfWifiManager");
31 
39 {
40  uint32_t m_timer;
41  uint32_t m_success;
42  uint32_t m_failed;
43  bool m_recovery;
44  uint32_t m_retry;
45  uint32_t m_timerTimeout;
46  uint32_t m_successThreshold;
47  uint8_t m_rate;
48 };
49 
51 
52 TypeId
54 {
55  static TypeId tid = TypeId ("ns3::AarfWifiManager")
57  .SetGroupName ("Wifi")
58  .AddConstructor<AarfWifiManager> ()
59  .AddAttribute ("SuccessK", "Multiplication factor for the success threshold in the AARF algorithm.",
60  DoubleValue (2.0),
62  MakeDoubleChecker<double> ())
63  .AddAttribute ("TimerK",
64  "Multiplication factor for the timer threshold in the AARF algorithm.",
65  DoubleValue (2.0),
67  MakeDoubleChecker<double> ())
68  .AddAttribute ("MaxSuccessThreshold",
69  "Maximum value of the success threshold in the AARF algorithm.",
70  UintegerValue (60),
72  MakeUintegerChecker<uint32_t> ())
73  .AddAttribute ("MinTimerThreshold",
74  "The minimum value for the 'timer' threshold in the AARF algorithm.",
75  UintegerValue (15),
77  MakeUintegerChecker<uint32_t> ())
78  .AddAttribute ("MinSuccessThreshold",
79  "The minimum value for the success threshold in the AARF algorithm.",
80  UintegerValue (10),
82  MakeUintegerChecker<uint32_t> ())
83  .AddTraceSource ("Rate",
84  "Traced value for rate changes (b/s)",
86  "ns3::TracedValueCallback::Uint64")
87  ;
88  return tid;
89 }
90 
93  m_currentRate (0)
94 {
95  NS_LOG_FUNCTION (this);
96 }
97 
99 {
100  NS_LOG_FUNCTION (this);
101 }
102 
103 void
105 {
106  NS_LOG_FUNCTION (this);
107  if (GetHtSupported ())
108  {
109  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HT rates");
110  }
111  if (GetVhtSupported ())
112  {
113  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support VHT rates");
114  }
115  if (GetHeSupported ())
116  {
117  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HE rates");
118  }
119 }
120 
123 {
124  NS_LOG_FUNCTION (this);
126 
129  station->m_rate = 0;
130  station->m_success = 0;
131  station->m_failed = 0;
132  station->m_recovery = false;
133  station->m_retry = 0;
134  station->m_timer = 0;
135 
136  return station;
137 }
138 
139 void
141 {
142  NS_LOG_FUNCTION (this << station);
143 }
155 void
157 {
158  NS_LOG_FUNCTION (this << st);
160  station->m_timer++;
161  station->m_failed++;
162  station->m_retry++;
163  station->m_success = 0;
164 
165  if (station->m_recovery)
166  {
167  NS_ASSERT (station->m_retry >= 1);
168  if (station->m_retry == 1)
169  {
170  //need recovery fallback
171  station->m_successThreshold = (int)(Min (station->m_successThreshold * m_successK,
173  station->m_timerTimeout = (int)(Max (station->m_timerTimeout * m_timerK,
175  if (station->m_rate != 0)
176  {
177  station->m_rate--;
178  }
179  }
180  station->m_timer = 0;
181  }
182  else
183  {
184  NS_ASSERT (station->m_retry >= 1);
185  if (((station->m_retry - 1) % 2) == 1)
186  {
187  //need normal fallback
190  if (station->m_rate != 0)
191  {
192  station->m_rate--;
193  }
194  }
195  if (station->m_retry >= 2)
196  {
197  station->m_timer = 0;
198  }
199  }
200 }
201 
202 void
204  double rxSnr, WifiMode txMode)
205 {
206  NS_LOG_FUNCTION (this << station << rxSnr << txMode);
207 }
208 
209 void
211  double ctsSnr, WifiMode ctsMode, double rtsSnr)
212 {
213  NS_LOG_FUNCTION (this << station << ctsSnr << ctsMode << rtsSnr);
214  NS_LOG_DEBUG ("station=" << station << " rts ok");
215 }
216 
217 void
219  double ackSnr, WifiMode ackMode, double dataSnr)
220 {
221  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
223  station->m_timer++;
224  station->m_success++;
225  station->m_failed = 0;
226  station->m_recovery = false;
227  station->m_retry = 0;
228  NS_LOG_DEBUG ("station=" << station << " data ok success=" << station->m_success << ", timer=" << station->m_timer);
229  if ((station->m_success == station->m_successThreshold
230  || station->m_timer == station->m_timerTimeout)
231  && (station->m_rate < (GetNSupported (station) - 1)))
232  {
233  NS_LOG_DEBUG ("station=" << station << " inc rate");
234  station->m_rate++;
235  station->m_timer = 0;
236  station->m_success = 0;
237  station->m_recovery = true;
238  }
239 }
240 
241 void
243 {
244  NS_LOG_FUNCTION (this << station);
245 }
246 
247 void
249 {
250  NS_LOG_FUNCTION (this << station);
251 }
252 
255 {
256  NS_LOG_FUNCTION (this << st);
258  uint16_t channelWidth = GetChannelWidth (station);
259  if (channelWidth > 20 && channelWidth != 22)
260  {
261  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
262  channelWidth = 20;
263  }
264  WifiMode mode = GetSupported (station, station->m_rate);
265  if (m_currentRate != mode.GetDataRate (channelWidth))
266  {
267  NS_LOG_DEBUG ("New datarate: " << mode.GetDataRate (channelWidth));
268  m_currentRate = mode.GetDataRate (channelWidth);
269  }
270  return WifiTxVector (mode, GetDefaultTxPowerLevel (), GetPreambleForTransmission (mode.GetModulationClass (), GetShortPreambleEnabled (), UseGreenfieldForDestination (GetAddress (station))), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
271 }
272 
275 {
276  NS_LOG_FUNCTION (this << st);
280  uint16_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  WifiTxVector rtsTxVector;
287  WifiMode mode;
288  if (GetUseNonErpProtection () == false)
289  {
290  mode = GetSupported (station, 0);
291  }
292  else
293  {
294  mode = GetNonErpSupported (station, 0);
295  }
296  rtsTxVector = WifiTxVector (mode, GetDefaultTxPowerLevel (), GetPreambleForTransmission (mode.GetModulationClass (), GetShortPreambleEnabled (), UseGreenfieldForDestination (GetAddress (station))), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
297  return rtsTxVector;
298 }
299 
300 bool
302 {
303  return true;
304 }
305 
306 } //namespace ns3
uint32_t m_minSuccessThreshold
minimum success threshold
bool GetVhtSupported(void) const
Return whether the device has VHT capability support enabled.
#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
double m_successK
Multiplication factor for the success threshold.
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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:204
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
bool IsLowLatency(void) const
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
void DoReportDataFailed(WifiRemoteStation *station)
It is important to realize that "recovery" mode starts after failure of the first transmission after ...
void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode)
This method is a pure virtual method that must be implemented by the sub-class.
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
void DoInitialize(void)
Initialize() implementation.
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.
bool GetShortPreambleEnabled(void) const
Return whether the device uses short PLCP preambles.
void DoReportFinalDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
int64x64_t Min(const int64x64_t &a, const int64x64_t &b)
Minimum.
Definition: int64x64.h:197
WifiRemoteStation * DoCreateStation(void) const
void DoReportRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
Hold an unsigned integer type.
Definition: uinteger.h:44
bool GetHtSupported(void) const
Return whether the device has HT capability support enabled.
int64x64_t Max(const int64x64_t &a, const int64x64_t &b)
Maximum.
Definition: int64x64.h:209
uint32_t m_minTimerThreshold
minimum timer threshold
hold a list of per-remote-station state.
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:494
AARF Rate control algorithmThis class implements the AARF rate control algorithm which was initially ...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool UseGreenfieldForDestination(Mac48Address dest) const
double m_timerK
Multiplication factor for the timer threshold.
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...
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
uint32_t m_successThreshold
success threshold
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: double.h:42
hold per-remote-station state for AARF Wifi manager.
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.
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
TracedValue< uint64_t > m_currentRate
Trace rate changes.
void DoReportFinalRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
uint32_t m_timerTimeout
timer timeout
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
Definition: double.h:41
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
uint32_t m_maxSuccessThreshold
maximum success threshold
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
hold per-remote-station state.
static TypeId GetTypeId(void)
Get the type ID.
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:150
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station)
uint16_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.