20#include "ns3/ap-wifi-mac.h"
21#include "ns3/boolean.h"
22#include "ns3/config.h"
23#include "ns3/mobility-helper.h"
24#include "ns3/packet-socket-client.h"
25#include "ns3/packet-socket-helper.h"
26#include "ns3/packet-socket-server.h"
27#include "ns3/packet.h"
28#include "ns3/pointer.h"
29#include "ns3/qos-txop.h"
30#include "ns3/qos-utils.h"
31#include "ns3/rng-seed-manager.h"
32#include "ns3/single-model-spectrum-channel.h"
33#include "ns3/spectrum-wifi-helper.h"
34#include "ns3/string.h"
36#include "ns3/wifi-mac-header.h"
37#include "ns3/wifi-net-device.h"
38#include "ns3/wifi-ppdu.h"
39#include "ns3/wifi-psdu.h"
85 void DoRun()
override;
108 :
TestCase(
"Check correct operation within TXOPs"),
112 m_pifsRecovery(pifsRecovery)
123 if (p->GetSize() >= 500)
146 std::cout <<
Simulator::Now() <<
" " << psduMap.begin()->second->GetHeader(0).GetTypeString()
147 <<
" seq " << psduMap.begin()->second->GetHeader(0).GetSequenceNumber() <<
" to "
148 << psduMap.begin()->second->GetAddr1() <<
" TX duration "
150 <<
" duration/ID " << psduMap.begin()->second->GetHeader(0).GetDuration()
159 int64_t streamNumber = 100;
162 wifiApNode.Create(1);
169 spectrumChannel->AddPropagationLossModel(lossModel);
171 CreateObject<ConstantSpeedPropagationDelayModel>();
172 spectrumChannel->SetPropagationDelayModel(delayModel);
175 phy.SetChannel(spectrumChannel);
182 wifi.SetRemoteStationManager(
"ns3::ConstantRateWifiManager",
189 mac.SetType(
"ns3::StaWifiMac",
197 mac.SetType(
"ns3::ApWifiMac",
204 "EnableBeaconJitter",
213 dev->GetMac()->SetSsid(
Ssid(
"wifi-txop-ssid"));
221 Ssid(
"wifi-txop-ssid"));
230 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
231 positionAlloc->Add(Vector(1.0, 0.0, 0.0));
232 positionAlloc->Add(Vector(0.0, 1.0, 0.0));
233 positionAlloc->Add(Vector(-1.0, 0.0, 0.0));
234 mobility.SetPositionAllocator(positionAlloc);
236 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
237 mobility.Install(wifiApNode);
238 mobility.Install(wifiStaNodes);
243 dev->GetMac()->GetAttribute(
"BE_Txop", ptr);
249 packetSocket.
Install(wifiApNode);
250 packetSocket.
Install(wifiStaNodes);
265 client1->SetRemote(socket);
266 wifiApNode.Get(0)->AddApplication(client1);
268 client1->SetStopTime(
Seconds(1.0));
275 client2->SetRemote(socket);
276 wifiApNode.Get(0)->AddApplication(client2);
278 client2->SetStopTime(
Seconds(1.0));
281 server->SetLocal(socket);
282 wifiStaNodes.Get(i)->AddApplication(server);
283 server->SetStartTime(
Seconds(0.0));
284 server->SetStopTime(
Seconds(1.0));
292 dev->GetMac()->GetWifiPhy()->SetPostReceptionErrorModel(apPem);
297 sta2Pem->SetList({24});
299 dev->GetMac()->GetWifiPhy()->SetPostReceptionErrorModel(sta2Pem);
312 client->SetRemote(socket);
313 wifiStaNodes.Get(0)->AddApplication(client);
315 client->SetStopTime(
Seconds(1.0));
318 server->SetLocal(socket);
319 wifiApNode.Get(0)->AddApplication(server);
320 server->SetStartTime(
Seconds(0.0));
321 server->SetStopTime(
Seconds(1.0));
324 Config::Connect(
"/NodeList/*/ApplicationList/*/$ns3::PacketSocketServer/Rx",
327 Config::Connect(
"/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxPsduBegin",
350 auto RoundDurationId = [](
Time t) {
351 return MicroSeconds(ceil(
static_cast<double>(t.GetNanoSeconds()) / 1000));
383 DynamicCast<WifiNetDevice>(
m_staDevices.
Get(0))->GetMac()->GetAddress(),
384 "Expected a frame sent by the AP to the first station");
387 "Duration/ID of the first frame must cover the whole TXOP");
395 tEnd + sifs + tolerance,
396 "Ack in response to the first frame sent too late");
399 DynamicCast<WifiNetDevice>(
m_apDevices.
Get(0))->GetMac()->GetAddress(),
400 "Expected a Normal Ack sent to the AP");
404 "Duration/ID of the Ack must be derived from that of the first frame");
417 "Less than AIFS elapsed between AckTimeout and the next TXOP start");
421 "More than AIFS+BO elapsed between AckTimeout and the next TXOP start");
424 "Expected to retransmit a QoS data frame");
426 DynamicCast<WifiNetDevice>(
m_staDevices.
Get(0))->GetMac()->GetAddress(),
427 "Expected to retransmit a frame to the first station");
430 "Duration/ID of the retransmitted frame must cover the whole TXOP");
438 tEnd + sifs + tolerance,
439 "Ack in response to the first frame sent too late");
442 DynamicCast<WifiNetDevice>(
m_apDevices.
Get(0))->GetMac()->GetAddress(),
443 "Expected a Normal Ack sent to the AP");
447 "Duration/ID of the Ack must be derived from that of the previous frame");
457 DynamicCast<WifiNetDevice>(
m_staDevices.
Get(1))->GetMac()->GetAddress(),
458 "Expected a frame sent by the AP to the second station");
462 "Duration/ID of the second frame does not cover the remaining TXOP");
475 "Second frame must have been sent after a PIFS");
482 "Less than AIFS elapsed between AckTimeout and the next transmission");
486 "More than AIFS+BO elapsed between AckTimeout and the next TXOP start");
490 DynamicCast<WifiNetDevice>(
m_staDevices.
Get(1))->GetMac()->GetAddress(),
491 "Expected a frame sent by the AP to the second station");
495 "Duration/ID of the second frame does not cover the remaining TXOP");
503 "Ack in response to the second frame sent too early");
505 tEnd + sifs + tolerance,
506 "Ack in response to the second frame sent too late");
509 DynamicCast<WifiNetDevice>(
m_apDevices.
Get(0))->GetMac()->GetAddress(),
510 "Expected a Normal Ack sent to the AP");
514 "Duration/ID of the Ack must be derived from that of the previous frame");
524 DynamicCast<WifiNetDevice>(
m_staDevices.
Get(2))->GetMac()->GetAddress(),
525 "Expected a frame sent by the AP to the third station");
529 "Duration/ID of the third frame does not cover the remaining TXOP");
537 tEnd + sifs + tolerance,
538 "Ack in response to the third frame sent too late");
541 DynamicCast<WifiNetDevice>(
m_apDevices.
Get(0))->GetMac()->GetAddress(),
542 "Expected a Normal Ack sent to the AP");
546 "Duration/ID of the Ack must be derived from that of the previous frame");
557 "Duration/ID must be set to 0 for CF-End frames");
565 "Less than AIFS elapsed between two TXOPs");
568 "More than AIFS+BO elapsed between two TXOPs");
571 DynamicCast<WifiNetDevice>(
m_apDevices.
Get(0))->GetMac()->GetAddress(),
572 "Expected a frame sent by the first station to the AP");
576 "Duration/ID of the frame sent by the first station does not cover the remaining TXOP");
586 DynamicCast<WifiNetDevice>(
m_staDevices.
Get(0))->GetMac()->GetAddress(),
587 "Expected a Normal Ack sent to the first station");
590 RoundDurationId(
m_txPsdus[10].header.GetDuration() - sifs -
m_txPsdus[11].txDuration),
591 "Duration/ID of the Ack must be derived from that of the previous frame");
602 "Duration/ID must be set to 0 for CF-End frames");
633 DynamicCast<WifiNetDevice>(
m_staDevices.
Get(0))->GetMac()->GetAddress(),
634 "Expected an RTS frame sent by the AP to the first station");
637 "Duration/ID of the first RTS frame must cover the whole TXOP");
645 "CTS in response to the first RTS frame sent too early");
647 tEnd + sifs + tolerance,
648 "CTS in response to the first RTS frame sent too late");
651 DynamicCast<WifiNetDevice>(
m_apDevices.
Get(0))->GetMac()->GetAddress(),
652 "Expected a CTS frame sent to the AP");
655 RoundDurationId(
m_txPsdus[13].header.GetDuration() - sifs -
m_txPsdus[14].txDuration),
656 "Duration/ID of the CTS frame must be derived from that of the RTS frame");
666 DynamicCast<WifiNetDevice>(
m_staDevices.
Get(0))->GetMac()->GetAddress(),
667 "Expected a frame sent by the AP to the first station");
672 "Duration/ID of the first QoS data frame does not cover the remaining TXOP");
680 "Ack in response to the first QoS data frame sent too early");
682 tEnd + sifs + tolerance,
683 "Ack in response to the first QoS data frame sent too late");
686 DynamicCast<WifiNetDevice>(
m_apDevices.
Get(0))->GetMac()->GetAddress(),
687 "Expected a Normal Ack sent to the AP");
690 RoundDurationId(
m_txPsdus[15].header.GetDuration() - sifs -
m_txPsdus[16].txDuration),
691 "Duration/ID of the Ack must be derived from that of the previous frame");
701 DynamicCast<WifiNetDevice>(
m_staDevices.
Get(1))->GetMac()->GetAddress(),
702 "Expected an RTS frame sent by the AP to the second station");
706 "Duration/ID of the second RTS frame must cover the whole TXOP");
714 "CTS in response to the second RTS frame sent too early");
716 tEnd + sifs + tolerance,
717 "CTS in response to the second RTS frame sent too late");
720 DynamicCast<WifiNetDevice>(
m_apDevices.
Get(0))->GetMac()->GetAddress(),
721 "Expected a CTS frame sent to the AP");
724 RoundDurationId(
m_txPsdus[17].header.GetDuration() - sifs -
m_txPsdus[18].txDuration),
725 "Duration/ID of the CTS frame must be derived from that of the RTS frame");
735 DynamicCast<WifiNetDevice>(
m_staDevices.
Get(1))->GetMac()->GetAddress(),
736 "Expected a frame sent by the AP to the second station");
741 "Duration/ID of the second QoS data frame does not cover the remaining TXOP");
749 "Ack in response to the second QoS data frame sent too early");
751 tEnd + sifs + tolerance,
752 "Ack in response to the second QoS data frame sent too late");
755 DynamicCast<WifiNetDevice>(
m_apDevices.
Get(0))->GetMac()->GetAddress(),
756 "Expected a Normal Ack sent to the AP");
759 RoundDurationId(
m_txPsdus[19].header.GetDuration() - sifs -
m_txPsdus[20].txDuration),
760 "Duration/ID of the Ack must be derived from that of the previous frame");
770 DynamicCast<WifiNetDevice>(
m_staDevices.
Get(2))->GetMac()->GetAddress(),
771 "Expected an RTS frame sent by the AP to the third station");
775 "Duration/ID of the third RTS frame must cover the whole TXOP");
783 "CTS in response to the third RTS frame sent too early");
785 tEnd + sifs + tolerance,
786 "CTS in response to the third RTS frame sent too late");
789 DynamicCast<WifiNetDevice>(
m_apDevices.
Get(0))->GetMac()->GetAddress(),
790 "Expected a CTS frame sent to the AP");
793 RoundDurationId(
m_txPsdus[21].header.GetDuration() - sifs -
m_txPsdus[22].txDuration),
794 "Duration/ID of the CTS frame must be derived from that of the RTS frame");
804 DynamicCast<WifiNetDevice>(
m_staDevices.
Get(2))->GetMac()->GetAddress(),
805 "Expected a frame sent by the AP to the third station");
810 "Duration/ID of the third QoS data frame does not cover the remaining TXOP");
818 "Ack in response to the third QoS data frame sent too early");
820 tEnd + sifs + tolerance,
821 "Ack in response to the third QoS data frame sent too late");
824 DynamicCast<WifiNetDevice>(
m_apDevices.
Get(0))->GetMac()->GetAddress(),
825 "Expected a Normal Ack sent to the AP");
828 RoundDurationId(
m_txPsdus[23].header.GetDuration() - sifs -
m_txPsdus[24].txDuration),
829 "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
void DoRun() override
Implementation to actually run this TestCase.
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.
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
WifiTxopTest(bool pifsRecovery)
Constructor.
void CheckResults()
Check correctness of transmitted frames.
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.
keep track of a set of node pointers.
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>.
Smart pointer class similar to boost::intrusive_ptr.
Handle packet fragmentation and retransmissions for QoS data frames as well as MSDU aggregation (A-MS...
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.
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.
uint32_t GetMinCw() const
Return the minimum contention window size.
uint8_t GetAifsn() const
Return the number of slots that make up an AIFS.
Hold an unsigned integer type.
helps to create WifiNetDevice objects
create MAC layers for a ns3::WifiNetDevice.
static Time CalculateTxDuration(uint32_t size, const WifiTxVector &txVector, WifiPhyBand band, uint16_t staId=SU_STA_ID)
static Time CalculatePhyPreambleAndHeaderDuration(const WifiTxVector &txVector)
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_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, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
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.
static WifiTxopTestSuite g_wifiTxopTestSuite
the test suite