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/yans-error-rate-model.h"
32 #include "ns3/constant-position-mobility-model.h"
33 #include "ns3/test.h"
34 #include "ns3/pointer.h"
35 #include "ns3/rng-seed-manager.h"
36 #include "ns3/config.h"
37 #include "ns3/error-model.h"
38 #include "ns3/socket.h"
39 #include "ns3/packet-socket-server.h"
40 #include "ns3/packet-socket-client.h"
41 #include "ns3/packet-socket-helper.h"
42 #include "ns3/spectrum-wifi-helper.h"
43 #include "ns3/multi-model-spectrum-channel.h"
44 #include "ns3/wifi-spectrum-signal-parameters.h"
45 #include "ns3/yans-wifi-phy.h"
46 #include "ns3/mgt-headers.h"
47 #include "ns3/ht-configuration.h"
48 #include "ns3/wifi-ppdu.h"
49 #include "ns3/wifi-psdu.h"
50 #include "ns3/vht-phy.h"
51 #include "ns3/waypoint-mobility-model.h"
52 #include "ns3/frame-exchange-manager.h"
53 #include "ns3/wifi-default-protection-manager.h"
54 #include "ns3/wifi-default-ack-manager.h"
55 
56 using namespace ns3;
57 
58 //Helper function to assign streams to random variables, to control
59 //randomness in the tests
60 static void
62 {
63  int64_t currentStream = stream;
64  Ptr<RegularWifiMac> rmac = DynamicCast<RegularWifiMac> (mac);
65  if (rmac)
66  {
67  PointerValue ptr;
68  rmac->GetAttribute ("Txop", ptr);
69  Ptr<Txop> txop = ptr.Get<Txop> ();
70  currentStream += txop->AssignStreams (currentStream);
71 
72  rmac->GetAttribute ("VO_Txop", ptr);
73  Ptr<QosTxop> vo_txop = ptr.Get<QosTxop> ();
74  currentStream += vo_txop->AssignStreams (currentStream);
75 
76  rmac->GetAttribute ("VI_Txop", ptr);
77  Ptr<QosTxop> vi_txop = ptr.Get<QosTxop> ();
78  currentStream += vi_txop->AssignStreams (currentStream);
79 
80  rmac->GetAttribute ("BE_Txop", ptr);
81  Ptr<QosTxop> be_txop = ptr.Get<QosTxop> ();
82  currentStream += be_txop->AssignStreams (currentStream);
83 
84  rmac->GetAttribute ("BK_Txop", ptr);
85  Ptr<QosTxop> bk_txop = ptr.Get<QosTxop> ();
86  bk_txop->AssignStreams (currentStream);
87  }
88 }
89 
96 class WifiTest : public TestCase
97 {
98 public:
99  WifiTest ();
100 
101  void DoRun (void) override;
102 
103 
104 private:
106  void RunOne (void);
112  void CreateOne (Vector pos, Ptr<YansWifiChannel> channel);
118 
122 };
123 
125  : TestCase ("Wifi")
126 {
127 }
128 
129 void
131 {
132  Ptr<Packet> p = Create<Packet> ();
133  dev->Send (p, dev->GetBroadcast (), 1);
134 }
135 
136 void
138 {
139  Ptr<Node> node = CreateObject<Node> ();
140  Ptr<WifiNetDevice> dev = CreateObject<WifiNetDevice> ();
141 
143  mac->SetDevice (dev);
144  mac->SetAddress (Mac48Address::Allocate ());
145  mac->ConfigureStandard (WIFI_STANDARD_80211a);
146  Ptr<FrameExchangeManager> fem = mac->GetFrameExchangeManager ();
147  Ptr<WifiProtectionManager> protectionManager = CreateObject<WifiDefaultProtectionManager> ();
148  protectionManager->SetWifiMac (mac);
149  fem->SetProtectionManager (protectionManager);
150  Ptr<WifiAckManager> ackManager = CreateObject<WifiDefaultAckManager> ();
151  ackManager->SetWifiMac (mac);
152  fem->SetAckManager (ackManager);
153 
154  Ptr<ConstantPositionMobilityModel> mobility = CreateObject<ConstantPositionMobilityModel> ();
155  Ptr<YansWifiPhy> phy = CreateObject<YansWifiPhy> ();
156  Ptr<ErrorRateModel> error = CreateObject<YansErrorRateModel> ();
157  phy->SetErrorRateModel (error);
158  phy->SetChannel (channel);
159  phy->SetDevice (dev);
160  phy->ConfigureStandardAndBand (WIFI_PHY_STANDARD_80211a, WIFI_PHY_BAND_5GHZ);
162 
163  mobility->SetPosition (pos);
164  node->AggregateObject (mobility);
165  dev->SetMac (mac);
166  dev->SetPhy (phy);
167  dev->SetRemoteStationManager (manager);
168  node->AddDevice (dev);
169 
170  Simulator::Schedule (Seconds (1.0), &WifiTest::SendOnePacket, this, dev);
171 }
172 
173 void
175 {
176  Ptr<YansWifiChannel> channel = CreateObject<YansWifiChannel> ();
178  Ptr<PropagationLossModel> propLoss = CreateObject<RandomPropagationLossModel> ();
179  channel->SetPropagationDelayModel (propDelay);
180  channel->SetPropagationLossModel (propLoss);
181 
182  CreateOne (Vector (0.0, 0.0, 0.0), channel);
183  CreateOne (Vector (5.0, 0.0, 0.0), channel);
184  CreateOne (Vector (5.0, 0.0, 0.0), channel);
185 
186  Simulator::Stop (Seconds (10.0));
187 
188  Simulator::Run ();
189  Simulator::Destroy ();
190 }
191 
192 void
194 {
195  m_mac.SetTypeId ("ns3::AdhocWifiMac");
196  m_propDelay.SetTypeId ("ns3::ConstantSpeedPropagationDelayModel");
197 
198  m_manager.SetTypeId ("ns3::ArfWifiManager");
199  RunOne ();
200  m_manager.SetTypeId ("ns3::AarfWifiManager");
201  RunOne ();
202  m_manager.SetTypeId ("ns3::ConstantRateWifiManager");
203  RunOne ();
204  m_manager.SetTypeId ("ns3::OnoeWifiManager");
205  RunOne ();
206  m_manager.SetTypeId ("ns3::AmrrWifiManager");
207  RunOne ();
208  m_manager.SetTypeId ("ns3::IdealWifiManager");
209  RunOne ();
210 
211  m_mac.SetTypeId ("ns3::AdhocWifiMac");
212  RunOne ();
213  m_mac.SetTypeId ("ns3::ApWifiMac");
214  RunOne ();
215  m_mac.SetTypeId ("ns3::StaWifiMac");
216  RunOne ();
217 
218 
219  m_propDelay.SetTypeId ("ns3::RandomPropagationDelayModel");
220  m_mac.SetTypeId ("ns3::AdhocWifiMac");
221  RunOne ();
222 }
223 
231 {
232 public:
233  QosUtilsIsOldPacketTest () : TestCase ("QosUtilsIsOldPacket")
234  {
235  }
236  void DoRun (void) override
237  {
238  //startingSeq=0, seqNum=2047
239  NS_TEST_EXPECT_MSG_EQ (QosUtilsIsOldPacket (0, 2047), false, "2047 is new in comparison to 0");
240  //startingSeq=0, seqNum=2048
241  NS_TEST_EXPECT_MSG_EQ (QosUtilsIsOldPacket (0, 2048), true, "2048 is old in comparison to 0");
242  //startingSeq=2048, seqNum=0
243  NS_TEST_EXPECT_MSG_EQ (QosUtilsIsOldPacket (2048, 0), true, "0 is old in comparison to 2048");
244  //startingSeq=4095, seqNum=0
245  NS_TEST_EXPECT_MSG_EQ (QosUtilsIsOldPacket (4095, 0), false, "0 is new in comparison to 4095");
246  //startingSeq=0, seqNum=4095
247  NS_TEST_EXPECT_MSG_EQ (QosUtilsIsOldPacket (0, 4095), true, "4095 is old in comparison to 0");
248  //startingSeq=4095 seqNum=2047
249  NS_TEST_EXPECT_MSG_EQ (QosUtilsIsOldPacket (4095, 2047), true, "2047 is old in comparison to 4095");
250  //startingSeq=2048 seqNum=4095
251  NS_TEST_EXPECT_MSG_EQ (QosUtilsIsOldPacket (2048, 4095), false, "4095 is new in comparison to 2048");
252  //startingSeq=2049 seqNum=0
253  NS_TEST_EXPECT_MSG_EQ (QosUtilsIsOldPacket (2049, 0), false, "0 is new in comparison to 2049");
254  }
255 };
256 
257 
262 {
263 public:
265 
266  void DoRun (void) override;
267 
268 
269 private:
286  void SwitchCh (Ptr<WifiNetDevice> dev);
287 
291 };
292 
294  : TestCase ("InterferenceHelperSequence")
295 {
296 }
297 
298 void
300 {
301  Ptr<Packet> p = Create<Packet> (1000);
302  dev->Send (p, dev->GetBroadcast (), 1);
303 }
304 
305 void
307 {
308  Ptr<WifiPhy> p = dev->GetPhy ();
309  p->SetChannelNumber (40);
310 }
311 
312 Ptr<Node>
314 {
315  Ptr<Node> node = CreateObject<Node> ();
316  Ptr<WifiNetDevice> dev = CreateObject<WifiNetDevice> ();
317 
319  mac->SetDevice (dev);
320  mac->SetAddress (Mac48Address::Allocate ());
321  mac->ConfigureStandard (WIFI_STANDARD_80211a);
322  Ptr<FrameExchangeManager> fem = mac->GetFrameExchangeManager ();
323  Ptr<WifiProtectionManager> protectionManager = CreateObject<WifiDefaultProtectionManager> ();
324  protectionManager->SetWifiMac (mac);
325  fem->SetProtectionManager (protectionManager);
326  Ptr<WifiAckManager> ackManager = CreateObject<WifiDefaultAckManager> ();
327  ackManager->SetWifiMac (mac);
328  fem->SetAckManager (ackManager);
329 
330  Ptr<ConstantPositionMobilityModel> mobility = CreateObject<ConstantPositionMobilityModel> ();
331  Ptr<YansWifiPhy> phy = CreateObject<YansWifiPhy> ();
332  Ptr<ErrorRateModel> error = CreateObject<YansErrorRateModel> ();
333  phy->SetErrorRateModel (error);
334  phy->SetChannel (channel);
335  phy->SetDevice (dev);
336  phy->SetMobility (mobility);
337  phy->ConfigureStandardAndBand (WIFI_PHY_STANDARD_80211a, WIFI_PHY_BAND_5GHZ);
339 
340  mobility->SetPosition (pos);
341  node->AggregateObject (mobility);
342  dev->SetMac (mac);
343  dev->SetPhy (phy);
344  dev->SetRemoteStationManager (manager);
345  node->AddDevice (dev);
346 
347  return node;
348 }
349 
350 void
352 {
353  m_mac.SetTypeId ("ns3::AdhocWifiMac");
354  m_propDelay.SetTypeId ("ns3::ConstantSpeedPropagationDelayModel");
355  m_manager.SetTypeId ("ns3::ConstantRateWifiManager");
356 
357  Ptr<YansWifiChannel> channel = CreateObject<YansWifiChannel> ();
359  Ptr<MatrixPropagationLossModel> propLoss = CreateObject<MatrixPropagationLossModel> ();
360  channel->SetPropagationDelayModel (propDelay);
361  channel->SetPropagationLossModel (propLoss);
362 
363  Ptr<Node> rxOnly = CreateOne (Vector (0.0, 0.0, 0.0), channel);
364  Ptr<Node> senderA = CreateOne (Vector (5.0, 0.0, 0.0), channel);
365  Ptr<Node> senderB = CreateOne (Vector (-5.0, 0.0, 0.0), channel);
366 
367  propLoss->SetLoss (senderB->GetObject<MobilityModel> (), rxOnly->GetObject<MobilityModel> (), 0, true);
368  propLoss->SetDefaultLoss (999);
369 
370  Simulator::Schedule (Seconds (1.0),
372  DynamicCast<WifiNetDevice> (senderB->GetDevice (0)));
373 
374  Simulator::Schedule (Seconds (1.0000001),
376  DynamicCast<WifiNetDevice> (rxOnly->GetDevice (0)));
377 
378  Simulator::Schedule (Seconds (5.0),
380  DynamicCast<WifiNetDevice> (senderA->GetDevice (0)));
381 
382  Simulator::Schedule (Seconds (7.0),
384  DynamicCast<WifiNetDevice> (senderB->GetDevice (0)));
385 
386  Simulator::Stop (Seconds (100.0));
387  Simulator::Run ();
388 
389  Simulator::Destroy ();
390 }
391 
392 //-----------------------------------------------------------------------------
444 {
445 public:
447 
448  void DoRun (void) override;
449 
450 
451 private:
457 
461 
464  unsigned int m_numSentPackets;
465 
471  void NotifyPhyTxBegin (Ptr<const Packet> p, double txPowerW);
472 };
473 
475  : TestCase ("Test case for DCF immediate access with broadcast frames")
476 {
477 }
478 
479 void
481 {
482  if (m_numSentPackets == 0)
483  {
486  }
487  else if (m_numSentPackets == 1)
488  {
490  }
491 }
492 
493 void
495 {
496  Ptr<Packet> p = Create<Packet> (1000);
497  dev->Send (p, dev->GetBroadcast (), 1);
498 }
499 
500 void
502 {
503  m_mac.SetTypeId ("ns3::AdhocWifiMac");
504  m_propDelay.SetTypeId ("ns3::ConstantSpeedPropagationDelayModel");
505  m_manager.SetTypeId ("ns3::ConstantRateWifiManager");
506 
507  //Assign a seed and run number, and later fix the assignment of streams to
508  //WiFi random variables, so that the first backoff used is one slot
509  RngSeedManager::SetSeed (1);
510  RngSeedManager::SetRun (40); // a value of 17 will result in zero slots
511 
512  Ptr<YansWifiChannel> channel = CreateObject<YansWifiChannel> ();
514  Ptr<PropagationLossModel> propLoss = CreateObject<RandomPropagationLossModel> ();
515  channel->SetPropagationDelayModel (propDelay);
516  channel->SetPropagationLossModel (propLoss);
517 
518  Ptr<Node> txNode = CreateObject<Node> ();
519  Ptr<WifiNetDevice> txDev = CreateObject<WifiNetDevice> ();
521  txMac->SetDevice (txDev);
522  txMac->ConfigureStandard (WIFI_STANDARD_80211a);
523  Ptr<FrameExchangeManager> fem = txMac->GetFrameExchangeManager ();
524  Ptr<WifiProtectionManager> protectionManager = CreateObject<WifiDefaultProtectionManager> ();
525  protectionManager->SetWifiMac (txMac);
526  fem->SetProtectionManager (protectionManager);
527  Ptr<WifiAckManager> ackManager = CreateObject<WifiDefaultAckManager> ();
528  ackManager->SetWifiMac (txMac);
529  fem->SetAckManager (ackManager);
530 
531 
532  //Fix the stream assignment to the Dcf Txop objects (backoffs)
533  //The below stream assignment will result in the Txop object
534  //using a backoff value of zero for this test when the
535  //Txop::EndTxNoAck() calls to StartBackoffNow()
536  AssignWifiRandomStreams (txMac, 23);
537 
538  Ptr<ConstantPositionMobilityModel> txMobility = CreateObject<ConstantPositionMobilityModel> ();
539  Ptr<YansWifiPhy> txPhy = CreateObject<YansWifiPhy> ();
540  Ptr<ErrorRateModel> txError = CreateObject<YansErrorRateModel> ();
541  txPhy->SetErrorRateModel (txError);
542  txPhy->SetChannel (channel);
543  txPhy->SetDevice (txDev);
544  txPhy->SetMobility (txMobility);
545  txPhy->ConfigureStandardAndBand (WIFI_PHY_STANDARD_80211a, WIFI_PHY_BAND_5GHZ);
546 
547  txPhy->TraceConnectWithoutContext ("PhyTxBegin", MakeCallback (&DcfImmediateAccessBroadcastTestCase::NotifyPhyTxBegin, this));
548 
549  txMobility->SetPosition (Vector (0.0, 0.0, 0.0));
550  txNode->AggregateObject (txMobility);
551  txMac->SetAddress (Mac48Address::Allocate ());
552  txDev->SetMac (txMac);
553  txDev->SetPhy (txPhy);
554  txDev->SetRemoteStationManager (m_manager.Create<WifiRemoteStationManager> ());
555  txNode->AddDevice (txDev);
556 
559  m_numSentPackets = 0;
560 
561  Simulator::Schedule (Seconds (1.0), &DcfImmediateAccessBroadcastTestCase::SendOnePacket, this, txDev);
562  Simulator::Schedule (Seconds (1.0) + MicroSeconds (1), &DcfImmediateAccessBroadcastTestCase::SendOnePacket, this, txDev);
563 
564  Simulator::Stop (Seconds (2.0));
565  Simulator::Run ();
566  Simulator::Destroy ();
567 
568  // First packet is transmitted a DIFS after the packet is queued. A DIFS
569  // is 2 slots (2 * 9 = 18 us) plus a SIFS (16 us), i.e., 34 us
570  Time expectedFirstTransmissionTime = Seconds (1.0) + MicroSeconds (34);
571 
572  //First packet has 1408 us of transmit time. Slot time is 9 us.
573  //Backoff is 1 slots. SIFS is 16 us. DIFS is 2 slots = 18 us.
574  //Should send next packet at 1408 us + (1 * 9 us) + 16 us + (2 * 9) us
575  //1451 us after the first one.
576  uint32_t expectedWait1 = 1408 + (1 * 9) + 16 + (2 * 9);
577  Time expectedSecondTransmissionTime = expectedFirstTransmissionTime + MicroSeconds (expectedWait1);
578  NS_TEST_ASSERT_MSG_EQ (m_firstTransmissionTime, expectedFirstTransmissionTime, "The first transmission time not correct!");
579 
580  NS_TEST_ASSERT_MSG_EQ (m_secondTransmissionTime, expectedSecondTransmissionTime, "The second transmission time not correct!");
581 }
582 
583 //-----------------------------------------------------------------------------
596 class Bug730TestCase : public TestCase
597 {
598 public:
599  Bug730TestCase ();
600  virtual ~Bug730TestCase ();
601 
602  void DoRun (void) override;
603 
604 
605 private:
606  uint32_t m_received;
607 
614  void Receive (std::string context, Ptr<const Packet> p, const Address &adr);
615 
616 };
617 
619  : TestCase ("Test case for Bug 730"),
620  m_received (0)
621 {
622 }
623 
625 {
626 }
627 
628 void
629 Bug730TestCase::Receive (std::string context, Ptr<const Packet> p, const Address &adr)
630 {
631  if ((p->GetSize () == 1460) && (Simulator::Now () > Seconds (20)))
632  {
633  m_received++;
634  }
635 }
636 
637 
638 void
640 {
641  m_received = 0;
642 
643  NodeContainer wifiStaNode;
644  wifiStaNode.Create (1);
645 
647  wifiApNode.Create (1);
648 
649  YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
651  phy.SetChannel (channel.Create ());
652 
654  wifi.SetStandard (WIFI_STANDARD_80211b);
655  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
656  "DataMode", StringValue ("DsssRate1Mbps"),
657  "ControlMode", StringValue ("DsssRate1Mbps"));
658 
660  Ssid ssid = Ssid ("ns-3-ssid");
661  mac.SetType ("ns3::StaWifiMac",
662  "Ssid", SsidValue (ssid),
663  "ActiveProbing", BooleanValue (false));
664 
666  staDevices = wifi.Install (phy, mac, wifiStaNode);
667 
668  mac.SetType ("ns3::ApWifiMac",
669  "Ssid", SsidValue (ssid),
670  "BeaconGeneration", BooleanValue (true));
671 
673  apDevices = wifi.Install (phy, mac, wifiApNode);
674 
676  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
677 
678  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
679  positionAlloc->Add (Vector (1.0, 0.0, 0.0));
680  mobility.SetPositionAllocator (positionAlloc);
681 
682  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
683  mobility.Install (wifiApNode);
684  mobility.Install (wifiStaNode);
685 
686  Ptr<WifiNetDevice> ap_device = DynamicCast<WifiNetDevice> (apDevices.Get (0));
687  Ptr<WifiNetDevice> sta_device = DynamicCast<WifiNetDevice> (staDevices.Get (0));
688 
689  PacketSocketAddress socket;
690  socket.SetSingleDevice (sta_device->GetIfIndex ());
691  socket.SetPhysicalAddress (ap_device->GetAddress ());
692  socket.SetProtocol (1);
693 
694  // give packet socket powers to nodes.
695  PacketSocketHelper packetSocket;
696  packetSocket.Install (wifiStaNode);
697  packetSocket.Install (wifiApNode);
698 
699  Ptr<PacketSocketClient> client = CreateObject<PacketSocketClient> ();
700  client->SetAttribute ("PacketSize", UintegerValue (1460));
701  client->SetRemote (socket);
702  wifiStaNode.Get (0)->AddApplication (client);
703  client->SetStartTime (Seconds (1));
704  client->SetStopTime (Seconds (51.0));
705 
706  Ptr<PacketSocketServer> server = CreateObject<PacketSocketServer> ();
707  server->SetLocal (socket);
708  wifiApNode.Get (0)->AddApplication (server);
709  server->SetStartTime (Seconds (0.0));
710  server->SetStopTime (Seconds (52.0));
711 
712  Config::Connect ("/NodeList/*/ApplicationList/0/$ns3::PacketSocketServer/Rx", MakeCallback (&Bug730TestCase::Receive, this));
713 
714  Simulator::Schedule (Seconds (10.0), Config::Set, "/NodeList/0/DeviceList/0/RemoteStationManager/FragmentationThreshold", StringValue ("800"));
715 
716  Simulator::Stop (Seconds (55));
717  Simulator::Run ();
718 
719  Simulator::Destroy ();
720 
721  bool result = (m_received > 0);
722  NS_TEST_ASSERT_MSG_EQ (result, true, "packet reception unexpectedly stopped after adapting fragmentation threshold!");
723 }
724 
725 //-----------------------------------------------------------------------------
734 {
735 public:
737  virtual ~QosFragmentationTestCase ();
738 
739  void DoRun (void) override;
740 
741 
742 private:
743  uint32_t m_received;
744  uint32_t m_fragments;
745 
752  void Receive (std::string context, Ptr<const Packet> p, const Address &adr);
753 
760  void Transmit (std::string context, Ptr<const Packet> p, double power);
761 };
762 
764  : TestCase ("Test case for fragmentation with QoS stations"),
765  m_received (0),
766  m_fragments (0)
767 {
768 }
769 
771 {
772 }
773 
774 void
775 QosFragmentationTestCase::Receive (std::string context, Ptr<const Packet> p, const Address &adr)
776 {
777  if (p->GetSize () == 1400)
778  {
779  m_received++;
780  }
781 }
782 
783 void
784 QosFragmentationTestCase::Transmit (std::string context, Ptr<const Packet> p, double power)
785 {
786  WifiMacHeader hdr;
787  p->PeekHeader (hdr);
788  if (hdr.IsQosData ())
789  {
790  NS_TEST_EXPECT_MSG_LT_OR_EQ (p->GetSize (), 400, "Unexpected fragment size");
791  m_fragments++;
792  }
793 }
794 
795 void
797 {
798  NodeContainer wifiStaNode;
799  wifiStaNode.Create (1);
800 
802  wifiApNode.Create (1);
803 
804  YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
806  phy.SetChannel (channel.Create ());
807 
809  wifi.SetStandard (WIFI_STANDARD_80211n_5GHZ);
810  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
811  "DataMode", StringValue ("HtMcs7"));
812 
814  Ssid ssid = Ssid ("ns-3-ssid");
815  mac.SetType ("ns3::StaWifiMac",
816  "Ssid", SsidValue (ssid),
817  "ActiveProbing", BooleanValue (false));
818 
820  staDevices = wifi.Install (phy, mac, wifiStaNode);
821 
822  mac.SetType ("ns3::ApWifiMac",
823  "Ssid", SsidValue (ssid),
824  "BeaconGeneration", BooleanValue (true));
825 
827  apDevices = wifi.Install (phy, mac, wifiApNode);
828 
830  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
831 
832  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
833  positionAlloc->Add (Vector (1.0, 0.0, 0.0));
834  mobility.SetPositionAllocator (positionAlloc);
835 
836  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
837  mobility.Install (wifiApNode);
838  mobility.Install (wifiStaNode);
839 
840  Ptr<WifiNetDevice> ap_device = DynamicCast<WifiNetDevice> (apDevices.Get (0));
841  Ptr<WifiNetDevice> sta_device = DynamicCast<WifiNetDevice> (staDevices.Get (0));
842 
843  // set the TXOP limit on BE AC
844  Ptr<RegularWifiMac> sta_mac = DynamicCast<RegularWifiMac> (sta_device->GetMac ());
845  NS_ASSERT (sta_mac);
846  PointerValue ptr;
847  sta_mac->GetAttribute ("BE_Txop", ptr);
848  ptr.Get<QosTxop> ()->SetTxopLimit (MicroSeconds (3008));
849 
850  PacketSocketAddress socket;
851  socket.SetSingleDevice (sta_device->GetIfIndex ());
852  socket.SetPhysicalAddress (ap_device->GetAddress ());
853  socket.SetProtocol (1);
854 
855  // give packet socket powers to nodes.
856  PacketSocketHelper packetSocket;
857  packetSocket.Install (wifiStaNode);
858  packetSocket.Install (wifiApNode);
859 
860  Ptr<PacketSocketClient> client = CreateObject<PacketSocketClient> ();
861  client->SetAttribute ("PacketSize", UintegerValue (1400));
862  client->SetAttribute ("MaxPackets", UintegerValue (1));
863  client->SetRemote (socket);
864  wifiStaNode.Get (0)->AddApplication (client);
865  client->SetStartTime (Seconds (1));
866  client->SetStopTime (Seconds (3.0));
867 
868  Ptr<PacketSocketServer> server = CreateObject<PacketSocketServer> ();
869  server->SetLocal (socket);
870  wifiApNode.Get (0)->AddApplication (server);
871  server->SetStartTime (Seconds (0.0));
872  server->SetStopTime (Seconds (4.0));
873 
874  Config::Connect ("/NodeList/*/ApplicationList/0/$ns3::PacketSocketServer/Rx", MakeCallback (&QosFragmentationTestCase::Receive, this));
875 
876  Config::Set ("/NodeList/0/DeviceList/0/RemoteStationManager/FragmentationThreshold", StringValue ("400"));
877  Config::Connect ("/NodeList/0/DeviceList/0/Phy/PhyTxBegin", MakeCallback (&QosFragmentationTestCase::Transmit, this));
878 
879  Simulator::Stop (Seconds (5));
880  Simulator::Run ();
881 
882  Simulator::Destroy ();
883 
884  NS_TEST_ASSERT_MSG_EQ (m_received, 1, "Unexpected number of received packets");
885  NS_TEST_ASSERT_MSG_EQ (m_fragments, 4, "Unexpected number of transmitted fragments");
886 }
887 
895 {
896 public:
898 
899  void DoRun (void) override;
900 
901 
902 private:
909 
910 };
911 
913  : TestCase ("Test case for setting WifiPhy channel and frequency")
914 {
915 }
916 
919 {
920  Ptr<WifiNetDevice> wnd = nc.Get (0)->GetObject<WifiNetDevice> ();
921  Ptr<WifiPhy> wp = wnd->GetPhy ();
922  return wp->GetObject<YansWifiPhy> ();
923 }
924 
925 void
927 {
928  NodeContainer wifiStaNode;
929  wifiStaNode.Create (1);
931  wifiApNode.Create (1);
932 
933  YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
935  phy.SetChannel (channel.Create ());
936 
937  // Configure and declare other generic components of this example
938  Ssid ssid;
939  ssid = Ssid ("wifi-phy-configuration");
940  WifiMacHelper macSta;
941  macSta.SetType ("ns3::StaWifiMac",
942  "Ssid", SsidValue (ssid),
943  "ActiveProbing", BooleanValue (false));
944  NetDeviceContainer staDevice;
945  Ptr<YansWifiPhy> phySta;
946 
947  // Cases taken from src/wifi/examples/wifi-phy-configuration.cc example
948  {
949  // case 0:
950  // Default configuration, without WifiHelper::SetStandard or WifiHelper
951  phySta = CreateObject<YansWifiPhy> ();
952  // The default results in an invalid configuration
953  NS_TEST_ASSERT_MSG_EQ (phySta->GetOperatingChannel ().IsSet (), false, "default configuration");
954  }
955  {
956  // case 1:
958  // By default, WifiHelper will use WIFI_PHY_STANDARD_80211a
959  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
960  phySta = GetYansWifiPhyPtr (staDevice);
961  // We expect channel 36, width 20, frequency 5180
962  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 36, "default configuration");
963  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "default configuration");
964  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5180, "default configuration");
965  }
966  {
967  // case 2:
969  wifi.SetStandard (WIFI_STANDARD_80211b);
970  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
971  phySta = GetYansWifiPhyPtr (staDevice);
972  // We expect channel 1, width 22, frequency 2412
973  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 1, "802.11b configuration");
974  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 22, "802.11b configuration");
975  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 2412, "802.11b configuration");
976  }
977  {
978  // case 3:
980  wifi.SetStandard (WIFI_STANDARD_80211g);
981  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
982  phySta = GetYansWifiPhyPtr (staDevice);
983  // We expect channel 1, width 20, frequency 2412
984  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 1, "802.11g configuration");
985  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11g configuration");
986  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 2412, "802.11g configuration");
987  }
988  {
989  // case 4:
991  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
992  wifi.SetStandard (WIFI_STANDARD_80211n_5GHZ);
993  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
994  phySta = GetYansWifiPhyPtr (staDevice);
995  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 36, "802.11n-5GHz configuration");
996  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11n-5GHz configuration");
997  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5180, "802.11n-5GHz configuration");
998  }
999  {
1000  // case 5:
1001  WifiHelper wifi;
1002  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1003  wifi.SetStandard (WIFI_STANDARD_80211n_2_4GHZ);
1004  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1005  phySta = GetYansWifiPhyPtr (staDevice);
1006  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 1, "802.11n-2.4GHz configuration");
1007  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11n-2.4GHz configuration");
1008  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 2412, "802.11n-2.4GHz configuration");
1009  }
1010  {
1011  // case 6:
1012  WifiHelper wifi;
1013  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1014  wifi.SetStandard (WIFI_STANDARD_80211ac);
1015  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1016  phySta = GetYansWifiPhyPtr (staDevice);
1017  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 42, "802.11ac configuration");
1018  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 80, "802.11ac configuration");
1019  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5210, "802.11ac configuration");
1020  }
1021  {
1022  // case 7:
1023  WifiHelper wifi;
1024  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1025  wifi.SetStandard (WIFI_STANDARD_80211ax_2_4GHZ);
1026  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1027  phySta = GetYansWifiPhyPtr (staDevice);
1028  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 1, "802.11ax-2.4GHz configuration");
1029  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11ax-2.4GHz configuration");
1030  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 2412, "802.11ax-2.4GHz configuration");
1031  }
1032  {
1033  // case 8:
1034  WifiHelper wifi;
1035  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1036  wifi.SetStandard (WIFI_STANDARD_80211ax_5GHZ);
1037  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1038  phySta = GetYansWifiPhyPtr (staDevice);
1039  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 42, "802.11ax-5GHz configuration");
1040  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 80, "802.11ax-5GHz configuration");
1041  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5210, "802.11ax-5GHz configuration");
1042  }
1043  {
1044  // case 9:
1045  WifiHelper wifi;
1046  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1047  wifi.SetStandard (WIFI_STANDARD_80211ax_6GHZ);
1048  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1049  phySta = GetYansWifiPhyPtr (staDevice);
1050  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 7, "802.11ax-6GHz configuration");
1051  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 80, "802.11ax-6GHz configuration");
1052  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5975, "802.11ax-6GHz configuration");
1053  }
1054  {
1055  // case 10:
1056  WifiHelper wifi;
1057  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1058  wifi.SetStandard (WIFI_STANDARD_80211p);
1059  phy.Set ("ChannelWidth", UintegerValue (10));
1060  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1061  phySta = GetYansWifiPhyPtr (staDevice);
1062  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 172, "802.11p 10Mhz configuration");
1063  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 10, "802.11p 10Mhz configuration");
1064  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5860, "802.11p 10Mhz configuration");
1065  }
1066  {
1067  // case 11:
1068  WifiHelper wifi;
1069  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1070  wifi.SetStandard (WIFI_STANDARD_80211p);
1071  phy.Set ("ChannelWidth", UintegerValue (5));
1072  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1073  phySta = GetYansWifiPhyPtr (staDevice);
1074  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 171, "802.11p 5Mhz configuration");
1075  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 5, "802.11p 5Mhz configuration");
1076  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5860, "802.11p 5Mhz configuration");
1077  }
1078  {
1079  // case 12:
1080  WifiHelper wifi;
1081  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1082  wifi.SetStandard (WIFI_STANDARD_80211n_5GHZ);
1083  phy.Set ("ChannelWidth", UintegerValue (20)); // reset value after previous case
1084  phy.Set ("ChannelNumber", UintegerValue (44));
1085  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1086  phySta = GetYansWifiPhyPtr (staDevice);
1087  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 44, "802.11 5GHz configuration");
1088  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
1089  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5220, "802.11 5GHz configuration");
1090  }
1091  {
1092  // case 13:
1093  WifiHelper wifi;
1094  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1095  phy.Set ("ChannelNumber", UintegerValue (44));
1096  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1097  phySta = GetYansWifiPhyPtr (staDevice);
1098  // Post-install reconfiguration to channel number 40
1099  std::ostringstream path;
1100  path << "/NodeList/*/DeviceList/" << staDevice.Get(0)->GetIfIndex () << "/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/ChannelNumber";
1101  Config::Set (path.str(), UintegerValue (40));
1102  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 40, "802.11 5GHz configuration");
1103  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
1104  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5200, "802.11 5GHz configuration");
1105  }
1106  {
1107  // case 14:
1108  WifiHelper wifi;
1109  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1110  phy.Set ("ChannelNumber", UintegerValue (44));
1111  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1112  phySta = GetYansWifiPhyPtr (staDevice);
1113  // Post-install reconfiguration to a 40 MHz channel
1114  std::ostringstream path;
1115  path << "/NodeList/*/DeviceList/" << staDevice.Get(0)->GetIfIndex () << "/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/ChannelNumber";
1116  Config::Set (path.str(), UintegerValue (46));
1117  // Although channel 44 is configured originally for 20 MHz, we
1118  // allow it to be used for 40 MHz here
1119  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 46, "802.11 5GHz configuration");
1120  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 40, "802.11 5GHz configuration");
1121  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5230, "802.11 5GHz configuration");
1122  }
1123  {
1124  // case 15:
1125  WifiHelper wifi;
1126  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1127  wifi.SetStandard (WIFI_STANDARD_80211n_5GHZ);
1128  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1129  phySta = GetYansWifiPhyPtr (staDevice);
1130  phySta->SetAttribute ("ChannelNumber", UintegerValue (44));
1131  // Post-install reconfiguration to a 40 MHz channel
1132  std::ostringstream path;
1133  path << "/NodeList/*/DeviceList/" << staDevice.Get(0)->GetIfIndex () << "/$ns3::WifiNetDevice/Phy/$ns3::YansWifiPhy/ChannelNumber";
1134  Config::Set (path.str(), UintegerValue (46));
1135  // Although channel 44 is configured originally for 20 MHz, we
1136  // allow it to be used for 40 MHz here
1137  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 46, "802.11 5GHz configuration");
1138  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 40, "802.11 5GHz configuration");
1139  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5230, "802.11 5GHz configuration");
1140  }
1141  {
1142  // case 16:
1143  WifiHelper wifi;
1144  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1145  // Test that setting Frequency to a non-standard value will throw an exception
1146  wifi.SetStandard (WIFI_STANDARD_80211n_5GHZ);
1147  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1148  phySta = GetYansWifiPhyPtr (staDevice);
1149  bool exceptionThrown = false;
1150  try
1151  {
1152  phySta->SetAttribute ("Frequency", UintegerValue (5281));
1153  }
1154  catch (const std::runtime_error&)
1155  {
1156  exceptionThrown = true;
1157  }
1158  // We expect that an exception is thrown
1159  NS_TEST_ASSERT_MSG_EQ (exceptionThrown, true, "802.11 5GHz configuration");
1160  }
1161  {
1162  // case 17:
1163  WifiHelper wifi;
1164  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1165  wifi.SetStandard (WIFI_STANDARD_80211n_5GHZ);
1166  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1167  phySta = GetYansWifiPhyPtr (staDevice);
1168  // Test that setting Frequency to a standard value will set the
1169  // channel number correctly
1170  phySta->SetAttribute ("Frequency", UintegerValue (5500));
1171  // We expect channel number to be 100 due to frequency 5500
1172  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 100, "802.11 5GHz configuration");
1173  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
1174  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5500, "802.11 5GHz configuration");
1175  }
1176  {
1177  // case 18:
1178  // Set a wrong channel after initialization
1179  WifiHelper wifi;
1180  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1181  wifi.SetStandard (WIFI_STANDARD_80211n_5GHZ);
1182  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1183  phySta = GetYansWifiPhyPtr (staDevice);
1184  bool exceptionThrown = false;
1185  try
1186  {
1187  phySta->SetOperatingChannel (99, 5185, 40);
1188  }
1189  catch (const std::runtime_error&)
1190  {
1191  exceptionThrown = true;
1192  }
1193  // We expect that an exception is thrown
1194  NS_TEST_ASSERT_MSG_EQ (exceptionThrown, true, "802.11 5GHz configuration");
1195  }
1196  {
1197  // case 19:
1198  WifiHelper wifi;
1199  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1200  // Test how channel number behaves when frequency is non-standard
1201  wifi.SetStandard (WIFI_STANDARD_80211n_5GHZ);
1202  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1203  phySta = GetYansWifiPhyPtr (staDevice);
1204  bool exceptionThrown = false;
1205  try
1206  {
1207  phySta->SetAttribute ("Frequency", UintegerValue (5181));
1208  }
1209  catch (const std::runtime_error&)
1210  {
1211  exceptionThrown = true;
1212  }
1213  // We expect that an exception is thrown due to unknown center frequency 5181
1214  NS_TEST_ASSERT_MSG_EQ (exceptionThrown, true, "802.11 5GHz configuration");
1215  phySta->SetAttribute ("Frequency", UintegerValue (5180));
1216  // We expect channel number to be 36 due to known center frequency 5180
1217  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 36, "802.11 5GHz configuration");
1218  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
1219  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5180, "802.11 5GHz configuration");
1220  exceptionThrown = false;
1221  try
1222  {
1223  phySta->SetAttribute ("Frequency", UintegerValue (5179));
1224  }
1225  catch (const std::runtime_error&)
1226  {
1227  exceptionThrown = true;
1228  }
1229  // We expect that an exception is thrown due to unknown center frequency 5179
1230  NS_TEST_ASSERT_MSG_EQ (exceptionThrown, true, "802.11 5GHz configuration");
1231  phySta->SetAttribute ("ChannelNumber", UintegerValue (36));
1232  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 36, "802.11 5GHz configuration");
1233  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
1234  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5180, "802.11 5GHz configuration");
1235  }
1236  {
1237  // case 20:
1238  WifiHelper wifi;
1239  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
1240  // Set both channel and frequency to consistent values before initialization
1241  phy.Set ("Frequency", UintegerValue (5200));
1242  phy.Set ("ChannelNumber", UintegerValue (40));
1243  wifi.SetStandard (WIFI_STANDARD_80211n_5GHZ);
1244  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1245  phySta = GetYansWifiPhyPtr (staDevice);
1246  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 40, "802.11 5GHz configuration");
1247  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
1248  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5200, "802.11 5GHz configuration");
1249  // Set both channel and frequency to consistent values after initialization
1250  wifi.SetStandard (WIFI_STANDARD_80211n_5GHZ);
1251  staDevice = wifi.Install (phy, macSta, wifiStaNode.Get (0));
1252  phySta = GetYansWifiPhyPtr (staDevice);
1253  phySta->SetAttribute ("Frequency", UintegerValue (5200));
1254  phySta->SetAttribute ("ChannelNumber", UintegerValue (40));
1255  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 40, "802.11 5GHz configuration");
1256  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
1257  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5200, "802.11 5GHz configuration");
1258  // Set both channel and frequency to inconsistent values
1259  phySta->SetAttribute ("Frequency", UintegerValue (5200));
1260  phySta->SetAttribute ("ChannelNumber", UintegerValue (36));
1261  // We expect channel number to be 36
1262  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 36, "802.11 5GHz configuration");
1263  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
1264  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5180, "802.11 5GHz configuration");
1265  phySta->SetAttribute ("ChannelNumber", UintegerValue (36));
1266  phySta->SetAttribute ("Frequency", UintegerValue (5200));
1267  // We expect channel number to be 40
1268  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 40, "802.11 5GHz configuration");
1269  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
1270  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5200, "802.11 5GHz configuration");
1271  bool exceptionThrown = false;
1272  try
1273  {
1274  phySta->SetAttribute ("Frequency", UintegerValue (5179));
1275  }
1276  catch (const std::runtime_error&)
1277  {
1278  exceptionThrown = true;
1279  }
1280  phySta->SetAttribute ("ChannelNumber", UintegerValue (36));
1281  // We expect channel number to be 36 and an exception to be thrown
1282  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 36, "802.11 5GHz configuration");
1283  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
1284  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5180, "802.11 5GHz configuration");
1285  NS_TEST_ASSERT_MSG_EQ (exceptionThrown, true, "802.11 5GHz configuration");
1286  phySta->SetAttribute ("ChannelNumber", UintegerValue (36));
1287  exceptionThrown = false;
1288  try
1289  {
1290  phySta->SetAttribute ("Frequency", UintegerValue (5179));
1291  }
1292  catch (const std::runtime_error&)
1293  {
1294  exceptionThrown = true;
1295  }
1296  // We expect channel number to be 36 and an exception to be thrown
1297  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelNumber (), 36, "802.11 5GHz configuration");
1298  NS_TEST_ASSERT_MSG_EQ (phySta->GetChannelWidth (), 20, "802.11 5GHz configuration");
1299  NS_TEST_ASSERT_MSG_EQ (phySta->GetFrequency (), 5180, "802.11 5GHz configuration");
1300  NS_TEST_ASSERT_MSG_EQ (exceptionThrown, true, "802.11 5GHz configuration");
1301  }
1302 
1303  Simulator::Destroy ();
1304 }
1305 
1306 //-----------------------------------------------------------------------------
1315 {
1316 public:
1317  Bug2222TestCase ();
1318  virtual ~Bug2222TestCase ();
1319 
1320  void DoRun (void) override;
1321 
1322 
1323 private:
1325 
1331  void TxDataFailedTrace (std::string context, Mac48Address adr);
1332 };
1333 
1335  : TestCase ("Test case for Bug 2222"),
1336  m_countInternalCollisions (0)
1337 {
1338 }
1339 
1341 {
1342 }
1343 
1344 void
1346 {
1347  //Indicate the long retry counter has been increased in the wifi remote station manager
1349 }
1350 
1351 void
1353 {
1355 
1356  //Generate same backoff for AC_VI and AC_VO
1357  //The below combination will work
1358  RngSeedManager::SetSeed (1);
1359  RngSeedManager::SetRun (16);
1360  int64_t streamNumber = 100;
1361 
1362  NodeContainer wifiNodes;
1363  wifiNodes.Create (2);
1364 
1365  YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
1367  phy.SetChannel (channel.Create ());
1368 
1369  WifiHelper wifi;
1370  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
1371  "DataMode", StringValue ("OfdmRate54Mbps"),
1372  "ControlMode", StringValue ("OfdmRate24Mbps"));
1374  Ssid ssid = Ssid ("ns-3-ssid");
1375  mac.SetType ("ns3::AdhocWifiMac",
1376  "QosSupported", BooleanValue (true));
1377 
1378  NetDeviceContainer wifiDevices;
1379  wifiDevices = wifi.Install (phy, mac, wifiNodes);
1380 
1381  // Assign fixed streams to random variables in use
1382  wifi.AssignStreams (wifiDevices, streamNumber);
1383 
1385  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
1386 
1387  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
1388  positionAlloc->Add (Vector (10.0, 0.0, 0.0));
1389  mobility.SetPositionAllocator (positionAlloc);
1390 
1391  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
1392  mobility.Install (wifiNodes);
1393 
1394  Ptr<WifiNetDevice> device1 = DynamicCast<WifiNetDevice> (wifiDevices.Get (0));
1395  Ptr<WifiNetDevice> device2 = DynamicCast<WifiNetDevice> (wifiDevices.Get (1));
1396 
1397  PacketSocketAddress socket;
1398  socket.SetSingleDevice (device1->GetIfIndex ());
1399  socket.SetPhysicalAddress (device2->GetAddress ());
1400  socket.SetProtocol (1);
1401 
1402  PacketSocketHelper packetSocket;
1403  packetSocket.Install (wifiNodes);
1404 
1405  Ptr<PacketSocketClient> clientLowPriority = CreateObject<PacketSocketClient> ();
1406  clientLowPriority->SetAttribute ("PacketSize", UintegerValue (1460));
1407  clientLowPriority->SetAttribute ("MaxPackets", UintegerValue (1));
1408  clientLowPriority->SetAttribute ("Priority", UintegerValue (4)); //AC_VI
1409  clientLowPriority->SetRemote (socket);
1410  wifiNodes.Get (0)->AddApplication (clientLowPriority);
1411  clientLowPriority->SetStartTime (Seconds (0.0));
1412  clientLowPriority->SetStopTime (Seconds (1.0));
1413 
1414  Ptr<PacketSocketClient> clientHighPriority = CreateObject<PacketSocketClient> ();
1415  clientHighPriority->SetAttribute ("PacketSize", UintegerValue (1460));
1416  clientHighPriority->SetAttribute ("MaxPackets", UintegerValue (1));
1417  clientHighPriority->SetAttribute ("Priority", UintegerValue (6)); //AC_VO
1418  clientHighPriority->SetRemote (socket);
1419  wifiNodes.Get (0)->AddApplication (clientHighPriority);
1420  clientHighPriority->SetStartTime (Seconds (0.0));
1421  clientHighPriority->SetStopTime (Seconds (1.0));
1422 
1423  Ptr<PacketSocketServer> server = CreateObject<PacketSocketServer> ();
1424  server->SetLocal (socket);
1425  wifiNodes.Get (1)->AddApplication (server);
1426  server->SetStartTime (Seconds (0.0));
1427  server->SetStopTime (Seconds (1.0));
1428 
1429  Config::Connect ("/NodeList/*/DeviceList/*/RemoteStationManager/MacTxDataFailed", MakeCallback (&Bug2222TestCase::TxDataFailedTrace, this));
1430 
1431  Simulator::Stop (Seconds (1.0));
1432  Simulator::Run ();
1433  Simulator::Destroy ();
1434 
1435  NS_TEST_ASSERT_MSG_EQ (m_countInternalCollisions, 1, "unexpected number of internal collisions!");
1436 }
1437 
1438 //-----------------------------------------------------------------------------
1452 {
1453 public:
1454  Bug2843TestCase ();
1455  virtual ~Bug2843TestCase ();
1456  void DoRun (void) override;
1457 
1458 private:
1462  typedef std::tuple<double, uint16_t, uint32_t, WifiModulationClass> FreqWidthSubbandModulationTuple;
1463  std::vector<FreqWidthSubbandModulationTuple> m_distinctTuples;
1464 
1471  void StoreDistinctTuple (std::string context, Ptr<SpectrumSignalParameters> txParams);
1478  void SendPacketBurst (uint8_t numPackets, Ptr<NetDevice> sourceDevice, Address& destination) const;
1479 
1480  uint16_t m_channelWidth;
1481 };
1482 
1484  : TestCase ("Test case for Bug 2843"),
1485  m_channelWidth (20)
1486 {
1487 }
1488 
1490 {
1491 }
1492 
1493 void
1495 {
1496  // Extract starting frequency and number of subbands
1497  Ptr<const SpectrumModel> c = txParams->psd->GetSpectrumModel ();
1498  std::size_t numBands = c->GetNumBands ();
1499  double startingFreq = c->Begin ()->fl;
1500 
1501  // Get channel bandwidth and modulation class
1502  Ptr<const WifiSpectrumSignalParameters> wifiTxParams = DynamicCast<WifiSpectrumSignalParameters> (txParams);
1503 
1504  Ptr<WifiPpdu> ppdu = wifiTxParams->ppdu->Copy ();
1505  WifiTxVector txVector = ppdu->GetTxVector ();
1506  m_channelWidth = txVector.GetChannelWidth ();
1507  WifiModulationClass modulationClass = txVector.GetMode ().GetModulationClass ();
1508 
1509  // Build a tuple and check if seen before (if so store it)
1510  FreqWidthSubbandModulationTuple tupleForCurrentTx = std::make_tuple (startingFreq, m_channelWidth, numBands, modulationClass);
1511  bool found = false;
1512  for (std::vector<FreqWidthSubbandModulationTuple>::const_iterator it = m_distinctTuples.begin (); it != m_distinctTuples.end (); it++)
1513  {
1514  if (*it == tupleForCurrentTx)
1515  {
1516  found = true;
1517  }
1518  }
1519  if (!found)
1520  {
1521  m_distinctTuples.push_back (tupleForCurrentTx);
1522  }
1523 }
1524 
1525 void
1526 Bug2843TestCase::SendPacketBurst (uint8_t numPackets, Ptr<NetDevice> sourceDevice,
1527  Address& destination) const
1528 {
1529  for (uint8_t i = 0; i < numPackets; i++)
1530  {
1531  Ptr<Packet> pkt = Create<Packet> (1000); // 1000 dummy bytes of data
1532  sourceDevice->Send (pkt, destination, 0);
1533  }
1534 }
1535 
1536 void
1538 {
1539  uint16_t channelWidth = 40; // at least 40 MHz expected here
1540 
1541  NodeContainer wifiStaNode;
1542  wifiStaNode.Create (1);
1543 
1545  wifiApNode.Create (1);
1546 
1547  SpectrumWifiPhyHelper spectrumPhy;
1548  Ptr<MultiModelSpectrumChannel> spectrumChannel = CreateObject<MultiModelSpectrumChannel> ();
1549  Ptr<FriisPropagationLossModel> lossModel = CreateObject<FriisPropagationLossModel> ();
1550  lossModel->SetFrequency (5.190e9);
1551  spectrumChannel->AddPropagationLossModel (lossModel);
1552 
1554  = CreateObject<ConstantSpeedPropagationDelayModel> ();
1555  spectrumChannel->SetPropagationDelayModel (delayModel);
1556 
1557  spectrumPhy.SetChannel (spectrumChannel);
1558  spectrumPhy.SetErrorRateModel ("ns3::NistErrorRateModel");
1559  spectrumPhy.Set ("Frequency", UintegerValue (5190));
1560  spectrumPhy.Set ("ChannelWidth", UintegerValue (channelWidth));
1561  spectrumPhy.Set ("TxPowerStart", DoubleValue (10));
1562  spectrumPhy.Set ("TxPowerEnd", DoubleValue (10));
1563 
1564  WifiHelper wifi;
1565  wifi.SetStandard (WIFI_STANDARD_80211ac);
1566  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
1567  "DataMode", StringValue ("VhtMcs8"),
1568  "ControlMode", StringValue ("VhtMcs8"),
1569  "RtsCtsThreshold", StringValue ("500")); // so as to force RTS/CTS for data frames
1570 
1572  mac.SetType ("ns3::StaWifiMac");
1573  NetDeviceContainer staDevice;
1574  staDevice = wifi.Install (spectrumPhy, mac, wifiStaNode);
1575 
1576  mac.SetType ("ns3::ApWifiMac");
1577  NetDeviceContainer apDevice;
1578  apDevice = wifi.Install (spectrumPhy, mac, wifiApNode);
1579 
1581  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
1582  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
1583  positionAlloc->Add (Vector (1.0, 0.0, 0.0)); // put close enough in order to use MCS
1584  mobility.SetPositionAllocator (positionAlloc);
1585 
1586  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
1587  mobility.Install (wifiApNode);
1588  mobility.Install (wifiStaNode);
1589 
1590  // Send two 5 packet-bursts
1591  Simulator::Schedule (Seconds (0.5), &Bug2843TestCase::SendPacketBurst, this, 5, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
1592  Simulator::Schedule (Seconds (0.6), &Bug2843TestCase::SendPacketBurst, this, 5, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
1593 
1594  Config::Connect ("/ChannelList/*/$ns3::MultiModelSpectrumChannel/TxSigParams", MakeCallback (&Bug2843TestCase::StoreDistinctTuple, this));
1595 
1596  Simulator::Stop (Seconds (0.8));
1597  Simulator::Run ();
1598 
1599  Simulator::Destroy ();
1600 
1601  // {starting frequency, channelWidth, Number of subbands in SpectrumModel, modulation type} tuples
1602  std::size_t numberTuples = m_distinctTuples.size ();
1603  NS_TEST_ASSERT_MSG_EQ (numberTuples, 2, "Only two distinct tuples expected");
1604  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");
1605  // Note that the first tuple should the one initiated by the beacon, i.e. non-HT OFDM (20 MHz)
1606  NS_TEST_ASSERT_MSG_EQ (std::get<1> (m_distinctTuples[0]), 20, "First tuple's channel width should be 20 MHz");
1607  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)");
1608  NS_TEST_ASSERT_MSG_EQ (std::get<3> (m_distinctTuples[0]), WifiModulationClass::WIFI_MOD_CLASS_OFDM, "First tuple should be OFDM");
1609  // Second tuple
1610  NS_TEST_ASSERT_MSG_EQ (std::get<1> (m_distinctTuples[1]), channelWidth, "Second tuple's channel width should be 40 MHz");
1611  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)");
1612  NS_TEST_ASSERT_MSG_EQ (std::get<3> (m_distinctTuples[1]), WifiModulationClass::WIFI_MOD_CLASS_VHT, "Second tuple should be VHT_OFDM");
1613 }
1614 
1615 //-----------------------------------------------------------------------------
1628 {
1629 public:
1630  Bug2831TestCase ();
1631  virtual ~Bug2831TestCase ();
1632  void DoRun (void) override;
1633 
1634 private:
1638  void ChangeSupportedChannelWidth (void);
1645  void RxCallback (std::string context, Ptr<const Packet> p, RxPowerWattPerChannelBand rxPowersW);
1646 
1649 
1654 };
1655 
1657  : TestCase ("Test case for Bug 2831"),
1658  m_reassocReqCount (0),
1659  m_reassocRespCount (0),
1660  m_countOperationalChannelWidth20 (0),
1661  m_countOperationalChannelWidth40 (0)
1662 {
1663 }
1664 
1666 {
1667 }
1668 
1669 void
1671 {
1672  m_apPhy->SetChannelNumber (38);
1673  m_apPhy->SetChannelWidth (40);
1674  m_staPhy->SetChannelNumber (38);
1675  m_staPhy->SetChannelWidth (40);
1676 }
1677 
1678 void
1680 {
1681  Ptr<Packet> packet = p->Copy ();
1682  WifiMacHeader hdr;
1683  packet->RemoveHeader (hdr);
1684  if (hdr.IsReassocReq ())
1685  {
1687  }
1688  else if (hdr.IsReassocResp ())
1689  {
1691  }
1692  else if (hdr.IsBeacon ())
1693  {
1694  MgtBeaconHeader beacon;
1695  packet->RemoveHeader (beacon);
1696  HtOperation htOperation = beacon.GetHtOperation ();
1697  if (htOperation.GetStaChannelWidth () > 0)
1698  {
1700  }
1701  else
1702  {
1704  }
1705  }
1706 }
1707 
1708 void
1710 {
1711  Ptr<YansWifiChannel> channel = CreateObject<YansWifiChannel> ();
1712  ObjectFactory propDelay;
1713  propDelay.SetTypeId ("ns3::ConstantSpeedPropagationDelayModel");
1714  Ptr<PropagationDelayModel> propagationDelay = propDelay.Create<PropagationDelayModel> ();
1715  Ptr<PropagationLossModel> propagationLoss = CreateObject<FriisPropagationLossModel> ();
1716  channel->SetPropagationDelayModel (propagationDelay);
1717  channel->SetPropagationLossModel (propagationLoss);
1718 
1719  Ptr<Node> apNode = CreateObject<Node> ();
1720  Ptr<WifiNetDevice> apDev = CreateObject<WifiNetDevice> ();
1721  Ptr<HtConfiguration> apHtConfiguration = CreateObject<HtConfiguration> ();
1722  apDev->SetHtConfiguration (apHtConfiguration);
1724  mac.SetTypeId ("ns3::ApWifiMac");
1725  mac.Set ("EnableBeaconJitter", BooleanValue (false));
1726  Ptr<RegularWifiMac> apMac = mac.Create<RegularWifiMac> ();
1727  apMac->SetDevice (apDev);
1728  apMac->SetAddress (Mac48Address::Allocate ());
1731  Ptr<WifiProtectionManager> protectionManager = CreateObject<WifiDefaultProtectionManager> ();
1732  protectionManager->SetWifiMac (apMac);
1733  fem->SetProtectionManager (protectionManager);
1734  Ptr<WifiAckManager> ackManager = CreateObject<WifiDefaultAckManager> ();
1735  ackManager->SetWifiMac (apMac);
1736  fem->SetAckManager (ackManager);
1737 
1738  Ptr<Node> staNode = CreateObject<Node> ();
1739  Ptr<WifiNetDevice> staDev = CreateObject<WifiNetDevice> ();
1740  Ptr<HtConfiguration> staHtConfiguration = CreateObject<HtConfiguration> ();
1741  staDev->SetHtConfiguration (staHtConfiguration);
1742  mac.SetTypeId ("ns3::StaWifiMac");
1743  Ptr<RegularWifiMac> staMac = mac.Create<RegularWifiMac> ();
1744  staMac->SetDevice (staDev);
1745  staMac->SetAddress (Mac48Address::Allocate ());
1747  fem = staMac->GetFrameExchangeManager ();
1748  protectionManager = CreateObject<WifiDefaultProtectionManager> ();
1749  protectionManager->SetWifiMac (staMac);
1750  fem->SetProtectionManager (protectionManager);
1751  ackManager = CreateObject<WifiDefaultAckManager> ();
1752  ackManager->SetWifiMac (staMac);
1753  fem->SetAckManager (ackManager);
1754 
1755  Ptr<ConstantPositionMobilityModel> apMobility = CreateObject<ConstantPositionMobilityModel> ();
1756  apMobility->SetPosition (Vector (0.0, 0.0, 0.0));
1757  apNode->AggregateObject (apMobility);
1758 
1759  Ptr<ErrorRateModel> error = CreateObject<YansErrorRateModel> ();
1760  m_apPhy = CreateObject<YansWifiPhy> ();
1761  m_apPhy->SetErrorRateModel (error);
1763  m_apPhy->SetMobility (apMobility);
1764  m_apPhy->SetDevice (apDev);
1766  m_apPhy->SetChannelNumber (36);
1767  m_apPhy->SetChannelWidth (20);
1768 
1769  Ptr<ConstantPositionMobilityModel> staMobility = CreateObject<ConstantPositionMobilityModel> ();
1770  staMobility->SetPosition (Vector (1.0, 0.0, 0.0));
1771  staNode->AggregateObject (staMobility);
1772 
1773  m_staPhy = CreateObject<YansWifiPhy> ();
1774  m_staPhy->SetErrorRateModel (error);
1776  m_staPhy->SetMobility (staMobility);
1777  m_staPhy->SetDevice (apDev);
1779  m_staPhy->SetChannelNumber (36);
1780  m_staPhy->SetChannelWidth (20);
1781 
1782  apDev->SetMac (apMac);
1783  apDev->SetPhy (m_apPhy);
1784  ObjectFactory manager;
1785  manager.SetTypeId ("ns3::ConstantRateWifiManager");
1786  apDev->SetRemoteStationManager (manager.Create<WifiRemoteStationManager> ());
1787  apNode->AddDevice (apDev);
1788 
1789  staDev->SetMac (staMac);
1790  staDev->SetPhy (m_staPhy);
1791  staDev->SetRemoteStationManager (manager.Create<WifiRemoteStationManager> ());
1792  staNode->AddDevice (staDev);
1793 
1794  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::WifiPhy/PhyRxBegin", MakeCallback (&Bug2831TestCase::RxCallback, this));
1795 
1796  Simulator::Schedule (Seconds (1.0), &Bug2831TestCase::ChangeSupportedChannelWidth, this);
1797 
1798  Simulator::Stop (Seconds (3.0));
1799  Simulator::Run ();
1800  Simulator::Destroy ();
1801 
1802  NS_TEST_ASSERT_MSG_EQ (m_reassocReqCount, 1, "Reassociation request not received");
1803  NS_TEST_ASSERT_MSG_EQ (m_reassocRespCount, 1, "Reassociation response not received");
1804  NS_TEST_ASSERT_MSG_EQ (m_countOperationalChannelWidth20, 10, "Incorrect operational channel width before channel change");
1805  NS_TEST_ASSERT_MSG_EQ (m_countOperationalChannelWidth40, 20, "Incorrect operational channel width after channel change");
1806 }
1807 
1808 //-----------------------------------------------------------------------------
1825 {
1826 public:
1828  virtual ~StaWifiMacScanningTestCase ();
1829  void DoRun (void) override;
1830 
1831 private:
1837  void AssocCallback (std::string context, Mac48Address bssid);
1842  void TurnBeaconGenerationOn (Ptr<Node> apNode);
1847  void TurnApOff (Ptr<Node> apNode);
1854  NodeContainer Setup (bool nearestApBeaconGeneration, bool staActiveProbe);
1855 
1857 };
1858 
1860  : TestCase ("Test case for StaWifiMac scanning capability")
1861 {
1862 }
1863 
1865 {
1866 }
1867 
1868 void
1870 {
1871  m_associatedApBssid = bssid;
1872 }
1873 
1874 void
1876 {
1877  Ptr<WifiNetDevice> netDevice = DynamicCast<WifiNetDevice> (apNode->GetDevice (0));
1878  Ptr<ApWifiMac> mac = DynamicCast<ApWifiMac> (netDevice->GetMac ());
1879  mac->SetAttribute ("BeaconGeneration", BooleanValue (true));
1880 }
1881 
1882 void
1884 {
1885  Ptr<WifiNetDevice> netDevice = DynamicCast<WifiNetDevice> (apNode->GetDevice (0));
1886  Ptr<WifiPhy> phy = netDevice->GetPhy ();
1887  phy->SetOffMode ();
1888 }
1889 
1891 StaWifiMacScanningTestCase::Setup (bool nearestApBeaconGeneration, bool staActiveProbe)
1892 {
1893  RngSeedManager::SetSeed (1);
1894  RngSeedManager::SetRun (1);
1895  int64_t streamNumber = 1;
1896 
1897  NodeContainer apNodes;
1898  apNodes.Create (2);
1899 
1900  Ptr<Node> apNodeNearest = CreateObject<Node> ();
1901  Ptr<Node> staNode = CreateObject<Node> ();
1902 
1904  YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
1905  phy.SetChannel (channel.Create ());
1906 
1907  WifiHelper wifi;
1908  wifi.SetStandard (WIFI_STANDARD_80211n_2_4GHZ);
1909  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager");
1910 
1912  NetDeviceContainer apDevice, apDeviceNearest;
1913  mac.SetType ("ns3::ApWifiMac",
1914  "BeaconGeneration", BooleanValue (true));
1915  apDevice = wifi.Install (phy, mac, apNodes);
1916  mac.SetType ("ns3::ApWifiMac",
1917  "BeaconGeneration", BooleanValue (nearestApBeaconGeneration));
1918  apDeviceNearest = wifi.Install (phy, mac, apNodeNearest);
1919 
1920  NetDeviceContainer staDevice;
1921  mac.SetType ("ns3::StaWifiMac",
1922  "ActiveProbing", BooleanValue (staActiveProbe));
1923  staDevice = wifi.Install (phy, mac, staNode);
1924 
1925  // Assign fixed streams to random variables in use
1926  wifi.AssignStreams (apDevice, streamNumber);
1927  wifi.AssignStreams (apDeviceNearest, streamNumber + 1);
1928  wifi.AssignStreams (staDevice, streamNumber + 2);
1929 
1931  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
1932  positionAlloc->Add (Vector (0.0, 0.0, 0.0)); // Furthest AP
1933  positionAlloc->Add (Vector (10.0, 0.0, 0.0)); // Second nearest AP
1934  positionAlloc->Add (Vector (5.0, 5.0, 0.0)); // Nearest AP
1935  positionAlloc->Add (Vector (6.0, 5.0, 0.0)); // STA
1936  mobility.SetPositionAllocator (positionAlloc);
1937 
1938  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
1939  mobility.Install (apNodes);
1940  mobility.Install (apNodeNearest);
1941  mobility.Install (staNode);
1942 
1943  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/$ns3::StaWifiMac/Assoc", MakeCallback (&StaWifiMacScanningTestCase::AssocCallback, this));
1944 
1945  NodeContainer allNodes = NodeContainer (apNodes, apNodeNearest, staNode);
1946  return allNodes;
1947 }
1948 
1949 void
1951 {
1952  {
1953  NodeContainer nodes = Setup (false, false);
1954  Ptr<Node> nearestAp = nodes.Get (2);
1955  Mac48Address nearestApAddr = DynamicCast<WifiNetDevice> (nearestAp->GetDevice (0))->GetMac ()->GetAddress ();
1956 
1957  Simulator::Schedule (Seconds (0.05), &StaWifiMacScanningTestCase::TurnBeaconGenerationOn, this, nearestAp);
1958 
1959  Simulator::Stop (Seconds (0.2));
1960  Simulator::Run ();
1961  Simulator::Destroy ();
1962 
1963  NS_TEST_ASSERT_MSG_EQ (m_associatedApBssid, nearestApAddr, "STA is associated to the wrong AP");
1964  }
1966  {
1967  NodeContainer nodes = Setup (true, true);
1968  Ptr<Node> nearestAp = nodes.Get (2);
1969  Mac48Address nearestApAddr = DynamicCast<WifiNetDevice> (nearestAp->GetDevice (0))->GetMac ()->GetAddress ();
1970 
1971  Simulator::Stop (Seconds (0.2));
1972  Simulator::Run ();
1973  Simulator::Destroy ();
1974 
1975  NS_TEST_ASSERT_MSG_EQ (m_associatedApBssid, nearestApAddr, "STA is associated to the wrong AP");
1976  }
1978  {
1979  NodeContainer nodes = Setup (true, false);
1980  Ptr<Node> nearestAp = nodes.Get (2);
1981  Mac48Address secondNearestApAddr = DynamicCast<WifiNetDevice> (nodes.Get (1)->GetDevice (0))->GetMac ()->GetAddress ();
1982 
1983  Simulator::Schedule (Seconds (0.1), &StaWifiMacScanningTestCase::TurnApOff, this, nearestAp);
1984 
1985  Simulator::Stop (Seconds (1.5));
1986  Simulator::Run ();
1987  Simulator::Destroy ();
1988 
1989  NS_TEST_ASSERT_MSG_EQ (m_associatedApBssid, secondNearestApAddr, "STA is associated to the wrong AP");
1990  }
1991 }
1992 
1993 //-----------------------------------------------------------------------------
2017 {
2018 public:
2019  Bug2470TestCase ();
2020  virtual ~Bug2470TestCase ();
2021  void DoRun (void) override;
2022 
2023 private:
2032  void AddbaStateChangedCallback (std::string context, Time t, Mac48Address recipient, uint8_t tid, OriginatorBlockAckAgreement::State state);
2043  void RxCallback (std::string context, Ptr<const Packet> p, uint16_t channelFreqMhz, WifiTxVector txVector, MpduInfo aMpdu, SignalNoiseDbm signalNoise, uint16_t staId);
2050  void RxErrorCallback (std::string context, Ptr<const Packet> p, double snr);
2057  void SendPacketBurst (uint32_t numPackets, Ptr<NetDevice> sourceDevice, Address& destination) const;
2063  void RunSubtest (PointerValue apErrorModel, PointerValue staErrorModel);
2064 
2073 };
2074 
2076  : TestCase ("Test case for Bug 2470"),
2077  m_receivedNormalMpduCount (0),
2078  m_receivedAmpduCount (0),
2079  m_failedActionCount (0),
2080  m_addbaEstablishedCount (0),
2081  m_addbaPendingCount (0),
2082  m_addbaRejectedCount (0),
2083  m_addbaNoReplyCount (0),
2084  m_addbaResetCount (0)
2085 {
2086 }
2087 
2089 {
2090 }
2091 
2092 void
2094 {
2095  switch (state)
2096  {
2097  case OriginatorBlockAckAgreement::ESTABLISHED:
2099  break;
2100  case OriginatorBlockAckAgreement::PENDING:
2102  break;
2103  case OriginatorBlockAckAgreement::REJECTED:
2105  break;
2106  case OriginatorBlockAckAgreement::NO_REPLY:
2108  break;
2109  case OriginatorBlockAckAgreement::RESET:
2111  break;
2112  }
2113 }
2114 
2115 void
2116 Bug2470TestCase::RxCallback (std::string context, Ptr<const Packet> p, uint16_t channelFreqMhz, WifiTxVector txVector, MpduInfo aMpdu, SignalNoiseDbm signalNoise, uint16_t staId)
2117 {
2118  Ptr<Packet> packet = p->Copy ();
2119  if (aMpdu.type != MpduType::NORMAL_MPDU)
2120  {
2122  }
2123  else
2124  {
2125  WifiMacHeader hdr;
2126  packet->RemoveHeader (hdr);
2127  if (hdr.IsData ())
2128  {
2130  }
2131  }
2132 }
2133 
2134 void
2135 Bug2470TestCase::RxErrorCallback (std::string context, Ptr<const Packet> p, double snr)
2136 {
2137  Ptr<Packet> packet = p->Copy ();
2138  WifiMacHeader hdr;
2139  packet->RemoveHeader (hdr);
2140  if (hdr.IsAction ())
2141  {
2143  }
2144 }
2145 
2146 void
2147 Bug2470TestCase::SendPacketBurst (uint32_t numPackets, Ptr<NetDevice> sourceDevice,
2148  Address& destination) const
2149 {
2150  for (uint32_t i = 0; i < numPackets; i++)
2151  {
2152  Ptr<Packet> pkt = Create<Packet> (1000); // 1000 dummy bytes of data
2153  sourceDevice->Send (pkt, destination, 0);
2154  }
2155 }
2156 
2157 void
2159 {
2160  RngSeedManager::SetSeed (1);
2161  RngSeedManager::SetRun (1);
2162  int64_t streamNumber = 200;
2163 
2164  NodeContainer wifiApNode, wifiStaNode;
2165  wifiApNode.Create (1);
2166  wifiStaNode.Create (1);
2167 
2169  YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
2170  phy.SetChannel (channel.Create ());
2171 
2172  WifiHelper wifi;
2173  wifi.SetStandard (WIFI_STANDARD_80211n_5GHZ);
2174  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
2175  "DataMode", StringValue ("HtMcs7"),
2176  "ControlMode", StringValue ("HtMcs7"));
2177 
2179  NetDeviceContainer apDevice;
2180  phy.Set ("PostReceptionErrorModel", apErrorModel);
2181  mac.SetType ("ns3::ApWifiMac", "EnableBeaconJitter", BooleanValue (false));
2182  apDevice = wifi.Install (phy, mac, wifiApNode);
2183 
2184  NetDeviceContainer staDevice;
2185  phy.Set ("PostReceptionErrorModel", staErrorModel);
2186  mac.SetType ("ns3::StaWifiMac");
2187  staDevice = wifi.Install (phy, mac, wifiStaNode);
2188 
2189  // Assign fixed streams to random variables in use
2190  wifi.AssignStreams (apDevice, streamNumber);
2191  wifi.AssignStreams (staDevice, streamNumber);
2192 
2194  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
2195  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
2196  positionAlloc->Add (Vector (1.0, 0.0, 0.0));
2197  mobility.SetPositionAllocator (positionAlloc);
2198 
2199  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
2200  mobility.Install (wifiApNode);
2201  mobility.Install (wifiStaNode);
2202 
2203  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::WifiPhy/MonitorSnifferRx", MakeCallback (&Bug2470TestCase::RxCallback, this));
2204  Config::Connect ("/NodeList/*/DeviceList/*/Phy/State/RxError", MakeCallback (&Bug2470TestCase::RxErrorCallback, this));
2205  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/$ns3::RegularWifiMac/BE_Txop/BlockAckManager/AgreementState", MakeCallback (&Bug2470TestCase::AddbaStateChangedCallback, this));
2206 
2207  Simulator::Schedule (Seconds (0.5), &Bug2470TestCase::SendPacketBurst, this, 1, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2208  Simulator::Schedule (Seconds (0.5) + MicroSeconds (5), &Bug2470TestCase::SendPacketBurst, this, 4, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2209  Simulator::Schedule (Seconds (0.8), &Bug2470TestCase::SendPacketBurst, this, 1, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2210  Simulator::Schedule (Seconds (0.8) + MicroSeconds (5), &Bug2470TestCase::SendPacketBurst, this, 4, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2211 
2212  Simulator::Stop (Seconds (1.0));
2213  Simulator::Run ();
2214  Simulator::Destroy ();
2215 }
2216 
2217 void
2219 {
2220  // Create ReceiveListErrorModel to corrupt ADDBA req packet. We use ReceiveListErrorModel
2221  // instead of ListErrorModel since packet UID is incremented between simulations. But
2222  // problem may occur because of random stream, therefore we suppress usage of RNG as
2223  // much as possible (i.e., removing beacon jitter).
2224  Ptr<ReceiveListErrorModel> staPem = CreateObject<ReceiveListErrorModel> ();
2225  std::list<uint32_t> blackList;
2226  // Block ADDBA request 6 times (== maximum number of MAC frame transmissions in the ADDBA response timeout interval)
2227  blackList.push_back (8);
2228  blackList.push_back (9);
2229  blackList.push_back (10);
2230  blackList.push_back (11);
2231  blackList.push_back (12);
2232  blackList.push_back (13);
2233  staPem->SetList (blackList);
2234 
2235  {
2236  RunSubtest (PointerValue (), PointerValue (staPem));
2237  NS_TEST_ASSERT_MSG_EQ (m_failedActionCount, 6, "ADDBA request packets are not failed");
2238  // There are two sets of 5 packets to be transmitted. The first 5 packets should be sent by normal
2239  // MPDU because of failed ADDBA handshake. For the second set, the first packet should be sent by
2240  // normal MPDU, and the rest with A-MPDU. In total we expect to receive 2 normal MPDU packets and
2241  // 8 A-MPDU packets.
2242  NS_TEST_ASSERT_MSG_EQ (m_receivedNormalMpduCount, 2, "Receiving incorrect number of normal MPDU packet on subtest 1");
2243  NS_TEST_ASSERT_MSG_EQ (m_receivedAmpduCount, 8, "Receiving incorrect number of A-MPDU packet on subtest 1");
2244 
2245  NS_TEST_ASSERT_MSG_EQ (m_addbaEstablishedCount, 1, "Incorrect number of times the ADDBA state machine was in established state on subtest 1");
2246  NS_TEST_ASSERT_MSG_EQ (m_addbaPendingCount, 1, "Incorrect number of times the ADDBA state machine was in pending state on subtest 1");
2247  NS_TEST_ASSERT_MSG_EQ (m_addbaRejectedCount, 0, "Incorrect number of times the ADDBA state machine was in rejected state on subtest 1");
2248  NS_TEST_ASSERT_MSG_EQ (m_addbaNoReplyCount, 0, "Incorrect number of times the ADDBA state machine was in no_reply state on subtest 1");
2249  NS_TEST_ASSERT_MSG_EQ (m_addbaResetCount, 0, "Incorrect number of times the ADDBA state machine was in reset state on subtest 1");
2250  }
2251 
2254  m_failedActionCount = 0;
2256  m_addbaPendingCount = 0;
2258  m_addbaNoReplyCount = 0;
2259  m_addbaResetCount = 0;
2260 
2261  Ptr<ReceiveListErrorModel> apPem = CreateObject<ReceiveListErrorModel> ();
2262  blackList.clear ();
2263  // Block ADDBA request 3 times (== maximum number of MAC frame transmissions in the ADDBA response timeout interval)
2264  blackList.push_back (4);
2265  blackList.push_back (5);
2266  blackList.push_back (6);
2267  apPem->SetList (blackList);
2268 
2269  {
2270  RunSubtest (PointerValue (apPem), PointerValue ());
2271  NS_TEST_ASSERT_MSG_EQ (m_failedActionCount, 3, "ADDBA response packets are not failed");
2272  // Similar to subtest 1, we also expect to receive 6 normal MPDU packets and 4 A-MPDU packets.
2273  NS_TEST_ASSERT_MSG_EQ (m_receivedNormalMpduCount, 6, "Receiving incorrect number of normal MPDU packet on subtest 2");
2274  NS_TEST_ASSERT_MSG_EQ (m_receivedAmpduCount, 4, "Receiving incorrect number of A-MPDU packet on subtest 2");
2275 
2276  NS_TEST_ASSERT_MSG_EQ (m_addbaEstablishedCount, 1, "Incorrect number of times the ADDBA state machine was in established state on subtest 2");
2277  NS_TEST_ASSERT_MSG_EQ (m_addbaPendingCount, 1, "Incorrect number of times the ADDBA state machine was in pending state on subtest 2");
2278  NS_TEST_ASSERT_MSG_EQ (m_addbaRejectedCount, 0, "Incorrect number of times the ADDBA state machine was in rejected state on subtest 2");
2279  NS_TEST_ASSERT_MSG_EQ (m_addbaNoReplyCount, 1, "Incorrect number of times the ADDBA state machine was in no_reply state on subtest 2");
2280  NS_TEST_ASSERT_MSG_EQ (m_addbaResetCount, 0, "Incorrect number of times the ADDBA state machine was in reset state on subtest 2");
2281  }
2282 
2283  // TODO: In the second test set, it does not go to reset state since ADDBA response is received after timeout (NO_REPLY)
2284  // but before it does not enter RESET state. More tests should be written to verify all possible scenarios.
2285 }
2286 
2287 //-----------------------------------------------------------------------------
2303 {
2304 public:
2305  Issue40TestCase ();
2306  virtual ~Issue40TestCase ();
2307  void DoRun (void) override;
2308 
2309 private:
2314  void RunOne (bool useAmpdu);
2315 
2321  void RxSuccessCallback (std::string context, Ptr<const Packet> p);
2328  void SendPackets (uint8_t numPackets, Ptr<NetDevice> sourceDevice, Address& destination);
2334  void TxFinalDataFailedCallback (std::string context, Mac48Address address);
2335 
2336  uint16_t m_rxCount;
2337  uint16_t m_txCount;
2339 };
2340 
2342  : TestCase ("Test case for issue #40"),
2343  m_rxCount (0),
2344  m_txCount (0),
2345  m_txMacFinalDataFailedCount (0)
2346 {
2347 }
2348 
2350 {
2351 }
2352 
2353 void
2355 {
2356  m_rxCount++;
2357 }
2358 
2359 void
2360 Issue40TestCase::SendPackets (uint8_t numPackets, Ptr<NetDevice> sourceDevice, Address& destination)
2361 {
2362  for (uint8_t i = 0; i < numPackets; i++)
2363  {
2364  Ptr<Packet> pkt = Create<Packet> (1000); // 1000 dummy bytes of data
2365  sourceDevice->Send (pkt, destination, 0);
2366  m_txCount++;
2367  }
2368 }
2369 
2370 void
2372 {
2374 }
2375 
2376 void
2378 {
2379  m_rxCount = 0;
2380  m_txCount = 0;
2382 
2383  RngSeedManager::SetSeed (1);
2384  RngSeedManager::SetRun (1);
2385  int64_t streamNumber = 100;
2386 
2387  NodeContainer wifiApNode, wifiStaNode;
2388  wifiApNode.Create (1);
2389  wifiStaNode.Create (1);
2390 
2392  YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
2393  phy.SetChannel (channel.Create ());
2394 
2395  WifiHelper wifi;
2396  wifi.SetStandard (WIFI_STANDARD_80211ac);
2397  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
2398 
2400  NetDeviceContainer apDevice;
2401  mac.SetType ("ns3::ApWifiMac");
2402  apDevice = wifi.Install (phy, mac, wifiApNode);
2403 
2404  NetDeviceContainer staDevice;
2405  mac.SetType ("ns3::StaWifiMac");
2406  staDevice = wifi.Install (phy, mac, wifiStaNode);
2407 
2408  // Assign fixed streams to random variables in use
2409  wifi.AssignStreams (apDevice, streamNumber);
2410  wifi.AssignStreams (staDevice, streamNumber);
2411 
2413  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
2414  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
2415  positionAlloc->Add (Vector (10.0, 0.0, 0.0));
2416  mobility.SetPositionAllocator (positionAlloc);
2417 
2418  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
2419  mobility.Install (wifiApNode);
2420 
2421  mobility.SetMobilityModel("ns3::WaypointMobilityModel");
2422  mobility.Install (wifiStaNode);
2423 
2424  Config::Connect ("/NodeList/*/DeviceList/*/RemoteStationManager/MacTxFinalDataFailed", MakeCallback (&Issue40TestCase::TxFinalDataFailedCallback, this));
2425  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/$ns3::WifiMac/MacRx", MakeCallback (&Issue40TestCase::RxSuccessCallback, this));
2426 
2427  Ptr<WaypointMobilityModel> staWaypointMobility = DynamicCast<WaypointMobilityModel>(wifiStaNode.Get(0)->GetObject<MobilityModel>());
2428  staWaypointMobility->AddWaypoint (Waypoint (Seconds(1.0), Vector (10.0, 0.0, 0.0)));
2429  staWaypointMobility->AddWaypoint (Waypoint (Seconds(1.5), Vector (50.0, 0.0, 0.0)));
2430 
2431  if (useAmpdu)
2432  {
2433  // 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
2434  Ptr<WifiNetDevice> ap_device = DynamicCast<WifiNetDevice> (apDevice.Get (0));
2435  Ptr<RegularWifiMac> ap_mac = DynamicCast<RegularWifiMac> (ap_device->GetMac ());
2436  NS_ASSERT (ap_mac);
2437  PointerValue ptr;
2438  ap_mac->GetAttribute ("BE_Txop", ptr);
2439  ptr.Get<QosTxop> ()->SetAttribute ("UseExplicitBarAfterMissedBlockAck", BooleanValue (false));
2440  }
2441 
2442  // Transmit a first data packet before the station moves: it should be sent with a high modulation and successfully received
2443  Simulator::Schedule (Seconds (0.5), &Issue40TestCase::SendPackets, this, useAmpdu ? 2 : 1, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2444 
2445  // 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
2446  Simulator::Schedule (Seconds (2.0), &Issue40TestCase::SendPackets, this, useAmpdu ? 2 : 1, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2447 
2448  // 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
2449  Simulator::Schedule (Seconds (2.1), &Issue40TestCase::SendPackets, this, useAmpdu ? 2 : 1, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2450  Simulator::Schedule (Seconds (2.2), &Issue40TestCase::SendPackets, this, useAmpdu ? 2 : 1, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2451  Simulator::Schedule (Seconds (2.3), &Issue40TestCase::SendPackets, this, useAmpdu ? 2 : 1, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2452  Simulator::Schedule (Seconds (2.4), &Issue40TestCase::SendPackets, this, useAmpdu ? 2 : 1, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2453  Simulator::Schedule (Seconds (2.5), &Issue40TestCase::SendPackets, this, useAmpdu ? 2 : 1, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2454 
2455  Simulator::Stop (Seconds (3.0));
2456  Simulator::Run ();
2457 
2458  NS_TEST_ASSERT_MSG_EQ (m_txCount, (useAmpdu ? 14 : 7), "Incorrect number of transmitted packets");
2459  NS_TEST_ASSERT_MSG_EQ (m_rxCount, (useAmpdu ? 12 : 6), "Incorrect number of successfully received packets");
2460  NS_TEST_ASSERT_MSG_EQ (m_txMacFinalDataFailedCount, 1, "Incorrect number of dropped TX packets");
2461 
2462  Simulator::Destroy ();
2463 }
2464 
2465 void
2467 {
2468  //Test without A-MPDU
2469  RunOne (false);
2470 
2471  //Test with A-MPDU
2472  RunOne (true);
2473 }
2474 
2475 //-----------------------------------------------------------------------------
2489 {
2490 public:
2491  Issue169TestCase ();
2492  virtual ~Issue169TestCase ();
2493  void DoRun (void) override;
2494 
2495 private:
2503  void SendPackets (uint8_t numPackets, Ptr<NetDevice> sourceDevice, Address& destination, uint8_t priority);
2504 
2512  void TxCallback (std::string context, WifiConstPsduMap psdus, WifiTxVector txVector, double txPowerW);
2513 };
2514 
2516  : TestCase ("Test case for issue #169")
2517 {
2518 }
2519 
2521 {
2522 }
2523 
2524 void
2525 Issue169TestCase::SendPackets (uint8_t numPackets, Ptr<NetDevice> sourceDevice, Address& destination, uint8_t priority)
2526 {
2527  SocketPriorityTag priorityTag;
2528  priorityTag.SetPriority (priority);
2529  for (uint8_t i = 0; i < numPackets; i++)
2530  {
2531  Ptr<Packet> packet = Create<Packet> (1000); // 1000 dummy bytes of data
2532  packet->AddPacketTag (priorityTag);
2533  sourceDevice->Send (packet, destination, 0);
2534  }
2535 }
2536 
2537 void
2538 Issue169TestCase::TxCallback (std::string context, WifiConstPsduMap psdus, WifiTxVector txVector, double txPowerW)
2539 {
2540  if (psdus.begin()->second->GetSize () >= 1000)
2541  {
2542  NS_TEST_ASSERT_MSG_EQ (txVector.GetMode ().GetModulationClass (), WifiModulationClass::WIFI_MOD_CLASS_VHT, "Ideal rate manager selected incorrect modulation class");
2543  }
2544 }
2545 
2546 void
2548 {
2549  RngSeedManager::SetSeed (1);
2550  RngSeedManager::SetRun (1);
2551  int64_t streamNumber = 100;
2552 
2553  NodeContainer wifiApNode, wifiStaNode;
2554  wifiApNode.Create (1);
2555  wifiStaNode.Create (1);
2556 
2558  YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
2559  phy.SetChannel (channel.Create ());
2560 
2561  WifiHelper wifi;
2562  wifi.SetStandard (WIFI_STANDARD_80211ac);
2563  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
2564 
2566  NetDeviceContainer apDevice;
2567  mac.SetType ("ns3::ApWifiMac");
2568  apDevice = wifi.Install (phy, mac, wifiApNode);
2569 
2570  NetDeviceContainer staDevice;
2571  mac.SetType ("ns3::StaWifiMac");
2572  staDevice = wifi.Install (phy, mac, wifiStaNode);
2573 
2574  // Assign fixed streams to random variables in use
2575  wifi.AssignStreams (apDevice, streamNumber);
2576  wifi.AssignStreams (staDevice, streamNumber);
2577 
2579  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
2580  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
2581  positionAlloc->Add (Vector (1.0, 0.0, 0.0));
2582  mobility.SetPositionAllocator (positionAlloc);
2583 
2584  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
2585  mobility.Install (wifiApNode);
2586  mobility.Install (wifiStaNode);
2587 
2588  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::WifiPhy/PhyTxPsduBegin", MakeCallback (&Issue169TestCase::TxCallback, this));
2589 
2590  //Send best-effort packet (i.e. priority 0)
2591  Simulator::Schedule (Seconds (0.5), &Issue169TestCase::SendPackets, this, 1, apDevice.Get (0), staDevice.Get (0)->GetAddress (), 0);
2592 
2593  //Send non best-effort (voice) packet (i.e. priority 6)
2594  Simulator::Schedule (Seconds (1.0), &Issue169TestCase::SendPackets, this, 1, apDevice.Get (0), staDevice.Get (0)->GetAddress (), 6);
2595 
2596  Simulator::Stop (Seconds (2.0));
2597  Simulator::Run ();
2598 
2599  Simulator::Destroy ();
2600 }
2601 
2602 
2603 //-----------------------------------------------------------------------------
2619 {
2620 public:
2623  void DoRun (void) override;
2624 
2625 private:
2630  void ChangeChannelWidth (uint16_t channelWidth);
2631 
2637  void SendPacket (Ptr<NetDevice> sourceDevice, Address& destination);
2638 
2646  void TxCallback (std::string context, WifiConstPsduMap psduMap, WifiTxVector txVector, double txPowerW);
2647 
2652  void CheckLastSelectedMode (WifiMode expectedMode);
2653 
2655 };
2656 
2658  : TestCase ("Test case for use of channel bonding with Ideal rate manager")
2659 {
2660 }
2661 
2663 {
2664 }
2665 
2666 void
2668 {
2669  uint16_t frequency;
2670  switch (channelWidth)
2671  {
2672  case 20:
2673  default:
2674  frequency = 5180;
2675  break;
2676  case 40:
2677  frequency = 5190;
2678  break;
2679  case 80:
2680  frequency = 5210;
2681  break;
2682  case 160:
2683  frequency = 5250;
2684  break;
2685  }
2686  Config::Set ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/Frequency", UintegerValue (frequency));
2687 }
2688 
2689 void
2691 {
2692  Ptr<Packet> packet = Create<Packet> (1000);
2693  sourceDevice->Send (packet, destination, 0);
2694 }
2695 
2696 void
2697 IdealRateManagerChannelWidthTest::TxCallback (std::string context, WifiConstPsduMap psduMap, WifiTxVector txVector, double txPowerW)
2698 {
2699  if (psduMap.begin ()->second->GetSize () >= 1000)
2700  {
2701  m_txMode = txVector.GetMode ();
2702  }
2703 }
2704 
2705 void
2707 {
2708  NS_TEST_ASSERT_MSG_EQ (m_txMode, expectedMode, "Last selected WifiMode " << m_txMode << " does not match expected WifiMode " << expectedMode);
2709 }
2710 
2711 void
2713 {
2714  RngSeedManager::SetSeed (1);
2715  RngSeedManager::SetRun (1);
2716  int64_t streamNumber = 100;
2717 
2718  NodeContainer wifiApNode, wifiStaNode;
2719  wifiApNode.Create (1);
2720  wifiStaNode.Create (1);
2721 
2723  YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
2724  phy.SetChannel (channel.Create ());
2725 
2726  WifiHelper wifi;
2727  wifi.SetStandard (WIFI_STANDARD_80211ac);
2728  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
2729 
2731  NetDeviceContainer apDevice;
2732  mac.SetType ("ns3::ApWifiMac");
2733  apDevice = wifi.Install (phy, mac, wifiApNode);
2734 
2735  NetDeviceContainer staDevice;
2736  mac.SetType ("ns3::StaWifiMac");
2737  staDevice = wifi.Install (phy, mac, wifiStaNode);
2738 
2739  // Assign fixed streams to random variables in use
2740  wifi.AssignStreams (apDevice, streamNumber);
2741  wifi.AssignStreams (staDevice, streamNumber);
2742 
2744  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
2745  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
2746  positionAlloc->Add (Vector (50.0, 0.0, 0.0));
2747  mobility.SetPositionAllocator (positionAlloc);
2748 
2749  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
2750  mobility.Install (wifiApNode);
2751  mobility.Install (wifiStaNode);
2752 
2753  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::WifiPhy/PhyTxPsduBegin", MakeCallback (&IdealRateManagerChannelWidthTest::TxCallback, this));
2754 
2755  //Set channel width to 80 MHz & send packet
2756  Simulator::Schedule (Seconds (0.5), &IdealRateManagerChannelWidthTest::ChangeChannelWidth, this, 80);
2757  Simulator::Schedule (Seconds (1.0), &IdealRateManagerChannelWidthTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2758  //Selected rate should be VHT-MCS 1
2759  Simulator::Schedule (Seconds (1.1), &IdealRateManagerChannelWidthTest::CheckLastSelectedMode, this, VhtPhy::GetVhtMcs1 ());
2760 
2761  //Set channel width to 20 MHz & send packet
2762  Simulator::Schedule (Seconds (1.5), &IdealRateManagerChannelWidthTest::ChangeChannelWidth, this, 20);
2763  Simulator::Schedule (Seconds (2.0), &IdealRateManagerChannelWidthTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2764  //Selected rate should be VHT-MCS 3 since SNR should be 6 dB higher than previously
2765  Simulator::Schedule (Seconds (2.1), &IdealRateManagerChannelWidthTest::CheckLastSelectedMode, this, VhtPhy::GetVhtMcs3 ());
2766 
2767  //Set channel width to 40 MHz & send packet
2768  Simulator::Schedule (Seconds (2.5), &IdealRateManagerChannelWidthTest::ChangeChannelWidth, this, 40);
2769  Simulator::Schedule (Seconds (3.0), &IdealRateManagerChannelWidthTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2770  //Selected rate should be VHT-MCS 2 since SNR should be 3 dB lower than previously
2771  Simulator::Schedule (Seconds (3.1), &IdealRateManagerChannelWidthTest::CheckLastSelectedMode, this, VhtPhy::GetVhtMcs2 ());
2772 
2773  Simulator::Stop (Seconds (3.2));
2774  Simulator::Run ();
2775 
2776  Simulator::Destroy ();
2777 }
2778 
2779 
2780 //-----------------------------------------------------------------------------
2789 {
2790 public:
2792  virtual ~IdealRateManagerMimoTest ();
2793  void DoRun (void) override;
2794 
2795 private:
2801  void SetApMimoSettings (uint8_t antennas, uint8_t maxStreams);
2807  void SetStaMimoSettings (uint8_t antennas, uint8_t maxStreams);
2813  void SendPacket (Ptr<NetDevice> sourceDevice, Address& destination);
2814 
2822  void TxCallback (std::string context, WifiConstPsduMap psdus, WifiTxVector txVector, double txPowerW);
2823 
2828  void CheckLastSelectedMode (WifiMode expectedMode);
2833  void CheckLastSelectedNss (uint8_t expectedNss);
2834 
2836 };
2837 
2839  : TestCase ("Test case for use of imbalanced MIMO settings with Ideal rate manager")
2840 {
2841 }
2842 
2844 {
2845 }
2846 
2847 void
2848 IdealRateManagerMimoTest::SetApMimoSettings (uint8_t antennas, uint8_t maxStreams)
2849 {
2850  Config::Set ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/Antennas", UintegerValue (antennas));
2851  Config::Set ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/MaxSupportedTxSpatialStreams", UintegerValue (maxStreams));
2852  Config::Set ("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Phy/MaxSupportedRxSpatialStreams", UintegerValue (maxStreams));
2853 }
2854 
2855 void
2856 IdealRateManagerMimoTest::SetStaMimoSettings (uint8_t antennas, uint8_t maxStreams)
2857 {
2858  Config::Set ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/Antennas", UintegerValue (antennas));
2859  Config::Set ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/MaxSupportedTxSpatialStreams", UintegerValue (maxStreams));
2860  Config::Set ("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Phy/MaxSupportedRxSpatialStreams", UintegerValue (maxStreams));
2861 }
2862 
2863 void
2865 {
2866  Ptr<Packet> packet = Create<Packet> (1000);
2867  sourceDevice->Send (packet, destination, 0);
2868 }
2869 
2870 void
2871 IdealRateManagerMimoTest::TxCallback (std::string context, WifiConstPsduMap psdus, WifiTxVector txVector, double txPowerW)
2872 {
2873  if (psdus.begin ()->second->GetSize () >= 1000)
2874  {
2875  m_txVector = txVector;
2876  }
2877 }
2878 
2879 void
2881 {
2882  NS_TEST_ASSERT_MSG_EQ (m_txVector.GetNss (), expectedNss, "Last selected Nss " << m_txVector.GetNss () << " does not match expected Nss " << expectedNss);
2883 }
2884 
2885 void
2887 {
2888  NS_TEST_ASSERT_MSG_EQ (m_txVector.GetMode (), expectedMode, "Last selected WifiMode " << m_txVector.GetMode () << " does not match expected WifiMode " << expectedMode);
2889 }
2890 
2891 void
2893 {
2894  RngSeedManager::SetSeed (1);
2895  RngSeedManager::SetRun (1);
2896  int64_t streamNumber = 100;
2897 
2898  NodeContainer wifiApNode, wifiStaNode;
2899  wifiApNode.Create (1);
2900  wifiStaNode.Create (1);
2901 
2903  YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
2904  phy.SetChannel (channel.Create ());
2905 
2906  WifiHelper wifi;
2907  wifi.SetStandard (WIFI_STANDARD_80211ac);
2908  wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
2909 
2911  NetDeviceContainer apDevice;
2912  mac.SetType ("ns3::ApWifiMac");
2913  apDevice = wifi.Install (phy, mac, wifiApNode);
2914 
2915  NetDeviceContainer staDevice;
2916  mac.SetType ("ns3::StaWifiMac");
2917  staDevice = wifi.Install (phy, mac, wifiStaNode);
2918 
2919  // Assign fixed streams to random variables in use
2920  wifi.AssignStreams (apDevice, streamNumber);
2921  wifi.AssignStreams (staDevice, streamNumber);
2922 
2924  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
2925  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
2926  positionAlloc->Add (Vector (40.0, 0.0, 0.0));
2927  mobility.SetPositionAllocator (positionAlloc);
2928 
2929  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
2930  mobility.Install (wifiApNode);
2931  mobility.Install (wifiStaNode);
2932 
2933  Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/$ns3::WifiPhy/PhyTxPsduBegin", MakeCallback (&IdealRateManagerMimoTest::TxCallback, this));
2934 
2935 
2936  // TX: 1 antenna
2937  Simulator::Schedule (Seconds (0.9), &IdealRateManagerMimoTest::SetApMimoSettings, this, 1, 1);
2938  // RX: 1 antenna
2939  Simulator::Schedule (Seconds (0.9), &IdealRateManagerMimoTest::SetStaMimoSettings, this, 1, 1);
2940  // Send packets (2 times to get one feedback)
2941  Simulator::Schedule (Seconds (1.0), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2942  Simulator::Schedule (Seconds (1.1), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2943  // Selected NSS should be 1 since both TX and RX support a single antenna
2944  Simulator::Schedule (Seconds (1.2), &IdealRateManagerMimoTest::CheckLastSelectedNss, this, 1);
2945  // Selected rate should be VHT-MCS 2 because of settings and distance between TX and RX
2946  Simulator::Schedule (Seconds (1.2), &IdealRateManagerMimoTest::CheckLastSelectedMode, this, VhtPhy::GetVhtMcs2 ());
2947 
2948 
2949  // TX: 1 antenna
2950  Simulator::Schedule (Seconds (1.9), &IdealRateManagerMimoTest::SetApMimoSettings, this, 1, 1);
2951  // RX: 2 antennas, but only supports 1 spatial stream
2952  Simulator::Schedule (Seconds (1.9), &IdealRateManagerMimoTest::SetStaMimoSettings, this, 2, 1);
2953  // Send packets (2 times to get one feedback)
2954  Simulator::Schedule (Seconds (2.0), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2955  Simulator::Schedule (Seconds (2.1), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2956  // Selected NSS should be 1 since both TX and RX support a single antenna
2957  Simulator::Schedule (Seconds (2.2), &IdealRateManagerMimoTest::CheckLastSelectedNss, this, 1);
2958  // Selected rate should be increased to VHT-MCS 3 because of RX diversity resulting in SNR improvement of about 3dB
2959  Simulator::Schedule (Seconds (2.2), &IdealRateManagerMimoTest::CheckLastSelectedMode, this, VhtPhy::GetVhtMcs3 ());
2960 
2961 
2962  // TX: 1 antenna
2963  Simulator::Schedule (Seconds (2.9), &IdealRateManagerMimoTest::SetApMimoSettings, this, 1, 1);
2964  // RX: 2 antennas, and supports 2 spatial streams
2965  Simulator::Schedule (Seconds (2.9), &IdealRateManagerMimoTest::SetStaMimoSettings, this, 2, 2);
2966  // Send packets (2 times to get one feedback)
2967  Simulator::Schedule (Seconds (3.0), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2968  Simulator::Schedule (Seconds (3.1), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2969  // Selected NSS should be 1 since TX supports a single antenna
2970  Simulator::Schedule (Seconds (3.2), &IdealRateManagerMimoTest::CheckLastSelectedNss, this, 1);
2971  // Selected rate should be as previously
2972  Simulator::Schedule (Seconds (3.2), &IdealRateManagerMimoTest::CheckLastSelectedMode, this, VhtPhy::GetVhtMcs3 ());
2973 
2974 
2975  // TX: 2 antennas, but only supports 1 spatial stream
2976  Simulator::Schedule (Seconds (3.9), &IdealRateManagerMimoTest::SetApMimoSettings, this, 2, 1);
2977  // RX: 1 antenna
2978  Simulator::Schedule (Seconds (3.9), &IdealRateManagerMimoTest::SetStaMimoSettings, this, 1, 1);
2979  // Send packets (2 times to get one feedback)
2980  Simulator::Schedule (Seconds (4.0), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2981  Simulator::Schedule (Seconds (4.1), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2982  // Selected NSS should be 1 since both TX and RX support a single antenna
2983  Simulator::Schedule (Seconds (4.2), &IdealRateManagerMimoTest::CheckLastSelectedNss, this, 1);
2984  // 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)
2985  Simulator::Schedule (Seconds (4.2), &IdealRateManagerMimoTest::CheckLastSelectedMode, this, VhtPhy::GetVhtMcs2 ());
2986 
2987 
2988  // TX: 2 antennas, but only supports 1 spatial stream
2989  Simulator::Schedule (Seconds (4.9), &IdealRateManagerMimoTest::SetApMimoSettings, this, 2, 1);
2990  // RX: 2 antennas, but only supports 1 spatial stream
2991  Simulator::Schedule (Seconds (4.9), &IdealRateManagerMimoTest::SetStaMimoSettings, this, 2, 1);
2992  // Send packets (2 times to get one feedback)
2993  Simulator::Schedule (Seconds (5.0), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2994  Simulator::Schedule (Seconds (5.1), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
2995  // Selected NSS should be 1 since both TX and RX support a single antenna
2996  Simulator::Schedule (Seconds (5.2), &IdealRateManagerMimoTest::CheckLastSelectedNss, this, 1);
2997  // 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)
2998  Simulator::Schedule (Seconds (5.2), &IdealRateManagerMimoTest::CheckLastSelectedMode, this, VhtPhy::GetVhtMcs3 ());
2999 
3000 
3001  // TX: 2 antennas, but only supports 1 spatial stream
3002  Simulator::Schedule (Seconds (5.9), &IdealRateManagerMimoTest::SetApMimoSettings, this, 2, 1);
3003  // RX: 2 antennas, and supports 2 spatial streams
3004  Simulator::Schedule (Seconds (5.9), &IdealRateManagerMimoTest::SetStaMimoSettings, this, 2, 2);
3005  // Send packets (2 times to get one feedback)
3006  Simulator::Schedule (Seconds (6.0), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
3007  Simulator::Schedule (Seconds (6.1), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
3008  // Selected NSS should be 1 since TX supports a single antenna
3009  Simulator::Schedule (Seconds (6.2), &IdealRateManagerMimoTest::CheckLastSelectedNss, this, 1);
3010  // Selected rate should be as previously
3011  Simulator::Schedule (Seconds (6.2), &IdealRateManagerMimoTest::CheckLastSelectedMode, this, VhtPhy::GetVhtMcs3 ());
3012 
3013 
3014  // TX: 2 antennas, and supports 2 spatial streams
3015  Simulator::Schedule (Seconds (6.9), &IdealRateManagerMimoTest::SetApMimoSettings, this, 2, 2);
3016  // RX: 1 antenna
3017  Simulator::Schedule (Seconds (6.9), &IdealRateManagerMimoTest::SetStaMimoSettings, this, 1, 1);
3018  // Send packets (2 times to get one feedback)
3019  Simulator::Schedule (Seconds (7.0), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
3020  Simulator::Schedule (Seconds (7.1), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
3021  // Selected NSS should be 1 since RX supports a single antenna
3022  Simulator::Schedule (Seconds (7.2), &IdealRateManagerMimoTest::CheckLastSelectedNss, this, 1);
3023  // 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)
3024  Simulator::Schedule (Seconds (7.2), &IdealRateManagerMimoTest::CheckLastSelectedMode, this, VhtPhy::GetVhtMcs2 ());
3025 
3026 
3027  // TX: 2 antennas, and supports 2 spatial streams
3028  Simulator::Schedule (Seconds (7.9), &IdealRateManagerMimoTest::SetApMimoSettings, this, 2, 2);
3029  // RX: 2 antennas, but only supports 1 spatial stream
3030  Simulator::Schedule (Seconds (7.9), &IdealRateManagerMimoTest::SetStaMimoSettings, this, 2, 1);
3031  // Send packets (2 times to get one feedback)
3032  Simulator::Schedule (Seconds (8.0), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
3033  Simulator::Schedule (Seconds (8.1), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
3034  // Selected NSS should be 1 since RX supports a single antenna
3035  Simulator::Schedule (Seconds (8.2), &IdealRateManagerMimoTest::CheckLastSelectedNss, this, 1);
3036  // 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)
3037  Simulator::Schedule (Seconds (8.2), &IdealRateManagerMimoTest::CheckLastSelectedMode, this, VhtPhy::GetVhtMcs3 ());
3038 
3039 
3040  // TX: 2 antennas, and supports 2 spatial streams
3041  Simulator::Schedule (Seconds (8.9), &IdealRateManagerMimoTest::SetApMimoSettings, this, 2, 2);
3042  // RX: 2 antennas, and supports 2 spatial streams
3043  Simulator::Schedule (Seconds (8.9), &IdealRateManagerMimoTest::SetStaMimoSettings, this, 2, 2);
3044  // Send packets (2 times to get one feedback)
3045  Simulator::Schedule (Seconds (9.0), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
3046  Simulator::Schedule (Seconds (9.1), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
3047  // Selected NSS should be 2 since both TX and RX support 2 antennas
3048  Simulator::Schedule (Seconds (9.2), &IdealRateManagerMimoTest::CheckLastSelectedNss, this, 2);
3049  // 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
3050  Simulator::Schedule (Seconds (9.2), &IdealRateManagerMimoTest::CheckLastSelectedMode, this, VhtPhy::GetVhtMcs2 ());
3051 
3052 
3053  // Verify we can go back to initial situation
3054  Simulator::Schedule (Seconds (9.9), &IdealRateManagerMimoTest::SetApMimoSettings, this, 1, 1);
3055  Simulator::Schedule (Seconds (9.9), &IdealRateManagerMimoTest::SetStaMimoSettings, this, 1, 1);
3056  Simulator::Schedule (Seconds (10.0), &IdealRateManagerMimoTest::SendPacket, this, apDevice.Get (0), staDevice.Get (0)->GetAddress ());
3057  Simulator::Schedule (Seconds (10.1), &IdealRateManagerMimoTest::CheckLastSelectedNss, this, 1);
3058  Simulator::Schedule (Seconds (10.1), &IdealRateManagerMimoTest::CheckLastSelectedMode, this, VhtPhy::GetVhtMcs2 ());
3059 
3060  Simulator::Stop (Seconds (10.2));
3061  Simulator::Run ();
3062  Simulator::Destroy ();
3063 }
3064 
3065 //-----------------------------------------------------------------------------
3073 {
3074 public:
3076 
3077 private:
3087  bool CheckDataRate (HeRu::RuType ruType, std::string mcs, uint8_t nss, uint16_t guardInterval, uint16_t expectedDataRate);
3088  void DoRun (void) override;
3089 };
3090 
3092  : TestCase ("Check data rates for different RU types.")
3093 {
3094 }
3095 
3096 bool
3097 HeRuMcsDataRateTestCase::CheckDataRate (HeRu::RuType ruType, std::string mcs, uint8_t nss, uint16_t guardInterval, uint16_t expectedDataRate)
3098 {
3099  uint16_t approxWidth = HeRu::GetBandwidth (ruType);
3100  WifiMode mode (mcs);
3101  uint64_t dataRate = round (mode.GetDataRate (approxWidth, guardInterval, nss) / 100000.0);
3102  NS_ABORT_MSG_IF (dataRate > 65535, "Rate is way too high");
3103  if (static_cast<uint16_t> (dataRate) != expectedDataRate)
3104  {
3105  std::cerr << "RU=" << ruType
3106  << " mode=" << mode
3107  << " Nss=" << +nss
3108  << " guardInterval=" << guardInterval
3109  << " expected=" << expectedDataRate << " x100kbps"
3110  << " computed=" << static_cast<uint16_t> (dataRate) << " x100kbps"
3111  << std::endl;
3112  return false;
3113  }
3114  return true;
3115 }
3116 
3117 void
3119 {
3120  bool retval = true;
3121 
3122  //26-tone RU, browse over all MCSs, GIs and Nss's (up to 4, current max)
3123  retval = retval
3124  && CheckDataRate (HeRu::RU_26_TONE, "HeMcs0", 1, 800, 9)
3125  && CheckDataRate (HeRu::RU_26_TONE, "HeMcs1", 1, 1600, 17)
3126  && CheckDataRate (HeRu::RU_26_TONE, "HeMcs2", 1, 3200, 23)
3127  && CheckDataRate (HeRu::RU_26_TONE, "HeMcs3", 1, 3200, 30)
3128  && CheckDataRate (HeRu::RU_26_TONE, "HeMcs4", 2, 1600, 100)
3129  && CheckDataRate (HeRu::RU_26_TONE, "HeMcs5", 3, 1600, 200)
3130  && CheckDataRate (HeRu::RU_26_TONE, "HeMcs6", 4, 1600, 300)
3131  && CheckDataRate (HeRu::RU_26_TONE, "HeMcs7", 4, 3200, 300)
3132  && CheckDataRate (HeRu::RU_26_TONE, "HeMcs8", 4, 1600, 400)
3133  && CheckDataRate (HeRu::RU_26_TONE, "HeMcs9", 4, 3200, 400)
3134  && CheckDataRate (HeRu::RU_26_TONE, "HeMcs10", 4, 1600, 500)
3135  && CheckDataRate (HeRu::RU_26_TONE, "HeMcs11", 4, 3200, 500);
3136 
3137  NS_TEST_EXPECT_MSG_EQ (retval, true, "26-tone RU data rate verification for different MCSs, GIs, and Nss's failed");
3138 
3139  //Check other RU sizes
3140  retval = retval
3141  && CheckDataRate ( HeRu::RU_52_TONE, "HeMcs2", 1, 1600, 50)
3142  && CheckDataRate ( HeRu::RU_106_TONE, "HeMcs9", 1, 800, 500)
3143  && CheckDataRate ( HeRu::RU_242_TONE, "HeMcs5", 1, 1600, 650)
3144  && CheckDataRate ( HeRu::RU_484_TONE, "HeMcs3", 1, 1600, 650)
3145  && CheckDataRate ( HeRu::RU_996_TONE, "HeMcs5", 1, 3200, 2450)
3146  && CheckDataRate (HeRu::RU_2x996_TONE, "HeMcs3", 1, 3200, 2450);
3147 
3148  NS_TEST_EXPECT_MSG_EQ (retval, true, "Data rate verification for RUs above 52-tone RU (included) failed");
3149 }
3150 
3157 class WifiTestSuite : public TestSuite
3158 {
3159 public:
3160  WifiTestSuite ();
3161 };
3162 
3164  : TestSuite ("wifi-devices", UNIT)
3165 {
3166  AddTestCase (new WifiTest, TestCase::QUICK);
3167  AddTestCase (new QosUtilsIsOldPacketTest, TestCase::QUICK);
3168  AddTestCase (new InterferenceHelperSequenceTest, TestCase::QUICK); //Bug 991
3169  AddTestCase (new DcfImmediateAccessBroadcastTestCase, TestCase::QUICK);
3170  AddTestCase (new Bug730TestCase, TestCase::QUICK); //Bug 730
3171  AddTestCase (new QosFragmentationTestCase, TestCase::QUICK);
3172  AddTestCase (new SetChannelFrequencyTest, TestCase::QUICK);
3173  AddTestCase (new Bug2222TestCase, TestCase::QUICK); //Bug 2222
3174  AddTestCase (new Bug2843TestCase, TestCase::QUICK); //Bug 2843
3175  AddTestCase (new Bug2831TestCase, TestCase::QUICK); //Bug 2831
3176  AddTestCase (new StaWifiMacScanningTestCase, TestCase::QUICK); //Bug 2399
3177  AddTestCase (new Bug2470TestCase, TestCase::QUICK); //Bug 2470
3178  AddTestCase (new Issue40TestCase, TestCase::QUICK); //Issue #40
3179  AddTestCase (new Issue169TestCase, TestCase::QUICK); //Issue #169
3180  AddTestCase (new IdealRateManagerChannelWidthTest, TestCase::QUICK);
3181  AddTestCase (new IdealRateManagerMimoTest, TestCase::QUICK);
3182  AddTestCase (new HeRuMcsDataRateTestCase, TestCase::QUICK);
3183 }
3184 
WifiModulationClass
This enumeration defines the modulation classes per (Table 10-6 "Modulation classes"; IEEE 802...
MpduInfo structure.
Definition: phy-entity.h:59
size_t GetNumBands() const
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
void RunOne(void)
Run one function.
Definition: wifi-test.cc:174
void Set(std::string name, const AttributeValue &v)
Definition: wifi-helper.cc:140
uint32_t AddApplication(Ptr< Application > application)
Associate an Application to this Node.
Definition: node.cc:159
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
void SetStopTime(Time stop)
Specify application stop time.
Definition: application.cc:75
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
void AddbaStateChangedCallback(std::string context, Time t, Mac48Address recipient, uint8_t tid, OriginatorBlockAckAgreement::State state)
Callback when ADDBA state changed.
Definition: wifi-test.cc:2093
virtual ~Bug730TestCase()
Definition: wifi-test.cc:624
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
void SetType(std::string type, Args &&... args)
virtual ~QosFragmentationTestCase()
Definition: wifi-test.cc:770
void Transmit(std::string context, Ptr< const Packet > p, double power)
Callback invoked when PHY transmits a packet.
Definition: wifi-test.cc:784
uint16_t m_countOperationalChannelWidth20
count number of beacon frames announcing a 20 MHz operating channel width
Definition: wifi-test.cc:1652
AttributeValue implementation for Boolean.
Definition: boolean.h:36
virtual void SetProtectionManager(Ptr< WifiProtectionManager > protectionManager)
Set the Protection Manager to use.
Ptr< T > Get(void) const
Definition: pointer.h:201
void SetLocal(PacketSocketAddress addr)
set the local address and protocol to be used
void TxFinalDataFailedCallback(std::string context, Mac48Address address)
Transmit final data failed function.
Definition: wifi-test.cc:2371
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
void Receive(std::string context, Ptr< const Packet > p, const Address &adr)
Receive function.
Definition: wifi-test.cc:629
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:852
void StoreDistinctTuple(std::string context, Ptr< SpectrumSignalParameters > txParams)
Stores the distinct {starting frequency, channelWidth, Number of subbands in SpectrumModel, modulation type} tuples that have been used during the testcase run.
Definition: wifi-test.cc:1494
Ptr< WifiPpdu > ppdu
The PPDU being transmitted.
Hold variables of type string.
Definition: string.h:41
Make sure that the ADDBA handshake process is protected.
Definition: wifi-test.cc:2016
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:796
Make it easy to create and manage PHY objects for the YANS model.
void Set(std::string path, const AttributeValue &value)
Definition: config.cc:839
void SetOperatingChannel(uint8_t number, uint16_t frequency, uint16_t width)
Set the operating channel according to the specified parameters.
Definition: wifi-phy.cc:1256
void SetChannel(const Ptr< YansWifiChannel > channel)
Set the YansWifiChannel this YansWifiPhy is to be connected to.
virtual ~IdealRateManagerMimoTest()
Definition: wifi-test.cc:2843
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Definition: node.cc:144
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:1679
A suite of tests to run.
Definition: test.h:1343
void AddWaypoint(const Waypoint &waypoint)
virtual void ConfigureStandardAndBand(WifiPhyStandard standard, WifiPhyBand band)
Configure the PHY-level parameters for different Wi-Fi standard.
Definition: wifi-phy.cc:1069
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition: object.cc:252
Handle packet fragmentation and retransmissions for QoS data frames as well as MSDU aggregation (A-MS...
Definition: qos-txop.h:74
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:2547
an address for a packet socket
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:2218
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
uint16_t m_receivedNormalMpduCount
Count received normal MPDU packets on STA.
Definition: wifi-test.cc:2065
uint16_t m_rxCount
Count number of successfully received data packets.
Definition: wifi-test.cc:2336
uint16_t m_receivedAmpduCount
Count received A-MPDU packets on STA.
Definition: wifi-test.cc:2066
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
#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:283
Make sure that Ideal rate manager is able to handle non best-effort traffic.
Definition: wifi-test.cc:2488
void SetMobility(const Ptr< MobilityModel > mobility)
assign a mobility model to this device
Definition: wifi-phy.cc:789
The HT Operation Information ElementThis class knows how to serialise and deserialise the HT Operatio...
Definition: ht-operation.h:50
staDevices
Definition: third.py:103
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
HtOperation GetHtOperation(void) const
Return the HT operation.
Definition: mgt-headers.cc:262
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:351
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:1526
The 5 GHz band.
Definition: wifi-phy-band.h:37
Qos Utils Is Old Packet Test.
Definition: wifi-test.cc:230
encapsulates test code
Definition: test.h:1153
void AddPropagationLossModel(Ptr< PropagationLossModel > loss)
Add the single-frequency propagation loss model to be used.
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.
virtual ~StaWifiMacScanningTestCase()
Definition: wifi-test.cc:1864
Make sure that when changing the fragmentation threshold during the simulation, the TCP transmission ...
Definition: wifi-test.cc:596
virtual ~Bug2843TestCase()
Definition: wifi-test.cc:1489
void AssocCallback(std::string context, Mac48Address bssid)
Callback function on STA assoc event.
Definition: wifi-test.cc:1869
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:926
helps to create WifiNetDevice objects
Definition: wifi-helper.h:326
Mac48Address m_associatedApBssid
Associated AP&#39;s bssid.
Definition: wifi-test.cc:1856
Make sure that Ideal rate manager recovers when the station is moving away from the access point...
Definition: wifi-test.cc:2302
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:47
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:639
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:3097
Give ns3::PacketSocket powers to ns3::Node.
void SetSingleDevice(uint32_t device)
Set the address to match only a specified NetDevice.
a polymophic address class
Definition: address.h:90
unsigned int m_numSentPackets
number of sent packets
Definition: wifi-test.cc:464
channel
Definition: third.py:92
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:2360
mobility
Definition: third.py:108
ObjectFactory m_propDelay
propagation delay
Definition: wifi-test.cc:460
phy
Definition: third.py:93
void SetDevice(const Ptr< NetDevice > device)
Sets the device this PHY is associated with.
Definition: wifi-phy.cc:777
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...
virtual ~Issue169TestCase()
Definition: wifi-test.cc:2520
uint16_t m_countOperationalChannelWidth40
count number of beacon frames announcing a 40 MHz operating channel width
Definition: wifi-test.cc:1653
uint16_t GetChannelWidth(void) const
Definition: wifi-phy.cc:1233
void CheckLastSelectedMode(WifiMode expectedMode)
Check if the selected WifiMode is correct.
Definition: wifi-test.cc:2706
uint16_t m_addbaRejectedCount
Count number of times ADDBA state machine is in rejected state.
Definition: wifi-test.cc:2070
uint16_t m_addbaEstablishedCount
Count number of times ADDBA state machine is in established state.
Definition: wifi-test.cc:2068
void SetWifiMac(Ptr< RegularWifiMac > mac)
Set the MAC which is using this Acknowledgment Manager.
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:2864
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:1950
void TurnBeaconGenerationOn(Ptr< Node > apNode)
Turn beacon generation on the AP node.
Definition: wifi-test.cc:1875
Keep track of the current position and velocity of an object.
void SetStaMimoSettings(uint8_t antennas, uint8_t maxStreams)
Change the configured MIMO settings for STA node.
Definition: wifi-test.cc:2856
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:2116
The MPDU is not part of an A-MPDU.
bool IsAction(void) const
Return true if the header is an Action header.
virtual ~Bug2470TestCase()
Definition: wifi-test.cc:2088
Ptr< Node > CreateOne(Vector pos, Ptr< YansWifiChannel > channel)
Create one function.
Definition: wifi-test.cc:313
virtual void SetAckManager(Ptr< WifiAckManager > ackManager)
Set the Acknowledgment Manager to use.
base class for all MAC-level wifi objects.
virtual ~Bug2831TestCase()
Definition: wifi-test.cc:1665
nodes
Definition: first.py:32
Make sure that Wifi STA is correctly associating to the best AP (i.e., nearest from STA)...
Definition: wifi-test.cc:1824
uint32_t GetIfIndex(void) const override
void SetDevice(const Ptr< NetDevice > device)
Sets the device this PHY is associated with.
Definition: wifi-mac.cc:85
Time m_firstTransmissionTime
first transmission time
Definition: wifi-test.cc:462
uint16_t m_reassocReqCount
count number of reassociation requests
Definition: wifi-test.cc:1650
void Receive(std::string context, Ptr< const Packet > p, const Address &adr)
Receive function.
Definition: wifi-test.cc:775
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
WifiMode m_txMode
Store the last selected mode to send data packet.
Definition: wifi-test.cc:2654
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Definition: txop.cc:303
bool IsBeacon(void) const
Return true if the header is a Beacon header.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
uint32_t m_countInternalCollisions
count internal collisions
Definition: wifi-test.cc:1324
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:1709
void SetChannel(Ptr< SpectrumChannel > channel)
Hold an unsigned integer type.
Definition: uinteger.h:44
Address GetAddress(void) const override
Vector3D Vector
Definition: vector.h:297
ssid
Definition: third.py:100
#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:166
void SetWifiMac(Ptr< RegularWifiMac > mac)
Set the MAC which is using this Protection Manager.
holds a vector of ns3::NetDevice pointers
mac
Definition: third.py:99
indicates whether the socket has a priority set.
Definition: socket.h:1308
void RunOne(bool useAmpdu)
Run one function.
Definition: wifi-test.cc:2377
calculate a propagation delay.
Hold together all Wifi-related objects.
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:290
wifiApNode
Definition: third.py:90
Make sure that the channel width and the channel number can be changed at runtime.
Definition: wifi-test.cc:1627
uint16_t m_addbaResetCount
Count number of times ADDBA state machine is in reset state.
Definition: wifi-test.cc:2072
void SetAddress(Mac48Address address) override
ObjectFactory m_mac
MAC.
Definition: wifi-test.cc:289
hold a list of per-remote-station state.
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:159
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:920
uint32_t m_fragments
transmitted fragments
Definition: wifi-test.cc:744
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:2690
void SetErrorRateModel(const Ptr< ErrorRateModel > rate)
Sets the error rate model.
Definition: wifi-phy.cc:808
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
void SwitchCh(Ptr< WifiNetDevice > dev)
Switch channel function.
Definition: wifi-test.cc:306
Ptr< FrameExchangeManager > GetFrameExchangeManager(void) const
Get the Frame Exchange Manager.
Ptr< WifiPhy > GetPhy(void) const
Bands::const_iterator Begin() const
Const Iterator to the model Bands container start.
Ptr< YansWifiPhy > m_staPhy
STA PHY.
Definition: wifi-test.cc:1648
void CheckLastSelectedMode(WifiMode expectedMode)
Check if the selected WifiMode is correct.
Definition: wifi-test.cc:2886
OFDM PHY (Clause 17)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
void SetApMimoSettings(uint8_t antennas, uint8_t maxStreams)
Change the configured MIMO settings for AP node.
Definition: wifi-test.cc:2848
Hold objects of type Ptr<T>.
Definition: pointer.h:36
bool IsData(void) const
Return true if the Type is DATA.
address
Definition: first.py:44
void NotifyPhyTxBegin(Ptr< const Packet > p, double txPowerW)
Notify Phy transmit begin.
Definition: wifi-test.cc:480
static WifiTestSuite g_wifiTestSuite
the test suite
Definition: wifi-test.cc:3185
uint16_t GetFrequency(void) const
Definition: wifi-phy.cc:1168
802.11 PHY layer modelThis PHY implements a model of 802.11a.
Definition: yans-wifi-phy.h:47
ObjectFactory m_mac
MAC.
Definition: wifi-test.cc:120
void TxCallback(std::string context, WifiConstPsduMap psdus, WifiTxVector txVector, double txPowerW)
Callback that indicates a PSDU is being transmitted.
Definition: wifi-test.cc:2871
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)=0
uint32_t m_received
received packets
Definition: wifi-test.cc:743
void SetList(const std::list< uint32_t > &packetlist)
Definition: error-model.cc:520
RuType
The different HE Resource Unit (RU) types.
Definition: he-ru.h:41
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:1537
uint16_t m_addbaPendingCount
Count number of times ADDBA state machine is in pending state.
Definition: wifi-test.cc:2069
an EUI-48 address
Definition: mac48-address.h:43
ObjectFactory m_manager
manager
Definition: wifi-test.cc:458
NodeContainer Setup(bool nearestApBeaconGeneration, bool staActiveProbe)
Setup test.
Definition: wifi-test.cc:1891
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:193
virtual ~Bug2222TestCase()
Definition: wifi-test.cc:1340
Ptr< const SpectrumModel > GetSpectrumModel() const
virtual void SetChannelNumber(uint8_t id)
Set channel number.
Definition: wifi-phy.cc:1174
manage and create wifi channel objects for the YANS model.
ObjectFactory m_propDelay
propagation delay
Definition: wifi-test.cc:121
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:1352
void SendOnePacket(Ptr< WifiNetDevice > dev)
Send one packet function.
Definition: wifi-test.cc:494
uint8_t GetChannelNumber(void) const
Return current channel number.
Definition: wifi-phy.cc:1199
create MAC layers for a ns3::WifiNetDevice.
void SendOnePacket(Ptr< LrWpanPhy > sender, Ptr< LrWpanPhy > receiver)
Send one packet.
State
Represents the state for this agreement.
void RxSuccessCallback(std::string context, Ptr< const Packet > p)
Callback when packet is successfully received.
Definition: wifi-test.cc:2354
Address GetBroadcast(void) const override
void ChangeChannelWidth(uint16_t channelWidth)
Change the configured channel width for all nodes.
Definition: wifi-test.cc:2667
void SetErrorRateModel(std::string name, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
Definition: wifi-helper.cc:146
Test to validate that Ideal rate manager properly selects TXVECTOR in scenarios where MIMO is used...
Definition: wifi-test.cc:2788
bool IsSet(void) const
Return true if a valid channel has been set, false otherwise.
void TxCallback(std::string context, WifiConstPsduMap psduMap, WifiTxVector txVector, double txPowerW)
Callback that indicates a PSDU is being transmitted.
Definition: wifi-test.cc:2697
void SetPosition(const Vector &position)
The IEEE 802.11 SSID Information Element.
Definition: ssid.h:35
Make sure that the correct channel width and center frequency have been set for OFDM basic rate trans...
Definition: wifi-test.cc:1451
ObjectFactory m_propDelay
propagation delay
Definition: wifi-test.cc:290
void RxErrorCallback(std::string context, Ptr< const Packet > p, double snr)
Callback when packet is dropped.
Definition: wifi-test.cc:2135
Wifi Test Suite.
Definition: wifi-test.cc:3157
Make sure that when virtual collision occurs the wifi remote station manager is triggered and the ret...
Definition: wifi-test.cc:1314
bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber) override
std::tuple< double, uint16_t, uint32_t, WifiModulationClass > FreqWidthSubbandModulationTuple
A tuple of {starting frequency, channelWidth, Number of subbands in SpectrumModel, modulation type}.
Definition: wifi-test.cc:1462
uint16_t m_txCount
Count number of transmitted data packets.
Definition: wifi-test.cc:2337
void RunSubtest(PointerValue apErrorModel, PointerValue staErrorModel)
Run subtest for this test suite.
Definition: wifi-test.cc:2158
wifi
Definition: third.py:96
uint8_t GetStaChannelWidth(void) const
Return the STA channel width.
Helper class used to assign positions and mobility models to nodes.
ObjectFactory m_manager
manager
Definition: wifi-test.cc:119
Instantiate subclasses of ns3::Object.
Ptr< WifiMac > GetMac(void) const
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Definition: node.cc:130
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
void AddPacketTag(const Tag &tag) const
Add a packet tag.
Definition: packet.cc:956
void SetRemote(PacketSocketAddress addr)
set the remote address and protocol to be used
Ptr< SpectrumValue > psd
The Power Spectral Density of the waveform, in linear units.
void TxCallback(std::string context, WifiConstPsduMap psdus, WifiTxVector txVector, double txPowerW)
Callback that indicates a PSDU is being transmitted.
Definition: wifi-test.cc:2538
static void AssignWifiRandomStreams(Ptr< WifiMac > mac, int64_t stream)
Definition: wifi-test.cc:61
SignalNoiseDbm structure.
Definition: phy-entity.h:52
virtual void SetChannelWidth(uint16_t channelWidth)
If the operating channel for this object has not been set yet, the given channel width is saved and w...
Definition: wifi-phy.cc:1205
Ptr< YansWifiPhy > m_apPhy
AP PHY.
Definition: wifi-test.cc:1647
void SetPropagationDelayModel(Ptr< PropagationDelayModel > delay)
Set the propagation delay model to be used.
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:2892
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
AttributeValue implementation for Ssid.
Definition: ssid.h:105
ObjectFactory m_manager
manager
Definition: wifi-test.cc:288
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:2147
bool IsReassocReq(void) const
Return true if the header is a Reassociation Request header.
uint32_t m_received
received
Definition: wifi-test.cc:606
void Add(Vector v)
Add a position to the list of positions.
void SendOnePacket(Ptr< WifiNetDevice > dev)
Send one packet function.
Definition: wifi-test.cc:299
void ConfigureStandard(WifiStandard standard) override
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
apDevices
Definition: third.py:106
void Install(Ptr< Node > node) const
Aggregate an instance of a ns3::PacketSocketFactory onto the provided node.
Data rate verification test for MCSs of different RU sizes.
Definition: wifi-test.cc:3072
WifiTxVector m_txVector
Store the last TXVECTOR used to transmit Data.
Definition: wifi-test.cc:2835
Make sure that Ideal rate manager properly selects MCS based on the configured channel width...
Definition: wifi-test.cc:2618
void TurnApOff(Ptr< Node > apNode)
Turn the AP node off.
Definition: wifi-test.cc:1883
uint16_t m_txMacFinalDataFailedCount
Count number of unsuccessfully transmitted data packets.
Definition: wifi-test.cc:2338
bool IsQosData(void) const
Return true if the Type is DATA and Subtype is one of the possible values for QoS Data...
void SendOnePacket(Ptr< WifiNetDevice > dev)
Send one packet function.
Definition: wifi-test.cc:130
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:2466
void CheckLastSelectedNss(uint8_t expectedNss)
Check if the selected Nss is correct.
Definition: wifi-test.cc:2880
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1305
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
uint16_t m_addbaNoReplyCount
Count number of times ADDBA state machine is in no_reply state.
Definition: wifi-test.cc:2071
Wifi Test.
Definition: wifi-test.cc:96
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
virtual ~Issue40TestCase()
Definition: wifi-test.cc:2349
uint16_t GetChannelWidth(void) const
const WifiPhyOperatingChannel & GetOperatingChannel(void) const
Get a const reference to the operating channel.
Definition: wifi-phy.cc:1137
std::vector< FreqWidthSubbandModulationTuple > m_distinctTuples
vector of distinct {starting frequency, channelWidth, Number of subbands in SpectrumModel, modulation type} tuples
Definition: wifi-test.cc:1463
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:501
void TxDataFailedTrace(std::string context, Mac48Address adr)
Transmit data failed function.
Definition: wifi-test.cc:1345
Time m_secondTransmissionTime
second transmission time
Definition: wifi-test.cc:463
void ChangeSupportedChannelWidth(void)
Function called to change the supported channel width at runtime.
Definition: wifi-test.cc:1670
void SetPriority(uint8_t priority)
Set the tag&#39;s priority.
Definition: socket.cc:842
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
Definition: double.h:41
uint16_t m_failedActionCount
Count failed ADDBA request/response.
Definition: wifi-test.cc:2067
MpduType type
type of MPDU
Definition: phy-entity.h:61
Ptr< YansWifiPhy > GetYansWifiPhyPtr(const NetDeviceContainer &nc) const
Get yans wifi phy function.
Definition: wifi-test.cc:918
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:185
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:3118
uint16_t m_reassocRespCount
count number of reassociation responses
Definition: wifi-test.cc:1651
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:2525
a (time, location) pair.
Definition: waypoint.h:35
void GetAttribute(std::string name, AttributeValue &value) const
Get the value of an attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:223
void SetStartTime(Time start)
Specify application start time.
Definition: application.cc:69
std::unordered_map< uint16_t, Ptr< const WifiPsdu > > WifiConstPsduMap
Map of const PSDUs indexed by STA-ID.
#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:922
Implement the header for management frames of type beacon.
Definition: mgt-headers.h:834
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:1642
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:2712
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:100
std::map< WifiSpectrumBand, double > RxPowerWattPerChannelBand
A map of the received power (Watts) for each band.
Definition: phy-entity.h:75
Implements the IEEE 802.11 MAC header.
void CreateOne(Vector pos, Ptr< YansWifiChannel > channel)
Create one function.
Definition: wifi-test.cc:137
bool IsReassocResp(void) const
Return true if the header is a Reassociation Response header.
void DoRun(void) override
Implementation to actually run this TestCase.
Definition: wifi-test.cc:236
Make sure that fragmentation works with QoS stations.
Definition: wifi-test.cc:733
uint16_t m_channelWidth
channel width (in MHz)
Definition: wifi-test.cc:1480
Set Channel Frequency Test.
Definition: wifi-test.cc:894
Make sure that when multiple broadcast packets are queued on the same device in a short succession...
Definition: wifi-test.cc:443
Handle packet fragmentation and retransmissions for data and management frames.
Definition: txop.h:65
Make it easy to create and manage PHY objects for the spectrum model.