A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-association-test.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025 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_TEST_H
10#define WIFI_ASSOC_TEST_H
11
12#include "ns3/ap-wifi-mac.h"
13#include "ns3/log.h"
14#include "ns3/multi-model-spectrum-channel.h"
15#include "ns3/packet-socket-client.h"
16#include "ns3/spectrum-wifi-helper.h"
17#include "ns3/sta-wifi-mac.h"
18#include "ns3/test.h"
19#include "ns3/wifi-assoc-manager.h"
20
21#include <list>
22#include <map>
23#include <set>
24#include <sstream>
25
26using namespace ns3;
27
28namespace
29{
30/**
31 * @ingroup wifi-test
32 * @ingroup tests
33 *
34 * Test Association Manager allowing users to explicitly configure the best AP to associate with.
35 */
37{
38 public:
39 /**
40 * @brief Get the type ID.
41 * @return the object TypeId
42 */
43 static TypeId GetTypeId();
44
45 void NotifyChannelSwitched(linkId_t linkId) override;
46 bool Compare(const StaWifiMac::ApInfo& lhs, const StaWifiMac::ApInfo& rhs) const override;
47
48 /**
49 * Set the best AP to associate with. For all the APs other than the best AP, CanBeReturned()
50 * returns false, therefore the station can only associate with the given AP, if present in
51 * the AP info list held by this manager.
52 *
53 * @param bssid the address of the best AP (possibly affiliated with an AP MLD)
54 * @param setupLinks the list of links to setup, in case of ML setup
55 */
56 void SetBestAp(Mac48Address bssid,
57 const std::list<StaWifiMac::ApInfo::SetupLinksInfo>& setupLinks);
58
59 protected:
60 bool CanBeInserted(const StaWifiMac::ApInfo& apInfo) const override;
61 bool CanBeReturned(const StaWifiMac::ApInfo& apInfo) const override;
62
63 private:
64 void DoStartScanning() override;
65
66 Mac48Address m_bestAp; ///< the MAC address of the AP to associate with
67 std::list<StaWifiMac::ApInfo::SetupLinksInfo> m_setupLinks; ///< the list of links to setup
68};
69
70} // namespace
71
72/**
73 * @ingroup wifi-test
74 * @ingroup tests
75 *
76 * @brief Base class for association tests
77 *
78 * Setup one non-AP STA and two APs with a configurable number of links.
79 */
81{
82 public:
83 /// Configuration parameters common to all subclasses
85 {
86 std::string ap1Channels; ///< Semicolon separated (no spaces) list of channel settings for
87 ///< the links of AP 1
88 std::string ap2Channels; ///< Semicolon separated (no spaces) list of channel settings for
89 ///< the links of AP 2
90 std::string staChannels; ///< Semicolon separated (no spaces) list of channel settings for
91 ///< the links of STA
92 };
93
94 /**
95 * Constructor
96 *
97 * @param name The name of the new TestCase created
98 * @param baseParams common configuration parameters
99 */
100 WifiAssociationTestBase(const std::string& name, const BaseParams& baseParams);
101 ~WifiAssociationTestBase() override = default;
102
103 protected:
104 /**
105 * Callback invoked when a FEM passes PSDUs to the PHY.
106 *
107 * @param mac the MAC transmitting the PSDUs
108 * @param phyId the ID of the PHY transmitting the PSDUs
109 * @param psduMap the PSDU map
110 * @param txVector the TX vector
111 * @param txPowerW the tx power in Watts
112 */
113 virtual void Transmit(Ptr<WifiMac> mac,
114 uint8_t phyId,
115 WifiConstPsduMap psduMap,
116 WifiTxVector txVector,
117 double txPowerW);
118
119 /**
120 * @param dir the traffic direction (uplink/downlink)
121 * @param apId the AP ID (1 or 2)
122 * @param count the number of packets to generate
123 * @param pktSize the size of the packets to generate
124 * @param priority user priority for generated packets
125 * @return an application generating the given number packets from/to the given AP to/from the
126 * STA
127 */
129 std::size_t apId,
130 std::size_t count,
131 std::size_t pktSize,
132 uint8_t priority = 0) const;
133
134 /**
135 * Callback invoked when a STA completes association with an AP.
136 *
137 * @param bssid the AP address
138 */
139 virtual void AssocSeenBySta(Mac48Address bssid)
140 {
141 }
142
143 /**
144 * Callback invoked when a STA transitions to unassociated state.
145 *
146 * @param bssid the address of the AP the STA was associated with
147 */
148 virtual void DisassocSeenBySta(Mac48Address bssid)
149 {
150 }
151
152 /**
153 * Callback invoked when the given AP detects that the given STA has completed association.
154 *
155 * @param apMac the MAC of the given AP
156 * @param aid the AID of the associated STA
157 * @param staAddress the address of the associated STA
158 */
159 virtual void AssocSeenByAp(ApWifiMac* apMac, uint16_t aid, Mac48Address staAddress)
160 {
161 }
162
163 /**
164 * Callback invoked when the given AP detects that the given STA has disassociated.
165 *
166 * @param apMac the MAC of the given AP
167 * @param aid the AID of the STA that disassociated
168 * @param staAddress the address of the STA that disassociated
169 */
170 virtual void DisassocSeenByAp(ApWifiMac* apMac, uint16_t aid, Mac48Address staAddress)
171 {
172 }
173
174 void DoSetup() override;
175
176 /// Actions and checks to perform upon the transmission of each frame
177 struct Events
178 {
179 /**
180 * Constructor.
181 *
182 * @param type the frame MAC header type
183 * @param f function to perform actions and checks
184 */
186 std::function<void(Ptr<const WifiPsdu>, const WifiTxVector&, linkId_t)>&& f = {})
187 : hdrType(type),
188 func(f)
189 {
190 }
191
192 WifiMacType hdrType; ///< MAC header type of frame being transmitted
193 std::function<void(Ptr<const WifiPsdu>, const WifiTxVector&, linkId_t)>
194 func; ///< function to perform actions and checks
195 };
196
197 std::list<Events> m_events; //!< list of events for a test run
198
199 BaseParams m_baseParams; ///< configuration parameters
200 std::string m_assocMgrTypeId{"ns3::WifiDefaultAssocManager"}; ///< Association Manager type ID
201 Ptr<ApWifiMac> m_ap1Mac; ///< AP 1 wifi MAC
202 Ptr<ApWifiMac> m_ap2Mac; ///< AP 2 wifi MAC
203 Ptr<StaWifiMac> m_staMac; ///< STA wifi MAC
204 Time m_duration{Seconds(0.8)}; ///< simulation duration
205 std::map<WifiDirection, PacketSocketAddress> m_ap1Sockets; ///< packet socket addresses for
206 ///< DL/UL traffic from AP1
207 std::map<WifiDirection, PacketSocketAddress> m_ap2Sockets; ///< packet socket addresses for
208 ///< DL/UL traffic from AP2
209 bool m_checkTxPsdus{false}; ///< whether TX PSDUs should be checked against the list of events
210 std::set<WifiMacType>
211 m_framesToSkip; ///< frames that must not be checked against the list of events
212
213 private:
214 /**
215 * Start the generation of traffic (needs to be overridden)
216 */
217 virtual void StartTraffic()
218 {
219 }
220};
221
222/**
223 * @ingroup wifi-test
224 * @ingroup tests
225 *
226 * @brief Test association, disassociation and reassociation in various scenarios
227 *
228 * Example scenario for uplink traffic (STA sends Disassociation frame before roaming to another AP)
229 *
230 * request
231 * ┌───┬───┬───┐ disassociation ┌─────┐ ┌───┬───┬───┐
232 * │QoS│ │QoS│ | ┌────────┐ │Assoc│ ┌───┐ │QoS│ │QoS│
233 * STA │ 1 │...│ n │ | │Disassoc│ │ Req │ │Ack│ │ 1 │...│ n │
234 * ─────┴───X───┴───┴─────v─┴────────┴───────┴─────┴───────────────┴───┴─^───────┴───┴───┴───┴─────
235 * |---optional--| | BA agreement
236 * ┌──┐ ┌───┐ establishment
237 * AP 1 │BA│ │Ack│ between STA and AP 2
238 * ──────────────────┴──X─────────────┴───┴────────────────────────────────────────────────────────
239 * ┌─────┐
240 * ┌───┐ │Assoc│ ┌──┐
241 * AP 2 │Ack│ │ Resp│ │BA│
242 * ─────────────────────────────────────────────────┴───┴───┴─────┴───────────────────────────┴──┴─
243 *
244 *
245 * After each association, it is checked that:
246 *
247 * - the station manager of the AP operating on a given link reports that the STA is associated
248 * if and only if that link is expected to be setup
249 * - the station manager of the AP operating on a given link returns the address of the STA
250 * affiliated to the non-AP MLD and operating on that link if and only if the STA performs ML
251 * setup (instead of legacy association) and that link is expected to be setup
252 * - the STA has setup the expected links and the BSSIDs are correct
253 *
254 * After the first association, a first set of (DL or UL) packets are generated, transmitted to/by
255 * the first AP. The first two MPDUs in the transmitted A-MPDU are corrupted; the receiver sends the
256 * acknowledgment, which however is corrupted and is not received.
257 * Disassociation is then requested (before BlockAck timeout, if a Disassociation frame is sent, or
258 * after BlockAckTimeout, otherwise) so that a BlockAckReq is queued when the STA actually
259 * disassociates (tested).
260 * On both the STA side (when disassociation is requested, if a Disassociation frame is not sent,
261 * or when the Disassociation frame is acked, otherwise) and the AP side (when the Disassociation
262 * frame is received, if the STA sends a Disassociation frame, or when the Reassociation frame is
263 * received, if the STA does not send a Disassociation frame and associates with the same AP again),
264 * it is checked that:
265 *
266 * - transmissions of unicast frames (but management frames) on all links setup by the STA are
267 * blocked with DISASSOCIATION reason
268 * - [STA side only] QoS data frames are still queued
269 * - [STA side only] no BAR (having link addresses) is queued anymore if ML setup was performed or
270 * STA notified disassociation to the AP
271 * - Block Ack agreement has been destroyed if and only if STA notified disassociation to the AP
272 *
273 * After the second association, it is checked that:
274 *
275 * - a new Block Ack agreement is established if STA roams to a different AP or if STA destroyed the
276 * previous agreement (which occurs when STA sends a Disassociation frame) or legacy association
277 * is performed and STA setups a different link than before
278 * - STA has not dropped the BlockAckReq frame if and only if STA has not sent a Disassociation
279 * frame (otherwise all control frames are dropped), STA established legacy association and
280 * reassociates with the same AP (and same link)
281 * - if STA has a queued BlockAckReq frame, such a frame is transmitted first, followed by a
282 * BlockAck response; afterwards, STA retransmits the two MPDUs that are indicated as not received
283 * in the BlockAck response. Otherwise, all the QoS data frames are retransmitted.
284 */
286{
287 public:
288 /// Setup Links info for AP info objects
289 using SetupLinksInfo = std::pair<linkId_t /* STA link ID */, linkId_t /* AP link ID */>;
290
291 /// Configuration parameters specific to this test
292 struct Params
293 {
294 WifiAssocType assocType{}; ///< the association type (legacy or ML setup)
295 std::size_t firstApLinkId{}; ///< the ID of the link (as seen by the AP) that is used to
296 ///< send the first Association Request
297 std::list<SetupLinksInfo> firstSetupLinks; ///< links to setup with the first AP
298 std::size_t secondApId{}; ///< the ID (1 or 2) of the AP (possibly affiliated with an AP
299 ///< MLD) that is the recipient of the second Association Request
300 std::size_t secondApLinkId{}; ///< the ID of the link (as seen by the AP) that is used to
301 ///< send the second Association Request
302 std::list<SetupLinksInfo> secondSetupLinks; ///< links to setup with the second AP
303 WifiDirection trafficDir{}; ///< traffic direction
304 bool sendDisassoc{}; ///< whether the STA notifies disassociation to the AP
305 };
306
307 /**
308 * Constructor
309 *
310 * @param baseParams common configuration parameters
311 * @param params parameters specific for this test
312 */
313 WifiDisassocAndReassocTest(const BaseParams& baseParams, const Params& params);
314
315 protected:
316 void AssocSeenBySta(Mac48Address bssid) override;
317 void AssocSeenByAp(ApWifiMac* apMac, uint16_t aid, Mac48Address staAddress) override;
318 void DisassocSeenByAp(ApWifiMac* apMac, uint16_t aid, Mac48Address staAddress) override;
319
320 /// Insert elements in the list of expected events (transmitted frames)
321 void InsertEvents();
322
323 /// Take actions connected to roaming
324 void StartRoaming();
325
326 /**
327 * Check that the AP which the STA is expected to be associated with stores the expected info
328 * about the STA in its remote station managers.
329 *
330 * @param firstAssoc true/false if the STA associated for the first/second time
331 */
332 void CheckRemoteStaInfo(bool firstAssoc);
333
334 /**
335 * Check that the STA stores the expected info about the AP it is expected to be associated
336 * with.
337 *
338 * @param firstAssoc true/false if the STA associated for the first/second time
339 */
340 void CheckRemoteApInfo(bool firstAssoc);
341
342 /**
343 * Check that the expected operations are performed by the local device after disassociation.
344 *
345 * @param local the MAC of the local device
346 */
348
349 private:
350 void DoSetup() override;
351 void DoRun() override;
352
353 const std::size_t m_firstApId{1}; ///< the ID of the AP (possibly affiliated with an AP MLD)
354 ///< that is the recipient of the first Assoc Request
355 Params m_params; ///< parameters specific for this test
356 const std::size_t m_nPackets{5}; ///< number of packets generated in a burst
357 Time m_assocTime; ///< time at which last association took place
359 SINGLE_LINK_OP_ID}; ///< ID of the link on which the BA is sent before roaming
360 std::size_t m_assocWithAp1Count{0}; ///< number of associations with AP 1 (seen by STA)
361 std::size_t m_assocWithAp2Count{0}; ///< number of associations with AP 2 (seen by STA)
362 std::size_t m_assocSeenByAp1Count{0}; ///< number of associations with AP 1 (seen by AP 1)
363 std::size_t m_assocSeenByAp2Count{0}; ///< number of associations with AP 2 (seen by AP 2)
364 Ptr<ListErrorModel> m_staErrorModel; ///< error rate model to install on the STA
365 Ptr<ListErrorModel> m_ap1ErrorModel; ///< error rate model to install on the first AP
366};
367
368/**
369 * @ingroup wifi-test
370 * @ingroup tests
371 *
372 * @brief wifi 11be MLD Test Suite
373 */
375{
376 public:
378};
379
380/**
381 * @brief Stream insertion operator.
382 *
383 * @param os the stream
384 * @param params the base params
385 * @returns a reference to the stream
386 */
387inline std::ostream&
388operator<<(std::ostream& os, const WifiAssociationTestBase::BaseParams& params)
389{
390 return (os << "BaseParams{AP 1: " << params.ap1Channels << ", AP 2: " << params.ap2Channels
391 << ", STA: " << params.staChannels << "}");
392}
393
394/**
395 * @brief Stream insertion operator.
396 *
397 * @param os the stream
398 * @param params the WifiDisassocAndReassocTest params
399 * @returns a reference to the stream
400 */
401inline std::ostream&
402operator<<(std::ostream& os, const WifiDisassocAndReassocTest::Params& params)
403{
404 os << "Params{" << params.trafficDir << ", "
405 << (params.assocType == WifiAssocType::ML_SETUP ? "ML setup" : "Legacy assoc") << ", "
406 << (params.sendDisassoc ? "Send" : "Do NOT send") << " Disassoc frame";
407 os << " [1st] AP link ID: " << params.firstApLinkId << ", Setup links: ";
408 for (const auto& [staLinkId, apLinkID] : params.firstSetupLinks)
409 {
410 os << "(" << +staLinkId << "," << +apLinkID << ")";
411 }
412 os << " [2nd] AP ID: " << params.secondApId << ", AP link ID: " << params.secondApLinkId
413 << ", Setup links: ";
414 for (const auto& [staLinkId, apLinkID] : params.secondSetupLinks)
415 {
416 os << "(" << +staLinkId << "," << +apLinkID << ")";
417 }
418 os << "}";
419
420 return os;
421}
422
423#endif /* WIFI_ASSOC_TEST_H */
virtual void DisassocSeenByAp(ApWifiMac *apMac, uint16_t aid, Mac48Address staAddress)
Callback invoked when the given AP detects that the given STA has disassociated.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
virtual void DisassocSeenBySta(Mac48Address bssid)
Callback invoked when a STA transitions to unassociated state.
WifiAssociationTestBase(const std::string &name, const BaseParams &baseParams)
Constructor.
virtual void Transmit(Ptr< WifiMac > mac, uint8_t phyId, WifiConstPsduMap psduMap, WifiTxVector txVector, double txPowerW)
Callback invoked when a FEM passes PSDUs to the PHY.
Ptr< ApWifiMac > m_ap1Mac
AP 1 wifi MAC.
Ptr< StaWifiMac > m_staMac
STA wifi MAC.
virtual void AssocSeenBySta(Mac48Address bssid)
Callback invoked when a STA completes association with an AP.
std::string m_assocMgrTypeId
Association Manager type ID.
bool m_checkTxPsdus
whether TX PSDUs should be checked against the list of events
Ptr< PacketSocketClient > GetApplication(WifiDirection dir, std::size_t apId, std::size_t count, std::size_t pktSize, uint8_t priority=0) const
Ptr< ApWifiMac > m_ap2Mac
AP 2 wifi MAC.
BaseParams m_baseParams
configuration parameters
std::map< WifiDirection, PacketSocketAddress > m_ap1Sockets
packet socket addresses for DL/UL traffic from AP1
virtual void StartTraffic()
Start the generation of traffic (needs to be overridden).
virtual void AssocSeenByAp(ApWifiMac *apMac, uint16_t aid, Mac48Address staAddress)
Callback invoked when the given AP detects that the given STA has completed association.
std::map< WifiDirection, PacketSocketAddress > m_ap2Sockets
packet socket addresses for DL/UL traffic from AP2
Time m_duration
simulation duration
std::list< Events > m_events
list of events for a test run
std::set< WifiMacType > m_framesToSkip
frames that must not be checked against the list of events
~WifiAssociationTestBase() override=default
void InsertEvents()
Insert elements in the list of expected events (transmitted frames).
Params m_params
parameters specific for this test
linkId_t m_baLinkId
ID of the link on which the BA is sent before roaming.
Ptr< ListErrorModel > m_ap1ErrorModel
error rate model to install on the first AP
void DoSetup() override
Implementation to do any local setup required for this TestCase.
void StartRoaming()
Take actions connected to roaming.
void AssocSeenByAp(ApWifiMac *apMac, uint16_t aid, Mac48Address staAddress) override
Callback invoked when the given AP detects that the given STA has completed association.
void DisassocSeenByAp(ApWifiMac *apMac, uint16_t aid, Mac48Address staAddress) override
Callback invoked when the given AP detects that the given STA has disassociated.
Time m_assocTime
time at which last association took place
std::size_t m_assocWithAp2Count
number of associations with AP 2 (seen by STA)
void CheckAfterDisassoc(Ptr< WifiMac > local)
Check that the expected operations are performed by the local device after disassociation.
std::size_t m_assocSeenByAp2Count
number of associations with AP 2 (seen by AP 2)
void CheckRemoteApInfo(bool firstAssoc)
Check that the STA stores the expected info about the AP it is expected to be associated with.
void AssocSeenBySta(Mac48Address bssid) override
Callback invoked when a STA completes association with an AP.
WifiDisassocAndReassocTest(const BaseParams &baseParams, const Params &params)
Constructor.
std::size_t m_assocSeenByAp1Count
number of associations with AP 1 (seen by AP 1)
const std::size_t m_firstApId
the ID of the AP (possibly affiliated with an AP MLD) that is the recipient of the first Assoc Reques...
Ptr< ListErrorModel > m_staErrorModel
error rate model to install on the STA
std::pair< linkId_t, linkId_t > SetupLinksInfo
Setup Links info for AP info objects.
const std::size_t m_nPackets
number of packets generated in a burst
void CheckRemoteStaInfo(bool firstAssoc)
Check that the AP which the STA is expected to be associated with stores the expected info about the ...
std::size_t m_assocWithAp1Count
number of associations with AP 1 (seen by STA)
void DoRun() override
Implementation to actually run this TestCase.
Test Association Manager allowing users to explicitly configure the best AP to associate with.
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 ...
void SetBestAp(Mac48Address bssid, const std::list< StaWifiMac::ApInfo::SetupLinksInfo > &setupLinks)
Set the best AP to associate with.
std::list< StaWifiMac::ApInfo::SetupLinksInfo > m_setupLinks
the list of links to setup
void NotifyChannelSwitched(linkId_t linkId) override
Notify that the given link has completed channel switching.
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.
Mac48Address m_bestAp
the MAC address of the AP to associate with
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...
Wi-Fi AP state machine.
Definition ap-wifi-mac.h:63
an EUI-48 address
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
TestCase(const TestCase &)=delete
Caller graph was not generated because of its size.
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
Definition test.cc:494
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
a unique identifier for an interface.
Definition type-id.h:50
WifiAssocManager()
Constructor (protected as this is an abstract base class).
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1313
WifiAssocType
Type of association performed by this device (provided that it is supported by the standard configure...
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:148
static constexpr uint8_t SINGLE_LINK_OP_ID
Link ID for single link operations (helps tracking places where correct link ID is to be used to supp...
Definition wifi-utils.h:307
WifiMacType
Combination of valid MAC header type/subtype.
WifiDirection
Wifi direction.
Definition wifi-utils.h:42
std::unordered_map< uint16_t, Ptr< const WifiPsdu > > WifiConstPsduMap
Map of const PSDUs indexed by STA-ID.
Definition wifi-ppdu.h:39
uint8_t linkId_t
IEEE 802.11be D7.0 Figure 9-207e—Link ID Info field format.
Definition wifi-utils.h:76
Configuration parameters common to all subclasses.
std::string ap1Channels
Semicolon separated (no spaces) list of channel settings for the links of AP 1.
std::string staChannels
Semicolon separated (no spaces) list of channel settings for the links of STA.
std::string ap2Channels
Semicolon separated (no spaces) list of channel settings for the links of AP 2.
Events(WifiMacType type, std::function< void(Ptr< const WifiPsdu >, const WifiTxVector &, linkId_t)> &&f={})
Constructor.
std::function< void(Ptr< const WifiPsdu >, const WifiTxVector &, linkId_t)> func
function to perform actions and checks
WifiMacType hdrType
MAC header type of frame being transmitted.
Configuration parameters specific to this test.
std::size_t secondApId
the ID (1 or 2) of the AP (possibly affiliated with an AP MLD) that is the recipient of the second As...
std::list< SetupLinksInfo > secondSetupLinks
links to setup with the second AP
std::list< SetupLinksInfo > firstSetupLinks
links to setup with the first AP
WifiAssocType assocType
the association type (legacy or ML setup)
std::size_t secondApLinkId
the ID of the link (as seen by the AP) that is used to send the second Association Request
std::size_t firstApLinkId
the ID of the link (as seen by the AP) that is used to send the first Association Request
WifiDirection trafficDir
traffic direction
bool sendDisassoc
whether the STA notifies disassociation to the AP
Struct to hold information regarding observed AP through active/passive scanning.
std::string dir