From 6eae98fbca5fca5964cea8341a59cd9f12d5e7b8 Mon Sep 17 00:00:00 2001 From: ZorazeAli Date: Tue, 26 Feb 2019 08:12:32 +0100 Subject: [PATCH] lte: Refactor DoInitialize methods of LteEnbPhy and LteUePhy see merge request !29 --- src/lte/model/lte-enb-phy.cc | 30 +++++++++++------------------- src/lte/model/lte-ue-phy.cc | 30 +++++++++++------------------- 2 files changed, 22 insertions(+), 38 deletions(-) diff --git a/src/lte/model/lte-enb-phy.cc b/src/lte/model/lte-enb-phy.cc index c788c6106..2aa05bc48 100644 --- a/src/lte/model/lte-enb-phy.cc +++ b/src/lte/model/lte-enb-phy.cc @@ -265,25 +265,17 @@ void LteEnbPhy::DoInitialize () { NS_LOG_FUNCTION (this); - bool haveNodeId = false; - uint32_t nodeId = 0; - if (m_netDevice != 0) - { - Ptr node = m_netDevice->GetNode (); - if (node != 0) - { - nodeId = node->GetId (); - haveNodeId = true; - } - } - if (haveNodeId) - { - Simulator::ScheduleWithContext (nodeId, Seconds (0), &LteEnbPhy::StartFrame, this); - } - else - { - Simulator::ScheduleNow (&LteEnbPhy::StartFrame, this); - } + + NS_ABORT_MSG_IF (m_netDevice == nullptr, "LteEnbDevice is not available in LteEnbPhy"); + Ptr node = m_netDevice->GetNode (); + NS_ABORT_MSG_IF (node == nullptr, "Node is not available in the LteNetDevice of LteEnbPhy"); + uint32_t nodeId = node->GetId (); + + //ScheduleWithContext() is needed here to set context for logs, + //because Initialize() is called outside of Node::AddDevice(). + + Simulator::ScheduleWithContext (nodeId, Seconds (0), &LteEnbPhy::StartFrame, this); + Ptr noisePsd = LteSpectrumValueHelper::CreateNoisePowerSpectralDensity (m_ulEarfcn, m_ulBandwidth, m_noiseFigure); m_uplinkSpectrumPhy->SetNoisePowerSpectralDensity (noisePsd); LtePhy::DoInitialize (); diff --git a/src/lte/model/lte-ue-phy.cc b/src/lte/model/lte-ue-phy.cc index 858c58240..ffcccb905 100644 --- a/src/lte/model/lte-ue-phy.cc +++ b/src/lte/model/lte-ue-phy.cc @@ -311,25 +311,17 @@ void LteUePhy::DoInitialize () { NS_LOG_FUNCTION (this); - bool haveNodeId = false; - uint32_t nodeId = 0; - if (m_netDevice != 0) - { - Ptr node = m_netDevice->GetNode (); - if (node != 0) - { - nodeId = node->GetId (); - haveNodeId = true; - } - } - if (haveNodeId) - { - Simulator::ScheduleWithContext (nodeId, Seconds (0), &LteUePhy::SubframeIndication, this, 1, 1); - } - else - { - Simulator::ScheduleNow (&LteUePhy::SubframeIndication, this, 1, 1); - } + + NS_ABORT_MSG_IF (m_netDevice == nullptr, "LteNetDevice is not available in LteUePhy"); + Ptr node = m_netDevice->GetNode (); + NS_ABORT_MSG_IF (node == nullptr, "Node is not available in the LteNetDevice of LteUePhy"); + uint32_t nodeId = node->GetId (); + + //ScheduleWithContext() is needed here to set context for logs, + //because Initialize() is called outside of Node::AddDevice(). + + Simulator::ScheduleWithContext (nodeId, Seconds (0), &LteUePhy::SubframeIndication, this, 1, 1); + LtePhy::DoInitialize (); }