A Discrete-Event Network Simulator
API
wifi-mac-helper.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016
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: Sébastien Deronne <sebastien.deronne@gmail.com>
18  */
19 
20 #include "wifi-mac-helper.h"
21 
22 #include "ns3/boolean.h"
23 #include "ns3/eht-configuration.h"
24 #include "ns3/emlsr-manager.h"
25 #include "ns3/frame-exchange-manager.h"
26 #include "ns3/multi-user-scheduler.h"
27 #include "ns3/wifi-ack-manager.h"
28 #include "ns3/wifi-assoc-manager.h"
29 #include "ns3/wifi-mac-queue-scheduler.h"
30 #include "ns3/wifi-net-device.h"
31 #include "ns3/wifi-protection-manager.h"
32 
33 namespace ns3
34 {
35 
37 {
38  // By default, we create an AdHoc MAC layer (without QoS).
39  SetType("ns3::AdhocWifiMac");
40 
41  m_assocManager.SetTypeId("ns3::WifiDefaultAssocManager");
42  m_queueScheduler.SetTypeId("ns3::FcfsWifiQueueScheduler");
43  m_protectionManager.SetTypeId("ns3::WifiDefaultProtectionManager");
44  m_ackManager.SetTypeId("ns3::WifiDefaultAckManager");
45  m_emlsrManager.SetTypeId("ns3::DefaultEmlsrManager");
46 }
47 
49 {
50 }
51 
54 {
55  NS_ABORT_MSG_IF(standard == WIFI_STANDARD_UNSPECIFIED, "No standard specified!");
56 
57  // this is a const method, but we need to force the correct QoS setting
58  ObjectFactory macObjectFactory = m_mac;
59  if (standard >= WIFI_STANDARD_80211n)
60  {
61  macObjectFactory.Set("QosSupported", BooleanValue(true));
62  }
63 
64  Ptr<WifiMac> mac = macObjectFactory.Create<WifiMac>();
65  mac->SetDevice(device);
66  mac->SetAddress(Mac48Address::Allocate());
67  device->SetMac(mac);
68  mac->ConfigureStandard(standard);
69 
71  mac->SetMacQueueScheduler(queueScheduler);
72 
73  // WaveNetDevice (through ns-3.38) stores PHY entities in a different member than WifiNetDevice,
74  // hence GetNPhys() would return 0. We have to attach a protection manager and an ack manager to
75  // the unique instance of frame exchange manager anyway
76  for (uint8_t linkId = 0; linkId < std::max<uint8_t>(device->GetNPhys(), 1); ++linkId)
77  {
78  auto fem = mac->GetFrameExchangeManager(linkId);
79 
80  Ptr<WifiProtectionManager> protectionManager =
82  protectionManager->SetWifiMac(mac);
83  protectionManager->SetLinkId(linkId);
84  fem->SetProtectionManager(protectionManager);
85 
87  ackManager->SetWifiMac(mac);
88  ackManager->SetLinkId(linkId);
89  fem->SetAckManager(ackManager);
90 
91  // 11be MLDs require a MAC address to be assigned to each STA. Note that
92  // FrameExchangeManager objects are created by WifiMac::SetupFrameExchangeManager
93  // (which is invoked by WifiMac::ConfigureStandard, which is called above),
94  // which sets the FrameExchangeManager's address to the address held by WifiMac.
95  // Hence, in case the number of PHY objects is 1, the FrameExchangeManager's
96  // address equals the WifiMac's address.
97  if (device->GetNPhys() > 1)
98  {
99  fem->SetAddress(Mac48Address::Allocate());
100  }
101  }
102 
103  // create and install the Multi User Scheduler if this is an HE AP
104  Ptr<ApWifiMac> apMac;
105  if (standard >= WIFI_STANDARD_80211ax && m_muScheduler.IsTypeIdSet() &&
106  (apMac = DynamicCast<ApWifiMac>(mac)))
107  {
109  apMac->AggregateObject(muScheduler);
110  }
111 
112  // create and install the Association Manager if this is a STA
113  auto staMac = DynamicCast<StaWifiMac>(mac);
114  if (staMac)
115  {
117  staMac->SetAssocManager(assocManager);
118  }
119 
120  // create and install the EMLSR Manager if this is an EHT non-AP MLD with EMLSR activated
121  if (BooleanValue emlsrActivated;
122  standard >= WIFI_STANDARD_80211be && staMac && staMac->GetNLinks() > 1 &&
123  device->GetEhtConfiguration()->GetAttributeFailSafe("EmlsrActivated", emlsrActivated) &&
124  emlsrActivated.Get())
125  {
126  auto emlsrManager = m_emlsrManager.Create<EmlsrManager>();
127  staMac->SetEmlsrManager(emlsrManager);
128  }
129 
130  return mac;
131 }
132 
133 } // namespace ns3
EmlsrManager is an abstract base class defining the API that EHT non-AP MLDs with EMLSR activated can...
Definition: emlsr-manager.h:47
static Mac48Address Allocate()
Allocate a new Mac48Address.
MultiUserScheduler is an abstract base class defining the API that APs supporting at least VHT can us...
Instantiate subclasses of ns3::Object.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
bool IsTypeIdSet() const
Check if the ObjectFactory has been configured with a TypeId.
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition: object.cc:259
WifiAckManager is an abstract base class.
Abstract base class for the Association Manager, which manages scanning and association for single li...
ObjectFactory m_mac
MAC object factory.
ObjectFactory m_queueScheduler
MAC queue scheduler.
virtual ~WifiMacHelper()
Destroy a WifiMacHelper.
virtual Ptr< WifiMac > Create(Ptr< WifiNetDevice > device, WifiStandard standard) const
ObjectFactory m_protectionManager
Factory to create a protection manager.
ObjectFactory m_muScheduler
Multi-user Scheduler object factory.
ObjectFactory m_assocManager
Association Manager.
WifiMacHelper()
Create a WifiMacHelper to make life easier for people who want to work with Wifi MAC layers.
ObjectFactory m_emlsrManager
EMLSR Manager object factory.
ObjectFactory m_ackManager
Factory to create an acknowledgment manager.
void SetType(std::string type, Args &&... args)
base class for all MAC-level wifi objects.
Definition: wifi-mac.h:96
WifiMacQueueScheduler is an abstract base class defining the public interface for a wifi MAC queue sc...
void SetMac(const Ptr< WifiMac > mac)
Ptr< EhtConfiguration > GetEhtConfiguration() const
uint8_t GetNPhys() const
WifiProtectionManager is an abstract base class.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
WifiStandard
Identifies the IEEE 802.11 specifications that a Wifi device can be configured to use.
@ WIFI_STANDARD_80211be
@ WIFI_STANDARD_80211n
@ WIFI_STANDARD_80211ax
@ WIFI_STANDARD_UNSPECIFIED
Every class exported by the ns3 library is enclosed in the ns3 namespace.
mac
Definition: third.py:92