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 * 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: Stefano Avallone <stavallo@unina.it>
18 */
19
20#ifndef WIFI_ASSOC_MANAGER_H
21#define WIFI_ASSOC_MANAGER_H
22
23#include "qos-utils.h"
24#include "sta-wifi-mac.h"
25
26#include <optional>
27#include <set>
28#include <unordered_map>
29
30namespace ns3
31{
32
33/**
34 * \ingroup wifi
35 *
36 * Abstract base class for the Association Manager, which manages
37 * scanning and association for single link devices and ML discovery
38 * and setup for multi-link devices.
39 */
41{
42 /**
43 * Struct providing a function call operator to compare two ApInfo objects.
44 * This struct is used as the Compare template type parameter of the set of
45 * ApInfo objects maintained by the Association Manager.
46 */
48 {
49 /**
50 * Constructor.
51 *
52 * \param manager a pointer to the Association Manager
53 */
54 ApInfoCompare(const WifiAssocManager& manager);
55 /**
56 * Function call operator. Calls the Compare method of the Association Manager.
57 *
58 * \param lhs left hand side ApInfo object
59 * \param rhs right hand side ApInfo object
60 * \return true if the left hand side ApInfo object should be placed before the
61 * right hand side ApInfo object in the sorted list maintained by the
62 * Association Manager, false otherwise
63 */
64 bool operator()(const StaWifiMac::ApInfo& lhs, const StaWifiMac::ApInfo& rhs) const;
65
66 private:
67 const WifiAssocManager& m_manager; ///< Association Manager
68 };
69
70 public:
71 /**
72 * Struct to identify a specific TBTT Information field of a Neighbor AP Information
73 * field in a Reduced Neighbor Report element.
74 */
76 {
77 std::size_t m_nbrApInfoId; ///< Neighbor AP Information field index
78 std::size_t m_tbttInfoFieldId; ///< TBTT Information field index
79 };
80
81 /**
82 * \brief Get the type ID.
83 * \return the object TypeId
84 */
85 static TypeId GetTypeId();
86
87 ~WifiAssocManager() override;
88
89 /**
90 * Set the pointer to the STA wifi MAC.
91 *
92 * \param mac the pointer to the STA wifi MAC
93 */
95
96 /**
97 * Request the Association Manager to start a scanning procedure according to
98 * the given scanning parameters. At subclass' discretion, stored information
99 * about APs matching the given scanning parameters may be used and scanning
100 * not performed.
101 *
102 * \param scanParams the scanning parameters
103 */
104 void StartScanning(WifiScanParams&& scanParams);
105
106 /**
107 * STA wifi MAC received a Beacon frame or Probe Response frame while scanning
108 * and notifies us the AP information contained in the received frame.
109 *
110 * Note that the given ApInfo object is moved to the sorted list of ApInfo objects.
111 *
112 * \param apInfo the AP information contained in the received frame
113 */
114 virtual void NotifyApInfo(const StaWifiMac::ApInfo&& apInfo);
115
116 /**
117 * Notify that the given link has completed channel switching.
118 *
119 * \param linkId the ID of the given link
120 */
121 virtual void NotifyChannelSwitched(uint8_t linkId) = 0;
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 * Extract the best AP to associate with from the sorted list and return
215 * it, if any, to the STA wifi MAC along with the notification that scanning
216 * is completed.
217 */
218 void ScanningTimeout();
219
220 /// typedef for an optional const reference to a ReducedNeighborReport object
221 using OptRnrConstRef = std::optional<std::reference_wrapper<const ReducedNeighborReport>>;
222 /// typedef for an optional const reference to a MultiLinkElement object
223 using OptMleConstRef = std::optional<std::reference_wrapper<const MultiLinkElement>>;
224
225 /**
226 * Check whether 11be Multi-Link setup can be established with the current best AP.
227 *
228 * \param[out] mle const reference to the Multi-Link Element present in the
229 * Beacon/Probe Response received from the best AP, if any
230 * \param[out] rnr const reference to the Reduced Neighbor Report Element present
231 * in the Beacon/Probe Response received from the best AP, if any.
232 * \return whether 11be Multi-Link setup can be established with the current best AP
233 */
235
236 Ptr<StaWifiMac> m_mac; ///< pointer to the STA wifi MAC
237 std::set<uint8_t> m_allowedLinks; /**< "Only Beacon and Probe Response frames received on a
238 link belonging to the this set are processed */
239
240 private:
241 /**
242 * Start a scanning procedure. This method needs to schedule a call to
243 * ScanningTimeout when the scanning procedure is completed.
244 */
245 virtual void DoStartScanning() = 0;
246
247 WifiScanParams m_scanParams; ///< scanning parameters
248 SortedList m_apList; ///< sorted list of candidate APs
249 /// hash table to help locate ApInfo objects in the sorted list based on the BSSID
250 std::unordered_map<Mac48Address, SortedList::const_iterator, WifiAddressHash> m_apListIt;
251};
252
253} // namespace ns3
254
255#endif /* WIFI_ASSOC_MANAGER_H */
A base class which provides memory management and object aggregation.
Definition: object.h:89
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
The Reduced Neighbor Report element.
a unique identifier for an interface.
Definition: type-id.h:59
Abstract base class for the Association Manager, which manages scanning and association for single li...
const SortedList & GetSortedList() const
std::optional< std::reference_wrapper< const MultiLinkElement > > OptMleConstRef
typedef for an optional const reference to a MultiLinkElement object
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.
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.
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...
std::optional< std::reference_wrapper< const ReducedNeighborReport > > OptRnrConstRef
typedef for an optional const reference to a ReducedNeighborReport object
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
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.
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.
Definition: sta-wifi-mac.h:160
Struct providing a function call operator to compare two ApInfo objects.
const WifiAssocManager & m_manager
Association Manager.
bool operator()(const StaWifiMac::ApInfo &lhs, const StaWifiMac::ApInfo &rhs) const
Function call operator.
Structure holding scan parameters.
Definition: sta-wifi-mac.h:62