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
14#define Min(a, b) ((a < b) ? a : b)
15
16namespace ns3
17{
18
19NS_LOG_COMPONENT_DEFINE("CaraWifiManager");
20
21/**
22 * \brief hold per-remote-station state for CARA Wifi manager.
23 *
24 * This struct extends from WifiRemoteStation struct to hold additional
25 * information required by the CARA Wifi manager
26 */
28{
29 uint32_t m_timer; ///< timer count
30 uint32_t m_success; ///< success count
31 uint32_t m_failed; ///< failed count
32 uint8_t m_rate; ///< rate in bps
33};
34
36
39{
40 static TypeId tid =
41 TypeId("ns3::CaraWifiManager")
43 .SetGroupName("Wifi")
44 .AddConstructor<CaraWifiManager>()
45 .AddAttribute(
46 "ProbeThreshold",
47 "The number of consecutive transmissions failure to activate the RTS probe.",
51 .AddAttribute("FailureThreshold",
52 "The number of consecutive transmissions failure to decrease the rate.",
56 .AddAttribute("SuccessThreshold",
57 "The minimum number of successful transmissions to try a new rate.",
58 UintegerValue(10),
61 .AddAttribute("Timeout",
62 "The 'timer' in the CARA algorithm",
63 UintegerValue(15),
66 .AddTraceSource("Rate",
67 "Traced value for rate changes (b/s)",
69 "ns3::TracedValueCallback::Uint64");
70 return tid;
71}
72
75 m_currentRate(0)
76{
77 NS_LOG_FUNCTION(this);
78}
79
84
85void
87{
88 NS_LOG_FUNCTION(this);
89 if (GetHtSupported())
90 {
91 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HT rates");
92 }
93 if (GetVhtSupported())
94 {
95 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support VHT rates");
96 }
97 if (GetHeSupported())
98 {
99 NS_FATAL_ERROR("WifiRemoteStationManager selected does not support HE rates");
100 }
101}
102
105{
106 NS_LOG_FUNCTION(this);
107 auto station = new CaraWifiRemoteStation();
108 station->m_rate = 0;
109 station->m_success = 0;
110 station->m_failed = 0;
111 station->m_timer = 0;
112 return station;
113}
114
115void
120
121void
123{
124 NS_LOG_FUNCTION(this << st);
125 auto station = static_cast<CaraWifiRemoteStation*>(st);
126 station->m_timer++;
127 station->m_failed++;
128 station->m_success = 0;
129 if (station->m_failed >= m_failureThreshold)
130 {
131 NS_LOG_DEBUG("self=" << station << " dec rate");
132 if (station->m_rate != 0)
133 {
134 station->m_rate--;
135 }
136 station->m_failed = 0;
137 station->m_timer = 0;
138 }
139}
140
141void
143{
144 NS_LOG_FUNCTION(this << st << rxSnr << txMode);
145}
146
147void
149 double ctsSnr,
150 WifiMode ctsMode,
151 double rtsSnr)
152{
153 NS_LOG_FUNCTION(this << st << ctsSnr << ctsMode << rtsSnr);
154}
155
156void
158 double ackSnr,
159 WifiMode ackMode,
160 double dataSnr,
161 MHz_u dataChannelWidth,
162 uint8_t dataNss)
163{
164 NS_LOG_FUNCTION(this << st << ackSnr << ackMode << dataSnr << dataChannelWidth << +dataNss);
165 auto station = static_cast<CaraWifiRemoteStation*>(st);
166 station->m_timer++;
167 station->m_success++;
168 station->m_failed = 0;
169 NS_LOG_DEBUG("self=" << station << " data ok success=" << station->m_success
170 << ", timer=" << station->m_timer);
171 if (station->m_success == m_successThreshold || station->m_timer >= m_timerTimeout)
172 {
173 if (station->m_rate < GetNSupported(station) - 1)
174 {
175 station->m_rate++;
176 }
177 NS_LOG_DEBUG("self=" << station << " inc rate=" << +station->m_rate);
178 station->m_timer = 0;
179 station->m_success = 0;
180 }
181}
182
183void
188
189void
194
197{
198 NS_LOG_FUNCTION(this << st << allowedWidth);
199 auto station = static_cast<CaraWifiRemoteStation*>(st);
200 auto channelWidth = GetChannelWidth(station);
201 if (channelWidth > 20 && channelWidth != 22)
202 {
203 channelWidth = 20;
204 }
205 WifiMode mode = GetSupported(station, station->m_rate);
206 uint64_t rate = mode.GetDataRate(channelWidth);
207 if (m_currentRate != rate)
208 {
209 NS_LOG_DEBUG("New datarate: " << rate);
210 m_currentRate = rate;
211 }
212 return WifiTxVector(
213 mode,
216 NanoSeconds(800),
217 1,
218 1,
219 0,
220 channelWidth,
221 GetAggregation(station));
222}
223
226{
227 NS_LOG_FUNCTION(this << st);
228 auto station = static_cast<CaraWifiRemoteStation*>(st);
229 /// \todo we could/should implement the Arf algorithm for
230 /// RTS only by picking a single rate within the BasicRateSet.
231 auto channelWidth = GetChannelWidth(station);
232 if (channelWidth > 20 && channelWidth != 22)
233 {
234 channelWidth = 20;
235 }
236 WifiMode mode;
238 {
239 mode = GetSupported(station, 0);
240 }
241 else
242 {
243 mode = GetNonErpSupported(station, 0);
244 }
245 return WifiTxVector(
246 mode,
249 NanoSeconds(800),
250 1,
251 1,
252 0,
253 channelWidth,
254 GetAggregation(station));
255}
256
257bool
259{
260 NS_LOG_FUNCTION(this << st << size << normally);
261 auto station = static_cast<CaraWifiRemoteStation*>(st);
262 return normally || station->m_failed >= m_probeThreshold;
263}
264
265} // 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:48
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:40
WifiModulationClass GetModulationClass() const
Definition wifi-mode.cc:174
uint64_t GetDataRate(MHz_u channelWidth, Time guardInterval, uint8_t nss) const
Definition wifi-mode.cc:111
hold a list of per-remote-station state.
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...
#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:1344
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.
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition uinteger.h:35
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.