A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
cara-wifi-manager.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2004,2005,2006 INRIA
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Federico Maguolo <maguolof@dei.unipd.it>
18 */
19
20#include "cara-wifi-manager.h"
21
22#include "ns3/log.h"
23#include "ns3/wifi-tx-vector.h"
24
25#define Min(a, b) ((a < b) ? a : b)
26
27namespace ns3
28{
29
30NS_LOG_COMPONENT_DEFINE("CaraWifiManager");
31
32/**
33 * \brief hold per-remote-station state for CARA Wifi manager.
34 *
35 * This struct extends from WifiRemoteStation struct to hold additional
36 * information required by the CARA Wifi manager
37 */
39{
40 uint32_t m_timer; ///< timer count
41 uint32_t m_success; ///< success count
42 uint32_t m_failed; ///< failed count
43 uint8_t m_rate; ///< rate in bps
44};
45
47
50{
51 static TypeId tid =
52 TypeId("ns3::CaraWifiManager")
54 .SetGroupName("Wifi")
55 .AddConstructor<CaraWifiManager>()
56 .AddAttribute(
57 "ProbeThreshold",
58 "The number of consecutive transmissions failure to activate the RTS probe.",
61 MakeUintegerChecker<uint32_t>())
62 .AddAttribute("FailureThreshold",
63 "The number of consecutive transmissions failure to decrease the rate.",
66 MakeUintegerChecker<uint32_t>())
67 .AddAttribute("SuccessThreshold",
68 "The minimum number of successful 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 .AddTraceSource("Rate",
78 "Traced value for rate changes (b/s)",
80 "ns3::TracedValueCallback::Uint64");
81 return tid;
82}
83
86 m_currentRate(0)
87{
88 NS_LOG_FUNCTION(this);
89}
90
92{
93 NS_LOG_FUNCTION(this);
94}
95
96void
98{
99 NS_LOG_FUNCTION(this);
100 if (GetHtSupported())
101 {
102 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HT rates");
103 }
104 if (GetVhtSupported())
105 {
106 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support VHT rates");
107 }
108 if (GetHeSupported())
109 {
110 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HE rates");
111 }
112}
113
116{
117 NS_LOG_FUNCTION(this);
118 auto station = new CaraWifiRemoteStation();
119 station->m_rate = 0;
120 station->m_success = 0;
121 station->m_failed = 0;
122 station->m_timer = 0;
123 return station;
124}
125
126void
128{
129 NS_LOG_FUNCTION(this << st);
130}
131
132void
134{
135 NS_LOG_FUNCTION(this << st);
136 auto station = static_cast<CaraWifiRemoteStation*>(st);
137 station->m_timer++;
138 station->m_failed++;
139 station->m_success = 0;
140 if (station->m_failed >= m_failureThreshold)
141 {
142 NS_LOG_DEBUG("self=" << station << " dec rate");
143 if (station->m_rate != 0)
144 {
145 station->m_rate--;
146 }
147 station->m_failed = 0;
148 station->m_timer = 0;
149 }
150}
151
152void
154{
155 NS_LOG_FUNCTION(this << st << rxSnr << txMode);
156}
157
158void
160 double ctsSnr,
161 WifiMode ctsMode,
162 double rtsSnr)
163{
164 NS_LOG_FUNCTION(this << st << ctsSnr << ctsMode << rtsSnr);
165}
166
167void
169 double ackSnr,
170 WifiMode ackMode,
171 double dataSnr,
172 uint16_t dataChannelWidth,
173 uint8_t dataNss)
174{
175 NS_LOG_FUNCTION(this << st << ackSnr << ackMode << dataSnr << dataChannelWidth << +dataNss);
176 auto station = static_cast<CaraWifiRemoteStation*>(st);
177 station->m_timer++;
178 station->m_success++;
179 station->m_failed = 0;
180 NS_LOG_DEBUG("self=" << station << " data ok success=" << station->m_success
181 << ", timer=" << station->m_timer);
182 if (station->m_success == m_successThreshold || station->m_timer >= m_timerTimeout)
183 {
184 if (station->m_rate < GetNSupported(station) - 1)
185 {
186 station->m_rate++;
187 }
188 NS_LOG_DEBUG("self=" << station << " inc rate=" << +station->m_rate);
189 station->m_timer = 0;
190 station->m_success = 0;
191 }
192}
193
194void
196{
197 NS_LOG_FUNCTION(this << st);
198}
199
200void
202{
203 NS_LOG_FUNCTION(this << st);
204}
205
208{
209 NS_LOG_FUNCTION(this << st << allowedWidth);
210 auto station = static_cast<CaraWifiRemoteStation*>(st);
211 uint16_t channelWidth = GetChannelWidth(station);
212 if (channelWidth > 20 && channelWidth != 22)
213 {
214 channelWidth = 20;
215 }
216 WifiMode mode = GetSupported(station, station->m_rate);
217 uint64_t rate = mode.GetDataRate(channelWidth);
218 if (m_currentRate != rate)
219 {
220 NS_LOG_DEBUG("New datarate: " << rate);
221 m_currentRate = rate;
222 }
223 return WifiTxVector(
224 mode,
227 800,
228 1,
229 1,
230 0,
231 channelWidth,
232 GetAggregation(station));
233}
234
237{
238 NS_LOG_FUNCTION(this << st);
239 auto station = static_cast<CaraWifiRemoteStation*>(st);
240 /// \todo we could/should implement the Arf algorithm for
241 /// RTS only by picking a single rate within the BasicRateSet.
242 uint16_t channelWidth = GetChannelWidth(station);
243 if (channelWidth > 20 && channelWidth != 22)
244 {
245 channelWidth = 20;
246 }
247 WifiMode mode;
249 {
250 mode = GetSupported(station, 0);
251 }
252 else
253 {
254 mode = GetNonErpSupported(station, 0);
255 }
256 return WifiTxVector(
257 mode,
260 800,
261 1,
262 1,
263 0,
264 channelWidth,
265 GetAggregation(station));
266}
267
268bool
270{
271 NS_LOG_FUNCTION(this << st << size << normally);
272 auto station = static_cast<CaraWifiRemoteStation*>(st);
273 return normally || station->m_failed >= m_probeThreshold;
274}
275
276} // namespace ns3
implement the CARA rate control algorithm
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, uint16_t allowedWidth) override
void DoInitialize() override
Initialize() implementation.
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.
void DoReportFinalDataFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
static TypeId GetTypeId()
Get the type ID.
uint32_t m_failureThreshold
failure threshold
void DoReportRxOk(WifiRemoteStation *station, double rxSnr, WifiMode txMode) override
This method is a pure virtual method that must be implemented by the sub-class.
WifiTxVector DoGetRtsTxVector(WifiRemoteStation *station) override
bool DoNeedRts(WifiRemoteStation *station, uint32_t size, bool normally) override
uint32_t m_timerTimeout
timer threshold
void DoReportRtsFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
void DoReportDataFailed(WifiRemoteStation *station) override
This method is a pure virtual method that must be implemented by the sub-class.
WifiRemoteStation * DoCreateStation() const override
uint32_t m_successThreshold
success threshold
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.
void DoReportFinalRtsFailed(WifiRemoteStation *station) override
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
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
Hold an unsigned integer type.
Definition: uinteger.h:45
represent a single transmission mode
Definition: wifi-mode.h:51
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:185
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:122
hold a list of per-remote-station state.
uint16_t GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the station.
uint8_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
bool GetAggregation(const WifiRemoteStation *station) const
Return whether the given station supports A-MPDU.
bool GetHtSupported() const
Return whether the device has HT capability support enabled.
WifiMode GetNonErpSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether non-ERP mode associated with the specified station at the specified index.
bool GetUseNonErpProtection() const
Return whether the device supports protection of non-ERP stations.
bool GetVhtSupported() const
Return whether the device has VHT capability support enabled.
bool GetShortPreambleEnabled() const
Return whether the device uses short PHY preambles.
WifiMode GetSupported(const WifiRemoteStation *station, uint8_t i) const
Return whether mode associated with the specified station at the specified index.
bool GetHeSupported() const
Return whether the device has HE capability support enabled.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:46
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
WifiPreamble GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble)
Return the preamble to be used for the transmission.
hold per-remote-station state for CARA Wifi manager.
uint32_t m_success
success count
uint32_t m_failed
failed count
uint32_t m_timer
timer count
hold per-remote-station state.