A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-default-protection-manager.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Universita' degli Studi di Napoli Federico II
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: Stefano Avallone <stavallo@unina.it>
18 */
19
21
22#include "ap-wifi-mac.h"
24#include "wifi-mpdu.h"
25#include "wifi-tx-parameters.h"
26
27#include "ns3/boolean.h"
28#include "ns3/erp-ofdm-phy.h"
29#include "ns3/log.h"
30
31#include <type_traits>
32
33namespace ns3
34{
35
36NS_LOG_COMPONENT_DEFINE("WifiDefaultProtectionManager");
37
38NS_OBJECT_ENSURE_REGISTERED(WifiDefaultProtectionManager);
39
40TypeId
42{
43 static TypeId tid =
44 TypeId("ns3::WifiDefaultProtectionManager")
46 .SetGroupName("Wifi")
47 .AddConstructor<WifiDefaultProtectionManager>()
48 .AddAttribute("EnableMuRts",
49 "If enabled, always protect a DL/UL MU frame exchange with MU-RTS/CTS.",
50 BooleanValue(false),
53 return tid;
54}
55
57{
58 NS_LOG_FUNCTION(this);
59}
60
62{
64}
65
66std::unique_ptr<WifiProtection>
68{
69 NS_LOG_FUNCTION(this << *mpdu << &txParams);
70
71 // Call a separate method that handles MU-RTS/CTS protection in case of DL MU PPDU containing
72 // more than one PSDU or in case the MPDU being added is addressed to an EMLSR client or in
73 // case the protection method is already MU-RTS/CTS.
74 // A DL MU PPDU contains more than one PSDU if either the TX params' PSDU info map
75 // contains more than one entry or it contains one entry but the MPDU being added is
76 // addressed to a different receiver (hence generating a new entry if the MPDU is added)
77 const auto& psduInfoMap = txParams.GetPsduInfoMap();
78 auto dlMuPpdu =
79 txParams.m_txVector.IsDlMu() &&
80 (psduInfoMap.size() > 1 ||
81 (psduInfoMap.size() == 1 && psduInfoMap.begin()->first != mpdu->GetHeader().GetAddr1()));
82 auto isEmlsrDestination =
83 GetWifiRemoteStationManager()->GetEmlsrEnabled(mpdu->GetHeader().GetAddr1());
84
85 if (dlMuPpdu || isEmlsrDestination ||
86 (txParams.m_protection && txParams.m_protection->method == WifiProtection::MU_RTS_CTS))
87 {
88 return TryAddMpduToMuPpdu(mpdu, txParams);
89 }
90
91 // No protection for TB PPDUs (the soliciting Trigger Frame can be protected by an MU-RTS)
92 if (txParams.m_txVector.IsUlMu())
93 {
94 if (txParams.m_protection)
95 {
96 NS_ASSERT(txParams.m_protection->method == WifiProtection::NONE);
97 return nullptr;
98 }
99 return std::make_unique<WifiNoProtection>();
100 }
101
102 // if this is a Trigger Frame, call a separate method
103 if (mpdu->GetHeader().IsTrigger())
104 {
105 return TryUlMuTransmission(mpdu, txParams);
106 }
107
108 // if the current protection method (if any) is already RTS/CTS or CTS-to-Self,
109 // it will not change by adding an MPDU
110 if (txParams.m_protection && (txParams.m_protection->method == WifiProtection::RTS_CTS ||
111 txParams.m_protection->method == WifiProtection::CTS_TO_SELF))
112 {
113 return nullptr;
114 }
115
116 // if a protection method is set, it must be NONE
117 NS_ASSERT(!txParams.m_protection || txParams.m_protection->method == WifiProtection::NONE);
118
119 std::unique_ptr<WifiProtection> protection;
120 protection =
121 GetPsduProtection(mpdu->GetHeader(), txParams.GetSizeIfAddMpdu(mpdu), txParams.m_txVector);
122
123 // return the newly computed method if none was set or it is not NONE
124 if (!txParams.m_protection || protection->method != WifiProtection::NONE)
125 {
126 return protection;
127 }
128 // the protection method has not changed
129 return nullptr;
130}
131
132std::unique_ptr<WifiProtection>
134 const WifiTxParameters& txParams)
135{
136 NS_LOG_FUNCTION(this << *msdu << &txParams);
137
138 // if the current protection method is already RTS/CTS, CTS-to-Self or MU-RTS/CTS,
139 // it will not change by aggregating an MSDU
140 NS_ASSERT(txParams.m_protection);
141 if (txParams.m_protection->method == WifiProtection::RTS_CTS ||
142 txParams.m_protection->method == WifiProtection::CTS_TO_SELF ||
143 txParams.m_protection->method == WifiProtection::MU_RTS_CTS)
144 {
145 return nullptr;
146 }
147
148 NS_ASSERT(txParams.m_protection->method == WifiProtection::NONE);
149
150 // No protection for TB PPDUs and DL MU PPDUs containing more than one PSDU
151 if (txParams.m_txVector.IsUlMu() ||
152 (txParams.m_txVector.IsDlMu() && txParams.GetPsduInfoMap().size() > 1))
153 {
154 return nullptr;
155 }
156
157 std::unique_ptr<WifiProtection> protection;
158 protection = GetPsduProtection(msdu->GetHeader(),
159 txParams.GetSizeIfAggregateMsdu(msdu).second,
160 txParams.m_txVector);
161
162 // the protection method may still be none
163 if (protection->method == WifiProtection::NONE)
164 {
165 return nullptr;
166 }
167
168 // the protection method has changed
169 return protection;
170}
171
172std::unique_ptr<WifiProtection>
174 uint32_t size,
175 const WifiTxVector& txVector) const
176{
177 NS_LOG_FUNCTION(this << hdr << size << txVector);
178
179 // a non-initial fragment does not need to be protected, unless it is being retransmitted
180 if (hdr.GetFragmentNumber() > 0 && !hdr.IsRetry())
181 {
182 return std::make_unique<WifiNoProtection>();
183 }
184
185 // no need to use protection if destination already received an RTS in this TXOP
186 if (m_mac->GetFrameExchangeManager(m_linkId)->GetProtectedStas().count(hdr.GetAddr1()) == 1)
187 {
188 return std::make_unique<WifiNoProtection>();
189 }
190
191 // check if RTS/CTS is needed
192 if (GetWifiRemoteStationManager()->NeedRts(hdr, size))
193 {
194 auto protection = std::make_unique<WifiRtsCtsProtection>();
195 protection->rtsTxVector = GetWifiRemoteStationManager()->GetRtsTxVector(hdr.GetAddr1());
196 protection->ctsTxVector =
198 protection->rtsTxVector.GetMode());
199 return protection;
200 }
201
202 // check if CTS-to-Self is needed
203 if (GetWifiRemoteStationManager()->GetUseNonErpProtection() &&
204 GetWifiRemoteStationManager()->NeedCtsToSelf(txVector))
205 {
206 auto protection = std::make_unique<WifiCtsToSelfProtection>();
207 protection->ctsTxVector = GetWifiRemoteStationManager()->GetCtsToSelfTxVector();
208 return protection;
209 }
210
211 return std::make_unique<WifiNoProtection>();
212}
213
214std::unique_ptr<WifiProtection>
216 const WifiTxParameters& txParams)
217{
218 NS_LOG_FUNCTION(this << *mpdu << &txParams);
219
220 auto receiver = mpdu->GetHeader().GetAddr1();
221 const auto& psduInfoMap = txParams.GetPsduInfoMap();
222 auto dlMuPpdu = txParams.m_txVector.IsDlMu() &&
223 (psduInfoMap.size() > 1 ||
224 (psduInfoMap.size() == 1 && psduInfoMap.begin()->first != receiver));
225 auto isEmlsrDestination = GetWifiRemoteStationManager()->GetEmlsrEnabled(receiver);
226 NS_ASSERT(
227 dlMuPpdu || isEmlsrDestination ||
228 (txParams.m_protection && txParams.m_protection->method == WifiProtection::MU_RTS_CTS));
229
230 auto isProtected =
231 m_mac->GetFrameExchangeManager(m_linkId)->GetProtectedStas().count(receiver) == 1;
232 bool needMuRts =
233 (txParams.m_protection && txParams.m_protection->method == WifiProtection::MU_RTS_CTS) ||
234 (dlMuPpdu && m_sendMuRts && !isProtected) || (isEmlsrDestination && !isProtected);
235
236 if (!needMuRts)
237 {
238 // No protection needed
239 if (txParams.m_protection && txParams.m_protection->method == WifiProtection::NONE)
240 {
241 return nullptr;
242 }
243 return std::make_unique<WifiNoProtection>();
244 }
245
246 WifiMuRtsCtsProtection* protection = nullptr;
247 if (txParams.m_protection && txParams.m_protection->method == WifiProtection::MU_RTS_CTS)
248 {
249 protection = static_cast<WifiMuRtsCtsProtection*>(txParams.m_protection.get());
250 }
251
252 if (txParams.GetPsduInfo(receiver) == nullptr)
253 {
254 // we get here if this is the first MPDU for this receiver.
255 NS_ABORT_MSG_IF(m_mac->GetTypeOfStation() != AP, "HE APs only can send DL MU PPDUs");
256 auto apMac = StaticCast<ApWifiMac>(m_mac);
257 auto modClass = txParams.m_txVector.GetModulationClass();
258 auto txWidth = modClass == WIFI_MOD_CLASS_DSSS || modClass == WIFI_MOD_CLASS_HR_DSSS
259 ? 20
260 : txParams.m_txVector.GetChannelWidth();
261
262 if (protection != nullptr)
263 {
264 // txParams.m_protection points to an existing WifiMuRtsCtsProtection object.
265 // We have to return a copy of this object including the needed changes
266 protection = new WifiMuRtsCtsProtection(*protection);
267 }
268 else
269 {
270 // we have to create a new WifiMuRtsCtsProtection object
271 protection = new WifiMuRtsCtsProtection;
272
273 // initialize the MU-RTS Trigger Frame
274 // The UL Length, GI And HE-LTF Type, MU-MIMO HE-LTF Mode, Number Of HE-LTF Symbols,
275 // UL STBC, LDPC Extra Symbol Segment, AP TX Power, Pre-FEC Padding Factor,
276 // PE Disambiguity, UL Spatial Reuse, Doppler and UL HE-SIG-A2 Reserved subfields in
277 // the Common Info field are reserved. (Sec. 9.3.1.22.5 of 802.11ax)
279 protection->muRts.SetUlBandwidth(txWidth);
280
281 // Add a User Info field for each of the receivers already in the TX params
282 for (const auto& [address, info] : txParams.GetPsduInfoMap())
283 {
284 NS_ASSERT_MSG(address != receiver, "This must be the first MPDU for " << receiver);
285 AddUserInfoToMuRts(protection->muRts, txWidth, address);
286 }
287
288 // compute the TXVECTOR to use to send the MU-RTS Trigger Frame
290 // The transmitter of an MU-RTS Trigger frame shall not request a non-AP STA to send
291 // a CTS frame response in a 20 MHz channel that is not occupied by the PPDU that
292 // contains the MU-RTS Trigger frame. (Sec. 26.2.6.2 of 802.11ax)
293 protection->muRtsTxVector.SetChannelWidth(txWidth);
294 // OFDM is needed to transmit the PPDU over a bandwidth that is a multiple of 20 MHz
295 const auto modulation = protection->muRtsTxVector.GetModulationClass();
296 if (modulation == WIFI_MOD_CLASS_DSSS || modulation == WIFI_MOD_CLASS_HR_DSSS)
297 {
299 }
300 }
301
302 // The initial Control frame of frame exchanges shall be sent in the non-HT PPDU or
303 // non-HT duplicate PPDU format using a rate of 6 Mb/s, 12 Mb/s, or 24 Mb/s.
304 // (Sec. 35.3.17 of 802.11be D3.0)
305 if (isEmlsrDestination && !isProtected)
306 {
308 }
309
310 // Add a User Info field for the new receiver
311 // The UL HE-MCS, UL FEC Coding Type, UL DCM, SS Allocation and UL Target RSSI fields
312 // in the User Info field are reserved (Sec. 9.3.1.22.5 of 802.11ax)
313 AddUserInfoToMuRts(protection->muRts, txWidth, receiver);
314
315 return std::unique_ptr<WifiMuRtsCtsProtection>(protection);
316 }
317
318 // an MPDU addressed to the same receiver has been already added
319 NS_ASSERT(protection != nullptr);
320
321 // no change is needed
322 return nullptr;
323}
324
325std::unique_ptr<WifiProtection>
327 const WifiTxParameters& txParams)
328{
329 NS_LOG_FUNCTION(this << *mpdu << &txParams);
330 NS_ASSERT(mpdu->GetHeader().IsTrigger());
331
332 CtrlTriggerHeader trigger;
333 mpdu->GetPacket()->PeekHeader(trigger);
334 NS_ASSERT(trigger.GetNUserInfoFields() > 0);
335 auto txWidth = trigger.GetUlBandwidth();
336
337 auto protection = std::make_unique<WifiMuRtsCtsProtection>();
338 // initialize the MU-RTS Trigger Frame
339 // The UL Length, GI And HE-LTF Type, MU-MIMO HE-LTF Mode, Number Of HE-LTF Symbols,
340 // UL STBC, LDPC Extra Symbol Segment, AP TX Power, Pre-FEC Padding Factor,
341 // PE Disambiguity, UL Spatial Reuse, Doppler and UL HE-SIG-A2 Reserved subfields in
342 // the Common Info field are reserved. (Sec. 9.3.1.22.5 of 802.11ax)
343 protection->muRts.SetType(TriggerFrameType::MU_RTS_TRIGGER);
344 protection->muRts.SetUlBandwidth(txWidth);
345
346 NS_ABORT_MSG_IF(m_mac->GetTypeOfStation() != AP, "HE APs only can send DL MU PPDUs");
347 const auto& staList = StaticCast<ApWifiMac>(m_mac)->GetStaList(m_linkId);
348 std::remove_reference_t<decltype(staList)>::const_iterator staIt;
349
350 bool allProtected = true;
351 bool isUnprotectedEmlsrDst = false;
352
353 for (const auto& userInfo : trigger)
354 {
355 // Add a User Info field to the MU-RTS for this solicited station
356 // The UL HE-MCS, UL FEC Coding Type, UL DCM, SS Allocation and UL Target RSSI fields
357 // in the User Info field are reserved (Sec. 9.3.1.22.5 of 802.11ax)
358 staIt = staList.find(userInfo.GetAid12());
359 NS_ASSERT(staIt != staList.cend());
360 AddUserInfoToMuRts(protection->muRts, txWidth, staIt->second);
361 bool isProtected =
362 m_mac->GetFrameExchangeManager(m_linkId)->GetProtectedStas().count(staIt->second) == 1;
363 allProtected = allProtected && isProtected;
364
365 isUnprotectedEmlsrDst =
366 isUnprotectedEmlsrDst ||
367 (!isProtected && GetWifiRemoteStationManager()->GetEmlsrEnabled(staIt->second));
368 }
369
370 bool needMuRts = (m_sendMuRts && !allProtected) || isUnprotectedEmlsrDst;
371
372 if (!needMuRts)
373 {
374 // No protection needed
375 return std::make_unique<WifiNoProtection>();
376 }
377
378 // compute the TXVECTOR to use to send the MU-RTS Trigger Frame
379 protection->muRtsTxVector =
380 GetWifiRemoteStationManager()->GetRtsTxVector(mpdu->GetHeader().GetAddr1());
381 // The transmitter of an MU-RTS Trigger frame shall not request a non-AP STA to send
382 // a CTS frame response in a 20 MHz channel that is not occupied by the PPDU that
383 // contains the MU-RTS Trigger frame. (Sec. 26.2.6.2 of 802.11ax)
384 protection->muRtsTxVector.SetChannelWidth(txWidth);
385 // OFDM is needed to transmit the PPDU over a bandwidth that is a multiple of 20 MHz
386 const auto modulation = protection->muRtsTxVector.GetModulationClass();
387 if (modulation == WIFI_MOD_CLASS_DSSS || modulation == WIFI_MOD_CLASS_HR_DSSS)
388 {
389 protection->muRtsTxVector.SetMode(ErpOfdmPhy::GetErpOfdmRate6Mbps());
390 }
391 // The initial Control frame of frame exchanges shall be sent in the non-HT PPDU or
392 // non-HT duplicate PPDU format using a rate of 6 Mb/s, 12 Mb/s, or 24 Mb/s.
393 // (Sec. 35.3.17 of 802.11be D3.0)
394 if (isUnprotectedEmlsrDst)
395 {
396 GetWifiRemoteStationManager()->AdjustTxVectorForIcf(protection->muRtsTxVector);
397 }
398
399 return protection;
400}
401
402} // namespace ns3
AttributeValue implementation for Boolean.
Definition: boolean.h:37
Headers for Trigger frames.
Definition: ctrl-headers.h:942
void SetUlBandwidth(uint16_t bw)
Set the bandwidth of the solicited HE TB PPDU.
std::size_t GetNUserInfoFields() const
Get the number of User Info fields in this Trigger Frame.
void SetType(TriggerFrameType type)
Set the Trigger frame type.
uint16_t GetUlBandwidth() const
Get the bandwidth of the solicited HE TB PPDU.
static WifiMode GetErpOfdmRate6Mbps()
Return a WifiMode for ERP-OFDM at 6 Mbps.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:936
WifiDefaultProtectionManager is the default protection manager, which selects the protection method f...
std::unique_ptr< WifiProtection > TryAddMpdu(Ptr< const WifiMpdu > mpdu, const WifiTxParameters &txParams) override
Determine the protection method to use if the given MPDU is added to the current frame.
bool m_sendMuRts
true for sending an MU-RTS to protect DL MU PPDUs
std::unique_ptr< WifiProtection > TryAggregateMsdu(Ptr< const WifiMpdu > msdu, const WifiTxParameters &txParams) override
Determine the protection method to use if the given MSDU is aggregated to the current frame.
virtual std::unique_ptr< WifiProtection > TryUlMuTransmission(Ptr< const WifiMpdu > mpdu, const WifiTxParameters &txParams)
Calculate the protection method for the UL MU transmission solicited by the given Trigger Frame.
virtual std::unique_ptr< WifiProtection > TryAddMpduToMuPpdu(Ptr< const WifiMpdu > mpdu, const WifiTxParameters &txParams)
Calculate the protection method to use if the given MPDU is added to the current DL MU PPDU (represen...
virtual std::unique_ptr< WifiProtection > GetPsduProtection(const WifiMacHeader &hdr, uint32_t size, const WifiTxVector &txVector) const
Select the protection method for a single PSDU.
Implements the IEEE 802.11 MAC header.
Mac48Address GetAddr1() const
Return the address in the Address 1 field.
bool IsRetry() const
Return if the Retry bit is set.
uint8_t GetFragmentNumber() const
Return the fragment number of the header.
Ptr< FrameExchangeManager > GetFrameExchangeManager(uint8_t linkId=SINGLE_LINK_OP_ID) const
Get the Frame Exchange Manager associated with the given link.
Definition: wifi-mac.cc:864
TypeOfStation GetTypeOfStation() const
Return the type of station.
Definition: wifi-mac.cc:425
WifiProtectionManager is an abstract base class.
Ptr< WifiMac > m_mac
MAC which is using this Protection Manager.
void AddUserInfoToMuRts(CtrlTriggerHeader &muRts, uint16_t txWidth, const Mac48Address &receiver) const
Add a User Info field to the given MU-RTS Trigger Frame to solicit a CTS from the station with the gi...
Ptr< WifiRemoteStationManager > GetWifiRemoteStationManager() const
uint8_t m_linkId
ID of the link this Protection Manager is operating on.
bool GetEmlsrEnabled(const Mac48Address &address) const
void AdjustTxVectorForIcf(WifiTxVector &txVector) const
Adjust the TXVECTOR for an initial Control frame to ensure that the modulation class is non-HT and th...
WifiTxVector GetCtsToSelfTxVector()
Since CTS-to-self parameters are not dependent on the station, it is implemented in wifi remote stati...
WifiTxVector GetCtsTxVector(Mac48Address to, WifiMode rtsTxMode) const
Return a TXVECTOR for the CTS frame given the destination and the mode of the RTS used by the sender.
WifiTxVector GetRtsTxVector(Mac48Address address)
This class stores the TX parameters (TX vector, protection mechanism, acknowledgment mechanism,...
uint32_t GetSizeIfAddMpdu(Ptr< const WifiMpdu > mpdu) const
Get the size in bytes of the frame in case the given MPDU is added.
const PsduInfoMap & GetPsduInfoMap() const
Get a const reference to the map containing information about PSDUs.
std::pair< uint32_t, uint32_t > GetSizeIfAggregateMsdu(Ptr< const WifiMpdu > msdu) const
Get the size in bytes of the frame in case the given MSDU is aggregated.
std::unique_ptr< WifiProtection > m_protection
protection method
const PsduInfo * GetPsduInfo(Mac48Address receiver) const
Get a pointer to the information about the PSDU addressed to the given receiver, if present,...
WifiTxVector m_txVector
TXVECTOR of the frame being prepared.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
void SetChannelWidth(uint16_t channelWidth)
Sets the selected channelWidth (in MHz)
bool IsDlMu() const
WifiModulationClass GetModulationClass() const
Get the modulation class specified by this TXVECTOR.
bool IsUlMu() const
uint16_t GetChannelWidth() const
void SetMode(WifiMode mode)
Sets the selected payload transmission mode.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:86
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Definition: boolean.h:86
Ptr< const AttributeChecker > MakeBooleanChecker()
Definition: boolean.cc:124
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#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
@ AP
Definition: wifi-mac.h:64
@ WIFI_MOD_CLASS_HR_DSSS
HR/DSSS (Clause 16)
@ WIFI_MOD_CLASS_DSSS
DSSS (Clause 15)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
WifiMuRtsCtsProtection specifies that MU-RTS/CTS protection method is used.
CtrlTriggerHeader muRts
MU-RTS.
WifiTxVector muRtsTxVector
MU-RTS TXVECTOR.