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/log.h"
23 #include "ns3/uinteger.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  uint32_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 sucessfull 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  NS_LOG_DEBUG ("self=" << st << " rts ok");
145 }
146 
147 void
149  double ackSnr, WifiMode ackMode, double dataSnr)
150 {
151  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr);
153  station->m_timer++;
154  station->m_success++;
155  station->m_failed = 0;
156  NS_LOG_DEBUG ("self=" << station << " data ok success=" << station->m_success << ", timer=" << station->m_timer);
157  if ((station->m_success == m_successThreshold
158  || station->m_timer >= m_timerTimeout))
159  {
160  if (station->m_rate < GetNSupported (station) - 1)
161  {
162  station->m_rate++;
163  }
164  NS_LOG_DEBUG ("self=" << station << " inc rate=" << station->m_rate);
165  station->m_timer = 0;
166  station->m_success = 0;
167  }
168 }
169 
170 void
172 {
173  NS_LOG_FUNCTION (this << st);
174 }
175 
176 void
178 {
179  NS_LOG_FUNCTION (this << st);
180 }
181 
184 {
185  NS_LOG_FUNCTION (this << st);
187  uint32_t channelWidth = GetChannelWidth (station);
188  if (channelWidth > 20 && channelWidth != 22)
189  {
190  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
191  channelWidth = 20;
192  }
193  WifiMode mode = GetSupported (station, station->m_rate);
194  if (m_currentRate != mode.GetDataRate (channelWidth))
195  {
196  NS_LOG_DEBUG ("New datarate: " << mode.GetDataRate (channelWidth));
197  m_currentRate = mode.GetDataRate (channelWidth);
198  }
199  return WifiTxVector (mode, GetDefaultTxPowerLevel (), GetLongRetryCount (station), GetPreambleForTransmission (mode, GetAddress (station)), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
200 }
201 
204 {
205  NS_LOG_FUNCTION (this << st);
209  uint32_t channelWidth = GetChannelWidth (station);
210  if (channelWidth > 20 && channelWidth != 22)
211  {
212  //avoid to use legacy rate adaptation algorithms for IEEE 802.11n/ac
213  channelWidth = 20;
214  }
215  WifiTxVector rtsTxVector;
216  WifiMode mode;
217  if (GetUseNonErpProtection () == false)
218  {
219  mode = GetSupported (station, 0);
220  }
221  else
222  {
223  mode = GetNonErpSupported (station, 0);
224  }
225  rtsTxVector = WifiTxVector (mode, GetDefaultTxPowerLevel (), GetLongRetryCount (station), GetPreambleForTransmission (mode, GetAddress (station)), 800, 1, 1, 0, channelWidth, GetAggregation (station), false);
226  return rtsTxVector;
227 }
228 
229 bool
231  Ptr<const Packet> packet, bool normally)
232 {
233  NS_LOG_FUNCTION (this << st << normally);
235  return normally || station->m_failed >= m_probeThreshold;
236 }
237 
238 bool
240 {
241  NS_LOG_FUNCTION (this);
242  return true;
243 }
244 
245 void
247 {
248  //HT is not supported by this algorithm.
249  if (enable)
250  {
251  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HT rates");
252  }
253 }
254 
255 void
257 {
258  //VHT is not supported by this algorithm.
259  if (enable)
260  {
261  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support VHT rates");
262  }
263 }
264 
265 void
267 {
268  //HE is not supported by this algorithm.
269  if (enable)
270  {
271  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HE rates");
272  }
273 }
274 
275 } //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.
WifiRemoteStation * DoCreateStation(void) const
bool IsLowLatency(void) const
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
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.
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.
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
TracedValue< uint64_t > m_currentRate
Trace rate changes.
uint32_t m_probeThreshold
probe threshold
WifiMode GetSupported(const WifiRemoteStation *station, uint32_t i) const
Return whether mode associated with the specified station at the specified index. ...
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
WifiMode GetNonErpSupported(const WifiRemoteStation *station, uint32_t i) const
Return whether non-ERP mode associated with the specified station at the specified index...
WifiPreamble GetPreambleForTransmission(WifiMode mode, Mac48Address dest)
Return the preamble to be used for the transmission.
uint64_t GetDataRate(uint8_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:143
void SetHtSupported(bool enable)
Enable or disable HT capability support.
uint8_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
uint32_t m_failed
failed count
Mac48Address GetAddress(const WifiRemoteStation *station) const
Return the address of the station.
hold a list of per-remote-station state.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void DoReportRtsFailed(WifiRemoteStation *station)
This method is a pure virtual method that must be implemented by the sub-class.
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 GetLongRetryCount(const WifiRemoteStation *station) const
Return the long retry limit of the given station.
uint32_t m_success
success count
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:269
uint32_t m_successThreshold
success threshold
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station)
hold per-remote-station state for CARA Wifi manager.
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:904
hold per-remote-station state.
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station)