diff --git a/src/lr-wpan/model/lr-wpan-net-device.cc b/src/lr-wpan/model/lr-wpan-net-device.cc index d8681801a..6b75bcc18 100644 --- a/src/lr-wpan/model/lr-wpan-net-device.cc +++ b/src/lr-wpan/model/lr-wpan-net-device.cc @@ -30,7 +30,6 @@ #include #include #include -#include #include @@ -133,12 +132,6 @@ LrWpanNetDevice::CompleteConfig (void) m_mac->SetMcpsDataIndicationCallback (MakeCallback (&LrWpanNetDevice::McpsDataIndication, this)); m_csmaca->SetMac (m_mac); - Ptr mobility = m_node->GetObject (); - if (!mobility) - { - NS_LOG_WARN ("LrWpanNetDevice: no Mobility found on the node, probably it's not a good idea."); - } - m_phy->SetMobility (mobility); Ptr model = CreateObject (); m_phy->SetErrorModel (model); m_phy->SetDevice (this); diff --git a/src/lr-wpan/model/lr-wpan-phy.cc b/src/lr-wpan/model/lr-wpan-phy.cc index c23144a32..530b9dbb1 100644 --- a/src/lr-wpan/model/lr-wpan-phy.cc +++ b/src/lr-wpan/model/lr-wpan-phy.cc @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -150,6 +151,29 @@ LrWpanPhy::LrWpanPhy (void) LrWpanPhy::~LrWpanPhy (void) {} +void +LrWpanPhy::DoInitialize (void) +{ + 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 LrWpanPhy 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 LrWpanPhy::DoDispose (void) { diff --git a/src/lr-wpan/model/lr-wpan-phy.h b/src/lr-wpan/model/lr-wpan-phy.h index 1961e25a0..fc86a8408 100644 --- a/src/lr-wpan/model/lr-wpan-phy.h +++ b/src/lr-wpan/model/lr-wpan-phy.h @@ -547,6 +547,7 @@ private: typedef std::pair, bool> PacketAndStatus; // Inherited from Object. + virtual void DoInitialize (void); virtual void DoDispose (void); /**