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/power-save-manager.h"
21#include "ns3/wifi-ack-manager.h"
22#include "ns3/wifi-assoc-manager.h"
23#include "ns3/wifi-mac-queue-scheduler.h"
24#include "ns3/wifi-net-device.h"
25#include "ns3/wifi-protection-manager.h"
26
27#include <sstream>
28#include <vector>
29
30namespace ns3
31{
32
34{
35 // By default, we create an AdHoc MAC layer (without QoS).
36 SetType("ns3::AdhocWifiMac");
37
38 m_dcf.SetTypeId("ns3::Txop");
39 for (const auto& [aci, ac] : wifiAcList)
40 {
41 auto [it, inserted] = m_edca.try_emplace(aci);
42 it->second.SetTypeId("ns3::QosTxop");
43 }
44 m_channelAccessManager.SetTypeId("ns3::ChannelAccessManager");
45 // Setting FEM attributes requires setting a TypeId first. We initialize the TypeId to the FEM
46 // of the latest standard, in order to allow users to set the attributes of all the FEMs. The
47 // Create method will set the requested standard before creating the FEM(s).
49 m_assocManager.SetTypeId("ns3::WifiDefaultAssocManager");
50 m_queueScheduler.SetTypeId("ns3::FcfsWifiQueueScheduler");
51 m_protectionManager.SetTypeId("ns3::WifiDefaultProtectionManager");
52 m_ackManager.SetTypeId("ns3::WifiDefaultAckManager");
53 m_emlsrManager.SetTypeId("ns3::DefaultEmlsrManager");
54 m_apEmlsrManager.SetTypeId("ns3::DefaultApEmlsrManager");
55}
56
60
63{
64 NS_ABORT_MSG_IF(standard == WIFI_STANDARD_UNSPECIFIED, "No standard specified!");
65
66 // this is a const method, but we need to force the correct QoS setting
67 ObjectFactory macObjectFactory = m_mac;
68 if (standard >= WIFI_STANDARD_80211n)
69 {
70 macObjectFactory.Set("QosSupported", BooleanValue(true));
71 }
72
73 // do not create a Txop if the standard is at least 802.11n
74 if (standard < WIFI_STANDARD_80211n)
75 {
76 auto dcf = m_dcf; // create a copy because this is a const method
77 dcf.Set("AcIndex", EnumValue<AcIndex>(AC_BE_NQOS));
78 macObjectFactory.Set("Txop", PointerValue(dcf.Create<Txop>()));
79 }
80 // create (Qos)Txop objects
81 for (auto [aci, edca] : m_edca)
82 {
83 edca.Set("AcIndex", EnumValue<AcIndex>(aci));
84 std::stringstream ss;
85 ss << aci << "_Txop";
86 auto s = ss.str().substr(3); // discard "AC "
87 macObjectFactory.Set(s, PointerValue(edca.Create<QosTxop>()));
88 }
89
90 // WaveNetDevice (through ns-3.38) stores PHY entities in a different member than WifiNetDevice,
91 // hence GetNPhys() would return 0
92 auto nLinks = std::max<uint8_t>(device->GetNPhys(), 1);
93
94 // create Channel Access Managers
95 std::vector<Ptr<ChannelAccessManager>> caManagers;
96 caManagers.reserve(nLinks);
97 for (uint8_t linkId = 0; linkId < nLinks; ++linkId)
98 {
99 caManagers.emplace_back(m_channelAccessManager.Create<ChannelAccessManager>());
100 }
101
102 Ptr<WifiMac> mac = macObjectFactory.Create<WifiMac>();
103 mac->SetDevice(device);
104 mac->SetAddress(Mac48Address::Allocate());
105 device->SetMac(mac);
106 mac->SetChannelAccessManagers(caManagers);
107
108 // create Frame Exchange Managers, each with an attached protection manager and ack manager
109 std::vector<Ptr<FrameExchangeManager>> feManagers;
110 auto frameExchangeManager = m_frameExchangeManager;
111 frameExchangeManager.SetTypeId(
112 GetFrameExchangeManagerTypeIdName(standard, mac->GetQosSupported()));
113 for (uint8_t linkId = 0; linkId < nLinks; ++linkId)
114 {
115 auto fem = frameExchangeManager.Create<FrameExchangeManager>();
116 feManagers.emplace_back(fem);
117
118 auto protectionManager = m_protectionManager.Create<WifiProtectionManager>();
119 protectionManager->SetWifiMac(mac);
120 protectionManager->SetLinkId(linkId);
121 fem->SetProtectionManager(protectionManager);
122
123 auto ackManager = m_ackManager.Create<WifiAckManager>();
124 ackManager->SetWifiMac(mac);
125 ackManager->SetLinkId(linkId);
126 fem->SetAckManager(ackManager);
127
128 // 11be MLDs require a MAC address to be assigned to each STA
129 fem->SetAddress(device->GetNPhys() > 1 ? Mac48Address::Allocate() : mac->GetAddress());
130 }
131
132 mac->SetFrameExchangeManagers(feManagers);
133
135 mac->SetMacQueueScheduler(queueScheduler);
136
137 // create and install the Multi User Scheduler if this is an HE AP
138 auto apMac = DynamicCast<ApWifiMac>(mac);
139 if (standard >= WIFI_STANDARD_80211ax && m_muScheduler.IsTypeIdSet() && apMac)
140 {
141 auto muScheduler = m_muScheduler.Create<MultiUserScheduler>();
142 apMac->AggregateObject(muScheduler);
143 }
144
145 // create and install the Association Manager if this is a STA
146 auto staMac = DynamicCast<StaWifiMac>(mac);
147 if (staMac)
148 {
150 staMac->SetAssocManager(assocManager);
151 }
152
153 // create and install a Power Save Manager if this is a STA and a Power Save Manager typeid
154 // has been set
155 if (staMac && m_powerSaveManager.IsTypeIdSet())
156 {
157 auto powerSaveManager = m_powerSaveManager.Create<PowerSaveManager>();
158 staMac->SetPowerSaveManager(powerSaveManager);
159 }
160
161 // create and install the EMLSR Manager if this is an EHT non-AP device with EMLSR activated
162 // and association type set to ML setup
163 if (standard >= WIFI_STANDARD_80211be && staMac &&
164 device->GetEhtConfiguration()->m_emlsrActivated &&
165 staMac->GetAssocType() == WifiAssocType::ML_SETUP)
166 {
167 auto emlsrManager = m_emlsrManager.Create<EmlsrManager>();
168 staMac->SetEmlsrManager(emlsrManager);
169 }
170
171 // create and install the AP EMLSR Manager if this is an EHT AP MLD with EMLSR activated
172 if (standard >= WIFI_STANDARD_80211be && apMac && apMac->GetNLinks() > 1 &&
173 device->GetEhtConfiguration()->m_emlsrActivated)
174 {
175 auto apEmlsrManager = m_apEmlsrManager.Create<ApEmlsrManager>();
176 apMac->SetApEmlsrManager(apEmlsrManager);
177 }
178
179 // create and install the GCR Manager if this is a HT-capable AP
180 if (apMac && apMac->GetRobustAVStreamingSupported() && m_gcrManager.IsTypeIdSet())
181 {
182 auto gcrManager = m_gcrManager.Create<GcrManager>();
183 apMac->SetGcrManager(gcrManager);
184 }
185
186 return mac;
187}
188
189} // namespace ns3
ApEmlsrManager is an abstract base class defining the API that EHT AP MLDs with EMLSR activated can u...
AttributeValue implementation for Boolean.
Definition boolean.h:26
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:295
AttributeValue implementation for Pointer.
Definition pointer.h:37
PowerSaveManager is an abstract base class.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
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_powerSaveManager
Factory to create a power save manager.
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:74
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:605
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