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