9#include "ns3/ap-wifi-mac.h"
10#include "ns3/boolean.h"
11#include "ns3/config.h"
12#include "ns3/he-phy.h"
14#include "ns3/mobility-helper.h"
15#include "ns3/multi-model-spectrum-channel.h"
16#include "ns3/packet-socket-client.h"
17#include "ns3/packet-socket-helper.h"
18#include "ns3/packet-socket-server.h"
19#include "ns3/packet.h"
20#include "ns3/pointer.h"
21#include "ns3/qos-txop.h"
22#include "ns3/qos-utils.h"
23#include "ns3/rng-seed-manager.h"
24#include "ns3/spectrum-wifi-helper.h"
25#include "ns3/string.h"
27#include "ns3/wifi-mac-header.h"
28#include "ns3/wifi-net-device.h"
29#include "ns3/wifi-ppdu.h"
30#include "ns3/wifi-psdu.h"
100 void DoRun()
override;
137 :
TestCase(
"Check correct operation within TXOPs"),
145 m_nonHt(params.nonHt),
146 m_payloadSizeRtsOn(m_nonHt ? 2000 : 540),
147 m_payloadSizeRtsOff(500),
149 m_mode(m_nonHt ?
OfdmPhy::GetOfdmRate12Mbps() :
HePhy::GetHeMcs0()),
150 m_pifsRecovery(params.pifsRecovery),
151 m_singleRtsPerTxop(params.singleRtsPerTxop),
152 m_lengthBasedRtsCtsThresh(params.lengthBasedRtsCtsThresh),
155 m_apCorrupted(false),
156 m_staCorrupted(false)
175 bool corrupted{
false};
179 if (
const auto& hdr = psduMap.begin()->second->GetHeader(0);
189 if (
const auto& hdr = psduMap.begin()->second->GetHeader(0);
219 NS_LOG_INFO(psduMap.begin()->second->GetHeader(0).GetTypeString()
220 <<
" seq " << psduMap.begin()->second->GetHeader(0).GetSequenceNumber() <<
" to "
221 << psduMap.begin()->second->GetAddr1() <<
" TX duration "
223 <<
" duration/ID " << psduMap.begin()->second->GetHeader(0).GetDuration()
224 << (corrupted ?
" CORRUPTED" :
"") << std::endl);
232 int64_t streamNumber = 100;
235 wifiApNode.Create(1);
242 spectrumChannel->AddPropagationLossModel(lossModel);
244 spectrumChannel->SetPropagationDelayModel(delayModel);
247 phy.SetChannel(spectrumChannel);
249 phy.Set(
"ChannelSettings",
StringValue(
"{0, 20, BAND_5GHZ, 0}"));
268 wifi.SetRemoteStationManager(
"ns3::ConstantRateWifiManager",
275 mac.SetType(
"ns3::StaWifiMac",
291 "EnableBeaconJitter",
311 dev->GetMac()->SetSsid(
Ssid(
"wifi-txop-ssid"));
319 Ssid(
"wifi-txop-ssid"));
328 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
329 positionAlloc->Add(Vector(1.0, 0.0, 0.0));
330 positionAlloc->Add(Vector(0.0, 1.0, 0.0));
331 positionAlloc->Add(Vector(-1.0, 0.0, 0.0));
332 mobility.SetPositionAllocator(positionAlloc);
334 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
335 mobility.Install(wifiApNode);
336 mobility.Install(wifiStaNodes);
339 packetSocket.
Install(wifiApNode);
340 packetSocket.
Install(wifiStaNodes);
358 client->SetRemote(socket);
359 wifiApNode.Get(0)->AddApplication(client);
361 client->SetStopTime(
Seconds(1.0));
369 client1->SetRemote(socket);
370 wifiApNode.Get(0)->AddApplication(client1);
372 client1->SetStopTime(
Seconds(1.0));
379 client2->SetRemote(socket);
380 wifiApNode.Get(0)->AddApplication(client2);
382 client2->SetStopTime(
Seconds(1.0));
385 server->SetLocal(socket);
386 wifiStaNodes.Get(i)->AddApplication(server);
387 server->SetStartTime(
Seconds(0.0));
388 server->SetStopTime(
Seconds(1.0));
393 dev->GetMac()->GetWifiPhy()->SetPostReceptionErrorModel(
m_apErrorModel);
397 dev->GetMac()->GetWifiPhy()->SetPostReceptionErrorModel(
m_staErrorModel);
414 client->SetRemote(socket);
415 wifiStaNodes.Get(0)->AddApplication(client);
417 client->SetStopTime(
Seconds(1.0));
424 client->SetRemote(socket);
425 wifiStaNodes.Get(0)->AddApplication(client);
427 client->SetStopTime(
Seconds(1.0));
430 server->SetLocal(socket);
431 wifiApNode.Get(0)->AddApplication(server);
432 server->SetStartTime(
Seconds(0.0));
433 server->SetStopTime(
Seconds(1.0));
436 Config::Connect(
"/NodeList/*/ApplicationList/*/$ns3::PacketSocketServer/Rx",
439 Config::Connect(
"/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxPsduBegin",
459 "Unexpected AIFSN for STA " << i);
462 "Unexpected CWmin for STA " << i);
465 "Unexpected CWmax for STA " << i);
468 "Unexpected TXOP limit for STA " << i);
475 "Unexpected TXOP limit for AP");
483 Time sifs = apDev->GetPhy()->GetSifs();
484 Time slot = apDev->GetPhy()->GetSlot();
493 auto RoundDurationId = [](
Time t) {
494 return MicroSeconds(ceil(
static_cast<double>(t.GetNanoSeconds()) / 1000));
522 "Unexpected number of transmitted frames");
530 "Expected a frame sent by the AP to the first station");
535 "PSDU size expected not to exceed length based RTS/CTS threshold");
541 rtsCtsTxDurationThresh,
542 "PSDU duration expected not to exceed duration based RTS/CTS threshold");
546 "Duration/ID of the first frame must cover the whole TXOP");
554 tEnd + sifs + tolerance,
555 "Ack in response to the first frame sent too late");
558 apDev->GetMac()->GetAddress(),
559 "Expected a Normal Ack sent to the AP");
563 "Duration/ID of the Ack must be derived from that of the first frame");
574 auto eifsNoDifs = apPhy->GetSifs() + apPhy->GetAckTxTime();
578 eifsNoDifs + sifs + aifsn * slot,
579 "Less than AIFS elapsed between AckTimeout and the next TXOP start");
582 eifsNoDifs + sifs + aifsn * slot + (2 * (cwMin + 1) - 1) * slot,
583 "More than AIFS+BO elapsed between AckTimeout and the next TXOP start");
586 "Expected to retransmit a QoS data frame");
589 "Expected to retransmit a frame to the first station");
594 "PSDU size expected not to exceed length based RTS/CTS threshold");
600 rtsCtsTxDurationThresh,
601 "PSDU duration expected not to exceed duration based RTS/CTS threshold");
605 "Duration/ID of the retransmitted frame must cover the whole TXOP");
613 tEnd + sifs + tolerance,
614 "Ack in response to the first frame sent too late");
617 apDev->GetMac()->GetAddress(),
618 "Expected a Normal Ack sent to the AP");
622 "Duration/ID of the Ack must be derived from that of the previous frame");
633 "Expected a frame sent by the AP to the second station");
638 "PSDU size expected not to exceed length based RTS/CTS threshold");
644 rtsCtsTxDurationThresh,
645 "PSDU duration expected not to exceed duration based RTS/CTS threshold");
650 "Duration/ID of the second frame does not cover the remaining TXOP");
657 auto ackTxVector = apStationManager->GetAckTxVector(staAddress,
m_txPsdus[4].txVector);
666 "Second frame must have been sent after a PIFS");
673 "Less than AIFS elapsed between AckTimeout and the next transmission");
676 sifs + aifsn * slot + (2 * (cwMin + 1) - 1) * slot,
677 "More than AIFS+BO elapsed between AckTimeout and the next TXOP start");
682 "Expected a frame sent by the AP to the second station");
687 "PSDU size expected not to exceed length based RTS/CTS threshold");
693 rtsCtsTxDurationThresh,
694 "PSDU duration expected not to exceed duration based RTS/CTS threshold");
699 "Duration/ID of the second frame does not cover the remaining TXOP");
707 "Ack in response to the second frame sent too early");
709 tEnd + sifs + tolerance,
710 "Ack in response to the second frame sent too late");
713 apDev->GetMac()->GetAddress(),
714 "Expected a Normal Ack sent to the AP");
718 "Duration/ID of the Ack must be derived from that of the previous frame");
729 "Expected a frame sent by the AP to the third station");
734 "PSDU size expected not to exceed length based RTS/CTS threshold");
740 rtsCtsTxDurationThresh,
741 "PSDU duration expected not to exceed duration based RTS/CTS threshold");
746 "Duration/ID of the third frame does not cover the remaining TXOP");
754 tEnd + sifs + tolerance,
755 "Ack in response to the third frame sent too late");
758 apDev->GetMac()->GetAddress(),
759 "Expected a Normal Ack sent to the AP");
763 "Duration/ID of the Ack must be derived from that of the previous frame");
774 "Duration/ID must be set to 0 for CF-End frames");
782 "Less than AIFS elapsed between two TXOPs");
785 "More than AIFS+BO elapsed between two TXOPs");
788 apDev->GetMac()->GetAddress(),
789 "Expected a frame sent by the first station to the AP");
794 "PSDU size expected not to exceed length based RTS/CTS threshold");
800 rtsCtsTxDurationThresh,
801 "PSDU duration expected not to exceed duration based RTS/CTS threshold");
806 "Duration/ID of the frame sent by the first station does not cover the remaining TXOP");
817 "Expected a Normal Ack sent to the first station");
820 RoundDurationId(
m_txPsdus[10].header.GetDuration() - sifs -
m_txPsdus[11].txDuration),
821 "Duration/ID of the Ack must be derived from that of the previous frame");
832 "Duration/ID must be set to 0 for CF-End frames");
860 std::string ack(
m_nonHt ?
"Normal Ack" :
"Block Ack");
865 "Expected an RTS frame sent by the AP to the first station");
868 "Duration/ID of the first RTS frame must cover the whole TXOP");
876 "CTS in response to the first RTS frame sent too early");
878 tEnd + sifs + tolerance,
879 "CTS in response to the first RTS frame sent too late");
882 apDev->GetMac()->GetAddress(),
883 "Expected a CTS frame sent to the AP");
886 RoundDurationId(
m_txPsdus[13].header.GetDuration() - sifs -
m_txPsdus[14].txDuration),
887 "Duration/ID of the CTS frame must be derived from that of the RTS frame");
898 "Expected a frame sent by the AP to the first station");
903 "PSDU size expected to exceed length based RTS/CTS threshold");
908 rtsCtsTxDurationThresh,
909 "PSDU duration expected to exceed duration based RTS/CTS threshold");
915 "Duration/ID of the first QoS data frame does not cover the remaining TXOP");
923 ack <<
" in response to the first QoS data frame sent too early");
925 tEnd + sifs + tolerance,
926 ack <<
" in response to the first QoS data frame sent too late");
930 "Expected a " << ack);
932 apDev->GetMac()->GetAddress(),
933 "Expected a " << ack <<
" sent to the AP");
936 RoundDurationId(
m_txPsdus[15].header.GetDuration() - sifs -
m_txPsdus[16].txDuration),
937 "Duration/ID of the " << ack <<
" must be derived from that of the previous frame");
939 std::size_t idx = 16;
954 "Expected an RTS frame sent by the AP to the second station");
958 "Duration/ID of the second RTS frame must cover the whole TXOP");
966 "CTS in response to the second RTS frame sent too early");
968 tEnd + sifs + tolerance,
969 "CTS in response to the second RTS frame sent too late");
972 apDev->GetMac()->GetAddress(),
973 "Expected a CTS frame sent to the AP");
976 RoundDurationId(
m_txPsdus[idx].header.GetDuration() - sifs -
978 "Duration/ID of the CTS frame must be derived from that of the RTS frame");
993 "Expected a frame sent by the AP to the second station");
998 "PSDU size expected to exceed length based RTS/CTS threshold");
1003 rtsCtsTxDurationThresh,
1004 "PSDU duration expected to exceed duration based RTS/CTS threshold");
1010 "Duration/ID of the second QoS data frame does not cover the remaining TXOP");
1018 ack <<
" in response to the second QoS data frame sent too early");
1020 tEnd + sifs + tolerance,
1021 ack <<
" in response to the second QoS data frame sent too late");
1025 "Expected a " << ack);
1027 apDev->GetMac()->GetAddress(),
1028 "Expected a " << ack <<
" sent to the AP");
1030 m_txPsdus[idx + 1].header.GetDuration(),
1031 RoundDurationId(
m_txPsdus[idx].header.GetDuration() - sifs -
m_txPsdus[idx + 1].txDuration),
1032 "Duration/ID of the " << ack <<
" must be derived from that of the previous frame");
1048 "Expected an RTS frame sent by the AP to the third station");
1052 "Duration/ID of the third RTS frame must cover the whole TXOP");
1060 "CTS in response to the third RTS frame sent too early");
1062 tEnd + sifs + tolerance,
1063 "CTS in response to the third RTS frame sent too late");
1066 apDev->GetMac()->GetAddress(),
1067 "Expected a CTS frame sent to the AP");
1069 m_txPsdus[idx + 1].header.GetDuration(),
1070 RoundDurationId(
m_txPsdus[idx].header.GetDuration() - sifs -
1072 "Duration/ID of the CTS frame must be derived from that of the RTS frame");
1086 "Expected a frame sent by the AP to the third station");
1091 "PSDU size expected to exceed length based RTS/CTS threshold");
1096 rtsCtsTxDurationThresh,
1097 "PSDU duration expected to exceed duration based RTS/CTS threshold");
1103 "Duration/ID of the third QoS data frame does not cover the remaining TXOP");
1111 ack <<
" in response to the third QoS data frame sent too early");
1113 tEnd + sifs + tolerance,
1114 ack <<
" in response to the third QoS data frame sent too late");
1118 "Expected a " << ack);
1120 apDev->GetMac()->GetAddress(),
1121 "Expected a " << ack <<
" sent to the AP");
1123 m_txPsdus[idx + 1].header.GetDuration(),
1124 RoundDurationId(
m_txPsdus[idx].header.GetDuration() - sifs -
m_txPsdus[idx + 1].txDuration),
1125 "Duration/ID of the " << ack <<
" must be derived from that of the previous frame");
1141 "Duration/ID must be set to 0 for CF-End frames");
1166 for (
const auto nonHt : {
true,
false})
1169 .pifsRecovery =
true,
1170 .singleRtsPerTxop =
false,
1171 .lengthBasedRtsCtsThresh =
false}),
1172 TestCase::Duration::QUICK);
1174 .pifsRecovery =
false,
1175 .singleRtsPerTxop =
true,
1176 .lengthBasedRtsCtsThresh =
false}),
1177 TestCase::Duration::QUICK);
1179 .pifsRecovery =
true,
1180 .singleRtsPerTxop =
true,
1181 .lengthBasedRtsCtsThresh =
true}),
1182 TestCase::Duration::QUICK);
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
WifiTxopTest(const Params ¶ms)
Constructor.
uint8_t m_staAifsn
AIFSN for STAs (AC BE)
void DoRun() override
Implementation to actually run this TestCase.
uint16_t m_received
number of packets received by the stations
uint16_t m_nStations
number of stations
Ptr< ListErrorModel > m_apErrorModel
error model to install on the AP
uint32_t m_staCwMin
CWmin for STAs (AC BE)
bool m_nonHt
whether to use 802.11a or 802.11ax
std::size_t m_payloadSizeRtsOff
size in bytes of packets not protected by RTS
WifiMode m_mode
wifi mode used to transmit data frames
Time m_apTxopLimit
TXOP limit for AP (AC BE)
std::vector< FrameInfo > m_txPsdus
transmitted PSDUs
Time m_startTime
time when data frame exchanges start
bool m_staCorrupted
whether the frame to be corrupted by the STA has been corrupted
void Transmit(std::string context, WifiConstPsduMap psduMap, WifiTxVector txVector, double txPowerW)
Callback invoked when PHY receives a PSDU to transmit.
bool m_singleRtsPerTxop
whether to use single RTS per TXOP
NetDeviceContainer m_staDevices
container for stations' NetDevices
bool m_apCorrupted
whether the frame to be corrupted by the AP has been corrupted
std::size_t m_payloadSizeRtsOn
size in bytes of packets protected by RTS
uint32_t m_staCwMax
CWmax for STAs (AC BE)
bool m_lengthBasedRtsCtsThresh
whether to use length based RTS/CTS threshold
Time m_staTxopLimit
TXOP limit for STAs (AC BE)
Ptr< ListErrorModel > m_staErrorModel
error model to install on a STA
void CheckResults()
Check correctness of transmitted frames.
a polymophic address class
AttributeContainerValue< UintAccessParamsPairValue, ';'> UintAccessParamsMapValue
AttributeValue type of an ACI-indexed map of access parameters of type unsigned integer.
std::map< AcIndex, std::vector< uint64_t > > UintAccessParamsMap
ACI-indexed map of access parameters of type unsigned integer (CWmin, CWmax and AIFSN)
A container for one type of attribute.
Provide a list of Packet uids to corrupt.
void SetList(const std::list< uint64_t > &packetlist)
Helper class used to assign positions and mobility models to nodes.
holds a vector of ns3::NetDevice pointers
uint32_t GetN() const
Get the number of Ptr<NetDevice> stored in this container.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
keep track of a set of node pointers.
PHY entity for OFDM (11a)
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.
Smart pointer class similar to boost::intrusive_ptr.
static void SetRun(uint64_t run)
Set the run number of simulation.
static void SetSeed(uint32_t seed)
Set the seed.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static Time Now()
Return the current simulation virtual time.
static void Run()
Run the simulation.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Make it easy to create and manage PHY objects for the spectrum model.
The IEEE 802.11 SSID Information Element.
Hold variables of type string.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Simulation virtual time values and global simulation resolution.
int64_t GetMicroSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
bool LookupAttributeByName(std::string name, AttributeInformation *info, bool permissive=false) const
Find an Attribute by name, retrieving the associated AttributeInformation.
Hold an unsigned integer type.
helps to create WifiNetDevice objects
static int64_t AssignStreams(NetDeviceContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by the PHY and MAC aspects ...
create MAC layers for a ns3::WifiNetDevice.
represent a single transmission mode
uint64_t GetDataRate(MHz_u channelWidth, Time guardInterval, uint8_t nss) const
static Time CalculateTxDuration(uint32_t size, const WifiTxVector &txVector, WifiPhyBand band, uint16_t staId=SU_STA_ID)
static Time CalculatePhyPreambleAndHeaderDuration(const WifiTxVector &txVector)
static TypeId GetTypeId()
Get the type ID.
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)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
#define NS_TEST_EXPECT_MSG_GT_OR_EQ(actual, limit, msg)
Test that an actual value is greater than or equal to limit and report 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_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.
#define NS_TEST_EXPECT_MSG_LT(actual, limit, msg)
Test that an actual value is less than a limit and report if not.
#define NS_TEST_EXPECT_MSG_GT(actual, limit, msg)
Test that an actual value is greater than a limit and report if not.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report 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, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
static constexpr uint8_t SINGLE_LINK_OP_ID
Link ID for single link operations (helps tracking places where correct link ID is to be used to supp...
static constexpr uint16_t SU_STA_ID
STA_ID to identify a single user (SU)
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.
uint32_t size
PSDU size in bytes.
Parameters for this test.
bool lengthBasedRtsCtsThresh
if true, use length based RTS/CTS threshold; if false, use TX duration based RTS/CTS threshold
bool singleRtsPerTxop
whether protection mechanism is used no more than once per TXOP
bool nonHt
use 802.11a standard if true, 802.11ax standard otherwise
bool pifsRecovery
whether PIFS recovery is used after failure of a non-initial frame
static WifiTxopTestSuite g_wifiTxopTestSuite
the test suite