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  .SetGroupName ("Wifi")
66  .AddConstructor<ParfWifiManager> ()
67  .AddAttribute ("AttemptThreshold",
68  "The minimum number of transmission attempts to try a new power or rate.",
69  UintegerValue (15),
71  MakeUintegerChecker<uint32_t> ())
72  .AddAttribute ("SuccessThreshold",
73  "The minimum number of successful transmissions to try a new power or rate.",
74  UintegerValue (10),
76  MakeUintegerChecker<uint32_t> ())
77  .AddTraceSource ("PowerChange",
78  "The transmission power has change",
80  "ns3::ParfWifiManager::PowerChangeTracedCallback")
81  .AddTraceSource ("RateChange",
82  "The transmission rate has change",
84  "ns3::ParfWifiManager::RateChangeTracedCallback")
85  ;
86  return tid;
87 }
88 
90 {
91  NS_LOG_FUNCTION (this);
92 }
94 {
95  NS_LOG_FUNCTION (this);
96 }
97 
98 void
100 {
101  m_nPower = phy->GetNTxPower ();
103 }
104 
107 {
108  NS_LOG_FUNCTION (this);
110 
111  station->m_nSuccess = 0;
112  station->m_nFail = 0;
113  station->m_usingRecoveryRate = false;
114  station->m_usingRecoveryPower = false;
115  station->m_initialized = false;
116  station->m_nRetry = 0;
117  station->m_nAttempt = 0;
118 
119  NS_LOG_DEBUG ("create station=" << station << ", timer=" << station->m_nAttempt
120  << ", rate=" << station->m_currentRate << ", power=" << (int)station->m_currentPower);
121 
122  return station;
123 }
124 
125 void
127 {
128  if (!station->m_initialized)
129  {
130  station->m_nSupported = GetNSupported (station);
131  station->m_currentRate = station->m_nSupported - 1;
132  station->m_currentPower = m_nPower - 1;
133  m_powerChange (station->m_currentPower, station->m_state->m_address);
134  m_rateChange (station->m_currentRate, station->m_state->m_address);
135  station->m_initialized = true;
136  }
137 }
138 
139 void
141 {
142  NS_LOG_FUNCTION (this << station);
143 }
154 void
156 {
157  NS_LOG_FUNCTION (this << st);
159  CheckInit (station);
160  station->m_nAttempt++;
161  station->m_nFail++;
162  station->m_nRetry++;
163  station->m_nSuccess = 0;
164 
165  NS_LOG_DEBUG ("station=" << station << " data fail retry=" << station->m_nRetry << ", timer=" << station->m_nAttempt
166  << ", rate=" << station->m_currentRate << ", power=" << (int)station->m_currentPower);
167  if (station->m_usingRecoveryRate)
168  {
169  NS_ASSERT (station->m_nRetry >= 1);
170  if (station->m_nRetry == 1)
171  {
172  // need recovery fallback
173  if (station->m_currentRate != 0)
174  {
175  NS_LOG_DEBUG ("station=" << station << " dec rate");
176  station->m_currentRate--;
177  m_rateChange (station->m_currentRate, station->m_state->m_address);
178  station->m_usingRecoveryRate = false;
179  }
180  }
181  station->m_nAttempt = 0;
182  }
183  else if (station->m_usingRecoveryPower)
184  {
185  NS_ASSERT (station->m_nRetry >= 1);
186  if (station->m_nRetry == 1)
187  {
188  // need recovery fallback
189  if (station->m_currentPower < m_nPower - 1)
190  {
191  NS_LOG_DEBUG ("station=" << station << " inc power");
192  station->m_currentPower++;
193  m_powerChange (station->m_currentPower, station->m_state->m_address);
194  station->m_usingRecoveryPower = false;
195  }
196  }
197  station->m_nAttempt = 0;
198  }
199  else
200  {
201  NS_ASSERT (station->m_nRetry >= 1);
202  if (((station->m_nRetry - 1) % 2) == 1)
203  {
204  // need normal fallback
205  if (station->m_currentPower == m_nPower - 1)
206  {
207  if (station->m_currentRate != 0)
208  {
209  NS_LOG_DEBUG ("station=" << station << " dec rate");
210  station->m_currentRate--;
211  m_rateChange (station->m_currentRate, station->m_state->m_address);
212  }
213  }
214  else
215  {
216  NS_LOG_DEBUG ("station=" << station << " inc power");
217  station->m_currentPower++;
218  m_powerChange (station->m_currentPower, station->m_state->m_address);
219  }
220  }
221  if (station->m_nRetry >= 2)
222  {
223  station->m_nAttempt = 0;
224  }
225  }
226 }
227 void
229  double rxSnr, WifiMode txMode)
230 {
231  NS_LOG_FUNCTION (this << station << rxSnr << txMode);
232 }
234  double ctsSnr, WifiMode ctsMode, double rtsSnr)
235 {
236  NS_LOG_FUNCTION (this << station << ctsSnr << ctsMode << rtsSnr);
237  NS_LOG_DEBUG ("station=" << station << " rts ok");
238 }
240  double ackSnr, WifiMode ackMode, double dataSnr)
241 {
242  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
244  CheckInit (station);
245  station->m_nAttempt++;
246  station->m_nSuccess++;
247  station->m_nFail = 0;
248  station->m_usingRecoveryRate = false;
249  station->m_usingRecoveryPower = false;
250  station->m_nRetry = 0;
251  NS_LOG_DEBUG ("station=" << station << " data ok success=" << station->m_nSuccess << ", timer=" << station->m_nAttempt << ", rate=" << station->m_currentRate << ", power=" << (int)station->m_currentPower);
252  if ((station->m_nSuccess == m_successThreshold
253  || station->m_nAttempt == m_attemptThreshold)
254  && (station->m_currentRate < (station->m_state->m_operationalRateSet.size () - 1)))
255  {
256  NS_LOG_DEBUG ("station=" << station << " inc rate");
257  station->m_currentRate++;
258  m_rateChange (station->m_currentRate, station->m_state->m_address);
259  station->m_nAttempt = 0;
260  station->m_nSuccess = 0;
261  station->m_usingRecoveryRate = true;
262  }
263  else if (station->m_nSuccess == m_successThreshold || station->m_nAttempt == m_attemptThreshold)
264  {
265  //we are at the maximum rate, we decrease power
266  if (station->m_currentPower != 0)
267  {
268  NS_LOG_DEBUG ("station=" << station << " dec power");
269  station->m_currentPower--;
270  m_powerChange (station->m_currentPower, station->m_state->m_address);
271  }
272  station->m_nAttempt = 0;
273  station->m_nSuccess = 0;
274  station->m_usingRecoveryPower = true;
275  }
276 }
277 void
279 {
280  NS_LOG_FUNCTION (this << station);
281 }
282 void
284 {
285  NS_LOG_FUNCTION (this << station);
286 }
287 
290 {
291  NS_LOG_FUNCTION (this << st << size);
293  CheckInit (station);
295 }
298 {
299  NS_LOG_FUNCTION (this << st);
304 }
305 
306 bool
308 {
309  NS_LOG_FUNCTION (this);
310  return true;
311 }
312 } // 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: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.
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: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.
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:57
TypeId SetParent(TypeId tid)
Definition: type-id.cc:638
hold per-remote-station state.
uint32_t m_attemptThreshold
The minimum number of transmission attempts to try a new power or rate.