22 #include "ns3/string.h"
23 #include "ns3/boolean.h"
24 #include "ns3/qos-utils.h"
25 #include "ns3/packet.h"
26 #include "ns3/wifi-net-device.h"
27 #include "ns3/wifi-mac-header.h"
28 #include "ns3/mobility-helper.h"
29 #include "ns3/spectrum-wifi-helper.h"
30 #include "ns3/single-model-spectrum-channel.h"
31 #include "ns3/packet-socket-server.h"
32 #include "ns3/packet-socket-client.h"
33 #include "ns3/packet-socket-helper.h"
34 #include "ns3/config.h"
35 #include "ns3/pointer.h"
36 #include "ns3/rng-seed-manager.h"
37 #include "ns3/wifi-psdu.h"
38 #include "ns3/wifi-ppdu.h"
39 #include "ns3/ap-wifi-mac.h"
40 #include "ns3/qos-txop.h"
81 void CheckResults (
void);
84 void DoRun (
void)
override;
107 :
TestCase (
"Check correct operation within TXOPs"),
111 m_pifsRecovery (pifsRecovery)
133 if (!psduMap.begin ()->second->GetHeader (0).IsBeacon ()
138 psduMap[
SU_STA_ID]->GetHeader (0), txVector});
142 std::cout <<
Simulator::Now () <<
" " << psduMap.begin ()->second->GetHeader (0).GetTypeString ()
143 <<
" seq " << psduMap.begin ()->second->GetHeader (0).GetSequenceNumber ()
144 <<
" to " << psduMap.begin ()->second->GetAddr1 ()
145 <<
" TX duration " << WifiPhy::CalculateTxDuration (psduMap, txVector,
WIFI_PHY_BAND_5GHZ)
146 <<
" duration/ID " << psduMap.begin ()->second->GetHeader (0).GetDuration () << std::endl;
152 RngSeedManager::SetSeed (1);
153 RngSeedManager::SetRun (40);
154 int64_t streamNumber = 100;
164 spectrumChannel->AddPropagationLossModel (lossModel);
166 spectrumChannel->SetPropagationDelayModel (delayModel);
169 phy.SetChannel (spectrumChannel);
176 wifi.SetRemoteStationManager (
"ns3::ConstantRateWifiManager",
181 mac.SetType (
"ns3::StaWifiMac",
187 mac.SetType (
"ns3::ApWifiMac",
202 Simulator::Schedule (init + i *
MicroSeconds (102400), &WifiMac::SetSsid,
212 positionAlloc->Add (Vector (0.0, 0.0, 0.0));
213 positionAlloc->Add (Vector (1.0, 0.0, 0.0));
214 positionAlloc->Add (Vector (0.0, 1.0, 0.0));
215 positionAlloc->Add (Vector (-1.0, 0.0, 0.0));
216 mobility.SetPositionAllocator (positionAlloc);
218 mobility.SetMobilityModel (
"ns3::ConstantPositionMobilityModel");
225 dev->
GetMac ()->GetAttribute (
"BE_Txop", ptr);
247 client1->SetRemote (socket);
250 client1->SetStopTime (
Seconds (1.0));
257 client2->SetRemote (socket);
260 client2->SetStopTime (
Seconds (1.0));
263 server->SetLocal (socket);
265 server->SetStartTime (
Seconds (0.0));
266 server->SetStopTime (
Seconds (1.0));
272 apPem->SetList ({9});
274 dev->
GetMac ()->GetWifiPhy ()->SetPostReceptionErrorModel (apPem);
279 sta2Pem->SetList ({24});
281 dev->
GetMac ()->GetWifiPhy ()->SetPostReceptionErrorModel (sta2Pem);
294 client->SetRemote (socket);
297 client->SetStopTime (
Seconds (1.0));
300 server->SetLocal (socket);
302 server->SetStartTime (
Seconds (0.0));
303 server->SetStopTime (
Seconds (1.0));
306 Config::Connect (
"/NodeList/*/ApplicationList/*/$ns3::PacketSocketServer/Rx",
309 Config::Connect (
"/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxPsduBegin",
317 Simulator::Destroy ();
327 sifs = DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetPhy ()->GetSifs (),
328 slot = DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetPhy ()->GetSlot (),
332 auto RoundDurationId = [] (
Time t)
334 return MicroSeconds (ceil (
static_cast<double> (t.GetNanoSeconds ()) / 1000));
364 "Expected a QoS data frame");
366 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (0))->GetMac ()->GetAddress (),
367 "Expected a frame sent by the AP to the first station");
370 "Duration/ID of the first frame must cover the whole TXOP");
377 NS_TEST_ASSERT_MSG_LT (tStart, tEnd + sifs + tolerance,
"Ack in response to the first frame sent too late");
380 DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetMac ()->GetAddress (),
381 "Expected a Normal Ack sent to the AP");
383 RoundDurationId (
m_txPsdus[0].header.GetDuration () - sifs -
m_txPsdus[1].txDuration),
384 "Duration/ID of the Ack must be derived from that of the first frame");
395 "Less than AIFS elapsed between AckTimeout and the next TXOP start");
397 "More than AIFS+BO elapsed between AckTimeout and the next TXOP start");
399 "Expected to retransmit a QoS data frame");
401 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (0))->GetMac ()->GetAddress (),
402 "Expected to retransmit a frame to the first station");
405 "Duration/ID of the retransmitted frame must cover the whole TXOP");
412 NS_TEST_ASSERT_MSG_LT (tStart, tEnd + sifs + tolerance,
"Ack in response to the first frame sent too late");
415 DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetMac ()->GetAddress (),
416 "Expected a Normal Ack sent to the AP");
418 RoundDurationId (
m_txPsdus[2].header.GetDuration () - sifs -
m_txPsdus[3].txDuration),
419 "Duration/ID of the Ack must be derived from that of the previous frame");
428 "Expected a QoS data frame");
430 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (1))->GetMac ()->GetAddress (),
431 "Expected a frame sent by the AP to the second station");
434 "Duration/ID of the second frame does not cover the remaining TXOP");
440 + sifs + slot + WifiPhy::CalculatePhyPreambleAndHeaderDuration (
m_txPsdus[4].txVector);
450 "Less than AIFS elapsed between AckTimeout and the next transmission");
452 "More than AIFS+BO elapsed between AckTimeout and the next TXOP start");
455 "Expected a QoS data frame");
457 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (1))->GetMac ()->GetAddress (),
458 "Expected a frame sent by the AP to the second station");
461 "Duration/ID of the second frame does not cover the remaining TXOP");
468 NS_TEST_ASSERT_MSG_LT (tStart, tEnd + sifs + tolerance,
"Ack in response to the second frame sent too late");
471 DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetMac ()->GetAddress (),
472 "Expected a Normal Ack sent to the AP");
474 RoundDurationId (
m_txPsdus[5].header.GetDuration () - sifs -
m_txPsdus[6].txDuration),
475 "Duration/ID of the Ack must be derived from that of the previous frame");
484 "Expected a QoS data frame");
486 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (2))->GetMac ()->GetAddress (),
487 "Expected a frame sent by the AP to the third station");
490 "Duration/ID of the third frame does not cover the remaining TXOP");
497 NS_TEST_ASSERT_MSG_LT (tStart, tEnd + sifs + tolerance,
"Ack in response to the third frame sent too late");
500 DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetMac ()->GetAddress (),
501 "Expected a Normal Ack sent to the AP");
503 RoundDurationId (
m_txPsdus[7].header.GetDuration () - sifs -
m_txPsdus[8].txDuration),
504 "Duration/ID of the Ack must be derived from that of the previous frame");
514 "Duration/ID must be set to 0 for CF-End frames");
521 "Less than AIFS elapsed between two TXOPs");
523 "More than AIFS+BO elapsed between two TXOPs");
525 "Expected a QoS data frame");
527 DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetMac ()->GetAddress (),
528 "Expected a frame sent by the first station to the AP");
531 "Duration/ID of the frame sent by the first station does not cover the remaining TXOP");
541 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (0))->GetMac ()->GetAddress (),
542 "Expected a Normal Ack sent to the first station");
544 RoundDurationId (
m_txPsdus[10].header.GetDuration () - sifs -
m_txPsdus[11].txDuration),
545 "Duration/ID of the Ack must be derived from that of the previous frame");
555 "Duration/ID must be set to 0 for CF-End frames");
586 "Expected an RTS frame");
588 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (0))->GetMac ()->GetAddress (),
589 "Expected an RTS frame sent by the AP to the first station");
592 "Duration/ID of the first RTS frame must cover the whole TXOP");
598 NS_TEST_ASSERT_MSG_LT (tEnd + sifs, tStart,
"CTS in response to the first RTS frame sent too early");
599 NS_TEST_ASSERT_MSG_LT (tStart, tEnd + sifs + tolerance,
"CTS in response to the first RTS frame sent too late");
602 DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetMac ()->GetAddress (),
603 "Expected a CTS frame sent to the AP");
605 RoundDurationId (
m_txPsdus[13].header.GetDuration () - sifs -
m_txPsdus[14].txDuration),
606 "Duration/ID of the CTS frame must be derived from that of the RTS frame");
615 "Expected a QoS data frame");
617 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (0))->GetMac ()->GetAddress (),
618 "Expected a frame sent by the AP to the first station");
621 "Duration/ID of the first QoS data frame does not cover the remaining TXOP");
627 NS_TEST_ASSERT_MSG_LT (tEnd + sifs, tStart,
"Ack in response to the first QoS data frame sent too early");
628 NS_TEST_ASSERT_MSG_LT (tStart, tEnd + sifs + tolerance,
"Ack in response to the first QoS data frame sent too late");
631 DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetMac ()->GetAddress (),
632 "Expected a Normal Ack sent to the AP");
634 RoundDurationId (
m_txPsdus[15].header.GetDuration () - sifs -
m_txPsdus[16].txDuration),
635 "Duration/ID of the Ack must be derived from that of the previous frame");
644 "Expected an RTS frame");
646 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (1))->GetMac ()->GetAddress (),
647 "Expected an RTS frame sent by the AP to the second station");
650 "Duration/ID of the second RTS frame must cover the whole TXOP");
656 NS_TEST_ASSERT_MSG_LT (tEnd + sifs, tStart,
"CTS in response to the second RTS frame sent too early");
657 NS_TEST_ASSERT_MSG_LT (tStart, tEnd + sifs + tolerance,
"CTS in response to the second RTS frame sent too late");
660 DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetMac ()->GetAddress (),
661 "Expected a CTS frame sent to the AP");
663 RoundDurationId (
m_txPsdus[17].header.GetDuration () - sifs -
m_txPsdus[18].txDuration),
664 "Duration/ID of the CTS frame must be derived from that of the RTS frame");
673 "Expected a QoS data frame");
675 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (1))->GetMac ()->GetAddress (),
676 "Expected a frame sent by the AP to the second station");
679 "Duration/ID of the second QoS data frame does not cover the remaining TXOP");
685 NS_TEST_ASSERT_MSG_LT (tEnd + sifs, tStart,
"Ack in response to the second QoS data frame sent too early");
686 NS_TEST_ASSERT_MSG_LT (tStart, tEnd + sifs + tolerance,
"Ack in response to the second QoS data frame sent too late");
689 DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetMac ()->GetAddress (),
690 "Expected a Normal Ack sent to the AP");
692 RoundDurationId (
m_txPsdus[19].header.GetDuration () - sifs -
m_txPsdus[20].txDuration),
693 "Duration/ID of the Ack must be derived from that of the previous frame");
702 "Expected an RTS frame");
704 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (2))->GetMac ()->GetAddress (),
705 "Expected an RTS frame sent by the AP to the third station");
708 "Duration/ID of the third RTS frame must cover the whole TXOP");
714 NS_TEST_ASSERT_MSG_LT (tEnd + sifs, tStart,
"CTS in response to the third RTS frame sent too early");
715 NS_TEST_ASSERT_MSG_LT (tStart, tEnd + sifs + tolerance,
"CTS in response to the third RTS frame sent too late");
718 DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetMac ()->GetAddress (),
719 "Expected a CTS frame sent to the AP");
721 RoundDurationId (
m_txPsdus[21].header.GetDuration () - sifs -
m_txPsdus[22].txDuration),
722 "Duration/ID of the CTS frame must be derived from that of the RTS frame");
731 "Expected a QoS data frame");
733 DynamicCast<WifiNetDevice> (
m_staDevices.
Get (2))->GetMac ()->GetAddress (),
734 "Expected a frame sent by the AP to the third station");
737 "Duration/ID of the third QoS data frame does not cover the remaining TXOP");
743 NS_TEST_ASSERT_MSG_LT (tEnd + sifs, tStart,
"Ack in response to the third QoS data frame sent too early");
744 NS_TEST_ASSERT_MSG_LT (tStart, tEnd + sifs + tolerance,
"Ack in response to the third QoS data frame sent too late");
747 DynamicCast<WifiNetDevice> (
m_apDevices.
Get (0))->GetMac ()->GetAddress (),
748 "Expected a Normal Ack sent to the AP");
750 RoundDurationId (
m_txPsdus[23].header.GetDuration () - sifs -
m_txPsdus[24].txDuration),
751 "Duration/ID of the Ack must be derived from that of the previous frame");
void L7Receive(std::string context, Ptr< const Packet > p, const Address &addr)
Function to trace packets received by the server application.
bool m_pifsRecovery
whether to use PIFS recovery
NetDeviceContainer m_apDevices
container for AP's NetDevice
uint32_t m_cwMin
CWmin for BE.
uint16_t m_received
number of packets received by the stations
uint16_t m_nStations
number of stations
uint8_t m_aifsn
AIFSN for BE.
Time m_txopLimit
TXOP limit.
void CheckResults(void)
Check correctness of transmitted frames.
std::vector< FrameInfo > m_txPsdus
transmitted PSDUs
void Transmit(std::string context, WifiConstPsduMap psduMap, WifiTxVector txVector, double txPowerW)
Callback invoked when PHY receives a PSDU to transmit.
NetDeviceContainer m_staDevices
container for stations' NetDevices
void DoRun(void) override
Implementation to actually run this TestCase.
WifiTxopTest(bool pifsRecovery)
Constructor.
a polymophic address class
AttributeValue implementation for Boolean.
Helper class used to assign positions and mobility models to nodes.
holds a vector of ns3::NetDevice pointers
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
virtual Address GetAddress(void) const =0
virtual uint32_t GetIfIndex(void) const =0
keep track of a set of node pointers.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
an address for a packet socket
void SetProtocol(uint16_t protocol)
Set the protocol.
void SetPhysicalAddress(const Address address)
Set the destination address.
void SetSingleDevice(uint32_t device)
Set the address to match only a specified NetDevice.
Give ns3::PacketSocket powers to ns3::Node.
void Install(Ptr< Node > node) const
Aggregate an instance of a ns3::PacketSocketFactory onto the provided node.
Hold objects of type Ptr<T>.
Handle packet fragmentation and retransmissions for QoS data frames as well as MSDU aggregation (A-MS...
Make it easy to create and manage PHY objects for the spectrum model.
The IEEE 802.11 SSID Information Element.
AttributeValue implementation for Ssid.
Hold variables of type string.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Simulation virtual time values and global simulation resolution.
AttributeValue implementation for Time.
Hold an unsigned integer type.
helps to create WifiNetDevice objects
create MAC layers for a ns3::WifiNetDevice.
Ptr< WifiMac > GetMac(void) const
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
void SetDefault(std::string name, const AttributeValue &value)
void Connect(std::string path, const CallbackBase &cb)
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
#define NS_TEST_ASSERT_MSG_LT(actual, limit, msg)
Test that an actual value is less than a limit and report and abort if not.
#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.
#define NS_TEST_ASSERT_MSG_LT_OR_EQ(actual, limit, msg)
Test that an actual value is less than or equal to a limit and report and abort if not.
#define NS_TEST_ASSERT_MSG_GT_OR_EQ(actual, limit, msg)
Test that an actual value is greater than or equal to a limit and report and abort if not.
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Time Seconds(double value)
Construct a Time in the indicated unit.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
@ WIFI_PHY_BAND_5GHZ
The 5 GHz band.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::unordered_map< uint16_t, Ptr< const WifiPsdu > > WifiConstPsduMap
Map of const PSDUs indexed by STA-ID.
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...
Information about transmitted frames.
WifiMacHeader header
Frame MAC header.
WifiTxVector txVector
TX vector used to transmit the frame.
Time txStart
Frame start TX time.
Time txDuration
Frame TX duration.
static WifiTxopTestSuite g_wifiTxopTestSuite
the test suite