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