A Discrete-Event Network Simulator
API
cara-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: Federico Maguolo <maguolof@dei.unipd.it>
19  */
20 
21 #include "cara-wifi-manager.h"
22 #include "ns3/assert.h"
23 #include "ns3/log.h"
24 #include "ns3/double.h"
25 #include "ns3/uinteger.h"
26 #include "ns3/simulator.h"
27 
28 #define Min(a,b) ((a < b) ? a : b)
29 
30 namespace ns3 {
31 
33 
41 {
42  uint32_t m_timer;
43  uint32_t m_success;
44  uint32_t m_failed;
45  uint32_t m_rate;
46 };
47 
49 
50 TypeId
52 {
53  static TypeId tid = TypeId ("ns3::CaraWifiManager")
55  .SetGroupName ("Wifi")
56  .AddConstructor<CaraWifiManager> ()
57  .AddAttribute ("ProbeThreshold",
58  "The number of consecutive transmissions failure to activate the RTS probe.",
59  UintegerValue (1),
61  MakeUintegerChecker<uint32_t> ())
62  .AddAttribute ("FailureThreshold",
63  "The number of consecutive transmissions failure to decrease the rate.",
64  UintegerValue (2),
66  MakeUintegerChecker<uint32_t> ())
67  .AddAttribute ("SuccessThreshold",
68  "The minimum number of sucessfull transmissions to try a new rate.",
69  UintegerValue (10),
71  MakeUintegerChecker<uint32_t> ())
72  .AddAttribute ("Timeout",
73  "The 'timer' in the CARA algorithm",
74  UintegerValue (15),
76  MakeUintegerChecker<uint32_t> ())
77  ;
78  return tid;
79 }
80 
83 {
84  NS_LOG_FUNCTION (this);
85 }
86 
88 {
89  NS_LOG_FUNCTION (this);
90 }
91 
94 {
95  NS_LOG_FUNCTION (this);
97  station->m_rate = 0;
98  station->m_success = 0;
99  station->m_failed = 0;
100  station->m_timer = 0;
101  return station;
102 }
103 
104 void
106 {
107  NS_LOG_FUNCTION (this << st);
108 }
109 
110 void
112 {
113  NS_LOG_FUNCTION (this << st);
115  station->m_timer++;
116  station->m_failed++;
117  station->m_success = 0;
118  if (station->m_failed >= m_failureThreshold)
119  {
120  NS_LOG_DEBUG ("self=" << station << " dec rate");
121  if (station->m_rate != 0)
122  {
123  station->m_rate--;
124  }
125  station->m_failed = 0;
126  station->m_timer = 0;
127  }
128 }
129 
130 void
132  double rxSnr, WifiMode txMode)
133 {
134  NS_LOG_FUNCTION (this << st << rxSnr << txMode);
135 }
136 
137 void
139  double ctsSnr, WifiMode ctsMode, double rtsSnr)
140 {
141  NS_LOG_FUNCTION (this << st << ctsSnr << ctsMode << rtsSnr);
142  NS_LOG_DEBUG ("self=" << st << " rts ok");
143 }
144 
145 void
147  double ackSnr, WifiMode ackMode, double dataSnr)
148 {
149  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
151  station->m_timer++;
152  station->m_success++;
153  station->m_failed = 0;
154  NS_LOG_DEBUG ("self=" << station << " data ok success=" << station->m_success << ", timer=" << station->m_timer);
155  if ((station->m_success == m_successThreshold
156  || station->m_timer >= m_timerTimeout))
157  {
158  if (station->m_rate < GetNSupported (station) - 1)
159  {
160  station->m_rate++;
161  }
162  NS_LOG_DEBUG ("self=" << station << " inc rate=" << station->m_rate);
163  station->m_timer = 0;
164  station->m_success = 0;
165  }
166 }
167 
168 void
170 {
171  NS_LOG_FUNCTION (this << st);
172 }
173 
174 void
176 {
177  NS_LOG_FUNCTION (this << st);
178 }
179 
182 {
183  NS_LOG_FUNCTION (this << st);
185  uint32_t channelWidth = GetChannelWidth (station);
186  if (channelWidth > 20 && channelWidth != 22)
187  {
188  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
189  channelWidth = 20;
190  }
191  return WifiTxVector (GetSupported (station, station->m_rate), GetDefaultTxPowerLevel (), GetLongRetryCount (station), false, 1, 0, channelWidth, GetAggregation (station), false);
192 }
193 
196 {
197  NS_LOG_FUNCTION (this << st);
201  uint32_t channelWidth = GetChannelWidth (station);
202  if (channelWidth > 20 && channelWidth != 22)
203  {
204  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
205  channelWidth = 20;
206  }
207  WifiTxVector rtsTxVector;
208  if (GetUseNonErpProtection () == false)
209  {
210  rtsTxVector = WifiTxVector (GetSupported (station, 0), GetDefaultTxPowerLevel (), GetLongRetryCount (station), false, 1, 0, channelWidth, GetAggregation (station), false);
211  }
212  else
213  {
214  rtsTxVector = WifiTxVector (GetNonErpSupported (station, 0), GetDefaultTxPowerLevel (), GetLongRetryCount (station), false, 1, 0, channelWidth, GetAggregation (station), false);
215  }
216  return rtsTxVector;
217 }
218 
219 bool
221  Ptr<const Packet> packet, bool normally)
222 {
223  NS_LOG_FUNCTION (this << st << normally);
225  return normally || station->m_failed >= m_probeThreshold;
226 }
227 
228 bool
230 {
231  NS_LOG_FUNCTION (this);
232  return true;
233 }
234 
235 void
237 {
238  //HT is not supported by this algorithm.
239  if (enable)
240  {
241  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HT rates");
242  }
243 }
244 
245 void
247 {
248  //VHT is not supported by this algorithm.
249  if (enable)
250  {
251  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support VHT rates");
252  }
253 }
254 
255 } //namespace ns3
uint32_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
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
bool GetUseNonErpProtection(void) const
Return whether the device supports protection of non-ERP stations.
virtual WifiRemoteStation * DoCreateStation(void) const
virtual bool IsLowLatency(void) const
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
virtual void DoReportFinalDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
virtual void DoReportDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:99
virtual void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode)
This method is a pure virtual method that must be implemented by the sub-class.
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
WifiMode GetSupported(const WifiRemoteStation *station, uint32_t i) const
Return whether mode associated with the specified station at the specified index. ...
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.
static TypeId GetTypeId(void)
Hold an unsigned integer type.
Definition: uinteger.h:44
WifiMode GetNonErpSupported(const WifiRemoteStation *station, uint32_t i) const
Return whether non-ERP mode associated with the specified station at the specified index...
virtual void SetHtSupported(bool enable)
Enable or disable HT capability support.
hold a list of per-remote-station state.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual void DoReportRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
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 SetVhtSupported(bool enable)
Enable or disable VHT capability support.
uint32_t GetLongRetryCount(const WifiRemoteStation *station) const
Return the long retry limit of the given station.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
virtual WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)
uint32_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
hold per-remote-station state for CARA Wifi manager.
implement the CARA rate control algorithmImplement the CARA algorithm from: J.
virtual void DoReportFinalRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
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
virtual bool DoNeedRts(WifiRemoteStation *station, Ptr< const Packet > packet, bool normally)
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:904
hold per-remote-station state.
virtual WifiTxVector DoGetDataTxVector(WifiRemoteStation *station)