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

Merge branch 'fix_deregistration' into 'develop'

Fix deregistration

See merge request oai/cn5g/oai-cn5g-amf!101
parents 596cead1 1479b781
......@@ -872,6 +872,11 @@ void amf_app::trigger_nf_deregistration() {
}
}
void amf_app::add_promise(
uint32_t pid, boost::shared_ptr<boost::promise<uint32_t>>& p) {
std::unique_lock lock(m_curl_handle_responses_smf);
curl_handle_responses_smf.emplace(pid, p);
}
//---------------------------------------------------------------------------------------------
void amf_app::add_promise(
uint32_t id, boost::shared_ptr<boost::promise<std::string>>& p) {
......@@ -886,6 +891,18 @@ void amf_app::add_promise(
curl_handle_responses_n11.emplace(pid, p);
}
void amf_app::trigger_process_response(uint32_t pid, uint32_t http_code) {
Logger::amf_app().debug(
"Trigger process response: Set promise with ID %u "
"to ready",
pid);
std::unique_lock lock(m_curl_handle_responses_smf);
if (curl_handle_responses_smf.count(pid) > 0) {
curl_handle_responses_smf[pid]->set_value(http_code);
// Remove this promise from list
curl_handle_responses_smf.erase(pid);
}
}
//------------------------------------------------------------------------------
void amf_app::trigger_process_response(uint32_t pid, std::string n2_sm) {
Logger::amf_app().debug(
......
......@@ -83,6 +83,10 @@ class amf_app {
std::map<std::string, std::shared_ptr<ue_context>> supi2ue_ctx;
mutable std::shared_mutex m_supi2ue_ctx;
mutable std::shared_mutex m_curl_handle_responses_smf;
std::map<uint32_t, boost::shared_ptr<boost::promise<uint32_t>>>
curl_handle_responses_smf;
mutable std::shared_mutex m_curl_handle_responses_n2_sm;
std::map<uint32_t, boost::shared_ptr<boost::promise<std::string>>>
curl_handle_responses_n2_sm;
......
This diff is collapsed.
......@@ -148,6 +148,7 @@ class amf_n1 {
void set_amf_ue_ngap_id_2_nas_context(
const long& amf_ue_ngap_id, std::shared_ptr<nas_context> nc);
void remove_amf_ue_ngap_id_2_nas_context(const long& amf_ue_ngap_id);
// TODO
void run_registration_procedure(std::shared_ptr<nas_context>& nc);
......
......@@ -105,6 +105,14 @@ void amf_n11_task(void*) {
amf_n11_inst->handle_itti_message(ref(*m));
} break;
case NSMF_PDU_SESSION_RELEASE_SM_CTX: {
Logger::amf_n11().info(
"Receive Nsmf_PDUSessionReleaseSMContext, handling ...");
itti_nsmf_pdusession_release_sm_context* m =
dynamic_cast<itti_nsmf_pdusession_release_sm_context*>(msg);
amf_n11_inst->handle_itti_message(ref(*m));
} break;
case PDU_SESSION_RESOURCE_SETUP_RESPONSE: {
Logger::amf_n11().info(
"Receive PDU Session Resource Setup response, handling ...");
......@@ -550,6 +558,7 @@ void amf_n11::handle_itti_message(
string smf_addr = {};
std::string smf_api_version = {};
std::string remote_uri = {};
if (!psc.get()->smf_available) {
Logger::amf_n11().error("No SMF is available for this PDU session");
......@@ -558,24 +567,34 @@ void amf_n11::handle_itti_message(
smf_api_version = psc->smf_api_version;
}
string remote_uri = psc.get()->location + "release";
remote_uri = psc.get()->smf_context_location + "/release";
nlohmann::json pdu_session_release_request;
pdu_session_release_request["supi"] = itti_msg.supi.c_str();
pdu_session_release_request["dnn"] = psc.get()->dnn.c_str();
pdu_session_release_request["sNssai"]["sst"] =
1; // TODO: check hardcoded value
pdu_session_release_request["sNssai"]["sd"] =
"0"; // TODO: check hardcoded value
pdu_session_release_request["pduSessionId"] = psc.get()->pdu_session_id;
pdu_session_release_request["cause"] = "REL_DUE_TO_REACTIVATION";
pdu_session_release_request["ngApCause"] = "radioNetwork";
std::string json_part = pdu_session_release_request.dump();
uint8_t http_version = 1;
pdu_session_release_request["supi"] = itti_msg.supi.c_str();
pdu_session_release_request["dnn"] = psc.get()->dnn.c_str();
pdu_session_release_request["sNssai"]["sst"] = psc.get()->snssai.sST;
pdu_session_release_request["sNssai"]["sd"] = psc.get()->snssai.sD;
pdu_session_release_request["pduSessionId"] = psc.get()->pdu_session_id;
pdu_session_release_request["cause"] = "REL_DUE_TO_REACTIVATION"; // TODO:
pdu_session_release_request["ngApCause"] = "radioNetwork";
std::string msg_body = pdu_session_release_request.dump();
uint8_t http_version = 1;
if (amf_cfg.support_features.use_http2) http_version = 2;
nlohmann::json response_json = {};
uint32_t response_code = 0;
// curl_http_client(
// remote_uri, json_part, "", "", itti_msg.supi,
// psc.get()->pdu_session_id, http_version);
curl_http_client(
remote_uri, json_part, "", "", itti_msg.supi, psc.get()->pdu_session_id,
http_version);
remote_uri, "POST", msg_body, response_json, response_code, http_version);
// Notify to the result
if (itti_msg.promise_id > 0) {
amf_app_inst->trigger_process_response(itti_msg.promise_id, response_code);
return;
}
}
//------------------------------------------------------------------------------
......
......@@ -1338,6 +1338,7 @@ void amf_n2::handle_itti_message(itti_ue_context_release_complete& itti_msg) {
Logger::amf_n2().debug("Handle UE Context Release Complete ...");
unsigned long amf_ue_ngap_id = itti_msg.ueCtxRelCmpl->getAmfUeNgapId();
uint32_t ran_ue_ngap_id = itti_msg.ueCtxRelCmpl->getRanUeNgapId();
// Change UE status from CM-CONNECTED to CM-IDLE
std::shared_ptr<nas_context> nc;
if (amf_n1_inst->is_amf_ue_id_2_nas_context(amf_ue_ngap_id))
......@@ -1347,16 +1348,18 @@ void amf_n2::handle_itti_message(itti_ue_context_release_complete& itti_msg) {
"No existed nas_context with amf_ue_ngap_id(" AMF_UE_NGAP_ID_FMT ")",
amf_ue_ngap_id);
}
amf_n1_inst->set_5gcm_state(nc, CM_IDLE);
if (nc.get() != nullptr) {
amf_n1_inst->set_5gcm_state(nc, CM_IDLE);
// Start/reset the Mobile Reachable Timer
timer_id_t tid = itti_inst->timer_setup(
MOBILE_REACHABLE_TIMER_NO_EMERGENCY_SERVICES_MIN * 60, 0, TASK_AMF_N1,
TASK_AMF_MOBILE_REACHABLE_TIMER_EXPIRE, amf_ue_ngap_id);
Logger::amf_app().startup("Started mobile reachable timer (tid %d)", tid);
// Start/reset the Mobile Reachable Timer
timer_id_t tid = itti_inst->timer_setup(
MOBILE_REACHABLE_TIMER_NO_EMERGENCY_SERVICES_MIN * 60, 0, TASK_AMF_N1,
TASK_AMF_MOBILE_REACHABLE_TIMER_EXPIRE, amf_ue_ngap_id);
Logger::amf_app().startup("Started mobile reachable timer (tid %d)", tid);
amf_n1_inst->set_mobile_reachable_timer(nc, tid);
amf_n1_inst->set_mobile_reachable_timer_timeout(nc, false);
amf_n1_inst->set_mobile_reachable_timer(nc, tid);
amf_n1_inst->set_mobile_reachable_timer_timeout(nc, false);
}
// TODO: User Location Information IE
// TODO: Information on Recommended Cells & RAN Nodes for Paging IE
......@@ -2137,7 +2140,14 @@ void amf_n2::send_handover_preparation_failure(
bool amf_n2::is_ran_ue_id_2_ue_ngap_context(
const uint32_t& ran_ue_ngap_id) const {
std::shared_lock lock(m_ranid2uecontext);
return bool{ranid2uecontext.count(ran_ue_ngap_id) > 0};
if (ranid2uecontext.count(ran_ue_ngap_id) > 0) {
if (ranid2uecontext.at(ran_ue_ngap_id).get() != nullptr) {
return true;
}
}
return false;
// return bool{ranid2uecontext.count(ran_ue_ngap_id) > 0};
}
//------------------------------------------------------------------------------
......@@ -2165,7 +2175,13 @@ std::shared_ptr<ue_ngap_context> amf_n2::amf_ue_id_2_ue_ngap_context(
bool amf_n2::is_amf_ue_id_2_ue_ngap_context(
const unsigned long& amf_ue_ngap_id) const {
std::shared_lock lock(m_amfueid2uecontext);
return bool{amfueid2uecontext.count(amf_ue_ngap_id) > 0};
// return bool{amfueid2uecontext.count(amf_ue_ngap_id) > 0};
if (amfueid2uecontext.count(amf_ue_ngap_id) > 0) {
if (amfueid2uecontext.at(amf_ue_ngap_id).get() != nullptr) {
return true;
}
}
return false;
}
//------------------------------------------------------------------------------
......
......@@ -72,7 +72,10 @@ typedef enum {
PDU_SESSION_RESOURCE_SETUP_REQUEST,
PDU_SESSION_RESOURCE_MODIFY_REQUEST,
PDU_SESSION_RESOURCE_RELEASE_COMMAND,
PDU_SESSION_RESOURCE_SETUP_RESPONSE,
NSMF_PDU_SESSION_RELEASE_SM_CTX,
UE_CONTEXT_RELEASE_REQUEST,
UE_CONTEXT_RELEASE_COMMAND,
UE_CONTEXT_RELEASE_COMPLETE,
UE_RADIO_CAP_IND,
UL_NAS_DATA_IND, // task amf_n1 message id
......@@ -95,13 +98,10 @@ typedef enum {
SBI_NOTIFICATION_DATA,
SBI_NOTIFY_SUBSCRIBED_EVENT,
SBI_N1_MESSAGE_NOTIFICATION,
UE_CONTEXT_RELEASE_COMMAND,
NSMF_PDU_SESSION_RELEASE_SM_CTX,
HANDOVER_REQUIRED,
HANDOVER_REQUEST_ACK,
HANDOVER_NOTIFY,
UPLINK_RAN_STATUS_TRANSFER,
PDU_SESSION_RESOURCE_SETUP_RESPONSE,
PAGING,
TIME_OUT,
HEALTH_PING,
......
......@@ -117,13 +117,17 @@ class itti_nsmf_pdusession_release_sm_context : public itti_msg_n11 {
itti_nsmf_pdusession_release_sm_context(
const itti_nsmf_pdusession_release_sm_context& i)
: itti_msg_n11(i) {
supi = i.supi;
pdu_session_id = i.pdu_session_id;
supi = i.supi;
pdu_session_id = i.pdu_session_id;
promise_id = i.promise_id;
context_location = i.context_location;
}
public:
std::string supi;
uint8_t pdu_session_id;
uint32_t promise_id;
std::string context_location;
};
//-----------------------------------------------------------------------------
......
......@@ -45,11 +45,11 @@ _5GSDeregistrationType::_5GSDeregistrationType(uint8_t type) {
//------------------------------------------------------------------------------
_5GSDeregistrationType::_5GSDeregistrationType(
_5gs_deregistration_type_t type) {
u1.b = 0;
u1.bf.switch_off = type.switch_off;
u1.bf.dereg_required = type.dereg_required;
u1.bf.access_type = type.access_type;
u1.bf.iei = type.iei;
u1.b = 0;
u1.bf.switch_off = type.switch_off;
u1.bf.re_registration_required = type.re_registration_required;
u1.bf.access_type = type.access_type;
u1.bf.iei = type.iei;
}
//------------------------------------------------------------------------------
......@@ -57,19 +57,19 @@ _5GSDeregistrationType::~_5GSDeregistrationType() {}
//------------------------------------------------------------------------------
void _5GSDeregistrationType::set(_5gs_deregistration_type_t type) {
u1.b = 0;
u1.bf.switch_off = type.switch_off;
u1.bf.dereg_required = type.dereg_required;
u1.bf.access_type = type.access_type;
u1.bf.iei = type.iei;
u1.b = 0;
u1.bf.switch_off = type.switch_off;
u1.bf.re_registration_required = type.re_registration_required;
u1.bf.access_type = type.access_type;
u1.bf.iei = type.iei;
}
//------------------------------------------------------------------------------
void _5GSDeregistrationType::get(_5gs_deregistration_type_t& type) {
type.switch_off = u1.bf.switch_off;
type.dereg_required = u1.bf.dereg_required;
type.access_type = u1.bf.access_type;
type.iei = u1.bf.iei;
type.switch_off = u1.bf.switch_off;
type.re_registration_required = u1.bf.re_registration_required;
type.access_type = u1.bf.access_type;
type.iei = u1.bf.iei;
}
//------------------------------------------------------------------------------
......
......@@ -35,7 +35,7 @@ namespace nas {
typedef struct _5gs_deregistration_type_s {
uint8_t iei : 4;
uint8_t switch_off : 1;
uint8_t dereg_required : 1;
uint8_t re_registration_required : 1;
uint8_t access_type : 2;
} _5gs_deregistration_type_t;
......@@ -58,7 +58,7 @@ class _5GSDeregistrationType {
struct {
uint8_t iei : 4;
uint8_t switch_off : 1;
uint8_t dereg_required : 1;
uint8_t re_registration_required : 1;
uint8_t access_type : 2;
} bf;
uint8_t b;
......
......@@ -37,10 +37,10 @@ using namespace nas;
//------------------------------------------------------------------------------
DeregistrationRequest::DeregistrationRequest() {
plain_header = NULL;
ie_deregistrationtype = NULL;
ie_ngKSI = NULL;
ie_5gs_mobility_id = NULL;
plain_header = nullptr;
ie_deregistrationtype = nullptr;
ie_ngKSI = nullptr;
ie_5gs_mobility_id = nullptr;
}
//------------------------------------------------------------------------------
......@@ -72,13 +72,13 @@ void DeregistrationRequest::setngKSI(uint8_t tsc, uint8_t key_set_id) {
//------------------------------------------------------------------------------
void DeregistrationRequest::getDeregistrationType(uint8_t& dereg_type) {
ie_deregistrationtype->get(dereg_type);
if (ie_deregistrationtype) ie_deregistrationtype->get(dereg_type);
}
//------------------------------------------------------------------------------
void DeregistrationRequest::getDeregistrationType(
_5gs_deregistration_type_t& type) {
ie_deregistrationtype->get(type);
if (ie_deregistrationtype) ie_deregistrationtype->get(type);
}
//------------------------------------------------------------------------------
......@@ -99,8 +99,8 @@ void DeregistrationRequest::setSUCI_SUPI_format_IMSI(
uint8_t protection_sch_id, const string msin) {
if (protection_sch_id != NULL_SCHEME) {
Logger::nas_mm().error(
"encoding suci and supi format for imsi error, please choose right "
"interface");
"Encoding SUCI and SUPI format for IMSI error, please choose correct "
"protection scheme");
return;
} else {
ie_5gs_mobility_id =
......@@ -184,7 +184,7 @@ int DeregistrationRequest::encode2buffer(uint8_t* buf, int len) {
return 0;
}
} else {
Logger::nas_mm().error("Encoding IE Deregistrationt Type error");
Logger::nas_mm().error("Encoding IE Deregistration Type error");
return 0;
}
if (int size = ie_5gs_mobility_id->encode2buffer(
......
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