A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-co-trace-helper-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Indraprastha Institute of Information Technology Delhi
3 * Copyright (c) 2009 University of Washington
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 */
7
8#include "ns3/boolean.h"
9#include "ns3/double.h"
10#include "ns3/eht-configuration.h"
11#include "ns3/enum.h"
12#include "ns3/he-phy.h"
13#include "ns3/integer.h"
14#include "ns3/mobility-helper.h"
15#include "ns3/multi-model-spectrum-channel.h"
16#include "ns3/names.h"
17#include "ns3/node-list.h"
18#include "ns3/object.h"
19#include "ns3/packet-socket-client.h"
20#include "ns3/packet-socket-helper.h"
21#include "ns3/packet-socket-server.h"
22#include "ns3/packet.h"
23#include "ns3/pointer.h"
24#include "ns3/rng-seed-manager.h"
25#include "ns3/spectrum-wifi-helper.h"
26#include "ns3/ssid.h"
27#include "ns3/string.h"
28#include "ns3/test.h"
29#include "ns3/uinteger.h"
30#include "ns3/wifi-co-trace-helper.h"
31#include "ns3/wifi-helper.h"
32#include "ns3/wifi-mac.h"
33#include "ns3/wifi-mpdu.h"
34#include "ns3/wifi-net-device.h"
35#include "ns3/wifi-phy-state.h"
36#include "ns3/wifi-psdu.h"
37#include "ns3/yans-wifi-helper.h"
38
39using namespace ns3;
40NS_LOG_COMPONENT_DEFINE("WifiCoTraceHelperTest");
41
42/**
43 * @ingroup wifi-test
44 * @brief It's a base class with some utility methods for other test cases in this file.
45 */
47{
48 public:
49 /**
50 * Constructor.
51 *
52 * @param testName Name of a test.
53 */
54 WifiCoTraceHelperBaseTestCase(const std::string& testName)
55 : TestCase(testName)
56 {
57 }
58
59 protected:
60 /**
61 * It gets the channel occupancy of a link on a node measured by WifiCoTraceHelper.
62 *
63 * @param nodeId Id of a node.
64 * @param linkId Id of link.
65 * @param coHelper Helper to obtain channel occupancy
66 * @return Statistics measured by WifiCoTraceHelper corresponding to nodeId,linkId.
67 */
68 const std::map<WifiPhyState, Time>& GetChannelOccupancy(size_t nodeId,
69 size_t linkId,
70 WifiCoTraceHelper& coHelper);
71
72 /**
73 * A helper function that sets tid-to-link mapping.
74 *
75 * @param mapping A string that configure tid-to-link mapping.
76 */
77 void ConfigureTidToLinkMapping(const std::string& mapping);
78
79 /**
80 * A helper function that installs PacketSocketServer on a node.
81 *
82 * @param node The node on which the server is installed.
83 * @param startAfter The server starts after a delay of "startAfter" duration.
84 * @param prot The PacketSocketAddress of the server uses "prot" as its protocol number.
85 */
86 void InstallPacketSocketServer(Ptr<Node> node, Time startAfter, size_t prot);
87
88 /**
89 * A helper function that installs PacketSocketClient application on a node.
90 *
91 * @param client The node on which the client is installed.
92 * @param server A node on which PacketSocketServer is installed and to whom the client sends
93 * requests.
94 * @param prot The protocol number used by both the client and the server.
95 * @param startAfter The client starts after a delay of "startAfter" duration.
96 * @param numPkts The client sends these many packets to server immediately.
97 * @param pktLen The length of each packet in bytes.
98 * @param tid The tid of each packet.
99 * @return A pointer to the installed PacketSocketClient application.
100 */
102 Ptr<Node> server,
103 size_t prot,
104 Time startAfter,
105 size_t numPkts,
106 size_t pktLen,
107 size_t tid);
108
109 /**
110 * A helper function that schedules to send given number of packets from one node to another.
111 *
112 * @param from The node which sends the packets.
113 * @param to The node which receives the packets.
114 * @param startAfter The packets are scheduled to send after this much duration.
115 * @param numPkts The number of packets.
116 * @param pktLen The length of each packet in bytes.
117 * @param tid The optional tid of each packet. The default value is "0".
118 */
119 void SchedulePackets(Ptr<Node> from,
120 Ptr<Node> to,
121 Time startAfter,
122 size_t numPkts,
123 size_t pktLen,
124 size_t tid);
125
126 /**
127 * A helper function that disables frame aggregation.
128 */
129 void DisableAggregation();
130
131 Time m_simulationStop{Seconds(5.0)}; ///< Instant at which simulation should stop.
132 NodeContainer m_nodes; ///< Container of all nodes instantiated in this test case.
133 NetDeviceContainer m_devices; ///< Container of all devices instantiated in this test case.
134 size_t protocol =
135 1; ///< A unique Protocol used in each PacketSocketClient and PacketSocketServer pair.
136};
137
138const std::map<WifiPhyState, Time>&
140 size_t linkId,
141 WifiCoTraceHelper& coHelper)
142{
143 const auto& devRecords = coHelper.GetDeviceRecords();
144 auto senderRecord = std::find_if(devRecords.cbegin(), devRecords.cend(), [nodeId](auto& x) {
145 return x.m_nodeId == nodeId;
146 });
147
148 NS_ASSERT_MSG((senderRecord != devRecords.end()), "Expected statistics for nodeId: " << nodeId);
149
150 auto stats = senderRecord->m_linkStateDurations.find(linkId);
151 auto endItr = senderRecord->m_linkStateDurations.end();
152 NS_ASSERT_MSG((stats != endItr),
153 "Expected statistics at nodeId: " << nodeId << ", linkId: " << linkId);
154
155 return stats->second;
156}
157
158void
160{
161 for (size_t i = 0; i < m_devices.GetN(); ++i)
162 {
163 auto wifiDevice = DynamicCast<WifiNetDevice>(m_devices.Get(i));
164 wifiDevice->GetMac()->GetEhtConfiguration()->SetAttribute(
165 "TidToLinkMappingNegSupport",
166 EnumValue(WifiTidToLinkMappingNegSupport::ANY_LINK_SET));
167
168 wifiDevice->GetMac()->GetEhtConfiguration()->SetAttribute("TidToLinkMappingUl",
169 StringValue(mapping));
170 }
171}
172
173/**
174 * Install Packet Socket Server on a node. A Packet Socket client generates an uplink flow and sends
175 * it to the server.
176 */
177void
179 Time startAfter,
180 size_t prot)
181{
182 Ptr<WifiNetDevice> device = DynamicCast<WifiNetDevice>(node->GetDevice(0));
183 PacketSocketAddress srvAddr;
184 srvAddr.SetSingleDevice(device->GetIfIndex());
185 srvAddr.SetProtocol(prot);
186 auto psServer = CreateObject<PacketSocketServer>();
187 psServer->SetLocal(srvAddr);
188 node->AddApplication(psServer);
189 psServer->SetStartTime(startAfter);
190}
191
192/**
193 * Install packet socket client that generates an uplink flow on a node.
194 */
197 Ptr<Node> server,
198 size_t prot,
199 Time startAfter,
200 size_t numPkts,
201 size_t pktLen,
202 size_t tid)
203{
204 NS_LOG_INFO("Start Flow on node:" << client->GetId()
205 << " at:" << Simulator::Now() + startAfter);
206
207 Ptr<WifiNetDevice> staDevice = DynamicCast<WifiNetDevice>(client->GetDevice(0));
208 PacketSocketAddress sockAddr;
209 sockAddr.SetSingleDevice(staDevice->GetIfIndex());
210 sockAddr.SetPhysicalAddress(server->GetDevice(0)->GetAddress());
211 sockAddr.SetProtocol(prot);
212
213 auto clientApp = CreateObject<PacketSocketClient>();
214 clientApp->SetAttribute("PacketSize", UintegerValue(pktLen));
215 clientApp->SetAttribute("MaxPackets", UintegerValue(numPkts));
216 clientApp->SetAttribute("Interval", TimeValue(Seconds(0))); // Send packets immediately
217 clientApp->SetAttribute("Priority", UintegerValue(tid));
218 clientApp->SetRemote(sockAddr);
219 clientApp->SetStartTime(startAfter);
220
221 staDevice->GetNode()->AddApplication(clientApp);
222 return clientApp;
223}
224
225void
227 Ptr<Node> to,
228 Time startDelay,
229 size_t numPkts,
230 size_t pktLen,
231 size_t tid = 0)
232{
233 /* Install a PacketSocket server and client pair with a unique protocol on each invocation. */
234 this->protocol++;
235
236 InstallPacketSocketServer(to, startDelay, this->protocol);
237 InstallPacketSocketClient(from, to, this->protocol, startDelay, numPkts, pktLen, tid);
238}
239
240void
242{
243 for (size_t i = 0; i < this->m_nodes.GetN(); i++)
244 {
245 for (uint32_t j = 0; j < this->m_nodes.Get(i)->GetNDevices(); j++)
246 {
247 auto device = DynamicCast<WifiNetDevice>(m_nodes.Get(i)->GetDevice(j));
248 if (!device)
249 {
250 continue;
251 }
252
253 device->GetMac()->SetAttribute("BE_MaxAmpduSize", UintegerValue(0));
254 device->GetMac()->SetAttribute("BK_MaxAmpduSize", UintegerValue(0));
255 device->GetMac()->SetAttribute("VO_MaxAmpduSize", UintegerValue(0));
256 device->GetMac()->SetAttribute("VI_MaxAmpduSize", UintegerValue(0));
257
258 device->GetMac()->SetAttribute("BE_MaxAmsduSize", UintegerValue(0));
259 device->GetMac()->SetAttribute("BK_MaxAmsduSize", UintegerValue(0));
260 device->GetMac()->SetAttribute("VO_MaxAmsduSize", UintegerValue(0));
261 device->GetMac()->SetAttribute("VI_MaxAmsduSize", UintegerValue(0));
262 }
263 }
264}
265
266/**
267 * @ingroup wifi-test
268 * @brief Send one packet from one WifiNetDevice to other.
269 *
270 * This test case sends a single packet from one wifi device to another, operating in Adhoc mode,
271 * and compares the TX duration measured by WifiCoTraceHelper with the analytically calculated
272 * value.
273 */
275{
276 public:
277 /** Constructor. */
279
280 private:
281 /** Executes test case and assertions. */
282 void DoRun() override;
283 /** Setup test case's scenario. */
284 void DoSetup() override;
285};
286
289 "SendOnePacketTestCase: Send one packet from one WifiNetDevice to other.")
290{
291}
292
293void
295{
296 size_t senderNodeId = 1;
297 size_t recNodeId = 0;
298 Ptr<Node> sender = m_nodes.Get(senderNodeId);
299 Ptr<Node> receiver = m_nodes.Get(recNodeId);
300
301 // Send a packet to initiate one-time control frame exchanges in Adhoc mode.
302 // To avoid one-time control frames, we will not measure channel occupancy during transmission
303 // of this packet.
304 SchedulePackets(sender, receiver, Seconds(0.5), 1 /*num of packets*/, 1000 /*packet length*/);
305
306 // Send a packet that requires only one symbol to transmit and measure its channel occupancy.
307 /**
308 * Size of frame in Bytes = 204 (payload) + 34 (Mac & Phy Headers) = 238
309 * Frame Size in bits + Phy service and tail bits = 238*8 + 22 = 1926
310 * Phy rate at MCS 11, 40 MHz, 800 ns GI, 1 spatial stream = 286.6 Mbps
311 * Symbol duration = 12.8 + 0.8 = 13.6 us
312 * Number of symbols = ceil(1926 / (286.6 * 13.6)) = 1
313 */
314 Time scheduleAt{Seconds(1.0)};
315 size_t packetLen = 200; /*In Bytes*/
316 SchedulePackets(sender, receiver, scheduleAt, 1 /*num of packets*/, packetLen);
317 WifiCoTraceHelper helper1{scheduleAt, scheduleAt + Seconds(0.1)};
318 helper1.Enable(m_nodes);
319
320 // Send a packet that requires two symbols to transmit and measure its channel occupancy.
321 /**
322 * If we replace payload size from 204 to 504 in the above calculation in comments, then number
323 * of symbols equals 2.
324 * Number of symbols = ceil(4326 / (286.6 * 13.6)) = 2
325 */
326 scheduleAt = Seconds(1.5);
327 packetLen = 500; /*In Bytes*/
328 SchedulePackets(sender, receiver, scheduleAt, 1 /*num of packets*/, packetLen);
329 WifiCoTraceHelper helper2{scheduleAt, scheduleAt + Seconds(0.1)};
330 helper2.Enable(m_nodes);
331
332 // Send a packet that requires three symbols to transmit and measure its channel occupancy.
333 /**
334 * If we replace payload size from 204 to 1004 in the above calculation in comments, then number
335 * of symbols equals 3.
336 * Number of symbols = ceil(8326 / (286.6 * 13.6)) = 2
337 */
338 scheduleAt = Seconds(2.0);
339 packetLen = 1000; /*In Bytes*/
340 SchedulePackets(sender, receiver, scheduleAt, 1 /*num of packets*/, packetLen);
341 WifiCoTraceHelper helper3{scheduleAt, scheduleAt + Seconds(0.1)};
342 helper3.Enable(m_nodes);
343
345
348
349 /**
350 * Data Packet
351 * ===========
352 * Preamble Duration = 48 us
353 * Symbol Duration = 12.8 + 0.8 (Guard Interval) = 13.6 us
354 * Tx Duration of a packet requiring 1 symbol = (1 * 13.6) + 48 = 61.6 us
355 * Tx Duration of a packet requiring 2 symbols = (2 * 13.6) + 48 = 75.2 us
356 * Tx Duration of a packet requiring 3 symbols = (3 * 13.6) + 48 = 88.8 us
357 */
358
359 auto map1 = GetChannelOccupancy(senderNodeId, 0 /*linkId*/, helper1);
360 NS_TEST_ASSERT_MSG_EQ(map1.at(WifiPhyState::TX),
361 NanoSeconds(61600),
362 "TX duration does not match");
363
364 auto map2 = GetChannelOccupancy(senderNodeId, 0 /*linkId*/, helper2);
365 NS_TEST_ASSERT_MSG_EQ(map2.at(WifiPhyState::TX),
366 NanoSeconds(75200),
367 "TX duration does not match");
368
369 auto map3 = GetChannelOccupancy(senderNodeId, 0 /*linkId*/, helper3);
370 NS_TEST_ASSERT_MSG_EQ(map3.at(WifiPhyState::TX),
371 NanoSeconds(88800),
372 "TX duration does not match");
373
374 /**
375 * Acknowledgement Packet
376 * ======================
377 * Preamble Duration = 20 us
378 * Symbol Duration = 4 us
379 * Number of symbols = 2
380 * Tx Duration of Ack packet = 2*4 + 20 = 28 us
381 */
382 auto ackMap = GetChannelOccupancy(recNodeId, 0 /*linkId*/, helper1);
383 NS_TEST_ASSERT_MSG_EQ(ackMap.at(WifiPhyState::TX),
384 NanoSeconds(28000),
385 "TX duration does not match");
386}
387
388void
390{
391 std::string mcs{"11"};
392
393 uint32_t nWifi = 2;
394 m_nodes.Create(nWifi);
395
396 WifiMacHelper mac;
397 Ssid ssid = Ssid("ns-3-ssid");
398
399 WifiHelper wifi;
400 wifi.SetStandard(WIFI_STANDARD_80211be);
401
402 // Create multiple spectrum channels
404
406 phy.SetPcapDataLinkType(WifiPhyHelper::DLT_IEEE802_11_RADIO);
407 phy.AddChannel(spectrumChannel5Ghz, WIFI_SPECTRUM_5_GHZ);
408
409 // configure operating channel for each link
410 phy.Set(0, "ChannelSettings", StringValue("{0, 40, BAND_5GHZ, 0}"));
411
412 uint8_t linkId = 0;
413 wifi.SetRemoteStationManager(linkId,
414 "ns3::ConstantRateWifiManager",
415 "DataMode",
416 StringValue("EhtMcs" + mcs),
417 "ControlMode",
418 StringValue("OfdmRate24Mbps"));
419
420 mac.SetType("ns3::AdhocWifiMac");
421 m_devices = wifi.Install(phy, mac, m_nodes);
422
423 MobilityHelper mobility;
425 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
426 auto distance = 0.1;
427 positionAlloc->Add(Vector(distance, 0.0, 0.0));
428 mobility.SetPositionAllocator(positionAlloc);
429 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
430 mobility.Install(m_nodes);
431
432 /* Disable aggregation and set guard interval */
434 int gi = 800; // Guard Interval in nano seconds
435 Config::Set("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/HeConfiguration/GuardInterval",
437
438 PacketSocketHelper helper;
439 helper.Install(m_nodes);
440}
441
442/**
443 * @ingroup wifi-test
444 * @brief Trace channel occupany on each link of MLDs
445 *
446 * This test case sends a packet on each link of a MLD and asserts that WifiCoTraceHelper measures
447 * TX duration correctly on every link. It uses tid-to-link mapping to schedule a packet to a
448 * specific link.
449 *
450 */
452{
453 public:
454 /** Constructor. */
455 MLOTestCase();
456
457 private:
458 void DoRun() override;
459 void DoSetup() override;
460};
461
464 "MLOTestCase: Track channel occupancy on multiple links of a multi-link device (MLD).")
465{
466}
467
468void
470{
471 /* Configure tid-to-link mapping such that packets with different tids are sent on different
472 * links. */
473 ConfigureTidToLinkMapping("0 0; 1,2,3,4,5,6,7 1");
474
475 size_t senderNodeId = 1;
476 size_t recNodeId = 0;
477 Ptr<Node> sender = m_nodes.Get(senderNodeId);
478 Ptr<Node> receiver = m_nodes.Get(recNodeId);
479
480 SchedulePackets(sender, receiver, Seconds(0.5), 1, 1000, 0 /*tid*/);
481 SchedulePackets(sender, receiver, Seconds(0.5), 1, 1000, 3 /*tid*/);
482
483 // Send a packet with tid '0' and measure channel occupancy.
484 Time scheduleAt = Seconds(1.05);
485 size_t tid = 0;
486 SchedulePackets(sender, receiver, scheduleAt, 1 /*num of packets*/, 1000 /*Bytes*/, tid);
487 WifiCoTraceHelper helper0{scheduleAt, scheduleAt + Seconds(0.01)};
488 helper0.Enable(m_nodes);
489
490 // Send a packet with tid '3' and measure channel occupancy.
491 scheduleAt = Seconds(2.0);
492 tid = 3;
493 SchedulePackets(sender, receiver, scheduleAt, 1 /*num of packets*/, 1000 /*Bytes*/, tid);
494 WifiCoTraceHelper helper1{scheduleAt, scheduleAt + Seconds(0.1)};
495 helper1.Enable(m_nodes);
496
498
500
501 std::cout << "## MLOTestCase: Tid 0 Packet ##\n";
502 helper0.PrintStatistics(std::cout);
503 std::cout << "## MLOTestCase: Tid 3 Packet ##\n";
504 helper1.PrintStatistics(std::cout);
505
506 /* Assert TX time for each packet matches analytically compuated value of 88.8 us. Refer
507 * SendOnePacketTestCase above for the analytical calculation of TX time of 88.8 us.*/
508 // Assert on link 0
509 auto map0 = GetChannelOccupancy(senderNodeId, 0 /*linkId*/, helper0);
510 NS_TEST_ASSERT_MSG_EQ(map0.at(WifiPhyState::TX),
511 NanoSeconds(88800),
512 "TX duration does not match");
513
514 // Assert on link 1
515 auto map1 = GetChannelOccupancy(senderNodeId, 1 /*linkId*/, helper1);
516 NS_TEST_ASSERT_MSG_EQ(map1.at(WifiPhyState::TX),
517 NanoSeconds(88800),
518 "TX duration does not match");
519
521}
522
523void
525{
526 // LogComponentEnable("WifiCoTraceHelper", LOG_LEVEL_INFO);
528
529 NodeContainer ap;
530 ap.Create(1);
531
532 uint32_t nWifi = 1;
533 NodeContainer sta;
534 sta.Create(nWifi);
535
536 m_nodes.Add(ap);
537 m_nodes.Add(sta);
538
539 WifiMacHelper mac;
540 Ssid ssid = Ssid("ns-3-ssid");
541
542 WifiHelper wifi;
543 wifi.SetStandard(WIFI_STANDARD_80211be);
544
545 // Create multiple spectrum channels
548
549 // SpectrumWifiPhyHelper (3 links)
551 phy.SetPcapDataLinkType(WifiPhyHelper::DLT_IEEE802_11_RADIO);
552 phy.AddChannel(spectrumChannel5Ghz, WIFI_SPECTRUM_5_GHZ);
553 phy.AddChannel(spectrumChannel6Ghz, WIFI_SPECTRUM_6_GHZ);
554
555 // configure operating channel for each link
556 phy.Set(0, "ChannelSettings", StringValue("{0, 40, BAND_5GHZ, 0}"));
557 phy.Set(1, "ChannelSettings", StringValue("{0, 40, BAND_6GHZ, 0}"));
558
559 // configure rate manager for each link
560 uint8_t linkId = 0;
561 wifi.SetRemoteStationManager(linkId,
562 "ns3::ConstantRateWifiManager",
563 "DataMode",
564 StringValue("EhtMcs11"),
565 "ControlMode",
566 StringValue("OfdmRate24Mbps"));
567 wifi.SetRemoteStationManager(1,
568 "ns3::ConstantRateWifiManager",
569 "DataMode",
570 StringValue("EhtMcs11"),
571 "ControlMode",
572 StringValue("OfdmRate24Mbps"));
573
574 mac.SetType("ns3::ApWifiMac", "Ssid", SsidValue(ssid));
575 m_devices.Add(wifi.Install(phy, mac, ap));
576 mac.SetType("ns3::StaWifiMac", "Ssid", SsidValue(ssid), "ActiveProbing", BooleanValue(false));
577 m_devices.Add(wifi.Install(phy, mac, sta));
578
579 MobilityHelper mobility;
581
582 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
583 auto distance = 1;
584 positionAlloc->Add(Vector(distance, 0.0, 0.0));
585 mobility.SetPositionAllocator(positionAlloc);
586
587 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
588 mobility.Install(m_nodes);
589
590 /* Disable aggregation and set guard interval */
592 int gi = 800; // Guard Interval in nano seconds
593 Config::Set("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/HeConfiguration/GuardInterval",
595
596 PacketSocketHelper helper;
597 helper.Install(m_nodes);
598}
599
600/**
601 * @ingroup wifi-test
602 * @brief LinkId of non-AP MLD changes after MLO setup.
603 *
604 * This test case configures one AP MLD with three links and one non-AP MLD with two links. Ngon-AP
605 * MLD swaps (i.e., renames) its link after MLO setup. It asserts that WifiCoTraceHelper should
606 * capture statistics of the renamed link.
607 */
609{
610 public:
611 /** Constructor. */
613
614 private:
615 void DoRun() override;
616 void DoSetup() override;
617};
618
621 "LinkRenameTestCase: WifiCoTraceHelper should record statistics under new LinkId.")
622{
623}
624
625void
627{
628 // Adding nodes to wificohelper
629 WifiCoTraceHelper coHelper;
630 coHelper.Stop(m_simulationStop);
631 coHelper.Enable(m_nodes);
632 auto staNodeId = 1;
633
634 SchedulePackets(m_nodes.Get(1), m_nodes.Get(0), Seconds(2.0), 1000, 1000);
636
639
640 std::cout << "## LinkRenameTestCase ##\n";
641 coHelper.PrintStatistics(std::cout);
642
643 auto staStatistics = coHelper.GetDeviceRecords().at(staNodeId).m_linkStateDurations;
644
645 // Note that sta has only two phys. So, a linkId of '2' is created by renaming one of the
646 // existing links.
647 auto renamedLinkId = 2;
648 auto it = staStatistics.find(renamedLinkId);
649 NS_TEST_ASSERT_MSG_EQ((it != staStatistics.end()),
650 true,
651 "Link: " << renamedLinkId << " isn't present at non-AP MLD");
652}
653
654void
656{
657 // LogComponentEnable("WifiCoTraceHelper", LOG_LEVEL_DEBUG);
658
660
661 NodeContainer ap;
662 ap.Create(1);
663
664 uint32_t nWifi = 1;
665 NodeContainer sta;
666 sta.Create(nWifi);
667
668 m_nodes.Add(ap);
669 m_nodes.Add(sta);
670
671 WifiMacHelper mac;
672 Ssid ssid = Ssid("ns-3-ssid");
673
674 // Create multiple spectrum channels
675 Ptr<MultiModelSpectrumChannel> spectrumChannel2_4Ghz =
678
679 // SpectrumWifiPhyHelper (2 links)
680 SpectrumWifiPhyHelper nonApPhyHelper(2);
682 nonApPhyHelper.AddChannel(spectrumChannel5Ghz, WIFI_SPECTRUM_5_GHZ);
683 nonApPhyHelper.AddChannel(spectrumChannel5Ghz, WIFI_SPECTRUM_5_GHZ);
684
685 // configure operating channel for each link
686 nonApPhyHelper.Set(0, "ChannelSettings", StringValue("{42, 80, BAND_5GHZ, 0}"));
687 nonApPhyHelper.Set(1, "ChannelSettings", StringValue("{0, 80, BAND_5GHZ, 0}"));
688
689 nonApPhyHelper.Set("FixedPhyBand", BooleanValue(true));
690
691 WifiHelper nonApWifiHelper;
692 nonApWifiHelper.SetStandard(WIFI_STANDARD_80211be);
693
694 // configure rate manager for each link
695 uint8_t firstLinkId = 0;
696 nonApWifiHelper.SetRemoteStationManager(firstLinkId,
697 "ns3::ConstantRateWifiManager",
698 "DataMode",
699 StringValue("EhtMcs9"),
700 "ControlMode",
701 StringValue("EhtMcs9"));
702 nonApWifiHelper.SetRemoteStationManager(1,
703 "ns3::ConstantRateWifiManager",
704 "DataMode",
705 StringValue("EhtMcs9"),
706 "ControlMode",
707 StringValue("EhtMcs9"));
708
709 SpectrumWifiPhyHelper apPhyHelper(3);
711 apPhyHelper.AddChannel(spectrumChannel2_4Ghz, WIFI_SPECTRUM_2_4_GHZ);
712 apPhyHelper.AddChannel(spectrumChannel5Ghz, WIFI_SPECTRUM_5_GHZ);
713 apPhyHelper.AddChannel(spectrumChannel5Ghz, WIFI_SPECTRUM_5_GHZ);
714
715 // configure operating channel for each link
716 apPhyHelper.Set(0, "ChannelSettings", StringValue("{6, 40, BAND_2_4GHZ, 0}"));
717 apPhyHelper.Set(1, "ChannelSettings", StringValue("{42, 80, BAND_5GHZ, 0}"));
718 apPhyHelper.Set(2, "ChannelSettings", StringValue("{0, 0, BAND_5GHZ, 0}"));
719
720 apPhyHelper.Set("FixedPhyBand", BooleanValue(true));
721
722 WifiHelper apWifiHelper;
724
725 apWifiHelper.SetRemoteStationManager(firstLinkId,
726 "ns3::ConstantRateWifiManager",
727 "DataMode",
728 StringValue("EhtMcs9"),
729 "ControlMode",
730 StringValue("EhtMcs9"));
731 apWifiHelper.SetRemoteStationManager(1,
732 "ns3::ConstantRateWifiManager",
733 "DataMode",
734 StringValue("EhtMcs9"),
735 "ControlMode",
736 StringValue("EhtMcs9"));
737 apWifiHelper.SetRemoteStationManager(2,
738 "ns3::ConstantRateWifiManager",
739 "DataMode",
740 StringValue("EhtMcs9"),
741 "ControlMode",
742 StringValue("EhtMcs9"));
743
744 mac.SetType("ns3::ApWifiMac", "Ssid", SsidValue(ssid), "BeaconGeneration", BooleanValue(true));
745 m_devices.Add(apWifiHelper.Install(apPhyHelper, mac, ap));
746
747 mac.SetType("ns3::StaWifiMac", "Ssid", SsidValue(ssid), "ActiveProbing", BooleanValue(true));
748 m_devices.Add(nonApWifiHelper.Install(nonApPhyHelper, mac, sta));
749
750 MobilityHelper mobility;
752
753 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
754 auto distance = 0.1;
755 positionAlloc->Add(Vector(distance, 0.0, 0.0));
756 mobility.SetPositionAllocator(positionAlloc);
757
758 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
759 mobility.Install(m_nodes);
760
761 PacketSocketHelper helper;
762 helper.Install(m_nodes);
763}
764
765/**
766 * @ingroup wifi-test
767 * @brief Wifi Channel Occupancy Helper Test Suite
768 */
770{
771 public:
772 /** Constructor. */
774};
775
777 : TestSuite("wifi-co-trace-helper", Type::UNIT)
778{
779 AddTestCase(new SendOnePacketTestCase, TestCase::Duration::QUICK);
780 AddTestCase(new MLOTestCase, TestCase::Duration::QUICK);
781 AddTestCase(new LinkRenameTestCase, TestCase::Duration::QUICK);
782}
783
784/**
785 * @ingroup wifi-test
786 * WifiCoHelperTestSuite instance variable.
787 */
Trace channel occupany on each link of MLDs.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
void DoRun() override
Implementation to actually run this TestCase.
Send one packet from one WifiNetDevice to other.
void DoRun() override
Executes test case and assertions.
void DoSetup() override
Setup test case's scenario.
Wifi Channel Occupancy Helper Test Suite.
It's a base class with some utility methods for other test cases in this file.
NodeContainer m_nodes
Container of all nodes instantiated in this test case.
WifiCoTraceHelperBaseTestCase(const std::string &testName)
Constructor.
void SchedulePackets(Ptr< Node > from, Ptr< Node > to, Time startAfter, size_t numPkts, size_t pktLen, size_t tid)
A helper function that schedules to send given number of packets from one node to another.
Time m_simulationStop
Instant at which simulation should stop.
Ptr< PacketSocketClient > InstallPacketSocketClient(Ptr< Node > client, Ptr< Node > server, size_t prot, Time startAfter, size_t numPkts, size_t pktLen, size_t tid)
A helper function that installs PacketSocketClient application on a node.
void DisableAggregation()
A helper function that disables frame aggregation.
void ConfigureTidToLinkMapping(const std::string &mapping)
A helper function that sets tid-to-link mapping.
size_t protocol
A unique Protocol used in each PacketSocketClient and PacketSocketServer pair.
void InstallPacketSocketServer(Ptr< Node > node, Time startAfter, size_t prot)
A helper function that installs PacketSocketServer on a node.
const std::map< WifiPhyState, Time > & GetChannelOccupancy(size_t nodeId, size_t linkId, WifiCoTraceHelper &coHelper)
It gets the channel occupancy of a link on a node measured by WifiCoTraceHelper.
NetDeviceContainer m_devices
Container of all devices instantiated in this test case.
Hold variables of type enum.
Definition enum.h:52
Helper class used to assign positions and mobility models to nodes.
holds a vector of ns3::NetDevice pointers
uint32_t GetN() const
Get the number of Ptr<NetDevice> stored in this container.
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
keep track of a set of node pointers.
uint32_t GetN() const
Get the number of Ptr<Node> stored in this container.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void Add(const NodeContainer &nc)
Append the contents of another NodeContainer to the end of this container.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Definition node.cc:138
an address for a packet socket
void SetProtocol(uint16_t protocol)
Set the protocol.
void SetPhysicalAddress(const Address address)
Set the destination address.
void SetSingleDevice(uint32_t device)
Set the address to match only a specified NetDevice.
Give ns3::PacketSocket powers to ns3::Node.
void Install(Ptr< Node > node) const
Aggregate an instance of a ns3::PacketSocketFactory onto the provided node.
Smart pointer class similar to boost::intrusive_ptr.
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
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)
The IEEE 802.11 SSID Information Element.
Definition ssid.h:25
Hold variables of type string.
Definition string.h:45
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
Hold an unsigned integer type.
Definition uinteger.h:34
Track channel occupancy durations for WifiNetDevice.
void Stop(Time stopTime)
Stops the collection of statistics at a specified time.
void Enable(NodeContainer nodes)
Enables trace collection for all nodes and WifiNetDevices in the specified NodeContainer.
void PrintStatistics(std::ostream &os, Time::Unit unit=Time::Unit::AUTO) const
Print measurement results on an output stream.
const std::vector< DeviceRecord > & GetDeviceRecords() const
Returns measurement results on each installed device.
helps to create WifiNetDevice objects
void SetRemoteStationManager(std::string type, Args &&... args)
Helper function used to set the station manager.
virtual void SetStandard(WifiStandard standard)
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer::Iterator first, NodeContainer::Iterator last) const
create MAC layers for a ns3::WifiNetDevice.
void SetPcapDataLinkType(SupportedPcapDataLinkTypes dlt)
Set the data link type of PCAP traces to be used.
void Set(std::string name, const AttributeValue &v)
@ DLT_IEEE802_11_RADIO
Include Radiotap link layer information.
#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
void Set(std::string path, const AttributeValue &value)
Definition config.cc:869
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
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:134
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1380
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1344
static WifiCoHelperTestSuite g_WifiCoHelperTestSuite
WifiCoHelperTestSuite instance variable.
@ WIFI_STANDARD_80211be
Every class exported by the ns3 library is enclosed in the ns3 namespace.
constexpr FrequencyRange WIFI_SPECTRUM_6_GHZ
Identifier for the frequency range covering the wifi spectrum in the 6 GHz band.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:580
constexpr FrequencyRange WIFI_SPECTRUM_5_GHZ
Identifier for the frequency range covering the wifi spectrum in the 5 GHz band.
constexpr FrequencyRange WIFI_SPECTRUM_2_4_GHZ
Identifier for the frequency range covering the wifi spectrum in the 2.4 GHz band.