fix: AMF/SMF/UDM crash issues resolved (#770/#771)

This commit is contained in:
Sukchan Lee 2021-01-22 22:17:01 -05:00
parent 708784e222
commit 9eac90252e
16 changed files with 626 additions and 33 deletions

View File

@ -484,8 +484,6 @@ void ogs_sbi_nf_instance_clear(ogs_sbi_nf_instance_t *nf_instance)
ogs_freeaddrinfo(nf_instance->ipv6[i]);
}
nf_instance->num_of_ipv6 = 0;
ogs_sbi_nf_service_remove_all(nf_instance);
}
void ogs_sbi_nf_instance_remove(ogs_sbi_nf_instance_t *nf_instance)
@ -502,12 +500,13 @@ void ogs_sbi_nf_instance_remove(ogs_sbi_nf_instance_t *nf_instance)
ogs_list_remove(&ogs_sbi_self()->nf_instance_list, nf_instance);
ogs_sbi_subscription_remove_all_by_nf_instance_id(nf_instance->id);
ogs_sbi_nf_service_remove_all(nf_instance);
ogs_sbi_nf_instance_clear(nf_instance);
ogs_assert(nf_instance->id);
ogs_free(nf_instance->id);
ogs_sbi_nf_instance_clear(nf_instance);
ogs_timer_delete(nf_instance->t_registration_interval);
ogs_timer_delete(nf_instance->t_heartbeat_interval);
ogs_timer_delete(nf_instance->t_no_heartbeat);
@ -657,7 +656,24 @@ void ogs_sbi_nf_service_remove_all(ogs_sbi_nf_instance_t *nf_instance)
ogs_sbi_nf_service_remove(nf_service);
}
ogs_sbi_nf_service_t *ogs_sbi_nf_service_find(
ogs_sbi_nf_service_t *ogs_sbi_nf_service_find_by_id(
ogs_sbi_nf_instance_t *nf_instance, char *id)
{
ogs_sbi_nf_service_t *nf_service = NULL;
ogs_assert(nf_instance);
ogs_assert(id);
ogs_list_for_each(&nf_instance->nf_service_list, nf_service) {
ogs_assert(nf_service->id);
if (strcmp(nf_service->id, id) == 0)
break;
}
return nf_service;
}
ogs_sbi_nf_service_t *ogs_sbi_nf_service_find_by_name(
ogs_sbi_nf_instance_t *nf_instance, char *name)
{
ogs_sbi_nf_service_t *nf_service = NULL;

View File

@ -213,7 +213,9 @@ void ogs_sbi_nf_service_add_version(ogs_sbi_nf_service_t *nf_service,
void ogs_sbi_nf_service_clear(ogs_sbi_nf_service_t *nf_service);
void ogs_sbi_nf_service_remove(ogs_sbi_nf_service_t *nf_service);
void ogs_sbi_nf_service_remove_all(ogs_sbi_nf_instance_t *nf_instance);
ogs_sbi_nf_service_t *ogs_sbi_nf_service_find(
ogs_sbi_nf_service_t *ogs_sbi_nf_service_find_by_id(
ogs_sbi_nf_instance_t *nf_instance, char *id);
ogs_sbi_nf_service_t *ogs_sbi_nf_service_find_by_name(
ogs_sbi_nf_instance_t *nf_instance, char *name);
void ogs_sbi_nf_instance_build_default(

View File

@ -284,6 +284,9 @@ static void server_send_response(
ogs_sbi_stream_t *stream, ogs_sbi_response_t *response)
{
ogs_sbi_session_t *sbi_sess = NULL;
ogs_sock_t *sock = NULL;
ogs_socket_t fd = INVALID_SOCKET;
ogs_hash_index_t *hi;
nghttp2_nv *nva;
size_t nvlen;
@ -298,6 +301,11 @@ static void server_send_response(
ogs_assert(sbi_sess->session);
ogs_assert(response);
sock = sbi_sess->sock;
ogs_assert(sock);
fd = sock->fd;
ogs_assert(fd != INVALID_SOCKET); /* Check if session is removed */
nvlen = 3; /* :status && server && date */
for (hi = ogs_hash_first(response->http.headers);
@ -793,7 +801,7 @@ static int on_stream_close(nghttp2_session *session, int32_t stream_id,
if (error_code) {
ogs_error("on_stream_close_callback() failed (%d:%s)",
error_code, nghttp2_strerror(error_code));
error_code, nghttp2_http2_strerror(error_code));
nghttp2_submit_rst_stream(
session, NGHTTP2_FLAG_NONE, stream_id, error_code);
}

View File

@ -27,6 +27,7 @@ bool ogs_sbi_nnrf_handle_nf_profile(ogs_sbi_nf_instance_t *nf_instance,
int rv;
OpenAPI_lnode_t *node;
ogs_sbi_nf_service_t *nf_service = NULL, *next_nf_service = NULL;
ogs_assert(nf_instance);
ogs_assert(NFProfile);
@ -63,6 +64,41 @@ bool ogs_sbi_nnrf_handle_nf_profile(ogs_sbi_nf_instance_t *nf_instance,
return false;
}
ogs_list_for_each_safe(&nf_instance->nf_service_list,
next_nf_service, nf_service) {
bool nf_service_should_not_be_deleted = false;
ogs_assert(nf_service->id);
OpenAPI_list_for_each(NFProfile->nf_services, node) {
OpenAPI_nf_service_t *NFService = node->data;
if (!NFService) continue;
if (!NFService->service_instance_id) continue;
if (!NFService->service_name) continue;
if (strcmp(nf_service->id, NFService->service_instance_id) == 0) {
nf_service_should_not_be_deleted = true;
break;
}
}
if (nf_service_should_not_be_deleted == false) {
ogs_warn("NFService[%s:%s] removed",
nf_service->id, nf_service->name);
OpenAPI_list_for_each(NFProfile->nf_services, node) {
OpenAPI_nf_service_t *NFService = node->data;
if (!NFService) continue;
if (!NFService->service_instance_id) continue;
if (!NFService->service_name) continue;
ogs_warn("NFService[%s:%s] will be added",
NFService->service_instance_id, NFService->service_name);
}
ogs_sbi_nf_service_remove(nf_service);
}
}
ogs_sbi_nf_instance_clear(nf_instance);
nf_instance->nf_type = NFProfile->nf_type;
@ -111,8 +147,6 @@ bool ogs_sbi_nnrf_handle_nf_profile(ogs_sbi_nf_instance_t *nf_instance,
OpenAPI_list_t *IpEndPointList = NULL;
OpenAPI_lnode_t *node2 = NULL;
ogs_sbi_nf_service_t *nf_service = NULL;
if (!NFService) continue;
if (!NFService->service_instance_id) continue;
if (!NFService->service_name) continue;
@ -120,8 +154,8 @@ bool ogs_sbi_nnrf_handle_nf_profile(ogs_sbi_nf_instance_t *nf_instance,
VersionList = NFService->versions;
IpEndPointList = NFService->ip_end_points;
nf_service = ogs_sbi_nf_service_find(nf_instance,
NFService->service_name);
nf_service = ogs_sbi_nf_service_find_by_id(nf_instance,
NFService->service_instance_id);
if (!nf_service) {
nf_service = ogs_sbi_nf_service_add(nf_instance,
NFService->service_instance_id,

View File

@ -791,6 +791,9 @@ int gmm_handle_ul_nas_transport(amf_ue_t *amf_ue,
ogs_assert_if_reached();
}
ogs_info("UE SUPI[%s] DNN[%s] S_NSSAI[SST:%d SD:0x%x]",
amf_ue->supi, sess->dnn, sess->s_nssai.sst, sess->s_nssai.sd.v);
amf_sess_sbi_discover_and_send(OpenAPI_nf_type_SMF,
sess, AMF_SESS_SM_CONTEXT_NO_STATE, NULL,
amf_nsmf_pdu_session_build_create_sm_context);

View File

@ -53,6 +53,7 @@ int ngap_send_to_gnb(amf_gnb_t *gnb, ogs_pkbuf_t *pkbuf, uint16_t stream_no)
ogs_assert(gnb);
ogs_assert(pkbuf);
ogs_assert(gnb->sctp.sock);
ogs_assert(gnb->sctp.sock->fd != INVALID_SOCKET);
ogs_debug(" IP[%s] RAN_ID[%d]",
OGS_ADDR(gnb->sctp.addr, buf), gnb->gnb_id);

View File

@ -54,6 +54,7 @@ int s1ap_send_to_enb(mme_enb_t *enb, ogs_pkbuf_t *pkbuf, uint16_t stream_no)
ogs_assert(enb);
ogs_assert(pkbuf);
ogs_assert(enb->sctp.sock);
ogs_assert(enb->sctp.sock->fd != INVALID_SOCKET);
ogs_debug(" IP[%s] ENB_ID[%d]",
OGS_ADDR(enb->sctp.addr, buf), enb->enb_id);

View File

@ -197,6 +197,23 @@ static void sess_timeout(ogs_pfcp_xact_t *xact, void *data)
}
}
static void bearer_timeout(ogs_pfcp_xact_t *xact, void *data)
{
uint8_t type;
ogs_assert(xact);
type = xact->seq[0].type;
switch (type) {
case OGS_PFCP_SESSION_MODIFICATION_REQUEST_TYPE:
ogs_error("No PFCP session modification response");
break;
default:
ogs_error("Not implemented [type:%d]", type);
break;
}
}
void sgwc_pfcp_send_session_establishment_request(
sgwc_sess_t *sess, ogs_gtp_xact_t *gtp_xact, ogs_pkbuf_t *gtpbuf)
{
@ -281,7 +298,7 @@ void sgwc_pfcp_send_bearer_modification_request(
ogs_expect_or_return(sxabuf);
xact = ogs_pfcp_xact_local_create(
sess->pfcp_node, &h, sxabuf, sess_timeout, bearer);
sess->pfcp_node, &h, sxabuf, bearer_timeout, bearer);
ogs_expect_or_return(xact);
xact->assoc_xact = gtp_xact;
xact->modify_flags = flags;

View File

@ -430,7 +430,7 @@ sgwu_sess_t *sgwu_sess_add(ogs_pfcp_f_seid_t *cp_f_seid)
ogs_hash_set(self.sess_hash, &sess->sgwc_sxa_seid,
sizeof(sess->sgwc_sxa_seid), sess);
ogs_info("UE F-SEID[CP:0x%lx,UP:0x%lx]",
ogs_info("UE F-SEID[CP:0x%lx UP:0x%lx]",
(long)sess->sgwu_sxa_seid, (long)sess->sgwc_sxa_seid);
ogs_list_add(&self.sess_list, sess);

View File

@ -393,7 +393,7 @@ bool smf_npcf_smpolicycontrol_handle_create(
&dl_pdr->ue_ip_addr, &dl_pdr->ue_ip_addr_len);
dl_pdr->ue_ip_addr.sd = OGS_PFCP_UE_IP_DST;
ogs_info("UE SUPI:[%s] DNN:[%s] IPv4:[%s] IPv6:[%s]",
ogs_info("UE SUPI[%s] DNN[%s] IPv4[%s] IPv6[%s]",
smf_ue->supi, sess->pdn.dnn,
sess->ipv4 ? OGS_INET_NTOP(&sess->ipv4->addr, buf1) : "",
sess->ipv6 ? OGS_INET6_NTOP(&sess->ipv6->addr, buf2) : "");

View File

@ -226,6 +226,45 @@ static void sess_5gc_timeout(ogs_pfcp_xact_t *xact, void *data)
}
}
static void qos_flow_5gc_timeout(ogs_pfcp_xact_t *xact, void *data)
{
smf_ue_t *smf_ue = NULL;
smf_sess_t *sess = NULL;
smf_bearer_t *qos_flow = NULL;
ogs_sbi_stream_t *stream = NULL;
uint8_t type;
char *strerror = NULL;
ogs_assert(xact);
ogs_assert(data);
qos_flow = data;
ogs_assert(qos_flow);
sess = qos_flow->sess;
ogs_assert(sess);
smf_ue = sess->smf_ue;
ogs_assert(smf_ue);
type = xact->seq[0].type;
switch (type) {
case OGS_PFCP_SESSION_MODIFICATION_REQUEST_TYPE:
strerror = ogs_msprintf("[%s:%d] No PFCP session modification response",
smf_ue->supi, sess->psi);
ogs_assert(strerror);
ogs_error("%s", strerror);
if (stream)
smf_sbi_send_sm_context_update_error(stream,
OGS_SBI_HTTP_STATUS_GATEWAY_TIMEOUT,
strerror, NULL, NULL, NULL);
ogs_free(strerror);
break;
default:
ogs_error("Not implemented [type:%d]", type);
break;
}
}
static void sess_epc_timeout(ogs_pfcp_xact_t *xact, void *data)
{
uint8_t type;
@ -237,9 +276,6 @@ static void sess_epc_timeout(ogs_pfcp_xact_t *xact, void *data)
case OGS_PFCP_SESSION_ESTABLISHMENT_REQUEST_TYPE:
ogs_warn("No PFCP session establishment response");
break;
case OGS_PFCP_SESSION_MODIFICATION_REQUEST_TYPE:
ogs_error("No PFCP session modification response");
break;
case OGS_PFCP_SESSION_DELETION_REQUEST_TYPE:
ogs_error("No PFCP session deletion response");
break;
@ -249,6 +285,23 @@ static void sess_epc_timeout(ogs_pfcp_xact_t *xact, void *data)
}
}
static void bearer_epc_timeout(ogs_pfcp_xact_t *xact, void *data)
{
uint8_t type;
ogs_assert(xact);
type = xact->seq[0].type;
switch (type) {
case OGS_PFCP_SESSION_MODIFICATION_REQUEST_TYPE:
ogs_error("No PFCP session modification response");
break;
default:
ogs_error("Not implemented [type:%d]", type);
break;
}
}
void smf_5gc_pfcp_send_session_establishment_request(
smf_sess_t *sess, ogs_sbi_stream_t *stream)
{
@ -296,10 +349,7 @@ void smf_5gc_pfcp_send_session_modification_request(
ogs_expect_or_return(n4buf);
xact = ogs_pfcp_xact_local_create(
sess->pfcp_node, &h, n4buf, sess_5gc_timeout,
/* We'll use xact->data to find out
* Modification Type(Session or QosFlow) */
NULL);
sess->pfcp_node, &h, n4buf, sess_5gc_timeout, sess);
ogs_expect_or_return(xact);
xact->assoc_stream = stream;
xact->modify_flags = flags | OGS_PFCP_MODIFY_SESSION;
@ -329,10 +379,7 @@ void smf_5gc_pfcp_send_qos_flow_modification_request(smf_bearer_t *qos_flow,
ogs_expect_or_return(n4buf);
xact = ogs_pfcp_xact_local_create(
sess->pfcp_node, &h, n4buf, sess_5gc_timeout,
/* We'll use xact->data to find out
* Modification Type(Session or QosFlow) */
qos_flow);
sess->pfcp_node, &h, n4buf, qos_flow_5gc_timeout, qos_flow);
ogs_expect_or_return(xact);
xact->assoc_stream = stream;
@ -420,7 +467,7 @@ void smf_epc_pfcp_send_bearer_modification_request(
ogs_expect_or_return(n4buf);
xact = ogs_pfcp_xact_local_create(
sess->pfcp_node, &h, n4buf, sess_epc_timeout, bearer);
sess->pfcp_node, &h, n4buf, bearer_epc_timeout, bearer);
ogs_expect_or_return(xact);
xact->epc = true; /* EPC PFCP transaction */

View File

@ -154,7 +154,7 @@ void smf_s5c_handle_create_session_request(
smf_sess_set_ue_ip(sess);
ogs_info("UE IMSI:[%s] APN:[%s] IPv4:[%s] IPv6:[%s]",
ogs_info("UE IMSI[%s] APN[%s] IPv4[%s] IPv6[%s]",
smf_ue->imsi_bcd,
sess->pdn.apn,
sess->ipv4 ? OGS_INET_NTOP(&sess->ipv4->addr, buf1) : "",

View File

@ -600,14 +600,17 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e)
ogs_assert(sbi_xact);
stream = sbi_xact->assoc_stream;
ogs_assert(stream);
/* Here, we should not use ogs_assert(stream)
* since 'namf-comm' service has no an associated stream. */
ogs_sbi_xact_remove(sbi_xact);
ogs_error("Cannot receive SBI message");
ogs_sbi_server_send_error(stream,
OGS_SBI_HTTP_STATUS_GATEWAY_TIMEOUT, NULL,
"Cannot receive SBI message", NULL);
if (stream) {
ogs_sbi_server_send_error(stream,
OGS_SBI_HTTP_STATUS_GATEWAY_TIMEOUT, NULL,
"Cannot receive SBI message", NULL);
}
break;
case SMF_TIMER_RELEASE_HOLDING:

View File

@ -600,7 +600,7 @@ void upf_sess_set_ue_ip(upf_sess_t *sess,
pdn_type, ue_ip->ipv4, ue_ip->ipv6, pdr->dnn ? pdr->dnn : "");
}
ogs_info("UE F-SEID[CP:0x%lx,UP:0x%lx] "
ogs_info("UE F-SEID[CP:0x%lx UP:0x%lx] "
"APN[%s] PDN-Type[%d] IPv4[%s] IPv6[%s]",
(long)sess->upf_n4_seid, (long)sess->smf_n4_seid,
pdr->dnn, pdn_type,

View File

@ -259,7 +259,7 @@ static void test1_func(abts_case *tc, void *data)
sess->ul_nas_transport_param.request_type =
OGS_NAS_5GS_REQUEST_TYPE_INITIAL;
sess->ul_nas_transport_param.dnn = 0;
sess->ul_nas_transport_param.dnn = 1;
sess->ul_nas_transport_param.s_nssai = 1;
gsmbuf = testgsm_build_pdu_session_establishment_request(sess);

View File

@ -1666,6 +1666,466 @@ static void test3_func(abts_case *tc, void *data)
test_ue_remove(test_ue);
}
static void test4_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 *sess5 = NULL, *sess6 = NULL;
test_bearer_t *qos_flow1 = NULL, *qos_flow2 = 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, true);
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 +
* Registration accept */
recvbuf = testgnb_ngap_read(ngap);
ABTS_PTR_NOTNULL(tc, recvbuf);
testngap_recv(test_ue, recvbuf);
ABTS_INT_EQUAL(tc,
NGAP_ProcedureCode_id_InitialContextSetup,
test_ue->ngap_procedure_code);
/* 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 */
sess5 = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5);
ogs_assert(sess5);
sess5->ul_nas_transport_param.request_type =
OGS_NAS_5GS_REQUEST_TYPE_INITIAL;
sess5->ul_nas_transport_param.dnn = 1;
sess5->ul_nas_transport_param.s_nssai = 1;
gsmbuf = testgsm_build_pdu_session_establishment_request(sess5);
ABTS_PTR_NOTNULL(tc, gsmbuf);
gmmbuf = testgmm_build_ul_nas_transport(sess5,
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 PDU session establishment request */
sess6 = test_sess_add_by_dnn_and_psi(test_ue, "ims", 6);
ogs_assert(sess6);
sess6->ul_nas_transport_param.request_type =
OGS_NAS_5GS_REQUEST_TYPE_INITIAL;
sess6->ul_nas_transport_param.dnn = 1;
sess6->ul_nas_transport_param.s_nssai = 1;
gsmbuf = testgsm_build_pdu_session_establishment_request(sess6);
ABTS_PTR_NOTNULL(tc, gsmbuf);
gmmbuf = testgmm_build_ul_nas_transport(sess6,
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 PDUSessionResourceSetupRequest +
* DL NAS transport +
* PDU session establishment accept */
recvbuf = testgnb_ngap_read(ngap);
ABTS_PTR_NOTNULL(tc, recvbuf);
testngap_recv(test_ue, recvbuf);
ABTS_INT_EQUAL(tc,
NGAP_ProcedureCode_id_PDUSessionResourceSetup,
test_ue->ngap_procedure_code);
/* Receive PDU session establishment accept */
recvbuf = testgnb_ngap_read(ngap);
ABTS_PTR_NOTNULL(tc, recvbuf);
testngap_recv(test_ue, recvbuf);
ABTS_INT_EQUAL(tc,
NGAP_ProcedureCode_id_PDUSessionResourceSetup,
test_ue->ngap_procedure_code);
/* Send GTP-U ICMP Packet */
qos_flow1 = test_qos_flow_find_by_qfi(sess5, 1);
ogs_assert(qos_flow1);
rv = test_gtpu_send_ping(gtpu, qos_flow1, TEST_PING_IPV4);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Send PDUSessionResourceSetupResponse */
sendbuf = testngap_sess_build_pdu_session_resource_setup_response(sess5);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Send PDUSessionResourceSetupResponse */
sendbuf = testngap_sess_build_pdu_session_resource_setup_response(sess6);
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_flow1, 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);
/* 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_flow2 = test_qos_flow_find_by_qfi(sess6, 2);
ogs_assert(qos_flow2);
sendbuf = testngap_build_pdu_session_resource_modify_response(qos_flow2);
ABTS_PTR_NOTNULL(tc, sendbuf);
rv = testgnb_ngap_send(ngap, sendbuf);
ABTS_INT_EQUAL(tc, OGS_OK, rv);
/* Send PDU session resource modify complete */
sess6->ul_nas_transport_param.request_type =
OGS_NAS_5GS_REQUEST_TYPE_MODIFICATION_REQUEST;
sess6->ul_nas_transport_param.dnn = 0;
sess6->ul_nas_transport_param.s_nssai = 0;
gsmbuf = testgsm_build_pdu_session_modification_complete(sess6);
ABTS_PTR_NOTNULL(tc, gsmbuf);
gmmbuf = testgmm_build_ul_nas_transport(sess6,
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_flow2, 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);
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)
@ -1673,6 +2133,7 @@ abts_suite *test_session(abts_suite *suite)
abts_run_test(suite, test1_func, NULL);
abts_run_test(suite, test2_func, NULL);
abts_run_test(suite, test3_func, NULL);
abts_run_test(suite, test4_func, NULL);
return suite;
}