From a96d3ca0fa88828f4efb1135ebcb8a88d8bdc66c Mon Sep 17 00:00:00 2001 From: Sukchan Lee Date: Sun, 3 Jan 2021 23:29:01 -0500 Subject: [PATCH] feat: Add multiple session --- README.md | 8 +- docs/_docs/guide/01-quickstart.md | 7 + .../troubleshoot/02-now-in-github-issues.md | 13 +- src/amf/context.h | 7 +- src/amf/ngap-build.c | 16 +- src/amf/ngap-build.h | 2 +- src/amf/ngap-handler.c | 100 +-- src/amf/ngap-path.c | 5 +- src/amf/ngap-path.h | 2 +- src/amf/nsmf-handler.c | 71 ++- src/mme/s1ap-handler.c | 82 +-- src/smf/ngap-build.h | 2 + tests/common/context.c | 18 +- tests/common/context.h | 3 +- tests/common/gsm-build.c | 7 +- tests/common/ngap-build.c | 117 ++-- tests/common/ngap-build.h | 4 +- tests/common/ngap-handler.c | 4 +- tests/handover/5gc-xn-test.c | 24 +- tests/minimal/minimal-test.c | 16 +- tests/registration/auth-test.c | 4 - tests/registration/dereg-test.c | 34 +- tests/registration/gmm-status-test.c | 8 +- tests/registration/guti-test.c | 19 +- tests/registration/identity-test.c | 11 +- tests/registration/idle-test.c | 42 +- tests/registration/ue-context-test.c | 11 +- tests/vonr/abts-main.c | 2 + tests/vonr/meson.build | 1 + tests/vonr/qos-flow-test.c | 14 +- tests/vonr/session-test.c | 585 ++++++++++++++++++ 31 files changed, 941 insertions(+), 298 deletions(-) create mode 100644 tests/vonr/session-test.c diff --git a/README.md b/README.md index 143affd05..9e4d9f63e 100644 --- a/README.md +++ b/README.md @@ -40,11 +40,9 @@ If you don't understand something about Open5GS, the [https://open5gs.org/open5g ## Community -Problem with Open5GS can be filed as [issues](https://github.com/open5gs/open5gs/issues) in this repository. - -Other topics related to this project are happening on the [discussions](https://github.com/open5gs/open5gs/discussions). - -Voice and text chat are available in Open5GS's [Discord](https://discordapp.com/) workspace. Use [this link](https://discord.gg/GreNkuc) to get started. +- Problem with Open5GS can be filed as [issues](https://github.com/open5gs/open5gs/issues) in this repository. +- Other topics related to this project are happening on the [discussions](https://github.com/open5gs/open5gs/discussions). +- Voice and text chat are available in Open5GS's [Discord](https://discordapp.com/) workspace. Use [this link](https://discord.gg/GreNkuc) to get started. ## Contributing diff --git a/docs/_docs/guide/01-quickstart.md b/docs/_docs/guide/01-quickstart.md index 61c7268d9..67f81a491 100644 --- a/docs/_docs/guide/01-quickstart.md +++ b/docs/_docs/guide/01-quickstart.md @@ -10,6 +10,13 @@ Welcome! If you want to set up your first Open5GS core you have come to the righ **TL;DR:** Open5GS contains a series of software components and network functions that implement the 4G/ 5G NSA and 5G SA core functions. If you know what each of these do already and how they interface with each other, skip to section 2. {: .notice--info} + + ![Open5GS Diagram]({{ site.url }}{{ site.baseurl }}/assets/images/Open5GS_CUPS-01.jpg) [[Higher quality PDF diagram available HERE]]({{ site.url }}{{ site.baseurl }}/assets/images/Open5GS_CUPS-01.pdf) diff --git a/docs/_docs/troubleshoot/02-now-in-github-issues.md b/docs/_docs/troubleshoot/02-now-in-github-issues.md index 371810388..924eb9d60 100644 --- a/docs/_docs/troubleshoot/02-now-in-github-issues.md +++ b/docs/_docs/troubleshoot/02-now-in-github-issues.md @@ -3,6 +3,13 @@ title: Now in the Github Issue head_inline: "" --- + + #### Cannot open shared object file when running daemon An error occurred when running as follows. @@ -176,15 +183,15 @@ $ sudo systemctl restart open5gs-upfd.service By default, wireshark cannot decode NAS-5GS message when the security header type is "Integrity protected and ciphered". -![Wireshark cannot decode]({{ site.url }}{{ site.baseurl }}/assets/images/wireshark_cannot_decode_nas_5gs.png){: height="100%" width="100%"} +![Wireshark cannot decode]({{ site.url }}{{ site.baseurl }}/assets/images/wireshark_cannot_decode_nas_5gs.png) You need to turn on "Try to detect and decode 5G-EA0 ciphered messages" in the wireshark perference menu. -![Wireshark perference]({{ site.url }}{{ site.baseurl }}/assets/images/wireshark_preference.png){: height="100%" width="100%"} +![Wireshark perference]({{ site.url }}{{ site.baseurl }}/assets/images/wireshark_preference.png) Now, you can see the NAS-5GS message in the wireshark. -![Wireshark can decode]({{ site.url }}{{ site.baseurl }}/assets/images/wireshark_can_decode_nas_5gs.png){: height="100%" width="100%"} +![Wireshark can decode]({{ site.url }}{{ site.baseurl }}/assets/images/wireshark_can_decode_nas_5gs.png) #### Test failed (e.g. `meson test -v`) diff --git a/src/amf/context.h b/src/amf/context.h index c6ed52642..b93f74a79 100644 --- a/src/amf/context.h +++ b/src/amf/context.h @@ -440,9 +440,10 @@ typedef struct amf_sess_s { bool n1_released; bool n2_released; - /* SMF sends the RESPONSE - * of [POST] /nsmf-pdusession/v1/sm-contexts/{smContextRef}/modify */ - ogs_pkbuf_t *pdu_session_resource_setup_request_transfer; + struct { + ogs_pkbuf_t *pdu_session_resource_setup_request; + ogs_pkbuf_t *path_switch_request_ack; + } transfer; /* last payload for sending back to the UE */ uint8_t payload_container_type; diff --git a/src/amf/ngap-build.c b/src/amf/ngap-build.c index c7a274810..a92577a6d 100644 --- a/src/amf/ngap-build.c +++ b/src/amf/ngap-build.c @@ -387,7 +387,7 @@ ogs_pkbuf_t *ngap_build_initial_context_setup_request( NGAP_S_NSSAI_t *s_NSSAI = NULL; NGAP_SST_t *sST = NULL; - if (!sess->pdu_session_resource_setup_request_transfer) continue; + if (!sess->transfer.pdu_session_resource_setup_request) continue; if (!PDUSessionList) { ie = CALLOC(1, sizeof(NGAP_InitialContextSetupRequestIEs_t)); @@ -417,10 +417,10 @@ ogs_pkbuf_t *ngap_build_initial_context_setup_request( } transfer = &PDUSessionItem->pDUSessionResourceSetupRequestTransfer; - transfer->size = sess->pdu_session_resource_setup_request_transfer->len; + transfer->size = sess->transfer.pdu_session_resource_setup_request->len; transfer->buf = CALLOC(transfer->size, sizeof(uint8_t)); memcpy(transfer->buf, - sess->pdu_session_resource_setup_request_transfer->data, + sess->transfer.pdu_session_resource_setup_request->data, transfer->size); } @@ -1289,7 +1289,7 @@ ogs_pkbuf_t *ngap_build_amf_configuration_transfer( } #endif -ogs_pkbuf_t *ngap_build_path_switch_ack(amf_ue_t *amf_ue, ogs_pkbuf_t *n2smbuf) +ogs_pkbuf_t *ngap_build_path_switch_ack(amf_ue_t *amf_ue) { int i, j; @@ -1382,6 +1382,8 @@ ogs_pkbuf_t *ngap_build_path_switch_ack(amf_ue_t *amf_ue, ogs_pkbuf_t *n2smbuf) OCTET_STRING_t *transfer = NULL; NGAP_PDUSessionResourceSwitchedItem_t *PDUSessionItem = NULL; + if (!sess->transfer.path_switch_request_ack) continue; + if (!PDUSessionResourceSwitchedList) { ie = CALLOC(1, sizeof(NGAP_PathSwitchRequestAcknowledgeIEs_t)); ASN_SEQUENCE_ADD(&PathSwitchRequestAcknowledge->protocolIEs, ie); @@ -1401,10 +1403,10 @@ ogs_pkbuf_t *ngap_build_path_switch_ack(amf_ue_t *amf_ue, ogs_pkbuf_t *n2smbuf) PDUSessionItem->pDUSessionID = sess->psi; transfer = &PDUSessionItem->pathSwitchRequestAcknowledgeTransfer; - transfer->size = n2smbuf->len; + transfer->size = sess->transfer.path_switch_request_ack->len; transfer->buf = CALLOC(transfer->size, sizeof(uint8_t)); - memcpy(transfer->buf, n2smbuf->data, transfer->size); - ogs_pkbuf_free(n2smbuf); + memcpy(transfer->buf, sess->transfer.path_switch_request_ack->data, + transfer->size); } ie = CALLOC(1, sizeof(NGAP_PathSwitchRequestAcknowledgeIEs_t)); diff --git a/src/amf/ngap-build.h b/src/amf/ngap-build.h index 6a693dbc2..dba5fa993 100644 --- a/src/amf/ngap-build.h +++ b/src/amf/ngap-build.h @@ -54,7 +54,7 @@ ogs_pkbuf_t *ngap_build_paging( ogs_pkbuf_t *ngap_build_amf_configuration_transfer( NGAP_SONConfigurationTransfer_t *son_configuration_transfer); -ogs_pkbuf_t *ngap_build_path_switch_ack(amf_ue_t *amf_ue, ogs_pkbuf_t *n2smbuf); +ogs_pkbuf_t *ngap_build_path_switch_ack(amf_ue_t *amf_ue); ogs_pkbuf_t *ngap_build_handover_command(ran_ue_t *source_ue); ogs_pkbuf_t *ngap_build_handover_preparation_failure( diff --git a/src/amf/ngap-handler.c b/src/amf/ngap-handler.c index 3746ebf9e..795d22236 100644 --- a/src/amf/ngap-handler.c +++ b/src/amf/ngap-handler.c @@ -1730,6 +1730,7 @@ void ngap_handle_path_switch_request( NGAP_RAN_UE_NGAP_ID_t *RAN_UE_NGAP_ID = NULL; NGAP_AMF_UE_NGAP_ID_t *AMF_UE_NGAP_ID = NULL; NGAP_UserLocationInformation_t *UserLocationInformation = NULL; + NGAP_UserLocationInformationNR_t *UserLocationInformationNR = NULL; NGAP_UESecurityCapabilities_t *UESecurityCapabilities = NULL; NGAP_PDUSessionResourceToBeSwitchedDLList_t *PDUSessionResourceToBeSwitchedDLList = NULL; @@ -1812,9 +1813,6 @@ void ngap_handle_path_switch_request( return; } - ogs_debug(" RAN_UE_NGAP_ID[%d] AMF_UE_NGAP_ID[%lld]", - ran_ue->ran_ue_ngap_id, (long long)ran_ue->amf_ue_ngap_id); - amf_ue = ran_ue->amf_ue; if (!amf_ue) { ogs_error("Cannot find AMF-UE Context [%lld]", @@ -1826,68 +1824,58 @@ void ngap_handle_path_switch_request( return; } + ogs_debug(" [OLD] RAN_UE_NGAP_ID[%d] AMF_UE_NGAP_ID[%lld] ", + ran_ue->ran_ue_ngap_id, (long long)ran_ue->amf_ue_ngap_id); + ogs_debug(" [OLD] TAC[%d] CellID[0x%llx]", + amf_ue->tai.tac.v, (long long)amf_ue->nr_cgi.cell_id); + + /* Update RAN-UE-NGAP-ID */ + ran_ue->ran_ue_ngap_id = *RAN_UE_NGAP_ID; + + /* Change ran_ue to the NEW gNB */ + ran_ue_switch_to_gnb(ran_ue, gnb); + if (!UserLocationInformation) { ogs_error("No UserLocationInformation"); - ngap_send_error_indication(gnb, &ran_ue->ran_ue_ngap_id, NULL, + ngap_send_error_indication2(amf_ue, NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error); return; } - if (!UESecurityCapabilities) { - ogs_error("No UESecurityCapabilities"); - ngap_send_error_indication(gnb, &ran_ue->ran_ue_ngap_id, NULL, - NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error); - return; - } - - if (!PDUSessionResourceToBeSwitchedDLList) { - ogs_error("No PDUSessionResourceToBeSwitchedDLList"); - ngap_send_error_indication(gnb, &ran_ue->ran_ue_ngap_id, NULL, - NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error); - return; - } - - if (UserLocationInformation->present == + if (UserLocationInformation->present != NGAP_UserLocationInformation_PR_userLocationInformationNR) { - NGAP_UserLocationInformationNR_t *userLocationInformationNR = - UserLocationInformation->choice.userLocationInformationNR; - - ogs_ngap_ASN_to_nr_cgi( - &userLocationInformationNR->nR_CGI, &ran_ue->saved.nr_cgi); - ogs_ngap_ASN_to_5gs_tai( - &userLocationInformationNR->tAI, &ran_ue->saved.tai); - - } else { ogs_error("Not implemented UserLocationInformation[%d]", UserLocationInformation->present); - ngap_send_error_indication(gnb, &ran_ue->ran_ue_ngap_id, NULL, + ngap_send_error_indication2(amf_ue, NGAP_Cause_PR_protocol, NGAP_CauseProtocol_unspecified); return; } - if (SECURITY_CONTEXT_IS_VALID(amf_ue)) { - amf_ue->nhcc++; - ogs_kdf_nh_gnb(amf_ue->kamf, amf_ue->nh, amf_ue->nh); - } else { - ogs_error("No Security Context"); - ngap_send_error_indication(gnb, &ran_ue->ran_ue_ngap_id, NULL, - NGAP_Cause_PR_nas, NGAP_CauseNas_authentication_failure); - return; - } - - ran_ue->ran_ue_ngap_id = *RAN_UE_NGAP_ID; - - ogs_debug(" RAN_UE_NGAP_ID[%d] AMF_UE_NGAP_ID[%lld] ", + ogs_debug(" [NEW] RAN_UE_NGAP_ID[%d] AMF_UE_NGAP_ID[%lld] ", ran_ue->ran_ue_ngap_id, (long long)ran_ue->amf_ue_ngap_id); - ogs_debug(" [OLD] TAC[%d] CellID[0x%llx]", - amf_ue->tai.tac.v, (long long)amf_ue->nr_cgi.cell_id); - ogs_debug(" [NEW] TAC[%d] CellID[0x%llx]", - ran_ue->saved.tai.tac.v, (long long)ran_ue->saved.nr_cgi.cell_id); + + UserLocationInformationNR = + UserLocationInformation->choice.userLocationInformationNR; + ogs_assert(UserLocationInformationNR); + ogs_ngap_ASN_to_nr_cgi( + &UserLocationInformationNR->nR_CGI, &ran_ue->saved.nr_cgi); + ogs_ngap_ASN_to_5gs_tai( + &UserLocationInformationNR->tAI, &ran_ue->saved.tai); /* Copy TAI and ECGI from ran_ue */ memcpy(&amf_ue->tai, &ran_ue->saved.tai, sizeof(ogs_5gs_tai_t)); memcpy(&amf_ue->nr_cgi, &ran_ue->saved.nr_cgi, sizeof(ogs_nr_cgi_t)); + ogs_debug(" [NEW] TAC[%d] CellID[0x%llx]", + amf_ue->tai.tac.v, (long long)amf_ue->nr_cgi.cell_id); + + if (!UESecurityCapabilities) { + ogs_error("No UESecurityCapabilities"); + ngap_send_error_indication2(amf_ue, + NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error); + return; + } + nRencryptionAlgorithms = &UESecurityCapabilities->nRencryptionAlgorithms; nRintegrityProtectionAlgorithms = &UESecurityCapabilities->nRintegrityProtectionAlgorithms; @@ -1920,6 +1908,24 @@ void ngap_handle_path_switch_request( amf_ue->ue_security_capability.eps_ia = eps_ia >> 9; amf_ue->ue_security_capability.eps_ia0 = eps_ia0; + if (!SECURITY_CONTEXT_IS_VALID(amf_ue)) { + ogs_error("No Security Context"); + ngap_send_error_indication2(amf_ue, + NGAP_Cause_PR_nas, NGAP_CauseNas_authentication_failure); + return; + } + + /* Update Security Context (NextHop) */ + amf_ue->nhcc++; + ogs_kdf_nh_gnb(amf_ue->kamf, amf_ue->nh, amf_ue->nh); + + if (!PDUSessionResourceToBeSwitchedDLList) { + ogs_error("No PDUSessionResourceToBeSwitchedDLList"); + ngap_send_error_indication2(amf_ue, + NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error); + return; + } + for (i = 0; i < PDUSessionResourceToBeSwitchedDLList->list.count; i++) { amf_sess_t *sess = NULL; PDUSessionItem = (NGAP_PDUSessionResourceToBeSwitchedDLItem_t *) @@ -1979,6 +1985,4 @@ void ngap_handle_path_switch_request( ogs_pkbuf_free(param.n2smbuf); } - - ran_ue_switch_to_gnb(ran_ue, gnb); } diff --git a/src/amf/ngap-path.c b/src/amf/ngap-path.c index 07e7517f6..d7deec532 100644 --- a/src/amf/ngap-path.c +++ b/src/amf/ngap-path.c @@ -389,7 +389,7 @@ void ngap_send_amf_configuration_transfer( #endif -void ngap_send_path_switch_ack(amf_sess_t *sess, ogs_pkbuf_t *n2smbuf) +void ngap_send_path_switch_ack(amf_sess_t *sess) { int rv; @@ -399,9 +399,8 @@ void ngap_send_path_switch_ack(amf_sess_t *sess, ogs_pkbuf_t *n2smbuf) ogs_assert(sess); amf_ue = sess->amf_ue; ogs_assert(amf_ue); - ogs_assert(n2smbuf); - ngapbuf = ngap_build_path_switch_ack(amf_ue, n2smbuf); + ngapbuf = ngap_build_path_switch_ack(amf_ue); ogs_expect_or_return(ngapbuf); rv = nas_5gs_send_to_gnb(amf_ue, ngapbuf); diff --git a/src/amf/ngap-path.h b/src/amf/ngap-path.h index 8d0e5020d..bb566e35b 100644 --- a/src/amf/ngap-path.h +++ b/src/amf/ngap-path.h @@ -69,7 +69,7 @@ void ngap_send_amf_configuration_transfer( amf_gnb_t *target_gnb, NGAP_SONConfigurationTransfer_t *SONConfigurationTransfer); -void ngap_send_path_switch_ack(amf_sess_t *sess, ogs_pkbuf_t *n2smbuf); +void ngap_send_path_switch_ack(amf_sess_t *sess); void ngap_send_handover_command(ran_ue_t *source_ue); void ngap_send_handover_preparation_failure( diff --git a/src/amf/nsmf-handler.c b/src/amf/nsmf-handler.c index bf6e15039..d57ffb460 100644 --- a/src/amf/nsmf-handler.c +++ b/src/amf/nsmf-handler.c @@ -193,7 +193,7 @@ int amf_nsmf_pdu_session_handle_update_sm_context( * To Deliver N2 SM Content to gNB Temporarily, * Store N2 SM Context in Session Context */ - if (sess->pdu_session_resource_setup_request_transfer) { + if (sess->transfer.pdu_session_resource_setup_request) { /* * It should not be reached this way. * If the problem occurred, free the old n2smbuf @@ -201,16 +201,16 @@ int amf_nsmf_pdu_session_handle_update_sm_context( ogs_error("[%s:%d] N2 SM Content is duplicated", amf_ue->supi, sess->psi); ogs_pkbuf_free( - sess->pdu_session_resource_setup_request_transfer); + sess->transfer.pdu_session_resource_setup_request); } /* * NOTE : The pkbuf created in the SBI message will be removed * from ogs_sbi_message_free(). * So it must be copied and push a event queue. */ - sess->pdu_session_resource_setup_request_transfer = + sess->transfer.pdu_session_resource_setup_request = ogs_pkbuf_copy(n2smbuf); - ogs_assert(sess->pdu_session_resource_setup_request_transfer); + ogs_assert(sess->transfer.pdu_session_resource_setup_request); if (SESSION_SYNC_DONE(amf_ue)) { nas_5gs_send_accept(amf_ue); @@ -220,10 +220,10 @@ int amf_nsmf_pdu_session_handle_update_sm_context( * For checking memory, NULL pointer should be set to n2smbuf. */ ogs_list_for_each(&amf_ue->sess_list, sess) { - if (sess->pdu_session_resource_setup_request_transfer) { + if (sess->transfer.pdu_session_resource_setup_request) { ogs_pkbuf_free(sess-> - pdu_session_resource_setup_request_transfer); - sess->pdu_session_resource_setup_request_transfer = + transfer.pdu_session_resource_setup_request); + sess->transfer.pdu_session_resource_setup_request = NULL; } } @@ -239,6 +239,14 @@ int amf_nsmf_pdu_session_handle_update_sm_context( return OGS_ERROR; } + if (!n2smbuf) { + ogs_error("[%s:%d] No N2 SM Content", + amf_ue->supi, sess->psi); + nas_5gs_send_back_5gsm_message(sess, + OGS_5GMM_CAUSE_SEMANTICALLY_INCORRECT_MESSAGE); + return OGS_ERROR; + } + /* * NOTE : The pkbuf created in the SBI message will be removed * from ogs_sbi_message_free(), so it must be copied. @@ -253,11 +261,54 @@ int amf_nsmf_pdu_session_handle_update_sm_context( break; case OpenAPI_n2_sm_info_type_PATH_SWITCH_REQ_ACK: - n2smbuf = ogs_pkbuf_copy(n2smbuf); - ogs_assert(n2smbuf); + if (!n2smbuf) { + ogs_error("[%s:%d] No N2 SM Content", + amf_ue->supi, sess->psi); + ngap_send_error_indication2(amf_ue, + NGAP_Cause_PR_protocol, + NGAP_CauseProtocol_semantic_error); + return OGS_ERROR; + } - ngap_send_path_switch_ack(sess, n2smbuf); + /* + * To Deliver N2 SM Content to gNB Temporarily, + * Store N2 SM Context in Session Context + */ + if (sess->transfer.path_switch_request_ack) { + /* + * It should not be reached this way. + * If the problem occurred, free the old n2smbuf + */ + ogs_error("[%s:%d] N2 SM Content is duplicated", + amf_ue->supi, sess->psi); + ogs_pkbuf_free(sess->transfer.path_switch_request_ack); + } + /* + * NOTE : The pkbuf created in the SBI message will be removed + * from ogs_sbi_message_free(). + * So it must be copied and push a event queue. + */ + sess->transfer.path_switch_request_ack = + ogs_pkbuf_copy(n2smbuf); + ogs_assert(sess->transfer.path_switch_request_ack); + + if (SESSION_SYNC_DONE(amf_ue)) { + ngap_send_path_switch_ack(sess); + + /* + * After sending ack message, N2 SM context is freed + * For checking memory, NULL pointer should be set to n2smbuf. + */ + ogs_list_for_each(&amf_ue->sess_list, sess) { + if (sess->transfer.path_switch_request_ack) { + ogs_pkbuf_free( + sess->transfer.path_switch_request_ack); + sess->transfer.path_switch_request_ack = NULL; + } + } + } break; + default: ogs_error("Not implemented [%d]", SmContextUpdatedData->n2_sm_info_type); diff --git a/src/mme/s1ap-handler.c b/src/mme/s1ap-handler.c index e62b40d3c..e330abef7 100644 --- a/src/mme/s1ap-handler.c +++ b/src/mme/s1ap-handler.c @@ -1255,24 +1255,6 @@ void s1ap_handle_path_switch_request( ogs_debug(" IP[%s] ENB_ID[%d]", OGS_ADDR(enb->sctp.addr, buf), enb->enb_id); - ogs_assert(EUTRAN_CGI); - pLMNidentity = &EUTRAN_CGI->pLMNidentity; - ogs_assert(pLMNidentity && pLMNidentity->size == sizeof(ogs_plmn_id_t)); - cell_ID = &EUTRAN_CGI->cell_ID; - ogs_assert(cell_ID); - - ogs_assert(TAI); - pLMNidentity = &TAI->pLMNidentity; - ogs_assert(pLMNidentity && pLMNidentity->size == sizeof(ogs_plmn_id_t)); - tAC = &TAI->tAC; - ogs_assert(tAC && tAC->size == sizeof(uint16_t)); - - ogs_assert(UESecurityCapabilities); - encryptionAlgorithms = - &UESecurityCapabilities->encryptionAlgorithms; - integrityProtectionAlgorithms = - &UESecurityCapabilities->integrityProtectionAlgorithms; - ogs_assert(MME_UE_S1AP_ID); ogs_assert(ENB_UE_S1AP_ID); enb_ue = enb_ue_find_by_mme_ue_s1ap_id(*MME_UE_S1AP_ID); @@ -1298,21 +1280,31 @@ void s1ap_handle_path_switch_request( mme_ue = enb_ue->mme_ue; ogs_expect_or_return(mme_ue); - if (SECURITY_CONTEXT_IS_VALID(mme_ue)) { - mme_ue->nhcc++; - ogs_kdf_nh_enb(mme_ue->kasme, mme_ue->nh, mme_ue->nh); - } else { - s1apbuf = s1ap_build_path_switch_failure( - *ENB_UE_S1AP_ID, *MME_UE_S1AP_ID, - S1AP_Cause_PR_nas, S1AP_CauseNas_authentication_failure); - ogs_expect_or_return(s1apbuf); - - s1ap_send_to_enb_ue(enb_ue, s1apbuf); - return; - } + ogs_debug(" OLD TAI[PLMN_ID:%06x,TAC:%d]", + ogs_plmn_id_hexdump(&mme_ue->tai.plmn_id), + mme_ue->tai.tac); + ogs_debug(" OLD E_CGI[PLMN_ID:%06x,CELL_ID:%d]", + ogs_plmn_id_hexdump(&mme_ue->e_cgi.plmn_id), + mme_ue->e_cgi.cell_id); + /* Update ENB-UE-S1AP-ID */ enb_ue->enb_ue_s1ap_id = *ENB_UE_S1AP_ID; + /* Change enb_ue to the NEW eNB */ + enb_ue_switch_to_enb(enb_ue, enb); + + ogs_assert(EUTRAN_CGI); + pLMNidentity = &EUTRAN_CGI->pLMNidentity; + ogs_assert(pLMNidentity && pLMNidentity->size == sizeof(ogs_plmn_id_t)); + cell_ID = &EUTRAN_CGI->cell_ID; + ogs_assert(cell_ID); + + ogs_assert(TAI); + pLMNidentity = &TAI->pLMNidentity; + ogs_assert(pLMNidentity && pLMNidentity->size == sizeof(ogs_plmn_id_t)); + tAC = &TAI->tAC; + ogs_assert(tAC && tAC->size == sizeof(uint16_t)); + memcpy(&enb_ue->saved.tai.plmn_id, pLMNidentity->buf, sizeof(enb_ue->saved.tai.plmn_id)); memcpy(&enb_ue->saved.tai.tac, tAC->buf, sizeof(enb_ue->saved.tai.tac)); @@ -1324,12 +1316,6 @@ void s1ap_handle_path_switch_request( sizeof(enb_ue->saved.e_cgi.cell_id)); enb_ue->saved.e_cgi.cell_id = (be32toh(enb_ue->saved.e_cgi.cell_id) >> 4); - ogs_debug(" OLD TAI[PLMN_ID:%06x,TAC:%d]", - ogs_plmn_id_hexdump(&mme_ue->tai.plmn_id), - mme_ue->tai.tac); - ogs_debug(" OLD E_CGI[PLMN_ID:%06x,CELL_ID:%d]", - ogs_plmn_id_hexdump(&mme_ue->e_cgi.plmn_id), - mme_ue->e_cgi.cell_id); ogs_debug(" TAI[PLMN_ID:%06x,TAC:%d]", ogs_plmn_id_hexdump(&enb_ue->saved.tai.plmn_id), enb_ue->saved.tai.tac); @@ -1341,6 +1327,12 @@ void s1ap_handle_path_switch_request( memcpy(&mme_ue->tai, &enb_ue->saved.tai, sizeof(ogs_eps_tai_t)); memcpy(&mme_ue->e_cgi, &enb_ue->saved.e_cgi, sizeof(ogs_e_cgi_t)); + ogs_assert(UESecurityCapabilities); + encryptionAlgorithms = + &UESecurityCapabilities->encryptionAlgorithms; + integrityProtectionAlgorithms = + &UESecurityCapabilities->integrityProtectionAlgorithms; + memcpy(&eea, encryptionAlgorithms->buf, sizeof(eea)); eea = be16toh(eea); eea0 = mme_ue->ue_network_capability.eea0; @@ -1353,6 +1345,21 @@ void s1ap_handle_path_switch_request( mme_ue->ue_network_capability.eia = eia >> 9; mme_ue->ue_network_capability.eia0 = eia0; + if (!SECURITY_CONTEXT_IS_VALID(mme_ue)) { + ogs_error("No Security Context"); + s1apbuf = s1ap_build_path_switch_failure( + *ENB_UE_S1AP_ID, *MME_UE_S1AP_ID, + S1AP_Cause_PR_nas, S1AP_CauseNas_authentication_failure); + ogs_expect_or_return(s1apbuf); + + s1ap_send_to_enb_ue(enb_ue, s1apbuf); + return; + } + + /* Update Security Context (NextHop) */ + mme_ue->nhcc++; + ogs_kdf_nh_enb(mme_ue->kasme, mme_ue->nh, mme_ue->nh); + ogs_assert(E_RABToBeSwitchedDLList); for (i = 0; i < E_RABToBeSwitchedDLList->list.count; i++) { S1AP_E_RABToBeSwitchedDLItemIEs_t *ie2 = NULL; @@ -1382,9 +1389,6 @@ void s1ap_handle_path_switch_request( mme_gtp_send_modify_bearer_request(bearer, 1); } - - /* Switch to enb */ - enb_ue_switch_to_enb(enb_ue, enb); } void s1ap_handle_enb_configuration_transfer( diff --git a/src/smf/ngap-build.h b/src/smf/ngap-build.h index a56869691..fd1e42c4f 100644 --- a/src/smf/ngap-build.h +++ b/src/smf/ngap-build.h @@ -34,7 +34,9 @@ ogs_pkbuf_t *ngap_build_qos_flow_resource_modify_request_transfer( ogs_pkbuf_t *ngap_build_pdu_session_resource_release_command_transfer( NGAP_Cause_PR group, long cause); + ogs_pkbuf_t *ngap_build_path_switch_request_ack_transfer(smf_sess_t *sess); + #ifdef __cplusplus } #endif diff --git a/tests/common/context.c b/tests/common/context.c index 815e4b322..be7443d2b 100644 --- a/tests/common/context.c +++ b/tests/common/context.c @@ -1132,7 +1132,7 @@ test_bearer_t *test_bearer_find_by_ue_ebi(test_ue_t *test_ue, uint8_t ebi) return NULL; } -test_bearer_t *test_qos_flow_find_by_sess_qfi(test_sess_t *sess, uint8_t qfi) +test_bearer_t *test_qos_flow_find_by_qfi(test_sess_t *sess, uint8_t qfi) { test_bearer_t *qos_flow = NULL; @@ -1143,19 +1143,3 @@ test_bearer_t *test_qos_flow_find_by_sess_qfi(test_sess_t *sess, uint8_t qfi) return NULL; } - -test_bearer_t *test_qos_flow_find_by_ue_qfi(test_ue_t *test_ue, uint8_t qfi) -{ - test_sess_t *sess = NULL; - test_bearer_t *qos_flow = NULL; - - ogs_assert(test_ue); - - ogs_list_for_each(&test_ue->sess_list, sess) { - qos_flow = test_qos_flow_find_by_sess_qfi(sess, qfi); - if (qos_flow) return qos_flow; - - } - - return NULL; -} diff --git a/tests/common/context.h b/tests/common/context.h index bc1713023..80c76a0dd 100644 --- a/tests/common/context.h +++ b/tests/common/context.h @@ -466,8 +466,7 @@ void test_bearer_remove_all(test_sess_t *sess); test_bearer_t *test_bearer_find_by_sess_ebi(test_sess_t *sess, uint8_t ebi); test_bearer_t *test_bearer_find_by_ue_ebi(test_ue_t *test_ue, uint8_t ebi); -test_bearer_t *test_qos_flow_find_by_sess_qfi(test_sess_t *sess, uint8_t qfi); -test_bearer_t *test_qos_flow_find_by_ue_qfi(test_ue_t *test_ue, uint8_t qfi); +test_bearer_t *test_qos_flow_find_by_qfi(test_sess_t *sess, uint8_t qfi); #ifdef __cplusplus } diff --git a/tests/common/gsm-build.c b/tests/common/gsm-build.c index 65dbe907c..ab89f8fa6 100644 --- a/tests/common/gsm-build.c +++ b/tests/common/gsm-build.c @@ -35,7 +35,10 @@ ogs_pkbuf_t *testgsm_build_pdu_session_establishment_request( #endif ogs_nas_extended_protocol_configuration_options_t *extended_protocol_configuration_options = NULL; - uint8_t ue_pco[10] = "\x80\x00\x0a\x00\x00\x03\x00\x00\x0d\x00"; + uint8_t ue_pco[35] = + "\x80\x80\x21\x10\x01\x00\x00\x10\x81\x06\x00\x00\x00\x00" + "\x83\x06\x00\x00\x00\x00\x00\x0c\x00\x00\x0d\x00\x00\x02\x00\x00" + "\x0a\x00\x00\x10\x00"; ogs_s_nssai_t *s_nssai = NULL; @@ -80,7 +83,7 @@ ogs_pkbuf_t *testgsm_build_pdu_session_establishment_request( pdu_session_establishment_request->presencemask |= OGS_NAS_5GS_PDU_SESSION_ESTABLISHMENT_REQUEST_EXTENDED_PROTOCOL_CONFIGURATION_OPTIONS_PRESENT; - extended_protocol_configuration_options->length = 10; + extended_protocol_configuration_options->length = sizeof(ue_pco); extended_protocol_configuration_options->buffer = ue_pco; s_nssai = &test_self()->plmn_support[0].s_nssai[0]; diff --git a/tests/common/ngap-build.c b/tests/common/ngap-build.c index 71da038c0..fe0322261 100644 --- a/tests/common/ngap-build.c +++ b/tests/common/ngap-build.c @@ -397,9 +397,10 @@ ogs_pkbuf_t *testngap_build_uplink_nas_transport( } ogs_pkbuf_t *testngap_build_initial_context_setup_response( - test_ue_t *test_ue, test_sess_t *sess) + test_ue_t *test_ue, bool pdu_session) { int rv; + test_sess_t *sess = NULL; NGAP_NGAP_PDU_t pdu; NGAP_SuccessfulOutcome_t *successfulOutcome = NULL; @@ -446,36 +447,44 @@ ogs_pkbuf_t *testngap_build_initial_context_setup_response( asn_uint642INTEGER(AMF_UE_NGAP_ID, test_ue->amf_ue_ngap_id); *RAN_UE_NGAP_ID = test_ue->ran_ue_ngap_id; - if (sess) { + if (pdu_session) { NGAP_PDUSessionResourceSetupListCxtRes_t *PDUSessionList = NULL; NGAP_PDUSessionResourceSetupItemCxtRes_t *PDUSessionItem = NULL; - OCTET_STRING_t *transfer = NULL; - ogs_pkbuf_t *n2smbuf = NULL; - ie = CALLOC(1, sizeof(NGAP_InitialContextSetupResponseIEs_t)); - ASN_SEQUENCE_ADD(&InitialContextSetupResponse->protocolIEs, ie); + ogs_list_for_each(&test_ue->sess_list, sess) { + OCTET_STRING_t *transfer = NULL; + ogs_pkbuf_t *n2smbuf = NULL; - ie->id = NGAP_ProtocolIE_ID_id_PDUSessionResourceSetupListCxtRes; - ie->criticality = NGAP_Criticality_ignore; - ie->value.present = NGAP_InitialContextSetupResponseIEs__value_PR_PDUSessionResourceSetupListCxtRes; + if (!PDUSessionList) { + ie = CALLOC(1, sizeof(NGAP_InitialContextSetupResponseIEs_t)); + ASN_SEQUENCE_ADD(&InitialContextSetupResponse->protocolIEs, ie); - PDUSessionList = &ie->value.choice.PDUSessionResourceSetupListCxtRes; + ie->id = + NGAP_ProtocolIE_ID_id_PDUSessionResourceSetupListCxtRes; + ie->criticality = NGAP_Criticality_ignore; + ie->value.present = NGAP_InitialContextSetupResponseIEs__value_PR_PDUSessionResourceSetupListCxtRes; - PDUSessionItem = - CALLOC(1, sizeof(struct NGAP_PDUSessionResourceSetupItemCxtRes)); - ASN_SEQUENCE_ADD(&PDUSessionList->list, PDUSessionItem); + PDUSessionList = + &ie->value.choice.PDUSessionResourceSetupListCxtRes; + } - PDUSessionItem->pDUSessionID = sess->psi; + PDUSessionItem = CALLOC(1, + sizeof(struct NGAP_PDUSessionResourceSetupItemCxtRes)); + ASN_SEQUENCE_ADD(&PDUSessionList->list, PDUSessionItem); - n2smbuf = testngap_build_pdu_session_resource_setup_response_trasfer( - sess); - ogs_assert(n2smbuf); - transfer = &PDUSessionItem->pDUSessionResourceSetupResponseTransfer; + PDUSessionItem->pDUSessionID = sess->psi; - transfer->size = n2smbuf->len; - transfer->buf = CALLOC(transfer->size, sizeof(uint8_t)); - memcpy(transfer->buf, n2smbuf->data, transfer->size); - ogs_pkbuf_free(n2smbuf); + n2smbuf = + testngap_build_pdu_session_resource_setup_response_trasfer( + sess); + ogs_assert(n2smbuf); + transfer = &PDUSessionItem->pDUSessionResourceSetupResponseTransfer; + + transfer->size = n2smbuf->len; + transfer->buf = CALLOC(transfer->size, sizeof(uint8_t)); + memcpy(transfer->buf, n2smbuf->data, transfer->size); + ogs_pkbuf_free(n2smbuf); + } } return ogs_ngap_encode(&pdu); @@ -649,8 +658,6 @@ ogs_pkbuf_t *testngap_build_ue_context_release_request(test_ue_t *test_ue, NGAP_UEContextReleaseRequest_IEs_t *ie = NULL; NGAP_AMF_UE_NGAP_ID_t *AMF_UE_NGAP_ID = NULL; NGAP_RAN_UE_NGAP_ID_t *RAN_UE_NGAP_ID = NULL; - NGAP_PDUSessionResourceListCxtRelReq_t *PDUSessionList = NULL; - NGAP_PDUSessionResourceItemCxtRelReq_t *PDUSessionItem = NULL; NGAP_Cause_t *Cause = NULL; memset(&pdu, 0, sizeof (NGAP_NGAP_PDU_t)); @@ -691,23 +698,28 @@ ogs_pkbuf_t *testngap_build_ue_context_release_request(test_ue_t *test_ue, *RAN_UE_NGAP_ID = test_ue->ran_ue_ngap_id; if (pdu_session) { - ie = CALLOC(1, sizeof(NGAP_UEContextReleaseRequest_IEs_t)); - ASN_SEQUENCE_ADD(&UEContextReleaseRequest->protocolIEs, ie); + NGAP_PDUSessionResourceListCxtRelReq_t *PDUSessionList = NULL; + NGAP_PDUSessionResourceItemCxtRelReq_t *PDUSessionItem = NULL; - ie->id = NGAP_ProtocolIE_ID_id_PDUSessionResourceListCxtRelReq; - ie->criticality = NGAP_Criticality_reject; - ie->value.present = NGAP_UEContextReleaseRequest_IEs__value_PR_PDUSessionResourceListCxtRelReq; + ogs_list_for_each(&test_ue->sess_list, sess) { + if (!PDUSessionList) { + ie = CALLOC(1, sizeof(NGAP_UEContextReleaseRequest_IEs_t)); + ASN_SEQUENCE_ADD(&UEContextReleaseRequest->protocolIEs, ie); - PDUSessionList = &ie->value.choice.PDUSessionResourceListCxtRelReq; + ie->id = NGAP_ProtocolIE_ID_id_PDUSessionResourceListCxtRelReq; + ie->criticality = NGAP_Criticality_reject; + ie->value.present = NGAP_UEContextReleaseRequest_IEs__value_PR_PDUSessionResourceListCxtRelReq; - PDUSessionItem = - CALLOC(1, sizeof(struct NGAP_PDUSessionResourceItemCxtRelReq)); - ASN_SEQUENCE_ADD(&PDUSessionList->list, PDUSessionItem); + PDUSessionList = + &ie->value.choice.PDUSessionResourceListCxtRelReq; + } - sess = ogs_list_first(&test_ue->sess_list); - ogs_assert(sess); + PDUSessionItem = + CALLOC(1, sizeof(struct NGAP_PDUSessionResourceItemCxtRelReq)); + ASN_SEQUENCE_ADD(&PDUSessionList->list, PDUSessionItem); - PDUSessionItem->pDUSessionID = sess->psi; + PDUSessionItem->pDUSessionID = sess->psi; + } } ie = CALLOC(1, sizeof(NGAP_UEContextReleaseRequest_IEs_t)); @@ -1042,11 +1054,11 @@ ogs_pkbuf_t *testngap_build_pdu_session_resource_release_response( return ogs_ngap_encode(&pdu); } -ogs_pkbuf_t *testngap_build_path_switch_request(test_sess_t *sess) +ogs_pkbuf_t *testngap_build_path_switch_request(test_ue_t *test_ue) { int rv; - test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; ogs_pkbuf_t *n2smbuf = NULL; ogs_pkbuf_t *ngapbuf = NULL; @@ -1071,8 +1083,7 @@ ogs_pkbuf_t *testngap_build_path_switch_request(test_sess_t *sess) NGAP_TAI_t *tAI = NULL; OCTET_STRING_t *transfer = NULL; - ogs_assert(sess); - test_ue = sess->test_ue; + ogs_assert(test_ue); memset(&pdu, 0, sizeof (NGAP_NGAP_PDU_t)); @@ -1188,21 +1199,23 @@ ogs_pkbuf_t *testngap_build_path_switch_request(test_sess_t *sess) UESecurityCapabilities->eUTRAintegrityProtectionAlgorithms.buf[0] = (test_ue->ue_security_capability.eps_ia << 1); - PDUSessionItem = - CALLOC(1, sizeof(NGAP_PDUSessionResourceToBeSwitchedDLItem_t)); - ASN_SEQUENCE_ADD( - &PDUSessionResourceToBeSwitchedDLList->list, PDUSessionItem); + ogs_list_for_each(&test_ue->sess_list, sess) { + PDUSessionItem = + CALLOC(1, sizeof(NGAP_PDUSessionResourceToBeSwitchedDLItem_t)); + ASN_SEQUENCE_ADD( + &PDUSessionResourceToBeSwitchedDLList->list, PDUSessionItem); - PDUSessionItem->pDUSessionID = sess->psi; + PDUSessionItem->pDUSessionID = sess->psi; - n2smbuf = testngap_build_path_switch_request_trasfer(sess); - ogs_assert(n2smbuf); - transfer = &PDUSessionItem->pathSwitchRequestTransfer; + n2smbuf = testngap_build_path_switch_request_trasfer(sess); + ogs_assert(n2smbuf); + transfer = &PDUSessionItem->pathSwitchRequestTransfer; - transfer->size = n2smbuf->len; - transfer->buf = CALLOC(transfer->size, sizeof(uint8_t)); - memcpy(transfer->buf, n2smbuf->data, transfer->size); - ogs_pkbuf_free(n2smbuf); + transfer->size = n2smbuf->len; + transfer->buf = CALLOC(transfer->size, sizeof(uint8_t)); + memcpy(transfer->buf, n2smbuf->data, transfer->size); + ogs_pkbuf_free(n2smbuf); + } return ogs_ngap_encode(&pdu); } diff --git a/tests/common/ngap-build.h b/tests/common/ngap-build.h index c14ddb02c..3a3d92d4d 100644 --- a/tests/common/ngap-build.h +++ b/tests/common/ngap-build.h @@ -31,7 +31,7 @@ ogs_pkbuf_t *testngap_build_uplink_nas_transport( test_ue_t *test_ue, ogs_pkbuf_t *gmmbuf); ogs_pkbuf_t *testngap_build_initial_context_setup_response( - test_ue_t *test_ue, test_sess_t *sess); + test_ue_t *test_ue, bool pdu_session); ogs_pkbuf_t *testngap_build_initial_context_setup_failure(test_ue_t *test_ue, NGAP_Cause_PR group, long cause); @@ -49,7 +49,7 @@ ogs_pkbuf_t *testngap_build_pdu_session_resource_modify_response( ogs_pkbuf_t *testngap_build_pdu_session_resource_release_response( test_sess_t *sess); -ogs_pkbuf_t *testngap_build_path_switch_request(test_sess_t *sess); +ogs_pkbuf_t *testngap_build_path_switch_request(test_ue_t *test_ue); #ifdef __cplusplus } diff --git a/tests/common/ngap-handler.c b/tests/common/ngap-handler.c index ec906ad82..e75251562 100644 --- a/tests/common/ngap-handler.c +++ b/tests/common/ngap-handler.c @@ -302,7 +302,7 @@ void testngap_handle_pdu_session_resource_setup_request( (struct NGAP_QosFlowSetupRequestItem *) QosFlowSetupRequestList->list.array[l]; ogs_assert(QosFlowSetupRequestItem); - qos_flow = test_qos_flow_find_by_sess_qfi(sess, + qos_flow = test_qos_flow_find_by_qfi(sess, QosFlowSetupRequestItem->qosFlowIdentifier); if (!qos_flow) qos_flow = test_qos_flow_add(sess); @@ -425,7 +425,7 @@ void testngap_handle_pdu_session_resource_modify_request( (struct NGAP_QosFlowAddOrModifyRequestItem *) QosFlowAddOrModifyRequestList->list.array[l]; ogs_assert(QosFlowAddOrModifyRequestItem); - qos_flow = test_qos_flow_find_by_sess_qfi(sess, + qos_flow = test_qos_flow_find_by_qfi(sess, QosFlowAddOrModifyRequestItem-> qosFlowIdentifier); if (!qos_flow) diff --git a/tests/handover/5gc-xn-test.c b/tests/handover/5gc-xn-test.c index b12dc8405..b9c26d6be 100644 --- a/tests/handover/5gc-xn-test.c +++ b/tests/handover/5gc-xn-test.c @@ -154,9 +154,6 @@ static void test1_func(abts_case *tc, void *data) OGS_HEX(_k_string, strlen(_k_string), test_ue->k); OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); - sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); - ogs_assert(sess); - /* Two gNB connects to AMF */ ngap1 = testngap_client(AF_INET); ABTS_PTR_NOTNULL(tc, ngap1); @@ -288,7 +285,7 @@ static void test1_func(abts_case *tc, void *data) ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(test_ue, NULL); + sendbuf = testngap_build_initial_context_setup_response(test_ue, false); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap1, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -307,6 +304,9 @@ static void test1_func(abts_case *tc, void *data) testngap_recv(test_ue, recvbuf); /* Send PDU session establishment request */ + sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); + ogs_assert(sess); + sess->ul_nas_transport_param.request_type = OGS_NAS_5GS_REQUEST_TYPE_INITIAL; sess->ul_nas_transport_param.dnn = 1; @@ -328,7 +328,7 @@ static void test1_func(abts_case *tc, void *data) testngap_recv(test_ue, recvbuf); /* Send GTP-U ICMP Packet */ - qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 1); + qos_flow = test_qos_flow_find_by_qfi(sess, 1); ogs_assert(qos_flow); rv = test_gtpu_send_ping(gtpu1, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -359,7 +359,7 @@ static void test1_func(abts_case *tc, void *data) testngap_recv(test_ue, recvbuf); /* Send PDU session resource modify response */ - qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 2); + qos_flow = test_qos_flow_find_by_qfi(sess, 2); ogs_assert(qos_flow); sendbuf = testngap_build_pdu_session_resource_modify_response(qos_flow); @@ -400,7 +400,7 @@ static void test1_func(abts_case *tc, void *data) test_ue->ran_ue_ngap_id++; sess->gnb_n3_addr = test_self()->gnb2_addr; - sendbuf = testngap_build_path_switch_request(sess); + sendbuf = testngap_build_path_switch_request(test_ue); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap2, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -421,7 +421,7 @@ static void test1_func(abts_case *tc, void *data) testngap_recv(test_ue, recvbuf); /* Send GTP-U ICMP Packet */ - qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 1); + qos_flow = test_qos_flow_find_by_qfi(sess, 1); ogs_assert(qos_flow); rv = test_gtpu_send_ping(gtpu2, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -432,7 +432,7 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Send GTP-U ICMP Packet */ - qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 2); + qos_flow = test_qos_flow_find_by_qfi(sess, 2); ogs_assert(qos_flow); rv = test_gtpu_send_ping(gtpu2, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -447,7 +447,7 @@ static void test1_func(abts_case *tc, void *data) test_ue->ran_ue_ngap_id++; sess->gnb_n3_addr = test_self()->gnb1_addr; - sendbuf = testngap_build_path_switch_request(sess); + sendbuf = testngap_build_path_switch_request(test_ue); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap1, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -468,7 +468,7 @@ static void test1_func(abts_case *tc, void *data) testngap_recv(test_ue, recvbuf); /* Send GTP-U ICMP Packet */ - qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 1); + qos_flow = test_qos_flow_find_by_qfi(sess, 1); ogs_assert(qos_flow); rv = test_gtpu_send_ping(gtpu1, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -479,7 +479,7 @@ static void test1_func(abts_case *tc, void *data) ogs_pkbuf_free(recvbuf); /* Send GTP-U ICMP Packet */ - qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 2); + qos_flow = test_qos_flow_find_by_qfi(sess, 2); ogs_assert(qos_flow); rv = test_gtpu_send_ping(gtpu1, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); diff --git a/tests/minimal/minimal-test.c b/tests/minimal/minimal-test.c index 7af899f64..11d090b1a 100644 --- a/tests/minimal/minimal-test.c +++ b/tests/minimal/minimal-test.c @@ -119,12 +119,6 @@ static void test1_func(abts_case *tc, void *data) OGS_HEX(_k_string, strlen(_k_string), test_ue->k); OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); - sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 10); - ogs_assert(sess); - - sess->pti = 0; - sess->pdu_session_type = OGS_PDU_SESSION_TYPE_IPV4; - /* gNB connects to AMF */ ngap = testngap_client(AF_INET); ABTS_PTR_NOTNULL(tc, ngap); @@ -222,7 +216,7 @@ static void test1_func(abts_case *tc, void *data) ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(test_ue, NULL); + sendbuf = testngap_build_initial_context_setup_response(test_ue, false); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -241,6 +235,12 @@ static void test1_func(abts_case *tc, void *data) testngap_recv(test_ue, recvbuf); /* Send PDU session establishment request */ + sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 10); + ogs_assert(sess); + + sess->pti = 0; + sess->pdu_session_type = OGS_PDU_SESSION_TYPE_IPV4; + sess->ul_nas_transport_param.request_type = OGS_NAS_5GS_REQUEST_TYPE_INITIAL; sess->ul_nas_transport_param.dnn = 1; @@ -262,7 +262,7 @@ static void test1_func(abts_case *tc, void *data) testngap_recv(test_ue, recvbuf); /* Send GTP-U ICMP Packet */ - qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 1); + qos_flow = test_qos_flow_find_by_qfi(sess, 1); ogs_assert(qos_flow); rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); diff --git a/tests/registration/auth-test.c b/tests/registration/auth-test.c index 115e061bf..15b9f0aa4 100644 --- a/tests/registration/auth-test.c +++ b/tests/registration/auth-test.c @@ -34,7 +34,6 @@ static void test1_func(abts_case *tc, void *data) ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; test_ue_t *test_ue = NULL; - test_sess_t *sess = NULL; test_bearer_t *qos_flow = NULL; const char *_k_string = "70d49a71dd1a2b806a25abe0ef749f1e"; @@ -115,9 +114,6 @@ static void test1_func(abts_case *tc, void *data) OGS_HEX(_k_string, strlen(_k_string), test_ue->k); OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); - sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); - ogs_assert(sess); - /* gNB connects to AMF */ ngap = testngap_client(AF_INET); ABTS_PTR_NOTNULL(tc, ngap); diff --git a/tests/registration/dereg-test.c b/tests/registration/dereg-test.c index 97aad9475..2378a4cc2 100644 --- a/tests/registration/dereg-test.c +++ b/tests/registration/dereg-test.c @@ -119,9 +119,6 @@ static void test1_func(abts_case *tc, void *data) OGS_HEX(_k_string, strlen(_k_string), test_ue->k); OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); - sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); - ogs_assert(sess); - /* gNB connects to AMF */ ngap = testngap_client(AF_INET); ABTS_PTR_NOTNULL(tc, ngap); @@ -224,7 +221,7 @@ static void test1_func(abts_case *tc, void *data) ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(test_ue, NULL); + sendbuf = testngap_build_initial_context_setup_response(test_ue, false); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -253,6 +250,9 @@ static void test1_func(abts_case *tc, void *data) #endif /* Send PDU session establishment request */ + sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); + ogs_assert(sess); + sess->ul_nas_transport_param.request_type = OGS_NAS_5GS_REQUEST_TYPE_INITIAL; sess->ul_nas_transport_param.dnn = 1; @@ -274,7 +274,7 @@ static void test1_func(abts_case *tc, void *data) testngap_recv(test_ue, recvbuf); /* Send GTP-U ICMP Packet */ - qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 1); + qos_flow = test_qos_flow_find_by_qfi(sess, 1); ogs_assert(qos_flow); rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -354,7 +354,6 @@ static void test2_func(abts_case *tc, void *data) ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; test_ue_t *test_ue = NULL; - test_sess_t *sess = NULL; test_bearer_t *qos_flow = NULL; const char *_k_string = "70d49a71dd1a2b806a25abe0ef749f1e"; @@ -439,9 +438,6 @@ static void test2_func(abts_case *tc, void *data) OGS_HEX(_k_string, strlen(_k_string), test_ue->k); OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); - sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); - ogs_assert(sess); - /* gNB connects to AMF */ ngap = testngap_client(AF_INET); ABTS_PTR_NOTNULL(tc, ngap); @@ -544,7 +540,7 @@ static void test2_func(abts_case *tc, void *data) ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(test_ue, NULL); + sendbuf = testngap_build_initial_context_setup_response(test_ue, false); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -698,9 +694,6 @@ static void test3_func(abts_case *tc, void *data) OGS_HEX(_k_string, strlen(_k_string), test_ue->k); OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); - sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); - ogs_assert(sess); - /* gNB connects to AMF */ ngap = testngap_client(AF_INET); ABTS_PTR_NOTNULL(tc, ngap); @@ -804,7 +797,7 @@ static void test3_func(abts_case *tc, void *data) ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(test_ue, NULL); + sendbuf = testngap_build_initial_context_setup_response(test_ue, false); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -823,6 +816,9 @@ static void test3_func(abts_case *tc, void *data) testngap_recv(test_ue, recvbuf); /* Send PDU session establishment request */ + sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); + ogs_assert(sess); + sess->ul_nas_transport_param.request_type = OGS_NAS_5GS_REQUEST_TYPE_INITIAL; sess->ul_nas_transport_param.dnn = 1; @@ -844,7 +840,7 @@ static void test3_func(abts_case *tc, void *data) testngap_recv(test_ue, recvbuf); /* Send GTP-U ICMP Packet */ - qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 1); + qos_flow = test_qos_flow_find_by_qfi(sess, 1); ogs_assert(qos_flow); rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -962,7 +958,7 @@ static void test3_func(abts_case *tc, void *data) ABTS_INT_EQUAL(tc, 0x0000, test_ue->pdu_session_reactivation_result); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(test_ue, NULL); + sendbuf = testngap_build_initial_context_setup_response(test_ue, false); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -989,7 +985,7 @@ static void test3_func(abts_case *tc, void *data) testngap_recv(test_ue, recvbuf); /* Send GTP-U ICMP Packet */ - qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 1); + qos_flow = test_qos_flow_find_by_qfi(sess, 1); ogs_assert(qos_flow); rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1257,7 +1253,7 @@ static void test4_func(abts_case *tc, void *data) ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(test_ue, NULL); + sendbuf = testngap_build_initial_context_setup_response(test_ue, false); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1304,7 +1300,7 @@ static void test4_func(abts_case *tc, void *data) ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send GTP-U ICMP Packet */ - qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 1); + qos_flow = test_qos_flow_find_by_qfi(sess, 1); ogs_assert(qos_flow); rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); diff --git a/tests/registration/gmm-status-test.c b/tests/registration/gmm-status-test.c index 933db47b6..63cf0d6a4 100644 --- a/tests/registration/gmm-status-test.c +++ b/tests/registration/gmm-status-test.c @@ -115,9 +115,6 @@ static void test1_func(abts_case *tc, void *data) OGS_HEX(_k_string, strlen(_k_string), test_ue->k); OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); - sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); - ogs_assert(sess); - /* gNB connects to AMF */ ngap = testngap_client(AF_INET); ABTS_PTR_NOTNULL(tc, ngap); @@ -214,7 +211,7 @@ static void test1_func(abts_case *tc, void *data) testngap_recv(test_ue, recvbuf); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(test_ue, NULL); + sendbuf = testngap_build_initial_context_setup_response(test_ue, false); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -233,6 +230,9 @@ static void test1_func(abts_case *tc, void *data) testngap_recv(test_ue, recvbuf); /* Send PDU session establishment request */ + sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); + ogs_assert(sess); + sess->ul_nas_transport_param.request_type = OGS_NAS_5GS_REQUEST_TYPE_INITIAL; sess->ul_nas_transport_param.dnn = 1; diff --git a/tests/registration/guti-test.c b/tests/registration/guti-test.c index 54702a556..60bc404f4 100644 --- a/tests/registration/guti-test.c +++ b/tests/registration/guti-test.c @@ -115,9 +115,6 @@ static void test1_func(abts_case *tc, void *data) OGS_HEX(_k_string, strlen(_k_string), test_ue->k); OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); - sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); - ogs_assert(sess); - /* gNB connects to AMF */ ngap = testngap_client(AF_INET); ABTS_PTR_NOTNULL(tc, ngap); @@ -234,7 +231,7 @@ static void test1_func(abts_case *tc, void *data) ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(test_ue, NULL); + sendbuf = testngap_build_initial_context_setup_response(test_ue, false); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -253,6 +250,9 @@ static void test1_func(abts_case *tc, void *data) testngap_recv(test_ue, recvbuf); /* Send PDU session establishment request */ + sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); + ogs_assert(sess); + sess->ul_nas_transport_param.request_type = OGS_NAS_5GS_REQUEST_TYPE_INITIAL; sess->ul_nas_transport_param.dnn = 0; @@ -274,7 +274,7 @@ static void test1_func(abts_case *tc, void *data) testngap_recv(test_ue, recvbuf); /* Send GTP-U ICMP Packet */ - qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 1); + qos_flow = test_qos_flow_find_by_qfi(sess, 1); ogs_assert(qos_flow); rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -350,14 +350,13 @@ static void test1_func(abts_case *tc, void *data) ABTS_INT_EQUAL(tc, 0x0000, test_ue->pdu_session_reactivation_result); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response( - test_ue, sess); + sendbuf = testngap_build_initial_context_setup_response(test_ue, true); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send GTP-U ICMP Packet */ - qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 1); + qos_flow = test_qos_flow_find_by_qfi(sess, 1); ogs_assert(qos_flow); rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -433,7 +432,7 @@ static void test1_func(abts_case *tc, void *data) testngap_recv(test_ue, recvbuf); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(test_ue, NULL); + sendbuf = testngap_build_initial_context_setup_response(test_ue, false); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -479,7 +478,7 @@ static void test1_func(abts_case *tc, void *data) ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send GTP-U ICMP Packet */ - qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 1); + qos_flow = test_qos_flow_find_by_qfi(sess, 1); ogs_assert(qos_flow); rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); diff --git a/tests/registration/identity-test.c b/tests/registration/identity-test.c index f2eff7bb7..50a72dd03 100644 --- a/tests/registration/identity-test.c +++ b/tests/registration/identity-test.c @@ -115,9 +115,6 @@ static void test1_func(abts_case *tc, void *data) OGS_HEX(_k_string, strlen(_k_string), test_ue->k); OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); - sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); - ogs_assert(sess); - /* gNB connects to AMF */ ngap = testngap_client(AF_INET); ABTS_PTR_NOTNULL(tc, ngap); @@ -220,7 +217,7 @@ static void test1_func(abts_case *tc, void *data) ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(test_ue, NULL); + sendbuf = testngap_build_initial_context_setup_response(test_ue, false); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -239,6 +236,9 @@ static void test1_func(abts_case *tc, void *data) testngap_recv(test_ue, recvbuf); /* Send PDU session establishment request */ + sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); + ogs_assert(sess); + sess->ul_nas_transport_param.request_type = OGS_NAS_5GS_REQUEST_TYPE_INITIAL; sess->ul_nas_transport_param.dnn = 1; @@ -298,8 +298,7 @@ static void test1_func(abts_case *tc, void *data) testngap_recv(test_ue, recvbuf); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response( - test_ue, sess); + sendbuf = testngap_build_initial_context_setup_response(test_ue, true); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); diff --git a/tests/registration/idle-test.c b/tests/registration/idle-test.c index dea957d6c..bc432f029 100644 --- a/tests/registration/idle-test.c +++ b/tests/registration/idle-test.c @@ -115,9 +115,6 @@ static void test1_func(abts_case *tc, void *data) OGS_HEX(_k_string, strlen(_k_string), test_ue->k); OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); - sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); - ogs_assert(sess); - /* gNB connects to AMF */ ngap = testngap_client(AF_INET); ABTS_PTR_NOTNULL(tc, ngap); @@ -220,7 +217,7 @@ static void test1_func(abts_case *tc, void *data) ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(test_ue, NULL); + sendbuf = testngap_build_initial_context_setup_response(test_ue, false); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -239,6 +236,9 @@ static void test1_func(abts_case *tc, void *data) testngap_recv(test_ue, recvbuf); /* Send PDU session establishment request */ + sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); + ogs_assert(sess); + sess->ul_nas_transport_param.request_type = OGS_NAS_5GS_REQUEST_TYPE_INITIAL; sess->ul_nas_transport_param.dnn = 1; @@ -260,7 +260,7 @@ static void test1_func(abts_case *tc, void *data) testngap_recv(test_ue, recvbuf); /* Send GTP-U ICMP Packet */ - qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 1); + qos_flow = test_qos_flow_find_by_qfi(sess, 1); ogs_assert(qos_flow); rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -337,8 +337,7 @@ static void test1_func(abts_case *tc, void *data) ABTS_INT_EQUAL(tc, 0x0000, test_ue->pdu_session_reactivation_result); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response( - test_ue, sess); + sendbuf = testngap_build_initial_context_setup_response(test_ue, true); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -411,7 +410,7 @@ static void test1_func(abts_case *tc, void *data) ABTS_INT_EQUAL(tc, 0x0000, test_ue->pdu_session_reactivation_result); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(test_ue, sess); + sendbuf = testngap_build_initial_context_setup_response(test_ue, true); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -485,7 +484,6 @@ static void test2_func(abts_case *tc, void *data) ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; test_ue_t *test_ue = NULL; - test_sess_t *sess = NULL; test_bearer_t *qos_flow = NULL; const char *_k_string = "70d49a71dd1a2b806a25abe0ef749f1e"; @@ -566,9 +564,6 @@ static void test2_func(abts_case *tc, void *data) OGS_HEX(_k_string, strlen(_k_string), test_ue->k); OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); - sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); - ogs_assert(sess); - /* gNB connects to AMF */ ngap = testngap_client(AF_INET); ABTS_PTR_NOTNULL(tc, ngap); @@ -875,9 +870,6 @@ static void test3_func(abts_case *tc, void *data) OGS_HEX(_k_string, strlen(_k_string), test_ue->k); OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); - sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); - ogs_assert(sess); - /* gNB connects to AMF */ ngap = testngap_client(AF_INET); ABTS_PTR_NOTNULL(tc, ngap); @@ -999,6 +991,9 @@ static void test3_func(abts_case *tc, void *data) testngap_recv(test_ue, recvbuf); /* Send PDU session establishment request */ + sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); + ogs_assert(sess); + sess->ul_nas_transport_param.request_type = OGS_NAS_5GS_REQUEST_TYPE_INITIAL; sess->ul_nas_transport_param.dnn = 1; @@ -1020,7 +1015,7 @@ static void test3_func(abts_case *tc, void *data) testngap_recv(test_ue, recvbuf); /* Send GTP-U ICMP Packet */ - qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 1); + qos_flow = test_qos_flow_find_by_qfi(sess, 1); ogs_assert(qos_flow); rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1277,9 +1272,6 @@ static void test4_func(abts_case *tc, void *data) OGS_HEX(_k_string, strlen(_k_string), test_ue->k); OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); - sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); - ogs_assert(sess); - /* gNB connects to AMF */ ngap = testngap_client(AF_INET); ABTS_PTR_NOTNULL(tc, ngap); @@ -1465,6 +1457,9 @@ static void test4_func(abts_case *tc, void *data) ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send PDU session establishment request */ + sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); + ogs_assert(sess); + sess->ul_nas_transport_param.request_type = OGS_NAS_5GS_REQUEST_TYPE_INITIAL; sess->ul_nas_transport_param.dnn = 1; @@ -1492,7 +1487,7 @@ static void test4_func(abts_case *tc, void *data) ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send GTP-U ICMP Packet */ - qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 1); + qos_flow = test_qos_flow_find_by_qfi(sess, 1); ogs_assert(qos_flow); rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -1914,7 +1909,7 @@ static void test5_func(abts_case *tc, void *data) testngap_recv(test_ue, recvbuf); /* Send GTP-U ICMP Packet */ - qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 1); + qos_flow = test_qos_flow_find_by_qfi(sess, 1); ogs_assert(qos_flow); rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -2347,7 +2342,7 @@ static void test6_func(abts_case *tc, void *data) testngap_recv(test_ue, recvbuf); /* Send GTP-U ICMP Packet */ - qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 1); + qos_flow = test_qos_flow_find_by_qfi(sess, 1); ogs_assert(qos_flow); rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -2426,8 +2421,7 @@ static void test6_func(abts_case *tc, void *data) ABTS_INT_EQUAL(tc, 0x0000, test_ue->pdu_session_reactivation_result); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response( - test_ue, sess); + sendbuf = testngap_build_initial_context_setup_response(test_ue, true); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); diff --git a/tests/registration/ue-context-test.c b/tests/registration/ue-context-test.c index d7786bb43..bea883c22 100644 --- a/tests/registration/ue-context-test.c +++ b/tests/registration/ue-context-test.c @@ -115,9 +115,6 @@ static void test1_func(abts_case *tc, void *data) OGS_HEX(_k_string, strlen(_k_string), test_ue->k); OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); - sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); - ogs_assert(sess); - /* gNB connects to AMF */ ngap = testngap_client(AF_INET); ABTS_PTR_NOTNULL(tc, ngap); @@ -346,9 +343,6 @@ static void test2_func(abts_case *tc, void *data) OGS_HEX(_k_string, strlen(_k_string), test_ue->k); OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); - sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); - ogs_assert(sess); - /* gNB connects to AMF */ ngap = testngap_client(AF_INET); ABTS_PTR_NOTNULL(tc, ngap); @@ -514,6 +508,9 @@ static void test2_func(abts_case *tc, void *data) /* SKIP Receive Configuration update command */ /* Send PDU session establishment request */ + sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); + ogs_assert(sess); + sess->ul_nas_transport_param.request_type = OGS_NAS_5GS_REQUEST_TYPE_INITIAL; sess->ul_nas_transport_param.dnn = 1; @@ -541,7 +538,7 @@ static void test2_func(abts_case *tc, void *data) ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send GTP-U ICMP Packet */ - qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 1); + qos_flow = test_qos_flow_find_by_qfi(sess, 1); ogs_assert(qos_flow); rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); diff --git a/tests/vonr/abts-main.c b/tests/vonr/abts-main.c index 79c0bc3be..b3ff6104f 100644 --- a/tests/vonr/abts-main.c +++ b/tests/vonr/abts-main.c @@ -20,11 +20,13 @@ #include "test-app.h" abts_suite *test_qos_flow(abts_suite *suite); +abts_suite *test_session(abts_suite *suite); const struct testlist { abts_suite *(*func)(abts_suite *suite); } alltests[] = { {test_qos_flow}, + {test_session}, {NULL}, }; diff --git a/tests/vonr/meson.build b/tests/vonr/meson.build index a37393d74..a5cc30f02 100644 --- a/tests/vonr/meson.build +++ b/tests/vonr/meson.build @@ -18,6 +18,7 @@ test5gc_vonr_sources = files(''' abts-main.c qos-flow-test.c + session-test.c '''.split()) test5gc_vonr_exe = executable('vonr', diff --git a/tests/vonr/qos-flow-test.c b/tests/vonr/qos-flow-test.c index 1ea904981..051643fff 100644 --- a/tests/vonr/qos-flow-test.c +++ b/tests/vonr/qos-flow-test.c @@ -154,9 +154,6 @@ static void test1_func(abts_case *tc, void *data) OGS_HEX(_k_string, strlen(_k_string), test_ue->k); OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); - sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); - ogs_assert(sess); - /* gNB connects to AMF */ ngap = testngap_client(AF_INET); ABTS_PTR_NOTNULL(tc, ngap); @@ -273,7 +270,7 @@ static void test1_func(abts_case *tc, void *data) ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(test_ue, NULL); + sendbuf = testngap_build_initial_context_setup_response(test_ue, false); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -292,6 +289,9 @@ static void test1_func(abts_case *tc, void *data) testngap_recv(test_ue, recvbuf); /* Send PDU session establishment request */ + sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); + ogs_assert(sess); + sess->ul_nas_transport_param.request_type = OGS_NAS_5GS_REQUEST_TYPE_INITIAL; sess->ul_nas_transport_param.dnn = 1; @@ -313,7 +313,7 @@ static void test1_func(abts_case *tc, void *data) testngap_recv(test_ue, recvbuf); /* Send GTP-U ICMP Packet */ - qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 1); + qos_flow = test_qos_flow_find_by_qfi(sess, 1); ogs_assert(qos_flow); rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -344,7 +344,7 @@ static void test1_func(abts_case *tc, void *data) testngap_recv(test_ue, recvbuf); /* Send PDU session resource modify response */ - qos_flow = test_qos_flow_find_by_ue_qfi(test_ue, 2); + qos_flow = test_qos_flow_find_by_qfi(sess, 2); ogs_assert(qos_flow); sendbuf = testngap_build_pdu_session_resource_modify_response(qos_flow); @@ -437,7 +437,7 @@ static void test1_func(abts_case *tc, void *data) ABTS_INT_EQUAL(tc, OGS_OK, rv); /* Send Initial context setup response */ - sendbuf = testngap_build_initial_context_setup_response(test_ue, sess); + sendbuf = testngap_build_initial_context_setup_response(test_ue, true); ABTS_PTR_NOTNULL(tc, sendbuf); rv = testgnb_ngap_send(ngap, sendbuf); ABTS_INT_EQUAL(tc, OGS_OK, rv); diff --git a/tests/vonr/session-test.c b/tests/vonr/session-test.c new file mode 100644 index 000000000..d36047fac --- /dev/null +++ b/tests/vonr/session-test.c @@ -0,0 +1,585 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "test-common.h" + +static void test1_func(abts_case *tc, void *data) +{ + int rv; + ogs_socknode_t *ngap; + ogs_socknode_t *gtpu; + ogs_pkbuf_t *gmmbuf; + ogs_pkbuf_t *gsmbuf; + ogs_pkbuf_t *nasbuf; + ogs_pkbuf_t *sendbuf; + ogs_pkbuf_t *recvbuf; + ogs_ngap_message_t message; + int i; + + uint8_t tmp[OGS_MAX_SDU_LEN]; + char *_gtp_payload = "34ff0024" + "0000000100000085 010002004500001c 0c0b000040015a7a 0a2d00010a2d0002" + "00000964cd7c291f"; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *qos_flow = NULL; + + const char *_k_string = "70d49a71dd1a2b806a25abe0ef749f1e"; + uint8_t k[OGS_KEY_LEN]; + const char *_opc_string = "6f1bf53d624b3a43af6592854e2444c7"; + uint8_t opc[OGS_KEY_LEN]; + + mongoc_collection_t *collection = NULL; + bson_t *doc = NULL; + int64_t count = 0; + bson_error_t error; + const char *json = + "{" + "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c6\" }, " + "\"imsi\" : \"901700000021309\"," + "\"ambr\" : { " + "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1024000\" } " + "}," + "\"pdn\" : [" + "{" + "\"apn\" : \"internet\", " + "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c6\" }, " + "\"ambr\" : {" + "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1024000\" } " + "}," + "\"qos\" : { " + "\"qci\" : 9, " + "\"arp\" : { " + "\"priority_level\" : 8," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" + "} " + "}, " + "\"type\" : 2" + "}," + "{" + "\"apn\" : \"ims\", " + "\"_id\" : { \"$oid\" : \"597223158b8861d7605378c7\" }, " + "\"ambr\" : {" + "\"uplink\" : { \"$numberLong\" : \"1024000\" }, " + "\"downlink\" : { \"$numberLong\" : \"1024000\" } " + "}," + "\"qos\" : { " + "\"qci\" : 6, " + "\"arp\" : { " + "\"priority_level\" : 6," + "\"pre_emption_vulnerability\" : 1, " + "\"pre_emption_capability\" : 1" + "} " + "}, " + "\"type\" : 2," + "\"pcc_rule\" : [" + "{" + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2d\" }," + "\"qos\" : {" + "\"qci\" : 1," + "\"gbr\" : {" + "\"downlink\" : { \"$numberLong\" : \"64\" }," + "\"uplink\" : { \"$numberLong\" : \"44\" }" + "}," + "\"mbr\" : {" + "\"downlink\" : { \"$numberLong\" : \"64\" }," + "\"uplink\" : { \"$numberLong\" : \"44\" }" + "}," + "\"arp\" : {" + "\"priority_level\" : 3," + "\"pre_emption_vulnerability\" : 0," + "\"pre_emption_capability\" : 0 }" + "}," + "\"flow\" : [" + "{ \"direction\" : 2," + "\"description\" : \"permit out udp from 10.200.136.98/32 23454 to assigned 1-65535\"," + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd31\" } }," + "{ \"direction\" : 1," + "\"description\" : \"permit out udp from 10.200.136.98/32 1-65535 to assigned 50020\"," + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd30\" } }," + "{ \"direction\" : 2," + "\"description\" : \"permit out udp from 10.200.136.98/32 23455 to assigned 1-65535\"," + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2f\" } }," + "{ \"direction\" : 1," + "\"description\" : \"permit out udp from 10.200.136.98/32 1-65535 to assigned 50021\"," + "\"_id\" : { \"$oid\" : \"599eb929c850caabcbfdcd2e\" } }" + "]" + "}" + "]" + "}" + "]," + "\"security\" : { " + "\"k\" : \"70d49a71dd1a2b806a25abe0ef749f1e\", " + "\"opc\" : \"6f1bf53d624b3a43af6592854e2444c7\", " + "\"amf\" : \"8000\", " + "\"sqn\" : { \"$numberLong\" : \"25235952177090\" } " + "}, " + "\"subscribed_rau_tau_timer\" : 12," + "\"network_access_mode\" : 2, " + "\"subscriber_status\" : 0, " + "\"access_restriction_data\" : 32, " + "\"__v\" : 0 " + "}"; + + /* Setup Test UE & Session Context */ + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0; + mobile_identity_suci.scheme_output[1] = 0; + mobile_identity_suci.scheme_output[2] = 0x20; + mobile_identity_suci.scheme_output[3] = 0x31; + mobile_identity_suci.scheme_output[4] = 0x90; + + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); + + test_ue->nr_cgi.cell_id = 0x40001; + + test_ue->nas.registration.type = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.registration.follow_on_request = 1; + test_ue->nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; + + OGS_HEX(_k_string, strlen(_k_string), test_ue->k); + OGS_HEX(_opc_string, strlen(_opc_string), test_ue->opc); + + /* gNB connects to AMF */ + ngap = testngap_client(AF_INET); + ABTS_PTR_NOTNULL(tc, ngap); + + /* gNB connects to UPF */ + gtpu = test_gtpu_server(1, AF_INET); + ABTS_PTR_NOTNULL(tc, gtpu); + + /* Send NG-Setup Reqeust */ + sendbuf = testngap_build_ng_setup_request(0x4000, 22); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive NG-Setup Response */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(test_ue, recvbuf); + + /********** Insert Subscriber in Database */ + collection = mongoc_client_get_collection( + ogs_mongoc()->client, ogs_mongoc()->name, "subscribers"); + ABTS_PTR_NOTNULL(tc, collection); + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + if (count) { + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + } + bson_destroy(doc); + + doc = bson_new_from_json((const uint8_t *)json, -1, &error);; + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_insert(collection, + MONGOC_INSERT_NONE, doc, NULL, &error)); + bson_destroy(doc); + + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + do { + count = mongoc_collection_count ( + collection, MONGOC_QUERY_NONE, doc, 0, 0, NULL, &error); + } while (count == 0); + bson_destroy(doc); + + /* Send Registration request */ + test_ue->registration_request_param.guti = 1; + gmmbuf = testgmm_build_registration_request(test_ue, NULL); + ABTS_PTR_NOTNULL(tc, gmmbuf); + + test_ue->registration_request_param.gmm_capability = 1; + test_ue->registration_request_param.requested_nssai = 1; + test_ue->registration_request_param.last_visited_registered_tai = 1; + test_ue->registration_request_param.ue_usage_setting = 1; + nasbuf = testgmm_build_registration_request(test_ue, NULL); + ABTS_PTR_NOTNULL(tc, nasbuf); + + sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf, false); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Identity request */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(test_ue, recvbuf); + + /* Send Identity response */ + gmmbuf = testgmm_build_identity_response(test_ue); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication request */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(test_ue, recvbuf); + + /* Send Authentication response */ + gmmbuf = testgmm_build_authentication_response(test_ue); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Security mode command */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(test_ue, recvbuf); + + /* Send Security mode complete */ + gmmbuf = testgmm_build_security_mode_complete(test_ue, nasbuf); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Initial context setup request */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(test_ue, recvbuf); + + /* Send UE radio capability info indication */ + sendbuf = testngap_build_ue_radio_capability_info_indication(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Initial context setup response */ + sendbuf = testngap_build_initial_context_setup_response(test_ue, false); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Registration complete */ + gmmbuf = testgmm_build_registration_complete(test_ue); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Configuration update command */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(test_ue, recvbuf); + + /* Send PDU session establishment request */ + sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); + ogs_assert(sess); + + sess->ul_nas_transport_param.request_type = + OGS_NAS_5GS_REQUEST_TYPE_INITIAL; + sess->ul_nas_transport_param.dnn = 1; + sess->ul_nas_transport_param.s_nssai = 1; + + gsmbuf = testgsm_build_pdu_session_establishment_request(sess); + ABTS_PTR_NOTNULL(tc, gsmbuf); + gmmbuf = testgmm_build_ul_nas_transport(sess, + OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive PDU session establishment accept */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(test_ue, recvbuf); + + /* Send GTP-U ICMP Packet */ + qos_flow = test_qos_flow_find_by_qfi(sess, 1); + ogs_assert(qos_flow); + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send PDU session resource setup response */ + sendbuf = testngap_build_pdu_session_resource_setup_response(sess); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = testgnb_gtpu_read(gtpu); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Send GTP-U ICMP Packet */ + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = testgnb_gtpu_read(gtpu); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Send PDU session establishment request */ + sess = test_sess_add_by_dnn_and_psi(test_ue, "ims", 6); + ogs_assert(sess); + + sess->ul_nas_transport_param.request_type = + OGS_NAS_5GS_REQUEST_TYPE_INITIAL; + sess->ul_nas_transport_param.dnn = 1; + sess->ul_nas_transport_param.s_nssai = 1; + + gsmbuf = testgsm_build_pdu_session_establishment_request(sess); + ABTS_PTR_NOTNULL(tc, gsmbuf); + gmmbuf = testgmm_build_ul_nas_transport(sess, + OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive PDU session establishment accept */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(test_ue, recvbuf); + + /* Send PDU session resource setup response */ + sendbuf = testngap_build_pdu_session_resource_setup_response(sess); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive PDU session modification command */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(test_ue, recvbuf); + + /* Send PDU session resource modify response */ + qos_flow = test_qos_flow_find_by_qfi(sess, 2); + ogs_assert(qos_flow); + + sendbuf = testngap_build_pdu_session_resource_modify_response(qos_flow); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send PDU session resource modify complete */ + sess->ul_nas_transport_param.request_type = + OGS_NAS_5GS_REQUEST_TYPE_MODIFICATION_REQUEST; + sess->ul_nas_transport_param.dnn = 0; + sess->ul_nas_transport_param.s_nssai = 0; + + gsmbuf = testgsm_build_pdu_session_modification_complete(sess); + ABTS_PTR_NOTNULL(tc, gsmbuf); + gmmbuf = testgmm_build_ul_nas_transport(sess, + OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Waiting for creating dedicated QoS flow in PFCP protocol */ + ogs_msleep(100); + + /* Send GTP-U ICMP Packet */ + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = testgnb_gtpu_read(gtpu); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Send UE context release request */ + sendbuf = testngap_build_ue_context_release_request(test_ue, + NGAP_Cause_PR_radioNetwork, NGAP_CauseRadioNetwork_user_inactivity, + true); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive UE context release command */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(test_ue, recvbuf); + + /* Send UE context release complete */ + sendbuf = testngap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* + * Send Service request Using InitialUEMessage + * - Uplink Data Status + */ + test_ue->service_request_param.integrity_protected = 0; + test_ue->service_request_param.uplink_data_status = 1; + test_ue->service_request_param. + psimask.uplink_data_status = (1 << 5 | 1 << 6); + test_ue->service_request_param.pdu_session_status = 0; + nasbuf = testgmm_build_service_request(test_ue, NULL); + ABTS_PTR_NOTNULL(tc, nasbuf); + + test_ue->service_request_param.integrity_protected = 1; + test_ue->service_request_param.uplink_data_status = 0; + test_ue->service_request_param.pdu_session_status = 0; + gmmbuf = testgmm_build_service_request(test_ue, nasbuf); + ABTS_PTR_NOTNULL(tc, gmmbuf); + + sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf, true); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Service accept */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(test_ue, recvbuf); + ABTS_INT_EQUAL(tc, 0x0000, test_ue->pdu_session_status); + ABTS_INT_EQUAL(tc, 0x0000, test_ue->pdu_session_reactivation_result); + + /* Send GTP-U ICMP Packet */ + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Initial context setup response */ + sendbuf = testngap_build_initial_context_setup_response(test_ue, true); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = testgnb_gtpu_read(gtpu); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Send PDU Session release request */ + sess->ul_nas_transport_param.request_type = 0; + sess->ul_nas_transport_param.dnn = 0; + sess->ul_nas_transport_param.s_nssai = 0; + + gsmbuf = testgsm_build_pdu_session_release_request(sess); + ABTS_PTR_NOTNULL(tc, gsmbuf); + gmmbuf = testgmm_build_ul_nas_transport(sess, + OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive PDU session release command */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(test_ue, recvbuf); + + /* Send PDU session resource release response */ + sendbuf = testngap_build_pdu_session_resource_release_response(sess); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Test Session Remove */ + test_sess_remove(sess); + + /* Send PDU session resource release complete */ + sess->ul_nas_transport_param.request_type = 0; + sess->ul_nas_transport_param.dnn = 0; + sess->ul_nas_transport_param.s_nssai = 0; + + gsmbuf = testgsm_build_pdu_session_release_complete(sess); + ABTS_PTR_NOTNULL(tc, gsmbuf); + gmmbuf = testgmm_build_ul_nas_transport(sess, + OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send UE context release request */ + sendbuf = testngap_build_ue_context_release_request(test_ue, + NGAP_Cause_PR_radioNetwork, NGAP_CauseRadioNetwork_user_inactivity, + true); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive UE context release command */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(test_ue, recvbuf); + + /* Send UE context release complete */ + sendbuf = testngap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(300); + + /********** Remove Subscriber in Database */ + doc = BCON_NEW("imsi", BCON_UTF8(test_ue->imsi)); + ABTS_PTR_NOTNULL(tc, doc); + ABTS_TRUE(tc, mongoc_collection_remove(collection, + MONGOC_REMOVE_SINGLE_REMOVE, doc, NULL, &error)) + bson_destroy(doc); + + mongoc_collection_destroy(collection); + + /* gNB disonncect from UPF */ + testgnb_gtpu_close(gtpu); + + /* gNB disonncect from AMF */ + testgnb_ngap_close(ngap); + + /* Clear Test UE Context */ + test_ue_remove(test_ue); +} + +abts_suite *test_session(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, test1_func, NULL); + + return suite; +}