From 2d9a2bb22f36ae5c4710ac4c229e8a5501c0b1e2 Mon Sep 17 00:00:00 2001 From: Stefano Avallone Date: Tue, 9 Apr 2024 22:22:06 +0200 Subject: [PATCH] wifi: Make WifiAcknowledgment::acknowledgmentTime optional ...instead of relying on Time::Min() as blank value --- src/wifi/model/frame-exchange-manager.cc | 12 +++++++----- src/wifi/model/he/he-frame-exchange-manager.cc | 9 +++++---- src/wifi/model/he/rr-multi-user-scheduler.cc | 7 ++++--- src/wifi/model/ht/ht-frame-exchange-manager.cc | 12 ++++++------ src/wifi/model/qos-frame-exchange-manager.cc | 12 ++++++------ src/wifi/model/wifi-acknowledgment.cc | 3 +-- src/wifi/model/wifi-acknowledgment.h | 5 +++-- src/wifi/test/wifi-mac-ofdma-test.cc | 2 +- 8 files changed, 33 insertions(+), 29 deletions(-) diff --git a/src/wifi/model/frame-exchange-manager.cc b/src/wifi/model/frame-exchange-manager.cc index b848847c5..7f21a06ba 100644 --- a/src/wifi/model/frame-exchange-manager.cc +++ b/src/wifi/model/frame-exchange-manager.cc @@ -401,7 +401,7 @@ FrameExchangeManager::SendMpduWithProtection(Ptr mpdu, WifiTxParameter // and SendCtsToSelf() can reuse this value. NS_ASSERT(m_txParams.m_acknowledgment); - if (m_txParams.m_acknowledgment->acknowledgmentTime == Time::Min()) + if (!m_txParams.m_acknowledgment->acknowledgmentTime.has_value()) { CalculateAcknowledgmentTime(m_txParams.m_acknowledgment.get()); } @@ -648,8 +648,8 @@ FrameExchangeManager::GetFrameDurationId(const WifiMacHeader& header, NS_LOG_FUNCTION(this << header << size << &txParams << fragmentedPacket); NS_ASSERT(txParams.m_acknowledgment && - txParams.m_acknowledgment->acknowledgmentTime != Time::Min()); - Time durationId = txParams.m_acknowledgment->acknowledgmentTime; + txParams.m_acknowledgment->acknowledgmentTime.has_value()); + auto durationId = *txParams.m_acknowledgment->acknowledgmentTime; // if the current frame is a fragment followed by another fragment, we have to // update the Duration/ID to cover the next fragment and the corresponding Ack @@ -706,9 +706,10 @@ FrameExchangeManager::SendRts(const WifiTxParameters& txParams) auto rtsCtsProtection = static_cast(txParams.m_protection.get()); NS_ASSERT(txParams.m_txDuration.has_value()); + NS_ASSERT(txParams.m_acknowledgment->acknowledgmentTime.has_value()); rts.SetDuration(GetRtsDurationId(rtsCtsProtection->rtsTxVector, *txParams.m_txDuration, - txParams.m_acknowledgment->acknowledgmentTime)); + *txParams.m_acknowledgment->acknowledgmentTime)); Ptr mpdu = Create(Create(), rts); // After transmitting an RTS frame, the STA shall wait for a CTSTimeout interval with @@ -807,9 +808,10 @@ FrameExchangeManager::SendCtsToSelf(const WifiTxParameters& txParams) auto ctsToSelfProtection = static_cast(txParams.m_protection.get()); NS_ASSERT(txParams.m_txDuration.has_value()); + NS_ASSERT(txParams.m_acknowledgment->acknowledgmentTime.has_value()); cts.SetDuration(GetCtsToSelfDurationId(ctsToSelfProtection->ctsTxVector, *txParams.m_txDuration, - txParams.m_acknowledgment->acknowledgmentTime)); + *txParams.m_acknowledgment->acknowledgmentTime)); ForwardMpduDown(Create(Create(), cts), ctsToSelfProtection->ctsTxVector); diff --git a/src/wifi/model/he/he-frame-exchange-manager.cc b/src/wifi/model/he/he-frame-exchange-manager.cc index 680d9bb90..66c70dfcb 100644 --- a/src/wifi/model/he/he-frame-exchange-manager.cc +++ b/src/wifi/model/he/he-frame-exchange-manager.cc @@ -212,7 +212,7 @@ HeFrameExchangeManager::SendPsduMapWithProtection(WifiPsduMap psduMap, WifiTxPar // can reuse this value. NS_ASSERT(m_txParams.m_acknowledgment); - if (m_txParams.m_acknowledgment->acknowledgmentTime == Time::Min()) + if (!m_txParams.m_acknowledgment->acknowledgmentTime.has_value()) { CalculateAcknowledgmentTime(m_txParams.m_acknowledgment.get()); } @@ -233,7 +233,7 @@ HeFrameExchangeManager::SendPsduMapWithProtection(WifiPsduMap psduMap, WifiTxPar << ") incompatible with BSRP Trigger Frame"); // Add a SIFS and the TB PPDU duration to the acknowledgment time of the Trigger Frame auto txVector = trigger.GetHeTbTxVector(trigger.begin()->GetAid12()); - m_txParams.m_acknowledgment->acknowledgmentTime += + *m_txParams.m_acknowledgment->acknowledgmentTime += m_phy->GetSifs() + HePhy::ConvertLSigLengthToHeTbPpduDuration(trigger.GetUlLength(), txVector, m_phy->GetPhyBand()); @@ -361,11 +361,12 @@ HeFrameExchangeManager::SendMuRts(const WifiTxParameters& txParams) auto mpdu = Create(payload, hdr); NS_ASSERT(txParams.m_txDuration.has_value()); + NS_ASSERT(txParams.m_acknowledgment->acknowledgmentTime.has_value()); mpdu->GetHeader().SetDuration( GetMuRtsDurationId(mpdu->GetSize(), protection->muRtsTxVector, *txParams.m_txDuration, - txParams.m_acknowledgment->acknowledgmentTime)); + *txParams.m_acknowledgment->acknowledgmentTime)); // Get the TXVECTOR used by one station to send the CTS response. This is used // to compute the preamble duration, so it does not matter which station we choose @@ -624,7 +625,7 @@ HeFrameExchangeManager::SendPsduMap() acknowledgment->muBarTxVector, m_phy->GetPhyBand()); // update acknowledgmentTime to correctly set the Duration/ID - acknowledgment->acknowledgmentTime -= (m_phy->GetSifs() + txDuration); + *acknowledgment->acknowledgmentTime -= (m_phy->GetSifs() + txDuration); m_triggerFrame->GetHeader().SetDuration(GetPsduDurationId(txDuration, m_txParams)); responseTxVector = diff --git a/src/wifi/model/he/rr-multi-user-scheduler.cc b/src/wifi/model/he/rr-multi-user-scheduler.cc index 7d6dca676..f8acfc047 100644 --- a/src/wifi/model/he/rr-multi-user-scheduler.cc +++ b/src/wifi/model/he/rr-multi-user-scheduler.cc @@ -348,7 +348,8 @@ RrMultiUserScheduler::TrySendingBsrpTf() // TryAddMpdu only considers the time to transmit the Trigger Frame NS_ASSERT(m_txParams.m_protection && m_txParams.m_protection->protectionTime.has_value()); NS_ASSERT(m_txParams.m_acknowledgment && - m_txParams.m_acknowledgment->acknowledgmentTime.IsZero()); + m_txParams.m_acknowledgment->acknowledgmentTime.has_value() && + m_txParams.m_acknowledgment->acknowledgmentTime->IsZero()); NS_ASSERT(m_txParams.m_txDuration.has_value()); if (*m_txParams.m_protection->protectionTime + *m_txParams.m_txDuration // BSRP TF tx time @@ -458,13 +459,13 @@ RrMultiUserScheduler::TrySendingBasicTf() // TryAddMpdu only considers the time to transmit the Trigger Frame NS_ASSERT(m_txParams.m_protection && m_txParams.m_protection->protectionTime.has_value()); NS_ASSERT(m_txParams.m_acknowledgment && - m_txParams.m_acknowledgment->acknowledgmentTime != Time::Min()); + m_txParams.m_acknowledgment->acknowledgmentTime.has_value()); NS_ASSERT(m_txParams.m_txDuration.has_value()); maxDuration = Min(maxDuration, m_availableTime - *m_txParams.m_protection->protectionTime - *m_txParams.m_txDuration - m_apMac->GetWifiPhy(m_linkId)->GetSifs() - - m_txParams.m_acknowledgment->acknowledgmentTime); + *m_txParams.m_acknowledgment->acknowledgmentTime); if (maxDuration.IsNegative()) { NS_LOG_DEBUG("Remaining TXOP duration is not enough for UL MU exchange"); diff --git a/src/wifi/model/ht/ht-frame-exchange-manager.cc b/src/wifi/model/ht/ht-frame-exchange-manager.cc index 6434d36af..5250e9206 100644 --- a/src/wifi/model/ht/ht-frame-exchange-manager.cc +++ b/src/wifi/model/ht/ht-frame-exchange-manager.cc @@ -885,8 +885,8 @@ HtFrameExchangeManager::GetPsduDurationId(Time txDuration, const WifiTxParameter if (m_edca->GetTxopLimit(m_linkId).IsZero()) { NS_ASSERT(txParams.m_acknowledgment && - txParams.m_acknowledgment->acknowledgmentTime != Time::Min()); - return txParams.m_acknowledgment->acknowledgmentTime; + txParams.m_acknowledgment->acknowledgmentTime.has_value()); + return *txParams.m_acknowledgment->acknowledgmentTime; } // under multiple protection settings, if the TXOP limit is not null, Duration/ID @@ -920,7 +920,7 @@ HtFrameExchangeManager::SendPsduWithProtection(Ptr psdu, WifiTxParamet // and SendCtsToSelf() can reuse this value. NS_ASSERT(m_txParams.m_acknowledgment); - if (m_txParams.m_acknowledgment->acknowledgmentTime == Time::Min()) + if (!m_txParams.m_acknowledgment->acknowledgmentTime.has_value()) { CalculateAcknowledgmentTime(m_txParams.m_acknowledgment.get()); } @@ -1232,7 +1232,7 @@ HtFrameExchangeManager::TryAggregateMsdu(Ptr msdu, // check if aggregating the given MSDU requires a different acknowledgment method NS_ASSERT(txParams.m_acknowledgment); - Time acknowledgmentTime = txParams.m_acknowledgment->acknowledgmentTime; + auto acknowledgmentTime = txParams.m_acknowledgment->acknowledgmentTime; std::unique_ptr acknowledgment; acknowledgment = GetAckManager()->TryAggregateMsdu(msdu, txParams); @@ -1248,12 +1248,12 @@ HtFrameExchangeManager::TryAggregateMsdu(Ptr msdu, txParams.m_acknowledgment.swap(acknowledgment); acknowledgmentSwapped = true; } - NS_ASSERT(acknowledgmentTime != Time::Min()); + NS_ASSERT(acknowledgmentTime.has_value()); Time ppduDurationLimit = Time::Min(); if (availableTime != Time::Min()) { - ppduDurationLimit = availableTime - *protectionTime - acknowledgmentTime; + ppduDurationLimit = availableTime - *protectionTime - *acknowledgmentTime; } if (!IsWithinLimitsIfAggregateMsdu(msdu, txParams, ppduDurationLimit)) diff --git a/src/wifi/model/qos-frame-exchange-manager.cc b/src/wifi/model/qos-frame-exchange-manager.cc index 5d18ab06e..dfef0eeb6 100644 --- a/src/wifi/model/qos-frame-exchange-manager.cc +++ b/src/wifi/model/qos-frame-exchange-manager.cc @@ -359,7 +359,7 @@ QosFrameExchangeManager::TryAddMpdu(Ptr mpdu, NS_LOG_DEBUG("protection time=" << *protectionTime); // check if adding the given MPDU requires a different acknowledgment method - Time acknowledgmentTime = Time::Min(); // uninitialized + std::optional