Commit badd6274 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

Code cleanup for periodic registration update

parent f9ffb813
......@@ -191,6 +191,16 @@ std::shared_ptr<ue_context> amf_app::ran_amf_id_2_ue_context(
return ue_ctx_key.at(ue_context_key);
}
bool amf_app::ran_amf_id_2_ue_context(
const std::string& ue_context_key, std::shared_ptr<ue_context>& uc) const {
std::shared_lock lock(m_ue_ctx_key);
if (ue_ctx_key.count(ue_context_key) > 0) {
uc = ue_ctx_key.at(ue_context_key);
if (uc.get() == nullptr) return false;
return true;
} else
return false;
}
//------------------------------------------------------------------------------
void amf_app::set_ran_amf_id_2_ue_context(
const string& ue_context_key, std::shared_ptr<ue_context> uc) {
......
......@@ -91,6 +91,10 @@ class amf_app {
bool is_ran_amf_id_2_ue_context(const std::string& ue_context_key) const;
std::shared_ptr<ue_context> ran_amf_id_2_ue_context(
const std::string& ue_context_key) const;
bool ran_amf_id_2_ue_context(
const std::string& ue_context_key, std::shared_ptr<ue_context>& uc) const;
void set_ran_amf_id_2_ue_context(
const std::string& ue_context_key, std::shared_ptr<ue_context> uc);
......
......@@ -226,27 +226,13 @@ void amf_n1::handle_itti_message(itti_downlink_nas_transfer& itti_msg) {
}
} else {
string ue_context_key = "app_ue_ranid_" + to_string(ran_ue_ngap_id) +
":amfid_" + to_string(amf_ue_ngap_id);
std::shared_ptr<ue_context> uc = {};
if (!amf_app_inst->is_ran_amf_id_2_ue_context(ue_context_key)) {
Logger::amf_n1().error(
"No UE context for %s exit", ue_context_key.c_str());
if (!find_ue_context(ran_ue_ngap_id, amf_ue_ngap_id, uc)) {
Logger::amf_n1().warn("Cannot find the UE context");
return;
}
std::shared_ptr<ue_context> uc = {};
uc = amf_app_inst->ran_amf_id_2_ue_context(ue_context_key);
if (uc.get() == nullptr) {
// TODO:
Logger::amf_n1().error(
"ue_context in amf_app using ran_amf_id (%s) does not existed!",
ue_context_key.c_str());
}
Logger::amf_n1().info(
"Found ue_context (%p) in amf_app using ran_amf_id (%s)", uc.get(),
ue_context_key.c_str());
if (uc.get()->isUeContextRequest) {
// PDU SESSION RESOURCE SETUP_REQUEST
itti_pdu_session_resource_setup_request* psrsr =
......@@ -682,14 +668,11 @@ void amf_n1::identity_response_handle(
void amf_n1::service_request_handle(
bool isNasSig, std::shared_ptr<nas_context> nc, uint32_t ran_ue_ngap_id,
long amf_ue_ngap_id, bstring nas) {
string ue_context_key = "app_ue_ranid_" + to_string(ran_ue_ngap_id) +
":amfid_" + to_string(amf_ue_ngap_id);
std::shared_ptr<ue_context> uc = {};
if (!amf_app_inst->is_ran_amf_id_2_ue_context(ue_context_key)) {
Logger::amf_n1().error("No UE context for %s exit", ue_context_key.c_str());
} else {
uc = amf_app_inst->ran_amf_id_2_ue_context(ue_context_key);
if (!find_ue_context(ran_ue_ngap_id, amf_ue_ngap_id, uc)) {
Logger::amf_n1().warn("Cannot find the UE context");
return;
}
if (!nc.get() or !uc.get()) {
......@@ -904,20 +887,13 @@ void amf_n1::registration_request_handle(
bdestroy(reg); // free buffer
// Find UE context
string ue_context_key = "app_ue_ranid_" + to_string(ran_ue_ngap_id) +
":amfid_" + to_string(amf_ue_ngap_id);
std::shared_ptr<ue_context> uc = {};
Logger::amf_n1().info(
"Try to find ue_context in amf_app using ran_amf_id (%s)",
ue_context_key.c_str());
if (!amf_app_inst->is_ran_amf_id_2_ue_context(ue_context_key)) {
Logger::amf_n1().error("No UE context for %s exit", ue_context_key.c_str());
if (!find_ue_context(ran_ue_ngap_id, amf_ue_ngap_id, uc)) {
Logger::amf_n1().warn("Cannot find the UE context");
return;
}
uc = amf_app_inst->ran_amf_id_2_ue_context(ue_context_key);
// Check 5gs Mobility Identity (Mandatory IE)
std::string guti;
uint8_t mobility_id_type = regReq->getMobilityIdentityType();
......@@ -2160,27 +2136,13 @@ int amf_n1::security_select_algorithms(
void amf_n1::security_mode_complete_handle(
uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring nas_msg) {
Logger::amf_n1().debug("Handling security mode complete ...");
string ue_context_key = "app_ue_ranid_" + to_string(ran_ue_ngap_id) +
":amfid_" + to_string(amf_ue_ngap_id);
std::shared_ptr<ue_context> uc;
if (!amf_app_inst->is_ran_amf_id_2_ue_context(ue_context_key)) {
Logger::amf_n1().error("No UE context for %s exit", ue_context_key.c_str());
return;
}
uc = amf_app_inst->ran_amf_id_2_ue_context(ue_context_key);
if (uc.get() == nullptr) {
// TODO:
Logger::amf_n1().error(
"ue_context in amf_app using ran_amf_id (%s) does not existed!",
ue_context_key.c_str());
std::shared_ptr<ue_context> uc = {};
if (!find_ue_context(ran_ue_ngap_id, amf_ue_ngap_id, uc)) {
Logger::amf_n1().warn("Cannot find the UE context");
return;
}
Logger::amf_n1().info(
"Found ue_context (%p) in amf_app using ran_amf_id (%s)", uc.get(),
ue_context_key.c_str());
// Encoding REGISTRATION ACCEPT
auto regAccept = std::make_unique<RegistrationAccept>();
initialize_registration_accept(regAccept);
......@@ -2805,24 +2767,14 @@ void amf_n1::run_mobility_registration_update_procedure(
// Encoding REGISTRATION ACCEPT
auto regAccept = std::make_unique<RegistrationAccept>();
initialize_registration_accept(regAccept);
regAccept->set_5GS_Network_Feature_Support(0x00, 0x00);
regAccept->set_5GS_Network_Feature_Support(
0x00, 0x00); // TODO: remove hardcoded values
string supi = "imsi-" + nc.get()->imsi;
Logger::amf_n1().debug("Key for PDU Session Context SUPI (%s)", supi.c_str());
std::shared_ptr<pdu_session_context> psc = {};
string ue_context_key = "app_ue_ranid_" + to_string(nc->ran_ue_ngap_id) +
":amfid_" + to_string(nc->amf_ue_ngap_id);
std::shared_ptr<ue_context> uc = {};
if (!amf_app_inst->is_ran_amf_id_2_ue_context(ue_context_key)) {
Logger::amf_n1().error("No UE context for %s exit", ue_context_key.c_str());
return;
}
uc = amf_app_inst->ran_amf_id_2_ue_context(ue_context_key);
if (uc.get() == nullptr) {
Logger::amf_n1().warn(
"Cannot find the UE context with key %s", ue_context_key.c_str());
if (!find_ue_context(nc, uc)) {
Logger::amf_n1().warn("Cannot find the UE context");
return;
}
......@@ -2879,7 +2831,7 @@ void amf_n1::run_mobility_registration_update_procedure(
itti_msg->amf_ue_ngap_id = nc.get()->amf_ue_ngap_id;
itti_msg->kgnb = kgnb_bs;
itti_msg->nas = protectedNas;
itti_msg->is_sr = true; // service request indicator
itti_msg->is_sr = true; // service request indicator, to be verified
if (psc.get() != nullptr) {
itti_msg->pdu_session_id = psc.get()->pdu_session_id;
......@@ -2904,22 +2856,11 @@ void amf_n1::run_periodic_registration_update_procedure(
auto regAccept = std::make_unique<RegistrationAccept>();
initialize_registration_accept(regAccept);
string supi = "imsi-" + nc.get()->imsi;
Logger::amf_n1().debug("Key for PDU Session Context SUPI (%s)", supi.c_str());
string ue_context_key = "app_ue_ranid_" + to_string(nc->ran_ue_ngap_id) +
":amfid_" + to_string(nc->amf_ue_ngap_id);
// amf_ue_context
std::shared_ptr<ue_context> uc = {};
if (!amf_app_inst->is_ran_amf_id_2_ue_context(ue_context_key)) {
Logger::amf_n1().error("No UE context for %s exit", ue_context_key.c_str());
return;
}
uc = amf_app_inst->ran_amf_id_2_ue_context(ue_context_key);
if (uc.get() == nullptr) {
Logger::amf_n1().warn(
"Cannot find the UE context with key %s", ue_context_key.c_str());
if (!find_ue_context(nc, uc)) {
Logger::amf_n1().warn("Cannot find the UE context");
return;
}
......@@ -2986,22 +2927,10 @@ void amf_n1::run_periodic_registration_update_procedure(
auto regAccept = std::make_unique<RegistrationAccept>();
initialize_registration_accept(regAccept);
string supi = "imsi-" + nc.get()->imsi;
Logger::amf_n1().debug("Key for PDU Session Context SUPI (%s)", supi.c_str());
string ue_context_key = "app_ue_ranid_" + to_string(nc->ran_ue_ngap_id) +
":amfid_" + to_string(nc->amf_ue_ngap_id);
std::shared_ptr<ue_context> uc = {};
if (!amf_app_inst->is_ran_amf_id_2_ue_context(ue_context_key)) {
Logger::amf_n1().error("No UE context for %s exit", ue_context_key.c_str());
return;
}
uc = amf_app_inst->ran_amf_id_2_ue_context(ue_context_key);
if (uc.get() == nullptr) {
Logger::amf_n1().warn(
"Cannot find the UE context with key %s", ue_context_key.c_str());
if (!find_ue_context(nc, uc)) {
Logger::amf_n1().warn("Cannot find the UE context");
return;
}
......@@ -3180,3 +3109,51 @@ void amf_n1::initialize_registration_accept(
registration_accept->setALLOWED_NSSAI(nssai);
return;
}
//------------------------------------------------------------------------------
bool amf_n1::find_ue_context(
const std::shared_ptr<nas_context>& nc, std::shared_ptr<ue_context>& uc) {
string supi = "imsi-" + nc.get()->imsi;
Logger::amf_n1().debug("Key for PDU Session Context SUPI (%s)", supi.c_str());
string ue_context_key = "app_ue_ranid_" + to_string(nc->ran_ue_ngap_id) +
":amfid_" + to_string(nc->amf_ue_ngap_id);
if (!amf_app_inst->is_ran_amf_id_2_ue_context(ue_context_key)) {
Logger::amf_n1().error("No UE context with key %s", ue_context_key.c_str());
return false;
}
uc = amf_app_inst->ran_amf_id_2_ue_context(ue_context_key);
if (uc.get() == nullptr) {
Logger::amf_n1().warn(
"Cannot find the UE context with key %s", ue_context_key.c_str());
return false;
}
return true;
}
//------------------------------------------------------------------------------
bool amf_n1::find_ue_context(
uint32_t ran_ue_ngap_id, long amf_ue_ngap_id,
std::shared_ptr<ue_context>& uc) {
string ue_context_key = "app_ue_ranid_" + to_string(ran_ue_ngap_id) +
":amfid_" + to_string(amf_ue_ngap_id);
if (!amf_app_inst->is_ran_amf_id_2_ue_context(ue_context_key)) {
Logger::amf_n1().error("No UE context with key %s", ue_context_key.c_str());
return false;
}
uc = amf_app_inst->ran_amf_id_2_ue_context(ue_context_key);
if (uc.get() == nullptr) {
Logger::amf_n1().warn(
"Cannot find the UE context with key %s", ue_context_key.c_str());
return false;
}
return true;
}
......@@ -46,6 +46,7 @@
#include "pdu_session_context.hpp"
#include "amf_event.hpp"
#include "RegistrationAccept.hpp"
#include "ue_context.hpp"
namespace amf_application {
......@@ -170,6 +171,13 @@ class amf_n1 {
void initialize_registration_accept(
std::unique_ptr<nas::RegistrationAccept>& registration_accept);
bool find_ue_context(
const std::shared_ptr<nas_context>& nc, std::shared_ptr<ue_context>& uc);
bool find_ue_context(
uint32_t ran_ue_ngap_id, long amf_ue_ngap_id,
std::shared_ptr<ue_context>& uc);
private:
void ue_initiate_de_registration_handle(
uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring nas);
......
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