A Discrete-Event Network Simulator
API
arf-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) 2004,2005,2006 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 #include "ns3/log.h"
22 #include "arf-wifi-manager.h"
23 #include "wifi-tx-vector.h"
24 
25 #define Min(a,b) ((a < b) ? a : b)
26 
27 namespace ns3 {
28 
29 NS_LOG_COMPONENT_DEFINE ("ArfWifiManager");
30 
38 {
39  uint32_t m_timer;
40  uint32_t m_success;
41  uint32_t m_failed;
42  bool m_recovery;
43  uint32_t m_retry;
44  uint32_t m_timerTimeout;
45  uint32_t m_successThreshold;
46  uint8_t m_rate;
47 };
48 
50 
51 TypeId
53 {
54  static TypeId tid = TypeId ("ns3::ArfWifiManager")
56  .SetGroupName ("Wifi")
57  .AddConstructor<ArfWifiManager> ()
58  .AddAttribute ("TimerThreshold", "The 'timer' threshold in the ARF algorithm.",
59  UintegerValue (15),
61  MakeUintegerChecker<uint32_t> ())
62  .AddAttribute ("SuccessThreshold",
63  "The minimum number of successful transmissions to try a new rate.",
64  UintegerValue (10),
66  MakeUintegerChecker<uint32_t> ())
67  .AddTraceSource ("Rate",
68  "Traced value for rate changes (b/s)",
70  "ns3::TracedValueCallback::Uint64")
71  ;
72  return tid;
73 }
74 
77  m_currentRate (0)
78 {
79  NS_LOG_FUNCTION (this);
80 }
81 
83 {
84  NS_LOG_FUNCTION (this);
85 }
86 
87 void
89 {
90  NS_LOG_FUNCTION (this);
91  if (GetHtSupported ())
92  {
93  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HT rates");
94  }
95  if (GetVhtSupported ())
96  {
97  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support VHT rates");
98  }
99  if (GetHeSupported ())
100  {
101  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HE rates");
102  }
103 }
104 
107 {
108  NS_LOG_FUNCTION (this);
109  ArfWifiRemoteStation *station = new ArfWifiRemoteStation ();
110 
112  station->m_timerTimeout = m_timerThreshold;
113  station->m_rate = 0;
114  station->m_success = 0;
115  station->m_failed = 0;
116  station->m_recovery = false;
117  station->m_retry = 0;
118  station->m_timer = 0;
119 
120  return station;
121 }
122 
123 void
125 {
126  NS_LOG_FUNCTION (this << station);
127 }
128 
140 void
142 {
143  NS_LOG_FUNCTION (this << st);
145  station->m_timer++;
146  station->m_failed++;
147  station->m_retry++;
148  station->m_success = 0;
149 
150  if (station->m_recovery)
151  {
152  NS_ASSERT (station->m_retry >= 1);
153  if (station->m_retry == 1)
154  {
155  //need recovery fallback
156  if (station->m_rate != 0)
157  {
158  station->m_rate--;
159  }
160  }
161  station->m_timer = 0;
162  }
163  else
164  {
165  NS_ASSERT (station->m_retry >= 1);
166  if (((station->m_retry - 1) % 2) == 1)
167  {
168  //need normal fallback
169  if (station->m_rate != 0)
170  {
171  station->m_rate--;
172  }
173  }
174  if (station->m_retry >= 2)
175  {
176  station->m_timer = 0;
177  }
178  }
179 }
180 
181 void
183  double rxSnr, WifiMode txMode)
184 {
185  NS_LOG_FUNCTION (this << station << rxSnr << txMode);
186 }
187 
189  double ctsSnr, WifiMode ctsMode, double rtsSnr)
190 {
191  NS_LOG_FUNCTION (this << station << ctsSnr << ctsMode << rtsSnr);
192  NS_LOG_DEBUG ("station=" << station << " rts ok");
193 }
194 
196  double ackSnr, WifiMode ackMode, double dataSnr)
197 {
198  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
199  ArfWifiRemoteStation *station = (ArfWifiRemoteStation *) st;
200  station->m_timer++;
201  station->m_success++;
202  station->m_failed = 0;
203  station->m_recovery = false;
204  station->m_retry = 0;
205  NS_LOG_DEBUG ("station=" << station << " data ok success=" << station->m_success << ", timer=" << station->m_timer);
206  if ((station->m_success == m_successThreshold
207  || station->m_timer == m_timerThreshold)
208  && (station->m_rate < (station->m_state->m_operationalRateSet.size () - 1)))
209  {
210  NS_LOG_DEBUG ("station=" << station << " inc rate");
211  station->m_rate++;
212  station->m_timer = 0;
213  station->m_success = 0;
214  station->m_recovery = true;
215  }
216 }
217 
218 void
220 {
221  NS_LOG_FUNCTION (this << station);
222 }
223 
224 void
226 {
227  NS_LOG_FUNCTION (this << station);
228 }
229 
232 {
233  NS_LOG_FUNCTION (this << st);
234  ArfWifiRemoteStation *station = (ArfWifiRemoteStation *) st;
235  uint16_t channelWidth = GetChannelWidth (station);
236  if (channelWidth > 20 && channelWidth != 22)
237  {
238  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
239  channelWidth = 20;
240  }
241  WifiMode mode = GetSupported (station, station->m_rate);
242  if (m_currentRate != mode.GetDataRate (channelWidth))
243  {
244  NS_LOG_DEBUG ("New datarate: " << mode.GetDataRate (channelWidth));
245  m_currentRate = mode.GetDataRate (channelWidth);
246  }
247  return WifiTxVector (mode, GetDefaultTxPowerLevel (), GetPreambleForTransmission (mode.GetModulationClass (), GetShortPreambleEnabled (), UseGreenfieldForDestination (GetAddress (station))), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
248 }
249 
252 {
253  NS_LOG_FUNCTION (this << st);
256  ArfWifiRemoteStation *station = (ArfWifiRemoteStation *) st;
257  uint16_t channelWidth = GetChannelWidth (station);
258  if (channelWidth > 20 && channelWidth != 22)
259  {
260  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
261  channelWidth = 20;
262  }
263  WifiTxVector rtsTxVector;
264  WifiMode mode;
265  if (GetUseNonErpProtection () == false)
266  {
267  mode = GetSupported (station, 0);
268  }
269  else
270  {
271  mode = GetNonErpSupported (station, 0);
272  }
273  rtsTxVector = WifiTxVector (mode, GetDefaultTxPowerLevel (), GetPreambleForTransmission (mode.GetModulationClass (), GetShortPreambleEnabled (), UseGreenfieldForDestination (GetAddress (station))), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
274  return rtsTxVector;
275 }
276 
277 bool
279 {
280  return true;
281 }
282 
283 } //namespace ns3
bool GetVhtSupported(void) const
Return whether the device has VHT capability support enabled.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
uint32_t m_retry
retry count
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
uint32_t m_timerThreshold
timer threshold
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
void DoInitialize(void)
Initialize() implementation.
void DoReportRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
bool GetHeSupported(void) const
Return whether the device has HE capability support enabled.
#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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:204
uint32_t m_success
success count
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
uint32_t m_timerTimeout
timer timeout
WifiPreamble GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble, bool useGreenfield)
Return the preamble to be used for the transmission.
Definition: wifi-utils.cc:128
WifiMode GetSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether mode associated with the specified station at the specified index. ...
hold per-remote-station state for ARF Wifi manager.
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:97
static TypeId GetTypeId(void)
Get the type ID.
WifiRemoteStationState * m_state
Remote station state.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
bool GetShortPreambleEnabled(void) const
Return whether the device uses short PLCP preambles.
void DoReportFinalDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
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.
Hold an unsigned integer type.
Definition: uinteger.h:44
bool GetHtSupported(void) const
Return whether the device has HT capability support enabled.
uint32_t m_successThreshold
success threshold
hold a list of per-remote-station state.
void DoReportDataFailed(WifiRemoteStation *station)
It is important to realize that "recovery" mode starts after failure of the first transmission after ...
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:494
TracedValue< uint64_t > m_currentRate
Trace rate changes.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint32_t m_failed
failed count
WifiModeList m_operationalRateSet
This member is the list of WifiMode objects that comprise the OperationalRateSet parameter for this r...
bool UseGreenfieldForDestination(Mac48Address dest) const
Mac48Address GetAddress(const WifiRemoteStation *station) const
Return the address of the station.
WifiMode GetNonErpSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether non-ERP mode associated with the specified station at the specified index...
void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode)
This method is a pure virtual method that must be implemented by the sub-class.
ARF Rate control algorithm.
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
bool IsLowLatency(void) const
bool GetUseNonErpProtection(void) const
Return whether the device supports protection of non-ERP stations.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:272
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station)
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:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
hold per-remote-station state.
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:150
WifiRemoteStation * DoCreateStation(void) const
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.
uint32_t m_timer
timer value
uint32_t m_successThreshold
success threshold
uint16_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.