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 "parf-wifi-manager.h"
22 #include "wifi-phy.h"
23 #include "ns3/assert.h"
24 #include "ns3/log.h"
25 #include "ns3/uinteger.h"
26 #include "ns3/trace-source-accessor.h"
27 
28 #define Min(a,b) ((a < b) ? a : b)
29 
30 NS_LOG_COMPONENT_DEFINE ("ns3::ParfWifiManager");
31 
32 namespace ns3 {
33 
41 {
42  uint32_t m_nAttempt;
43  uint32_t m_nSuccess;
44  uint32_t m_nFail;
47  uint32_t m_nRetry;
48  uint32_t m_currentRate;
49  uint8_t m_currentPower;
50  uint32_t m_nSupported;
52 };
53 
55 
56 TypeId
58 {
59  static TypeId tid = TypeId ("ns3::ParfWifiManager")
61  .SetGroupName ("Wifi")
62  .AddConstructor<ParfWifiManager> ()
63  .AddAttribute ("AttemptThreshold",
64  "The minimum number of transmission attempts to try a new power or rate.",
65  UintegerValue (15),
67  MakeUintegerChecker<uint32_t> ())
68  .AddAttribute ("SuccessThreshold",
69  "The minimum number of successful transmissions to try a new power or rate.",
70  UintegerValue (10),
72  MakeUintegerChecker<uint32_t> ())
73  .AddTraceSource ("PowerChange",
74  "The transmission power has change",
76  "ns3::WifiRemoteStationManager::PowerChangeTracedCallback")
77  .AddTraceSource ("RateChange",
78  "The transmission rate has change",
80  "ns3::WifiRemoteStationManager::RateChangeTracedCallback")
81  ;
82  return tid;
83 }
84 
86 {
87  NS_LOG_FUNCTION (this);
88 }
89 
91 {
92  NS_LOG_FUNCTION (this);
93 }
94 
95 void
97 {
98  m_minPower = phy->GetTxPowerStart ();
99  m_maxPower = phy->GetTxPowerEnd ();
101 }
102 
105 {
106  NS_LOG_FUNCTION (this);
108 
109  station->m_nSuccess = 0;
110  station->m_nFail = 0;
111  station->m_usingRecoveryRate = false;
112  station->m_usingRecoveryPower = false;
113  station->m_initialized = false;
114  station->m_nRetry = 0;
115  station->m_nAttempt = 0;
116 
117  NS_LOG_DEBUG ("create station=" << station << ", timer=" << station->m_nAttempt
118  << ", rate=" << station->m_currentRate << ", power=" << (int)station->m_currentPower);
119 
120  return station;
121 }
122 
123 void
125 {
126  if (!station->m_initialized)
127  {
128  station->m_nSupported = GetNSupported (station);
129  station->m_currentRate = station->m_nSupported - 1;
130  station->m_currentPower = m_maxPower;
131  m_powerChange (station->m_currentPower, station->m_state->m_address);
132  m_rateChange (station->m_currentRate, station->m_state->m_address);
133  station->m_initialized = true;
134  }
135 }
136 
137 void
139 {
140  NS_LOG_FUNCTION (this << station);
141 }
142 
153 void
155 {
156  NS_LOG_FUNCTION (this << st);
158  CheckInit (station);
159  station->m_nAttempt++;
160  station->m_nFail++;
161  station->m_nRetry++;
162  station->m_nSuccess = 0;
163 
164  NS_LOG_DEBUG ("station=" << station << " data fail retry=" << station->m_nRetry << ", timer=" << station->m_nAttempt
165  << ", rate=" << station->m_currentRate << ", power=" << (int)station->m_currentPower);
166  if (station->m_usingRecoveryRate)
167  {
168  NS_ASSERT (station->m_nRetry >= 1);
169  if (station->m_nRetry == 1)
170  {
171  //need recovery fallback
172  if (station->m_currentRate != 0)
173  {
174  NS_LOG_DEBUG ("station=" << station << " dec rate");
175  station->m_currentRate--;
176  m_rateChange (station->m_currentRate, station->m_state->m_address);
177  station->m_usingRecoveryRate = false;
178  }
179  }
180  station->m_nAttempt = 0;
181  }
182  else if (station->m_usingRecoveryPower)
183  {
184  NS_ASSERT (station->m_nRetry >= 1);
185  if (station->m_nRetry == 1)
186  {
187  //need recovery fallback
188  if (station->m_currentPower < m_maxPower)
189  {
190  NS_LOG_DEBUG ("station=" << station << " inc power");
191  station->m_currentPower++;
192  m_powerChange (station->m_currentPower, station->m_state->m_address);
193  station->m_usingRecoveryPower = false;
194  }
195  }
196  station->m_nAttempt = 0;
197  }
198  else
199  {
200  NS_ASSERT (station->m_nRetry >= 1);
201  if (((station->m_nRetry - 1) % 2) == 1)
202  {
203  //need normal fallback
204  if (station->m_currentPower == m_maxPower)
205  {
206  if (station->m_currentRate != 0)
207  {
208  NS_LOG_DEBUG ("station=" << station << " dec rate");
209  station->m_currentRate--;
210  m_rateChange (station->m_currentRate, station->m_state->m_address);
211  }
212  }
213  else
214  {
215  NS_LOG_DEBUG ("station=" << station << " inc power");
216  station->m_currentPower++;
217  m_powerChange (station->m_currentPower, station->m_state->m_address);
218  }
219  }
220  if (station->m_nRetry >= 2)
221  {
222  station->m_nAttempt = 0;
223  }
224  }
225 }
226 
227 void
229  double rxSnr, WifiMode txMode)
230 {
231  NS_LOG_FUNCTION (this << station << rxSnr << txMode);
232 }
233 
235  double ctsSnr, WifiMode ctsMode, double rtsSnr)
236 {
237  NS_LOG_FUNCTION (this << station << ctsSnr << ctsMode << rtsSnr);
238  NS_LOG_DEBUG ("station=" << station << " rts ok");
239 }
240 
242  double ackSnr, WifiMode ackMode, double dataSnr)
243 {
244  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
246  CheckInit (station);
247  station->m_nAttempt++;
248  station->m_nSuccess++;
249  station->m_nFail = 0;
250  station->m_usingRecoveryRate = false;
251  station->m_usingRecoveryPower = false;
252  station->m_nRetry = 0;
253  NS_LOG_DEBUG ("station=" << station << " data ok success=" << station->m_nSuccess << ", timer=" << station->m_nAttempt << ", rate=" << station->m_currentRate << ", power=" << (int)station->m_currentPower);
254  if ((station->m_nSuccess == m_successThreshold
255  || station->m_nAttempt == m_attemptThreshold)
256  && (station->m_currentRate < (station->m_state->m_operationalRateSet.size () - 1)))
257  {
258  NS_LOG_DEBUG ("station=" << station << " inc rate");
259  station->m_currentRate++;
260  m_rateChange (station->m_currentRate, station->m_state->m_address);
261  station->m_nAttempt = 0;
262  station->m_nSuccess = 0;
263  station->m_usingRecoveryRate = true;
264  }
265  else if (station->m_nSuccess == m_successThreshold || station->m_nAttempt == m_attemptThreshold)
266  {
267  //we are at the maximum rate, we decrease power
268  if (station->m_currentPower != m_minPower)
269  {
270  NS_LOG_DEBUG ("station=" << station << " dec power");
271  station->m_currentPower--;
272  m_powerChange (station->m_currentPower, station->m_state->m_address);
273  }
274  station->m_nAttempt = 0;
275  station->m_nSuccess = 0;
276  station->m_usingRecoveryPower = true;
277  }
278 }
279 
280 void
282 {
283  NS_LOG_FUNCTION (this << station);
284 }
285 
286 void
288 {
289  NS_LOG_FUNCTION (this << station);
290 }
291 
294 {
295  NS_LOG_FUNCTION (this << st);
297  uint32_t channelWidth = GetChannelWidth (station);
298  if (channelWidth > 20 && channelWidth != 22)
299  {
300  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
301  channelWidth = 20;
302  }
303  CheckInit (station);
304  return WifiTxVector (GetSupported (station, station->m_currentRate), station->m_currentPower, GetLongRetryCount (station), false, 1, 0, channelWidth, GetAggregation (station), false);
305 }
306 
309 {
310  NS_LOG_FUNCTION (this << st);
314  uint32_t channelWidth = GetChannelWidth (station);
315  if (channelWidth > 20 && channelWidth != 22)
316  {
317  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
318  channelWidth = 20;
319  }
320  WifiTxVector rtsTxVector;
321  if (GetUseNonErpProtection () == false)
322  {
323  rtsTxVector = WifiTxVector (GetSupported (station, 0), GetDefaultTxPowerLevel (), GetShortRetryCount (station), false, 1, 0, channelWidth, GetAggregation (station), false);
324  }
325  else
326  {
327  rtsTxVector = WifiTxVector (GetNonErpSupported (station, 0), GetDefaultTxPowerLevel (), GetShortRetryCount (station), false, 1, 0, channelWidth, GetAggregation (station), false);
328  }
329  return rtsTxVector;
330 }
331 
332 bool
334 {
335  NS_LOG_FUNCTION (this);
336  return true;
337 }
338 
339 void
341 {
342  //HT is not supported by this algorithm.
343  if (enable)
344  {
345  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HT rates");
346  }
347 }
348 
349 void
351 {
352  //VHT is not supported by this algorithm.
353  if (enable)
354  {
355  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support VHT rates");
356  }
357 }
358 
359 } //namespace ns3
uint32_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Hold per-remote-station state for PARF Wifi manager.
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...
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:44
uint32_t m_maxPower
Maximal power level.
bool GetUseNonErpProtection(void) const
Return whether the device supports protection of non-ERP stations.
#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:201
uint32_t m_currentRate
Current rate used by the remote station.
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
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:99
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
WifiMode GetSupported(const WifiRemoteStation *station, uint32_t i) const
Return whether mode associated with the specified station at the specified index. ...
virtual void DoReportDataFailed(WifiRemoteStation *station)
WifiRemoteStationState * m_state
Remote station state.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
virtual 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 SetVhtSupported(bool enable)
Enable or disable VHT capability support.
virtual 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.
virtual void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode)
This method is a pure virtual method that must be implemented by the sub-class.
tuple phy
Definition: third.py:86
virtual void SetHtSupported(bool enable)
Enable or disable HT capability support.
uint32_t m_successThreshold
The minimum number of successful transmissions to try a new power or rate.
virtual WifiRemoteStation * DoCreateStation(void) const
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...
virtual void DoReportRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
virtual void DoReportFinalDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
hold a list of per-remote-station state.
uint32_t m_minPower
Minimal power level.
TracedCallback< uint8_t, Mac48Address > m_powerChange
The trace source fired when the transmission power changes....
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual double GetTxPowerEnd(void) const
Return the maximum available transmission power level (dBm).
Definition: wifi-phy.cc:488
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.
uint32_t m_nSupported
Number of supported rates by the remote station.
uint32_t m_nRetry
Number of transmission retries.
TracedCallback< uint32_t, Mac48Address > m_rateChange
The trace source fired when the transmission rate changes.
uint32_t GetLongRetryCount(const WifiRemoteStation *station) const
Return the long retry limit of the given station.
static TypeId GetTypeId(void)
Register this type.
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:236
uint32_t m_nSuccess
Number of successful transmission attempts.
uint8_t m_currentPower
Current power used by the remote station.
uint32_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
virtual bool IsLowLatency(void) const
uint32_t GetShortRetryCount(const WifiRemoteStation *station) const
Return the short retry limit of the given station.
bool m_usingRecoveryRate
If using recovery rate.
virtual WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)
bool m_usingRecoveryPower
If using recovery power.
virtual WifiTxVector DoGetDataTxVector(WifiRemoteStation *station)
virtual 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:904
hold per-remote-station state.
uint32_t m_attemptThreshold
The minimum number of transmission attempts to try a new power or rate.
virtual double GetTxPowerStart(void) const
Return the minimum available transmission power level (dBm).
Definition: wifi-phy.cc:475