A Discrete-Event Network Simulator
API
wifi-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2005,2006 INRIA
4  * 2010 NICTA
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20  * Quincy Tse <quincy.tse@nicta.com.au>
21  * S├ębastien Deronne <sebastien.deronne@gmail.com>
22  */
23 
24 #include "ns3/string.h"
25 #include "ns3/yans-wifi-helper.h"
26 #include "ns3/mobility-helper.h"
27 #include "ns3/wifi-net-device.h"
28 #include "ns3/adhoc-wifi-mac.h"
29 #include "ns3/ap-wifi-mac.h"
30 #include "ns3/propagation-loss-model.h"
31 #include "ns3/interference-helper.h"
32 #include "ns3/yans-error-rate-model.h"
33 #include "ns3/constant-position-mobility-model.h"
34 #include "ns3/test.h"
35 #include "ns3/pointer.h"
36 #include "ns3/rng-seed-manager.h"
37 #include "ns3/config.h"
38 #include "ns3/error-model.h"
39 #include "ns3/socket.h"
40 #include "ns3/packet-socket-server.h"
41 #include "ns3/packet-socket-client.h"
42 #include "ns3/packet-socket-helper.h"
43 #include "ns3/spectrum-wifi-helper.h"
44 #include "ns3/multi-model-spectrum-channel.h"
45 #include "ns3/wifi-spectrum-signal-parameters.h"
46 #include "ns3/yans-wifi-phy.h"
47 #include "ns3/mgt-headers.h"
48 #include "ns3/ht-configuration.h"
49 #include "ns3/wifi-ppdu.h"
50 #include "ns3/wifi-psdu.h"
51 #include "ns3/vht-phy.h"
52 #include "ns3/waypoint-mobility-model.h"
53 #include "ns3/frame-exchange-manager.h"
54 #include "ns3/wifi-default-protection-manager.h"
55 #include "ns3/wifi-default-ack-manager.h"
56 
57 using namespace ns3;
58 
59 //Helper function to assign streams to random variables, to control
60 //randomness in the tests
61 static void
63 {
64  int64_t currentStream = stream;
65  PointerValue ptr;
66  if (!mac->GetQosSupported ())
67  {
68  mac->GetAttribute ("Txop", ptr);
69  Ptr<Txop> txop = ptr.Get<Txop> ();
70  currentStream += txop->AssignStreams (currentStream);
71  }
72  else
73  {
74  mac->GetAttribute ("VO_Txop", ptr);
75  Ptr<QosTxop> vo_txop = ptr.Get<QosTxop> ();
76  currentStream += vo_txop->AssignStreams (currentStream);
77 
78  mac->GetAttribute ("VI_Txop", ptr);
79  Ptr<QosTxop> vi_txop = ptr.Get<QosTxop> ();
80  currentStream += vi_txop->AssignStreams (currentStream);
81 
82  mac->GetAttribute ("BE_Txop", ptr);
83  Ptr<QosTxop> be_txop = ptr.Get<QosTxop> ();
84  currentStream += be_txop->AssignStreams (currentStream);
85 
86  mac->GetAttribute ("BK_Txop", ptr);
87  Ptr<QosTxop> bk_txop = ptr.Get<QosTxop> ();
88  bk_txop->AssignStreams (currentStream);
89  }
90 }
91 
98 class WifiTest : public TestCase
99 {
100 public:
101  WifiTest ();
102 
103  void DoRun (void) override;
104 
105 
106 private:
108  void RunOne (void);
114  void CreateOne (Vector pos, Ptr<YansWifiChannel> channel);
120 
124 };
125 
127  : TestCase ("Wifi")
128 {
129 }
130 
131 void
133 {
134  Ptr<Packet> p = Create<Packet> ();
135  dev->Send (p, dev->GetBroadcast (), 1);
136 }
137 
138 void
140 {
141  Ptr<Node> node = CreateObject<Node> ();
142  Ptr<WifiNetDevice> dev = CreateObject<WifiNetDevice> ();
143 
145  mac->SetDevice (dev);
146  mac->SetAddress (Mac48Address::Allocate ());
147  mac->ConfigureStandard (WIFI_STANDARD_80211a);
148  Ptr<FrameExchangeManager> fem = mac->GetFrameExchangeManager ();
149  Ptr<WifiProtectionManager> protectionManager = CreateObject<WifiDefaultProtectionManager> ();
150  protectionManager->SetWifiMac (mac);
151  fem->SetProtectionManager (protectionManager);
152  Ptr<WifiAckManager> ackManager = CreateObject<WifiDefaultAckManager> ();
153  ackManager->SetWifiMac (mac);
154  fem->SetAckManager (ackManager);
155 
156  Ptr<ConstantPositionMobilityModel> mobility = CreateObject<ConstantPositionMobilityModel> ();
157  Ptr<YansWifiPhy> phy = CreateObject<YansWifiPhy> ();
158  Ptr<InterferenceHelper> interferenceHelper = CreateObject<InterferenceHelper> ();
159  phy->SetInterferenceHelper (interferenceHelper);
160  Ptr<ErrorRateModel> error = CreateObject<YansErrorRateModel> ();
161  phy->SetErrorRateModel (error);
162  phy->SetChannel (channel);
163  phy->SetDevice (dev);
164  phy->ConfigureStandard (WIFI_STANDARD_80211a);
166 
167  mobility->SetPosition (pos);
168  node->AggregateObject (mobility);
169  dev->SetMac (mac);
170  dev->SetPhy (phy);
171  dev->SetRemoteStationManager (manager);
172  node->AddDevice (dev);
173 
174  Simulator::Schedule (Seconds (1.0), &WifiTest::SendOnePacket, this, dev);
175 }
176 
177 void
179 {
180  Ptr<YansWifiChannel> channel = CreateObject<YansWifiChannel> ();
182  Ptr<PropagationLossModel> propLoss = CreateObject<RandomPropagationLossModel> ();
183  channel->SetPropagationDelayModel (propDelay);
184  channel->SetPropagationLossModel (propLoss);
185 
186  CreateOne (Vector (0.0, 0.0, 0.0), channel);
187  CreateOne (Vector (5.0, 0.0, 0.0), channel);
188  CreateOne (Vector (5.0, 0.0, 0.0), channel);
189 
190  Simulator::Stop (Seconds (10.0));
191 
192  Simulator::Run ();
193  Simulator::Destroy ();
194 }
195 
196 void
198 {
199  m_mac.SetTypeId ("ns3::AdhocWifiMac");
200  m_propDelay.SetTypeId ("ns3::ConstantSpeedPropagationDelayModel");
201 
202  m_manager.SetTypeId ("ns3::ArfWifiManager");
203  RunOne ();
204  m_manager.SetTypeId ("ns3::AarfWifiManager");
205  RunOne ();
206  m_manager.SetTypeId ("ns3::ConstantRateWifiManager");
207  RunOne ();
208  m_manager.SetTypeId ("ns3::OnoeWifiManager");
209  RunOne ();
210  m_manager.SetTypeId ("ns3::AmrrWifiManager");
211  RunOne ();
212  m_manager.SetTypeId ("ns3::IdealWifiManager");
213  RunOne ();
214 
215  m_mac.SetTypeId ("ns3::AdhocWifiMac");
216  RunOne ();
217  m_mac.SetTypeId ("ns3::ApWifiMac");
218  RunOne ();
219  m_mac.SetTypeId ("ns3::StaWifiMac");
220  RunOne ();
221 
222 
223  m_propDelay.SetTypeId ("ns3::RandomPropagationDelayModel");
224  m_mac.SetTypeId ("ns3::AdhocWifiMac");
225  RunOne ();
226 }
227 
235 {
236 public:
237  QosUtilsIsOldPacketTest () : TestCase ("QosUtilsIsOldPacket")
238  {
239  }
240  void DoRun (void) override
241  {
242  //startingSeq=0, seqNum=2047
243  NS_TEST_EXPECT_MSG_EQ (QosUtilsIsOldPacket (0, 2047), false, "2047 is new in comparison to 0");
244  //startingSeq=0, seqNum=2048
245  NS_TEST_EXPECT_MSG_EQ (QosUtilsIsOldPacket (0, 2048), true, "2048 is old in comparison to 0");
246  //startingSeq=2048, seqNum=0
247  NS_TEST_EXPECT_MSG_EQ (QosUtilsIsOldPacket (2048, 0), true, "0 is old in comparison to 2048");
248  //startingSeq=4095, seqNum=0
249  NS_TEST_EXPECT_MSG_EQ (QosUtilsIsOldPacket (4095, 0), false, "0 is new in comparison to 4095");
250  //startingSeq=0, seqNum=4095
251  NS_TEST_EXPECT_MSG_EQ (QosUtilsIsOldPacket (0, 4095), true, "4095 is old in comparison to 0");
252  //startingSeq=4095 seqNum=2047
253  NS_TEST_EXPECT_MSG_EQ (QosUtilsIsOldPacket (4095, 2047), true, "2047 is old in comparison to 4095");
254  //startingSeq=2048 seqNum=4095
255  NS_TEST_EXPECT_MSG_EQ (QosUtilsIsOldPacket (2048, 4095), false, "4095 is new in comparison to 2048");
256  //startingSeq=2049 seqNum=0
257  NS_TEST_EXPECT_MSG_EQ (QosUtilsIsOldPacket (2049, 0), false, "0 is new in comparison to 2049");
258  }
259 };
260 
261 
266 {
267 public:
269 
270  void DoRun (void) override;
271 
272 
273 private:
290  void SwitchCh (Ptr<WifiNetDevice> dev);
291 
295 };
296 
298  : TestCase ("InterferenceHelperSequence")
299 {
300 }
301 
302 void
304 {
305  Ptr<Packet> p = Create<Packet> (1000);
306  dev->Send (p, dev->GetBroadcast (), 1);
307 }
308 
309 void
311 {
312  Ptr<WifiPhy> p = dev->GetPhy ();
314 }
315 
316 Ptr<Node>
318 {
319  Ptr<Node> node = CreateObject<Node> ();
320  Ptr<WifiNetDevice> dev = CreateObject<WifiNetDevice> ();
321 
323  mac->SetDevice (dev);
324  mac->SetAddress (Mac48Address::Allocate ());
325  mac->ConfigureStandard (WIFI_STANDARD_80211a);
326  Ptr<FrameExchangeManager> fem = mac->GetFrameExchangeManager ();
327  Ptr<WifiProtectionManager> protectionManager = CreateObject<WifiDefaultProtectionManager> ();
328  protectionManager->SetWifiMac (mac);
329  fem->SetProtectionManager (protectionManager);
330  Ptr<WifiAckManager> ackManager = CreateObject<WifiDefaultAckManager> ();
331  ackManager->SetWifiMac (mac);
332  fem->SetAckManager (ackManager);
333 
334  Ptr<ConstantPositionMobilityModel> mobility = CreateObject<ConstantPositionMobilityModel> ();
335  Ptr<YansWifiPhy> phy = CreateObject<YansWifiPhy> ();
336  Ptr<InterferenceHelper> interferenceHelper = CreateObject<InterferenceHelper> ();
337  phy->SetInterferenceHelper (interferenceHelper);
338  Ptr<ErrorRateModel> error = CreateObject<YansErrorRateModel> ();
339  phy->SetErrorRateModel (error);
340  phy->SetChannel (channel);
341  phy->SetDevice (dev);
342  phy->SetMobility (mobility);
343  phy->ConfigureStandard (WIFI_STANDARD_80211a);
345 
346  mobility->SetPosition (pos);
347  node->AggregateObject (mobility);
348  dev->SetMac (mac);
349  dev->SetPhy (phy);
350  dev->SetRemoteStationManager (manager);
351  node->AddDevice (dev);
352 
353  return node;
354 }
355 
356 void
358 {
359  m_mac.SetTypeId ("ns3::AdhocWifiMac");
360  m_propDelay.SetTypeId ("ns3::ConstantSpeedPropagationDelayModel");
361  m_manager.SetTypeId ("ns3::ConstantRateWifiManager");
362 
363  Ptr<YansWifiChannel> channel = CreateObject<YansWifiChannel> ();
365  Ptr<MatrixPropagationLossModel> propLoss = CreateObject<MatrixPropagationLossModel> ();
366  channel->SetPropagationDelayModel (propDelay);
367  channel->SetPropagationLossModel (propLoss);
368 
369  Ptr<Node> rxOnly = CreateOne (Vector (0.0, 0.0, 0.0), channel);
370  Ptr<Node> senderA = CreateOne (Vector (5.0, 0.0, 0.0), channel);
371  Ptr<Node> senderB = CreateOne (Vector (-5.0, 0.0, 0.0), channel);
372 
373  propLoss->SetLoss (senderB->GetObject<MobilityModel> (), rxOnly->GetObject<MobilityModel> (), 0, true);
374  propLoss->SetDefaultLoss (999);
375 
376  Simulator::Schedule (Seconds (1.0),
378  DynamicCast<WifiNetDevice> (senderB->GetDevice (0)));
379 
380  Simulator::Schedule (Seconds (1.0000001),
382  DynamicCast<WifiNetDevice> (rxOnly->GetDevice (0)));
383 
384  Simulator::Schedule (Seconds (5.0),
386  DynamicCast<WifiNetDevice> (senderA->GetDevice (0)));
387 
388  Simulator::Schedule (Seconds (7.0),
390  DynamicCast<WifiNetDevice> (senderB->GetDevice (0)));
391 
392  Simulator::Stop (Seconds (100.0));
393  Simulator::Run ();
394 
395  Simulator::Destroy ();
396 }
397 
398 //-----------------------------------------------------------------------------
450 {
451 public:
453 
454  void DoRun (void) override;
455 
456 
457 private:
463 
467 
470  unsigned int m_numSentPackets;
471 
477  void NotifyPhyTxBegin (Ptr<const Packet> p, double txPowerW);
478 };
479 
481  : TestCase ("Test case for DCF immediate access with broadcast frames")
482 {
483 }
484 
485 void
487 {
488  if (m_numSentPackets == 0)
489  {
492  }
493  else if (m_numSentPackets == 1)
494  {
496  }
497 }
498 
499 void
501 {
502  Ptr<Packet> p = Create<Packet> (1000);
503  dev->Send (p, dev->GetBroadcast (), 1);
504 }
505 
506 void
508 {
509  m_mac.SetTypeId ("ns3::AdhocWifiMac");
510  m_propDelay.SetTypeId ("ns3::ConstantSpeedPropagationDelayModel");
511  m_manager.SetTypeId ("ns3::ConstantRateWifiManager");
512 
513  //Assign a seed and run number, and later fix the assignment of streams to
514  //WiFi random variables, so that the first backoff used is one slot
515  RngSeedManager::SetSeed (1);
516  RngSeedManager::SetRun (40); // a value of 17 will result in zero slots
517 
518  Ptr<YansWifiChannel> channel = CreateObject<YansWifiChannel> ();
520  Ptr<PropagationLossModel> propLoss = CreateObject<RandomPropagationLossModel> ();
521  channel->SetPropagationDelayModel (propDelay);
522  channel->SetPropagationLossModel (propLoss);
523 
524  Ptr<Node> txNode = CreateObject<Node> ();
525  Ptr<WifiNetDevice> txDev = CreateObject<WifiNetDevice> ();
526  Ptr<WifiMac> txMac = m_mac.Create<WifiMac> ();
527  txMac->SetDevice (txDev);
528  txMac->ConfigureStandard (WIFI_STANDARD_80211a);
529  Ptr<FrameExchangeManager> fem = txMac->GetFrameExchangeManager ();
530  Ptr<WifiProtectionManager> protectionManager = CreateObject<WifiDefaultProtectionManager> ();
531  protectionManager->SetWifiMac (txMac);
532  fem->SetProtectionManager (protectionManager);
533  Ptr<WifiAckManager> ackManager = CreateObject<WifiDefaultAckManager> ();
534  ackManager->SetWifiMac (txMac);
535  fem->SetAckManager (ackManager);
536 
537 
538  //Fix the stream assignment to the Dcf Txop objects (backoffs)
539  //The below stream assignment will result in the Txop object
540  //using a backoff value of zero for this test when the
541  //Txop::EndTxNoAck() calls to StartBackoffNow()
542  AssignWifiRandomStreams (txMac, 23);
543 
544  Ptr<ConstantPositionMobilityModel> txMobility = CreateObject<ConstantPositionMobilityModel> ();
545  Ptr<YansWifiPhy> txPhy = CreateObject<YansWifiPhy> ();
546  Ptr<InterferenceHelper> txInterferenceHelper = CreateObject<InterferenceHelper> ();
547  txPhy->SetInterferenceHelper (txInterferenceHelper);
548  Ptr<ErrorRateModel> txError = CreateObject<YansErrorRateModel> ();
549  txPhy->SetErrorRateModel (txError);
550  txPhy->SetChannel (channel);
551  txPhy->SetDevice (txDev);
552  txPhy->SetMobility (txMobility);
554 
556 
557  txMobility->SetPosition (Vector (0.0, 0.0, 0.0));
558  txNode->AggregateObject (txMobility);
559  txMac->SetAddress (Mac48Address::Allocate ());
560  txDev->SetMac (txMac);
561  txDev->SetPhy (txPhy);
563  txNode->AddDevice (txDev);
564 
567  m_numSentPackets = 0;
568 
569  Simulator::Schedule (Seconds (1.0), &DcfImmediateAccessBroadcastTestCase::SendOnePacket, this, txDev);
570  Simulator::Schedule (Seconds (1.0) + MicroSeconds (1), &DcfImmediateAccessBroadcastTestCase::SendOnePacket, this, txDev);
571 
572  Simulator::Stop (Seconds (2.0));
573  Simulator::Run ();
574  Simulator::Destroy ();
575 
576  // First packet is transmitted a DIFS after the packet is queued. A DIFS
577  // is 2 slots (2 * 9 = 18 us) plus a SIFS (16 us), i.e., 34 us
578  Time expectedFirstTransmissionTime = Seconds (1.0) + MicroSeconds (34);
579 
580  //First packet has 1408 us of transmit time. Slot time is 9 us.
581  //Backoff is 1 slots. SIFS is 16 us. DIFS is 2 slots = 18 us.
582  //Should send next packet at 1408 us + (1 * 9 us) + 16 us + (2 * 9) us
583  //1451 us after the first one.
584  uint32_t expectedWait1 = 1408 + (1 * 9) + 16 + (2 * 9);
585  Time expectedSecondTransmissionTime = expectedFirstTransmissionTime + MicroSeconds (expectedWait1);
586  NS_TEST_ASSERT_MSG_EQ (m_firstTransmissionTime, expectedFirstTransmissionTime, "The first transmission time not correct!");
587 
588  NS_TEST_ASSERT_MSG_EQ (m_secondTransmissionTime, expectedSecondTransmissionTime, "The second transmission time not correct!");
589 }
590 
591 //-----------------------------------------------------------------------------
604 class Bug730TestCase : public TestCase
605 {
606 public:
607  Bug730TestCase ();
608  virtual ~Bug730TestCase ();
609 
610  void DoRun (void) override;
611 
612 
613 private:
614  uint32_t m_received;
615 
622  void Receive (std::string context, Ptr<const Packet> p, const Address &adr);
623 
624 };
625 
627  : TestCase ("Test case for Bug 730"),
628  m_received (0)
629 {
630 }
631 
633 {
634 }
635 
636 void
637 Bug730TestCase::Receive (std::string context, Ptr<const Packet> p, const Address &adr)
638 {
639  if ((p->GetSize () == 1460) && (Simulator::Now () > Seconds (20)))
640  {
641  m_received++;
642  }
643 }
644 
645 
646 void
648 {
649  m_received = 0;
650 
651  NodeContainer wifiStaNode;
652  wifiStaNode.Create (1);
653 
655  wifiApNode.Create (1);
656 
657  YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
659  phy.SetChannel (channel.Create ());
660 
662  wifi.SetStandard (WIFI_STANDARD_80211b);
663  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
664  "DataMode", StringValue ("DsssRate1Mbps"),
665  "ControlMode", StringValue ("DsssRate1Mbps"));
666 
668  Ssid ssid = Ssid ("ns-3-ssid");
669  mac.SetType ("ns3::StaWifiMac",
670  "Ssid", SsidValue (ssid),
671  "ActiveProbing", BooleanValue (false));
672 
674  staDevices = wifi.Install (phy, mac, wifiStaNode);
675 
676  mac.SetType ("ns3::ApWifiMac",
677  "Ssid", SsidValue (ssid),
678  "BeaconGeneration", BooleanValue (true));
679 
681  apDevices = wifi.Install (phy, mac, wifiApNode);
682 
684  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
685 
686  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
687  positionAlloc->Add (Vector (1.0, 0.0, 0.0));
688  mobility.SetPositionAllocator (positionAlloc);
689 
690  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
691  mobility.Install (wifiApNode);
692  mobility.Install (wifiStaNode);
693 
694  Ptr<WifiNetDevice> ap_device = DynamicCast<WifiNetDevice> (apDevices.Get (0));
695  Ptr<WifiNetDevice> sta_device = DynamicCast<WifiNetDevice> (staDevices.Get (0));
696 
697  PacketSocketAddress socket;
698  socket.SetSingleDevice (sta_device->GetIfIndex ());
699  socket.SetPhysicalAddress (ap_device->GetAddress ());
700  socket.SetProtocol (1);
701 
702  // give packet socket powers to nodes.
703  PacketSocketHelper packetSocket;
704  packetSocket.Install (wifiStaNode);
705  packetSocket.Install (wifiApNode);
706 
707  Ptr<PacketSocketClient> client = CreateObject<PacketSocketClient> ();
708  client->SetAttribute ("PacketSize", UintegerValue (1460));
709  client->SetRemote (socket);
710  wifiStaNode.Get (0)->AddApplication (client);
711  client->SetStartTime (Seconds (1));
712  client->SetStopTime (Seconds (51.0));
713 
714  Ptr<PacketSocketServer> server = CreateObject<PacketSocketServer> ();
715  server->SetLocal (socket);
716  wifiApNode.Get (0)->AddApplication (server);
717  server->SetStartTime (Seconds (0.0));
718  server->SetStopTime (Seconds (52.0));
719 
720  Config::Connect ("/NodeList/*/ApplicationList/0/$ns3::PacketSocketServer/Rx", MakeCallback (&Bug730TestCase::Receive, this));
721 
722  Simulator::Schedule (Seconds (10.0), Config::Set, "/NodeList/0/DeviceList/0/RemoteStationManager/FragmentationThreshold", StringValue ("800"));
723 
724  Simulator::Stop (Seconds (55));
725  Simulator::Run ();
726 
727  Simulator::Destroy ();
728 
729  bool result = (m_received > 0);
730  NS_TEST_ASSERT_MSG_EQ (result, true, "packet reception unexpectedly stopped after adapting fragmentation threshold!");
731 }
732 
733 //-----------------------------------------------------------------------------
742 {
743 public:
745  virtual ~QosFragmentationTestCase ();
746 
747  void DoRun (void) override;
748 
749 
750 private:
751  uint32_t m_received;
752  uint32_t m_fragments;
753 
760  void Receive (std::string context, Ptr<const Packet> p, const Address &adr);
761 
768  void Transmit (std::string context, Ptr<const Packet> p, double power);
769 };
770 
772  : TestCase ("Test case for fragmentation with QoS stations"),
773  m_received (0),
774  m_fragments (0)
775 {
776 }
777 
779 {
780 }
781 
782 void
783 QosFragmentationTestCase::Receive (std::string context, Ptr<const Packet> p, const Address &adr)
784 {
785  if (p->GetSize () == 1400)
786  {
787  m_received++;
788  }
789 }
790 
791 void
792 QosFragmentationTestCase::Transmit (std::string context, Ptr<const Packet> p, double power)
793 {
794  WifiMacHeader hdr;
795  p->PeekHeader (hdr);
796  if (hdr.IsQosData ())
797  {
798  NS_TEST_EXPECT_MSG_LT_OR_EQ (p->GetSize (), 400, "Unexpected fragment size");
799  m_fragments++;
800  }
801 }
802 
803 void
805 {
806  NodeContainer wifiStaNode;
807  wifiStaNode.Create (1);
808 
810  wifiApNode.Create (1);
811 
812  YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
814  phy.SetChannel (channel.Create ());
815 
817  wifi.SetStandard (WIFI_STANDARD_80211n);
818  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
819  "DataMode", StringValue ("HtMcs7"));
820 
822  Ssid ssid = Ssid ("ns-3-ssid");
823  mac.SetType ("ns3::StaWifiMac",
824  "Ssid", SsidValue (ssid),
825  "ActiveProbing", BooleanValue (false));
826 
828  staDevices = wifi.Install (phy, mac, wifiStaNode);
829 
830  mac.SetType ("ns3::ApWifiMac",
831  "Ssid", SsidValue (ssid),
832  "BeaconGeneration", BooleanValue (true));
833 
835  apDevices = wifi.Install (phy, mac, wifiApNode);
836 
838  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
839 
840  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
841  positionAlloc->Add (Vector (1.0, 0.0, 0.0));
842  mobility.SetPositionAllocator (positionAlloc);
843 
844  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
845  mobility.Install (wifiApNode);
846  mobility.Install (wifiStaNode);
847 
848  Ptr<WifiNetDevice> ap_device = DynamicCast<WifiNetDevice> (apDevices.Get (0));
849  Ptr<WifiNetDevice> sta_device = DynamicCast<WifiNetDevice> (staDevices.Get (0));
850 
851  // set the TXOP limit on BE AC
852  PointerValue ptr;
853  sta_device->GetMac ()->GetAttribute ("BE_Txop", ptr);
854  ptr.Get<QosTxop> ()->SetTxopLimit (MicroSeconds (3008));
855 
856  PacketSocketAddress socket;
857  socket.SetSingleDevice (sta_device->GetIfIndex ());
858  socket.SetPhysicalAddress (ap_device->GetAddress ());
859  socket.SetProtocol (1);
860 
861  // give packet socket powers to nodes.
862  PacketSocketHelper packetSocket;
863  packetSocket.Install (wifiStaNode);
864  packetSocket.Install (wifiApNode);
865 
866  Ptr<PacketSocketClient> client = CreateObject<PacketSocketClient> ();
867  client->SetAttribute ("PacketSize", UintegerValue (1400));
868  client->SetAttribute ("MaxPackets", UintegerValue (1));
869  client->SetRemote (socket);
870  wifiStaNode.Get (0)->AddApplication (client);
871  client->SetStartTime (Seconds (1));
872  client->SetStopTime (Seconds (3.0));
873 
874  Ptr<PacketSocketServer> server = CreateObject<PacketSocketServer> ();
875  server->SetLocal (socket);
876  wifiApNode.Get (0)->AddApplication (server);
877  server->SetStartTime (Seconds (0.0));
878  server->SetStopTime (Seconds (4.0));
879 
880  Config::Connect ("/NodeList/*/ApplicationList/0/$ns3::PacketSocketServer/Rx", MakeCallback (&QosFragmentationTestCase::Receive, this));
881 
882  Config::Set ("/NodeList/0/DeviceList/0/RemoteStationManager/FragmentationThreshold", StringValue ("400"));
883  Config::Connect ("/NodeList/0/DeviceList/0/Phy/PhyTxBegin", MakeCallback (&QosFragmentationTestCase::Transmit, this));
884 
885  Simulator::Stop (Seconds (5));
886  Simulator::Run ();
887 
888  Simulator::Destroy ();
889 
890  NS_TEST_ASSERT_MSG_EQ (m_received, 1, "Unexpected number of received packets");
891  NS_TEST_ASSERT_MSG_EQ (m_fragments, 4, "Unexpected number of transmitted fragments");
892 }
893 
901 {
902 public:
904 
905  void DoRun (void) override;
906 
907 
908 private:
915 
916 };
917 
919  : TestCase ("Test case for setting WifiPhy channel and frequency")
920 {
921 }
922 
925 {
926  Ptr<WifiNetDevice> wnd = nc.Get (0)->GetObject<WifiNetDevice> ();
927  Ptr<WifiPhy> wp = wnd->GetPhy ();
928  return wp->GetObject<YansWifiPhy> ();
929 }
930 
931 void
933 {
934  NodeContainer wifiStaNode;
935  wifiStaNode.Create (1);
937  wifiApNode.Create (1);
938 
939  YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
941  phy.SetChannel (channel.Create ());
942 
943  // Configure and declare other generic components of this example
944  Ssid ssid;
945  ssid = Ssid ("wifi-phy-configuration");
946  WifiMacHelper macSta;
947  macSta.SetType ("ns3::StaWifiMac",
948  "Ssid", SsidValue (ssid),
949  "ActiveProbing", BooleanValue (false));
950  NetDeviceContainer staDevice;
951  Ptr<YansWifiPhy> phySta;
952 
953  // Cases taken from src/wifi/examples/wifi-phy-configuration.cc example
954  {
955  // case 0:
956  // Default configuration, without WifiHelper::SetStandard or WifiHelper
957  phySta = CreateObject<YansWifiPhy> ();
958  // The default results in an invalid configuration
959  NS_TEST_ASSERT_MSG_EQ (phySta->GetOperatingChannel ().IsSet (), false, "default configuration");
960  }
961  {
962  // case 1:
964  wifi.SetStandard (WIFI_STANDARD_80211a);
965  wifi.SetRemoteStationManager ("ns3::ArfWifiManager");
966  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
967  phySta = GetYansWifiPhyPtr (staDevice);
968  // We expect channel 36, width 20, frequency 5180
969  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 36, "default configuration");
970  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "default configuration");
971  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5180, "default configuration");
972  }
973  {
974  // case 2:
976  wifi.SetStandard (WIFI_STANDARD_80211b);
977  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
978  phySta = GetYansWifiPhyPtr (staDevice);
979  // We expect channel 1, width 22, frequency 2412
980  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 1, "802.11b configuration");
981  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 22, "802.11b configuration");
982  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 2412, "802.11b configuration");
983  }
984  {
985  // case 3:
987  wifi.SetStandard (WIFI_STANDARD_80211g);
988  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
989  phySta = GetYansWifiPhyPtr (staDevice);
990  // We expect channel 1, width 20, frequency 2412
991  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 1, "802.11g configuration");
992  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11g configuration");
993  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 2412, "802.11g configuration");
994  }
995  {
996  // case 4:
998  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
999  wifi.SetStandard (WIFI_STANDARD_80211n);
1000  phy.Set ("ChannelSettings", StringValue ("{0, 0, BAND_5GHZ, 0}"));
1001  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1002  phySta = GetYansWifiPhyPtr (staDevice);
1003  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 36, "802.11n-5GHz configuration");
1004  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11n-5GHz configuration");
1005  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5180, "802.11n-5GHz configuration");
1006  phy.Set ("ChannelSettings", StringValue ("{0, 0, BAND_UNSPECIFIED, 0}")); // restore default
1007  }
1008  {
1009  // case 5:
1010  WifiHelper wifi;
1011  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1012  wifi.SetStandard (WIFI_STANDARD_80211n);
1013  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1014  phySta = GetYansWifiPhyPtr (staDevice);
1015  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 1, "802.11n-2.4GHz configuration");
1016  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11n-2.4GHz configuration");
1017  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 2412, "802.11n-2.4GHz configuration");
1018  }
1019  {
1020  // case 6:
1021  WifiHelper wifi;
1022  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1023  wifi.SetStandard (WIFI_STANDARD_80211ac);
1024  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1025  phySta = GetYansWifiPhyPtr (staDevice);
1026  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 42, "802.11ac configuration");
1027  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 80, "802.11ac configuration");
1028  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5210, "802.11ac configuration");
1029  }
1030  {
1031  // case 7:
1032  // By default, WifiHelper will use WIFI_PHY_STANDARD_80211ax
1033  WifiHelper wifi;
1034  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1035  phy.Set ("ChannelSettings", StringValue ("{0, 0, BAND_2_4GHZ, 0}"));
1036  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1037  phySta = GetYansWifiPhyPtr (staDevice);
1038  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 1, "802.11ax-2.4GHz configuration");
1039  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11ax-2.4GHz configuration");
1040  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 2412, "802.11ax-2.4GHz configuration");
1041  phy.Set ("ChannelSettings", StringValue ("{0, 0, BAND_UNSPECIFIED, 0}")); // restore default
1042  }
1043  {
1044  // case 8:
1045  WifiHelper wifi;
1046  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1047  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1048  phySta = GetYansWifiPhyPtr (staDevice);
1049  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 42, "802.11ax-5GHz configuration");
1050  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 80, "802.11ax-5GHz configuration");
1051  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5210, "802.11ax-5GHz configuration");
1052  }
1053  {
1054  // case 9:
1055  WifiHelper wifi;
1056  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1057  phy.Set ("ChannelSettings", StringValue ("{0, 0, BAND_6GHZ, 0}"));
1058  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1059  phySta = GetYansWifiPhyPtr (staDevice);
1060  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 7, "802.11ax-6GHz configuration");
1061  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 80, "802.11ax-6GHz configuration");
1062  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5975, "802.11ax-6GHz configuration");
1063  phy.Set ("ChannelSettings", StringValue ("{0, 0, BAND_UNSPECIFIED, 0}")); // restore default
1064  }
1065  {
1066  // case 10:
1067  WifiHelper wifi;
1068  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1069  wifi.SetStandard (WIFI_STANDARD_80211p);
1070  phy.Set ("ChannelSettings", StringValue ("{0, 10, BAND_5GHZ, 0}"));
1071  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1072  phySta = GetYansWifiPhyPtr (staDevice);
1073  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 172, "802.11p 10Mhz configuration");
1074  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 10, "802.11p 10Mhz configuration");
1075  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5860, "802.11p 10Mhz configuration");
1076  phy.Set ("ChannelSettings", StringValue ("{0, 0, BAND_UNSPECIFIED, 0}")); // restore default
1077  }
1078  {
1079  // case 11:
1080  WifiHelper wifi;
1081  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1082  wifi.SetStandard (WIFI_STANDARD_80211p);
1083  phy.Set ("ChannelSettings", StringValue ("{0, 5, BAND_5GHZ, 0}"));
1084  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1085  phySta = GetYansWifiPhyPtr (staDevice);
1086  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 171, "802.11p 5Mhz configuration");
1087  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 5, "802.11p 5Mhz configuration");
1088  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5860, "802.11p 5Mhz configuration");
1089  phy.Set ("ChannelSettings", StringValue ("{0, 0, BAND_UNSPECIFIED, 0}")); // restore default
1090  }
1091  {
1092  // case 12:
1093  WifiHelper wifi;
1094  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1095  wifi.SetStandard (WIFI_STANDARD_80211n);
1096  phy.Set ("ChannelSettings", StringValue ("{44, 20, BAND_5GHZ, 0}"));
1097  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1098  phySta = GetYansWifiPhyPtr (staDevice);
1099  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 44, "802.11 5GHz configuration");
1100  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
1101  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5220, "802.11 5GHz configuration");
1102  phy.Set ("ChannelSettings", StringValue ("{0, 0, BAND_UNSPECIFIED, 0}")); // restore default
1103  }
1104  {
1105  // case 13:
1106  WifiHelper wifi;
1107  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1108  phy.Set ("ChannelSettings", StringValue ("{44, 0, BAND_5GHZ, 0}"));
1109  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1110  phySta = GetYansWifiPhyPtr (staDevice);
1111  // Post-install reconfiguration to channel number 40
1112  std::ostringstream path;
1113  path << "/NodeList/*/DeviceList/" << staDevice.Get(0)->GetIfIndex () << "/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/ChannelSettings";
1114  Config::Set (path.str(), StringValue ("{40, 0, BAND_5GHZ, 0}"));
1115  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 40, "802.11 5GHz configuration");
1116  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
1117  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5200, "802.11 5GHz configuration");
1118  phy.Set ("ChannelSettings", StringValue ("{0, 0, BAND_UNSPECIFIED, 0}")); // restore default
1119  }
1120  {
1121  // case 14:
1122  WifiHelper wifi;
1123  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1124  phy.Set ("ChannelSettings", StringValue ("{44, 0, BAND_5GHZ, 0}"));
1125  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1126  phySta = GetYansWifiPhyPtr (staDevice);
1127  // Post-install reconfiguration to a 40 MHz channel
1128  std::ostringstream path;
1129  path << "/NodeList/*/DeviceList/" << staDevice.Get(0)->GetIfIndex () << "/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/ChannelSettings";
1130  Config::Set (path.str(), StringValue ("{46, 0, BAND_5GHZ, 0}"));
1131  // Although channel 44 is configured originally for 20 MHz, we
1132  // allow it to be used for 40 MHz here
1133  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 46, "802.11 5GHz configuration");
1134  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 40, "802.11 5GHz configuration");
1135  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5230, "802.11 5GHz configuration");
1136  phy.Set ("ChannelSettings", StringValue ("{0, 0, BAND_UNSPECIFIED, 0}")); // restore default
1137  }
1138  {
1139  // case 15:
1140  WifiHelper wifi;
1141  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1142  wifi.SetStandard (WIFI_STANDARD_80211n);
1143  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1144  phySta = GetYansWifiPhyPtr (staDevice);
1145  phySta->SetAttribute ("ChannelSettings", StringValue ("{3, 20, BAND_2_4GHZ, 0}"));
1146  return;
1147  // Post-install reconfiguration to a 40 MHz channel
1148  std::ostringstream path;
1149  path << "/NodeList/*/DeviceList/" << staDevice.Get(0)->GetIfIndex () << "/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/ChannelSettings";
1150  Config::Set (path.str(), StringValue ("{4, 40, BAND_2_4GHZ, 0}"));
1151  // Although channel 44 is configured originally for 20 MHz, we
1152  // allow it to be used for 40 MHz here
1153  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 4, "802.11 5GHz configuration");
1154  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 40, "802.11 5GHz configuration");
1155  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 2427, "802.11 5GHz configuration");
1156  phy.Set ("ChannelSettings", StringValue ("{0, 0, BAND_UNSPECIFIED, 0}")); // restore default
1157  }
1158  {
1159  // case 16:
1160  WifiHelper wifi;
1161  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1162  // Test that setting Frequency to a non-standard value will throw an exception
1163  wifi.SetStandard (WIFI_STANDARD_80211n);
1164  phy.Set ("ChannelSettings", StringValue ("{44, 0, BAND_5GHZ, 0}"));
1165  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1166  phySta = GetYansWifiPhyPtr (staDevice);
1167  bool exceptionThrown = false;
1168  try
1169  {
1170  phySta->SetAttribute ("ChannelSettings", StringValue ("{45, 0, BAND_5GHZ, 0}"));
1171  }
1172  catch (const std::runtime_error&)
1173  {
1174  exceptionThrown = true;
1175  }
1176  // We expect that an exception is thrown
1177  NS_TEST_ASSERT_MSG_EQ (exceptionThrown, true, "802.11 5GHz configuration");
1178  }
1179  {
1180  // case 17:
1181  WifiHelper wifi;
1182  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1183  wifi.SetStandard (WIFI_STANDARD_80211n);
1184  phy.Set ("ChannelSettings", StringValue ("{44, 0, BAND_5GHZ, 0}"));
1185  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1186  phySta = GetYansWifiPhyPtr (staDevice);
1187  // Test that setting channel to a standard value will set the
1188  // frequency correctly
1189  phySta->SetAttribute ("ChannelSettings", StringValue ("{100, 0, BAND_5GHZ, 0}"));
1190  // We expect frequency to be 5500 due to channel number being 100
1191  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 100, "802.11 5GHz configuration");
1192  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
1193  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5500, "802.11 5GHz configuration");
1194  }
1195  {
1196  // case 18:
1197  // Set a wrong channel after initialization
1198  WifiHelper wifi;
1199  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1200  wifi.SetStandard (WIFI_STANDARD_80211n);
1201  phy.Set ("ChannelSettings", StringValue ("{44, 0, BAND_5GHZ, 0}"));
1202  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1203  phySta = GetYansWifiPhyPtr (staDevice);
1204  bool exceptionThrown = false;
1205  try
1206  {
1208  }
1209  catch (const std::runtime_error&)
1210  {
1211  exceptionThrown = true;
1212  }
1213  // We expect that an exception is thrown
1214  NS_TEST_ASSERT_MSG_EQ (exceptionThrown, true, "802.11 5GHz configuration");
1215  }
1216  {
1217  // case 19:
1218  WifiHelper wifi;
1219  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1220  // Test how channel number behaves when frequency is non-standard
1221  wifi.SetStandard (WIFI_STANDARD_80211n);
1222  phy.Set ("ChannelSettings", StringValue ("{44, 0, BAND_5GHZ, 0}"));
1223  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1224  phySta = GetYansWifiPhyPtr (staDevice);
1225  bool exceptionThrown = false;
1226  try
1227  {
1228  phySta->SetAttribute ("ChannelSettings", StringValue ("{45, 0, BAND_5GHZ, 0}"));
1229  }
1230  catch (const std::runtime_error&)
1231  {
1232  exceptionThrown = true;
1233  }
1234  // We expect that an exception is thrown due to unknown channel number 45
1235  NS_TEST_ASSERT_MSG_EQ (exceptionThrown, true, "802.11 5GHz configuration");
1236  phySta->SetAttribute ("ChannelSettings", StringValue ("{36, 0, BAND_5GHZ, 0}"));
1237  // We expect channel number to be 36 due to known center frequency 5180
1238  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 36, "802.11 5GHz configuration");
1239  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
1240  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5180, "802.11 5GHz configuration");
1241  exceptionThrown = false;
1242  try
1243  {
1244  phySta->SetAttribute ("ChannelSettings", StringValue ("{43, 0, BAND_5GHZ, 0}"));
1245  }
1246  catch (const std::runtime_error&)
1247  {
1248  exceptionThrown = true;
1249  }
1250  // We expect that an exception is thrown due to unknown channel number 43
1251  NS_TEST_ASSERT_MSG_EQ (exceptionThrown, true, "802.11 5GHz configuration");
1252  phySta->SetAttribute ("ChannelSettings", StringValue ("{36, 0, BAND_5GHZ, 0}"));
1253  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 36, "802.11 5GHz configuration");
1254  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
1255  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5180, "802.11 5GHz configuration");
1256  }
1257  {
1258  // case 20:
1259  WifiHelper wifi;
1260  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1261  phy.Set ("ChannelSettings", StringValue ("{40, 0, BAND_5GHZ, 0}"));
1262  wifi.SetStandard (WIFI_STANDARD_80211n);
1263  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1264  phySta = GetYansWifiPhyPtr (staDevice);
1265  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 40, "802.11 5GHz configuration");
1266  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
1267  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5200, "802.11 5GHz configuration");
1268  // Set both channel and frequency to consistent values after initialization
1269  wifi.SetStandard (WIFI_STANDARD_80211n);
1270  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1271  phySta = GetYansWifiPhyPtr (staDevice);
1272  phySta->SetAttribute ("ChannelSettings", StringValue ("{40, 0, BAND_5GHZ, 0}"));
1273  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 40, "802.11 5GHz configuration");
1274  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
1275  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5200, "802.11 5GHz configuration");
1276 
1277  phySta->SetAttribute ("ChannelSettings", StringValue ("{36, 0, BAND_5GHZ, 0}"));
1278  // We expect channel number to be 36
1279  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 36, "802.11 5GHz configuration");
1280  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
1281  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5180, "802.11 5GHz configuration");
1282  phySta->SetAttribute ("ChannelSettings", StringValue ("{40, 0, BAND_5GHZ, 0}"));
1283  // We expect channel number to be 40
1284  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 40, "802.11 5GHz configuration");
1285  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
1286  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5200, "802.11 5GHz configuration");
1287  bool exceptionThrown = false;
1288  try
1289  {
1290  phySta->SetAttribute ("ChannelSettings", StringValue ("{45, 0, BAND_5GHZ, 0}"));
1291  }
1292  catch (const std::runtime_error&)
1293  {
1294  exceptionThrown = true;
1295  }
1296  phySta->SetAttribute ("ChannelSettings", StringValue ("{36, 0, BAND_5GHZ, 0}"));
1297  // We expect channel number to be 36 and an exception to be thrown
1298  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 36, "802.11 5GHz configuration");
1299  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
1300  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5180, "802.11 5GHz configuration");
1301  NS_TEST_ASSERT_MSG_EQ (exceptionThrown, true, "802.11 5GHz configuration");
1302  phySta->SetAttribute ("ChannelSettings", StringValue ("{36, 0, BAND_5GHZ, 0}"));
1303  exceptionThrown = false;
1304  try
1305  {
1306  phySta->SetAttribute ("ChannelSettings", StringValue ("{43, 0, BAND_5GHZ, 0}"));
1307  }
1308  catch (const std::runtime_error&)
1309  {
1310  exceptionThrown = true;
1311  }
1312  // We expect channel number to be 36 and an exception to be thrown
1313  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 36, "802.11 5GHz configuration");
1314  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
1315  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5180, "802.11 5GHz configuration");
1316  NS_TEST_ASSERT_MSG_EQ (exceptionThrown, true, "802.11 5GHz configuration");
1317  }
1318 
1319  Simulator::Destroy ();
1320 }
1321 
1322 //-----------------------------------------------------------------------------
1331 {
1332 public:
1333  Bug2222TestCase ();
1334  virtual ~Bug2222TestCase ();
1335 
1336  void DoRun (void) override;
1337 
1338 
1339 private:
1341 
1347  void TxDataFailedTrace (std::string context, Mac48Address adr);
1348 };
1349 
1351  : TestCase ("Test case for Bug 2222"),
1352  m_countInternalCollisions (0)
1353 {
1354 }
1355 
1357 {
1358 }
1359 
1360 void
1362 {
1363  //Indicate the long retry counter has been increased in the wifi remote station manager
1365 }
1366 
1367 void
1369 {
1371 
1372  //Generate same backoff for AC_VI and AC_VO
1373  //The below combination will work
1374  RngSeedManager::SetSeed (1);
1375  RngSeedManager::SetRun (1);
1376  int64_t streamNumber = 100;
1377 
1378  NodeContainer wifiNodes;
1379  wifiNodes.Create (2);
1380 
1381  YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
1383  phy.SetChannel (channel.Create ());
1384 
1385  WifiHelper wifi;
1386  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
1387  "DataMode", StringValue ("OfdmRate54Mbps"),
1388  "ControlMode", StringValue ("OfdmRate24Mbps"));
1390  Ssid ssid = Ssid ("ns-3-ssid");
1391  mac.SetType ("ns3::AdhocWifiMac",
1392  "QosSupported", BooleanValue (true));
1393 
1394  NetDeviceContainer wifiDevices;
1395  wifiDevices = wifi.Install (phy, mac, wifiNodes);
1396 
1397  // Assign fixed streams to random variables in use
1398  wifi.AssignStreams (wifiDevices, streamNumber);
1399 
1401  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
1402 
1403  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
1404  positionAlloc->Add (Vector (10.0, 0.0, 0.0));
1405  mobility.SetPositionAllocator (positionAlloc);
1406 
1407  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
1408  mobility.Install (wifiNodes);
1409 
1410  Ptr<WifiNetDevice> device1 = DynamicCast<WifiNetDevice> (wifiDevices.Get (0));
1411  Ptr<WifiNetDevice> device2 = DynamicCast<WifiNetDevice> (wifiDevices.Get (1));
1412 
1413  PacketSocketAddress socket;
1414  socket.SetSingleDevice (device1->GetIfIndex ());
1415  socket.SetPhysicalAddress (device2->GetAddress ());
1416  socket.SetProtocol (1);
1417 
1418  PacketSocketHelper packetSocket;
1419  packetSocket.Install (wifiNodes);
1420 
1421  Ptr<PacketSocketClient> clientLowPriority = CreateObject<PacketSocketClient> ();
1422  clientLowPriority->SetAttribute ("PacketSize", UintegerValue (1460));
1423  clientLowPriority->SetAttribute ("MaxPackets", UintegerValue (1));
1424  clientLowPriority->SetAttribute ("Priority", UintegerValue (4)); //AC_VI
1425  clientLowPriority->SetRemote (socket);
1426  wifiNodes.Get (0)->AddApplication (clientLowPriority);
1427  clientLowPriority->SetStartTime (Seconds (0.0));
1428  clientLowPriority->SetStopTime (Seconds (1.0));
1429 
1430  Ptr<PacketSocketClient> clientHighPriority = CreateObject<PacketSocketClient> ();
1431  clientHighPriority->SetAttribute ("PacketSize", UintegerValue (1460));
1432  clientHighPriority->SetAttribute ("MaxPackets", UintegerValue (1));
1433  clientHighPriority->SetAttribute ("Priority", UintegerValue (6)); //AC_VO
1434  clientHighPriority->SetRemote (socket);
1435  wifiNodes.Get (0)->AddApplication (clientHighPriority);
1436  clientHighPriority->SetStartTime (Seconds (0.0));
1437  clientHighPriority->SetStopTime (Seconds (1.0));
1438 
1439  Ptr<PacketSocketServer> server = CreateObject<PacketSocketServer> ();
1440  server->SetLocal (socket);
1441  wifiNodes.Get (1)->AddApplication (server);
1442  server->SetStartTime (Seconds (0.0));
1443  server->SetStopTime (Seconds (1.0));
1444 
1445  Config::Connect ("/NodeList/*/DeviceList/*/RemoteStationManager/MacTxDataFailed", MakeCallback (&Bug2222TestCase::TxDataFailedTrace, this));
1446 
1447  Simulator::Stop (Seconds (1.0));
1448  Simulator::Run ();
1449  Simulator::Destroy ();
1450 
1451  NS_TEST_ASSERT_MSG_EQ (m_countInternalCollisions, 1, "unexpected number of internal collisions!");
1452 }
1453 
1454 //-----------------------------------------------------------------------------
1468 {
1469 public:
1470  Bug2843TestCase ();
1471  virtual ~Bug2843TestCase ();
1472  void DoRun (void) override;
1473 
1474 private:
1478  typedef std::tuple<double, uint16_t, uint32_t, WifiModulationClass> FreqWidthSubbandModulationTuple;
1479  std::vector<FreqWidthSubbandModulationTuple> m_distinctTuples;
1480 
1487  void StoreDistinctTuple (std::string context, Ptr<SpectrumSignalParameters> txParams);
1494  void SendPacketBurst (uint8_t numPackets, Ptr<NetDevice> sourceDevice, Address& destination) const;
1495 
1496  uint16_t m_channelWidth;
1497 };
1498 
1500  : TestCase ("Test case for Bug 2843"),
1501  m_channelWidth (20)
1502 {
1503 }
1504 
1506 {
1507 }
1508 
1509 void
1511 {
1512  // Extract starting frequency and number of subbands
1513  Ptr<const SpectrumModel> c = txParams->psd->GetSpectrumModel ();
1514  std::size_t numBands = c->GetNumBands ();
1515  double startingFreq = c->Begin ()->fl;
1516 
1517  // Get channel bandwidth and modulation class
1518  Ptr<const WifiSpectrumSignalParameters> wifiTxParams = DynamicCast<WifiSpectrumSignalParameters> (txParams);
1519 
1520  Ptr<WifiPpdu> ppdu = wifiTxParams->ppdu->Copy ();
1521  WifiTxVector txVector = ppdu->GetTxVector ();
1522  m_channelWidth = txVector.GetChannelWidth ();
1523  WifiModulationClass modulationClass = txVector.GetMode ().GetModulationClass ();
1524 
1525  // Build a tuple and check if seen before (if so store it)
1526  FreqWidthSubbandModulationTuple tupleForCurrentTx = std::make_tuple (startingFreq, m_channelWidth, numBands, modulationClass);
1527  bool found = false;
1528  for (std::vector<FreqWidthSubbandModulationTuple>::const_iterator it = m_distinctTuples.begin (); it != m_distinctTuples.end (); it++)
1529  {
1530  if (*it == tupleForCurrentTx)
1531  {
1532  found = true;
1533  }
1534  }
1535  if (!found)
1536  {
1537  m_distinctTuples.push_back (tupleForCurrentTx);
1538  }
1539 }
1540 
1541 void
1542 Bug2843TestCase::SendPacketBurst (uint8_t numPackets, Ptr<NetDevice> sourceDevice,
1543  Address& destination) const
1544 {
1545  for (uint8_t i = 0; i < numPackets; i++)
1546  {
1547  Ptr<Packet> pkt = Create<Packet> (1000); // 1000 dummy bytes of data
1548  sourceDevice->Send (pkt, destination, 0);
1549  }
1550 }
1551 
1552 void
1554 {
1555  uint16_t channelWidth = 40; // at least 40 MHz expected here
1556 
1557  NodeContainer wifiStaNode;
1558  wifiStaNode.Create (1);
1559 
1561  wifiApNode.Create (1);
1562 
1563  SpectrumWifiPhyHelper spectrumPhy;
1564  Ptr<MultiModelSpectrumChannel> spectrumChannel = CreateObject<MultiModelSpectrumChannel> ();
1565  Ptr<FriisPropagationLossModel> lossModel = CreateObject<FriisPropagationLossModel> ();
1566  lossModel->SetFrequency (5.190e9);
1567  spectrumChannel->AddPropagationLossModel (lossModel);
1568 
1570  = CreateObject<ConstantSpeedPropagationDelayModel> ();
1571  spectrumChannel->SetPropagationDelayModel (delayModel);
1572 
1573  spectrumPhy.SetChannel (spectrumChannel);
1574  spectrumPhy.SetErrorRateModel ("ns3::NistErrorRateModel");
1575  spectrumPhy.Set ("ChannelSettings", StringValue ("{38, 40, BAND_5GHZ, 0}"));
1576  spectrumPhy.Set ("TxPowerStart", DoubleValue (10));
1577  spectrumPhy.Set ("TxPowerEnd", DoubleValue (10));
1578 
1579  WifiHelper wifi;
1580  wifi.SetStandard (WIFI_STANDARD_80211ac);
1581  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
1582  "DataMode", StringValue ("VhtMcs8"),
1583  "ControlMode", StringValue ("VhtMcs8"),
1584  "RtsCtsThreshold", StringValue ("500")); // so as to force RTS/CTS for data frames
1585 
1587  mac.SetType ("ns3::StaWifiMac");
1588  NetDeviceContainer staDevice;
1589  staDevice = wifi.Install (spectrumPhy, mac, wifiStaNode);
1590 
1591  mac.SetType ("ns3::ApWifiMac");
1592  NetDeviceContainer apDevice;
1593  apDevice = wifi.Install (spectrumPhy, mac, wifiApNode);
1594 
1596  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
1597  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
1598  positionAlloc->Add (Vector (1.0, 0.0, 0.0)); // put close enough in order to use MCS
1599  mobility.SetPositionAllocator (positionAlloc);
1600 
1601  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
1602  mobility.Install (wifiApNode);
1603  mobility.Install (wifiStaNode);
1604 
1605  // Send two 5 packet-bursts
1606  Simulator::Schedule (Seconds (0.5), &Bug2843TestCase::SendPacketBurst, this, 5, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
1607  Simulator::Schedule (Seconds (0.6), &Bug2843TestCase::SendPacketBurst, this, 5, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
1608 
1609  Config::Connect ("/ChannelList/*/$ns3::MultiModelSpectrumChannel/TxSigParams", MakeCallback (&Bug2843TestCase::StoreDistinctTuple, this));
1610 
1611  Simulator::Stop (Seconds (0.8));
1612  Simulator::Run ();
1613 
1614  Simulator::Destroy ();
1615 
1616  // {starting frequency, channelWidth, Number of subbands in SpectrumModel, modulation type} tuples
1617  std::size_t numberTuples = m_distinctTuples.size ();
1618  NS_TEST_ASSERT_MSG_EQ (numberTuples, 2, "Only two distinct tuples expected");
1619  NS_TEST_ASSERT_MSG_EQ (std::get<0> (m_distinctTuples[0]) - 20e6, std::get<0> (m_distinctTuples[1]), "The starting frequency of the first tuple should be shifted 20 MHz to the right wrt second tuple");
1620  // Note that the first tuple should the one initiated by the beacon, i.e. non-HT OFDM (20 MHz)
1621  NS_TEST_ASSERT_MSG_EQ (std::get<1> (m_distinctTuples[0]), 20, "First tuple's channel width should be 20 MHz");
1622  NS_TEST_ASSERT_MSG_EQ (std::get<2> (m_distinctTuples[0]), 193, "First tuple should have 193 subbands (64+DC, 20MHz+DC, inband and 64*2 out-of-band, 20MHz on each side)");
1623  NS_TEST_ASSERT_MSG_EQ (std::get<3> (m_distinctTuples[0]), WifiModulationClass::WIFI_MOD_CLASS_OFDM, "First tuple should be OFDM");
1624  // Second tuple
1625  NS_TEST_ASSERT_MSG_EQ (std::get<1> (m_distinctTuples[1]), channelWidth, "Second tuple's channel width should be 40 MHz");
1626  NS_TEST_ASSERT_MSG_EQ (std::get<2> (m_distinctTuples[1]), 385, "Second tuple should have 385 subbands (128+DC, 40MHz+DC, inband and 128*2 out-of-band, 40MHz on each side)");
1627  NS_TEST_ASSERT_MSG_EQ (std::get<3> (m_distinctTuples[1]), WifiModulationClass::WIFI_MOD_CLASS_VHT, "Second tuple should be VHT_OFDM");
1628 }
1629 
1630 //-----------------------------------------------------------------------------
1643 {
1644 public:
1645  Bug2831TestCase ();
1646  virtual ~Bug2831TestCase ();
1647  void DoRun (void) override;
1648 
1649 private:
1653  void ChangeSupportedChannelWidth (void);
1660  void RxCallback (std::string context, Ptr<const Packet> p, RxPowerWattPerChannelBand rxPowersW);
1661 
1664 
1665  uint16_t m_assocReqCount;
1666  uint16_t m_assocRespCount;
1669 };
1670 
1672  : TestCase ("Test case for Bug 2831"),
1673  m_assocReqCount (0),
1674  m_assocRespCount (0),
1675  m_countOperationalChannelWidth20 (0),
1676  m_countOperationalChannelWidth40 (0)
1677 {
1678 }
1679 
1681 {
1682 }
1683 
1684 void
1686 {
1689 }
1690 
1691 void
1693 {
1694  Ptr<Packet> packet = p->Copy ();
1695  WifiMacHeader hdr;
1696  packet->RemoveHeader (hdr);
1697  if (hdr.IsAssocReq ())
1698  {
1699  m_assocReqCount++;
1700  }
1701  else if (hdr.IsAssocResp ())
1702  {
1703  m_assocRespCount++;
1704  }
1705  else if (hdr.IsBeacon ())
1706  {
1707  MgtBeaconHeader beacon;
1708  packet->RemoveHeader (beacon);
1709  HtOperation htOperation = beacon.GetHtOperation ();
1710  if (htOperation.GetStaChannelWidth () > 0)
1711  {
1713  }
1714  else
1715  {
1717  }
1718  }
1719 }
1720 
1721 void
1723 {
1724  Ptr<YansWifiChannel> channel = CreateObject<YansWifiChannel> ();
1725  ObjectFactory propDelay;
1726  propDelay.SetTypeId ("ns3::ConstantSpeedPropagationDelayModel");
1727  Ptr<PropagationDelayModel> propagationDelay = propDelay.Create<PropagationDelayModel> ();
1728  Ptr<PropagationLossModel> propagationLoss = CreateObject<FriisPropagationLossModel> ();
1729  channel->SetPropagationDelayModel (propagationDelay);
1730  channel->SetPropagationLossModel (propagationLoss);
1731 
1732  Ptr<Node> apNode = CreateObject<Node> ();
1733  Ptr<WifiNetDevice> apDev = CreateObject<WifiNetDevice> ();
1735  Ptr<HtConfiguration> apHtConfiguration = CreateObject<HtConfiguration> ();
1736  apDev->SetHtConfiguration (apHtConfiguration);
1738  mac.SetTypeId ("ns3::ApWifiMac");
1739  mac.Set ("EnableBeaconJitter", BooleanValue (false));
1740  mac.Set ("QosSupported", BooleanValue (true));
1741  Ptr<WifiMac> apMac = mac.Create<WifiMac> ();
1742  apMac->SetDevice (apDev);
1743  apMac->SetAddress (Mac48Address::Allocate ());
1744  apMac->ConfigureStandard (WIFI_STANDARD_80211ax);
1745  Ptr<FrameExchangeManager> fem = apMac->GetFrameExchangeManager ();
1746  Ptr<WifiProtectionManager> protectionManager = CreateObject<WifiDefaultProtectionManager> ();
1747  protectionManager->SetWifiMac (apMac);
1748  fem->SetProtectionManager (protectionManager);
1749  Ptr<WifiAckManager> ackManager = CreateObject<WifiDefaultAckManager> ();
1750  ackManager->SetWifiMac (apMac);
1751  fem->SetAckManager (ackManager);
1752 
1753  Ptr<Node> staNode = CreateObject<Node> ();
1754  Ptr<WifiNetDevice> staDev = CreateObject<WifiNetDevice> ();
1756  Ptr<HtConfiguration> staHtConfiguration = CreateObject<HtConfiguration> ();
1757  staDev->SetHtConfiguration (staHtConfiguration);
1758  mac.SetTypeId ("ns3::StaWifiMac");
1759  Ptr<WifiMac> staMac = mac.Create<WifiMac> ();
1760  staMac->SetDevice (staDev);
1761  staMac->SetAddress (Mac48Address::Allocate ());
1762  staMac->ConfigureStandard (WIFI_STANDARD_80211ax);
1763  fem = staMac->GetFrameExchangeManager ();
1764  protectionManager = CreateObject<WifiDefaultProtectionManager> ();
1765  protectionManager->SetWifiMac (staMac);
1766  fem->SetProtectionManager (protectionManager);
1767  ackManager = CreateObject<WifiDefaultAckManager> ();
1768  ackManager->SetWifiMac (staMac);
1769  fem->SetAckManager (ackManager);
1770 
1771  Ptr<ConstantPositionMobilityModel> apMobility = CreateObject<ConstantPositionMobilityModel> ();
1772  apMobility->SetPosition (Vector (0.0, 0.0, 0.0));
1773  apNode->AggregateObject (apMobility);
1774 
1775  m_apPhy = CreateObject<YansWifiPhy> ();
1776  Ptr<InterferenceHelper> apInterferenceHelper = CreateObject<InterferenceHelper> ();
1777  m_apPhy->SetInterferenceHelper (apInterferenceHelper);
1778  Ptr<ErrorRateModel> apErrorModel = CreateObject<YansErrorRateModel> ();
1779  m_apPhy->SetErrorRateModel (apErrorModel);
1781  m_apPhy->SetMobility (apMobility);
1782  m_apPhy->SetDevice (apDev);
1785 
1786  Ptr<ConstantPositionMobilityModel> staMobility = CreateObject<ConstantPositionMobilityModel> ();
1787  staMobility->SetPosition (Vector (1.0, 0.0, 0.0));
1788  staNode->AggregateObject (staMobility);
1789 
1790  m_staPhy = CreateObject<YansWifiPhy> ();
1791  Ptr<InterferenceHelper> staInterferenceHelper = CreateObject<InterferenceHelper> ();
1792  m_staPhy->SetInterferenceHelper (staInterferenceHelper);
1793  Ptr<ErrorRateModel> staErrorModel = CreateObject<YansErrorRateModel> ();
1794  m_staPhy->SetErrorRateModel (staErrorModel);
1796  m_staPhy->SetMobility (staMobility);
1797  m_staPhy->SetDevice (apDev);
1800 
1801  apDev->SetMac (apMac);
1802  apDev->SetPhy (m_apPhy);
1803  ObjectFactory manager;
1804  manager.SetTypeId ("ns3::ConstantRateWifiManager");
1806  apNode->AddDevice (apDev);
1807 
1808  staDev->SetMac (staMac);
1809  staDev->SetPhy (m_staPhy);
1811  staNode->AddDevice (staDev);
1812 
1813  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::WifiPhy/PhyRxBegin", MakeCallback (&Bug2831TestCase::RxCallback, this));
1814 
1815  Simulator::Schedule (Seconds (1.0), &Bug2831TestCase::ChangeSupportedChannelWidth, this);
1816 
1817  Simulator::Stop (Seconds (3.0));
1818  Simulator::Run ();
1819  Simulator::Destroy ();
1820 
1821  NS_TEST_ASSERT_MSG_EQ (m_assocReqCount, 2, "Second Association request not received");
1822  NS_TEST_ASSERT_MSG_EQ (m_assocRespCount, 2, "Second Association response not received");
1823  NS_TEST_ASSERT_MSG_EQ (m_countOperationalChannelWidth20, 10, "Incorrect operational channel width before channel change");
1824  NS_TEST_ASSERT_MSG_EQ (m_countOperationalChannelWidth40, 20, "Incorrect operational channel width after channel change");
1825 }
1826 
1827 //-----------------------------------------------------------------------------
1844 {
1845 public:
1847  virtual ~StaWifiMacScanningTestCase ();
1848  void DoRun (void) override;
1849 
1850 private:
1856  void AssocCallback (std::string context, Mac48Address bssid);
1861  void TurnBeaconGenerationOn (Ptr<Node> apNode);
1866  void TurnApOff (Ptr<Node> apNode);
1873  NodeContainer Setup (bool nearestApBeaconGeneration, bool staActiveProbe);
1874 
1876 };
1877 
1879  : TestCase ("Test case for StaWifiMac scanning capability")
1880 {
1881 }
1882 
1884 {
1885 }
1886 
1887 void
1889 {
1890  m_associatedApBssid = bssid;
1891 }
1892 
1893 void
1895 {
1896  Ptr<WifiNetDevice> netDevice = DynamicCast<WifiNetDevice> (apNode->GetDevice (0));
1897  Ptr<ApWifiMac> mac = DynamicCast<ApWifiMac> (netDevice->GetMac ());
1898  mac->SetAttribute ("BeaconGeneration", BooleanValue (true));
1899 }
1900 
1901 void
1903 {
1904  Ptr<WifiNetDevice> netDevice = DynamicCast<WifiNetDevice> (apNode->GetDevice (0));
1905  Ptr<WifiPhy> phy = netDevice->GetPhy ();
1906  phy->SetOffMode ();
1907 }
1908 
1910 StaWifiMacScanningTestCase::Setup (bool nearestApBeaconGeneration, bool staActiveProbe)
1911 {
1912  RngSeedManager::SetSeed (1);
1913  RngSeedManager::SetRun (1);
1914  int64_t streamNumber = 1;
1915 
1916  NodeContainer apNodes;
1917  apNodes.Create (2);
1918 
1919  Ptr<Node> apNodeNearest = CreateObject<Node> ();
1920  Ptr<Node> staNode = CreateObject<Node> ();
1921 
1923  YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
1924  phy.SetChannel (channel.Create ());
1925 
1926  WifiHelper wifi;
1927  wifi.SetStandard (WIFI_STANDARD_80211n);
1928  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager");
1929 
1931  NetDeviceContainer apDevice, apDeviceNearest;
1932  mac.SetType ("ns3::ApWifiMac",
1933  "BeaconGeneration", BooleanValue (true));
1934  apDevice = wifi.Install (phy, mac, apNodes);
1935  mac.SetType ("ns3::ApWifiMac",
1936  "BeaconGeneration", BooleanValue (nearestApBeaconGeneration));
1937  apDeviceNearest = wifi.Install (phy, mac, apNodeNearest);
1938 
1939  NetDeviceContainer staDevice;
1940  mac.SetType ("ns3::StaWifiMac",
1941  "ActiveProbing", BooleanValue (staActiveProbe));
1942  staDevice = wifi.Install (phy, mac, staNode);
1943 
1944  // Assign fixed streams to random variables in use
1945  wifi.AssignStreams (apDevice, streamNumber);
1946  wifi.AssignStreams (apDeviceNearest, streamNumber + 1);
1947  wifi.AssignStreams (staDevice, streamNumber + 2);
1948 
1950  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
1951  positionAlloc->Add (Vector (0.0, 0.0, 0.0)); // Furthest AP
1952  positionAlloc->Add (Vector (10.0, 0.0, 0.0)); // Second nearest AP
1953  positionAlloc->Add (Vector (5.0, 5.0, 0.0)); // Nearest AP
1954  positionAlloc->Add (Vector (6.0, 5.0, 0.0)); // STA
1955  mobility.SetPositionAllocator (positionAlloc);
1956 
1957  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
1958  mobility.Install (apNodes);
1959  mobility.Install (apNodeNearest);
1960  mobility.Install (staNode);
1961 
1962  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/$ns3::StaWifiMac/Assoc", MakeCallback (&StaWifiMacScanningTestCase::AssocCallback, this));
1963 
1964  NodeContainer allNodes = NodeContainer (apNodes, apNodeNearest, staNode);
1965  return allNodes;
1966 }
1967 
1968 void
1970 {
1971  {
1972  NodeContainer nodes = Setup (false, false);
1973  Ptr<Node> nearestAp = nodes.Get (2);
1974  Mac48Address nearestApAddr = DynamicCast<WifiNetDevice> (nearestAp->GetDevice (0))->GetMac ()->GetAddress ();
1975 
1976  Simulator::Schedule (Seconds (0.05), &StaWifiMacScanningTestCase::TurnBeaconGenerationOn, this, nearestAp);
1977 
1978  Simulator::Stop (Seconds (0.2));
1979  Simulator::Run ();
1980  Simulator::Destroy ();
1981 
1982  NS_TEST_ASSERT_MSG_EQ (m_associatedApBssid, nearestApAddr, "STA is associated to the wrong AP");
1983  }
1985  {
1986  NodeContainer nodes = Setup (true, true);
1987  Ptr<Node> nearestAp = nodes.Get (2);
1988  Mac48Address nearestApAddr = DynamicCast<WifiNetDevice> (nearestAp->GetDevice (0))->GetMac ()->GetAddress ();
1989 
1990  Simulator::Stop (Seconds (0.2));
1991  Simulator::Run ();
1992  Simulator::Destroy ();
1993 
1994  NS_TEST_ASSERT_MSG_EQ (m_associatedApBssid, nearestApAddr, "STA is associated to the wrong AP");
1995  }
1997  {
1998  NodeContainer nodes = Setup (true, false);
1999  Ptr<Node> nearestAp = nodes.Get (2);
2000  Mac48Address secondNearestApAddr = DynamicCast<WifiNetDevice> (nodes.Get (1)->GetDevice (0))->GetMac ()->GetAddress ();
2001 
2002  Simulator::Schedule (Seconds (0.1), &StaWifiMacScanningTestCase::TurnApOff, this, nearestAp);
2003 
2004  Simulator::Stop (Seconds (1.5));
2005  Simulator::Run ();
2006  Simulator::Destroy ();
2007 
2008  NS_TEST_ASSERT_MSG_EQ (m_associatedApBssid, secondNearestApAddr, "STA is associated to the wrong AP");
2009  }
2010 }
2011 
2012 //-----------------------------------------------------------------------------
2036 {
2037 public:
2038  Bug2470TestCase ();
2039  virtual ~Bug2470TestCase ();
2040  void DoRun (void) override;
2041 
2042 private:
2051  void AddbaStateChangedCallback (std::string context, Time t, Mac48Address recipient, uint8_t tid, OriginatorBlockAckAgreement::State state);
2062  void RxCallback (std::string context, Ptr<const Packet> p, uint16_t channelFreqMhz, WifiTxVector txVector, MpduInfo aMpdu, SignalNoiseDbm signalNoise, uint16_t staId);
2069  void RxErrorCallback (std::string context, Ptr<const Packet> p, double snr);
2076  void SendPacketBurst (uint32_t numPackets, Ptr<NetDevice> sourceDevice, Address& destination) const;
2082  void RunSubtest (PointerValue apErrorModel, PointerValue staErrorModel);
2083 
2092 };
2093 
2095  : TestCase ("Test case for Bug 2470"),
2096  m_receivedNormalMpduCount (0),
2097  m_receivedAmpduCount (0),
2098  m_failedActionCount (0),
2099  m_addbaEstablishedCount (0),
2100  m_addbaPendingCount (0),
2101  m_addbaRejectedCount (0),
2102  m_addbaNoReplyCount (0),
2103  m_addbaResetCount (0)
2104 {
2105 }
2106 
2108 {
2109 }
2110 
2111 void
2113 {
2114  switch (state)
2115  {
2116  case OriginatorBlockAckAgreement::ESTABLISHED:
2118  break;
2119  case OriginatorBlockAckAgreement::PENDING:
2121  break;
2122  case OriginatorBlockAckAgreement::REJECTED:
2124  break;
2125  case OriginatorBlockAckAgreement::NO_REPLY:
2127  break;
2128  case OriginatorBlockAckAgreement::RESET:
2130  break;
2131  }
2132 }
2133 
2134 void
2135 Bug2470TestCase::RxCallback (std::string context, Ptr<const Packet> p, uint16_t channelFreqMhz, WifiTxVector txVector, MpduInfo aMpdu, SignalNoiseDbm signalNoise, uint16_t staId)
2136 {
2137  Ptr<Packet> packet = p->Copy ();
2138  if (aMpdu.type != MpduType::NORMAL_MPDU)
2139  {
2141  }
2142  else
2143  {
2144  WifiMacHeader hdr;
2145  packet->RemoveHeader (hdr);
2146  if (hdr.IsData ())
2147  {
2149  }
2150  }
2151 }
2152 
2153 void
2154 Bug2470TestCase::RxErrorCallback (std::string context, Ptr<const Packet> p, double snr)
2155 {
2156  Ptr<Packet> packet = p->Copy ();
2157  WifiMacHeader hdr;
2158  packet->RemoveHeader (hdr);
2159  if (hdr.IsAction ())
2160  {
2162  }
2163 }
2164 
2165 void
2166 Bug2470TestCase::SendPacketBurst (uint32_t numPackets, Ptr<NetDevice> sourceDevice,
2167  Address& destination) const
2168 {
2169  for (uint32_t i = 0; i < numPackets; i++)
2170  {
2171  Ptr<Packet> pkt = Create<Packet> (1000); // 1000 dummy bytes of data
2172  sourceDevice->Send (pkt, destination, 0);
2173  }
2174 }
2175 
2176 void
2178 {
2179  RngSeedManager::SetSeed (1);
2180  RngSeedManager::SetRun (1);
2181  int64_t streamNumber = 200;
2182 
2183  NodeContainer wifiApNode, wifiStaNode;
2184  wifiApNode.Create (1);
2185  wifiStaNode.Create (1);
2186 
2188  YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
2189  phy.SetChannel (channel.Create ());
2190 
2191  WifiHelper wifi;
2192  wifi.SetStandard (WIFI_STANDARD_80211n);
2193  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
2194  "DataMode", StringValue ("HtMcs7"),
2195  "ControlMode", StringValue ("HtMcs7"));
2196 
2198  NetDeviceContainer apDevice;
2199  phy.Set ("PostReceptionErrorModel", apErrorModel);
2200  phy.Set ("ChannelSettings", StringValue ("{36, 20, BAND_5GHZ, 0}"));
2201  mac.SetType ("ns3::ApWifiMac", "EnableBeaconJitter", BooleanValue (false));
2202  apDevice = wifi.Install (phy, mac, wifiApNode);
2203 
2204  NetDeviceContainer staDevice;
2205  phy.Set ("PostReceptionErrorModel", staErrorModel);
2206  mac.SetType ("ns3::StaWifiMac");
2207  staDevice = wifi.Install (phy, mac, wifiStaNode);
2208 
2209  // Assign fixed streams to random variables in use
2210  wifi.AssignStreams (apDevice, streamNumber);
2211  wifi.AssignStreams (staDevice, streamNumber);
2212 
2214  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
2215  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
2216  positionAlloc->Add (Vector (1.0, 0.0, 0.0));
2217  mobility.SetPositionAllocator (positionAlloc);
2218 
2219  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
2220  mobility.Install (wifiApNode);
2221  mobility.Install (wifiStaNode);
2222 
2223  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::WifiPhy/MonitorSnifferRx", MakeCallback (&Bug2470TestCase::RxCallback, this));
2224  Config::Connect ("/NodeList/*/DeviceList/*/Phy/State/RxError", MakeCallback (&Bug2470TestCase::RxErrorCallback, this));
2225  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/$ns3::WifiMac/BE_Txop/BlockAckManager/AgreementState", MakeCallback (&Bug2470TestCase::AddbaStateChangedCallback, this));
2226 
2227  Simulator::Schedule (Seconds (0.5), &Bug2470TestCase::SendPacketBurst, this, 1, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2228  Simulator::Schedule (Seconds (0.5) + MicroSeconds (5), &Bug2470TestCase::SendPacketBurst, this, 4, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2229  Simulator::Schedule (Seconds (0.8), &Bug2470TestCase::SendPacketBurst, this, 1, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2230  Simulator::Schedule (Seconds (0.8) + MicroSeconds (5), &Bug2470TestCase::SendPacketBurst, this, 4, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2231 
2232  Simulator::Stop (Seconds (1.0));
2233  Simulator::Run ();
2234  Simulator::Destroy ();
2235 }
2236 
2237 void
2239 {
2240  // Create ReceiveListErrorModel to corrupt ADDBA req packet. We use ReceiveListErrorModel
2241  // instead of ListErrorModel since packet UID is incremented between simulations. But
2242  // problem may occur because of random stream, therefore we suppress usage of RNG as
2243  // much as possible (i.e., removing beacon jitter).
2244  Ptr<ReceiveListErrorModel> staPem = CreateObject<ReceiveListErrorModel> ();
2245  std::list<uint32_t> blackList;
2246  // Block ADDBA request 6 times (== maximum number of MAC frame transmissions in the ADDBA response timeout interval)
2247  blackList.push_back (9);
2248  blackList.push_back (10);
2249  blackList.push_back (11);
2250  blackList.push_back (12);
2251  blackList.push_back (13);
2252  blackList.push_back (14);
2253  staPem->SetList (blackList);
2254 
2255  {
2256  RunSubtest (PointerValue (), PointerValue (staPem));
2257  NS_TEST_ASSERT_MSG_EQ (m_failedActionCount, 6, "ADDBA request packets are not failed");
2258  // There are two sets of 5 packets to be transmitted. The first 5 packets should be sent by normal
2259  // MPDU because of failed ADDBA handshake. For the second set, the first packet should be sent by
2260  // normal MPDU, and the rest with A-MPDU. In total we expect to receive 2 normal MPDU packets and
2261  // 8 A-MPDU packets.
2262  NS_TEST_ASSERT_MSG_EQ (m_receivedNormalMpduCount, 2, "Receiving incorrect number of normal MPDU packet on subtest 1");
2263  NS_TEST_ASSERT_MSG_EQ (m_receivedAmpduCount, 8, "Receiving incorrect number of A-MPDU packet on subtest 1");
2264 
2265  NS_TEST_ASSERT_MSG_EQ (m_addbaEstablishedCount, 1, "Incorrect number of times the ADDBA state machine was in established state on subtest 1");
2266  NS_TEST_ASSERT_MSG_EQ (m_addbaPendingCount, 1, "Incorrect number of times the ADDBA state machine was in pending state on subtest 1");
2267  NS_TEST_ASSERT_MSG_EQ (m_addbaRejectedCount, 0, "Incorrect number of times the ADDBA state machine was in rejected state on subtest 1");
2268  NS_TEST_ASSERT_MSG_EQ (m_addbaNoReplyCount, 0, "Incorrect number of times the ADDBA state machine was in no_reply state on subtest 1");
2269  NS_TEST_ASSERT_MSG_EQ (m_addbaResetCount, 0, "Incorrect number of times the ADDBA state machine was in reset state on subtest 1");
2270  }
2271 
2274  m_failedActionCount = 0;
2276  m_addbaPendingCount = 0;
2278  m_addbaNoReplyCount = 0;
2279  m_addbaResetCount = 0;
2280 
2281  Ptr<ReceiveListErrorModel> apPem = CreateObject<ReceiveListErrorModel> ();
2282  blackList.clear ();
2283  // Block ADDBA request 4 times (== maximum number of MAC frame transmissions in the ADDBA response timeout interval)
2284  blackList.push_back (5);
2285  blackList.push_back (6);
2286  blackList.push_back (7);
2287  blackList.push_back (9);
2288  apPem->SetList (blackList);
2289 
2290  {
2291  RunSubtest (PointerValue (apPem), PointerValue ());
2292  NS_TEST_ASSERT_MSG_EQ (m_failedActionCount, 4, "ADDBA response packets are not failed");
2293  // Similar to subtest 1, we also expect to receive 6 normal MPDU packets and 4 A-MPDU packets.
2294  NS_TEST_ASSERT_MSG_EQ (m_receivedNormalMpduCount, 6, "Receiving incorrect number of normal MPDU packet on subtest 2");
2295  NS_TEST_ASSERT_MSG_EQ (m_receivedAmpduCount, 4, "Receiving incorrect number of A-MPDU packet on subtest 2");
2296 
2297  NS_TEST_ASSERT_MSG_EQ (m_addbaEstablishedCount, 1, "Incorrect number of times the ADDBA state machine was in established state on subtest 2");
2298  NS_TEST_ASSERT_MSG_EQ (m_addbaPendingCount, 1, "Incorrect number of times the ADDBA state machine was in pending state on subtest 2");
2299  NS_TEST_ASSERT_MSG_EQ (m_addbaRejectedCount, 0, "Incorrect number of times the ADDBA state machine was in rejected state on subtest 2");
2300  NS_TEST_ASSERT_MSG_EQ (m_addbaNoReplyCount, 1, "Incorrect number of times the ADDBA state machine was in no_reply state on subtest 2");
2301  NS_TEST_ASSERT_MSG_EQ (m_addbaResetCount, 0, "Incorrect number of times the ADDBA state machine was in reset state on subtest 2");
2302  }
2303 
2304  // TODO: In the second test set, it does not go to reset state since ADDBA response is received after timeout (NO_REPLY)
2305  // but before it does not enter RESET state. More tests should be written to verify all possible scenarios.
2306 }
2307 
2308 //-----------------------------------------------------------------------------
2324 {
2325 public:
2326  Issue40TestCase ();
2327  virtual ~Issue40TestCase ();
2328  void DoRun (void) override;
2329 
2330 private:
2335  void RunOne (bool useAmpdu);
2336 
2342  void RxSuccessCallback (std::string context, Ptr<const Packet> p);
2349  void SendPackets (uint8_t numPackets, Ptr<NetDevice> sourceDevice, Address& destination);
2355  void TxFinalDataFailedCallback (std::string context, Mac48Address address);
2356 
2357  uint16_t m_rxCount;
2358  uint16_t m_txCount;
2360 };
2361 
2363  : TestCase ("Test case for issue #40"),
2364  m_rxCount (0),
2365  m_txCount (0),
2366  m_txMacFinalDataFailedCount (0)
2367 {
2368 }
2369 
2371 {
2372 }
2373 
2374 void
2376 {
2377  m_rxCount++;
2378 }
2379 
2380 void
2381 Issue40TestCase::SendPackets (uint8_t numPackets, Ptr<NetDevice> sourceDevice, Address& destination)
2382 {
2383  for (uint8_t i = 0; i < numPackets; i++)
2384  {
2385  Ptr<Packet> pkt = Create<Packet> (1000); // 1000 dummy bytes of data
2386  sourceDevice->Send (pkt, destination, 0);
2387  m_txCount++;
2388  }
2389 }
2390 
2391 void
2393 {
2395 }
2396 
2397 void
2399 {
2400  m_rxCount = 0;
2401  m_txCount = 0;
2403 
2404  RngSeedManager::SetSeed (1);
2405  RngSeedManager::SetRun (1);
2406  int64_t streamNumber = 100;
2407 
2408  NodeContainer wifiApNode, wifiStaNode;
2409  wifiApNode.Create (1);
2410  wifiStaNode.Create (1);
2411 
2413  YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
2414  phy.SetChannel (channel.Create ());
2415 
2416  WifiHelper wifi;
2417  wifi.SetStandard (WIFI_STANDARD_80211ac);
2418  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
2419 
2421  NetDeviceContainer apDevice;
2422  mac.SetType ("ns3::ApWifiMac");
2423  apDevice = wifi.Install (phy, mac, wifiApNode);
2424 
2425  NetDeviceContainer staDevice;
2426  mac.SetType ("ns3::StaWifiMac");
2427  staDevice = wifi.Install (phy, mac, wifiStaNode);
2428 
2429  // Assign fixed streams to random variables in use
2430  wifi.AssignStreams (apDevice, streamNumber);
2431  wifi.AssignStreams (staDevice, streamNumber);
2432 
2434  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
2435  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
2436  positionAlloc->Add (Vector (10.0, 0.0, 0.0));
2437  mobility.SetPositionAllocator (positionAlloc);
2438 
2439  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
2440  mobility.Install (wifiApNode);
2441 
2442  mobility.SetMobilityModel("ns3::WaypointMobilityModel");
2443  mobility.Install (wifiStaNode);
2444 
2445  Config::Connect ("/NodeList/*/DeviceList/*/RemoteStationManager/MacTxFinalDataFailed", MakeCallback (&Issue40TestCase::TxFinalDataFailedCallback, this));
2446  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/$ns3::WifiMac/MacRx", MakeCallback (&Issue40TestCase::RxSuccessCallback, this));
2447 
2448  Ptr<WaypointMobilityModel> staWaypointMobility = DynamicCast<WaypointMobilityModel>(wifiStaNode.Get(0)->GetObject<MobilityModel>());
2449  staWaypointMobility->AddWaypoint (Waypoint (Seconds(1.0), Vector (10.0, 0.0, 0.0)));
2450  staWaypointMobility->AddWaypoint (Waypoint (Seconds(1.5), Vector (50.0, 0.0, 0.0)));
2451 
2452  if (useAmpdu)
2453  {
2454  // Disable use of BAR that are sent with the lowest modulation so that we can also reproduce the problem with A-MPDU, i.e. the lack of feedback about SNR change
2455  Ptr<WifiNetDevice> ap_device = DynamicCast<WifiNetDevice> (apDevice.Get (0));
2456  PointerValue ptr;
2457  ap_device->GetMac ()->GetAttribute ("BE_Txop", ptr);
2458  ptr.Get<QosTxop> ()->SetAttribute ("UseExplicitBarAfterMissedBlockAck", BooleanValue (false));
2459  }
2460 
2461  // Transmit a first data packet before the station moves: it should be sent with a high modulation and successfully received
2462  Simulator::Schedule (Seconds (0.5), &Issue40TestCase::SendPackets, this, useAmpdu ? 2 : 1, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2463 
2464  // Transmit a second data packet once the station is away from the access point: it should be sent with the same high modulation and be unsuccessfully received
2465  Simulator::Schedule (Seconds (2.0), &Issue40TestCase::SendPackets, this, useAmpdu ? 2 : 1, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2466 
2467  // Keep on transmitting data packets while the station is away from the access point: it should be sent with a lower modulation and be successfully received
2468  Simulator::Schedule (Seconds (2.1), &Issue40TestCase::SendPackets, this, useAmpdu ? 2 : 1, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2469  Simulator::Schedule (Seconds (2.2), &Issue40TestCase::SendPackets, this, useAmpdu ? 2 : 1, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2470  Simulator::Schedule (Seconds (2.3), &Issue40TestCase::SendPackets, this, useAmpdu ? 2 : 1, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2471  Simulator::Schedule (Seconds (2.4), &Issue40TestCase::SendPackets, this, useAmpdu ? 2 : 1, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2472  Simulator::Schedule (Seconds (2.5), &Issue40TestCase::SendPackets, this, useAmpdu ? 2 : 1, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2473 
2474  Simulator::Stop (Seconds (3.0));
2475  Simulator::Run ();
2476 
2477  NS_TEST_ASSERT_MSG_EQ (m_txCount, (useAmpdu ? 14 : 7), "Incorrect number of transmitted packets");
2478  NS_TEST_ASSERT_MSG_EQ (m_rxCount, (useAmpdu ? 12 : 6), "Incorrect number of successfully received packets");
2479  NS_TEST_ASSERT_MSG_EQ (m_txMacFinalDataFailedCount, 1, "Incorrect number of dropped TX packets");
2480 
2481  Simulator::Destroy ();
2482 }
2483 
2484 void
2486 {
2487  //Test without A-MPDU
2488  RunOne (false);
2489 
2490  //Test with A-MPDU
2491  RunOne (true);
2492 }
2493 
2494 //-----------------------------------------------------------------------------
2508 {
2509 public:
2510  Issue169TestCase ();
2511  virtual ~Issue169TestCase ();
2512  void DoRun (void) override;
2513 
2514 private:
2522  void SendPackets (uint8_t numPackets, Ptr<NetDevice> sourceDevice, Address& destination, uint8_t priority);
2523 
2531  void TxCallback (std::string context, WifiConstPsduMap psdus, WifiTxVector txVector, double txPowerW);
2532 };
2533 
2535  : TestCase ("Test case for issue #169")
2536 {
2537 }
2538 
2540 {
2541 }
2542 
2543 void
2544 Issue169TestCase::SendPackets (uint8_t numPackets, Ptr<NetDevice> sourceDevice, Address& destination, uint8_t priority)
2545 {
2546  SocketPriorityTag priorityTag;
2547  priorityTag.SetPriority (priority);
2548  for (uint8_t i = 0; i < numPackets; i++)
2549  {
2550  Ptr<Packet> packet = Create<Packet> (1000); // 1000 dummy bytes of data
2551  packet->AddPacketTag (priorityTag);
2552  sourceDevice->Send (packet, destination, 0);
2553  }
2554 }
2555 
2556 void
2557 Issue169TestCase::TxCallback (std::string context, WifiConstPsduMap psdus, WifiTxVector txVector, double txPowerW)
2558 {
2559  if (psdus.begin()->second->GetSize () >= 1000)
2560  {
2561  NS_TEST_ASSERT_MSG_EQ (txVector.GetMode ().GetModulationClass (), WifiModulationClass::WIFI_MOD_CLASS_VHT, "Ideal rate manager selected incorrect modulation class");
2562  }
2563 }
2564 
2565 void
2567 {
2568  RngSeedManager::SetSeed (1);
2569  RngSeedManager::SetRun (1);
2570  int64_t streamNumber = 100;
2571 
2572  NodeContainer wifiApNode, wifiStaNode;
2573  wifiApNode.Create (1);
2574  wifiStaNode.Create (1);
2575 
2577  YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
2578  phy.SetChannel (channel.Create ());
2579 
2580  WifiHelper wifi;
2581  wifi.SetStandard (WIFI_STANDARD_80211ac);
2582  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
2583 
2585  NetDeviceContainer apDevice;
2586  mac.SetType ("ns3::ApWifiMac");
2587  apDevice = wifi.Install (phy, mac, wifiApNode);
2588 
2589  NetDeviceContainer staDevice;
2590  mac.SetType ("ns3::StaWifiMac");
2591  staDevice = wifi.Install (phy, mac, wifiStaNode);
2592 
2593  // Assign fixed streams to random variables in use
2594  wifi.AssignStreams (apDevice, streamNumber);
2595  wifi.AssignStreams (staDevice, streamNumber);
2596 
2598  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
2599  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
2600  positionAlloc->Add (Vector (1.0, 0.0, 0.0));
2601  mobility.SetPositionAllocator (positionAlloc);
2602 
2603  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
2604  mobility.Install (wifiApNode);
2605  mobility.Install (wifiStaNode);
2606 
2607  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::WifiPhy/PhyTxPsduBegin", MakeCallback (&Issue169TestCase::TxCallback, this));
2608 
2609  //Send best-effort packet (i.e. priority 0)
2610  Simulator::Schedule (Seconds (0.5), &Issue169TestCase::SendPackets, this, 1, apDevice.Get (0), staDevice.Get (0)->GetAddress (), 0);
2611 
2612  //Send non best-effort (voice) packet (i.e. priority 6)
2613  Simulator::Schedule (Seconds (1.0), &Issue169TestCase::SendPackets, this, 1, apDevice.Get (0), staDevice.Get (0)->GetAddress (), 6);
2614 
2615  Simulator::Stop (Seconds (2.0));
2616  Simulator::Run ();
2617 
2618  Simulator::Destroy ();
2619 }
2620 
2621 
2622 //-----------------------------------------------------------------------------
2638 {
2639 public:
2642  void DoRun (void) override;
2643 
2644 private:
2649  void ChangeChannelWidth (uint16_t channelWidth);
2650 
2656  void SendPacket (Ptr<NetDevice> sourceDevice, Address& destination);
2657 
2665  void TxCallback (std::string context, WifiConstPsduMap psduMap, WifiTxVector txVector, double txPowerW);
2666 
2671  void CheckLastSelectedMode (WifiMode expectedMode);
2672 
2674 };
2675 
2677  : TestCase ("Test case for use of channel bonding with Ideal rate manager")
2678 {
2679 }
2680 
2682 {
2683 }
2684 
2685 void
2687 {
2688  Config::Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/ChannelSettings",
2689  StringValue ("{0, " + std::to_string (channelWidth) + ", BAND_5GHZ, 0}"));
2690 }
2691 
2692 void
2694 {
2695  Ptr<Packet> packet = Create<Packet> (1000);
2696  sourceDevice->Send (packet, destination, 0);
2697 }
2698 
2699 void
2700 IdealRateManagerChannelWidthTest::TxCallback (std::string context, WifiConstPsduMap psduMap, WifiTxVector txVector, double txPowerW)
2701 {
2702  if (psduMap.begin ()->second->GetSize () >= 1000)
2703  {
2704  m_txMode = txVector.GetMode ();
2705  }
2706 }
2707 
2708 void
2710 {
2711  NS_TEST_ASSERT_MSG_EQ (m_txMode, expectedMode, "Last selected WifiMode " << m_txMode << " does not match expected WifiMode " << expectedMode);
2712 }
2713 
2714 void
2716 {
2717  RngSeedManager::SetSeed (1);
2718  RngSeedManager::SetRun (1);
2719  int64_t streamNumber = 100;
2720 
2721  NodeContainer wifiApNode, wifiStaNode;
2722  wifiApNode.Create (1);
2723  wifiStaNode.Create (1);
2724 
2726  YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
2727  phy.SetChannel (channel.Create ());
2728 
2729  WifiHelper wifi;
2730  wifi.SetStandard (WIFI_STANDARD_80211ac);
2731  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
2732 
2734  NetDeviceContainer apDevice;
2735  mac.SetType ("ns3::ApWifiMac");
2736  apDevice = wifi.Install (phy, mac, wifiApNode);
2737 
2738  NetDeviceContainer staDevice;
2739  mac.SetType ("ns3::StaWifiMac");
2740  staDevice = wifi.Install (phy, mac, wifiStaNode);
2741 
2742  // Assign fixed streams to random variables in use
2743  wifi.AssignStreams (apDevice, streamNumber);
2744  wifi.AssignStreams (staDevice, streamNumber);
2745 
2747  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
2748  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
2749  positionAlloc->Add (Vector (50.0, 0.0, 0.0));
2750  mobility.SetPositionAllocator (positionAlloc);
2751 
2752  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
2753  mobility.Install (wifiApNode);
2754  mobility.Install (wifiStaNode);
2755 
2756  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::WifiPhy/PhyTxPsduBegin", MakeCallback (&IdealRateManagerChannelWidthTest::TxCallback, this));
2757 
2758  //Set channel width to 80 MHz & send packet
2759  Simulator::Schedule (Seconds (0.5), &IdealRateManagerChannelWidthTest::ChangeChannelWidth, this, 80);
2760  Simulator::Schedule (Seconds (1.0), &IdealRateManagerChannelWidthTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2761  //Selected rate should be VHT-MCS 1
2762  Simulator::Schedule (Seconds (1.1), &IdealRateManagerChannelWidthTest::CheckLastSelectedMode, this, VhtPhy::GetVhtMcs1 ());
2763 
2764  //Set channel width to 20 MHz & send packet
2765  Simulator::Schedule (Seconds (1.5), &IdealRateManagerChannelWidthTest::ChangeChannelWidth, this, 20);
2766  Simulator::Schedule (Seconds (2.0), &IdealRateManagerChannelWidthTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2767  //Selected rate should be VHT-MCS 3 since SNR should be 6 dB higher than previously
2768  Simulator::Schedule (Seconds (2.1), &IdealRateManagerChannelWidthTest::CheckLastSelectedMode, this, VhtPhy::GetVhtMcs3 ());
2769 
2770  //Set channel width to 40 MHz & send packet
2771  Simulator::Schedule (Seconds (2.5), &IdealRateManagerChannelWidthTest::ChangeChannelWidth, this, 40);
2772  Simulator::Schedule (Seconds (3.0), &IdealRateManagerChannelWidthTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2773  //Selected rate should be VHT-MCS 2 since SNR should be 3 dB lower than previously
2774  Simulator::Schedule (Seconds (3.1), &IdealRateManagerChannelWidthTest::CheckLastSelectedMode, this, VhtPhy::GetVhtMcs2 ());
2775 
2776  Simulator::Stop (Seconds (3.2));
2777  Simulator::Run ();
2778 
2779  Simulator::Destroy ();
2780 }
2781 
2782 
2783 //-----------------------------------------------------------------------------
2792 {
2793 public:
2795  virtual ~IdealRateManagerMimoTest ();
2796  void DoRun (void) override;
2797 
2798 private:
2804  void SetApMimoSettings (uint8_t antennas, uint8_t maxStreams);
2810  void SetStaMimoSettings (uint8_t antennas, uint8_t maxStreams);
2816  void SendPacket (Ptr<NetDevice> sourceDevice, Address& destination);
2817 
2825  void TxCallback (std::string context, WifiConstPsduMap psdus, WifiTxVector txVector, double txPowerW);
2826 
2831  void CheckLastSelectedMode (WifiMode expectedMode);
2836  void CheckLastSelectedNss (uint8_t expectedNss);
2837 
2839 };
2840 
2842  : TestCase ("Test case for use of imbalanced MIMO settings with Ideal rate manager")
2843 {
2844 }
2845 
2847 {
2848 }
2849 
2850 void
2851 IdealRateManagerMimoTest::SetApMimoSettings (uint8_t antennas, uint8_t maxStreams)
2852 {
2853  Config::Set ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/Antennas", UintegerValue (antennas));
2854  Config::Set ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/MaxSupportedTxSpatialStreams", UintegerValue (maxStreams));
2855  Config::Set ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/MaxSupportedRxSpatialStreams", UintegerValue (maxStreams));
2856 }
2857 
2858 void
2859 IdealRateManagerMimoTest::SetStaMimoSettings (uint8_t antennas, uint8_t maxStreams)
2860 {
2861  Config::Set ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/Antennas", UintegerValue (antennas));
2862  Config::Set ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/MaxSupportedTxSpatialStreams", UintegerValue (maxStreams));
2863  Config::Set ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/MaxSupportedRxSpatialStreams", UintegerValue (maxStreams));
2864 }
2865 
2866 void
2868 {
2869  Ptr<Packet> packet = Create<Packet> (1000);
2870  sourceDevice->Send (packet, destination, 0);
2871 }
2872 
2873 void
2874 IdealRateManagerMimoTest::TxCallback (std::string context, WifiConstPsduMap psdus, WifiTxVector txVector, double txPowerW)
2875 {
2876  if (psdus.begin ()->second->GetSize () >= 1000)
2877  {
2878  m_txVector = txVector;
2879  }
2880 }
2881 
2882 void
2884 {
2885  NS_TEST_ASSERT_MSG_EQ (m_txVector.GetNss (), expectedNss, "Last selected Nss " << m_txVector.GetNss () << " does not match expected Nss " << expectedNss);
2886 }
2887 
2888 void
2890 {
2891  NS_TEST_ASSERT_MSG_EQ (m_txVector.GetMode (), expectedMode, "Last selected WifiMode " << m_txVector.GetMode () << " does not match expected WifiMode " << expectedMode);
2892 }
2893 
2894 void
2896 {
2897  RngSeedManager::SetSeed (1);
2898  RngSeedManager::SetRun (1);
2899  int64_t streamNumber = 100;
2900 
2901  NodeContainer wifiApNode, wifiStaNode;
2902  wifiApNode.Create (1);
2903  wifiStaNode.Create (1);
2904 
2906  YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
2907  phy.SetChannel (channel.Create ());
2908 
2909  WifiHelper wifi;
2910  wifi.SetStandard (WIFI_STANDARD_80211ac);
2911  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
2912 
2914  NetDeviceContainer apDevice;
2915  mac.SetType ("ns3::ApWifiMac");
2916  apDevice = wifi.Install (phy, mac, wifiApNode);
2917 
2918  NetDeviceContainer staDevice;
2919  mac.SetType ("ns3::StaWifiMac");
2920  staDevice = wifi.Install (phy, mac, wifiStaNode);
2921 
2922  // Assign fixed streams to random variables in use
2923  wifi.AssignStreams (apDevice, streamNumber);
2924  wifi.AssignStreams (staDevice, streamNumber);
2925 
2927  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
2928  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
2929  positionAlloc->Add (Vector (40.0, 0.0, 0.0));
2930  mobility.SetPositionAllocator (positionAlloc);
2931 
2932  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
2933  mobility.Install (wifiApNode);
2934  mobility.Install (wifiStaNode);
2935 
2936  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::WifiPhy/PhyTxPsduBegin", MakeCallback (&IdealRateManagerMimoTest::TxCallback, this));
2937 
2938 
2939  // TX: 1 antenna
2940  Simulator::Schedule (Seconds (0.9), &IdealRateManagerMimoTest::SetApMimoSettings, this, 1, 1);
2941  // RX: 1 antenna
2942  Simulator::Schedule (Seconds (0.9), &IdealRateManagerMimoTest::SetStaMimoSettings, this, 1, 1);
2943  // Send packets (2 times to get one feedback)
2944  Simulator::Schedule (Seconds (1.0), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2945  Simulator::Schedule (Seconds (1.1), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2946  // Selected NSS should be 1 since both TX and RX support a single antenna
2947  Simulator::Schedule (Seconds (1.2), &IdealRateManagerMimoTest::CheckLastSelectedNss, this, 1);
2948  // Selected rate should be VHT-MCS 2 because of settings and distance between TX and RX
2949  Simulator::Schedule (Seconds (1.2), &IdealRateManagerMimoTest::CheckLastSelectedMode, this, VhtPhy::GetVhtMcs2 ());
2950 
2951 
2952  // TX: 1 antenna
2953  Simulator::Schedule (Seconds (1.9), &IdealRateManagerMimoTest::SetApMimoSettings, this, 1, 1);
2954  // RX: 2 antennas, but only supports 1 spatial stream
2955  Simulator::Schedule (Seconds (1.9), &IdealRateManagerMimoTest::SetStaMimoSettings, this, 2, 1);
2956  // Send packets (2 times to get one feedback)
2957  Simulator::Schedule (Seconds (2.0), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2958  Simulator::Schedule (Seconds (2.1), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2959  // Selected NSS should be 1 since both TX and RX support a single antenna
2960  Simulator::Schedule (Seconds (2.2), &IdealRateManagerMimoTest::CheckLastSelectedNss, this, 1);
2961  // Selected rate should be increased to VHT-MCS 3 because of RX diversity resulting in SNR improvement of about 3dB
2962  Simulator::Schedule (Seconds (2.2), &IdealRateManagerMimoTest::CheckLastSelectedMode, this, VhtPhy::GetVhtMcs3 ());
2963 
2964 
2965  // TX: 1 antenna
2966  Simulator::Schedule (Seconds (2.9), &IdealRateManagerMimoTest::SetApMimoSettings, this, 1, 1);
2967  // RX: 2 antennas, and supports 2 spatial streams
2968  Simulator::Schedule (Seconds (2.9), &IdealRateManagerMimoTest::SetStaMimoSettings, this, 2, 2);
2969  // Send packets (2 times to get one feedback)
2970  Simulator::Schedule (Seconds (3.0), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2971  Simulator::Schedule (Seconds (3.1), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2972  // Selected NSS should be 1 since TX supports a single antenna
2973  Simulator::Schedule (Seconds (3.2), &IdealRateManagerMimoTest::CheckLastSelectedNss, this, 1);
2974  // Selected rate should be as previously
2975  Simulator::Schedule (Seconds (3.2), &IdealRateManagerMimoTest::CheckLastSelectedMode, this, VhtPhy::GetVhtMcs3 ());
2976 
2977 
2978  // TX: 2 antennas, but only supports 1 spatial stream
2979  Simulator::Schedule (Seconds (3.9), &IdealRateManagerMimoTest::SetApMimoSettings, this, 2, 1);
2980  // RX: 1 antenna
2981  Simulator::Schedule (Seconds (3.9), &IdealRateManagerMimoTest::SetStaMimoSettings, this, 1, 1);
2982  // Send packets (2 times to get one feedback)
2983  Simulator::Schedule (Seconds (4.0), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2984  Simulator::Schedule (Seconds (4.1), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2985  // Selected NSS should be 1 since both TX and RX support a single antenna
2986  Simulator::Schedule (Seconds (4.2), &IdealRateManagerMimoTest::CheckLastSelectedNss, this, 1);
2987  // Selected rate should be VHT-MCS 2 because we do no longer have diversity in this scenario (more antennas at TX does not result in SNR improvement in AWGN channel)
2988  Simulator::Schedule (Seconds (4.2), &IdealRateManagerMimoTest::CheckLastSelectedMode, this, VhtPhy::GetVhtMcs2 ());
2989 
2990 
2991  // TX: 2 antennas, but only supports 1 spatial stream
2992  Simulator::Schedule (Seconds (4.9), &IdealRateManagerMimoTest::SetApMimoSettings, this, 2, 1);
2993  // RX: 2 antennas, but only supports 1 spatial stream
2994  Simulator::Schedule (Seconds (4.9), &IdealRateManagerMimoTest::SetStaMimoSettings, this, 2, 1);
2995  // Send packets (2 times to get one feedback)
2996  Simulator::Schedule (Seconds (5.0), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2997  Simulator::Schedule (Seconds (5.1), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2998  // Selected NSS should be 1 since both TX and RX support a single antenna
2999  Simulator::Schedule (Seconds (5.2), &IdealRateManagerMimoTest::CheckLastSelectedNss, this, 1);
3000  // Selected rate should be increased to VHT-MCS 3 because of RX diversity resulting in SNR improvement of about 3dB (more antennas at TX does not result in SNR improvement in AWGN channel)
3001  Simulator::Schedule (Seconds (5.2), &IdealRateManagerMimoTest::CheckLastSelectedMode, this, VhtPhy::GetVhtMcs3 ());
3002 
3003 
3004  // TX: 2 antennas, but only supports 1 spatial stream
3005  Simulator::Schedule (Seconds (5.9), &IdealRateManagerMimoTest::SetApMimoSettings, this, 2, 1);
3006  // RX: 2 antennas, and supports 2 spatial streams
3007  Simulator::Schedule (Seconds (5.9), &IdealRateManagerMimoTest::SetStaMimoSettings, this, 2, 2);
3008  // Send packets (2 times to get one feedback)
3009  Simulator::Schedule (Seconds (6.0), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
3010  Simulator::Schedule (Seconds (6.1), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
3011  // Selected NSS should be 1 since TX supports a single antenna
3012  Simulator::Schedule (Seconds (6.2), &IdealRateManagerMimoTest::CheckLastSelectedNss, this, 1);
3013  // Selected rate should be as previously
3014  Simulator::Schedule (Seconds (6.2), &IdealRateManagerMimoTest::CheckLastSelectedMode, this, VhtPhy::GetVhtMcs3 ());
3015 
3016 
3017  // TX: 2 antennas, and supports 2 spatial streams
3018  Simulator::Schedule (Seconds (6.9), &IdealRateManagerMimoTest::SetApMimoSettings, this, 2, 2);
3019  // RX: 1 antenna
3020  Simulator::Schedule (Seconds (6.9), &IdealRateManagerMimoTest::SetStaMimoSettings, this, 1, 1);
3021  // Send packets (2 times to get one feedback)
3022  Simulator::Schedule (Seconds (7.0), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
3023  Simulator::Schedule (Seconds (7.1), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
3024  // Selected NSS should be 1 since RX supports a single antenna
3025  Simulator::Schedule (Seconds (7.2), &IdealRateManagerMimoTest::CheckLastSelectedNss, this, 1);
3026  // Selected rate should be VHT-MCS 2 because we do no longer have diversity in this scenario (more antennas at TX does not result in SNR improvement in AWGN channel)
3027  Simulator::Schedule (Seconds (7.2), &IdealRateManagerMimoTest::CheckLastSelectedMode, this, VhtPhy::GetVhtMcs2 ());
3028 
3029 
3030  // TX: 2 antennas, and supports 2 spatial streams
3031  Simulator::Schedule (Seconds (7.9), &IdealRateManagerMimoTest::SetApMimoSettings, this, 2, 2);
3032  // RX: 2 antennas, but only supports 1 spatial stream
3033  Simulator::Schedule (Seconds (7.9), &IdealRateManagerMimoTest::SetStaMimoSettings, this, 2, 1);
3034  // Send packets (2 times to get one feedback)
3035  Simulator::Schedule (Seconds (8.0), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
3036  Simulator::Schedule (Seconds (8.1), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
3037  // Selected NSS should be 1 since RX supports a single antenna
3038  Simulator::Schedule (Seconds (8.2), &IdealRateManagerMimoTest::CheckLastSelectedNss, this, 1);
3039  // Selected rate should be increased to VHT-MCS 3 because of RX diversity resulting in SNR improvement of about 3dB (more antennas at TX does not result in SNR improvement in AWGN channel)
3040  Simulator::Schedule (Seconds (8.2), &IdealRateManagerMimoTest::CheckLastSelectedMode, this, VhtPhy::GetVhtMcs3 ());
3041 
3042 
3043  // TX: 2 antennas, and supports 2 spatial streams
3044  Simulator::Schedule (Seconds (8.9), &IdealRateManagerMimoTest::SetApMimoSettings, this, 2, 2);
3045  // RX: 2 antennas, and supports 2 spatial streams
3046  Simulator::Schedule (Seconds (8.9), &IdealRateManagerMimoTest::SetStaMimoSettings, this, 2, 2);
3047  // Send packets (2 times to get one feedback)
3048  Simulator::Schedule (Seconds (9.0), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
3049  Simulator::Schedule (Seconds (9.1), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
3050  // Selected NSS should be 2 since both TX and RX support 2 antennas
3051  Simulator::Schedule (Seconds (9.2), &IdealRateManagerMimoTest::CheckLastSelectedNss, this, 2);
3052  // Selecte rate should be the same as without diversity, as it uses 2 spatial streams so there is no more benefits from diversity in AWGN channels
3053  Simulator::Schedule (Seconds (9.2), &IdealRateManagerMimoTest::CheckLastSelectedMode, this, VhtPhy::GetVhtMcs2 ());
3054 
3055 
3056  // Verify we can go back to initial situation
3057  Simulator::Schedule (Seconds (9.9), &IdealRateManagerMimoTest::SetApMimoSettings, this, 1, 1);
3058  Simulator::Schedule (Seconds (9.9), &IdealRateManagerMimoTest::SetStaMimoSettings, this, 1, 1);
3059  Simulator::Schedule (Seconds (10.0), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
3060  Simulator::Schedule (Seconds (10.1), &IdealRateManagerMimoTest::CheckLastSelectedNss, this, 1);
3061  Simulator::Schedule (Seconds (10.1), &IdealRateManagerMimoTest::CheckLastSelectedMode, this, VhtPhy::GetVhtMcs2 ());
3062 
3063  Simulator::Stop (Seconds (10.2));
3064  Simulator::Run ();
3065  Simulator::Destroy ();
3066 }
3067 
3068 //-----------------------------------------------------------------------------
3076 {
3077 public:
3079 
3080 private:
3090  bool CheckDataRate (HeRu::RuType ruType, std::string mcs, uint8_t nss, uint16_t guardInterval, uint16_t expectedDataRate);
3091  void DoRun (void) override;
3092 };
3093 
3095  : TestCase ("Check data rates for different RU types.")
3096 {
3097 }
3098 
3099 bool
3100 HeRuMcsDataRateTestCase::CheckDataRate (HeRu::RuType ruType, std::string mcs, uint8_t nss, uint16_t guardInterval, uint16_t expectedDataRate)
3101 {
3102  uint16_t approxWidth = HeRu::GetBandwidth (ruType);
3103  WifiMode mode (mcs);
3104  uint64_t dataRate = round (mode.GetDataRate (approxWidth, guardInterval, nss) / 100000.0);
3105  NS_ABORT_MSG_IF (dataRate > 65535, "Rate is way too high");
3106  if (static_cast<uint16_t> (dataRate) != expectedDataRate)
3107  {
3108  std::cerr << "RU=" << ruType
3109  << " mode=" << mode
3110  << " Nss=" << +nss
3111  << " guardInterval=" << guardInterval
3112  << " expected=" << expectedDataRate << " x100kbps"
3113  << " computed=" << static_cast<uint16_t> (dataRate) << " x100kbps"
3114  << std::endl;
3115  return false;
3116  }
3117  return true;
3118 }
3119 
3120 void
3122 {
3123  bool retval = true;
3124 
3125  //26-tone RU, browse over all MCSs, GIs and Nss's (up to 4, current max)
3126  retval = retval
3127  && CheckDataRate (HeRu::RU_26_TONE, "HeMcs0", 1, 800, 9)
3128  && CheckDataRate (HeRu::RU_26_TONE, "HeMcs1", 1, 1600, 17)
3129  && CheckDataRate (HeRu::RU_26_TONE, "HeMcs2", 1, 3200, 23)
3130  && CheckDataRate (HeRu::RU_26_TONE, "HeMcs3", 1, 3200, 30)
3131  && CheckDataRate (HeRu::RU_26_TONE, "HeMcs4", 2, 1600, 100)
3132  && CheckDataRate (HeRu::RU_26_TONE, "HeMcs5", 3, 1600, 200)
3133  && CheckDataRate (HeRu::RU_26_TONE, "HeMcs6", 4, 1600, 300)
3134  && CheckDataRate (HeRu::RU_26_TONE, "HeMcs7", 4, 3200, 300)
3135  && CheckDataRate (HeRu::RU_26_TONE, "HeMcs8", 4, 1600, 400)
3136  && CheckDataRate (HeRu::RU_26_TONE, "HeMcs9", 4, 3200, 400)
3137  && CheckDataRate (HeRu::RU_26_TONE, "HeMcs10", 4, 1600, 500)
3138  && CheckDataRate (HeRu::RU_26_TONE, "HeMcs11", 4, 3200, 500);
3139 
3140  NS_TEST_EXPECT_MSG_EQ (retval, true, "26-tone RU data rate verification for different MCSs, GIs, and Nss's failed");
3141 
3142  //Check other RU sizes
3143  retval = retval
3144  && CheckDataRate ( HeRu::RU_52_TONE, "HeMcs2", 1, 1600, 50)
3145  && CheckDataRate ( HeRu::RU_106_TONE, "HeMcs9", 1, 800, 500)
3146  && CheckDataRate ( HeRu::RU_242_TONE, "HeMcs5", 1, 1600, 650)
3147  && CheckDataRate ( HeRu::RU_484_TONE, "HeMcs3", 1, 1600, 650)
3148  && CheckDataRate ( HeRu::RU_996_TONE, "HeMcs5", 1, 3200, 2450)
3149  && CheckDataRate (HeRu::RU_2x996_TONE, "HeMcs3", 1, 3200, 2450);
3150 
3151  NS_TEST_EXPECT_MSG_EQ (retval, true, "Data rate verification for RUs above 52-tone RU (included) failed");
3152 }
3153 
3160 class WifiTestSuite : public TestSuite
3161 {
3162 public:
3163  WifiTestSuite ();
3164 };
3165 
3167  : TestSuite ("wifi-devices", UNIT)
3168 {
3169  AddTestCase (new WifiTest, TestCase::QUICK);
3170  AddTestCase (new QosUtilsIsOldPacketTest, TestCase::QUICK);
3171  AddTestCase (new InterferenceHelperSequenceTest, TestCase::QUICK); //Bug 991
3172  AddTestCase (new DcfImmediateAccessBroadcastTestCase, TestCase::QUICK);
3173  AddTestCase (new Bug730TestCase, TestCase::QUICK); //Bug 730
3174  AddTestCase (new QosFragmentationTestCase, TestCase::QUICK);
3175  AddTestCase (new SetChannelFrequencyTest, TestCase::QUICK);
3176  AddTestCase (new Bug2222TestCase, TestCase::QUICK); //Bug 2222
3177  AddTestCase (new Bug2843TestCase, TestCase::QUICK); //Bug 2843
3178  AddTestCase (new Bug2831TestCase, TestCase::QUICK); //Bug 2831
3179  AddTestCase (new StaWifiMacScanningTestCase, TestCase::QUICK); //Bug 2399
3180  AddTestCase (new Bug2470TestCase, TestCase::QUICK); //Bug 2470
3181  AddTestCase (new Issue40TestCase, TestCase::QUICK); //Issue #40
3182  AddTestCase (new Issue169TestCase, TestCase::QUICK); //Issue #169
3183  AddTestCase (new IdealRateManagerChannelWidthTest, TestCase::QUICK);
3184  AddTestCase (new IdealRateManagerMimoTest, TestCase::QUICK);
3185  AddTestCase (new HeRuMcsDataRateTestCase, TestCase::QUICK);
3186 }
3187 
Make sure that when virtual collision occurs the wifi remote station manager is triggered and the ret...
Definition: wifi-test.cc:1331
uint32_t m_countInternalCollisions
count internal collisions
Definition: wifi-test.cc:1340
void TxDataFailedTrace(std::string context, Mac48Address adr)
Transmit data failed function.
Definition: wifi-test.cc:1361
virtual ~Bug2222TestCase()
Definition: wifi-test.cc:1356
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:1368
Make sure that the ADDBA handshake process is protected.
Definition: wifi-test.cc:2036
void RxErrorCallback(std::string context, Ptr< const Packet > p, double snr)
Callback when packet is dropped.
Definition: wifi-test.cc:2154
uint16_t m_addbaResetCount
Count number of times ADDBA state machine is in reset state.
Definition: wifi-test.cc:2091
virtual ~Bug2470TestCase()
Definition: wifi-test.cc:2107
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:2238
uint16_t m_addbaRejectedCount
Count number of times ADDBA state machine is in rejected state.
Definition: wifi-test.cc:2089
void AddbaStateChangedCallback(std::string context, Time t, Mac48Address recipient, uint8_t tid, OriginatorBlockAckAgreement::State state)
Callback when ADDBA state changed.
Definition: wifi-test.cc:2112
void RunSubtest(PointerValue apErrorModel, PointerValue staErrorModel)
Run subtest for this test suite.
Definition: wifi-test.cc:2177
uint16_t m_failedActionCount
Count failed ADDBA request/response.
Definition: wifi-test.cc:2086
uint16_t m_addbaEstablishedCount
Count number of times ADDBA state machine is in established state.
Definition: wifi-test.cc:2087
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.
Definition: wifi-test.cc:2135
uint16_t m_receivedNormalMpduCount
Count received normal MPDU packets on STA.
Definition: wifi-test.cc:2084
uint16_t m_addbaNoReplyCount
Count number of times ADDBA state machine is in no_reply state.
Definition: wifi-test.cc:2090
uint16_t m_addbaPendingCount
Count number of times ADDBA state machine is in pending state.
Definition: wifi-test.cc:2088
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.
Definition: wifi-test.cc:2166
uint16_t m_receivedAmpduCount
Count received A-MPDU packets on STA.
Definition: wifi-test.cc:2085
Make sure that the channel width and the channel number can be changed at runtime.
Definition: wifi-test.cc:1643
uint16_t m_countOperationalChannelWidth20
count number of beacon frames announcing a 20 MHz operating channel width
Definition: wifi-test.cc:1667
uint16_t m_countOperationalChannelWidth40
count number of beacon frames announcing a 40 MHz operating channel width
Definition: wifi-test.cc:1668
virtual ~Bug2831TestCase()
Definition: wifi-test.cc:1680
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:1722
void RxCallback(std::string context, Ptr< const Packet > p, RxPowerWattPerChannelBand rxPowersW)
Callback triggered when a packet is received by the PHYs.
Definition: wifi-test.cc:1692
uint16_t m_assocReqCount
count number of association requests
Definition: wifi-test.cc:1665
Ptr< YansWifiPhy > m_apPhy
AP PHY.
Definition: wifi-test.cc:1662
Ptr< YansWifiPhy > m_staPhy
STA PHY.
Definition: wifi-test.cc:1663
void ChangeSupportedChannelWidth(void)
Function called to change the supported channel width at runtime.
Definition: wifi-test.cc:1685
uint16_t m_assocRespCount
count number of association responses
Definition: wifi-test.cc:1666
Make sure that the correct channel width and center frequency have been set for OFDM basic rate trans...
Definition: wifi-test.cc:1468
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.
Definition: wifi-test.cc:1542
void StoreDistinctTuple(std::string context, Ptr< SpectrumSignalParameters > txParams)
Stores the distinct {starting frequency, channelWidth, Number of subbands in SpectrumModel,...
Definition: wifi-test.cc:1510
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:1553
std::vector< FreqWidthSubbandModulationTuple > m_distinctTuples
vector of distinct {starting frequency, channelWidth, Number of subbands in SpectrumModel,...
Definition: wifi-test.cc:1479
uint16_t m_channelWidth
channel width (in MHz)
Definition: wifi-test.cc:1496
std::tuple< double, uint16_t, uint32_t, WifiModulationClass > FreqWidthSubbandModulationTuple
A tuple of {starting frequency, channelWidth, Number of subbands in SpectrumModel,...
Definition: wifi-test.cc:1478
virtual ~Bug2843TestCase()
Definition: wifi-test.cc:1505
Make sure that when changing the fragmentation threshold during the simulation, the TCP transmission ...
Definition: wifi-test.cc:605
virtual ~Bug730TestCase()
Definition: wifi-test.cc:632
void Receive(std::string context, Ptr< const Packet > p, const Address &adr)
Receive function.
Definition: wifi-test.cc:637
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:647
uint32_t m_received
received
Definition: wifi-test.cc:614
Make sure that when multiple broadcast packets are queued on the same device in a short succession,...
Definition: wifi-test.cc:450
void NotifyPhyTxBegin(Ptr< const Packet > p, double txPowerW)
Notify Phy transmit begin.
Definition: wifi-test.cc:486
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:507
ObjectFactory m_propDelay
propagation delay
Definition: wifi-test.cc:466
unsigned int m_numSentPackets
number of sent packets
Definition: wifi-test.cc:470
Time m_secondTransmissionTime
second transmission time
Definition: wifi-test.cc:469
Time m_firstTransmissionTime
first transmission time
Definition: wifi-test.cc:468
ObjectFactory m_manager
manager
Definition: wifi-test.cc:464
void SendOnePacket(Ptr< WifiNetDevice > dev)
Send one packet function.
Definition: wifi-test.cc:500
Data rate verification test for MCSs of different RU sizes.
Definition: wifi-test.cc:3076
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:3121
bool CheckDataRate(HeRu::RuType ruType, std::string mcs, uint8_t nss, uint16_t guardInterval, uint16_t expectedDataRate)
Compare the data rate computed for the provided combination with standard defined one.
Definition: wifi-test.cc:3100
Make sure that Ideal rate manager properly selects MCS based on the configured channel width.
Definition: wifi-test.cc:2638
WifiMode m_txMode
Store the last selected mode to send data packet.
Definition: wifi-test.cc:2673
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:2715
void SendPacket(Ptr< NetDevice > sourceDevice, Address &destination)
Triggers the transmission of a 1000 Byte-long data packet from the source device.
Definition: wifi-test.cc:2693
void CheckLastSelectedMode(WifiMode expectedMode)
Check if the selected WifiMode is correct.
Definition: wifi-test.cc:2709
void TxCallback(std::string context, WifiConstPsduMap psduMap, WifiTxVector txVector, double txPowerW)
Callback that indicates a PSDU is being transmitted.
Definition: wifi-test.cc:2700
void ChangeChannelWidth(uint16_t channelWidth)
Change the configured channel width for all nodes.
Definition: wifi-test.cc:2686
Test to validate that Ideal rate manager properly selects TXVECTOR in scenarios where MIMO is used.
Definition: wifi-test.cc:2792
void CheckLastSelectedNss(uint8_t expectedNss)
Check if the selected Nss is correct.
Definition: wifi-test.cc:2883
virtual ~IdealRateManagerMimoTest()
Definition: wifi-test.cc:2846
void TxCallback(std::string context, WifiConstPsduMap psdus, WifiTxVector txVector, double txPowerW)
Callback that indicates a PSDU is being transmitted.
Definition: wifi-test.cc:2874
void SetApMimoSettings(uint8_t antennas, uint8_t maxStreams)
Change the configured MIMO settings for AP node.
Definition: wifi-test.cc:2851
WifiTxVector m_txVector
Store the last TXVECTOR used to transmit Data.
Definition: wifi-test.cc:2838
void SetStaMimoSettings(uint8_t antennas, uint8_t maxStreams)
Change the configured MIMO settings for STA node.
Definition: wifi-test.cc:2859
void SendPacket(Ptr< NetDevice > sourceDevice, Address &destination)
Triggers the transmission of a 1000 Byte-long data packet from the source device.
Definition: wifi-test.cc:2867
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:2895
void CheckLastSelectedMode(WifiMode expectedMode)
Check if the selected WifiMode is correct.
Definition: wifi-test.cc:2889
void SwitchCh(Ptr< WifiNetDevice > dev)
Switch channel function.
Definition: wifi-test.cc:310
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:357
void SendOnePacket(Ptr< WifiNetDevice > dev)
Send one packet function.
Definition: wifi-test.cc:303
ObjectFactory m_manager
manager
Definition: wifi-test.cc:292
ObjectFactory m_propDelay
propagation delay
Definition: wifi-test.cc:294
Ptr< Node > CreateOne(Vector pos, Ptr< YansWifiChannel > channel)
Create one function.
Definition: wifi-test.cc:317
Make sure that Ideal rate manager is able to handle non best-effort traffic.
Definition: wifi-test.cc:2508
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.
Definition: wifi-test.cc:2544
void TxCallback(std::string context, WifiConstPsduMap psdus, WifiTxVector txVector, double txPowerW)
Callback that indicates a PSDU is being transmitted.
Definition: wifi-test.cc:2557
virtual ~Issue169TestCase()
Definition: wifi-test.cc:2539
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:2566
Make sure that Ideal rate manager recovers when the station is moving away from the access point.
Definition: wifi-test.cc:2324
uint16_t m_txCount
Count number of transmitted data packets.
Definition: wifi-test.cc:2358
uint16_t m_txMacFinalDataFailedCount
Count number of unsuccessfully transmitted data packets.
Definition: wifi-test.cc:2359
void RunOne(bool useAmpdu)
Run one function.
Definition: wifi-test.cc:2398
uint16_t m_rxCount
Count number of successfully received data packets.
Definition: wifi-test.cc:2357
void RxSuccessCallback(std::string context, Ptr< const Packet > p)
Callback when packet is successfully received.
Definition: wifi-test.cc:2375
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:2485
virtual ~Issue40TestCase()
Definition: wifi-test.cc:2370
void TxFinalDataFailedCallback(std::string context, Mac48Address address)
Transmit final data failed function.
Definition: wifi-test.cc:2392
void SendPackets(uint8_t numPackets, Ptr< NetDevice > sourceDevice, Address &destination)
Triggers the arrival of 1000 Byte-long packets in the source device.
Definition: wifi-test.cc:2381
Make sure that fragmentation works with QoS stations.
Definition: wifi-test.cc:742
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:804
uint32_t m_received
received packets
Definition: wifi-test.cc:751
virtual ~QosFragmentationTestCase()
Definition: wifi-test.cc:778
uint32_t m_fragments
transmitted fragments
Definition: wifi-test.cc:752
void Transmit(std::string context, Ptr< const Packet > p, double power)
Callback invoked when PHY transmits a packet.
Definition: wifi-test.cc:792
void Receive(std::string context, Ptr< const Packet > p, const Address &adr)
Receive function.
Definition: wifi-test.cc:783
Qos Utils Is Old Packet Test.
Definition: wifi-test.cc:235
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:240
Set Channel Frequency Test.
Definition: wifi-test.cc:901
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:932
Ptr< YansWifiPhy > GetYansWifiPhyPtr(const NetDeviceContainer &nc) const
Get yans wifi phy function.
Definition: wifi-test.cc:924
Make sure that Wifi STA is correctly associating to the best AP (i.e., nearest from STA).
Definition: wifi-test.cc:1844
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:1969
void TurnBeaconGenerationOn(Ptr< Node > apNode)
Turn beacon generation on the AP node.
Definition: wifi-test.cc:1894
Mac48Address m_associatedApBssid
Associated AP's bssid.
Definition: wifi-test.cc:1875
virtual ~StaWifiMacScanningTestCase()
Definition: wifi-test.cc:1883
void TurnApOff(Ptr< Node > apNode)
Turn the AP node off.
Definition: wifi-test.cc:1902
NodeContainer Setup(bool nearestApBeaconGeneration, bool staActiveProbe)
Setup test.
Definition: wifi-test.cc:1910
void AssocCallback(std::string context, Mac48Address bssid)
Callback function on STA assoc event.
Definition: wifi-test.cc:1888
Wifi Test.
Definition: wifi-test.cc:99
void CreateOne(Vector pos, Ptr< YansWifiChannel > channel)
Create one function.
Definition: wifi-test.cc:139
ObjectFactory m_mac
MAC.
Definition: wifi-test.cc:122
void RunOne(void)
Run one function.
Definition: wifi-test.cc:178
void SendOnePacket(Ptr< WifiNetDevice > dev)
Send one packet function.
Definition: wifi-test.cc:132
ObjectFactory m_manager
manager
Definition: wifi-test.cc:121
ObjectFactory m_propDelay
propagation delay
Definition: wifi-test.cc:123
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:197
Wifi Test Suite.
Definition: wifi-test.cc:3161
a polymophic address class
Definition: address.h:91
AttributeValue implementation for Boolean.
Definition: boolean.h:37
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
RuType
The different HE Resource Unit (RU) types.
Definition: he-ru.h:42
The HT Operation Information Element.
Definition: ht-operation.h:51
uint8_t GetStaChannelWidth(void) const
Return the STA channel width.
an EUI-48 address
Definition: mac48-address.h:44
Implement the header for management frames of type beacon.
Definition: mgt-headers.h:862
HtOperation GetHtOperation(void) const
Return the HT operation.
Definition: mgt-headers.cc:262
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.
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)=0
virtual Address GetAddress(void) const =0
virtual uint32_t GetIfIndex(void) const =0
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 AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Definition: node.cc:130
uint32_t AddApplication(Ptr< Application > application)
Associate an Application to this Node.
Definition: node.cc:159
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Definition: node.cc:144
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:364
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:256
Instantiate subclasses of ns3::Object.
Ptr< Object > Create(void) 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(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition: object.cc:252
State
Represents the state for this agreement.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
void AddPacketTag(const Tag &tag) const
Add a packet tag.
Definition: packet.cc:956
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:290
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:856
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.
Hold objects of type Ptr<T>.
Definition: pointer.h:37
Ptr< T > Get(void) const
Definition: pointer.h:201
calculate a propagation delay.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
Handle packet fragmentation and retransmissions for QoS data frames as well as MSDU aggregation (A-MS...
Definition: qos-txop.h:72
indicates whether the socket has a priority set.
Definition: socket.h:1309
void SetPriority(uint8_t priority)
Set the tag's priority.
Definition: socket.cc:842
size_t GetNumBands() const
Bands::const_iterator Begin() const
Const Iterator to the model Bands container start.
Make it easy to create and manage PHY objects for the spectrum model.
void SetChannel(Ptr< SpectrumChannel > channel)
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:36
AttributeValue implementation for Ssid.
Definition: ssid.h:105
Hold variables of type string.
Definition: string.h:41
encapsulates test code
Definition: test.h:994
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
A suite of tests to run.
Definition: test.h:1188
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
Handle packet fragmentation and retransmissions for data and management frames.
Definition: txop.h:65
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Definition: txop.cc:309
Hold an unsigned integer type.
Definition: uinteger.h:44
Vector3D Vector
Vector alias typedef for compatibility with mobility models.
Definition: vector.h:324
a (time, location) pair.
Definition: waypoint.h:36
void AddWaypoint(const Waypoint &waypoint)
helps to create WifiNetDevice objects
Definition: wifi-helper.h:274
Implements the IEEE 802.11 MAC header.
bool IsQosData(void) const
Return true if the Type is DATA and Subtype is one of the possible values for QoS Data.
bool IsAssocReq(void) const
Return true if the header is an Association Request header.
bool IsAction(void) const
Return true if the header is an Action header.
bool IsAssocResp(void) const
Return true if the header is an Association Response header.
bool IsData(void) const
Return true if the Type is DATA.
bool IsBeacon(void) const
Return true if the header is a Beacon header.
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:85
represent a single transmission mode
Definition: wifi-mode.h:48
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:177
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:114
Hold together all Wifi-related objects.
void SetMac(const Ptr< WifiMac > mac)
void SetHtConfiguration(Ptr< HtConfiguration > htConfiguration)
Ptr< WifiMac > GetMac(void) const
bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber) override
Address GetAddress(void) const override
Address GetBroadcast(void) const override
Ptr< WifiPhy > GetPhy(void) const
void SetRemoteStationManager(const Ptr< WifiRemoteStationManager > manager)
uint32_t GetIfIndex(void) const override
void SetStandard(WifiStandard standard)
Set the Wifi standard.
void SetPhy(const Ptr< WifiPhy > phy)
void Set(std::string name, const AttributeValue &v)
Definition: wifi-helper.cc:154
void SetErrorRateModel(std::string type, Args &&... args)
Helper function used to set the error rate model.
Definition: wifi-helper.h:440
uint8_t GetChannelNumber(void) const
Return current channel number.
Definition: wifi-phy.cc:912
void SetErrorRateModel(const Ptr< ErrorRateModel > model)
Sets the error rate model.
Definition: wifi-phy.cc:574
const WifiPhyOperatingChannel & GetOperatingChannel(void) const
Get a const reference to the operating channel.
Definition: wifi-phy.cc:900
virtual void ConfigureStandard(WifiStandard standard)
Configure the PHY-level parameters for different Wi-Fi standard.
Definition: wifi-phy.cc:835
void SetOperatingChannel(const ChannelTuple &channelTuple)
If the standard for this object has not been set yet, store the given channel settings.
Definition: wifi-phy.cc:930
void SetDevice(const Ptr< WifiNetDevice > device)
Sets the device this PHY is associated with.
Definition: wifi-phy.cc:535
void SetMobility(const Ptr< MobilityModel > mobility)
assign a mobility model to this device
Definition: wifi-phy.cc:547
std::tuple< uint8_t, uint16_t, int, uint8_t > ChannelTuple
Tuple identifying an operating channel.
Definition: wifi-phy.h:833
uint16_t GetChannelWidth(void) const
Definition: wifi-phy.cc:918
uint16_t GetFrequency(void) const
Definition: wifi-phy.cc:906
bool IsSet(void) const
Return true if a valid channel has been set, false otherwise.
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.
uint8_t GetNss(uint16_t staId=SU_STA_ID) const
If this TX vector is associated with an SU PPDU, return the number of spatial streams.
uint16_t GetChannelWidth(void) const
manage and create wifi channel objects for the YANS model.
Make it easy to create and manage PHY objects for the YANS model.
802.11 PHY layer model
Definition: yans-wifi-phy.h:48
void SetChannel(const Ptr< YansWifiChannel > channel)
Set the YansWifiChannel this YansWifiPhy is to be connected to.
void SetInterferenceHelper(const Ptr< InterferenceHelper > helper) override
Sets the interference helper.
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:920
void Set(std::string path, const AttributeValue &value)
Definition: config.cc:839
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
#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:141
#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:785
#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:1260
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
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:178
WifiModulationClass
This enumeration defines the modulation classes per (Table 10-6 "Modulation classes"; IEEE 802....
@ WIFI_STANDARD_80211a
@ WIFI_STANDARD_80211p
@ WIFI_STANDARD_80211n
@ WIFI_STANDARD_80211g
@ WIFI_STANDARD_80211ax
@ WIFI_STANDARD_80211ac
@ WIFI_STANDARD_80211b
@ WIFI_PHY_BAND_5GHZ
The 5 GHz band.
Definition: wifi-phy-band.h:37
@ WIFI_MOD_CLASS_OFDM
OFDM (Clause 17)
@ WIFI_MOD_CLASS_VHT
VHT (Clause 22)
@ NORMAL_MPDU
The MPDU is not part of an A-MPDU.
void SendOnePacket(Ptr< LrWpanPhy > sender, Ptr< LrWpanPhy > receiver)
Send one packet.
address
Definition: first.py:44
nodes
Definition: first.py:32
NLOHMANN_BASIC_JSON_TPL_DECLARATION std::string to_string(const NLOHMANN_BASIC_JSON_TPL &j)
user-defined to_string function for JSON values
Definition: json.h:25255
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::unordered_map< uint16_t, Ptr< const WifiPsdu > > WifiConstPsduMap
Map of const PSDUs indexed by STA-ID.
std::map< WifiSpectrumBand, double > RxPowerWattPerChannelBand
A map of the received power (Watts) for each band.
Definition: phy-entity.h:75
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1648
staDevices
Definition: third.py:103
ssid
Definition: third.py:100
channel
Definition: third.py:92
mac
Definition: third.py:99
wifi
Definition: third.py:96
apDevices
Definition: third.py:106
wifiApNode
Definition: third.py:90
mobility
Definition: third.py:108
phy
Definition: third.py:93
MpduInfo structure.
Definition: phy-entity.h:60
MpduType type
type of MPDU
Definition: phy-entity.h:61
SignalNoiseDbm structure.
Definition: phy-entity.h:53
static void AssignWifiRandomStreams(Ptr< WifiMac > mac, int64_t stream)
Definition: wifi-test.cc:62
static WifiTestSuite g_wifiTestSuite
the test suite
Definition: wifi-test.cc:3188