A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
aarf-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 "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;
44 
45  uint32_t m_rate;
46 };
47 
48 
50 
51 TypeId
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 
86 {
87 }
89 {
90 }
91 
94 {
96 
99  station->m_rate = 0;
100  station->m_success = 0;
101  station->m_failed = 0;
102  station->m_recovery = false;
103  station->m_retry = 0;
104  station->m_timer = 0;
105 
106  return station;
107 }
108 
109 void
111 {
112 }
122 void
124 {
126  station->m_timer++;
127  station->m_failed++;
128  station->m_retry++;
129  station->m_success = 0;
130 
131  if (station->m_recovery)
132  {
133  NS_ASSERT (station->m_retry >= 1);
134  if (station->m_retry == 1)
135  {
136  // need recovery fallback
137  station->m_successThreshold = (int)(Min (station->m_successThreshold * m_successK,
139  station->m_timerTimeout = (int)(Max (station->m_timerTimeout * m_timerK,
141  if (station->m_rate != 0)
142  {
143  station->m_rate--;
144  }
145  }
146  station->m_timer = 0;
147  }
148  else
149  {
150  NS_ASSERT (station->m_retry >= 1);
151  if (((station->m_retry - 1) % 2) == 1)
152  {
153  // need normal fallback
156  if (station->m_rate != 0)
157  {
158  station->m_rate--;
159  }
160  }
161  if (station->m_retry >= 2)
162  {
163  station->m_timer = 0;
164  }
165  }
166 }
167 void
169  double rxSnr, WifiMode txMode)
170 {
171 }
172 void
174  double ctsSnr, WifiMode ctsMode, double rtsSnr)
175 {
176  NS_LOG_DEBUG ("station=" << station << " rts ok");
177 }
178 void
180  double ackSnr, WifiMode ackMode, double dataSnr)
181 {
183  station->m_timer++;
184  station->m_success++;
185  station->m_failed = 0;
186  station->m_recovery = false;
187  station->m_retry = 0;
188  NS_LOG_DEBUG ("station=" << station << " data ok success=" << station->m_success << ", timer=" << station->m_timer);
189  if ((station->m_success == station->m_successThreshold
190  || station->m_timer == station->m_timerTimeout)
191  && (station->m_rate < (GetNSupported (station) - 1)))
192  {
193  NS_LOG_DEBUG ("station=" << station << " inc rate");
194  station->m_rate++;
195  station->m_timer = 0;
196  station->m_success = 0;
197  station->m_recovery = true;
198  }
199 }
200 void
202 {
203 }
204 void
206 {
207 }
208 
209 WifiMode
211 {
213  return GetSupported (station, station->m_rate);
214 }
215 WifiMode
217 {
218  // XXX: we could/should implement the Aarf algorithm for
219  // RTS only by picking a single rate within the BasicRateSet.
221  return GetSupported (station, 0);
222 }
223 
224 bool
226 {
227  return true;
228 }
229 
230 } // namespace ns3