A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
aarf-wifi-manager.cc
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 "aarf-wifi-manager.h"
22 
23 #include "ns3/double.h"
24 #include "ns3/uinteger.h"
25 #include "ns3/log.h"
26 
27 #define Min(a,b) ((a < b) ? a : b)
28 #define Max(a,b) ((a > b) ? a : b)
29 
30 NS_LOG_COMPONENT_DEFINE ("AarfWifiManager");
31 
32 namespace ns3 {
33 
35 {
36  uint32_t m_timer;
37  uint32_t m_success;
38  uint32_t m_failed;
39  bool m_recovery;
40  uint32_t m_retry;
41 
42  uint32_t m_timerTimeout;
43  uint32_t m_successThreshold;
44 
45  uint32_t m_rate;
46 };
47 
48 
49 NS_OBJECT_ENSURE_REGISTERED (AarfWifiManager);
50 
51 TypeId
52 AarfWifiManager::GetTypeId (void)
53 {
54  static TypeId tid = TypeId ("ns3::AarfWifiManager")
56  .AddConstructor<AarfWifiManager> ()
57  .AddAttribute ("SuccessK", "Multiplication factor for the success threshold in the AARF algorithm.",
58  DoubleValue (2.0),
59  MakeDoubleAccessor (&AarfWifiManager::m_successK),
60  MakeDoubleChecker<double> ())
61  .AddAttribute ("TimerK",
62  "Multiplication factor for the timer threshold in the AARF algorithm.",
63  DoubleValue (2.0),
64  MakeDoubleAccessor (&AarfWifiManager::m_timerK),
65  MakeDoubleChecker<double> ())
66  .AddAttribute ("MaxSuccessThreshold",
67  "Maximum value of the success threshold in the AARF algorithm.",
68  UintegerValue (60),
69  MakeUintegerAccessor (&AarfWifiManager::m_maxSuccessThreshold),
70  MakeUintegerChecker<uint32_t> ())
71  .AddAttribute ("MinTimerThreshold",
72  "The minimum value for the 'timer' threshold in the AARF algorithm.",
73  UintegerValue (15),
74  MakeUintegerAccessor (&AarfWifiManager::m_minTimerThreshold),
75  MakeUintegerChecker<uint32_t> ())
76  .AddAttribute ("MinSuccessThreshold",
77  "The minimum value for the success threshold in the AARF algorithm.",
78  UintegerValue (10),
79  MakeUintegerAccessor (&AarfWifiManager::m_minSuccessThreshold),
80  MakeUintegerChecker<uint32_t> ())
81  ;
82  return tid;
83 }
84 
85 AarfWifiManager::AarfWifiManager ()
86 {
87  NS_LOG_FUNCTION (this);
88 }
89 AarfWifiManager::~AarfWifiManager ()
90 {
91  NS_LOG_FUNCTION (this);
92 }
93 
94 WifiRemoteStation *
96 {
97  NS_LOG_FUNCTION (this);
99 
100  station->m_successThreshold = m_minSuccessThreshold;
101  station->m_timerTimeout = m_minTimerThreshold;
102  station->m_rate = 0;
103  station->m_success = 0;
104  station->m_failed = 0;
105  station->m_recovery = false;
106  station->m_retry = 0;
107  station->m_timer = 0;
108 
109  return station;
110 }
111 
112 void
113 AarfWifiManager::DoReportRtsFailed (WifiRemoteStation *station)
114 {
115  NS_LOG_FUNCTION (this << station);
116 }
126 void
128 {
129  NS_LOG_FUNCTION (this << st);
131  station->m_timer++;
132  station->m_failed++;
133  station->m_retry++;
134  station->m_success = 0;
135 
136  if (station->m_recovery)
137  {
138  NS_ASSERT (station->m_retry >= 1);
139  if (station->m_retry == 1)
140  {
141  // need recovery fallback
142  station->m_successThreshold = (int)(Min (station->m_successThreshold * m_successK,
143  m_maxSuccessThreshold));
144  station->m_timerTimeout = (int)(Max (station->m_timerTimeout * m_timerK,
145  m_minSuccessThreshold));
146  if (station->m_rate != 0)
147  {
148  station->m_rate--;
149  }
150  }
151  station->m_timer = 0;
152  }
153  else
154  {
155  NS_ASSERT (station->m_retry >= 1);
156  if (((station->m_retry - 1) % 2) == 1)
157  {
158  // need normal fallback
159  station->m_timerTimeout = m_minTimerThreshold;
160  station->m_successThreshold = m_minSuccessThreshold;
161  if (station->m_rate != 0)
162  {
163  station->m_rate--;
164  }
165  }
166  if (station->m_retry >= 2)
167  {
168  station->m_timer = 0;
169  }
170  }
171 }
172 void
173 AarfWifiManager::DoReportRxOk (WifiRemoteStation *station,
174  double rxSnr, WifiMode txMode)
175 {
176  NS_LOG_FUNCTION (this << station << rxSnr << txMode);
177 }
178 void
179 AarfWifiManager::DoReportRtsOk (WifiRemoteStation *station,
180  double ctsSnr, WifiMode ctsMode, double rtsSnr)
181 {
182  NS_LOG_FUNCTION (this << station << ctsSnr << ctsMode << rtsSnr);
183  NS_LOG_DEBUG ("station=" << station << " rts ok");
184 }
185 void
186 AarfWifiManager::DoReportDataOk (WifiRemoteStation *st,
187  double ackSnr, WifiMode ackMode, double dataSnr)
188 {
189  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
190  AarfWifiRemoteStation *station = (AarfWifiRemoteStation *) st;
191  station->m_timer++;
192  station->m_success++;
193  station->m_failed = 0;
194  station->m_recovery = false;
195  station->m_retry = 0;
196  NS_LOG_DEBUG ("station=" << station << " data ok success=" << station->m_success << ", timer=" << station->m_timer);
197  if ((station->m_success == station->m_successThreshold
198  || station->m_timer == station->m_timerTimeout)
199  && (station->m_rate < (GetNSupported (station) - 1)))
200  {
201  NS_LOG_DEBUG ("station=" << station << " inc rate");
202  station->m_rate++;
203  station->m_timer = 0;
204  station->m_success = 0;
205  station->m_recovery = true;
206  }
207 }
208 void
209 AarfWifiManager::DoReportFinalRtsFailed (WifiRemoteStation *station)
210 {
211  NS_LOG_FUNCTION (this << station);
212 }
213 void
214 AarfWifiManager::DoReportFinalDataFailed (WifiRemoteStation *station)
215 {
216  NS_LOG_FUNCTION (this << station);
217 }
218 
219 WifiMode
221 {
222  NS_LOG_FUNCTION (this << st << size);
224  return GetSupported (station, station->m_rate);
225 }
226 WifiMode
228 {
229  NS_LOG_FUNCTION (this << st);
230  // XXX: we could/should implement the Aarf algorithm for
231  // RTS only by picking a single rate within the BasicRateSet.
233  return GetSupported (station, 0);
234 }
235 
236 bool
238 {
239  NS_LOG_FUNCTION (this);
240  return true;
241 }
242 
243 } // namespace ns3
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
#define NS_ASSERT(condition)
Definition: assert.h:64
virtual WifiMode DoGetDataMode(WifiRemoteStation *station, uint32_t size)
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:88
virtual void DoReportDataFailed(WifiRemoteStation *station)
Hold an unsigned integer type.
Definition: uinteger.h:46
virtual bool IsLowLatency(void) const
hold a list of per-remote-station state.
AARF Rate control algorithmThis class implements the AARF rate control algorithm which was initially ...
#define NS_LOG_DEBUG(msg)
Definition: log.h:255
Hold an floating point type.
Definition: double.h:41
virtual WifiRemoteStation * DoCreateStation(void) const
a unique identifier for an interface.
Definition: type-id.h:44
TypeId SetParent(TypeId tid)
Definition: type-id.cc:471
hold per-remote-station state.
virtual WifiMode DoGetRtsMode(WifiRemoteStation *station)