From 9f98d421a081a5edc3a525d1cf2504b8b6cf059e Mon Sep 17 00:00:00 2001 From: Sukchan Lee Date: Sat, 27 Aug 2022 10:49:07 +0900 Subject: [PATCH] [SBI] Added config for service-names discovery --- configs/open5gs/amf.yaml.in | 24 ++++++++++++ configs/open5gs/ausf.yaml.in | 24 ++++++++++++ configs/open5gs/bsf.yaml.in | 24 ++++++++++++ configs/open5gs/nssf.yaml.in | 24 ++++++++++++ configs/open5gs/pcf.yaml.in | 24 ++++++++++++ configs/open5gs/scp.yaml.in | 38 +++++++++--------- configs/open5gs/smf.yaml.in | 25 ++++++++++++ configs/open5gs/udm.yaml.in | 24 ++++++++++++ configs/open5gs/udr.yaml.in | 24 ++++++++++++ configs/sample.yaml.in | 54 +++++--------------------- lib/proto/types.c | 74 +++++++++++++++++++++++++++++++----- lib/proto/types.h | 1 + lib/sbi/context.c | 2 + lib/sbi/message.c | 3 +- src/amf/context.c | 2 + src/amf/gmm-handler.c | 3 +- src/ausf/context.c | 4 +- src/bsf/context.c | 2 + src/nssf/context.c | 2 + src/pcf/context.c | 2 + src/pcf/pcf-sm.c | 25 ++++++------ src/scp/context.c | 2 + src/smf/context.c | 2 + src/udm/context.c | 4 +- src/udr/context.c | 2 + tests/af/context.c | 2 + 26 files changed, 332 insertions(+), 85 deletions(-) diff --git a/configs/open5gs/amf.yaml.in b/configs/open5gs/amf.yaml.in index 978979c2c..c37fd459d 100644 --- a/configs/open5gs/amf.yaml.in +++ b/configs/open5gs/amf.yaml.in @@ -94,6 +94,30 @@ logger: # service_name: # - namf-comm # +# +# +# o (Default) If you do not set Query Parameter as shown below, +# +# sbi: +# - addr: 127.0.0.5 +# port: 7777 +# +# - 'service-names' is included. +# +# sbi: +# - addr: 127.0.0.5 +# port: 7777 +# discovery: +# option: +# no_service_names: false +# +# o To remove 'service-names' from URI query parameters in NS Discovery +# no_service_names: true +# +# * For Indirect Communication with Delegated Discovery, +# 'service-names' is always included in the URI query parameter. +# * That is, 'no_service_names' has no effect. +# # > # # o NGAP Server(all address available) diff --git a/configs/open5gs/ausf.yaml.in b/configs/open5gs/ausf.yaml.in index bfab59872..867403da3 100644 --- a/configs/open5gs/ausf.yaml.in +++ b/configs/open5gs/ausf.yaml.in @@ -94,6 +94,30 @@ logger: # service_name: # - nausf-auth # +# +# +# o (Default) If you do not set Query Parameter as shown below, +# +# sbi: +# - addr: 127.0.0.11 +# port: 7777 +# +# - 'service-names' is included. +# +# sbi: +# - addr: 127.0.0.11 +# port: 7777 +# discovery: +# option: +# no_service_names: false +# +# o To remove 'service-names' from URI query parameters in NS Discovery +# no_service_names: true +# +# * For Indirect Communication with Delegated Discovery, +# 'service-names' is always included in the URI query parameter. +# * That is, 'no_service_names' has no effect. +# ausf: sbi: - addr: 127.0.0.11 diff --git a/configs/open5gs/bsf.yaml.in b/configs/open5gs/bsf.yaml.in index f5e4def20..c7b895016 100644 --- a/configs/open5gs/bsf.yaml.in +++ b/configs/open5gs/bsf.yaml.in @@ -96,6 +96,30 @@ logger: # service_name: # - nbsf-management # +# +# +# o (Default) If you do not set Query Parameter as shown below, +# +# sbi: +# - addr: 127.0.0.15 +# port: 7777 +# +# - 'service-names' is included. +# +# sbi: +# - addr: 127.0.0.15 +# port: 7777 +# discovery: +# option: +# no_service_names: false +# +# o To remove 'service-names' from URI query parameters in NS Discovery +# no_service_names: true +# +# * For Indirect Communication with Delegated Discovery, +# 'service-names' is always included in the URI query parameter. +# * That is, 'no_service_names' has no effect. +# bsf: sbi: - addr: 127.0.0.15 diff --git a/configs/open5gs/nssf.yaml.in b/configs/open5gs/nssf.yaml.in index a178da7c2..5d1214c04 100644 --- a/configs/open5gs/nssf.yaml.in +++ b/configs/open5gs/nssf.yaml.in @@ -144,6 +144,30 @@ logger: # service_name: # - nnssf-nsselection # +# +# +# o (Default) If you do not set Query Parameter as shown below, +# +# sbi: +# - addr: 127.0.0.14 +# port: 7777 +# +# - 'service-names' is included. +# +# sbi: +# - addr: 127.0.0.14 +# port: 7777 +# discovery: +# option: +# no_service_names: false +# +# o To remove 'service-names' from URI query parameters in NS Discovery +# no_service_names: true +# +# * For Indirect Communication with Delegated Discovery, +# 'service-names' is always included in the URI query parameter. +# * That is, 'no_service_names' has no effect. +# nssf: sbi: - addr: 127.0.0.14 diff --git a/configs/open5gs/pcf.yaml.in b/configs/open5gs/pcf.yaml.in index 7c01d858b..31dc5e26f 100644 --- a/configs/open5gs/pcf.yaml.in +++ b/configs/open5gs/pcf.yaml.in @@ -98,6 +98,30 @@ logger: # - npcf-smpolicycontrol # - npcf-policyauthorization # +# +# +# o (Default) If you do not set Query Parameter as shown below, +# +# sbi: +# - addr: 127.0.0.13 +# port: 7777 +# +# - 'service-names' is included. +# +# sbi: +# - addr: 127.0.0.13 +# port: 7777 +# discovery: +# option: +# no_service_names: false +# +# o To remove 'service-names' from URI query parameters in NS Discovery +# no_service_names: true +# +# * For Indirect Communication with Delegated Discovery, +# 'service-names' is always included in the URI query parameter. +# * That is, 'no_service_names' has no effect. +# pcf: sbi: - addr: 127.0.0.13 diff --git a/configs/open5gs/scp.yaml.in b/configs/open5gs/scp.yaml.in index 282f40600..8d720c3d8 100644 --- a/configs/open5gs/scp.yaml.in +++ b/configs/open5gs/scp.yaml.in @@ -96,26 +96,30 @@ logger: # - addr: 127.0.1.11 # port: 7777 # -# +# # -# o NF Discovery and Selection -# for indirect communication with Delegated Discovery; -# -# o delegated: -# o auto: (Default) -# Use next-hop SCP if next-hop SCP available. Otherwise NRF is used. -# => App fails if both next-hop SCP and NRF are unavailable. -# o yes: Use next-hop SCP always. -# => App fails if no next-hop SCP available. -# o no: Don't use next-hop SCP server. -# => App fails if no NRF available. +# o (Default) If you do not set Delegated Discovery as shown below, # # next_scp: -# sbi: -# - addr: 127.0.1.11 -# port: 7777 -# discovery: -# delegated: auto|yes|no +# sbi: +# - addr: 127.0.1.10 +# port: 7777 +# +# - Use SCP if SCP avaiable. Otherwise NRF is used. +# => App fails if both NRF and SCP are unavailable. +# +# next_scp: +# sbi: +# - addr: 127.0.1.10 +# port: 7777 +# discovery: +# delegated: auto +# +# o To use SCP always => App fails if no SCP available. +# delegated: yes +# +# o Don't use SCP server => App fails if no NRF available. +# delegated: no # scp: sbi: diff --git a/configs/open5gs/smf.yaml.in b/configs/open5gs/smf.yaml.in index 798a7421e..561fc5600 100644 --- a/configs/open5gs/smf.yaml.in +++ b/configs/open5gs/smf.yaml.in @@ -94,6 +94,31 @@ logger: # service_name: # - nsmf-pdusession # +# +# +# o (Default) If you do not set Query Parameter as shown below, +# +# sbi: +# - addr: 127.0.0.4 +# port: 7777 +# +# - 'service-names' is included. +# +# sbi: +# - addr: 127.0.0.4 +# port: 7777 +# discovery: +# option: +# no_service_names: false +# +# o To remove 'service-names' from URI query parameters in NS Discovery +# no_service_names: true +# +# * For Indirect Communication with Delegated Discovery, +# 'service-names' is always included in the URI query parameter. +# * That is, 'no_service_names' has no effect. +# +# # # # o PFCP Server(127.0.0.4:8805, ::1:8805) diff --git a/configs/open5gs/udm.yaml.in b/configs/open5gs/udm.yaml.in index 38bca839b..3cc10fe43 100644 --- a/configs/open5gs/udm.yaml.in +++ b/configs/open5gs/udm.yaml.in @@ -96,6 +96,30 @@ logger: # - nudm-uecm # - nudm-ueau # +# +# +# o (Default) If you do not set Query Parameter as shown below, +# +# sbi: +# - addr: 127.0.0.12 +# port: 7777 +# +# - 'service-names' is included. +# +# sbi: +# - addr: 127.0.0.12 +# port: 7777 +# discovery: +# option: +# no_service_names: false +# +# o To remove 'service-names' from URI query parameters in NS Discovery +# no_service_names: true +# +# * For Indirect Communication with Delegated Discovery, +# 'service-names' is always included in the URI query parameter. +# * That is, 'no_service_names' has no effect. +# udm: sbi: - addr: 127.0.0.12 diff --git a/configs/open5gs/udr.yaml.in b/configs/open5gs/udr.yaml.in index 7ef337530..33be88860 100644 --- a/configs/open5gs/udr.yaml.in +++ b/configs/open5gs/udr.yaml.in @@ -96,6 +96,30 @@ logger: # service_name: # - nudr-dr # +# +# +# o (Default) If you do not set Query Parameter as shown below, +# +# sbi: +# - addr: 127.0.0.20 +# port: 7777 +# +# - 'service-names' is included. +# +# sbi: +# - addr: 127.0.0.20 +# port: 7777 +# discovery: +# option: +# no_service_names: false +# +# o To remove 'service-names' from URI query parameters in NS Discovery +# no_service_names: true +# +# * For Indirect Communication with Delegated Discovery, +# 'service-names' is always included in the URI query parameter. +# * That is, 'no_service_names' has no effect. +# udr: sbi: - addr: 127.0.0.20 diff --git a/configs/sample.yaml.in b/configs/sample.yaml.in index 20dbef30e..20df424f2 100644 --- a/configs/sample.yaml.in +++ b/configs/sample.yaml.in @@ -106,63 +106,29 @@ smf: - identity: pcrf.localdomain addr: 127.0.0.9 -# -# -# -# o (Default) If you do not set Query Parameter as shown below, -# -# amf: -# sbi: -# - addr: 127.0.0.5 -# port: 7777 -# -# - 'service-names' is included. -# - 'requester-nf-instance-id' is NOT included. -# -# amf: -# sbi: -# - addr: 127.0.0.5 -# port: 7777 -# discovery: -# option: -# no_service_names: false -# prefer_requester_nf_instance_id: false -# -# o To remove 'service-names' from URI query parameters in NS Discovery -# no_service_names: true -# -# * For Indirect Communication with Delegated Discovery, -# 'service-names' is always included in the URI query parameter. -# * That is, 'no_service_names' has no effect. -# -# o To add 'requester-nf-instance-id' from URI query parameters in NS Discovery -# prefer_requester_nf_instance_id: true -# # # # # o (Default) If you do not set Delegated Discovery as shown below, # -# amf: -# sbi: -# - addr: 127.0.0.5 -# port: 7777 +# sbi: +# - addr: 127.0.0.5 +# port: 7777 # # - Use SCP if SCP avaiable. Otherwise NRF is used. # => App fails if both NRF and SCP are unavailable. # -# amf: -# sbi: -# - addr: 127.0.0.5 -# port: 7777 -# discovery: -# delegated: auto +# sbi: +# - addr: 127.0.0.5 +# port: 7777 +# discovery: +# delegated: auto # # o To use SCP always => App fails if no SCP available. -# delegated: yes +# delegated: yes # # o Don't use SCP server => App fails if no NRF available. -# delegated: no +# delegated: no # amf: sbi: diff --git a/lib/proto/types.c b/lib/proto/types.c index 291fee34e..06742cb8c 100644 --- a/lib/proto/types.c +++ b/lib/proto/types.c @@ -235,6 +235,37 @@ char *ogs_supi_from_suci(char *suci) return supi; } +char *ogs_supi_from_supi_or_suci(char *supi_or_suci) +{ + char *type = NULL; + char *supi = NULL; + + ogs_assert(supi_or_suci); + type = ogs_id_get_type(supi_or_suci); + if (!type) { + ogs_error("ogs_id_get_type[%s] failed", supi_or_suci); + goto cleanup; + } + SWITCH(type) + CASE("imsi") + supi = ogs_strdup(supi_or_suci); + ogs_expect(supi); + break; + CASE("suci") + supi = ogs_supi_from_suci(supi_or_suci); + ogs_expect(supi); + break; + DEFAULT + ogs_error("Not implemented [%s]", type); + break; + END + +cleanup: + if (type) + ogs_free(type); + return supi; +} + char *ogs_id_get_type(char *str) { char *token, *p, *tmp; @@ -242,15 +273,26 @@ char *ogs_id_get_type(char *str) ogs_assert(str); tmp = ogs_strdup(str); - ogs_expect_or_return_val(tmp, NULL); + if (!tmp) { + ogs_error("ogs_strdup[%s] failed", str); + goto cleanup; + } p = tmp; token = strsep(&p, "-"); - ogs_assert(token); + if (!token) { + ogs_error("strsep[%s] failed", str); + goto cleanup; + } type = ogs_strdup(token); - ogs_expect_or_return_val(type, NULL); + if (!type) { + ogs_error("ogs_strdup[%s:%s] failed", str, token); + goto cleanup; + } - ogs_free(tmp); +cleanup: + if (tmp) + ogs_free(tmp); return type; } @@ -261,17 +303,31 @@ char *ogs_id_get_value(char *str) ogs_assert(str); tmp = ogs_strdup(str); - ogs_expect_or_return_val(tmp, NULL); + if (!tmp) { + ogs_error("ogs_strdup[%s] failed", str); + goto cleanup; + } p = tmp; token = strsep(&p, "-"); - ogs_assert(token); + if (!token) { + ogs_error("strsep[%s] failed", str); + goto cleanup; + } token = strsep(&p, "-"); - ogs_assert(token); + if (!token) { + ogs_error("strsep[%s] failed", str); + goto cleanup; + } ueid = ogs_strdup(token); - ogs_expect_or_return_val(ueid, NULL); + if (!ueid) { + ogs_error("ogs_strdup[%s:%s] failed", str, token); + goto cleanup; + } - ogs_free(tmp); +cleanup: + if (tmp) + ogs_free(tmp); return ueid; } diff --git a/lib/proto/types.h b/lib/proto/types.h index 89d854bf6..9afee3c24 100644 --- a/lib/proto/types.h +++ b/lib/proto/types.h @@ -177,6 +177,7 @@ ogs_amf_id_t *ogs_amf_id_build(ogs_amf_id_t *amf_id, /************************************ * SUPI/SUCI */ char *ogs_supi_from_suci(char *suci); +char *ogs_supi_from_supi_or_suci(char *supi_or_suci); /************************************ * SUPI/GPSI */ diff --git a/lib/sbi/context.c b/lib/sbi/context.c index 689cf0e4e..268f68ccc 100644 --- a/lib/sbi/context.c +++ b/lib/sbi/context.c @@ -1307,6 +1307,8 @@ ogs_sbi_nf_service_t *ogs_sbi_nf_service_build_default( ogs_assert(nf_service->fqdn); } + ogs_info("NF Service [%s]", nf_service->name); + return nf_service; } diff --git a/lib/sbi/message.c b/lib/sbi/message.c index ce3a20e08..fa00494b4 100644 --- a/lib/sbi/message.c +++ b/lib/sbi/message.c @@ -303,7 +303,8 @@ ogs_sbi_request_t *ogs_sbi_build_request(ogs_sbi_message_t *message) OGS_SBI_PARAM_REQUESTER_NF_INSTANCE_ID, discovery_option->requester_nf_instance_id); } - if (discovery_option->num_of_service_names) { + if (ogs_sbi_self()->discovery_config.no_service_names == false && + discovery_option->num_of_service_names) { char *v = NULL; cJSON *item = NULL; diff --git a/src/amf/context.c b/src/amf/context.c index b6c918c00..1f47f0b1c 100644 --- a/src/amf/context.c +++ b/src/amf/context.c @@ -823,6 +823,8 @@ int amf_context_parse_config(void) /* handle config in sbi library */ } else if (!strcmp(amf_key, "service_name")) { /* handle config in sbi library */ + } else if (!strcmp(amf_key, "discovery")) { + /* handle config in sbi library */ } else ogs_warn("unknown key `%s`", amf_key); } diff --git a/src/amf/gmm-handler.c b/src/amf/gmm-handler.c index d4ad28b0a..977461b3c 100644 --- a/src/amf/gmm-handler.c +++ b/src/amf/gmm-handler.c @@ -1085,7 +1085,8 @@ int gmm_handle_ul_nas_transport(amf_ue_t *amf_ue, OGS_SBI_SERVICE_TYPE_NSMF_PDUSESSION); } - ogs_sbi_discovery_option_free(discovery_option); + if (discovery_option) + ogs_sbi_discovery_option_free(discovery_option); if (nf_instance) { ogs_assert(true == diff --git a/src/ausf/context.c b/src/ausf/context.c index c9002059e..153e327e1 100644 --- a/src/ausf/context.c +++ b/src/ausf/context.c @@ -104,6 +104,8 @@ int ausf_context_parse_config(void) /* handle config in sbi library */ } else if (!strcmp(ausf_key, "service_name")) { /* handle config in sbi library */ + } else if (!strcmp(ausf_key, "discovery")) { + /* handle config in sbi library */ } else ogs_warn("unknown key `%s`", ausf_key); } @@ -135,7 +137,7 @@ ausf_ue_t *ausf_ue_add(char *suci) ogs_assert(ausf_ue->suci); ogs_hash_set(self.suci_hash, ausf_ue->suci, strlen(ausf_ue->suci), ausf_ue); - ausf_ue->supi = ogs_supi_from_suci(ausf_ue->suci); + ausf_ue->supi = ogs_supi_from_supi_or_suci(ausf_ue->suci); ogs_assert(ausf_ue->supi); ogs_hash_set(self.supi_hash, ausf_ue->supi, strlen(ausf_ue->supi), ausf_ue); diff --git a/src/bsf/context.c b/src/bsf/context.c index de66aae83..36b5cfe5d 100644 --- a/src/bsf/context.c +++ b/src/bsf/context.c @@ -106,6 +106,8 @@ int bsf_context_parse_config(void) /* handle config in sbi library */ } else if (!strcmp(bsf_key, "service_name")) { /* handle config in sbi library */ + } else if (!strcmp(bsf_key, "discovery")) { + /* handle config in sbi library */ } else ogs_warn("unknown key `%s`", bsf_key); } diff --git a/src/nssf/context.c b/src/nssf/context.c index 1dae37088..316599438 100644 --- a/src/nssf/context.c +++ b/src/nssf/context.c @@ -98,6 +98,8 @@ int nssf_context_parse_config(void) /* handle config in sbi library */ } else if (!strcmp(nssf_key, "service_name")) { /* handle config in sbi library */ + } else if (!strcmp(nssf_key, "discovery")) { + /* handle config in sbi library */ } else if (!strcmp(nssf_key, "nsi")) { ogs_list_t list, list6; ogs_socknode_t *node = NULL, *node6 = NULL; diff --git a/src/pcf/context.c b/src/pcf/context.c index 55fe0d4ba..beaf4557c 100644 --- a/src/pcf/context.c +++ b/src/pcf/context.c @@ -119,6 +119,8 @@ int pcf_context_parse_config(void) /* handle config in sbi library */ } else if (!strcmp(pcf_key, "service_name")) { /* handle config in sbi library */ + } else if (!strcmp(pcf_key, "discovery")) { + /* handle config in sbi library */ } else ogs_warn("unknown key `%s`", pcf_key); } diff --git a/src/pcf/pcf-sm.c b/src/pcf/pcf-sm.c index 570fd51f3..381f08f69 100644 --- a/src/pcf/pcf-sm.c +++ b/src/pcf/pcf-sm.c @@ -179,17 +179,20 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e) message.SmPolicyContextData->supi) { pcf_ue = pcf_ue_find_by_supi( message.SmPolicyContextData->supi); - if (pcf_ue) { - if (message.SmPolicyContextData->pdu_session_id) { - sess = pcf_sess_find_by_psi(pcf_ue, message. - SmPolicyContextData->pdu_session_id); - if (!sess) { - sess = pcf_sess_add(pcf_ue, message. - SmPolicyContextData->pdu_session_id); - ogs_assert(sess); - ogs_debug("[%s:%d] PCF session added", - pcf_ue->supi, sess->psi); - } + if (!pcf_ue) { + pcf_ue = pcf_ue_add( + message.SmPolicyContextData->supi); + ogs_assert(pcf_ue); + } + if (message.SmPolicyContextData->pdu_session_id) { + sess = pcf_sess_find_by_psi(pcf_ue, message. + SmPolicyContextData->pdu_session_id); + if (!sess) { + sess = pcf_sess_add(pcf_ue, message. + SmPolicyContextData->pdu_session_id); + ogs_assert(sess); + ogs_debug("[%s:%d] PCF session added", + pcf_ue->supi, sess->psi); } } } diff --git a/src/scp/context.c b/src/scp/context.c index 7ff44f55d..617f90b58 100644 --- a/src/scp/context.c +++ b/src/scp/context.c @@ -98,6 +98,8 @@ int scp_context_parse_config(void) /* handle config in sbi library */ } else if (!strcmp(scp_key, "service_name")) { /* handle config in sbi library */ + } else if (!strcmp(scp_key, "discovery")) { + /* handle config in sbi library */ } else ogs_warn("unknown key `%s`", scp_key); } diff --git a/src/smf/context.c b/src/smf/context.c index 152a1ada8..5c8e53d4c 100644 --- a/src/smf/context.c +++ b/src/smf/context.c @@ -833,6 +833,8 @@ int smf_context_parse_config(void) /* handle config in sbi library */ } else if (!strcmp(smf_key, "service_name")) { /* handle config in sbi library */ + } else if (!strcmp(smf_key, "discovery")) { + /* handle config in sbi library */ } else ogs_warn("unknown key `%s`", smf_key); } diff --git a/src/udm/context.c b/src/udm/context.c index 3698337a5..254cbb310 100644 --- a/src/udm/context.c +++ b/src/udm/context.c @@ -104,6 +104,8 @@ int udm_context_parse_config(void) /* handle config in sbi library */ } else if (!strcmp(udm_key, "service_name")) { /* handle config in sbi library */ + } else if (!strcmp(udm_key, "discovery")) { + /* handle config in sbi library */ } else ogs_warn("unknown key `%s`", udm_key); } @@ -135,7 +137,7 @@ udm_ue_t *udm_ue_add(char *suci) ogs_assert(udm_ue->suci); ogs_hash_set(self.suci_hash, udm_ue->suci, strlen(udm_ue->suci), udm_ue); - udm_ue->supi = ogs_supi_from_suci(udm_ue->suci); + udm_ue->supi = ogs_supi_from_supi_or_suci(udm_ue->suci); ogs_assert(udm_ue->supi); ogs_hash_set(self.supi_hash, udm_ue->supi, strlen(udm_ue->supi), udm_ue); diff --git a/src/udr/context.c b/src/udr/context.c index 7637dbcec..ba679dfd8 100644 --- a/src/udr/context.c +++ b/src/udr/context.c @@ -86,6 +86,8 @@ int udr_context_parse_config(void) /* handle config in sbi library */ } else if (!strcmp(udr_key, "service_name")) { /* handle config in sbi library */ + } else if (!strcmp(udr_key, "discovery")) { + /* handle config in sbi library */ } else ogs_warn("unknown key `%s`", udr_key); } diff --git a/tests/af/context.c b/tests/af/context.c index 8135aaceb..8c64b29b9 100644 --- a/tests/af/context.c +++ b/tests/af/context.c @@ -113,6 +113,8 @@ int af_context_parse_config(void) /* handle config in sbi library */ } else if (!strcmp(af_key, "service_name")) { /* handle config in sbi library */ + } else if (!strcmp(af_key, "discovery")) { + /* handle config in sbi library */ } else ogs_warn("unknown key `%s`", af_key); }