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  uint8_t m_prevRateIndex;
47  uint8_t m_rateIndex;
48  uint8_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<uint8_t> ())
90  .AddAttribute ("PowerIncrementStep",
91  "Step size for increment the power.",
92  UintegerValue (1),
94  MakeUintegerChecker<uint8_t> ())
95  .AddAttribute ("RateDecrementStep",
96  "Step size for decrement the rate.",
97  UintegerValue (1),
99  MakeUintegerChecker<uint8_t> ())
100  .AddAttribute ("RateIncrementStep",
101  "Step size for increment the rate.",
102  UintegerValue (1),
104  MakeUintegerChecker<uint8_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  NS_LOG_FUNCTION (this << phy);
131  m_minPower = phy->GetTxPowerStart ();
132  m_maxPower = phy->GetTxPowerEnd ();
134 }
135 
138 {
139  NS_LOG_FUNCTION (this);
141 
142  station->m_successThreshold = m_succesMax1;
143  station->m_failThreshold = m_failMax;
144  station->m_nSuccess = 0;
145  station->m_nFailed = 0;
146  station->m_pCount = 0;
148  station->m_initialized = false;
149 
150  NS_LOG_DEBUG ("create station=" << station << ", rate=" << +station->m_rateIndex
151  << ", power=" << +station->m_powerLevel);
152 
153  return station;
154 }
155 
156 void
158 {
159  if (!station->m_initialized)
160  {
161  station->m_nSupported = GetNSupported (station);
162  station->m_rateIndex = station->m_nSupported - 1;
163  station->m_prevRateIndex = station->m_nSupported - 1;
164  station->m_powerLevel = m_maxPower;
165  station->m_prevPowerLevel = m_maxPower;
166  station->m_critRateIndex = 0;
167  WifiMode mode = GetSupported (station, station->m_rateIndex);
168  uint8_t channelWidth = GetChannelWidth (station);
169  DataRate rate = DataRate (mode.GetDataRate (channelWidth));
170  double power = GetPhy ()->GetPowerDbm (m_maxPower);
171  m_powerChange (power, power, station->m_state->m_address);
172  m_rateChange (rate, rate, station->m_state->m_address);
173  station->m_initialized = true;
174  }
175 }
176 
178 {
179  NS_LOG_FUNCTION (this << station);
180 }
181 
183 {
184  NS_LOG_FUNCTION (this << st);
186  CheckInit (station);
187  station->m_nFailed++;
188  station->m_nSuccess = 0;
189  NS_LOG_DEBUG ("station=" << station << ", rate=" << station->m_rateIndex
190  << ", power=" << (int)station->m_powerLevel);
191 
192  if (station->m_aparfState == AparfWifiManager::Low)
193  {
195  station->m_successThreshold = m_succesMax1;
196  }
197  else if (station->m_aparfState == AparfWifiManager::Spread)
198  {
200  station->m_successThreshold = m_succesMax2;
201  }
202 
203  if (station->m_nFailed == station->m_failThreshold)
204  {
205  station->m_nFailed = 0;
206  station->m_nSuccess = 0;
207  station->m_pCount = 0;
208  if (station->m_powerLevel == m_maxPower)
209  {
210  station->m_critRateIndex = station->m_rateIndex;
211  if (station->m_rateIndex != 0)
212  {
213  NS_LOG_DEBUG ("station=" << station << " dec rate");
214  station->m_rateIndex -= m_rateDec;
215  }
216  }
217  else
218  {
219  NS_LOG_DEBUG ("station=" << station << " inc power");
220  station->m_powerLevel += m_powerInc;
221  }
222  }
223 }
224 
225 void
227 {
228  NS_LOG_FUNCTION (this << station << rxSnr << txMode);
229 }
230 
231 void
233  WifiMode ctsMode, double rtsSnr)
234 {
235  NS_LOG_FUNCTION (this << station << ctsSnr << ctsMode << rtsSnr);
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=" << +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  uint8_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, GetPreambleForTransmission (mode, GetAddress (st)), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
347 }
348 
351 {
352  NS_LOG_FUNCTION (this << st);
356  uint8_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 (), GetPreambleForTransmission (mode, GetAddress (st)), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
373  return rtsTxVector;
374 }
375 
376 bool
378 {
379  return true;
380 }
381 
382 void
384 {
385  //HT is not supported by this algorithm.
386  if (enable)
387  {
388  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HT rates");
389  }
390 }
391 
392 void
394 {
395  //VHT is not supported by this algorithm.
396  if (enable)
397  {
398  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support VHT rates");
399  }
400 }
401 
402 void
404 {
405  //HE is not supported by this algorithm.
406  if (enable)
407  {
408  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HE rates");
409  }
410 }
411 
412 } //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.
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
bool GetUseNonErpProtection(void) const
Return whether the device supports protection of non-ERP stations.
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: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.
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.
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.
Class for representing data rates.
Definition: data-rate.h:88
Ptr< WifiPhy > GetPhy(void) const
Return the WifiPhy.
double GetPowerDbm(uint8_t power) const
Get the power of the given power level in dBm.
Definition: wifi-phy.cc:716
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.
tuple phy
Definition: third.py:86
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.
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.
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.
bool IsLowLatency(void) const
uint32_t m_nSupported
Number of supported rates by the remote station.
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.
double GetTxPowerEnd(void) const
Return the maximum available transmission power level (dBm).
Definition: wifi-phy.cc:530
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.
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.
WifiMode GetSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether mode associated with the specified station at the specified index. ...
uint32_t m_succesMax1
The minimum number of successful transmissions in "High" state to try a new power or rate...
WifiMode GetNonErpSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether non-ERP mode associated with the specified station at the specified index...
uint32_t m_powerMax
The maximum number of power changes.
uint8_t m_minPower
Minimal power level.
#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.
uint8_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by 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:914
uint8_t m_prevRateIndex
Rate index of the previous transmission.
hold per-remote-station state.
double GetTxPowerStart(void) const
Return the minimum available transmission power level (dBm).
Definition: wifi-phy.cc:517
void SetVhtSupported(bool enable)
Enable or disable VHT capability support.
uint8_t m_rateIndex
Current rate index.