From c528e0d5bc258336ab302efe08df7ca5472d0134 Mon Sep 17 00:00:00 2001 From: Sukchan Lee Date: Sat, 18 Jun 2022 23:56:12 +0900 Subject: [PATCH] [SBI] Change NfInstance.Id to Optional --- lib/sbi/context.c | 120 ++++++++++++++++++++++++-------------- lib/sbi/context.h | 51 ++++++++++------- lib/sbi/nnrf-build.c | 22 +++++-- lib/sbi/nnrf-build.h | 9 +-- lib/sbi/path.c | 20 ++++--- src/amf/amf-sm.c | 7 ++- src/amf/context.c | 13 +---- src/amf/context.h | 2 - src/amf/init.c | 3 +- src/amf/nf-sm.c | 123 ++++++++++++++++++++++++--------------- src/amf/nnrf-build.c | 14 ++--- src/amf/nnrf-build.h | 3 +- src/amf/nnrf-handler.c | 8 ++- src/amf/nnssf-build.c | 5 +- src/amf/nsmf-build.c | 3 +- src/amf/nudm-build.c | 3 +- src/amf/sbi-path.c | 64 ++++++++++----------- src/ausf/ausf-sm.c | 7 ++- src/ausf/context.c | 8 +-- src/ausf/context.h | 2 - src/ausf/init.c | 3 +- src/ausf/nf-sm.c | 109 +++++++++++++++++++++-------------- src/ausf/nnrf-build.c | 14 ++--- src/ausf/nnrf-build.h | 3 +- src/ausf/nnrf-handler.c | 8 ++- src/ausf/nudm-build.c | 6 +- src/ausf/sbi-path.c | 61 ++++++++++---------- src/bsf/bsf-sm.c | 8 ++- src/bsf/context.c | 7 +-- src/bsf/context.h | 2 - src/bsf/init.c | 3 +- src/bsf/nf-sm.c | 107 ++++++++++++++++++++-------------- src/bsf/nnrf-build.c | 14 ++--- src/bsf/nnrf-build.h | 3 +- src/bsf/nnrf-handler.c | 8 ++- src/bsf/sbi-path.c | 61 ++++++++++---------- src/nrf/init.c | 3 +- src/nrf/nnrf-build.c | 1 + src/nrf/nrf-sm.c | 9 ++- src/nssf/context.c | 2 - src/nssf/context.h | 2 - src/nssf/init.c | 3 +- src/nssf/nf-sm.c | 105 ++++++++++++++++++++-------------- src/nssf/nnrf-build.c | 14 ++--- src/nssf/nnrf-build.h | 3 +- src/nssf/nnrf-handler.c | 5 +- src/nssf/nssf-sm.c | 7 ++- src/nssf/sbi-path.c | 61 ++++++++++---------- src/pcf/context.c | 12 +--- src/pcf/context.h | 2 - src/pcf/init.c | 3 +- src/pcf/nbsf-build.c | 2 +- src/pcf/nf-sm.c | 114 ++++++++++++++++++++++-------------- src/pcf/nnrf-build.c | 14 ++--- src/pcf/nnrf-build.h | 3 +- src/pcf/nnrf-handler.c | 8 ++- src/pcf/pcf-sm.c | 7 ++- src/pcf/sbi-path.c | 90 ++++++++++++++--------------- src/smf/context.c | 20 ++++--- src/smf/context.h | 2 - src/smf/init.c | 2 +- src/smf/nf-sm.c | 124 ++++++++++++++++++++++++---------------- src/smf/nnrf-build.c | 16 +++--- src/smf/nnrf-build.h | 3 +- src/smf/nnrf-handler.c | 8 ++- src/smf/sbi-path.c | 61 ++++++++++---------- src/smf/smf-sm.c | 8 ++- src/udm/context.c | 7 +-- src/udm/context.h | 2 - src/udm/init.c | 3 +- src/udm/nf-sm.c | 109 +++++++++++++++++++++-------------- src/udm/nnrf-build.c | 14 ++--- src/udm/nnrf-build.h | 3 +- src/udm/nnrf-handler.c | 8 ++- src/udm/sbi-path.c | 93 ++++++++++++++---------------- src/udm/udm-sm.c | 7 ++- src/udr/context.c | 2 - src/udr/context.h | 2 - src/udr/init.c | 3 +- src/udr/nf-sm.c | 105 ++++++++++++++++++++-------------- src/udr/nnrf-build.c | 14 ++--- src/udr/nnrf-build.h | 3 +- src/udr/nnrf-handler.c | 5 +- src/udr/sbi-path.c | 66 ++++++++++----------- src/udr/udr-sm.c | 4 +- tests/af/af-sm.c | 4 +- tests/af/context.c | 7 +-- tests/af/context.h | 2 - tests/af/init.c | 3 +- tests/af/nf-sm.c | 109 +++++++++++++++++++++-------------- tests/af/nnrf-build.c | 14 ++--- tests/af/nnrf-build.h | 3 +- tests/af/nnrf-handler.c | 8 ++- tests/af/sbi-path.c | 56 +++++++++--------- 94 files changed, 1260 insertions(+), 1014 deletions(-) diff --git a/lib/sbi/context.c b/lib/sbi/context.c index 46ae876cf..2a0f0faee 100644 --- a/lib/sbi/context.c +++ b/lib/sbi/context.c @@ -33,6 +33,8 @@ static OGS_POOL(nf_info_pool, ogs_sbi_nf_info_t); void ogs_sbi_context_init(void) { + char nf_instance_id[OGS_UUID_FORMATTED_LENGTH + 1]; + ogs_assert(context_initialized == 0); /* Initialize SBI context */ @@ -57,8 +59,14 @@ void ogs_sbi_context_init(void) ogs_pool_init(&nf_info_pool, ogs_app()->pool.nf * OGS_MAX_NUM_OF_NF_INFO); + /* Add SELF NF instance */ + self.nf_instance = ogs_sbi_nf_instance_add(); + ogs_assert(self.nf_instance); + ogs_uuid_get(&self.uuid); - ogs_uuid_format(self.nf_instance_id, &self.uuid); + ogs_uuid_format(nf_instance_id, &self.uuid); + + ogs_sbi_nf_instance_set_id(self.nf_instance, nf_instance_id); context_initialized = 1; } @@ -74,8 +82,6 @@ void ogs_sbi_context_final(void) ogs_sbi_nf_instance_remove_all(); - ogs_sbi_nf_info_remove_all(&self.nf_info_list); - ogs_pool_final(&nf_instance_pool); ogs_pool_final(&nf_service_pool); ogs_pool_final(&smf_info_pool); @@ -470,9 +476,10 @@ int ogs_sbi_context_parse_config(const char *local, const char *remote) client = ogs_sbi_client_add(addr); ogs_assert(client); - nf_instance = ogs_sbi_nf_instance_add( - ogs_sbi_self()->nf_instance_id); + nf_instance = ogs_sbi_nf_instance_add(); ogs_assert(nf_instance); + ogs_sbi_nf_instance_set_type( + nf_instance, OpenAPI_nf_type_NRF); OGS_SBI_SETUP_CLIENT(nf_instance, client); @@ -494,17 +501,10 @@ int ogs_sbi_context_parse_config(const char *local, const char *remote) return OGS_OK; } -bool ogs_sbi_nf_instance_maximum_number_is_reached() -{ - return nf_instance_pool.avail <= 0; -} - -ogs_sbi_nf_instance_t *ogs_sbi_nf_instance_add(char *id) +ogs_sbi_nf_instance_t *ogs_sbi_nf_instance_add(void) { ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_assert(id); - ogs_pool_alloc(&nf_instance_pool, &nf_instance); ogs_assert(nf_instance); memset(nf_instance, 0, sizeof(ogs_sbi_nf_instance_t)); @@ -512,9 +512,6 @@ ogs_sbi_nf_instance_t *ogs_sbi_nf_instance_add(char *id) nf_instance->reference_count++; ogs_trace("ogs_sbi_nf_instance_add()"); - nf_instance->id = ogs_strdup(id); - ogs_assert(nf_instance->id); - nf_instance->time.heartbeat_interval = ogs_app()->time.nf_instance.heartbeat_interval; @@ -540,6 +537,33 @@ ogs_sbi_nf_instance_t *ogs_sbi_nf_instance_add(char *id) return nf_instance; } +void ogs_sbi_nf_instance_set_id(ogs_sbi_nf_instance_t *nf_instance, char *id) +{ + ogs_assert(nf_instance); + ogs_assert(id); + + nf_instance->id = ogs_strdup(id); + ogs_assert(nf_instance->id); +} + +void ogs_sbi_nf_instance_set_type( + ogs_sbi_nf_instance_t *nf_instance, OpenAPI_nf_type_e nf_type) +{ + ogs_assert(nf_instance); + ogs_assert(nf_type); + + nf_instance->nf_type = nf_type; +} + +void ogs_sbi_nf_instance_set_status( + ogs_sbi_nf_instance_t *nf_instance, OpenAPI_nf_status_e nf_status) +{ + ogs_assert(nf_instance); + ogs_assert(nf_status); + + nf_instance->nf_status = nf_status; +} + void ogs_sbi_nf_instance_add_allowed_nf_type( ogs_sbi_nf_instance_t *nf_instance, OpenAPI_nf_type_e allowed_nf_type) { @@ -592,13 +616,14 @@ void ogs_sbi_nf_instance_remove(ogs_sbi_nf_instance_t *nf_instance) ogs_sbi_nf_info_remove_all(&nf_instance->nf_info_list); - 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); + if (nf_instance->id) { + ogs_sbi_subscription_remove_all_by_nf_instance_id(nf_instance->id); + ogs_free(nf_instance->id); + } ogs_timer_delete(nf_instance->t_registration_interval); ogs_timer_delete(nf_instance->t_heartbeat_interval); @@ -630,15 +655,20 @@ ogs_sbi_nf_instance_t *ogs_sbi_nf_instance_find(char *id) ogs_assert(id); ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) { - ogs_assert(nf_instance->id); - if (strcmp(nf_instance->id, id) == 0) + if (nf_instance->id && strcmp(nf_instance->id, id) == 0) break; } return nf_instance; } -ogs_sbi_nf_service_t *ogs_sbi_nf_service_add(ogs_sbi_nf_instance_t *nf_instance, +bool ogs_sbi_nf_instance_maximum_number_is_reached() +{ + return nf_instance_pool.avail <= 0; +} + +ogs_sbi_nf_service_t *ogs_sbi_nf_service_add( + ogs_sbi_nf_instance_t *nf_instance, char *id, char *name, OpenAPI_uri_scheme_e scheme) { ogs_sbi_nf_service_t *nf_service = NULL; @@ -884,9 +914,10 @@ void ogs_sbi_nf_instance_build_default( char *hostname = NULL; ogs_assert(nf_instance); + ogs_assert(nf_type); - nf_instance->nf_type = nf_type; - nf_instance->nf_status = OpenAPI_nf_status_REGISTERED; + ogs_sbi_nf_instance_set_type(nf_instance, nf_type); + ogs_sbi_nf_instance_set_status(nf_instance, OpenAPI_nf_status_REGISTERED); hostname = NULL; ogs_list_for_each(&ogs_sbi_self()->server_list, server) { @@ -933,11 +964,11 @@ ogs_sbi_nf_service_t *ogs_sbi_nf_service_build_default( ogs_sbi_nf_instance_t *nf_instance, char *name) { ogs_sbi_server_t *server = NULL; - ogs_sbi_client_t *client = NULL; ogs_sbi_nf_service_t *nf_service = NULL; ogs_uuid_t uuid; char id[OGS_UUID_FORMATTED_LENGTH + 1]; char *hostname = NULL; + OpenAPI_uri_scheme_e scheme = OpenAPI_uri_scheme_NULL; ogs_assert(nf_instance); ogs_assert(name); @@ -945,14 +976,27 @@ ogs_sbi_nf_service_t *ogs_sbi_nf_service_build_default( ogs_uuid_get(&uuid); ogs_uuid_format(id, &uuid); - client = nf_instance->client; - ogs_assert(client); + ogs_list_for_each(&ogs_sbi_self()->server_list, server) { + OpenAPI_uri_scheme_e s; - nf_service = ogs_sbi_nf_service_add(nf_instance, id, name, - (client->tls.key && client->tls.pem) ? - OpenAPI_uri_scheme_https : OpenAPI_uri_scheme_http); + if (server->tls.key && server->tls.pem) + s = OpenAPI_uri_scheme_https; + else + s = OpenAPI_uri_scheme_http; + + if (scheme == OpenAPI_uri_scheme_NULL) { + scheme = s; + } else if (scheme != s) { + ogs_fatal("Please CHECK CONFIGURATION - sbi[%d:%s]", + nf_instance->nf_type, + OpenAPI_nf_type_ToString(nf_instance->nf_type)); + ogs_assert_if_reached(); + return NULL; + } + } + + nf_service = ogs_sbi_nf_service_add(nf_instance, id, name, scheme); ogs_assert(nf_service); - OGS_SBI_SETUP_CLIENT(nf_service, client); hostname = NULL; ogs_list_for_each(&ogs_sbi_self()->server_list, server) { @@ -1092,19 +1136,7 @@ static void nf_service_associate_client_all(ogs_sbi_nf_instance_t *nf_instance) nf_service_associate_client(nf_service); } -void ogs_sbi_select_nrf(ogs_sbi_object_t *sbi_object, void *state) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - - ogs_assert(sbi_object); - - /* SELF NF Instace is used for NRF Instance */ - nf_instance = ogs_sbi_nf_instance_find(ogs_sbi_self()->nf_instance_id); - if (nf_instance && OGS_FSM_CHECK(&nf_instance->sm, state)) - OGS_SBI_SETUP_NF(sbi_object, OpenAPI_nf_type_NRF, nf_instance); -} - -void ogs_sbi_select_first_nf( +void ogs_sbi_select_nf( ogs_sbi_object_t *sbi_object, OpenAPI_nf_type_e nf_type, void *state) { ogs_sbi_nf_instance_t *nf_instance = NULL; diff --git a/lib/sbi/context.h b/lib/sbi/context.h index 9401b2047..cb14da7ee 100644 --- a/lib/sbi/context.h +++ b/lib/sbi/context.h @@ -34,43 +34,48 @@ extern "C" { typedef struct ogs_sbi_client_s ogs_sbi_client_t; typedef struct ogs_sbi_smf_info_s ogs_sbi_smf_info_t; +typedef struct ogs_sbi_nf_instance_s ogs_sbi_nf_instance_t; typedef struct ogs_sbi_context_s { - uint32_t sbi_port; /* SBI local port */ + uint32_t sbi_port; /* SBI local port */ - ogs_list_t server_list; - ogs_list_t client_list; + ogs_list_t server_list; + ogs_list_t client_list; - ogs_uuid_t uuid; - char nf_instance_id[OGS_UUID_FORMATTED_LENGTH + 1]; + ogs_uuid_t uuid; - ogs_list_t nf_instance_list; - ogs_list_t subscription_list; + ogs_list_t nf_instance_list; + ogs_list_t subscription_list; - ogs_list_t nf_info_list; + ogs_sbi_nf_instance_t *nf_instance; /* SELF NF Instance */ - const char *content_encoding; + const char *content_encoding; } ogs_sbi_context_t; typedef struct ogs_sbi_nf_instance_s { - ogs_lnode_t lnode; + ogs_lnode_t lnode; - ogs_fsm_t sm; /* A state machine */ - ogs_timer_t *t_registration_interval; /* timer to retry + ogs_fsm_t sm; /* A state machine */ + ogs_timer_t *t_registration_interval; /* timer to retry to register peer node */ struct { int heartbeat_interval; int validity_duration; } time; - ogs_timer_t *t_heartbeat_interval; /* heartbeat interval */ - ogs_timer_t *t_no_heartbeat; /* check heartbeat */ - ogs_timer_t *t_validity; /* check validation */ + ogs_timer_t *t_heartbeat_interval; /* heartbeat interval */ + ogs_timer_t *t_no_heartbeat; /* check heartbeat */ + ogs_timer_t *t_validity; /* check validation */ #define NF_INSTANCE_IS_SELF(_iD) \ - strcmp((_iD), ogs_sbi_self()->nf_instance_id) == 0 + (_iD) && ogs_sbi_self()->nf_instance && \ + strcmp((_iD), ogs_sbi_self()->nf_instance->id) == 0 #define NF_INSTANCE_IS_OTHERS(_iD) \ - strcmp((_iD), ogs_sbi_self()->nf_instance_id) != 0 + (_iD) && ogs_sbi_self()->nf_instance && \ + strcmp((_iD), ogs_sbi_self()->nf_instance->id) != 0 + +#define NF_INSTANCE_IS_NRF(__nFInstance) \ + ((__nFInstance->nf_type) == OpenAPI_nf_type_NRF) char *id; /* NFInstanceId */ @@ -246,14 +251,19 @@ void ogs_sbi_context_final(void); ogs_sbi_context_t *ogs_sbi_self(void); int ogs_sbi_context_parse_config(const char *local, const char *remote); -bool ogs_sbi_nf_instance_maximum_number_is_reached(void); -ogs_sbi_nf_instance_t *ogs_sbi_nf_instance_add(char *id); +ogs_sbi_nf_instance_t *ogs_sbi_nf_instance_add(void); +void ogs_sbi_nf_instance_set_id(ogs_sbi_nf_instance_t *nf_instance, char *id); +void ogs_sbi_nf_instance_set_type( + ogs_sbi_nf_instance_t *nf_instance, OpenAPI_nf_type_e nf_type); +void ogs_sbi_nf_instance_set_status( + ogs_sbi_nf_instance_t *nf_instance, OpenAPI_nf_status_e nf_status); void ogs_sbi_nf_instance_add_allowed_nf_type( ogs_sbi_nf_instance_t *nf_instance, OpenAPI_nf_type_e allowed_nf_type); void ogs_sbi_nf_instance_clear(ogs_sbi_nf_instance_t *nf_instance); void ogs_sbi_nf_instance_remove(ogs_sbi_nf_instance_t *nf_instance); void ogs_sbi_nf_instance_remove_all(void); ogs_sbi_nf_instance_t *ogs_sbi_nf_instance_find(char *id); +bool ogs_sbi_nf_instance_maximum_number_is_reached(void); ogs_sbi_nf_service_t *ogs_sbi_nf_service_add(ogs_sbi_nf_instance_t *nf_instance, char *id, char *name, OpenAPI_uri_scheme_e scheme); @@ -309,8 +319,7 @@ OpenAPI_uri_scheme_e ogs_sbi_default_uri_scheme(void); (__nFInstance)->reference_count); \ } while(0) -void ogs_sbi_select_nrf(ogs_sbi_object_t *sbi_object, void *state); -void ogs_sbi_select_first_nf( +void ogs_sbi_select_nf( ogs_sbi_object_t *sbi_object, OpenAPI_nf_type_e nf_type, void *state); void ogs_sbi_object_free(ogs_sbi_object_t *sbi_object); diff --git a/lib/sbi/nnrf-build.c b/lib/sbi/nnrf-build.c index f7858421d..ea98a81e5 100644 --- a/lib/sbi/nnrf-build.c +++ b/lib/sbi/nnrf-build.c @@ -20,9 +20,9 @@ #include "ogs-sbi.h" #include "ogs-app.h" -OpenAPI_nf_profile_t *ogs_nnrf_nfm_build_nf_profile( - ogs_sbi_nf_instance_t *nf_instance) +OpenAPI_nf_profile_t *ogs_nnrf_nfm_build_nf_profile(void) { + ogs_sbi_nf_instance_t *nf_instance = NULL; ogs_sbi_nf_service_t *nf_service = NULL; OpenAPI_nf_profile_t *NFProfile = NULL; @@ -39,7 +39,9 @@ OpenAPI_nf_profile_t *ogs_nnrf_nfm_build_nf_profile( char *ipstr = NULL; + nf_instance = ogs_sbi_self()->nf_instance; ogs_assert(nf_instance); + ogs_assert(nf_instance->id); NFProfile = ogs_calloc(1, sizeof(*NFProfile)); ogs_expect_or_return_val(NFProfile, NULL); @@ -331,15 +333,19 @@ void ogs_sbi_nnrf_free_nf_profile(OpenAPI_nf_profile_t *NFProfile) ogs_free(NFProfile); } -ogs_sbi_request_t *ogs_nnrf_nfm_build_update(ogs_sbi_nf_instance_t *nf_instance) +ogs_sbi_request_t *ogs_nnrf_nfm_build_update(void) { + ogs_sbi_nf_instance_t *nf_instance = NULL; + ogs_sbi_message_t message; ogs_sbi_request_t *request = NULL; OpenAPI_list_t *PatchItemList; OpenAPI_patch_item_t item; + nf_instance = ogs_sbi_self()->nf_instance; ogs_assert(nf_instance); + ogs_assert(nf_instance->id); memset(&message, 0, sizeof(message)); message.h.method = (char *)OGS_SBI_HTTP_METHOD_PATCH; @@ -347,7 +353,8 @@ ogs_sbi_request_t *ogs_nnrf_nfm_build_update(ogs_sbi_nf_instance_t *nf_instance) message.h.api.version = (char *)OGS_SBI_API_V1; message.h.resource.component[0] = (char *)OGS_SBI_RESOURCE_NAME_NF_INSTANCES; - message.h.resource.component[1] = ogs_sbi_self()->nf_instance_id; + message.h.resource.component[1] = nf_instance->id; + message.http.content_type = (char *)OGS_SBI_CONTENT_PATCH_TYPE; PatchItemList = OpenAPI_list_create(); @@ -372,13 +379,16 @@ ogs_sbi_request_t *ogs_nnrf_nfm_build_update(ogs_sbi_nf_instance_t *nf_instance) return request; } -ogs_sbi_request_t *ogs_nnrf_nfm_build_de_register( - ogs_sbi_nf_instance_t *nf_instance) +ogs_sbi_request_t *ogs_nnrf_nfm_build_de_register(void) { + ogs_sbi_nf_instance_t *nf_instance = NULL; + ogs_sbi_message_t message; ogs_sbi_request_t *request = NULL; + nf_instance = ogs_sbi_self()->nf_instance; ogs_assert(nf_instance); + ogs_assert(nf_instance->id); memset(&message, 0, sizeof(message)); message.h.method = (char *)OGS_SBI_HTTP_METHOD_DELETE; diff --git a/lib/sbi/nnrf-build.h b/lib/sbi/nnrf-build.h index 567b3e4ff..44cedcfe0 100644 --- a/lib/sbi/nnrf-build.h +++ b/lib/sbi/nnrf-build.h @@ -24,14 +24,11 @@ extern "C" { #endif -OpenAPI_nf_profile_t *ogs_nnrf_nfm_build_nf_profile( - ogs_sbi_nf_instance_t *nf_instance); +OpenAPI_nf_profile_t *ogs_nnrf_nfm_build_nf_profile(void); void ogs_sbi_nnrf_free_nf_profile(OpenAPI_nf_profile_t *NFProfile); -ogs_sbi_request_t *ogs_nnrf_nfm_build_update( - ogs_sbi_nf_instance_t *nf_instance); -ogs_sbi_request_t *ogs_nnrf_nfm_build_de_register( - ogs_sbi_nf_instance_t *nf_instance); +ogs_sbi_request_t *ogs_nnrf_nfm_build_update(void); +ogs_sbi_request_t *ogs_nnrf_nfm_build_de_register(void); ogs_sbi_request_t *ogs_nnrf_nfm_build_status_subscribe( ogs_sbi_subscription_t *subscription); diff --git a/lib/sbi/path.c b/lib/sbi/path.c index 5f6231bde..c563dc329 100644 --- a/lib/sbi/path.c +++ b/lib/sbi/path.c @@ -39,7 +39,8 @@ bool ogs_sbi_send(ogs_sbi_nf_instance_t *nf_instance, client = ogs_sbi_client_find_by_service_name(nf_instance, request->h.service.name, request->h.api.version); if (!client) { - ogs_error("[%s] Cannot find client [%s:%s]", + ogs_error("[%s:%s] Cannot find client [%s:%s]", + OpenAPI_nf_type_ToString(nf_instance->nf_type), nf_instance->id, request->h.service.name, request->h.api.version); return false; @@ -50,12 +51,16 @@ bool ogs_sbi_send(ogs_sbi_nf_instance_t *nf_instance, addr = ogs_sbi_getaddr_from_uri(request->h.uri); if (!addr) { - ogs_error("[%s] Invalid URL [%s]", nf_instance->id, request->h.uri); + ogs_error("[%s:%s] Invalid URL [%s]", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id, request->h.uri); return false; } client = ogs_sbi_client_find(addr); if (!client) { - ogs_error("[%s] Cannot find client [%s:%d]", nf_instance->id, + ogs_error("[%s:%s] Cannot find client [%s:%d]", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id, OGS_ADDR(addr, buf), OGS_PORT(addr)); ogs_freeaddrinfo(addr); return false; @@ -88,7 +93,7 @@ bool ogs_sbi_discover_and_send(ogs_sbi_xact_t *xact, nf_instance = OGS_SBI_NF_INSTANCE(xact->sbi_object, xact->target_nf_type); if (!nf_instance) { ogs_assert(xact->target_nf_type != OpenAPI_nf_type_NRF); - ogs_sbi_select_first_nf( + ogs_sbi_select_nf( xact->sbi_object, xact->target_nf_type, nf_state_registered); nf_instance = OGS_SBI_NF_INSTANCE( xact->sbi_object, xact->target_nf_type); @@ -101,7 +106,8 @@ bool ogs_sbi_discover_and_send(ogs_sbi_xact_t *xact, /* NRF NF-Instance */ nf_instance = OGS_SBI_NF_INSTANCE(xact->sbi_object, OpenAPI_nf_type_NRF); if (!nf_instance) { - ogs_sbi_select_nrf(xact->sbi_object, nf_state_registered); + ogs_sbi_select_nf( + xact->sbi_object, OpenAPI_nf_type_NRF, nf_state_registered); nf_instance = OGS_SBI_NF_INSTANCE( xact->sbi_object, OpenAPI_nf_type_NRF); } @@ -128,7 +134,7 @@ bool ogs_nnrf_nfm_send_nf_update(ogs_sbi_nf_instance_t *nf_instance) client = nf_instance->client; ogs_assert(client); - request = ogs_nnrf_nfm_build_update(nf_instance); + request = ogs_nnrf_nfm_build_update(); ogs_expect_or_return_val(request, false); return ogs_sbi_client_send_request( @@ -144,7 +150,7 @@ bool ogs_nnrf_nfm_send_nf_de_register(ogs_sbi_nf_instance_t *nf_instance) client = nf_instance->client; ogs_assert(client); - request = ogs_nnrf_nfm_build_de_register(nf_instance); + request = ogs_nnrf_nfm_build_de_register(); ogs_expect_or_return_val(request, false); return ogs_sbi_client_send_request( diff --git a/src/amf/amf-sm.c b/src/amf/amf-sm.c index 164f46057..899d04c12 100644 --- a/src/amf/amf-sm.c +++ b/src/amf/amf-sm.c @@ -537,7 +537,8 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) ogs_fsm_dispatch(&nf_instance->sm, e); if (OGS_FSM_CHECK(&nf_instance->sm, amf_nf_state_exception)) - ogs_error("[%s] State machine exception [%d]", + ogs_error("[%s:%s] State machine exception [%d]", + OpenAPI_nf_type_ToString(nf_instance->nf_type), nf_instance->id, e->timer_id); break; @@ -545,9 +546,11 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) subscription = e->sbi.data; ogs_assert(subscription); + ogs_assert(ogs_sbi_self()->nf_instance); ogs_assert(true == ogs_nnrf_nfm_send_nf_status_subscribe(subscription->client, - amf_self()->nf_type, subscription->req_nf_instance_id, + ogs_sbi_self()->nf_instance->nf_type, + subscription->req_nf_instance_id, subscription->subscr_cond.nf_type)); ogs_info("[%s] Subscription validity expired", subscription->id); diff --git a/src/amf/context.c b/src/amf/context.c index 7d3c0ec1f..6b0f6968f 100644 --- a/src/amf/context.c +++ b/src/amf/context.c @@ -114,8 +114,6 @@ amf_context_t *amf_self(void) static int amf_context_prepare(void) { - self.nf_type = OpenAPI_nf_type_AMF; - self.relative_capacity = 0xff; self.ngap_port = OGS_NGAP_SCTP_PORT; @@ -1780,10 +1778,7 @@ void amf_ue_select_nf(amf_ue_t *amf_ue, OpenAPI_nf_type_e nf_type) ogs_assert(amf_ue); ogs_assert(nf_type); - if (nf_type == OpenAPI_nf_type_NRF) - ogs_sbi_select_nrf(&amf_ue->sbi, amf_nf_state_registered); - else - ogs_sbi_select_first_nf(&amf_ue->sbi, nf_type, amf_nf_state_registered); + ogs_sbi_select_nf(&amf_ue->sbi, nf_type, amf_nf_state_registered); } void amf_sess_select_nf(amf_sess_t *sess, OpenAPI_nf_type_e nf_type) @@ -1791,12 +1786,10 @@ void amf_sess_select_nf(amf_sess_t *sess, OpenAPI_nf_type_e nf_type) ogs_assert(sess); ogs_assert(nf_type); - if (nf_type == OpenAPI_nf_type_NRF) - ogs_sbi_select_nrf(&sess->sbi, amf_nf_state_registered); - else if (nf_type == OpenAPI_nf_type_SMF) + if (nf_type == OpenAPI_nf_type_SMF) amf_sess_select_smf(sess); else - ogs_sbi_select_first_nf(&sess->sbi, nf_type, amf_nf_state_registered); + ogs_sbi_select_nf(&sess->sbi, nf_type, amf_nf_state_registered); } static bool check_smf_info(amf_sess_t *sess, ogs_list_t *nf_info_list); diff --git a/src/amf/context.h b/src/amf/context.h index fef85d060..16fdb38f8 100644 --- a/src/amf/context.h +++ b/src/amf/context.h @@ -48,8 +48,6 @@ typedef struct amf_ue_s amf_ue_t; typedef uint32_t amf_m_tmsi_t; typedef struct amf_context_s { - OpenAPI_nf_type_e nf_type; - /* Served GUAMI */ uint8_t num_of_served_guami; ogs_guami_t served_guami[MAX_NUM_OF_SERVED_GUAMI]; diff --git a/src/amf/init.c b/src/amf/init.c index 8e76c7c4e..9738b0ef9 100644 --- a/src/amf/init.c +++ b/src/amf/init.c @@ -30,9 +30,10 @@ int amf_initialize() int rv; ogs_metrics_context_init(); + ogs_sbi_context_init(); + amf_context_init(); amf_event_init(); - ogs_sbi_context_init(); rv = ogs_sbi_context_parse_config("amf", "nrf"); if (rv != OGS_OK) return rv; diff --git a/src/amf/nf-sm.c b/src/amf/nf-sm.c index f0786e02e..b8f61fd80 100644 --- a/src/amf/nf-sm.c +++ b/src/amf/nf-sm.c @@ -60,7 +60,6 @@ void amf_nf_state_initial(ogs_fsm_t *s, amf_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); - ogs_assert(nf_instance->id); ogs_assert(nf_instance->t_registration_interval); nf_instance->t_registration_interval->cb = @@ -73,9 +72,10 @@ void amf_nf_state_initial(ogs_fsm_t *s, amf_event_t *e) ogs_assert(nf_instance->t_validity); nf_instance->t_validity->cb = amf_timer_nf_instance_validity; - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { + if (NF_INSTANCE_IS_NRF(nf_instance)) { OGS_FSM_TRAN(s, &amf_nf_state_will_register); } else { + ogs_assert(nf_instance->id); OGS_FSM_TRAN(s, &amf_nf_state_registered); } } @@ -102,19 +102,19 @@ void amf_nf_state_will_register(ogs_fsm_t *s, amf_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); + ogs_assert(NF_INSTANCE_IS_NRF(nf_instance)); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); + ogs_timer_start(nf_instance->t_registration_interval, + ogs_app()->time.message.sbi.nf_register_interval); ogs_assert(true == amf_nnrf_nfm_send_nf_register(nf_instance)); break; case OGS_FSM_EXIT_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) - ogs_timer_stop(nf_instance->t_registration_interval); + ogs_timer_stop(nf_instance->t_registration_interval); break; case AMF_EVT_SBI_CLIENT: @@ -133,20 +133,22 @@ void amf_nf_state_will_register(ogs_fsm_t *s, amf_event_t *e) OGS_FSM_TRAN(s, &amf_nf_state_registered); } else { ogs_error("[%s] HTTP Response Status Code [%d]", - nf_instance->id, message->res_status); + ogs_sbi_self()->nf_instance->id, + message->res_status); OGS_FSM_TRAN(s, &amf_nf_state_exception); } break; DEFAULT ogs_error("[%s] Invalid resource name [%s]", - nf_instance->id, message->h.resource.component[0]); + ogs_sbi_self()->nf_instance->id, + message->h.resource.component[0]); END break; DEFAULT ogs_error("[%s] Invalid API name [%s]", - nf_instance->id, message->h.service.name); + ogs_sbi_self()->nf_instance->id, message->h.service.name); END break; @@ -158,17 +160,18 @@ void amf_nf_state_will_register(ogs_fsm_t *s, amf_event_t *e) addr = client->node.addr; ogs_assert(addr); - ogs_warn("[%s] Retry to registration with NRF", nf_instance->id); + ogs_warn("[%s] Retry to registration with NRF", + ogs_sbi_self()->nf_instance->id); - if (NF_INSTANCE_IS_SELF(nf_instance->id)) - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); + ogs_timer_start(nf_instance->t_registration_interval, + ogs_app()->time.message.sbi.nf_register_interval); ogs_assert(true == amf_nnrf_nfm_send_nf_register(nf_instance)); break; default: - ogs_error("[%s] Unknown timer[%s:%d]", nf_instance->id, + ogs_error("[%s] Unknown timer[%s:%d]", + ogs_sbi_self()->nf_instance->id, amf_timer_get_name(e->timer_id), e->timer_id); } break; @@ -191,12 +194,14 @@ void amf_nf_state_registered(ogs_fsm_t *s, amf_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { + if (NF_INSTANCE_IS_NRF(nf_instance)) { ogs_info("[%s] NF registered [Heartbeat:%ds]", - nf_instance->id, nf_instance->time.heartbeat_interval); + ogs_sbi_self()->nf_instance->id, + nf_instance->time.heartbeat_interval); client = nf_instance->client; ogs_assert(client); @@ -212,26 +217,36 @@ void amf_nf_state_registered(ogs_fsm_t *s, amf_event_t *e) ogs_assert(true == ogs_nnrf_nfm_send_nf_status_subscribe(client, - amf_self()->nf_type, nf_instance->id, OpenAPI_nf_type_AUSF)); + ogs_sbi_self()->nf_instance->nf_type, + ogs_sbi_self()->nf_instance->id, + OpenAPI_nf_type_AUSF)); ogs_assert(true == ogs_nnrf_nfm_send_nf_status_subscribe(client, - amf_self()->nf_type, nf_instance->id, OpenAPI_nf_type_UDM)); + ogs_sbi_self()->nf_instance->nf_type, + ogs_sbi_self()->nf_instance->id, + OpenAPI_nf_type_UDM)); ogs_assert(true == ogs_nnrf_nfm_send_nf_status_subscribe(client, - amf_self()->nf_type, nf_instance->id, OpenAPI_nf_type_PCF)); + ogs_sbi_self()->nf_instance->nf_type, + ogs_sbi_self()->nf_instance->id, + OpenAPI_nf_type_PCF)); ogs_assert(true == ogs_nnrf_nfm_send_nf_status_subscribe(client, - amf_self()->nf_type, nf_instance->id, OpenAPI_nf_type_SMF)); + ogs_sbi_self()->nf_instance->nf_type, + ogs_sbi_self()->nf_instance->id, + OpenAPI_nf_type_SMF)); ogs_assert(true == ogs_nnrf_nfm_send_nf_status_subscribe(client, - amf_self()->nf_type, nf_instance->id, OpenAPI_nf_type_NSSF)); + ogs_sbi_self()->nf_instance->nf_type, + ogs_sbi_self()->nf_instance->id, + OpenAPI_nf_type_NSSF)); } break; case OGS_FSM_EXIT_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { - ogs_info("[%s] NF de-registered", nf_instance->id); + if (NF_INSTANCE_IS_NRF(nf_instance)) { + ogs_info("[%s] NF de-registered", ogs_sbi_self()->nf_instance->id); if (nf_instance->time.heartbeat_interval) { ogs_timer_stop(nf_instance->t_heartbeat_interval); @@ -265,7 +280,8 @@ void amf_nf_state_registered(ogs_fsm_t *s, amf_event_t *e) no_heartbeat_margin)); } else { ogs_warn("[%s] HTTP response error [%d]", - nf_instance->id, message->res_status); + ogs_sbi_self()->nf_instance->id, + message->res_status); OGS_FSM_TRAN(s, &amf_nf_state_exception); } @@ -273,13 +289,14 @@ void amf_nf_state_registered(ogs_fsm_t *s, amf_event_t *e) DEFAULT ogs_error("[%s] Invalid resource name [%s]", - nf_instance->id, message->h.resource.component[0]); + ogs_sbi_self()->nf_instance->id, + message->h.resource.component[0]); END break; DEFAULT ogs_error("[%s] Invalid API name [%s]", - nf_instance->id, message->h.service.name); + ogs_sbi_self()->nf_instance->id, message->h.service.name); END break; @@ -294,26 +311,31 @@ void amf_nf_state_registered(ogs_fsm_t *s, amf_event_t *e) break; case AMF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - ogs_error("[%s] No heartbeat", nf_instance->id); + ogs_error("[%s] No heartbeat", ogs_sbi_self()->nf_instance->id); OGS_FSM_TRAN(s, &amf_nf_state_will_register); break; case AMF_TIMER_NF_INSTANCE_VALIDITY: - if (NF_INSTANCE_IS_OTHERS(nf_instance->id)) { - ogs_info("[%s] NF expired", nf_instance->id); - OGS_FSM_TRAN(s, &amf_nf_state_de_registered); - } + ogs_assert(!NF_INSTANCE_IS_NRF(nf_instance)); + ogs_assert(nf_instance->id); + + ogs_info("[%s] NF expired", nf_instance->id); + OGS_FSM_TRAN(s, &amf_nf_state_de_registered); break; default: - ogs_error("[%s] Unknown timer[%s:%d]", nf_instance->id, + ogs_error("[%s:%s] Unknown timer[%s:%d]", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", amf_timer_get_name(e->timer_id), e->timer_id); - break; } break; default: - ogs_error("Unknown event %s", amf_event_get_name(e)); + ogs_error("[%s:%s] Unknown event %s", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", + amf_event_get_name(e)); break; } } @@ -328,11 +350,12 @@ void amf_nf_state_de_registered(ogs_fsm_t *s, amf_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { - ogs_info("[%s] NF de-registered", nf_instance->id); + if (NF_INSTANCE_IS_NRF(nf_instance)) { + ogs_info("[%s] NF de-registered", ogs_sbi_self()->nf_instance->id); } break; @@ -340,7 +363,10 @@ void amf_nf_state_de_registered(ogs_fsm_t *s, amf_event_t *e) break; default: - ogs_error("Unknown event %s", amf_event_get_name(e)); + ogs_error("[%s:%s] Unknown event %s", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", + amf_event_get_name(e)); break; } } @@ -358,18 +384,21 @@ void amf_nf_state_exception(ogs_fsm_t *s, amf_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) + if (NF_INSTANCE_IS_NRF(nf_instance)) { ogs_timer_start(nf_instance->t_registration_interval, ogs_app()->time.message.sbi. nf_register_interval_in_exception); + } break; case OGS_FSM_EXIT_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) + if (NF_INSTANCE_IS_NRF(nf_instance)) { ogs_timer_stop(nf_instance->t_registration_interval); + } break; case AMF_EVT_SBI_TIMER: @@ -380,15 +409,17 @@ void amf_nf_state_exception(ogs_fsm_t *s, amf_event_t *e) addr = client->node.addr; ogs_assert(addr); - ogs_warn("[%s] Retry to registration with NRF", nf_instance->id); + ogs_warn("[%s] Retry to registration with NRF", + ogs_sbi_self()->nf_instance->id); OGS_FSM_TRAN(s, &amf_nf_state_will_register); break; default: - ogs_error("[%s] Unknown timer[%s:%d]", nf_instance->id, + ogs_error("[%s:%s] Unknown timer[%s:%d]", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", amf_timer_get_name(e->timer_id), e->timer_id); - break; } break; @@ -413,8 +444,10 @@ void amf_nf_state_exception(ogs_fsm_t *s, amf_event_t *e) break; default: - ogs_error("[%s] Unknown event %s", - nf_instance->id, amf_event_get_name(e)); + ogs_error("[%s:%s] Unknown event %s", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", + amf_event_get_name(e)); break; } } diff --git a/src/amf/nnrf-build.c b/src/amf/nnrf-build.c index e42a9fbd8..aa8961c81 100644 --- a/src/amf/nnrf-build.c +++ b/src/amf/nnrf-build.c @@ -19,18 +19,18 @@ #include "nnrf-build.h" -ogs_sbi_request_t *amf_nnrf_nfm_build_register( - ogs_sbi_nf_instance_t *nf_instance) +ogs_sbi_request_t *amf_nnrf_nfm_build_register(void) { + ogs_sbi_nf_instance_t *nf_instance = NULL; + ogs_sbi_message_t message; ogs_sbi_request_t *request = NULL; - ogs_sbi_client_t *client = NULL; OpenAPI_nf_profile_t *NFProfile = NULL; + nf_instance = ogs_sbi_self()->nf_instance; ogs_assert(nf_instance); - client = nf_instance->client; - ogs_assert(client); + ogs_assert(nf_instance->id); memset(&message, 0, sizeof(message)); message.h.method = (char *)OGS_SBI_HTTP_METHOD_PUT; @@ -38,11 +38,11 @@ ogs_sbi_request_t *amf_nnrf_nfm_build_register( message.h.api.version = (char *)OGS_SBI_API_V1; message.h.resource.component[0] = (char *)OGS_SBI_RESOURCE_NAME_NF_INSTANCES; - message.h.resource.component[1] = ogs_sbi_self()->nf_instance_id; + message.h.resource.component[1] = nf_instance->id; message.http.content_encoding = (char*)ogs_sbi_self()->content_encoding; - NFProfile = ogs_nnrf_nfm_build_nf_profile(nf_instance); + NFProfile = ogs_nnrf_nfm_build_nf_profile(); ogs_expect_or_return_val(NFProfile, NULL); message.NFProfile = NFProfile; diff --git a/src/amf/nnrf-build.h b/src/amf/nnrf-build.h index 77d80ae57..825e1e0be 100644 --- a/src/amf/nnrf-build.h +++ b/src/amf/nnrf-build.h @@ -26,8 +26,7 @@ extern "C" { #endif -ogs_sbi_request_t *amf_nnrf_nfm_build_register( - ogs_sbi_nf_instance_t *nf_instance); +ogs_sbi_request_t *amf_nnrf_nfm_build_register(void); ogs_sbi_request_t *amf_nnrf_disc_build_discover( char *nrf_id, diff --git a/src/amf/nnrf-handler.c b/src/amf/nnrf-handler.c index 6056b09a3..f184ad7e4 100644 --- a/src/amf/nnrf-handler.c +++ b/src/amf/nnrf-handler.c @@ -173,9 +173,10 @@ bool amf_nnrf_handle_nf_status_notify( nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); if (!nf_instance) { - nf_instance = ogs_sbi_nf_instance_add( - message.h.resource.component[1]); + nf_instance = ogs_sbi_nf_instance_add(); ogs_assert(nf_instance); + ogs_sbi_nf_instance_set_id(nf_instance, + message.h.resource.component[1]); amf_nf_fsm_init(nf_instance); @@ -336,8 +337,9 @@ void amf_nnrf_handle_nf_discover_search_result( nf_instance = ogs_sbi_nf_instance_find(NFProfile->nf_instance_id); if (!nf_instance) { - nf_instance = ogs_sbi_nf_instance_add(NFProfile->nf_instance_id); + nf_instance = ogs_sbi_nf_instance_add(); ogs_assert(nf_instance); + ogs_sbi_nf_instance_set_id(nf_instance, NFProfile->nf_instance_id); amf_nf_fsm_init(nf_instance); diff --git a/src/amf/nnssf-build.c b/src/amf/nnssf-build.c index 3daa0f363..9c1f311d7 100644 --- a/src/amf/nnssf-build.c +++ b/src/amf/nnssf-build.c @@ -34,8 +34,9 @@ ogs_sbi_request_t *amf_nnssf_nsselection_build_get( message.h.resource.component[0] = (char *)OGS_SBI_RESOURCE_NAME_NETWORK_SLICE_INFORMATION; - message.param.nf_id = ogs_sbi_self()->nf_instance_id; - message.param.nf_type = amf_self()->nf_type; + ogs_assert(ogs_sbi_self()->nf_instance); + message.param.nf_id = ogs_sbi_self()->nf_instance->id; + message.param.nf_type = ogs_sbi_self()->nf_instance->nf_type; message.param.slice_info_request_for_pdu_session_presence = true; message.param.roaming_indication = OpenAPI_roaming_indication_NON_ROAMING; diff --git a/src/amf/nsmf-build.c b/src/amf/nsmf-build.c index da6332963..e9e933b27 100644 --- a/src/amf/nsmf-build.c +++ b/src/amf/nsmf-build.c @@ -51,7 +51,8 @@ ogs_sbi_request_t *amf_nsmf_pdusession_build_create_sm_context( memset(&SmContextCreateData, 0, sizeof(SmContextCreateData)); - SmContextCreateData.serving_nf_id = ogs_sbi_self()->nf_instance_id; + ogs_assert(ogs_sbi_self()->nf_instance); + SmContextCreateData.serving_nf_id = ogs_sbi_self()->nf_instance->id; SmContextCreateData.serving_network = ogs_sbi_build_plmn_id_nid(&amf_ue->nr_tai.plmn_id); diff --git a/src/amf/nudm-build.c b/src/amf/nudm-build.c index 11adc3ad4..14913b0f2 100644 --- a/src/amf/nudm-build.c +++ b/src/amf/nudm-build.c @@ -44,7 +44,8 @@ ogs_sbi_request_t *amf_nudm_uecm_build_registration( memset(&Amf3GppAccessRegistration, 0, sizeof(Amf3GppAccessRegistration)); - Amf3GppAccessRegistration.amf_instance_id = ogs_sbi_self()->nf_instance_id; + ogs_assert(ogs_sbi_self()->nf_instance); + Amf3GppAccessRegistration.amf_instance_id = ogs_sbi_self()->nf_instance->id; server = ogs_list_first(&ogs_sbi_self()->server_list); ogs_assert(server); diff --git a/src/amf/sbi-path.c b/src/amf/sbi-path.c index 9d3d25974..470feba2a 100644 --- a/src/amf/sbi-path.c +++ b/src/amf/sbi-path.c @@ -70,43 +70,41 @@ static int client_cb(ogs_sbi_response_t *response, void *data) int amf_sbi_open(void) { ogs_sbi_nf_instance_t *nf_instance = NULL; + ogs_sbi_nf_service_t *service = NULL; if (ogs_sbi_server_start_all(server_cb) != OGS_OK) return OGS_ERROR; - /* - * The connection between NF and NRF is a little special. - * - * NF and NRF share nf_instance. I get the NRF EndPoint(client) information - * the configuration file via lib/sbi/context.c. - * - * ogs_sbi_self()->nf_instance_id means NF's InstanceId. - */ + /* Add SELF NF instance */ + nf_instance = ogs_sbi_self()->nf_instance; + ogs_assert(nf_instance); + + /* Build NF instance information. It will be transmitted to NRF. */ + ogs_sbi_nf_instance_build_default(nf_instance, OpenAPI_nf_type_AMF); + ogs_sbi_nf_instance_add_allowed_nf_type(nf_instance, OpenAPI_nf_type_SMF); + + /* Build NF service information. It will be transmitted to NRF. */ + service = ogs_sbi_nf_service_build_default(nf_instance, + (char*)OGS_SBI_SERVICE_NAME_NAMF_COMM); + ogs_assert(service); + ogs_sbi_nf_service_add_version(service, (char*)OGS_SBI_API_V1, + (char*)OGS_SBI_API_V1_0_0, NULL); + ogs_sbi_nf_service_add_allowed_nf_type(service, OpenAPI_nf_type_SMF); + + /* Initialize NRF NF Instance */ ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) { - ogs_sbi_nf_service_t *service = NULL; - ogs_sbi_client_t *client = NULL; + if (NF_INSTANCE_IS_NRF(nf_instance)) { + ogs_sbi_client_t *client = NULL; - /* Build NF instance information. It will be transmitted to NRF. */ - ogs_sbi_nf_instance_build_default(nf_instance, amf_self()->nf_type); - ogs_sbi_nf_instance_add_allowed_nf_type( - nf_instance, OpenAPI_nf_type_SMF); + /* Client callback is only used when NF sends to NRF */ + client = nf_instance->client; + ogs_assert(client); + client->cb = client_cb; - /* Build NF service information. It will be transmitted to NRF. */ - service = ogs_sbi_nf_service_build_default(nf_instance, - (char*)OGS_SBI_SERVICE_NAME_NAMF_COMM); - ogs_assert(service); - ogs_sbi_nf_service_add_version(service, (char*)OGS_SBI_API_V1, - (char*)OGS_SBI_API_V1_0_0, NULL); - ogs_sbi_nf_service_add_allowed_nf_type(service, OpenAPI_nf_type_SMF); - - /* Client callback is only used when NF sends to NRF */ - client = nf_instance->client; - ogs_assert(client); - client->cb = client_cb; - - /* NFRegister is sent and the response is received - * by the above client callback. */ - amf_nf_fsm_init(nf_instance); + /* NFRegister is sent and the response is received + * by the above client callback. */ + amf_nf_fsm_init(nf_instance); + } } return OGS_OK; @@ -126,7 +124,7 @@ bool amf_nnrf_nfm_send_nf_register(ogs_sbi_nf_instance_t *nf_instance) client = nf_instance->client; ogs_assert(client); - request = amf_nnrf_nfm_build_register(nf_instance); + request = amf_nnrf_nfm_build_register(); ogs_expect_or_return_val(request, false); return ogs_sbi_client_send_request( @@ -277,8 +275,10 @@ bool amf_sess_sbi_discover_by_nsi( client = sess->nssf.nrf.client; ogs_assert(client); + ogs_assert(ogs_sbi_self()->nf_instance); request = amf_nnrf_disc_build_discover( - sess->nssf.nrf.id, target_nf_type, amf_self()->nf_type); + sess->nssf.nrf.id, target_nf_type, + ogs_sbi_self()->nf_instance->nf_type); ogs_expect_or_return_val(request, false); return ogs_sbi_client_send_request( diff --git a/src/ausf/ausf-sm.c b/src/ausf/ausf-sm.c index 979c9a28a..b6ea582ca 100644 --- a/src/ausf/ausf-sm.c +++ b/src/ausf/ausf-sm.c @@ -323,7 +323,8 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e) ogs_fsm_dispatch(&nf_instance->sm, e); if (OGS_FSM_CHECK(&nf_instance->sm, ausf_nf_state_exception)) - ogs_error("[%s] State machine exception [%d]", + ogs_error("[%s:%s] State machine exception [%d]", + OpenAPI_nf_type_ToString(nf_instance->nf_type), nf_instance->id, e->timer_id); break; @@ -331,9 +332,11 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e) subscription = e->sbi.data; ogs_assert(subscription); + ogs_assert(ogs_sbi_self()->nf_instance); ogs_assert(true == ogs_nnrf_nfm_send_nf_status_subscribe(subscription->client, - ausf_self()->nf_type, subscription->req_nf_instance_id, + ogs_sbi_self()->nf_instance->nf_type, + subscription->req_nf_instance_id, subscription->subscr_cond.nf_type)); ogs_info("[%s] Subscription validity expired", subscription->id); diff --git a/src/ausf/context.c b/src/ausf/context.c index ca53342c1..9d666db5b 100644 --- a/src/ausf/context.c +++ b/src/ausf/context.c @@ -70,8 +70,6 @@ ausf_context_t *ausf_self(void) static int ausf_context_prepare(void) { - self.nf_type = OpenAPI_nf_type_AUSF; - return OGS_OK; } @@ -230,9 +228,5 @@ void ausf_ue_select_nf(ausf_ue_t *ausf_ue, OpenAPI_nf_type_e nf_type) ogs_assert(ausf_ue); ogs_assert(nf_type); - if (nf_type == OpenAPI_nf_type_NRF) - ogs_sbi_select_nrf(&ausf_ue->sbi, ausf_nf_state_registered); - else - ogs_sbi_select_first_nf( - &ausf_ue->sbi, nf_type, ausf_nf_state_registered); + ogs_sbi_select_nf(&ausf_ue->sbi, nf_type, ausf_nf_state_registered); } diff --git a/src/ausf/context.h b/src/ausf/context.h index b7a564826..3f0fe9d4d 100644 --- a/src/ausf/context.h +++ b/src/ausf/context.h @@ -39,8 +39,6 @@ extern int __ausf_log_domain; #define OGS_LOG_DOMAIN __ausf_log_domain typedef struct ausf_context_s { - OpenAPI_nf_type_e nf_type; - ogs_list_t ausf_ue_list; ogs_hash_t *suci_hash; ogs_hash_t *supi_hash; diff --git a/src/ausf/init.c b/src/ausf/init.c index df771cf32..250e9df16 100644 --- a/src/ausf/init.c +++ b/src/ausf/init.c @@ -27,9 +27,10 @@ int ausf_initialize() { int rv; + ogs_sbi_context_init(); + ausf_context_init(); ausf_event_init(); - ogs_sbi_context_init(); rv = ogs_sbi_context_parse_config("ausf", "nrf"); if (rv != OGS_OK) return rv; diff --git a/src/ausf/nf-sm.c b/src/ausf/nf-sm.c index c49a22fe0..a82d2b0fc 100644 --- a/src/ausf/nf-sm.c +++ b/src/ausf/nf-sm.c @@ -60,7 +60,6 @@ void ausf_nf_state_initial(ogs_fsm_t *s, ausf_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); - ogs_assert(nf_instance->id); ogs_assert(nf_instance->t_registration_interval); nf_instance->t_registration_interval->cb = @@ -73,9 +72,10 @@ void ausf_nf_state_initial(ogs_fsm_t *s, ausf_event_t *e) ogs_assert(nf_instance->t_validity); nf_instance->t_validity->cb = ausf_timer_nf_instance_validity; - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { + if (NF_INSTANCE_IS_NRF(nf_instance)) { OGS_FSM_TRAN(s, &ausf_nf_state_will_register); } else { + ogs_assert(nf_instance->id); OGS_FSM_TRAN(s, &ausf_nf_state_registered); } } @@ -102,19 +102,19 @@ void ausf_nf_state_will_register(ogs_fsm_t *s, ausf_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); + ogs_assert(NF_INSTANCE_IS_NRF(nf_instance)); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); + ogs_timer_start(nf_instance->t_registration_interval, + ogs_app()->time.message.sbi.nf_register_interval); ogs_assert(true == ausf_nnrf_nfm_send_nf_register(nf_instance)); break; case OGS_FSM_EXIT_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) - ogs_timer_stop(nf_instance->t_registration_interval); + ogs_timer_stop(nf_instance->t_registration_interval); break; case AUSF_EVT_SBI_CLIENT: @@ -133,20 +133,22 @@ void ausf_nf_state_will_register(ogs_fsm_t *s, ausf_event_t *e) OGS_FSM_TRAN(s, &ausf_nf_state_registered); } else { ogs_error("[%s] HTTP response error [%d]", - nf_instance->id, message->res_status); + ogs_sbi_self()->nf_instance->id, + message->res_status); OGS_FSM_TRAN(s, &ausf_nf_state_exception); } break; DEFAULT ogs_error("[%s] Invalid resource name [%s]", - nf_instance->id, message->h.resource.component[0]); + ogs_sbi_self()->nf_instance->id, + message->h.resource.component[0]); END break; DEFAULT ogs_error("[%s] Invalid API name [%s]", - nf_instance->id, message->h.service.name); + ogs_sbi_self()->nf_instance->id, message->h.service.name); END break; @@ -158,17 +160,18 @@ void ausf_nf_state_will_register(ogs_fsm_t *s, ausf_event_t *e) addr = client->node.addr; ogs_assert(addr); - ogs_warn("[%s] Retry to registration with NRF", nf_instance->id); + ogs_warn("[%s] Retry to registration with NRF", + ogs_sbi_self()->nf_instance->id); - if (NF_INSTANCE_IS_SELF(nf_instance->id)) - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); + ogs_timer_start(nf_instance->t_registration_interval, + ogs_app()->time.message.sbi.nf_register_interval); ogs_assert(true == ausf_nnrf_nfm_send_nf_register(nf_instance)); break; default: - ogs_error("[%s] Unknown timer[%s:%d]", nf_instance->id, + ogs_error("[%s] Unknown timer[%s:%d]", + ogs_sbi_self()->nf_instance->id, ausf_timer_get_name(e->timer_id), e->timer_id); } break; @@ -191,12 +194,14 @@ void ausf_nf_state_registered(ogs_fsm_t *s, ausf_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { + if (NF_INSTANCE_IS_NRF(nf_instance)) { ogs_info("[%s] NF registered [Heartbeat:%ds]", - nf_instance->id, nf_instance->time.heartbeat_interval); + ogs_sbi_self()->nf_instance->id, + nf_instance->time.heartbeat_interval); client = nf_instance->client; ogs_assert(client); @@ -212,14 +217,16 @@ void ausf_nf_state_registered(ogs_fsm_t *s, ausf_event_t *e) ogs_assert(true == ogs_nnrf_nfm_send_nf_status_subscribe(client, - ausf_self()->nf_type, nf_instance->id, OpenAPI_nf_type_UDM)); + ogs_sbi_self()->nf_instance->nf_type, + ogs_sbi_self()->nf_instance->id, + OpenAPI_nf_type_UDM)); } break; case OGS_FSM_EXIT_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { - ogs_info("[%s] NF de-registered", nf_instance->id); + if (NF_INSTANCE_IS_NRF(nf_instance)) { + ogs_info("[%s] NF de-registered", ogs_sbi_self()->nf_instance->id); if (nf_instance->time.heartbeat_interval) { ogs_timer_stop(nf_instance->t_heartbeat_interval); @@ -253,7 +260,8 @@ void ausf_nf_state_registered(ogs_fsm_t *s, ausf_event_t *e) no_heartbeat_margin)); } else { ogs_warn("[%s] HTTP response error [%d]", - nf_instance->id, message->res_status); + ogs_sbi_self()->nf_instance->id, + message->res_status); OGS_FSM_TRAN(s, &ausf_nf_state_exception); } @@ -261,13 +269,14 @@ void ausf_nf_state_registered(ogs_fsm_t *s, ausf_event_t *e) DEFAULT ogs_error("[%s] Invalid resource name [%s]", - nf_instance->id, message->h.resource.component[0]); + ogs_sbi_self()->nf_instance->id, + message->h.resource.component[0]); END break; DEFAULT ogs_error("[%s] Invalid API name [%s]", - nf_instance->id, message->h.service.name); + ogs_sbi_self()->nf_instance->id, message->h.service.name); END break; @@ -282,27 +291,31 @@ void ausf_nf_state_registered(ogs_fsm_t *s, ausf_event_t *e) break; case AUSF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - ogs_error("[%s] No heartbeat", nf_instance->id); + ogs_error("[%s] No heartbeat", ogs_sbi_self()->nf_instance->id); OGS_FSM_TRAN(s, &ausf_nf_state_will_register); break; case AUSF_TIMER_NF_INSTANCE_VALIDITY: - if (NF_INSTANCE_IS_OTHERS(nf_instance->id)) { - ogs_info("[%s] NF expired", nf_instance->id); - OGS_FSM_TRAN(s, &ausf_nf_state_de_registered); - } + ogs_assert(!NF_INSTANCE_IS_NRF(nf_instance)); + ogs_assert(nf_instance->id); + + ogs_info("[%s] NF expired", nf_instance->id); + OGS_FSM_TRAN(s, &ausf_nf_state_de_registered); break; default: - ogs_error("[%s] Unknown timer[%s:%d]", nf_instance->id, + ogs_error("[%s:%s] Unknown timer[%s:%d]", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", ausf_timer_get_name(e->timer_id), e->timer_id); - break; } break; default: - ogs_error("[%s] Unknown event %s", - nf_instance->id, ausf_event_get_name(e)); + ogs_error("[%s:%s] Unknown event %s", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", + ausf_event_get_name(e)); break; } } @@ -317,11 +330,12 @@ void ausf_nf_state_de_registered(ogs_fsm_t *s, ausf_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { - ogs_info("[%s] NF de-registered", nf_instance->id); + if (NF_INSTANCE_IS_NRF(nf_instance)) { + ogs_info("[%s] NF de-registered", ogs_sbi_self()->nf_instance->id); } break; @@ -329,8 +343,10 @@ void ausf_nf_state_de_registered(ogs_fsm_t *s, ausf_event_t *e) break; default: - ogs_error("[%s] Unknown event %s", - nf_instance->id, ausf_event_get_name(e)); + ogs_error("[%s:%s] Unknown event %s", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", + ausf_event_get_name(e)); break; } } @@ -348,18 +364,21 @@ void ausf_nf_state_exception(ogs_fsm_t *s, ausf_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) + if (NF_INSTANCE_IS_NRF(nf_instance)) { ogs_timer_start(nf_instance->t_registration_interval, ogs_app()->time.message.sbi. nf_register_interval_in_exception); + } break; case OGS_FSM_EXIT_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) + if (NF_INSTANCE_IS_NRF(nf_instance)) { ogs_timer_stop(nf_instance->t_registration_interval); + } break; case AUSF_EVT_SBI_TIMER: @@ -370,15 +389,17 @@ void ausf_nf_state_exception(ogs_fsm_t *s, ausf_event_t *e) addr = client->node.addr; ogs_assert(addr); - ogs_warn("[%s] Retry to registration with NRF", nf_instance->id); + ogs_warn("[%s] Retry to registration with NRF", + ogs_sbi_self()->nf_instance->id); OGS_FSM_TRAN(s, &ausf_nf_state_will_register); break; default: - ogs_error("[%s] Unknown timer[%s:%d]", nf_instance->id, + ogs_error("[%s:%s] Unknown timer[%s:%d]", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", ausf_timer_get_name(e->timer_id), e->timer_id); - break; } break; @@ -403,8 +424,10 @@ void ausf_nf_state_exception(ogs_fsm_t *s, ausf_event_t *e) break; default: - ogs_error("[%s] Unknown event %s", - nf_instance->id, ausf_event_get_name(e)); + ogs_error("[%s:%s] Unknown event %s", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", + ausf_event_get_name(e)); break; } } diff --git a/src/ausf/nnrf-build.c b/src/ausf/nnrf-build.c index 487db2c76..24da5ba18 100644 --- a/src/ausf/nnrf-build.c +++ b/src/ausf/nnrf-build.c @@ -19,18 +19,18 @@ #include "nnrf-build.h" -ogs_sbi_request_t *ausf_nnrf_nfm_build_register( - ogs_sbi_nf_instance_t *nf_instance) +ogs_sbi_request_t *ausf_nnrf_nfm_build_register(void) { + ogs_sbi_nf_instance_t *nf_instance = NULL; + ogs_sbi_message_t message; ogs_sbi_request_t *request = NULL; - ogs_sbi_client_t *client = NULL; OpenAPI_nf_profile_t *NFProfile = NULL; + nf_instance = ogs_sbi_self()->nf_instance; ogs_assert(nf_instance); - client = nf_instance->client; - ogs_assert(client); + ogs_assert(nf_instance->id); memset(&message, 0, sizeof(message)); message.h.method = (char *)OGS_SBI_HTTP_METHOD_PUT; @@ -38,11 +38,11 @@ ogs_sbi_request_t *ausf_nnrf_nfm_build_register( message.h.api.version = (char *)OGS_SBI_API_V1; message.h.resource.component[0] = (char *)OGS_SBI_RESOURCE_NAME_NF_INSTANCES; - message.h.resource.component[1] = ogs_sbi_self()->nf_instance_id; + message.h.resource.component[1] = nf_instance->id; message.http.content_encoding = (char*)ogs_sbi_self()->content_encoding; - NFProfile = ogs_nnrf_nfm_build_nf_profile(nf_instance); + NFProfile = ogs_nnrf_nfm_build_nf_profile(); ogs_expect_or_return_val(NFProfile, NULL); message.NFProfile = NFProfile; diff --git a/src/ausf/nnrf-build.h b/src/ausf/nnrf-build.h index ae5465ad4..79c5bd624 100644 --- a/src/ausf/nnrf-build.h +++ b/src/ausf/nnrf-build.h @@ -26,8 +26,7 @@ extern "C" { #endif -ogs_sbi_request_t *ausf_nnrf_nfm_build_register( - ogs_sbi_nf_instance_t *nf_instance); +ogs_sbi_request_t *ausf_nnrf_nfm_build_register(void); #ifdef __cplusplus } diff --git a/src/ausf/nnrf-handler.c b/src/ausf/nnrf-handler.c index 7467a0392..1a04197fe 100644 --- a/src/ausf/nnrf-handler.c +++ b/src/ausf/nnrf-handler.c @@ -170,9 +170,10 @@ bool ausf_nnrf_handle_nf_status_notify( nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); if (!nf_instance) { - nf_instance = ogs_sbi_nf_instance_add( - message.h.resource.component[1]); + nf_instance = ogs_sbi_nf_instance_add(); ogs_assert(nf_instance); + ogs_sbi_nf_instance_set_id(nf_instance, + message.h.resource.component[1]); ausf_nf_fsm_init(nf_instance); @@ -277,8 +278,9 @@ void ausf_nnrf_handle_nf_discover( nf_instance = ogs_sbi_nf_instance_find(NFProfile->nf_instance_id); if (!nf_instance) { - nf_instance = ogs_sbi_nf_instance_add(NFProfile->nf_instance_id); + nf_instance = ogs_sbi_nf_instance_add(); ogs_assert(nf_instance); + ogs_sbi_nf_instance_set_id(nf_instance, NFProfile->nf_instance_id); ausf_nf_fsm_init(nf_instance); diff --git a/src/ausf/nudm-build.c b/src/ausf/nudm-build.c index 360d0fbd2..b2782e63d 100644 --- a/src/ausf/nudm-build.c +++ b/src/ausf/nudm-build.c @@ -43,8 +43,9 @@ ogs_sbi_request_t *ausf_nudm_ueau_build_get(ausf_ue_t *ausf_ue, void *data) AuthenticationInfoRequest.serving_network_name = ausf_ue->serving_network_name; + ogs_assert(ogs_sbi_self()->nf_instance); AuthenticationInfoRequest.ausf_instance_id = - ogs_sbi_self()->nf_instance_id; + ogs_sbi_self()->nf_instance->id; if (data) { OpenAPI_resynchronization_info_t *recvinfo = data; @@ -88,7 +89,8 @@ ogs_sbi_request_t *ausf_nudm_ueau_build_result_confirmation_inform( AuthEvent->time_stamp = ogs_sbi_localtime_string(ogs_time_now()); ogs_expect_or_return_val(AuthEvent->time_stamp, NULL); - AuthEvent->nf_instance_id = ogs_sbi_self()->nf_instance_id; + ogs_assert(ogs_sbi_self()->nf_instance); + AuthEvent->nf_instance_id = ogs_sbi_self()->nf_instance->id; if (ausf_ue->auth_result == OpenAPI_auth_result_AUTHENTICATION_SUCCESS) AuthEvent->success = true; else diff --git a/src/ausf/sbi-path.c b/src/ausf/sbi-path.c index 102d1d3af..59ab56859 100644 --- a/src/ausf/sbi-path.c +++ b/src/ausf/sbi-path.c @@ -68,44 +68,41 @@ static int client_cb(ogs_sbi_response_t *response, void *data) int ausf_sbi_open(void) { ogs_sbi_nf_instance_t *nf_instance = NULL; + ogs_sbi_nf_service_t *service = NULL; if (ogs_sbi_server_start_all(server_cb) != OGS_OK) return OGS_ERROR; - /* - * The connection between NF and NRF is a little special. - * - * NF and NRF share nf_instance. I get the NRF EndPoint(client) information - * the configuration file via lib/sbi/context.c. - * And, the NFService information will be transmitted to NRF. - * - * ogs_sbi_self()->nf_instance_id means NF's InstanceId. - */ + /* Add SELF NF instance */ + nf_instance = ogs_sbi_self()->nf_instance; + ogs_assert(nf_instance); + + /* Build NF instance information. It will be transmitted to NRF. */ + ogs_sbi_nf_instance_build_default(nf_instance, OpenAPI_nf_type_AUSF); + ogs_sbi_nf_instance_add_allowed_nf_type(nf_instance, OpenAPI_nf_type_AMF); + + /* Build NF service information. It will be transmitted to NRF. */ + service = ogs_sbi_nf_service_build_default(nf_instance, + (char*)OGS_SBI_SERVICE_NAME_NAUSF_AUTH); + ogs_assert(service); + ogs_sbi_nf_service_add_version(service, (char*)OGS_SBI_API_V1, + (char*)OGS_SBI_API_V1_0_0, NULL); + ogs_sbi_nf_service_add_allowed_nf_type(service, OpenAPI_nf_type_AMF); + + /* Initialize NRF NF Instance */ ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) { - ogs_sbi_nf_service_t *service = NULL; - ogs_sbi_client_t *client = NULL; + if (NF_INSTANCE_IS_NRF(nf_instance)) { + ogs_sbi_client_t *client = NULL; - /* Build NF instance information. It will be transmitted to NRF. */ - ogs_sbi_nf_instance_build_default(nf_instance, ausf_self()->nf_type); - ogs_sbi_nf_instance_add_allowed_nf_type( - nf_instance, OpenAPI_nf_type_AMF); + /* Client callback is only used when NF sends to NRF */ + client = nf_instance->client; + ogs_assert(client); + client->cb = client_cb; - /* Build NF service information. It will be transmitted to NRF. */ - service = ogs_sbi_nf_service_build_default(nf_instance, - (char*)OGS_SBI_SERVICE_NAME_NAUSF_AUTH); - ogs_assert(service); - ogs_sbi_nf_service_add_version(service, (char*)OGS_SBI_API_V1, - (char*)OGS_SBI_API_V1_0_0, NULL); - ogs_sbi_nf_service_add_allowed_nf_type(service, OpenAPI_nf_type_AMF); - - /* Client callback is only used when NF sends to NRF */ - client = nf_instance->client; - ogs_assert(client); - client->cb = client_cb; - - /* NFRegister is sent and the response is received - * by the above client callback. */ - ausf_nf_fsm_init(nf_instance); + /* NFRegister is sent and the response is received + * by the above client callback. */ + ausf_nf_fsm_init(nf_instance); + } } return OGS_OK; @@ -125,7 +122,7 @@ bool ausf_nnrf_nfm_send_nf_register(ogs_sbi_nf_instance_t *nf_instance) client = nf_instance->client; ogs_assert(client); - request = ausf_nnrf_nfm_build_register(nf_instance); + request = ausf_nnrf_nfm_build_register(); ogs_expect_or_return_val(request, false); return ogs_sbi_client_send_request( diff --git a/src/bsf/bsf-sm.c b/src/bsf/bsf-sm.c index e02f8b17b..f7874412e 100644 --- a/src/bsf/bsf-sm.c +++ b/src/bsf/bsf-sm.c @@ -317,16 +317,20 @@ void bsf_state_operational(ogs_fsm_t *s, bsf_event_t *e) ogs_fsm_dispatch(&nf_instance->sm, e); if (OGS_FSM_CHECK(&nf_instance->sm, bsf_nf_state_exception)) - ogs_error("State machine exception [%d]", e->timer_id); + ogs_error("[%s:%s] State machine exception [%d]", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id, e->timer_id); break; case BSF_TIMER_SUBSCRIPTION_VALIDITY: subscription = e->sbi.data; ogs_assert(subscription); + ogs_assert(ogs_sbi_self()->nf_instance); ogs_assert(true == ogs_nnrf_nfm_send_nf_status_subscribe(subscription->client, - bsf_self()->nf_type, subscription->req_nf_instance_id, + ogs_sbi_self()->nf_instance->nf_type, + subscription->req_nf_instance_id, subscription->subscr_cond.nf_type)); ogs_info("Subscription validity expired [%s]", subscription->id); diff --git a/src/bsf/context.c b/src/bsf/context.c index 169239cfb..91ac65883 100644 --- a/src/bsf/context.c +++ b/src/bsf/context.c @@ -72,8 +72,6 @@ bsf_context_t *bsf_self(void) static int bsf_context_prepare(void) { - self.nf_type = OpenAPI_nf_type_BSF; - return OGS_OK; } @@ -331,8 +329,5 @@ void bsf_sess_select_nf(bsf_sess_t *sess, OpenAPI_nf_type_e nf_type) ogs_assert(sess); ogs_assert(nf_type); - if (nf_type == OpenAPI_nf_type_NRF) - ogs_sbi_select_nrf(&sess->sbi, bsf_nf_state_registered); - else - ogs_sbi_select_first_nf(&sess->sbi, nf_type, bsf_nf_state_registered); + ogs_sbi_select_nf(&sess->sbi, nf_type, bsf_nf_state_registered); } diff --git a/src/bsf/context.h b/src/bsf/context.h index f5fc5dd2f..ed9353f07 100644 --- a/src/bsf/context.h +++ b/src/bsf/context.h @@ -36,8 +36,6 @@ extern int __bsf_log_domain; #define OGS_LOG_DOMAIN __bsf_log_domain typedef struct bsf_context_s { - OpenAPI_nf_type_e nf_type; - ogs_hash_t *ipv4addr_hash; ogs_hash_t *ipv6prefix_hash; diff --git a/src/bsf/init.c b/src/bsf/init.c index 548f68322..95a9c24ea 100644 --- a/src/bsf/init.c +++ b/src/bsf/init.c @@ -29,9 +29,10 @@ int bsf_initialize() { int rv; + ogs_sbi_context_init(); + bsf_context_init(); bsf_event_init(); - ogs_sbi_context_init(); rv = ogs_sbi_context_parse_config("bsf", "nrf"); if (rv != OGS_OK) return rv; diff --git a/src/bsf/nf-sm.c b/src/bsf/nf-sm.c index b22a1d821..389cfbd7b 100644 --- a/src/bsf/nf-sm.c +++ b/src/bsf/nf-sm.c @@ -60,7 +60,6 @@ void bsf_nf_state_initial(ogs_fsm_t *s, bsf_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); - ogs_assert(nf_instance->id); ogs_assert(nf_instance->t_registration_interval); nf_instance->t_registration_interval->cb = @@ -73,9 +72,10 @@ void bsf_nf_state_initial(ogs_fsm_t *s, bsf_event_t *e) ogs_assert(nf_instance->t_validity); nf_instance->t_validity->cb = bsf_timer_nf_instance_validity; - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { + if (NF_INSTANCE_IS_NRF(nf_instance)) { OGS_FSM_TRAN(s, &bsf_nf_state_will_register); } else { + ogs_assert(nf_instance->id); OGS_FSM_TRAN(s, &bsf_nf_state_registered); } } @@ -102,19 +102,19 @@ void bsf_nf_state_will_register(ogs_fsm_t *s, bsf_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); + ogs_assert(NF_INSTANCE_IS_NRF(nf_instance)); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); + ogs_timer_start(nf_instance->t_registration_interval, + ogs_app()->time.message.sbi.nf_register_interval); ogs_assert(true == bsf_nnrf_nfm_send_nf_register(nf_instance)); break; case OGS_FSM_EXIT_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) - ogs_timer_stop(nf_instance->t_registration_interval); + ogs_timer_stop(nf_instance->t_registration_interval); break; case BSF_EVT_SBI_CLIENT: @@ -133,20 +133,22 @@ void bsf_nf_state_will_register(ogs_fsm_t *s, bsf_event_t *e) OGS_FSM_TRAN(s, &bsf_nf_state_registered); } else { ogs_error("[%s] HTTP Response Status Code [%d]", - nf_instance->id, message->res_status); + ogs_sbi_self()->nf_instance->id, + message->res_status); OGS_FSM_TRAN(s, &bsf_nf_state_exception); } break; DEFAULT ogs_error("[%s] Invalid resource name [%s]", - nf_instance->id, message->h.resource.component[0]); + ogs_sbi_self()->nf_instance->id, + message->h.resource.component[0]); END break; DEFAULT ogs_error("[%s] Invalid API name [%s]", - nf_instance->id, message->h.service.name); + ogs_sbi_self()->nf_instance->id, message->h.service.name); END break; @@ -158,24 +160,25 @@ void bsf_nf_state_will_register(ogs_fsm_t *s, bsf_event_t *e) addr = client->node.addr; ogs_assert(addr); - ogs_warn("[%s] Retry to registration with NRF", nf_instance->id); + ogs_warn("[%s] Retry to registration with NRF", + ogs_sbi_self()->nf_instance->id); - if (NF_INSTANCE_IS_SELF(nf_instance->id)) - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); + ogs_timer_start(nf_instance->t_registration_interval, + ogs_app()->time.message.sbi.nf_register_interval); ogs_assert(true == bsf_nnrf_nfm_send_nf_register(nf_instance)); break; default: - ogs_error("[%s] Unknown timer[%s:%d]", nf_instance->id, + ogs_error("[%s] Unknown timer[%s:%d]", + ogs_sbi_self()->nf_instance->id, bsf_timer_get_name(e->timer_id), e->timer_id); } break; default: ogs_error("[%s] Unknown event %s", - nf_instance->id, bsf_event_get_name(e)); + ogs_sbi_self()->nf_instance->id, bsf_event_get_name(e)); break; } } @@ -192,12 +195,14 @@ void bsf_nf_state_registered(ogs_fsm_t *s, bsf_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { + if (NF_INSTANCE_IS_NRF(nf_instance)) { ogs_info("[%s] NF registered [Heartbeat:%ds]", - nf_instance->id, nf_instance->time.heartbeat_interval); + ogs_sbi_self()->nf_instance->id, + nf_instance->time.heartbeat_interval); client = nf_instance->client; ogs_assert(client); @@ -215,8 +220,8 @@ void bsf_nf_state_registered(ogs_fsm_t *s, bsf_event_t *e) break; case OGS_FSM_EXIT_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { - ogs_info("[%s] NF de-registered", nf_instance->id); + if (NF_INSTANCE_IS_NRF(nf_instance)) { + ogs_info("[%s] NF de-registered", ogs_sbi_self()->nf_instance->id); if (nf_instance->time.heartbeat_interval) { ogs_timer_stop(nf_instance->t_heartbeat_interval); @@ -250,7 +255,8 @@ void bsf_nf_state_registered(ogs_fsm_t *s, bsf_event_t *e) no_heartbeat_margin)); } else { ogs_warn("[%s] HTTP response error [%d]", - nf_instance->id, message->res_status); + ogs_sbi_self()->nf_instance->id, + message->res_status); OGS_FSM_TRAN(s, &bsf_nf_state_exception); } @@ -258,13 +264,14 @@ void bsf_nf_state_registered(ogs_fsm_t *s, bsf_event_t *e) DEFAULT ogs_error("[%s] Invalid resource name [%s]", - nf_instance->id, message->h.resource.component[0]); + ogs_sbi_self()->nf_instance->id, + message->h.resource.component[0]); END break; DEFAULT ogs_error("[%s] Invalid API name [%s]", - nf_instance->id, message->h.service.name); + ogs_sbi_self()->nf_instance->id, message->h.service.name); END break; @@ -279,27 +286,31 @@ void bsf_nf_state_registered(ogs_fsm_t *s, bsf_event_t *e) break; case BSF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - ogs_error("[%s] No heartbeat", nf_instance->id); + ogs_error("[%s] No heartbeat", ogs_sbi_self()->nf_instance->id); OGS_FSM_TRAN(s, &bsf_nf_state_will_register); break; case BSF_TIMER_NF_INSTANCE_VALIDITY: - if (NF_INSTANCE_IS_OTHERS(nf_instance->id)) { - ogs_info("[%s] NF expired", nf_instance->id); - OGS_FSM_TRAN(s, &bsf_nf_state_de_registered); - } + ogs_assert(!NF_INSTANCE_IS_NRF(nf_instance)); + ogs_assert(nf_instance->id); + + ogs_info("[%s] NF expired", nf_instance->id); + OGS_FSM_TRAN(s, &bsf_nf_state_de_registered); break; default: - ogs_error("[%s] Unknown timer[%s:%d]", nf_instance->id, + ogs_error("[%s:%s] Unknown timer[%s:%d]", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", bsf_timer_get_name(e->timer_id), e->timer_id); - break; } break; default: - ogs_error("[%s] Unknown event %s", - nf_instance->id, bsf_event_get_name(e)); + ogs_error("[%s:%s] Unknown event %s", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", + bsf_event_get_name(e)); break; } } @@ -314,11 +325,12 @@ void bsf_nf_state_de_registered(ogs_fsm_t *s, bsf_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { - ogs_info("[%s] NF de-registered", nf_instance->id); + if (NF_INSTANCE_IS_NRF(nf_instance)) { + ogs_info("[%s] NF de-registered", ogs_sbi_self()->nf_instance->id); } break; @@ -326,8 +338,10 @@ void bsf_nf_state_de_registered(ogs_fsm_t *s, bsf_event_t *e) break; default: - ogs_error("[%s] Unknown event %s", - nf_instance->id, bsf_event_get_name(e)); + ogs_error("[%s:%s] Unknown event %s", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", + bsf_event_get_name(e)); break; } } @@ -345,18 +359,21 @@ void bsf_nf_state_exception(ogs_fsm_t *s, bsf_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) + if (NF_INSTANCE_IS_NRF(nf_instance)) { ogs_timer_start(nf_instance->t_registration_interval, ogs_app()->time.message.sbi. nf_register_interval_in_exception); + } break; case OGS_FSM_EXIT_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) + if (NF_INSTANCE_IS_NRF(nf_instance)) { ogs_timer_stop(nf_instance->t_registration_interval); + } break; case BSF_EVT_SBI_TIMER: @@ -367,15 +384,17 @@ void bsf_nf_state_exception(ogs_fsm_t *s, bsf_event_t *e) addr = client->node.addr; ogs_assert(addr); - ogs_warn("[%s] Retry to registration with NRF", nf_instance->id); + ogs_warn("[%s] Retry to registration with NRF", + ogs_sbi_self()->nf_instance->id); OGS_FSM_TRAN(s, &bsf_nf_state_will_register); break; default: - ogs_error("[%s] Unknown timer[%s:%d]", nf_instance->id, + ogs_error("[%s:%s] Unknown timer[%s:%d]", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", bsf_timer_get_name(e->timer_id), e->timer_id); - break; } break; @@ -400,8 +419,10 @@ void bsf_nf_state_exception(ogs_fsm_t *s, bsf_event_t *e) break; default: - ogs_error("[%s] Unknown event %s", - nf_instance->id, bsf_event_get_name(e)); + ogs_error("[%s:%s] Unknown event %s", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", + bsf_event_get_name(e)); break; } } diff --git a/src/bsf/nnrf-build.c b/src/bsf/nnrf-build.c index 3dd0c5ec4..cf21a1988 100644 --- a/src/bsf/nnrf-build.c +++ b/src/bsf/nnrf-build.c @@ -19,18 +19,18 @@ #include "nnrf-build.h" -ogs_sbi_request_t *bsf_nnrf_nfm_build_register( - ogs_sbi_nf_instance_t *nf_instance) +ogs_sbi_request_t *bsf_nnrf_nfm_build_register(void) { + ogs_sbi_nf_instance_t *nf_instance = NULL; + ogs_sbi_message_t message; ogs_sbi_request_t *request = NULL; - ogs_sbi_client_t *client = NULL; OpenAPI_nf_profile_t *NFProfile = NULL; + nf_instance = ogs_sbi_self()->nf_instance; ogs_assert(nf_instance); - client = nf_instance->client; - ogs_assert(client); + ogs_assert(nf_instance->id); memset(&message, 0, sizeof(message)); message.h.method = (char *)OGS_SBI_HTTP_METHOD_PUT; @@ -38,11 +38,11 @@ ogs_sbi_request_t *bsf_nnrf_nfm_build_register( message.h.api.version = (char *)OGS_SBI_API_V1; message.h.resource.component[0] = (char *)OGS_SBI_RESOURCE_NAME_NF_INSTANCES; - message.h.resource.component[1] = ogs_sbi_self()->nf_instance_id; + message.h.resource.component[1] = nf_instance->id; message.http.content_encoding = (char*)ogs_sbi_self()->content_encoding; - NFProfile = ogs_nnrf_nfm_build_nf_profile(nf_instance); + NFProfile = ogs_nnrf_nfm_build_nf_profile(); ogs_expect_or_return_val(NFProfile, NULL); message.NFProfile = NFProfile; diff --git a/src/bsf/nnrf-build.h b/src/bsf/nnrf-build.h index 29d13e5d2..f5333abd9 100644 --- a/src/bsf/nnrf-build.h +++ b/src/bsf/nnrf-build.h @@ -26,8 +26,7 @@ extern "C" { #endif -ogs_sbi_request_t *bsf_nnrf_nfm_build_register( - ogs_sbi_nf_instance_t *nf_instance); +ogs_sbi_request_t *bsf_nnrf_nfm_build_register(void); #ifdef __cplusplus } diff --git a/src/bsf/nnrf-handler.c b/src/bsf/nnrf-handler.c index c0bd7d670..e17f0aabc 100644 --- a/src/bsf/nnrf-handler.c +++ b/src/bsf/nnrf-handler.c @@ -171,9 +171,10 @@ bool bsf_nnrf_handle_nf_status_notify( nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); if (!nf_instance) { - nf_instance = ogs_sbi_nf_instance_add( - message.h.resource.component[1]); + nf_instance = ogs_sbi_nf_instance_add(); ogs_assert(nf_instance); + ogs_sbi_nf_instance_set_id(nf_instance, + message.h.resource.component[1]); bsf_nf_fsm_init(nf_instance); @@ -278,8 +279,9 @@ void bsf_nnrf_handle_nf_discover( nf_instance = ogs_sbi_nf_instance_find(NFProfile->nf_instance_id); if (!nf_instance) { - nf_instance = ogs_sbi_nf_instance_add(NFProfile->nf_instance_id); + nf_instance = ogs_sbi_nf_instance_add(); ogs_assert(nf_instance); + ogs_sbi_nf_instance_set_id(nf_instance, NFProfile->nf_instance_id); bsf_nf_fsm_init(nf_instance); diff --git a/src/bsf/sbi-path.c b/src/bsf/sbi-path.c index 4ce2777ec..36cd59af8 100644 --- a/src/bsf/sbi-path.c +++ b/src/bsf/sbi-path.c @@ -68,44 +68,41 @@ static int client_cb(ogs_sbi_response_t *response, void *data) int bsf_sbi_open(void) { ogs_sbi_nf_instance_t *nf_instance = NULL; + ogs_sbi_nf_service_t *service = NULL; if (ogs_sbi_server_start_all(server_cb) != OGS_OK) return OGS_ERROR; - /* - * The connection between NF and NRF is a little special. - * - * NF and NRF share nf_instance. I get the NRF EndPoint(client) information - * the configuration file via lib/sbi/context.c. - * And, the NFService information will be transmitted to NRF. - * - * ogs_sbi_self()->nf_instance_id means NF's InstanceId. - */ + /* Add SELF NF instance */ + nf_instance = ogs_sbi_self()->nf_instance; + ogs_assert(nf_instance); + + /* Build NF instance information. It will be transmitted to NRF. */ + ogs_sbi_nf_instance_build_default(nf_instance, OpenAPI_nf_type_BSF); + ogs_sbi_nf_instance_add_allowed_nf_type(nf_instance, OpenAPI_nf_type_PCF); + + /* Build NF service information. It will be transmitted to NRF. */ + service = ogs_sbi_nf_service_build_default(nf_instance, + (char*)OGS_SBI_SERVICE_NAME_NBSF_MANAGEMENT); + ogs_assert(service); + ogs_sbi_nf_service_add_version(service, (char*)OGS_SBI_API_V1, + (char*)OGS_SBI_API_V1_0_0, NULL); + ogs_sbi_nf_service_add_allowed_nf_type(service, OpenAPI_nf_type_PCF); + + /* Initialize NRF NF Instance */ ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) { - ogs_sbi_nf_service_t *service = NULL; - ogs_sbi_client_t *client = NULL; + if (NF_INSTANCE_IS_NRF(nf_instance)) { + ogs_sbi_client_t *client = NULL; - /* Build NF instance information. It will be transmitted to NRF. */ - ogs_sbi_nf_instance_build_default(nf_instance, bsf_self()->nf_type); - ogs_sbi_nf_instance_add_allowed_nf_type( - nf_instance, OpenAPI_nf_type_PCF); + /* Client callback is only used when NF sends to NRF */ + client = nf_instance->client; + ogs_assert(client); + client->cb = client_cb; - /* Build NF service information. It will be transmitted to NRF. */ - service = ogs_sbi_nf_service_build_default(nf_instance, - (char*)OGS_SBI_SERVICE_NAME_NBSF_MANAGEMENT); - ogs_assert(service); - ogs_sbi_nf_service_add_version(service, (char*)OGS_SBI_API_V1, - (char*)OGS_SBI_API_V1_0_0, NULL); - ogs_sbi_nf_service_add_allowed_nf_type(service, OpenAPI_nf_type_PCF); - - /* Client callback is only used when NF sends to NRF */ - client = nf_instance->client; - ogs_assert(client); - client->cb = client_cb; - - /* NFRegister is sent and the response is received - * by the above client callback. */ - bsf_nf_fsm_init(nf_instance); + /* NFRegister is sent and the response is received + * by the above client callback. */ + bsf_nf_fsm_init(nf_instance); + } } return OGS_OK; @@ -125,7 +122,7 @@ bool bsf_nnrf_nfm_send_nf_register(ogs_sbi_nf_instance_t *nf_instance) client = nf_instance->client; ogs_assert(client); - request = bsf_nnrf_nfm_build_register(nf_instance); + request = bsf_nnrf_nfm_build_register(); ogs_expect_or_return_val(request, false); return ogs_sbi_client_send_request( diff --git a/src/nrf/init.c b/src/nrf/init.c index 9c0e1f9b4..26f8b3999 100644 --- a/src/nrf/init.c +++ b/src/nrf/init.c @@ -27,9 +27,10 @@ int nrf_initialize() { int rv; + ogs_sbi_context_init(); + nrf_context_init(); nrf_event_init(); - ogs_sbi_context_init(); rv = ogs_sbi_context_parse_config("nrf", NULL); if (rv != OGS_OK) return rv; diff --git a/src/nrf/nnrf-build.c b/src/nrf/nnrf-build.c index c2142d7f6..bdaf15608 100644 --- a/src/nrf/nnrf-build.c +++ b/src/nrf/nnrf-build.c @@ -36,6 +36,7 @@ ogs_sbi_request_t *nrf_nnrf_nfm_build_nf_status_notify( ogs_assert(subscription); ogs_assert(event); ogs_assert(nf_instance); + ogs_assert(nf_instance->id); memset(&message, 0, sizeof(message)); message.h.method = (char *)OGS_SBI_HTTP_METHOD_POST; diff --git a/src/nrf/nrf-sm.c b/src/nrf/nrf-sm.c index d70590b3e..e6635b4aa 100644 --- a/src/nrf/nrf-sm.c +++ b/src/nrf/nrf-sm.c @@ -105,7 +105,8 @@ void nrf_state_operational(ogs_fsm_t *s, nrf_event_t *e) if (!nf_instance) { SWITCH(message.h.method) CASE(OGS_SBI_HTTP_METHOD_PUT) - if (ogs_sbi_nf_instance_maximum_number_is_reached()) { + if (ogs_sbi_nf_instance_maximum_number_is_reached()) + { ogs_warn("Can't add instance [%s] " "due to insufficient space", message.h.resource.component[1]); @@ -118,9 +119,11 @@ void nrf_state_operational(ogs_fsm_t *s, nrf_event_t *e) message.h.resource.component[1])); break; } - nf_instance = ogs_sbi_nf_instance_add( - message.h.resource.component[1]); + nf_instance = ogs_sbi_nf_instance_add(); ogs_assert(nf_instance); + ogs_sbi_nf_instance_set_id(nf_instance, + message.h.resource.component[1]); + nrf_nf_fsm_init(nf_instance); break; DEFAULT diff --git a/src/nssf/context.c b/src/nssf/context.c index bd64d7684..6b50fb8ad 100644 --- a/src/nssf/context.c +++ b/src/nssf/context.c @@ -59,8 +59,6 @@ nssf_context_t *nssf_self(void) static int nssf_context_prepare(void) { - self.nf_type = OpenAPI_nf_type_NSSF; - return OGS_OK; } diff --git a/src/nssf/context.h b/src/nssf/context.h index d2743775a..d20ccaded 100644 --- a/src/nssf/context.h +++ b/src/nssf/context.h @@ -38,8 +38,6 @@ extern int __nssf_log_domain; #define OGS_LOG_DOMAIN __nssf_log_domain typedef struct nssf_context_s { - OpenAPI_nf_type_e nf_type; - ogs_list_t nsi_list; /* NSI List */ } nssf_context_t; diff --git a/src/nssf/init.c b/src/nssf/init.c index d5e21d853..49df3a7ce 100644 --- a/src/nssf/init.c +++ b/src/nssf/init.c @@ -27,9 +27,10 @@ int nssf_initialize() { int rv; + ogs_sbi_context_init(); + nssf_context_init(); nssf_event_init(); - ogs_sbi_context_init(); rv = ogs_sbi_context_parse_config("nssf", "nrf"); if (rv != OGS_OK) return rv; diff --git a/src/nssf/nf-sm.c b/src/nssf/nf-sm.c index bf635635e..b4bc2f670 100644 --- a/src/nssf/nf-sm.c +++ b/src/nssf/nf-sm.c @@ -60,7 +60,6 @@ void nssf_nf_state_initial(ogs_fsm_t *s, nssf_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); - ogs_assert(nf_instance->id); ogs_assert(nf_instance->t_registration_interval); nf_instance->t_registration_interval->cb = @@ -73,9 +72,10 @@ void nssf_nf_state_initial(ogs_fsm_t *s, nssf_event_t *e) ogs_assert(nf_instance->t_validity); nf_instance->t_validity->cb = nssf_timer_nf_instance_validity; - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { + if (NF_INSTANCE_IS_NRF(nf_instance)) { OGS_FSM_TRAN(s, &nssf_nf_state_will_register); } else { + ogs_assert(nf_instance->id); OGS_FSM_TRAN(s, &nssf_nf_state_registered); } } @@ -102,19 +102,19 @@ void nssf_nf_state_will_register(ogs_fsm_t *s, nssf_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); + ogs_assert(NF_INSTANCE_IS_NRF(nf_instance)); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); + ogs_timer_start(nf_instance->t_registration_interval, + ogs_app()->time.message.sbi.nf_register_interval); ogs_assert(true == nssf_nnrf_nfm_send_nf_register(nf_instance)); break; case OGS_FSM_EXIT_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) - ogs_timer_stop(nf_instance->t_registration_interval); + ogs_timer_stop(nf_instance->t_registration_interval); break; case NSSF_EVT_SBI_CLIENT: @@ -133,20 +133,22 @@ void nssf_nf_state_will_register(ogs_fsm_t *s, nssf_event_t *e) OGS_FSM_TRAN(s, &nssf_nf_state_registered); } else { ogs_error("[%s] HTTP response error [%d]", - nf_instance->id, message->res_status); + ogs_sbi_self()->nf_instance->id, + message->res_status); OGS_FSM_TRAN(s, &nssf_nf_state_exception); } break; DEFAULT ogs_error("[%s] Invalid resource name [%s]", - nf_instance->id, message->h.resource.component[0]); + ogs_sbi_self()->nf_instance->id, + message->h.resource.component[0]); END break; DEFAULT ogs_error("[%s] Invalid API name [%s]", - nf_instance->id, message->h.service.name); + ogs_sbi_self()->nf_instance->id, message->h.service.name); END break; @@ -158,17 +160,18 @@ void nssf_nf_state_will_register(ogs_fsm_t *s, nssf_event_t *e) addr = client->node.addr; ogs_assert(addr); - ogs_warn("[%s] Retry to registration with NRF", nf_instance->id); + ogs_warn("[%s] Retry to registration with NRF", + ogs_sbi_self()->nf_instance->id); - if (NF_INSTANCE_IS_SELF(nf_instance->id)) - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); + ogs_timer_start(nf_instance->t_registration_interval, + ogs_app()->time.message.sbi.nf_register_interval); ogs_assert(true == nssf_nnrf_nfm_send_nf_register(nf_instance)); break; default: - ogs_error("[%s] Unknown timer[%s:%d]", nf_instance->id, + ogs_error("[%s] Unknown timer[%s:%d]", + ogs_sbi_self()->nf_instance->id, nssf_timer_get_name(e->timer_id), e->timer_id); } break; @@ -191,12 +194,14 @@ void nssf_nf_state_registered(ogs_fsm_t *s, nssf_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { + if (NF_INSTANCE_IS_NRF(nf_instance)) { ogs_info("[%s] NF registered [Heartbeat:%ds]", - nf_instance->id, nf_instance->time.heartbeat_interval); + ogs_sbi_self()->nf_instance->id, + nf_instance->time.heartbeat_interval); client = nf_instance->client; ogs_assert(client); @@ -214,8 +219,8 @@ void nssf_nf_state_registered(ogs_fsm_t *s, nssf_event_t *e) break; case OGS_FSM_EXIT_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { - ogs_info("[%s] NF de-registered", nf_instance->id); + if (NF_INSTANCE_IS_NRF(nf_instance)) { + ogs_info("[%s] NF de-registered", ogs_sbi_self()->nf_instance->id); if (nf_instance->time.heartbeat_interval) { ogs_timer_stop(nf_instance->t_heartbeat_interval); @@ -249,7 +254,8 @@ void nssf_nf_state_registered(ogs_fsm_t *s, nssf_event_t *e) no_heartbeat_margin)); } else { ogs_warn("[%s] HTTP response error [%d]", - nf_instance->id, message->res_status); + ogs_sbi_self()->nf_instance->id, + message->res_status); OGS_FSM_TRAN(s, &nssf_nf_state_exception); } @@ -257,13 +263,14 @@ void nssf_nf_state_registered(ogs_fsm_t *s, nssf_event_t *e) DEFAULT ogs_error("[%s] Invalid resource name [%s]", - nf_instance->id, message->h.resource.component[0]); + ogs_sbi_self()->nf_instance->id, + message->h.resource.component[0]); END break; DEFAULT ogs_error("[%s] Invalid API name [%s]", - nf_instance->id, message->h.service.name); + ogs_sbi_self()->nf_instance->id, message->h.service.name); END break; @@ -278,27 +285,31 @@ void nssf_nf_state_registered(ogs_fsm_t *s, nssf_event_t *e) break; case NSSF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - ogs_error("[%s] No heartbeat", nf_instance->id); + ogs_error("[%s] No heartbeat", ogs_sbi_self()->nf_instance->id); OGS_FSM_TRAN(s, &nssf_nf_state_will_register); break; case NSSF_TIMER_NF_INSTANCE_VALIDITY: - if (NF_INSTANCE_IS_OTHERS(nf_instance->id)) { - ogs_info("[%s] NF expired", nf_instance->id); - OGS_FSM_TRAN(s, &nssf_nf_state_de_registered); - } + ogs_assert(!NF_INSTANCE_IS_NRF(nf_instance)); + ogs_assert(nf_instance->id); + + ogs_info("[%s] NF expired", nf_instance->id); + OGS_FSM_TRAN(s, &nssf_nf_state_de_registered); break; default: - ogs_error("[%s] Unknown timer[%s:%d]", nf_instance->id, + ogs_error("[%s:%s] Unknown timer[%s:%d]", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", nssf_timer_get_name(e->timer_id), e->timer_id); - break; } break; default: - ogs_error("[%s] Unknown event %s", - nf_instance->id, nssf_event_get_name(e)); + ogs_error("[%s:%s] Unknown event %s", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", + nssf_event_get_name(e)); break; } } @@ -313,11 +324,12 @@ void nssf_nf_state_de_registered(ogs_fsm_t *s, nssf_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { - ogs_info("[%s] NF de-registered", nf_instance->id); + if (NF_INSTANCE_IS_NRF(nf_instance)) { + ogs_info("[%s] NF de-registered", ogs_sbi_self()->nf_instance->id); } break; @@ -325,8 +337,10 @@ void nssf_nf_state_de_registered(ogs_fsm_t *s, nssf_event_t *e) break; default: - ogs_error("[%s] Unknown event %s", - nf_instance->id, nssf_event_get_name(e)); + ogs_error("[%s:%s] Unknown event %s", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", + nssf_event_get_name(e)); break; } } @@ -344,18 +358,21 @@ void nssf_nf_state_exception(ogs_fsm_t *s, nssf_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) + if (NF_INSTANCE_IS_NRF(nf_instance)) { ogs_timer_start(nf_instance->t_registration_interval, ogs_app()->time.message.sbi. nf_register_interval_in_exception); + } break; case OGS_FSM_EXIT_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) + if (NF_INSTANCE_IS_NRF(nf_instance)) { ogs_timer_stop(nf_instance->t_registration_interval); + } break; case NSSF_EVT_SBI_TIMER: @@ -366,15 +383,17 @@ void nssf_nf_state_exception(ogs_fsm_t *s, nssf_event_t *e) addr = client->node.addr; ogs_assert(addr); - ogs_warn("[%s] Retry to registration with NRF", nf_instance->id); + ogs_warn("[%s] Retry to registration with NRF", + ogs_sbi_self()->nf_instance->id); OGS_FSM_TRAN(s, &nssf_nf_state_will_register); break; default: - ogs_error("[%s] Unknown timer[%s:%d]", nf_instance->id, + ogs_error("[%s:%s] Unknown timer[%s:%d]", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", nssf_timer_get_name(e->timer_id), e->timer_id); - break; } break; @@ -399,8 +418,10 @@ void nssf_nf_state_exception(ogs_fsm_t *s, nssf_event_t *e) break; default: - ogs_error("[%s] Unknown event %s", - nf_instance->id, nssf_event_get_name(e)); + ogs_error("[%s:%s] Unknown event %s", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", + nssf_event_get_name(e)); break; } } diff --git a/src/nssf/nnrf-build.c b/src/nssf/nnrf-build.c index 97ce8eddb..56ec2601a 100644 --- a/src/nssf/nnrf-build.c +++ b/src/nssf/nnrf-build.c @@ -19,18 +19,18 @@ #include "nnrf-build.h" -ogs_sbi_request_t *nssf_nnrf_nfm_build_register( - ogs_sbi_nf_instance_t *nf_instance) +ogs_sbi_request_t *nssf_nnrf_nfm_build_register(void) { + ogs_sbi_nf_instance_t *nf_instance = NULL; + ogs_sbi_message_t message; ogs_sbi_request_t *request = NULL; - ogs_sbi_client_t *client = NULL; OpenAPI_nf_profile_t *NFProfile = NULL; + nf_instance = ogs_sbi_self()->nf_instance; ogs_assert(nf_instance); - client = nf_instance->client; - ogs_assert(client); + ogs_assert(nf_instance->id); memset(&message, 0, sizeof(message)); message.h.method = (char *)OGS_SBI_HTTP_METHOD_PUT; @@ -38,11 +38,11 @@ ogs_sbi_request_t *nssf_nnrf_nfm_build_register( message.h.api.version = (char *)OGS_SBI_API_V1; message.h.resource.component[0] = (char *)OGS_SBI_RESOURCE_NAME_NF_INSTANCES; - message.h.resource.component[1] = ogs_sbi_self()->nf_instance_id; + message.h.resource.component[1] = nf_instance->id; message.http.content_encoding = (char*)ogs_sbi_self()->content_encoding; - NFProfile = ogs_nnrf_nfm_build_nf_profile(nf_instance); + NFProfile = ogs_nnrf_nfm_build_nf_profile(); ogs_expect_or_return_val(NFProfile, NULL); message.NFProfile = NFProfile; diff --git a/src/nssf/nnrf-build.h b/src/nssf/nnrf-build.h index 4598900f8..1304e69aa 100644 --- a/src/nssf/nnrf-build.h +++ b/src/nssf/nnrf-build.h @@ -26,8 +26,7 @@ extern "C" { #endif -ogs_sbi_request_t *nssf_nnrf_nfm_build_register( - ogs_sbi_nf_instance_t *nf_instance); +ogs_sbi_request_t *nssf_nnrf_nfm_build_register(void); #ifdef __cplusplus } diff --git a/src/nssf/nnrf-handler.c b/src/nssf/nnrf-handler.c index f2e296e98..32ebecdfa 100644 --- a/src/nssf/nnrf-handler.c +++ b/src/nssf/nnrf-handler.c @@ -170,9 +170,10 @@ bool nssf_nnrf_handle_nf_status_notify( nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); if (!nf_instance) { - nf_instance = ogs_sbi_nf_instance_add( - message.h.resource.component[1]); + nf_instance = ogs_sbi_nf_instance_add(); ogs_assert(nf_instance); + ogs_sbi_nf_instance_set_id(nf_instance, + message.h.resource.component[1]); nssf_nf_fsm_init(nf_instance); diff --git a/src/nssf/nssf-sm.c b/src/nssf/nssf-sm.c index da53d9383..b0b404666 100644 --- a/src/nssf/nssf-sm.c +++ b/src/nssf/nssf-sm.c @@ -234,7 +234,8 @@ void nssf_state_operational(ogs_fsm_t *s, nssf_event_t *e) ogs_fsm_dispatch(&nf_instance->sm, e); if (OGS_FSM_CHECK(&nf_instance->sm, nssf_nf_state_exception)) - ogs_error("[%s] State machine exception [%d]", + ogs_error("[%s:%s] State machine exception [%d]", + OpenAPI_nf_type_ToString(nf_instance->nf_type), nf_instance->id, e->timer_id); break; @@ -242,9 +243,11 @@ void nssf_state_operational(ogs_fsm_t *s, nssf_event_t *e) subscription = e->sbi.data; ogs_assert(subscription); + ogs_assert(ogs_sbi_self()->nf_instance); ogs_assert(true == ogs_nnrf_nfm_send_nf_status_subscribe(subscription->client, - nssf_self()->nf_type, subscription->req_nf_instance_id, + ogs_sbi_self()->nf_instance->nf_type, + subscription->req_nf_instance_id, subscription->subscr_cond.nf_type)); ogs_info("[%s] Subscription validity expired", subscription->id); diff --git a/src/nssf/sbi-path.c b/src/nssf/sbi-path.c index 49146cdb5..f7c548180 100644 --- a/src/nssf/sbi-path.c +++ b/src/nssf/sbi-path.c @@ -68,44 +68,41 @@ static int client_cb(ogs_sbi_response_t *response, void *data) int nssf_sbi_open(void) { ogs_sbi_nf_instance_t *nf_instance = NULL; + ogs_sbi_nf_service_t *service = NULL; if (ogs_sbi_server_start_all(server_cb) != OGS_OK) return OGS_ERROR; - /* - * The connection between NF and NRF is a little special. - * - * NF and NRF share nf_instance. I get the NRF EndPoint(client) information - * the configuration file via lib/sbi/context.c. - * And, the NFService information will be transmitted to NRF. - * - * ogs_sbi_self()->nf_instance_id means NF's InstanceId. - */ + /* Add SELF NF instance */ + nf_instance = ogs_sbi_self()->nf_instance; + ogs_assert(nf_instance); + + /* Build NF instance information. It will be transmitted to NRF. */ + ogs_sbi_nf_instance_build_default(nf_instance, OpenAPI_nf_type_NSSF); + ogs_sbi_nf_instance_add_allowed_nf_type(nf_instance, OpenAPI_nf_type_AMF); + + /* Build NF service information. It will be transmitted to NRF. */ + service = ogs_sbi_nf_service_build_default(nf_instance, + (char*)OGS_SBI_SERVICE_NAME_NNSSF_NSSELECTION); + ogs_assert(service); + ogs_sbi_nf_service_add_version(service, (char*)OGS_SBI_API_V2, + (char*)OGS_SBI_API_V2_0_0, NULL); + ogs_sbi_nf_service_add_allowed_nf_type(service, OpenAPI_nf_type_AMF); + + /* Initialize NRF NF Instance */ ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) { - ogs_sbi_nf_service_t *service = NULL; - ogs_sbi_client_t *client = NULL; + if (NF_INSTANCE_IS_NRF(nf_instance)) { + ogs_sbi_client_t *client = NULL; - /* Build NF instance information. It will be transmitted to NRF. */ - ogs_sbi_nf_instance_build_default(nf_instance, nssf_self()->nf_type); - ogs_sbi_nf_instance_add_allowed_nf_type( - nf_instance, OpenAPI_nf_type_AMF); + /* Client callback is only used when NF sends to NRF */ + client = nf_instance->client; + ogs_assert(client); + client->cb = client_cb; - /* Build NF service information. It will be transmitted to NRF. */ - service = ogs_sbi_nf_service_build_default(nf_instance, - (char*)OGS_SBI_SERVICE_NAME_NNSSF_NSSELECTION); - ogs_assert(service); - ogs_sbi_nf_service_add_version(service, (char*)OGS_SBI_API_V2, - (char*)OGS_SBI_API_V2_0_0, NULL); - ogs_sbi_nf_service_add_allowed_nf_type(service, OpenAPI_nf_type_AMF); - - /* Client callback is only used when NF sends to NRF */ - client = nf_instance->client; - ogs_assert(client); - client->cb = client_cb; - - /* NFRegister is sent and the response is received - * by the above client callback. */ - nssf_nf_fsm_init(nf_instance); + /* NFRegister is sent and the response is received + * by the above client callback. */ + nssf_nf_fsm_init(nf_instance); + } } return OGS_OK; @@ -125,7 +122,7 @@ bool nssf_nnrf_nfm_send_nf_register(ogs_sbi_nf_instance_t *nf_instance) client = nf_instance->client; ogs_assert(client); - request = nssf_nnrf_nfm_build_register(nf_instance); + request = nssf_nnrf_nfm_build_register(); ogs_expect_or_return_val(request, false); return ogs_sbi_client_send_request( diff --git a/src/pcf/context.c b/src/pcf/context.c index 389acd06a..e1ef6b61a 100644 --- a/src/pcf/context.c +++ b/src/pcf/context.c @@ -85,8 +85,6 @@ pcf_context_t *pcf_self(void) static int pcf_context_prepare(void) { - self.nf_type = OpenAPI_nf_type_PCF; - return OGS_OK; } @@ -506,10 +504,7 @@ void pcf_ue_select_nf(pcf_ue_t *pcf_ue, OpenAPI_nf_type_e nf_type) ogs_assert(pcf_ue); ogs_assert(nf_type); - if (nf_type == OpenAPI_nf_type_NRF) - ogs_sbi_select_nrf(&pcf_ue->sbi, pcf_nf_state_registered); - else - ogs_sbi_select_first_nf(&pcf_ue->sbi, nf_type, pcf_nf_state_registered); + ogs_sbi_select_nf(&pcf_ue->sbi, nf_type, pcf_nf_state_registered); } void pcf_sess_select_nf(pcf_sess_t *sess, OpenAPI_nf_type_e nf_type) @@ -517,10 +512,7 @@ void pcf_sess_select_nf(pcf_sess_t *sess, OpenAPI_nf_type_e nf_type) ogs_assert(sess); ogs_assert(nf_type); - if (nf_type == OpenAPI_nf_type_NRF) - ogs_sbi_select_nrf(&sess->sbi, pcf_nf_state_registered); - else - ogs_sbi_select_first_nf(&sess->sbi, nf_type, pcf_nf_state_registered); + ogs_sbi_select_nf(&sess->sbi, nf_type, pcf_nf_state_registered); } pcf_app_t *pcf_app_add(pcf_sess_t *sess) diff --git a/src/pcf/context.h b/src/pcf/context.h index 56ab21a83..3ffdb6a30 100644 --- a/src/pcf/context.h +++ b/src/pcf/context.h @@ -40,8 +40,6 @@ extern int __pcf_log_domain; #define OGS_LOG_DOMAIN __pcf_log_domain typedef struct pcf_context_s { - OpenAPI_nf_type_e nf_type; - ogs_list_t pcf_ue_list; ogs_hash_t *supi_hash; diff --git a/src/pcf/init.c b/src/pcf/init.c index d2c6918e7..dd6fabc72 100644 --- a/src/pcf/init.c +++ b/src/pcf/init.c @@ -27,9 +27,10 @@ int pcf_initialize() { int rv; + ogs_sbi_context_init(); + pcf_context_init(); pcf_event_init(); - ogs_sbi_context_init(); rv = ogs_sbi_context_parse_config("pcf", "nrf"); if (rv != OGS_OK) return rv; diff --git a/src/pcf/nbsf-build.c b/src/pcf/nbsf-build.c index 499bdf21c..0aab0bbb6 100644 --- a/src/pcf/nbsf-build.c +++ b/src/pcf/nbsf-build.c @@ -63,7 +63,7 @@ ogs_sbi_request_t *pcf_nbsf_management_build_register( ogs_expect_or_return_val(sess->dnn, NULL); PcfBinding.dnn = sess->dnn; - nf_instance = ogs_sbi_nf_instance_find(ogs_sbi_self()->nf_instance_id); + nf_instance = ogs_sbi_self()->nf_instance; ogs_expect_or_return_val(nf_instance, NULL); nf_service = ogs_list_first(&nf_instance->nf_service_list); ogs_expect_or_return_val(nf_service, NULL); diff --git a/src/pcf/nf-sm.c b/src/pcf/nf-sm.c index 0831b2cf5..ba51df645 100644 --- a/src/pcf/nf-sm.c +++ b/src/pcf/nf-sm.c @@ -60,7 +60,6 @@ void pcf_nf_state_initial(ogs_fsm_t *s, pcf_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); - ogs_assert(nf_instance->id); ogs_assert(nf_instance->t_registration_interval); nf_instance->t_registration_interval->cb = @@ -73,9 +72,10 @@ void pcf_nf_state_initial(ogs_fsm_t *s, pcf_event_t *e) ogs_assert(nf_instance->t_validity); nf_instance->t_validity->cb = pcf_timer_nf_instance_validity; - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { + if (NF_INSTANCE_IS_NRF(nf_instance)) { OGS_FSM_TRAN(s, &pcf_nf_state_will_register); } else { + ogs_assert(nf_instance->id); OGS_FSM_TRAN(s, &pcf_nf_state_registered); } } @@ -102,19 +102,19 @@ void pcf_nf_state_will_register(ogs_fsm_t *s, pcf_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); + ogs_assert(NF_INSTANCE_IS_NRF(nf_instance)); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); + ogs_timer_start(nf_instance->t_registration_interval, + ogs_app()->time.message.sbi.nf_register_interval); ogs_assert(true == pcf_nnrf_nfm_send_nf_register(nf_instance)); break; case OGS_FSM_EXIT_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) - ogs_timer_stop(nf_instance->t_registration_interval); + ogs_timer_stop(nf_instance->t_registration_interval); break; case PCF_EVT_SBI_CLIENT: @@ -133,20 +133,23 @@ void pcf_nf_state_will_register(ogs_fsm_t *s, pcf_event_t *e) OGS_FSM_TRAN(s, &pcf_nf_state_registered); } else { ogs_error("[%s] HTTP response error [%d]", - nf_instance->id, message->res_status); + ogs_sbi_self()->nf_instance->id, + message->res_status); OGS_FSM_TRAN(s, &pcf_nf_state_exception); } break; DEFAULT ogs_error("[%s] Invalid resource name [%s]", - nf_instance->id, message->h.resource.component[0]); + ogs_sbi_self()->nf_instance->id, + message->h.resource.component[0]); END break; DEFAULT ogs_error("[%s] Invalid API name [%s]", - nf_instance->id, message->h.service.name); + ogs_sbi_self()->nf_instance->id, + message->h.service.name); END break; @@ -158,17 +161,18 @@ void pcf_nf_state_will_register(ogs_fsm_t *s, pcf_event_t *e) addr = client->node.addr; ogs_assert(addr); - ogs_warn("[%s] Retry to registration with NRF", nf_instance->id); + ogs_warn("[%s] Retry to registration with NRF", + ogs_sbi_self()->nf_instance->id); - if (NF_INSTANCE_IS_SELF(nf_instance->id)) - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); + ogs_timer_start(nf_instance->t_registration_interval, + ogs_app()->time.message.sbi.nf_register_interval); ogs_assert(true == pcf_nnrf_nfm_send_nf_register(nf_instance)); break; default: - ogs_error("[%s] Unknown timer[%s:%d]", nf_instance->id, + ogs_error("[%s] Unknown timer[%s:%d]", + ogs_sbi_self()->nf_instance->id, pcf_timer_get_name(e->timer_id), e->timer_id); } break; @@ -191,12 +195,14 @@ void pcf_nf_state_registered(ogs_fsm_t *s, pcf_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { + if (NF_INSTANCE_IS_NRF(nf_instance)) { ogs_info("[%s] NF registered [Heartbeat:%ds]", - nf_instance->id, nf_instance->time.heartbeat_interval); + ogs_sbi_self()->nf_instance->id, + nf_instance->time.heartbeat_interval); client = nf_instance->client; ogs_assert(client); @@ -212,17 +218,21 @@ void pcf_nf_state_registered(ogs_fsm_t *s, pcf_event_t *e) ogs_assert(true == ogs_nnrf_nfm_send_nf_status_subscribe(client, - pcf_self()->nf_type, nf_instance->id, OpenAPI_nf_type_BSF)); + ogs_sbi_self()->nf_instance->nf_type, + ogs_sbi_self()->nf_instance->id, + OpenAPI_nf_type_BSF)); ogs_assert(true == ogs_nnrf_nfm_send_nf_status_subscribe(client, - pcf_self()->nf_type, nf_instance->id, OpenAPI_nf_type_UDR)); + ogs_sbi_self()->nf_instance->nf_type, + ogs_sbi_self()->nf_instance->id, + OpenAPI_nf_type_UDR)); } break; case OGS_FSM_EXIT_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { - ogs_info("[%s] NF de-registered", nf_instance->id); + if (NF_INSTANCE_IS_NRF(nf_instance)) { + ogs_info("[%s] NF de-registered", ogs_sbi_self()->nf_instance->id); if (nf_instance->time.heartbeat_interval) { ogs_timer_stop(nf_instance->t_heartbeat_interval); @@ -256,7 +266,8 @@ void pcf_nf_state_registered(ogs_fsm_t *s, pcf_event_t *e) no_heartbeat_margin)); } else { ogs_warn("[%s] HTTP response error [%d]", - nf_instance->id, message->res_status); + ogs_sbi_self()->nf_instance->id, + message->res_status); OGS_FSM_TRAN(s, &pcf_nf_state_exception); } @@ -264,13 +275,14 @@ void pcf_nf_state_registered(ogs_fsm_t *s, pcf_event_t *e) DEFAULT ogs_error("[%s] Invalid resource name [%s]", - nf_instance->id, message->h.resource.component[0]); + ogs_sbi_self()->nf_instance->id, + message->h.resource.component[0]); END break; DEFAULT ogs_error("[%s] Invalid API name [%s]", - nf_instance->id, message->h.service.name); + ogs_sbi_self()->nf_instance->id, message->h.service.name); END break; @@ -285,27 +297,31 @@ void pcf_nf_state_registered(ogs_fsm_t *s, pcf_event_t *e) break; case PCF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - ogs_error("[%s] No heartbeat", nf_instance->id); + ogs_error("[%s] No heartbeat", ogs_sbi_self()->nf_instance->id); OGS_FSM_TRAN(s, &pcf_nf_state_will_register); break; case PCF_TIMER_NF_INSTANCE_VALIDITY: - if (NF_INSTANCE_IS_OTHERS(nf_instance->id)) { - ogs_info("[%s] NF expired", nf_instance->id); - OGS_FSM_TRAN(s, &pcf_nf_state_de_registered); - } + ogs_assert(!NF_INSTANCE_IS_NRF(nf_instance)); + ogs_assert(nf_instance->id); + + ogs_info("[%s] NF expired", nf_instance->id); + OGS_FSM_TRAN(s, &pcf_nf_state_de_registered); break; default: - ogs_error("[%s] Unknown timer[%s:%d]", nf_instance->id, + ogs_error("[%s:%s] Unknown timer[%s:%d]", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", pcf_timer_get_name(e->timer_id), e->timer_id); - break; } break; default: - ogs_error("[%s] Unknown event %s", - nf_instance->id, pcf_event_get_name(e)); + ogs_error("[%s:%s] Unknown event %s", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", + pcf_event_get_name(e)); break; } } @@ -320,11 +336,12 @@ void pcf_nf_state_de_registered(ogs_fsm_t *s, pcf_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { - ogs_info("[%s] NF de-registered", nf_instance->id); + if (NF_INSTANCE_IS_NRF(nf_instance)) { + ogs_info("[%s] NF de-registered", ogs_sbi_self()->nf_instance->id); } break; @@ -332,8 +349,10 @@ void pcf_nf_state_de_registered(ogs_fsm_t *s, pcf_event_t *e) break; default: - ogs_error("[%s] Unknown event %s", - nf_instance->id, pcf_event_get_name(e)); + ogs_error("[%s:%s] Unknown event %s", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", + pcf_event_get_name(e)); break; } } @@ -351,18 +370,21 @@ void pcf_nf_state_exception(ogs_fsm_t *s, pcf_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) + if (NF_INSTANCE_IS_NRF(nf_instance)) { ogs_timer_start(nf_instance->t_registration_interval, ogs_app()->time.message.sbi. nf_register_interval_in_exception); + } break; case OGS_FSM_EXIT_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) + if (NF_INSTANCE_IS_NRF(nf_instance)) { ogs_timer_stop(nf_instance->t_registration_interval); + } break; case PCF_EVT_SBI_TIMER: @@ -373,15 +395,17 @@ void pcf_nf_state_exception(ogs_fsm_t *s, pcf_event_t *e) addr = client->node.addr; ogs_assert(addr); - ogs_warn("[%s] Retry to registration with NRF", nf_instance->id); + ogs_warn("[%s] Retry to registration with NRF", + ogs_sbi_self()->nf_instance->id); OGS_FSM_TRAN(s, &pcf_nf_state_will_register); break; default: - ogs_error("[%s] Unknown timer[%s:%d]", nf_instance->id, + ogs_error("[%s:%s] Unknown timer[%s:%d]", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", pcf_timer_get_name(e->timer_id), e->timer_id); - break; } break; @@ -406,8 +430,10 @@ void pcf_nf_state_exception(ogs_fsm_t *s, pcf_event_t *e) break; default: - ogs_error("[%s] Unknown event %s", - nf_instance->id, pcf_event_get_name(e)); + ogs_error("[%s:%s] Unknown event %s", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", + pcf_event_get_name(e)); break; } } diff --git a/src/pcf/nnrf-build.c b/src/pcf/nnrf-build.c index 2be877fd7..a265cec50 100644 --- a/src/pcf/nnrf-build.c +++ b/src/pcf/nnrf-build.c @@ -19,18 +19,18 @@ #include "nnrf-build.h" -ogs_sbi_request_t *pcf_nnrf_nfm_build_register( - ogs_sbi_nf_instance_t *nf_instance) +ogs_sbi_request_t *pcf_nnrf_nfm_build_register(void) { + ogs_sbi_nf_instance_t *nf_instance = NULL; + ogs_sbi_message_t message; ogs_sbi_request_t *request = NULL; - ogs_sbi_client_t *client = NULL; OpenAPI_nf_profile_t *NFProfile = NULL; + nf_instance = ogs_sbi_self()->nf_instance; ogs_assert(nf_instance); - client = nf_instance->client; - ogs_assert(client); + ogs_assert(nf_instance->id); memset(&message, 0, sizeof(message)); message.h.method = (char *)OGS_SBI_HTTP_METHOD_PUT; @@ -38,11 +38,11 @@ ogs_sbi_request_t *pcf_nnrf_nfm_build_register( message.h.api.version = (char *)OGS_SBI_API_V1; message.h.resource.component[0] = (char *)OGS_SBI_RESOURCE_NAME_NF_INSTANCES; - message.h.resource.component[1] = ogs_sbi_self()->nf_instance_id; + message.h.resource.component[1] = nf_instance->id; message.http.content_encoding = (char*)ogs_sbi_self()->content_encoding; - NFProfile = ogs_nnrf_nfm_build_nf_profile(nf_instance); + NFProfile = ogs_nnrf_nfm_build_nf_profile(); ogs_expect_or_return_val(NFProfile, NULL); message.NFProfile = NFProfile; diff --git a/src/pcf/nnrf-build.h b/src/pcf/nnrf-build.h index 034a872d5..3e13d241e 100644 --- a/src/pcf/nnrf-build.h +++ b/src/pcf/nnrf-build.h @@ -26,8 +26,7 @@ extern "C" { #endif -ogs_sbi_request_t *pcf_nnrf_nfm_build_register( - ogs_sbi_nf_instance_t *nf_instance); +ogs_sbi_request_t *pcf_nnrf_nfm_build_register(void); #ifdef __cplusplus } diff --git a/src/pcf/nnrf-handler.c b/src/pcf/nnrf-handler.c index 19276832e..0c15944e9 100644 --- a/src/pcf/nnrf-handler.c +++ b/src/pcf/nnrf-handler.c @@ -171,9 +171,10 @@ bool pcf_nnrf_handle_nf_status_notify( nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); if (!nf_instance) { - nf_instance = ogs_sbi_nf_instance_add( - message.h.resource.component[1]); + nf_instance = ogs_sbi_nf_instance_add(); ogs_assert(nf_instance); + ogs_sbi_nf_instance_set_id(nf_instance, + message.h.resource.component[1]); pcf_nf_fsm_init(nf_instance); @@ -280,8 +281,9 @@ void pcf_nnrf_handle_nf_discover( nf_instance = ogs_sbi_nf_instance_find(NFProfile->nf_instance_id); if (!nf_instance) { - nf_instance = ogs_sbi_nf_instance_add(NFProfile->nf_instance_id); + nf_instance = ogs_sbi_nf_instance_add(); ogs_assert(nf_instance); + ogs_sbi_nf_instance_set_id(nf_instance, NFProfile->nf_instance_id); pcf_nf_fsm_init(nf_instance); diff --git a/src/pcf/pcf-sm.c b/src/pcf/pcf-sm.c index a815b8f79..30b66d0e4 100644 --- a/src/pcf/pcf-sm.c +++ b/src/pcf/pcf-sm.c @@ -527,7 +527,8 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e) ogs_fsm_dispatch(&nf_instance->sm, e); if (OGS_FSM_CHECK(&nf_instance->sm, pcf_nf_state_exception)) - ogs_error("[%s] State machine exception [%d]", + ogs_error("[%s:%s] State machine exception [%d]", + OpenAPI_nf_type_ToString(nf_instance->nf_type), nf_instance->id, e->timer_id); break; @@ -535,9 +536,11 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e) subscription = e->sbi.data; ogs_assert(subscription); + ogs_assert(ogs_sbi_self()->nf_instance); ogs_assert(true == ogs_nnrf_nfm_send_nf_status_subscribe(subscription->client, - pcf_self()->nf_type, subscription->req_nf_instance_id, + ogs_sbi_self()->nf_instance->nf_type, + subscription->req_nf_instance_id, subscription->subscr_cond.nf_type)); ogs_info("[%s] Subscription validity expired", subscription->id); diff --git a/src/pcf/sbi-path.c b/src/pcf/sbi-path.c index 4abd4b8b8..1b5a42108 100644 --- a/src/pcf/sbi-path.c +++ b/src/pcf/sbi-path.c @@ -68,60 +68,54 @@ static int client_cb(ogs_sbi_response_t *response, void *data) int pcf_sbi_open(void) { ogs_sbi_nf_instance_t *nf_instance = NULL; + ogs_sbi_nf_service_t *service = NULL; if (ogs_sbi_server_start_all(server_cb) != OGS_OK) return OGS_ERROR; - /* - * The connection between NF and NRF is a little special. - * - * NF and NRF share nf_instance. I get the NRF EndPoint(client) information - * the configuration file via lib/sbi/context.c. - * And, the NFService information will be transmitted to NRF. - * - * ogs_sbi_self()->nf_instance_id means NF's InstanceId. - */ + /* Add SELF NF instance */ + nf_instance = ogs_sbi_self()->nf_instance; + ogs_assert(nf_instance); + + /* Build NF instance information. It will be transmitted to NRF. */ + ogs_sbi_nf_instance_build_default(nf_instance, OpenAPI_nf_type_PCF); + ogs_sbi_nf_instance_add_allowed_nf_type(nf_instance, OpenAPI_nf_type_AMF); + ogs_sbi_nf_instance_add_allowed_nf_type(nf_instance, OpenAPI_nf_type_SMF); + ogs_sbi_nf_instance_add_allowed_nf_type(nf_instance, OpenAPI_nf_type_NEF); + ogs_sbi_nf_instance_add_allowed_nf_type(nf_instance, OpenAPI_nf_type_AF); + + /* Build NF service information. It will be transmitted to NRF. */ + service = ogs_sbi_nf_service_build_default(nf_instance, + (char*)OGS_SBI_SERVICE_NAME_NPCF_AM_POLICY_CONTROL); + ogs_assert(service); + ogs_sbi_nf_service_add_version(service, (char*)OGS_SBI_API_V1, + (char*)OGS_SBI_API_V1_0_0, NULL); + ogs_sbi_nf_service_add_allowed_nf_type(service, OpenAPI_nf_type_AMF); + ogs_sbi_nf_service_add_allowed_nf_type(service, OpenAPI_nf_type_NEF); + + service = ogs_sbi_nf_service_build_default(nf_instance, + (char*)OGS_SBI_SERVICE_NAME_NPCF_SMPOLICYCONTROL); + ogs_assert(service); + ogs_sbi_nf_service_add_version(service, (char*)OGS_SBI_API_V1, + (char*)OGS_SBI_API_V1_0_0, NULL); + ogs_sbi_nf_service_add_allowed_nf_type(service, OpenAPI_nf_type_SMF); + ogs_sbi_nf_service_add_allowed_nf_type(service, OpenAPI_nf_type_NEF); + ogs_sbi_nf_service_add_allowed_nf_type(service, OpenAPI_nf_type_AF); + + /* Initialize NRF NF Instance */ ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) { - ogs_sbi_nf_service_t *service = NULL; - ogs_sbi_client_t *client = NULL; + if (NF_INSTANCE_IS_NRF(nf_instance)) { + ogs_sbi_client_t *client = NULL; - /* Build NF instance information. It will be transmitted to NRF. */ - ogs_sbi_nf_instance_build_default(nf_instance, pcf_self()->nf_type); - ogs_sbi_nf_instance_add_allowed_nf_type( - nf_instance, OpenAPI_nf_type_AMF); - ogs_sbi_nf_instance_add_allowed_nf_type( - nf_instance, OpenAPI_nf_type_SMF); - ogs_sbi_nf_instance_add_allowed_nf_type( - nf_instance, OpenAPI_nf_type_NEF); - ogs_sbi_nf_instance_add_allowed_nf_type( - nf_instance, OpenAPI_nf_type_AF); + /* Client callback is only used when NF sends to NRF */ + client = nf_instance->client; + ogs_assert(client); + client->cb = client_cb; - /* Build NF service information. It will be transmitted to NRF. */ - service = ogs_sbi_nf_service_build_default(nf_instance, - (char*)OGS_SBI_SERVICE_NAME_NPCF_AM_POLICY_CONTROL); - ogs_assert(service); - ogs_sbi_nf_service_add_version(service, (char*)OGS_SBI_API_V1, - (char*)OGS_SBI_API_V1_0_0, NULL); - ogs_sbi_nf_service_add_allowed_nf_type(service, OpenAPI_nf_type_AMF); - ogs_sbi_nf_service_add_allowed_nf_type(service, OpenAPI_nf_type_NEF); - - service = ogs_sbi_nf_service_build_default(nf_instance, - (char*)OGS_SBI_SERVICE_NAME_NPCF_SMPOLICYCONTROL); - ogs_assert(service); - ogs_sbi_nf_service_add_version(service, (char*)OGS_SBI_API_V1, - (char*)OGS_SBI_API_V1_0_0, NULL); - ogs_sbi_nf_service_add_allowed_nf_type(service, OpenAPI_nf_type_SMF); - ogs_sbi_nf_service_add_allowed_nf_type(service, OpenAPI_nf_type_NEF); - ogs_sbi_nf_service_add_allowed_nf_type(service, OpenAPI_nf_type_AF); - - /* Client callback is only used when NF sends to NRF */ - client = nf_instance->client; - ogs_assert(client); - client->cb = client_cb; - - /* NFRegister is sent and the response is received - * by the above client callback. */ - pcf_nf_fsm_init(nf_instance); + /* NFRegister is sent and the response is received + * by the above client callback. */ + pcf_nf_fsm_init(nf_instance); + } } return OGS_OK; @@ -141,7 +135,7 @@ bool pcf_nnrf_nfm_send_nf_register(ogs_sbi_nf_instance_t *nf_instance) client = nf_instance->client; ogs_assert(client); - request = pcf_nnrf_nfm_build_register(nf_instance); + request = pcf_nnrf_nfm_build_register(); ogs_expect_or_return_val(request, false); return ogs_sbi_client_send_request( diff --git a/src/smf/context.c b/src/smf/context.c index ed20dcccd..3edd356ac 100644 --- a/src/smf/context.c +++ b/src/smf/context.c @@ -148,15 +148,18 @@ static int smf_context_prepare(void) { self.diam_config->cnf_port = DIAMETER_PORT; self.diam_config->cnf_port_tls = DIAMETER_SECURE_PORT; - self.nf_type = OpenAPI_nf_type_SMF; return OGS_OK; } static int smf_context_validation(void) { + ogs_sbi_nf_instance_t *nf_instance = NULL; ogs_sbi_nf_info_t *nf_info = NULL; + nf_instance = ogs_sbi_self()->nf_instance; + ogs_assert(nf_instance); + if (self.dns[0] == NULL && self.dns6[0] == NULL) { ogs_error("No smf.dns in '%s'", ogs_app()->file); return OGS_ERROR; @@ -170,7 +173,7 @@ static int smf_context_validation(void) return OGS_ERROR; } - ogs_list_for_each(&ogs_sbi_self()->nf_info_list, nf_info) { + ogs_list_for_each(&nf_instance->nf_info_list, nf_info) { int i; ogs_sbi_smf_info_t *smf_info = &nf_info->smf; ogs_assert(smf_info); @@ -479,8 +482,14 @@ int smf_context_parse_config(void) } while (ogs_yaml_iter_type(&p_cscf_iter) == YAML_SEQUENCE_NODE); } else if (!strcmp(smf_key, "info")) { + ogs_sbi_nf_instance_t *nf_instance = NULL; + ogs_yaml_iter_t info_array, info_iter; ogs_yaml_iter_recurse(&smf_iter, &info_array); + + nf_instance = ogs_sbi_self()->nf_instance; + ogs_assert(nf_instance); + do { ogs_sbi_nf_info_t *nf_info = NULL; ogs_sbi_smf_info_t *smf_info = NULL; @@ -501,7 +510,7 @@ int smf_context_parse_config(void) ogs_assert_if_reached(); nf_info = ogs_sbi_nf_info_add( - &ogs_sbi_self()->nf_info_list, + &nf_instance->nf_info_list, OpenAPI_nf_type_SMF); ogs_assert(nf_info); @@ -2471,10 +2480,7 @@ void smf_sess_select_nf(smf_sess_t *sess, OpenAPI_nf_type_e nf_type) ogs_assert(sess); ogs_assert(nf_type); - if (nf_type == OpenAPI_nf_type_NRF) - ogs_sbi_select_nrf(&sess->sbi, smf_nf_state_registered); - else - ogs_sbi_select_first_nf(&sess->sbi, nf_type, smf_nf_state_registered); + ogs_sbi_select_nf(&sess->sbi, nf_type, smf_nf_state_registered); } smf_pf_t *smf_pf_add(smf_bearer_t *bearer) diff --git a/src/smf/context.h b/src/smf/context.h index 62b95c7fc..80563759f 100644 --- a/src/smf/context.h +++ b/src/smf/context.h @@ -69,8 +69,6 @@ typedef struct smf_context_s { const char* diam_conf_path; /* SMF Diameter conf path */ ogs_diam_config_t *diam_config; /* SMF Diameter config */ - OpenAPI_nf_type_e nf_type; - #define MAX_NUM_OF_DNS 2 const char *dns[MAX_NUM_OF_DNS]; const char *dns6[MAX_NUM_OF_DNS]; diff --git a/src/smf/init.c b/src/smf/init.c index 0280f4bb3..329f2b122 100644 --- a/src/smf/init.c +++ b/src/smf/init.c @@ -36,10 +36,10 @@ int smf_initialize() ogs_metrics_context_init(); ogs_gtp_context_init(ogs_app()->pool.nf * OGS_MAX_NUM_OF_GTPU_RESOURCE); ogs_pfcp_context_init(); + ogs_sbi_context_init(); smf_context_init(); smf_event_init(); - ogs_sbi_context_init(); rv = ogs_gtp_xact_init(); if (rv != OGS_OK) return rv; diff --git a/src/smf/nf-sm.c b/src/smf/nf-sm.c index c5a8ec89d..018f05133 100644 --- a/src/smf/nf-sm.c +++ b/src/smf/nf-sm.c @@ -60,7 +60,6 @@ void smf_nf_state_initial(ogs_fsm_t *s, smf_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); - ogs_assert(nf_instance->id); ogs_assert(nf_instance->t_registration_interval); nf_instance->t_registration_interval->cb = @@ -73,9 +72,10 @@ void smf_nf_state_initial(ogs_fsm_t *s, smf_event_t *e) ogs_assert(nf_instance->t_validity); nf_instance->t_validity->cb = smf_timer_nf_instance_validity; - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { + if (NF_INSTANCE_IS_NRF(nf_instance)) { OGS_FSM_TRAN(s, &smf_nf_state_will_register); } else { + ogs_assert(nf_instance->id); OGS_FSM_TRAN(s, &smf_nf_state_registered); } } @@ -102,19 +102,19 @@ void smf_nf_state_will_register(ogs_fsm_t *s, smf_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); + ogs_assert(NF_INSTANCE_IS_NRF(nf_instance)); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); + ogs_timer_start(nf_instance->t_registration_interval, + ogs_app()->time.message.sbi.nf_register_interval); ogs_assert(true == smf_nnrf_nfm_send_nf_register(nf_instance)); break; case OGS_FSM_EXIT_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) - ogs_timer_stop(nf_instance->t_registration_interval); + ogs_timer_stop(nf_instance->t_registration_interval); break; case SMF_EVT_SBI_CLIENT: @@ -133,20 +133,22 @@ void smf_nf_state_will_register(ogs_fsm_t *s, smf_event_t *e) OGS_FSM_TRAN(s, &smf_nf_state_registered); } else { ogs_error("[%s] HTTP Response Status Code [%d]", - nf_instance->id, message->res_status); + ogs_sbi_self()->nf_instance->id, + message->res_status); OGS_FSM_TRAN(s, &smf_nf_state_exception); } break; DEFAULT ogs_error("[%s] Invalid resource name [%s]", - nf_instance->id, message->h.resource.component[0]); + ogs_sbi_self()->nf_instance->id, + message->h.resource.component[0]); END break; DEFAULT ogs_error("[%s] Invalid API name [%s]", - nf_instance->id, message->h.service.name); + ogs_sbi_self()->nf_instance->id, message->h.service.name); END break; @@ -158,24 +160,25 @@ void smf_nf_state_will_register(ogs_fsm_t *s, smf_event_t *e) addr = client->node.addr; ogs_assert(addr); - ogs_warn("[%s] Retry to registration with NRF", nf_instance->id); + ogs_warn("[%s] Retry to registration with NRF", + ogs_sbi_self()->nf_instance->id); - if (NF_INSTANCE_IS_SELF(nf_instance->id)) - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); + ogs_timer_start(nf_instance->t_registration_interval, + ogs_app()->time.message.sbi.nf_register_interval); ogs_assert(true == smf_nnrf_nfm_send_nf_register(nf_instance)); break; default: - ogs_error("[%s] Unknown timer[%s:%d]", nf_instance->id, + ogs_error("[%s] Unknown timer[%s:%d]", + ogs_sbi_self()->nf_instance->id, smf_timer_get_name(e->timer_id), e->timer_id); } break; default: ogs_error("[%s] Unknown event %s", - nf_instance->id, smf_event_get_name(e)); + ogs_sbi_self()->nf_instance->id, smf_event_get_name(e)); break; } } @@ -192,12 +195,14 @@ void smf_nf_state_registered(ogs_fsm_t *s, smf_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { + if (NF_INSTANCE_IS_NRF(nf_instance)) { ogs_info("[%s] NF registered [Heartbeat:%ds]", - nf_instance->id, nf_instance->time.heartbeat_interval); + ogs_sbi_self()->nf_instance->id, + nf_instance->time.heartbeat_interval); client = nf_instance->client; ogs_assert(client); @@ -213,23 +218,30 @@ void smf_nf_state_registered(ogs_fsm_t *s, smf_event_t *e) ogs_assert(true == ogs_nnrf_nfm_send_nf_status_subscribe(client, - smf_self()->nf_type, nf_instance->id, OpenAPI_nf_type_AMF)); + ogs_sbi_self()->nf_instance->nf_type, + ogs_sbi_self()->nf_instance->id, + OpenAPI_nf_type_AMF)); ogs_assert(true == ogs_nnrf_nfm_send_nf_status_subscribe(client, - smf_self()->nf_type, nf_instance->id, OpenAPI_nf_type_UDM)); + ogs_sbi_self()->nf_instance->nf_type, + ogs_sbi_self()->nf_instance->id, + OpenAPI_nf_type_UDM)); ogs_assert(true == ogs_nnrf_nfm_send_nf_status_subscribe(client, - smf_self()->nf_type, nf_instance->id, OpenAPI_nf_type_PCF)); + ogs_sbi_self()->nf_instance->nf_type, + ogs_sbi_self()->nf_instance->id, + OpenAPI_nf_type_PCF)); ogs_assert(true == ogs_nnrf_nfm_send_nf_status_subscribe(client, - smf_self()->nf_type, nf_instance->id, OpenAPI_nf_type_UPF)); + ogs_sbi_self()->nf_instance->nf_type, + ogs_sbi_self()->nf_instance->id, + OpenAPI_nf_type_UPF)); } - break; case OGS_FSM_EXIT_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { - ogs_info("[%s] NF de-registered", nf_instance->id); + if (NF_INSTANCE_IS_NRF(nf_instance)) { + ogs_info("[%s] NF de-registered", ogs_sbi_self()->nf_instance->id); if (nf_instance->time.heartbeat_interval) { ogs_timer_stop(nf_instance->t_heartbeat_interval); @@ -263,7 +275,8 @@ void smf_nf_state_registered(ogs_fsm_t *s, smf_event_t *e) no_heartbeat_margin)); } else { ogs_warn("[%s] HTTP response error [%d]", - nf_instance->id, message->res_status); + ogs_sbi_self()->nf_instance->id, + message->res_status); OGS_FSM_TRAN(s, &smf_nf_state_exception); } @@ -271,13 +284,14 @@ void smf_nf_state_registered(ogs_fsm_t *s, smf_event_t *e) DEFAULT ogs_error("[%s] Invalid resource name [%s]", - nf_instance->id, message->h.resource.component[0]); + ogs_sbi_self()->nf_instance->id, + message->h.resource.component[0]); END break; DEFAULT ogs_error("[%s] Invalid API name [%s]", - nf_instance->id, message->h.service.name); + ogs_sbi_self()->nf_instance->id, message->h.service.name); END break; @@ -292,27 +306,31 @@ void smf_nf_state_registered(ogs_fsm_t *s, smf_event_t *e) break; case SMF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - ogs_error("[%s] No heartbeat", nf_instance->id); + ogs_error("[%s] No heartbeat", ogs_sbi_self()->nf_instance->id); OGS_FSM_TRAN(s, &smf_nf_state_will_register); break; case SMF_TIMER_NF_INSTANCE_VALIDITY: - if (NF_INSTANCE_IS_OTHERS(nf_instance->id)) { - ogs_info("[%s] NF expired", nf_instance->id); - OGS_FSM_TRAN(s, &smf_nf_state_de_registered); - } + ogs_assert(!NF_INSTANCE_IS_NRF(nf_instance)); + ogs_assert(nf_instance->id); + + ogs_info("[%s] NF expired", nf_instance->id); + OGS_FSM_TRAN(s, &smf_nf_state_de_registered); break; default: - ogs_error("[%s] Unknown timer[%s:%d]", nf_instance->id, + ogs_error("[%s:%s] Unknown timer[%s:%d]", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", smf_timer_get_name(e->timer_id), e->timer_id); - break; } break; default: - ogs_error("[%s] Unknown event %s", - nf_instance->id, smf_event_get_name(e)); + ogs_error("[%s:%s] Unknown event %s", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", + smf_event_get_name(e)); break; } } @@ -327,11 +345,12 @@ void smf_nf_state_de_registered(ogs_fsm_t *s, smf_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { - ogs_info("[%s] NF de-registered", nf_instance->id); + if (NF_INSTANCE_IS_NRF(nf_instance)) { + ogs_info("[%s] NF de-registered", ogs_sbi_self()->nf_instance->id); } break; @@ -339,8 +358,10 @@ void smf_nf_state_de_registered(ogs_fsm_t *s, smf_event_t *e) break; default: - ogs_error("[%s] Unknown event %s", - nf_instance->id, smf_event_get_name(e)); + ogs_error("[%s:%s] Unknown event %s", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", + smf_event_get_name(e)); break; } } @@ -358,18 +379,21 @@ void smf_nf_state_exception(ogs_fsm_t *s, smf_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) + if (NF_INSTANCE_IS_NRF(nf_instance)) { ogs_timer_start(nf_instance->t_registration_interval, ogs_app()->time.message.sbi. nf_register_interval_in_exception); + } break; case OGS_FSM_EXIT_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) + if (NF_INSTANCE_IS_NRF(nf_instance)) { ogs_timer_stop(nf_instance->t_registration_interval); + } break; case SMF_EVT_SBI_TIMER: @@ -380,15 +404,17 @@ void smf_nf_state_exception(ogs_fsm_t *s, smf_event_t *e) addr = client->node.addr; ogs_assert(addr); - ogs_warn("[%s] Retry to registration with NRF", nf_instance->id); + ogs_warn("[%s] Retry to registration with NRF", + ogs_sbi_self()->nf_instance->id); OGS_FSM_TRAN(s, &smf_nf_state_will_register); break; default: - ogs_error("[%s] Unknown timer[%s:%d]", nf_instance->id, + ogs_error("[%s:%s] Unknown timer[%s:%d]", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", smf_timer_get_name(e->timer_id), e->timer_id); - break; } break; @@ -413,8 +439,10 @@ void smf_nf_state_exception(ogs_fsm_t *s, smf_event_t *e) break; default: - ogs_error("[%s] Unknown event %s", - nf_instance->id, smf_event_get_name(e)); + ogs_error("[%s:%s] Unknown event %s", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", + smf_event_get_name(e)); break; } } diff --git a/src/smf/nnrf-build.c b/src/smf/nnrf-build.c index 07bf52f34..68b769f85 100644 --- a/src/smf/nnrf-build.c +++ b/src/smf/nnrf-build.c @@ -19,15 +19,14 @@ #include "nnrf-build.h" -ogs_sbi_request_t *smf_nnrf_nfm_build_register( - ogs_sbi_nf_instance_t *nf_instance) +ogs_sbi_request_t *smf_nnrf_nfm_build_register(void) { int i, j; + ogs_sbi_nf_instance_t *nf_instance = NULL; ogs_sbi_nf_info_t *nf_info = NULL; ogs_sbi_message_t message; ogs_sbi_request_t *request = NULL; - ogs_sbi_client_t *client = NULL; OpenAPI_nf_profile_t *NFProfile = NULL; @@ -51,9 +50,9 @@ ogs_sbi_request_t *smf_nnrf_nfm_build_register( OpenAPI_lnode_t *node = NULL, *node2 = NULL, *node3 = NULL; + nf_instance = ogs_sbi_self()->nf_instance; ogs_assert(nf_instance); - client = nf_instance->client; - ogs_assert(client); + ogs_assert(nf_instance->id); memset(&message, 0, sizeof(message)); message.h.method = (char *)OGS_SBI_HTTP_METHOD_PUT; @@ -61,7 +60,7 @@ ogs_sbi_request_t *smf_nnrf_nfm_build_register( message.h.api.version = (char *)OGS_SBI_API_V1; message.h.resource.component[0] = (char *)OGS_SBI_RESOURCE_NAME_NF_INSTANCES; - message.h.resource.component[1] = ogs_sbi_self()->nf_instance_id; + message.h.resource.component[1] = nf_instance->id; message.http.content_encoding = (char*)ogs_sbi_self()->content_encoding; @@ -69,7 +68,8 @@ ogs_sbi_request_t *smf_nnrf_nfm_build_register( ogs_assert(SmfInfoList); SmfInfoMapKey = 0; - ogs_list_for_each(&ogs_sbi_self()->nf_info_list, nf_info) { + + ogs_list_for_each(&nf_instance->nf_info_list, nf_info) { if (nf_info->nf_type != OpenAPI_nf_type_SMF) { ogs_fatal("Not implemented NF-type[%s]", OpenAPI_nf_type_ToString(nf_info->nf_type)); @@ -199,7 +199,7 @@ ogs_sbi_request_t *smf_nnrf_nfm_build_register( OpenAPI_list_add(SmfInfoList, SmfInfoMap); } - NFProfile = ogs_nnrf_nfm_build_nf_profile(nf_instance); + NFProfile = ogs_nnrf_nfm_build_nf_profile(); ogs_expect_or_return_val(NFProfile, NULL); if (SmfInfoList->count == 1) { diff --git a/src/smf/nnrf-build.h b/src/smf/nnrf-build.h index 97bac7fbc..5c12726cf 100644 --- a/src/smf/nnrf-build.h +++ b/src/smf/nnrf-build.h @@ -26,8 +26,7 @@ extern "C" { #endif -ogs_sbi_request_t *smf_nnrf_nfm_build_register( - ogs_sbi_nf_instance_t *nf_instance); +ogs_sbi_request_t *smf_nnrf_nfm_build_register(void); #ifdef __cplusplus } diff --git a/src/smf/nnrf-handler.c b/src/smf/nnrf-handler.c index dab4316a0..46c111a1c 100644 --- a/src/smf/nnrf-handler.c +++ b/src/smf/nnrf-handler.c @@ -171,9 +171,10 @@ bool smf_nnrf_handle_nf_status_notify( nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); if (!nf_instance) { - nf_instance = ogs_sbi_nf_instance_add( - message.h.resource.component[1]); + nf_instance = ogs_sbi_nf_instance_add(); ogs_assert(nf_instance); + ogs_sbi_nf_instance_set_id(nf_instance, + message.h.resource.component[1]); smf_nf_fsm_init(nf_instance); @@ -278,8 +279,9 @@ void smf_nnrf_handle_nf_discover( nf_instance = ogs_sbi_nf_instance_find(NFProfile->nf_instance_id); if (!nf_instance) { - nf_instance = ogs_sbi_nf_instance_add(NFProfile->nf_instance_id); + nf_instance = ogs_sbi_nf_instance_add(); ogs_assert(nf_instance); + ogs_sbi_nf_instance_set_id(nf_instance, NFProfile->nf_instance_id); smf_nf_fsm_init(nf_instance); diff --git a/src/smf/sbi-path.c b/src/smf/sbi-path.c index 4b40acd1e..476075c08 100644 --- a/src/smf/sbi-path.c +++ b/src/smf/sbi-path.c @@ -70,44 +70,41 @@ static int client_cb(ogs_sbi_response_t *response, void *data) int smf_sbi_open(void) { ogs_sbi_nf_instance_t *nf_instance = NULL; + ogs_sbi_nf_service_t *service = NULL; if (ogs_sbi_server_start_all(server_cb) != OGS_OK) return OGS_ERROR; - /* - * The connection between NF and NRF is a little special. - * - * NF and NRF share nf_instance. I get the NRF EndPoint(client) information - * the configuration file via lib/sbi/context.c. - * And, the NFService information will be transmitted to NRF. - * - * ogs_sbi_self()->nf_instance_id means NF's InstanceId. - */ + /* Add SELF NF instance */ + nf_instance = ogs_sbi_self()->nf_instance; + ogs_assert(nf_instance); + + /* Build NF instance information. It will be transmitted to NRF. */ + ogs_sbi_nf_instance_build_default(nf_instance, OpenAPI_nf_type_SMF); + ogs_sbi_nf_instance_add_allowed_nf_type(nf_instance, OpenAPI_nf_type_AMF); + + /* Build NF service information. It will be transmitted to NRF. */ + service = ogs_sbi_nf_service_build_default(nf_instance, + (char*)OGS_SBI_SERVICE_NAME_NSMF_PDUSESSION); + ogs_assert(service); + ogs_sbi_nf_service_add_version(service, (char*)OGS_SBI_API_V1, + (char*)OGS_SBI_API_V1_0_0, NULL); + ogs_sbi_nf_service_add_allowed_nf_type(service, OpenAPI_nf_type_AMF); + + /* Initialize NRF NF Instance */ ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) { - ogs_sbi_nf_service_t *service = NULL; - ogs_sbi_client_t *client = NULL; + if (NF_INSTANCE_IS_NRF(nf_instance)) { + ogs_sbi_client_t *client = NULL; - /* Build NF instance information. It will be transmitted to NRF. */ - ogs_sbi_nf_instance_build_default(nf_instance, smf_self()->nf_type); - ogs_sbi_nf_instance_add_allowed_nf_type( - nf_instance, OpenAPI_nf_type_AMF); + /* Client callback is only used when NF sends to NRF */ + client = nf_instance->client; + ogs_assert(client); + client->cb = client_cb; - /* Build NF service information. It will be transmitted to NRF. */ - service = ogs_sbi_nf_service_build_default(nf_instance, - (char*)OGS_SBI_SERVICE_NAME_NSMF_PDUSESSION); - ogs_assert(service); - ogs_sbi_nf_service_add_version(service, (char*)OGS_SBI_API_V1, - (char*)OGS_SBI_API_V1_0_0, NULL); - ogs_sbi_nf_service_add_allowed_nf_type(service, OpenAPI_nf_type_AMF); - - /* Client callback is only used when NF sends to NRF */ - client = nf_instance->client; - ogs_assert(client); - client->cb = client_cb; - - /* NFRegister is sent and the response is received - * by the above client callback. */ - smf_nf_fsm_init(nf_instance); + /* NFRegister is sent and the response is received + * by the above client callback. */ + smf_nf_fsm_init(nf_instance); + } } return OGS_OK; @@ -127,7 +124,7 @@ bool smf_nnrf_nfm_send_nf_register(ogs_sbi_nf_instance_t *nf_instance) client = nf_instance->client; ogs_assert(client); - request = smf_nnrf_nfm_build_register(nf_instance); + request = smf_nnrf_nfm_build_register(); ogs_expect_or_return_val(request, false); return ogs_sbi_client_send_request( client, client->cb, request, nf_instance); diff --git a/src/smf/smf-sm.c b/src/smf/smf-sm.c index ee644b778..a7d0e5232 100644 --- a/src/smf/smf-sm.c +++ b/src/smf/smf-sm.c @@ -776,16 +776,20 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) ogs_fsm_dispatch(&nf_instance->sm, e); if (OGS_FSM_CHECK(&nf_instance->sm, smf_nf_state_exception)) - ogs_error("State machine exception [%d]", e->timer_id); + ogs_error("[%s:%s] State machine exception [%d]", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id, e->timer_id); break; case SMF_TIMER_SUBSCRIPTION_VALIDITY: subscription = e->sbi.data; ogs_assert(subscription); + ogs_assert(ogs_sbi_self()->nf_instance); ogs_assert(true == ogs_nnrf_nfm_send_nf_status_subscribe(subscription->client, - smf_self()->nf_type, subscription->req_nf_instance_id, + ogs_sbi_self()->nf_instance->nf_type, + subscription->req_nf_instance_id, subscription->subscr_cond.nf_type)); ogs_info("Subscription validity expired [%s]", subscription->id); diff --git a/src/udm/context.c b/src/udm/context.c index ca2825545..f3a22fa59 100644 --- a/src/udm/context.c +++ b/src/udm/context.c @@ -70,8 +70,6 @@ udm_context_t *udm_self(void) static int udm_context_prepare(void) { - self.nf_type = OpenAPI_nf_type_UDM; - return OGS_OK; } @@ -237,8 +235,5 @@ void udm_ue_select_nf(udm_ue_t *udm_ue, OpenAPI_nf_type_e nf_type) ogs_assert(udm_ue); ogs_assert(nf_type); - if (nf_type == OpenAPI_nf_type_NRF) - ogs_sbi_select_nrf(&udm_ue->sbi, udm_nf_state_registered); - else - ogs_sbi_select_first_nf(&udm_ue->sbi, nf_type, udm_nf_state_registered); + ogs_sbi_select_nf(&udm_ue->sbi, nf_type, udm_nf_state_registered); } diff --git a/src/udm/context.h b/src/udm/context.h index 16ed47ec3..b5d898834 100644 --- a/src/udm/context.h +++ b/src/udm/context.h @@ -39,8 +39,6 @@ extern int __udm_log_domain; #define OGS_LOG_DOMAIN __udm_log_domain typedef struct udm_context_s { - OpenAPI_nf_type_e nf_type; - ogs_list_t udm_ue_list; ogs_hash_t *suci_hash; ogs_hash_t *supi_hash; diff --git a/src/udm/init.c b/src/udm/init.c index 7d6e54e06..f64f08538 100644 --- a/src/udm/init.c +++ b/src/udm/init.c @@ -27,9 +27,10 @@ int udm_initialize() { int rv; + ogs_sbi_context_init(); + udm_context_init(); udm_event_init(); - ogs_sbi_context_init(); rv = ogs_sbi_context_parse_config("udm", "nrf"); if (rv != OGS_OK) return rv; diff --git a/src/udm/nf-sm.c b/src/udm/nf-sm.c index 48f9016e1..9aff494b4 100644 --- a/src/udm/nf-sm.c +++ b/src/udm/nf-sm.c @@ -60,7 +60,6 @@ void udm_nf_state_initial(ogs_fsm_t *s, udm_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); - ogs_assert(nf_instance->id); ogs_assert(nf_instance->t_registration_interval); nf_instance->t_registration_interval->cb = @@ -73,9 +72,10 @@ void udm_nf_state_initial(ogs_fsm_t *s, udm_event_t *e) ogs_assert(nf_instance->t_validity); nf_instance->t_validity->cb = udm_timer_nf_instance_validity; - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { + if (NF_INSTANCE_IS_NRF(nf_instance)) { OGS_FSM_TRAN(s, &udm_nf_state_will_register); } else { + ogs_assert(nf_instance->id); OGS_FSM_TRAN(s, &udm_nf_state_registered); } } @@ -102,19 +102,19 @@ void udm_nf_state_will_register(ogs_fsm_t *s, udm_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); + ogs_assert(NF_INSTANCE_IS_NRF(nf_instance)); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); + ogs_timer_start(nf_instance->t_registration_interval, + ogs_app()->time.message.sbi.nf_register_interval); ogs_assert(true == udm_nnrf_nfm_send_nf_register(nf_instance)); break; case OGS_FSM_EXIT_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) - ogs_timer_stop(nf_instance->t_registration_interval); + ogs_timer_stop(nf_instance->t_registration_interval); break; case UDM_EVT_SBI_CLIENT: @@ -133,20 +133,22 @@ void udm_nf_state_will_register(ogs_fsm_t *s, udm_event_t *e) OGS_FSM_TRAN(s, &udm_nf_state_registered); } else { ogs_error("[%s] HTTP response error [%d]", - nf_instance->id, message->res_status); + ogs_sbi_self()->nf_instance->id, + message->res_status); OGS_FSM_TRAN(s, &udm_nf_state_exception); } break; DEFAULT ogs_error("[%s] Invalid resource name [%s]", - nf_instance->id, message->h.resource.component[0]); + ogs_sbi_self()->nf_instance->id, + message->h.resource.component[0]); END break; DEFAULT ogs_error("[%s] Invalid API name [%s]", - nf_instance->id, message->h.service.name); + ogs_sbi_self()->nf_instance->id, message->h.service.name); END break; @@ -158,17 +160,18 @@ void udm_nf_state_will_register(ogs_fsm_t *s, udm_event_t *e) addr = client->node.addr; ogs_assert(addr); - ogs_warn("[%s] Retry to registration with NRF", nf_instance->id); + ogs_warn("[%s] Retry to registration with NRF", + ogs_sbi_self()->nf_instance->id); - if (NF_INSTANCE_IS_SELF(nf_instance->id)) - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); + ogs_timer_start(nf_instance->t_registration_interval, + ogs_app()->time.message.sbi.nf_register_interval); ogs_assert(true == udm_nnrf_nfm_send_nf_register(nf_instance)); break; default: - ogs_error("[%s] Unknown timer[%s:%d]", nf_instance->id, + ogs_error("[%s] Unknown timer[%s:%d]", + ogs_sbi_self()->nf_instance->id, udm_timer_get_name(e->timer_id), e->timer_id); } break; @@ -191,12 +194,14 @@ void udm_nf_state_registered(ogs_fsm_t *s, udm_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { + if (NF_INSTANCE_IS_NRF(nf_instance)) { ogs_info("[%s] NF registered [Heartbeat:%ds]", - nf_instance->id, nf_instance->time.heartbeat_interval); + ogs_sbi_self()->nf_instance->id, + nf_instance->time.heartbeat_interval); client = nf_instance->client; ogs_assert(client); @@ -212,14 +217,16 @@ void udm_nf_state_registered(ogs_fsm_t *s, udm_event_t *e) ogs_assert(true == ogs_nnrf_nfm_send_nf_status_subscribe(client, - udm_self()->nf_type, nf_instance->id, OpenAPI_nf_type_UDR)); + ogs_sbi_self()->nf_instance->nf_type, + ogs_sbi_self()->nf_instance->id, + OpenAPI_nf_type_UDR)); } break; case OGS_FSM_EXIT_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { - ogs_info("[%s] NF de-registered", nf_instance->id); + if (NF_INSTANCE_IS_NRF(nf_instance)) { + ogs_info("[%s] NF de-registered", ogs_sbi_self()->nf_instance->id); if (nf_instance->time.heartbeat_interval) { ogs_timer_stop(nf_instance->t_heartbeat_interval); @@ -253,7 +260,8 @@ void udm_nf_state_registered(ogs_fsm_t *s, udm_event_t *e) no_heartbeat_margin)); } else { ogs_warn("[%s] HTTP response error [%d]", - nf_instance->id, message->res_status); + ogs_sbi_self()->nf_instance->id, + message->res_status); OGS_FSM_TRAN(s, &udm_nf_state_exception); } @@ -261,13 +269,14 @@ void udm_nf_state_registered(ogs_fsm_t *s, udm_event_t *e) DEFAULT ogs_error("[%s] Invalid resource name [%s]", - nf_instance->id, message->h.resource.component[0]); + ogs_sbi_self()->nf_instance->id, + message->h.resource.component[0]); END break; DEFAULT ogs_error("[%s] Invalid API name [%s]", - nf_instance->id, message->h.service.name); + ogs_sbi_self()->nf_instance->id, message->h.service.name); END break; @@ -282,27 +291,31 @@ void udm_nf_state_registered(ogs_fsm_t *s, udm_event_t *e) break; case UDM_TIMER_NF_INSTANCE_NO_HEARTBEAT: - ogs_error("[%s] No heartbeat", nf_instance->id); + ogs_error("[%s] No heartbeat", ogs_sbi_self()->nf_instance->id); OGS_FSM_TRAN(s, &udm_nf_state_will_register); break; case UDM_TIMER_NF_INSTANCE_VALIDITY: - if (NF_INSTANCE_IS_OTHERS(nf_instance->id)) { - ogs_info("[%s] NF expired", nf_instance->id); - OGS_FSM_TRAN(s, &udm_nf_state_de_registered); - } + ogs_assert(!NF_INSTANCE_IS_NRF(nf_instance)); + ogs_assert(nf_instance->id); + + ogs_info("[%s] NF expired", nf_instance->id); + OGS_FSM_TRAN(s, &udm_nf_state_de_registered); break; default: - ogs_error("[%s] Unknown timer[%s:%d]", nf_instance->id, + ogs_error("[%s:%s] Unknown timer[%s:%d]", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", udm_timer_get_name(e->timer_id), e->timer_id); - break; } break; default: - ogs_error("[%s] Unknown event %s", - nf_instance->id, udm_event_get_name(e)); + ogs_error("[%s:%s] Unknown event %s", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", + udm_event_get_name(e)); break; } } @@ -317,11 +330,12 @@ void udm_nf_state_de_registered(ogs_fsm_t *s, udm_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { - ogs_info("[%s] NF de-registered", nf_instance->id); + if (NF_INSTANCE_IS_NRF(nf_instance)) { + ogs_info("[%s] NF de-registered", ogs_sbi_self()->nf_instance->id); } break; @@ -329,8 +343,10 @@ void udm_nf_state_de_registered(ogs_fsm_t *s, udm_event_t *e) break; default: - ogs_error("[%s] Unknown event %s", - nf_instance->id, udm_event_get_name(e)); + ogs_error("[%s:%s] Unknown event %s", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", + udm_event_get_name(e)); break; } } @@ -348,18 +364,21 @@ void udm_nf_state_exception(ogs_fsm_t *s, udm_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) + if (NF_INSTANCE_IS_NRF(nf_instance)) { ogs_timer_start(nf_instance->t_registration_interval, ogs_app()->time.message.sbi. nf_register_interval_in_exception); + } break; case OGS_FSM_EXIT_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) + if (NF_INSTANCE_IS_NRF(nf_instance)) { ogs_timer_stop(nf_instance->t_registration_interval); + } break; case UDM_EVT_SBI_TIMER: @@ -370,15 +389,17 @@ void udm_nf_state_exception(ogs_fsm_t *s, udm_event_t *e) addr = client->node.addr; ogs_assert(addr); - ogs_warn("[%s] Retry to registration with NRF", nf_instance->id); + ogs_warn("[%s] Retry to registration with NRF", + ogs_sbi_self()->nf_instance->id); OGS_FSM_TRAN(s, &udm_nf_state_will_register); break; default: - ogs_error("[%s] Unknown timer[%s:%d]", nf_instance->id, + ogs_error("[%s:%s] Unknown timer[%s:%d]", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", udm_timer_get_name(e->timer_id), e->timer_id); - break; } break; @@ -403,8 +424,10 @@ void udm_nf_state_exception(ogs_fsm_t *s, udm_event_t *e) break; default: - ogs_error("[%s] Unknown event %s", - nf_instance->id, udm_event_get_name(e)); + ogs_error("[%s:%s] Unknown event %s", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", + udm_event_get_name(e)); break; } } diff --git a/src/udm/nnrf-build.c b/src/udm/nnrf-build.c index 0ccd9d84e..751805b83 100644 --- a/src/udm/nnrf-build.c +++ b/src/udm/nnrf-build.c @@ -19,18 +19,18 @@ #include "nnrf-build.h" -ogs_sbi_request_t *udm_nnrf_nfm_build_register( - ogs_sbi_nf_instance_t *nf_instance) +ogs_sbi_request_t *udm_nnrf_nfm_build_register(void) { + ogs_sbi_nf_instance_t *nf_instance = NULL; + ogs_sbi_message_t message; ogs_sbi_request_t *request = NULL; - ogs_sbi_client_t *client = NULL; OpenAPI_nf_profile_t *NFProfile = NULL; + nf_instance = ogs_sbi_self()->nf_instance; ogs_assert(nf_instance); - client = nf_instance->client; - ogs_assert(client); + ogs_assert(nf_instance->id); memset(&message, 0, sizeof(message)); message.h.method = (char *)OGS_SBI_HTTP_METHOD_PUT; @@ -38,11 +38,11 @@ ogs_sbi_request_t *udm_nnrf_nfm_build_register( message.h.api.version = (char *)OGS_SBI_API_V1; message.h.resource.component[0] = (char *)OGS_SBI_RESOURCE_NAME_NF_INSTANCES; - message.h.resource.component[1] = ogs_sbi_self()->nf_instance_id; + message.h.resource.component[1] = nf_instance->id; message.http.content_encoding = (char*)ogs_sbi_self()->content_encoding; - NFProfile = ogs_nnrf_nfm_build_nf_profile(nf_instance); + NFProfile = ogs_nnrf_nfm_build_nf_profile(); ogs_expect_or_return_val(NFProfile, NULL); message.NFProfile = NFProfile; diff --git a/src/udm/nnrf-build.h b/src/udm/nnrf-build.h index 95dedd152..fd1f30a67 100644 --- a/src/udm/nnrf-build.h +++ b/src/udm/nnrf-build.h @@ -26,8 +26,7 @@ extern "C" { #endif -ogs_sbi_request_t *udm_nnrf_nfm_build_register( - ogs_sbi_nf_instance_t *nf_instance); +ogs_sbi_request_t *udm_nnrf_nfm_build_register(void); #ifdef __cplusplus } diff --git a/src/udm/nnrf-handler.c b/src/udm/nnrf-handler.c index 55de06ac6..de16a12fe 100644 --- a/src/udm/nnrf-handler.c +++ b/src/udm/nnrf-handler.c @@ -171,9 +171,10 @@ bool udm_nnrf_handle_nf_status_notify( nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); if (!nf_instance) { - nf_instance = ogs_sbi_nf_instance_add( - message.h.resource.component[1]); + nf_instance = ogs_sbi_nf_instance_add(); ogs_assert(nf_instance); + ogs_sbi_nf_instance_set_id(nf_instance, + message.h.resource.component[1]); udm_nf_fsm_init(nf_instance); @@ -278,8 +279,9 @@ void udm_nnrf_handle_nf_discover( nf_instance = ogs_sbi_nf_instance_find(NFProfile->nf_instance_id); if (!nf_instance) { - nf_instance = ogs_sbi_nf_instance_add(NFProfile->nf_instance_id); + nf_instance = ogs_sbi_nf_instance_add(); ogs_assert(nf_instance); + ogs_sbi_nf_instance_set_id(nf_instance, NFProfile->nf_instance_id); udm_nf_fsm_init(nf_instance); diff --git a/src/udm/sbi-path.c b/src/udm/sbi-path.c index 047217fad..b12f054f2 100644 --- a/src/udm/sbi-path.c +++ b/src/udm/sbi-path.c @@ -68,61 +68,56 @@ static int client_cb(ogs_sbi_response_t *response, void *data) int udm_sbi_open(void) { ogs_sbi_nf_instance_t *nf_instance = NULL; + ogs_sbi_nf_service_t *service = NULL; if (ogs_sbi_server_start_all(server_cb) != OGS_OK) return OGS_ERROR; - /* - * The connection between NF and NRF is a little special. - * - * NF and NRF share nf_instance. I get the NRF EndPoint(client) information - * the configuration file via lib/sbi/context.c. - * And, the NFService information will be transmitted to NRF. - * - * ogs_sbi_self()->nf_instance_id means NF's InstanceId. - */ + /* Add SELF NF instance */ + nf_instance = ogs_sbi_self()->nf_instance; + ogs_assert(nf_instance); + + /* Build NF instance information. It will be transmitted to NRF. */ + ogs_sbi_nf_instance_build_default(nf_instance, OpenAPI_nf_type_UDM); + ogs_sbi_nf_instance_add_allowed_nf_type(nf_instance, OpenAPI_nf_type_AMF); + ogs_sbi_nf_instance_add_allowed_nf_type(nf_instance, OpenAPI_nf_type_SMF); + ogs_sbi_nf_instance_add_allowed_nf_type(nf_instance, OpenAPI_nf_type_AUSF); + + /* Build NF service information. It will be transmitted to NRF. */ + service = ogs_sbi_nf_service_build_default(nf_instance, + (char*)OGS_SBI_SERVICE_NAME_NUDM_UEAU); + ogs_assert(service); + ogs_sbi_nf_service_add_version(service, (char*)OGS_SBI_API_V1, + (char*)OGS_SBI_API_V1_0_0, NULL); + ogs_sbi_nf_service_add_allowed_nf_type(service, OpenAPI_nf_type_AUSF); + service = ogs_sbi_nf_service_build_default(nf_instance, + (char*)OGS_SBI_SERVICE_NAME_NUDM_UECM); + ogs_assert(service); + ogs_sbi_nf_service_add_version(service, (char*)OGS_SBI_API_V1, + (char*)OGS_SBI_API_V1_0_0, NULL); + ogs_sbi_nf_service_add_allowed_nf_type(service, OpenAPI_nf_type_AMF); + service = ogs_sbi_nf_service_build_default(nf_instance, + (char*)OGS_SBI_SERVICE_NAME_NUDM_SDM); + ogs_assert(service); + ogs_sbi_nf_service_add_version(service, (char*)OGS_SBI_API_V2, + (char*)OGS_SBI_API_V2_0_0, NULL); + ogs_sbi_nf_service_add_allowed_nf_type(service, OpenAPI_nf_type_AMF); + ogs_sbi_nf_service_add_allowed_nf_type(service, OpenAPI_nf_type_SMF); + + /* Initialize NRF NF Instance */ ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) { - ogs_sbi_nf_service_t *service = NULL; - ogs_sbi_client_t *client = NULL; + if (NF_INSTANCE_IS_NRF(nf_instance)) { + ogs_sbi_client_t *client = NULL; - /* Build NF instance information. It will be transmitted to NRF. */ - ogs_sbi_nf_instance_build_default(nf_instance, udm_self()->nf_type); - ogs_sbi_nf_instance_add_allowed_nf_type( - nf_instance, OpenAPI_nf_type_AMF); - ogs_sbi_nf_instance_add_allowed_nf_type( - nf_instance, OpenAPI_nf_type_SMF); - ogs_sbi_nf_instance_add_allowed_nf_type( - nf_instance, OpenAPI_nf_type_AUSF); + /* Client callback is only used when NF sends to NRF */ + client = nf_instance->client; + ogs_assert(client); + client->cb = client_cb; - /* Build NF service information. It will be transmitted to NRF. */ - service = ogs_sbi_nf_service_build_default(nf_instance, - (char*)OGS_SBI_SERVICE_NAME_NUDM_UEAU); - ogs_assert(service); - ogs_sbi_nf_service_add_version(service, (char*)OGS_SBI_API_V1, - (char*)OGS_SBI_API_V1_0_0, NULL); - ogs_sbi_nf_service_add_allowed_nf_type(service, OpenAPI_nf_type_AUSF); - service = ogs_sbi_nf_service_build_default(nf_instance, - (char*)OGS_SBI_SERVICE_NAME_NUDM_UECM); - ogs_assert(service); - ogs_sbi_nf_service_add_version(service, (char*)OGS_SBI_API_V1, - (char*)OGS_SBI_API_V1_0_0, NULL); - ogs_sbi_nf_service_add_allowed_nf_type(service, OpenAPI_nf_type_AMF); - service = ogs_sbi_nf_service_build_default(nf_instance, - (char*)OGS_SBI_SERVICE_NAME_NUDM_SDM); - ogs_assert(service); - ogs_sbi_nf_service_add_version(service, (char*)OGS_SBI_API_V2, - (char*)OGS_SBI_API_V2_0_0, NULL); - ogs_sbi_nf_service_add_allowed_nf_type(service, OpenAPI_nf_type_AMF); - ogs_sbi_nf_service_add_allowed_nf_type(service, OpenAPI_nf_type_SMF); - - /* Client callback is only used when NF sends to NRF */ - client = nf_instance->client; - ogs_assert(client); - client->cb = client_cb; - - /* NFRegister is sent and the response is received - * by the above client callback. */ - udm_nf_fsm_init(nf_instance); + /* NFRegister is sent and the response is received + * by the above client callback. */ + udm_nf_fsm_init(nf_instance); + } } return OGS_OK; @@ -142,7 +137,7 @@ bool udm_nnrf_nfm_send_nf_register(ogs_sbi_nf_instance_t *nf_instance) client = nf_instance->client; ogs_assert(client); - request = udm_nnrf_nfm_build_register(nf_instance); + request = udm_nnrf_nfm_build_register(); ogs_expect_or_return_val(request, false); return ogs_sbi_client_send_request( client, client->cb, request, nf_instance); diff --git a/src/udm/udm-sm.c b/src/udm/udm-sm.c index ea7c0762f..4f6fd5327 100644 --- a/src/udm/udm-sm.c +++ b/src/udm/udm-sm.c @@ -364,7 +364,8 @@ void udm_state_operational(ogs_fsm_t *s, udm_event_t *e) ogs_fsm_dispatch(&nf_instance->sm, e); if (OGS_FSM_CHECK(&nf_instance->sm, udm_nf_state_exception)) - ogs_error("[%s] State machine exception [%d]", + ogs_error("[%s:%s] State machine exception [%d]", + OpenAPI_nf_type_ToString(nf_instance->nf_type), nf_instance->id, e->timer_id); break; @@ -372,9 +373,11 @@ void udm_state_operational(ogs_fsm_t *s, udm_event_t *e) subscription = e->sbi.data; ogs_assert(subscription); + ogs_assert(ogs_sbi_self()->nf_instance); ogs_assert(true == ogs_nnrf_nfm_send_nf_status_subscribe(subscription->client, - udm_self()->nf_type, subscription->req_nf_instance_id, + ogs_sbi_self()->nf_instance->nf_type, + subscription->req_nf_instance_id, subscription->subscr_cond.nf_type)); ogs_info("[%s] Subscription validity expired", subscription->id); diff --git a/src/udr/context.c b/src/udr/context.c index 98b2501d3..f571c7c1f 100644 --- a/src/udr/context.c +++ b/src/udr/context.c @@ -52,8 +52,6 @@ udr_context_t *udr_self(void) static int udr_context_prepare(void) { - self.nf_type = OpenAPI_nf_type_UDR; - return OGS_OK; } diff --git a/src/udr/context.h b/src/udr/context.h index 4bd5bc86a..e682dca90 100644 --- a/src/udr/context.h +++ b/src/udr/context.h @@ -39,8 +39,6 @@ extern int __udr_log_domain; #define OGS_LOG_DOMAIN __udr_log_domain typedef struct udr_context_s { - OpenAPI_nf_type_e nf_type; - } udr_context_t; #define UDR_NF_INSTANCE_CLEAR(_cAUSE, _nFInstance) \ diff --git a/src/udr/init.c b/src/udr/init.c index 0cb72a266..d61b237ba 100644 --- a/src/udr/init.c +++ b/src/udr/init.c @@ -27,9 +27,10 @@ int udr_initialize() { int rv; + ogs_sbi_context_init(); + udr_context_init(); udr_event_init(); - ogs_sbi_context_init(); rv = ogs_sbi_context_parse_config("udr", "nrf"); if (rv != OGS_OK) return rv; diff --git a/src/udr/nf-sm.c b/src/udr/nf-sm.c index ea63ab522..15a96a613 100644 --- a/src/udr/nf-sm.c +++ b/src/udr/nf-sm.c @@ -60,7 +60,6 @@ void udr_nf_state_initial(ogs_fsm_t *s, udr_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); - ogs_assert(nf_instance->id); ogs_assert(nf_instance->t_registration_interval); nf_instance->t_registration_interval->cb = @@ -73,9 +72,10 @@ void udr_nf_state_initial(ogs_fsm_t *s, udr_event_t *e) ogs_assert(nf_instance->t_validity); nf_instance->t_validity->cb = udr_timer_nf_instance_validity; - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { + if (NF_INSTANCE_IS_NRF(nf_instance)) { OGS_FSM_TRAN(s, &udr_nf_state_will_register); } else { + ogs_assert(nf_instance->id); OGS_FSM_TRAN(s, &udr_nf_state_registered); } } @@ -102,19 +102,19 @@ void udr_nf_state_will_register(ogs_fsm_t *s, udr_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); + ogs_assert(NF_INSTANCE_IS_NRF(nf_instance)); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); + ogs_timer_start(nf_instance->t_registration_interval, + ogs_app()->time.message.sbi.nf_register_interval); ogs_assert(true == udr_nnrf_nfm_send_nf_register(nf_instance)); break; case OGS_FSM_EXIT_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) - ogs_timer_stop(nf_instance->t_registration_interval); + ogs_timer_stop(nf_instance->t_registration_interval); break; case UDR_EVT_SBI_CLIENT: @@ -133,20 +133,22 @@ void udr_nf_state_will_register(ogs_fsm_t *s, udr_event_t *e) OGS_FSM_TRAN(s, &udr_nf_state_registered); } else { ogs_error("[%s] HTTP response error [%d]", - nf_instance->id, message->res_status); + ogs_sbi_self()->nf_instance->id, + message->res_status); OGS_FSM_TRAN(s, &udr_nf_state_exception); } break; DEFAULT ogs_error("[%s] Invalid resource name [%s]", - nf_instance->id, message->h.resource.component[0]); + ogs_sbi_self()->nf_instance->id, + message->h.resource.component[0]); END break; DEFAULT ogs_error("[%s] Invalid API name [%s]", - nf_instance->id, message->h.service.name); + ogs_sbi_self()->nf_instance->id, message->h.service.name); END break; @@ -158,17 +160,18 @@ void udr_nf_state_will_register(ogs_fsm_t *s, udr_event_t *e) addr = client->node.addr; ogs_assert(addr); - ogs_warn("[%s] Retry to registration with NRF", nf_instance->id); + ogs_warn("[%s] Retry to registration with NRF", + ogs_sbi_self()->nf_instance->id); - if (NF_INSTANCE_IS_SELF(nf_instance->id)) - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); + ogs_timer_start(nf_instance->t_registration_interval, + ogs_app()->time.message.sbi.nf_register_interval); ogs_assert(true == udr_nnrf_nfm_send_nf_register(nf_instance)); break; default: - ogs_error("[%s] Unknown timer[%s:%d]", nf_instance->id, + ogs_error("[%s] Unknown timer[%s:%d]", + ogs_sbi_self()->nf_instance->id, udr_timer_get_name(e->timer_id), e->timer_id); } break; @@ -191,12 +194,14 @@ void udr_nf_state_registered(ogs_fsm_t *s, udr_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { + if (NF_INSTANCE_IS_NRF(nf_instance)) { ogs_info("[%s] NF registered [Heartbeat:%ds]", - nf_instance->id, nf_instance->time.heartbeat_interval); + ogs_sbi_self()->nf_instance->id, + nf_instance->time.heartbeat_interval); client = nf_instance->client; ogs_assert(client); @@ -214,8 +219,8 @@ void udr_nf_state_registered(ogs_fsm_t *s, udr_event_t *e) break; case OGS_FSM_EXIT_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { - ogs_info("[%s] NF de-registered", nf_instance->id); + if (NF_INSTANCE_IS_NRF(nf_instance)) { + ogs_info("[%s] NF de-registered", ogs_sbi_self()->nf_instance->id); if (nf_instance->time.heartbeat_interval) { ogs_timer_stop(nf_instance->t_heartbeat_interval); @@ -249,7 +254,8 @@ void udr_nf_state_registered(ogs_fsm_t *s, udr_event_t *e) no_heartbeat_margin)); } else { ogs_warn("[%s] HTTP response error [%d]", - nf_instance->id, message->res_status); + ogs_sbi_self()->nf_instance->id, + message->res_status); OGS_FSM_TRAN(s, &udr_nf_state_exception); } @@ -257,13 +263,14 @@ void udr_nf_state_registered(ogs_fsm_t *s, udr_event_t *e) DEFAULT ogs_error("[%s] Invalid resource name [%s]", - nf_instance->id, message->h.resource.component[0]); + ogs_sbi_self()->nf_instance->id, + message->h.resource.component[0]); END break; DEFAULT ogs_error("[%s] Invalid API name [%s]", - nf_instance->id, message->h.service.name); + ogs_sbi_self()->nf_instance->id, message->h.service.name); END break; @@ -278,27 +285,31 @@ void udr_nf_state_registered(ogs_fsm_t *s, udr_event_t *e) break; case UDR_TIMER_NF_INSTANCE_NO_HEARTBEAT: - ogs_error("[%s] No heartbeat", nf_instance->id); + ogs_error("[%s] No heartbeat", ogs_sbi_self()->nf_instance->id); OGS_FSM_TRAN(s, &udr_nf_state_will_register); break; case UDR_TIMER_NF_INSTANCE_VALIDITY: - if (NF_INSTANCE_IS_OTHERS(nf_instance->id)) { - ogs_info("[%s] NF expired", nf_instance->id); - OGS_FSM_TRAN(s, &udr_nf_state_de_registered); - } + ogs_assert(!NF_INSTANCE_IS_NRF(nf_instance)); + ogs_assert(nf_instance->id); + + ogs_info("[%s] NF expired", nf_instance->id); + OGS_FSM_TRAN(s, &udr_nf_state_de_registered); break; default: - ogs_error("[%s] Unknown timer[%s:%d]", nf_instance->id, + ogs_error("[%s:%s] Unknown timer[%s:%d]", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", udr_timer_get_name(e->timer_id), e->timer_id); - break; } break; default: - ogs_error("[%s] Unknown event %s", - nf_instance->id, udr_event_get_name(e)); + ogs_error("[%s:%s] Unknown event %s", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", + udr_event_get_name(e)); break; } } @@ -313,11 +324,12 @@ void udr_nf_state_de_registered(ogs_fsm_t *s, udr_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { - ogs_info("[%s] NF de-registered", nf_instance->id); + if (NF_INSTANCE_IS_NRF(nf_instance)) { + ogs_info("[%s] NF de-registered", ogs_sbi_self()->nf_instance->id); } break; @@ -325,8 +337,10 @@ void udr_nf_state_de_registered(ogs_fsm_t *s, udr_event_t *e) break; default: - ogs_error("[%s] Unknown event %s", - nf_instance->id, udr_event_get_name(e)); + ogs_error("[%s:%s] Unknown event %s", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", + udr_event_get_name(e)); break; } } @@ -344,18 +358,21 @@ void udr_nf_state_exception(ogs_fsm_t *s, udr_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) + if (NF_INSTANCE_IS_NRF(nf_instance)) { ogs_timer_start(nf_instance->t_registration_interval, ogs_app()->time.message.sbi. nf_register_interval_in_exception); + } break; case OGS_FSM_EXIT_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) + if (NF_INSTANCE_IS_NRF(nf_instance)) { ogs_timer_stop(nf_instance->t_registration_interval); + } break; case UDR_EVT_SBI_TIMER: @@ -366,15 +383,17 @@ void udr_nf_state_exception(ogs_fsm_t *s, udr_event_t *e) addr = client->node.addr; ogs_assert(addr); - ogs_warn("[%s] Retry to registration with NRF", nf_instance->id); + ogs_warn("[%s] Retry to registration with NRF", + ogs_sbi_self()->nf_instance->id); OGS_FSM_TRAN(s, &udr_nf_state_will_register); break; default: - ogs_error("[%s] Unknown timer[%s:%d]", nf_instance->id, + ogs_error("[%s:%s] Unknown timer[%s:%d]", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", udr_timer_get_name(e->timer_id), e->timer_id); - break; } break; @@ -399,8 +418,10 @@ void udr_nf_state_exception(ogs_fsm_t *s, udr_event_t *e) break; default: - ogs_error("[%s] Unknown event %s", - nf_instance->id, udr_event_get_name(e)); + ogs_error("[%s:%s] Unknown event %s", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", + udr_event_get_name(e)); break; } } diff --git a/src/udr/nnrf-build.c b/src/udr/nnrf-build.c index c02bbb0b9..b6c047934 100644 --- a/src/udr/nnrf-build.c +++ b/src/udr/nnrf-build.c @@ -19,18 +19,18 @@ #include "nnrf-build.h" -ogs_sbi_request_t *udr_nnrf_nfm_build_register( - ogs_sbi_nf_instance_t *nf_instance) +ogs_sbi_request_t *udr_nnrf_nfm_build_register(void) { + ogs_sbi_nf_instance_t *nf_instance = NULL; + ogs_sbi_message_t message; ogs_sbi_request_t *request = NULL; - ogs_sbi_client_t *client = NULL; OpenAPI_nf_profile_t *NFProfile = NULL; + nf_instance = ogs_sbi_self()->nf_instance; ogs_assert(nf_instance); - client = nf_instance->client; - ogs_assert(client); + ogs_assert(nf_instance->id); memset(&message, 0, sizeof(message)); message.h.method = (char *)OGS_SBI_HTTP_METHOD_PUT; @@ -38,11 +38,11 @@ ogs_sbi_request_t *udr_nnrf_nfm_build_register( message.h.api.version = (char *)OGS_SBI_API_V1; message.h.resource.component[0] = (char *)OGS_SBI_RESOURCE_NAME_NF_INSTANCES; - message.h.resource.component[1] = ogs_sbi_self()->nf_instance_id; + message.h.resource.component[1] = nf_instance->id; message.http.content_encoding = (char*)ogs_sbi_self()->content_encoding; - NFProfile = ogs_nnrf_nfm_build_nf_profile(nf_instance); + NFProfile = ogs_nnrf_nfm_build_nf_profile(); ogs_expect_or_return_val(NFProfile, NULL); message.NFProfile = NFProfile; diff --git a/src/udr/nnrf-build.h b/src/udr/nnrf-build.h index e8a053c47..95922a685 100644 --- a/src/udr/nnrf-build.h +++ b/src/udr/nnrf-build.h @@ -26,8 +26,7 @@ extern "C" { #endif -ogs_sbi_request_t *udr_nnrf_nfm_build_register( - ogs_sbi_nf_instance_t *nf_instance); +ogs_sbi_request_t *udr_nnrf_nfm_build_register(void); #ifdef __cplusplus } diff --git a/src/udr/nnrf-handler.c b/src/udr/nnrf-handler.c index 801e08ead..80398b57b 100644 --- a/src/udr/nnrf-handler.c +++ b/src/udr/nnrf-handler.c @@ -171,9 +171,10 @@ bool udr_nnrf_handle_nf_status_notify( nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); if (!nf_instance) { - nf_instance = ogs_sbi_nf_instance_add( - message.h.resource.component[1]); + nf_instance = ogs_sbi_nf_instance_add(); ogs_assert(nf_instance); + ogs_sbi_nf_instance_set_id(nf_instance, + message.h.resource.component[1]); udr_nf_fsm_init(nf_instance); diff --git a/src/udr/sbi-path.c b/src/udr/sbi-path.c index fb23cf64c..9b559ac6a 100644 --- a/src/udr/sbi-path.c +++ b/src/udr/sbi-path.c @@ -68,47 +68,43 @@ static int client_cb(ogs_sbi_response_t *response, void *data) int udr_sbi_open(void) { ogs_sbi_nf_instance_t *nf_instance = NULL; + ogs_sbi_nf_service_t *service = NULL; if (ogs_sbi_server_start_all(server_cb) != OGS_OK) return OGS_ERROR; - /* - * The connection between NF and NRF is a little special. - * - * NF and NRF share nf_instance. I get the NRF EndPoint(client) information - * the configuration file via lib/sbi/context.c. - * And, the NFService information will be transmitted to NRF. - * - * ogs_sbi_self()->nf_instance_id means NF's InstanceId. - */ + /* Add SELF NF instance */ + nf_instance = ogs_sbi_self()->nf_instance; + ogs_assert(nf_instance); + + /* Build NF instance information. It will be transmitted to NRF. */ + ogs_sbi_nf_instance_build_default(nf_instance, OpenAPI_nf_type_UDR); + ogs_sbi_nf_instance_add_allowed_nf_type(nf_instance, OpenAPI_nf_type_PCF); + ogs_sbi_nf_instance_add_allowed_nf_type(nf_instance, OpenAPI_nf_type_UDM); + + /* Build NF service information. It will be transmitted to NRF. */ + service = ogs_sbi_nf_service_build_default(nf_instance, + (char*)OGS_SBI_SERVICE_NAME_NUDR_DR); + ogs_assert(service); + ogs_sbi_nf_service_add_version(service, (char*)OGS_SBI_API_V1, + (char*)OGS_SBI_API_V1_0_0, NULL); + ogs_sbi_nf_service_add_allowed_nf_type(service, OpenAPI_nf_type_PCF); + ogs_sbi_nf_service_add_allowed_nf_type(service, OpenAPI_nf_type_UDM); + + /* Initialize NRF NF Instance */ ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) { - ogs_sbi_nf_service_t *service = NULL; - ogs_sbi_client_t *client = NULL; + if (NF_INSTANCE_IS_NRF(nf_instance)) { + ogs_sbi_client_t *client = NULL; - /* Build NF instance information. It will be transmitted to NRF. */ - ogs_sbi_nf_instance_build_default(nf_instance, udr_self()->nf_type); - ogs_sbi_nf_instance_add_allowed_nf_type( - nf_instance, OpenAPI_nf_type_PCF); - ogs_sbi_nf_instance_add_allowed_nf_type( - nf_instance, OpenAPI_nf_type_UDM); + /* Client callback is only used when NF sends to NRF */ + client = nf_instance->client; + ogs_assert(client); + client->cb = client_cb; - /* Build NF service information. It will be transmitted to NRF. */ - service = ogs_sbi_nf_service_build_default(nf_instance, - (char*)OGS_SBI_SERVICE_NAME_NUDR_DR); - ogs_assert(service); - ogs_sbi_nf_service_add_version(service, (char*)OGS_SBI_API_V1, - (char*)OGS_SBI_API_V1_0_0, NULL); - ogs_sbi_nf_service_add_allowed_nf_type(service, OpenAPI_nf_type_PCF); - ogs_sbi_nf_service_add_allowed_nf_type(service, OpenAPI_nf_type_UDM); - - /* Client callback is only used when NF sends to NRF */ - client = nf_instance->client; - ogs_assert(client); - client->cb = client_cb; - - /* NFRegister is sent and the response is received - * by the above client callback. */ - udr_nf_fsm_init(nf_instance); + /* NFRegister is sent and the response is received + * by the above client callback. */ + udr_nf_fsm_init(nf_instance); + } } return OGS_OK; @@ -128,7 +124,7 @@ bool udr_nnrf_nfm_send_nf_register(ogs_sbi_nf_instance_t *nf_instance) client = nf_instance->client; ogs_assert(client); - request = udr_nnrf_nfm_build_register(nf_instance); + request = udr_nnrf_nfm_build_register(); ogs_expect_or_return_val(request, false); return ogs_sbi_client_send_request(client, client->cb, request, nf_instance); } diff --git a/src/udr/udr-sm.c b/src/udr/udr-sm.c index 950ef00ee..8d661cab8 100644 --- a/src/udr/udr-sm.c +++ b/src/udr/udr-sm.c @@ -292,9 +292,11 @@ void udr_state_operational(ogs_fsm_t *s, udr_event_t *e) subscription = e->sbi.data; ogs_assert(subscription); + ogs_assert(ogs_sbi_self()->nf_instance); ogs_assert(true == ogs_nnrf_nfm_send_nf_status_subscribe(subscription->client, - udr_self()->nf_type, subscription->req_nf_instance_id, + ogs_sbi_self()->nf_instance->nf_type, + subscription->req_nf_instance_id, subscription->subscr_cond.nf_type)); ogs_info("[%s] Subscription validity expired", subscription->id); diff --git a/tests/af/af-sm.c b/tests/af/af-sm.c index 7af30e6a3..b36cfd037 100644 --- a/tests/af/af-sm.c +++ b/tests/af/af-sm.c @@ -406,9 +406,11 @@ void af_state_operational(ogs_fsm_t *s, af_event_t *e) subscription = e->sbi.data; ogs_assert(subscription); + ogs_assert(ogs_sbi_self()->nf_instance); ogs_assert(true == ogs_nnrf_nfm_send_nf_status_subscribe(subscription->client, - af_self()->nf_type, subscription->req_nf_instance_id, + ogs_sbi_self()->nf_instance->nf_type, + subscription->req_nf_instance_id, subscription->subscr_cond.nf_type)); ogs_info("Subscription validity expired [%s]", subscription->id); diff --git a/tests/af/context.c b/tests/af/context.c index fac1b7448..b81abb3f6 100644 --- a/tests/af/context.c +++ b/tests/af/context.c @@ -79,8 +79,6 @@ af_context_t *af_self(void) static int af_context_prepare(void) { - self.nf_type = OpenAPI_nf_type_AF; - return OGS_OK; } @@ -269,10 +267,7 @@ void af_sess_select_nf(af_sess_t *sess, OpenAPI_nf_type_e nf_type) ogs_assert(sess); ogs_assert(nf_type); - if (nf_type == OpenAPI_nf_type_NRF) - ogs_sbi_select_nrf(&sess->sbi, af_nf_state_registered); - else - ogs_sbi_select_first_nf(&sess->sbi, nf_type, af_nf_state_registered); + ogs_sbi_select_nf(&sess->sbi, nf_type, af_nf_state_registered); } static ogs_sbi_client_t *find_client_by_fqdn(char *fqdn, int port) diff --git a/tests/af/context.h b/tests/af/context.h index afc85cd98..d20989bd5 100644 --- a/tests/af/context.h +++ b/tests/af/context.h @@ -38,8 +38,6 @@ extern int __af_log_domain; #define OGS_LOG_DOMAIN __af_log_domain typedef struct af_context_s { - OpenAPI_nf_type_e nf_type; - ogs_hash_t *supi_hash; /* hash table (SUPI) */ ogs_hash_t *ipv4_hash; /* hash table (IPv4 Address) */ ogs_hash_t *ipv6_hash; /* hash table (IPv6 Address) */ diff --git a/tests/af/init.c b/tests/af/init.c index 82338821e..aaa64ffcb 100644 --- a/tests/af/init.c +++ b/tests/af/init.c @@ -29,9 +29,10 @@ int af_initialize() { int rv; + ogs_sbi_context_init(); + af_context_init(); af_event_init(); - ogs_sbi_context_init(); rv = ogs_sbi_context_parse_config("af", "nrf"); if (rv != OGS_OK) return rv; diff --git a/tests/af/nf-sm.c b/tests/af/nf-sm.c index bd99d4f7b..5096902f7 100644 --- a/tests/af/nf-sm.c +++ b/tests/af/nf-sm.c @@ -60,7 +60,6 @@ void af_nf_state_initial(ogs_fsm_t *s, af_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); - ogs_assert(nf_instance->id); ogs_assert(nf_instance->t_registration_interval); nf_instance->t_registration_interval->cb = @@ -73,9 +72,10 @@ void af_nf_state_initial(ogs_fsm_t *s, af_event_t *e) ogs_assert(nf_instance->t_validity); nf_instance->t_validity->cb = af_timer_nf_instance_validity; - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { + if (NF_INSTANCE_IS_NRF(nf_instance)) { OGS_FSM_TRAN(s, &af_nf_state_will_register); } else { + ogs_assert(nf_instance->id); OGS_FSM_TRAN(s, &af_nf_state_registered); } } @@ -102,19 +102,19 @@ void af_nf_state_will_register(ogs_fsm_t *s, af_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); + ogs_assert(NF_INSTANCE_IS_NRF(nf_instance)); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); + ogs_timer_start(nf_instance->t_registration_interval, + ogs_app()->time.message.sbi.nf_register_interval); ogs_assert(true == af_nnrf_nfm_send_nf_register(nf_instance)); break; case OGS_FSM_EXIT_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) - ogs_timer_stop(nf_instance->t_registration_interval); + ogs_timer_stop(nf_instance->t_registration_interval); break; case AF_EVT_SBI_CLIENT: @@ -133,20 +133,22 @@ void af_nf_state_will_register(ogs_fsm_t *s, af_event_t *e) OGS_FSM_TRAN(s, &af_nf_state_registered); } else { ogs_error("[%s] HTTP Response Status Code [%d]", - nf_instance->id, message->res_status); + ogs_sbi_self()->nf_instance->id, + message->res_status); OGS_FSM_TRAN(s, &af_nf_state_exception); } break; DEFAULT ogs_error("[%s] Invalid resource name [%s]", - nf_instance->id, message->h.resource.component[0]); + ogs_sbi_self()->nf_instance->id, + message->h.resource.component[0]); END break; DEFAULT ogs_error("[%s] Invalid API name [%s]", - nf_instance->id, message->h.service.name); + ogs_sbi_self()->nf_instance->id, message->h.service.name); END break; @@ -158,24 +160,25 @@ void af_nf_state_will_register(ogs_fsm_t *s, af_event_t *e) addr = client->node.addr; ogs_assert(addr); - ogs_warn("[%s] Retry to registration with NRF", nf_instance->id); + ogs_warn("[%s] Retry to registration with NRF", + ogs_sbi_self()->nf_instance->id); - if (NF_INSTANCE_IS_SELF(nf_instance->id)) - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); + ogs_timer_start(nf_instance->t_registration_interval, + ogs_app()->time.message.sbi.nf_register_interval); ogs_assert(true == af_nnrf_nfm_send_nf_register(nf_instance)); break; default: - ogs_error("[%s] Unknown timer[%s:%d]", nf_instance->id, + ogs_error("[%s] Unknown timer[%s:%d]", + ogs_sbi_self()->nf_instance->id, af_timer_get_name(e->timer_id), e->timer_id); } break; default: ogs_error("[%s] Unknown event %s", - nf_instance->id, af_event_get_name(e)); + ogs_sbi_self()->nf_instance->id, af_event_get_name(e)); break; } } @@ -192,12 +195,14 @@ void af_nf_state_registered(ogs_fsm_t *s, af_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { + if (NF_INSTANCE_IS_NRF(nf_instance)) { ogs_info("[%s] NF registered [Heartbeat:%ds]", - nf_instance->id, nf_instance->time.heartbeat_interval); + ogs_sbi_self()->nf_instance->id, + nf_instance->time.heartbeat_interval); client = nf_instance->client; ogs_assert(client); @@ -213,14 +218,16 @@ void af_nf_state_registered(ogs_fsm_t *s, af_event_t *e) ogs_assert(true == ogs_nnrf_nfm_send_nf_status_subscribe(client, - af_self()->nf_type, nf_instance->id, OpenAPI_nf_type_BSF)); + ogs_sbi_self()->nf_instance->nf_type, + ogs_sbi_self()->nf_instance->id, + OpenAPI_nf_type_BSF)); } break; case OGS_FSM_EXIT_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { - ogs_info("[%s] NF de-registered", nf_instance->id); + if (NF_INSTANCE_IS_NRF(nf_instance)) { + ogs_info("[%s] NF de-registered", ogs_sbi_self()->nf_instance->id); if (nf_instance->time.heartbeat_interval) { ogs_timer_stop(nf_instance->t_heartbeat_interval); @@ -254,7 +261,8 @@ void af_nf_state_registered(ogs_fsm_t *s, af_event_t *e) no_heartbeat_margin)); } else { ogs_warn("[%s] HTTP response error [%d]", - nf_instance->id, message->res_status); + ogs_sbi_self()->nf_instance->id, + message->res_status); OGS_FSM_TRAN(s, &af_nf_state_exception); } @@ -262,13 +270,14 @@ void af_nf_state_registered(ogs_fsm_t *s, af_event_t *e) DEFAULT ogs_error("[%s] Invalid resource name [%s]", - nf_instance->id, message->h.resource.component[0]); + ogs_sbi_self()->nf_instance->id, + message->h.resource.component[0]); END break; DEFAULT ogs_error("[%s] Invalid API name [%s]", - nf_instance->id, message->h.service.name); + ogs_sbi_self()->nf_instance->id, message->h.service.name); END break; @@ -283,27 +292,32 @@ void af_nf_state_registered(ogs_fsm_t *s, af_event_t *e) break; case AF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - ogs_error("[%s] No heartbeat", nf_instance->id); + ogs_error("[%s] No heartbeat", ogs_sbi_self()->nf_instance->id); OGS_FSM_TRAN(s, &af_nf_state_will_register); break; case AF_TIMER_NF_INSTANCE_VALIDITY: - if (NF_INSTANCE_IS_OTHERS(nf_instance->id)) { - ogs_info("[%s] NF expired", nf_instance->id); - OGS_FSM_TRAN(s, &af_nf_state_de_registered); - } + ogs_assert(!NF_INSTANCE_IS_NRF(nf_instance)); + ogs_assert(nf_instance->id); + + ogs_info("[%s] NF expired", nf_instance->id); + OGS_FSM_TRAN(s, &af_nf_state_de_registered); break; default: - ogs_error("[%s] Unknown timer[%s:%d]", nf_instance->id, + ogs_error("[%s:%s] Unknown timer[%s:%d]", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", af_timer_get_name(e->timer_id), e->timer_id); break; } break; default: - ogs_error("[%s] Unknown event %s", - nf_instance->id, af_event_get_name(e)); + ogs_error("[%s:%s] Unknown event %s", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", + af_event_get_name(e)); break; } } @@ -318,11 +332,12 @@ void af_nf_state_de_registered(ogs_fsm_t *s, af_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) { - ogs_info("[%s] NF de-registered", nf_instance->id); + if (NF_INSTANCE_IS_NRF(nf_instance)) { + ogs_info("[%s] NF de-registered", ogs_sbi_self()->nf_instance->id); } break; @@ -330,8 +345,10 @@ void af_nf_state_de_registered(ogs_fsm_t *s, af_event_t *e) break; default: - ogs_error("[%s] Unknown event %s", - nf_instance->id, af_event_get_name(e)); + ogs_error("[%s:%s] Unknown event %s", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", + af_event_get_name(e)); break; } } @@ -349,18 +366,21 @@ void af_nf_state_exception(ogs_fsm_t *s, af_event_t *e) nf_instance = e->sbi.data; ogs_assert(nf_instance); + ogs_assert(ogs_sbi_self()->nf_instance); switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) + if (NF_INSTANCE_IS_NRF(nf_instance)) { ogs_timer_start(nf_instance->t_registration_interval, ogs_app()->time.message.sbi. nf_register_interval_in_exception); + } break; case OGS_FSM_EXIT_SIG: - if (NF_INSTANCE_IS_SELF(nf_instance->id)) + if (NF_INSTANCE_IS_NRF(nf_instance)) { ogs_timer_stop(nf_instance->t_registration_interval); + } break; case AF_EVT_SBI_TIMER: @@ -371,13 +391,16 @@ void af_nf_state_exception(ogs_fsm_t *s, af_event_t *e) addr = client->node.addr; ogs_assert(addr); - ogs_warn("[%s] Retry to registration with NRF", nf_instance->id); + ogs_warn("[%s] Retry to registration with NRF", + ogs_sbi_self()->nf_instance->id); OGS_FSM_TRAN(s, &af_nf_state_will_register); break; default: - ogs_error("[%s] Unknown timer[%s:%d]", nf_instance->id, + ogs_error("[%s:%s] Unknown timer[%s:%d]", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", af_timer_get_name(e->timer_id), e->timer_id); break; } @@ -404,8 +427,10 @@ void af_nf_state_exception(ogs_fsm_t *s, af_event_t *e) break; default: - ogs_error("[%s] Unknown event %s", - nf_instance->id, af_event_get_name(e)); + ogs_error("[%s:%s] Unknown event %s", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id ? nf_instance->id : "Undefined", + af_event_get_name(e)); break; } } diff --git a/tests/af/nnrf-build.c b/tests/af/nnrf-build.c index d0068d583..b4993ba0e 100644 --- a/tests/af/nnrf-build.c +++ b/tests/af/nnrf-build.c @@ -19,18 +19,18 @@ #include "nnrf-build.h" -ogs_sbi_request_t *af_nnrf_nfm_build_register( - ogs_sbi_nf_instance_t *nf_instance) +ogs_sbi_request_t *af_nnrf_nfm_build_register(void) { + ogs_sbi_nf_instance_t *nf_instance = NULL; + ogs_sbi_message_t message; ogs_sbi_request_t *request = NULL; - ogs_sbi_client_t *client = NULL; OpenAPI_nf_profile_t *NFProfile = NULL; + nf_instance = ogs_sbi_self()->nf_instance; ogs_assert(nf_instance); - client = nf_instance->client; - ogs_assert(client); + ogs_assert(nf_instance->id); memset(&message, 0, sizeof(message)); message.h.method = (char *)OGS_SBI_HTTP_METHOD_PUT; @@ -38,11 +38,11 @@ ogs_sbi_request_t *af_nnrf_nfm_build_register( message.h.api.version = (char *)OGS_SBI_API_V1; message.h.resource.component[0] = (char *)OGS_SBI_RESOURCE_NAME_NF_INSTANCES; - message.h.resource.component[1] = ogs_sbi_self()->nf_instance_id; + message.h.resource.component[1] = nf_instance->id; message.http.content_encoding = (char*)ogs_sbi_self()->content_encoding; - NFProfile = ogs_nnrf_nfm_build_nf_profile(nf_instance); + NFProfile = ogs_nnrf_nfm_build_nf_profile(); ogs_expect_or_return_val(NFProfile, NULL); message.NFProfile = NFProfile; diff --git a/tests/af/nnrf-build.h b/tests/af/nnrf-build.h index 1e2814ed5..779c0783a 100644 --- a/tests/af/nnrf-build.h +++ b/tests/af/nnrf-build.h @@ -26,8 +26,7 @@ extern "C" { #endif -ogs_sbi_request_t *af_nnrf_nfm_build_register( - ogs_sbi_nf_instance_t *nf_instance); +ogs_sbi_request_t *af_nnrf_nfm_build_register(void); #ifdef __cplusplus } diff --git a/tests/af/nnrf-handler.c b/tests/af/nnrf-handler.c index 3108736fe..c7c0bbc1d 100644 --- a/tests/af/nnrf-handler.c +++ b/tests/af/nnrf-handler.c @@ -175,9 +175,10 @@ bool af_nnrf_handle_nf_status_notify( nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); if (!nf_instance) { - nf_instance = ogs_sbi_nf_instance_add( - message.h.resource.component[1]); + nf_instance = ogs_sbi_nf_instance_add(); ogs_assert(nf_instance); + ogs_sbi_nf_instance_set_id(nf_instance, + message.h.resource.component[1]); af_nf_fsm_init(nf_instance); @@ -282,8 +283,9 @@ void af_nnrf_handle_nf_discover( nf_instance = ogs_sbi_nf_instance_find(NFProfile->nf_instance_id); if (!nf_instance) { - nf_instance = ogs_sbi_nf_instance_add(NFProfile->nf_instance_id); + nf_instance = ogs_sbi_nf_instance_add(); ogs_assert(nf_instance); + ogs_sbi_nf_instance_set_id(nf_instance, NFProfile->nf_instance_id); af_nf_fsm_init(nf_instance); diff --git a/tests/af/sbi-path.c b/tests/af/sbi-path.c index b87912b28..ec4901833 100644 --- a/tests/af/sbi-path.c +++ b/tests/af/sbi-path.c @@ -68,41 +68,39 @@ static int client_cb(ogs_sbi_response_t *response, void *data) int af_sbi_open(void) { ogs_sbi_nf_instance_t *nf_instance = NULL; + ogs_sbi_nf_service_t *service = NULL; if (ogs_sbi_server_start_all(server_cb) != OGS_OK) return OGS_ERROR; - /* - * The connection between NF and NRF is a little special. - * - * NF and NRF share nf_instance. I get the NRF EndPoint(client) information - * the configuration file via lib/sbi/context.c. - * And, the NFService information will be transmitted to NRF. - * - * ogs_sbi_self()->nf_instance_id means NF's InstanceId. - */ + /* Add SELF NF instance */ + nf_instance = ogs_sbi_self()->nf_instance; + ogs_assert(nf_instance); + + /* Build NF instance information. It will be transmitted to NRF. */ + ogs_sbi_nf_instance_build_default(nf_instance, OpenAPI_nf_type_AF); + + /* Build NF service information. It will be transmitted to NRF. */ + service = ogs_sbi_nf_service_build_default(nf_instance, + (char*)OGS_SBI_SERVICE_NAME_NAF_EVENTEXPOSURE); + ogs_assert(service); + ogs_sbi_nf_service_add_version(service, (char*)OGS_SBI_API_V1, + (char*)OGS_SBI_API_V1_0_0, NULL); + + /* Initialize NRF NF Instance */ ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) { - ogs_sbi_nf_service_t *service = NULL; - ogs_sbi_client_t *client = NULL; + if (NF_INSTANCE_IS_NRF(nf_instance)) { + ogs_sbi_client_t *client = NULL; - /* Build NF instance information. It will be transmitted to NRF. */ - ogs_sbi_nf_instance_build_default(nf_instance, af_self()->nf_type); + /* Client callback is only used when NF sends to NRF */ + client = nf_instance->client; + ogs_assert(client); + client->cb = client_cb; - /* Build NF service information. It will be transmitted to NRF. */ - service = ogs_sbi_nf_service_build_default(nf_instance, - (char*)OGS_SBI_SERVICE_NAME_NAF_EVENTEXPOSURE); - ogs_assert(service); - ogs_sbi_nf_service_add_version(service, (char*)OGS_SBI_API_V1, - (char*)OGS_SBI_API_V1_0_0, NULL); - - /* Client callback is only used when NF sends to NRF */ - client = nf_instance->client; - ogs_assert(client); - client->cb = client_cb; - - /* NFRegister is sent and the response is received - * by the above client callback. */ - af_nf_fsm_init(nf_instance); + /* NFRegister is sent and the response is received + * by the above client callback. */ + af_nf_fsm_init(nf_instance); + } } return OGS_OK; @@ -122,7 +120,7 @@ bool af_nnrf_nfm_send_nf_register(ogs_sbi_nf_instance_t *nf_instance) client = nf_instance->client; ogs_assert(client); - request = af_nnrf_nfm_build_register(nf_instance); + request = af_nnrf_nfm_build_register(); ogs_expect_or_return_val(request, false); return ogs_sbi_client_send_request( client, client->cb, request, nf_instance);