A Discrete-Event Network Simulator
API
parf-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 "parf-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 ("ParfWifiManager");
32 
40 {
41  uint32_t m_nAttempt;
42  uint32_t m_nSuccess;
43  uint32_t m_nFail;
46  uint32_t m_nRetry;
47  uint8_t m_prevRateIndex;
48  uint8_t m_rateIndex;
49  uint8_t m_prevPowerLevel;
50  uint8_t m_powerLevel;
51  uint8_t m_nSupported;
53 };
54 
56 
57 TypeId
59 {
60  static TypeId tid = TypeId ("ns3::ParfWifiManager")
62  .SetGroupName ("Wifi")
63  .AddConstructor<ParfWifiManager> ()
64  .AddAttribute ("AttemptThreshold",
65  "The minimum number of transmission attempts to try a new power or rate.",
66  UintegerValue (15),
68  MakeUintegerChecker<uint32_t> ())
69  .AddAttribute ("SuccessThreshold",
70  "The minimum number of successful transmissions to try a new power or rate.",
71  UintegerValue (10),
73  MakeUintegerChecker<uint32_t> ())
74  .AddTraceSource ("PowerChange",
75  "The transmission power has change",
77  "ns3::WifiRemoteStationManager::PowerChangeTracedCallback")
78  .AddTraceSource ("RateChange",
79  "The transmission rate has change",
81  "ns3::WifiRemoteStationManager::RateChangeTracedCallback")
82  ;
83  return tid;
84 }
85 
87 {
88  NS_LOG_FUNCTION (this);
89 }
90 
92 {
93  NS_LOG_FUNCTION (this);
94 }
95 
96 void
98 {
99  NS_LOG_FUNCTION (this << phy);
100  m_minPower = 0;
101  m_maxPower = phy->GetNTxPower () - 1;
103 }
104 
105 void
107 {
108  NS_LOG_FUNCTION (this);
109  if (GetHtSupported ())
110  {
111  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HT rates");
112  }
113  if (GetVhtSupported ())
114  {
115  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support VHT rates");
116  }
117  if (GetHeSupported ())
118  {
119  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HE rates");
120  }
121 }
122 
125 {
126  NS_LOG_FUNCTION (this);
128 
129  station->m_nSuccess = 0;
130  station->m_nFail = 0;
131  station->m_usingRecoveryRate = false;
132  station->m_usingRecoveryPower = false;
133  station->m_initialized = false;
134  station->m_nRetry = 0;
135  station->m_nAttempt = 0;
136 
137  NS_LOG_DEBUG ("create station=" << station << ", timer=" << station->m_nAttempt
138  << ", rate=" << +station->m_rateIndex << ", power=" << +station->m_powerLevel);
139 
140  return station;
141 }
142 
143 void
145 {
146  if (!station->m_initialized)
147  {
148  station->m_nSupported = GetNSupported (station);
149  station->m_rateIndex = station->m_nSupported - 1;
150  station->m_prevRateIndex = station->m_nSupported - 1;
151  station->m_powerLevel = m_maxPower;
152  station->m_prevPowerLevel = m_maxPower;
153  WifiMode mode = GetSupported (station, station->m_rateIndex);
154  uint16_t channelWidth = GetChannelWidth (station);
155  DataRate rate = DataRate (mode.GetDataRate (channelWidth));
156  double power = GetPhy ()->GetPowerDbm (m_maxPower);
157  m_powerChange (power, power, station->m_state->m_address);
158  m_rateChange (rate, rate, station->m_state->m_address);
159  station->m_initialized = true;
160  }
161 }
162 
163 void
165 {
166  NS_LOG_FUNCTION (this << station);
167 }
168 
169 /*
170  * It is important to realize that "recovery" mode starts after failure of
171  * the first transmission after a rate increase and ends at the first successful
172  * transmission. Specifically, recovery mode spans retransmissions boundaries.
173  * Fundamentally, ARF handles each data transmission independently, whether it
174  * is the initial transmission of a packet or the retransmission of a packet.
175  * The fundamental reason for this is that there is a backoff between each data
176  * transmission, be it an initial transmission or a retransmission.
177  */
178 void
180 {
181  NS_LOG_FUNCTION (this << st);
183  CheckInit (station);
184  station->m_nAttempt++;
185  station->m_nFail++;
186  station->m_nRetry++;
187  station->m_nSuccess = 0;
188 
189  NS_LOG_DEBUG ("station=" << station << " data fail retry=" << station->m_nRetry << ", timer=" << station->m_nAttempt
190  << ", rate=" << +station->m_rateIndex << ", power=" << +station->m_powerLevel);
191  if (station->m_usingRecoveryRate)
192  {
193  NS_ASSERT (station->m_nRetry >= 1);
194  if (station->m_nRetry == 1)
195  {
196  //need recovery fallback
197  if (station->m_rateIndex != 0)
198  {
199  NS_LOG_DEBUG ("station=" << station << " dec rate");
200  station->m_rateIndex--;
201  station->m_usingRecoveryRate = false;
202  }
203  }
204  station->m_nAttempt = 0;
205  }
206  else if (station->m_usingRecoveryPower)
207  {
208  NS_ASSERT (station->m_nRetry >= 1);
209  if (station->m_nRetry == 1)
210  {
211  //need recovery fallback
212  if (station->m_powerLevel < m_maxPower)
213  {
214  NS_LOG_DEBUG ("station=" << station << " inc power");
215  station->m_powerLevel++;
216  station->m_usingRecoveryPower = false;
217  }
218  }
219  station->m_nAttempt = 0;
220  }
221  else
222  {
223  NS_ASSERT (station->m_nRetry >= 1);
224  if (((station->m_nRetry - 1) % 2) == 1)
225  {
226  //need normal fallback
227  if (station->m_powerLevel == m_maxPower)
228  {
229  if (station->m_rateIndex != 0)
230  {
231  NS_LOG_DEBUG ("station=" << station << " dec rate");
232  station->m_rateIndex--;
233  }
234  }
235  else
236  {
237  NS_LOG_DEBUG ("station=" << station << " inc power");
238  station->m_powerLevel++;
239  }
240  }
241  if (station->m_nRetry >= 2)
242  {
243  station->m_nAttempt = 0;
244  }
245  }
246 }
247 
248 void
250  double rxSnr, WifiMode txMode)
251 {
252  NS_LOG_FUNCTION (this << station << rxSnr << txMode);
253 }
254 
256  double ctsSnr, WifiMode ctsMode, double rtsSnr)
257 {
258  NS_LOG_FUNCTION (this << station << ctsSnr << ctsMode << rtsSnr);
259 }
260 
262  double ackSnr, WifiMode ackMode, double dataSnr)
263 {
264  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
266  CheckInit (station);
267  station->m_nAttempt++;
268  station->m_nSuccess++;
269  station->m_nFail = 0;
270  station->m_usingRecoveryRate = false;
271  station->m_usingRecoveryPower = false;
272  station->m_nRetry = 0;
273  NS_LOG_DEBUG ("station=" << station << " data ok success=" << station->m_nSuccess << ", timer=" << station->m_nAttempt << ", rate=" << +station->m_rateIndex << ", power=" << +station->m_powerLevel);
274  if ((station->m_nSuccess == m_successThreshold
275  || station->m_nAttempt == m_attemptThreshold)
276  && (station->m_rateIndex < (station->m_state->m_operationalRateSet.size () - 1)))
277  {
278  NS_LOG_DEBUG ("station=" << station << " inc rate");
279  station->m_rateIndex++;
280  station->m_nAttempt = 0;
281  station->m_nSuccess = 0;
282  station->m_usingRecoveryRate = true;
283  }
284  else if (station->m_nSuccess == m_successThreshold || station->m_nAttempt == m_attemptThreshold)
285  {
286  //we are at the maximum rate, we decrease power
287  if (station->m_powerLevel != m_minPower)
288  {
289  NS_LOG_DEBUG ("station=" << station << " dec power");
290  station->m_powerLevel--;
291  }
292  station->m_nAttempt = 0;
293  station->m_nSuccess = 0;
294  station->m_usingRecoveryPower = true;
295  }
296 }
297 
298 void
300 {
301  NS_LOG_FUNCTION (this << station);
302 }
303 
304 void
306 {
307  NS_LOG_FUNCTION (this << station);
308 }
309 
312 {
313  NS_LOG_FUNCTION (this << st);
315  uint16_t channelWidth = GetChannelWidth (station);
316  if (channelWidth > 20 && channelWidth != 22)
317  {
318  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
319  channelWidth = 20;
320  }
321  CheckInit (station);
322  WifiMode mode = GetSupported (station, station->m_rateIndex);
323  DataRate rate = DataRate (mode.GetDataRate (channelWidth));
324  DataRate prevRate = DataRate (GetSupported (station, station->m_prevRateIndex).GetDataRate (channelWidth));
325  double power = GetPhy ()->GetPowerDbm (station->m_powerLevel);
326  double prevPower = GetPhy ()->GetPowerDbm (station->m_prevPowerLevel);
327  if (station->m_prevPowerLevel != station->m_powerLevel)
328  {
329  m_powerChange (prevPower, power, station->m_state->m_address);
330  station->m_prevPowerLevel = station->m_powerLevel;
331  }
332  if (station->m_prevRateIndex != station->m_rateIndex)
333  {
334  m_rateChange (prevRate, rate, station->m_state->m_address);
335  station->m_prevRateIndex = station->m_rateIndex;
336  }
337  return WifiTxVector (mode, station->m_powerLevel, GetPreambleForTransmission (mode.GetModulationClass (), GetShortPreambleEnabled (), UseGreenfieldForDestination (GetAddress (station))), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
338 }
339 
342 {
343  NS_LOG_FUNCTION (this << st);
347  uint16_t channelWidth = GetChannelWidth (station);
348  if (channelWidth > 20 && channelWidth != 22)
349  {
350  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
351  channelWidth = 20;
352  }
353  WifiTxVector rtsTxVector;
354  WifiMode mode;
355  if (GetUseNonErpProtection () == false)
356  {
357  mode = GetSupported (station, 0);
358  }
359  else
360  {
361  mode = GetNonErpSupported (station, 0);
362  }
363  rtsTxVector = WifiTxVector (mode, GetDefaultTxPowerLevel (), GetPreambleForTransmission (mode.GetModulationClass (), GetShortPreambleEnabled (), UseGreenfieldForDestination (GetAddress (station))), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
364  return rtsTxVector;
365 }
366 
367 bool
369 {
370  return true;
371 }
372 
373 } //namespace ns3
uint8_t m_powerLevel
Current power level used by the remote station.
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.
Hold per-remote-station state for PARF Wifi manager.
uint8_t m_maxPower
Maximal power level.
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
TracedCallback< DataRate, DataRate, Mac48Address > m_rateChange
The trace source fired when the transmission rate changes.
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
void CheckInit(ParfWifiRemoteStation *station)
Check for initializations.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:204
uint32_t m_nAttempt
Number of transmission attempts.
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
TracedCallback< double, double, Mac48Address > m_powerChange
The trace source fired when the transmission power changes.
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. ...
uint8_t m_nSupported
Number of supported rates by the remote station.
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)
This method is a pure virtual method that must be implemented by the sub-class.
WifiRemoteStationState * m_state
Remote station state.
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
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 GetShortPreambleEnabled(void) const
Return whether the device uses short PLCP preambles.
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.
void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode)
This method is a pure virtual method that must be implemented by the sub-class.
uint32_t m_successThreshold
The minimum number of successful transmissions to try a new power or rate.
Hold an unsigned integer type.
Definition: uinteger.h:44
uint8_t m_rateIndex
Current rate index used by the remote station.
void DoReportRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
void DoReportFinalDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
bool GetHtSupported(void) const
Return whether the device has HT capability support enabled.
void DoInitialize(void)
Initialize() implementation.
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.
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:494
double GetPowerDbm(uint8_t power) const
Get the power of the given power level in dBm.
Definition: wifi-phy.cc:794
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool m_initialized
For initializing variables.
WifiModeList m_operationalRateSet
This member is the list of WifiMode objects that comprise the OperationalRateSet parameter for this r...
PARF Rate control algorithm.
uint8_t m_minPower
Minimal power level.
bool UseGreenfieldForDestination(Mac48Address dest) const
bool IsLowLatency(void) const
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...
uint32_t m_nRetry
Number of transmission retries.
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
uint8_t m_prevRateIndex
Rate index of the previous transmission.
Ptr< WifiPhy > GetPhy(void) const
Return the WifiPhy.
WifiRemoteStation * DoCreateStation(void) const
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...
static TypeId GetTypeId(void)
Register this type.
bool GetUseNonErpProtection(void) const
Return whether the device supports protection of non-ERP stations.
uint32_t m_nFail
Number of failed transmission attempts.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:272
uint32_t m_nSuccess
Number of successful transmission attempts.
bool m_usingRecoveryRate
If using recovery rate.
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)
bool m_usingRecoveryPower
If using recovery power.
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station)
void DoReportFinalRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
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
hold per-remote-station state.
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:150
uint32_t m_attemptThreshold
The minimum number of transmission attempts to try a new power or rate.
uint16_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
uint8_t m_prevPowerLevel
Power level of the previous transmission.