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 
33 namespace ns3 {
34 
42 {
43  uint32_t m_nAttempt;
44  uint32_t m_nSuccess;
45  uint32_t m_nFail;
48  uint32_t m_nRetry;
49 
50  uint32_t m_currentRate;
51 
52  uint8_t m_currentPower;
53 
54  uint32_t m_nSupported;
56 };
57 
59 
60 TypeId
62 {
63  static TypeId tid = TypeId ("ns3::ParfWifiManager")
65  .AddConstructor<ParfWifiManager> ()
66  .AddAttribute ("AttemptThreshold",
67  "The minimum number of transmission attempts to try a new power or rate.",
68  UintegerValue (15),
70  MakeUintegerChecker<uint32_t> ())
71  .AddAttribute ("SuccessThreshold",
72  "The minimum number of successful transmissions to try a new power or rate.",
73  UintegerValue (10),
75  MakeUintegerChecker<uint32_t> ())
76  .AddTraceSource ("PowerChange",
77  "The transmission power has change",
79  "ns3::ParfWifiManager::PowerChangeTracedCallback")
80  .AddTraceSource ("RateChange",
81  "The transmission rate has change",
83  "ns3::ParfWifiManager::RateChangeTracedCallback")
84  ;
85  return tid;
86 }
87 
89 {
90  NS_LOG_FUNCTION (this);
91 }
93 {
94  NS_LOG_FUNCTION (this);
95 }
96 
97 void
99 {
100  m_nPower = phy->GetNTxPower ();
102 }
103 
106 {
107  NS_LOG_FUNCTION (this);
109 
110  station->m_nSuccess = 0;
111  station->m_nFail = 0;
112  station->m_usingRecoveryRate = false;
113  station->m_usingRecoveryPower = false;
114  station->m_initialized = false;
115  station->m_nRetry = 0;
116  station->m_nAttempt = 0;
117 
118  NS_LOG_DEBUG ("create station=" << station << ", timer=" << station->m_nAttempt
119  << ", rate=" << station->m_currentRate << ", power=" << (int)station->m_currentPower);
120 
121  return station;
122 }
123 
124 void
126 {
127  if (!station->m_initialized)
128  {
129  station->m_nSupported = GetNSupported (station);
130  station->m_currentRate = station->m_nSupported - 1;
131  station->m_currentPower = m_nPower - 1;
132  m_powerChange (station->m_currentPower, station->m_state->m_address);
133  m_rateChange (station->m_currentRate, station->m_state->m_address);
134  station->m_initialized = true;
135  }
136 }
137 
138 void
140 {
141  NS_LOG_FUNCTION (this << station);
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_nPower - 1)
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_nPower - 1)
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 void
228  double rxSnr, WifiMode txMode)
229 {
230  NS_LOG_FUNCTION (this << station << rxSnr << txMode);
231 }
233  double ctsSnr, WifiMode ctsMode, double rtsSnr)
234 {
235  NS_LOG_FUNCTION (this << station << ctsSnr << ctsMode << rtsSnr);
236  NS_LOG_DEBUG ("station=" << station << " rts ok");
237 }
239  double ackSnr, WifiMode ackMode, double dataSnr)
240 {
241  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
243  CheckInit (station);
244  station->m_nAttempt++;
245  station->m_nSuccess++;
246  station->m_nFail = 0;
247  station->m_usingRecoveryRate = false;
248  station->m_usingRecoveryPower = false;
249  station->m_nRetry = 0;
250  NS_LOG_DEBUG ("station=" << station << " data ok success=" << station->m_nSuccess << ", timer=" << station->m_nAttempt << ", rate=" << station->m_currentRate << ", power=" << (int)station->m_currentPower);
251  if ((station->m_nSuccess == m_successThreshold
252  || station->m_nAttempt == m_attemptThreshold)
253  && (station->m_currentRate < (station->m_state->m_operationalRateSet.size () - 1)))
254  {
255  NS_LOG_DEBUG ("station=" << station << " inc rate");
256  station->m_currentRate++;
257  m_rateChange (station->m_currentRate, station->m_state->m_address);
258  station->m_nAttempt = 0;
259  station->m_nSuccess = 0;
260  station->m_usingRecoveryRate = true;
261  }
262  else if (station->m_nSuccess == m_successThreshold || station->m_nAttempt == m_attemptThreshold)
263  {
264  //we are at the maximum rate, we decrease power
265  if (station->m_currentPower != 0)
266  {
267  NS_LOG_DEBUG ("station=" << station << " dec power");
268  station->m_currentPower--;
269  m_powerChange (station->m_currentPower, station->m_state->m_address);
270  }
271  station->m_nAttempt = 0;
272  station->m_nSuccess = 0;
273  station->m_usingRecoveryPower = true;
274  }
275 }
276 void
278 {
279  NS_LOG_FUNCTION (this << station);
280 }
281 void
283 {
284  NS_LOG_FUNCTION (this << station);
285 }
286 
289 {
290  NS_LOG_FUNCTION (this << st << size);
292  CheckInit (station);
294 }
297 {
298  NS_LOG_FUNCTION (this << st);
303 }
304 
305 bool
307 {
308  NS_LOG_FUNCTION (this);
309  return true;
310 }
311 } // namespace ns3
uint32_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
virtual WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, uint32_t size)
#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
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
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.
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.
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.
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.
virtual void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode)
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.
virtual WifiRemoteStation * DoCreateStation(void) const
Hold an unsigned integer type.
Definition: uinteger.h:44
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.
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.
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.
bool GetShortGuardInterval(const WifiRemoteStation *station) const
Return whether the given station supports short guard interval.
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_nPower
Number of power levels.
uint32_t m_nFail
Number of failed transmission attempts.
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_nSuccess
Number of successful transmission attempts.
uint8_t m_currentPower
Current power used by the remote 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 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:51
TypeId SetParent(TypeId tid)
Definition: type-id.cc:631
hold per-remote-station state.
uint32_t m_attemptThreshold
The minimum number of transmission attempts to try a new power or rate.