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 "ns3/log.h"
22 #include "cara-wifi-manager.h"
23 #include "wifi-tx-vector.h"
24 
25 #define Min(a,b) ((a < b) ? a : b)
26 
27 namespace ns3 {
28 
29 NS_LOG_COMPONENT_DEFINE ("CaraWifiManager");
30 
38 {
39  uint32_t m_timer;
40  uint32_t m_success;
41  uint32_t m_failed;
42  uint8_t m_rate;
43 };
44 
46 
47 TypeId
49 {
50  static TypeId tid = TypeId ("ns3::CaraWifiManager")
52  .SetGroupName ("Wifi")
53  .AddConstructor<CaraWifiManager> ()
54  .AddAttribute ("ProbeThreshold",
55  "The number of consecutive transmissions failure to activate the RTS probe.",
56  UintegerValue (1),
58  MakeUintegerChecker<uint32_t> ())
59  .AddAttribute ("FailureThreshold",
60  "The number of consecutive transmissions failure to decrease the rate.",
61  UintegerValue (2),
63  MakeUintegerChecker<uint32_t> ())
64  .AddAttribute ("SuccessThreshold",
65  "The minimum number of successful transmissions to try a new rate.",
66  UintegerValue (10),
68  MakeUintegerChecker<uint32_t> ())
69  .AddAttribute ("Timeout",
70  "The 'timer' in the CARA algorithm",
71  UintegerValue (15),
73  MakeUintegerChecker<uint32_t> ())
74  .AddTraceSource ("Rate",
75  "Traced value for rate changes (b/s)",
77  "ns3::TracedValueCallback::Uint64")
78  ;
79  return tid;
80 }
81 
84  m_currentRate (0)
85 {
86  NS_LOG_FUNCTION (this);
87 }
88 
90 {
91  NS_LOG_FUNCTION (this);
92 }
93 
96 {
97  NS_LOG_FUNCTION (this);
99  station->m_rate = 0;
100  station->m_success = 0;
101  station->m_failed = 0;
102  station->m_timer = 0;
103  return station;
104 }
105 
106 void
108 {
109  NS_LOG_FUNCTION (this << st);
110 }
111 
112 void
114 {
115  NS_LOG_FUNCTION (this << st);
117  station->m_timer++;
118  station->m_failed++;
119  station->m_success = 0;
120  if (station->m_failed >= m_failureThreshold)
121  {
122  NS_LOG_DEBUG ("self=" << station << " dec rate");
123  if (station->m_rate != 0)
124  {
125  station->m_rate--;
126  }
127  station->m_failed = 0;
128  station->m_timer = 0;
129  }
130 }
131 
132 void
134  double rxSnr, WifiMode txMode)
135 {
136  NS_LOG_FUNCTION (this << st << rxSnr << txMode);
137 }
138 
139 void
141  double ctsSnr, WifiMode ctsMode, double rtsSnr)
142 {
143  NS_LOG_FUNCTION (this << st << ctsSnr << ctsMode << rtsSnr);
144 }
145 
146 void
148  double ackSnr, WifiMode ackMode, double dataSnr)
149 {
150  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
152  station->m_timer++;
153  station->m_success++;
154  station->m_failed = 0;
155  NS_LOG_DEBUG ("self=" << station << " data ok success=" << station->m_success << ", timer=" << station->m_timer);
156  if ((station->m_success == m_successThreshold
157  || station->m_timer >= m_timerTimeout))
158  {
159  if (station->m_rate < GetNSupported (station) - 1)
160  {
161  station->m_rate++;
162  }
163  NS_LOG_DEBUG ("self=" << station << " inc rate=" << +station->m_rate);
164  station->m_timer = 0;
165  station->m_success = 0;
166  }
167 }
168 
169 void
171 {
172  NS_LOG_FUNCTION (this << st);
173 }
174 
175 void
177 {
178  NS_LOG_FUNCTION (this << st);
179 }
180 
183 {
184  NS_LOG_FUNCTION (this << st);
186  uint16_t channelWidth = GetChannelWidth (station);
187  if (channelWidth > 20 && channelWidth != 22)
188  {
189  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
190  channelWidth = 20;
191  }
192  WifiMode mode = GetSupported (station, station->m_rate);
193  if (m_currentRate != mode.GetDataRate (channelWidth))
194  {
195  NS_LOG_DEBUG ("New datarate: " << mode.GetDataRate (channelWidth));
196  m_currentRate = mode.GetDataRate (channelWidth);
197  }
198  return WifiTxVector (mode, GetDefaultTxPowerLevel (), GetPreambleForTransmission (mode, GetAddress (station)), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
199 }
200 
203 {
204  NS_LOG_FUNCTION (this << st);
208  uint16_t channelWidth = GetChannelWidth (station);
209  if (channelWidth > 20 && channelWidth != 22)
210  {
211  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
212  channelWidth = 20;
213  }
214  WifiTxVector rtsTxVector;
215  WifiMode mode;
216  if (GetUseNonErpProtection () == false)
217  {
218  mode = GetSupported (station, 0);
219  }
220  else
221  {
222  mode = GetNonErpSupported (station, 0);
223  }
224  rtsTxVector = WifiTxVector (mode, GetDefaultTxPowerLevel (), GetPreambleForTransmission (mode, GetAddress (station)), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
225  return rtsTxVector;
226 }
227 
228 bool
230  Ptr<const Packet> packet, bool normally)
231 {
232  NS_LOG_FUNCTION (this << st << normally);
234  return normally || station->m_failed >= m_probeThreshold;
235 }
236 
237 bool
239 {
240  return true;
241 }
242 
243 void
245 {
246  //HT is not supported by this algorithm.
247  if (enable)
248  {
249  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HT rates");
250  }
251 }
252 
253 void
255 {
256  //VHT is not supported by this algorithm.
257  if (enable)
258  {
259  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support VHT rates");
260  }
261 }
262 
263 void
265 {
266  //HE is not supported by this algorithm.
267  if (enable)
268  {
269  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HE rates");
270  }
271 }
272 
273 } //namespace ns3
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
uint8_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
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:45
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
uint32_t m_timerTimeout
timer threshold
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
void DoReportFinalDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
void DoReportDataFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
WifiMode GetSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether mode associated with the specified station at the specified index. ...
void SetHeSupported(bool enable)
Enable or disable HE capability support.
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:97
void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode)
This method is a pure virtual method that must be implemented by the sub-class.
TracedValue< uint64_t > m_currentRate
Trace rate changes.
uint32_t m_probeThreshold
probe threshold
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
uint32_t m_failureThreshold
failure threshold
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)
Get the type ID.
Hold an unsigned integer type.
Definition: uinteger.h:44
WifiPreamble GetPreambleForTransmission(WifiMode mode, Mac48Address dest)
Return the preamble to be used for the transmission.
void SetHtSupported(bool enable)
Enable or disable HT capability support.
uint32_t m_failed
failed count
hold a list of per-remote-station state.
WifiRemoteStation * DoCreateStation(void) const
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Mac48Address GetAddress(const WifiRemoteStation *station) const
Return the address of the station.
WifiMode GetNonErpSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether non-ERP mode associated with the specified station at the specified index...
void DoReportRtsFailed(WifiRemoteStation *station)
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.
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.
void SetVhtSupported(bool enable)
Enable or disable VHT capability support.
uint32_t m_success
success count
bool GetUseNonErpProtection(void) const
Return whether the device supports protection of non-ERP stations.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:270
uint32_t m_successThreshold
success threshold
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)
hold per-remote-station state for CARA Wifi manager.
bool IsLowLatency(void) const
uint32_t m_timer
timer count
implement the CARA rate control algorithmImplement the CARA algorithm from: J.
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
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:915
hold per-remote-station state.
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:156
uint16_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station)