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
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
NS_ASSERT
#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
ns3::WifiNoProtection
WifiNoProtection specifies that no protection method is used.
Definition: wifi-protection.h:82
regular-wifi-mac.h
ns3::WifiRtsCtsProtection
WifiRtsCtsProtection specifies that RTS/CTS protection method is used.
Definition: wifi-protection.h:96
wifi-tx-parameters.h
ns3::WifiMacHeader::IsRetry
bool IsRetry(void) const
Return if the Retry bit is set.
Definition: wifi-mac-header.cc:789
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::WifiProtection::CTS_TO_SELF
@ CTS_TO_SELF
Definition: wifi-protection.h:49
ns3::WifiRtsCtsProtection::ctsTxVector
WifiTxVector ctsTxVector
CTS TXVECTOR.
Definition: wifi-protection.h:103
ns3::WifiDefaultProtectionManager::WifiDefaultProtectionManager
WifiDefaultProtectionManager()
Definition: wifi-default-protection-manager.cc:45
ns3::WifiTxVector
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
Definition: wifi-tx-vector.h:71
ns3::WifiDefaultProtectionManager::TryAggregateMsdu
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.
Definition: wifi-default-protection-manager.cc:87
wifi-mac-queue-item.h
ns3::WifiMacHeader::GetAddr1
Mac48Address GetAddr1(void) const
Return the address in the Address 1 field.
Definition: wifi-mac-header.cc:424
ns3::WifiTxParameters
This class stores the TX parameters (TX vector, protection mechanism, acknowledgment mechanism,...
Definition: wifi-tx-parameters.h:45
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
ns3::WifiTxParameters::m_protection
std::unique_ptr< WifiProtection > m_protection
protection method
Definition: wifi-tx-parameters.h:63
ns3::WifiMacHeader
Implements the IEEE 802.11 MAC header.
Definition: wifi-mac-header.h:85
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
ns3::WifiCtsToSelfProtection::ctsTxVector
WifiTxVector ctsTxVector
CTS TXVECTOR.
Definition: wifi-protection.h:119
ns3::WifiDefaultProtectionManager::TryAddMpdu
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.
Definition: wifi-default-protection-manager.cc:56
ns3::WifiTxParameters::GetSizeIfAddMpdu
uint32_t GetSizeIfAddMpdu(Ptr< const WifiMacQueueItem > mpdu) const
Get the size in bytes of the frame in case the given MPDU is added.
Definition: wifi-tx-parameters.cc:147
ns3::WifiProtection::NONE
@ NONE
Definition: wifi-protection.h:47
ns3::WifiTxParameters::GetSizeIfAggregateMsdu
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.
Definition: wifi-tx-parameters.cc:187
ns3::WifiDefaultProtectionManager::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition: wifi-default-protection-manager.cc:35
ns3::WifiRtsCtsProtection::rtsTxVector
WifiTxVector rtsTxVector
RTS TXVECTOR.
Definition: wifi-protection.h:102
ns3::WifiMacHeader::GetFragmentNumber
uint8_t GetFragmentNumber(void) const
Return the fragment number of the header.
Definition: wifi-mac-header.cc:783
NS_LOG_FUNCTION_NOARGS
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Definition: log-macros-enabled.h:209
wifi-default-protection-manager.h
ns3::WifiTxParameters::m_txVector
WifiTxVector m_txVector
TXVECTOR of the frame being prepared.
Definition: wifi-tx-parameters.h:62
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition: log-macros-enabled.h:244
ns3::WifiDefaultProtectionManager::~WifiDefaultProtectionManager
virtual ~WifiDefaultProtectionManager()
Definition: wifi-default-protection-manager.cc:50
ns3::WifiProtection::RTS_CTS
@ RTS_CTS
Definition: wifi-protection.h:48
ns3::WifiDefaultProtectionManager
WifiDefaultProtectionManager is the default protection manager, which selects the protection method f...
Definition: wifi-default-protection-manager.h:40
ns3::WifiProtectionManager::m_mac
Ptr< RegularWifiMac > m_mac
MAC which is using this Protection Manager.
Definition: wifi-protection-manager.h:87
ns3::WifiProtectionManager
WifiProtectionManager is an abstract base class.
Definition: wifi-protection-manager.h:42
ns3::WifiCtsToSelfProtection
WifiCtsToSelfProtection specifies that CTS-to-self protection method is used.
Definition: wifi-protection.h:113
ns3::WifiTxVector::GetMode
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.
Definition: wifi-tx-vector.cc:112
ns3::WifiDefaultProtectionManager::GetPsduProtection
virtual std::unique_ptr< WifiProtection > GetPsduProtection(const WifiMacHeader &hdr, uint32_t size, const WifiTxVector &txVector) const
Select the protection method for a single PSDU.
Definition: wifi-default-protection-manager.cc:118