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 "ns3/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);
182  ParfWifiRemoteStation *station = static_cast<ParfWifiRemoteStation*> (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 dataSnr, uint16_t dataChannelWidth, uint8_t dataNss)
263 {
264  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr << dataChannelWidth << +dataNss);
265  ParfWifiRemoteStation *station = static_cast<ParfWifiRemoteStation*> (st);
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);
314  ParfWifiRemoteStation *station = static_cast<ParfWifiRemoteStation*> (st);
315  uint16_t channelWidth = GetChannelWidth (station);
316  if (channelWidth > 20 && channelWidth != 22)
317  {
318  channelWidth = 20;
319  }
320  CheckInit (station);
321  WifiMode mode = GetSupported (station, station->m_rateIndex);
322  DataRate rate = DataRate (mode.GetDataRate (channelWidth));
323  DataRate prevRate = DataRate (GetSupported (station, station->m_prevRateIndex).GetDataRate (channelWidth));
324  double power = GetPhy ()->GetPowerDbm (station->m_powerLevel);
325  double prevPower = GetPhy ()->GetPowerDbm (station->m_prevPowerLevel);
326  if (station->m_prevPowerLevel != station->m_powerLevel)
327  {
328  m_powerChange (prevPower, power, station->m_state->m_address);
329  station->m_prevPowerLevel = station->m_powerLevel;
330  }
331  if (station->m_prevRateIndex != station->m_rateIndex)
332  {
333  m_rateChange (prevRate, rate, station->m_state->m_address);
334  station->m_prevRateIndex = station->m_rateIndex;
335  }
336  return WifiTxVector (mode, station->m_powerLevel, GetPreambleForTransmission (mode.GetModulationClass (), GetShortPreambleEnabled ()), 800, 1, 1, 0, channelWidth, GetAggregation (station));
337 }
338 
341 {
342  NS_LOG_FUNCTION (this << st);
345  ParfWifiRemoteStation *station = static_cast<ParfWifiRemoteStation*> (st);
346  uint16_t channelWidth = GetChannelWidth (station);
347  if (channelWidth > 20 && channelWidth != 22)
348  {
349  channelWidth = 20;
350  }
351  WifiMode mode;
352  if (GetUseNonErpProtection () == false)
353  {
354  mode = GetSupported (station, 0);
355  }
356  else
357  {
358  mode = GetNonErpSupported (station, 0);
359  }
360  return WifiTxVector (mode, GetDefaultTxPowerLevel (), GetPreambleForTransmission (mode.GetModulationClass (), GetShortPreambleEnabled ()), 800, 1, 1, 0, channelWidth, GetAggregation (station));
361 }
362 
363 } //namespace ns3
Class for representing data rates.
Definition: data-rate.h:89
PARF Rate control algorithm.
void DoInitialize(void) override
Initialize() implementation.
void DoReportFinalRtsFailed(WifiRemoteStation *station) override
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.
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.
void CheckInit(ParfWifiRemoteStation *station)
Check for initializations.
TracedCallback< double, double, Mac48Address > m_powerChange
The trace source fired when the transmission power changes.
void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode) override
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 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.
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station) override
void DoReportRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
void DoReportDataFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
static TypeId GetTypeId(void)
Register this type.
uint32_t m_attemptThreshold
The minimum number of transmission attempts to try a new power or rate.
void SetupPhy(const Ptr< WifiPhy > phy) override
Set up PHY associated with this device since it is the object that knows the full set of transmit rat...
WifiRemoteStation * DoCreateStation(void) const override
uint8_t m_maxPower
Maximal power level.
uint8_t m_minPower
Minimal power level.
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.
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
Hold an unsigned integer type.
Definition: uinteger.h:44
represent a single transmission mode
Definition: wifi-mode.h:48
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:177
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:114
double GetPowerDbm(uint8_t power) const
Get the power of the given power level in dBm.
Definition: wifi-phy.cc:606
hold a list of per-remote-station state.
uint16_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
bool GetVhtSupported(void) const
Return whether the device has VHT capability support enabled.
Ptr< WifiPhy > GetPhy(void) const
Return the WifiPhy.
uint8_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
bool GetUseNonErpProtection(void) const
Return whether the device supports protection of non-ERP stations.
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
WifiMode GetNonErpSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether non-ERP mode associated with the specified station at the specified index.
bool GetShortPreambleEnabled(void) const
Return whether the device uses short PHY preambles.
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...
bool GetHeSupported(void) const
Return whether the device has HE capability support enabled.
WifiMode GetSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether mode associated with the specified station at the specified index.
bool GetHtSupported(void) const
Return whether the device has HT 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:67
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
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
void(* DataRate)(DataRate oldValue, DataRate newValue)
TracedValue callback signature for DataRate.
Definition: data-rate.h:329
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
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.
WifiPreamble GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble)
Return the preamble to be used for the transmission.
phy
Definition: third.py:93
Hold per-remote-station state for PARF Wifi manager.
uint32_t m_nRetry
Number of transmission retries.
bool m_usingRecoveryPower
If using recovery power.
uint32_t m_nFail
Number of failed transmission attempts.
bool m_usingRecoveryRate
If using recovery rate.
uint8_t m_rateIndex
Current rate index used by the remote station.
uint32_t m_nSuccess
Number of successful transmission attempts.
uint8_t m_prevRateIndex
Rate index of the previous transmission.
uint8_t m_powerLevel
Current power level used by the remote station.
uint8_t m_nSupported
Number of supported rates by the remote station.
bool m_initialized
For initializing variables.
uint8_t m_prevPowerLevel
Power level of the previous transmission.
uint32_t m_nAttempt
Number of transmission attempts.
hold per-remote-station state.
WifiRemoteStationState * m_state
Remote station state.
Mac48Address m_address
Mac48Address of the remote station.
WifiModeList m_operationalRateSet
This member is the list of WifiMode objects that comprise the OperationalRateSet parameter for this r...