22 #include "ns3/string.h"
23 #include "ns3/qos-utils.h"
24 #include "ns3/packet.h"
25 #include "ns3/wifi-net-device.h"
26 #include "ns3/wifi-mac-header.h"
27 #include "ns3/mobility-helper.h"
28 #include "ns3/spectrum-wifi-helper.h"
29 #include "ns3/single-model-spectrum-channel.h"
30 #include "ns3/packet-socket-server.h"
31 #include "ns3/packet-socket-client.h"
32 #include "ns3/packet-socket-helper.h"
33 #include "ns3/config.h"
34 #include "ns3/pointer.h"
35 #include "ns3/rng-seed-manager.h"
36 #include "ns3/wifi-psdu.h"
37 #include "ns3/wifi-ppdu.h"
38 #include "ns3/ap-wifi-mac.h"
79 void CheckResults (
void);
82 void DoRun (
void)
override;
105 :
TestCase (
"Check correct operation within TXOPs"),
109 m_pifsRecovery (pifsRecovery)
131 if (!psduMap.begin ()->second->GetHeader (0).IsBeacon ()
136 psduMap[
SU_STA_ID]->GetHeader (0), txVector});
140 std::cout <<
Simulator::Now () <<
" " << psduMap.begin ()->second->GetHeader (0).GetTypeString ()
141 <<
" seq " << psduMap.begin ()->second->GetHeader (0).GetSequenceNumber ()
142 <<
" to " << psduMap.begin ()->second->GetAddr1 ()
143 <<
" TX duration " << WifiPhy::CalculateTxDuration (psduMap, txVector,
WIFI_PHY_BAND_5GHZ)
144 <<
" duration/ID " << psduMap.begin ()->second->GetHeader (0).GetDuration () << std::endl;
150 RngSeedManager::SetSeed (1);
151 RngSeedManager::SetRun (40);
152 int64_t streamNumber = 100;
167 phy.SetChannel (spectrumChannel);
174 wifi.SetRemoteStationManager (
"ns3::ConstantRateWifiManager",
179 mac.SetType (
"ns3::StaWifiMac",
185 mac.SetType (
"ns3::ApWifiMac",
200 Simulator::Schedule (init + i *
MicroSeconds (102400), &WifiMac::SetSsid,
210 positionAlloc->
Add (Vector (0.0, 0.0, 0.0));
211 positionAlloc->
Add (Vector (1.0, 0.0, 0.0));
212 positionAlloc->
Add (Vector (0.0, 1.0, 0.0));
213 positionAlloc->
Add (Vector (-1.0, 0.0, 0.0));
214 mobility.SetPositionAllocator (positionAlloc);
216 mobility.SetMobilityModel (
"ns3::ConstantPositionMobilityModel");
223 dev->
GetMac ()->GetAttribute (
"BE_Txop", ptr);
272 dev->
GetMac ()->GetWifiPhy ()->SetPostReceptionErrorModel (apPem);
279 dev->
GetMac ()->GetWifiPhy ()->SetPostReceptionErrorModel (sta2Pem);
304 Config::Connect (
"/NodeList/*/ApplicationList/*/$ns3::PacketSocketServer/Rx",
307 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxPsduBegin",
315 Simulator::Destroy ();
325 sifs = DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetPhy ()->GetSifs (),
326 slot = DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetPhy ()->GetSlot (),
330 auto RoundDurationId = [] (
Time t)
332 return MicroSeconds (ceil (
static_cast<double> (t.GetNanoSeconds ()) / 1000));
362 "Expected a QoS data frame");
364 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (0))->GetMac ()->GetAddress (),
365 "Expected a frame sent by the AP to the first station");
368 "Duration/ID of the first frame must cover the whole TXOP");
375 NS_TEST_EXPECT_MSG_LT (tStart, tEnd + sifs + tolerance,
"Ack in response to the first frame sent too late");
378 DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetMac ()->GetAddress (),
379 "Expected a Normal Ack sent to the AP");
381 RoundDurationId (
m_txPsdus[0].header.GetDuration () - sifs -
m_txPsdus[1].txDuration),
382 "Duration/ID of the Ack must be derived from that of the first frame");
393 "Less than AIFS elapsed between AckTimeout and the next TXOP start");
395 "More than AIFS+BO elapsed between AckTimeout and the next TXOP start");
397 "Expected to retransmit a QoS data frame");
399 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (0))->GetMac ()->GetAddress (),
400 "Expected to retransmit a frame to the first station");
403 "Duration/ID of the retransmitted frame must cover the whole TXOP");
410 NS_TEST_EXPECT_MSG_LT (tStart, tEnd + sifs + tolerance,
"Ack in response to the first frame sent too late");
413 DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetMac ()->GetAddress (),
414 "Expected a Normal Ack sent to the AP");
416 RoundDurationId (
m_txPsdus[2].header.GetDuration () - sifs -
m_txPsdus[3].txDuration),
417 "Duration/ID of the Ack must be derived from that of the previous frame");
426 "Expected a QoS data frame");
428 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (1))->GetMac ()->GetAddress (),
429 "Expected a frame sent by the AP to the second station");
432 "Duration/ID of the second frame does not cover the remaining TXOP");
438 + sifs + slot + WifiPhy::CalculatePhyPreambleAndHeaderDuration (
m_txPsdus[4].txVector);
448 "Less than AIFS elapsed between AckTimeout and the next transmission");
450 "More than AIFS+BO elapsed between AckTimeout and the next TXOP start");
453 "Expected a QoS data frame");
455 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (1))->GetMac ()->GetAddress (),
456 "Expected a frame sent by the AP to the second station");
459 "Duration/ID of the second frame does not cover the remaining TXOP");
466 NS_TEST_EXPECT_MSG_LT (tStart, tEnd + sifs + tolerance,
"Ack in response to the second frame sent too late");
469 DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetMac ()->GetAddress (),
470 "Expected a Normal Ack sent to the AP");
472 RoundDurationId (
m_txPsdus[5].header.GetDuration () - sifs -
m_txPsdus[6].txDuration),
473 "Duration/ID of the Ack must be derived from that of the previous frame");
482 "Expected a QoS data frame");
484 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (2))->GetMac ()->GetAddress (),
485 "Expected a frame sent by the AP to the third station");
488 "Duration/ID of the third frame does not cover the remaining TXOP");
495 NS_TEST_EXPECT_MSG_LT (tStart, tEnd + sifs + tolerance,
"Ack in response to the third frame sent too late");
498 DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetMac ()->GetAddress (),
499 "Expected a Normal Ack sent to the AP");
501 RoundDurationId (
m_txPsdus[7].header.GetDuration () - sifs -
m_txPsdus[8].txDuration),
502 "Duration/ID of the Ack must be derived from that of the previous frame");
512 "Duration/ID must be set to 0 for CF-End frames");
519 "Less than AIFS elapsed between two TXOPs");
521 "More than AIFS+BO elapsed between two TXOPs");
523 "Expected a QoS data frame");
525 DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetMac ()->GetAddress (),
526 "Expected a frame sent by the first station to the AP");
529 "Duration/ID of the frame sent by the first station does not cover the remaining TXOP");
539 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (0))->GetMac ()->GetAddress (),
540 "Expected a Normal Ack sent to the first station");
542 RoundDurationId (
m_txPsdus[10].header.GetDuration () - sifs -
m_txPsdus[11].txDuration),
543 "Duration/ID of the Ack must be derived from that of the previous frame");
553 "Duration/ID must be set to 0 for CF-End frames");
584 "Expected an RTS frame");
586 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (0))->GetMac ()->GetAddress (),
587 "Expected an RTS frame sent by the AP to the first station");
590 "Duration/ID of the first RTS frame must cover the whole TXOP");
596 NS_TEST_EXPECT_MSG_LT (tEnd + sifs, tStart,
"CTS in response to the first RTS frame sent too early");
597 NS_TEST_EXPECT_MSG_LT (tStart, tEnd + sifs + tolerance,
"CTS in response to the first RTS frame sent too late");
600 DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetMac ()->GetAddress (),
601 "Expected a CTS frame sent to the AP");
603 RoundDurationId (
m_txPsdus[13].header.GetDuration () - sifs -
m_txPsdus[14].txDuration),
604 "Duration/ID of the CTS frame must be derived from that of the RTS frame");
613 "Expected a QoS data frame");
615 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (0))->GetMac ()->GetAddress (),
616 "Expected a frame sent by the AP to the first station");
619 "Duration/ID of the first QoS data frame does not cover the remaining TXOP");
625 NS_TEST_EXPECT_MSG_LT (tEnd + sifs, tStart,
"Ack in response to the first QoS data frame sent too early");
626 NS_TEST_EXPECT_MSG_LT (tStart, tEnd + sifs + tolerance,
"Ack in response to the first QoS data frame sent too late");
629 DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetMac ()->GetAddress (),
630 "Expected a Normal Ack sent to the AP");
632 RoundDurationId (
m_txPsdus[15].header.GetDuration () - sifs -
m_txPsdus[16].txDuration),
633 "Duration/ID of the Ack must be derived from that of the previous frame");
642 "Expected an RTS frame");
644 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (1))->GetMac ()->GetAddress (),
645 "Expected an RTS frame sent by the AP to the second station");
648 "Duration/ID of the second RTS frame must cover the whole TXOP");
654 NS_TEST_EXPECT_MSG_LT (tEnd + sifs, tStart,
"CTS in response to the second RTS frame sent too early");
655 NS_TEST_EXPECT_MSG_LT (tStart, tEnd + sifs + tolerance,
"CTS in response to the second RTS frame sent too late");
658 DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetMac ()->GetAddress (),
659 "Expected a CTS frame sent to the AP");
661 RoundDurationId (
m_txPsdus[17].header.GetDuration () - sifs -
m_txPsdus[18].txDuration),
662 "Duration/ID of the CTS frame must be derived from that of the RTS frame");
671 "Expected a QoS data frame");
673 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (1))->GetMac ()->GetAddress (),
674 "Expected a frame sent by the AP to the second station");
677 "Duration/ID of the second QoS data frame does not cover the remaining TXOP");
683 NS_TEST_EXPECT_MSG_LT (tEnd + sifs, tStart,
"Ack in response to the second QoS data frame sent too early");
684 NS_TEST_EXPECT_MSG_LT (tStart, tEnd + sifs + tolerance,
"Ack in response to the second QoS data frame sent too late");
687 DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetMac ()->GetAddress (),
688 "Expected a Normal Ack sent to the AP");
690 RoundDurationId (
m_txPsdus[19].header.GetDuration () - sifs -
m_txPsdus[20].txDuration),
691 "Duration/ID of the Ack must be derived from that of the previous frame");
700 "Expected an RTS frame");
702 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (2))->GetMac ()->GetAddress (),
703 "Expected an RTS frame sent by the AP to the third station");
706 "Duration/ID of the third RTS frame must cover the whole TXOP");
712 NS_TEST_EXPECT_MSG_LT (tEnd + sifs, tStart,
"CTS in response to the third RTS frame sent too early");
713 NS_TEST_EXPECT_MSG_LT (tStart, tEnd + sifs + tolerance,
"CTS in response to the third RTS frame sent too late");
716 DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetMac ()->GetAddress (),
717 "Expected a CTS frame sent to the AP");
719 RoundDurationId (
m_txPsdus[21].header.GetDuration () - sifs -
m_txPsdus[22].txDuration),
720 "Duration/ID of the CTS frame must be derived from that of the RTS frame");
729 "Expected a QoS data frame");
731 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (2))->GetMac ()->GetAddress (),
732 "Expected a frame sent by the AP to the third station");
735 "Duration/ID of the third QoS data frame does not cover the remaining TXOP");
741 NS_TEST_EXPECT_MSG_LT (tEnd + sifs, tStart,
"Ack in response to the third QoS data frame sent too early");
742 NS_TEST_EXPECT_MSG_LT (tStart, tEnd + sifs + tolerance,
"Ack in response to the third QoS data frame sent too late");
745 DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetMac ()->GetAddress (),
746 "Expected a Normal Ack sent to the AP");
748 RoundDurationId (
m_txPsdus[23].header.GetDuration () - sifs -
m_txPsdus[24].txDuration),
749 "Duration/ID of the Ack must be derived from that of the previous frame");