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  .SetGroupName ("Wifi")
65  .AddConstructor<AparfWifiManager> ()
66  .AddAttribute ("SuccessThreshold 1",
67  "The minimum number of successful transmissions in \"High\" state to try a new power or rate.",
68  UintegerValue (3),
70  MakeUintegerChecker<uint32_t> ())
71  .AddAttribute ("SuccessThreshold 2",
72  "The minimum number of successful transmissions in \"Low\" state to try a new power or rate.",
73  UintegerValue (10),
75  MakeUintegerChecker<uint32_t> ())
76  .AddAttribute ("FailThreshold",
77  "The minimum number of failed transmissions to try a new power or rate.",
78  UintegerValue (1),
80  MakeUintegerChecker<uint32_t> ())
81  .AddAttribute ("PowerThreshold",
82  "The maximum number of power changes.",
83  UintegerValue (10),
85  MakeUintegerChecker<uint32_t> ())
86  .AddAttribute ("Power decrement step",
87  "Step size for decrement the power.",
88  UintegerValue (1),
90  MakeUintegerChecker<uint32_t> ())
91  .AddAttribute ("Power increment step",
92  "Step size for increment the power.",
93  UintegerValue (1),
95  MakeUintegerChecker<uint32_t> ())
96  .AddAttribute ("Rate decrement step",
97  "Step size for decrement the rate.",
98  UintegerValue (1),
100  MakeUintegerChecker<uint32_t> ())
101  .AddAttribute ("Rate increment step",
102  "Step size for increment the rate.",
103  UintegerValue (1),
105  MakeUintegerChecker<uint32_t> ())
106  .AddTraceSource ("PowerChange",
107  "The transmission power has change",
109  "ns3::AparfWifiManager::PowerChangeTracedCallback")
110  .AddTraceSource ("RateChange",
111  "The transmission rate has change",
113  "ns3::AparfWifiManager::RateChangeTracedCallback")
114  ;
115  return tid;
116 }
117 
119 {
120  NS_LOG_FUNCTION (this);
121 }
123 {
124  NS_LOG_FUNCTION (this);
125 }
126 
127 void
129 {
130  m_nPower = phy->GetNTxPower ();
132 }
133 
136 {
137  NS_LOG_FUNCTION (this);
139 
140  station->m_successThreshold = m_succesMax1;
141  station->m_failThreshold = m_failMax;
142  station->m_nSuccess = 0;
143  station->m_nFailed = 0;
144  station->m_pCount = 0;
146  station->m_initialized = false;
147 
148  NS_LOG_DEBUG ("create station=" << station << ", rate=" << station->m_rate
149  << ", power=" << (int)station->m_power);
150 
151  return station;
152 }
153 
154 void
156 {
157  if (!station->m_initialized)
158  {
159  station->m_nSupported = GetNSupported (station);
160  station->m_rate = station->m_nSupported - 1;
161  station->m_power = m_nPower - 1;
162  station->m_rateCrit = 0;
163  m_powerChange (station->m_power, station->m_state->m_address);
164  m_rateChange (station->m_rate, station->m_state->m_address);
165  station->m_initialized = true;
166  }
167 }
168 
170 {
171  NS_LOG_FUNCTION (this << station);
172 }
173 
175 {
176  NS_LOG_FUNCTION (this << st);
178  CheckInit (station);
179  station->m_nFailed++;
180  station->m_nSuccess = 0;
181  NS_LOG_DEBUG ("station=" << station << ", rate=" << station->m_rate
182  << ", power=" << (int)station->m_power);
183 
184  if (station->m_aparfState == AparfWifiManager::Low)
185  {
187  station->m_successThreshold = m_succesMax1;
188  }
189  else if (station->m_aparfState == AparfWifiManager::Spread)
190  {
192  station->m_successThreshold = m_succesMax2;
193  }
194 
195  if (station->m_nFailed == station->m_failThreshold)
196  {
197  station->m_nFailed = 0;
198  station->m_nSuccess = 0;
199  station->m_pCount = 0;
200  if (station->m_power == (m_nPower - 1))
201  {
202  station->m_rateCrit = station->m_rate;
203  if (station->m_rate != 0)
204  {
205  NS_LOG_DEBUG ("station=" << station << " dec rate");
206  station->m_rate -= m_rateDec;
207  m_rateChange (station->m_rate, station->m_state->m_address);
208  }
209  }
210  else
211  {
212  NS_LOG_DEBUG ("station=" << station << " inc power");
213  station->m_power += m_powerInc;
214  m_powerChange (station->m_power, station->m_state->m_address);
215  }
216  }
217 }
218 void
220 {
221  NS_LOG_FUNCTION (this << station << rxSnr << txMode);
222 }
223 void
225  WifiMode ctsMode, double rtsSnr)
226 {
227  NS_LOG_FUNCTION (this << station << ctsSnr << ctsMode << rtsSnr);
228  NS_LOG_DEBUG ("station=" << station << " rts ok");
229 }
230 void
232  WifiMode ackMode, double dataSnr)
233 {
234  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
236  CheckInit (station);
237  station->m_nSuccess++;
238  station->m_nFailed = 0;
239  NS_LOG_DEBUG ("station=" << station << " data ok success=" << station->m_nSuccess << ", rate=" << station->m_rate << ", power=" << (int)station->m_power);
240 
241  if ((station->m_aparfState == AparfWifiManager::High) && (station->m_nSuccess >= station->m_successThreshold))
242  {
244  }
245  else if ((station->m_aparfState == AparfWifiManager::Low) && (station->m_nSuccess >= station->m_successThreshold))
246  {
248  }
249  else if (station->m_aparfState == AparfWifiManager::Spread)
250  {
252  station->m_successThreshold = m_succesMax1;
253  }
254 
255  if (station->m_nSuccess == station->m_successThreshold)
256  {
257  station->m_nSuccess = 0;
258  station->m_nFailed = 0;
259  if (station->m_rate == (station->m_state->m_operationalRateSet.size () - 1))
260  {
261  if (station->m_power != 0)
262  {
263  NS_LOG_DEBUG ("station=" << station << " dec power");
264  station->m_power -= m_powerDec;
265  m_powerChange (station->m_power, station->m_state->m_address);
266  }
267  }
268  else
269  {
270  if (station->m_rateCrit == 0)
271  {
272  if (station->m_rate != (station->m_state->m_operationalRateSet.size () - 1))
273  {
274  NS_LOG_DEBUG ("station=" << station << " inc rate");
275  station->m_rate += m_rateInc;
276  m_rateChange (station->m_rate, station->m_state->m_address);
277  }
278  }
279  else
280  {
281  if (station->m_pCount == m_powerMax)
282  {
283  station->m_power = (m_nPower - 1);
284  m_powerChange (station->m_power, station->m_state->m_address);
285  station->m_rate = station->m_rateCrit;
286  m_rateChange (station->m_rate, station->m_state->m_address);
287  station->m_pCount = 0;
288  station->m_rateCrit = 0;
289  }
290  else
291  {
292  if (station->m_power != 0)
293  {
294  station->m_power -= m_powerDec;
295  m_powerChange (station->m_power, station->m_state->m_address);
296  station->m_pCount++;
297  }
298  }
299  }
300  }
301  }
302 }
303 void
305 {
306  NS_LOG_FUNCTION (this << station);
307 }
308 void
310 {
311  NS_LOG_FUNCTION (this << station);
312 }
313 
316 {
317  NS_LOG_FUNCTION (this << st << size);
319  CheckInit (station);
320  return WifiTxVector (GetSupported (station, station->m_rate), station->m_power, GetLongRetryCount (station), GetShortGuardInterval (station), Min (GetNumberOfReceiveAntennas (station),GetNumberOfTransmitAntennas ()), GetNumberOfTransmitAntennas (station), GetStbc (station));
321 }
324 {
325  NS_LOG_FUNCTION (this << st);
330 }
331 
332 bool
334 {
335  NS_LOG_FUNCTION (this);
336  return true;
337 }
338 
339 } // 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:197
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:57
TypeId SetParent(TypeId tid)
Definition: type-id.cc:638
hold per-remote-station state.
uint8_t m_power
Current power.