A Discrete-Event Network Simulator
API
amrr-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) 2003,2007 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 "amrr-wifi-manager.h"
22 #include "ns3/simulator.h"
23 #include "ns3/log.h"
24 #include "ns3/uinteger.h"
25 #include "ns3/double.h"
26 
27 #define Min(a,b) ((a < b) ? a : b)
28 
29 namespace ns3 {
30 
31 NS_LOG_COMPONENT_DEFINE ("AmrrWifiRemoteStation");
32 
40 {
42  uint32_t m_tx_ok;
43  uint32_t m_tx_err;
44  uint32_t m_tx_retr;
45  uint32_t m_retry;
46  uint32_t m_txrate;
48  uint32_t m_success;
49  bool m_recovery;
50 };
51 
52 
54 
55 TypeId
57 {
58  static TypeId tid = TypeId ("ns3::AmrrWifiManager")
60  .SetGroupName ("Wifi")
61  .AddConstructor<AmrrWifiManager> ()
62  .AddAttribute ("UpdatePeriod",
63  "The interval between decisions about rate control changes",
64  TimeValue (Seconds (1.0)),
66  MakeTimeChecker ())
67  .AddAttribute ("FailureRatio",
68  "Ratio of minimum erroneous transmissions needed to switch to a lower rate",
69  DoubleValue (1.0 / 3.0),
71  MakeDoubleChecker<double> (0.0, 1.0))
72  .AddAttribute ("SuccessRatio",
73  "Ratio of maximum erroneous transmissions needed to switch to a higher rate",
74  DoubleValue (1.0 / 10.0),
76  MakeDoubleChecker<double> (0.0, 1.0))
77  .AddAttribute ("MaxSuccessThreshold",
78  "Maximum number of consecutive success periods needed to switch to a higher rate",
79  UintegerValue (10),
81  MakeUintegerChecker<uint32_t> ())
82  .AddAttribute ("MinSuccessThreshold",
83  "Minimum number of consecutive success periods needed to switch to a higher rate",
84  UintegerValue (1),
86  MakeUintegerChecker<uint32_t> ())
87  ;
88  return tid;
89 }
90 
92 {
93  NS_LOG_FUNCTION (this);
94 }
95 
98 {
99  NS_LOG_FUNCTION (this);
102  station->m_tx_ok = 0;
103  station->m_tx_err = 0;
104  station->m_tx_retr = 0;
105  station->m_retry = 0;
106  station->m_txrate = 0;
108  station->m_success = 0;
109  station->m_recovery = false;
110  return station;
111 }
112 
113 
114 void
116  double rxSnr, WifiMode txMode)
117 {
118  NS_LOG_FUNCTION (this << station << rxSnr << txMode);
119 }
120 void
122 {
123  NS_LOG_FUNCTION (this << station);
124 }
125 void
127 {
128  NS_LOG_FUNCTION (this << st);
130  station->m_retry++;
131  station->m_tx_retr++;
132 }
133 void
135  double ctsSnr, WifiMode ctsMode, double rtsSnr)
136 {
137  NS_LOG_FUNCTION (this << st << ctsSnr << ctsMode << rtsSnr);
138 }
139 void
141  double ackSnr, WifiMode ackMode, double dataSnr)
142 {
143  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
145  station->m_retry = 0;
146  station->m_tx_ok++;
147 }
148 void
150 {
151  NS_LOG_FUNCTION (this << station);
152 }
153 void
155 {
156  NS_LOG_FUNCTION (this << st);
158  station->m_retry = 0;
159  station->m_tx_err++;
160 }
161 bool
163 {
164  NS_LOG_FUNCTION (this << station);
165  return (station->m_txrate == 0);
166 }
167 bool
169 {
170  NS_LOG_FUNCTION (this << station);
171  NS_ASSERT (station->m_txrate + 1 <= GetNSupported (station));
172  return (station->m_txrate + 1 == GetNSupported (station));
173 }
174 bool
176 {
177  NS_LOG_FUNCTION (this << station);
178  return (station->m_tx_retr + station->m_tx_err) < station->m_tx_ok * m_successRatio;
179 }
180 bool
182 {
183  NS_LOG_FUNCTION (this << station);
184  return (station->m_tx_retr + station->m_tx_err) > station->m_tx_ok * m_failureRatio;
185 }
186 bool
188 {
189  NS_LOG_FUNCTION (this << station);
190  return (station->m_tx_retr + station->m_tx_err + station->m_tx_ok) > 10;
191 }
192 void
194 {
195  NS_LOG_FUNCTION (this << station);
196  station->m_tx_ok = 0;
197  station->m_tx_err = 0;
198  station->m_tx_retr = 0;
199 }
200 void
202 {
203  NS_LOG_FUNCTION (this << station);
204  station->m_txrate++;
205  NS_ASSERT (station->m_txrate < GetNSupported (station));
206 }
207 void
209 {
210  NS_LOG_FUNCTION (this << station);
211  station->m_txrate--;
212 }
213 
214 void
216 {
217  NS_LOG_FUNCTION (this << station);
218  if (Simulator::Now () < station->m_nextModeUpdate)
219  {
220  return;
221  }
223  NS_LOG_DEBUG ("Update");
224 
225  bool needChange = false;
226 
227  if (IsSuccess (station) && IsEnough (station))
228  {
229  station->m_success++;
230  NS_LOG_DEBUG ("++ success=" << station->m_success << " successThreshold=" << station->m_successThreshold <<
231  " tx_ok=" << station->m_tx_ok << " tx_err=" << station->m_tx_err << " tx_retr=" << station->m_tx_retr <<
232  " rate=" << station->m_txrate << " n-supported-rates=" << GetNSupported (station));
233  if (station->m_success >= station->m_successThreshold
234  && !IsMaxRate (station))
235  {
236  station->m_recovery = true;
237  station->m_success = 0;
238  IncreaseRate (station);
239  needChange = true;
240  }
241  else
242  {
243  station->m_recovery = false;
244  }
245  }
246  else if (IsFailure (station))
247  {
248  station->m_success = 0;
249  NS_LOG_DEBUG ("-- success=" << station->m_success << " successThreshold=" << station->m_successThreshold <<
250  " tx_ok=" << station->m_tx_ok << " tx_err=" << station->m_tx_err << " tx_retr=" << station->m_tx_retr <<
251  " rate=" << station->m_txrate << " n-supported-rates=" << GetNSupported (station));
252  if (!IsMinRate (station))
253  {
254  if (station->m_recovery)
255  {
256  station->m_successThreshold *= 2;
257  station->m_successThreshold = std::min (station->m_successThreshold,
259  }
260  else
261  {
263  }
264  station->m_recovery = false;
265  DecreaseRate (station);
266  needChange = true;
267  }
268  else
269  {
270  station->m_recovery = false;
271  }
272  }
273  if (IsEnough (station) || needChange)
274  {
275  NS_LOG_DEBUG ("Reset");
276  ResetCnt (station);
277  }
278 }
281 {
282  NS_LOG_FUNCTION (this << st << size);
284  UpdateMode (station);
285  NS_ASSERT (station->m_txrate < GetNSupported (station));
286  uint32_t rateIndex;
287  if (station->m_retry < 1)
288  {
289  rateIndex = station->m_txrate;
290  }
291  else if (station->m_retry < 2)
292  {
293  if (station->m_txrate > 0)
294  {
295  rateIndex = station->m_txrate - 1;
296  }
297  else
298  {
299  rateIndex = station->m_txrate;
300  }
301  }
302  else if (station->m_retry < 3)
303  {
304  if (station->m_txrate > 1)
305  {
306  rateIndex = station->m_txrate - 2;
307  }
308  else
309  {
310  rateIndex = station->m_txrate;
311  }
312  }
313  else
314  {
315  if (station->m_txrate > 2)
316  {
317  rateIndex = station->m_txrate - 3;
318  }
319  else
320  {
321  rateIndex = station->m_txrate;
322  }
323  }
324 
325  return WifiTxVector (GetSupported (station, rateIndex), GetDefaultTxPowerLevel (), GetLongRetryCount (station), GetShortGuardInterval (station), Min (GetNumberOfReceiveAntennas (station),GetNumberOfTransmitAntennas()), GetNess (station), GetStbc (station));
326 }
329 {
330  NS_LOG_FUNCTION (this << st);
332  UpdateMode (station);
335 }
336 
337 
338 bool
340 {
341  NS_LOG_FUNCTION (this);
342  return true;
343 }
344 
345 } // namespace ns3
uint32_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
bool IsMinRate(AmrrWifiRemoteStation *station) const
Check if the current rate for the given station is the minimum rate.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
AMRR Rate control algorithmThis class implements the AMRR rate control algorithm which was initially ...
virtual WifiRemoteStation * DoCreateStation(void) const
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
virtual void DoReportFinalRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
void ResetCnt(AmrrWifiRemoteStation *station)
Reset transmission statistics of the given station.
hold per-remote-station state for AMRR Wifi manager.
virtual WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)
#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:201
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:93
virtual void DoReportRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
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. ...
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:446
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 bool IsLowLatency(void) const
bool IsFailure(AmrrWifiRemoteStation *station) const
Check if the number of retransmission and transmission error is greater than the number of successful...
AttributeValue implementation for Time.
Definition: nstime.h:928
Hold an unsigned integer type.
Definition: uinteger.h:44
virtual void DoReportDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
void DecreaseRate(AmrrWifiRemoteStation *station)
Decrease the transmission rate to the given station.
hold a list of per-remote-station state.
uint32_t GetNess(const WifiRemoteStation *station) const
void IncreaseRate(AmrrWifiRemoteStation *station)
Increase the transmission rate to the given station.
virtual WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, uint32_t size)
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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode)
This method is a pure virtual method that must be implemented by the sub-class.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: nstime.h:929
static TypeId GetTypeId(void)
bool GetShortGuardInterval(const WifiRemoteStation *station) const
Return whether the given station supports short guard interval.
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:223
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.
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: double.h:42
bool IsSuccess(AmrrWifiRemoteStation *station) const
Check if the number of retransmission and transmission error is less than the number of successful tr...
uint32_t GetLongRetryCount(const WifiRemoteStation *station) const
Return the long retry limit of the given station.
virtual void DoReportFinalDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:866
void UpdateMode(AmrrWifiRemoteStation *station)
Update the mode used to send to the given station.
bool IsMaxRate(AmrrWifiRemoteStation *station) const
Check if the current rate for the given station is the maximum rate.
bool IsEnough(AmrrWifiRemoteStation *station) const
Check if the number of retransmission, transmission error, and successful transmission are greater th...
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41
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.