A Discrete-Event Network Simulator
API
ap-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 AP_WIFI_MAC_H
23 #define AP_WIFI_MAC_H
24 
25 #include "wifi-mac-header.h"
26 #include "wifi-mac.h"
27 
28 #include <unordered_map>
29 #include <variant>
30 
31 namespace ns3
32 {
33 
34 struct AllSupportedRates;
35 class CapabilityInformation;
36 class DsssParameterSet;
37 class ErpInformation;
38 class EdcaParameterSet;
39 class MuEdcaParameterSet;
40 class ReducedNeighborReport;
41 class MultiLinkElement;
42 class HtOperation;
43 class VhtOperation;
44 class HeOperation;
45 class EhtOperation;
46 class CfParameterSet;
47 class UniformRandomVariable;
48 class MgtAssocRequestHeader;
49 class MgtReassocRequestHeader;
50 class MgtAssocResponseHeader;
51 class MgtEmlOmn;
52 
54 using AssocReqRefVariant = std::variant<std::reference_wrapper<MgtAssocRequestHeader>,
55  std::reference_wrapper<MgtReassocRequestHeader>>;
56 
64 class ApWifiMac : public WifiMac
65 {
66  public:
71  static TypeId GetTypeId();
72 
73  ApWifiMac();
74  ~ApWifiMac() override;
75 
76  void SetLinkUpCallback(Callback<void> linkUp) override;
77  bool CanForwardPacketsTo(Mac48Address to) const override;
78  void Enqueue(Ptr<Packet> packet, Mac48Address to) override;
79  void Enqueue(Ptr<Packet> packet, Mac48Address to, Mac48Address from) override;
80  bool SupportsSendFrom() const override;
81  Ptr<WifiMacQueue> GetTxopQueue(AcIndex ac) const override;
82  void ConfigureStandard(WifiStandard standard) override;
83 
87  void SetBeaconInterval(Time interval);
91  Time GetBeaconInterval() const;
92 
102  int64_t AssignStreams(int64_t stream);
103 
112  const std::map<uint16_t, Mac48Address>& GetStaList(uint8_t linkId) const;
118  uint16_t GetAssociationId(Mac48Address addr, uint8_t linkId) const;
119 
128  std::optional<uint8_t> IsAssociated(const Mac48Address& address) const;
129 
135  std::optional<Mac48Address> GetMldOrLinkAddressByAid(uint16_t aid) const;
136 
153  uint8_t GetBufferStatus(uint8_t tid, Mac48Address address) const;
163  void SetBufferStatus(uint8_t tid, Mac48Address address, uint8_t size);
172  uint8_t GetMaxBufferStatus(Mac48Address address) const;
173 
174  protected:
181  {
183  ~ApLinkEntity() override;
184 
186  std::map<uint16_t, Mac48Address> staList;
188  uint16_t numNonHtStations{0};
190  0};
192  false};
193  bool shortPreambleEnabled{false};
194  };
195 
202  ApLinkEntity& GetLink(uint8_t linkId) const;
203 
204  std::map<uint16_t, Mac48Address>
207 
208  private:
209  std::unique_ptr<LinkEntity> CreateLinkEntity() const override;
210  Mac48Address DoGetLocalAddress(const Mac48Address& remoteAddr) const override;
211  void Receive(Ptr<const WifiMpdu> mpdu, uint8_t linkId) override;
212 
224  bool ReceiveAssocRequest(const AssocReqRefVariant& assoc,
225  const Mac48Address& from,
226  uint8_t linkId);
227 
239  void ParseReportedStaInfo(const AssocReqRefVariant& assoc, Mac48Address from, uint8_t linkId);
240 
249  void ReceiveEmlOmn(MgtEmlOmn& frame, const Mac48Address& sender, uint8_t linkId);
250 
259  void TxOk(Ptr<const WifiMpdu> mpdu);
269  void TxFailed(WifiMacDropReason timeoutReason, Ptr<const WifiMpdu> mpdu);
270 
288  void ForwardDown(Ptr<Packet> packet, Mac48Address from, Mac48Address to);
297  void ForwardDown(Ptr<Packet> packet, Mac48Address from, Mac48Address to, uint8_t tid);
305  void SendProbeResp(Mac48Address to, uint8_t linkId);
316  using LinkIdStaAddrMap = std::map<uint8_t, Mac48Address>;
328  void SetAid(MgtAssocResponseHeader& assoc, const LinkIdStaAddrMap& linkIdStaAddrMap);
340  const Mac48Address& to,
341  uint8_t linkId);
349  void SendAssocResp(Mac48Address to, bool isReassoc, uint8_t linkId);
356  void SendOneBeacon(uint8_t linkId);
357 
365  void ProcessPowerManagementFlag(Ptr<const WifiMpdu> mpdu, uint8_t linkId);
373  void StaSwitchingToPsMode(const Mac48Address& staAddr, uint8_t linkId);
381  void StaSwitchingToActiveModeOrDeassociated(const Mac48Address& staAddr, uint8_t linkId);
382 
389  CapabilityInformation GetCapabilities(uint8_t linkId) const;
396  ErpInformation GetErpInformation(uint8_t linkId) const;
403  EdcaParameterSet GetEdcaParameterSet(uint8_t linkId) const;
409  std::optional<MuEdcaParameterSet> GetMuEdcaParameterSet() const;
417  std::optional<ReducedNeighborReport> GetReducedNeighborReport(uint8_t linkId) const;
427  MultiLinkElement GetMultiLinkElement(uint8_t linkId,
428  WifiMacType frameType,
436  HtOperation GetHtOperation(uint8_t linkId) const;
443  VhtOperation GetVhtOperation(uint8_t linkId) const;
450  HeOperation GetHeOperation(uint8_t linkId) const;
457  EhtOperation GetEhtOperation(uint8_t linkId) const;
465  AllSupportedRates GetSupportedRates(uint8_t linkId) const;
472  DsssParameterSet GetDsssParameterSet(uint8_t linkId) const;
478  void SetBeaconGeneration(bool enable);
479 
489  void UpdateShortSlotTimeEnabled(uint8_t linkId);
498  void UpdateShortPreambleEnabled(uint8_t linkId);
499 
508  bool GetUseNonErpProtection(uint8_t linkId) const;
509 
510  void DoDispose() override;
511  void DoInitialize() override;
512 
517  uint16_t GetNextAssociationId(std::list<uint8_t> linkIds);
518 
529  std::map<Mac48Address, EventId> m_transitionTimeoutEvents;
530 
532  struct BsrType
533  {
534  uint8_t value;
536  };
537 
539  std::unordered_map<WifiAddressTidPair, BsrType, WifiAddressTidHash> m_bufferStatus;
540 
547  typedef void (*AssociationCallback)(uint16_t aid, Mac48Address address);
548 
551 };
552 
553 } // namespace ns3
554 
555 #endif /* AP_WIFI_MAC_H */
Wi-Fi AP state machine.
Definition: ap-wifi-mac.h:65
void SendAssocResp(Mac48Address to, bool isReassoc, uint8_t linkId)
Forward an association or a reassociation response packet to the DCF/EDCA.
uint16_t GetAssociationId(Mac48Address addr, uint8_t linkId) const
std::unique_ptr< LinkEntity > CreateLinkEntity() const override
Create a LinkEntity object.
Definition: ap-wifi-mac.cc:144
Ptr< Txop > m_beaconTxop
Dedicated Txop for beacons.
Definition: ap-wifi-mac.h:519
void SetBeaconGeneration(bool enable)
Enable or disable beacon generation of the AP.
Definition: ap-wifi-mac.cc:181
void ParseReportedStaInfo(const AssocReqRefVariant &assoc, Mac48Address from, uint8_t linkId)
Given a (Re)Association Request frame body containing a Multi-Link Element, check if a link can be se...
void UpdateShortSlotTimeEnabled(uint8_t linkId)
Update whether short slot time should be enabled or not in the BSS corresponding to the given link.
Definition: ap-wifi-mac.cc:244
const std::map< uint16_t, Mac48Address > & GetStaList(uint8_t linkId) const
Get a const reference to the map of associated stations on the given link.
void DoDispose() override
Destructor implementation.
Definition: ap-wifi-mac.cc:128
void SetBeaconInterval(Time interval)
Definition: ap-wifi-mac.cc:219
bool ReceiveAssocRequest(const AssocReqRefVariant &assoc, const Mac48Address &from, uint8_t linkId)
Check whether the supported rate set included in the received (Re)Association Request frame is compat...
std::map< uint8_t, Mac48Address > LinkIdStaAddrMap
Map of (link ID, remote STA address) of the links to setup.
Definition: ap-wifi-mac.h:316
std::map< Mac48Address, EventId > m_transitionTimeoutEvents
transition timeout events running for EMLSR clients
Definition: ap-wifi-mac.h:529
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...
CapabilityInformation GetCapabilities(uint8_t linkId) const
Return the Capability information of the current AP for the given link.
Definition: ap-wifi-mac.cc:484
Ptr< UniformRandomVariable > m_beaconJitter
UniformRandomVariable used to randomize the time of the first beacon.
Definition: ap-wifi-mac.h:523
void(* AssociationCallback)(uint16_t aid, Mac48Address address)
TracedCallback signature for association/deassociation events.
Definition: ap-wifi-mac.h:547
bool CanForwardPacketsTo(Mac48Address to) const override
Return true if packets can be forwarded to the given destination, false otherwise.
Definition: ap-wifi-mac.cc:392
bool m_enableNonErpProtection
Flag whether protection mechanism is used or not when non-ERP STAs are present within the BSS.
Definition: ap-wifi-mac.h:525
EdcaParameterSet GetEdcaParameterSet(uint8_t linkId) const
Return the EDCA Parameter Set of the current AP for the given link.
Definition: ap-wifi-mac.cc:516
void StaSwitchingToActiveModeOrDeassociated(const Mac48Address &staAddr, uint8_t linkId)
Perform the necessary actions when a given station deassociates or switches from powersave mode to ac...
MultiLinkElement GetMultiLinkElement(uint8_t linkId, WifiMacType frameType, const Mac48Address &to=Mac48Address::GetBroadcast())
Return the Multi-Link Element that the current AP includes in the management frames of the given type...
Definition: ap-wifi-mac.cc:662
HtOperation GetHtOperation(uint8_t linkId) const
Return the HT operation of the current AP for the given link.
Definition: ap-wifi-mac.cc:768
std::optional< Mac48Address > GetMldOrLinkAddressByAid(uint16_t aid) const
void UpdateShortPreambleEnabled(uint8_t linkId)
Update whether short preamble should be enabled or not in the BSS corresponding to the given link.
Definition: ap-wifi-mac.cc:267
void TxOk(Ptr< const WifiMpdu > mpdu)
The packet we sent was successfully received by the receiver (i.e.
std::map< uint16_t, Mac48Address > m_aidToMldOrLinkAddress
Maps AIDs to MLD addresses (for MLDs) or link addresses (in case of single link devices)
Definition: ap-wifi-mac.h:205
TracedCallback< uint16_t, Mac48Address > m_deAssocLogger
deassociation logger
Definition: ap-wifi-mac.h:550
LinkIdStaAddrMap GetLinkIdStaAddrMap(MgtAssocResponseHeader &assoc, const Mac48Address &to, uint8_t linkId)
Get a map of (link ID, remote STA address) of the links to setup.
void SetAid(MgtAssocResponseHeader &assoc, const LinkIdStaAddrMap &linkIdStaAddrMap)
Set the AID field of the given Association Response frame.
bool m_enableBeaconGeneration
Flag whether beacons are being generated.
Definition: ap-wifi-mac.h:520
Time m_beaconInterval
Beacon interval.
Definition: ap-wifi-mac.h:521
uint16_t GetNextAssociationId(std::list< uint8_t > linkIds)
bool m_enableBeaconJitter
Flag whether the first beacon should be generated at random time.
Definition: ap-wifi-mac.h:524
std::unordered_map< WifiAddressTidPair, BsrType, WifiAddressTidHash > m_bufferStatus
Per (MAC address, TID) buffer status reports.
Definition: ap-wifi-mac.h:539
void SendProbeResp(Mac48Address to, uint8_t linkId)
Send a Probe Response in response to a Probe Request received from the STA with the given address on ...
Definition: ap-wifi-mac.cc:969
DsssParameterSet GetDsssParameterSet(uint8_t linkId) const
Return the DSSS Parameter Set that we support on the given link.
Definition: ap-wifi-mac.cc:474
TracedCallback< uint16_t, Mac48Address > m_assocLogger
association logger
Definition: ap-wifi-mac.h:549
Time GetBeaconInterval() const
Definition: ap-wifi-mac.cc:200
static TypeId GetTypeId()
Get the type ID.
Definition: ap-wifi-mac.cc:58
std::optional< ReducedNeighborReport > GetReducedNeighborReport(uint8_t linkId) const
Return the Reduced Neighbor Report (RNR) element that the current AP sends on the given link,...
Definition: ap-wifi-mac.cc:631
void ReceiveEmlOmn(MgtEmlOmn &frame, const Mac48Address &sender, uint8_t linkId)
Take necessary actions upon receiving the given EML Operating Mode Notification frame from the given ...
void Enqueue(Ptr< Packet > packet, Mac48Address to) override
Definition: ap-wifi-mac.cc:412
uint8_t GetMaxBufferStatus(Mac48Address address) const
Return the maximum among the values of the Queue Size subfield of the last QoS Data or QoS Null frame...
Time m_bsrLifetime
Lifetime of Buffer Status Reports.
Definition: ap-wifi-mac.h:527
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Definition: ap-wifi-mac.cc:236
ApLinkEntity & GetLink(uint8_t linkId) const
Get a reference to the link associated with the given ID.
Definition: ap-wifi-mac.cc:150
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...
uint8_t GetBufferStatus(uint8_t tid, Mac48Address address) const
Return the value of the Queue Size subfield of the last QoS Data or QoS Null frame received from the ...
EhtOperation GetEhtOperation(uint8_t linkId) const
Return the EHT operation of the current AP for the given link.
Definition: ap-wifi-mac.cc:945
void ConfigureStandard(WifiStandard standard) override
Definition: ap-wifi-mac.cc:156
ErpInformation GetErpInformation(uint8_t linkId) const
Return the ERP information of the current AP for the given link.
Definition: ap-wifi-mac.cc:495
void SetLinkUpCallback(Callback< void > linkUp) override
Definition: ap-wifi-mac.cc:207
VhtOperation GetVhtOperation(uint8_t linkId) const
Return the VHT operation of the current AP for the given link.
Definition: ap-wifi-mac.cc:866
~ApWifiMac() override
Definition: ap-wifi-mac.cc:122
void TxFailed(WifiMacDropReason timeoutReason, Ptr< const WifiMpdu > mpdu)
The packet we sent was successfully received by the receiver (i.e.
HeOperation GetHeOperation(uint8_t linkId) const
Return the HE operation of the current AP for the given link.
Definition: ap-wifi-mac.cc:915
void SetBufferStatus(uint8_t tid, Mac48Address address, uint8_t size)
Store the value of the Queue Size subfield of the last QoS Data or QoS Null frame received from the s...
std::optional< MuEdcaParameterSet > GetMuEdcaParameterSet() const
Return the MU EDCA Parameter Set of the current AP, if one needs to be advertised.
Definition: ap-wifi-mac.cc:563
void ProcessPowerManagementFlag(Ptr< const WifiMpdu > mpdu, uint8_t linkId)
Process the Power Management bit in the Frame Control field of an MPDU successfully received on the g...
void DeaggregateAmsduAndForward(Ptr< const WifiMpdu > mpdu) override
This method is called to de-aggregate an A-MSDU and forward the constituent packets up the stack.
bool SupportsSendFrom() const override
Definition: ap-wifi-mac.cc:422
MgtAssocResponseHeader GetAssocResp(Mac48Address to, uint8_t linkId)
Get the Association Response frame to send on a given link.
void ForwardDown(Ptr< Packet > packet, Mac48Address from, Mac48Address to)
Forward the packet down to DCF/EDCAF (enqueue the packet).
Definition: ap-wifi-mac.cc:291
void DoInitialize() override
Initialize() implementation.
std::optional< uint8_t > IsAssociated(const Mac48Address &address) const
Get the ID of a link (if any) that has been setup with the station having the given MAC address.
void SendOneBeacon(uint8_t linkId)
Forward a beacon packet to the beacon special DCF for transmission on the given link.
Ptr< WifiMacQueue > GetTxopQueue(AcIndex ac) const override
Get the wifi MAC queue of the (Qos)Txop associated with the given AC, if such (Qos)Txop is installed,...
Definition: ap-wifi-mac.cc:171
bool GetUseNonErpProtection(uint8_t linkId) const
Return whether protection for non-ERP stations is used in the BSS corresponding to the given link.
void StaSwitchingToPsMode(const Mac48Address &staAddr, uint8_t linkId)
Perform the necessary actions when a given station switches from active mode to powersave mode.
AllSupportedRates GetSupportedRates(uint8_t linkId) const
Return an instance of SupportedRates that contains all rates that we support for the given link (incl...
Definition: ap-wifi-mac.cc:429
The DSSS Parameter Set.
The EDCA Parameter Set.
EHT Operation Information Element.
Definition: eht-operation.h:66
The ErpInformation Information Element.
An identifier for simulation events.
Definition: event-id.h:55
The HE Operation Information Element.
Definition: he-operation.h:36
The HT Operation Information Element.
Definition: ht-operation.h:51
an EUI-48 address
Definition: mac48-address.h:46
static Mac48Address GetBroadcast()
Implement the header for management frames of type association and reassociation response.
Definition: mgt-headers.h:334
Implement the header for Action frames of type EML Operating Mode Notification.
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
The VHT Operation Information Element.
Definition: vht-operation.h:36
base class for all MAC-level wifi objects.
Definition: wifi-mac.h:96
WifiStandard
Identifies the IEEE 802.11 specifications that a Wifi device can be configured to use.
WifiMacDropReason
The reason why an MPDU was dropped.
Definition: wifi-mac.h:77
AcIndex
This enumeration defines the Access Categories as an enumeration with values corresponding to the AC ...
Definition: qos-utils.h:73
address
Definition: first.py:47
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::variant< std::reference_wrapper< MgtAssocRequestHeader >, std::reference_wrapper< MgtReassocRequestHeader > > AssocReqRefVariant
variant holding a reference to a (Re)Association Request
Definition: ap-wifi-mac.h:55
WifiMacType
Combination of valid MAC header type/subtype.
Struct containing all supported rates.
store value and timestamp for each Buffer Status Report
Definition: ap-wifi-mac.h:533
Time timestamp
timestamp of BSR
Definition: ap-wifi-mac.h:535
uint8_t value
value of BSR
Definition: ap-wifi-mac.h:534