A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
sta-wifi-mac.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2006, 2009 INRIA
3 * Copyright (c) 2009 MIRKO BANCHI
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19 * Mirko Banchi <mk.banchi@gmail.com>
20 */
21
22#ifndef STA_WIFI_MAC_H
23#define STA_WIFI_MAC_H
24
25#include "mgt-headers.h"
26#include "wifi-mac.h"
27
28#include <set>
29#include <variant>
30
33
34namespace ns3
35{
36
37class SupportedRates;
38class CapabilityInformation;
39class RandomVariableStream;
40class WifiAssocManager;
41class EmlsrManager;
42
48enum class WifiScanType : uint8_t
49{
50 ACTIVE = 0,
52};
53
60{
67 struct Channel
68 {
69 uint16_t number{0};
71 };
72
74 using ChannelList = std::list<Channel>;
75
78 std::vector<ChannelList> channelList;
82};
83
90{
95};
96
141class StaWifiMac : public WifiMac
142{
143 public:
145 friend class ::AmpduAggregationTest;
147 friend class ::MultiLinkOperationsTestBase;
148
151 std::variant<MgtBeaconHeader, MgtProbeResponseHeader, MgtAssocResponseHeader>;
152
157 struct ApInfo
158 {
163 {
164 uint8_t localLinkId;
165 uint8_t apLinkId;
167 };
168
171 double m_snr;
174 uint8_t m_linkId;
175 std::list<SetupLinksInfo>
177 };
178
183 static TypeId GetTypeId();
184
185 StaWifiMac();
186 ~StaWifiMac() override;
187
196 void Enqueue(Ptr<Packet> packet, Mac48Address to) override;
197 bool CanForwardPacketsTo(Mac48Address to) const override;
198
202 void SetWifiPhys(const std::vector<Ptr<WifiPhy>>& phys) override;
203
209 void SetAssocManager(Ptr<WifiAssocManager> assocManager);
210
216 void SetEmlsrManager(Ptr<EmlsrManager> emlsrManager);
217
222
228 void SendProbeRequest(uint8_t linkId);
229
237 void ScanningTimeout(const std::optional<ApInfo>& bestAp);
238
244 bool IsAssociated() const;
245
251 std::set<uint8_t> GetSetupLinkIds() const;
252
258 uint16_t GetAssociationId() const;
259
266 void SetPowerSaveMode(const std::pair<bool, uint8_t>& enableLinkIdPair);
267
272 WifiPowerManagementMode GetPmMode(uint8_t linkId) const;
273
279 void SetPmModeAfterAssociation(uint8_t linkId);
280
287 void TxOk(Ptr<const WifiMpdu> mpdu);
288
289 void NotifyChannelSwitching(uint8_t linkId) override;
290
297 void NotifyEmlsrModeChanged(const std::set<uint8_t>& linkIds);
298
303 bool IsEmlsrLink(uint8_t linkId) const;
304
312 void NotifySwitchingEmlsrLink(Ptr<WifiPhy> phy, uint8_t linkId, Time delay);
313
320 void BlockTxOnLink(uint8_t linkId, WifiQueueBlockedReason reason);
321
328 void UnblockTxOnLink(uint8_t linkId, WifiQueueBlockedReason reason);
329
339 int64_t AssignStreams(int64_t stream);
340
341 protected:
348 {
350 ~StaLinkEntity() override;
351
354 std::optional<Mac48Address> bssid;
358 bool emlsrEnabled{false};
359 };
360
367 StaLinkEntity& GetLink(uint8_t linkId) const;
368
375 StaLinkEntity& GetStaLink(const std::unique_ptr<WifiMac::LinkEntity>& link) const;
376
377 public:
382 {
387 REFUSED
388 };
389
390 private:
396 void SetActiveProbing(bool enable);
402 bool GetActiveProbing() const;
403
413 bool CheckSupportedRates(std::variant<MgtBeaconHeader, MgtProbeResponseHeader> frame,
414 uint8_t linkId);
415
416 void Receive(Ptr<const WifiMpdu> mpdu, uint8_t linkId) override;
417 std::unique_ptr<LinkEntity> CreateLinkEntity() const override;
418 Mac48Address DoGetLocalAddress(const Mac48Address& remoteAddr) const override;
419
426 void ReceiveBeacon(Ptr<const WifiMpdu> mpdu, uint8_t linkId);
427
434 void ReceiveProbeResp(Ptr<const WifiMpdu> mpdu, uint8_t linkId);
435
442 void ReceiveAssocResp(Ptr<const WifiMpdu> mpdu, uint8_t linkId);
443
454 void UpdateApInfo(const MgtFrameType& frame,
455 const Mac48Address& apAddr,
456 const Mac48Address& bssid,
457 uint8_t linkId);
458
467 std::variant<MgtAssocRequestHeader, MgtReassocRequestHeader> GetAssociationRequest(
468 bool isReassoc,
469 uint8_t linkId) const;
470
479 void SendAssociationRequest(bool isReassoc);
489 void AssocRequestTimeout();
494 void StartScanning();
500 bool IsWaitAssocResp() const;
504 void MissedBeacons();
510 void RestartBeaconWatchdog(Time delay);
514 void Disassociated();
522 AllSupportedRates GetSupportedRates(uint8_t linkId) const;
531 MultiLinkElement GetMultiLinkElement(bool isReassoc, uint8_t linkId) const;
532
537 std::vector<TidToLinkMapping> GetTidToLinkMappingElements(uint8_t apNegSupport);
538
544 void SetState(MacState value);
545
550 {
554 uint8_t aifsn;
556 };
557
564 void SetEdcaParameters(const EdcaParams& params, uint8_t linkId);
565
570 {
574 uint8_t aifsn;
576 };
577
584 void SetMuEdcaParameters(const MuEdcaParams& params, uint8_t linkId);
585
592 CapabilityInformation GetCapabilities(uint8_t linkId) const;
593
598
606 WifiScanParams::Channel GetCurrentChannel(uint8_t linkId) const;
607
608 void DoInitialize() override;
609 void DoDispose() override;
610
612 uint16_t m_aid;
626
631
638
640 using LinkSetupCallback = void (*)(uint8_t /* link ID */, Mac48Address /* AP address */);
641};
642
650std::ostream& operator<<(std::ostream& os, const StaWifiMac::ApInfo& apInfo);
651
652} // namespace ns3
653
654#endif /* STA_WIFI_MAC_H */
Ampdu Aggregation Test.
An identifier for simulation events.
Definition: event-id.h:55
an EUI-48 address
Definition: mac48-address.h:46
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:36
The Wifi MAC high model for a non-AP STA in a BSS.
Definition: sta-wifi-mac.h:142
std::set< uint8_t > GetSetupLinkIds() const
Get the IDs of the setup links (if any).
void ScanningTimeout(const std::optional< ApInfo > &bestAp)
This method is called after wait beacon timeout or wait probe request timeout has occurred.
Time m_waitBeaconTimeout
wait beacon timeout
Definition: sta-wifi-mac.h:615
void SetPowerSaveMode(const std::pair< bool, uint8_t > &enableLinkIdPair)
Enable or disable Power Save mode on the given link.
Ptr< WifiAssocManager > m_assocManager
Association Manager.
Definition: sta-wifi-mac.h:613
bool m_activeProbing
active probing
Definition: sta-wifi-mac.h:622
void DoInitialize() override
Initialize() implementation.
void SetAssocManager(Ptr< WifiAssocManager > assocManager)
Set the Association Manager.
bool CanForwardPacketsTo(Mac48Address to) const override
Return true if packets can be forwarded to the given destination, false otherwise.
std::unique_ptr< LinkEntity > CreateLinkEntity() const override
Create a LinkEntity object.
void SetState(MacState value)
Set the current MAC state.
Time m_beaconWatchdogEnd
beacon watchdog end
Definition: sta-wifi-mac.h:621
AllSupportedRates GetSupportedRates(uint8_t linkId) const
Return an instance of SupportedRates that contains all rates that we support including HT rates.
void SetEdcaParameters(const EdcaParams &params, uint8_t linkId)
Set the EDCA parameters for the given link.
void UnblockTxOnLink(uint8_t linkId, WifiQueueBlockedReason reason)
Unblock transmissions on the given link for the given reason.
TracedCallback< Mac48Address > m_deAssocLogger
disassociation logger
Definition: sta-wifi-mac.h:634
MacState
The current MAC state of the STA.
Definition: sta-wifi-mac.h:382
void NotifyChannelSwitching(uint8_t linkId) override
Notify that channel on the given link has been switched.
bool GetActiveProbing() const
Return whether active probing is enabled.
EventId m_beaconWatchdog
beacon watchdog
Definition: sta-wifi-mac.h:620
void PhyCapabilitiesChanged()
Indicate that PHY capabilities have changed.
StaLinkEntity & GetStaLink(const std::unique_ptr< WifiMac::LinkEntity > &link) const
Cast the given LinkEntity object to StaLinkEntity.
void ReceiveProbeResp(Ptr< const WifiMpdu > mpdu, uint8_t linkId)
Process the Probe Response frame received on the given link.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
void SetPmModeAfterAssociation(uint8_t linkId)
Set the Power Management mode of the setup links after association.
WifiScanParams::Channel GetCurrentChannel(uint8_t linkId) const
Get the current primary20 channel used on the given link as a (channel number, PHY band) pair.
uint16_t GetAssociationId() const
Return the association ID.
void TryToEnsureAssociated()
Try to ensure that we are associated with an AP by taking an appropriate action depending on the curr...
void ReceiveAssocResp(Ptr< const WifiMpdu > mpdu, uint8_t linkId)
Process the (Re)Association Response frame received on the given link.
void NotifySwitchingEmlsrLink(Ptr< WifiPhy > phy, uint8_t linkId, Time delay)
Notify that the given PHY switched channel to operate on another EMLSR link.
std::variant< MgtAssocRequestHeader, MgtReassocRequestHeader > GetAssociationRequest(bool isReassoc, uint8_t linkId) const
Get the (Re)Association Request frame to send on a given link.
static TypeId GetTypeId()
Get the type ID.
Definition: sta-wifi-mac.cc:58
void(*)(uint8_t, Mac48Address) LinkSetupCallback
TracedCallback signature for link setup completed/canceled events.
Definition: sta-wifi-mac.h:640
void DoDispose() override
Destructor implementation.
void SendProbeRequest(uint8_t linkId)
Enqueue a probe request packet for transmission on the given link.
void BlockTxOnLink(uint8_t linkId, WifiQueueBlockedReason reason)
Block transmissions on the given link for the given reason.
StaLinkEntity & GetLink(uint8_t linkId) const
Get a reference to the link associated with the given ID.
uint32_t m_maxMissedBeacons
maximum missed beacons
Definition: sta-wifi-mac.h:619
TracedCallback< uint8_t, Mac48Address > m_setupCompleted
link setup completed logger
Definition: sta-wifi-mac.h:633
TracedCallback< Mac48Address > m_assocLogger
association logger
Definition: sta-wifi-mac.h:632
void SetWifiPhys(const std::vector< Ptr< WifiPhy > > &phys) override
void SetMuEdcaParameters(const MuEdcaParams &params, uint8_t linkId)
Set the MU EDCA parameters for the given link.
TracedCallback< uint8_t, Mac48Address > m_setupCanceled
link setup canceled logger
Definition: sta-wifi-mac.h:635
void NotifyEmlsrModeChanged(const std::set< uint8_t > &linkIds)
Notify the MAC that EMLSR mode has changed on the given set of links.
bool CheckSupportedRates(std::variant< MgtBeaconHeader, MgtProbeResponseHeader > frame, uint8_t linkId)
Determine whether the supported rates indicated in a given Beacon frame or Probe Response frame fit w...
Mac48Address DoGetLocalAddress(const Mac48Address &remoteAddr) const override
This method is called if this device is an MLD to determine the MAC address of the affiliated STA use...
void RestartBeaconWatchdog(Time delay)
Restarts the beacon timer.
void SetEmlsrManager(Ptr< EmlsrManager > emlsrManager)
Set the EMLSR Manager.
Time m_pmModeSwitchTimeout
PM mode switch timeout.
Definition: sta-wifi-mac.h:625
void Disassociated()
Set the state to unassociated and try to associate again.
Ptr< EmlsrManager > GetEmlsrManager() const
void TxOk(Ptr< const WifiMpdu > mpdu)
Notify that the MPDU we sent was successfully received by the receiver (i.e.
void Receive(Ptr< const WifiMpdu > mpdu, uint8_t linkId) override
This method acts as the MacRxMiddle receive callback and is invoked to notify us that a frame has bee...
WifiTidLinkMapping m_ulTidLinkMappingInAssocReq
store the UL TID-to-Link Mapping included in the Association Request frame
Definition: sta-wifi-mac.h:630
WifiPowerManagementMode GetPmMode(uint8_t linkId) const
Ptr< RandomVariableStream > m_probeDelay
RandomVariable used to randomize the time of the first Probe Response on each channel.
Definition: sta-wifi-mac.h:623
TracedCallback< ApInfo > m_beaconInfo
beacon info logger
Definition: sta-wifi-mac.h:637
void MissedBeacons()
This method is called after we have not received a beacon from the AP on any link.
uint16_t m_aid
Association AID.
Definition: sta-wifi-mac.h:612
MacState m_state
MAC state.
Definition: sta-wifi-mac.h:611
bool IsEmlsrLink(uint8_t linkId) const
void Enqueue(Ptr< Packet > packet, Mac48Address to) override
void StartScanning()
Start the scanning process which trigger active or passive scanning based on the active probing flag.
TracedCallback< Time > m_beaconArrival
beacon arrival logger
Definition: sta-wifi-mac.h:636
void AssocRequestTimeout()
This method is called after the association timeout occurred.
Ptr< EmlsrManager > m_emlsrManager
EMLSR Manager.
Definition: sta-wifi-mac.h:614
void UpdateApInfo(const MgtFrameType &frame, const Mac48Address &apAddr, const Mac48Address &bssid, uint8_t linkId)
Update associated AP's information from the given management frame (Beacon, Probe Response or Associa...
Time m_assocRequestTimeout
association request timeout
Definition: sta-wifi-mac.h:617
void ReceiveBeacon(Ptr< const WifiMpdu > mpdu, uint8_t linkId)
Process the Beacon frame received on the given link.
Time m_probeRequestTimeout
probe request timeout
Definition: sta-wifi-mac.h:616
void SetActiveProbing(bool enable)
Enable or disable active probing.
CapabilityInformation GetCapabilities(uint8_t linkId) const
Return the Capability information for the given link.
bool IsAssociated() const
Return whether we are associated with an AP.
~StaWifiMac() override
std::variant< MgtBeaconHeader, MgtProbeResponseHeader, MgtAssocResponseHeader > MgtFrameType
type of the management frames used to get info about APs
Definition: sta-wifi-mac.h:151
bool IsWaitAssocResp() const
Return whether we are waiting for an association response from an AP.
std::vector< TidToLinkMapping > GetTidToLinkMappingElements(uint8_t apNegSupport)
MultiLinkElement GetMultiLinkElement(bool isReassoc, uint8_t linkId) const
Return the Multi-Link Element to include in the management frames transmitted on the given link.
EventId m_assocRequestEvent
association request event
Definition: sta-wifi-mac.h:618
void SendAssociationRequest(bool isReassoc)
Forward an association or reassociation request packet to the DCF.
WifiTidLinkMapping m_dlTidLinkMappingInAssocReq
store the DL TID-to-Link Mapping included in the Association Request frame
Definition: sta-wifi-mac.h:628
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:59
base class for all MAC-level wifi objects.
Definition: wifi-mac.h:96
WifiScanType
Scan type (active or passive)
Definition: sta-wifi-mac.h:49
WifiPowerManagementMode
Enumeration for power management modes.
Definition: sta-wifi-mac.h:90
WifiPhyBand
Identifies the PHY band.
Definition: wifi-phy-band.h:33
WifiQueueBlockedReason
Enumeration of the reasons to block container queues.
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Definition: qos-utils.h:73
@ WIFI_PM_SWITCHING_TO_ACTIVE
Definition: sta-wifi-mac.h:94
@ WIFI_PM_POWERSAVE
Definition: sta-wifi-mac.h:93
@ WIFI_PM_SWITCHING_TO_PS
Definition: sta-wifi-mac.h:92
@ WIFI_PM_ACTIVE
Definition: sta-wifi-mac.h:91
@ WIFI_PHY_BAND_UNSPECIFIED
Unspecified.
Definition: wifi-phy-band.h:43
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:159
std::map< uint8_t, std::set< uint8_t > > WifiTidLinkMapping
TID-indexed map of the link set to which the TID is mapped.
Definition: wifi-utils.h:74
Struct containing all supported rates.
Struct to hold information regarding observed AP through active/passive scanning.
Definition: sta-wifi-mac.h:158
MgtFrameType m_frame
The body of the management frame used to update AP info.
Definition: sta-wifi-mac.h:172
WifiScanParams::Channel m_channel
The channel the management frame was received on.
Definition: sta-wifi-mac.h:173
std::list< SetupLinksInfo > m_setupLinks
information about the links to setup between MLDs
Definition: sta-wifi-mac.h:176
Mac48Address m_apAddr
AP MAC address.
Definition: sta-wifi-mac.h:170
uint8_t m_linkId
ID of the link used to communicate with the AP.
Definition: sta-wifi-mac.h:174
Mac48Address m_bssid
BSSID.
Definition: sta-wifi-mac.h:169
double m_snr
SNR in linear scale.
Definition: sta-wifi-mac.h:171
uint32_t cwMax
the maximum contention window size
Definition: sta-wifi-mac.h:553
AcIndex ac
the access category
Definition: sta-wifi-mac.h:551
uint32_t cwMin
the minimum contention window size
Definition: sta-wifi-mac.h:552
uint8_t aifsn
the number of slots that make up an AIFS
Definition: sta-wifi-mac.h:554
Time txopLimit
the TXOP limit
Definition: sta-wifi-mac.h:555
Time muEdcaTimer
the MU EDCA timer
Definition: sta-wifi-mac.h:575
uint8_t aifsn
the number of slots that make up an AIFS
Definition: sta-wifi-mac.h:574
uint32_t cwMin
the minimum contention window size
Definition: sta-wifi-mac.h:572
AcIndex ac
the access category
Definition: sta-wifi-mac.h:571
uint32_t cwMax
the maximum contention window size
Definition: sta-wifi-mac.h:573
Struct identifying a channel to scan.
Definition: sta-wifi-mac.h:68
WifiPhyBand band
PHY band.
Definition: sta-wifi-mac.h:70
uint16_t number
channel number
Definition: sta-wifi-mac.h:69
Structure holding scan parameters.
Definition: sta-wifi-mac.h:60
std::list< Channel > ChannelList
typedef for a list of channels
Definition: sta-wifi-mac.h:74
std::vector< ChannelList > channelList
list of channels to scan, for each link
Definition: sta-wifi-mac.h:78
Time probeDelay
delay prior to transmitting a Probe Request
Definition: sta-wifi-mac.h:79
WifiScanType type
indicates either active or passive scanning
Definition: sta-wifi-mac.h:76
Time maxChannelTime
maximum time to spend on each channel
Definition: sta-wifi-mac.h:81
Ssid ssid
desired SSID or wildcard SSID
Definition: sta-wifi-mac.h:77
Time minChannelTime
minimum time to spend on each channel
Definition: sta-wifi-mac.h:80