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 #include "aparf-wifi-manager.h"
21 #include "wifi-phy.h"
22 #include "ns3/assert.h"
23 #include "ns3/log.h"
24 #include "ns3/uinteger.h"
25 #include "ns3/trace-source-accessor.h"
26 #define Min(a,b) ((a < b) ? a : b)
27 NS_LOG_COMPONENT_DEFINE ("ns3::AparfWifiManager");
28 
29 namespace ns3 {
30 
37 struct
39 {
40  uint32_t m_nSuccess;
41  uint32_t m_nFailed;
42  uint32_t m_pCount;
43 
44  uint32_t m_successThreshold;
45  uint32_t m_failThreshold;
46 
47  uint32_t m_rate;
48  uint32_t m_rateCrit;
49  uint8_t m_power;
50 
51  uint32_t m_nSupported;
53 
55 };
56 
58 
59 TypeId
61 {
62  static TypeId tid = TypeId ("ns3::AparfWifiManager")
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::AparfWifiManager::PowerChangeTracedCallback")
109  .AddTraceSource ("RateChange",
110  "The transmission rate has change",
112  "ns3::AparfWifiManager::RateChangeTracedCallback")
113  ;
114  return tid;
115 }
116 
118 {
119  NS_LOG_FUNCTION (this);
120 }
122 {
123  NS_LOG_FUNCTION (this);
124 }
125 
126 void
128 {
129  m_nPower = phy->GetNTxPower ();
131 }
132 
135 {
136  NS_LOG_FUNCTION (this);
138 
139  station->m_successThreshold = m_succesMax1;
140  station->m_failThreshold = m_failMax;
141  station->m_nSuccess = 0;
142  station->m_nFailed = 0;
143  station->m_pCount = 0;
145  station->m_initialized = false;
146 
147  NS_LOG_DEBUG ("create station=" << station << ", rate=" << station->m_rate
148  << ", power=" << (int)station->m_power);
149 
150  return station;
151 }
152 
153 void
155 {
156  if (!station->m_initialized)
157  {
158  station->m_nSupported = GetNSupported (station);
159  station->m_rate = station->m_nSupported - 1;
160  station->m_power = m_nPower - 1;
161  station->m_rateCrit = 0;
162  m_powerChange (station->m_power, station->m_state->m_address);
163  m_rateChange (station->m_rate, station->m_state->m_address);
164  station->m_initialized = true;
165  }
166 }
167 
169 {
170  NS_LOG_FUNCTION (this << station);
171 }
172 
174 {
175  NS_LOG_FUNCTION (this << st);
177  CheckInit (station);
178  station->m_nFailed++;
179  station->m_nSuccess = 0;
180  NS_LOG_DEBUG ("station=" << station << ", rate=" << station->m_rate
181  << ", power=" << (int)station->m_power);
182 
183  if (station->m_aparfState == AparfWifiManager::Low)
184  {
186  station->m_successThreshold = m_succesMax1;
187  }
188  else if (station->m_aparfState == AparfWifiManager::Spread)
189  {
191  station->m_successThreshold = m_succesMax2;
192  }
193 
194  if (station->m_nFailed == station->m_failThreshold)
195  {
196  station->m_nFailed = 0;
197  station->m_nSuccess = 0;
198  station->m_pCount = 0;
199  if (station->m_power == (m_nPower - 1))
200  {
201  station->m_rateCrit = station->m_rate;
202  if (station->m_rate != 0)
203  {
204  NS_LOG_DEBUG ("station=" << station << " dec rate");
205  station->m_rate -= m_rateDec;
206  m_rateChange (station->m_rate, station->m_state->m_address);
207  }
208  }
209  else
210  {
211  NS_LOG_DEBUG ("station=" << station << " inc power");
212  station->m_power += m_powerInc;
213  m_powerChange (station->m_power, station->m_state->m_address);
214  }
215  }
216 }
217 void
219 {
220  NS_LOG_FUNCTION (this << station << rxSnr << txMode);
221 }
222 void
224  WifiMode ctsMode, double rtsSnr)
225 {
226  NS_LOG_FUNCTION (this << station << ctsSnr << ctsMode << rtsSnr);
227  NS_LOG_DEBUG ("station=" << station << " rts ok");
228 }
229 void
231  WifiMode ackMode, double dataSnr)
232 {
233  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
235  CheckInit (station);
236  station->m_nSuccess++;
237  station->m_nFailed = 0;
238  NS_LOG_DEBUG ("station=" << station << " data ok success=" << station->m_nSuccess << ", rate=" << station->m_rate << ", power=" << (int)station->m_power);
239 
240  if ((station->m_aparfState == AparfWifiManager::High) && (station->m_nSuccess >= station->m_successThreshold))
241  {
243  }
244  else if ((station->m_aparfState == AparfWifiManager::Low) && (station->m_nSuccess >= station->m_successThreshold))
245  {
247  }
248  else if (station->m_aparfState == AparfWifiManager::Spread)
249  {
251  station->m_successThreshold = m_succesMax1;
252  }
253 
254  if (station->m_nSuccess == station->m_successThreshold)
255  {
256  station->m_nSuccess = 0;
257  station->m_nFailed = 0;
258  if (station->m_rate == (station->m_state->m_operationalRateSet.size () - 1))
259  {
260  if (station->m_power != 0)
261  {
262  NS_LOG_DEBUG ("station=" << station << " dec power");
263  station->m_power -= m_powerDec;
264  m_powerChange (station->m_power, station->m_state->m_address);
265  }
266  }
267  else
268  {
269  if (station->m_rateCrit == 0)
270  {
271  if (station->m_rate != (station->m_state->m_operationalRateSet.size () - 1))
272  {
273  NS_LOG_DEBUG ("station=" << station << " inc rate");
274  station->m_rate += m_rateInc;
275  m_rateChange (station->m_rate, station->m_state->m_address);
276  }
277  }
278  else
279  {
280  if (station->m_pCount == m_powerMax)
281  {
282  station->m_power = (m_nPower - 1);
283  m_powerChange (station->m_power, station->m_state->m_address);
284  station->m_rate = station->m_rateCrit;
285  m_rateChange (station->m_rate, station->m_state->m_address);
286  station->m_pCount = 0;
287  station->m_rateCrit = 0;
288  }
289  else
290  {
291  if (station->m_power != 0)
292  {
293  station->m_power -= m_powerDec;
294  m_powerChange (station->m_power, station->m_state->m_address);
295  station->m_pCount++;
296  }
297  }
298  }
299  }
300  }
301 }
302 void
304 {
305  NS_LOG_FUNCTION (this << station);
306 }
307 void
309 {
310  NS_LOG_FUNCTION (this << station);
311 }
312 
315 {
316  NS_LOG_FUNCTION (this << st << size);
318  CheckInit (station);
319  return WifiTxVector (GetSupported (station, station->m_rate), station->m_power, GetLongRetryCount (station), GetShortGuardInterval (station), Min (GetNumberOfReceiveAntennas (station),GetNumberOfTransmitAntennas ()), GetNumberOfTransmitAntennas (station), GetStbc (station));
320 }
323 {
324  NS_LOG_FUNCTION (this << st);
329 }
330 
331 bool
333 {
334  NS_LOG_FUNCTION (this);
335  return true;
336 }
337 
338 } // 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.
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:93
uint32_t GetNumberOfReceiveAntennas(const WifiRemoteStation *station) const
Return the number of receive antenna the station has.
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.
bool GetStbc(const WifiRemoteStation *station) const
Return whether the given station supports space-time block coding (STBC).
int64x64_t Min(const int64x64_t &a, const int64x64_t &b)
Minimum.
Definition: int64x64.h:191
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.
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.
bool GetShortGuardInterval(const WifiRemoteStation *station) const
Return whether the given station supports short guard interval.
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 void DoReportDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
uint32_t m_nPower
Number of power levels.
uint32_t m_succesMax1
The minimum number of successful transmissions in "High" state to try a new power or rate...
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.
virtual uint32_t GetNTxPower(void) const =0
#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 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:51
TypeId SetParent(TypeId tid)
Definition: type-id.cc:631
hold per-remote-station state.
uint8_t m_power
Current power.