From 83dcacadc512edfbba5a83b37530a2909a0b2989 Mon Sep 17 00:00:00 2001 From: Tommaso Pecorella Date: Wed, 28 Sep 2022 23:53:19 +0200 Subject: [PATCH] wifi: mobility initialization and caching in WifiPhy --- src/wifi/model/wifi-phy.cc | 34 ++++++++++++++++++++++++++-------- src/wifi/model/wifi-phy.h | 1 + 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/wifi/model/wifi-phy.cc b/src/wifi/model/wifi-phy.cc index fc5b45aa6..9e1a89ea7 100644 --- a/src/wifi/model/wifi-phy.cc +++ b/src/wifi/model/wifi-phy.cc @@ -363,6 +363,31 @@ WifiPhy::~WifiPhy() NS_LOG_FUNCTION(this); } +void +WifiPhy::DoInitialize() +{ + NS_LOG_FUNCTION(this); + + // This method ensures that the local mobility model pointer holds + // a pointer to the Node's aggregated mobility model (if one exists) + // in the case that the user has not directly called SetMobility() + // on this WifiPhy during simulation setup. If the mobility model + // needs to be added or changed during simulation runtime, users must + // call SetMobility() on this object. + + if (!m_mobility) + { + NS_ABORT_MSG_UNLESS(m_device && m_device->GetNode(), + "Either install a MobilityModel on this object or ensure that this " + "object is part of a Node and NetDevice"); + m_mobility = m_device->GetNode()->GetObject(); + if (!m_mobility) + { + NS_LOG_WARN("Mobility not found, propagation models might not work properly"); + } + } +} + void WifiPhy::DoDispose() { @@ -592,14 +617,7 @@ WifiPhy::SetMobility(const Ptr mobility) Ptr WifiPhy::GetMobility() const { - if (m_mobility) - { - return m_mobility; - } - else - { - return m_device->GetNode()->GetObject(); - } + return m_mobility; } void diff --git a/src/wifi/model/wifi-phy.h b/src/wifi/model/wifi-phy.h index 7836b6e5e..009e2aa7e 100644 --- a/src/wifi/model/wifi-phy.h +++ b/src/wifi/model/wifi-phy.h @@ -1132,6 +1132,7 @@ class WifiPhy : public Object virtual WifiSpectrumBand GetBand(uint16_t bandWidth, uint8_t bandIndex = 0); protected: + void DoInitialize() override; void DoDispose() override; /**