From 97954dc0dbed29e6ae762dfa39a103bc4a15e787 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Apitzsch?= Date: Thu, 10 Oct 2024 16:45:24 +0200 Subject: [PATCH] lte: Add operator<<() for the several enums --- src/lte/examples/lena-radio-link-failure.cc | 31 +---- src/lte/model/epc-ue-nas.cc | 45 +++---- src/lte/model/epc-ue-nas.h | 8 ++ src/lte/model/lte-enb-rrc.cc | 112 +++++++++--------- src/lte/model/lte-enb-rrc.h | 8 ++ src/lte/model/lte-ue-phy.cc | 35 +++--- src/lte/model/lte-ue-phy.h | 8 ++ src/lte/model/lte-ue-rrc.cc | 101 +++++++++------- src/lte/model/lte-ue-rrc.h | 10 ++ .../test/lte-test-secondary-cell-selection.cc | 3 +- 10 files changed, 195 insertions(+), 166 deletions(-) diff --git a/src/lte/examples/lena-radio-link-failure.cc b/src/lte/examples/lena-radio-link-failure.cc index 4d2572d72f..c560253ea8 100644 --- a/src/lte/examples/lena-radio-link-failure.cc +++ b/src/lte/examples/lena-radio-link-failure.cc @@ -100,33 +100,6 @@ NotifyConnectionEstablishedEnb(std::string context, uint64_t imsi, uint16_t cell } } -/// Map each of UE RRC states to its string representation. -static const std::string g_ueRrcStateName[LteUeRrc::NUM_STATES] = { - "IDLE_START", - "IDLE_CELL_SEARCH", - "IDLE_WAIT_MIB_SIB1", - "IDLE_WAIT_MIB", - "IDLE_WAIT_SIB1", - "IDLE_CAMPED_NORMALLY", - "IDLE_WAIT_SIB2", - "IDLE_RANDOM_ACCESS", - "IDLE_CONNECTING", - "CONNECTED_NORMALLY", - "CONNECTED_HANDOVER", - "CONNECTED_PHY_PROBLEM", - "CONNECTED_REESTABLISHING", -}; - -/** - * @param s The UE RRC state. - * @return The string representation of the given state. - */ -static const std::string& -ToString(LteUeRrc::State s) -{ - return g_ueRrcStateName[s]; -} - /** * UE state transition tracer. * @@ -144,8 +117,8 @@ UeStateTransition(uint64_t imsi, LteUeRrc::State newState) { std::cout << Simulator::Now().As(Time::S) << " UE with IMSI " << imsi << " RNTI " << rnti - << " connected to cell " << cellId << " transitions from " << ToString(oldState) - << " to " << ToString(newState) << std::endl; + << " connected to cell " << cellId << " transitions from " << oldState << " to " + << newState << std::endl; } /** diff --git a/src/lte/model/epc-ue-nas.cc b/src/lte/model/epc-ue-nas.cc index 7344be398c..1f07d44a17 100644 --- a/src/lte/model/epc-ue-nas.cc +++ b/src/lte/model/epc-ue-nas.cc @@ -20,25 +20,6 @@ namespace ns3 NS_LOG_COMPONENT_DEFINE("EpcUeNas"); -/// Map each of UE NAS states to its string representation. -static const std::string g_ueNasStateName[EpcUeNas::NUM_STATES] = { - "OFF", - "ATTACHING", - "IDLE_REGISTERED", - "CONNECTING_TO_EPC", - "ACTIVE", -}; - -/** - * @param s The UE NAS state. - * @return The string representation of the given state. - */ -static inline const std::string& -ToString(EpcUeNas::State s) -{ - return g_ueNasStateName[s]; -} - NS_OBJECT_ENSURE_REGISTERED(EpcUeNas); EpcUeNas::EpcUeNas() @@ -273,11 +254,10 @@ EpcUeNas::GetState() const void EpcUeNas::SwitchToState(State newState) { - NS_LOG_FUNCTION(this << ToString(newState)); + NS_LOG_FUNCTION(this << newState); State oldState = m_state; m_state = newState; - NS_LOG_INFO("IMSI " << m_imsi << " NAS " << ToString(oldState) << " --> " - << ToString(newState)); + NS_LOG_INFO("IMSI " << m_imsi << " NAS " << oldState << " --> " << newState); m_stateTransitionCallback(oldState, newState); // actions to be done when entering a new state: @@ -296,4 +276,25 @@ EpcUeNas::SwitchToState(State newState) } } +std::ostream& +operator<<(std::ostream& os, EpcUeNas::State state) +{ + switch (state) + { + case EpcUeNas::State::OFF: + return os << "OFF"; + case EpcUeNas::State::ATTACHING: + return os << "ATTACHING"; + case EpcUeNas::State::IDLE_REGISTERED: + return os << "IDLE_REGISTERED"; + case EpcUeNas::State::CONNECTING_TO_EPC: + return os << "CONNECTING_TO_EPC"; + case EpcUeNas::State::ACTIVE: + return os << "ACTIVE"; + case EpcUeNas::State::NUM_STATES: + return os << "NUM_STATES"; + }; + return os << "UNKNOWN(" << static_cast(state) << ")"; +} + } // namespace ns3 diff --git a/src/lte/model/epc-ue-nas.h b/src/lte/model/epc-ue-nas.h index f013f2fbb6..dc1313f902 100644 --- a/src/lte/model/epc-ue-nas.h +++ b/src/lte/model/epc-ue-nas.h @@ -243,6 +243,14 @@ class EpcUeNas : public Object std::list m_bearersToBeActivatedListForReconnection; }; +/** + * @brief Stream insertion operator. + * @param [in] os The reference to the output stream. + * @param [in] state The EpcUeNas::State. + * @return The reference to the output stream. + */ +std::ostream& operator<<(std::ostream& os, EpcUeNas::State state); + } // namespace ns3 #endif // EPC_UE_NAS_H diff --git a/src/lte/model/lte-enb-rrc.cc b/src/lte/model/lte-enb-rrc.cc index 86f4fa466f..ce62a972fa 100644 --- a/src/lte/model/lte-enb-rrc.cc +++ b/src/lte/model/lte-enb-rrc.cc @@ -102,31 +102,6 @@ EnbRrcMemberLteEnbCmacSapUser::IsRandomAccessCompleted(uint16_t rnti) // UeManager /////////////////////////////////////////// -/// Map each of UE Manager states to its string representation. -static const std::string g_ueManagerStateName[UeManager::NUM_STATES] = { - "INITIAL_RANDOM_ACCESS", - "CONNECTION_SETUP", - "CONNECTION_REJECTED", - "ATTACH_REQUEST", - "CONNECTED_NORMALLY", - "CONNECTION_RECONFIGURATION", - "CONNECTION_REESTABLISHMENT", - "HANDOVER_PREPARATION", - "HANDOVER_JOINING", - "HANDOVER_PATH_SWITCH", - "HANDOVER_LEAVING", -}; - -/** - * @param s The UE manager state. - * @return The string representation of the given state. - */ -static const std::string& -ToString(UeManager::State s) -{ - return g_ueManagerStateName[s]; -} - NS_OBJECT_ENSURE_REGISTERED(UeManager); UeManager::UeManager() @@ -296,7 +271,7 @@ UeManager::DoInitialize() break; default: - NS_FATAL_ERROR("unexpected state " << ToString(m_state)); + NS_FATAL_ERROR("unexpected state " << m_state); break; } m_caSupportConfigured = false; @@ -381,7 +356,7 @@ UeManager::InitialContextSetupRequest() } else { - NS_FATAL_ERROR("method unexpected in state " << ToString(m_state)); + NS_FATAL_ERROR("method unexpected in state " << m_state); } } @@ -640,7 +615,7 @@ UeManager::ScheduleRrcConnectionReconfiguration() break; default: - NS_FATAL_ERROR("method unexpected in state " << ToString(m_state)); + NS_FATAL_ERROR("method unexpected in state " << m_state); break; } } @@ -780,7 +755,7 @@ UeManager::PrepareHandover(uint16_t cellId) break; default: - NS_FATAL_ERROR("method unexpected in state " << ToString(m_state)); + NS_FATAL_ERROR("method unexpected in state " << m_state); break; } } @@ -975,7 +950,7 @@ UeManager::SendData(uint8_t bid, Ptr p) break; default: - NS_FATAL_ERROR("method unexpected in state " << ToString(m_state)); + NS_FATAL_ERROR("method unexpected in state " << m_state); break; } } @@ -1027,7 +1002,7 @@ UeManager::SendUeContextRelease() break; default: - NS_FATAL_ERROR("method unexpected in state " << ToString(m_state)); + NS_FATAL_ERROR("method unexpected in state " << m_state); break; } } @@ -1051,7 +1026,7 @@ UeManager::RecvHandoverPreparationFailure(uint16_t cellId) break; default: - NS_FATAL_ERROR("method unexpected in state " << ToString(m_state)); + NS_FATAL_ERROR("method unexpected in state " << m_state); break; } } @@ -1078,7 +1053,7 @@ void UeManager::RecvUeContextRelease(EpcX2SapUser::UeContextReleaseParams params) { NS_LOG_FUNCTION(this); - NS_ASSERT_MSG(m_state == HANDOVER_LEAVING, "method unexpected in state " << ToString(m_state)); + NS_ASSERT_MSG(m_state == HANDOVER_LEAVING, "method unexpected in state " << m_state); m_handoverLeavingTimeout.Cancel(); } @@ -1086,7 +1061,7 @@ void UeManager::RecvHandoverCancel(EpcX2SapUser::HandoverCancelParams params) { NS_LOG_FUNCTION(this); - NS_ASSERT_MSG(m_state == HANDOVER_JOINING, "method unexpected in state " << ToString(m_state)); + NS_ASSERT_MSG(m_state == HANDOVER_JOINING, "method unexpected in state " << m_state); m_handoverJoiningTimeout.Cancel(); } @@ -1164,7 +1139,7 @@ UeManager::RecvRrcConnectionRequest(LteRrcSap::RrcConnectionRequest msg) break; default: - NS_FATAL_ERROR("method unexpected in state " << ToString(m_state)); + NS_FATAL_ERROR("method unexpected in state " << m_state); break; } } @@ -1198,7 +1173,7 @@ UeManager::RecvRrcConnectionSetupCompleted(LteRrcSap::RrcConnectionSetupComplete break; default: - NS_FATAL_ERROR("method unexpected in state " << ToString(m_state)); + NS_FATAL_ERROR("method unexpected in state " << m_state); break; } } @@ -1242,13 +1217,11 @@ UeManager::RecvRrcConnectionReconfigurationCompleted( // This case is added to NS-3 in order to handle bearer de-activation scenario for CONNECTED // state UE case CONNECTED_NORMALLY: - NS_LOG_INFO("ignoring RecvRrcConnectionReconfigurationCompleted in state " - << ToString(m_state)); + NS_LOG_INFO("ignoring RecvRrcConnectionReconfigurationCompleted in state " << m_state); break; case HANDOVER_LEAVING: - NS_LOG_INFO("ignoring RecvRrcConnectionReconfigurationCompleted in state " - << ToString(m_state)); + NS_LOG_INFO("ignoring RecvRrcConnectionReconfigurationCompleted in state " << m_state); break; case HANDOVER_JOINING: { @@ -1285,7 +1258,7 @@ UeManager::RecvRrcConnectionReconfigurationCompleted( break; default: - NS_FATAL_ERROR("method unexpected in state " << ToString(m_state)); + NS_FATAL_ERROR("method unexpected in state " << m_state); break; } } @@ -1305,7 +1278,7 @@ UeManager::RecvRrcConnectionReestablishmentRequest( break; default: - NS_FATAL_ERROR("method unexpected in state " << ToString(m_state)); + NS_FATAL_ERROR("method unexpected in state " << m_state); break; } @@ -1685,11 +1658,11 @@ UeManager::Bid2Drbid(uint8_t bid) void UeManager::SwitchToState(State newState) { - NS_LOG_FUNCTION(this << ToString(newState)); + NS_LOG_FUNCTION(this << newState); State oldState = m_state; m_state = newState; - NS_LOG_INFO(this << " IMSI " << m_imsi << " RNTI " << m_rnti << " UeManager " - << ToString(oldState) << " --> " << ToString(newState)); + NS_LOG_INFO(this << " IMSI " << m_imsi << " RNTI " << m_rnti << " UeManager " << oldState + << " --> " << newState); m_stateTransitionTrace(m_imsi, m_rrc->ComponentCarrierToCellId(m_componentCarrierId), m_rnti, @@ -2608,7 +2581,7 @@ LteEnbRrc::ConnectionRequestTimeout(uint16_t rnti) NS_LOG_FUNCTION(this << rnti); NS_ASSERT_MSG(GetUeManager(rnti)->GetState() == UeManager::INITIAL_RANDOM_ACCESS, "ConnectionRequestTimeout in unexpected state " - << ToString(GetUeManager(rnti)->GetState())); + << GetUeManager(rnti)->GetState()); m_rrcTimeoutTrace(GetUeManager(rnti)->GetImsi(), rnti, ComponentCarrierToCellId(GetUeManager(rnti)->GetComponentCarrierId()), @@ -2621,8 +2594,7 @@ LteEnbRrc::ConnectionSetupTimeout(uint16_t rnti) { NS_LOG_FUNCTION(this << rnti); NS_ASSERT_MSG(GetUeManager(rnti)->GetState() == UeManager::CONNECTION_SETUP, - "ConnectionSetupTimeout in unexpected state " - << ToString(GetUeManager(rnti)->GetState())); + "ConnectionSetupTimeout in unexpected state " << GetUeManager(rnti)->GetState()); m_rrcTimeoutTrace(GetUeManager(rnti)->GetImsi(), rnti, ComponentCarrierToCellId(GetUeManager(rnti)->GetComponentCarrierId()), @@ -2636,7 +2608,7 @@ LteEnbRrc::ConnectionRejectedTimeout(uint16_t rnti) NS_LOG_FUNCTION(this << rnti); NS_ASSERT_MSG(GetUeManager(rnti)->GetState() == UeManager::CONNECTION_REJECTED, "ConnectionRejectedTimeout in unexpected state " - << ToString(GetUeManager(rnti)->GetState())); + << GetUeManager(rnti)->GetState()); m_rrcTimeoutTrace(GetUeManager(rnti)->GetImsi(), rnti, ComponentCarrierToCellId(GetUeManager(rnti)->GetComponentCarrierId()), @@ -2649,8 +2621,7 @@ LteEnbRrc::HandoverJoiningTimeout(uint16_t rnti) { NS_LOG_FUNCTION(this << rnti); NS_ASSERT_MSG(GetUeManager(rnti)->GetState() == UeManager::HANDOVER_JOINING, - "HandoverJoiningTimeout in unexpected state " - << ToString(GetUeManager(rnti)->GetState())); + "HandoverJoiningTimeout in unexpected state " << GetUeManager(rnti)->GetState()); m_handoverFailureJoiningTrace( GetUeManager(rnti)->GetImsi(), rnti, @@ -2677,8 +2648,7 @@ LteEnbRrc::HandoverLeavingTimeout(uint16_t rnti) { NS_LOG_FUNCTION(this << rnti); NS_ASSERT_MSG(GetUeManager(rnti)->GetState() == UeManager::HANDOVER_LEAVING, - "HandoverLeavingTimeout in unexpected state " - << ToString(GetUeManager(rnti)->GetState())); + "HandoverLeavingTimeout in unexpected state " << GetUeManager(rnti)->GetState()); m_handoverFailureLeavingTrace( GetUeManager(rnti)->GetImsi(), rnti, @@ -3166,8 +3136,7 @@ LteEnbRrc::DoTriggerHandover(uint16_t rnti, uint16_t targetCellId) { isHandoverAllowed = false; NS_LOG_LOGIC(this << " handover is not allowed because the UE" - << " rnti=" << rnti << " is in " << ToString(ueManager->GetState()) - << " state"); + << " rnti=" << rnti << " is in " << ueManager->GetState() << " state"); } if (isHandoverAllowed) @@ -3525,4 +3494,37 @@ LteEnbRrc::IsRandomAccessCompleted(uint16_t rnti) } } +std::ostream& +operator<<(std::ostream& os, UeManager::State state) +{ + switch (state) + { + case UeManager::State::INITIAL_RANDOM_ACCESS: + return os << "INITIAL_RANDOM_ACCESS"; + case UeManager::State::CONNECTION_SETUP: + return os << "CONNECTION_SETUP"; + case UeManager::State::CONNECTION_REJECTED: + return os << "CONNECTION_REJECTED"; + case UeManager::State::ATTACH_REQUEST: + return os << "ATTACH_REQUEST"; + case UeManager::State::CONNECTED_NORMALLY: + return os << "CONNECTED_NORMALLY"; + case UeManager::State::CONNECTION_RECONFIGURATION: + return os << "CONNECTION_RECONFIGURATION"; + case UeManager::State::CONNECTION_REESTABLISHMENT: + return os << "CONNECTION_REESTABLISHMENT"; + case UeManager::State::HANDOVER_PREPARATION: + return os << "HANDOVER_PREPARATION"; + case UeManager::State::HANDOVER_JOINING: + return os << "HANDOVER_JOINING"; + case UeManager::State::HANDOVER_PATH_SWITCH: + return os << "HANDOVER_PATH_SWITCH"; + case UeManager::State::HANDOVER_LEAVING: + return os << "HANDOVER_LEAVING"; + case UeManager::State::NUM_STATES: + return os << "NUM_STATES"; + }; + return os << "UNKNOWN(" << static_cast(state) << ")"; +} + } // namespace ns3 diff --git a/src/lte/model/lte-enb-rrc.h b/src/lte/model/lte-enb-rrc.h index 62bdd0bf86..58091d34aa 100644 --- a/src/lte/model/lte-enb-rrc.h +++ b/src/lte/model/lte-enb-rrc.h @@ -1777,6 +1777,14 @@ class LteEnbRrc : public Object }; // end of `class LteEnbRrc` +/** + * @brief Stream insertion operator. + * @param [in] os The reference to the output stream. + * @param [in] state The UeManager::State. + * @return The reference to the output stream. + */ +std::ostream& operator<<(std::ostream& os, UeManager::State state); + } // namespace ns3 #endif // LTE_ENB_RRC_H diff --git a/src/lte/model/lte-ue-phy.cc b/src/lte/model/lte-ue-phy.cc index 79dc5b20a5..80a7cc6449 100644 --- a/src/lte/model/lte-ue-phy.cc +++ b/src/lte/model/lte-ue-phy.cc @@ -111,22 +111,6 @@ UeMemberLteUePhySapProvider::NotifyConnectionSuccessful() // LteUePhy methods //////////////////////////////////////// -/// Map each of UE PHY states to its string representation. -static const std::string g_uePhyStateName[LteUePhy::NUM_STATES] = { - "CELL_SEARCH", - "SYNCHRONIZED", -}; - -/** - * @param s The UE PHY state. - * @return The string representation of the given state. - */ -static inline const std::string& -ToString(LteUePhy::State s) -{ - return g_uePhyStateName[s]; -} - NS_OBJECT_ENSURE_REGISTERED(LteUePhy); LteUePhy::LteUePhy() @@ -1755,9 +1739,24 @@ LteUePhy::SwitchToState(State newState) NS_LOG_FUNCTION(this << newState); State oldState = m_state; m_state = newState; - NS_LOG_INFO(this << " cellId=" << m_cellId << " rnti=" << m_rnti << " UePhy " - << ToString(oldState) << " --> " << ToString(newState)); + NS_LOG_INFO(this << " cellId=" << m_cellId << " rnti=" << m_rnti << " UePhy " << oldState + << " --> " << newState); m_stateTransitionTrace(m_cellId, m_rnti, oldState, newState); } +std::ostream& +operator<<(std::ostream& os, LteUePhy::State state) +{ + switch (state) + { + case LteUePhy::State::CELL_SEARCH: + return os << "CELL_SEARCH"; + case LteUePhy::State::SYNCHRONIZED: + return os << "SYNCHRONIZED"; + case LteUePhy::State::NUM_STATES: + return os << "NUM_STATES"; + }; + return os << "UNKNOWN(" << static_cast(state) << ")"; +} + } // namespace ns3 diff --git a/src/lte/model/lte-ue-phy.h b/src/lte/model/lte-ue-phy.h index 9969e732f8..8b8c44c67b 100644 --- a/src/lte/model/lte-ue-phy.h +++ b/src/lte/model/lte-ue-phy.h @@ -844,6 +844,14 @@ class LteUePhy : public LtePhy }; // end of `class LteUePhy` +/** + * @brief Stream insertion operator. + * @param [in] os The reference to the output stream. + * @param [in] state The LteUePhy::State. + * @return The reference to the output stream. + */ +std::ostream& operator<<(std::ostream& os, LteUePhy::State state); + } // namespace ns3 #endif /* LTE_UE_PHY_H */ diff --git a/src/lte/model/lte-ue-rrc.cc b/src/lte/model/lte-ue-rrc.cc index 12d4a343cb..83e109c3e8 100644 --- a/src/lte/model/lte-ue-rrc.cc +++ b/src/lte/model/lte-ue-rrc.cc @@ -82,23 +82,6 @@ UeMemberLteUeCmacSapUser::NotifyRandomAccessFailed() m_rrc->DoNotifyRandomAccessFailed(); } -/// Map each of UE RRC states to its string representation. -static const std::string g_ueRrcStateName[LteUeRrc::NUM_STATES] = { - "IDLE_START", - "IDLE_CELL_SEARCH", - "IDLE_WAIT_MIB_SIB1", - "IDLE_WAIT_MIB", - "IDLE_WAIT_SIB1", - "IDLE_CAMPED_NORMALLY", - "IDLE_WAIT_SIB2", - "IDLE_RANDOM_ACCESS", - "IDLE_CONNECTING", - "CONNECTED_NORMALLY", - "CONNECTED_HANDOVER", - "CONNECTED_PHY_PROBLEM", - "CONNECTED_REESTABLISHING", -}; - ///////////////////////////// // ue RRC methods ///////////////////////////// @@ -625,7 +608,7 @@ LteUeRrc::DoDisconnect() break; default: // i.e. IDLE_RANDOM_ACCESS - NS_FATAL_ERROR("method unexpected in state " << ToString(m_state)); + NS_FATAL_ERROR("method unexpected in state " << m_state); break; } } @@ -649,7 +632,7 @@ LteUeRrc::DoSetTemporaryCellRnti(uint16_t rnti) void LteUeRrc::DoNotifyRandomAccessSuccessful() { - NS_LOG_FUNCTION(this << m_imsi << ToString(m_state)); + NS_LOG_FUNCTION(this << m_imsi << m_state); m_randomAccessSuccessfulTrace(m_imsi, m_cellId, m_rnti); switch (m_state) @@ -685,7 +668,7 @@ LteUeRrc::DoNotifyRandomAccessSuccessful() break; default: - NS_FATAL_ERROR("unexpected event in state " << ToString(m_state)); + NS_FATAL_ERROR("unexpected event in state " << m_state); break; } } @@ -693,7 +676,7 @@ LteUeRrc::DoNotifyRandomAccessSuccessful() void LteUeRrc::DoNotifyRandomAccessFailed() { - NS_LOG_FUNCTION(this << m_imsi << ToString(m_state)); + NS_LOG_FUNCTION(this << m_imsi << m_state); m_randomAccessErrorTrace(m_imsi, m_cellId, m_rnti); switch (m_state) @@ -725,7 +708,7 @@ LteUeRrc::DoNotifyRandomAccessFailed() break; default: - NS_FATAL_ERROR("unexpected event in state " << ToString(m_state)); + NS_FATAL_ERROR("unexpected event in state " << m_state); break; } } @@ -741,8 +724,7 @@ void LteUeRrc::DoStartCellSelection(uint32_t dlEarfcn) { NS_LOG_FUNCTION(this << m_imsi << dlEarfcn); - NS_ASSERT_MSG(m_state == IDLE_START, - "cannot start cell selection from state " << ToString(m_state)); + NS_ASSERT_MSG(m_state == IDLE_START, "cannot start cell selection from state " << m_state); m_dlEarfcn = dlEarfcn; m_cphySapProvider.at(0)->StartCellSearch(dlEarfcn); SwitchToState(IDLE_CELL_SEARCH); @@ -765,7 +747,7 @@ LteUeRrc::DoForceCampedOnEnb(uint16_t cellId, uint32_t dlEarfcn) case IDLE_CELL_SEARCH: case IDLE_WAIT_MIB_SIB1: case IDLE_WAIT_SIB1: - NS_FATAL_ERROR("cannot abort cell selection " << ToString(m_state)); + NS_FATAL_ERROR("cannot abort cell selection " << m_state); break; case IDLE_WAIT_MIB: @@ -787,7 +769,7 @@ LteUeRrc::DoForceCampedOnEnb(uint16_t cellId, uint32_t dlEarfcn) break; default: - NS_FATAL_ERROR("unexpected event in state " << ToString(m_state)); + NS_FATAL_ERROR("unexpected event in state " << m_state); break; } } @@ -825,7 +807,7 @@ LteUeRrc::DoConnect() break; default: - NS_FATAL_ERROR("unexpected event in state " << ToString(m_state)); + NS_FATAL_ERROR("unexpected event in state " << m_state); break; } } @@ -1032,7 +1014,7 @@ LteUeRrc::DoRecvRrcConnectionSetup(LteRrcSap::RrcConnectionSetup msg) break; default: - NS_FATAL_ERROR("method unexpected in state " << ToString(m_state)); + NS_FATAL_ERROR("method unexpected in state " << m_state); break; } } @@ -1136,7 +1118,7 @@ LteUeRrc::DoRecvRrcConnectionReconfiguration(LteRrcSap::RrcConnectionReconfigura break; default: - NS_FATAL_ERROR("method unexpected in state " << ToString(m_state)); + NS_FATAL_ERROR("method unexpected in state " << m_state); break; } } @@ -1159,7 +1141,7 @@ LteUeRrc::DoRecvRrcConnectionReestablishment(LteRrcSap::RrcConnectionReestablish break; default: - NS_FATAL_ERROR("method unexpected in state " << ToString(m_state)); + NS_FATAL_ERROR("method unexpected in state " << m_state); break; } } @@ -1181,7 +1163,7 @@ LteUeRrc::DoRecvRrcConnectionReestablishmentReject( break; default: - NS_FATAL_ERROR("method unexpected in state " << ToString(m_state)); + NS_FATAL_ERROR("method unexpected in state " << m_state); break; } } @@ -1318,7 +1300,7 @@ LteUeRrc::EvaluateCellForSelection() // and start random access. if (!m_connectionPending) { - NS_LOG_DEBUG("Calling DoConnect in state = " << ToString(m_state)); + NS_LOG_DEBUG("Calling DoConnect in state = " << m_state); DoConnect(); } SwitchToState(IDLE_CAMPED_NORMALLY); @@ -1428,7 +1410,7 @@ LteUeRrc::ApplyRadioResourceConfigDedicated(LteRrcSap::RadioResourceConfigDedica { // SRB1 not setup yet NS_ASSERT_MSG((m_state == IDLE_CONNECTING) || (m_state == CONNECTED_HANDOVER), - "unexpected state " << ToString(m_state)); + "unexpected state " << m_state); NS_ASSERT_MSG(stamIt->srbIdentity == 1, "only SRB1 supported"); const uint8_t lcid = 1; // fixed LCID for SRB1 @@ -1888,9 +1870,9 @@ LteUeRrc::SaveUeMeasurements(uint16_t cellId, storedMeasIt = ret.first; } - NS_LOG_DEBUG(this << " IMSI " << m_imsi << " state " << ToString(m_state) << ", measured cell " - << cellId << ", carrier component Id " << componentCarrierId << ", new RSRP " - << rsrp << " stored " << storedMeasIt->second.rsrp << ", new RSRQ " << rsrq + NS_LOG_DEBUG(this << " IMSI " << m_imsi << " state " << m_state << ", measured cell " << cellId + << ", carrier component Id " << componentCarrierId << ", new RSRP " << rsrp + << " stored " << storedMeasIt->second.rsrp << ", new RSRQ " << rsrq << " stored " << storedMeasIt->second.rsrq); } // end of void SaveUeMeasurements @@ -3214,11 +3196,11 @@ LteUeRrc::Bid2Drbid(uint8_t bid) void LteUeRrc::SwitchToState(State newState) { - NS_LOG_FUNCTION(this << ToString(newState)); + NS_LOG_FUNCTION(this << newState); State oldState = m_state; m_state = newState; - NS_LOG_INFO(this << " IMSI " << m_imsi << " RNTI " << m_rnti << " UeRrc " << ToString(oldState) - << " --> " << ToString(newState)); + NS_LOG_INFO(this << " IMSI " << m_imsi << " RNTI " << m_rnti << " UeRrc " << oldState << " --> " + << newState); m_stateTransitionTrace(m_imsi, m_cellId, m_rnti, oldState, newState); switch (newState) @@ -3332,7 +3314,46 @@ LteUeRrc::ResetRlfParams() const std::string LteUeRrc::ToString(LteUeRrc::State s) { - return g_ueRrcStateName[s]; + std::ostringstream ss; + ss << s; + return ss.str(); +} + +std::ostream& +operator<<(std::ostream& os, LteUeRrc::State state) +{ + switch (state) + { + case LteUeRrc::State::IDLE_START: + return os << "IDLE_START"; + case LteUeRrc::State::IDLE_CELL_SEARCH: + return os << "IDLE_CELL_SEARCH"; + case LteUeRrc::State::IDLE_WAIT_MIB_SIB1: + return os << "IDLE_WAIT_MIB_SIB1"; + case LteUeRrc::State::IDLE_WAIT_MIB: + return os << "IDLE_WAIT_MIB"; + case LteUeRrc::State::IDLE_WAIT_SIB1: + return os << "IDLE_WAIT_SIB1"; + case LteUeRrc::State::IDLE_CAMPED_NORMALLY: + return os << "IDLE_CAMPED_NORMALLY"; + case LteUeRrc::State::IDLE_WAIT_SIB2: + return os << "IDLE_WAIT_SIB2"; + case LteUeRrc::State::IDLE_RANDOM_ACCESS: + return os << "IDLE_RANDOM_ACCESS"; + case LteUeRrc::State::IDLE_CONNECTING: + return os << "IDLE_CONNECTING"; + case LteUeRrc::State::CONNECTED_NORMALLY: + return os << "CONNECTED_NORMALLY"; + case LteUeRrc::State::CONNECTED_HANDOVER: + return os << "CONNECTED_HANDOVER"; + case LteUeRrc::State::CONNECTED_PHY_PROBLEM: + return os << "CONNECTED_PHY_PROBLEM"; + case LteUeRrc::State::CONNECTED_REESTABLISHING: + return os << "CONNECTED_REESTABLISHING"; + case LteUeRrc::State::NUM_STATES: + return os << "NUM_STATES"; + }; + return os << "UNKNOWN(" << static_cast(state) << ")"; } } // namespace ns3 diff --git a/src/lte/model/lte-ue-rrc.h b/src/lte/model/lte-ue-rrc.h index 77a40cdcb2..6ae9719056 100644 --- a/src/lte/model/lte-ue-rrc.h +++ b/src/lte/model/lte-ue-rrc.h @@ -22,6 +22,7 @@ #include "lte-ue-cmac-sap.h" #include "lte-ue-cphy-sap.h" +#include #include #include #include @@ -313,6 +314,7 @@ class LteUeRrc : public Object * @param s The UE RRC state. * @return The string representation of the given state. */ + NS_DEPRECATED_3_44("Use operator<< instead") static const std::string ToString(LteUeRrc::State s); /** @@ -1333,6 +1335,14 @@ class LteUeRrc : public Object }; // end of class LteUeRrc +/** + * @brief Stream insertion operator. + * @param [in] os The reference to the output stream. + * @param [in] state The LteUeRrc::State. + * @return The reference to the output stream. + */ +std::ostream& operator<<(std::ostream& os, LteUeRrc::State state); + } // namespace ns3 #endif // LTE_UE_RRC_H diff --git a/src/lte/test/lte-test-secondary-cell-selection.cc b/src/lte/test/lte-test-secondary-cell-selection.cc index ac132492f8..3b859f2086 100644 --- a/src/lte/test/lte-test-secondary-cell-selection.cc +++ b/src/lte/test/lte-test-secondary-cell-selection.cc @@ -173,8 +173,7 @@ LteSecondaryCellSelectionTestCase::StateTransitionCallback(std::string context, LteUeRrc::State oldState, LteUeRrc::State newState) { - NS_LOG_FUNCTION(this << imsi << cellId << rnti << LteUeRrc::ToString(oldState) - << LteUeRrc::ToString(newState)); + NS_LOG_FUNCTION(this << imsi << cellId << rnti << oldState << newState); m_lastState[imsi] = newState; }