diff --git a/lib/app/meson.build b/lib/app/meson.build index 0a23d713e..6d6e0d4d8 100644 --- a/lib/app/meson.build +++ b/lib/app/meson.build @@ -38,11 +38,11 @@ libapp = library('ogsapp', version : libogslib_version, c_args : '-DOGS_APP_COMPILATION', include_directories : [libapp_inc, libinc], - dependencies : [libcore_dep, yaml_dep], + dependencies : [libproto_dep, yaml_dep], install : true) libapp_dep = declare_dependency( link_with : libapp, include_directories : [libapp_inc, libinc], - dependencies : [libcore_dep, yaml_dep], + dependencies : [libproto_dep, yaml_dep], ) diff --git a/lib/app/ogs-app.h b/lib/app/ogs-app.h index c6b13cf5d..a5f8f6c7b 100644 --- a/lib/app/ogs-app.h +++ b/lib/app/ogs-app.h @@ -20,7 +20,7 @@ #ifndef OGS_APP_H #define OGS_APP_H -#include "ogs-core.h" +#include "ogs-proto.h" #define OGS_APP_INSIDE diff --git a/lib/app/ogs-context.c b/lib/app/ogs-context.c index b2be2b266..c55ce220e 100644 --- a/lib/app/ogs-context.c +++ b/lib/app/ogs-context.c @@ -170,16 +170,6 @@ static void app_context_prepare(void) #define USRSCTP_LOCAL_UDP_PORT 9899 self.usrsctp.udp_port = USRSCTP_LOCAL_UDP_PORT; - self.sctp.heartbit_interval = 5000; /* 5 seconds */ - self.sctp.sack_delay = 200; /* 200 ms */ - self.sctp.rto_initial = 3000; /* 3 seconds */ - self.sctp.rto_min = 1000; /* 1 seconds */ - self.sctp.rto_max = 5000; /* 5 seconds */ - self.sctp.max_num_of_ostreams = OGS_DEFAULT_SCTP_MAX_NUM_OF_OSTREAMS; - self.sctp.max_num_of_istreams = 65535; - self.sctp.max_attempts = 4; - self.sctp.max_initial_timeout = 8000; /* 8 seconds */ - self.sockopt.no_delay = true; #define MAX_NUM_OF_UE 1024 /* Num of UEs */ @@ -379,48 +369,6 @@ int ogs_app_context_parse_config(void) } else ogs_warn("unknown key `%s`", sockopt_key); } - } else if (!strcmp(root_key, "sctp")) { - ogs_yaml_iter_t sctp_iter; - ogs_yaml_iter_recurse(&root_iter, &sctp_iter); - while (ogs_yaml_iter_next(&sctp_iter)) { - const char *sctp_key = ogs_yaml_iter_key(&sctp_iter); - ogs_assert(sctp_key); - if (!strcmp(sctp_key, "heartbit_interval")) { - const char *v = ogs_yaml_iter_value(&sctp_iter); - if (v) self.sctp.heartbit_interval = atoi(v); - } else if (!strcmp(sctp_key, "sack_delay")) { - const char *v = ogs_yaml_iter_value(&sctp_iter); - if (v) self.sctp.sack_delay = atoi(v); - } else if (!strcmp(sctp_key, "rto_initial")) { - const char *v = ogs_yaml_iter_value(&sctp_iter); - if (v) self.sctp.rto_initial = atoi(v); - } else if (!strcmp(sctp_key, "rto_min")) { - const char *v = ogs_yaml_iter_value(&sctp_iter); - if (v) self.sctp.rto_min = atoi(v); - } else if (!strcmp(sctp_key, "rto_max")) { - const char *v = ogs_yaml_iter_value(&sctp_iter); - if (v) self.sctp.rto_max = atoi(v); - } else if (!strcmp(sctp_key, "max_num_of_ostreams")) { - const char *v = ogs_yaml_iter_value(&sctp_iter); - if (v) - self.sctp.max_num_of_ostreams = atoi(v); - } else if (!strcmp(sctp_key, "max_num_of_istreams")) { - const char *v = ogs_yaml_iter_value(&sctp_iter); - if (v) - self.sctp.max_num_of_istreams = atoi(v); - } else if (!strcmp(sctp_key, "max_attempts")) { - const char *v = ogs_yaml_iter_value(&sctp_iter); - if (v) self.sctp.max_attempts = atoi(v); - } else if (!strcmp(sctp_key, "max_initial_timeout")) { - const char *v = ogs_yaml_iter_value(&sctp_iter); - if (v) - self.sctp.max_initial_timeout = atoi(v); - } else if (!strcmp(sctp_key, "usrsctp_udp_port")) { - const char *v = ogs_yaml_iter_value(&sctp_iter); - if (v) self.usrsctp.udp_port = atoi(v); - } else - ogs_warn("unknown key `%s`", sctp_key); - } } else if (!strcmp(root_key, "max")) { ogs_yaml_iter_t max_iter; ogs_yaml_iter_recurse(&root_iter, &max_iter); diff --git a/lib/app/ogs-context.h b/lib/app/ogs-context.h index 2bc8c6c07..2850c88ff 100644 --- a/lib/app/ogs-context.h +++ b/lib/app/ogs-context.h @@ -85,18 +85,6 @@ typedef struct ogs_app_context_s { int l_linger; } sockopt; - struct { - int heartbit_interval; - int sack_delay; - int rto_initial; - int rto_min; - int rto_max; - int max_num_of_ostreams; - int max_num_of_istreams; - int max_attempts; - int max_initial_timeout; - } sctp; - struct { int udp_port; } usrsctp; diff --git a/lib/asn1c/common/asn_internal.h b/lib/asn1c/common/asn_internal.h index 7e04f1669..6c472cdaf 100644 --- a/lib/asn1c/common/asn_internal.h +++ b/lib/asn1c/common/asn_internal.h @@ -40,7 +40,7 @@ int get_asn1c_environment_version(void); /* Run-time version */ #define REALLOC(oldptr, size) realloc(oldptr, size) #define FREEMEM(ptr) free(ptr) #else -#include "ogs-core.h" +#include "ogs-proto.h" static ogs_inline void *ogs_asn_malloc(size_t size, const char *file_line) { diff --git a/lib/asn1c/common/meson.build b/lib/asn1c/common/meson.build index c984ecd6b..285ae7f87 100644 --- a/lib/asn1c/common/meson.build +++ b/lib/asn1c/common/meson.build @@ -171,10 +171,10 @@ libasn1c_common = library('ogsasn1c-common', version : libogslib_version, c_args : libasn1c_common_cc_flags, include_directories : libasn1c_common_inc, - dependencies : libcore_dep, + dependencies : libproto_dep, install : true) libasn1c_common_dep = declare_dependency( link_with : libasn1c_common, include_directories : libasn1c_common_inc, - dependencies : libcore_dep) + dependencies : libproto_dep) diff --git a/lib/core/meson.build b/lib/core/meson.build index ddc0e9dbc..d84b6a5c7 100644 --- a/lib/core/meson.build +++ b/lib/core/meson.build @@ -256,7 +256,6 @@ libcore_sources = files(''' ogs-hash.h ogs-misc.h ogs-getopt.h - ogs-3gpp-types.h abts.h ogs-abort.c @@ -292,7 +291,6 @@ libcore_sources = files(''' ogs-hash.c ogs-misc.c ogs-getopt.c - ogs-3gpp-types.c ogs-core.c abts.c '''.split()) diff --git a/lib/core/ogs-conv.c b/lib/core/ogs-conv.c index 5d1f99a8c..d847b644f 100644 --- a/lib/core/ogs-conv.c +++ b/lib/core/ogs-conv.c @@ -232,25 +232,3 @@ uint64_t ogs_uint64_from_string(char *str) return x; } - -void ogs_extract_digit_from_string(char *digit, char *string) -{ - bool extracting = false; - int i = 0; - - ogs_assert(string); - ogs_assert(digit); - - while (*string && i < OGS_MAX_IMSI_BCD_LEN) { - if (*string >= '0' && *string <= '9') { - *digit++ = *string; - extracting = true; - } else if (extracting == true) { - break; - } - string++; - i++; - } - - *digit = 0; -} diff --git a/lib/core/ogs-conv.h b/lib/core/ogs-conv.h index ca516b92e..68b96d6b7 100644 --- a/lib/core/ogs-conv.h +++ b/lib/core/ogs-conv.h @@ -49,8 +49,6 @@ char *ogs_uint64_to_string(uint64_t x); ogs_uint24_t ogs_uint24_from_string(char *str); uint64_t ogs_uint64_from_string(char *str); -void ogs_extract_digit_from_string(char *digit, char *string); - #ifdef __cplusplus } #endif diff --git a/lib/core/ogs-core.h b/lib/core/ogs-core.h index ca4a523bc..c91cfa716 100644 --- a/lib/core/ogs-core.h +++ b/lib/core/ogs-core.h @@ -62,7 +62,6 @@ #include "core/ogs-hash.h" #include "core/ogs-misc.h" #include "core/ogs-getopt.h" -#include "core/ogs-3gpp-types.h" #undef OGS_CORE_INSIDE diff --git a/lib/core/ogs-fsm.c b/lib/core/ogs-fsm.c index 725aba6ac..0e6990cd5 100644 --- a/lib/core/ogs-fsm.c +++ b/lib/core/ogs-fsm.c @@ -34,69 +34,116 @@ const char *OGS_FSM_NAME_INIT_SIG = "INIT"; const char *OGS_FSM_NAME_ENTRY_SIG = "ENTRY"; const char *OGS_FSM_NAME_EXIT_SIG = "EXIT"; -void ogs_fsm_init(void *sm, void *event) +static void fsm_entry(ogs_fsm_t *sm, ogs_fsm_handler_t state, fsm_event_t *e) { - ogs_fsm_t *s = sm; - fsm_event_t *e = event; - ogs_assert(s); + ogs_assert(sm); + ogs_assert(state); - if (s->init != NULL) { - (*s->init)(s, e); - if (s->init != s->state) { - if (e) { - e->id = OGS_FSM_ENTRY_SIG; - (*s->state)(s, e); - } else { - (*s->state)(s, &entry_event); - } + if (e) { + e->id = OGS_FSM_ENTRY_SIG; + (*state)(sm, e); + } else { + (*state)(sm, &entry_event); + } +} + +static void fsm_exit(ogs_fsm_t *sm, ogs_fsm_handler_t state, fsm_event_t *e) +{ + ogs_assert(sm); + ogs_assert(state); + + if (e) { + e->id = OGS_FSM_EXIT_SIG; + (*state)(sm, e); + } else { + (*state)(sm, &exit_event); + } +} + +static void fsm_change( + ogs_fsm_t *sm, + ogs_fsm_handler_t oldstate, + ogs_fsm_handler_t newstate, + fsm_event_t *e) +{ + ogs_assert(sm); + ogs_assert(oldstate); + ogs_assert(newstate); + + fsm_exit(sm, oldstate, e); + fsm_entry(sm, newstate, e); +} + +void ogs_fsm_init(void *fsm, void *init, void *fini, void *event) +{ + ogs_fsm_t *sm = fsm; + fsm_event_t *e = event; + + ogs_assert(sm); + + sm->init = sm->state = init; + sm->fini = fini; + + if (sm->init) { + (*sm->init)(sm, e); + + if (sm->init != sm->state) { + ogs_assert(sm->state); + fsm_entry(sm, sm->state, e); } } } -void ogs_fsm_dispatch(void *sm, void *event) +void ogs_fsm_tran(void *fsm, void *state, void *event) { - ogs_fsm_t *s = sm; + ogs_fsm_t *sm = fsm; fsm_event_t *e = event; - ogs_assert(s); - ogs_fsm_handler_t tmp = s->state; + ogs_fsm_handler_t tmp = NULL; + + ogs_assert(sm); + + tmp = sm->state; + ogs_assert(tmp); + + sm->state = state; + ogs_assert(sm->state); + + if (sm->state != tmp) + fsm_change(fsm, tmp, sm->state, e); +} + +void ogs_fsm_dispatch(void *fsm, void *event) +{ + ogs_fsm_t *sm = fsm; + fsm_event_t *e = event; + ogs_fsm_handler_t tmp = NULL; + + ogs_assert(sm); + + tmp = sm->state; + ogs_assert(tmp); if (e) - (*tmp)(s, e); + (*tmp)(sm, e); - if (s->state != tmp) { - if (e) { - e->id = OGS_FSM_EXIT_SIG; - (*tmp)(s, e); - } else { - (*tmp)(s, &exit_event); - } - if (e) { - e->id = OGS_FSM_ENTRY_SIG; - (*s->state)(s, e); - } else { - (*s->state)(s, &entry_event); - } - } + if (sm->state != tmp) + fsm_change(fsm, tmp, sm->state, e); } -void ogs_fsm_fini(void *sm, void *event) +void ogs_fsm_fini(void *fsm, void *event) { - ogs_fsm_t *s = sm; + ogs_fsm_t *sm = fsm; fsm_event_t *e = event; - ogs_assert(s); - if (s->fini != s->state) { - if (e) { - e->id = OGS_FSM_EXIT_SIG; - (*s->state)(s, e); - } else { - (*s->state)(s, &exit_event); - } + ogs_assert(sm); + + if (sm->fini != sm->state) { + ogs_assert(sm->state); + fsm_exit(sm, sm->state, e); + + if (sm->fini) + (*sm->fini)(sm, e); } - if (s->fini != NULL) { - (*s->fini)(s, e); - } - - s->state = s->init; + sm->init = sm->state = sm->fini = NULL; } diff --git a/lib/core/ogs-fsm.h b/lib/core/ogs-fsm.h index 1923cc691..4c14b60a2 100644 --- a/lib/core/ogs-fsm.h +++ b/lib/core/ogs-fsm.h @@ -46,16 +46,10 @@ typedef struct _ogs_fsm_t { ogs_fsm_handler_t state; } ogs_fsm_t; -#define ogs_fsm_create(__s, __i, __f) \ - (((__s)->init = (__s)->state = (ogs_fsm_handler_t)(__i)), \ - (__s)->fini = (ogs_fsm_handler_t)(__f)) - -#define ogs_fsm_delete(__s) \ - ((__s)->init = (__s)->state = (__s)->fini = NULL) - -void ogs_fsm_init(void *sm, void *event); -void ogs_fsm_dispatch(void *sm, void *event); -void ogs_fsm_fini(void *sm, void *event); +void ogs_fsm_init(void *fsm, void *init, void *fini, void *event); +void ogs_fsm_tran(void *fsm, void *state, void *event); +void ogs_fsm_dispatch(void *fsm, void *event); +void ogs_fsm_fini(void *fsm, void *event); #define OGS_FSM_TRAN(__s, __target) \ ((ogs_fsm_t *)__s)->state = (ogs_fsm_handler_t)(__target) diff --git a/lib/core/ogs-macros.h b/lib/core/ogs-macros.h index 07e442828..1b3468d71 100644 --- a/lib/core/ogs-macros.h +++ b/lib/core/ogs-macros.h @@ -210,6 +210,14 @@ static ogs_inline ogs_uint24_t ogs_htobe24(ogs_uint24_t x) #define ogs_uint64_to_uint32(x) ((x >= 0xffffffffUL) ? 0xffffffffU : x) +#define OGS_OBJECT_REF(__oBJ) \ + ((__oBJ)->reference_count)++, \ + ogs_debug("[REF] %d", ((__oBJ)->reference_count)) +#define OGS_OBJECT_UNREF(__oBJ) \ + ogs_debug("[UNREF] %d", ((__oBJ)->reference_count)), \ + ((__oBJ)->reference_count)-- +#define OGS_OBJECT_IS_REF(__oBJ) ((__oBJ)->reference_count > 1) + #ifdef __cplusplus } #endif diff --git a/lib/core/ogs-pkbuf.c b/lib/core/ogs-pkbuf.c index e73892c76..4f2ef4054 100644 --- a/lib/core/ogs-pkbuf.c +++ b/lib/core/ogs-pkbuf.c @@ -245,7 +245,7 @@ ogs_pkbuf_t *ogs_pkbuf_alloc_debug( } memset(pkbuf, 0, sizeof(*pkbuf)); - cluster->ref++; + OGS_OBJECT_REF(cluster); pkbuf->cluster = cluster; @@ -283,8 +283,9 @@ void ogs_pkbuf_free(ogs_pkbuf_t *pkbuf) cluster = pkbuf->cluster; ogs_assert(cluster); - cluster->ref--; - if (cluster->ref == 0) + if (OGS_OBJECT_IS_REF(cluster)) + OGS_OBJECT_UNREF(cluster); + else cluster_free(pool, pkbuf->cluster); ogs_pool_free(&pool->pkbuf, pkbuf); @@ -337,7 +338,7 @@ ogs_pkbuf_t *ogs_pkbuf_copy_debug(ogs_pkbuf_t *pkbuf, const char *file_line) ogs_assert(newbuf); memcpy(newbuf, pkbuf, sizeof *pkbuf); - newbuf->cluster->ref++; + OGS_OBJECT_REF(newbuf->cluster); ogs_thread_mutex_unlock(&pool->mutex); #endif diff --git a/lib/core/ogs-pkbuf.h b/lib/core/ogs-pkbuf.h index 1bb1aeb6c..2952b0681 100644 --- a/lib/core/ogs-pkbuf.h +++ b/lib/core/ogs-pkbuf.h @@ -32,7 +32,7 @@ typedef struct ogs_cluster_s { unsigned char *buffer; unsigned int size; - unsigned int ref; + unsigned int reference_count; } ogs_cluster_t; #if OGS_USE_TALLOC diff --git a/lib/core/ogs-sockopt.h b/lib/core/ogs-sockopt.h index 49d767469..a7642f694 100644 --- a/lib/core/ogs-sockopt.h +++ b/lib/core/ogs-sockopt.h @@ -35,6 +35,7 @@ typedef struct ogs_sockopt_s { uint32_t srto_initial; uint32_t srto_min; uint32_t srto_max; +#define OGS_DEFAULT_SCTP_MAX_NUM_OF_OSTREAMS 30 uint16_t sinit_num_ostreams; uint16_t sinit_max_instreams; uint16_t sinit_max_attempts; diff --git a/lib/crypt/meson.build b/lib/crypt/meson.build index 2f35c3a35..e22601e50 100644 --- a/lib/crypt/meson.build +++ b/lib/crypt/meson.build @@ -52,10 +52,10 @@ libcrypt = library('ogscrypt', version : libogslib_version, c_args : '-DOGS_CRYPT_COMPILATION', include_directories : [libcrypt_inc, libinc], - dependencies : libcore_dep, + dependencies : libproto_dep, install : true) libcrypt_dep = declare_dependency( link_with : libcrypt, include_directories : [libcrypt_inc, libinc], - dependencies : libcore_dep) + dependencies : libproto_dep) diff --git a/lib/crypt/ogs-crypt.h b/lib/crypt/ogs-crypt.h index e39e25d4d..a55cf50d9 100644 --- a/lib/crypt/ogs-crypt.h +++ b/lib/crypt/ogs-crypt.h @@ -20,7 +20,7 @@ #ifndef OGS_CRYPT_H #define OGS_CRYPT_H -#include "ogs-core.h" +#include "ogs-proto.h" #define OGS_CRYPT_INSIDE diff --git a/lib/diameter/common/meson.build b/lib/diameter/common/meson.build index 38528db72..3b6b6d93b 100644 --- a/lib/diameter/common/meson.build +++ b/lib/diameter/common/meson.build @@ -51,10 +51,10 @@ libdiameter_common = library('ogsdiameter-common', version : libogslib_version, c_args : libdiameter_common_cc_flags, include_directories : [libdiameter_common_inc, libinc], - dependencies : [libcore_dep, libfdcore_dep], + dependencies : [libproto_dep, libfdcore_dep], install : true) libdiameter_common_dep = declare_dependency( link_with : libdiameter_common, include_directories : [libdiameter_common_inc, libinc], - dependencies : [libcore_dep, libfdcore_dep]) + dependencies : [libproto_dep, libfdcore_dep]) diff --git a/lib/diameter/common/ogs-diameter-common.h b/lib/diameter/common/ogs-diameter-common.h index 04834dca0..4fd7e3b02 100644 --- a/lib/diameter/common/ogs-diameter-common.h +++ b/lib/diameter/common/ogs-diameter-common.h @@ -37,7 +37,7 @@ #pragma GCC diagnostic pop #endif -#include "ogs-core.h" +#include "ogs-proto.h" #define OGS_DIAMETER_INSIDE diff --git a/lib/gtp/xact.c b/lib/gtp/xact.c index 517e0409b..056fd85a9 100644 --- a/lib/gtp/xact.c +++ b/lib/gtp/xact.c @@ -191,7 +191,8 @@ static ogs_gtp_xact_t *ogs_gtp_xact_remote_create(ogs_gtp_node_t *gnode, uint8_t xact->gtp_version = gtp_version; xact->org = OGS_GTP_REMOTE_ORIGINATOR; - xact->xid = (gtp_version == 1) ? OGS_GTP1_SQN_TO_XID(sqn) : OGS_GTP2_SQN_TO_XID(sqn); + xact->xid = (gtp_version == 1) ? + OGS_GTP1_SQN_TO_XID(sqn) : OGS_GTP2_SQN_TO_XID(sqn); xact->gnode = gnode; xact->tm_response = ogs_timer_add( diff --git a/lib/ipfw/meson.build b/lib/ipfw/meson.build index 990972764..95cea39b9 100644 --- a/lib/ipfw/meson.build +++ b/lib/ipfw/meson.build @@ -80,10 +80,10 @@ libipfw = library('ogsipfw', version : libogslib_version, c_args : ['-include', 'glue.h', ipfw_cc_flags], include_directories : libipfw_inc, - dependencies : libcore_dep, + dependencies : libproto_dep, install : true) libipfw_dep = declare_dependency( link_with : libipfw, include_directories : libinc, - dependencies : libcore_dep) + dependencies : libproto_dep) diff --git a/lib/ipfw/ogs-ipfw.h b/lib/ipfw/ogs-ipfw.h index 24df8af5f..ef591f5c1 100644 --- a/lib/ipfw/ogs-ipfw.h +++ b/lib/ipfw/ogs-ipfw.h @@ -24,7 +24,7 @@ extern "C" { #endif -#include "ogs-core.h" +#include "ogs-proto.h" typedef struct ogs_ipfw_rule_s { uint8_t proto; diff --git a/lib/meson.build b/lib/meson.build index 94b3ff0a1..2cdb7594a 100644 --- a/lib/meson.build +++ b/lib/meson.build @@ -18,8 +18,9 @@ libinc = include_directories('.') subdir('core') -subdir('ipfw') +subdir('proto') subdir('crypt') +subdir('ipfw') subdir('app') subdir('metrics') subdir('sctp') diff --git a/src/nssf/nnrf-build.h b/lib/proto/conv.c similarity index 57% rename from src/nssf/nnrf-build.h rename to lib/proto/conv.c index 1304e69aa..62a5afa05 100644 --- a/src/nssf/nnrf-build.h +++ b/lib/proto/conv.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -17,19 +17,26 @@ * along with this program. If not, see . */ -#ifndef NSSF_NNRF_BUILD_H -#define NSSF_NNRF_BUILD_H +#include "ogs-proto.h" -#include "context.h" +void ogs_extract_digit_from_string(char *digit, char *string) +{ + bool extracting = false; + int i = 0; -#ifdef __cplusplus -extern "C" { -#endif + ogs_assert(string); + ogs_assert(digit); -ogs_sbi_request_t *nssf_nnrf_nfm_build_register(void); + while (*string && i < OGS_MAX_IMSI_BCD_LEN) { + if (*string >= '0' && *string <= '9') { + *digit++ = *string; + extracting = true; + } else if (extracting == true) { + break; + } + string++; + i++; + } -#ifdef __cplusplus + *digit = 0; } -#endif - -#endif /* NSSF_NNRF_BUILD_H */ diff --git a/src/ausf/nnrf-build.h b/lib/proto/conv.h similarity index 70% rename from src/ausf/nnrf-build.h rename to lib/proto/conv.h index 79c5bd624..7f7578db5 100644 --- a/src/ausf/nnrf-build.h +++ b/lib/proto/conv.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -17,19 +17,21 @@ * along with this program. If not, see . */ -#ifndef AUSF_NNRF_BUILD_H -#define AUSF_NNRF_BUILD_H +#if !defined(OGS_PROTO_INSIDE) && !defined(OGS_PROTO_COMPILATION) +#error "This header cannot be included directly." +#endif -#include "context.h" +#ifndef OGS_PROTO_CONV_H +#define OGS_PROTO_CONV_H #ifdef __cplusplus extern "C" { #endif -ogs_sbi_request_t *ausf_nnrf_nfm_build_register(void); +void ogs_extract_digit_from_string(char *digit, char *string); #ifdef __cplusplus } #endif -#endif /* AUSF_NNRF_BUILD_H */ +#endif /* OGS_PROTO_CONV_H */ diff --git a/lib/proto/event.c b/lib/proto/event.c new file mode 100644 index 000000000..61694a942 --- /dev/null +++ b/lib/proto/event.c @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2019-2022 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-proto.h" + +const char *OGS_EVENT_NAME_SBI_SERVER = "OGS_EVENT_NAME_SBI_SERVER"; +const char *OGS_EVENT_NAME_SBI_CLIENT = "OGS_EVENT_NAME_SBI_CLIENT"; +const char *OGS_EVENT_NAME_SBI_TIMER = "OGS_EVENT_NAME_SBI_TIMER"; + +void *ogs_event_size(int id, size_t size) +{ + ogs_event_t *e = NULL; + + e = ogs_calloc(1, size); + ogs_assert(e); + + e->id = id; + + return e; +} + +ogs_event_t *ogs_event_new(int id) +{ + return ogs_event_size(id, sizeof(ogs_event_t)); +} + +void ogs_event_free(void *e) +{ + ogs_assert(e); + ogs_free(e); +} + +const char *ogs_event_get_name(ogs_event_t *e) +{ + if (e == NULL) { + return OGS_FSM_NAME_INIT_SIG; + } + + switch (e->id) { + case OGS_FSM_ENTRY_SIG: + return OGS_FSM_NAME_ENTRY_SIG; + case OGS_FSM_EXIT_SIG: + return OGS_FSM_NAME_EXIT_SIG; + + case OGS_EVENT_SBI_SERVER: + return OGS_EVENT_NAME_SBI_SERVER; + case OGS_EVENT_SBI_CLIENT: + return OGS_EVENT_NAME_SBI_CLIENT; + case OGS_EVENT_SBI_TIMER: + return OGS_EVENT_NAME_SBI_TIMER; + + default: + break; + } + + ogs_error("Unknown Event[%d]", e->id); + return "UNKNOWN_EVENT"; +} diff --git a/lib/proto/event.h b/lib/proto/event.h new file mode 100644 index 000000000..21445281f --- /dev/null +++ b/lib/proto/event.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2019-2022 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_PROTO_INSIDE) && !defined(OGS_PROTO_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_PROTO_EVENT_H +#define OGS_PROTO_EVENT_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern const char *OGS_EVENT_NAME_SBI_SERVER; +extern const char *OGS_EVENT_NAME_SBI_CLIENT; +extern const char *OGS_EVENT_NAME_SBI_TIMER; + +typedef enum { + OGS_EVENT_BASE = OGS_FSM_USER_SIG, + + OGS_EVENT_SBI_SERVER, + OGS_EVENT_SBI_CLIENT, + OGS_EVENT_SBI_TIMER, + + OGS_MAX_NUM_OF_PROTO_EVENT, + +} ogs_event_e; + +typedef struct ogs_sbi_request_s ogs_sbi_request_t; +typedef struct ogs_sbi_response_s ogs_sbi_response_t; +typedef struct ogs_sbi_message_s ogs_sbi_message_t; + +typedef struct ogs_event_s { + int id; + int timer_id; + + struct { + ogs_sbi_request_t *request; + ogs_sbi_response_t *response; + void *data; + int state; + + ogs_sbi_message_t *message; + } sbi; +} ogs_event_t; + +void *ogs_event_size(int id, size_t size); +ogs_event_t *ogs_event_new(int id); +void ogs_event_free(void *e); + +const char *ogs_event_get_name(ogs_event_t *e); + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_PROTO_EVENT_H */ diff --git a/lib/proto/meson.build b/lib/proto/meson.build new file mode 100644 index 000000000..533d0aa07 --- /dev/null +++ b/lib/proto/meson.build @@ -0,0 +1,45 @@ +# Copyright (C) 2019-2022 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +libproto_sources = files(''' + ogs-proto.h + + types.h + conv.h + event.h + timer.h + + types.c + conv.c + event.c + timer.c +'''.split()) + +libproto_inc = include_directories('.') + +libproto = library('ogsproto', + sources : libproto_sources, + version : libogslib_version, + c_args : '-DOGS_PROTO_COMPILATION', + include_directories : [libproto_inc, libinc], + dependencies : libcore_dep, + install : true) + +libproto_dep = declare_dependency( + link_with : libproto, + include_directories : [libproto_inc, libinc], + dependencies : libcore_dep) diff --git a/src/scp/nnrf-build.h b/lib/proto/ogs-proto.h similarity index 77% rename from src/scp/nnrf-build.h rename to lib/proto/ogs-proto.h index 9ae01aee2..25bae395e 100644 --- a/src/scp/nnrf-build.h +++ b/lib/proto/ogs-proto.h @@ -17,19 +17,26 @@ * along with this program. If not, see . */ -#ifndef SCP_NNRF_BUILD_H -#define SCP_NNRF_BUILD_H +#ifndef OGS_PROTO_H +#define OGS_PROTO_H -#include "context.h" +#include "ogs-core.h" + +#define OGS_PROTO_INSIDE + +#include "proto/types.h" +#include "proto/conv.h" +#include "proto/event.h" +#include "proto/timer.h" + +#undef OGS_PROTO_INSIDE #ifdef __cplusplus extern "C" { #endif -ogs_sbi_request_t *scp_nnrf_nfm_build_register(void); - #ifdef __cplusplus } #endif -#endif /* SCP_NNRF_BUILD_H */ +#endif /* OGS_PROTO_H */ diff --git a/lib/proto/timer.c b/lib/proto/timer.c new file mode 100644 index 000000000..11cfcd1f4 --- /dev/null +++ b/lib/proto/timer.c @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2019-2022 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-proto.h" + +const char *OGS_TIMER_NAME_NF_INSTANCE_REGISTRATION_INTERVAL = + "OGS_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL"; +const char *OGS_TIMER_NAME_NF_INSTANCE_HEARTBEAT_INTERVAL = + "OGS_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL"; +const char *OGS_TIMER_NAME_NF_INSTANCE_NO_HEARTBEAT = + "OGS_TIMER_NF_INSTANCE_NO_HEARTBEAT"; +const char *OGS_TIMER_NAME_NF_INSTANCE_VALIDITY = + "OGS_TIMER_NF_INSTANCE_VALIDITY"; +const char *OGS_TIMER_NAME_SUBSCRIPTION_VALIDITY = + "OGS_TIMER_SUBSCRIPTION_VALIDITY"; +const char *OGS_TIMER_NAME_SBI_CLIENT_WAIT = + "OGS_TIMER_SBI_CLIENT_WAIT"; + +const char *ogs_timer_get_name(int timer_id) +{ + switch (timer_id) { + case OGS_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: + return OGS_TIMER_NAME_NF_INSTANCE_REGISTRATION_INTERVAL; + case OGS_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: + return OGS_TIMER_NAME_NF_INSTANCE_HEARTBEAT_INTERVAL; + case OGS_TIMER_NF_INSTANCE_NO_HEARTBEAT: + return OGS_TIMER_NAME_NF_INSTANCE_NO_HEARTBEAT; + case OGS_TIMER_NF_INSTANCE_VALIDITY: + return OGS_TIMER_NAME_NF_INSTANCE_VALIDITY; + case OGS_TIMER_SUBSCRIPTION_VALIDITY: + return OGS_TIMER_NAME_SUBSCRIPTION_VALIDITY; + case OGS_TIMER_SBI_CLIENT_WAIT: + return OGS_TIMER_NAME_SBI_CLIENT_WAIT; + default: + break; + } + + ogs_error("Unknown Timer[%d]", timer_id); + return "UNKNOWN_TIMER"; +} diff --git a/lib/proto/timer.h b/lib/proto/timer.h new file mode 100644 index 000000000..b52092207 --- /dev/null +++ b/lib/proto/timer.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2019-2022 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_PROTO_INSIDE) && !defined(OGS_PROTO_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_PROTO_TIMER_H +#define OGS_PROTO_TIMER_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern const char *OGS_TIMER_NAME_NF_INSTANCE_REGISTRATION_INTERVAL; +extern const char *OGS_TIMER_NAME_NF_INSTANCE_HEARTBEAT_INTERVAL; +extern const char *OGS_TIMER_NAME_NF_INSTANCE_NO_HEARTBEAT; +extern const char *OGS_TIMER_NAME_NF_INSTANCE_VALIDITY; +extern const char *OGS_TIMER_NAME_SUBSCRIPTION_VALIDITY; +extern const char *OGS_TIMER_NAME_SBI_CLIENT_WAIT; + +/* forward declaration */ +typedef enum { + OGS_TIMER_BASE = 0, + + OGS_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL, + OGS_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL, + OGS_TIMER_NF_INSTANCE_NO_HEARTBEAT, + OGS_TIMER_NF_INSTANCE_VALIDITY, + OGS_TIMER_SUBSCRIPTION_VALIDITY, + OGS_TIMER_SBI_CLIENT_WAIT, + + OGS_MAX_NUM_OF_PROTO_TIMER, + +} ogs_timer_e; + +const char *ogs_timer_get_name(int timer_id); + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_PROTO_TIMER_H */ diff --git a/lib/core/ogs-3gpp-types.c b/lib/proto/types.c similarity index 99% rename from lib/core/ogs-3gpp-types.c rename to lib/proto/types.c index b3245389e..291fee34e 100644 --- a/lib/core/ogs-3gpp-types.c +++ b/lib/proto/types.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "ogs-core.h" +#include "ogs-proto.h" #define PLMN_ID_DIGIT1(x) (((x) / 100) % 10) #define PLMN_ID_DIGIT2(x) (((x) / 10) % 10) diff --git a/lib/core/ogs-3gpp-types.h b/lib/proto/types.h similarity index 99% rename from lib/core/ogs-3gpp-types.h rename to lib/proto/types.h index abb3df74b..d2aae9162 100644 --- a/lib/core/ogs-3gpp-types.h +++ b/lib/proto/types.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -17,12 +17,12 @@ * along with this program. If not, see . */ -#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#if !defined(OGS_PROTO_INSIDE) && !defined(OGS_PROTO_COMPILATION) #error "This header cannot be included directly." #endif -#ifndef OGS_3GPP_TYPES_H -#define OGS_3GPP_TYPES_H +#ifndef OGS_PROTO_TYPES_H +#define OGS_PROTO_TYPES_H #ifdef __cplusplus extern "C" { @@ -107,8 +107,6 @@ extern "C" { #define OGS_MAX_QOS_FLOW_ID 63 -#define OGS_DEFAULT_SCTP_MAX_NUM_OF_OSTREAMS 30 - /************************************ * PLMN_ID Structure */ #define OGS_MAX_NUM_OF_PLMN 6 @@ -778,4 +776,4 @@ int ogs_pcc_rule_update_qos_from_media( } #endif -#endif /* OGS_3GPP_TYPES_H */ +#endif /* OGS_PROTO_TYPES_H */ diff --git a/lib/sbi/client.c b/lib/sbi/client.c index 5c16fb8a1..e0ce44ab1 100644 --- a/lib/sbi/client.c +++ b/lib/sbi/client.c @@ -102,8 +102,8 @@ ogs_sbi_client_t *ogs_sbi_client_add(ogs_sockaddr_t *addr) ogs_assert(client); memset(client, 0, sizeof(ogs_sbi_client_t)); - client->reference_count++; - ogs_trace("ogs_sbi_client_add()"); + ogs_debug("ogs_sbi_client_add()"); + OGS_OBJECT_REF(client); ogs_assert(OGS_OK == ogs_copyaddrinfo(&client->node.addr, addr)); @@ -128,17 +128,22 @@ ogs_sbi_client_t *ogs_sbi_client_add(ogs_sockaddr_t *addr) void ogs_sbi_client_remove(ogs_sbi_client_t *client) { + ogs_sockaddr_t *addr = NULL; + char buf[OGS_ADDRSTRLEN]; + ogs_assert(client); + addr = client->node.addr; + ogs_assert(addr); + ogs_debug("ogs_sbi_client_remove() [%s:%d]", + OGS_ADDR(addr, buf), OGS_PORT(addr)); + /* ogs_sbi_client_t is always created with reference context */ - ogs_assert(client->reference_count > 0); - - ogs_trace("client->reference_count = %d", client->reference_count); - client->reference_count--; - if (client->reference_count > 0) + if (OGS_OBJECT_IS_REF(client)) { + OGS_OBJECT_UNREF(client); return; + } - ogs_trace("ogs_sbi_client_remove()"); ogs_list_remove(&ogs_sbi_self()->client_list, client); connection_remove_all(client); diff --git a/lib/sbi/client.h b/lib/sbi/client.h index ae93a961e..3a450efe4 100644 --- a/lib/sbi/client.h +++ b/lib/sbi/client.h @@ -47,10 +47,8 @@ extern "C" { ogs_sbi_client_remove(client); \ } \ \ - (__pClient)->reference_count++; \ + OGS_OBJECT_REF(__pClient); \ ((__cTX)->client) = (__pClient); \ - ogs_trace("client->reference_count = %d", \ - (__pClient)->reference_count); \ } while(0) typedef int (*ogs_sbi_client_cb_f)( diff --git a/lib/sbi/context.c b/lib/sbi/context.c index 5c0c3c779..8559dd726 100644 --- a/lib/sbi/context.c +++ b/lib/sbi/context.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "app/ogs-app.h" +#include "ogs-app.h" #include "ogs-sbi.h" int __ogs_sbi_domain; @@ -727,6 +727,16 @@ int ogs_sbi_context_parse_config( return OGS_OK; } +void ogs_sbi_add_to_be_notified_nf_type(OpenAPI_nf_type_e nf_type) +{ + ogs_assert(nf_type); + + if (self.num_of_to_be_notified_nf_type < OGS_SBI_MAX_NUM_OF_NF_TYPE) { + self.to_be_notified_nf_type[self.num_of_to_be_notified_nf_type] = nf_type; + self.num_of_to_be_notified_nf_type++; + } +} + bool ogs_sbi_nf_service_is_available(const char *name) { int i; @@ -753,8 +763,9 @@ ogs_sbi_nf_instance_t *ogs_sbi_nf_instance_add(void) ogs_assert(nf_instance); memset(nf_instance, 0, sizeof(ogs_sbi_nf_instance_t)); - nf_instance->reference_count++; - ogs_trace("ogs_sbi_nf_instance_add()"); + ogs_debug("ogs_sbi_nf_instance_add()"); + + OGS_OBJECT_REF(nf_instance); nf_instance->time.heartbeat_interval = ogs_app()->time.nf_instance.heartbeat_interval; @@ -802,7 +813,7 @@ void ogs_sbi_nf_instance_add_allowed_nf_type( ogs_assert(allowed_nf_type); if (nf_instance->num_of_allowed_nf_type < OGS_SBI_MAX_NUM_OF_NF_TYPE) { - nf_instance->allowed_nf_types[nf_instance->num_of_allowed_nf_type] = + nf_instance->allowed_nf_type[nf_instance->num_of_allowed_nf_type] = allowed_nf_type; nf_instance->num_of_allowed_nf_type++; } @@ -836,13 +847,13 @@ void ogs_sbi_nf_instance_remove(ogs_sbi_nf_instance_t *nf_instance) { ogs_assert(nf_instance); - ogs_trace("nf_instance->reference_count = %d", - nf_instance->reference_count); - nf_instance->reference_count--; - if (nf_instance->reference_count > 0) - return; + ogs_debug("ogs_sbi_nf_instance_remove()"); + + if (OGS_OBJECT_IS_REF(nf_instance)) { + OGS_OBJECT_UNREF(nf_instance); + return; + } - ogs_trace("ogs_sbi_nf_instance_remove()"); ogs_list_remove(&ogs_sbi_self()->nf_instance_list, nf_instance); ogs_sbi_nf_info_remove_all(&nf_instance->nf_info_list); @@ -935,17 +946,17 @@ void ogs_sbi_nf_service_add_version(ogs_sbi_nf_service_t *nf_service, ogs_assert(full); if (nf_service->num_of_version < OGS_SBI_MAX_NUM_OF_SERVICE_VERSION) { - nf_service->versions[nf_service->num_of_version].in_uri = + nf_service->version[nf_service->num_of_version].in_uri = ogs_strdup(in_uri); - ogs_assert(nf_service->versions[nf_service->num_of_version].in_uri); - nf_service->versions[nf_service->num_of_version].full = + ogs_assert(nf_service->version[nf_service->num_of_version].in_uri); + nf_service->version[nf_service->num_of_version].full = ogs_strdup(full); - ogs_assert(nf_service->versions[nf_service->num_of_version].full); + ogs_assert(nf_service->version[nf_service->num_of_version].full); if (expiry) { - nf_service->versions[nf_service->num_of_version].expiry = + nf_service->version[nf_service->num_of_version].expiry = ogs_strdup(expiry); ogs_assert( - nf_service->versions[nf_service->num_of_version].expiry); + nf_service->version[nf_service->num_of_version].expiry); } nf_service->num_of_version++; @@ -978,12 +989,12 @@ void ogs_sbi_nf_service_clear(ogs_sbi_nf_service_t *nf_service) ogs_free(nf_service->fqdn); for (i = 0; i < nf_service->num_of_version; i++) { - if (nf_service->versions[i].in_uri) - ogs_free(nf_service->versions[i].in_uri); - if (nf_service->versions[i].full) - ogs_free(nf_service->versions[i].full); - if (nf_service->versions[i].expiry) - ogs_free(nf_service->versions[i].expiry); + if (nf_service->version[i].in_uri) + ogs_free(nf_service->version[i].in_uri); + if (nf_service->version[i].full) + ogs_free(nf_service->version[i].full); + if (nf_service->version[i].expiry) + ogs_free(nf_service->version[i].expiry); } nf_service->num_of_version = 0; @@ -1368,13 +1379,13 @@ bool ogs_sbi_discovery_param_is_matched( ogs_sbi_discovery_option_t *discovery_option) { ogs_assert(nf_instance); - ogs_assert(ogs_sbi_self()->nf_state_registered); ogs_assert(target_nf_type); - if (!OGS_FSM_CHECK(&nf_instance->sm, - ogs_sbi_self()->nf_state_registered)) return false; + if (!OGS_FSM_CHECK(&nf_instance->sm, ogs_sbi_nf_state_registered)) + return false; - if (nf_instance->nf_type != target_nf_type) return false; + if (nf_instance->nf_type != target_nf_type) + return false; if (discovery_option) { if (discovery_option->target_nf_instance_id && @@ -1393,7 +1404,6 @@ void ogs_sbi_select_nf( { ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_assert(ogs_sbi_self()->nf_state_registered); ogs_assert(sbi_object); ogs_assert(target_nf_type); @@ -1407,20 +1417,18 @@ void ogs_sbi_select_nf( } } -bool ogs_sbi_client_associate(ogs_sbi_nf_instance_t *nf_instance) +void ogs_sbi_client_associate(ogs_sbi_nf_instance_t *nf_instance) { ogs_sbi_client_t *client = NULL; ogs_assert(nf_instance); client = nf_instance_find_client(nf_instance); - if (!client) return false; + ogs_assert(client); OGS_SBI_SETUP_CLIENT(nf_instance, client); nf_service_associate_client_all(nf_instance); - - return true; } OpenAPI_uri_scheme_e ogs_sbi_default_uri_scheme(void) @@ -1442,7 +1450,7 @@ ogs_sbi_client_t *ogs_sbi_client_find_by_service_name( ogs_assert(nf_service->name); if (strcmp(nf_service->name, name) == 0) { for (i = 0; i < nf_service->num_of_version; i++) { - if (strcmp(nf_service->versions[i].in_uri, version) == 0) { + if (strcmp(nf_service->version[i].in_uri, version) == 0) { return nf_service->client; } } @@ -1476,7 +1484,6 @@ ogs_sbi_xact_t *ogs_sbi_xact_add( { ogs_sbi_xact_t *xact = NULL; - ogs_assert(ogs_sbi_self()->client_wait_expire); ogs_assert(sbi_object); ogs_pool_alloc(&xact_pool, &xact); @@ -1496,7 +1503,7 @@ ogs_sbi_xact_t *ogs_sbi_xact_add( } xact->t_response = ogs_timer_add( - ogs_app()->timer_mgr, ogs_sbi_self()->client_wait_expire, xact); + ogs_app()->timer_mgr, ogs_timer_sbi_client_wait_expire, xact); if (!xact->t_response) { ogs_error("ogs_timer_add() failed"); ogs_sbi_request_free(xact->request); diff --git a/lib/sbi/context.h b/lib/sbi/context.h index fbe9ee8fb..6854ceb4d 100644 --- a/lib/sbi/context.h +++ b/lib/sbi/context.h @@ -65,11 +65,12 @@ typedef struct ogs_sbi_context_s { const char *content_encoding; - void (*client_wait_expire)(void *data); - ogs_fsm_handler_t nf_state_registered; - int num_of_service_name; const char *service_name[OGS_MAX_NUM_OF_NF_SERVICE]; + +#define OGS_SBI_MAX_NUM_OF_NF_TYPE 16 + int num_of_to_be_notified_nf_type; + OpenAPI_nf_type_e to_be_notified_nf_type[OGS_SBI_MAX_NUM_OF_NF_TYPE]; } ogs_sbi_context_t; typedef struct ogs_sbi_nf_instance_s { @@ -87,14 +88,14 @@ typedef struct ogs_sbi_nf_instance_s { ogs_timer_t *t_no_heartbeat; /* check heartbeat */ ogs_timer_t *t_validity; /* check validation */ -#define NF_INSTANCE_IS_SELF(_iD) \ +#define NF_INSTANCE_ID_IS_SELF(_iD) \ (_iD) && ogs_sbi_self()->nf_instance && \ strcmp((_iD), ogs_sbi_self()->nf_instance->id) == 0 -#define NF_INSTANCE_IS_OTHERS(_iD) \ +#define NF_INSTANCE_ID_IS_OTHERS(_iD) \ (_iD) && ogs_sbi_self()->nf_instance && \ strcmp((_iD), ogs_sbi_self()->nf_instance->id) != 0 -#define NF_INSTANCE_IS_NRF(__nFInstance) \ +#define NF_INSTANCE_TYPE_IS_NRF(__nFInstance) \ ((__nFInstance->nf_type) == OpenAPI_nf_type_NRF) char *id; /* NFInstanceId */ @@ -110,9 +111,8 @@ typedef struct ogs_sbi_nf_instance_s { int num_of_ipv6; ogs_sockaddr_t *ipv6[OGS_SBI_MAX_NUM_OF_IP_ADDRESS]; -#define OGS_SBI_MAX_NUM_OF_NF_TYPE 16 int num_of_allowed_nf_type; - OpenAPI_nf_type_e allowed_nf_types[OGS_SBI_MAX_NUM_OF_NF_TYPE]; + OpenAPI_nf_type_e allowed_nf_type[OGS_SBI_MAX_NUM_OF_NF_TYPE]; #define OGS_SBI_DEFAULT_PRIORITY 0 #define OGS_SBI_DEFAULT_CAPACITY 100 @@ -188,7 +188,7 @@ typedef struct ogs_sbi_nf_service_s { char *in_uri; char *full; char *expiry; - } versions[OGS_SBI_MAX_NUM_OF_SERVICE_VERSION]; + } version[OGS_SBI_MAX_NUM_OF_SERVICE_VERSION]; char *fqdn; int num_of_addr; @@ -273,6 +273,8 @@ ogs_sbi_context_t *ogs_sbi_self(void); int ogs_sbi_context_parse_config( const char *local, const char *nrf, const char *scp); +void ogs_sbi_add_to_be_notified_nf_type(OpenAPI_nf_type_e nf_type); + bool ogs_sbi_nf_service_is_available(const char *name); ogs_sbi_nf_instance_t *ogs_sbi_scp_instance(void); @@ -320,7 +322,7 @@ ogs_sbi_nf_service_t *ogs_sbi_nf_service_build_default( ogs_sbi_client_t *ogs_sbi_client_find_by_service_name( ogs_sbi_nf_instance_t *nf_instance, char *name, char *version); -bool ogs_sbi_client_associate(ogs_sbi_nf_instance_t *nf_instance); +void ogs_sbi_client_associate(ogs_sbi_nf_instance_t *nf_instance); OpenAPI_uri_scheme_e ogs_sbi_default_uri_scheme(void); @@ -341,10 +343,8 @@ OpenAPI_uri_scheme_e ogs_sbi_default_uri_scheme(void); OGS_SBI_NF_INSTANCE((__sBIObject), (__nFType))); \ } \ \ - (__nFInstance)->reference_count++; \ + OGS_OBJECT_REF(__nFInstance); \ OGS_SBI_NF_INSTANCE((__sBIObject), (__nFType)) = (__nFInstance); \ - ogs_trace("nf_instance->reference_count = %d", \ - (__nFInstance)->reference_count); \ } while(0) bool ogs_sbi_discovery_param_is_matched( diff --git a/lib/sbi/meson.build b/lib/sbi/meson.build index f5c32ae40..db8f3e562 100644 --- a/lib/sbi/meson.build +++ b/lib/sbi/meson.build @@ -28,6 +28,7 @@ libsbi_sources = files(''' yuarel.c conv.c + timer.c message.c mhd-server.c @@ -39,8 +40,9 @@ libsbi_sources = files(''' nnrf-build.c nnrf-handler.c - + path.c + nf-sm.c '''.split()) libsbi_inc = include_directories('.') @@ -57,8 +59,7 @@ libsbi = library('ogssbi', version : libogslib_version, c_args : sbi_cc_flags, include_directories : [libsbi_inc, libinc], - dependencies : [libcore_dep, - libcrypt_dep, + dependencies : [libcrypt_dep, libapp_dep, libsbi_openapi_dep, libgnutls_dep, @@ -71,8 +72,7 @@ libsbi = library('ogssbi', libsbi_dep = declare_dependency( link_with : libsbi, include_directories : [libsbi_inc, libinc], - dependencies : [libcore_dep, - libcrypt_dep, + dependencies : [libcrypt_dep, libapp_dep, libsbi_openapi_dep, libgnutls_dep, diff --git a/src/bsf/nf-sm.c b/lib/sbi/nf-sm.c similarity index 72% rename from src/bsf/nf-sm.c rename to lib/sbi/nf-sm.c index 503777285..1da972189 100644 --- a/src/bsf/nf-sm.c +++ b/lib/sbi/nf-sm.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -17,28 +17,44 @@ * along with this program. If not, see . */ -#include "context.h" +#include "ogs-app.h" +#include "ogs-sbi.h" -#include "sbi-path.h" -#include "nnrf-handler.h" - -void bsf_nf_fsm_init(ogs_sbi_nf_instance_t *nf_instance) +void ogs_sbi_nf_fsm_init(ogs_sbi_nf_instance_t *nf_instance) { - bsf_event_t e; + ogs_event_t e; + + ogs_assert(nf_instance); + + if (NF_INSTANCE_TYPE_IS_NRF(nf_instance)) { + } else if (NF_INSTANCE_ID_IS_OTHERS(nf_instance->id)) { + } else { + ogs_fatal("FSM is available in NRF or OTHERS"); + ogs_assert_if_reached(); + } + + memset(&e, 0, sizeof(e)); + e.sbi.data = nf_instance; + + ogs_fsm_init(&nf_instance->sm, + ogs_sbi_nf_state_initial, ogs_sbi_nf_state_final, &e); +} + +void ogs_sbi_nf_fsm_tran(ogs_sbi_nf_instance_t *nf_instance, void *state) +{ + ogs_event_t e; ogs_assert(nf_instance); memset(&e, 0, sizeof(e)); e.sbi.data = nf_instance; - ogs_fsm_create(&nf_instance->sm, - bsf_nf_state_initial, bsf_nf_state_final); - ogs_fsm_init(&nf_instance->sm, &e); + ogs_fsm_tran(&nf_instance->sm, state, &e); } -void bsf_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance) +void ogs_sbi_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance) { - bsf_event_t e; + ogs_event_t e; ogs_assert(nf_instance); @@ -46,50 +62,49 @@ void bsf_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance) e.sbi.data = nf_instance; ogs_fsm_fini(&nf_instance->sm, &e); - ogs_fsm_delete(&nf_instance->sm); } -void bsf_nf_state_initial(ogs_fsm_t *s, bsf_event_t *e) +void ogs_sbi_nf_state_initial(ogs_fsm_t *s, ogs_event_t *e) { ogs_sbi_nf_instance_t *nf_instance = NULL; ogs_assert(s); ogs_assert(e); - bsf_sm_debug(e); + ogs_sbi_sm_debug(e); nf_instance = e->sbi.data; ogs_assert(nf_instance); nf_instance->t_registration_interval = ogs_timer_add(ogs_app()->timer_mgr, - bsf_timer_nf_instance_registration_interval, nf_instance); + ogs_timer_nf_instance_registration_interval, nf_instance); ogs_assert(nf_instance->t_registration_interval); nf_instance->t_heartbeat_interval = ogs_timer_add(ogs_app()->timer_mgr, - bsf_timer_nf_instance_heartbeat_interval, nf_instance); + ogs_timer_nf_instance_heartbeat_interval, nf_instance); ogs_assert(nf_instance->t_heartbeat_interval); nf_instance->t_no_heartbeat = ogs_timer_add(ogs_app()->timer_mgr, - bsf_timer_nf_instance_no_heartbeat, nf_instance); + ogs_timer_nf_instance_no_heartbeat, nf_instance); ogs_assert(nf_instance->t_no_heartbeat); nf_instance->t_validity = ogs_timer_add(ogs_app()->timer_mgr, - bsf_timer_nf_instance_validity, nf_instance); + ogs_timer_nf_instance_validity, nf_instance); ogs_assert(nf_instance->t_validity); - if (NF_INSTANCE_IS_NRF(nf_instance)) { - OGS_FSM_TRAN(s, &bsf_nf_state_will_register); + if (NF_INSTANCE_TYPE_IS_NRF(nf_instance)) { + OGS_FSM_TRAN(s, &ogs_sbi_nf_state_will_register); } else { ogs_assert(nf_instance->id); - OGS_FSM_TRAN(s, &bsf_nf_state_registered); + OGS_FSM_TRAN(s, &ogs_sbi_nf_state_registered); } } -void bsf_nf_state_final(ogs_fsm_t *s, bsf_event_t *e) +void ogs_sbi_nf_state_final(ogs_fsm_t *s, ogs_event_t *e) { ogs_sbi_nf_instance_t *nf_instance = NULL; ogs_assert(s); ogs_assert(e); - bsf_sm_debug(e); + ogs_sbi_sm_debug(e); nf_instance = e->sbi.data; ogs_assert(nf_instance); @@ -100,7 +115,7 @@ void bsf_nf_state_final(ogs_fsm_t *s, bsf_event_t *e) ogs_timer_delete(nf_instance->t_validity); } -void bsf_nf_state_will_register(ogs_fsm_t *s, bsf_event_t *e) +void ogs_sbi_nf_state_will_register(ogs_fsm_t *s, ogs_event_t *e) { ogs_sbi_nf_instance_t *nf_instance = NULL; ogs_sbi_client_t *client = NULL; @@ -110,27 +125,26 @@ void bsf_nf_state_will_register(ogs_fsm_t *s, bsf_event_t *e) ogs_assert(s); ogs_assert(e); - bsf_sm_debug(e); + ogs_sbi_sm_debug(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)); + ogs_assert(NF_INSTANCE_TYPE_IS_NRF(nf_instance)); switch (e->id) { case OGS_FSM_ENTRY_SIG: ogs_timer_start(nf_instance->t_registration_interval, ogs_app()->time.message.sbi.nf_register_interval); - ogs_assert(true == ogs_nnrf_nfm_send_nf_register( - nf_instance, bsf_nnrf_nfm_build_register)); + ogs_assert(true == ogs_nnrf_nfm_send_nf_register(nf_instance)); break; case OGS_FSM_EXIT_SIG: ogs_timer_stop(nf_instance->t_registration_interval); break; - case BSF_EVT_SBI_CLIENT: + case OGS_EVENT_SBI_CLIENT: message = e->sbi.message; ogs_assert(message); @@ -142,13 +156,13 @@ void bsf_nf_state_will_register(ogs_fsm_t *s, bsf_event_t *e) if (message->res_status == OGS_SBI_HTTP_STATUS_OK || message->res_status == OGS_SBI_HTTP_STATUS_CREATED) { - bsf_nnrf_handle_nf_register(nf_instance, message); - OGS_FSM_TRAN(s, &bsf_nf_state_registered); + ogs_sbi_nnrf_handle_nf_register(nf_instance, message); + OGS_FSM_TRAN(s, &ogs_sbi_nf_state_registered); } else { ogs_error("[%s] HTTP Response Status Code [%d]", ogs_sbi_self()->nf_instance->id, message->res_status); - OGS_FSM_TRAN(s, &bsf_nf_state_exception); + OGS_FSM_TRAN(s, &ogs_sbi_nf_state_exception); } break; @@ -165,9 +179,9 @@ void bsf_nf_state_will_register(ogs_fsm_t *s, bsf_event_t *e) END break; - case BSF_EVT_SBI_TIMER: + case OGS_EVENT_SBI_TIMER: switch(e->timer_id) { - case BSF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: + case OGS_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: client = nf_instance->client; ogs_assert(client); addr = client->node.addr; @@ -179,25 +193,23 @@ void bsf_nf_state_will_register(ogs_fsm_t *s, bsf_event_t *e) ogs_timer_start(nf_instance->t_registration_interval, ogs_app()->time.message.sbi.nf_register_interval); - ogs_assert(true == ogs_nnrf_nfm_send_nf_register( - nf_instance, bsf_nnrf_nfm_build_register)); + ogs_assert(true == ogs_nnrf_nfm_send_nf_register(nf_instance)); break; default: ogs_error("[%s] Unknown timer[%s:%d]", ogs_sbi_self()->nf_instance->id, - bsf_timer_get_name(e->timer_id), e->timer_id); + ogs_timer_get_name(e->timer_id), e->timer_id); } break; default: - ogs_error("[%s] Unknown event %s", - ogs_sbi_self()->nf_instance->id, bsf_event_get_name(e)); + ogs_error("Unknown event %s", ogs_event_get_name(e)); break; } } -void bsf_nf_state_registered(ogs_fsm_t *s, bsf_event_t *e) +void ogs_sbi_nf_state_registered(ogs_fsm_t *s, ogs_event_t *e) { ogs_sbi_nf_instance_t *nf_instance = NULL; ogs_sbi_client_t *client = NULL; @@ -205,7 +217,7 @@ void bsf_nf_state_registered(ogs_fsm_t *s, bsf_event_t *e) ogs_assert(s); ogs_assert(e); - bsf_sm_debug(e); + ogs_sbi_sm_debug(e); nf_instance = e->sbi.data; ogs_assert(nf_instance); @@ -213,7 +225,9 @@ void bsf_nf_state_registered(ogs_fsm_t *s, bsf_event_t *e) switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_NRF(nf_instance)) { + if (NF_INSTANCE_TYPE_IS_NRF(nf_instance)) { + int i; + ogs_info("[%s] NF registered [Heartbeat:%ds]", ogs_sbi_self()->nf_instance->id, nf_instance->time.heartbeat_interval); @@ -229,12 +243,20 @@ void bsf_nf_state_registered(ogs_fsm_t *s, bsf_event_t *e) nf_instance->time.heartbeat_interval + ogs_app()->time.nf_instance.no_heartbeat_margin)); } - } + for (i = 0; + i < ogs_sbi_self()->num_of_to_be_notified_nf_type; i++) { + ogs_assert(true == + ogs_nnrf_nfm_send_nf_status_subscribe(client, + ogs_sbi_self()->nf_instance->nf_type, + ogs_sbi_self()->nf_instance->id, + ogs_sbi_self()->to_be_notified_nf_type[i])); + } + } break; case OGS_FSM_EXIT_SIG: - if (NF_INSTANCE_IS_NRF(nf_instance)) { + if (NF_INSTANCE_TYPE_IS_NRF(nf_instance)) { ogs_info("[%s] NF de-registered", ogs_sbi_self()->nf_instance->id); if (nf_instance->time.heartbeat_interval) { @@ -242,14 +264,14 @@ void bsf_nf_state_registered(ogs_fsm_t *s, bsf_event_t *e) ogs_timer_stop(nf_instance->t_no_heartbeat); } - if (!OGS_FSM_CHECK(&nf_instance->sm, bsf_nf_state_exception)) { + if (!OGS_FSM_CHECK(&nf_instance->sm, ogs_sbi_nf_state_exception)) { ogs_assert(true == - ogs_nnrf_nfm_send_nf_de_register(nf_instance)); + ogs_nnrf_nfm_send_nf_de_register(nf_instance)); } } break; - case BSF_EVT_SBI_CLIENT: + case OGS_EVENT_SBI_CLIENT: message = e->sbi.message; ogs_assert(message); @@ -271,7 +293,7 @@ void bsf_nf_state_registered(ogs_fsm_t *s, bsf_event_t *e) ogs_warn("[%s] HTTP response error [%d]", ogs_sbi_self()->nf_instance->id, message->res_status); - OGS_FSM_TRAN(s, &bsf_nf_state_exception); + OGS_FSM_TRAN(s, &ogs_sbi_nf_state_exception); } break; @@ -289,9 +311,9 @@ void bsf_nf_state_registered(ogs_fsm_t *s, bsf_event_t *e) END break; - case BSF_EVT_SBI_TIMER: + case OGS_EVENT_SBI_TIMER: switch(e->timer_id) { - case BSF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: + case OGS_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: if (nf_instance->time.heartbeat_interval) ogs_timer_start(nf_instance->t_heartbeat_interval, ogs_time_from_sec(nf_instance->time.heartbeat_interval)); @@ -299,24 +321,24 @@ void bsf_nf_state_registered(ogs_fsm_t *s, bsf_event_t *e) ogs_assert(true == ogs_nnrf_nfm_send_nf_update(nf_instance)); break; - case BSF_TIMER_NF_INSTANCE_NO_HEARTBEAT: + case OGS_TIMER_NF_INSTANCE_NO_HEARTBEAT: ogs_error("[%s] No heartbeat", ogs_sbi_self()->nf_instance->id); - OGS_FSM_TRAN(s, &bsf_nf_state_will_register); + OGS_FSM_TRAN(s, &ogs_sbi_nf_state_will_register); break; - case BSF_TIMER_NF_INSTANCE_VALIDITY: - ogs_assert(!NF_INSTANCE_IS_NRF(nf_instance)); + case OGS_TIMER_NF_INSTANCE_VALIDITY: + ogs_assert(!NF_INSTANCE_TYPE_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); + OGS_FSM_TRAN(s, &ogs_sbi_nf_state_de_registered); break; default: 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); + ogs_timer_get_name(e->timer_id), e->timer_id); } break; @@ -324,18 +346,18 @@ void bsf_nf_state_registered(ogs_fsm_t *s, bsf_event_t *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)); + ogs_event_get_name(e)); break; } } -void bsf_nf_state_de_registered(ogs_fsm_t *s, bsf_event_t *e) +void ogs_sbi_nf_state_de_registered(ogs_fsm_t *s, ogs_event_t *e) { ogs_sbi_nf_instance_t *nf_instance = NULL; ogs_assert(s); ogs_assert(e); - bsf_sm_debug(e); + ogs_sbi_sm_debug(e); nf_instance = e->sbi.data; ogs_assert(nf_instance); @@ -343,7 +365,7 @@ void bsf_nf_state_de_registered(ogs_fsm_t *s, bsf_event_t *e) switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_NRF(nf_instance)) { + if (NF_INSTANCE_TYPE_IS_NRF(nf_instance)) { ogs_info("[%s] NF de-registered", ogs_sbi_self()->nf_instance->id); } break; @@ -355,12 +377,12 @@ void bsf_nf_state_de_registered(ogs_fsm_t *s, bsf_event_t *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)); + ogs_event_get_name(e)); break; } } -void bsf_nf_state_exception(ogs_fsm_t *s, bsf_event_t *e) +void ogs_sbi_nf_state_exception(ogs_fsm_t *s, ogs_event_t *e) { ogs_sbi_nf_instance_t *nf_instance = NULL; ogs_sbi_client_t *client = NULL; @@ -369,7 +391,7 @@ void bsf_nf_state_exception(ogs_fsm_t *s, bsf_event_t *e) ogs_assert(s); ogs_assert(e); - bsf_sm_debug(e); + ogs_sbi_sm_debug(e); nf_instance = e->sbi.data; ogs_assert(nf_instance); @@ -377,7 +399,7 @@ void bsf_nf_state_exception(ogs_fsm_t *s, bsf_event_t *e) switch (e->id) { case OGS_FSM_ENTRY_SIG: - if (NF_INSTANCE_IS_NRF(nf_instance)) { + if (NF_INSTANCE_TYPE_IS_NRF(nf_instance)) { ogs_timer_start(nf_instance->t_registration_interval, ogs_app()->time.message.sbi. nf_register_interval_in_exception); @@ -385,14 +407,14 @@ void bsf_nf_state_exception(ogs_fsm_t *s, bsf_event_t *e) break; case OGS_FSM_EXIT_SIG: - if (NF_INSTANCE_IS_NRF(nf_instance)) { + if (NF_INSTANCE_TYPE_IS_NRF(nf_instance)) { ogs_timer_stop(nf_instance->t_registration_interval); } break; - case BSF_EVT_SBI_TIMER: + case OGS_EVENT_SBI_TIMER: switch(e->timer_id) { - case BSF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: + case OGS_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: client = nf_instance->client; ogs_assert(client); addr = client->node.addr; @@ -401,18 +423,18 @@ void bsf_nf_state_exception(ogs_fsm_t *s, bsf_event_t *e) ogs_warn("[%s] Retry to registration with NRF", ogs_sbi_self()->nf_instance->id); - OGS_FSM_TRAN(s, &bsf_nf_state_will_register); + OGS_FSM_TRAN(s, &ogs_sbi_nf_state_will_register); break; default: 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); + ogs_timer_get_name(e->timer_id), e->timer_id); } break; - case BSF_EVT_SBI_CLIENT: + case OGS_EVENT_SBI_CLIENT: message = e->sbi.message; ogs_assert(message); @@ -436,7 +458,7 @@ void bsf_nf_state_exception(ogs_fsm_t *s, bsf_event_t *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)); + ogs_event_get_name(e)); break; } } diff --git a/lib/sbi/nf-sm.h b/lib/sbi/nf-sm.h new file mode 100644 index 000000000..4c0a45473 --- /dev/null +++ b/lib/sbi/nf-sm.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_SBI_INSIDE) && !defined(OGS_SBI_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_SBI_NF_SM_H +#define OGS_SBI_NF_SM_H + +#ifdef __cplusplus +extern "C" { +#endif + +void ogs_sbi_nf_fsm_init(ogs_sbi_nf_instance_t *nf_instance); +void ogs_sbi_nf_fsm_tran(ogs_sbi_nf_instance_t *nf_instance, void *state); +void ogs_sbi_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance); + +void ogs_sbi_nf_state_initial(ogs_fsm_t *s, ogs_event_t *e); +void ogs_sbi_nf_state_final(ogs_fsm_t *s, ogs_event_t *e); +void ogs_sbi_nf_state_will_register(ogs_fsm_t *s, ogs_event_t *e); +void ogs_sbi_nf_state_registered(ogs_fsm_t *s, ogs_event_t *e); +void ogs_sbi_nf_state_de_registered(ogs_fsm_t *s, ogs_event_t *e); +void ogs_sbi_nf_state_exception(ogs_fsm_t *s, ogs_event_t *e); + +#define ogs_sbi_sm_debug(__e) \ + ogs_debug("%s(): %s", __func__, ogs_event_get_name(__e)) + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_SBI_NF_SM_H */ diff --git a/lib/sbi/nnrf-build.c b/lib/sbi/nnrf-build.c index 8249b4f9c..6952b25da 100644 --- a/lib/sbi/nnrf-build.c +++ b/lib/sbi/nnrf-build.c @@ -32,11 +32,6 @@ OpenAPI_nf_profile_t *ogs_nnrf_nfm_build_nf_profile(void) OpenAPI_list_t *NFServiceList = NULL; int i = 0; -#if SBI_FQDN_WITH_ONE_OCTET_LENGTH - int fqdn_len; - char fqdn[OGS_MAX_FQDN_LEN]; -#endif - char *ipstr = NULL; nf_instance = ogs_sbi_self()->nf_instance; @@ -64,22 +59,8 @@ OpenAPI_nf_profile_t *ogs_nnrf_nfm_build_nf_profile(void) NFProfile->is_nf_profile_changes_support_ind = true; NFProfile->nf_profile_changes_support_ind = true; - if (nf_instance->fqdn) { -#if SBI_FQDN_WITH_ONE_OCTET_LENGTH - memset(fqdn, 0, sizeof(fqdn)); - fqdn_len = ogs_fqdn_build(fqdn, - nf_instance->fqdn, strlen(nf_instance->fqdn)); - NFProfile->fqdn = ogs_memdup(fqdn, fqdn_len+1); - ogs_expect_or_return_val(NFProfile->fqdn, NULL); - NFProfile->fqdn[fqdn_len] = 0; - - ogs_debug("NFInstance-FQDN[%s]", nf_instance->fqdn); - ogs_log_hexdump(OGS_LOG_DEBUG, - (unsigned char *)NFProfile->fqdn, fqdn_len); -#else + if (nf_instance->fqdn) NFProfile->fqdn = ogs_strdup(nf_instance->fqdn); -#endif - } NFProfile->is_priority = true; NFProfile->priority = nf_instance->priority; @@ -131,7 +112,7 @@ OpenAPI_nf_profile_t *ogs_nnrf_nfm_build_nf_profile(void) for (i = 0; i < nf_instance->num_of_allowed_nf_type; i++) { OpenAPI_list_add(AllowedNfTypeList, - (void *)(uintptr_t)nf_instance->allowed_nf_types[i]); + (void *)(uintptr_t)nf_instance->allowed_nf_type[i]); } if (AllowedNfTypeList->count) @@ -163,21 +144,21 @@ OpenAPI_nf_profile_t *ogs_nnrf_nfm_build_nf_profile(void) NFServiceVersion = ogs_calloc(1, sizeof(*NFServiceVersion)); ogs_expect_or_return_val(NFServiceVersion, NULL); - if (nf_service->versions[i].in_uri) { + if (nf_service->version[i].in_uri) { NFServiceVersion->api_version_in_uri = - ogs_strdup(nf_service->versions[i].in_uri); + ogs_strdup(nf_service->version[i].in_uri); ogs_expect_or_return_val( NFServiceVersion->api_version_in_uri, NULL); } - if (nf_service->versions[i].full) { + if (nf_service->version[i].full) { NFServiceVersion->api_full_version = - ogs_strdup(nf_service->versions[i].full); + ogs_strdup(nf_service->version[i].full); ogs_expect_or_return_val( NFServiceVersion->api_full_version, NULL); } - if (nf_service->versions[i].expiry) { + if (nf_service->version[i].expiry) { NFServiceVersion->expiry = - ogs_strdup(nf_service->versions[i].expiry); + ogs_strdup(nf_service->version[i].expiry); ogs_expect_or_return_val( NFServiceVersion->expiry, NULL); } @@ -191,22 +172,8 @@ OpenAPI_nf_profile_t *ogs_nnrf_nfm_build_nf_profile(void) NFService->scheme = nf_service->scheme; NFService->nf_service_status = nf_service->status; - if (nf_service->fqdn) { -#if SBI_FQDN_WITH_ONE_OCTET_LENGTH - memset(fqdn, 0, sizeof(fqdn)); - fqdn_len = ogs_fqdn_build(fqdn, - nf_service->fqdn, strlen(nf_service->fqdn)); - NFService->fqdn = ogs_memdup(fqdn, fqdn_len+1); - ogs_expect_or_return_val(NFService->fqdn, NULL); - NFService->fqdn[fqdn_len] = 0; - - ogs_debug("NFService-FQDN[%s]", nf_service->fqdn); - ogs_log_hexdump(OGS_LOG_DEBUG, - (unsigned char *)NFService->fqdn, fqdn_len); -#else + if (nf_service->fqdn) NFService->fqdn = ogs_strdup(nf_service->fqdn); -#endif - } IpEndPointList = OpenAPI_list_create(); ogs_assert(IpEndPointList); @@ -333,6 +300,284 @@ void ogs_sbi_nnrf_free_nf_profile(OpenAPI_nf_profile_t *NFProfile) ogs_free(NFProfile); } +ogs_sbi_request_t *ogs_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; + + OpenAPI_nf_profile_t *NFProfile = NULL; + + OpenAPI_list_t *SmfInfoList = NULL; + OpenAPI_map_t *SmfInfoMap = NULL; + OpenAPI_smf_info_t *SmfInfo = NULL; + int SmfInfoMapKey; + + OpenAPI_list_t *sNssaiSmfInfoList = NULL; + OpenAPI_snssai_smf_info_item_t *sNssaiSmfInfoItem = NULL; + OpenAPI_snssai_t *sNssai = NULL; + OpenAPI_list_t *DnnSmfInfoList = NULL; + OpenAPI_dnn_smf_info_item_t *DnnSmfInfoItem = NULL; + + OpenAPI_list_t *TaiList = NULL; + OpenAPI_tai_t *TaiItem = NULL; + OpenAPI_list_t *TaiRangeList = NULL; + OpenAPI_tai_range_t *TaiRangeItem = NULL; + OpenAPI_list_t *TacRangeList = NULL; + OpenAPI_tac_range_t *TacRangeItem = NULL; + + OpenAPI_lnode_t *node = NULL, *node2 = NULL, *node3 = 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_PUT; + message.h.service.name = (char *)OGS_SBI_SERVICE_NAME_NNRF_NFM; + 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] = nf_instance->id; + + message.http.content_encoding = (char*)ogs_sbi_self()->content_encoding; + + SmfInfoList = OpenAPI_list_create(); + ogs_assert(SmfInfoList); + + SmfInfoMapKey = 0; + + ogs_list_for_each(&nf_instance->nf_info_list, nf_info) { + if (nf_info->nf_type == OpenAPI_nf_type_SMF) { + + if (nf_info->smf.num_of_slice == 0) { + ogs_fatal("CHECK CONFIGURATION: No S-NSSAI"); + ogs_assert_if_reached(); + } + + SmfInfo = ogs_calloc(1, sizeof(*SmfInfo)); + ogs_expect_or_return_val(SmfInfo, NULL); + + sNssaiSmfInfoList = OpenAPI_list_create(); + ogs_assert(sNssaiSmfInfoList); + + for (i = 0; i < nf_info->smf.num_of_slice; i++) { + DnnSmfInfoList = OpenAPI_list_create(); + ogs_assert(DnnSmfInfoList); + + for (j = 0; j < nf_info->smf.slice[i].num_of_dnn; j++) { + DnnSmfInfoItem = ogs_calloc(1, sizeof(*DnnSmfInfoItem)); + ogs_expect_or_return_val(DnnSmfInfoItem, NULL); + DnnSmfInfoItem->dnn = nf_info->smf.slice[i].dnn[j]; + + OpenAPI_list_add(DnnSmfInfoList, DnnSmfInfoItem); + } + + if (!DnnSmfInfoList->count) { + OpenAPI_list_free(DnnSmfInfoList); + + ogs_error("CHECK CONFIGURATION: No DNN"); + ogs_expect_or_return_val(0, NULL); + } + + sNssaiSmfInfoItem = ogs_calloc(1, sizeof(*sNssaiSmfInfoItem)); + ogs_expect_or_return_val(sNssaiSmfInfoItem, NULL); + + sNssaiSmfInfoItem->dnn_smf_info_list = DnnSmfInfoList; + + sNssaiSmfInfoItem->s_nssai = sNssai = + ogs_calloc(1, sizeof(*sNssai)); + ogs_expect_or_return_val(sNssai, NULL); + sNssai->sst = nf_info->smf.slice[i].s_nssai.sst; + sNssai->sd = + ogs_s_nssai_sd_to_string(nf_info->smf.slice[i].s_nssai.sd); + + OpenAPI_list_add(sNssaiSmfInfoList, sNssaiSmfInfoItem); + } + + if (sNssaiSmfInfoList->count) + SmfInfo->s_nssai_smf_info_list = sNssaiSmfInfoList; + else + OpenAPI_list_free(sNssaiSmfInfoList); + + TaiList = OpenAPI_list_create(); + ogs_assert(TaiList); + + for (i = 0; i < nf_info->smf.num_of_nr_tai; i++) { + TaiItem = ogs_calloc(1, sizeof(*TaiItem)); + ogs_expect_or_return_val(TaiItem, NULL); + TaiItem->plmn_id = ogs_sbi_build_plmn_id( + &nf_info->smf.nr_tai[i].plmn_id); + ogs_expect_or_return_val(TaiItem->plmn_id, NULL); + TaiItem->tac = + ogs_uint24_to_0string(nf_info->smf.nr_tai[i].tac); + ogs_expect_or_return_val(TaiItem->tac, NULL); + + OpenAPI_list_add(TaiList, TaiItem); + } + + if (TaiList->count) + SmfInfo->tai_list = TaiList; + else + OpenAPI_list_free(TaiList); + + TaiRangeList = OpenAPI_list_create(); + ogs_assert(TaiRangeList); + + for (i = 0; i < nf_info->smf.num_of_nr_tai_range; i++) { + TacRangeList = OpenAPI_list_create(); + ogs_assert(TacRangeList); + + for (j = 0; + j < nf_info->smf.nr_tai_range[i].num_of_tac_range; + j++) { + TacRangeItem = ogs_calloc(1, sizeof(*TacRangeItem)); + ogs_expect_or_return_val(TacRangeItem, NULL); + + TacRangeItem->start = ogs_uint24_to_0string( + nf_info->smf.nr_tai_range[i].start[j]); + ogs_expect_or_return_val(TacRangeItem->start, NULL); + TacRangeItem->end = + ogs_uint24_to_0string( + nf_info->smf.nr_tai_range[i].end[j]); + ogs_expect_or_return_val(TacRangeItem->end, NULL); + + OpenAPI_list_add(TacRangeList, TacRangeItem); + } + + if (!TacRangeList->count) { + OpenAPI_list_free(TacRangeList); + + ogs_error("CHECK CONFIGURATION: No Start/End in TacRange"); + ogs_expect_or_return_val(0, NULL); + } + + TaiRangeItem = ogs_calloc(1, sizeof(*TaiRangeItem)); + ogs_expect_or_return_val(TaiRangeItem, NULL); + + TaiRangeItem->plmn_id = ogs_sbi_build_plmn_id( + &nf_info->smf.nr_tai_range[i].plmn_id); + ogs_expect_or_return_val(TaiRangeItem->plmn_id, NULL); + + TaiRangeItem->tac_range_list = TacRangeList; + + OpenAPI_list_add(TaiRangeList, TaiRangeItem); + } + + if (TaiRangeList->count) + SmfInfo->tai_range_list = TaiRangeList; + else + OpenAPI_list_free(TaiRangeList); + + SmfInfoMap = OpenAPI_map_create( + ogs_msprintf("%d", ++SmfInfoMapKey), SmfInfo); + ogs_assert(SmfInfoMap); + + OpenAPI_list_add(SmfInfoList, SmfInfoMap); + + } else { + ogs_fatal("Not implemented NF-type[%s]", + OpenAPI_nf_type_ToString(nf_info->nf_type)); + ogs_assert_if_reached(); + } + } + + NFProfile = ogs_nnrf_nfm_build_nf_profile(); + ogs_expect_or_return_val(NFProfile, NULL); + + if (SmfInfoList->count == 1) { + NFProfile->smf_info = SmfInfo; + } else if (SmfInfoList->count > 1) { + NFProfile->smf_info_list = SmfInfoList; + } + + message.NFProfile = NFProfile; + + request = ogs_sbi_build_request(&message); + + ogs_sbi_nnrf_free_nf_profile(NFProfile); + + OpenAPI_list_for_each(SmfInfoList, node) { + SmfInfoMap = node->data; + if (SmfInfoMap) { + SmfInfo = SmfInfoMap->value; + if (SmfInfo) { + sNssaiSmfInfoList = SmfInfo->s_nssai_smf_info_list; + OpenAPI_list_for_each(sNssaiSmfInfoList, node2) { + sNssaiSmfInfoItem = node2->data; + ogs_assert(sNssaiSmfInfoItem); + + DnnSmfInfoList = sNssaiSmfInfoItem->dnn_smf_info_list; + OpenAPI_list_for_each(DnnSmfInfoList, node3) { + DnnSmfInfoItem = node3->data; + ogs_assert(DnnSmfInfoItem); + ogs_free(DnnSmfInfoItem); + } + OpenAPI_list_free(DnnSmfInfoList); + + sNssai = sNssaiSmfInfoItem->s_nssai; + if (sNssai) { + if (sNssai->sd) + ogs_free(sNssai->sd); + ogs_free(sNssai); + } + + ogs_free(sNssaiSmfInfoItem); + } + OpenAPI_list_free(sNssaiSmfInfoList); + + TaiList = SmfInfo->tai_list; + OpenAPI_list_for_each(TaiList, node2) { + TaiItem = node2->data; + ogs_assert(TaiItem); + if (TaiItem->plmn_id) + ogs_sbi_free_plmn_id(TaiItem->plmn_id); + if (TaiItem->tac) + ogs_free(TaiItem->tac); + ogs_free(TaiItem); + } + OpenAPI_list_free(TaiList); + + TaiRangeList = SmfInfo->tai_range_list; + OpenAPI_list_for_each(TaiRangeList, node2) { + TaiRangeItem = node2->data; + ogs_assert(TaiRangeItem); + + if (TaiRangeItem->plmn_id) + ogs_sbi_free_plmn_id(TaiRangeItem->plmn_id); + + TacRangeList = TaiRangeItem->tac_range_list; + OpenAPI_list_for_each(TacRangeList, node3) { + TacRangeItem = node3->data; + ogs_assert(TacRangeItem); + if (TacRangeItem->start) + ogs_free(TacRangeItem->start); + if (TacRangeItem->end) + ogs_free(TacRangeItem->end); + + ogs_free(TacRangeItem); + } + OpenAPI_list_free(TacRangeList); + + ogs_free(TaiRangeItem); + } + OpenAPI_list_free(TaiRangeList); + + ogs_free(SmfInfo); + } + if (SmfInfoMap->key) + ogs_free(SmfInfoMap->key); + ogs_free(SmfInfoMap); + } + } + OpenAPI_list_free(SmfInfoList); + + return request; +} + ogs_sbi_request_t *ogs_nnrf_nfm_build_update(void) { ogs_sbi_nf_instance_t *nf_instance = NULL; diff --git a/lib/sbi/nnrf-build.h b/lib/sbi/nnrf-build.h index edd8ee0db..52c7c9ac2 100644 --- a/lib/sbi/nnrf-build.h +++ b/lib/sbi/nnrf-build.h @@ -27,6 +27,7 @@ extern "C" { 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_register(void); ogs_sbi_request_t *ogs_nnrf_nfm_build_update(void); ogs_sbi_request_t *ogs_nnrf_nfm_build_de_register(void); diff --git a/lib/sbi/nnrf-handler.c b/lib/sbi/nnrf-handler.c index df9f3df34..68907c162 100644 --- a/lib/sbi/nnrf-handler.c +++ b/lib/sbi/nnrf-handler.c @@ -20,6 +20,245 @@ #include "ogs-sbi.h" #include "ogs-app.h" +static void handle_smf_info( + ogs_sbi_nf_instance_t *nf_instance, OpenAPI_smf_info_t *SmfInfo); + +void ogs_sbi_nnrf_handle_nf_register( + ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_message_t *recvmsg) +{ + OpenAPI_nf_profile_t *NFProfile = NULL; + ogs_sbi_client_t *client = NULL; + + ogs_assert(recvmsg); + ogs_assert(nf_instance); + client = nf_instance->client; + ogs_assert(client); + + NFProfile = recvmsg->NFProfile; + if (!NFProfile) { + ogs_error("No NFProfile"); + return; + } + + /* TIME : Update heartbeat from NRF */ + if (NFProfile->is_heart_beat_timer == true) + nf_instance->time.heartbeat_interval = NFProfile->heart_beat_timer; +} + +void ogs_sbi_nnrf_handle_nf_profile(ogs_sbi_nf_instance_t *nf_instance, + OpenAPI_nf_profile_t *NFProfile, + ogs_sbi_stream_t *stream, ogs_sbi_message_t *message) +{ + int rv; + + OpenAPI_lnode_t *node; + ogs_sbi_nf_service_t *nf_service = NULL, *next_nf_service = NULL; + + ogs_assert(nf_instance); + ogs_assert(NFProfile); + ogs_assert(NFProfile->nf_instance_id); + ogs_assert(NFProfile->nf_type); + ogs_assert(NFProfile->nf_status); + + ogs_list_for_each_safe(&nf_instance->nf_service_list, + next_nf_service, nf_service) { + bool nf_service_should_not_be_deleted = false; + + ogs_assert(nf_service->id); + + OpenAPI_list_for_each(NFProfile->nf_services, node) { + OpenAPI_nf_service_t *NFService = node->data; + + if (!NFService) continue; + if (!NFService->service_instance_id) continue; + if (!NFService->service_name) continue; + + if (strcmp(nf_service->id, NFService->service_instance_id) == 0) { + nf_service_should_not_be_deleted = true; + break; + } + } + + if (nf_service_should_not_be_deleted == false) { + ogs_warn("NFService[%s:%s] removed", + nf_service->id, nf_service->name); + OpenAPI_list_for_each(NFProfile->nf_services, node) { + OpenAPI_nf_service_t *NFService = node->data; + + if (!NFService) continue; + if (!NFService->service_instance_id) continue; + if (!NFService->service_name) continue; + + ogs_warn("NFService[%s:%s] will be added", + NFService->service_instance_id, NFService->service_name); + } + ogs_sbi_nf_service_remove(nf_service); + } + } + ogs_sbi_nf_instance_clear(nf_instance); + + nf_instance->nf_type = NFProfile->nf_type; + nf_instance->nf_status = NFProfile->nf_status; + if (NFProfile->is_heart_beat_timer == true) + nf_instance->time.heartbeat_interval = NFProfile->heart_beat_timer; + + if (NFProfile->fqdn) + nf_instance->fqdn = ogs_strdup(NFProfile->fqdn); + + if (NFProfile->is_priority == true) + nf_instance->priority = NFProfile->priority; + if (NFProfile->is_capacity == true) + nf_instance->capacity = NFProfile->capacity; + if (NFProfile->is_load == true) + nf_instance->load = NFProfile->load; + + /* Only one time handles RegisterNFInstance operation */ + OpenAPI_list_for_each(NFProfile->ipv4_addresses, node) { + ogs_sockaddr_t *addr = NULL; + + if (!node->data) continue; + + if (nf_instance->num_of_ipv4 < OGS_SBI_MAX_NUM_OF_IP_ADDRESS) { + + rv = ogs_getaddrinfo(&addr, AF_UNSPEC, + node->data, ogs_sbi_self()->sbi_port, 0); + if (rv != OGS_OK) continue; + + nf_instance->ipv4[nf_instance->num_of_ipv4] = addr; + nf_instance->num_of_ipv4++; + } + } + OpenAPI_list_for_each(NFProfile->ipv6_addresses, node) { + ogs_sockaddr_t *addr = NULL; + + if (!node->data) continue; + + if (nf_instance->num_of_ipv6 < OGS_SBI_MAX_NUM_OF_IP_ADDRESS) { + + rv = ogs_getaddrinfo(&addr, AF_UNSPEC, + node->data, ogs_sbi_self()->sbi_port, 0); + if (rv != OGS_OK) continue; + + nf_instance->ipv6[nf_instance->num_of_ipv6] = addr; + nf_instance->num_of_ipv6++; + } + } + + OpenAPI_list_for_each(NFProfile->nf_services, node) { + OpenAPI_nf_service_t *NFService = node->data; + OpenAPI_list_t *VersionList = NULL; + OpenAPI_list_t *IpEndPointList = NULL; + OpenAPI_list_t *AllowedNfTypeList = NULL; + OpenAPI_lnode_t *node2 = NULL; + + if (!NFService) continue; + if (!NFService->service_instance_id) continue; + if (!NFService->service_name) continue; + + VersionList = NFService->versions; + IpEndPointList = NFService->ip_end_points; + AllowedNfTypeList = NFService->allowed_nf_types; + + nf_service = ogs_sbi_nf_service_find_by_id(nf_instance, + NFService->service_instance_id); + if (!nf_service) { + nf_service = ogs_sbi_nf_service_add(nf_instance, + NFService->service_instance_id, + NFService->service_name, NFService->scheme); + ogs_assert(nf_service); + } + + ogs_sbi_nf_service_clear(nf_service); + + OpenAPI_list_for_each(VersionList, node2) { + OpenAPI_nf_service_version_t *NFServiceVersion = node2->data; + + if (!NFServiceVersion) continue; + + ogs_sbi_nf_service_add_version(nf_service, + NFServiceVersion->api_version_in_uri, + NFServiceVersion->api_full_version, + NFServiceVersion->expiry); + } + + if (NFService->fqdn) + nf_service->fqdn = ogs_strdup(NFService->fqdn); + + OpenAPI_list_for_each(IpEndPointList, node2) { + OpenAPI_ip_end_point_t *IpEndPoint = node2->data; + ogs_sockaddr_t *addr = NULL, *addr6 = NULL; + int port = 0; + + if (!IpEndPoint) continue; + + if (nf_service->num_of_addr < OGS_SBI_MAX_NUM_OF_IP_ADDRESS) { + if (!IpEndPoint->is_port) { + if (nf_service->scheme == OpenAPI_uri_scheme_http) + port = OGS_SBI_HTTP_PORT; + else if (nf_service->scheme == OpenAPI_uri_scheme_https) + port = OGS_SBI_HTTPS_PORT; + else + continue; + } else { + port = IpEndPoint->port; + } + + if (IpEndPoint->ipv4_address) { + rv = ogs_getaddrinfo(&addr, AF_UNSPEC, + IpEndPoint->ipv4_address, port, 0); + if (rv != OGS_OK) continue; + } + if (IpEndPoint->ipv6_address) { + rv = ogs_getaddrinfo(&addr6, AF_UNSPEC, + IpEndPoint->ipv6_address, port, 0); + if (rv != OGS_OK) continue; + } + + if (addr || addr6) { + nf_service->addr[nf_service->num_of_addr]. + port = port; + nf_service->addr[nf_service->num_of_addr]. + ipv4 = addr; + nf_service->addr[nf_service->num_of_addr]. + ipv6 = addr6; + nf_service->num_of_addr++; + } + } + } + + OpenAPI_list_for_each(AllowedNfTypeList, node2) { + OpenAPI_nf_type_e AllowedNfType = (uintptr_t)node2->data; + + if (!AllowedNfType) continue; + + if (nf_service->num_of_allowed_nf_type < + OGS_SBI_MAX_NUM_OF_NF_TYPE) { + nf_service->allowed_nf_types[ + nf_service->num_of_allowed_nf_type] = AllowedNfType; + nf_service->num_of_allowed_nf_type++; + } + } + + if (NFService->is_priority == true) + nf_service->priority = NFService->priority; + if (NFService->is_capacity == true) + nf_service->capacity = NFService->capacity; + if (NFService->is_load == true) + nf_service->load = NFService->load; + } + + ogs_sbi_nf_info_remove_all(&nf_instance->nf_info_list); + + if (NFProfile->smf_info) + handle_smf_info(nf_instance, NFProfile->smf_info); + + OpenAPI_list_for_each(NFProfile->smf_info_list, node) { + OpenAPI_map_t *SmfInfoMap = node->data; + if (SmfInfoMap && SmfInfoMap->value) + handle_smf_info(nf_instance, SmfInfoMap->value); + } +} + static void handle_smf_info( ogs_sbi_nf_instance_t *nf_instance, OpenAPI_smf_info_t *SmfInfo) { @@ -153,291 +392,306 @@ static void handle_smf_info( } } -bool ogs_sbi_nnrf_handle_nf_profile(ogs_sbi_nf_instance_t *nf_instance, - OpenAPI_nf_profile_t *NFProfile, - ogs_sbi_stream_t *stream, ogs_sbi_message_t *message) +void ogs_nnrf_handle_nf_status_subscribe( + ogs_sbi_subscription_t *subscription, ogs_sbi_message_t *recvmsg) +{ + OpenAPI_subscription_data_t *SubscriptionData = NULL; + ogs_sbi_client_t *client = NULL; + + ogs_assert(recvmsg); + ogs_assert(subscription); + client = subscription->client; + ogs_assert(client); + + SubscriptionData = recvmsg->SubscriptionData; + if (!SubscriptionData) { + ogs_error("No SubscriptionData"); + return; + } + + if (!SubscriptionData->subscription_id) { + ogs_error("No SubscriptionId"); + return; + } + ogs_sbi_subscription_set_id( + subscription, SubscriptionData->subscription_id); + + if (SubscriptionData->validity_time) { +#define VALIDITY_MINIMUM (10LL * OGS_USEC_PER_SEC) /* 10 seconds */ + ogs_time_t time, duration; + if (ogs_sbi_time_from_string( + &time, SubscriptionData->validity_time) == true) { + duration = time - ogs_time_now(); + if (duration < VALIDITY_MINIMUM) { + duration = VALIDITY_MINIMUM; + ogs_warn("[%s] Forced to %lld seconds", subscription->id, + (long long)ogs_time_sec(VALIDITY_MINIMUM)); + } + subscription->t_validity = ogs_timer_add(ogs_app()->timer_mgr, + ogs_timer_subscription_validity, subscription); + ogs_assert(subscription->t_validity); + ogs_timer_start(subscription->t_validity, duration); + } else { + ogs_error("Cannot parse validitiyTime [%s]", + SubscriptionData->validity_time); + } + } +} + +bool ogs_nnrf_handle_nf_status_notify( + ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) { int rv; - OpenAPI_lnode_t *node; - ogs_sbi_nf_service_t *nf_service = NULL, *next_nf_service = NULL; -#if SBI_FQDN_WITH_ONE_OCTET_LENGTH - char fqdn[OGS_MAX_FQDN_LEN+1]; -#endif + ogs_sbi_response_t *response = NULL; + OpenAPI_notification_data_t *NotificationData = NULL; + ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_assert(nf_instance); - ogs_assert(NFProfile); + ogs_sbi_message_t message; + ogs_sbi_header_t header; - if (!NFProfile) { - ogs_error("No NFProfile"); - if (stream) - ogs_assert(true == - ogs_sbi_server_send_error( - stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - message, "No NFProfile", NULL)); + ogs_assert(stream); + ogs_assert(recvmsg); + + NotificationData = recvmsg->NotificationData; + if (!NotificationData) { + ogs_error("No NotificationData"); + ogs_assert(true == + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + recvmsg, "No NotificationData", NULL)); return false; } - if (!NFProfile->nf_instance_id) { - ogs_error("No NFProfile.NFInstanceId"); - if (stream) - ogs_assert(true == - ogs_sbi_server_send_error( - stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - message, "NFProfile", "No NFInstanceId")); + if (!NotificationData->nf_instance_uri) { + ogs_error("No nfInstanceUri"); + ogs_assert(true == + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + recvmsg, "No nfInstanceUri", NULL)); return false; } - if (!NFProfile->nf_type) { - ogs_error("No NFProfile.NFType"); - if (stream) - ogs_assert(true == - ogs_sbi_server_send_error( - stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - message, "NFProfile", "No NFType")); + memset(&header, 0, sizeof(header)); + header.uri = NotificationData->nf_instance_uri; + + rv = ogs_sbi_parse_header(&message, &header); + if (rv != OGS_OK) { + ogs_error("Cannot parse nfInstanceUri [%s]", header.uri); + ogs_assert(true == + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + recvmsg, "Cannot parse nfInstanceUri", header.uri)); return false; } - if (!NFProfile->nf_status) { - ogs_error("No NFProfile.NFStatus"); - if (stream) - ogs_assert(true == - ogs_sbi_server_send_error( - stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - message, "NFProfile", "No NFStatus")); + if (!message.h.resource.component[1]) { + ogs_error("No nfInstanceId [%s]", header.uri); + ogs_assert(true == + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + recvmsg, "Cannot parse nfInstanceUri", header.uri)); + ogs_sbi_header_free(&header); return false; } - ogs_list_for_each_safe(&nf_instance->nf_service_list, - next_nf_service, nf_service) { - bool nf_service_should_not_be_deleted = false; - - ogs_assert(nf_service->id); - - OpenAPI_list_for_each(NFProfile->nf_services, node) { - OpenAPI_nf_service_t *NFService = node->data; - - if (!NFService) continue; - if (!NFService->service_instance_id) continue; - if (!NFService->service_name) continue; - - if (strcmp(nf_service->id, NFService->service_instance_id) == 0) { - nf_service_should_not_be_deleted = true; - break; - } - } - - if (nf_service_should_not_be_deleted == false) { - ogs_warn("NFService[%s:%s] removed", - nf_service->id, nf_service->name); - OpenAPI_list_for_each(NFProfile->nf_services, node) { - OpenAPI_nf_service_t *NFService = node->data; - - if (!NFService) continue; - if (!NFService->service_instance_id) continue; - if (!NFService->service_name) continue; - - ogs_warn("NFService[%s:%s] will be added", - NFService->service_instance_id, NFService->service_name); - } - ogs_sbi_nf_service_remove(nf_service); - } + if (NF_INSTANCE_ID_IS_SELF(message.h.resource.component[1])) { + ogs_warn("[%s] The notification is not allowed", + message.h.resource.component[1]); + ogs_assert(true == + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, + recvmsg, "The notification is not allowed", + message.h.resource.component[1])); + ogs_sbi_header_free(&header); + return false; } - ogs_sbi_nf_instance_clear(nf_instance); - nf_instance->nf_type = NFProfile->nf_type; - nf_instance->nf_status = NFProfile->nf_status; - if (NFProfile->is_heart_beat_timer == true) - nf_instance->time.heartbeat_interval = NFProfile->heart_beat_timer; + if (NotificationData->event == + OpenAPI_notification_event_type_NF_REGISTERED) { - if (NFProfile->fqdn) { -#if SBI_FQDN_WITH_ONE_OCTET_LENGTH - if (ogs_fqdn_parse( - fqdn, NFProfile->fqdn, - ogs_min(strlen(NFProfile->fqdn), OGS_MAX_FQDN_LEN)) > 0) { + OpenAPI_nf_profile_t *NFProfile = NULL; - /* Nothing : succeeded to parse FQDN */ - nf_instance->fqdn = ogs_strdup(fqdn); - ogs_assert(nf_instance); - - } else { - ogs_error("ogs_fqdn_parse() failed[%s]", NFProfile->fqdn); + NFProfile = NotificationData->nf_profile; + if (!NFProfile) { + ogs_error("No NFProfile"); + ogs_assert(true == + ogs_sbi_server_send_error( + stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + recvmsg, "No NFProfile", NULL)); + ogs_sbi_header_free(&header); return false; } -#else - nf_instance->fqdn = ogs_strdup(NFProfile->fqdn); -#endif - } - if (NFProfile->is_priority == true) - nf_instance->priority = NFProfile->priority; - if (NFProfile->is_capacity == true) - nf_instance->capacity = NFProfile->capacity; - if (NFProfile->is_load == true) - nf_instance->load = NFProfile->load; - - /* Only one time handles RegisterNFInstance operation */ - OpenAPI_list_for_each(NFProfile->ipv4_addresses, node) { - ogs_sockaddr_t *addr = NULL; - - if (!node->data) continue; - - if (nf_instance->num_of_ipv4 < OGS_SBI_MAX_NUM_OF_IP_ADDRESS) { - - rv = ogs_getaddrinfo(&addr, AF_UNSPEC, - node->data, ogs_sbi_self()->sbi_port, 0); - if (rv != OGS_OK) continue; - - nf_instance->ipv4[nf_instance->num_of_ipv4] = addr; - nf_instance->num_of_ipv4++; - } - } - OpenAPI_list_for_each(NFProfile->ipv6_addresses, node) { - ogs_sockaddr_t *addr = NULL; - - if (!node->data) continue; - - if (nf_instance->num_of_ipv6 < OGS_SBI_MAX_NUM_OF_IP_ADDRESS) { - - rv = ogs_getaddrinfo(&addr, AF_UNSPEC, - node->data, ogs_sbi_self()->sbi_port, 0); - if (rv != OGS_OK) continue; - - nf_instance->ipv6[nf_instance->num_of_ipv6] = addr; - nf_instance->num_of_ipv6++; - } - } - - OpenAPI_list_for_each(NFProfile->nf_services, node) { - OpenAPI_nf_service_t *NFService = node->data; - OpenAPI_list_t *VersionList = NULL; - OpenAPI_list_t *IpEndPointList = NULL; - OpenAPI_list_t *AllowedNfTypeList = NULL; - OpenAPI_lnode_t *node2 = NULL; - - if (!NFService) continue; - if (!NFService->service_instance_id) continue; - if (!NFService->service_name) continue; - - VersionList = NFService->versions; - IpEndPointList = NFService->ip_end_points; - AllowedNfTypeList = NFService->allowed_nf_types; - - nf_service = ogs_sbi_nf_service_find_by_id(nf_instance, - NFService->service_instance_id); - if (!nf_service) { - nf_service = ogs_sbi_nf_service_add(nf_instance, - NFService->service_instance_id, - NFService->service_name, NFService->scheme); - ogs_assert(nf_service); + if (!NFProfile->nf_instance_id) { + ogs_error("No NFProfile.NFInstanceId"); + ogs_assert(true == + ogs_sbi_server_send_error( + stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + recvmsg, "No NFProfile.NFInstanceId", NULL)); + ogs_sbi_header_free(&header); + return false; } - ogs_sbi_nf_service_clear(nf_service); - - OpenAPI_list_for_each(VersionList, node2) { - OpenAPI_nf_service_version_t *NFServiceVersion = node2->data; - - if (!NFServiceVersion) continue; - - ogs_sbi_nf_service_add_version(nf_service, - NFServiceVersion->api_version_in_uri, - NFServiceVersion->api_full_version, - NFServiceVersion->expiry); + if (!NFProfile->nf_type) { + ogs_error("No NFProfile.NFType"); + ogs_assert(true == + ogs_sbi_server_send_error( + stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + recvmsg, "No NFProfile.NFType", NULL)); + ogs_sbi_header_free(&header); + return false; } - if (NFService->fqdn) { -#if SBI_FQDN_WITH_ONE_OCTET_LENGTH - if (ogs_fqdn_parse( - fqdn, NFService->fqdn, - ogs_min(strlen(NFService->fqdn), OGS_MAX_FQDN_LEN)) > 0) { + if (!NFProfile->nf_status) { + ogs_error("No NFProfile.NFStatus"); + ogs_assert(true == + ogs_sbi_server_send_error( + stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + recvmsg, "No NFProfile.NFStatus", NULL)); + ogs_sbi_header_free(&header); + return false; + } - /* Nothing : succeeded to parse FQDN */ - nf_service->fqdn = ogs_strdup(fqdn); - ogs_assert(nf_service); + nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); + if (!nf_instance) { + nf_instance = ogs_sbi_nf_instance_add(); + ogs_assert(nf_instance); + ogs_sbi_nf_instance_set_id( + nf_instance, message.h.resource.component[1]); + ogs_sbi_nf_fsm_init(nf_instance); + + ogs_info("[%s] (NRF-notify) NF registered", nf_instance->id); + } else { + ogs_sbi_nf_fsm_tran(nf_instance, ogs_sbi_nf_state_registered); + + ogs_warn("[%s] (NRF-notify) NF has already been added", + message.h.resource.component[1]); + } + + ogs_sbi_nnrf_handle_nf_profile(nf_instance, NFProfile, stream, recvmsg); + + ogs_info("[%s] (NRF-notify) NF Profile updated", nf_instance->id); + + ogs_sbi_client_associate(nf_instance); + + } else if (NotificationData->event == + OpenAPI_notification_event_type_NF_DEREGISTERED) { + nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); + if (nf_instance) { + if (OGS_OBJECT_IS_REF(nf_instance)) { + /* There are references to other contexts. */ + ogs_warn("[%s:%d] NF was referenced in other contexts", + nf_instance->id, nf_instance->reference_count); + ogs_sbi_nf_fsm_tran( + nf_instance, ogs_sbi_nf_state_de_registered); } else { - ogs_error("ogs_fqdn_parse() failed[%s]", NFService->fqdn); - return false; + ogs_info("[%s] NF removed", nf_instance->id); + ogs_sbi_nf_fsm_fini((nf_instance)); + ogs_sbi_nf_instance_remove(nf_instance); } -#else - nf_service->fqdn = ogs_strdup(NFService->fqdn); - ogs_assert(nf_service); -#endif + } else { + ogs_warn("[%s] (NRF-notify) Not found", + message.h.resource.component[1]); + ogs_assert(true == + ogs_sbi_server_send_error(stream, + OGS_SBI_HTTP_STATUS_NOT_FOUND, + recvmsg, "Not found", message.h.resource.component[1])); + ogs_sbi_header_free(&header); + return false; } - - OpenAPI_list_for_each(IpEndPointList, node2) { - OpenAPI_ip_end_point_t *IpEndPoint = node2->data; - ogs_sockaddr_t *addr = NULL, *addr6 = NULL; - int port = 0; - - if (!IpEndPoint) continue; - - if (nf_service->num_of_addr < OGS_SBI_MAX_NUM_OF_IP_ADDRESS) { - if (!IpEndPoint->is_port) { - if (nf_service->scheme == OpenAPI_uri_scheme_http) - port = OGS_SBI_HTTP_PORT; - else if (nf_service->scheme == OpenAPI_uri_scheme_https) - port = OGS_SBI_HTTPS_PORT; - else - continue; - } else { - port = IpEndPoint->port; - } - - if (IpEndPoint->ipv4_address) { - rv = ogs_getaddrinfo(&addr, AF_UNSPEC, - IpEndPoint->ipv4_address, port, 0); - if (rv != OGS_OK) continue; - } - if (IpEndPoint->ipv6_address) { - rv = ogs_getaddrinfo(&addr6, AF_UNSPEC, - IpEndPoint->ipv6_address, port, 0); - if (rv != OGS_OK) continue; - } - - if (addr || addr6) { - nf_service->addr[nf_service->num_of_addr]. - port = port; - nf_service->addr[nf_service->num_of_addr]. - ipv4 = addr; - nf_service->addr[nf_service->num_of_addr]. - ipv6 = addr6; - nf_service->num_of_addr++; - } - } - } - - OpenAPI_list_for_each(AllowedNfTypeList, node2) { - OpenAPI_nf_type_e AllowedNfType = (uintptr_t)node2->data; - - if (!AllowedNfType) continue; - - if (nf_service->num_of_allowed_nf_type < - OGS_SBI_MAX_NUM_OF_NF_TYPE) { - nf_service->allowed_nf_types[ - nf_service->num_of_allowed_nf_type] = AllowedNfType; - nf_service->num_of_allowed_nf_type++; - } - } - - if (NFService->is_priority == true) - nf_service->priority = NFService->priority; - if (NFService->is_capacity == true) - nf_service->capacity = NFService->capacity; - if (NFService->is_load == true) - nf_service->load = NFService->load; + } else { + char *eventstr = OpenAPI_notification_event_type_ToString( + NotificationData->event); + ogs_error("Not supported event [%d:%s]", + NotificationData->event, eventstr ? eventstr : "Unknown"); + ogs_assert(true == + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + recvmsg, "Not supported event", + eventstr ? eventstr : "Unknown")); + ogs_sbi_header_free(&header); + return false; } - ogs_sbi_nf_info_remove_all(&nf_instance->nf_info_list); - - if (NFProfile->smf_info) - handle_smf_info(nf_instance, NFProfile->smf_info); - - OpenAPI_list_for_each(NFProfile->smf_info_list, node) { - OpenAPI_map_t *SmfInfoMap = node->data; - if (SmfInfoMap && SmfInfoMap->value) - handle_smf_info(nf_instance, SmfInfoMap->value); - } + response = ogs_sbi_build_response(recvmsg, OGS_SBI_HTTP_STATUS_NO_CONTENT); + ogs_assert(response); + ogs_assert(true == ogs_sbi_server_send_response(stream, response)); + ogs_sbi_header_free(&header); return true; } + +void ogs_nnrf_handle_nf_discover_search_result( + ogs_sbi_object_t *sbi_object, + OpenAPI_nf_type_e target_nf_type, + ogs_sbi_discovery_option_t *discovery_option, + OpenAPI_search_result_t *SearchResult) +{ + OpenAPI_lnode_t *node = NULL; + ogs_sbi_nf_instance_t *nf_instance = NULL; + + ogs_assert(sbi_object); + ogs_assert(SearchResult); + + OpenAPI_list_for_each(SearchResult->nf_instances, node) { + OpenAPI_nf_profile_t *NFProfile = NULL; + + if (!node->data) continue; + + NFProfile = node->data; + + if (!NFProfile) { + ogs_error("No NFProfile"); + continue; + } + + if (!NFProfile->nf_instance_id) { + ogs_error("No NFProfile.NFInstanceId"); + continue; + } + + if (!NFProfile->nf_type) { + ogs_error("No NFProfile.NFType"); + continue; + } + + if (!NFProfile->nf_status) { + ogs_error("No NFProfile.NFStatus"); + continue; + } + + nf_instance = ogs_sbi_nf_instance_find(NFProfile->nf_instance_id); + if (!nf_instance) { + nf_instance = ogs_sbi_nf_instance_add(); + ogs_assert(nf_instance); + + ogs_sbi_nf_instance_set_id(nf_instance, NFProfile->nf_instance_id); + ogs_sbi_nf_fsm_init(nf_instance); + + ogs_info("[%s] (NF-discover) NF registered", nf_instance->id); + } else { + ogs_sbi_nf_fsm_tran(nf_instance, ogs_sbi_nf_state_registered); + + ogs_warn("[%s] (NF-discover) NF has already been added", + NFProfile->nf_instance_id); + } + + if (NF_INSTANCE_ID_IS_OTHERS(nf_instance->id)) { + ogs_sbi_nnrf_handle_nf_profile(nf_instance, NFProfile, NULL, NULL); + + ogs_sbi_client_associate(nf_instance); + + /* TIME : Update validity from NRF */ + if (SearchResult->is_validity_period && + SearchResult->validity_period) { + nf_instance->time.validity_duration = + SearchResult->validity_period; + + ogs_assert(nf_instance->t_validity); + ogs_timer_start(nf_instance->t_validity, + ogs_time_from_sec(nf_instance->time.validity_duration)); + + } else + ogs_warn("[%s] NF Instance validity-time should not 0", + nf_instance->id); + + ogs_info("[%s] (NF-discover) NF Profile updated", nf_instance->id); + } + } +} diff --git a/lib/sbi/nnrf-handler.h b/lib/sbi/nnrf-handler.h index 4a09aa78c..c3f135ef4 100644 --- a/lib/sbi/nnrf-handler.h +++ b/lib/sbi/nnrf-handler.h @@ -24,10 +24,23 @@ extern "C" { #endif -bool ogs_sbi_nnrf_handle_nf_profile(ogs_sbi_nf_instance_t *nf_instance, +void ogs_sbi_nnrf_handle_nf_register( + ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_message_t *recvmsg); +void ogs_sbi_nnrf_handle_nf_profile(ogs_sbi_nf_instance_t *nf_instance, OpenAPI_nf_profile_t *NFProfile, ogs_sbi_stream_t *stream, ogs_sbi_message_t *message); +void ogs_nnrf_handle_nf_status_subscribe( + ogs_sbi_subscription_t *subscription, ogs_sbi_message_t *recvmsg); +bool ogs_nnrf_handle_nf_status_notify( + ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); + +void ogs_nnrf_handle_nf_discover_search_result( + ogs_sbi_object_t *sbi_object, + OpenAPI_nf_type_e target_nf_type, + ogs_sbi_discovery_option_t *discovery_option, + OpenAPI_search_result_t *SearchResult); + #ifdef __cplusplus } #endif diff --git a/lib/sbi/ogs-sbi.h b/lib/sbi/ogs-sbi.h index d1d62c0d0..12800fa4b 100644 --- a/lib/sbi/ogs-sbi.h +++ b/lib/sbi/ogs-sbi.h @@ -20,7 +20,7 @@ #ifndef OGS_SBI_H #define OGS_SBI_H -#include "ogs-core.h" +#include "ogs-proto.h" #if defined(__GNUC__) #pragma GCC diagnostic push @@ -86,12 +86,15 @@ #define OGS_SBI_INSIDE #include "sbi/conv.h" +#include "sbi/timer.h" #include "sbi/message.h" #include "sbi/server.h" #include "sbi/client.h" #include "sbi/context.h" +#include "sbi/nf-sm.h" + #include "sbi/nnrf-build.h" #include "sbi/nnrf-handler.h" diff --git a/lib/sbi/path.c b/lib/sbi/path.c index fff71596b..5a8305556 100644 --- a/lib/sbi/path.c +++ b/lib/sbi/path.c @@ -124,8 +124,7 @@ bool ogs_sbi_discover_and_send( return false; } -bool ogs_nnrf_nfm_send_nf_register( - ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_request_t *(*build)(void)) +bool ogs_nnrf_nfm_send_nf_register(ogs_sbi_nf_instance_t *nf_instance) { ogs_sbi_request_t *request = NULL; ogs_sbi_client_t *client = NULL; @@ -133,9 +132,8 @@ bool ogs_nnrf_nfm_send_nf_register( ogs_assert(nf_instance); client = nf_instance->client; ogs_assert(client); - ogs_assert(build); - request = (*build)(); + request = ogs_nnrf_nfm_build_register(); ogs_expect_or_return_val(request, false); return ogs_sbi_scp_send_request(client, client->cb, request, nf_instance); diff --git a/lib/sbi/path.h b/lib/sbi/path.h index 6ba2d092a..ab022d7b8 100644 --- a/lib/sbi/path.h +++ b/lib/sbi/path.h @@ -35,8 +35,7 @@ bool ogs_sbi_discover_and_send( ogs_sbi_discovery_option_t *discovery_option, ogs_sbi_client_cb_f client_cb, void *data); -bool ogs_nnrf_nfm_send_nf_register( - ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_request_t *(*build)(void)); +bool ogs_nnrf_nfm_send_nf_register(ogs_sbi_nf_instance_t *nf_instance); bool ogs_nnrf_nfm_send_nf_update(ogs_sbi_nf_instance_t *nf_instance); bool ogs_nnrf_nfm_send_nf_de_register(ogs_sbi_nf_instance_t *nf_instance); bool ogs_nnrf_nfm_send_nf_profile_retrieve(ogs_sbi_nf_instance_t *nf_instance, diff --git a/lib/sbi/timer.c b/lib/sbi/timer.c new file mode 100644 index 000000000..749627c3e --- /dev/null +++ b/lib/sbi/timer.c @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2019-2022 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-sbi.h" +#include "ogs-app.h" + +static void timer_send_event(int timer_id, void *data) +{ + int rv; + ogs_event_t *e = NULL; + ogs_assert(data); + + switch (timer_id) { + case OGS_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: + case OGS_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: + case OGS_TIMER_NF_INSTANCE_NO_HEARTBEAT: + case OGS_TIMER_NF_INSTANCE_VALIDITY: + case OGS_TIMER_SUBSCRIPTION_VALIDITY: + case OGS_TIMER_SBI_CLIENT_WAIT: + e = ogs_event_new(OGS_EVENT_SBI_TIMER); + ogs_assert(e); + e->timer_id = timer_id; + e->sbi.data = data; + break; + default: + ogs_fatal("Unknown timer id[%d]", timer_id); + ogs_assert_if_reached(); + break; + } + + rv = ogs_queue_push(ogs_app()->queue, e); + if (rv != OGS_OK) { + ogs_error("ogs_queue_push() failed [%d] in %s", + (int)rv, ogs_timer_get_name(e->timer_id)); + ogs_event_free(e); + } +} + +void ogs_timer_nf_instance_registration_interval(void *data) +{ + timer_send_event(OGS_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL, data); +} + +void ogs_timer_nf_instance_heartbeat_interval(void *data) +{ + timer_send_event(OGS_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL, data); +} + +void ogs_timer_nf_instance_no_heartbeat(void *data) +{ + timer_send_event(OGS_TIMER_NF_INSTANCE_NO_HEARTBEAT, data); +} + +void ogs_timer_nf_instance_validity(void *data) +{ + timer_send_event(OGS_TIMER_NF_INSTANCE_VALIDITY, data); +} + +void ogs_timer_subscription_validity(void *data) +{ + timer_send_event(OGS_TIMER_SUBSCRIPTION_VALIDITY, data); +} + +void ogs_timer_sbi_client_wait_expire(void *data) +{ + timer_send_event(OGS_TIMER_SBI_CLIENT_WAIT, data); +} diff --git a/src/nssf/nnrf-handler.h b/lib/sbi/timer.h similarity index 57% rename from src/nssf/nnrf-handler.h rename to lib/sbi/timer.h index fb0e15479..c6e03814b 100644 --- a/src/nssf/nnrf-handler.h +++ b/lib/sbi/timer.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -17,25 +17,26 @@ * along with this program. If not, see . */ -#ifndef NSSF_NNRF_HANDLER_H -#define NSSF_NNRF_HANDLER_H +#if !defined(OGS_SBI_INSIDE) && !defined(OGS_SBI_COMPILATION) +#error "This header cannot be included directly." +#endif -#include "context.h" +#ifndef OGS_SBI_TIMER_H +#define OGS_SBI_TIMER_H #ifdef __cplusplus extern "C" { #endif -void nssf_nnrf_handle_nf_register( - ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_message_t *recvmsg); -void nssf_nnrf_handle_nf_status_subscribe( - ogs_sbi_subscription_t *subscription, ogs_sbi_message_t *recvmsg); - -bool nssf_nnrf_handle_nf_status_notify( - ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); +void ogs_timer_nf_instance_registration_interval(void *data); +void ogs_timer_nf_instance_heartbeat_interval(void *data); +void ogs_timer_nf_instance_no_heartbeat(void *data); +void ogs_timer_nf_instance_validity(void *data); +void ogs_timer_subscription_validity(void *data); +void ogs_timer_sbi_client_wait_expire(void *data); #ifdef __cplusplus } #endif -#endif /* NSSF_NNRF_HANDLER_H */ +#endif /* OGS_SBI_TIMER_H */ diff --git a/lib/tun/meson.build b/lib/tun/meson.build index c2eb5bf68..c12eb2569 100644 --- a/lib/tun/meson.build +++ b/lib/tun/meson.build @@ -36,10 +36,10 @@ libtun = library('ogstun', version : libogslib_version, c_args : '-DOGS_TUN_COMPILATION', include_directories : [libtun_inc, libinc], - dependencies : [libcore_dep, libipfw_dep], + dependencies : libipfw_dep, install : true) libtun_dep = declare_dependency( link_with : libtun, include_directories : [libtun_inc, libinc], - dependencies : [libcore_dep, libipfw_dep]) + dependencies : libipfw_dep) diff --git a/lib/tun/ogs-tun.h b/lib/tun/ogs-tun.h index 8c6fc0fd8..df7386865 100644 --- a/lib/tun/ogs-tun.h +++ b/lib/tun/ogs-tun.h @@ -20,7 +20,7 @@ #ifndef OGS_TUN_H #define OGS_TUN_H -#include "ogs-core.h" +#include "ogs-proto.h" #ifdef __cplusplus extern "C" { diff --git a/src/amf/amf-sm.c b/src/amf/amf-sm.c index 173ee053c..b6f0c1c72 100644 --- a/src/amf/amf-sm.c +++ b/src/amf/amf-sm.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -79,17 +79,17 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) ogs_assert(s); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: break; case OGS_FSM_EXIT_SIG: break; - case AMF_EVT_SBI_SERVER: - sbi_request = e->sbi.request; + case OGS_EVENT_SBI_SERVER: + sbi_request = e->h.sbi.request; ogs_assert(sbi_request); - stream = e->sbi.data; + stream = e->h.sbi.data; ogs_assert(stream); rv = ogs_sbi_parse_request(&sbi_message, sbi_request); @@ -129,7 +129,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) CASE(OGS_SBI_RESOURCE_NAME_NF_STATUS_NOTIFY) SWITCH(sbi_message.h.method) CASE(OGS_SBI_HTTP_METHOD_POST) - amf_nnrf_handle_nf_status_notify(stream, &sbi_message); + ogs_nnrf_handle_nf_status_notify(stream, &sbi_message); break; DEFAULT @@ -240,10 +240,10 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) ogs_sbi_message_free(&sbi_message); break; - case AMF_EVT_SBI_CLIENT: + case OGS_EVENT_SBI_CLIENT: ogs_assert(e); - sbi_response = e->sbi.response; + sbi_response = e->h.sbi.response; ogs_assert(sbi_response); rv = ogs_sbi_parse_response(&sbi_message, sbi_response); if (rv != OGS_OK) { @@ -275,23 +275,23 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) SWITCH(sbi_message.h.resource.component[0]) CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - nf_instance = e->sbi.data; + nf_instance = e->h.sbi.data; ogs_assert(nf_instance); ogs_assert(OGS_FSM_STATE(&nf_instance->sm)); - e->sbi.message = &sbi_message; + e->h.sbi.message = &sbi_message; ogs_fsm_dispatch(&nf_instance->sm, e); break; CASE(OGS_SBI_RESOURCE_NAME_SUBSCRIPTIONS) - subscription = e->sbi.data; + subscription = e->h.sbi.data; ogs_assert(subscription); SWITCH(sbi_message.h.method) CASE(OGS_SBI_HTTP_METHOD_POST) if (sbi_message.res_status == OGS_SBI_HTTP_STATUS_CREATED || sbi_message.res_status == OGS_SBI_HTTP_STATUS_OK) { - amf_nnrf_handle_nf_status_subscribe( + ogs_nnrf_handle_nf_status_subscribe( subscription, &sbi_message); } else { ogs_error("[%s] HTTP response error [%d]", @@ -325,7 +325,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) CASE(OGS_SBI_SERVICE_NAME_NNRF_DISC) SWITCH(sbi_message.h.resource.component[0]) CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - sbi_xact = e->sbi.data; + sbi_xact = e->h.sbi.data; ogs_assert(sbi_xact); SWITCH(sbi_message.h.method) @@ -354,7 +354,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) CASE(OGS_SBI_SERVICE_NAME_NUDM_UECM) CASE(OGS_SBI_SERVICE_NAME_NUDM_SDM) CASE(OGS_SBI_SERVICE_NAME_NPCF_AM_POLICY_CONTROL) - sbi_xact = e->sbi.data; + sbi_xact = e->h.sbi.data; ogs_assert(sbi_xact); sbi_xact = ogs_sbi_xact_cycle(sbi_xact); @@ -376,7 +376,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) ogs_assert(OGS_FSM_STATE(&amf_ue->sm)); e->amf_ue = amf_ue; - e->sbi.message = &sbi_message;; + e->h.sbi.message = &sbi_message;; ogs_fsm_dispatch(&amf_ue->sm, e); } else { @@ -385,7 +385,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) break; CASE(OGS_SBI_SERVICE_NAME_NSMF_PDUSESSION) - sbi_xact = e->sbi.data; + sbi_xact = e->h.sbi.data; ogs_assert(sbi_xact); sbi_xact = ogs_sbi_xact_cycle(sbi_xact); @@ -449,7 +449,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) e->amf_ue = amf_ue; e->sess = sess; - e->sbi.message = &sbi_message;; + e->h.sbi.message = &sbi_message;; SWITCH(sbi_message.h.resource.component[2]) CASE(OGS_SBI_RESOURCE_NAME_MODIFY) @@ -502,7 +502,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) break; CASE(OGS_SBI_SERVICE_NAME_NNSSF_NSSELECTION) - sbi_xact = e->sbi.data; + sbi_xact = e->h.sbi.data; ogs_assert(sbi_xact); sbi_xact = ogs_sbi_xact_cycle(sbi_xact); @@ -535,7 +535,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) e->amf_ue = amf_ue; e->sess = sess; - e->sbi.message = &sbi_message;; + e->h.sbi.message = &sbi_message;; amf_nnssf_nsselection_handle_get(sess, &sbi_message); break; @@ -549,27 +549,27 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) ogs_sbi_response_free(sbi_response); break; - case AMF_EVT_SBI_TIMER: + case OGS_EVENT_SBI_TIMER: ogs_assert(e); - switch(e->timer_id) { - case AMF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - case AMF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - case AMF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - case AMF_TIMER_NF_INSTANCE_VALIDITY: - nf_instance = e->sbi.data; + switch(e->h.timer_id) { + case OGS_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: + case OGS_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: + case OGS_TIMER_NF_INSTANCE_NO_HEARTBEAT: + case OGS_TIMER_NF_INSTANCE_VALIDITY: + nf_instance = e->h.sbi.data; ogs_assert(nf_instance); ogs_assert(OGS_FSM_STATE(&nf_instance->sm)); ogs_fsm_dispatch(&nf_instance->sm, e); - if (OGS_FSM_CHECK(&nf_instance->sm, amf_nf_state_exception)) + if (OGS_FSM_CHECK(&nf_instance->sm, ogs_sbi_nf_state_exception)) ogs_error("[%s:%s] State machine exception [%d]", OpenAPI_nf_type_ToString(nf_instance->nf_type), - nf_instance->id, e->timer_id); + nf_instance->id, e->h.timer_id); break; - case AMF_TIMER_SUBSCRIPTION_VALIDITY: - subscription = e->sbi.data; + case OGS_TIMER_SUBSCRIPTION_VALIDITY: + subscription = e->h.sbi.data; ogs_assert(subscription); ogs_assert(ogs_sbi_self()->nf_instance); @@ -583,8 +583,8 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) ogs_sbi_subscription_remove(subscription); break; - case AMF_TIMER_SBI_CLIENT_WAIT: - sbi_xact = e->sbi.data; + case OGS_TIMER_SBI_CLIENT_WAIT: + sbi_xact = e->h.sbi.data; ogs_assert(sbi_xact); sbi_object = sbi_xact->sbi_object; @@ -647,11 +647,11 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) default: ogs_error("Unknown timer[%s:%d]", - amf_timer_get_name(e->timer_id), e->timer_id); + ogs_timer_get_name(e->h.timer_id), e->h.timer_id); } break; - case AMF_EVT_NGAP_LO_ACCEPT: + case AMF_EVENT_NGAP_LO_ACCEPT: sock = e->ngap.sock; ogs_assert(sock); addr = e->ngap.addr; @@ -674,7 +674,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) break; - case AMF_EVT_NGAP_LO_SCTP_COMM_UP: + case AMF_EVENT_NGAP_LO_SCTP_COMM_UP: sock = e->ngap.sock; ogs_assert(sock); addr = e->ngap.addr; @@ -701,7 +701,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) break; - case AMF_EVT_NGAP_LO_CONNREFUSED: + case AMF_EVENT_NGAP_LO_CONNREFUSED: sock = e->ngap.sock; ogs_assert(sock); addr = e->ngap.addr; @@ -720,7 +720,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) ogs_free(addr); break; - case AMF_EVT_NGAP_MESSAGE: + case AMF_EVENT_NGAP_MESSAGE: sock = e->ngap.sock; ogs_assert(sock); addr = e->ngap.addr; @@ -751,11 +751,11 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) ogs_pkbuf_free(pkbuf); break; - case AMF_EVT_NGAP_TIMER: + case AMF_EVENT_NGAP_TIMER: ran_ue = e->ran_ue; ogs_assert(ran_ue); - switch (e->timer_id) { + switch (e->h.timer_id) { case AMF_TIMER_NG_DELAYED_SEND: gnb = e->gnb; ogs_assert(gnb); @@ -774,12 +774,12 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) break; default: ogs_error("Unknown timer[%s:%d]", - amf_timer_get_name(e->timer_id), e->timer_id); + amf_timer_get_name(e->h.timer_id), e->h.timer_id); break; } break; - case AMF_EVT_5GMM_MESSAGE: + case AMF_EVENT_5GMM_MESSAGE: ran_ue = e->ran_ue; ogs_assert(ran_ue); pkbuf = e->pkbuf; @@ -867,7 +867,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) ogs_pkbuf_free(pkbuf); break; - case AMF_EVT_5GMM_TIMER: + case AMF_EVENT_5GMM_TIMER: amf_ue = e->amf_ue; ogs_assert(amf_ue); ogs_assert(OGS_FSM_STATE(&amf_ue->sm)); diff --git a/src/amf/amf-sm.h b/src/amf/amf-sm.h index f98a54cf9..81f214aff 100644 --- a/src/amf/amf-sm.h +++ b/src/amf/amf-sm.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -30,16 +30,6 @@ void amf_state_initial(ogs_fsm_t *s, amf_event_t *e); void amf_state_final(ogs_fsm_t *s, amf_event_t *e); void amf_state_operational(ogs_fsm_t *s, amf_event_t *e); -void amf_nf_fsm_init(ogs_sbi_nf_instance_t *nf_instance); -void amf_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance); - -void amf_nf_state_initial(ogs_fsm_t *s, amf_event_t *e); -void amf_nf_state_final(ogs_fsm_t *s, amf_event_t *e); -void amf_nf_state_will_register(ogs_fsm_t *s, amf_event_t *e); -void amf_nf_state_registered(ogs_fsm_t *s, amf_event_t *e); -void amf_nf_state_de_registered(ogs_fsm_t *s, amf_event_t *e); -void amf_nf_state_exception(ogs_fsm_t *s, amf_event_t *e); - void ngap_state_initial(ogs_fsm_t *s, amf_event_t *e); void ngap_state_final(ogs_fsm_t *s, amf_event_t *e); void ngap_state_operational(ogs_fsm_t *s, amf_event_t *e); diff --git a/src/amf/context.c b/src/amf/context.c index 92cf2942a..953d414d2 100644 --- a/src/amf/context.c +++ b/src/amf/context.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -870,8 +870,7 @@ amf_gnb_t *amf_gnb_add(ogs_sock_t *sock, ogs_sockaddr_t *addr) memset(&e, 0, sizeof(e)); e.gnb = gnb; - ogs_fsm_create(&gnb->sm, ngap_state_initial, ngap_state_final); - ogs_fsm_init(&gnb->sm, &e); + ogs_fsm_init(&gnb->sm, ngap_state_initial, ngap_state_final, &e); ogs_list_add(&self.gnb_list, gnb); amf_metrics_inst_global_inc(AMF_METR_GLOB_GAUGE_GNB); @@ -894,7 +893,6 @@ void amf_gnb_remove(amf_gnb_t *gnb) memset(&e, 0, sizeof(e)); e.gnb = gnb; ogs_fsm_fini(&gnb->sm, &e); - ogs_fsm_delete(&gnb->sm); ogs_hash_set(self.gnb_addr_hash, gnb->sctp.addr, sizeof(ogs_sockaddr_t), NULL); @@ -1311,8 +1309,7 @@ void amf_ue_fsm_init(amf_ue_t *amf_ue) memset(&e, 0, sizeof(e)); e.amf_ue = amf_ue; - ogs_fsm_create(&amf_ue->sm, gmm_state_initial, gmm_state_final); - ogs_fsm_init(&amf_ue->sm, &e); + ogs_fsm_init(&amf_ue->sm, gmm_state_initial, gmm_state_final, &e); } void amf_ue_fsm_fini(amf_ue_t *amf_ue) @@ -1324,7 +1321,6 @@ void amf_ue_fsm_fini(amf_ue_t *amf_ue) memset(&e, 0, sizeof(e)); e.amf_ue = amf_ue; ogs_fsm_fini(&amf_ue->sm, &e); - ogs_fsm_delete(&amf_ue->sm); } amf_ue_t *amf_ue_find_by_guti(ogs_nas_5gs_guti_t *guti) @@ -1792,7 +1788,6 @@ void amf_sbi_select_nf( ogs_sbi_nf_instance_t *nf_instance = NULL; amf_sess_t *sess = NULL; - ogs_assert(ogs_sbi_self()->nf_state_registered); ogs_assert(sbi_object); ogs_assert(target_nf_type); diff --git a/src/amf/context.h b/src/amf/context.h index bd08d7bdc..d70b8a1aa 100644 --- a/src/amf/context.h +++ b/src/amf/context.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -197,22 +197,6 @@ struct ran_ue_s { amf_ue_t *amf_ue; }; -#define AMF_NF_INSTANCE_CLEAR(_cAUSE, _nFInstance) \ - do { \ - ogs_assert(_nFInstance); \ - if ((_nFInstance)->reference_count == 1) { \ - ogs_info("[%s] (%s) NF removed", (_nFInstance)->id, (_cAUSE)); \ - amf_nf_fsm_fini((_nFInstance)); \ - ogs_sbi_nf_instance_remove(_nFInstance); \ - } else { \ - /* There is an assocation with other context */ \ - ogs_info("[%s:%d] (%s) NF suspended", \ - _nFInstance->id, _nFInstance->reference_count, (_cAUSE)); \ - OGS_FSM_TRAN(&_nFInstance->sm, amf_nf_state_de_registered); \ - ogs_fsm_dispatch(&_nFInstance->sm, NULL); \ - } \ - } while(0) - struct amf_ue_s { ogs_sbi_object_t sbi; ogs_fsm_t sm; diff --git a/src/amf/event.c b/src/amf/event.c index 838e63c9b..a920f6160 100644 --- a/src/amf/event.c +++ b/src/amf/event.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -20,90 +20,66 @@ #include "event.h" #include "context.h" -static OGS_POOL(pool, amf_event_t); -static ogs_thread_mutex_t amf_event_alloc_mutex; - -void amf_event_init(void) -{ - ogs_pool_init(&pool, ogs_app()->pool.event); - ogs_thread_mutex_init(&amf_event_alloc_mutex); -} - -void amf_event_final(void) -{ - ogs_pool_final(&pool); - ogs_thread_mutex_destroy(&amf_event_alloc_mutex); -} - -amf_event_t *amf_event_new(amf_event_e id) +amf_event_t *amf_event_new(int id) { amf_event_t *e = NULL; - ogs_thread_mutex_lock(&amf_event_alloc_mutex); - ogs_pool_alloc(&pool, &e); - ogs_thread_mutex_unlock(&amf_event_alloc_mutex); + e = ogs_event_size(id, sizeof(amf_event_t)); ogs_assert(e); - memset(e, 0, sizeof(*e)); - e->id = id; + e->h.id = id; return e; } -void amf_event_free(amf_event_t *e) -{ - ogs_assert(e); - ogs_thread_mutex_lock(&amf_event_alloc_mutex); - ogs_pool_free(&pool, e); - ogs_thread_mutex_unlock(&amf_event_alloc_mutex); -} - const char *amf_event_get_name(amf_event_t *e) { - if (e == NULL) + if (e == NULL) { return OGS_FSM_NAME_INIT_SIG; - - switch (e->id) { - case OGS_FSM_ENTRY_SIG: - return OGS_FSM_NAME_ENTRY_SIG; - case OGS_FSM_EXIT_SIG: - return OGS_FSM_NAME_EXIT_SIG; - - case AMF_EVT_SBI_SERVER: - return "AMF_EVT_SBI_SERVER"; - case AMF_EVT_SBI_CLIENT: - return "AMF_EVT_SBI_CLIENT"; - case AMF_EVT_SBI_TIMER: - return "AMF_EVT_SBI_TIMER"; - - case AMF_EVT_NGAP_MESSAGE: - return "AMF_EVT_NGAP_MESSAGE"; - case AMF_EVT_NGAP_TIMER: - return "AMF_EVT_NGAP_TIMER"; - case AMF_EVT_NGAP_LO_ACCEPT: - return "AMF_EVT_NGAP_LO_ACCEPT"; - case AMF_EVT_NGAP_LO_SCTP_COMM_UP: - return "AMF_EVT_NGAP_LO_SCTP_COMM_UP"; - case AMF_EVT_NGAP_LO_CONNREFUSED: - return "AMF_EVT_NGAP_LO_CONNREFUSED"; - - case AMF_EVT_5GMM_MESSAGE: - return "AMF_EVT_5GMM_MESSAGE"; - case AMF_EVT_5GMM_TIMER: - return "AMF_EVT_5GMM_TIMER"; - case AMF_EVT_5GSM_MESSAGE: - return "AMF_EVT_5GSM_MESSAGE"; - case AMF_EVT_5GSM_TIMER: - return "AMF_EVT_5GSM_TIMER"; - - default: - break; } + switch (e->h.id) { + case OGS_FSM_ENTRY_SIG: + return OGS_FSM_NAME_ENTRY_SIG; + case OGS_FSM_EXIT_SIG: + return OGS_FSM_NAME_EXIT_SIG; + + case OGS_EVENT_SBI_SERVER: + return OGS_EVENT_NAME_SBI_SERVER; + case OGS_EVENT_SBI_CLIENT: + return OGS_EVENT_NAME_SBI_CLIENT; + case OGS_EVENT_SBI_TIMER: + return OGS_EVENT_NAME_SBI_TIMER; + + case AMF_EVENT_NGAP_MESSAGE: + return "AMF_EVENT_NGAP_MESSAGE"; + case AMF_EVENT_NGAP_TIMER: + return "AMF_EVENT_NGAP_TIMER"; + case AMF_EVENT_NGAP_LO_ACCEPT: + return "AMF_EVENT_NGAP_LO_ACCEPT"; + case AMF_EVENT_NGAP_LO_SCTP_COMM_UP: + return "AMF_EVENT_NGAP_LO_SCTP_COMM_UP"; + case AMF_EVENT_NGAP_LO_CONNREFUSED: + return "AMF_EVENT_NGAP_LO_CONNREFUSED"; + + case AMF_EVENT_5GMM_MESSAGE: + return "AMF_EVENT_5GMM_MESSAGE"; + case AMF_EVENT_5GMM_TIMER: + return "AMF_EVENT_5GMM_TIMER"; + case AMF_EVENT_5GSM_MESSAGE: + return "AMF_EVENT_5GSM_MESSAGE"; + case AMF_EVENT_5GSM_TIMER: + return "AMF_EVENT_5GSM_TIMER"; + + default: + break; + } + + ogs_error("Unknown Event[%d]", e->h.id); return "UNKNOWN_EVENT"; } -void amf_sctp_event_push(amf_event_e id, +void amf_sctp_event_push(int id, void *sock, ogs_sockaddr_t *addr, ogs_pkbuf_t *pkbuf, uint16_t max_num_of_istreams, uint16_t max_num_of_ostreams) { @@ -130,7 +106,7 @@ void amf_sctp_event_push(amf_event_e id, ogs_free(e->ngap.addr); if (e->pkbuf) ogs_pkbuf_free(e->pkbuf); - amf_event_free(e); + ogs_event_free(e); } #if HAVE_USRSCTP else { diff --git a/src/amf/event.h b/src/amf/event.h index f4535905b..15091c3a0 100644 --- a/src/amf/event.h +++ b/src/amf/event.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -20,18 +20,12 @@ #ifndef AMF_EVENT_H #define AMF_EVENT_H -#include "ogs-core.h" +#include "ogs-proto.h" #ifdef __cplusplus extern "C" { #endif -typedef struct ogs_sbi_request_s ogs_sbi_request_t; -typedef struct ogs_sbi_response_s ogs_sbi_response_t; -typedef struct ogs_sbi_message_s ogs_sbi_message_t; -typedef struct ogs_sbi_nf_instance_s ogs_sbi_nf_instance_t; -typedef struct ogs_sbi_subscription_s ogs_sbi_subscription_t; - typedef struct ogs_nas_5gs_message_s ogs_nas_5gs_message_t; typedef struct NGAP_NGAP_PDU ogs_ngap_message_t; typedef long NGAP_ProcedureCode_t; @@ -43,39 +37,27 @@ typedef struct amf_sess_s amf_sess_t; typedef struct amf_bearer_s amf_bearer_t; typedef enum { - AMF_EVT_BASE = OGS_FSM_USER_SIG, + AMF_EVENT_BASE = OGS_MAX_NUM_OF_PROTO_EVENT, - AMF_EVT_SBI_SERVER, - AMF_EVT_SBI_CLIENT, - AMF_EVT_SBI_TIMER, + AMF_EVENT_NGAP_MESSAGE, + AMF_EVENT_NGAP_TIMER, + AMF_EVENT_NGAP_LO_ACCEPT, + AMF_EVENT_NGAP_LO_SCTP_COMM_UP, + AMF_EVENT_NGAP_LO_CONNREFUSED, - AMF_EVT_NGAP_MESSAGE, - AMF_EVT_NGAP_TIMER, - AMF_EVT_NGAP_LO_ACCEPT, - AMF_EVT_NGAP_LO_SCTP_COMM_UP, - AMF_EVT_NGAP_LO_CONNREFUSED, + AMF_EVENT_5GMM_MESSAGE, + AMF_EVENT_5GMM_TIMER, + AMF_EVENT_5GSM_MESSAGE, + AMF_EVENT_5GSM_TIMER, - AMF_EVT_5GMM_MESSAGE, - AMF_EVT_5GMM_TIMER, - AMF_EVT_5GSM_MESSAGE, - AMF_EVT_5GSM_TIMER, - - AMF_EVT_TOP, + MAX_NUM_OF_AMF_EVENT, } amf_event_e; typedef struct amf_event_s { - int id; + ogs_event_t h; + ogs_pkbuf_t *pkbuf; - int timer_id; - - struct { - ogs_sbi_request_t *request; - ogs_sbi_response_t *response; - void *data; - - ogs_sbi_message_t *message; - } sbi; struct { ogs_sock_t *sock; @@ -101,15 +83,11 @@ typedef struct amf_event_s { ogs_timer_t *timer; } amf_event_t; -void amf_event_init(void); -void amf_event_final(void); - -amf_event_t *amf_event_new(amf_event_e id); -void amf_event_free(amf_event_t *e); +amf_event_t *amf_event_new(int id); const char *amf_event_get_name(amf_event_t *e); -void amf_sctp_event_push(amf_event_e id, +void amf_sctp_event_push(int id, void *sock, ogs_sockaddr_t *addr, ogs_pkbuf_t *pkbuf, uint16_t max_num_of_istreams, uint16_t max_num_of_ostreams); diff --git a/src/amf/gmm-sm.c b/src/amf/gmm-sm.c index fad56b944..c7be6a75a 100644 --- a/src/amf/gmm-sm.c +++ b/src/amf/gmm-sm.c @@ -62,7 +62,7 @@ void gmm_state_de_registered(ogs_fsm_t *s, amf_event_t *e) amf_ue = e->amf_ue; ogs_assert(amf_ue); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: AMF_UE_CLEAR_PAGING_INFO(amf_ue); AMF_UE_CLEAR_N2_TRANSFER(amf_ue, pdu_session_resource_setup_request); @@ -113,13 +113,13 @@ static void common_register_state(ogs_fsm_t *s, amf_event_t *e) ogs_assert(amf_ue); } - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: break; case OGS_FSM_EXIT_SIG: break; - case AMF_EVT_5GMM_MESSAGE: + case AMF_EVENT_5GMM_MESSAGE: nas_message = e->nas.message; ogs_assert(nas_message); @@ -367,8 +367,8 @@ static void common_register_state(ogs_fsm_t *s, amf_event_t *e) } break; - case AMF_EVT_5GMM_TIMER: - switch (e->timer_id) { + case AMF_EVENT_5GMM_TIMER: + switch (e->h.timer_id) { case AMF_TIMER_T3513: if (amf_ue->t3513.retry_count >= amf_timer_cfg(AMF_TIMER_T3513)->max_count) { @@ -457,14 +457,14 @@ static void common_register_state(ogs_fsm_t *s, amf_event_t *e) default: ogs_error("Unknown timer[%s:%d]", - amf_timer_get_name(e->timer_id), e->timer_id); + amf_timer_get_name(e->h.timer_id), e->h.timer_id); } break; - case AMF_EVT_SBI_CLIENT: - sbi_response = e->sbi.response; + case OGS_EVENT_SBI_CLIENT: + sbi_response = e->h.sbi.response; ogs_assert(sbi_response); - sbi_message = e->sbi.message; + sbi_message = e->h.sbi.message; ogs_assert(sbi_message); SWITCH(sbi_message->h.service.name) @@ -536,12 +536,12 @@ void gmm_state_authentication(ogs_fsm_t *s, amf_event_t *e) ogs_assert(amf_ue); } - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: break; case OGS_FSM_EXIT_SIG: break; - case AMF_EVT_5GMM_MESSAGE: + case AMF_EVENT_5GMM_MESSAGE: nas_message = e->nas.message; ogs_assert(nas_message); @@ -651,8 +651,8 @@ void gmm_state_authentication(ogs_fsm_t *s, amf_event_t *e) break; } break; - case AMF_EVT_5GMM_TIMER: - switch (e->timer_id) { + case AMF_EVENT_5GMM_TIMER: + switch (e->h.timer_id) { case AMF_TIMER_T3560: if (amf_ue->t3560.retry_count >= amf_timer_cfg(AMF_TIMER_T3560)->max_count) { @@ -673,14 +673,14 @@ void gmm_state_authentication(ogs_fsm_t *s, amf_event_t *e) break; default: ogs_error("[%s] Unknown timer[%s:%d]", amf_ue->suci, - amf_timer_get_name(e->timer_id), e->timer_id); + amf_timer_get_name(e->h.timer_id), e->h.timer_id); break; } break; - case AMF_EVT_SBI_CLIENT: - sbi_response = e->sbi.response; + case OGS_EVENT_SBI_CLIENT: + sbi_response = e->h.sbi.response; ogs_assert(sbi_response); - sbi_message = e->sbi.message; + sbi_message = e->h.sbi.message; ogs_assert(sbi_message); SWITCH(sbi_message->h.service.name) @@ -772,7 +772,7 @@ void gmm_state_security_mode(ogs_fsm_t *s, amf_event_t *e) amf_ue = e->amf_ue; ogs_assert(amf_ue); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: CLEAR_AMF_UE_TIMER(amf_ue->t3560); ogs_assert(OGS_OK == @@ -780,7 +780,7 @@ void gmm_state_security_mode(ogs_fsm_t *s, amf_event_t *e) break; case OGS_FSM_EXIT_SIG: break; - case AMF_EVT_5GMM_MESSAGE: + case AMF_EVENT_5GMM_MESSAGE: nas_message = e->nas.message; ogs_assert(nas_message); @@ -901,8 +901,8 @@ void gmm_state_security_mode(ogs_fsm_t *s, amf_event_t *e) break; } break; - case AMF_EVT_5GMM_TIMER: - switch (e->timer_id) { + case AMF_EVENT_5GMM_TIMER: + switch (e->h.timer_id) { case AMF_TIMER_T3560: if (amf_ue->t3560.retry_count >= amf_timer_cfg(AMF_TIMER_T3560)->max_count) { @@ -923,7 +923,7 @@ void gmm_state_security_mode(ogs_fsm_t *s, amf_event_t *e) break; default: ogs_error("Unknown timer[%s:%d]", - amf_timer_get_name(e->timer_id), e->timer_id); + amf_timer_get_name(e->h.timer_id), e->h.timer_id); break; } break; @@ -962,16 +962,16 @@ void gmm_state_initial_context_setup(ogs_fsm_t *s, amf_event_t *e) ogs_assert(amf_ue); } - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: break; case OGS_FSM_EXIT_SIG: break; - case AMF_EVT_SBI_CLIENT: - sbi_response = e->sbi.response; + case OGS_EVENT_SBI_CLIENT: + sbi_response = e->h.sbi.response; ogs_assert(sbi_response); - sbi_message = e->sbi.message; + sbi_message = e->h.sbi.message; ogs_assert(sbi_message); SWITCH(sbi_message->h.service.name) @@ -1105,7 +1105,7 @@ void gmm_state_initial_context_setup(ogs_fsm_t *s, amf_event_t *e) END break; - case AMF_EVT_5GMM_MESSAGE: + case AMF_EVENT_5GMM_MESSAGE: nas_message = e->nas.message; ogs_assert(nas_message); @@ -1228,8 +1228,8 @@ void gmm_state_initial_context_setup(ogs_fsm_t *s, amf_event_t *e) break; } break; - case AMF_EVT_5GMM_TIMER: - switch (e->timer_id) { + case AMF_EVENT_5GMM_TIMER: + switch (e->h.timer_id) { case AMF_TIMER_T3550: if (amf_ue->t3550.retry_count >= amf_timer_cfg(AMF_TIMER_T3550)->max_count) { @@ -1248,7 +1248,7 @@ void gmm_state_initial_context_setup(ogs_fsm_t *s, amf_event_t *e) break; default: ogs_error("[%s] Unknown timer[%s:%d]", amf_ue->suci, - amf_timer_get_name(e->timer_id), e->timer_id); + amf_timer_get_name(e->h.timer_id), e->h.timer_id); break; } break; @@ -1281,7 +1281,7 @@ void gmm_state_exception(ogs_fsm_t *s, amf_event_t *e) ogs_assert(amf_ue); } - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: AMF_UE_CLEAR_PAGING_INFO(amf_ue); AMF_UE_CLEAR_N2_TRANSFER(amf_ue, pdu_session_resource_setup_request); @@ -1300,7 +1300,7 @@ void gmm_state_exception(ogs_fsm_t *s, amf_event_t *e) case OGS_FSM_EXIT_SIG: break; - case AMF_EVT_5GMM_MESSAGE: + case AMF_EVENT_5GMM_MESSAGE: nas_message = e->nas.message; ogs_assert(nas_message); diff --git a/src/amf/init.c b/src/amf/init.c index a58de7c89..a51c64b41 100644 --- a/src/amf/init.c +++ b/src/amf/init.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -33,7 +33,6 @@ int amf_initialize() ogs_sbi_context_init(); amf_context_init(); - amf_event_init(); rv = ogs_sbi_context_parse_config("amf", "nrf", "scp"); if (rv != OGS_OK) return rv; @@ -76,7 +75,7 @@ static void event_termination(void) /* Sending NF Instance De-registeration to NRF */ ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) - amf_nf_fsm_fini(nf_instance); + ogs_sbi_nf_fsm_fini(nf_instance); /* Starting holding timer */ t_termination_holding = ogs_timer_add(ogs_app()->timer_mgr, NULL, NULL); @@ -105,8 +104,6 @@ void amf_terminate(void) amf_context_final(); ogs_sbi_context_final(); ogs_metrics_context_final(); - - amf_event_final(); /* Destroy event */ } static void amf_main(void *data) @@ -114,8 +111,7 @@ static void amf_main(void *data) ogs_fsm_t amf_sm; int rv; - ogs_fsm_create(&amf_sm, amf_state_initial, amf_state_final); - ogs_fsm_init(&amf_sm, 0); + ogs_fsm_init(&amf_sm, amf_state_initial, amf_state_final, 0); for ( ;; ) { ogs_pollset_poll(ogs_app()->pollset, @@ -148,11 +144,10 @@ static void amf_main(void *data) ogs_assert(e); ogs_fsm_dispatch(&amf_sm, e); - amf_event_free(e); + ogs_event_free(e); } } done: ogs_fsm_fini(&amf_sm, 0); - ogs_fsm_delete(&amf_sm); } diff --git a/src/amf/meson.build b/src/amf/meson.build index 64891595f..d954625aa 100644 --- a/src/amf/meson.build +++ b/src/amf/meson.build @@ -1,4 +1,4 @@ -# Copyright (C) 2019,2020 by Sukchan Lee +# Copyright (C) 2019-2022 by Sukchan Lee # This file is part of Open5GS. @@ -43,8 +43,6 @@ libamf_sources = files(''' namf-handler.c sbi-path.c - nf-sm.c - ngap-sctp.c ngap-build.c ngap-handler.c diff --git a/src/amf/nf-sm.c b/src/amf/nf-sm.c deleted file mode 100644 index 3b19227e0..000000000 --- a/src/amf/nf-sm.c +++ /dev/null @@ -1,467 +0,0 @@ -/* - * Copyright (C) 2019,2020 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "context.h" - -#include "sbi-path.h" -#include "nnrf-handler.h" - -void amf_nf_fsm_init(ogs_sbi_nf_instance_t *nf_instance) -{ - amf_event_t e; - - ogs_assert(nf_instance); - - memset(&e, 0, sizeof(e)); - e.sbi.data = nf_instance; - - ogs_fsm_create(&nf_instance->sm, - amf_nf_state_initial, amf_nf_state_final); - ogs_fsm_init(&nf_instance->sm, &e); -} - -void amf_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance) -{ - amf_event_t e; - - ogs_assert(nf_instance); - - memset(&e, 0, sizeof(e)); - e.sbi.data = nf_instance; - - ogs_fsm_fini(&nf_instance->sm, &e); - ogs_fsm_delete(&nf_instance->sm); -} - -void amf_nf_state_initial(ogs_fsm_t *s, amf_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - - ogs_assert(s); - ogs_assert(e); - - amf_sm_debug(e); - - nf_instance = e->sbi.data; - ogs_assert(nf_instance); - - nf_instance->t_registration_interval = ogs_timer_add(ogs_app()->timer_mgr, - amf_timer_nf_instance_registration_interval, nf_instance); - ogs_assert(nf_instance->t_registration_interval); - nf_instance->t_heartbeat_interval = ogs_timer_add(ogs_app()->timer_mgr, - amf_timer_nf_instance_heartbeat_interval, nf_instance); - ogs_assert(nf_instance->t_heartbeat_interval); - nf_instance->t_no_heartbeat = ogs_timer_add(ogs_app()->timer_mgr, - amf_timer_nf_instance_no_heartbeat, nf_instance); - ogs_assert(nf_instance->t_no_heartbeat); - nf_instance->t_validity = ogs_timer_add(ogs_app()->timer_mgr, - amf_timer_nf_instance_validity, nf_instance); - ogs_assert(nf_instance->t_validity); - - 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); - } -} - -void amf_nf_state_final(ogs_fsm_t *s, amf_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - - ogs_assert(s); - ogs_assert(e); - - amf_sm_debug(e); - - nf_instance = e->sbi.data; - ogs_assert(nf_instance); - - ogs_timer_delete(nf_instance->t_registration_interval); - ogs_timer_delete(nf_instance->t_heartbeat_interval); - ogs_timer_delete(nf_instance->t_no_heartbeat); - ogs_timer_delete(nf_instance->t_validity); -} - -void amf_nf_state_will_register(ogs_fsm_t *s, amf_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_sbi_client_t *client = NULL; - ogs_sbi_message_t *message = NULL; - ogs_sockaddr_t *addr = NULL; - - ogs_assert(s); - ogs_assert(e); - - amf_sm_debug(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: - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); - - ogs_assert(true == ogs_nnrf_nfm_send_nf_register( - nf_instance, amf_nnrf_nfm_build_register)); - break; - - case OGS_FSM_EXIT_SIG: - ogs_timer_stop(nf_instance->t_registration_interval); - break; - - case AMF_EVT_SBI_CLIENT: - message = e->sbi.message; - ogs_assert(message); - - SWITCH(message->h.service.name) - CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) - - SWITCH(message->h.resource.component[0]) - CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - - if (message->res_status == OGS_SBI_HTTP_STATUS_OK || - message->res_status == OGS_SBI_HTTP_STATUS_CREATED) { - amf_nnrf_handle_nf_register(nf_instance, message); - OGS_FSM_TRAN(s, &amf_nf_state_registered); - } else { - ogs_error("[%s] HTTP Response Status Code [%d]", - 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]", - ogs_sbi_self()->nf_instance->id, - message->h.resource.component[0]); - END - break; - - DEFAULT - ogs_error("[%s] Invalid API name [%s]", - ogs_sbi_self()->nf_instance->id, message->h.service.name); - END - break; - - case AMF_EVT_SBI_TIMER: - switch(e->timer_id) { - case AMF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - client = nf_instance->client; - ogs_assert(client); - addr = client->node.addr; - ogs_assert(addr); - - ogs_warn("[%s] Retry to registration with NRF", - ogs_sbi_self()->nf_instance->id); - - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); - - ogs_assert(true == ogs_nnrf_nfm_send_nf_register( - nf_instance, amf_nnrf_nfm_build_register)); - break; - - default: - ogs_error("[%s] Unknown timer[%s:%d]", - ogs_sbi_self()->nf_instance->id, - amf_timer_get_name(e->timer_id), e->timer_id); - } - break; - - default: - ogs_error("Unknown event %s", amf_event_get_name(e)); - break; - } -} - -void amf_nf_state_registered(ogs_fsm_t *s, amf_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_sbi_client_t *client = NULL; - ogs_sbi_message_t *message = NULL; - ogs_assert(s); - ogs_assert(e); - - amf_sm_debug(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_NRF(nf_instance)) { - ogs_info("[%s] NF registered [Heartbeat:%ds]", - ogs_sbi_self()->nf_instance->id, - nf_instance->time.heartbeat_interval); - - client = nf_instance->client; - ogs_assert(client); - - if (nf_instance->time.heartbeat_interval) { - ogs_timer_start(nf_instance->t_heartbeat_interval, - ogs_time_from_sec(nf_instance->time.heartbeat_interval)); - ogs_timer_start(nf_instance->t_no_heartbeat, - ogs_time_from_sec( - nf_instance->time.heartbeat_interval + - ogs_app()->time.nf_instance.no_heartbeat_margin)); - } - - ogs_assert(true == - ogs_nnrf_nfm_send_nf_status_subscribe(client, - 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, - 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, - 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, - 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, - 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_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); - ogs_timer_stop(nf_instance->t_no_heartbeat); - } - - if (!OGS_FSM_CHECK(&nf_instance->sm, amf_nf_state_exception)) { - ogs_assert(true == - ogs_nnrf_nfm_send_nf_de_register(nf_instance)); - } - } - break; - - case AMF_EVT_SBI_CLIENT: - message = e->sbi.message; - ogs_assert(message); - - SWITCH(message->h.service.name) - CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) - - SWITCH(message->h.resource.component[0]) - CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - - if (message->res_status == OGS_SBI_HTTP_STATUS_NO_CONTENT || - message->res_status == OGS_SBI_HTTP_STATUS_OK) { - if (nf_instance->time.heartbeat_interval) - ogs_timer_start(nf_instance->t_no_heartbeat, - ogs_time_from_sec( - nf_instance->time.heartbeat_interval + - ogs_app()->time.nf_instance. - no_heartbeat_margin)); - } else { - ogs_warn("[%s] HTTP response error [%d]", - 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]", - ogs_sbi_self()->nf_instance->id, - message->h.resource.component[0]); - END - break; - - DEFAULT - ogs_error("[%s] Invalid API name [%s]", - ogs_sbi_self()->nf_instance->id, message->h.service.name); - END - break; - - case AMF_EVT_SBI_TIMER: - switch(e->timer_id) { - case AMF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - if (nf_instance->time.heartbeat_interval) - ogs_timer_start(nf_instance->t_heartbeat_interval, - ogs_time_from_sec(nf_instance->time.heartbeat_interval)); - - ogs_assert(true == ogs_nnrf_nfm_send_nf_update(nf_instance)); - break; - - case AMF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - 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: - 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:%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; - - default: - 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; - } -} - -void amf_nf_state_de_registered(ogs_fsm_t *s, amf_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_assert(s); - ogs_assert(e); - - amf_sm_debug(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_NRF(nf_instance)) { - ogs_info("[%s] NF de-registered", ogs_sbi_self()->nf_instance->id); - } - break; - - case OGS_FSM_EXIT_SIG: - break; - - default: - 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; - } -} - -void amf_nf_state_exception(ogs_fsm_t *s, amf_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_sbi_client_t *client = NULL; - ogs_sbi_message_t *message = NULL; - ogs_sockaddr_t *addr = NULL; - ogs_assert(s); - ogs_assert(e); - - amf_sm_debug(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_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_NRF(nf_instance)) { - ogs_timer_stop(nf_instance->t_registration_interval); - } - break; - - case AMF_EVT_SBI_TIMER: - switch(e->timer_id) { - case AMF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - client = nf_instance->client; - ogs_assert(client); - addr = client->node.addr; - ogs_assert(addr); - - 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:%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; - - case AMF_EVT_SBI_CLIENT: - message = e->sbi.message; - ogs_assert(message); - - SWITCH(message->h.service.name) - CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) - - SWITCH(message->h.resource.component[0]) - CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - break; - DEFAULT - ogs_error("Invalid resource name [%s]", - message->h.resource.component[0]); - END - break; - DEFAULT - ogs_error("Invalid API name [%s]", message->h.service.name); - END - break; - - default: - 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/ngap-path.c b/src/amf/ngap-path.c index a9f9300fa..d36e29750 100644 --- a/src/amf/ngap-path.c +++ b/src/amf/ngap-path.c @@ -104,7 +104,7 @@ int ngap_delayed_send_to_ran_ue( if (duration) { amf_event_t *e = NULL; - e = amf_event_new(AMF_EVT_NGAP_TIMER); + e = amf_event_new(AMF_EVENT_NGAP_TIMER); ogs_assert(e); e->timer = ogs_timer_add( ogs_app()->timer_mgr, amf_timer_ng_delayed_send, e); @@ -132,7 +132,7 @@ int ngap_send_to_5gsm(amf_ue_t *amf_ue, ogs_pkbuf_t *esmbuf) ogs_assert(amf_ue); ogs_assert(esmbuf); - e = amf_event_new(AMF_EVT_5GSM_MESSAGE); + e = amf_event_new(AMF_EVENT_5GSM_MESSAGE); ogs_assert(e); e->amf_ue = amf_ue; e->pkbuf = esmbuf; @@ -140,7 +140,7 @@ int ngap_send_to_5gsm(amf_ue_t *amf_ue, ogs_pkbuf_t *esmbuf) if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed:%d", (int)rv); ogs_pkbuf_free(e->pkbuf); - amf_event_free(e); + ogs_event_free(e); } return rv; @@ -212,7 +212,7 @@ int ngap_send_to_nas(ran_ue_t *ran_ue, if (h->extended_protocol_discriminator == OGS_NAS_EXTENDED_PROTOCOL_DISCRIMINATOR_5GMM) { int rv; - e = amf_event_new(AMF_EVT_5GMM_MESSAGE); + e = amf_event_new(AMF_EVENT_5GMM_MESSAGE); if (!e) { ogs_error("ngap_send_to_nas() failed"); ogs_pkbuf_free(nasbuf); @@ -226,7 +226,7 @@ int ngap_send_to_nas(ran_ue_t *ran_ue, if (rv != OGS_OK) { ogs_error("ngap_send_to_nas() failed:%d", (int)rv); ogs_pkbuf_free(e->pkbuf); - amf_event_free(e); + ogs_event_free(e); } return rv; } else if (h->extended_protocol_discriminator == diff --git a/src/amf/ngap-sctp.c b/src/amf/ngap-sctp.c index aa34889d9..142daf161 100644 --- a/src/amf/ngap-sctp.c +++ b/src/amf/ngap-sctp.c @@ -113,7 +113,7 @@ void ngap_accept_handler(ogs_sock_t *sock) ogs_info("gNB-N2 accepted[%s]:%d in ng-path module", OGS_ADDR(addr, buf), OGS_PORT(addr)); - ngap_event_push(AMF_EVT_NGAP_LO_ACCEPT, + ngap_event_push(AMF_EVENT_NGAP_LO_ACCEPT, new, addr, NULL, 0, 0); } else { ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, "accept() failed"); @@ -164,7 +164,7 @@ void ngap_recv_handler(ogs_sock_t *sock) ogs_assert(addr); memcpy(addr, &from, sizeof(ogs_sockaddr_t)); - ngap_event_push(AMF_EVT_NGAP_LO_SCTP_COMM_UP, + ngap_event_push(AMF_EVENT_NGAP_LO_SCTP_COMM_UP, sock, addr, NULL, not->sn_assoc_change.sac_inbound_streams, not->sn_assoc_change.sac_outbound_streams); @@ -180,7 +180,7 @@ void ngap_recv_handler(ogs_sock_t *sock) ogs_assert(addr); memcpy(addr, &from, sizeof(ogs_sockaddr_t)); - ngap_event_push(AMF_EVT_NGAP_LO_CONNREFUSED, + ngap_event_push(AMF_EVENT_NGAP_LO_CONNREFUSED, sock, addr, NULL, 0, 0); } break; @@ -193,7 +193,7 @@ void ngap_recv_handler(ogs_sock_t *sock) ogs_assert(addr); memcpy(addr, &from, sizeof(ogs_sockaddr_t)); - ngap_event_push(AMF_EVT_NGAP_LO_CONNREFUSED, + ngap_event_push(AMF_EVENT_NGAP_LO_CONNREFUSED, sock, addr, NULL, 0, 0); break; @@ -235,7 +235,7 @@ void ngap_recv_handler(ogs_sock_t *sock) ogs_assert(addr); memcpy(addr, &from, sizeof(ogs_sockaddr_t)); - ngap_event_push(AMF_EVT_NGAP_MESSAGE, sock, addr, pkbuf, 0, 0); + ngap_event_push(AMF_EVENT_NGAP_MESSAGE, sock, addr, pkbuf, 0, 0); return; } else { if (ogs_socket_errno != OGS_EAGAIN) { diff --git a/src/amf/ngap-sm.c b/src/amf/ngap-sm.c index 86ccf66a0..1fb3693de 100644 --- a/src/amf/ngap-sm.c +++ b/src/amf/ngap-sm.c @@ -55,12 +55,12 @@ void ngap_state_operational(ogs_fsm_t *s, amf_event_t *e) gnb = e->gnb; ogs_assert(gnb); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: break; case OGS_FSM_EXIT_SIG: break; - case AMF_EVT_NGAP_MESSAGE: + case AMF_EVENT_NGAP_MESSAGE: pdu = e->ngap.message; ogs_assert(pdu); @@ -190,8 +190,8 @@ void ngap_state_operational(ogs_fsm_t *s, amf_event_t *e) } break; - case AMF_EVT_NGAP_TIMER: - switch (e->timer_id) { + case AMF_EVENT_NGAP_TIMER: + switch (e->h.timer_id) { case AMF_TIMER_NG_DELAYED_SEND: ogs_assert(e->ran_ue); ogs_assert(e->pkbuf); @@ -201,7 +201,7 @@ void ngap_state_operational(ogs_fsm_t *s, amf_event_t *e) break; default: ogs_error("Unknown timer[%s:%d]", - amf_timer_get_name(e->timer_id), e->timer_id); + amf_timer_get_name(e->h.timer_id), e->h.timer_id); break; } break; @@ -218,7 +218,7 @@ void ngap_state_exception(ogs_fsm_t *s, amf_event_t *e) amf_sm_debug(e); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: break; case OGS_FSM_EXIT_SIG: diff --git a/src/amf/nnrf-build.c b/src/amf/nnrf-build.c index aa8961c81..4f2d6a6b6 100644 --- a/src/amf/nnrf-build.c +++ b/src/amf/nnrf-build.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -19,41 +19,6 @@ #include "nnrf-build.h" -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; - - OpenAPI_nf_profile_t *NFProfile = 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_PUT; - message.h.service.name = (char *)OGS_SBI_SERVICE_NAME_NNRF_NFM; - 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] = nf_instance->id; - - message.http.content_encoding = (char*)ogs_sbi_self()->content_encoding; - - NFProfile = ogs_nnrf_nfm_build_nf_profile(); - ogs_expect_or_return_val(NFProfile, NULL); - - message.NFProfile = NFProfile; - - request = ogs_sbi_build_request(&message); - - ogs_sbi_nnrf_free_nf_profile(NFProfile); - - return request; -} - ogs_sbi_request_t *amf_nnrf_disc_build_discover( char *nrf_id, OpenAPI_nf_type_e target_nf_type, OpenAPI_nf_type_e requester_nf_type) diff --git a/src/amf/nnrf-build.h b/src/amf/nnrf-build.h index 825e1e0be..b82d3f354 100644 --- a/src/amf/nnrf-build.h +++ b/src/amf/nnrf-build.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -26,8 +26,6 @@ extern "C" { #endif -ogs_sbi_request_t *amf_nnrf_nfm_build_register(void); - ogs_sbi_request_t *amf_nnrf_disc_build_discover( char *nrf_id, OpenAPI_nf_type_e target_nf_type, OpenAPI_nf_type_e requester_nf_type); diff --git a/src/amf/nnrf-handler.c b/src/amf/nnrf-handler.c index c1126bca4..ffe99b12a 100644 --- a/src/amf/nnrf-handler.c +++ b/src/amf/nnrf-handler.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -22,233 +22,6 @@ #include "ngap-path.h" #include "nnrf-handler.h" -void amf_nnrf_handle_nf_register( - ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_message_t *recvmsg) -{ - OpenAPI_nf_profile_t *NFProfile = NULL; - ogs_sbi_client_t *client = NULL; - - ogs_assert(recvmsg); - ogs_assert(nf_instance); - client = nf_instance->client; - ogs_assert(client); - - NFProfile = recvmsg->NFProfile; - if (!NFProfile) { - ogs_error("No NFProfile"); - return; - } - - /* TIME : Update heartbeat from NRF */ - if (NFProfile->is_heart_beat_timer == true) - nf_instance->time.heartbeat_interval = NFProfile->heart_beat_timer; -} - -void amf_nnrf_handle_nf_status_subscribe( - ogs_sbi_subscription_t *subscription, ogs_sbi_message_t *recvmsg) -{ - OpenAPI_subscription_data_t *SubscriptionData = NULL; - ogs_sbi_client_t *client = NULL; - - ogs_assert(recvmsg); - ogs_assert(subscription); - client = subscription->client; - ogs_assert(client); - - SubscriptionData = recvmsg->SubscriptionData; - if (!SubscriptionData) { - ogs_error("No SubscriptionData"); - return; - } - - if (!SubscriptionData->subscription_id) { - ogs_error("No SubscriptionId"); - return; - } - ogs_sbi_subscription_set_id( - subscription, SubscriptionData->subscription_id); - - if (SubscriptionData->validity_time) { -#define VALIDITY_MINIMUM (10LL * OGS_USEC_PER_SEC) /* 10 seconds */ - ogs_time_t time, duration; - if (ogs_sbi_time_from_string( - &time, SubscriptionData->validity_time) == true) { - duration = time - ogs_time_now(); - if (duration < VALIDITY_MINIMUM) { - duration = VALIDITY_MINIMUM; - ogs_warn("[%s] Forced to %lld seconds", subscription->id, - (long long)ogs_time_sec(VALIDITY_MINIMUM)); - } - subscription->t_validity = ogs_timer_add(ogs_app()->timer_mgr, - amf_timer_subscription_validity, subscription); - ogs_assert(subscription->t_validity); - ogs_timer_start(subscription->t_validity, duration); - } else { - ogs_error("Cannot parse validitiyTime [%s]", - SubscriptionData->validity_time); - } - } -} - -bool amf_nnrf_handle_nf_status_notify( - ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) -{ - int rv; - bool handled; - - ogs_sbi_response_t *response = NULL; - OpenAPI_notification_data_t *NotificationData = NULL; - ogs_sbi_nf_instance_t *nf_instance = NULL; - - ogs_sbi_message_t message; - ogs_sbi_header_t header; - - ogs_assert(stream); - ogs_assert(recvmsg); - - NotificationData = recvmsg->NotificationData; - if (!NotificationData) { - ogs_error("No NotificationData"); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "No NotificationData", NULL)); - return false; - } - - if (!NotificationData->nf_instance_uri) { - ogs_error("No nfInstanceUri"); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "No nfInstanceUri", NULL)); - return false; - } - - memset(&header, 0, sizeof(header)); - header.uri = NotificationData->nf_instance_uri; - - rv = ogs_sbi_parse_header(&message, &header); - if (rv != OGS_OK) { - ogs_error("Cannot parse nfInstanceUri [%s]", header.uri); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Cannot parse nfInstanceUri", header.uri)); - return false; - } - - if (!message.h.resource.component[1]) { - ogs_error("No nfInstanceId [%s]", header.uri); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Cannot parse nfInstanceUri", header.uri)); - ogs_sbi_header_free(&header); - return false; - } - - if (NF_INSTANCE_IS_SELF(message.h.resource.component[1])) { - ogs_warn("[%s] The notification is not allowed", - message.h.resource.component[1]); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, - recvmsg, "The notification is not allowed", - message.h.resource.component[1])); - ogs_sbi_header_free(&header); - return false; - } - - if (NotificationData->event == - OpenAPI_notification_event_type_NF_REGISTERED) { - - OpenAPI_nf_profile_t *NFProfile = NULL; - - NFProfile = NotificationData->nf_profile; - if (!NFProfile) { - ogs_error("No NFProfile"); - ogs_assert(true == - ogs_sbi_server_send_error( - stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "No NFProfile", NULL)); - ogs_sbi_header_free(&header); - return false; - } - - nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); - if (!nf_instance) { - 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); - - ogs_info("[%s] (NRF-notify) NF registered", nf_instance->id); - - } else { - OGS_FSM_TRAN(&nf_instance->sm, amf_nf_state_registered); - ogs_fsm_dispatch(&nf_instance->sm, NULL); - - ogs_warn("[%s] (NRF-notify) NF has already been added", - message.h.resource.component[1]); - - } - - handled = ogs_sbi_nnrf_handle_nf_profile( - nf_instance, NFProfile, stream, recvmsg); - if (!handled) { - AMF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); - ogs_sbi_header_free(&header); - return false; - } - - ogs_info("[%s] (NRF-notify) NF Profile updated", nf_instance->id); - - handled = ogs_sbi_client_associate(nf_instance); - if (!handled) { - ogs_error("[%s] Cannot associate NF EndPoint", nf_instance->id); - ogs_assert(true == - ogs_sbi_server_send_error(stream, - OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Cannot find NF EndPoint", nf_instance->id)); - AMF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); - ogs_sbi_header_free(&header); - return false; - } - - } else if (NotificationData->event == - OpenAPI_notification_event_type_NF_DEREGISTERED) { - nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); - if (nf_instance) { - AMF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); - } else { - ogs_warn("[%s] (NRF-notify) Not found", - message.h.resource.component[1]); - ogs_assert(true == - ogs_sbi_server_send_error(stream, - OGS_SBI_HTTP_STATUS_NOT_FOUND, - recvmsg, "Not found", message.h.resource.component[1])); - ogs_sbi_header_free(&header); - return false; - } - } else { - char *eventstr = OpenAPI_notification_event_type_ToString( - NotificationData->event); - ogs_error("Not supported event [%d:%s]", - NotificationData->event, eventstr ? eventstr : "Unknown"); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Not supported event", - eventstr ? eventstr : "Unknown")); - ogs_sbi_header_free(&header); - return false; - } - - response = ogs_sbi_build_response(recvmsg, OGS_SBI_HTTP_STATUS_NO_CONTENT); - ogs_assert(response); - ogs_assert(true == ogs_sbi_server_send_response(stream, response)); - - ogs_sbi_header_free(&header); - return true; -} - void amf_nnrf_handle_nf_discover( ogs_sbi_xact_t *xact, ogs_sbi_message_t *recvmsg) { @@ -273,84 +46,10 @@ void amf_nnrf_handle_nf_discover( return; } - amf_nnrf_handle_nf_discover_search_result( + ogs_nnrf_handle_nf_discover_search_result( sbi_object, target_nf_type, discovery_option, SearchResult); amf_sbi_select_nf(sbi_object, target_nf_type, discovery_option); ogs_expect(true == amf_sbi_send_request(sbi_object, target_nf_type, xact)); } - -void amf_nnrf_handle_nf_discover_search_result( - ogs_sbi_object_t *sbi_object, - OpenAPI_nf_type_e target_nf_type, - ogs_sbi_discovery_option_t *discovery_option, - OpenAPI_search_result_t *SearchResult) -{ - bool handled; - - OpenAPI_lnode_t *node = NULL; - ogs_sbi_nf_instance_t *nf_instance = NULL; - - ogs_assert(sbi_object); - ogs_assert(SearchResult); - - OpenAPI_list_for_each(SearchResult->nf_instances, node) { - OpenAPI_nf_profile_t *NFProfile = NULL; - - if (!node->data) continue; - - NFProfile = node->data; - - nf_instance = ogs_sbi_nf_instance_find(NFProfile->nf_instance_id); - if (!nf_instance) { - 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); - - ogs_info("[%s] (NF-discover) NF registered", nf_instance->id); - } else { - OGS_FSM_TRAN(&nf_instance->sm, amf_nf_state_registered); - ogs_fsm_dispatch(&nf_instance->sm, NULL); - - ogs_warn("[%s] (NF-discover) NF has already been added", - NFProfile->nf_instance_id); - } - - if (NF_INSTANCE_IS_OTHERS(nf_instance->id)) { - handled = ogs_sbi_nnrf_handle_nf_profile( - nf_instance, NFProfile, NULL, NULL); - if (!handled) { - ogs_error("ogs_sbi_nnrf_handle_nf_profile() failed [%s]", - nf_instance->id); - AMF_NF_INSTANCE_CLEAR("NRF-discover", nf_instance); - continue; - } - - handled = ogs_sbi_client_associate(nf_instance); - if (!handled) { - ogs_error("[%s] Cannot assciate NF EndPoint", nf_instance->id); - AMF_NF_INSTANCE_CLEAR("NRF-discover", nf_instance); - continue; - } - - /* TIME : Update validity from NRF */ - if (SearchResult->is_validity_period && - SearchResult->validity_period) { - nf_instance->time.validity_duration = - SearchResult->validity_period; - - ogs_assert(nf_instance->t_validity); - ogs_timer_start(nf_instance->t_validity, - ogs_time_from_sec(nf_instance->time.validity_duration)); - - } else - ogs_warn("[%s] NF Instance validity-time should not 0", - nf_instance->id); - - ogs_info("[%s] (NF-discover) NF Profile updated", nf_instance->id); - } - } -} diff --git a/src/amf/nnrf-handler.h b/src/amf/nnrf-handler.h index 38b766b6a..9298339da 100644 --- a/src/amf/nnrf-handler.h +++ b/src/amf/nnrf-handler.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -26,21 +26,8 @@ extern "C" { #endif -void amf_nnrf_handle_nf_register( - ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_message_t *recvmsg); -void amf_nnrf_handle_nf_status_subscribe( - ogs_sbi_subscription_t *subscription, ogs_sbi_message_t *recvmsg); - -bool amf_nnrf_handle_nf_status_notify( - ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); - void amf_nnrf_handle_nf_discover( ogs_sbi_xact_t *xact, ogs_sbi_message_t *recvmsg); -void amf_nnrf_handle_nf_discover_search_result( - ogs_sbi_object_t *sbi_object, - OpenAPI_nf_type_e target_nf_type, - ogs_sbi_discovery_option_t *discovery_option, - OpenAPI_search_result_t *SearchResult); #ifdef __cplusplus } diff --git a/src/amf/nsmf-handler.c b/src/amf/nsmf-handler.c index ec610f962..a78b8cbe6 100644 --- a/src/amf/nsmf-handler.c +++ b/src/amf/nsmf-handler.c @@ -174,6 +174,8 @@ int amf_nsmf_pdusession_handle_update_sm_context( amf_sess_t *sess, int state, ogs_sbi_message_t *recvmsg) { amf_ue_t *amf_ue = NULL; + ran_ue_t *ran_ue = NULL; + ogs_assert(sess); amf_ue = sess->amf_ue; ogs_assert(amf_ue); @@ -356,7 +358,7 @@ int amf_nsmf_pdusession_handle_update_sm_context( if (!n2smbuf) { ogs_error("[%s:%d] No N2 SM Content", amf_ue->supi, sess->psi); - ogs_assert(OGS_OK == + ogs_expect(OGS_OK == ngap_send_error_indication2(amf_ue, NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error)); @@ -380,7 +382,7 @@ int amf_nsmf_pdusession_handle_update_sm_context( if (!n2smbuf) { ogs_error("[%s:%d] No N2 SM Content", amf_ue->supi, sess->psi); - ogs_assert(OGS_OK == + ogs_expect(OGS_OK == ngap_send_error_indication2(amf_ue, NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error)); @@ -402,7 +404,7 @@ int amf_nsmf_pdusession_handle_update_sm_context( default: ogs_error("Not implemented [%d]", SmContextUpdatedData->n2_sm_info_type); - ogs_assert(OGS_OK == + ogs_expect(OGS_OK == ngap_send_error_indication2(amf_ue, NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error)); @@ -605,7 +607,7 @@ int amf_nsmf_pdusession_handle_update_sm_context( } else if (state == AMF_REMOVE_S1_CONTEXT_BY_LO_CONNREFUSED) { if (AMF_SESSION_SYNC_DONE(amf_ue, state)) { - ran_ue_t *ran_ue = ran_ue_cycle(amf_ue->ran_ue); + ran_ue = ran_ue_cycle(amf_ue->ran_ue); amf_ue_deassociate(amf_ue); @@ -644,7 +646,7 @@ int amf_nsmf_pdusession_handle_update_sm_context( } else if (state == AMF_REMOVE_S1_CONTEXT_BY_RESET_PARTIAL) { if (AMF_SESSION_SYNC_DONE(amf_ue, state)) { ran_ue_t *iter = NULL; - ran_ue_t *ran_ue = ran_ue_cycle(amf_ue->ran_ue); + ran_ue = ran_ue_cycle(amf_ue->ran_ue); amf_ue_deassociate(amf_ue); @@ -701,8 +703,6 @@ int amf_nsmf_pdusession_handle_update_sm_context( } } } else { - amf_ue_t *amf_ue = NULL; - OpenAPI_sm_context_update_error_t *SmContextUpdateError = NULL; OpenAPI_ref_to_binary_data_t *n1SmMsg = NULL; ogs_pkbuf_t *n1smbuf = NULL; @@ -719,7 +719,7 @@ int amf_nsmf_pdusession_handle_update_sm_context( if (!SmContextUpdateError) { ogs_error("[%d:%d] No SmContextUpdateError [%d]", sess->psi, sess->pti, recvmsg->res_status); - ogs_assert(OGS_OK == + ogs_expect(OGS_OK == ngap_send_error_indication2(amf_ue, NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error)); @@ -728,7 +728,7 @@ int amf_nsmf_pdusession_handle_update_sm_context( if (!SmContextUpdateError->error) { ogs_error("[%d:%d] No Error [%d]", sess->psi, sess->pti, recvmsg->res_status); - ogs_assert(OGS_OK == + ogs_expect(OGS_OK == ngap_send_error_indication2(amf_ue, NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error)); @@ -761,7 +761,7 @@ int amf_nsmf_pdusession_handle_update_sm_context( n2SmInfo = SmContextUpdateError->n2_sm_info; if (!n2SmInfo || !n2SmInfo->content_id) { ogs_error("[%d:%d] No N2 SM Message", sess->psi, sess->pti); - ogs_assert(OGS_OK == + ogs_expect(OGS_OK == ngap_send_error_indication2(amf_ue, NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error)); @@ -773,7 +773,7 @@ int amf_nsmf_pdusession_handle_update_sm_context( if (!n2smbuf) { ogs_error("[%d:%d] No N2 SM Content [%s]", sess->psi, sess->pti, n2SmInfo->content_id); - ogs_assert(OGS_OK == + ogs_expect(OGS_OK == ngap_send_error_indication2(amf_ue, NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error)); @@ -783,7 +783,7 @@ int amf_nsmf_pdusession_handle_update_sm_context( ogs_error("[%d:%d] Error Indication", sess->psi, sess->pti); - ogs_assert(OGS_OK == + ogs_expect(OGS_OK == ngap_send_error_indication2(amf_ue, NGAP_Cause_PR_protocol, NGAP_CauseProtocol_semantic_error)); diff --git a/src/amf/sbi-path.c b/src/amf/sbi-path.c index 7aaecf575..f027078e9 100644 --- a/src/amf/sbi-path.c +++ b/src/amf/sbi-path.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -30,17 +30,17 @@ static int server_cb(ogs_sbi_request_t *request, void *data) ogs_assert(request); ogs_assert(data); - e = amf_event_new(AMF_EVT_SBI_SERVER); + e = amf_event_new(OGS_EVENT_SBI_SERVER); ogs_assert(e); - e->sbi.request = request; - e->sbi.data = data; + e->h.sbi.request = request; + e->h.sbi.data = data; rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed:%d", (int)rv); ogs_sbi_request_free(request); - amf_event_free(e); + ogs_event_free(e); return OGS_ERROR; } @@ -61,16 +61,16 @@ static int client_cb(int status, ogs_sbi_response_t *response, void *data) ogs_assert(response); - e = amf_event_new(AMF_EVT_SBI_CLIENT); + e = amf_event_new(OGS_EVENT_SBI_CLIENT); ogs_assert(e); - e->sbi.response = response; - e->sbi.data = data; + e->h.sbi.response = response; + e->h.sbi.data = data; rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed:%d", (int)rv); ogs_sbi_response_free(response); - amf_event_free(e); + ogs_event_free(e); return OGS_ERROR; } @@ -82,6 +82,14 @@ int amf_sbi_open(void) ogs_sbi_nf_instance_t *nf_instance = NULL; ogs_sbi_nf_service_t *service = NULL; + /* To be notified when NF Instances registered/deregistered in NRF + * or when their profile is modified */ + ogs_sbi_add_to_be_notified_nf_type(OpenAPI_nf_type_AUSF); + ogs_sbi_add_to_be_notified_nf_type(OpenAPI_nf_type_UDM); + ogs_sbi_add_to_be_notified_nf_type(OpenAPI_nf_type_PCF); + ogs_sbi_add_to_be_notified_nf_type(OpenAPI_nf_type_SMF); + ogs_sbi_add_to_be_notified_nf_type(OpenAPI_nf_type_NSSF); + /* Add SELF NF instance */ nf_instance = ogs_sbi_self()->nf_instance; ogs_assert(nf_instance); @@ -123,16 +131,9 @@ int amf_sbi_open(void) /* NFRegister is sent and the response is received * by the above client callback. */ - amf_nf_fsm_init(nf_instance); + ogs_sbi_nf_fsm_init(nf_instance); } - /* Timer expiration handler of client wait timer */ - ogs_sbi_self()->client_wait_expire = amf_timer_sbi_client_wait_expire; - - /* NF register state in NF state machine */ - ogs_sbi_self()->nf_state_registered = - (ogs_fsm_handler_t)amf_nf_state_registered; - if (ogs_sbi_server_start_all(server_cb) != OGS_OK) return OGS_ERROR; @@ -332,7 +333,7 @@ static int client_discover_cb( goto cleanup; } - amf_nnrf_handle_nf_discover_search_result( + ogs_nnrf_handle_nf_discover_search_result( &sess->sbi, OpenAPI_nf_type_SMF, NULL, message.SearchResult); amf_sbi_select_nf(&sess->sbi, OpenAPI_nf_type_SMF, NULL); diff --git a/src/amf/sbi-path.h b/src/amf/sbi-path.h index 76bd53dc4..38b5dd78a 100644 --- a/src/amf/sbi-path.h +++ b/src/amf/sbi-path.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * diff --git a/src/amf/timer.c b/src/amf/timer.c index c3efd1b27..8b857202a 100644 --- a/src/amf/timer.c +++ b/src/amf/timer.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -20,36 +20,33 @@ #include "context.h" static amf_timer_cfg_t g_amf_timer_cfg[MAX_NUM_OF_AMF_TIMER] = { - [AMF_TIMER_SBI_CLIENT_WAIT] = - { .duration = ogs_time_from_msec(500) }, - /* Paging procedure for EPS services initiated */ [AMF_TIMER_T3513] = - { .max_count = 2, .duration = ogs_time_from_sec(2) }, + { .have = true, .max_count = 2, .duration = ogs_time_from_sec(2) }, /* DEREGISTRATION REQUEST sent */ [AMF_TIMER_T3522] = - { .max_count = 4, .duration = ogs_time_from_sec(3) }, + { .have = true, .max_count = 4, .duration = ogs_time_from_sec(3) }, /* REGISTRATION ACCEPT sent */ [AMF_TIMER_T3550] = - { .max_count = 4, .duration = ogs_time_from_sec(6) }, + { .have = true, .max_count = 4, .duration = ogs_time_from_sec(6) }, /* CONFIGURATION UPDATE COMMAND sent */ [AMF_TIMER_T3555] = - { .max_count = 4, .duration = ogs_time_from_sec(6) }, + { .have = true, .max_count = 4, .duration = ogs_time_from_sec(6) }, /* AUTHENTICATION REQUEST sent * SECURITY MODE COMMAND sent */ [AMF_TIMER_T3560] = - { .max_count = 4, .duration = ogs_time_from_sec(6) }, + { .have = true, .max_count = 4, .duration = ogs_time_from_sec(6) }, /* IDENTITY REQUEST sent */ [AMF_TIMER_T3570] = - { .max_count = 4, .duration = ogs_time_from_sec(3) }, + { .have = true, .max_count = 4, .duration = ogs_time_from_sec(3) }, [AMF_TIMER_NG_HOLDING] = - { .duration = ogs_time_from_sec(30) }, + { .have = true, .duration = ogs_time_from_sec(30) }, }; static void gmm_timer_event_send( @@ -58,24 +55,28 @@ static void gmm_timer_event_send( amf_timer_cfg_t *amf_timer_cfg(amf_timer_e id) { ogs_assert(id < MAX_NUM_OF_AMF_TIMER); + if (g_amf_timer_cfg[id].have != true) { + ogs_fatal("No timer[%d] configuration", id); + ogs_assert_if_reached(); + } return &g_amf_timer_cfg[id]; } -const char *amf_timer_get_name(amf_timer_e id) +const char *amf_timer_get_name(int timer_id) { - switch (id) { - case AMF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - return "AMF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL"; - case AMF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - return "AMF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL"; - case AMF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - return "AMF_TIMER_NF_INSTANCE_NO_HEARTBEAT"; - case AMF_TIMER_NF_INSTANCE_VALIDITY: - return "AMF_TIMER_NF_INSTANCE_VALIDITY"; - case AMF_TIMER_SUBSCRIPTION_VALIDITY: - return "AMF_TIMER_SUBSCRIPTION_VALIDITY"; - case AMF_TIMER_SBI_CLIENT_WAIT: - return "AMF_TIMER_SBI_CLIENT_WAIT"; + switch (timer_id) { + case OGS_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: + return OGS_TIMER_NAME_NF_INSTANCE_REGISTRATION_INTERVAL; + case OGS_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: + return OGS_TIMER_NAME_NF_INSTANCE_HEARTBEAT_INTERVAL; + case OGS_TIMER_NF_INSTANCE_NO_HEARTBEAT: + return OGS_TIMER_NAME_NF_INSTANCE_NO_HEARTBEAT; + case OGS_TIMER_NF_INSTANCE_VALIDITY: + return OGS_TIMER_NAME_NF_INSTANCE_VALIDITY; + case OGS_TIMER_SUBSCRIPTION_VALIDITY: + return OGS_TIMER_NAME_SUBSCRIPTION_VALIDITY; + case OGS_TIMER_SBI_CLIENT_WAIT: + return OGS_TIMER_NAME_SBI_CLIENT_WAIT; case AMF_TIMER_NG_DELAYED_SEND: return "AMF_TIMER_NG_DELAYED_SEND"; case AMF_TIMER_T3513: @@ -93,9 +94,10 @@ const char *amf_timer_get_name(amf_timer_e id) case AMF_TIMER_NG_HOLDING: return "AMF_TIMER_NG_HOLDING"; default: - break; + break; } + ogs_error("Unknown Timer[%d]", timer_id); return "UNKNOWN_TIMER"; } @@ -105,90 +107,16 @@ void amf_timer_ng_delayed_send(void *data) amf_event_t *e = data; ogs_assert(e); - e->timer_id = AMF_TIMER_NG_DELAYED_SEND; + e->h.timer_id = AMF_TIMER_NG_DELAYED_SEND; rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed:%d", (int)rv); ogs_timer_delete(e->timer); - amf_event_free(e); + ogs_event_free(e); } } -static void sbi_timer_send_event(int timer_id, void *data) -{ - int rv; - amf_event_t *e = NULL; - ogs_assert(data); - - switch (timer_id) { - case AMF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - case AMF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - case AMF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - case AMF_TIMER_NF_INSTANCE_VALIDITY: - case AMF_TIMER_SUBSCRIPTION_VALIDITY: - e = amf_event_new(AMF_EVT_SBI_TIMER); - ogs_assert(e); - e->timer_id = timer_id; - e->sbi.data = data; - break; - case AMF_TIMER_SBI_CLIENT_WAIT: - e = amf_event_new(AMF_EVT_SBI_TIMER); - if (!e) { - ogs_sbi_xact_t *sbi_xact = data; - ogs_assert(sbi_xact); - - ogs_error("sbi_timer_send_event() failed"); - ogs_sbi_xact_remove(sbi_xact); - return; - } - e->timer_id = timer_id; - e->sbi.data = data; - break; - default: - ogs_fatal("Unknown timer id[%d]", timer_id); - ogs_assert_if_reached(); - break; - } - - rv = ogs_queue_push(ogs_app()->queue, e); - if (rv != OGS_OK) { - ogs_error("ogs_queue_push() failed [%d] in %s", - (int)rv, amf_timer_get_name(e->timer_id)); - amf_event_free(e); - } -} - -void amf_timer_nf_instance_registration_interval(void *data) -{ - sbi_timer_send_event(AMF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL, data); -} - -void amf_timer_nf_instance_heartbeat_interval(void *data) -{ - sbi_timer_send_event(AMF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL, data); -} - -void amf_timer_nf_instance_no_heartbeat(void *data) -{ - sbi_timer_send_event(AMF_TIMER_NF_INSTANCE_NO_HEARTBEAT, data); -} - -void amf_timer_nf_instance_validity(void *data) -{ - sbi_timer_send_event(AMF_TIMER_NF_INSTANCE_VALIDITY, data); -} - -void amf_timer_subscription_validity(void *data) -{ - sbi_timer_send_event(AMF_TIMER_SUBSCRIPTION_VALIDITY, data); -} - -void amf_timer_sbi_client_wait_expire(void *data) -{ - sbi_timer_send_event(AMF_TIMER_SBI_CLIENT_WAIT, data); -} - static void gmm_timer_event_send( amf_timer_e timer_id, amf_ue_t *amf_ue) { @@ -196,15 +124,16 @@ static void gmm_timer_event_send( amf_event_t *e = NULL; ogs_assert(amf_ue); - e = amf_event_new(AMF_EVT_5GMM_TIMER); + e = amf_event_new(AMF_EVENT_5GMM_TIMER); ogs_assert(e); - e->timer_id = timer_id; + e->h.timer_id = timer_id; e->amf_ue = amf_ue; rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { - ogs_error("ogs_queue_push() failed:%d", (int)rv); - amf_event_free(e); + ogs_error("ogs_queue_push() failed:%d in %s", + (int)rv, amf_timer_get_name(timer_id)); + ogs_event_free(e); } } @@ -242,15 +171,15 @@ void amf_timer_ng_holding_timer_expire(void *data) ogs_assert(data); ran_ue = data; - e = amf_event_new(AMF_EVT_NGAP_TIMER); + e = amf_event_new(AMF_EVENT_NGAP_TIMER); ogs_assert(e); - e->timer_id = AMF_TIMER_NG_HOLDING; + e->h.timer_id = AMF_TIMER_NG_HOLDING; e->ran_ue = ran_ue; rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed:%d", (int)rv); - amf_event_free(e); + ogs_event_free(e); } } diff --git a/src/amf/timer.h b/src/amf/timer.h index db751b8ca..3f70b0faa 100644 --- a/src/amf/timer.h +++ b/src/amf/timer.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -20,7 +20,7 @@ #ifndef AMF_TIMER_H #define AMF_TIMER_H -#include "ogs-core.h" +#include "ogs-proto.h" #ifdef __cplusplus extern "C" { @@ -28,14 +28,7 @@ extern "C" { /* forward declaration */ typedef enum { - AMF_TIMER_BASE = 0, - - AMF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL, - AMF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL, - AMF_TIMER_NF_INSTANCE_NO_HEARTBEAT, - AMF_TIMER_NF_INSTANCE_VALIDITY, - AMF_TIMER_SUBSCRIPTION_VALIDITY, - AMF_TIMER_SBI_CLIENT_WAIT, + AMF_TIMER_BASE = OGS_MAX_NUM_OF_PROTO_TIMER, AMF_TIMER_NG_DELAYED_SEND, AMF_TIMER_NG_HOLDING, @@ -52,20 +45,14 @@ typedef enum { } amf_timer_e; typedef struct amf_timer_cfg_s { + bool have; int max_count; ogs_time_t duration; } amf_timer_cfg_t; amf_timer_cfg_t *amf_timer_cfg(amf_timer_e id); -const char *amf_timer_get_name(amf_timer_e id); - -void amf_timer_nf_instance_registration_interval(void *data); -void amf_timer_nf_instance_heartbeat_interval(void *data); -void amf_timer_nf_instance_no_heartbeat(void *data); -void amf_timer_nf_instance_validity(void *data); -void amf_timer_subscription_validity(void *data); -void amf_timer_sbi_client_wait_expire(void *data); +const char *amf_timer_get_name(int timer_id); void amf_timer_ng_delayed_send(void *data); diff --git a/src/ausf/ausf-sm.c b/src/ausf/ausf-sm.c index e8e0bc8bf..36eb2661e 100644 --- a/src/ausf/ausf-sm.c +++ b/src/ausf/ausf-sm.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -53,17 +53,17 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e) ogs_assert(s); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: break; case OGS_FSM_EXIT_SIG: break; - case AUSF_EVT_SBI_SERVER: - request = e->sbi.request; + case OGS_EVENT_SBI_SERVER: + request = e->h.sbi.request; ogs_assert(request); - stream = e->sbi.data; + stream = e->h.sbi.data; ogs_assert(stream); rv = ogs_sbi_parse_request(&message, request); @@ -94,7 +94,7 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e) CASE(OGS_SBI_RESOURCE_NAME_NF_STATUS_NOTIFY) SWITCH(message.h.method) CASE(OGS_SBI_HTTP_METHOD_POST) - ausf_nnrf_handle_nf_status_notify(stream, &message); + ogs_nnrf_handle_nf_status_notify(stream, &message); break; DEFAULT @@ -154,7 +154,7 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e) ogs_assert(OGS_FSM_STATE(&ausf_ue->sm)); e->ausf_ue = ausf_ue; - e->sbi.message = &message; + e->h.sbi.message = &message; ogs_fsm_dispatch(&ausf_ue->sm, e); if (OGS_FSM_CHECK(&ausf_ue->sm, ausf_ue_state_exception)) { ogs_error("[%s] State machine exception", ausf_ue->suci); @@ -174,10 +174,10 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e) ogs_sbi_message_free(&message); break; - case AUSF_EVT_SBI_CLIENT: + case OGS_EVENT_SBI_CLIENT: ogs_assert(e); - response = e->sbi.response; + response = e->h.sbi.response; ogs_assert(response); rv = ogs_sbi_parse_response(&message, response); if (rv != OGS_OK) { @@ -199,23 +199,23 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e) SWITCH(message.h.resource.component[0]) CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - nf_instance = e->sbi.data; + nf_instance = e->h.sbi.data; ogs_assert(nf_instance); ogs_assert(OGS_FSM_STATE(&nf_instance->sm)); - e->sbi.message = &message; + e->h.sbi.message = &message; ogs_fsm_dispatch(&nf_instance->sm, e); break; CASE(OGS_SBI_RESOURCE_NAME_SUBSCRIPTIONS) - subscription = e->sbi.data; + subscription = e->h.sbi.data; ogs_assert(subscription); SWITCH(message.h.method) CASE(OGS_SBI_HTTP_METHOD_POST) if (message.res_status == OGS_SBI_HTTP_STATUS_CREATED || message.res_status == OGS_SBI_HTTP_STATUS_OK) { - ausf_nnrf_handle_nf_status_subscribe( + ogs_nnrf_handle_nf_status_subscribe( subscription, &message); } else { ogs_error("[%s] HTTP response error [%d]", @@ -250,7 +250,7 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e) CASE(OGS_SBI_SERVICE_NAME_NNRF_DISC) SWITCH(message.h.resource.component[0]) CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - sbi_xact = e->sbi.data; + sbi_xact = e->h.sbi.data; ogs_assert(sbi_xact); SWITCH(message.h.method) @@ -276,7 +276,7 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e) break; CASE(OGS_SBI_SERVICE_NAME_NUDM_UEAU) - sbi_xact = e->sbi.data; + sbi_xact = e->h.sbi.data; ogs_assert(sbi_xact); sbi_xact = ogs_sbi_xact_cycle(sbi_xact); @@ -290,7 +290,7 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e) ausf_ue = (ausf_ue_t *)sbi_xact->sbi_object; ogs_assert(ausf_ue); - e->sbi.data = sbi_xact->assoc_stream; + e->h.sbi.data = sbi_xact->assoc_stream; ogs_sbi_xact_remove(sbi_xact); @@ -301,7 +301,7 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e) } e->ausf_ue = ausf_ue; - e->sbi.message = &message; + e->h.sbi.message = &message; ogs_fsm_dispatch(&ausf_ue->sm, e); if (OGS_FSM_CHECK(&ausf_ue->sm, ausf_ue_state_exception)) { @@ -319,27 +319,27 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e) ogs_sbi_response_free(response); break; - case AUSF_EVT_SBI_TIMER: + case OGS_EVENT_SBI_TIMER: ogs_assert(e); - switch(e->timer_id) { - case AUSF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - case AUSF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - case AUSF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - case AUSF_TIMER_NF_INSTANCE_VALIDITY: - nf_instance = e->sbi.data; + switch(e->h.timer_id) { + case OGS_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: + case OGS_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: + case OGS_TIMER_NF_INSTANCE_NO_HEARTBEAT: + case OGS_TIMER_NF_INSTANCE_VALIDITY: + nf_instance = e->h.sbi.data; ogs_assert(nf_instance); ogs_assert(OGS_FSM_STATE(&nf_instance->sm)); ogs_fsm_dispatch(&nf_instance->sm, e); - if (OGS_FSM_CHECK(&nf_instance->sm, ausf_nf_state_exception)) + if (OGS_FSM_CHECK(&nf_instance->sm, ogs_sbi_nf_state_exception)) ogs_error("[%s:%s] State machine exception [%d]", OpenAPI_nf_type_ToString(nf_instance->nf_type), - nf_instance->id, e->timer_id); + nf_instance->id, e->h.timer_id); break; - case AUSF_TIMER_SUBSCRIPTION_VALIDITY: - subscription = e->sbi.data; + case OGS_TIMER_SUBSCRIPTION_VALIDITY: + subscription = e->h.sbi.data; ogs_assert(subscription); ogs_assert(ogs_sbi_self()->nf_instance); @@ -353,8 +353,8 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e) ogs_sbi_subscription_remove(subscription); break; - case AUSF_TIMER_SBI_CLIENT_WAIT: - sbi_xact = e->sbi.data; + case OGS_TIMER_SBI_CLIENT_WAIT: + sbi_xact = e->h.sbi.data; ogs_assert(sbi_xact); stream = sbi_xact->assoc_stream; @@ -370,7 +370,7 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e) break; default: ogs_error("Unknown timer[%s:%d]", - ausf_timer_get_name(e->timer_id), e->timer_id); + ogs_timer_get_name(e->h.timer_id), e->h.timer_id); } break; diff --git a/src/ausf/ausf-sm.h b/src/ausf/ausf-sm.h index c43eefd27..aa1fd1bab 100644 --- a/src/ausf/ausf-sm.h +++ b/src/ausf/ausf-sm.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -30,16 +30,6 @@ void ausf_state_initial(ogs_fsm_t *s, ausf_event_t *e); void ausf_state_final(ogs_fsm_t *s, ausf_event_t *e); void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e); -void ausf_nf_fsm_init(ogs_sbi_nf_instance_t *nf_instance); -void ausf_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance); - -void ausf_nf_state_initial(ogs_fsm_t *s, ausf_event_t *e); -void ausf_nf_state_final(ogs_fsm_t *s, ausf_event_t *e); -void ausf_nf_state_will_register(ogs_fsm_t *s, ausf_event_t *e); -void ausf_nf_state_registered(ogs_fsm_t *s, ausf_event_t *e); -void ausf_nf_state_de_registered(ogs_fsm_t *s, ausf_event_t *e); -void ausf_nf_state_exception(ogs_fsm_t *s, ausf_event_t *e); - void ausf_ue_state_initial(ogs_fsm_t *s, ausf_event_t *e); void ausf_ue_state_final(ogs_fsm_t *s, ausf_event_t *e); void ausf_ue_state_operational(ogs_fsm_t *s, ausf_event_t *e); diff --git a/src/ausf/context.c b/src/ausf/context.c index a70ba5bc4..c9002059e 100644 --- a/src/ausf/context.c +++ b/src/ausf/context.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -141,8 +141,7 @@ ausf_ue_t *ausf_ue_add(char *suci) memset(&e, 0, sizeof(e)); e.ausf_ue = ausf_ue; - ogs_fsm_create(&ausf_ue->sm, ausf_ue_state_initial, ausf_ue_state_final); - ogs_fsm_init(&ausf_ue->sm, &e); + ogs_fsm_init(&ausf_ue->sm, ausf_ue_state_initial, ausf_ue_state_final, &e); ogs_list_add(&self.ausf_ue_list, ausf_ue); @@ -160,7 +159,6 @@ void ausf_ue_remove(ausf_ue_t *ausf_ue) memset(&e, 0, sizeof(e)); e.ausf_ue = ausf_ue; ogs_fsm_fini(&ausf_ue->sm, &e); - ogs_fsm_delete(&ausf_ue->sm); /* Free SBI object memory */ ogs_sbi_object_free(&ausf_ue->sbi); diff --git a/src/ausf/context.h b/src/ausf/context.h index 8f2276738..5470b9b6b 100644 --- a/src/ausf/context.h +++ b/src/ausf/context.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -25,7 +25,6 @@ #include "ogs-sbi.h" #include "ausf-sm.h" -#include "timer.h" #ifdef __cplusplus extern "C" { @@ -63,22 +62,6 @@ struct ausf_ue_s { uint8_t hxres_star[OGS_MAX_RES_LEN]; uint8_t kausf[OGS_SHA256_DIGEST_SIZE]; uint8_t kseaf[OGS_SHA256_DIGEST_SIZE]; - -#define AUSF_NF_INSTANCE_CLEAR(_cAUSE, _nFInstance) \ - do { \ - ogs_assert(_nFInstance); \ - if ((_nFInstance)->reference_count == 1) { \ - ogs_info("[%s] (%s) NF removed", (_nFInstance)->id, (_cAUSE)); \ - ausf_nf_fsm_fini((_nFInstance)); \ - ogs_sbi_nf_instance_remove(_nFInstance); \ - } else { \ - /* There is an assocation with other context */ \ - ogs_info("[%s:%d] (%s) NF suspended", \ - _nFInstance->id, _nFInstance->reference_count, (_cAUSE)); \ - OGS_FSM_TRAN(&_nFInstance->sm, ausf_nf_state_de_registered); \ - ogs_fsm_dispatch(&_nFInstance->sm, NULL); \ - } \ - } while(0) }; void ausf_context_init(void); diff --git a/src/ausf/event.c b/src/ausf/event.c index a55593c06..b725b26de 100644 --- a/src/ausf/event.c +++ b/src/ausf/event.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -18,60 +18,42 @@ */ #include "event.h" -#include "context.h" -static OGS_POOL(pool, ausf_event_t); - -void ausf_event_init(void) -{ - ogs_pool_init(&pool, ogs_app()->pool.event); -} - -void ausf_event_final(void) -{ - ogs_pool_final(&pool); -} - -ausf_event_t *ausf_event_new(ausf_event_e id) +ausf_event_t *ausf_event_new(int id) { ausf_event_t *e = NULL; - ogs_pool_alloc(&pool, &e); + e = ogs_event_size(id, sizeof(ausf_event_t)); ogs_assert(e); - memset(e, 0, sizeof(*e)); - e->id = id; + e->h.id = id; return e; } -void ausf_event_free(ausf_event_t *e) -{ - ogs_assert(e); - ogs_pool_free(&pool, e); -} - const char *ausf_event_get_name(ausf_event_t *e) { - if (e == NULL) + if (e == NULL) { return OGS_FSM_NAME_INIT_SIG; - - switch (e->id) { - case OGS_FSM_ENTRY_SIG: - return OGS_FSM_NAME_ENTRY_SIG; - case OGS_FSM_EXIT_SIG: - return OGS_FSM_NAME_EXIT_SIG; - - case AUSF_EVT_SBI_SERVER: - return "AUSF_EVT_SBI_SERVER"; - case AUSF_EVT_SBI_CLIENT: - return "AUSF_EVT_SBI_CLIENT"; - case AUSF_EVT_SBI_TIMER: - return "AUSF_EVT_SBI_TIMER"; - - default: - break; } + switch (e->h.id) { + case OGS_FSM_ENTRY_SIG: + return OGS_FSM_NAME_ENTRY_SIG; + case OGS_FSM_EXIT_SIG: + return OGS_FSM_NAME_EXIT_SIG; + + case OGS_EVENT_SBI_SERVER: + return OGS_EVENT_NAME_SBI_SERVER; + case OGS_EVENT_SBI_CLIENT: + return OGS_EVENT_NAME_SBI_CLIENT; + case OGS_EVENT_SBI_TIMER: + return OGS_EVENT_NAME_SBI_TIMER; + + default: + break; + } + + ogs_error("Unknown Event[%d]", e->h.id); return "UNKNOWN_EVENT"; } diff --git a/src/ausf/event.h b/src/ausf/event.h index b2ac9ea2f..8a4befcac 100644 --- a/src/ausf/event.h +++ b/src/ausf/event.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -20,53 +20,21 @@ #ifndef AUSF_EVENT_H #define AUSF_EVENT_H -#include "ogs-core.h" +#include "ogs-proto.h" #ifdef __cplusplus extern "C" { #endif -typedef struct ogs_sbi_request_s ogs_sbi_request_t; -typedef struct ogs_sbi_response_s ogs_sbi_response_t; -typedef struct ogs_sbi_message_s ogs_sbi_message_t; -typedef struct ogs_sbi_nf_instance_s ogs_sbi_nf_instance_t; -typedef struct ogs_sbi_subscription_s ogs_sbi_subscription_t; - typedef struct ausf_ue_s ausf_ue_t; -typedef enum { - AUSF_EVT_BASE = OGS_FSM_USER_SIG, - - AUSF_EVT_SBI_SERVER, - AUSF_EVT_SBI_CLIENT, - AUSF_EVT_SBI_TIMER, - - AUSF_EVT_TOP, - -} ausf_event_e; - typedef struct ausf_event_s { - int id; - int timer_id; - - struct { - ogs_sbi_request_t *request; - ogs_sbi_response_t *response; - void *data; - - ogs_sbi_message_t *message; - } sbi; + ogs_event_t h; ausf_ue_t *ausf_ue; - - ogs_timer_t *timer; } ausf_event_t; -void ausf_event_init(void); -void ausf_event_final(void); - -ausf_event_t *ausf_event_new(ausf_event_e id); -void ausf_event_free(ausf_event_t *e); +ausf_event_t *ausf_event_new(int id); const char *ausf_event_get_name(ausf_event_t *e); diff --git a/src/ausf/init.c b/src/ausf/init.c index 1b8a96722..a69a529d3 100644 --- a/src/ausf/init.c +++ b/src/ausf/init.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -30,7 +30,6 @@ int ausf_initialize() ogs_sbi_context_init(); ausf_context_init(); - ausf_event_init(); rv = ogs_sbi_context_parse_config("ausf", "nrf", "scp"); if (rv != OGS_OK) return rv; @@ -61,7 +60,7 @@ static void event_termination(void) /* Sending NF Instance De-registeration to NRF */ ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) - ausf_nf_fsm_fini(nf_instance); + ogs_sbi_nf_fsm_fini(nf_instance); /* Starting holding timer */ t_termination_holding = ogs_timer_add(ogs_app()->timer_mgr, NULL, NULL); @@ -87,8 +86,6 @@ void ausf_terminate(void) ausf_context_final(); ogs_sbi_context_final(); - - ausf_event_final(); /* Destroy event */ } static void ausf_main(void *data) @@ -96,8 +93,7 @@ static void ausf_main(void *data) ogs_fsm_t ausf_sm; int rv; - ogs_fsm_create(&ausf_sm, ausf_state_initial, ausf_state_final); - ogs_fsm_init(&ausf_sm, 0); + ogs_fsm_init(&ausf_sm, ausf_state_initial, ausf_state_final, 0); for ( ;; ) { ogs_pollset_poll(ogs_app()->pollset, @@ -130,11 +126,10 @@ static void ausf_main(void *data) ogs_assert(e); ogs_fsm_dispatch(&ausf_sm, e); - ausf_event_free(e); + ogs_event_free(e); } } done: ogs_fsm_fini(&ausf_sm, 0); - ogs_fsm_delete(&ausf_sm); } diff --git a/src/ausf/meson.build b/src/ausf/meson.build index a96aafaa8..1378b9e2a 100644 --- a/src/ausf/meson.build +++ b/src/ausf/meson.build @@ -1,4 +1,4 @@ -# Copyright (C) 2019,2020 by Sukchan Lee +# Copyright (C) 2019-2022 by Sukchan Lee # This file is part of Open5GS. @@ -18,12 +18,8 @@ libausf_sources = files(''' context.c event.c - timer.c - nnrf-build.c nnrf-handler.c - nf-sm.c - nausf-handler.c nudm-build.c diff --git a/src/ausf/nf-sm.c b/src/ausf/nf-sm.c deleted file mode 100644 index 22873df82..000000000 --- a/src/ausf/nf-sm.c +++ /dev/null @@ -1,447 +0,0 @@ -/* - * Copyright (C) 2019,2020 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "context.h" - -#include "sbi-path.h" -#include "nnrf-handler.h" - -void ausf_nf_fsm_init(ogs_sbi_nf_instance_t *nf_instance) -{ - ausf_event_t e; - - ogs_assert(nf_instance); - - memset(&e, 0, sizeof(e)); - e.sbi.data = nf_instance; - - ogs_fsm_create(&nf_instance->sm, - ausf_nf_state_initial, ausf_nf_state_final); - ogs_fsm_init(&nf_instance->sm, &e); -} - -void ausf_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance) -{ - ausf_event_t e; - - ogs_assert(nf_instance); - - memset(&e, 0, sizeof(e)); - e.sbi.data = nf_instance; - - ogs_fsm_fini(&nf_instance->sm, &e); - ogs_fsm_delete(&nf_instance->sm); -} - -void ausf_nf_state_initial(ogs_fsm_t *s, ausf_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - - ogs_assert(s); - ogs_assert(e); - - ausf_sm_debug(e); - - nf_instance = e->sbi.data; - ogs_assert(nf_instance); - - nf_instance->t_registration_interval = ogs_timer_add(ogs_app()->timer_mgr, - ausf_timer_nf_instance_registration_interval, nf_instance); - ogs_assert(nf_instance->t_registration_interval); - nf_instance->t_heartbeat_interval = ogs_timer_add(ogs_app()->timer_mgr, - ausf_timer_nf_instance_heartbeat_interval, nf_instance); - ogs_assert(nf_instance->t_heartbeat_interval); - nf_instance->t_no_heartbeat = ogs_timer_add(ogs_app()->timer_mgr, - ausf_timer_nf_instance_no_heartbeat, nf_instance); - ogs_assert(nf_instance->t_no_heartbeat); - nf_instance->t_validity = ogs_timer_add(ogs_app()->timer_mgr, - ausf_timer_nf_instance_validity, nf_instance); - ogs_assert(nf_instance->t_validity); - - 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); - } -} - -void ausf_nf_state_final(ogs_fsm_t *s, ausf_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - - ogs_assert(s); - ogs_assert(e); - - ausf_sm_debug(e); - - nf_instance = e->sbi.data; - ogs_assert(nf_instance); - - ogs_timer_delete(nf_instance->t_registration_interval); - ogs_timer_delete(nf_instance->t_heartbeat_interval); - ogs_timer_delete(nf_instance->t_no_heartbeat); - ogs_timer_delete(nf_instance->t_validity); -} - -void ausf_nf_state_will_register(ogs_fsm_t *s, ausf_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_sbi_client_t *client = NULL; - ogs_sbi_message_t *message = NULL; - ogs_sockaddr_t *addr = NULL; - - ogs_assert(s); - ogs_assert(e); - - ausf_sm_debug(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: - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); - - ogs_assert(true == ogs_nnrf_nfm_send_nf_register( - nf_instance, ausf_nnrf_nfm_build_register)); - break; - - case OGS_FSM_EXIT_SIG: - ogs_timer_stop(nf_instance->t_registration_interval); - break; - - case AUSF_EVT_SBI_CLIENT: - message = e->sbi.message; - ogs_assert(message); - - SWITCH(message->h.service.name) - CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) - - SWITCH(message->h.resource.component[0]) - CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - - if (message->res_status == OGS_SBI_HTTP_STATUS_OK || - message->res_status == OGS_SBI_HTTP_STATUS_CREATED) { - ausf_nnrf_handle_nf_register(nf_instance, message); - OGS_FSM_TRAN(s, &ausf_nf_state_registered); - } else { - ogs_error("[%s] HTTP response error [%d]", - 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]", - ogs_sbi_self()->nf_instance->id, - message->h.resource.component[0]); - END - break; - - DEFAULT - ogs_error("[%s] Invalid API name [%s]", - ogs_sbi_self()->nf_instance->id, message->h.service.name); - END - break; - - case AUSF_EVT_SBI_TIMER: - switch(e->timer_id) { - case AUSF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - client = nf_instance->client; - ogs_assert(client); - addr = client->node.addr; - ogs_assert(addr); - - ogs_warn("[%s] Retry to registration with NRF", - ogs_sbi_self()->nf_instance->id); - - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); - - ogs_assert(true == ogs_nnrf_nfm_send_nf_register( - nf_instance, ausf_nnrf_nfm_build_register)); - break; - - default: - ogs_error("[%s] Unknown timer[%s:%d]", - ogs_sbi_self()->nf_instance->id, - ausf_timer_get_name(e->timer_id), e->timer_id); - } - break; - - default: - ogs_error("Unknown event %s", ausf_event_get_name(e)); - break; - } -} - -void ausf_nf_state_registered(ogs_fsm_t *s, ausf_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_sbi_client_t *client = NULL; - ogs_sbi_message_t *message = NULL; - ogs_assert(s); - ogs_assert(e); - - ausf_sm_debug(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_NRF(nf_instance)) { - ogs_info("[%s] NF registered [Heartbeat:%ds]", - ogs_sbi_self()->nf_instance->id, - nf_instance->time.heartbeat_interval); - - client = nf_instance->client; - ogs_assert(client); - - if (nf_instance->time.heartbeat_interval) { - ogs_timer_start(nf_instance->t_heartbeat_interval, - ogs_time_from_sec(nf_instance->time.heartbeat_interval)); - ogs_timer_start(nf_instance->t_no_heartbeat, - ogs_time_from_sec( - nf_instance->time.heartbeat_interval + - ogs_app()->time.nf_instance.no_heartbeat_margin)); - } - - ogs_assert(true == - ogs_nnrf_nfm_send_nf_status_subscribe(client, - 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_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); - ogs_timer_stop(nf_instance->t_no_heartbeat); - } - - if (!OGS_FSM_CHECK(&nf_instance->sm, ausf_nf_state_exception)) { - ogs_assert(true == - ogs_nnrf_nfm_send_nf_de_register(nf_instance)); - } - } - break; - - case AUSF_EVT_SBI_CLIENT: - message = e->sbi.message; - ogs_assert(message); - - SWITCH(message->h.service.name) - CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) - - SWITCH(message->h.resource.component[0]) - CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - - if (message->res_status == OGS_SBI_HTTP_STATUS_NO_CONTENT || - message->res_status == OGS_SBI_HTTP_STATUS_OK) { - if (nf_instance->time.heartbeat_interval) - ogs_timer_start(nf_instance->t_no_heartbeat, - ogs_time_from_sec( - nf_instance->time.heartbeat_interval + - ogs_app()->time.nf_instance. - no_heartbeat_margin)); - } else { - ogs_warn("[%s] HTTP response error [%d]", - 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]", - ogs_sbi_self()->nf_instance->id, - message->h.resource.component[0]); - END - break; - - DEFAULT - ogs_error("[%s] Invalid API name [%s]", - ogs_sbi_self()->nf_instance->id, message->h.service.name); - END - break; - - case AUSF_EVT_SBI_TIMER: - switch(e->timer_id) { - case AUSF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - if (nf_instance->time.heartbeat_interval) - ogs_timer_start(nf_instance->t_heartbeat_interval, - ogs_time_from_sec(nf_instance->time.heartbeat_interval)); - - ogs_assert(true == ogs_nnrf_nfm_send_nf_update(nf_instance)); - break; - - case AUSF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - 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: - 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:%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; - - default: - 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; - } -} - -void ausf_nf_state_de_registered(ogs_fsm_t *s, ausf_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_assert(s); - ogs_assert(e); - - ausf_sm_debug(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_NRF(nf_instance)) { - ogs_info("[%s] NF de-registered", ogs_sbi_self()->nf_instance->id); - } - break; - - case OGS_FSM_EXIT_SIG: - break; - - default: - 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; - } -} - -void ausf_nf_state_exception(ogs_fsm_t *s, ausf_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_sbi_client_t *client = NULL; - ogs_sbi_message_t *message = NULL; - ogs_sockaddr_t *addr = NULL; - ogs_assert(s); - ogs_assert(e); - - ausf_sm_debug(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_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_NRF(nf_instance)) { - ogs_timer_stop(nf_instance->t_registration_interval); - } - break; - - case AUSF_EVT_SBI_TIMER: - switch(e->timer_id) { - case AUSF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - client = nf_instance->client; - ogs_assert(client); - addr = client->node.addr; - ogs_assert(addr); - - 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:%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; - - case AUSF_EVT_SBI_CLIENT: - message = e->sbi.message; - ogs_assert(message); - - SWITCH(message->h.service.name) - CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) - - SWITCH(message->h.resource.component[0]) - CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - break; - DEFAULT - ogs_error("Invalid resource name [%s]", - message->h.resource.component[0]); - END - break; - DEFAULT - ogs_error("Invalid API name [%s]", message->h.service.name); - END - break; - - default: - 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 deleted file mode 100644 index 24da5ba18..000000000 --- a/src/ausf/nnrf-build.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2019,2020 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "nnrf-build.h" - -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; - - OpenAPI_nf_profile_t *NFProfile = 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_PUT; - message.h.service.name = (char *)OGS_SBI_SERVICE_NAME_NNRF_NFM; - 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] = nf_instance->id; - - message.http.content_encoding = (char*)ogs_sbi_self()->content_encoding; - - NFProfile = ogs_nnrf_nfm_build_nf_profile(); - ogs_expect_or_return_val(NFProfile, NULL); - - message.NFProfile = NFProfile; - - request = ogs_sbi_build_request(&message); - - ogs_sbi_nnrf_free_nf_profile(NFProfile); - - return request; -} diff --git a/src/ausf/nnrf-handler.c b/src/ausf/nnrf-handler.c index 3dfacc444..f56b7403c 100644 --- a/src/ausf/nnrf-handler.c +++ b/src/ausf/nnrf-handler.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -20,243 +20,14 @@ #include "sbi-path.h" #include "nnrf-handler.h" -void ausf_nnrf_handle_nf_register( - ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_message_t *recvmsg) -{ - OpenAPI_nf_profile_t *NFProfile = NULL; - ogs_sbi_client_t *client = NULL; - - ogs_assert(recvmsg); - ogs_assert(nf_instance); - client = nf_instance->client; - ogs_assert(client); - - NFProfile = recvmsg->NFProfile; - if (!NFProfile) { - ogs_error("No NFProfile"); - return; - } - - /* TIME : Update heartbeat from NRF */ - if (NFProfile->is_heart_beat_timer == true) - nf_instance->time.heartbeat_interval = NFProfile->heart_beat_timer; -} - -void ausf_nnrf_handle_nf_status_subscribe( - ogs_sbi_subscription_t *subscription, ogs_sbi_message_t *recvmsg) -{ - OpenAPI_subscription_data_t *SubscriptionData = NULL; - ogs_sbi_client_t *client = NULL; - - ogs_assert(recvmsg); - ogs_assert(subscription); - client = subscription->client; - ogs_assert(client); - - SubscriptionData = recvmsg->SubscriptionData; - if (!SubscriptionData) { - ogs_error("No SubscriptionData"); - return; - } - - if (!SubscriptionData->subscription_id) { - ogs_error("No SubscriptionId"); - return; - } - ogs_sbi_subscription_set_id( - subscription, SubscriptionData->subscription_id); - - if (SubscriptionData->validity_time) { -#define VALIDITY_MINIMUM (10LL * OGS_USEC_PER_SEC) /* 10 seconds */ - ogs_time_t time, duration; - if (ogs_sbi_time_from_string( - &time, SubscriptionData->validity_time) == true) { - duration = time - ogs_time_now(); - if (duration < VALIDITY_MINIMUM) { - duration = VALIDITY_MINIMUM; - ogs_warn("[%s] Forced to %lld seconds", subscription->id, - (long long)ogs_time_sec(VALIDITY_MINIMUM)); - } - subscription->t_validity = ogs_timer_add(ogs_app()->timer_mgr, - ausf_timer_subscription_validity, subscription); - ogs_assert(subscription->t_validity); - ogs_timer_start(subscription->t_validity, duration); - } else { - ogs_error("Cannot parse validitiyTime [%s]", - SubscriptionData->validity_time); - } - } -} - -bool ausf_nnrf_handle_nf_status_notify( - ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) -{ - int rv; - bool handled; - - ogs_sbi_response_t *response = NULL; - OpenAPI_notification_data_t *NotificationData = NULL; - ogs_sbi_nf_instance_t *nf_instance = NULL; - - ogs_sbi_message_t message; - ogs_sbi_header_t header; - - ogs_assert(stream); - ogs_assert(recvmsg); - - NotificationData = recvmsg->NotificationData; - if (!NotificationData) { - ogs_error("No NotificationData"); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "No NotificationData", NULL)); - return false; - } - - if (!NotificationData->nf_instance_uri) { - ogs_error("No nfInstanceUri"); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "No nfInstanceUri", NULL)); - return false; - } - - memset(&header, 0, sizeof(header)); - header.uri = NotificationData->nf_instance_uri; - - rv = ogs_sbi_parse_header(&message, &header); - if (rv != OGS_OK) { - ogs_error("Cannot parse nfInstanceUri [%s]", header.uri); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Cannot parse nfInstanceUri", header.uri)); - return false; - } - - if (!message.h.resource.component[1]) { - ogs_error("No nfInstanceId [%s]", header.uri); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Cannot parse nfInstanceUri", header.uri)); - ogs_sbi_header_free(&header); - return false; - } - - if (NF_INSTANCE_IS_SELF(message.h.resource.component[1])) { - ogs_warn("[%s] The notification is not allowed", - message.h.resource.component[1]); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, - recvmsg, "The notification is not allowed", - message.h.resource.component[1])); - ogs_sbi_header_free(&header); - return false; - } - - if (NotificationData->event == - OpenAPI_notification_event_type_NF_REGISTERED) { - - OpenAPI_nf_profile_t *NFProfile = NULL; - - NFProfile = NotificationData->nf_profile; - if (!NFProfile) { - ogs_error("No NFProfile"); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "No NFProfile", NULL)); - ogs_sbi_header_free(&header); - return false; - } - - nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); - if (!nf_instance) { - 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); - - ogs_info("[%s] (NRF-notify) NF registered", nf_instance->id); - - } else { - OGS_FSM_TRAN(&nf_instance->sm, ausf_nf_state_registered); - ogs_fsm_dispatch(&nf_instance->sm, NULL); - - ogs_warn("[%s] (NRF-notify) NF has already been added", - message.h.resource.component[1]); - - } - - handled = ogs_sbi_nnrf_handle_nf_profile( - nf_instance, NFProfile, stream, recvmsg); - if (!handled) { - AUSF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); - ogs_sbi_header_free(&header); - return false; - } - - ogs_info("[%s] (NRF-notify) NF Profile updated", nf_instance->id); - - handled = ogs_sbi_client_associate(nf_instance); - if (!handled) { - ogs_error("[%s] Cannot associate NF EndPoint", nf_instance->id); - ogs_assert(true == - ogs_sbi_server_send_error(stream, - OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Cannot find NF EndPoint", nf_instance->id)); - AUSF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); - ogs_sbi_header_free(&header); - return false; - } - - } else if (NotificationData->event == - OpenAPI_notification_event_type_NF_DEREGISTERED) { - nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); - if (nf_instance) { - AUSF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); - } else { - ogs_warn("[%s] (NRF-notify) Not found", - message.h.resource.component[1]); - ogs_assert(true == - ogs_sbi_server_send_error(stream, - OGS_SBI_HTTP_STATUS_NOT_FOUND, - recvmsg, "Not found", message.h.resource.component[1])); - ogs_sbi_header_free(&header); - return false; - } - } else { - char *eventstr = OpenAPI_notification_event_type_ToString( - NotificationData->event); - ogs_error("Not supported event [%d:%s]", - NotificationData->event, eventstr ? eventstr : "Unknown"); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Not supported event", - eventstr ? eventstr : "Unknown")); - ogs_sbi_header_free(&header); - return false; - } - - response = ogs_sbi_build_response(recvmsg, OGS_SBI_HTTP_STATUS_NO_CONTENT); - ogs_assert(response); - ogs_assert(true == ogs_sbi_server_send_response(stream, response)); - - ogs_sbi_header_free(&header); - return true; -} - void ausf_nnrf_handle_nf_discover( ogs_sbi_xact_t *xact, ogs_sbi_message_t *recvmsg) { ogs_sbi_object_t *sbi_object = NULL; OpenAPI_nf_type_e target_nf_type = 0; ogs_sbi_discovery_option_t *discovery_option = NULL; - ogs_sbi_nf_instance_t *nf_instance = NULL; OpenAPI_search_result_t *SearchResult = NULL; - OpenAPI_lnode_t *node = NULL; - bool handled; ogs_assert(recvmsg); ogs_assert(xact); @@ -273,64 +44,8 @@ void ausf_nnrf_handle_nf_discover( return; } - OpenAPI_list_for_each(SearchResult->nf_instances, node) { - OpenAPI_nf_profile_t *NFProfile = NULL; - - if (!node->data) continue; - - NFProfile = node->data; - - nf_instance = ogs_sbi_nf_instance_find(NFProfile->nf_instance_id); - if (!nf_instance) { - 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); - - ogs_info("[%s] (NF-discover) NF registered", nf_instance->id); - } else { - OGS_FSM_TRAN(&nf_instance->sm, ausf_nf_state_registered); - ogs_fsm_dispatch(&nf_instance->sm, NULL); - - ogs_warn("[%s] (NF-discover) NF has already been added", - NFProfile->nf_instance_id); - } - - if (NF_INSTANCE_IS_OTHERS(nf_instance->id)) { - handled = ogs_sbi_nnrf_handle_nf_profile( - nf_instance, NFProfile, NULL, NULL); - if (!handled) { - ogs_error("[%s] ogs_sbi_nnrf_handle_nf_profile() failed", - nf_instance->id); - AUSF_NF_INSTANCE_CLEAR("NRF-discover", nf_instance); - continue; - } - - handled = ogs_sbi_client_associate(nf_instance); - if (!handled) { - ogs_error("[%s] Cannot assciate NF EndPoint", nf_instance->id); - AUSF_NF_INSTANCE_CLEAR("NRF-discover", nf_instance); - continue; - } - - /* TIME : Update validity from NRF */ - if (SearchResult->is_validity_period && - SearchResult->validity_period) { - nf_instance->time.validity_duration = - SearchResult->validity_period; - - ogs_assert(nf_instance->t_validity); - ogs_timer_start(nf_instance->t_validity, - ogs_time_from_sec(nf_instance->time.validity_duration)); - - } else - ogs_warn("[%s] NF Instance validity-time should not 0", - nf_instance->id); - - ogs_info("[%s] (NF-discover) NF Profile updated", nf_instance->id); - } - } + ogs_nnrf_handle_nf_discover_search_result( + sbi_object, target_nf_type, discovery_option, SearchResult); ogs_sbi_select_nf(sbi_object, target_nf_type, discovery_option); diff --git a/src/ausf/nnrf-handler.h b/src/ausf/nnrf-handler.h index 9ef650128..a4cd54851 100644 --- a/src/ausf/nnrf-handler.h +++ b/src/ausf/nnrf-handler.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -26,14 +26,6 @@ extern "C" { #endif -void ausf_nnrf_handle_nf_register( - ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_message_t *recvmsg); -void ausf_nnrf_handle_nf_status_subscribe( - ogs_sbi_subscription_t *subscription, ogs_sbi_message_t *recvmsg); - -bool ausf_nnrf_handle_nf_status_notify( - ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); - void ausf_nnrf_handle_nf_discover( ogs_sbi_xact_t *xact, ogs_sbi_message_t *recvmsg); diff --git a/src/ausf/sbi-path.c b/src/ausf/sbi-path.c index a34de4f5e..947f4ccf5 100644 --- a/src/ausf/sbi-path.c +++ b/src/ausf/sbi-path.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -27,17 +27,17 @@ static int server_cb(ogs_sbi_request_t *request, void *data) ogs_assert(request); ogs_assert(data); - e = ausf_event_new(AUSF_EVT_SBI_SERVER); + e = ausf_event_new(OGS_EVENT_SBI_SERVER); ogs_assert(e); - e->sbi.request = request; - e->sbi.data = data; + e->h.sbi.request = request; + e->h.sbi.data = data; rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed:%d", (int)rv); ogs_sbi_request_free(request); - ausf_event_free(e); + ogs_event_free(e); return OGS_ERROR; } @@ -58,16 +58,16 @@ static int client_cb(int status, ogs_sbi_response_t *response, void *data) ogs_assert(response); - e = ausf_event_new(AUSF_EVT_SBI_CLIENT); + e = ausf_event_new(OGS_EVENT_SBI_CLIENT); ogs_assert(e); - e->sbi.response = response; - e->sbi.data = data; + e->h.sbi.response = response; + e->h.sbi.data = data; rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed:%d", (int)rv); ogs_sbi_response_free(response); - ausf_event_free(e); + ogs_event_free(e); return OGS_ERROR; } @@ -79,6 +79,10 @@ int ausf_sbi_open(void) ogs_sbi_nf_instance_t *nf_instance = NULL; ogs_sbi_nf_service_t *service = NULL; + /* To be notified when NF Instances registered/deregistered in NRF + * or when their profile is modified */ + ogs_sbi_add_to_be_notified_nf_type(OpenAPI_nf_type_UDM); + /* Add SELF NF instance */ nf_instance = ogs_sbi_self()->nf_instance; ogs_assert(nf_instance); @@ -98,28 +102,20 @@ int ausf_sbi_open(void) } /* Initialize NRF NF Instance */ - ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) { - if (NF_INSTANCE_IS_NRF(nf_instance)) { - ogs_sbi_client_t *client = NULL; + nf_instance = ogs_sbi_self()->nrf_instance; + if (nf_instance) { + ogs_sbi_client_t *client = NULL; - /* Client callback is only used when NF sends to NRF */ - client = nf_instance->client; - ogs_assert(client); - client->cb = client_cb; + /* 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. */ + ogs_sbi_nf_fsm_init(nf_instance); } - /* Timer expiration handler of client wait timer */ - ogs_sbi_self()->client_wait_expire = ausf_timer_sbi_client_wait_expire; - - /* NF register state in NF state machine */ - ogs_sbi_self()->nf_state_registered = - (ogs_fsm_handler_t)ausf_nf_state_registered; - if (ogs_sbi_server_start_all(server_cb) != OGS_OK) return OGS_ERROR; diff --git a/src/ausf/sbi-path.h b/src/ausf/sbi-path.h index 0ec3df789..145914a52 100644 --- a/src/ausf/sbi-path.h +++ b/src/ausf/sbi-path.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -20,7 +20,6 @@ #ifndef AUSF_SBI_PATH_H #define AUSF_SBI_PATH_H -#include "nnrf-build.h" #include "nudm-build.h" #ifdef __cplusplus diff --git a/src/ausf/timer.c b/src/ausf/timer.c deleted file mode 100644 index a022238ff..000000000 --- a/src/ausf/timer.c +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (C) 2019,2020 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "context.h" - -const char *ausf_timer_get_name(ausf_timer_e id) -{ - switch (id) { - case AUSF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - return "AUSF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL"; - case AUSF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - return "AUSF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL"; - case AUSF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - return "AUSF_TIMER_NF_INSTANCE_NO_HEARTBEAT"; - case AUSF_TIMER_NF_INSTANCE_VALIDITY: - return "AUSF_TIMER_NF_INSTANCE_VALIDITY"; - case AUSF_TIMER_SUBSCRIPTION_VALIDITY: - return "AUSF_TIMER_SUBSCRIPTION_VALIDITY"; - case AUSF_TIMER_SBI_CLIENT_WAIT: - return "AUSF_TIMER_SBI_CLIENT_WAIT"; - default: - break; - } - - return "UNKNOWN_TIMER"; -} - -static void sbi_timer_send_event(int timer_id, void *data) -{ - int rv; - ausf_event_t *e = NULL; - ogs_assert(data); - - switch (timer_id) { - case AUSF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - case AUSF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - case AUSF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - case AUSF_TIMER_NF_INSTANCE_VALIDITY: - case AUSF_TIMER_SUBSCRIPTION_VALIDITY: - e = ausf_event_new(AUSF_EVT_SBI_TIMER); - ogs_assert(e); - e->timer_id = timer_id; - e->sbi.data = data; - break; - case AUSF_TIMER_SBI_CLIENT_WAIT: - e = ausf_event_new(AUSF_EVT_SBI_TIMER); - if (!e) { - ogs_sbi_xact_t *sbi_xact = data; - ogs_assert(sbi_xact); - - ogs_error("sbi_timer_send_event() failed"); - ogs_sbi_xact_remove(sbi_xact); - return; - } - e->timer_id = timer_id; - e->sbi.data = data; - break; - default: - ogs_fatal("Unknown timer id[%d]", timer_id); - ogs_assert_if_reached(); - break; - } - - rv = ogs_queue_push(ogs_app()->queue, e); - if (rv != OGS_OK) { - ogs_error("ogs_queue_push() failed [%d] in %s", - (int)rv, ausf_timer_get_name(e->timer_id)); - ausf_event_free(e); - } -} - -void ausf_timer_nf_instance_registration_interval(void *data) -{ - sbi_timer_send_event(AUSF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL, data); -} - -void ausf_timer_nf_instance_heartbeat_interval(void *data) -{ - sbi_timer_send_event(AUSF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL, data); -} - -void ausf_timer_nf_instance_no_heartbeat(void *data) -{ - sbi_timer_send_event(AUSF_TIMER_NF_INSTANCE_NO_HEARTBEAT, data); -} - -void ausf_timer_nf_instance_validity(void *data) -{ - sbi_timer_send_event(AUSF_TIMER_NF_INSTANCE_VALIDITY, data); -} - -void ausf_timer_subscription_validity(void *data) -{ - sbi_timer_send_event(AUSF_TIMER_SUBSCRIPTION_VALIDITY, data); -} - -void ausf_timer_sbi_client_wait_expire(void *data) -{ - sbi_timer_send_event(AUSF_TIMER_SBI_CLIENT_WAIT, data); -} diff --git a/src/ausf/timer.h b/src/ausf/timer.h deleted file mode 100644 index c154924f6..000000000 --- a/src/ausf/timer.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2019 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef AUSF_TIMER_H -#define AUSF_TIMER_H - -#include "ogs-core.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* forward declaration */ -typedef enum { - AUSF_TIMER_BASE = 0, - - AUSF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL, - AUSF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL, - AUSF_TIMER_NF_INSTANCE_NO_HEARTBEAT, - AUSF_TIMER_NF_INSTANCE_VALIDITY, - AUSF_TIMER_SUBSCRIPTION_VALIDITY, - AUSF_TIMER_SBI_CLIENT_WAIT, - - MAX_NUM_OF_AUSF_TIMER, - -} ausf_timer_e; - -const char *ausf_timer_get_name(ausf_timer_e id); - -void ausf_timer_nf_instance_registration_interval(void *data); -void ausf_timer_nf_instance_heartbeat_interval(void *data); -void ausf_timer_nf_instance_no_heartbeat(void *data); -void ausf_timer_nf_instance_validity(void *data); -void ausf_timer_subscription_validity(void *data); -void ausf_timer_sbi_client_wait_expire(void *data); - -#ifdef __cplusplus -} -#endif - -#endif /* AUSF_TIMER_H */ diff --git a/src/ausf/ue-sm.c b/src/ausf/ue-sm.c index 38dd9665d..7be6bdcec 100644 --- a/src/ausf/ue-sm.c +++ b/src/ausf/ue-sm.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -66,17 +66,17 @@ void ausf_ue_state_operational(ogs_fsm_t *s, ausf_event_t *e) ausf_ue = e->ausf_ue; ogs_assert(ausf_ue); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: break; case OGS_FSM_EXIT_SIG: break; - case AUSF_EVT_SBI_SERVER: - message = e->sbi.message; + case OGS_EVENT_SBI_SERVER: + message = e->h.sbi.message; ogs_assert(message); - stream = e->sbi.data; + stream = e->h.sbi.data; ogs_assert(stream); SWITCH(message->h.method) @@ -109,13 +109,13 @@ void ausf_ue_state_operational(ogs_fsm_t *s, ausf_event_t *e) break; - case AUSF_EVT_SBI_CLIENT: - message = e->sbi.message; + case OGS_EVENT_SBI_CLIENT: + message = e->h.sbi.message; ogs_assert(message); ausf_ue = e->ausf_ue; ogs_assert(ausf_ue); - stream = e->sbi.data; + stream = e->h.sbi.data; ogs_assert(stream); SWITCH(message->h.service.name) @@ -178,7 +178,7 @@ void ausf_ue_state_exception(ogs_fsm_t *s, ausf_event_t *e) ausf_ue = e->ausf_ue; ogs_assert(ausf_ue); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: break; diff --git a/src/bsf/bsf-sm.c b/src/bsf/bsf-sm.c index f7874412e..1a134eeeb 100644 --- a/src/bsf/bsf-sm.c +++ b/src/bsf/bsf-sm.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -56,17 +56,17 @@ void bsf_state_operational(ogs_fsm_t *s, bsf_event_t *e) ogs_assert(s); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: break; case OGS_FSM_EXIT_SIG: break; - case BSF_EVT_SBI_SERVER: - request = e->sbi.request; + case OGS_EVENT_SBI_SERVER: + request = e->h.sbi.request; ogs_assert(request); - stream = e->sbi.data; + stream = e->h.sbi.data; ogs_assert(stream); rv = ogs_sbi_parse_request(&message, request); @@ -97,7 +97,7 @@ void bsf_state_operational(ogs_fsm_t *s, bsf_event_t *e) CASE(OGS_SBI_RESOURCE_NAME_NF_STATUS_NOTIFY) SWITCH(message.h.method) CASE(OGS_SBI_HTTP_METHOD_POST) - bsf_nnrf_handle_nf_status_notify(stream, &message); + ogs_nnrf_handle_nf_status_notify(stream, &message); break; DEFAULT @@ -195,10 +195,10 @@ void bsf_state_operational(ogs_fsm_t *s, bsf_event_t *e) ogs_sbi_message_free(&message); break; - case BSF_EVT_SBI_CLIENT: + case OGS_EVENT_SBI_CLIENT: ogs_assert(e); - response = e->sbi.response; + response = e->h.sbi.response; ogs_assert(response); rv = ogs_sbi_parse_response(&message, response); if (rv != OGS_OK) { @@ -220,23 +220,23 @@ void bsf_state_operational(ogs_fsm_t *s, bsf_event_t *e) SWITCH(message.h.resource.component[0]) CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - nf_instance = e->sbi.data; + nf_instance = e->h.sbi.data; ogs_assert(nf_instance); ogs_assert(OGS_FSM_STATE(&nf_instance->sm)); - e->sbi.message = &message; + e->h.sbi.message = &message; ogs_fsm_dispatch(&nf_instance->sm, e); break; CASE(OGS_SBI_RESOURCE_NAME_SUBSCRIPTIONS) - subscription = e->sbi.data; + subscription = e->h.sbi.data; ogs_assert(subscription); SWITCH(message.h.method) CASE(OGS_SBI_HTTP_METHOD_POST) if (message.res_status == OGS_SBI_HTTP_STATUS_CREATED || message.res_status == OGS_SBI_HTTP_STATUS_OK) { - bsf_nnrf_handle_nf_status_subscribe( + ogs_nnrf_handle_nf_status_subscribe( subscription, &message); } else { ogs_error("HTTP response error : %d", @@ -269,7 +269,7 @@ void bsf_state_operational(ogs_fsm_t *s, bsf_event_t *e) CASE(OGS_SBI_SERVICE_NAME_NNRF_DISC) SWITCH(message.h.resource.component[0]) CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - sbi_xact = e->sbi.data; + sbi_xact = e->h.sbi.data; ogs_assert(sbi_xact); SWITCH(message.h.method) @@ -303,27 +303,27 @@ void bsf_state_operational(ogs_fsm_t *s, bsf_event_t *e) ogs_sbi_response_free(response); break; - case BSF_EVT_SBI_TIMER: + case OGS_EVENT_SBI_TIMER: ogs_assert(e); - switch(e->timer_id) { - case BSF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - case BSF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - case BSF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - case BSF_TIMER_NF_INSTANCE_VALIDITY: - nf_instance = e->sbi.data; + switch(e->h.timer_id) { + case OGS_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: + case OGS_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: + case OGS_TIMER_NF_INSTANCE_NO_HEARTBEAT: + case OGS_TIMER_NF_INSTANCE_VALIDITY: + nf_instance = e->h.sbi.data; ogs_assert(nf_instance); ogs_assert(OGS_FSM_STATE(&nf_instance->sm)); ogs_fsm_dispatch(&nf_instance->sm, e); - if (OGS_FSM_CHECK(&nf_instance->sm, bsf_nf_state_exception)) + if (OGS_FSM_CHECK(&nf_instance->sm, ogs_sbi_nf_state_exception)) ogs_error("[%s:%s] State machine exception [%d]", OpenAPI_nf_type_ToString(nf_instance->nf_type), - nf_instance->id, e->timer_id); + nf_instance->id, e->h.timer_id); break; - case BSF_TIMER_SUBSCRIPTION_VALIDITY: - subscription = e->sbi.data; + case OGS_TIMER_SUBSCRIPTION_VALIDITY: + subscription = e->h.sbi.data; ogs_assert(subscription); ogs_assert(ogs_sbi_self()->nf_instance); @@ -337,8 +337,8 @@ void bsf_state_operational(ogs_fsm_t *s, bsf_event_t *e) ogs_sbi_subscription_remove(subscription); break; - case BSF_TIMER_SBI_CLIENT_WAIT: - sbi_xact = e->sbi.data; + case OGS_TIMER_SBI_CLIENT_WAIT: + sbi_xact = e->h.sbi.data; ogs_assert(sbi_xact); stream = sbi_xact->assoc_stream; @@ -358,7 +358,7 @@ void bsf_state_operational(ogs_fsm_t *s, bsf_event_t *e) default: ogs_error("Unknown timer[%s:%d]", - bsf_timer_get_name(e->timer_id), e->timer_id); + ogs_timer_get_name(e->h.timer_id), e->h.timer_id); } break; diff --git a/src/bsf/bsf-sm.h b/src/bsf/bsf-sm.h index e4808f16e..bcaf878de 100644 --- a/src/bsf/bsf-sm.h +++ b/src/bsf/bsf-sm.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -31,16 +31,6 @@ void bsf_state_final(ogs_fsm_t *s, bsf_event_t *e); void bsf_state_operational(ogs_fsm_t *s, bsf_event_t *e); void bsf_state_exception(ogs_fsm_t *s, bsf_event_t *e); -void bsf_nf_fsm_init(ogs_sbi_nf_instance_t *nf_instance); -void bsf_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance); - -void bsf_nf_state_initial(ogs_fsm_t *s, bsf_event_t *e); -void bsf_nf_state_final(ogs_fsm_t *s, bsf_event_t *e); -void bsf_nf_state_will_register(ogs_fsm_t *s, bsf_event_t *e); -void bsf_nf_state_registered(ogs_fsm_t *s, bsf_event_t *e); -void bsf_nf_state_de_registered(ogs_fsm_t *s, bsf_event_t *e); -void bsf_nf_state_exception(ogs_fsm_t *s, bsf_event_t *e); - #define bsf_sm_debug(__pe) \ ogs_debug("%s(): %s", __func__, bsf_event_get_name(__pe)) diff --git a/src/bsf/context.c b/src/bsf/context.c index 3d75d356c..de66aae83 100644 --- a/src/bsf/context.c +++ b/src/bsf/context.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * diff --git a/src/bsf/context.h b/src/bsf/context.h index 976f69f10..f62da657c 100644 --- a/src/bsf/context.h +++ b/src/bsf/context.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -23,7 +23,6 @@ #include "ogs-sbi.h" #include "ogs-app.h" -#include "timer.h" #include "bsf-sm.h" #ifdef __cplusplus @@ -42,22 +41,6 @@ typedef struct bsf_context_s { ogs_list_t sess_list; } bsf_context_t; -#define BSF_NF_INSTANCE_CLEAR(_cAUSE, _nFInstance) \ - do { \ - ogs_assert(_nFInstance); \ - if ((_nFInstance)->reference_count == 1) { \ - ogs_info("[%s] (%s) NF removed", (_nFInstance)->id, (_cAUSE)); \ - bsf_nf_fsm_fini((_nFInstance)); \ - ogs_sbi_nf_instance_remove(_nFInstance); \ - } else { \ - /* There is an assocation with other context */ \ - ogs_info("[%s:%d] (%s) NF suspended", \ - _nFInstance->id, _nFInstance->reference_count, (_cAUSE)); \ - OGS_FSM_TRAN(&_nFInstance->sm, bsf_nf_state_de_registered); \ - ogs_fsm_dispatch(&_nFInstance->sm, NULL); \ - } \ - } while(0) - typedef struct bsf_sess_s bsf_sess_t; typedef struct bsf_sess_s { diff --git a/src/bsf/event.c b/src/bsf/event.c index 7f65f76c3..9fb504767 100644 --- a/src/bsf/event.c +++ b/src/bsf/event.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -18,60 +18,42 @@ */ #include "event.h" -#include "context.h" -static OGS_POOL(pool, bsf_event_t); - -void bsf_event_init(void) -{ - ogs_pool_init(&pool, ogs_app()->pool.event); -} - -void bsf_event_final(void) -{ - ogs_pool_final(&pool); -} - -bsf_event_t *bsf_event_new(bsf_event_e id) +bsf_event_t *bsf_event_new(int id) { bsf_event_t *e = NULL; - ogs_pool_alloc(&pool, &e); + e = ogs_event_size(id, sizeof(bsf_event_t)); ogs_assert(e); - memset(e, 0, sizeof(*e)); - e->id = id; + e->h.id = id; return e; } -void bsf_event_free(bsf_event_t *e) -{ - ogs_assert(e); - ogs_pool_free(&pool, e); -} - const char *bsf_event_get_name(bsf_event_t *e) { - if (e == NULL) + if (e == NULL) { return OGS_FSM_NAME_INIT_SIG; - - switch (e->id) { - case OGS_FSM_ENTRY_SIG: - return OGS_FSM_NAME_ENTRY_SIG; - case OGS_FSM_EXIT_SIG: - return OGS_FSM_NAME_EXIT_SIG; - - case BSF_EVT_SBI_SERVER: - return "BSF_EVT_SBI_SERVER"; - case BSF_EVT_SBI_CLIENT: - return "BSF_EVT_SBI_CLIENT"; - case BSF_EVT_SBI_TIMER: - return "BSF_EVT_SBI_TIMER"; - - default: - break; } + switch (e->h.id) { + case OGS_FSM_ENTRY_SIG: + return OGS_FSM_NAME_ENTRY_SIG; + case OGS_FSM_EXIT_SIG: + return OGS_FSM_NAME_EXIT_SIG; + + case OGS_EVENT_SBI_SERVER: + return OGS_EVENT_NAME_SBI_SERVER; + case OGS_EVENT_SBI_CLIENT: + return OGS_EVENT_NAME_SBI_CLIENT; + case OGS_EVENT_SBI_TIMER: + return OGS_EVENT_NAME_SBI_TIMER; + + default: + break; + } + + ogs_error("Unknown Event[%d]", e->h.id); return "UNKNOWN_EVENT"; } diff --git a/src/bsf/event.h b/src/bsf/event.h index f466b06c1..027d5cbba 100644 --- a/src/bsf/event.h +++ b/src/bsf/event.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -20,51 +20,20 @@ #ifndef BSF_EVENT_H #define BSF_EVENT_H -#include "ogs-core.h" +#include "ogs-proto.h" #ifdef __cplusplus extern "C" { #endif typedef struct bsf_sess_s bsf_sess_t; -typedef struct ogs_sbi_request_s ogs_sbi_request_t; -typedef struct ogs_sbi_response_s ogs_sbi_response_t; -typedef struct ogs_sbi_message_s ogs_sbi_message_t; -typedef struct ogs_sbi_subscription_s ogs_sbi_subscription_t; - -typedef enum { - BSF_EVT_BASE = OGS_FSM_USER_SIG, - - BSF_EVT_SBI_SERVER, - BSF_EVT_SBI_CLIENT, - BSF_EVT_SBI_TIMER, - - BSF_EVT_TOP, - -} bsf_event_e; typedef struct bsf_event_s { - int id; - ogs_pkbuf_t *pkbuf; - int timer_id; - - struct { - ogs_sbi_request_t *request; - ogs_sbi_response_t *response; - void *data; - int state; - - ogs_sbi_message_t *message; - } sbi; - + ogs_event_t h; bsf_sess_t *sess; } bsf_event_t; -void bsf_event_init(void); -void bsf_event_final(void); - -bsf_event_t *bsf_event_new(bsf_event_e id); -void bsf_event_free(bsf_event_t *e); +bsf_event_t *bsf_event_new(int id); const char *bsf_event_get_name(bsf_event_t *e); diff --git a/src/bsf/init.c b/src/bsf/init.c index 247cd86ea..63aa84481 100644 --- a/src/bsf/init.c +++ b/src/bsf/init.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -32,7 +32,6 @@ int bsf_initialize() ogs_sbi_context_init(); bsf_context_init(); - bsf_event_init(); rv = ogs_sbi_context_parse_config("bsf", "nrf", "scp"); if (rv != OGS_OK) return rv; @@ -63,7 +62,7 @@ static void event_termination(void) /* Sending NF Instance De-registeration to NRF */ ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) - bsf_nf_fsm_fini(nf_instance); + ogs_sbi_nf_fsm_fini(nf_instance); /* Starting holding timer */ t_termination_holding = ogs_timer_add(ogs_app()->timer_mgr, NULL, NULL); @@ -90,8 +89,6 @@ void bsf_terminate(void) bsf_context_final(); ogs_sbi_context_final(); - - bsf_event_final(); /* Destroy event */ } static void bsf_main(void *data) @@ -99,8 +96,7 @@ static void bsf_main(void *data) ogs_fsm_t bsf_sm; int rv; - ogs_fsm_create(&bsf_sm, bsf_state_initial, bsf_state_final); - ogs_fsm_init(&bsf_sm, 0); + ogs_fsm_init(&bsf_sm, bsf_state_initial, bsf_state_final, 0); for ( ;; ) { ogs_pollset_poll(ogs_app()->pollset, @@ -133,11 +129,10 @@ static void bsf_main(void *data) ogs_assert(e); ogs_fsm_dispatch(&bsf_sm, e); - bsf_event_free(e); + ogs_event_free(e); } } done: ogs_fsm_fini(&bsf_sm, 0); - ogs_fsm_delete(&bsf_sm); } diff --git a/src/bsf/meson.build b/src/bsf/meson.build index 6f51df030..24ae8340e 100644 --- a/src/bsf/meson.build +++ b/src/bsf/meson.build @@ -1,4 +1,4 @@ -# Copyright (C) 2019,2020 by Sukchan Lee +# Copyright (C) 2019-2022 by Sukchan Lee # This file is part of Open5GS. @@ -18,12 +18,8 @@ libbsf_sources = files(''' context.c event.c - timer.c - nnrf-build.c nnrf-handler.c - nf-sm.c - nbsf-handler.c sbi-path.c diff --git a/src/bsf/nbsf-handler.c b/src/bsf/nbsf-handler.c index 661d9ace9..ff3aa4516 100644 --- a/src/bsf/nbsf-handler.c +++ b/src/bsf/nbsf-handler.c @@ -34,10 +34,6 @@ bool bsf_nbsf_management_handle_pcf_binding( OpenAPI_pcf_binding_t *RecvPcfBinding = NULL; OpenAPI_pcf_binding_t SendPcfBinding; OpenAPI_snssai_t Snssai; -#if SBI_FQDN_WITH_ONE_OCTET_LENGTH - char fqdn[OGS_MAX_FQDN_LEN+1]; - int fqdn_len; -#endif ogs_assert(stream); ogs_assert(recvmsg); @@ -103,22 +99,10 @@ bool bsf_nbsf_management_handle_pcf_binding( bsf_sess_set_ipv6prefix(sess, RecvPcfBinding->ipv6_prefix); if (RecvPcfBinding->pcf_fqdn) { -#if SBI_FQDN_WITH_ONE_OCTET_LENGTH - ogs_assert(0 < ogs_fqdn_parse( - fqdn, RecvPcfBinding->pcf_fqdn, - ogs_min(strlen(RecvPcfBinding->pcf_fqdn), - OGS_MAX_FQDN_LEN))); - - if (sess->pcf_fqdn) - ogs_free(sess->pcf_fqdn); - sess->pcf_fqdn = ogs_strdup(fqdn); - ogs_assert(sess->pcf_fqdn); -#else if (sess->pcf_fqdn) ogs_free(sess->pcf_fqdn); sess->pcf_fqdn = ogs_strdup(RecvPcfBinding->pcf_fqdn); ogs_assert(sess->pcf_fqdn); -#endif } PcfIpEndPointList = RecvPcfBinding->pcf_ip_end_points; @@ -232,18 +216,8 @@ bool bsf_nbsf_management_handle_pcf_binding( PcfIpEndPointList = OpenAPI_list_create(); ogs_assert(PcfIpEndPointList); - if (sess->pcf_fqdn && strlen(sess->pcf_fqdn)) { -#if SBI_FQDN_WITH_ONE_OCTET_LENGTH - memset(fqdn, 0, sizeof(fqdn)); - fqdn_len = ogs_fqdn_build(fqdn, - sess->pcf_fqdn, strlen(sess->pcf_fqdn)); - SendPcfBinding.pcf_fqdn = ogs_memdup(fqdn, fqdn_len+1); - ogs_assert(SendPcfBinding.pcf_fqdn); - SendPcfBinding.pcf_fqdn[fqdn_len] = 0; -#else + if (sess->pcf_fqdn && strlen(sess->pcf_fqdn)) SendPcfBinding.pcf_fqdn = ogs_strdup(sess->pcf_fqdn); -#endif - } for (i = 0; i < sess->num_of_pcf_ip; i++) { OpenAPI_ip_end_point_t *PcfIpEndPoint = NULL; diff --git a/src/bsf/nnrf-build.c b/src/bsf/nnrf-build.c deleted file mode 100644 index cf21a1988..000000000 --- a/src/bsf/nnrf-build.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2019,2020 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "nnrf-build.h" - -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; - - OpenAPI_nf_profile_t *NFProfile = 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_PUT; - message.h.service.name = (char *)OGS_SBI_SERVICE_NAME_NNRF_NFM; - 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] = nf_instance->id; - - message.http.content_encoding = (char*)ogs_sbi_self()->content_encoding; - - NFProfile = ogs_nnrf_nfm_build_nf_profile(); - ogs_expect_or_return_val(NFProfile, NULL); - - message.NFProfile = NFProfile; - - request = ogs_sbi_build_request(&message); - - ogs_sbi_nnrf_free_nf_profile(NFProfile); - - return request; -} diff --git a/src/bsf/nnrf-build.h b/src/bsf/nnrf-build.h deleted file mode 100644 index f5333abd9..000000000 --- a/src/bsf/nnrf-build.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2019,2020 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef BSF_NNRF_BUILD_H -#define BSF_NNRF_BUILD_H - -#include "context.h" - -#ifdef __cplusplus -extern "C" { -#endif - -ogs_sbi_request_t *bsf_nnrf_nfm_build_register(void); - -#ifdef __cplusplus -} -#endif - -#endif /* BSF_NNRF_BUILD_H */ diff --git a/src/bsf/nnrf-handler.c b/src/bsf/nnrf-handler.c index 8722ae0f4..13065dd01 100644 --- a/src/bsf/nnrf-handler.c +++ b/src/bsf/nnrf-handler.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -20,244 +20,14 @@ #include "sbi-path.h" #include "nnrf-handler.h" -void bsf_nnrf_handle_nf_register( - ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_message_t *recvmsg) -{ - OpenAPI_nf_profile_t *NFProfile = NULL; - ogs_sbi_client_t *client = NULL; - - ogs_assert(recvmsg); - ogs_assert(nf_instance); - client = nf_instance->client; - ogs_assert(client); - - NFProfile = recvmsg->NFProfile; - if (!NFProfile) { - ogs_error("No NFProfile"); - return; - } - - /* TIME : Update heartbeat from NRF */ - if (NFProfile->is_heart_beat_timer == true) - nf_instance->time.heartbeat_interval = NFProfile->heart_beat_timer; -} - -void bsf_nnrf_handle_nf_status_subscribe( - ogs_sbi_subscription_t *subscription, ogs_sbi_message_t *recvmsg) -{ - OpenAPI_subscription_data_t *SubscriptionData = NULL; - ogs_sbi_client_t *client = NULL; - - ogs_assert(recvmsg); - ogs_assert(subscription); - client = subscription->client; - ogs_assert(client); - - SubscriptionData = recvmsg->SubscriptionData; - if (!SubscriptionData) { - ogs_error("No SubscriptionData"); - return; - } - - if (!SubscriptionData->subscription_id) { - ogs_error("No SubscriptionId"); - return; - } - ogs_sbi_subscription_set_id( - subscription, SubscriptionData->subscription_id); - - if (SubscriptionData->validity_time) { -#define VALIDITY_MINIMUM (10LL * OGS_USEC_PER_SEC) /* 10 seconds */ - ogs_time_t time, duration; - if (ogs_sbi_time_from_string( - &time, SubscriptionData->validity_time) == true) { - duration = time - ogs_time_now(); - if (duration < VALIDITY_MINIMUM) { - duration = VALIDITY_MINIMUM; - ogs_warn("[%s] Forced to %lld seconds", subscription->id, - (long long)ogs_time_sec(VALIDITY_MINIMUM)); - } - subscription->t_validity = ogs_timer_add(ogs_app()->timer_mgr, - bsf_timer_subscription_validity, subscription); - ogs_assert(subscription->t_validity); - ogs_timer_start(subscription->t_validity, duration); - } else { - ogs_error("Cannot parse validitiyTime [%s]", - SubscriptionData->validity_time); - } - } -} - -bool bsf_nnrf_handle_nf_status_notify( - ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) -{ - int rv; - bool handled; - - ogs_sbi_response_t *response = NULL; - OpenAPI_notification_data_t *NotificationData = NULL; - ogs_sbi_nf_instance_t *nf_instance = NULL; - - ogs_sbi_message_t message; - ogs_sbi_header_t header; - - ogs_assert(stream); - ogs_assert(recvmsg); - - NotificationData = recvmsg->NotificationData; - if (!NotificationData) { - ogs_error("No NotificationData"); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "No NotificationData", NULL)); - return false; - } - - if (!NotificationData->nf_instance_uri) { - ogs_error("No nfInstanceUri"); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "No nfInstanceUri", NULL)); - return false; - } - - memset(&header, 0, sizeof(header)); - header.uri = NotificationData->nf_instance_uri; - - rv = ogs_sbi_parse_header(&message, &header); - if (rv != OGS_OK) { - ogs_error("Cannot parse nfInstanceUri [%s]", header.uri); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Cannot parse nfInstanceUri", header.uri)); - return false; - } - - if (!message.h.resource.component[1]) { - ogs_error("No nfInstanceId [%s]", header.uri); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Cannot parse nfInstanceUri", header.uri)); - ogs_sbi_header_free(&header); - return false; - } - - if (NF_INSTANCE_IS_SELF(message.h.resource.component[1])) { - ogs_warn("[%s] The notification is not allowed", - message.h.resource.component[1]); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, - recvmsg, "The notification is not allowed", - message.h.resource.component[1])); - ogs_sbi_header_free(&header); - return false; - } - - if (NotificationData->event == - OpenAPI_notification_event_type_NF_REGISTERED) { - - OpenAPI_nf_profile_t *NFProfile = NULL; - - NFProfile = NotificationData->nf_profile; - if (!NFProfile) { - ogs_error("No NFProfile"); - ogs_assert(true == - ogs_sbi_server_send_error( - stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "No NFProfile", NULL)); - ogs_sbi_header_free(&header); - return false; - } - - nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); - if (!nf_instance) { - 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); - - ogs_info("[%s] (NRF-notify) NF registered", nf_instance->id); - - } else { - OGS_FSM_TRAN(&nf_instance->sm, bsf_nf_state_registered); - ogs_fsm_dispatch(&nf_instance->sm, NULL); - - ogs_warn("[%s] (NRF-notify) NF has already been added", - message.h.resource.component[1]); - - } - - handled = ogs_sbi_nnrf_handle_nf_profile( - nf_instance, NFProfile, stream, recvmsg); - if (!handled) { - BSF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); - ogs_sbi_header_free(&header); - return false; - } - - ogs_info("[%s] (NRF-notify) NF Profile updated", nf_instance->id); - - handled = ogs_sbi_client_associate(nf_instance); - if (!handled) { - ogs_error("[%s] Cannot associate NF EndPoint", nf_instance->id); - ogs_assert(true == - ogs_sbi_server_send_error(stream, - OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Cannot find NF EndPoint", nf_instance->id)); - BSF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); - ogs_sbi_header_free(&header); - return false; - } - - } else if (NotificationData->event == - OpenAPI_notification_event_type_NF_DEREGISTERED) { - nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); - if (nf_instance) { - BSF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); - } else { - ogs_warn("[%s] (NRF-notify) Not found", - message.h.resource.component[1]); - ogs_assert(true == - ogs_sbi_server_send_error(stream, - OGS_SBI_HTTP_STATUS_NOT_FOUND, - recvmsg, "Not found", message.h.resource.component[1])); - ogs_sbi_header_free(&header); - return false; - } - } else { - char *eventstr = OpenAPI_notification_event_type_ToString( - NotificationData->event); - ogs_error("Not supported event [%d:%s]", - NotificationData->event, eventstr ? eventstr : "Unknown"); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Not supported event", - eventstr ? eventstr : "Unknown")); - ogs_sbi_header_free(&header); - return false; - } - - response = ogs_sbi_build_response(recvmsg, OGS_SBI_HTTP_STATUS_NO_CONTENT); - ogs_assert(response); - ogs_assert(true == ogs_sbi_server_send_response(stream, response)); - - ogs_sbi_header_free(&header); - return true; -} - void bsf_nnrf_handle_nf_discover( ogs_sbi_xact_t *xact, ogs_sbi_message_t *recvmsg) { ogs_sbi_object_t *sbi_object = NULL; OpenAPI_nf_type_e target_nf_type = 0; ogs_sbi_discovery_option_t *discovery_option = NULL; - ogs_sbi_nf_instance_t *nf_instance = NULL; OpenAPI_search_result_t *SearchResult = NULL; - OpenAPI_lnode_t *node = NULL; - bool handled; ogs_assert(recvmsg); ogs_assert(xact); @@ -274,64 +44,8 @@ void bsf_nnrf_handle_nf_discover( return; } - OpenAPI_list_for_each(SearchResult->nf_instances, node) { - OpenAPI_nf_profile_t *NFProfile = NULL; - - if (!node->data) continue; - - NFProfile = node->data; - - nf_instance = ogs_sbi_nf_instance_find(NFProfile->nf_instance_id); - if (!nf_instance) { - 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); - - ogs_info("[%s] (NF-discover) NF registered", nf_instance->id); - } else { - OGS_FSM_TRAN(&nf_instance->sm, bsf_nf_state_registered); - ogs_fsm_dispatch(&nf_instance->sm, NULL); - - ogs_warn("[%s] (NF-discover) NF has already been added", - NFProfile->nf_instance_id); - } - - if (NF_INSTANCE_IS_OTHERS(nf_instance->id)) { - handled = ogs_sbi_nnrf_handle_nf_profile( - nf_instance, NFProfile, NULL, NULL); - if (!handled) { - ogs_error("ogs_sbi_nnrf_handle_nf_profile() failed [%s]", - nf_instance->id); - BSF_NF_INSTANCE_CLEAR("NRF-discover", nf_instance); - continue; - } - - handled = ogs_sbi_client_associate(nf_instance); - if (!handled) { - ogs_error("[%s] Cannot assciate NF EndPoint", nf_instance->id); - BSF_NF_INSTANCE_CLEAR("NRF-discover", nf_instance); - continue; - } - - /* TIME : Update validity from NRF */ - if (SearchResult->is_validity_period && - SearchResult->validity_period) { - nf_instance->time.validity_duration = - SearchResult->validity_period; - - ogs_assert(nf_instance->t_validity); - ogs_timer_start(nf_instance->t_validity, - ogs_time_from_sec(nf_instance->time.validity_duration)); - - } else - ogs_warn("[%s] NF Instance validity-time should not 0", - nf_instance->id); - - ogs_info("[%s] (NF-discover) NF Profile updated", nf_instance->id); - } - } + ogs_nnrf_handle_nf_discover_search_result( + sbi_object, target_nf_type, discovery_option, SearchResult); ogs_sbi_select_nf(sbi_object, target_nf_type, discovery_option); diff --git a/src/bsf/nnrf-handler.h b/src/bsf/nnrf-handler.h index fcad53b00..ec5d5a851 100644 --- a/src/bsf/nnrf-handler.h +++ b/src/bsf/nnrf-handler.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -26,14 +26,6 @@ extern "C" { #endif -void bsf_nnrf_handle_nf_register( - ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_message_t *recvmsg); -void bsf_nnrf_handle_nf_status_subscribe( - ogs_sbi_subscription_t *subscription, ogs_sbi_message_t *recvmsg); - -bool bsf_nnrf_handle_nf_status_notify( - ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); - void bsf_nnrf_handle_nf_discover( ogs_sbi_xact_t *xact, ogs_sbi_message_t *recvmsg); diff --git a/src/bsf/sbi-path.c b/src/bsf/sbi-path.c index 1104265c9..5c23c04fc 100644 --- a/src/bsf/sbi-path.c +++ b/src/bsf/sbi-path.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -27,17 +27,17 @@ static int server_cb(ogs_sbi_request_t *request, void *data) ogs_assert(request); ogs_assert(data); - e = bsf_event_new(BSF_EVT_SBI_SERVER); + e = bsf_event_new(OGS_EVENT_SBI_SERVER); ogs_assert(e); - e->sbi.request = request; - e->sbi.data = data; + e->h.sbi.request = request; + e->h.sbi.data = data; rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed:%d", (int)rv); ogs_sbi_request_free(request); - bsf_event_free(e); + ogs_event_free(e); return OGS_ERROR; } @@ -58,16 +58,16 @@ static int client_cb(int status, ogs_sbi_response_t *response, void *data) ogs_assert(response); - e = bsf_event_new(BSF_EVT_SBI_CLIENT); + e = bsf_event_new(OGS_EVENT_SBI_CLIENT); ogs_assert(e); - e->sbi.response = response; - e->sbi.data = data; + e->h.sbi.response = response; + e->h.sbi.data = data; rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed:%d", (int)rv); ogs_sbi_response_free(response); - bsf_event_free(e); + ogs_event_free(e); return OGS_ERROR; } @@ -79,6 +79,10 @@ int bsf_sbi_open(void) ogs_sbi_nf_instance_t *nf_instance = NULL; ogs_sbi_nf_service_t *service = NULL; + /* To be notified when NF Instances registered/deregistered in NRF + * or when their profile is modified */ + ogs_sbi_add_to_be_notified_nf_type(OpenAPI_nf_type_UDM); + /* Add SELF NF instance */ nf_instance = ogs_sbi_self()->nf_instance; ogs_assert(nf_instance); @@ -98,28 +102,20 @@ int bsf_sbi_open(void) } /* Initialize NRF NF Instance */ - ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) { - if (NF_INSTANCE_IS_NRF(nf_instance)) { - ogs_sbi_client_t *client = NULL; + nf_instance = ogs_sbi_self()->nrf_instance; + if (nf_instance) { + ogs_sbi_client_t *client = NULL; - /* Client callback is only used when NF sends to NRF */ - client = nf_instance->client; - ogs_assert(client); - client->cb = client_cb; + /* 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. */ + ogs_sbi_nf_fsm_init(nf_instance); } - /* Timer expiration handler of client wait timer */ - ogs_sbi_self()->client_wait_expire = bsf_timer_sbi_client_wait_expire; - - /* NF register state in NF state machine */ - ogs_sbi_self()->nf_state_registered = - (ogs_fsm_handler_t)bsf_nf_state_registered; - if (ogs_sbi_server_start_all(server_cb) != OGS_OK) return OGS_ERROR; diff --git a/src/bsf/sbi-path.h b/src/bsf/sbi-path.h index 61d17cec2..2d08ed8ad 100644 --- a/src/bsf/sbi-path.h +++ b/src/bsf/sbi-path.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -20,7 +20,7 @@ #ifndef BSF_SBI_PATH_H #define BSF_SBI_PATH_H -#include "nnrf-build.h" +#include "context.h" #ifdef __cplusplus extern "C" { diff --git a/src/bsf/timer.c b/src/bsf/timer.c deleted file mode 100644 index 35e47e936..000000000 --- a/src/bsf/timer.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (C) 2019 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "timer.h" -#include "event.h" -#include "context.h" - -const char *bsf_timer_get_name(bsf_timer_e id) -{ - switch (id) { - case BSF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - return "BSF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL"; - case BSF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - return "BSF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL"; - case BSF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - return "BSF_TIMER_NF_INSTANCE_NO_HEARTBEAT"; - case BSF_TIMER_NF_INSTANCE_VALIDITY: - return "BSF_TIMER_NF_INSTANCE_VALIDITY"; - case BSF_TIMER_SUBSCRIPTION_VALIDITY: - return "BSF_TIMER_SUBSCRIPTION_VALIDITY"; - case BSF_TIMER_SBI_CLIENT_WAIT: - return "BSF_TIMER_SBI_CLIENT_WAIT"; - default: - break; - } - - return "UNKNOWN_TIMER"; -} - -static void timer_send_event(int timer_id, void *data) -{ - int rv; - bsf_event_t *e = NULL; - ogs_assert(data); - - switch (timer_id) { - case BSF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - case BSF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - case BSF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - case BSF_TIMER_NF_INSTANCE_VALIDITY: - case BSF_TIMER_SUBSCRIPTION_VALIDITY: - e = bsf_event_new(BSF_EVT_SBI_TIMER); - ogs_assert(e); - e->timer_id = timer_id; - e->sbi.data = data; - break; - case BSF_TIMER_SBI_CLIENT_WAIT: - e = bsf_event_new(BSF_EVT_SBI_TIMER); - if (!e) { - ogs_sbi_xact_t *sbi_xact = data; - ogs_assert(sbi_xact); - - ogs_error("timer_send_event() failed"); - ogs_sbi_xact_remove(sbi_xact); - return; - } - e->timer_id = timer_id; - e->sbi.data = data; - break; - default: - ogs_fatal("Unknown timer id[%d]", timer_id); - ogs_assert_if_reached(); - break; - } - - rv = ogs_queue_push(ogs_app()->queue, e); - if (rv != OGS_OK) { - ogs_error("ogs_queue_push() failed [%d] in %s", - (int)rv, bsf_timer_get_name(e->timer_id)); - bsf_event_free(e); - } -} - -void bsf_timer_nf_instance_registration_interval(void *data) -{ - timer_send_event(BSF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL, data); -} - -void bsf_timer_nf_instance_heartbeat_interval(void *data) -{ - timer_send_event(BSF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL, data); -} - -void bsf_timer_nf_instance_no_heartbeat(void *data) -{ - timer_send_event(BSF_TIMER_NF_INSTANCE_NO_HEARTBEAT, data); -} - -void bsf_timer_nf_instance_validity(void *data) -{ - timer_send_event(BSF_TIMER_NF_INSTANCE_VALIDITY, data); -} - -void bsf_timer_subscription_validity(void *data) -{ - timer_send_event(BSF_TIMER_SUBSCRIPTION_VALIDITY, data); -} - -void bsf_timer_sbi_client_wait_expire(void *data) -{ - timer_send_event(BSF_TIMER_SBI_CLIENT_WAIT, data); -} diff --git a/src/bsf/timer.h b/src/bsf/timer.h deleted file mode 100644 index 1c7b11d3c..000000000 --- a/src/bsf/timer.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2019 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef BSF_TIMER_H -#define BSF_TIMER_H - -#include "ogs-core.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* forward declaration */ -typedef enum { - BSF_TIMER_BASE = 0, - - BSF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL, - BSF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL, - BSF_TIMER_NF_INSTANCE_NO_HEARTBEAT, - BSF_TIMER_NF_INSTANCE_VALIDITY, - BSF_TIMER_SUBSCRIPTION_VALIDITY, - BSF_TIMER_SBI_CLIENT_WAIT, - - MAX_NUM_OF_BSF_TIMER, - -} bsf_timer_e; - -const char *bsf_timer_get_name(bsf_timer_e id); - -void bsf_timer_nf_instance_registration_interval(void *data); -void bsf_timer_nf_instance_heartbeat_interval(void *data); -void bsf_timer_nf_instance_no_heartbeat(void *data); -void bsf_timer_nf_instance_validity(void *data); -void bsf_timer_subscription_validity(void *data); -void bsf_timer_sbi_client_wait_expire(void *data); - -#ifdef __cplusplus -} -#endif - -#endif /* BSF_TIMER_H */ diff --git a/src/mme/emm-sm.c b/src/mme/emm-sm.c index 24ed763a3..acfa232ed 100644 --- a/src/mme/emm-sm.c +++ b/src/mme/emm-sm.c @@ -109,7 +109,7 @@ static void common_register_state(ogs_fsm_t *s, mme_event_t *e) case OGS_FSM_EXIT_SIG: break; - case MME_EVT_EMM_MESSAGE: + case MME_EVENT_EMM_MESSAGE: message = e->nas_message; ogs_assert(message); @@ -590,7 +590,7 @@ static void common_register_state(ogs_fsm_t *s, mme_event_t *e) } break; - case MME_EVT_EMM_TIMER: + case MME_EVENT_EMM_TIMER: switch (e->timer_id) { case MME_TIMER_T3413: if (mme_ue->t3413.retry_count >= @@ -679,7 +679,7 @@ void emm_state_authentication(ogs_fsm_t *s, mme_event_t *e) break; case OGS_FSM_EXIT_SIG: break; - case MME_EVT_EMM_MESSAGE: + case MME_EVENT_EMM_MESSAGE: message = e->nas_message; ogs_assert(message); @@ -794,7 +794,7 @@ void emm_state_authentication(ogs_fsm_t *s, mme_event_t *e) break; } break; - case MME_EVT_EMM_TIMER: + case MME_EVENT_EMM_TIMER: switch (e->timer_id) { case MME_TIMER_T3460: if (mme_ue->t3460.retry_count >= @@ -850,7 +850,7 @@ void emm_state_security_mode(ogs_fsm_t *s, mme_event_t *e) break; case OGS_FSM_EXIT_SIG: break; - case MME_EVT_EMM_MESSAGE: + case MME_EVENT_EMM_MESSAGE: message = e->nas_message; ogs_assert(message); @@ -966,7 +966,7 @@ void emm_state_security_mode(ogs_fsm_t *s, mme_event_t *e) break; } break; - case MME_EVT_EMM_TIMER: + case MME_EVENT_EMM_TIMER: switch (e->timer_id) { case MME_TIMER_T3460: if (mme_ue->t3460.retry_count >= @@ -1021,7 +1021,7 @@ void emm_state_initial_context_setup(ogs_fsm_t *s, mme_event_t *e) break; case OGS_FSM_EXIT_SIG: break; - case MME_EVT_EMM_MESSAGE: + case MME_EVENT_EMM_MESSAGE: message = e->nas_message; ogs_assert(message); @@ -1159,7 +1159,7 @@ void emm_state_initial_context_setup(ogs_fsm_t *s, mme_event_t *e) break; } break; - case MME_EVT_EMM_TIMER: + case MME_EVENT_EMM_TIMER: switch (e->timer_id) { case MME_TIMER_T3450: if (mme_ue->t3450.retry_count >= @@ -1224,7 +1224,7 @@ void emm_state_exception(ogs_fsm_t *s, mme_event_t *e) case OGS_FSM_EXIT_SIG: break; - case MME_EVT_EMM_MESSAGE: + case MME_EVENT_EMM_MESSAGE: message = e->nas_message; ogs_assert(message); diff --git a/src/mme/esm-sm.c b/src/mme/esm-sm.c index a9ccee7bf..4cb31ac89 100644 --- a/src/mme/esm-sm.c +++ b/src/mme/esm-sm.c @@ -96,7 +96,7 @@ void esm_state_inactive(ogs_fsm_t *s, mme_event_t *e) break; case OGS_FSM_EXIT_SIG: break; - case MME_EVT_ESM_MESSAGE: + case MME_EVENT_ESM_MESSAGE: message = e->nas_message; ogs_assert(message); @@ -221,7 +221,7 @@ void esm_state_inactive(ogs_fsm_t *s, mme_event_t *e) break; } break; - case MME_EVT_ESM_TIMER: + case MME_EVENT_ESM_TIMER: switch (e->timer_id) { case MME_TIMER_T3489: if (bearer->t3489.retry_count >= @@ -281,7 +281,7 @@ void esm_state_active(ogs_fsm_t *s, mme_event_t *e) break; case OGS_FSM_EXIT_SIG: break; - case MME_EVT_ESM_MESSAGE: + case MME_EVENT_ESM_MESSAGE: message = e->nas_message; ogs_assert(message); @@ -382,7 +382,7 @@ void esm_state_pdn_will_disconnect(ogs_fsm_t *s, mme_event_t *e) break; case OGS_FSM_EXIT_SIG: break; - case MME_EVT_ESM_MESSAGE: + case MME_EVENT_ESM_MESSAGE: message = e->nas_message; ogs_assert(message); diff --git a/src/mme/mme-context.c b/src/mme/mme-context.c index 9fcdc3e8e..a564d0802 100644 --- a/src/mme/mme-context.c +++ b/src/mme/mme-context.c @@ -1831,8 +1831,7 @@ mme_enb_t *mme_enb_add(ogs_sock_t *sock, ogs_sockaddr_t *addr) memset(&e, 0, sizeof(e)); e.enb = enb; - ogs_fsm_create(&enb->sm, s1ap_state_initial, s1ap_state_final); - ogs_fsm_init(&enb->sm, &e); + ogs_fsm_init(&enb->sm, s1ap_state_initial, s1ap_state_final, &e); ogs_list_add(&self.enb_list, enb); mme_metrics_inst_global_inc(MME_METR_GLOB_GAUGE_ENB); @@ -1855,7 +1854,6 @@ int mme_enb_remove(mme_enb_t *enb) memset(&e, 0, sizeof(e)); e.enb = enb; ogs_fsm_fini(&enb->sm, &e); - ogs_fsm_delete(&enb->sm); ogs_hash_set(self.enb_addr_hash, enb->sctp.addr, sizeof(ogs_sockaddr_t), NULL); @@ -2399,8 +2397,7 @@ void mme_ue_fsm_init(mme_ue_t *mme_ue) memset(&e, 0, sizeof(e)); e.mme_ue = mme_ue; - ogs_fsm_create(&mme_ue->sm, emm_state_initial, emm_state_final); - ogs_fsm_init(&mme_ue->sm, &e); + ogs_fsm_init(&mme_ue->sm, emm_state_initial, emm_state_final, &e); } void mme_ue_fsm_fini(mme_ue_t *mme_ue) @@ -2412,7 +2409,6 @@ void mme_ue_fsm_fini(mme_ue_t *mme_ue) memset(&e, 0, sizeof(e)); e.mme_ue = mme_ue; ogs_fsm_fini(&mme_ue->sm, &e); - ogs_fsm_delete(&mme_ue->sm); } mme_ue_t *mme_ue_find_by_imsi_bcd(char *imsi_bcd) @@ -3004,8 +3000,7 @@ mme_bearer_t *mme_bearer_add(mme_sess_t *sess) memset(&e, 0, sizeof(e)); e.bearer = bearer; - ogs_fsm_create(&bearer->sm, esm_state_initial, esm_state_final); - ogs_fsm_init(&bearer->sm, &e); + ogs_fsm_init(&bearer->sm, esm_state_initial, esm_state_final, &e); return bearer; } @@ -3021,7 +3016,6 @@ void mme_bearer_remove(mme_bearer_t *bearer) memset(&e, 0, sizeof(e)); e.bearer = bearer; ogs_fsm_fini(&bearer->sm, &e); - ogs_fsm_delete(&bearer->sm); CLEAR_BEARER_ALL_TIMERS(bearer); ogs_timer_delete(bearer->t3489.timer); diff --git a/src/mme/mme-event.c b/src/mme/mme-event.c index b5482a853..4ea8050e6 100644 --- a/src/mme/mme-event.c +++ b/src/mme/mme-event.c @@ -60,42 +60,42 @@ const char *mme_event_get_name(mme_event_t *e) case OGS_FSM_EXIT_SIG: return OGS_FSM_NAME_EXIT_SIG; - case MME_EVT_S1AP_MESSAGE: - return "MME_EVT_S1AP_MESSAGE"; - case MME_EVT_S1AP_TIMER: - return "MME_EVT_S1AP_TIMER"; - case MME_EVT_S1AP_LO_ACCEPT: - return "MME_EVT_S1AP_LO_ACCEPT"; - case MME_EVT_S1AP_LO_SCTP_COMM_UP: - return "MME_EVT_S1AP_LO_SCTP_COMM_UP"; - case MME_EVT_S1AP_LO_CONNREFUSED: - return "MME_EVT_S1AP_LO_CONNREFUSED"; + case MME_EVENT_S1AP_MESSAGE: + return "MME_EVENT_S1AP_MESSAGE"; + case MME_EVENT_S1AP_TIMER: + return "MME_EVENT_S1AP_TIMER"; + case MME_EVENT_S1AP_LO_ACCEPT: + return "MME_EVENT_S1AP_LO_ACCEPT"; + case MME_EVENT_S1AP_LO_SCTP_COMM_UP: + return "MME_EVENT_S1AP_LO_SCTP_COMM_UP"; + case MME_EVENT_S1AP_LO_CONNREFUSED: + return "MME_EVENT_S1AP_LO_CONNREFUSED"; - case MME_EVT_EMM_MESSAGE: - return "MME_EVT_EMM_MESSAGE"; - case MME_EVT_EMM_TIMER: - return "MME_EVT_EMM_TIMER"; - case MME_EVT_ESM_MESSAGE: - return "MME_EVT_ESM_MESSAGE"; - case MME_EVT_ESM_TIMER: - return "MME_EVT_ESM_TIMER"; - case MME_EVT_S11_MESSAGE: - return "MME_EVT_S11_MESSAGE"; - case MME_EVT_S11_TIMER: - return "MME_EVT_S11_TIMER"; - case MME_EVT_S6A_MESSAGE: - return "MME_EVT_S6A_MESSAGE"; - case MME_EVT_S6A_TIMER: - return "MME_EVT_S6A_TIMER"; + case MME_EVENT_EMM_MESSAGE: + return "MME_EVENT_EMM_MESSAGE"; + case MME_EVENT_EMM_TIMER: + return "MME_EVENT_EMM_TIMER"; + case MME_EVENT_ESM_MESSAGE: + return "MME_EVENT_ESM_MESSAGE"; + case MME_EVENT_ESM_TIMER: + return "MME_EVENT_ESM_TIMER"; + case MME_EVENT_S11_MESSAGE: + return "MME_EVENT_S11_MESSAGE"; + case MME_EVENT_S11_TIMER: + return "MME_EVENT_S11_TIMER"; + case MME_EVENT_S6A_MESSAGE: + return "MME_EVENT_S6A_MESSAGE"; + case MME_EVENT_S6A_TIMER: + return "MME_EVENT_S6A_TIMER"; - case MME_EVT_SGSAP_MESSAGE: - return "MME_EVT_SGSAP_MESSAGE"; - case MME_EVT_SGSAP_TIMER: - return "MME_EVT_SGSAP_TIMER"; - case MME_EVT_SGSAP_LO_SCTP_COMM_UP: - return "MME_EVT_SGSAP_LO_SCTP_COMM_UP"; - case MME_EVT_SGSAP_LO_CONNREFUSED: - return "MME_EVT_SGSAP_LO_CONNREFUSED"; + case MME_EVENT_SGSAP_MESSAGE: + return "MME_EVENT_SGSAP_MESSAGE"; + case MME_EVENT_SGSAP_TIMER: + return "MME_EVENT_SGSAP_TIMER"; + case MME_EVENT_SGSAP_LO_SCTP_COMM_UP: + return "MME_EVENT_SGSAP_LO_SCTP_COMM_UP"; + case MME_EVENT_SGSAP_LO_CONNREFUSED: + return "MME_EVENT_SGSAP_LO_CONNREFUSED"; default: break; diff --git a/src/mme/mme-event.h b/src/mme/mme-event.h index 38af33c47..8cdef31da 100644 --- a/src/mme/mme-event.h +++ b/src/mme/mme-event.h @@ -20,7 +20,7 @@ #ifndef MME_EVENT_H #define MME_EVENT_H -#include "ogs-core.h" +#include "ogs-proto.h" #ifdef __cplusplus extern "C" { @@ -28,29 +28,29 @@ extern "C" { /* forward declaration */ typedef enum { - MME_EVT_BASE = OGS_FSM_USER_SIG, + MME_EVENT_BASE = OGS_MAX_NUM_OF_PROTO_EVENT, - MME_EVT_S1AP_MESSAGE, - MME_EVT_S1AP_TIMER, - MME_EVT_S1AP_LO_ACCEPT, - MME_EVT_S1AP_LO_SCTP_COMM_UP, - MME_EVT_S1AP_LO_CONNREFUSED, + MME_EVENT_S1AP_MESSAGE, + MME_EVENT_S1AP_TIMER, + MME_EVENT_S1AP_LO_ACCEPT, + MME_EVENT_S1AP_LO_SCTP_COMM_UP, + MME_EVENT_S1AP_LO_CONNREFUSED, - MME_EVT_EMM_MESSAGE, - MME_EVT_EMM_TIMER, - MME_EVT_ESM_MESSAGE, - MME_EVT_ESM_TIMER, - MME_EVT_S11_MESSAGE, - MME_EVT_S11_TIMER, - MME_EVT_S6A_MESSAGE, - MME_EVT_S6A_TIMER, + MME_EVENT_EMM_MESSAGE, + MME_EVENT_EMM_TIMER, + MME_EVENT_ESM_MESSAGE, + MME_EVENT_ESM_TIMER, + MME_EVENT_S11_MESSAGE, + MME_EVENT_S11_TIMER, + MME_EVENT_S6A_MESSAGE, + MME_EVENT_S6A_TIMER, - MME_EVT_SGSAP_MESSAGE, - MME_EVT_SGSAP_TIMER, - MME_EVT_SGSAP_LO_SCTP_COMM_UP, - MME_EVT_SGSAP_LO_CONNREFUSED, + MME_EVENT_SGSAP_MESSAGE, + MME_EVENT_SGSAP_TIMER, + MME_EVENT_SGSAP_LO_SCTP_COMM_UP, + MME_EVENT_SGSAP_LO_CONNREFUSED, - MME_EVT_TOP, + MAX_NUM_OF_MME_EVENT, } mme_event_e; @@ -69,9 +69,10 @@ typedef struct ogs_gtp_node_s ogs_gtp_node_t; typedef struct mme_event_s { int id; - ogs_pkbuf_t *pkbuf; int timer_id; + ogs_pkbuf_t *pkbuf; + ogs_sock_t *sock; ogs_sockaddr_t *addr; diff --git a/src/mme/mme-fd-path.c b/src/mme/mme-fd-path.c index e17ce8cfb..f2d2bef61 100644 --- a/src/mme/mme-fd-path.c +++ b/src/mme/mme-fd-path.c @@ -376,7 +376,7 @@ static void mme_s6a_aia_cb(void *data, struct msg **msg) out: if (!error) { int rv; - e = mme_event_new(MME_EVT_S6A_MESSAGE); + e = mme_event_new(MME_EVENT_S6A_MESSAGE); ogs_assert(e); e->mme_ue = mme_ue; e->s6a_message = s6a_message; @@ -1344,7 +1344,7 @@ static void mme_s6a_ula_cb(void *data, struct msg **msg) if (!error) { int rv; - e = mme_event_new(MME_EVT_S6A_MESSAGE); + e = mme_event_new(MME_EVENT_S6A_MESSAGE); ogs_assert(e); e->mme_ue = mme_ue; e->s6a_message = s6a_message; @@ -1501,7 +1501,7 @@ static int mme_ogs_diam_s6a_clr_cb( struct msg **msg, struct avp *avp, ogs_diam_logger_self()->stats.nb_echoed++; ogs_assert( pthread_mutex_unlock(&ogs_diam_logger_self()->stats_lock) == 0); - e = mme_event_new(MME_EVT_S6A_MESSAGE); + e = mme_event_new(MME_EVENT_S6A_MESSAGE); ogs_assert(e); e->mme_ue = mme_ue; e->s6a_message = s6a_message; diff --git a/src/mme/mme-gtp-path.c b/src/mme/mme-gtp-path.c index 688a0aaac..677c59ce0 100644 --- a/src/mme/mme-gtp-path.c +++ b/src/mme/mme-gtp-path.c @@ -61,7 +61,7 @@ static void _gtpv2_c_recv_cb(short when, ogs_socket_t fd, void *data) } ogs_assert(sgw); - e = mme_event_new(MME_EVT_S11_MESSAGE); + e = mme_event_new(MME_EVENT_S11_MESSAGE); ogs_assert(e); e->gnode = (ogs_gtp_node_t *)sgw; e->pkbuf = pkbuf; diff --git a/src/mme/mme-init.c b/src/mme/mme-init.c index b389cc97c..44e4f3ec9 100644 --- a/src/mme/mme-init.c +++ b/src/mme/mme-init.c @@ -114,8 +114,7 @@ static void mme_main(void *data) ogs_fsm_t mme_sm; int rv; - ogs_fsm_create(&mme_sm, mme_state_initial, mme_state_final); - ogs_fsm_init(&mme_sm, 0); + ogs_fsm_init(&mme_sm, mme_state_initial, mme_state_final, 0); for ( ;; ) { ogs_pollset_poll(ogs_app()->pollset, @@ -154,5 +153,4 @@ static void mme_main(void *data) done: ogs_fsm_fini(&mme_sm, 0); - ogs_fsm_delete(&mme_sm); } diff --git a/src/mme/mme-sm.c b/src/mme/mme-sm.c index 58edee6ef..765305358 100644 --- a/src/mme/mme-sm.c +++ b/src/mme/mme-sm.c @@ -94,7 +94,7 @@ void mme_state_operational(ogs_fsm_t *s, mme_event_t *e) case OGS_FSM_EXIT_SIG: break; - case MME_EVT_S1AP_LO_ACCEPT: + case MME_EVENT_S1AP_LO_ACCEPT: sock = e->sock; ogs_assert(sock); addr = e->addr; @@ -120,7 +120,7 @@ void mme_state_operational(ogs_fsm_t *s, mme_event_t *e) break; - case MME_EVT_S1AP_LO_SCTP_COMM_UP: + case MME_EVENT_S1AP_LO_SCTP_COMM_UP: sock = e->sock; ogs_assert(sock); addr = e->addr; @@ -150,7 +150,7 @@ void mme_state_operational(ogs_fsm_t *s, mme_event_t *e) break; - case MME_EVT_S1AP_LO_CONNREFUSED: + case MME_EVENT_S1AP_LO_CONNREFUSED: sock = e->sock; ogs_assert(sock); addr = e->addr; @@ -172,7 +172,7 @@ void mme_state_operational(ogs_fsm_t *s, mme_event_t *e) ogs_free(addr); break; - case MME_EVT_S1AP_MESSAGE: + case MME_EVENT_S1AP_MESSAGE: sock = e->sock; ogs_assert(sock); addr = e->addr; @@ -206,7 +206,7 @@ void mme_state_operational(ogs_fsm_t *s, mme_event_t *e) ogs_pkbuf_free(pkbuf); break; - case MME_EVT_S1AP_TIMER: + case MME_EVENT_S1AP_TIMER: enb_ue = e->enb_ue; ogs_assert(enb_ue); @@ -233,7 +233,7 @@ void mme_state_operational(ogs_fsm_t *s, mme_event_t *e) } break; - case MME_EVT_EMM_MESSAGE: + case MME_EVENT_EMM_MESSAGE: enb_ue = e->enb_ue; ogs_assert(enb_ue); pkbuf = e->pkbuf; @@ -309,7 +309,7 @@ void mme_state_operational(ogs_fsm_t *s, mme_event_t *e) ogs_pkbuf_free(pkbuf); break; - case MME_EVT_EMM_TIMER: + case MME_EVENT_EMM_TIMER: mme_ue = e->mme_ue; ogs_assert(mme_ue); ogs_assert(OGS_FSM_STATE(&mme_ue->sm)); @@ -317,7 +317,7 @@ void mme_state_operational(ogs_fsm_t *s, mme_event_t *e) ogs_fsm_dispatch(&mme_ue->sm, e); break; - case MME_EVT_ESM_MESSAGE: + case MME_EVENT_ESM_MESSAGE: mme_ue = e->mme_ue; ogs_assert(mme_ue); @@ -376,7 +376,7 @@ void mme_state_operational(ogs_fsm_t *s, mme_event_t *e) ogs_pkbuf_free(pkbuf); break; - case MME_EVT_ESM_TIMER: + case MME_EVENT_ESM_TIMER: bearer = e->bearer; ogs_assert(bearer); ogs_assert(OGS_FSM_STATE(&bearer->sm)); @@ -384,7 +384,7 @@ void mme_state_operational(ogs_fsm_t *s, mme_event_t *e) ogs_fsm_dispatch(&bearer->sm, e); break; - case MME_EVT_S6A_MESSAGE: + case MME_EVENT_S6A_MESSAGE: mme_ue = e->mme_ue; ogs_assert(mme_ue); s6a_message = e->s6a_message; @@ -442,7 +442,7 @@ void mme_state_operational(ogs_fsm_t *s, mme_event_t *e) ogs_free(s6a_message); break; - case MME_EVT_S11_MESSAGE: + case MME_EVENT_S11_MESSAGE: pkbuf = e->pkbuf; ogs_assert(pkbuf); @@ -570,7 +570,7 @@ void mme_state_operational(ogs_fsm_t *s, mme_event_t *e) ogs_pkbuf_free(pkbuf); break; - case MME_EVT_S11_TIMER: + case MME_EVENT_S11_TIMER: sgw_ue = e->sgw_ue; ogs_assert(sgw_ue); mme_ue = sgw_ue->mme_ue; @@ -601,7 +601,7 @@ void mme_state_operational(ogs_fsm_t *s, mme_event_t *e) break; - case MME_EVT_SGSAP_LO_SCTP_COMM_UP: + case MME_EVENT_SGSAP_LO_SCTP_COMM_UP: sock = e->sock; ogs_assert(sock); addr = e->addr; @@ -628,7 +628,7 @@ void mme_state_operational(ogs_fsm_t *s, mme_event_t *e) ogs_fsm_dispatch(&vlr->sm, e); break; - case MME_EVT_SGSAP_LO_CONNREFUSED: + case MME_EVENT_SGSAP_LO_CONNREFUSED: sock = e->sock; ogs_assert(sock); addr = e->addr; @@ -656,7 +656,7 @@ void mme_state_operational(ogs_fsm_t *s, mme_event_t *e) } break; - case MME_EVT_SGSAP_MESSAGE: + case MME_EVENT_SGSAP_MESSAGE: sock = e->sock; ogs_assert(sock); addr = e->addr; @@ -679,7 +679,7 @@ void mme_state_operational(ogs_fsm_t *s, mme_event_t *e) ogs_pkbuf_free(pkbuf); break; - case MME_EVT_SGSAP_TIMER: + case MME_EVENT_SGSAP_TIMER: vlr = e->vlr; ogs_assert(vlr); ogs_assert(OGS_FSM_STATE(&vlr->sm)); diff --git a/src/mme/mme-timer.c b/src/mme/mme-timer.c index 7cfde96f4..1e3780e60 100644 --- a/src/mme/mme-timer.c +++ b/src/mme/mme-timer.c @@ -24,40 +24,40 @@ static mme_timer_cfg_t g_mme_timer_cfg[MAX_NUM_OF_MME_TIMER] = { /* Paging procedure for EPS services initiated */ [MME_TIMER_T3413] = - { .max_count = 2, .duration = ogs_time_from_sec(2) }, + { .have = true, .max_count = 2, .duration = ogs_time_from_sec(2) }, /* DETACH REQUEST sent */ [MME_TIMER_T3422] = - { .max_count = 4, .duration = ogs_time_from_sec(3) }, + { .have = true, .max_count = 4, .duration = ogs_time_from_sec(3) }, /* ATTACH ACCEPT sent * TRACKING AREA UPDATE ACCEPT sent with GUTI * TRACKING AREA UPDATE ACCEPT sent with TMSI * GUTI REALLOCATION COMMAND sent */ [MME_TIMER_T3450] = - { .max_count = 4, .duration = ogs_time_from_sec(6) }, + { .have = true, .max_count = 4, .duration = ogs_time_from_sec(6) }, /* AUTHENTICATION REQUEST sent * SECURITY MODE COMMAND sent */ [MME_TIMER_T3460] = - { .max_count = 4, .duration = ogs_time_from_sec(3) }, + { .have = true, .max_count = 4, .duration = ogs_time_from_sec(3) }, /* IDENTITY REQUEST sent */ [MME_TIMER_T3470] = - { .max_count = 4, .duration = ogs_time_from_sec(3) }, + { .have = true, .max_count = 4, .duration = ogs_time_from_sec(3) }, /* ESM INFORMATION REQUEST sent */ [MME_TIMER_T3489] = - { .max_count = 2, .duration = ogs_time_from_sec(4) }, + { .have = true, .max_count = 2, .duration = ogs_time_from_sec(4) }, [MME_TIMER_SGS_CLI_CONN_TO_SRV] = - { .duration = ogs_time_from_sec(3) }, + { .have = true, .duration = ogs_time_from_sec(3) }, [MME_TIMER_S1_HOLDING] = - { .duration = ogs_time_from_sec(30) }, + { .have = true, .duration = ogs_time_from_sec(30) }, [MME_TIMER_S11_HOLDING] = - { .duration = ogs_time_from_msec(300) }, + { .have = true, .duration = ogs_time_from_msec(300) }, }; static void emm_timer_event_send( @@ -68,6 +68,10 @@ static void esm_timer_event_send( mme_timer_cfg_t *mme_timer_cfg(mme_timer_e id) { ogs_assert(id < MAX_NUM_OF_MME_TIMER); + if (g_mme_timer_cfg[id].have != true) { + ogs_fatal("No timer[%d] configuration", id); + ogs_assert_if_reached(); + } return &g_mme_timer_cfg[id]; } @@ -125,7 +129,7 @@ static void emm_timer_event_send( mme_event_t *e = NULL; ogs_assert(mme_ue); - e = mme_event_new(MME_EVT_EMM_TIMER); + e = mme_event_new(MME_EVENT_EMM_TIMER); e->timer_id = timer_id; e->mme_ue = mme_ue; @@ -167,7 +171,7 @@ static void esm_timer_event_send( mme_ue = bearer->mme_ue; ogs_assert(bearer); - e = mme_event_new(MME_EVT_ESM_TIMER); + e = mme_event_new(MME_EVENT_ESM_TIMER); e->timer_id = timer_id; e->mme_ue = mme_ue; e->bearer = bearer; @@ -190,7 +194,7 @@ void mme_timer_sgs_cli_conn_to_srv(void *data) mme_event_t *e = NULL; ogs_assert(data); - e = mme_event_new(MME_EVT_SGSAP_TIMER); + e = mme_event_new(MME_EVENT_SGSAP_TIMER); e->timer_id = MME_TIMER_SGS_CLI_CONN_TO_SRV; e->vlr = data; @@ -210,7 +214,7 @@ void mme_timer_s1_holding_timer_expire(void *data) ogs_assert(data); enb_ue = data; - e = mme_event_new(MME_EVT_S1AP_TIMER); + e = mme_event_new(MME_EVENT_S1AP_TIMER); e->timer_id = MME_TIMER_S1_HOLDING; e->enb_ue = enb_ue; @@ -231,7 +235,7 @@ void mme_timer_s11_holding_timer_expire(void *data) ogs_assert(data); sgw_ue = data; - e = mme_event_new(MME_EVT_S11_TIMER); + e = mme_event_new(MME_EVENT_S11_TIMER); e->timer_id = MME_TIMER_S11_HOLDING; e->sgw_ue = sgw_ue; diff --git a/src/mme/mme-timer.h b/src/mme/mme-timer.h index e60056304..8356311f6 100644 --- a/src/mme/mme-timer.h +++ b/src/mme/mme-timer.h @@ -49,6 +49,7 @@ typedef enum { } mme_timer_e; typedef struct mme_timer_cfg_s { + bool have; int max_count; ogs_time_t duration; } mme_timer_cfg_t; diff --git a/src/mme/s1ap-path.c b/src/mme/s1ap-path.c index 03ad82922..219d37fb5 100644 --- a/src/mme/s1ap-path.c +++ b/src/mme/s1ap-path.c @@ -95,7 +95,7 @@ int s1ap_delayed_send_to_enb_ue( if (duration) { mme_event_t *e = NULL; - e = mme_event_new(MME_EVT_S1AP_TIMER); + e = mme_event_new(MME_EVENT_S1AP_TIMER); ogs_assert(e); e->timer = ogs_timer_add( ogs_app()->timer_mgr, mme_timer_s1_delayed_send, e); @@ -125,7 +125,7 @@ int s1ap_send_to_esm( ogs_assert(mme_ue); ogs_assert(esmbuf); - e = mme_event_new(MME_EVT_ESM_MESSAGE); + e = mme_event_new(MME_EVENT_ESM_MESSAGE); ogs_assert(e); e->mme_ue = mme_ue; e->pkbuf = esmbuf; @@ -209,7 +209,7 @@ int s1ap_send_to_nas(enb_ue_t *enb_ue, ogs_assert(h); if (h->protocol_discriminator == OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM) { int rv; - e = mme_event_new(MME_EVT_EMM_MESSAGE); + e = mme_event_new(MME_EVENT_EMM_MESSAGE); if (!e) { ogs_error("s1ap_send_to_nas() failed"); ogs_pkbuf_free(nasbuf); diff --git a/src/mme/s1ap-sctp.c b/src/mme/s1ap-sctp.c index 400b99237..ce010e73c 100644 --- a/src/mme/s1ap-sctp.c +++ b/src/mme/s1ap-sctp.c @@ -114,7 +114,7 @@ void s1ap_accept_handler(ogs_sock_t *sock) ogs_info("eNB-S1 accepted[%s]:%d in s1_path module", OGS_ADDR(addr, buf), OGS_PORT(addr)); - s1ap_event_push(MME_EVT_S1AP_LO_ACCEPT, new, addr, NULL, 0, 0); + s1ap_event_push(MME_EVENT_S1AP_LO_ACCEPT, new, addr, NULL, 0, 0); } else { ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, "accept() failed"); } @@ -164,7 +164,7 @@ void s1ap_recv_handler(ogs_sock_t *sock) ogs_assert(addr); memcpy(addr, &from, sizeof(ogs_sockaddr_t)); - s1ap_event_push(MME_EVT_S1AP_LO_SCTP_COMM_UP, + s1ap_event_push(MME_EVENT_S1AP_LO_SCTP_COMM_UP, sock, addr, NULL, not->sn_assoc_change.sac_inbound_streams, not->sn_assoc_change.sac_outbound_streams); @@ -180,7 +180,7 @@ void s1ap_recv_handler(ogs_sock_t *sock) ogs_assert(addr); memcpy(addr, &from, sizeof(ogs_sockaddr_t)); - s1ap_event_push(MME_EVT_S1AP_LO_CONNREFUSED, + s1ap_event_push(MME_EVENT_S1AP_LO_CONNREFUSED, sock, addr, NULL, 0, 0); } break; @@ -195,7 +195,7 @@ void s1ap_recv_handler(ogs_sock_t *sock) ogs_assert(addr); memcpy(addr, &from, sizeof(ogs_sockaddr_t)); - s1ap_event_push(MME_EVT_S1AP_LO_CONNREFUSED, + s1ap_event_push(MME_EVENT_S1AP_LO_CONNREFUSED, sock, addr, NULL, 0, 0); break; @@ -237,7 +237,7 @@ void s1ap_recv_handler(ogs_sock_t *sock) ogs_assert(addr); memcpy(addr, &from, sizeof(ogs_sockaddr_t)); - s1ap_event_push(MME_EVT_S1AP_MESSAGE, sock, addr, pkbuf, 0, 0); + s1ap_event_push(MME_EVENT_S1AP_MESSAGE, sock, addr, pkbuf, 0, 0); return; } else { if (ogs_socket_errno != OGS_EAGAIN) { diff --git a/src/mme/s1ap-sm.c b/src/mme/s1ap-sm.c index 9132cd00b..18a8194c7 100644 --- a/src/mme/s1ap-sm.c +++ b/src/mme/s1ap-sm.c @@ -67,7 +67,7 @@ void s1ap_state_operational(ogs_fsm_t *s, mme_event_t *e) break; case OGS_FSM_EXIT_SIG: break; - case MME_EVT_S1AP_MESSAGE: + case MME_EVENT_S1AP_MESSAGE: pdu = e->s1ap_message; ogs_assert(pdu); diff --git a/src/mme/sgsap-conv.h b/src/mme/sgsap-conv.h index 1d1c22281..6090d5edd 100644 --- a/src/mme/sgsap-conv.h +++ b/src/mme/sgsap-conv.h @@ -20,7 +20,7 @@ #ifndef SGSAP_CONV_H #define SGSAP_CONV_H -#include "ogs-core.h" +#include "ogs-proto.h" #ifdef __cplusplus extern "C" { diff --git a/src/mme/sgsap-path.c b/src/mme/sgsap-path.c index 073655905..dde72e706 100644 --- a/src/mme/sgsap-path.c +++ b/src/mme/sgsap-path.c @@ -34,8 +34,7 @@ int sgsap_open() memset(&e, 0, sizeof(e)); e.vlr = vlr; - ogs_fsm_create(&vlr->sm, sgsap_state_initial, sgsap_state_final); - ogs_fsm_init(&vlr->sm, &e); + ogs_fsm_init(&vlr->sm, sgsap_state_initial, sgsap_state_final, &e); } return OGS_OK; @@ -51,7 +50,6 @@ void sgsap_close() e.vlr = vlr; ogs_fsm_fini(&vlr->sm, &e); - ogs_fsm_delete(&vlr->sm); } } diff --git a/src/mme/sgsap-sctp.c b/src/mme/sgsap-sctp.c index ccd0ed1ea..8335fdda0 100644 --- a/src/mme/sgsap-sctp.c +++ b/src/mme/sgsap-sctp.c @@ -126,7 +126,7 @@ static void recv_handler(ogs_sock_t *sock) ogs_assert(addr); memcpy(addr, &from, sizeof(ogs_sockaddr_t)); - sgsap_event_push(MME_EVT_SGSAP_LO_SCTP_COMM_UP, + sgsap_event_push(MME_EVENT_SGSAP_LO_SCTP_COMM_UP, sock, addr, NULL, not->sn_assoc_change.sac_inbound_streams, not->sn_assoc_change.sac_outbound_streams); @@ -142,7 +142,7 @@ static void recv_handler(ogs_sock_t *sock) ogs_assert(addr); memcpy(addr, &from, sizeof(ogs_sockaddr_t)); - sgsap_event_push(MME_EVT_SGSAP_LO_CONNREFUSED, + sgsap_event_push(MME_EVENT_SGSAP_LO_CONNREFUSED, sock, addr, NULL, 0, 0); } break; @@ -170,7 +170,7 @@ static void recv_handler(ogs_sock_t *sock) ogs_assert(addr); memcpy(addr, &from, sizeof(ogs_sockaddr_t)); - sgsap_event_push(MME_EVT_SGSAP_LO_CONNREFUSED, + sgsap_event_push(MME_EVENT_SGSAP_LO_CONNREFUSED, sock, addr, NULL, 0, 0); break; case SCTP_PEER_ADDR_CHANGE: @@ -197,7 +197,7 @@ static void recv_handler(ogs_sock_t *sock) ogs_assert(addr); memcpy(addr, &from, sizeof(ogs_sockaddr_t)); - sgsap_event_push(MME_EVT_SGSAP_MESSAGE, sock, addr, pkbuf, 0, 0); + sgsap_event_push(MME_EVENT_SGSAP_MESSAGE, sock, addr, pkbuf, 0, 0); return; } else { ogs_fatal("Invalid flag(0x%x)", flags); diff --git a/src/mme/sgsap-sm.c b/src/mme/sgsap-sm.c index 4de1e22d4..f8dd3a37c 100644 --- a/src/mme/sgsap-sm.c +++ b/src/mme/sgsap-sm.c @@ -84,7 +84,7 @@ void sgsap_state_will_connect(ogs_fsm_t *s, mme_event_t *e) case OGS_FSM_EXIT_SIG: ogs_timer_stop(vlr->t_conn); break; - case MME_EVT_SGSAP_TIMER: + case MME_EVENT_SGSAP_TIMER: switch(e->timer_id) { case MME_TIMER_SGS_CLI_CONN_TO_SRV: vlr = e->vlr; @@ -108,7 +108,7 @@ void sgsap_state_will_connect(ogs_fsm_t *s, mme_event_t *e) break; } break; - case MME_EVT_SGSAP_LO_SCTP_COMM_UP: + case MME_EVENT_SGSAP_LO_SCTP_COMM_UP: OGS_FSM_TRAN(s, sgsap_state_connected); break; default: @@ -135,11 +135,11 @@ void sgsap_state_connected(ogs_fsm_t *s, mme_event_t *e) break; case OGS_FSM_EXIT_SIG: break; - case MME_EVT_SGSAP_LO_CONNREFUSED: + case MME_EVENT_SGSAP_LO_CONNREFUSED: mme_vlr_close(vlr); OGS_FSM_TRAN(s, sgsap_state_will_connect); break; - case MME_EVT_SGSAP_MESSAGE: + case MME_EVENT_SGSAP_MESSAGE: pkbuf = e->pkbuf; ogs_assert(pkbuf); type = *(unsigned char *)(pkbuf->data); diff --git a/src/nrf/context.c b/src/nrf/context.c index d050fcdd3..a43d3947c 100644 --- a/src/nrf/context.c +++ b/src/nrf/context.c @@ -47,7 +47,7 @@ void nrf_context_final(void) ogs_list_for_each_safe( &ogs_sbi_self()->nf_instance_list, next_nf_instance, nf_instance) - nrf_nf_fsm_fini(nf_instance); + if (OGS_FSM_STATE(&nf_instance->sm)) nrf_nf_fsm_fini(nf_instance); context_initialized = 0; } diff --git a/src/nrf/event.h b/src/nrf/event.h index cbddb2827..3dc906ed8 100644 --- a/src/nrf/event.h +++ b/src/nrf/event.h @@ -20,7 +20,7 @@ #ifndef NRF_EVENT_H #define NRF_EVENT_H -#include "ogs-core.h" +#include "ogs-proto.h" #ifdef __cplusplus extern "C" { @@ -33,7 +33,7 @@ typedef struct ogs_sbi_nf_instance_s ogs_sbi_nf_instance_t; typedef struct ogs_sbi_subscription_s ogs_sbi_subscription_t; typedef enum { - NRF_EVT_BASE = OGS_FSM_USER_SIG, + NRF_EVT_BASE = OGS_MAX_NUM_OF_PROTO_EVENT, NRF_EVT_SBI_SERVER, NRF_EVT_SBI_CLIENT, diff --git a/src/nrf/init.c b/src/nrf/init.c index 5733a2441..fe6a1b87a 100644 --- a/src/nrf/init.c +++ b/src/nrf/init.c @@ -94,8 +94,7 @@ static void nrf_main(void *data) ogs_fsm_t nrf_sm; int rv; - ogs_fsm_create(&nrf_sm, nrf_state_initial, nrf_state_final); - ogs_fsm_init(&nrf_sm, 0); + ogs_fsm_init(&nrf_sm, nrf_state_initial, nrf_state_final, 0); for ( ;; ) { ogs_pollset_poll(ogs_app()->pollset, @@ -134,5 +133,4 @@ static void nrf_main(void *data) done: ogs_fsm_fini(&nrf_sm, 0); - ogs_fsm_delete(&nrf_sm); } diff --git a/src/nrf/nf-sm.c b/src/nrf/nf-sm.c index 8a45439a7..3b09dff7b 100644 --- a/src/nrf/nf-sm.c +++ b/src/nrf/nf-sm.c @@ -30,9 +30,8 @@ void nrf_nf_fsm_init(ogs_sbi_nf_instance_t *nf_instance) memset(&e, 0, sizeof(e)); e.nf_instance = nf_instance; - ogs_fsm_create(&nf_instance->sm, - nrf_nf_state_initial, nrf_nf_state_final); - ogs_fsm_init(&nf_instance->sm, &e); + ogs_fsm_init(&nf_instance->sm, + nrf_nf_state_initial, nrf_nf_state_final, &e); } void nrf_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance) @@ -44,7 +43,6 @@ void nrf_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance) e.nf_instance = nf_instance; ogs_fsm_fini(&nf_instance->sm, &e); - ogs_fsm_delete(&nf_instance->sm); } void nrf_nf_state_initial(ogs_fsm_t *s, nrf_event_t *e) diff --git a/src/nrf/nnrf-handler.c b/src/nrf/nnrf-handler.c index 8e142ea85..33a0927d9 100644 --- a/src/nrf/nnrf-handler.c +++ b/src/nrf/nnrf-handler.c @@ -23,7 +23,6 @@ bool nrf_nnrf_handle_nf_register(ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) { int status; - bool handled; ogs_sbi_response_t *response = NULL; OpenAPI_nf_profile_t *NFProfile = NULL; @@ -46,9 +45,7 @@ bool nrf_nnrf_handle_nf_register(ogs_sbi_nf_instance_t *nf_instance, nf_instance->nf_profile, NFProfile); /* ogs_sbi_nnrf_handle_nf_profile() sends error response */ - handled = ogs_sbi_nnrf_handle_nf_profile( - nf_instance, NFProfile, stream, recvmsg); - if (!handled) return false; + ogs_sbi_nnrf_handle_nf_profile(nf_instance, NFProfile, stream, recvmsg); if (OGS_FSM_CHECK(&nf_instance->sm, nrf_nf_state_will_register)) { recvmsg->http.location = recvmsg->h.uri; diff --git a/src/nrf/sbi-path.c b/src/nrf/sbi-path.c index 74ee6d55b..5d0bc7a00 100644 --- a/src/nrf/sbi-path.c +++ b/src/nrf/sbi-path.c @@ -93,13 +93,6 @@ int nrf_sbi_open(void) client->cb = client_notify_cb; } - /* Timer expiration handler of client wait timer */ - ogs_sbi_self()->client_wait_expire = nrf_timer_sbi_client_wait_expire; - - /* NF register state in NF state machine */ - ogs_sbi_self()->nf_state_registered = - (ogs_fsm_handler_t)nrf_nf_state_registered; - if (ogs_sbi_server_start_all(server_cb) != OGS_OK) return OGS_ERROR; diff --git a/src/nrf/timer.c b/src/nrf/timer.c index 5e78ca256..6f8eff0af 100644 --- a/src/nrf/timer.c +++ b/src/nrf/timer.c @@ -19,16 +19,6 @@ #include "context.h" -static nrf_timer_cfg_t g_nrf_timer_cfg[MAX_NUM_OF_NRF_TIMER] = { - /* Nothing */ -}; - -nrf_timer_cfg_t *nrf_timer_cfg(nrf_timer_e id) -{ - ogs_assert(id < MAX_NUM_OF_NRF_TIMER); - return &g_nrf_timer_cfg[id]; -} - const char *nrf_timer_get_name(nrf_timer_e id) { switch (id) { @@ -82,8 +72,3 @@ void nrf_timer_subscription_validity(void *data) { timer_send_event(NRF_TIMER_SUBSCRIPTION_VALIDITY, data); } - -void nrf_timer_sbi_client_wait_expire(void *data) -{ - timer_send_event(NRF_TIMER_SBI_CLIENT_WAIT, data); -} diff --git a/src/nrf/timer.h b/src/nrf/timer.h index 69e4c2ba6..c995401ff 100644 --- a/src/nrf/timer.h +++ b/src/nrf/timer.h @@ -38,18 +38,10 @@ typedef enum { } nrf_timer_e; -typedef struct nrf_timer_cfg_s { - int max_count; - ogs_time_t duration; -} nrf_timer_cfg_t; - -nrf_timer_cfg_t *nrf_timer_cfg(nrf_timer_e id); - const char *nrf_timer_get_name(nrf_timer_e id); void nrf_timer_nf_instance_no_heartbeat(void *data); void nrf_timer_subscription_validity(void *data); -void nrf_timer_sbi_client_wait_expire(void *data); #ifdef __cplusplus } diff --git a/src/nssf/context.c b/src/nssf/context.c index 771c6a2f6..1dae37088 100644 --- a/src/nssf/context.c +++ b/src/nssf/context.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * diff --git a/src/nssf/context.h b/src/nssf/context.h index 274e7bdb4..192a12223 100644 --- a/src/nssf/context.h +++ b/src/nssf/context.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -24,7 +24,6 @@ #include "ogs-sbi.h" #include "nssf-sm.h" -#include "timer.h" #ifdef __cplusplus extern "C" { @@ -41,22 +40,6 @@ typedef struct nssf_context_s { ogs_list_t nsi_list; /* NSI List */ } nssf_context_t; -#define NSSF_NF_INSTANCE_CLEAR(_cAUSE, _nFInstance) \ - do { \ - ogs_assert(_nFInstance); \ - if ((_nFInstance)->reference_count == 1) { \ - ogs_info("[%s] (%s) NF removed", (_nFInstance)->id, (_cAUSE)); \ - nssf_nf_fsm_fini((_nFInstance)); \ - ogs_sbi_nf_instance_remove(_nFInstance); \ - } else { \ - /* There is an assocation with other context */ \ - ogs_info("[%s:%d] (%s) NF suspended", \ - _nFInstance->id, _nFInstance->reference_count, (_cAUSE)); \ - OGS_FSM_TRAN(&_nFInstance->sm, nssf_nf_state_de_registered); \ - ogs_fsm_dispatch(&_nFInstance->sm, NULL); \ - } \ - } while(0) - void nssf_context_init(void); void nssf_context_final(void); nssf_context_t *nssf_self(void); diff --git a/src/nssf/event.c b/src/nssf/event.c index d7db10680..c31f45a57 100644 --- a/src/nssf/event.c +++ b/src/nssf/event.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -18,60 +18,42 @@ */ #include "event.h" -#include "context.h" -static OGS_POOL(pool, nssf_event_t); - -void nssf_event_init(void) -{ - ogs_pool_init(&pool, ogs_app()->pool.event); -} - -void nssf_event_final(void) -{ - ogs_pool_final(&pool); -} - -nssf_event_t *nssf_event_new(nssf_event_e id) +nssf_event_t *nssf_event_new(int id) { nssf_event_t *e = NULL; - ogs_pool_alloc(&pool, &e); + e = ogs_event_size(id, sizeof(nssf_event_t)); ogs_assert(e); - memset(e, 0, sizeof(*e)); - e->id = id; + e->h.id = id; return e; } -void nssf_event_free(nssf_event_t *e) -{ - ogs_assert(e); - ogs_pool_free(&pool, e); -} - const char *nssf_event_get_name(nssf_event_t *e) { - if (e == NULL) + if (e == NULL) { return OGS_FSM_NAME_INIT_SIG; - - switch (e->id) { - case OGS_FSM_ENTRY_SIG: - return OGS_FSM_NAME_ENTRY_SIG; - case OGS_FSM_EXIT_SIG: - return OGS_FSM_NAME_EXIT_SIG; - - case NSSF_EVT_SBI_SERVER: - return "NSSF_EVT_SBI_SERVER"; - case NSSF_EVT_SBI_CLIENT: - return "NSSF_EVT_SBI_CLIENT"; - case NSSF_EVT_SBI_TIMER: - return "NSSF_EVT_SBI_TIMER"; - - default: - break; } + switch (e->h.id) { + case OGS_FSM_ENTRY_SIG: + return OGS_FSM_NAME_ENTRY_SIG; + case OGS_FSM_EXIT_SIG: + return OGS_FSM_NAME_EXIT_SIG; + + case OGS_EVENT_SBI_SERVER: + return OGS_EVENT_NAME_SBI_SERVER; + case OGS_EVENT_SBI_CLIENT: + return OGS_EVENT_NAME_SBI_CLIENT; + case OGS_EVENT_SBI_TIMER: + return OGS_EVENT_NAME_SBI_TIMER; + + default: + break; + } + + ogs_error("Unknown Event[%d]", e->h.id); return "UNKNOWN_EVENT"; } diff --git a/src/nssf/event.h b/src/nssf/event.h index 2f0c066f1..b78346d61 100644 --- a/src/nssf/event.h +++ b/src/nssf/event.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -20,49 +20,19 @@ #ifndef NSSF_EVENT_H #define NSSF_EVENT_H -#include "ogs-core.h" +#include "ogs-proto.h" #ifdef __cplusplus extern "C" { #endif -typedef struct ogs_sbi_request_s ogs_sbi_request_t; -typedef struct ogs_sbi_response_s ogs_sbi_response_t; -typedef struct ogs_sbi_message_s ogs_sbi_message_t; -typedef struct ogs_sbi_nf_instance_s ogs_sbi_nf_instance_t; -typedef struct ogs_sbi_subscription_s ogs_sbi_subscription_t; - -typedef enum { - NSSF_EVT_BASE = OGS_FSM_USER_SIG, - - NSSF_EVT_SBI_SERVER, - NSSF_EVT_SBI_CLIENT, - NSSF_EVT_SBI_TIMER, - - NSSF_EVT_TOP, - -} nssf_event_e; +typedef struct nssf_ue_s nssf_ue_t; typedef struct nssf_event_s { - int id; - int timer_id; - - struct { - ogs_sbi_request_t *request; - ogs_sbi_response_t *response; - void *data; - - ogs_sbi_message_t *message; - } sbi; - - ogs_timer_t *timer; + ogs_event_t h; } nssf_event_t; -void nssf_event_init(void); -void nssf_event_final(void); - -nssf_event_t *nssf_event_new(nssf_event_e id); -void nssf_event_free(nssf_event_t *e); +nssf_event_t *nssf_event_new(int id); const char *nssf_event_get_name(nssf_event_t *e); diff --git a/src/nssf/init.c b/src/nssf/init.c index 1648d2c5c..e5b01e78e 100644 --- a/src/nssf/init.c +++ b/src/nssf/init.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -30,7 +30,6 @@ int nssf_initialize() ogs_sbi_context_init(); nssf_context_init(); - nssf_event_init(); rv = ogs_sbi_context_parse_config("nssf", "nrf", "scp"); if (rv != OGS_OK) return rv; @@ -61,7 +60,7 @@ static void event_termination(void) /* Sending NF Instance De-registeration to NRF */ ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) - nssf_nf_fsm_fini(nf_instance); + ogs_sbi_nf_fsm_fini(nf_instance); /* Starting holding timer */ t_termination_holding = ogs_timer_add(ogs_app()->timer_mgr, NULL, NULL); @@ -87,8 +86,6 @@ void nssf_terminate(void) nssf_context_final(); ogs_sbi_context_final(); - - nssf_event_final(); /* Destroy event */ } static void nssf_main(void *data) @@ -96,8 +93,7 @@ static void nssf_main(void *data) ogs_fsm_t nssf_sm; int rv; - ogs_fsm_create(&nssf_sm, nssf_state_initial, nssf_state_final); - ogs_fsm_init(&nssf_sm, 0); + ogs_fsm_init(&nssf_sm, nssf_state_initial, nssf_state_final, 0); for ( ;; ) { ogs_pollset_poll(ogs_app()->pollset, @@ -130,11 +126,10 @@ static void nssf_main(void *data) ogs_assert(e); ogs_fsm_dispatch(&nssf_sm, e); - nssf_event_free(e); + ogs_event_free(e); } } done: ogs_fsm_fini(&nssf_sm, 0); - ogs_fsm_delete(&nssf_sm); } diff --git a/src/nssf/meson.build b/src/nssf/meson.build index 055680553..bedf6c758 100644 --- a/src/nssf/meson.build +++ b/src/nssf/meson.build @@ -1,4 +1,4 @@ -# Copyright (C) 2019,2020 by Sukchan Lee +# Copyright (C) 2019-2022 by Sukchan Lee # This file is part of Open5GS. @@ -18,11 +18,6 @@ libnssf_sources = files(''' context.c event.c - timer.c - - nnrf-build.c - nnrf-handler.c - nf-sm.c nnssf-handler.c diff --git a/src/nssf/nf-sm.c b/src/nssf/nf-sm.c deleted file mode 100644 index 6f9f9897b..000000000 --- a/src/nssf/nf-sm.c +++ /dev/null @@ -1,441 +0,0 @@ -/* - * Copyright (C) 2019,2020 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "context.h" - -#include "sbi-path.h" -#include "nnrf-handler.h" - -void nssf_nf_fsm_init(ogs_sbi_nf_instance_t *nf_instance) -{ - nssf_event_t e; - - ogs_assert(nf_instance); - - memset(&e, 0, sizeof(e)); - e.sbi.data = nf_instance; - - ogs_fsm_create(&nf_instance->sm, - nssf_nf_state_initial, nssf_nf_state_final); - ogs_fsm_init(&nf_instance->sm, &e); -} - -void nssf_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance) -{ - nssf_event_t e; - - ogs_assert(nf_instance); - - memset(&e, 0, sizeof(e)); - e.sbi.data = nf_instance; - - ogs_fsm_fini(&nf_instance->sm, &e); - ogs_fsm_delete(&nf_instance->sm); -} - -void nssf_nf_state_initial(ogs_fsm_t *s, nssf_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - - ogs_assert(s); - ogs_assert(e); - - nssf_sm_debug(e); - - nf_instance = e->sbi.data; - ogs_assert(nf_instance); - - nf_instance->t_registration_interval = ogs_timer_add(ogs_app()->timer_mgr, - nssf_timer_nf_instance_registration_interval, nf_instance); - ogs_assert(nf_instance->t_registration_interval); - nf_instance->t_heartbeat_interval = ogs_timer_add(ogs_app()->timer_mgr, - nssf_timer_nf_instance_heartbeat_interval, nf_instance); - ogs_assert(nf_instance->t_heartbeat_interval); - nf_instance->t_no_heartbeat = ogs_timer_add(ogs_app()->timer_mgr, - nssf_timer_nf_instance_no_heartbeat, nf_instance); - ogs_assert(nf_instance->t_no_heartbeat); - nf_instance->t_validity = ogs_timer_add(ogs_app()->timer_mgr, - nssf_timer_nf_instance_validity, nf_instance); - ogs_assert(nf_instance->t_validity); - - 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); - } -} - -void nssf_nf_state_final(ogs_fsm_t *s, nssf_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - - ogs_assert(s); - ogs_assert(e); - - nssf_sm_debug(e); - - nf_instance = e->sbi.data; - ogs_assert(nf_instance); - - ogs_timer_delete(nf_instance->t_registration_interval); - ogs_timer_delete(nf_instance->t_heartbeat_interval); - ogs_timer_delete(nf_instance->t_no_heartbeat); - ogs_timer_delete(nf_instance->t_validity); -} - -void nssf_nf_state_will_register(ogs_fsm_t *s, nssf_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_sbi_client_t *client = NULL; - ogs_sbi_message_t *message = NULL; - ogs_sockaddr_t *addr = NULL; - - ogs_assert(s); - ogs_assert(e); - - nssf_sm_debug(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: - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); - - ogs_assert(true == ogs_nnrf_nfm_send_nf_register( - nf_instance, nssf_nnrf_nfm_build_register)); - break; - - case OGS_FSM_EXIT_SIG: - ogs_timer_stop(nf_instance->t_registration_interval); - break; - - case NSSF_EVT_SBI_CLIENT: - message = e->sbi.message; - ogs_assert(message); - - SWITCH(message->h.service.name) - CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) - - SWITCH(message->h.resource.component[0]) - CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - - if (message->res_status == OGS_SBI_HTTP_STATUS_OK || - message->res_status == OGS_SBI_HTTP_STATUS_CREATED) { - nssf_nnrf_handle_nf_register(nf_instance, message); - OGS_FSM_TRAN(s, &nssf_nf_state_registered); - } else { - ogs_error("[%s] HTTP response error [%d]", - 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]", - ogs_sbi_self()->nf_instance->id, - message->h.resource.component[0]); - END - break; - - DEFAULT - ogs_error("[%s] Invalid API name [%s]", - ogs_sbi_self()->nf_instance->id, message->h.service.name); - END - break; - - case NSSF_EVT_SBI_TIMER: - switch(e->timer_id) { - case NSSF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - client = nf_instance->client; - ogs_assert(client); - addr = client->node.addr; - ogs_assert(addr); - - ogs_warn("[%s] Retry to registration with NRF", - ogs_sbi_self()->nf_instance->id); - - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); - - ogs_assert(true == ogs_nnrf_nfm_send_nf_register( - nf_instance, nssf_nnrf_nfm_build_register)); - break; - - default: - ogs_error("[%s] Unknown timer[%s:%d]", - ogs_sbi_self()->nf_instance->id, - nssf_timer_get_name(e->timer_id), e->timer_id); - } - break; - - default: - ogs_error("Unknown event %s", nssf_event_get_name(e)); - break; - } -} - -void nssf_nf_state_registered(ogs_fsm_t *s, nssf_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_sbi_client_t *client = NULL; - ogs_sbi_message_t *message = NULL; - ogs_assert(s); - ogs_assert(e); - - nssf_sm_debug(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_NRF(nf_instance)) { - ogs_info("[%s] NF registered [Heartbeat:%ds]", - ogs_sbi_self()->nf_instance->id, - nf_instance->time.heartbeat_interval); - - client = nf_instance->client; - ogs_assert(client); - - if (nf_instance->time.heartbeat_interval) { - ogs_timer_start(nf_instance->t_heartbeat_interval, - ogs_time_from_sec(nf_instance->time.heartbeat_interval)); - ogs_timer_start(nf_instance->t_no_heartbeat, - ogs_time_from_sec( - nf_instance->time.heartbeat_interval + - ogs_app()->time.nf_instance.no_heartbeat_margin)); - } - } - - break; - - case OGS_FSM_EXIT_SIG: - 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); - ogs_timer_stop(nf_instance->t_no_heartbeat); - } - - if (!OGS_FSM_CHECK(&nf_instance->sm, nssf_nf_state_exception)) { - ogs_assert(true == - ogs_nnrf_nfm_send_nf_de_register(nf_instance)); - } - } - break; - - case NSSF_EVT_SBI_CLIENT: - message = e->sbi.message; - ogs_assert(message); - - SWITCH(message->h.service.name) - CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) - - SWITCH(message->h.resource.component[0]) - CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - - if (message->res_status == OGS_SBI_HTTP_STATUS_NO_CONTENT || - message->res_status == OGS_SBI_HTTP_STATUS_OK) { - if (nf_instance->time.heartbeat_interval) - ogs_timer_start(nf_instance->t_no_heartbeat, - ogs_time_from_sec( - nf_instance->time.heartbeat_interval + - ogs_app()->time.nf_instance. - no_heartbeat_margin)); - } else { - ogs_warn("[%s] HTTP response error [%d]", - 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]", - ogs_sbi_self()->nf_instance->id, - message->h.resource.component[0]); - END - break; - - DEFAULT - ogs_error("[%s] Invalid API name [%s]", - ogs_sbi_self()->nf_instance->id, message->h.service.name); - END - break; - - case NSSF_EVT_SBI_TIMER: - switch(e->timer_id) { - case NSSF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - if (nf_instance->time.heartbeat_interval) - ogs_timer_start(nf_instance->t_heartbeat_interval, - ogs_time_from_sec(nf_instance->time.heartbeat_interval)); - - ogs_assert(true == ogs_nnrf_nfm_send_nf_update(nf_instance)); - break; - - case NSSF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - 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: - 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:%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; - - default: - 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; - } -} - -void nssf_nf_state_de_registered(ogs_fsm_t *s, nssf_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_assert(s); - ogs_assert(e); - - nssf_sm_debug(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_NRF(nf_instance)) { - ogs_info("[%s] NF de-registered", ogs_sbi_self()->nf_instance->id); - } - break; - - case OGS_FSM_EXIT_SIG: - break; - - default: - 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; - } -} - -void nssf_nf_state_exception(ogs_fsm_t *s, nssf_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_sbi_client_t *client = NULL; - ogs_sbi_message_t *message = NULL; - ogs_sockaddr_t *addr = NULL; - ogs_assert(s); - ogs_assert(e); - - nssf_sm_debug(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_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_NRF(nf_instance)) { - ogs_timer_stop(nf_instance->t_registration_interval); - } - break; - - case NSSF_EVT_SBI_TIMER: - switch(e->timer_id) { - case NSSF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - client = nf_instance->client; - ogs_assert(client); - addr = client->node.addr; - ogs_assert(addr); - - 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:%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; - - case NSSF_EVT_SBI_CLIENT: - message = e->sbi.message; - ogs_assert(message); - - SWITCH(message->h.service.name) - CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) - - SWITCH(message->h.resource.component[0]) - CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - break; - DEFAULT - ogs_error("Invalid resource name [%s]", - message->h.resource.component[0]); - END - break; - DEFAULT - ogs_error("Invalid API name [%s]", message->h.service.name); - END - break; - - default: - 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 deleted file mode 100644 index 56ec2601a..000000000 --- a/src/nssf/nnrf-build.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2019,2020 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "nnrf-build.h" - -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; - - OpenAPI_nf_profile_t *NFProfile = 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_PUT; - message.h.service.name = (char *)OGS_SBI_SERVICE_NAME_NNRF_NFM; - 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] = nf_instance->id; - - message.http.content_encoding = (char*)ogs_sbi_self()->content_encoding; - - NFProfile = ogs_nnrf_nfm_build_nf_profile(); - ogs_expect_or_return_val(NFProfile, NULL); - - message.NFProfile = NFProfile; - - request = ogs_sbi_build_request(&message); - - ogs_sbi_nnrf_free_nf_profile(NFProfile); - - return request; -} diff --git a/src/nssf/nnrf-handler.c b/src/nssf/nnrf-handler.c deleted file mode 100644 index 13599489b..000000000 --- a/src/nssf/nnrf-handler.c +++ /dev/null @@ -1,247 +0,0 @@ -/* - * Copyright (C) 2019,2020 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "sbi-path.h" -#include "nnrf-handler.h" - -void nssf_nnrf_handle_nf_register( - ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_message_t *recvmsg) -{ - OpenAPI_nf_profile_t *NFProfile = NULL; - ogs_sbi_client_t *client = NULL; - - ogs_assert(recvmsg); - ogs_assert(nf_instance); - client = nf_instance->client; - ogs_assert(client); - - NFProfile = recvmsg->NFProfile; - if (!NFProfile) { - ogs_error("No NFProfile"); - return; - } - - /* TIME : Update heartbeat from NRF */ - if (NFProfile->is_heart_beat_timer == true) - nf_instance->time.heartbeat_interval = NFProfile->heart_beat_timer; -} - -void nssf_nnrf_handle_nf_status_subscribe( - ogs_sbi_subscription_t *subscription, ogs_sbi_message_t *recvmsg) -{ - OpenAPI_subscription_data_t *SubscriptionData = NULL; - ogs_sbi_client_t *client = NULL; - - ogs_assert(recvmsg); - ogs_assert(subscription); - client = subscription->client; - ogs_assert(client); - - SubscriptionData = recvmsg->SubscriptionData; - if (!SubscriptionData) { - ogs_error("No SubscriptionData"); - return; - } - - if (!SubscriptionData->subscription_id) { - ogs_error("No SubscriptionId"); - return; - } - ogs_sbi_subscription_set_id( - subscription, SubscriptionData->subscription_id); - - if (SubscriptionData->validity_time) { -#define VALIDITY_MINIMUM (10LL * OGS_USEC_PER_SEC) /* 10 seconds */ - ogs_time_t time, duration; - if (ogs_sbi_time_from_string( - &time, SubscriptionData->validity_time) == true) { - duration = time - ogs_time_now(); - if (duration < VALIDITY_MINIMUM) { - duration = VALIDITY_MINIMUM; - ogs_warn("[%s] Forced to %lld seconds", subscription->id, - (long long)ogs_time_sec(VALIDITY_MINIMUM)); - } - subscription->t_validity = ogs_timer_add(ogs_app()->timer_mgr, - nssf_timer_subscription_validity, subscription); - ogs_assert(subscription->t_validity); - ogs_timer_start(subscription->t_validity, duration); - } else { - ogs_error("Cannot parse validitiyTime [%s]", - SubscriptionData->validity_time); - } - } -} - -bool nssf_nnrf_handle_nf_status_notify( - ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) -{ - int rv; - bool handled; - - ogs_sbi_response_t *response = NULL; - OpenAPI_notification_data_t *NotificationData = NULL; - ogs_sbi_nf_instance_t *nf_instance = NULL; - - ogs_sbi_message_t message; - ogs_sbi_header_t header; - - ogs_assert(stream); - ogs_assert(recvmsg); - - NotificationData = recvmsg->NotificationData; - if (!NotificationData) { - ogs_error("No NotificationData"); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "No NotificationData", NULL)); - return false; - } - - if (!NotificationData->nf_instance_uri) { - ogs_error("No nfInstanceUri"); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "No nfInstanceUri", NULL)); - return false; - } - - memset(&header, 0, sizeof(header)); - header.uri = NotificationData->nf_instance_uri; - - rv = ogs_sbi_parse_header(&message, &header); - if (rv != OGS_OK) { - ogs_error("Cannot parse nfInstanceUri [%s]", header.uri); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Cannot parse nfInstanceUri", header.uri)); - return false; - } - - if (!message.h.resource.component[1]) { - ogs_error("No nfInstanceId [%s]", header.uri); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Cannot parse nfInstanceUri", header.uri)); - ogs_sbi_header_free(&header); - return false; - } - - if (NF_INSTANCE_IS_SELF(message.h.resource.component[1])) { - ogs_warn("[%s] The notification is not allowed", - message.h.resource.component[1]); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, - recvmsg, "The notification is not allowed", - message.h.resource.component[1])); - ogs_sbi_header_free(&header); - return false; - } - - if (NotificationData->event == - OpenAPI_notification_event_type_NF_REGISTERED) { - - OpenAPI_nf_profile_t *NFProfile = NULL; - - NFProfile = NotificationData->nf_profile; - if (!NFProfile) { - ogs_error("No NFProfile"); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "No NFProfile", NULL)); - ogs_sbi_header_free(&header); - return false; - } - - nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); - if (!nf_instance) { - 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); - - ogs_info("[%s] (NRF-notify) NF registered", nf_instance->id); - - } else { - OGS_FSM_TRAN(&nf_instance->sm, nssf_nf_state_registered); - ogs_fsm_dispatch(&nf_instance->sm, NULL); - - ogs_warn("[%s] (NRF-notify) NF has already been added", - message.h.resource.component[1]); - - } - - handled = ogs_sbi_nnrf_handle_nf_profile( - nf_instance, NFProfile, stream, recvmsg); - if (!handled) { - NSSF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); - ogs_sbi_header_free(&header); - return false; - } - - ogs_info("[%s] (NRF-notify) NF Profile updated", nf_instance->id); - - handled = ogs_sbi_client_associate(nf_instance); - if (!handled) { - ogs_error("[%s] Cannot associate NF EndPoint", nf_instance->id); - ogs_assert(true == - ogs_sbi_server_send_error(stream, - OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Cannot find NF EndPoint", nf_instance->id)); - NSSF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); - ogs_sbi_header_free(&header); - return false; - } - - } else if (NotificationData->event == - OpenAPI_notification_event_type_NF_DEREGISTERED) { - nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); - if (nf_instance) { - NSSF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); - } else { - ogs_warn("[%s] (NRF-notify) Not found", - message.h.resource.component[1]); - ogs_assert(true == - ogs_sbi_server_send_error(stream, - OGS_SBI_HTTP_STATUS_NOT_FOUND, - recvmsg, "Not found", message.h.resource.component[1])); - ogs_sbi_header_free(&header); - return false; - } - } else { - char *eventstr = OpenAPI_notification_event_type_ToString( - NotificationData->event); - ogs_error("Not supported event [%d:%s]", - NotificationData->event, eventstr ? eventstr : "Unknown"); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Not supported event", - eventstr ? eventstr : "Unknown")); - ogs_sbi_header_free(&header); - return false; - } - - response = ogs_sbi_build_response(recvmsg, OGS_SBI_HTTP_STATUS_NO_CONTENT); - ogs_assert(response); - ogs_assert(true == ogs_sbi_server_send_response(stream, response)); - - ogs_sbi_header_free(&header); - return true; -} diff --git a/src/nssf/nssf-sm.c b/src/nssf/nssf-sm.c index b0b404666..03d087647 100644 --- a/src/nssf/nssf-sm.c +++ b/src/nssf/nssf-sm.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -54,17 +54,17 @@ void nssf_state_operational(ogs_fsm_t *s, nssf_event_t *e) ogs_assert(s); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: break; case OGS_FSM_EXIT_SIG: break; - case NSSF_EVT_SBI_SERVER: - request = e->sbi.request; + case OGS_EVENT_SBI_SERVER: + request = e->h.sbi.request; ogs_assert(request); - stream = e->sbi.data; + stream = e->h.sbi.data; ogs_assert(stream); rv = ogs_sbi_parse_request(&message, request); @@ -138,10 +138,10 @@ void nssf_state_operational(ogs_fsm_t *s, nssf_event_t *e) ogs_sbi_message_free(&message); break; - case NSSF_EVT_SBI_CLIENT: + case OGS_EVENT_SBI_CLIENT: ogs_assert(e); - response = e->sbi.response; + response = e->h.sbi.response; ogs_assert(response); rv = ogs_sbi_parse_response(&message, response); if (rv != OGS_OK) { @@ -163,23 +163,23 @@ void nssf_state_operational(ogs_fsm_t *s, nssf_event_t *e) SWITCH(message.h.resource.component[0]) CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - nf_instance = e->sbi.data; + nf_instance = e->h.sbi.data; ogs_assert(nf_instance); ogs_assert(OGS_FSM_STATE(&nf_instance->sm)); - e->sbi.message = &message; + e->h.sbi.message = &message; ogs_fsm_dispatch(&nf_instance->sm, e); break; CASE(OGS_SBI_RESOURCE_NAME_SUBSCRIPTIONS) - subscription = e->sbi.data; + subscription = e->h.sbi.data; ogs_assert(subscription); SWITCH(message.h.method) CASE(OGS_SBI_HTTP_METHOD_POST) if (message.res_status == OGS_SBI_HTTP_STATUS_CREATED || message.res_status == OGS_SBI_HTTP_STATUS_OK) { - nssf_nnrf_handle_nf_status_subscribe( + ogs_nnrf_handle_nf_status_subscribe( subscription, &message); } else { ogs_error("[%s] HTTP response error [%d]", @@ -220,27 +220,27 @@ void nssf_state_operational(ogs_fsm_t *s, nssf_event_t *e) ogs_sbi_response_free(response); break; - case NSSF_EVT_SBI_TIMER: + case OGS_EVENT_SBI_TIMER: ogs_assert(e); - switch(e->timer_id) { - case NSSF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - case NSSF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - case NSSF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - case NSSF_TIMER_NF_INSTANCE_VALIDITY: - nf_instance = e->sbi.data; + switch(e->h.timer_id) { + case OGS_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: + case OGS_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: + case OGS_TIMER_NF_INSTANCE_NO_HEARTBEAT: + case OGS_TIMER_NF_INSTANCE_VALIDITY: + nf_instance = e->h.sbi.data; ogs_assert(nf_instance); ogs_assert(OGS_FSM_STATE(&nf_instance->sm)); ogs_fsm_dispatch(&nf_instance->sm, e); - if (OGS_FSM_CHECK(&nf_instance->sm, nssf_nf_state_exception)) + if (OGS_FSM_CHECK(&nf_instance->sm, ogs_sbi_nf_state_exception)) ogs_error("[%s:%s] State machine exception [%d]", OpenAPI_nf_type_ToString(nf_instance->nf_type), - nf_instance->id, e->timer_id); + nf_instance->id, e->h.timer_id); break; - case NSSF_TIMER_SUBSCRIPTION_VALIDITY: - subscription = e->sbi.data; + case OGS_TIMER_SUBSCRIPTION_VALIDITY: + subscription = e->h.sbi.data; ogs_assert(subscription); ogs_assert(ogs_sbi_self()->nf_instance); @@ -256,7 +256,7 @@ void nssf_state_operational(ogs_fsm_t *s, nssf_event_t *e) default: ogs_error("Unknown timer[%s:%d]", - nssf_timer_get_name(e->timer_id), e->timer_id); + ogs_timer_get_name(e->h.timer_id), e->h.timer_id); } break; diff --git a/src/nssf/nssf-sm.h b/src/nssf/nssf-sm.h index 83d812d10..961fe4540 100644 --- a/src/nssf/nssf-sm.h +++ b/src/nssf/nssf-sm.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -30,16 +30,6 @@ void nssf_state_initial(ogs_fsm_t *s, nssf_event_t *e); void nssf_state_final(ogs_fsm_t *s, nssf_event_t *e); void nssf_state_operational(ogs_fsm_t *s, nssf_event_t *e); -void nssf_nf_fsm_init(ogs_sbi_nf_instance_t *nf_instance); -void nssf_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance); - -void nssf_nf_state_initial(ogs_fsm_t *s, nssf_event_t *e); -void nssf_nf_state_final(ogs_fsm_t *s, nssf_event_t *e); -void nssf_nf_state_will_register(ogs_fsm_t *s, nssf_event_t *e); -void nssf_nf_state_registered(ogs_fsm_t *s, nssf_event_t *e); -void nssf_nf_state_de_registered(ogs_fsm_t *s, nssf_event_t *e); -void nssf_nf_state_exception(ogs_fsm_t *s, nssf_event_t *e); - #define nssf_sm_debug(__pe) \ ogs_debug("%s(): %s", __func__, nssf_event_get_name(__pe)) diff --git a/src/nssf/sbi-path.c b/src/nssf/sbi-path.c index be7ebed42..591e5a813 100644 --- a/src/nssf/sbi-path.c +++ b/src/nssf/sbi-path.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -27,17 +27,17 @@ static int server_cb(ogs_sbi_request_t *request, void *data) ogs_assert(request); ogs_assert(data); - e = nssf_event_new(NSSF_EVT_SBI_SERVER); + e = nssf_event_new(OGS_EVENT_SBI_SERVER); ogs_assert(e); - e->sbi.request = request; - e->sbi.data = data; + e->h.sbi.request = request; + e->h.sbi.data = data; rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed:%d", (int)rv); ogs_sbi_request_free(request); - nssf_event_free(e); + ogs_event_free(e); return OGS_ERROR; } @@ -58,16 +58,16 @@ static int client_cb(int status, ogs_sbi_response_t *response, void *data) ogs_assert(response); - e = nssf_event_new(NSSF_EVT_SBI_CLIENT); + e = nssf_event_new(OGS_EVENT_SBI_CLIENT); ogs_assert(e); - e->sbi.response = response; - e->sbi.data = data; + e->h.sbi.response = response; + e->h.sbi.data = data; rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed:%d", (int)rv); ogs_sbi_response_free(response); - nssf_event_free(e); + ogs_event_free(e); return OGS_ERROR; } @@ -99,28 +99,20 @@ int nssf_sbi_open(void) } /* Initialize NRF NF Instance */ - ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) { - if (NF_INSTANCE_IS_NRF(nf_instance)) { - ogs_sbi_client_t *client = NULL; + nf_instance = ogs_sbi_self()->nrf_instance; + if (nf_instance) { + ogs_sbi_client_t *client = NULL; - /* Client callback is only used when NF sends to NRF */ - client = nf_instance->client; - ogs_assert(client); - client->cb = client_cb; + /* 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. */ + ogs_sbi_nf_fsm_init(nf_instance); } - /* Timer expiration handler of client wait timer */ - ogs_sbi_self()->client_wait_expire = nssf_timer_sbi_client_wait_expire; - - /* NF register state in NF state machine */ - ogs_sbi_self()->nf_state_registered = - (ogs_fsm_handler_t)nssf_nf_state_registered; - if (ogs_sbi_server_start_all(server_cb) != OGS_OK) return OGS_ERROR; diff --git a/src/nssf/sbi-path.h b/src/nssf/sbi-path.h index bb733041e..5309f32b6 100644 --- a/src/nssf/sbi-path.h +++ b/src/nssf/sbi-path.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -20,7 +20,7 @@ #ifndef NSSF_SBI_PATH_H #define NSSF_SBI_PATH_H -#include "nnrf-build.h" +#include "context.h" #ifdef __cplusplus extern "C" { diff --git a/src/nssf/timer.c b/src/nssf/timer.c deleted file mode 100644 index 2a105758e..000000000 --- a/src/nssf/timer.c +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (C) 2019,2020 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "context.h" - -const char *nssf_timer_get_name(nssf_timer_e id) -{ - switch (id) { - case NSSF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - return "NSSF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL"; - case NSSF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - return "NSSF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL"; - case NSSF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - return "NSSF_TIMER_NF_INSTANCE_NO_HEARTBEAT"; - case NSSF_TIMER_NF_INSTANCE_VALIDITY: - return "NSSF_TIMER_NF_INSTANCE_VALIDITY"; - case NSSF_TIMER_SUBSCRIPTION_VALIDITY: - return "NSSF_TIMER_SUBSCRIPTION_VALIDITY"; - default: - break; - } - - return "UNKNOWN_TIMER"; -} - -static void sbi_timer_send_event(int timer_id, void *data) -{ - int rv; - nssf_event_t *e = NULL; - ogs_assert(data); - - switch (timer_id) { - case NSSF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - case NSSF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - case NSSF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - case NSSF_TIMER_NF_INSTANCE_VALIDITY: - case NSSF_TIMER_SUBSCRIPTION_VALIDITY: - e = nssf_event_new(NSSF_EVT_SBI_TIMER); - ogs_assert(e); - e->timer_id = timer_id; - e->sbi.data = data; - break; - default: - ogs_fatal("Unknown timer id[%d]", timer_id); - ogs_assert_if_reached(); - break; - } - - rv = ogs_queue_push(ogs_app()->queue, e); - if (rv != OGS_OK) { - ogs_error("ogs_queue_push() failed [%d] in %s", - (int)rv, nssf_timer_get_name(e->timer_id)); - nssf_event_free(e); - } -} - -void nssf_timer_nf_instance_registration_interval(void *data) -{ - sbi_timer_send_event(NSSF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL, data); -} - -void nssf_timer_nf_instance_heartbeat_interval(void *data) -{ - sbi_timer_send_event(NSSF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL, data); -} - -void nssf_timer_nf_instance_no_heartbeat(void *data) -{ - sbi_timer_send_event(NSSF_TIMER_NF_INSTANCE_NO_HEARTBEAT, data); -} - -void nssf_timer_nf_instance_validity(void *data) -{ - sbi_timer_send_event(NSSF_TIMER_NF_INSTANCE_VALIDITY, data); -} - -void nssf_timer_subscription_validity(void *data) -{ - sbi_timer_send_event(NSSF_TIMER_SUBSCRIPTION_VALIDITY, data); -} - -void nssf_timer_sbi_client_wait_expire(void *data) -{ - sbi_timer_send_event(NSSF_TIMER_SBI_CLIENT_WAIT, data); -} diff --git a/src/nssf/timer.h b/src/nssf/timer.h deleted file mode 100644 index 67e10cac5..000000000 --- a/src/nssf/timer.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2019 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef NSSF_TIMER_H -#define NSSF_TIMER_H - -#include "ogs-core.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* forward declaration */ -typedef enum { - NSSF_TIMER_BASE = 0, - - NSSF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL, - NSSF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL, - NSSF_TIMER_NF_INSTANCE_NO_HEARTBEAT, - NSSF_TIMER_NF_INSTANCE_VALIDITY, - NSSF_TIMER_SUBSCRIPTION_VALIDITY, - NSSF_TIMER_SBI_CLIENT_WAIT, - - MAX_NUM_OF_NSSF_TIMER, - -} nssf_timer_e; - -const char *nssf_timer_get_name(nssf_timer_e id); - -void nssf_timer_nf_instance_registration_interval(void *data); -void nssf_timer_nf_instance_heartbeat_interval(void *data); -void nssf_timer_nf_instance_no_heartbeat(void *data); -void nssf_timer_nf_instance_validity(void *data); -void nssf_timer_subscription_validity(void *data); -void nssf_timer_sbi_client_wait_expire(void *data); - -#ifdef __cplusplus -} -#endif - -#endif /* NSSF_TIMER_H */ diff --git a/src/pcf/am-sm.c b/src/pcf/am-sm.c index 7197a6bec..f9d3429d0 100644 --- a/src/pcf/am-sm.c +++ b/src/pcf/am-sm.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -50,17 +50,17 @@ void pcf_am_state_operational(ogs_fsm_t *s, pcf_event_t *e) pcf_ue = e->pcf_ue; ogs_assert(pcf_ue); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: break; case OGS_FSM_EXIT_SIG: break; - case PCF_EVT_SBI_SERVER: - message = e->sbi.message; + case OGS_EVENT_SBI_SERVER: + message = e->h.sbi.message; ogs_assert(message); - stream = e->sbi.data; + stream = e->h.sbi.data; ogs_assert(stream); SWITCH(message->h.method) @@ -88,10 +88,10 @@ void pcf_am_state_operational(ogs_fsm_t *s, pcf_event_t *e) END break; - case PCF_EVT_SBI_CLIENT: - message = e->sbi.message; + case OGS_EVENT_SBI_CLIENT: + message = e->h.sbi.message; ogs_assert(message); - stream = e->sbi.data; + stream = e->h.sbi.data; ogs_assert(stream); SWITCH(message->h.service.name) @@ -161,7 +161,7 @@ void pcf_am_state_deleted(ogs_fsm_t *s, pcf_event_t *e) pcf_ue = e->pcf_ue; ogs_assert(pcf_ue); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: break; @@ -185,7 +185,7 @@ void pcf_am_state_exception(ogs_fsm_t *s, pcf_event_t *e) pcf_ue = e->pcf_ue; ogs_assert(pcf_ue); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: break; diff --git a/src/pcf/context.c b/src/pcf/context.c index dcfa62e49..55fe0d4ba 100644 --- a/src/pcf/context.c +++ b/src/pcf/context.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -159,8 +159,7 @@ pcf_ue_t *pcf_ue_add(char *supi) memset(&e, 0, sizeof(e)); e.pcf_ue = pcf_ue; - ogs_fsm_create(&pcf_ue->sm, pcf_am_state_initial, pcf_am_state_final); - ogs_fsm_init(&pcf_ue->sm, &e); + ogs_fsm_init(&pcf_ue->sm, pcf_am_state_initial, pcf_am_state_final, &e); ogs_list_add(&self.pcf_ue_list, pcf_ue); @@ -178,7 +177,6 @@ void pcf_ue_remove(pcf_ue_t *pcf_ue) memset(&e, 0, sizeof(e)); e.pcf_ue = pcf_ue; ogs_fsm_fini(&pcf_ue->sm, &e); - ogs_fsm_delete(&pcf_ue->sm); /* Free SBI object memory */ ogs_sbi_object_free(&pcf_ue->sbi); @@ -270,8 +268,7 @@ pcf_sess_t *pcf_sess_add(pcf_ue_t *pcf_ue, uint8_t psi) memset(&e, 0, sizeof(e)); e.sess = sess; - ogs_fsm_create(&sess->sm, pcf_sm_state_initial, pcf_sm_state_final); - ogs_fsm_init(&sess->sm, &e); + ogs_fsm_init(&sess->sm, pcf_sm_state_initial, pcf_sm_state_final, &e); ogs_list_add(&pcf_ue->sess_list, sess); @@ -290,7 +287,6 @@ void pcf_sess_remove(pcf_sess_t *sess) memset(&e, 0, sizeof(e)); e.sess = sess; ogs_fsm_fini(&sess->sm, &e); - ogs_fsm_delete(&sess->sm); /* Free SBI object memory */ ogs_sbi_object_free(&sess->sbi); diff --git a/src/pcf/context.h b/src/pcf/context.h index 19321f5b2..bb347d177 100644 --- a/src/pcf/context.h +++ b/src/pcf/context.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -26,7 +26,6 @@ #include "ogs-dbi.h" #include "pcf-sm.h" -#include "timer.h" #ifdef __cplusplus extern "C" { @@ -47,22 +46,6 @@ typedef struct pcf_context_s { ogs_hash_t *ipv6prefix_hash; } pcf_context_t; -#define PCF_NF_INSTANCE_CLEAR(_cAUSE, _nFInstance) \ - do { \ - ogs_assert(_nFInstance); \ - if ((_nFInstance)->reference_count == 1) { \ - ogs_info("[%s] (%s) NF removed", (_nFInstance)->id, (_cAUSE)); \ - pcf_nf_fsm_fini((_nFInstance)); \ - ogs_sbi_nf_instance_remove(_nFInstance); \ - } else { \ - /* There is an assocation with other context */ \ - ogs_info("[%s:%d] (%s) NF suspended", \ - _nFInstance->id, _nFInstance->reference_count, (_cAUSE)); \ - OGS_FSM_TRAN(&_nFInstance->sm, pcf_nf_state_de_registered); \ - ogs_fsm_dispatch(&_nFInstance->sm, NULL); \ - } \ - } while(0) - struct pcf_ue_s { ogs_sbi_object_t sbi; ogs_fsm_t sm; diff --git a/src/pcf/event.c b/src/pcf/event.c index 7ccee7df1..fbc73e9b9 100644 --- a/src/pcf/event.c +++ b/src/pcf/event.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -18,60 +18,42 @@ */ #include "event.h" -#include "context.h" -static OGS_POOL(pool, pcf_event_t); - -void pcf_event_init(void) -{ - ogs_pool_init(&pool, ogs_app()->pool.event); -} - -void pcf_event_final(void) -{ - ogs_pool_final(&pool); -} - -pcf_event_t *pcf_event_new(pcf_event_e id) +pcf_event_t *pcf_event_new(int id) { pcf_event_t *e = NULL; - ogs_pool_alloc(&pool, &e); + e = ogs_event_size(id, sizeof(pcf_event_t)); ogs_assert(e); - memset(e, 0, sizeof(*e)); - e->id = id; + e->h.id = id; return e; } -void pcf_event_free(pcf_event_t *e) -{ - ogs_assert(e); - ogs_pool_free(&pool, e); -} - const char *pcf_event_get_name(pcf_event_t *e) { - if (e == NULL) + if (e == NULL) { return OGS_FSM_NAME_INIT_SIG; - - switch (e->id) { - case OGS_FSM_ENTRY_SIG: - return OGS_FSM_NAME_ENTRY_SIG; - case OGS_FSM_EXIT_SIG: - return OGS_FSM_NAME_EXIT_SIG; - - case PCF_EVT_SBI_SERVER: - return "PCF_EVT_SBI_SERVER"; - case PCF_EVT_SBI_CLIENT: - return "PCF_EVT_SBI_CLIENT"; - case PCF_EVT_SBI_TIMER: - return "PCF_EVT_SBI_TIMER"; - - default: - break; } + switch (e->h.id) { + case OGS_FSM_ENTRY_SIG: + return OGS_FSM_NAME_ENTRY_SIG; + case OGS_FSM_EXIT_SIG: + return OGS_FSM_NAME_EXIT_SIG; + + case OGS_EVENT_SBI_SERVER: + return OGS_EVENT_NAME_SBI_SERVER; + case OGS_EVENT_SBI_CLIENT: + return OGS_EVENT_NAME_SBI_CLIENT; + case OGS_EVENT_SBI_TIMER: + return OGS_EVENT_NAME_SBI_TIMER; + + default: + break; + } + + ogs_error("Unknown Event[%d]", e->h.id); return "UNKNOWN_EVENT"; } diff --git a/src/pcf/event.h b/src/pcf/event.h index 58de3e609..5f746dd5b 100644 --- a/src/pcf/event.h +++ b/src/pcf/event.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -20,57 +20,25 @@ #ifndef PCF_EVENT_H #define PCF_EVENT_H -#include "ogs-core.h" +#include "ogs-proto.h" #ifdef __cplusplus extern "C" { #endif -typedef struct ogs_sbi_request_s ogs_sbi_request_t; -typedef struct ogs_sbi_response_s ogs_sbi_response_t; -typedef struct ogs_sbi_message_s ogs_sbi_message_t; -typedef struct ogs_sbi_nf_instance_s ogs_sbi_nf_instance_t; -typedef struct ogs_sbi_subscription_s ogs_sbi_subscription_t; - typedef struct pcf_ue_s pcf_ue_t; typedef struct pcf_sess_s pcf_sess_t; typedef struct pcf_app_s pcf_app_t; -typedef enum { - PCF_EVT_BASE = OGS_FSM_USER_SIG, - - PCF_EVT_SBI_SERVER, - PCF_EVT_SBI_CLIENT, - PCF_EVT_SBI_TIMER, - - PCF_EVT_TOP, - -} pcf_event_e; - typedef struct pcf_event_s { - int id; - int timer_id; - - struct { - ogs_sbi_request_t *request; - ogs_sbi_response_t *response; - void *data; - - ogs_sbi_message_t *message; - } sbi; + ogs_event_t h; pcf_ue_t *pcf_ue; pcf_sess_t *sess; pcf_app_t *app; - - ogs_timer_t *timer; } pcf_event_t; -void pcf_event_init(void); -void pcf_event_final(void); - -pcf_event_t *pcf_event_new(pcf_event_e id); -void pcf_event_free(pcf_event_t *e); +pcf_event_t *pcf_event_new(int id); const char *pcf_event_get_name(pcf_event_t *e); diff --git a/src/pcf/init.c b/src/pcf/init.c index 91332c9f7..e87141754 100644 --- a/src/pcf/init.c +++ b/src/pcf/init.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -30,7 +30,6 @@ int pcf_initialize() ogs_sbi_context_init(); pcf_context_init(); - pcf_event_init(); rv = ogs_sbi_context_parse_config("pcf", "nrf", "scp"); if (rv != OGS_OK) return rv; @@ -64,7 +63,7 @@ static void event_termination(void) /* Sending NF Instance De-registeration to NRF */ ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) - pcf_nf_fsm_fini(nf_instance); + ogs_sbi_nf_fsm_fini(nf_instance); /* Starting holding timer */ t_termination_holding = ogs_timer_add(ogs_app()->timer_mgr, NULL, NULL); @@ -92,8 +91,6 @@ void pcf_terminate(void) pcf_context_final(); ogs_sbi_context_final(); - - pcf_event_final(); /* Destroy event */ } static void pcf_main(void *data) @@ -101,8 +98,7 @@ static void pcf_main(void *data) ogs_fsm_t pcf_sm; int rv; - ogs_fsm_create(&pcf_sm, pcf_state_initial, pcf_state_final); - ogs_fsm_init(&pcf_sm, 0); + ogs_fsm_init(&pcf_sm, pcf_state_initial, pcf_state_final, 0); for ( ;; ) { ogs_pollset_poll(ogs_app()->pollset, @@ -135,11 +131,10 @@ static void pcf_main(void *data) ogs_assert(e); ogs_fsm_dispatch(&pcf_sm, e); - pcf_event_free(e); + ogs_event_free(e); } } done: ogs_fsm_fini(&pcf_sm, 0); - ogs_fsm_delete(&pcf_sm); } diff --git a/src/pcf/meson.build b/src/pcf/meson.build index 72ed9125e..5b1c13ba4 100644 --- a/src/pcf/meson.build +++ b/src/pcf/meson.build @@ -1,4 +1,4 @@ -# Copyright (C) 2019,2020 by Sukchan Lee +# Copyright (C) 2019-2022 by Sukchan Lee # This file is part of Open5GS. @@ -18,12 +18,8 @@ libpcf_sources = files(''' context.c event.c - timer.c - nnrf-build.c nnrf-handler.c - nf-sm.c - npcf-handler.c nudr-build.c diff --git a/src/pcf/nbsf-build.c b/src/pcf/nbsf-build.c index 0aab0bbb6..05755e84c 100644 --- a/src/pcf/nbsf-build.c +++ b/src/pcf/nbsf-build.c @@ -36,10 +36,6 @@ ogs_sbi_request_t *pcf_nbsf_management_build_register( ogs_sbi_nf_service_t *nf_service = NULL; int i; -#if SBI_FQDN_WITH_ONE_OCTET_LENGTH - int fqdn_len; - char fqdn[OGS_MAX_FQDN_LEN]; -#endif ogs_assert(sess); pcf_ue = sess->pcf_ue; @@ -68,18 +64,8 @@ ogs_sbi_request_t *pcf_nbsf_management_build_register( nf_service = ogs_list_first(&nf_instance->nf_service_list); ogs_expect_or_return_val(nf_service, NULL); - if (nf_service->fqdn) { -#if SBI_FQDN_WITH_ONE_OCTET_LENGTH - memset(fqdn, 0, sizeof(fqdn)); - fqdn_len = ogs_fqdn_build(fqdn, - nf_service->fqdn, strlen(nf_service->fqdn)); - PcfBinding.pcf_fqdn = ogs_memdup(fqdn, fqdn_len+1); - ogs_expect_or_return_val(PcfBinding.pcf_fqdn, NULL); - PcfBinding.pcf_fqdn[fqdn_len] = 0; -#else + if (nf_service->fqdn) PcfBinding.pcf_fqdn = ogs_strdup(nf_service->fqdn); -#endif - } PcfIpEndPointList = OpenAPI_list_create(); ogs_assert(PcfIpEndPointList); diff --git a/src/pcf/nf-sm.c b/src/pcf/nf-sm.c deleted file mode 100644 index b6fc57506..000000000 --- a/src/pcf/nf-sm.c +++ /dev/null @@ -1,453 +0,0 @@ -/* - * Copyright (C) 2019,2020 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "context.h" - -#include "sbi-path.h" -#include "nnrf-handler.h" - -void pcf_nf_fsm_init(ogs_sbi_nf_instance_t *nf_instance) -{ - pcf_event_t e; - - ogs_assert(nf_instance); - - memset(&e, 0, sizeof(e)); - e.sbi.data = nf_instance; - - ogs_fsm_create(&nf_instance->sm, - pcf_nf_state_initial, pcf_nf_state_final); - ogs_fsm_init(&nf_instance->sm, &e); -} - -void pcf_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance) -{ - pcf_event_t e; - - ogs_assert(nf_instance); - - memset(&e, 0, sizeof(e)); - e.sbi.data = nf_instance; - - ogs_fsm_fini(&nf_instance->sm, &e); - ogs_fsm_delete(&nf_instance->sm); -} - -void pcf_nf_state_initial(ogs_fsm_t *s, pcf_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - - ogs_assert(s); - ogs_assert(e); - - pcf_sm_debug(e); - - nf_instance = e->sbi.data; - ogs_assert(nf_instance); - - nf_instance->t_registration_interval = ogs_timer_add(ogs_app()->timer_mgr, - pcf_timer_nf_instance_registration_interval, nf_instance); - ogs_assert(nf_instance->t_registration_interval); - nf_instance->t_heartbeat_interval = ogs_timer_add(ogs_app()->timer_mgr, - pcf_timer_nf_instance_heartbeat_interval, nf_instance); - ogs_assert(nf_instance->t_heartbeat_interval); - nf_instance->t_no_heartbeat = ogs_timer_add(ogs_app()->timer_mgr, - pcf_timer_nf_instance_no_heartbeat, nf_instance); - ogs_assert(nf_instance->t_no_heartbeat); - nf_instance->t_validity = ogs_timer_add(ogs_app()->timer_mgr, - pcf_timer_nf_instance_validity, nf_instance); - ogs_assert(nf_instance->t_validity); - - 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); - } -} - -void pcf_nf_state_final(ogs_fsm_t *s, pcf_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - - ogs_assert(s); - ogs_assert(e); - - pcf_sm_debug(e); - - nf_instance = e->sbi.data; - ogs_assert(nf_instance); - - ogs_timer_delete(nf_instance->t_registration_interval); - ogs_timer_delete(nf_instance->t_heartbeat_interval); - ogs_timer_delete(nf_instance->t_no_heartbeat); - ogs_timer_delete(nf_instance->t_validity); -} - -void pcf_nf_state_will_register(ogs_fsm_t *s, pcf_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_sbi_client_t *client = NULL; - ogs_sbi_message_t *message = NULL; - ogs_sockaddr_t *addr = NULL; - - ogs_assert(s); - ogs_assert(e); - - pcf_sm_debug(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: - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); - - ogs_assert(true == ogs_nnrf_nfm_send_nf_register( - nf_instance, pcf_nnrf_nfm_build_register)); - break; - - case OGS_FSM_EXIT_SIG: - ogs_timer_stop(nf_instance->t_registration_interval); - break; - - case PCF_EVT_SBI_CLIENT: - message = e->sbi.message; - ogs_assert(message); - - SWITCH(message->h.service.name) - CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) - - SWITCH(message->h.resource.component[0]) - CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - - if (message->res_status == OGS_SBI_HTTP_STATUS_OK || - message->res_status == OGS_SBI_HTTP_STATUS_CREATED) { - pcf_nnrf_handle_nf_register(nf_instance, message); - OGS_FSM_TRAN(s, &pcf_nf_state_registered); - } else { - ogs_error("[%s] HTTP response error [%d]", - 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]", - ogs_sbi_self()->nf_instance->id, - message->h.resource.component[0]); - END - break; - - DEFAULT - ogs_error("[%s] Invalid API name [%s]", - ogs_sbi_self()->nf_instance->id, - message->h.service.name); - END - break; - - case PCF_EVT_SBI_TIMER: - switch(e->timer_id) { - case PCF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - client = nf_instance->client; - ogs_assert(client); - addr = client->node.addr; - ogs_assert(addr); - - ogs_warn("[%s] Retry to registration with NRF", - ogs_sbi_self()->nf_instance->id); - - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); - - ogs_assert(true == ogs_nnrf_nfm_send_nf_register( - nf_instance, pcf_nnrf_nfm_build_register)); - break; - - default: - ogs_error("[%s] Unknown timer[%s:%d]", - ogs_sbi_self()->nf_instance->id, - pcf_timer_get_name(e->timer_id), e->timer_id); - } - break; - - default: - ogs_error("Unknown event %s", pcf_event_get_name(e)); - break; - } -} - -void pcf_nf_state_registered(ogs_fsm_t *s, pcf_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_sbi_client_t *client = NULL; - ogs_sbi_message_t *message = NULL; - ogs_assert(s); - ogs_assert(e); - - pcf_sm_debug(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_NRF(nf_instance)) { - ogs_info("[%s] NF registered [Heartbeat:%ds]", - ogs_sbi_self()->nf_instance->id, - nf_instance->time.heartbeat_interval); - - client = nf_instance->client; - ogs_assert(client); - - if (nf_instance->time.heartbeat_interval) { - ogs_timer_start(nf_instance->t_heartbeat_interval, - ogs_time_from_sec(nf_instance->time.heartbeat_interval)); - ogs_timer_start(nf_instance->t_no_heartbeat, - ogs_time_from_sec( - nf_instance->time.heartbeat_interval + - ogs_app()->time.nf_instance.no_heartbeat_margin)); - } - - ogs_assert(true == - ogs_nnrf_nfm_send_nf_status_subscribe(client, - 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, - 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_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); - ogs_timer_stop(nf_instance->t_no_heartbeat); - } - - if (!OGS_FSM_CHECK(&nf_instance->sm, pcf_nf_state_exception)) { - ogs_assert(true == - ogs_nnrf_nfm_send_nf_de_register(nf_instance)); - } - } - break; - - case PCF_EVT_SBI_CLIENT: - message = e->sbi.message; - ogs_assert(message); - - SWITCH(message->h.service.name) - CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) - - SWITCH(message->h.resource.component[0]) - CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - - if (message->res_status == OGS_SBI_HTTP_STATUS_NO_CONTENT || - message->res_status == OGS_SBI_HTTP_STATUS_OK) { - if (nf_instance->time.heartbeat_interval) - ogs_timer_start(nf_instance->t_no_heartbeat, - ogs_time_from_sec( - nf_instance->time.heartbeat_interval + - ogs_app()->time.nf_instance. - no_heartbeat_margin)); - } else { - ogs_warn("[%s] HTTP response error [%d]", - 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]", - ogs_sbi_self()->nf_instance->id, - message->h.resource.component[0]); - END - break; - - DEFAULT - ogs_error("[%s] Invalid API name [%s]", - ogs_sbi_self()->nf_instance->id, message->h.service.name); - END - break; - - case PCF_EVT_SBI_TIMER: - switch(e->timer_id) { - case PCF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - if (nf_instance->time.heartbeat_interval) - ogs_timer_start(nf_instance->t_heartbeat_interval, - ogs_time_from_sec(nf_instance->time.heartbeat_interval)); - - ogs_assert(true == ogs_nnrf_nfm_send_nf_update(nf_instance)); - break; - - case PCF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - 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: - 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:%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; - - default: - 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; - } -} - -void pcf_nf_state_de_registered(ogs_fsm_t *s, pcf_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_assert(s); - ogs_assert(e); - - pcf_sm_debug(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_NRF(nf_instance)) { - ogs_info("[%s] NF de-registered", ogs_sbi_self()->nf_instance->id); - } - break; - - case OGS_FSM_EXIT_SIG: - break; - - default: - 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; - } -} - -void pcf_nf_state_exception(ogs_fsm_t *s, pcf_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_sbi_client_t *client = NULL; - ogs_sbi_message_t *message = NULL; - ogs_sockaddr_t *addr = NULL; - ogs_assert(s); - ogs_assert(e); - - pcf_sm_debug(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_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_NRF(nf_instance)) { - ogs_timer_stop(nf_instance->t_registration_interval); - } - break; - - case PCF_EVT_SBI_TIMER: - switch(e->timer_id) { - case PCF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - client = nf_instance->client; - ogs_assert(client); - addr = client->node.addr; - ogs_assert(addr); - - 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:%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; - - case PCF_EVT_SBI_CLIENT: - message = e->sbi.message; - ogs_assert(message); - - SWITCH(message->h.service.name) - CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) - - SWITCH(message->h.resource.component[0]) - CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - break; - DEFAULT - ogs_error("Invalid resource name [%s]", - message->h.resource.component[0]); - END - break; - DEFAULT - ogs_error("Invalid API name [%s]", message->h.service.name); - END - break; - - default: - 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 deleted file mode 100644 index a265cec50..000000000 --- a/src/pcf/nnrf-build.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2019,2020 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "nnrf-build.h" - -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; - - OpenAPI_nf_profile_t *NFProfile = 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_PUT; - message.h.service.name = (char *)OGS_SBI_SERVICE_NAME_NNRF_NFM; - 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] = nf_instance->id; - - message.http.content_encoding = (char*)ogs_sbi_self()->content_encoding; - - NFProfile = ogs_nnrf_nfm_build_nf_profile(); - ogs_expect_or_return_val(NFProfile, NULL); - - message.NFProfile = NFProfile; - - request = ogs_sbi_build_request(&message); - - ogs_sbi_nnrf_free_nf_profile(NFProfile); - - return request; -} diff --git a/src/pcf/nnrf-build.h b/src/pcf/nnrf-build.h deleted file mode 100644 index 3e13d241e..000000000 --- a/src/pcf/nnrf-build.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2019,2020 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef PCF_NNRF_BUILD_H -#define PCF_NNRF_BUILD_H - -#include "context.h" - -#ifdef __cplusplus -extern "C" { -#endif - -ogs_sbi_request_t *pcf_nnrf_nfm_build_register(void); - -#ifdef __cplusplus -} -#endif - -#endif /* PCF_NNRF_BUILD_H */ diff --git a/src/pcf/nnrf-handler.c b/src/pcf/nnrf-handler.c index b137faf3a..f44ce32ed 100644 --- a/src/pcf/nnrf-handler.c +++ b/src/pcf/nnrf-handler.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -20,233 +20,6 @@ #include "sbi-path.h" #include "nnrf-handler.h" -void pcf_nnrf_handle_nf_register( - ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_message_t *recvmsg) -{ - OpenAPI_nf_profile_t *NFProfile = NULL; - ogs_sbi_client_t *client = NULL; - - ogs_assert(recvmsg); - ogs_assert(nf_instance); - client = nf_instance->client; - ogs_assert(client); - - NFProfile = recvmsg->NFProfile; - if (!NFProfile) { - ogs_error("No NFProfile"); - return; - } - - /* TIME : Update heartbeat from NRF */ - if (NFProfile->is_heart_beat_timer == true) - nf_instance->time.heartbeat_interval = NFProfile->heart_beat_timer; -} - -void pcf_nnrf_handle_nf_status_subscribe( - ogs_sbi_subscription_t *subscription, ogs_sbi_message_t *recvmsg) -{ - OpenAPI_subscription_data_t *SubscriptionData = NULL; - ogs_sbi_client_t *client = NULL; - - ogs_assert(recvmsg); - ogs_assert(subscription); - client = subscription->client; - ogs_assert(client); - - SubscriptionData = recvmsg->SubscriptionData; - if (!SubscriptionData) { - ogs_error("No SubscriptionData"); - return; - } - - if (!SubscriptionData->subscription_id) { - ogs_error("No SubscriptionId"); - return; - } - ogs_sbi_subscription_set_id( - subscription, SubscriptionData->subscription_id); - - if (SubscriptionData->validity_time) { -#define VALIDITY_MINIMUM (10LL * OGS_USEC_PER_SEC) /* 10 seconds */ - ogs_time_t time, duration; - if (ogs_sbi_time_from_string( - &time, SubscriptionData->validity_time) == true) { - duration = time - ogs_time_now(); - if (duration < VALIDITY_MINIMUM) { - duration = VALIDITY_MINIMUM; - ogs_warn("[%s] Forced to %lld seconds", subscription->id, - (long long)ogs_time_sec(VALIDITY_MINIMUM)); - } - subscription->t_validity = ogs_timer_add(ogs_app()->timer_mgr, - pcf_timer_subscription_validity, subscription); - ogs_assert(subscription->t_validity); - ogs_timer_start(subscription->t_validity, duration); - } else { - ogs_error("Cannot parse validitiyTime [%s]", - SubscriptionData->validity_time); - } - } -} - -bool pcf_nnrf_handle_nf_status_notify( - ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) -{ - int rv; - bool handled; - - ogs_sbi_response_t *response = NULL; - OpenAPI_notification_data_t *NotificationData = NULL; - ogs_sbi_nf_instance_t *nf_instance = NULL; - - ogs_sbi_message_t message; - ogs_sbi_header_t header; - - ogs_assert(stream); - ogs_assert(recvmsg); - - NotificationData = recvmsg->NotificationData; - if (!NotificationData) { - ogs_error("No NotificationData"); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "No NotificationData", NULL)); - return false; - } - - if (!NotificationData->nf_instance_uri) { - ogs_error("No nfInstanceUri"); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "No nfInstanceUri", NULL)); - return false; - } - - memset(&header, 0, sizeof(header)); - header.uri = NotificationData->nf_instance_uri; - - rv = ogs_sbi_parse_header(&message, &header); - if (rv != OGS_OK) { - ogs_error("Cannot parse nfInstanceUri [%s]", header.uri); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Cannot parse nfInstanceUri", header.uri)); - return false; - } - - if (!message.h.resource.component[1]) { - ogs_error("No nfInstanceId [%s]", header.uri); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Cannot parse nfInstanceUri", header.uri)); - ogs_sbi_header_free(&header); - return false; - } - - if (NF_INSTANCE_IS_SELF(message.h.resource.component[1])) { - ogs_warn("[%s] The notification is not allowed", - message.h.resource.component[1]); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, - recvmsg, "The notification is not allowed", - message.h.resource.component[1])); - ogs_sbi_header_free(&header); - return false; - } - - if (NotificationData->event == - OpenAPI_notification_event_type_NF_REGISTERED) { - - OpenAPI_nf_profile_t *NFProfile = NULL; - - NFProfile = NotificationData->nf_profile; - if (!NFProfile) { - ogs_error("No NFProfile"); - ogs_assert(true == - ogs_sbi_server_send_error( - stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "No NFProfile", NULL)); - ogs_sbi_header_free(&header); - return false; - } - - nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); - if (!nf_instance) { - 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); - - ogs_info("[%s] (NRF-notify) NF registered", nf_instance->id); - - } else { - OGS_FSM_TRAN(&nf_instance->sm, pcf_nf_state_registered); - ogs_fsm_dispatch(&nf_instance->sm, NULL); - - ogs_warn("[%s] (NRF-notify) NF has already been added", - message.h.resource.component[1]); - - } - - handled = ogs_sbi_nnrf_handle_nf_profile( - nf_instance, NFProfile, stream, recvmsg); - if (!handled) { - PCF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); - ogs_sbi_header_free(&header); - return false; - } - - ogs_info("[%s] (NRF-notify) NF Profile updated", nf_instance->id); - - handled = ogs_sbi_client_associate(nf_instance); - if (!handled) { - ogs_error("[%s] Cannot associate NF EndPoint", nf_instance->id); - ogs_assert(true == - ogs_sbi_server_send_error(stream, - OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Cannot find NF EndPoint", nf_instance->id)); - PCF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); - ogs_sbi_header_free(&header); - return false; - } - - } else if (NotificationData->event == - OpenAPI_notification_event_type_NF_DEREGISTERED) { - nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); - if (nf_instance) { - PCF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); - } else { - ogs_warn("[%s] (NRF-notify) Not found", - message.h.resource.component[1]); - ogs_assert(true == - ogs_sbi_server_send_error(stream, - OGS_SBI_HTTP_STATUS_NOT_FOUND, - recvmsg, "Not found", message.h.resource.component[1])); - ogs_sbi_header_free(&header); - return false; - } - } else { - char *eventstr = OpenAPI_notification_event_type_ToString( - NotificationData->event); - ogs_error("Not supported event [%d:%s]", - NotificationData->event, eventstr ? eventstr : "Unknown"); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Not supported event", - eventstr ? eventstr : "Unknown")); - ogs_sbi_header_free(&header); - return false; - } - - response = ogs_sbi_build_response(recvmsg, OGS_SBI_HTTP_STATUS_NO_CONTENT); - ogs_assert(response); - ogs_assert(true == ogs_sbi_server_send_response(stream, response)); - - ogs_sbi_header_free(&header); - return true; -} - void pcf_nnrf_handle_nf_discover( ogs_sbi_xact_t *xact, ogs_sbi_message_t *recvmsg) { @@ -254,11 +27,7 @@ void pcf_nnrf_handle_nf_discover( OpenAPI_nf_type_e target_nf_type = 0; ogs_sbi_discovery_option_t *discovery_option = NULL; - ogs_sbi_nf_instance_t *nf_instance = NULL; - OpenAPI_search_result_t *SearchResult = NULL; - OpenAPI_lnode_t *node = NULL; - bool handled; ogs_assert(recvmsg); ogs_assert(xact); @@ -275,64 +44,8 @@ void pcf_nnrf_handle_nf_discover( return; } - OpenAPI_list_for_each(SearchResult->nf_instances, node) { - OpenAPI_nf_profile_t *NFProfile = NULL; - - if (!node->data) continue; - - NFProfile = node->data; - - nf_instance = ogs_sbi_nf_instance_find(NFProfile->nf_instance_id); - if (!nf_instance) { - 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); - - ogs_info("[%s] (NF-discover) NF registered", nf_instance->id); - } else { - OGS_FSM_TRAN(&nf_instance->sm, pcf_nf_state_registered); - ogs_fsm_dispatch(&nf_instance->sm, NULL); - - ogs_warn("[%s] (NF-discover) NF has already been added", - NFProfile->nf_instance_id); - } - - if (NF_INSTANCE_IS_OTHERS(nf_instance->id)) { - handled = ogs_sbi_nnrf_handle_nf_profile( - nf_instance, NFProfile, NULL, NULL); - if (!handled) { - ogs_error("[%s] ogs_sbi_nnrf_handle_nf_profile() failed", - nf_instance->id); - PCF_NF_INSTANCE_CLEAR("NRF-discover", nf_instance); - continue; - } - - handled = ogs_sbi_client_associate(nf_instance); - if (!handled) { - ogs_error("[%s] Cannot assciate NF EndPoint", nf_instance->id); - PCF_NF_INSTANCE_CLEAR("NRF-discover", nf_instance); - continue; - } - - /* TIME : Update validity from NRF */ - if (SearchResult->is_validity_period && - SearchResult->validity_period) { - nf_instance->time.validity_duration = - SearchResult->validity_period; - - ogs_assert(nf_instance->t_validity); - ogs_timer_start(nf_instance->t_validity, - ogs_time_from_sec(nf_instance->time.validity_duration)); - - } else - ogs_warn("[%s] NF Instance validity-time should not 0", - nf_instance->id); - - ogs_info("[%s] (NF-discover) NF Profile updated", nf_instance->id); - } - } + ogs_nnrf_handle_nf_discover_search_result( + sbi_object, target_nf_type, discovery_option, SearchResult); ogs_sbi_select_nf(sbi_object, target_nf_type, discovery_option); diff --git a/src/pcf/nnrf-handler.h b/src/pcf/nnrf-handler.h index c3965ce3a..7ae650349 100644 --- a/src/pcf/nnrf-handler.h +++ b/src/pcf/nnrf-handler.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -26,14 +26,6 @@ extern "C" { #endif -void pcf_nnrf_handle_nf_register( - ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_message_t *recvmsg); -void pcf_nnrf_handle_nf_status_subscribe( - ogs_sbi_subscription_t *subscription, ogs_sbi_message_t *recvmsg); - -bool pcf_nnrf_handle_nf_status_notify( - ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); - void pcf_nnrf_handle_nf_discover( ogs_sbi_xact_t *xact, ogs_sbi_message_t *recvmsg); diff --git a/src/pcf/pcf-sm.c b/src/pcf/pcf-sm.c index 37b261faa..cfb30ecb2 100644 --- a/src/pcf/pcf-sm.c +++ b/src/pcf/pcf-sm.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -59,17 +59,17 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e) ogs_assert(s); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: break; case OGS_FSM_EXIT_SIG: break; - case PCF_EVT_SBI_SERVER: - request = e->sbi.request; + case OGS_EVENT_SBI_SERVER: + request = e->h.sbi.request; ogs_assert(request); - stream = e->sbi.data; + stream = e->h.sbi.data; ogs_assert(stream); rv = ogs_sbi_parse_request(&message, request); @@ -100,7 +100,7 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e) CASE(OGS_SBI_RESOURCE_NAME_NF_STATUS_NOTIFY) SWITCH(message.h.method) CASE(OGS_SBI_HTTP_METHOD_POST) - pcf_nnrf_handle_nf_status_notify(stream, &message); + ogs_nnrf_handle_nf_status_notify(stream, &message); break; DEFAULT @@ -160,7 +160,7 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e) ogs_assert(OGS_FSM_STATE(&pcf_ue->sm)); e->pcf_ue = pcf_ue; - e->sbi.message = &message; + e->h.sbi.message = &message; ogs_fsm_dispatch(&pcf_ue->sm, e); if (OGS_FSM_CHECK(&pcf_ue->sm, pcf_am_state_exception)) { ogs_error("[%s] State machine exception", pcf_ue->supi); @@ -214,7 +214,7 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e) ogs_assert(OGS_FSM_STATE(&sess->sm)); e->sess = sess; - e->sbi.message = &message; + e->h.sbi.message = &message; ogs_fsm_dispatch(&sess->sm, e); if (OGS_FSM_CHECK(&sess->sm, pcf_sm_state_exception)) { ogs_error("[%s:%d] State machine exception", @@ -265,7 +265,7 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e) e->sess = sess; e->app = app_session; - e->sbi.message = &message; + e->h.sbi.message = &message; ogs_fsm_dispatch(&sess->sm, e); if (OGS_FSM_CHECK(&sess->sm, pcf_sm_state_exception)) { ogs_error("[%s:%d] State machine exception", @@ -286,10 +286,10 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e) ogs_sbi_message_free(&message); break; - case PCF_EVT_SBI_CLIENT: + case OGS_EVENT_SBI_CLIENT: ogs_assert(e); - response = e->sbi.response; + response = e->h.sbi.response; ogs_assert(response); rv = ogs_sbi_parse_response(&message, response); if (rv != OGS_OK) { @@ -311,23 +311,23 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e) SWITCH(message.h.resource.component[0]) CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - nf_instance = e->sbi.data; + nf_instance = e->h.sbi.data; ogs_assert(nf_instance); ogs_assert(OGS_FSM_STATE(&nf_instance->sm)); - e->sbi.message = &message; + e->h.sbi.message = &message; ogs_fsm_dispatch(&nf_instance->sm, e); break; CASE(OGS_SBI_RESOURCE_NAME_SUBSCRIPTIONS) - subscription = e->sbi.data; + subscription = e->h.sbi.data; ogs_assert(subscription); SWITCH(message.h.method) CASE(OGS_SBI_HTTP_METHOD_POST) if (message.res_status == OGS_SBI_HTTP_STATUS_CREATED || message.res_status == OGS_SBI_HTTP_STATUS_OK) { - pcf_nnrf_handle_nf_status_subscribe( + ogs_nnrf_handle_nf_status_subscribe( subscription, &message); } else { ogs_error("[%s] HTTP response error [%d]", @@ -362,7 +362,7 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e) CASE(OGS_SBI_SERVICE_NAME_NNRF_DISC) SWITCH(message.h.resource.component[0]) CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - sbi_xact = e->sbi.data; + sbi_xact = e->h.sbi.data; ogs_assert(sbi_xact); SWITCH(message.h.method) @@ -392,7 +392,7 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e) CASE(OGS_SBI_RESOURCE_NAME_POLICY_DATA) SWITCH(message.h.resource.component[3]) CASE(OGS_SBI_RESOURCE_NAME_AM_DATA) - sbi_xact = e->sbi.data; + sbi_xact = e->h.sbi.data; ogs_assert(sbi_xact); sbi_xact = ogs_sbi_xact_cycle(sbi_xact); @@ -406,7 +406,7 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e) pcf_ue = (pcf_ue_t *)sbi_xact->sbi_object; ogs_assert(pcf_ue); - e->sbi.data = sbi_xact->assoc_stream; + e->h.sbi.data = sbi_xact->assoc_stream; ogs_sbi_xact_remove(sbi_xact); @@ -418,7 +418,7 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e) } e->pcf_ue = pcf_ue; - e->sbi.message = &message; + e->h.sbi.message = &message; ogs_fsm_dispatch(&pcf_ue->sm, e); if (OGS_FSM_CHECK(&pcf_ue->sm, pcf_am_state_exception)) { @@ -428,7 +428,7 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e) break; CASE(OGS_SBI_RESOURCE_NAME_SM_DATA) - sbi_xact = e->sbi.data; + sbi_xact = e->h.sbi.data; ogs_assert(sbi_xact); sbi_xact = ogs_sbi_xact_cycle(sbi_xact); @@ -442,7 +442,7 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e) sess = (pcf_sess_t *)sbi_xact->sbi_object; ogs_assert(sess); - e->sbi.data = sbi_xact->assoc_stream; + e->h.sbi.data = sbi_xact->assoc_stream; ogs_sbi_xact_remove(sbi_xact); @@ -458,7 +458,7 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e) ogs_assert(pcf_ue); e->sess = sess; - e->sbi.message = &message; + e->h.sbi.message = &message; ogs_fsm_dispatch(&sess->sm, e); if (OGS_FSM_CHECK(&sess->sm, pcf_sm_state_exception)) { @@ -487,7 +487,7 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e) SWITCH(message.h.resource.component[0]) CASE(OGS_SBI_RESOURCE_NAME_PCF_BINDINGS) - sbi_xact = e->sbi.data; + sbi_xact = e->h.sbi.data; ogs_assert(sbi_xact); sbi_xact = ogs_sbi_xact_cycle(sbi_xact); @@ -501,7 +501,7 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e) sess = (pcf_sess_t *)sbi_xact->sbi_object; ogs_assert(sess); - e->sbi.data = sbi_xact->assoc_stream; + e->h.sbi.data = sbi_xact->assoc_stream; ogs_sbi_xact_remove(sbi_xact); @@ -517,7 +517,7 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e) ogs_assert(pcf_ue); e->sess = sess; - e->sbi.message = &message; + e->h.sbi.message = &message; ogs_fsm_dispatch(&sess->sm, e); if (OGS_FSM_CHECK(&sess->sm, pcf_sm_state_exception)) { @@ -547,27 +547,27 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e) ogs_sbi_response_free(response); break; - case PCF_EVT_SBI_TIMER: + case OGS_EVENT_SBI_TIMER: ogs_assert(e); - switch(e->timer_id) { - case PCF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - case PCF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - case PCF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - case PCF_TIMER_NF_INSTANCE_VALIDITY: - nf_instance = e->sbi.data; + switch(e->h.timer_id) { + case OGS_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: + case OGS_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: + case OGS_TIMER_NF_INSTANCE_NO_HEARTBEAT: + case OGS_TIMER_NF_INSTANCE_VALIDITY: + nf_instance = e->h.sbi.data; ogs_assert(nf_instance); ogs_assert(OGS_FSM_STATE(&nf_instance->sm)); ogs_fsm_dispatch(&nf_instance->sm, e); - if (OGS_FSM_CHECK(&nf_instance->sm, pcf_nf_state_exception)) + if (OGS_FSM_CHECK(&nf_instance->sm, ogs_sbi_nf_state_exception)) ogs_error("[%s:%s] State machine exception [%d]", OpenAPI_nf_type_ToString(nf_instance->nf_type), - nf_instance->id, e->timer_id); + nf_instance->id, e->h.timer_id); break; - case PCF_TIMER_SUBSCRIPTION_VALIDITY: - subscription = e->sbi.data; + case OGS_TIMER_SUBSCRIPTION_VALIDITY: + subscription = e->h.sbi.data; ogs_assert(subscription); ogs_assert(ogs_sbi_self()->nf_instance); @@ -581,8 +581,8 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e) ogs_sbi_subscription_remove(subscription); break; - case PCF_TIMER_SBI_CLIENT_WAIT: - sbi_xact = e->sbi.data; + case OGS_TIMER_SBI_CLIENT_WAIT: + sbi_xact = e->h.sbi.data; ogs_assert(sbi_xact); sbi_object = sbi_xact->sbi_object; @@ -636,7 +636,7 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e) default: ogs_error("Unknown timer[%s:%d]", - pcf_timer_get_name(e->timer_id), e->timer_id); + ogs_timer_get_name(e->h.timer_id), e->h.timer_id); } break; diff --git a/src/pcf/pcf-sm.h b/src/pcf/pcf-sm.h index c281c0fd6..4200f2ec2 100644 --- a/src/pcf/pcf-sm.h +++ b/src/pcf/pcf-sm.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -30,16 +30,6 @@ void pcf_state_initial(ogs_fsm_t *s, pcf_event_t *e); void pcf_state_final(ogs_fsm_t *s, pcf_event_t *e); void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e); -void pcf_nf_fsm_init(ogs_sbi_nf_instance_t *nf_instance); -void pcf_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance); - -void pcf_nf_state_initial(ogs_fsm_t *s, pcf_event_t *e); -void pcf_nf_state_final(ogs_fsm_t *s, pcf_event_t *e); -void pcf_nf_state_will_register(ogs_fsm_t *s, pcf_event_t *e); -void pcf_nf_state_registered(ogs_fsm_t *s, pcf_event_t *e); -void pcf_nf_state_de_registered(ogs_fsm_t *s, pcf_event_t *e); -void pcf_nf_state_exception(ogs_fsm_t *s, pcf_event_t *e); - void pcf_am_state_initial(ogs_fsm_t *s, pcf_event_t *e); void pcf_am_state_final(ogs_fsm_t *s, pcf_event_t *e); void pcf_am_state_operational(ogs_fsm_t *s, pcf_event_t *e); diff --git a/src/pcf/sbi-path.c b/src/pcf/sbi-path.c index 1c5489c5d..ee94a7d2d 100644 --- a/src/pcf/sbi-path.c +++ b/src/pcf/sbi-path.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -27,17 +27,17 @@ static int server_cb(ogs_sbi_request_t *request, void *data) ogs_assert(request); ogs_assert(data); - e = pcf_event_new(PCF_EVT_SBI_SERVER); + e = pcf_event_new(OGS_EVENT_SBI_SERVER); ogs_assert(e); - e->sbi.request = request; - e->sbi.data = data; + e->h.sbi.request = request; + e->h.sbi.data = data; rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed:%d", (int)rv); ogs_sbi_request_free(request); - pcf_event_free(e); + ogs_event_free(e); return OGS_ERROR; } @@ -58,16 +58,16 @@ static int client_cb(int status, ogs_sbi_response_t *response, void *data) ogs_assert(response); - e = pcf_event_new(PCF_EVT_SBI_CLIENT); + e = pcf_event_new(OGS_EVENT_SBI_CLIENT); ogs_assert(e); - e->sbi.response = response; - e->sbi.data = data; + e->h.sbi.response = response; + e->h.sbi.data = data; rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed:%d", (int)rv); ogs_sbi_response_free(response); - pcf_event_free(e); + ogs_event_free(e); return OGS_ERROR; } @@ -79,6 +79,11 @@ int pcf_sbi_open(void) ogs_sbi_nf_instance_t *nf_instance = NULL; ogs_sbi_nf_service_t *service = NULL; + /* To be notified when NF Instances registered/deregistered in NRF + * or when their profile is modified */ + ogs_sbi_add_to_be_notified_nf_type(OpenAPI_nf_type_BSF); + ogs_sbi_add_to_be_notified_nf_type(OpenAPI_nf_type_UDR); + /* Add SELF NF instance */ nf_instance = ogs_sbi_self()->nf_instance; ogs_assert(nf_instance); @@ -125,28 +130,20 @@ int pcf_sbi_open(void) } /* Initialize NRF NF Instance */ - ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) { - if (NF_INSTANCE_IS_NRF(nf_instance)) { - ogs_sbi_client_t *client = NULL; + nf_instance = ogs_sbi_self()->nrf_instance; + if (nf_instance) { + ogs_sbi_client_t *client = NULL; - /* Client callback is only used when NF sends to NRF */ - client = nf_instance->client; - ogs_assert(client); - client->cb = client_cb; + /* 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. */ + ogs_sbi_nf_fsm_init(nf_instance); } - /* Timer expiration handler of client wait timer */ - ogs_sbi_self()->client_wait_expire = pcf_timer_sbi_client_wait_expire; - - /* NF register state in NF state machine */ - ogs_sbi_self()->nf_state_registered = - (ogs_fsm_handler_t)pcf_nf_state_registered; - if (ogs_sbi_server_start_all(server_cb) != OGS_OK) return OGS_ERROR; diff --git a/src/pcf/sbi-path.h b/src/pcf/sbi-path.h index 2fc612554..774617cfb 100644 --- a/src/pcf/sbi-path.h +++ b/src/pcf/sbi-path.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -20,7 +20,6 @@ #ifndef PCF_SBI_PATH_H #define PCF_SBI_PATH_H -#include "nnrf-build.h" #include "nudr-build.h" #include "nbsf-build.h" #include "namf-build.h" diff --git a/src/pcf/sm-sm.c b/src/pcf/sm-sm.c index 8715dfca1..10618eaf8 100644 --- a/src/pcf/sm-sm.c +++ b/src/pcf/sm-sm.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -54,17 +54,17 @@ void pcf_sm_state_operational(ogs_fsm_t *s, pcf_event_t *e) pcf_ue = sess->pcf_ue; ogs_assert(pcf_ue); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: break; case OGS_FSM_EXIT_SIG: break; - case PCF_EVT_SBI_SERVER: - message = e->sbi.message; + case OGS_EVENT_SBI_SERVER: + message = e->h.sbi.message; ogs_assert(message); - stream = e->sbi.data; + stream = e->h.sbi.data; ogs_assert(stream); SWITCH(message->h.service.name) @@ -158,10 +158,10 @@ void pcf_sm_state_operational(ogs_fsm_t *s, pcf_event_t *e) END break; - case PCF_EVT_SBI_CLIENT: - message = e->sbi.message; + case OGS_EVENT_SBI_CLIENT: + message = e->h.sbi.message; ogs_assert(message); - stream = e->sbi.data; + stream = e->h.sbi.data; ogs_assert(stream); SWITCH(message->h.service.name) @@ -285,7 +285,7 @@ void pcf_sm_state_deleted(ogs_fsm_t *s, pcf_event_t *e) pcf_ue = sess->pcf_ue; ogs_assert(pcf_ue); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: break; @@ -314,7 +314,7 @@ void pcf_sm_state_exception(ogs_fsm_t *s, pcf_event_t *e) pcf_ue = sess->pcf_ue; ogs_assert(pcf_ue); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: break; diff --git a/src/pcf/timer.c b/src/pcf/timer.c deleted file mode 100644 index 3fb493d1e..000000000 --- a/src/pcf/timer.c +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (C) 2019,2020 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "context.h" - -const char *pcf_timer_get_name(pcf_timer_e id) -{ - switch (id) { - case PCF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - return "PCF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL"; - case PCF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - return "PCF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL"; - case PCF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - return "PCF_TIMER_NF_INSTANCE_NO_HEARTBEAT"; - case PCF_TIMER_NF_INSTANCE_VALIDITY: - return "PCF_TIMER_NF_INSTANCE_VALIDITY"; - case PCF_TIMER_SUBSCRIPTION_VALIDITY: - return "PCF_TIMER_SUBSCRIPTION_VALIDITY"; - case PCF_TIMER_SBI_CLIENT_WAIT: - return "PCF_TIMER_SBI_CLIENT_WAIT"; - default: - break; - } - - return "UNKNOWN_TIMER"; -} - -static void sbi_timer_send_event(int timer_id, void *data) -{ - int rv; - pcf_event_t *e = NULL; - ogs_assert(data); - - switch (timer_id) { - case PCF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - case PCF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - case PCF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - case PCF_TIMER_NF_INSTANCE_VALIDITY: - case PCF_TIMER_SUBSCRIPTION_VALIDITY: - e = pcf_event_new(PCF_EVT_SBI_TIMER); - ogs_assert(e); - e->timer_id = timer_id; - e->sbi.data = data; - break; - case PCF_TIMER_SBI_CLIENT_WAIT: - e = pcf_event_new(PCF_EVT_SBI_TIMER); - if (!e) { - ogs_sbi_xact_t *sbi_xact = data; - ogs_assert(sbi_xact); - - ogs_error("sbi_timer_send_event() failed"); - ogs_sbi_xact_remove(sbi_xact); - return; - } - e->timer_id = timer_id; - e->sbi.data = data; - break; - default: - ogs_fatal("Unknown timer id[%d]", timer_id); - ogs_assert_if_reached(); - break; - } - - rv = ogs_queue_push(ogs_app()->queue, e); - if (rv != OGS_OK) { - ogs_error("ogs_queue_push() failed [%d] in %s", - (int)rv, pcf_timer_get_name(e->timer_id)); - pcf_event_free(e); - } -} - -void pcf_timer_nf_instance_registration_interval(void *data) -{ - sbi_timer_send_event(PCF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL, data); -} - -void pcf_timer_nf_instance_heartbeat_interval(void *data) -{ - sbi_timer_send_event(PCF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL, data); -} - -void pcf_timer_nf_instance_no_heartbeat(void *data) -{ - sbi_timer_send_event(PCF_TIMER_NF_INSTANCE_NO_HEARTBEAT, data); -} - -void pcf_timer_nf_instance_validity(void *data) -{ - sbi_timer_send_event(PCF_TIMER_NF_INSTANCE_VALIDITY, data); -} - -void pcf_timer_subscription_validity(void *data) -{ - sbi_timer_send_event(PCF_TIMER_SUBSCRIPTION_VALIDITY, data); -} - -void pcf_timer_sbi_client_wait_expire(void *data) -{ - sbi_timer_send_event(PCF_TIMER_SBI_CLIENT_WAIT, data); -} diff --git a/src/pcf/timer.h b/src/pcf/timer.h deleted file mode 100644 index 122315ada..000000000 --- a/src/pcf/timer.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2019 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef PCF_TIMER_H -#define PCF_TIMER_H - -#include "ogs-core.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* forward declaration */ -typedef enum { - PCF_TIMER_BASE = 0, - - PCF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL, - PCF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL, - PCF_TIMER_NF_INSTANCE_NO_HEARTBEAT, - PCF_TIMER_NF_INSTANCE_VALIDITY, - PCF_TIMER_SUBSCRIPTION_VALIDITY, - PCF_TIMER_SBI_CLIENT_WAIT, - - MAX_NUM_OF_PCF_TIMER, - -} pcf_timer_e; - -const char *pcf_timer_get_name(pcf_timer_e id); - -void pcf_timer_nf_instance_registration_interval(void *data); -void pcf_timer_nf_instance_heartbeat_interval(void *data); -void pcf_timer_nf_instance_no_heartbeat(void *data); -void pcf_timer_nf_instance_validity(void *data); -void pcf_timer_subscription_validity(void *data); -void pcf_timer_sbi_client_wait_expire(void *data); - -#ifdef __cplusplus -} -#endif - -#endif /* PCF_TIMER_H */ diff --git a/src/scp/context.h b/src/scp/context.h index ec1bf611a..3e89b83f1 100644 --- a/src/scp/context.h +++ b/src/scp/context.h @@ -23,7 +23,6 @@ #include "ogs-sbi.h" #include "ogs-app.h" -#include "timer.h" #include "scp-sm.h" #ifdef __cplusplus @@ -39,22 +38,6 @@ typedef struct scp_context_s { ogs_list_t conn_list; } scp_context_t; -#define SCP_NF_INSTANCE_CLEAR(_cAUSE, _nFInstance) \ - do { \ - ogs_assert(_nFInstance); \ - if ((_nFInstance)->reference_count == 1) { \ - ogs_info("[%s] (%s) NF removed", (_nFInstance)->id, (_cAUSE)); \ - scp_nf_fsm_fini((_nFInstance)); \ - ogs_sbi_nf_instance_remove(_nFInstance); \ - } else { \ - /* There is an assocation with other context */ \ - ogs_info("[%s:%d] (%s) NF suspended", \ - _nFInstance->id, _nFInstance->reference_count, (_cAUSE)); \ - OGS_FSM_TRAN(&_nFInstance->sm, scp_nf_state_de_registered); \ - ogs_fsm_dispatch(&_nFInstance->sm, NULL); \ - } \ - } while(0) - typedef struct scp_conn_s scp_conn_t; typedef struct scp_conn_s { diff --git a/src/scp/event.c b/src/scp/event.c index e4736a0d4..6e7b47e04 100644 --- a/src/scp/event.c +++ b/src/scp/event.c @@ -18,60 +18,42 @@ */ #include "event.h" -#include "context.h" -static OGS_POOL(pool, scp_event_t); - -void scp_event_init(void) -{ - ogs_pool_init(&pool, ogs_app()->pool.event); -} - -void scp_event_final(void) -{ - ogs_pool_final(&pool); -} - -scp_event_t *scp_event_new(scp_event_e id) +scp_event_t *scp_event_new(int id) { scp_event_t *e = NULL; - ogs_pool_alloc(&pool, &e); + e = ogs_event_size(id, sizeof(scp_event_t)); ogs_assert(e); - memset(e, 0, sizeof(*e)); - e->id = id; + e->h.id = id; return e; } -void scp_event_free(scp_event_t *e) -{ - ogs_assert(e); - ogs_pool_free(&pool, e); -} - const char *scp_event_get_name(scp_event_t *e) { - if (e == NULL) + if (e == NULL) { return OGS_FSM_NAME_INIT_SIG; - - switch (e->id) { - case OGS_FSM_ENTRY_SIG: - return OGS_FSM_NAME_ENTRY_SIG; - case OGS_FSM_EXIT_SIG: - return OGS_FSM_NAME_EXIT_SIG; - - case SCP_EVT_SBI_SERVER: - return "SCP_EVT_SBI_SERVER"; - case SCP_EVT_SBI_CLIENT: - return "SCP_EVT_SBI_CLIENT"; - case SCP_EVT_SBI_TIMER: - return "SCP_EVT_SBI_TIMER"; - - default: - break; } + switch (e->h.id) { + case OGS_FSM_ENTRY_SIG: + return OGS_FSM_NAME_ENTRY_SIG; + case OGS_FSM_EXIT_SIG: + return OGS_FSM_NAME_EXIT_SIG; + + case OGS_EVENT_SBI_SERVER: + return OGS_EVENT_NAME_SBI_SERVER; + case OGS_EVENT_SBI_CLIENT: + return OGS_EVENT_NAME_SBI_CLIENT; + case OGS_EVENT_SBI_TIMER: + return OGS_EVENT_NAME_SBI_TIMER; + + default: + break; + } + + ogs_error("Unknown Event[%d]", e->h.id); return "UNKNOWN_EVENT"; } diff --git a/src/scp/event.h b/src/scp/event.h index 29983261d..229fdfefa 100644 --- a/src/scp/event.h +++ b/src/scp/event.h @@ -20,52 +20,23 @@ #ifndef SCP_EVENT_H #define SCP_EVENT_H -#include "ogs-core.h" +#include "ogs-proto.h" #ifdef __cplusplus extern "C" { #endif typedef struct scp_sess_s scp_sess_t; -typedef struct ogs_sbi_request_s ogs_sbi_request_t; -typedef struct ogs_sbi_response_s ogs_sbi_response_t; -typedef struct ogs_sbi_message_s ogs_sbi_message_t; typedef struct ogs_sbi_nf_instance_s ogs_sbi_nf_instance_t; -typedef enum { - SCP_EVT_BASE = OGS_FSM_USER_SIG, - - SCP_EVT_SBI_SERVER, - SCP_EVT_SBI_CLIENT, - SCP_EVT_SBI_TIMER, - - SCP_EVT_TOP, - -} scp_event_e; - typedef struct scp_event_s { - int id; - ogs_pkbuf_t *pkbuf; - int timer_id; - - struct { - ogs_sbi_request_t *request; - ogs_sbi_response_t *response; - void *data; - int state; - - ogs_sbi_message_t *message; - } sbi; + ogs_event_t h; ogs_sbi_nf_instance_t *nf_instance; scp_sess_t *sess; } scp_event_t; -void scp_event_init(void); -void scp_event_final(void); - -scp_event_t *scp_event_new(scp_event_e id); -void scp_event_free(scp_event_t *e); +scp_event_t *scp_event_new(int id); const char *scp_event_get_name(scp_event_t *e); diff --git a/src/scp/init.c b/src/scp/init.c index d0250d72c..83f25c52c 100644 --- a/src/scp/init.c +++ b/src/scp/init.c @@ -32,7 +32,6 @@ int scp_initialize() ogs_sbi_context_init(); scp_context_init(); - scp_event_init(); rv = ogs_sbi_context_parse_config("scp", "nrf", "next_scp"); if (rv != OGS_OK) return rv; @@ -63,7 +62,7 @@ static void event_termination(void) /* Sending NF Instance De-registeration to NRF */ ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) - scp_nf_fsm_fini(nf_instance); + ogs_sbi_nf_fsm_fini(nf_instance); /* Starting holding timer */ t_termination_holding = ogs_timer_add(ogs_app()->timer_mgr, NULL, NULL); @@ -88,10 +87,7 @@ void scp_terminate(void) scp_sbi_close(); scp_context_final(); - ogs_sbi_context_final(); - - scp_event_final(); /* Destroy event */ } static void scp_main(void *data) @@ -99,8 +95,7 @@ static void scp_main(void *data) ogs_fsm_t scp_sm; int rv; - ogs_fsm_create(&scp_sm, scp_state_initial, scp_state_final); - ogs_fsm_init(&scp_sm, 0); + ogs_fsm_init(&scp_sm, scp_state_initial, scp_state_final, 0); for ( ;; ) { ogs_pollset_poll(ogs_app()->pollset, @@ -133,11 +128,10 @@ static void scp_main(void *data) ogs_assert(e); ogs_fsm_dispatch(&scp_sm, e); - scp_event_free(e); + ogs_event_free(e); } } done: ogs_fsm_fini(&scp_sm, 0); - ogs_fsm_delete(&scp_sm); } diff --git a/src/scp/meson.build b/src/scp/meson.build index b8249f40b..aa41e197e 100644 --- a/src/scp/meson.build +++ b/src/scp/meson.build @@ -18,12 +18,8 @@ libscp_sources = files(''' context.c event.c - timer.c - nnrf-build.c nnrf-handler.c - nf-sm.c - nscp-handler.c sbi-path.c diff --git a/src/scp/nf-sm.c b/src/scp/nf-sm.c deleted file mode 100644 index 4af54d0e1..000000000 --- a/src/scp/nf-sm.c +++ /dev/null @@ -1,483 +0,0 @@ -/* - * Copyright (C) 2019-2022 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "context.h" - -#include "sbi-path.h" -#include "nnrf-handler.h" - -void scp_nf_fsm_init(ogs_sbi_nf_instance_t *nf_instance) -{ - scp_event_t e; - - ogs_assert(nf_instance); - - memset(&e, 0, sizeof(e)); - e.sbi.data = nf_instance; - - ogs_fsm_create(&nf_instance->sm, - scp_nf_state_initial, scp_nf_state_final); - ogs_fsm_init(&nf_instance->sm, &e); -} - -void scp_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance) -{ - scp_event_t e; - - ogs_assert(nf_instance); - - memset(&e, 0, sizeof(e)); - e.sbi.data = nf_instance; - - ogs_fsm_fini(&nf_instance->sm, &e); - ogs_fsm_delete(&nf_instance->sm); -} - -void scp_nf_state_initial(ogs_fsm_t *s, scp_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - - ogs_assert(s); - ogs_assert(e); - - scp_sm_debug(e); - - nf_instance = e->sbi.data; - ogs_assert(nf_instance); - - nf_instance->t_registration_interval = ogs_timer_add(ogs_app()->timer_mgr, - scp_timer_nf_instance_registration_interval, nf_instance); - ogs_assert(nf_instance->t_registration_interval); - nf_instance->t_heartbeat_interval = ogs_timer_add(ogs_app()->timer_mgr, - scp_timer_nf_instance_heartbeat_interval, nf_instance); - ogs_assert(nf_instance->t_heartbeat_interval); - nf_instance->t_no_heartbeat = ogs_timer_add(ogs_app()->timer_mgr, - scp_timer_nf_instance_no_heartbeat, nf_instance); - ogs_assert(nf_instance->t_no_heartbeat); - nf_instance->t_validity = ogs_timer_add(ogs_app()->timer_mgr, - scp_timer_nf_instance_validity, nf_instance); - ogs_assert(nf_instance->t_validity); - - if (NF_INSTANCE_IS_NRF(nf_instance)) { - OGS_FSM_TRAN(s, &scp_nf_state_will_register); - } else { - ogs_assert(nf_instance->id); - OGS_FSM_TRAN(s, &scp_nf_state_registered); - } -} - -void scp_nf_state_final(ogs_fsm_t *s, scp_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - - ogs_assert(s); - ogs_assert(e); - - scp_sm_debug(e); - - nf_instance = e->sbi.data; - ogs_assert(nf_instance); - - ogs_timer_delete(nf_instance->t_registration_interval); - ogs_timer_delete(nf_instance->t_heartbeat_interval); - ogs_timer_delete(nf_instance->t_no_heartbeat); - ogs_timer_delete(nf_instance->t_validity); -} - -void scp_nf_state_will_register(ogs_fsm_t *s, scp_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_sbi_client_t *client = NULL; - ogs_sbi_message_t *message = NULL; - ogs_sockaddr_t *addr = NULL; - - ogs_assert(s); - ogs_assert(e); - - scp_sm_debug(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: - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); - - ogs_assert(true == ogs_nnrf_nfm_send_nf_register( - nf_instance, scp_nnrf_nfm_build_register)); - break; - - case OGS_FSM_EXIT_SIG: - ogs_timer_stop(nf_instance->t_registration_interval); - break; - - case SCP_EVT_SBI_CLIENT: - message = e->sbi.message; - ogs_assert(message); - - SWITCH(message->h.service.name) - CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) - - SWITCH(message->h.resource.component[0]) - CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - - if (message->res_status == OGS_SBI_HTTP_STATUS_OK || - message->res_status == OGS_SBI_HTTP_STATUS_CREATED) { - scp_nnrf_handle_nf_register(nf_instance, message); - OGS_FSM_TRAN(s, &scp_nf_state_registered); - } else { - ogs_error("[%s] HTTP Response Status Code [%d]", - ogs_sbi_self()->nf_instance->id, - message->res_status); - OGS_FSM_TRAN(s, &scp_nf_state_exception); - } - break; - - DEFAULT - ogs_error("[%s] Invalid resource name [%s]", - ogs_sbi_self()->nf_instance->id, - message->h.resource.component[0]); - END - break; - - DEFAULT - ogs_error("[%s] Invalid API name [%s]", - ogs_sbi_self()->nf_instance->id, message->h.service.name); - END - break; - - case SCP_EVT_SBI_TIMER: - switch(e->timer_id) { - case SCP_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - client = nf_instance->client; - ogs_assert(client); - addr = client->node.addr; - ogs_assert(addr); - - ogs_warn("[%s] Retry to registration with NRF", - ogs_sbi_self()->nf_instance->id); - - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); - - ogs_assert(true == ogs_nnrf_nfm_send_nf_register( - nf_instance, scp_nnrf_nfm_build_register)); - break; - - default: - ogs_error("[%s] Unknown timer[%s:%d]", - ogs_sbi_self()->nf_instance->id, - scp_timer_get_name(e->timer_id), e->timer_id); - } - break; - - default: - ogs_error("[%s] Unknown event %s", - ogs_sbi_self()->nf_instance->id, scp_event_get_name(e)); - break; - } -} - -void scp_nf_state_registered(ogs_fsm_t *s, scp_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_sbi_client_t *client = NULL; - ogs_sbi_message_t *message = NULL; - ogs_assert(s); - ogs_assert(e); - - scp_sm_debug(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_NRF(nf_instance)) { - ogs_info("[%s] NF registered [Heartbeat:%ds]", - ogs_sbi_self()->nf_instance->id, - nf_instance->time.heartbeat_interval); - - client = nf_instance->client; - ogs_assert(client); - - if (nf_instance->time.heartbeat_interval) { - ogs_timer_start(nf_instance->t_heartbeat_interval, - ogs_time_from_sec(nf_instance->time.heartbeat_interval)); - ogs_timer_start(nf_instance->t_no_heartbeat, - ogs_time_from_sec( - nf_instance->time.heartbeat_interval + - ogs_app()->time.nf_instance.no_heartbeat_margin)); - } - - ogs_assert(true == - ogs_nnrf_nfm_send_nf_status_subscribe(client, - 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, - 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, - 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, - ogs_sbi_self()->nf_instance->nf_type, - ogs_sbi_self()->nf_instance->id, - OpenAPI_nf_type_NSSF)); - ogs_assert(true == - ogs_nnrf_nfm_send_nf_status_subscribe(client, - 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, - 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, - 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, - 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_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); - ogs_timer_stop(nf_instance->t_no_heartbeat); - } - - if (!OGS_FSM_CHECK(&nf_instance->sm, scp_nf_state_exception)) { - ogs_assert(true == - ogs_nnrf_nfm_send_nf_de_register(nf_instance)); - } - } - break; - - case SCP_EVT_SBI_CLIENT: - message = e->sbi.message; - ogs_assert(message); - - SWITCH(message->h.service.name) - CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) - - SWITCH(message->h.resource.component[0]) - CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - - if (message->res_status == OGS_SBI_HTTP_STATUS_NO_CONTENT || - message->res_status == OGS_SBI_HTTP_STATUS_OK) { - if (nf_instance->time.heartbeat_interval) - ogs_timer_start(nf_instance->t_no_heartbeat, - ogs_time_from_sec( - nf_instance->time.heartbeat_interval + - ogs_app()->time.nf_instance. - no_heartbeat_margin)); - } else { - ogs_warn("[%s] HTTP response error [%d]", - ogs_sbi_self()->nf_instance->id, - message->res_status); - OGS_FSM_TRAN(s, &scp_nf_state_exception); - } - - break; - - DEFAULT - ogs_error("[%s] Invalid resource name [%s]", - ogs_sbi_self()->nf_instance->id, - message->h.resource.component[0]); - END - break; - - DEFAULT - ogs_error("[%s] Invalid API name [%s]", - ogs_sbi_self()->nf_instance->id, message->h.service.name); - END - break; - - case SCP_EVT_SBI_TIMER: - switch(e->timer_id) { - case SCP_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - if (nf_instance->time.heartbeat_interval) - ogs_timer_start(nf_instance->t_heartbeat_interval, - ogs_time_from_sec(nf_instance->time.heartbeat_interval)); - - ogs_assert(true == ogs_nnrf_nfm_send_nf_update(nf_instance)); - break; - - case SCP_TIMER_NF_INSTANCE_NO_HEARTBEAT: - ogs_error("[%s] No heartbeat", ogs_sbi_self()->nf_instance->id); - OGS_FSM_TRAN(s, &scp_nf_state_will_register); - break; - - case SCP_TIMER_NF_INSTANCE_VALIDITY: - 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, &scp_nf_state_de_registered); - break; - - default: - ogs_error("[%s:%s] Unknown timer[%s:%d]", - OpenAPI_nf_type_ToString(nf_instance->nf_type), - nf_instance->id ? nf_instance->id : "Undefined", - scp_timer_get_name(e->timer_id), e->timer_id); - } - break; - - default: - ogs_error("[%s:%s] Unknown event %s", - OpenAPI_nf_type_ToString(nf_instance->nf_type), - nf_instance->id ? nf_instance->id : "Undefined", - scp_event_get_name(e)); - break; - } -} - -void scp_nf_state_de_registered(ogs_fsm_t *s, scp_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_assert(s); - ogs_assert(e); - - scp_sm_debug(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_NRF(nf_instance)) { - ogs_info("[%s] NF de-registered", ogs_sbi_self()->nf_instance->id); - } - break; - - case OGS_FSM_EXIT_SIG: - break; - - default: - ogs_error("[%s:%s] Unknown event %s", - OpenAPI_nf_type_ToString(nf_instance->nf_type), - nf_instance->id ? nf_instance->id : "Undefined", - scp_event_get_name(e)); - break; - } -} - -void scp_nf_state_exception(ogs_fsm_t *s, scp_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_sbi_client_t *client = NULL; - ogs_sbi_message_t *message = NULL; - ogs_sockaddr_t *addr = NULL; - ogs_assert(s); - ogs_assert(e); - - scp_sm_debug(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_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_NRF(nf_instance)) { - ogs_timer_stop(nf_instance->t_registration_interval); - } - break; - - case SCP_EVT_SBI_TIMER: - switch(e->timer_id) { - case SCP_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - client = nf_instance->client; - ogs_assert(client); - addr = client->node.addr; - ogs_assert(addr); - - ogs_warn("[%s] Retry to registration with NRF", - ogs_sbi_self()->nf_instance->id); - - OGS_FSM_TRAN(s, &scp_nf_state_will_register); - break; - - default: - ogs_error("[%s:%s] Unknown timer[%s:%d]", - OpenAPI_nf_type_ToString(nf_instance->nf_type), - nf_instance->id ? nf_instance->id : "Undefined", - scp_timer_get_name(e->timer_id), e->timer_id); - } - break; - - case SCP_EVT_SBI_CLIENT: - message = e->sbi.message; - ogs_assert(message); - - SWITCH(message->h.service.name) - CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) - - SWITCH(message->h.resource.component[0]) - CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - break; - DEFAULT - ogs_error("Invalid resource name [%s]", - message->h.resource.component[0]); - END - break; - DEFAULT - ogs_error("Invalid API name [%s]", message->h.service.name); - END - break; - - default: - ogs_error("[%s:%s] Unknown event %s", - OpenAPI_nf_type_ToString(nf_instance->nf_type), - nf_instance->id ? nf_instance->id : "Undefined", - scp_event_get_name(e)); - break; - } -} diff --git a/src/scp/nnrf-build.c b/src/scp/nnrf-build.c deleted file mode 100644 index 7c7b42c13..000000000 --- a/src/scp/nnrf-build.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2019-2022 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "nnrf-build.h" - -ogs_sbi_request_t *scp_nnrf_nfm_build_register(void) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - - ogs_sbi_message_t message; - ogs_sbi_request_t *request = NULL; - - OpenAPI_nf_profile_t *NFProfile = 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_PUT; - message.h.service.name = (char *)OGS_SBI_SERVICE_NAME_NNRF_NFM; - 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] = nf_instance->id; - - message.http.content_encoding = (char*)ogs_sbi_self()->content_encoding; - - NFProfile = ogs_nnrf_nfm_build_nf_profile(); - ogs_expect_or_return_val(NFProfile, NULL); - - message.NFProfile = NFProfile; - - request = ogs_sbi_build_request(&message); - - ogs_sbi_nnrf_free_nf_profile(NFProfile); - - return request; -} diff --git a/src/scp/nnrf-handler.c b/src/scp/nnrf-handler.c index f4767899d..832b5bfc8 100644 --- a/src/scp/nnrf-handler.c +++ b/src/scp/nnrf-handler.c @@ -20,233 +20,6 @@ #include "sbi-path.h" #include "nnrf-handler.h" -void scp_nnrf_handle_nf_register( - ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_message_t *recvmsg) -{ - OpenAPI_nf_profile_t *NFProfile = NULL; - ogs_sbi_client_t *client = NULL; - - ogs_assert(recvmsg); - ogs_assert(nf_instance); - client = nf_instance->client; - ogs_assert(client); - - NFProfile = recvmsg->NFProfile; - if (!NFProfile) { - ogs_error("No NFProfile"); - return; - } - - /* TIME : Update heartbeat from NRF */ - if (NFProfile->is_heart_beat_timer == true) - nf_instance->time.heartbeat_interval = NFProfile->heart_beat_timer; -} - -void scp_nnrf_handle_nf_status_subscribe( - ogs_sbi_subscription_t *subscription, ogs_sbi_message_t *recvmsg) -{ - OpenAPI_subscription_data_t *SubscriptionData = NULL; - ogs_sbi_client_t *client = NULL; - - ogs_assert(recvmsg); - ogs_assert(subscription); - client = subscription->client; - ogs_assert(client); - - SubscriptionData = recvmsg->SubscriptionData; - if (!SubscriptionData) { - ogs_error("No SubscriptionData"); - return; - } - - if (!SubscriptionData->subscription_id) { - ogs_error("No SubscriptionId"); - return; - } - ogs_sbi_subscription_set_id( - subscription, SubscriptionData->subscription_id); - - if (SubscriptionData->validity_time) { -#define VALIDITY_MINIMUM (10LL * OGS_USEC_PER_SEC) /* 10 seconds */ - ogs_time_t time, duration; - if (ogs_sbi_time_from_string( - &time, SubscriptionData->validity_time) == true) { - duration = time - ogs_time_now(); - if (duration < VALIDITY_MINIMUM) { - duration = VALIDITY_MINIMUM; - ogs_warn("[%s] Forced to %lld seconds", subscription->id, - (long long)ogs_time_sec(VALIDITY_MINIMUM)); - } - subscription->t_validity = ogs_timer_add(ogs_app()->timer_mgr, - scp_timer_subscription_validity, subscription); - ogs_assert(subscription->t_validity); - ogs_timer_start(subscription->t_validity, duration); - } else { - ogs_error("Cannot parse validitiyTime [%s]", - SubscriptionData->validity_time); - } - } -} - -bool scp_nnrf_handle_nf_status_notify( - ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) -{ - int rv; - bool handled; - - ogs_sbi_response_t *response = NULL; - OpenAPI_notification_data_t *NotificationData = NULL; - ogs_sbi_nf_instance_t *nf_instance = NULL; - - ogs_sbi_message_t message; - ogs_sbi_header_t header; - - ogs_assert(stream); - ogs_assert(recvmsg); - - NotificationData = recvmsg->NotificationData; - if (!NotificationData) { - ogs_error("No NotificationData"); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "No NotificationData", NULL)); - return false; - } - - if (!NotificationData->nf_instance_uri) { - ogs_error("No nfInstanceUri"); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "No nfInstanceUri", NULL)); - return false; - } - - memset(&header, 0, sizeof(header)); - header.uri = NotificationData->nf_instance_uri; - - rv = ogs_sbi_parse_header(&message, &header); - if (rv != OGS_OK) { - ogs_error("Cannot parse nfInstanceUri [%s]", header.uri); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Cannot parse nfInstanceUri", header.uri)); - return false; - } - - if (!message.h.resource.component[1]) { - ogs_error("No nfInstanceId [%s]", header.uri); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Cannot parse nfInstanceUri", header.uri)); - ogs_sbi_header_free(&header); - return false; - } - - if (NF_INSTANCE_IS_SELF(message.h.resource.component[1])) { - ogs_warn("[%s] The notification is not allowed", - message.h.resource.component[1]); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, - recvmsg, "The notification is not allowed", - message.h.resource.component[1])); - ogs_sbi_header_free(&header); - return false; - } - - if (NotificationData->event == - OpenAPI_notification_event_type_NF_REGISTERED) { - - OpenAPI_nf_profile_t *NFProfile = NULL; - - NFProfile = NotificationData->nf_profile; - if (!NFProfile) { - ogs_error("No NFProfile"); - ogs_assert(true == - ogs_sbi_server_send_error( - stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "No NFProfile", NULL)); - ogs_sbi_header_free(&header); - return false; - } - - nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); - if (!nf_instance) { - nf_instance = ogs_sbi_nf_instance_add(); - ogs_assert(nf_instance); - ogs_sbi_nf_instance_set_id(nf_instance, - message.h.resource.component[1]); - - scp_nf_fsm_init(nf_instance); - - ogs_info("[%s] (NRF-notify) NF registered", nf_instance->id); - - } else { - OGS_FSM_TRAN(&nf_instance->sm, scp_nf_state_registered); - ogs_fsm_dispatch(&nf_instance->sm, NULL); - - ogs_warn("[%s] (NRF-notify) NF has already been added", - message.h.resource.component[1]); - - } - - handled = ogs_sbi_nnrf_handle_nf_profile( - nf_instance, NFProfile, stream, recvmsg); - if (!handled) { - SCP_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); - ogs_sbi_header_free(&header); - return false; - } - - ogs_info("[%s] (NRF-notify) NF Profile updated", nf_instance->id); - - handled = ogs_sbi_client_associate(nf_instance); - if (!handled) { - ogs_error("[%s] Cannot associate NF EndPoint", nf_instance->id); - ogs_assert(true == - ogs_sbi_server_send_error(stream, - OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Cannot find NF EndPoint", nf_instance->id)); - SCP_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); - ogs_sbi_header_free(&header); - return false; - } - - } else if (NotificationData->event == - OpenAPI_notification_event_type_NF_DEREGISTERED) { - nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); - if (nf_instance) { - SCP_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); - } else { - ogs_warn("[%s] (NRF-notify) Not found", - message.h.resource.component[1]); - ogs_assert(true == - ogs_sbi_server_send_error(stream, - OGS_SBI_HTTP_STATUS_NOT_FOUND, - recvmsg, "Not found", message.h.resource.component[1])); - ogs_sbi_header_free(&header); - return false; - } - } else { - char *eventstr = OpenAPI_notification_event_type_ToString( - NotificationData->event); - ogs_error("Not supported event [%d:%s]", - NotificationData->event, eventstr ? eventstr : "Unknown"); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Not supported event", - eventstr ? eventstr : "Unknown")); - ogs_sbi_header_free(&header); - return false; - } - - response = ogs_sbi_build_response(recvmsg, OGS_SBI_HTTP_STATUS_NO_CONTENT); - ogs_assert(response); - ogs_assert(true == ogs_sbi_server_send_response(stream, response)); - - ogs_sbi_header_free(&header); - return true; -} - void scp_nnrf_handle_nf_discover( ogs_sbi_xact_t *xact, ogs_sbi_message_t *recvmsg) { @@ -256,8 +29,6 @@ void scp_nnrf_handle_nf_discover( ogs_sbi_nf_instance_t *nf_instance = NULL; OpenAPI_search_result_t *SearchResult = NULL; - OpenAPI_lnode_t *node = NULL; - bool handled; ogs_assert(recvmsg); ogs_assert(xact); @@ -274,64 +45,8 @@ void scp_nnrf_handle_nf_discover( return; } - OpenAPI_list_for_each(SearchResult->nf_instances, node) { - OpenAPI_nf_profile_t *NFProfile = NULL; - - if (!node->data) continue; - - NFProfile = node->data; - - nf_instance = ogs_sbi_nf_instance_find(NFProfile->nf_instance_id); - if (!nf_instance) { - nf_instance = ogs_sbi_nf_instance_add(); - ogs_assert(nf_instance); - ogs_sbi_nf_instance_set_id(nf_instance, NFProfile->nf_instance_id); - - scp_nf_fsm_init(nf_instance); - - ogs_info("[%s] (NF-discover) NF registered", nf_instance->id); - } else { - OGS_FSM_TRAN(&nf_instance->sm, scp_nf_state_registered); - ogs_fsm_dispatch(&nf_instance->sm, NULL); - - ogs_warn("[%s] (NF-discover) NF has already been added", - NFProfile->nf_instance_id); - } - - if (NF_INSTANCE_IS_OTHERS(nf_instance->id)) { - handled = ogs_sbi_nnrf_handle_nf_profile( - nf_instance, NFProfile, NULL, NULL); - if (!handled) { - ogs_error("ogs_sbi_nnrf_handle_nf_profile() failed [%s]", - nf_instance->id); - SCP_NF_INSTANCE_CLEAR("NRF-discover", nf_instance); - continue; - } - - handled = ogs_sbi_client_associate(nf_instance); - if (!handled) { - ogs_error("[%s] Cannot assciate NF EndPoint", nf_instance->id); - SCP_NF_INSTANCE_CLEAR("NRF-discover", nf_instance); - continue; - } - - /* TIME : Update validity from NRF */ - if (SearchResult->is_validity_period && - SearchResult->validity_period) { - nf_instance->time.validity_duration = - SearchResult->validity_period; - - ogs_assert(nf_instance->t_validity); - ogs_timer_start(nf_instance->t_validity, - ogs_time_from_sec(nf_instance->time.validity_duration)); - - } else - ogs_warn("[%s] NF Instance validity-time should not 0", - nf_instance->id); - - ogs_info("[%s] (NF-discover) NF Profile updated", nf_instance->id); - } - } + ogs_nnrf_handle_nf_discover_search_result( + sbi_object, target_nf_type, discovery_option, SearchResult); ogs_sbi_select_nf(sbi_object, target_nf_type, discovery_option); diff --git a/src/scp/nnrf-handler.h b/src/scp/nnrf-handler.h index 736851433..6fac7be9d 100644 --- a/src/scp/nnrf-handler.h +++ b/src/scp/nnrf-handler.h @@ -26,14 +26,6 @@ extern "C" { #endif -void scp_nnrf_handle_nf_register( - ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_message_t *recvmsg); -void scp_nnrf_handle_nf_status_subscribe( - ogs_sbi_subscription_t *subscription, ogs_sbi_message_t *recvmsg); - -bool scp_nnrf_handle_nf_status_notify( - ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); - void scp_nnrf_handle_nf_discover( ogs_sbi_xact_t *xact, ogs_sbi_message_t *recvmsg); diff --git a/src/scp/sbi-path.c b/src/scp/sbi-path.c index ce15f7679..62538d3a3 100644 --- a/src/scp/sbi-path.c +++ b/src/scp/sbi-path.c @@ -29,6 +29,17 @@ int scp_sbi_open(void) { ogs_sbi_nf_instance_t *nf_instance = NULL; + /* To be notified when NF Instances registered/deregistered in NRF + * or when their profile is modified */ + ogs_sbi_add_to_be_notified_nf_type(OpenAPI_nf_type_AMF); + ogs_sbi_add_to_be_notified_nf_type(OpenAPI_nf_type_AUSF); + ogs_sbi_add_to_be_notified_nf_type(OpenAPI_nf_type_BSF); + ogs_sbi_add_to_be_notified_nf_type(OpenAPI_nf_type_NSSF); + ogs_sbi_add_to_be_notified_nf_type(OpenAPI_nf_type_PCF); + ogs_sbi_add_to_be_notified_nf_type(OpenAPI_nf_type_SMF); + ogs_sbi_add_to_be_notified_nf_type(OpenAPI_nf_type_UDM); + ogs_sbi_add_to_be_notified_nf_type(OpenAPI_nf_type_UDR); + /* Add SELF NF instance */ nf_instance = ogs_sbi_self()->nf_instance; ogs_assert(nf_instance); @@ -59,16 +70,9 @@ int scp_sbi_open(void) /* NFRegister is sent and the response is received * by the above client callback. */ - scp_nf_fsm_init(nf_instance); + ogs_sbi_nf_fsm_init(nf_instance); } - /* Timer expiration handler of client wait timer */ - ogs_sbi_self()->client_wait_expire = scp_timer_sbi_client_wait_expire; - - /* NF register state in NF state machine */ - ogs_sbi_self()->nf_state_registered = - (ogs_fsm_handler_t)scp_nf_state_registered; - if (ogs_sbi_server_start_all(request_handler) != OGS_OK) return OGS_ERROR; @@ -259,17 +263,17 @@ static int request_handler(ogs_sbi_request_t *source, void *data) } else if (headers.discovery) { scp_event_t *e = NULL; - e = scp_event_new(SCP_EVT_SBI_SERVER); + e = scp_event_new(OGS_EVENT_SBI_SERVER); ogs_assert(e); - e->sbi.request = source; - e->sbi.data = stream; + e->h.sbi.request = source; + e->h.sbi.data = stream; rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed:%d", (int)rv); ogs_sbi_request_free(source); - scp_event_free(e); + ogs_event_free(e); return OGS_ERROR; } } else { @@ -279,17 +283,17 @@ static int request_handler(ogs_sbi_request_t *source, void *data) ogs_assert(source); ogs_assert(data); - e = scp_event_new(SCP_EVT_SBI_SERVER); + e = scp_event_new(OGS_EVENT_SBI_SERVER); ogs_assert(e); - e->sbi.request = source; - e->sbi.data = data; + e->h.sbi.request = source; + e->h.sbi.data = data; rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed:%d", (int)rv); ogs_sbi_request_free(source); - scp_event_free(e); + ogs_event_free(e); return OGS_ERROR; } } @@ -344,16 +348,16 @@ static int client_cb(int status, ogs_sbi_response_t *response, void *data) ogs_assert(response); - e = scp_event_new(SCP_EVT_SBI_CLIENT); + e = scp_event_new(OGS_EVENT_SBI_CLIENT); ogs_assert(e); - e->sbi.response = response; - e->sbi.data = data; + e->h.sbi.response = response; + e->h.sbi.data = data; rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed:%d", (int)rv); ogs_sbi_response_free(response); - scp_event_free(e); + ogs_event_free(e); return OGS_ERROR; } diff --git a/src/scp/sbi-path.h b/src/scp/sbi-path.h index 2dba2758e..da891b0ba 100644 --- a/src/scp/sbi-path.h +++ b/src/scp/sbi-path.h @@ -20,7 +20,7 @@ #ifndef SCP_SBI_PATH_H #define SCP_SBI_PATH_H -#include "nnrf-build.h" +#include "context.h" #ifdef __cplusplus extern "C" { diff --git a/src/scp/scp-sm.c b/src/scp/scp-sm.c index c5580ece3..16ce5627f 100644 --- a/src/scp/scp-sm.c +++ b/src/scp/scp-sm.c @@ -54,17 +54,17 @@ void scp_state_operational(ogs_fsm_t *s, scp_event_t *e) ogs_assert(s); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: break; case OGS_FSM_EXIT_SIG: break; - case SCP_EVT_SBI_SERVER: - request = e->sbi.request; + case OGS_EVENT_SBI_SERVER: + request = e->h.sbi.request; ogs_assert(request); - stream = e->sbi.data; + stream = e->h.sbi.data; ogs_assert(stream); rv = ogs_sbi_parse_request(&message, request); @@ -95,7 +95,7 @@ void scp_state_operational(ogs_fsm_t *s, scp_event_t *e) CASE(OGS_SBI_RESOURCE_NAME_NF_STATUS_NOTIFY) SWITCH(message.h.method) CASE(OGS_SBI_HTTP_METHOD_POST) - scp_nnrf_handle_nf_status_notify(stream, &message); + ogs_nnrf_handle_nf_status_notify(stream, &message); break; DEFAULT @@ -195,10 +195,10 @@ void scp_state_operational(ogs_fsm_t *s, scp_event_t *e) ogs_sbi_message_free(&message); break; - case SCP_EVT_SBI_CLIENT: + case OGS_EVENT_SBI_CLIENT: ogs_assert(e); - response = e->sbi.response; + response = e->h.sbi.response; ogs_assert(response); rv = ogs_sbi_parse_response(&message, response); if (rv != OGS_OK) { @@ -220,23 +220,23 @@ void scp_state_operational(ogs_fsm_t *s, scp_event_t *e) SWITCH(message.h.resource.component[0]) CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - nf_instance = e->sbi.data; + nf_instance = e->h.sbi.data; ogs_assert(nf_instance); ogs_assert(OGS_FSM_STATE(&nf_instance->sm)); - e->sbi.message = &message; + e->h.sbi.message = &message; ogs_fsm_dispatch(&nf_instance->sm, e); break; CASE(OGS_SBI_RESOURCE_NAME_SUBSCRIPTIONS) - subscription = e->sbi.data; + subscription = e->h.sbi.data; ogs_assert(subscription); SWITCH(message.h.method) CASE(OGS_SBI_HTTP_METHOD_POST) if (message.res_status == OGS_SBI_HTTP_STATUS_CREATED || message.res_status == OGS_SBI_HTTP_STATUS_OK) { - scp_nnrf_handle_nf_status_subscribe( + ogs_nnrf_handle_nf_status_subscribe( subscription, &message); } else { ogs_error("HTTP response error : %d", @@ -269,7 +269,7 @@ void scp_state_operational(ogs_fsm_t *s, scp_event_t *e) CASE(OGS_SBI_SERVICE_NAME_NNRF_DISC) SWITCH(message.h.resource.component[0]) CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - sbi_xact = e->sbi.data; + sbi_xact = e->h.sbi.data; ogs_assert(sbi_xact); SWITCH(message.h.method) @@ -303,27 +303,27 @@ void scp_state_operational(ogs_fsm_t *s, scp_event_t *e) ogs_sbi_response_free(response); break; - case SCP_EVT_SBI_TIMER: + case OGS_EVENT_SBI_TIMER: ogs_assert(e); - switch(e->timer_id) { - case SCP_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - case SCP_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - case SCP_TIMER_NF_INSTANCE_NO_HEARTBEAT: - case SCP_TIMER_NF_INSTANCE_VALIDITY: - nf_instance = e->sbi.data; + switch(e->h.timer_id) { + case OGS_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: + case OGS_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: + case OGS_TIMER_NF_INSTANCE_NO_HEARTBEAT: + case OGS_TIMER_NF_INSTANCE_VALIDITY: + nf_instance = e->h.sbi.data; ogs_assert(nf_instance); ogs_assert(OGS_FSM_STATE(&nf_instance->sm)); ogs_fsm_dispatch(&nf_instance->sm, e); - if (OGS_FSM_CHECK(&nf_instance->sm, scp_nf_state_exception)) + if (OGS_FSM_CHECK(&nf_instance->sm, ogs_sbi_nf_state_exception)) ogs_error("[%s:%s] State machine exception [%d]", OpenAPI_nf_type_ToString(nf_instance->nf_type), - nf_instance->id, e->timer_id); + nf_instance->id, e->h.timer_id); break; - case SCP_TIMER_SUBSCRIPTION_VALIDITY: - subscription = e->sbi.data; + case OGS_TIMER_SUBSCRIPTION_VALIDITY: + subscription = e->h.sbi.data; ogs_assert(subscription); ogs_assert(ogs_sbi_self()->nf_instance); @@ -337,8 +337,8 @@ void scp_state_operational(ogs_fsm_t *s, scp_event_t *e) ogs_sbi_subscription_remove(subscription); break; - case SCP_TIMER_SBI_CLIENT_WAIT: - sbi_xact = e->sbi.data; + case OGS_TIMER_SBI_CLIENT_WAIT: + sbi_xact = e->h.sbi.data; ogs_assert(sbi_xact); stream = sbi_xact->assoc_stream; @@ -358,7 +358,7 @@ void scp_state_operational(ogs_fsm_t *s, scp_event_t *e) default: ogs_error("Unknown timer[%s:%d]", - scp_timer_get_name(e->timer_id), e->timer_id); + ogs_timer_get_name(e->h.timer_id), e->h.timer_id); } break; diff --git a/src/scp/scp-sm.h b/src/scp/scp-sm.h index 41b84a49d..2e603b9c7 100644 --- a/src/scp/scp-sm.h +++ b/src/scp/scp-sm.h @@ -31,16 +31,6 @@ void scp_state_final(ogs_fsm_t *s, scp_event_t *e); void scp_state_operational(ogs_fsm_t *s, scp_event_t *e); void scp_state_exception(ogs_fsm_t *s, scp_event_t *e); -void scp_nf_fsm_init(ogs_sbi_nf_instance_t *nf_instance); -void scp_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance); - -void scp_nf_state_initial(ogs_fsm_t *s, scp_event_t *e); -void scp_nf_state_final(ogs_fsm_t *s, scp_event_t *e); -void scp_nf_state_will_register(ogs_fsm_t *s, scp_event_t *e); -void scp_nf_state_registered(ogs_fsm_t *s, scp_event_t *e); -void scp_nf_state_de_registered(ogs_fsm_t *s, scp_event_t *e); -void scp_nf_state_exception(ogs_fsm_t *s, scp_event_t *e); - #define scp_sm_debug(__pe) \ ogs_debug("%s(): %s", __func__, scp_event_get_name(__pe)) diff --git a/src/scp/timer.c b/src/scp/timer.c deleted file mode 100644 index 86d0fd0c6..000000000 --- a/src/scp/timer.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (C) 2019-2022 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "timer.h" -#include "event.h" -#include "context.h" - -const char *scp_timer_get_name(scp_timer_e id) -{ - switch (id) { - case SCP_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - return "SCP_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL"; - case SCP_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - return "SCP_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL"; - case SCP_TIMER_NF_INSTANCE_NO_HEARTBEAT: - return "SCP_TIMER_NF_INSTANCE_NO_HEARTBEAT"; - case SCP_TIMER_NF_INSTANCE_VALIDITY: - return "SCP_TIMER_NF_INSTANCE_VALIDITY"; - case SCP_TIMER_SUBSCRIPTION_VALIDITY: - return "SCP_TIMER_SUBSCRIPTION_VALIDITY"; - case SCP_TIMER_SBI_CLIENT_WAIT: - return "SCP_TIMER_SBI_CLIENT_WAIT"; - default: - break; - } - - return "UNKNOWN_TIMER"; -} - -static void timer_send_event(int timer_id, void *data) -{ - int rv; - scp_event_t *e = NULL; - ogs_assert(data); - - switch (timer_id) { - case SCP_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - case SCP_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - case SCP_TIMER_NF_INSTANCE_NO_HEARTBEAT: - case SCP_TIMER_NF_INSTANCE_VALIDITY: - case SCP_TIMER_SUBSCRIPTION_VALIDITY: - e = scp_event_new(SCP_EVT_SBI_TIMER); - ogs_assert(e); - e->timer_id = timer_id; - e->sbi.data = data; - break; - case SCP_TIMER_SBI_CLIENT_WAIT: - e = scp_event_new(SCP_EVT_SBI_TIMER); - if (!e) { - ogs_sbi_xact_t *sbi_xact = data; - ogs_assert(sbi_xact); - - ogs_error("timer_send_event() failed"); - ogs_sbi_xact_remove(sbi_xact); - return; - } - e->timer_id = timer_id; - e->sbi.data = data; - break; - default: - ogs_fatal("Unknown timer id[%d]", timer_id); - ogs_assert_if_reached(); - break; - } - - rv = ogs_queue_push(ogs_app()->queue, e); - if (rv != OGS_OK) { - ogs_warn("ogs_queue_push() failed [%d] in %s", - (int)rv, scp_timer_get_name(e->timer_id)); - scp_event_free(e); - } -} - -void scp_timer_nf_instance_registration_interval(void *data) -{ - timer_send_event(SCP_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL, data); -} - -void scp_timer_nf_instance_heartbeat_interval(void *data) -{ - timer_send_event(SCP_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL, data); -} - -void scp_timer_nf_instance_no_heartbeat(void *data) -{ - timer_send_event(SCP_TIMER_NF_INSTANCE_NO_HEARTBEAT, data); -} - -void scp_timer_nf_instance_validity(void *data) -{ - timer_send_event(SCP_TIMER_NF_INSTANCE_VALIDITY, data); -} - -void scp_timer_subscription_validity(void *data) -{ - timer_send_event(SCP_TIMER_SUBSCRIPTION_VALIDITY, data); -} - -void scp_timer_sbi_client_wait_expire(void *data) -{ - timer_send_event(SCP_TIMER_SBI_CLIENT_WAIT, data); -} diff --git a/src/scp/timer.h b/src/scp/timer.h deleted file mode 100644 index 4dcd8c59e..000000000 --- a/src/scp/timer.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2019-2022 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef SCP_TIMER_H -#define SCP_TIMER_H - -#include "ogs-core.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* forward declaration */ -typedef enum { - SCP_TIMER_BASE = 0, - - SCP_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL, - SCP_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL, - SCP_TIMER_NF_INSTANCE_NO_HEARTBEAT, - SCP_TIMER_NF_INSTANCE_VALIDITY, - SCP_TIMER_SUBSCRIPTION_VALIDITY, - SCP_TIMER_SBI_CLIENT_WAIT, - - MAX_NUM_OF_SCP_TIMER, - -} scp_timer_e; - -const char *scp_timer_get_name(scp_timer_e id); - -void scp_timer_nf_instance_registration_interval(void *data); -void scp_timer_nf_instance_heartbeat_interval(void *data); -void scp_timer_nf_instance_no_heartbeat(void *data); -void scp_timer_nf_instance_validity(void *data); -void scp_timer_subscription_validity(void *data); -void scp_timer_sbi_client_wait_expire(void *data); - -#ifdef __cplusplus -} -#endif - -#endif /* SCP_TIMER_H */ diff --git a/src/sgwc/event.h b/src/sgwc/event.h index 748d34a61..ad653ec40 100644 --- a/src/sgwc/event.h +++ b/src/sgwc/event.h @@ -20,7 +20,7 @@ #ifndef SGWC_EVENT_H #define SGWC_EVENT_H -#include "ogs-core.h" +#include "ogs-proto.h" #ifdef __cplusplus extern "C" { @@ -34,7 +34,7 @@ typedef struct ogs_pfcp_message_s ogs_pfcp_message_t; typedef struct sgwc_bearer_s sgwc_bearer_t; typedef enum { - SGWC_EVT_BASE = OGS_FSM_USER_SIG, + SGWC_EVT_BASE = OGS_MAX_NUM_OF_PROTO_EVENT, SGWC_EVT_S11_MESSAGE, SGWC_EVT_S5C_MESSAGE, @@ -49,9 +49,10 @@ typedef enum { typedef struct sgwc_event_s { int id; - ogs_pkbuf_t *pkbuf; int timer_id; + ogs_pkbuf_t *pkbuf; + ogs_gtp_node_t *gnode; ogs_gtp2_message_t *gtp_message; diff --git a/src/sgwc/init.c b/src/sgwc/init.c index 65c7971e7..389917d83 100644 --- a/src/sgwc/init.c +++ b/src/sgwc/init.c @@ -97,8 +97,7 @@ static void sgwc_main(void *data) ogs_fsm_t sgwc_sm; int rv; - ogs_fsm_create(&sgwc_sm, sgwc_state_initial, sgwc_state_final); - ogs_fsm_init(&sgwc_sm, 0); + ogs_fsm_init(&sgwc_sm, sgwc_state_initial, sgwc_state_final, 0); for ( ;; ) { ogs_pollset_poll(ogs_app()->pollset, @@ -137,5 +136,4 @@ static void sgwc_main(void *data) done: ogs_fsm_fini(&sgwc_sm, 0); - ogs_fsm_delete(&sgwc_sm); } diff --git a/src/sgwc/pfcp-path.c b/src/sgwc/pfcp-path.c index 231b51507..e75305720 100644 --- a/src/sgwc/pfcp-path.c +++ b/src/sgwc/pfcp-path.c @@ -34,8 +34,7 @@ static void pfcp_node_fsm_init(ogs_pfcp_node_t *node, bool try_to_assoicate) ogs_assert(node->t_association); } - ogs_fsm_create(&node->sm, sgwc_pfcp_state_initial, sgwc_pfcp_state_final); - ogs_fsm_init(&node->sm, &e); + ogs_fsm_init(&node->sm, sgwc_pfcp_state_initial, sgwc_pfcp_state_final, &e); } static void pfcp_node_fsm_fini(ogs_pfcp_node_t *node) @@ -48,7 +47,6 @@ static void pfcp_node_fsm_fini(ogs_pfcp_node_t *node) e.pfcp_node = node; ogs_fsm_fini(&node->sm, &e); - ogs_fsm_delete(&node->sm); if (node->t_association) ogs_timer_delete(node->t_association); diff --git a/src/sgwu/event.h b/src/sgwu/event.h index e64f0ae19..8bbda9546 100644 --- a/src/sgwu/event.h +++ b/src/sgwu/event.h @@ -20,7 +20,7 @@ #ifndef SGWU_EVENT_H #define SGWU_EVENT_H -#include "ogs-core.h" +#include "ogs-proto.h" #ifdef __cplusplus extern "C" { @@ -33,7 +33,7 @@ typedef struct ogs_pfcp_message_s ogs_pfcp_message_t; typedef struct sgwu_bearer_s sgwu_bearer_t; typedef enum { - SGWU_EVT_BASE = OGS_FSM_USER_SIG, + SGWU_EVT_BASE = OGS_MAX_NUM_OF_PROTO_EVENT, SGWU_EVT_SXA_MESSAGE, SGWU_EVT_SXA_TIMER, @@ -45,9 +45,10 @@ typedef enum { typedef struct sgwu_event_s { int id; - ogs_pkbuf_t *pkbuf; int timer_id; + ogs_pkbuf_t *pkbuf; + ogs_gtp_node_t *gnode; ogs_pfcp_node_t *pfcp_node; diff --git a/src/sgwu/init.c b/src/sgwu/init.c index ed3546ffa..5d80dac23 100644 --- a/src/sgwu/init.c +++ b/src/sgwu/init.c @@ -94,8 +94,7 @@ static void sgwu_main(void *data) ogs_fsm_t sgwu_sm; int rv; - ogs_fsm_create(&sgwu_sm, sgwu_state_initial, sgwu_state_final); - ogs_fsm_init(&sgwu_sm, 0); + ogs_fsm_init(&sgwu_sm, sgwu_state_initial, sgwu_state_final, 0); for ( ;; ) { ogs_pollset_poll(ogs_app()->pollset, @@ -134,5 +133,4 @@ static void sgwu_main(void *data) done: ogs_fsm_fini(&sgwu_sm, 0); - ogs_fsm_delete(&sgwu_sm); } diff --git a/src/sgwu/pfcp-path.c b/src/sgwu/pfcp-path.c index bd0e5c438..ff38d3959 100644 --- a/src/sgwu/pfcp-path.c +++ b/src/sgwu/pfcp-path.c @@ -34,8 +34,7 @@ static void pfcp_node_fsm_init(ogs_pfcp_node_t *node, bool try_to_assoicate) ogs_assert(node->t_association); } - ogs_fsm_create(&node->sm, sgwu_pfcp_state_initial, sgwu_pfcp_state_final); - ogs_fsm_init(&node->sm, &e); + ogs_fsm_init(&node->sm, sgwu_pfcp_state_initial, sgwu_pfcp_state_final, &e); } static void pfcp_node_fsm_fini(ogs_pfcp_node_t *node) @@ -48,7 +47,6 @@ static void pfcp_node_fsm_fini(ogs_pfcp_node_t *node) e.pfcp_node = node; ogs_fsm_fini(&node->sm, &e); - ogs_fsm_delete(&node->sm); if (node->t_association) ogs_timer_delete(node->t_association); diff --git a/src/smf/context.c b/src/smf/context.c index 5471ab8c2..152a1ada8 100644 --- a/src/smf/context.c +++ b/src/smf/context.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -1111,8 +1111,7 @@ smf_sess_t *smf_sess_add_by_apn(smf_ue_t *smf_ue, char *apn, uint8_t rat_type) memset(&e, 0, sizeof(e)); e.sess = sess; - ogs_fsm_create(&sess->sm, smf_gsm_state_initial, smf_gsm_state_final); - ogs_fsm_init(&sess->sm, &e); + ogs_fsm_init(&sess->sm, smf_gsm_state_initial, smf_gsm_state_final, &e); sess->smf_ue = smf_ue; @@ -1321,8 +1320,7 @@ smf_sess_t *smf_sess_add_by_psi(smf_ue_t *smf_ue, uint8_t psi) memset(&e, 0, sizeof(e)); e.sess = sess; - ogs_fsm_create(&sess->sm, smf_gsm_state_initial, smf_gsm_state_final); - ogs_fsm_init(&sess->sm, &e); + ogs_fsm_init(&sess->sm, smf_gsm_state_initial, smf_gsm_state_final, &e); sess->smf_ue = smf_ue; @@ -1602,7 +1600,6 @@ void smf_sess_remove(smf_sess_t *sess) memset(&e, 0, sizeof(e)); e.sess = sess; ogs_fsm_fini(&sess->sm, &e); - ogs_fsm_delete(&sess->sm); OGS_TLV_CLEAR_DATA(&sess->gtp.ue_pco); OGS_TLV_CLEAR_DATA(&sess->gtp.user_location_information); diff --git a/src/smf/context.h b/src/smf/context.h index bb5b785de..31cbdb4c7 100644 --- a/src/smf/context.h +++ b/src/smf/context.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -126,21 +126,6 @@ typedef struct smf_ue_s { ogs_list_t sess_list; } smf_ue_t; -#define SMF_NF_INSTANCE_CLEAR(_cAUSE, _nFInstance) \ - do { \ - ogs_assert(_nFInstance); \ - if ((_nFInstance)->reference_count == 1) { \ - ogs_info("[%s] (%s) NF removed", (_nFInstance)->id, (_cAUSE)); \ - smf_nf_fsm_fini((_nFInstance)); \ - ogs_sbi_nf_instance_remove(_nFInstance); \ - } else { \ - /* There is an assocation with other context */ \ - ogs_info("[%s:%d] (%s) NF suspended", \ - _nFInstance->id, _nFInstance->reference_count, (_cAUSE)); \ - OGS_FSM_TRAN(&_nFInstance->sm, smf_nf_state_de_registered); \ - ogs_fsm_dispatch(&_nFInstance->sm, NULL); \ - } \ - } while(0) #define SMF_SESS_CLEAR(__sESS) \ do { \ smf_ue_t *smf_ue = NULL; \ diff --git a/src/smf/event.c b/src/smf/event.c index 3c70bbbce..6e8281eb3 100644 --- a/src/smf/event.c +++ b/src/smf/event.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -18,52 +18,26 @@ */ #include "event.h" -#include "context.h" -static OGS_POOL(pool, smf_event_t); -static ogs_thread_mutex_t smf_event_alloc_mutex; - -void smf_event_init(void) -{ - ogs_pool_init(&pool, ogs_app()->pool.event); - ogs_thread_mutex_init(&smf_event_alloc_mutex); -} - -void smf_event_final(void) -{ - ogs_pool_final(&pool); - ogs_thread_mutex_destroy(&smf_event_alloc_mutex); -} - -smf_event_t *smf_event_new(smf_event_e id) +smf_event_t *smf_event_new(int id) { smf_event_t *e = NULL; - ogs_thread_mutex_lock(&smf_event_alloc_mutex); - ogs_pool_alloc(&pool, &e); - ogs_thread_mutex_unlock(&smf_event_alloc_mutex); + e = ogs_event_size(id, sizeof(smf_event_t)); ogs_assert(e); - memset(e, 0, sizeof(*e)); - e->id = id; + e->h.id = id; return e; } -void smf_event_free(smf_event_t *e) -{ - ogs_assert(e); - ogs_thread_mutex_lock(&smf_event_alloc_mutex); - ogs_pool_free(&pool, e); - ogs_thread_mutex_unlock(&smf_event_alloc_mutex); -} - const char *smf_event_get_name(smf_event_t *e) { - if (e == NULL) + if (e == NULL) { return OGS_FSM_NAME_INIT_SIG; + } - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: return OGS_FSM_NAME_ENTRY_SIG; case OGS_FSM_EXIT_SIG: @@ -86,12 +60,12 @@ const char *smf_event_get_name(smf_event_t *e) case SMF_EVT_N4_NO_HEARTBEAT: return "SMF_EVT_N4_NO_HEARTBEAT"; - case SMF_EVT_SBI_SERVER: - return "SMF_EVT_SBI_SERVER"; - case SMF_EVT_SBI_CLIENT: - return "SMF_EVT_SBI_CLIENT"; - case SMF_EVT_SBI_TIMER: - return "SMF_EVT_SBI_TIMER"; + case OGS_EVENT_SBI_SERVER: + return OGS_EVENT_NAME_SBI_SERVER; + case OGS_EVENT_SBI_CLIENT: + return OGS_EVENT_NAME_SBI_CLIENT; + case OGS_EVENT_SBI_TIMER: + return OGS_EVENT_NAME_SBI_TIMER; case SMF_EVT_NGAP_MESSAGE: return "SMF_EVT_NGAP_MESSAGE"; @@ -107,5 +81,6 @@ const char *smf_event_get_name(smf_event_t *e) break; } + ogs_error("Unknown Event[%d]", e->h.id); return "UNKNOWN_EVENT"; } diff --git a/src/smf/event.h b/src/smf/event.h index 03ac91fa1..87d4cc3f2 100644 --- a/src/smf/event.h +++ b/src/smf/event.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -20,8 +20,7 @@ #ifndef SMF_EVENT_H #define SMF_EVENT_H -#include "ogs-core.h" -#include "ogs-gtp.h" +#include "ogs-proto.h" #ifdef __cplusplus extern "C" { @@ -29,6 +28,8 @@ extern "C" { typedef struct ogs_gtp_node_s ogs_gtp_node_t; typedef struct ogs_gtp_xact_s ogs_gtp_xact_t; +typedef struct ogs_gtp1_message_s ogs_gtp1_message_t; +typedef struct ogs_gtp2_message_s ogs_gtp2_message_t; typedef struct ogs_pfcp_node_s ogs_pfcp_node_t; typedef struct ogs_pfcp_xact_s ogs_pfcp_xact_t; typedef struct ogs_pfcp_message_s ogs_pfcp_message_t; @@ -38,16 +39,12 @@ typedef struct ogs_diam_s6b_message_s ogs_diam_s6b_message_t; typedef struct smf_sess_s smf_sess_t; typedef struct smf_upf_s smf_upf_t; typedef struct smf_gtp_node_s smf_gtp_node_t; -typedef struct ogs_sbi_request_s ogs_sbi_request_t; -typedef struct ogs_sbi_response_s ogs_sbi_response_t; -typedef struct ogs_sbi_message_s ogs_sbi_message_t; -typedef struct ogs_sbi_subscription_s ogs_sbi_subscription_t; typedef struct ogs_nas_5gs_message_s ogs_nas_5gs_message_t; typedef struct NGAP_NGAP_PDU ogs_ngap_message_t; typedef long NGAP_ProcedureCode_t; typedef enum { - SMF_EVT_BASE = OGS_FSM_USER_SIG, + SMF_EVT_BASE = OGS_MAX_NUM_OF_PROTO_EVENT, SMF_EVT_S5C_MESSAGE, SMF_EVT_S6B_MESSAGE, @@ -59,10 +56,6 @@ typedef enum { SMF_EVT_N4_TIMER, SMF_EVT_N4_NO_HEARTBEAT, - SMF_EVT_SBI_SERVER, - SMF_EVT_SBI_CLIENT, - SMF_EVT_SBI_TIMER, - SMF_EVT_NGAP_MESSAGE, SMF_EVT_NGAP_TIMER, @@ -74,9 +67,9 @@ typedef enum { } smf_event_e; typedef struct smf_event_s { - int id; + ogs_event_t h; + ogs_pkbuf_t *pkbuf; - int timer_id; smf_gtp_node_t *gnode; ogs_gtp_xact_t *gtp_xact; @@ -96,15 +89,6 @@ typedef struct smf_event_s { ogs_diam_s6b_message_t *s6b_message; }; - struct { - ogs_sbi_request_t *request; - ogs_sbi_response_t *response; - void *data; - int state; - - ogs_sbi_message_t *message; - } sbi; - struct { int type; ogs_ngap_message_t *message; @@ -118,11 +102,7 @@ typedef struct smf_event_s { smf_sess_t *sess; } smf_event_t; -void smf_event_init(void); -void smf_event_final(void); - -smf_event_t *smf_event_new(smf_event_e id); -void smf_event_free(smf_event_t *e); +smf_event_t *smf_event_new(int id); const char *smf_event_get_name(smf_event_t *e); diff --git a/src/smf/gsm-sm.c b/src/smf/gsm-sm.c index 20a9a8f69..e427265d2 100644 --- a/src/smf/gsm-sm.c +++ b/src/smf/gsm-sm.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -235,7 +235,7 @@ void smf_gsm_state_initial(ogs_fsm_t *s, smf_event_t *e) sess = e->sess; ogs_assert(sess); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: /* reset state: */ sess->sm_data.gx_ccr_init_in_flight = false; @@ -298,10 +298,10 @@ void smf_gsm_state_initial(ogs_fsm_t *s, smf_event_t *e) } break; - case SMF_EVT_SBI_SERVER: - sbi_message = e->sbi.message; + case OGS_EVENT_SBI_SERVER: + sbi_message = e->h.sbi.message; ogs_assert(sbi_message); - stream = e->sbi.data; + stream = e->h.sbi.data; ogs_assert(stream); SWITCH(sbi_message->h.service.name) @@ -342,7 +342,7 @@ void smf_gsm_state_initial(ogs_fsm_t *s, smf_event_t *e) ogs_assert(nas_message); sess = e->sess; ogs_assert(sess); - stream = e->sbi.data; + stream = e->h.sbi.data; ogs_assert(stream); smf_ue = sess->smf_ue; ogs_assert(smf_ue); @@ -397,7 +397,7 @@ void smf_gsm_state_wait_epc_auth_initial(ogs_fsm_t *s, smf_event_t *e) sess = e->sess; ogs_assert(sess); - switch (e->id) { + switch (e->h.id) { case SMF_EVT_GX_MESSAGE: gx_message = e->gx_message; ogs_assert(gx_message); @@ -482,14 +482,14 @@ void smf_gsm_state_wait_5gc_sm_policy_association(ogs_fsm_t *s, smf_event_t *e) sess = e->sess; ogs_assert(sess); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: break; case OGS_FSM_EXIT_SIG: break; - case SMF_EVT_SBI_CLIENT: - sbi_message = e->sbi.message; + case OGS_EVENT_SBI_CLIENT: + sbi_message = e->h.sbi.message; ogs_assert(sbi_message); sess = e->sess; @@ -499,7 +499,7 @@ void smf_gsm_state_wait_5gc_sm_policy_association(ogs_fsm_t *s, smf_event_t *e) SWITCH(sbi_message->h.service.name) CASE(OGS_SBI_SERVICE_NAME_NUDM_SDM) - stream = e->sbi.data; + stream = e->h.sbi.data; ogs_assert(stream); SWITCH(sbi_message->h.resource.component[1]) @@ -545,8 +545,8 @@ void smf_gsm_state_wait_5gc_sm_policy_association(ogs_fsm_t *s, smf_event_t *e) break; CASE(OGS_SBI_SERVICE_NAME_NPCF_SMPOLICYCONTROL) - stream = e->sbi.data; - state = e->sbi.state; + stream = e->h.sbi.data; + state = e->h.sbi.state; SWITCH(sbi_message->h.resource.component[0]) CASE(OGS_SBI_RESOURCE_NAME_SM_POLICIES) @@ -648,7 +648,7 @@ void smf_gsm_state_wait_pfcp_establishment(ogs_fsm_t *s, smf_event_t *e) sess = e->sess; ogs_assert(sess); - switch (e->id) { + switch (e->h.id) { case SMF_EVT_N4_MESSAGE: pfcp_xact = e->pfcp_xact; ogs_assert(pfcp_xact); @@ -757,7 +757,7 @@ void smf_gsm_state_operational(ogs_fsm_t *s, smf_event_t *e) sess = e->sess; ogs_assert(sess); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: break; @@ -812,10 +812,10 @@ void smf_gsm_state_operational(ogs_fsm_t *s, smf_event_t *e) } break; - case SMF_EVT_SBI_SERVER: - sbi_message = e->sbi.message; + case OGS_EVENT_SBI_SERVER: + sbi_message = e->h.sbi.message; ogs_assert(sbi_message); - stream = e->sbi.data; + stream = e->h.sbi.data; ogs_assert(stream); SWITCH(sbi_message->h.service.name) @@ -849,8 +849,8 @@ void smf_gsm_state_operational(ogs_fsm_t *s, smf_event_t *e) END break; - case SMF_EVT_SBI_CLIENT: - sbi_message = e->sbi.message; + case OGS_EVENT_SBI_CLIENT: + sbi_message = e->h.sbi.message; ogs_assert(sbi_message); sess = e->sess; @@ -860,7 +860,7 @@ void smf_gsm_state_operational(ogs_fsm_t *s, smf_event_t *e) SWITCH(sbi_message->h.service.name) CASE(OGS_SBI_SERVICE_NAME_NPCF_SMPOLICYCONTROL) - stream = e->sbi.data; + stream = e->h.sbi.data; SWITCH(sbi_message->h.resource.component[0]) CASE(OGS_SBI_RESOURCE_NAME_SM_POLICIES) @@ -940,7 +940,7 @@ void smf_gsm_state_operational(ogs_fsm_t *s, smf_event_t *e) SWITCH(sbi_message->h.resource.component[0]) CASE(OGS_SBI_RESOURCE_NAME_UE_CONTEXTS) smf_namf_comm_handle_n1_n2_message_transfer( - sess, e->sbi.state, sbi_message); + sess, e->h.sbi.state, sbi_message); break; DEFAULT @@ -963,7 +963,7 @@ void smf_gsm_state_operational(ogs_fsm_t *s, smf_event_t *e) ogs_assert(nas_message); sess = e->sess; ogs_assert(sess); - stream = e->sbi.data; + stream = e->h.sbi.data; ogs_assert(stream); smf_ue = sess->smf_ue; ogs_assert(smf_ue); @@ -1023,7 +1023,7 @@ void smf_gsm_state_operational(ogs_fsm_t *s, smf_event_t *e) case SMF_EVT_NGAP_MESSAGE: sess = e->sess; ogs_assert(sess); - stream = e->sbi.data; + stream = e->h.sbi.data; ogs_assert(stream); smf_ue = sess->smf_ue; ogs_assert(smf_ue); @@ -1160,7 +1160,7 @@ void smf_gsm_state_wait_pfcp_deletion(ogs_fsm_t *s, smf_event_t *e) sess = e->sess; ogs_assert(sess); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: /* Since `pfcp_xact->epc` is not avaiable, * we'll use `sess->epc` */ @@ -1170,12 +1170,12 @@ void smf_gsm_state_wait_pfcp_deletion(ogs_fsm_t *s, smf_event_t *e) smf_epc_pfcp_send_session_deletion_request(sess, e->gtp_xact)); } else { /* 5GC */ - stream = e->sbi.data; + stream = e->h.sbi.data; ogs_assert(stream); ogs_assert(OGS_OK == smf_5gc_pfcp_send_session_deletion_request( - sess, stream, e->sbi.state)); + sess, stream, e->h.sbi.state)); } break; @@ -1286,7 +1286,7 @@ void smf_gsm_state_wait_epc_auth_release(ogs_fsm_t *s, smf_event_t *e) sess = e->sess; ogs_assert(sess); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: /* reset state: */ sess->sm_data.gx_cca_term_err = ER_DIAMETER_SUCCESS; @@ -1413,16 +1413,16 @@ void smf_gsm_state_wait_5gc_n1_n2_release(ogs_fsm_t *s, smf_event_t *e) sess = e->sess; ogs_assert(sess); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: break; case OGS_FSM_EXIT_SIG: break; - case SMF_EVT_SBI_SERVER: - sbi_message = e->sbi.message; + case OGS_EVENT_SBI_SERVER: + sbi_message = e->h.sbi.message; ogs_assert(sbi_message); - stream = e->sbi.data; + stream = e->h.sbi.data; ogs_assert(stream); SWITCH(sbi_message->h.service.name) @@ -1453,8 +1453,8 @@ void smf_gsm_state_wait_5gc_n1_n2_release(ogs_fsm_t *s, smf_event_t *e) END break; - case SMF_EVT_SBI_CLIENT: - sbi_message = e->sbi.message; + case OGS_EVENT_SBI_CLIENT: + sbi_message = e->h.sbi.message; ogs_assert(sbi_message); sess = e->sess; @@ -1467,7 +1467,7 @@ void smf_gsm_state_wait_5gc_n1_n2_release(ogs_fsm_t *s, smf_event_t *e) SWITCH(sbi_message->h.resource.component[0]) CASE(OGS_SBI_RESOURCE_NAME_UE_CONTEXTS) smf_namf_comm_handle_n1_n2_message_transfer( - sess, e->sbi.state, sbi_message); + sess, e->h.sbi.state, sbi_message); break; DEFAULT @@ -1488,7 +1488,7 @@ void smf_gsm_state_wait_5gc_n1_n2_release(ogs_fsm_t *s, smf_event_t *e) case SMF_EVT_NGAP_MESSAGE: sess = e->sess; ogs_assert(sess); - stream = e->sbi.data; + stream = e->h.sbi.data; ogs_assert(stream); smf_ue = sess->smf_ue; ogs_assert(smf_ue); @@ -1535,7 +1535,7 @@ void smf_gsm_state_wait_5gc_n1_n2_release(ogs_fsm_t *s, smf_event_t *e) ogs_assert(nas_message); sess = e->sess; ogs_assert(sess); - stream = e->sbi.data; + stream = e->h.sbi.data; ogs_assert(stream); smf_ue = sess->smf_ue; ogs_assert(smf_ue); @@ -1572,7 +1572,7 @@ void smf_gsm_state_session_will_release(ogs_fsm_t *s, smf_event_t *e) sess = e->sess; ogs_assert(sess); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: SMF_SESS_CLEAR(sess); break; @@ -1601,7 +1601,7 @@ void smf_gsm_state_exception(ogs_fsm_t *s, smf_event_t *e) smf_ue = sess->smf_ue; ogs_assert(smf_ue); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: ogs_error("[%s:%d] State machine exception", smf_ue->supi, sess->psi); SMF_SESS_CLEAR(sess); diff --git a/src/smf/gtp-path.c b/src/smf/gtp-path.c index 7146c211b..5b34f0ab0 100644 --- a/src/smf/gtp-path.c +++ b/src/smf/gtp-path.c @@ -108,7 +108,7 @@ static void _gtpv1v2_c_recv_cb(short when, ogs_socket_t fd, void *data) if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed:%d", (int)rv); ogs_pkbuf_free(e->pkbuf); - smf_event_free(e); + ogs_event_free(e); } } diff --git a/src/smf/gx-path.c b/src/smf/gx-path.c index 6957697c9..14c3185ac 100644 --- a/src/smf/gx-path.c +++ b/src/smf/gx-path.c @@ -1008,7 +1008,7 @@ out: ogs_error("ogs_queue_push() failed:%d", (int)rv); ogs_session_data_free(&gx_message->session_data); ogs_free(gx_message); - smf_event_free(e); + ogs_event_free(e); } else { ogs_pollset_notify(ogs_app()->pollset); } @@ -1251,7 +1251,7 @@ static int smf_gx_rar_cb( struct msg **msg, struct avp *avp, ogs_error("ogs_queue_push() failed:%d", (int)rv); ogs_session_data_free(&gx_message->session_data); ogs_free(gx_message); - smf_event_free(e); + ogs_event_free(e); } else { ogs_pollset_notify(ogs_app()->pollset); } diff --git a/src/smf/gy-path.c b/src/smf/gy-path.c index ecbda74dd..65783db42 100644 --- a/src/smf/gy-path.c +++ b/src/smf/gy-path.c @@ -1106,7 +1106,7 @@ out: if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed:%d", (int)rv); ogs_free(gy_message); - smf_event_free(e); + ogs_event_free(e); } else { ogs_pollset_notify(ogs_app()->pollset); } @@ -1235,7 +1235,7 @@ static int smf_gy_rar_cb( struct msg **msg, struct avp *avp, if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed:%d", (int)rv); ogs_free(gy_message); - smf_event_free(e); + ogs_event_free(e); } else { ogs_pollset_notify(ogs_app()->pollset); } diff --git a/src/smf/init.c b/src/smf/init.c index b56f8be00..669bc0637 100644 --- a/src/smf/init.c +++ b/src/smf/init.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -39,7 +39,6 @@ int smf_initialize() ogs_sbi_context_init(); smf_context_init(); - smf_event_init(); rv = ogs_gtp_xact_init(); if (rv != OGS_OK) return rv; @@ -100,7 +99,7 @@ static void event_termination(void) /* Sending NF Instance De-registeration to NRF */ ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) - smf_nf_fsm_fini(nf_instance); + ogs_sbi_nf_fsm_fini(nf_instance); /* Starting holding timer */ t_termination_holding = ogs_timer_add(ogs_app()->timer_mgr, NULL, NULL); @@ -138,8 +137,6 @@ void smf_terminate(void) ogs_pfcp_xact_final(); ogs_gtp_xact_final(); - - smf_event_final(); /* Destroy event */ } static void smf_main(void *data) @@ -147,8 +144,7 @@ static void smf_main(void *data) ogs_fsm_t smf_sm; int rv; - ogs_fsm_create(&smf_sm, smf_state_initial, smf_state_final); - ogs_fsm_init(&smf_sm, 0); + ogs_fsm_init(&smf_sm, smf_state_initial, smf_state_final, 0); for ( ;; ) { ogs_pollset_poll(ogs_app()->pollset, @@ -181,11 +177,10 @@ static void smf_main(void *data) ogs_assert(e); ogs_fsm_dispatch(&smf_sm, e); - smf_event_free(e); + ogs_event_free(e); } } done: ogs_fsm_fini(&smf_sm, 0); - ogs_fsm_delete(&smf_sm); } diff --git a/src/smf/meson.build b/src/smf/meson.build index dc06cac43..ee8419e2f 100644 --- a/src/smf/meson.build +++ b/src/smf/meson.build @@ -1,4 +1,4 @@ -# Copyright (C) 2019 by Sukchan Lee +# Copyright (C) 2019-2022 by Sukchan Lee # This file is part of Open5GS. @@ -51,7 +51,6 @@ libsmf_sources = files(''' n4-build.h n4-handler.h binding.h - nnrf-build.h nnrf-handler.h nudm-build.h nudm-handler.h @@ -74,7 +73,6 @@ libsmf_sources = files(''' timer.c context.c smf-sm.c - nf-sm.c gsm-sm.c pfcp-sm.c gtp-path.c @@ -92,7 +90,6 @@ libsmf_sources = files(''' n4-build.c n4-handler.c binding.c - nnrf-build.c nnrf-handler.c nudm-build.c nudm-handler.c diff --git a/src/smf/n4-handler.c b/src/smf/n4-handler.c index 1fe0ef10b..e9de2c401 100644 --- a/src/smf/n4-handler.c +++ b/src/smf/n4-handler.c @@ -18,7 +18,6 @@ */ #include "context.h" -#include "timer.h" #include "s5c-build.h" #include "pfcp-path.h" #include "gtp-path.h" diff --git a/src/smf/nas-path.c b/src/smf/nas-path.c index 06c5c2ef4..615e183e4 100644 --- a/src/smf/nas-path.c +++ b/src/smf/nas-path.c @@ -31,12 +31,12 @@ void nas_5gs_send_to_gsm( e = smf_event_new(SMF_EVT_5GSM_MESSAGE); ogs_assert(e); e->sess = sess; - e->sbi.data = stream; + e->h.sbi.data = stream; e->pkbuf = pkbuf; rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed:%d", (int)rv); ogs_pkbuf_free(e->pkbuf); - smf_event_free(e); + ogs_event_free(e); } } diff --git a/src/smf/nf-sm.c b/src/smf/nf-sm.c deleted file mode 100644 index 334be8892..000000000 --- a/src/smf/nf-sm.c +++ /dev/null @@ -1,462 +0,0 @@ -/* - * Copyright (C) 2019 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "context.h" - -#include "sbi-path.h" -#include "nnrf-handler.h" - -void smf_nf_fsm_init(ogs_sbi_nf_instance_t *nf_instance) -{ - smf_event_t e; - - ogs_assert(nf_instance); - - memset(&e, 0, sizeof(e)); - e.sbi.data = nf_instance; - - ogs_fsm_create(&nf_instance->sm, - smf_nf_state_initial, smf_nf_state_final); - ogs_fsm_init(&nf_instance->sm, &e); -} - -void smf_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance) -{ - smf_event_t e; - - ogs_assert(nf_instance); - - memset(&e, 0, sizeof(e)); - e.sbi.data = nf_instance; - - ogs_fsm_fini(&nf_instance->sm, &e); - ogs_fsm_delete(&nf_instance->sm); -} - -void smf_nf_state_initial(ogs_fsm_t *s, smf_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - - ogs_assert(s); - ogs_assert(e); - - smf_sm_debug(e); - - nf_instance = e->sbi.data; - ogs_assert(nf_instance); - - nf_instance->t_registration_interval = ogs_timer_add(ogs_app()->timer_mgr, - smf_timer_nf_instance_registration_interval, nf_instance); - ogs_assert(nf_instance->t_registration_interval); - nf_instance->t_heartbeat_interval = ogs_timer_add(ogs_app()->timer_mgr, - smf_timer_nf_instance_heartbeat_interval, nf_instance); - ogs_assert(nf_instance->t_heartbeat_interval); - nf_instance->t_no_heartbeat = ogs_timer_add(ogs_app()->timer_mgr, - smf_timer_nf_instance_no_heartbeat, nf_instance); - ogs_assert(nf_instance->t_no_heartbeat); - nf_instance->t_validity = ogs_timer_add(ogs_app()->timer_mgr, - smf_timer_nf_instance_validity, nf_instance); - ogs_assert(nf_instance->t_validity); - - 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); - } -} - -void smf_nf_state_final(ogs_fsm_t *s, smf_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - - ogs_assert(s); - ogs_assert(e); - - smf_sm_debug(e); - - nf_instance = e->sbi.data; - ogs_assert(nf_instance); - - ogs_timer_delete(nf_instance->t_registration_interval); - ogs_timer_delete(nf_instance->t_heartbeat_interval); - ogs_timer_delete(nf_instance->t_no_heartbeat); - ogs_timer_delete(nf_instance->t_validity); -} - -void smf_nf_state_will_register(ogs_fsm_t *s, smf_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_sbi_client_t *client = NULL; - ogs_sbi_message_t *message = NULL; - ogs_sockaddr_t *addr = NULL; - - ogs_assert(s); - ogs_assert(e); - - smf_sm_debug(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: - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); - - ogs_assert(true == ogs_nnrf_nfm_send_nf_register( - nf_instance, smf_nnrf_nfm_build_register)); - break; - - case OGS_FSM_EXIT_SIG: - ogs_timer_stop(nf_instance->t_registration_interval); - break; - - case SMF_EVT_SBI_CLIENT: - message = e->sbi.message; - ogs_assert(message); - - SWITCH(message->h.service.name) - CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) - - SWITCH(message->h.resource.component[0]) - CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - - if (message->res_status == OGS_SBI_HTTP_STATUS_OK || - message->res_status == OGS_SBI_HTTP_STATUS_CREATED) { - smf_nnrf_handle_nf_register(nf_instance, message); - OGS_FSM_TRAN(s, &smf_nf_state_registered); - } else { - ogs_error("[%s] HTTP Response Status Code [%d]", - 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]", - ogs_sbi_self()->nf_instance->id, - message->h.resource.component[0]); - END - break; - - DEFAULT - ogs_error("[%s] Invalid API name [%s]", - ogs_sbi_self()->nf_instance->id, message->h.service.name); - END - break; - - case SMF_EVT_SBI_TIMER: - switch(e->timer_id) { - case SMF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - client = nf_instance->client; - ogs_assert(client); - addr = client->node.addr; - ogs_assert(addr); - - ogs_warn("[%s] Retry to registration with NRF", - ogs_sbi_self()->nf_instance->id); - - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); - - ogs_assert(true == ogs_nnrf_nfm_send_nf_register( - nf_instance, smf_nnrf_nfm_build_register)); - break; - - default: - 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", - ogs_sbi_self()->nf_instance->id, smf_event_get_name(e)); - break; - } -} - -void smf_nf_state_registered(ogs_fsm_t *s, smf_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_sbi_client_t *client = NULL; - ogs_sbi_message_t *message = NULL; - ogs_assert(s); - ogs_assert(e); - - smf_sm_debug(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_NRF(nf_instance)) { - ogs_info("[%s] NF registered [Heartbeat:%ds]", - ogs_sbi_self()->nf_instance->id, - nf_instance->time.heartbeat_interval); - - client = nf_instance->client; - ogs_assert(client); - - if (nf_instance->time.heartbeat_interval) { - ogs_timer_start(nf_instance->t_heartbeat_interval, - ogs_time_from_sec(nf_instance->time.heartbeat_interval)); - ogs_timer_start(nf_instance->t_no_heartbeat, - ogs_time_from_sec( - nf_instance->time.heartbeat_interval + - ogs_app()->time.nf_instance.no_heartbeat_margin)); - } - - ogs_assert(true == - ogs_nnrf_nfm_send_nf_status_subscribe(client, - 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, - 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, - 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, - 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_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); - ogs_timer_stop(nf_instance->t_no_heartbeat); - } - - if (!OGS_FSM_CHECK(&nf_instance->sm, smf_nf_state_exception)) { - ogs_assert(true == - ogs_nnrf_nfm_send_nf_de_register(nf_instance)); - } - } - break; - - case SMF_EVT_SBI_CLIENT: - message = e->sbi.message; - ogs_assert(message); - - SWITCH(message->h.service.name) - CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) - - SWITCH(message->h.resource.component[0]) - CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - - if (message->res_status == OGS_SBI_HTTP_STATUS_NO_CONTENT || - message->res_status == OGS_SBI_HTTP_STATUS_OK) { - if (nf_instance->time.heartbeat_interval) - ogs_timer_start(nf_instance->t_no_heartbeat, - ogs_time_from_sec( - nf_instance->time.heartbeat_interval + - ogs_app()->time.nf_instance. - no_heartbeat_margin)); - } else { - ogs_warn("[%s] HTTP response error [%d]", - 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]", - ogs_sbi_self()->nf_instance->id, - message->h.resource.component[0]); - END - break; - - DEFAULT - ogs_error("[%s] Invalid API name [%s]", - ogs_sbi_self()->nf_instance->id, message->h.service.name); - END - break; - - case SMF_EVT_SBI_TIMER: - switch(e->timer_id) { - case SMF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - if (nf_instance->time.heartbeat_interval) - ogs_timer_start(nf_instance->t_heartbeat_interval, - ogs_time_from_sec(nf_instance->time.heartbeat_interval)); - - ogs_assert(true == ogs_nnrf_nfm_send_nf_update(nf_instance)); - break; - - case SMF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - 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: - 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:%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; - - default: - 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; - } -} - -void smf_nf_state_de_registered(ogs_fsm_t *s, smf_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_assert(s); - ogs_assert(e); - - smf_sm_debug(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_NRF(nf_instance)) { - ogs_info("[%s] NF de-registered", ogs_sbi_self()->nf_instance->id); - } - break; - - case OGS_FSM_EXIT_SIG: - break; - - default: - 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; - } -} - -void smf_nf_state_exception(ogs_fsm_t *s, smf_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_sbi_client_t *client = NULL; - ogs_sbi_message_t *message = NULL; - ogs_sockaddr_t *addr = NULL; - ogs_assert(s); - ogs_assert(e); - - smf_sm_debug(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_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_NRF(nf_instance)) { - ogs_timer_stop(nf_instance->t_registration_interval); - } - break; - - case SMF_EVT_SBI_TIMER: - switch(e->timer_id) { - case SMF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - client = nf_instance->client; - ogs_assert(client); - addr = client->node.addr; - ogs_assert(addr); - - 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:%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; - - case SMF_EVT_SBI_CLIENT: - message = e->sbi.message; - ogs_assert(message); - - SWITCH(message->h.service.name) - CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) - - SWITCH(message->h.resource.component[0]) - CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - break; - DEFAULT - ogs_error("Invalid resource name [%s]", - message->h.resource.component[0]); - END - break; - DEFAULT - ogs_error("Invalid API name [%s]", message->h.service.name); - END - break; - - default: - 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/ngap-path.c b/src/smf/ngap-path.c index 7a6c6ee46..3240a6b48 100644 --- a/src/smf/ngap-path.c +++ b/src/smf/ngap-path.c @@ -31,13 +31,13 @@ void ngap_send_to_n2sm(smf_sess_t *sess, e = smf_event_new(SMF_EVT_NGAP_MESSAGE); ogs_assert(e); e->sess = sess; - e->sbi.data = stream; + e->h.sbi.data = stream; e->pkbuf = pkbuf; e->ngap.type = type; rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed:%d", (int)rv); ogs_pkbuf_free(e->pkbuf); - smf_event_free(e); + ogs_event_free(e); } -} \ No newline at end of file +} diff --git a/src/smf/nnrf-build.c b/src/smf/nnrf-build.c deleted file mode 100644 index 68b769f85..000000000 --- a/src/smf/nnrf-build.c +++ /dev/null @@ -1,293 +0,0 @@ -/* - * Copyright (C) 2019,2020 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "nnrf-build.h" - -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; - - OpenAPI_nf_profile_t *NFProfile = NULL; - - OpenAPI_list_t *SmfInfoList = NULL; - OpenAPI_map_t *SmfInfoMap = NULL; - OpenAPI_smf_info_t *SmfInfo = NULL; - int SmfInfoMapKey; - - OpenAPI_list_t *sNssaiSmfInfoList = NULL; - OpenAPI_snssai_smf_info_item_t *sNssaiSmfInfoItem = NULL; - OpenAPI_snssai_t *sNssai = NULL; - OpenAPI_list_t *DnnSmfInfoList = NULL; - OpenAPI_dnn_smf_info_item_t *DnnSmfInfoItem = NULL; - - OpenAPI_list_t *TaiList = NULL; - OpenAPI_tai_t *TaiItem = NULL; - OpenAPI_list_t *TaiRangeList = NULL; - OpenAPI_tai_range_t *TaiRangeItem = NULL; - OpenAPI_list_t *TacRangeList = NULL; - OpenAPI_tac_range_t *TacRangeItem = NULL; - - OpenAPI_lnode_t *node = NULL, *node2 = NULL, *node3 = 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_PUT; - message.h.service.name = (char *)OGS_SBI_SERVICE_NAME_NNRF_NFM; - 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] = nf_instance->id; - - message.http.content_encoding = (char*)ogs_sbi_self()->content_encoding; - - SmfInfoList = OpenAPI_list_create(); - ogs_assert(SmfInfoList); - - SmfInfoMapKey = 0; - - 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)); - ogs_assert_if_reached(); - } - - if (nf_info->smf.num_of_slice == 0) { - ogs_fatal("CHECK CONFIGURATION: No S-NSSAI"); - ogs_assert_if_reached(); - } - - SmfInfo = ogs_calloc(1, sizeof(*SmfInfo)); - ogs_expect_or_return_val(SmfInfo, NULL); - - sNssaiSmfInfoList = OpenAPI_list_create(); - ogs_assert(sNssaiSmfInfoList); - - for (i = 0; i < nf_info->smf.num_of_slice; i++) { - DnnSmfInfoList = OpenAPI_list_create(); - ogs_assert(DnnSmfInfoList); - - for (j = 0; j < nf_info->smf.slice[i].num_of_dnn; j++) { - DnnSmfInfoItem = ogs_calloc(1, sizeof(*DnnSmfInfoItem)); - ogs_expect_or_return_val(DnnSmfInfoItem, NULL); - DnnSmfInfoItem->dnn = nf_info->smf.slice[i].dnn[j]; - - OpenAPI_list_add(DnnSmfInfoList, DnnSmfInfoItem); - } - - if (!DnnSmfInfoList->count) { - OpenAPI_list_free(DnnSmfInfoList); - - ogs_error("CHECK CONFIGURATION: No DNN"); - ogs_expect_or_return_val(0, NULL); - } - - sNssaiSmfInfoItem = ogs_calloc(1, sizeof(*sNssaiSmfInfoItem)); - ogs_expect_or_return_val(sNssaiSmfInfoItem, NULL); - - sNssaiSmfInfoItem->dnn_smf_info_list = DnnSmfInfoList; - - sNssaiSmfInfoItem->s_nssai = sNssai = - ogs_calloc(1, sizeof(*sNssai)); - ogs_expect_or_return_val(sNssai, NULL); - sNssai->sst = nf_info->smf.slice[i].s_nssai.sst; - sNssai->sd = - ogs_s_nssai_sd_to_string(nf_info->smf.slice[i].s_nssai.sd); - - OpenAPI_list_add(sNssaiSmfInfoList, sNssaiSmfInfoItem); - } - - if (sNssaiSmfInfoList->count) - SmfInfo->s_nssai_smf_info_list = sNssaiSmfInfoList; - else - OpenAPI_list_free(sNssaiSmfInfoList); - - TaiList = OpenAPI_list_create(); - ogs_assert(TaiList); - - for (i = 0; i < nf_info->smf.num_of_nr_tai; i++) { - TaiItem = ogs_calloc(1, sizeof(*TaiItem)); - ogs_expect_or_return_val(TaiItem, NULL); - TaiItem->plmn_id = ogs_sbi_build_plmn_id( - &nf_info->smf.nr_tai[i].plmn_id); - ogs_expect_or_return_val(TaiItem->plmn_id, NULL); - TaiItem->tac = ogs_uint24_to_0string(nf_info->smf.nr_tai[i].tac); - ogs_expect_or_return_val(TaiItem->tac, NULL); - - OpenAPI_list_add(TaiList, TaiItem); - } - - if (TaiList->count) - SmfInfo->tai_list = TaiList; - else - OpenAPI_list_free(TaiList); - - TaiRangeList = OpenAPI_list_create(); - ogs_assert(TaiRangeList); - - for (i = 0; i < nf_info->smf.num_of_nr_tai_range; i++) { - TacRangeList = OpenAPI_list_create(); - ogs_assert(TacRangeList); - - for (j = 0; - j < nf_info->smf.nr_tai_range[i].num_of_tac_range; j++) { - TacRangeItem = ogs_calloc(1, sizeof(*TacRangeItem)); - ogs_expect_or_return_val(TacRangeItem, NULL); - - TacRangeItem->start = ogs_uint24_to_0string( - nf_info->smf.nr_tai_range[i].start[j]); - ogs_expect_or_return_val(TacRangeItem->start, NULL); - TacRangeItem->end = - ogs_uint24_to_0string(nf_info->smf.nr_tai_range[i].end[j]); - ogs_expect_or_return_val(TacRangeItem->end, NULL); - - OpenAPI_list_add(TacRangeList, TacRangeItem); - } - - if (!TacRangeList->count) { - OpenAPI_list_free(TacRangeList); - - ogs_error("CHECK CONFIGURATION: No Start/End in TacRange"); - ogs_expect_or_return_val(0, NULL); - } - - TaiRangeItem = ogs_calloc(1, sizeof(*TaiRangeItem)); - ogs_expect_or_return_val(TaiRangeItem, NULL); - - TaiRangeItem->plmn_id = ogs_sbi_build_plmn_id( - &nf_info->smf.nr_tai_range[i].plmn_id); - ogs_expect_or_return_val(TaiRangeItem->plmn_id, NULL); - - TaiRangeItem->tac_range_list = TacRangeList; - - OpenAPI_list_add(TaiRangeList, TaiRangeItem); - } - - if (TaiRangeList->count) - SmfInfo->tai_range_list = TaiRangeList; - else - OpenAPI_list_free(TaiRangeList); - - SmfInfoMap = OpenAPI_map_create( - ogs_msprintf("%d", ++SmfInfoMapKey), SmfInfo); - ogs_assert(SmfInfoMap); - - OpenAPI_list_add(SmfInfoList, SmfInfoMap); - } - - NFProfile = ogs_nnrf_nfm_build_nf_profile(); - ogs_expect_or_return_val(NFProfile, NULL); - - if (SmfInfoList->count == 1) { - NFProfile->smf_info = SmfInfo; - } else if (SmfInfoList->count > 1) { - NFProfile->smf_info_list = SmfInfoList; - } - - message.NFProfile = NFProfile; - - request = ogs_sbi_build_request(&message); - - ogs_sbi_nnrf_free_nf_profile(NFProfile); - - OpenAPI_list_for_each(SmfInfoList, node) { - SmfInfoMap = node->data; - if (SmfInfoMap) { - SmfInfo = SmfInfoMap->value; - if (SmfInfo) { - sNssaiSmfInfoList = SmfInfo->s_nssai_smf_info_list; - OpenAPI_list_for_each(sNssaiSmfInfoList, node2) { - sNssaiSmfInfoItem = node2->data; - ogs_assert(sNssaiSmfInfoItem); - - DnnSmfInfoList = sNssaiSmfInfoItem->dnn_smf_info_list; - OpenAPI_list_for_each(DnnSmfInfoList, node3) { - DnnSmfInfoItem = node3->data; - ogs_assert(DnnSmfInfoItem); - ogs_free(DnnSmfInfoItem); - } - OpenAPI_list_free(DnnSmfInfoList); - - sNssai = sNssaiSmfInfoItem->s_nssai; - if (sNssai) { - if (sNssai->sd) - ogs_free(sNssai->sd); - ogs_free(sNssai); - } - - ogs_free(sNssaiSmfInfoItem); - } - OpenAPI_list_free(sNssaiSmfInfoList); - - TaiList = SmfInfo->tai_list; - OpenAPI_list_for_each(TaiList, node2) { - TaiItem = node2->data; - ogs_assert(TaiItem); - if (TaiItem->plmn_id) - ogs_sbi_free_plmn_id(TaiItem->plmn_id); - if (TaiItem->tac) - ogs_free(TaiItem->tac); - ogs_free(TaiItem); - } - OpenAPI_list_free(TaiList); - - TaiRangeList = SmfInfo->tai_range_list; - OpenAPI_list_for_each(TaiRangeList, node2) { - TaiRangeItem = node2->data; - ogs_assert(TaiRangeItem); - - if (TaiRangeItem->plmn_id) - ogs_sbi_free_plmn_id(TaiRangeItem->plmn_id); - - TacRangeList = TaiRangeItem->tac_range_list; - OpenAPI_list_for_each(TacRangeList, node3) { - TacRangeItem = node3->data; - ogs_assert(TacRangeItem); - if (TacRangeItem->start) - ogs_free(TacRangeItem->start); - if (TacRangeItem->end) - ogs_free(TacRangeItem->end); - - ogs_free(TacRangeItem); - } - OpenAPI_list_free(TacRangeList); - - ogs_free(TaiRangeItem); - } - OpenAPI_list_free(TaiRangeList); - - ogs_free(SmfInfo); - } - if (SmfInfoMap->key) - ogs_free(SmfInfoMap->key); - ogs_free(SmfInfoMap); - } - } - OpenAPI_list_free(SmfInfoList); - - return request; -} diff --git a/src/smf/nnrf-build.h b/src/smf/nnrf-build.h deleted file mode 100644 index 5c12726cf..000000000 --- a/src/smf/nnrf-build.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2019,2020 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef SMF_NNRF_BUILD_H -#define SMF_NNRF_BUILD_H - -#include "context.h" - -#ifdef __cplusplus -extern "C" { -#endif - -ogs_sbi_request_t *smf_nnrf_nfm_build_register(void); - -#ifdef __cplusplus -} -#endif - -#endif /* SMF_NNRF_BUILD_H */ diff --git a/src/smf/nnrf-handler.c b/src/smf/nnrf-handler.c index ffa98322b..347757a84 100644 --- a/src/smf/nnrf-handler.c +++ b/src/smf/nnrf-handler.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -20,244 +20,14 @@ #include "sbi-path.h" #include "nnrf-handler.h" -void smf_nnrf_handle_nf_register( - ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_message_t *recvmsg) -{ - OpenAPI_nf_profile_t *NFProfile = NULL; - ogs_sbi_client_t *client = NULL; - - ogs_assert(recvmsg); - ogs_assert(nf_instance); - client = nf_instance->client; - ogs_assert(client); - - NFProfile = recvmsg->NFProfile; - if (!NFProfile) { - ogs_error("No NFProfile"); - return; - } - - /* TIME : Update heartbeat from NRF */ - if (NFProfile->is_heart_beat_timer == true) - nf_instance->time.heartbeat_interval = NFProfile->heart_beat_timer; -} - -void smf_nnrf_handle_nf_status_subscribe( - ogs_sbi_subscription_t *subscription, ogs_sbi_message_t *recvmsg) -{ - OpenAPI_subscription_data_t *SubscriptionData = NULL; - ogs_sbi_client_t *client = NULL; - - ogs_assert(recvmsg); - ogs_assert(subscription); - client = subscription->client; - ogs_assert(client); - - SubscriptionData = recvmsg->SubscriptionData; - if (!SubscriptionData) { - ogs_error("No SubscriptionData"); - return; - } - - if (!SubscriptionData->subscription_id) { - ogs_error("No SubscriptionId"); - return; - } - ogs_sbi_subscription_set_id( - subscription, SubscriptionData->subscription_id); - - if (SubscriptionData->validity_time) { -#define VALIDITY_MINIMUM (10LL * OGS_USEC_PER_SEC) /* 10 seconds */ - ogs_time_t time, duration; - if (ogs_sbi_time_from_string( - &time, SubscriptionData->validity_time) == true) { - duration = time - ogs_time_now(); - if (duration < VALIDITY_MINIMUM) { - duration = VALIDITY_MINIMUM; - ogs_warn("[%s] Forced to %lld seconds", subscription->id, - (long long)ogs_time_sec(VALIDITY_MINIMUM)); - } - subscription->t_validity = ogs_timer_add(ogs_app()->timer_mgr, - smf_timer_subscription_validity, subscription); - ogs_assert(subscription->t_validity); - ogs_timer_start(subscription->t_validity, duration); - } else { - ogs_error("Cannot parse validitiyTime [%s]", - SubscriptionData->validity_time); - } - } -} - -bool smf_nnrf_handle_nf_status_notify( - ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) -{ - int rv; - bool handled; - - ogs_sbi_response_t *response = NULL; - OpenAPI_notification_data_t *NotificationData = NULL; - ogs_sbi_nf_instance_t *nf_instance = NULL; - - ogs_sbi_message_t message; - ogs_sbi_header_t header; - - ogs_assert(stream); - ogs_assert(recvmsg); - - NotificationData = recvmsg->NotificationData; - if (!NotificationData) { - ogs_error("No NotificationData"); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "No NotificationData", NULL)); - return false; - } - - if (!NotificationData->nf_instance_uri) { - ogs_error("No nfInstanceUri"); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "No nfInstanceUri", NULL)); - return false; - } - - memset(&header, 0, sizeof(header)); - header.uri = NotificationData->nf_instance_uri; - - rv = ogs_sbi_parse_header(&message, &header); - if (rv != OGS_OK) { - ogs_error("Cannot parse nfInstanceUri [%s]", header.uri); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Cannot parse nfInstanceUri", header.uri)); - return false; - } - - if (!message.h.resource.component[1]) { - ogs_error("No nfInstanceId [%s]", header.uri); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Cannot parse nfInstanceUri", header.uri)); - ogs_sbi_header_free(&header); - return false; - } - - if (NF_INSTANCE_IS_SELF(message.h.resource.component[1])) { - ogs_warn("[%s] The notification is not allowed", - message.h.resource.component[1]); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, - recvmsg, "The notification is not allowed", - message.h.resource.component[1])); - ogs_sbi_header_free(&header); - return false; - } - - if (NotificationData->event == - OpenAPI_notification_event_type_NF_REGISTERED) { - - OpenAPI_nf_profile_t *NFProfile = NULL; - - NFProfile = NotificationData->nf_profile; - if (!NFProfile) { - ogs_error("No NFProfile"); - ogs_assert(true == - ogs_sbi_server_send_error( - stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "No NFProfile", NULL)); - ogs_sbi_header_free(&header); - return false; - } - - nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); - if (!nf_instance) { - 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); - - ogs_info("[%s] (NRF-notify) NF registered", nf_instance->id); - - } else { - OGS_FSM_TRAN(&nf_instance->sm, smf_nf_state_registered); - ogs_fsm_dispatch(&nf_instance->sm, NULL); - - ogs_warn("[%s] (NRF-notify) NF has already been added", - message.h.resource.component[1]); - - } - - handled = ogs_sbi_nnrf_handle_nf_profile( - nf_instance, NFProfile, stream, recvmsg); - if (!handled) { - SMF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); - ogs_sbi_header_free(&header); - return false; - } - - ogs_info("[%s] (NRF-notify) NF Profile updated", nf_instance->id); - - handled = ogs_sbi_client_associate(nf_instance); - if (!handled) { - ogs_error("[%s] Cannot associate NF EndPoint", nf_instance->id); - ogs_assert(true == - ogs_sbi_server_send_error(stream, - OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Cannot find NF EndPoint", nf_instance->id)); - SMF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); - ogs_sbi_header_free(&header); - return false; - } - - } else if (NotificationData->event == - OpenAPI_notification_event_type_NF_DEREGISTERED) { - nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); - if (nf_instance) { - SMF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); - } else { - ogs_warn("[%s] (NRF-notify) Not found", - message.h.resource.component[1]); - ogs_assert(true == - ogs_sbi_server_send_error(stream, - OGS_SBI_HTTP_STATUS_NOT_FOUND, - recvmsg, "Not found", message.h.resource.component[1])); - ogs_sbi_header_free(&header); - return false; - } - } else { - char *eventstr = OpenAPI_notification_event_type_ToString( - NotificationData->event); - ogs_error("Not supported event [%d:%s]", - NotificationData->event, eventstr ? eventstr : "Unknown"); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Not supported event", - eventstr ? eventstr : "Unknown")); - ogs_sbi_header_free(&header); - return false; - } - - response = ogs_sbi_build_response(recvmsg, OGS_SBI_HTTP_STATUS_NO_CONTENT); - ogs_assert(response); - ogs_assert(true == ogs_sbi_server_send_response(stream, response)); - - ogs_sbi_header_free(&header); - return true; -} - void smf_nnrf_handle_nf_discover( ogs_sbi_xact_t *xact, ogs_sbi_message_t *recvmsg) { ogs_sbi_object_t *sbi_object = NULL; OpenAPI_nf_type_e target_nf_type = 0; ogs_sbi_discovery_option_t *discovery_option = NULL; - ogs_sbi_nf_instance_t *nf_instance = NULL; OpenAPI_search_result_t *SearchResult = NULL; - OpenAPI_lnode_t *node = NULL; - bool handled; ogs_assert(recvmsg); ogs_assert(xact); @@ -274,64 +44,8 @@ void smf_nnrf_handle_nf_discover( return; } - OpenAPI_list_for_each(SearchResult->nf_instances, node) { - OpenAPI_nf_profile_t *NFProfile = NULL; - - if (!node->data) continue; - - NFProfile = node->data; - - nf_instance = ogs_sbi_nf_instance_find(NFProfile->nf_instance_id); - if (!nf_instance) { - 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); - - ogs_info("[%s] (NF-discover) NF registered", nf_instance->id); - } else { - OGS_FSM_TRAN(&nf_instance->sm, smf_nf_state_registered); - ogs_fsm_dispatch(&nf_instance->sm, NULL); - - ogs_warn("[%s] (NF-discover) NF has already been added", - NFProfile->nf_instance_id); - } - - if (NF_INSTANCE_IS_OTHERS(nf_instance->id)) { - handled = ogs_sbi_nnrf_handle_nf_profile( - nf_instance, NFProfile, NULL, NULL); - if (!handled) { - ogs_error("ogs_sbi_nnrf_handle_nf_profile() failed [%s]", - nf_instance->id); - SMF_NF_INSTANCE_CLEAR("NRF-discover", nf_instance); - continue; - } - - handled = ogs_sbi_client_associate(nf_instance); - if (!handled) { - ogs_error("[%s] Cannot assciate NF EndPoint", nf_instance->id); - SMF_NF_INSTANCE_CLEAR("NRF-discover", nf_instance); - continue; - } - - /* TIME : Update validity from NRF */ - if (SearchResult->is_validity_period && - SearchResult->validity_period) { - nf_instance->time.validity_duration = - SearchResult->validity_period; - - ogs_assert(nf_instance->t_validity); - ogs_timer_start(nf_instance->t_validity, - ogs_time_from_sec(nf_instance->time.validity_duration)); - - } else - ogs_warn("[%s] NF Instance validity-time should not 0", - nf_instance->id); - - ogs_info("[%s] (NF-discover) NF Profile updated", nf_instance->id); - } - } + ogs_nnrf_handle_nf_discover_search_result( + sbi_object, target_nf_type, discovery_option, SearchResult); ogs_sbi_select_nf(sbi_object, target_nf_type, discovery_option); diff --git a/src/smf/nnrf-handler.h b/src/smf/nnrf-handler.h index 431b6c933..33d16348b 100644 --- a/src/smf/nnrf-handler.h +++ b/src/smf/nnrf-handler.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -26,14 +26,6 @@ extern "C" { #endif -void smf_nnrf_handle_nf_register( - ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_message_t *recvmsg); -void smf_nnrf_handle_nf_status_subscribe( - ogs_sbi_subscription_t *subscription, ogs_sbi_message_t *recvmsg); - -bool smf_nnrf_handle_nf_status_notify( - ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); - void smf_nnrf_handle_nf_discover( ogs_sbi_xact_t *xact, ogs_sbi_message_t *recvmsg); diff --git a/src/smf/pfcp-path.c b/src/smf/pfcp-path.c index 94323b8bf..e122513aa 100644 --- a/src/smf/pfcp-path.c +++ b/src/smf/pfcp-path.c @@ -74,8 +74,7 @@ static void pfcp_node_fsm_init(ogs_pfcp_node_t *node, bool try_to_assoicate) ogs_assert(node->t_association); } - ogs_fsm_create(&node->sm, smf_pfcp_state_initial, smf_pfcp_state_final); - ogs_fsm_init(&node->sm, &e); + ogs_fsm_init(&node->sm, smf_pfcp_state_initial, smf_pfcp_state_final, &e); } static void pfcp_node_fsm_fini(ogs_pfcp_node_t *node) @@ -88,7 +87,6 @@ static void pfcp_node_fsm_fini(ogs_pfcp_node_t *node) e.pfcp_node = node; ogs_fsm_fini(&node->sm, &e); - ogs_fsm_delete(&node->sm); if (node->t_association) ogs_timer_delete(node->t_association); @@ -159,7 +157,7 @@ static void pfcp_recv_cb(short when, ogs_socket_t fd, void *data) if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed:%d", (int)rv); ogs_pkbuf_free(e->pkbuf); - smf_event_free(e); + ogs_event_free(e); } } diff --git a/src/smf/pfcp-sm.c b/src/smf/pfcp-sm.c index c51394bdc..de2fdd4a1 100644 --- a/src/smf/pfcp-sm.c +++ b/src/smf/pfcp-sm.c @@ -82,7 +82,7 @@ void smf_pfcp_state_will_associate(ogs_fsm_t *s, smf_event_t *e) addr = node->sa_list; ogs_assert(addr); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: if (node->t_association) { ogs_timer_start(node->t_association, @@ -99,7 +99,7 @@ void smf_pfcp_state_will_associate(ogs_fsm_t *s, smf_event_t *e) break; case SMF_EVT_N4_TIMER: - switch(e->timer_id) { + switch(e->h.timer_id) { case SMF_TIMER_PFCP_ASSOCIATION: node = e->pfcp_node; ogs_assert(node); @@ -115,7 +115,7 @@ void smf_pfcp_state_will_associate(ogs_fsm_t *s, smf_event_t *e) break; default: ogs_error("Unknown timer[%s:%d]", - smf_timer_get_name(e->timer_id), e->timer_id); + smf_timer_get_name(e->h.timer_id), e->h.timer_id); break; } break; @@ -169,7 +169,7 @@ void smf_pfcp_state_associated(ogs_fsm_t *s, smf_event_t *e) addr = node->sa_list; ogs_assert(addr); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: ogs_info("PFCP associated"); ogs_timer_start(node->t_no_heartbeat, @@ -290,7 +290,7 @@ void smf_pfcp_state_associated(ogs_fsm_t *s, smf_event_t *e) break; case SMF_EVT_N4_TIMER: - switch(e->timer_id) { + switch(e->h.timer_id) { case SMF_TIMER_PFCP_NO_HEARTBEAT: node = e->pfcp_node; ogs_assert(node); @@ -300,7 +300,7 @@ void smf_pfcp_state_associated(ogs_fsm_t *s, smf_event_t *e) break; default: ogs_error("Unknown timer[%s:%d]", - smf_timer_get_name(e->timer_id), e->timer_id); + smf_timer_get_name(e->h.timer_id), e->h.timer_id); break; } break; @@ -322,7 +322,7 @@ void smf_pfcp_state_exception(ogs_fsm_t *s, smf_event_t *e) smf_sm_debug(e); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: break; case OGS_FSM_EXIT_SIG: @@ -353,7 +353,7 @@ static void node_timeout(ogs_pfcp_xact_t *xact, void *data) rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed:%d", (int)rv); - smf_event_free(e); + ogs_event_free(e); } break; case OGS_PFCP_ASSOCIATION_SETUP_REQUEST_TYPE: diff --git a/src/smf/s6b-path.c b/src/smf/s6b-path.c index fdd9922ae..91f5c1706 100644 --- a/src/smf/s6b-path.c +++ b/src/smf/s6b-path.c @@ -714,7 +714,7 @@ static void smf_s6b_sta_cb(void *data, struct msg **msg) if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed:%d", (int)rv); ogs_free(s6b_message); - smf_event_free(e); + ogs_event_free(e); } else { ogs_pollset_notify(ogs_app()->pollset); } diff --git a/src/smf/sbi-path.c b/src/smf/sbi-path.c index 935f2251b..b914d3647 100644 --- a/src/smf/sbi-path.c +++ b/src/smf/sbi-path.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -29,17 +29,17 @@ static int server_cb(ogs_sbi_request_t *request, void *data) ogs_assert(request); ogs_assert(data); - e = smf_event_new(SMF_EVT_SBI_SERVER); + e = smf_event_new(OGS_EVENT_SBI_SERVER); ogs_assert(e); - e->sbi.request = request; - e->sbi.data = data; + e->h.sbi.request = request; + e->h.sbi.data = data; rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed:%d", (int)rv); ogs_sbi_request_free(request); - smf_event_free(e); + ogs_event_free(e); return OGS_ERROR; } @@ -60,16 +60,16 @@ static int client_cb(int status, ogs_sbi_response_t *response, void *data) ogs_assert(response); - e = smf_event_new(SMF_EVT_SBI_CLIENT); + e = smf_event_new(OGS_EVENT_SBI_CLIENT); ogs_assert(e); - e->sbi.response = response; - e->sbi.data = data; + e->h.sbi.response = response; + e->h.sbi.data = data; rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed:%d", (int)rv); ogs_sbi_response_free(response); - smf_event_free(e); + ogs_event_free(e); return OGS_ERROR; } @@ -81,6 +81,13 @@ int smf_sbi_open(void) ogs_sbi_nf_instance_t *nf_instance = NULL; ogs_sbi_nf_service_t *service = NULL; + /* To be notified when NF Instances registered/deregistered in NRF + * or when their profile is modified */ + ogs_sbi_add_to_be_notified_nf_type(OpenAPI_nf_type_AMF); + ogs_sbi_add_to_be_notified_nf_type(OpenAPI_nf_type_PCF); + ogs_sbi_add_to_be_notified_nf_type(OpenAPI_nf_type_UDM); + ogs_sbi_add_to_be_notified_nf_type(OpenAPI_nf_type_UPF); + /* Add SELF NF instance */ nf_instance = ogs_sbi_self()->nf_instance; ogs_assert(nf_instance); @@ -100,28 +107,20 @@ int smf_sbi_open(void) } /* Initialize NRF NF Instance */ - ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) { - if (NF_INSTANCE_IS_NRF(nf_instance)) { - ogs_sbi_client_t *client = NULL; + nf_instance = ogs_sbi_self()->nrf_instance; + if (nf_instance) { + ogs_sbi_client_t *client = NULL; - /* Client callback is only used when NF sends to NRF */ - client = nf_instance->client; - ogs_assert(client); - client->cb = client_cb; + /* 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. */ + ogs_sbi_nf_fsm_init(nf_instance); } - /* Timer expiration handler of client wait timer */ - ogs_sbi_self()->client_wait_expire = smf_timer_sbi_client_wait_expire; - - /* NF register state in NF state machine */ - ogs_sbi_self()->nf_state_registered = - (ogs_fsm_handler_t)smf_nf_state_registered; - if (ogs_sbi_server_start_all(server_cb) != OGS_OK) return OGS_ERROR; diff --git a/src/smf/sbi-path.h b/src/smf/sbi-path.h index 46124c47d..364307d3a 100644 --- a/src/smf/sbi-path.h +++ b/src/smf/sbi-path.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -20,7 +20,6 @@ #ifndef SMF_SBI_PATH_H #define SMF_SBI_PATH_H -#include "nnrf-build.h" #include "nudm-build.h" #include "namf-build.h" #include "gsm-build.h" diff --git a/src/smf/smf-sm.c b/src/smf/smf-sm.c index f3ae98f32..c427ed88d 100644 --- a/src/smf/smf-sm.c +++ b/src/smf/smf-sm.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -84,7 +84,7 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) ogs_assert(s); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: break; @@ -418,10 +418,10 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) ogs_fsm_dispatch(&pfcp_node->sm, e); break; - case SMF_EVT_SBI_SERVER: - sbi_request = e->sbi.request; + case OGS_EVENT_SBI_SERVER: + sbi_request = e->h.sbi.request; ogs_assert(sbi_request); - stream = e->sbi.data; + stream = e->h.sbi.data; ogs_assert(stream); rv = ogs_sbi_parse_request(&sbi_message, sbi_request); @@ -461,7 +461,7 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) CASE(OGS_SBI_RESOURCE_NAME_NF_STATUS_NOTIFY) SWITCH(sbi_message.h.method) CASE(OGS_SBI_HTTP_METHOD_POST) - smf_nnrf_handle_nf_status_notify(stream, &sbi_message); + ogs_nnrf_handle_nf_status_notify(stream, &sbi_message); break; DEFAULT @@ -535,7 +535,7 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) ogs_assert(OGS_FSM_STATE(&sess->sm)); e->sess = sess; - e->sbi.message = &sbi_message; + e->h.sbi.message = &sbi_message; ogs_fsm_dispatch(&sess->sm, e); } break; @@ -624,10 +624,10 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) ogs_sbi_message_free(&sbi_message); break; - case SMF_EVT_SBI_CLIENT: + case OGS_EVENT_SBI_CLIENT: ogs_assert(e); - sbi_response = e->sbi.response; + sbi_response = e->h.sbi.response; ogs_assert(sbi_response); rv = ogs_sbi_parse_response(&sbi_message, sbi_response); if (rv != OGS_OK) { @@ -658,23 +658,23 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) SWITCH(sbi_message.h.resource.component[0]) CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - nf_instance = e->sbi.data; + nf_instance = e->h.sbi.data; ogs_assert(nf_instance); ogs_assert(OGS_FSM_STATE(&nf_instance->sm)); - e->sbi.message = &sbi_message; + e->h.sbi.message = &sbi_message; ogs_fsm_dispatch(&nf_instance->sm, e); break; CASE(OGS_SBI_RESOURCE_NAME_SUBSCRIPTIONS) - subscription = e->sbi.data; + subscription = e->h.sbi.data; ogs_assert(subscription); SWITCH(sbi_message.h.method) CASE(OGS_SBI_HTTP_METHOD_POST) if (sbi_message.res_status == OGS_SBI_HTTP_STATUS_CREATED || sbi_message.res_status == OGS_SBI_HTTP_STATUS_OK) { - smf_nnrf_handle_nf_status_subscribe( + ogs_nnrf_handle_nf_status_subscribe( subscription, &sbi_message); } else { ogs_error("HTTP response error : %d", @@ -708,7 +708,7 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) CASE(OGS_SBI_SERVICE_NAME_NNRF_DISC) SWITCH(sbi_message.h.resource.component[0]) CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - sbi_xact = e->sbi.data; + sbi_xact = e->h.sbi.data; ogs_assert(sbi_xact); SWITCH(sbi_message.h.method) @@ -736,7 +736,7 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) CASE(OGS_SBI_SERVICE_NAME_NUDM_SDM) CASE(OGS_SBI_SERVICE_NAME_NPCF_SMPOLICYCONTROL) CASE(OGS_SBI_SERVICE_NAME_NAMF_COMM) - sbi_xact = e->sbi.data; + sbi_xact = e->h.sbi.data; ogs_assert(sbi_xact); sbi_xact = ogs_sbi_xact_cycle(sbi_xact); @@ -750,8 +750,8 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) sess = (smf_sess_t *)sbi_xact->sbi_object; ogs_assert(sess); - e->sbi.data = sbi_xact->assoc_stream; - e->sbi.state = sbi_xact->state; + e->h.sbi.data = sbi_xact->assoc_stream; + e->h.sbi.state = sbi_xact->state; ogs_sbi_xact_remove(sbi_xact); @@ -767,7 +767,7 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) ogs_assert(OGS_FSM_STATE(&sess->sm)); e->sess = sess; - e->sbi.message = &sbi_message; + e->h.sbi.message = &sbi_message; ogs_fsm_dispatch(&sess->sm, e); break; @@ -781,27 +781,27 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) ogs_sbi_response_free(sbi_response); break; - case SMF_EVT_SBI_TIMER: + case OGS_EVENT_SBI_TIMER: ogs_assert(e); - switch(e->timer_id) { - case SMF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - case SMF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - case SMF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - case SMF_TIMER_NF_INSTANCE_VALIDITY: - nf_instance = e->sbi.data; + switch(e->h.timer_id) { + case OGS_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: + case OGS_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: + case OGS_TIMER_NF_INSTANCE_NO_HEARTBEAT: + case OGS_TIMER_NF_INSTANCE_VALIDITY: + nf_instance = e->h.sbi.data; ogs_assert(nf_instance); ogs_assert(OGS_FSM_STATE(&nf_instance->sm)); ogs_fsm_dispatch(&nf_instance->sm, e); - if (OGS_FSM_CHECK(&nf_instance->sm, smf_nf_state_exception)) + if (OGS_FSM_CHECK(&nf_instance->sm, ogs_sbi_nf_state_exception)) ogs_error("[%s:%s] State machine exception [%d]", OpenAPI_nf_type_ToString(nf_instance->nf_type), - nf_instance->id, e->timer_id); + nf_instance->id, e->h.timer_id); break; - case SMF_TIMER_SUBSCRIPTION_VALIDITY: - subscription = e->sbi.data; + case OGS_TIMER_SUBSCRIPTION_VALIDITY: + subscription = e->h.sbi.data; ogs_assert(subscription); ogs_assert(ogs_sbi_self()->nf_instance); @@ -815,8 +815,8 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) ogs_sbi_subscription_remove(subscription); break; - case SMF_TIMER_SBI_CLIENT_WAIT: - sbi_xact = e->sbi.data; + case OGS_TIMER_SBI_CLIENT_WAIT: + sbi_xact = e->h.sbi.data; ogs_assert(sbi_xact); stream = sbi_xact->assoc_stream; @@ -836,14 +836,14 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) default: ogs_error("Unknown timer[%s:%d]", - smf_timer_get_name(e->timer_id), e->timer_id); + ogs_timer_get_name(e->h.timer_id), e->h.timer_id); } break; case SMF_EVT_5GSM_MESSAGE: sess = e->sess; ogs_assert(sess); - stream = e->sbi.data; + stream = e->h.sbi.data; ogs_assert(stream); pkbuf = e->pkbuf; ogs_assert(pkbuf); @@ -868,7 +868,7 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) case SMF_EVT_NGAP_MESSAGE: sess = e->sess; ogs_assert(sess); - stream = e->sbi.data; + stream = e->h.sbi.data; ogs_assert(stream); pkbuf = e->pkbuf; ogs_assert(pkbuf); diff --git a/src/smf/smf-sm.h b/src/smf/smf-sm.h index 68dffdd7a..caedd356c 100644 --- a/src/smf/smf-sm.h +++ b/src/smf/smf-sm.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -31,16 +31,6 @@ void smf_state_final(ogs_fsm_t *s, smf_event_t *e); void smf_state_operational(ogs_fsm_t *s, smf_event_t *e); void smf_state_exception(ogs_fsm_t *s, smf_event_t *e); -void smf_nf_fsm_init(ogs_sbi_nf_instance_t *nf_instance); -void smf_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance); - -void smf_nf_state_initial(ogs_fsm_t *s, smf_event_t *e); -void smf_nf_state_final(ogs_fsm_t *s, smf_event_t *e); -void smf_nf_state_will_register(ogs_fsm_t *s, smf_event_t *e); -void smf_nf_state_registered(ogs_fsm_t *s, smf_event_t *e); -void smf_nf_state_de_registered(ogs_fsm_t *s, smf_event_t *e); -void smf_nf_state_exception(ogs_fsm_t *s, smf_event_t *e); - void smf_gsm_state_initial(ogs_fsm_t *s, smf_event_t *e); void smf_gsm_state_final(ogs_fsm_t *s, smf_event_t *e); void smf_gsm_state_wait_epc_auth_initial(ogs_fsm_t *s, smf_event_t *e); diff --git a/src/smf/timer.c b/src/smf/timer.c index 1e475396d..f9a94e102 100644 --- a/src/smf/timer.c +++ b/src/smf/timer.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -17,33 +17,32 @@ * along with this program. If not, see . */ -#include "timer.h" -#include "event.h" #include "context.h" -const char *smf_timer_get_name(smf_timer_e id) +const char *smf_timer_get_name(int timer_id) { - switch (id) { + switch (timer_id) { + case OGS_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: + return OGS_TIMER_NAME_NF_INSTANCE_REGISTRATION_INTERVAL; + case OGS_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: + return OGS_TIMER_NAME_NF_INSTANCE_HEARTBEAT_INTERVAL; + case OGS_TIMER_NF_INSTANCE_NO_HEARTBEAT: + return OGS_TIMER_NAME_NF_INSTANCE_NO_HEARTBEAT; + case OGS_TIMER_NF_INSTANCE_VALIDITY: + return OGS_TIMER_NAME_NF_INSTANCE_VALIDITY; + case OGS_TIMER_SUBSCRIPTION_VALIDITY: + return OGS_TIMER_NAME_SUBSCRIPTION_VALIDITY; + case OGS_TIMER_SBI_CLIENT_WAIT: + return OGS_TIMER_NAME_SBI_CLIENT_WAIT; case SMF_TIMER_PFCP_ASSOCIATION: return "SMF_TIMER_PFCP_ASSOCIATION"; case SMF_TIMER_PFCP_NO_HEARTBEAT: return "SMF_TIMER_PFCP_NO_HEARTBEAT"; - case SMF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - return "SMF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL"; - case SMF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - return "SMF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL"; - case SMF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - return "SMF_TIMER_NF_INSTANCE_NO_HEARTBEAT"; - case SMF_TIMER_NF_INSTANCE_VALIDITY: - return "SMF_TIMER_NF_INSTANCE_VALIDITY"; - case SMF_TIMER_SUBSCRIPTION_VALIDITY: - return "SMF_TIMER_SUBSCRIPTION_VALIDITY"; - case SMF_TIMER_SBI_CLIENT_WAIT: - return "SMF_TIMER_SBI_CLIENT_WAIT"; default: break; } + ogs_error("Unknown Timer[%d]", timer_id); return "UNKNOWN_TIMER"; } @@ -58,32 +57,9 @@ static void timer_send_event(int timer_id, void *data) case SMF_TIMER_PFCP_NO_HEARTBEAT: e = smf_event_new(SMF_EVT_N4_TIMER); ogs_assert(e); - e->timer_id = timer_id; + e->h.timer_id = timer_id; e->pfcp_node = data; break; - case SMF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - case SMF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - case SMF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - case SMF_TIMER_NF_INSTANCE_VALIDITY: - case SMF_TIMER_SUBSCRIPTION_VALIDITY: - e = smf_event_new(SMF_EVT_SBI_TIMER); - ogs_assert(e); - e->timer_id = timer_id; - e->sbi.data = data; - break; - case SMF_TIMER_SBI_CLIENT_WAIT: - e = smf_event_new(SMF_EVT_SBI_TIMER); - if (!e) { - ogs_sbi_xact_t *sbi_xact = data; - ogs_assert(sbi_xact); - - ogs_error("timer_send_event() failed"); - ogs_sbi_xact_remove(sbi_xact); - return; - } - e->timer_id = timer_id; - e->sbi.data = data; - break; default: ogs_fatal("Unknown timer id[%d]", timer_id); ogs_assert_if_reached(); @@ -93,8 +69,8 @@ static void timer_send_event(int timer_id, void *data) rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed [%d] in %s", - (int)rv, smf_timer_get_name(e->timer_id)); - smf_event_free(e); + (int)rv, smf_timer_get_name(timer_id)); + ogs_event_free(e); } } @@ -107,33 +83,3 @@ void smf_timer_pfcp_no_heartbeat(void *data) { timer_send_event(SMF_TIMER_PFCP_NO_HEARTBEAT, data); } - -void smf_timer_nf_instance_registration_interval(void *data) -{ - timer_send_event(SMF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL, data); -} - -void smf_timer_nf_instance_heartbeat_interval(void *data) -{ - timer_send_event(SMF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL, data); -} - -void smf_timer_nf_instance_no_heartbeat(void *data) -{ - timer_send_event(SMF_TIMER_NF_INSTANCE_NO_HEARTBEAT, data); -} - -void smf_timer_nf_instance_validity(void *data) -{ - timer_send_event(SMF_TIMER_NF_INSTANCE_VALIDITY, data); -} - -void smf_timer_subscription_validity(void *data) -{ - timer_send_event(SMF_TIMER_SUBSCRIPTION_VALIDITY, data); -} - -void smf_timer_sbi_client_wait_expire(void *data) -{ - timer_send_event(SMF_TIMER_SBI_CLIENT_WAIT, data); -} diff --git a/src/smf/timer.h b/src/smf/timer.h index bf0f76b94..3eae8e3f6 100644 --- a/src/smf/timer.h +++ b/src/smf/timer.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -20,7 +20,7 @@ #ifndef SMF_TIMER_H #define SMF_TIMER_H -#include "ogs-core.h" +#include "ogs-proto.h" #ifdef __cplusplus extern "C" { @@ -28,34 +28,20 @@ extern "C" { /* forward declaration */ typedef enum { - SMF_TIMER_BASE = 0, + SMF_TIMER_BASE = OGS_MAX_NUM_OF_PROTO_TIMER, SMF_TIMER_PFCP_ASSOCIATION, SMF_TIMER_PFCP_NO_HEARTBEAT, - SMF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL, - SMF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL, - SMF_TIMER_NF_INSTANCE_NO_HEARTBEAT, - SMF_TIMER_NF_INSTANCE_VALIDITY, - SMF_TIMER_SUBSCRIPTION_VALIDITY, - SMF_TIMER_SBI_CLIENT_WAIT, - MAX_NUM_OF_SMF_TIMER, } smf_timer_e; -const char *smf_timer_get_name(smf_timer_e id); +const char *smf_timer_get_name(int timer_id); void smf_timer_pfcp_association(void *data); void smf_timer_pfcp_no_heartbeat(void *data); -void smf_timer_nf_instance_registration_interval(void *data); -void smf_timer_nf_instance_heartbeat_interval(void *data); -void smf_timer_nf_instance_no_heartbeat(void *data); -void smf_timer_nf_instance_validity(void *data); -void smf_timer_subscription_validity(void *data); -void smf_timer_sbi_client_wait_expire(void *data); - #ifdef __cplusplus } #endif diff --git a/src/udm/context.c b/src/udm/context.c index 675eddd78..3698337a5 100644 --- a/src/udm/context.c +++ b/src/udm/context.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -141,8 +141,7 @@ udm_ue_t *udm_ue_add(char *suci) memset(&e, 0, sizeof(e)); e.udm_ue = udm_ue; - ogs_fsm_create(&udm_ue->sm, udm_ue_state_initial, udm_ue_state_final); - ogs_fsm_init(&udm_ue->sm, &e); + ogs_fsm_init(&udm_ue->sm, udm_ue_state_initial, udm_ue_state_final, &e); ogs_list_add(&self.udm_ue_list, udm_ue); @@ -160,7 +159,6 @@ void udm_ue_remove(udm_ue_t *udm_ue) memset(&e, 0, sizeof(e)); e.udm_ue = udm_ue; ogs_fsm_fini(&udm_ue->sm, &e); - ogs_fsm_delete(&udm_ue->sm); /* Free SBI object memory */ ogs_sbi_object_free(&udm_ue->sbi); diff --git a/src/udm/context.h b/src/udm/context.h index f4780e920..0c675a36c 100644 --- a/src/udm/context.h +++ b/src/udm/context.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -25,7 +25,6 @@ #include "ogs-sbi.h" #include "udm-sm.h" -#include "timer.h" #ifdef __cplusplus extern "C" { @@ -72,22 +71,6 @@ struct udm_ue_s { OpenAPI_auth_type_e auth_type; OpenAPI_rat_type_e rat_type; - -#define UDM_NF_INSTANCE_CLEAR(_cAUSE, _nFInstance) \ - do { \ - ogs_assert(_nFInstance); \ - if ((_nFInstance)->reference_count == 1) { \ - ogs_info("[%s] (%s) NF removed", (_nFInstance)->id, (_cAUSE)); \ - udm_nf_fsm_fini((_nFInstance)); \ - ogs_sbi_nf_instance_remove(_nFInstance); \ - } else { \ - /* There is an assocation with other context */ \ - ogs_info("[%s:%d] (%s) NF suspended", \ - _nFInstance->id, _nFInstance->reference_count, (_cAUSE)); \ - OGS_FSM_TRAN(&_nFInstance->sm, udm_nf_state_de_registered); \ - ogs_fsm_dispatch(&_nFInstance->sm, NULL); \ - } \ - } while(0) }; void udm_context_init(void); diff --git a/src/udm/event.c b/src/udm/event.c index ad2376683..e4b7ca45f 100644 --- a/src/udm/event.c +++ b/src/udm/event.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -18,60 +18,41 @@ */ #include "event.h" -#include "context.h" -static OGS_POOL(pool, udm_event_t); - -void udm_event_init(void) -{ - ogs_pool_init(&pool, ogs_app()->pool.event); -} - -void udm_event_final(void) -{ - ogs_pool_final(&pool); -} - -udm_event_t *udm_event_new(udm_event_e id) +udm_event_t *udm_event_new(int id) { udm_event_t *e = NULL; - ogs_pool_alloc(&pool, &e); + e = ogs_event_size(id, sizeof(udm_event_t)); ogs_assert(e); - memset(e, 0, sizeof(*e)); - e->id = id; + e->h.id = id; return e; } -void udm_event_free(udm_event_t *e) -{ - ogs_assert(e); - ogs_pool_free(&pool, e); -} - const char *udm_event_get_name(udm_event_t *e) { if (e == NULL) return OGS_FSM_NAME_INIT_SIG; - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: return OGS_FSM_NAME_ENTRY_SIG; case OGS_FSM_EXIT_SIG: return OGS_FSM_NAME_EXIT_SIG; - case UDM_EVT_SBI_SERVER: - return "UDM_EVT_SBI_SERVER"; - case UDM_EVT_SBI_CLIENT: - return "UDM_EVT_SBI_CLIENT"; - case UDM_EVT_SBI_TIMER: - return "UDM_EVT_SBI_TIMER"; + case OGS_EVENT_SBI_SERVER: + return OGS_EVENT_NAME_SBI_SERVER; + case OGS_EVENT_SBI_CLIENT: + return OGS_EVENT_NAME_SBI_CLIENT; + case OGS_EVENT_SBI_TIMER: + return OGS_EVENT_NAME_SBI_TIMER; default: break; } + ogs_error("Unknown Event[%d]", e->h.id); return "UNKNOWN_EVENT"; } diff --git a/src/udm/event.h b/src/udm/event.h index 5d24a9650..b9e03d60d 100644 --- a/src/udm/event.h +++ b/src/udm/event.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -20,53 +20,21 @@ #ifndef UDM_EVENT_H #define UDM_EVENT_H -#include "ogs-core.h" +#include "ogs-proto.h" #ifdef __cplusplus extern "C" { #endif -typedef struct ogs_sbi_request_s ogs_sbi_request_t; -typedef struct ogs_sbi_response_s ogs_sbi_response_t; -typedef struct ogs_sbi_message_s ogs_sbi_message_t; -typedef struct ogs_sbi_nf_instance_s ogs_sbi_nf_instance_t; -typedef struct ogs_sbi_subscription_s ogs_sbi_subscription_t; - typedef struct udm_ue_s udm_ue_t; -typedef enum { - UDM_EVT_BASE = OGS_FSM_USER_SIG, - - UDM_EVT_SBI_SERVER, - UDM_EVT_SBI_CLIENT, - UDM_EVT_SBI_TIMER, - - UDM_EVT_TOP, - -} udm_event_e; - typedef struct udm_event_s { - int id; - int timer_id; - - struct { - ogs_sbi_request_t *request; - ogs_sbi_response_t *response; - void *data; - - ogs_sbi_message_t *message; - } sbi; + ogs_event_t h; udm_ue_t *udm_ue; - - ogs_timer_t *timer; } udm_event_t; -void udm_event_init(void); -void udm_event_final(void); - -udm_event_t *udm_event_new(udm_event_e id); -void udm_event_free(udm_event_t *e); +udm_event_t *udm_event_new(int id); const char *udm_event_get_name(udm_event_t *e); diff --git a/src/udm/init.c b/src/udm/init.c index f48f26804..2cb9cc941 100644 --- a/src/udm/init.c +++ b/src/udm/init.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -30,7 +30,6 @@ int udm_initialize() ogs_sbi_context_init(); udm_context_init(); - udm_event_init(); rv = ogs_sbi_context_parse_config("udm", "nrf", "scp"); if (rv != OGS_OK) return rv; @@ -61,7 +60,7 @@ static void event_termination(void) /* Sending NF Instance De-registeration to NRF */ ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) - udm_nf_fsm_fini(nf_instance); + ogs_sbi_nf_fsm_fini(nf_instance); /* Starting holding timer */ t_termination_holding = ogs_timer_add(ogs_app()->timer_mgr, NULL, NULL); @@ -87,8 +86,6 @@ void udm_terminate(void) udm_context_final(); ogs_sbi_context_final(); - - udm_event_final(); /* Destroy event */ } static void udm_main(void *data) @@ -96,8 +93,7 @@ static void udm_main(void *data) ogs_fsm_t udm_sm; int rv; - ogs_fsm_create(&udm_sm, udm_state_initial, udm_state_final); - ogs_fsm_init(&udm_sm, 0); + ogs_fsm_init(&udm_sm, udm_state_initial, udm_state_final, 0); for ( ;; ) { ogs_pollset_poll(ogs_app()->pollset, @@ -130,11 +126,10 @@ static void udm_main(void *data) ogs_assert(e); ogs_fsm_dispatch(&udm_sm, e); - udm_event_free(e); + ogs_event_free(e); } } done: ogs_fsm_fini(&udm_sm, 0); - ogs_fsm_delete(&udm_sm); } diff --git a/src/udm/meson.build b/src/udm/meson.build index 33d8396d2..a2cce842c 100644 --- a/src/udm/meson.build +++ b/src/udm/meson.build @@ -1,4 +1,4 @@ -# Copyright (C) 2019,2020 by Sukchan Lee +# Copyright (C) 2019-2022 by Sukchan Lee # This file is part of Open5GS. @@ -18,12 +18,8 @@ libudm_sources = files(''' context.c event.c - timer.c - nnrf-build.c nnrf-handler.c - nf-sm.c - nudm-handler.c nudr-build.c diff --git a/src/udm/nf-sm.c b/src/udm/nf-sm.c deleted file mode 100644 index 6172fc558..000000000 --- a/src/udm/nf-sm.c +++ /dev/null @@ -1,447 +0,0 @@ -/* - * Copyright (C) 2019,2020 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "context.h" - -#include "sbi-path.h" -#include "nnrf-handler.h" - -void udm_nf_fsm_init(ogs_sbi_nf_instance_t *nf_instance) -{ - udm_event_t e; - - ogs_assert(nf_instance); - - memset(&e, 0, sizeof(e)); - e.sbi.data = nf_instance; - - ogs_fsm_create(&nf_instance->sm, - udm_nf_state_initial, udm_nf_state_final); - ogs_fsm_init(&nf_instance->sm, &e); -} - -void udm_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance) -{ - udm_event_t e; - - ogs_assert(nf_instance); - - memset(&e, 0, sizeof(e)); - e.sbi.data = nf_instance; - - ogs_fsm_fini(&nf_instance->sm, &e); - ogs_fsm_delete(&nf_instance->sm); -} - -void udm_nf_state_initial(ogs_fsm_t *s, udm_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - - ogs_assert(s); - ogs_assert(e); - - udm_sm_debug(e); - - nf_instance = e->sbi.data; - ogs_assert(nf_instance); - - nf_instance->t_registration_interval = ogs_timer_add(ogs_app()->timer_mgr, - udm_timer_nf_instance_registration_interval, nf_instance); - ogs_assert(nf_instance->t_registration_interval); - nf_instance->t_heartbeat_interval = ogs_timer_add(ogs_app()->timer_mgr, - udm_timer_nf_instance_heartbeat_interval, nf_instance); - ogs_assert(nf_instance->t_heartbeat_interval); - nf_instance->t_no_heartbeat = ogs_timer_add(ogs_app()->timer_mgr, - udm_timer_nf_instance_no_heartbeat, nf_instance); - ogs_assert(nf_instance->t_no_heartbeat); - nf_instance->t_validity = ogs_timer_add(ogs_app()->timer_mgr, - udm_timer_nf_instance_validity, nf_instance); - ogs_assert(nf_instance->t_validity); - - 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); - } -} - -void udm_nf_state_final(ogs_fsm_t *s, udm_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - - ogs_assert(s); - ogs_assert(e); - - udm_sm_debug(e); - - nf_instance = e->sbi.data; - ogs_assert(nf_instance); - - ogs_timer_delete(nf_instance->t_registration_interval); - ogs_timer_delete(nf_instance->t_heartbeat_interval); - ogs_timer_delete(nf_instance->t_no_heartbeat); - ogs_timer_delete(nf_instance->t_validity); -} - -void udm_nf_state_will_register(ogs_fsm_t *s, udm_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_sbi_client_t *client = NULL; - ogs_sbi_message_t *message = NULL; - ogs_sockaddr_t *addr = NULL; - - ogs_assert(s); - ogs_assert(e); - - udm_sm_debug(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: - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); - - ogs_assert(true == ogs_nnrf_nfm_send_nf_register( - nf_instance, udm_nnrf_nfm_build_register)); - break; - - case OGS_FSM_EXIT_SIG: - ogs_timer_stop(nf_instance->t_registration_interval); - break; - - case UDM_EVT_SBI_CLIENT: - message = e->sbi.message; - ogs_assert(message); - - SWITCH(message->h.service.name) - CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) - - SWITCH(message->h.resource.component[0]) - CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - - if (message->res_status == OGS_SBI_HTTP_STATUS_OK || - message->res_status == OGS_SBI_HTTP_STATUS_CREATED) { - udm_nnrf_handle_nf_register(nf_instance, message); - OGS_FSM_TRAN(s, &udm_nf_state_registered); - } else { - ogs_error("[%s] HTTP response error [%d]", - 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]", - ogs_sbi_self()->nf_instance->id, - message->h.resource.component[0]); - END - break; - - DEFAULT - ogs_error("[%s] Invalid API name [%s]", - ogs_sbi_self()->nf_instance->id, message->h.service.name); - END - break; - - case UDM_EVT_SBI_TIMER: - switch(e->timer_id) { - case UDM_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - client = nf_instance->client; - ogs_assert(client); - addr = client->node.addr; - ogs_assert(addr); - - ogs_warn("[%s] Retry to registration with NRF", - ogs_sbi_self()->nf_instance->id); - - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); - - ogs_assert(true == ogs_nnrf_nfm_send_nf_register( - nf_instance, udm_nnrf_nfm_build_register)); - break; - - default: - ogs_error("[%s] Unknown timer[%s:%d]", - ogs_sbi_self()->nf_instance->id, - udm_timer_get_name(e->timer_id), e->timer_id); - } - break; - - default: - ogs_error("Unknown event %s", udm_event_get_name(e)); - break; - } -} - -void udm_nf_state_registered(ogs_fsm_t *s, udm_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_sbi_client_t *client = NULL; - ogs_sbi_message_t *message = NULL; - ogs_assert(s); - ogs_assert(e); - - udm_sm_debug(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_NRF(nf_instance)) { - ogs_info("[%s] NF registered [Heartbeat:%ds]", - ogs_sbi_self()->nf_instance->id, - nf_instance->time.heartbeat_interval); - - client = nf_instance->client; - ogs_assert(client); - - if (nf_instance->time.heartbeat_interval) { - ogs_timer_start(nf_instance->t_heartbeat_interval, - ogs_time_from_sec(nf_instance->time.heartbeat_interval)); - ogs_timer_start(nf_instance->t_no_heartbeat, - ogs_time_from_sec( - nf_instance->time.heartbeat_interval + - ogs_app()->time.nf_instance.no_heartbeat_margin)); - } - - ogs_assert(true == - ogs_nnrf_nfm_send_nf_status_subscribe(client, - 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_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); - ogs_timer_stop(nf_instance->t_no_heartbeat); - } - - if (!OGS_FSM_CHECK(&nf_instance->sm, udm_nf_state_exception)) { - ogs_assert(true == - ogs_nnrf_nfm_send_nf_de_register(nf_instance)); - } - } - break; - - case UDM_EVT_SBI_CLIENT: - message = e->sbi.message; - ogs_assert(message); - - SWITCH(message->h.service.name) - CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) - - SWITCH(message->h.resource.component[0]) - CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - - if (message->res_status == OGS_SBI_HTTP_STATUS_NO_CONTENT || - message->res_status == OGS_SBI_HTTP_STATUS_OK) { - if (nf_instance->time.heartbeat_interval) - ogs_timer_start(nf_instance->t_no_heartbeat, - ogs_time_from_sec( - nf_instance->time.heartbeat_interval + - ogs_app()->time.nf_instance. - no_heartbeat_margin)); - } else { - ogs_warn("[%s] HTTP response error [%d]", - 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]", - ogs_sbi_self()->nf_instance->id, - message->h.resource.component[0]); - END - break; - - DEFAULT - ogs_error("[%s] Invalid API name [%s]", - ogs_sbi_self()->nf_instance->id, message->h.service.name); - END - break; - - case UDM_EVT_SBI_TIMER: - switch(e->timer_id) { - case UDM_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - if (nf_instance->time.heartbeat_interval) - ogs_timer_start(nf_instance->t_heartbeat_interval, - ogs_time_from_sec(nf_instance->time.heartbeat_interval)); - - ogs_assert(true == ogs_nnrf_nfm_send_nf_update(nf_instance)); - break; - - case UDM_TIMER_NF_INSTANCE_NO_HEARTBEAT: - 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: - 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:%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; - - default: - 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; - } -} - -void udm_nf_state_de_registered(ogs_fsm_t *s, udm_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_assert(s); - ogs_assert(e); - - udm_sm_debug(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_NRF(nf_instance)) { - ogs_info("[%s] NF de-registered", ogs_sbi_self()->nf_instance->id); - } - break; - - case OGS_FSM_EXIT_SIG: - break; - - default: - 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; - } -} - -void udm_nf_state_exception(ogs_fsm_t *s, udm_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_sbi_client_t *client = NULL; - ogs_sbi_message_t *message = NULL; - ogs_sockaddr_t *addr = NULL; - ogs_assert(s); - ogs_assert(e); - - udm_sm_debug(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_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_NRF(nf_instance)) { - ogs_timer_stop(nf_instance->t_registration_interval); - } - break; - - case UDM_EVT_SBI_TIMER: - switch(e->timer_id) { - case UDM_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - client = nf_instance->client; - ogs_assert(client); - addr = client->node.addr; - ogs_assert(addr); - - 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:%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; - - case UDM_EVT_SBI_CLIENT: - message = e->sbi.message; - ogs_assert(message); - - SWITCH(message->h.service.name) - CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) - - SWITCH(message->h.resource.component[0]) - CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - break; - DEFAULT - ogs_error("Invalid resource name [%s]", - message->h.resource.component[0]); - END - break; - DEFAULT - ogs_error("Invalid API name [%s]", message->h.service.name); - END - break; - - default: - 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 deleted file mode 100644 index 751805b83..000000000 --- a/src/udm/nnrf-build.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2019,2020 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "nnrf-build.h" - -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; - - OpenAPI_nf_profile_t *NFProfile = 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_PUT; - message.h.service.name = (char *)OGS_SBI_SERVICE_NAME_NNRF_NFM; - 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] = nf_instance->id; - - message.http.content_encoding = (char*)ogs_sbi_self()->content_encoding; - - NFProfile = ogs_nnrf_nfm_build_nf_profile(); - ogs_expect_or_return_val(NFProfile, NULL); - - message.NFProfile = NFProfile; - - request = ogs_sbi_build_request(&message); - - ogs_sbi_nnrf_free_nf_profile(NFProfile); - - return request; -} diff --git a/src/udm/nnrf-build.h b/src/udm/nnrf-build.h deleted file mode 100644 index fd1f30a67..000000000 --- a/src/udm/nnrf-build.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2019,2020 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef UDM_NNRF_BUILD_H -#define UDM_NNRF_BUILD_H - -#include "context.h" - -#ifdef __cplusplus -extern "C" { -#endif - -ogs_sbi_request_t *udm_nnrf_nfm_build_register(void); - -#ifdef __cplusplus -} -#endif - -#endif /* UDM_NNRF_BUILD_H */ diff --git a/src/udm/nnrf-handler.c b/src/udm/nnrf-handler.c index 8e4a5f9ef..28743329b 100644 --- a/src/udm/nnrf-handler.c +++ b/src/udm/nnrf-handler.c @@ -20,244 +20,14 @@ #include "sbi-path.h" #include "nnrf-handler.h" -void udm_nnrf_handle_nf_register( - ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_message_t *recvmsg) -{ - OpenAPI_nf_profile_t *NFProfile = NULL; - ogs_sbi_client_t *client = NULL; - - ogs_assert(recvmsg); - ogs_assert(nf_instance); - client = nf_instance->client; - ogs_assert(client); - - NFProfile = recvmsg->NFProfile; - if (!NFProfile) { - ogs_error("No NFProfile"); - return; - } - - /* TIME : Update heartbeat from NRF */ - if (NFProfile->is_heart_beat_timer == true) - nf_instance->time.heartbeat_interval = NFProfile->heart_beat_timer; -} - -void udm_nnrf_handle_nf_status_subscribe( - ogs_sbi_subscription_t *subscription, ogs_sbi_message_t *recvmsg) -{ - OpenAPI_subscription_data_t *SubscriptionData = NULL; - ogs_sbi_client_t *client = NULL; - - ogs_assert(recvmsg); - ogs_assert(subscription); - client = subscription->client; - ogs_assert(client); - - SubscriptionData = recvmsg->SubscriptionData; - if (!SubscriptionData) { - ogs_error("No SubscriptionData"); - return; - } - - if (!SubscriptionData->subscription_id) { - ogs_error("No SubscriptionId"); - return; - } - ogs_sbi_subscription_set_id( - subscription, SubscriptionData->subscription_id); - - if (SubscriptionData->validity_time) { -#define VALIDITY_MINIMUM (10LL * OGS_USEC_PER_SEC) /* 10 seconds */ - ogs_time_t time, duration; - if (ogs_sbi_time_from_string( - &time, SubscriptionData->validity_time) == true) { - duration = time - ogs_time_now(); - if (duration < VALIDITY_MINIMUM) { - duration = VALIDITY_MINIMUM; - ogs_warn("[%s] Forced to %lld seconds", subscription->id, - (long long)ogs_time_sec(VALIDITY_MINIMUM)); - } - subscription->t_validity = ogs_timer_add(ogs_app()->timer_mgr, - udm_timer_subscription_validity, subscription); - ogs_assert(subscription->t_validity); - ogs_timer_start(subscription->t_validity, duration); - } else { - ogs_error("Cannot parse validitiyTime [%s]", - SubscriptionData->validity_time); - } - } -} - -bool udm_nnrf_handle_nf_status_notify( - ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) -{ - int rv; - bool handled; - - ogs_sbi_response_t *response = NULL; - OpenAPI_notification_data_t *NotificationData = NULL; - ogs_sbi_nf_instance_t *nf_instance = NULL; - - ogs_sbi_message_t message; - ogs_sbi_header_t header; - - ogs_assert(stream); - ogs_assert(recvmsg); - - NotificationData = recvmsg->NotificationData; - if (!NotificationData) { - ogs_error("No NotificationData"); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "No NotificationData", NULL)); - return false; - } - - if (!NotificationData->nf_instance_uri) { - ogs_error("No nfInstanceUri"); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "No nfInstanceUri", NULL)); - return false; - } - - memset(&header, 0, sizeof(header)); - header.uri = NotificationData->nf_instance_uri; - - rv = ogs_sbi_parse_header(&message, &header); - if (rv != OGS_OK) { - ogs_error("Cannot parse nfInstanceUri [%s]", header.uri); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Cannot parse nfInstanceUri", header.uri)); - return false; - } - - if (!message.h.resource.component[1]) { - ogs_error("No nfInstanceId [%s]", header.uri); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Cannot parse nfInstanceUri", header.uri)); - ogs_sbi_header_free(&header); - return false; - } - - if (NF_INSTANCE_IS_SELF(message.h.resource.component[1])) { - ogs_warn("[%s] The notification is not allowed", - message.h.resource.component[1]); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, - recvmsg, "The notification is not allowed", - message.h.resource.component[1])); - ogs_sbi_header_free(&header); - return false; - } - - if (NotificationData->event == - OpenAPI_notification_event_type_NF_REGISTERED) { - - OpenAPI_nf_profile_t *NFProfile = NULL; - - NFProfile = NotificationData->nf_profile; - if (!NFProfile) { - ogs_error("No NFProfile"); - ogs_assert(true == - ogs_sbi_server_send_error( - stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "No NFProfile", NULL)); - ogs_sbi_header_free(&header); - return false; - } - - nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); - if (!nf_instance) { - 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); - - ogs_info("[%s] (NRF-notify) NF registered", nf_instance->id); - - } else { - OGS_FSM_TRAN(&nf_instance->sm, udm_nf_state_registered); - ogs_fsm_dispatch(&nf_instance->sm, NULL); - - ogs_warn("[%s] (NRF-notify) NF has already been added", - message.h.resource.component[1]); - - } - - handled = ogs_sbi_nnrf_handle_nf_profile( - nf_instance, NFProfile, stream, recvmsg); - if (!handled) { - UDM_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); - ogs_sbi_header_free(&header); - return false; - } - - ogs_info("[%s] (NRF-notify) NF Profile updated", nf_instance->id); - - handled = ogs_sbi_client_associate(nf_instance); - if (!handled) { - ogs_error("[%s] Cannot associate NF EndPoint", nf_instance->id); - ogs_assert(true == - ogs_sbi_server_send_error(stream, - OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Cannot find NF EndPoint", nf_instance->id)); - UDM_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); - ogs_sbi_header_free(&header); - return false; - } - - } else if (NotificationData->event == - OpenAPI_notification_event_type_NF_DEREGISTERED) { - nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); - if (nf_instance) { - UDM_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); - } else { - ogs_warn("[%s] (NRF-notify) Not found", - message.h.resource.component[1]); - ogs_assert(true == - ogs_sbi_server_send_error(stream, - OGS_SBI_HTTP_STATUS_NOT_FOUND, - recvmsg, "Not found", message.h.resource.component[1])); - ogs_sbi_header_free(&header); - return false; - } - } else { - char *eventstr = OpenAPI_notification_event_type_ToString( - NotificationData->event); - ogs_error("Not supported event [%d:%s]", - NotificationData->event, eventstr ? eventstr : "Unknown"); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Not supported event", - eventstr ? eventstr : "Unknown")); - ogs_sbi_header_free(&header); - return false; - } - - response = ogs_sbi_build_response(recvmsg, OGS_SBI_HTTP_STATUS_NO_CONTENT); - ogs_assert(response); - ogs_assert(true == ogs_sbi_server_send_response(stream, response)); - - ogs_sbi_header_free(&header); - return true; -} - void udm_nnrf_handle_nf_discover( ogs_sbi_xact_t *xact, ogs_sbi_message_t *recvmsg) { ogs_sbi_object_t *sbi_object = NULL; OpenAPI_nf_type_e target_nf_type = 0; ogs_sbi_discovery_option_t *discovery_option = NULL; - ogs_sbi_nf_instance_t *nf_instance = NULL; OpenAPI_search_result_t *SearchResult = NULL; - OpenAPI_lnode_t *node = NULL; - bool handled; ogs_assert(recvmsg); ogs_assert(xact); @@ -274,64 +44,8 @@ void udm_nnrf_handle_nf_discover( return; } - OpenAPI_list_for_each(SearchResult->nf_instances, node) { - OpenAPI_nf_profile_t *NFProfile = NULL; - - if (!node->data) continue; - - NFProfile = node->data; - - nf_instance = ogs_sbi_nf_instance_find(NFProfile->nf_instance_id); - if (!nf_instance) { - 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); - - ogs_info("[%s] (NF-discover) NF registered", nf_instance->id); - } else { - OGS_FSM_TRAN(&nf_instance->sm, udm_nf_state_registered); - ogs_fsm_dispatch(&nf_instance->sm, NULL); - - ogs_warn("[%s] (NF-discover) NF has already been added", - NFProfile->nf_instance_id); - } - - if (NF_INSTANCE_IS_OTHERS(nf_instance->id)) { - handled = ogs_sbi_nnrf_handle_nf_profile( - nf_instance, NFProfile, NULL, NULL); - if (!handled) { - ogs_error("[%s] ogs_sbi_nnrf_handle_nf_profile() failed", - nf_instance->id); - UDM_NF_INSTANCE_CLEAR("NRF-discover", nf_instance); - continue; - } - - handled = ogs_sbi_client_associate(nf_instance); - if (!handled) { - ogs_error("[%s] Cannot assciate NF EndPoint", nf_instance->id); - UDM_NF_INSTANCE_CLEAR("NRF-discover", nf_instance); - continue; - } - - /* TIME : Update validity from NRF */ - if (SearchResult->is_validity_period && - SearchResult->validity_period) { - nf_instance->time.validity_duration = - SearchResult->validity_period; - - ogs_assert(nf_instance->t_validity); - ogs_timer_start(nf_instance->t_validity, - ogs_time_from_sec(nf_instance->time.validity_duration)); - - } else - ogs_warn("[%s] NF Instance validity-time should not 0", - nf_instance->id); - - ogs_info("[%s] (NF-discover) NF Profile updated", nf_instance->id); - } - } + ogs_nnrf_handle_nf_discover_search_result( + sbi_object, target_nf_type, discovery_option, SearchResult); ogs_sbi_select_nf(sbi_object, target_nf_type, discovery_option); diff --git a/src/udm/nnrf-handler.h b/src/udm/nnrf-handler.h index 2c69040c5..c43611b72 100644 --- a/src/udm/nnrf-handler.h +++ b/src/udm/nnrf-handler.h @@ -26,14 +26,6 @@ extern "C" { #endif -void udm_nnrf_handle_nf_register( - ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_message_t *recvmsg); -void udm_nnrf_handle_nf_status_subscribe( - ogs_sbi_subscription_t *subscription, ogs_sbi_message_t *recvmsg); - -bool udm_nnrf_handle_nf_status_notify( - ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); - void udm_nnrf_handle_nf_discover( ogs_sbi_xact_t *xact, ogs_sbi_message_t *recvmsg); diff --git a/src/udm/sbi-path.c b/src/udm/sbi-path.c index bf5f17a7c..aee1f0cee 100644 --- a/src/udm/sbi-path.c +++ b/src/udm/sbi-path.c @@ -27,17 +27,17 @@ static int server_cb(ogs_sbi_request_t *request, void *data) ogs_assert(request); ogs_assert(data); - e = udm_event_new(UDM_EVT_SBI_SERVER); + e = udm_event_new(OGS_EVENT_SBI_SERVER); ogs_assert(e); - e->sbi.request = request; - e->sbi.data = data; + e->h.sbi.request = request; + e->h.sbi.data = data; rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed:%d", (int)rv); ogs_sbi_request_free(request); - udm_event_free(e); + ogs_event_free(e); return OGS_ERROR; } @@ -58,16 +58,16 @@ static int client_cb(int status, ogs_sbi_response_t *response, void *data) ogs_assert(response); - e = udm_event_new(UDM_EVT_SBI_CLIENT); + e = udm_event_new(OGS_EVENT_SBI_CLIENT); ogs_assert(e); - e->sbi.response = response; - e->sbi.data = data; + e->h.sbi.response = response; + e->h.sbi.data = data; rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed:%d", (int)rv); ogs_sbi_response_free(response); - udm_event_free(e); + ogs_event_free(e); return OGS_ERROR; } @@ -79,6 +79,10 @@ int udm_sbi_open(void) ogs_sbi_nf_instance_t *nf_instance = NULL; ogs_sbi_nf_service_t *service = NULL; + /* To be notified when NF Instances registered/deregistered in NRF + * or when their profile is modified */ + ogs_sbi_add_to_be_notified_nf_type(OpenAPI_nf_type_UDR); + /* Add SELF NF instance */ nf_instance = ogs_sbi_self()->nf_instance; ogs_assert(nf_instance); @@ -119,28 +123,20 @@ int udm_sbi_open(void) } /* Initialize NRF NF Instance */ - ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) { - if (NF_INSTANCE_IS_NRF(nf_instance)) { - ogs_sbi_client_t *client = NULL; + nf_instance = ogs_sbi_self()->nrf_instance; + if (nf_instance) { + ogs_sbi_client_t *client = NULL; - /* Client callback is only used when NF sends to NRF */ - client = nf_instance->client; - ogs_assert(client); - client->cb = client_cb; + /* 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. */ + ogs_sbi_nf_fsm_init(nf_instance); } - /* Timer expiration handler of client wait timer */ - ogs_sbi_self()->client_wait_expire = udm_timer_sbi_client_wait_expire; - - /* NF register state in NF state machine */ - ogs_sbi_self()->nf_state_registered = - (ogs_fsm_handler_t)udm_nf_state_registered; - if (ogs_sbi_server_start_all(server_cb) != OGS_OK) return OGS_ERROR; diff --git a/src/udm/sbi-path.h b/src/udm/sbi-path.h index c7dd32759..fc9a90125 100644 --- a/src/udm/sbi-path.h +++ b/src/udm/sbi-path.h @@ -20,7 +20,6 @@ #ifndef UDM_SBI_PATH_H #define UDM_SBI_PATH_H -#include "nnrf-build.h" #include "nudr-build.h" #ifdef __cplusplus diff --git a/src/udm/timer.c b/src/udm/timer.c deleted file mode 100644 index 95a9d5216..000000000 --- a/src/udm/timer.c +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (C) 2019,2020 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "context.h" - -const char *udm_timer_get_name(udm_timer_e id) -{ - switch (id) { - case UDM_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - return "UDM_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL"; - case UDM_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - return "UDM_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL"; - case UDM_TIMER_NF_INSTANCE_NO_HEARTBEAT: - return "UDM_TIMER_NF_INSTANCE_NO_HEARTBEAT"; - case UDM_TIMER_NF_INSTANCE_VALIDITY: - return "UDM_TIMER_NF_INSTANCE_VALIDITY"; - case UDM_TIMER_SUBSCRIPTION_VALIDITY: - return "UDM_TIMER_SUBSCRIPTION_VALIDITY"; - case UDM_TIMER_SBI_CLIENT_WAIT: - return "UDM_TIMER_SBI_CLIENT_WAIT"; - default: - break; - } - - return "UNKNOWN_TIMER"; -} - -static void sbi_timer_send_event(int timer_id, void *data) -{ - int rv; - udm_event_t *e = NULL; - ogs_assert(data); - - switch (timer_id) { - case UDM_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - case UDM_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - case UDM_TIMER_NF_INSTANCE_NO_HEARTBEAT: - case UDM_TIMER_NF_INSTANCE_VALIDITY: - case UDM_TIMER_SUBSCRIPTION_VALIDITY: - e = udm_event_new(UDM_EVT_SBI_TIMER); - ogs_assert(e); - e->timer_id = timer_id; - e->sbi.data = data; - break; - case UDM_TIMER_SBI_CLIENT_WAIT: - e = udm_event_new(UDM_EVT_SBI_TIMER); - if (!e) { - ogs_sbi_xact_t *sbi_xact = data; - ogs_assert(sbi_xact); - - ogs_error("sbi_timer_send_event() failed"); - ogs_sbi_xact_remove(sbi_xact); - return; - } - e->timer_id = timer_id; - e->sbi.data = data; - break; - default: - ogs_fatal("Unknown timer id[%d]", timer_id); - ogs_assert_if_reached(); - break; - } - - rv = ogs_queue_push(ogs_app()->queue, e); - if (rv != OGS_OK) { - ogs_error("ogs_queue_push() failed [%d] in %s", - (int)rv, udm_timer_get_name(e->timer_id)); - udm_event_free(e); - } -} - -void udm_timer_nf_instance_registration_interval(void *data) -{ - sbi_timer_send_event(UDM_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL, data); -} - -void udm_timer_nf_instance_heartbeat_interval(void *data) -{ - sbi_timer_send_event(UDM_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL, data); -} - -void udm_timer_nf_instance_no_heartbeat(void *data) -{ - sbi_timer_send_event(UDM_TIMER_NF_INSTANCE_NO_HEARTBEAT, data); -} - -void udm_timer_nf_instance_validity(void *data) -{ - sbi_timer_send_event(UDM_TIMER_NF_INSTANCE_VALIDITY, data); -} - -void udm_timer_subscription_validity(void *data) -{ - sbi_timer_send_event(UDM_TIMER_SUBSCRIPTION_VALIDITY, data); -} - -void udm_timer_sbi_client_wait_expire(void *data) -{ - sbi_timer_send_event(UDM_TIMER_SBI_CLIENT_WAIT, data); -} diff --git a/src/udm/timer.h b/src/udm/timer.h deleted file mode 100644 index 9f029294f..000000000 --- a/src/udm/timer.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2019 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef UDM_TIMER_H -#define UDM_TIMER_H - -#include "ogs-core.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* forward declaration */ -typedef enum { - UDM_TIMER_BASE = 0, - - UDM_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL, - UDM_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL, - UDM_TIMER_NF_INSTANCE_NO_HEARTBEAT, - UDM_TIMER_NF_INSTANCE_VALIDITY, - UDM_TIMER_SUBSCRIPTION_VALIDITY, - UDM_TIMER_SBI_CLIENT_WAIT, - - MAX_NUM_OF_UDM_TIMER, - -} udm_timer_e; - -const char *udm_timer_get_name(udm_timer_e id); - -void udm_timer_nf_instance_registration_interval(void *data); -void udm_timer_nf_instance_heartbeat_interval(void *data); -void udm_timer_nf_instance_no_heartbeat(void *data); -void udm_timer_nf_instance_validity(void *data); -void udm_timer_subscription_validity(void *data); -void udm_timer_sbi_client_wait_expire(void *data); - -#ifdef __cplusplus -} -#endif - -#endif /* UDM_TIMER_H */ diff --git a/src/udm/udm-sm.c b/src/udm/udm-sm.c index c3e2d69c4..7d0aa93c9 100644 --- a/src/udm/udm-sm.c +++ b/src/udm/udm-sm.c @@ -54,17 +54,17 @@ void udm_state_operational(ogs_fsm_t *s, udm_event_t *e) ogs_assert(s); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: break; case OGS_FSM_EXIT_SIG: break; - case UDM_EVT_SBI_SERVER: - request = e->sbi.request; + case OGS_EVENT_SBI_SERVER: + request = e->h.sbi.request; ogs_assert(request); - stream = e->sbi.data; + stream = e->h.sbi.data; ogs_assert(stream); rv = ogs_sbi_parse_request(&message, request); @@ -103,7 +103,7 @@ void udm_state_operational(ogs_fsm_t *s, udm_event_t *e) CASE(OGS_SBI_RESOURCE_NAME_NF_STATUS_NOTIFY) SWITCH(message.h.method) CASE(OGS_SBI_HTTP_METHOD_POST) - udm_nnrf_handle_nf_status_notify(stream, &message); + ogs_nnrf_handle_nf_status_notify(stream, &message); break; DEFAULT @@ -178,7 +178,7 @@ void udm_state_operational(ogs_fsm_t *s, udm_event_t *e) ogs_assert(OGS_FSM_STATE(&udm_ue->sm)); e->udm_ue = udm_ue; - e->sbi.message = &message; + e->h.sbi.message = &message; ogs_fsm_dispatch(&udm_ue->sm, e); if (OGS_FSM_CHECK(&udm_ue->sm, udm_ue_state_exception)) { ogs_error("[%s] State machine exception", udm_ue->suci); @@ -198,10 +198,10 @@ void udm_state_operational(ogs_fsm_t *s, udm_event_t *e) ogs_sbi_message_free(&message); break; - case UDM_EVT_SBI_CLIENT: + case OGS_EVENT_SBI_CLIENT: ogs_assert(e); - response = e->sbi.response; + response = e->h.sbi.response; ogs_assert(response); rv = ogs_sbi_parse_response(&message, response); if (rv != OGS_OK) { @@ -231,23 +231,23 @@ void udm_state_operational(ogs_fsm_t *s, udm_event_t *e) SWITCH(message.h.resource.component[0]) CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - nf_instance = e->sbi.data; + nf_instance = e->h.sbi.data; ogs_assert(nf_instance); ogs_assert(OGS_FSM_STATE(&nf_instance->sm)); - e->sbi.message = &message; + e->h.sbi.message = &message; ogs_fsm_dispatch(&nf_instance->sm, e); break; CASE(OGS_SBI_RESOURCE_NAME_SUBSCRIPTIONS) - subscription = e->sbi.data; + subscription = e->h.sbi.data; ogs_assert(subscription); SWITCH(message.h.method) CASE(OGS_SBI_HTTP_METHOD_POST) if (message.res_status == OGS_SBI_HTTP_STATUS_CREATED || message.res_status == OGS_SBI_HTTP_STATUS_OK) { - udm_nnrf_handle_nf_status_subscribe( + ogs_nnrf_handle_nf_status_subscribe( subscription, &message); } else { ogs_error("[%s] HTTP response error [%d]", @@ -282,7 +282,7 @@ void udm_state_operational(ogs_fsm_t *s, udm_event_t *e) CASE(OGS_SBI_SERVICE_NAME_NNRF_DISC) SWITCH(message.h.resource.component[0]) CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - sbi_xact = e->sbi.data; + sbi_xact = e->h.sbi.data; ogs_assert(sbi_xact); SWITCH(message.h.method) @@ -310,7 +310,7 @@ void udm_state_operational(ogs_fsm_t *s, udm_event_t *e) CASE(OGS_SBI_SERVICE_NAME_NUDR_DR) SWITCH(message.h.resource.component[0]) CASE(OGS_SBI_RESOURCE_NAME_SUBSCRIPTION_DATA) - sbi_xact = e->sbi.data; + sbi_xact = e->h.sbi.data; ogs_assert(sbi_xact); sbi_xact = ogs_sbi_xact_cycle(sbi_xact); @@ -324,7 +324,7 @@ void udm_state_operational(ogs_fsm_t *s, udm_event_t *e) udm_ue = (udm_ue_t *)sbi_xact->sbi_object; ogs_assert(udm_ue); - e->sbi.data = sbi_xact->assoc_stream; + e->h.sbi.data = sbi_xact->assoc_stream; ogs_sbi_xact_remove(sbi_xact); @@ -335,7 +335,7 @@ void udm_state_operational(ogs_fsm_t *s, udm_event_t *e) } e->udm_ue = udm_ue; - e->sbi.message = &message; + e->h.sbi.message = &message; ogs_fsm_dispatch(&udm_ue->sm, e); if (OGS_FSM_CHECK(&udm_ue->sm, udm_ue_state_exception)) { @@ -361,27 +361,27 @@ void udm_state_operational(ogs_fsm_t *s, udm_event_t *e) ogs_sbi_response_free(response); break; - case UDM_EVT_SBI_TIMER: + case OGS_EVENT_SBI_TIMER: ogs_assert(e); - switch(e->timer_id) { - case UDM_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - case UDM_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - case UDM_TIMER_NF_INSTANCE_NO_HEARTBEAT: - case UDM_TIMER_NF_INSTANCE_VALIDITY: - nf_instance = e->sbi.data; + switch(e->h.timer_id) { + case OGS_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: + case OGS_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: + case OGS_TIMER_NF_INSTANCE_NO_HEARTBEAT: + case OGS_TIMER_NF_INSTANCE_VALIDITY: + nf_instance = e->h.sbi.data; ogs_assert(nf_instance); ogs_assert(OGS_FSM_STATE(&nf_instance->sm)); ogs_fsm_dispatch(&nf_instance->sm, e); - if (OGS_FSM_CHECK(&nf_instance->sm, udm_nf_state_exception)) + if (OGS_FSM_CHECK(&nf_instance->sm, ogs_sbi_nf_state_exception)) ogs_error("[%s:%s] State machine exception [%d]", OpenAPI_nf_type_ToString(nf_instance->nf_type), - nf_instance->id, e->timer_id); + nf_instance->id, e->h.timer_id); break; - case UDM_TIMER_SUBSCRIPTION_VALIDITY: - subscription = e->sbi.data; + case OGS_TIMER_SUBSCRIPTION_VALIDITY: + subscription = e->h.sbi.data; ogs_assert(subscription); ogs_assert(ogs_sbi_self()->nf_instance); @@ -395,8 +395,8 @@ void udm_state_operational(ogs_fsm_t *s, udm_event_t *e) ogs_sbi_subscription_remove(subscription); break; - case UDM_TIMER_SBI_CLIENT_WAIT: - sbi_xact = e->sbi.data; + case OGS_TIMER_SBI_CLIENT_WAIT: + sbi_xact = e->h.sbi.data; ogs_assert(sbi_xact); stream = sbi_xact->assoc_stream; @@ -413,7 +413,7 @@ void udm_state_operational(ogs_fsm_t *s, udm_event_t *e) default: ogs_error("Unknown timer[%s:%d]", - udm_timer_get_name(e->timer_id), e->timer_id); + ogs_timer_get_name(e->h.timer_id), e->h.timer_id); } break; diff --git a/src/udm/udm-sm.h b/src/udm/udm-sm.h index 401970018..e92e83547 100644 --- a/src/udm/udm-sm.h +++ b/src/udm/udm-sm.h @@ -30,16 +30,6 @@ void udm_state_initial(ogs_fsm_t *s, udm_event_t *e); void udm_state_final(ogs_fsm_t *s, udm_event_t *e); void udm_state_operational(ogs_fsm_t *s, udm_event_t *e); -void udm_nf_fsm_init(ogs_sbi_nf_instance_t *nf_instance); -void udm_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance); - -void udm_nf_state_initial(ogs_fsm_t *s, udm_event_t *e); -void udm_nf_state_final(ogs_fsm_t *s, udm_event_t *e); -void udm_nf_state_will_register(ogs_fsm_t *s, udm_event_t *e); -void udm_nf_state_registered(ogs_fsm_t *s, udm_event_t *e); -void udm_nf_state_de_registered(ogs_fsm_t *s, udm_event_t *e); -void udm_nf_state_exception(ogs_fsm_t *s, udm_event_t *e); - void udm_ue_state_initial(ogs_fsm_t *s, udm_event_t *e); void udm_ue_state_final(ogs_fsm_t *s, udm_event_t *e); void udm_ue_state_operational(ogs_fsm_t *s, udm_event_t *e); diff --git a/src/udm/ue-sm.c b/src/udm/ue-sm.c index 16781925b..4122c52e0 100644 --- a/src/udm/ue-sm.c +++ b/src/udm/ue-sm.c @@ -48,17 +48,17 @@ void udm_ue_state_operational(ogs_fsm_t *s, udm_event_t *e) udm_ue = e->udm_ue; ogs_assert(udm_ue); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: break; case OGS_FSM_EXIT_SIG: break; - case UDM_EVT_SBI_SERVER: - message = e->sbi.message; + case OGS_EVENT_SBI_SERVER: + message = e->h.sbi.message; ogs_assert(message); - stream = e->sbi.data; + stream = e->h.sbi.data; ogs_assert(stream); SWITCH(message->h.service.name) @@ -181,13 +181,13 @@ void udm_ue_state_operational(ogs_fsm_t *s, udm_event_t *e) END break; - case UDM_EVT_SBI_CLIENT: - message = e->sbi.message; + case OGS_EVENT_SBI_CLIENT: + message = e->h.sbi.message; ogs_assert(message); udm_ue = e->udm_ue; ogs_assert(udm_ue); - stream = e->sbi.data; + stream = e->h.sbi.data; ogs_assert(stream); SWITCH(message->h.service.name) @@ -252,7 +252,7 @@ void udm_ue_state_exception(ogs_fsm_t *s, udm_event_t *e) udm_ue = e->udm_ue; ogs_assert(udm_ue); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: break; diff --git a/src/udr/context.c b/src/udr/context.c index 9dbc864bb..7637dbcec 100644 --- a/src/udr/context.c +++ b/src/udr/context.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * diff --git a/src/udr/context.h b/src/udr/context.h index a2d6747e0..effddb1c4 100644 --- a/src/udr/context.h +++ b/src/udr/context.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -25,7 +25,6 @@ #include "ogs-sbi.h" #include "udr-sm.h" -#include "timer.h" #ifdef __cplusplus extern "C" { @@ -41,22 +40,6 @@ extern int __udr_log_domain; typedef struct udr_context_s { } udr_context_t; -#define UDR_NF_INSTANCE_CLEAR(_cAUSE, _nFInstance) \ - do { \ - ogs_assert(_nFInstance); \ - if ((_nFInstance)->reference_count == 1) { \ - ogs_info("[%s] (%s) NF removed", (_nFInstance)->id, (_cAUSE)); \ - udr_nf_fsm_fini((_nFInstance)); \ - ogs_sbi_nf_instance_remove(_nFInstance); \ - } else { \ - /* There is an assocation with other context */ \ - ogs_info("[%s:%d] (%s) NF suspended", \ - _nFInstance->id, _nFInstance->reference_count, (_cAUSE)); \ - OGS_FSM_TRAN(&_nFInstance->sm, udr_nf_state_de_registered); \ - ogs_fsm_dispatch(&_nFInstance->sm, NULL); \ - } \ - } while(0) - void udr_context_init(void); void udr_context_final(void); udr_context_t *udr_self(void); diff --git a/src/udr/event.c b/src/udr/event.c index 3cd6ae195..eeb1fc407 100644 --- a/src/udr/event.c +++ b/src/udr/event.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -18,60 +18,42 @@ */ #include "event.h" -#include "context.h" -static OGS_POOL(pool, udr_event_t); - -void udr_event_init(void) -{ - ogs_pool_init(&pool, ogs_app()->pool.event); -} - -void udr_event_final(void) -{ - ogs_pool_final(&pool); -} - -udr_event_t *udr_event_new(udr_event_e id) +udr_event_t *udr_event_new(int id) { udr_event_t *e = NULL; - ogs_pool_alloc(&pool, &e); + e = ogs_event_size(id, sizeof(udr_event_t)); ogs_assert(e); - memset(e, 0, sizeof(*e)); - e->id = id; + e->h.id = id; return e; } -void udr_event_free(udr_event_t *e) -{ - ogs_assert(e); - ogs_pool_free(&pool, e); -} - const char *udr_event_get_name(udr_event_t *e) { - if (e == NULL) + if (e == NULL) { return OGS_FSM_NAME_INIT_SIG; - - switch (e->id) { - case OGS_FSM_ENTRY_SIG: - return OGS_FSM_NAME_ENTRY_SIG; - case OGS_FSM_EXIT_SIG: - return OGS_FSM_NAME_EXIT_SIG; - - case UDR_EVT_SBI_SERVER: - return "UDR_EVT_SBI_SERVER"; - case UDR_EVT_SBI_CLIENT: - return "UDR_EVT_SBI_CLIENT"; - case UDR_EVT_SBI_TIMER: - return "UDR_EVT_SBI_TIMER"; - - default: - break; } + switch (e->h.id) { + case OGS_FSM_ENTRY_SIG: + return OGS_FSM_NAME_ENTRY_SIG; + case OGS_FSM_EXIT_SIG: + return OGS_FSM_NAME_EXIT_SIG; + + case OGS_EVENT_SBI_SERVER: + return OGS_EVENT_NAME_SBI_SERVER; + case OGS_EVENT_SBI_CLIENT: + return OGS_EVENT_NAME_SBI_CLIENT; + case OGS_EVENT_SBI_TIMER: + return OGS_EVENT_NAME_SBI_TIMER; + + default: + break; + } + + ogs_error("Unknown Event[%d]", e->h.id); return "UNKNOWN_EVENT"; } diff --git a/src/udr/event.h b/src/udr/event.h index 761c2ff12..0589df9e7 100644 --- a/src/udr/event.h +++ b/src/udr/event.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -20,49 +20,17 @@ #ifndef UDR_EVENT_H #define UDR_EVENT_H -#include "ogs-core.h" +#include "ogs-proto.h" #ifdef __cplusplus extern "C" { #endif -typedef struct ogs_sbi_request_s ogs_sbi_request_t; -typedef struct ogs_sbi_response_s ogs_sbi_response_t; -typedef struct ogs_sbi_message_s ogs_sbi_message_t; -typedef struct ogs_sbi_nf_instance_s ogs_sbi_nf_instance_t; -typedef struct ogs_sbi_subscription_s ogs_sbi_subscription_t; - -typedef enum { - UDR_EVT_BASE = OGS_FSM_USER_SIG, - - UDR_EVT_SBI_SERVER, - UDR_EVT_SBI_CLIENT, - UDR_EVT_SBI_TIMER, - - UDR_EVT_TOP, - -} udr_event_e; - typedef struct udr_event_s { - int id; - int timer_id; - - struct { - ogs_sbi_request_t *request; - ogs_sbi_response_t *response; - void *data; - - ogs_sbi_message_t *message; - } sbi; - - ogs_timer_t *timer; + ogs_event_t h; } udr_event_t; -void udr_event_init(void); -void udr_event_final(void); - -udr_event_t *udr_event_new(udr_event_e id); -void udr_event_free(udr_event_t *e); +udr_event_t *udr_event_new(int id); const char *udr_event_get_name(udr_event_t *e); diff --git a/src/udr/init.c b/src/udr/init.c index fd1a08388..0e4403a48 100644 --- a/src/udr/init.c +++ b/src/udr/init.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -30,7 +30,6 @@ int udr_initialize() ogs_sbi_context_init(); udr_context_init(); - udr_event_init(); rv = ogs_sbi_context_parse_config("udr", "nrf", "scp"); if (rv != OGS_OK) return rv; @@ -64,7 +63,7 @@ static void event_termination(void) /* Sending NF Instance De-registeration to NRF */ ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) - udr_nf_fsm_fini(nf_instance); + ogs_sbi_nf_fsm_fini(nf_instance); /* Starting holding timer */ t_termination_holding = ogs_timer_add(ogs_app()->timer_mgr, NULL, NULL); @@ -92,8 +91,6 @@ void udr_terminate(void) udr_context_final(); ogs_sbi_context_final(); - - udr_event_final(); /* Destroy event */ } static void udr_main(void *data) @@ -101,8 +98,7 @@ static void udr_main(void *data) ogs_fsm_t udr_sm; int rv; - ogs_fsm_create(&udr_sm, udr_state_initial, udr_state_final); - ogs_fsm_init(&udr_sm, 0); + ogs_fsm_init(&udr_sm, udr_state_initial, udr_state_final, 0); for ( ;; ) { ogs_pollset_poll(ogs_app()->pollset, @@ -135,11 +131,10 @@ static void udr_main(void *data) ogs_assert(e); ogs_fsm_dispatch(&udr_sm, e); - udr_event_free(e); + ogs_event_free(e); } } done: ogs_fsm_fini(&udr_sm, 0); - ogs_fsm_delete(&udr_sm); } diff --git a/src/udr/meson.build b/src/udr/meson.build index 2a77ea4ae..f75e7802a 100644 --- a/src/udr/meson.build +++ b/src/udr/meson.build @@ -1,4 +1,4 @@ -# Copyright (C) 2019,2020 by Sukchan Lee +# Copyright (C) 2019-2022 by Sukchan Lee # This file is part of Open5GS. @@ -18,11 +18,6 @@ libudr_sources = files(''' context.c event.c - timer.c - - nnrf-build.c - nnrf-handler.c - nf-sm.c nudr-handler.c diff --git a/src/udr/nf-sm.c b/src/udr/nf-sm.c deleted file mode 100644 index 4c760a96f..000000000 --- a/src/udr/nf-sm.c +++ /dev/null @@ -1,441 +0,0 @@ -/* - * Copyright (C) 2019,2020 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "context.h" - -#include "sbi-path.h" -#include "nnrf-handler.h" - -void udr_nf_fsm_init(ogs_sbi_nf_instance_t *nf_instance) -{ - udr_event_t e; - - ogs_assert(nf_instance); - - memset(&e, 0, sizeof(e)); - e.sbi.data = nf_instance; - - ogs_fsm_create(&nf_instance->sm, - udr_nf_state_initial, udr_nf_state_final); - ogs_fsm_init(&nf_instance->sm, &e); -} - -void udr_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance) -{ - udr_event_t e; - - ogs_assert(nf_instance); - - memset(&e, 0, sizeof(e)); - e.sbi.data = nf_instance; - - ogs_fsm_fini(&nf_instance->sm, &e); - ogs_fsm_delete(&nf_instance->sm); -} - -void udr_nf_state_initial(ogs_fsm_t *s, udr_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - - ogs_assert(s); - ogs_assert(e); - - udr_sm_debug(e); - - nf_instance = e->sbi.data; - ogs_assert(nf_instance); - - nf_instance->t_registration_interval = ogs_timer_add(ogs_app()->timer_mgr, - udr_timer_nf_instance_registration_interval, nf_instance); - ogs_assert(nf_instance->t_registration_interval); - nf_instance->t_heartbeat_interval = ogs_timer_add(ogs_app()->timer_mgr, - udr_timer_nf_instance_heartbeat_interval, nf_instance); - ogs_assert(nf_instance->t_heartbeat_interval); - nf_instance->t_no_heartbeat = ogs_timer_add(ogs_app()->timer_mgr, - udr_timer_nf_instance_no_heartbeat, nf_instance); - ogs_assert(nf_instance->t_no_heartbeat); - nf_instance->t_validity = ogs_timer_add(ogs_app()->timer_mgr, - udr_timer_nf_instance_validity, nf_instance); - ogs_assert(nf_instance->t_validity); - - 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); - } -} - -void udr_nf_state_final(ogs_fsm_t *s, udr_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - - ogs_assert(s); - ogs_assert(e); - - udr_sm_debug(e); - - nf_instance = e->sbi.data; - ogs_assert(nf_instance); - - ogs_timer_delete(nf_instance->t_registration_interval); - ogs_timer_delete(nf_instance->t_heartbeat_interval); - ogs_timer_delete(nf_instance->t_no_heartbeat); - ogs_timer_delete(nf_instance->t_validity); -} - -void udr_nf_state_will_register(ogs_fsm_t *s, udr_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_sbi_client_t *client = NULL; - ogs_sbi_message_t *message = NULL; - ogs_sockaddr_t *addr = NULL; - - ogs_assert(s); - ogs_assert(e); - - udr_sm_debug(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: - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); - - ogs_assert(true == ogs_nnrf_nfm_send_nf_register( - nf_instance, udr_nnrf_nfm_build_register)); - break; - - case OGS_FSM_EXIT_SIG: - ogs_timer_stop(nf_instance->t_registration_interval); - break; - - case UDR_EVT_SBI_CLIENT: - message = e->sbi.message; - ogs_assert(message); - - SWITCH(message->h.service.name) - CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) - - SWITCH(message->h.resource.component[0]) - CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - - if (message->res_status == OGS_SBI_HTTP_STATUS_OK || - message->res_status == OGS_SBI_HTTP_STATUS_CREATED) { - udr_nnrf_handle_nf_register(nf_instance, message); - OGS_FSM_TRAN(s, &udr_nf_state_registered); - } else { - ogs_error("[%s] HTTP response error [%d]", - 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]", - ogs_sbi_self()->nf_instance->id, - message->h.resource.component[0]); - END - break; - - DEFAULT - ogs_error("[%s] Invalid API name [%s]", - ogs_sbi_self()->nf_instance->id, message->h.service.name); - END - break; - - case UDR_EVT_SBI_TIMER: - switch(e->timer_id) { - case UDR_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - client = nf_instance->client; - ogs_assert(client); - addr = client->node.addr; - ogs_assert(addr); - - ogs_warn("[%s] Retry to registration with NRF", - ogs_sbi_self()->nf_instance->id); - - ogs_timer_start(nf_instance->t_registration_interval, - ogs_app()->time.message.sbi.nf_register_interval); - - ogs_assert(true == ogs_nnrf_nfm_send_nf_register( - nf_instance, udr_nnrf_nfm_build_register)); - break; - - default: - ogs_error("[%s] Unknown timer[%s:%d]", - ogs_sbi_self()->nf_instance->id, - udr_timer_get_name(e->timer_id), e->timer_id); - } - break; - - default: - ogs_error("Unknown event %s", udr_event_get_name(e)); - break; - } -} - -void udr_nf_state_registered(ogs_fsm_t *s, udr_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_sbi_client_t *client = NULL; - ogs_sbi_message_t *message = NULL; - ogs_assert(s); - ogs_assert(e); - - udr_sm_debug(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_NRF(nf_instance)) { - ogs_info("[%s] NF registered [Heartbeat:%ds]", - ogs_sbi_self()->nf_instance->id, - nf_instance->time.heartbeat_interval); - - client = nf_instance->client; - ogs_assert(client); - - if (nf_instance->time.heartbeat_interval) { - ogs_timer_start(nf_instance->t_heartbeat_interval, - ogs_time_from_sec(nf_instance->time.heartbeat_interval)); - ogs_timer_start(nf_instance->t_no_heartbeat, - ogs_time_from_sec( - nf_instance->time.heartbeat_interval + - ogs_app()->time.nf_instance.no_heartbeat_margin)); - } - } - - break; - - case OGS_FSM_EXIT_SIG: - 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); - ogs_timer_stop(nf_instance->t_no_heartbeat); - } - - if (!OGS_FSM_CHECK(&nf_instance->sm, udr_nf_state_exception)) { - ogs_assert(true == - ogs_nnrf_nfm_send_nf_de_register(nf_instance)); - } - } - break; - - case UDR_EVT_SBI_CLIENT: - message = e->sbi.message; - ogs_assert(message); - - SWITCH(message->h.service.name) - CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) - - SWITCH(message->h.resource.component[0]) - CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - - if (message->res_status == OGS_SBI_HTTP_STATUS_NO_CONTENT || - message->res_status == OGS_SBI_HTTP_STATUS_OK) { - if (nf_instance->time.heartbeat_interval) - ogs_timer_start(nf_instance->t_no_heartbeat, - ogs_time_from_sec( - nf_instance->time.heartbeat_interval + - ogs_app()->time.nf_instance. - no_heartbeat_margin)); - } else { - ogs_warn("[%s] HTTP response error [%d]", - 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]", - ogs_sbi_self()->nf_instance->id, - message->h.resource.component[0]); - END - break; - - DEFAULT - ogs_error("[%s] Invalid API name [%s]", - ogs_sbi_self()->nf_instance->id, message->h.service.name); - END - break; - - case UDR_EVT_SBI_TIMER: - switch(e->timer_id) { - case UDR_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - if (nf_instance->time.heartbeat_interval) - ogs_timer_start(nf_instance->t_heartbeat_interval, - ogs_time_from_sec(nf_instance->time.heartbeat_interval)); - - ogs_assert(true == ogs_nnrf_nfm_send_nf_update(nf_instance)); - break; - - case UDR_TIMER_NF_INSTANCE_NO_HEARTBEAT: - 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: - 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:%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; - - default: - 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; - } -} - -void udr_nf_state_de_registered(ogs_fsm_t *s, udr_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_assert(s); - ogs_assert(e); - - udr_sm_debug(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_NRF(nf_instance)) { - ogs_info("[%s] NF de-registered", ogs_sbi_self()->nf_instance->id); - } - break; - - case OGS_FSM_EXIT_SIG: - break; - - default: - 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; - } -} - -void udr_nf_state_exception(ogs_fsm_t *s, udr_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_sbi_client_t *client = NULL; - ogs_sbi_message_t *message = NULL; - ogs_sockaddr_t *addr = NULL; - ogs_assert(s); - ogs_assert(e); - - udr_sm_debug(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_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_NRF(nf_instance)) { - ogs_timer_stop(nf_instance->t_registration_interval); - } - break; - - case UDR_EVT_SBI_TIMER: - switch(e->timer_id) { - case UDR_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - client = nf_instance->client; - ogs_assert(client); - addr = client->node.addr; - ogs_assert(addr); - - 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:%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; - - case UDR_EVT_SBI_CLIENT: - message = e->sbi.message; - ogs_assert(message); - - SWITCH(message->h.service.name) - CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) - - SWITCH(message->h.resource.component[0]) - CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - break; - DEFAULT - ogs_error("Invalid resource name [%s]", - message->h.resource.component[0]); - END - break; - DEFAULT - ogs_error("Invalid API name [%s]", message->h.service.name); - END - break; - - default: - 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 deleted file mode 100644 index b6c047934..000000000 --- a/src/udr/nnrf-build.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2019,2020 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "nnrf-build.h" - -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; - - OpenAPI_nf_profile_t *NFProfile = 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_PUT; - message.h.service.name = (char *)OGS_SBI_SERVICE_NAME_NNRF_NFM; - 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] = nf_instance->id; - - message.http.content_encoding = (char*)ogs_sbi_self()->content_encoding; - - NFProfile = ogs_nnrf_nfm_build_nf_profile(); - ogs_expect_or_return_val(NFProfile, NULL); - - message.NFProfile = NFProfile; - - request = ogs_sbi_build_request(&message); - - ogs_sbi_nnrf_free_nf_profile(NFProfile); - - return request; -} diff --git a/src/udr/nnrf-build.h b/src/udr/nnrf-build.h deleted file mode 100644 index 95922a685..000000000 --- a/src/udr/nnrf-build.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2019,2020 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef UDR_NNRF_BUILD_H -#define UDR_NNRF_BUILD_H - -#include "context.h" - -#ifdef __cplusplus -extern "C" { -#endif - -ogs_sbi_request_t *udr_nnrf_nfm_build_register(void); - -#ifdef __cplusplus -} -#endif - -#endif /* UDR_NNRF_BUILD_H */ diff --git a/src/udr/nnrf-handler.c b/src/udr/nnrf-handler.c deleted file mode 100644 index 6874c5ccc..000000000 --- a/src/udr/nnrf-handler.c +++ /dev/null @@ -1,248 +0,0 @@ -/* - * Copyright (C) 2019,2020 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "sbi-path.h" -#include "nnrf-handler.h" - -void udr_nnrf_handle_nf_register( - ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_message_t *recvmsg) -{ - OpenAPI_nf_profile_t *NFProfile = NULL; - ogs_sbi_client_t *client = NULL; - - ogs_assert(recvmsg); - ogs_assert(nf_instance); - client = nf_instance->client; - ogs_assert(client); - - NFProfile = recvmsg->NFProfile; - if (!NFProfile) { - ogs_error("No NFProfile"); - return; - } - - /* TIME : Update heartbeat from NRF */ - if (NFProfile->is_heart_beat_timer == true) - nf_instance->time.heartbeat_interval = NFProfile->heart_beat_timer; -} - -void udr_nnrf_handle_nf_status_subscribe( - ogs_sbi_subscription_t *subscription, ogs_sbi_message_t *recvmsg) -{ - OpenAPI_subscription_data_t *SubscriptionData = NULL; - ogs_sbi_client_t *client = NULL; - - ogs_assert(recvmsg); - ogs_assert(subscription); - client = subscription->client; - ogs_assert(client); - - SubscriptionData = recvmsg->SubscriptionData; - if (!SubscriptionData) { - ogs_error("No SubscriptionData"); - return; - } - - if (!SubscriptionData->subscription_id) { - ogs_error("No SubscriptionId"); - return; - } - ogs_sbi_subscription_set_id( - subscription, SubscriptionData->subscription_id); - - if (SubscriptionData->validity_time) { -#define VALIDITY_MINIMUM (10LL * OGS_USEC_PER_SEC) /* 10 seconds */ - ogs_time_t time, duration; - if (ogs_sbi_time_from_string( - &time, SubscriptionData->validity_time) == true) { - duration = time - ogs_time_now(); - if (duration < VALIDITY_MINIMUM) { - duration = VALIDITY_MINIMUM; - ogs_warn("[%s] Forced to %lld seconds", subscription->id, - (long long)ogs_time_sec(VALIDITY_MINIMUM)); - } - subscription->t_validity = ogs_timer_add(ogs_app()->timer_mgr, - udr_timer_subscription_validity, subscription); - ogs_assert(subscription->t_validity); - ogs_timer_start(subscription->t_validity, duration); - } else { - ogs_error("Cannot parse validitiyTime [%s]", - SubscriptionData->validity_time); - } - } -} - -bool udr_nnrf_handle_nf_status_notify( - ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) -{ - int rv; - bool handled; - - ogs_sbi_response_t *response = NULL; - OpenAPI_notification_data_t *NotificationData = NULL; - ogs_sbi_nf_instance_t *nf_instance = NULL; - - ogs_sbi_message_t message; - ogs_sbi_header_t header; - - ogs_assert(stream); - ogs_assert(recvmsg); - - NotificationData = recvmsg->NotificationData; - if (!NotificationData) { - ogs_error("No NotificationData"); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "No NotificationData", NULL)); - return false; - } - - if (!NotificationData->nf_instance_uri) { - ogs_error("No nfInstanceUri"); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "No nfInstanceUri", NULL)); - return false; - } - - memset(&header, 0, sizeof(header)); - header.uri = NotificationData->nf_instance_uri; - - rv = ogs_sbi_parse_header(&message, &header); - if (rv != OGS_OK) { - ogs_error("Cannot parse nfInstanceUri [%s]", header.uri); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Cannot parse nfInstanceUri", header.uri)); - return false; - } - - if (!message.h.resource.component[1]) { - ogs_error("No nfInstanceId [%s]", header.uri); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Cannot parse nfInstanceUri", header.uri)); - ogs_sbi_header_free(&header); - return false; - } - - if (NF_INSTANCE_IS_SELF(message.h.resource.component[1])) { - ogs_warn("[%s] The notification is not allowed", - message.h.resource.component[1]); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, - recvmsg, "The notification is not allowed", - message.h.resource.component[1])); - ogs_sbi_header_free(&header); - return false; - } - - if (NotificationData->event == - OpenAPI_notification_event_type_NF_REGISTERED) { - - OpenAPI_nf_profile_t *NFProfile = NULL; - - NFProfile = NotificationData->nf_profile; - if (!NFProfile) { - ogs_error("No NFProfile"); - ogs_assert(true == - ogs_sbi_server_send_error( - stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "No NFProfile", NULL)); - ogs_sbi_header_free(&header); - return false; - } - - nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); - if (!nf_instance) { - 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); - - ogs_info("[%s] (NRF-notify) NF registered", nf_instance->id); - - } else { - OGS_FSM_TRAN(&nf_instance->sm, udr_nf_state_registered); - ogs_fsm_dispatch(&nf_instance->sm, NULL); - - ogs_warn("[%s] (NRF-notify) NF has already been added", - message.h.resource.component[1]); - - } - - handled = ogs_sbi_nnrf_handle_nf_profile( - nf_instance, NFProfile, stream, recvmsg); - if (!handled) { - UDR_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); - ogs_sbi_header_free(&header); - return false; - } - - ogs_info("[%s] (NRF-notify) NF Profile updated", nf_instance->id); - - handled = ogs_sbi_client_associate(nf_instance); - if (!handled) { - ogs_error("[%s] Cannot associate NF EndPoint", nf_instance->id); - ogs_assert(true == - ogs_sbi_server_send_error(stream, - OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Cannot find NF EndPoint", nf_instance->id)); - UDR_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); - ogs_sbi_header_free(&header); - return false; - } - - } else if (NotificationData->event == - OpenAPI_notification_event_type_NF_DEREGISTERED) { - nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); - if (nf_instance) { - UDR_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); - } else { - ogs_warn("[%s] (NRF-notify) Not found", - message.h.resource.component[1]); - ogs_assert(true == - ogs_sbi_server_send_error(stream, - OGS_SBI_HTTP_STATUS_NOT_FOUND, - recvmsg, "Not found", message.h.resource.component[1])); - ogs_sbi_header_free(&header); - return false; - } - } else { - char *eventstr = OpenAPI_notification_event_type_ToString( - NotificationData->event); - ogs_error("Not supported event [%d:%s]", - NotificationData->event, eventstr ? eventstr : "Unknown"); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Not supported event", - eventstr ? eventstr : "Unknown")); - ogs_sbi_header_free(&header); - return false; - } - - response = ogs_sbi_build_response(recvmsg, OGS_SBI_HTTP_STATUS_NO_CONTENT); - ogs_assert(response); - ogs_assert(true == ogs_sbi_server_send_response(stream, response)); - - ogs_sbi_header_free(&header); - return true; -} diff --git a/src/udr/nnrf-handler.h b/src/udr/nnrf-handler.h deleted file mode 100644 index a257e5119..000000000 --- a/src/udr/nnrf-handler.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2019,2020 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef UDR_NNRF_HANDLER_H -#define UDR_NNRF_HANDLER_H - -#include "context.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void udr_nnrf_handle_nf_register( - ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_message_t *recvmsg); -void udr_nnrf_handle_nf_status_subscribe( - ogs_sbi_subscription_t *subscription, ogs_sbi_message_t *recvmsg); - -bool udr_nnrf_handle_nf_status_notify( - ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); - -#ifdef __cplusplus -} -#endif - -#endif /* UDR_NNRF_HANDLER_H */ diff --git a/src/udr/nudr-handler.c b/src/udr/nudr-handler.c index 7ece34180..8791d17d8 100644 --- a/src/udr/nudr-handler.c +++ b/src/udr/nudr-handler.c @@ -18,7 +18,6 @@ */ #include "sbi-path.h" -#include "nnrf-handler.h" #include "nudr-handler.h" bool udr_nudr_dr_handle_subscription_authentication( diff --git a/src/udr/sbi-path.c b/src/udr/sbi-path.c index a30d9b64c..3de425113 100644 --- a/src/udr/sbi-path.c +++ b/src/udr/sbi-path.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -27,17 +27,17 @@ static int server_cb(ogs_sbi_request_t *request, void *data) ogs_assert(request); ogs_assert(data); - e = udr_event_new(UDR_EVT_SBI_SERVER); + e = udr_event_new(OGS_EVENT_SBI_SERVER); ogs_assert(e); - e->sbi.request = request; - e->sbi.data = data; + e->h.sbi.request = request; + e->h.sbi.data = data; rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed:%d", (int)rv); ogs_sbi_request_free(request); - udr_event_free(e); + ogs_event_free(e); return OGS_ERROR; } @@ -58,16 +58,16 @@ static int client_cb(int status, ogs_sbi_response_t *response, void *data) ogs_assert(response); - e = udr_event_new(UDR_EVT_SBI_CLIENT); + e = udr_event_new(OGS_EVENT_SBI_CLIENT); ogs_assert(e); - e->sbi.response = response; - e->sbi.data = data; + e->h.sbi.response = response; + e->h.sbi.data = data; rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed:%d", (int)rv); ogs_sbi_response_free(response); - udr_event_free(e); + ogs_event_free(e); return OGS_ERROR; } @@ -100,28 +100,20 @@ int udr_sbi_open(void) } /* Initialize NRF NF Instance */ - ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) { - if (NF_INSTANCE_IS_NRF(nf_instance)) { - ogs_sbi_client_t *client = NULL; + nf_instance = ogs_sbi_self()->nrf_instance; + if (nf_instance) { + ogs_sbi_client_t *client = NULL; - /* Client callback is only used when NF sends to NRF */ - client = nf_instance->client; - ogs_assert(client); - client->cb = client_cb; + /* 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. */ + ogs_sbi_nf_fsm_init(nf_instance); } - /* Timer expiration handler of client wait timer */ - ogs_sbi_self()->client_wait_expire = udr_timer_sbi_client_wait_expire; - - /* NF register state in NF state machine */ - ogs_sbi_self()->nf_state_registered = - (ogs_fsm_handler_t)udr_nf_state_registered; - if (ogs_sbi_server_start_all(server_cb) != OGS_OK) return OGS_ERROR; diff --git a/src/udr/sbi-path.h b/src/udr/sbi-path.h index f0a0e29f3..d611d5ebe 100644 --- a/src/udr/sbi-path.h +++ b/src/udr/sbi-path.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -20,7 +20,7 @@ #ifndef UDR_SBI_PATH_H #define UDR_SBI_PATH_H -#include "nnrf-build.h" +#include "context.h" #ifdef __cplusplus extern "C" { diff --git a/src/udr/timer.c b/src/udr/timer.c deleted file mode 100644 index e672f3724..000000000 --- a/src/udr/timer.c +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (C) 2019,2020 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "context.h" - -const char *udr_timer_get_name(udr_timer_e id) -{ - switch (id) { - case UDR_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - return "UDR_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL"; - case UDR_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - return "UDR_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL"; - case UDR_TIMER_NF_INSTANCE_NO_HEARTBEAT: - return "UDR_TIMER_NF_INSTANCE_NO_HEARTBEAT"; - case UDR_TIMER_NF_INSTANCE_VALIDITY: - return "UDR_TIMER_NF_INSTANCE_VALIDITY"; - case UDR_TIMER_SUBSCRIPTION_VALIDITY: - return "UDR_TIMER_SUBSCRIPTION_VALIDITY"; - default: - break; - } - - return "UNKNOWN_TIMER"; -} - -static void sbi_timer_send_event(int timer_id, void *data) -{ - int rv; - udr_event_t *e = NULL; - ogs_assert(data); - - switch (timer_id) { - case UDR_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - case UDR_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - case UDR_TIMER_NF_INSTANCE_NO_HEARTBEAT: - case UDR_TIMER_NF_INSTANCE_VALIDITY: - case UDR_TIMER_SUBSCRIPTION_VALIDITY: - e = udr_event_new(UDR_EVT_SBI_TIMER); - ogs_assert(e); - e->timer_id = timer_id; - e->sbi.data = data; - break; - default: - ogs_fatal("Unknown timer id[%d]", timer_id); - ogs_assert_if_reached(); - break; - } - - rv = ogs_queue_push(ogs_app()->queue, e); - if (rv != OGS_OK) { - ogs_error("ogs_queue_push() failed [%d] in %s", - (int)rv, udr_timer_get_name(e->timer_id)); - udr_event_free(e); - } -} - -void udr_timer_nf_instance_registration_interval(void *data) -{ - sbi_timer_send_event(UDR_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL, data); -} - -void udr_timer_nf_instance_heartbeat_interval(void *data) -{ - sbi_timer_send_event(UDR_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL, data); -} - -void udr_timer_nf_instance_no_heartbeat(void *data) -{ - sbi_timer_send_event(UDR_TIMER_NF_INSTANCE_NO_HEARTBEAT, data); -} - -void udr_timer_nf_instance_validity(void *data) -{ - sbi_timer_send_event(UDR_TIMER_NF_INSTANCE_VALIDITY, data); -} - -void udr_timer_subscription_validity(void *data) -{ - sbi_timer_send_event(UDR_TIMER_SUBSCRIPTION_VALIDITY, data); -} - -void udr_timer_sbi_client_wait_expire(void *data) -{ - sbi_timer_send_event(UDR_TIMER_SBI_CLIENT_WAIT, data); -} diff --git a/src/udr/timer.h b/src/udr/timer.h deleted file mode 100644 index 7f078afb8..000000000 --- a/src/udr/timer.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2019 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef UDR_TIMER_H -#define UDR_TIMER_H - -#include "ogs-core.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* forward declaration */ -typedef enum { - UDR_TIMER_BASE = 0, - - UDR_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL, - UDR_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL, - UDR_TIMER_NF_INSTANCE_NO_HEARTBEAT, - UDR_TIMER_NF_INSTANCE_VALIDITY, - UDR_TIMER_SUBSCRIPTION_VALIDITY, - UDR_TIMER_SBI_CLIENT_WAIT, - - MAX_NUM_OF_UDR_TIMER, - -} udr_timer_e; - -const char *udr_timer_get_name(udr_timer_e id); - -void udr_timer_nf_instance_registration_interval(void *data); -void udr_timer_nf_instance_heartbeat_interval(void *data); -void udr_timer_nf_instance_no_heartbeat(void *data); -void udr_timer_nf_instance_validity(void *data); -void udr_timer_subscription_validity(void *data); -void udr_timer_sbi_client_wait_expire(void *data); - -#ifdef __cplusplus -} -#endif - -#endif /* UDR_TIMER_H */ diff --git a/src/udr/udr-sm.c b/src/udr/udr-sm.c index 8d661cab8..86ddb7b13 100644 --- a/src/udr/udr-sm.c +++ b/src/udr/udr-sm.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -18,7 +18,6 @@ */ #include "sbi-path.h" -#include "nnrf-handler.h" #include "nudr-handler.h" void udr_state_initial(ogs_fsm_t *s, udr_event_t *e) @@ -53,17 +52,17 @@ void udr_state_operational(ogs_fsm_t *s, udr_event_t *e) ogs_assert(s); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: break; case OGS_FSM_EXIT_SIG: break; - case UDR_EVT_SBI_SERVER: - request = e->sbi.request; + case OGS_EVENT_SBI_SERVER: + request = e->h.sbi.request; ogs_assert(request); - stream = e->sbi.data; + stream = e->h.sbi.data; ogs_assert(stream); rv = ogs_sbi_parse_request(&message, request); @@ -94,7 +93,7 @@ void udr_state_operational(ogs_fsm_t *s, udr_event_t *e) CASE(OGS_SBI_RESOURCE_NAME_NF_STATUS_NOTIFY) SWITCH(message.h.method) CASE(OGS_SBI_HTTP_METHOD_POST) - udr_nnrf_handle_nf_status_notify(stream, &message); + ogs_nnrf_handle_nf_status_notify(stream, &message); break; DEFAULT @@ -188,10 +187,10 @@ void udr_state_operational(ogs_fsm_t *s, udr_event_t *e) ogs_sbi_message_free(&message); break; - case UDR_EVT_SBI_CLIENT: + case OGS_EVENT_SBI_CLIENT: ogs_assert(e); - response = e->sbi.response; + response = e->h.sbi.response; ogs_assert(response); rv = ogs_sbi_parse_response(&message, response); if (rv != OGS_OK) { @@ -213,23 +212,23 @@ void udr_state_operational(ogs_fsm_t *s, udr_event_t *e) SWITCH(message.h.resource.component[0]) CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - nf_instance = e->sbi.data; + nf_instance = e->h.sbi.data; ogs_assert(nf_instance); ogs_assert(OGS_FSM_STATE(&nf_instance->sm)); - e->sbi.message = &message; + e->h.sbi.message = &message; ogs_fsm_dispatch(&nf_instance->sm, e); break; CASE(OGS_SBI_RESOURCE_NAME_SUBSCRIPTIONS) - subscription = e->sbi.data; + subscription = e->h.sbi.data; ogs_assert(subscription); SWITCH(message.h.method) CASE(OGS_SBI_HTTP_METHOD_POST) if (message.res_status == OGS_SBI_HTTP_STATUS_CREATED || message.res_status == OGS_SBI_HTTP_STATUS_OK) { - udr_nnrf_handle_nf_status_subscribe( + ogs_nnrf_handle_nf_status_subscribe( subscription, &message); } else { ogs_error("[%s] HTTP response error [%d]", @@ -270,26 +269,26 @@ void udr_state_operational(ogs_fsm_t *s, udr_event_t *e) ogs_sbi_response_free(response); break; - case UDR_EVT_SBI_TIMER: + case OGS_EVENT_SBI_TIMER: ogs_assert(e); - switch(e->timer_id) { - case UDR_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - case UDR_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - case UDR_TIMER_NF_INSTANCE_NO_HEARTBEAT: - case UDR_TIMER_NF_INSTANCE_VALIDITY: - nf_instance = e->sbi.data; + switch(e->h.timer_id) { + case OGS_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: + case OGS_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: + case OGS_TIMER_NF_INSTANCE_NO_HEARTBEAT: + case OGS_TIMER_NF_INSTANCE_VALIDITY: + nf_instance = e->h.sbi.data; ogs_assert(nf_instance); ogs_assert(OGS_FSM_STATE(&nf_instance->sm)); ogs_fsm_dispatch(&nf_instance->sm, e); - if (OGS_FSM_CHECK(&nf_instance->sm, udr_nf_state_exception)) + if (OGS_FSM_CHECK(&nf_instance->sm, ogs_sbi_nf_state_exception)) ogs_error("[%s] State machine exception [%d]", - nf_instance->id, e->timer_id); + nf_instance->id, e->h.timer_id); break; - case UDR_TIMER_SUBSCRIPTION_VALIDITY: - subscription = e->sbi.data; + case OGS_TIMER_SUBSCRIPTION_VALIDITY: + subscription = e->h.sbi.data; ogs_assert(subscription); ogs_assert(ogs_sbi_self()->nf_instance); @@ -305,7 +304,7 @@ void udr_state_operational(ogs_fsm_t *s, udr_event_t *e) default: ogs_error("Unknown timer[%s:%d]", - udr_timer_get_name(e->timer_id), e->timer_id); + ogs_timer_get_name(e->h.timer_id), e->h.timer_id); } break; diff --git a/src/udr/udr-sm.h b/src/udr/udr-sm.h index a2eb17910..518e56dcf 100644 --- a/src/udr/udr-sm.h +++ b/src/udr/udr-sm.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019,2020 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * diff --git a/src/upf/event.h b/src/upf/event.h index 9914c608c..8fe4c0c12 100644 --- a/src/upf/event.h +++ b/src/upf/event.h @@ -20,7 +20,7 @@ #ifndef UPF_EVENT_H #define UPF_EVENT_H -#include "ogs-core.h" +#include "ogs-proto.h" #ifdef __cplusplus extern "C" { @@ -32,7 +32,7 @@ typedef struct ogs_pfcp_message_s ogs_pfcp_message_t; typedef struct upf_sess_s upf_sess_t; typedef enum { - UPF_EVT_BASE = OGS_FSM_USER_SIG, + UPF_EVT_BASE = OGS_MAX_NUM_OF_PROTO_EVENT, UPF_EVT_N4_MESSAGE, UPF_EVT_N4_TIMER, @@ -44,9 +44,10 @@ typedef enum { typedef struct upf_event_s { int id; - ogs_pkbuf_t *pkbuf; int timer_id; + ogs_pkbuf_t *pkbuf; + ogs_pfcp_node_t *pfcp_node; ogs_pfcp_xact_t *pfcp_xact; ogs_pfcp_message_t *pfcp_message; diff --git a/src/upf/init.c b/src/upf/init.c index 2a217867f..92d38014a 100644 --- a/src/upf/init.c +++ b/src/upf/init.c @@ -97,8 +97,7 @@ static void upf_main(void *data) ogs_fsm_t upf_sm; int rv; - ogs_fsm_create(&upf_sm, upf_state_initial, upf_state_final); - ogs_fsm_init(&upf_sm, 0); + ogs_fsm_init(&upf_sm, upf_state_initial, upf_state_final, 0); for ( ;; ) { ogs_pollset_poll(ogs_app()->pollset, @@ -137,5 +136,4 @@ static void upf_main(void *data) done: ogs_fsm_fini(&upf_sm, 0); - ogs_fsm_delete(&upf_sm); } diff --git a/src/upf/pfcp-path.c b/src/upf/pfcp-path.c index 4888d1627..13cc1bb44 100644 --- a/src/upf/pfcp-path.c +++ b/src/upf/pfcp-path.c @@ -37,8 +37,7 @@ static void pfcp_node_fsm_init(ogs_pfcp_node_t *node, bool try_to_assoicate) ogs_assert(node->t_association); } - ogs_fsm_create(&node->sm, upf_pfcp_state_initial, upf_pfcp_state_final); - ogs_fsm_init(&node->sm, &e); + ogs_fsm_init(&node->sm, upf_pfcp_state_initial, upf_pfcp_state_final, &e); } static void pfcp_node_fsm_fini(ogs_pfcp_node_t *node) @@ -51,7 +50,6 @@ static void pfcp_node_fsm_fini(ogs_pfcp_node_t *node) e.pfcp_node = node; ogs_fsm_fini(&node->sm, &e); - ogs_fsm_delete(&node->sm); if (node->t_association) ogs_timer_delete(node->t_association); diff --git a/tests/af/af-sm.c b/tests/af/af-sm.c index a1c05164e..9ac11ffb6 100644 --- a/tests/af/af-sm.c +++ b/tests/af/af-sm.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -57,17 +57,17 @@ void af_state_operational(ogs_fsm_t *s, af_event_t *e) ogs_assert(s); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: break; case OGS_FSM_EXIT_SIG: break; - case AF_EVT_SBI_SERVER: - request = e->sbi.request; + case OGS_EVENT_SBI_SERVER: + request = e->h.sbi.request; ogs_assert(request); - stream = e->sbi.data; + stream = e->h.sbi.data; ogs_assert(stream); rv = ogs_sbi_parse_request(&message, request); @@ -98,7 +98,7 @@ void af_state_operational(ogs_fsm_t *s, af_event_t *e) CASE(OGS_SBI_RESOURCE_NAME_NF_STATUS_NOTIFY) SWITCH(message.h.method) CASE(OGS_SBI_HTTP_METHOD_POST) - af_nnrf_handle_nf_status_notify(stream, &message); + ogs_nnrf_handle_nf_status_notify(stream, &message); break; DEFAULT @@ -189,10 +189,10 @@ void af_state_operational(ogs_fsm_t *s, af_event_t *e) ogs_sbi_message_free(&message); break; - case AF_EVT_SBI_CLIENT: + case OGS_EVENT_SBI_CLIENT: ogs_assert(e); - response = e->sbi.response; + response = e->h.sbi.response; ogs_assert(response); rv = ogs_sbi_parse_response(&message, response); if (rv != OGS_OK) { @@ -214,23 +214,23 @@ void af_state_operational(ogs_fsm_t *s, af_event_t *e) SWITCH(message.h.resource.component[0]) CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - nf_instance = e->sbi.data; + nf_instance = e->h.sbi.data; ogs_assert(nf_instance); ogs_assert(OGS_FSM_STATE(&nf_instance->sm)); - e->sbi.message = &message; + e->h.sbi.message = &message; ogs_fsm_dispatch(&nf_instance->sm, e); break; CASE(OGS_SBI_RESOURCE_NAME_SUBSCRIPTIONS) - subscription = e->sbi.data; + subscription = e->h.sbi.data; ogs_assert(subscription); SWITCH(message.h.method) CASE(OGS_SBI_HTTP_METHOD_POST) if (message.res_status == OGS_SBI_HTTP_STATUS_CREATED || message.res_status == OGS_SBI_HTTP_STATUS_OK) { - af_nnrf_handle_nf_status_subscribe( + ogs_nnrf_handle_nf_status_subscribe( subscription, &message); } else { ogs_error("HTTP response error : %d", @@ -263,7 +263,7 @@ void af_state_operational(ogs_fsm_t *s, af_event_t *e) CASE(OGS_SBI_SERVICE_NAME_NNRF_DISC) SWITCH(message.h.resource.component[0]) CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - sbi_xact = e->sbi.data; + sbi_xact = e->h.sbi.data; ogs_assert(sbi_xact); SWITCH(message.h.method) @@ -291,7 +291,7 @@ void af_state_operational(ogs_fsm_t *s, af_event_t *e) CASE(OGS_SBI_SERVICE_NAME_NBSF_MANAGEMENT) SWITCH(message.h.resource.component[0]) CASE(OGS_SBI_RESOURCE_NAME_PCF_BINDINGS) - sbi_xact = e->sbi.data; + sbi_xact = e->h.sbi.data; ogs_assert(sbi_xact); sbi_xact = ogs_sbi_xact_cycle(sbi_xact); @@ -331,7 +331,7 @@ void af_state_operational(ogs_fsm_t *s, af_event_t *e) CASE(OGS_SBI_SERVICE_NAME_NPCF_POLICYAUTHORIZATION) SWITCH(message.h.resource.component[0]) CASE(OGS_SBI_RESOURCE_NAME_APP_SESSIONS) - sess = e->sbi.data; + sess = e->h.sbi.data; ogs_assert(sess); if (message.h.resource.component[1]) { @@ -393,25 +393,25 @@ void af_state_operational(ogs_fsm_t *s, af_event_t *e) ogs_sbi_response_free(response); break; - case AF_EVT_SBI_TIMER: + case OGS_EVENT_SBI_TIMER: ogs_assert(e); - switch(e->timer_id) { - case AF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - case AF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - case AF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - case AF_TIMER_NF_INSTANCE_VALIDITY: - nf_instance = e->sbi.data; + switch(e->h.timer_id) { + case OGS_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: + case OGS_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: + case OGS_TIMER_NF_INSTANCE_NO_HEARTBEAT: + case OGS_TIMER_NF_INSTANCE_VALIDITY: + nf_instance = e->h.sbi.data; ogs_assert(nf_instance); ogs_assert(OGS_FSM_STATE(&nf_instance->sm)); ogs_fsm_dispatch(&nf_instance->sm, e); - if (OGS_FSM_CHECK(&nf_instance->sm, af_nf_state_exception)) - ogs_error("State machine exception [%d]", e->timer_id); + if (OGS_FSM_CHECK(&nf_instance->sm, ogs_sbi_nf_state_exception)) + ogs_error("State machine exception [%d]", e->h.timer_id); break; - case AF_TIMER_SUBSCRIPTION_VALIDITY: - subscription = e->sbi.data; + case OGS_TIMER_SUBSCRIPTION_VALIDITY: + subscription = e->h.sbi.data; ogs_assert(subscription); ogs_assert(ogs_sbi_self()->nf_instance); @@ -425,8 +425,8 @@ void af_state_operational(ogs_fsm_t *s, af_event_t *e) ogs_sbi_subscription_remove(subscription); break; - case AF_TIMER_SBI_CLIENT_WAIT: - sbi_xact = e->sbi.data; + case OGS_TIMER_SBI_CLIENT_WAIT: + sbi_xact = e->h.sbi.data; ogs_assert(sbi_xact); stream = sbi_xact->assoc_stream; @@ -446,7 +446,7 @@ void af_state_operational(ogs_fsm_t *s, af_event_t *e) default: ogs_error("Unknown timer[%s:%d]", - af_timer_get_name(e->timer_id), e->timer_id); + ogs_timer_get_name(e->h.timer_id), e->h.timer_id); } break; diff --git a/tests/af/af-sm.h b/tests/af/af-sm.h index 7fa09e683..ac3b1db91 100644 --- a/tests/af/af-sm.h +++ b/tests/af/af-sm.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -31,16 +31,6 @@ void af_state_final(ogs_fsm_t *s, af_event_t *e); void af_state_operational(ogs_fsm_t *s, af_event_t *e); void af_state_exception(ogs_fsm_t *s, af_event_t *e); -void af_nf_fsm_init(ogs_sbi_nf_instance_t *nf_instance); -void af_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance); - -void af_nf_state_initial(ogs_fsm_t *s, af_event_t *e); -void af_nf_state_final(ogs_fsm_t *s, af_event_t *e); -void af_nf_state_will_register(ogs_fsm_t *s, af_event_t *e); -void af_nf_state_registered(ogs_fsm_t *s, af_event_t *e); -void af_nf_state_de_registered(ogs_fsm_t *s, af_event_t *e); -void af_nf_state_exception(ogs_fsm_t *s, af_event_t *e); - #define af_sm_debug(__pe) \ ogs_debug("%s(): %s", __func__, af_event_get_name(__pe)) diff --git a/tests/af/context.c b/tests/af/context.c index 886217f16..8135aaceb 100644 --- a/tests/af/context.c +++ b/tests/af/context.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * diff --git a/tests/af/context.h b/tests/af/context.h index ee9737549..e2f323b06 100644 --- a/tests/af/context.h +++ b/tests/af/context.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -24,7 +24,6 @@ #include "ogs-app.h" #include "event.h" -#include "timer.h" #include "local.h" #include "af-sm.h" @@ -46,22 +45,6 @@ typedef struct af_context_s { ogs_list_t sess_list; } af_context_t; -#define AF_NF_INSTANCE_CLEAR(_cAUSE, _nFInstance) \ - do { \ - ogs_assert(_nFInstance); \ - if ((_nFInstance)->reference_count == 1) { \ - ogs_info("[%s] (%s) NF removed", (_nFInstance)->id, (_cAUSE)); \ - af_nf_fsm_fini((_nFInstance)); \ - ogs_sbi_nf_instance_remove(_nFInstance); \ - } else { \ - /* There is an assocation with other context */ \ - ogs_info("[%s:%d] (%s) NF suspended", \ - _nFInstance->id, _nFInstance->reference_count, (_cAUSE)); \ - OGS_FSM_TRAN(&_nFInstance->sm, af_nf_state_de_registered); \ - ogs_fsm_dispatch(&_nFInstance->sm, NULL); \ - } \ - } while(0) - typedef struct af_sess_s af_sess_t; typedef struct af_sess_s { diff --git a/tests/af/event.c b/tests/af/event.c index f2e8cfedf..4274047f4 100644 --- a/tests/af/event.c +++ b/tests/af/event.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -19,54 +19,37 @@ #include "context.h" -static OGS_POOL(pool, af_event_t); - -void af_event_init(void) -{ - ogs_pool_init(&pool, ogs_app()->pool.event); -} - -void af_event_final(void) -{ - ogs_pool_final(&pool); -} - -af_event_t *af_event_new(af_event_e id) +af_event_t *af_event_new(int id) { af_event_t *e = NULL; - ogs_pool_alloc(&pool, &e); + e = ogs_event_size(id, sizeof(af_event_t)); ogs_assert(e); - memset(e, 0, sizeof(*e)); - e->id = id; + e->h.id = id; return e; } -void af_event_free(af_event_t *e) -{ - ogs_assert(e); - ogs_pool_free(&pool, e); -} - const char *af_event_get_name(af_event_t *e) { - if (e == NULL) + if (e == NULL) { return OGS_FSM_NAME_INIT_SIG; + } - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: return OGS_FSM_NAME_ENTRY_SIG; case OGS_FSM_EXIT_SIG: return OGS_FSM_NAME_EXIT_SIG; - case AF_EVT_SBI_SERVER: - return "AF_EVT_SBI_SERVER"; - case AF_EVT_SBI_CLIENT: - return "AF_EVT_SBI_CLIENT"; - case AF_EVT_SBI_TIMER: - return "AF_EVT_SBI_TIMER"; + case OGS_EVENT_SBI_SERVER: + return OGS_EVENT_NAME_SBI_SERVER; + case OGS_EVENT_SBI_CLIENT: + return OGS_EVENT_NAME_SBI_CLIENT; + case OGS_EVENT_SBI_TIMER: + return OGS_EVENT_NAME_SBI_TIMER; + case AF_EVT_SBI_LOCAL: return "AF_EVT_SBI_LOCAL"; @@ -74,5 +57,6 @@ const char *af_event_get_name(af_event_t *e) break; } + ogs_error("Unknown Event[%d]", e->h.id); return "UNKNOWN_EVENT"; } diff --git a/tests/af/event.h b/tests/af/event.h index 22178d8ee..cb3349bc7 100644 --- a/tests/af/event.h +++ b/tests/af/event.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -20,24 +20,17 @@ #ifndef AF_EVENT_H #define AF_EVENT_H -#include "ogs-core.h" +#include "ogs-proto.h" #ifdef __cplusplus extern "C" { #endif typedef struct af_sess_s af_sess_t; -typedef struct ogs_sbi_request_s ogs_sbi_request_t; -typedef struct ogs_sbi_response_s ogs_sbi_response_t; -typedef struct ogs_sbi_message_s ogs_sbi_message_t; -typedef struct ogs_sbi_subscription_s ogs_sbi_subscription_t; typedef enum { - AF_EVT_BASE = OGS_FSM_USER_SIG, + AF_EVT_BASE = OGS_MAX_NUM_OF_PROTO_EVENT, - AF_EVT_SBI_SERVER, - AF_EVT_SBI_CLIENT, - AF_EVT_SBI_TIMER, AF_EVT_SBI_LOCAL, AF_EVT_TOP, @@ -45,34 +38,21 @@ typedef enum { } af_event_e; typedef struct af_event_s { - int id; - ogs_pkbuf_t *pkbuf; - int timer_id; + ogs_event_t h; int local_id; + ogs_pkbuf_t *pkbuf; + struct { OpenAPI_nf_type_e target_nf_type; void *data; ogs_sbi_request_t *(*build)(af_sess_t *sess, void *data); } local; - struct { - ogs_sbi_request_t *request; - ogs_sbi_response_t *response; - void *data; - int state; - - ogs_sbi_message_t *message; - } sbi; - af_sess_t *sess; } af_event_t; -void af_event_init(void); -void af_event_final(void); - -af_event_t *af_event_new(af_event_e id); -void af_event_free(af_event_t *e); +af_event_t *af_event_new(int id); const char *af_event_get_name(af_event_t *e); diff --git a/tests/af/init.c b/tests/af/init.c index 9fafca223..59685e864 100644 --- a/tests/af/init.c +++ b/tests/af/init.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -32,7 +32,6 @@ int af_initialize() ogs_sbi_context_init(); af_context_init(); - af_event_init(); rv = ogs_sbi_context_parse_config("af", "nrf", "scp"); if (rv != OGS_OK) return rv; @@ -63,7 +62,7 @@ static void event_termination(void) /* Sending NF Instance De-registeration to NRF */ ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) - af_nf_fsm_fini(nf_instance); + ogs_sbi_nf_fsm_fini(nf_instance); /* Starting holding timer */ t_termination_holding = ogs_timer_add(ogs_app()->timer_mgr, NULL, NULL); @@ -88,10 +87,7 @@ void af_terminate(void) af_sbi_close(); af_context_final(); - ogs_sbi_context_final(); - - af_event_final(); /* Destroy event */ } static void af_main(void *data) @@ -99,8 +95,7 @@ static void af_main(void *data) ogs_fsm_t af_sm; int rv; - ogs_fsm_create(&af_sm, af_state_initial, af_state_final); - ogs_fsm_init(&af_sm, 0); + ogs_fsm_init(&af_sm, af_state_initial, af_state_final, 0); for ( ;; ) { ogs_pollset_poll(ogs_app()->pollset, @@ -133,11 +128,10 @@ static void af_main(void *data) ogs_assert(e); ogs_fsm_dispatch(&af_sm, e); - af_event_free(e); + ogs_event_free(e); } } done: ogs_fsm_fini(&af_sm, 0); - ogs_fsm_delete(&af_sm); } diff --git a/tests/af/init.h b/tests/af/init.h index e351f7f2d..7a0cc6bc2 100644 --- a/tests/af/init.h +++ b/tests/af/init.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * diff --git a/tests/af/local.c b/tests/af/local.c index 9e7fd0e97..73c65628e 100644 --- a/tests/af/local.c +++ b/tests/af/local.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -51,8 +51,8 @@ void af_local_discover_and_send(OpenAPI_nf_type_e target_nf_type, rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed [%d] in %s", - (int)rv, af_timer_get_name(e->timer_id)); - af_event_free(e); + (int)rv, af_local_get_name(e->local_id)); + ogs_event_free(e); } else { ogs_pollset_notify(ogs_app()->pollset); } @@ -77,8 +77,8 @@ void af_local_send_to_pcf( rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed [%d] in %s", - (int)rv, af_timer_get_name(e->timer_id)); - af_event_free(e); + (int)rv, af_local_get_name(e->local_id)); + ogs_event_free(e); } else { ogs_pollset_notify(ogs_app()->pollset); } diff --git a/tests/af/local.h b/tests/af/local.h index dc5a04f04..aca1177fa 100644 --- a/tests/af/local.h +++ b/tests/af/local.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * diff --git a/tests/af/meson.build b/tests/af/meson.build index 80d1f4b10..18a240337 100644 --- a/tests/af/meson.build +++ b/tests/af/meson.build @@ -1,4 +1,4 @@ -# Copyright (C) 2019,2020 by Sukchan Lee +# Copyright (C) 2019-2022 by Sukchan Lee # This file is part of Open5GS. @@ -18,12 +18,9 @@ libaf_sources = files(''' context.c event.c - timer.c local.c - nnrf-build.c nnrf-handler.c - nf-sm.c nbsf-build.c nbsf-handler.c diff --git a/tests/af/nbsf-handler.c b/tests/af/nbsf-handler.c index f2ada6bcc..d7a73d91b 100644 --- a/tests/af/nbsf-handler.c +++ b/tests/af/nbsf-handler.c @@ -28,9 +28,6 @@ void af_nbsf_management_handle_pcf_binding( OpenAPI_pcf_binding_t *PcfBinding = NULL; OpenAPI_list_t *PcfIpEndPointList = NULL; OpenAPI_lnode_t *node = NULL; -#if SBI_FQDN_WITH_ONE_OCTET_LENGTH - char fqdn[OGS_MAX_FQDN_LEN]; -#endif ogs_assert(sess); ogs_assert(recvmsg); @@ -46,19 +43,10 @@ void af_nbsf_management_handle_pcf_binding( } if (PcfBinding->pcf_fqdn) { -#if SBI_FQDN_WITH_ONE_OCTET_LENGTH - ogs_assert(0 < ogs_fqdn_parse(fqdn, PcfBinding->pcf_fqdn, - ogs_min(strlen(PcfBinding->pcf_fqdn), OGS_MAX_FQDN_LEN))); - if (sess->pcf.fqdn) - ogs_free(sess->pcf.fqdn); - sess->pcf.fqdn = ogs_strdup(fqdn); - ogs_assert(sess->pcf.fqdn); -#else if (sess->pcf.fqdn) ogs_free(sess->pcf.fqdn); sess->pcf.fqdn = ogs_strdup(PcfBinding->pcf_fqdn); ogs_assert(sess->pcf.fqdn); -#endif } PcfIpEndPointList = PcfBinding->pcf_ip_end_points; diff --git a/tests/af/nf-sm.c b/tests/af/nf-sm.c deleted file mode 100644 index 6fc9daefb..000000000 --- a/tests/af/nf-sm.c +++ /dev/null @@ -1,448 +0,0 @@ -/* - * Copyright (C) 2019 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "context.h" - -#include "sbi-path.h" -#include "nnrf-handler.h" - -void af_nf_fsm_init(ogs_sbi_nf_instance_t *nf_instance) -{ - af_event_t e; - - ogs_assert(nf_instance); - - memset(&e, 0, sizeof(e)); - e.sbi.data = nf_instance; - - ogs_fsm_create(&nf_instance->sm, - af_nf_state_initial, af_nf_state_final); - ogs_fsm_init(&nf_instance->sm, &e); -} - -void af_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance) -{ - af_event_t e; - - ogs_assert(nf_instance); - - memset(&e, 0, sizeof(e)); - e.sbi.data = nf_instance; - - ogs_fsm_fini(&nf_instance->sm, &e); - ogs_fsm_delete(&nf_instance->sm); -} - -void af_nf_state_initial(ogs_fsm_t *s, af_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - - ogs_assert(s); - ogs_assert(e); - - af_sm_debug(e); - - nf_instance = e->sbi.data; - ogs_assert(nf_instance); - - nf_instance->t_registration_interval = ogs_timer_add(ogs_app()->timer_mgr, - af_timer_nf_instance_registration_interval, nf_instance); - ogs_assert(nf_instance->t_registration_interval); - nf_instance->t_heartbeat_interval = ogs_timer_add(ogs_app()->timer_mgr, - af_timer_nf_instance_heartbeat_interval, nf_instance); - ogs_assert(nf_instance->t_heartbeat_interval); - nf_instance->t_no_heartbeat = ogs_timer_add(ogs_app()->timer_mgr, - af_timer_nf_instance_no_heartbeat, nf_instance); - ogs_assert(nf_instance->t_no_heartbeat); - nf_instance->t_validity = ogs_timer_add(ogs_app()->timer_mgr, - af_timer_nf_instance_validity, nf_instance); - ogs_assert(nf_instance->t_validity); - - 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); - } -} - -void af_nf_state_final(ogs_fsm_t *s, af_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - - ogs_assert(s); - ogs_assert(e); - - af_sm_debug(e); - - nf_instance = e->sbi.data; - ogs_assert(nf_instance); - - ogs_timer_delete(nf_instance->t_registration_interval); - ogs_timer_delete(nf_instance->t_heartbeat_interval); - ogs_timer_delete(nf_instance->t_no_heartbeat); - ogs_timer_delete(nf_instance->t_validity); -} - -void af_nf_state_will_register(ogs_fsm_t *s, af_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_sbi_client_t *client = NULL; - ogs_sbi_message_t *message = NULL; - ogs_sockaddr_t *addr = NULL; - - ogs_assert(s); - ogs_assert(e); - - af_sm_debug(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: - 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: - ogs_timer_stop(nf_instance->t_registration_interval); - break; - - case AF_EVT_SBI_CLIENT: - message = e->sbi.message; - ogs_assert(message); - - SWITCH(message->h.service.name) - CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) - - SWITCH(message->h.resource.component[0]) - CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - - if (message->res_status == OGS_SBI_HTTP_STATUS_OK || - message->res_status == OGS_SBI_HTTP_STATUS_CREATED) { - af_nnrf_handle_nf_register(nf_instance, message); - OGS_FSM_TRAN(s, &af_nf_state_registered); - } else { - ogs_error("[%s] HTTP Response Status Code [%d]", - 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]", - ogs_sbi_self()->nf_instance->id, - message->h.resource.component[0]); - END - break; - - DEFAULT - ogs_error("[%s] Invalid API name [%s]", - ogs_sbi_self()->nf_instance->id, message->h.service.name); - END - break; - - case AF_EVT_SBI_TIMER: - switch(e->timer_id) { - case AF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - client = nf_instance->client; - ogs_assert(client); - addr = client->node.addr; - ogs_assert(addr); - - ogs_warn("[%s] Retry to registration with NRF", - ogs_sbi_self()->nf_instance->id); - - 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]", - ogs_sbi_self()->nf_instance->id, - af_timer_get_name(e->timer_id), e->timer_id); - } - break; - - default: - ogs_error("[%s] Unknown event %s", - ogs_sbi_self()->nf_instance->id, af_event_get_name(e)); - break; - } -} - -void af_nf_state_registered(ogs_fsm_t *s, af_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_sbi_client_t *client = NULL; - ogs_sbi_message_t *message = NULL; - ogs_assert(s); - ogs_assert(e); - - af_sm_debug(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_NRF(nf_instance)) { - ogs_info("[%s] NF registered [Heartbeat:%ds]", - ogs_sbi_self()->nf_instance->id, - nf_instance->time.heartbeat_interval); - - client = nf_instance->client; - ogs_assert(client); - - if (nf_instance->time.heartbeat_interval) { - ogs_timer_start(nf_instance->t_heartbeat_interval, - ogs_time_from_sec(nf_instance->time.heartbeat_interval)); - ogs_timer_start(nf_instance->t_no_heartbeat, - ogs_time_from_sec( - nf_instance->time.heartbeat_interval + - ogs_app()->time.nf_instance.no_heartbeat_margin)); - } - - ogs_assert(true == - ogs_nnrf_nfm_send_nf_status_subscribe(client, - 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_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); - ogs_timer_stop(nf_instance->t_no_heartbeat); - } - - if (!OGS_FSM_CHECK(&nf_instance->sm, af_nf_state_exception)) { - ogs_assert(true == - ogs_nnrf_nfm_send_nf_de_register(nf_instance)); - } - } - break; - - case AF_EVT_SBI_CLIENT: - message = e->sbi.message; - ogs_assert(message); - - SWITCH(message->h.service.name) - CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) - - SWITCH(message->h.resource.component[0]) - CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - - if (message->res_status == OGS_SBI_HTTP_STATUS_NO_CONTENT || - message->res_status == OGS_SBI_HTTP_STATUS_OK) { - if (nf_instance->time.heartbeat_interval) - ogs_timer_start(nf_instance->t_no_heartbeat, - ogs_time_from_sec( - nf_instance->time.heartbeat_interval + - ogs_app()->time.nf_instance. - no_heartbeat_margin)); - } else { - ogs_warn("[%s] HTTP response error [%d]", - 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]", - ogs_sbi_self()->nf_instance->id, - message->h.resource.component[0]); - END - break; - - DEFAULT - ogs_error("[%s] Invalid API name [%s]", - ogs_sbi_self()->nf_instance->id, message->h.service.name); - END - break; - - case AF_EVT_SBI_TIMER: - switch(e->timer_id) { - case AF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - if (nf_instance->time.heartbeat_interval) - ogs_timer_start(nf_instance->t_heartbeat_interval, - ogs_time_from_sec(nf_instance->time.heartbeat_interval)); - - ogs_assert(true == ogs_nnrf_nfm_send_nf_update(nf_instance)); - break; - - case AF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - 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: - 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:%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:%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; - } -} - -void af_nf_state_de_registered(ogs_fsm_t *s, af_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_assert(s); - ogs_assert(e); - - af_sm_debug(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_NRF(nf_instance)) { - ogs_info("[%s] NF de-registered", ogs_sbi_self()->nf_instance->id); - } - break; - - case OGS_FSM_EXIT_SIG: - break; - - default: - 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; - } -} - -void af_nf_state_exception(ogs_fsm_t *s, af_event_t *e) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_sbi_client_t *client = NULL; - ogs_sbi_message_t *message = NULL; - ogs_sockaddr_t *addr = NULL; - ogs_assert(s); - ogs_assert(e); - - af_sm_debug(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_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_NRF(nf_instance)) { - ogs_timer_stop(nf_instance->t_registration_interval); - } - break; - - case AF_EVT_SBI_TIMER: - switch(e->timer_id) { - case AF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - client = nf_instance->client; - ogs_assert(client); - addr = client->node.addr; - ogs_assert(addr); - - 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:%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; - - case AF_EVT_SBI_CLIENT: - message = e->sbi.message; - ogs_assert(message); - - SWITCH(message->h.service.name) - CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) - - SWITCH(message->h.resource.component[0]) - CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - break; - DEFAULT - ogs_error("Invalid resource name [%s]", - message->h.resource.component[0]); - END - break; - DEFAULT - ogs_error("Invalid API name [%s]", message->h.service.name); - END - break; - - default: - 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 deleted file mode 100644 index b4993ba0e..000000000 --- a/tests/af/nnrf-build.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2019,2020 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "nnrf-build.h" - -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; - - OpenAPI_nf_profile_t *NFProfile = 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_PUT; - message.h.service.name = (char *)OGS_SBI_SERVICE_NAME_NNRF_NFM; - 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] = nf_instance->id; - - message.http.content_encoding = (char*)ogs_sbi_self()->content_encoding; - - NFProfile = ogs_nnrf_nfm_build_nf_profile(); - ogs_expect_or_return_val(NFProfile, NULL); - - message.NFProfile = NFProfile; - - request = ogs_sbi_build_request(&message); - - ogs_sbi_nnrf_free_nf_profile(NFProfile); - - return request; -} diff --git a/tests/af/nnrf-build.h b/tests/af/nnrf-build.h deleted file mode 100644 index 779c0783a..000000000 --- a/tests/af/nnrf-build.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2019,2020 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef AF_NNRF_BUILD_H -#define AF_NNRF_BUILD_H - -#include "context.h" - -#ifdef __cplusplus -extern "C" { -#endif - -ogs_sbi_request_t *af_nnrf_nfm_build_register(void); - -#ifdef __cplusplus -} -#endif - -#endif /* AF_NNRF_BUILD_H */ diff --git a/tests/af/nnrf-handler.c b/tests/af/nnrf-handler.c index c08db177e..c754ed9c7 100644 --- a/tests/af/nnrf-handler.c +++ b/tests/af/nnrf-handler.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -20,248 +20,14 @@ #include "sbi-path.h" #include "nnrf-handler.h" -void af_nnrf_handle_nf_register( - ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_message_t *recvmsg) -{ - OpenAPI_nf_profile_t *NFProfile = NULL; - ogs_sbi_client_t *client = NULL; - - ogs_assert(recvmsg); - ogs_assert(nf_instance); - client = nf_instance->client; - ogs_assert(client); - - NFProfile = recvmsg->NFProfile; - if (!NFProfile) { - ogs_error("No NFProfile"); - return; - } - - /* TIME : Update heartbeat from NRF */ - if (NFProfile->nf_profile_changes_ind == true) { - if (NFProfile->heart_beat_timer) - nf_instance->time.heartbeat_interval = NFProfile->heart_beat_timer; - } else { - nf_instance->time.heartbeat_interval = NFProfile->heart_beat_timer; - } -} - -void af_nnrf_handle_nf_status_subscribe( - ogs_sbi_subscription_t *subscription, ogs_sbi_message_t *recvmsg) -{ - OpenAPI_subscription_data_t *SubscriptionData = NULL; - ogs_sbi_client_t *client = NULL; - - ogs_assert(recvmsg); - ogs_assert(subscription); - client = subscription->client; - ogs_assert(client); - - SubscriptionData = recvmsg->SubscriptionData; - if (!SubscriptionData) { - ogs_error("No SubscriptionData"); - return; - } - - if (!SubscriptionData->subscription_id) { - ogs_error("No SubscriptionId"); - return; - } - ogs_sbi_subscription_set_id( - subscription, SubscriptionData->subscription_id); - - if (SubscriptionData->validity_time) { -#define VALIDITY_MINIMUM (10LL * OGS_USEC_PER_SEC) /* 10 seconds */ - ogs_time_t time, duration; - if (ogs_sbi_time_from_string( - &time, SubscriptionData->validity_time) == true) { - duration = time - ogs_time_now(); - if (duration < VALIDITY_MINIMUM) { - duration = VALIDITY_MINIMUM; - ogs_warn("[%s] Forced to %lld seconds", subscription->id, - (long long)ogs_time_sec(VALIDITY_MINIMUM)); - } - subscription->t_validity = ogs_timer_add(ogs_app()->timer_mgr, - af_timer_subscription_validity, subscription); - ogs_assert(subscription->t_validity); - ogs_timer_start(subscription->t_validity, duration); - } else { - ogs_error("Cannot parse validitiyTime [%s]", - SubscriptionData->validity_time); - } - } -} - -bool af_nnrf_handle_nf_status_notify( - ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) -{ - int rv; - bool handled; - - ogs_sbi_response_t *response = NULL; - OpenAPI_notification_data_t *NotificationData = NULL; - ogs_sbi_nf_instance_t *nf_instance = NULL; - - ogs_sbi_message_t message; - ogs_sbi_header_t header; - - ogs_assert(stream); - ogs_assert(recvmsg); - - NotificationData = recvmsg->NotificationData; - if (!NotificationData) { - ogs_error("No NotificationData"); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "No NotificationData", NULL)); - return false; - } - - if (!NotificationData->nf_instance_uri) { - ogs_error("No nfInstanceUri"); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "No nfInstanceUri", NULL)); - return false; - } - - memset(&header, 0, sizeof(header)); - header.uri = NotificationData->nf_instance_uri; - - rv = ogs_sbi_parse_header(&message, &header); - if (rv != OGS_OK) { - ogs_error("Cannot parse nfInstanceUri [%s]", header.uri); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Cannot parse nfInstanceUri", header.uri)); - return false; - } - - if (!message.h.resource.component[1]) { - ogs_error("No nfInstanceId [%s]", header.uri); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Cannot parse nfInstanceUri", header.uri)); - ogs_sbi_header_free(&header); - return false; - } - - if (NF_INSTANCE_IS_SELF(message.h.resource.component[1])) { - ogs_warn("[%s] The notification is not allowed", - message.h.resource.component[1]); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, - recvmsg, "The notification is not allowed", - message.h.resource.component[1])); - ogs_sbi_header_free(&header); - return false; - } - - if (NotificationData->event == - OpenAPI_notification_event_type_NF_REGISTERED) { - - OpenAPI_nf_profile_t *NFProfile = NULL; - - NFProfile = NotificationData->nf_profile; - if (!NFProfile) { - ogs_error("No NFProfile"); - ogs_assert(true == - ogs_sbi_server_send_error( - stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "No NFProfile", NULL)); - ogs_sbi_header_free(&header); - return false; - } - - nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); - if (!nf_instance) { - 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); - - ogs_info("[%s] (NRF-notify) NF registered", nf_instance->id); - - } else { - OGS_FSM_TRAN(&nf_instance->sm, af_nf_state_registered); - ogs_fsm_dispatch(&nf_instance->sm, NULL); - - ogs_warn("[%s] (NRF-notify) NF has already been added", - message.h.resource.component[1]); - - } - - handled = ogs_sbi_nnrf_handle_nf_profile( - nf_instance, NFProfile, stream, recvmsg); - if (!handled) { - AF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); - ogs_sbi_header_free(&header); - return false; - } - - ogs_info("[%s] (NRF-notify) NF Profile updated", nf_instance->id); - - handled = ogs_sbi_client_associate(nf_instance); - if (!handled) { - ogs_error("[%s] Cannot associate NF EndPoint", nf_instance->id); - ogs_assert(true == - ogs_sbi_server_send_error(stream, - OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Cannot find NF EndPoint", nf_instance->id)); - AF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); - ogs_sbi_header_free(&header); - return false; - } - - } else if (NotificationData->event == - OpenAPI_notification_event_type_NF_DEREGISTERED) { - nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); - if (nf_instance) { - AF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); - } else { - ogs_warn("[%s] (NRF-notify) Not found", - message.h.resource.component[1]); - ogs_assert(true == - ogs_sbi_server_send_error(stream, - OGS_SBI_HTTP_STATUS_NOT_FOUND, - recvmsg, "Not found", message.h.resource.component[1])); - ogs_sbi_header_free(&header); - return false; - } - } else { - char *eventstr = OpenAPI_notification_event_type_ToString( - NotificationData->event); - ogs_error("Not supported event [%d:%s]", - NotificationData->event, eventstr ? eventstr : "Unknown"); - ogs_assert(true == - ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, - recvmsg, "Not supported event", - eventstr ? eventstr : "Unknown")); - ogs_sbi_header_free(&header); - return false; - } - - response = ogs_sbi_build_response(recvmsg, OGS_SBI_HTTP_STATUS_NO_CONTENT); - ogs_assert(response); - ogs_assert(true == ogs_sbi_server_send_response(stream, response)); - - ogs_sbi_header_free(&header); - return true; -} - void af_nnrf_handle_nf_discover( ogs_sbi_xact_t *xact, ogs_sbi_message_t *recvmsg) { ogs_sbi_object_t *sbi_object = NULL; OpenAPI_nf_type_e target_nf_type = 0; ogs_sbi_discovery_option_t *discovery_option = NULL; - ogs_sbi_nf_instance_t *nf_instance = NULL; OpenAPI_search_result_t *SearchResult = NULL; - OpenAPI_lnode_t *node = NULL; - bool handled; ogs_assert(recvmsg); ogs_assert(xact); @@ -278,63 +44,8 @@ void af_nnrf_handle_nf_discover( return; } - OpenAPI_list_for_each(SearchResult->nf_instances, node) { - OpenAPI_nf_profile_t *NFProfile = NULL; - - if (!node->data) continue; - - NFProfile = node->data; - - nf_instance = ogs_sbi_nf_instance_find(NFProfile->nf_instance_id); - if (!nf_instance) { - 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); - - ogs_info("[%s] (NF-discover) NF registered", nf_instance->id); - } else { - OGS_FSM_TRAN(&nf_instance->sm, af_nf_state_registered); - ogs_fsm_dispatch(&nf_instance->sm, NULL); - - ogs_warn("[%s] (NF-discover) NF has already been added", - NFProfile->nf_instance_id); - } - - if (NF_INSTANCE_IS_OTHERS(nf_instance->id)) { - handled = ogs_sbi_nnrf_handle_nf_profile( - nf_instance, NFProfile, NULL, NULL); - if (!handled) { - ogs_error("ogs_sbi_nnrf_handle_nf_profile() failed [%s]", - nf_instance->id); - AF_NF_INSTANCE_CLEAR("NRF-discover", nf_instance); - continue; - } - - handled = ogs_sbi_client_associate(nf_instance); - if (!handled) { - ogs_error("[%s] Cannot assciate NF EndPoint", nf_instance->id); - AF_NF_INSTANCE_CLEAR("NRF-discover", nf_instance); - continue; - } - - /* TIME : Update validity from NRF */ - if (SearchResult->validity_period) { - nf_instance->time.validity_duration = - SearchResult->validity_period; - - ogs_assert(nf_instance->t_validity); - ogs_timer_start(nf_instance->t_validity, - ogs_time_from_sec(nf_instance->time.validity_duration)); - - } else - ogs_warn("[%s] NF Instance validity-time should not 0", - nf_instance->id); - - ogs_info("[%s] (NF-discover) NF Profile updated", nf_instance->id); - } - } + ogs_nnrf_handle_nf_discover_search_result( + sbi_object, target_nf_type, discovery_option, SearchResult); ogs_sbi_select_nf(sbi_object, target_nf_type, discovery_option); diff --git a/tests/af/nnrf-handler.h b/tests/af/nnrf-handler.h index b666a7abc..07b3aa235 100644 --- a/tests/af/nnrf-handler.h +++ b/tests/af/nnrf-handler.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -26,14 +26,6 @@ extern "C" { #endif -void af_nnrf_handle_nf_register( - ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_message_t *recvmsg); -void af_nnrf_handle_nf_status_subscribe( - ogs_sbi_subscription_t *subscription, ogs_sbi_message_t *recvmsg); - -bool af_nnrf_handle_nf_status_notify( - ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); - void af_nnrf_handle_nf_discover( ogs_sbi_xact_t *xact, ogs_sbi_message_t *recvmsg); diff --git a/tests/af/sbi-path.c b/tests/af/sbi-path.c index 54dd40041..8e5bc7148 100644 --- a/tests/af/sbi-path.c +++ b/tests/af/sbi-path.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -27,17 +27,17 @@ static int server_cb(ogs_sbi_request_t *request, void *data) ogs_assert(request); ogs_assert(data); - e = af_event_new(AF_EVT_SBI_SERVER); + e = af_event_new(OGS_EVENT_SBI_SERVER); ogs_assert(e); - e->sbi.request = request; - e->sbi.data = data; + e->h.sbi.request = request; + e->h.sbi.data = data; rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed:%d", (int)rv); ogs_sbi_request_free(request); - af_event_free(e); + ogs_event_free(e); return OGS_ERROR; } @@ -58,16 +58,16 @@ static int client_cb(int status, ogs_sbi_response_t *response, void *data) ogs_assert(response); - e = af_event_new(AF_EVT_SBI_CLIENT); + e = af_event_new(OGS_EVENT_SBI_CLIENT); ogs_assert(e); - e->sbi.response = response; - e->sbi.data = data; + e->h.sbi.response = response; + e->h.sbi.data = data; rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { ogs_error("ogs_queue_push() failed:%d", (int)rv); ogs_sbi_response_free(response); - af_event_free(e); + ogs_event_free(e); return OGS_ERROR; } @@ -79,6 +79,10 @@ int af_sbi_open(void) ogs_sbi_nf_instance_t *nf_instance = NULL; ogs_sbi_nf_service_t *service = NULL; + /* To be notified when NF Instances registered/deregistered in NRF + * or when their profile is modified */ + ogs_sbi_add_to_be_notified_nf_type(OpenAPI_nf_type_BSF); + /* Add SELF NF instance */ nf_instance = ogs_sbi_self()->nf_instance; ogs_assert(nf_instance); @@ -97,32 +101,23 @@ int af_sbi_open(void) } /* Initialize NRF NF Instance */ - ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) { - if (NF_INSTANCE_IS_NRF(nf_instance)) { - ogs_sbi_client_t *client = NULL; + nf_instance = ogs_sbi_self()->nrf_instance; + if (nf_instance) { + ogs_sbi_client_t *client = NULL; - /* Client callback is only used when NF sends to NRF */ - client = nf_instance->client; - ogs_assert(client); - client->cb = client_cb; + /* 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. */ + ogs_sbi_nf_fsm_init(nf_instance); } - /* Timer expiration handler of client wait timer */ - ogs_sbi_self()->client_wait_expire = af_timer_sbi_client_wait_expire; - - /* NF register state in NF state machine */ - ogs_sbi_self()->nf_state_registered = - (ogs_fsm_handler_t)af_nf_state_registered; - if (ogs_sbi_server_start_all(server_cb) != OGS_OK) return OGS_ERROR; - return OGS_OK; } @@ -132,21 +127,6 @@ void af_sbi_close(void) ogs_sbi_server_stop_all(); } -bool af_nnrf_nfm_send_nf_register(ogs_sbi_nf_instance_t *nf_instance) -{ - ogs_sbi_request_t *request = NULL; - ogs_sbi_client_t *client = NULL; - - ogs_assert(nf_instance); - client = nf_instance->client; - ogs_assert(client); - - 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); -} - bool af_sbi_send_request( ogs_sbi_object_t *sbi_object, OpenAPI_nf_type_e target_nf_type, diff --git a/tests/af/sbi-path.h b/tests/af/sbi-path.h index d487f04d7..e1c7cfbb5 100644 --- a/tests/af/sbi-path.h +++ b/tests/af/sbi-path.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -20,7 +20,6 @@ #ifndef AF_SBI_PATH_H #define AF_SBI_PATH_H -#include "nnrf-build.h" #include "nbsf-build.h" #include "npcf-build.h" @@ -31,8 +30,6 @@ extern "C" { int af_sbi_open(void); void af_sbi_close(void); -bool af_nnrf_nfm_send_nf_register(ogs_sbi_nf_instance_t *nf_instance); - bool af_sbi_send_request( ogs_sbi_object_t *sbi_object, OpenAPI_nf_type_e target_nf_type, diff --git a/tests/af/timer.c b/tests/af/timer.c deleted file mode 100644 index de25eee47..000000000 --- a/tests/af/timer.c +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (C) 2019 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "context.h" - -const char *af_timer_get_name(af_timer_e id) -{ - switch (id) { - case AF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - return "AF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL"; - case AF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - return "AF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL"; - case AF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - return "AF_TIMER_NF_INSTANCE_NO_HEARTBEAT"; - case AF_TIMER_NF_INSTANCE_VALIDITY: - return "AF_TIMER_NF_INSTANCE_VALIDITY"; - case AF_TIMER_SUBSCRIPTION_VALIDITY: - return "AF_TIMER_SUBSCRIPTION_VALIDITY"; - case AF_TIMER_SBI_CLIENT_WAIT: - return "AF_TIMER_SBI_CLIENT_WAIT"; - default: - break; - } - - return "UNKNOWN_TIMER"; -} - -static void timer_send_event(int timer_id, void *data) -{ - int rv; - af_event_t *e = NULL; - ogs_assert(data); - - switch (timer_id) { - case AF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: - case AF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: - case AF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - case AF_TIMER_NF_INSTANCE_VALIDITY: - case AF_TIMER_SUBSCRIPTION_VALIDITY: - e = af_event_new(AF_EVT_SBI_TIMER); - ogs_assert(e); - e->timer_id = timer_id; - e->sbi.data = data; - break; - case AF_TIMER_SBI_CLIENT_WAIT: - e = af_event_new(AF_EVT_SBI_TIMER); - if (!e) { - ogs_sbi_xact_t *sbi_xact = data; - ogs_assert(sbi_xact); - - ogs_error("timer_send_event() failed"); - ogs_sbi_xact_remove(sbi_xact); - return; - } - e->timer_id = timer_id; - e->sbi.data = data; - break; - default: - ogs_fatal("Unknown timer id[%d]", timer_id); - ogs_assert_if_reached(); - break; - } - - rv = ogs_queue_push(ogs_app()->queue, e); - if (rv != OGS_OK) { - ogs_error("ogs_queue_push() failed [%d] in %s", - (int)rv, af_timer_get_name(e->timer_id)); - af_event_free(e); - } -} - -void af_timer_nf_instance_registration_interval(void *data) -{ - timer_send_event(AF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL, data); -} - -void af_timer_nf_instance_heartbeat_interval(void *data) -{ - timer_send_event(AF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL, data); -} - -void af_timer_nf_instance_no_heartbeat(void *data) -{ - timer_send_event(AF_TIMER_NF_INSTANCE_NO_HEARTBEAT, data); -} - -void af_timer_nf_instance_validity(void *data) -{ - timer_send_event(AF_TIMER_NF_INSTANCE_VALIDITY, data); -} - -void af_timer_subscription_validity(void *data) -{ - timer_send_event(AF_TIMER_SUBSCRIPTION_VALIDITY, data); -} - -void af_timer_sbi_client_wait_expire(void *data) -{ - timer_send_event(AF_TIMER_SBI_CLIENT_WAIT, data); -} diff --git a/tests/af/timer.h b/tests/af/timer.h deleted file mode 100644 index 2246d15eb..000000000 --- a/tests/af/timer.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2019 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef AF_TIMER_H -#define AF_TIMER_H - -#include "ogs-core.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* forward declaration */ -typedef enum { - AF_TIMER_BASE = 0, - - AF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL, - AF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL, - AF_TIMER_NF_INSTANCE_NO_HEARTBEAT, - AF_TIMER_NF_INSTANCE_VALIDITY, - AF_TIMER_SUBSCRIPTION_VALIDITY, - AF_TIMER_SBI_CLIENT_WAIT, - - MAX_NUM_OF_AF_TIMER, - -} af_timer_e; - -const char *af_timer_get_name(af_timer_e id); - -void af_timer_nf_instance_registration_interval(void *data); -void af_timer_nf_instance_heartbeat_interval(void *data); -void af_timer_nf_instance_no_heartbeat(void *data); -void af_timer_nf_instance_validity(void *data); -void af_timer_subscription_validity(void *data); -void af_timer_sbi_client_wait_expire(void *data); - -#ifdef __cplusplus -} -#endif - -#endif /* AF_TIMER_H */ diff --git a/tests/core/fsm-test.c b/tests/core/fsm-test.c index a5e2ba37e..1b45e0330 100644 --- a/tests/core/fsm-test.c +++ b/tests/core/fsm-test.c @@ -41,12 +41,6 @@ void bomb_initial(bomb_t *s, tick_event_t *e); void bomb_setting(bomb_t *s, tick_event_t *e); void bomb_timing(bomb_t *s, tick_event_t *e); -void bomb_create(bomb_t *s, uint8_t defuse) -{ - ogs_fsm_create(&s->fsm, &bomb_initial, 0); - s->defuse = defuse; -} - void bomb_initial(bomb_t *s, tick_event_t *e) { s->timeout = 10; @@ -98,9 +92,8 @@ static void test1_func(abts_case *tc, void *data) bomb_t bomb; tick_event_t tick_event; - bomb_create(&bomb, 14); - - ogs_fsm_init(&bomb, 0); + ogs_fsm_init(&bomb, &bomb_initial, 0, 0); + bomb.defuse = 14; ABTS_PTR_EQUAL(tc, &bomb_setting, OGS_FSM_STATE(&bomb)); ABTS_INT_EQUAL(tc, 10, bomb.timeout); @@ -246,9 +239,7 @@ static void test2_func(abts_case *tc, void *data) set_event_t set_event; time_event_t time_event; - ogs_fsm_create(&alarm.fsm, &alarm_initial, 0); - - ogs_fsm_init(&alarm, 0); + ogs_fsm_init(&alarm, &alarm_initial, 0, 0); ABTS_PTR_EQUAL(tc, &alarm_off, OGS_FSM_STATE(&alarm)); ABTS_INT_EQUAL(tc, 1200, alarm.time);