diff --git a/src/wifi/model/spectrum-wifi-phy.cc b/src/wifi/model/spectrum-wifi-phy.cc index f1eb5a06b..6bffabc88 100644 --- a/src/wifi/model/spectrum-wifi-phy.cc +++ b/src/wifi/model/spectrum-wifi-phy.cc @@ -345,6 +345,17 @@ SpectrumWifiPhy::DoChannelSwitch() { SwitchMaybeToCcaBusy(nullptr); } + + Simulator::ScheduleNow(&SpectrumWifiPhy::NotifyChannelSwitched, this); +} + +void +SpectrumWifiPhy::NotifyChannelSwitched() +{ + if (!m_channelSwitchedCallback.IsNull()) + { + m_channelSwitchedCallback(); + } } void @@ -693,4 +704,10 @@ SpectrumWifiPhy::GetCurrentInterface() const return m_currentSpectrumPhyInterface; } +void +SpectrumWifiPhy::SetChannelSwitchedCallback(Callback callback) +{ + m_channelSwitchedCallback = callback; +} + } // namespace ns3 diff --git a/src/wifi/model/spectrum-wifi-phy.h b/src/wifi/model/spectrum-wifi-phy.h index cc17f6f2a..f29505bb7 100644 --- a/src/wifi/model/spectrum-wifi-phy.h +++ b/src/wifi/model/spectrum-wifi-phy.h @@ -176,6 +176,11 @@ class SpectrumWifiPhy : public WifiPhy */ const std::map>& GetSpectrumPhyInterfaces() const; + /** + * \param callback the callback to invoke when operating channel has switched. + */ + void SetChannelSwitchedCallback(Callback callback); + protected: void DoDispose() override; void DoInitialize() override; @@ -270,6 +275,11 @@ class SpectrumWifiPhy : public WifiPhy Ptr GetInterfaceCoveringChannelBand(uint16_t frequency, uint16_t width) const; + /** + * Notify the spectrum channel has switched + */ + void NotifyChannelSwitched(); + Ptr m_antenna; //!< antenna model bool m_disableWifiReception; //!< forces this PHY to fail to sync on any signal @@ -284,6 +294,8 @@ class SpectrumWifiPhy : public WifiPhy //!< of the transmit spectrum mask double m_txMaskOuterBandMaximumRejection; //!< The maximum rejection (in dBr) for the outer band //!< of the transmit spectrum mask + + Callback m_channelSwitchedCallback; //!< Callback when channel switched }; } // namespace ns3