From be2f46e5ad449fed9bae1e109f8f590211d5d745 Mon Sep 17 00:00:00 2001 From: Stefano Avallone Date: Thu, 11 Apr 2024 15:51:17 +0200 Subject: [PATCH] wifi: Remove redundant computation of PPDU TX duration --- .../model/he/he-frame-exchange-manager.cc | 33 ++++++++++--------- src/wifi/model/qos-frame-exchange-manager.cc | 3 +- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/wifi/model/he/he-frame-exchange-manager.cc b/src/wifi/model/he/he-frame-exchange-manager.cc index 8f0a3029a..c9caa1864 100644 --- a/src/wifi/model/he/he-frame-exchange-manager.cc +++ b/src/wifi/model/he/he-frame-exchange-manager.cc @@ -1830,8 +1830,7 @@ HeFrameExchangeManager::SendQosNullFramesInTbPpdu(const CtrlTriggerHeader& trigg return; } - WifiMacHeader header; - header.SetType(WIFI_MAC_QOSDATA_NULL); + WifiMacHeader header(WIFI_MAC_QOSDATA_NULL); header.SetAddr1(hdr.GetAddr2()); header.SetAddr2(m_self); header.SetAddr3(hdr.GetAddr2()); @@ -1853,36 +1852,38 @@ HeFrameExchangeManager::SendQosNullFramesInTbPpdu(const CtrlTriggerHeader& trigg m_phy->GetPhyBand()); header.SetDuration(hdr.GetDuration() - m_phy->GetSifs() - ppduDuration); - Ptr mpdu; std::vector> mpduList; - uint8_t tid = 0; - header.SetQosTid(tid); - while (tid < 8 && - IsWithinSizeAndTimeLimits( - txParams.GetSizeIfAddMpdu(mpdu = Create(Create(), header)), - hdr.GetAddr2(), - txParams, - ppduDuration)) + for (uint8_t tid = 0; tid < 8; ++tid) { if (!m_mac->GetBaAgreementEstablishedAsOriginator(hdr.GetAddr2(), tid)) { NS_LOG_DEBUG("Skipping tid=" << +tid << " because no agreement established"); - header.SetQosTid(++tid); continue; } - NS_LOG_DEBUG("Aggregating a QoS Null frame with tid=" << +tid); - // We could call TryAddMpdu instead of IsWithinSizeAndTimeLimits above in order to + // We could call TryAddMpdu instead of IsWithinSizeAndTimeLimits below in order to // get the TX parameters updated automatically. However, aggregating the QoS Null // frames might fail because MPDU aggregation is disabled by default for VO // and BK. Therefore, we skip the check on max A-MPDU size and only update the // TX parameters below. + header.SetQosTid(tid); + auto mpdu = Create(Create(), header); txParams.AddMpdu(mpdu); - UpdateTxDuration(mpdu->GetHeader().GetAddr1(), txParams); + UpdateTxDuration(header.GetAddr1(), txParams); + + if (!IsWithinSizeAndTimeLimits(txParams.GetSize(header.GetAddr1()), + hdr.GetAddr2(), + txParams, + ppduDuration)) + { + txParams.UndoAddMpdu(); + break; + } + + NS_LOG_DEBUG("Aggregating a QoS Null frame with tid=" << +tid); txParams.m_acknowledgment = GetAckManager()->TryAddMpdu(mpdu, txParams); mpduList.push_back(mpdu); - header.SetQosTid(++tid); } if (mpduList.empty()) diff --git a/src/wifi/model/qos-frame-exchange-manager.cc b/src/wifi/model/qos-frame-exchange-manager.cc index eaeb66a6f..12a43cac2 100644 --- a/src/wifi/model/qos-frame-exchange-manager.cc +++ b/src/wifi/model/qos-frame-exchange-manager.cc @@ -454,7 +454,8 @@ QosFrameExchangeManager::IsWithinSizeAndTimeLimits(uint32_t ppduPayloadSize, // Get the maximum PPDU Duration based on the preamble type Time maxPpduDuration = GetPpduMaxTime(txParams.m_txVector.GetPreambleType()); - Time txTime = GetTxDuration(ppduPayloadSize, receiver, txParams); + NS_ASSERT_MSG(txParams.m_txDuration, "TX duration not yet computed"); + auto txTime = txParams.m_txDuration.value(); NS_LOG_DEBUG("PPDU duration: " << txTime.As(Time::MS)); if ((ppduDurationLimit.IsStrictlyPositive() && txTime > ppduDurationLimit) ||