A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
arf-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 "arf-wifi-manager.h"
22 #include "ns3/assert.h"
23 #include "ns3/log.h"
24 #include "ns3/uinteger.h"
25 
26 NS_LOG_COMPONENT_DEFINE ("ns3::ArfWifiManager");
27 
28 
29 namespace ns3 {
30 
32 {
33  uint32_t m_timer;
34  uint32_t m_success;
35  uint32_t m_failed;
36  bool m_recovery;
37  uint32_t m_retry;
38 
39  uint32_t m_timerTimeout;
40  uint32_t m_successThreshold;
41 
42  uint32_t m_rate;
43 };
44 
45 NS_OBJECT_ENSURE_REGISTERED (ArfWifiManager);
46 
47 TypeId
48 ArfWifiManager::GetTypeId (void)
49 {
50  static TypeId tid = TypeId ("ns3::ArfWifiManager")
52  .AddConstructor<ArfWifiManager> ()
53  .AddAttribute ("TimerThreshold", "The 'timer' threshold in the ARF algorithm.",
54  UintegerValue (15),
55  MakeUintegerAccessor (&ArfWifiManager::m_timerThreshold),
56  MakeUintegerChecker<uint32_t> ())
57  .AddAttribute ("SuccessThreshold",
58  "The minimum number of sucessfull transmissions to try a new rate.",
59  UintegerValue (10),
60  MakeUintegerAccessor (&ArfWifiManager::m_successThreshold),
61  MakeUintegerChecker<uint32_t> ())
62  ;
63  return tid;
64 }
65 
66 ArfWifiManager::ArfWifiManager ()
67 {
68  NS_LOG_FUNCTION (this);
69 }
70 ArfWifiManager::~ArfWifiManager ()
71 {
72  NS_LOG_FUNCTION (this);
73 }
74 WifiRemoteStation *
76 {
77  NS_LOG_FUNCTION (this);
79 
80  station->m_successThreshold = m_successThreshold;
81  station->m_timerTimeout = m_timerThreshold;
82  station->m_rate = 0;
83  station->m_success = 0;
84  station->m_failed = 0;
85  station->m_recovery = false;
86  station->m_retry = 0;
87  station->m_timer = 0;
88 
89  return station;
90 }
91 
92 void
93 ArfWifiManager::DoReportRtsFailed (WifiRemoteStation *station)
94 {
95  NS_LOG_FUNCTION (this << station);
96 }
106 void
108 {
109  NS_LOG_FUNCTION (this << st);
111  station->m_timer++;
112  station->m_failed++;
113  station->m_retry++;
114  station->m_success = 0;
115 
116  if (station->m_recovery)
117  {
118  NS_ASSERT (station->m_retry >= 1);
119  if (station->m_retry == 1)
120  {
121  // need recovery fallback
122  if (station->m_rate != 0)
123  {
124  station->m_rate--;
125  }
126  }
127  station->m_timer = 0;
128  }
129  else
130  {
131  NS_ASSERT (station->m_retry >= 1);
132  if (((station->m_retry - 1) % 2) == 1)
133  {
134  // need normal fallback
135  if (station->m_rate != 0)
136  {
137  station->m_rate--;
138  }
139  }
140  if (station->m_retry >= 2)
141  {
142  station->m_timer = 0;
143  }
144  }
145 }
146 void
147 ArfWifiManager::DoReportRxOk (WifiRemoteStation *station,
148  double rxSnr, WifiMode txMode)
149 {
150  NS_LOG_FUNCTION (this << station << rxSnr << txMode);
151 }
152 void ArfWifiManager::DoReportRtsOk (WifiRemoteStation *station,
153  double ctsSnr, WifiMode ctsMode, double rtsSnr)
154 {
155  NS_LOG_FUNCTION (this << station << ctsSnr << ctsMode << rtsSnr);
156  NS_LOG_DEBUG ("station=" << station << " rts ok");
157 }
158 void ArfWifiManager::DoReportDataOk (WifiRemoteStation *st,
159  double ackSnr, WifiMode ackMode, double dataSnr)
160 {
161  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
162  ArfWifiRemoteStation *station = (ArfWifiRemoteStation *) st;
163  station->m_timer++;
164  station->m_success++;
165  station->m_failed = 0;
166  station->m_recovery = false;
167  station->m_retry = 0;
168  NS_LOG_DEBUG ("station=" << station << " data ok success=" << station->m_success << ", timer=" << station->m_timer);
169  if ((station->m_success == m_successThreshold
170  || station->m_timer == m_timerThreshold)
171  && (station->m_rate < (station->m_state->m_operationalRateSet.size () - 1)))
172  {
173  NS_LOG_DEBUG ("station=" << station << " inc rate");
174  station->m_rate++;
175  station->m_timer = 0;
176  station->m_success = 0;
177  station->m_recovery = true;
178  }
179 }
180 void
181 ArfWifiManager::DoReportFinalRtsFailed (WifiRemoteStation *station)
182 {
183  NS_LOG_FUNCTION (this << station);
184 }
185 void
186 ArfWifiManager::DoReportFinalDataFailed (WifiRemoteStation *station)
187 {
188  NS_LOG_FUNCTION (this << station);
189 }
190 
191 WifiMode
193 {
194  NS_LOG_FUNCTION (this << st << size);
195  ArfWifiRemoteStation *station = (ArfWifiRemoteStation *) st;
196  return GetSupported (station, station->m_rate);
197 }
198 WifiMode
200 {
201  NS_LOG_FUNCTION (this << st);
202  // XXX: we could/should implement the Arf algorithm for
203  // RTS only by picking a single rate within the BasicRateSet.
204  ArfWifiRemoteStation *station = (ArfWifiRemoteStation *) st;
205  return GetSupported (station, 0);
206 }
207 
208 bool
210 {
211  NS_LOG_FUNCTION (this);
212  return true;
213 }
214 
215 } // namespace ns3
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
virtual WifiRemoteStation * DoCreateStation(void) const
#define NS_ASSERT(condition)
Definition: assert.h:64
#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 bool IsLowLatency(void) const
Hold an unsigned integer type.
Definition: uinteger.h:46
virtual WifiMode DoGetRtsMode(WifiRemoteStation *station)
hold a list of per-remote-station state.
virtual void DoReportDataFailed(WifiRemoteStation *station)
ARF Rate control algorithm.
#define NS_LOG_DEBUG(msg)
Definition: log.h:255
virtual WifiMode DoGetDataMode(WifiRemoteStation *station, uint32_t size)
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.