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 "ns3/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 
94 void
96 {
97  NS_LOG_FUNCTION (this);
98  if (GetHtSupported ())
99  {
100  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HT rates");
101  }
102  if (GetVhtSupported ())
103  {
104  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support VHT rates");
105  }
106  if (GetHeSupported ())
107  {
108  NS_FATAL_ERROR ("WifiRemoteStationManager selected does not support HE rates");
109  }
110 }
111 
114 {
115  NS_LOG_FUNCTION (this);
117  station->m_rate = 0;
118  station->m_success = 0;
119  station->m_failed = 0;
120  station->m_timer = 0;
121  return station;
122 }
123 
124 void
126 {
127  NS_LOG_FUNCTION (this << st);
128 }
129 
130 void
132 {
133  NS_LOG_FUNCTION (this << st);
134  CaraWifiRemoteStation *station = static_cast<CaraWifiRemoteStation*> (st);
135  station->m_timer++;
136  station->m_failed++;
137  station->m_success = 0;
138  if (station->m_failed >= m_failureThreshold)
139  {
140  NS_LOG_DEBUG ("self=" << station << " dec rate");
141  if (station->m_rate != 0)
142  {
143  station->m_rate--;
144  }
145  station->m_failed = 0;
146  station->m_timer = 0;
147  }
148 }
149 
150 void
152  double rxSnr, WifiMode txMode)
153 {
154  NS_LOG_FUNCTION (this << st << rxSnr << txMode);
155 }
156 
157 void
159  double ctsSnr, WifiMode ctsMode, double rtsSnr)
160 {
161  NS_LOG_FUNCTION (this << st << ctsSnr << ctsMode << rtsSnr);
162 }
163 
164 void
166  double dataSnr, uint16_t dataChannelWidth, uint8_t dataNss)
167 {
168  NS_LOG_FUNCTION (this << st << ackSnr << ackMode << dataSnr << dataChannelWidth << +dataNss);
169  CaraWifiRemoteStation *station = static_cast<CaraWifiRemoteStation*> (st);
170  station->m_timer++;
171  station->m_success++;
172  station->m_failed = 0;
173  NS_LOG_DEBUG ("self=" << station << " data ok success=" << station->m_success << ", timer=" << station->m_timer);
174  if ((station->m_success == m_successThreshold
175  || station->m_timer >= m_timerTimeout))
176  {
177  if (station->m_rate < GetNSupported (station) - 1)
178  {
179  station->m_rate++;
180  }
181  NS_LOG_DEBUG ("self=" << station << " inc rate=" << +station->m_rate);
182  station->m_timer = 0;
183  station->m_success = 0;
184  }
185 }
186 
187 void
189 {
190  NS_LOG_FUNCTION (this << st);
191 }
192 
193 void
195 {
196  NS_LOG_FUNCTION (this << st);
197 }
198 
201 {
202  NS_LOG_FUNCTION (this << st);
203  CaraWifiRemoteStation *station = static_cast<CaraWifiRemoteStation*> (st);
204  uint16_t channelWidth = GetChannelWidth (station);
205  if (channelWidth > 20 && channelWidth != 22)
206  {
207  channelWidth = 20;
208  }
209  WifiMode mode = GetSupported (station, station->m_rate);
210  if (m_currentRate != mode.GetDataRate (channelWidth))
211  {
212  NS_LOG_DEBUG ("New datarate: " << mode.GetDataRate (channelWidth));
213  m_currentRate = mode.GetDataRate (channelWidth);
214  }
215  return WifiTxVector (mode, GetDefaultTxPowerLevel (), GetPreambleForTransmission (mode.GetModulationClass (), GetShortPreambleEnabled ()), 800, 1, 1, 0, channelWidth, GetAggregation (station));
216 }
217 
220 {
221  NS_LOG_FUNCTION (this << st);
222  CaraWifiRemoteStation *station = static_cast<CaraWifiRemoteStation*> (st);
225  uint16_t channelWidth = GetChannelWidth (station);
226  if (channelWidth > 20 && channelWidth != 22)
227  {
228  channelWidth = 20;
229  }
230  WifiTxVector rtsTxVector;
231  WifiMode mode;
232  if (GetUseNonErpProtection () == false)
233  {
234  mode = GetSupported (station, 0);
235  }
236  else
237  {
238  mode = GetNonErpSupported (station, 0);
239  }
240  rtsTxVector = WifiTxVector (mode, GetDefaultTxPowerLevel (), GetPreambleForTransmission (mode.GetModulationClass (), GetShortPreambleEnabled ()), 800, 1, 1, 0, channelWidth, GetAggregation (station));
241  return rtsTxVector;
242 }
243 
244 bool
246  uint32_t size, bool normally)
247 {
248  NS_LOG_FUNCTION (this << st << size << normally);
249  CaraWifiRemoteStation *station = static_cast<CaraWifiRemoteStation*> (st);
250  return normally || station->m_failed >= m_probeThreshold;
251 }
252 
253 } //namespace ns3
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
ns3::WifiRemoteStationManager::GetDefaultTxPowerLevel
uint8_t GetDefaultTxPowerLevel(void) const
Definition: wifi-remote-station-manager.cc:1206
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
ns3::CaraWifiManager::DoReportRtsOk
void DoReportRtsOk(WifiRemoteStation *station, double ctsSnr, WifiMode ctsMode, double rtsSnr) override
This method is a pure virtual method that must be implemented by the sub-class.
Definition: cara-wifi-manager.cc:158
ns3::WifiRemoteStationManager::GetUseNonErpProtection
bool GetUseNonErpProtection(void) const
Return whether the device supports protection of non-ERP stations.
Definition: wifi-remote-station-manager.cc:1051
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::CaraWifiManager::DoReportFinalDataFailed
void DoReportFinalDataFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
Definition: cara-wifi-manager.cc:194
ns3::WifiRemoteStationManager::GetSupported
WifiMode GetSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether mode associated with the specified station at the specified index.
Definition: wifi-remote-station-manager.cc:1635
ns3::CaraWifiManager::DoReportRxOk
void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode) override
This method is a pure virtual method that must be implemented by the sub-class.
Definition: cara-wifi-manager.cc:151
ns3::WifiMode::GetModulationClass
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:159
ns3::WifiRemoteStationManager
hold a list of per-remote-station state.
Definition: wifi-remote-station-manager.h:121
ns3::CaraWifiManager::m_currentRate
TracedValue< uint64_t > m_currentRate
Trace rate changes.
Definition: cara-wifi-manager.h:79
ns3::CaraWifiManager::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition: cara-wifi-manager.cc:48
ns3::WifiRemoteStationManager::GetHtSupported
bool GetHtSupported(void) const
Return whether the device has HT capability support enabled.
Definition: wifi-remote-station-manager.cc:232
ns3::WifiRemoteStationManager::GetVhtSupported
bool GetVhtSupported(void) const
Return whether the device has VHT capability support enabled.
Definition: wifi-remote-station-manager.cc:244
ns3::WifiRemoteStationManager::GetNSupported
uint8_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
Definition: wifi-remote-station-manager.cc:1743
ns3::WifiTxVector
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
Definition: wifi-tx-vector.h:71
ns3::CaraWifiRemoteStation::m_failed
uint32_t m_failed
failed count
Definition: cara-wifi-manager.cc:41
ns3::CaraWifiManager::DoReportDataFailed
void DoReportDataFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
Definition: cara-wifi-manager.cc:131
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
ns3::WifiRemoteStationManager::GetShortPreambleEnabled
bool GetShortPreambleEnabled(void) const
Return whether the device uses short PHY preambles.
Definition: wifi-remote-station-manager.cc:226
ns3::CaraWifiManager::m_successThreshold
uint32_t m_successThreshold
success threshold
Definition: cara-wifi-manager.h:75
ns3::CaraWifiRemoteStation::m_rate
uint8_t m_rate
rate in bps
Definition: cara-wifi-manager.cc:42
ns3::MakeTraceSourceAccessor
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Definition: trace-source-accessor.h:202
ns3::CaraWifiManager::DoGetDataTxVector
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station) override
Definition: cara-wifi-manager.cc:200
ns3::CaraWifiManager::DoCreateStation
WifiRemoteStation * DoCreateStation(void) const override
Definition: cara-wifi-manager.cc:113
ns3::CaraWifiManager::~CaraWifiManager
virtual ~CaraWifiManager()
Definition: cara-wifi-manager.cc:89
NS_FATAL_ERROR
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
ns3::WifiMode
represent a single transmission mode
Definition: wifi-mode.h:48
ns3::CaraWifiManager::DoNeedRts
bool DoNeedRts(WifiRemoteStation *station, uint32_t size, bool normally) override
Definition: cara-wifi-manager.cc:245
ns3::CaraWifiManager
implement the CARA rate control algorithm
Definition: cara-wifi-manager.h:45
ns3::CaraWifiManager::m_probeThreshold
uint32_t m_probeThreshold
probe threshold
Definition: cara-wifi-manager.h:77
ns3::CaraWifiManager::DoReportDataOk
void DoReportDataOk(WifiRemoteStation *station, double ackSnr, WifiMode ackMode, double dataSnr, uint16_t dataChannelWidth, uint8_t dataNss) override
This method is a pure virtual method that must be implemented by the sub-class.
Definition: cara-wifi-manager.cc:165
ns3::CaraWifiManager::m_timerTimeout
uint32_t m_timerTimeout
timer threshold
Definition: cara-wifi-manager.h:74
ns3::GetPreambleForTransmission
WifiPreamble GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble)
Return the preamble to be used for the transmission.
Definition: wifi-phy-common.cc:87
ns3::CaraWifiManager::CaraWifiManager
CaraWifiManager()
Definition: cara-wifi-manager.cc:82
ns3::WifiRemoteStation
hold per-remote-station state.
Definition: wifi-remote-station-manager.h:62
ns3::WifiRemoteStationManager::GetAggregation
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
Definition: wifi-remote-station-manager.cc:1707
ns3::CaraWifiManager::DoInitialize
void DoInitialize(void) override
Initialize() implementation.
Definition: cara-wifi-manager.cc:95
NS_LOG_DEBUG
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
ns3::WifiRemoteStationManager::GetNonErpSupported
WifiMode GetNonErpSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether non-ERP mode associated with the specified station at the specified index.
Definition: wifi-remote-station-manager.cc:1649
ns3::CaraWifiRemoteStation
hold per-remote-station state for CARA Wifi manager.
Definition: cara-wifi-manager.cc:38
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition: log-macros-enabled.h:244
ns3::CaraWifiManager::m_failureThreshold
uint32_t m_failureThreshold
failure threshold
Definition: cara-wifi-manager.h:76
cara-wifi-manager.h
ns3::UintegerValue
Hold an unsigned integer type.
Definition: uinteger.h:44
ns3::CaraWifiRemoteStation::m_timer
uint32_t m_timer
timer count
Definition: cara-wifi-manager.cc:39
ns3::CaraWifiManager::DoGetRtsTxVector
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station) override
Definition: cara-wifi-manager.cc:219
ns3::WifiRemoteStationManager::GetChannelWidth
uint16_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
Definition: wifi-remote-station-manager.cc:1683
ns3::WifiMode::GetDataRate
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:100
ns3::MakeUintegerAccessor
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
ns3::CaraWifiManager::DoReportFinalRtsFailed
void DoReportFinalRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
Definition: cara-wifi-manager.cc:188
ns3::CaraWifiManager::DoReportRtsFailed
void DoReportRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
Definition: cara-wifi-manager.cc:125
ns3::WifiRemoteStationManager::GetHeSupported
bool GetHeSupported(void) const
Return whether the device has HE capability support enabled.
Definition: wifi-remote-station-manager.cc:256
ns3::CaraWifiRemoteStation::m_success
uint32_t m_success
success count
Definition: cara-wifi-manager.cc:40