A Discrete-Event Network Simulator
API
aparf-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) 2014 Universidad de la República - Uruguay
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: Matias Richart <mrichart@fing.edu.uy>
19  */
20 
21 #include "ns3/log.h"
22 #include "ns3/uinteger.h"
23 #include "ns3/data-rate.h"
24 #include "aparf-wifi-manager.h"
25 #include "wifi-phy.h"
26 
27 #define Min(a,b) ((a < b) ? a : b)
28 
29 namespace ns3 {
30 
31 NS_LOG_COMPONENT_DEFINE ("AparfWifiManager");
32 
39 struct
41 {
42  uint32_t m_nSuccess;
43  uint32_t m_nFailed;
44  uint32_t m_pCount;
45  uint32_t m_successThreshold;
46  uint32_t m_failThreshold;
47  uint8_t m_prevRateIndex;
48  uint8_t m_rateIndex;
49  uint8_t m_critRateIndex;
50  uint8_t m_prevPowerLevel;
51  uint8_t m_powerLevel;
52  uint8_t m_nSupported;
55 };
56 
58 
59 TypeId
61 {
62  static TypeId tid = TypeId ("ns3::AparfWifiManager")
64  .SetGroupName ("Wifi")
65  .AddConstructor<AparfWifiManager> ()
66  .AddAttribute ("SuccessThreshold1",
67  "The minimum number of successful transmissions in \"High\" state to try a new power or rate.",
68  UintegerValue (3),
70  MakeUintegerChecker<uint32_t> ())
71  .AddAttribute ("SuccessThreshold2",
72  "The minimum number of successful transmissions in \"Low\" state to try a new power or rate.",
73  UintegerValue (10),
75  MakeUintegerChecker<uint32_t> ())
76  .AddAttribute ("FailThreshold",
77  "The minimum number of failed transmissions to try a new power or rate.",
78  UintegerValue (1),
80  MakeUintegerChecker<uint32_t> ())
81  .AddAttribute ("PowerThreshold",
82  "The maximum number of power changes.",
83  UintegerValue (10),
85  MakeUintegerChecker<uint32_t> ())
86  .AddAttribute ("PowerDecrementStep",
87  "Step size for decrement the power.",
88  UintegerValue (1),
90  MakeUintegerChecker<uint8_t> ())
91  .AddAttribute ("PowerIncrementStep",
92  "Step size for increment the power.",
93  UintegerValue (1),
95  MakeUintegerChecker<uint8_t> ())
96  .AddAttribute ("RateDecrementStep",
97  "Step size for decrement the rate.",
98  UintegerValue (1),
100  MakeUintegerChecker<uint8_t> ())
101  .AddAttribute ("RateIncrementStep",
102  "Step size for increment the rate.",
103  UintegerValue (1),
105  MakeUintegerChecker<uint8_t> ())
106  .AddTraceSource ("PowerChange",
107  "The transmission power has change",
109  "ns3::WifiRemoteStationManager::PowerChangeTracedCallback")
110  .AddTraceSource ("RateChange",
111  "The transmission rate has change",
113  "ns3::WifiRemoteStationManager::RateChangeTracedCallback")
114  ;
115  return tid;
116 }
117 
119 {
120  NS_LOG_FUNCTION (this);
121 }
122 
124 {
125  NS_LOG_FUNCTION (this);
126 }
127 
128 void
130 {
131  NS_LOG_FUNCTION (this << phy);
132  m_minPower = 0;
133  m_maxPower = phy->GetNTxPower () - 1;
135 }
136 
139 {
140  NS_LOG_FUNCTION (this);
142 
143  station->m_successThreshold = m_succesMax1;
144  station->m_failThreshold = m_failMax;
145  station->m_nSuccess = 0;
146  station->m_nFailed = 0;
147  station->m_pCount = 0;
149  station->m_initialized = false;
150 
151  NS_LOG_DEBUG ("create station=" << station << ", rate=" << +station->m_rateIndex
152  << ", power=" << +station->m_powerLevel);
153 
154  return station;
155 }
156 
157 void
159 {
160  if (!station->m_initialized)
161  {
162  station->m_nSupported = GetNSupported (station);
163  station->m_rateIndex = station->m_nSupported - 1;
164  station->m_prevRateIndex = station->m_nSupported - 1;
165  station->m_powerLevel = m_maxPower;
166  station->m_prevPowerLevel = m_maxPower;
167  station->m_critRateIndex = 0;
168  WifiMode mode = GetSupported (station, station->m_rateIndex);
169  uint16_t channelWidth = GetChannelWidth (station);
170  DataRate rate = DataRate (mode.GetDataRate (channelWidth));
171  double power = GetPhy ()->GetPowerDbm (m_maxPower);
172  m_powerChange (power, power, station->m_state->m_address);
173  m_rateChange (rate, rate, station->m_state->m_address);
174  station->m_initialized = true;
175  }
176 }
177 
179 {
180  NS_LOG_FUNCTION (this << station);
181 }
182 
184 {
185  NS_LOG_FUNCTION (this << st);
187  CheckInit (station);
188  station->m_nFailed++;
189  station->m_nSuccess = 0;
190  NS_LOG_DEBUG ("station=" << station << ", rate=" << station->m_rateIndex
191  << ", power=" << (int)station->m_powerLevel);
192 
193  if (station->m_aparfState == AparfWifiManager::Low)
194  {
196  station->m_successThreshold = m_succesMax1;
197  }
198  else if (station->m_aparfState == AparfWifiManager::Spread)
199  {
201  station->m_successThreshold = m_succesMax2;
202  }
203 
204  if (station->m_nFailed == station->m_failThreshold)
205  {
206  station->m_nFailed = 0;
207  station->m_nSuccess = 0;
208  station->m_pCount = 0;
209  if (station->m_powerLevel == m_maxPower)
210  {
211  station->m_critRateIndex = station->m_rateIndex;
212  if (station->m_rateIndex != 0)
213  {
214  NS_LOG_DEBUG ("station=" << station << " dec rate");
215  station->m_rateIndex -= m_rateDec;
216  }
217  }
218  else
219  {
220  NS_LOG_DEBUG ("station=" << station << " inc power");
221  station->m_powerLevel += m_powerInc;
222  }
223  }
224 }
225 
226 void
228 {
229  NS_LOG_FUNCTION (this << station << rxSnr << txMode);
230 }
231 
232 void
234  WifiMode ctsMode, double rtsSnr)
235 {
236  NS_LOG_FUNCTION (this << station << ctsSnr << ctsMode << rtsSnr);
237 }
238 
239 void
241  WifiMode ackMode, double dataSnr)
242 {
243  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
245  CheckInit (station);
246  station->m_nSuccess++;
247  station->m_nFailed = 0;
248  NS_LOG_DEBUG ("station=" << station << " data ok success=" << station->m_nSuccess << ", rate=" << +station->m_rateIndex << ", power=" << +station->m_powerLevel);
249 
250  if ((station->m_aparfState == AparfWifiManager::High) && (station->m_nSuccess >= station->m_successThreshold))
251  {
253  }
254  else if ((station->m_aparfState == AparfWifiManager::Low) && (station->m_nSuccess >= station->m_successThreshold))
255  {
257  }
258  else if (station->m_aparfState == AparfWifiManager::Spread)
259  {
261  station->m_successThreshold = m_succesMax1;
262  }
263 
264  if (station->m_nSuccess == station->m_successThreshold)
265  {
266  station->m_nSuccess = 0;
267  station->m_nFailed = 0;
268  if (station->m_rateIndex == (station->m_state->m_operationalRateSet.size () - 1))
269  {
270  if (station->m_powerLevel != m_minPower)
271  {
272  NS_LOG_DEBUG ("station=" << station << " dec power");
273  station->m_powerLevel -= m_powerDec;
274  }
275  }
276  else
277  {
278  if (station->m_critRateIndex == 0)
279  {
280  if (station->m_rateIndex != (station->m_state->m_operationalRateSet.size () - 1))
281  {
282  NS_LOG_DEBUG ("station=" << station << " inc rate");
283  station->m_rateIndex += m_rateInc;
284  }
285  }
286  else
287  {
288  if (station->m_pCount == m_powerMax)
289  {
290  station->m_powerLevel = m_maxPower;
291  station->m_rateIndex = station->m_critRateIndex;
292  station->m_pCount = 0;
293  station->m_critRateIndex = 0;
294  }
295  else
296  {
297  if (station->m_powerLevel != m_minPower)
298  {
299  station->m_powerLevel -= m_powerDec;
300  station->m_pCount++;
301  }
302  }
303  }
304  }
305  }
306 }
307 
308 void
310 {
311  NS_LOG_FUNCTION (this << station);
312 }
313 
314 void
316 {
317  NS_LOG_FUNCTION (this << station);
318 }
319 
322 {
323  NS_LOG_FUNCTION (this << st);
325  uint16_t channelWidth = GetChannelWidth (station);
326  if (channelWidth > 20 && channelWidth != 22)
327  {
328  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
329  channelWidth = 20;
330  }
331  CheckInit (station);
332  WifiMode mode = GetSupported (station, station->m_rateIndex);
333  DataRate rate = DataRate (mode.GetDataRate (channelWidth));
334  DataRate prevRate = DataRate (GetSupported (station, station->m_prevRateIndex).GetDataRate (channelWidth));
335  double power = GetPhy ()->GetPowerDbm (station->m_powerLevel);
336  double prevPower = GetPhy ()->GetPowerDbm (station->m_prevPowerLevel);
337  if (station->m_prevPowerLevel != station->m_powerLevel)
338  {
339  m_powerChange (prevPower, power, station->m_state->m_address);
340  station->m_prevPowerLevel = station->m_powerLevel;
341  }
342  if (station->m_prevRateIndex != station->m_rateIndex)
343  {
344  m_rateChange (prevRate, rate, station->m_state->m_address);
345  station->m_prevRateIndex = station->m_rateIndex;
346  }
347  return WifiTxVector (mode, station->m_powerLevel, GetPreambleForTransmission (mode, GetAddress (st)), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
348 }
349 
352 {
353  NS_LOG_FUNCTION (this << st);
357  uint16_t channelWidth = GetChannelWidth (station);
358  if (channelWidth > 20 && channelWidth != 22)
359  {
360  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
361  channelWidth = 20;
362  }
363  WifiTxVector rtsTxVector;
364  WifiMode mode;
365  if (GetUseNonErpProtection () == false)
366  {
367  mode = GetSupported (station, 0);
368  }
369  else
370  {
371  mode = GetNonErpSupported (station, 0);
372  }
373  rtsTxVector = WifiTxVector (mode, GetDefaultTxPowerLevel (), GetPreambleForTransmission (mode, GetAddress (st)), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
374  return rtsTxVector;
375 }
376 
377 bool
379 {
380  return true;
381 }
382 
383 void
385 {
386  //HT is not supported by this algorithm.
387  if (enable)
388  {
389  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HT rates");
390  }
391 }
392 
393 void
395 {
396  //VHT is not supported by this algorithm.
397  if (enable)
398  {
399  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support VHT rates");
400  }
401 }
402 
403 void
405 {
406  //HE is not supported by this algorithm.
407  if (enable)
408  {
409  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HE rates");
410  }
411 }
412 
413 } //namespace ns3
uint32_t m_succesMax2
The minimum number of successful transmissions in "Low" state to try a new power or rate...
uint32_t m_nSuccess
Number of successful transmission attempts.
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station)
uint8_t m_powerDec
Step size for decrement the power.
uint8_t m_rateInc
Step size for increment the rate.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode)
This method is a pure virtual method that must be implemented by the sub-class.
uint8_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
APARF Power and rate control algorithm.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
void DoReportRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
static TypeId GetTypeId(void)
Register this type.
uint8_t m_critRateIndex
Critical rate.
uint8_t m_powerLevel
Current power level.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
Mac48Address m_address
Mac48Address of the remote station.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
AparfWifiManager::State m_aparfState
The estimated state of the channel.
uint32_t m_failThreshold
The minimum number of failed transmissions to try a new power or rate.
WifiMode GetSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether mode associated with the specified station at the specified index. ...
uint32_t m_successThreshold
The minimum number of successful transmissions to try a new power or rate.
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:97
State
Enumeration of the possible states of the channel.
WifiRemoteStation * DoCreateStation(void) const
void SetHeSupported(bool enable)
Enable or disable HE capability support.
WifiRemoteStationState * m_state
Remote station state.
bool m_initialized
For initializing variables.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
phy
Definition: third.py:86
Class for representing data rates.
Definition: data-rate.h:88
uint8_t m_maxPower
Maximal power level.
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.
uint8_t m_powerInc
Step size for increment the power.
TracedCallback< double, double, Mac48Address > m_powerChange
The trace source fired when the transmission power changes.
Hold an unsigned integer type.
Definition: uinteger.h:44
WifiPreamble GetPreambleForTransmission(WifiMode mode, Mac48Address dest)
Return the preamble to be used for the transmission.
uint32_t m_nFailed
Number of failed transmission attempts.
void CheckInit(AparfWifiRemoteStation *station)
Check for initializations.
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.
virtual void SetupPhy(const Ptr< WifiPhy > phy)
Set up PHY associated with this device since it is the object that knows the full set of transmit rat...
hold a list of per-remote-station state.
double GetPowerDbm(uint8_t power) const
Get the power of the given power level in dBm.
Definition: wifi-phy.cc:700
uint8_t m_rateDec
Step size for decrement the rate.
void SetupPhy(const Ptr< WifiPhy > phy)
Set up PHY associated with this device since it is the object that knows the full set of transmit rat...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
WifiModeList m_operationalRateSet
This member is the list of WifiMode objects that comprise the OperationalRateSet parameter for this r...
Hold per-remote-station state for APARF Wifi manager.
uint32_t m_failMax
The minimum number of failed transmissions to try a new power or rate.
uint8_t m_nSupported
Number of supported rates by the remote station.
uint8_t m_prevPowerLevel
Power level of the previous transmission.
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...
void DoReportFinalRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
TracedCallback< DataRate, DataRate, Mac48Address > m_rateChange
The trace source fired when the transmission rate changes.
void DoReportFinalDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
void DoReportDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
uint32_t m_succesMax1
The minimum number of successful transmissions in "High" state to try a new power or rate...
Ptr< WifiPhy > GetPhy(void) const
Return the WifiPhy.
uint32_t m_powerMax
The maximum number of power changes.
bool IsLowLatency(void) const
uint8_t m_minPower
Minimal power level.
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:270
uint32_t m_pCount
Number of power changes.
void SetHtSupported(bool enable)
Enable or disable HT capability support.
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:915
uint8_t m_prevRateIndex
Rate index of the previous transmission.
hold per-remote-station state.
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:156
uint16_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
void SetVhtSupported(bool enable)
Enable or disable VHT capability support.
uint8_t m_rateIndex
Current rate index.