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 "aparf-wifi-manager.h"
22 #include "wifi-phy.h"
23 #include "ns3/log.h"
24 #include "ns3/uinteger.h"
25 
26 #define Min(a,b) ((a < b) ? a : b)
27 
28 namespace ns3 {
29 
30 NS_LOG_COMPONENT_DEFINE ("AparfWifiManager");
31 
38 struct
40 {
41  uint32_t m_nSuccess;
42  uint32_t m_nFailed;
43  uint32_t m_pCount;
44  uint32_t m_successThreshold;
45  uint32_t m_failThreshold;
46  uint32_t m_prevRateIndex;
47  uint32_t m_rateIndex;
48  uint32_t m_critRateIndex;
49  uint8_t m_prevPowerLevel;
50  uint8_t m_powerLevel;
51  uint32_t m_nSupported;
54 };
55 
57 
58 TypeId
60 {
61  static TypeId tid = TypeId ("ns3::AparfWifiManager")
63  .SetGroupName ("Wifi")
64  .AddConstructor<AparfWifiManager> ()
65  .AddAttribute ("SuccessThreshold1",
66  "The minimum number of successful transmissions in \"High\" state to try a new power or rate.",
67  UintegerValue (3),
69  MakeUintegerChecker<uint32_t> ())
70  .AddAttribute ("SuccessThreshold2",
71  "The minimum number of successful transmissions in \"Low\" state to try a new power or rate.",
72  UintegerValue (10),
74  MakeUintegerChecker<uint32_t> ())
75  .AddAttribute ("FailThreshold",
76  "The minimum number of failed transmissions to try a new power or rate.",
77  UintegerValue (1),
79  MakeUintegerChecker<uint32_t> ())
80  .AddAttribute ("PowerThreshold",
81  "The maximum number of power changes.",
82  UintegerValue (10),
84  MakeUintegerChecker<uint32_t> ())
85  .AddAttribute ("PowerDecrementStep",
86  "Step size for decrement the power.",
87  UintegerValue (1),
89  MakeUintegerChecker<uint32_t> ())
90  .AddAttribute ("PowerIncrementStep",
91  "Step size for increment the power.",
92  UintegerValue (1),
94  MakeUintegerChecker<uint32_t> ())
95  .AddAttribute ("RateDecrementStep",
96  "Step size for decrement the rate.",
97  UintegerValue (1),
99  MakeUintegerChecker<uint32_t> ())
100  .AddAttribute ("RateIncrementStep",
101  "Step size for increment the rate.",
102  UintegerValue (1),
104  MakeUintegerChecker<uint32_t> ())
105  .AddTraceSource ("PowerChange",
106  "The transmission power has change",
108  "ns3::WifiRemoteStationManager::PowerChangeTracedCallback")
109  .AddTraceSource ("RateChange",
110  "The transmission rate has change",
112  "ns3::WifiRemoteStationManager::RateChangeTracedCallback")
113  ;
114  return tid;
115 }
116 
118 {
119  NS_LOG_FUNCTION (this);
120 }
121 
123 {
124  NS_LOG_FUNCTION (this);
125 }
126 
127 void
129 {
130  m_minPower = phy->GetTxPowerStart ();
131  m_maxPower = phy->GetTxPowerEnd ();
133 }
134 
137 {
138  NS_LOG_FUNCTION (this);
140 
141  station->m_successThreshold = m_succesMax1;
142  station->m_failThreshold = m_failMax;
143  station->m_nSuccess = 0;
144  station->m_nFailed = 0;
145  station->m_pCount = 0;
147  station->m_initialized = false;
148 
149  NS_LOG_DEBUG ("create station=" << station << ", rate=" << station->m_rateIndex
150  << ", power=" << (int)station->m_powerLevel);
151 
152  return station;
153 }
154 
155 void
157 {
158  if (!station->m_initialized)
159  {
160  station->m_nSupported = GetNSupported (station);
161  station->m_rateIndex = station->m_nSupported - 1;
162  station->m_prevRateIndex = station->m_nSupported - 1;
163  station->m_powerLevel = m_maxPower;
164  station->m_prevPowerLevel = m_maxPower;
165  station->m_critRateIndex = 0;
166  WifiMode mode = GetSupported (station, station->m_rateIndex);
167  uint8_t channelWidth = GetChannelWidth (station);
168  DataRate rate = DataRate (mode.GetDataRate (channelWidth));
169  double power = GetPhy ()->GetPowerDbm (m_maxPower);
170  m_powerChange (power, power, station->m_state->m_address);
171  m_rateChange (rate, rate, station->m_state->m_address);
172  station->m_initialized = true;
173  }
174 }
175 
177 {
178  NS_LOG_FUNCTION (this << station);
179 }
180 
182 {
183  NS_LOG_FUNCTION (this << st);
185  CheckInit (station);
186  station->m_nFailed++;
187  station->m_nSuccess = 0;
188  NS_LOG_DEBUG ("station=" << station << ", rate=" << station->m_rateIndex
189  << ", power=" << (int)station->m_powerLevel);
190 
191  if (station->m_aparfState == AparfWifiManager::Low)
192  {
194  station->m_successThreshold = m_succesMax1;
195  }
196  else if (station->m_aparfState == AparfWifiManager::Spread)
197  {
199  station->m_successThreshold = m_succesMax2;
200  }
201 
202  if (station->m_nFailed == station->m_failThreshold)
203  {
204  station->m_nFailed = 0;
205  station->m_nSuccess = 0;
206  station->m_pCount = 0;
207  if (station->m_powerLevel == m_maxPower)
208  {
209  station->m_critRateIndex = station->m_rateIndex;
210  if (station->m_rateIndex != 0)
211  {
212  NS_LOG_DEBUG ("station=" << station << " dec rate");
213  station->m_rateIndex -= m_rateDec;
214  }
215  }
216  else
217  {
218  NS_LOG_DEBUG ("station=" << station << " inc power");
219  station->m_powerLevel += m_powerInc;
220  }
221  }
222 }
223 
224 void
226 {
227  NS_LOG_FUNCTION (this << station << rxSnr << txMode);
228 }
229 
230 void
232  WifiMode ctsMode, double rtsSnr)
233 {
234  NS_LOG_FUNCTION (this << station << ctsSnr << ctsMode << rtsSnr);
235  NS_LOG_DEBUG ("station=" << station << " rts ok");
236 }
237 
238 void
240  WifiMode ackMode, double dataSnr)
241 {
242  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
244  CheckInit (station);
245  station->m_nSuccess++;
246  station->m_nFailed = 0;
247  NS_LOG_DEBUG ("station=" << station << " data ok success=" << station->m_nSuccess << ", rate=" << station->m_rateIndex << ", power=" << (int)station->m_powerLevel);
248 
249  if ((station->m_aparfState == AparfWifiManager::High) && (station->m_nSuccess >= station->m_successThreshold))
250  {
252  }
253  else if ((station->m_aparfState == AparfWifiManager::Low) && (station->m_nSuccess >= station->m_successThreshold))
254  {
256  }
257  else if (station->m_aparfState == AparfWifiManager::Spread)
258  {
260  station->m_successThreshold = m_succesMax1;
261  }
262 
263  if (station->m_nSuccess == station->m_successThreshold)
264  {
265  station->m_nSuccess = 0;
266  station->m_nFailed = 0;
267  if (station->m_rateIndex == (station->m_state->m_operationalRateSet.size () - 1))
268  {
269  if (station->m_powerLevel != m_minPower)
270  {
271  NS_LOG_DEBUG ("station=" << station << " dec power");
272  station->m_powerLevel -= m_powerDec;
273  }
274  }
275  else
276  {
277  if (station->m_critRateIndex == 0)
278  {
279  if (station->m_rateIndex != (station->m_state->m_operationalRateSet.size () - 1))
280  {
281  NS_LOG_DEBUG ("station=" << station << " inc rate");
282  station->m_rateIndex += m_rateInc;
283  }
284  }
285  else
286  {
287  if (station->m_pCount == m_powerMax)
288  {
289  station->m_powerLevel = m_maxPower;
290  station->m_rateIndex = station->m_critRateIndex;
291  station->m_pCount = 0;
292  station->m_critRateIndex = 0;
293  }
294  else
295  {
296  if (station->m_powerLevel != m_minPower)
297  {
298  station->m_powerLevel -= m_powerDec;
299  station->m_pCount++;
300  }
301  }
302  }
303  }
304  }
305 }
306 
307 void
309 {
310  NS_LOG_FUNCTION (this << station);
311 }
312 
313 void
315 {
316  NS_LOG_FUNCTION (this << station);
317 }
318 
321 {
322  NS_LOG_FUNCTION (this << st);
324  uint32_t channelWidth = GetChannelWidth (station);
325  if (channelWidth > 20 && channelWidth != 22)
326  {
327  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
328  channelWidth = 20;
329  }
330  CheckInit (station);
331  WifiMode mode = GetSupported (station, station->m_rateIndex);
332  DataRate rate = DataRate (mode.GetDataRate (channelWidth));
333  DataRate prevRate = DataRate (GetSupported (station, station->m_prevRateIndex).GetDataRate (channelWidth));
334  double power = GetPhy ()->GetPowerDbm (station->m_powerLevel);
335  double prevPower = GetPhy ()->GetPowerDbm (station->m_prevPowerLevel);
336  if (station->m_prevPowerLevel != station->m_powerLevel)
337  {
338  m_powerChange (prevPower, power, station->m_state->m_address);
339  station->m_prevPowerLevel = station->m_powerLevel;
340  }
341  if (station->m_prevRateIndex != station->m_rateIndex)
342  {
343  m_rateChange (prevRate, rate, station->m_state->m_address);
344  station->m_prevRateIndex = station->m_rateIndex;
345  }
346  return WifiTxVector (mode, station->m_powerLevel, GetLongRetryCount (station), GetPreambleForTransmission (mode, GetAddress (st)), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
347 }
348 
351 {
352  NS_LOG_FUNCTION (this << st);
356  uint32_t channelWidth = GetChannelWidth (station);
357  if (channelWidth > 20 && channelWidth != 22)
358  {
359  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
360  channelWidth = 20;
361  }
362  WifiTxVector rtsTxVector;
363  WifiMode mode;
364  if (GetUseNonErpProtection () == false)
365  {
366  mode = GetSupported (station, 0);
367  }
368  else
369  {
370  mode = GetNonErpSupported (station, 0);
371  }
372  rtsTxVector = WifiTxVector (mode, GetDefaultTxPowerLevel (), GetShortRetryCount (station), GetPreambleForTransmission (mode, GetAddress (st)), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
373  return rtsTxVector;
374 }
375 
376 bool
378 {
379  NS_LOG_FUNCTION (this);
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 GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
uint32_t m_nSuccess
Number of successful transmission attempts.
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station)
#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.
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:44
uint32_t m_rateInc
Step size for increment the rate.
uint32_t m_minPower
Minimal power level.
bool GetUseNonErpProtection(void) const
Return whether the device supports protection of non-ERP stations.
static TypeId GetTypeId(void)
Register this type.
uint8_t m_powerLevel
Current power level.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
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.
uint32_t m_successThreshold
The minimum number of successful transmissions to try a new power or rate.
virtual void SetupPhy(Ptr< WifiPhy > phy)
Set up PHY associated with this device since it is the object that knows the full set of transmit rat...
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:97
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
uint32_t m_powerDec
Step size for decrement the power.
WifiMode GetSupported(const WifiRemoteStation *station, uint32_t i) const
Return whether mode associated with the specified station at the specified index. ...
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.
uint32_t m_rateDec
Step size for decrement the rate.
Class for representing data rates.
Definition: data-rate.h:88
Ptr< WifiPhy > GetPhy(void) const
Return the WifiPhy.
uint32_t m_powerInc
Step size for increment the power.
double GetPowerDbm(uint8_t power) const
Get the power of the given power level in dBm.
Definition: wifi-phy.cc:726
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.
uint32_t m_maxPower
Maximal power level.
tuple phy
Definition: third.py:86
TracedCallback< double, double, Mac48Address > m_powerChange
The trace source fired when the transmission power changes.
Hold an unsigned integer type.
Definition: uinteger.h:44
WifiMode GetNonErpSupported(const WifiRemoteStation *station, uint32_t i) const
Return whether non-ERP mode associated with the specified station at the specified index...
WifiPreamble GetPreambleForTransmission(WifiMode mode, Mac48Address dest)
Return the preamble to be used for the transmission.
uint64_t GetDataRate(uint8_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:143
uint8_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
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.
WifiRemoteStation * DoCreateStation(void) const
Mac48Address GetAddress(const WifiRemoteStation *station) const
Return the address of the station.
hold a list of per-remote-station state.
uint32_t m_critRateIndex
Critical rate.
bool IsLowLatency(void) const
uint32_t m_nSupported
Number of supported rates by the remote station.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double GetTxPowerEnd(void) const
Return the maximum available transmission power level (dBm).
Definition: wifi-phy.cc:546
void SetupPhy(Ptr< WifiPhy > phy)
Set up PHY associated with this device since it is the object that knows the full set of transmit rat...
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_prevPowerLevel
Power level of the previous transmission.
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.
uint32_t m_rateIndex
Current rate index.
void DoReportFinalDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
State
Enumeration of the possible states of the channel.
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)
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...
uint32_t m_prevRateIndex
Rate index of the previous transmission.
uint32_t m_powerMax
The maximum number of power changes.
uint32_t GetLongRetryCount(const WifiRemoteStation *station) const
Return the long retry limit of the given station.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:269
uint32_t m_pCount
Number of power changes.
void SetHtSupported(bool enable)
Enable or disable HT capability support.
uint32_t GetShortRetryCount(const WifiRemoteStation *station) const
Return the short retry limit of the given station.
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:904
hold per-remote-station state.
double GetTxPowerStart(void) const
Return the minimum available transmission power level (dBm).
Definition: wifi-phy.cc:533
void SetVhtSupported(bool enable)
Enable or disable VHT capability support.