A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-mac-helper.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
7 */
8
9#include "wifi-mac-helper.h"
10
11#include "ns3/ap-emlsr-manager.h"
12#include "ns3/boolean.h"
13#include "ns3/eht-configuration.h"
14#include "ns3/emlsr-manager.h"
15#include "ns3/enum.h"
16#include "ns3/frame-exchange-manager.h"
17#include "ns3/gcr-manager.h"
18#include "ns3/multi-user-scheduler.h"
19#include "ns3/pointer.h"
20#include "ns3/wifi-ack-manager.h"
21#include "ns3/wifi-assoc-manager.h"
22#include "ns3/wifi-mac-queue-scheduler.h"
23#include "ns3/wifi-net-device.h"
24#include "ns3/wifi-protection-manager.h"
25
26#include <sstream>
27#include <vector>
28
29namespace ns3
30{
31
33{
34 // By default, we create an AdHoc MAC layer (without QoS).
35 SetType("ns3::AdhocWifiMac");
36
37 m_dcf.SetTypeId("ns3::Txop");
38 for (const auto& [aci, ac] : wifiAcList)
39 {
40 auto [it, inserted] = m_edca.try_emplace(aci);
41 it->second.SetTypeId("ns3::QosTxop");
42 }
43 m_channelAccessManager.SetTypeId("ns3::ChannelAccessManager");
44 // Setting FEM attributes requires setting a TypeId first. We initialize the TypeId to the FEM
45 // of the latest standard, in order to allow users to set the attributes of all the FEMs. The
46 // Create method will set the requested standard before creating the FEM(s).
48 m_assocManager.SetTypeId("ns3::WifiDefaultAssocManager");
49 m_queueScheduler.SetTypeId("ns3::FcfsWifiQueueScheduler");
50 m_protectionManager.SetTypeId("ns3::WifiDefaultProtectionManager");
51 m_ackManager.SetTypeId("ns3::WifiDefaultAckManager");
52 m_emlsrManager.SetTypeId("ns3::DefaultEmlsrManager");
53 m_apEmlsrManager.SetTypeId("ns3::DefaultApEmlsrManager");
54}
55
59
62{
63 NS_ABORT_MSG_IF(standard == WIFI_STANDARD_UNSPECIFIED, "No standard specified!");
64
65 // this is a const method, but we need to force the correct QoS setting
66 ObjectFactory macObjectFactory = m_mac;
67 if (standard >= WIFI_STANDARD_80211n)
68 {
69 macObjectFactory.Set("QosSupported", BooleanValue(true));
70 }
71
72 // do not create a Txop if the standard is at least 802.11n
73 if (standard < WIFI_STANDARD_80211n)
74 {
75 auto dcf = m_dcf; // create a copy because this is a const method
76 dcf.Set("AcIndex", EnumValue<AcIndex>(AC_BE_NQOS));
77 macObjectFactory.Set("Txop", PointerValue(dcf.Create<Txop>()));
78 }
79 // create (Qos)Txop objects
80 for (auto [aci, edca] : m_edca)
81 {
82 edca.Set("AcIndex", EnumValue<AcIndex>(aci));
83 std::stringstream ss;
84 ss << aci << "_Txop";
85 auto s = ss.str().substr(3); // discard "AC "
86 macObjectFactory.Set(s, PointerValue(edca.Create<QosTxop>()));
87 }
88
89 // WaveNetDevice (through ns-3.38) stores PHY entities in a different member than WifiNetDevice,
90 // hence GetNPhys() would return 0
91 auto nLinks = std::max<uint8_t>(device->GetNPhys(), 1);
92
93 // create Channel Access Managers
94 std::vector<Ptr<ChannelAccessManager>> caManagers;
95 caManagers.reserve(nLinks);
96 for (uint8_t linkId = 0; linkId < nLinks; ++linkId)
97 {
98 caManagers.emplace_back(m_channelAccessManager.Create<ChannelAccessManager>());
99 }
100
101 Ptr<WifiMac> mac = macObjectFactory.Create<WifiMac>();
102 mac->SetDevice(device);
103 mac->SetAddress(Mac48Address::Allocate());
104 device->SetMac(mac);
105 mac->SetChannelAccessManagers(caManagers);
106
107 // create Frame Exchange Managers, each with an attached protection manager and ack manager
108 std::vector<Ptr<FrameExchangeManager>> feManagers;
109 auto frameExchangeManager = m_frameExchangeManager;
110 frameExchangeManager.SetTypeId(
111 GetFrameExchangeManagerTypeIdName(standard, mac->GetQosSupported()));
112 for (uint8_t linkId = 0; linkId < nLinks; ++linkId)
113 {
114 auto fem = frameExchangeManager.Create<FrameExchangeManager>();
115 feManagers.emplace_back(fem);
116
117 auto protectionManager = m_protectionManager.Create<WifiProtectionManager>();
118 protectionManager->SetWifiMac(mac);
119 protectionManager->SetLinkId(linkId);
120 fem->SetProtectionManager(protectionManager);
121
122 auto ackManager = m_ackManager.Create<WifiAckManager>();
123 ackManager->SetWifiMac(mac);
124 ackManager->SetLinkId(linkId);
125 fem->SetAckManager(ackManager);
126
127 // 11be MLDs require a MAC address to be assigned to each STA
128 fem->SetAddress(device->GetNPhys() > 1 ? Mac48Address::Allocate() : mac->GetAddress());
129 }
130
131 mac->SetFrameExchangeManagers(feManagers);
132
134 mac->SetMacQueueScheduler(queueScheduler);
135
136 // create and install the Multi User Scheduler if this is an HE AP
137 auto apMac = DynamicCast<ApWifiMac>(mac);
138 if (standard >= WIFI_STANDARD_80211ax && m_muScheduler.IsTypeIdSet() && apMac)
139 {
140 auto muScheduler = m_muScheduler.Create<MultiUserScheduler>();
141 apMac->AggregateObject(muScheduler);
142 }
143
144 // create and install the Association Manager if this is a STA
145 auto staMac = DynamicCast<StaWifiMac>(mac);
146 if (staMac)
147 {
149 staMac->SetAssocManager(assocManager);
150 }
151
152 // create and install the EMLSR Manager if this is an EHT non-AP device with EMLSR activated
153 // and association type set to ML setup
154 if (standard >= WIFI_STANDARD_80211be && staMac &&
155 device->GetEhtConfiguration()->m_emlsrActivated &&
156 staMac->GetAssocType() == WifiAssocType::ML_SETUP)
157 {
158 auto emlsrManager = m_emlsrManager.Create<EmlsrManager>();
159 staMac->SetEmlsrManager(emlsrManager);
160 }
161
162 // create and install the AP EMLSR Manager if this is an EHT AP MLD with EMLSR activated
163 if (standard >= WIFI_STANDARD_80211be && apMac && apMac->GetNLinks() > 1 &&
164 device->GetEhtConfiguration()->m_emlsrActivated)
165 {
166 auto apEmlsrManager = m_apEmlsrManager.Create<ApEmlsrManager>();
167 apMac->SetApEmlsrManager(apEmlsrManager);
168 }
169
170 // create and install the GCR Manager if this is a HT-capable AP
171 if (apMac && apMac->GetRobustAVStreamingSupported() && m_gcrManager.IsTypeIdSet())
172 {
173 auto gcrManager = m_gcrManager.Create<GcrManager>();
174 apMac->SetGcrManager(gcrManager);
175 }
176
177 return mac;
178}
179
180} // namespace ns3
ApEmlsrManager is an abstract base class defining the API that EHT AP MLDs with EMLSR activated can u...
Manage a set of ns3::Txop.
EmlsrManager is an abstract base class defining the API that EHT non-AP MLDs with EMLSR activated can...
Hold variables of type enum.
Definition enum.h:52
FrameExchangeManager is a base class handling the basic frame exchange sequences for non-QoS stations...
GcrManager is a base class defining the API to handle 802.11aa GCR.
Definition gcr-manager.h:49
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 AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition object.cc:298
AttributeValue implementation for Pointer.
Definition pointer.h:37
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:66
Handles the packet queue and stores DCF/EDCA access parameters (one Txop per AC).
Definition qos-txop.h:52
Handles the packet queue and stores DCF/EDCA access parameters (one Txop per AC).
Definition txop.h:56
WifiAckManager is an abstract base class.
void SetWifiMac(Ptr< WifiMac > mac)
Set the MAC which is using this Acknowledgment Manager.
Abstract base class for the Association Manager, which manages scanning and association for single li...
ObjectFactory m_apEmlsrManager
AP EMLSR Manager object factory.
std::map< AcIndex, ObjectFactory, std::greater<> > m_edca
QosTxop (EDCA) object factories.
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_dcf
Txop (DCF) object factory.
ObjectFactory m_ackManager
Factory to create an acknowledgment manager.
void SetType(std::string type, Args &&... args)
ObjectFactory m_frameExchangeManager
Frame Exchange Manager object factory.
ObjectFactory m_channelAccessManager
Channel Access Manager object factory.
ObjectFactory m_gcrManager
GCR Manager object factory.
base class for all MAC-level wifi objects.
Definition wifi-mac.h:90
WifiMacQueueScheduler is an abstract base class defining the public interface for a wifi MAC queue sc...
WifiProtectionManager is an abstract base class.
void SetWifiMac(Ptr< WifiMac > mac)
Set the MAC which is using this Protection Manager.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition abort.h:97
WifiStandard
Identifies the IEEE 802.11 specifications that a Wifi device can be configured to use.
@ WIFI_STANDARD_COUNT
@ WIFI_STANDARD_80211be
@ WIFI_STANDARD_80211n
@ WIFI_STANDARD_80211ax
@ WIFI_STANDARD_UNSPECIFIED
@ AC_BE_NQOS
Non-QoS.
Definition qos-utils.h:72
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::string GetFrameExchangeManagerTypeIdName(WifiStandard standard, bool qosSupported)
Get the TypeId name for the FrameExchangeManager corresponding to the given standard.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:580
const std::map< AcIndex, WifiAc > wifiAcList
Map containing the four ACs in increasing order of priority (according to Table 10-1 "UP-to-AC Mappin...
Definition qos-utils.cc:115