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/frame-exchange-manager.h"
24 #include "ns3/multi-user-scheduler.h"
25 #include "ns3/wifi-ack-manager.h"
26 #include "ns3/wifi-assoc-manager.h"
27 #include "ns3/wifi-mac-queue-scheduler.h"
28 #include "ns3/wifi-net-device.h"
29 #include "ns3/wifi-protection-manager.h"
30 
31 namespace ns3
32 {
33 
35 {
36  // By default, we create an AdHoc MAC layer (without QoS).
37  SetType("ns3::AdhocWifiMac");
38 
39  m_assocManager.SetTypeId("ns3::WifiDefaultAssocManager");
40  m_queueScheduler.SetTypeId("ns3::FcfsWifiQueueScheduler");
41  m_protectionManager.SetTypeId("ns3::WifiDefaultProtectionManager");
42  m_ackManager.SetTypeId("ns3::WifiDefaultAckManager");
43 }
44 
46 {
47 }
48 
51 {
52  NS_ABORT_MSG_IF(standard == WIFI_STANDARD_UNSPECIFIED, "No standard specified!");
53 
54  // this is a const method, but we need to force the correct QoS setting
55  ObjectFactory macObjectFactory = m_mac;
56  if (standard >= WIFI_STANDARD_80211n)
57  {
58  macObjectFactory.Set("QosSupported", BooleanValue(true));
59  }
60 
61  Ptr<WifiMac> mac = macObjectFactory.Create<WifiMac>();
62  mac->SetDevice(device);
63  mac->SetAddress(Mac48Address::Allocate());
64  device->SetMac(mac);
65  mac->ConfigureStandard(standard);
66 
68  mac->SetMacQueueScheduler(queueScheduler);
69 
70  // WaveNetDevice stores PHY entities in a different member than WifiNetDevice, hence
71  // GetNPhys() would return 0. We have to attach a protection manager and an ack manager
72  // to the unique instance of frame exchange manager anyway
73  for (uint8_t linkId = 0; linkId < std::max<uint8_t>(device->GetNPhys(), 1); ++linkId)
74  {
75  auto fem = mac->GetFrameExchangeManager(linkId);
76 
77  Ptr<WifiProtectionManager> protectionManager =
79  protectionManager->SetWifiMac(mac);
80  protectionManager->SetLinkId(linkId);
81  fem->SetProtectionManager(protectionManager);
82 
84  ackManager->SetWifiMac(mac);
85  ackManager->SetLinkId(linkId);
86  fem->SetAckManager(ackManager);
87 
88  // 11be MLDs require a MAC address to be assigned to each STA. Note that
89  // FrameExchangeManager objects are created by WifiMac::SetupFrameExchangeManager
90  // (which is invoked by WifiMac::ConfigureStandard, which is called above),
91  // which sets the FrameExchangeManager's address to the address held by WifiMac.
92  // Hence, in case the number of PHY objects is 1, the FrameExchangeManager's
93  // address equals the WifiMac's address.
94  if (device->GetNPhys() > 1)
95  {
96  fem->SetAddress(Mac48Address::Allocate());
97  }
98  }
99 
100  // create and install the Multi User Scheduler if this is an HE AP
101  Ptr<ApWifiMac> apMac;
102  if (standard >= WIFI_STANDARD_80211ax && m_muScheduler.IsTypeIdSet() &&
103  (apMac = DynamicCast<ApWifiMac>(mac)))
104  {
106  apMac->AggregateObject(muScheduler);
107  }
108 
109  // create and install the Association Manager if this is a STA
110  if (auto staMac = DynamicCast<StaWifiMac>(mac); staMac != nullptr)
111  {
113  staMac->SetAssocManager(assocManager);
114  }
115 
116  return mac;
117 }
118 
119 } // namespace ns3
AttributeValue implementation for Boolean.
Definition: boolean.h:37
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_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:94
WifiMacQueueScheduler is an abstract base class defining the public interface for a wifi MAC queue sc...
void SetMac(const Ptr< WifiMac > mac)
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_80211n
@ WIFI_STANDARD_80211ax
@ WIFI_STANDARD_UNSPECIFIED
Every class exported by the ns3 library is enclosed in the ns3 namespace.
mac
Definition: third.py:85