Skip to content

Commit

Permalink
lte: Add operator<<() for the several enums
Browse files Browse the repository at this point in the history
  • Loading branch information
a-andre authored and Gabrielcarvfer committed Nov 20, 2024
1 parent 30ab8f4 commit 97954dc
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 166 deletions.
31 changes: 2 additions & 29 deletions src/lte/examples/lena-radio-link-failure.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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;
}

/**
Expand Down
45 changes: 23 additions & 22 deletions src/lte/model/epc-ue-nas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand All @@ -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<uint32_t>(state) << ")";
}

} // namespace ns3
8 changes: 8 additions & 0 deletions src/lte/model/epc-ue-nas.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,14 @@ class EpcUeNas : public Object
std::list<BearerToBeActivated> 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
Loading

0 comments on commit 97954dc

Please sign in to comment.