diff --git a/src/wifi/model/interference-helper.h b/src/wifi/model/interference-helper.h index dfefe49ea..cf289cccc 100644 --- a/src/wifi/model/interference-helper.h +++ b/src/wifi/model/interference-helper.h @@ -352,6 +352,10 @@ class InterferenceHelper : public Object const WifiTxVector& txVector, uint16_t staId = SU_STA_ID) const; + protected: + std::map + m_rxing; //!< flag whether it is in receiving state for a given FrequencyRange + private: /** * Noise and Interference (thus Ni) event. @@ -518,8 +522,6 @@ class InterferenceHelper : public Object uint8_t m_numRxAntennas; //!< the number of RX antennas in the corresponding receiver NiChangesPerBand m_niChanges; //!< NI Changes for each band FirstPowerPerBand m_firstPowers; //!< first power of each band in watts - std::map - m_rxing; //!< flag whether it is in receiving state for a given FrequencyRange /** * Returns an iterator to the first NiChange that is later than moment diff --git a/src/wifi/test/spectrum-wifi-phy-test.cc b/src/wifi/test/spectrum-wifi-phy-test.cc index 7e226305e..e07d29561 100644 --- a/src/wifi/test/spectrum-wifi-phy-test.cc +++ b/src/wifi/test/spectrum-wifi-phy-test.cc @@ -60,6 +60,40 @@ class ExtSpectrumWifiPhy : public SpectrumWifiPhy using WifiPhy::GetBand; }; +/** + * Extended InterferenceHelper class for the purpose of the tests. + */ +class ExtInterferenceHelper : public InterferenceHelper +{ + public: + /** + * \brief Get the type ID. + * \return the object TypeId + */ + static TypeId GetTypeId() + { + static TypeId tid = TypeId("ns3::ExtInterferenceHelper") + .SetParent() + .SetGroupName("Wifi") + .AddConstructor(); + return tid; + } + + /** + * Indicate whether the interference helper is in receiving state + * + * \return true if the interference helper is in receiving state, false otherwise + */ + bool IsRxing() const + { + return std::any_of(m_rxing.cbegin(), m_rxing.cend(), [](const auto& rxing) { + return rxing.second; + }); + } +}; + +NS_OBJECT_ENSURE_REGISTERED(ExtInterferenceHelper); + /** * \ingroup wifi-test * \ingroup tests @@ -909,6 +943,15 @@ class SpectrumWifiPhyMultipleInterfacesTest : public TestCase */ void CheckCcaIndication(std::size_t index, bool expectedCcaBusyIndication, Time switchingDelay); + /** + * Verify rxing state of the interference helper + * + * \param phy the PHY to which the interference helper instance is attached + * \param rxingExpected flag whether the interference helper is expected to be in rxing state or + * not + */ + void CheckRxingState(Ptr phy, bool rxingExpected); + /** * Reset function */ @@ -957,6 +1000,11 @@ SpectrumWifiPhyMultipleInterfacesTest::SwitchChannel(Ptr phy, listener->m_ccaBusyEnd = Seconds(0); } phy->SetOperatingChannel(WifiPhy::ChannelTuple{channelNumber, channelWidth, band, 0}); + // verify rxing state of interference helper is reset after channel switch + Simulator::ScheduleNow(&SpectrumWifiPhyMultipleInterfacesTest::CheckRxingState, + this, + phy, + false); } void @@ -1117,6 +1165,17 @@ SpectrumWifiPhyMultipleInterfacesTest::CheckCcaIndication(std::size_t index, NS_TEST_ASSERT_MSG_EQ(ccaBusyEnd, expectedCcaBusyEnd, "CCA busy end mismatch"); } +void +SpectrumWifiPhyMultipleInterfacesTest::CheckRxingState(Ptr phy, bool rxingExpected) +{ + NS_LOG_FUNCTION(this << phy << rxingExpected); + PointerValue ptr; + phy->GetAttribute("InterferenceHelper", ptr); + auto interferenceHelper = DynamicCast(ptr.Get()); + NS_ASSERT(interferenceHelper); + NS_TEST_ASSERT_MSG_EQ(interferenceHelper->IsRxing(), rxingExpected, "Incorrect rxing state"); +} + void SpectrumWifiPhyMultipleInterfacesTest::Reset() { @@ -1169,6 +1228,7 @@ SpectrumWifiPhyMultipleInterfacesTest::DoSetup() wifi.SetStandard(WIFI_STANDARD_80211be); SpectrumWifiPhyHelper phyHelper(4); + phyHelper.SetInterferenceHelper("ns3::ExtInterferenceHelper"); phyHelper.SetPcapDataLinkType(WifiPhyHelper::DLT_IEEE802_11_RADIO); struct SpectrumPhyInterfaceInfo