A Discrete-Event Network Simulator
API
wifi-default-protection-manager.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2020 Universita' degli Studi di Napoli Federico II
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Stefano Avallone <stavallo@unina.it>
19 */
20
21#include "ns3/log.h"
23#include "wifi-tx-parameters.h"
24#include "wifi-mac-queue-item.h"
25#include "wifi-mac.h"
26
27
28namespace ns3 {
29
30NS_LOG_COMPONENT_DEFINE ("WifiDefaultProtectionManager");
31
32NS_OBJECT_ENSURE_REGISTERED (WifiDefaultProtectionManager);
33
34TypeId
36{
37 static TypeId tid = TypeId ("ns3::WifiDefaultProtectionManager")
39 .SetGroupName ("Wifi")
40 .AddConstructor<WifiDefaultProtectionManager> ()
41 ;
42 return tid;
43}
44
46{
47 NS_LOG_FUNCTION (this);
48}
49
51{
53}
54
55std::unique_ptr<WifiProtection>
57 const WifiTxParameters& txParams)
58{
59 NS_LOG_FUNCTION (this << *mpdu << &txParams);
60
61 // TB PPDUs need no protection (the soliciting Trigger Frame can be protected
62 // by an MU-RTS). Until MU-RTS is implemented, we disable protection also for:
63 // - Trigger Frames
64 // - DL MU PPDUs containing more than one PSDU
65 if (txParams.m_txVector.IsUlMu ()
66 || mpdu->GetHeader ().IsTrigger ()
67 || (txParams.m_txVector.IsDlMu () && txParams.GetPsduInfoMap ().size () > 1))
68 {
69 if (txParams.m_protection)
70 {
71 NS_ASSERT (txParams.m_protection->method == WifiProtection::NONE);
72 return nullptr;
73 }
74 return std::unique_ptr<WifiProtection> (new WifiNoProtection);
75 }
76
77 // If we are adding a second PSDU to a DL MU PPDU, switch to no protection
78 // (until MU-RTS is implemented)
79 if (txParams.m_txVector.IsDlMu () && txParams.GetPsduInfoMap ().size () == 1
80 && txParams.GetPsduInfo (mpdu->GetHeader ().GetAddr1 ()) == nullptr)
81 {
82 return std::unique_ptr<WifiProtection> (new WifiNoProtection);
83 }
84
85 // if the current protection method (if any) is already RTS/CTS or CTS-to-Self,
86 // it will not change by adding an MPDU
87 if (txParams.m_protection
88 && (txParams.m_protection->method == WifiProtection::RTS_CTS
89 || txParams.m_protection->method == WifiProtection::CTS_TO_SELF))
90 {
91 return nullptr;
92 }
93
94 // if a protection method is set, it must be NONE
95 NS_ASSERT (!txParams.m_protection || txParams.m_protection->method == WifiProtection::NONE);
96
97 std::unique_ptr<WifiProtection> protection;
98 protection = GetPsduProtection (mpdu->GetHeader (), txParams.GetSizeIfAddMpdu (mpdu),
99 txParams.m_txVector);
100
101 // return the newly computed method if none was set or it is not NONE
102 if (!txParams.m_protection || protection->method != WifiProtection::NONE)
103 {
104 return protection;
105 }
106 // the protection method has not changed
107 return nullptr;
108}
109
110std::unique_ptr<WifiProtection>
112 const WifiTxParameters& txParams)
113{
114 NS_LOG_FUNCTION (this << *msdu << &txParams);
115
116 // if the current protection method is already RTS/CTS or CTS-to-Self,
117 // it will not change by aggregating an MSDU
118 NS_ASSERT (txParams.m_protection);
119 if (txParams.m_protection->method == WifiProtection::RTS_CTS
120 || txParams.m_protection->method == WifiProtection::CTS_TO_SELF)
121 {
122 return nullptr;
123 }
124
125 NS_ASSERT (txParams.m_protection->method == WifiProtection::NONE);
126
127 // No protection for TB PPDUs
128 if (txParams.m_txVector.IsUlMu ())
129 {
130 return nullptr;
131 }
132
133 std::unique_ptr<WifiProtection> protection;
134 protection = GetPsduProtection (msdu->GetHeader (), txParams.GetSizeIfAggregateMsdu (msdu).second,
135 txParams.m_txVector);
136
137 // the protection method may still be none
138 if (protection->method == WifiProtection::NONE)
139 {
140 return nullptr;
141 }
142
143 // the protection method has changed
144 return protection;
145}
146
147std::unique_ptr<WifiProtection>
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 (m_mac->GetWifiRemoteStationManager ()->NeedRts (hdr, size))
161 {
163 protection->rtsTxVector = m_mac->GetWifiRemoteStationManager ()->GetRtsTxVector (hdr.GetAddr1 ());
164 protection->ctsTxVector = m_mac->GetWifiRemoteStationManager ()->GetCtsTxVector (hdr.GetAddr1 (),
165 protection->rtsTxVector.GetMode ());
166 return std::unique_ptr<WifiProtection> (protection);
167 }
168
169 // check if CTS-to-Self is needed
170 if (m_mac->GetWifiRemoteStationManager ()->GetUseNonErpProtection ()
171 && m_mac->GetWifiRemoteStationManager ()->NeedCtsToSelf (txVector))
172 {
174 protection->ctsTxVector = m_mac->GetWifiRemoteStationManager ()->GetCtsToSelfTxVector ();
175 return std::unique_ptr<WifiProtection> (protection);
176 }
177
178 return std::unique_ptr<WifiProtection> (new WifiNoProtection ());
179}
180
181} //namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
WifiDefaultProtectionManager is the default protection manager, which selects the protection method f...
virtual std::unique_ptr< WifiProtection > TryAggregateMsdu(Ptr< const WifiMacQueueItem > msdu, const WifiTxParameters &txParams) override
Determine the protection method to use if the given MSDU is aggregated to the current frame.
static TypeId GetTypeId(void)
Get the type ID.
virtual std::unique_ptr< WifiProtection > TryAddMpdu(Ptr< const WifiMacQueueItem > mpdu, const WifiTxParameters &txParams) override
Determine the protection method to use if the given MPDU is added 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.
bool IsRetry(void) const
Return if the Retry bit is set.
Mac48Address GetAddr1(void) const
Return the address in the Address 1 field.
uint8_t GetFragmentNumber(void) const
Return the fragment number of the header.
WifiProtectionManager is an abstract base class.
Ptr< WifiMac > m_mac
MAC which is using this Protection Manager.
This class stores the TX parameters (TX vector, protection mechanism, acknowledgment mechanism,...
std::pair< uint32_t, uint32_t > GetSizeIfAggregateMsdu(Ptr< const WifiMacQueueItem > msdu) const
Get the size in bytes of the frame in case the given MSDU is aggregated.
const PsduInfoMap & GetPsduInfoMap(void) const
Get a const reference to the map containing information about PSDUs.
std::unique_ptr< WifiProtection > m_protection
protection method
uint32_t GetSizeIfAddMpdu(Ptr< const WifiMacQueueItem > mpdu) const
Get the size in bytes of the frame in case the given MPDU is added.
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...
bool IsDlMu(void) const
Return true if this TX vector is used for a downlink multi-user transmission.
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 IsUlMu(void) 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:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#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.