A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-static-emlsr-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Sharan Naribole <sharan.naribole@gmail.com>
7 */
8
9#include "ns3/ap-wifi-mac.h"
10#include "ns3/assert.h"
11#include "ns3/attribute-container.h"
12#include "ns3/boolean.h"
13#include "ns3/emlsr-manager.h"
14#include "ns3/frame-exchange-manager.h"
15#include "ns3/log.h"
16#include "ns3/mac48-address.h"
17#include "ns3/multi-model-spectrum-channel.h"
18#include "ns3/node-container.h"
19#include "ns3/rng-seed-manager.h"
20#include "ns3/simulator.h"
21#include "ns3/spectrum-wifi-helper.h"
22#include "ns3/sta-wifi-mac.h"
23#include "ns3/string.h"
24#include "ns3/test.h"
25#include "ns3/wifi-mac-header.h"
26#include "ns3/wifi-mac-helper.h"
27#include "ns3/wifi-mac.h"
28#include "ns3/wifi-net-device.h"
29#include "ns3/wifi-static-setup-helper.h"
30#include "ns3/wifi-utils.h"
31
32#include <algorithm>
33#include <iterator>
34#include <set>
35#include <unordered_map>
36
37/// @ingroup wifi-test
38/// @ingroup tests
39/// @brief WifiStaticSetupHelper EMLSR setup test suite
40/// Test suite intended to test static EMLSR setup between AP MLD and client MLD.
41/// The test prepares AP WifiNetDevice and client WifiNetDevice based on test vector input and
42/// performs static EMLSR setup using WifiStaticSetupHelper. The test verifies if EMLSR state
43/// machine at ApWifiMac and StaWifiMac has been updated correctly.
44
45using namespace ns3;
46NS_LOG_COMPONENT_DEFINE("WifiStaticEmlsrTestSuite");
47
49{
50const auto DEFAULT_RNG_SEED = 3;
51const auto DEFAULT_RNG_RUN = 7;
52const auto DEFAULT_STREAM_INDEX = 100;
54const auto DEFAULT_BEACON_GEN = false;
55const auto DEFAULT_DATA_MODE = "HeMcs3";
56const auto DEFAULT_CONTROL_MODE = "OfdmRate24Mbps";
59const auto DEFAULT_SWITCH_AUX_PHY = false;
61const auto DEFAULT_SSID = Ssid("static-assoc-test");
62const std::string CHANNEL_0 = "{42, 80, BAND_5GHZ, 0}";
63const std::string CHANNEL_1 = "{23, 80, BAND_6GHZ, 0}";
64const std::string CHANNEL_2 = "{2, 0, BAND_2_4GHZ, 0}";
65const std::vector<std::string> DEFAULT_AP_CHS = {CHANNEL_0, CHANNEL_1, CHANNEL_2};
66using ChannelMap = std::unordered_map<WifiPhyBand, Ptr<MultiModelSpectrumChannel>>;
67} // namespace WifiStaticEmlsrTestConstants
68
69/// @brief test case information
71{
72 std::string name; ///< Test case name
73 std::vector<std::string> clientChs{}; ///< Channel settings for client device
74 std::set<uint8_t> emlsrLinks{}; ///< EMLSR mode links
79};
80
81/**
82 * Test static setup of the EMLSR mode.
83 *
84 * It is checked that:
85 * - EMLSR mode is enabled on the expected set of links, both at client side and AP MLD side
86 * - the channel switch delay is configured on the client links as expected
87 */
89{
90 public:
91 /**
92 * Constructor.
93 *
94 * @param testVec the test vector
95 */
97
98 private:
99 /// Construct WifiNetDevice
100 /// @param isAp true if AP, false otherwise
101 /// @param channelMap created spectrum channels
102 /// @return constructed WifiNetDevice
105
106 /// Construct PHY helper based on input operating channels
107 /// @param settings vector of strings specifying the operating channels to configure
108 /// @param channelMap created spectrum channels
109 /// @return PHY helper
111 const std::vector<std::string>& settings,
112 const WifiStaticEmlsrTestConstants::ChannelMap& channelMap) const;
113
114 /// @return the WifiHelper
116 /// @return the AP MAC helper
118 /// @return the Client MAC helper
120 void ValidateEmlsr(); ///< Validate EMLSR setup
121 void DoRun() override;
122 void DoSetup() override;
123
125 Ptr<WifiNetDevice> m_apDev{nullptr}; ///< AP WiFi device
126 Ptr<WifiNetDevice> m_clientDev{nullptr}; ///< client WiFi device
127};
128
130 : TestCase(testVec.name),
131 m_testVec(testVec)
132{
133}
134
137{
138 WifiHelper wifiHelper;
140 wifiHelper.SetRemoteStationManager(
141 "ns3::ConstantRateWifiManager",
142 "DataMode",
144 "ControlMode",
146 wifiHelper.ConfigEhtOptions("EmlsrActivated", BooleanValue(true));
147 return wifiHelper;
148}
149
151WifiStaticEmlsrTest::GetPhyHelper(const std::vector<std::string>& settings,
152 const WifiStaticEmlsrTestConstants::ChannelMap& channelMap) const
153{
154 NS_ASSERT(not settings.empty());
155 SpectrumWifiPhyHelper helper(settings.size());
156
157 uint8_t linkId = 0;
158 for (const auto& str : settings)
159 {
160 helper.Set(linkId, "ChannelSettings", StringValue(str));
161 helper.Set(linkId, "ChannelSwitchDelay", TimeValue(m_testVec.switchDelay));
162 auto channelConfig = WifiChannelConfig::FromString(str);
163 auto phyBand = channelConfig.front().band;
164 auto freqRange = GetFrequencyRange(phyBand);
165 helper.AddPhyToFreqRangeMapping(linkId, freqRange);
166 helper.AddChannel(channelMap.at(phyBand), freqRange);
167
168 ++linkId;
169 }
170 return helper;
171}
172
175{
176 WifiMacHelper macHelper;
178
179 macHelper.SetType("ns3::ApWifiMac",
180 "Ssid",
181 SsidValue(ssid),
182 "BeaconGeneration",
184 return macHelper;
185}
186
189{
190 WifiMacHelper macHelper;
192 macHelper.SetType("ns3::StaWifiMac", "Ssid", SsidValue(ssid));
193 macHelper.SetEmlsrManager("ns3::DefaultEmlsrManager",
194 "EmlsrLinkSet",
196 "AuxPhyChannelWidth",
197 UintegerValue(m_testVec.auxPhyWidth),
198 "SwitchAuxPhy",
199 BooleanValue(m_testVec.switchAuxPhy));
200 return macHelper;
201}
202
206{
207 NodeContainer node(1);
208 auto wifiHelper = GetWifiHelper();
209 auto settings = isAp ? WifiStaticEmlsrTestConstants::DEFAULT_AP_CHS : m_testVec.clientChs;
210 auto phyHelper = GetPhyHelper(settings, channelMap);
211 auto macHelper = isAp ? GetApMacHelper() : GetClientMacHelper();
212 auto netDev = wifiHelper.Install(phyHelper, macHelper, node);
214 return DynamicCast<WifiNetDevice>(netDev.Get(0));
215}
216
217void
236
237void
239{
240 auto clientMac = DynamicCast<StaWifiMac>(m_clientDev->GetMac());
241 NS_ASSERT_MSG(clientMac, "Expected StaWifiMac");
242 NS_TEST_ASSERT_MSG_EQ(clientMac->IsAssociated(), true, "Expected non-AP MLD to be associated");
243 auto setupLinks = clientMac->GetSetupLinkIds();
244 auto isMldAssoc = (setupLinks.size() > 1);
245 NS_TEST_ASSERT_MSG_EQ(isMldAssoc, true, "EMLSR mode requires association on multiple links");
246 auto emlsrManager = clientMac->GetEmlsrManager();
247 NS_ASSERT_MSG(emlsrManager, "EMLSR Manager not set");
248 auto clientEmlsrLinks = emlsrManager->GetEmlsrLinks();
249 auto match = (clientEmlsrLinks == m_testVec.emlsrLinks);
250 NS_TEST_ASSERT_MSG_EQ(match, true, "Unexpected set of EMLSR links enabled");
251 for (auto linkId : setupLinks)
252 {
253 auto expectedState = clientEmlsrLinks.contains(linkId);
254 auto clientLinkAddr = clientMac->GetFrameExchangeManager(linkId)->GetAddress();
255 auto apManager = m_apDev->GetRemoteStationManager(linkId);
256 auto actualState = apManager->GetEmlsrEnabled(clientLinkAddr);
257 NS_TEST_ASSERT_MSG_EQ(actualState,
258 expectedState,
259 "EMLSR state mismatch on client link ID " << +linkId);
260
261 // Validate Channel switch delay
262 auto actualDelay = clientMac->GetWifiPhy(linkId)->GetChannelSwitchDelay();
263 NS_TEST_ASSERT_MSG_EQ(actualDelay,
264 m_testVec.switchDelay,
265 "Channel switch delay mismatch on client link ID " << +linkId);
266 }
267}
268
269void
277
278/**
279 * @ingroup wifi-test
280 * @ingroup tests
281 *
282 * @brief EMLSR static setup test suite
283 */
285{
286 public:
288};
289
291 : TestSuite("wifi-static-emlsr-test", Type::UNIT)
292{
293 auto CHANNELS_2_LINKS = {WifiStaticEmlsrTestConstants::CHANNEL_0,
295 auto CHANNELS_3_LINKS = {WifiStaticEmlsrTestConstants::CHANNEL_0,
298 auto CHANNELS_2_LINKS_ALT = {WifiStaticEmlsrTestConstants::CHANNEL_0,
300
301 for (const std::vector<WifiStaticEmlsrTestVector> inputs{
302 {"Setup-2-link-EMLSR-2-link",
303 CHANNELS_2_LINKS,
304 {0, 1},
308 {"Setup-3-link-EMLSR-2-link",
309 CHANNELS_3_LINKS,
310 {0, 1},
314 {"Setup-3-link-EMLSR-2-link-Diff",
315 CHANNELS_3_LINKS,
316 {1, 2},
320 {"Setup-3-link-EMLSR-2-link-Diff-2",
321 CHANNELS_3_LINKS,
322 {0, 2},
326 {"Setup-3-link-EMLSR-3-link",
327 CHANNELS_3_LINKS,
328 {0, 1, 2},
332 {"Setup-2-link-EMLSR-2-link-Diff-Set",
333 CHANNELS_2_LINKS_ALT,
334 {0, 2},
338 {"EMLSR-2-link-16us-delay",
339 CHANNELS_2_LINKS,
340 {0, 1},
341 MicroSeconds(16),
344 {"EMLSR-2-link-32us-delay",
345 CHANNELS_2_LINKS,
346 {0, 1},
347 MicroSeconds(32),
350 {"EMLSR-2-link-80MHz-AuxPhy",
351 CHANNELS_2_LINKS,
352 {0, 1},
353 MicroSeconds(32),
354 MHz_u{80},
356 {"EMLSR-2-link-Switch-Aux-PHY",
357 CHANNELS_2_LINKS,
358 {0, 1},
361 true},
362 {"EMLSR-2-link-80MHz-AuxPhy-Switch",
363 CHANNELS_2_LINKS,
364 {0, 1},
366 MHz_u{80},
367 true}};
368 const auto& input : inputs)
369 {
371 }
372}
373
Test static setup of the EMLSR mode.
WifiStaticEmlsrTestVector m_testVec
Test vector.
WifiMacHelper GetApMacHelper() const
SpectrumWifiPhyHelper GetPhyHelper(const std::vector< std::string > &settings, const WifiStaticEmlsrTestConstants::ChannelMap &channelMap) const
Construct PHY helper based on input operating channels.
Ptr< WifiNetDevice > m_apDev
AP WiFi device.
Ptr< WifiNetDevice > GetWifiNetDevice(bool isAp, const WifiStaticEmlsrTestConstants::ChannelMap &channelMap)
Construct WifiNetDevice.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
void DoRun() override
Implementation to actually run this TestCase.
WifiMacHelper GetClientMacHelper() const
WifiStaticEmlsrTest(const WifiStaticEmlsrTestVector &testVec)
Constructor.
WifiHelper GetWifiHelper() const
void ValidateEmlsr()
Validate EMLSR setup.
Ptr< WifiNetDevice > m_clientDev
client WiFi device
EMLSR static setup test suite.
A container for one type of attribute.
AttributeValue implementation for Boolean.
Definition boolean.h:26
keep track of a set of node pointers.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:67
static void SetRun(uint64_t run)
Set the run number of simulation.
static void SetSeed(uint32_t seed)
Set the seed.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
Make it easy to create and manage PHY objects for the spectrum model.
void AddChannel(const Ptr< SpectrumChannel > channel, const FrequencyRange &freqRange=WHOLE_WIFI_SPECTRUM)
void AddPhyToFreqRangeMapping(uint8_t linkId, const FrequencyRange &freqRange)
Add a given spectrum PHY interface to the PHY instance corresponding of a given link.
The IEEE 802.11 SSID Information Element.
Definition ssid.h:25
AttributeValue implementation for Ssid.
Definition ssid.h:85
Hold variables of type string.
Definition string.h:45
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
@ QUICK
Fast test.
Definition test.h:1054
TestCase(const TestCase &)=delete
Type
Type of test.
Definition test.h:1257
@ UNIT
This test suite implements a Unit Test.
Definition test.h:1259
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
Definition test.cc:490
Simulation virtual time values and global simulation resolution.
Definition nstime.h:96
AttributeValue implementation for Time.
Definition nstime.h:1456
Hold an unsigned integer type.
Definition uinteger.h:34
helps to create WifiNetDevice objects
void SetRemoteStationManager(std::string type, Args &&... args)
Helper function used to set the station manager.
void ConfigEhtOptions(Args &&... args)
Helper function used to configure the EHT options listed as attributes of the EhtConfiguration class.
static int64_t AssignStreams(NetDeviceContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by the PHY and MAC aspects ...
virtual void SetStandard(WifiStandard standard)
create MAC layers for a ns3::WifiNetDevice.
void SetEmlsrManager(std::string type, Args &&... args)
Helper function used to set the EMLSR Manager that can be installed on an EHT non-AP MLD.
void SetType(std::string type, Args &&... args)
void Set(std::string name, const AttributeValue &v)
static void SetStaticAssociation(Ptr< WifiNetDevice > bssDev, const NetDeviceContainer &clientDevs)
Bypass static capabilities exchange for input devices.
static void SetStaticEmlsr(Ptr< WifiNetDevice > apDev, const NetDeviceContainer &clientDevs)
Bypass EML Operating Mode Notification exchange sequence between AP MLD and input non-AP devices.
#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_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition assert.h:75
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition test.h:133
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1393
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1405
@ WIFI_STANDARD_80211be
@ WIFI_PHY_BAND_6GHZ
The 6 GHz band.
@ WIFI_PHY_BAND_2_4GHZ
The 2.4 GHz band.
@ WIFI_PHY_BAND_5GHZ
The 5 GHz band.
const std::vector< std::string > DEFAULT_AP_CHS
std::unordered_map< WifiPhyBand, Ptr< MultiModelSpectrumChannel > > ChannelMap
Every class exported by the ns3 library is enclosed in the ns3 namespace.
FrequencyRange GetFrequencyRange(WifiPhyBand band)
Get the frequency range corresponding to the given PHY band.
double MHz_u
MHz weak type.
Definition wifi-units.h:31
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:585
MHz_u auxPhyWidth
Aux PHY channel width.
std::vector< std::string > clientChs
Channel settings for client device.
std::set< uint8_t > emlsrLinks
EMLSR mode links.
std::string name
Test case name.
Time switchDelay
Radio Switch Delay.
static WifiChannelConfig FromString(const std::string &settings, WifiStandard standard=WIFI_STANDARD_UNSPECIFIED)
Get the wifi channel config from a WifiPhy::ChannelSettings string.
Definition wifi-types.cc:24
static WifiStaticEmlsrTestSuite g_wifiStaticEmlsrTestSuite