diff --git a/src/wifi/model/eht/eht-ppdu.cc b/src/wifi/model/eht/eht-ppdu.cc index 908c8917b..d441c6d97 100644 --- a/src/wifi/model/eht/eht-ppdu.cc +++ b/src/wifi/model/eht/eht-ppdu.cc @@ -86,30 +86,16 @@ EhtPpdu::IsUlMu() const return (m_preamble == WIFI_PREAMBLE_EHT_TB) && !m_muUserInfos.empty(); } -WifiTxVector -EhtPpdu::DoGetTxVector() const +void +EhtPpdu::SetTxVectorFromPhyHeaders(WifiTxVector& txVector, + const LSigHeader& lSig, + const HeSigHeader& heSig) const { - auto phyHeaders = m_phyHeaders->Copy(); - - LSigHeader lSig; - if (phyHeaders->RemoveHeader(lSig) == 0) - { - NS_FATAL_ERROR("Missing L-SIG header in EHT PPDU"); - } - - // FIXME: define EHT PHY headers - HeSigHeader ehtPhyHdr; - if (phyHeaders->PeekHeader(ehtPhyHdr) == 0) - { - NS_FATAL_ERROR("Missing EHT PHY headers in EHT PPDU"); - } - WifiTxVector txVector; - txVector.SetPreambleType(m_preamble); txVector.SetMode(EhtPhy::GetEhtMcs(m_ehtSuMcs)); - txVector.SetChannelWidth(ehtPhyHdr.GetChannelWidth()); + txVector.SetChannelWidth(heSig.GetChannelWidth()); txVector.SetNss(m_ehtSuNStreams); - txVector.SetGuardInterval(ehtPhyHdr.GetGuardInterval()); - txVector.SetBssColor(ehtPhyHdr.GetBssColor()); + txVector.SetGuardInterval(heSig.GetGuardInterval()); + txVector.SetBssColor(heSig.GetBssColor()); txVector.SetLength(lSig.GetLength()); txVector.SetAggregation(m_psdus.size() > 1 || m_psdus.begin()->second->IsAggregate()); if (!m_muUserInfos.empty()) @@ -122,10 +108,9 @@ EhtPpdu::DoGetTxVector() const } if (ns3::IsDlMu(m_preamble)) { - txVector.SetSigBMode(HePhy::GetVhtMcs(ehtPhyHdr.GetMcs())); + txVector.SetSigBMode(HePhy::GetVhtMcs(heSig.GetMcs())); txVector.SetRuAllocation(m_ruAllocation); } - return txVector; } Ptr diff --git a/src/wifi/model/eht/eht-ppdu.h b/src/wifi/model/eht/eht-ppdu.h index 4be50bc6b..15d61ef13 100644 --- a/src/wifi/model/eht/eht-ppdu.h +++ b/src/wifi/model/eht/eht-ppdu.h @@ -64,10 +64,12 @@ class EhtPpdu : public HePpdu WifiPpduType GetType() const override; Ptr Copy() const override; - protected: + private: bool IsDlMu() const override; bool IsUlMu() const override; - WifiTxVector DoGetTxVector() const override; + void SetTxVectorFromPhyHeaders(WifiTxVector& txVector, + const LSigHeader& lSig, + const HeSigHeader& heSig) const override; uint8_t m_ehtSuMcs{0}; //!< EHT-MCS for EHT SU transmissions uint8_t m_ehtSuNStreams{1}; //!< Number of streams for EHT SU transmissions diff --git a/src/wifi/model/he/he-ppdu.cc b/src/wifi/model/he/he-ppdu.cc index 8272f426d..91f14b495 100644 --- a/src/wifi/model/he/he-ppdu.cc +++ b/src/wifi/model/he/he-ppdu.cc @@ -107,7 +107,24 @@ HePpdu::SetPhyHeaders(const WifiTxVector& txVector, Time ppduDuration) { NS_LOG_FUNCTION(this << txVector << ppduDuration); +#ifdef NS3_BUILD_PROFILE_DEBUG LSigHeader lSig; + SetLSigHeader(lSig, ppduDuration); + + HeSigHeader heSig; + SetHeSigHeader(heSig, txVector); + + m_phyHeaders->AddHeader(heSig); + m_phyHeaders->AddHeader(lSig); +#else + SetLSigHeader(m_lSig, ppduDuration); + SetHeSigHeader(m_heSig, txVector); +#endif +} + +void +HePpdu::SetLSigHeader(LSigHeader& lSig, Time ppduDuration) const +{ uint8_t sigExtension = 0; if (m_band == WIFI_PHY_BAND_2_4GHZ) { @@ -121,8 +138,11 @@ HePpdu::SetPhyHeaders(const WifiTxVector& txVector, Time ppduDuration) 3) - 3 - m); lSig.SetLength(length); +} - HeSigHeader heSig; +void +HePpdu::SetHeSigHeader(HeSigHeader& heSig, const WifiTxVector& txVector) const +{ if (ns3::IsDlMu(m_preamble)) { heSig.SetMuFlag(true); @@ -136,14 +156,15 @@ HePpdu::SetPhyHeaders(const WifiTxVector& txVector, Time ppduDuration) heSig.SetBssColor(txVector.GetBssColor()); heSig.SetChannelWidth(m_channelWidth); heSig.SetGuardIntervalAndLtfSize(txVector.GetGuardInterval(), 2 /*NLTF currently unused*/); - - m_phyHeaders->AddHeader(heSig); - m_phyHeaders->AddHeader(lSig); } WifiTxVector HePpdu::DoGetTxVector() const { + WifiTxVector txVector; + txVector.SetPreambleType(m_preamble); + +#ifdef NS3_BUILD_PROFILE_DEBUG auto phyHeaders = m_phyHeaders->Copy(); LSigHeader lSig; @@ -158,8 +179,19 @@ HePpdu::DoGetTxVector() const NS_FATAL_ERROR("Missing HE-SIG header in HE PPDU"); } - WifiTxVector txVector; - txVector.SetPreambleType(m_preamble); + SetTxVectorFromPhyHeaders(txVector, lSig, heSig); +#else + SetTxVectorFromPhyHeaders(txVector, m_lSig, m_heSig); +#endif + + return txVector; +} + +void +HePpdu::SetTxVectorFromPhyHeaders(WifiTxVector& txVector, + const LSigHeader& lSig, + const HeSigHeader& heSig) const +{ txVector.SetMode(HePhy::GetHeMcs(heSig.GetMcs())); txVector.SetChannelWidth(heSig.GetChannelWidth()); txVector.SetNss(heSig.GetNStreams()); @@ -176,7 +208,6 @@ HePpdu::DoGetTxVector() const txVector.SetSigBMode(HePhy::GetVhtMcs(heSig.GetMcs())); txVector.SetRuAllocation(m_ruAllocation); } - return txVector; } Time @@ -185,8 +216,14 @@ HePpdu::GetTxDuration() const Time ppduDuration = Seconds(0); const WifiTxVector& txVector = GetTxVector(); + uint16_t length = 0; +#ifdef NS3_BUILD_PROFILE_DEBUG LSigHeader lSig; m_phyHeaders->PeekHeader(lSig); + length = lSig.GetLength(); +#else + length = m_lSig.GetLength(); +#endif Time tSymbol = NanoSeconds(12800 + txVector.GetGuardInterval()); Time preambleDuration = WifiPhy::CalculatePhyPreambleAndHeaderDuration(txVector); @@ -197,8 +234,8 @@ HePpdu::GetTxDuration() const } uint8_t m = IsDlMu() ? 1 : 2; // Equation 27-11 of IEEE P802.11ax/D4.0 - Time calculatedDuration = MicroSeconds( - ((ceil(static_cast(lSig.GetLength() + 3 + m) / 3)) * 4) + 20 + sigExtension); + Time calculatedDuration = + MicroSeconds(((ceil(static_cast(length + 3 + m) / 3)) * 4) + 20 + sigExtension); NS_ASSERT(calculatedDuration > preambleDuration); uint32_t nSymbols = floor(static_cast((calculatedDuration - preambleDuration).GetNanoSeconds() - @@ -255,26 +292,32 @@ HePpdu::GetPsdu(uint8_t bssColor, uint16_t staId /* = SU_STA_ID */) const return m_psdus.at(SU_STA_ID); } + uint8_t ppduBssColor = 0; +#ifdef NS3_BUILD_PROFILE_DEBUG auto phyHeaders = m_phyHeaders->Copy(); LSigHeader lSig; phyHeaders->RemoveHeader(lSig); HeSigHeader heSig; phyHeaders->RemoveHeader(heSig); + ppduBssColor = heSig.GetBssColor(); +#else + ppduBssColor = m_heSig.GetBssColor(); +#endif if (IsUlMu()) { NS_ASSERT(m_psdus.size() == 1); - if (bssColor == 0 || heSig.GetBssColor() == 0 || (bssColor == heSig.GetBssColor())) + if (bssColor == 0 || ppduBssColor == 0 || (bssColor == ppduBssColor)) { - return m_psdus.begin()->second; + return m_psdus.cbegin()->second; } } else { - if (bssColor == 0 || heSig.GetBssColor() == 0 || (bssColor == heSig.GetBssColor())) + if (bssColor == 0 || ppduBssColor == 0 || (bssColor == ppduBssColor)) { - auto it = m_psdus.find(staId); - if (it != m_psdus.end()) + const auto it = m_psdus.find(staId); + if (it != m_psdus.cend()) { return it->second; } diff --git a/src/wifi/model/he/he-ppdu.h b/src/wifi/model/he/he-ppdu.h index 6f06b850b..be5d46e17 100644 --- a/src/wifi/model/he/he-ppdu.h +++ b/src/wifi/model/he/he-ppdu.h @@ -240,33 +240,20 @@ class HePpdu : public OfdmPpdu bool IsAllocated(uint16_t staId) const; protected: - std::string PrintPayload() const override; - WifiTxVector DoGetTxVector() const override; - /** - * Return true if the PPDU is a MU PPDU - * \return true if the PPDU is a MU PPDU - */ - virtual bool IsMu() const; - /** - * Return true if the PPDU is a DL MU PPDU - * \return true if the PPDU is a DL MU PPDU - */ - virtual bool IsDlMu() const; - /** - * Return true if the PPDU is an UL MU PPDU - * \return true if the PPDU is an UL MU PPDU - */ - virtual bool IsUlMu() const; - - /** - * Fill in the HE PHY headers. + * Fill in the TXVECTOR from PHY headers. * - * \param txVector the TXVECTOR that was used for this PPDU - * \param ppduDuration the transmission duration of this PPDU + * \param txVector the TXVECTOR to fill in + * \param lSig the L-SIG header + * \param heSig the HE-SIG header */ - virtual void SetPhyHeaders(const WifiTxVector& txVector, Time ppduDuration); + virtual void SetTxVectorFromPhyHeaders(WifiTxVector& txVector, + const LSigHeader& lSig, + const HeSigHeader& heSig) const; +#ifndef NS3_BUILD_PROFILE_DEBUG + HeSigHeader m_heSig; //!< the HE-SIG PHY header +#endif mutable TxPsdFlag m_txPsdFlag; //!< the transmit power spectral density flag WifiTxVector::HeMuUserInfoMap m_muUserInfos; //!< HE MU specific per-user information (to be @@ -276,7 +263,53 @@ class HePpdu : public OfdmPpdu //!< headers are implemented) RuAllocation m_ruAllocation; //!< RU_ALLOCATION in SIG-B common field (to be removed once //!< HE-SIG-B headers are implemented) -}; // class HePpdu + + private: + std::string PrintPayload() const override; + WifiTxVector DoGetTxVector() const override; + + /** + * Return true if the PPDU is a MU PPDU + * \return true if the PPDU is a MU PPDU + */ + virtual bool IsMu() const; + + /** + * Return true if the PPDU is a DL MU PPDU + * \return true if the PPDU is a DL MU PPDU + */ + virtual bool IsDlMu() const; + + /** + * Return true if the PPDU is an UL MU PPDU + * \return true if the PPDU is an UL MU PPDU + */ + virtual bool IsUlMu() const; + + /** + * Fill in the PHY headers. + * + * \param txVector the TXVECTOR that was used for this PPDU + * \param ppduDuration the transmission duration of this PPDU + */ + virtual void SetPhyHeaders(const WifiTxVector& txVector, Time ppduDuration); + + /** + * Fill in the L-SIG header. + * + * \param lSig the L-SIG header to fill in + * \param ppduDuration the transmission duration of this PPDU + */ + virtual void SetLSigHeader(LSigHeader& lSig, Time ppduDuration) const; + + /** + * Fill in the HE-SIG header. + * + * \param heSig the HE-SIG header to fill in + * \param txVector the TXVECTOR that was used for this PPDU + */ + void SetHeSigHeader(HeSigHeader& heSig, const WifiTxVector& txVector) const; +}; // class HePpdu /** * \brief Stream insertion operator. diff --git a/src/wifi/model/ht/ht-ppdu.cc b/src/wifi/model/ht/ht-ppdu.cc index bbcd18920..eb859c250 100644 --- a/src/wifi/model/ht/ht-ppdu.cc +++ b/src/wifi/model/ht/ht-ppdu.cc @@ -54,7 +54,25 @@ void HtPpdu::SetPhyHeaders(const WifiTxVector& txVector, Time ppduDuration, std::size_t psduSize) { NS_LOG_FUNCTION(this << txVector << ppduDuration << psduSize); + +#ifdef NS3_BUILD_PROFILE_DEBUG LSigHeader lSig; + SetLSigHeader(lSig, ppduDuration); + + HtSigHeader htSig; + SetHtSigHeader(htSig, txVector, psduSize); + + m_phyHeaders->AddHeader(htSig); + m_phyHeaders->AddHeader(lSig); +#else + SetLSigHeader(m_lSig, ppduDuration); + SetHtSigHeader(m_htSig, txVector, psduSize); +#endif +} + +void +HtPpdu::SetLSigHeader(LSigHeader& lSig, Time ppduDuration) const +{ uint8_t sigExtension = 0; if (m_band == WIFI_PHY_BAND_2_4GHZ) { @@ -67,21 +85,25 @@ HtPpdu::SetPhyHeaders(const WifiTxVector& txVector, Time ppduDuration, std::size 3) - 3); lSig.SetLength(length); +} - HtSigHeader htSig; +void +HtPpdu::SetHtSigHeader(HtSigHeader& htSig, const WifiTxVector& txVector, std::size_t psduSize) const +{ htSig.SetMcs(txVector.GetMode().GetMcsValue()); htSig.SetChannelWidth(m_channelWidth); htSig.SetHtLength(psduSize); htSig.SetAggregation(txVector.IsAggregation()); htSig.SetShortGuardInterval(txVector.GetGuardInterval() == 400); - - m_phyHeaders->AddHeader(htSig); - m_phyHeaders->AddHeader(lSig); } WifiTxVector HtPpdu::DoGetTxVector() const { + WifiTxVector txVector; + txVector.SetPreambleType(m_preamble); + +#ifdef NS3_BUILD_PROFILE_DEBUG auto phyHeaders = m_phyHeaders->Copy(); LSigHeader lSig; @@ -96,14 +118,24 @@ HtPpdu::DoGetTxVector() const NS_FATAL_ERROR("Missing HT-SIG header in HT PPDU"); } - WifiTxVector txVector; - txVector.SetPreambleType(m_preamble); + SetTxVectorFromPhyHeaders(txVector, lSig, htSig); +#else + SetTxVectorFromPhyHeaders(txVector, m_lSig, m_htSig); +#endif + + return txVector; +} + +void +HtPpdu::SetTxVectorFromPhyHeaders(WifiTxVector& txVector, + const LSigHeader& lSig, + const HtSigHeader& htSig) const +{ txVector.SetMode(HtPhy::GetHtMcs(htSig.GetMcs())); txVector.SetChannelWidth(htSig.GetChannelWidth()); txVector.SetNss(1 + (htSig.GetMcs() / 8)); txVector.SetGuardInterval(htSig.GetShortGuardInterval() ? 400 : 800); txVector.SetAggregation(htSig.GetAggregation()); - return txVector; } Time @@ -111,6 +143,9 @@ HtPpdu::GetTxDuration() const { Time ppduDuration = Seconds(0); const WifiTxVector& txVector = GetTxVector(); + + uint16_t htLength = 0; +#ifdef NS3_BUILD_PROFILE_DEBUG auto phyHeaders = m_phyHeaders->Copy(); LSigHeader lSig; @@ -118,7 +153,12 @@ HtPpdu::GetTxDuration() const HtSigHeader htSig; phyHeaders->RemoveHeader(htSig); - ppduDuration = WifiPhy::CalculateTxDuration(htSig.GetHtLength(), txVector, m_band); + htLength = htSig.GetHtLength(); +#else + htLength = m_htSig.GetHtLength(); +#endif + + ppduDuration = WifiPhy::CalculateTxDuration(htLength, txVector, m_band); return ppduDuration; } diff --git a/src/wifi/model/ht/ht-ppdu.h b/src/wifi/model/ht/ht-ppdu.h index b2151e0e3..65dc77f0f 100644 --- a/src/wifi/model/ht/ht-ppdu.h +++ b/src/wifi/model/ht/ht-ppdu.h @@ -165,6 +165,40 @@ class HtPpdu : public OfdmPpdu * \param psduSize the size duration of the PHY payload (PSDU) */ void SetPhyHeaders(const WifiTxVector& txVector, Time ppduDuration, std::size_t psduSize); + + /** + * Fill in the L-SIG header. + * + * \param lSig the L-SIG header to fill in + * \param ppduDuration the transmission duration of this PPDU + */ + virtual void SetLSigHeader(LSigHeader& lSig, Time ppduDuration) const; + + /** + * Fill in the HT-SIG header. + * + * \param htSig the HT-SIG header to fill in + * \param txVector the TXVECTOR that was used for this PPDU + * \param psduSize the size duration of the PHY payload (PSDU) + */ + void SetHtSigHeader(HtSigHeader& htSig, + const WifiTxVector& txVector, + std::size_t psduSize) const; + + /** + * Fill in the TXVECTOR from PHY headers. + * + * \param txVector the TXVECTOR to fill in + * \param lSig the L-SIG header + * \param htSig the HT-SIG header + */ + void SetTxVectorFromPhyHeaders(WifiTxVector& txVector, + const LSigHeader& lSig, + const HtSigHeader& htSig) const; + +#ifndef NS3_BUILD_PROFILE_DEBUG + HtSigHeader m_htSig; //!< the HT-SIG PHY header +#endif }; // class HtPpdu } // namespace ns3 diff --git a/src/wifi/model/non-ht/dsss-ppdu.cc b/src/wifi/model/non-ht/dsss-ppdu.cc index a33987958..1d7c97c7b 100644 --- a/src/wifi/model/non-ht/dsss-ppdu.cc +++ b/src/wifi/model/non-ht/dsss-ppdu.cc @@ -46,39 +46,69 @@ DsssPpdu::DsssPpdu(Ptr psdu, void DsssPpdu::SetPhyHeaders(const WifiTxVector& txVector, Time ppduDuration) { - NS_LOG_FUNCTION(this << txVector << ppduDuration); + NS_LOG_FUNCTION(this << txVector); + +#ifdef NS3_BUILD_PROFILE_DEBUG DsssSigHeader dsssSig; + SetDsssHeader(dsssSig, txVector, ppduDuration); + m_phyHeaders->AddHeader(dsssSig); +#else + SetDsssHeader(m_dsssSig, txVector, ppduDuration); +#endif +} + +void +DsssPpdu::SetDsssHeader(DsssSigHeader& dsssSig, + const WifiTxVector& txVector, + Time ppduDuration) const +{ dsssSig.SetRate(txVector.GetMode().GetDataRate(22)); Time psduDuration = ppduDuration - WifiPhy::CalculatePhyPreambleAndHeaderDuration(txVector); dsssSig.SetLength(psduDuration.GetMicroSeconds()); - m_phyHeaders->AddHeader(dsssSig); } WifiTxVector DsssPpdu::DoGetTxVector() const { + WifiTxVector txVector; + txVector.SetPreambleType(m_preamble); + txVector.SetChannelWidth(22); + +#ifdef NS3_BUILD_PROFILE_DEBUG DsssSigHeader dsssSig; if (m_phyHeaders->PeekHeader(dsssSig) == 0) { NS_FATAL_ERROR("Missing DSSS SIG PHY header in DSSS PPDU"); } - WifiTxVector txVector; - txVector.SetPreambleType(m_preamble); - txVector.SetMode(DsssPhy::GetDsssRate(dsssSig.GetRate())); - txVector.SetChannelWidth(22); + SetTxVectorFromDsssHeader(txVector, dsssSig); +#else + SetTxVectorFromDsssHeader(txVector, m_dsssSig); +#endif + return txVector; } +void +DsssPpdu::SetTxVectorFromDsssHeader(WifiTxVector& txVector, const DsssSigHeader& dsssSig) const +{ + txVector.SetMode(DsssPhy::GetDsssRate(dsssSig.GetRate())); +} + Time DsssPpdu::GetTxDuration() const { Time ppduDuration = Seconds(0); const WifiTxVector& txVector = GetTxVector(); + uint16_t length = 0; +#ifdef NS3_BUILD_PROFILE_DEBUG DsssSigHeader dsssSig; m_phyHeaders->PeekHeader(dsssSig); - ppduDuration = MicroSeconds(dsssSig.GetLength()) + - WifiPhy::CalculatePhyPreambleAndHeaderDuration(txVector); + length = dsssSig.GetLength(); +#else + length = m_dsssSig.GetLength(); +#endif + ppduDuration = MicroSeconds(length) + WifiPhy::CalculatePhyPreambleAndHeaderDuration(txVector); return ppduDuration; } diff --git a/src/wifi/model/non-ht/dsss-ppdu.h b/src/wifi/model/non-ht/dsss-ppdu.h index 8b1b98d32..75e587cde 100644 --- a/src/wifi/model/non-ht/dsss-ppdu.h +++ b/src/wifi/model/non-ht/dsss-ppdu.h @@ -124,6 +124,30 @@ class DsssPpdu : public WifiPpdu * \param ppduDuration the transmission duration of this PPDU */ void SetPhyHeaders(const WifiTxVector& txVector, Time ppduDuration); + + /** + * Fill in the DSSS header. + * + * \param dsssSig the DSSS header to fill in + * \param txVector the TXVECTOR that was used for this PPDU + * \param ppduDuration the transmission duration of this PPDU + */ + void SetDsssHeader(DsssSigHeader& dsssSig, + const WifiTxVector& txVector, + Time ppduDuration) const; + + /** + * Fill in the TXVECTOR from DSSS header. + * + * \param txVector the TXVECTOR to fill in + * \param dsssSig the DSSS header + */ + virtual void SetTxVectorFromDsssHeader(WifiTxVector& txVector, + const DsssSigHeader& dsssSig) const; + +#ifndef NS3_BUILD_PROFILE_DEBUG + DsssSigHeader m_dsssSig; //!< the DSSS SIG PHY header +#endif }; // class DsssPpdu } // namespace ns3 diff --git a/src/wifi/model/non-ht/erp-ofdm-ppdu.cc b/src/wifi/model/non-ht/erp-ofdm-ppdu.cc index 188441865..289981bb6 100644 --- a/src/wifi/model/non-ht/erp-ofdm-ppdu.cc +++ b/src/wifi/model/non-ht/erp-ofdm-ppdu.cc @@ -40,21 +40,12 @@ ErpOfdmPpdu::ErpOfdmPpdu(Ptr psdu, NS_LOG_FUNCTION(this << psdu << txVector << txCenterFreq << band << uid); } -WifiTxVector -ErpOfdmPpdu::DoGetTxVector() const +void +ErpOfdmPpdu::SetTxVectorFromLSigHeader(WifiTxVector& txVector, const LSigHeader& lSig) const { - LSigHeader lSig; - if (m_phyHeaders->PeekHeader(lSig) == 0) - { - NS_FATAL_ERROR("Missing L-SIG in PPDU"); - } - - WifiTxVector txVector; - txVector.SetPreambleType(m_preamble); NS_ASSERT(m_channelWidth == 20); txVector.SetMode(ErpOfdmPhy::GetErpOfdmRate(lSig.GetRate())); txVector.SetChannelWidth(m_channelWidth); - return txVector; } Ptr diff --git a/src/wifi/model/non-ht/erp-ofdm-ppdu.h b/src/wifi/model/non-ht/erp-ofdm-ppdu.h index fda38a8af..8f54c224b 100644 --- a/src/wifi/model/non-ht/erp-ofdm-ppdu.h +++ b/src/wifi/model/non-ht/erp-ofdm-ppdu.h @@ -62,7 +62,7 @@ class ErpOfdmPpdu : public OfdmPpdu Ptr Copy() const override; private: - WifiTxVector DoGetTxVector() const override; + void SetTxVectorFromLSigHeader(WifiTxVector& txVector, const LSigHeader& lSig) const override; }; // class ErpOfdmPpdu } // namespace ns3 diff --git a/src/wifi/model/non-ht/ofdm-ppdu.cc b/src/wifi/model/non-ht/ofdm-ppdu.cc index a382ee738..ebcb42ebe 100644 --- a/src/wifi/model/non-ht/ofdm-ppdu.cc +++ b/src/wifi/model/non-ht/ofdm-ppdu.cc @@ -53,39 +53,66 @@ void OfdmPpdu::SetPhyHeaders(const WifiTxVector& txVector, std::size_t psduSize) { NS_LOG_FUNCTION(this << txVector << psduSize); + +#ifdef NS3_BUILD_PROFILE_DEBUG LSigHeader lSig; + SetLSigHeader(lSig, txVector, psduSize); + m_phyHeaders->AddHeader(lSig); +#else + SetLSigHeader(m_lSig, txVector, psduSize); +#endif +} + +void +OfdmPpdu::SetLSigHeader(LSigHeader& lSig, const WifiTxVector& txVector, std::size_t psduSize) const +{ lSig.SetRate(txVector.GetMode().GetDataRate(txVector), m_channelWidth); lSig.SetLength(psduSize); - m_phyHeaders->AddHeader(lSig); } WifiTxVector OfdmPpdu::DoGetTxVector() const { + WifiTxVector txVector; + txVector.SetPreambleType(m_preamble); + +#ifdef NS3_BUILD_PROFILE_DEBUG LSigHeader lSig; if (m_phyHeaders->PeekHeader(lSig) == 0) { NS_FATAL_ERROR("Missing L-SIG in PPDU"); } - WifiTxVector txVector; - txVector.SetPreambleType(m_preamble); + SetTxVectorFromLSigHeader(txVector, lSig); +#else + SetTxVectorFromLSigHeader(txVector, m_lSig); +#endif + + return txVector; +} + +void +OfdmPpdu::SetTxVectorFromLSigHeader(WifiTxVector& txVector, const LSigHeader& lSig) const +{ // OFDM uses 20 MHz, unless PHY channel width is 5 MHz or 10 MHz uint16_t channelWidth = m_channelWidth < 20 ? m_channelWidth : 20; txVector.SetMode(OfdmPhy::GetOfdmRate(lSig.GetRate(m_channelWidth), channelWidth)); txVector.SetChannelWidth(channelWidth); - return txVector; } Time OfdmPpdu::GetTxDuration() const { - Time ppduDuration = Seconds(0); const WifiTxVector& txVector = GetTxVector(); + uint16_t length = 0; +#ifdef NS3_BUILD_PROFILE_DEBUG LSigHeader lSig; m_phyHeaders->PeekHeader(lSig); - ppduDuration = WifiPhy::CalculateTxDuration(lSig.GetLength(), txVector, m_band); - return ppduDuration; + length = lSig.GetLength(); +#else + length = m_lSig.GetLength(); +#endif + return WifiPhy::CalculateTxDuration(length, txVector, m_band); } Ptr diff --git a/src/wifi/model/non-ht/ofdm-ppdu.h b/src/wifi/model/non-ht/ofdm-ppdu.h index 932d5cd39..f7289bf7a 100644 --- a/src/wifi/model/non-ht/ofdm-ppdu.h +++ b/src/wifi/model/non-ht/ofdm-ppdu.h @@ -124,6 +124,9 @@ class OfdmPpdu : public WifiPpdu protected: WifiPhyBand m_band; //!< the WifiPhyBand used to transmit that PPDU uint16_t m_channelWidth; //!< the channel width used to transmit that PPDU in MHz +#ifndef NS3_BUILD_PROFILE_DEBUG + LSigHeader m_lSig; //!< the L-SIG PHY header +#endif private: WifiTxVector DoGetTxVector() const override; @@ -135,6 +138,23 @@ class OfdmPpdu : public WifiPpdu * \param psduSize the size duration of the PHY payload (PSDU) */ void SetPhyHeaders(const WifiTxVector& txVector, std::size_t psduSize); + + /** + * Fill in the L-SIG header. + * + * \param lSig the L-SIG header to fill in + * \param txVector the TXVECTOR that was used for this PPDU + * \param psduSize the size duration of the PHY payload (PSDU) + */ + void SetLSigHeader(LSigHeader& lSig, const WifiTxVector& txVector, std::size_t psduSize) const; + + /** + * Fill in the TXVECTOR from L-SIG header. + * + * \param txVector the TXVECTOR to fill in + * \param lSig the L-SIG header + */ + virtual void SetTxVectorFromLSigHeader(WifiTxVector& txVector, const LSigHeader& lSig) const; }; // class OfdmPpdu } // namespace ns3 diff --git a/src/wifi/model/vht/vht-ppdu.cc b/src/wifi/model/vht/vht-ppdu.cc index f61cd45f3..e926ff73f 100644 --- a/src/wifi/model/vht/vht-ppdu.cc +++ b/src/wifi/model/vht/vht-ppdu.cc @@ -53,14 +53,37 @@ void VhtPpdu::SetPhyHeaders(const WifiTxVector& txVector, Time ppduDuration) { NS_LOG_FUNCTION(this << txVector << ppduDuration); + +#ifdef NS3_BUILD_PROFILE_DEBUG LSigHeader lSig; + SetLSigHeader(lSig, ppduDuration); + + VhtSigHeader vhtSig; + SetVhtSigHeader(vhtSig, txVector, ppduDuration); + + m_phyHeaders->AddHeader(vhtSig); + m_phyHeaders->AddHeader(lSig); +#else + SetLSigHeader(m_lSig, ppduDuration); + SetVhtSigHeader(m_vhtSig, txVector, ppduDuration); +#endif +} + +void +VhtPpdu::SetLSigHeader(LSigHeader& lSig, Time ppduDuration) const +{ uint16_t length = ((ceil((static_cast(ppduDuration.GetNanoSeconds() - (20 * 1000)) / 1000) / 4.0) * 3) - 3); lSig.SetLength(length); +} - VhtSigHeader vhtSig; +void +VhtPpdu::SetVhtSigHeader(VhtSigHeader& vhtSig, + const WifiTxVector& txVector, + Time ppduDuration) const +{ vhtSig.SetMuFlag(m_preamble == WIFI_PREAMBLE_VHT_MU); vhtSig.SetChannelWidth(m_channelWidth); vhtSig.SetShortGuardInterval(txVector.GetGuardInterval() == 400); @@ -75,14 +98,15 @@ VhtPpdu::SetPhyHeaders(const WifiTxVector& txVector, Time ppduDuration) } vhtSig.SetSuMcs(txVector.GetMode().GetMcsValue()); vhtSig.SetNStreams(txVector.GetNss()); - - m_phyHeaders->AddHeader(vhtSig); - m_phyHeaders->AddHeader(lSig); } WifiTxVector VhtPpdu::DoGetTxVector() const { + WifiTxVector txVector; + txVector.SetPreambleType(m_preamble); + +#ifdef NS3_BUILD_PROFILE_DEBUG auto phyHeaders = m_phyHeaders->Copy(); LSigHeader lSig; @@ -97,14 +121,24 @@ VhtPpdu::DoGetTxVector() const NS_FATAL_ERROR("Missing VHT-SIG header in VHT PPDU"); } - WifiTxVector txVector; - txVector.SetPreambleType(m_preamble); + SetTxVectorFromPhyHeaders(txVector, lSig, vhtSig); +#else + SetTxVectorFromPhyHeaders(txVector, m_lSig, m_vhtSig); +#endif + + return txVector; +} + +void +VhtPpdu::SetTxVectorFromPhyHeaders(WifiTxVector& txVector, + const LSigHeader& lSig, + const VhtSigHeader& vhtSig) const +{ txVector.SetMode(VhtPhy::GetVhtMcs(vhtSig.GetSuMcs())); txVector.SetChannelWidth(vhtSig.GetChannelWidth()); txVector.SetNss(vhtSig.GetNStreams()); txVector.SetGuardInterval(vhtSig.GetShortGuardInterval() ? 400 : 800); txVector.SetAggregation(GetPsdu()->IsAggregate()); - return txVector; } Time @@ -112,6 +146,11 @@ VhtPpdu::GetTxDuration() const { Time ppduDuration = Seconds(0); const WifiTxVector& txVector = GetTxVector(); + + uint16_t length = 0; + bool sgi = false; + bool sgiDisambiguation = false; +#ifdef NS3_BUILD_PROFILE_DEBUG auto phyHeaders = m_phyHeaders->Copy(); LSigHeader lSig; @@ -119,14 +158,22 @@ VhtPpdu::GetTxDuration() const VhtSigHeader vhtSig; phyHeaders->RemoveHeader(vhtSig); + length = lSig.GetLength(); + sgi = vhtSig.GetShortGuardInterval(); + sgiDisambiguation = vhtSig.GetShortGuardIntervalDisambiguation(); +#else + length = m_lSig.GetLength(); + sgi = m_vhtSig.GetShortGuardInterval(); + sgiDisambiguation = m_vhtSig.GetShortGuardIntervalDisambiguation(); +#endif + Time tSymbol = NanoSeconds(3200 + txVector.GetGuardInterval()); Time preambleDuration = WifiPhy::CalculatePhyPreambleAndHeaderDuration(txVector); - Time calculatedDuration = - MicroSeconds(((ceil(static_cast(lSig.GetLength() + 3) / 3)) * 4) + 20); + Time calculatedDuration = MicroSeconds(((ceil(static_cast(length + 3) / 3)) * 4) + 20); uint32_t nSymbols = floor(static_cast((calculatedDuration - preambleDuration).GetNanoSeconds()) / tSymbol.GetNanoSeconds()); - if (vhtSig.GetShortGuardInterval() && vhtSig.GetShortGuardIntervalDisambiguation()) + if (sgi && sgiDisambiguation) { nSymbols--; } diff --git a/src/wifi/model/vht/vht-ppdu.h b/src/wifi/model/vht/vht-ppdu.h index 84a35ed45..b1735dba2 100644 --- a/src/wifi/model/vht/vht-ppdu.h +++ b/src/wifi/model/vht/vht-ppdu.h @@ -178,8 +178,42 @@ class VhtPpdu : public OfdmPpdu * \param txVector the TXVECTOR that was used for this PPDU * \param ppduDuration the transmission duration of this PPDU */ - void SetPhyHeaders(const WifiTxVector& txVector, Time ppduDuration); -}; // class VhtPpdu + virtual void SetPhyHeaders(const WifiTxVector& txVector, Time ppduDuration); + + /** + * Fill in the L-SIG header. + * + * \param lSig the L-SIG header to fill in + * \param ppduDuration the transmission duration of this PPDU + */ + virtual void SetLSigHeader(LSigHeader& lSig, Time ppduDuration) const; + + /** + * Fill in the VHT-SIG header. + * + * \param vhtSig the VHT-SIG header to fill in + * \param txVector the TXVECTOR that was used for this PPDU + * \param ppduDuration the transmission duration of this PPDU + */ + void SetVhtSigHeader(VhtSigHeader& vhtSig, + const WifiTxVector& txVector, + Time ppduDuration) const; + + /** + * Fill in the TXVECTOR from PHY headers. + * + * \param txVector the TXVECTOR to fill in + * \param lSig the L-SIG header + * \param vhtSig the VHT-SIG header + */ + void SetTxVectorFromPhyHeaders(WifiTxVector& txVector, + const LSigHeader& lSig, + const VhtSigHeader& vhtSig) const; + +#ifndef NS3_BUILD_PROFILE_DEBUG + VhtSigHeader m_vhtSig; //!< the VHT-SIG PHY header +#endif +}; // class VhtPpdu } // namespace ns3 diff --git a/src/wifi/model/wifi-ppdu.cc b/src/wifi/model/wifi-ppdu.cc index ab0b6a45b..65dafb1be 100644 --- a/src/wifi/model/wifi-ppdu.cc +++ b/src/wifi/model/wifi-ppdu.cc @@ -37,7 +37,9 @@ WifiPpdu::WifiPpdu(Ptr psdu, m_modulation(txVector.IsValid() ? txVector.GetModulationClass() : WIFI_MOD_CLASS_UNKNOWN), m_txCenterFreq(txCenterFreq), m_uid(uid), +#ifdef NS3_BUILD_PROFILE_DEBUG m_phyHeaders(Create()), +#endif m_truncatedTx(false), m_txPowerLevel(txVector.GetTxPowerLevel()), m_txVector(txVector) @@ -55,7 +57,9 @@ WifiPpdu::WifiPpdu(const WifiConstPsduMap& psdus, : WIFI_MOD_CLASS_UNKNOWN), m_txCenterFreq(txCenterFreq), m_uid(uid), +#ifdef NS3_BUILD_PROFILE_DEBUG m_phyHeaders(Create()), +#endif m_truncatedTx(false), m_txPowerLevel(txVector.GetTxPowerLevel()), m_txAntennas(txVector.GetNTx()), diff --git a/src/wifi/model/wifi-ppdu.h b/src/wifi/model/wifi-ppdu.h index 7172ca13b..5d51b4b3a 100644 --- a/src/wifi/model/wifi-ppdu.h +++ b/src/wifi/model/wifi-ppdu.h @@ -201,7 +201,9 @@ class WifiPpdu : public SimpleRefCount uint16_t m_txCenterFreq; //!< the center frequency (MHz) used for the transmission of this PPDU uint64_t m_uid; //!< the unique ID of this PPDU +#ifdef NS3_BUILD_PROFILE_DEBUG Ptr m_phyHeaders; //!< the PHY headers contained in this PPDU +#endif private: /**