A Discrete-Event Network Simulator
API
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 "wifi-mac.h"
23#include "wifi-mpdu.h"
24#include "wifi-tx-parameters.h"
25
26#include "ns3/log.h"
27
28namespace ns3
29{
30
31NS_LOG_COMPONENT_DEFINE("WifiDefaultProtectionManager");
32
33NS_OBJECT_ENSURE_REGISTERED(WifiDefaultProtectionManager);
34
35TypeId
37{
38 static TypeId tid = TypeId("ns3::WifiDefaultProtectionManager")
40 .SetGroupName("Wifi")
41 .AddConstructor<WifiDefaultProtectionManager>();
42 return tid;
43}
44
46{
47 NS_LOG_FUNCTION(this);
48}
49
51{
53}
54
55std::unique_ptr<WifiProtection>
57{
58 NS_LOG_FUNCTION(this << *mpdu << &txParams);
59
60 // TB PPDUs need no protection (the soliciting Trigger Frame can be protected
61 // by an MU-RTS). Until MU-RTS is implemented, we disable protection also for:
62 // - Trigger Frames
63 // - DL MU PPDUs containing more than one PSDU
64 if (txParams.m_txVector.IsUlMu() || mpdu->GetHeader().IsTrigger() ||
65 (txParams.m_txVector.IsDlMu() && txParams.GetPsduInfoMap().size() > 1))
66 {
67 if (txParams.m_protection)
68 {
69 NS_ASSERT(txParams.m_protection->method == WifiProtection::NONE);
70 return nullptr;
71 }
72 return std::unique_ptr<WifiProtection>(new WifiNoProtection);
73 }
74
75 // If we are adding a second PSDU to a DL MU PPDU, switch to no protection
76 // (until MU-RTS is implemented)
77 if (txParams.m_txVector.IsDlMu() && txParams.GetPsduInfoMap().size() == 1 &&
78 !txParams.GetPsduInfo(mpdu->GetHeader().GetAddr1()))
79 {
80 return std::unique_ptr<WifiProtection>(new WifiNoProtection);
81 }
82
83 // if the current protection method (if any) is already RTS/CTS or CTS-to-Self,
84 // it will not change by adding an MPDU
85 if (txParams.m_protection && (txParams.m_protection->method == WifiProtection::RTS_CTS ||
86 txParams.m_protection->method == WifiProtection::CTS_TO_SELF))
87 {
88 return nullptr;
89 }
90
91 // if a protection method is set, it must be NONE
92 NS_ASSERT(!txParams.m_protection || txParams.m_protection->method == WifiProtection::NONE);
93
94 std::unique_ptr<WifiProtection> protection;
95 protection =
96 GetPsduProtection(mpdu->GetHeader(), txParams.GetSizeIfAddMpdu(mpdu), txParams.m_txVector);
97
98 // return the newly computed method if none was set or it is not NONE
99 if (!txParams.m_protection || protection->method != WifiProtection::NONE)
100 {
101 return protection;
102 }
103 // the protection method has not changed
104 return nullptr;
105}
106
107std::unique_ptr<WifiProtection>
109 const WifiTxParameters& txParams)
110{
111 NS_LOG_FUNCTION(this << *msdu << &txParams);
112
113 // if the current protection method is already RTS/CTS or CTS-to-Self,
114 // it will not change by aggregating an MSDU
115 NS_ASSERT(txParams.m_protection);
116 if (txParams.m_protection->method == WifiProtection::RTS_CTS ||
117 txParams.m_protection->method == WifiProtection::CTS_TO_SELF)
118 {
119 return nullptr;
120 }
121
122 NS_ASSERT(txParams.m_protection->method == WifiProtection::NONE);
123
124 // No protection for TB PPDUs and DL MU PPDUs containing more than one PSDU
125 if (txParams.m_txVector.IsUlMu() ||
126 (txParams.m_txVector.IsDlMu() && txParams.GetPsduInfoMap().size() > 1))
127 {
128 return nullptr;
129 }
130
131 std::unique_ptr<WifiProtection> protection;
132 protection = GetPsduProtection(msdu->GetHeader(),
133 txParams.GetSizeIfAggregateMsdu(msdu).second,
134 txParams.m_txVector);
135
136 // the protection method may still be none
137 if (protection->method == WifiProtection::NONE)
138 {
139 return nullptr;
140 }
141
142 // the protection method has changed
143 return protection;
144}
145
146std::unique_ptr<WifiProtection>
148 uint32_t size,
149 const WifiTxVector& txVector) const
150{
151 NS_LOG_FUNCTION(this << hdr << size << txVector);
152
153 // a non-initial fragment does not need to be protected, unless it is being retransmitted
154 if (hdr.GetFragmentNumber() > 0 && !hdr.IsRetry())
155 {
156 return std::unique_ptr<WifiProtection>(new WifiNoProtection());
157 }
158
159 // check if RTS/CTS is needed
160 if (GetWifiRemoteStationManager()->NeedRts(hdr, size))
161 {
164 protection->ctsTxVector =
166 protection->rtsTxVector.GetMode());
167 return std::unique_ptr<WifiProtection>(protection);
168 }
169
170 // check if CTS-to-Self is needed
171 if (GetWifiRemoteStationManager()->GetUseNonErpProtection() &&
172 GetWifiRemoteStationManager()->NeedCtsToSelf(txVector))
173 {
176 return std::unique_ptr<WifiProtection>(protection);
177 }
178
179 return std::unique_ptr<WifiProtection>(new WifiNoProtection());
180}
181
182} // namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
a unique identifier for an interface.
Definition: type-id.h:60
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
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.
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 > 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.
WifiProtectionManager is an abstract base class.
Ptr< WifiRemoteStationManager > GetWifiRemoteStationManager() const
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...
WifiMode GetMode(uint16_t staId=SU_STA_ID) const
If this TX vector is associated with an SU PPDU, return the selected payload transmission mode.
bool IsDlMu() const
Return true if this TX vector is used for a downlink multi-user transmission.
bool IsUlMu() const
Return true if this TX vector is used for an uplink multi-user transmission.
#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_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:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.
WifiCtsToSelfProtection specifies that CTS-to-self protection method is used.
WifiTxVector ctsTxVector
CTS TXVECTOR.
WifiNoProtection specifies that no protection method is used.
WifiRtsCtsProtection specifies that RTS/CTS protection method is used.
WifiTxVector ctsTxVector
CTS TXVECTOR.
WifiTxVector rtsTxVector
RTS TXVECTOR.