A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-default-assoc-manager.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Universita' degli Studi di Napoli Federico II
3
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 * Author: Stefano Avallone <stavallo@unina.it>
8 */
9
11
12#include "sta-wifi-mac.h"
13#include "wifi-net-device.h"
14#include "wifi-phy.h"
15
16#include "ns3/boolean.h"
17#include "ns3/log.h"
18#include "ns3/simulator.h"
19#include "ns3/vht-configuration.h"
20
21#include <algorithm>
22
23namespace ns3
24{
25
26NS_LOG_COMPONENT_DEFINE("WifiDefaultAssocManager");
27
29
32{
33 static TypeId tid =
34 TypeId("ns3::WifiDefaultAssocManager")
36 .AddConstructor<WifiDefaultAssocManager>()
37 .SetGroupName("Wifi")
38 .AddAttribute("ChannelSwitchTimeout",
39 "After requesting a channel switch on a link to setup that link, "
40 "wait at most this amount of time. If a channel switch is not "
41 "notified within this amount of time, we give up setting up that link.",
45 .AddAttribute(
46 "SkipAssocIncompatibleChannelWidth",
47 "If set to true, it does not include APs with incompatible channel width with the "
48 "STA in the list of candidate APs. An incompatible channel width is one that the "
49 "STA cannot advertise to the AP, unless AP operates on a channel width that is "
50 "equal or lower than that channel width.",
51 BooleanValue(false),
54 .AddAttribute(
55 "SkipScanningIfApInfoAvail",
56 "If this attribute is set to true, any existing AP information (gathered "
57 "from previous scanning) can be used instead of starting a new scanning "
58 "procedure. If this attribute is set to false, existing AP information "
59 "is disregarded and a new scanning procedure is started when requested.",
60 BooleanValue(true),
63 return tid;
64}
65
70
75
76void
84
85bool
87{
88 return lhs.m_snr > rhs.m_snr;
89}
90
91void
93{
94 NS_LOG_FUNCTION(this);
95
96 // if there are entries in the sorted list of AP information, reuse them and
97 // do not perform scanning if SkipScanningIfApInfoAvail is set to true
99 {
101 return;
102 }
103
104 const_cast<SortedList&>(GetSortedList()).clear();
105 m_probeRequestEvent.Cancel();
106 m_waitBeaconEvent.Cancel();
107
109 {
110 for (uint8_t linkId = 0; linkId < m_mac->GetNLinks(); linkId++)
111 {
114 m_mac,
115 m_mac->GetProbeRequest(linkId),
116 linkId,
119 }
121 Simulator::Schedule(GetScanParams().probeDelay + GetScanParams().maxChannelTime,
123 this);
124 }
125 else
126 {
129 this);
130 }
131}
132
133void
135{
136 NS_LOG_FUNCTION(this);
137
138 OptMleConstRef mle;
139 OptRnrConstRef rnr;
140 std::list<WifiAssocManager::RnrLinkInfo> apList;
141
142 // If multi-link setup is not possible, just call ScanningTimeout() and return
143 if (!CanSetupMultiLink(mle, rnr) || (apList = GetAllAffiliatedAps(*rnr)).empty())
144 {
146 return;
147 }
148
149 auto& bestAp = *GetSortedList().begin();
150 auto& setupLinks = GetSetupLinks(bestAp);
151
152 setupLinks.clear();
153 setupLinks.emplace_back(StaWifiMac::ApInfo::SetupLinksInfo{bestAp.m_linkId,
154 mle->get().GetLinkIdInfo(),
155 bestAp.m_bssid});
156
157 // sort local PHY objects so that radios with constrained PHY band comes first,
158 // then radios with no constraint
159 std::list<uint8_t> localLinkIds;
160
161 for (const auto linkId : m_mac->GetLinkIds())
162 {
163 if (linkId == bestAp.m_linkId)
164 {
165 // this link has been already added (it is the link on which the Beacon/Probe
166 // Response was received)
167 continue;
168 }
169
170 if (m_mac->GetWifiPhy(linkId)->HasFixedPhyBand())
171 {
172 localLinkIds.push_front(linkId);
173 }
174 else
175 {
176 localLinkIds.push_back(linkId);
177 }
178 }
179
180 // iterate over all the local links and find if we can setup a link for each of them
181 for (const auto& linkId : localLinkIds)
182 {
183 auto phy = m_mac->GetWifiPhy(linkId);
184 auto apIt = apList.begin();
185
186 while (apIt != apList.end())
187 {
188 auto apChannel = rnr->get().GetOperatingChannel(apIt->m_nbrApInfoId);
189
190 // we cannot setup a link with this affiliated AP if this PHY object is
191 // constrained to operate in the current PHY band and this affiliated AP
192 // is operating in a different PHY band than this PHY object
193 if (phy->HasFixedPhyBand() && phy->GetPhyBand() != apChannel.GetPhyBand())
194 {
195 apIt++;
196 continue;
197 }
198
199 bool needChannelSwitch = false;
200 if (phy->GetOperatingChannel() != apChannel)
201 {
202 needChannelSwitch = true;
203 }
204
205 if (needChannelSwitch && phy->IsStateSwitching())
206 {
207 // skip this affiliated AP, which is operating on a different channel
208 // than ours, because we are already switching channel and cannot
209 // schedule another channel switch to match the affiliated AP channel
210 apIt++;
211 continue;
212 }
213
214 // if we get here, it means we can setup a link with this affiliated AP
215 // set the BSSID for this link
216 Mac48Address bssid = rnr->get().GetBssid(apIt->m_nbrApInfoId, apIt->m_tbttInfoFieldId);
217 setupLinks.emplace_back(StaWifiMac::ApInfo::SetupLinksInfo{
218 linkId,
219 rnr->get().GetMldParameters(apIt->m_nbrApInfoId, apIt->m_tbttInfoFieldId).linkId,
220 bssid});
221
222 if (needChannelSwitch)
223 {
224 if (phy->IsStateSleep())
225 {
226 // switching channel while a PHY is in sleep state fails
227 phy->ResumeFromSleep();
228 }
229
230 // switch this link to using the channel used by a reported AP (or one of its
231 // primary subchannels in case the reported AP has larger channel width than the one
232 // supported by the non-AP MLD)
233 if (apChannel.GetTotalWidth() > phy->GetChannelWidth())
234 {
235 apChannel = apChannel.GetPrimaryChannel(phy->GetChannelWidth());
236 }
237
238 NS_LOG_DEBUG("Switch link " << +linkId << " to using " << apChannel);
239 phy->SetOperatingChannel(apChannel);
240 // actual channel switching may be delayed, thus setup a channel switch timer
241 m_channelSwitchInfo.resize(m_mac->GetNLinks());
242 m_channelSwitchInfo[linkId].timer.Cancel();
243 m_channelSwitchInfo[linkId].timer =
246 this,
247 linkId);
248 m_channelSwitchInfo[linkId].apLinkAddress = bssid;
249 m_channelSwitchInfo[linkId].apMldAddress = mle->get().GetMldMacAddress();
250 }
251
252 // remove the affiliated AP with which we are going to setup a link and move
253 // to the next local linkId
254 apList.erase(apIt);
255 break;
256 }
257 }
258
259 if (std::none_of(m_channelSwitchInfo.begin(), m_channelSwitchInfo.end(), [](auto&& info) {
260 return info.timer.IsPending();
261 }))
262 {
263 // we are done
265 }
266}
267
268void
270{
271 NS_LOG_FUNCTION(this << +linkId);
272 if (m_channelSwitchInfo.size() > linkId && m_channelSwitchInfo[linkId].timer.IsPending())
273 {
274 // we were waiting for this notification
275 m_channelSwitchInfo[linkId].timer.Cancel();
276
277 if (std::none_of(m_channelSwitchInfo.begin(), m_channelSwitchInfo.end(), [](auto&& info) {
278 return info.timer.IsPending();
279 }))
280 {
281 // we are done
283 }
284 }
285}
286
287void
289{
290 NS_LOG_FUNCTION(this << +linkId);
291
292 // we give up setting up this link
293 auto& bestAp = *GetSortedList().begin();
294 auto& setupLinks = GetSetupLinks(bestAp);
295 auto it = std::find_if(setupLinks.begin(), setupLinks.end(), [&linkId](auto&& linkIds) {
296 return linkIds.localLinkId == linkId;
297 });
298 NS_ASSERT(it != setupLinks.end());
299 setupLinks.erase(it);
300
301 if (std::none_of(m_channelSwitchInfo.begin(), m_channelSwitchInfo.end(), [](auto&& info) {
302 return info.timer.IsPending();
303 }))
304 {
305 // we are done
307 }
308}
309
310bool
315
316bool
318{
319 return true;
320}
321
322} // namespace ns3
an EUI-48 address
static Mac48Address GetBroadcast()
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:580
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
Definition simulator.h:614
void EnqueueProbeRequest(const MgtProbeRequestHeader &probeReq, uint8_t linkId, const Mac48Address &addr1=Mac48Address::GetBroadcast(), const Mac48Address &addr3=Mac48Address::GetBroadcast())
Enqueue the given probe request packet for transmission on the given link.
a unique identifier for an interface.
Definition type-id.h:50
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1003
const SortedList & GetSortedList() const
Ptr< StaWifiMac > m_mac
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...
std::set< StaWifiMac::ApInfo, ApInfoCompare > SortedList
typedef for the 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.
const WifiScanParams & GetScanParams() const
void DoDispose() override
Destructor implementation.
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).
Default wifi Association Manager.
void EndScanning()
Perform operations to do at the end of a scanning procedure, such as identifying the links to setup i...
void DoDispose() override
Destructor implementation.
bool m_skipAssocIncompatibleChannelWidth
flag whether to skip APs with incompatible channel width
EventId m_probeRequestEvent
probe request event
void DoStartScanning() override
Start a scanning procedure.
bool CanBeInserted(const StaWifiMac::ApInfo &apInfo) const override
Allow subclasses to choose whether the given ApInfo shall be considered and hence inserted in the sor...
Time m_channelSwitchTimeout
maximum delay for channel switching
void NotifyChannelSwitched(uint8_t linkId) override
Notify that the given link has completed channel switching.
bool m_skipScanningIfApInfoAvail
whether AP information from a scanning procedure should be retained and used afterwards to avoid new ...
bool Compare(const StaWifiMac::ApInfo &lhs, const StaWifiMac::ApInfo &rhs) const override
Compare two ApInfo objects for the purpose of keeping a sorted list of ApInfo objects.
EventId m_waitBeaconEvent
wait beacon event
static TypeId GetTypeId()
Get the type ID.
void ChannelSwitchTimeout(uint8_t linkId)
Take action upon the expiration of the timer set when requesting channel switch on the given link.
std::vector< ChannelSwitchInfo > m_channelSwitchInfo
per-link channel switch info
bool CanBeReturned(const StaWifiMac::ApInfo &apInfo) const override
Allow subclasses to choose whether the given ApInfo shall be returned or discarded when the STA wifi ...
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:201
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:267
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1313
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1330
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeBooleanChecker()
Definition boolean.cc:113
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition nstime.h:1416
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Definition boolean.h:70
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition nstime.h:1436
Struct to hold information regarding observed AP through active/passive scanning.
double m_snr
SNR in linear scale.