A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("AmrrWifiRemoteStation");
30 
31 namespace ns3 {
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)),
64  MakeTimeAccessor (&AmrrWifiManager::m_updatePeriod),
65  MakeTimeChecker ())
66  .AddAttribute ("FailureRatio",
67  "Ratio of minimum erroneous transmissions needed to switch to a lower rate",
68  DoubleValue (1.0 / 3.0),
69  MakeDoubleAccessor (&AmrrWifiManager::m_failureRatio),
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),
74  MakeDoubleAccessor (&AmrrWifiManager::m_successRatio),
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),
79  MakeUintegerAccessor (&AmrrWifiManager::m_maxSuccessThreshold),
80  MakeUintegerChecker<uint32_t> ())
81  .AddAttribute ("MinSuccessThreshold",
82  "Minimum number of consecutive success periods needed to switch to a higher rate",
83  UintegerValue (1),
84  MakeUintegerAccessor (&AmrrWifiManager::m_minSuccessThreshold),
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 
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:79
#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 the class in the ns-3 factory.
Definition: object-base.h:38
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:170
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:91
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. ...
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:194
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...
hold objects of type ns3::Time
Definition: nstime.h:1008
Hold an unsigned integer type.
Definition: uinteger.h:46
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.
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.
virtual void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode)
This method is a pure virtual method that must be implemented by the sub-class.
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 time".
Definition: simulator.cc:180
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 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:213
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...
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:441
Hold a floating point type.
Definition: double.h:41
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
hold per-remote-station state.