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/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::AparfWifiManager");
31 
32 namespace ns3 {
33 
40 struct
42 {
43  uint32_t m_nSuccess;
44  uint32_t m_nFailed;
45  uint32_t m_pCount;
46  uint32_t m_successThreshold;
47  uint32_t m_failThreshold;
48  uint32_t m_rate;
49  uint32_t m_rateCrit;
50  uint8_t m_power;
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 ("SuccessThreshold 1",
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 ("SuccessThreshold 2",
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 ("Power decrement step",
86  "Step size for decrement the power.",
87  UintegerValue (1),
89  MakeUintegerChecker<uint32_t> ())
90  .AddAttribute ("Power increment step",
91  "Step size for increment the power.",
92  UintegerValue (1),
94  MakeUintegerChecker<uint32_t> ())
95  .AddAttribute ("Rate decrement step",
96  "Step size for decrement the rate.",
97  UintegerValue (1),
99  MakeUintegerChecker<uint32_t> ())
100  .AddAttribute ("Rate increment step",
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_rate
150  << ", power=" << (int)station->m_power);
151 
152  return station;
153 }
154 
155 void
157 {
158  if (!station->m_initialized)
159  {
160  station->m_nSupported = GetNSupported (station);
161  station->m_rate = station->m_nSupported - 1;
162  station->m_power = m_maxPower;
163  station->m_rateCrit = 0;
164  m_powerChange (station->m_power, station->m_state->m_address);
165  m_rateChange (station->m_rate, station->m_state->m_address);
166  station->m_initialized = true;
167  }
168 }
169 
171 {
172  NS_LOG_FUNCTION (this << station);
173 }
174 
176 {
177  NS_LOG_FUNCTION (this << st);
179  CheckInit (station);
180  station->m_nFailed++;
181  station->m_nSuccess = 0;
182  NS_LOG_DEBUG ("station=" << station << ", rate=" << station->m_rate
183  << ", power=" << (int)station->m_power);
184 
185  if (station->m_aparfState == AparfWifiManager::Low)
186  {
188  station->m_successThreshold = m_succesMax1;
189  }
190  else if (station->m_aparfState == AparfWifiManager::Spread)
191  {
193  station->m_successThreshold = m_succesMax2;
194  }
195 
196  if (station->m_nFailed == station->m_failThreshold)
197  {
198  station->m_nFailed = 0;
199  station->m_nSuccess = 0;
200  station->m_pCount = 0;
201  if (station->m_power == m_maxPower)
202  {
203  station->m_rateCrit = station->m_rate;
204  if (station->m_rate != 0)
205  {
206  NS_LOG_DEBUG ("station=" << station << " dec rate");
207  station->m_rate -= m_rateDec;
208  m_rateChange (station->m_rate, station->m_state->m_address);
209  }
210  }
211  else
212  {
213  NS_LOG_DEBUG ("station=" << station << " inc power");
214  station->m_power += m_powerInc;
215  m_powerChange (station->m_power, station->m_state->m_address);
216  }
217  }
218 }
219 
220 void
222 {
223  NS_LOG_FUNCTION (this << station << rxSnr << txMode);
224 }
225 
226 void
228  WifiMode ctsMode, double rtsSnr)
229 {
230  NS_LOG_FUNCTION (this << station << ctsSnr << ctsMode << rtsSnr);
231  NS_LOG_DEBUG ("station=" << station << " rts ok");
232 }
233 
234 void
236  WifiMode ackMode, double dataSnr)
237 {
238  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
240  CheckInit (station);
241  station->m_nSuccess++;
242  station->m_nFailed = 0;
243  NS_LOG_DEBUG ("station=" << station << " data ok success=" << station->m_nSuccess << ", rate=" << station->m_rate << ", power=" << (int)station->m_power);
244 
245  if ((station->m_aparfState == AparfWifiManager::High) && (station->m_nSuccess >= station->m_successThreshold))
246  {
248  }
249  else if ((station->m_aparfState == AparfWifiManager::Low) && (station->m_nSuccess >= station->m_successThreshold))
250  {
252  }
253  else if (station->m_aparfState == AparfWifiManager::Spread)
254  {
256  station->m_successThreshold = m_succesMax1;
257  }
258 
259  if (station->m_nSuccess == station->m_successThreshold)
260  {
261  station->m_nSuccess = 0;
262  station->m_nFailed = 0;
263  if (station->m_rate == (station->m_state->m_operationalRateSet.size () - 1))
264  {
265  if (station->m_power != m_minPower)
266  {
267  NS_LOG_DEBUG ("station=" << station << " dec power");
268  station->m_power -= m_powerDec;
269  m_powerChange (station->m_power, station->m_state->m_address);
270  }
271  }
272  else
273  {
274  if (station->m_rateCrit == 0)
275  {
276  if (station->m_rate != (station->m_state->m_operationalRateSet.size () - 1))
277  {
278  NS_LOG_DEBUG ("station=" << station << " inc rate");
279  station->m_rate += m_rateInc;
280  m_rateChange (station->m_rate, station->m_state->m_address);
281  }
282  }
283  else
284  {
285  if (station->m_pCount == m_powerMax)
286  {
287  station->m_power = m_maxPower;
288  m_powerChange (station->m_power, station->m_state->m_address);
289  station->m_rate = station->m_rateCrit;
290  m_rateChange (station->m_rate, station->m_state->m_address);
291  station->m_pCount = 0;
292  station->m_rateCrit = 0;
293  }
294  else
295  {
296  if (station->m_power != m_minPower)
297  {
298  station->m_power -= m_powerDec;
299  m_powerChange (station->m_power, station->m_state->m_address);
300  station->m_pCount++;
301  }
302  }
303  }
304  }
305  }
306 }
307 
308 void
310 {
311  NS_LOG_FUNCTION (this << station);
312 }
313 
314 void
316 {
317  NS_LOG_FUNCTION (this << station);
318 }
319 
322 {
323  NS_LOG_FUNCTION (this << st << size);
325  uint32_t channelWidth = GetChannelWidth (station);
326  if (channelWidth > 20 && channelWidth != 22)
327  {
328  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
329  channelWidth = 20;
330  }
331  CheckInit (station);
332  return WifiTxVector (GetSupported (station, station->m_rate), station->m_power, GetLongRetryCount (station), false, 1, 0, channelWidth, GetAggregation (station), false);
333 }
334 
337 {
338  NS_LOG_FUNCTION (this << st);
342  uint32_t channelWidth = GetChannelWidth (station);
343  if (channelWidth > 20 && channelWidth != 22)
344  {
345  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
346  channelWidth = 20;
347  }
348  return WifiTxVector (GetSupported (station, 0), GetDefaultTxPowerLevel (), GetShortRetryCount (station), false, 1, 0, channelWidth, GetAggregation (station), false);
349 }
350 
351 bool
353 {
354  NS_LOG_FUNCTION (this);
355  return true;
356 }
357 
358 } //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.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
virtual 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...
virtual 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.
static TypeId GetTypeId(void)
Register this type.
#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.
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. ...
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.
uint32_t m_powerInc
Step size for increment the power.
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.
TracedCallback< uint32_t, Mac48Address > m_rateChange
The trace source fired when the transmission rate change.
uint32_t m_maxPower
Maximal power level.
tuple phy
Definition: third.py:86
virtual WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, uint32_t size)
Hold an unsigned integer type.
Definition: uinteger.h:44
uint32_t m_nFailed
Number of failed transmission attempts.
void CheckInit(AparfWifiRemoteStation *station)
Check for initializations.
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 WifiRemoteStation * DoCreateStation(void) const
hold a list of per-remote-station state.
virtual 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.
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...
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.
uint32_t m_rateCrit
Critical rate.
virtual void DoReportFinalRtsFailed(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.
State
Enumeration of the possible states of the channel.
virtual WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)
virtual double GetTxPowerEnd(void) const =0
Return the maximum available transmission power level (dBm).
virtual 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...
virtual double GetTxPowerStart(void) const =0
Return the minimum available transmission power level (dBm).
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:236
uint32_t m_pCount
Number of power changes.
TracedCallback< uint8_t, Mac48Address > m_powerChange
The trace source fired when the transmission power change.
uint32_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
uint32_t GetShortRetryCount(const WifiRemoteStation *station) const
Return the short retry limit of the given station.
uint32_t m_rate
Current rate.
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:826
hold per-remote-station state.
uint8_t m_power
Current power.