diff --git a/lib/sbi/nf-sm.c b/lib/sbi/nf-sm.c index 4a4821bf5..9f9a26077 100644 --- a/lib/sbi/nf-sm.c +++ b/lib/sbi/nf-sm.c @@ -275,6 +275,52 @@ void ogs_sbi_nf_state_will_register(ogs_fsm_t *s, ogs_event_t *e) } } +static bool nf_status_subscription_exists( + const char *req_nf_instance_id, + OpenAPI_nf_type_e nf_type, + const char *service_name) +{ + ogs_sbi_subscription_data_t *s = NULL; + bool same_nf_type = false; + bool same_service_name = false; + bool nf_type_present = false; + bool service_name_present = false; + + ogs_assert(req_nf_instance_id); + + nf_type_present = (nf_type != OpenAPI_nf_type_NULL); + service_name_present = (service_name != NULL); + + ogs_list_for_each(&ogs_sbi_self()->subscription_data_list, s) { + if (!s->req_nf_instance_id) + continue; + + if (strcmp(s->req_nf_instance_id, req_nf_instance_id) != 0) + continue; + + if (s->flags & OGS_SBI_SUBSCRIPTION_DELETE_SENT) + continue; + + same_nf_type = false; + same_service_name = false; + + if (nf_type_present && + s->subscr_cond.nf_type != OpenAPI_nf_type_NULL && + s->subscr_cond.nf_type == nf_type) + same_nf_type = true; + + if (service_name_present && + s->subscr_cond.service_name && + strcmp(s->subscr_cond.service_name, service_name) == 0) + same_service_name = true; + + if (same_nf_type || same_service_name) + return true; + } + + return false; +} + void ogs_sbi_nf_state_registered(ogs_fsm_t *s, ogs_event_t *e) { ogs_sbi_nf_instance_t *nf_instance = NULL; @@ -308,6 +354,15 @@ void ogs_sbi_nf_state_registered(ogs_fsm_t *s, ogs_event_t *e) ogs_list_for_each( &ogs_sbi_self()->subscription_spec_list, subscription_spec) { + if (nf_status_subscription_exists( + ogs_sbi_self()->nf_instance->id, + subscription_spec->subscr_cond.nf_type, + subscription_spec->subscr_cond.service_name)) { + ogs_warn("[%s] NF status subscription already exists, skip", + ogs_sbi_self()->nf_instance->id); + continue; + } + ogs_nnrf_nfm_send_nf_status_subscribe( ogs_sbi_self()->nf_instance->nf_type, ogs_sbi_self()->nf_instance->id, diff --git a/src/amf/amf-sm.c b/src/amf/amf-sm.c index 09fa09d1c..e3487f896 100644 --- a/src/amf/amf-sm.c +++ b/src/amf/amf-sm.c @@ -417,14 +417,17 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) CASE(OGS_SBI_HTTP_METHOD_DELETE) if (sbi_message.res_status == - OGS_SBI_HTTP_STATUS_NO_CONTENT) { - ogs_sbi_subscription_data_remove(subscription_data); - } else { + OGS_SBI_HTTP_STATUS_NO_CONTENT) + ogs_info("[%s] Subscription deleted", + subscription_data->id ? + subscription_data->id : "Unknown"); + else ogs_error("[%s] HTTP response error [%d]", subscription_data->id ? subscription_data->id : "Unknown", sbi_message.res_status); - } + + ogs_sbi_subscription_data_remove(subscription_data); break; DEFAULT diff --git a/src/ausf/ausf-sm.c b/src/ausf/ausf-sm.c index f1c8b9d72..a9413bc7e 100644 --- a/src/ausf/ausf-sm.c +++ b/src/ausf/ausf-sm.c @@ -274,15 +274,17 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e) break; CASE(OGS_SBI_HTTP_METHOD_DELETE) - if (message.res_status == - OGS_SBI_HTTP_STATUS_NO_CONTENT) { - ogs_sbi_subscription_data_remove(subscription_data); - } else { + if (message.res_status == OGS_SBI_HTTP_STATUS_NO_CONTENT) + ogs_info("[%s] Subscription deleted", + subscription_data->id ? + subscription_data->id : "Unknown"); + else ogs_error("[%s] HTTP response error [%d]", subscription_data->id ? subscription_data->id : "Unknown", message.res_status); - } + + ogs_sbi_subscription_data_remove(subscription_data); break; DEFAULT diff --git a/src/bsf/bsf-sm.c b/src/bsf/bsf-sm.c index ab233b088..8bda9d038 100644 --- a/src/bsf/bsf-sm.c +++ b/src/bsf/bsf-sm.c @@ -293,14 +293,17 @@ void bsf_state_operational(ogs_fsm_t *s, bsf_event_t *e) break; CASE(OGS_SBI_HTTP_METHOD_DELETE) - if (message.res_status == OGS_SBI_HTTP_STATUS_NO_CONTENT) { - ogs_sbi_subscription_data_remove(subscription_data); - } else { + if (message.res_status == OGS_SBI_HTTP_STATUS_NO_CONTENT) + ogs_info("[%s] Subscription deleted", + subscription_data->id ? + subscription_data->id : "Unknown"); + else ogs_error("[%s] HTTP response error [%d]", subscription_data->id ? subscription_data->id : "Unknown", message.res_status); - } + + ogs_sbi_subscription_data_remove(subscription_data); break; DEFAULT diff --git a/src/nssf/nssf-sm.c b/src/nssf/nssf-sm.c index a27a76077..adcf2ff75 100644 --- a/src/nssf/nssf-sm.c +++ b/src/nssf/nssf-sm.c @@ -280,15 +280,17 @@ void nssf_state_operational(ogs_fsm_t *s, nssf_event_t *e) break; CASE(OGS_SBI_HTTP_METHOD_DELETE) - if (message.res_status == - OGS_SBI_HTTP_STATUS_NO_CONTENT) { - ogs_sbi_subscription_data_remove(subscription_data); - } else { + if (message.res_status == OGS_SBI_HTTP_STATUS_NO_CONTENT) + ogs_info("[%s] Subscription deleted", + subscription_data->id ? + subscription_data->id : "Unknown"); + else ogs_error("[%s] HTTP response error [%d]", subscription_data->id ? subscription_data->id : "Unknown", message.res_status); - } + + ogs_sbi_subscription_data_remove(subscription_data); break; DEFAULT diff --git a/src/pcf/pcf-sm.c b/src/pcf/pcf-sm.c index 7260ad2e8..f2bf66fbd 100644 --- a/src/pcf/pcf-sm.c +++ b/src/pcf/pcf-sm.c @@ -440,15 +440,17 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e) break; CASE(OGS_SBI_HTTP_METHOD_DELETE) - if (message.res_status == - OGS_SBI_HTTP_STATUS_NO_CONTENT) { - ogs_sbi_subscription_data_remove(subscription_data); - } else { + if (message.res_status == OGS_SBI_HTTP_STATUS_NO_CONTENT) + ogs_info("[%s] Subscription deleted", + subscription_data->id ? + subscription_data->id : "Unknown"); + else ogs_error("[%s] HTTP response error [%d]", subscription_data->id ? subscription_data->id : "Unknown", message.res_status); - } + + ogs_sbi_subscription_data_remove(subscription_data); break; DEFAULT diff --git a/src/scp/scp-sm.c b/src/scp/scp-sm.c index 6cf3ca0df..67f095f44 100644 --- a/src/scp/scp-sm.c +++ b/src/scp/scp-sm.c @@ -226,14 +226,17 @@ void scp_state_operational(ogs_fsm_t *s, scp_event_t *e) break; CASE(OGS_SBI_HTTP_METHOD_DELETE) - if (message.res_status == OGS_SBI_HTTP_STATUS_NO_CONTENT) { - ogs_sbi_subscription_data_remove(subscription_data); - } else { + if (message.res_status == OGS_SBI_HTTP_STATUS_NO_CONTENT) + ogs_info("[%s] Subscription deleted", + subscription_data->id ? + subscription_data->id : "Unknown"); + else ogs_error("[%s] HTTP response error [%d]", subscription_data->id ? subscription_data->id : "Unknown", message.res_status); - } + + ogs_sbi_subscription_data_remove(subscription_data); break; DEFAULT diff --git a/src/sepp/sepp-sm.c b/src/sepp/sepp-sm.c index c1bf95557..40ca481bc 100644 --- a/src/sepp/sepp-sm.c +++ b/src/sepp/sepp-sm.c @@ -330,14 +330,17 @@ void sepp_state_operational(ogs_fsm_t *s, sepp_event_t *e) break; CASE(OGS_SBI_HTTP_METHOD_DELETE) - if (message.res_status == OGS_SBI_HTTP_STATUS_NO_CONTENT) { - ogs_sbi_subscription_data_remove(subscription_data); - } else { + if (message.res_status == OGS_SBI_HTTP_STATUS_NO_CONTENT) + ogs_info("[%s] Subscription deleted", + subscription_data->id ? + subscription_data->id : "Unknown"); + else ogs_error("[%s] HTTP response error [%d]", subscription_data->id ? subscription_data->id : "Unknown", message.res_status); - } + + ogs_sbi_subscription_data_remove(subscription_data); break; DEFAULT diff --git a/src/smf/smf-sm.c b/src/smf/smf-sm.c index 57c741046..a3558db76 100644 --- a/src/smf/smf-sm.c +++ b/src/smf/smf-sm.c @@ -903,14 +903,17 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) CASE(OGS_SBI_HTTP_METHOD_DELETE) if (sbi_message.res_status == - OGS_SBI_HTTP_STATUS_NO_CONTENT) { - ogs_sbi_subscription_data_remove(subscription_data); - } else { + OGS_SBI_HTTP_STATUS_NO_CONTENT) + ogs_info("[%s] Subscription deleted", + subscription_data->id ? + subscription_data->id : "Unknown"); + else ogs_error("[%s] HTTP response error [%d]", subscription_data->id ? subscription_data->id : "Unknown", sbi_message.res_status); - } + + ogs_sbi_subscription_data_remove(subscription_data); break; DEFAULT diff --git a/src/udm/udm-sm.c b/src/udm/udm-sm.c index 05c05a2a4..ce90c914e 100644 --- a/src/udm/udm-sm.c +++ b/src/udm/udm-sm.c @@ -364,15 +364,17 @@ void udm_state_operational(ogs_fsm_t *s, udm_event_t *e) break; CASE(OGS_SBI_HTTP_METHOD_DELETE) - if (message.res_status == - OGS_SBI_HTTP_STATUS_NO_CONTENT) { - ogs_sbi_subscription_data_remove(subscription_data); - } else { + if (message.res_status == OGS_SBI_HTTP_STATUS_NO_CONTENT) + ogs_info("[%s] Subscription deleted", + subscription_data->id ? + subscription_data->id : "Unknown"); + else ogs_error("[%s] HTTP response error [%d]", subscription_data->id ? subscription_data->id : "Unknown", message.res_status); - } + + ogs_sbi_subscription_data_remove(subscription_data); break; DEFAULT diff --git a/src/udr/udr-sm.c b/src/udr/udr-sm.c index 72100483c..f6bb2d414 100644 --- a/src/udr/udr-sm.c +++ b/src/udr/udr-sm.c @@ -284,17 +284,20 @@ void udr_state_operational(ogs_fsm_t *s, udr_event_t *e) break; CASE(OGS_SBI_HTTP_METHOD_DELETE) - if (message.res_status == - OGS_SBI_HTTP_STATUS_NO_CONTENT) { - ogs_sbi_subscription_data_remove(subscription_data); - } else { + if (message.res_status == OGS_SBI_HTTP_STATUS_NO_CONTENT) + ogs_info("[%s] Subscription deleted", + subscription_data->id ? + subscription_data->id : "Unknown"); + else ogs_error("[%s] HTTP response error [%d]", subscription_data->id ? subscription_data->id : "Unknown", message.res_status); - } + + ogs_sbi_subscription_data_remove(subscription_data); break; + DEFAULT ogs_error("[%s] Invalid HTTP method [%s]", subscription_data->id, message.h.method); diff --git a/tests/af/af-sm.c b/tests/af/af-sm.c index 49e216c9e..4b6dc08e0 100644 --- a/tests/af/af-sm.c +++ b/tests/af/af-sm.c @@ -262,16 +262,20 @@ void af_state_operational(ogs_fsm_t *s, af_event_t *e) break; CASE(OGS_SBI_HTTP_METHOD_DELETE) - if (message.res_status == OGS_SBI_HTTP_STATUS_NO_CONTENT) { - ogs_sbi_subscription_data_remove(subscription_data); - } else { + if (message.res_status == OGS_SBI_HTTP_STATUS_NO_CONTENT) + ogs_info("[%s] Subscription deleted", + subscription_data->id ? + subscription_data->id : "Unknown"); + else ogs_error("[%s] HTTP response error [%d]", subscription_data->id ? subscription_data->id : "Unknown", message.res_status); - } + + ogs_sbi_subscription_data_remove(subscription_data); break; + DEFAULT ogs_error("Invalid HTTP method [%s]", message.h.method); ogs_assert_if_reached();