Commit c62e8552 authored by Tien Thinh NGUYEN's avatar Tien Thinh NGUYEN

Refactor for UE NAS/NGAP context

parent b78197fc
......@@ -235,7 +235,6 @@ void amf_app::set_ran_amf_id_2_ue_context(
//------------------------------------------------------------------------------
bool amf_app::is_supi_2_ue_context(const string& supi) const {
std::shared_lock lock(m_supi2ue_ctx);
// return bool{supi2ue_ctx.count(supi) > 0};
if (supi2ue_ctx.count(supi) > 0) {
if (supi2ue_ctx.at(supi) != nullptr) {
return true;
......@@ -244,13 +243,6 @@ bool amf_app::is_supi_2_ue_context(const string& supi) const {
return false;
}
//------------------------------------------------------------------------------
std::shared_ptr<ue_context> amf_app::supi_2_ue_context(
const string& supi) const {
std::shared_lock lock(m_supi2ue_ctx);
return supi2ue_ctx.at(supi);
}
//------------------------------------------------------------------------------
bool amf_app::supi_2_ue_context(
const std::string& supi, std::shared_ptr<ue_context>& uc) const {
......@@ -520,7 +512,8 @@ void amf_app::handle_itti_message(itti_sbi_n1_message_notification& itti_msg) {
if (ue_ctx.supiIsSet()) {
supi = ue_ctx.getSupi();
if (!is_supi_2_ue_context(supi)) {
// Update UE Context
if (!supi_2_ue_context(supi, uc)) {
// Create a new UE Context
Logger::amf_app().debug(
"No existing UE Context, Create a new one with SUPI %s",
......@@ -529,8 +522,6 @@ void amf_app::handle_itti_message(itti_sbi_n1_message_notification& itti_msg) {
uc->amf_ue_ngap_id = -1;
uc->supi = supi;
set_supi_2_ue_context(supi, uc);
} else { // Update UE Context
uc = supi_2_ue_context(supi);
}
}
......
......@@ -224,13 +224,6 @@ class amf_app {
*/
bool is_supi_2_ue_context(const string& supi) const;
/*
* Get UE context associated with a SUPI
* @param [const std::string&] supi: UE SUPI
* @return shared pointer to the context
*/
std::shared_ptr<ue_context> supi_2_ue_context(const string& supi) const;
/*
* Get UE context associated with a SUPI
* @param [const std::string&] supi: SUPI
......
......@@ -124,6 +124,7 @@ typedef struct auth_conf_s {
std::string mysql_pass;
std::string mysql_db;
std::string random;
nlohmann::json to_json() const {
nlohmann::json json_data = {};
json_data["mysql_server"] = this->mysql_server;
......@@ -231,6 +232,7 @@ typedef struct guami_s {
typedef struct slice_s {
uint8_t sst;
uint32_t sd;
bool operator==(const struct slice_s& s) const {
if ((s.sst == this->sst) && (s.sd == this->sd)) {
return true;
......@@ -238,13 +240,16 @@ typedef struct slice_s {
return false;
}
}
bool operator>(const struct slice_s& s) const {
if (this->sst > s.sst) return true;
if (this->sst == s.sst) {
if (this->sd > s.sd) return true;
if (this->sd <= s.sd) return false;
}
return true;
}
nlohmann::json to_json() const {
nlohmann::json json_data = {};
json_data["sst"] = this->sst;
......
......@@ -212,7 +212,7 @@ void amf_n1::handle_itti_message(itti_downlink_nas_transfer& itti_msg) {
long amf_ue_ngap_id = itti_msg.amf_ue_ngap_id;
uint32_t ran_ue_ngap_id = itti_msg.ran_ue_ngap_id;
std::shared_ptr<nas_context> nc = {};
if (!is_amf_ue_id_2_nas_context(amf_ue_ngap_id, nc)) {
if (!amf_ue_id_2_nas_context(amf_ue_ngap_id, nc)) {
Logger::amf_n1().warn(
"No existed nas_context with amf_ue_ngap_id (" AMF_UE_NGAP_ID_FMT ")",
amf_ue_ngap_id);
......@@ -263,7 +263,7 @@ void amf_n1::handle_itti_message(itti_downlink_nas_transfer& itti_msg) {
// Get NSSAI
std::shared_ptr<nas_context> nc = {};
if (!is_amf_ue_id_2_nas_context(amf_ue_ngap_id, nc)) {
if (!amf_ue_id_2_nas_context(amf_ue_ngap_id, nc)) {
Logger::amf_n1().warn(
"No existed NAS context for UE with amf_ue_ngap_id "
"(" AMF_UE_NGAP_ID_FMT ")",
......@@ -657,7 +657,7 @@ void amf_n1::uplink_nas_msg_handle(
case SERVICE_REQUEST: {
Logger::amf_n1().debug("Received Service Request message, handling...");
std::shared_ptr<nas_context> nc = {};
if (is_amf_ue_id_2_nas_context(amf_ue_ngap_id, nc)) {
if (amf_ue_id_2_nas_context(amf_ue_ngap_id, nc)) {
service_request_handle(nc, ran_ue_ngap_id, amf_ue_ngap_id, plain_msg);
} else {
Logger::amf_n1().debug("No NAS context available");
......@@ -732,9 +732,8 @@ void amf_n1::identity_response_handle(
uc->supi = "imsi-" + supi;
// associate SUPI with UC
// Verify if there's PDU session info in the old context
if (amf_app_inst->is_supi_2_ue_context(uc->supi)) {
std::shared_ptr<ue_context> old_uc = {};
old_uc = amf_app_inst->supi_2_ue_context(uc->supi);
std::shared_ptr<ue_context> old_uc = {};
if (amf_app_inst->is_supi_2_ue_context(uc->supi, old_uc)) {
uc->copy_pdu_sessions(old_uc);
}
amf_app_inst->set_supi_2_ue_context(uc->supi, uc);
......@@ -902,9 +901,8 @@ void amf_n1::service_request_handle(
// Get the status of PDU Session context
std::shared_ptr<pdu_session_context> old_psc = {};
if (amf_app_inst->is_supi_2_ue_context(supi)) {
std::shared_ptr<ue_context> old_uc = {};
old_uc = amf_app_inst->supi_2_ue_context(supi);
std::shared_ptr<ue_context> old_uc = {};
if (amf_app_inst->supi_2_ue_context(supi, old_uc)) {
uc->copy_pdu_sessions(old_uc);
amf_app_inst->set_supi_2_ue_context(supi, uc);
}
......@@ -1140,11 +1138,10 @@ void amf_n1::registration_request_handle(
// Try to find old nas_context and release
std::shared_ptr<nas_context> old_nc = {};
old_nc = imsi_2_nas_context("imsi-" + nc->imsi);
// release
if (old_nc) {
if (imsi_2_nas_context("imsi-" + nc->imsi, old_nc)) {
old_nc.reset();
}
set_imsi_2_nas_context("imsi-" + nc->imsi, nc);
Logger::amf_n1().info(
"Associating IMSI (%s) with nas_context (%p)",
......@@ -1453,25 +1450,18 @@ bool amf_n1::is_amf_ue_id_2_nas_context(const long& amf_ue_ngap_id) const {
}
//------------------------------------------------------------------------------
bool amf_n1::is_amf_ue_id_2_nas_context(
bool amf_n1::amf_ue_id_2_nas_context(
const long& amf_ue_ngap_id, std::shared_ptr<nas_context>& nc) const {
std::shared_lock lock(m_amfueid2nas_context);
if (amfueid2nas_context.count(amf_ue_ngap_id) > 0) {
nc = amfueid2nas_context.at(amf_ue_ngap_id);
if (nc != nullptr) {
if (amfueid2nas_context.at(amf_ue_ngap_id) != nullptr) {
nc = amfueid2nas_context.at(amf_ue_ngap_id);
return true;
}
}
return false;
}
//------------------------------------------------------------------------------
std::shared_ptr<nas_context> amf_n1::amf_ue_id_2_nas_context(
const long& amf_ue_ngap_id) const {
std::shared_lock lock(m_amfueid2nas_context);
return amfueid2nas_context.at(amf_ue_ngap_id);
}
//------------------------------------------------------------------------------
void amf_n1::set_amf_ue_ngap_id_2_nas_context(
const long& amf_ue_ngap_id, std::shared_ptr<nas_context> nc) {
......@@ -1589,13 +1579,15 @@ bool amf_n1::remove_guti_2_nas_context(const std::string& guti) {
}
//------------------------------------------------------------------------------
std::shared_ptr<nas_context> amf_n1::imsi_2_nas_context(
const std::string& imsi) const {
bool amf_n1::imsi_2_nas_context(
const std::string& imsi, std::shared_ptr<nas_context>& nc) const {
std::shared_lock lock(m_nas_context);
if (imsi2nas_context.count(imsi) > 0) {
return imsi2nas_context.at(imsi);
if (!imsi2nas_context.at(imsi)) return false;
nc = imsi2nas_context.at(imsi);
return true;
} else {
return nullptr;
return false;
}
}
......@@ -2217,7 +2209,7 @@ void amf_n1::authentication_response_handle(
bstring plain_msg) {
std::shared_ptr<nas_context> nc = {};
if (!is_amf_ue_id_2_nas_context(amf_ue_ngap_id, nc)) {
if (!amf_ue_id_2_nas_context(amf_ue_ngap_id, nc)) {
Logger::amf_n1().error(
"No existed NAS context for UE with amf_ue_ngap_id " AMF_UE_NGAP_ID_FMT,
amf_ue_ngap_id);
......@@ -2310,7 +2302,7 @@ void amf_n1::authentication_failure_handle(
const uint32_t ran_ue_ngap_id, const long amf_ue_ngap_id,
bstring plain_msg) {
std::shared_ptr<nas_context> nc = {};
if (!is_amf_ue_id_2_nas_context(amf_ue_ngap_id, nc)) {
if (!amf_ue_id_2_nas_context(amf_ue_ngap_id, nc)) {
Logger::amf_n1().error(
"No existed NAS context for UE with amf_ue_ngap_id (" AMF_UE_NGAP_ID_FMT
")",
......@@ -2514,7 +2506,7 @@ void amf_n1::security_mode_complete_handle(
}
std::shared_ptr<nas_context> nc = {};
if (!is_amf_ue_id_2_nas_context(amf_ue_ngap_id, nc)) {
if (!amf_ue_id_2_nas_context(amf_ue_ngap_id, nc)) {
Logger::amf_n1().warn(
"No existed nas_context with amf_ue_ngap_id (" AMF_UE_NGAP_ID_FMT ")",
amf_ue_ngap_id);
......@@ -2775,7 +2767,7 @@ void amf_n1::registration_complete_handle(
}
std::shared_ptr<nas_context> nc = {};
if (!is_amf_ue_id_2_nas_context(amf_ue_ngap_id, nc)) {
if (!amf_ue_id_2_nas_context(amf_ue_ngap_id, nc)) {
Logger::amf_n1().warn(
"No existed nas_context with amf_ue_ngap_id (" AMF_UE_NGAP_ID_FMT ")",
amf_ue_ngap_id);
......@@ -3049,7 +3041,7 @@ void amf_n1::ue_initiate_de_registration_handle(
Logger::amf_n1().debug("Handling UE-initiated De-registration Request");
std::shared_ptr<nas_context> nc = {};
if (!is_amf_ue_id_2_nas_context(amf_ue_ngap_id, nc)) {
if (!amf_ue_id_2_nas_context(amf_ue_ngap_id, nc)) {
Logger::amf_n1().warn(
"No existed nas_context with amf_ue_ngap_id (" AMF_UE_NGAP_ID_FMT ")",
amf_ue_ngap_id);
......@@ -3290,7 +3282,7 @@ void amf_n1::ul_nas_transport_handle(
"Requested/Configured NSSAI!");
std::shared_ptr<nas_context> nc = {};
if (!amf_n1_inst->is_amf_ue_id_2_nas_context(amf_ue_ngap_id, nc)) {
if (!amf_n1_inst->amf_ue_id_2_nas_context(amf_ue_ngap_id, nc)) {
Logger::amf_n1().warn(
"No existed nas_context with amf_ue_ngap_id(0x%x)", amf_ue_ngap_id);
return;
......@@ -4271,7 +4263,7 @@ bool amf_n1::find_ue_context(
void amf_n1::mobile_reachable_timer_timeout(
timer_id_t& timer_id, const uint64_t amf_ue_ngap_id) {
std::shared_ptr<nas_context> nc = {};
if (!amf_n1_inst->is_amf_ue_id_2_nas_context(amf_ue_ngap_id, nc)) {
if (!amf_n1_inst->amf_ue_id_2_nas_context(amf_ue_ngap_id, nc)) {
Logger::amf_n1().warn(
"No existed nas_context with amf_ue_ngap_id (" AMF_UE_NGAP_ID_FMT ")",
amf_ue_ngap_id);
......@@ -4301,7 +4293,7 @@ void amf_n1::mobile_reachable_timer_timeout(
void amf_n1::implicit_deregistration_timer_timeout(
timer_id_t timer_id, uint64_t amf_ue_ngap_id) {
std::shared_ptr<nas_context> nc = {};
if (amf_n1_inst->is_amf_ue_id_2_nas_context(amf_ue_ngap_id, nc)) {
if (amf_n1_inst->amf_ue_id_2_nas_context(amf_ue_ngap_id, nc)) {
Logger::amf_n1().warn(
"No existed nas_context with amf_ue_ngap_id (" AMF_UE_NGAP_ID_FMT ")",
amf_ue_ngap_id);
......
......@@ -147,22 +147,15 @@ class amf_n1 {
bool is_amf_ue_id_2_nas_context(const long& amf_ue_ngap_id) const;
/*
* Verify if a UE NAS context associated with an AMF UE NGAP ID exist
* Verify if a UE NAS context associated with an AMF UE NGAP ID exist and not
* null
* @param [const long& ] amf_ue_ngap_id: AMF UE NGAP ID
* @param [std::shared_ptr<nas_context>&] nc: pointer to UE NAS context
* @return true if UE NAS context exist, otherwise false
*/
bool is_amf_ue_id_2_nas_context(
bool amf_ue_id_2_nas_context(
const long& amf_ue_ngap_id, std::shared_ptr<nas_context>& nc) const;
/*
* Get UE NAS context associated with an AMF UE NGAP ID
* @param [const long& ] amf_ue_ngap_id: AMF UE NGAP ID
* @return shared pointer to the UE NAS context
*/
std::shared_ptr<nas_context> amf_ue_id_2_nas_context(
const long& amf_ue_ngap_id) const;
/*
* Store an UE NAS context associated with an AMF UE NGAP ID
* @param [const long& ] amf_ue_ngap_id: AMF UE NGAP ID
......
This diff is collapsed.
......@@ -224,14 +224,6 @@ class amf_n2 : public ngap::ngap_app {
bool get_common_NSSAI(
const uint32_t& ran_ue_ngap_id, std::vector<nas::SNSSAI_t>& common_nssai);
/*
* Get UE NGAP context associated with a RAN UE NGAP ID
* @param [const uint32_t&] ran_ue_ngap_id: RAN UE NGAP ID
* @return shared pointer to the UE NGAP context
*/
// std::shared_ptr<ue_ngap_context> ran_ue_id_2_ue_ngap_context(
// const uint32_t& ran_ue_ngap_id) const;
/*
* Verify whether a UE NGAP context associated with a RAN UE NGAP ID exist
* @param [const uint32_t&] ran_ue_ngap_id: RAN UE NGAP ID
......@@ -292,13 +284,13 @@ class amf_n2 : public ngap::ngap_app {
const unsigned long& amf_ue_ngap_id) const;
/*
* Verify whether a UE NGAP context associated with a AMF UE NGAP ID exist
* Get UE NGAP context associated with a AMF UE NGAP ID
* @param [const unsigned long&] amf_ue_ngap_id: AMF UE NGAP ID
* @param [std::shared_ptr<ue_ngap_context>&] unc: store the pointer to UE
* NGAP context
* @return true if exist, otherwise return false
* @return true if context exist and not null, otherwise return false
*/
bool is_amf_ue_id_2_ue_ngap_context(
bool amf_ue_id_2_ue_ngap_context(
const unsigned long& amf_ue_ngap_id,
std::shared_ptr<ue_ngap_context>& unc) const;
......
......@@ -278,7 +278,7 @@ void amf_sbi::handle_itti_message(itti_nsmf_pdusession_create_sm_context& smf) {
Logger::amf_sbi().debug("Handle ITTI SMF_PDU_SESSION_CREATE_SM_CTX");
std::shared_ptr<nas_context> nc = {};
if (!amf_n1_inst->is_amf_ue_id_2_nas_context(smf.amf_ue_ngap_id, nc)) {
if (!amf_n1_inst->amf_ue_id_2_nas_context(smf.amf_ue_ngap_id, nc)) {
Logger::amf_sbi().error(
"No UE NAS context with amf_ue_ngap_id (" AMF_UE_NGAP_ID_FMT ")",
smf.amf_ue_ngap_id);
......
......@@ -422,7 +422,7 @@ int ngap_amf_handle_pdu_session_resource_setup_response(
new itti_nsmf_pdusession_update_sm_context(TASK_NGAP, TASK_AMF_SBI);
long amf_ue_ngap_id = pdu_session_resource_setup_resp->getAmfUeNgapId();
std::shared_ptr<nas_context> nct = {};
if (!amf_n1_inst->is_amf_ue_id_2_nas_context(amf_ue_ngap_id, nct)) {
if (!amf_n1_inst->amf_ue_id_2_nas_context(amf_ue_ngap_id, nct)) {
Logger::ngap().error(
"No UE NAS context with amf_ue_ngap_id (0x%x)", amf_ue_ngap_id);
return RETURNerror;
......@@ -491,7 +491,7 @@ int ngap_amf_handle_pdu_session_resource_setup_response(
long amf_ue_ngap_id = pdu_session_resource_setup_resp->getAmfUeNgapId();
std::shared_ptr<nas_context> nct = {};
if (!amf_n1_inst->is_amf_ue_id_2_nas_context(amf_ue_ngap_id, nct)) {
if (!amf_n1_inst->amf_ue_id_2_nas_context(amf_ue_ngap_id, nct)) {
Logger::ngap().error(
"No UE NAS context with amf_ue_ngap_id (0x%x)", amf_ue_ngap_id);
return RETURNerror;
......
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