A Discrete-Event Network Simulator
QKDNetSim v2.0 (NS-3 v3.41) @ (+)
API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
aarf-wifi-manager.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2004,2005,2006 INRIA
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18  */
19 
20 #include "aarf-wifi-manager.h"
21 
22 #include "ns3/log.h"
23 #include "ns3/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 
31 NS_LOG_COMPONENT_DEFINE("AarfWifiManager");
32 
40 {
41  uint32_t m_timer;
42  uint32_t m_success;
43  uint32_t m_failed;
44  bool m_recovery;
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 =
56  TypeId("ns3::AarfWifiManager")
58  .SetGroupName("Wifi")
59  .AddConstructor<AarfWifiManager>()
60  .AddAttribute("SuccessK",
61  "Multiplication factor for the success threshold in the AARF algorithm.",
62  DoubleValue(2.0),
64  MakeDoubleChecker<double>())
65  .AddAttribute("TimerK",
66  "Multiplication factor for the timer threshold in the AARF algorithm.",
67  DoubleValue(2.0),
69  MakeDoubleChecker<double>())
70  .AddAttribute("MaxSuccessThreshold",
71  "Maximum value of the success threshold in the AARF algorithm.",
72  UintegerValue(60),
74  MakeUintegerChecker<uint32_t>())
75  .AddAttribute("MinTimerThreshold",
76  "The minimum value for the 'timer' threshold in the AARF algorithm.",
77  UintegerValue(15),
79  MakeUintegerChecker<uint32_t>())
80  .AddAttribute("MinSuccessThreshold",
81  "The minimum value for the success threshold in the AARF algorithm.",
82  UintegerValue(10),
84  MakeUintegerChecker<uint32_t>())
85  .AddTraceSource("Rate",
86  "Traced value for rate changes (b/s)",
88  "ns3::TracedValueCallback::Uint64");
89  return tid;
90 }
91 
94  m_currentRate(0)
95 {
96  NS_LOG_FUNCTION(this);
97 }
98 
100 {
101  NS_LOG_FUNCTION(this);
102 }
103 
104 void
106 {
107  NS_LOG_FUNCTION(this);
108  if (GetHtSupported())
109  {
110  NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HT rates");
111  }
112  if (GetVhtSupported())
113  {
114  NS_FATAL_ERROR("WifiRemoteStationManager selected does not support VHT rates");
115  }
116  if (GetHeSupported())
117  {
118  NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HE rates");
119  }
120 }
121 
124 {
125  NS_LOG_FUNCTION(this);
126  auto station = new AarfWifiRemoteStation();
127 
128  station->m_successThreshold = m_minSuccessThreshold;
129  station->m_timerTimeout = m_minTimerThreshold;
130  station->m_rate = 0;
131  station->m_success = 0;
132  station->m_failed = 0;
133  station->m_recovery = false;
134  station->m_timer = 0;
135 
136  return station;
137 }
138 
139 void
141 {
142  NS_LOG_FUNCTION(this << station);
143 }
144 
156 void
158 {
159  NS_LOG_FUNCTION(this << st);
160  auto station = static_cast<AarfWifiRemoteStation*>(st);
161  station->m_timer++;
162  station->m_failed++;
163  station->m_success = 0;
164 
165  if (station->m_recovery)
166  {
167  NS_ASSERT(station->m_failed >= 1);
168  if (station->m_failed == 1)
169  {
170  // need recovery fallback
171  station->m_successThreshold =
172  (int)(Min(station->m_successThreshold * m_successK, m_maxSuccessThreshold));
173  station->m_timerTimeout =
174  (int)(Max(station->m_timerTimeout * m_timerK, m_minSuccessThreshold));
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_failed >= 1);
185  if (((station->m_failed - 1) % 2) == 1)
186  {
187  // need normal fallback
188  station->m_timerTimeout = m_minTimerThreshold;
189  station->m_successThreshold = m_minSuccessThreshold;
190  if (station->m_rate != 0)
191  {
192  station->m_rate--;
193  }
194  }
195  if (station->m_failed >= 2)
196  {
197  station->m_timer = 0;
198  }
199  }
200 }
201 
202 void
204 {
205  NS_LOG_FUNCTION(this << station << rxSnr << txMode);
206 }
207 
208 void
210  double ctsSnr,
211  WifiMode ctsMode,
212  double rtsSnr)
213 {
214  NS_LOG_FUNCTION(this << station << ctsSnr << ctsMode << rtsSnr);
215  NS_LOG_DEBUG("station=" << station << " rts ok");
216 }
217 
218 void
220  double ackSnr,
221  WifiMode ackMode,
222  double dataSnr,
223  uint16_t dataChannelWidth,
224  uint8_t dataNss)
225 {
226  NS_LOG_FUNCTION(this << st << ackSnr << ackMode << dataSnr << dataChannelWidth << +dataNss);
227  auto station = static_cast<AarfWifiRemoteStation*>(st);
228  station->m_timer++;
229  station->m_success++;
230  station->m_failed = 0;
231  station->m_recovery = false;
232  NS_LOG_DEBUG("station=" << station << " data ok success=" << station->m_success
233  << ", timer=" << station->m_timer);
234  if ((station->m_success == station->m_successThreshold ||
235  station->m_timer == station->m_timerTimeout) &&
236  (station->m_rate < (GetNSupported(station) - 1)))
237  {
238  NS_LOG_DEBUG("station=" << station << " inc rate");
239  station->m_rate++;
240  station->m_timer = 0;
241  station->m_success = 0;
242  station->m_recovery = true;
243  }
244 }
245 
246 void
248 {
249  NS_LOG_FUNCTION(this << station);
250 }
251 
252 void
254 {
255  NS_LOG_FUNCTION(this << station);
256 }
257 
260 {
261  NS_LOG_FUNCTION(this << st << allowedWidth);
262  auto station = static_cast<AarfWifiRemoteStation*>(st);
263  uint16_t channelWidth = GetChannelWidth(station);
264  if (channelWidth > 20 && channelWidth != 22)
265  {
266  channelWidth = 20;
267  }
268  WifiMode mode = GetSupported(station, station->m_rate);
269  uint64_t rate = mode.GetDataRate(channelWidth);
270  if (m_currentRate != rate)
271  {
272  NS_LOG_DEBUG("New datarate: " << rate);
273  m_currentRate = rate;
274  }
275  return WifiTxVector(
276  mode,
279  800,
280  1,
281  1,
282  0,
283  channelWidth,
284  GetAggregation(station));
285 }
286 
289 {
290  NS_LOG_FUNCTION(this << st);
293  auto station = static_cast<AarfWifiRemoteStation*>(st);
294  uint16_t channelWidth = GetChannelWidth(station);
295  if (channelWidth > 20 && channelWidth != 22)
296  {
297  channelWidth = 20;
298  }
299  WifiMode mode;
300  if (!GetUseNonErpProtection())
301  {
302  mode = GetSupported(station, 0);
303  }
304  else
305  {
306  mode = GetNonErpSupported(station, 0);
307  }
308  return WifiTxVector(
309  mode,
312  800,
313  1,
314  1,
315  0,
316  channelWidth,
317  GetAggregation(station));
318 }
319 
320 } // namespace ns3
AARF Rate control algorithm.
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.
uint32_t m_minSuccessThreshold
minimum success threshold
WifiRemoteStation * DoCreateStation() const override
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station) override
void DoReportFinalDataFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
void DoInitialize() override
Initialize() implementation.
void DoReportFinalRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
double m_successK
Multiplication factor for the success threshold.
void DoReportDataFailed(WifiRemoteStation *station) override
It is important to realize that "recovery" mode starts after failure of the first transmission after ...
double m_timerK
Multiplication factor for the timer threshold.
void DoReportRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
static TypeId GetTypeId()
Get the type ID.
uint32_t m_maxSuccessThreshold
maximum success threshold
void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode) override
This method is a pure virtual method that must be implemented by the sub-class.
uint32_t m_minTimerThreshold
minimum timer threshold
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, uint16_t allowedWidth) override
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.
TracedValue< uint64_t > m_currentRate
Trace rate changes.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
Hold an unsigned integer type.
Definition: uinteger.h:45
represent a single transmission mode
Definition: wifi-mode.h:51
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:185
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:122
hold a list of per-remote-station state.
uint16_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
uint8_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
bool GetHtSupported() const
Return whether the device has HT capability support enabled.
WifiMode GetNonErpSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether non-ERP mode associated with the specified station at the specified index.
bool GetUseNonErpProtection() const
Return whether the device supports protection of non-ERP stations.
bool GetVhtSupported() const
Return whether the device has VHT capability support enabled.
bool GetShortPreambleEnabled() const
Return whether the device uses short PHY preambles.
WifiMode GetSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether mode associated with the specified station at the specified index.
bool GetHeSupported() const
Return whether the device has HE capability support enabled.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
int64x64_t Max(const int64x64_t &a, const int64x64_t &b)
Maximum.
Definition: int64x64.h:243
int64x64_t Min(const int64x64_t &a, const int64x64_t &b)
Minimum.
Definition: int64x64.h:229
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition: double.h:43
WifiPreamble GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble)
Return the preamble to be used for the transmission.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:46
hold per-remote-station state for AARF Wifi manager.
uint32_t m_timerTimeout
timer timeout
uint32_t m_successThreshold
success threshold
hold per-remote-station state.