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  .AddConstructor<AmrrWifiManager> ()
61  .AddAttribute ("UpdatePeriod",
62  "The interval between decisions about rate control changes",
63  TimeValue (Seconds (1.0)),
65  MakeTimeChecker ())
66  .AddAttribute ("FailureRatio",
67  "Ratio of minimum erroneous transmissions needed to switch to a lower rate",
68  DoubleValue (1.0 / 3.0),
70  MakeDoubleChecker<double> (0.0, 1.0))
71  .AddAttribute ("SuccessRatio",
72  "Ratio of maximum erroneous transmissions needed to switch to a higher rate",
73  DoubleValue (1.0 / 10.0),
75  MakeDoubleChecker<double> (0.0, 1.0))
76  .AddAttribute ("MaxSuccessThreshold",
77  "Maximum number of consecutive success periods needed to switch to a higher rate",
78  UintegerValue (10),
80  MakeUintegerChecker<uint32_t> ())
81  .AddAttribute ("MinSuccessThreshold",
82  "Minimum number of consecutive success periods needed to switch to a higher rate",
83  UintegerValue (1),
85  MakeUintegerChecker<uint32_t> ())
86  ;
87  return tid;
88 }
89 
91 {
92  NS_LOG_FUNCTION (this);
93 }
94 
97 {
98  NS_LOG_FUNCTION (this);
101  station->m_tx_ok = 0;
102  station->m_tx_err = 0;
103  station->m_tx_retr = 0;
104  station->m_retry = 0;
105  station->m_txrate = 0;
107  station->m_success = 0;
108  station->m_recovery = false;
109  return station;
110 }
111 
112 
113 void
115  double rxSnr, WifiMode txMode)
116 {
117  NS_LOG_FUNCTION (this << station << rxSnr << txMode);
118 }
119 void
121 {
122  NS_LOG_FUNCTION (this << station);
123 }
124 void
126 {
127  NS_LOG_FUNCTION (this << st);
129  station->m_retry++;
130  station->m_tx_retr++;
131 }
132 void
134  double ctsSnr, WifiMode ctsMode, double rtsSnr)
135 {
136  NS_LOG_FUNCTION (this << st << ctsSnr << ctsMode << rtsSnr);
137 }
138 void
140  double ackSnr, WifiMode ackMode, double dataSnr)
141 {
142  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
144  station->m_retry = 0;
145  station->m_tx_ok++;
146 }
147 void
149 {
150  NS_LOG_FUNCTION (this << station);
151 }
152 void
154 {
155  NS_LOG_FUNCTION (this << st);
157  station->m_retry = 0;
158  station->m_tx_err++;
159 }
160 bool
162 {
163  NS_LOG_FUNCTION (this << station);
164  return (station->m_txrate == 0);
165 }
166 bool
168 {
169  NS_LOG_FUNCTION (this << station);
170  NS_ASSERT (station->m_txrate + 1 <= GetNSupported (station));
171  return (station->m_txrate + 1 == GetNSupported (station));
172 }
173 bool
175 {
176  NS_LOG_FUNCTION (this << station);
177  return (station->m_tx_retr + station->m_tx_err) < station->m_tx_ok * m_successRatio;
178 }
179 bool
181 {
182  NS_LOG_FUNCTION (this << station);
183  return (station->m_tx_retr + station->m_tx_err) > station->m_tx_ok * m_failureRatio;
184 }
185 bool
187 {
188  NS_LOG_FUNCTION (this << station);
189  return (station->m_tx_retr + station->m_tx_err + station->m_tx_ok) > 10;
190 }
191 void
193 {
194  NS_LOG_FUNCTION (this << station);
195  station->m_tx_ok = 0;
196  station->m_tx_err = 0;
197  station->m_tx_retr = 0;
198 }
199 void
201 {
202  NS_LOG_FUNCTION (this << station);
203  station->m_txrate++;
204  NS_ASSERT (station->m_txrate < GetNSupported (station));
205 }
206 void
208 {
209  NS_LOG_FUNCTION (this << station);
210  station->m_txrate--;
211 }
212 
213 void
215 {
216  NS_LOG_FUNCTION (this << station);
217  if (Simulator::Now () < station->m_nextModeUpdate)
218  {
219  return;
220  }
222  NS_LOG_DEBUG ("Update");
223 
224  bool needChange = false;
225 
226  if (IsSuccess (station) && IsEnough (station))
227  {
228  station->m_success++;
229  NS_LOG_DEBUG ("++ success=" << station->m_success << " successThreshold=" << station->m_successThreshold <<
230  " tx_ok=" << station->m_tx_ok << " tx_err=" << station->m_tx_err << " tx_retr=" << station->m_tx_retr <<
231  " rate=" << station->m_txrate << " n-supported-rates=" << GetNSupported (station));
232  if (station->m_success >= station->m_successThreshold
233  && !IsMaxRate (station))
234  {
235  station->m_recovery = true;
236  station->m_success = 0;
237  IncreaseRate (station);
238  needChange = true;
239  }
240  else
241  {
242  station->m_recovery = false;
243  }
244  }
245  else if (IsFailure (station))
246  {
247  station->m_success = 0;
248  NS_LOG_DEBUG ("-- success=" << station->m_success << " successThreshold=" << station->m_successThreshold <<
249  " tx_ok=" << station->m_tx_ok << " tx_err=" << station->m_tx_err << " tx_retr=" << station->m_tx_retr <<
250  " rate=" << station->m_txrate << " n-supported-rates=" << GetNSupported (station));
251  if (!IsMinRate (station))
252  {
253  if (station->m_recovery)
254  {
255  station->m_successThreshold *= 2;
256  station->m_successThreshold = std::min (station->m_successThreshold,
258  }
259  else
260  {
262  }
263  station->m_recovery = false;
264  DecreaseRate (station);
265  needChange = true;
266  }
267  else
268  {
269  station->m_recovery = false;
270  }
271  }
272  if (IsEnough (station) || needChange)
273  {
274  NS_LOG_DEBUG ("Reset");
275  ResetCnt (station);
276  }
277 }
280 {
281  NS_LOG_FUNCTION (this << st << size);
283  UpdateMode (station);
284  NS_ASSERT (station->m_txrate < GetNSupported (station));
285  uint32_t rateIndex;
286  if (station->m_retry < 1)
287  {
288  rateIndex = station->m_txrate;
289  }
290  else if (station->m_retry < 2)
291  {
292  if (station->m_txrate > 0)
293  {
294  rateIndex = station->m_txrate - 1;
295  }
296  else
297  {
298  rateIndex = station->m_txrate;
299  }
300  }
301  else if (station->m_retry < 3)
302  {
303  if (station->m_txrate > 1)
304  {
305  rateIndex = station->m_txrate - 2;
306  }
307  else
308  {
309  rateIndex = station->m_txrate;
310  }
311  }
312  else
313  {
314  if (station->m_txrate > 2)
315  {
316  rateIndex = station->m_txrate - 3;
317  }
318  else
319  {
320  rateIndex = station->m_txrate;
321  }
322  }
323 
324  return WifiTxVector (GetSupported (station, rateIndex), GetDefaultTxPowerLevel (), GetLongRetryCount (station), GetShortGuardInterval (station), Min (GetNumberOfReceiveAntennas (station),GetNumberOfTransmitAntennas()), GetNess (station), GetStbc (station));
325 }
328 {
329  NS_LOG_FUNCTION (this << st);
331  UpdateMode (station);
334 }
335 
336 
337 bool
339 {
340  NS_LOG_FUNCTION (this);
341  return true;
342 }
343 
344 } // 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:95
#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:61
#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:439
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 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:921
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:922
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:859
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:51
TypeId SetParent(TypeId tid)
Definition: type-id.cc:631
hold per-remote-station state.