Commit 25617b9f authored by Tien Thinh NGUYEN's avatar Tien Thinh NGUYEN

Code refactor for gNB context

parent 7b46f95a
...@@ -1673,8 +1673,12 @@ bool amf_n2::handle_itti_message(itti_handover_required& itti_msg) { ...@@ -1673,8 +1673,12 @@ bool amf_n2::handle_itti_message(itti_handover_required& itti_msg) {
int encoded_size = handover_request->Encode(buffer, BUFFER_SIZE_4096); int encoded_size = handover_request->Encode(buffer, BUFFER_SIZE_4096);
bstring b = blk2bstr(buffer, encoded_size); bstring b = blk2bstr(buffer, encoded_size);
std::shared_ptr<gnb_context> gc_target = {}; std::shared_ptr<gnb_context> gc_target = {};
gc_target = gnb_id_2_gnb_context(gnb_id_value); if (!gnb_id_2_gnb_context(gnb_id_value, gc_target)) {
unc->target_gnb_assoc_id = gc_target->sctp_assoc_id; Logger::amf_n2().warn("Could not find Target's gNB context!");
return false;
}
unc->target_gnb_assoc_id = gc_target->sctp_assoc_id;
sctp_s_38412.sctp_send_msg(gc_target->sctp_assoc_id, 0, &b); sctp_s_38412.sctp_send_msg(gc_target->sctp_assoc_id, 0, &b);
bdestroy_wrapper(&b); bdestroy_wrapper(&b);
return true; return true;
......
...@@ -43,11 +43,14 @@ typedef enum { ...@@ -43,11 +43,14 @@ typedef enum {
NGAP_RESETING, NGAP_RESETING,
NGAP_READY, NGAP_READY,
NGAP_SHUTDOWN NGAP_SHUTDOWN
} amf_ng_gnb_state_t; } ng_gnb_state_t;
static const std::vector<std::string> ng_gnb_state_str = {
"NGAP_INIT", "NGAP_RESETTING", "NGAP_READY", "NGAP_SHUTDOWN"};
class gnb_context { class gnb_context {
public: public:
amf_ng_gnb_state_t ng_state; ng_gnb_state_t ng_state;
std::string gnb_name; std::string gnb_name;
long globalRanNodeId; long globalRanNodeId;
......
...@@ -164,14 +164,22 @@ void ngap_app::set_assoc_id_2_gnb_context( ...@@ -164,14 +164,22 @@ void ngap_app::set_assoc_id_2_gnb_context(
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool ngap_app::is_gnb_id_2_gnb_context(const long& gnb_id) const { bool ngap_app::is_gnb_id_2_gnb_context(const long& gnb_id) const {
std::shared_lock lock(m_gnbid2gnbContext); std::shared_lock lock(m_gnbid2gnbContext);
return bool{gnbid2gnbContext.count(gnb_id) > 0}; if (gnbid2gnbContext.count(gnb_id) > 0) {
if (gnbid2gnbContext.at(gnb_id) != nullptr) return true;
}
return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
std::shared_ptr<gnb_context> ngap_app::gnb_id_2_gnb_context( bool ngap_app::gnb_id_2_gnb_context(
const long& gnb_id) const { const long& gnb_id, std::shared_ptr<gnb_context>& gc) const {
std::shared_lock lock(m_gnbid2gnbContext); std::shared_lock lock(m_gnbid2gnbContext);
return gnbid2gnbContext.at(gnb_id); if (gnbid2gnbContext.count(gnb_id) > 0) {
if (gnbid2gnbContext.at(gnb_id) == nullptr) return false;
gc = gnbid2gnbContext.at(gnb_id);
return true;
}
return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
......
...@@ -33,9 +33,6 @@ using namespace sctp; ...@@ -33,9 +33,6 @@ using namespace sctp;
namespace ngap { namespace ngap {
static const std::vector<std::string> ng_gnb_state_str = {
"NGAP_INIT", "NGAP_RESETTING", "NGAP_READY", "NGAP_SHUTDOWN"};
class ngap_app : public sctp_application { class ngap_app : public sctp_application {
public: public:
ngap_app(const std::string& address, const uint16_t port_num); ngap_app(const std::string& address, const uint16_t port_num);
...@@ -121,11 +118,13 @@ class ngap_app : public sctp_application { ...@@ -121,11 +118,13 @@ class ngap_app : public sctp_application {
const long& gnb_id, const std::shared_ptr<gnb_context>& gc); const long& gnb_id, const std::shared_ptr<gnb_context>& gc);
/* /*
* Get the gNB Context associated with a gNB id * Get the gNB Context associated with a gNB id if exits and not null
* @param [const long& ] gnb_id: gNB ID * @param [const long& ] gnb_id: gNB ID
* @return the pointer to the gNB context * @param [const std::shared_ptr<gnb_context>&] gc: pointer to the gNB context
* @return true if the context exists and not null, otherwise return false
*/ */
std::shared_ptr<gnb_context> gnb_id_2_gnb_context(const long& gnb_id) const; bool gnb_id_2_gnb_context(
const long& gnb_id, std::shared_ptr<gnb_context>& gc) const;
/* /*
* Remove the gNB Context associated with a gNB id * Remove the gNB Context associated with a gNB id
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment