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 "regular-wifi-mac.h"
26 
27 
28 namespace ns3 {
29 
30 NS_LOG_COMPONENT_DEFINE ("WifiDefaultProtectionManager");
31 
32 NS_OBJECT_ENSURE_REGISTERED (WifiDefaultProtectionManager);
33 
34 TypeId
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 
55 std::unique_ptr<WifiProtection>
57  const WifiTxParameters& txParams)
58 {
59  NS_LOG_FUNCTION (this << *mpdu << &txParams);
60 
61  // if the current protection method (if any) is already RTS/CTS or CTS-to-Self,
62  // it will not change by adding an MPDU
63  if (txParams.m_protection
64  && (txParams.m_protection->method == WifiProtection::RTS_CTS
65  || txParams.m_protection->method == WifiProtection::CTS_TO_SELF))
66  {
67  return nullptr;
68  }
69 
70  // if a protection method is set, it must be NONE
71  NS_ASSERT (!txParams.m_protection || txParams.m_protection->method == WifiProtection::NONE);
72 
73  std::unique_ptr<WifiProtection> protection;
74  protection = GetPsduProtection (mpdu->GetHeader (), txParams.GetSizeIfAddMpdu (mpdu),
75  txParams.m_txVector);
76 
77  // return the newly computed method if none was set or it is not NONE
78  if (!txParams.m_protection || protection->method != WifiProtection::NONE)
79  {
80  return protection;
81  }
82  // the protection method has not changed
83  return nullptr;
84 }
85 
86 std::unique_ptr<WifiProtection>
88  const WifiTxParameters& txParams)
89 {
90  NS_LOG_FUNCTION (this << *msdu << &txParams);
91 
92  // if the current protection method is already RTS/CTS or CTS-to-Self,
93  // it will not change by aggregating an MSDU
94  NS_ASSERT (txParams.m_protection);
95  if (txParams.m_protection->method == WifiProtection::RTS_CTS
96  || txParams.m_protection->method == WifiProtection::CTS_TO_SELF)
97  {
98  return nullptr;
99  }
100 
101  NS_ASSERT (txParams.m_protection->method == WifiProtection::NONE);
102 
103  std::unique_ptr<WifiProtection> protection;
104  protection = GetPsduProtection (msdu->GetHeader (), txParams.GetSizeIfAggregateMsdu (msdu).second,
105  txParams.m_txVector);
106 
107  // the protection method may still be none
108  if (protection->method == WifiProtection::NONE)
109  {
110  return nullptr;
111  }
112 
113  // the protection method has changed
114  return protection;
115 }
116 
117 std::unique_ptr<WifiProtection>
119  const WifiTxVector& txVector) const
120 {
121  NS_LOG_FUNCTION (this << hdr << size << txVector);
122 
123  // a non-initial fragment does not need to be protected, unless it is being retransmitted
124  if (hdr.GetFragmentNumber () > 0 && !hdr.IsRetry ())
125  {
126  return std::unique_ptr<WifiProtection> (new WifiNoProtection ());
127  }
128 
129  // check if RTS/CTS is needed
130  if (m_mac->GetWifiRemoteStationManager ()->NeedRts (hdr, size))
131  {
132  WifiRtsCtsProtection* protection = new WifiRtsCtsProtection;
133  protection->rtsTxVector = m_mac->GetWifiRemoteStationManager ()->GetRtsTxVector (hdr.GetAddr1 ());
134  protection->ctsTxVector = m_mac->GetWifiRemoteStationManager ()->GetCtsTxVector (hdr.GetAddr1 (),
135  protection->rtsTxVector.GetMode ());
136  return std::unique_ptr<WifiProtection> (protection);
137  }
138 
139  // check if CTS-to-Self is needed
140  if (m_mac->GetWifiRemoteStationManager ()->GetUseNonErpProtection ()
141  && m_mac->GetWifiRemoteStationManager ()->NeedCtsToSelf (txVector))
142  {
144  protection->ctsTxVector = m_mac->GetWifiRemoteStationManager ()->GetCtsToSelfTxVector ();
145  return std::unique_ptr<WifiProtection> (protection);
146  }
147 
148  return std::unique_ptr<WifiProtection> (new WifiNoProtection ());
149 }
150 
151 } //namespace ns3
bool IsRetry(void) const
Return if the Retry bit is set.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
virtual std::unique_ptr< WifiProtection > GetPsduProtection(const WifiMacHeader &hdr, uint32_t size, const WifiTxVector &txVector) const
Select the protection method for a single PSDU.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
std::unique_ptr< WifiProtection > m_protection
protection method
Mac48Address GetAddr1(void) const
Return the address in the Address 1 field.
#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
WifiTxVector ctsTxVector
CTS TXVECTOR.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
WifiTxVector rtsTxVector
RTS TXVECTOR.
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...
WifiDefaultProtectionManager is the default protection manager, which selects the protection method f...
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.
WifiTxVector m_txVector
TXVECTOR of the frame being prepared.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TypeId GetTypeId(void)
Get the type ID.
WifiRtsCtsProtection specifies that RTS/CTS protection method is used.
WifiProtectionManager is an abstract base class.
uint32_t GetSizeIfAddMpdu(Ptr< const WifiMacQueueItem > mpdu) const
Get the size in bytes of the frame in case the given MPDU is added.
WifiTxVector ctsTxVector
CTS TXVECTOR.
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.
This class stores the TX parameters (TX vector, protection mechanism, acknowledgment mechanism...
Ptr< RegularWifiMac > m_mac
MAC which is using this Protection Manager.
WifiCtsToSelfProtection specifies that CTS-to-self protection method is used.
WifiNoProtection specifies that no protection method is used.
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...
uint8_t GetFragmentNumber(void) const
Return the fragment number of the header.
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
Implements the IEEE 802.11 MAC header.