diff --git a/src/wifi/model/wifi-phy.cc b/src/wifi/model/wifi-phy.cc index c12df3bcb..4c28b854b 100644 --- a/src/wifi/model/wifi-phy.cc +++ b/src/wifi/model/wifi-phy.cc @@ -38,7 +38,6 @@ #include "he-configuration.h" #include "mpdu-aggregator.h" #include "wifi-psdu.h" -#include "wifi-ppdu.h" namespace ns3 { @@ -2545,6 +2544,27 @@ WifiPhy::CalculateTxDuration (uint32_t size, WifiTxVector txVector, WifiPhyBand return duration; } +Time +WifiPhy::CalculateTxDuration (WifiConstPsduMap psduMap, WifiTxVector txVector, WifiPhyBand band) +{ + Time maxDuration = Seconds (0); + for (auto & staIdPsdu : psduMap) + { + if (txVector.GetPreambleType () == WIFI_PREAMBLE_HE_MU) + { + WifiTxVector::HeMuUserInfoMap userInfoMap = txVector.GetHeMuUserInfoMap (); + NS_ABORT_MSG_IF (userInfoMap.find (staIdPsdu.first) == userInfoMap.end (), "STA-ID in psduMap (" << staIdPsdu.first << ") should be referenced in txVector"); + } + Time current = CalculateTxDuration (staIdPsdu.second->GetSize (), txVector, band, staIdPsdu.first); + if (current > maxDuration) + { + maxDuration = current; + } + } + NS_ASSERT (maxDuration.IsStrictlyPositive ()); + return maxDuration; +} + void WifiPhy::NotifyTxBegin (Ptr psdu, double txPowerW) { diff --git a/src/wifi/model/wifi-phy.h b/src/wifi/model/wifi-phy.h index a09a5fc95..b014a74fb 100644 --- a/src/wifi/model/wifi-phy.h +++ b/src/wifi/model/wifi-phy.h @@ -28,6 +28,7 @@ #include "wifi-standards.h" #include "interference-helper.h" #include "wifi-phy-state-helper.h" +#include "wifi-ppdu.h" namespace ns3 { @@ -44,7 +45,6 @@ class PreambleDetectionModel; class WifiRadioEnergyModel; class UniformRandomVariable; class WifiPsdu; -class WifiPpdu; /** * Enumeration of the possible reception failure reasons. @@ -327,6 +327,14 @@ public: */ static Time CalculateTxDuration (uint32_t size, WifiTxVector txVector, WifiPhyBand band, uint16_t staId = SU_STA_ID); + /** + * \param psduMap the PSDU(s) to transmit indexed by STA-ID + * \param txVector the TXVECTOR used for the transmission of the PPDU + * \param band the frequency band being used + * + * \return the total amount of time this PHY will stay busy for the transmission of the PPDU + */ + static Time CalculateTxDuration (WifiConstPsduMap psduMap, WifiTxVector txVector, WifiPhyBand band); /** * \param txVector the transmission parameters used for this packet diff --git a/src/wifi/test/tx-duration-test.cc b/src/wifi/test/tx-duration-test.cc index 2cb3a82b8..dc1139471 100644 --- a/src/wifi/test/tx-duration-test.cc +++ b/src/wifi/test/tx-duration-test.cc @@ -23,6 +23,8 @@ #include "ns3/test.h" #include "ns3/yans-wifi-phy.h" #include "ns3/he-ru.h" +#include "ns3/wifi-psdu.h" +#include "ns3/packet.h" #include using namespace ns3; @@ -90,6 +92,22 @@ private: uint16_t channelWidth, uint16_t guardInterval, Time knownDuration); + /** + * Calculate the overall Tx duration returned by WifiPhy for list of sizes. + * A map of WifiPsdu indexed by STA-ID is built using the provided lists + * and handed over to the corresponding SU/MU WifiPhy Tx duration computing + * method. + * Note that provided lists should be of same size. + * + * @param sizes the list of PSDU sizes for each station in octets + * @param staIds the list of STA-IDs of each station + * @param txVector the TXVECTOR used for the transmission of the PPDU + * @param band the selected wifi PHY band + * + * @return the overall Tx duration for the list of sizes (SU or MU PPDU) + */ + static Time CalculateTxDurationUsingList (std::list sizes, std::list staIds, + WifiTxVector txVector, WifiPhyBand band); }; TxDurationTest::TxDurationTest () @@ -177,7 +195,9 @@ TxDurationTest::CheckTxDuration (uint32_t size, WifiMode payloadMode, uint16_t c band = WIFI_PHY_BAND_5GHZ; } Time calculatedDuration = phy->CalculateTxDuration (size, txVector, band); - if (calculatedDuration != knownDuration) + Time calculatedDurationUsingList = CalculateTxDurationUsingList (std::list {size}, std::list {SU_STA_ID}, + txVector, band); + if (calculatedDuration != knownDuration || calculatedDuration != calculatedDurationUsingList) { std::cerr << "size=" << size << " mode=" << payloadMode @@ -187,6 +207,7 @@ TxDurationTest::CheckTxDuration (uint32_t size, WifiMode payloadMode, uint16_t c << " preamble=" << preamble << " known=" << knownDuration << " calculated=" << calculatedDuration + << " calculatedUsingList=" << calculatedDurationUsingList << std::endl; return false; } @@ -195,8 +216,10 @@ TxDurationTest::CheckTxDuration (uint32_t size, WifiMode payloadMode, uint16_t c //Durations vary depending on frequency; test also 2.4 GHz (bug 1971) band = WIFI_PHY_BAND_2_4GHZ; calculatedDuration = phy->CalculateTxDuration (size, txVector, band); + calculatedDurationUsingList = CalculateTxDurationUsingList (std::list {size}, std::list {SU_STA_ID}, + txVector, band); knownDuration += MicroSeconds (6); - if (calculatedDuration != knownDuration) + if (calculatedDuration != knownDuration || calculatedDuration != calculatedDurationUsingList) { std::cerr << "size=" << size << " mode=" << payloadMode @@ -206,6 +229,7 @@ TxDurationTest::CheckTxDuration (uint32_t size, WifiMode payloadMode, uint16_t c << " preamble=" << preamble << " known=" << knownDuration << " calculated=" << calculatedDuration + << " calculatedUsingList=" << calculatedDurationUsingList << std::endl; return false; } @@ -258,7 +282,8 @@ TxDurationTest::CheckHeMuTxDuration (std::list sizes, std::list