A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-assoc-manager.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Universita' degli Studi di Napoli Federico II
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Stefano Avallone <stavallo@unina.it>
7 */
8
9#ifndef WIFI_ASSOC_MANAGER_H
10#define WIFI_ASSOC_MANAGER_H
11
12#include "qos-utils.h"
13#include "sta-wifi-mac.h"
14
15#include "ns3/wifi-export.h"
16
17#include <optional>
18#include <set>
19#include <unordered_map>
20
21namespace ns3
22{
23
24/**
25 * @ingroup wifi
26 *
27 * Abstract base class for the Association Manager, which manages
28 * scanning and association for single link devices and ML discovery
29 * and setup for multi-link devices.
30 */
31class WIFI_EXPORT WifiAssocManager : public Object
32{
33 /**
34 * Struct providing a function call operator to compare two ApInfo objects.
35 * This struct is used as the Compare template type parameter of the set of
36 * ApInfo objects maintained by the Association Manager.
37 */
38 struct WIFI_EXPORT ApInfoCompare
39 {
40 /**
41 * Constructor.
42 *
43 * @param manager a pointer to the Association Manager
44 */
45 ApInfoCompare(const WifiAssocManager& manager);
46 /**
47 * Function call operator. Calls the Compare method of the Association Manager.
48 *
49 * @param lhs left hand side ApInfo object
50 * @param rhs right hand side ApInfo object
51 * @return true if the left hand side ApInfo object should be placed before the
52 * right hand side ApInfo object in the sorted list maintained by the
53 * Association Manager, false otherwise
54 */
55 bool operator()(const StaWifiMac::ApInfo& lhs, const StaWifiMac::ApInfo& rhs) const;
56
57 private:
58 const WifiAssocManager& m_manager; ///< Association Manager
59 };
60
61 public:
62 /**
63 * Struct to identify a specific TBTT Information field of a Neighbor AP Information
64 * field in a Reduced Neighbor Report element.
65 */
66 struct WIFI_EXPORT RnrLinkInfo
67 {
68 std::size_t m_nbrApInfoId; ///< Neighbor AP Information field index
69 std::size_t m_tbttInfoFieldId; ///< TBTT Information field index
70 };
71
72 /**
73 * @brief Get the type ID.
74 * @return the object TypeId
75 */
76 static TypeId GetTypeId();
77
78 ~WifiAssocManager() override;
79
80 /**
81 * Set the pointer to the STA wifi MAC.
82 *
83 * @param mac the pointer to the STA wifi MAC
84 */
86
87 /**
88 * Request the Association Manager to start a scanning procedure according to
89 * the given scanning parameters. At subclass' discretion, stored information
90 * about APs matching the given scanning parameters may be used and scanning
91 * not performed.
92 *
93 * @param scanParams the scanning parameters
94 */
95 void StartScanning(WifiScanParams&& scanParams);
96
97 /**
98 * STA wifi MAC received a Beacon frame or Probe Response frame while scanning
99 * and notifies us the AP information contained in the received frame.
100 *
101 * Note that the given ApInfo object is moved to the sorted list of ApInfo objects.
102 *
103 * @param apInfo the AP information contained in the received frame
104 */
105 virtual void NotifyApInfo(const StaWifiMac::ApInfo&& apInfo);
106
107 /**
108 * Notify that the given link has completed channel switching.
109 *
110 * @param linkId the ID of the given link
111 */
112 virtual void NotifyChannelSwitched(uint8_t linkId) = 0;
113
114 /**
115 * Notify that ML setup has been completed and link IDs have been swapped. This method
116 * updates the link IDs in the information gathered so far.
117 *
118 * @param swapInfo a set of pairs (from, to) each mapping a current link ID to the
119 * link ID it has to become (i.e., link 'from' becomes link 'to')
120 */
121 void NotifyLinkSwapped(const std::map<uint8_t, uint8_t>& swapInfo);
122
123 /**
124 * Compare two ApInfo objects for the purpose of keeping a sorted list of
125 * ApInfo objects.
126 *
127 * @param lhs left hand side ApInfo object
128 * @param rhs right hand side ApInfo object
129 * @return true if the left hand side ApInfo object should be placed before the
130 * right hand side ApInfo object in the sorted list of ApInfo objects,
131 * false otherwise
132 */
133 virtual bool Compare(const StaWifiMac::ApInfo& lhs, const StaWifiMac::ApInfo& rhs) const = 0;
134
135 /**
136 * Search the given RNR element for APs affiliated to the same AP MLD as the
137 * reporting AP. The search starts at the given Neighbor AP Information field.
138 *
139 * @param rnr the given RNR element
140 * @param nbrApInfoId the index of the given Neighbor AP Information field
141 * @return the index of the Neighbor AP Information field and the index of the
142 * TBTT Information field containing the next affiliated AP, if any.
143 */
144 static std::optional<WifiAssocManager::RnrLinkInfo> GetNextAffiliatedAp(
145 const ReducedNeighborReport& rnr,
146 std::size_t nbrApInfoId);
147
148 /**
149 * Find all the APs affiliated to the same AP MLD as the reporting AP that sent
150 * the given RNR element.
151 *
152 * @param rnr the given RNR element
153 * @return a list containing the index of the Neighbor AP Information field and the index of the
154 * TBTT Information field containing all the affiliated APs
155 */
156 static std::list<WifiAssocManager::RnrLinkInfo> GetAllAffiliatedAps(
157 const ReducedNeighborReport& rnr);
158
159 protected:
160 /**
161 * Constructor (protected as this is an abstract base class)
162 */
164 void DoDispose() override;
165
166 /// typedef for the sorted list of ApInfo objects
167 using SortedList = std::set<StaWifiMac::ApInfo, ApInfoCompare>;
168
169 /**
170 * @return a const reference to the sorted list of ApInfo objects.
171 */
172 const SortedList& GetSortedList() const;
173
174 /**
175 * Get a reference to the list of the links to setup with the given AP. This method
176 * allows subclasses to modify such a list.
177 *
178 * @param apInfo the info about the given AP
179 * @return a reference to the list of the links to setup with the given AP
180 */
181 std::list<StaWifiMac::ApInfo::SetupLinksInfo>& GetSetupLinks(const StaWifiMac::ApInfo& apInfo);
182
183 /**
184 * @return the scanning parameters.
185 */
186 const WifiScanParams& GetScanParams() const;
187
188 /**
189 * Check whether the given AP information match the current scanning parameters.
190 *
191 * @param apInfo the given AP information
192 * @return whether the given AP information match the current scanning parameters
193 */
194 bool MatchScanParams(const StaWifiMac::ApInfo& apInfo) const;
195
196 /**
197 * Allow subclasses to choose whether the given ApInfo shall be considered
198 * and hence inserted in the sorted list of ApInfo objects.
199 *
200 * @param apInfo the apInfo object to insert
201 * @return true if the apInfo object can be inserted, false otherwise
202 */
203 virtual bool CanBeInserted(const StaWifiMac::ApInfo& apInfo) const = 0;
204 /**
205 * Allow subclasses to choose whether the given ApInfo shall be returned or
206 * discarded when the STA wifi MAC requests information on the best AP.
207 *
208 * @param apInfo the apInfo object to return
209 * @return true if the apInfo object can be returned, false otherwise
210 */
211 virtual bool CanBeReturned(const StaWifiMac::ApInfo& apInfo) const = 0;
212
213 /**
214 * Check whether the channel width of the STA is compatible with the channel width of the
215 * operating channel of a given AP. A channel width is compatible if the STA can advertise it to
216 * the AP, or AP operates on a channel width that is equal or lower than that channel width
217 *
218 * @param apInfo the given AP information
219 * @return true if the channel width of the STA is compatible, false otherwise
220 */
221 bool IsChannelWidthCompatible(const StaWifiMac::ApInfo& apInfo) const;
222
223 /**
224 * Extract the best AP to associate with from the sorted list and return
225 * it, if any, to the STA wifi MAC along with the notification that scanning
226 * is completed.
227 */
228 void ScanningTimeout();
229
230 /// typedef for an optional const reference to a ReducedNeighborReport object
231 using OptRnrConstRef = std::optional<std::reference_wrapper<const ReducedNeighborReport>>;
232 /// typedef for an optional const reference to a MultiLinkElement object
233 using OptMleConstRef = std::optional<std::reference_wrapper<const MultiLinkElement>>;
234
235 /**
236 * Check whether 11be Multi-Link setup can be established with the current best AP.
237 *
238 * @param [out] mle const reference to the Multi-Link Element present in the
239 * Beacon/Probe Response received from the best AP, if any
240 * @param [out] rnr const reference to the Reduced Neighbor Report Element present
241 * in the Beacon/Probe Response received from the best AP, if any.
242 * @return whether 11be Multi-Link setup can be established with the current best AP
243 */
245
246 Ptr<StaWifiMac> m_mac; ///< pointer to the STA wifi MAC
247 std::set<uint8_t> m_allowedLinks; /**< "Only Beacon and Probe Response frames received on a
248 link belonging to the this set are processed */
249
250 bool m_allowAssocAllChannelWidths; ///< flag whether the check on channel width compatibility
251 ///< with the candidate AP should be skipped
252
253 private:
254 /**
255 * Start a scanning procedure. This method needs to schedule a call to
256 * ScanningTimeout when the scanning procedure is completed.
257 */
258 virtual void DoStartScanning() = 0;
259
260 WifiScanParams m_scanParams; ///< scanning parameters
261 SortedList m_apList; ///< sorted list of candidate APs
262 /// hash table to help locate ApInfo objects in the sorted list based on the BSSID
263 std::unordered_map<Mac48Address, SortedList::const_iterator, WifiAddressHash> m_apListIt;
264};
265
266} // namespace ns3
267
268#endif /* WIFI_ASSOC_MANAGER_H */
Object()
Caller graph was not generated because of its size.
Definition object.cc:93
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
The Reduced Neighbor Report element.
a unique identifier for an interface.
Definition type-id.h:50
const SortedList & GetSortedList() const
virtual void NotifyChannelSwitched(uint8_t linkId)=0
Notify that the given link has completed channel switching.
virtual void NotifyApInfo(const StaWifiMac::ApInfo &&apInfo)
STA wifi MAC received a Beacon frame or Probe Response frame while scanning and notifies us the AP in...
Ptr< StaWifiMac > m_mac
pointer to the STA wifi MAC
virtual void DoStartScanning()=0
Start a scanning procedure.
void SetStaWifiMac(Ptr< StaWifiMac > mac)
Set the pointer to the STA wifi MAC.
bool IsChannelWidthCompatible(const StaWifiMac::ApInfo &apInfo) const
Check whether the channel width of the STA is compatible with the channel width of the operating chan...
std::optional< std::reference_wrapper< const MultiLinkElement > > OptMleConstRef
typedef for an optional const reference to a MultiLinkElement object
std::list< StaWifiMac::ApInfo::SetupLinksInfo > & GetSetupLinks(const StaWifiMac::ApInfo &apInfo)
Get a reference to the list of the links to setup with the given AP.
std::optional< std::reference_wrapper< const ReducedNeighborReport > > OptRnrConstRef
typedef for an optional const reference to a ReducedNeighborReport object
void ScanningTimeout()
Extract the best AP to associate with from the sorted list and return it, if any, to the STA wifi MAC...
virtual bool CanBeInserted(const StaWifiMac::ApInfo &apInfo) const =0
Allow subclasses to choose whether the given ApInfo shall be considered and hence inserted in the sor...
SortedList m_apList
sorted list of candidate APs
static std::optional< WifiAssocManager::RnrLinkInfo > GetNextAffiliatedAp(const ReducedNeighborReport &rnr, std::size_t nbrApInfoId)
Search the given RNR element for APs affiliated to the same AP MLD as the reporting AP.
WifiScanParams m_scanParams
scanning parameters
virtual bool CanBeReturned(const StaWifiMac::ApInfo &apInfo) const =0
Allow subclasses to choose whether the given ApInfo shall be returned or discarded when the STA wifi ...
void StartScanning(WifiScanParams &&scanParams)
Request the Association Manager to start a scanning procedure according to the given scanning paramet...
std::set< StaWifiMac::ApInfo, ApInfoCompare > SortedList
typedef for the sorted list of ApInfo objects
bool m_allowAssocAllChannelWidths
flag whether the check on channel width compatibility with the candidate AP should be skipped
std::set< uint8_t > m_allowedLinks
"Only Beacon and Probe Response frames received on a link belonging to the this set are processed
virtual bool Compare(const StaWifiMac::ApInfo &lhs, const StaWifiMac::ApInfo &rhs) const =0
Compare two ApInfo objects for the purpose of keeping a sorted list of ApInfo objects.
static std::list< WifiAssocManager::RnrLinkInfo > GetAllAffiliatedAps(const ReducedNeighborReport &rnr)
Find all the APs affiliated to the same AP MLD as the reporting AP that sent the given RNR element.
void NotifyLinkSwapped(const std::map< uint8_t, uint8_t > &swapInfo)
Notify that ML setup has been completed and link IDs have been swapped.
static TypeId GetTypeId()
Get the type ID.
const WifiScanParams & GetScanParams() const
void DoDispose() override
Destructor implementation.
std::unordered_map< Mac48Address, SortedList::const_iterator, WifiAddressHash > m_apListIt
hash table to help locate ApInfo objects in the sorted list based on the BSSID
bool CanSetupMultiLink(OptMleConstRef &mle, OptRnrConstRef &rnr)
Check whether 11be Multi-Link setup can be established with the current best AP.
WifiAssocManager()
Constructor (protected as this is an abstract base class).
bool MatchScanParams(const StaWifiMac::ApInfo &apInfo) const
Check whether the given AP information match the current scanning parameters.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Struct to hold information regarding observed AP through active/passive scanning.
const WifiAssocManager & m_manager
Association Manager.
ApInfoCompare(const WifiAssocManager &manager)
Constructor.
bool operator()(const StaWifiMac::ApInfo &lhs, const StaWifiMac::ApInfo &rhs) const
Function call operator.
Structure holding scan parameters.