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"
101 void DoRun()
override;
121 void CheckValues(
const std::map<uint16_t, uint32_t>& seqNoRetryCountMap,
124 std::optional<std::size_t> qsrcOther);
168 :
TestCase(
std::string(
"Check retransmit procedure (useRts=") +
std::to_string(params.useRts) +
169 ", incrRetryCountUnderBa=" +
std::to_string(params.incrRetryCountUnderBa) +
170 ", useBarAfterBaTimeout=" +
std::to_string(params.useBarAfterBaTimeout) +
171 ", pifsRecovery=" +
std::to_string(params.pifsRecovery) +
")"),
172 m_nLinks(params.isMld ? 2 : 1),
173 m_useRts(params.useRts),
174 m_incrRetryCountUnderBa(params.incrRetryCountUnderBa),
175 m_useBarAfterBaTimeout(params.useBarAfterBaTimeout),
176 m_pifsRecovery(params.pifsRecovery),
186 int64_t streamNumber = 10;
194 phy.Set(0,
"ChannelSettings",
StringValue(
"{0, 20, BAND_5GHZ, 0}"));
198 phy.Set(1,
"ChannelSettings",
StringValue(
"{0, 20, BAND_6GHZ, 0}"));
212 wifi.SetRemoteStationManager(
"ns3::ConstantRateWifiManager",
219 mac.SetType(
"ns3::StaWifiMac",
"Ssid",
SsidValue(
Ssid(
"retransmit-ssid")));
224 mac.SetType(
"ns3::ApWifiMac");
229 m_apDevice = wifi.Install(phy, mac, wifiApNode);
238 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
239 positionAlloc->Add(Vector(1.0, 0.0, 0.0));
240 mobility.SetPositionAllocator(positionAlloc);
242 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
243 mobility.Install(wifiApNode);
244 mobility.Install(wifiStaNode);
247 packetSocket.
Install(wifiApNode);
248 packetSocket.
Install(wifiStaNode);
255 server->SetLocal(srvAddr);
256 wifiApNode.Get(0)->AddApplication(server);
257 server->SetStartTime(
Time{0});
258 server->SetStopTime(
Seconds(1.0));
267 for (std::size_t linkId = 0; linkId <
m_nLinks; ++linkId)
269 dev->GetMac()->GetWifiPhy(linkId)->SetPostReceptionErrorModel(
m_apErrorModel);
273 [
this](
Mac48Address, uint8_t, std::optional<Mac48Address>) {
278 m_staMac->BlockTxOnLink(1, WifiQueueBlockedReason::TID_NOT_MAPPED);
282 m_staMac->GetQosTxop(
AC_BE)->TraceConnectWithoutContext(
"BaEstablished", baEstablished);
285 for (std::size_t phyId = 0; phyId <
m_nLinks; phyId++)
288 "/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phys/" + std::to_string(phyId) +
300 std::optional<std::size_t> qsrcOther)
307 staQueue->GetNPackets(queueId),
308 "Unexpected number of queued MPDUs when transmitting frame #"
312 while ((mpdu = staQueue->PeekByQueueId(queueId, mpdu)))
314 const auto seqNo = mpdu->GetHeader().GetSequenceNumber();
315 const auto it = seqNoRetryCountMap.find(seqNo);
318 "SeqNo " << seqNo <<
" not found in PSDU #" << psduNumber);
321 "Unexpected retry count for MPDU with SeqNo=" << seqNo <<
" in PSDU #"
327 "QSRC for other link can be provided iff devices are multi-link");
329 std::map<uint8_t, std::size_t> qsrcLinkIdMap{{linkId, qsrc}};
333 qsrcLinkIdMap.emplace((linkId == 0 ? 1 : 0), qsrcOther.value());
338 for (
const auto& [
id, expectedQsrc] : qsrcLinkIdMap)
342 "Unexpected QSRC value on link " << +
id <<
" when transmitting PSDU #"
345 const auto cwMin = txop->GetMinCw(
id);
346 const auto cwMax = txop->GetMaxCw(
id);
347 const auto expectedCw = std::min(cwMax, (1 << expectedQsrc) * (cwMin + 1) - 1);
351 "Unexpected CW value on link " << +
id <<
" when transmitting PSDU #"
362 const auto psdu = psduMap.cbegin()->second;
363 const auto& hdr = psdu->GetHeader(0);
364 const auto printAndQuit = (!
m_baEstablished || hdr.IsBeacon() || hdr.IsCfEnd());
366 std::stringstream ss;
367 ss <<
" Phy ID " << +phyId;
376 ss <<
"\nTXVECTOR = " << txVector <<
"\n";
391 "Unexpected MAC header type for frame #"
408 std::list<uint64_t> uids;
411 uids.push_back(mpdu->GetPacket()->GetUid());
418 auto alternateLinks =
420 m_staMac->BlockTxOnLink(0, WifiQueueBlockedReason::TID_NOT_MAPPED);
422 const auto txDuration =
426 m_staMac->UnblockTxOnLink({1}, WifiQueueBlockedReason::TID_NOT_MAPPED);
430 std::size_t qsrc = 0;
432 std::optional<std::size_t> qsrcOther;
443 CheckValues({{0, 0}, {1, 0}}, 0, linkId, qsrcOther);
445 dropPsdu(psdu, txVector);
456 m_staMac->GetFrameExchangeManager(0)->GetWifiTxTimer().GetDelayLeft());
492 alternateLinks(psdu, txVector,
Time{0});
509 CheckValues({{0, 1}, {1, 1}, {2, 0}, {3, 0}}, qsrc, linkId, qsrcOther);
513 CheckValues({{0, 0}, {1, 0}, {2, 0}, {3, 0}}, qsrc, linkId, qsrcOther);
533 CheckValues({{1, 1}, {2, 0}}, qsrc, linkId, qsrcOther);
537 CheckValues({{1, 0}, {2, 0}}, qsrc, linkId, qsrcOther);
562 CheckValues({{1, retryCount}, {2, retryCount - 1}},
569 CheckValues({{1, 0}, {2, 0}}, qsrc, linkId, qsrcOther);
586 CheckValues({{1, retryCount}, {2, retryCount - 1}}, qsrc, linkId, qsrcOther);
590 CheckValues({{1, 0}, {2, 0}}, qsrc, linkId, qsrcOther);
593 dropPsdu(psdu, txVector);
608 for (std::size_t count = 0; count < 4; ++count)
623 dropPsdu(psdu, txVector);
639 CheckValues({{1, 0}, {2, 0}}, qsrc, linkId, qsrcOther);
673 client->SetStartTime(
Time{0});
674 client->SetStopTime(
Seconds(1.0));
694 for (
auto isMld : {
true,
false})
696 for (
auto useRts : {
true,
false})
698 for (
auto incrRetryCountUnderBa : {
true,
false})
700 for (
auto useBarAfterBaTimeout : {
true,
false})
702 for (
auto pifsRecovery : {
true,
false})
707 .incrRetryCountUnderBa = incrRetryCountUnderBa,
708 .useBarAfterBaTimeout = useBarAfterBaTimeout,
709 .pifsRecovery = pifsRecovery}),
710 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.
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.
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.
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.
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...
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