Skip to content

Commit

Permalink
feat(mme): NGAP Reset ALL
Browse files Browse the repository at this point in the history
feat(ngap): NGAP Reset ALL

Signed-off-by: aniket021997 <aniket.sonawane@wavelabs.ai>

rebased ngap reset all

Signed-off-by: aniket021997 <aniket.sonawane@wavelabs.ai>

ng reset all - rebased and imrpoved loggings

Signed-off-by: aniket021997 <aniket.sonawane@wavelabs.ai>
  • Loading branch information
aniket021997 committed Jul 5, 2022
1 parent 563d6fc commit 6a1410b
Show file tree
Hide file tree
Showing 15 changed files with 553 additions and 4 deletions.
4 changes: 4 additions & 0 deletions lte/gateway/c/core/oai/common/itti_free_defined_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ void itti_free_msg_content(MessageDef* const message_p) {
bdestroy_wrapper(&pdusession_resource_setup_req->nas_pdu);
break;
}
case NGAP_GNB_INITIATED_RESET_REQ:
free_wrapper((void**)&message_p->ittiMsg.ngap_gnb_initiated_reset_req
.ue_to_reset_list);
break;

default:;
}
Expand Down
3 changes: 3 additions & 0 deletions lte/gateway/c/core/oai/include/ngap_messages_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ MESSAGE_DEF(NGAP_UE_CONTEXT_MODIFICATION_FAILURE,
MESSAGE_DEF(NGAP_GNB_INITIATED_RESET_REQ, itti_ngap_gnb_initiated_reset_req_t,
ngap_gnb_initiated_reset_req)

MESSAGE_DEF(NGAP_GNB_INITIATED_RESET_ACK, itti_ngap_gnb_initiated_reset_ack_t,
ngap_gnb_initiated_reset_ack)

MESSAGE_DEF(NGAP_PDUSESSIONRESOURCE_SETUP_RSP,
itti_ngap_pdusessionresource_setup_rsp_t,
ngap_pdusessionresource_setup_rsp)
Expand Down
3 changes: 3 additions & 0 deletions lte/gateway/c/core/oai/tasks/amf/amf_app_defs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,7 @@ void amf_app_handle_ngap_ue_context_release_complete(
// Handling of SCTP shutdown
void amf_app_handle_gnb_deregister_ind(
const itti_ngap_gNB_deregistered_ind_t* const gNB_deregistered_ind);

void amf_app_handle_gnb_reset_req(
const itti_ngap_gnb_initiated_reset_req_t* const gnb_reset_req);
} // namespace magma5g
46 changes: 46 additions & 0 deletions lte/gateway/c/core/oai/tasks/amf/amf_app_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ extern "C" {
#include "lte/gateway/c/core/oai/tasks/amf/amf_common.h"
#include "lte/gateway/c/core/oai/include/map.h"
#include "lte/gateway/c/core/oai/tasks/amf/include/amf_client_servicer.hpp"
#include "lte/gateway/c/core/oai/include/ngap_messages_types.h"

extern amf_config_t amf_config;
extern amf_config_t amf_config;
Expand Down Expand Up @@ -1690,4 +1691,49 @@ int amf_app_handle_pdu_session_failure(
}
return RETURNok;
}

//------------------------------------------------------------------------------
void amf_app_handle_gnb_reset_req(
const itti_ngap_gnb_initiated_reset_req_t* const gnb_reset_req) {
MessageDef* msg;
itti_ngap_gnb_initiated_reset_ack_t* reset_ack;

OAILOG_FUNC_IN(LOG_AMF_APP);

OAILOG_INFO(LOG_AMF_APP,
" gNB Reset request received. gNB id = %d, reset_type %d \n ",
gnb_reset_req->gnb_id, gnb_reset_req->ngap_reset_type);
if (gnb_reset_req->ue_to_reset_list == NULL) {
OAILOG_ERROR(LOG_AMF_APP,
"Invalid UE list received in gNB Reset Request\n");
OAILOG_FUNC_OUT(LOG_AMF_APP);
}

for (int i = 0; i < gnb_reset_req->num_ue; i++) {
amf_app_handle_ngap_ue_context_release(
gnb_reset_req->ue_to_reset_list[i].amf_ue_ngap_id,
gnb_reset_req->ue_to_reset_list[i].gnb_ue_ngap_id,
gnb_reset_req->gnb_id, NGAP_SCTP_SHUTDOWN_OR_RESET);
}

// Send Reset Ack to NGAP module
msg = DEPRECATEDitti_alloc_new_message_fatal(TASK_AMF_APP,
NGAP_GNB_INITIATED_RESET_ACK);
reset_ack = &NGAP_GNB_INITIATED_RESET_ACK(msg);

// ue_to_reset_list needs to be freed by NGAP module
reset_ack->ue_to_reset_list = gnb_reset_req->ue_to_reset_list;
reset_ack->ngap_reset_type = gnb_reset_req->ngap_reset_type;
reset_ack->sctp_assoc_id = gnb_reset_req->sctp_assoc_id;
reset_ack->sctp_stream_id = gnb_reset_req->sctp_stream_id;
reset_ack->num_ue = gnb_reset_req->num_ue;

amf_send_msg_to_task(&amf_app_task_zmq_ctx, TASK_NGAP, msg);

OAILOG_INFO(LOG_AMF_APP,
" Reset Ack sent to NGAP. gNB id = %d, reset_type %d \n ",
gnb_reset_req->gnb_id, gnb_reset_req->ngap_reset_type);

OAILOG_FUNC_OUT(LOG_AMF_APP);
}
} // namespace magma5g
6 changes: 6 additions & 0 deletions lte/gateway/c/core/oai/tasks/amf/amf_app_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ static int handle_message(zloop_t* loop, zsock_t* reader, void* arg) {
&received_message_p->ittiMsg.ngap_gNB_deregistered_ind);
break;

