9#include "ns3/attribute-container.h"
10#include "ns3/boolean.h"
11#include "ns3/config.h"
12#include "ns3/frame-exchange-manager.h"
13#include "ns3/he-phy.h"
15#include "ns3/mobility-helper.h"
16#include "ns3/multi-model-spectrum-channel.h"
17#include "ns3/packet-socket-client.h"
18#include "ns3/packet-socket-helper.h"
19#include "ns3/packet-socket-server.h"
20#include "ns3/packet.h"
21#include "ns3/pointer.h"
22#include "ns3/qos-txop.h"
23#include "ns3/qos-utils.h"
24#include "ns3/rng-seed-manager.h"
25#include "ns3/spectrum-wifi-helper.h"
26#include "ns3/sta-wifi-mac.h"
27#include "ns3/string.h"
29#include "ns3/wifi-mac-header.h"
30#include "ns3/wifi-mac-queue.h"
31#include "ns3/wifi-net-device.h"
32#include "ns3/wifi-psdu.h"
106 void DoRun()
override;
126 void CheckValues(
const std::map<uint16_t, uint32_t>& seqNoRetryCountMap,
129 std::optional<std::size_t> qsrcOther);
173 :
TestCase(
std::string(
"Check retransmit procedure (useRts=") +
std::to_string(params.useRts) +
174 ", incrRetryCountUnderBa=" +
std::to_string(params.incrRetryCountUnderBa) +
175 ", useBarAfterBaTimeout=" +
std::to_string(params.useBarAfterBaTimeout) +
176 ", pifsRecovery=" +
std::to_string(params.pifsRecovery) +
")"),
177 m_nLinks(params.isMld ? 2 : 1),
178 m_useRts(params.useRts),
179 m_incrRetryCountUnderBa(params.incrRetryCountUnderBa),
180 m_useBarAfterBaTimeout(params.useBarAfterBaTimeout),
181 m_pifsRecovery(params.pifsRecovery),
191 int64_t streamNumber = 10;
199 phy.Set(0,
"ChannelSettings",
StringValue(
"{0, 80, BAND_5GHZ, 0}"));
203 phy.Set(1,
"ChannelSettings",
StringValue(
"{0, 40, BAND_6GHZ, 0}"));
217 wifi.SetRemoteStationManager(
"ns3::ConstantRateWifiManager",
224 mac.SetType(
"ns3::StaWifiMac",
"Ssid",
SsidValue(
Ssid(
"retransmit-ssid")));
230 phy.Set(0,
"ChannelSettings",
StringValue(
"{0, 160, BAND_5GHZ, 0}"));
232 mac.SetType(
"ns3::ApWifiMac");
237 m_apDevice = wifi.Install(phy, mac, wifiApNode);
246 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
247 positionAlloc->Add(Vector(1.0, 0.0, 0.0));
248 mobility.SetPositionAllocator(positionAlloc);
250 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
251 mobility.Install(wifiApNode);
252 mobility.Install(wifiStaNode);
255 packetSocket.
Install(wifiApNode);
256 packetSocket.
Install(wifiStaNode);
263 server->SetLocal(srvAddr);
264 wifiApNode.Get(0)->AddApplication(server);
265 server->SetStartTime(
Time{0});
266 server->SetStopTime(
Seconds(1.0));
275 for (std::size_t linkId = 0; linkId <
m_nLinks; ++linkId)
277 dev->GetMac()->GetWifiPhy(linkId)->SetPostReceptionErrorModel(
m_apErrorModel);
281 [
this](
Mac48Address, uint8_t, std::optional<Mac48Address>) {
286 m_staMac->BlockTxOnLink(1, WifiQueueBlockedReason::TID_NOT_MAPPED);
290 m_staMac->GetQosTxop(
AC_BE)->TraceConnectWithoutContext(
"BaEstablished", baEstablished);
293 for (std::size_t phyId = 0; phyId <
m_nLinks; phyId++)
296 "/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phys/" + std::to_string(phyId) +
308 std::optional<std::size_t> qsrcOther)
315 staQueue->GetNPackets(queueId),
316 "Unexpected number of queued MPDUs when transmitting frame #"
320 while ((mpdu = staQueue->PeekByQueueId(queueId, mpdu)))
322 const auto seqNo = mpdu->GetHeader().GetSequenceNumber();
323 const auto it = seqNoRetryCountMap.find(seqNo);
326 "SeqNo " << seqNo <<
" not found in PSDU #" << psduNumber);
329 "Unexpected retry count for MPDU with SeqNo=" << seqNo <<
" in PSDU #"
335 "QSRC for other link can be provided iff devices are multi-link");
337 std::map<uint8_t, std::size_t> qsrcLinkIdMap{{linkId, qsrc}};
341 qsrcLinkIdMap.emplace((linkId == 0 ? 1 : 0), qsrcOther.value());
346 for (
const auto& [
id, expectedQsrc] : qsrcLinkIdMap)
350 "Unexpected QSRC value on link " << +
id <<
" when transmitting PSDU #"
353 const auto cwMin = txop->GetMinCw(
id);
354 const auto cwMax = txop->GetMaxCw(
id);
355 const auto expectedCw = std::min(cwMax, (1 << expectedQsrc) * (cwMin + 1) - 1);
359 "Unexpected CW value on link " << +
id <<
" when transmitting PSDU #"
370 const auto psdu = psduMap.cbegin()->second;
371 const auto& hdr = psdu->GetHeader(0);
372 const auto printAndQuit = (!
m_baEstablished || hdr.IsBeacon() || hdr.IsCfEnd());
374 std::stringstream ss;
375 ss <<
" Phy ID " << +phyId;
384 ss <<
"\nTXVECTOR = " << txVector <<
"\n";
396 const auto expectedWidth = (phyId == 0 ? 80 : 40);
401 "Unexpected width for " << hdr.GetTypeString());
409 "Unexpected MAC header type for frame #"
426 std::list<uint64_t> uids;
429 uids.push_back(mpdu->GetPacket()->GetUid());
436 auto alternateLinks =
438 m_staMac->BlockTxOnLink(0, WifiQueueBlockedReason::TID_NOT_MAPPED);
440 const auto txDuration =
444 m_staMac->UnblockTxOnLink({1}, WifiQueueBlockedReason::TID_NOT_MAPPED);
448 std::size_t qsrc = 0;
450 std::optional<std::size_t> qsrcOther;
461 CheckValues({{0, 0}, {1, 0}}, 0, linkId, qsrcOther);
463 dropPsdu(psdu, txVector);
474 m_staMac->GetFrameExchangeManager(0)->GetWifiTxTimer().GetDelayLeft());
510 alternateLinks(psdu, txVector,
Time{0});
527 CheckValues({{0, 1}, {1, 1}, {2, 0}, {3, 0}}, qsrc, linkId, qsrcOther);
531 CheckValues({{0, 0}, {1, 0}, {2, 0}, {3, 0}}, qsrc, linkId, qsrcOther);
551 CheckValues({{1, 1}, {2, 0}}, qsrc, linkId, qsrcOther);
555 CheckValues({{1, 0}, {2, 0}}, qsrc, linkId, qsrcOther);
580 CheckValues({{1, retryCount}, {2, retryCount - 1}},
587 CheckValues({{1, 0}, {2, 0}}, qsrc, linkId, qsrcOther);
604 CheckValues({{1, retryCount}, {2, retryCount - 1}}, qsrc, linkId, qsrcOther);
608 CheckValues({{1, 0}, {2, 0}}, qsrc, linkId, qsrcOther);
611 dropPsdu(psdu, txVector);
626 for (std::size_t count = 0; count < 4; ++count)
641 dropPsdu(psdu, txVector);
657 CheckValues({{1, 0}, {2, 0}}, qsrc, linkId, qsrcOther);
691 client->SetStartTime(
Time{0});
692 client->SetStopTime(
Seconds(1.0));
712 for (
auto isMld : {
true,
false})
714 for (
auto useRts : {
true,
false})
716 for (
auto incrRetryCountUnderBa : {
true,
false})
718 for (
auto useBarAfterBaTimeout : {
true,
false})
720 for (
auto pifsRecovery : {
true,
false})
725 .incrRetryCountUnderBa = incrRetryCountUnderBa,
726 .useBarAfterBaTimeout = useBarAfterBaTimeout,
727 .pifsRecovery = pifsRecovery}),
728 TestCase::Duration::QUICK);
Test retransmit procedure.
std::list< Events >::const_iterator m_eventIt
iterator over the list of events
NetDeviceContainer m_apDevice
container for AP's NetDevice
bool m_incrRetryCountUnderBa
whether retry count is incremented under block ack
bool m_useBarAfterBaTimeout
whether to send a BAR after a missed BlockAck
PacketSocketAddress m_ulSocket
packet socket address for UL traffic
const uint32_t m_frameRetryLimit
frame retry limit
void DoSetup() override
Implementation to do any local setup required for this TestCase.
const std::size_t m_pktSize
size in bytes of generated packets
std::list< Events > m_events
list of events for a test run
const Time m_txopLimit
TXOP limit.
void DoRun() override
Implementation to actually run this TestCase.
void SetEvents()
Set the list of events to expect in this test run.
std::size_t m_nLinks
number of links for the devices
Ptr< StaWifiMac > m_staMac
MAC of the non-AP STA.
WifiRetransmitTest(const Params ¶ms)
Constructor.
void CheckValues(const std::map< uint16_t, uint32_t > &seqNoRetryCountMap, std::size_t qsrc, uint8_t linkId, std::optional< std::size_t > qsrcOther)
Check the retry count of the MPDUs stored in the STA MAC queue, the CW and the QSRC of the given link...
Ptr< ListErrorModel > m_apErrorModel
error model to install on the AP
void Transmit(uint8_t phyId, WifiConstPsduMap psduMap, WifiTxVector txVector, double txPowerW)
Callback invoked when PHY receives a PSDU to transmit.
bool m_pifsRecovery
whether to use PIFS recovery
Ptr< PacketSocketClient > GetApplication(std::size_t count, std::size_t pktSize) const
bool m_baEstablished
whether BA agreement has been established
bool m_useRts
whether RTS is used to protect frame transmissions
wifi retransmit procedure Test Suite
WifiRetransmitTestSuite()
A container for one type of attribute.
AttributeValue implementation for Boolean.
static WifiMode GetHeMcs8()
Return MCS 8 from HE MCS values.
Provide a list of Packet uids to corrupt.
void SetList(const std::list< uint64_t > &packetlist)
static Mac48Address ConvertFrom(const Address &address)
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.
uint32_t AddApplication(Ptr< Application > application)
Associate an Application to this Node.
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 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, Duration duration=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
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.
AttributeValue implementation for WifiMode.
static Time CalculateTxDuration(uint32_t size, const WifiTxVector &txVector, WifiPhyBand band, uint16_t staId=SU_STA_ID)
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
MHz_u GetChannelWidth() const
void SetDefault(std::string name, const AttributeValue &value)
void ConnectWithoutContext(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_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_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 Seconds(double value)
Construct a Time in the indicated unit.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
U * PeekPointer(const Ptr< U > &p)
std:: tuple< WifiContainerQueueType, WifiReceiverAddressType, Mac48Address, std::optional< uint8_t > > WifiContainerQueueId
Tuple (queue type, receiver address type, Address, TID) identifying a container queue.
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.
WifiMacType
Combination of valid MAC header type/subtype.
Ptr< T1 > StaticCast(const Ptr< T2 > &p)
Cast a Ptr.
std::unordered_map< uint16_t, Ptr< const WifiPsdu > > WifiConstPsduMap
Map of const PSDUs indexed by STA-ID.
Actions and checks to perform upon the transmission of each frame.
std::function< void(Ptr< const WifiPsdu >, const WifiTxVector &)> func
function to perform actions and checks
WifiMacType hdrType
MAC header type of frame being transmitted.
Events(WifiMacType type, std::function< void(Ptr< const WifiPsdu >, const WifiTxVector &)> &&f={})
Constructor.
Parameters for this test.
bool useRts
whether RTS is used to protect frame transmissions
bool useBarAfterBaTimeout
whether to send a BAR after a missed BlockAck
bool pifsRecovery
whether PIFS recovery is used after failure of a non-initial
bool isMld
whether devices are MLDs
bool incrRetryCountUnderBa
whether retry count is incremented under block ack
uint32_t pktSize
packet size used for the simulation (in bytes)
static WifiRetransmitTestSuite g_wifiRetransmitTestSuite
the test suite