A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-fils-frame-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Rami Abdallah
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 */
6
7#include "ns3/ap-wifi-mac.h"
8#include "ns3/assert.h"
9#include "ns3/attribute-container.h"
10#include "ns3/boolean.h"
11#include "ns3/enum.h"
12#include "ns3/error-model.h"
13#include "ns3/log.h"
14#include "ns3/mac48-address.h"
15#include "ns3/mgt-action-headers.h"
16#include "ns3/mgt-headers.h"
17#include "ns3/mobility-helper.h"
18#include "ns3/node-container.h"
19#include "ns3/object-factory.h"
20#include "ns3/rng-seed-manager.h"
21#include "ns3/simulator.h"
22#include "ns3/spectrum-helper.h"
23#include "ns3/string.h"
24#include "ns3/test.h"
25#include "ns3/tuple.h"
26#include "ns3/wifi-mac-header.h"
27#include "ns3/wifi-mac-helper.h"
28#include "ns3/wifi-net-device.h"
29#include "ns3/wifi-psdu.h"
30#include "ns3/wifi-utils.h"
31#include "ns3/yans-wifi-helper.h"
32#include "ns3/yans-wifi-phy.h"
33
34#include <algorithm>
35#include <filesystem>
36#include <iterator>
37#include <optional>
38#include <variant>
39
40using namespace ns3;
41
42/// @ingroup wifi-test
43/// @ingroup tests
44/// @brief Fast Initial Link Setup (FILS) frame Test Suite
45/// Test suite intended to test (de)serialization and timing
46/// of frames associated with FILS procedure.
47/// The test creates a BSS consisting of an AP and client and
48/// and analyzes the timings and contents of frames associated
49/// with FILS procedure.
50
51NS_LOG_COMPONENT_DEFINE("WifiFilsFrameTestSuite");
52
53static const auto DEFAULT_BANDWIDTH = 20;
54static const auto INVALID_CHAN_NUM = 0;
55static const auto DEFAULT_PRIMARY_INDEX = 0;
56static const auto DEFAULT_SIM_STOP_TIME = MilliSeconds(610);
57static const auto DEFAULT_RNG_SEED = 3;
58static const auto DEFAULT_RNG_RUN = 7;
59static const auto DEFAULT_STREAM_INDEX = 100;
60static const auto DUMMY_AP_ADDR = Mac48Address("00:00:00:00:00:10");
61static const auto DEFAULT_STANDARD = WifiStandard::WIFI_STANDARD_80211ax;
62static const auto DEFAULT_BAND = WifiPhyBand::WIFI_PHY_BAND_6GHZ;
63static const auto DEFAULT_SSID = "01234567890123456789012345678901"; // max length (32 bytes)
64static const auto DEFAULT_BCN_INTRVL = 100 * WIFI_TU;
65static const auto DEFAULT_FILS_INTRVL = 20 * WIFI_TU;
66static const auto DEFAULT_TIMING_TOLERANCE = MicroSeconds(100);
67static const auto DEFAULT_UNSOL_PROBE_RESP_EN = false;
68static const auto DEFAULT_PCAP_PREFIX = "ap-fils";
69static const auto DEFAULT_OUTDIR = ".";
70static const auto DEFAULT_ENABLE_PCAP = false;
71static const auto DEFAULT_AP_LOC = Vector(0.01, 0, 0);
72static const auto DEFAULT_CLIENT_LOC = Vector(0, 0, 0);
73static const uint8_t WIFI_6GHZ_FD_PHY_IDX = 4;
74
75/// @brief Wi-Fi FILS frame test parameters
77{
78 MHz_u bw{DEFAULT_BANDWIDTH}; ///< Operation bandwidth
79 std::string ssid{DEFAULT_SSID}; ///< SSID name
80 uint8_t nss{0}; ///< Number of spatial streams
81 Time bcnIntrvl{DEFAULT_BCN_INTRVL}; ///< Time between Beacons
82 Time filsIntrvl{DEFAULT_FILS_INTRVL}; ///< Time between FILS frames
83 bool unsolProbeRespEn{DEFAULT_UNSOL_PROBE_RESP_EN}; ///< Unsolicited Probe Response enable
84 uint8_t expNssFld{0}; ///< Expected NSS field
85 uint8_t expChWidFld{0}; ///< Expected Channel Width field
86};
87
88/// @ingroup wifi-test
89/// @ingroup tests
90/// Test FILS frames
92{
93 public:
94 /// @brief constructor
95 /// @param params the parameters for this test
97
98 /// Transmitted PSDUs
100 {
101 Time timeSt; ///< timestamp
103 };
104
105 private:
106 /// Timing statistic for test validation
108 {
109 size_t cntBcns{0}; ///< Beacon frames count
110 Time bcnTimeSt{0}; ///< last Beacon timestamp
111 size_t cntFilsOrUnsolProbeResps{0}; ///< FILS Discovery or Unsolicited Probe Response count
112 Time filsOrUnsolProbeRespTimeSt{0}; ///< last FILS Discovery or Unsolicited Probe Response
113 ///< timestamp
114 Time filsOrUnsolProbeRespTimeDelta{0}; ///< time between last FILS Discovery or Unsolicited
115 ///< Probe Response and last Beacon
116 };
117
118 /// @brief setup a WifiNetDevice
119 /// @param channel the channel to attach to
120 /// @param isAp whether the device is an AP
121 /// @return the created WifiNetDevice
123
124 /// @brief callback connected to PSDU TX begin trace source
125 /// @param psduMap the transmitted PSDU map
126 /// @param txVector the TXVECTOR
127 /// @param txPowerW the TX power in Watts
128 void PsduTxCallback(WifiConstPsduMap psduMap, WifiTxVector txVector, double txPowerW);
129
130 /// @brief validate the given FILS Discovery frame
131 /// @param filsDisc the FILS Discovery frame
132 void ValidateFilsDiscFrame(const FilsDiscHeader& filsDisc);
133
134 /// @brief check the correctness of the test
135 void ValidateTest();
136
137 /// @brief Check the number of FILS Discovery frames or unsolicited Probe Response frames
138 /// transmitted since the last Beacon frame
139 /// @param psduCapt information about the transmitted Beacon frame
140 void ValidateCnt(const PsduCapture& psduCapt);
141
142 /// @brief check the timing of the transmitted FILS Discovery or unsolicited Probe Response
143 /// @param psduCapt information about the FILS Discovery or unsolicited Probe Response
144 void ValidateTiming(const PsduCapture& psduCapt);
145
146 /// @brief Get the FILS Discovery header, if present in the given frame
147 /// @param psduCapt information about the given frame
148 /// @return the FILS Discovery header, if present
149 std::optional<FilsDiscHeader> GetFilsDiscFrame(const PsduCapture& psduCapt);
150
151 void DoSetup() override;
152 void DoTeardown() override;
153 void DoRun() override;
154
155 TimeStats m_timeStats; ///< collected timing statistic
156 Ptr<WifiNetDevice> m_ap{nullptr}; ///< AP device
157 Ptr<WifiNetDevice> m_client{nullptr}; ///< Client device
158 WifiFilsFrameTestParams m_params; ///< Test parameters
159 std::vector<PsduCapture> m_txPsdus{}; ///< TX PSDUS frame infos
160};
161
163 : TestCase("WifiFilsFrameTest"),
164 m_params(params)
165{
166}
167
170{
171 NodeContainer node;
173 WifiMacHelper mac;
174 WifiHelper wifi;
175 MobilityHelper mobility;
176 node.Create(1);
177 phy.SetChannel(channel);
180 ';'>
181 channelValue;
182 channelValue.Set(WifiPhy::ChannelSegments{
184 phy.Set("ChannelSettings", channelValue);
185 phy.Set("Antennas", UintegerValue(m_params.nss));
186 phy.Set("MaxSupportedTxSpatialStreams", UintegerValue(m_params.nss));
187 phy.Set("MaxSupportedRxSpatialStreams", UintegerValue(m_params.nss));
188
189 wifi.SetStandard(DEFAULT_STANDARD);
190 wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager");
191
192 if (isAp)
193 {
194 mac.SetType("ns3::ApWifiMac",
195 "Ssid",
197 "BeaconGeneration",
198 BooleanValue(true),
199 "BeaconInterval",
201 "FdBeaconInterval6GHz",
203 "SendUnsolProbeResp",
205 }
206 else
207 {
208 mac.SetType("ns3::StaWifiMac",
209 "Ssid",
211 "ActiveProbing",
212 BooleanValue(false));
213 }
214 auto testDevs = wifi.Install(phy, mac, node);
216 auto dev = DynamicCast<WifiNetDevice>(testDevs.Get(0));
217 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
218 mobility.Install(node);
219 node.Get(0)->GetObject<MobilityModel>()->SetPosition(isAp ? DEFAULT_AP_LOC
221 phy.SetPcapDataLinkType(WifiPhyHelper::DLT_IEEE802_11_RADIO);
222 if (isAp && DEFAULT_ENABLE_PCAP)
223 {
224 auto path = std::filesystem::path(DEFAULT_OUTDIR);
225 phy.EnablePcap(path.append(DEFAULT_PCAP_PREFIX).string(), testDevs);
226 }
227 return dev;
228}
229
230void
232{
233 auto psdu = psduMap[SU_STA_ID];
234 m_txPsdus.push_back({Simulator::Now(), psdu});
235 NS_LOG_DEBUG("MPDU " << **psdu->begin());
236}
237
238void
240{
243 auto channel = YansWifiChannelHelper::Default().Create();
244 // setup devices and capabilities
245 m_ap = SetupDevice(channel, true);
246 m_client = SetupDevice(channel, false);
247 // setup AP TX PSDU trace
248 auto phy = m_ap->GetPhy();
249 phy->TraceConnectWithoutContext("PhyTxPsduBegin",
251}
252
253void
255{
256 if (m_timeStats.cntBcns > 0)
257 {
260 static_cast<std::size_t>((m_params.bcnIntrvl / m_params.filsIntrvl).GetHigh() - 1),
261 "Number of FILS or Unsolicited Response Frames per Beacon Interval is not expected");
262 }
263 m_timeStats.bcnTimeSt = psduCapt.timeSt;
266}
267
268void
284
285std::optional<FilsDiscHeader>
287{
288 auto pkt = psduCapt.psdu->GetPayload(0)->Copy();
289 WifiActionHeader actionHdr;
290 pkt->RemoveHeader(actionHdr);
291 if ((actionHdr.GetCategory() == WifiActionHeader::PUBLIC) &&
293 {
294 FilsDiscHeader filsDisc;
295 pkt->PeekHeader(filsDisc);
296 return filsDisc;
297 }
298 return std::nullopt;
299}
300
301void
303{
304 for (const auto& psduCapt : m_txPsdus)
305 {
306 auto hdr = psduCapt.psdu->GetHeader(0);
307 if (hdr.IsBeacon())
308 {
309 ValidateCnt(psduCapt);
310 }
311 else
312 {
313 if (m_params.unsolProbeRespEn && hdr.IsProbeResp() && hdr.GetAddr1().IsBroadcast())
314 { // Unsolicited Probe Response frame
315 ValidateTiming(psduCapt);
316 }
317 else if (hdr.IsAction())
318 { // possible FILS Discovery frame
319 if (auto filsDisc = GetFilsDiscFrame(psduCapt))
320 {
321 ValidateFilsDiscFrame(filsDisc.value());
322 ValidateTiming(psduCapt);
323 }
324 }
325 }
327 {
328 break;
329 }
330 }
331}
332
333void
335{
336 NS_TEST_ASSERT_MSG_EQ(filsDisc.GetSsid(), m_params.ssid, "FILS Discovery frame SSID mismatch");
337 NS_TEST_ASSERT_MSG_EQ(+filsDisc.m_fdCap->m_chWidth,
339 "FILS Discovery frame channel width mismatch");
340 NS_TEST_ASSERT_MSG_EQ(+filsDisc.m_fdCap->m_maxNss,
342 "FILS Discovery frame NSS mismatch");
343 NS_TEST_ASSERT_MSG_EQ(+filsDisc.m_fdCap->m_phyIdx,
345 "FILS Discovery frame PHY idx mismatch");
346}
347
348void
356
357void
359{
360 m_ap->Dispose();
361 m_ap = nullptr;
362 m_client->Dispose();
363 m_client = nullptr;
364 m_txPsdus.clear();
365}
366
367/// Testcases for FILS frame test
378
381{
383 switch (tc)
384 {
386 params.bw = 20;
387 params.ssid = DEFAULT_SSID;
388 params.nss = 1;
389 params.expChWidFld = 0;
390 params.expNssFld = 0;
391 break;
393 params.bw = 20;
394 params.ssid = "BW20MHZ_NSS3";
395 params.nss = 3;
396 params.filsIntrvl = 15 * WIFI_TU;
397 params.expChWidFld = 0;
398 params.expNssFld = 2;
399 break;
401 params.bw = 40;
402 params.ssid = "BW40MHZ_NSS2";
403 params.nss = 2;
404 params.filsIntrvl = 10 * WIFI_TU;
405 params.expChWidFld = 1;
406 params.expNssFld = 1;
407 break;
409 params.bw = 80;
410 params.ssid = "BW80MHZ_NSS2";
411 params.nss = 2;
412 params.filsIntrvl = 7 * WIFI_TU;
413 params.expChWidFld = 2;
414 params.expNssFld = 1;
415 break;
417 params.bw = 160;
418 params.ssid = "BW160MHZ_NSS2";
419 params.nss = 2;
420 params.filsIntrvl = 5 * WIFI_TU;
421 params.expChWidFld = 3;
422 params.expNssFld = 1;
423 break;
425 params.bw = 160;
426 params.ssid = "BW160MHZ_NSS2";
427 params.nss = 2;
428 params.unsolProbeRespEn = true;
429 params.expChWidFld = 3;
430 params.expNssFld = 1;
431 break;
432 default:
433 NS_ABORT_MSG("Testcase is unsupported");
434 break;
435 }
436 return params;
437}
438
439/// @ingroup wifi-test
440/// @ingroup tests
441/// @brief WiFi FILS frame Test Suite
443{
444 public:
446};
447
464
Ptr< WifiNetDevice > m_ap
AP device.
void DoRun() override
Implementation to actually run this TestCase.
Ptr< WifiNetDevice > m_client
Client device.
void PsduTxCallback(WifiConstPsduMap psduMap, WifiTxVector txVector, double txPowerW)
callback connected to PSDU TX begin trace source
Ptr< WifiNetDevice > SetupDevice(Ptr< YansWifiChannel > &channel, bool isAp)
setup a WifiNetDevice
std::vector< PsduCapture > m_txPsdus
TX PSDUS frame infos.
void ValidateCnt(const PsduCapture &psduCapt)
Check the number of FILS Discovery frames or unsolicited Probe Response frames transmitted since the ...
void ValidateTiming(const PsduCapture &psduCapt)
check the timing of the transmitted FILS Discovery or unsolicited Probe Response
TimeStats m_timeStats
collected timing statistic
void ValidateFilsDiscFrame(const FilsDiscHeader &filsDisc)
validate the given FILS Discovery frame
void ValidateTest()
check the correctness of the test
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
WifiFilsFrameTest(const WifiFilsFrameTestParams &params)
constructor
WifiFilsFrameTestParams m_params
Test parameters.
std::optional< FilsDiscHeader > GetFilsDiscFrame(const PsduCapture &psduCapt)
Get the FILS Discovery header, if present in the given frame.
WiFi FILS frame Test Suite.
A container for one type of attribute.
void Set(const T &c)
Copy items from container c.
AttributeValue implementation for Boolean.
Definition boolean.h:26
Implement the FILS (Fast Initial Link Setup) action frame.
const std::string & GetSsid() const
OptFieldWithPresenceInd< FdCapability > m_fdCap
FD Capability.
an EUI-48 address
Helper class used to assign positions and mobility models to nodes.
Keep track of the current position and velocity of an object.
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition object.h:511
Ptr< Packet > Copy() const
performs a COW copy of the packet.
Definition packet.cc:120
Smart pointer class similar to boost::intrusive_ptr.
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 Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
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
The IEEE 802.11 SSID Information Element.
Definition ssid.h:25
AttributeValue implementation for Ssid.
Definition ssid.h:85
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
int64_t GetTimeStep() const
Get the raw time value, in the current resolution unit.
Definition nstime.h:434
AttributeValue implementation for Time.
Definition nstime.h:1431
AttributeValue implementation for Tuple.
Definition tuple.h:67
Hold an unsigned integer type.
Definition uinteger.h:34
See IEEE 802.11 chapter 7.3.1.11 Header format: | category: 1 | action value: 1 |.
CategoryValue GetCategory() const
Return the category value.
ActionValue GetAction() const
Return the action value.
helps to create WifiNetDevice objects
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 ...
create MAC layers for a ns3::WifiNetDevice.
@ DLT_IEEE802_11_RADIO
Include Radiotap link layer information.
std::vector< ChannelTuple > ChannelSegments
segments identifying an operating channel
Definition wifi-phy.h:927
Ptr< const Packet > GetPayload(std::size_t i) const
Get the payload of the i-th MPDU.
Definition wifi-psdu.cc:290
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
static YansWifiChannelHelper Default()
Create a channel helper in a default working state.
Ptr< YansWifiChannel > Create() const
Make it easy to create and manage PHY objects for the YANS model.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition abort.h:38
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#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:134
#define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and...
Definition test.h:327
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1368
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1356
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::unordered_map< uint16_t, Ptr< const WifiPsdu > > WifiConstPsduMap
Map of const PSDUs indexed by STA-ID.
const Time WIFI_TU
Wi-Fi Time Unit (see IEEE 802.11-2020 sec. 3.1)
Definition wifi-utils.cc:22
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition callback.h:684
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:580
static constexpr uint16_t SU_STA_ID
STA_ID to identify a single user (SU)
Definition wifi-mode.h:24
Ptr< const WifiPsdu > psdu
PSDU.
Timing statistic for test validation.
Time filsOrUnsolProbeRespTimeDelta
time between last FILS Discovery or Unsolicited Probe Response and last Beacon
Time bcnTimeSt
last Beacon timestamp
Time filsOrUnsolProbeRespTimeSt
last FILS Discovery or Unsolicited Probe Response timestamp
size_t cntFilsOrUnsolProbeResps
FILS Discovery or Unsolicited Probe Response count.
size_t cntBcns
Beacon frames count.
Wi-Fi FILS frame test parameters.
Time filsIntrvl
Time between FILS frames.
uint8_t nss
Number of spatial streams.
std::string ssid
SSID name.
uint8_t expNssFld
Expected NSS field.
bool unsolProbeRespEn
Unsolicited Probe Response enable.
Time bcnIntrvl
Time between Beacons.
MHz_u bw
Operation bandwidth.
uint8_t expChWidFld
Expected Channel Width field.
static const auto DEFAULT_SSID
static const auto DUMMY_AP_ADDR
static const auto DEFAULT_UNSOL_PROBE_RESP_EN
static const auto DEFAULT_BANDWIDTH
Fast Initial Link Setup (FILS) frame Test Suite Test suite intended to test (de)serialization and tim...
static const uint8_t WIFI_6GHZ_FD_PHY_IDX
static const auto DEFAULT_STREAM_INDEX
static const auto DEFAULT_STANDARD
static const auto INVALID_CHAN_NUM
WifiFilsFrameTestCase
Testcases for FILS frame test.
static const auto DEFAULT_RNG_RUN
static const auto DEFAULT_PRIMARY_INDEX
static WifiFilsFrameTestSuite g_WifiFilsFrameTestSuite
static const auto DEFAULT_BCN_INTRVL
static const auto DEFAULT_AP_LOC
static const auto DEFAULT_OUTDIR
static const auto DEFAULT_CLIENT_LOC
static const auto DEFAULT_BAND
WifiFilsFrameTestParams WifiFilsFrameTestBuildCase(const WifiFilsFrameTestCase &tc)
static const auto DEFAULT_ENABLE_PCAP
static const auto DEFAULT_TIMING_TOLERANCE
static const auto DEFAULT_FILS_INTRVL
static const auto DEFAULT_RNG_SEED
static const auto DEFAULT_PCAP_PREFIX
static const auto DEFAULT_SIM_STOP_TIME