case NGAP_GNB_INITIATED_RESET_REQ: {
amf_app_handle_gnb_reset_req(
&NGAP_GNB_INITIATED_RESET_REQ(received_message_p));
is_task_state_same = true;
} break;

/* Handle Terminate message */
case TERMINATE_MESSAGE:
itti_free_msg_content(received_message_p);
Expand Down
7 changes: 7 additions & 0 deletions lte/gateway/c/core/oai/tasks/ngap/ngap_amf.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ static int handle_message(zloop_t* loop, zsock_t* reader, void* arg) {
state, &NGAP_PDUSESSIONRESOURCE_REL_REQ(received_message_p));
} break;

case NGAP_GNB_INITIATED_RESET_ACK: {
is_task_state_same = true; // the following handler does not modify state
is_ue_state_same = true;
ngap_handle_gnb_initiated_reset_ack(
&NGAP_GNB_INITIATED_RESET_ACK(received_message_p));
} break;

case NGAP_PAGING_REQUEST: {
is_task_state_same = true; // the following handler does not modify state
is_ue_state_same = true;
Expand Down
1 change: 1 addition & 0 deletions lte/gateway/c/core/oai/tasks/ngap/ngap_amf_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ static inline int ngap_amf_encode_successful_outcome(Ngap_NGAP_PDU_t* pdu,
OAILOG_FUNC_IN(LOG_NGAP);
switch (pdu->choice.successfulOutcome.procedureCode) {
case Ngap_ProcedureCode_id_NGSetup:
case Ngap_ProcedureCode_id_NGReset:
break;

default:
Expand Down
174 changes: 170 additions & 4 deletions lte/gateway/c/core/oai/tasks/ngap/ngap_amf_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ ngap_message_handler_t ngap_message_handlers[][3] = {
0}, /* UEContextReleaseRequest */
{0, 0, 0}, /* DownlinkNgcdma2000tunneling */
{0, 0, 0}, /* UplinkNgcdma2000tunneling */
{0, /*ngap_amf_handle_ue_context_modification_response*/ 0,
/*ngap_amf_handle_ue_context_modification_failure*/
0}, /* UEContextModification
*/
/* {0, ngap_amf_handle_ue_context_modification_response 0,
ngap_amf_handle_ue_context_modification_failure
0}, UEContextModification*/
{ngap_amf_handle_gnb_reset, 0, 0}, /*NG Reset */
{ngap_amf_handle_ng_setup_request, 0, 0}, /* NGSetup */
{/*ngap_amf_handle_ue_cap_indication*/ 0, 0,
0}, /* TODO UECapabilityInfoIndication */
Expand Down Expand Up @@ -2071,3 +2071,169 @@ status_code_e ngap_handle_paging_request(

OAILOG_FUNC_RETURN(LOG_NGAP, rc);
}

bool construct_ngap_amf_full_reset_req(const hash_key_t keyP,
const uint64_t dataP, void* argP,
void** resultP) {
arg_ngap_construct_gnb_reset_req_t* arg = argP;
m5g_ue_description_t* ue_ref = (m5g_ue_description_t*)dataP;

hash_table_ts_t* ng_ue_state = get_ngap_ue_state();
hashtable_ts_get(ng_ue_state, (const hash_key_t)dataP, (void**)&ue_ref);
uint32_t i = arg->current_ue_index;
if (ue_ref) {
NGAP_GNB_INITIATED_RESET_REQ(arg->msg).ue_to_reset_list[i].amf_ue_ngap_id =
ue_ref->amf_ue_ngap_id;
NGAP_GNB_INITIATED_RESET_REQ(arg->msg).ue_to_reset_list[i].gnb_ue_ngap_id =
ue_ref->gnb_ue_ngap_id;
} else {
OAILOG_TRACE(LOG_NGAP, "No valid UE provided in callback: %p\n", ue_ref);
NGAP_GNB_INITIATED_RESET_REQ(arg->msg).ue_to_reset_list[i].amf_ue_ngap_id =
INVALID_AMF_UE_NGAP_ID;
}
arg->current_ue_index++;

return false;
}

//------------------------------------------------------------------------------
status_code_e ngap_amf_handle_gnb_reset(ngap_state_t* state,
const sctp_assoc_id_t assoc_id,
const sctp_stream_id_t stream,
Ngap_NGAP_PDU_t* pdu) {
MessageDef* msg = NULL;
itti_ngap_gnb_initiated_reset_req_t* reset_req = NULL;
gnb_description_t* gnb_association = NULL;
ngap_reset_type_t ngap_reset_type;
Ngap_NGReset_t* container = NULL;
Ngap_NGResetIEs_t* ie = NULL;
imsi64_t imsi64 = INVALID_IMSI64;
arg_ngap_construct_gnb_reset_req_t arg = {0};
int rc = RETURNok;

OAILOG_FUNC_IN(LOG_NGAP);

gnb_association = ngap_state_get_gnb(state, assoc_id);

if (gnb_association == NULL) {
OAILOG_ERROR(LOG_NGAP, "No gNB attached to this assoc_id: %d\n", assoc_id);
OAILOG_FUNC_RETURN(LOG_NGAP, RETURNerror);
}

if (gnb_association->ng_state != NGAP_READY) {
// ignore the message if NG not ready
OAILOG_INFO(
LOG_NGAP,
"NG setup is not done.Invalid state.Ignoring gNB Initiated Reset.gNB "
"Id "
"= %d , NGAP state = %d \n",
gnb_association->gnb_id, gnb_association->ng_state);
OAILOG_FUNC_RETURN(LOG_NGAP, RETURNok);
}

if (gnb_association->nb_ue_associated == 0) {
// Even if there are no UEs connected, we proceed -- this can happen if we
// receive a reset during a handover procedure, for example.
OAILOG_INFO(
LOG_NGAP,
"No UEs connected, still proceeding with GNB Initiated Reset. gNB Id = "
"%d\n",
gnb_association->gnb_id);
}

// Check the reset type - partial_reset OR reset_all
container = &pdu->choice.initiatingMessage.value.choice.NGReset;

NGAP_FIND_PROTOCOLIE_BY_ID(Ngap_NGResetIEs_t, ie, container,
Ngap_ProtocolIE_ID_id_ResetType, true);

Ngap_ResetType_t* resetType = &ie->value.choice.ResetType;

switch (resetType->present) {
case Ngap_ResetType_PR_nG_Interface:
ngap_reset_type = M5G_RESET_ALL;
break;
case Ngap_ResetType_PR_partOfNG_Interface:
ngap_reset_type = M5G_RESET_PARTIAL;
break;
default:
OAILOG_ERROR(LOG_NGAP,
"NGReset Request from gNB with Invalid reset_type = %d\n",
resetType->present);
// TBD - Here AMF should send Error Indication as it is abnormal scenario.
OAILOG_FUNC_RETURN(LOG_NGAP, RETURNerror);
}

msg = DEPRECATEDitti_alloc_new_message_fatal(TASK_NGAP,
NGAP_GNB_INITIATED_RESET_REQ);
reset_req = &NGAP_GNB_INITIATED_RESET_REQ(msg);

reset_req->ngap_reset_type = ngap_reset_type;
reset_req->gnb_id = gnb_association->gnb_id;
reset_req->sctp_assoc_id = assoc_id;
reset_req->sctp_stream_id = stream;

switch (ngap_reset_type) {
case M5G_RESET_ALL:
increment_counter("ngap_reset_from_gnb", 1, 1, "type", "M5G_RESET_ALL");

reset_req->num_ue = gnb_association->nb_ue_associated;

reset_req->ue_to_reset_list =
calloc(gnb_association->nb_ue_associated,
sizeof(*(reset_req->ue_to_reset_list)));

if (reset_req->ue_to_reset_list == NULL) {
OAILOG_ERROR(LOG_NGAP, "ue_to_reset_list is NULL\n");
return RETURNerror;
}
arg.msg = msg;
arg.current_ue_index = 0;
hashtable_uint64_ts_apply_callback_on_elements(
&gnb_association->ue_id_coll, construct_ngap_amf_full_reset_req, &arg,
NULL);

break;
}
msg->ittiMsgHeader.imsi = imsi64;
rc = ngap_send_msg_to_task(&ngap_task_zmq_ctx, TASK_AMF_APP, msg);
OAILOG_FUNC_RETURN(LOG_NGAP, rc);
}

//------------------------------------------------------------------------------
status_code_e ngap_handle_gnb_initiated_reset_ack(
const itti_ngap_gnb_initiated_reset_ack_t* const gnb_reset_ack_p) {
uint8_t* buffer = NULL;
uint32_t length = 0;
Ngap_NGAP_PDU_t pdu;
/** NGReset Acknowledgment. */
Ngap_NGResetAcknowledge_t* out;
Ngap_NGResetAcknowledgeIEs_t* ie = NULL;
int rc = RETURNok;

OAILOG_FUNC_IN(LOG_NGAP);

memset(&pdu, 0, sizeof(pdu));
pdu.present = Ngap_NGAP_PDU_PR_successfulOutcome;
pdu.choice.successfulOutcome.procedureCode = Ngap_ProcedureCode_id_NGReset;
pdu.choice.successfulOutcome.criticality = Ngap_Criticality_ignore;
pdu.choice.successfulOutcome.value.present =
Ngap_SuccessfulOutcome__value_PR_NGResetAcknowledge;
out = &pdu.choice.successfulOutcome.value.choice.NGResetAcknowledge;

if (ngap_amf_encode_pdu(&pdu, &buffer, &length) < 0) {
OAILOG_ERROR(LOG_NGAP, "Failed to NG NGReset command \n");
/** We rely on the handover_notify timeout to remove the UE context. */
DevAssert(!buffer);
OAILOG_FUNC_RETURN(LOG_NGAP, RETURNerror);
}
increment_counter("NG_reset_from_gnb", 1, 1, "action", "reset_ack_sent");
if (buffer) {
bstring b = blk2bstr(buffer, length);
free_wrapper((void**)&buffer);
rc = ngap_amf_itti_send_sctp_request(&b, gnb_reset_ack_p->sctp_assoc_id,
gnb_reset_ack_p->sctp_stream_id,
INVALID_AMF_UE_NGAP_ID);
}
OAILOG_FUNC_RETURN(LOG_NGAP, rc);
}
12 changes: 12 additions & 0 deletions lte/gateway/c/core/oai/tasks/ngap/ngap_amf_handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,15 @@ int ngap_amf_handle_pduSession_setup_response(ngap_state_t* state,
const sctp_assoc_id_t assoc_id,
const sctp_stream_id_t stream,
Ngap_NGAP_PDU_t* pdu);

status_code_e ngap_amf_handle_gnb_reset(ngap_state_t* state,
const sctp_assoc_id_t assoc_id,
const sctp_stream_id_t stream,
Ngap_NGAP_PDU_t* message);

status_code_e ngap_handle_gnb_initiated_reset_ack(
const itti_ngap_gnb_initiated_reset_ack_t* const gnb_reset_ack_p);

bool construct_ngap_amf_full_reset_req(const hash_key_t keyP,
const uint64_t dataP, void* argP,
void** resultP);
17 changes: 17 additions & 0 deletions lte/gateway/c/core/oai/test/amf/amf_app_test_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,4 +706,21 @@ int unit_test_registration_accept_t3550(amf_ue_ngap_id_t ue_id) {
return (rc);
}

// Send GNB Reset Request
void send_gnb_reset_req() {
itti_ngap_gnb_initiated_reset_req_t reset_req_msg = {};
reset_req_msg.ngap_reset_type = M5G_RESET_ALL;
reset_req_msg.gnb_id = 1;
reset_req_msg.sctp_assoc_id = 1;
reset_req_msg.sctp_stream_id = 1;
reset_req_msg.num_ue = 1;
reset_req_msg.ue_to_reset_list =
reinterpret_cast<ng_sig_conn_id_t*>(calloc(1, sizeof(ng_sig_conn_id_t)));
reset_req_msg.ue_to_reset_list[0].amf_ue_ngap_id = 1;
reset_req_msg.ue_to_reset_list[0].gnb_ue_ngap_id = 1;

amf_app_handle_gnb_reset_req(&reset_req_msg);

free(reset_req_msg.ue_to_reset_list);
}
} // namespace magma5g
2 changes: 2 additions & 0 deletions lte/gateway/c/core/oai/test/amf/amf_app_test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,6 @@ int check_ue_context_state(amf_ue_ngap_id_t ue_id,
// mimicing registration_accept_t3550_handler
int unit_test_registration_accept_t3550(amf_ue_ngap_id_t ue_id);

// Send GNB Reset Request
void send_gnb_reset_req();
} // namespace magma5g

0 comments on commit 6a1410b

Please sign in to comment.