Commit 63a4dc20 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

Code cleanup

parent 033c09f6
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
/*! \file amf_app.cpp /*! \file amf_app.cpp
\brief \brief
\author Keliang DU, BUPT \author Keliang DU, BUPT, Tien-Thinh NGUYEN, EURECOM
\date 2020 \date 2020
\email: contact@openairinterface.org \email: contact@openairinterface.org
*/ */
...@@ -162,7 +162,7 @@ std::shared_ptr<ue_context> amf_app::amf_ue_id_2_ue_context( ...@@ -162,7 +162,7 @@ std::shared_ptr<ue_context> amf_app::amf_ue_id_2_ue_context(
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_app::set_amf_ue_ngap_id_2_ue_context( void amf_app::set_amf_ue_ngap_id_2_ue_context(
const long& amf_ue_ngap_id, std::shared_ptr<ue_context> uc) { const long& amf_ue_ngap_id, std::shared_ptr<ue_context> uc) {
std::shared_lock lock(m_amf_ue_ngap_id2ue_ctx); std::unique_lock lock(m_amf_ue_ngap_id2ue_ctx);
amf_ue_ngap_id2ue_ctx[amf_ue_ngap_id] = uc; amf_ue_ngap_id2ue_ctx[amf_ue_ngap_id] = uc;
} }
...@@ -182,7 +182,7 @@ std::shared_ptr<ue_context> amf_app::ran_amf_id_2_ue_context( ...@@ -182,7 +182,7 @@ std::shared_ptr<ue_context> amf_app::ran_amf_id_2_ue_context(
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_app::set_ran_amf_id_2_ue_context( void amf_app::set_ran_amf_id_2_ue_context(
const string& ue_context_key, std::shared_ptr<ue_context> uc) { const string& ue_context_key, std::shared_ptr<ue_context> uc) {
std::shared_lock lock(m_ue_ctx_key); std::unique_lock lock(m_ue_ctx_key);
ue_ctx_key[ue_context_key] = uc; ue_ctx_key[ue_context_key] = uc;
} }
...@@ -202,14 +202,16 @@ std::shared_ptr<ue_context> amf_app::supi_2_ue_context( ...@@ -202,14 +202,16 @@ std::shared_ptr<ue_context> amf_app::supi_2_ue_context(
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_app::set_supi_2_ue_context( void amf_app::set_supi_2_ue_context(
const string& supi, std::shared_ptr<ue_context>& uc) { const string& supi, std::shared_ptr<ue_context>& uc) {
std::unique_lock lock(m_supi2ue_ctx); std::unique_lock lock(m_supi2ue_ctx);
supi2ue_ctx[supi] = uc; supi2ue_ctx[supi] = uc;
} }
bool amf_app::find_pdu_session_context(const string& supi, const std::uint8_t pdu_session_id, std::shared_ptr<pdu_session_context>& psc){ bool amf_app::find_pdu_session_context(
const string& supi, const std::uint8_t pdu_session_id,
std::shared_ptr<pdu_session_context>& psc) {
if (!is_supi_2_ue_context(supi)) return false; if (!is_supi_2_ue_context(supi)) return false;
std::shared_ptr<ue_context> uc = {}; std::shared_ptr<ue_context> uc = {};
uc = supi_2_ue_context(supi); uc = supi_2_ue_context(supi);
if (!uc.get()->find_pdu_session_context(pdu_session_id, psc)) return false; if (!uc.get()->find_pdu_session_context(pdu_session_id, psc)) return false;
return true; return true;
} }
...@@ -218,13 +220,14 @@ bool amf_app::find_pdu_session_context(const string& supi, const std::uint8_t pd ...@@ -218,13 +220,14 @@ bool amf_app::find_pdu_session_context(const string& supi, const std::uint8_t pd
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_app::handle_itti_message( void amf_app::handle_itti_message(
itti_n1n2_message_transfer_request& itti_msg) { itti_n1n2_message_transfer_request& itti_msg) {
// 1. encode DL NAS TRANSPORT message(NAS message) // Encode DL NAS TRANSPORT message(NAS message)
DLNASTransport* dl = new DLNASTransport(); DLNASTransport* dl = new DLNASTransport();
dl->setHeader(PLAIN_5GS_MSG); dl->setHeader(PLAIN_5GS_MSG);
dl->setPayload_Container_Type(N1_SM_INFORMATION); dl->setPayload_Container_Type(N1_SM_INFORMATION);
dl->setPayload_Container( dl->setPayload_Container(
(uint8_t*) bdata(itti_msg.n1sm), blength(itti_msg.n1sm)); (uint8_t*) bdata(itti_msg.n1sm), blength(itti_msg.n1sm));
dl->setPDUSessionId(itti_msg.pdu_session_id); dl->setPDUSessionId(itti_msg.pdu_session_id);
uint8_t nas[1024]; uint8_t nas[1024];
int encoded_size = dl->encode2buffer(nas, 1024); int encoded_size = dl->encode2buffer(nas, 1024);
print_buffer("amf_app", "n1n2 transfer", nas, encoded_size); print_buffer("amf_app", "n1n2 transfer", nas, encoded_size);
...@@ -256,28 +259,28 @@ void amf_app::handle_itti_message( ...@@ -256,28 +259,28 @@ void amf_app::handle_itti_message(
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_app::handle_itti_message( void amf_app::handle_itti_message(
itti_nas_signalling_establishment_request& itti_msg) { itti_nas_signalling_establishment_request& itti_msg) {
// 1. generate amf_ue_ngap_id // 1. Generate amf_ue_ngap_id
// 2. establish ue_context associated with amf_ue_ngap_id // 2. Create UE Context and store related information information
// 3. store ue-reated core information // 3. Send nas-pdu to task_amf_n1
// 4. send nas-pdu to task_amf_n1
long amf_ue_ngap_id = 0; long amf_ue_ngap_id = 0;
std::shared_ptr<ue_context> uc; std::shared_ptr<ue_context> uc;
// check ue context with 5g-s-tmsi
// check UE Context with 5g-s-tmsi
if ((amf_ue_ngap_id = itti_msg.amf_ue_ngap_id) == -1) { if ((amf_ue_ngap_id = itti_msg.amf_ue_ngap_id) == -1) {
amf_ue_ngap_id = generate_amf_ue_ngap_id(); amf_ue_ngap_id = generate_amf_ue_ngap_id();
} }
string ue_context_key = "app_ue_ranid_" + to_string(itti_msg.ran_ue_ngap_id) + string ue_context_key = "app_ue_ranid_" + to_string(itti_msg.ran_ue_ngap_id) +
":amfid_" + to_string(amf_ue_ngap_id); ":amfid_" + to_string(amf_ue_ngap_id);
// if(!is_amf_ue_id_2_ue_context(amf_ue_ngap_id)){
if (!is_ran_amf_id_2_ue_context(ue_context_key)) { if (!is_ran_amf_id_2_ue_context(ue_context_key)) {
Logger::amf_app().debug( Logger::amf_app().debug(
"No existing UE Context, Create a new one with ran_amf_id %s", "No existing UE Context, Create a new one with ran_amf_id %s",
ue_context_key.c_str()); ue_context_key.c_str());
uc = std::shared_ptr<ue_context>(new ue_context()); uc = std::shared_ptr<ue_context>(new ue_context());
// set_amf_ue_ngap_id_2_ue_context(amf_ue_ngap_id, uc);
set_ran_amf_id_2_ue_context(ue_context_key, uc); set_ran_amf_id_2_ue_context(ue_context_key, uc);
} }
if (uc.get() == nullptr) { if (uc.get() == nullptr) {
Logger::amf_app().error( Logger::amf_app().error(
"Failed to create ue_context with ran_amf_id %s", "Failed to create ue_context with ran_amf_id %s",
......
...@@ -126,7 +126,7 @@ void amf_n1::handle_itti_message(itti_downlink_nas_transfer& itti_msg) { ...@@ -126,7 +126,7 @@ void amf_n1::handle_itti_message(itti_downlink_nas_transfer& itti_msg) {
nc = amf_ue_id_2_nas_context(amf_ue_ngap_id); nc = amf_ue_id_2_nas_context(amf_ue_ngap_id);
else { else {
Logger::amf_n1().warn( Logger::amf_n1().warn(
"No existed nas_context with amf_ue_ngap_id(0x%x)", amf_ue_ngap_id); "No existed nas_context with amf_ue_ngap_id (0x%x)", amf_ue_ngap_id);
return; return;
} }
nas_secu_ctx* secu = nc.get()->security_ctx; nas_secu_ctx* secu = nc.get()->security_ctx;
...@@ -135,9 +135,10 @@ void amf_n1::handle_itti_message(itti_downlink_nas_transfer& itti_msg) { ...@@ -135,9 +135,10 @@ void amf_n1::handle_itti_message(itti_downlink_nas_transfer& itti_msg) {
secu, false, INTEGRITY_PROTECTED_AND_CIPHERED, NAS_MESSAGE_DOWNLINK, secu, false, INTEGRITY_PROTECTED_AND_CIPHERED, NAS_MESSAGE_DOWNLINK,
(uint8_t*) bdata(itti_msg.dl_nas), blength(itti_msg.dl_nas), (uint8_t*) bdata(itti_msg.dl_nas), blength(itti_msg.dl_nas),
protected_nas); protected_nas);
if (itti_msg.is_n2sm_set) { if (itti_msg.is_n2sm_set) {
if (itti_msg.n2sm_info_type.compare("PDU_RES_REL_CMD") == if (itti_msg.n2sm_info_type.compare("PDU_RES_REL_CMD") == 0) {
0) { // PDU SESSION RESOURCE RELEASE COMMAND // PDU SESSION RESOURCE RELEASE COMMAND
itti_pdu_session_resource_release_command* release_command = itti_pdu_session_resource_release_command* release_command =
new itti_pdu_session_resource_release_command( new itti_pdu_session_resource_release_command(
TASK_AMF_N1, TASK_AMF_N2); TASK_AMF_N1, TASK_AMF_N2);
...@@ -155,7 +156,8 @@ void amf_n1::handle_itti_message(itti_downlink_nas_transfer& itti_msg) { ...@@ -155,7 +156,8 @@ void amf_n1::handle_itti_message(itti_downlink_nas_transfer& itti_msg) {
"Could not send ITTI message %s to task TASK_AMF_N2", "Could not send ITTI message %s to task TASK_AMF_N2",
i->get_msg_name()); i->get_msg_name());
} }
} else { // PDU SESSION RESOURCE SETUP_REQUEST } else {
// PDU SESSION RESOURCE SETUP_REQUEST
itti_pdu_session_resource_setup_request* psrsr = itti_pdu_session_resource_setup_request* psrsr =
new itti_pdu_session_resource_setup_request(TASK_AMF_N1, TASK_AMF_N2); new itti_pdu_session_resource_setup_request(TASK_AMF_N1, TASK_AMF_N2);
psrsr->nas = protected_nas; psrsr->nas = protected_nas;
...@@ -194,9 +196,11 @@ void amf_n1::handle_itti_message(itti_downlink_nas_transfer& itti_msg) { ...@@ -194,9 +196,11 @@ void amf_n1::handle_itti_message(itti_downlink_nas_transfer& itti_msg) {
void amf_n1::handle_itti_message(itti_uplink_nas_data_ind& nas_data_ind) { void amf_n1::handle_itti_message(itti_uplink_nas_data_ind& nas_data_ind) {
long amf_ue_ngap_id = nas_data_ind.amf_ue_ngap_id; long amf_ue_ngap_id = nas_data_ind.amf_ue_ngap_id;
uint32_t ran_ue_ngap_id = nas_data_ind.ran_ue_ngap_id; uint32_t ran_ue_ngap_id = nas_data_ind.ran_ue_ngap_id;
std::string nas_context_key = std::string nas_context_key =
"app_ue_ranid_" + to_string(ran_ue_ngap_id) + ":amfid_" + "app_ue_ranid_" + to_string(ran_ue_ngap_id) + ":amfid_" +
to_string(amf_ue_ngap_id); // key for nas_context, option 1 to_string(amf_ue_ngap_id); // key for nas_context, option 1
std::string snn; std::string snn;
if (nas_data_ind.mnc.length() == 2) // TODO: remove hardcoded value if (nas_data_ind.mnc.length() == 2) // TODO: remove hardcoded value
snn = "5G:mnc0" + nas_data_ind.mnc + ".mcc" + nas_data_ind.mcc + snn = "5G:mnc0" + nas_data_ind.mnc + ".mcc" + nas_data_ind.mcc +
...@@ -205,6 +209,7 @@ void amf_n1::handle_itti_message(itti_uplink_nas_data_ind& nas_data_ind) { ...@@ -205,6 +209,7 @@ void amf_n1::handle_itti_message(itti_uplink_nas_data_ind& nas_data_ind) {
snn = "5G:mnc" + nas_data_ind.mnc + ".mcc" + nas_data_ind.mcc + snn = "5G:mnc" + nas_data_ind.mnc + ".mcc" + nas_data_ind.mcc +
".3gppnetwork.org"; ".3gppnetwork.org";
Logger::amf_n1().debug("Serving network name %s", snn.c_str()); Logger::amf_n1().debug("Serving network name %s", snn.c_str());
plmn_t plmn = {}; plmn_t plmn = {};
plmn.mnc = nas_data_ind.mnc; plmn.mnc = nas_data_ind.mnc;
plmn.mcc = nas_data_ind.mcc; plmn.mcc = nas_data_ind.mcc;
...@@ -235,12 +240,15 @@ void amf_n1::handle_itti_message(itti_uplink_nas_data_ind& nas_data_ind) { ...@@ -235,12 +240,15 @@ void amf_n1::handle_itti_message(itti_uplink_nas_data_ind& nas_data_ind) {
Logger::amf_n1().error("Not 5GS MOBILITY MANAGEMENT message"); Logger::amf_n1().error("Not 5GS MOBILITY MANAGEMENT message");
return; return;
} }
uint8_t ulCount = 0; uint8_t ulCount = 0;
switch (type) { switch (type) {
case PlainNasMsg: { case PlainNasMsg: {
Logger::amf_n1().debug("Received plain NAS message"); Logger::amf_n1().debug("Received plain NAS message");
decoded_plain_msg = recved_nas_msg; decoded_plain_msg = recved_nas_msg;
} break; } break;
case IntegrityProtected: { case IntegrityProtected: {
Logger::amf_n1().debug("Received integrity protected NAS message"); Logger::amf_n1().debug("Received integrity protected NAS message");
ulCount = *((uint8_t*) bdata(recved_nas_msg) + 6); ulCount = *((uint8_t*) bdata(recved_nas_msg) + 6);
...@@ -249,6 +257,7 @@ void amf_n1::handle_itti_message(itti_uplink_nas_data_ind& nas_data_ind) { ...@@ -249,6 +257,7 @@ void amf_n1::handle_itti_message(itti_uplink_nas_data_ind& nas_data_ind) {
decoded_plain_msg = blk2bstr( decoded_plain_msg = blk2bstr(
(uint8_t*) bdata(recved_nas_msg) + 7, blength(recved_nas_msg) - 7); (uint8_t*) bdata(recved_nas_msg) + 7, blength(recved_nas_msg) - 7);
} break; } break;
case IntegrityProtectedAndCiphered: { case IntegrityProtectedAndCiphered: {
Logger::amf_n1().debug( Logger::amf_n1().debug(
"Received integrity protected and ciphered NAS message"); "Received integrity protected and ciphered NAS message");
...@@ -266,6 +275,7 @@ void amf_n1::handle_itti_message(itti_uplink_nas_data_ind& nas_data_ind) { ...@@ -266,6 +275,7 @@ void amf_n1::handle_itti_message(itti_uplink_nas_data_ind& nas_data_ind) {
"Abnormal condition: no existed nas_context. exit..."); "Abnormal condition: no existed nas_context. exit...");
return; return;
} }
uint32_t mac32 = 0; uint32_t mac32 = 0;
if (!nas_message_integrity_protected( if (!nas_message_integrity_protected(
nc.get()->security_ctx, NAS_MESSAGE_UPLINK, nc.get()->security_ctx, NAS_MESSAGE_UPLINK,
...@@ -299,11 +309,14 @@ void amf_n1::handle_itti_message(itti_uplink_nas_data_ind& nas_data_ind) { ...@@ -299,11 +309,14 @@ void amf_n1::handle_itti_message(itti_uplink_nas_data_ind& nas_data_ind) {
} }
} }
} break; } break;
default: {
Logger::amf_n1().error("unknown NAS msg type");
return;
}
} }
if (nas_data_ind.is_nas_signalling_estab_req) { if (nas_data_ind.is_nas_signalling_estab_req) {
Logger::amf_n1().debug("Received NAS signalling establishment request..."); Logger::amf_n1().debug("Received NAS signalling establishment request...");
// dump_nas_message((uint8_t*)bdata(decoded_plain_msg),
// blength(decoded_plain_msg));
print_buffer( print_buffer(
"amf_n1", "Decoded plain NAS Message buffer", "amf_n1", "Decoded plain NAS Message buffer",
(uint8_t*) bdata(decoded_plain_msg), blength(decoded_plain_msg)); (uint8_t*) bdata(decoded_plain_msg), blength(decoded_plain_msg));
...@@ -327,7 +340,7 @@ void amf_n1::nas_signalling_establishment_request_handle( ...@@ -327,7 +340,7 @@ void amf_n1::nas_signalling_establishment_request_handle(
SecurityHeaderType type, std::shared_ptr<nas_context> nc, SecurityHeaderType type, std::shared_ptr<nas_context> nc,
uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring plain_msg, uint32_t ran_ue_ngap_id, long amf_ue_ngap_id, bstring plain_msg,
std::string snn, uint8_t ulCount) { std::string snn, uint8_t ulCount) {
// 1. Create nas context, or update nas context // Create NAS Context, or Update if existed
if ((nc.get() == nullptr) && (type == PlainNasMsg)) { if ((nc.get() == nullptr) && (type == PlainNasMsg)) {
Logger::amf_n1().debug( Logger::amf_n1().debug(
"No existing nas_context with amf_ue_ngap_id 0x%x --> Create a new one", "No existing nas_context with amf_ue_ngap_id 0x%x --> Create a new one",
...@@ -355,6 +368,7 @@ void amf_n1::nas_signalling_establishment_request_handle( ...@@ -355,6 +368,7 @@ void amf_n1::nas_signalling_establishment_request_handle(
uint8_t* buf = (uint8_t*) bdata(plain_msg); uint8_t* buf = (uint8_t*) bdata(plain_msg);
uint8_t message_type = *(buf + 2); uint8_t message_type = *(buf + 2);
Logger::amf_n1().debug("NAS message type 0x%x", message_type); Logger::amf_n1().debug("NAS message type 0x%x", message_type);
switch (message_type) { switch (message_type) {
case REGISTRATION_REQUEST: { case REGISTRATION_REQUEST: {
Logger::amf_n1().debug( Logger::amf_n1().debug(
...@@ -362,19 +376,22 @@ void amf_n1::nas_signalling_establishment_request_handle( ...@@ -362,19 +376,22 @@ void amf_n1::nas_signalling_establishment_request_handle(
registration_request_handle( registration_request_handle(
true, nc, ran_ue_ngap_id, amf_ue_ngap_id, snn, plain_msg); true, nc, ran_ue_ngap_id, amf_ue_ngap_id, snn, plain_msg);
} break; } break;
case SERVICE_REQUEST: { case SERVICE_REQUEST: {
Logger::amf_n1().debug("Received service request message, handling..."); Logger::amf_n1().debug("Received service request message, handling...");
nc.get()->security_ctx->ul_count.seq_num = ulCount; nc.get()->security_ctx->ul_count.seq_num = ulCount;
service_request_handle( service_request_handle(
true, nc, ran_ue_ngap_id, amf_ue_ngap_id, plain_msg); true, nc, ran_ue_ngap_id, amf_ue_ngap_id, plain_msg);
} break; } break;
case UE_INIT_DEREGISTER: { case UE_INIT_DEREGISTER: {
Logger::amf_n1().debug( Logger::amf_n1().debug(
"received initialUeMessage de-registration request messgae , handle " "Received initialUeMessage de-registration request message, "
"..."); "handling...");
// ue_initiate_de_registration_handle(ran_ue_ngap_id, amf_ue_ngap_id, // ue_initiate_de_registration_handle(ran_ue_ngap_id, amf_ue_ngap_id,
// plain_msg); // plain_msg);
} break; } break;
default: default:
Logger::amf_n1().error("No handler for NAS message 0x%x", message_type); Logger::amf_n1().error("No handler for NAS message 0x%x", message_type);
} }
...@@ -598,19 +615,20 @@ void amf_n1::service_request_handle( ...@@ -598,19 +615,20 @@ void amf_n1::service_request_handle(
"amf_ue_ngap_id %d, ran_ue_ngap_id %d", amf_ue_ngap_id, ran_ue_ngap_id); "amf_ue_ngap_id %d, ran_ue_ngap_id %d", amf_ue_ngap_id, ran_ue_ngap_id);
Logger::amf_n1().debug("Key for pdu session context: SUPI %s", supi.c_str()); Logger::amf_n1().debug("Key for pdu session context: SUPI %s", supi.c_str());
std::shared_ptr<pdu_session_context> psc; std::shared_ptr<pdu_session_context> psc;
/* /*
//TODO: get the pdu_session_context from AMF_APP based on both SUPI and PDU Session ID //TODO: get the pdu_session_context from AMF_APP based on both SUPI and PDU
string ue_context_key = "app_ue_ranid_" + to_string(ran_ue_ngap_id) + Session ID string ue_context_key = "app_ue_ranid_" +
":amfid_" + to_string(amf_ue_ngap_id); to_string(ran_ue_ngap_id) +
std::shared_ptr<ue_context> uc; ":amfid_" + to_string(amf_ue_ngap_id);
std::shared_ptr<ue_context> uc;
uc = amf_app_inst->ran_amf_id_2_ue_context(ue_context_key); uc = amf_app_inst->ran_amf_id_2_ue_context(ue_context_key);
if (uc.get() !=nullptr){ if (uc.get() !=nullptr){
if (!uc.get()->find_pdu_session_context(pdu_session_id,psc)) { if (!uc.get()->find_pdu_session_context(pdu_session_id,psc)) {
} }
} }
//TO check: in which condition we should have PDU Session ID //TO check: in which condition we should have PDU Session ID
*/ */
if (amf_n11_inst->is_supi_to_pdu_ctx(supi)) { if (amf_n11_inst->is_supi_to_pdu_ctx(supi)) {
psc = amf_n11_inst->supi_to_pdu_ctx(supi); psc = amf_n11_inst->supi_to_pdu_ctx(supi);
...@@ -717,7 +735,8 @@ void amf_n1::registration_request_handle( ...@@ -717,7 +735,8 @@ void amf_n1::registration_request_handle(
RegistrationRequest* regReq = new RegistrationRequest(); RegistrationRequest* regReq = new RegistrationRequest();
regReq->decodefrombuffer(nullptr, (uint8_t*) bdata(reg), blength(reg)); regReq->decodefrombuffer(nullptr, (uint8_t*) bdata(reg), blength(reg));
bdestroy(reg); // free buffer bdestroy(reg); // free buffer
//find UE context
// Find UE context
string ue_context_key = "app_ue_ranid_" + to_string(ran_ue_ngap_id) + string ue_context_key = "app_ue_ranid_" + to_string(ran_ue_ngap_id) +
":amfid_" + to_string(amf_ue_ngap_id); ":amfid_" + to_string(amf_ue_ngap_id);
std::shared_ptr<ue_context> uc; std::shared_ptr<ue_context> uc;
...@@ -779,31 +798,13 @@ void amf_n1::registration_request_handle( ...@@ -779,31 +798,13 @@ void amf_n1::registration_request_handle(
stacs.update_ue_info(ueItem); stacs.update_ue_info(ueItem);
set_5gmm_state(nc, _5GMM_COMMON_PROCEDURE_INITIATED); set_5gmm_state(nc, _5GMM_COMMON_PROCEDURE_INITIATED);
nc.get()->is_stacs_available = true; nc.get()->is_stacs_available = true;
/* }
bool add_new_ue = true;
for(int i=0; i< stacs.ues.size(); i++){
if(!stacs.ues[i].imsi.compare(nc.get()->imsi)){
stacs.ues[i].connStatus = ueItem.connStatus;
stacs.ues[i].registerStatus = ueItem.registerStatus;
stacs.ues[i].ranid = ueItem.ranid;
stacs.ues[i].amfid = ueItem.amfid;
stacs.ues[i].guti = ueItem.guti;
stacs.ues[i].mcc = ueItem.mcc;
stacs.ues[i].mnc = ueItem.mnc;
stacs.ues[i].cellId = ueItem.cellId;
add_new_ue = false;
break;
}
}
if(add_new_ue)
stacs.ues.push_back(ueItem);
*/}
// nc.get()->imsi = //need interface to transfer SUCI_imsi_t to string
} }
} break; } break;
case _5G_GUTI: { case _5G_GUTI: {
guti = regReq->get_5g_guti(); guti = regReq->get_5g_guti();
Logger::amf_n1().debug("Decoded GUTI from registeration request message"); Logger::amf_n1().debug("Decoded GUTI from registration request message");
if (!guti.compare("error")) { if (!guti.compare("error")) {
Logger::amf_n1().warn("No GUTI IE"); Logger::amf_n1().warn("No GUTI IE");
} }
...@@ -847,6 +848,10 @@ void amf_n1::registration_request_handle( ...@@ -847,6 +848,10 @@ void amf_n1::registration_request_handle(
// supi2ranId[("imsi-"+nc.get()->imsi)] = ran_ue_ngap_id; // supi2ranId[("imsi-"+nc.get()->imsi)] = ran_ue_ngap_id;
} }
} break; } break;
default: {
Logger::amf_n1().warn("Unknown UE Mobility Identity");
}
} }
// Create NAS context // Create NAS context
...@@ -883,12 +888,12 @@ void amf_n1::registration_request_handle( ...@@ -883,12 +888,12 @@ void amf_n1::registration_request_handle(
nc.get()->amf_ue_ngap_id = amf_ue_ngap_id; nc.get()->amf_ue_ngap_id = amf_ue_ngap_id;
nc.get()->serving_network = snn; nc.get()->serving_network = snn;
// update UE conext // Update UE conext
if (uc.get() != nullptr) { if (uc.get() != nullptr) {
std::string supi = "imsi-" + nc.get()->imsi; std::string supi = "imsi-" + nc.get()->imsi;
uc.get()->supi = supi; uc.get()->supi = supi;
//associate SUPI with UC // associate SUPI with UC
amf_app_inst->set_supi_2_ue_context(supi, uc); amf_app_inst->set_supi_2_ue_context(supi, uc);
} }
// Check 5GS_Registration_type IE (Mandatory IE) // Check 5GS_Registration_type IE (Mandatory IE)
...@@ -916,7 +921,7 @@ void amf_n1::registration_request_handle( ...@@ -916,7 +921,7 @@ void amf_n1::registration_request_handle(
} }
nc.get()->ngKsi = ngKSI; nc.get()->ngKsi = ngKSI;
// Get non-current native nas key set identity (Optional IE), used for // Get non-current native NAS key set identity (Optional IE), used for
// inter-system change from S1 to N1 Get 5GMM Capability IE (optional), not // inter-system change from S1 to N1 Get 5GMM Capability IE (optional), not
// included for periodic registration updating procedure // included for periodic registration updating procedure
uint8_t _5g_mm_cap = regReq->get5GMMCapability(); uint8_t _5g_mm_cap = regReq->get5GMMCapability();
...@@ -957,24 +962,32 @@ void amf_n1::registration_request_handle( ...@@ -957,24 +962,32 @@ void amf_n1::registration_request_handle(
run_initial_registration_procedure(); // IEs? run_initial_registration_procedure(); // IEs?
run_registration_procedure(nc); run_registration_procedure(nc);
} break; } break;
case MOBILITY_REGISTRATION_UPDATING: { case MOBILITY_REGISTRATION_UPDATING: {
Logger::amf_n1().error("Network handling mobility registration ..."); Logger::amf_n1().error("Network handling mobility registration ...");
run_mobility_registration_update_procedure(nc); run_mobility_registration_update_procedure(nc);
} break; } break;
case PERIODIC_REGISTRATION_UPDATING: { case PERIODIC_REGISTRATION_UPDATING: {
Logger::amf_n1().error( Logger::amf_n1().error(
"Network doesn't support periodic registration, reject ..."); "Network does not support periodic registration, reject ...");
} break; } break;
case EMERGENCY_REGISTRATION: { case EMERGENCY_REGISTRATION: {
if (!amf_cfg.is_emergency_support.compare("false")) { if (!amf_cfg.is_emergency_support.compare("false")) {
Logger::amf_n1().error( Logger::amf_n1().error(
"Network doesn't support emergency registration, reject ..."); "Network does not support emergency registration, reject ...");
response_registration_reject_msg( response_registration_reject_msg(
_5GMM_CAUSE_ILLEGAL_UE, ran_ue_ngap_id, _5GMM_CAUSE_ILLEGAL_UE, ran_ue_ngap_id,
amf_ue_ngap_id); // cause? amf_ue_ngap_id); // cause?
return; return;
} }
} break; } break;
default :{
Logger::amf_n1().error("Unknown registration type ...");
//TODO:
return;
}
} }
} }
...@@ -2357,15 +2370,16 @@ void amf_n1::run_mobility_registration_update_procedure( ...@@ -2357,15 +2370,16 @@ void amf_n1::run_mobility_registration_update_procedure(
Logger::amf_n1().debug("Key for pdu session context SUPI (%s)", supi.c_str()); Logger::amf_n1().debug("Key for pdu session context SUPI (%s)", supi.c_str());
std::shared_ptr<pdu_session_context> psc; std::shared_ptr<pdu_session_context> psc;
/* /*
//TODO: get the pdu_session_context from AMF_APP based on both SUPI and PDU Session ID //TODO: get the pdu_session_context from AMF_APP based on both SUPI and PDU
string ue_context_key = "app_ue_ranid_" + to_string(ran_ue_ngap_id) + Session ID string ue_context_key = "app_ue_ranid_" +
to_string(ran_ue_ngap_id) +
":amfid_" + to_string(amf_ue_ngap_id); ":amfid_" + to_string(amf_ue_ngap_id);
std::shared_ptr<ue_context> uc; std::shared_ptr<ue_context> uc;
uc = amf_app_inst->ran_amf_id_2_ue_context(ue_context_key); uc = amf_app_inst->ran_amf_id_2_ue_context(ue_context_key);
if (uc.get() !=nullptr){ if (uc.get() !=nullptr){
if (!uc.get()->find_pdu_session_context()) { if (!uc.get()->find_pdu_session_context()) {
} }
} }
//TO check: in which condition we should have PDU Session ID //TO check: in which condition we should have PDU Session ID
*/ */
......
...@@ -427,8 +427,8 @@ void amf_n11::handle_pdu_session_initial_request( ...@@ -427,8 +427,8 @@ void amf_n11::handle_pdu_session_initial_request(
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void amf_n11::handle_itti_message( void amf_n11::handle_itti_message(
itti_nsmf_pdusession_release_sm_context& itti_msg) { itti_nsmf_pdusession_release_sm_context& itti_msg) {
//TTN: Should be replace by new mechanism to support multiple PDU sessions // TTN: Should be replace by new mechanism to support multiple PDU sessions
//Need PDU session ID // Need PDU session ID
std::shared_ptr<pdu_session_context> psc = supi_to_pdu_ctx(itti_msg.supi); std::shared_ptr<pdu_session_context> psc = supi_to_pdu_ctx(itti_msg.supi);
string smf_addr; string smf_addr;
std::string smf_api_version; std::string smf_api_version;
...@@ -530,21 +530,21 @@ void amf_n11::curl_http_client( ...@@ -530,21 +530,21 @@ void amf_n11::curl_http_client(
std::string body; std::string body;
std::shared_ptr<pdu_session_context> psc; std::shared_ptr<pdu_session_context> psc;
//TTN: Should be replace by new mechanism to support multiple PDU sessions // TTN: Should be replace by new mechanism to support multiple PDU sessions
if (!amf_app_inst->find_pdu_session_context(supi,pdu_session_id, psc)) { if (!amf_app_inst->find_pdu_session_context(supi, pdu_session_id, psc)) {
Logger::amf_n11().warn(
"PDU Session context for SUPI %s doesn't exit!", supi.c_str());
//TODO:
}
/*
if (is_supi_to_pdu_ctx(supi)) {
psc = supi_to_pdu_ctx(supi);
} else {
Logger::amf_n11().warn( Logger::amf_n11().warn(
"PDU Session context for SUPI %s doesn't exit!", supi.c_str()); "PDU Session context for SUPI %s doesn't exit!", supi.c_str());
// TODO: // TODO:
} }
*/ /*
if (is_supi_to_pdu_ctx(supi)) {
psc = supi_to_pdu_ctx(supi);
} else {
Logger::amf_n11().warn(
"PDU Session context for SUPI %s doesn't exit!", supi.c_str());
// TODO:
}
*/
if ((n1SmMsg.size() > 0) and (n2SmMsg.size() > 0)) { if ((n1SmMsg.size() > 0) and (n2SmMsg.size() > 0)) {
// prepare the body content for Curl // prepare the body content for Curl
......
...@@ -349,7 +349,7 @@ void amf_n2::handle_itti_message(itti_initial_ue_message& init_ue_msg) { ...@@ -349,7 +349,7 @@ void amf_n2::handle_itti_message(itti_initial_ue_message& init_ue_msg) {
// gNB, for example, here RAN UE NGAP ID and location information and RRC // gNB, for example, here RAN UE NGAP ID and location information and RRC
// Establishment Cause send NAS-PDU to NAS layer Get INITIAL_UE_MESSAGE IEs // Establishment Cause send NAS-PDU to NAS layer Get INITIAL_UE_MESSAGE IEs
// check the gNB context on which this UE is attached with assoc_id // Check the gNB context on which this UE is attached with assoc_id
itti_nas_signalling_establishment_request* itti_msg = itti_nas_signalling_establishment_request* itti_msg =
new itti_nas_signalling_establishment_request(TASK_AMF_N2, TASK_AMF_APP); new itti_nas_signalling_establishment_request(TASK_AMF_N2, TASK_AMF_APP);
...@@ -358,6 +358,7 @@ void amf_n2::handle_itti_message(itti_initial_ue_message& init_ue_msg) { ...@@ -358,6 +358,7 @@ void amf_n2::handle_itti_message(itti_initial_ue_message& init_ue_msg) {
"No existing gNG context with assoc_id (%d)", init_ue_msg.assoc_id); "No existing gNG context with assoc_id (%d)", init_ue_msg.assoc_id);
return; return;
} }
std::shared_ptr<gnb_context> gc; std::shared_ptr<gnb_context> gc;
gc = assoc_id_2_gnb_context(init_ue_msg.assoc_id); gc = assoc_id_2_gnb_context(init_ue_msg.assoc_id);
if (gc.get()->ng_state == NGAP_RESETING || if (gc.get()->ng_state == NGAP_RESETING ||
...@@ -378,6 +379,7 @@ void amf_n2::handle_itti_message(itti_initial_ue_message& init_ue_msg) { ...@@ -378,6 +379,7 @@ void amf_n2::handle_itti_message(itti_initial_ue_message& init_ue_msg) {
Logger::amf_n2().error("Missing Mandatory IE (RanUeNgapId)"); Logger::amf_n2().error("Missing Mandatory IE (RanUeNgapId)");
return; return;
} }
std::shared_ptr<ue_ngap_context> unc; std::shared_ptr<ue_ngap_context> unc;
if (!is_ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id)) { if (!is_ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id)) {
Logger::amf_n2().debug( Logger::amf_n2().debug(
...@@ -388,11 +390,12 @@ void amf_n2::handle_itti_message(itti_initial_ue_message& init_ue_msg) { ...@@ -388,11 +390,12 @@ void amf_n2::handle_itti_message(itti_initial_ue_message& init_ue_msg) {
} else { } else {
unc = ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id); unc = ran_ue_id_2_ue_ngap_context(ran_ue_ngap_id);
} }
if (unc.get() == nullptr) { if (unc.get() == nullptr) {
Logger::amf_n2().error( Logger::amf_n2().error(
"Failed to get UE NGAP context for ran_ue_ngap_id 0x%x", 21); "Failed to get UE NGAP context for ran_ue_ngap_id 0x%x", 21);
} else { } else {
// store information into UE NGAP context // Store related information into UE NGAP context
unc.get()->ran_ue_ngap_id = ran_ue_ngap_id; unc.get()->ran_ue_ngap_id = ran_ue_ngap_id;
unc.get()->sctp_stream_recv = init_ue_msg.stream; unc.get()->sctp_stream_recv = init_ue_msg.stream;
unc.get()->sctp_stream_send == gc.get()->next_sctp_stream; unc.get()->sctp_stream_send == gc.get()->next_sctp_stream;
...@@ -402,6 +405,7 @@ void amf_n2::handle_itti_message(itti_initial_ue_message& init_ue_msg) { ...@@ -402,6 +405,7 @@ void amf_n2::handle_itti_message(itti_initial_ue_message& init_ue_msg) {
unc.get()->gnb_assoc_id = init_ue_msg.assoc_id; unc.get()->gnb_assoc_id = init_ue_msg.assoc_id;
NrCgi_t cgi; NrCgi_t cgi;
Tai_t tai; Tai_t tai;
if (init_ue_msg.initUeMsg->getUserLocationInfoNR(cgi, tai)) { if (init_ue_msg.initUeMsg->getUserLocationInfoNR(cgi, tai)) {
itti_msg->cgi = cgi; itti_msg->cgi = cgi;
itti_msg->tai = tai; itti_msg->tai = tai;
...@@ -409,12 +413,14 @@ void amf_n2::handle_itti_message(itti_initial_ue_message& init_ue_msg) { ...@@ -409,12 +413,14 @@ void amf_n2::handle_itti_message(itti_initial_ue_message& init_ue_msg) {
Logger::amf_n2().error("Missing Mandatory IE UserLocationInfoNR"); Logger::amf_n2().error("Missing Mandatory IE UserLocationInfoNR");
return; return;
} }
if (init_ue_msg.initUeMsg->getRRCEstablishmentCause() == -1) { if (init_ue_msg.initUeMsg->getRRCEstablishmentCause() == -1) {
Logger::amf_n2().warn("IE RRCEstablishmentCause not present"); Logger::amf_n2().warn("IE RRCEstablishmentCause not present");
itti_msg->rrc_cause = -1; // not present itti_msg->rrc_cause = -1; // not present
} else { } else {
itti_msg->rrc_cause = init_ue_msg.initUeMsg->getRRCEstablishmentCause(); itti_msg->rrc_cause = init_ue_msg.initUeMsg->getRRCEstablishmentCause();
} }
#if 0 #if 0
if(init_ue_msg.initUeMsg->getUeContextRequest() == -1){ if(init_ue_msg.initUeMsg->getUeContextRequest() == -1){
Logger::amf_n2().warn("IE UeContextRequest not present"); Logger::amf_n2().warn("IE UeContextRequest not present");
...@@ -423,6 +429,7 @@ void amf_n2::handle_itti_message(itti_initial_ue_message& init_ue_msg) { ...@@ -423,6 +429,7 @@ void amf_n2::handle_itti_message(itti_initial_ue_message& init_ue_msg) {
itti_msg->ueCtxReq = init_ue_msg.initUeMsg->getUeContextRequest(); itti_msg->ueCtxReq = init_ue_msg.initUeMsg->getUeContextRequest();
} }
#endif #endif
std::string _5g_s_tmsi; std::string _5g_s_tmsi;
if (!init_ue_msg.initUeMsg->get5GS_TMSI(_5g_s_tmsi)) { if (!init_ue_msg.initUeMsg->get5GS_TMSI(_5g_s_tmsi)) {
itti_msg->is_5g_s_tmsi_present = false; itti_msg->is_5g_s_tmsi_present = false;
...@@ -688,18 +695,20 @@ void amf_n2::handle_itti_message( ...@@ -688,18 +695,20 @@ void amf_n2::handle_itti_message(
Logger::amf_n2().debug("SUPI (%s)", supi.c_str()); Logger::amf_n2().debug("SUPI (%s)", supi.c_str());
std::shared_ptr<pdu_session_context> psc; std::shared_ptr<pdu_session_context> psc;
//TODO: REMOVE supi_to_pdu_ctx // TODO: REMOVE supi_to_pdu_ctx
if (!amf_app_inst->find_pdu_session_context(supi, itti_msg.pdu_session_id, psc)){ if (!amf_app_inst->find_pdu_session_context(
Logger::amf_n2().warn("Cannot get pdu_session_context with SUPI (%s)", supi.c_str()); supi, itti_msg.pdu_session_id, psc)) {
}
/*
if (amf_n11_inst->is_supi_to_pdu_ctx(supi)) {
psc = amf_n11_inst->supi_to_pdu_ctx(supi);
} else {
Logger::amf_n2().warn( Logger::amf_n2().warn(
"Cannot get pdu_session_context with SUPI (%s)", supi.c_str()); "Cannot get pdu_session_context with SUPI (%s)", supi.c_str());
} }
*/ /*
if (amf_n11_inst->is_supi_to_pdu_ctx(supi)) {
psc = amf_n11_inst->supi_to_pdu_ctx(supi);
} else {
Logger::amf_n2().warn(
"Cannot get pdu_session_context with SUPI (%s)", supi.c_str());
}
*/
// item.s_nssai.sst = std::to_string(psc.get()->snssai.sST); // item.s_nssai.sst = std::to_string(psc.get()->snssai.sST);
// item.s_nssai.sd = psc.get()->snssai.sD; // item.s_nssai.sd = psc.get()->snssai.sD;
...@@ -1023,7 +1032,7 @@ void amf_n2::handle_itti_message(itti_handover_required& itti_msg) { ...@@ -1023,7 +1032,7 @@ void amf_n2::handle_itti_message(itti_handover_required& itti_msg) {
// handoverrequest->setSourceToTarget_TransparentContainer(sourceTotarget); // handoverrequest->setSourceToTarget_TransparentContainer(sourceTotarget);
string supi = "imsi-" + nc.get()->imsi; string supi = "imsi-" + nc.get()->imsi;
//TODO: REMOVE supi_to_pdu_ctx (need PDU Session ID)/ list of PDU Session ID // TODO: REMOVE supi_to_pdu_ctx (need PDU Session ID)/ list of PDU Session ID
std::shared_ptr<pdu_session_context> psc = std::shared_ptr<pdu_session_context> psc =
amf_n11_inst->supi_to_pdu_ctx(supi); amf_n11_inst->supi_to_pdu_ctx(supi);
......
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