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 "ns3/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_timerTimeout;
44  uint32_t m_successThreshold;
45  uint8_t m_rate;
46 };
47 
49 
50 TypeId
52 {
53  static TypeId tid = TypeId ("ns3::ArfWifiManager")
55  .SetGroupName ("Wifi")
56  .AddConstructor<ArfWifiManager> ()
57  .AddAttribute ("TimerThreshold", "The 'timer' threshold in the ARF algorithm.",
58  UintegerValue (15),
60  MakeUintegerChecker<uint32_t> ())
61  .AddAttribute ("SuccessThreshold",
62  "The minimum number of successful transmissions to try a new rate.",
63  UintegerValue (10),
65  MakeUintegerChecker<uint32_t> ())
66  .AddTraceSource ("Rate",
67  "Traced value for rate changes (b/s)",
69  "ns3::TracedValueCallback::Uint64")
70  ;
71  return tid;
72 }
73 
76  m_currentRate (0)
77 {
78  NS_LOG_FUNCTION (this);
79 }
80 
82 {
83  NS_LOG_FUNCTION (this);
84 }
85 
86 void
88 {
89  NS_LOG_FUNCTION (this);
90  if (GetHtSupported ())
91  {
92  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HT rates");
93  }
94  if (GetVhtSupported ())
95  {
96  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support VHT rates");
97  }
98  if (GetHeSupported ())
99  {
100  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HE rates");
101  }
102 }
103 
106 {
107  NS_LOG_FUNCTION (this);
108  ArfWifiRemoteStation *station = new ArfWifiRemoteStation ();
109 
111  station->m_timerTimeout = m_timerThreshold;
112  station->m_rate = 0;
113  station->m_success = 0;
114  station->m_failed = 0;
115  station->m_recovery = false;
116  station->m_timer = 0;
117 
118  return station;
119 }
120 
121 void
123 {
124  NS_LOG_FUNCTION (this << station);
125 }
126 
138 void
140 {
141  NS_LOG_FUNCTION (this << st);
142  ArfWifiRemoteStation *station = static_cast<ArfWifiRemoteStation*> (st);
143  station->m_timer++;
144  station->m_failed++;
145  station->m_success = 0;
146 
147  if (station->m_recovery)
148  {
149  NS_ASSERT (station->m_failed >= 1);
150  if (station->m_failed == 1)
151  {
152  //need recovery fallback
153  if (station->m_rate != 0)
154  {
155  station->m_rate--;
156  }
157  }
158  station->m_timer = 0;
159  }
160  else
161  {
162  NS_ASSERT (station->m_failed >= 1);
163  if (((station->m_failed - 1) % 2) == 1)
164  {
165  //need normal fallback
166  if (station->m_rate != 0)
167  {
168  station->m_rate--;
169  }
170  }
171  if (station->m_failed >= 2)
172  {
173  station->m_timer = 0;
174  }
175  }
176 }
177 
178 void
180  double rxSnr, WifiMode txMode)
181 {
182  NS_LOG_FUNCTION (this << station << rxSnr << txMode);
183 }
184 
186  double ctsSnr, WifiMode ctsMode, double rtsSnr)
187 {
188  NS_LOG_FUNCTION (this << station << ctsSnr << ctsMode << rtsSnr);
189  NS_LOG_DEBUG ("station=" << station << " rts ok");
190 }
191 
193  double dataSnr, uint16_t dataChannelWidth, uint8_t dataNss)
194 {
195  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr << dataChannelWidth << +dataNss);
196  ArfWifiRemoteStation *station = static_cast<ArfWifiRemoteStation*> (st);
197  station->m_timer++;
198  station->m_success++;
199  station->m_failed = 0;
200  station->m_recovery = false;
201  NS_LOG_DEBUG ("station=" << station << " data ok success=" << station->m_success << ", timer=" << station->m_timer);
202  if ((station->m_success == m_successThreshold
203  || station->m_timer == m_timerThreshold)
204  && (station->m_rate < (station->m_state->m_operationalRateSet.size () - 1)))
205  {
206  NS_LOG_DEBUG ("station=" << station << " inc rate");
207  station->m_rate++;
208  station->m_timer = 0;
209  station->m_success = 0;
210  station->m_recovery = true;
211  }
212 }
213 
214 void
216 {
217  NS_LOG_FUNCTION (this << station);
218 }
219 
220 void
222 {
223  NS_LOG_FUNCTION (this << station);
224 }
225 
228 {
229  NS_LOG_FUNCTION (this << st);
230  ArfWifiRemoteStation *station = static_cast<ArfWifiRemoteStation*> (st);
231  uint16_t channelWidth = GetChannelWidth (station);
232  if (channelWidth > 20 && channelWidth != 22)
233  {
234  channelWidth = 20;
235  }
236  WifiMode mode = GetSupported (station, station->m_rate);
237  uint64_t rate = mode.GetDataRate (channelWidth);
238  if (m_currentRate != rate)
239  {
240  NS_LOG_DEBUG ("New datarate: " << rate);
241  m_currentRate = rate;
242  }
243  return WifiTxVector (mode, GetDefaultTxPowerLevel (), GetPreambleForTransmission (mode.GetModulationClass (), GetShortPreambleEnabled ()), 800, 1, 1, 0, channelWidth, GetAggregation (station));
244 }
245 
248 {
249  NS_LOG_FUNCTION (this << st);
252  ArfWifiRemoteStation *station = static_cast<ArfWifiRemoteStation*> (st);
253  uint16_t channelWidth = GetChannelWidth (station);
254  if (channelWidth > 20 && channelWidth != 22)
255  {
256  channelWidth = 20;
257  }
258  WifiMode mode;
259  if (GetUseNonErpProtection () == false)
260  {
261  mode = GetSupported (station, 0);
262  }
263  else
264  {
265  mode = GetNonErpSupported (station, 0);
266  }
267  return WifiTxVector (mode, GetDefaultTxPowerLevel (), GetPreambleForTransmission (mode.GetModulationClass (), GetShortPreambleEnabled ()), 800, 1, 1, 0, channelWidth, GetAggregation (station));
268 }
269 
270 } //namespace ns3
ARF Rate control algorithm.
void DoReportFinalRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
void DoReportRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
WifiRemoteStation * DoCreateStation(void) const override
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station) override
uint32_t m_successThreshold
success threshold
void DoReportDataOk(WifiRemoteStation *station, double ackSnr, WifiMode ackMode, double dataSnr, uint16_t dataChannelWidth, uint8_t dataNss) override
This method is a pure virtual method that must be implemented by the sub-class.
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station) override
void DoInitialize(void) override
Initialize() implementation.
void DoReportRtsOk(WifiRemoteStation *station, double ctsSnr, WifiMode ctsMode, double rtsSnr) override
This method is a pure virtual method that must be implemented by the sub-class.
uint32_t m_timerThreshold
timer threshold
void DoReportFinalDataFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode) override
This method is a pure virtual method that must be implemented by the sub-class.
static TypeId GetTypeId(void)
Get the type ID.
void DoReportDataFailed(WifiRemoteStation *station) override
It is important to realize that "recovery" mode starts after failure of the first transmission after ...
TracedValue< uint64_t > m_currentRate
Trace rate changes.
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
Hold an unsigned integer type.
Definition: uinteger.h:44
represent a single transmission mode
Definition: wifi-mode.h:48
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:177
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:114
hold a list of per-remote-station state.
uint16_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
bool GetVhtSupported(void) const
Return whether the device has VHT capability support enabled.
bool GetUseNonErpProtection(void) const
Return whether the device supports protection of non-ERP stations.
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
WifiMode GetNonErpSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether non-ERP mode associated with the specified station at the specified index.
bool GetShortPreambleEnabled(void) const
Return whether the device uses short PHY preambles.
bool GetHeSupported(void) const
Return whether the device has HE capability support enabled.
WifiMode GetSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether mode associated with the specified station at the specified index.
bool GetHtSupported(void) const
Return whether the device has HT capability support enabled.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
#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
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
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
WifiPreamble GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble)
Return the preamble to be used for the transmission.
hold per-remote-station state for ARF Wifi manager.
uint32_t m_timer
timer value
uint32_t m_failed
failed count
uint32_t m_timerTimeout
timer timeout
uint32_t m_successThreshold
success threshold
uint32_t m_success
success count
hold per-remote-station state.
WifiRemoteStationState * m_state
Remote station state.
WifiModeList m_operationalRateSet
This member is the list of WifiMode objects that comprise the OperationalRateSet parameter for this r...