From 5ccb5f0f990d210b25dc565b553cf583de3d28f0 Mon Sep 17 00:00:00 2001 From: Sukchan Lee Date: Sat, 22 Oct 2022 11:26:04 +0900 Subject: [PATCH] SCP(Model D) is now the default setting. --- configs/310014.yaml.in | 2 +- configs/csfb.yaml.in | 2 +- configs/non3gpp.yaml.in | 2 +- configs/open5gs/amf.yaml.in | 80 +- configs/open5gs/ausf.yaml.in | 80 +- configs/open5gs/bsf.yaml.in | 80 +- configs/open5gs/nrf.yaml.in | 44 + configs/open5gs/nssf.yaml.in | 82 +- configs/open5gs/pcf.yaml.in | 80 +- configs/open5gs/scp.yaml.in | 49 +- configs/open5gs/smf.yaml.in | 80 +- configs/open5gs/udm.yaml.in | 80 +- configs/open5gs/udr.yaml.in | 80 +- configs/sample.yaml.in | 2 +- configs/srslte.yaml.in | 2 +- configs/volte.yaml.in | 2 +- configs/vonr.yaml.in | 2 +- .../guide/02-building-open5gs-from-sources.md | 358 +++--- .../guide/03-splitting-network-functions.md | 124 +- docs/_docs/platform/02-centos.md | 9 +- docs/_docs/platform/03-fedora.md | 2 +- .../_docs/platform/05-macosx-apple-silicon.md | 2 +- docs/_docs/platform/06-macosx-intel.md | 2 +- docs/_docs/platform/07-freebsd.md | 2 +- docs/_docs/platform/08-alpine.md | 2 +- docs/_docs/troubleshoot/01-simple-issues.md | 23 +- .../troubleshoot/02-now-in-github-issues.md | 43 +- docs/_posts/2021-04-09-release-v2.2.6.md | 4 +- docs/_posts/2021-04-30-release-v2.2.7.md | 4 +- docs/_posts/2021-05-09-release-v2.2.8.md | 4 +- docs/_posts/2021-05-19-release-v2.2.9.md | 4 +- docs/assets/webui/install | 2 +- lib/proto/event.c | 2 +- lib/proto/event.h | 2 + lib/sbi/client.c | 184 ++- lib/sbi/client.h | 13 +- lib/sbi/context.c | 149 +-- lib/sbi/context.h | 15 +- lib/sbi/meson.build | 1 + lib/sbi/message.c | 141 ++- lib/sbi/message.h | 49 + lib/sbi/nf-sm.c | 16 +- lib/sbi/nf-sm.h | 2 +- lib/sbi/nnrf-build.c | 549 ++++++--- lib/sbi/nnrf-build.h | 1 + lib/sbi/nnrf-handler.c | 20 +- lib/sbi/nnrf-handler.h | 10 +- lib/sbi/nnrf-path.c | 132 +++ src/scp/nnrf-handler.h => lib/sbi/nnrf-path.h | 23 +- lib/sbi/ogs-sbi.h | 3 +- lib/sbi/path.c | 706 ++++++++---- lib/sbi/path.h | 36 +- misc/netconf.sh | 2 + src/amf/amf-sm.c | 4 +- src/amf/context.c | 8 +- src/amf/context.h | 1 + src/amf/event.h | 2 + src/amf/gmm-handler.c | 8 +- src/amf/nausf-build.c | 18 +- src/amf/nnrf-build.c | 1 + src/amf/nnrf-handler.c | 8 +- src/amf/nnssf-build.c | 14 +- src/amf/nnssf-handler.c | 58 +- src/amf/npcf-build.c | 58 +- src/amf/nsmf-build.c | 169 ++- src/amf/nsmf-build.h | 6 + src/amf/nudm-build.c | 72 +- src/amf/sbi-path.c | 118 +- src/amf/sbi-path.h | 3 +- src/ausf/ausf-sm.c | 4 +- src/ausf/event.h | 2 + src/ausf/nnrf-handler.c | 12 +- src/ausf/nudm-build.c | 24 +- src/ausf/sbi-path.c | 80 +- src/ausf/sbi-path.h | 3 +- src/bsf/bsf-sm.c | 4 +- src/bsf/event.h | 2 + src/bsf/nnrf-handler.c | 12 +- src/bsf/sbi-path.c | 80 +- src/bsf/sbi-path.h | 3 +- src/mme/mme-event.h | 2 + src/nrf/context.c | 8 +- src/nrf/event.c | 39 +- src/nrf/event.h | 31 +- src/nrf/init.c | 5 +- src/nrf/nf-sm.c | 20 +- src/nrf/nnrf-build.c | 34 +- src/nrf/nnrf-handler.c | 2 +- src/nrf/nrf-sm.c | 16 +- src/nrf/sbi-path.c | 50 +- src/nrf/timer.c | 27 +- src/nrf/timer.h | 4 +- src/nssf/event.h | 2 + src/nssf/nssf-sm.c | 2 +- src/nssf/sbi-path.c | 71 +- src/pcf/event.h | 2 + src/pcf/naf-build.c | 10 +- src/pcf/nbsf-build.c | 57 +- src/pcf/nnrf-handler.c | 12 +- src/pcf/nsmf-build.c | 33 +- src/pcf/nudr-handler.c | 7 +- src/pcf/pcf-sm.c | 4 +- src/pcf/sbi-path.c | 131 +-- src/pcf/sbi-path.h | 3 +- src/scp/context.c | 60 +- src/scp/context.h | 27 +- src/scp/event.h | 2 + src/scp/meson.build | 3 - src/scp/nnrf-handler.c | 65 -- src/scp/nscp-handler.c | 27 - src/scp/nscp-handler.h | 36 - src/scp/sbi-path.c | 1001 +++++++++++------ src/scp/sbi-path.h | 7 - src/scp/scp-sm.c | 99 +- src/sgwc/event.h | 2 + src/sgwu/event.h | 2 + src/smf/event.h | 2 + src/smf/namf-build.c | 4 +- src/smf/nnrf-handler.c | 12 +- src/smf/npcf-build.c | 103 +- src/smf/nudm-build.c | 2 +- src/smf/sbi-path.c | 121 +- src/smf/sbi-path.h | 3 +- src/smf/smf-sm.c | 4 +- src/udm/event.h | 2 + src/udm/nnrf-handler.c | 12 +- src/udm/sbi-path.c | 80 +- src/udm/sbi-path.h | 3 +- src/udm/udm-sm.c | 4 +- src/udr/event.h | 2 + src/udr/sbi-path.c | 71 +- src/udr/udr-sm.c | 4 +- src/upf/event.h | 2 + tests/af/af-sm.c | 4 +- tests/af/event.h | 2 + tests/af/nbsf-build.c | 2 +- tests/af/nnrf-handler.c | 12 +- tests/af/npcf-build.c | 20 +- tests/af/sbi-path.c | 85 +- tests/af/sbi-path.h | 3 +- 140 files changed, 4019 insertions(+), 2607 deletions(-) create mode 100644 lib/sbi/nnrf-path.c rename src/scp/nnrf-handler.h => lib/sbi/nnrf-path.h (51%) delete mode 100644 src/scp/nnrf-handler.c delete mode 100644 src/scp/nscp-handler.c delete mode 100644 src/scp/nscp-handler.h diff --git a/configs/310014.yaml.in b/configs/310014.yaml.in index 9dc0af7e3..be56f6c11 100644 --- a/configs/310014.yaml.in +++ b/configs/310014.yaml.in @@ -221,7 +221,7 @@ nssf: - addr: 127.0.0.14 port: 7777 nsi: - - addr: ::1 + - addr: 127.0.0.10 port: 7777 s_nssai: sst: 1 diff --git a/configs/csfb.yaml.in b/configs/csfb.yaml.in index 3542dabed..fa618caa8 100644 --- a/configs/csfb.yaml.in +++ b/configs/csfb.yaml.in @@ -250,7 +250,7 @@ nssf: - addr: 127.0.0.14 port: 7777 nsi: - - addr: ::1 + - addr: 127.0.0.10 port: 7777 s_nssai: sst: 1 diff --git a/configs/non3gpp.yaml.in b/configs/non3gpp.yaml.in index a9842fe86..fe35cb4f0 100644 --- a/configs/non3gpp.yaml.in +++ b/configs/non3gpp.yaml.in @@ -220,7 +220,7 @@ nssf: - addr: 127.0.0.14 port: 7777 nsi: - - addr: ::1 + - addr: 127.0.0.10 port: 7777 s_nssai: sst: 1 diff --git a/configs/open5gs/amf.yaml.in b/configs/open5gs/amf.yaml.in index be70fd239..286f81184 100644 --- a/configs/open5gs/amf.yaml.in +++ b/configs/open5gs/amf.yaml.in @@ -20,6 +20,7 @@ # logger: file: @localstatedir@/log/open5gs/amf.log + # # amf: # @@ -118,6 +119,29 @@ logger: # 'service-names' is always included in the URI query parameter. # * That is, 'no_service_names' has no effect. # +# +# +# o (Default) If you do not set Delegated Discovery as shown below, +# +# 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. +# +# sbi: +# - addr: 127.0.0.5 +# 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 +# # > # # o NGAP Server(all address available) @@ -298,6 +322,50 @@ amf: full: Open5GS amf_name: open5gs-amf0 +# +# scp: +# +# > +# +# o SBI Client(http://127.0.1.10:7777) +# sbi: +# addr: 127.0.1.10 +# port: 7777 +# +# o SBI Client(https://127.0.1.10:443, http://scp.open5gs.org:80) +# sbi: +# - addr: 127.0.1.10 +# tls: +# key: scp.key +# pem: scp.pem +# - name: scp.open5gs.org +# +# o SBI Client(http://[fd69:f21d:873c:fb::1]:80) +# If prefer_ipv4 is true, http://127.0.1.10:80 is selected. +# +# sbi: +# addr: +# - 127.0.1.10 +# - fd69:f21d:873c:fb::1 +# +# o SBI Option (Default) +# - tcp_nodelay : true +# - so_linger.l_onoff : false +# +# sbi: +# addr: 127.0.1.10 +# option: +# tcp_nodelay: false +# so_linger: +# l_onoff: true +# l_linger: 10 +# +# +scp: + sbi: + - addr: 127.0.1.10 + port: 7777 + # # nrf: # @@ -336,12 +404,12 @@ amf: # l_onoff: true # l_linger: 10 # -nrf: - sbi: - - addr: - - 127.0.0.10 - - ::1 - port: 7777 +#nrf: +# sbi: +# - addr: +# - 127.0.0.10 +# - ::1 +# port: 7777 # # parameter: diff --git a/configs/open5gs/ausf.yaml.in b/configs/open5gs/ausf.yaml.in index 867403da3..f4bcfe83b 100644 --- a/configs/open5gs/ausf.yaml.in +++ b/configs/open5gs/ausf.yaml.in @@ -20,6 +20,7 @@ # logger: file: @localstatedir@/log/open5gs/ausf.log + # # ausf: # @@ -118,11 +119,78 @@ logger: # 'service-names' is always included in the URI query parameter. # * That is, 'no_service_names' has no effect. # +# +# +# o (Default) If you do not set Delegated Discovery as shown below, +# +# sbi: +# - addr: 127.0.0.11 +# port: 7777 +# +# - Use SCP if SCP avaiable. Otherwise NRF is used. +# => App fails if both NRF and SCP are unavailable. +# +# sbi: +# - addr: 127.0.0.11 +# 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 +# ausf: sbi: - addr: 127.0.0.11 port: 7777 +# +# scp: +# +# > +# +# o SBI Client(http://127.0.1.10:7777) +# sbi: +# addr: 127.0.1.10 +# port: 7777 +# +# o SBI Client(https://127.0.1.10:443, http://scp.open5gs.org:80) +# sbi: +# - addr: 127.0.1.10 +# tls: +# key: scp.key +# pem: scp.pem +# - name: scp.open5gs.org +# +# o SBI Client(http://[fd69:f21d:873c:fb::1]:80) +# If prefer_ipv4 is true, http://127.0.1.10:80 is selected. +# +# sbi: +# addr: +# - 127.0.1.10 +# - fd69:f21d:873c:fb::1 +# +# o SBI Option (Default) +# - tcp_nodelay : true +# - so_linger.l_onoff : false +# +# sbi: +# addr: 127.0.1.10 +# option: +# tcp_nodelay: false +# so_linger: +# l_onoff: true +# l_linger: 10 +# +# +scp: + sbi: + - addr: 127.0.1.10 + port: 7777 + # # nrf: # @@ -161,12 +229,12 @@ ausf: # l_onoff: true # l_linger: 10 # -nrf: - sbi: - - addr: - - 127.0.0.10 - - ::1 - port: 7777 +#nrf: +# sbi: +# - addr: +# - 127.0.0.10 +# - ::1 +# port: 7777 # # parameter: diff --git a/configs/open5gs/bsf.yaml.in b/configs/open5gs/bsf.yaml.in index c7b895016..7ca701bd5 100644 --- a/configs/open5gs/bsf.yaml.in +++ b/configs/open5gs/bsf.yaml.in @@ -22,6 +22,7 @@ db_uri: mongodb://localhost/open5gs # logger: file: @localstatedir@/log/open5gs/bsf.log + # # bsf: # @@ -120,11 +121,78 @@ logger: # 'service-names' is always included in the URI query parameter. # * That is, 'no_service_names' has no effect. # +# +# +# o (Default) If you do not set Delegated Discovery as shown below, +# +# sbi: +# - addr: 127.0.0.15 +# port: 7777 +# +# - Use SCP if SCP avaiable. Otherwise NRF is used. +# => App fails if both NRF and SCP are unavailable. +# +# sbi: +# - addr: 127.0.0.15 +# 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 +# bsf: sbi: - addr: 127.0.0.15 port: 7777 +# +# scp: +# +# > +# +# o SBI Client(http://127.0.1.10:7777) +# sbi: +# addr: 127.0.1.10 +# port: 7777 +# +# o SBI Client(https://127.0.1.10:443, http://scp.open5gs.org:80) +# sbi: +# - addr: 127.0.1.10 +# tls: +# key: scp.key +# pem: scp.pem +# - name: scp.open5gs.org +# +# o SBI Client(http://[fd69:f21d:873c:fb::1]:80) +# If prefer_ipv4 is true, http://127.0.1.10:80 is selected. +# +# sbi: +# addr: +# - 127.0.1.10 +# - fd69:f21d:873c:fb::1 +# +# o SBI Option (Default) +# - tcp_nodelay : true +# - so_linger.l_onoff : false +# +# sbi: +# addr: 127.0.1.10 +# option: +# tcp_nodelay: false +# so_linger: +# l_onoff: true +# l_linger: 10 +# +# +scp: + sbi: + - addr: 127.0.1.10 + port: 7777 + # # nrf: # @@ -163,12 +231,12 @@ bsf: # l_onoff: true # l_linger: 10 # -nrf: - sbi: - - addr: - - 127.0.0.10 - - ::1 - port: 7777 +#nrf: +# sbi: +# - addr: +# - 127.0.0.10 +# - ::1 +# port: 7777 # # parameter: diff --git a/configs/open5gs/nrf.yaml.in b/configs/open5gs/nrf.yaml.in index ab1a52961..a43fcf194 100644 --- a/configs/open5gs/nrf.yaml.in +++ b/configs/open5gs/nrf.yaml.in @@ -92,6 +92,50 @@ nrf: - ::1 port: 7777 +# +# scp: +# +# > +# +# o SBI Client(http://127.0.1.10:7777) +# sbi: +# addr: 127.0.1.10 +# port: 7777 +# +# o SBI Client(https://127.0.1.10:443, http://scp.open5gs.org:80) +# sbi: +# - addr: 127.0.1.10 +# tls: +# key: scp.key +# pem: scp.pem +# - name: scp.open5gs.org +# +# o SBI Client(http://[fd69:f21d:873c:fb::1]:80) +# If prefer_ipv4 is true, http://127.0.1.10:80 is selected. +# +# sbi: +# addr: +# - 127.0.1.10 +# - fd69:f21d:873c:fb::1 +# +# o SBI Option (Default) +# - tcp_nodelay : true +# - so_linger.l_onoff : false +# +# sbi: +# addr: 127.0.1.10 +# option: +# tcp_nodelay: false +# so_linger: +# l_onoff: true +# l_linger: 10 +# +# +scp: + sbi: + - addr: 127.0.1.10 + port: 7777 + # # parameter: # diff --git a/configs/open5gs/nssf.yaml.in b/configs/open5gs/nssf.yaml.in index 5d1214c04..695ac704e 100644 --- a/configs/open5gs/nssf.yaml.in +++ b/configs/open5gs/nssf.yaml.in @@ -20,6 +20,7 @@ # logger: file: @localstatedir@/log/open5gs/nssf.log + # # nssf: # @@ -168,16 +169,83 @@ logger: # 'service-names' is always included in the URI query parameter. # * That is, 'no_service_names' has no effect. # +# +# +# o (Default) If you do not set Delegated Discovery as shown below, +# +# sbi: +# - addr: 127.0.0.14 +# port: 7777 +# +# - Use SCP if SCP avaiable. Otherwise NRF is used. +# => App fails if both NRF and SCP are unavailable. +# +# sbi: +# - addr: 127.0.0.14 +# 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 +# nssf: sbi: - addr: 127.0.0.14 port: 7777 nsi: - - addr: ::1 + - addr: 127.0.0.10 port: 7777 s_nssai: sst: 1 +# +# scp: +# +# > +# +# o SBI Client(http://127.0.1.10:7777) +# sbi: +# addr: 127.0.1.10 +# port: 7777 +# +# o SBI Client(https://127.0.1.10:443, http://scp.open5gs.org:80) +# sbi: +# - addr: 127.0.1.10 +# tls: +# key: scp.key +# pem: scp.pem +# - name: scp.open5gs.org +# +# o SBI Client(http://[fd69:f21d:873c:fb::1]:80) +# If prefer_ipv4 is true, http://127.0.1.10:80 is selected. +# +# sbi: +# addr: +# - 127.0.1.10 +# - fd69:f21d:873c:fb::1 +# +# o SBI Option (Default) +# - tcp_nodelay : true +# - so_linger.l_onoff : false +# +# sbi: +# addr: 127.0.1.10 +# option: +# tcp_nodelay: false +# so_linger: +# l_onoff: true +# l_linger: 10 +# +# +scp: + sbi: + - addr: 127.0.1.10 + port: 7777 + # # nrf: # @@ -204,12 +272,12 @@ nssf: # - 127.0.0.10 # - fd69:f21d:873c:fa::1 # -nrf: - sbi: - - addr: - - 127.0.0.10 - - ::1 - port: 7777 +#nrf: +# sbi: +# - addr: +# - 127.0.0.10 +# - ::1 +# port: 7777 # # parameter: diff --git a/configs/open5gs/pcf.yaml.in b/configs/open5gs/pcf.yaml.in index 5b1a1a9a8..63ada49fc 100644 --- a/configs/open5gs/pcf.yaml.in +++ b/configs/open5gs/pcf.yaml.in @@ -22,6 +22,7 @@ db_uri: mongodb://localhost/open5gs # logger: file: @localstatedir@/log/open5gs/pcf.log + # # pcf: # @@ -127,11 +128,78 @@ logger: # 'service-names' is always included in the URI query parameter. # * That is, 'no_service_names' has no effect. # +# +# +# o (Default) If you do not set Delegated Discovery as shown below, +# +# sbi: +# - addr: 127.0.0.13 +# port: 7777 +# +# - Use SCP if SCP avaiable. Otherwise NRF is used. +# => App fails if both NRF and SCP are unavailable. +# +# sbi: +# - addr: 127.0.0.13 +# 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 +# pcf: sbi: - addr: 127.0.0.13 port: 7777 +# +# scp: +# +# > +# +# o SBI Client(http://127.0.1.10:7777) +# sbi: +# addr: 127.0.1.10 +# port: 7777 +# +# o SBI Client(https://127.0.1.10:443, http://scp.open5gs.org:80) +# sbi: +# - addr: 127.0.1.10 +# tls: +# key: scp.key +# pem: scp.pem +# - name: scp.open5gs.org +# +# o SBI Client(http://[fd69:f21d:873c:fb::1]:80) +# If prefer_ipv4 is true, http://127.0.1.10:80 is selected. +# +# sbi: +# addr: +# - 127.0.1.10 +# - fd69:f21d:873c:fb::1 +# +# o SBI Option (Default) +# - tcp_nodelay : true +# - so_linger.l_onoff : false +# +# sbi: +# addr: 127.0.1.10 +# option: +# tcp_nodelay: false +# so_linger: +# l_onoff: true +# l_linger: 10 +# +# +scp: + sbi: + - addr: 127.0.1.10 + port: 7777 + # # nrf: # @@ -170,12 +238,12 @@ pcf: # l_onoff: true # l_linger: 10 # -nrf: - sbi: - - addr: - - 127.0.0.10 - - ::1 - port: 7777 +#nrf: +# sbi: +# - addr: +# - 127.0.0.10 +# - ::1 +# port: 7777 # # parameter: diff --git a/configs/open5gs/scp.yaml.in b/configs/open5gs/scp.yaml.in index 8d720c3d8..cfdbdce74 100644 --- a/configs/open5gs/scp.yaml.in +++ b/configs/open5gs/scp.yaml.in @@ -88,19 +88,10 @@ logger: # l_onoff: true # l_linger: 10 # -# -# -# o Next hop SCP Server(https://127.0.1.11:7777) -# next_scp: -# sbi: -# - addr: 127.0.1.11 -# port: 7777 -# # # # o (Default) If you do not set Delegated Discovery as shown below, # -# next_scp: # sbi: # - addr: 127.0.1.10 # port: 7777 @@ -108,7 +99,6 @@ logger: # - 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 @@ -126,6 +116,45 @@ scp: - addr: 127.0.1.10 port: 7777 +# +# next_scp: +# +# +# +# o SBI Client(http://127.0.1.11:7777) +# sbi: +# addr: 127.0.1.11 +# port: 7777 +# +# o SBI Client(https://127.0.1.11:443, http://next-scp.open5gs.org:80) +# sbi: +# - addr: 127.0.1.11 +# tls: +# key: next-scp.key +# pem: next-scp.pem +# - name: next-scp.open5gs.org +# +# o SBI Client(http://[fd69:f21d:873c:fb::1]:80) +# If prefer_ipv4 is true, http://127.0.1.11:80 is selected. +# +# sbi: +# addr: +# - 127.0.1.11 +# - fd69:f21d:873c:fb::1 +# +# o SBI Option (Default) +# - tcp_nodelay : true +# - so_linger.l_onoff : false +# +# sbi: +# addr: 127.0.1.11 +# option: +# tcp_nodelay: false +# so_linger: +# l_onoff: true +# l_linger: 10 +# + # # nrf: # diff --git a/configs/open5gs/smf.yaml.in b/configs/open5gs/smf.yaml.in index d919b8839..9aeb8e903 100644 --- a/configs/open5gs/smf.yaml.in +++ b/configs/open5gs/smf.yaml.in @@ -20,6 +20,7 @@ # logger: file: @localstatedir@/log/open5gs/smf.log + # # smf: # @@ -118,6 +119,29 @@ logger: # 'service-names' is always included in the URI query parameter. # * That is, 'no_service_names' has no effect. # +# +# +# o (Default) If you do not set Delegated Discovery as shown below, +# +# sbi: +# - addr: 127.0.0.4 +# port: 7777 +# +# - Use SCP if SCP avaiable. Otherwise NRF is used. +# => App fails if both NRF and SCP are unavailable. +# +# sbi: +# - addr: 127.0.0.4 +# 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 +# # # # @@ -446,6 +470,50 @@ smf: enabled: auto freeDiameter: @sysconfdir@/freeDiameter/smf.conf +# +# scp: +# +# > +# +# o SBI Client(http://127.0.1.10:7777) +# sbi: +# addr: 127.0.1.10 +# port: 7777 +# +# o SBI Client(https://127.0.1.10:443, http://scp.open5gs.org:80) +# sbi: +# - addr: 127.0.1.10 +# tls: +# key: scp.key +# pem: scp.pem +# - name: scp.open5gs.org +# +# o SBI Client(http://[fd69:f21d:873c:fb::1]:80) +# If prefer_ipv4 is true, http://127.0.1.10:80 is selected. +# +# sbi: +# addr: +# - 127.0.1.10 +# - fd69:f21d:873c:fb::1 +# +# o SBI Option (Default) +# - tcp_nodelay : true +# - so_linger.l_onoff : false +# +# sbi: +# addr: 127.0.1.10 +# option: +# tcp_nodelay: false +# so_linger: +# l_onoff: true +# l_linger: 10 +# +# +scp: + sbi: + - addr: 127.0.1.10 + port: 7777 + # # nrf: # @@ -484,12 +552,12 @@ smf: # l_onoff: true # l_linger: 10 # -nrf: - sbi: - - addr: - - 127.0.0.10 - - ::1 - port: 7777 +#nrf: +# sbi: +# - addr: +# - 127.0.0.10 +# - ::1 +# port: 7777 # # upf: diff --git a/configs/open5gs/udm.yaml.in b/configs/open5gs/udm.yaml.in index 3cc10fe43..fef01c571 100644 --- a/configs/open5gs/udm.yaml.in +++ b/configs/open5gs/udm.yaml.in @@ -20,6 +20,7 @@ # logger: file: @localstatedir@/log/open5gs/udm.log + # # udm: # @@ -120,11 +121,78 @@ logger: # 'service-names' is always included in the URI query parameter. # * That is, 'no_service_names' has no effect. # +# +# +# o (Default) If you do not set Delegated Discovery as shown below, +# +# sbi: +# - addr: 127.0.0.12 +# port: 7777 +# +# - Use SCP if SCP avaiable. Otherwise NRF is used. +# => App fails if both NRF and SCP are unavailable. +# +# sbi: +# - addr: 127.0.0.12 +# 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 +# udm: sbi: - addr: 127.0.0.12 port: 7777 +# +# scp: +# +# > +# +# o SBI Client(http://127.0.1.10:7777) +# sbi: +# addr: 127.0.1.10 +# port: 7777 +# +# o SBI Client(https://127.0.1.10:443, http://scp.open5gs.org:80) +# sbi: +# - addr: 127.0.1.10 +# tls: +# key: scp.key +# pem: scp.pem +# - name: scp.open5gs.org +# +# o SBI Client(http://[fd69:f21d:873c:fb::1]:80) +# If prefer_ipv4 is true, http://127.0.1.10:80 is selected. +# +# sbi: +# addr: +# - 127.0.1.10 +# - fd69:f21d:873c:fb::1 +# +# o SBI Option (Default) +# - tcp_nodelay : true +# - so_linger.l_onoff : false +# +# sbi: +# addr: 127.0.1.10 +# option: +# tcp_nodelay: false +# so_linger: +# l_onoff: true +# l_linger: 10 +# +# +scp: + sbi: + - addr: 127.0.1.10 + port: 7777 + # # nrf: # @@ -163,12 +231,12 @@ udm: # l_onoff: true # l_linger: 10 # -nrf: - sbi: - - addr: - - 127.0.0.10 - - ::1 - port: 7777 +#nrf: +# sbi: +# - addr: +# - 127.0.0.10 +# - ::1 +# port: 7777 # # parameter: diff --git a/configs/open5gs/udr.yaml.in b/configs/open5gs/udr.yaml.in index 33be88860..d8943d00a 100644 --- a/configs/open5gs/udr.yaml.in +++ b/configs/open5gs/udr.yaml.in @@ -22,6 +22,7 @@ db_uri: mongodb://localhost/open5gs # logger: file: @localstatedir@/log/open5gs/udr.log + # # udr: # @@ -120,11 +121,78 @@ logger: # 'service-names' is always included in the URI query parameter. # * That is, 'no_service_names' has no effect. # +# +# +# o (Default) If you do not set Delegated Discovery as shown below, +# +# sbi: +# - addr: 127.0.0.20 +# port: 7777 +# +# - Use SCP if SCP avaiable. Otherwise NRF is used. +# => App fails if both NRF and SCP are unavailable. +# +# sbi: +# - addr: 127.0.0.20 +# 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 +# udr: sbi: - addr: 127.0.0.20 port: 7777 +# +# scp: +# +# > +# +# o SBI Client(http://127.0.1.10:7777) +# sbi: +# addr: 127.0.1.10 +# port: 7777 +# +# o SBI Client(https://127.0.1.10:443, http://scp.open5gs.org:80) +# sbi: +# - addr: 127.0.1.10 +# tls: +# key: scp.key +# pem: scp.pem +# - name: scp.open5gs.org +# +# o SBI Client(http://[fd69:f21d:873c:fb::1]:80) +# If prefer_ipv4 is true, http://127.0.1.10:80 is selected. +# +# sbi: +# addr: +# - 127.0.1.10 +# - fd69:f21d:873c:fb::1 +# +# o SBI Option (Default) +# - tcp_nodelay : true +# - so_linger.l_onoff : false +# +# sbi: +# addr: 127.0.1.10 +# option: +# tcp_nodelay: false +# so_linger: +# l_onoff: true +# l_linger: 10 +# +# +scp: + sbi: + - addr: 127.0.1.10 + port: 7777 + # # nrf: # @@ -163,12 +231,12 @@ udr: # l_onoff: true # l_linger: 10 # -nrf: - sbi: - - addr: - - 127.0.0.10 - - ::1 - port: 7777 +#nrf: +# sbi: +# - addr: +# - 127.0.0.10 +# - ::1 +# port: 7777 # # parameter: diff --git a/configs/sample.yaml.in b/configs/sample.yaml.in index a64e14d9f..a06017392 100644 --- a/configs/sample.yaml.in +++ b/configs/sample.yaml.in @@ -285,7 +285,7 @@ nssf: - addr: 127.0.0.14 port: 7777 nsi: - - addr: ::1 + - addr: 127.0.0.10 port: 7777 s_nssai: sst: 1 diff --git a/configs/srslte.yaml.in b/configs/srslte.yaml.in index 20055efd0..7c994d052 100644 --- a/configs/srslte.yaml.in +++ b/configs/srslte.yaml.in @@ -216,7 +216,7 @@ nssf: - addr: 127.0.0.14 port: 7777 nsi: - - addr: ::1 + - addr: 127.0.0.10 port: 7777 s_nssai: sst: 1 diff --git a/configs/volte.yaml.in b/configs/volte.yaml.in index f9a8a6ce7..b5909bfc6 100644 --- a/configs/volte.yaml.in +++ b/configs/volte.yaml.in @@ -223,7 +223,7 @@ nssf: - addr: 127.0.0.14 port: 7777 nsi: - - addr: ::1 + - addr: 127.0.0.10 port: 7777 s_nssai: sst: 1 diff --git a/configs/vonr.yaml.in b/configs/vonr.yaml.in index 122660717..696b6e165 100644 --- a/configs/vonr.yaml.in +++ b/configs/vonr.yaml.in @@ -226,7 +226,7 @@ nssf: - addr: 127.0.0.14 port: 7777 nsi: - - addr: ::1 + - addr: 127.0.0.10 port: 7777 s_nssai: sst: 1 diff --git a/docs/_docs/guide/02-building-open5gs-from-sources.md b/docs/_docs/guide/02-building-open5gs-from-sources.md index 897e387b7..81c064d55 100644 --- a/docs/_docs/guide/02-building-open5gs-from-sources.md +++ b/docs/_docs/guide/02-building-open5gs-from-sources.md @@ -6,7 +6,7 @@ head_inline: "" This post explains how to compile and install the source code on **Debian/Ubuntu** based Linux Distribution. {: .blue} -**Note:** Ubuntu 16.04(xenial) and earlier versions, and Debian 9(stretch) and earlier versions are not supported. +**Note:** Ubuntu 22.04(focal) and earlier versions, and Debian 9(stretch) and earlier versions are not supported. {: .notice--danger} @@ -15,11 +15,24 @@ This post explains how to compile and install the source code on **Debian/Ubuntu Install MongoDB with package manager. It is used as database for NRF/PCF/UDR and PCRF/HSS. +Import the public key used by the package management system. + +```bash +$ wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add - +``` + +Create the list file /etc/apt/sources.list.d/mongodb-org-6.0.list for your version of Ubuntu. + +```bash +$ echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list +``` + +Install the MongoDB packages. ```bash $ sudo apt update -$ sudo apt install mongodb -$ sudo systemctl start mongodb (if '/usr/bin/mongod' is not running) -$ sudo systemctl enable mongodb (ensure to automatically start it on system boot) +$ sudo apt-get install -y mongodb-org +$ sudo systemctl start mongod (if '/usr/bin/mongod' is not running) +$ sudo systemctl enable mongod (ensure to automatically start it on system boot) ``` ### Setting up TUN device (not persistent after rebooting) @@ -99,12 +112,15 @@ Modify [install/etc/open5gs/amf.yaml](https://github.com/{{ site.github_username $ diff -u /etc/open5gs/amf.yaml.old /etc/open5gs/amf.yaml --- amf.yaml 2020-09-05 20:52:28.652234967 -0400 +++ amf.yaml.new 2020-09-05 20:55:07.453114885 -0400 -@@ -165,23 +165,23 @@ +@@ -293,26 +293,26 @@ amf: - addr: 127.0.0.5 port: 7777 ngap: - - addr: 127.0.0.5 + - addr: 10.10.0.5 + metrics: + addr: 127.0.0.5 + port: 9090 guami: - plmn_id: - mcc: 999 @@ -118,10 +134,9 @@ $ diff -u /etc/open5gs/amf.yaml.old /etc/open5gs/amf.yaml - plmn_id: - mcc: 999 - mnc: 70 -- tac: 1 + mcc: 001 + mnc: 01 -+ tac: 2 + tac: 1 plmn_support: - plmn_id: - mcc: 999 @@ -138,13 +153,11 @@ Modify [install/etc/open5gs/upf.yaml](https://github.com/{{ site.github_username $ diff -u /etc/open5gs/upf.yaml.old /etc/open5gs/upf.yaml --- upf.yaml 2020-09-05 20:52:28.652234967 -0400 +++ upf.yaml.new 2020-09-05 20:52:55.279052142 -0400 -@@ -137,9 +137,7 @@ +@@ -168,7 +168,7 @@ upf: pfcp: - addr: 127.0.0.7 gtpu: -- - addr: -- - 127.0.0.7 -- - ::1 +- - addr: 127.0.0.7 + - addr: 10.11.0.7 subnet: - addr: 10.45.0.1/16 @@ -158,14 +171,15 @@ Modify [install/etc/open5gs/mme.yaml](https://github.com/{{ site.github_username $ diff -u /etc/open5gs/mme.yaml.old /etc/open5gs/mme.yaml --- mme.yaml 2020-09-05 20:52:28.648235143 -0400 +++ mme.yaml.new 2020-09-05 20:56:05.434484208 -0400 -@@ -204,20 +204,20 @@ - mme: - freeDiameter: /home/acetcom/Documents/git/open5gs/install/etc/freeDiameter/mme.conf +@@ -253,20 +253,20 @@ mme: s1ap: -- addr: 127.0.0.2 -+ addr: 10.10.0.2 + - addr: 127.0.0.2 gtpc: +- - addr: 127.0.0.2 ++ - addr: 10.10.0.2 + metrics: addr: 127.0.0.2 + port: 9090 gummei: plmn_id: - mcc: 999 @@ -178,13 +192,11 @@ $ diff -u /etc/open5gs/mme.yaml.old /etc/open5gs/mme.yaml plmn_id: - mcc: 999 - mnc: 70 -- tac: 1 + mcc: 001 + mnc: 01 -+ tac: 2 + tac: 1 security: - integrity_order : [ EIA1, EIA2, EIA0 ] - ciphering_order : [ EEA0, EEA1, EEA2 ] + integrity_order : [ EIA2, EIA1, EIA0 ] ``` Modify [install/etc/open5gs/sgwu.yaml](https://github.com/{{ site.github_username }}/open5gs/blob/main/configs/open5gs/sgwu.yaml.in) to set the GTP-U IP address. @@ -192,15 +204,14 @@ Modify [install/etc/open5gs/sgwu.yaml](https://github.com/{{ site.github_usernam $ diff -u /etc/open5gs/sgwu.yaml.old /etc/open5gs/sgwu.yaml --- sgwu.yaml 2020-09-05 20:50:39.393022566 -0400 +++ sgwu.yaml.new 2020-09-05 20:51:06.667838823 -0400 -@@ -51,7 +51,7 @@ +@@ -98,7 +98,7 @@ logger: # sgwu: - gtpu: -- addr: 127.0.0.6 -+ addr: 10.11.0.6 pfcp: - addr: 127.0.0.6 - +- - addr: 127.0.0.6 ++ - addr: 10.11.0.6 + gtpu: + - addr: 127.0.0.6 ``` If you modify the config files while Open5GS daemons are running, please restart them @@ -210,140 +221,164 @@ If you modify the config files while Open5GS daemons are running, please restart --- ```bash -$ ./install/bin/open5gs-mmed -Open5GS daemon v2.1.0 +$ ./install/bin/open5gs-nrfd +Open5GS daemon v2.4.11-100-gbea24d7 -08/21 22:53:47.328: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/mme.yaml' (../src/main.c:54) -08/21 22:53:47.328: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/mme.log' (../src/main.c:57) -08/21 22:53:47.365: [app] INFO: MME initialize...done (../src/mme/app-init.c:33) -08/21 22:53:47.365: [gtp] INFO: gtp_server() [127.0.0.2]:2123 (../lib/gtp/path.c:32) -08/21 22:53:47.365: [gtp] INFO: gtp_connect() [127.0.0.3]:2123 (../lib/gtp/path.c:59) -08/21 22:53:47.366: [mme] INFO: s1ap_server() [127.0.0.2]:36412 (../src/mme/s1ap-sctp.c:57) +10/22 10:43:43.669: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/nrf.yaml' (../lib/app/ogs-init.c:126) +10/22 10:43:43.669: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/nrf.log' (../lib/app/ogs-init.c:129) +10/22 10:43:43.670: [sbi] INFO: nghttp2_server() [127.0.0.10]:7777 (../lib/sbi/nghttp2-server.c:150) +10/22 10:43:43.670: [sbi] INFO: nghttp2_server() [::1]:7777 (../lib/sbi/nghttp2-server.c:150) +10/22 10:43:43.671: [app] INFO: NRF initialize...done (../src/nrf/app.c:31) -$ ./install/bin/open5gs-sgwcd -Open5GS daemon v2.1.0 +$ ./install/bin/open5gs-scpd +Open5GS daemon v2.4.11-100-gbea24d7 -08/21 22:54:43.059: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/sgwc.yaml' (../src/main.c:54) -08/21 22:54:43.059: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/sgwc.log' (../src/main.c:57) -08/21 22:54:43.065: [app] INFO: SGW-C initialize...done (../src/sgwc/app.c:31) -08/21 22:54:43.066: [gtp] INFO: gtp_server() [127.0.0.3]:2123 (../lib/gtp/path.c:32) -08/21 22:54:43.066: [pfcp] INFO: pfcp_server() [127.0.0.3]:8805 (../lib/pfcp/path.c:32) -08/21 22:54:43.066: [pfcp] INFO: ogs_pfcp_connect() [127.0.0.6]:8805 (../lib/pfcp/path.c:60) - -$ ./install/bin/open5gs-smfd -Open5GS daemon v2.1.0 - -08/21 22:54:56.000: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/smf.yaml' (../src/main.c:54) -08/21 22:54:56.000: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/smf.log' (../src/main.c:57) -08/21 22:54:56.050: [gtp] INFO: gtp_server() [127.0.0.4]:2123 (../lib/gtp/path.c:32) -08/21 22:54:56.050: [app] INFO: SMF initialize...done (../src/smf/app.c:31) -08/21 22:54:56.050: [gtp] INFO: gtp_server() [::1]:2123 (../lib/gtp/path.c:32) -08/21 22:54:56.050: [pfcp] INFO: pfcp_server() [127.0.0.4]:8805 (../lib/pfcp/path.c:32) -08/21 22:54:56.050: [pfcp] INFO: pfcp_server() [::1]:8805 (../lib/pfcp/path.c:32) -08/21 22:54:56.050: [pfcp] INFO: ogs_pfcp_connect() [127.0.0.7]:8805 (../lib/pfcp/path.c:60) -08/21 22:54:56.051: [sbi] INFO: sbi_server() [127.0.0.4]:7777 (../lib/sbi/server.c:298) +10/22 10:43:45.709: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/scp.yaml' (../lib/app/ogs-init.c:126) +10/22 10:43:45.709: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/scp.log' (../lib/app/ogs-init.c:129) +10/22 10:43:45.711: [sbi] INFO: nghttp2_server() [127.0.1.10]:7777 (../lib/sbi/nghttp2-server.c:150) +10/22 10:43:45.712: [app] INFO: SCP initialize...done (../src/scp/app.c:31) $ ./install/bin/open5gs-amfd -Open5GS daemon v2.1.0 +Open5GS daemon v2.4.11-100-gbea24d7 -08/21 22:55:14.015: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/amf.yaml' (../src/main.c:54) -08/21 22:55:14.015: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/amf.log' (../src/main.c:57) -08/21 22:55:14.039: [app] INFO: AMF initialize...done (../src/amf/app.c:33) -08/21 22:55:14.040: [sbi] INFO: sbi_server() [127.0.0.5]:7777 (../lib/sbi/server.c:298) -08/21 22:55:14.040: [amf] INFO: ngap_server() [127.0.0.5]:38412 (../src/amf/ngap-sctp.c:56) +10/22 10:44:01.416: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/amf.yaml' (../lib/app/ogs-init.c:126) +10/22 10:44:01.416: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/amf.log' (../lib/app/ogs-init.c:129) +10/22 10:44:01.419: [sbi] INFO: NF Service [namf-comm] (../lib/sbi/context.c:1401) +10/22 10:44:01.420: [sbi] INFO: nghttp2_server() [127.0.0.5]:7777 (../lib/sbi/nghttp2-server.c:150) +10/22 10:44:01.420: [amf] INFO: ngap_server() [127.0.0.5]:38412 (../src/amf/ngap-sctp.c:61) +10/22 10:44:01.420: [sctp] INFO: AMF initialize...done (../src/amf/app.c:33) -$ ./install/bin/open5gs-sgwud -Open5GS daemon v2.1.0 +$ ./install/bin/open5gs-smfd +Open5GS daemon v2.4.11-100-gbea24d7 -08/21 22:54:10.357: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/sgwu.yaml' (../src/main.c:54) -08/21 22:54:10.357: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/sgwu.log' (../src/main.c:57) -08/21 22:54:10.360: [pfcp] INFO: pfcp_server() [127.0.0.6]:8805 (../lib/pfcp/path.c:32) -08/21 22:54:10.360: [app] INFO: SGW-U initialize...done (../src/sgwu/app.c:31) -08/21 22:54:10.361: [gtp] INFO: gtp_server() [127.0.0.6]:2152 (../lib/gtp/path.c:32) +10/22 10:44:03.217: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/smf.yaml' (../lib/app/ogs-init.c:126) +10/22 10:44:03.217: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/smf.log' (../lib/app/ogs-init.c:129) +10/22 10:44:03.269: [gtp] INFO: gtp_server() [127.0.0.4]:2123 (../lib/gtp/path.c:30) +10/22 10:44:03.269: [gtp] INFO: gtp_server() [::1]:2123 (../lib/gtp/path.c:30) +10/22 10:44:03.269: [gtp] INFO: gtp_server() [127.0.0.4]:2152 (../lib/gtp/path.c:30) +10/22 10:44:03.269: [gtp] INFO: gtp_server() [::1]:2152 (../lib/gtp/path.c:30) +10/22 10:44:03.269: [pfcp] INFO: pfcp_server() [127.0.0.4]:8805 (../lib/pfcp/path.c:30) +10/22 10:44:03.269: [pfcp] INFO: pfcp_server() [::1]:8805 (../lib/pfcp/path.c:30) +10/22 10:44:03.269: [pfcp] INFO: ogs_pfcp_connect() [127.0.0.7]:8805 (../lib/pfcp/path.c:61) +10/22 10:44:03.269: [sbi] INFO: NF Service [nsmf-pdusession] (../lib/sbi/context.c:1401) +10/22 10:44:03.270: [sbi] INFO: nghttp2_server() [127.0.0.4]:7777 (../lib/sbi/nghttp2-server.c:150) +10/22 10:44:03.270: [app] INFO: SMF initialize...done (../src/smf/app.c:31) $ ./install/bin/open5gs-upfd -Open5GS daemon v2.1.0 +Open5GS daemon v2.4.11-100-gbea24d7 -08/21 22:54:21.596: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/upf.yaml' (../src/main.c:54) -08/21 22:54:21.596: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/upf.log' (../src/main.c:57) -08/21 22:54:21.601: [pfcp] INFO: pfcp_server() [127.0.0.7]:8805 (../lib/pfcp/path.c:32) -08/21 22:54:21.601: [app] INFO: UPF initialize...done (../src/upf/app.c:31) -08/21 22:54:21.601: [gtp] INFO: gtp_server() [127.0.0.7]:2152 (../lib/gtp/path.c:32) -08/21 22:54:21.601: [gtp] INFO: gtp_server() [::1]:2152 (../lib/gtp/path.c:32) +10/22 10:44:06.884: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/upf.yaml' (../lib/app/ogs-init.c:126) +10/22 10:44:06.884: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/upf.log' (../lib/app/ogs-init.c:129) +10/22 10:44:06.892: [pfcp] INFO: pfcp_server() [127.0.0.7]:8805 (../lib/pfcp/path.c:30) +10/22 10:44:06.892: [gtp] INFO: gtp_server() [127.0.0.7]:2152 (../lib/gtp/path.c:30) +10/22 10:44:06.892: [app] INFO: UPF initialize...done (../src/upf/app.c:31) -$ ./install/bin/open5gs-hssd -Open5GS daemon v2.1.0 +$./install/bin/open5gs-ausfd +Open5GS daemon v2.4.11-100-gbea24d7 -08/21 22:57:17.450: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/hss.yaml' (../src/main.c:54) -08/21 22:57:17.450: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/hss.log' (../src/main.c:57) -08/21 22:57:17.451: [dbi] INFO: MongoDB URI: 'mongodb://localhost/open5gs' (../lib/dbi/ogs-mongoc.c:99) -08/21 22:57:17.519: [app] INFO: HSS initialize...done (../src/hss/app-init.c:31) - -$ ./install/bin/open5gs-pcrfd -Open5GS daemon v2.1.0 - -08/21 22:57:45.894: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/pcrf.yaml' (../src/main.c:54) -08/21 22:57:45.894: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/pcrf.log' (../src/main.c:57) -08/21 22:57:45.896: [dbi] INFO: MongoDB URI: 'mongodb://localhost/open5gs' (../lib/dbi/ogs-mongoc.c:99) -08/21 22:57:45.997: [app] INFO: PCRF initialize...done (../src/pcrf/app-init.c:31) - -$ ./install/bin/open5gs-nrfd -Open5GS daemon v2.1.0 - -08/21 22:56:35.472: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/nrf.yaml' (../src/main.c:54) -08/21 22:56:35.472: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/nrf.log' (../src/main.c:57) -08/21 22:56:35.472: [app] INFO: NRF initialize...done (../src/nrf/app.c:31) -08/21 22:56:35.473: [sbi] INFO: sbi_server() [127.0.0.10]:7777 (../lib/sbi/server.c:298) -08/21 22:56:35.473: [sbi] INFO: sbi_server() [::1]:7777 (../lib/sbi/server.c:298 - -$ ./install/bin/open5gs-ausfd -Open5GS daemon v2.1.0 - -08/21 22:55:41.899: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/ausf.yaml' (../src/main.c:54) -08/21 22:55:41.899: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/ausf.log' (../src/main.c:57) -08/21 22:55:41.900: [app] INFO: AUSF initialize...done (../src/ausf/app.c:31) -08/21 22:55:41.900: [sbi] INFO: sbi_server() [127.0.0.11]:7777 (../lib/sbi/server.c:298) +10/22 10:44:08.747: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/ausf.yaml' (../lib/app/ogs-init.c:126) +10/22 10:44:08.747: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/ausf.log' (../lib/app/ogs-init.c:129) +10/22 10:44:08.748: [sbi] INFO: NF Service [nausf-auth] (../lib/sbi/context.c:1401) +10/22 10:44:08.749: [sbi] INFO: nghttp2_server() [127.0.0.11]:7777 (../lib/sbi/nghttp2-server.c:150) +10/22 10:44:08.749: [app] INFO: AUSF initialize...done (../src/ausf/app.c:31) $ ./install/bin/open5gs-udmd -Open5GS daemon v2.1.0 +Open5GS daemon v2.4.11-100-gbea24d7 -08/21 22:56:02.154: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/udm.yaml' (../src/main.c:54) -08/21 22:56:02.154: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/udm.log' (../src/main.c:57) -08/21 22:56:02.155: [app] INFO: UDM initialize...done (../src/udm/app.c:31) -08/21 22:56:02.155: [sbi] INFO: sbi_server() [127.0.0.12]:7777 (../lib/sbi/server.c:298) +10/22 10:44:10.724: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/udm.yaml' (../lib/app/ogs-init.c:126) +10/22 10:44:10.724: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/udm.log' (../lib/app/ogs-init.c:129) +10/22 10:44:10.726: [sbi] INFO: NF Service [nudm-ueau] (../lib/sbi/context.c:1401) +10/22 10:44:10.726: [sbi] INFO: NF Service [nudm-uecm] (../lib/sbi/context.c:1401) +10/22 10:44:10.726: [sbi] INFO: NF Service [nudm-sdm] (../lib/sbi/context.c:1401) +10/22 10:44:10.727: [sbi] INFO: nghttp2_server() [127.0.0.12]:7777 (../lib/sbi/nghttp2-server.c:150) +10/22 10:44:10.727: [app] INFO: UDM initialize...done (../src/udm/app.c:31) -$ ./install/bin/open5gs-pcfd -Open5GS daemon v2.1.0 +$./install/bin/open5gs-pcfd +Open5GS daemon v2.4.11-100-gbea24d7 -08/21 22:56:02.154: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/pcf.yaml' (../src/main.c:54) -08/21 22:56:02.154: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/pcf.log' (../src/main.c:57) -08/21 22:56:02.155: [app] INFO: PCF initialize...done (../src/pcf/app.c:31) -08/21 22:56:02.155: [sbi] INFO: sbi_server() [127.0.0.12]:7777 (../lib/sbi/server.c:298) +10/22 10:44:14.265: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/pcf.yaml' (../lib/app/ogs-init.c:126) +10/22 10:44:14.265: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/pcf.log' (../lib/app/ogs-init.c:129) +10/22 10:44:14.269: [dbi] INFO: MongoDB URI: 'mongodb://localhost/open5gs' (../lib/dbi/ogs-mongoc.c:130) +10/22 10:44:14.269: [sbi] INFO: NF Service [npcf-am-policy-control] (../lib/sbi/context.c:1401) +10/22 10:44:14.269: [sbi] INFO: NF Service [npcf-smpolicycontrol] (../lib/sbi/context.c:1401) +10/22 10:44:14.269: [sbi] INFO: NF Service [npcf-policyauthorization] (../lib/sbi/context.c:1401) +10/22 10:44:14.269: [sbi] INFO: nghttp2_server() [127.0.0.13]:7777 (../lib/sbi/nghttp2-server.c:150) +10/22 10:44:14.269: [app] INFO: PCF initialize...done (../src/pcf/app.c:31) $ ./install/bin/open5gs-nssfd -Open5GS daemon v2.1.0 +Open5GS daemon v2.4.11-100-gbea24d7 -08/21 22:56:02.154: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/nssfd.yaml' (../src/main.c:54) -08/21 22:56:02.154: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/nssfd.log' (../src/main.c:57) -08/21 22:56:02.155: [app] INFO: NSSF initialize...done (../src/nssfd/app.c:31) -08/21 22:56:02.155: [sbi] INFO: sbi_server() [127.0.0.12]:7777 (../lib/sbi/server.c:298) +10/22 10:44:16.250: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/nssf.yaml' (../lib/app/ogs-init.c:126) +10/22 10:44:16.250: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/nssf.log' (../lib/app/ogs-init.c:129) +10/22 10:44:16.252: [sbi] INFO: NF Service [nnssf-nsselection] (../lib/sbi/context.c:1401) +10/22 10:44:16.252: [sbi] INFO: nghttp2_server() [127.0.0.14]:7777 (../lib/sbi/nghttp2-server.c:150) +10/22 10:44:16.252: [app] INFO: NSSF initialize...done (../src/nssf/app.c:31) $ ./install/bin/open5gs-bsfd -Open5GS daemon v2.1.0 +Open5GS daemon v2.4.11-100-gbea24d7 -08/21 22:56:02.154: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/bsf.yaml' (../src/main.c:54) -08/21 22:56:02.154: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/bsf.log' (../src/main.c:57) -08/21 22:56:02.155: [app] INFO: BSF initialize...done (../src/bsf/app.c:31) -08/21 22:56:02.155: [sbi] INFO: sbi_server() [127.0.0.12]:7777 (../lib/sbi/server.c:298) +10/22 10:44:18.836: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/bsf.yaml' (../lib/app/ogs-init.c:126) +10/22 10:44:18.836: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/bsf.log' (../lib/app/ogs-init.c:129) +10/22 10:44:18.837: [sbi] INFO: NF Service [nbsf-management] (../lib/sbi/context.c:1401) +10/22 10:44:18.837: [sbi] INFO: nghttp2_server() [127.0.0.15]:7777 (../lib/sbi/nghttp2-server.c:150) +10/22 10:44:18.837: [app] INFO: BSF initialize...done (../src/bsf/app.c:31) $ ./install/bin/open5gs-udrd -Open5GS daemon v2.1.0 +Open5GS daemon v2.4.11-100-gbea24d7 -08/21 22:56:15.810: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/udr.yaml' (../src/main.c:54) -08/21 22:56:15.810: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/udr.log' (../src/main.c:57) -08/21 22:56:15.813: [dbi] INFO: MongoDB URI: 'mongodb://localhost/open5gs' (../lib/dbi/ogs-mongoc.c:99) -08/21 22:56:15.813: [app] INFO: UDR initialize...done (../src/udr/app.c:31) -08/21 22:56:15.813: [sbi] INFO: sbi_server() [127.0.0.13]:7777 (../lib/sbi/server.c:298) +10/22 10:44:24.018: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/udr.yaml' (../lib/app/ogs-init.c:126) +10/22 10:44:24.018: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/udr.log' (../lib/app/ogs-init.c:129) +10/22 10:44:24.021: [dbi] INFO: MongoDB URI: 'mongodb://localhost/open5gs' (../lib/dbi/ogs-mongoc.c:130) +10/22 10:44:24.021: [sbi] INFO: NF Service [nudr-dr] (../lib/sbi/context.c:1401) +10/22 10:44:24.021: [sbi] INFO: nghttp2_server() [127.0.0.20]:7777 (../lib/sbi/nghttp2-server.c:150) +10/22 10:44:24.021: [app] INFO: UDR initialize...done (../src/udr/app.c:31) + +$ ./install/bin/open5gs-mmed +Open5GS daemon v2.4.11-100-gbea24d7 + +10/22 10:44:26.011: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/mme.yaml' (../lib/app/ogs-init.c:126) +10/22 10:44:26.011: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/mme.log' (../lib/app/ogs-init.c:129) +10/22 10:44:26.062: [gtp] INFO: gtp_server() [127.0.0.2]:2123 (../lib/gtp/path.c:30) +10/22 10:44:26.063: [gtp] INFO: gtp_connect() [127.0.0.3]:2123 (../lib/gtp/path.c:60) +10/22 10:44:26.063: [mme] INFO: s1ap_server() [127.0.0.2]:36412 (../src/mme/s1ap-sctp.c:62) +10/22 10:44:26.063: [sctp] INFO: MME initialize...done (../src/mme/app-init.c:33) + +$ ./install/bin/open5gs-sgwcd +Open5GS daemon v2.4.11-100-gbea24d7 + +10/22 10:44:29.050: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/sgwc.yaml' (../lib/app/ogs-init.c:126) +10/22 10:44:29.050: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/sgwc.log' (../lib/app/ogs-init.c:129) +10/22 10:44:29.058: [gtp] INFO: gtp_server() [127.0.0.3]:2123 (../lib/gtp/path.c:30) +10/22 10:44:29.058: [pfcp] INFO: pfcp_server() [127.0.0.3]:8805 (../lib/pfcp/path.c:30) +10/22 10:44:29.058: [pfcp] INFO: ogs_pfcp_connect() [127.0.0.6]:8805 (../lib/pfcp/path.c:61) +10/22 10:44:29.058: [app] INFO: SGW-C initialize...done (../src/sgwc/app.c:31) + +$ ./install/bin/open5gs-sgwud +Open5GS daemon v2.4.11-100-gbea24d7 + +10/22 10:44:36.178: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/sgwu.yaml' (../lib/app/ogs-init.c:126) +10/22 10:44:36.178: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/sgwu.log' (../lib/app/ogs-init.c:129) +10/22 10:44:36.185: [pfcp] INFO: pfcp_server() [127.0.0.6]:8805 (../lib/pfcp/path.c:30) +10/22 10:44:36.185: [gtp] INFO: gtp_server() [127.0.0.6]:2152 (../lib/gtp/path.c:30) +10/22 10:44:36.185: [app] INFO: SGW-U initialize...done (../src/sgwu/app.c:31) + +$ ./install/bin/open5gs-hssd +Open5GS daemon v2.4.11-100-gbea24d7 + +10/22 10:49:22.963: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/hss.yaml' (../lib/app/ogs-init.c:126) +10/22 10:49:22.963: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/hss.log' (../lib/app/ogs-init.c:129) +10/22 10:49:22.965: [dbi] INFO: MongoDB URI: 'mongodb://localhost/open5gs' (../lib/dbi/ogs-mongoc.c:130) +10/22 10:49:22.996: [app] INFO: HSS initialize...done (../src/hss/app-init.c:31) +10/22 10:49:22.997: [diam] INFO: CONNECTED TO 'mme.localdomain' (SCTP,soc#15): (../lib/diameter/common/logger.c:108) + +$ ./install/bin/open5gs-pcrfd +Open5GS daemon v2.4.11-100-gbea24d7 + +10/22 10:49:26.089: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/pcrf.yaml' (../lib/app/ogs-init.c:126) +10/22 10:49:26.089: [app] INFO: File Logging: '/home/acetcom/Documents/git/open5gs/install/var/log/open5gs/pcrf.log' (../lib/app/ogs-init.c:129) +10/22 10:49:26.091: [dbi] INFO: MongoDB URI: 'mongodb://localhost/open5gs' (../lib/dbi/ogs-mongoc.c:130) +10/22 10:49:26.124: [app] INFO: PCRF initialize...done (../src/pcrf/app-init.c:31) +10/22 10:49:26.125: [diam] INFO: CONNECTED TO 'smf.localdomain' (SCTP,soc#15): (../lib/diameter/common/logger.c:108) ``` Several command line options are provided. @@ -382,7 +417,7 @@ $ ./build/tests/app/app ## Both 5G Core and EPC with ./build/configs/sample.yaml ```bash $ sudo apt install curl -$ curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash - +$ curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash - $ sudo apt install nodejs ``` @@ -390,7 +425,7 @@ Install the dependencies to run WebUI ```bash $ cd webui -$ npm ci --no-optional +$ npm ci ``` The WebUI runs as an [npm](https://www.npmjs.com/) script. @@ -547,32 +582,37 @@ You can use the command line option[`-d`] to record more logs. ```bash $ ./tests/app/app -d -Open5GS daemon v1.3.0-213-gd190548+ +Open5GS daemon v2.4.11-100-gbea24d7 -08/21 23:01:54.246: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/build/configs/sample.yaml' (../src/main.c:54) -08/21 23:01:54.246: [thread] DEBUG: [0x7f8de4d25018] worker signal (../lib/core/ogs-thread.c:66) -08/21 23:01:54.246: [thread] DEBUG: [0x7f8de4d25018] thread started (../lib/core/ogs-thread.c:101) -Open5GS daemon v1.3.0-213-gd190548+ - -08/21 23:01:54.254: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/build/configs/sample.yaml' (../src/main.c:54) -08/21 23:01:54.254: [thread] DEBUG: [0x7ff8d13be818] worker signal (../lib/core/ogs-thread.c:66) -08/21 23:01:54.254: [nrf] DEBUG: nrf_state_initial(): INIT (../src/nrf/nrf-sm.c:25) -08/21 23:01:54.254: [nrf] DEBUG: nrf_state_operational(): ENTRY (../src/nrf/nrf-sm.c:50) -08/21 23:01:54.254: [thread] DEBUG: [0x7ff8d13be818] thread started (../lib/core/ogs-thread.c:101) -08/21 23:01:54.254: [app] INFO: NRF initialize...done (../src/nrf/app.c:31) -08/21 23:01:54.255: [sbi] INFO: sbi_server() [127.0.0.10]:7777 (../lib/sbi/server.c:298) -08/21 23:01:54.255: [sbi] INFO: sbi_server() [::1]:7777 (../lib/sbi/server.c:298) -08/21 23:01:54.296: [thread] DEBUG: [0x7f8de4d25098] worker signal (../lib/core/ogs-thread.c:66) -08/21 23:01:54.296: [thread] DEBUG: [0x7f8de4d25098] thread started (../lib/core/ogs-thread.c:101) -Open5GS daemon v1.3.0-213-gd190548+ - -08/21 23:01:54.315: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/build/configs/sample.yaml' (../src/main.c:54) -08/21 23:01:54.319: [dbi] INFO: MongoDB URI: 'mongodb://localhost/open5gs' (../lib/dbi/ogs-mongoc.c:99) -08/21 23:01:54.332: [app] INFO: PCRF initialize...done (../src/pcrf/app-init.c:31) -08/21 23:01:54.347: [thread] DEBUG: [0x7f8de4d25118] worker signal (../lib/core/ogs-thread.c:66) -08/21 23:01:54.347: [thread] DEBUG: [0x7f8de4d25118] thread started (../lib/core/ogs-thread.c:101) -Open5GS daemon v1.3.0-213-gd190548+ +10/22 10:59:03.813: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/build/configs/sample.yaml' (../lib/app/ogs-init.c:126) +10/22 10:59:03.813: [thread] DEBUG: [0x55fab86aff40] worker signal (../lib/core/ogs-thread.c:66) +10/22 10:59:03.813: [thread] DEBUG: [0x55fab86aff40] thread started (../lib/core/ogs-thread.c:101) +Open5GS daemon v2.4.11-100-gbea24d7 +10/22 10:59:03.818: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/build/configs/sample.yaml' (../lib/app/ogs-init.c:126) +10/22 10:59:03.819: [sock] DEBUG: addr:127.0.0.10, port:7777 (../lib/core/ogs-sockaddr.c:140) +10/22 10:59:03.819: [sock] DEBUG: addr:::1, port:7777 (../lib/core/ogs-sockaddr.c:140) +10/22 10:59:03.819: [sock] DEBUG: addr:127.0.1.10, port:7777 (../lib/core/ogs-sockaddr.c:140) +10/22 10:59:03.819: [sock] DEBUG: socket create(2:1:6) (../lib/core/ogs-socket.c:92) +10/22 10:59:03.819: [sock] DEBUG: Turn on TCP_NODELAY (../lib/core/ogs-sockopt.c:139) +10/22 10:59:03.819: [sock] DEBUG: Turn on SO_REUSEADDR (../lib/core/ogs-sockopt.c:120) +10/22 10:59:03.819: [sock] DEBUG: socket bind 127.0.0.10:7777 (../lib/core/ogs-socket.c:117) +10/22 10:59:03.819: [sock] DEBUG: tcp_server() [127.0.0.10]:7777 (../lib/core/ogs-tcp.c:60) +10/22 10:59:03.819: [sbi] INFO: nghttp2_server() [127.0.0.10]:7777 (../lib/sbi/nghttp2-server.c:150) +10/22 10:59:03.819: [sock] DEBUG: socket create(10:1:6) (../lib/core/ogs-socket.c:92) +10/22 10:59:03.819: [sock] DEBUG: Turn on TCP_NODELAY (../lib/core/ogs-sockopt.c:139) +10/22 10:59:03.819: [sock] DEBUG: Turn on SO_REUSEADDR (../lib/core/ogs-sockopt.c:120) +10/22 10:59:03.819: [sock] DEBUG: socket bind ::1:7777 (../lib/core/ogs-socket.c:117) +10/22 10:59:03.819: [sock] DEBUG: tcp_server() [::1]:7777 (../lib/core/ogs-tcp.c:60) +10/22 10:59:03.819: [sbi] INFO: nghttp2_server() [::1]:7777 (../lib/sbi/nghttp2-server.c:150) +10/22 10:59:03.819: [thread] DEBUG: [0x5601b141e520] worker signal (../lib/core/ogs-thread.c:66) +10/22 10:59:03.819: [nrf] DEBUG: nrf_state_initial(): INIT (../src/nrf/nrf-sm.c:25) +10/22 10:59:03.819: [nrf] DEBUG: nrf_state_operational(): ENTRY (../src/nrf/nrf-sm.c:50) +10/22 10:59:03.819: [thread] DEBUG: [0x5601b141e520] thread started (../lib/core/ogs-thread.c:101) +10/22 10:59:03.819: [app] INFO: NRF initialize...done (../src/nrf/app.c:31) +10/22 10:59:03.864: [thread] DEBUG: [0x55fab86d2100] worker signal (../lib/core/ogs-thread.c:66) +10/22 10:59:03.864: [thread] DEBUG: [0x55fab86d2100] thread started (../lib/core/ogs-thread.c:101) +Open5GS daemon v2.4.11-100-gbea24d7 ... ``` diff --git a/docs/_docs/guide/03-splitting-network-functions.md b/docs/_docs/guide/03-splitting-network-functions.md index ddf855f03..51a0b333b 100644 --- a/docs/_docs/guide/03-splitting-network-functions.md +++ b/docs/_docs/guide/03-splitting-network-functions.md @@ -31,6 +31,7 @@ AMF-sbi = 127.0.0.5 :7777 for 5G SBI (N8,N12,N11) HSS-frDi = 127.0.0.8 :3868 for S6a auth PCRF-frDi = 127.0.0.9 :3868 for Gx auth NRF-sbi = 127.0.0.10:7777 for 5G SBI +SCP-sbi = 127.0.1.10:7777 for 5G SBI AUSF-sbi = 127.0.0.11:7777 for 5G SBI UDM-sbi = 127.0.0.12:7777 for 5G SBI PCF-sbi = 127.0.0.13:7777 for 5G SBI @@ -58,53 +59,52 @@ Modify [install/etc/open5gs/mme.yaml](https://github.com/{{ site.github_username $ diff -u /etc/open5gs/mme.yaml.old /etc/open5gs/mme.yaml --- mme.yaml.old 2020-08-22 11:36:40.512418765 -0400 +++ mme.yaml 2020-08-22 11:36:27.081466682 -0400 -@@ -204,20 +204,20 @@ - mme: - freeDiameter: /home/acetcom/Documents/git/open5gs/install/etc/freeDiameter/mme.conf +@@ -253,20 +253,20 @@ mme: s1ap: -- addr: 127.0.0.2 -+ addr: 10.10.0.2 + - addr: 127.0.0.2 gtpc: +- - addr: 127.0.0.2 ++ - addr: 10.10.0.2 + metrics: addr: 127.0.0.2 - gummei: + port: 9090 + gummei: plmn_id: -- mcc: 001 -- mnc: 01 -+ mcc: 999 -+ mnc: 70 +- mcc: 999 +- mnc: 70 ++ mcc: 001 ++ mnc: 01 mme_gid: 2 mme_code: 1 tai: plmn_id: -- mcc: 001 -- mnc: 01 -- tac: 7 -+ mcc: 999 -+ mnc: 70 -+ tac: 1 +- mcc: 999 +- mnc: 70 ++ mcc: 001 ++ mnc: 01 + tac: 1 security: - integrity_order : [ EIA1, EIA2, EIA0 ] - ciphering_order : [ EEA0, EEA1, EEA2 ] + integrity_order : [ EIA2, EIA1, EIA0 ] ``` Modify [install/etc/open5gs/sgwc.yaml](https://github.com/{{ site.github_username }}/open5gs/blob/main/configs/open5gs/sgwc.yaml.in) to set the PFCP IP address. ```diff $ diff -u /etc/open5gs/sgwc.yaml.old /etc/open5gs/sgwc.yaml -@@ -49,7 +49,7 @@ +@@ -69,7 +69,7 @@ sgwc: gtpc: - addr: 127.0.0.3 + - addr: 127.0.0.3 pfcp: -- addr: 127.0.0.3 -+ addr: 10.10.0.3 +- - addr: 127.0.0.3 ++ - addr: 10.10.0.3 # # sgwu: -@@ -100,7 +100,7 @@ +@@ -120,7 +120,7 @@ sgwc: # sgwu: pfcp: -- addr: 127.0.0.6 -+ addr: 10.10.0.6 +- - addr: 127.0.0.6 ++ - addr: 10.10.0.6 # # parameter: @@ -115,17 +115,16 @@ Modify [install/etc/open5gs/smf.yaml](https://github.com/{{ site.github_username $ diff -u /etc/open5gs/smf.yaml.old /etc/open5gs/smf.yaml --- smf.yaml.old 2020-08-22 11:37:39.990816411 -0400 +++ smf.yaml 2020-08-22 11:38:18.647999952 -0400 -@@ -187,8 +187,7 @@ +@@ -446,7 +446,7 @@ smf: - addr: 127.0.0.4 - - addr: ::1 + port: 7777 pfcp: - - addr: 127.0.0.4 -- - addr: ::1 + - addr: 10.10.0.4 - subnet: - - addr: 10.45.0.1/16 - - addr: 2001:db8:cafe::1/48 -@@ -282,7 +281,7 @@ + - addr: ::1 + gtpc: + - addr: 127.0.0.4 +@@ -613,7 +613,7 @@ scp: # upf: pfcp: @@ -134,7 +133,6 @@ $ diff -u /etc/open5gs/smf.yaml.old /etc/open5gs/smf.yaml # # parameter: - ``` Modify [install/etc/open5gs/amf.yaml](https://github.com/{{ site.github_username }}/open5gs/blob/main/configs/open5gs/amf.yaml.in) to set the NGAP IP address, PLMN ID, TAC and NSSAI. @@ -143,41 +141,40 @@ Modify [install/etc/open5gs/amf.yaml](https://github.com/{{ site.github_username diff -u /etc/open5gs/amf.yaml.old /etc/open5gs/amf.yaml --- amf.yaml.old 2020-06-21 23:34:14.643114779 -0400 +++ amf.yaml 2020-06-21 23:34:28.718482095 -0400 -@@ -67,25 +67,25 @@ +@@ -293,26 +293,26 @@ amf: - addr: 127.0.0.5 port: 7777 ngap: - - addr: 127.0.0.5 + - addr: 10.10.0.5 + metrics: + addr: 127.0.0.5 + port: 9090 guami: - plmn_id: -- mcc: 001 -- mnc: 01 -+ mcc: 999 -+ mnc: 70 +- mcc: 999 +- mnc: 70 ++ mcc: 001 ++ mnc: 01 amf_id: region: 2 set: 1 tai: - plmn_id: -- mcc: 001 -- mnc: 01 -- tac: 7 -+ mcc: 999 -+ mnc: 70 -+ tac: 1 +- mcc: 999 +- mnc: 70 ++ mcc: 001 ++ mnc: 01 + tac: 1 plmn_support: - plmn_id: -- mcc: 001 -- mnc: 01 -+ mcc: 999 -+ mnc: 70 +- mcc: 999 +- mnc: 70 ++ mcc: 001 ++ mnc: 01 s_nssai: - sst: 1 -- - sd: 2 security: - integrity_order : [ NIA1, NIA2, NIA0 ] - ciphering_order : [ NEA0, NEA1, NEA2 ] ``` Modify [install/etc/open5gs/sgwu.yaml](https://github.com/{{ site.github_username }}/open5gs/blob/main/configs/open5gs/sgwu.yaml.in) to set the GTP-U and PFCP IP address. @@ -185,18 +182,14 @@ Modify [install/etc/open5gs/sgwu.yaml](https://github.com/{{ site.github_usernam $ diff -u /etc/open5gs/sgwu.yaml.old /etc/open5gs/sgwu.yaml --- sgwu.yaml.old 2020-08-22 11:41:09.214670723 -0400 +++ sgwu.yaml 2020-08-22 11:41:27.433937124 -0400 -@@ -51,9 +51,9 @@ +@@ -98,7 +98,7 @@ logger: # sgwu: - gtpu: -- addr: 127.0.0.6 -+ addr: 10.11.0.6 pfcp: -- addr: 127.0.0.6 -+ addr: 10.10.0.6 - - # - # sgwc: +- - addr: 127.0.0.6 ++ - addr: 10.11.0.6 + gtpu: + - addr: 127.0.0.6 ``` Modify [install/etc/open5gs/upf.yaml](https://github.com/{{ site.github_username }}/open5gs/blob/main/configs/open5gs/upf.yaml.in) to set the GTP-U and PFCP IP address. @@ -204,16 +197,11 @@ Modify [install/etc/open5gs/upf.yaml](https://github.com/{{ site.github_username $ diff -u /etc/open5gs/upf.yaml.old /etc/open5gs/upf.yaml --- upf.yaml.old 2020-08-22 11:42:57.781750067 -0400 +++ upf.yaml 2020-08-22 11:43:13.268901616 -0400 -@@ -59,11 +59,9 @@ - # - upf: +@@ -168,7 +168,7 @@ upf: pfcp: -- - addr: 127.0.0.7 -+ - addr: 10.10.0.7 + - addr: 127.0.0.7 gtpu: -- - addr: -- - 127.0.0.7 -- - ::1 +- - addr: 127.0.0.7 + - addr: 10.11.0.7 subnet: - addr: 10.45.0.1/16 diff --git a/docs/_docs/platform/02-centos.md b/docs/_docs/platform/02-centos.md index e2c99be7d..42ea78eae 100644 --- a/docs/_docs/platform/02-centos.md +++ b/docs/_docs/platform/02-centos.md @@ -328,9 +328,10 @@ $ cd build $ ninja install $ cd ../ $ ls install/bin -open5gs-amfd open5gs-hssd open5gs-nrfd open5gs-sgwcd open5gs-smfd open5gs-udrd -open5gs-ausfd open5gs-mmed open5gs-pcrfd open5gs-sgwud open5gs-udmd open5gs-pcfd -open5gs-upfd open5gs-nssfd open5gs-bsfd +open5gs-amfd open5gs-mmed open5gs-pcrfd open5gs-smfd +open5gs-ausfd open5gs-nrfd open5gs-scpd open5gs-udmd +open5gs-bsfd open5gs-nssfd open5gs-sgwcd open5gs-udrd +open5gs-hssd open5gs-pcfd open5gs-sgwud open5gs-upfd ``` ## Building WebUI of Open5GS @@ -347,7 +348,7 @@ Install the dependencies to run WebUI ```bash $ cd ~/open5gs $ cd webui -$ npm ci --no-optional +$ npm ci ``` The WebUI runs as an [npm](https://www.npmjs.com/) script. diff --git a/docs/_docs/platform/03-fedora.md b/docs/_docs/platform/03-fedora.md index 2c9fdd269..526b159a4 100644 --- a/docs/_docs/platform/03-fedora.md +++ b/docs/_docs/platform/03-fedora.md @@ -127,7 +127,7 @@ Install the dependencies to run WebUI ```bash $ cd webui -$ npm ci --no-optional +$ npm ci ``` The WebUI runs as an [npm](https://www.npmjs.com/) script. diff --git a/docs/_docs/platform/05-macosx-apple-silicon.md b/docs/_docs/platform/05-macosx-apple-silicon.md index 504a6e436..77feadd06 100644 --- a/docs/_docs/platform/05-macosx-apple-silicon.md +++ b/docs/_docs/platform/05-macosx-apple-silicon.md @@ -164,7 +164,7 @@ Install the dependencies to run WebUI ```bash $ cd webui -$ npm ci --no-optional +$ npm ci ``` The WebUI runs as an [npm](https://www.npmjs.com/) script. diff --git a/docs/_docs/platform/06-macosx-intel.md b/docs/_docs/platform/06-macosx-intel.md index 6a7d0dafb..29b93d454 100644 --- a/docs/_docs/platform/06-macosx-intel.md +++ b/docs/_docs/platform/06-macosx-intel.md @@ -162,7 +162,7 @@ Install the dependencies to run WebUI ```bash $ cd webui -$ npm ci --no-optional +$ npm ci ``` The WebUI runs as an [npm](https://www.npmjs.com/) script. diff --git a/docs/_docs/platform/07-freebsd.md b/docs/_docs/platform/07-freebsd.md index ce73e2dc5..6a872c118 100644 --- a/docs/_docs/platform/07-freebsd.md +++ b/docs/_docs/platform/07-freebsd.md @@ -207,7 +207,7 @@ Install the dependencies to run WebUI ```bash $ cd webui -$ npm ci --no-optional +$ npm ci ``` The WebUI runs as an [npm](https://www.npmjs.com/) script. diff --git a/docs/_docs/platform/08-alpine.md b/docs/_docs/platform/08-alpine.md index 4f72f0e95..09b691ff5 100644 --- a/docs/_docs/platform/08-alpine.md +++ b/docs/_docs/platform/08-alpine.md @@ -105,7 +105,7 @@ Install the dependencies to run WebUI ```bash $ cd webui -$ npm ci --no-optional +$ npm ci ``` The WebUI runs as an [npm](https://www.npmjs.com/) script. diff --git a/docs/_docs/troubleshoot/01-simple-issues.md b/docs/_docs/troubleshoot/01-simple-issues.md index 6f20e8cc8..1936ca6f4 100644 --- a/docs/_docs/troubleshoot/01-simple-issues.md +++ b/docs/_docs/troubleshoot/01-simple-issues.md @@ -21,6 +21,7 @@ open5gs 26934 0.0 0.0 707472 12732 ? Ssl 12:13 0:00 /usr/bin/open5g open5gs 27244 0.2 0.0 2861424 13584 ? Ssl 12:13 0:00 /usr/bin/open5gs-hssd -c /etc/open5gs/hss.yaml open5gs 27366 0.0 0.0 2890772 14380 ? Ssl 12:13 0:00 /usr/bin/open5gs-pcrfd -c /etc/open5gs/pcrf.yaml open5gs 27485 0.0 0.0 243816 15064 ? Ssl 12:13 0:00 /usr/bin/open5gs-nrfd -c /etc/open5gs/nrf.yaml +open5gs 27485 0.0 0.0 243916 13064 ? Ssl 12:13 0:00 /usr/bin/open5gs-scpd -c /etc/open5gs/scp.yaml open5gs 27543 0.0 0.0 222416 9672 ? Ssl 12:13 0:00 /usr/bin/open5gs-ausfd -c /etc/open5gs/ausf.yaml open5gs 27600 0.0 0.0 222328 9668 ? Ssl 12:13 0:00 /usr/bin/open5gs-udmd -c /etc/open5gs/udm.yaml open5gs 27600 0.0 0.0 222329 9669 ? Ssl 12:13 0:00 /usr/bin/open5gs-pcfd -c /etc/open5gs/pcf.yaml @@ -29,7 +30,7 @@ open5gs 27600 0.0 0.0 222329 9669 ? Ssl 12:13 0:00 /usr/bin/open5g open5gs 27697 0.0 0.0 243976 13716 ? Ssl 12:13 0:00 /usr/bin/open5gs-udrd -c /etc/open5gs/udr.yaml ``` -You should see each of the above services, MME, SGW-C, SMF, AMF, SGW-U, UPF, HSS, PCRF, NRF, AUSF, UDM, PCF, NSSF, BSF & UDR are all running. +You should see each of the above services, MME, SGW-C, SMF, AMF, SGW-U, UPF, HSS, PCRF, NRF, SCP, AUSF, UDM, PCF, NSSF, BSF & UDR are all running. If your instance doesn't show this make sure you're started each service: ```bash @@ -42,6 +43,7 @@ $ systemctl start open5gs-upfd.service $ systemctl start open5gs-hssd.service $ systemctl start open5gs-pcrfd.service $ systemctl start open5gs-nrfd.service +$ systemctl start open5gs-scpd.service $ systemctl start open5gs-ausfd.service $ systemctl start open5gs-udmd.service $ systemctl start open5gs-pcfd.service @@ -55,14 +57,15 @@ $ systemctl start open5gs-udrd.service If a service isn't running check the log for that service - logs for each service live in */var/log/open5gs/* where each service logs to it's own file - MME logs in mme.log, AMF logs in amf.log, and so on. ```bash -$ cat /var/log/open5gs/mme.log -Open5GS daemon v1.0.0 +$ cat a.log +Open5GS daemon v2.4.11-100-gbea24d7 -[app] INFO: Configuration: '/etc/open5gs/mme.yaml' (../src/main.c:54) -[app] INFO: File Logging: '/var/log/open5gs/mme.log' (../src/main.c:57) -[mme] ERROR: No sgwc.gtpc in '/etc/open5gs/mme.yaml' (../src/mme/mme-context.c:192) -[app] ERROR: Failed to intialize MME (../src/mme/app-init.c:30) -[app] FATAL: Open5GS initialization failed. Aborted (../src/main.c:222) +10/22 11:05:40.032: [app] INFO: Configuration: '/home/acetcom/Documents/git/open5gs/install/etc/open5gs/mme.yaml' (../lib/app/ogs-init.c:126) +10/22 11:05:40.032: [app] INFO: File Logging: 'a.log' (../lib/app/ogs-init.c:129) +10/22 11:05:40.094: [gtp] INFO: gtp_server() [127.0.0.2]:2123 (../lib/gtp/path.c:30) +10/22 11:05:40.094: [gtp] INFO: gtp_connect() [127.0.0.3]:2123 (../lib/gtp/path.c:60) +10/22 11:05:40.094: [mme] INFO: s1ap_server() [127.0.0.2]:36412 (../src/mme/s1ap-sctp.c:62) +10/22 11:05:40.094: [sctp] INFO: MME initialize...done (../src/mme/app-init.c:33) ``` Or, you can use `journalctl` like below to view live log. @@ -181,11 +184,11 @@ $ diff -u /etc/open5gs/amf.yaml.old /etc/open5gs/amf.yaml @@ -20,6 +20,7 @@ # logger: - file: /home/acetcom/Documents/git/open5gs/install/var/log/open5gs/amf.log + file: @localstatedir@/log/open5gs/amf.log + level: debug + # # amf: - # ``` After changing conf files, please restart Open5GS daemons. diff --git a/docs/_docs/troubleshoot/02-now-in-github-issues.md b/docs/_docs/troubleshoot/02-now-in-github-issues.md index 5bf0af242..2a46fc66f 100644 --- a/docs/_docs/troubleshoot/02-now-in-github-issues.md +++ b/docs/_docs/troubleshoot/02-now-in-github-issues.md @@ -92,7 +92,7 @@ home/open5gs/install/lib/x86_64-linux-gnu/libfdcore.so.7(+0x67c3c) [0x7f3b715f9c At this time, you need to check the DB schema is in the form below by using the command the below. ``` -$ mongo +$ mongosh > use open5gs > db.subscribers.find().pretty() { @@ -159,7 +159,7 @@ $ mongo If you see below, you are using the old format DB schema. ``` -$ mongo +$ mongosh > use open5gs > db.subscribers.find().pretty() { @@ -207,7 +207,7 @@ If you are using old format DB schema, please perform the following step. 1. First of all, it is recommended to use the following command to remove all existing subscription DB. ``` -$ mongo +$ mongosh > use open5gs switched to db open5gs > db.subscribers.drop() @@ -221,7 +221,7 @@ $ curl -fsSL https://open5gs.org/open5gs/assets/webui/install | sudo -E bash - 4. Log in to the new WebUI and add new subscriber information using your web browser. 5. Make sure it is a new DB schema as below: ``` -$ mongo +$ mongosh > use open5gs > db.subscribers.find().pretty() { @@ -256,7 +256,7 @@ This is a test program bug and has not yet been resolved. To restart the test program, first remove all subscriber information using MongoDB Client ``` -$ mongo +$ mongosh > use open5gs switched to db open5gs > db.subscribers.find() ### Check the test subscriber @@ -276,6 +276,7 @@ $ sudo pkill -9 open5gs-upfd $ sudo pkill -9 open5gs-hssd $ sudo pkill -9 open5gs-pcrfd $ sudo pkill -9 open5gs-nrfd +$ sudo pkill -9 open5gs-scpd $ sudo pkill -9 open5gs-ausfd $ sudo pkill -9 open5gs-udmd $ sudo pkill -9 open5gs-pcfd @@ -312,7 +313,7 @@ $ diff --git a/configs/open5gs/amf.yaml.in b/configs/open5gs/amf.yaml.in index 7e939e81..dfe4456d 100644 --- a/configs/open5gs/amf.yaml.in +++ b/configs/open5gs/amf.yaml.in -@@ -199,6 +199,12 @@ amf: +@@ -315,6 +315,12 @@ amf: mnc: 70 s_nssai: - sst: 1 @@ -332,9 +333,9 @@ $ diff --git a/configs/open5gs/smf.yaml.in b/configs/open5gs/smf.yaml.in index d45aa60f..701ee533 100644 --- a/configs/open5gs/smf.yaml.in +++ b/configs/open5gs/smf.yaml.in -@@ -317,6 +317,11 @@ logger: - # - +@@ -442,6 +442,11 @@ logger: + # + smf: + info: + - s_nssai: @@ -351,7 +352,7 @@ $ diff --git a/configs/open5gs/smf.yaml.in b/configs/open5gs/smf.yaml.in index d45aa60f..949da220 100644 --- a/configs/open5gs/smf.yaml.in +++ b/configs/open5gs/smf.yaml.in -@@ -317,6 +317,12 @@ logger: +@@ -442,6 +442,12 @@ logger: # smf: @@ -370,7 +371,7 @@ $ diff --git a/configs/open5gs/nssf.yaml.in b/configs/open5gs/nssf.yaml.in index ecd4f7e2..04d9c4ba 100644 --- a/configs/open5gs/nssf.yaml.in +++ b/configs/open5gs/nssf.yaml.in -@@ -119,6 +119,11 @@ nssf: +@@ -201,6 +201,12 @@ nssf: port: 7777 s_nssai: sst: 1 @@ -379,9 +380,10 @@ index ecd4f7e2..04d9c4ba 100644 + s_nssai: + sst: 1 + sd: 000080 - ++ + # - # nrf: + # scp: ``` Then add a slice to MongoDB's subscriber info. @@ -409,6 +411,7 @@ And the process below is only used in 5G, so there is no need to run it. ```bash $ open5gs-nrfd +$ open5gs-scpd $ open5gs-amfd $ open5gs-ausfd $ open5gs-udmd @@ -503,9 +506,9 @@ Now, you need to modify the configuration file of Open5GS to adjust the UE IP Po $ diff -u smf.yaml smf.yaml.new --- smf.yaml 2020-09-17 09:31:16.547882093 -0400 +++ smf.yaml.new 2020-09-17 09:32:18.267726844 -0400 -@@ -190,7 +190,7 @@ - - addr: 127.0.0.4 - - addr: ::1 +@@ -458,7 +458,7 @@ smf: + addr: 127.0.0.4 + port: 9090 subnet: - - addr: 10.45.0.1/16 + - addr: 10.46.0.1/16 @@ -518,7 +521,7 @@ $ diff -u smf.yaml smf.yaml.new $ diff -u upf.yaml upf.yaml.new --- upf.yaml 2020-09-17 09:31:16.547882093 -0400 +++ upf.yaml.new 2020-09-17 09:32:25.199619989 -0400 -@@ -139,7 +139,7 @@ +@@ -170,7 +170,7 @@ upf: gtpu: - addr: 127.0.0.7 subnet: @@ -596,7 +599,7 @@ Please make sure that MongoDB server daemon is running. Then, remove all subscriber information using MongoDB Client ``` -$ mongo +$ mongosh > use open5gs switched to db open5gs > db.subscribers.find() ### Check the test subscriber @@ -616,6 +619,7 @@ $ sudo pkill -9 open5gs-upfd $ sudo pkill -9 open5gs-hssd $ sudo pkill -9 open5gs-pcrfd $ sudo pkill -9 open5gs-nrfd +$ sudo pkill -9 open5gs-scpd $ sudo pkill -9 open5gs-ausfd $ sudo pkill -9 open5gs-udmd $ sudo pkill -9 open5gs-pcfd @@ -998,7 +1002,7 @@ attach_test : -Line 134: Condition is false, but expected true Remove all subscriber information using MongoDB Client ``` -$ mongo +$ mongosh > db.subscribers.find() ### Check the test subscriber > db.subscribers.drop() ### Remove all subscriber > db.subscribers.find() ### Check that all subscribers are empty @@ -1077,6 +1081,7 @@ Currently, the number of UE is limited to `128*128`. * HSS : 127.0.0.8 * PCRF : 127.0.0.9 * NRF : 127.0.0.10 +* SCP : 127.0.1.10 * AUSF : 127.0.0.11 * UDM : 127.0.0.12 * PCF : 127.0.0.13 diff --git a/docs/_posts/2021-04-09-release-v2.2.6.md b/docs/_posts/2021-04-09-release-v2.2.6.md index 0b1f6ab1f..56fd1812d 100644 --- a/docs/_posts/2021-04-09-release-v2.2.6.md +++ b/docs/_posts/2021-04-09-release-v2.2.6.md @@ -52,7 +52,7 @@ true $ git checkout v2.1.7 $ cd webui $ rm -Rf ./node_modules -$ npm ci --no-optional +$ npm ci $ npm run dev ## You should log out @@ -60,7 +60,7 @@ $ npm run dev $ git checkout main $ cd webui $ rm -Rf ./node_modules -$ npm ci --no-optional +$ npm ci $ npm run dev ## You can log back in diff --git a/docs/_posts/2021-04-30-release-v2.2.7.md b/docs/_posts/2021-04-30-release-v2.2.7.md index 0849311d2..5c176df23 100644 --- a/docs/_posts/2021-04-30-release-v2.2.7.md +++ b/docs/_posts/2021-04-30-release-v2.2.7.md @@ -46,7 +46,7 @@ true $ git checkout v2.1.7 $ cd webui $ rm -Rf ./node_modules -$ npm ci --no-optional +$ npm ci $ npm run dev ## You should log out @@ -54,7 +54,7 @@ $ npm run dev $ git checkout main $ cd webui $ rm -Rf ./node_modules -$ npm ci --no-optional +$ npm ci $ npm run dev ## You can log back in diff --git a/docs/_posts/2021-05-09-release-v2.2.8.md b/docs/_posts/2021-05-09-release-v2.2.8.md index 5ee1a7f1b..eb5ac5732 100644 --- a/docs/_posts/2021-05-09-release-v2.2.8.md +++ b/docs/_posts/2021-05-09-release-v2.2.8.md @@ -42,7 +42,7 @@ true $ git checkout v2.1.7 $ cd webui $ rm -Rf ./node_modules -$ npm ci --no-optional +$ npm ci $ npm run dev ## You should log out @@ -50,7 +50,7 @@ $ npm run dev $ git checkout main $ cd webui $ rm -Rf ./node_modules -$ npm ci --no-optional +$ npm ci $ npm run dev ## You can log back in diff --git a/docs/_posts/2021-05-19-release-v2.2.9.md b/docs/_posts/2021-05-19-release-v2.2.9.md index b5bf4060b..c6a8fa122 100644 --- a/docs/_posts/2021-05-19-release-v2.2.9.md +++ b/docs/_posts/2021-05-19-release-v2.2.9.md @@ -36,7 +36,7 @@ true $ git checkout v2.1.7 $ cd webui $ rm -Rf ./node_modules -$ npm ci --no-optional +$ npm ci $ npm run dev ## You should log out @@ -44,7 +44,7 @@ $ npm run dev $ git checkout main $ cd webui $ rm -Rf ./node_modules -$ npm ci --no-optional +$ npm ci $ npm run dev ## You can log back in diff --git a/docs/assets/webui/install b/docs/assets/webui/install index 08b9d6275..e7508d6b9 100644 --- a/docs/assets/webui/install +++ b/docs/assets/webui/install @@ -240,7 +240,7 @@ if [[ $RC != 0 ]]; then fi print_status "Build the Open5GS WebUI..." -exec_cmd "cd ./${PACKAGE}-${VERSION}/webui && npm ci --no-optional && npm run build" +exec_cmd "cd ./${PACKAGE}-${VERSION}/webui && npm ci && npm run build" print_status "Install the Open5GS WebUI..." exec_cmd "mv ./${PACKAGE}-${VERSION}/webui /usr/lib/node_modules/${PACKAGE}" diff --git a/lib/proto/event.c b/lib/proto/event.c index ba8ad5074..4073d3c7d 100644 --- a/lib/proto/event.c +++ b/lib/proto/event.c @@ -37,7 +37,7 @@ void *ogs_event_size(int id, size_t size) ogs_event_t *ogs_event_new(int id) { - return ogs_event_size(id, sizeof(ogs_event_t)); + return ogs_event_size(id, OGS_EVENT_SIZE); } void ogs_event_free(void *e) diff --git a/lib/proto/event.h b/lib/proto/event.h index 51ed9ef4c..89624a9ad 100644 --- a/lib/proto/event.h +++ b/lib/proto/event.h @@ -70,6 +70,8 @@ typedef struct ogs_event_s { } dbi; } ogs_event_t; +#define OGS_EVENT_SIZE 256 + void *ogs_event_size(int id, size_t size); ogs_event_t *ogs_event_new(int id); void ogs_event_free(void *e); diff --git a/lib/sbi/client.c b/lib/sbi/client.c index e4a5290ca..8c45a097b 100644 --- a/lib/sbi/client.c +++ b/lib/sbi/client.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -47,6 +47,7 @@ typedef struct connection_s { bool memory_overflow; char *location; + char *producer_id; ogs_timer_t *timer; CURL *easy; @@ -66,8 +67,14 @@ static size_t header_cb(void *ptr, size_t size, size_t nmemb, void *data); static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp); static int multi_timer_cb(CURLM *multi, long timeout_ms, void *cbp); static void multi_timer_expired(void *data); -static void connection_timer_expired(void *data); + +static connection_t *connection_add( + ogs_sbi_client_t *client, ogs_sbi_client_cb_f client_cb, + ogs_sbi_request_t *request, void *data); +static void connection_remove(connection_t *conn); +static void connection_free(connection_t *conn); static void connection_remove_all(ogs_sbi_client_t *client); +static void connection_timer_expired(void *data); void ogs_sbi_client_init(int num_of_sockinfo_pool, int num_of_connection_pool) { @@ -280,8 +287,6 @@ static char *add_params_to_uri(CURL *easy, char *uri, ogs_hash_t *params) return uri; } -static void _connection_remove(connection_t *conn); - static connection_t *connection_add( ogs_sbi_client_t *client, ogs_sbi_client_cb_f client_cb, ogs_sbi_request_t *request, void *data) @@ -307,7 +312,7 @@ static connection_t *connection_add( conn->method = ogs_strdup(request->h.method); if (!conn->method) { ogs_error("conn->method is NULL"); - _connection_remove(conn); + connection_free(conn); return NULL; } @@ -316,7 +321,7 @@ static connection_t *connection_add( conn->headers = ogs_calloc(conn->num_of_header, sizeof(char *)); if (!conn->headers) { ogs_error("conn->headers is NULL"); - _connection_remove(conn); + connection_free(conn); return NULL; } for (hi = ogs_hash_first(request->http.headers), i = 0; @@ -327,7 +332,7 @@ static connection_t *connection_add( conn->headers[i] = ogs_msprintf("%s: %s", key, val); if (!conn->headers[i]) { ogs_error("conn->headers[i=%d] is NULL", i); - _connection_remove(conn); + connection_free(conn); return NULL; } conn->header_list = curl_slist_append( @@ -339,7 +344,7 @@ static connection_t *connection_add( ogs_app()->timer_mgr, connection_timer_expired, conn); if (!conn->timer) { ogs_error("conn->timer is NULL"); - _connection_remove(conn); + connection_free(conn); return NULL; } @@ -351,7 +356,7 @@ static connection_t *connection_add( conn->easy = curl_easy_init(); if (!conn->easy) { ogs_error("conn->easy is NULL"); - _connection_remove(conn); + connection_free(conn); return NULL; } @@ -360,7 +365,7 @@ static connection_t *connection_add( request->h.uri, request->http.params); if (!uri) { ogs_error("add_params_to_uri() failed"); - _connection_remove(conn); + connection_free(conn); return NULL; } @@ -380,7 +385,7 @@ static connection_t *connection_add( request->http.content, request->http.content_length); if (!conn->content) { ogs_error("conn->content is NULL"); - _connection_remove(conn); + connection_free(conn); return NULL; } curl_easy_setopt(conn->easy, @@ -424,7 +429,23 @@ static connection_t *connection_add( return conn; } -static void _connection_remove(connection_t *conn) +static void connection_remove(connection_t *conn) +{ + ogs_sbi_client_t *client = NULL; + + ogs_assert(conn); + client = conn->client; + ogs_assert(client); + + ogs_list_remove(&client->connection_list, conn); + + ogs_assert(client->multi); + curl_multi_remove_handle(client->multi, conn->easy); + + connection_free(conn); +} + +static void connection_free(connection_t *conn) { int i; @@ -435,6 +456,8 @@ static void _connection_remove(connection_t *conn) if (conn->location) ogs_free(conn->location); + if (conn->producer_id) + ogs_free(conn->producer_id); if (conn->memory) ogs_free(conn->memory); @@ -459,22 +482,6 @@ static void _connection_remove(connection_t *conn) ogs_pool_free(&connection_pool, conn); } -static void connection_remove(connection_t *conn) -{ - ogs_sbi_client_t *client = NULL; - - ogs_assert(conn); - client = conn->client; - ogs_assert(client); - - ogs_list_remove(&client->connection_list, conn); - - ogs_assert(client->multi); - curl_multi_remove_handle(client->multi, conn->easy); - - _connection_remove(conn); -} - static void connection_remove_all(ogs_sbi_client_t *client) { connection_t *conn = NULL, *next_conn = NULL; @@ -555,6 +562,9 @@ static void check_multi_info(ogs_sbi_client_t *client) if (conn->location) ogs_sbi_header_set(response->http.headers, OGS_SBI_LOCATION, conn->location); + if (conn->producer_id) + ogs_sbi_header_set(response->http.headers, + OGS_SBI_CUSTOM_PRODUCER_ID, conn->producer_id); if (conn->memory_overflow == true) level = OGS_LOG_ERROR; @@ -585,8 +595,11 @@ static void check_multi_info(ogs_sbi_client_t *client) ogs_warn("[%d] %s", res, conn->error); ogs_assert(conn->client_cb); - conn->client_cb(res == CURLE_OK ? OGS_OK : OGS_ERROR, - response, conn->data); + if (res == CURLE_OK) + conn->client_cb(OGS_OK, response, conn->data); + else + conn->client_cb(OGS_ERROR, NULL, conn->data); + connection_remove(conn); break; default: @@ -596,7 +609,7 @@ static void check_multi_info(ogs_sbi_client_t *client) } } -bool ogs_sbi_client_send_reqmem_persistent( +bool ogs_sbi_client_send_request( ogs_sbi_client_t *client, ogs_sbi_client_cb_f client_cb, ogs_sbi_request_t *request, void *data) { @@ -604,10 +617,10 @@ bool ogs_sbi_client_send_reqmem_persistent( ogs_assert(client); ogs_assert(request); - if (request->h.uri == NULL) { request->h.uri = ogs_sbi_client_uri(client, &request->h); - ogs_expect_or_return_val(request->h.uri, false); + ogs_assert(request->h.method); + ogs_assert(request->h.uri); } ogs_debug("[%s] %s", request->h.method, request->h.uri); @@ -617,67 +630,14 @@ bool ogs_sbi_client_send_reqmem_persistent( return true; } -bool ogs_sbi_client_send_request( +bool ogs_sbi_client_send_via_scp( ogs_sbi_client_t *client, ogs_sbi_client_cb_f client_cb, ogs_sbi_request_t *request, void *data) { - bool rc; - - ogs_assert(client); ogs_assert(request); - - rc = ogs_sbi_client_send_reqmem_persistent( - client, client_cb, request, data); - ogs_expect(rc == true); - - ogs_sbi_request_free(request); - - return rc; -} - -bool ogs_sbi_scp_send_reqmem_persistent( - ogs_sbi_client_t *client, ogs_sbi_client_cb_f client_cb, - ogs_sbi_request_t *request, void *data) -{ - ogs_sbi_nf_instance_t *scp_instance = NULL; - connection_t *conn = NULL; - char *apiroot = NULL; - ogs_assert(client); - ogs_assert(request); - scp_instance = ogs_sbi_self()->scp_instance; - - if (scp_instance) { - /* - * In case of indirect communication using SCP, - * add 3gpp-Sbi-Target-apiRoot to HTTP header and - * change CLIENT instance to SCP. - */ - apiroot = ogs_sbi_client_apiroot(client); - ogs_assert(apiroot); - - ogs_sbi_header_set(request->http.headers, - OGS_SBI_CUSTOM_TARGET_APIROOT, apiroot); - - ogs_free(apiroot); - - client = scp_instance->client; - ogs_assert(client); - } - - if (request->h.uri == NULL) { - /* - * Regardless of direct or indirect communication, - * if there is no URI, we automatically creates a URI - * with Client Address and request->h - */ - request->h.uri = ogs_sbi_client_uri(client, &request->h); - ogs_assert(request->h.uri); - - ogs_debug("[%s] %s", request->h.method, request->h.uri); - - } else if (scp_instance) { + if (request->h.uri) { /* * In case of indirect communication using SCP, * If the full URI is already defined, change full URI to SCP as below. @@ -685,6 +645,7 @@ bool ogs_sbi_scp_send_reqmem_persistent( * OLD: http://127.0.0.5:7777/nnrf-nfm/v1/nf-status-notify * NEW: https://scp.open5gs.org/nnrf-nfm/v1/nf-status-notify */ + char *apiroot = NULL; char *path = NULL; char *old = NULL; @@ -697,38 +658,21 @@ bool ogs_sbi_scp_send_reqmem_persistent( ogs_assert(path); request->h.uri = ogs_msprintf("%s/%s", apiroot, path); + ogs_assert(request->h.method); ogs_assert(request->h.uri); + ogs_debug("[%s] %s", request->h.method, request->h.uri); ogs_free(apiroot); ogs_free(path); ogs_free(old); - - ogs_debug("[%s] %s", request->h.method, request->h.uri); } - conn = connection_add(client, client_cb, request, data); - ogs_expect_or_return_val(conn, false); + ogs_expect_or_return_val(true == + ogs_sbi_client_send_request(client, client_cb, request, data), false); return true; } -bool ogs_sbi_scp_send_request( - ogs_sbi_client_t *client, ogs_sbi_client_cb_f client_cb, - ogs_sbi_request_t *request, void *data) -{ - bool rc; - - ogs_assert(client); - ogs_assert(request); - - rc = ogs_sbi_scp_send_reqmem_persistent(client, client_cb, request, data); - ogs_expect(rc == true); - - ogs_sbi_request_free(request); - - return rc; -} - static size_t write_cb(void *contents, size_t size, size_t nmemb, void *data) { size_t realsize = 0; @@ -766,16 +710,32 @@ static size_t header_cb(void *ptr, size_t size, size_t nmemb, void *data) ogs_assert(conn); if (ogs_strncasecmp(ptr, OGS_SBI_LOCATION, strlen(OGS_SBI_LOCATION)) == 0) { - /* ptr : "Location: http://xxx/xxx/xxx\r\n" - We need to truncate "Location" + ": " + "\r\n" in 'ptr' string */ + /* ptr : "Location: http://xxx/xxx/xxx\r\n" + We need to truncate "Location" + ": " + "\r\n" in 'ptr' string */ int len = strlen(ptr) - strlen(OGS_SBI_LOCATION) - 2 - 2; if (len) { /* Only copy http://xxx/xxx/xxx" from 'ptr' string */ conn->location = ogs_memdup( - (char *)ptr + strlen(OGS_SBI_LOCATION) + 2, len+1); + (char *)ptr + strlen(OGS_SBI_LOCATION) + 2, + len+1); ogs_assert(conn->location); conn->location[len] = 0; } + } else if (ogs_strncasecmp(ptr, + OGS_SBI_CUSTOM_PRODUCER_ID, + strlen(OGS_SBI_CUSTOM_PRODUCER_ID)) == 0) { + /* ptr : "3gpp-Sbi-Producer-Id: 0cb58eca-4e84-41ed-aa10-9f892634b770\r\n" + We need to truncate "3gpp-Sbi-Producer-Id" + ": " + "\r\n" + in 'ptr' string */ + int len = strlen(ptr) - strlen(OGS_SBI_CUSTOM_PRODUCER_ID) - 2 - 2; + if (len) { + /* Only copy 0cb58eca-4e84-41ed-aa10-9f892634b770from 'ptr' string */ + conn->producer_id = ogs_memdup( + (char *)ptr + strlen(OGS_SBI_CUSTOM_PRODUCER_ID) + 2, + len+1); + ogs_assert(conn->producer_id); + conn->producer_id[len] = 0; + } } return (nmemb*size); diff --git a/lib/sbi/client.h b/lib/sbi/client.h index 3a450efe4..a49da977c 100644 --- a/lib/sbi/client.h +++ b/lib/sbi/client.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -62,8 +62,6 @@ typedef struct ogs_sbi_client_s { const char *pem; } tls; - ogs_sbi_client_cb_f cb; /* Only used when NF send to NRF */ - ogs_timer_t *t_curl; /* timer for CURL */ ogs_list_t connection_list; /* CURL connection list */ @@ -86,17 +84,10 @@ ogs_sbi_client_t *ogs_sbi_client_find(ogs_sockaddr_t *addr); void ogs_sbi_client_stop(ogs_sbi_client_t *client); void ogs_sbi_client_stop_all(void); -bool ogs_sbi_client_send_reqmem_persistent( - ogs_sbi_client_t *client, ogs_sbi_client_cb_f client_cb, - ogs_sbi_request_t *request, void *data); bool ogs_sbi_client_send_request( ogs_sbi_client_t *client, ogs_sbi_client_cb_f client_cb, ogs_sbi_request_t *request, void *data); - -bool ogs_sbi_scp_send_reqmem_persistent( - ogs_sbi_client_t *client, ogs_sbi_client_cb_f client_cb, - ogs_sbi_request_t *request, void *data); -bool ogs_sbi_scp_send_request( +bool ogs_sbi_client_send_via_scp( ogs_sbi_client_t *client, ogs_sbi_client_cb_f client_cb, ogs_sbi_request_t *request, void *data); diff --git a/lib/sbi/context.c b/lib/sbi/context.c index 1b06487f7..6213c01a7 100644 --- a/lib/sbi/context.c +++ b/lib/sbi/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. * @@ -58,15 +58,24 @@ void ogs_sbi_context_init(void) ogs_pool_init(&nf_info_pool, ogs_app()->pool.nf * OGS_MAX_NUM_OF_NF_INFO); - /* Add SELF NF instance */ + /* Add AELF NF-Instance */ self.nf_instance = ogs_sbi_nf_instance_add(); ogs_assert(self.nf_instance); ogs_uuid_get(&self.uuid); ogs_uuid_format(nf_instance_id, &self.uuid); - ogs_sbi_nf_instance_set_id(self.nf_instance, nf_instance_id); + /* Add NRF NF-Instance */ + self.nrf_instance = ogs_sbi_nf_instance_add(); + ogs_assert(self.nrf_instance); + ogs_sbi_nf_instance_set_type(self.nrf_instance, OpenAPI_nf_type_NRF); + + /* Add SCP NF-Instance */ + self.scp_instance = ogs_sbi_nf_instance_add(); + ogs_assert(self.scp_instance); + ogs_sbi_nf_instance_set_type(self.scp_instance, OpenAPI_nf_type_SCP); + context_initialized = 1; } @@ -123,25 +132,31 @@ static int ogs_sbi_context_validation( ogs_assert(context_initialized == 1); switch (self.discovery_config.delegated) { case OGS_SBI_DISCOVERY_DELEGATED_AUTO: - if (strcmp(local, "nrf") != 0 && /* Skip NRF */ - strcmp(local, "scp") != 0 && /* Skip SCP */ - strcmp(local, "smf") != 0 && /* Skip SMF since SMF can run 4G */ - ogs_sbi_self()->nrf_instance == NULL && - ogs_sbi_self()->scp_instance == NULL) { - ogs_error("DELEGATED_AUTO - Both NRF and %s are unavailable", - strcmp(scp, "next_scp") == 0 ? "Next-hop SCP" : "SCP"); - return OGS_ERROR; + if (strcmp(local, "nrf") == 0) { + /* Skip NRF */ + } else if (strcmp(local, "scp") == 0) { + /* Skip SCP */ + } else if (strcmp(local, "smf") == 0) { + /* Skip SMF since SMF can run 4G */ + } else { + if (NF_INSTANCE_CLIENT(self.nrf_instance) || + NF_INSTANCE_CLIENT(self.scp_instance)) { + } else { + ogs_error("DELEGATED_AUTO - Both NRF and %s are unavailable", + strcmp(scp, "next_scp") == 0 ? "Next-hop SCP" : "SCP"); + return OGS_ERROR; + } } break; case OGS_SBI_DISCOVERY_DELEGATED_YES: - if (ogs_sbi_self()->scp_instance == NULL) { + if (NF_INSTANCE_CLIENT(self.scp_instance) == NULL) { ogs_error("DELEGATED_YES - no %s available", strcmp(scp, "next_scp") == 0 ? "Next-hop SCP" : "SCP"); return OGS_ERROR; } break; case OGS_SBI_DISCOVERY_DELEGATED_NO: - if (ogs_sbi_self()->nrf_instance == NULL) { + if (NF_INSTANCE_CLIENT(self.nrf_instance) == NULL) { ogs_error("DELEGATED_NO - no NRF available"); return OGS_ERROR; } @@ -155,11 +170,6 @@ static int ogs_sbi_context_validation( return OGS_OK; } -ogs_sbi_nf_instance_t *ogs_sbi_scp_instance(void) -{ - return NULL; -} - int ogs_sbi_context_parse_config( const char *local, const char *nrf, const char *scp) { @@ -479,7 +489,6 @@ int ogs_sbi_context_parse_config( ogs_yaml_iter_t sbi_array, sbi_iter; ogs_yaml_iter_recurse(&nrf_iter, &sbi_array); do { - ogs_sbi_nf_instance_t *nrf_instance = NULL; ogs_sbi_client_t *client = NULL; ogs_sockaddr_t *addr = NULL; int family = AF_UNSPEC; @@ -581,14 +590,7 @@ int ogs_sbi_context_parse_config( client = ogs_sbi_client_add(addr); ogs_assert(client); - - ogs_sbi_self()->nrf_instance = - nrf_instance = ogs_sbi_nf_instance_add(); - ogs_assert(nrf_instance); - ogs_sbi_nf_instance_set_type( - nrf_instance, OpenAPI_nf_type_NRF); - - OGS_SBI_SETUP_CLIENT(nrf_instance, client); + OGS_SBI_SETUP_CLIENT(self.nrf_instance, client); if (key) client->tls.key = key; if (pem) client->tls.pem = pem; @@ -599,7 +601,8 @@ int ogs_sbi_context_parse_config( YAML_SEQUENCE_NODE); } } - } else if (scp && !strcmp(root_key, scp)) { + } else if (ogs_app()->parameter.no_scp == false && + scp && !strcmp(root_key, scp)) { ogs_yaml_iter_t scp_iter; ogs_yaml_iter_recurse(&root_iter, &scp_iter); while (ogs_yaml_iter_next(&scp_iter)) { @@ -609,7 +612,6 @@ int ogs_sbi_context_parse_config( ogs_yaml_iter_t sbi_array, sbi_iter; ogs_yaml_iter_recurse(&scp_iter, &sbi_array); do { - ogs_sbi_nf_instance_t *scp_instance = NULL; ogs_sbi_client_t *client = NULL; ogs_sockaddr_t *addr = NULL; int family = AF_UNSPEC; @@ -711,14 +713,7 @@ int ogs_sbi_context_parse_config( client = ogs_sbi_client_add(addr); ogs_assert(client); - - ogs_sbi_self()->scp_instance = - scp_instance = ogs_sbi_nf_instance_add(); - ogs_assert(scp_instance); - ogs_sbi_nf_instance_set_type( - scp_instance, OpenAPI_nf_type_SCP); - - OGS_SBI_SETUP_CLIENT(scp_instance, client); + OGS_SBI_SETUP_CLIENT(self.scp_instance, client); if (key) client->tls.key = key; if (pem) client->tls.pem = pem; @@ -923,15 +918,18 @@ ogs_sbi_nf_instance_t *ogs_sbi_nf_instance_find(char *id) ogs_sbi_nf_instance_t *ogs_sbi_nf_instance_find_by_discovery_param( OpenAPI_nf_type_e target_nf_type, + OpenAPI_nf_type_e requester_nf_type, ogs_sbi_discovery_option_t *discovery_option) { ogs_sbi_nf_instance_t *nf_instance = NULL; ogs_assert(target_nf_type); + ogs_assert(requester_nf_type); ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) { if (ogs_sbi_discovery_param_is_matched( - nf_instance, target_nf_type, discovery_option) == false) + nf_instance, target_nf_type, requester_nf_type, + discovery_option) == false) continue; return nf_instance; @@ -941,7 +939,8 @@ ogs_sbi_nf_instance_t *ogs_sbi_nf_instance_find_by_discovery_param( } ogs_sbi_nf_instance_t *ogs_sbi_nf_instance_find_by_service_type( - ogs_sbi_service_type_e service_type) + ogs_sbi_service_type_e service_type, + OpenAPI_nf_type_e requester_nf_type) { ogs_sbi_nf_instance_t *nf_instance = NULL; ogs_sbi_discovery_option_t *discovery_option = NULL; @@ -949,6 +948,7 @@ ogs_sbi_nf_instance_t *ogs_sbi_nf_instance_find_by_service_type( OpenAPI_nf_type_e target_nf_type = OpenAPI_nf_type_NULL; char *service_name = NULL; + ogs_assert(requester_nf_type); ogs_assert(service_type); target_nf_type = ogs_sbi_service_type_to_nf_type(service_type); ogs_assert(target_nf_type); @@ -960,7 +960,7 @@ ogs_sbi_nf_instance_t *ogs_sbi_nf_instance_find_by_service_type( ogs_sbi_discovery_option_add_service_names(discovery_option, service_name); nf_instance = ogs_sbi_nf_instance_find_by_discovery_param( - target_nf_type, discovery_option); + target_nf_type, requester_nf_type, discovery_option); ogs_sbi_discovery_option_free(discovery_option); @@ -1537,14 +1537,11 @@ bool ogs_sbi_discovery_option_is_matched( bool ogs_sbi_discovery_param_is_matched( ogs_sbi_nf_instance_t *nf_instance, OpenAPI_nf_type_e target_nf_type, + OpenAPI_nf_type_e requester_nf_type, ogs_sbi_discovery_option_t *discovery_option) { - OpenAPI_nf_type_e requester_nf_type = OpenAPI_nf_type_NULL; - ogs_assert(nf_instance); ogs_assert(target_nf_type); - ogs_assert(ogs_sbi_self()->nf_instance); - requester_nf_type = ogs_sbi_self()->nf_instance->nf_type; ogs_assert(requester_nf_type); if (!OGS_FSM_CHECK(&nf_instance->sm, ogs_sbi_nf_state_registered)) @@ -1601,7 +1598,24 @@ ogs_sbi_client_t *ogs_sbi_client_find_by_service_name( } } - ogs_error("[Fallback] Cannot find NF service[%s:%s]", name, version); + return nf_instance->client; +} + +ogs_sbi_client_t *ogs_sbi_client_find_by_service_type( + ogs_sbi_nf_instance_t *nf_instance, + ogs_sbi_service_type_e service_type) +{ + ogs_sbi_nf_service_t *nf_service = NULL; + + ogs_assert(nf_instance); + ogs_assert(service_type); + + ogs_list_for_each(&nf_instance->nf_service_list, nf_service) { + ogs_assert(nf_service->name); + if (ogs_sbi_service_type_from_name(nf_service->name) == service_type) + return nf_service->client; + } + return nf_instance->client; } @@ -1644,8 +1658,15 @@ ogs_sbi_xact_t *ogs_sbi_xact_add( xact->sbi_object = sbi_object; xact->service_type = service_type; + xact->requester_nf_type = NF_INSTANCE_TYPE(ogs_sbi_self()->nf_instance); + ogs_assert(xact->requester_nf_type); - /* Always insert one service-name in the discovery option */ + /* + * Insert one service-name in the discovery option in the function below. + * + * - ogs_sbi_xact_add() + * - ogs_sbi_send_notification_request() + */ if (!discovery_option) { discovery_option = ogs_sbi_discovery_option_new(); ogs_assert(discovery_option); @@ -1662,7 +1683,11 @@ ogs_sbi_xact_t *ogs_sbi_xact_add( ogs_app()->timer_mgr, ogs_timer_sbi_client_wait_expire, xact); if (!xact->t_response) { ogs_error("ogs_timer_add() failed"); + + if (xact->discovery_option) + ogs_sbi_discovery_option_free(xact->discovery_option); ogs_pool_free(&xact_pool, xact); + return NULL; } @@ -1673,8 +1698,13 @@ ogs_sbi_xact_t *ogs_sbi_xact_add( xact->request = (*build)(context, data); if (!xact->request) { ogs_error("SBI build failed"); + + if (xact->discovery_option) + ogs_sbi_discovery_option_free(xact->discovery_option); + ogs_timer_delete(xact->t_response); ogs_pool_free(&xact_pool, xact); + return NULL; } if (!xact->request->h.uri) { @@ -1849,33 +1879,18 @@ void ogs_sbi_subscription_data_build_default( OpenAPI_nf_type_e nf_type, const char *service_name) { ogs_sbi_subscription_data_t *subscription_data = NULL; - ogs_sbi_nf_instance_t *nf_instance = NULL, *nrf_instance = NULL; - ogs_sbi_client_t *client = NULL; ogs_assert(nf_type); - nrf_instance = ogs_sbi_self()->nrf_instance; - if (!nrf_instance) { - ogs_warn("[%s:%s] has no NRF", - OpenAPI_nf_type_ToString(nf_type), service_name); - return; - } - - client = nrf_instance->client; - ogs_assert(client); - - nf_instance = ogs_sbi_self()->nf_instance; - ogs_assert(nf_instance); - ogs_assert(nf_instance->id); - ogs_assert(nf_instance->nf_type); - subscription_data = ogs_sbi_subscription_data_add(); ogs_assert(subscription_data); - OGS_SBI_SETUP_CLIENT(subscription_data, client); - subscription_data->req_nf_type = nf_instance->nf_type; - if (nf_instance->id) - subscription_data->req_nf_instance_id = ogs_strdup(nf_instance->id); + subscription_data->req_nf_type = + NF_INSTANCE_TYPE(ogs_sbi_self()->nf_instance); + ogs_assert(subscription_data->req_nf_type); + if (NF_INSTANCE_ID(ogs_sbi_self()->nf_instance)) + subscription_data->req_nf_instance_id = + ogs_strdup(NF_INSTANCE_ID(ogs_sbi_self()->nf_instance)); subscription_data->subscr_cond.nf_type = nf_type; if (service_name) subscription_data->subscr_cond.service_name = ogs_strdup(service_name); diff --git a/lib/sbi/context.h b/lib/sbi/context.h index b1a5b4eb1..24a48991d 100644 --- a/lib/sbi/context.h +++ b/lib/sbi/context.h @@ -123,6 +123,8 @@ typedef struct ogs_sbi_nf_instance_s { ogs_list_t nf_service_list; ogs_list_t nf_info_list; +#define NF_INSTANCE_CLIENT(__nFInstance) \ + ((__nFInstance) ? ((__nFInstance)->client) : NULL) void *client; /* only used in CLIENT */ unsigned int reference_count; /* reference count for memory free */ } ogs_sbi_nf_instance_t; @@ -157,6 +159,7 @@ typedef struct ogs_sbi_xact_s { ogs_lnode_t lnode; ogs_sbi_service_type_e service_type; + OpenAPI_nf_type_e requester_nf_type; ogs_sbi_discovery_option_t *discovery_option; ogs_sbi_request_t *request; @@ -222,7 +225,7 @@ typedef struct ogs_sbi_subscription_data_s { struct { OpenAPI_nf_type_e nf_type; /* nfType */ - char *service_name; /* ServiceName */ + char *service_name; /* ServiceName */ } subscr_cond; uint64_t requester_features; @@ -299,8 +302,6 @@ int ogs_sbi_context_parse_config( bool ogs_sbi_nf_service_is_available(const char *name); -ogs_sbi_nf_instance_t *ogs_sbi_scp_instance(void); - ogs_sbi_nf_instance_t *ogs_sbi_nf_instance_add(void); void ogs_sbi_nf_instance_set_id(ogs_sbi_nf_instance_t *nf_instance, char *id); void ogs_sbi_nf_instance_set_type( @@ -317,9 +318,11 @@ void ogs_sbi_nf_instance_remove_all(void); ogs_sbi_nf_instance_t *ogs_sbi_nf_instance_find(char *id); ogs_sbi_nf_instance_t *ogs_sbi_nf_instance_find_by_discovery_param( OpenAPI_nf_type_e nf_type, + OpenAPI_nf_type_e requester_nf_type, ogs_sbi_discovery_option_t *discovery_option); ogs_sbi_nf_instance_t *ogs_sbi_nf_instance_find_by_service_type( - ogs_sbi_service_type_e service_type); + ogs_sbi_service_type_e service_type, + OpenAPI_nf_type_e requester_nf_type); bool ogs_sbi_nf_instance_maximum_number_is_reached(void); ogs_sbi_nf_service_t *ogs_sbi_nf_service_add( @@ -354,6 +357,9 @@ 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); +ogs_sbi_client_t *ogs_sbi_client_find_by_service_type( + ogs_sbi_nf_instance_t *nf_instance, + ogs_sbi_service_type_e service_type); void ogs_sbi_client_associate(ogs_sbi_nf_instance_t *nf_instance); @@ -375,6 +381,7 @@ OpenAPI_uri_scheme_e ogs_sbi_default_uri_scheme(void); bool ogs_sbi_discovery_param_is_matched( ogs_sbi_nf_instance_t *nf_instance, OpenAPI_nf_type_e target_nf_type, + OpenAPI_nf_type_e requester_nf_type, ogs_sbi_discovery_option_t *discovery_option); bool ogs_sbi_discovery_option_is_matched( diff --git a/lib/sbi/meson.build b/lib/sbi/meson.build index 9da256055..3b160dab2 100644 --- a/lib/sbi/meson.build +++ b/lib/sbi/meson.build @@ -41,6 +41,7 @@ libsbi_sources = files(''' nnrf-build.c nnrf-handler.c + nnrf-path.c path.c nf-sm.c diff --git a/lib/sbi/message.c b/lib/sbi/message.c index ca926096d..90ae995fd 100644 --- a/lib/sbi/message.c +++ b/lib/sbi/message.c @@ -253,6 +253,7 @@ ogs_sbi_request_t *ogs_sbi_build_request(ogs_sbi_message_t *message) { int i; ogs_sbi_request_t *request = NULL; + OpenAPI_nf_type_e nf_type = OpenAPI_nf_type_NULL; char sender_timestamp[OGS_SBI_RFC7231_DATE_LEN]; char *max_rsp_time = NULL; @@ -313,21 +314,17 @@ ogs_sbi_request_t *ogs_sbi_build_request(ogs_sbi_message_t *message) discovery_option->num_of_service_names) { /* send array items separated by a comma */ - char *v = NULL; - - v = ogs_strdup(discovery_option->service_names[0]); - ogs_expect_or_return_val(v, NULL); - - if (discovery_option->num_of_service_names > 1) - { - int i; - for (i = 1; i < discovery_option->num_of_service_names; i++) - v = ogs_mstrcatf(v, ",%s", discovery_option->service_names[i]); + char *v = ogs_sbi_discovery_option_build_service_names( + discovery_option); + if (v) { + ogs_sbi_header_set(request->http.params, + OGS_SBI_PARAM_SERVICE_NAMES, v); + ogs_free(v); + } else { + ogs_warn("invalid service names failed[%d:%s]", + discovery_option->num_of_service_names, + discovery_option->service_names[0]); } - - ogs_sbi_header_set( - request->http.params, OGS_SBI_PARAM_SERVICE_NAMES, v); - ogs_free(v); } } @@ -449,6 +446,14 @@ ogs_sbi_request_t *ogs_sbi_build_request(ogs_sbi_message_t *message) END } + nf_type = NF_INSTANCE_TYPE(ogs_sbi_self()->nf_instance); + if (nf_type) { + char *user_agent = OpenAPI_nf_type_ToString(nf_type); + if (user_agent) + ogs_sbi_header_set(request->http.headers, + OGS_SBI_USER_AGENT, user_agent); + } + ogs_assert(OGS_OK == ogs_sbi_rfc7231_string(sender_timestamp, ogs_time_now())); ogs_sbi_header_set(request->http.headers, @@ -465,6 +470,14 @@ ogs_sbi_request_t *ogs_sbi_build_request(ogs_sbi_message_t *message) ogs_sbi_header_set(request->http.headers, OGS_SBI_ACCEPT_ENCODING, message->http.content_encoding); + if (message->http.custom.callback) + ogs_sbi_header_set(request->http.headers, + OGS_SBI_CUSTOM_CALLBACK, message->http.custom.callback); + + if (message->http.custom.nrf_uri) + ogs_sbi_header_set(request->http.headers, + OGS_SBI_CUSTOM_NRF_URI, message->http.custom.nrf_uri); + return request; } @@ -532,37 +545,33 @@ int ogs_sbi_parse_request( /* Discovery Option Parameter */ } else if (!strcmp(ogs_hash_this_key(hi), OGS_SBI_PARAM_TARGET_NF_INSTANCE_ID)) { - discovery_option_presence = true; - ogs_sbi_discovery_option_set_target_nf_instance_id( - discovery_option, ogs_hash_this_val(hi)); + char *v = NULL; + v = ogs_hash_this_val(hi); + + if (v) { + ogs_sbi_discovery_option_set_target_nf_instance_id( + discovery_option, v); + discovery_option_presence = true; + } } else if (!strcmp(ogs_hash_this_key(hi), OGS_SBI_PARAM_REQUESTER_NF_INSTANCE_ID)) { - discovery_option_presence = true; - ogs_sbi_discovery_option_set_requester_nf_instance_id( - discovery_option, ogs_hash_this_val(hi)); + char *v = NULL; + v = ogs_hash_this_val(hi); + + if (v) { + ogs_sbi_discovery_option_set_requester_nf_instance_id( + discovery_option, v); + discovery_option_presence = true; + } } else if (!strcmp(ogs_hash_this_key(hi), OGS_SBI_PARAM_SERVICE_NAMES)) { char *v = NULL; - char *service_names; - char *token; - char *saveptr; v = ogs_hash_this_val(hi); if (v) { - service_names = ogs_strdup(v); - ogs_assert(service_names); - - token = ogs_strtok_r(service_names, ",", &saveptr); - while (token != NULL) - { - discovery_option_presence = true; - ogs_sbi_discovery_option_add_service_names( - discovery_option, token); - - token = ogs_strtok_r(NULL, ",", &saveptr); - } - - ogs_free(service_names); + ogs_sbi_discovery_option_parse_service_names( + discovery_option, v); + discovery_option_presence = true; } /* URL Query Parameter */ @@ -671,11 +680,26 @@ int ogs_sbi_parse_request( message->http.content_type = ogs_hash_this_val(hi); } else if (!ogs_strcasecmp(ogs_hash_this_key(hi), OGS_SBI_ACCEPT)) { message->http.accept = ogs_hash_this_val(hi); + } else if (!ogs_strcasecmp(ogs_hash_this_key(hi), OGS_SBI_USER_AGENT)) { + char *v = ogs_hash_this_val(hi); + if (v) + message->http.requester_nf_type = + OpenAPI_nf_type_FromString(v); + } else if (!ogs_strcasecmp(ogs_hash_this_key(hi), + OGS_SBI_CUSTOM_CALLBACK)) { + message->http.custom.callback = ogs_hash_this_val(hi); } } + if (!message->http.requester_nf_type) { + ogs_error("No User-Agent in HTTP2 Header"); + ogs_sbi_message_free(message); + return OGS_ERROR; + } + if (parse_content(message, &request->http) != OGS_OK) { ogs_error("parse_content() failed"); + ogs_sbi_message_free(message); return OGS_ERROR; } @@ -2396,3 +2420,46 @@ void ogs_sbi_discovery_option_add_service_names( [discovery_option->num_of_service_names]); discovery_option->num_of_service_names++; } + +char *ogs_sbi_discovery_option_build_service_names( + ogs_sbi_discovery_option_t *discovery_option) +{ + int i; + char *service_names = NULL; + + ogs_assert(discovery_option); + + service_names = ogs_strdup(discovery_option->service_names[0]); + ogs_expect_or_return_val(service_names, NULL); + + if (discovery_option->num_of_service_names > 1) { + for (i = 1; i < discovery_option->num_of_service_names; i++) + service_names = ogs_mstrcatf( + service_names, ",%s", discovery_option->service_names[i]); + } + + return service_names; +} + +void ogs_sbi_discovery_option_parse_service_names( + ogs_sbi_discovery_option_t *discovery_option, + char *service_names) +{ + char *v = NULL; + char *token = NULL; + char *saveptr = NULL; + + ogs_assert(discovery_option); + ogs_assert(service_names); + + v = ogs_strdup(service_names); + ogs_assert(v); + + token = ogs_strtok_r(v, ",", &saveptr); + while (token != NULL) { + ogs_sbi_discovery_option_add_service_names(discovery_option, token); + token = ogs_strtok_r(NULL, ",", &saveptr); + } + + ogs_free(v); +} diff --git a/lib/sbi/message.h b/lib/sbi/message.h index 40a78fa8d..7fbd2f1e0 100644 --- a/lib/sbi/message.h +++ b/lib/sbi/message.h @@ -233,8 +233,11 @@ extern "C" { #define OGS_SBI_NBSF_MANAGEMENT_ES3XX 4 #define OGS_SBI_NBSF_MANAGEMENT_EXTENDED_SAME_PCF 5 +#define OGS_SBI_SCHEME ":scheme" +#define OGS_SBI_AUTHORITY ":authority" #define OGS_SBI_ACCEPT "Accept" #define OGS_SBI_ACCEPT_ENCODING "Accept-Encoding" +#define OGS_SBI_USER_AGENT "User-Agent" #define OGS_SBI_CONTENT_TYPE "Content-Type" #define OGS_SBI_LOCATION "Location" #define OGS_SBI_EXPECT "Expect" @@ -328,6 +331,39 @@ extern "C" { #define OGS_SBI_CONTENT_5GNAS_SM_ID "5gnas-sm" #define OGS_SBI_CONTENT_NGAP_SM_ID "ngap-sm" +#define OGS_SBI_CALLBACK_NSMF_PDUSESSION_UPDATE \ + "Nsmf_PDUSession_Update" +#define OGS_SBI_CALLBACK_NSMF_PDUSESSION_STATUS_NOTIFY \ + "Nsmf_PDUSession_StatusNotify" +#define OGS_SBI_CALLBACK_NUDM_SDM_NOTIFICATION \ + "Nudm_SDM_Notification" +#define OGS_SBI_CALLBACK_NUDM_UECM_DEREGISTRATION_NOTIFICATION \ + "Nudm_UECM_DeregistrationNotification" +#define OGS_SBI_CALLBACK_NUDM_UECM_PCSCF_RESTORATION_NOTIFICATION \ + "Nudm_UECM_PCSCFRestorationNotification" +#define OGS_SBI_CALLBACK_NNRF_NFMANAGEMENT_NF_STATUS_NOTIFY \ + "Nnrf_NFManagement_NFStatusNotify" +#define OGS_SBI_CALLBACK_NAMF_EVENTEXPOSURE_NOTIFY \ + "Namf_EventExposure_Notify" +#define OGS_SBI_CALLBACK_NPCF_UEPOLICYCONTROL_UPDATE_NOTIFY \ + "Npcf_UEPolicyControl_UpdateNotify" +#define OGS_SBI_CALLBACK_NNSSF_NSSAIAVAILABILITY_NOTIFICATION \ + "Nnssf_NSSAIAvailability_Notification" +#define OGS_SBI_CALLBACK_NAMF_COMMUNICATION_AMF_STATUS_CHANGE_NOTIFY \ + "Namf_Communication_AMFStatusChangeNotify" +#define OGS_SBI_CALLBACK_NGMLC_LOCATION_EVENT_NOTIFY \ + "Ngmlc_Location_EventNotify" +#define OGS_SBI_CALLBACK_NCHF_CONVERGEDCHARGING_NOTIFY \ + "Nchf_ConvergedCharging_Notify" +#define OGS_SBI_CALLBACK_NNSSAAF_NSSAA_RE_AUTHENTICATION \ + "Nnssaaf_NSSAA_ReAuthentication" +#define OGS_SBI_CALLBACK_NNSSAAF_NSSAA_REVOCATION \ + "Nnssaaf_NSSAA_Revocation" +#define OGS_SBI_CALLBACK_N5G_DDNMF_DISCOVERY_MONITOR_UPDATE_RESULT \ + "N5g-ddnmf_Discovery_MonitorUpdateResult" +#define OGS_SBI_CALLBACK_N5G_DDNMF_DISCOVERY_MATCH_INFORMATION \ + "N5g-ddnmf_Discovery_MatchInformation" + typedef struct ogs_sbi_header_s { char *method; char *uri; @@ -366,11 +402,18 @@ typedef struct ogs_sbi_message_s { ogs_sbi_header_t h; struct { + OpenAPI_nf_type_e requester_nf_type; + char *accept; char *content_encoding; char *content_type; char *location; char *cache_control; + + struct { + char *callback; + char *nrf_uri; + } custom; } http; struct { @@ -537,9 +580,15 @@ void ogs_sbi_discovery_option_set_target_nf_instance_id( void ogs_sbi_discovery_option_set_requester_nf_instance_id( ogs_sbi_discovery_option_t *discovery_option, char *requester_nf_instance_id); + void ogs_sbi_discovery_option_add_service_names( ogs_sbi_discovery_option_t *discovery_option, char *service_name); +char *ogs_sbi_discovery_option_build_service_names( + ogs_sbi_discovery_option_t *discovery_option); +void ogs_sbi_discovery_option_parse_service_names( + ogs_sbi_discovery_option_t *discovery_option, + char *service_names); #ifdef __cplusplus } diff --git a/lib/sbi/nf-sm.c b/lib/sbi/nf-sm.c index 2c7e21529..9be81cc62 100644 --- a/lib/sbi/nf-sm.c +++ b/lib/sbi/nf-sm.c @@ -110,9 +110,7 @@ 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) { 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); @@ -147,7 +145,7 @@ void ogs_sbi_nf_state_will_register(ogs_fsm_t *s, ogs_event_t *e) if (message->res_status == OGS_SBI_HTTP_STATUS_OK || message->res_status == OGS_SBI_HTTP_STATUS_CREATED) { - ogs_sbi_nnrf_handle_nf_register(nf_instance, message); + ogs_nnrf_nfm_handle_nf_register(nf_instance, message); OGS_FSM_TRAN(s, &ogs_sbi_nf_state_registered); } else { ogs_error("[%s] HTTP Response Status Code [%d]", @@ -174,11 +172,6 @@ void ogs_sbi_nf_state_will_register(ogs_fsm_t *s, ogs_event_t *e) case OGS_EVENT_SBI_TIMER: switch(e->timer_id) { case OGS_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", NF_INSTANCE_ID(ogs_sbi_self()->nf_instance)); @@ -373,9 +366,7 @@ 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) { 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); @@ -403,11 +394,6 @@ void ogs_sbi_nf_state_exception(ogs_fsm_t *s, ogs_event_t *e) case OGS_EVENT_SBI_TIMER: switch(e->timer_id) { case OGS_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", NF_INSTANCE_ID(ogs_sbi_self()->nf_instance)); diff --git a/lib/sbi/nf-sm.h b/lib/sbi/nf-sm.h index 4c0a45473..8873e61ba 100644 --- a/lib/sbi/nf-sm.h +++ b/lib/sbi/nf-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/lib/sbi/nnrf-build.c b/lib/sbi/nnrf-build.c index 2e2808b2d..c3d055b71 100644 --- a/lib/sbi/nnrf-build.c +++ b/lib/sbi/nnrf-build.c @@ -55,13 +55,20 @@ ogs_sbi_request_t *ogs_nnrf_nfm_build_register(void) NFProfile = ogs_nnrf_nfm_build_nf_profile( ogs_sbi_self()->nf_instance, NULL, NULL, supported_features); - ogs_expect_or_return_val(NFProfile, NULL); + if (!NFProfile) { + ogs_error("No NFProfile"); + goto end; + } message.NFProfile = NFProfile; request = ogs_sbi_build_request(&message); + ogs_expect(request); - ogs_nnrf_nfm_free_nf_profile(NFProfile); +end: + + if (NFProfile) + ogs_nnrf_nfm_free_nf_profile(NFProfile); return request; } @@ -97,7 +104,10 @@ OpenAPI_nf_profile_t *ogs_nnrf_nfm_build_nf_profile( ogs_assert(nf_instance->id); NFProfile = ogs_calloc(1, sizeof(*NFProfile)); - ogs_expect_or_return_val(NFProfile, NULL); + if (!NFProfile) { + ogs_error("No NFProfile"); + return NULL; + } NFProfile->nf_instance_id = nf_instance->id; NFProfile->nf_type = nf_instance->nf_type; @@ -127,10 +137,12 @@ OpenAPI_nf_profile_t *ogs_nnrf_nfm_build_nf_profile( NFProfile->is_load = true; NFProfile->load = nf_instance->load; - Ipv4AddrList = OpenAPI_list_create(); - ogs_assert(Ipv4AddrList); - Ipv6AddrList = OpenAPI_list_create(); - ogs_assert(Ipv6AddrList); + NFProfile->ipv4_addresses = Ipv4AddrList = OpenAPI_list_create(); + if (!Ipv4AddrList) { + ogs_error("No Ipv4AddrList"); + ogs_nnrf_nfm_free_nf_profile(NFProfile); + return NULL; + } for (i = 0; i < nf_instance->num_of_ipv4; i++) { if (nf_instance->ipv4[i]) { @@ -140,10 +152,22 @@ OpenAPI_nf_profile_t *ogs_nnrf_nfm_build_nf_profile( nf_instance->ipv4[i]->ogs_sin_port); ogs_assert(nf_instance->ipv4[i]->ogs_sa_family == AF_INET); ipstr = ogs_ipstrdup(nf_instance->ipv4[i]); - ogs_expect_or_return_val(ipstr, NULL); + if (!ipstr) { + ogs_error("No ipstr"); + ogs_nnrf_nfm_free_nf_profile(NFProfile); + return NULL; + } OpenAPI_list_add(Ipv4AddrList, ipstr); } } + + NFProfile->ipv6_addresses = Ipv6AddrList = OpenAPI_list_create(); + if (!Ipv6AddrList) { + ogs_error("No IPv6AddrList"); + ogs_nnrf_nfm_free_nf_profile(NFProfile); + return NULL; + } + for (i = 0; i < nf_instance->num_of_ipv6; i++) { if (nf_instance->ipv6[i]) { ogs_trace("IPv6 [family:%d, port:%d]", @@ -151,35 +175,40 @@ OpenAPI_nf_profile_t *ogs_nnrf_nfm_build_nf_profile( nf_instance->ipv6[i]->ogs_sin_port); ogs_assert(nf_instance->ipv6[i]->ogs_sa_family == AF_INET6); ipstr = ogs_ipstrdup(nf_instance->ipv6[i]); - ogs_expect_or_return_val(ipstr, NULL); + if (!ipstr) { + ogs_error("No ipstr"); + ogs_nnrf_nfm_free_nf_profile(NFProfile); + return NULL; + } OpenAPI_list_add(Ipv6AddrList, ipstr); } } - if (Ipv4AddrList->count) - NFProfile->ipv4_addresses = Ipv4AddrList; - else - OpenAPI_list_free(Ipv4AddrList); - if (Ipv6AddrList->count) - NFProfile->ipv6_addresses = Ipv6AddrList; - else - OpenAPI_list_free(Ipv6AddrList); - - AllowedNfTypeList = OpenAPI_list_create(); - ogs_assert(AllowedNfTypeList); + NFProfile->allowed_nf_types = AllowedNfTypeList = OpenAPI_list_create(); + if (!AllowedNfTypeList) { + ogs_error("No AllowedNfTypeList"); + ogs_nnrf_nfm_free_nf_profile(NFProfile); + return NULL; + } for (i = 0; i < nf_instance->num_of_allowed_nf_type; i++) { OpenAPI_list_add(AllowedNfTypeList, (void *)(uintptr_t)nf_instance->allowed_nf_type[i]); } - if (AllowedNfTypeList->count) - NFProfile->allowed_nf_types = AllowedNfTypeList; - else - OpenAPI_list_free(AllowedNfTypeList); - NFServiceList = OpenAPI_list_create(); - ogs_assert(NFServiceList); + if (!NFServiceList) { + ogs_error("No nf_service_list"); + ogs_nnrf_nfm_free_nf_profile(NFProfile); + return NULL; + } + + if (OGS_SBI_FEATURES_IS_SET( + supported_features, OGS_SBI_NNRF_NFM_SERVICE_MAP)) { + NFProfile->nf_service_list = NFServiceList; + } else { + NFProfile->nf_services = NFServiceList; + } ogs_list_for_each(&nf_instance->nf_service_list, nf_service) { OpenAPI_nf_service_t *NFService = NULL; @@ -203,12 +232,20 @@ OpenAPI_nf_profile_t *ogs_nnrf_nfm_build_nf_profile( } NFService = build_nf_service(nf_service); - ogs_expect_or_return_val(NFService, NULL); + if (!NFService) { + ogs_error("No NFService"); + ogs_nnrf_nfm_free_nf_profile(NFProfile); + return NULL; + } if (OGS_SBI_FEATURES_IS_SET( supported_features, OGS_SBI_NNRF_NFM_SERVICE_MAP)) { NFServiceMap = OpenAPI_map_create(nf_service->id, NFService); - ogs_assert(NFServiceMap); + if (!NFServiceMap) { + ogs_error("No NFServiceMap"); + ogs_nnrf_nfm_free_nf_profile(NFProfile); + return NULL; + } OpenAPI_list_add(NFServiceList, NFServiceMap); } else { @@ -216,16 +253,6 @@ OpenAPI_nf_profile_t *ogs_nnrf_nfm_build_nf_profile( } } - if (NFServiceList->count) { - if (OGS_SBI_FEATURES_IS_SET( - supported_features, OGS_SBI_NNRF_NFM_SERVICE_MAP)) { - NFProfile->nf_service_list = NFServiceList; - } else { - NFProfile->nf_services = NFServiceList; - } - } else - OpenAPI_list_free(NFServiceList); - InfoList = OpenAPI_list_create(); ogs_assert(InfoList); @@ -240,7 +267,7 @@ OpenAPI_nf_profile_t *ogs_nnrf_nfm_build_nf_profile( } SmfInfo = build_smf_info(nf_info); - ogs_expect_or_return_val(SmfInfo, NULL); + ogs_assert(SmfInfo); InfoMap = OpenAPI_map_create( ogs_msprintf("%d", ++InfoMapKey), SmfInfo); @@ -250,7 +277,7 @@ OpenAPI_nf_profile_t *ogs_nnrf_nfm_build_nf_profile( } else if (nf_info->nf_type == OpenAPI_nf_type_AMF) { AmfInfo = build_amf_info(nf_info); - ogs_expect_or_return_val(AmfInfo, NULL); + ogs_assert(AmfInfo); InfoMap = OpenAPI_map_create( ogs_msprintf("%d", ++InfoMapKey), AmfInfo); @@ -390,53 +417,96 @@ static OpenAPI_nf_service_t *build_nf_service( ogs_assert(nf_service->name); NFService = ogs_calloc(1, sizeof(*NFService)); - ogs_expect_or_return_val(NFService, NULL); + if (!NFService) { + ogs_error("No NFService"); + return NULL; + } NFService->service_instance_id = ogs_strdup(nf_service->id); - ogs_expect_or_return_val(NFService->service_instance_id, NULL); + if (!NFService->service_instance_id) { + ogs_error("No service_instance_id"); + free_nf_service(NFService); + return NULL; + } NFService->service_name = ogs_strdup(nf_service->name); - ogs_expect_or_return_val(NFService->service_name, NULL); + if (!NFService->service_name) { + ogs_error("No service_name"); + free_nf_service(NFService); + return NULL; + } - VersionList = OpenAPI_list_create(); - ogs_assert(VersionList); + NFService->versions = VersionList = OpenAPI_list_create(); + if (!VersionList) { + ogs_error("No VersionList"); + free_nf_service(NFService); + return NULL; + } for (i = 0; i < nf_service->num_of_version; i++) { OpenAPI_nf_service_version_t *NFServiceVersion = NULL; NFServiceVersion = ogs_calloc(1, sizeof(*NFServiceVersion)); - ogs_expect_or_return_val(NFServiceVersion, NULL); + if (!NFServiceVersion) { + ogs_error("No NFServiceVersion"); + free_nf_service(NFService); + return NULL; + } if (nf_service->version[i].in_uri) { NFServiceVersion->api_version_in_uri = ogs_strdup(nf_service->version[i].in_uri); - ogs_expect_or_return_val( - NFServiceVersion->api_version_in_uri, NULL); + if (!NFServiceVersion->api_version_in_uri) { + ogs_error("No api_version_in_uri"); + if (NFServiceVersion) + ogs_free(NFServiceVersion); + free_nf_service(NFService); + return NULL; + } } if (nf_service->version[i].full) { NFServiceVersion->api_full_version = ogs_strdup(nf_service->version[i].full); - ogs_expect_or_return_val( - NFServiceVersion->api_full_version, NULL); + if (!NFServiceVersion->api_full_version) { + ogs_error("No api_full_version"); + if (NFServiceVersion) { + if (NFServiceVersion->api_version_in_uri) + ogs_free(NFServiceVersion->api_version_in_uri); + ogs_free(NFServiceVersion); + } + free_nf_service(NFService); + return NULL; + } } if (nf_service->version[i].expiry) { NFServiceVersion->expiry = ogs_strdup(nf_service->version[i].expiry); - ogs_expect_or_return_val( - NFServiceVersion->expiry, NULL); + if (!NFServiceVersion->expiry) { + ogs_error("No expiry"); + if (NFServiceVersion) { + if (NFServiceVersion->api_version_in_uri) + ogs_free(NFServiceVersion->api_version_in_uri); + if (NFServiceVersion->api_full_version) + ogs_free(NFServiceVersion->api_full_version); + ogs_free(NFServiceVersion); + } + free_nf_service(NFService); + return NULL; + } } OpenAPI_list_add(VersionList, NFServiceVersion); } - ogs_assert(VersionList->count); - NFService->versions = VersionList; - NFService->scheme = nf_service->scheme; NFService->nf_service_status = nf_service->status; if (nf_service->fqdn) NFService->fqdn = ogs_strdup(nf_service->fqdn); - IpEndPointList = OpenAPI_list_create(); - ogs_assert(IpEndPointList); + NFService->ip_end_points = IpEndPointList = OpenAPI_list_create(); + if (!IpEndPointList) { + ogs_error("No IpEndPointList"); + free_nf_service(NFService); + return NULL; + } for (i = 0; i < nf_service->num_of_addr; i++) { ogs_sockaddr_t *ipv4 = NULL; @@ -449,14 +519,33 @@ static OpenAPI_nf_service_t *build_nf_service( if (ipv4 || ipv6) { IpEndPoint = ogs_calloc(1, sizeof(*IpEndPoint)); - ogs_expect_or_return_val(IpEndPoint, NULL); + if (!IpEndPoint) { + ogs_error("No IpEndPoint"); + free_nf_service(NFService); + return NULL; + } if (ipv4) { IpEndPoint->ipv4_address = ogs_ipstrdup(ipv4); - ogs_expect_or_return_val(IpEndPoint->ipv4_address, NULL); + if (!IpEndPoint->ipv4_address) { + ogs_error("No ipv4_address"); + if (IpEndPoint) + ogs_free(IpEndPoint); + free_nf_service(NFService); + return NULL; + } } if (ipv6) { IpEndPoint->ipv6_address = ogs_ipstrdup(ipv6); - ogs_expect_or_return_val(IpEndPoint->ipv6_address, NULL); + if (!IpEndPoint->ipv6_address) { + ogs_error("No ipv6_address"); + if (IpEndPoint) { + if (IpEndPoint->ipv4_address) + ogs_free(IpEndPoint->ipv4_address); + ogs_free(IpEndPoint); + } + free_nf_service(NFService); + return NULL; + } } IpEndPoint->is_port = true; IpEndPoint->port = nf_service->addr[i].port; @@ -464,24 +553,18 @@ static OpenAPI_nf_service_t *build_nf_service( } } - if (IpEndPointList->count) - NFService->ip_end_points = IpEndPointList; - else - OpenAPI_list_free(IpEndPointList); - - AllowedNfTypeList = OpenAPI_list_create(); - ogs_assert(AllowedNfTypeList); + NFService->allowed_nf_types = AllowedNfTypeList = OpenAPI_list_create(); + if (!AllowedNfTypeList) { + ogs_error("No AllowedNfTypeList"); + free_nf_service(NFService); + return NULL; + } for (i = 0; i < nf_service->num_of_allowed_nf_type; i++) { OpenAPI_list_add(AllowedNfTypeList, (void *)(uintptr_t)nf_service->allowed_nf_type[i]); } - if (AllowedNfTypeList->count) - NFService->allowed_nf_types = AllowedNfTypeList; - else - OpenAPI_list_free(AllowedNfTypeList); - NFService->is_priority = true; NFService->priority = nf_service->priority; NFService->is_capacity = true; @@ -552,38 +635,50 @@ static OpenAPI_smf_info_t *build_smf_info(ogs_sbi_nf_info_t *nf_info) ogs_assert(nf_info); SmfInfo = ogs_calloc(1, sizeof(*SmfInfo)); - ogs_expect_or_return_val(SmfInfo, NULL); + if (!SmfInfo) { + ogs_error("No SmfInfo"); + return NULL; + } - sNssaiSmfInfoList = OpenAPI_list_create(); - ogs_assert(sNssaiSmfInfoList); + SmfInfo->s_nssai_smf_info_list = sNssaiSmfInfoList = OpenAPI_list_create(); + if (!sNssaiSmfInfoList) { + ogs_error("No sNssaiSmfInfoList"); + free_smf_info(SmfInfo); + return NULL; + } for (i = 0; i < nf_info->smf.num_of_slice; i++) { DnnSmfInfoList = OpenAPI_list_create(); - ogs_assert(DnnSmfInfoList); + if (!DnnSmfInfoList) { + ogs_error("No DnnSmfInfoList"); + free_smf_info(SmfInfo); + return NULL; + } 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); + ogs_assert(DnnSmfInfoItem); 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); + + OpenAPI_list_free(DnnSmfInfoList); + free_smf_info(SmfInfo); + + return NULL; } sNssaiSmfInfoItem = ogs_calloc(1, sizeof(*sNssaiSmfInfoItem)); - ogs_expect_or_return_val(sNssaiSmfInfoItem, NULL); + ogs_assert(sNssaiSmfInfoItem); sNssaiSmfInfoItem->dnn_smf_info_list = DnnSmfInfoList; - sNssaiSmfInfoItem->s_nssai = sNssai = - ogs_calloc(1, sizeof(*sNssai)); - ogs_expect_or_return_val(sNssai, NULL); + sNssaiSmfInfoItem->s_nssai = sNssai = ogs_calloc(1, sizeof(*sNssai)); + ogs_assert(sNssai); 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); @@ -591,80 +686,98 @@ static OpenAPI_smf_info_t *build_smf_info(ogs_sbi_nf_info_t *nf_info) 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); + SmfInfo->tai_list = TaiList = OpenAPI_list_create(); + if (!TaiList) { + ogs_error("No TaiList"); + free_smf_info(SmfInfo); + return NULL; + } 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); + if (!TaiItem) { + ogs_error("No TaiItem"); + free_smf_info(SmfInfo); + return 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); + if (!TaiItem->plmn_id) { + ogs_error("No TaiItem->plmn_id"); + if (TaiItem) + ogs_free(TaiItem); + free_smf_info(SmfInfo); + return NULL; + } TaiItem->tac = ogs_uint24_to_0string(nf_info->smf.nr_tai[i].tac); - ogs_expect_or_return_val(TaiItem->tac, NULL); + if (!TaiItem->tac) { + ogs_error("No TaiItem->tac"); + if (TaiItem) { + if (TaiItem->plmn_id) + ogs_free(TaiItem->plmn_id); + ogs_free(TaiItem); + } + free_smf_info(SmfInfo); + return 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); + SmfInfo->tai_range_list = TaiRangeList = OpenAPI_list_create(); + if (!TaiRangeList) { + ogs_error("No TaiRangeList"); + free_smf_info(SmfInfo); + return NULL; + } for (i = 0; i < nf_info->smf.num_of_nr_tai_range; i++) { TacRangeList = OpenAPI_list_create(); - ogs_assert(TacRangeList); + if (!TacRangeList) { + ogs_error("No TacRangeList"); + free_smf_info(SmfInfo); + return NULL; + } 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); + ogs_assert(TacRangeItem); TacRangeItem->start = ogs_uint24_to_0string( nf_info->smf.nr_tai_range[i].start[j]); - ogs_expect_or_return_val(TacRangeItem->start, NULL); + ogs_assert(TacRangeItem->start); TacRangeItem->end = ogs_uint24_to_0string( nf_info->smf.nr_tai_range[i].end[j]); - ogs_expect_or_return_val(TacRangeItem->end, NULL); + ogs_assert(TacRangeItem->end); 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); + + OpenAPI_list_free(TacRangeList); + free_smf_info(SmfInfo); + + return NULL; } TaiRangeItem = ogs_calloc(1, sizeof(*TaiRangeItem)); - ogs_expect_or_return_val(TaiRangeItem, NULL); + ogs_assert(TaiRangeItem); 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); + ogs_assert(TaiRangeItem->plmn_id); TaiRangeItem->tac_range_list = TacRangeList; OpenAPI_list_add(TaiRangeList, TaiRangeItem); } - if (TaiRangeList->count) - SmfInfo->tai_range_list = TaiRangeList; - else - OpenAPI_list_free(TaiRangeList); - return SmfInfo; } @@ -686,103 +799,166 @@ static OpenAPI_amf_info_t *build_amf_info(ogs_sbi_nf_info_t *nf_info) ogs_assert(nf_info); AmfInfo = ogs_calloc(1, sizeof(*AmfInfo)); - ogs_expect_or_return_val(AmfInfo, NULL); + if (!AmfInfo) { + ogs_error("No AmfInfo"); + return NULL; + } AmfInfo->amf_set_id = ogs_msprintf("%03x", nf_info->amf.amf_set_id); + if (!AmfInfo->amf_set_id) { + ogs_error("No amf_set_id"); + free_amf_info(AmfInfo); + return NULL; + } AmfInfo->amf_region_id = ogs_msprintf("%02x", nf_info->amf.amf_region_id); + if (!AmfInfo->amf_region_id) { + ogs_error("No amf_region_id"); + free_amf_info(AmfInfo); + return NULL; + } - guamiAmfInfoList = OpenAPI_list_create(); - ogs_assert(guamiAmfInfoList); + AmfInfo->guami_list = guamiAmfInfoList = OpenAPI_list_create(); + if (!guamiAmfInfoList) { + ogs_error("No guamiAmfInfoList"); + free_amf_info(AmfInfo); + return NULL; + } for (i = 0; i < nf_info->amf.num_of_guami; i++) { guamiAmfInfoItem = ogs_calloc(1, sizeof(*guamiAmfInfoItem)); - ogs_expect_or_return_val(guamiAmfInfoItem, NULL); + if (!guamiAmfInfoItem) { + ogs_error("guamiAmfInfoItem"); + free_amf_info(AmfInfo); + return NULL; + } guamiAmfInfoItem->plmn_id = ogs_sbi_build_plmn_id_nid(&nf_info->amf.guami[i].plmn_id); - ogs_expect_or_return_val(guamiAmfInfoItem->plmn_id, NULL); + if (!guamiAmfInfoItem->plmn_id) { + ogs_error("guamiAmfInfoItem->plmn_id"); + if (guamiAmfInfoItem) + ogs_free(guamiAmfInfoItem); + free_amf_info(AmfInfo); + return NULL; + } guamiAmfInfoItem->amf_id = ogs_amf_id_to_string(&nf_info->amf.guami[i].amf_id); - ogs_expect_or_return_val(guamiAmfInfoItem->amf_id, NULL); + if (!guamiAmfInfoItem->amf_id) { + ogs_error("guamiAmfInfoItem->amf_id"); + if (guamiAmfInfoItem) { + if (guamiAmfInfoItem->plmn_id) + ogs_free(guamiAmfInfoItem->plmn_id); + ogs_free(guamiAmfInfoItem); + } + free_amf_info(AmfInfo); + return NULL; + } OpenAPI_list_add(guamiAmfInfoList, guamiAmfInfoItem); } - if (guamiAmfInfoList->count) - AmfInfo->guami_list = guamiAmfInfoList; - else - OpenAPI_list_free(guamiAmfInfoList); - - TaiList = OpenAPI_list_create(); - ogs_assert(TaiList); + AmfInfo->tai_list = TaiList = OpenAPI_list_create(); + if (!TaiList) { + ogs_error("No TaiList"); + free_amf_info(AmfInfo); + return NULL; + } for (i = 0; i < nf_info->amf.num_of_nr_tai; i++) { TaiItem = ogs_calloc(1, sizeof(*TaiItem)); - ogs_expect_or_return_val(TaiItem, NULL); + if (!TaiList) { + ogs_error("No TaiItem"); + free_amf_info(AmfInfo); + return NULL; + } TaiItem->plmn_id = ogs_sbi_build_plmn_id( &nf_info->amf.nr_tai[i].plmn_id); - ogs_expect_or_return_val(TaiItem->plmn_id, NULL); + if (!TaiItem->plmn_id) { + ogs_error("No TaiItem->plmn_id"); + if (TaiItem) + ogs_free(TaiItem); + free_amf_info(AmfInfo); + return NULL; + } TaiItem->tac = ogs_uint24_to_0string(nf_info->amf.nr_tai[i].tac); - ogs_expect_or_return_val(TaiItem->tac, NULL); + if (!TaiItem->tac) { + ogs_error("No TaiItem->tac"); + if (TaiItem) { + if (TaiItem->plmn_id) + ogs_free(TaiItem->plmn_id); + ogs_free(TaiItem); + } + free_amf_info(AmfInfo); + return NULL; + } OpenAPI_list_add(TaiList, TaiItem); } - if (TaiList->count) - AmfInfo->tai_list = TaiList; - else - OpenAPI_list_free(TaiList); - - TaiRangeList = OpenAPI_list_create(); - ogs_assert(TaiRangeList); + AmfInfo->tai_range_list = TaiRangeList = OpenAPI_list_create(); + if (!TaiRangeList) { + ogs_error("No TaiRangeList"); + free_amf_info(AmfInfo); + return NULL; + } for (i = 0; i < nf_info->amf.num_of_nr_tai_range; i++) { TacRangeList = OpenAPI_list_create(); - ogs_assert(TacRangeList); + if (!TacRangeList) { + ogs_error("No TacRangeList"); + free_amf_info(AmfInfo); + return NULL; + } for (j = 0; j < nf_info->amf.nr_tai_range[i].num_of_tac_range; j++) { TacRangeItem = ogs_calloc(1, sizeof(*TacRangeItem)); - ogs_expect_or_return_val(TacRangeItem, NULL); + ogs_assert(TacRangeItem); TacRangeItem->start = ogs_uint24_to_0string( nf_info->amf.nr_tai_range[i].start[j]); - ogs_expect_or_return_val(TacRangeItem->start, NULL); + ogs_assert(TacRangeItem->start); TacRangeItem->end = ogs_uint24_to_0string( nf_info->amf.nr_tai_range[i].end[j]); - ogs_expect_or_return_val(TacRangeItem->end, NULL); + ogs_assert(TacRangeItem->end); 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); + + OpenAPI_list_free(TacRangeList); + free_amf_info(AmfInfo); + + return NULL; } TaiRangeItem = ogs_calloc(1, sizeof(*TaiRangeItem)); - ogs_expect_or_return_val(TaiRangeItem, NULL); + if (!TaiRangeItem) { + ogs_error("No TaiRangeItem"); + free_amf_info(AmfInfo); + return NULL; + } TaiRangeItem->plmn_id = ogs_sbi_build_plmn_id( &nf_info->amf.nr_tai_range[i].plmn_id); - ogs_expect_or_return_val(TaiRangeItem->plmn_id, NULL); + if (!TaiRangeItem->plmn_id) { + ogs_error("No TaiRangeItem->plmn_id"); + ogs_free(TaiRangeItem); + free_amf_info(AmfInfo); + return NULL; + } TaiRangeItem->tac_range_list = TacRangeList; OpenAPI_list_add(TaiRangeList, TaiRangeItem); } - if (TaiRangeList->count) - AmfInfo->tai_range_list = TaiRangeList; - else - OpenAPI_list_free(TaiRangeList); - return AmfInfo; } @@ -885,8 +1061,10 @@ static void free_amf_info(OpenAPI_amf_info_t *AmfInfo) ogs_assert(AmfInfo); - ogs_free(AmfInfo->amf_set_id); - ogs_free(AmfInfo->amf_region_id); + if (AmfInfo->amf_set_id) + ogs_free(AmfInfo->amf_set_id); + if (AmfInfo->amf_region_id) + ogs_free(AmfInfo->amf_region_id); guamiAmfInfoList = AmfInfo->guami_list; OpenAPI_list_for_each(guamiAmfInfoList, node) { @@ -972,21 +1150,29 @@ ogs_sbi_request_t *ogs_nnrf_nfm_build_update(void) message.http.content_type = (char *)OGS_SBI_CONTENT_PATCH_TYPE; PatchItemList = OpenAPI_list_create(); - ogs_assert(PatchItemList); + if (!PatchItemList) { + ogs_error("No PatchItemList"); + goto end; + } memset(&item, 0, sizeof(item)); item.op = OpenAPI_patch_operation_replace; item.path = (char *)"/nfStatus"; item.value = OpenAPI_any_type_create_string( OpenAPI_nf_status_ToString(OpenAPI_nf_status_REGISTERED)); - ogs_assert(item.value); + if (!item.value) { + ogs_error("No item.value"); + goto end; + } OpenAPI_list_add(PatchItemList, &item); message.PatchItemList = PatchItemList; request = ogs_sbi_build_request(&message); + ogs_expect(request); +end: OpenAPI_list_free(PatchItemList); OpenAPI_any_type_free(item.value); @@ -1013,6 +1199,7 @@ ogs_sbi_request_t *ogs_nnrf_nfm_build_de_register(void) message.h.resource.component[1] = nf_instance->id; request = ogs_sbi_build_request(&message); + ogs_expect(request); return request; } @@ -1039,10 +1226,16 @@ ogs_sbi_request_t *ogs_nnrf_nfm_build_status_subscribe( (char *)OGS_SBI_RESOURCE_NAME_SUBSCRIPTIONS; SubscriptionData = ogs_calloc(1, sizeof(*SubscriptionData)); - ogs_expect_or_return_val(SubscriptionData, NULL); + if (!SubscriptionData) { + ogs_error("No SubscriptionData"); + goto end; + } server = ogs_list_first(&ogs_sbi_self()->server_list); - ogs_expect_or_return_val(server, NULL); + if (!server) { + ogs_error("No server"); + goto end; + } memset(&header, 0, sizeof(header)); header.service.name = (char *)OGS_SBI_SERVICE_NAME_NNRF_NFM; @@ -1051,8 +1244,10 @@ ogs_sbi_request_t *ogs_nnrf_nfm_build_status_subscribe( (char *)OGS_SBI_RESOURCE_NAME_NF_STATUS_NOTIFY; SubscriptionData->nf_status_notification_uri = ogs_sbi_server_uri(server, &header); - ogs_expect_or_return_val( - SubscriptionData->nf_status_notification_uri, NULL); + if (!SubscriptionData->nf_status_notification_uri) { + ogs_error("No nf_status_notification_uri"); + goto end; + } SubscriptionData->req_nf_type = subscription_data->req_nf_type; SubscriptionData->req_nf_instance_id = @@ -1062,7 +1257,10 @@ ogs_sbi_request_t *ogs_nnrf_nfm_build_status_subscribe( OGS_SBI_NNRF_NFM_SERVICE_MAP); SubscriptionData->requester_features = ogs_uint64_to_string(subscription_data->requester_features); - ogs_expect_or_return_val(SubscriptionData->requester_features, NULL); + if (!SubscriptionData->requester_features) { + ogs_error("No requester_features"); + goto end; + } memset(&SubscrCond, 0, sizeof(SubscrCond)); if (subscription_data->subscr_cond.nf_type) { @@ -1076,11 +1274,20 @@ ogs_sbi_request_t *ogs_nnrf_nfm_build_status_subscribe( message.SubscriptionData = SubscriptionData; - request = ogs_sbi_build_request(&message); + message.http.custom.callback = + (char *)OGS_SBI_CALLBACK_NNRF_NFMANAGEMENT_NF_STATUS_NOTIFY; - ogs_free(SubscriptionData->nf_status_notification_uri); - ogs_free(SubscriptionData->requester_features); - ogs_free(SubscriptionData); + request = ogs_sbi_build_request(&message); + ogs_expect(request); + +end: + if (SubscriptionData) { + if (SubscriptionData->nf_status_notification_uri) + ogs_free(SubscriptionData->nf_status_notification_uri); + if (SubscriptionData->requester_features) + ogs_free(SubscriptionData->requester_features); + ogs_free(SubscriptionData); + } return request; } @@ -1102,7 +1309,11 @@ ogs_sbi_request_t *ogs_nnrf_nfm_build_status_unsubscribe( (char *)OGS_SBI_RESOURCE_NAME_SUBSCRIPTIONS; message.h.resource.component[1] = subscription_data->id; + message.http.custom.callback = + (char *)OGS_SBI_CALLBACK_NNRF_NFMANAGEMENT_NF_STATUS_NOTIFY; + request = ogs_sbi_build_request(&message); + ogs_expect(request); return request; } @@ -1123,23 +1334,20 @@ ogs_sbi_request_t *ogs_nnrf_nfm_build_profile_retrieve(char *nf_instance_id) message.h.resource.component[1] = nf_instance_id; request = ogs_sbi_build_request(&message); + ogs_expect(request); return request; } ogs_sbi_request_t *ogs_nnrf_disc_build_discover( OpenAPI_nf_type_e target_nf_type, + OpenAPI_nf_type_e requester_nf_type, ogs_sbi_discovery_option_t *discovery_option) { ogs_sbi_message_t message; ogs_sbi_request_t *request = NULL; - OpenAPI_nf_type_e requester_nf_type = OpenAPI_nf_type_NULL; - ogs_assert(target_nf_type); - - ogs_assert(ogs_sbi_self()->nf_instance); - requester_nf_type = ogs_sbi_self()->nf_instance->nf_type; ogs_assert(requester_nf_type); memset(&message, 0, sizeof(message)); @@ -1155,6 +1363,7 @@ ogs_sbi_request_t *ogs_nnrf_disc_build_discover( message.param.discovery_option = discovery_option; request = ogs_sbi_build_request(&message); + ogs_expect(request); return request; } diff --git a/lib/sbi/nnrf-build.h b/lib/sbi/nnrf-build.h index 16c8019e7..f1ba23028 100644 --- a/lib/sbi/nnrf-build.h +++ b/lib/sbi/nnrf-build.h @@ -43,6 +43,7 @@ ogs_sbi_request_t *ogs_nnrf_nfm_build_profile_retrieve(char *nf_instance_id); ogs_sbi_request_t *ogs_nnrf_disc_build_discover( OpenAPI_nf_type_e target_nf_type, + OpenAPI_nf_type_e requester_nf_type, ogs_sbi_discovery_option_t *discovery_option); #ifdef __cplusplus diff --git a/lib/sbi/nnrf-handler.c b/lib/sbi/nnrf-handler.c index bfd964787..e6b8fb7f3 100644 --- a/lib/sbi/nnrf-handler.c +++ b/lib/sbi/nnrf-handler.c @@ -24,16 +24,13 @@ static void handle_nf_service( static void handle_smf_info( ogs_sbi_nf_instance_t *nf_instance, OpenAPI_smf_info_t *SmfInfo); -void ogs_sbi_nnrf_handle_nf_register( +void ogs_nnrf_nfm_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) { @@ -46,7 +43,7 @@ void ogs_sbi_nnrf_handle_nf_register( nf_instance->time.heartbeat_interval = NFProfile->heart_beat_timer; } -void ogs_sbi_nnrf_handle_nf_profile( +void ogs_nnrf_nfm_handle_nf_profile( ogs_sbi_nf_instance_t *nf_instance, OpenAPI_nf_profile_t *NFProfile) { int rv; @@ -451,17 +448,14 @@ static void handle_smf_info( } } -void ogs_nnrf_handle_nf_status_subscribe( +void ogs_nnrf_nfm_handle_nf_status_subscribe( ogs_sbi_subscription_data_t *subscription_data, ogs_sbi_message_t *recvmsg) { OpenAPI_subscription_data_t *SubscriptionData = NULL; - ogs_sbi_client_t *client = NULL; ogs_assert(recvmsg); ogs_assert(subscription_data); - client = subscription_data->client; - ogs_assert(client); SubscriptionData = recvmsg->SubscriptionData; if (!SubscriptionData) { @@ -506,7 +500,7 @@ void ogs_nnrf_handle_nf_status_subscribe( } } -bool ogs_nnrf_handle_nf_status_notify( +bool ogs_nnrf_nfm_handle_nf_status_notify( ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) { int rv; @@ -633,7 +627,7 @@ bool ogs_nnrf_handle_nf_status_notify( message.h.resource.component[1]); } - ogs_sbi_nnrf_handle_nf_profile(nf_instance, NFProfile); + ogs_nnrf_nfm_handle_nf_profile(nf_instance, NFProfile); ogs_info("[%s] (NRF-notify) NF Profile updated", nf_instance->id); @@ -685,7 +679,7 @@ bool ogs_nnrf_handle_nf_status_notify( return true; } -void ogs_nnrf_handle_nf_discover_search_result( +void ogs_nnrf_disc_handle_nf_discover_search_result( OpenAPI_search_result_t *SearchResult) { OpenAPI_lnode_t *node = NULL; @@ -737,7 +731,7 @@ void ogs_nnrf_handle_nf_discover_search_result( } if (NF_INSTANCE_ID_IS_OTHERS(nf_instance->id)) { - ogs_sbi_nnrf_handle_nf_profile(nf_instance, NFProfile); + ogs_nnrf_nfm_handle_nf_profile(nf_instance, NFProfile); ogs_sbi_client_associate(nf_instance); diff --git a/lib/sbi/nnrf-handler.h b/lib/sbi/nnrf-handler.h index a943362ea..e6044a9cc 100644 --- a/lib/sbi/nnrf-handler.h +++ b/lib/sbi/nnrf-handler.h @@ -24,18 +24,18 @@ extern "C" { #endif -void ogs_sbi_nnrf_handle_nf_register( +void ogs_nnrf_nfm_handle_nf_register( ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_message_t *recvmsg); -void ogs_sbi_nnrf_handle_nf_profile( +void ogs_nnrf_nfm_handle_nf_profile( ogs_sbi_nf_instance_t *nf_instance, OpenAPI_nf_profile_t *NFProfile); -void ogs_nnrf_handle_nf_status_subscribe( +void ogs_nnrf_nfm_handle_nf_status_subscribe( ogs_sbi_subscription_data_t *subscription_data, ogs_sbi_message_t *recvmsg); -bool ogs_nnrf_handle_nf_status_notify( +bool ogs_nnrf_nfm_handle_nf_status_notify( ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); -void ogs_nnrf_handle_nf_discover_search_result( +void ogs_nnrf_disc_handle_nf_discover_search_result( OpenAPI_search_result_t *SearchResult); #ifdef __cplusplus diff --git a/lib/sbi/nnrf-path.c b/lib/sbi/nnrf-path.c new file mode 100644 index 000000000..2d4fe4f63 --- /dev/null +++ b/lib/sbi/nnrf-path.c @@ -0,0 +1,132 @@ +/* + * Copyright (C) 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" + +bool ogs_nnrf_nfm_send_nf_register(ogs_sbi_nf_instance_t *nf_instance) +{ + bool rc; + ogs_sbi_request_t *request = NULL; + + ogs_assert(nf_instance); + + request = ogs_nnrf_nfm_build_register(); + if (!request) { + ogs_error("No Request"); + return false; + } + + rc = ogs_sbi_send_notification_request( + OGS_SBI_SERVICE_TYPE_NNRF_NFM, NULL, request, nf_instance); + ogs_expect(rc == true); + + ogs_sbi_request_free(request); + + return rc; +} + +bool ogs_nnrf_nfm_send_nf_update(ogs_sbi_nf_instance_t *nf_instance) +{ + bool rc; + ogs_sbi_request_t *request = NULL; + + ogs_assert(nf_instance); + + request = ogs_nnrf_nfm_build_update(); + if (!request) { + ogs_error("No Request"); + return false; + } + + rc = ogs_sbi_send_notification_request( + OGS_SBI_SERVICE_TYPE_NNRF_NFM, NULL, request, nf_instance); + ogs_expect(rc == true); + + ogs_sbi_request_free(request); + + return rc; +} + +bool ogs_nnrf_nfm_send_nf_de_register(ogs_sbi_nf_instance_t *nf_instance) +{ + bool rc; + ogs_sbi_request_t *request = NULL; + + ogs_assert(nf_instance); + + request = ogs_nnrf_nfm_build_de_register(); + if (!request) { + ogs_error("No Request"); + return false; + } + + rc = ogs_sbi_send_notification_request( + OGS_SBI_SERVICE_TYPE_NNRF_NFM, NULL, request, nf_instance); + ogs_expect(rc == true); + + ogs_sbi_request_free(request); + + return rc; +} + +bool ogs_nnrf_nfm_send_nf_status_subscribe( + ogs_sbi_subscription_data_t *subscription_data) +{ + bool rc; + ogs_sbi_request_t *request = NULL; + + ogs_assert(subscription_data); + + request = ogs_nnrf_nfm_build_status_subscribe(subscription_data); + if (!request) { + ogs_error("No Request"); + return false; + } + + rc = ogs_sbi_send_notification_request( + OGS_SBI_SERVICE_TYPE_NNRF_NFM, NULL, request, subscription_data); + ogs_expect(rc == true); + + ogs_sbi_request_free(request); + + return rc; +} + +bool ogs_nnrf_nfm_send_nf_status_unsubscribe( + ogs_sbi_subscription_data_t *subscription_data) +{ + bool rc; + ogs_sbi_request_t *request = NULL; + + ogs_assert(subscription_data); + + request = ogs_nnrf_nfm_build_status_unsubscribe(subscription_data); + if (!request) { + ogs_error("No Request"); + return false; + } + + rc = ogs_sbi_send_notification_request( + OGS_SBI_SERVICE_TYPE_NNRF_NFM, NULL, request, subscription_data); + ogs_expect(rc == true); + + ogs_sbi_request_free(request); + + return rc; +} diff --git a/src/scp/nnrf-handler.h b/lib/sbi/nnrf-path.h similarity index 51% rename from src/scp/nnrf-handler.h rename to lib/sbi/nnrf-path.h index 6fac7be9d..869eaf660 100644 --- a/src/scp/nnrf-handler.h +++ b/lib/sbi/nnrf-path.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2022 by Sukchan Lee + * Copyright (C) 2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -17,20 +17,29 @@ * along with this program. If not, see . */ -#ifndef SCP_NNRF_HANDLER_H -#define SCP_NNRF_HANDLER_H +#ifndef OGS_NNRF_PATH_H +#define OGS_NNRF_PATH_H -#include "context.h" +#include "nnrf-build.h" #ifdef __cplusplus extern "C" { #endif -void scp_nnrf_handle_nf_discover( - ogs_sbi_xact_t *xact, ogs_sbi_message_t *recvmsg); +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_status_subscribe( + ogs_sbi_subscription_data_t *subscription_data); +bool ogs_nnrf_nfm_send_nf_status_unsubscribe( + ogs_sbi_subscription_data_t *subscription_data); + +bool ogs_nnrf_nfm_send_to_nrf( + ogs_sbi_client_t *client, ogs_sbi_client_cb_f client_cb, + ogs_sbi_request_t *request, void *data); #ifdef __cplusplus } #endif -#endif /* SCP_NNRF_HANDLER_H */ +#endif /* OGS_NNRF_PATH_H */ diff --git a/lib/sbi/ogs-sbi.h b/lib/sbi/ogs-sbi.h index 8139bba62..db0ed6663 100644 --- a/lib/sbi/ogs-sbi.h +++ b/lib/sbi/ogs-sbi.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 by Sukchan Lee + * Copyright (C) 2019-2022 by Sukchan Lee * * This file is part of Open5GS. * @@ -101,6 +101,7 @@ #include "sbi/nnrf-build.h" #include "sbi/nnrf-handler.h" +#include "sbi/nnrf-path.h" #include "sbi/path.h" diff --git a/lib/sbi/path.c b/lib/sbi/path.c index 95c192a6e..26a107a4f 100644 --- a/lib/sbi/path.c +++ b/lib/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. * @@ -19,11 +19,351 @@ #include "ogs-sbi.h" -bool ogs_sbi_send_request(ogs_sbi_nf_instance_t *nf_instance, - ogs_sbi_client_cb_f client_cb, ogs_sbi_xact_t *xact) +static void build_default_discovery_parameter( + ogs_sbi_request_t *request, + ogs_sbi_service_type_e service_type, + ogs_sbi_discovery_option_t *discovery_option); + +int ogs_sbi_server_handler(ogs_sbi_request_t *request, void *data) +{ + ogs_event_t *e = NULL; + int rv; + + ogs_assert(request); + ogs_assert(data); + + e = ogs_event_new(OGS_EVENT_SBI_SERVER); + ogs_assert(e); + + e->sbi.request = request; + e->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); + ogs_event_free(e); + return OGS_ERROR; + } + + return OGS_OK; +} + +int ogs_sbi_client_handler( + int status, ogs_sbi_response_t *response, void *data) +{ + ogs_event_t *e = NULL; + int rv; + + if (status != OGS_OK) { + ogs_log_message( + status == OGS_DONE ? OGS_LOG_DEBUG : OGS_LOG_WARN, 0, + "ogs_sbi_client_handler() failed [%d]", status); + return OGS_ERROR; + } + + ogs_assert(response); + + e = ogs_event_new(OGS_EVENT_SBI_CLIENT); + ogs_assert(e); + e->sbi.response = response; + e->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); + ogs_event_free(e); + return OGS_ERROR; + } + + return OGS_OK; +} + +static int client_discover_cb( + int status, ogs_sbi_response_t *response, void *data) +{ + int rv; + ogs_event_t *e = NULL; + + ogs_sbi_xact_t *xact = NULL; + ogs_sbi_object_t *sbi_object = NULL; + ogs_sbi_service_type_e service_type = OGS_SBI_SERVICE_TYPE_NULL; + OpenAPI_nf_type_e target_nf_type = OpenAPI_nf_type_NULL; + OpenAPI_nf_type_e requester_nf_type = OpenAPI_nf_type_NULL; + + ogs_hash_index_t *hi = NULL; + char *producer_id = NULL; + + xact = data; + ogs_assert(xact); + + xact = ogs_sbi_xact_cycle(xact); + if (!xact) { + ogs_error("SBI transaction has already been removed"); + if (response) + ogs_sbi_response_free(response); + return OGS_ERROR; + } + + sbi_object = xact->sbi_object; + ogs_assert(sbi_object); + service_type = xact->service_type; + ogs_assert(service_type); + target_nf_type = ogs_sbi_service_type_to_nf_type(service_type); + requester_nf_type = xact->requester_nf_type; + ogs_assert(requester_nf_type); + + if (status != OGS_OK) { + ogs_log_message( + status == OGS_DONE ? OGS_LOG_DEBUG : OGS_LOG_WARN, 0, + "ogs_sbi_client_handler() failed [%d]", status); + ogs_sbi_xact_remove(xact); + return OGS_ERROR; + } + + ogs_assert(response); + + /* Check if 3gpp-Sbi-Producer-Id in HTTP2 Header */ + for (hi = ogs_hash_first(response->http.headers); + hi; hi = ogs_hash_next(hi)) { + if (!ogs_strcasecmp(ogs_hash_this_key(hi), OGS_SBI_CUSTOM_PRODUCER_ID)) { + producer_id = ogs_hash_this_val(hi); + break; + } + } + + /* Added newly discovered NF Instance */ + if (producer_id) { + ogs_sbi_nf_instance_t *nf_instance = + ogs_sbi_nf_instance_find(producer_id); + if (!nf_instance) { + nf_instance = ogs_sbi_nf_instance_add(); + ogs_assert(nf_instance); + + ogs_sbi_nf_instance_set_id(nf_instance, producer_id); + ogs_sbi_nf_instance_set_type(nf_instance, target_nf_type); + } + + OGS_SBI_SETUP_NF_INSTANCE( + sbi_object->service_type_array[service_type], nf_instance); + } + + e = ogs_event_new(OGS_EVENT_SBI_CLIENT); + ogs_assert(e); + e->sbi.response = response; + e->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); + ogs_event_free(e); + return OGS_ERROR; + } + + return OGS_OK; +} + +bool ogs_sbi_discover_and_send(ogs_sbi_xact_t *xact) +{ + ogs_sbi_client_t *client = NULL, *scp_client = NULL; + ogs_sbi_nf_instance_t *nf_instance = NULL; + + ogs_sbi_object_t *sbi_object = NULL; + ogs_sbi_service_type_e service_type = OGS_SBI_SERVICE_TYPE_NULL; + ogs_sbi_discovery_option_t *discovery_option = NULL; + ogs_sbi_request_t *request = NULL; + + OpenAPI_nf_type_e target_nf_type = OpenAPI_nf_type_NULL; + OpenAPI_nf_type_e requester_nf_type = OpenAPI_nf_type_NULL; + char *apiroot = NULL; + + sbi_object = xact->sbi_object; + ogs_assert(sbi_object); + service_type = xact->service_type; + ogs_assert(service_type); + target_nf_type = ogs_sbi_service_type_to_nf_type(service_type); + ogs_assert(target_nf_type); + requester_nf_type = xact->requester_nf_type; + ogs_assert(requester_nf_type); + request = xact->request; + ogs_assert(request); + + discovery_option = xact->discovery_option; + + /* SCP Availability */ + if (ogs_sbi_self()->discovery_config.delegated == + OGS_SBI_DISCOVERY_DELEGATED_AUTO) { + scp_client = NF_INSTANCE_CLIENT(ogs_sbi_self()->scp_instance); + } else if (ogs_sbi_self()->discovery_config.delegated == + OGS_SBI_DISCOVERY_DELEGATED_YES) { + scp_client = NF_INSTANCE_CLIENT(ogs_sbi_self()->scp_instance); + ogs_assert(scp_client); + } + + /* Target NF-Instance */ + nf_instance = sbi_object->service_type_array[service_type].nf_instance; + if (!nf_instance) { + nf_instance = ogs_sbi_nf_instance_find_by_discovery_param( + target_nf_type, requester_nf_type, discovery_option); + if (nf_instance) + OGS_SBI_SETUP_NF_INSTANCE( + sbi_object->service_type_array[service_type], nf_instance); + } + + /* Target Client */ + if (request->h.uri == NULL) { + if (nf_instance) { + client = ogs_sbi_client_find_by_service_name(nf_instance, + request->h.service.name, request->h.api.version); + } + } else { + ogs_sockaddr_t *addr = NULL; + + addr = ogs_sbi_getaddr_from_uri(request->h.uri); + if (!addr) { + ogs_error("Invalid URL [%s]", request->h.uri); + return false; + } + client = ogs_sbi_client_find(addr); + ogs_freeaddrinfo(addr); + } + + if (scp_client) { + /************************* + * INDIRECT COMMUNICATION + *************************/ + build_default_discovery_parameter( + request, service_type, discovery_option); + + if (client) { + /* + * If `client` instance is avaiable, + * 3gpp-Sbi-Target-apiRoot is added to HTTP header. + */ + apiroot = ogs_sbi_client_apiroot(client); + ogs_assert(apiroot); + + ogs_sbi_header_set(request->http.headers, + OGS_SBI_CUSTOM_TARGET_APIROOT, apiroot); + + ogs_free(apiroot); + + ogs_expect_or_return_val(true == + ogs_sbi_client_send_via_scp( + scp_client, ogs_sbi_client_handler, request, xact), false); + + } else { + /* + * If no `client` instance, + * + * Discovery-*** is added to HTTP header. + */ + if (discovery_option && + discovery_option->target_nf_instance_id) { + ogs_sbi_header_set(request->http.headers, + OGS_SBI_CUSTOM_DISCOVERY_TARGET_NF_INSTANCE_ID, + discovery_option->target_nf_instance_id); + } else if (nf_instance && nf_instance->id) { + ogs_sbi_header_set(request->http.headers, + OGS_SBI_CUSTOM_DISCOVERY_TARGET_NF_INSTANCE_ID, + nf_instance->id); + } + + ogs_expect_or_return_val(true == + ogs_sbi_client_send_via_scp( + scp_client, client_discover_cb, request, xact), false); + } + + } else if (client) { + /*********************** + * DIRECT COMMUNICATION + ***********************/ + + /* If `client` instance is available, use direct communication */ + ogs_expect_or_return_val(true == + ogs_sbi_client_send_request( + client, ogs_sbi_client_handler, request, xact), false); + + } else { + /********************************************** + * No SCP and Client, Use NRF for NF-Discovery + **********************************************/ + return ogs_sbi_discover_only(xact); + } + + return true; +} + +bool ogs_sbi_discover_only(ogs_sbi_xact_t *xact) +{ + ogs_sbi_nf_instance_t *nf_instance = NULL; + + ogs_sbi_object_t *sbi_object = NULL; + ogs_sbi_service_type_e service_type = OGS_SBI_SERVICE_TYPE_NULL; + ogs_sbi_discovery_option_t *discovery_option = NULL; + + OpenAPI_nf_type_e target_nf_type = OpenAPI_nf_type_NULL; + OpenAPI_nf_type_e requester_nf_type = OpenAPI_nf_type_NULL; + + sbi_object = xact->sbi_object; + ogs_assert(sbi_object); + service_type = xact->service_type; + ogs_assert(service_type); + target_nf_type = ogs_sbi_service_type_to_nf_type(service_type); + ogs_assert(target_nf_type); + requester_nf_type = xact->requester_nf_type; + ogs_assert(requester_nf_type); + + discovery_option = xact->discovery_option; + + /* NRF NF-Instance */ + nf_instance = sbi_object->nf_type_array[OpenAPI_nf_type_NRF].nf_instance; + if (!nf_instance) { + nf_instance = ogs_sbi_nf_instance_find_by_discovery_param( + OpenAPI_nf_type_NRF, requester_nf_type, NULL); + if (nf_instance) + OGS_SBI_SETUP_NF_INSTANCE( + sbi_object->nf_type_array[OpenAPI_nf_type_NRF], nf_instance); + } + + if (nf_instance) { + bool rc; + ogs_sbi_client_t *client = NULL; + ogs_sbi_request_t *request = NULL; + + ogs_warn("Try to discover [%s]", + ogs_sbi_service_type_to_name(service_type)); + + client = NF_INSTANCE_CLIENT(nf_instance); + ogs_expect_or_return_val(client, false); + + request = ogs_nnrf_disc_build_discover( + target_nf_type, requester_nf_type, discovery_option); + ogs_expect_or_return_val(request, false); + + rc = ogs_sbi_client_send_request( + client, ogs_sbi_client_handler, request, xact); + ogs_expect(rc == true); + + ogs_sbi_request_free(request); + + return rc; + } + + ogs_error("Cannot discover [%s]", + ogs_sbi_service_type_to_name(service_type)); + + return false; +} + +bool ogs_sbi_send_request_to_nf_instance( + ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_xact_t *xact) { ogs_sbi_request_t *request = NULL; ogs_sbi_client_t *client = NULL; + ogs_sbi_object_t *sbi_object = NULL; ogs_assert(xact); @@ -67,225 +407,119 @@ bool ogs_sbi_send_request(ogs_sbi_nf_instance_t *nf_instance, ogs_freeaddrinfo(addr); } - /* ogs_sbi_xact_remove() will call ogs_sbi_request_free() - * As such, we'll use ogs_sbi_client_send_reqmem_persistent() */ ogs_expect_or_return_val(true == - ogs_sbi_scp_send_reqmem_persistent( - client, client_cb, request, xact), false); + ogs_sbi_send_request_to_client( + client, ogs_sbi_client_handler, request, xact), false); return true; } -bool ogs_sbi_discover_only( - ogs_sbi_xact_t *xact, ogs_sbi_client_cb_f client_cb) +bool ogs_sbi_send_request_to_client( + ogs_sbi_client_t *client, ogs_sbi_client_cb_f client_cb, + ogs_sbi_request_t *request, void *data) { - ogs_sbi_nf_instance_t *nf_instance = NULL; + ogs_sbi_client_t *scp_client = NULL; + char *apiroot = NULL; - ogs_sbi_object_t *sbi_object = NULL; - ogs_sbi_service_type_e service_type = OGS_SBI_SERVICE_TYPE_NULL; - ogs_sbi_discovery_option_t *discovery_option = NULL; + /* + * If the HTTP2 Server's EndPoint is known, + * 3gpp-Sbi-Target-apiRoot should always be included in the HTTP2 Request. + */ + ogs_assert(client); + ogs_assert(request); - OpenAPI_nf_type_e target_nf_type = OpenAPI_nf_type_NULL; + scp_client = NF_INSTANCE_CLIENT(ogs_sbi_self()->scp_instance); - sbi_object = xact->sbi_object; - ogs_assert(sbi_object); - service_type = xact->service_type; - ogs_assert(service_type); - target_nf_type = ogs_sbi_service_type_to_nf_type(service_type); - ogs_assert(target_nf_type); - ogs_assert(client_cb); + if (scp_client && scp_client != client) { - discovery_option = xact->discovery_option; + /************************* + * INDIRECT COMMUNICATION + *************************/ + + /* Added 3gpp-Sbi-Target-apiRoot to HTTP header */ + apiroot = ogs_sbi_client_apiroot(client); + ogs_assert(apiroot); + + ogs_sbi_header_set(request->http.headers, + OGS_SBI_CUSTOM_TARGET_APIROOT, apiroot); + + ogs_free(apiroot); + + ogs_expect_or_return_val(true == + ogs_sbi_client_send_via_scp( + scp_client, client_cb, request, data), false); + + } else { + + /*********************** + * DIRECT COMMUNICATION + ***********************/ + + /* Direct communication since `client' instance is always avaiable */ + ogs_expect_or_return_val(true == + ogs_sbi_client_send_request( + client, client_cb, request, data), false); - /* NRF NF-Instance */ - nf_instance = sbi_object->nf_type_array[OpenAPI_nf_type_NRF].nf_instance; - if (!nf_instance) { - nf_instance = ogs_sbi_nf_instance_find_by_discovery_param( - OpenAPI_nf_type_NRF, NULL); - if (nf_instance) - OGS_SBI_SETUP_NF_INSTANCE( - sbi_object->nf_type_array[OpenAPI_nf_type_NRF], nf_instance); } - if (nf_instance) { - ogs_sbi_client_t *client = NULL; - ogs_sbi_request_t *request = NULL; - - ogs_warn("Try to discover [%s]", - ogs_sbi_service_type_to_name(service_type)); - - request = ogs_nnrf_disc_build_discover( - target_nf_type, discovery_option); - ogs_expect_or_return_val(request, false); - - client = nf_instance->client; - ogs_assert(client); - - return ogs_sbi_client_send_request(client, client_cb, request, xact); - } - - ogs_error("Cannot discover [%s]", - ogs_sbi_service_type_to_name(service_type)); - - return false; + return true; } -bool ogs_sbi_discover_and_send( - ogs_sbi_xact_t *xact, ogs_sbi_client_cb_f client_cb) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - - ogs_sbi_object_t *sbi_object = NULL; - ogs_sbi_service_type_e service_type = OGS_SBI_SERVICE_TYPE_NULL; - ogs_sbi_discovery_option_t *discovery_option = NULL; - - OpenAPI_nf_type_e target_nf_type = OpenAPI_nf_type_NULL; - - sbi_object = xact->sbi_object; - ogs_assert(sbi_object); - service_type = xact->service_type; - ogs_assert(service_type); - target_nf_type = ogs_sbi_service_type_to_nf_type(service_type); - ogs_assert(target_nf_type); - ogs_assert(client_cb); - - discovery_option = xact->discovery_option; - - /* Target NF-Instance */ - nf_instance = sbi_object->service_type_array[service_type].nf_instance; - if (!nf_instance) { - nf_instance = ogs_sbi_nf_instance_find_by_discovery_param( - target_nf_type, discovery_option); - if (nf_instance) - OGS_SBI_SETUP_NF_INSTANCE( - sbi_object->service_type_array[service_type], nf_instance); - } - - if (nf_instance) { - return ogs_sbi_send_request(nf_instance, client_cb, xact); - } - - return ogs_sbi_discover_only(xact, client_cb); -} - -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; - - ogs_assert(nf_instance); - client = nf_instance->client; - ogs_assert(client); - - 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); -} - -bool ogs_nnrf_nfm_send_nf_update(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 = ogs_nnrf_nfm_build_update(); - ogs_expect_or_return_val(request, false); - - return ogs_sbi_scp_send_request(client, client->cb, request, nf_instance); -} - -bool ogs_nnrf_nfm_send_nf_de_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 = ogs_nnrf_nfm_build_de_register(); - ogs_expect_or_return_val(request, false); - - return ogs_sbi_scp_send_request(client, client->cb, request, nf_instance); -} - -bool ogs_nnrf_nfm_send_nf_profile_retrieve(ogs_sbi_nf_instance_t *nf_instance, - char *nf_instance_id, void *data) -{ - ogs_sbi_request_t *request = NULL; - ogs_sbi_client_t *client = NULL; - - ogs_assert(nf_instance); - client = nf_instance->client; - ogs_assert(client); - ogs_assert(nf_instance_id); - - request = ogs_nnrf_nfm_build_profile_retrieve(nf_instance_id); - ogs_expect_or_return_val(request, false); - - return ogs_sbi_client_send_request( - client, client->cb, request, data); -} - -bool ogs_nnrf_nfm_send_nf_status_subscribe( - ogs_sbi_subscription_data_t *subscription_data) -{ - ogs_sbi_request_t *request = NULL; - ogs_sbi_client_t *client = NULL; - - ogs_assert(subscription_data); - - request = ogs_nnrf_nfm_build_status_subscribe(subscription_data); - ogs_expect_or_return_val(request, false); - - client = subscription_data->client; - ogs_assert(client); - - return ogs_sbi_scp_send_request( - client, client->cb, request, subscription_data); -} - -bool ogs_nnrf_nfm_send_nf_status_unsubscribe( - ogs_sbi_subscription_data_t *subscription_data) -{ - ogs_sbi_request_t *request = NULL; - ogs_sbi_client_t *client = NULL; - - ogs_assert(subscription_data); - - request = ogs_nnrf_nfm_build_status_unsubscribe(subscription_data); - ogs_expect_or_return_val(request, false); - - client = subscription_data->client; - ogs_assert(client); - - return ogs_sbi_scp_send_request( - client, client->cb, request, subscription_data); -} - -bool ogs_nnrf_disc_send_nf_discover( - ogs_sbi_nf_instance_t *nf_instance, - OpenAPI_nf_type_e target_nf_type, +bool ogs_sbi_send_notification_request( + ogs_sbi_service_type_e service_type, ogs_sbi_discovery_option_t *discovery_option, - void *data) + ogs_sbi_request_t *request, void *data) { - ogs_sbi_client_t *client = NULL; - ogs_sbi_request_t *request = NULL; + ogs_sbi_client_t *client = NULL, *scp_client = NULL; + OpenAPI_nf_type_e target_nf_type = OpenAPI_nf_type_NULL; - ogs_assert(nf_instance); + ogs_assert(service_type); + target_nf_type = ogs_sbi_service_type_to_nf_type(service_type); ogs_assert(target_nf_type); + ogs_assert(request); - request = ogs_nnrf_disc_build_discover(target_nf_type, discovery_option); - ogs_expect_or_return_val(request, false); + scp_client = NF_INSTANCE_CLIENT(ogs_sbi_self()->scp_instance); + if (target_nf_type == OpenAPI_nf_type_NRF) + client = NF_INSTANCE_CLIENT(ogs_sbi_self()->nrf_instance); + else { + ogs_fatal("Not implemented[%s]", + ogs_sbi_service_type_to_name(service_type)); + ogs_assert_if_reached(); + } - client = nf_instance->client; - ogs_assert(client); + if (scp_client) { + /************************* + * INDIRECT COMMUNICATION + *************************/ + build_default_discovery_parameter( + request, service_type, discovery_option); - return ogs_sbi_client_send_request(client, client->cb, request, data); + ogs_expect_or_return_val(true == + ogs_sbi_client_send_via_scp( + scp_client, ogs_sbi_client_handler, request, data), false); + + } else if (client) { + + /*********************** + * DIRECT COMMUNICATION + ***********************/ + + /* NRF is avaiable */ + ogs_expect_or_return_val(true == + ogs_sbi_client_send_request( + client, ogs_sbi_client_handler, request, data), false); + + + } else { + ogs_fatal("[%s:%s] Cannot send request [%s:%s:%s]", + client ? "CLIENT" : "No-CLIENT", + scp_client ? "SCP" : "No-SCP", + ogs_sbi_service_type_to_name(service_type), + request->h.service.name, request->h.api.version); + ogs_assert_if_reached(); + } + + return true; } bool ogs_sbi_send_response(ogs_sbi_stream_t *stream, int status) @@ -299,5 +533,77 @@ bool ogs_sbi_send_response(ogs_sbi_stream_t *stream, int status) response = ogs_sbi_build_response(&sendmsg, status); ogs_expect_or_return_val(response, false); + return ogs_sbi_server_send_response(stream, response); } + +static void build_default_discovery_parameter( + ogs_sbi_request_t *request, + ogs_sbi_service_type_e service_type, + ogs_sbi_discovery_option_t *discovery_option) +{ + OpenAPI_nf_type_e target_nf_type = OpenAPI_nf_type_NULL; + OpenAPI_nf_type_e requester_nf_type = OpenAPI_nf_type_NULL; + ogs_sbi_discovery_option_t *local_discovery_option = NULL; + + ogs_assert(service_type); + target_nf_type = ogs_sbi_service_type_to_nf_type(service_type); + ogs_assert(target_nf_type); + requester_nf_type = NF_INSTANCE_TYPE(ogs_sbi_self()->nf_instance); + ogs_assert(requester_nf_type); + + /* + * Insert one service-name in the discovery option + * in the function below. + * + * - ogs_sbi_xact_add() + * - ogs_sbi_send_notification_request() + */ + if (!discovery_option) { + local_discovery_option = ogs_sbi_discovery_option_new(); + ogs_assert(local_discovery_option); + + discovery_option = local_discovery_option; + } + + if (!discovery_option->num_of_service_names) { + ogs_sbi_discovery_option_add_service_names( + discovery_option, + (char *)ogs_sbi_service_type_to_name(service_type)); + } + + ogs_sbi_header_set(request->http.headers, + OGS_SBI_CUSTOM_DISCOVERY_TARGET_NF_TYPE, + OpenAPI_nf_type_ToString(target_nf_type)); + + /* Instead of Discovery-requester-nf-type, + * Open5GS uses User-Agent for requester-nf-type */ + + if (discovery_option) { + if (discovery_option->requester_nf_instance_id) { + ogs_sbi_header_set(request->http.headers, + OGS_SBI_CUSTOM_DISCOVERY_REQUESTER_NF_INSTANCE_ID, + discovery_option->requester_nf_instance_id); + } + if (ogs_sbi_self()->discovery_config. + no_service_names == false && + discovery_option->num_of_service_names) { + + /* send array items separated by a comma */ + char *v = ogs_sbi_discovery_option_build_service_names( + discovery_option); + if (v) { + ogs_sbi_header_set(request->http.headers, + OGS_SBI_CUSTOM_DISCOVERY_SERVICE_NAMES, v); + ogs_free(v); + } else { + ogs_warn("invalid service names failed[%d:%s]", + discovery_option->num_of_service_names, + discovery_option->service_names[0]); + } + } + } + + if (local_discovery_option) + ogs_sbi_discovery_option_free(local_discovery_option); +} diff --git a/lib/sbi/path.h b/lib/sbi/path.h index 3023406c9..0a45a5d8b 100644 --- a/lib/sbi/path.h +++ b/lib/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. * @@ -26,30 +26,22 @@ extern "C" { #endif -bool ogs_sbi_send_request(ogs_sbi_nf_instance_t *nf_instance, - ogs_sbi_client_cb_f client_cb, ogs_sbi_xact_t *xact); -bool ogs_sbi_discover_only( - ogs_sbi_xact_t *xact, ogs_sbi_client_cb_f client_cb); -bool ogs_sbi_discover_and_send( - ogs_sbi_xact_t *xact, ogs_sbi_client_cb_f client_cb); +int ogs_sbi_server_handler(ogs_sbi_request_t *request, void *data); +int ogs_sbi_client_handler( + int status, ogs_sbi_response_t *response, void *data); -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, - char *nf_instance_id, void *data); +bool ogs_sbi_discover_and_send(ogs_sbi_xact_t *xact); +bool ogs_sbi_discover_only(ogs_sbi_xact_t *xact); -bool ogs_nnrf_nfm_send_nf_status_subscribe( - ogs_sbi_subscription_data_t *subscription_data); -bool ogs_nnrf_nfm_send_nf_status_unsubscribe( - ogs_sbi_subscription_data_t *subscription_data); - -bool ogs_nnrf_disc_send_nf_discover( - ogs_sbi_nf_instance_t *nf_instance, - OpenAPI_nf_type_e target_nf_type, +bool ogs_sbi_send_request_to_nf_instance( + ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_xact_t *xact); +bool ogs_sbi_send_request_to_client( + ogs_sbi_client_t *client, ogs_sbi_client_cb_f client_cb, + ogs_sbi_request_t *request, void *data); +bool ogs_sbi_send_notification_request( + ogs_sbi_service_type_e service_type, ogs_sbi_discovery_option_t *discovery_option, - void *data); - + ogs_sbi_request_t *request, void *data); #define ogs_sbi_send_http_status_no_content(__sTREAM) \ ogs_sbi_send_response(__sTREAM, OGS_SBI_HTTP_STATUS_NO_CONTENT) diff --git a/misc/netconf.sh b/misc/netconf.sh index 1108b7de7..78da22d22 100755 --- a/misc/netconf.sh +++ b/misc/netconf.sh @@ -38,6 +38,8 @@ else ifconfig lo0 alias 127.0.0.19 netmask 255.255.255.255 ifconfig lo0 alias 127.0.0.20 netmask 255.255.255.255 ifconfig lo0 alias 127.0.1.10 netmask 255.255.255.255 + ifconfig lo0 alias 127.0.1.11 netmask 255.255.255.255 + ifconfig lo0 alias 127.0.1.12 netmask 255.255.255.255 if [ "$SYSTEM" = "Darwin" ]; then if ! test -f /etc/pf.anchors/org.open5gs; then sudo sh -c "echo 'nat on {en0} from 10.45.0.0/16 to any -> {en0}' > /etc/pf.anchors/org.open5gs" diff --git a/src/amf/amf-sm.c b/src/amf/amf-sm.c index 632d2a384..3c751112e 100644 --- a/src/amf/amf-sm.c +++ b/src/amf/amf-sm.c @@ -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) - ogs_nnrf_handle_nf_status_notify(stream, &sbi_message); + ogs_nnrf_nfm_handle_nf_status_notify(stream, &sbi_message); break; DEFAULT @@ -296,7 +296,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) 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) { - ogs_nnrf_handle_nf_status_subscribe( + ogs_nnrf_nfm_handle_nf_status_subscribe( subscription_data, &sbi_message); } else { ogs_error("[%s] HTTP response error [%d]", diff --git a/src/amf/context.c b/src/amf/context.c index 0b01c68d0..064a3cb8a 100644 --- a/src/amf/context.c +++ b/src/amf/context.c @@ -1922,6 +1922,7 @@ static bool check_smf_info(ogs_sbi_nf_info_t *nf_info, void *context); void amf_sbi_select_nf( ogs_sbi_object_t *sbi_object, ogs_sbi_service_type_e service_type, + OpenAPI_nf_type_e requester_nf_type, ogs_sbi_discovery_option_t *discovery_option) { OpenAPI_nf_type_e target_nf_type = OpenAPI_nf_type_NULL; @@ -1933,11 +1934,12 @@ void amf_sbi_select_nf( ogs_assert(service_type); target_nf_type = ogs_sbi_service_type_to_nf_type(service_type); ogs_assert(target_nf_type); + ogs_assert(requester_nf_type); switch(sbi_object->type) { case OGS_SBI_OBJ_UE_TYPE: nf_instance = ogs_sbi_nf_instance_find_by_discovery_param( - target_nf_type, discovery_option); + target_nf_type, requester_nf_type, discovery_option); if (nf_instance) OGS_SBI_SETUP_NF_INSTANCE( sbi_object->service_type_array[service_type], nf_instance); @@ -1948,7 +1950,9 @@ void amf_sbi_select_nf( ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) { if (ogs_sbi_discovery_param_is_matched( - nf_instance, target_nf_type, discovery_option) == false) + nf_instance, + target_nf_type, requester_nf_type, discovery_option) == + false) continue; nf_info = ogs_sbi_nf_info_find( diff --git a/src/amf/context.h b/src/amf/context.h index b4e7db868..b29ea9a28 100644 --- a/src/amf/context.h +++ b/src/amf/context.h @@ -741,6 +741,7 @@ amf_sess_t *amf_sess_cycle(amf_sess_t *sess); void amf_sbi_select_nf( ogs_sbi_object_t *sbi_object, ogs_sbi_service_type_e service_type, + OpenAPI_nf_type_e requester_nf_type, ogs_sbi_discovery_option_t *discovery_option); #define AMF_SESSION_SYNC_DONE(__aMF, __sTATE) \ diff --git a/src/amf/event.h b/src/amf/event.h index 15091c3a0..0a53b467d 100644 --- a/src/amf/event.h +++ b/src/amf/event.h @@ -83,6 +83,8 @@ typedef struct amf_event_s { ogs_timer_t *timer; } amf_event_t; +OGS_STATIC_ASSERT(OGS_EVENT_SIZE >= sizeof(amf_event_t)); + amf_event_t *amf_event_new(int id); const char *amf_event_get_name(amf_event_t *e); diff --git a/src/amf/gmm-handler.c b/src/amf/gmm-handler.c index d1a1929f4..d7528f37f 100644 --- a/src/amf/gmm-handler.c +++ b/src/amf/gmm-handler.c @@ -1070,8 +1070,12 @@ int gmm_handle_ul_nas_transport(amf_ue_t *amf_ue, nf_instance = sess->sbi. service_type_array[service_type].nf_instance; if (!nf_instance) { - nf_instance = - ogs_sbi_nf_instance_find_by_service_type(service_type); + OpenAPI_nf_type_e requester_nf_type = + NF_INSTANCE_TYPE(ogs_sbi_self()->nf_instance); + ogs_assert(requester_nf_type); + + nf_instance = ogs_sbi_nf_instance_find_by_service_type( + service_type, requester_nf_type); if (nf_instance) OGS_SBI_SETUP_NF_INSTANCE( sess->sbi.service_type_array[service_type], diff --git a/src/amf/nausf-build.c b/src/amf/nausf-build.c index 1cc734b1d..174e11c2a 100644 --- a/src/amf/nausf-build.c +++ b/src/amf/nausf-build.c @@ -50,7 +50,10 @@ ogs_sbi_request_t *amf_nausf_auth_build_authenticate( AuthenticationInfo.supi_or_suci = amf_ue->suci; AuthenticationInfo.serving_network_name = ogs_serving_network_name_from_plmn_id(&amf_ue->nr_tai.plmn_id); - ogs_expect_or_return_val(AuthenticationInfo.serving_network_name, NULL); + if (!AuthenticationInfo.serving_network_name) { + ogs_error("No serving_network_name"); + goto end; + } if (auts) { memset(&ResynchronizationInfo, 0, sizeof(ResynchronizationInfo)); @@ -70,7 +73,9 @@ ogs_sbi_request_t *amf_nausf_auth_build_authenticate( request = ogs_sbi_build_request(&message); ogs_expect(request); - ogs_free(AuthenticationInfo.serving_network_name); +end: + if (AuthenticationInfo.serving_network_name) + ogs_free(AuthenticationInfo.serving_network_name); return request; } @@ -93,7 +98,10 @@ ogs_sbi_request_t *amf_nausf_auth_build_authenticate_confirmation( message.h.uri = amf_ue->confirmation_url_for_5g_aka; ConfirmationData = ogs_calloc(1, sizeof(*ConfirmationData)); - ogs_expect_or_return_val(ConfirmationData, NULL); + if (!ConfirmationData) { + ogs_error("No ConfirmationData"); + goto end; + } ogs_hex_to_ascii(amf_ue->xres_star, sizeof(amf_ue->xres_star), xres_star_string, sizeof(xres_star_string)); @@ -105,7 +113,9 @@ ogs_sbi_request_t *amf_nausf_auth_build_authenticate_confirmation( request = ogs_sbi_build_request(&message); ogs_expect(request); - ogs_free(ConfirmationData); +end: + if (ConfirmationData) + ogs_free(ConfirmationData); return request; } diff --git a/src/amf/nnrf-build.c b/src/amf/nnrf-build.c index 94864acf0..1031c51e7 100644 --- a/src/amf/nnrf-build.c +++ b/src/amf/nnrf-build.c @@ -50,6 +50,7 @@ ogs_sbi_request_t *amf_nnrf_disc_build_discover( message.param.discovery_option = discovery_option; request = ogs_sbi_build_request(&message); + ogs_expect(request); return request; } diff --git a/src/amf/nnrf-handler.c b/src/amf/nnrf-handler.c index 27971dbb3..858e9ef4d 100644 --- a/src/amf/nnrf-handler.c +++ b/src/amf/nnrf-handler.c @@ -28,6 +28,7 @@ void amf_nnrf_handle_nf_discover( ogs_sbi_nf_instance_t *nf_instance = NULL; ogs_sbi_object_t *sbi_object = NULL; ogs_sbi_service_type_e service_type = OGS_SBI_SERVICE_TYPE_NULL; + OpenAPI_nf_type_e requester_nf_type = OpenAPI_nf_type_NULL; ogs_sbi_discovery_option_t *discovery_option = NULL; OpenAPI_search_result_t *SearchResult = NULL; @@ -38,6 +39,8 @@ void amf_nnrf_handle_nf_discover( ogs_assert(sbi_object); service_type = xact->service_type; ogs_assert(service_type); + requester_nf_type = xact->requester_nf_type; + ogs_assert(requester_nf_type); discovery_option = xact->discovery_option; @@ -47,9 +50,10 @@ void amf_nnrf_handle_nf_discover( return; } - ogs_nnrf_handle_nf_discover_search_result(SearchResult); + ogs_nnrf_disc_handle_nf_discover_search_result(SearchResult); - amf_sbi_select_nf(sbi_object, service_type, discovery_option); + amf_sbi_select_nf(sbi_object, + service_type, requester_nf_type, discovery_option); nf_instance = sbi_object->service_type_array[service_type].nf_instance; if (!nf_instance) { diff --git a/src/amf/nnssf-build.c b/src/amf/nnssf-build.c index dcbe90136..76e613451 100644 --- a/src/amf/nnssf-build.c +++ b/src/amf/nnssf-build.c @@ -35,9 +35,15 @@ ogs_sbi_request_t *amf_nnssf_nsselection_build_get( (char *)OGS_SBI_RESOURCE_NAME_NETWORK_SLICE_INFORMATION; message.param.nf_id = NF_INSTANCE_ID(ogs_sbi_self()->nf_instance); - ogs_assert(message.param.nf_id); + if (!message.param.nf_id) { + ogs_error("No nf_id"); + goto end; + } message.param.nf_type = NF_INSTANCE_TYPE(ogs_sbi_self()->nf_instance); - ogs_assert(message.param.nf_type); + if (!message.param.nf_type) { + ogs_error("No nf_type"); + goto end; + } message.param.slice_info_request_for_pdu_session_presence = true; message.param.roaming_indication = OpenAPI_roaming_indication_NON_ROAMING; @@ -45,7 +51,9 @@ ogs_sbi_request_t *amf_nnssf_nsselection_build_get( sizeof(message.param.s_nssai)); request = ogs_sbi_build_request(&message); - ogs_assert(request); + ogs_expect(request); + +end: return request; } diff --git a/src/amf/nnssf-handler.c b/src/amf/nnssf-handler.c index bb42398ae..84ed75380 100644 --- a/src/amf/nnssf-handler.c +++ b/src/amf/nnssf-handler.c @@ -26,7 +26,7 @@ int amf_nnssf_nsselection_handle_get( { amf_ue_t *amf_ue = NULL; - ogs_sbi_client_t *client = NULL; + ogs_sbi_client_t *client = NULL, *scp_client = NULL; ogs_sockaddr_t *addr = NULL; OpenAPI_authorized_network_slice_info_t *AuthorizedNetworkSliceInfo = NULL; @@ -78,28 +78,42 @@ int amf_nnssf_nsselection_handle_get( sess->nssf.nrf.id = ogs_strdup(NsiInformation->nrf_id); ogs_assert(sess->nssf.nrf.id); - addr = ogs_sbi_getaddr_from_uri(NsiInformation->nrf_id); - if (!addr) { - ogs_error("[%s:%d] Invalid URI [%s]", - amf_ue->supi, sess->psi, NsiInformation->nrf_id); - ogs_assert(OGS_OK == - nas_5gs_send_gmm_reject_from_sbi( - amf_ue, OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR)); - return OGS_ERROR;; + scp_client = NF_INSTANCE_CLIENT(ogs_sbi_self()->scp_instance); + + if (scp_client) { + amf_nsmf_pdusession_sm_context_param_t param; + + memset(¶m, 0, sizeof(param)); + param.nrf_uri.nrf.id = sess->nssf.nrf.id; + + amf_sess_sbi_discover_and_send( + OGS_SBI_SERVICE_TYPE_NSMF_PDUSESSION, NULL, + amf_nsmf_pdusession_build_create_sm_context, + sess, AMF_CREATE_SM_CONTEXT_NO_STATE, ¶m); + } else { + addr = ogs_sbi_getaddr_from_uri(NsiInformation->nrf_id); + if (!addr) { + ogs_error("[%s:%d] Invalid URI [%s]", + amf_ue->supi, sess->psi, NsiInformation->nrf_id); + ogs_assert(OGS_OK == + nas_5gs_send_gmm_reject_from_sbi( + amf_ue, OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR)); + return OGS_ERROR;; + } + + client = ogs_sbi_client_find(addr); + if (!client) { + client = ogs_sbi_client_add(addr); + ogs_assert(client); + } + + OGS_SBI_SETUP_CLIENT(&sess->nssf.nrf, client); + + ogs_freeaddrinfo(addr); + + ogs_assert(true == amf_sess_sbi_discover_by_nsi( + sess, OGS_SBI_SERVICE_TYPE_NSMF_PDUSESSION, NULL)); } - client = ogs_sbi_client_find(addr); - if (!client) { - client = ogs_sbi_client_add(addr); - ogs_assert(client); - } - - OGS_SBI_SETUP_CLIENT(&sess->nssf.nrf, client); - - ogs_freeaddrinfo(addr); - - ogs_assert(true == amf_sess_sbi_discover_by_nsi( - sess, OGS_SBI_SERVICE_TYPE_NSMF_PDUSESSION, NULL)); - return OGS_OK; } diff --git a/src/amf/npcf-build.c b/src/amf/npcf-build.c index d57ddbc05..aa5ccd861 100644 --- a/src/amf/npcf-build.c +++ b/src/amf/npcf-build.c @@ -49,7 +49,10 @@ ogs_sbi_request_t *amf_npcf_am_policy_control_build_create( memset(&PolicyAssociationRequest, 0, sizeof(PolicyAssociationRequest)); server = ogs_list_first(&ogs_sbi_self()->server_list); - ogs_expect_or_return_val(server, NULL); + if (!server) { + ogs_error("No server"); + goto end; + } memset(&header, 0, sizeof(header)); header.service.name = (char *)OGS_SBI_SERVICE_NAME_NAMF_CALLBACK; @@ -59,7 +62,10 @@ ogs_sbi_request_t *amf_npcf_am_policy_control_build_create( (char *)OGS_SBI_RESOURCE_NAME_AM_POLICY_NOTIFY; PolicyAssociationRequest.notification_uri = ogs_sbi_server_uri(server, &header); - ogs_expect_or_return_val(PolicyAssociationRequest.notification_uri, NULL); + if (!PolicyAssociationRequest.notification_uri) { + ogs_error("No notifiation_uri"); + goto end; + } PolicyAssociationRequest.supi = amf_ue->supi; @@ -67,7 +73,10 @@ ogs_sbi_request_t *amf_npcf_am_policy_control_build_create( if (amf_ue->msisdn[0]) { PolicyAssociationRequest.gpsi = ogs_msprintf("%s-%s", OGS_ID_GPSI_TYPE_MSISDN, amf_ue->msisdn[0]); - ogs_assert(PolicyAssociationRequest.gpsi); + if (!PolicyAssociationRequest.gpsi) { + ogs_error("No gpsi"); + goto end; + } } } @@ -77,20 +86,31 @@ ogs_sbi_request_t *amf_npcf_am_policy_control_build_create( memset(&ueLocation, 0, sizeof(ueLocation)); ueLocation.nr_location = ogs_sbi_build_nr_location( &amf_ue->nr_tai, &amf_ue->nr_cgi); - ogs_expect_or_return_val(ueLocation.nr_location, NULL); + if (!ueLocation.nr_location) { + ogs_error("No ueLocation.nr_location"); + goto end; + } ueLocation.nr_location->ue_location_timestamp = ogs_sbi_gmtime_string(amf_ue->ue_location_timestamp); - ogs_expect_or_return_val( - ueLocation.nr_location->ue_location_timestamp, NULL); + if (!ueLocation.nr_location->ue_location_timestamp) { + ogs_error("No ueLocation.nr_location->ue_location_timestamp"); + goto end; + } PolicyAssociationRequest.user_loc = &ueLocation; PolicyAssociationRequest.time_zone = ogs_sbi_timezone_string(ogs_timezone()); - ogs_expect_or_return_val(PolicyAssociationRequest.time_zone, NULL); + if (!PolicyAssociationRequest.time_zone) { + ogs_error("No time_zone"); + goto end; + } PolicyAssociationRequest.serving_plmn = ogs_sbi_build_plmn_id_nid(&amf_ue->nr_tai.plmn_id); - ogs_expect_or_return_val(PolicyAssociationRequest.serving_plmn, NULL); + if (!PolicyAssociationRequest.serving_plmn) { + ogs_error("No serving_plmn"); + goto end; + } PolicyAssociationRequest.rat_type = amf_ue_rat_type(amf_ue); @@ -115,7 +135,10 @@ ogs_sbi_request_t *amf_npcf_am_policy_control_build_create( for (i = 0; i < amf_ue->allowed_nssai.num_of_s_nssai; i++) { struct OpenAPI_snssai_s *Snssai = ogs_calloc(1, sizeof(*Snssai)); - ogs_expect_or_return_val(Snssai, NULL); + if (!Snssai) { + ogs_error("No Snssai"); + goto end; + } Snssai->sst = amf_ue->allowed_nssai.s_nssai[i].sst; Snssai->sd = ogs_s_nssai_sd_to_string( @@ -130,22 +153,31 @@ ogs_sbi_request_t *amf_npcf_am_policy_control_build_create( OpenAPI_list_free(AllowedSnssais); PolicyAssociationRequest.guami = ogs_sbi_build_guami(amf_ue->guami); - ogs_expect_or_return_val(PolicyAssociationRequest.guami, NULL); + if (!PolicyAssociationRequest.guami) { + ogs_error("No guami"); + goto end; + } PolicyAssociationRequest.service_name = (char *)OGS_SBI_SERVICE_NAME_NAMF_CALLBACK; PolicyAssociationRequest.supp_feat = ogs_uint64_to_string(amf_ue->am_policy_control_features); - ogs_expect_or_return_val(PolicyAssociationRequest.supp_feat, NULL); + if (!PolicyAssociationRequest.supp_feat) { + ogs_error("No supp_feat"); + goto end; + } message.PolicyAssociationRequest = &PolicyAssociationRequest; request = ogs_sbi_build_request(&message); ogs_expect(request); - ogs_free(PolicyAssociationRequest.notification_uri); - ogs_free(PolicyAssociationRequest.supp_feat); +end: + if (PolicyAssociationRequest.notification_uri) + ogs_free(PolicyAssociationRequest.notification_uri); + if (PolicyAssociationRequest.supp_feat) + ogs_free(PolicyAssociationRequest.supp_feat); if (PolicyAssociationRequest.gpsi) ogs_free(PolicyAssociationRequest.gpsi); diff --git a/src/amf/nsmf-build.c b/src/amf/nsmf-build.c index a5a2b0a50..359510b9f 100644 --- a/src/amf/nsmf-build.c +++ b/src/amf/nsmf-build.c @@ -22,6 +22,7 @@ ogs_sbi_request_t *amf_nsmf_pdusession_build_create_sm_context( amf_sess_t *sess, void *data) { + amf_nsmf_pdusession_sm_context_param_t *param = data; ogs_sbi_message_t message; ogs_sbi_request_t *request = NULL; @@ -53,11 +54,17 @@ ogs_sbi_request_t *amf_nsmf_pdusession_build_create_sm_context( SmContextCreateData.serving_nf_id = NF_INSTANCE_ID(ogs_sbi_self()->nf_instance); - ogs_expect_or_return_val(SmContextCreateData.serving_nf_id, NULL); + if (!SmContextCreateData.serving_nf_id) { + ogs_error("No serving_nf_id"); + goto end; + } SmContextCreateData.serving_network = ogs_sbi_build_plmn_id_nid(&amf_ue->nr_tai.plmn_id); - ogs_expect_or_return_val(SmContextCreateData.serving_network, NULL); + if (!SmContextCreateData.serving_nf_id) { + ogs_error("No serving_network"); + goto end; + } SmContextCreateData.supi = amf_ue->supi; SmContextCreateData.pei = amf_ue->pei; @@ -65,12 +72,18 @@ ogs_sbi_request_t *amf_nsmf_pdusession_build_create_sm_context( if (amf_ue->msisdn[0]) { SmContextCreateData.gpsi = ogs_msprintf("%s-%s", OGS_ID_GPSI_TYPE_MSISDN, amf_ue->msisdn[0]); - ogs_expect_or_return_val(SmContextCreateData.gpsi, NULL); + if (!SmContextCreateData.gpsi) { + ogs_error("No gpsi"); + goto end; + } } } SmContextCreateData.is_pdu_session_id = true; SmContextCreateData.pdu_session_id = sess->psi; - ogs_expect_or_return_val(sess->dnn, NULL); + if (!SmContextCreateData.pdu_session_id) { + ogs_error("No pdu_session_id"); + goto end; + } SmContextCreateData.dnn = sess->dnn; memset(&sNssai, 0, sizeof(sNssai)); @@ -86,7 +99,10 @@ ogs_sbi_request_t *amf_nsmf_pdusession_build_create_sm_context( } SmContextCreateData.guami = ogs_sbi_build_guami(amf_ue->guami); - ogs_expect_or_return_val(SmContextCreateData.guami, NULL); + if (!SmContextCreateData.guami) { + ogs_error("No guami"); + goto end; + } SmContextCreateData.an_type = amf_ue->nas.access_type; memset(&header, 0, sizeof(header)); @@ -96,10 +112,16 @@ ogs_sbi_request_t *amf_nsmf_pdusession_build_create_sm_context( header.resource.component[1] = (char *)OGS_SBI_RESOURCE_NAME_SM_CONTEXT_STATUS; header.resource.component[2] = ogs_msprintf("%d", sess->psi); - ogs_expect_or_return_val(header.resource.component[2], NULL); + if (!header.resource.component[2]) { + ogs_error("No header.resource.component[2]"); + goto end; + } server = ogs_list_first(&ogs_sbi_self()->server_list); - ogs_expect_or_return_val(server, NULL); + if (!server) { + ogs_error("No server"); + goto end; + } SmContextCreateData.sm_context_status_uri = ogs_sbi_server_uri(server, &header); @@ -111,19 +133,30 @@ ogs_sbi_request_t *amf_nsmf_pdusession_build_create_sm_context( memset(&ueLocation, 0, sizeof(ueLocation)); ueLocation.nr_location = ogs_sbi_build_nr_location( &amf_ue->nr_tai, &amf_ue->nr_cgi); - ogs_expect_or_return_val(ueLocation.nr_location, NULL); + if (!ueLocation.nr_location) { + ogs_error("No ueLocation.nr_location"); + goto end; + } ueLocation.nr_location->ue_location_timestamp = ogs_sbi_gmtime_string(amf_ue->ue_location_timestamp); - ogs_expect_or_return_val( - ueLocation.nr_location->ue_location_timestamp, NULL); + if (!ueLocation.nr_location->ue_location_timestamp) { + ogs_error("No ue_location_timestamp"); + goto end; + } SmContextCreateData.ue_location = &ueLocation; SmContextCreateData.ue_time_zone = ogs_sbi_timezone_string(ogs_timezone()); - ogs_expect_or_return_val(SmContextCreateData.ue_time_zone, NULL); + if (!SmContextCreateData.ue_time_zone) { + ogs_error("No ue_time_zone"); + goto end; + } pcf_nf_instance = amf_ue->sbi.service_type_array[ OGS_SBI_SERVICE_TYPE_NPCF_AM_POLICY_CONTROL].nf_instance; - ogs_expect_or_return_val(pcf_nf_instance, NULL); + if (!pcf_nf_instance) { + ogs_error("No pcf_nf_instance"); + goto end; + } SmContextCreateData.pcf_id = pcf_nf_instance->id; message.SmContextCreateData = &SmContextCreateData; @@ -140,13 +173,26 @@ ogs_sbi_request_t *amf_nsmf_pdusession_build_create_sm_context( message.http.accept = (char *)(OGS_SBI_CONTENT_JSON_TYPE "," OGS_SBI_CONTENT_NGAP_TYPE "," OGS_SBI_CONTENT_PROBLEM_TYPE); + message.http.custom.callback = + (char *)OGS_SBI_CALLBACK_NSMF_PDUSESSION_STATUS_NOTIFY; + + if (param && param->nrf_uri.nrf.id) { + message.http.custom.nrf_uri = + ogs_msprintf("%s: \"%s\"", + OGS_SBI_SERVICE_NAME_NNRF_DISC, param->nrf_uri.nrf.id); + } + request = ogs_sbi_build_request(&message); ogs_expect(request); +end: + if (SmContextCreateData.serving_network) ogs_sbi_free_plmn_id_nid(SmContextCreateData.serving_network); - ogs_free(SmContextCreateData.sm_context_status_uri); - ogs_free(header.resource.component[2]); + if (SmContextCreateData.sm_context_status_uri) + ogs_free(SmContextCreateData.sm_context_status_uri); + if (header.resource.component[2]) + ogs_free(header.resource.component[2]); if (sNssai.sd) ogs_free(sNssai.sd); if (hplmnSnssai.sd) @@ -163,6 +209,9 @@ ogs_sbi_request_t *amf_nsmf_pdusession_build_create_sm_context( if (SmContextCreateData.ue_time_zone) ogs_free(SmContextCreateData.ue_time_zone); + if (message.http.custom.nrf_uri) + ogs_free(message.http.custom.nrf_uri); + return request; } @@ -214,7 +263,10 @@ ogs_sbi_request_t *amf_nsmf_pdusession_build_update_sm_context( } if (param->n2smbuf) { - ogs_expect_or_return_val(param->n2SmInfoType, NULL); + if (!param->n2SmInfoType) { + ogs_error("No n2SmInfoType"); + goto end; + } SmContextUpdateData.n2_sm_info_type = param->n2SmInfoType; SmContextUpdateData.n2_sm_info = &n2SmInfo; @@ -236,7 +288,10 @@ ogs_sbi_request_t *amf_nsmf_pdusession_build_update_sm_context( if (param->TargetID) { SmContextUpdateData.target_id = amf_nsmf_pdusession_build_target_id(param->TargetID); - ogs_expect_or_return_val(SmContextUpdateData.target_id, NULL); + if (!SmContextUpdateData.target_id) { + ogs_error("No target_id"); + goto end; + } } if (param->ngApCause.group) { @@ -250,18 +305,26 @@ ogs_sbi_request_t *amf_nsmf_pdusession_build_update_sm_context( if (param->ue_location) { ueLocation.nr_location = ogs_sbi_build_nr_location( &amf_ue->nr_tai, &amf_ue->nr_cgi); - ogs_expect_or_return_val(ueLocation.nr_location, NULL); + if (!ueLocation.nr_location) { + ogs_error("No ueLocation.nr_location"); + goto end; + } ueLocation.nr_location->ue_location_timestamp = ogs_sbi_gmtime_string(amf_ue->ue_location_timestamp); - ogs_expect_or_return_val( - ueLocation.nr_location->ue_location_timestamp, NULL); + if (!ueLocation.nr_location->ue_location_timestamp) { + ogs_error("No ueLocation.nr_location->ue_location_timestamp"); + goto end; + } SmContextUpdateData.ue_location = &ueLocation; } if (param->ue_timezone) { SmContextUpdateData.ue_time_zone = ogs_sbi_timezone_string(ogs_timezone()); - ogs_expect_or_return_val(SmContextUpdateData.ue_time_zone, NULL); + if (!SmContextUpdateData.ue_time_zone) { + ogs_error("No SmContextUpdateData.ue_time_zone"); + goto end; + } } if (param->release) { @@ -273,6 +336,7 @@ ogs_sbi_request_t *amf_nsmf_pdusession_build_update_sm_context( request = ogs_sbi_build_request(&message); ogs_expect(request); +end: if (ueLocation.nr_location) { if (ueLocation.nr_location->ue_location_timestamp) ogs_free(ueLocation.nr_location->ue_location_timestamp); @@ -283,7 +347,6 @@ ogs_sbi_request_t *amf_nsmf_pdusession_build_update_sm_context( if (SmContextUpdateData.target_id) amf_nsmf_pdusession_free_target_id(SmContextUpdateData.target_id); - return request; } @@ -333,21 +396,30 @@ ogs_sbi_request_t *amf_nsmf_pdusession_build_release_sm_context( memset(&ueLocation, 0, sizeof(ueLocation)); ueLocation.nr_location = ogs_sbi_build_nr_location( &amf_ue->nr_tai, &amf_ue->nr_cgi); - ogs_expect_or_return_val(ueLocation.nr_location, NULL); + if (!ueLocation.nr_location) { + ogs_error("No ueLocation.nr_location"); + goto end; + } ueLocation.nr_location->ue_location_timestamp = ogs_sbi_gmtime_string(amf_ue->ue_location_timestamp); - ogs_expect_or_return_val( - ueLocation.nr_location->ue_location_timestamp, NULL); + if (!ueLocation.nr_location->ue_location_timestamp) { + ogs_error("No ueLocation.nr_location->ue_location_timestamp"); + goto end; + } SmContextReleaseData.ue_location = &ueLocation; SmContextReleaseData.ue_time_zone = ogs_sbi_timezone_string(ogs_timezone()); - ogs_expect_or_return_val(SmContextReleaseData.ue_time_zone, NULL); + if (!SmContextReleaseData.ue_time_zone) { + ogs_error("No SmContextReleaseData.ue_time_zone"); + goto end; + } message.SmContextReleaseData = &SmContextReleaseData; request = ogs_sbi_build_request(&message); ogs_expect(request); +end: if (ueLocation.nr_location) { if (ueLocation.nr_location->ue_location_timestamp) ogs_free(ueLocation.nr_location->ue_location_timestamp); @@ -445,21 +517,40 @@ OpenAPI_ng_ran_target_id_t *amf_nsmf_pdusession_build_target_id( } targetId = ogs_calloc(1, sizeof(*targetId)); - ogs_expect_or_return_val(targetId, NULL); + if (!targetId) { + ogs_error("No targetId"); + return NULL; + } targetId->ran_node_id = ranNodeId = ogs_calloc(1, sizeof(*ranNodeId));; - ogs_expect_or_return_val(ranNodeId, NULL); + if (!targetId->ran_node_id) { + ogs_error("No targetId->ran_node_id"); + amf_nsmf_pdusession_free_target_id(targetId); + return NULL; + } memcpy(&plmn_id, globalGNB_ID->pLMNIdentity.buf, OGS_PLMN_ID_LEN); ranNodeId->plmn_id = ogs_sbi_build_plmn_id(&plmn_id); - ogs_expect_or_return_val(ranNodeId->plmn_id, NULL); + if (!ranNodeId->plmn_id) { + ogs_error("No ranNodeId->plmn_id"); + amf_nsmf_pdusession_free_target_id(targetId); + return NULL; + } ranNodeId->g_nb_id = gNbId = ogs_calloc(1, sizeof(*gNbId)); - ogs_expect_or_return_val(gNbId, NULL); + if (!ranNodeId->g_nb_id) { + ogs_error("No ranNodeId->g_nb_id"); + amf_nsmf_pdusession_free_target_id(targetId); + return NULL; + } gNbId->g_nb_value = ogs_calloc( 1, OGS_KEYSTRLEN(globalGNB_ID->gNB_ID.choice.gNB_ID.size)); - ogs_expect_or_return_val(gNbId->g_nb_value, NULL); + if (!gNbId->g_nb_value) { + ogs_error("No gNbId->g_nb_value"); + amf_nsmf_pdusession_free_target_id(targetId); + return NULL; + } ogs_hex_to_ascii( globalGNB_ID->gNB_ID.choice.gNB_ID.buf, globalGNB_ID->gNB_ID.choice.gNB_ID.size, @@ -468,13 +559,25 @@ OpenAPI_ng_ran_target_id_t *amf_nsmf_pdusession_build_target_id( gNbId->bit_length = 32 - globalGNB_ID->gNB_ID.choice.gNB_ID.bits_unused; targetId->tai = tai = ogs_calloc(1, sizeof(*tai));; - ogs_expect_or_return_val(tai, NULL); + if (!targetId->tai) { + ogs_error("No targetId->tai"); + amf_nsmf_pdusession_free_target_id(targetId); + return NULL; + } ogs_ngap_ASN_to_5gs_tai(&targetRANNodeID->selectedTAI, &nr_tai); tai->plmn_id = ogs_sbi_build_plmn_id(&nr_tai.plmn_id); - ogs_expect_or_return_val(tai->plmn_id, NULL); + if (!tai->plmn_id) { + ogs_error("No tai->plmn_id"); + amf_nsmf_pdusession_free_target_id(targetId); + return NULL; + } tai->tac = ogs_uint24_to_0string(nr_tai.tac); - ogs_expect_or_return_val(tai->tac, NULL); + if (!tai->tac) { + ogs_error("No tai->tac"); + amf_nsmf_pdusession_free_target_id(targetId); + return NULL; + } return targetId; } diff --git a/src/amf/nsmf-build.h b/src/amf/nsmf-build.h index 9172ad0f2..4f84d973a 100644 --- a/src/amf/nsmf-build.h +++ b/src/amf/nsmf-build.h @@ -51,6 +51,12 @@ typedef struct amf_nsmf_pdusession_sm_context_param_s { OpenAPI_ho_state_e hoState; OpenAPI_ng_ran_target_id_t *targetId; NGAP_TargetID_t *TargetID; + + struct { + struct { + char *id; + } nrf; + } nrf_uri; } amf_nsmf_pdusession_sm_context_param_t; ogs_sbi_request_t *amf_nsmf_pdusession_build_create_sm_context( diff --git a/src/amf/nudm-build.c b/src/amf/nudm-build.c index ae56bba93..db2c275b6 100644 --- a/src/amf/nudm-build.c +++ b/src/amf/nudm-build.c @@ -46,9 +46,16 @@ ogs_sbi_request_t *amf_nudm_uecm_build_registration( Amf3GppAccessRegistration.amf_instance_id = NF_INSTANCE_ID(ogs_sbi_self()->nf_instance); + if (!Amf3GppAccessRegistration.amf_instance_id) { + ogs_error("No amf_instance_id"); + goto end; + } server = ogs_list_first(&ogs_sbi_self()->server_list); - ogs_assert(server); + if (!server) { + ogs_error("No server"); + goto end; + } memset(&header, 0, sizeof(header)); header.service.name = (char *)OGS_SBI_SERVICE_NAME_NAMF_CALLBACK; @@ -57,20 +64,32 @@ ogs_sbi_request_t *amf_nudm_uecm_build_registration( header.resource.component[1] = (char *)OGS_SBI_RESOURCE_NAME_DEREG_NOTIFY; Amf3GppAccessRegistration.dereg_callback_uri = ogs_sbi_server_uri(server, &header); - ogs_assert(Amf3GppAccessRegistration.dereg_callback_uri); + if (!Amf3GppAccessRegistration.dereg_callback_uri) { + ogs_error("No dereg_callback_uri"); + goto end; + } Amf3GppAccessRegistration.guami = ogs_sbi_build_guami(amf_ue->guami); Amf3GppAccessRegistration.rat_type = amf_ue_rat_type(amf_ue); - ogs_assert(Amf3GppAccessRegistration.rat_type != OpenAPI_rat_type_NULL); + if (Amf3GppAccessRegistration.rat_type == OpenAPI_rat_type_NULL) { + ogs_error("No rat_type"); + goto end; + } message.Amf3GppAccessRegistration = &Amf3GppAccessRegistration; + message.http.custom.callback = + (char *)OGS_SBI_CALLBACK_NUDM_UECM_DEREGISTRATION_NOTIFICATION; + request = ogs_sbi_build_request(&message); - ogs_assert(request); + ogs_expect(request); + +end: if (Amf3GppAccessRegistration.guami) ogs_sbi_free_guami(Amf3GppAccessRegistration.guami); - ogs_free(Amf3GppAccessRegistration.dereg_callback_uri); + if (Amf3GppAccessRegistration.dereg_callback_uri) + ogs_free(Amf3GppAccessRegistration.dereg_callback_uri); return request; } @@ -102,6 +121,10 @@ ogs_sbi_request_t *amf_nudm_uecm_build_registration_delete( Amf3GppAccessRegistrationModification.guami = ogs_sbi_build_guami(amf_ue->guami); + if (!Amf3GppAccessRegistrationModification.guami) { + ogs_error("No guami"); + goto end; + } Amf3GppAccessRegistrationModification.is_purge_flag = true; Amf3GppAccessRegistrationModification.purge_flag = 1; @@ -109,7 +132,9 @@ ogs_sbi_request_t *amf_nudm_uecm_build_registration_delete( &Amf3GppAccessRegistrationModification; request = ogs_sbi_build_request(&message); - ogs_assert(request); + ogs_expect(request); + +end: if (Amf3GppAccessRegistrationModification.guami) ogs_sbi_free_guami(Amf3GppAccessRegistrationModification.guami); @@ -133,7 +158,7 @@ ogs_sbi_request_t *amf_nudm_sdm_build_get(amf_ue_t *amf_ue, void *data) message.h.resource.component[1] = data; request = ogs_sbi_build_request(&message); - ogs_assert(request); + ogs_expect(request); return request; } @@ -167,7 +192,10 @@ ogs_sbi_request_t *amf_nudm_sdm_build_subscription(amf_ue_t *amf_ue, void *data) NF_INSTANCE_ID(ogs_sbi_self()->nf_instance); server = ogs_list_first(&ogs_sbi_self()->server_list); - ogs_assert(server); + if (!server) { + ogs_error("No server"); + goto end; + } memset(&header, 0, sizeof(header)); header.service.name = (char *)OGS_SBI_SERVICE_NAME_NAMF_CALLBACK; @@ -175,26 +203,38 @@ ogs_sbi_request_t *amf_nudm_sdm_build_subscription(amf_ue_t *amf_ue, void *data) header.resource.component[0] = amf_ue->supi; header.resource.component[1] = (char *)OGS_SBI_RESOURCE_NAME_SDMSUBSCRIPTION_NOTIFY; - SDMSubscription.callback_reference = - ogs_sbi_server_uri(server, &header); - ogs_assert(SDMSubscription.callback_reference); + SDMSubscription.callback_reference = ogs_sbi_server_uri(server, &header); + if (!SDMSubscription.callback_reference) { + ogs_error("No callback_reference"); + goto end; + } SDMSubscription.monitored_resource_uris = OpenAPI_list_create(); monres = ogs_msprintf("%s/%s", amf_ue->supi, (char *)data); - ogs_assert(monres); + if (!monres) { + ogs_error("No monres"); + goto end; + } OpenAPI_list_add(SDMSubscription.monitored_resource_uris, monres); SDMSubscription.implicit_unsubscribe = 1; message.SDMSubscription = &SDMSubscription; - request = ogs_sbi_build_request(&message); - ogs_assert(request); + message.http.custom.callback = + (char *)OGS_SBI_CALLBACK_NUDM_SDM_NOTIFICATION; - ogs_free(monres); + request = ogs_sbi_build_request(&message); + ogs_expect(request); + +end: + + if (monres) + ogs_free(monres); OpenAPI_list_free(SDMSubscription.monitored_resource_uris); - ogs_free(SDMSubscription.callback_reference); + if (SDMSubscription.callback_reference) + ogs_free(SDMSubscription.callback_reference); return request; } diff --git a/src/amf/sbi-path.c b/src/amf/sbi-path.c index 97432ad77..dc8c78720 100644 --- a/src/amf/sbi-path.c +++ b/src/amf/sbi-path.c @@ -22,67 +22,12 @@ #include "ngap-path.h" #include "nnrf-handler.h" -static int server_cb(ogs_sbi_request_t *request, void *data) -{ - amf_event_t *e = NULL; - int rv; - - ogs_assert(request); - ogs_assert(data); - - e = amf_event_new(OGS_EVENT_SBI_SERVER); - ogs_assert(e); - - 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); - ogs_event_free(e); - return OGS_ERROR; - } - - return OGS_OK; -} - -static int client_cb(int status, ogs_sbi_response_t *response, void *data) -{ - amf_event_t *e = NULL; - int rv; - - if (status != OGS_OK) { - ogs_log_message( - status == OGS_DONE ? OGS_LOG_DEBUG : OGS_LOG_WARN, 0, - "client_cb() failed [%d]", status); - return OGS_ERROR; - } - - ogs_assert(response); - - e = amf_event_new(OGS_EVENT_SBI_CLIENT); - ogs_assert(e); - 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); - ogs_event_free(e); - return OGS_ERROR; - } - - return OGS_OK; -} - int amf_sbi_open(void) { ogs_sbi_nf_instance_t *nf_instance = NULL; ogs_sbi_nf_service_t *service = NULL; - /* Add SELF NF instance */ + /* Initialize SELF NF instance */ nf_instance = ogs_sbi_self()->nf_instance; ogs_assert(nf_instance); ogs_sbi_nf_fsm_init(nf_instance); @@ -104,18 +49,8 @@ int amf_sbi_open(void) /* Initialize NRF NF Instance */ 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; - - /* NFRegister is sent and the response is received - * by the above client callback. */ + if (nf_instance) ogs_sbi_nf_fsm_init(nf_instance); - } /* Build Subscription-Data */ ogs_sbi_subscription_data_build_default( @@ -131,7 +66,7 @@ int amf_sbi_open(void) ogs_sbi_subscription_data_build_default( OpenAPI_nf_type_NSSF, OGS_SBI_SERVICE_NAME_NNSSF_NSSELECTION); - if (ogs_sbi_server_start_all(server_cb) != OGS_OK) + if (ogs_sbi_server_start_all(ogs_sbi_server_handler) != OGS_OK) return OGS_ERROR; return OGS_OK; @@ -143,12 +78,12 @@ void amf_sbi_close(void) ogs_sbi_server_stop_all(); } -bool amf_sbi_send_request(ogs_sbi_nf_instance_t *nf_instance, void *data) +bool amf_sbi_send_request( + ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_xact_t *xact) { ogs_assert(nf_instance); - ogs_assert(data); - - return ogs_sbi_send_request(nf_instance, client_cb, data); + ogs_assert(xact); + return ogs_sbi_send_request_to_nf_instance(nf_instance, xact); } bool amf_ue_sbi_discover_and_send( @@ -174,7 +109,7 @@ bool amf_ue_sbi_discover_and_send( return false; } - if (ogs_sbi_discover_and_send(xact, client_cb) != true) { + if (ogs_sbi_discover_and_send(xact) != true) { ogs_error("amf_ue_sbi_discover_and_send() failed"); ogs_sbi_xact_remove(xact); ogs_assert(OGS_OK == @@ -210,7 +145,7 @@ bool amf_sess_sbi_discover_and_send( xact->state = state; - if (ogs_sbi_discover_and_send(xact, client_cb) != true) { + if (ogs_sbi_discover_and_send(xact) != true) { ogs_error("amf_sess_sbi_discover_and_send() failed"); ogs_sbi_xact_remove(xact); ogs_assert(OGS_OK == nas_5gs_send_back_gsm_message(sess, @@ -228,18 +163,19 @@ static int client_discover_cb( ogs_sbi_xact_t *xact = NULL; ogs_sbi_service_type_e service_type = OGS_SBI_SERVICE_TYPE_NULL; + OpenAPI_nf_type_e requester_nf_type = OpenAPI_nf_type_NULL; ogs_sbi_discovery_option_t *discovery_option = NULL; amf_ue_t *amf_ue = NULL; amf_sess_t *sess = NULL; - ogs_assert(response); - xact = data; ogs_assert(xact); xact = ogs_sbi_xact_cycle(xact); if (!xact) { ogs_error("SBI transaction has already been removed"); + if (response) + ogs_sbi_response_free(response); return OGS_ERROR; } @@ -247,12 +183,17 @@ static int client_discover_cb( ogs_assert(sess); service_type = xact->service_type; + ogs_assert(service_type); + requester_nf_type = xact->requester_nf_type; + ogs_assert(requester_nf_type); discovery_option = xact->discovery_option; sess = amf_sess_cycle(sess); if (!sess) { ogs_error("Session has already been removed"); ogs_sbi_xact_remove(xact); + if (response) + ogs_sbi_response_free(response); return OGS_ERROR; } @@ -268,6 +209,8 @@ static int client_discover_cb( return OGS_ERROR; } + ogs_assert(response); + rv = ogs_sbi_parse_response(&message, response); if (rv != OGS_OK) { ogs_error("cannot parse HTTP response"); @@ -293,9 +236,10 @@ static int client_discover_cb( goto cleanup; } - ogs_nnrf_handle_nf_discover_search_result(message.SearchResult); + ogs_nnrf_disc_handle_nf_discover_search_result(message.SearchResult); - amf_sbi_select_nf(&sess->sbi, service_type, discovery_option); + amf_sbi_select_nf(&sess->sbi, + service_type, requester_nf_type, discovery_option); if (!sess->sbi.service_type_array[service_type].nf_instance) { ogs_error("[%s:%d] (NF discover) No [%s]", @@ -314,6 +258,13 @@ static int client_discover_cb( amf_nsmf_pdusession_build_create_sm_context, sess, AMF_CREATE_SM_CONTEXT_NO_STATE, NULL); + ogs_sbi_xact_remove(xact); + + ogs_sbi_message_free(&message); + ogs_sbi_response_free(response); + + return OGS_OK; + cleanup: ogs_sbi_xact_remove(xact); @@ -347,7 +298,7 @@ bool amf_sess_sbi_discover_by_nsi( sess->nssf.nrf.id, xact->service_type, xact->discovery_option); ogs_expect_or_return_val(xact->request, false); - return ogs_sbi_client_send_reqmem_persistent( + return ogs_sbi_client_send_request( client, client_discover_cb, xact->request, xact); } @@ -497,6 +448,7 @@ static int client_notify_cb( bool amf_sbi_send_n1_n2_failure_notify( amf_sess_t *sess, OpenAPI_n1_n2_message_transfer_cause_e cause) { + bool rc; ogs_sbi_request_t *request = NULL; ogs_sbi_client_t *client = NULL; @@ -508,5 +460,11 @@ bool amf_sbi_send_n1_n2_failure_notify( request = amf_nsmf_callback_build_n1_n2_failure_notify(sess, cause); ogs_expect_or_return_val(request, false); - return ogs_sbi_client_send_request(client, client_notify_cb, request, NULL); + rc = ogs_sbi_send_request_to_client( + client, client_notify_cb, request, NULL); + ogs_expect(rc == true); + + ogs_sbi_request_free(request); + + return rc; } diff --git a/src/amf/sbi-path.h b/src/amf/sbi-path.h index ba01a3136..deb3b9706 100644 --- a/src/amf/sbi-path.h +++ b/src/amf/sbi-path.h @@ -34,7 +34,8 @@ extern "C" { int amf_sbi_open(void); void amf_sbi_close(void); -bool amf_sbi_send_request(ogs_sbi_nf_instance_t *nf_instance, void *data); +bool amf_sbi_send_request( + ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_xact_t *xact); bool amf_ue_sbi_discover_and_send( ogs_sbi_service_type_e service_type, ogs_sbi_discovery_option_t *discovery_option, diff --git a/src/ausf/ausf-sm.c b/src/ausf/ausf-sm.c index 890771a47..889bed1e9 100644 --- a/src/ausf/ausf-sm.c +++ b/src/ausf/ausf-sm.c @@ -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) - ogs_nnrf_handle_nf_status_notify(stream, &message); + ogs_nnrf_nfm_handle_nf_status_notify(stream, &message); break; DEFAULT @@ -215,7 +215,7 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e) CASE(OGS_SBI_HTTP_METHOD_POST) if (message.res_status == OGS_SBI_HTTP_STATUS_CREATED || message.res_status == OGS_SBI_HTTP_STATUS_OK) { - ogs_nnrf_handle_nf_status_subscribe( + ogs_nnrf_nfm_handle_nf_status_subscribe( subscription_data, &message); } else { ogs_error("[%s] HTTP response error [%d]", diff --git a/src/ausf/event.h b/src/ausf/event.h index 8a4befcac..413c0b3d8 100644 --- a/src/ausf/event.h +++ b/src/ausf/event.h @@ -34,6 +34,8 @@ typedef struct ausf_event_s { ausf_ue_t *ausf_ue; } ausf_event_t; +OGS_STATIC_ASSERT(OGS_EVENT_SIZE >= sizeof(ausf_event_t)); + ausf_event_t *ausf_event_new(int id); const char *ausf_event_get_name(ausf_event_t *e); diff --git a/src/ausf/nnrf-handler.c b/src/ausf/nnrf-handler.c index 4e3324341..d826a7894 100644 --- a/src/ausf/nnrf-handler.c +++ b/src/ausf/nnrf-handler.c @@ -29,6 +29,7 @@ void ausf_nnrf_handle_nf_discover( ogs_sbi_discovery_option_t *discovery_option = NULL; OpenAPI_nf_type_e target_nf_type = OpenAPI_nf_type_NULL; + OpenAPI_nf_type_e requester_nf_type = OpenAPI_nf_type_NULL; OpenAPI_search_result_t *SearchResult = NULL; ogs_assert(recvmsg); @@ -39,6 +40,8 @@ void ausf_nnrf_handle_nf_discover( ogs_assert(service_type); target_nf_type = ogs_sbi_service_type_to_nf_type(service_type); ogs_assert(target_nf_type); + requester_nf_type = xact->requester_nf_type; + ogs_assert(requester_nf_type); discovery_option = xact->discovery_option; @@ -48,13 +51,14 @@ void ausf_nnrf_handle_nf_discover( return; } - ogs_nnrf_handle_nf_discover_search_result(SearchResult); + ogs_nnrf_disc_handle_nf_discover_search_result(SearchResult); nf_instance = ogs_sbi_nf_instance_find_by_discovery_param( - target_nf_type, discovery_option); + target_nf_type, requester_nf_type, discovery_option); if (!nf_instance) { - ogs_error("(NF discover) No [%s]", - ogs_sbi_service_type_to_name(service_type)); + ogs_error("(NF discover) No [%s:%s]", + ogs_sbi_service_type_to_name(service_type), + OpenAPI_nf_type_ToString(requester_nf_type)); return; } diff --git a/src/ausf/nudm-build.c b/src/ausf/nudm-build.c index 9b2f154de..0af3cfd7c 100644 --- a/src/ausf/nudm-build.c +++ b/src/ausf/nudm-build.c @@ -60,7 +60,7 @@ ogs_sbi_request_t *ausf_nudm_ueau_build_get(ausf_ue_t *ausf_ue, void *data) message.AuthenticationInfoRequest = &AuthenticationInfoRequest; request = ogs_sbi_build_request(&message); - ogs_expect_or_return_val(request, NULL); + ogs_expect(request); return request; } @@ -83,10 +83,16 @@ ogs_sbi_request_t *ausf_nudm_ueau_build_result_confirmation_inform( message.h.resource.component[1] = (char *)OGS_SBI_RESOURCE_NAME_AUTH_EVENTS; AuthEvent = ogs_calloc(1, sizeof(*AuthEvent)); - ogs_expect_or_return_val(AuthEvent, NULL); + if (!AuthEvent) { + ogs_error("No AuthEvent"); + goto end; + } AuthEvent->time_stamp = ogs_sbi_localtime_string(ogs_time_now()); - ogs_expect_or_return_val(AuthEvent->time_stamp, NULL); + if (!AuthEvent->time_stamp) { + ogs_error("No time_stamp"); + goto end; + } AuthEvent->nf_instance_id = NF_INSTANCE_ID(ogs_sbi_self()->nf_instance); if (ausf_ue->auth_result == OpenAPI_auth_result_AUTHENTICATION_SUCCESS) @@ -99,11 +105,15 @@ ogs_sbi_request_t *ausf_nudm_ueau_build_result_confirmation_inform( message.AuthEvent = AuthEvent; request = ogs_sbi_build_request(&message); - ogs_expect_or_return_val(request, NULL); + ogs_expect(request); - if (AuthEvent->time_stamp) - ogs_free(AuthEvent->time_stamp); - ogs_free(AuthEvent); +end: + + if (AuthEvent) { + if (AuthEvent->time_stamp) + ogs_free(AuthEvent->time_stamp); + ogs_free(AuthEvent); + } return request; } diff --git a/src/ausf/sbi-path.c b/src/ausf/sbi-path.c index af23509e0..552459abc 100644 --- a/src/ausf/sbi-path.c +++ b/src/ausf/sbi-path.c @@ -19,67 +19,12 @@ #include "sbi-path.h" -static int server_cb(ogs_sbi_request_t *request, void *data) -{ - ausf_event_t *e = NULL; - int rv; - - ogs_assert(request); - ogs_assert(data); - - e = ausf_event_new(OGS_EVENT_SBI_SERVER); - ogs_assert(e); - - 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); - ogs_event_free(e); - return OGS_ERROR; - } - - return OGS_OK; -} - -static int client_cb(int status, ogs_sbi_response_t *response, void *data) -{ - ausf_event_t *e = NULL; - int rv; - - if (status != OGS_OK) { - ogs_log_message( - status == OGS_DONE ? OGS_LOG_DEBUG : OGS_LOG_WARN, 0, - "client_cb() failed [%d]", status); - return OGS_ERROR; - } - - ogs_assert(response); - - e = ausf_event_new(OGS_EVENT_SBI_CLIENT); - ogs_assert(e); - 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); - ogs_event_free(e); - return OGS_ERROR; - } - - return OGS_OK; -} - int ausf_sbi_open(void) { ogs_sbi_nf_instance_t *nf_instance = NULL; ogs_sbi_nf_service_t *service = NULL; - /* Add SELF NF instance */ + /* Initialize SELF NF instance */ nf_instance = ogs_sbi_self()->nf_instance; ogs_assert(nf_instance); ogs_sbi_nf_fsm_init(nf_instance); @@ -101,24 +46,14 @@ int ausf_sbi_open(void) /* Initialize NRF NF Instance */ 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; - - /* NFRegister is sent and the response is received - * by the above client callback. */ + if (nf_instance) ogs_sbi_nf_fsm_init(nf_instance); - } /* Build Subscription-Data */ ogs_sbi_subscription_data_build_default( OpenAPI_nf_type_UDM, OGS_SBI_SERVICE_NAME_NUDM_UEAU); - if (ogs_sbi_server_start_all(server_cb) != OGS_OK) + if (ogs_sbi_server_start_all(ogs_sbi_server_handler) != OGS_OK) return OGS_ERROR; return OGS_OK; @@ -130,11 +65,12 @@ void ausf_sbi_close(void) ogs_sbi_server_stop_all(); } -bool ausf_sbi_send_request(ogs_sbi_nf_instance_t *nf_instance, void *data) +bool ausf_sbi_send_request( + ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_xact_t *xact) { ogs_assert(nf_instance); - - return ogs_sbi_send_request(nf_instance, client_cb, data); + ogs_assert(xact); + return ogs_sbi_send_request_to_nf_instance(nf_instance, xact); } bool ausf_sbi_discover_and_send( @@ -164,7 +100,7 @@ bool ausf_sbi_discover_and_send( xact->assoc_stream = stream; - if (ogs_sbi_discover_and_send(xact, client_cb) != true) { + if (ogs_sbi_discover_and_send(xact) != true) { ogs_error("ausf_sbi_discover_and_send() failed"); ogs_sbi_xact_remove(xact); ogs_assert(true == diff --git a/src/ausf/sbi-path.h b/src/ausf/sbi-path.h index c2c257f41..2f1b83fa0 100644 --- a/src/ausf/sbi-path.h +++ b/src/ausf/sbi-path.h @@ -29,7 +29,8 @@ extern "C" { int ausf_sbi_open(void); void ausf_sbi_close(void); -bool ausf_sbi_send_request(ogs_sbi_nf_instance_t *nf_instance, void *data); +bool ausf_sbi_send_request( + ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_xact_t *xact); bool ausf_sbi_discover_and_send( ogs_sbi_service_type_e service_type, ogs_sbi_discovery_option_t *discovery_option, diff --git a/src/bsf/bsf-sm.c b/src/bsf/bsf-sm.c index 553c4f700..95e8bf970 100644 --- a/src/bsf/bsf-sm.c +++ b/src/bsf/bsf-sm.c @@ -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) - ogs_nnrf_handle_nf_status_notify(stream, &message); + ogs_nnrf_nfm_handle_nf_status_notify(stream, &message); break; DEFAULT @@ -237,7 +237,7 @@ void bsf_state_operational(ogs_fsm_t *s, bsf_event_t *e) CASE(OGS_SBI_HTTP_METHOD_POST) if (message.res_status == OGS_SBI_HTTP_STATUS_CREATED || message.res_status == OGS_SBI_HTTP_STATUS_OK) { - ogs_nnrf_handle_nf_status_subscribe( + ogs_nnrf_nfm_handle_nf_status_subscribe( subscription_data, &message); } else { ogs_error("HTTP response error : %d", diff --git a/src/bsf/event.h b/src/bsf/event.h index 027d5cbba..a84f79263 100644 --- a/src/bsf/event.h +++ b/src/bsf/event.h @@ -33,6 +33,8 @@ typedef struct bsf_event_s { bsf_sess_t *sess; } bsf_event_t; +OGS_STATIC_ASSERT(OGS_EVENT_SIZE >= sizeof(bsf_event_t)); + bsf_event_t *bsf_event_new(int id); const char *bsf_event_get_name(bsf_event_t *e); diff --git a/src/bsf/nnrf-handler.c b/src/bsf/nnrf-handler.c index 260f08efc..2b7e2f107 100644 --- a/src/bsf/nnrf-handler.c +++ b/src/bsf/nnrf-handler.c @@ -29,6 +29,7 @@ void bsf_nnrf_handle_nf_discover( ogs_sbi_discovery_option_t *discovery_option = NULL; OpenAPI_nf_type_e target_nf_type = OpenAPI_nf_type_NULL; + OpenAPI_nf_type_e requester_nf_type = OpenAPI_nf_type_NULL; OpenAPI_search_result_t *SearchResult = NULL; ogs_assert(recvmsg); @@ -39,6 +40,8 @@ void bsf_nnrf_handle_nf_discover( ogs_assert(service_type); target_nf_type = ogs_sbi_service_type_to_nf_type(service_type); ogs_assert(target_nf_type); + requester_nf_type = xact->requester_nf_type; + ogs_assert(requester_nf_type); discovery_option = xact->discovery_option; @@ -48,13 +51,14 @@ void bsf_nnrf_handle_nf_discover( return; } - ogs_nnrf_handle_nf_discover_search_result(SearchResult); + ogs_nnrf_disc_handle_nf_discover_search_result(SearchResult); nf_instance = ogs_sbi_nf_instance_find_by_discovery_param( - target_nf_type, discovery_option); + target_nf_type, requester_nf_type, discovery_option); if (!nf_instance) { - ogs_error("(NF discover) No [%s]", - ogs_sbi_service_type_to_name(service_type)); + ogs_error("(NF discover) No [%s:%s]", + ogs_sbi_service_type_to_name(service_type), + OpenAPI_nf_type_ToString(requester_nf_type)); return; } diff --git a/src/bsf/sbi-path.c b/src/bsf/sbi-path.c index 1fe58e0c2..0575e8610 100644 --- a/src/bsf/sbi-path.c +++ b/src/bsf/sbi-path.c @@ -19,67 +19,12 @@ #include "sbi-path.h" -static int server_cb(ogs_sbi_request_t *request, void *data) -{ - bsf_event_t *e = NULL; - int rv; - - ogs_assert(request); - ogs_assert(data); - - e = bsf_event_new(OGS_EVENT_SBI_SERVER); - ogs_assert(e); - - 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); - ogs_event_free(e); - return OGS_ERROR; - } - - return OGS_OK; -} - -static int client_cb(int status, ogs_sbi_response_t *response, void *data) -{ - bsf_event_t *e = NULL; - int rv; - - if (status != OGS_OK) { - ogs_log_message( - status == OGS_DONE ? OGS_LOG_DEBUG : OGS_LOG_WARN, 0, - "client_cb() failed [%d]", status); - return OGS_ERROR; - } - - ogs_assert(response); - - e = bsf_event_new(OGS_EVENT_SBI_CLIENT); - ogs_assert(e); - 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); - ogs_event_free(e); - return OGS_ERROR; - } - - return OGS_OK; -} - int bsf_sbi_open(void) { ogs_sbi_nf_instance_t *nf_instance = NULL; ogs_sbi_nf_service_t *service = NULL; - /* Add SELF NF instance */ + /* Initialize SELF NF instance */ nf_instance = ogs_sbi_self()->nf_instance; ogs_assert(nf_instance); ogs_sbi_nf_fsm_init(nf_instance); @@ -103,20 +48,10 @@ int bsf_sbi_open(void) /* Initialize NRF NF Instance */ 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; - - /* NFRegister is sent and the response is received - * by the above client callback. */ + if (nf_instance) ogs_sbi_nf_fsm_init(nf_instance); - } - if (ogs_sbi_server_start_all(server_cb) != OGS_OK) + if (ogs_sbi_server_start_all(ogs_sbi_server_handler) != OGS_OK) return OGS_ERROR; return OGS_OK; @@ -128,11 +63,12 @@ void bsf_sbi_close(void) ogs_sbi_server_stop_all(); } -bool bsf_sbi_send_request(ogs_sbi_nf_instance_t *nf_instance, void *data) +bool bsf_sbi_send_request( + ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_xact_t *xact) { ogs_assert(nf_instance); - - return ogs_sbi_send_request(nf_instance, client_cb, data); + ogs_assert(xact); + return ogs_sbi_send_request_to_nf_instance(nf_instance, xact); } bool bsf_sbi_discover_and_send( @@ -162,7 +98,7 @@ bool bsf_sbi_discover_and_send( xact->assoc_stream = stream; - if (ogs_sbi_discover_and_send(xact, client_cb) != true) { + if (ogs_sbi_discover_and_send(xact) != true) { ogs_error("bsf_sbi_discover_and_send() failed"); ogs_sbi_xact_remove(xact); ogs_assert(true == diff --git a/src/bsf/sbi-path.h b/src/bsf/sbi-path.h index 4bffe075d..df2e459ab 100644 --- a/src/bsf/sbi-path.h +++ b/src/bsf/sbi-path.h @@ -29,7 +29,8 @@ extern "C" { int bsf_sbi_open(void); void bsf_sbi_close(void); -bool bsf_sbi_send_request(ogs_sbi_nf_instance_t *nf_instance, void *data); +bool bsf_sbi_send_request( + ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_xact_t *xact); bool bsf_sbi_discover_and_send( ogs_sbi_service_type_e service_type, ogs_sbi_discovery_option_t *discovery_option, diff --git a/src/mme/mme-event.h b/src/mme/mme-event.h index 8cdef31da..146c5cbb9 100644 --- a/src/mme/mme-event.h +++ b/src/mme/mme-event.h @@ -101,6 +101,8 @@ typedef struct mme_event_s { ogs_timer_t *timer; } mme_event_t; +OGS_STATIC_ASSERT(OGS_EVENT_SIZE >= sizeof(mme_event_t)); + void mme_event_term(void); mme_event_t *mme_event_new(mme_event_e id); diff --git a/src/nrf/context.c b/src/nrf/context.c index 943c63f5f..1ccc2f91d 100644 --- a/src/nrf/context.c +++ b/src/nrf/context.c @@ -44,8 +44,12 @@ void nrf_context_final(void) ogs_assert(context_initialized == 1); ogs_list_for_each_safe( - &ogs_sbi_self()->nf_instance_list, next_nf_instance, nf_instance) - if (OGS_FSM_STATE(&nf_instance->sm)) nrf_nf_fsm_fini(nf_instance); + &ogs_sbi_self()->nf_instance_list, next_nf_instance, nf_instance) { + if (NF_INSTANCE_TYPE_IS_NRF(nf_instance)) + continue; + if (OGS_FSM_STATE(&nf_instance->sm)) + nrf_nf_fsm_fini(nf_instance); + } context_initialized = 0; } diff --git a/src/nrf/event.c b/src/nrf/event.c index 80c0045ec..c66926448 100644 --- a/src/nrf/event.c +++ b/src/nrf/event.c @@ -20,54 +20,35 @@ #include "event.h" #include "context.h" -static OGS_POOL(pool, nrf_event_t); - -void nrf_event_init(void) -{ - ogs_pool_init(&pool, ogs_app()->pool.event); -} - -void nrf_event_final(void) -{ - ogs_pool_final(&pool); -} - -nrf_event_t *nrf_event_new(nrf_event_e id) +nrf_event_t *nrf_event_new(int id) { nrf_event_t *e = NULL; - ogs_pool_alloc(&pool, &e); + e = ogs_event_size(id, sizeof(nrf_event_t)); ogs_assert(e); - memset(e, 0, sizeof(*e)); - e->id = id; + e->h.id = id; return e; } -void nrf_event_free(nrf_event_t *e) -{ - ogs_assert(e); - ogs_pool_free(&pool, e); -} - const char *nrf_event_get_name(nrf_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 NRF_EVT_SBI_SERVER: - return "NRF_EVT_SBI_SERVER"; - case NRF_EVT_SBI_CLIENT: - return "NRF_EVT_SBI_CLIENT"; - case NRF_EVT_SBI_TIMER: - return "NRF_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; diff --git a/src/nrf/event.h b/src/nrf/event.h index ad7bc1ffb..374c77c2c 100644 --- a/src/nrf/event.h +++ b/src/nrf/event.h @@ -26,44 +26,17 @@ 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_data_s ogs_sbi_subscription_data_t; -typedef enum { - NRF_EVT_BASE = OGS_MAX_NUM_OF_PROTO_EVENT, - - NRF_EVT_SBI_SERVER, - NRF_EVT_SBI_CLIENT, - NRF_EVT_SBI_TIMER, - - NRF_EVT_TOP, - -} nrf_event_e; - typedef struct nrf_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; ogs_sbi_nf_instance_t *nf_instance; ogs_sbi_subscription_data_t *subscription_data; } nrf_event_t; -void nrf_event_init(void); -void nrf_event_final(void); - -nrf_event_t *nrf_event_new(nrf_event_e id); -void nrf_event_free(nrf_event_t *e); +nrf_event_t *nrf_event_new(int id); const char *nrf_event_get_name(nrf_event_t *e); diff --git a/src/nrf/init.c b/src/nrf/init.c index fe6a1b87a..782772850 100644 --- a/src/nrf/init.c +++ b/src/nrf/init.c @@ -30,7 +30,6 @@ int nrf_initialize() ogs_sbi_context_init(); nrf_context_init(); - nrf_event_init(); rv = ogs_sbi_context_parse_config("nrf", NULL, "scp"); if (rv != OGS_OK) return rv; @@ -85,8 +84,6 @@ void nrf_terminate(void) nrf_context_final(); ogs_sbi_context_final(); - - nrf_event_final(); /* Destroy event */ } static void nrf_main(void *data) @@ -127,7 +124,7 @@ static void nrf_main(void *data) ogs_assert(e); ogs_fsm_dispatch(&nrf_sm, e); - nrf_event_free(e); + ogs_event_free(e); } } done: diff --git a/src/nrf/nf-sm.c b/src/nrf/nf-sm.c index 3b09dff7b..aab91d109 100644 --- a/src/nrf/nf-sm.c +++ b/src/nrf/nf-sm.c @@ -95,17 +95,17 @@ void nrf_nf_state_will_register(ogs_fsm_t *s, nrf_event_t *e) nf_instance = e->nf_instance; ogs_assert(nf_instance); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: break; case OGS_FSM_EXIT_SIG: break; - case NRF_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) @@ -185,7 +185,7 @@ void nrf_nf_state_registered(ogs_fsm_t *s, nrf_event_t *e) nf_instance = e->nf_instance; ogs_assert(nf_instance); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: ogs_info("[%s] NF registered [Heartbeat:%ds]", nf_instance->id, nf_instance->time.heartbeat_interval); @@ -212,10 +212,10 @@ void nrf_nf_state_registered(ogs_fsm_t *s, nrf_event_t *e) OpenAPI_notification_event_type_NF_DEREGISTERED, nf_instance)); break; - case NRF_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) @@ -300,7 +300,7 @@ void nrf_nf_state_de_registered(ogs_fsm_t *s, nrf_event_t *e) nrf_sm_debug(e); - switch (e->id) { + switch (e->h.id) { case OGS_FSM_ENTRY_SIG: break; case OGS_FSM_EXIT_SIG: @@ -318,7 +318,7 @@ void nrf_nf_state_exception(ogs_fsm_t *s, nrf_event_t *e) nrf_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/nrf/nnrf-build.c b/src/nrf/nnrf-build.c index 84602c5ed..d957f6a4e 100644 --- a/src/nrf/nnrf-build.c +++ b/src/nrf/nnrf-build.c @@ -44,12 +44,18 @@ ogs_sbi_request_t *nrf_nnrf_nfm_build_nf_status_notify( message.http.accept = (char *)OGS_SBI_CONTENT_PROBLEM_TYPE; NotificationData = ogs_calloc(1, sizeof(*NotificationData)); - ogs_expect_or_return_val(NotificationData, NULL); + if (!NotificationData) { + ogs_error("No NotificationData"); + goto end; + } NotificationData->event = event; server = ogs_list_first(&ogs_sbi_self()->server_list); - ogs_expect_or_return_val(server, NULL); + if (!server) { + ogs_error("No server"); + goto end; + } memset(&header, 0, sizeof(header)); header.service.name = (char *)OGS_SBI_SERVICE_NAME_NNRF_NFM; @@ -58,7 +64,10 @@ ogs_sbi_request_t *nrf_nnrf_nfm_build_nf_status_notify( header.resource.component[1] = nf_instance->id; NotificationData->nf_instance_uri = ogs_sbi_server_uri(server, &header); - ogs_expect_or_return_val(NotificationData->nf_instance_uri, NULL); + if (!server) { + ogs_error("No nf_instance_uri"); + goto end; + } if (event != OpenAPI_notification_event_type_NF_DEREGISTERED) { NotificationData->nf_profile = @@ -67,19 +76,26 @@ ogs_sbi_request_t *nrf_nnrf_nfm_build_nf_status_notify( subscription_data->subscr_cond.service_name, NULL, subscription_data->requester_features); - ogs_expect_or_return_val(NotificationData->nf_profile, NULL); + if (!NotificationData->nf_profile) { + ogs_error("No nf_profile"); + goto end; + } } message.NotificationData = NotificationData; request = ogs_sbi_build_request(&message); - ogs_expect_or_return_val(request, NULL); + ogs_expect(request); - if (NotificationData->nf_profile) - ogs_nnrf_nfm_free_nf_profile(NotificationData->nf_profile); +end: - ogs_free(NotificationData->nf_instance_uri); - ogs_free(NotificationData); + if (NotificationData) { + if (NotificationData->nf_profile) + ogs_nnrf_nfm_free_nf_profile(NotificationData->nf_profile); + if (NotificationData->nf_instance_uri) + ogs_free(NotificationData->nf_instance_uri); + ogs_free(NotificationData); + } return request; } diff --git a/src/nrf/nnrf-handler.c b/src/nrf/nnrf-handler.c index 92f9c1121..7e706aa35 100644 --- a/src/nrf/nnrf-handler.c +++ b/src/nrf/nnrf-handler.c @@ -40,7 +40,7 @@ bool nrf_nnrf_handle_nf_register(ogs_sbi_nf_instance_t *nf_instance, return false; } - ogs_sbi_nnrf_handle_nf_profile(nf_instance, NFProfile); + ogs_nnrf_nfm_handle_nf_profile(nf_instance, NFProfile); if (OGS_FSM_CHECK(&nf_instance->sm, nrf_nf_state_will_register)) { recvmsg->http.location = recvmsg->h.uri; diff --git a/src/nrf/nrf-sm.c b/src/nrf/nrf-sm.c index 1bc927d26..8acba792d 100644 --- a/src/nrf/nrf-sm.c +++ b/src/nrf/nrf-sm.c @@ -51,17 +51,17 @@ void nrf_state_operational(ogs_fsm_t *s, nrf_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 NRF_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); @@ -141,7 +141,7 @@ void nrf_state_operational(ogs_fsm_t *s, nrf_event_t *e) e->nf_instance = 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); if (OGS_FSM_CHECK(&nf_instance->sm, nrf_nf_state_de_registered)) { @@ -235,8 +235,8 @@ void nrf_state_operational(ogs_fsm_t *s, nrf_event_t *e) ogs_sbi_message_free(&message); break; - case NRF_EVT_SBI_TIMER: - switch(e->timer_id) { + case OGS_EVENT_SBI_TIMER: + switch(e->h.timer_id) { case NRF_TIMER_NF_INSTANCE_NO_HEARTBEAT: nf_instance = e->nf_instance; ogs_assert(nf_instance); @@ -261,7 +261,7 @@ void nrf_state_operational(ogs_fsm_t *s, nrf_event_t *e) default: ogs_error("Unknown timer[%s:%d]", - nrf_timer_get_name(e->timer_id), e->timer_id); + nrf_timer_get_name(e->h.timer_id), e->h.timer_id); } break; diff --git a/src/nrf/sbi-path.c b/src/nrf/sbi-path.c index b01c9a6e6..1fe3e26ea 100644 --- a/src/nrf/sbi-path.c +++ b/src/nrf/sbi-path.c @@ -19,34 +19,6 @@ #include "sbi-path.h" -static int server_cb(ogs_sbi_request_t *request, void *data) -{ - nrf_event_t *e = NULL; - int rv; - - ogs_assert(request); - ogs_assert(data); - - e = nrf_event_new(NRF_EVT_SBI_SERVER); - ogs_assert(e); - - e->sbi.request = request; - e->sbi.data = data; - - rv = ogs_queue_push(ogs_app()->queue, e); - if (rv != OGS_OK) { - if (rv != OGS_DONE) - ogs_error("ogs_queue_push() failed:%d", (int)rv); - else - ogs_warn("ogs_queue_push() failed:%d", (int)rv); - ogs_sbi_request_free(request); - nrf_event_free(e); - return OGS_ERROR; - } - - return OGS_OK; -} - static int client_notify_cb( int status, ogs_sbi_response_t *response, void *data) { @@ -80,7 +52,16 @@ static int client_notify_cb( int nrf_sbi_open(void) { - if (ogs_sbi_server_start_all(server_cb) != OGS_OK) + ogs_sbi_nf_instance_t *nf_instance = NULL; + + /* Initialize SELF NF instance */ + nf_instance = ogs_sbi_self()->nf_instance; + ogs_assert(nf_instance); + + /* Build NF instance information. */ + ogs_sbi_nf_instance_build_default(nf_instance, OpenAPI_nf_type_NRF); + + if (ogs_sbi_server_start_all(ogs_sbi_server_handler) != OGS_OK) return OGS_ERROR; return OGS_OK; @@ -97,18 +78,25 @@ bool nrf_nnrf_nfm_send_nf_status_notify( OpenAPI_notification_event_type_e event, ogs_sbi_nf_instance_t *nf_instance) { + bool rc; ogs_sbi_request_t *request = NULL; ogs_sbi_client_t *client = NULL; ogs_assert(subscription_data); client = subscription_data->client; - ogs_assert(client); + ogs_expect_or_return_val(client, false); request = nrf_nnrf_nfm_build_nf_status_notify( subscription_data, event, nf_instance); ogs_expect_or_return_val(request, false); - return ogs_sbi_scp_send_request(client, client_notify_cb, request, NULL); + rc = ogs_sbi_send_request_to_client( + client, client_notify_cb, request, NULL); + ogs_expect(rc == true); + + ogs_sbi_request_free(request); + + return rc; } bool nrf_nnrf_nfm_send_nf_status_notify_all( diff --git a/src/nrf/timer.c b/src/nrf/timer.c index ae295885b..bab8c03a8 100644 --- a/src/nrf/timer.c +++ b/src/nrf/timer.c @@ -19,9 +19,21 @@ #include "context.h" -const char *nrf_timer_get_name(nrf_timer_e id) +const char *nrf_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 NRF_TIMER_NF_INSTANCE_NO_HEARTBEAT: return "NRF_TIMER_NF_INSTANCE_NO_HEARTBEAT"; case NRF_TIMER_SUBSCRIPTION_VALIDITY: @@ -30,6 +42,7 @@ const char *nrf_timer_get_name(nrf_timer_e id) break; } + ogs_error("Unknown Timer[%d]", timer_id); return "UNKNOWN_TIMER"; } @@ -41,13 +54,13 @@ static void timer_send_event(int timer_id, void *data) switch (timer_id) { case NRF_TIMER_NF_INSTANCE_NO_HEARTBEAT: - e = nrf_event_new(NRF_EVT_SBI_TIMER); - e->timer_id = timer_id; + e = nrf_event_new(OGS_EVENT_SBI_TIMER); + e->h.timer_id = timer_id; e->nf_instance = data; break; case NRF_TIMER_SUBSCRIPTION_VALIDITY: - e = nrf_event_new(NRF_EVT_SBI_TIMER); - e->timer_id = timer_id; + e = nrf_event_new(OGS_EVENT_SBI_TIMER); + e->h.timer_id = timer_id; e->subscription_data = data; break; default: @@ -59,7 +72,7 @@ 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", (int)rv); - nrf_event_free(e); + ogs_event_free(e); } } diff --git a/src/nrf/timer.h b/src/nrf/timer.h index c995401ff..6217edeb8 100644 --- a/src/nrf/timer.h +++ b/src/nrf/timer.h @@ -28,7 +28,7 @@ extern "C" { /* forward declaration */ typedef enum { - NRF_TIMER_BASE = 0, + NRF_TIMER_BASE = OGS_MAX_NUM_OF_PROTO_TIMER, NRF_TIMER_NF_INSTANCE_NO_HEARTBEAT, NRF_TIMER_SUBSCRIPTION_VALIDITY, @@ -38,7 +38,7 @@ typedef enum { } nrf_timer_e; -const char *nrf_timer_get_name(nrf_timer_e id); +const char *nrf_timer_get_name(int timer_id); void nrf_timer_nf_instance_no_heartbeat(void *data); void nrf_timer_subscription_validity(void *data); diff --git a/src/nssf/event.h b/src/nssf/event.h index b78346d61..6b71db69a 100644 --- a/src/nssf/event.h +++ b/src/nssf/event.h @@ -32,6 +32,8 @@ typedef struct nssf_event_s { ogs_event_t h; } nssf_event_t; +OGS_STATIC_ASSERT(OGS_EVENT_SIZE >= sizeof(nssf_event_t)); + nssf_event_t *nssf_event_new(int id); const char *nssf_event_get_name(nssf_event_t *e); diff --git a/src/nssf/nssf-sm.c b/src/nssf/nssf-sm.c index b66539512..002ca5471 100644 --- a/src/nssf/nssf-sm.c +++ b/src/nssf/nssf-sm.c @@ -179,7 +179,7 @@ void nssf_state_operational(ogs_fsm_t *s, nssf_event_t *e) CASE(OGS_SBI_HTTP_METHOD_POST) if (message.res_status == OGS_SBI_HTTP_STATUS_CREATED || message.res_status == OGS_SBI_HTTP_STATUS_OK) { - ogs_nnrf_handle_nf_status_subscribe( + ogs_nnrf_nfm_handle_nf_status_subscribe( subscription_data, &message); } else { ogs_error("[%s] HTTP response error [%d]", diff --git a/src/nssf/sbi-path.c b/src/nssf/sbi-path.c index 1fd0d085c..7e3fc9166 100644 --- a/src/nssf/sbi-path.c +++ b/src/nssf/sbi-path.c @@ -19,67 +19,12 @@ #include "sbi-path.h" -static int server_cb(ogs_sbi_request_t *request, void *data) -{ - nssf_event_t *e = NULL; - int rv; - - ogs_assert(request); - ogs_assert(data); - - e = nssf_event_new(OGS_EVENT_SBI_SERVER); - ogs_assert(e); - - 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); - ogs_event_free(e); - return OGS_ERROR; - } - - return OGS_OK; -} - -static int client_cb(int status, ogs_sbi_response_t *response, void *data) -{ - nssf_event_t *e = NULL; - int rv; - - if (status != OGS_OK) { - ogs_log_message( - status == OGS_DONE ? OGS_LOG_DEBUG : OGS_LOG_WARN, 0, - "client_cb() failed [%d]", status); - return OGS_ERROR; - } - - ogs_assert(response); - - e = nssf_event_new(OGS_EVENT_SBI_CLIENT); - ogs_assert(e); - 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); - ogs_event_free(e); - return OGS_ERROR; - } - - return OGS_OK; -} - int nssf_sbi_open(void) { ogs_sbi_nf_instance_t *nf_instance = NULL; ogs_sbi_nf_service_t *service = NULL; - /* Add SELF NF instance */ + /* Initialize SELF NF instance */ nf_instance = ogs_sbi_self()->nf_instance; ogs_assert(nf_instance); ogs_sbi_nf_fsm_init(nf_instance); @@ -102,20 +47,10 @@ int nssf_sbi_open(void) /* Initialize NRF NF Instance */ 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; - - /* NFRegister is sent and the response is received - * by the above client callback. */ + if (nf_instance) ogs_sbi_nf_fsm_init(nf_instance); - } - if (ogs_sbi_server_start_all(server_cb) != OGS_OK) + if (ogs_sbi_server_start_all(ogs_sbi_server_handler) != OGS_OK) return OGS_ERROR; return OGS_OK; diff --git a/src/pcf/event.h b/src/pcf/event.h index 5f746dd5b..38e2a6f7f 100644 --- a/src/pcf/event.h +++ b/src/pcf/event.h @@ -38,6 +38,8 @@ typedef struct pcf_event_s { pcf_app_t *app; } pcf_event_t; +OGS_STATIC_ASSERT(OGS_EVENT_SIZE >= sizeof(pcf_event_t)); + pcf_event_t *pcf_event_new(int id); const char *pcf_event_get_name(pcf_event_t *e); diff --git a/src/pcf/naf-build.c b/src/pcf/naf-build.c index 0733ce19d..ca2f7007f 100644 --- a/src/pcf/naf-build.c +++ b/src/pcf/naf-build.c @@ -31,12 +31,18 @@ ogs_sbi_request_t *pcf_naf_callback_build_policyauthorization_terminate( message.h.method = (char *)OGS_SBI_HTTP_METHOD_POST; message.h.uri = ogs_msprintf("%s/%s", app_session->notif_uri, OGS_SBI_RESOURCE_NAME_TERMINATE); - ogs_assert(message.h.uri); + if (!message.h.uri) { + ogs_error("No message.h.uri"); + goto end; + } request = ogs_sbi_build_request(&message); ogs_assert(request); - ogs_free(message.h.uri); +end: + + if (message.h.uri) + ogs_free(message.h.uri); return request; } diff --git a/src/pcf/nbsf-build.c b/src/pcf/nbsf-build.c index 5366e981a..93fdc0509 100644 --- a/src/pcf/nbsf-build.c +++ b/src/pcf/nbsf-build.c @@ -59,18 +59,27 @@ ogs_sbi_request_t *pcf_nbsf_management_build_register( PcfBinding.ipv4_addr = sess->ipv4addr_string; PcfBinding.ipv6_prefix = sess->ipv6prefix_string; - ogs_expect_or_return_val(sess->dnn, NULL); + if (!sess->dnn) { + ogs_error("No DNN"); + goto end; + } PcfBinding.dnn = sess->dnn; nf_service = ogs_sbi_nf_service_find_by_name( nf_instance, (char *)OGS_SBI_SERVICE_NAME_NPCF_POLICYAUTHORIZATION); - ogs_expect_or_return_val(nf_service, NULL); + if (!nf_service) { + ogs_error("No NF-Service"); + goto end; + } if (nf_service->fqdn) PcfBinding.pcf_fqdn = ogs_strdup(nf_service->fqdn); - PcfIpEndPointList = OpenAPI_list_create(); - ogs_assert(PcfIpEndPointList); + PcfBinding.pcf_ip_end_points = PcfIpEndPointList = OpenAPI_list_create(); + if (!PcfIpEndPointList) { + ogs_error("No PcfIpEndPointList"); + goto end; + } for (i = 0; i < nf_service->num_of_addr; i++) { ogs_sockaddr_t *ipv4 = NULL; @@ -83,15 +92,30 @@ ogs_sbi_request_t *pcf_nbsf_management_build_register( if (ipv4 || ipv6) { IpEndPoint = ogs_calloc(1, sizeof(*IpEndPoint)); - ogs_expect_or_return_val(IpEndPoint, NULL); + if (!IpEndPoint) { + ogs_error("No IpEndPoint"); + goto end; + } if (ipv4) { IpEndPoint->ipv4_address = ogs_ipstrdup(ipv4); - ogs_expect_or_return_val(IpEndPoint->ipv4_address, NULL); + if (!IpEndPoint->ipv4_address) { + ogs_error("No IpEndPoint->ipv4_address"); + if (IpEndPoint) + ogs_free(IpEndPoint); + goto end; + } } if (ipv6) { IpEndPoint->ipv6_address = ogs_ipstrdup(ipv6); - ogs_expect_or_return_val(IpEndPoint->ipv6_address, NULL); - + if (!IpEndPoint->ipv6_address) { + ogs_error("No IpEndPoint->ipv6_address"); + if (IpEndPoint) { + if (IpEndPoint->ipv6_address) + ogs_free(IpEndPoint->ipv6_address); + ogs_free(IpEndPoint); + } + goto end; + } } IpEndPoint->is_port = true; IpEndPoint->port = nf_service->addr[i].port; @@ -99,12 +123,10 @@ ogs_sbi_request_t *pcf_nbsf_management_build_register( } } - if (PcfIpEndPointList->count) - PcfBinding.pcf_ip_end_points = PcfIpEndPointList; - else - OpenAPI_list_free(PcfIpEndPointList); - - ogs_expect_or_return_val(sess->s_nssai.sst, NULL); + if (!sess->s_nssai.sst) { + ogs_error("No SST"); + goto end; + } memset(&sNssai, 0, sizeof(sNssai)); sNssai.sst = sess->s_nssai.sst; sNssai.sd = ogs_s_nssai_sd_to_string(sess->s_nssai.sd); @@ -112,13 +134,18 @@ ogs_sbi_request_t *pcf_nbsf_management_build_register( if (sess->management_features) { PcfBinding.supp_feat = ogs_uint64_to_string(sess->management_features); - ogs_expect_or_return_val(PcfBinding.supp_feat, NULL); + if (!PcfBinding.supp_feat) { + ogs_error("No supp_feat"); + goto end; + } } message.PcfBinding = &PcfBinding; request = ogs_sbi_build_request(&message); ogs_expect(request); + +end: if (sNssai.sd) ogs_free(sNssai.sd); diff --git a/src/pcf/nnrf-handler.c b/src/pcf/nnrf-handler.c index 18af3bf5c..53b744e2e 100644 --- a/src/pcf/nnrf-handler.c +++ b/src/pcf/nnrf-handler.c @@ -33,6 +33,7 @@ void pcf_nnrf_handle_nf_discover( pcf_sess_t *sess = NULL; OpenAPI_nf_type_e target_nf_type = OpenAPI_nf_type_NULL; + OpenAPI_nf_type_e requester_nf_type = OpenAPI_nf_type_NULL; OpenAPI_search_result_t *SearchResult = NULL; ogs_assert(recvmsg); @@ -43,6 +44,8 @@ void pcf_nnrf_handle_nf_discover( ogs_assert(service_type); target_nf_type = ogs_sbi_service_type_to_nf_type(service_type); ogs_assert(target_nf_type); + requester_nf_type = xact->requester_nf_type; + ogs_assert(requester_nf_type); discovery_option = xact->discovery_option; stream = xact->assoc_stream; @@ -67,15 +70,16 @@ void pcf_nnrf_handle_nf_discover( ogs_assert_if_reached(); } - ogs_nnrf_handle_nf_discover_search_result(SearchResult); + ogs_nnrf_disc_handle_nf_discover_search_result(SearchResult); nf_instance = ogs_sbi_nf_instance_find_by_discovery_param( - target_nf_type, discovery_option); + target_nf_type, requester_nf_type, discovery_option); if (!nf_instance) { - ogs_error("[%s:%d] (NF discover) No [%s]", + ogs_error("[%s:%d] (NF discover) No [%s:%s]", pcf_ue ? pcf_ue->supi : "Unknown", sess ? sess->psi : 0, - ogs_sbi_service_type_to_name(service_type)); + ogs_sbi_service_type_to_name(service_type), + OpenAPI_nf_type_ToString(requester_nf_type)); return; } diff --git a/src/pcf/nsmf-build.c b/src/pcf/nsmf-build.c index 284032a21..31f0479dd 100644 --- a/src/pcf/nsmf-build.c +++ b/src/pcf/nsmf-build.c @@ -35,7 +35,10 @@ ogs_sbi_request_t *pcf_nsmf_callback_build_smpolicycontrol_update( ogs_assert(sess->notification_uri); server = ogs_list_first(&ogs_sbi_self()->server_list); - ogs_assert(server); + if (!server) { + ogs_error("No server"); + goto end; + } memset(&header, 0, sizeof(header)); header.service.name = (char *)OGS_SBI_SERVICE_NAME_NPCF_SMPOLICYCONTROL; @@ -47,7 +50,10 @@ ogs_sbi_request_t *pcf_nsmf_callback_build_smpolicycontrol_update( memset(&SmPolicyNotification, 0, sizeof(SmPolicyNotification)); SmPolicyNotification.resource_uri = ogs_sbi_server_uri(server, &header); - ogs_assert(SmPolicyNotification.resource_uri); + if (!SmPolicyNotification.resource_uri) { + ogs_error("No resource_uri"); + goto end; + } SmPolicyDecision = data; ogs_assert(SmPolicyDecision); @@ -58,15 +64,22 @@ ogs_sbi_request_t *pcf_nsmf_callback_build_smpolicycontrol_update( message.h.method = (char *)OGS_SBI_HTTP_METHOD_POST; message.h.uri = ogs_msprintf("%s/%s", sess->notification_uri, OGS_SBI_RESOURCE_NAME_UPDATE); - ogs_assert(message.h.uri); + if (!message.h.uri) { + ogs_error("No message.h.uri"); + goto end; + } message.SmPolicyNotification = &SmPolicyNotification; request = ogs_sbi_build_request(&message); ogs_assert(request); - ogs_free(SmPolicyNotification.resource_uri); - ogs_free(message.h.uri); +end: + + if (SmPolicyNotification.resource_uri) + ogs_free(SmPolicyNotification.resource_uri); + if (message.h.uri) + ogs_free(message.h.uri); return request; } @@ -93,12 +106,18 @@ ogs_sbi_request_t *pcf_nsmf_callback_build_smpolicycontrol_terminate( message.h.method = (char *)OGS_SBI_HTTP_METHOD_POST; message.h.uri = ogs_msprintf("%s/%s", sess->notification_uri, OGS_SBI_RESOURCE_NAME_TERMINATE); - ogs_assert(message.h.uri); + if (!message.h.uri) { + ogs_error("No message.h.uri"); + goto end; + } request = ogs_sbi_build_request(&message); ogs_assert(request); - ogs_free(message.h.uri); +end: + + if (message.h.uri) + ogs_free(message.h.uri); return request; } diff --git a/src/pcf/nudr-handler.c b/src/pcf/nudr-handler.c index e50d61bbe..b510a8ae5 100644 --- a/src/pcf/nudr-handler.c +++ b/src/pcf/nudr-handler.c @@ -200,8 +200,11 @@ bool pcf_nudr_dr_handle_query_sm_data( nf_instance = sess->sbi.service_type_array[service_type].nf_instance; if (!nf_instance) { - nf_instance = - ogs_sbi_nf_instance_find_by_service_type(service_type); + OpenAPI_nf_type_e requester_nf_type = + NF_INSTANCE_TYPE(ogs_sbi_self()->nf_instance); + ogs_assert(requester_nf_type); + nf_instance = ogs_sbi_nf_instance_find_by_service_type( + service_type, requester_nf_type); if (nf_instance) OGS_SBI_SETUP_NF_INSTANCE( sess->sbi.service_type_array[service_type], diff --git a/src/pcf/pcf-sm.c b/src/pcf/pcf-sm.c index 785b2a248..3944e8386 100644 --- a/src/pcf/pcf-sm.c +++ b/src/pcf/pcf-sm.c @@ -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) - ogs_nnrf_handle_nf_status_notify(stream, &message); + ogs_nnrf_nfm_handle_nf_status_notify(stream, &message); break; DEFAULT @@ -330,7 +330,7 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e) CASE(OGS_SBI_HTTP_METHOD_POST) if (message.res_status == OGS_SBI_HTTP_STATUS_CREATED || message.res_status == OGS_SBI_HTTP_STATUS_OK) { - ogs_nnrf_handle_nf_status_subscribe( + ogs_nnrf_nfm_handle_nf_status_subscribe( subscription_data, &message); } else { ogs_error("[%s] HTTP response error [%d]", diff --git a/src/pcf/sbi-path.c b/src/pcf/sbi-path.c index 2aab13137..86604e226 100644 --- a/src/pcf/sbi-path.c +++ b/src/pcf/sbi-path.c @@ -19,61 +19,6 @@ #include "sbi-path.h" -static int server_cb(ogs_sbi_request_t *request, void *data) -{ - pcf_event_t *e = NULL; - int rv; - - ogs_assert(request); - ogs_assert(data); - - e = pcf_event_new(OGS_EVENT_SBI_SERVER); - ogs_assert(e); - - 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); - ogs_event_free(e); - return OGS_ERROR; - } - - return OGS_OK; -} - -static int client_cb(int status, ogs_sbi_response_t *response, void *data) -{ - pcf_event_t *e = NULL; - int rv; - - if (status != OGS_OK) { - ogs_log_message( - status == OGS_DONE ? OGS_LOG_DEBUG : OGS_LOG_WARN, 0, - "client_cb() failed [%d]", status); - return OGS_ERROR; - } - - ogs_assert(response); - - e = pcf_event_new(OGS_EVENT_SBI_CLIENT); - ogs_assert(e); - 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); - ogs_event_free(e); - return OGS_ERROR; - } - - return OGS_OK; -} - int pcf_sbi_open(void) { ogs_sbi_nf_instance_t *nf_instance = NULL; @@ -82,7 +27,7 @@ int pcf_sbi_open(void) bool smpolicycontrol_enabled = false; bool policyauthorization_enabled = false; - /* Add SELF NF instance */ + /* Initialize SELF NF instance */ nf_instance = ogs_sbi_self()->nf_instance; ogs_assert(nf_instance); ogs_sbi_nf_fsm_init(nf_instance); @@ -148,18 +93,8 @@ int pcf_sbi_open(void) /* Initialize NRF NF Instance */ 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; - - /* NFRegister is sent and the response is received - * by the above client callback. */ + if (nf_instance) ogs_sbi_nf_fsm_init(nf_instance); - } /* Build Subscription-Data */ ogs_sbi_subscription_data_build_default( @@ -167,7 +102,7 @@ int pcf_sbi_open(void) ogs_sbi_subscription_data_build_default( OpenAPI_nf_type_UDR, OGS_SBI_SERVICE_NAME_NUDR_DR); - if (ogs_sbi_server_start_all(server_cb) != OGS_OK) + if (ogs_sbi_server_start_all(ogs_sbi_server_handler) != OGS_OK) return OGS_ERROR; return OGS_OK; @@ -179,11 +114,12 @@ void pcf_sbi_close(void) ogs_sbi_server_stop_all(); } -bool pcf_sbi_send_request(ogs_sbi_nf_instance_t *nf_instance, void *data) +bool pcf_sbi_send_request( + ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_xact_t *xact) { ogs_assert(nf_instance); - - return ogs_sbi_send_request(nf_instance, client_cb, data); + ogs_assert(xact); + return ogs_sbi_send_request_to_nf_instance(nf_instance, xact); } static bool pcf_sbi_discover_and_send( @@ -207,7 +143,7 @@ static bool pcf_sbi_discover_and_send( xact->assoc_stream = stream; - if (ogs_sbi_discover_and_send(xact, client_cb) != true) { + if (ogs_sbi_discover_and_send(xact) != true) { ogs_error("ogs_sbi_discover_and_send() failed"); ogs_sbi_xact_remove(xact); return false; @@ -250,7 +186,7 @@ bool pcf_sess_sbi_discover_only( xact->assoc_stream = stream; - return ogs_sbi_discover_only(xact, client_cb); + return ogs_sbi_discover_only(xact); } bool pcf_sess_sbi_discover_and_send( @@ -320,6 +256,7 @@ static int client_delete_notify_cb( bool pcf_sbi_send_am_policy_control_notify(pcf_ue_t *pcf_ue) { + bool rc; ogs_sbi_request_t *request = NULL; ogs_sbi_client_t *client = NULL; @@ -329,12 +266,20 @@ bool pcf_sbi_send_am_policy_control_notify(pcf_ue_t *pcf_ue) request = pcf_namf_callback_build_am_policy_control(pcf_ue, NULL); ogs_expect_or_return_val(request, false); - return ogs_sbi_client_send_request(client, client_notify_cb, request, NULL); + + rc = ogs_sbi_send_request_to_client( + client, client_notify_cb, request, NULL); + ogs_expect(rc == true); + + ogs_sbi_request_free(request); + + return rc; } bool pcf_sbi_send_smpolicycontrol_update_notify( pcf_sess_t *sess, OpenAPI_sm_policy_decision_t *SmPolicyDecision) { + bool rc; ogs_sbi_request_t *request = NULL; ogs_sbi_client_t *client = NULL; @@ -345,13 +290,21 @@ bool pcf_sbi_send_smpolicycontrol_update_notify( request = pcf_nsmf_callback_build_smpolicycontrol_update( sess, SmPolicyDecision); ogs_expect_or_return_val(request, false); - return ogs_sbi_client_send_request(client, client_notify_cb, request, NULL); + + rc = ogs_sbi_send_request_to_client( + client, client_notify_cb, request, NULL); + ogs_expect(rc == true); + + ogs_sbi_request_free(request); + + return rc; } bool pcf_sbi_send_smpolicycontrol_delete_notify( pcf_sess_t *sess, pcf_app_t *app_session, OpenAPI_sm_policy_decision_t *SmPolicyDecision) { + bool rc; ogs_sbi_request_t *request = NULL; ogs_sbi_client_t *client = NULL; @@ -362,12 +315,19 @@ bool pcf_sbi_send_smpolicycontrol_delete_notify( request = pcf_nsmf_callback_build_smpolicycontrol_update( sess, SmPolicyDecision); ogs_expect_or_return_val(request, false); - return ogs_sbi_client_send_request( + + rc = ogs_sbi_send_request_to_client( client, client_delete_notify_cb, request, app_session); + ogs_expect(rc == true); + + ogs_sbi_request_free(request); + + return rc; } bool pcf_sbi_send_smpolicycontrol_terminate_notify(pcf_sess_t *sess) { + bool rc; ogs_sbi_request_t *request = NULL; ogs_sbi_client_t *client = NULL; @@ -377,11 +337,19 @@ bool pcf_sbi_send_smpolicycontrol_terminate_notify(pcf_sess_t *sess) request = pcf_nsmf_callback_build_smpolicycontrol_terminate(sess, NULL); ogs_expect_or_return_val(request, false); - return ogs_sbi_client_send_request(client, client_notify_cb, request, NULL); + + rc = ogs_sbi_send_request_to_client( + client, client_notify_cb, request, NULL); + ogs_expect(rc == true); + + ogs_sbi_request_free(request); + + return rc; } bool pcf_sbi_send_policyauthorization_terminate_notify(pcf_app_t *app) { + bool rc; ogs_sbi_request_t *request = NULL; ogs_sbi_client_t *client = NULL; @@ -391,5 +359,12 @@ bool pcf_sbi_send_policyauthorization_terminate_notify(pcf_app_t *app) request = pcf_naf_callback_build_policyauthorization_terminate(app, NULL); ogs_expect_or_return_val(request, false); - return ogs_sbi_client_send_request(client, client_notify_cb, request, NULL); + + rc = ogs_sbi_send_request_to_client( + client, client_notify_cb, request, NULL); + ogs_expect(rc == true); + + ogs_sbi_request_free(request); + + return rc; } diff --git a/src/pcf/sbi-path.h b/src/pcf/sbi-path.h index c44bdf456..0ee062a3f 100644 --- a/src/pcf/sbi-path.h +++ b/src/pcf/sbi-path.h @@ -33,7 +33,8 @@ extern "C" { int pcf_sbi_open(void); void pcf_sbi_close(void); -bool pcf_sbi_send_request(ogs_sbi_nf_instance_t *nf_instance, void *data); +bool pcf_sbi_send_request( + ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_xact_t *xact); bool pcf_ue_sbi_discover_and_send( ogs_sbi_service_type_e service_type, ogs_sbi_discovery_option_t *discovery_option, diff --git a/src/scp/context.c b/src/scp/context.c index 617f90b58..9417088fe 100644 --- a/src/scp/context.c +++ b/src/scp/context.c @@ -23,11 +23,11 @@ static scp_context_t self; int __scp_log_domain; -static OGS_POOL(scp_conn_pool, scp_conn_t); +static OGS_POOL(scp_assoc_pool, scp_assoc_t); static int context_initialized = 0; -static int max_num_of_scp_conn = 0; +static int max_num_of_scp_assoc = 0; void scp_context_init(void) { @@ -38,10 +38,10 @@ void scp_context_init(void) ogs_log_install_domain(&__scp_log_domain, "scp", ogs_core()->log.level); -#define MAX_NUM_OF_SCP_CONN 8 - max_num_of_scp_conn = ogs_app()->max.ue * MAX_NUM_OF_SCP_CONN; +#define MAX_NUM_OF_SCP_ASSOC 8 + max_num_of_scp_assoc = ogs_app()->max.ue * MAX_NUM_OF_SCP_ASSOC; - ogs_pool_init(&scp_conn_pool, max_num_of_scp_conn); + ogs_pool_init(&scp_assoc_pool, max_num_of_scp_assoc); context_initialized = 1; } @@ -50,9 +50,9 @@ void scp_context_final(void) { ogs_assert(context_initialized == 1); - scp_conn_remove_all(); + scp_assoc_remove_all(); - ogs_pool_final(&scp_conn_pool); + ogs_pool_final(&scp_assoc_pool); context_initialized = 0; } @@ -112,48 +112,50 @@ int scp_context_parse_config(void) return OGS_OK; } -scp_conn_t *scp_conn_add(ogs_sbi_stream_t *stream) +scp_assoc_t *scp_assoc_add(ogs_sbi_stream_t *stream) { - scp_conn_t *conn = NULL; + scp_assoc_t *assoc = NULL; ogs_assert(stream); - ogs_pool_alloc(&scp_conn_pool, &conn); - if (!conn) { - ogs_error("Maximum number of connection[%d] reached", - max_num_of_scp_conn); + ogs_pool_alloc(&scp_assoc_pool, &assoc); + if (!assoc) { + ogs_error("Maximum number of association[%d] reached", + max_num_of_scp_assoc); return NULL; } - memset(conn, 0, sizeof *conn); + memset(assoc, 0, sizeof *assoc); - conn->stream = stream; + assoc->stream = stream; - ogs_list_add(&self.conn_list, conn); + ogs_list_add(&self.assoc_list, assoc); - return conn; + return assoc; } -void scp_conn_remove(scp_conn_t *conn) +void scp_assoc_remove(scp_assoc_t *assoc) { - ogs_assert(conn); + ogs_assert(assoc); - ogs_list_remove(&self.conn_list, conn); + ogs_list_remove(&self.assoc_list, assoc); - if (conn->client) - ogs_sbi_client_remove(conn->client); + if (assoc->client) + ogs_sbi_client_remove(assoc->client); + if (assoc->nrf_client) + ogs_sbi_client_remove(assoc->nrf_client); - ogs_pool_free(&scp_conn_pool, conn); + ogs_pool_free(&scp_assoc_pool, assoc); } -void scp_conn_remove_all(void) +void scp_assoc_remove_all(void) { - scp_conn_t *conn = NULL, *next_conn = NULL; + scp_assoc_t *assoc = NULL, *next_assoc = NULL; - ogs_list_for_each_safe(&self.conn_list, next_conn, conn) - scp_conn_remove(conn); + ogs_list_for_each_safe(&self.assoc_list, next_assoc, assoc) + scp_assoc_remove(assoc); } -scp_conn_t *scp_conn_find(uint32_t index) +scp_assoc_t *scp_assoc_find(uint32_t index) { - return ogs_pool_find(&scp_conn_pool, index); + return ogs_pool_find(&scp_assoc_pool, index); } diff --git a/src/scp/context.h b/src/scp/context.h index 3e89b83f1..e5419059a 100644 --- a/src/scp/context.h +++ b/src/scp/context.h @@ -35,20 +35,25 @@ extern int __scp_log_domain; #define OGS_LOG_DOMAIN __scp_log_domain typedef struct scp_context_s { - ogs_list_t conn_list; + ogs_list_t assoc_list; } scp_context_t; -typedef struct scp_conn_s scp_conn_t; +typedef struct scp_assoc_s scp_assoc_t; -typedef struct scp_conn_s { +typedef struct scp_assoc_s { ogs_sbi_object_t sbi; - ogs_sbi_client_t *client; - ogs_sbi_stream_t *stream; - ogs_sbi_request_t *request; -} scp_conn_t; + ogs_sbi_client_t *client; + ogs_sbi_client_t *nrf_client; + + ogs_sbi_request_t *request; + ogs_sbi_service_type_e service_type; + OpenAPI_nf_type_e requester_nf_type; + + ogs_sbi_nf_instance_t *nf_service_producer; +} scp_assoc_t; void scp_context_init(void); void scp_context_final(void); @@ -56,11 +61,11 @@ scp_context_t *scp_self(void); int scp_context_parse_config(void); -scp_conn_t *scp_conn_add(ogs_sbi_stream_t *stream); -void scp_conn_remove(scp_conn_t *sess); -void scp_conn_remove_all(void); +scp_assoc_t *scp_assoc_add(ogs_sbi_stream_t *stream); +void scp_assoc_remove(scp_assoc_t *sess); +void scp_assoc_remove_all(void); -scp_conn_t *scp_conn_find(uint32_t index); +scp_assoc_t *scp_assoc_find(uint32_t index); #ifdef __cplusplus } diff --git a/src/scp/event.h b/src/scp/event.h index 229fdfefa..d5e233e2f 100644 --- a/src/scp/event.h +++ b/src/scp/event.h @@ -36,6 +36,8 @@ typedef struct scp_event_s { scp_sess_t *sess; } scp_event_t; +OGS_STATIC_ASSERT(OGS_EVENT_SIZE >= sizeof(scp_event_t)); + scp_event_t *scp_event_new(int id); const char *scp_event_get_name(scp_event_t *e); diff --git a/src/scp/meson.build b/src/scp/meson.build index 7ff874271..15b2b33dc 100644 --- a/src/scp/meson.build +++ b/src/scp/meson.build @@ -19,9 +19,6 @@ libscp_sources = files(''' context.c event.c - nnrf-handler.c - nscp-handler.c - sbi-path.c scp-sm.c diff --git a/src/scp/nnrf-handler.c b/src/scp/nnrf-handler.c deleted file mode 100644 index 5e7c6bc59..000000000 --- a/src/scp/nnrf-handler.c +++ /dev/null @@ -1,65 +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 "sbi-path.h" -#include "nnrf-handler.h" - -void scp_nnrf_handle_nf_discover( - ogs_sbi_xact_t *xact, ogs_sbi_message_t *recvmsg) -{ - ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_sbi_object_t *sbi_object = NULL; - ogs_sbi_service_type_e service_type = OGS_SBI_SERVICE_TYPE_NULL; - ogs_sbi_discovery_option_t *discovery_option = NULL; - - OpenAPI_nf_type_e target_nf_type = OpenAPI_nf_type_NULL; - OpenAPI_search_result_t *SearchResult = NULL; - - ogs_assert(recvmsg); - ogs_assert(xact); - sbi_object = xact->sbi_object; - ogs_assert(sbi_object); - service_type = xact->service_type; - ogs_assert(service_type); - target_nf_type = ogs_sbi_service_type_to_nf_type(service_type); - ogs_assert(target_nf_type); - - discovery_option = xact->discovery_option; - - SearchResult = recvmsg->SearchResult; - if (!SearchResult) { - ogs_error("No SearchResult"); - return; - } - - ogs_nnrf_handle_nf_discover_search_result(SearchResult); - - nf_instance = ogs_sbi_nf_instance_find_by_discovery_param( - target_nf_type, discovery_option); - if (!nf_instance) { - ogs_error("(NF discover) No [%s]", - ogs_sbi_service_type_to_name(service_type)); - return; - } - - OGS_SBI_SETUP_NF_INSTANCE( - sbi_object->service_type_array[service_type], nf_instance); - - ogs_expect(true == scp_sbi_send_request(nf_instance, xact)); -} diff --git a/src/scp/nscp-handler.c b/src/scp/nscp-handler.c deleted file mode 100644 index 091ba8206..000000000 --- a/src/scp/nscp-handler.c +++ /dev/null @@ -1,27 +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 "sbi-path.h" -#include "nscp-handler.h" - -bool scp_nscp_management_handle_pcf_binding( - scp_conn_t *conn, ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) -{ - return true; -} diff --git a/src/scp/nscp-handler.h b/src/scp/nscp-handler.h deleted file mode 100644 index 01f7dadc8..000000000 --- a/src/scp/nscp-handler.h +++ /dev/null @@ -1,36 +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_NSCP_HANDLER_H -#define SCP_NSCP_HANDLER_H - -#include "context.h" - -#ifdef __cplusplus -extern "C" { -#endif - -bool scp_nscp_management_handle_pcf_binding( - scp_conn_t *conn, ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); - -#ifdef __cplusplus -} -#endif - -#endif /* SCP_NSCP_HANDLER_H */ diff --git a/src/scp/sbi-path.c b/src/scp/sbi-path.c index 777c27f06..da7b2ea99 100644 --- a/src/scp/sbi-path.c +++ b/src/scp/sbi-path.c @@ -22,14 +22,19 @@ static int request_handler(ogs_sbi_request_t *request, void *data); static int response_handler( int status, ogs_sbi_response_t *response, void *data); +static int discover_handler( + int status, ogs_sbi_response_t *response, void *data); -static int client_cb(int status, ogs_sbi_response_t *response, void *data); +static void copy_request( + ogs_sbi_request_t *target, ogs_sbi_request_t *source, + bool include_discovery); int scp_sbi_open(void) { - ogs_sbi_nf_instance_t *nf_instance = NULL; + ogs_sbi_nf_instance_t *nf_instance = NULL, *nrf_instance = NULL; + ogs_sbi_client_t *nrf_client = NULL, *next_scp = NULL; - /* Add SELF NF instance */ + /* Initialize SELF NF instance */ nf_instance = ogs_sbi_self()->nf_instance; ogs_assert(nf_instance); ogs_sbi_nf_fsm_init(nf_instance); @@ -37,30 +42,43 @@ int scp_sbi_open(void) /* Build NF instance information. It will be transmitted to NRF. */ ogs_sbi_nf_instance_build_default(nf_instance, OpenAPI_nf_type_SCP); - /* Initialize NRF NF Instance */ - nf_instance = ogs_sbi_self()->nrf_instance; - if (nf_instance) { - ogs_sbi_client_t *client = NULL; + /* + * If the SCP is running in Model D, + * it can send NFRegister/NFStatusSubscribe messages to the NRF. + */ + nrf_instance = ogs_sbi_self()->nrf_instance; + nrf_client = NF_INSTANCE_CLIENT(ogs_sbi_self()->nrf_instance); - /* Client callback is only used when NF sends to NRF */ - client = nf_instance->client; - ogs_assert(client); - client->cb = client_cb; + if (nrf_client) { - /* NFRegister is sent and the response is received - * by the above client callback. */ - ogs_sbi_nf_fsm_init(nf_instance); + /* Initialize NRF NF Instance */ + if (nrf_instance) + ogs_sbi_nf_fsm_init(nrf_instance); } - /* Build Subscription-Data */ - ogs_sbi_subscription_data_build_default(OpenAPI_nf_type_AMF, NULL); - ogs_sbi_subscription_data_build_default(OpenAPI_nf_type_AUSF, NULL); - ogs_sbi_subscription_data_build_default(OpenAPI_nf_type_BSF, NULL); - ogs_sbi_subscription_data_build_default(OpenAPI_nf_type_NSSF, NULL); - ogs_sbi_subscription_data_build_default(OpenAPI_nf_type_PCF, NULL); - ogs_sbi_subscription_data_build_default(OpenAPI_nf_type_SMF, NULL); - ogs_sbi_subscription_data_build_default(OpenAPI_nf_type_UDM, NULL); - ogs_sbi_subscription_data_build_default(OpenAPI_nf_type_UDR, NULL); + /* Check if Next-SCP's client */ + if (ogs_sbi_self()->discovery_config.delegated == + OGS_SBI_DISCOVERY_DELEGATED_AUTO) { + next_scp = NF_INSTANCE_CLIENT(ogs_sbi_self()->scp_instance); + } else if (ogs_sbi_self()->discovery_config.delegated == + OGS_SBI_DISCOVERY_DELEGATED_YES) { + next_scp = NF_INSTANCE_CLIENT(ogs_sbi_self()->scp_instance); + ogs_assert(next_scp); + } + + /* If the SCP has an NRF client and does not delegate to Next-SCP */ + if (nrf_client && !next_scp) { + + /* Build Subscription-Data */ + ogs_sbi_subscription_data_build_default(OpenAPI_nf_type_AMF, NULL); + ogs_sbi_subscription_data_build_default(OpenAPI_nf_type_AUSF, NULL); + ogs_sbi_subscription_data_build_default(OpenAPI_nf_type_BSF, NULL); + ogs_sbi_subscription_data_build_default(OpenAPI_nf_type_NSSF, NULL); + ogs_sbi_subscription_data_build_default(OpenAPI_nf_type_PCF, NULL); + ogs_sbi_subscription_data_build_default(OpenAPI_nf_type_SMF, NULL); + ogs_sbi_subscription_data_build_default(OpenAPI_nf_type_UDM, NULL); + ogs_sbi_subscription_data_build_default(OpenAPI_nf_type_UDR, NULL); + } if (ogs_sbi_server_start_all(request_handler) != OGS_OK) return OGS_ERROR; @@ -74,25 +92,651 @@ void scp_sbi_close(void) ogs_sbi_server_stop_all(); } -static int request_handler(ogs_sbi_request_t *source, void *data) +static int request_handler(ogs_sbi_request_t *request, void *data) { int rv; ogs_hash_index_t *hi; + ogs_sbi_client_t *client = NULL, *nrf_client = NULL, *next_scp = NULL; ogs_sbi_stream_t *stream = data; + ogs_sbi_request_t scp_request; + char *apiroot = NULL, *newuri = NULL; + + OpenAPI_nf_type_e target_nf_type = OpenAPI_nf_type_NULL; + OpenAPI_nf_type_e requester_nf_type = OpenAPI_nf_type_NULL; + ogs_sbi_discovery_option_t *discovery_option = NULL; + ogs_sbi_service_type_e service_type = OGS_SBI_SERVICE_TYPE_NULL; + bool discovery_presence = false; + + scp_assoc_t *assoc = NULL; + ogs_sbi_nf_instance_t *nf_instance = NULL; + struct { char *target_apiroot; - char *discovery; - char *accept; - char *content_type; - char *content_encoding; - } headers; + char *callback; + char *nrf_uri; + } headers = { + NULL, NULL, NULL + }; - ogs_assert(source); - ogs_assert(source->h.uri); + scp_event_t *e = NULL; + + ogs_assert(request); + ogs_assert(request->h.uri); ogs_assert(stream); - memset(&headers, 0, sizeof(headers)); + /* Check if Next-SCP's client */ + if (ogs_sbi_self()->discovery_config.delegated == + OGS_SBI_DISCOVERY_DELEGATED_AUTO) { + next_scp = NF_INSTANCE_CLIENT(ogs_sbi_self()->scp_instance); + } else if (ogs_sbi_self()->discovery_config.delegated == + OGS_SBI_DISCOVERY_DELEGATED_YES) { + next_scp = NF_INSTANCE_CLIENT(ogs_sbi_self()->scp_instance); + ogs_assert(next_scp); + } + + discovery_option = ogs_sbi_discovery_option_new(); + ogs_assert(discovery_option); + + /* Extract HTTP Header */ + for (hi = ogs_hash_first(request->http.headers); + hi; hi = ogs_hash_next(hi)) { + char *key = (char *)ogs_hash_this_key(hi); + char *val = ogs_hash_this_val(hi); + + if (!key || !val) { + ogs_error("No Key[%s] Value[%s]", key, val); + continue; + } + + /* + * + * Each header field consists of a name followed by a colon (":") + * and the field value. Field names are case-insensitive. + */ + if (!strcasecmp(key, OGS_SBI_USER_AGENT)) { + if (val) requester_nf_type = OpenAPI_nf_type_FromString(val); + } else if (!strcasecmp(key, OGS_SBI_CUSTOM_TARGET_APIROOT)) { + headers.target_apiroot = val; + } else if (!strcasecmp(key, OGS_SBI_CUSTOM_CALLBACK)) { + headers.callback = val; + } else if (!strcasecmp(key, OGS_SBI_CUSTOM_NRF_URI)) { + headers.nrf_uri = val; + } else if (!strcasecmp(key, OGS_SBI_CUSTOM_DISCOVERY_TARGET_NF_TYPE)) { + if (val) target_nf_type = OpenAPI_nf_type_FromString(val); + } else if (!strcasecmp(key, + OGS_SBI_CUSTOM_DISCOVERY_REQUESTER_NF_TYPE)) { + ogs_warn("Use User-Agent instead of Discovery-requester-nf-type"); + } else if (!strcasecmp(key, + OGS_SBI_CUSTOM_DISCOVERY_TARGET_NF_INSTANCE_ID)) { + ogs_sbi_discovery_option_set_target_nf_instance_id( + discovery_option, val); + } else if (!strcasecmp(key, + OGS_SBI_CUSTOM_DISCOVERY_REQUESTER_NF_INSTANCE_ID)) { + ogs_sbi_discovery_option_set_requester_nf_instance_id( + discovery_option, val); + } else if (!strcasecmp(key, OGS_SBI_CUSTOM_DISCOVERY_SERVICE_NAMES)) { + if (val) + ogs_sbi_discovery_option_parse_service_names( + discovery_option, val); + + /* + * So, we'll use the first item in service-names list. + * + * TS29.500 + * 6.10 Support of Indirect Communication + * 6.10.3 NF Discovery and Selection for indirect communication + * with Delegated Discovery + * 6.10.3.2 Conveyance of NF Discovery Factors + * + * If the NF service consumer includes more than one service name + * in the 3gpp-Sbi-Discovery-service-names header, the service name + * corresponding to the service request shall be listed + * as the first service name in the header. + * + * NOTE 3: The SCP can assume that the service request corresponds + * to the first service name in the header. + */ + if (discovery_option->num_of_service_names) { + service_type = ogs_sbi_service_type_from_name( + discovery_option->service_names[0]); + } + } else if (!strcasecmp(key, OGS_SBI_SCHEME)) { + /* ':scheme' will be automatically filled in later */ + } else if (!strcasecmp(key, OGS_SBI_AUTHORITY)) { + /* ':authority' will be automatically filled in later */ + } else { + } + } + + /* Check if Discovery Parameter and Option */ + discovery_presence = false; + + if (!requester_nf_type) { + ogs_error("[%s] No User-Agent", request->h.uri); + + ogs_sbi_discovery_option_free(discovery_option); + return OGS_ERROR; + } + + if (target_nf_type || service_type) { + if (!target_nf_type || !service_type) { + ogs_error("[%s] No Mandatory Discovery [%d:%d]", + request->h.uri, target_nf_type, service_type); + + ogs_sbi_discovery_option_free(discovery_option); + return OGS_ERROR; + } + + if (target_nf_type == OpenAPI_nf_type_NRF) + client = NF_INSTANCE_CLIENT(ogs_sbi_self()->nrf_instance); + else { + if (discovery_option && discovery_option->target_nf_instance_id) { + nf_instance = ogs_sbi_nf_instance_find( + discovery_option->target_nf_instance_id); + if (nf_instance) { + client = ogs_sbi_client_find_by_service_type( + nf_instance, service_type); + if (!client) { + ogs_error("[%s:%s] Cannot find client [%s:%s]", + OpenAPI_nf_type_ToString(nf_instance->nf_type), + nf_instance->id, + OpenAPI_nf_type_ToString(target_nf_type), + ogs_sbi_service_type_to_name(service_type)); + } + } + } + } + + discovery_presence = true; + } + + /************************************ + * Send REQUEST message to the CLIENT + ************************************/ + if (next_scp || headers.target_apiroot || client) { + assoc = scp_assoc_add(stream); + if (!assoc) { + ogs_error("scp_assoc_add() failed"); + ogs_sbi_discovery_option_free(discovery_option); + return OGS_ERROR; + } + + if (next_scp) { + /* Switch to the Next-SCP's client */ + client = next_scp; + + /* Client ApiRoot */ + apiroot = ogs_sbi_client_apiroot(client); + ogs_assert(apiroot); + + /* Setup New URI */ + newuri = ogs_msprintf("%s%s", apiroot, request->h.uri); + ogs_assert(newuri); + + ogs_free(apiroot); + + } else if (headers.target_apiroot) { + ogs_sockaddr_t *addr = NULL; + + /* Find or Add Client Instance */ + addr = ogs_sbi_getaddr_from_uri(headers.target_apiroot); + if (!addr) { + ogs_error("Invalid Target-apiRoot [%s]", + headers.target_apiroot); + + ogs_sbi_discovery_option_free(discovery_option); + scp_assoc_remove(assoc); + + return OGS_ERROR; + } + + client = ogs_sbi_client_find(addr); + if (!client) { + client = ogs_sbi_client_add(addr); + ogs_assert(client); + } + OGS_SBI_SETUP_CLIENT(assoc, client); + + ogs_freeaddrinfo(addr); + + /* Setup New URI */ + newuri = ogs_msprintf("%s%s", + headers.target_apiroot, request->h.uri); + ogs_assert(newuri); + + } else if (client) { + /* Client ApiRoot */ + apiroot = ogs_sbi_client_apiroot(client); + ogs_assert(apiroot); + + /* Setup New URI */ + newuri = ogs_msprintf("%s%s", apiroot, request->h.uri); + ogs_assert(newuri); + + ogs_free(apiroot); + } + + /* Check assocation and client instance */ + ogs_assert(assoc); + ogs_assert(client); + + /* Copy Request for sending SCP */ + copy_request(&scp_request, request, next_scp ? true : false); + ogs_assert(scp_request.http.headers); + + /* Setup NEW URI */ + scp_request.h.uri = newuri; + ogs_assert(scp_request.h.uri); + + /* Send the HTTP Request with New URI and HTTP Headers */ + if (ogs_sbi_client_send_request( + client, response_handler, &scp_request, assoc) != true) { + ogs_error("ogs_sbi_client_send_request() failed"); + + ogs_sbi_http_hash_free(scp_request.http.headers); + ogs_free(scp_request.h.uri); + ogs_sbi_discovery_option_free(discovery_option); + scp_assoc_remove(assoc); + + return OGS_ERROR; + } + + ogs_sbi_http_hash_free(scp_request.http.headers); + ogs_free(scp_request.h.uri); + ogs_sbi_discovery_option_free(discovery_option); + + return OGS_OK; + } + + /******************************* + * Send DISCOVERY message to NRF + *******************************/ + if (discovery_presence == true) { + ogs_sbi_request_t *nrf_request = NULL; + + assoc = scp_assoc_add(stream); + if (!assoc) { + ogs_error("scp_assoc_add() failed"); + ogs_sbi_discovery_option_free(discovery_option); + return OGS_ERROR; + } + + if (headers.nrf_uri) { + char *key = NULL; + char *nnrf_disc = NULL; + char *nnrf_nfm = NULL; + char *nnrf_oauth2 = NULL; + + char *tmp = NULL, *p = NULL; + char *v_start = NULL, *v_end = NULL; + + tmp = ogs_strdup(headers.nrf_uri); + ogs_assert(tmp); + + for (key = ogs_strtok_r(tmp, ": ", &p); + key != NULL; key = ogs_strtok_r(NULL, ": ", &p)) { + + v_start = v_end = NULL; + + while (*p++) { + if (*p == ';') { + if ((v_start && v_end) || !v_start) { + p++; + break; + } + } else if (*p == '"') { + if (!v_start) v_start = p+1; + else if (!v_end) v_end = p; + } + } + + if (v_start && v_end) { + SWITCH(key) + CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) + nnrf_nfm = ogs_strndup(v_start, v_end-v_start); + break; + CASE(OGS_SBI_SERVICE_NAME_NNRF_DISC) + nnrf_disc = ogs_strndup(v_start, v_end-v_start); + break; + CASE(OGS_SBI_SERVICE_NAME_NNRF_OAUTH2) + nnrf_oauth2 = ogs_strndup(v_start, v_end-v_start); + break; + DEFAULT + END + } + } + + ogs_free(tmp); + + /* Find or Add Client Instance */ + if (nnrf_disc) { + ogs_sockaddr_t *addr = NULL; + + addr = ogs_sbi_getaddr_from_uri(nnrf_disc); + if (!addr) { + ogs_error("Invalid nnrf-disc [%s]", nnrf_disc); + + ogs_sbi_discovery_option_free(discovery_option); + scp_assoc_remove(assoc); + + return OGS_ERROR; + } + + nrf_client = ogs_sbi_client_find(addr); + if (!nrf_client) { + nrf_client = ogs_sbi_client_add(addr); + ogs_assert(nrf_client); + } + OGS_SBI_SETUP_CLIENT(assoc, nrf_client); + + ogs_freeaddrinfo(addr); + } + + if (nnrf_nfm) ogs_free(nnrf_nfm); + if (nnrf_disc) ogs_free(nnrf_disc); + if (nnrf_oauth2) ogs_free(nnrf_oauth2); + } + + if (!nrf_client) { + nrf_client = NF_INSTANCE_CLIENT(ogs_sbi_self()->nrf_instance); + if (!nrf_client) { + ogs_error("No NRF"); + + ogs_sbi_discovery_option_free(discovery_option); + scp_assoc_remove(assoc); + + return OGS_ERROR; + } + } + + /* Store request and service-type in association context */ + assoc->request = request; + ogs_assert(assoc->request); + assoc->service_type = service_type; + ogs_assert(assoc->service_type); + assoc->requester_nf_type = requester_nf_type; + ogs_assert(assoc->requester_nf_type); + + ogs_assert(target_nf_type); + ogs_assert(discovery_option); + + nrf_request = ogs_nnrf_disc_build_discover( + target_nf_type, requester_nf_type, discovery_option); + if (!nrf_request) { + ogs_error("ogs_nnrf_disc_build_discover() failed"); + + ogs_sbi_discovery_option_free(discovery_option); + scp_assoc_remove(assoc); + + return OGS_ERROR; + } + + if (false == ogs_sbi_client_send_request( + nrf_client, discover_handler, nrf_request, assoc)) { + ogs_error("ogs_sbi_client_send_request() failed"); + + scp_assoc_remove(assoc); + + ogs_sbi_request_free(nrf_request); + ogs_sbi_discovery_option_free(discovery_option); + + return OGS_ERROR; + } + + ogs_sbi_request_free(nrf_request); + ogs_sbi_discovery_option_free(discovery_option); + + return OGS_OK; + } + + ogs_sbi_discovery_option_free(discovery_option); + + /*************************************** + * Receive NOTIFICATION message from NRF + ***************************************/ + ogs_assert(request); + ogs_assert(data); + + e = scp_event_new(OGS_EVENT_SBI_SERVER); + ogs_assert(e); + + 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_event_free(e); + return OGS_ERROR; + } + + return OGS_OK; +} + +static int response_handler( + int status, ogs_sbi_response_t *response, void *data) +{ + scp_assoc_t *assoc = data; + ogs_sbi_stream_t *stream = NULL; + + ogs_assert(assoc); + stream = assoc->stream; + ogs_assert(stream); + + if (status != OGS_OK) { + + ogs_log_message( + status == OGS_DONE ? OGS_LOG_DEBUG : OGS_LOG_WARN, 0, + "response_handler() failed [%d]", status); + + ogs_assert(true == + ogs_sbi_server_send_error(stream, + OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, NULL, + "response_handler() failed", NULL)); + + scp_assoc_remove(assoc); + + return OGS_ERROR; + } + + ogs_assert(response); + + if (assoc->nf_service_producer) { + if (assoc->nf_service_producer->id) + ogs_sbi_header_set(response->http.headers, + OGS_SBI_CUSTOM_PRODUCER_ID, assoc->nf_service_producer->id); + else + ogs_error("No NF-Instance ID"); + } + + ogs_assert(true == ogs_sbi_server_send_response(stream, response)); + scp_assoc_remove(assoc); + + return OGS_OK; +} + +static int discover_handler( + int status, ogs_sbi_response_t *response, void *data) +{ + int rv; + char *strerror = NULL; + ogs_sbi_message_t message; + + scp_assoc_t *assoc = data; + ogs_sbi_stream_t *stream = NULL; + ogs_sbi_request_t *request = NULL; + ogs_sbi_service_type_e service_type = OGS_SBI_SERVICE_TYPE_NULL; + OpenAPI_nf_type_e requester_nf_type = OpenAPI_nf_type_NULL; + + ogs_sbi_request_t scp_request; + char *apiroot = NULL; + + ogs_sbi_nf_instance_t *nf_instance = NULL; + ogs_sbi_client_t *client = NULL, *next_scp = NULL; + + ogs_assert(assoc); + stream = assoc->stream; + ogs_assert(stream); + request = assoc->request; + ogs_assert(request); + service_type = assoc->service_type; + ogs_assert(service_type); + requester_nf_type = assoc->requester_nf_type; + ogs_assert(requester_nf_type); + + if (status != OGS_OK) { + + ogs_log_message( + status == OGS_DONE ? OGS_LOG_DEBUG : OGS_LOG_WARN, 0, + "response_handler() failed [%d]", status); + + ogs_assert(true == + ogs_sbi_server_send_error(stream, + OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, NULL, + "response_handler() failed", NULL)); + + scp_assoc_remove(assoc); + + return OGS_ERROR; + } + + ogs_assert(response); + + rv = ogs_sbi_parse_response(&message, response); + if (rv != OGS_OK) { + strerror = ogs_msprintf("cannot parse HTTP response"); + goto cleanup; + } + + if (message.res_status != OGS_SBI_HTTP_STATUS_OK) { + strerror = ogs_msprintf("NF-Discover failed [%d]", message.res_status); + goto cleanup; + } + + if (!message.SearchResult) { + strerror = ogs_msprintf("No SearchResult"); + goto cleanup; + } + + ogs_nnrf_disc_handle_nf_discover_search_result(message.SearchResult); + + nf_instance = ogs_sbi_nf_instance_find_by_service_type( + service_type, requester_nf_type); + if (!nf_instance) { + strerror = ogs_msprintf("(NF discover) No NF-Instance [%s:%s]", + ogs_sbi_service_type_to_name(service_type), + OpenAPI_nf_type_ToString(requester_nf_type)); + + goto cleanup; + } + + client = ogs_sbi_client_find_by_service_type(nf_instance, service_type); + if (!client) { + strerror = ogs_msprintf("(NF discover) No client [%s:%s]", + ogs_sbi_service_type_to_name(service_type), + OpenAPI_nf_type_ToString(requester_nf_type)); + + goto cleanup; + } + + /* Copy Request for sending SCP */ + copy_request(&scp_request, request, false); + ogs_assert(scp_request.http.headers); + + /* Check if Next-SCP's client */ + next_scp = NF_INSTANCE_CLIENT(ogs_sbi_self()->scp_instance); + if (next_scp) { + apiroot = ogs_sbi_client_apiroot(client); + ogs_assert(apiroot); + + ogs_sbi_header_set(scp_request.http.headers, + OGS_SBI_CUSTOM_TARGET_APIROOT, apiroot); + + ogs_free(apiroot); + + /* Switch to the Next-SCP's client */ + client = next_scp; + } + + /* Client ApiRoot */ + apiroot = ogs_sbi_client_apiroot(client); + ogs_assert(apiroot); + + /* Setup New URI */ + scp_request.h.uri = ogs_msprintf("%s%s", apiroot, request->h.uri); + ogs_assert(scp_request.h.uri); + + ogs_free(apiroot); + + /* Store NF Service Producer */ + assoc->nf_service_producer = nf_instance; + ogs_assert(assoc->nf_service_producer); + + /* Send the HTTP Request with New URI and HTTP Headers */ + if (ogs_sbi_client_send_request( + client, response_handler, &scp_request, assoc) != true) { + ogs_error("ogs_sbi_client_send_request() failed"); + strerror = ogs_msprintf("ogs_sbi_client_send_request() failed"); + + ogs_sbi_http_hash_free(scp_request.http.headers); + ogs_free(scp_request.h.uri); + + goto cleanup; + } + + ogs_sbi_http_hash_free(scp_request.http.headers); + ogs_free(scp_request.h.uri); + + ogs_sbi_response_free(response); + ogs_sbi_message_free(&message); + + return OGS_OK; + +cleanup: + ogs_assert(strerror); + ogs_error("%s", strerror); + + ogs_assert(true == + ogs_sbi_server_send_error( + stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, NULL, strerror, NULL)); + + ogs_free(strerror); + + scp_assoc_remove(assoc); + + ogs_sbi_response_free(response); + ogs_sbi_message_free(&message); + + return OGS_ERROR; +} + +static void copy_request( + ogs_sbi_request_t *target, ogs_sbi_request_t *source, + bool next_scp) +{ + ogs_hash_index_t *hi; + + ogs_assert(source); + ogs_assert(target); + + memset(target, 0, sizeof(*target)); + + /* HTTP method/params/content */ + target->h.method = source->h.method; + target->http.params = source->http.params; + target->http.content = source->http.content; + target->http.content_length = source->http.content_length; + + /* HTTP Headers + * + * To remove the followings, + * Scheme - https + * Authority - scp.open5gs.org + */ + target->http.headers = ogs_hash_make(); + ogs_assert(target->http.headers); /* Extract HTTP Header */ for (hi = ogs_hash_first(source->http.headers); @@ -110,292 +754,15 @@ static int request_handler(ogs_sbi_request_t *source, void *data) * Each header field consists of a name followed by a colon (":") * and the field value. Field names are case-insensitive. */ - if (!strcasecmp(key, OGS_SBI_CUSTOM_TARGET_APIROOT)) { - headers.target_apiroot = val; - } else if (!strncasecmp(key, - OGS_SBI_CUSTOM_DISCOVERY_COMMON, - strlen(OGS_SBI_CUSTOM_DISCOVERY_COMMON))) { - headers.discovery = val; - } else if (!strcasecmp(key, OGS_SBI_ACCEPT)) { - headers.accept = val; - } else if (!strcasecmp(key, OGS_SBI_CONTENT_TYPE)) { - headers.content_type = val; - } else if (!strcasecmp(key, OGS_SBI_ACCEPT_ENCODING)) { - headers.content_encoding = val; - } - } - - if (headers.target_apiroot) { - ogs_sbi_nf_instance_t *scp_instance = NULL; - ogs_sbi_client_t *client = NULL; - ogs_sbi_request_t target; - - scp_conn_t *conn = NULL; - - memset(&target, 0, sizeof(target)); - - conn = scp_conn_add(stream); - if (!conn) { - ogs_error("scp_conn_add() failed"); - ogs_sbi_request_free(source); - return OGS_ERROR; - } - - if (ogs_sbi_self()->discovery_config.delegated == - OGS_SBI_DISCOVERY_DELEGATED_AUTO) { - scp_instance = ogs_sbi_self()->scp_instance; - } else if (ogs_sbi_self()->discovery_config.delegated == - OGS_SBI_DISCOVERY_DELEGATED_YES) { - scp_instance = ogs_sbi_self()->scp_instance; - ogs_assert(scp_instance); - } - - /* HTTP Method */ - target.h.method = source->h.method; - - /* HTTP Headers - * - * To remove the followings, - * Scheme - https - * Authority - scp.open5gs.org - * - * We regenerate the HTTP Headers. - */ - target.http.headers = ogs_hash_make(); - ogs_assert(target.http.headers); - - if (headers.content_type) - ogs_sbi_header_set(target.http.headers, - OGS_SBI_CONTENT_TYPE, headers.content_type); - if (headers.accept) - ogs_sbi_header_set(target.http.headers, - OGS_SBI_ACCEPT, headers.accept); - if (headers.content_encoding) - ogs_sbi_header_set(target.http.headers, - OGS_SBI_ACCEPT_ENCODING, headers.content_encoding); - - /* HTTP Params */ - target.http.params = source->http.params; - - /* HTTP Content */ - target.http.content = source->http.content; - target.http.content_length = source->http.content_length; - - if (scp_instance) { - char *apiroot = NULL; - - if (headers.target_apiroot) - ogs_sbi_header_set(target.http.headers, - OGS_SBI_CUSTOM_TARGET_APIROOT, headers.target_apiroot); - - /* Client Instance */ - client = scp_instance->client; - ogs_assert(client); - - /* Client ApiRoot */ - apiroot = ogs_sbi_client_apiroot(client); - ogs_assert(apiroot); - - /* Setup New URI */ - target.h.uri = ogs_msprintf("%s%s", apiroot, source->h.uri); - ogs_assert(target.h.uri); - - ogs_free(apiroot); - + if (next_scp == false && + !strcasecmp(key, OGS_SBI_CUSTOM_TARGET_APIROOT)) { + } else if (next_scp == false && + !strncasecmp(key, OGS_SBI_CUSTOM_DISCOVERY_COMMON, + strlen(OGS_SBI_CUSTOM_DISCOVERY_COMMON))) { + } else if (!strcasecmp(key, OGS_SBI_SCHEME)) { + } else if (!strcasecmp(key, OGS_SBI_AUTHORITY)) { } else { - ogs_sockaddr_t *addr = NULL; - - /* Find or Add Client Instance */ - addr = ogs_sbi_getaddr_from_uri(headers.target_apiroot); - if (!addr) { - ogs_error("Invalid Target-apiRoot [%s]", - headers.target_apiroot); - ogs_sbi_http_hash_free(target.http.headers); - ogs_free(target.h.uri); - - ogs_sbi_request_free(source); - scp_conn_remove(conn); - return OGS_ERROR; - } - - client = ogs_sbi_client_find(addr); - if (!client) { - client = ogs_sbi_client_add(addr); - ogs_assert(client); - client->cb = client_cb; - } - OGS_SBI_SETUP_CLIENT(conn, client); - - ogs_freeaddrinfo(addr); - - /* Setup New URI */ - target.h.uri = ogs_msprintf("%s%s", - headers.target_apiroot, source->h.uri); - ogs_assert(target.h.uri); - } - - /* Send the HTTP Request with New URI and HTTP Headers */ - if (ogs_sbi_client_send_reqmem_persistent( - client, response_handler, &target, conn) != true) { - ogs_error("ogs_sbi_client_send_request() failed"); - ogs_sbi_http_hash_free(target.http.headers); - ogs_free(target.h.uri); - - ogs_sbi_request_free(source); - scp_conn_remove(conn); - return OGS_ERROR; - } - - ogs_sbi_http_hash_free(target.http.headers); - ogs_free(target.h.uri); - - } else if (headers.discovery) { - scp_event_t *e = NULL; - - e = scp_event_new(OGS_EVENT_SBI_SERVER); - ogs_assert(e); - - 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); - ogs_event_free(e); - return OGS_ERROR; - } - } else { - scp_event_t *e = NULL; - int rv; - - ogs_assert(source); - ogs_assert(data); - - e = scp_event_new(OGS_EVENT_SBI_SERVER); - ogs_assert(e); - - 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); - ogs_event_free(e); - return OGS_ERROR; + ogs_sbi_header_set(target->http.headers, key, val); } } - - return OGS_OK; -} - -static int response_handler( - int status, ogs_sbi_response_t *response, void *data) -{ - scp_conn_t *conn = data; - ogs_sbi_stream_t *stream = NULL; - - ogs_assert(conn); - stream = conn->stream; - ogs_assert(stream); - - if (status != OGS_OK) { - - ogs_log_message( - status == OGS_DONE ? OGS_LOG_DEBUG : OGS_LOG_WARN, 0, - "response_handler() failed [%d]", status); - - ogs_assert(true == - ogs_sbi_server_send_error(stream, - OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, NULL, - "response_handler() failed", NULL)); - - scp_conn_remove(conn); - - return OGS_ERROR; - } - - ogs_assert(response); - ogs_assert(true == ogs_sbi_server_send_response(stream, response)); - scp_conn_remove(conn); - - return OGS_OK; -} - -static int client_cb(int status, ogs_sbi_response_t *response, void *data) -{ - scp_event_t *e = NULL; - int rv; - - if (status != OGS_OK) { - ogs_log_message( - status == OGS_DONE ? OGS_LOG_DEBUG : OGS_LOG_WARN, 0, - "client_cb() failed [%d]", status); - return OGS_ERROR; - } - - ogs_assert(response); - - e = scp_event_new(OGS_EVENT_SBI_CLIENT); - ogs_assert(e); - 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); - ogs_event_free(e); - return OGS_ERROR; - } - - return OGS_OK; -} - -bool scp_sbi_send_request(ogs_sbi_nf_instance_t *nf_instance, void *data) -{ - ogs_assert(nf_instance); - - return ogs_sbi_send_request(nf_instance, client_cb, data); -} - -bool scp_sbi_discover_and_send( - ogs_sbi_service_type_e service_type, - ogs_sbi_discovery_option_t *discovery_option, - ogs_sbi_request_t *(*build)(scp_conn_t *conn, void *data), - scp_conn_t *conn, ogs_sbi_stream_t *stream, void *data) -{ - ogs_sbi_xact_t *xact = NULL; - - ogs_assert(service_type); - ogs_assert(conn); - ogs_assert(stream); - ogs_assert(build); - - xact = ogs_sbi_xact_add( - &conn->sbi, service_type, discovery_option, - (ogs_sbi_build_f)build, conn, data); - if (!xact) { - ogs_error("scp_sbi_discover_and_send() failed"); - ogs_assert(true == - ogs_sbi_server_send_error(stream, - OGS_SBI_HTTP_STATUS_GATEWAY_TIMEOUT, NULL, - "Cannot discover", NULL)); - return false; - } - - xact->assoc_stream = stream; - - if (ogs_sbi_discover_and_send(xact, client_cb) != true) { - ogs_error("scp_sbi_discover_and_send() failed"); - ogs_sbi_xact_remove(xact); - ogs_assert(true == - ogs_sbi_server_send_error(stream, - OGS_SBI_HTTP_STATUS_GATEWAY_TIMEOUT, NULL, - "Cannot discover", NULL)); - return false; - } - - return true; } diff --git a/src/scp/sbi-path.h b/src/scp/sbi-path.h index 388979876..cbfde5832 100644 --- a/src/scp/sbi-path.h +++ b/src/scp/sbi-path.h @@ -29,13 +29,6 @@ extern "C" { int scp_sbi_open(void); void scp_sbi_close(void); -bool scp_sbi_send_request(ogs_sbi_nf_instance_t *nf_instance, void *data); -bool scp_sbi_discover_and_send( - ogs_sbi_service_type_e service_type, - ogs_sbi_discovery_option_t *discovery_option, - ogs_sbi_request_t *(*build)(scp_conn_t *conn, void *data), - scp_conn_t *conn, ogs_sbi_stream_t *stream, void *data); - #ifdef __cplusplus } #endif diff --git a/src/scp/scp-sm.c b/src/scp/scp-sm.c index 573253578..fba2a5a33 100644 --- a/src/scp/scp-sm.c +++ b/src/scp/scp-sm.c @@ -18,8 +18,6 @@ */ #include "sbi-path.h" -#include "nnrf-handler.h" -#include "nscp-handler.h" void scp_state_initial(ogs_fsm_t *s, scp_event_t *e) { @@ -95,7 +93,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) - ogs_nnrf_handle_nf_status_notify(stream, &message); + ogs_nnrf_nfm_handle_nf_status_notify(stream, &message); break; DEFAULT @@ -118,71 +116,6 @@ void scp_state_operational(ogs_fsm_t *s, scp_event_t *e) END break; -#if 0 - CASE(OGS_SBI_SERVICE_NAME_NBSF_MANAGEMENT) - SWITCH(message.h.resource.component[0]) - CASE(OGS_SBI_RESOURCE_NAME_PCF_BINDINGS) - if (message.h.resource.component[1]) { - sess = scp_sess_find_by_binding_id( - message.h.resource.component[1]); - } else { - SWITCH(message.h.method) - CASE(OGS_SBI_HTTP_METHOD_POST) - if (message.PcfBinding && - message.PcfBinding->snssai && - message.PcfBinding->dnn) { - ogs_s_nssai_t s_nssai; - - s_nssai.sst = message.PcfBinding->snssai->sst; - s_nssai.sd = ogs_s_nssai_sd_from_string( - message.PcfBinding->snssai->sd); - - sess = scp_sess_find_by_snssai_and_dnn( - &s_nssai, message.PcfBinding->dnn); - if (!sess) { - sess = scp_sess_add_by_snssai_and_dnn( - &s_nssai, message.PcfBinding->dnn); - ogs_assert(sess); - } - } - break; - CASE(OGS_SBI_HTTP_METHOD_GET) - if (!sess && message.param.ipv4addr) - sess = scp_sess_find_by_ipv4addr( - message.param.ipv4addr); - if (!sess && message.param.ipv6prefix) - sess = scp_sess_find_by_ipv6prefix( - message.param.ipv6prefix); - break; - DEFAULT - ogs_error("Invalid HTTP method [%s]", message.h.method); - END - } - - if (!sess) { - ogs_error("Not found [%s]", message.h.uri); - ogs_assert(true == - ogs_sbi_server_send_error(stream, - OGS_SBI_HTTP_STATUS_NOT_FOUND, - &message, "Not found", message.h.uri)); - break; - } - - scp_nscp_management_handle_pcf_binding(sess, stream, &message); - break; - - DEFAULT - ogs_error("Invalid resource name [%s]", - message.h.resource.component[0]); - ogs_assert(true == - ogs_sbi_server_send_error(stream, - OGS_SBI_HTTP_STATUS_BAD_REQUEST, &message, - "Invalid resource name", - message.h.resource.component[0])); - END - break; -#endif - DEFAULT ogs_error("Invalid API name [%s]", message.h.service.name); ogs_assert(true == @@ -236,7 +169,7 @@ void scp_state_operational(ogs_fsm_t *s, scp_event_t *e) CASE(OGS_SBI_HTTP_METHOD_POST) if (message.res_status == OGS_SBI_HTTP_STATUS_CREATED || message.res_status == OGS_SBI_HTTP_STATUS_OK) { - ogs_nnrf_handle_nf_status_subscribe( + ogs_nnrf_nfm_handle_nf_status_subscribe( subscription_data, &message); } else { ogs_error("HTTP response error : %d", @@ -266,34 +199,6 @@ void scp_state_operational(ogs_fsm_t *s, scp_event_t *e) END break; - CASE(OGS_SBI_SERVICE_NAME_NNRF_DISC) - SWITCH(message.h.resource.component[0]) - CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) - sbi_xact = e->h.sbi.data; - ogs_assert(sbi_xact); - - SWITCH(message.h.method) - CASE(OGS_SBI_HTTP_METHOD_GET) - if (message.res_status == OGS_SBI_HTTP_STATUS_OK) - scp_nnrf_handle_nf_discover(sbi_xact, &message); - else - ogs_error("HTTP response error [%d]", - message.res_status); - break; - - DEFAULT - ogs_error("Invalid HTTP method [%s]", message.h.method); - ogs_assert_if_reached(); - END - break; - - DEFAULT - ogs_error("Invalid resource name [%s]", - message.h.resource.component[0]); - ogs_assert_if_reached(); - END - break; - DEFAULT ogs_error("Invalid service name [%s]", message.h.service.name); ogs_assert_if_reached(); diff --git a/src/sgwc/event.h b/src/sgwc/event.h index ad653ec40..f146f66e7 100644 --- a/src/sgwc/event.h +++ b/src/sgwc/event.h @@ -63,6 +63,8 @@ typedef struct sgwc_event_s { sgwc_bearer_t *bearer; } sgwc_event_t; +OGS_STATIC_ASSERT(OGS_EVENT_SIZE >= sizeof(sgwc_event_t)); + void sgwc_event_init(void); void sgwc_event_term(void); void sgwc_event_final(void); diff --git a/src/sgwu/event.h b/src/sgwu/event.h index 8bbda9546..c37ccbdad 100644 --- a/src/sgwu/event.h +++ b/src/sgwu/event.h @@ -58,6 +58,8 @@ typedef struct sgwu_event_s { sgwu_bearer_t *bearer; } sgwu_event_t; +OGS_STATIC_ASSERT(OGS_EVENT_SIZE >= sizeof(sgwu_event_t)); + void sgwu_event_init(void); void sgwu_event_term(void); void sgwu_event_final(void); diff --git a/src/smf/event.h b/src/smf/event.h index 87d4cc3f2..258681c6d 100644 --- a/src/smf/event.h +++ b/src/smf/event.h @@ -102,6 +102,8 @@ typedef struct smf_event_s { smf_sess_t *sess; } smf_event_t; +OGS_STATIC_ASSERT(OGS_EVENT_SIZE >= sizeof(smf_event_t)); + smf_event_t *smf_event_new(int id); const char *smf_event_get_name(smf_event_t *e); diff --git a/src/smf/namf-build.c b/src/smf/namf-build.c index aee01936f..fb63a0738 100644 --- a/src/smf/namf-build.c +++ b/src/smf/namf-build.c @@ -146,7 +146,7 @@ ogs_sbi_request_t *smf_namf_comm_build_n1_n2_message_transfer( } request = ogs_sbi_build_request(&message); - ogs_assert(request); + ogs_expect(request); for (i = 0; i < message.num_of_part; i++) if (message.part[i].pkbuf) @@ -184,7 +184,7 @@ ogs_sbi_request_t *smf_namf_callback_build_sm_context_status( message.SmContextStatusNotification = &SmContextStatusNotification; request = ogs_sbi_build_request(&message); - ogs_assert(request); + ogs_expect(request); return request; } diff --git a/src/smf/nnrf-handler.c b/src/smf/nnrf-handler.c index e47fe2d17..d06e1f891 100644 --- a/src/smf/nnrf-handler.c +++ b/src/smf/nnrf-handler.c @@ -29,6 +29,7 @@ void smf_nnrf_handle_nf_discover( ogs_sbi_discovery_option_t *discovery_option = NULL; OpenAPI_nf_type_e target_nf_type = OpenAPI_nf_type_NULL; + OpenAPI_nf_type_e requester_nf_type = OpenAPI_nf_type_NULL; OpenAPI_search_result_t *SearchResult = NULL; ogs_assert(recvmsg); @@ -39,6 +40,8 @@ void smf_nnrf_handle_nf_discover( ogs_assert(service_type); target_nf_type = ogs_sbi_service_type_to_nf_type(service_type); ogs_assert(target_nf_type); + requester_nf_type = xact->requester_nf_type; + ogs_assert(requester_nf_type); discovery_option = xact->discovery_option; @@ -48,13 +51,14 @@ void smf_nnrf_handle_nf_discover( return; } - ogs_nnrf_handle_nf_discover_search_result(SearchResult); + ogs_nnrf_disc_handle_nf_discover_search_result(SearchResult); nf_instance = ogs_sbi_nf_instance_find_by_discovery_param( - target_nf_type, discovery_option); + target_nf_type, requester_nf_type, discovery_option); if (!nf_instance) { - ogs_error("(NF discover) No [%s]", - ogs_sbi_service_type_to_name(service_type)); + ogs_error("(NF discover) No [%s:%s]", + ogs_sbi_service_type_to_name(service_type), + OpenAPI_nf_type_ToString(requester_nf_type)); return; } diff --git a/src/smf/npcf-build.c b/src/smf/npcf-build.c index 8b45de189..2ca3dbb9b 100644 --- a/src/smf/npcf-build.c +++ b/src/smf/npcf-build.c @@ -48,17 +48,32 @@ ogs_sbi_request_t *smf_npcf_smpolicycontrol_build_create( memset(&SmPolicyContextData, 0, sizeof(SmPolicyContextData)); - ogs_assert(smf_ue->supi); SmPolicyContextData.supi = smf_ue->supi; - ogs_assert(sess->psi); + if (!SmPolicyContextData.supi) { + ogs_error("No supi"); + goto end; + } SmPolicyContextData.pdu_session_id = sess->psi; - ogs_assert(sess->session.session_type); + if (!SmPolicyContextData.pdu_session_id) { + ogs_error("No pdu_session_id"); + goto end; + } SmPolicyContextData.pdu_session_type = sess->session.session_type; - ogs_assert(sess->session.name); + if (!SmPolicyContextData.pdu_session_type) { + ogs_error("No pdu_session_type"); + goto end; + } SmPolicyContextData.dnn = sess->session.name; + if (!SmPolicyContextData.dnn) { + ogs_error("No dnn"); + goto end; + } server = ogs_list_first(&ogs_sbi_self()->server_list); - ogs_assert(server); + if (!server) { + ogs_error("No server"); + goto end; + } memset(&header, 0, sizeof(header)); header.service.name = (char *)OGS_SBI_SERVICE_NAME_NSMF_CALLBACK; @@ -67,18 +82,27 @@ ogs_sbi_request_t *smf_npcf_smpolicycontrol_build_create( (char *)OGS_SBI_RESOURCE_NAME_SM_POLICY_NOTIFY; header.resource.component[1] = sess->sm_context_ref; SmPolicyContextData.notification_uri = ogs_sbi_server_uri(server, &header); - ogs_assert(SmPolicyContextData.notification_uri); + if (!SmPolicyContextData.notification_uri) { + ogs_error("No notification_uri"); + goto end; + } if (sess->ipv4) { SmPolicyContextData.ipv4_address = ogs_ipv4_to_string(sess->ipv4->addr[0]); - ogs_expect_or_return_val(SmPolicyContextData.ipv4_address, NULL); + if (!SmPolicyContextData.ipv4_address) { + ogs_error("No ipv4_address"); + goto end; + } } if (sess->ipv6) { SmPolicyContextData.ipv6_address_prefix = ogs_ipv6prefix_to_string( (uint8_t *)sess->ipv6->addr, OGS_IPV6_128_PREFIX_LEN); - ogs_expect_or_return_val(SmPolicyContextData.ipv6_address_prefix, NULL); + if (!SmPolicyContextData.ipv6_address_prefix) { + ogs_error("No ipv6_address_prefix"); + goto end; + } } memset(&SubsSessAmbr, 0, sizeof(SubsSessAmbr)); @@ -104,14 +128,20 @@ ogs_sbi_request_t *smf_npcf_smpolicycontrol_build_create( else if (sess->session.qos.arp.pre_emption_capability == OGS_5GC_PRE_EMPTION_DISABLED) Arp.preempt_cap = OpenAPI_preemption_capability_NOT_PREEMPT; - ogs_assert(Arp.preempt_cap); + if (!Arp.preempt_cap) { + ogs_error("No Arp.preempt_cap"); + goto end; + } if (sess->session.qos.arp.pre_emption_vulnerability == OGS_5GC_PRE_EMPTION_ENABLED) Arp.preempt_vuln = OpenAPI_preemption_vulnerability_PREEMPTABLE; else if (sess->session.qos.arp.pre_emption_vulnerability == OGS_5GC_PRE_EMPTION_DISABLED) Arp.preempt_vuln = OpenAPI_preemption_vulnerability_NOT_PREEMPTABLE; - ogs_assert(Arp.preempt_vuln); + if (!Arp.preempt_vuln) { + ogs_error("No Arp.preempt_vuln"); + goto end; + } Arp.priority_level = sess->session.qos.arp.priority_level; memset(&SubsDefQos, 0, sizeof(SubsDefQos)); @@ -125,7 +155,10 @@ ogs_sbi_request_t *smf_npcf_smpolicycontrol_build_create( if (sess->smpolicycontrol_features) { SmPolicyContextData.supp_feat = ogs_uint64_to_string(sess->smpolicycontrol_features); - ogs_expect_or_return_val(SmPolicyContextData.supp_feat, NULL); + if (!SmPolicyContextData.supp_feat) { + ogs_error("No supp_feat"); + goto end; + } } memset(&sNssai, 0, sizeof(sNssai)); @@ -138,7 +171,9 @@ ogs_sbi_request_t *smf_npcf_smpolicycontrol_build_create( request = ogs_sbi_build_request(&message); ogs_expect(request); - ogs_free(SmPolicyContextData.notification_uri); +end: + if (SmPolicyContextData.notification_uri) + ogs_free(SmPolicyContextData.notification_uri); if (SmPolicyContextData.gpsi) ogs_free(SmPolicyContextData.gpsi); @@ -198,18 +233,29 @@ ogs_sbi_request_t *smf_npcf_smpolicycontrol_build_delete( param->ran_nas_release.gsm_cause || param->ran_nas_release.ngap_cause.group) { - ranNasRelCause = ogs_calloc(1, sizeof(*ranNasRelCause)); - ogs_expect_or_return_val(ranNasRelCause, NULL); - ranNasRelCauseList = OpenAPI_list_create(); - ogs_expect_or_return_val(ranNasRelCauseList, NULL); + if (!ranNasRelCauseList) { + ogs_error("No ranNasRelCauseList"); + goto end; + } + + ranNasRelCause = ogs_calloc(1, sizeof(*ranNasRelCause)); + if (!ranNasRelCause) { + ogs_error("No ranNasRelCause"); + goto end; + } if (param->ran_nas_release.ngap_cause.group) { OpenAPI_ng_ap_cause_t *ngApCause = NULL; ranNasRelCause->ng_ap_cause = ngApCause = ogs_calloc(1, sizeof(*ngApCause)); - ogs_expect_or_return_val(ngApCause, NULL); + if (!ranNasRelCause->ng_ap_cause) { + ogs_error("No ranNasRelCause->ng_ap_cause"); + if (ranNasRelCause) + ogs_free(ranNasRelCause); + goto end; + } ngApCause->group = param->ran_nas_release.ngap_cause.group; ngApCause->value = param->ran_nas_release.ngap_cause.value; @@ -226,24 +272,35 @@ ogs_sbi_request_t *smf_npcf_smpolicycontrol_build_delete( if (param->ue_location) { ueLocation.nr_location = ogs_sbi_build_nr_location( &sess->nr_tai, &sess->nr_cgi); - ogs_expect_or_return_val(ueLocation.nr_location, NULL); + if (!ueLocation.nr_location) { + ogs_error("ueLocation.nr_location"); + goto end; + } ueLocation.nr_location->ue_location_timestamp = ogs_sbi_gmtime_string(sess->ue_location_timestamp); - ogs_expect_or_return_val( - ueLocation.nr_location->ue_location_timestamp, NULL); + if (!ueLocation.nr_location->ue_location_timestamp) { + ogs_error("ueLocation.nr_location->ue_location_timestamp"); + goto end; + } SmPolicyDeleteData.user_location_info = &ueLocation; } if (param->ue_timezone) { SmPolicyDeleteData.ue_time_zone = ogs_sbi_timezone_string(ogs_timezone()); - ogs_expect_or_return_val(SmPolicyDeleteData.ue_time_zone, NULL); + if (!SmPolicyDeleteData.ue_time_zone) { + ogs_error("SmPolicyDeleteData.ue_time_zone"); + goto end; + } } } SmPolicyDeleteData.serving_network = ogs_sbi_build_plmn_id_nid(&sess->plmn_id); - ogs_expect_or_return_val(SmPolicyDeleteData.serving_network, NULL); + if (!SmPolicyDeleteData.serving_network) { + ogs_error("SmPolicyDeleteData.serving_network"); + goto end; + } SmPolicyDeleteData.ran_nas_rel_causes = ranNasRelCauseList; @@ -252,6 +309,8 @@ ogs_sbi_request_t *smf_npcf_smpolicycontrol_build_delete( request = ogs_sbi_build_request(&message); ogs_expect(request); +end: + if (ueLocation.nr_location) { if (ueLocation.nr_location->ue_location_timestamp) ogs_free(ueLocation.nr_location->ue_location_timestamp); diff --git a/src/smf/nudm-build.c b/src/smf/nudm-build.c index 09daeeca7..f4fc1f667 100644 --- a/src/smf/nudm-build.c +++ b/src/smf/nudm-build.c @@ -45,7 +45,7 @@ ogs_sbi_request_t *smf_nudm_sdm_build_get(smf_sess_t *sess, void *data) message.param.dnn = sess->session.name; request = ogs_sbi_build_request(&message); - ogs_assert(request); + ogs_expect(request); return request; } diff --git a/src/smf/sbi-path.c b/src/smf/sbi-path.c index fdc51a400..ad04230cf 100644 --- a/src/smf/sbi-path.c +++ b/src/smf/sbi-path.c @@ -21,67 +21,13 @@ #include "ngap-path.h" #include "sbi-path.h" -static int server_cb(ogs_sbi_request_t *request, void *data) -{ - smf_event_t *e = NULL; - int rv; - - ogs_assert(request); - ogs_assert(data); - - e = smf_event_new(OGS_EVENT_SBI_SERVER); - ogs_assert(e); - - 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); - ogs_event_free(e); - return OGS_ERROR; - } - - return OGS_OK; -} - -static int client_cb(int status, ogs_sbi_response_t *response, void *data) -{ - smf_event_t *e = NULL; - int rv; - - if (status != OGS_OK) { - ogs_log_message( - status == OGS_DONE ? OGS_LOG_DEBUG : OGS_LOG_WARN, 0, - "client_cb() failed [%d]", status); - return OGS_ERROR; - } - - ogs_assert(response); - - e = smf_event_new(OGS_EVENT_SBI_CLIENT); - ogs_assert(e); - 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); - ogs_event_free(e); - return OGS_ERROR; - } - - return OGS_OK; -} - int smf_sbi_open(void) { ogs_sbi_nf_instance_t *nf_instance = NULL; + ogs_sbi_nf_instance_t *nrf_instance = NULL, *scp_instance = NULL; ogs_sbi_nf_service_t *service = NULL; - /* Add SELF NF instance */ + /* Initialize SELF NF instance */ nf_instance = ogs_sbi_self()->nf_instance; ogs_assert(nf_instance); ogs_sbi_nf_fsm_init(nf_instance); @@ -101,30 +47,32 @@ int smf_sbi_open(void) ogs_sbi_nf_service_add_allowed_nf_type(service, OpenAPI_nf_type_AMF); } - /* Initialize NRF NF Instance */ - nf_instance = ogs_sbi_self()->nrf_instance; - if (nf_instance) { - ogs_sbi_client_t *client = NULL; + /* + * SMF can only run to support 4G EPC mode. + * + * If the SMF is only running in 4G EPC mode, + * it should not send NFRegister/NFStatusSubscribe messages to the NRF. + */ + nrf_instance = ogs_sbi_self()->nrf_instance; + scp_instance = ogs_sbi_self()->scp_instance; - /* Client callback is only used when NF sends to NRF */ - client = nf_instance->client; - ogs_assert(client); - client->cb = client_cb; + if (NF_INSTANCE_CLIENT(nrf_instance) || NF_INSTANCE_CLIENT(scp_instance)) { - /* NFRegister is sent and the response is received - * by the above client callback. */ - ogs_sbi_nf_fsm_init(nf_instance); + /* Initialize NRF NF Instance */ + nf_instance = ogs_sbi_self()->nrf_instance; + if (nf_instance) + ogs_sbi_nf_fsm_init(nf_instance); + + /* Build Subscription-Data */ + ogs_sbi_subscription_data_build_default( + OpenAPI_nf_type_AMF, OGS_SBI_SERVICE_NAME_NAMF_COMM); + ogs_sbi_subscription_data_build_default( + OpenAPI_nf_type_PCF, OGS_SBI_SERVICE_NAME_NPCF_SMPOLICYCONTROL); + ogs_sbi_subscription_data_build_default( + OpenAPI_nf_type_UDM, OGS_SBI_SERVICE_NAME_NUDM_SDM); } - /* Build Subscription-Data */ - ogs_sbi_subscription_data_build_default( - OpenAPI_nf_type_AMF, OGS_SBI_SERVICE_NAME_NAMF_COMM); - ogs_sbi_subscription_data_build_default( - OpenAPI_nf_type_PCF, OGS_SBI_SERVICE_NAME_NPCF_SMPOLICYCONTROL); - ogs_sbi_subscription_data_build_default( - OpenAPI_nf_type_UDM, OGS_SBI_SERVICE_NAME_NUDM_SDM); - - if (ogs_sbi_server_start_all(server_cb) != OGS_OK) + if (ogs_sbi_server_start_all(ogs_sbi_server_handler) != OGS_OK) return OGS_ERROR; return OGS_OK; @@ -136,11 +84,12 @@ void smf_sbi_close(void) ogs_sbi_server_stop_all(); } -bool smf_sbi_send_request(ogs_sbi_nf_instance_t *nf_instance, void *data) +bool smf_sbi_send_request( + ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_xact_t *xact) { ogs_assert(nf_instance); - - return ogs_sbi_send_request(nf_instance, client_cb, data); + ogs_assert(xact); + return ogs_sbi_send_request_to_nf_instance(nf_instance, xact); } bool smf_sbi_discover_and_send( @@ -173,7 +122,7 @@ bool smf_sbi_discover_and_send( xact->state = state; xact->assoc_stream = stream; - if (ogs_sbi_discover_and_send(xact, client_cb) != true) { + if (ogs_sbi_discover_and_send(xact) != true) { ogs_error("smf_sbi_discover_and_send() failed"); ogs_sbi_xact_remove(xact); @@ -219,7 +168,7 @@ void smf_namf_comm_send_n1_n2_message_transfer( xact->state = param->state; - if (ogs_sbi_discover_and_send(xact, client_cb) != true) { + if (ogs_sbi_discover_and_send(xact) != true) { ogs_error("smf_namf_comm_send_n1_n2_message_transfer() failed"); ogs_sbi_xact_remove(xact); } @@ -438,6 +387,7 @@ static int client_notify_cb( bool smf_sbi_send_sm_context_status_notify(smf_sess_t *sess) { + bool rc; ogs_sbi_request_t *request = NULL; ogs_sbi_client_t *client = NULL; @@ -447,5 +397,12 @@ bool smf_sbi_send_sm_context_status_notify(smf_sess_t *sess) request = smf_namf_callback_build_sm_context_status(sess, NULL); ogs_expect_or_return_val(request, false); - return ogs_sbi_client_send_request(client, client_notify_cb, request, NULL); + + rc = ogs_sbi_send_request_to_client( + client, client_notify_cb, request, NULL); + ogs_expect(rc == true); + + ogs_sbi_request_free(request); + + return rc; } diff --git a/src/smf/sbi-path.h b/src/smf/sbi-path.h index 89c2337a6..91c13f9fb 100644 --- a/src/smf/sbi-path.h +++ b/src/smf/sbi-path.h @@ -33,7 +33,8 @@ extern "C" { int smf_sbi_open(void); void smf_sbi_close(void); -bool smf_sbi_send_request(ogs_sbi_nf_instance_t *nf_instance, void *data); +bool smf_sbi_send_request( + ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_xact_t *xact); bool smf_sbi_discover_and_send( ogs_sbi_service_type_e service_type, ogs_sbi_discovery_option_t *discovery_option, diff --git a/src/smf/smf-sm.c b/src/smf/smf-sm.c index 2dd3bcffb..2efc77554 100644 --- a/src/smf/smf-sm.c +++ b/src/smf/smf-sm.c @@ -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) - ogs_nnrf_handle_nf_status_notify(stream, &sbi_message); + ogs_nnrf_nfm_handle_nf_status_notify(stream, &sbi_message); break; DEFAULT @@ -674,7 +674,7 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) 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) { - ogs_nnrf_handle_nf_status_subscribe( + ogs_nnrf_nfm_handle_nf_status_subscribe( subscription_data, &sbi_message); } else { ogs_error("HTTP response error : %d", diff --git a/src/udm/event.h b/src/udm/event.h index b9e03d60d..c6f4b9ec7 100644 --- a/src/udm/event.h +++ b/src/udm/event.h @@ -34,6 +34,8 @@ typedef struct udm_event_s { udm_ue_t *udm_ue; } udm_event_t; +OGS_STATIC_ASSERT(OGS_EVENT_SIZE >= sizeof(udm_event_t)); + udm_event_t *udm_event_new(int id); const char *udm_event_get_name(udm_event_t *e); diff --git a/src/udm/nnrf-handler.c b/src/udm/nnrf-handler.c index be1ae9242..14f92be56 100644 --- a/src/udm/nnrf-handler.c +++ b/src/udm/nnrf-handler.c @@ -29,6 +29,7 @@ void udm_nnrf_handle_nf_discover( ogs_sbi_discovery_option_t *discovery_option = NULL; OpenAPI_nf_type_e target_nf_type = OpenAPI_nf_type_NULL; + OpenAPI_nf_type_e requester_nf_type = OpenAPI_nf_type_NULL; OpenAPI_search_result_t *SearchResult = NULL; ogs_assert(recvmsg); @@ -39,6 +40,8 @@ void udm_nnrf_handle_nf_discover( ogs_assert(service_type); target_nf_type = ogs_sbi_service_type_to_nf_type(service_type); ogs_assert(target_nf_type); + requester_nf_type = xact->requester_nf_type; + ogs_assert(requester_nf_type); discovery_option = xact->discovery_option; @@ -48,13 +51,14 @@ void udm_nnrf_handle_nf_discover( return; } - ogs_nnrf_handle_nf_discover_search_result(SearchResult); + ogs_nnrf_disc_handle_nf_discover_search_result(SearchResult); nf_instance = ogs_sbi_nf_instance_find_by_discovery_param( - target_nf_type, discovery_option); + target_nf_type, requester_nf_type, discovery_option); if (!nf_instance) { - ogs_error("(NF discover) No [%s]", - ogs_sbi_service_type_to_name(service_type)); + ogs_error("(NF discover) No [%s:%s]", + ogs_sbi_service_type_to_name(service_type), + OpenAPI_nf_type_ToString(requester_nf_type)); return; } diff --git a/src/udm/sbi-path.c b/src/udm/sbi-path.c index cc2a04bef..a86aab259 100644 --- a/src/udm/sbi-path.c +++ b/src/udm/sbi-path.c @@ -19,67 +19,12 @@ #include "sbi-path.h" -static int server_cb(ogs_sbi_request_t *request, void *data) -{ - udm_event_t *e = NULL; - int rv; - - ogs_assert(request); - ogs_assert(data); - - e = udm_event_new(OGS_EVENT_SBI_SERVER); - ogs_assert(e); - - 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); - ogs_event_free(e); - return OGS_ERROR; - } - - return OGS_OK; -} - -static int client_cb(int status, ogs_sbi_response_t *response, void *data) -{ - udm_event_t *e = NULL; - int rv; - - if (status != OGS_OK) { - ogs_log_message( - status == OGS_DONE ? OGS_LOG_DEBUG : OGS_LOG_WARN, 0, - "client_cb() failed [%d]", status); - return OGS_ERROR; - } - - ogs_assert(response); - - e = udm_event_new(OGS_EVENT_SBI_CLIENT); - ogs_assert(e); - 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); - ogs_event_free(e); - return OGS_ERROR; - } - - return OGS_OK; -} - int udm_sbi_open(void) { ogs_sbi_nf_instance_t *nf_instance = NULL; ogs_sbi_nf_service_t *service = NULL; - /* Add SELF NF instance */ + /* Initialize SELF NF instance */ nf_instance = ogs_sbi_self()->nf_instance; ogs_assert(nf_instance); ogs_sbi_nf_fsm_init(nf_instance); @@ -122,23 +67,13 @@ int udm_sbi_open(void) /* Initialize NRF NF Instance */ 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; - - /* NFRegister is sent and the response is received - * by the above client callback. */ + if (nf_instance) ogs_sbi_nf_fsm_init(nf_instance); - } /* Build Subscription-Data */ ogs_sbi_subscription_data_build_default(OpenAPI_nf_type_UDR, NULL); - if (ogs_sbi_server_start_all(server_cb) != OGS_OK) + if (ogs_sbi_server_start_all(ogs_sbi_server_handler) != OGS_OK) return OGS_ERROR; return OGS_OK; @@ -150,11 +85,12 @@ void udm_sbi_close(void) ogs_sbi_server_stop_all(); } -bool udm_sbi_send_request(ogs_sbi_nf_instance_t *nf_instance, void *data) +bool udm_sbi_send_request( + ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_xact_t *xact) { ogs_assert(nf_instance); - - return ogs_sbi_send_request(nf_instance, client_cb, data); + ogs_assert(xact); + return ogs_sbi_send_request_to_nf_instance(nf_instance, xact); } bool udm_sbi_discover_and_send( @@ -184,7 +120,7 @@ bool udm_sbi_discover_and_send( xact->assoc_stream = stream; - if (ogs_sbi_discover_and_send(xact, client_cb) != true) { + if (ogs_sbi_discover_and_send(xact) != true) { ogs_error("udm_sbi_discover_and_send() failed"); ogs_sbi_xact_remove(xact); ogs_assert(true == diff --git a/src/udm/sbi-path.h b/src/udm/sbi-path.h index b92b339d0..65c14b8ef 100644 --- a/src/udm/sbi-path.h +++ b/src/udm/sbi-path.h @@ -29,7 +29,8 @@ extern "C" { int udm_sbi_open(void); void udm_sbi_close(void); -bool udm_sbi_send_request(ogs_sbi_nf_instance_t *nf_instance, void *data); +bool udm_sbi_send_request( + ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_xact_t *xact); bool udm_sbi_discover_and_send( ogs_sbi_service_type_e service_type, ogs_sbi_discovery_option_t *discovery_option, diff --git a/src/udm/udm-sm.c b/src/udm/udm-sm.c index 8084d61e9..47cb63428 100644 --- a/src/udm/udm-sm.c +++ b/src/udm/udm-sm.c @@ -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) - ogs_nnrf_handle_nf_status_notify(stream, &message); + ogs_nnrf_nfm_handle_nf_status_notify(stream, &message); break; DEFAULT @@ -247,7 +247,7 @@ void udm_state_operational(ogs_fsm_t *s, udm_event_t *e) CASE(OGS_SBI_HTTP_METHOD_POST) if (message.res_status == OGS_SBI_HTTP_STATUS_CREATED || message.res_status == OGS_SBI_HTTP_STATUS_OK) { - ogs_nnrf_handle_nf_status_subscribe( + ogs_nnrf_nfm_handle_nf_status_subscribe( subscription_data, &message); } else { ogs_error("[%s] HTTP response error [%d]", diff --git a/src/udr/event.h b/src/udr/event.h index 0589df9e7..8605c4683 100644 --- a/src/udr/event.h +++ b/src/udr/event.h @@ -30,6 +30,8 @@ typedef struct udr_event_s { ogs_event_t h; } udr_event_t; +OGS_STATIC_ASSERT(OGS_EVENT_SIZE >= sizeof(udr_event_t)); + udr_event_t *udr_event_new(int id); const char *udr_event_get_name(udr_event_t *e); diff --git a/src/udr/sbi-path.c b/src/udr/sbi-path.c index 6f5d8e562..7eb77c0ee 100644 --- a/src/udr/sbi-path.c +++ b/src/udr/sbi-path.c @@ -19,67 +19,12 @@ #include "sbi-path.h" -static int server_cb(ogs_sbi_request_t *request, void *data) -{ - udr_event_t *e = NULL; - int rv; - - ogs_assert(request); - ogs_assert(data); - - e = udr_event_new(OGS_EVENT_SBI_SERVER); - ogs_assert(e); - - 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); - ogs_event_free(e); - return OGS_ERROR; - } - - return OGS_OK; -} - -static int client_cb(int status, ogs_sbi_response_t *response, void *data) -{ - udr_event_t *e = NULL; - int rv; - - if (status != OGS_OK) { - ogs_log_message( - status == OGS_DONE ? OGS_LOG_DEBUG : OGS_LOG_WARN, 0, - "client_cb() failed [%d]", status); - return OGS_ERROR; - } - - ogs_assert(response); - - e = udr_event_new(OGS_EVENT_SBI_CLIENT); - ogs_assert(e); - 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); - ogs_event_free(e); - return OGS_ERROR; - } - - return OGS_OK; -} - int udr_sbi_open(void) { ogs_sbi_nf_instance_t *nf_instance = NULL; ogs_sbi_nf_service_t *service = NULL; - /* Add SELF NF instance */ + /* Initialize SELF NF instance */ nf_instance = ogs_sbi_self()->nf_instance; ogs_assert(nf_instance); ogs_sbi_nf_fsm_init(nf_instance); @@ -103,20 +48,10 @@ int udr_sbi_open(void) /* Initialize NRF NF Instance */ 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; - - /* NFRegister is sent and the response is received - * by the above client callback. */ + if (nf_instance) ogs_sbi_nf_fsm_init(nf_instance); - } - if (ogs_sbi_server_start_all(server_cb) != OGS_OK) + if (ogs_sbi_server_start_all(ogs_sbi_server_handler) != OGS_OK) return OGS_ERROR; return OGS_OK; diff --git a/src/udr/udr-sm.c b/src/udr/udr-sm.c index 3811330a0..f34a2e388 100644 --- a/src/udr/udr-sm.c +++ b/src/udr/udr-sm.c @@ -93,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) - ogs_nnrf_handle_nf_status_notify(stream, &message); + ogs_nnrf_nfm_handle_nf_status_notify(stream, &message); break; DEFAULT @@ -228,7 +228,7 @@ void udr_state_operational(ogs_fsm_t *s, udr_event_t *e) CASE(OGS_SBI_HTTP_METHOD_POST) if (message.res_status == OGS_SBI_HTTP_STATUS_CREATED || message.res_status == OGS_SBI_HTTP_STATUS_OK) { - ogs_nnrf_handle_nf_status_subscribe( + ogs_nnrf_nfm_handle_nf_status_subscribe( subscription_data, &message); } else { ogs_error("[%s] HTTP response error [%d]", diff --git a/src/upf/event.h b/src/upf/event.h index 8fe4c0c12..44e012b33 100644 --- a/src/upf/event.h +++ b/src/upf/event.h @@ -53,6 +53,8 @@ typedef struct upf_event_s { ogs_pfcp_message_t *pfcp_message; } upf_event_t; +OGS_STATIC_ASSERT(OGS_EVENT_SIZE >= sizeof(upf_event_t)); + void upf_event_init(void); void upf_event_term(void); void upf_event_final(void); diff --git a/tests/af/af-sm.c b/tests/af/af-sm.c index 3eff3d5ab..2e8aa2c20 100644 --- a/tests/af/af-sm.c +++ b/tests/af/af-sm.c @@ -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) - ogs_nnrf_handle_nf_status_notify(stream, &message); + ogs_nnrf_nfm_handle_nf_status_notify(stream, &message); break; DEFAULT @@ -230,7 +230,7 @@ void af_state_operational(ogs_fsm_t *s, af_event_t *e) CASE(OGS_SBI_HTTP_METHOD_POST) if (message.res_status == OGS_SBI_HTTP_STATUS_CREATED || message.res_status == OGS_SBI_HTTP_STATUS_OK) { - ogs_nnrf_handle_nf_status_subscribe( + ogs_nnrf_nfm_handle_nf_status_subscribe( subscription_data, &message); } else { ogs_error("HTTP response error : %d", diff --git a/tests/af/event.h b/tests/af/event.h index fd54c66e7..c7da702d2 100644 --- a/tests/af/event.h +++ b/tests/af/event.h @@ -52,6 +52,8 @@ typedef struct af_event_s { af_sess_t *sess; } af_event_t; +OGS_STATIC_ASSERT(OGS_EVENT_SIZE >= sizeof(af_event_t)); + af_event_t *af_event_new(int id); const char *af_event_get_name(af_event_t *e); diff --git a/tests/af/nbsf-build.c b/tests/af/nbsf-build.c index ff8c7de01..0dcecab28 100644 --- a/tests/af/nbsf-build.c +++ b/tests/af/nbsf-build.c @@ -38,7 +38,7 @@ ogs_sbi_request_t *af_nbsf_management_build_discover( message.param.ipv6prefix = sess->ipv6prefix; request = ogs_sbi_build_request(&message); - ogs_assert(request); + ogs_expect(request); return request; } diff --git a/tests/af/nnrf-handler.c b/tests/af/nnrf-handler.c index 6d4b79ab3..08f0fa3f1 100644 --- a/tests/af/nnrf-handler.c +++ b/tests/af/nnrf-handler.c @@ -29,6 +29,7 @@ void af_nnrf_handle_nf_discover( ogs_sbi_discovery_option_t *discovery_option = NULL; OpenAPI_nf_type_e target_nf_type = OpenAPI_nf_type_NULL; + OpenAPI_nf_type_e requester_nf_type = OpenAPI_nf_type_NULL; OpenAPI_search_result_t *SearchResult = NULL; ogs_assert(recvmsg); @@ -39,6 +40,8 @@ void af_nnrf_handle_nf_discover( ogs_assert(service_type); target_nf_type = ogs_sbi_service_type_to_nf_type(service_type); ogs_assert(target_nf_type); + requester_nf_type = xact->requester_nf_type; + ogs_assert(requester_nf_type); discovery_option = xact->discovery_option; @@ -48,13 +51,14 @@ void af_nnrf_handle_nf_discover( return; } - ogs_nnrf_handle_nf_discover_search_result(SearchResult); + ogs_nnrf_disc_handle_nf_discover_search_result(SearchResult); nf_instance = ogs_sbi_nf_instance_find_by_discovery_param( - target_nf_type, discovery_option); + target_nf_type, requester_nf_type, discovery_option); if (!nf_instance) { - ogs_error("(NF discover) No [%s]", - ogs_sbi_service_type_to_name(service_type)); + ogs_error("(NF discover) No [%s:%s]", + ogs_sbi_service_type_to_name(service_type), + OpenAPI_nf_type_ToString(requester_nf_type)); return; } diff --git a/tests/af/npcf-build.c b/tests/af/npcf-build.c index a2a1ad0cf..82777f8c5 100644 --- a/tests/af/npcf-build.c +++ b/tests/af/npcf-build.c @@ -273,11 +273,13 @@ ogs_sbi_request_t *af_npcf_policyauthorization_build_create( AscReqData.med_components = MediaComponentList; request = ogs_sbi_build_request(&message); - ogs_expect_or_return_val(request, NULL); + ogs_expect(request); - ogs_free(AscReqData.notif_uri); + if (AscReqData.notif_uri) + ogs_free(AscReqData.notif_uri); - ogs_free(AscReqData.supp_feat); + if (AscReqData.supp_feat) + ogs_free(AscReqData.supp_feat); EventList = evSubsc.events; OpenAPI_list_for_each(EventList, node) { @@ -534,7 +536,7 @@ ogs_sbi_request_t *af_npcf_policyauthorization_build_update( AscUpdateData.med_components = MediaComponentList; request = ogs_sbi_build_request(&message); - ogs_expect_or_return_val(request, NULL); + ogs_expect(request); OpenAPI_list_for_each(MediaComponentList, node) { MediaComponentMap = node->data; @@ -616,7 +618,7 @@ ogs_sbi_request_t *af_npcf_policyauthorization_build_delete( (char *)OGS_SBI_RESOURCE_NAME_DELETE; request = ogs_sbi_build_request(&message); - ogs_expect_or_return_val(request, NULL); + ogs_expect(request); return request; } @@ -992,11 +994,13 @@ ogs_sbi_request_t *af_npcf_policyauthorization_build_create_video( AscReqData.med_components = MediaComponentList; request = ogs_sbi_build_request(&message); - ogs_expect_or_return_val(request, NULL); + ogs_expect(request); - ogs_free(AscReqData.notif_uri); + if (AscReqData.notif_uri) + ogs_free(AscReqData.notif_uri); - ogs_free(AscReqData.supp_feat); + if (AscReqData.supp_feat) + ogs_free(AscReqData.supp_feat); EventList = evSubsc.events; OpenAPI_list_for_each(EventList, node) { diff --git a/tests/af/sbi-path.c b/tests/af/sbi-path.c index 5b2da5031..46cd1d672 100644 --- a/tests/af/sbi-path.c +++ b/tests/af/sbi-path.c @@ -19,66 +19,11 @@ #include "sbi-path.h" -static int server_cb(ogs_sbi_request_t *request, void *data) -{ - af_event_t *e = NULL; - int rv; - - ogs_assert(request); - ogs_assert(data); - - e = af_event_new(OGS_EVENT_SBI_SERVER); - ogs_assert(e); - - 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); - ogs_event_free(e); - return OGS_ERROR; - } - - return OGS_OK; -} - -static int client_cb(int status, ogs_sbi_response_t *response, void *data) -{ - af_event_t *e = NULL; - int rv; - - if (status != OGS_OK) { - ogs_log_message( - status == OGS_DONE ? OGS_LOG_DEBUG : OGS_LOG_WARN, 0, - "client_cb() failed [%d]", status); - return OGS_ERROR; - } - - ogs_assert(response); - - e = af_event_new(OGS_EVENT_SBI_CLIENT); - ogs_assert(e); - 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); - ogs_event_free(e); - return OGS_ERROR; - } - - return OGS_OK; -} - int af_sbi_open(void) { ogs_sbi_nf_instance_t *nf_instance = NULL; - /* Add SELF NF instance */ + /* Initialize SELF NF instance */ nf_instance = ogs_sbi_self()->nf_instance; ogs_assert(nf_instance); ogs_sbi_nf_fsm_init(nf_instance); @@ -88,24 +33,14 @@ int af_sbi_open(void) /* Initialize NRF NF Instance */ 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; - - /* NFRegister is sent and the response is received - * by the above client callback. */ + if (nf_instance) ogs_sbi_nf_fsm_init(nf_instance); - } /* Build Subscription-Data */ ogs_sbi_subscription_data_build_default( OpenAPI_nf_type_BSF, OGS_SBI_SERVICE_NAME_NBSF_MANAGEMENT); - if (ogs_sbi_server_start_all(server_cb) != OGS_OK) + if (ogs_sbi_server_start_all(ogs_sbi_server_handler) != OGS_OK) return OGS_ERROR; return OGS_OK; @@ -117,11 +52,12 @@ void af_sbi_close(void) ogs_sbi_server_stop_all(); } -bool af_sbi_send_request(ogs_sbi_nf_instance_t *nf_instance, void *data) +bool af_sbi_send_request( + ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_xact_t *xact) { ogs_assert(nf_instance); - - return ogs_sbi_send_request(nf_instance, client_cb, data); + ogs_assert(xact); + return ogs_sbi_send_request_to_nf_instance(nf_instance, xact); } void af_sbi_discover_and_send( @@ -144,7 +80,7 @@ void af_sbi_discover_and_send( return; } - if (ogs_sbi_discover_and_send(xact, client_cb) != true) { + if (ogs_sbi_discover_and_send(xact) != true) { ogs_error("af_sbi_discover_and_send() failed"); return; } @@ -164,5 +100,8 @@ void af_sbi_send_to_pcf( request = (*build)(sess, data); ogs_assert(request); - ogs_sbi_client_send_request(client, client_cb, request, sess); + ogs_sbi_send_request_to_client( + client, ogs_sbi_client_handler, request, sess); + + ogs_sbi_request_free(request); } diff --git a/tests/af/sbi-path.h b/tests/af/sbi-path.h index 96bc52fd4..6e602bd05 100644 --- a/tests/af/sbi-path.h +++ b/tests/af/sbi-path.h @@ -30,7 +30,8 @@ extern "C" { int af_sbi_open(void); void af_sbi_close(void); -bool af_sbi_send_request(ogs_sbi_nf_instance_t *nf_instance, void *data); +bool af_sbi_send_request( + ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_xact_t *xact); void af_sbi_discover_and_send( ogs_sbi_service_type_e service_type, ogs_sbi_discovery_option_t *discovery_option,