A Discrete-Event Network Simulator
API
wifi-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"
23 #include "wifi-phy.h"
24 
25 #include "ns3/log.h"
26 
27 namespace ns3
28 {
29 
30 NS_LOG_COMPONENT_DEFINE("WifiProtectionManager");
31 
32 NS_OBJECT_ENSURE_REGISTERED(WifiProtectionManager);
33 
34 TypeId
36 {
37  static TypeId tid =
38  TypeId("ns3::WifiProtectionManager").SetParent<Object>().SetGroupName("Wifi");
39  return tid;
40 }
41 
43  : m_linkId(0)
44 {
45  NS_LOG_FUNCTION(this);
46 }
47 
49 {
51 }
52 
53 void
55 {
56  NS_LOG_FUNCTION(this);
57  m_mac = nullptr;
59 }
60 
61 void
63 {
64  NS_LOG_FUNCTION(this << mac);
65  m_mac = mac;
66 }
67 
70 {
72 }
73 
74 void
76 {
77  NS_LOG_FUNCTION(this << +linkId);
78  m_linkId = linkId;
79 }
80 
81 void
83  uint16_t txWidth,
84  const Mac48Address& receiver) const
85 {
86  NS_LOG_FUNCTION(this << muRts << txWidth << receiver);
87 
89 
90  NS_ABORT_MSG_IF(m_mac->GetTypeOfStation() != AP, "HE APs only can send MU-RTS");
91  auto apMac = StaticCast<ApWifiMac>(m_mac);
92  ui.SetAid12(apMac->GetAssociationId(receiver, m_linkId));
93 
94  const uint16_t ctsTxWidth =
95  std::min(txWidth, GetWifiRemoteStationManager()->GetChannelWidthSupported(receiver));
96  auto phy = m_mac->GetWifiPhy(m_linkId);
97  std::size_t primaryIdx = phy->GetOperatingChannel().GetPrimaryChannelIndex(ctsTxWidth);
98  if (phy->GetChannelWidth() == 160 && ctsTxWidth <= 40 && primaryIdx >= 80 / ctsTxWidth)
99  {
100  // the primary80 is in the higher part of the 160 MHz channel
101  primaryIdx -= 80 / ctsTxWidth;
102  }
103  switch (ctsTxWidth)
104  {
105  case 20:
106  ui.SetMuRtsRuAllocation(61 + primaryIdx);
107  break;
108  case 40:
109  ui.SetMuRtsRuAllocation(65 + primaryIdx);
110  break;
111  case 80:
112  ui.SetMuRtsRuAllocation(67);
113  break;
114  case 160:
115  ui.SetMuRtsRuAllocation(68);
116  break;
117  default:
118  NS_ABORT_MSG("Unhandled TX width: " << ctsTxWidth << " MHz");
119  }
120 }
121 
122 } // namespace ns3
#define min(a, b)
Definition: 80211b.c:41
Headers for Trigger frames.
Definition: ctrl-headers.h:942
CtrlTriggerUserInfoField & AddUserInfoField()
Append a new User Info field to this Trigger frame and return a non-const reference to it.
User Info field of Trigger frames.
Definition: ctrl-headers.h:590
void SetMuRtsRuAllocation(uint8_t value)
Set the RU Allocation subfield based on the given value for the B7-B1 bits.
void SetAid12(uint16_t aid)
Set the AID12 subfield, which carries the 12 LSBs of the AID of the station for which this User Info ...
an EUI-48 address
Definition: mac48-address.h:46
A base class which provides memory management and object aggregation.
Definition: object.h:89
virtual void DoDispose()
Destructor implementation.
Definition: object.cc:352
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
TypeOfStation GetTypeOfStation() const
Return the type of station.
Definition: wifi-mac.cc:422
Ptr< WifiPhy > GetWifiPhy(uint8_t linkId=SINGLE_LINK_OP_ID) const
Definition: wifi-mac.cc:1171
Ptr< WifiRemoteStationManager > GetWifiRemoteStationManager(uint8_t linkId=0) const
Definition: wifi-mac.cc:906
void DoDispose() override
Destructor implementation.
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.
void SetLinkId(uint8_t linkId)
Set the ID of the link this Protection Manager is associated with.
void SetWifiMac(Ptr< WifiMac > mac)
Set the MAC which is using this Protection Manager.
static TypeId GetTypeId()
Get the type ID.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:49
#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:66
Every class exported by the ns3 library is enclosed in the ns3 namespace.
mac
Definition: third.py:92
phy
Definition: third.py:89