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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Federico Maguolo <maguolof@dei.unipd.it>
7 */
8
9#include "cara-wifi-manager.h"
10
11#include "ns3/log.h"
12#include "ns3/wifi-tx-vector.h"
13
14namespace ns3
15{
16
17NS_LOG_COMPONENT_DEFINE("CaraWifiManager");
18
19/**
20 * @brief hold per-remote-station state for CARA Wifi manager.
21 *
22 * This struct extends from WifiRemoteStation struct to hold additional
23 * information required by the CARA Wifi manager
24 */
26{
27 uint32_t m_timer; ///< timer count
28 uint32_t m_success; ///< success count
29 uint32_t m_failed; ///< failed count
30 uint8_t m_rate; ///< rate in bps
31};
32
34
37{
38 static TypeId tid =
39 TypeId("ns3::CaraWifiManager")
41 .SetGroupName("Wifi")
42 .AddConstructor<CaraWifiManager>()
43 .AddAttribute(
44 "ProbeThreshold",
45 "The number of consecutive transmissions failure to activate the RTS probe.",
49 .AddAttribute("FailureThreshold",
50 "The number of consecutive transmissions failure to decrease the rate.",
54 .AddAttribute("SuccessThreshold",
55 "The minimum number of successful transmissions to try a new rate.",
56 UintegerValue(10),
59 .AddAttribute("Timeout",
60 "The 'timer' in the CARA algorithm",
61 UintegerValue(15),
64 .AddTraceSource("Rate",
65 "Traced value for rate changes (b/s)",
67 "ns3::TracedValueCallback::Uint64");
68 return tid;
69}
70
77
82
83void
85{
86 NS_LOG_FUNCTION(this);
87 if (GetHtSupported())
88 {
89 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HT rates");
90 }
91 if (GetVhtSupported())
92 {
93 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support VHT rates");
94 }
95 if (GetHeSupported())
96 {
97 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HE rates");
98 }
99}
100
103{
104 NS_LOG_FUNCTION(this);
105 auto station = new CaraWifiRemoteStation();
106 station->m_rate = 0;
107 station->m_success = 0;
108 station->m_failed = 0;
109 station->m_timer = 0;
110 return station;
111}
112
113void
118
119void
121{
122 NS_LOG_FUNCTION(this << st);
123 auto station = static_cast<CaraWifiRemoteStation*>(st);
124 station->m_timer++;
125 station->m_failed++;
126 station->m_success = 0;
127 if (station->m_failed >= m_failureThreshold)
128 {
129 NS_LOG_DEBUG("self=" << station << " dec rate");
130 if (station->m_rate != 0)
131 {
132 station->m_rate--;
133 }
134 station->m_failed = 0;
135 station->m_timer = 0;
136 }
137}
138
139void
141{
142 NS_LOG_FUNCTION(this << st << rxSnr << txMode);
143}
144
145void
147 double ctsSnr,
148 WifiMode ctsMode,
149 double rtsSnr)
150{
151 NS_LOG_FUNCTION(this << st << ctsSnr << ctsMode << rtsSnr);
152}
153
154void
156 double ackSnr,
157 WifiMode ackMode,
158 double dataSnr,
159 MHz_u dataChannelWidth,
160 uint8_t dataNss)
161{
162 NS_LOG_FUNCTION(this << st << ackSnr << ackMode << dataSnr << dataChannelWidth << +dataNss);
163 auto station = static_cast<CaraWifiRemoteStation*>(st);
164 station->m_timer++;
165 station->m_success++;
166 station->m_failed = 0;
167 NS_LOG_DEBUG("self=" << station << " data ok success=" << station->m_success
168 << ", timer=" << station->m_timer);
169 if (station->m_success == m_successThreshold || station->m_timer >= m_timerTimeout)
170 {
171 if (station->m_rate < GetNSupported(station) - 1)
172 {
173 station->m_rate++;
174 }
175 NS_LOG_DEBUG("self=" << station << " inc rate=" << +station->m_rate);
176 station->m_timer = 0;
177 station->m_success = 0;
178 }
179}
180
181void
186
187void
192
195{
196 NS_LOG_FUNCTION(this << st << allowedWidth);
197 auto station = static_cast<CaraWifiRemoteStation*>(st);
198 auto channelWidth = GetChannelWidth(station);
199 if (channelWidth > MHz_u{20} && channelWidth != MHz_u{22})
200 {
201 channelWidth = MHz_u{20};
202 }
203 WifiMode mode = GetSupported(station, station->m_rate);
204 uint64_t rate = mode.GetDataRate(channelWidth);
205 if (m_currentRate != rate)
206 {
207 NS_LOG_DEBUG("New datarate: " << rate);
208 m_currentRate = rate;
209 }
210 return WifiTxVector(
211 mode,
214 NanoSeconds(800),
215 1,
216 1,
217 0,
218 channelWidth,
219 GetAggregation(station));
220}
221
224{
225 NS_LOG_FUNCTION(this << st);
226 auto station = static_cast<CaraWifiRemoteStation*>(st);
227 /// @todo we could/should implement the Arf algorithm for
228 /// RTS only by picking a single rate within the BasicRateSet.
229 auto channelWidth = GetChannelWidth(station);
230 if (channelWidth > MHz_u{20} && channelWidth != MHz_u{22})
231 {
232 channelWidth = MHz_u{20};
233 }
234 WifiMode mode;
236 {
237 mode = GetSupported(station, 0);
238 }
239 else
240 {
241 mode = GetNonErpSupported(station, 0);
242 }
243 return WifiTxVector(
244 mode,
247 NanoSeconds(800),
248 1,
249 1,
250 0,
251 channelWidth,
252 GetAggregation(station));
253}
254
255bool
257{
258 NS_LOG_FUNCTION(this << st << size << normally);
259 auto station = static_cast<CaraWifiRemoteStation*>(st);
260 return normally || station->m_failed >= m_probeThreshold;
261}
262
263} // namespace ns3
implement the CARA rate control algorithm
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
WifiTxVector DoGetDataTxVector(WifiRemoteStation *station, MHz_u allowedWidth) override
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 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
void DoReportDataOk(WifiRemoteStation *station, double ackSnr, WifiMode ackMode, double dataSnr, MHz_u dataChannelWidth, uint8_t dataNss) override
This method is a pure virtual method that must be implemented by the sub-class.
a unique identifier for an interface.
Definition type-id.h:49
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Hold an unsigned integer type.
Definition uinteger.h:34
represent a single transmission mode
Definition wifi-mode.h:38
WifiModulationClass GetModulationClass() const
Definition wifi-mode.cc:172
uint64_t GetDataRate(MHz_u channelWidth, Time guardInterval, uint8_t nss) const
Definition wifi-mode.cc:110
uint8_t GetNSupported(const WifiRemoteStation *station) const
Return the number of modes supported by the given station.
MHz_u GetChannelWidth(const WifiRemoteStation *station) const
Return the channel width supported by the 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 on the link this manager is associated wi...
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 on the link this manager is associated w...
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 AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
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:35
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#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:35
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1405
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.
double MHz_u
MHz weak type.
Definition wifi-units.h:31
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
hold per-remote-station state.