A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2005,2006 INRIA
3 * 2010 NICTA
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
8 * Quincy Tse <quincy.tse@nicta.com.au>
9 * Sébastien Deronne <sebastien.deronne@gmail.com>
10 */
11
12#include "ns3/adhoc-wifi-mac.h"
13#include "ns3/ap-wifi-mac.h"
14#include "ns3/config.h"
15#include "ns3/constant-position-mobility-model.h"
16#include "ns3/constant-rate-wifi-manager.h"
17#include "ns3/error-model.h"
18#include "ns3/fcfs-wifi-queue-scheduler.h"
19#include "ns3/he-frame-exchange-manager.h"
20#include "ns3/he-phy.h"
21#include "ns3/header-serialization-test.h"
22#include "ns3/ht-configuration.h"
23#include "ns3/interference-helper.h"
24#include "ns3/mgt-headers.h"
25#include "ns3/mobility-helper.h"
26#include "ns3/multi-model-spectrum-channel.h"
27#include "ns3/packet-socket-client.h"
28#include "ns3/packet-socket-helper.h"
29#include "ns3/packet-socket-server.h"
30#include "ns3/pointer.h"
31#include "ns3/propagation-loss-model.h"
32#include "ns3/rng-seed-manager.h"
33#include "ns3/socket.h"
34#include "ns3/spectrum-wifi-helper.h"
35#include "ns3/string.h"
36#include "ns3/test.h"
37#include "ns3/uinteger.h"
38#include "ns3/waypoint-mobility-model.h"
39#include "ns3/wifi-default-ack-manager.h"
40#include "ns3/wifi-default-assoc-manager.h"
41#include "ns3/wifi-default-protection-manager.h"
42#include "ns3/wifi-mgt-header.h"
43#include "ns3/wifi-net-device.h"
44#include "ns3/wifi-ppdu.h"
45#include "ns3/wifi-psdu.h"
46#include "ns3/wifi-spectrum-signal-parameters.h"
47#include "ns3/yans-error-rate-model.h"
48#include "ns3/yans-wifi-helper.h"
49#include "ns3/yans-wifi-phy.h"
50
51#include <optional>
52
53using namespace ns3;
54
55// Helper function to assign streams to random variables, to control
56// randomness in the tests
57static void
59{
60 int64_t currentStream = stream;
61 if (!mac->GetQosSupported())
62 {
63 currentStream += mac->GetTxop()->AssignStreams(currentStream);
64 }
65 else
66 {
67 currentStream += mac->GetQosTxop(AC_VO)->AssignStreams(currentStream);
68 currentStream += mac->GetQosTxop(AC_VI)->AssignStreams(currentStream);
69 currentStream += mac->GetQosTxop(AC_BE)->AssignStreams(currentStream);
70 currentStream += mac->GetQosTxop(AC_BK)->AssignStreams(currentStream);
71 }
72}
73
74/**
75 * @ingroup wifi-test
76 * @ingroup tests
77 *
78 * @brief Wifi Test
79 */
80class WifiTest : public TestCase
81{
82 public:
83 WifiTest();
84
85 void DoRun() override;
86
87 private:
88 /// Run one function
89 void RunOne();
90 /**
91 * Create one function
92 * @param pos the position
93 * @param channel the wifi channel
94 */
95 void CreateOne(Vector pos, Ptr<YansWifiChannel> channel);
96 /**
97 * Send one packet function
98 * @param dev the device
99 */
101
104 ObjectFactory m_propDelay; ///< propagation delay
105};
106
108 : TestCase("Wifi")
109{
110}
111
112void
114{
116 dev->Send(p, dev->GetBroadcast(), 1);
117}
118
119void
121{
124 node->AddDevice(dev);
125
127 auto phy = CreateObject<YansWifiPhy>();
129 phy->SetInterferenceHelper(interferenceHelper);
131 phy->SetErrorRateModel(error);
132 phy->SetChannel(channel);
133 phy->SetDevice(dev);
134 phy->ConfigureStandard(WIFI_STANDARD_80211a);
135 dev->SetPhy(phy);
136 auto manager = m_manager.Create<WifiRemoteStationManager>();
137 dev->SetRemoteStationManager(manager);
138
139 auto txop = CreateObjectWithAttributes<Txop>("AcIndex", StringValue("AC_BE_NQOS"));
140 m_mac.Set("Txop", PointerValue(txop));
141 auto mac = m_mac.Create<WifiMac>();
142 mac->SetDevice(dev);
143 mac->SetAddress(Mac48Address::Allocate());
144 dev->SetMac(mac);
145 mac->SetChannelAccessManagers({CreateObject<ChannelAccessManager>()});
146 mac->SetFrameExchangeManagers({CreateObject<FrameExchangeManager>()});
147 if (mac->GetTypeOfStation() == STA)
148 {
150 }
151 mac->SetMacQueueScheduler(CreateObject<FcfsWifiQueueScheduler>());
152 Ptr<FrameExchangeManager> fem = mac->GetFrameExchangeManager();
153 fem->SetAddress(mac->GetAddress());
155 protectionManager->SetWifiMac(mac);
156 fem->SetProtectionManager(protectionManager);
158 ackManager->SetWifiMac(mac);
159 fem->SetAckManager(ackManager);
160
161 mobility->SetPosition(pos);
162 node->AggregateObject(mobility);
163
165}
166
167void
169{
173 channel->SetPropagationDelayModel(propDelay);
174 channel->SetPropagationLossModel(propLoss);
175
176 CreateOne(Vector(0.0, 0.0, 0.0), channel);
177 CreateOne(Vector(5.0, 0.0, 0.0), channel);
178 CreateOne(Vector(5.0, 0.0, 0.0), channel);
179
181
184}
185
186void
188{
189 m_mac.SetTypeId("ns3::AdhocWifiMac");
190 m_propDelay.SetTypeId("ns3::ConstantSpeedPropagationDelayModel");
191
192 m_manager.SetTypeId("ns3::ArfWifiManager");
193 RunOne();
194 m_manager.SetTypeId("ns3::AarfWifiManager");
195 RunOne();
196 m_manager.SetTypeId("ns3::ConstantRateWifiManager");
197 RunOne();
198 m_manager.SetTypeId("ns3::OnoeWifiManager");
199 RunOne();
200 m_manager.SetTypeId("ns3::AmrrWifiManager");
201 RunOne();
202 m_manager.SetTypeId("ns3::IdealWifiManager");
203 RunOne();
204
205 m_mac.SetTypeId("ns3::AdhocWifiMac");
206 RunOne();
207 m_mac.SetTypeId("ns3::ApWifiMac");
208 RunOne();
209 m_mac.SetTypeId("ns3::StaWifiMac");
210 RunOne();
211
212 m_propDelay.SetTypeId("ns3::RandomPropagationDelayModel");
213 m_mac.SetTypeId("ns3::AdhocWifiMac");
214 RunOne();
215}
216
217/**
218 * @ingroup wifi-test
219 * @ingroup tests
220 *
221 * @brief Qos Utils Is Old Packet Test
222 */
224{
225 public:
227 : TestCase("QosUtilsIsOldPacket")
228 {
229 }
230
231 void DoRun() override
232 {
233 // startingSeq=0, seqNum=2047
235 false,
236 "2047 is new in comparison to 0");
237 // startingSeq=0, seqNum=2048
238 NS_TEST_EXPECT_MSG_EQ(QosUtilsIsOldPacket(0, 2048), true, "2048 is old in comparison to 0");
239 // startingSeq=2048, seqNum=0
240 NS_TEST_EXPECT_MSG_EQ(QosUtilsIsOldPacket(2048, 0), true, "0 is old in comparison to 2048");
241 // startingSeq=4095, seqNum=0
243 false,
244 "0 is new in comparison to 4095");
245 // startingSeq=0, seqNum=4095
246 NS_TEST_EXPECT_MSG_EQ(QosUtilsIsOldPacket(0, 4095), true, "4095 is old in comparison to 0");
247 // startingSeq=4095 seqNum=2047
249 true,
250 "2047 is old in comparison to 4095");
251 // startingSeq=2048 seqNum=4095
253 false,
254 "4095 is new in comparison to 2048");
255 // startingSeq=2049 seqNum=0
257 false,
258 "0 is new in comparison to 2049");
259 }
260};
261
262/**
263 * See \bugid{991}
264 */
266{
267 public:
269
270 void DoRun() override;
271
272 private:
273 /**
274 * Create one function
275 * @param pos the position
276 * @param channel the wifi channel
277 * @returns the node
278 */
279 Ptr<Node> CreateOne(Vector pos, Ptr<YansWifiChannel> channel);
280 /**
281 * Send one packet function
282 * @param dev the device
283 */
285 /**
286 * Switch channel function
287 * @param dev the device
288 */
290
293 ObjectFactory m_propDelay; ///< propagation delay
294};
295
297 : TestCase("InterferenceHelperSequence")
298{
299}
300
301void
303{
304 Ptr<Packet> p = Create<Packet>(1000);
305 dev->Send(p, dev->GetBroadcast(), 1);
306}
307
308void
310{
311 Ptr<WifiPhy> p = dev->GetPhy();
312 p->SetOperatingChannel(WifiPhy::ChannelTuple{40, 0, WIFI_PHY_BAND_5GHZ, 0});
313}
314
317{
320 node->AddDevice(dev);
321
323 auto phy = CreateObject<YansWifiPhy>();
325 phy->SetInterferenceHelper(interferenceHelper);
327 phy->SetErrorRateModel(error);
328 phy->SetChannel(channel);
329 phy->SetDevice(dev);
330 phy->SetMobility(mobility);
331 phy->ConfigureStandard(WIFI_STANDARD_80211a);
332 dev->SetPhy(phy);
333 auto manager = m_manager.Create<WifiRemoteStationManager>();
334 dev->SetRemoteStationManager(manager);
335
336 auto txop = CreateObjectWithAttributes<Txop>("AcIndex", StringValue("AC_BE_NQOS"));
337 m_mac.Set("Txop", PointerValue(txop));
338 auto mac = m_mac.Create<WifiMac>();
339 mac->SetDevice(dev);
340 mac->SetAddress(Mac48Address::Allocate());
341 dev->SetMac(mac);
342 mac->SetChannelAccessManagers({CreateObject<ChannelAccessManager>()});
343 mac->SetFrameExchangeManagers({CreateObject<FrameExchangeManager>()});
344 mac->SetMacQueueScheduler(CreateObject<FcfsWifiQueueScheduler>());
345 Ptr<FrameExchangeManager> fem = mac->GetFrameExchangeManager();
346 fem->SetAddress(mac->GetAddress());
348 protectionManager->SetWifiMac(mac);
349 fem->SetProtectionManager(protectionManager);
351 ackManager->SetWifiMac(mac);
352 fem->SetAckManager(ackManager);
353
354 mobility->SetPosition(pos);
355 node->AggregateObject(mobility);
356
357 return node;
358}
359
360void
362{
363 m_mac.SetTypeId("ns3::AdhocWifiMac");
364 m_propDelay.SetTypeId("ns3::ConstantSpeedPropagationDelayModel");
365 m_manager.SetTypeId("ns3::ConstantRateWifiManager");
366
370 channel->SetPropagationDelayModel(propDelay);
371 channel->SetPropagationLossModel(propLoss);
372
373 Ptr<Node> rxOnly = CreateOne(Vector(0.0, 0.0, 0.0), channel);
374 Ptr<Node> senderA = CreateOne(Vector(5.0, 0.0, 0.0), channel);
375 Ptr<Node> senderB = CreateOne(Vector(-5.0, 0.0, 0.0), channel);
376
377 propLoss->SetLoss(senderB->GetObject<MobilityModel>(),
378 rxOnly->GetObject<MobilityModel>(),
379 0,
380 true);
381 propLoss->SetDefaultLoss(999);
382
385 this,
386 DynamicCast<WifiNetDevice>(senderB->GetDevice(0)));
387
388 Simulator::Schedule(Seconds(1.0000001),
390 this,
391 DynamicCast<WifiNetDevice>(rxOnly->GetDevice(0)));
392
395 this,
396 DynamicCast<WifiNetDevice>(senderA->GetDevice(0)));
397
400 this,
401 DynamicCast<WifiNetDevice>(senderB->GetDevice(0)));
402
405
407}
408
409//-----------------------------------------------------------------------------
410/**
411 * Make sure that when multiple broadcast packets are queued on the same
412 * device in a short succession, that:
413 * 1) no backoff occurs if the frame arrives and the idle time >= DIFS or AIFSn
414 * (this is 'DCF immediate access', Figure 9-3 of IEEE 802.11-2012)
415 * 2) a backoff occurs for the second frame that arrives (this is clearly
416 * stated in Sec. 9.3.4.2 of IEEE 802.11-2012, (basic access, which
417 * applies to group-addressed frames) where it states
418 * "If, under these conditions, the medium is determined by the CS
419 * mechanism to be busy when a STA desires to initiate the initial frame
420 * of a frame exchange sequence (described in Annex G), exclusive of the
421 * CF period, the random backoff procedure described in 9.3.4.3
422 * shall be followed."
423 * and from 9.3.4.3
424 * "The result of this procedure is that transmitted
425 * frames from a STA are always separated by at least one backoff interval."
426 *
427 * The observed behavior is that the first frame will be sent immediately,
428 * and the frames are spaced by (backoff + DIFS) time intervals
429 * (where backoff is a random number of slot sizes up to maximum CW)
430 *
431 * The following test case should _not_ generate virtual collision for
432 * the second frame. The seed and run numbers were pick such that the
433 * second frame gets backoff = 1 slot.
434 *
435 * frame 1, frame 2
436 * arrive DIFS = 2 x slot + SIFS
437 * | = 2 x 9us + 16us for 11a
438 * | <----------->
439 * V <-backoff->
440 * time |--------------|-------------------|-------------|----------->
441 * 0 1s 1.001408s 1.001442s |1.001451s
442 * ^ ^ ^
443 * start TX finish TX start TX
444 * frame 1 frame 1 frame 2
445 * ^
446 * frame 2
447 * backoff = 1 slot
448 *
449 * The buggy behavior observed in prior versions was shown by picking
450 * RngSeedManager::SetRun (17);
451 * which generated a 0 slot backoff for frame 2. Then, frame 2
452 * experiences a virtual collision and re-selects the backoff again.
453 * As a result, the _actual_ backoff experience by frame 2 is less likely
454 * to be 0 since that would require two successions of 0 backoff (one that
455 * generates the virtual collision and one after the virtual collision).
456 *
457 * See \bugid{555} for past behavior.
458 */
459
461{
462 public:
464
465 void DoRun() override;
466
467 private:
468 /**
469 * Send one packet function
470 * @param dev the device
471 */
473
476 ObjectFactory m_propDelay; ///< propagation delay
477
478 Time m_firstTransmissionTime; ///< first transmission time
479 Time m_secondTransmissionTime; ///< second transmission time
480 unsigned int m_numSentPackets; ///< number of sent packets
481
482 /**
483 * Notify Phy transmit begin
484 * @param p the packet
485 * @param txPowerW the tx power
486 */
487 void NotifyPhyTxBegin(Ptr<const Packet> p, double txPowerW);
488};
489
491 : TestCase("Test case for DCF immediate access with broadcast frames")
492{
493}
494
495void
508
509void
511{
512 Ptr<Packet> p = Create<Packet>(1000);
513 dev->Send(p, dev->GetBroadcast(), 1);
514}
515
516void
518{
519 m_mac.SetTypeId("ns3::AdhocWifiMac");
520 m_propDelay.SetTypeId("ns3::ConstantSpeedPropagationDelayModel");
521 m_manager.SetTypeId("ns3::ConstantRateWifiManager");
522
523 // Assign a seed and run number, and later fix the assignment of streams to
524 // WiFi random variables, so that the first backoff used is one slot
526 RngSeedManager::SetRun(40); // a value of 17 will result in zero slots
527
531 channel->SetPropagationDelayModel(propDelay);
532 channel->SetPropagationLossModel(propLoss);
533
534 Ptr<Node> txNode = CreateObject<Node>();
536
540 txPhy->SetInterferenceHelper(txInterferenceHelper);
542 txPhy->SetErrorRateModel(txError);
543 txPhy->SetChannel(channel);
544 txPhy->SetDevice(txDev);
545 txPhy->SetMobility(txMobility);
546 txPhy->ConfigureStandard(WIFI_STANDARD_80211a);
547
548 txPhy->TraceConnectWithoutContext(
549 "PhyTxBegin",
551
552 txMobility->SetPosition(Vector(0.0, 0.0, 0.0));
553 txNode->AggregateObject(txMobility);
554 txDev->SetPhy(txPhy);
555 txDev->SetRemoteStationManager(m_manager.Create<WifiRemoteStationManager>());
556 txNode->AddDevice(txDev);
557
558 auto txop = CreateObjectWithAttributes<Txop>("AcIndex", StringValue("AC_BE_NQOS"));
559 m_mac.Set("Txop", PointerValue(txop));
560 auto txMac = m_mac.Create<WifiMac>();
561 txMac->SetDevice(txDev);
562 txMac->SetAddress(Mac48Address::Allocate());
563 txDev->SetMac(txMac);
564 txMac->SetChannelAccessManagers({CreateObject<ChannelAccessManager>()});
565 txMac->SetFrameExchangeManagers({CreateObject<FrameExchangeManager>()});
566 txMac->SetMacQueueScheduler(CreateObject<FcfsWifiQueueScheduler>());
567 auto fem = txMac->GetFrameExchangeManager();
568 fem->SetAddress(txMac->GetAddress());
569 auto protectionManager = CreateObject<WifiDefaultProtectionManager>();
570 protectionManager->SetWifiMac(txMac);
571 fem->SetProtectionManager(protectionManager);
572 auto ackManager = CreateObject<WifiDefaultAckManager>();
573 ackManager->SetWifiMac(txMac);
574 fem->SetAckManager(ackManager);
575
576 // Fix the stream assignment to the Dcf Txop objects (backoffs)
577 // The below stream assignment will result in the Txop object
578 // using a backoff value of zero for this test when the
579 // Txop::EndTxNoAck() calls to StartBackoffNow()
580 AssignWifiRandomStreams(txMac, 23);
581
585
588 this,
589 txDev);
592 this,
593 txDev);
594
598
599 // First packet is transmitted a DIFS after the packet is queued. A DIFS
600 // is 2 slots (2 * 9 = 18 us) plus a SIFS (16 us), i.e., 34 us
601 Time expectedFirstTransmissionTime = Seconds(1) + MicroSeconds(34);
602
603 // First packet has 1408 us of transmit time. Slot time is 9 us.
604 // Backoff is 1 slots. SIFS is 16 us. DIFS is 2 slots = 18 us.
605 // Should send next packet at 1408 us + (1 * 9 us) + 16 us + (2 * 9) us
606 // 1451 us after the first one.
607 uint32_t expectedWait1 = 1408 + (1 * 9) + 16 + (2 * 9);
608 Time expectedSecondTransmissionTime =
609 expectedFirstTransmissionTime + MicroSeconds(expectedWait1);
611 expectedFirstTransmissionTime,
612 "The first transmission time not correct!");
613
615 expectedSecondTransmissionTime,
616 "The second transmission time not correct!");
617}
618
619//-----------------------------------------------------------------------------
620/**
621 * Make sure that when changing the fragmentation threshold during the simulation,
622 * the TCP transmission does not unexpectedly stop.
623 *
624 * The scenario considers a TCP transmission between a 802.11b station and a 802.11b
625 * access point. After the simulation has begun, the fragmentation threshold is set at
626 * a value lower than the packet size. It then checks whether the TCP transmission
627 * continues after the fragmentation threshold modification.
628 *
629 * See \bugid{730}
630 */
631
633{
634 public:
636 ~Bug730TestCase() override;
637
638 void DoRun() override;
639
640 private:
641 uint32_t m_received; ///< received
642
643 /**
644 * Receive function
645 * @param context the context
646 * @param p the packet
647 * @param adr the address
648 */
649 void Receive(std::string context, Ptr<const Packet> p, const Address& adr);
650};
651
653 : TestCase("Test case for Bug 730"),
654 m_received(0)
655{
656}
657
661
662void
663Bug730TestCase::Receive(std::string context, Ptr<const Packet> p, const Address& adr)
664{
665 if ((p->GetSize() == 1460) && (Simulator::Now() > Seconds(20)))
666 {
667 m_received++;
668 }
669}
670
671void
673{
674 m_received = 0;
675
676 NodeContainer wifiStaNode;
677 wifiStaNode.Create(1);
678
679 NodeContainer wifiApNode;
680 wifiApNode.Create(1);
681
684 phy.SetChannel(channel.Create());
685
686 WifiHelper wifi;
687 wifi.SetStandard(WIFI_STANDARD_80211b);
688 wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager",
689 "DataMode",
690 StringValue("DsssRate1Mbps"),
691 "ControlMode",
692 StringValue("DsssRate1Mbps"));
693
694 WifiMacHelper mac;
695 Ssid ssid = Ssid("ns-3-ssid");
696 mac.SetType("ns3::StaWifiMac", "Ssid", SsidValue(ssid), "ActiveProbing", BooleanValue(false));
697
698 NetDeviceContainer staDevices;
699 staDevices = wifi.Install(phy, mac, wifiStaNode);
700
701 mac.SetType("ns3::ApWifiMac", "Ssid", SsidValue(ssid), "BeaconGeneration", BooleanValue(true));
702
703 NetDeviceContainer apDevices;
704 apDevices = wifi.Install(phy, mac, wifiApNode);
705
706 MobilityHelper mobility;
708
709 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
710 positionAlloc->Add(Vector(1.0, 0.0, 0.0));
711 mobility.SetPositionAllocator(positionAlloc);
712
713 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
714 mobility.Install(wifiApNode);
715 mobility.Install(wifiStaNode);
716
717 Ptr<WifiNetDevice> ap_device = DynamicCast<WifiNetDevice>(apDevices.Get(0));
718 Ptr<WifiNetDevice> sta_device = DynamicCast<WifiNetDevice>(staDevices.Get(0));
719
720 PacketSocketAddress socket;
721 socket.SetSingleDevice(sta_device->GetIfIndex());
722 socket.SetPhysicalAddress(ap_device->GetAddress());
723 socket.SetProtocol(1);
724
725 // give packet socket powers to nodes.
726 PacketSocketHelper packetSocket;
727 packetSocket.Install(wifiStaNode);
728 packetSocket.Install(wifiApNode);
729
731 client->SetAttribute("PacketSize", UintegerValue(1460));
732 client->SetRemote(socket);
733 wifiStaNode.Get(0)->AddApplication(client);
734 client->SetStartTime(Seconds(1));
735 client->SetStopTime(Seconds(51));
736
738 server->SetLocal(socket);
739 wifiApNode.Get(0)->AddApplication(server);
740 server->SetStartTime(Seconds(0));
741 server->SetStopTime(Seconds(52));
742
743 Config::Connect("/NodeList/*/ApplicationList/0/$ns3::PacketSocketServer/Rx",
745
748 "/NodeList/0/DeviceList/0/RemoteStationManager/FragmentationThreshold",
749 StringValue("800"));
750
753
755
756 bool result = (m_received > 0);
758 result,
759 true,
760 "packet reception unexpectedly stopped after adapting fragmentation threshold!");
761}
762
763//-----------------------------------------------------------------------------
764/**
765 * Make sure that fragmentation works with QoS stations.
766 *
767 * The scenario considers a TCP transmission between an 802.11n station and an 802.11n
768 * access point.
769 */
770
772{
773 public:
775 ~QosFragmentationTestCase() override;
776
777 void DoRun() override;
778
779 private:
780 uint32_t m_received; ///< received packets
781 uint32_t m_fragments; ///< transmitted fragments
782
783 /**
784 * Receive function
785 * @param context the context
786 * @param p the packet
787 * @param adr the address
788 */
789 void Receive(std::string context, Ptr<const Packet> p, const Address& adr);
790
791 /**
792 * Callback invoked when PHY transmits a packet
793 * @param context the context
794 * @param p the packet
795 * @param power the tx power
796 */
797 void Transmit(std::string context, Ptr<const Packet> p, double power);
798};
799
801 : TestCase("Test case for fragmentation with QoS stations"),
802 m_received(0),
803 m_fragments(0)
804{
805}
806
810
811void
813{
814 if (p->GetSize() == 1400)
815 {
816 m_received++;
817 }
818}
819
820void
821QosFragmentationTestCase::Transmit(std::string context, Ptr<const Packet> p, double power)
822{
823 WifiMacHeader hdr;
824 p->PeekHeader(hdr);
825 if (hdr.IsQosData())
826 {
827 NS_TEST_EXPECT_MSG_LT_OR_EQ(p->GetSize(), 400, "Unexpected fragment size");
828 m_fragments++;
829 }
830}
831
832void
834{
835 NodeContainer wifiStaNode;
836 wifiStaNode.Create(1);
837
838 NodeContainer wifiApNode;
839 wifiApNode.Create(1);
840
843 phy.SetChannel(channel.Create());
844
845 WifiHelper wifi;
846 wifi.SetStandard(WIFI_STANDARD_80211n);
847 wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager", "DataMode", StringValue("HtMcs7"));
848
849 WifiMacHelper mac;
850 Ssid ssid = Ssid("ns-3-ssid");
851 mac.SetType("ns3::StaWifiMac", "Ssid", SsidValue(ssid), "ActiveProbing", BooleanValue(false));
852
853 NetDeviceContainer staDevices;
854 staDevices = wifi.Install(phy, mac, wifiStaNode);
855
856 mac.SetType("ns3::ApWifiMac", "Ssid", SsidValue(ssid), "BeaconGeneration", BooleanValue(true));
857
858 NetDeviceContainer apDevices;
859 apDevices = wifi.Install(phy, mac, wifiApNode);
860
861 MobilityHelper mobility;
863
864 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
865 positionAlloc->Add(Vector(1.0, 0.0, 0.0));
866 mobility.SetPositionAllocator(positionAlloc);
867
868 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
869 mobility.Install(wifiApNode);
870 mobility.Install(wifiStaNode);
871
872 Ptr<WifiNetDevice> ap_device = DynamicCast<WifiNetDevice>(apDevices.Get(0));
873 Ptr<WifiNetDevice> sta_device = DynamicCast<WifiNetDevice>(staDevices.Get(0));
874
875 // set the TXOP limit on BE AC
876 sta_device->GetMac()->GetQosTxop(AC_BE)->SetTxopLimit(MicroSeconds(3008));
877
878 PacketSocketAddress socket;
879 socket.SetSingleDevice(sta_device->GetIfIndex());
880 socket.SetPhysicalAddress(ap_device->GetAddress());
881 socket.SetProtocol(1);
882
883 // give packet socket powers to nodes.
884 PacketSocketHelper packetSocket;
885 packetSocket.Install(wifiStaNode);
886 packetSocket.Install(wifiApNode);
887
889 client->SetAttribute("PacketSize", UintegerValue(1400));
890 client->SetAttribute("MaxPackets", UintegerValue(1));
891 client->SetRemote(socket);
892 wifiStaNode.Get(0)->AddApplication(client);
893 client->SetStartTime(Seconds(1));
894 client->SetStopTime(Seconds(3));
895
897 server->SetLocal(socket);
898 wifiApNode.Get(0)->AddApplication(server);
899 server->SetStartTime(Seconds(0));
900 server->SetStopTime(Seconds(4));
901
902 Config::Connect("/NodeList/*/ApplicationList/0/$ns3::PacketSocketServer/Rx",
904
905 Config::Set("/NodeList/0/DeviceList/0/RemoteStationManager/FragmentationThreshold",
906 StringValue("400"));
907 Config::Connect("/NodeList/0/DeviceList/0/Phy/PhyTxBegin",
909
912
914
915 NS_TEST_ASSERT_MSG_EQ(m_received, 1, "Unexpected number of received packets");
916 NS_TEST_ASSERT_MSG_EQ(m_fragments, 4, "Unexpected number of transmitted fragments");
917}
918
919/**
920 * @ingroup wifi-test
921 * @ingroup tests
922 *
923 * @brief Set Channel Frequency Test
924 */
926{
927 public:
929
930 void DoRun() override;
931
932 private:
933 /**
934 * Get yans wifi phy function
935 * @param nc the device collection
936 * @returns the wifi phy
937 */
939};
940
942 : TestCase("Test case for setting WifiPhy channel and frequency")
943{
944}
945
948{
949 Ptr<WifiNetDevice> wnd = nc.Get(0)->GetObject<WifiNetDevice>();
950 Ptr<WifiPhy> wp = wnd->GetPhy();
951 return wp->GetObject<YansWifiPhy>();
952}
953
954void
956{
957 NodeContainer wifiStaNode;
958 wifiStaNode.Create(1);
959 NodeContainer wifiApNode;
960 wifiApNode.Create(1);
961
964 phy.SetChannel(channel.Create());
965
966 // Configure and declare other generic components of this example
967 Ssid ssid;
968 ssid = Ssid("wifi-phy-configuration");
969 WifiMacHelper macSta;
970 macSta.SetType("ns3::StaWifiMac",
971 "Ssid",
972 SsidValue(ssid),
973 "ActiveProbing",
974 BooleanValue(false));
975 NetDeviceContainer staDevice;
976 Ptr<YansWifiPhy> phySta;
977
978 // Cases taken from src/wifi/examples/wifi-phy-configuration.cc example
979 {
980 // case 0:
981 // Default configuration, without WifiHelper::SetStandard or WifiHelper
982 phySta = CreateObject<YansWifiPhy>();
983 // The default results in an invalid configuration
984 NS_TEST_ASSERT_MSG_EQ(phySta->GetOperatingChannel().IsSet(),
985 false,
986 "default configuration");
987 }
988 {
989 // case 1:
990 WifiHelper wifi;
991 wifi.SetStandard(WIFI_STANDARD_80211a);
992 wifi.SetRemoteStationManager("ns3::ArfWifiManager");
993 staDevice = wifi.Install(phy, macSta, wifiStaNode.Get(0));
994 phySta = GetYansWifiPhyPtr(staDevice);
995 // We expect channel 36, width 20, frequency 5180
996 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelNumber(), 36, "default configuration");
997 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelWidth(), MHz_u{20}, "default configuration");
998 NS_TEST_ASSERT_MSG_EQ(phySta->GetFrequency(), MHz_u{5180}, "default configuration");
999 }
1000 {
1001 // case 2:
1002 WifiHelper wifi;
1003 wifi.SetStandard(WIFI_STANDARD_80211b);
1004 staDevice = wifi.Install(phy, macSta, wifiStaNode.Get(0));
1005 phySta = GetYansWifiPhyPtr(staDevice);
1006 // We expect channel 1, width 22, frequency 2412
1007 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelNumber(), 1, "802.11b configuration");
1008 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelWidth(), MHz_u{22}, "802.11b configuration");
1009 NS_TEST_ASSERT_MSG_EQ(phySta->GetFrequency(), MHz_u{2412}, "802.11b configuration");
1010 }
1011 {
1012 // case 3:
1013 WifiHelper wifi;
1014 wifi.SetStandard(WIFI_STANDARD_80211g);
1015 staDevice = wifi.Install(phy, macSta, wifiStaNode.Get(0));
1016 phySta = GetYansWifiPhyPtr(staDevice);
1017 // We expect channel 1, width 20, frequency 2412
1018 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelNumber(), 1, "802.11g configuration");
1019 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelWidth(), MHz_u{20}, "802.11g configuration");
1020 NS_TEST_ASSERT_MSG_EQ(phySta->GetFrequency(), MHz_u{2412}, "802.11g configuration");
1021 }
1022 {
1023 // case 4:
1024 WifiHelper wifi;
1025 wifi.SetRemoteStationManager("ns3::IdealWifiManager");
1026 wifi.SetStandard(WIFI_STANDARD_80211n);
1027 phy.Set("ChannelSettings", StringValue("{0, 0, BAND_5GHZ, 0}"));
1028 staDevice = wifi.Install(phy, macSta, wifiStaNode.Get(0));
1029 phySta = GetYansWifiPhyPtr(staDevice);
1030 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelNumber(), 36, "802.11n-5GHz configuration");
1031 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelWidth(), MHz_u{20}, "802.11n-5GHz configuration");
1032 NS_TEST_ASSERT_MSG_EQ(phySta->GetFrequency(), MHz_u{5180}, "802.11n-5GHz configuration");
1033 phy.Set("ChannelSettings", StringValue("{0, 0, BAND_UNSPECIFIED, 0}")); // restore default
1034 }
1035 {
1036 // case 5:
1037 WifiHelper wifi;
1038 wifi.SetRemoteStationManager("ns3::IdealWifiManager");
1039 wifi.SetStandard(WIFI_STANDARD_80211n);
1040 staDevice = wifi.Install(phy, macSta, wifiStaNode.Get(0));
1041 phySta = GetYansWifiPhyPtr(staDevice);
1042 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelNumber(), 1, "802.11n-2.4GHz configuration");
1043 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelWidth(), MHz_u{20}, "802.11n-2.4GHz configuration");
1044 NS_TEST_ASSERT_MSG_EQ(phySta->GetFrequency(), MHz_u{2412}, "802.11n-2.4GHz configuration");
1045 }
1046 {
1047 // case 6:
1048 WifiHelper wifi;
1049 wifi.SetRemoteStationManager("ns3::IdealWifiManager");
1050 wifi.SetStandard(WIFI_STANDARD_80211ac);
1051 staDevice = wifi.Install(phy, macSta, wifiStaNode.Get(0));
1052 phySta = GetYansWifiPhyPtr(staDevice);
1053 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelNumber(), 42, "802.11ac configuration");
1054 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelWidth(), MHz_u{80}, "802.11ac configuration");
1055 NS_TEST_ASSERT_MSG_EQ(phySta->GetFrequency(), MHz_u{5210}, "802.11ac configuration");
1056 }
1057 {
1058 // case 7:
1059 // By default, WifiHelper will use WIFI_PHY_STANDARD_80211ax
1060 WifiHelper wifi;
1061 wifi.SetRemoteStationManager("ns3::IdealWifiManager");
1062 phy.Set("ChannelSettings", StringValue("{0, 0, BAND_2_4GHZ, 0}"));
1063 staDevice = wifi.Install(phy, macSta, wifiStaNode.Get(0));
1064 phySta = GetYansWifiPhyPtr(staDevice);
1065 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelNumber(), 1, "802.11ax-2.4GHz configuration");
1066 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelWidth(),
1067 MHz_u{20},
1068 "802.11ax-2.4GHz configuration");
1069 NS_TEST_ASSERT_MSG_EQ(phySta->GetFrequency(), MHz_u{2412}, "802.11ax-2.4GHz configuration");
1070 phy.Set("ChannelSettings", StringValue("{0, 0, BAND_UNSPECIFIED, 0}")); // restore default
1071 }
1072 {
1073 // case 8:
1074 WifiHelper wifi;
1075 wifi.SetRemoteStationManager("ns3::IdealWifiManager");
1076 staDevice = wifi.Install(phy, macSta, wifiStaNode.Get(0));
1077 phySta = GetYansWifiPhyPtr(staDevice);
1078 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelNumber(), 42, "802.11ax-5GHz configuration");
1079 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelWidth(), MHz_u{80}, "802.11ax-5GHz configuration");
1080 NS_TEST_ASSERT_MSG_EQ(phySta->GetFrequency(), MHz_u{5210}, "802.11ax-5GHz configuration");
1081 }
1082 {
1083 // case 9:
1084 WifiHelper wifi;
1085 wifi.SetRemoteStationManager("ns3::IdealWifiManager");
1086 phy.Set("ChannelSettings", StringValue("{0, 0, BAND_6GHZ, 0}"));
1087 staDevice = wifi.Install(phy, macSta, wifiStaNode.Get(0));
1088 phySta = GetYansWifiPhyPtr(staDevice);
1089 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelNumber(), 7, "802.11ax-6GHz configuration");
1090 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelWidth(), MHz_u{80}, "802.11ax-6GHz configuration");
1091 NS_TEST_ASSERT_MSG_EQ(phySta->GetFrequency(), MHz_u{5985}, "802.11ax-6GHz configuration");
1092 phy.Set("ChannelSettings", StringValue("{0, 0, BAND_UNSPECIFIED, 0}")); // restore default
1093 }
1094 {
1095 // case 10:
1096 WifiHelper wifi;
1097 wifi.SetRemoteStationManager("ns3::IdealWifiManager");
1098 wifi.SetStandard(WIFI_STANDARD_80211p);
1099 phy.Set("ChannelSettings", StringValue("{0, 10, BAND_5GHZ, 0}"));
1100 staDevice = wifi.Install(phy, macSta, wifiStaNode.Get(0));
1101 phySta = GetYansWifiPhyPtr(staDevice);
1102 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelNumber(), 172, "802.11p 10Mhz configuration");
1103 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelWidth(), MHz_u{10}, "802.11p 10Mhz configuration");
1104 NS_TEST_ASSERT_MSG_EQ(phySta->GetFrequency(), MHz_u{5860}, "802.11p 10Mhz configuration");
1105 phy.Set("ChannelSettings", StringValue("{0, 0, BAND_UNSPECIFIED, 0}")); // restore default
1106 }
1107 {
1108 // case 11:
1109 WifiHelper wifi;
1110 wifi.SetRemoteStationManager("ns3::IdealWifiManager");
1111 wifi.SetStandard(WIFI_STANDARD_80211p);
1112 phy.Set("ChannelSettings", StringValue("{0, 5, BAND_5GHZ, 0}"));
1113 staDevice = wifi.Install(phy, macSta, wifiStaNode.Get(0));
1114 phySta = GetYansWifiPhyPtr(staDevice);
1115 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelNumber(), 171, "802.11p 5Mhz configuration");
1116 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelWidth(), MHz_u{5}, "802.11p 5Mhz configuration");
1117 NS_TEST_ASSERT_MSG_EQ(phySta->GetFrequency(), MHz_u{5860}, "802.11p 5Mhz configuration");
1118 phy.Set("ChannelSettings", StringValue("{0, 0, BAND_UNSPECIFIED, 0}")); // restore default
1119 }
1120 {
1121 // case 12:
1122 WifiHelper wifi;
1123 wifi.SetRemoteStationManager("ns3::IdealWifiManager");
1124 wifi.SetStandard(WIFI_STANDARD_80211n);
1125 phy.Set("ChannelSettings", StringValue("{44, 20, BAND_5GHZ, 0}"));
1126 staDevice = wifi.Install(phy, macSta, wifiStaNode.Get(0));
1127 phySta = GetYansWifiPhyPtr(staDevice);
1128 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelNumber(), 44, "802.11 5GHz configuration");
1129 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelWidth(), MHz_u{20}, "802.11 5GHz configuration");
1130 NS_TEST_ASSERT_MSG_EQ(phySta->GetFrequency(), MHz_u{5220}, "802.11 5GHz configuration");
1131 phy.Set("ChannelSettings", StringValue("{0, 0, BAND_UNSPECIFIED, 0}")); // restore default
1132 }
1133 {
1134 // case 13:
1135 WifiHelper wifi;
1136 wifi.SetRemoteStationManager("ns3::IdealWifiManager");
1137 phy.Set("ChannelSettings", StringValue("{44, 0, BAND_5GHZ, 0}"));
1138 staDevice = wifi.Install(phy, macSta, wifiStaNode.Get(0));
1139 phySta = GetYansWifiPhyPtr(staDevice);
1140 // Post-install reconfiguration to channel number 40
1141 std::ostringstream path;
1142 path << "/NodeList/*/DeviceList/" << staDevice.Get(0)->GetIfIndex()
1143 << "/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/ChannelSettings";
1144 Config::Set(path.str(), StringValue("{40, 0, BAND_5GHZ, 0}"));
1145 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelNumber(), 40, "802.11 5GHz configuration");
1146 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelWidth(), MHz_u{20}, "802.11 5GHz configuration");
1147 NS_TEST_ASSERT_MSG_EQ(phySta->GetFrequency(), MHz_u{5200}, "802.11 5GHz configuration");
1148 phy.Set("ChannelSettings", StringValue("{0, 0, BAND_UNSPECIFIED, 0}")); // restore default
1149 }
1150 {
1151 // case 14:
1152 WifiHelper wifi;
1153 wifi.SetRemoteStationManager("ns3::IdealWifiManager");
1154 phy.Set("ChannelSettings", StringValue("{44, 0, BAND_5GHZ, 0}"));
1155 staDevice = wifi.Install(phy, macSta, wifiStaNode.Get(0));
1156 phySta = GetYansWifiPhyPtr(staDevice);
1157 // Post-install reconfiguration to a 40 MHz channel
1158 std::ostringstream path;
1159 path << "/NodeList/*/DeviceList/" << staDevice.Get(0)->GetIfIndex()
1160 << "/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/ChannelSettings";
1161 Config::Set(path.str(), StringValue("{46, 0, BAND_5GHZ, 0}"));
1162 // Although channel 44 is configured originally for 20 MHz, we
1163 // allow it to be used for 40 MHz here
1164 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelNumber(), 46, "802.11 5GHz configuration");
1165 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelWidth(), MHz_u{40}, "802.11 5GHz configuration");
1166 NS_TEST_ASSERT_MSG_EQ(phySta->GetFrequency(), MHz_u{5230}, "802.11 5GHz configuration");
1167 phy.Set("ChannelSettings", StringValue("{0, 0, BAND_UNSPECIFIED, 0}")); // restore default
1168 }
1169 {
1170 // case 15:
1171 WifiHelper wifi;
1172 wifi.SetRemoteStationManager("ns3::IdealWifiManager");
1173 wifi.SetStandard(WIFI_STANDARD_80211n);
1174 staDevice = wifi.Install(phy, macSta, wifiStaNode.Get(0));
1175 phySta = GetYansWifiPhyPtr(staDevice);
1176 phySta->SetAttribute("ChannelSettings", StringValue("{3, 20, BAND_2_4GHZ, 0}"));
1177 // Post-install reconfiguration to a 40 MHz channel
1178 std::ostringstream path;
1179 path << "/NodeList/*/DeviceList/" << staDevice.Get(0)->GetIfIndex()
1180 << "/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/ChannelSettings";
1181 Config::Set(path.str(), StringValue("{4, 40, BAND_2_4GHZ, 0}"));
1182 // Although channel 44 is configured originally for 20 MHz, we
1183 // allow it to be used for 40 MHz here
1184 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelNumber(), 4, "802.11 5GHz configuration");
1185 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelWidth(), MHz_u{40}, "802.11 5GHz configuration");
1186 NS_TEST_ASSERT_MSG_EQ(phySta->GetFrequency(), MHz_u{2427}, "802.11 5GHz configuration");
1187 phy.Set("ChannelSettings", StringValue("{0, 0, BAND_UNSPECIFIED, 0}")); // restore default
1188 }
1189 {
1190 // case 16:
1191 WifiHelper wifi;
1192 wifi.SetRemoteStationManager("ns3::IdealWifiManager");
1193 // Test that setting Frequency to a non-standard value will throw an exception
1194 wifi.SetStandard(WIFI_STANDARD_80211n);
1195 phy.Set("ChannelSettings", StringValue("{44, 0, BAND_5GHZ, 0}"));
1196 staDevice = wifi.Install(phy, macSta, wifiStaNode.Get(0));
1197 phySta = GetYansWifiPhyPtr(staDevice);
1198 bool exceptionThrown = false;
1199 try
1200 {
1201 phySta->SetAttribute("ChannelSettings", StringValue("{45, 0, BAND_5GHZ, 0}"));
1202 }
1203 catch (const std::runtime_error&)
1204 {
1205 exceptionThrown = true;
1206 }
1207 // We expect that an exception is thrown
1208 NS_TEST_ASSERT_MSG_EQ(exceptionThrown, true, "802.11 5GHz configuration");
1209 }
1210 {
1211 // case 17:
1212 WifiHelper wifi;
1213 wifi.SetRemoteStationManager("ns3::IdealWifiManager");
1214 wifi.SetStandard(WIFI_STANDARD_80211n);
1215 phy.Set("ChannelSettings", StringValue("{44, 0, BAND_5GHZ, 0}"));
1216 staDevice = wifi.Install(phy, macSta, wifiStaNode.Get(0));
1217 phySta = GetYansWifiPhyPtr(staDevice);
1218 // Test that setting channel to a standard value will set the
1219 // frequency correctly
1220 phySta->SetAttribute("ChannelSettings", StringValue("{100, 0, BAND_5GHZ, 0}"));
1221 // We expect frequency to be 5500 due to channel number being 100
1222 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelNumber(), 100, "802.11 5GHz configuration");
1223 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelWidth(), MHz_u{20}, "802.11 5GHz configuration");
1224 NS_TEST_ASSERT_MSG_EQ(phySta->GetFrequency(), MHz_u{5500}, "802.11 5GHz configuration");
1225 }
1226 {
1227 // case 18:
1228 // Set a wrong channel after initialization
1229 WifiHelper wifi;
1230 wifi.SetRemoteStationManager("ns3::IdealWifiManager");
1231 wifi.SetStandard(WIFI_STANDARD_80211n);
1232 phy.Set("ChannelSettings", StringValue("{44, 0, BAND_5GHZ, 0}"));
1233 staDevice = wifi.Install(phy, macSta, wifiStaNode.Get(0));
1234 phySta = GetYansWifiPhyPtr(staDevice);
1235 bool exceptionThrown = false;
1236 try
1237 {
1238 phySta->SetOperatingChannel(WifiPhy::ChannelTuple{99, 40, WIFI_PHY_BAND_5GHZ, 0});
1239 }
1240 catch (const std::runtime_error&)
1241 {
1242 exceptionThrown = true;
1243 }
1244 // We expect that an exception is thrown
1245 NS_TEST_ASSERT_MSG_EQ(exceptionThrown, true, "802.11 5GHz configuration");
1246 }
1247 {
1248 // case 19:
1249 WifiHelper wifi;
1250 wifi.SetRemoteStationManager("ns3::IdealWifiManager");
1251 // Test how channel number behaves when frequency is non-standard
1252 wifi.SetStandard(WIFI_STANDARD_80211n);
1253 phy.Set("ChannelSettings", StringValue("{44, 0, BAND_5GHZ, 0}"));
1254 staDevice = wifi.Install(phy, macSta, wifiStaNode.Get(0));
1255 phySta = GetYansWifiPhyPtr(staDevice);
1256 bool exceptionThrown = false;
1257 try
1258 {
1259 phySta->SetAttribute("ChannelSettings", StringValue("{45, 0, BAND_5GHZ, 0}"));
1260 }
1261 catch (const std::runtime_error&)
1262 {
1263 exceptionThrown = true;
1264 }
1265 // We expect that an exception is thrown due to unknown channel number 45
1266 NS_TEST_ASSERT_MSG_EQ(exceptionThrown, true, "802.11 5GHz configuration");
1267 phySta->SetAttribute("ChannelSettings", StringValue("{36, 0, BAND_5GHZ, 0}"));
1268 // We expect channel number to be 36 due to known center frequency 5180
1269 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelNumber(), 36, "802.11 5GHz configuration");
1270 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelWidth(), MHz_u{20}, "802.11 5GHz configuration");
1271 NS_TEST_ASSERT_MSG_EQ(phySta->GetFrequency(), MHz_u{5180}, "802.11 5GHz configuration");
1272 exceptionThrown = false;
1273 try
1274 {
1275 phySta->SetAttribute("ChannelSettings", StringValue("{43, 0, BAND_5GHZ, 0}"));
1276 }
1277 catch (const std::runtime_error&)
1278 {
1279 exceptionThrown = true;
1280 }
1281 // We expect that an exception is thrown due to unknown channel number 43
1282 NS_TEST_ASSERT_MSG_EQ(exceptionThrown, true, "802.11 5GHz configuration");
1283 phySta->SetAttribute("ChannelSettings", StringValue("{36, 0, BAND_5GHZ, 0}"));
1284 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelNumber(), 36, "802.11 5GHz configuration");
1285 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelWidth(), MHz_u{20}, "802.11 5GHz configuration");
1286 NS_TEST_ASSERT_MSG_EQ(phySta->GetFrequency(), MHz_u{5180}, "802.11 5GHz configuration");
1287 }
1288 {
1289 // case 20:
1290 WifiHelper wifi;
1291 wifi.SetRemoteStationManager("ns3::IdealWifiManager");
1292 phy.Set("ChannelSettings", StringValue("{40, 0, BAND_5GHZ, 0}"));
1293 wifi.SetStandard(WIFI_STANDARD_80211n);
1294 staDevice = wifi.Install(phy, macSta, wifiStaNode.Get(0));
1295 phySta = GetYansWifiPhyPtr(staDevice);
1296 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelNumber(), 40, "802.11 5GHz configuration");
1297 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelWidth(), MHz_u{20}, "802.11 5GHz configuration");
1298 NS_TEST_ASSERT_MSG_EQ(phySta->GetFrequency(), MHz_u{5200}, "802.11 5GHz configuration");
1299 // Set both channel and frequency to consistent values after initialization
1300 wifi.SetStandard(WIFI_STANDARD_80211n);
1301 staDevice = wifi.Install(phy, macSta, wifiStaNode.Get(0));
1302 phySta = GetYansWifiPhyPtr(staDevice);
1303 phySta->SetAttribute("ChannelSettings", StringValue("{40, 0, BAND_5GHZ, 0}"));
1304 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelNumber(), 40, "802.11 5GHz configuration");
1305 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelWidth(), MHz_u{20}, "802.11 5GHz configuration");
1306 NS_TEST_ASSERT_MSG_EQ(phySta->GetFrequency(), MHz_u{5200}, "802.11 5GHz configuration");
1307
1308 phySta->SetAttribute("ChannelSettings", StringValue("{36, 0, BAND_5GHZ, 0}"));
1309 // We expect channel number to be 36
1310 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelNumber(), 36, "802.11 5GHz configuration");
1311 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelWidth(), MHz_u{20}, "802.11 5GHz configuration");
1312 NS_TEST_ASSERT_MSG_EQ(phySta->GetFrequency(), MHz_u{5180}, "802.11 5GHz configuration");
1313 phySta->SetAttribute("ChannelSettings", StringValue("{40, 0, BAND_5GHZ, 0}"));
1314 // We expect channel number to be 40
1315 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelNumber(), 40, "802.11 5GHz configuration");
1316 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelWidth(), MHz_u{20}, "802.11 5GHz configuration");
1317 NS_TEST_ASSERT_MSG_EQ(phySta->GetFrequency(), MHz_u{5200}, "802.11 5GHz configuration");
1318 bool exceptionThrown = false;
1319 try
1320 {
1321 phySta->SetAttribute("ChannelSettings", StringValue("{45, 0, BAND_5GHZ, 0}"));
1322 }
1323 catch (const std::runtime_error&)
1324 {
1325 exceptionThrown = true;
1326 }
1327 phySta->SetAttribute("ChannelSettings", StringValue("{36, 0, BAND_5GHZ, 0}"));
1328 // We expect channel number to be 36 and an exception to be thrown
1329 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelNumber(), 36, "802.11 5GHz configuration");
1330 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelWidth(), MHz_u{20}, "802.11 5GHz configuration");
1331 NS_TEST_ASSERT_MSG_EQ(phySta->GetFrequency(), MHz_u{5180}, "802.11 5GHz configuration");
1332 NS_TEST_ASSERT_MSG_EQ(exceptionThrown, true, "802.11 5GHz configuration");
1333 phySta->SetAttribute("ChannelSettings", StringValue("{36, 0, BAND_5GHZ, 0}"));
1334 exceptionThrown = false;
1335 try
1336 {
1337 phySta->SetAttribute("ChannelSettings", StringValue("{43, 0, BAND_5GHZ, 0}"));
1338 }
1339 catch (const std::runtime_error&)
1340 {
1341 exceptionThrown = true;
1342 }
1343 // We expect channel number to be 36 and an exception to be thrown
1344 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelNumber(), 36, "802.11 5GHz configuration");
1345 NS_TEST_ASSERT_MSG_EQ(phySta->GetChannelWidth(), MHz_u{20}, "802.11 5GHz configuration");
1346 NS_TEST_ASSERT_MSG_EQ(phySta->GetFrequency(), MHz_u{5180}, "802.11 5GHz configuration");
1347 NS_TEST_ASSERT_MSG_EQ(exceptionThrown, true, "802.11 5GHz configuration");
1348 }
1349
1351}
1352
1353//-----------------------------------------------------------------------------
1354/**
1355 * Make sure that when virtual collision occurs the wifi remote station manager
1356 * is triggered and the retry counter is increased.
1357 *
1358 * See \bugid{2222}
1359 */
1360
1362{
1363 public:
1365 ~Bug2222TestCase() override;
1366
1367 void DoRun() override;
1368
1369 private:
1370 uint32_t m_countInternalCollisions; ///< count internal collisions
1371
1372 /**
1373 * Transmit data failed function
1374 * @param context the context
1375 * @param adr the MAC address
1376 */
1377 void TxDataFailedTrace(std::string context, Mac48Address adr);
1378};
1379
1381 : TestCase("Test case for Bug 2222"),
1383{
1384}
1385
1389
1390void
1392{
1393 // Indicate the long retry counter has been increased in the wifi remote station manager
1395}
1396
1397void
1399{
1401
1402 // Generate same backoff for AC_VI and AC_VO
1403 // The below combination will work
1406 int64_t streamNumber = 100;
1407
1408 NodeContainer wifiNodes;
1409 wifiNodes.Create(2);
1410
1413 phy.SetChannel(channel.Create());
1414
1415 WifiHelper wifi;
1416 wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager",
1417 "DataMode",
1418 StringValue("OfdmRate54Mbps"),
1419 "ControlMode",
1420 StringValue("OfdmRate24Mbps"));
1421 WifiMacHelper mac;
1422 Ssid ssid = Ssid("ns-3-ssid");
1423 mac.SetType("ns3::AdhocWifiMac", "QosSupported", BooleanValue(true));
1424
1425 NetDeviceContainer wifiDevices;
1426 wifiDevices = wifi.Install(phy, mac, wifiNodes);
1427
1428 // Assign fixed streams to random variables in use
1429 WifiHelper::AssignStreams(wifiDevices, streamNumber);
1430
1431 MobilityHelper mobility;
1433
1434 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
1435 positionAlloc->Add(Vector(10.0, 0.0, 0.0));
1436 mobility.SetPositionAllocator(positionAlloc);
1437
1438 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
1439 mobility.Install(wifiNodes);
1440
1441 Ptr<WifiNetDevice> device1 = DynamicCast<WifiNetDevice>(wifiDevices.Get(0));
1442 Ptr<WifiNetDevice> device2 = DynamicCast<WifiNetDevice>(wifiDevices.Get(1));
1443
1444 PacketSocketAddress socket;
1445 socket.SetSingleDevice(device1->GetIfIndex());
1446 socket.SetPhysicalAddress(device2->GetAddress());
1447 socket.SetProtocol(1);
1448
1449 PacketSocketHelper packetSocket;
1450 packetSocket.Install(wifiNodes);
1451
1453 clientLowPriority->SetAttribute("PacketSize", UintegerValue(1460));
1454 clientLowPriority->SetAttribute("MaxPackets", UintegerValue(1));
1455 clientLowPriority->SetAttribute("Priority", UintegerValue(4)); // AC_VI
1456 clientLowPriority->SetRemote(socket);
1457 wifiNodes.Get(0)->AddApplication(clientLowPriority);
1458 clientLowPriority->SetStartTime(Seconds(0));
1459 clientLowPriority->SetStopTime(Seconds(1));
1460
1462 clientHighPriority->SetAttribute("PacketSize", UintegerValue(1460));
1463 clientHighPriority->SetAttribute("MaxPackets", UintegerValue(1));
1464 clientHighPriority->SetAttribute("Priority", UintegerValue(6)); // AC_VO
1465 clientHighPriority->SetRemote(socket);
1466 wifiNodes.Get(0)->AddApplication(clientHighPriority);
1467 clientHighPriority->SetStartTime(Seconds(0));
1468 clientHighPriority->SetStopTime(Seconds(1));
1469
1471 server->SetLocal(socket);
1472 wifiNodes.Get(1)->AddApplication(server);
1473 server->SetStartTime(Seconds(0));
1474 server->SetStopTime(Seconds(1));
1475
1476 Config::Connect("/NodeList/*/DeviceList/*/RemoteStationManager/MacTxDataFailed",
1478
1482
1484 1,
1485 "unexpected number of internal collisions!");
1486}
1487
1488//-----------------------------------------------------------------------------
1489/**
1490 * Make sure that the correct channel width and center frequency have been set
1491 * for OFDM basic rate transmissions and BSS channel widths larger than 20 MHz.
1492 *
1493 * The scenario considers a UDP transmission between a 40 MHz 802.11ac station and a
1494 * 40 MHz 802.11ac access point. All transmission parameters are checked so as
1495 * to ensure that only 3 {starting frequency, channelWidth, Number of subbands
1496 * in SpectrumModel, modulation type} tuples are used.
1497 *
1498 * See \bugid{2843}
1499 */
1500
1502{
1503 public:
1505 ~Bug2843TestCase() override;
1506 void DoRun() override;
1507
1508 private:
1509 /**
1510 * A tuple of {starting frequency, channelWidth, Number of subbands in SpectrumModel, modulation
1511 * type}
1512 */
1513 typedef std::tuple<Hz_u, MHz_u, uint32_t, WifiModulationClass> FreqWidthSubbandModulationTuple;
1514 std::vector<FreqWidthSubbandModulationTuple>
1515 m_distinctTuples; ///< vector of distinct {starting frequency, channelWidth, Number of
1516 ///< subbands in SpectrumModel, modulation type} tuples
1517
1518 /**
1519 * Stores the distinct {starting frequency, channelWidth, Number of subbands in SpectrumModel,
1520 * modulation type} tuples that have been used during the testcase run.
1521 * @param context the context
1522 * @param txParams spectrum signal parameters set by transmitter
1523 */
1524 void StoreDistinctTuple(std::string context, Ptr<SpectrumSignalParameters> txParams);
1525 /**
1526 * Triggers the arrival of a burst of 1000 Byte-long packets in the source device
1527 * @param numPackets number of packets in burst
1528 * @param sourceDevice pointer to the source NetDevice
1529 * @param destination address of the destination device
1530 */
1531 void SendPacketBurst(uint8_t numPackets,
1532 Ptr<NetDevice> sourceDevice,
1533 Address& destination) const;
1534
1535 MHz_u m_channelWidth; ///< channel width
1536};
1537
1539 : TestCase("Test case for Bug 2843"),
1541{
1542}
1543
1547
1548void
1550{
1551 // Extract starting frequency and number of subbands
1552 Ptr<const SpectrumModel> c = txParams->psd->GetSpectrumModel();
1553 std::size_t numBands = c->GetNumBands();
1554 const Hz_u startingFreq{c->Begin()->fl};
1555
1556 // Get channel bandwidth and modulation class
1559
1560 Ptr<WifiPpdu> ppdu = wifiTxParams->ppdu->Copy();
1561 WifiTxVector txVector = ppdu->GetTxVector();
1562 m_channelWidth = txVector.GetChannelWidth();
1563 WifiModulationClass modulationClass = txVector.GetMode().GetModulationClass();
1564
1565 // Build a tuple and check if seen before (if so store it)
1566 FreqWidthSubbandModulationTuple tupleForCurrentTx =
1567 std::make_tuple(startingFreq, m_channelWidth, numBands, modulationClass);
1568 bool found = false;
1569 for (auto it = m_distinctTuples.begin(); it != m_distinctTuples.end(); it++)
1570 {
1571 if (*it == tupleForCurrentTx)
1572 {
1573 found = true;
1574 }
1575 }
1576 if (!found)
1577 {
1578 m_distinctTuples.push_back(tupleForCurrentTx);
1579 }
1580}
1581
1582void
1584 Ptr<NetDevice> sourceDevice,
1585 Address& destination) const
1586{
1587 for (uint8_t i = 0; i < numPackets; i++)
1588 {
1589 Ptr<Packet> pkt = Create<Packet>(1000); // 1000 dummy bytes of data
1590 sourceDevice->Send(pkt, destination, 0);
1591 }
1592}
1593
1594void
1596{
1597 MHz_u channelWidth{40}; // at least 40 MHz expected here
1598
1599 NodeContainer wifiStaNode;
1600 wifiStaNode.Create(1);
1601
1602 NodeContainer wifiApNode;
1603 wifiApNode.Create(1);
1604
1605 SpectrumWifiPhyHelper spectrumPhy;
1608 lossModel->SetFrequency(5.190e9);
1609 spectrumChannel->AddPropagationLossModel(lossModel);
1610
1613 spectrumChannel->SetPropagationDelayModel(delayModel);
1614
1615 spectrumPhy.SetChannel(spectrumChannel);
1616 spectrumPhy.SetErrorRateModel("ns3::NistErrorRateModel");
1617 spectrumPhy.Set("ChannelSettings", StringValue("{38, 40, BAND_5GHZ, 0}"));
1618 spectrumPhy.Set("TxPowerStart", DoubleValue(10));
1619 spectrumPhy.Set("TxPowerEnd", DoubleValue(10));
1620
1621 WifiHelper wifi;
1622 wifi.SetStandard(WIFI_STANDARD_80211ac);
1623 wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager",
1624 "DataMode",
1625 StringValue("VhtMcs8"),
1626 "ControlMode",
1627 StringValue("VhtMcs8"),
1628 "RtsCtsThreshold",
1629 StringValue("500")); // so as to force RTS/CTS for data frames
1630
1631 WifiMacHelper mac;
1632 mac.SetType("ns3::StaWifiMac");
1633 NetDeviceContainer staDevice;
1634 staDevice = wifi.Install(spectrumPhy, mac, wifiStaNode);
1635
1636 mac.SetType("ns3::ApWifiMac");
1637 NetDeviceContainer apDevice;
1638 apDevice = wifi.Install(spectrumPhy, mac, wifiApNode);
1639
1640 MobilityHelper mobility;
1642 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
1643 positionAlloc->Add(Vector(1.0, 0.0, 0.0)); // put close enough in order to use MCS
1644 mobility.SetPositionAllocator(positionAlloc);
1645
1646 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
1647 mobility.Install(wifiApNode);
1648 mobility.Install(wifiStaNode);
1649
1650 // Send two 5 packet-bursts
1653 this,
1654 5,
1655 apDevice.Get(0),
1656 staDevice.Get(0)->GetAddress());
1659 this,
1660 5,
1661 apDevice.Get(0),
1662 staDevice.Get(0)->GetAddress());
1663
1664 Config::Connect("/ChannelList/*/$ns3::MultiModelSpectrumChannel/TxSigParams",
1666
1669
1671
1672 // {starting frequency, channelWidth, Number of subbands in SpectrumModel, modulation type}
1673 // tuples
1674 std::size_t numberTuples = m_distinctTuples.size();
1675 NS_TEST_ASSERT_MSG_EQ(numberTuples, 3, "Only three distinct tuples expected");
1676 NS_TEST_EXPECT_MSG_EQ(std::get<0>(m_distinctTuples[0]) - Hz_u{20e6},
1677 std::get<0>(m_distinctTuples[1]),
1678 "The starting frequency of the first tuple should be shifted 20 MHz to "
1679 "the right wrt second tuple");
1680 // Note that the first tuple should the one initiated by the beacon, i.e. non-HT OFDM (20 MHz)
1682 MHz_u{20},
1683 "First tuple's channel width should be 20 MHz");
1685 193,
1686 "First tuple should have 193 subbands (64+DC, 20MHz+DC, inband and 64*2 "
1687 "out-of-band, 20MHz on each side)");
1690 "First tuple should be OFDM");
1691 // Second tuple: data frames, VHT (40 MHz)
1693 channelWidth,
1694 "Second tuple's channel width should be 40 MHz");
1696 385,
1697 "Second tuple should have 385 subbands (128+DC, 40MHz+DC, inband and "
1698 "128*2 out-of-band, 40MHz on each side)");
1701 "Second tuple should be VHT_OFDM");
1702 // Third tuple: control response frames, non-HT (OFDM) duplicate (40 MHz)
1704 std::get<0>(m_distinctTuples[2]),
1705 "The starting frequency of the third tuple should be the same as the "
1706 "second tuple");
1708 channelWidth,
1709 "Third tuple's channel width should be 40 MHz");
1711 385,
1712 "Third tuple should have 385 subbands (128+DC, 40MHz+DC, inband and "
1713 "128*2 out-of-band, 40MHz on each side)");
1716 "Third tuple should be OFDM");
1717}
1718
1719//-----------------------------------------------------------------------------
1720/**
1721 * Make sure that the channel width and the channel number can be changed at runtime.
1722 *
1723 * The scenario considers an access point and a station using a 20 MHz channel width.
1724 * After 1s, we change the channel width and the channel number to use a 40 MHz channel.
1725 * The tests checks the operational channel width sent in Beacon frames
1726 * and verify that the association procedure is executed twice.
1727 *
1728 * See \bugid{2831}
1729 */
1730
1732{
1733 public:
1735 ~Bug2831TestCase() override;
1736 void DoRun() override;
1737
1738 private:
1739 /**
1740 * Function called to change the supported channel width at runtime
1741 */
1743 /**
1744 * Callback triggered when a packet is received by the PHYs
1745 * @param context the context
1746 * @param p the received packet
1747 * @param rxPowersW the received power per channel band in watts
1748 */
1749 void RxCallback(std::string context, Ptr<const Packet> p, RxPowerWattPerChannelBand rxPowersW);
1750
1753
1754 uint16_t m_assocReqCount; ///< count number of association requests
1755 uint16_t m_assocRespCount; ///< count number of association responses
1756 uint16_t m_countOperationalChannelWidth20; ///< count number of beacon frames announcing a 20
1757 ///< MHz operating channel width
1758 uint16_t m_countOperationalChannelWidth40; ///< count number of beacon frames announcing a 40
1759 ///< MHz operating channel width
1760};
1761
1770
1774
1775void
1777{
1778 m_apPhy->SetOperatingChannel(WifiPhy::ChannelTuple{38, 40, WIFI_PHY_BAND_5GHZ, 0});
1779 m_staPhy->SetOperatingChannel(WifiPhy::ChannelTuple{38, 40, WIFI_PHY_BAND_5GHZ, 0});
1780}
1781
1782void
1785 RxPowerWattPerChannelBand rxPowersW)
1786{
1787 Ptr<Packet> packet = p->Copy();
1788 WifiMacHeader hdr;
1789 packet->RemoveHeader(hdr);
1790 if (hdr.IsAssocReq())
1791 {
1793 }
1794 else if (hdr.IsAssocResp())
1795 {
1797 }
1798 else if (hdr.IsBeacon())
1799 {
1800 MgtBeaconHeader beacon;
1801 packet->RemoveHeader(beacon);
1802 const auto& htOperation = beacon.Get<HtOperation>();
1803 if (htOperation.has_value() && htOperation->GetStaChannelWidth() > 0)
1804 {
1806 }
1807 else
1808 {
1810 }
1811 }
1812}
1813
1814void
1816{
1818 ObjectFactory propDelay;
1819 propDelay.SetTypeId("ns3::ConstantSpeedPropagationDelayModel");
1820 Ptr<PropagationDelayModel> propagationDelay = propDelay.Create<PropagationDelayModel>();
1822 channel->SetPropagationDelayModel(propagationDelay);
1823 channel->SetPropagationLossModel(propagationLoss);
1824
1825 Ptr<Node> apNode = CreateObject<Node>();
1827 apNode->AddDevice(apDev);
1828 apDev->SetStandard(WIFI_STANDARD_80211ax);
1830 apDev->SetHtConfiguration(apHtConfiguration);
1831 ObjectFactory manager;
1832 manager.SetTypeId("ns3::ConstantRateWifiManager");
1833 apDev->SetRemoteStationManager(manager.Create<WifiRemoteStationManager>());
1834
1836 apMobility->SetPosition(Vector(0.0, 0.0, 0.0));
1837 apNode->AggregateObject(apMobility);
1838
1839 auto error = CreateObject<YansErrorRateModel>();
1841 apDev->SetPhy(m_apPhy);
1843 m_apPhy->SetInterferenceHelper(apInterferenceHelper);
1844 m_apPhy->SetErrorRateModel(error);
1845 m_apPhy->SetChannel(channel);
1846 m_apPhy->SetMobility(apMobility);
1847 m_apPhy->SetDevice(apDev);
1848 m_apPhy->ConfigureStandard(WIFI_STANDARD_80211ax);
1849 m_apPhy->SetOperatingChannel(WifiPhy::ChannelTuple{36, 20, WIFI_PHY_BAND_5GHZ, 0});
1850
1851 ObjectFactory mac;
1852 mac.SetTypeId("ns3::ApWifiMac");
1853 mac.Set("EnableBeaconJitter", BooleanValue(false));
1854 mac.Set("QosSupported", BooleanValue(true));
1855 for (const std::string ac : {"BE", "BK", "VI", "VO"})
1856 {
1857 auto qosTxop =
1858 CreateObjectWithAttributes<QosTxop>("AcIndex", StringValue(std::string("AC_") + ac));
1859 mac.Set(ac + "_Txop", PointerValue(qosTxop));
1860 }
1861 auto apMac = mac.Create<WifiMac>();
1862 apMac->SetDevice(apDev);
1863 apMac->SetAddress(Mac48Address::Allocate());
1864 apDev->SetMac(apMac);
1865 apMac->SetChannelAccessManagers({CreateObject<ChannelAccessManager>()});
1866 apMac->SetFrameExchangeManagers({CreateObject<HeFrameExchangeManager>()});
1867 apMac->SetMacQueueScheduler(CreateObject<FcfsWifiQueueScheduler>());
1868 Ptr<FrameExchangeManager> fem = apMac->GetFrameExchangeManager();
1869 fem->SetAddress(apMac->GetAddress());
1871 protectionManager->SetWifiMac(apMac);
1872 fem->SetProtectionManager(protectionManager);
1874 ackManager->SetWifiMac(apMac);
1875 fem->SetAckManager(ackManager);
1876
1877 Ptr<Node> staNode = CreateObject<Node>();
1879 staNode->AddDevice(staDev);
1880 staDev->SetStandard(WIFI_STANDARD_80211ax);
1882 staDev->SetHtConfiguration(staHtConfiguration);
1883 staDev->SetRemoteStationManager(manager.Create<WifiRemoteStationManager>());
1884
1886 staMobility->SetPosition(Vector(1.0, 0.0, 0.0));
1887 staNode->AggregateObject(staMobility);
1888
1890 staDev->SetPhy(m_staPhy);
1892 m_staPhy->SetInterferenceHelper(staInterferenceHelper);
1893 m_staPhy->SetErrorRateModel(error);
1894 m_staPhy->SetChannel(channel);
1895 m_staPhy->SetMobility(staMobility);
1896 m_staPhy->SetDevice(apDev);
1897 m_staPhy->ConfigureStandard(WIFI_STANDARD_80211ax);
1898 m_staPhy->SetOperatingChannel(WifiPhy::ChannelTuple{36, 20, WIFI_PHY_BAND_5GHZ, 0});
1899
1900 mac.SetTypeId("ns3::StaWifiMac");
1901 for (const std::string ac : {"BE", "BK", "VI", "VO"})
1902 {
1903 auto qosTxop =
1904 CreateObjectWithAttributes<QosTxop>("AcIndex", StringValue(std::string("AC_") + ac));
1905 mac.Set(ac + "_Txop", PointerValue(qosTxop));
1906 }
1907 auto staMac = mac.Create<WifiMac>();
1908 staDev->SetMac(staMac);
1909 staMac->SetDevice(staDev);
1910 staMac->SetAddress(Mac48Address::Allocate());
1911 staMac->SetChannelAccessManagers({CreateObject<ChannelAccessManager>()});
1912 staMac->SetFrameExchangeManagers({CreateObject<HeFrameExchangeManager>()});
1914 staMac->SetMacQueueScheduler(CreateObject<FcfsWifiQueueScheduler>());
1915 fem = staMac->GetFrameExchangeManager();
1916 fem->SetAddress(staMac->GetAddress());
1917 protectionManager = CreateObject<WifiDefaultProtectionManager>();
1918 protectionManager->SetWifiMac(staMac);
1919 fem->SetProtectionManager(protectionManager);
1921 ackManager->SetWifiMac(staMac);
1922 fem->SetAckManager(ackManager);
1923
1924 Config::Connect("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::WifiPhy/PhyRxBegin",
1926
1928
1932
1933 NS_TEST_ASSERT_MSG_EQ(m_assocReqCount, 2, "Second Association request not received");
1934 NS_TEST_ASSERT_MSG_EQ(m_assocRespCount, 2, "Second Association response not received");
1936 10,
1937 "Incorrect operational channel width before channel change");
1939 20,
1940 "Incorrect operational channel width after channel change");
1941}
1942
1943//-----------------------------------------------------------------------------
1944/**
1945 * Make sure that Wifi STA is correctly associating to the best AP (i.e.,
1946 * nearest from STA). We consider 3 AP and 1 STA. This test case consisted of
1947 * three sub tests:
1948 * - The best AP sends its beacon later than the other APs. STA is expected
1949 * to associate to the best AP.
1950 * - The STA is using active scanning instead of passive, the rest of the
1951 * APs works normally. STA is expected to associate to the best AP
1952 * - The nearest AP is turned off after sending beacon and while STA is
1953 * still scanning. STA is expected to associate to the second best AP.
1954 *
1955 * See \bugid{2399}
1956 * @todo Add explicit association refusal test if ns-3 implemented it.
1957 */
1958
1960{
1961 public:
1963 ~StaWifiMacScanningTestCase() override;
1964 void DoRun() override;
1965
1966 private:
1967 /**
1968 * Callback function on STA assoc event
1969 * @param context context string
1970 * @param bssid the associated AP's bssid
1971 */
1972 void AssocCallback(std::string context, Mac48Address bssid);
1973 /**
1974 * Turn beacon generation on the AP node
1975 * @param apNode the AP node
1976 */
1977 void TurnBeaconGenerationOn(Ptr<Node> apNode);
1978 /**
1979 * Turn the AP node off
1980 * @param apNode the AP node
1981 */
1982 void TurnApOff(Ptr<Node> apNode);
1983 /**
1984 * Setup test
1985 * @param nearestApBeaconGeneration set BeaconGeneration attribute of the nearest AP
1986 * @param staActiveProbe set ActiveProbing attribute of the STA
1987 * @return node container containing all nodes
1988 */
1989 NodeContainer Setup(bool nearestApBeaconGeneration, bool staActiveProbe);
1990
1991 Mac48Address m_associatedApBssid; ///< Associated AP's bssid
1992};
1993
1995 : TestCase("Test case for StaWifiMac scanning capability")
1996{
1997}
1998
2002
2003void
2005{
2006 m_associatedApBssid = bssid;
2007}
2008
2009void
2011{
2012 Ptr<WifiNetDevice> netDevice = DynamicCast<WifiNetDevice>(apNode->GetDevice(0));
2013 Ptr<ApWifiMac> mac = DynamicCast<ApWifiMac>(netDevice->GetMac());
2014 mac->SetAttribute("BeaconGeneration", BooleanValue(true));
2015}
2016
2017void
2019{
2020 Ptr<WifiNetDevice> netDevice = DynamicCast<WifiNetDevice>(apNode->GetDevice(0));
2021 Ptr<WifiPhy> phy = netDevice->GetPhy();
2022 phy->SetOffMode();
2023}
2024
2026StaWifiMacScanningTestCase::Setup(bool nearestApBeaconGeneration, bool staActiveProbe)
2027{
2030 int64_t streamNumber = 1;
2031
2032 NodeContainer apNodes;
2033 apNodes.Create(2);
2034
2035 Ptr<Node> apNodeNearest = CreateObject<Node>();
2036 Ptr<Node> staNode = CreateObject<Node>();
2037
2040 phy.SetChannel(channel.Create());
2041
2042 WifiHelper wifi;
2043 wifi.SetStandard(WIFI_STANDARD_80211n);
2044 wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager");
2045
2046 WifiMacHelper mac;
2047 NetDeviceContainer apDevice;
2048 NetDeviceContainer apDeviceNearest;
2049 mac.SetType("ns3::ApWifiMac", "BeaconGeneration", BooleanValue(true));
2050 apDevice = wifi.Install(phy, mac, apNodes);
2051 mac.SetType("ns3::ApWifiMac", "BeaconGeneration", BooleanValue(nearestApBeaconGeneration));
2052 apDeviceNearest = wifi.Install(phy, mac, apNodeNearest);
2053
2054 NetDeviceContainer staDevice;
2055 mac.SetType("ns3::StaWifiMac", "ActiveProbing", BooleanValue(staActiveProbe));
2056 staDevice = wifi.Install(phy, mac, staNode);
2057
2058 // Assign fixed streams to random variables in use
2059 WifiHelper::AssignStreams(apDevice, streamNumber);
2060 WifiHelper::AssignStreams(apDeviceNearest, streamNumber + 1);
2061 WifiHelper::AssignStreams(staDevice, streamNumber + 2);
2062
2063 MobilityHelper mobility;
2065 positionAlloc->Add(Vector(0.0, 0.0, 0.0)); // Furthest AP
2066 positionAlloc->Add(Vector(10.0, 0.0, 0.0)); // Second nearest AP
2067 positionAlloc->Add(Vector(5.0, 5.0, 0.0)); // Nearest AP
2068 positionAlloc->Add(Vector(6.0, 5.0, 0.0)); // STA
2069 mobility.SetPositionAllocator(positionAlloc);
2070
2071 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
2072 mobility.Install(apNodes);
2073 mobility.Install(apNodeNearest);
2074 mobility.Install(staNode);
2075
2076 Config::Connect("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/$ns3::StaWifiMac/Assoc",
2078
2079 NodeContainer allNodes = NodeContainer(apNodes, apNodeNearest, staNode);
2080 return allNodes;
2081}
2082
2083void
2085{
2086 {
2087 NodeContainer nodes = Setup(false, false);
2088 Ptr<Node> nearestAp = nodes.Get(2);
2089 Mac48Address nearestApAddr =
2090 DynamicCast<WifiNetDevice>(nearestAp->GetDevice(0))->GetMac()->GetAddress();
2091
2094 this,
2095 nearestAp);
2096
2100
2102 nearestApAddr,
2103 "STA is associated to the wrong AP");
2104 }
2106 {
2107 NodeContainer nodes = Setup(true, true);
2108 Ptr<Node> nearestAp = nodes.Get(2);
2109 Mac48Address nearestApAddr =
2110 DynamicCast<WifiNetDevice>(nearestAp->GetDevice(0))->GetMac()->GetAddress();
2111
2115
2117 nearestApAddr,
2118 "STA is associated to the wrong AP");
2119 }
2121 {
2122 NodeContainer nodes = Setup(true, false);
2123 Ptr<Node> nearestAp = nodes.Get(2);
2124 Mac48Address secondNearestApAddr =
2125 DynamicCast<WifiNetDevice>(nodes.Get(1)->GetDevice(0))->GetMac()->GetAddress();
2126
2128
2132
2134 secondNearestApAddr,
2135 "STA is associated to the wrong AP");
2136 }
2137}
2138
2139//-----------------------------------------------------------------------------
2140/**
2141 * Make sure that the ADDBA handshake process is protected.
2142 *
2143 * The scenario considers an access point and a station. It utilizes
2144 * ReceiveListErrorModel to drop by force ADDBA request on STA or ADDBA
2145 * response on AP. The AP sends 5 packets of each 1000 bytes (thus generating
2146 * BA agreement), 2 times during the test at 0.5s and 0.8s. We only drop the
2147 * first ADDBA request/response of the first BA negotiation. Therefore, we
2148 * expect that the packets still in queue after the failed BA agreement will be
2149 * sent with normal MPDU, and packets queued after that should be sent with
2150 * A-MPDU.
2151 *
2152 * This test consider 2 cases:
2153 *
2154 * 1. ADDBA request packets are blocked on receive at STA, triggering
2155 * transmission failure at AP
2156 * 2. ADDBA response packets are blocked on receive at AP, STA stops
2157 * retransmission of ADDBA response
2158 *
2159 * See \bugid{2470}
2160 */
2161
2163{
2164 public:
2166 ~Bug2470TestCase() override;
2167 void DoRun() override;
2168
2169 private:
2170 /**
2171 * Callback when ADDBA state changed
2172 * @param context node context
2173 * @param t the time the state changed
2174 * @param recipient the MAC address of the recipient
2175 * @param tid the TID
2176 * @param state the state
2177 */
2178 void AddbaStateChangedCallback(std::string context,
2179 Time t,
2180 Mac48Address recipient,
2181 uint8_t tid,
2183 /**
2184 * Callback when a frame is transmitted.
2185 * @param rxErrorModel the post reception error model on the receiver
2186 * @param context the context
2187 * @param psduMap the PSDU map
2188 * @param txVector the TX vector
2189 * @param txPowerW the tx power in Watts
2190 */
2191 void TxCallback(Ptr<ListErrorModel> rxErrorModel,
2192 std::string context,
2193 WifiConstPsduMap psduMap,
2194 WifiTxVector txVector,
2195 double txPowerW);
2196
2197 /**
2198 * Callback when packet is received
2199 * @param context node context
2200 * @param p the received packet
2201 * @param channelFreqMhz the channel frequency in MHz
2202 * @param txVector the TX vector
2203 * @param aMpdu the A-MPDU info
2204 * @param signalNoise the signal noise in dBm
2205 * @param staId the STA-ID
2206 */
2207 void RxCallback(std::string context,
2209 uint16_t channelFreqMhz,
2210 WifiTxVector txVector,
2211 MpduInfo aMpdu,
2212 SignalNoiseDbm signalNoise,
2213 uint16_t staId);
2214 /**
2215 * Callback when packet is dropped
2216 * @param context node context
2217 * @param p the failed packet
2218 * @param snr the SNR of the failed packet in linear scale
2219 */
2220 void RxErrorCallback(std::string context, Ptr<const Packet> p, double snr);
2221 /**
2222 * Triggers the arrival of a burst of 1000 Byte-long packets in the source device
2223 * @param numPackets number of packets in burst
2224 * @param sourceDevice pointer to the source NetDevice
2225 * @param destination address of the destination device
2226 */
2227 void SendPacketBurst(uint32_t numPackets,
2228 Ptr<NetDevice> sourceDevice,
2229 Address& destination) const;
2230 /**
2231 * Run subtest for this test suite
2232 * @param rcvErrorType type of station (STA or AP) to install the post reception error model on
2233 */
2234 void RunSubtest(TypeOfStation rcvErrorType);
2235
2236 uint16_t m_receivedNormalMpduCount; ///< Count received normal MPDU packets on STA
2237 uint16_t m_receivedAmpduCount; ///< Count received A-MPDU packets on STA
2238 uint16_t m_failedActionCount; ///< Count failed ADDBA request/response
2239 uint16_t m_addbaEstablishedCount; ///< Count number of times ADDBA state machine is in
2240 ///< established state
2241 uint16_t m_addbaPendingCount; ///< Count number of times ADDBA state machine is in pending state
2242 uint16_t
2243 m_addbaRejectedCount; ///< Count number of times ADDBA state machine is in rejected state
2244 uint16_t
2245 m_addbaNoReplyCount; ///< Count number of times ADDBA state machine is in no_reply state
2246 uint16_t m_addbaResetCount; ///< Count number of times ADDBA state machine is in reset state
2247 Time m_2ndPktSetStart; ///< time the second set of packets is generated
2248};
2249
2263
2267
2268void
2270 Time t,
2271 Mac48Address recipient,
2272 uint8_t tid,
2274{
2275 switch (state)
2276 {
2279 break;
2282 break;
2285 break;
2288 break;
2291 break;
2292 }
2293}
2294
2295void
2297 std::string context,
2298 WifiConstPsduMap psduMap,
2299 WifiTxVector txVector,
2300 double txPowerW)
2301{
2302 auto psdu = psduMap.begin()->second;
2303
2304 // The sender is transmitting an ADDBA_REQUEST or ADDBA_RESPONSE frame. If this is
2305 // the first attempt at establishing a BA agreement (i.e., before the second set of packets
2306 // is generated), make the reception of the frame fail at the receiver.
2307 if (psdu->GetHeader(0).GetType() == WIFI_MAC_MGT_ACTION && Simulator::Now() < m_2ndPktSetStart)
2308 {
2309 auto uid = psdu->GetPayload(0)->GetUid();
2310 rxErrorModel->SetList({uid});
2311 }
2312}
2313
2314void
2317 uint16_t channelFreqMhz,
2318 WifiTxVector txVector,
2319 MpduInfo aMpdu,
2320 SignalNoiseDbm signalNoise,
2321 uint16_t staId)
2322{
2323 Ptr<Packet> packet = p->Copy();
2324 if (aMpdu.type != MpduType::NORMAL_MPDU)
2325 {
2327 }
2328 else
2329 {
2330 WifiMacHeader hdr;
2331 packet->RemoveHeader(hdr);
2332 if (hdr.IsData())
2333 {
2335 }
2336 }
2337}
2338
2339void
2340Bug2470TestCase::RxErrorCallback(std::string context, Ptr<const Packet> p, double snr)
2341{
2342 Ptr<Packet> packet = p->Copy();
2343 WifiMacHeader hdr;
2344 packet->RemoveHeader(hdr);
2345 if (hdr.IsAction())
2346 {
2348 }
2349}
2350
2351void
2353 Ptr<NetDevice> sourceDevice,
2354 Address& destination) const
2355{
2356 for (uint32_t i = 0; i < numPackets; i++)
2357 {
2358 Ptr<Packet> pkt = Create<Packet>(1000); // 1000 dummy bytes of data
2359 sourceDevice->Send(pkt, destination, 0);
2360 }
2361}
2362
2363void
2365{
2368 int64_t streamNumber = 200;
2369
2370 NodeContainer wifiApNode;
2371 NodeContainer wifiStaNode;
2372 wifiApNode.Create(1);
2373 wifiStaNode.Create(1);
2374
2377 phy.SetChannel(channel.Create());
2378
2379 WifiHelper wifi;
2380 wifi.SetStandard(WIFI_STANDARD_80211n);
2381 wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager",
2382 "DataMode",
2383 StringValue("HtMcs7"),
2384 "ControlMode",
2385 StringValue("HtMcs7"));
2386
2387 WifiMacHelper mac;
2388 NetDeviceContainer apDevice;
2389 phy.Set("ChannelSettings", StringValue("{36, 20, BAND_5GHZ, 0}"));
2390 mac.SetType("ns3::ApWifiMac", "EnableBeaconJitter", BooleanValue(false));
2391 apDevice = wifi.Install(phy, mac, wifiApNode);
2392
2393 NetDeviceContainer staDevice;
2394 mac.SetType("ns3::StaWifiMac");
2395 staDevice = wifi.Install(phy, mac, wifiStaNode);
2396
2397 // Assign fixed streams to random variables in use
2398 WifiHelper::AssignStreams(apDevice, streamNumber);
2399 WifiHelper::AssignStreams(staDevice, streamNumber);
2400
2401 MobilityHelper mobility;
2403 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
2404 positionAlloc->Add(Vector(1.0, 0.0, 0.0));
2405 mobility.SetPositionAllocator(positionAlloc);
2406
2407 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
2408 mobility.Install(wifiApNode);
2409 mobility.Install(wifiStaNode);
2410
2411 auto rxErrorModel = CreateObject<ListErrorModel>();
2412 Ptr<WifiMac> wifiMac;
2413 switch (rcvErrorType)
2414 {
2415 case AP:
2416 wifiMac = DynamicCast<WifiNetDevice>(apDevice.Get(0))->GetMac();
2417 break;
2418 case STA:
2419 wifiMac = DynamicCast<WifiNetDevice>(staDevice.Get(0))->GetMac();
2420 break;
2421 default:
2422 NS_ABORT_MSG("Station type " << +rcvErrorType << " cannot be used here");
2423 }
2424 wifiMac->GetWifiPhy(0)->SetPostReceptionErrorModel(rxErrorModel);
2425
2427 "/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::WifiPhy/MonitorSnifferRx",
2429 Config::Connect("/NodeList/*/DeviceList/*/Phy/State/RxError",
2431 Config::Connect("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/$ns3::WifiMac/BE_Txop/"
2432 "BlockAckManager/AgreementState",
2434 Config::Connect("/NodeList/" + std::to_string(rcvErrorType == STA ? 0 /* AP */ : 1 /* STA */) +
2435 "/DeviceList/*/$ns3::WifiNetDevice/Phys/0/PhyTxPsduBegin",
2436 MakeCallback(&Bug2470TestCase::TxCallback, this).Bind(rxErrorModel));
2437
2440 this,
2441 1,
2442 apDevice.Get(0),
2443 staDevice.Get(0)->GetAddress());
2446 this,
2447 4,
2448 apDevice.Get(0),
2449 staDevice.Get(0)->GetAddress());
2452 this,
2453 1,
2454 apDevice.Get(0),
2455 staDevice.Get(0)->GetAddress());
2458 this,
2459 4,
2460 apDevice.Get(0),
2461 staDevice.Get(0)->GetAddress());
2462
2466}
2467
2468void
2470{
2471 {
2472 RunSubtest(STA);
2473 NS_TEST_ASSERT_MSG_EQ(m_failedActionCount, 7, "ADDBA request packets are not failed");
2474 // There are two sets of 5 packets to be transmitted. The first 5 packets should be sent by
2475 // normal MPDU because of failed ADDBA handshake. For the second set, the first packet
2476 // should be sent by normal MPDU, and the rest with A-MPDU. In total we expect to receive 6
2477 // normal MPDU packets and 4 A-MPDU packet.
2479 6,
2480 "Receiving incorrect number of normal MPDU packet on subtest 1");
2482 4,
2483 "Receiving incorrect number of A-MPDU packets on subtest 1");
2484
2486 1,
2487 "Incorrect number of times the ADDBA state machine was in "
2488 "established state on subtest 1");
2491 2,
2492 "Incorrect number of times the ADDBA state machine was in pending state on subtest 1");
2495 0,
2496 "Incorrect number of times the ADDBA state machine was in rejected state on subtest 1");
2499 1,
2500 "Incorrect number of times the ADDBA state machine was in no_reply state on subtest 1");
2503 1,
2504 "Incorrect number of times the ADDBA state machine was in reset state on subtest 1");
2505 }
2506
2515
2516 {
2517 RunSubtest(AP);
2518 NS_TEST_ASSERT_MSG_EQ(m_failedActionCount, 7, "ADDBA response packets are not failed");
2519 // Similar to subtest 1, we also expect to receive 6 normal MPDU packets and 4 A-MPDU
2520 // packets.
2522 6,
2523 "Receiving incorrect number of normal MPDU packet on subtest 2");
2525 4,
2526 "Receiving incorrect number of A-MPDU packet on subtest 2");
2527
2529 1,
2530 "Incorrect number of times the ADDBA state machine was in "
2531 "established state on subtest 2");
2534 2,
2535 "Incorrect number of times the ADDBA state machine was in pending state on subtest 2");
2538 0,
2539 "Incorrect number of times the ADDBA state machine was in rejected state on subtest 2");
2542 1,
2543 "Incorrect number of times the ADDBA state machine was in no_reply state on subtest 2");
2546 1,
2547 "Incorrect number of times the ADDBA state machine was in reset state on subtest 2");
2548 }
2549
2550 // TODO: In the second test set, it does not go to reset state since ADDBA response is received
2551 // after timeout (NO_REPLY) but before it does not enter RESET state. More tests should be
2552 // written to verify all possible scenarios.
2553}
2554
2555//-----------------------------------------------------------------------------
2556/**
2557 * Make sure that Ideal rate manager recovers when the station is moving away from the access point.
2558 *
2559 * The scenario considers an access point and a moving station.
2560 * Initially, the station is located at 1 meter from the access point.
2561 * After 1s, the station moves away from the access for 0.5s to
2562 * reach a point away of 50 meters from the access point.
2563 * The tests checks the Ideal rate manager is reset once it has
2564 * failed to transmit a data packet, so that the next data packets
2565 * can be successfully transmitted using a lower modulation.
2566 *
2567 * See \issueid{40}
2568 */
2569
2571{
2572 public:
2574 ~Issue40TestCase() override;
2575 void DoRun() override;
2576
2577 private:
2578 /**
2579 * Run one function
2580 * @param useAmpdu flag to indicate whether the test should be run with A-MPDU
2581 */
2582 void RunOne(bool useAmpdu);
2583
2584 /**
2585 * Callback when packet is successfully received
2586 * @param context node context
2587 * @param p the received packet
2588 */
2589 void RxSuccessCallback(std::string context, Ptr<const Packet> p);
2590 /**
2591 * Triggers the arrival of 1000 Byte-long packets in the source device
2592 * @param numPackets number of packets in burst
2593 * @param sourceDevice pointer to the source NetDevice
2594 * @param destination address of the destination device
2595 */
2596 void SendPackets(uint8_t numPackets, Ptr<NetDevice> sourceDevice, Address& destination);
2597 /**
2598 * Transmit final data failed function
2599 * @param context the context
2600 * @param address the MAC address
2601 */
2602 void TxFinalDataFailedCallback(std::string context, Mac48Address address);
2603
2604 uint16_t m_rxCount; ///< Count number of successfully received data packets
2605 uint16_t m_txCount; ///< Count number of transmitted data packets
2606 uint16_t
2607 m_txMacFinalDataFailedCount; ///< Count number of unsuccessfully transmitted data packets
2608};
2609
2611 : TestCase("Test case for issue #40"),
2612 m_rxCount(0),
2613 m_txCount(0),
2615{
2616}
2617
2621
2622void
2624{
2625 m_rxCount++;
2626}
2627
2628void
2629Issue40TestCase::SendPackets(uint8_t numPackets, Ptr<NetDevice> sourceDevice, Address& destination)
2630{
2631 for (uint8_t i = 0; i < numPackets; i++)
2632 {
2633 Ptr<Packet> pkt = Create<Packet>(1000); // 1000 dummy bytes of data
2634 sourceDevice->Send(pkt, destination, 0);
2635 m_txCount++;
2636 }
2637}
2638
2639void
2644
2645void
2647{
2648 m_rxCount = 0;
2649 m_txCount = 0;
2651
2654 int64_t streamNumber = 100;
2655
2656 NodeContainer wifiApNode;
2657 NodeContainer wifiStaNode;
2658 wifiApNode.Create(1);
2659 wifiStaNode.Create(1);
2660
2663 phy.SetChannel(channel.Create());
2664
2665 WifiHelper wifi;
2666 // use HT standard so that BlockAck agreement is not established in the useAmpdu false case
2667 wifi.SetStandard(useAmpdu ? WIFI_STANDARD_80211ac : WIFI_STANDARD_80211n);
2668 wifi.SetRemoteStationManager("ns3::IdealWifiManager");
2669
2670 WifiMacHelper mac;
2671 NetDeviceContainer apDevice;
2672 mac.SetType("ns3::ApWifiMac");
2673 apDevice = wifi.Install(phy, mac, wifiApNode);
2674
2675 NetDeviceContainer staDevice;
2676 mac.SetType("ns3::StaWifiMac");
2677 staDevice = wifi.Install(phy, mac, wifiStaNode);
2678
2679 // Assign fixed streams to random variables in use
2680 WifiHelper::AssignStreams(apDevice, streamNumber);
2681 WifiHelper::AssignStreams(staDevice, streamNumber);
2682
2683 MobilityHelper mobility;
2685 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
2686 positionAlloc->Add(Vector(10.0, 0.0, 0.0));
2687 mobility.SetPositionAllocator(positionAlloc);
2688
2689 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
2690 mobility.Install(wifiApNode);
2691
2692 mobility.SetMobilityModel("ns3::WaypointMobilityModel");
2693 mobility.Install(wifiStaNode);
2694
2695 Config::Connect("/NodeList/*/DeviceList/*/RemoteStationManager/MacTxFinalDataFailed",
2697 Config::Connect("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/$ns3::WifiMac/MacRx",
2699
2700 Ptr<WaypointMobilityModel> staWaypointMobility =
2702 staWaypointMobility->AddWaypoint(Waypoint(Seconds(1), Vector(10.0, 0.0, 0.0)));
2703 staWaypointMobility->AddWaypoint(Waypoint(Seconds(1.5), Vector(50.0, 0.0, 0.0)));
2704
2705 if (useAmpdu)
2706 {
2707 // Disable use of BAR that are sent with the lowest modulation so that we can also reproduce
2708 // the problem with A-MPDU, i.e. the lack of feedback about SNR change
2709 Ptr<WifiNetDevice> ap_device = DynamicCast<WifiNetDevice>(apDevice.Get(0));
2710 ap_device->GetMac()->GetQosTxop(AC_BE)->SetAttribute("UseExplicitBarAfterMissedBlockAck",
2711 BooleanValue(false));
2712 }
2713
2714 // Transmit a first data packet before the station moves: it should be sent with a high
2715 // modulation and successfully received
2718 this,
2719 useAmpdu ? 2 : 1,
2720 apDevice.Get(0),
2721 staDevice.Get(0)->GetAddress());
2722
2723 // Transmit a second data packet once the station is away from the access point: it should be
2724 // sent with the same high modulation and be unsuccessfully received
2727 this,
2728 useAmpdu ? 2 : 1,
2729 apDevice.Get(0),
2730 staDevice.Get(0)->GetAddress());
2731
2732 // Keep on transmitting data packets while the station is away from the access point: it should
2733 // be sent with a lower modulation and be successfully received
2736 this,
2737 useAmpdu ? 2 : 1,
2738 apDevice.Get(0),
2739 staDevice.Get(0)->GetAddress());
2742 this,
2743 useAmpdu ? 2 : 1,
2744 apDevice.Get(0),
2745 staDevice.Get(0)->GetAddress());
2748 this,
2749 useAmpdu ? 2 : 1,
2750 apDevice.Get(0),
2751 staDevice.Get(0)->GetAddress());
2754 this,
2755 useAmpdu ? 2 : 1,
2756 apDevice.Get(0),
2757 staDevice.Get(0)->GetAddress());
2760 this,
2761 useAmpdu ? 2 : 1,
2762 apDevice.Get(0),
2763 staDevice.Get(0)->GetAddress());
2764
2767
2769 (useAmpdu ? 14 : 7),
2770 "Incorrect number of transmitted packets");
2772 (useAmpdu ? 12 : 6),
2773 "Incorrect number of successfully received packets");
2775 (useAmpdu ? 2 : 1),
2776 "Incorrect number of dropped TX packets");
2777
2779}
2780
2781void
2783{
2784 // Test without A-MPDU
2785 RunOne(false);
2786
2787 // Test with A-MPDU
2788 RunOne(true);
2789}
2790
2791//-----------------------------------------------------------------------------
2792/**
2793 * Make sure that Ideal rate manager is able to handle non best-effort traffic.
2794 *
2795 * The scenario considers an access point and a fixed station.
2796 * The station first sends a best-effort packet to the access point,
2797 * for which Ideal rate manager should select a VHT rate. Then,
2798 * the station sends a non best-effort (voice) packet to the access point,
2799 * and since SNR is unchanged, the same VHT rate should be used.
2800 *
2801 * See \issueid{169}
2802 */
2803
2805{
2806 public:
2808 ~Issue169TestCase() override;
2809 void DoRun() override;
2810
2811 private:
2812 /**
2813 * Triggers the transmission of a 1000 Byte-long data packet from the source device
2814 * @param numPackets number of packets in burst
2815 * @param sourceDevice pointer to the source NetDevice
2816 * @param destination address of the destination device
2817 * @param priority the priority of the packets to send
2818 */
2819 void SendPackets(uint8_t numPackets,
2820 Ptr<NetDevice> sourceDevice,
2821 Address& destination,
2822 uint8_t priority);
2823
2824 /**
2825 * Callback that indicates a PSDU is being transmitted
2826 * @param context the context
2827 * @param psdus the PSDU map to transmit
2828 * @param txVector the TX vector
2829 * @param txPowerW the TX power (W)
2830 */
2831 void TxCallback(std::string context,
2832 WifiConstPsduMap psdus,
2833 WifiTxVector txVector,
2834 double txPowerW);
2835};
2836
2838 : TestCase("Test case for issue #169")
2839{
2840}
2841
2845
2846void
2848 Ptr<NetDevice> sourceDevice,
2849 Address& destination,
2850 uint8_t priority)
2851{
2852 SocketPriorityTag priorityTag;
2853 priorityTag.SetPriority(priority);
2854 for (uint8_t i = 0; i < numPackets; i++)
2855 {
2856 Ptr<Packet> packet = Create<Packet>(1000); // 1000 dummy bytes of data
2857 packet->AddPacketTag(priorityTag);
2858 sourceDevice->Send(packet, destination, 0);
2859 }
2860}
2861
2862void
2864 WifiConstPsduMap psdus,
2865 WifiTxVector txVector,
2866 double txPowerW)
2867{
2868 if (psdus.begin()->second->GetSize() >= 1000)
2869 {
2872 "Ideal rate manager selected incorrect modulation class");
2873 }
2874}
2875
2876void
2878{
2881 int64_t streamNumber = 100;
2882
2883 NodeContainer wifiApNode;
2884 NodeContainer wifiStaNode;
2885 wifiApNode.Create(1);
2886 wifiStaNode.Create(1);
2887
2890 phy.SetChannel(channel.Create());
2891
2892 WifiHelper wifi;
2893 wifi.SetStandard(WIFI_STANDARD_80211ac);
2894 wifi.SetRemoteStationManager("ns3::IdealWifiManager");
2895
2896 WifiMacHelper mac;
2897 NetDeviceContainer apDevice;
2898 mac.SetType("ns3::ApWifiMac");
2899 apDevice = wifi.Install(phy, mac, wifiApNode);
2900
2901 NetDeviceContainer staDevice;
2902 mac.SetType("ns3::StaWifiMac");
2903 staDevice = wifi.Install(phy, mac, wifiStaNode);
2904
2905 // Assign fixed streams to random variables in use
2906 WifiHelper::AssignStreams(apDevice, streamNumber);
2907 WifiHelper::AssignStreams(staDevice, streamNumber);
2908
2909 MobilityHelper mobility;
2911 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
2912 positionAlloc->Add(Vector(1.0, 0.0, 0.0));
2913 mobility.SetPositionAllocator(positionAlloc);
2914
2915 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
2916 mobility.Install(wifiApNode);
2917 mobility.Install(wifiStaNode);
2918
2919 Config::Connect("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::WifiPhy/PhyTxPsduBegin",
2921
2922 // Send best-effort packet (i.e. priority 0)
2925 this,
2926 1,
2927 apDevice.Get(0),
2928 staDevice.Get(0)->GetAddress(),
2929 0);
2930
2931 // Send non best-effort (voice) packet (i.e. priority 6)
2934 this,
2935 1,
2936 apDevice.Get(0),
2937 staDevice.Get(0)->GetAddress(),
2938 6);
2939
2942
2944}
2945
2946//-----------------------------------------------------------------------------
2947/**
2948 * Make sure that Ideal rate manager properly selects MCS based on the configured channel width.
2949 *
2950 * The scenario considers an access point and a fixed station.
2951 * The access point first sends a 80 MHz PPDU to the station,
2952 * for which Ideal rate manager should select VH-MCS 0 based
2953 * on the distance (no interference generated in this test). Then,
2954 * the access point sends a 20 MHz PPDU to the station,
2955 * which corresponds to a SNR 6 dB higher than previously, hence
2956 * VHT-MCS 2 should be selected. Finally, the access point sends a
2957 * 40 MHz PPDU to the station, which means corresponds to a SNR 3 dB
2958 * lower than previously, hence VHT-MCS 1 should be selected.
2959 */
2960
2962{
2963 public:
2966 void DoRun() override;
2967
2968 private:
2969 /**
2970 * Change the configured channel width for all nodes
2971 * @param channelWidth the channel width
2972 */
2973 void ChangeChannelWidth(MHz_u channelWidth);
2974
2975 /**
2976 * Triggers the transmission of a 1000 Byte-long data packet from the source device
2977 * @param sourceDevice pointer to the source NetDevice
2978 * @param destination address of the destination device
2979 */
2980 void SendPacket(Ptr<NetDevice> sourceDevice, Address& destination);
2981
2982 /**
2983 * Callback that indicates a PSDU is being transmitted
2984 * @param context the context
2985 * @param psduMap the PSDU map to transmit
2986 * @param txVector the TX vector
2987 * @param txPowerW the TX power (W)
2988 */
2989 void TxCallback(std::string context,
2990 WifiConstPsduMap psduMap,
2991 WifiTxVector txVector,
2992 double txPowerW);
2993
2994 /**
2995 * Check if the selected WifiMode is correct
2996 * @param expectedMode the expected WifiMode
2997 */
2998 void CheckLastSelectedMode(WifiMode expectedMode);
2999
3000 WifiMode m_txMode; ///< Store the last selected mode to send data packet
3001};
3002
3004 : TestCase("Test case for use of channel bonding with Ideal rate manager")
3005{
3006}
3007
3011
3012void
3014{
3015 Config::Set("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/ChannelSettings",
3016 StringValue("{0, " + std::to_string(static_cast<uint16_t>(channelWidth)) +
3017 ", BAND_5GHZ, 0}"));
3018}
3019
3020void
3022{
3023 Ptr<Packet> packet = Create<Packet>(1000);
3024 sourceDevice->Send(packet, destination, 0);
3025}
3026
3027void
3029 WifiConstPsduMap psduMap,
3030 WifiTxVector txVector,
3031 double txPowerW)
3032{
3033 if (psduMap.begin()->second->GetSize() >= 1000)
3034 {
3035 m_txMode = txVector.GetMode();
3036 }
3037}
3038
3039void
3041{
3043 expectedMode,
3044 "Last selected WifiMode "
3045 << m_txMode << " does not match expected WifiMode " << expectedMode);
3046}
3047
3048void
3050{
3053 int64_t streamNumber = 100;
3054
3055 NodeContainer wifiApNode;
3056 NodeContainer wifiStaNode;
3057 wifiApNode.Create(1);
3058 wifiStaNode.Create(1);
3059
3062 phy.SetChannel(channel.Create());
3063
3064 WifiHelper wifi;
3065 wifi.SetStandard(WIFI_STANDARD_80211ac);
3066 wifi.SetRemoteStationManager("ns3::IdealWifiManager");
3067
3068 WifiMacHelper mac;
3069 NetDeviceContainer apDevice;
3070 mac.SetType("ns3::ApWifiMac");
3071 apDevice = wifi.Install(phy, mac, wifiApNode);
3072
3073 NetDeviceContainer staDevice;
3074 mac.SetType("ns3::StaWifiMac");
3075 staDevice = wifi.Install(phy, mac, wifiStaNode);
3076
3077 // Assign fixed streams to random variables in use
3078 WifiHelper::AssignStreams(apDevice, streamNumber);
3079 WifiHelper::AssignStreams(staDevice, streamNumber);
3080
3081 MobilityHelper mobility;
3083 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
3084 positionAlloc->Add(Vector(50.0, 0.0, 0.0));
3085 mobility.SetPositionAllocator(positionAlloc);
3086
3087 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
3088 mobility.Install(wifiApNode);
3089 mobility.Install(wifiStaNode);
3090
3091 Config::Connect("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::WifiPhy/PhyTxPsduBegin",
3093
3094 // Set channel width to 80 MHz & send packet
3097 this,
3098 MHz_u{80});
3101 this,
3102 apDevice.Get(0),
3103 staDevice.Get(0)->GetAddress());
3104 // Selected rate should be VHT-MCS 1
3107 this,
3109
3110 // Set channel width to 20 MHz & send packet
3113 this,
3114 MHz_u{20});
3117 this,
3118 apDevice.Get(0),
3119 staDevice.Get(0)->GetAddress());
3120 // Selected rate should be VHT-MCS 3 since SNR should be 6 dB higher than previously
3123 this,
3125
3126 // Set channel width to 40 MHz & send packet
3129 this,
3130 MHz_u{40});
3133 this,
3134 apDevice.Get(0),
3135 staDevice.Get(0)->GetAddress());
3136 // Selected rate should be VHT-MCS 2 since SNR should be 3 dB lower than previously
3139 this,
3141
3144
3146}
3147
3148//-----------------------------------------------------------------------------
3149/**
3150 * Test to validate that Ideal rate manager properly selects TXVECTOR in scenarios where MIMO is
3151 * used. The test consider both balanced and unbalanced MIMO settings, and verify ideal picks the
3152 * correct number of spatial streams and the correct MCS, taking into account potential diversity in
3153 * AWGN channels when the number of antenna at the receiver is higher than the number of spatial
3154 * streams used for the transmission.
3155 */
3156
3158{
3159 public:
3161 ~IdealRateManagerMimoTest() override;
3162 void DoRun() override;
3163
3164 private:
3165 /**
3166 * Change the configured MIMO settings for AP node
3167 * @param antennas the number of active antennas
3168 * @param maxStreams the maximum number of allowed spatial streams
3169 */
3170 void SetApMimoSettings(uint8_t antennas, uint8_t maxStreams);
3171 /**
3172 * Change the configured MIMO settings for STA node
3173 * @param antennas the number of active antennas
3174 * @param maxStreams the maximum number of allowed spatial streams
3175 */
3176 void SetStaMimoSettings(uint8_t antennas, uint8_t maxStreams);
3177 /**
3178 * Triggers the transmission of a 1000 Byte-long data packet from the source device
3179 * @param sourceDevice pointer to the source NetDevice
3180 * @param destination address of the destination device
3181 */
3182 void SendPacket(Ptr<NetDevice> sourceDevice, Address& destination);
3183
3184 /**
3185 * Callback that indicates a PSDU is being transmitted
3186 * @param context the context
3187 * @param psdus the PSDU map to transmit
3188 * @param txVector the TX vector
3189 * @param txPowerW the TX power (W)
3190 */
3191 void TxCallback(std::string context,
3192 WifiConstPsduMap psdus,
3193 WifiTxVector txVector,
3194 double txPowerW);
3195
3196 /**
3197 * Check if the selected WifiMode is correct
3198 * @param expectedMode the expected WifiMode
3199 */
3200 void CheckLastSelectedMode(WifiMode expectedMode);
3201 /**
3202 * Check if the selected Nss is correct
3203 * @param expectedNss the expected Nss
3204 */
3205 void CheckLastSelectedNss(uint8_t expectedNss);
3206
3207 WifiTxVector m_txVector; ///< Store the last TXVECTOR used to transmit Data
3208};
3209
3211 : TestCase("Test case for use of imbalanced MIMO settings with Ideal rate manager")
3212{
3213}
3214
3218
3219void
3220IdealRateManagerMimoTest::SetApMimoSettings(uint8_t antennas, uint8_t maxStreams)
3221{
3222 Config::Set("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/Antennas",
3223 UintegerValue(antennas));
3224 Config::Set("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/MaxSupportedTxSpatialStreams",
3225 UintegerValue(maxStreams));
3226 Config::Set("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/MaxSupportedRxSpatialStreams",
3227 UintegerValue(maxStreams));
3228}
3229
3230void
3231IdealRateManagerMimoTest::SetStaMimoSettings(uint8_t antennas, uint8_t maxStreams)
3232{
3233 Config::Set("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/Antennas",
3234 UintegerValue(antennas));
3235 Config::Set("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/MaxSupportedTxSpatialStreams",
3236 UintegerValue(maxStreams));
3237 Config::Set("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/MaxSupportedRxSpatialStreams",
3238 UintegerValue(maxStreams));
3239}
3240
3241void
3243{
3244 Ptr<Packet> packet = Create<Packet>(1000);
3245 sourceDevice->Send(packet, destination, 0);
3246}
3247
3248void
3250 WifiConstPsduMap psdus,
3251 WifiTxVector txVector,
3252 double txPowerW)
3253{
3254 if (psdus.begin()->second->GetSize() >= 1000)
3255 {
3256 m_txVector = txVector;
3257 }
3258}
3259
3260void
3262{
3264 expectedNss,
3265 "Last selected Nss " << m_txVector.GetNss()
3266 << " does not match expected Nss " << expectedNss);
3267}
3268
3269void
3271{
3273 expectedMode,
3274 "Last selected WifiMode " << m_txVector.GetMode()
3275 << " does not match expected WifiMode "
3276 << expectedMode);
3277}
3278
3279void
3281{
3284 int64_t streamNumber = 100;
3285
3286 NodeContainer wifiApNode;
3287 NodeContainer wifiStaNode;
3288 wifiApNode.Create(1);
3289 wifiStaNode.Create(1);
3290
3293 phy.SetChannel(channel.Create());
3294
3295 WifiHelper wifi;
3296 wifi.SetStandard(WIFI_STANDARD_80211ac);
3297 wifi.SetRemoteStationManager("ns3::IdealWifiManager");
3298
3299 WifiMacHelper mac;
3300 NetDeviceContainer apDevice;
3301 mac.SetType("ns3::ApWifiMac");
3302 apDevice = wifi.Install(phy, mac, wifiApNode);
3303
3304 NetDeviceContainer staDevice;
3305 mac.SetType("ns3::StaWifiMac");
3306 staDevice = wifi.Install(phy, mac, wifiStaNode);
3307
3308 // Assign fixed streams to random variables in use
3309 WifiHelper::AssignStreams(apDevice, streamNumber);
3310 WifiHelper::AssignStreams(staDevice, streamNumber);
3311
3312 MobilityHelper mobility;
3314 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
3315 positionAlloc->Add(Vector(40.0, 0.0, 0.0));
3316 mobility.SetPositionAllocator(positionAlloc);
3317
3318 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
3319 mobility.Install(wifiApNode);
3320 mobility.Install(wifiStaNode);
3321
3322 Config::Connect("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::WifiPhy/PhyTxPsduBegin",
3324
3325 // TX: 1 antenna
3327 // RX: 1 antenna
3329 // Send packets (2 times to get one feedback)
3332 this,
3333 apDevice.Get(0),
3334 staDevice.Get(0)->GetAddress());
3337 this,
3338 apDevice.Get(0),
3339 staDevice.Get(0)->GetAddress());
3340 // Selected NSS should be 1 since both TX and RX support a single antenna
3342 // Selected rate should be VHT-MCS 2 because of settings and distance between TX and RX
3345 this,
3347
3348 // TX: 1 antenna
3350 // RX: 2 antennas, but only supports 1 spatial stream
3352 // Send packets (2 times to get one feedback)
3355 this,
3356 apDevice.Get(0),
3357 staDevice.Get(0)->GetAddress());
3360 this,
3361 apDevice.Get(0),
3362 staDevice.Get(0)->GetAddress());
3363 // Selected NSS should be 1 since both TX and RX support a single antenna
3365 // Selected rate should be increased to VHT-MCS 3 because of RX diversity resulting in SNR
3366 // improvement of about 3dB
3369 this,
3371
3372 // TX: 1 antenna
3374 // RX: 2 antennas, and supports 2 spatial streams
3376 // Send packets (2 times to get one feedback)
3379 this,
3380 apDevice.Get(0),
3381 staDevice.Get(0)->GetAddress());
3384 this,
3385 apDevice.Get(0),
3386 staDevice.Get(0)->GetAddress());
3387 // Selected NSS should be 1 since TX supports a single antenna
3389 // Selected rate should be as previously
3392 this,
3394
3395 // TX: 2 antennas, but only supports 1 spatial stream
3397 // RX: 1 antenna
3399 // Send packets (2 times to get one feedback)
3402 this,
3403 apDevice.Get(0),
3404 staDevice.Get(0)->GetAddress());
3407 this,
3408 apDevice.Get(0),
3409 staDevice.Get(0)->GetAddress());
3410 // Selected NSS should be 1 since both TX and RX support a single antenna
3412 // Selected rate should be VHT-MCS 2 because we do no longer have diversity in this scenario
3413 // (more antennas at TX does not result in SNR improvement in AWGN channel)
3416 this,
3418
3419 // TX: 2 antennas, but only supports 1 spatial stream
3421 // RX: 2 antennas, but only supports 1 spatial stream
3423 // Send packets (2 times to get one feedback)
3426 this,
3427 apDevice.Get(0),
3428 staDevice.Get(0)->GetAddress());
3431 this,
3432 apDevice.Get(0),
3433 staDevice.Get(0)->GetAddress());
3434 // Selected NSS should be 1 since both TX and RX support a single antenna
3436 // Selected rate should be increased to VHT-MCS 3 because of RX diversity resulting in SNR
3437 // improvement of about 3dB (more antennas at TX does not result in SNR improvement in AWGN
3438 // channel)
3441 this,
3443
3444 // TX: 2 antennas, but only supports 1 spatial stream
3446 // RX: 2 antennas, and supports 2 spatial streams
3448 // Send packets (2 times to get one feedback)
3451 this,
3452 apDevice.Get(0),
3453 staDevice.Get(0)->GetAddress());
3456 this,
3457 apDevice.Get(0),
3458 staDevice.Get(0)->GetAddress());
3459 // Selected NSS should be 1 since TX supports a single antenna
3461 // Selected rate should be as previously
3464 this,
3466
3467 // TX: 2 antennas, and supports 2 spatial streams
3469 // RX: 1 antenna
3471 // Send packets (2 times to get one feedback)
3474 this,
3475 apDevice.Get(0),
3476 staDevice.Get(0)->GetAddress());
3479 this,
3480 apDevice.Get(0),
3481 staDevice.Get(0)->GetAddress());
3482 // Selected NSS should be 1 since RX supports a single antenna
3484 // Selected rate should be VHT-MCS 2 because we do no longer have diversity in this scenario
3485 // (more antennas at TX does not result in SNR improvement in AWGN channel)
3488 this,
3490
3491 // TX: 2 antennas, and supports 2 spatial streams
3493 // RX: 2 antennas, but only supports 1 spatial stream
3495 // Send packets (2 times to get one feedback)
3498 this,
3499 apDevice.Get(0),
3500 staDevice.Get(0)->GetAddress());
3503 this,
3504 apDevice.Get(0),
3505 staDevice.Get(0)->GetAddress());
3506 // Selected NSS should be 1 since RX supports a single antenna
3508 // Selected rate should be increased to VHT-MCS 3 because of RX diversity resulting in SNR
3509 // improvement of about 3dB (more antennas at TX does not result in SNR improvement in AWGN
3510 // channel)
3513 this,
3515
3516 // TX: 2 antennas, and supports 2 spatial streams
3518 // RX: 2 antennas, and supports 2 spatial streams
3520 // Send packets (2 times to get one feedback)
3523 this,
3524 apDevice.Get(0),
3525 staDevice.Get(0)->GetAddress());
3528 this,
3529 apDevice.Get(0),
3530 staDevice.Get(0)->GetAddress());
3531 // Selected NSS should be 2 since both TX and RX support 2 antennas
3533 // Selected rate should be the same as without diversity, as it uses 2 spatial streams so there
3534 // is no more benefits from diversity in AWGN channels
3537 this,
3539
3540 // Verify we can go back to initial situation
3545 this,
3546 apDevice.Get(0),
3547 staDevice.Get(0)->GetAddress());
3551 this,
3553
3554 Simulator::Stop(Seconds(10.2));
3557}
3558
3559//-----------------------------------------------------------------------------
3560/**
3561 * @ingroup wifi-test
3562 * @ingroup tests
3563 *
3564 * @brief Data rate verification test for MCSs of different RU sizes
3565 */
3567{
3568 public:
3570
3571 private:
3572 /**
3573 * Compare the data rate computed for the provided combination with standard defined one.
3574 * @param ruType the RU type
3575 * @param mcs the modulation and coding scheme (as a string, e.g. HeMcs0)
3576 * @param nss the number of spatial streams
3577 * @param guardInterval the guard interval to use
3578 * @param expectedDataRate the expected data rate in 100 kbps units (minimum granularity in
3579 * standard tables)
3580 * @returns true if data rates are the same, false otherwise
3581 */
3582 bool CheckDataRate(RuType ruType,
3583 std::string mcs,
3584 uint8_t nss,
3585 Time guardInterval,
3586 uint16_t expectedDataRate);
3587 void DoRun() override;
3588};
3589
3591 : TestCase("Check data rates for different RU types.")
3592{
3593}
3594
3595bool
3597 std::string mcs,
3598 uint8_t nss,
3599 Time guardInterval,
3600 uint16_t expectedDataRate)
3601{
3602 uint8_t staId = 1;
3603 auto txVector = WifiTxVector(HePhy::GetHeMcs(0),
3606 guardInterval,
3607 1,
3608 1,
3609 0,
3610 MHz_u{160},
3611 false,
3612 false);
3613 WifiMode mode(mcs);
3614 txVector.SetMode(mode, staId);
3615 txVector.SetNss(nss, staId);
3616 HeRu::RuSpec ru(ruType, 1, true);
3617 txVector.SetRu(ru, staId);
3618 uint64_t dataRate = round(mode.GetDataRate(txVector, staId) / 100000.0);
3619 NS_ABORT_MSG_IF(dataRate > 65535, "Rate is way too high");
3620 if (static_cast<uint16_t>(dataRate) != expectedDataRate)
3621 {
3622 std::cerr << "RU=" << ruType << " mode=" << mode << " Nss=" << +nss
3623 << " guardInterval=" << guardInterval << " expected=" << expectedDataRate
3624 << " x100kbps"
3625 << " computed=" << static_cast<uint16_t>(dataRate) << " x100kbps" << std::endl;
3626 return false;
3627 }
3628 return true;
3629}
3630
3631void
3633{
3634 bool retval = true;
3635
3636 // 26-tone RU, browse over all MCSs, GIs and Nss's (up to 4, current max)
3637 retval = retval && CheckDataRate(RuType::RU_26_TONE, "HeMcs0", 1, NanoSeconds(800), 9) &&
3638 CheckDataRate(RuType::RU_26_TONE, "HeMcs1", 1, NanoSeconds(1600), 17) &&
3639 CheckDataRate(RuType::RU_26_TONE, "HeMcs2", 1, NanoSeconds(3200), 23) &&
3640 CheckDataRate(RuType::RU_26_TONE, "HeMcs3", 1, NanoSeconds(3200), 30) &&
3641 CheckDataRate(RuType::RU_26_TONE, "HeMcs4", 2, NanoSeconds(1600), 100) &&
3642 CheckDataRate(RuType::RU_26_TONE, "HeMcs5", 3, NanoSeconds(1600), 200) &&
3643 CheckDataRate(RuType::RU_26_TONE, "HeMcs6", 4, NanoSeconds(1600), 300) &&
3644 CheckDataRate(RuType::RU_26_TONE, "HeMcs7", 4, NanoSeconds(3200), 300) &&
3645 CheckDataRate(RuType::RU_26_TONE, "HeMcs8", 4, NanoSeconds(1600), 400) &&
3646 CheckDataRate(RuType::RU_26_TONE, "HeMcs9", 4, NanoSeconds(3200), 400) &&
3647 CheckDataRate(RuType::RU_26_TONE, "HeMcs10", 4, NanoSeconds(1600), 500) &&
3648 CheckDataRate(RuType::RU_26_TONE, "HeMcs11", 4, NanoSeconds(3200), 500);
3649
3651 retval,
3652 true,
3653 "26-tone RU data rate verification for different MCSs, GIs, and Nss's failed");
3654
3655 // Check other RU sizes
3656 retval = retval && CheckDataRate(RuType::RU_52_TONE, "HeMcs2", 1, NanoSeconds(1600), 50) &&
3657 CheckDataRate(RuType::RU_106_TONE, "HeMcs9", 1, NanoSeconds(800), 500) &&
3658 CheckDataRate(RuType::RU_242_TONE, "HeMcs5", 1, NanoSeconds(1600), 650) &&
3659 CheckDataRate(RuType::RU_484_TONE, "HeMcs3", 1, NanoSeconds(1600), 650) &&
3660 CheckDataRate(RuType::RU_996_TONE, "HeMcs5", 1, NanoSeconds(3200), 2450) &&
3661 CheckDataRate(RuType::RU_2x996_TONE, "HeMcs3", 1, NanoSeconds(3200), 2450);
3662
3663 NS_TEST_EXPECT_MSG_EQ(retval,
3664 true,
3665 "Data rate verification for RUs above 52-tone RU (included) failed");
3666}
3667
3668/// List of Information Elements included in the test management frame
3670 std::tuple<SupportedRates, std::optional<ExtendedSupportedRatesIE>, std::vector<Ssid>>;
3671
3672/**
3673 * @ingroup wifi-test
3674 * @ingroup tests
3675 *
3676 * @brief Test management header
3677 */
3678class MgtTestHeader : public WifiMgtHeader<MgtTestHeader, MgtTestElems>
3679{
3680 public:
3681 ~MgtTestHeader() override = default;
3682
3683 /**
3684 * Register this type.
3685 * @return The TypeId.
3686 */
3687 static TypeId GetTypeId();
3688
3689 /**
3690 * @return the TypeId for this object.
3691 */
3692 TypeId GetInstanceTypeId() const override;
3693
3694 using WifiMgtHeader<MgtTestHeader, MgtTestElems>::GetSerializedSize;
3695 using WifiMgtHeader<MgtTestHeader, MgtTestElems>::Serialize;
3696 using WifiMgtHeader<MgtTestHeader, MgtTestElems>::Deserialize;
3697};
3698
3699TypeId
3701{
3702 static TypeId tid = TypeId("ns3::MgtTestHeader")
3703 .SetParent<Header>()
3704 .SetGroupName("Wifi")
3705 .AddConstructor<MgtTestHeader>();
3706 return tid;
3707}
3708
3709TypeId
3711{
3712 return GetTypeId();
3713}
3714
3715/**
3716 * @ingroup wifi-test
3717 * @ingroup tests
3718 *
3719 * @brief Mgt header (de)serialization Test Suite
3720 */
3722{
3723 public:
3725 ~WifiMgtHeaderTest() override = default;
3726
3727 private:
3728 void DoRun() override;
3729};
3730
3732 : HeaderSerializationTestCase("Check (de)serialization of a test management header")
3733{
3734}
3735
3736void
3738{
3739 MgtTestHeader frame;
3740
3741 // Add the mandatory Information Element (SupportedRates)
3742 AllSupportedRates allRates;
3743 allRates.AddSupportedRate(1000000);
3744 allRates.AddSupportedRate(2000000);
3745 allRates.AddSupportedRate(3000000);
3746 allRates.AddSupportedRate(4000000);
3747 allRates.AddSupportedRate(5000000);
3748
3749 frame.Get<SupportedRates>() = allRates.rates;
3750 frame.Get<ExtendedSupportedRatesIE>() = allRates.extendedRates;
3751
3752 NS_TEST_EXPECT_MSG_EQ(frame.Get<SupportedRates>().has_value(),
3753 true,
3754 "Expected a SupportedRates IE to be included");
3755 NS_TEST_EXPECT_MSG_EQ(frame.Get<ExtendedSupportedRatesIE>().has_value(),
3756 false,
3757 "Expected no ExtendedSupportedRatesIE to be included");
3758 NS_TEST_EXPECT_MSG_EQ(frame.Get<Ssid>().size(), 0, "Expected no Ssid IE to be included");
3759
3761
3762 // Add more rates, so that the optional Information Element (ExtendedSupportedRatesIE) is added
3763 allRates.AddSupportedRate(6000000);
3764 allRates.AddSupportedRate(7000000);
3765 allRates.AddSupportedRate(8000000);
3766 allRates.AddSupportedRate(9000000);
3767 allRates.AddSupportedRate(10000000);
3768
3769 frame.Get<SupportedRates>() = allRates.rates;
3770 frame.Get<ExtendedSupportedRatesIE>() = allRates.extendedRates;
3771
3772 NS_TEST_EXPECT_MSG_EQ(frame.Get<SupportedRates>().has_value(),
3773 true,
3774 "Expected a SupportedRates IE to be included");
3775 NS_TEST_EXPECT_MSG_EQ(frame.Get<ExtendedSupportedRatesIE>().has_value(),
3776 true,
3777 "Expected an ExtendedSupportedRatesIE to be included");
3778 NS_TEST_EXPECT_MSG_EQ(frame.Get<Ssid>().size(), 0, "Expected no Ssid IE to be included");
3779
3781
3782 // Add a first Ssid IE
3783 Ssid one("Ssid One");
3784 frame.Get<Ssid>().push_back(one);
3785
3786 NS_TEST_EXPECT_MSG_EQ(frame.Get<SupportedRates>().has_value(),
3787 true,
3788 "Expected a SupportedRates IE to be included");
3789 NS_TEST_EXPECT_MSG_EQ(frame.Get<ExtendedSupportedRatesIE>().has_value(),
3790 true,
3791 "Expected an ExtendedSupportedRatesIE to be included");
3792 NS_TEST_EXPECT_MSG_EQ(frame.Get<Ssid>().size(), 1, "Expected one Ssid IE to be included");
3793 NS_TEST_EXPECT_MSG_EQ(std::string(frame.Get<Ssid>().front().PeekString()),
3794 "Ssid One",
3795 "Incorrect SSID");
3796
3798
3799 // Add a second Ssid IE
3800 frame.Get<Ssid>().emplace_back("Ssid Two");
3801
3802 NS_TEST_EXPECT_MSG_EQ(frame.Get<SupportedRates>().has_value(),
3803 true,
3804 "Expected a SupportedRates IE to be included");
3805 NS_TEST_EXPECT_MSG_EQ(frame.Get<ExtendedSupportedRatesIE>().has_value(),
3806 true,
3807 "Expected an ExtendedSupportedRatesIE to be included");
3808 NS_TEST_EXPECT_MSG_EQ(frame.Get<Ssid>().size(), 2, "Expected two Ssid IEs to be included");
3809 NS_TEST_EXPECT_MSG_EQ(std::string(frame.Get<Ssid>().front().PeekString()),
3810 "Ssid One",
3811 "Incorrect first SSID");
3812 NS_TEST_EXPECT_MSG_EQ(std::string(frame.Get<Ssid>().back().PeekString()),
3813 "Ssid Two",
3814 "Incorrect second SSID");
3815
3817}
3818
3819//-----------------------------------------------------------------------------
3820
3821/**
3822 * Make sure that all DSSS modulation types work (see issue #1095).
3823 *
3824 * This test sends four packets from a STA to an AP, each with a different
3825 * DSSS rate (1, 2, 5.5, and 11Mbps), and checks that all four are received.
3826 */
3828{
3829 public:
3831
3832 void DoRun() override;
3833
3834 private:
3835 uint32_t m_received; ///< number of received packets
3836
3837 /**
3838 * Trace sink to receive from the PacketSocket; the address parameter is unused
3839 * @param context the context
3840 * @param p the received packet
3841 */
3842 void Receive(std::string context, Ptr<const Packet> p, const Address&);
3843};
3844
3846 : TestCase("Test case for Bug 730"),
3847 m_received(0)
3848{
3849}
3850
3851void
3853{
3854 m_received++;
3855}
3856
3857void
3859{
3860 m_received = 0;
3861
3862 NodeContainer wifiStaNode;
3863 wifiStaNode.Create(1);
3864
3865 NodeContainer wifiApNode;
3866 wifiApNode.Create(1);
3867
3868 auto channel = YansWifiChannelHelper::Default();
3870 phy.SetChannel(channel.Create());
3871
3872 WifiHelper wifi;
3873 wifi.SetStandard(WIFI_STANDARD_80211b);
3874 wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager",
3875 "DataMode",
3876 StringValue("DsssRate1Mbps"),
3877 "ControlMode",
3878 StringValue("DsssRate1Mbps"));
3879
3880 WifiMacHelper mac;
3881 auto ssid = Ssid("ns-3-ssid");
3882 mac.SetType("ns3::StaWifiMac", "Ssid", SsidValue(ssid), "ActiveProbing", BooleanValue(false));
3883
3884 NetDeviceContainer staDevices;
3885 staDevices = wifi.Install(phy, mac, wifiStaNode);
3886
3887 mac.SetType("ns3::ApWifiMac", "Ssid", SsidValue(ssid), "BeaconGeneration", BooleanValue(true));
3888
3889 NetDeviceContainer apDevices;
3890 apDevices = wifi.Install(phy, mac, wifiApNode);
3891 auto apRemoteStationManager = apDevices.Get(0)
3892 ->GetObject<WifiNetDevice>()
3893 ->GetRemoteStationManager()
3895 apRemoteStationManager->SetAttribute("DataMode", StringValue("DsssRate1Mbps"));
3896
3897 MobilityHelper mobility;
3898 auto positionAlloc = CreateObject<ListPositionAllocator>();
3899
3900 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
3901 positionAlloc->Add(Vector(1.0, 0.0, 0.0));
3902 mobility.SetPositionAllocator(positionAlloc);
3903
3904 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
3905 mobility.Install(wifiApNode);
3906 mobility.Install(wifiStaNode);
3907
3908 auto apDevice = DynamicCast<WifiNetDevice>(apDevices.Get(0));
3909 auto staDevice = DynamicCast<WifiNetDevice>(staDevices.Get(0));
3910
3911 PacketSocketAddress socket;
3912 socket.SetSingleDevice(staDevice->GetIfIndex());
3913 socket.SetPhysicalAddress(apDevice->GetAddress());
3914 socket.SetProtocol(1);
3915
3916 // give packet socket powers to nodes.
3917 PacketSocketHelper packetSocket;
3918 packetSocket.Install(wifiStaNode);
3919 packetSocket.Install(wifiApNode);
3920
3921 auto client = CreateObject<PacketSocketClient>();
3922 client->SetAttribute("PacketSize", UintegerValue(1460));
3923 client->SetAttribute("MaxPackets", UintegerValue(4));
3924 client->SetRemote(socket);
3925 wifiStaNode.Get(0)->AddApplication(client);
3926 client->SetStartTime(Seconds(1));
3927 client->SetStopTime(Seconds(4.5));
3928
3929 auto server = CreateObject<PacketSocketServer>();
3930 server->SetLocal(socket);
3931 wifiApNode.Get(0)->AddApplication(server);
3932 server->SetStartTime(Seconds(0));
3933 server->SetStopTime(Seconds(4.5));
3934
3935 Config::Connect("/NodeList/1/ApplicationList/0/$ns3::PacketSocketServer/Rx",
3937
3938 // The PacketSocketClient starts at time 1s, and packets are sent at times 1s, 2s, 3s, 4s.
3939 // Change the MCS in between these send times (e.g., at 1.5s, 2.5s, 3.5s)
3941 Seconds(1.5),
3943 "/NodeList/0/DeviceList/0/RemoteStationManager/$ns3::ConstantRateWifiManager/DataMode",
3944 StringValue("DsssRate2Mbps"));
3946 Seconds(2.5),
3948 "/NodeList/0/DeviceList/0/RemoteStationManager/$ns3::ConstantRateWifiManager/DataMode",
3949 StringValue("DsssRate5_5Mbps"));
3951 Seconds(3.5),
3953 "/NodeList/0/DeviceList/0/RemoteStationManager/$ns3::ConstantRateWifiManager/DataMode",
3954 StringValue("DsssRate11Mbps"));
3955
3958
3960
3961 NS_TEST_ASSERT_MSG_EQ(m_received, 4, "Did not receive four DSSS packets");
3962}
3963
3964/**
3965 * @ingroup wifi-test
3966 * @ingroup tests
3967 *
3968 * @brief Wifi Test Suite
3969 */
3971{
3972 public:
3973 WifiTestSuite();
3974};
3975
3977 : TestSuite("wifi-devices", Type::UNIT)
3978{
3998}
3999
4000static WifiTestSuite g_wifiTestSuite; ///< the test suite
return result
Make sure that when virtual collision occurs the wifi remote station manager is triggered and the ret...
~Bug2222TestCase() override
uint32_t m_countInternalCollisions
count internal collisions
void DoRun() override
Implementation to actually run this TestCase.
void TxDataFailedTrace(std::string context, Mac48Address adr)
Transmit data failed function.
Make sure that the ADDBA handshake process is protected.
void RxErrorCallback(std::string context, Ptr< const Packet > p, double snr)
Callback when packet is dropped.
void RunSubtest(TypeOfStation rcvErrorType)
Run subtest for this test suite.
void DoRun() override
Implementation to actually run this TestCase.
uint16_t m_addbaResetCount
Count number of times ADDBA state machine is in reset state.
Time m_2ndPktSetStart
time the second set of packets is generated
uint16_t m_addbaRejectedCount
Count number of times ADDBA state machine is in rejected state.
void AddbaStateChangedCallback(std::string context, Time t, Mac48Address recipient, uint8_t tid, OriginatorBlockAckAgreement::State state)
Callback when ADDBA state changed.
uint16_t m_failedActionCount
Count failed ADDBA request/response.
void TxCallback(Ptr< ListErrorModel > rxErrorModel, std::string context, WifiConstPsduMap psduMap, WifiTxVector txVector, double txPowerW)
Callback when a frame is transmitted.
uint16_t m_addbaEstablishedCount
Count number of times ADDBA state machine is in established state.
void RxCallback(std::string context, Ptr< const Packet > p, uint16_t channelFreqMhz, WifiTxVector txVector, MpduInfo aMpdu, SignalNoiseDbm signalNoise, uint16_t staId)
Callback when packet is received.
~Bug2470TestCase() override
uint16_t m_receivedNormalMpduCount
Count received normal MPDU packets on STA.
uint16_t m_addbaNoReplyCount
Count number of times ADDBA state machine is in no_reply state.
uint16_t m_addbaPendingCount
Count number of times ADDBA state machine is in pending state.
void SendPacketBurst(uint32_t numPackets, Ptr< NetDevice > sourceDevice, Address &destination) const
Triggers the arrival of a burst of 1000 Byte-long packets in the source device.
uint16_t m_receivedAmpduCount
Count received A-MPDU packets on STA.
Make sure that the channel width and the channel number can be changed at runtime.
uint16_t m_countOperationalChannelWidth20
count number of beacon frames announcing a 20 MHz operating channel width
void ChangeSupportedChannelWidth()
Function called to change the supported channel width at runtime.
uint16_t m_countOperationalChannelWidth40
count number of beacon frames announcing a 40 MHz operating channel width
void RxCallback(std::string context, Ptr< const Packet > p, RxPowerWattPerChannelBand rxPowersW)
Callback triggered when a packet is received by the PHYs.
uint16_t m_assocReqCount
count number of association requests
Ptr< YansWifiPhy > m_apPhy
AP PHY.
void DoRun() override
Implementation to actually run this TestCase.
Ptr< YansWifiPhy > m_staPhy
STA PHY.
uint16_t m_assocRespCount
count number of association responses
~Bug2831TestCase() override
Make sure that the correct channel width and center frequency have been set for OFDM basic rate trans...
void SendPacketBurst(uint8_t numPackets, Ptr< NetDevice > sourceDevice, Address &destination) const
Triggers the arrival of a burst of 1000 Byte-long packets in the source device.
void StoreDistinctTuple(std::string context, Ptr< SpectrumSignalParameters > txParams)
Stores the distinct {starting frequency, channelWidth, Number of subbands in SpectrumModel,...
std::vector< FreqWidthSubbandModulationTuple > m_distinctTuples
vector of distinct {starting frequency, channelWidth, Number of subbands in SpectrumModel,...
void DoRun() override
Implementation to actually run this TestCase.
MHz_u m_channelWidth
channel width
std::tuple< Hz_u, MHz_u, uint32_t, WifiModulationClass > FreqWidthSubbandModulationTuple
A tuple of {starting frequency, channelWidth, Number of subbands in SpectrumModel,...
~Bug2843TestCase() override
Make sure that when changing the fragmentation threshold during the simulation, the TCP transmission ...
Definition wifi-test.cc:633
~Bug730TestCase() override
Definition wifi-test.cc:658
void Receive(std::string context, Ptr< const Packet > p, const Address &adr)
Receive function.
Definition wifi-test.cc:663
void DoRun() override
Implementation to actually run this TestCase.
Definition wifi-test.cc:672
uint32_t m_received
received
Definition wifi-test.cc:641
Make sure that when multiple broadcast packets are queued on the same device in a short succession,...
Definition wifi-test.cc:461
void NotifyPhyTxBegin(Ptr< const Packet > p, double txPowerW)
Notify Phy transmit begin.
Definition wifi-test.cc:496
void DoRun() override
Implementation to actually run this TestCase.
Definition wifi-test.cc:517
ObjectFactory m_propDelay
propagation delay
Definition wifi-test.cc:476
unsigned int m_numSentPackets
number of sent packets
Definition wifi-test.cc:480
Time m_secondTransmissionTime
second transmission time
Definition wifi-test.cc:479
Time m_firstTransmissionTime
first transmission time
Definition wifi-test.cc:478
void SendOnePacket(Ptr< WifiNetDevice > dev)
Send one packet function.
Definition wifi-test.cc:510
Make sure that all DSSS modulation types work (see issue #1095).
void Receive(std::string context, Ptr< const Packet > p, const Address &)
Trace sink to receive from the PacketSocket; the address parameter is unused.
void DoRun() override
Implementation to actually run this TestCase.
uint32_t m_received
number of received packets
Data rate verification test for MCSs of different RU sizes.
bool CheckDataRate(RuType ruType, std::string mcs, uint8_t nss, Time guardInterval, uint16_t expectedDataRate)
Compare the data rate computed for the provided combination with standard defined one.
void DoRun() override
Implementation to actually run this TestCase.
Make sure that Ideal rate manager properly selects MCS based on the configured channel width.
WifiMode m_txMode
Store the last selected mode to send data packet.
void ChangeChannelWidth(MHz_u channelWidth)
Change the configured channel width for all nodes.
void DoRun() override
Implementation to actually run this TestCase.
void SendPacket(Ptr< NetDevice > sourceDevice, Address &destination)
Triggers the transmission of a 1000 Byte-long data packet from the source device.
void CheckLastSelectedMode(WifiMode expectedMode)
Check if the selected WifiMode is correct.
void TxCallback(std::string context, WifiConstPsduMap psduMap, WifiTxVector txVector, double txPowerW)
Callback that indicates a PSDU is being transmitted.
Test to validate that Ideal rate manager properly selects TXVECTOR in scenarios where MIMO is used.
~IdealRateManagerMimoTest() override
void CheckLastSelectedNss(uint8_t expectedNss)
Check if the selected Nss is correct.
void DoRun() override
Implementation to actually run this TestCase.
void TxCallback(std::string context, WifiConstPsduMap psdus, WifiTxVector txVector, double txPowerW)
Callback that indicates a PSDU is being transmitted.
void SetApMimoSettings(uint8_t antennas, uint8_t maxStreams)
Change the configured MIMO settings for AP node.
WifiTxVector m_txVector
Store the last TXVECTOR used to transmit Data.
void SetStaMimoSettings(uint8_t antennas, uint8_t maxStreams)
Change the configured MIMO settings for STA node.
void SendPacket(Ptr< NetDevice > sourceDevice, Address &destination)
Triggers the transmission of a 1000 Byte-long data packet from the source device.
void CheckLastSelectedMode(WifiMode expectedMode)
Check if the selected WifiMode is correct.
void SwitchCh(Ptr< WifiNetDevice > dev)
Switch channel function.
Definition wifi-test.cc:309
void SendOnePacket(Ptr< WifiNetDevice > dev)
Send one packet function.
Definition wifi-test.cc:302
void DoRun() override
Implementation to actually run this TestCase.
Definition wifi-test.cc:361
ObjectFactory m_manager
manager
Definition wifi-test.cc:291
ObjectFactory m_propDelay
propagation delay
Definition wifi-test.cc:293
Ptr< Node > CreateOne(Vector pos, Ptr< YansWifiChannel > channel)
Create one function.
Definition wifi-test.cc:316
Make sure that Ideal rate manager is able to handle non best-effort traffic.
void SendPackets(uint8_t numPackets, Ptr< NetDevice > sourceDevice, Address &destination, uint8_t priority)
Triggers the transmission of a 1000 Byte-long data packet from the source device.
~Issue169TestCase() override
void TxCallback(std::string context, WifiConstPsduMap psdus, WifiTxVector txVector, double txPowerW)
Callback that indicates a PSDU is being transmitted.
void DoRun() override
Implementation to actually run this TestCase.
Make sure that Ideal rate manager recovers when the station is moving away from the access point.
uint16_t m_txCount
Count number of transmitted data packets.
uint16_t m_txMacFinalDataFailedCount
Count number of unsuccessfully transmitted data packets.
void RunOne(bool useAmpdu)
Run one function.
uint16_t m_rxCount
Count number of successfully received data packets.
void RxSuccessCallback(std::string context, Ptr< const Packet > p)
Callback when packet is successfully received.
void DoRun() override
Implementation to actually run this TestCase.
void TxFinalDataFailedCallback(std::string context, Mac48Address address)
Transmit final data failed function.
void SendPackets(uint8_t numPackets, Ptr< NetDevice > sourceDevice, Address &destination)
Triggers the arrival of 1000 Byte-long packets in the source device.
~Issue40TestCase() override
Test management header.
static TypeId GetTypeId()
Register this type.
~MgtTestHeader() override=default
TypeId GetInstanceTypeId() const override
Make sure that fragmentation works with QoS stations.
Definition wifi-test.cc:772
void DoRun() override
Implementation to actually run this TestCase.
Definition wifi-test.cc:833
uint32_t m_received
received packets
Definition wifi-test.cc:780
~QosFragmentationTestCase() override
Definition wifi-test.cc:807
uint32_t m_fragments
transmitted fragments
Definition wifi-test.cc:781
void Transmit(std::string context, Ptr< const Packet > p, double power)
Callback invoked when PHY transmits a packet.
Definition wifi-test.cc:821
void Receive(std::string context, Ptr< const Packet > p, const Address &adr)
Receive function.
Definition wifi-test.cc:812
Qos Utils Is Old Packet Test.
Definition wifi-test.cc:224
void DoRun() override
Implementation to actually run this TestCase.
Definition wifi-test.cc:231
Set Channel Frequency Test.
Definition wifi-test.cc:926
Ptr< YansWifiPhy > GetYansWifiPhyPtr(const NetDeviceContainer &nc) const
Get yans wifi phy function.
Definition wifi-test.cc:947
void DoRun() override
Implementation to actually run this TestCase.
Definition wifi-test.cc:955
Make sure that Wifi STA is correctly associating to the best AP (i.e., nearest from STA).
void DoRun() override
Implementation to actually run this TestCase.
void TurnBeaconGenerationOn(Ptr< Node > apNode)
Turn beacon generation on the AP node.
Mac48Address m_associatedApBssid
Associated AP's bssid.
~StaWifiMacScanningTestCase() override
void TurnApOff(Ptr< Node > apNode)
Turn the AP node off.
NodeContainer Setup(bool nearestApBeaconGeneration, bool staActiveProbe)
Setup test.
void AssocCallback(std::string context, Mac48Address bssid)
Callback function on STA assoc event.
Mgt header (de)serialization Test Suite.
void DoRun() override
Implementation to actually run this TestCase.
~WifiMgtHeaderTest() override=default
Wifi Test.
Definition wifi-test.cc:81
void CreateOne(Vector pos, Ptr< YansWifiChannel > channel)
Create one function.
Definition wifi-test.cc:120
void RunOne()
Run one function.
Definition wifi-test.cc:168
void DoRun() override
Implementation to actually run this TestCase.
Definition wifi-test.cc:187
ObjectFactory m_mac
MAC.
Definition wifi-test.cc:103
void SendOnePacket(Ptr< WifiNetDevice > dev)
Send one packet function.
Definition wifi-test.cc:113
ObjectFactory m_manager
manager
Definition wifi-test.cc:102
ObjectFactory m_propDelay
propagation delay
Definition wifi-test.cc:104
Wifi Test Suite.
a polymophic address class
Definition address.h:114
use constant rates for data and RTS transmissions
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
The Extended Supported Rates Information Element.
static WifiMode GetHeMcs(uint8_t index)
Return the HE MCS corresponding to the provided index.
Definition he-phy.cc:1581
RU Specification.
Definition he-ru.h:38
Protocol header serialization and deserialization.
Definition header.h:36
void TestHeaderSerialization(const T &hdr, Args &&... args)
Serialize the given header in a buffer, then create a new header by deserializing from the buffer and...
HeaderSerializationTestCase(std::string name)
Constructor.
The HT Operation Information Element.
an EUI-48 address
static Mac48Address Allocate()
Allocate a new Mac48Address.
Implement the header for management frames of type beacon.
Helper class used to assign positions and mobility models to nodes.
Keep track of the current position and velocity of an object.
holds a vector of ns3::NetDevice pointers
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.
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.
uint32_t AddApplication(Ptr< Application > application)
Associate an Application to this Node.
Definition node.cc:153
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Instantiate subclasses of ns3::Object.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition object.h:518
State
Represents the state for this agreement.
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.
AttributeValue implementation for Pointer.
Definition pointer.h:37
calculate a propagation delay.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
static void SetRun(uint64_t run)
Set the run number of simulation.
static void SetSeed(uint32_t seed)
Set the seed.
Received power (W) per spectrum band.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:580
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:125
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:191
static void Run()
Run the simulation.
Definition simulator.cc:161
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:169
indicates whether the socket has a priority set.
Definition socket.h:1308
void SetPriority(uint8_t priority)
Set the tag's priority.
Definition socket.cc:845
Make it easy to create and manage PHY objects for the spectrum model.
void SetChannel(const Ptr< SpectrumChannel > channel)
The IEEE 802.11 SSID Information Element.
Definition ssid.h:27
char * PeekString() const
Peek the SSID.
Definition ssid.cc:67
AttributeValue implementation for Ssid.
Definition ssid.h:98
Hold variables of type string.
Definition string.h:45
The Supported Rates Information Element.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:296
@ QUICK
Fast test.
Definition test.h:1057
TestCase(const TestCase &)=delete
Caller graph was not generated because of its size.
Type
Type of test.
Definition test.h:1271
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
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1003
Hold an unsigned integer type.
Definition uinteger.h:34
static WifiMode GetVhtMcs3()
static WifiMode GetVhtMcs1()
static WifiMode GetVhtMcs2()
a (time, location) pair.
Definition waypoint.h:25
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 ...
Implements the IEEE 802.11 MAC header.
bool IsAssocReq() const
Return true if the header is an Association Request header.
bool IsBeacon() const
Return true if the header is a Beacon header.
bool IsAssocResp() const
Return true if the header is an Association Response header.
bool IsAction() const
Return true if the header is an Action header.
bool IsData() const
Return true if the Type is DATA.
bool IsQosData() const
Return true if the Type is DATA and Subtype is one of the possible values for QoS Data.
create MAC layers for a ns3::WifiNetDevice.
void SetType(std::string type, Args &&... args)
base class for all MAC-level wifi objects.
Definition wifi-mac.h:117
void SetDevice(const Ptr< WifiNetDevice > device)
Sets the device this PHY is associated with.
Definition wifi-mac.cc:497
Implement the header for management frames.
represent a single transmission mode
Definition wifi-mode.h:39
WifiModulationClass GetModulationClass() const
Definition wifi-mode.cc:172
Hold together all Wifi-related objects.
void Set(std::string name, const AttributeValue &v)
void SetErrorRateModel(std::string type, Args &&... args)
Helper function used to set the error rate model.
WifiChannelConfig::SegmentWithoutUnits ChannelTuple
kept for backward compatibility, can be deprecated when using strong types
Definition wifi-phy.h:954
hold a list of per-remote-station state.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
WifiMode GetMode(uint16_t staId=SU_STA_ID) const
If this TX vector is associated with an SU PPDU, return the selected payload transmission mode.
MHz_u GetChannelWidth() const
manage and create wifi channel objects for the YANS model.
static YansWifiChannelHelper Default()
Create a channel helper in a default working state.
Make it easy to create and manage PHY objects for the YANS model.
802.11 PHY layer model
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:690
void Connect(std::string path, const CallbackBase &cb)
Definition config.cc:966
void Set(std::string path, const AttributeValue &value)
Definition config.cc:872
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition abort.h:38
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition abort.h:99
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:627
Ptr< T > CreateObjectWithAttributes(Args... args)
Allocate an Object on the heap and initialize with a set of attributes.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:492
#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
#define NS_TEST_EXPECT_MSG_LT_OR_EQ(actual, limit, msg)
Test that an actual value is less than or equal to a limit and report if not.
Definition test.h:819
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Definition test.h:240
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1347
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1364
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1313
TypeOfStation
Enumeration for type of WiFi station.
Definition wifi-mac.h:59
WifiModulationClass
This enumeration defines the modulation classes per (Table 10-6 "Modulation classes"; IEEE 802....
bool QosUtilsIsOldPacket(uint16_t startingSeq, uint16_t seqNumber)
This function checks if packet with sequence number seqNumber is an "old" packet.
Definition qos-utils.cc:156
@ STA
Definition wifi-mac.h:60
@ AP
Definition wifi-mac.h:61
@ WIFI_STANDARD_80211a
@ WIFI_STANDARD_80211p
@ WIFI_STANDARD_80211n
@ WIFI_STANDARD_80211g
@ WIFI_STANDARD_80211ax
@ WIFI_STANDARD_80211ac
@ WIFI_STANDARD_80211b
@ WIFI_PREAMBLE_HE_MU
@ WIFI_PHY_BAND_5GHZ
The 5 GHz band.
@ WIFI_MOD_CLASS_OFDM
OFDM (Clause 17).
@ WIFI_MOD_CLASS_VHT
VHT (Clause 22).
@ AC_BE
Best Effort.
Definition qos-utils.h:66
@ AC_VO
Voice.
Definition qos-utils.h:72
@ AC_VI
Video.
Definition qos-utils.h:70
@ AC_BK
Background.
Definition qos-utils.h:68
@ NORMAL_MPDU
The MPDU is not part of an A-MPDU.
Definition wifi-types.h:56
NodeContainer nodes
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< void, Ptr< const WifiPsdu > > RxErrorCallback
Callback if PSDU unsuccessfully received.
static constexpr uint8_t WIFI_MIN_TX_PWR_LEVEL
minimum TX power level value
double Hz_u
Hz weak type.
Definition wifi-units.h:30
RuType
The different Resource Unit (RU) types.
Definition wifi-types.h:286
double MHz_u
MHz weak type.
Definition wifi-units.h:31
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:643
@ WIFI_MAC_MGT_ACTION
Ptr< T1 > StaticCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:650
std::unordered_map< uint16_t, Ptr< const WifiPsdu > > WifiConstPsduMap
Map of const PSDUs indexed by STA-ID.
Definition wifi-ppdu.h:39
Struct containing all supported rates.
SupportedRates rates
supported rates
std::optional< ExtendedSupportedRatesIE > extendedRates
supported extended rates
void AddSupportedRate(uint64_t bs)
Add the given rate to the supported rates.
MpduInfo structure.
Definition wifi-types.h:78
MpduType type
type of MPDU
Definition wifi-types.h:79
SignalNoiseDbm structure.
Definition wifi-types.h:71
static void AssignWifiRandomStreams(Ptr< WifiMac > mac, int64_t stream)
Definition wifi-test.cc:58
static WifiTestSuite g_wifiTestSuite
the test suite
std::tuple< SupportedRates, std::optional< ExtendedSupportedRatesIE >, std::vector< Ssid > > MgtTestElems
List of Information Elements included in the test management frame.