From fe89f7cd11d415ae89da2724fc67aa573efa83c3 Mon Sep 17 00:00:00 2001 From: Sukchan Lee Date: Sat, 29 May 2021 15:56:12 +0900 Subject: [PATCH] [5GC] Added BSF(Binding Support Function) --- configs/310014.yaml.in | 6 + configs/csfb.yaml.in | 6 + configs/open5gs/bsf.yaml.in | 186 ++++ configs/open5gs/meson.build | 1 + configs/sample.yaml.in | 6 + configs/slice.yaml.in | 6 + configs/srslte.yaml.in | 6 + configs/systemd/meson.build | 1 + configs/systemd/open5gs-bsfd.service.in | 18 + configs/volte.yaml.in | 6 + configs/vonr.yaml.in | 11 + debian/control | 13 + debian/open5gs-bsf.install | 3 + docs/_docs/guide/01-quickstart.md | 4 + .../guide/02-building-open5gs-from-sources.md | 8 + .../guide/03-splitting-network-functions.md | 1 + docs/_docs/platform/02-centos.md | 2 +- docs/_docs/troubleshoot/01-simple-issues.md | 4 +- .../troubleshoot/02-now-in-github-issues.md | 4 + lib/app/ogs-app.h | 3 + lib/app/ogs-context.c | 3 + lib/app/ogs-context.h | 1 + lib/core/ogs-3gpp-types.c | 116 ++- lib/core/ogs-3gpp-types.h | 57 +- lib/dbi/ims.h | 11 +- lib/dbi/session.c | 1 - lib/diameter/rx/message.c | 26 - lib/diameter/rx/message.h | 53 +- lib/sbi/context.c | 5 + lib/sbi/context.h | 2 + lib/sbi/message.c | 177 +++- lib/sbi/message.h | 55 ++ lib/sbi/nnrf-build.c | 2 +- lib/sbi/nnrf-handler.c | 27 - lib/sbi/ogs-sbi.h | 5 + lib/sbi/openapi/meson.build | 57 ++ .../openapi/model/acceptable_service_info.c | 178 ++++ .../openapi/model/acceptable_service_info.h | 43 + .../model/access_net_charging_identifier.c | 155 ++++ .../model/access_net_charging_identifier.h | 41 + lib/sbi/openapi/model/accumulated_usage.c | 161 ++++ lib/sbi/openapi/model/accumulated_usage.h | 44 + lib/sbi/openapi/model/af_event_notification.c | 160 ++++ lib/sbi/openapi/model/af_event_notification.h | 42 + lib/sbi/openapi/model/af_event_subscription.c | 169 ++++ lib/sbi/openapi/model/af_event_subscription.h | 46 + lib/sbi/openapi/model/af_notif_method.c | 30 + lib/sbi/openapi/model/af_notif_method.h | 31 + lib/sbi/openapi/model/af_requested_data.c | 30 + lib/sbi/openapi/model/af_requested_data.h | 31 + .../openapi/model/af_routing_requirement.c | 271 ++++++ .../openapi/model/af_routing_requirement.h | 52 ++ .../openapi/model/af_routing_requirement_rm.c | 271 ++++++ .../openapi/model/af_routing_requirement_rm.h | 52 ++ .../model/amf3_gpp_access_registration.c | 21 +- .../model/amf3_gpp_access_registration.h | 4 +- ...mf3_gpp_access_registration_modification.c | 21 +- ...mf3_gpp_access_registration_modification.h | 4 +- lib/sbi/openapi/model/amf_dereg_info.c | 21 +- lib/sbi/openapi/model/amf_dereg_info.h | 4 +- .../model/amf_non3_gpp_access_registration.c | 21 +- .../model/amf_non3_gpp_access_registration.h | 4 +- ...on3_gpp_access_registration_modification.c | 21 +- ...on3_gpp_access_registration_modification.h | 4 +- lib/sbi/openapi/model/app_session_context.c | 157 ++++ lib/sbi/openapi/model/app_session_context.h | 45 + .../model/app_session_context_req_data.c | 771 ++++++++++++++++ .../model/app_session_context_req_data.h | 106 +++ .../model/app_session_context_resp_data.c | 176 ++++ .../model/app_session_context_resp_data.h | 44 + .../model/app_session_context_update_data.c | 528 +++++++++++ .../model/app_session_context_update_data.h | 81 ++ lib/sbi/openapi/model/binding_level.c | 30 + lib/sbi/openapi/model/binding_level.h | 31 + lib/sbi/openapi/model/binding_resp.c | 155 ++++ lib/sbi/openapi/model/binding_resp.h | 41 + lib/sbi/openapi/model/deregistration_data.c | 21 +- lib/sbi/openapi/model/deregistration_data.h | 4 +- lib/sbi/openapi/model/deregistration_reason.c | 89 +- lib/sbi/openapi/model/deregistration_reason.h | 13 +- lib/sbi/openapi/model/dnai_change_type.c | 89 +- lib/sbi/openapi/model/dnai_change_type.h | 15 +- lib/sbi/openapi/model/events_notification.c | 756 +++++++++++++++ lib/sbi/openapi/model/events_notification.h | 92 ++ lib/sbi/openapi/model/events_subsc_req_data.c | 286 ++++++ lib/sbi/openapi/model/events_subsc_req_data.h | 55 ++ .../openapi/model/events_subsc_req_data_rm.c | 286 ++++++ .../openapi/model/events_subsc_req_data_rm.h | 55 ++ .../openapi/model/extended_problem_details.c | 318 +++++++ .../openapi/model/extended_problem_details.h | 60 ++ .../model/extended_problem_details_all_of.c | 109 +++ .../model/extended_problem_details_all_of.h | 39 + lib/sbi/openapi/model/flow_status.c | 89 +- lib/sbi/openapi/model/flow_status.h | 13 +- lib/sbi/openapi/model/flow_usage.c | 30 + lib/sbi/openapi/model/flow_usage.h | 31 + lib/sbi/openapi/model/flows.c | 191 ++++ lib/sbi/openapi/model/flows.h | 42 + lib/sbi/openapi/model/ims_vo_ps.c | 89 +- lib/sbi/openapi/model/ims_vo_ps.h | 13 +- lib/sbi/openapi/model/media_component.c | 859 +++++++++++++++++ lib/sbi/openapi/model/media_component.h | 114 +++ .../model/media_component_resources_status.c | 30 + .../model/media_component_resources_status.h | 31 + lib/sbi/openapi/model/media_component_rm.c | 865 ++++++++++++++++++ lib/sbi/openapi/model/media_component_rm.h | 114 +++ lib/sbi/openapi/model/media_sub_component.c | 369 ++++++++ lib/sbi/openapi/model/media_sub_component.h | 63 ++ .../openapi/model/media_sub_component_rm.c | 369 ++++++++ .../openapi/model/media_sub_component_rm.h | 63 ++ lib/sbi/openapi/model/media_type.c | 30 + lib/sbi/openapi/model/media_type.h | 31 + lib/sbi/openapi/model/new_tsn_bridge.c | 184 ++++ lib/sbi/openapi/model/new_tsn_bridge.h | 44 + .../openapi/model/out_of_credit_information.c | 160 ++++ .../openapi/model/out_of_credit_information.h | 42 + lib/sbi/openapi/model/parameter_combination.c | 149 +++ lib/sbi/openapi/model/parameter_combination.h | 43 + lib/sbi/openapi/model/pcf_binding.c | 728 +++++++++++++++ lib/sbi/openapi/model/pcf_binding.h | 88 ++ lib/sbi/openapi/model/pcf_binding_patch.c | 381 ++++++++ lib/sbi/openapi/model/pcf_binding_patch.h | 59 ++ .../model/pcscf_restoration_request_data.c | 209 +++++ .../model/pcscf_restoration_request_data.h | 49 + .../openapi/model/preemption_capability_rm.c | 85 ++ .../openapi/model/preemption_capability_rm.h | 38 + .../model/preemption_control_information.c | 30 + .../model/preemption_control_information.h | 31 + .../model/preemption_control_information_rm.c | 85 ++ .../model/preemption_control_information_rm.h | 38 + .../model/preemption_vulnerability_rm.c | 85 ++ .../model/preemption_vulnerability_rm.h | 38 + .../model/priority_sharing_indicator.c | 30 + .../model/priority_sharing_indicator.h | 31 + .../model/qos_monitoring_information.c | 142 +++ .../model/qos_monitoring_information.h | 42 + .../model/qos_monitoring_information_rm.c | 142 +++ .../model/qos_monitoring_information_rm.h | 42 + lib/sbi/openapi/model/qos_monitoring_report.c | 74 +- lib/sbi/openapi/model/qos_monitoring_report.h | 7 +- .../model/qos_notification_control_info.c | 117 ++- .../model/qos_notification_control_info.h | 13 +- .../model/registration_data_set_name.c | 89 +- .../model/registration_data_set_name.h | 13 +- lib/sbi/openapi/model/registration_reason.c | 89 +- lib/sbi/openapi/model/registration_reason.h | 13 +- lib/sbi/openapi/model/required_access_info.c | 30 + lib/sbi/openapi/model/required_access_info.h | 31 + lib/sbi/openapi/model/reserv_priority.c | 30 + lib/sbi/openapi/model/reserv_priority.h | 31 + .../openapi/model/resources_allocation_info.c | 157 ++++ .../openapi/model/resources_allocation_info.h | 42 + lib/sbi/openapi/model/serv_auth_info.c | 30 + lib/sbi/openapi/model/serv_auth_info.h | 31 + lib/sbi/openapi/model/service_info_status.c | 30 + lib/sbi/openapi/model/service_info_status.h | 31 + .../openapi/model/sip_forking_indication.c | 30 + .../openapi/model/sip_forking_indication.h | 31 + lib/sbi/openapi/model/smf_registration.c | 21 +- lib/sbi/openapi/model/smf_registration.h | 4 +- lib/sbi/openapi/model/spatial_validity.c | 139 +++ lib/sbi/openapi/model/spatial_validity.h | 39 + lib/sbi/openapi/model/spatial_validity_rm.c | 139 +++ lib/sbi/openapi/model/spatial_validity_rm.h | 39 + lib/sbi/openapi/model/sponsoring_status.c | 30 + lib/sbi/openapi/model/sponsoring_status.h | 31 + lib/sbi/openapi/model/termination_cause.c | 30 + lib/sbi/openapi/model/termination_cause.h | 31 + lib/sbi/openapi/model/termination_info.c | 128 +++ lib/sbi/openapi/model/termination_info.h | 41 + lib/sbi/openapi/model/traffic_control_data.c | 21 +- lib/sbi/openapi/model/traffic_control_data.h | 4 +- lib/sbi/openapi/model/traffic_influ_data.c | 21 +- lib/sbi/openapi/model/traffic_influ_data.h | 4 +- lib/sbi/openapi/model/tsn_qos_container.c | 142 +++ lib/sbi/openapi/model/tsn_qos_container.h | 42 + lib/sbi/openapi/model/tsn_qos_container_rm.c | 142 +++ lib/sbi/openapi/model/tsn_qos_container_rm.h | 42 + lib/sbi/openapi/model/ue_identity_info.c | 145 +++ lib/sbi/openapi/model/ue_identity_info.h | 42 + lib/sbi/openapi/model/up_path_chg_event.c | 21 +- lib/sbi/openapi/model/up_path_chg_event.h | 4 +- lib/sbi/openapi/model/usage_threshold_rm.c | 161 ++++ lib/sbi/openapi/model/usage_threshold_rm.h | 44 + lib/sbi/path.c | 14 + lib/sbi/path.h | 4 + lib/sbi/support/README.md | 4 +- lib/sbi/support/generator.sh | 2 + .../support/modified/TS29503_Nudm_UECM.yaml | 24 +- .../TS29514_Npcf_PolicyAuthorization.yaml | 90 +- .../modified/TS29521_Nbsf_Management.yaml | 472 ++++++++++ .../support/modified/TS29571_CommonData.yaml | 22 +- .../standard/TS29521_Nbsf_Management.yaml | 472 ++++++++++ src/amf/amf-sm.c | 5 +- src/amf/gmm-handler.c | 2 +- src/amf/ngap-handler.c | 18 +- src/amf/nsmf-build.c | 18 +- src/amf/nsmf-build.h | 5 +- src/amf/sbi-path.c | 4 +- src/bsf/app.c | 40 + src/bsf/bsf-sm.c | 354 +++++++ src/bsf/bsf-sm.h | 51 ++ src/bsf/context.c | 336 +++++++ src/bsf/context.h | 125 +++ src/bsf/event.c | 77 ++ src/bsf/event.h | 75 ++ src/bsf/init.c | 142 +++ src/bsf/meson.build | 59 ++ src/bsf/nbsf-handler.c | 289 ++++++ src/bsf/nbsf-handler.h | 36 + src/bsf/nf-sm.c | 406 ++++++++ src/bsf/nnrf-build.c | 55 ++ src/bsf/nnrf-build.h | 36 + src/bsf/nnrf-handler.c | 335 +++++++ src/bsf/nnrf-handler.h | 44 + src/bsf/sbi-path.c | 185 ++++ src/bsf/sbi-path.h | 46 + src/bsf/timer.c | 118 +++ src/bsf/timer.h | 57 ++ src/meson.build | 1 + src/pcf/context.c | 174 +++- src/pcf/context.h | 48 +- src/pcf/meson.build | 6 + src/pcf/namf-build.c | 45 + src/pcf/namf-build.h | 36 + src/pcf/nbsf-build.c | 165 ++++ src/pcf/nbsf-build.h | 38 + src/pcf/nbsf-handler.c | 506 ++++++++++ src/pcf/nbsf-handler.h | 38 + src/pcf/nf-sm.c | 2 + src/pcf/npcf-handler.c | 293 ++++++ src/pcf/npcf-handler.h | 5 + src/pcf/nsmf-build.c | 45 + src/pcf/nsmf-build.h | 36 + src/pcf/nudr-handler.c | 401 +------- src/pcf/pcf-sm.c | 136 ++- src/pcf/pcf-sm.h | 1 + src/pcf/sbi-path.c | 53 ++ src/pcf/sbi-path.h | 10 +- src/pcf/sm-sm.c | 149 ++- src/pcrf/pcrf-context.c | 8 +- src/pcrf/pcrf-gx-path.c | 28 +- src/pcrf/pcrf-rx-path.c | 32 +- src/smf/gsm-handler.c | 3 +- src/smf/gsm-sm.c | 98 +- src/smf/n4-handler.c | 5 +- src/smf/namf-handler.c | 2 +- src/smf/ngap-handler.c | 4 +- src/smf/npcf-build.c | 127 +++ src/smf/npcf-build.h | 23 + src/smf/npcf-handler.c | 20 +- src/smf/npcf-handler.h | 6 +- src/smf/nsmf-handler.c | 54 +- src/smf/nudm-handler.c | 8 +- src/smf/sbi-path.c | 17 +- src/smf/sbi-path.h | 6 +- src/smf/smf-sm.c | 21 +- src/udr/nudr-handler.c | 2 +- tests/af/af-sm.c | 361 ++++++++ tests/af/af-sm.h | 51 ++ tests/af/context.c | 322 +++++++ tests/af/context.h | 126 +++ tests/af/event.c | 78 ++ tests/af/event.h | 83 ++ tests/af/init.c | 142 +++ tests/af/init.h | 36 + tests/af/local.c | 85 ++ tests/af/local.h | 54 ++ tests/af/meson.build | 51 ++ tests/af/nbsf-build.c | 44 + tests/af/nbsf-build.h | 36 + tests/af/nbsf-handler.c | 121 +++ tests/af/nbsf-handler.h | 36 + tests/af/nf-sm.c | 409 +++++++++ tests/af/nnrf-build.c | 55 ++ tests/af/nnrf-build.h | 36 + tests/af/nnrf-handler.c | 335 +++++++ tests/af/nnrf-handler.h | 44 + tests/af/npcf-build.c | 264 ++++++ tests/af/npcf-build.h | 36 + tests/af/npcf-handler.c | 63 ++ tests/af/npcf-handler.h | 36 + tests/af/sbi-path.c | 179 ++++ tests/af/sbi-path.h | 50 + tests/af/timer.c | 116 +++ tests/af/timer.h | 57 ++ tests/app/5gc-init.c | 4 + tests/app/app-init.c | 4 + tests/common/meson.build | 6 +- tests/meson.build | 1 + tests/vonr/abts-main.c | 8 + tests/vonr/af-test.c | 357 ++++++++ tests/vonr/meson.build | 1 + 293 files changed, 24988 insertions(+), 1507 deletions(-) create mode 100644 configs/open5gs/bsf.yaml.in create mode 100644 configs/systemd/open5gs-bsfd.service.in create mode 100644 debian/open5gs-bsf.install create mode 100644 lib/sbi/openapi/model/acceptable_service_info.c create mode 100644 lib/sbi/openapi/model/acceptable_service_info.h create mode 100644 lib/sbi/openapi/model/access_net_charging_identifier.c create mode 100644 lib/sbi/openapi/model/access_net_charging_identifier.h create mode 100644 lib/sbi/openapi/model/accumulated_usage.c create mode 100644 lib/sbi/openapi/model/accumulated_usage.h create mode 100644 lib/sbi/openapi/model/af_event_notification.c create mode 100644 lib/sbi/openapi/model/af_event_notification.h create mode 100644 lib/sbi/openapi/model/af_event_subscription.c create mode 100644 lib/sbi/openapi/model/af_event_subscription.h create mode 100644 lib/sbi/openapi/model/af_notif_method.c create mode 100644 lib/sbi/openapi/model/af_notif_method.h create mode 100644 lib/sbi/openapi/model/af_requested_data.c create mode 100644 lib/sbi/openapi/model/af_requested_data.h create mode 100644 lib/sbi/openapi/model/af_routing_requirement.c create mode 100644 lib/sbi/openapi/model/af_routing_requirement.h create mode 100644 lib/sbi/openapi/model/af_routing_requirement_rm.c create mode 100644 lib/sbi/openapi/model/af_routing_requirement_rm.h create mode 100644 lib/sbi/openapi/model/app_session_context.c create mode 100644 lib/sbi/openapi/model/app_session_context.h create mode 100644 lib/sbi/openapi/model/app_session_context_req_data.c create mode 100644 lib/sbi/openapi/model/app_session_context_req_data.h create mode 100644 lib/sbi/openapi/model/app_session_context_resp_data.c create mode 100644 lib/sbi/openapi/model/app_session_context_resp_data.h create mode 100644 lib/sbi/openapi/model/app_session_context_update_data.c create mode 100644 lib/sbi/openapi/model/app_session_context_update_data.h create mode 100644 lib/sbi/openapi/model/binding_level.c create mode 100644 lib/sbi/openapi/model/binding_level.h create mode 100644 lib/sbi/openapi/model/binding_resp.c create mode 100644 lib/sbi/openapi/model/binding_resp.h create mode 100644 lib/sbi/openapi/model/events_notification.c create mode 100644 lib/sbi/openapi/model/events_notification.h create mode 100644 lib/sbi/openapi/model/events_subsc_req_data.c create mode 100644 lib/sbi/openapi/model/events_subsc_req_data.h create mode 100644 lib/sbi/openapi/model/events_subsc_req_data_rm.c create mode 100644 lib/sbi/openapi/model/events_subsc_req_data_rm.h create mode 100644 lib/sbi/openapi/model/extended_problem_details.c create mode 100644 lib/sbi/openapi/model/extended_problem_details.h create mode 100644 lib/sbi/openapi/model/extended_problem_details_all_of.c create mode 100644 lib/sbi/openapi/model/extended_problem_details_all_of.h create mode 100644 lib/sbi/openapi/model/flow_usage.c create mode 100644 lib/sbi/openapi/model/flow_usage.h create mode 100644 lib/sbi/openapi/model/flows.c create mode 100644 lib/sbi/openapi/model/flows.h create mode 100644 lib/sbi/openapi/model/media_component.c create mode 100644 lib/sbi/openapi/model/media_component.h create mode 100644 lib/sbi/openapi/model/media_component_resources_status.c create mode 100644 lib/sbi/openapi/model/media_component_resources_status.h create mode 100644 lib/sbi/openapi/model/media_component_rm.c create mode 100644 lib/sbi/openapi/model/media_component_rm.h create mode 100644 lib/sbi/openapi/model/media_sub_component.c create mode 100644 lib/sbi/openapi/model/media_sub_component.h create mode 100644 lib/sbi/openapi/model/media_sub_component_rm.c create mode 100644 lib/sbi/openapi/model/media_sub_component_rm.h create mode 100644 lib/sbi/openapi/model/media_type.c create mode 100644 lib/sbi/openapi/model/media_type.h create mode 100644 lib/sbi/openapi/model/new_tsn_bridge.c create mode 100644 lib/sbi/openapi/model/new_tsn_bridge.h create mode 100644 lib/sbi/openapi/model/out_of_credit_information.c create mode 100644 lib/sbi/openapi/model/out_of_credit_information.h create mode 100644 lib/sbi/openapi/model/parameter_combination.c create mode 100644 lib/sbi/openapi/model/parameter_combination.h create mode 100644 lib/sbi/openapi/model/pcf_binding.c create mode 100644 lib/sbi/openapi/model/pcf_binding.h create mode 100644 lib/sbi/openapi/model/pcf_binding_patch.c create mode 100644 lib/sbi/openapi/model/pcf_binding_patch.h create mode 100644 lib/sbi/openapi/model/pcscf_restoration_request_data.c create mode 100644 lib/sbi/openapi/model/pcscf_restoration_request_data.h create mode 100644 lib/sbi/openapi/model/preemption_capability_rm.c create mode 100644 lib/sbi/openapi/model/preemption_capability_rm.h create mode 100644 lib/sbi/openapi/model/preemption_control_information.c create mode 100644 lib/sbi/openapi/model/preemption_control_information.h create mode 100644 lib/sbi/openapi/model/preemption_control_information_rm.c create mode 100644 lib/sbi/openapi/model/preemption_control_information_rm.h create mode 100644 lib/sbi/openapi/model/preemption_vulnerability_rm.c create mode 100644 lib/sbi/openapi/model/preemption_vulnerability_rm.h create mode 100644 lib/sbi/openapi/model/priority_sharing_indicator.c create mode 100644 lib/sbi/openapi/model/priority_sharing_indicator.h create mode 100644 lib/sbi/openapi/model/qos_monitoring_information.c create mode 100644 lib/sbi/openapi/model/qos_monitoring_information.h create mode 100644 lib/sbi/openapi/model/qos_monitoring_information_rm.c create mode 100644 lib/sbi/openapi/model/qos_monitoring_information_rm.h create mode 100644 lib/sbi/openapi/model/required_access_info.c create mode 100644 lib/sbi/openapi/model/required_access_info.h create mode 100644 lib/sbi/openapi/model/reserv_priority.c create mode 100644 lib/sbi/openapi/model/reserv_priority.h create mode 100644 lib/sbi/openapi/model/resources_allocation_info.c create mode 100644 lib/sbi/openapi/model/resources_allocation_info.h create mode 100644 lib/sbi/openapi/model/serv_auth_info.c create mode 100644 lib/sbi/openapi/model/serv_auth_info.h create mode 100644 lib/sbi/openapi/model/service_info_status.c create mode 100644 lib/sbi/openapi/model/service_info_status.h create mode 100644 lib/sbi/openapi/model/sip_forking_indication.c create mode 100644 lib/sbi/openapi/model/sip_forking_indication.h create mode 100644 lib/sbi/openapi/model/spatial_validity.c create mode 100644 lib/sbi/openapi/model/spatial_validity.h create mode 100644 lib/sbi/openapi/model/spatial_validity_rm.c create mode 100644 lib/sbi/openapi/model/spatial_validity_rm.h create mode 100644 lib/sbi/openapi/model/sponsoring_status.c create mode 100644 lib/sbi/openapi/model/sponsoring_status.h create mode 100644 lib/sbi/openapi/model/termination_cause.c create mode 100644 lib/sbi/openapi/model/termination_cause.h create mode 100644 lib/sbi/openapi/model/termination_info.c create mode 100644 lib/sbi/openapi/model/termination_info.h create mode 100644 lib/sbi/openapi/model/tsn_qos_container.c create mode 100644 lib/sbi/openapi/model/tsn_qos_container.h create mode 100644 lib/sbi/openapi/model/tsn_qos_container_rm.c create mode 100644 lib/sbi/openapi/model/tsn_qos_container_rm.h create mode 100644 lib/sbi/openapi/model/ue_identity_info.c create mode 100644 lib/sbi/openapi/model/ue_identity_info.h create mode 100644 lib/sbi/openapi/model/usage_threshold_rm.c create mode 100644 lib/sbi/openapi/model/usage_threshold_rm.h create mode 100644 lib/sbi/support/modified/TS29521_Nbsf_Management.yaml create mode 100644 lib/sbi/support/standard/TS29521_Nbsf_Management.yaml create mode 100644 src/bsf/app.c create mode 100644 src/bsf/bsf-sm.c create mode 100644 src/bsf/bsf-sm.h create mode 100644 src/bsf/context.c create mode 100644 src/bsf/context.h create mode 100644 src/bsf/event.c create mode 100644 src/bsf/event.h create mode 100644 src/bsf/init.c create mode 100644 src/bsf/meson.build create mode 100644 src/bsf/nbsf-handler.c create mode 100644 src/bsf/nbsf-handler.h create mode 100644 src/bsf/nf-sm.c create mode 100644 src/bsf/nnrf-build.c create mode 100644 src/bsf/nnrf-build.h create mode 100644 src/bsf/nnrf-handler.c create mode 100644 src/bsf/nnrf-handler.h create mode 100644 src/bsf/sbi-path.c create mode 100644 src/bsf/sbi-path.h create mode 100644 src/bsf/timer.c create mode 100644 src/bsf/timer.h create mode 100644 src/pcf/namf-build.c create mode 100644 src/pcf/namf-build.h create mode 100644 src/pcf/nbsf-build.c create mode 100644 src/pcf/nbsf-build.h create mode 100644 src/pcf/nbsf-handler.c create mode 100644 src/pcf/nbsf-handler.h create mode 100644 src/pcf/nsmf-build.c create mode 100644 src/pcf/nsmf-build.h create mode 100644 tests/af/af-sm.c create mode 100644 tests/af/af-sm.h create mode 100644 tests/af/context.c create mode 100644 tests/af/context.h create mode 100644 tests/af/event.c create mode 100644 tests/af/event.h create mode 100644 tests/af/init.c create mode 100644 tests/af/init.h create mode 100644 tests/af/local.c create mode 100644 tests/af/local.h create mode 100644 tests/af/meson.build create mode 100644 tests/af/nbsf-build.c create mode 100644 tests/af/nbsf-build.h create mode 100644 tests/af/nbsf-handler.c create mode 100644 tests/af/nbsf-handler.h create mode 100644 tests/af/nf-sm.c create mode 100644 tests/af/nnrf-build.c create mode 100644 tests/af/nnrf-build.h create mode 100644 tests/af/nnrf-handler.c create mode 100644 tests/af/nnrf-handler.h create mode 100644 tests/af/npcf-build.c create mode 100644 tests/af/npcf-build.h create mode 100644 tests/af/npcf-handler.c create mode 100644 tests/af/npcf-handler.h create mode 100644 tests/af/sbi-path.c create mode 100644 tests/af/sbi-path.h create mode 100644 tests/af/timer.c create mode 100644 tests/af/timer.h create mode 100644 tests/vonr/af-test.c diff --git a/configs/310014.yaml.in b/configs/310014.yaml.in index 6690ab14d..eaafc45c8 100644 --- a/configs/310014.yaml.in +++ b/configs/310014.yaml.in @@ -11,6 +11,7 @@ parameter: # no_udm: true # no_pcf: true # no_nssf: true +# no_bsf: true # no_udr: true # no_mme: true # no_sgwc: true @@ -214,6 +215,11 @@ nssf: s_nssai: sst: 1 +bsf: + sbi: + - addr: 127.0.0.15 + port: 7777 + udr: sbi: - addr: 127.0.0.20 diff --git a/configs/csfb.yaml.in b/configs/csfb.yaml.in index 9c5bc0334..b28cfae52 100644 --- a/configs/csfb.yaml.in +++ b/configs/csfb.yaml.in @@ -11,6 +11,7 @@ parameter: # no_udm: true # no_pcf: true # no_nssf: true +# no_bsf: true # no_udr: true # no_mme: true # no_sgwc: true @@ -248,6 +249,11 @@ nssf: s_nssai: sst: 1 +bsf: + sbi: + - addr: 127.0.0.15 + port: 7777 + udr: sbi: - addr: 127.0.0.20 diff --git a/configs/open5gs/bsf.yaml.in b/configs/open5gs/bsf.yaml.in new file mode 100644 index 000000000..cec7a9b7e --- /dev/null +++ b/configs/open5gs/bsf.yaml.in @@ -0,0 +1,186 @@ +db_uri: mongodb://localhost/open5gs + +# +# logger: +# +# o Set OGS_LOG_INFO to all domain level +# - If `level` is omitted, the default level is OGS_LOG_INFO) +# - If `domain` is omitted, the all domain level is set from 'level' +# (Nothing is needed) +# +# o Set OGS_LOG_ERROR to all domain level +# - `level` can be set with none, fatal, error, warn, info, debug, trace +# level: error +# +# o Set OGS_LOG_DEBUG to mme/emm domain level +# level: debug +# domain: mme,emm +# +# o Set OGS_LOG_TRACE to all domain level +# level: trace +# domain: core,sbi,bsf,event,tlv,mem,sock +# +logger: + file: @localstatedir@/log/open5gs/bsf.log +# +# bsf: +# +# +# +# o SBI Server(http://:80) +# sbi: +# +# o SBI Server(http://:80) +# sbi: +# - addr: +# - 0.0.0.0 +# - ::0 +# port: 7777 +# +# o SBI Server(https://:443) +# sbi: +# - tls: +# key: bsf.key +# pem: bsf.pem +# +# o SBI Server(https://127.0.0.15:443, http://[::1]:80) +# sbi: +# - addr: 127.0.0.15 +# tls: +# key: bsf.key +# pem: bsf.pem +# - addr: ::1 +# +# o SBI Server(http://bsf.open5gs.org:80) +# sbi: +# - name: bsf.open5gs.org +# +# o SBI Server(http://127.0.0.15:7777) +# sbi: +# - addr: 127.0.0.15 +# port: 7777 +# +# o SBI Server(http://:80) +# sbi: +# - dev: eth0 +# +# o Provide custom SBI address to be advertised to NRF +# sbi: +# - dev: eth0 +# advertise: open5gs-bsf.svc.local +# +# sbi: +# - addr: localhost +# advertise: +# - 127.0.0.99 +# - ::1 +# +bsf: + sbi: + - addr: 127.0.0.15 + port: 7777 + +# +# nrf: +# +# > +# +# o SBI Client(http://127.0.0.10:7777) +# sbi: +# addr: 127.0.0.10 +# port: 7777 +# +# o SBI Client(https://127.0.0.10:443, http://nrf.open5gs.org:80) +# sbi: +# - addr: 127.0.0.10 +# tls: +# key: nrf.key +# pem: nrf.pem +# - name: nrf.open5gs.org +# +# o SBI Client(http://[fe80::1%@loopback_devname@]:80) +# If prefer_ipv4 is true, http://127.0.0.10:80 is selected. +# +# sbi: +# addr: +# - 127.0.0.10 +# - fe80::1%@loopback_devname@ +# +nrf: + sbi: + - addr: + - 127.0.0.10 + - ::1 + port: 7777 + +# +# parameter: +# +# o Number of output streams per SCTP associations. +# sctp_streams: 30 +# +# o Disable use of IPv4 addresses (only IPv6) +# no_ipv4: true +# +# o Disable use of IPv6 addresses (only IPv4) +# no_ipv6: true +# +# o Prefer IPv4 instead of IPv6 for estabishing new GTP connections. +# prefer_ipv4: true +# +parameter: + +# +# max: +# +# o Maximum Number of UE per AMF/MME +# ue: 1024 +# o Maximum Number of gNB/eNB per AMF/MME +# gnb: 32 +# +max: + +# +# pool: +# +# o The default memory pool size was set assuming 1024 UEs. +# To connect more UEs, you need to increase the size further. +# +# - Pool-size 128 => 65536 Number +# - Pool-size 256 => 16384 Number +# - Pool-size 512 => 4096 Number +# - Pool-size 1024 => 1024 Number +# - Pool-size 2048 => 512 Number +# - Pool-size 8192 => 128 Number +# - Pool-size 1024*1024 => 8 Number +# +# 128: 65536 +# 256: 16384 +# 512: 4096 +# 1024: 1024 +# 2048: 512 +# 8192: 128 +# big: 8 +# +pool: + +# +# time: +# +# o NF Instance Heartbeat (Default : 0) +# NFs will not send heart-beat timer in NFProfile +# NRF will send heart-beat timer in NFProfile +# +# o NF Instance Heartbeat (20 seconds) +# NFs will send heart-beat timer (20 seconds) in NFProfile +# NRF can change heart-beat timer in NFProfile +# +# nf_instance: +# heartbeat: 20 +# +# o Message Wait Duration (Default : 10,000 ms = 10 seconds) +# +# o Message Wait Duration (3000 ms) +# message: +# duration: 3000 +time: diff --git a/configs/open5gs/meson.build b/configs/open5gs/meson.build index 11186bdb1..80fe9124c 100644 --- a/configs/open5gs/meson.build +++ b/configs/open5gs/meson.build @@ -34,6 +34,7 @@ open5gs_conf = ''' udr.yaml pcf.yaml nssf.yaml + bsf.yaml '''.split() foreach file : open5gs_conf diff --git a/configs/sample.yaml.in b/configs/sample.yaml.in index 6525b13fd..fcffb11ba 100644 --- a/configs/sample.yaml.in +++ b/configs/sample.yaml.in @@ -11,6 +11,7 @@ parameter: # no_udm: true # no_pcf: true # no_nssf: true +# no_bsf: true # no_udr: true # no_mme: true # no_sgwc: true @@ -213,6 +214,11 @@ nssf: port: 7777 s_nssai: sst: 1 +bsf: + sbi: + - addr: 127.0.0.15 + port: 7777 + udr: sbi: - addr: 127.0.0.20 diff --git a/configs/slice.yaml.in b/configs/slice.yaml.in index c759c1272..beb1792df 100644 --- a/configs/slice.yaml.in +++ b/configs/slice.yaml.in @@ -11,6 +11,7 @@ parameter: # no_udm: true # no_pcf: true # no_nssf: true +# no_bsf: true # no_udr: true # no_mme: true # no_sgwc: true @@ -228,6 +229,11 @@ nssf: sst: 1 sd: 009000 +bsf: + sbi: + - addr: 127.0.0.15 + port: 7777 + udr: sbi: - addr: 127.0.0.20 diff --git a/configs/srslte.yaml.in b/configs/srslte.yaml.in index f4690c7ad..9f3ad21ca 100644 --- a/configs/srslte.yaml.in +++ b/configs/srslte.yaml.in @@ -11,6 +11,7 @@ parameter: # no_udm: true # no_pcf: true # no_nssf: true +# no_bsf: true # no_udr: true # no_mme: true # no_sgwc: true @@ -214,6 +215,11 @@ nssf: s_nssai: sst: 1 +bsf: + sbi: + - addr: 127.0.0.15 + port: 7777 + udr: sbi: - addr: 127.0.0.20 diff --git a/configs/systemd/meson.build b/configs/systemd/meson.build index 8b0cf3422..d597c8263 100644 --- a/configs/systemd/meson.build +++ b/configs/systemd/meson.build @@ -29,6 +29,7 @@ systemd_conf_in = ''' open5gs-udmd.service open5gs-pcfd.service open5gs-nssfd.service + open5gs-bsfd.service open5gs-udrd.service '''.split() diff --git a/configs/systemd/open5gs-bsfd.service.in b/configs/systemd/open5gs-bsfd.service.in new file mode 100644 index 000000000..26fb6462e --- /dev/null +++ b/configs/systemd/open5gs-bsfd.service.in @@ -0,0 +1,18 @@ +[Unit] +Description=Open5GS BSF Daemon +Wants=mongodb.service mongod.service + +[Service] +Type=simple + +User=open5gs +Group=open5gs + +Restart=always +ExecStart=@bindir@/open5gs-bsfd -c @sysconfdir@/open5gs/bsf.yaml +RestartSec=2 +RestartPreventExitStatus=1 +ExecReload=/bin/kill -HUP $MAINPID + +[Install] +WantedBy=multi-user.target diff --git a/configs/volte.yaml.in b/configs/volte.yaml.in index 2fc0d5d49..5a19ce51d 100644 --- a/configs/volte.yaml.in +++ b/configs/volte.yaml.in @@ -11,6 +11,7 @@ parameter: # no_udm: true # no_pcf: true # no_nssf: true +# no_bsf: true # no_udr: true # no_mme: true # no_sgwc: true @@ -221,6 +222,11 @@ nssf: s_nssai: sst: 1 +bsf: + sbi: + - addr: 127.0.0.15 + port: 7777 + udr: sbi: - addr: 127.0.0.20 diff --git a/configs/vonr.yaml.in b/configs/vonr.yaml.in index bc28a0352..21ce6b84d 100644 --- a/configs/vonr.yaml.in +++ b/configs/vonr.yaml.in @@ -11,6 +11,7 @@ parameter: # no_udm: true # no_pcf: true # no_nssf: true +# no_bsf: true # no_udr: true # no_mme: true # no_sgwc: true @@ -219,6 +220,16 @@ nssf: s_nssai: sst: 1 +bsf: + sbi: + - addr: 127.0.0.15 + port: 7777 + +af: + sbi: + - addr: 127.0.0.16 + port: 7777 + udr: sbi: - addr: 127.0.0.20 diff --git a/debian/control b/debian/control index 65bc02c47..57916412e 100644 --- a/debian/control +++ b/debian/control @@ -211,6 +211,18 @@ Description: NSSF (Network Slice Selection Function) . This package provides the NSSF (Network Slice Selection Function) +Package: open5gs-bsf +Architecture: any +Multi-Arch: same +Depends: ${shlibs:Depends}, + ${misc:Depends}, + open5gs-common (= ${binary:Version}) +Description: PCF (Policy Control Function) + Open5GS is a C-language implementation of 5G Core and EPC + Packet Core, i.e. the core network of an NR/LTE network (Release-16) + . + This package provides the BSF (Binding Support Function) + Package: open5gs-udr Architecture: any Multi-Arch: same @@ -241,6 +253,7 @@ Depends: ${misc:Depends}, open5gs-udm (= ${binary:Version}), open5gs-pcf (= ${binary:Version}), open5gs-nssf (= ${binary:Version}), + open5gs-bsf (= ${binary:Version}), open5gs-udr (= ${binary:Version}) Description: 5G Core and EPC (metapackage) Open5GS is a C-language implementation of 5G Core and EPC diff --git a/debian/open5gs-bsf.install b/debian/open5gs-bsf.install new file mode 100644 index 000000000..4a870b563 --- /dev/null +++ b/debian/open5gs-bsf.install @@ -0,0 +1,3 @@ +usr/bin/open5gs-bsfd +configs/open5gs/bsf.yaml etc/open5gs +configs/systemd/open5gs-bsfd.service lib/systemd/system diff --git a/docs/_docs/guide/01-quickstart.md b/docs/_docs/guide/01-quickstart.md index b3a1d3280..8f9152958 100644 --- a/docs/_docs/guide/01-quickstart.md +++ b/docs/_docs/guide/01-quickstart.md @@ -53,6 +53,7 @@ The Open5GS 5G SA Core contains the following functions: * UDR - Unified Data Repository * PCF - Policy and Charging Function * NSSF - Network Slice Selection Function +* BSF - Binding Support Function The 5G SA core works in a different way to the 4G core - it uses a **Service Based Architecture** (SBI). **Control plane** functions are configured to register with the NRF, and the NRF then helps them discover the other core functions. Running through the other functions: The AMF handles connection and mobility management; a subset of what the 4G MME is tasked with. gNBs (5G basestations) connect to the AMF. The UDM, AUSF and UDR carry out similar operations as the 4G HSS, generating SIM authentication vectors and holding the subscriber profile. Session management is all handled by the SMF (previously the responsibility of the 4G MME/ SGWC/ PGWC). The NSSF provides a way to select the network slice. Finally there is the PCF, used for charging and enforcing subscriber policies. @@ -221,6 +222,7 @@ 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 NSSF-sbi = 127.0.0.14:7777 for 5G SBI +BSF-sbi = 127.0.0.15:7777 for 5G SBI UDR-sbi = 127.0.0.20:7777 for 5G SBI ``` @@ -467,6 +469,7 @@ $ sudo systemctl stop open5gs-ausfd $ sudo systemctl stop open5gs-udmd $ sudo systemctl stop open5gs-pcfd $ sudo systemctl stop open5gs-nssfd +$ sudo systemctl stop open5gs-bsfd $ sudo systemctl stop open5gs-udrd $ sudo systemctl stop open5gs-webui ``` @@ -485,6 +488,7 @@ $ sudo systemctl restart open5gs-ausfd $ sudo systemctl restart open5gs-udmd $ sudo systemctl restart open5gs-pcfd $ sudo systemctl restart open5gs-nssfd +$ sudo systemctl restart open5gs-bsfd $ sudo systemctl restart open5gs-udrd $ sudo systemctl restart open5gs-webui ``` diff --git a/docs/_docs/guide/02-building-open5gs-from-sources.md b/docs/_docs/guide/02-building-open5gs-from-sources.md index 8cb8b705a..7a4c3a626 100644 --- a/docs/_docs/guide/02-building-open5gs-from-sources.md +++ b/docs/_docs/guide/02-building-open5gs-from-sources.md @@ -329,6 +329,14 @@ Open5GS daemon v2.1.0 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) +$ ./install/bin/open5gs-bsfd +Open5GS daemon v2.1.0 + +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) + $ ./install/bin/open5gs-udrd Open5GS daemon v2.1.0 diff --git a/docs/_docs/guide/03-splitting-network-functions.md b/docs/_docs/guide/03-splitting-network-functions.md index a71c383a5..f476073db 100644 --- a/docs/_docs/guide/03-splitting-network-functions.md +++ b/docs/_docs/guide/03-splitting-network-functions.md @@ -35,6 +35,7 @@ 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 NSSF-sbi = 127.0.0.14:7777 for 5G SBI +BSF-sbi = 127.0.0.15:7777 for 5G SBI UDR-sbi = 127.0.0.20:7777 for 5G SBI ``` diff --git a/docs/_docs/platform/02-centos.md b/docs/_docs/platform/02-centos.md index cd7718047..cf58c0b87 100644 --- a/docs/_docs/platform/02-centos.md +++ b/docs/_docs/platform/02-centos.md @@ -325,7 +325,7 @@ $ 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-upfd open5gs-nssfd open5gs-bsfd ``` ## Building WebUI of Open5GS diff --git a/docs/_docs/troubleshoot/01-simple-issues.md b/docs/_docs/troubleshoot/01-simple-issues.md index 1d5504960..15f96d978 100644 --- a/docs/_docs/troubleshoot/01-simple-issues.md +++ b/docs/_docs/troubleshoot/01-simple-issues.md @@ -25,10 +25,11 @@ open5gs 27543 0.0 0.0 222416 9672 ? Ssl 12:13 0:00 /usr/bin/open5g 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 open5gs 27600 0.0 0.0 222329 9669 ? Ssl 12:13 0:00 /usr/bin/open5gs-nssfd -c /etc/open5gs/nssf.yaml +open5gs 27600 0.0 0.0 222329 9669 ? Ssl 12:13 0:00 /usr/bin/open5gs-bsfd -c /etc/open5gs/bsf.yaml 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 & UDR are all running. +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. If your instance doesn't show this make sure you're started each service: ```bash @@ -45,6 +46,7 @@ $ systemctl start open5gs-ausfd.service $ systemctl start open5gs-udmd.service $ systemctl start open5gs-pcfd.service $ systemctl start open5gs-nssfd.service +$ systemctl start open5gs-bsfd.service $ systemctl start open5gs-udrd.service ``` diff --git a/docs/_docs/troubleshoot/02-now-in-github-issues.md b/docs/_docs/troubleshoot/02-now-in-github-issues.md index 3eb76d857..8429fe723 100644 --- a/docs/_docs/troubleshoot/02-now-in-github-issues.md +++ b/docs/_docs/troubleshoot/02-now-in-github-issues.md @@ -280,6 +280,7 @@ $ sudo pkill -9 open5gs-ausfd $ sudo pkill -9 open5gs-udmd $ sudo pkill -9 open5gs-pcfd $ sudo pkill -9 open5gs-nssfd +$ sudo pkill -9 open5gs-bsfd $ sudo pkill -9 open5gs-udrd ``` @@ -413,6 +414,7 @@ $ open5gs-ausfd $ open5gs-udmd $ open5gs-pcfd $ open5gs-nssfd +$ open5gs-bsfd $ open5gs-udrd ``` @@ -618,6 +620,7 @@ $ sudo pkill -9 open5gs-ausfd $ sudo pkill -9 open5gs-udmd $ sudo pkill -9 open5gs-pcfd $ sudo pkill -9 open5gs-nssfd +$ sudo pkill -9 open5gs-bsfd $ sudo pkill -9 open5gs-udrd ``` @@ -1078,6 +1081,7 @@ Currently, the number of UE is limited to `128*128`. * UDM : 127.0.0.12 * PCF : 127.0.0.13 * NSSF : 127.0.0.14 +* BSF : 127.0.0.15 * UDR : 127.0.0.20 ``` diff --git a/lib/app/ogs-app.h b/lib/app/ogs-app.h index 40f62c72a..019450c32 100644 --- a/lib/app/ogs-app.h +++ b/lib/app/ogs-app.h @@ -81,6 +81,9 @@ void pcf_terminate(void); int nssf_initialize(void); void nssf_terminate(void); +int bsf_initialize(void); +void bsf_terminate(void); + int upf_initialize(void); void upf_terminate(void); diff --git a/lib/app/ogs-context.c b/lib/app/ogs-context.c index d63dc2931..17d074c0b 100644 --- a/lib/app/ogs-context.c +++ b/lib/app/ogs-context.c @@ -332,6 +332,9 @@ int ogs_app_context_parse_config(void) } else if (!strcmp(parameter_key, "no_nssf")) { self.parameter.no_nssf = ogs_yaml_iter_bool(¶meter_iter); + } else if (!strcmp(parameter_key, "no_bsf")) { + self.parameter.no_bsf = + ogs_yaml_iter_bool(¶meter_iter); } else if (!strcmp(parameter_key, "no_udr")) { self.parameter.no_udr = ogs_yaml_iter_bool(¶meter_iter); diff --git a/lib/app/ogs-context.h b/lib/app/ogs-context.h index 8b2841a86..67bc75cf3 100644 --- a/lib/app/ogs-context.h +++ b/lib/app/ogs-context.h @@ -64,6 +64,7 @@ typedef struct ogs_app_context_s { int no_udm; int no_pcf; int no_nssf; + int no_bsf; int no_udr; int no_nrf; diff --git a/lib/core/ogs-3gpp-types.c b/lib/core/ogs-3gpp-types.c index 3f6d72248..2f840613c 100644 --- a/lib/core/ogs-3gpp-types.c +++ b/lib/core/ogs-3gpp-types.c @@ -462,7 +462,7 @@ char *ogs_ipv4_to_string(uint32_t addr) return (char*)OGS_INET_NTOP(&addr, buf); } -char *ogs_ipv6_to_string(uint8_t *addr6) +char *ogs_ipv6addr_to_string(uint8_t *addr6) { char *buf = NULL; ogs_assert(addr6); @@ -473,6 +473,96 @@ char *ogs_ipv6_to_string(uint8_t *addr6) return (char *)OGS_INET6_NTOP(addr6, buf); } +char *ogs_ipv6prefix_to_string(uint8_t *addr6, uint8_t prefixlen) +{ + char *buf = NULL; + uint8_t tmp[OGS_IPV6_LEN]; + ogs_assert(addr6); + + memset(tmp, 0, OGS_IPV6_LEN); + memcpy(tmp, addr6, prefixlen >> 3); + + buf = ogs_calloc(1, OGS_ADDRSTRLEN); + ogs_assert(buf); + + if (OGS_INET6_NTOP(tmp, buf) == NULL) { + ogs_fatal("Invalid IPv6 address"); + ogs_log_hexdump(OGS_LOG_FATAL, addr6, OGS_IPV6_LEN); + ogs_assert_if_reached(); + } + return ogs_mstrcatf(buf, "/%d", prefixlen); +} + +int ogs_ipv4_from_string(uint32_t *addr, char *string) +{ + int rv; + ogs_sockaddr_t tmp; + + ogs_assert(addr); + ogs_assert(string); + + rv = ogs_inet_pton(AF_INET, string, &tmp); + if (rv != OGS_OK) { + ogs_error("Invalid IPv4 string = %s", string); + return OGS_ERROR; + } + + *addr = tmp.sin.sin_addr.s_addr; + + return OGS_OK; +} + +int ogs_ipv6addr_from_string(uint8_t *addr6, char *string) +{ + int rv; + ogs_sockaddr_t tmp; + + ogs_assert(addr6); + ogs_assert(string); + + rv = ogs_inet_pton(AF_INET6, string, &tmp); + if (rv != OGS_OK) { + ogs_error("Invalid IPv6 string = %s", string); + return OGS_ERROR; + } + + memcpy(addr6, tmp.sin6.sin6_addr.s6_addr, OGS_IPV6_LEN); + + return OGS_OK; +} + +int ogs_ipv6prefix_from_string(uint8_t *addr6, uint8_t *prefixlen, char *string) +{ + int rv; + ogs_sockaddr_t tmp; + char *v = NULL, *pv = NULL, *ipstr = NULL, *mask_or_numbits = NULL; + + ogs_assert(addr6); + ogs_assert(prefixlen); + ogs_assert(string); + pv = v = ogs_strdup(string); + ogs_assert(v); + + ipstr = strsep(&v, "/"); + if (ipstr) + mask_or_numbits = v; + + if (!ipstr || !mask_or_numbits) { + ogs_error("Invalid IPv6 Prefix string = %s", v); + ogs_free(v); + return OGS_ERROR; + } + + rv = ogs_inet_pton(AF_INET6, ipstr, &tmp); + ogs_expect_or_return_val(rv == OGS_OK, rv); + + memcpy(addr6, tmp.sin6.sin6_addr.s6_addr, OGS_IPV6_LEN); + *prefixlen = atoi(mask_or_numbits); + + ogs_free(pv); + return OGS_OK; +} + int ogs_sockaddr_to_user_plane_ip_resource_info( ogs_sockaddr_t *addr, ogs_sockaddr_t *addr6, ogs_user_plane_ip_resource_info_t *info) @@ -574,3 +664,27 @@ void ogs_session_data_free(ogs_session_data_t *session_data) for (i = 0; i < session_data->num_of_pcc_rule; i++) OGS_PCC_RULE_FREE(&session_data->pcc_rule[i]); } + +void ogs_ims_data_free(ogs_ims_data_t *ims_data) +{ + int i, j, k; + + ogs_assert(ims_data); + + for (i = 0; i < ims_data->num_of_media_component; i++) { + ogs_media_component_t *media_component = &ims_data->media_component[i]; + + for (j = 0; j < media_component->num_of_sub; j++) { + ogs_media_sub_component_t *sub = &media_component->sub[j]; + + for (k = 0; k < sub->num_of_flow; k++) { + ogs_flow_t *flow = &sub->flow[k]; + + if (flow->description) { + ogs_free(flow->description); + } else + ogs_assert_if_reached(); + } + } + } +} diff --git a/lib/core/ogs-3gpp-types.h b/lib/core/ogs-3gpp-types.h index ba7c3d342..f29fc8519 100644 --- a/lib/core/ogs-3gpp-types.h +++ b/lib/core/ogs-3gpp-types.h @@ -199,6 +199,7 @@ ogs_uint24_t ogs_s_nssai_sd_from_string(const char *hex); #define OGS_IPV4_LEN 4 #define OGS_IPV6_LEN 16 #define OGS_IPV6_DEFAULT_PREFIX_LEN 64 +#define OGS_IPV6_128_PREFIX_LEN 128 #define OGS_IPV4V6_LEN 20 typedef struct ogs_ip_s { uint32_t addr; @@ -212,8 +213,14 @@ ED3(uint8_t ipv4:1;, int ogs_ip_to_sockaddr(ogs_ip_t *ip, uint16_t port, ogs_sockaddr_t **list); void ogs_sockaddr_to_ip( ogs_sockaddr_t *addr, ogs_sockaddr_t *addr6, ogs_ip_t *ip); + char *ogs_ipv4_to_string(uint32_t addr); -char *ogs_ipv6_to_string(uint8_t *addr6); +char *ogs_ipv6addr_to_string(uint8_t *addr6); +char *ogs_ipv6prefix_to_string(uint8_t *addr6, uint8_t prefixlen); +int ogs_ipv4_from_string(uint32_t *addr, char *string); +int ogs_ipv6addr_from_string(uint8_t *addr6, char *string); +int ogs_ipv6prefix_from_string( + uint8_t *addr6, uint8_t *prefixlen, char *string); /************************************************** * 8.14 PDN Address Allocation (PAA) */ @@ -314,8 +321,7 @@ typedef struct ogs_flow_s { #define OGS_FLOW_FREE(__fLOW) \ do { \ - if ((__fLOW)->description) \ - { \ + if ((__fLOW)->description) { \ ogs_free((__fLOW)->description); \ } \ else \ @@ -337,11 +343,6 @@ typedef struct ogs_pcc_rule_s { ogs_flow_t flow[OGS_MAX_NUM_OF_FLOW]; int num_of_flow; -#define OGS_FLOW_STATUS_ENABLED_UPLINK 0 -#define OGS_FLOW_STATUS_ENABLED_DOWNLINK 1 -#define OGS_FLOW_STATUS_ENABLED 2 -#define OGS_FLOW_STATUS_DISABLED 3 -#define OGS_FLOW_STATUS_REMOVE 4 int flow_status; uint32_t precedence; @@ -624,6 +625,46 @@ typedef struct ogs_session_data_s { void ogs_session_data_free(ogs_session_data_t *session_data); +typedef struct ogs_media_sub_component_s { + uint32_t flow_number; + uint32_t flow_usage; + ogs_flow_t flow[OGS_MAX_NUM_OF_FLOW]; + int num_of_flow; +} ogs_media_sub_component_t; + +typedef struct ogs_media_component_s { + uint32_t media_component_number; + uint32_t media_type; + + uint64_t max_requested_bandwidth_dl; + uint64_t max_requested_bandwidth_ul; + uint64_t min_requested_bandwidth_dl; + uint64_t min_requested_bandwidth_ul; + uint64_t rr_bandwidth; + uint64_t rs_bandwidth; + + int flow_status; + +#define OGS_MAX_NUM_OF_MEDIA_SUB_COMPONENT 8 + ogs_media_sub_component_t sub[OGS_MAX_NUM_OF_MEDIA_SUB_COMPONENT]; + int num_of_sub; +} ogs_media_component_t; + +typedef struct ogs_ims_data_s { + int num_of_msisdn; + struct { + uint8_t buf[OGS_MAX_MSISDN_LEN]; + int len; + char bcd[OGS_MAX_MSISDN_BCD_LEN+1]; + } msisdn[OGS_MAX_NUM_OF_MSISDN]; + +#define OGS_MAX_NUM_OF_MEDIA_COMPONENT 16 + ogs_media_component_t media_component[OGS_MAX_NUM_OF_MEDIA_COMPONENT]; + int num_of_media_component; +} ogs_ims_data_t; + +void ogs_ims_data_free(ogs_ims_data_t *ims_data); + #ifdef __cplusplus } #endif diff --git a/lib/dbi/ims.h b/lib/dbi/ims.h index 82fcfe3b8..fadc8432c 100644 --- a/lib/dbi/ims.h +++ b/lib/dbi/ims.h @@ -28,6 +28,8 @@ extern "C" { #endif + +/* The ogs_msisdn_data_s structure is always used with the db library. */ typedef struct ogs_msisdn_data_s { struct { uint8_t buf[OGS_MAX_IMSI_LEN]; @@ -46,15 +48,6 @@ typedef struct ogs_msisdn_data_s { int ogs_dbi_msisdn_data( char *imsi_or_msisdn_bcd, ogs_msisdn_data_t *msisdn_data); -typedef struct ogs_ims_data_s { - int num_of_msisdn; - struct { - uint8_t buf[OGS_MAX_MSISDN_LEN]; - int len; - char bcd[OGS_MAX_MSISDN_BCD_LEN+1]; - } msisdn[OGS_MAX_NUM_OF_MSISDN]; -} ogs_ims_data_t; - int ogs_dbi_ims_data(char *supi, ogs_ims_data_t *ims_data); #ifdef __cplusplus diff --git a/lib/dbi/session.c b/lib/dbi/session.c index b9e419528..e5280eeb7 100644 --- a/lib/dbi/session.c +++ b/lib/dbi/session.c @@ -479,7 +479,6 @@ done: ogs_assert(pcc_rule->id); pcc_rule->precedence = pcc_rule_index+1; - pcc_rule->flow_status = OGS_FLOW_STATUS_ENABLED; pcc_rule_index++; } session_data->num_of_pcc_rule = pcc_rule_index; diff --git a/lib/diameter/rx/message.c b/lib/diameter/rx/message.c index 139d8dc52..6b89b2aff 100644 --- a/lib/diameter/rx/message.c +++ b/lib/diameter/rx/message.c @@ -106,29 +106,3 @@ int ogs_diam_rx_init(void) return 0; } - -void ogs_diam_rx_message_free(ogs_diam_rx_message_t *rx_message) -{ - int i, j, k; - - ogs_assert(rx_message); - - for (i = 0; i < rx_message->num_of_media_component; i++) { - ogs_diam_rx_media_component_t *media_component = - &rx_message->media_component[i]; - - for (j = 0; j < media_component->num_of_sub; j++) { - ogs_diam_rx_media_sub_component_t *sub = &media_component->sub[j]; - - for (k = 0; k < sub->num_of_flow; k++) { - ogs_flow_t *flow = &sub->flow[k]; - - if (flow->description) { - ogs_free(flow->description); - } - else - ogs_assert_if_reached(); - } - } - } -} diff --git a/lib/diameter/rx/message.h b/lib/diameter/rx/message.h index 6bc806705..c99b235fa 100644 --- a/lib/diameter/rx/message.h +++ b/lib/diameter/rx/message.h @@ -46,6 +46,7 @@ extern "C" { #define OGS_DIAM_RX_AVP_CODE_MEDIA_SUB_COMPONENT (519) #define OGS_DIAM_RX_AVP_CODE_FLOW_DESCRIPTION (507) #define OGS_DIAM_RX_AVP_CODE_FLOW_NUMBER (509) +#define OGS_DIAM_RX_AVP_CODE_FLOW_STATUS (511) #define OGS_DIAM_RX_AVP_CODE_FLOW_USAGE (512) extern struct dict_object *ogs_diam_rx_application; @@ -60,6 +61,14 @@ extern struct dict_object *ogs_diam_rx_cmd_sta; extern struct dict_object *ogs_diam_rx_af_application_identifier; extern struct dict_object *ogs_diam_rx_media_component_description; extern struct dict_object *ogs_diam_rx_media_component_number; +#define OGS_DIAM_RX_MEDIA_TYPE_AUDIO 0 +#define OGS_DIAM_RX_MEDIA_TYPE_VIDEO 1 +#define OGS_DIAM_RX_MEDIA_TYPE_DATA 2 +#define OGS_DIAM_RX_MEDIA_TYPE_APPLICATION 3 +#define OGS_DIAM_RX_MEDIA_TYPE_CONTROL 4 +#define OGS_DIAM_RX_MEDIA_TYPE_TEXT 5 +#define OGS_DIAM_RX_MEDIA_TYPE_MESSAGE 6 +#define OGS_DIAM_RX_MEDIA_TYPE_OTHER 0xFFFFFFFF extern struct dict_object *ogs_diam_rx_media_type; extern struct dict_object *ogs_diam_rx_max_requested_bandwidth_ul; extern struct dict_object *ogs_diam_rx_max_requested_bandwidth_dl; @@ -75,6 +84,9 @@ extern struct dict_object *ogs_diam_rx_flow_status; extern struct dict_object *ogs_diam_rx_codec_data; extern struct dict_object *ogs_diam_rx_media_sub_component; extern struct dict_object *ogs_diam_rx_flow_number; +#define OGS_DIAM_RX_FLOW_USAGE_NO_INFORMATION 0 +#define OGS_DIAM_RX_FLOW_USAGE_RTCP 1 +#define OGS_DIAM_RX_FLOW_USAGE_AF_SIGNALLING 2 extern struct dict_object *ogs_diam_rx_flow_usage; extern struct dict_object *ogs_diam_rx_flow_description; extern struct dict_object *ogs_diam_rx_subscription_id; @@ -132,41 +144,6 @@ extern struct dict_object *ogs_diam_rx_abort_cause; #define OGS_DIAM_RX_TERMINATION_CAUSE_DIAMETER_SESSION_TIMEOUT 8 extern struct dict_object *ogs_diam_rx_termination_cause; -typedef struct ogs_diam_rx_media_sub_component_s { - uint32_t flow_number; -#define OGS_DIAM_RX_FLOW_USAGE_NO_INFORMATION 0 -#define OGS_DIAM_RX_FLOW_USAGE_RTCP 1 -#define OGS_DIAM_RX_FLOW_USAGE_AF_SIGNALLING 2 - uint32_t flow_usage; - ogs_flow_t flow[OGS_MAX_NUM_OF_FLOW]; - int num_of_flow; -} ogs_diam_rx_media_sub_component_t; - -typedef struct ogs_diam_rx_media_component_s { - uint32_t media_component_number; -#define OGS_DIAM_RX_MEDIA_TYPE_AUDIO 0 -#define OGS_DIAM_RX_MEDIA_TYPE_VIDEO 1 -#define OGS_DIAM_RX_MEDIA_TYPE_DATA 2 -#define OGS_DIAM_RX_MEDIA_TYPE_APPLICATION 3 -#define OGS_DIAM_RX_MEDIA_TYPE_CONTROL 4 -#define OGS_DIAM_RX_MEDIA_TYPE_TEXT 5 -#define OGS_DIAM_RX_MEDIA_TYPE_MESSAGE 6 -#define OGS_DIAM_RX_MEDIA_TYPE_OTHER 0xFFFFFFFF - uint32_t media_type; - - uint64_t max_requested_bandwidth_dl; - uint64_t max_requested_bandwidth_ul; - uint64_t min_requested_bandwidth_dl; - uint64_t min_requested_bandwidth_ul; - uint64_t rr_bandwidth; - uint64_t rs_bandwidth; - -#define OGS_DIAM_MAX_NUM_OF_MEDIA_SUB_COMPONENT 8 - ogs_diam_rx_media_sub_component_t - sub[OGS_DIAM_MAX_NUM_OF_MEDIA_SUB_COMPONENT]; - int num_of_sub; -} ogs_diam_rx_media_component_t; - typedef struct ogs_diam_rx_message_s { #define OGS_DIAM_RX_CMD_CODE_AA 265 #define OGS_DIAM_RX_CMD_CODE_SESSION_TERMINATION 275 @@ -183,14 +160,10 @@ typedef struct ogs_diam_rx_message_s { #define OGS_DIAM_RX_DIAMETER_TEMPORARY_NETWORK_FAILURE 5068 uint32_t result_code; -#define OGS_DIAM_MAX_NUM_OF_MEDIA_COMPONENT 16 - ogs_diam_rx_media_component_t - media_component[OGS_DIAM_MAX_NUM_OF_MEDIA_COMPONENT]; - int num_of_media_component; + ogs_ims_data_t ims_data; } ogs_diam_rx_message_t; int ogs_diam_rx_init(void); -void ogs_diam_rx_message_free(ogs_diam_rx_message_t *rx_message); #ifdef __cplusplus } diff --git a/lib/sbi/context.c b/lib/sbi/context.c index 70123e5e4..8d4e18da4 100644 --- a/lib/sbi/context.c +++ b/lib/sbi/context.c @@ -1080,6 +1080,11 @@ bool ogs_sbi_client_associate(ogs_sbi_nf_instance_t *nf_instance) return true; } +OpenAPI_uri_scheme_e ogs_sbi_default_uri_scheme(void) +{ + return OpenAPI_uri_scheme_http; +} + ogs_sbi_client_t *ogs_sbi_client_find_by_service_name( ogs_sbi_nf_instance_t *nf_instance, char *name, char *version) { diff --git a/lib/sbi/context.h b/lib/sbi/context.h index 42287593c..a877999f1 100644 --- a/lib/sbi/context.h +++ b/lib/sbi/context.h @@ -271,6 +271,8 @@ ogs_sbi_client_t *ogs_sbi_client_find_by_service_name( bool ogs_sbi_client_associate(ogs_sbi_nf_instance_t *nf_instance); +OpenAPI_uri_scheme_e ogs_sbi_default_uri_scheme(void); + #define OGS_SBI_NF_INSTANCE(__sBIObject, __nFType) \ (((__sBIObject)->nf_type_array)[__nFType].nf_instance) diff --git a/lib/sbi/message.c b/lib/sbi/message.c index 46b3bc34f..77f5176ac 100644 --- a/lib/sbi/message.c +++ b/lib/sbi/message.c @@ -152,9 +152,15 @@ void ogs_sbi_message_free(ogs_sbi_message_t *message) OpenAPI_sm_policy_decision_free(message->SmPolicyDecision); if (message->SmPolicyData) OpenAPI_sm_policy_data_free(message->SmPolicyData); + if (message->SmPolicyDeleteData) + OpenAPI_sm_policy_delete_data_free(message->SmPolicyDeleteData); if (message->AuthorizedNetworkSliceInfo) OpenAPI_authorized_network_slice_info_free( message->AuthorizedNetworkSliceInfo); + if (message->PcfBinding) + OpenAPI_pcf_binding_free(message->PcfBinding); + if (message->AppSessionContext) + OpenAPI_app_session_context_free(message->AppSessionContext); for (i = 0; i < message->num_of_part; i++) { if (message->part[i].pkbuf) @@ -367,6 +373,14 @@ ogs_sbi_request_t *ogs_sbi_build_request(ogs_sbi_message_t *message) if (sNSSAI.sd) ogs_free(sNSSAI.sd); } + if (message->param.ipv4addr) { + ogs_sbi_header_set(request->http.params, + OGS_SBI_PARAM_IPV4ADDR, message->param.ipv4addr); + } + if (message->param.ipv6prefix) { + ogs_sbi_header_set(request->http.params, + OGS_SBI_PARAM_IPV6PREFIX, message->param.ipv6prefix); + } build_content(&request->http, message); @@ -522,6 +536,10 @@ int ogs_sbi_parse_request( cJSON_Delete(item); } } + } else if (!strcmp(ogs_hash_this_key(hi), OGS_SBI_PARAM_IPV4ADDR)) { + message->param.ipv4addr = ogs_hash_this_val(hi); + } else if (!strcmp(ogs_hash_this_key(hi), OGS_SBI_PARAM_IPV6PREFIX)) { + message->param.ipv6prefix = ogs_hash_this_val(hi); } } @@ -831,10 +849,21 @@ static char *build_json(ogs_sbi_message_t *message) } else if (message->SmPolicyData) { item = OpenAPI_sm_policy_data_convertToJSON(message->SmPolicyData); ogs_assert(item); + } else if (message->SmPolicyDeleteData) { + item = OpenAPI_sm_policy_delete_data_convertToJSON( + message->SmPolicyDeleteData); + ogs_assert(item); } else if (message->AuthorizedNetworkSliceInfo) { item = OpenAPI_authorized_network_slice_info_convertToJSON( message->AuthorizedNetworkSliceInfo); ogs_assert(item); + } else if (message->PcfBinding) { + item = OpenAPI_pcf_binding_convertToJSON(message->PcfBinding); + ogs_assert(item); + } else if (message->AppSessionContext) { + item = OpenAPI_app_session_context_convertToJSON( + message->AppSessionContext); + ogs_assert(item); } if (item) { @@ -1436,20 +1465,42 @@ static int parse_json(ogs_sbi_message_t *message, CASE(OGS_SBI_SERVICE_NAME_NPCF_SMPOLICYCONTROL) SWITCH(message->h.resource.component[0]) CASE(OGS_SBI_RESOURCE_NAME_SM_POLICIES) - if (message->res_status == 0) { - message->SmPolicyContextData = - OpenAPI_sm_policy_context_data_parseFromJSON(item); - if (!message->SmPolicyContextData) { - rv = OGS_ERROR; - ogs_error("JSON parse error"); + if (!message->h.resource.component[1]) { + if (message->res_status == 0) { + message->SmPolicyContextData = + OpenAPI_sm_policy_context_data_parseFromJSON(item); + if (!message->SmPolicyContextData) { + rv = OGS_ERROR; + ogs_error("JSON parse error"); + } + } else if (message->res_status == + OGS_SBI_HTTP_STATUS_CREATED) { + message->SmPolicyDecision = + OpenAPI_sm_policy_decision_parseFromJSON(item); + if (!message->SmPolicyDecision) { + rv = OGS_ERROR; + ogs_error("JSON parse error"); + } } - } else if (message->res_status == OGS_SBI_HTTP_STATUS_CREATED) { - message->SmPolicyDecision = - OpenAPI_sm_policy_decision_parseFromJSON(item); - if (!message->SmPolicyDecision) { + } else { + SWITCH(message->h.resource.component[2]) + CASE(OGS_SBI_RESOURCE_NAME_DELETE) + if (message->res_status == 0) { + message->SmPolicyDeleteData = + OpenAPI_sm_policy_delete_data_parseFromJSON( + item); + if (!message->SmPolicyDeleteData) { + rv = OGS_ERROR; + ogs_error("JSON parse error"); + } + } + break; + DEFAULT rv = OGS_ERROR; - ogs_error("JSON parse error"); - } + ogs_error("Unknown resource name [%s]", + message->h.resource.component[2]); + END + break; } break; @@ -1481,6 +1532,108 @@ static int parse_json(ogs_sbi_message_t *message, END break; + 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]) { + SWITCH(message->h.method) + CASE(OGS_SBI_HTTP_METHOD_PATCH) + if (message->res_status == OGS_SBI_HTTP_STATUS_OK) { + message->PcfBinding = + OpenAPI_pcf_binding_parseFromJSON(item); + if (!message->PcfBinding) { + rv = OGS_ERROR; + ogs_error("JSON parse error"); + } + } + break; + CASE(OGS_SBI_HTTP_METHOD_DELETE) + break; + DEFAULT + rv = OGS_ERROR; + ogs_error("Unknown method [%s]", message->h.method); + END + break; + } else { + SWITCH(message->h.method) + CASE(OGS_SBI_HTTP_METHOD_POST) + if (message->res_status == 0 || + message->res_status == + OGS_SBI_HTTP_STATUS_CREATED) { + message->PcfBinding = + OpenAPI_pcf_binding_parseFromJSON(item); + if (!message->PcfBinding) { + rv = OGS_ERROR; + ogs_error("JSON parse error"); + } + } + break; + + CASE(OGS_SBI_HTTP_METHOD_GET) + if (message->res_status == OGS_SBI_HTTP_STATUS_OK) { + message->PcfBinding = + OpenAPI_pcf_binding_parseFromJSON(item); + if (!message->PcfBinding) { + rv = OGS_ERROR; + ogs_error("JSON parse error"); + } + } + break; + DEFAULT + rv = OGS_ERROR; + ogs_error("Unknown method [%s]", message->h.method); + END + break; + } + + DEFAULT + rv = OGS_ERROR; + ogs_error("Unknown resource name [%s]", + message->h.resource.component[0]); + END + break; + + CASE(OGS_SBI_SERVICE_NAME_NPCF_POLICYAUTHORIZATION) + SWITCH(message->h.resource.component[0]) + CASE(OGS_SBI_RESOURCE_NAME_APP_SESSIONS) + if (message->h.resource.component[1]) { + SWITCH(message->h.method) + CASE(OGS_SBI_HTTP_METHOD_DELETE) + break; + DEFAULT + rv = OGS_ERROR; + ogs_error("Unknown method [%s]", message->h.method); + END + break; + } else { + SWITCH(message->h.method) + CASE(OGS_SBI_HTTP_METHOD_POST) + if (message->res_status == 0 || + message->res_status == + OGS_SBI_HTTP_STATUS_CREATED) { + message->AppSessionContext = + OpenAPI_app_session_context_parseFromJSON(item); + if (!message->AppSessionContext) { + rv = OGS_ERROR; + ogs_error("JSON parse error"); + } + } + break; + + DEFAULT + rv = OGS_ERROR; + ogs_error("Unknown method [%s]", message->h.method); + END + break; + } + + DEFAULT + rv = OGS_ERROR; + ogs_error("Unknown resource name [%s]", + message->h.resource.component[0]); + END + break; + CASE(OGS_SBI_SERVICE_NAME_NAMF_CALLBACK) SWITCH(message->h.resource.component[1]) CASE(OGS_SBI_RESOURCE_NAME_SM_CONTEXT_STATUS) diff --git a/lib/sbi/message.h b/lib/sbi/message.h index 18d508e40..67eea10f2 100644 --- a/lib/sbi/message.h +++ b/lib/sbi/message.h @@ -143,11 +143,21 @@ extern "C" { #define OGS_SBI_RESOURCE_NAME_POLICIES "policies" #define OGS_SBI_SERVICE_NAME_NPCF_SMPOLICYCONTROL "npcf-smpolicycontrol" #define OGS_SBI_RESOURCE_NAME_SM_POLICIES "sm-policies" +#define OGS_SBI_RESOURCE_NAME_DELETE "delete" +#define OGS_SBI_SERVICE_NAME_NPCF_POLICYAUTHORIZATION \ + "npcf-policyauthorization" +#define OGS_SBI_RESOURCE_NAME_APP_SESSIONS "app-sessions" +#define OGS_SBI_RESOURCE_NAME_NOTIFY "notify" #define OGS_SBI_SERVICE_NAME_NNSSF_NSSELECTION "nnssf-nsselection" #define OGS_SBI_RESOURCE_NAME_NETWORK_SLICE_INFORMATION \ "network-slice-information" +#define OGS_SBI_SERVICE_NAME_NBSF_MANAGEMENT "nbsf-management" +#define OGS_SBI_RESOURCE_NAME_PCF_BINDINGS "pcfBindings" + +#define OGS_SBI_SERVICE_NAME_NAF_EVENTEXPOSURE "naf-eventexposure" + #define OGS_SBI_FEATURES_IS_SET(__fEATURES, __n) \ (__fEATURES & (1 << ((__n)-1))) #define OGS_SBI_FEATURES_SET(__fEATURES, __n) \ @@ -199,6 +209,41 @@ extern "C" { #define OGS_SBI_NPCF_SMPOLICYCONTROL_DDN_EVENT_POLICY_CONTROL 37 #define OGS_SBI_NPCF_SMPOLICYCONTROL_REALLOCATION_OF_CREDIT 38 +#define OGS_SBI_NPCF_POLICYAUTHORIZATION_INFLUENCE_ON_TRAFFIC_ROUTING 1 +#define OGS_SBI_NPCF_POLICYAUTHORIZATION_SPONSORED_CONNECTIVITY 2 +#define OGS_SBI_NPCF_POLICYAUTHORIZATION_MEDIA_COMPONENT_VERSIONING 3 +#define OGS_SBI_NPCF_POLICYAUTHORIZATION_URLLC 4 +#define OGS_SBI_NPCF_POLICYAUTHORIZATION_IMS_SBI 5 +#define OGS_SBI_NPCF_POLICYAUTHORIZATION_NETLOC 6 +#define OGS_SBI_NPCF_POLICYAUTHORIZATION_PROV_AF_SIGNAL_FLOW 7 +#define OGS_SBI_NPCF_POLICYAUTHORIZATION_RESOURCE_SHARING 8 +#define OGS_SBI_NPCF_POLICYAUTHORIZATION_MCPTT 9 +#define OGS_SBI_NPCF_POLICYAUTHORIZATION_MCVIDEO 10 +#define OGS_SBI_NPCF_POLICYAUTHORIZATION_PRIORITY_SHARING 11 +#define OGS_SBI_NPCF_POLICYAUTHORIZATION_MCPTT_PREEMPTION 12 +#define OGS_SBI_NPCF_POLICYAUTHORIZATION_MAC_ADDRESS_RANGE 13 +#define OGS_SBI_NPCF_POLICYAUTHORIZATION_RAN_NAS_CAUSE 14 +#define OGS_SBI_NPCF_POLICYAUTHORIZATION_ENHANCED_SUBSCRIPTION_TO_NOTIFICATION 15 +#define OGS_SBI_NPCF_POLICYAUTHORIZATION_QOS_MONITORING 16 +#define OGS_SBI_NPCF_POLICYAUTHORIZATION_AUTHORIZATION_WITH_REQUIRED_QOS 17 +#define OGS_SBI_NPCF_POLICYAUTHORIZATION_TIME_SENSITIVE_NETWORKING 18 +#define OGS_SBI_NPCF_POLICYAUTHORIZATION_PCSCF_RESTORATION_ENHANCEMENT 19 +#define OGS_SBI_NPCF_POLICYAUTHORIZATION_CHEM 20 +#define OGS_SBI_NPCF_POLICYAUTHORIZATION_FLUS 21 +#define OGS_SBI_NPCF_POLICYAUTHORIZATION_EPS_FALLBACK_REPORT 22 +#define OGS_SBI_NPCF_POLICYAUTHORIZATION_ATSSS 23 +#define OGS_SBI_NPCF_POLICYAUTHORIZATION_QOS_HINT 24 +#define OGS_SBI_NPCF_POLICYAUTHORIZATION_REALLOCATION_OF_CREDIT 25 +#define OGS_SBI_NPCF_POLICYAUTHORIZATION_ES3XX 26 +#define OGS_SBI_NPCF_POLICYAUTHORIZATION_DISABLE_UE_NOTIFICATION 27 +#define OGS_SBI_NPCF_POLICYAUTHORIZATION_PATCH_CORRECTION 28 + +#define OGS_SBI_NBSF_MANAGEMENT_MULTI_UE_ADDR 1 +#define OGS_SBI_NBSF_MANAGEMENT_BINDING_UPDATE 2 +#define OGS_SBI_NBSF_MANAGEMENT_SAME_PCF 3 +#define OGS_SBI_NBSF_MANAGEMENT_ES3XX 4 +#define OGS_SBI_NBSF_MANAGEMENT_EXTENDED_SAME_PCF 5 + #define OGS_SBI_PARAM_NF_ID "nf-id" #define OGS_SBI_PARAM_NF_TYPE "nf-type" #define OGS_SBI_PARAM_TARGET_NF_TYPE "target-nf-type" @@ -210,6 +255,8 @@ extern "C" { #define OGS_SBI_PARAM_SNSSAI "snssai" #define OGS_SBI_PARAM_SLICE_INFO_REQUEST_FOR_PDU_SESSION \ "slice-info-request-for-pdu-session" +#define OGS_SBI_PARAM_IPV4ADDR "ipv4Addr" +#define OGS_SBI_PARAM_IPV6PREFIX "ipv6Prefix" #define OGS_SBI_ACCEPT "Accept" #define OGS_SBI_ACCEPT_ENCODING "Accept-Encoding" @@ -300,6 +347,9 @@ typedef struct ogs_sbi_message_s { bool snssai_presence; bool slice_info_request_for_pdu_session_presence; OpenAPI_roaming_indication_e roaming_indication; + + char *ipv4addr; + char *ipv6prefix; } param; int res_status; @@ -341,11 +391,16 @@ typedef struct ogs_sbi_message_s { OpenAPI_sm_context_status_notification_t *SmContextStatusNotification; OpenAPI_policy_association_request_t *PolicyAssociationRequest; OpenAPI_policy_association_t *PolicyAssociation; + OpenAPI_policy_update_t *PolicyUpdate; OpenAPI_am_policy_data_t *AmPolicyData; OpenAPI_sm_policy_context_data_t *SmPolicyContextData; OpenAPI_sm_policy_decision_t *SmPolicyDecision; OpenAPI_sm_policy_data_t *SmPolicyData; + OpenAPI_sm_policy_delete_data_t *SmPolicyDeleteData; + OpenAPI_sm_policy_notification_t *SmPolicyNotification; OpenAPI_authorized_network_slice_info_t *AuthorizedNetworkSliceInfo; + OpenAPI_pcf_binding_t *PcfBinding; + OpenAPI_app_session_context_t *AppSessionContext; ogs_sbi_links_t *links; diff --git a/lib/sbi/nnrf-build.c b/lib/sbi/nnrf-build.c index c6eed2053..72c4b6b7d 100644 --- a/lib/sbi/nnrf-build.c +++ b/lib/sbi/nnrf-build.c @@ -32,7 +32,7 @@ OpenAPI_nf_profile_t *ogs_nnrf_nfm_build_nf_profile( int i = 0; int fqdn_len; - char fqdn[OGS_MAX_FQDN_LEN+1]; + char fqdn[OGS_MAX_FQDN_LEN]; ogs_assert(nf_instance); diff --git a/lib/sbi/nnrf-handler.c b/lib/sbi/nnrf-handler.c index b182e83dd..e353a88e9 100644 --- a/lib/sbi/nnrf-handler.c +++ b/lib/sbi/nnrf-handler.c @@ -148,33 +148,6 @@ static void handle_smf_info( nf_info->smf.num_of_nr_tai_range++; } } - -#if 0 - ogs_sbi_smf_info_t *smf_info = &nf_info->smf; - int i, j; - for (i = 0; i < smf_info->num_of_slice; i++) { - ogs_fatal("%d, %x", smf_info->slice[i].s_nssai.sst, - smf_info->slice[i].s_nssai.sd.v); - for (j = 0; j < smf_info->slice[i].num_of_dnn; j++) - ogs_fatal(" %s", smf_info->slice[i].dnn[j]); - } - for (i = 0; i < smf_info->num_of_nr_tai; i++) { - ogs_fatal("%d, %d, %x", - ogs_plmn_id_mcc(&smf_info->nr_tai[i].plmn_id), - ogs_plmn_id_mnc(&smf_info->nr_tai[i].plmn_id), - smf_info->nr_tai[i].tac.v); - } - for (i = 0; i < smf_info->num_of_nr_tai_range; i++) { - ogs_fatal("%d, %d", - ogs_plmn_id_mcc(&smf_info->nr_tai[i].plmn_id), - ogs_plmn_id_mnc(&smf_info->nr_tai[i].plmn_id)); - for (j = 0; j < smf_info->nr_tai_range[i].num_of_tac_range; j++) { - ogs_fatal(" %d-%d", - smf_info->nr_tai_range[i].start[j].v, - smf_info->nr_tai_range[i].end[j].v); - } - } -#endif } bool ogs_sbi_nnrf_handle_nf_profile(ogs_sbi_nf_instance_t *nf_instance, diff --git a/lib/sbi/ogs-sbi.h b/lib/sbi/ogs-sbi.h index d6c5648fd..373e882ed 100644 --- a/lib/sbi/ogs-sbi.h +++ b/lib/sbi/ogs-sbi.h @@ -65,8 +65,13 @@ #include "model/sm_policy_context_data.h" #include "model/sm_policy_decision.h" #include "model/sm_policy_data.h" +#include "model/sm_policy_delete_data.h" #include "model/slice_info_for_pdu_session.h" #include "model/authorized_network_slice_info.h" +#include "model/pcf_binding.h" +#include "model/app_session_context.h" +#include "model/policy_update.h" +#include "model/sm_policy_notification.h" #include "custom/links.h" diff --git a/lib/sbi/openapi/meson.build b/lib/sbi/openapi/meson.build index 6194aa1e9..6e31cd6a9 100644 --- a/lib/sbi/openapi/meson.build +++ b/lib/sbi/openapi/meson.build @@ -779,6 +779,63 @@ libsbi_openapi_sources = files(''' model/w_agf_info.c model/wireline_area.c model/wireline_service_area_restriction.c + + model/acceptable_service_info.c + model/access_net_charging_identifier.c + model/accumulated_usage.c + model/af_event_notification.c + model/af_event_subscription.c + model/af_notif_method.c + model/af_requested_data.c + model/af_routing_requirement.c + model/af_routing_requirement_rm.c + model/app_session_context.c + model/app_session_context_req_data.c + model/app_session_context_resp_data.c + model/app_session_context_update_data.c + model/binding_level.c + model/binding_resp.c + model/events_notification.c + model/events_subsc_req_data.c + model/events_subsc_req_data_rm.c + model/extended_problem_details.c + model/extended_problem_details_all_of.c + model/flow_usage.c + model/flows.c + model/media_component.c + model/media_component_resources_status.c + model/media_component_rm.c + model/media_sub_component.c + model/media_sub_component_rm.c + model/media_type.c + model/new_tsn_bridge.c + model/out_of_credit_information.c + model/parameter_combination.c + model/pcf_binding.c + model/pcf_binding_patch.c + model/pcscf_restoration_request_data.c + model/preemption_capability_rm.c + model/preemption_control_information.c + model/preemption_control_information_rm.c + model/preemption_vulnerability_rm.c + model/priority_sharing_indicator.c + model/qos_monitoring_information.c + model/qos_monitoring_information_rm.c + model/required_access_info.c + model/reserv_priority.c + model/resources_allocation_info.c + model/serv_auth_info.c + model/service_info_status.c + model/sip_forking_indication.c + model/spatial_validity.c + model/spatial_validity_rm.c + model/sponsoring_status.c + model/termination_cause.c + model/termination_info.c + model/tsn_qos_container.c + model/tsn_qos_container_rm.c + model/ue_identity_info.c + model/usage_threshold_rm.c '''.split()) libsbi_openapi_inc = include_directories('.') diff --git a/lib/sbi/openapi/model/acceptable_service_info.c b/lib/sbi/openapi/model/acceptable_service_info.c new file mode 100644 index 000000000..5f90c450a --- /dev/null +++ b/lib/sbi/openapi/model/acceptable_service_info.c @@ -0,0 +1,178 @@ + +#include +#include +#include +#include "acceptable_service_info.h" + +OpenAPI_acceptable_service_info_t *OpenAPI_acceptable_service_info_create( + OpenAPI_list_t* acc_bw_med_comps, + char *mar_bw_ul, + char *mar_bw_dl + ) +{ + OpenAPI_acceptable_service_info_t *acceptable_service_info_local_var = OpenAPI_malloc(sizeof(OpenAPI_acceptable_service_info_t)); + if (!acceptable_service_info_local_var) { + return NULL; + } + acceptable_service_info_local_var->acc_bw_med_comps = acc_bw_med_comps; + acceptable_service_info_local_var->mar_bw_ul = mar_bw_ul; + acceptable_service_info_local_var->mar_bw_dl = mar_bw_dl; + + return acceptable_service_info_local_var; +} + +void OpenAPI_acceptable_service_info_free(OpenAPI_acceptable_service_info_t *acceptable_service_info) +{ + if (NULL == acceptable_service_info) { + return; + } + OpenAPI_lnode_t *node; + OpenAPI_list_for_each(acceptable_service_info->acc_bw_med_comps, node) { + OpenAPI_map_t *localKeyValue = (OpenAPI_map_t*)node->data; + OpenAPI_media_component_free(localKeyValue->value); + ogs_free(localKeyValue); + } + OpenAPI_list_free(acceptable_service_info->acc_bw_med_comps); + ogs_free(acceptable_service_info->mar_bw_ul); + ogs_free(acceptable_service_info->mar_bw_dl); + ogs_free(acceptable_service_info); +} + +cJSON *OpenAPI_acceptable_service_info_convertToJSON(OpenAPI_acceptable_service_info_t *acceptable_service_info) +{ + cJSON *item = NULL; + + if (acceptable_service_info == NULL) { + ogs_error("OpenAPI_acceptable_service_info_convertToJSON() failed [AcceptableServiceInfo]"); + return NULL; + } + + item = cJSON_CreateObject(); + if (acceptable_service_info->acc_bw_med_comps) { + cJSON *acc_bw_med_comps = cJSON_AddObjectToObject(item, "accBwMedComps"); + if (acc_bw_med_comps == NULL) { + ogs_error("OpenAPI_acceptable_service_info_convertToJSON() failed [acc_bw_med_comps]"); + goto end; + } + cJSON *localMapObject = acc_bw_med_comps; + OpenAPI_lnode_t *acc_bw_med_comps_node; + if (acceptable_service_info->acc_bw_med_comps) { + OpenAPI_list_for_each(acceptable_service_info->acc_bw_med_comps, acc_bw_med_comps_node) { + OpenAPI_map_t *localKeyValue = (OpenAPI_map_t*)acc_bw_med_comps_node->data; + cJSON *itemLocal = OpenAPI_media_component_convertToJSON(localKeyValue->value); + if (itemLocal == NULL) { + ogs_error("OpenAPI_acceptable_service_info_convertToJSON() failed [acc_bw_med_comps]"); + goto end; + } + cJSON_AddItemToObject(acc_bw_med_comps, localKeyValue->key, itemLocal); + } + } + } + + if (acceptable_service_info->mar_bw_ul) { + if (cJSON_AddStringToObject(item, "marBwUl", acceptable_service_info->mar_bw_ul) == NULL) { + ogs_error("OpenAPI_acceptable_service_info_convertToJSON() failed [mar_bw_ul]"); + goto end; + } + } + + if (acceptable_service_info->mar_bw_dl) { + if (cJSON_AddStringToObject(item, "marBwDl", acceptable_service_info->mar_bw_dl) == NULL) { + ogs_error("OpenAPI_acceptable_service_info_convertToJSON() failed [mar_bw_dl]"); + goto end; + } + } + +end: + return item; +} + +OpenAPI_acceptable_service_info_t *OpenAPI_acceptable_service_info_parseFromJSON(cJSON *acceptable_service_infoJSON) +{ + OpenAPI_acceptable_service_info_t *acceptable_service_info_local_var = NULL; + cJSON *acc_bw_med_comps = cJSON_GetObjectItemCaseSensitive(acceptable_service_infoJSON, "accBwMedComps"); + + OpenAPI_list_t *acc_bw_med_compsList; + if (acc_bw_med_comps) { + cJSON *acc_bw_med_comps_local_map; + if (!cJSON_IsObject(acc_bw_med_comps)) { + ogs_error("OpenAPI_acceptable_service_info_parseFromJSON() failed [acc_bw_med_comps]"); + goto end; + } + acc_bw_med_compsList = OpenAPI_list_create(); + OpenAPI_map_t *localMapKeyPair = NULL; + cJSON_ArrayForEach(acc_bw_med_comps_local_map, acc_bw_med_comps) { + cJSON *localMapObject = acc_bw_med_comps_local_map; + if (!cJSON_IsObject(acc_bw_med_comps_local_map)) { + ogs_error("OpenAPI_acceptable_service_info_parseFromJSON() failed [acc_bw_med_comps]"); + goto end; + } + localMapKeyPair = OpenAPI_map_create( + localMapObject->string, OpenAPI_media_component_parseFromJSON(localMapObject)); + OpenAPI_list_add(acc_bw_med_compsList, localMapKeyPair); + } + } + + cJSON *mar_bw_ul = cJSON_GetObjectItemCaseSensitive(acceptable_service_infoJSON, "marBwUl"); + + if (mar_bw_ul) { + if (!cJSON_IsString(mar_bw_ul)) { + ogs_error("OpenAPI_acceptable_service_info_parseFromJSON() failed [mar_bw_ul]"); + goto end; + } + } + + cJSON *mar_bw_dl = cJSON_GetObjectItemCaseSensitive(acceptable_service_infoJSON, "marBwDl"); + + if (mar_bw_dl) { + if (!cJSON_IsString(mar_bw_dl)) { + ogs_error("OpenAPI_acceptable_service_info_parseFromJSON() failed [mar_bw_dl]"); + goto end; + } + } + + acceptable_service_info_local_var = OpenAPI_acceptable_service_info_create ( + acc_bw_med_comps ? acc_bw_med_compsList : NULL, + mar_bw_ul ? ogs_strdup(mar_bw_ul->valuestring) : NULL, + mar_bw_dl ? ogs_strdup(mar_bw_dl->valuestring) : NULL + ); + + return acceptable_service_info_local_var; +end: + return NULL; +} + +OpenAPI_acceptable_service_info_t *OpenAPI_acceptable_service_info_copy(OpenAPI_acceptable_service_info_t *dst, OpenAPI_acceptable_service_info_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_acceptable_service_info_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_acceptable_service_info_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_acceptable_service_info_free(dst); + dst = OpenAPI_acceptable_service_info_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/acceptable_service_info.h b/lib/sbi/openapi/model/acceptable_service_info.h new file mode 100644 index 000000000..87bf6a1a1 --- /dev/null +++ b/lib/sbi/openapi/model/acceptable_service_info.h @@ -0,0 +1,43 @@ +/* + * acceptable_service_info.h + * + * Indicates the maximum bandwidth that shall be authorized by the PCF. + */ + +#ifndef _OpenAPI_acceptable_service_info_H_ +#define _OpenAPI_acceptable_service_info_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" +#include "media_component.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_acceptable_service_info_s OpenAPI_acceptable_service_info_t; +typedef struct OpenAPI_acceptable_service_info_s { + OpenAPI_list_t* acc_bw_med_comps; + char *mar_bw_ul; + char *mar_bw_dl; +} OpenAPI_acceptable_service_info_t; + +OpenAPI_acceptable_service_info_t *OpenAPI_acceptable_service_info_create( + OpenAPI_list_t* acc_bw_med_comps, + char *mar_bw_ul, + char *mar_bw_dl + ); +void OpenAPI_acceptable_service_info_free(OpenAPI_acceptable_service_info_t *acceptable_service_info); +OpenAPI_acceptable_service_info_t *OpenAPI_acceptable_service_info_parseFromJSON(cJSON *acceptable_service_infoJSON); +cJSON *OpenAPI_acceptable_service_info_convertToJSON(OpenAPI_acceptable_service_info_t *acceptable_service_info); +OpenAPI_acceptable_service_info_t *OpenAPI_acceptable_service_info_copy(OpenAPI_acceptable_service_info_t *dst, OpenAPI_acceptable_service_info_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_acceptable_service_info_H_ */ + diff --git a/lib/sbi/openapi/model/access_net_charging_identifier.c b/lib/sbi/openapi/model/access_net_charging_identifier.c new file mode 100644 index 000000000..b448403b2 --- /dev/null +++ b/lib/sbi/openapi/model/access_net_charging_identifier.c @@ -0,0 +1,155 @@ + +#include +#include +#include +#include "access_net_charging_identifier.h" + +OpenAPI_access_net_charging_identifier_t *OpenAPI_access_net_charging_identifier_create( + int acc_net_cha_id_value, + OpenAPI_list_t *flows + ) +{ + OpenAPI_access_net_charging_identifier_t *access_net_charging_identifier_local_var = OpenAPI_malloc(sizeof(OpenAPI_access_net_charging_identifier_t)); + if (!access_net_charging_identifier_local_var) { + return NULL; + } + access_net_charging_identifier_local_var->acc_net_cha_id_value = acc_net_cha_id_value; + access_net_charging_identifier_local_var->flows = flows; + + return access_net_charging_identifier_local_var; +} + +void OpenAPI_access_net_charging_identifier_free(OpenAPI_access_net_charging_identifier_t *access_net_charging_identifier) +{ + if (NULL == access_net_charging_identifier) { + return; + } + OpenAPI_lnode_t *node; + OpenAPI_list_for_each(access_net_charging_identifier->flows, node) { + OpenAPI_flows_free(node->data); + } + OpenAPI_list_free(access_net_charging_identifier->flows); + ogs_free(access_net_charging_identifier); +} + +cJSON *OpenAPI_access_net_charging_identifier_convertToJSON(OpenAPI_access_net_charging_identifier_t *access_net_charging_identifier) +{ + cJSON *item = NULL; + + if (access_net_charging_identifier == NULL) { + ogs_error("OpenAPI_access_net_charging_identifier_convertToJSON() failed [AccessNetChargingIdentifier]"); + return NULL; + } + + item = cJSON_CreateObject(); + if (cJSON_AddNumberToObject(item, "accNetChaIdValue", access_net_charging_identifier->acc_net_cha_id_value) == NULL) { + ogs_error("OpenAPI_access_net_charging_identifier_convertToJSON() failed [acc_net_cha_id_value]"); + goto end; + } + + if (access_net_charging_identifier->flows) { + cJSON *flowsList = cJSON_AddArrayToObject(item, "flows"); + if (flowsList == NULL) { + ogs_error("OpenAPI_access_net_charging_identifier_convertToJSON() failed [flows]"); + goto end; + } + + OpenAPI_lnode_t *flows_node; + if (access_net_charging_identifier->flows) { + OpenAPI_list_for_each(access_net_charging_identifier->flows, flows_node) { + cJSON *itemLocal = OpenAPI_flows_convertToJSON(flows_node->data); + if (itemLocal == NULL) { + ogs_error("OpenAPI_access_net_charging_identifier_convertToJSON() failed [flows]"); + goto end; + } + cJSON_AddItemToArray(flowsList, itemLocal); + } + } + } + +end: + return item; +} + +OpenAPI_access_net_charging_identifier_t *OpenAPI_access_net_charging_identifier_parseFromJSON(cJSON *access_net_charging_identifierJSON) +{ + OpenAPI_access_net_charging_identifier_t *access_net_charging_identifier_local_var = NULL; + cJSON *acc_net_cha_id_value = cJSON_GetObjectItemCaseSensitive(access_net_charging_identifierJSON, "accNetChaIdValue"); + if (!acc_net_cha_id_value) { + ogs_error("OpenAPI_access_net_charging_identifier_parseFromJSON() failed [acc_net_cha_id_value]"); + goto end; + } + + + if (!cJSON_IsNumber(acc_net_cha_id_value)) { + ogs_error("OpenAPI_access_net_charging_identifier_parseFromJSON() failed [acc_net_cha_id_value]"); + goto end; + } + + cJSON *flows = cJSON_GetObjectItemCaseSensitive(access_net_charging_identifierJSON, "flows"); + + OpenAPI_list_t *flowsList; + if (flows) { + cJSON *flows_local_nonprimitive; + if (!cJSON_IsArray(flows)) { + ogs_error("OpenAPI_access_net_charging_identifier_parseFromJSON() failed [flows]"); + goto end; + } + + flowsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(flows_local_nonprimitive, flows ) { + if (!cJSON_IsObject(flows_local_nonprimitive)) { + ogs_error("OpenAPI_access_net_charging_identifier_parseFromJSON() failed [flows]"); + goto end; + } + OpenAPI_flows_t *flowsItem = OpenAPI_flows_parseFromJSON(flows_local_nonprimitive); + + OpenAPI_list_add(flowsList, flowsItem); + } + } + + access_net_charging_identifier_local_var = OpenAPI_access_net_charging_identifier_create ( + acc_net_cha_id_value->valuedouble, + flows ? flowsList : NULL + ); + + return access_net_charging_identifier_local_var; +end: + return NULL; +} + +OpenAPI_access_net_charging_identifier_t *OpenAPI_access_net_charging_identifier_copy(OpenAPI_access_net_charging_identifier_t *dst, OpenAPI_access_net_charging_identifier_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_access_net_charging_identifier_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_access_net_charging_identifier_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_access_net_charging_identifier_free(dst); + dst = OpenAPI_access_net_charging_identifier_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/access_net_charging_identifier.h b/lib/sbi/openapi/model/access_net_charging_identifier.h new file mode 100644 index 000000000..6797f71cd --- /dev/null +++ b/lib/sbi/openapi/model/access_net_charging_identifier.h @@ -0,0 +1,41 @@ +/* + * access_net_charging_identifier.h + * + * Describes the access network charging identifier. + */ + +#ifndef _OpenAPI_access_net_charging_identifier_H_ +#define _OpenAPI_access_net_charging_identifier_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" +#include "flows.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_access_net_charging_identifier_s OpenAPI_access_net_charging_identifier_t; +typedef struct OpenAPI_access_net_charging_identifier_s { + int acc_net_cha_id_value; + OpenAPI_list_t *flows; +} OpenAPI_access_net_charging_identifier_t; + +OpenAPI_access_net_charging_identifier_t *OpenAPI_access_net_charging_identifier_create( + int acc_net_cha_id_value, + OpenAPI_list_t *flows + ); +void OpenAPI_access_net_charging_identifier_free(OpenAPI_access_net_charging_identifier_t *access_net_charging_identifier); +OpenAPI_access_net_charging_identifier_t *OpenAPI_access_net_charging_identifier_parseFromJSON(cJSON *access_net_charging_identifierJSON); +cJSON *OpenAPI_access_net_charging_identifier_convertToJSON(OpenAPI_access_net_charging_identifier_t *access_net_charging_identifier); +OpenAPI_access_net_charging_identifier_t *OpenAPI_access_net_charging_identifier_copy(OpenAPI_access_net_charging_identifier_t *dst, OpenAPI_access_net_charging_identifier_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_access_net_charging_identifier_H_ */ + diff --git a/lib/sbi/openapi/model/accumulated_usage.c b/lib/sbi/openapi/model/accumulated_usage.c new file mode 100644 index 000000000..2682e7c6f --- /dev/null +++ b/lib/sbi/openapi/model/accumulated_usage.c @@ -0,0 +1,161 @@ + +#include +#include +#include +#include "accumulated_usage.h" + +OpenAPI_accumulated_usage_t *OpenAPI_accumulated_usage_create( + int duration, + long total_volume, + long downlink_volume, + long uplink_volume + ) +{ + OpenAPI_accumulated_usage_t *accumulated_usage_local_var = OpenAPI_malloc(sizeof(OpenAPI_accumulated_usage_t)); + if (!accumulated_usage_local_var) { + return NULL; + } + accumulated_usage_local_var->duration = duration; + accumulated_usage_local_var->total_volume = total_volume; + accumulated_usage_local_var->downlink_volume = downlink_volume; + accumulated_usage_local_var->uplink_volume = uplink_volume; + + return accumulated_usage_local_var; +} + +void OpenAPI_accumulated_usage_free(OpenAPI_accumulated_usage_t *accumulated_usage) +{ + if (NULL == accumulated_usage) { + return; + } + OpenAPI_lnode_t *node; + ogs_free(accumulated_usage); +} + +cJSON *OpenAPI_accumulated_usage_convertToJSON(OpenAPI_accumulated_usage_t *accumulated_usage) +{ + cJSON *item = NULL; + + if (accumulated_usage == NULL) { + ogs_error("OpenAPI_accumulated_usage_convertToJSON() failed [AccumulatedUsage]"); + return NULL; + } + + item = cJSON_CreateObject(); + if (accumulated_usage->duration) { + if (cJSON_AddNumberToObject(item, "duration", accumulated_usage->duration) == NULL) { + ogs_error("OpenAPI_accumulated_usage_convertToJSON() failed [duration]"); + goto end; + } + } + + if (accumulated_usage->total_volume) { + if (cJSON_AddNumberToObject(item, "totalVolume", accumulated_usage->total_volume) == NULL) { + ogs_error("OpenAPI_accumulated_usage_convertToJSON() failed [total_volume]"); + goto end; + } + } + + if (accumulated_usage->downlink_volume) { + if (cJSON_AddNumberToObject(item, "downlinkVolume", accumulated_usage->downlink_volume) == NULL) { + ogs_error("OpenAPI_accumulated_usage_convertToJSON() failed [downlink_volume]"); + goto end; + } + } + + if (accumulated_usage->uplink_volume) { + if (cJSON_AddNumberToObject(item, "uplinkVolume", accumulated_usage->uplink_volume) == NULL) { + ogs_error("OpenAPI_accumulated_usage_convertToJSON() failed [uplink_volume]"); + goto end; + } + } + +end: + return item; +} + +OpenAPI_accumulated_usage_t *OpenAPI_accumulated_usage_parseFromJSON(cJSON *accumulated_usageJSON) +{ + OpenAPI_accumulated_usage_t *accumulated_usage_local_var = NULL; + cJSON *duration = cJSON_GetObjectItemCaseSensitive(accumulated_usageJSON, "duration"); + + if (duration) { + if (!cJSON_IsNumber(duration)) { + ogs_error("OpenAPI_accumulated_usage_parseFromJSON() failed [duration]"); + goto end; + } + } + + cJSON *total_volume = cJSON_GetObjectItemCaseSensitive(accumulated_usageJSON, "totalVolume"); + + if (total_volume) { + if (!cJSON_IsNumber(total_volume)) { + ogs_error("OpenAPI_accumulated_usage_parseFromJSON() failed [total_volume]"); + goto end; + } + } + + cJSON *downlink_volume = cJSON_GetObjectItemCaseSensitive(accumulated_usageJSON, "downlinkVolume"); + + if (downlink_volume) { + if (!cJSON_IsNumber(downlink_volume)) { + ogs_error("OpenAPI_accumulated_usage_parseFromJSON() failed [downlink_volume]"); + goto end; + } + } + + cJSON *uplink_volume = cJSON_GetObjectItemCaseSensitive(accumulated_usageJSON, "uplinkVolume"); + + if (uplink_volume) { + if (!cJSON_IsNumber(uplink_volume)) { + ogs_error("OpenAPI_accumulated_usage_parseFromJSON() failed [uplink_volume]"); + goto end; + } + } + + accumulated_usage_local_var = OpenAPI_accumulated_usage_create ( + duration ? duration->valuedouble : 0, + total_volume ? total_volume->valuedouble : 0, + downlink_volume ? downlink_volume->valuedouble : 0, + uplink_volume ? uplink_volume->valuedouble : 0 + ); + + return accumulated_usage_local_var; +end: + return NULL; +} + +OpenAPI_accumulated_usage_t *OpenAPI_accumulated_usage_copy(OpenAPI_accumulated_usage_t *dst, OpenAPI_accumulated_usage_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_accumulated_usage_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_accumulated_usage_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_accumulated_usage_free(dst); + dst = OpenAPI_accumulated_usage_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/accumulated_usage.h b/lib/sbi/openapi/model/accumulated_usage.h new file mode 100644 index 000000000..cf009f0a4 --- /dev/null +++ b/lib/sbi/openapi/model/accumulated_usage.h @@ -0,0 +1,44 @@ +/* + * accumulated_usage.h + * + * + */ + +#ifndef _OpenAPI_accumulated_usage_H_ +#define _OpenAPI_accumulated_usage_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_accumulated_usage_s OpenAPI_accumulated_usage_t; +typedef struct OpenAPI_accumulated_usage_s { + int duration; + long total_volume; + long downlink_volume; + long uplink_volume; +} OpenAPI_accumulated_usage_t; + +OpenAPI_accumulated_usage_t *OpenAPI_accumulated_usage_create( + int duration, + long total_volume, + long downlink_volume, + long uplink_volume + ); +void OpenAPI_accumulated_usage_free(OpenAPI_accumulated_usage_t *accumulated_usage); +OpenAPI_accumulated_usage_t *OpenAPI_accumulated_usage_parseFromJSON(cJSON *accumulated_usageJSON); +cJSON *OpenAPI_accumulated_usage_convertToJSON(OpenAPI_accumulated_usage_t *accumulated_usage); +OpenAPI_accumulated_usage_t *OpenAPI_accumulated_usage_copy(OpenAPI_accumulated_usage_t *dst, OpenAPI_accumulated_usage_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_accumulated_usage_H_ */ + diff --git a/lib/sbi/openapi/model/af_event_notification.c b/lib/sbi/openapi/model/af_event_notification.c new file mode 100644 index 000000000..73c1c9ac8 --- /dev/null +++ b/lib/sbi/openapi/model/af_event_notification.c @@ -0,0 +1,160 @@ + +#include +#include +#include +#include "af_event_notification.h" + +OpenAPI_af_event_notification_t *OpenAPI_af_event_notification_create( + OpenAPI_af_event_t *event, + OpenAPI_list_t *flows + ) +{ + OpenAPI_af_event_notification_t *af_event_notification_local_var = OpenAPI_malloc(sizeof(OpenAPI_af_event_notification_t)); + if (!af_event_notification_local_var) { + return NULL; + } + af_event_notification_local_var->event = event; + af_event_notification_local_var->flows = flows; + + return af_event_notification_local_var; +} + +void OpenAPI_af_event_notification_free(OpenAPI_af_event_notification_t *af_event_notification) +{ + if (NULL == af_event_notification) { + return; + } + OpenAPI_lnode_t *node; + OpenAPI_af_event_free(af_event_notification->event); + OpenAPI_list_for_each(af_event_notification->flows, node) { + OpenAPI_flows_free(node->data); + } + OpenAPI_list_free(af_event_notification->flows); + ogs_free(af_event_notification); +} + +cJSON *OpenAPI_af_event_notification_convertToJSON(OpenAPI_af_event_notification_t *af_event_notification) +{ + cJSON *item = NULL; + + if (af_event_notification == NULL) { + ogs_error("OpenAPI_af_event_notification_convertToJSON() failed [AfEventNotification]"); + return NULL; + } + + item = cJSON_CreateObject(); + cJSON *event_local_JSON = OpenAPI_af_event_convertToJSON(af_event_notification->event); + if (event_local_JSON == NULL) { + ogs_error("OpenAPI_af_event_notification_convertToJSON() failed [event]"); + goto end; + } + cJSON_AddItemToObject(item, "event", event_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_af_event_notification_convertToJSON() failed [event]"); + goto end; + } + + if (af_event_notification->flows) { + cJSON *flowsList = cJSON_AddArrayToObject(item, "flows"); + if (flowsList == NULL) { + ogs_error("OpenAPI_af_event_notification_convertToJSON() failed [flows]"); + goto end; + } + + OpenAPI_lnode_t *flows_node; + if (af_event_notification->flows) { + OpenAPI_list_for_each(af_event_notification->flows, flows_node) { + cJSON *itemLocal = OpenAPI_flows_convertToJSON(flows_node->data); + if (itemLocal == NULL) { + ogs_error("OpenAPI_af_event_notification_convertToJSON() failed [flows]"); + goto end; + } + cJSON_AddItemToArray(flowsList, itemLocal); + } + } + } + +end: + return item; +} + +OpenAPI_af_event_notification_t *OpenAPI_af_event_notification_parseFromJSON(cJSON *af_event_notificationJSON) +{ + OpenAPI_af_event_notification_t *af_event_notification_local_var = NULL; + cJSON *event = cJSON_GetObjectItemCaseSensitive(af_event_notificationJSON, "event"); + if (!event) { + ogs_error("OpenAPI_af_event_notification_parseFromJSON() failed [event]"); + goto end; + } + + OpenAPI_af_event_t *event_local_nonprim = NULL; + + event_local_nonprim = OpenAPI_af_event_parseFromJSON(event); + + cJSON *flows = cJSON_GetObjectItemCaseSensitive(af_event_notificationJSON, "flows"); + + OpenAPI_list_t *flowsList; + if (flows) { + cJSON *flows_local_nonprimitive; + if (!cJSON_IsArray(flows)) { + ogs_error("OpenAPI_af_event_notification_parseFromJSON() failed [flows]"); + goto end; + } + + flowsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(flows_local_nonprimitive, flows ) { + if (!cJSON_IsObject(flows_local_nonprimitive)) { + ogs_error("OpenAPI_af_event_notification_parseFromJSON() failed [flows]"); + goto end; + } + OpenAPI_flows_t *flowsItem = OpenAPI_flows_parseFromJSON(flows_local_nonprimitive); + + OpenAPI_list_add(flowsList, flowsItem); + } + } + + af_event_notification_local_var = OpenAPI_af_event_notification_create ( + event_local_nonprim, + flows ? flowsList : NULL + ); + + return af_event_notification_local_var; +end: + return NULL; +} + +OpenAPI_af_event_notification_t *OpenAPI_af_event_notification_copy(OpenAPI_af_event_notification_t *dst, OpenAPI_af_event_notification_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_af_event_notification_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_af_event_notification_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_af_event_notification_free(dst); + dst = OpenAPI_af_event_notification_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/af_event_notification.h b/lib/sbi/openapi/model/af_event_notification.h new file mode 100644 index 000000000..766a7b2a1 --- /dev/null +++ b/lib/sbi/openapi/model/af_event_notification.h @@ -0,0 +1,42 @@ +/* + * af_event_notification.h + * + * describes the event information delivered in the notification + */ + +#ifndef _OpenAPI_af_event_notification_H_ +#define _OpenAPI_af_event_notification_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" +#include "af_event.h" +#include "flows.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_af_event_notification_s OpenAPI_af_event_notification_t; +typedef struct OpenAPI_af_event_notification_s { + struct OpenAPI_af_event_s *event; + OpenAPI_list_t *flows; +} OpenAPI_af_event_notification_t; + +OpenAPI_af_event_notification_t *OpenAPI_af_event_notification_create( + OpenAPI_af_event_t *event, + OpenAPI_list_t *flows + ); +void OpenAPI_af_event_notification_free(OpenAPI_af_event_notification_t *af_event_notification); +OpenAPI_af_event_notification_t *OpenAPI_af_event_notification_parseFromJSON(cJSON *af_event_notificationJSON); +cJSON *OpenAPI_af_event_notification_convertToJSON(OpenAPI_af_event_notification_t *af_event_notification); +OpenAPI_af_event_notification_t *OpenAPI_af_event_notification_copy(OpenAPI_af_event_notification_t *dst, OpenAPI_af_event_notification_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_af_event_notification_H_ */ + diff --git a/lib/sbi/openapi/model/af_event_subscription.c b/lib/sbi/openapi/model/af_event_subscription.c new file mode 100644 index 000000000..ed0a5fad5 --- /dev/null +++ b/lib/sbi/openapi/model/af_event_subscription.c @@ -0,0 +1,169 @@ + +#include +#include +#include +#include "af_event_subscription.h" + +OpenAPI_af_event_subscription_t *OpenAPI_af_event_subscription_create( + OpenAPI_af_event_t *event, + OpenAPI_af_notif_method_e notif_method, + int rep_period, + int wait_time + ) +{ + OpenAPI_af_event_subscription_t *af_event_subscription_local_var = OpenAPI_malloc(sizeof(OpenAPI_af_event_subscription_t)); + if (!af_event_subscription_local_var) { + return NULL; + } + af_event_subscription_local_var->event = event; + af_event_subscription_local_var->notif_method = notif_method; + af_event_subscription_local_var->rep_period = rep_period; + af_event_subscription_local_var->wait_time = wait_time; + + return af_event_subscription_local_var; +} + +void OpenAPI_af_event_subscription_free(OpenAPI_af_event_subscription_t *af_event_subscription) +{ + if (NULL == af_event_subscription) { + return; + } + OpenAPI_lnode_t *node; + OpenAPI_af_event_free(af_event_subscription->event); + ogs_free(af_event_subscription); +} + +cJSON *OpenAPI_af_event_subscription_convertToJSON(OpenAPI_af_event_subscription_t *af_event_subscription) +{ + cJSON *item = NULL; + + if (af_event_subscription == NULL) { + ogs_error("OpenAPI_af_event_subscription_convertToJSON() failed [AfEventSubscription]"); + return NULL; + } + + item = cJSON_CreateObject(); + cJSON *event_local_JSON = OpenAPI_af_event_convertToJSON(af_event_subscription->event); + if (event_local_JSON == NULL) { + ogs_error("OpenAPI_af_event_subscription_convertToJSON() failed [event]"); + goto end; + } + cJSON_AddItemToObject(item, "event", event_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_af_event_subscription_convertToJSON() failed [event]"); + goto end; + } + + if (af_event_subscription->notif_method) { + if (cJSON_AddStringToObject(item, "notifMethod", OpenAPI_af_notif_method_ToString(af_event_subscription->notif_method)) == NULL) { + ogs_error("OpenAPI_af_event_subscription_convertToJSON() failed [notif_method]"); + goto end; + } + } + + if (af_event_subscription->rep_period) { + if (cJSON_AddNumberToObject(item, "repPeriod", af_event_subscription->rep_period) == NULL) { + ogs_error("OpenAPI_af_event_subscription_convertToJSON() failed [rep_period]"); + goto end; + } + } + + if (af_event_subscription->wait_time) { + if (cJSON_AddNumberToObject(item, "waitTime", af_event_subscription->wait_time) == NULL) { + ogs_error("OpenAPI_af_event_subscription_convertToJSON() failed [wait_time]"); + goto end; + } + } + +end: + return item; +} + +OpenAPI_af_event_subscription_t *OpenAPI_af_event_subscription_parseFromJSON(cJSON *af_event_subscriptionJSON) +{ + OpenAPI_af_event_subscription_t *af_event_subscription_local_var = NULL; + cJSON *event = cJSON_GetObjectItemCaseSensitive(af_event_subscriptionJSON, "event"); + if (!event) { + ogs_error("OpenAPI_af_event_subscription_parseFromJSON() failed [event]"); + goto end; + } + + OpenAPI_af_event_t *event_local_nonprim = NULL; + + event_local_nonprim = OpenAPI_af_event_parseFromJSON(event); + + cJSON *notif_method = cJSON_GetObjectItemCaseSensitive(af_event_subscriptionJSON, "notifMethod"); + + OpenAPI_af_notif_method_e notif_methodVariable; + if (notif_method) { + if (!cJSON_IsString(notif_method)) { + ogs_error("OpenAPI_af_event_subscription_parseFromJSON() failed [notif_method]"); + goto end; + } + notif_methodVariable = OpenAPI_af_notif_method_FromString(notif_method->valuestring); + } + + cJSON *rep_period = cJSON_GetObjectItemCaseSensitive(af_event_subscriptionJSON, "repPeriod"); + + if (rep_period) { + if (!cJSON_IsNumber(rep_period)) { + ogs_error("OpenAPI_af_event_subscription_parseFromJSON() failed [rep_period]"); + goto end; + } + } + + cJSON *wait_time = cJSON_GetObjectItemCaseSensitive(af_event_subscriptionJSON, "waitTime"); + + if (wait_time) { + if (!cJSON_IsNumber(wait_time)) { + ogs_error("OpenAPI_af_event_subscription_parseFromJSON() failed [wait_time]"); + goto end; + } + } + + af_event_subscription_local_var = OpenAPI_af_event_subscription_create ( + event_local_nonprim, + notif_method ? notif_methodVariable : 0, + rep_period ? rep_period->valuedouble : 0, + wait_time ? wait_time->valuedouble : 0 + ); + + return af_event_subscription_local_var; +end: + return NULL; +} + +OpenAPI_af_event_subscription_t *OpenAPI_af_event_subscription_copy(OpenAPI_af_event_subscription_t *dst, OpenAPI_af_event_subscription_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_af_event_subscription_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_af_event_subscription_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_af_event_subscription_free(dst); + dst = OpenAPI_af_event_subscription_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/af_event_subscription.h b/lib/sbi/openapi/model/af_event_subscription.h new file mode 100644 index 000000000..2ab857486 --- /dev/null +++ b/lib/sbi/openapi/model/af_event_subscription.h @@ -0,0 +1,46 @@ +/* + * af_event_subscription.h + * + * describes the event information delivered in the subscription + */ + +#ifndef _OpenAPI_af_event_subscription_H_ +#define _OpenAPI_af_event_subscription_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" +#include "af_event.h" +#include "af_notif_method.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_af_event_subscription_s OpenAPI_af_event_subscription_t; +typedef struct OpenAPI_af_event_subscription_s { + struct OpenAPI_af_event_s *event; + OpenAPI_af_notif_method_e notif_method; + int rep_period; + int wait_time; +} OpenAPI_af_event_subscription_t; + +OpenAPI_af_event_subscription_t *OpenAPI_af_event_subscription_create( + OpenAPI_af_event_t *event, + OpenAPI_af_notif_method_e notif_method, + int rep_period, + int wait_time + ); +void OpenAPI_af_event_subscription_free(OpenAPI_af_event_subscription_t *af_event_subscription); +OpenAPI_af_event_subscription_t *OpenAPI_af_event_subscription_parseFromJSON(cJSON *af_event_subscriptionJSON); +cJSON *OpenAPI_af_event_subscription_convertToJSON(OpenAPI_af_event_subscription_t *af_event_subscription); +OpenAPI_af_event_subscription_t *OpenAPI_af_event_subscription_copy(OpenAPI_af_event_subscription_t *dst, OpenAPI_af_event_subscription_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_af_event_subscription_H_ */ + diff --git a/lib/sbi/openapi/model/af_notif_method.c b/lib/sbi/openapi/model/af_notif_method.c new file mode 100644 index 000000000..328f1140e --- /dev/null +++ b/lib/sbi/openapi/model/af_notif_method.c @@ -0,0 +1,30 @@ + +#include +#include +#include +#include "af_notif_method.h" + +char* OpenAPI_af_notif_method_ToString(OpenAPI_af_notif_method_e af_notif_method) +{ + const char *af_notif_methodArray[] = { "NULL", "EVENT_DETECTION", "ONE_TIME", "PERIODIC", "PDU_SESSION_RELEASE" }; + size_t sizeofArray = sizeof(af_notif_methodArray) / sizeof(af_notif_methodArray[0]); + if (af_notif_method < sizeofArray) + return (char *)af_notif_methodArray[af_notif_method]; + else + return (char *)"Unknown"; +} + +OpenAPI_af_notif_method_e OpenAPI_af_notif_method_FromString(char* af_notif_method) +{ + int stringToReturn = 0; + const char *af_notif_methodArray[] = { "NULL", "EVENT_DETECTION", "ONE_TIME", "PERIODIC", "PDU_SESSION_RELEASE" }; + size_t sizeofArray = sizeof(af_notif_methodArray) / sizeof(af_notif_methodArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(af_notif_method, af_notif_methodArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; + } + return 0; +} + diff --git a/lib/sbi/openapi/model/af_notif_method.h b/lib/sbi/openapi/model/af_notif_method.h new file mode 100644 index 000000000..27f288bcb --- /dev/null +++ b/lib/sbi/openapi/model/af_notif_method.h @@ -0,0 +1,31 @@ +/* + * af_notif_method.h + * + * + */ + +#ifndef _OpenAPI_af_notif_method_H_ +#define _OpenAPI_af_notif_method_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { OpenAPI_af_notif_method_NULL = 0, OpenAPI_af_notif_method_EVENT_DETECTION, OpenAPI_af_notif_method_ONE_TIME, OpenAPI_af_notif_method_PERIODIC, OpenAPI_af_notif_method_PDU_SESSION_RELEASE } OpenAPI_af_notif_method_e; + +char* OpenAPI_af_notif_method_ToString(OpenAPI_af_notif_method_e af_notif_method); + +OpenAPI_af_notif_method_e OpenAPI_af_notif_method_FromString(char* af_notif_method); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_af_notif_method_H_ */ + diff --git a/lib/sbi/openapi/model/af_requested_data.c b/lib/sbi/openapi/model/af_requested_data.c new file mode 100644 index 000000000..33fe3e026 --- /dev/null +++ b/lib/sbi/openapi/model/af_requested_data.c @@ -0,0 +1,30 @@ + +#include +#include +#include +#include "af_requested_data.h" + +char* OpenAPI_af_requested_data_ToString(OpenAPI_af_requested_data_e af_requested_data) +{ + const char *af_requested_dataArray[] = { "NULL", "UE_IDENTITY" }; + size_t sizeofArray = sizeof(af_requested_dataArray) / sizeof(af_requested_dataArray[0]); + if (af_requested_data < sizeofArray) + return (char *)af_requested_dataArray[af_requested_data]; + else + return (char *)"Unknown"; +} + +OpenAPI_af_requested_data_e OpenAPI_af_requested_data_FromString(char* af_requested_data) +{ + int stringToReturn = 0; + const char *af_requested_dataArray[] = { "NULL", "UE_IDENTITY" }; + size_t sizeofArray = sizeof(af_requested_dataArray) / sizeof(af_requested_dataArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(af_requested_data, af_requested_dataArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; + } + return 0; +} + diff --git a/lib/sbi/openapi/model/af_requested_data.h b/lib/sbi/openapi/model/af_requested_data.h new file mode 100644 index 000000000..bd4f87bc9 --- /dev/null +++ b/lib/sbi/openapi/model/af_requested_data.h @@ -0,0 +1,31 @@ +/* + * af_requested_data.h + * + * + */ + +#ifndef _OpenAPI_af_requested_data_H_ +#define _OpenAPI_af_requested_data_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { OpenAPI_af_requested_data_NULL = 0, OpenAPI_af_requested_data_UE_IDENTITY } OpenAPI_af_requested_data_e; + +char* OpenAPI_af_requested_data_ToString(OpenAPI_af_requested_data_e af_requested_data); + +OpenAPI_af_requested_data_e OpenAPI_af_requested_data_FromString(char* af_requested_data); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_af_requested_data_H_ */ + diff --git a/lib/sbi/openapi/model/af_routing_requirement.c b/lib/sbi/openapi/model/af_routing_requirement.c new file mode 100644 index 000000000..cf7a180c2 --- /dev/null +++ b/lib/sbi/openapi/model/af_routing_requirement.c @@ -0,0 +1,271 @@ + +#include +#include +#include +#include "af_routing_requirement.h" + +OpenAPI_af_routing_requirement_t *OpenAPI_af_routing_requirement_create( + int app_reloc, + OpenAPI_list_t *route_to_locs, + OpenAPI_spatial_validity_t *sp_val, + OpenAPI_list_t *temp_vals, + OpenAPI_up_path_chg_event_t *up_path_chg_sub, + int addr_preser_ind + ) +{ + OpenAPI_af_routing_requirement_t *af_routing_requirement_local_var = OpenAPI_malloc(sizeof(OpenAPI_af_routing_requirement_t)); + if (!af_routing_requirement_local_var) { + return NULL; + } + af_routing_requirement_local_var->app_reloc = app_reloc; + af_routing_requirement_local_var->route_to_locs = route_to_locs; + af_routing_requirement_local_var->sp_val = sp_val; + af_routing_requirement_local_var->temp_vals = temp_vals; + af_routing_requirement_local_var->up_path_chg_sub = up_path_chg_sub; + af_routing_requirement_local_var->addr_preser_ind = addr_preser_ind; + + return af_routing_requirement_local_var; +} + +void OpenAPI_af_routing_requirement_free(OpenAPI_af_routing_requirement_t *af_routing_requirement) +{ + if (NULL == af_routing_requirement) { + return; + } + OpenAPI_lnode_t *node; + OpenAPI_list_for_each(af_routing_requirement->route_to_locs, node) { + OpenAPI_route_to_location_free(node->data); + } + OpenAPI_list_free(af_routing_requirement->route_to_locs); + OpenAPI_spatial_validity_free(af_routing_requirement->sp_val); + OpenAPI_list_for_each(af_routing_requirement->temp_vals, node) { + OpenAPI_temporal_validity_free(node->data); + } + OpenAPI_list_free(af_routing_requirement->temp_vals); + OpenAPI_up_path_chg_event_free(af_routing_requirement->up_path_chg_sub); + ogs_free(af_routing_requirement); +} + +cJSON *OpenAPI_af_routing_requirement_convertToJSON(OpenAPI_af_routing_requirement_t *af_routing_requirement) +{ + cJSON *item = NULL; + + if (af_routing_requirement == NULL) { + ogs_error("OpenAPI_af_routing_requirement_convertToJSON() failed [AfRoutingRequirement]"); + return NULL; + } + + item = cJSON_CreateObject(); + if (af_routing_requirement->app_reloc) { + if (cJSON_AddBoolToObject(item, "appReloc", af_routing_requirement->app_reloc) == NULL) { + ogs_error("OpenAPI_af_routing_requirement_convertToJSON() failed [app_reloc]"); + goto end; + } + } + + if (af_routing_requirement->route_to_locs) { + cJSON *route_to_locsList = cJSON_AddArrayToObject(item, "routeToLocs"); + if (route_to_locsList == NULL) { + ogs_error("OpenAPI_af_routing_requirement_convertToJSON() failed [route_to_locs]"); + goto end; + } + + OpenAPI_lnode_t *route_to_locs_node; + if (af_routing_requirement->route_to_locs) { + OpenAPI_list_for_each(af_routing_requirement->route_to_locs, route_to_locs_node) { + cJSON *itemLocal = OpenAPI_route_to_location_convertToJSON(route_to_locs_node->data); + if (itemLocal == NULL) { + ogs_error("OpenAPI_af_routing_requirement_convertToJSON() failed [route_to_locs]"); + goto end; + } + cJSON_AddItemToArray(route_to_locsList, itemLocal); + } + } + } + + if (af_routing_requirement->sp_val) { + cJSON *sp_val_local_JSON = OpenAPI_spatial_validity_convertToJSON(af_routing_requirement->sp_val); + if (sp_val_local_JSON == NULL) { + ogs_error("OpenAPI_af_routing_requirement_convertToJSON() failed [sp_val]"); + goto end; + } + cJSON_AddItemToObject(item, "spVal", sp_val_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_af_routing_requirement_convertToJSON() failed [sp_val]"); + goto end; + } + } + + if (af_routing_requirement->temp_vals) { + cJSON *temp_valsList = cJSON_AddArrayToObject(item, "tempVals"); + if (temp_valsList == NULL) { + ogs_error("OpenAPI_af_routing_requirement_convertToJSON() failed [temp_vals]"); + goto end; + } + + OpenAPI_lnode_t *temp_vals_node; + if (af_routing_requirement->temp_vals) { + OpenAPI_list_for_each(af_routing_requirement->temp_vals, temp_vals_node) { + cJSON *itemLocal = OpenAPI_temporal_validity_convertToJSON(temp_vals_node->data); + if (itemLocal == NULL) { + ogs_error("OpenAPI_af_routing_requirement_convertToJSON() failed [temp_vals]"); + goto end; + } + cJSON_AddItemToArray(temp_valsList, itemLocal); + } + } + } + + if (af_routing_requirement->up_path_chg_sub) { + cJSON *up_path_chg_sub_local_JSON = OpenAPI_up_path_chg_event_convertToJSON(af_routing_requirement->up_path_chg_sub); + if (up_path_chg_sub_local_JSON == NULL) { + ogs_error("OpenAPI_af_routing_requirement_convertToJSON() failed [up_path_chg_sub]"); + goto end; + } + cJSON_AddItemToObject(item, "upPathChgSub", up_path_chg_sub_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_af_routing_requirement_convertToJSON() failed [up_path_chg_sub]"); + goto end; + } + } + + if (af_routing_requirement->addr_preser_ind) { + if (cJSON_AddBoolToObject(item, "addrPreserInd", af_routing_requirement->addr_preser_ind) == NULL) { + ogs_error("OpenAPI_af_routing_requirement_convertToJSON() failed [addr_preser_ind]"); + goto end; + } + } + +end: + return item; +} + +OpenAPI_af_routing_requirement_t *OpenAPI_af_routing_requirement_parseFromJSON(cJSON *af_routing_requirementJSON) +{ + OpenAPI_af_routing_requirement_t *af_routing_requirement_local_var = NULL; + cJSON *app_reloc = cJSON_GetObjectItemCaseSensitive(af_routing_requirementJSON, "appReloc"); + + if (app_reloc) { + if (!cJSON_IsBool(app_reloc)) { + ogs_error("OpenAPI_af_routing_requirement_parseFromJSON() failed [app_reloc]"); + goto end; + } + } + + cJSON *route_to_locs = cJSON_GetObjectItemCaseSensitive(af_routing_requirementJSON, "routeToLocs"); + + OpenAPI_list_t *route_to_locsList; + if (route_to_locs) { + cJSON *route_to_locs_local_nonprimitive; + if (!cJSON_IsArray(route_to_locs)) { + ogs_error("OpenAPI_af_routing_requirement_parseFromJSON() failed [route_to_locs]"); + goto end; + } + + route_to_locsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(route_to_locs_local_nonprimitive, route_to_locs ) { + if (!cJSON_IsObject(route_to_locs_local_nonprimitive)) { + ogs_error("OpenAPI_af_routing_requirement_parseFromJSON() failed [route_to_locs]"); + goto end; + } + OpenAPI_route_to_location_t *route_to_locsItem = OpenAPI_route_to_location_parseFromJSON(route_to_locs_local_nonprimitive); + + OpenAPI_list_add(route_to_locsList, route_to_locsItem); + } + } + + cJSON *sp_val = cJSON_GetObjectItemCaseSensitive(af_routing_requirementJSON, "spVal"); + + OpenAPI_spatial_validity_t *sp_val_local_nonprim = NULL; + if (sp_val) { + sp_val_local_nonprim = OpenAPI_spatial_validity_parseFromJSON(sp_val); + } + + cJSON *temp_vals = cJSON_GetObjectItemCaseSensitive(af_routing_requirementJSON, "tempVals"); + + OpenAPI_list_t *temp_valsList; + if (temp_vals) { + cJSON *temp_vals_local_nonprimitive; + if (!cJSON_IsArray(temp_vals)) { + ogs_error("OpenAPI_af_routing_requirement_parseFromJSON() failed [temp_vals]"); + goto end; + } + + temp_valsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(temp_vals_local_nonprimitive, temp_vals ) { + if (!cJSON_IsObject(temp_vals_local_nonprimitive)) { + ogs_error("OpenAPI_af_routing_requirement_parseFromJSON() failed [temp_vals]"); + goto end; + } + OpenAPI_temporal_validity_t *temp_valsItem = OpenAPI_temporal_validity_parseFromJSON(temp_vals_local_nonprimitive); + + OpenAPI_list_add(temp_valsList, temp_valsItem); + } + } + + cJSON *up_path_chg_sub = cJSON_GetObjectItemCaseSensitive(af_routing_requirementJSON, "upPathChgSub"); + + OpenAPI_up_path_chg_event_t *up_path_chg_sub_local_nonprim = NULL; + if (up_path_chg_sub) { + up_path_chg_sub_local_nonprim = OpenAPI_up_path_chg_event_parseFromJSON(up_path_chg_sub); + } + + cJSON *addr_preser_ind = cJSON_GetObjectItemCaseSensitive(af_routing_requirementJSON, "addrPreserInd"); + + if (addr_preser_ind) { + if (!cJSON_IsBool(addr_preser_ind)) { + ogs_error("OpenAPI_af_routing_requirement_parseFromJSON() failed [addr_preser_ind]"); + goto end; + } + } + + af_routing_requirement_local_var = OpenAPI_af_routing_requirement_create ( + app_reloc ? app_reloc->valueint : 0, + route_to_locs ? route_to_locsList : NULL, + sp_val ? sp_val_local_nonprim : NULL, + temp_vals ? temp_valsList : NULL, + up_path_chg_sub ? up_path_chg_sub_local_nonprim : NULL, + addr_preser_ind ? addr_preser_ind->valueint : 0 + ); + + return af_routing_requirement_local_var; +end: + return NULL; +} + +OpenAPI_af_routing_requirement_t *OpenAPI_af_routing_requirement_copy(OpenAPI_af_routing_requirement_t *dst, OpenAPI_af_routing_requirement_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_af_routing_requirement_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_af_routing_requirement_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_af_routing_requirement_free(dst); + dst = OpenAPI_af_routing_requirement_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/af_routing_requirement.h b/lib/sbi/openapi/model/af_routing_requirement.h new file mode 100644 index 000000000..8e973f0df --- /dev/null +++ b/lib/sbi/openapi/model/af_routing_requirement.h @@ -0,0 +1,52 @@ +/* + * af_routing_requirement.h + * + * describes the event information delivered in the subscription + */ + +#ifndef _OpenAPI_af_routing_requirement_H_ +#define _OpenAPI_af_routing_requirement_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" +#include "route_to_location.h" +#include "spatial_validity.h" +#include "temporal_validity.h" +#include "up_path_chg_event.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_af_routing_requirement_s OpenAPI_af_routing_requirement_t; +typedef struct OpenAPI_af_routing_requirement_s { + int app_reloc; + OpenAPI_list_t *route_to_locs; + struct OpenAPI_spatial_validity_s *sp_val; + OpenAPI_list_t *temp_vals; + struct OpenAPI_up_path_chg_event_s *up_path_chg_sub; + int addr_preser_ind; +} OpenAPI_af_routing_requirement_t; + +OpenAPI_af_routing_requirement_t *OpenAPI_af_routing_requirement_create( + int app_reloc, + OpenAPI_list_t *route_to_locs, + OpenAPI_spatial_validity_t *sp_val, + OpenAPI_list_t *temp_vals, + OpenAPI_up_path_chg_event_t *up_path_chg_sub, + int addr_preser_ind + ); +void OpenAPI_af_routing_requirement_free(OpenAPI_af_routing_requirement_t *af_routing_requirement); +OpenAPI_af_routing_requirement_t *OpenAPI_af_routing_requirement_parseFromJSON(cJSON *af_routing_requirementJSON); +cJSON *OpenAPI_af_routing_requirement_convertToJSON(OpenAPI_af_routing_requirement_t *af_routing_requirement); +OpenAPI_af_routing_requirement_t *OpenAPI_af_routing_requirement_copy(OpenAPI_af_routing_requirement_t *dst, OpenAPI_af_routing_requirement_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_af_routing_requirement_H_ */ + diff --git a/lib/sbi/openapi/model/af_routing_requirement_rm.c b/lib/sbi/openapi/model/af_routing_requirement_rm.c new file mode 100644 index 000000000..aa53ba261 --- /dev/null +++ b/lib/sbi/openapi/model/af_routing_requirement_rm.c @@ -0,0 +1,271 @@ + +#include +#include +#include +#include "af_routing_requirement_rm.h" + +OpenAPI_af_routing_requirement_rm_t *OpenAPI_af_routing_requirement_rm_create( + int app_reloc, + OpenAPI_list_t *route_to_locs, + OpenAPI_spatial_validity_rm_t *sp_val, + OpenAPI_list_t *temp_vals, + OpenAPI_up_path_chg_event_t *up_path_chg_sub, + int addr_preser_ind + ) +{ + OpenAPI_af_routing_requirement_rm_t *af_routing_requirement_rm_local_var = OpenAPI_malloc(sizeof(OpenAPI_af_routing_requirement_rm_t)); + if (!af_routing_requirement_rm_local_var) { + return NULL; + } + af_routing_requirement_rm_local_var->app_reloc = app_reloc; + af_routing_requirement_rm_local_var->route_to_locs = route_to_locs; + af_routing_requirement_rm_local_var->sp_val = sp_val; + af_routing_requirement_rm_local_var->temp_vals = temp_vals; + af_routing_requirement_rm_local_var->up_path_chg_sub = up_path_chg_sub; + af_routing_requirement_rm_local_var->addr_preser_ind = addr_preser_ind; + + return af_routing_requirement_rm_local_var; +} + +void OpenAPI_af_routing_requirement_rm_free(OpenAPI_af_routing_requirement_rm_t *af_routing_requirement_rm) +{ + if (NULL == af_routing_requirement_rm) { + return; + } + OpenAPI_lnode_t *node; + OpenAPI_list_for_each(af_routing_requirement_rm->route_to_locs, node) { + OpenAPI_route_to_location_free(node->data); + } + OpenAPI_list_free(af_routing_requirement_rm->route_to_locs); + OpenAPI_spatial_validity_rm_free(af_routing_requirement_rm->sp_val); + OpenAPI_list_for_each(af_routing_requirement_rm->temp_vals, node) { + OpenAPI_temporal_validity_free(node->data); + } + OpenAPI_list_free(af_routing_requirement_rm->temp_vals); + OpenAPI_up_path_chg_event_free(af_routing_requirement_rm->up_path_chg_sub); + ogs_free(af_routing_requirement_rm); +} + +cJSON *OpenAPI_af_routing_requirement_rm_convertToJSON(OpenAPI_af_routing_requirement_rm_t *af_routing_requirement_rm) +{ + cJSON *item = NULL; + + if (af_routing_requirement_rm == NULL) { + ogs_error("OpenAPI_af_routing_requirement_rm_convertToJSON() failed [AfRoutingRequirementRm]"); + return NULL; + } + + item = cJSON_CreateObject(); + if (af_routing_requirement_rm->app_reloc) { + if (cJSON_AddBoolToObject(item, "appReloc", af_routing_requirement_rm->app_reloc) == NULL) { + ogs_error("OpenAPI_af_routing_requirement_rm_convertToJSON() failed [app_reloc]"); + goto end; + } + } + + if (af_routing_requirement_rm->route_to_locs) { + cJSON *route_to_locsList = cJSON_AddArrayToObject(item, "routeToLocs"); + if (route_to_locsList == NULL) { + ogs_error("OpenAPI_af_routing_requirement_rm_convertToJSON() failed [route_to_locs]"); + goto end; + } + + OpenAPI_lnode_t *route_to_locs_node; + if (af_routing_requirement_rm->route_to_locs) { + OpenAPI_list_for_each(af_routing_requirement_rm->route_to_locs, route_to_locs_node) { + cJSON *itemLocal = OpenAPI_route_to_location_convertToJSON(route_to_locs_node->data); + if (itemLocal == NULL) { + ogs_error("OpenAPI_af_routing_requirement_rm_convertToJSON() failed [route_to_locs]"); + goto end; + } + cJSON_AddItemToArray(route_to_locsList, itemLocal); + } + } + } + + if (af_routing_requirement_rm->sp_val) { + cJSON *sp_val_local_JSON = OpenAPI_spatial_validity_rm_convertToJSON(af_routing_requirement_rm->sp_val); + if (sp_val_local_JSON == NULL) { + ogs_error("OpenAPI_af_routing_requirement_rm_convertToJSON() failed [sp_val]"); + goto end; + } + cJSON_AddItemToObject(item, "spVal", sp_val_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_af_routing_requirement_rm_convertToJSON() failed [sp_val]"); + goto end; + } + } + + if (af_routing_requirement_rm->temp_vals) { + cJSON *temp_valsList = cJSON_AddArrayToObject(item, "tempVals"); + if (temp_valsList == NULL) { + ogs_error("OpenAPI_af_routing_requirement_rm_convertToJSON() failed [temp_vals]"); + goto end; + } + + OpenAPI_lnode_t *temp_vals_node; + if (af_routing_requirement_rm->temp_vals) { + OpenAPI_list_for_each(af_routing_requirement_rm->temp_vals, temp_vals_node) { + cJSON *itemLocal = OpenAPI_temporal_validity_convertToJSON(temp_vals_node->data); + if (itemLocal == NULL) { + ogs_error("OpenAPI_af_routing_requirement_rm_convertToJSON() failed [temp_vals]"); + goto end; + } + cJSON_AddItemToArray(temp_valsList, itemLocal); + } + } + } + + if (af_routing_requirement_rm->up_path_chg_sub) { + cJSON *up_path_chg_sub_local_JSON = OpenAPI_up_path_chg_event_convertToJSON(af_routing_requirement_rm->up_path_chg_sub); + if (up_path_chg_sub_local_JSON == NULL) { + ogs_error("OpenAPI_af_routing_requirement_rm_convertToJSON() failed [up_path_chg_sub]"); + goto end; + } + cJSON_AddItemToObject(item, "upPathChgSub", up_path_chg_sub_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_af_routing_requirement_rm_convertToJSON() failed [up_path_chg_sub]"); + goto end; + } + } + + if (af_routing_requirement_rm->addr_preser_ind) { + if (cJSON_AddBoolToObject(item, "addrPreserInd", af_routing_requirement_rm->addr_preser_ind) == NULL) { + ogs_error("OpenAPI_af_routing_requirement_rm_convertToJSON() failed [addr_preser_ind]"); + goto end; + } + } + +end: + return item; +} + +OpenAPI_af_routing_requirement_rm_t *OpenAPI_af_routing_requirement_rm_parseFromJSON(cJSON *af_routing_requirement_rmJSON) +{ + OpenAPI_af_routing_requirement_rm_t *af_routing_requirement_rm_local_var = NULL; + cJSON *app_reloc = cJSON_GetObjectItemCaseSensitive(af_routing_requirement_rmJSON, "appReloc"); + + if (app_reloc) { + if (!cJSON_IsBool(app_reloc)) { + ogs_error("OpenAPI_af_routing_requirement_rm_parseFromJSON() failed [app_reloc]"); + goto end; + } + } + + cJSON *route_to_locs = cJSON_GetObjectItemCaseSensitive(af_routing_requirement_rmJSON, "routeToLocs"); + + OpenAPI_list_t *route_to_locsList; + if (route_to_locs) { + cJSON *route_to_locs_local_nonprimitive; + if (!cJSON_IsArray(route_to_locs)) { + ogs_error("OpenAPI_af_routing_requirement_rm_parseFromJSON() failed [route_to_locs]"); + goto end; + } + + route_to_locsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(route_to_locs_local_nonprimitive, route_to_locs ) { + if (!cJSON_IsObject(route_to_locs_local_nonprimitive)) { + ogs_error("OpenAPI_af_routing_requirement_rm_parseFromJSON() failed [route_to_locs]"); + goto end; + } + OpenAPI_route_to_location_t *route_to_locsItem = OpenAPI_route_to_location_parseFromJSON(route_to_locs_local_nonprimitive); + + OpenAPI_list_add(route_to_locsList, route_to_locsItem); + } + } + + cJSON *sp_val = cJSON_GetObjectItemCaseSensitive(af_routing_requirement_rmJSON, "spVal"); + + OpenAPI_spatial_validity_rm_t *sp_val_local_nonprim = NULL; + if (sp_val) { + sp_val_local_nonprim = OpenAPI_spatial_validity_rm_parseFromJSON(sp_val); + } + + cJSON *temp_vals = cJSON_GetObjectItemCaseSensitive(af_routing_requirement_rmJSON, "tempVals"); + + OpenAPI_list_t *temp_valsList; + if (temp_vals) { + cJSON *temp_vals_local_nonprimitive; + if (!cJSON_IsArray(temp_vals)) { + ogs_error("OpenAPI_af_routing_requirement_rm_parseFromJSON() failed [temp_vals]"); + goto end; + } + + temp_valsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(temp_vals_local_nonprimitive, temp_vals ) { + if (!cJSON_IsObject(temp_vals_local_nonprimitive)) { + ogs_error("OpenAPI_af_routing_requirement_rm_parseFromJSON() failed [temp_vals]"); + goto end; + } + OpenAPI_temporal_validity_t *temp_valsItem = OpenAPI_temporal_validity_parseFromJSON(temp_vals_local_nonprimitive); + + OpenAPI_list_add(temp_valsList, temp_valsItem); + } + } + + cJSON *up_path_chg_sub = cJSON_GetObjectItemCaseSensitive(af_routing_requirement_rmJSON, "upPathChgSub"); + + OpenAPI_up_path_chg_event_t *up_path_chg_sub_local_nonprim = NULL; + if (up_path_chg_sub) { + up_path_chg_sub_local_nonprim = OpenAPI_up_path_chg_event_parseFromJSON(up_path_chg_sub); + } + + cJSON *addr_preser_ind = cJSON_GetObjectItemCaseSensitive(af_routing_requirement_rmJSON, "addrPreserInd"); + + if (addr_preser_ind) { + if (!cJSON_IsBool(addr_preser_ind)) { + ogs_error("OpenAPI_af_routing_requirement_rm_parseFromJSON() failed [addr_preser_ind]"); + goto end; + } + } + + af_routing_requirement_rm_local_var = OpenAPI_af_routing_requirement_rm_create ( + app_reloc ? app_reloc->valueint : 0, + route_to_locs ? route_to_locsList : NULL, + sp_val ? sp_val_local_nonprim : NULL, + temp_vals ? temp_valsList : NULL, + up_path_chg_sub ? up_path_chg_sub_local_nonprim : NULL, + addr_preser_ind ? addr_preser_ind->valueint : 0 + ); + + return af_routing_requirement_rm_local_var; +end: + return NULL; +} + +OpenAPI_af_routing_requirement_rm_t *OpenAPI_af_routing_requirement_rm_copy(OpenAPI_af_routing_requirement_rm_t *dst, OpenAPI_af_routing_requirement_rm_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_af_routing_requirement_rm_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_af_routing_requirement_rm_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_af_routing_requirement_rm_free(dst); + dst = OpenAPI_af_routing_requirement_rm_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/af_routing_requirement_rm.h b/lib/sbi/openapi/model/af_routing_requirement_rm.h new file mode 100644 index 000000000..3b2f274d3 --- /dev/null +++ b/lib/sbi/openapi/model/af_routing_requirement_rm.h @@ -0,0 +1,52 @@ +/* + * af_routing_requirement_rm.h + * + * this data type is defined in the same way as the AfRoutingRequirement data type, but with the OpenAPI nullable property set to true and the spVal and tempVals attributes defined as removable. + */ + +#ifndef _OpenAPI_af_routing_requirement_rm_H_ +#define _OpenAPI_af_routing_requirement_rm_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" +#include "route_to_location.h" +#include "spatial_validity_rm.h" +#include "temporal_validity.h" +#include "up_path_chg_event.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_af_routing_requirement_rm_s OpenAPI_af_routing_requirement_rm_t; +typedef struct OpenAPI_af_routing_requirement_rm_s { + int app_reloc; + OpenAPI_list_t *route_to_locs; + struct OpenAPI_spatial_validity_rm_s *sp_val; + OpenAPI_list_t *temp_vals; + struct OpenAPI_up_path_chg_event_s *up_path_chg_sub; + int addr_preser_ind; +} OpenAPI_af_routing_requirement_rm_t; + +OpenAPI_af_routing_requirement_rm_t *OpenAPI_af_routing_requirement_rm_create( + int app_reloc, + OpenAPI_list_t *route_to_locs, + OpenAPI_spatial_validity_rm_t *sp_val, + OpenAPI_list_t *temp_vals, + OpenAPI_up_path_chg_event_t *up_path_chg_sub, + int addr_preser_ind + ); +void OpenAPI_af_routing_requirement_rm_free(OpenAPI_af_routing_requirement_rm_t *af_routing_requirement_rm); +OpenAPI_af_routing_requirement_rm_t *OpenAPI_af_routing_requirement_rm_parseFromJSON(cJSON *af_routing_requirement_rmJSON); +cJSON *OpenAPI_af_routing_requirement_rm_convertToJSON(OpenAPI_af_routing_requirement_rm_t *af_routing_requirement_rm); +OpenAPI_af_routing_requirement_rm_t *OpenAPI_af_routing_requirement_rm_copy(OpenAPI_af_routing_requirement_rm_t *dst, OpenAPI_af_routing_requirement_rm_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_af_routing_requirement_rm_H_ */ + diff --git a/lib/sbi/openapi/model/amf3_gpp_access_registration.c b/lib/sbi/openapi/model/amf3_gpp_access_registration.c index 2668abd17..7b95dd074 100644 --- a/lib/sbi/openapi/model/amf3_gpp_access_registration.c +++ b/lib/sbi/openapi/model/amf3_gpp_access_registration.c @@ -9,7 +9,7 @@ OpenAPI_amf3_gpp_access_registration_t *OpenAPI_amf3_gpp_access_registration_cre char *supported_features, int purge_flag, char *pei, - OpenAPI_ims_vo_ps_t *ims_vo_ps, + OpenAPI_ims_vo_ps_e ims_vo_ps, char *dereg_callback_uri, char *amf_service_name_dereg, char *pcscf_restoration_callback_uri, @@ -68,7 +68,6 @@ void OpenAPI_amf3_gpp_access_registration_free(OpenAPI_amf3_gpp_access_registrat ogs_free(amf3_gpp_access_registration->amf_instance_id); ogs_free(amf3_gpp_access_registration->supported_features); ogs_free(amf3_gpp_access_registration->pei); - OpenAPI_ims_vo_ps_free(amf3_gpp_access_registration->ims_vo_ps); ogs_free(amf3_gpp_access_registration->dereg_callback_uri); ogs_free(amf3_gpp_access_registration->amf_service_name_dereg); ogs_free(amf3_gpp_access_registration->pcscf_restoration_callback_uri); @@ -123,13 +122,7 @@ cJSON *OpenAPI_amf3_gpp_access_registration_convertToJSON(OpenAPI_amf3_gpp_acces } if (amf3_gpp_access_registration->ims_vo_ps) { - cJSON *ims_vo_ps_local_JSON = OpenAPI_ims_vo_ps_convertToJSON(amf3_gpp_access_registration->ims_vo_ps); - if (ims_vo_ps_local_JSON == NULL) { - ogs_error("OpenAPI_amf3_gpp_access_registration_convertToJSON() failed [ims_vo_ps]"); - goto end; - } - cJSON_AddItemToObject(item, "imsVoPs", ims_vo_ps_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "imsVoPs", OpenAPI_ims_vo_ps_ToString(amf3_gpp_access_registration->ims_vo_ps)) == NULL) { ogs_error("OpenAPI_amf3_gpp_access_registration_convertToJSON() failed [ims_vo_ps]"); goto end; } @@ -333,9 +326,13 @@ OpenAPI_amf3_gpp_access_registration_t *OpenAPI_amf3_gpp_access_registration_par cJSON *ims_vo_ps = cJSON_GetObjectItemCaseSensitive(amf3_gpp_access_registrationJSON, "imsVoPs"); - OpenAPI_ims_vo_ps_t *ims_vo_ps_local_nonprim = NULL; + OpenAPI_ims_vo_ps_e ims_vo_psVariable; if (ims_vo_ps) { - ims_vo_ps_local_nonprim = OpenAPI_ims_vo_ps_parseFromJSON(ims_vo_ps); + if (!cJSON_IsString(ims_vo_ps)) { + ogs_error("OpenAPI_amf3_gpp_access_registration_parseFromJSON() failed [ims_vo_ps]"); + goto end; + } + ims_vo_psVariable = OpenAPI_ims_vo_ps_FromString(ims_vo_ps->valuestring); } cJSON *dereg_callback_uri = cJSON_GetObjectItemCaseSensitive(amf3_gpp_access_registrationJSON, "deregCallbackUri"); @@ -513,7 +510,7 @@ OpenAPI_amf3_gpp_access_registration_t *OpenAPI_amf3_gpp_access_registration_par supported_features ? ogs_strdup(supported_features->valuestring) : NULL, purge_flag ? purge_flag->valueint : 0, pei ? ogs_strdup(pei->valuestring) : NULL, - ims_vo_ps ? ims_vo_ps_local_nonprim : NULL, + ims_vo_ps ? ims_vo_psVariable : 0, ogs_strdup(dereg_callback_uri->valuestring), amf_service_name_dereg ? ogs_strdup(amf_service_name_dereg->valuestring) : NULL, pcscf_restoration_callback_uri ? ogs_strdup(pcscf_restoration_callback_uri->valuestring) : NULL, diff --git a/lib/sbi/openapi/model/amf3_gpp_access_registration.h b/lib/sbi/openapi/model/amf3_gpp_access_registration.h index 1511ed69a..ef973d6d9 100644 --- a/lib/sbi/openapi/model/amf3_gpp_access_registration.h +++ b/lib/sbi/openapi/model/amf3_gpp_access_registration.h @@ -30,7 +30,7 @@ typedef struct OpenAPI_amf3_gpp_access_registration_s { char *supported_features; int purge_flag; char *pei; - struct OpenAPI_ims_vo_ps_s *ims_vo_ps; + OpenAPI_ims_vo_ps_e ims_vo_ps; char *dereg_callback_uri; char *amf_service_name_dereg; char *pcscf_restoration_callback_uri; @@ -55,7 +55,7 @@ OpenAPI_amf3_gpp_access_registration_t *OpenAPI_amf3_gpp_access_registration_cre char *supported_features, int purge_flag, char *pei, - OpenAPI_ims_vo_ps_t *ims_vo_ps, + OpenAPI_ims_vo_ps_e ims_vo_ps, char *dereg_callback_uri, char *amf_service_name_dereg, char *pcscf_restoration_callback_uri, diff --git a/lib/sbi/openapi/model/amf3_gpp_access_registration_modification.c b/lib/sbi/openapi/model/amf3_gpp_access_registration_modification.c index 4e1c337e2..3eff0836a 100644 --- a/lib/sbi/openapi/model/amf3_gpp_access_registration_modification.c +++ b/lib/sbi/openapi/model/amf3_gpp_access_registration_modification.c @@ -8,7 +8,7 @@ OpenAPI_amf3_gpp_access_registration_modification_t *OpenAPI_amf3_gpp_access_reg OpenAPI_guami_t *guami, int purge_flag, char *pei, - OpenAPI_ims_vo_ps_t *ims_vo_ps, + OpenAPI_ims_vo_ps_e ims_vo_ps, OpenAPI_list_t *backup_amf_info, OpenAPI_eps_interworking_info_t *eps_interworking_info, int ue_srvcc_capability, @@ -39,7 +39,6 @@ void OpenAPI_amf3_gpp_access_registration_modification_free(OpenAPI_amf3_gpp_acc OpenAPI_lnode_t *node; OpenAPI_guami_free(amf3_gpp_access_registration_modification->guami); ogs_free(amf3_gpp_access_registration_modification->pei); - OpenAPI_ims_vo_ps_free(amf3_gpp_access_registration_modification->ims_vo_ps); OpenAPI_list_for_each(amf3_gpp_access_registration_modification->backup_amf_info, node) { OpenAPI_backup_amf_info_free(node->data); } @@ -84,13 +83,7 @@ cJSON *OpenAPI_amf3_gpp_access_registration_modification_convertToJSON(OpenAPI_a } if (amf3_gpp_access_registration_modification->ims_vo_ps) { - cJSON *ims_vo_ps_local_JSON = OpenAPI_ims_vo_ps_convertToJSON(amf3_gpp_access_registration_modification->ims_vo_ps); - if (ims_vo_ps_local_JSON == NULL) { - ogs_error("OpenAPI_amf3_gpp_access_registration_modification_convertToJSON() failed [ims_vo_ps]"); - goto end; - } - cJSON_AddItemToObject(item, "imsVoPs", ims_vo_ps_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "imsVoPs", OpenAPI_ims_vo_ps_ToString(amf3_gpp_access_registration_modification->ims_vo_ps)) == NULL) { ogs_error("OpenAPI_amf3_gpp_access_registration_modification_convertToJSON() failed [ims_vo_ps]"); goto end; } @@ -180,9 +173,13 @@ OpenAPI_amf3_gpp_access_registration_modification_t *OpenAPI_amf3_gpp_access_reg cJSON *ims_vo_ps = cJSON_GetObjectItemCaseSensitive(amf3_gpp_access_registration_modificationJSON, "imsVoPs"); - OpenAPI_ims_vo_ps_t *ims_vo_ps_local_nonprim = NULL; + OpenAPI_ims_vo_ps_e ims_vo_psVariable; if (ims_vo_ps) { - ims_vo_ps_local_nonprim = OpenAPI_ims_vo_ps_parseFromJSON(ims_vo_ps); + if (!cJSON_IsString(ims_vo_ps)) { + ogs_error("OpenAPI_amf3_gpp_access_registration_modification_parseFromJSON() failed [ims_vo_ps]"); + goto end; + } + ims_vo_psVariable = OpenAPI_ims_vo_ps_FromString(ims_vo_ps->valuestring); } cJSON *backup_amf_info = cJSON_GetObjectItemCaseSensitive(amf3_gpp_access_registration_modificationJSON, "backupAmfInfo"); @@ -237,7 +234,7 @@ OpenAPI_amf3_gpp_access_registration_modification_t *OpenAPI_amf3_gpp_access_reg guami_local_nonprim, purge_flag ? purge_flag->valueint : 0, pei ? ogs_strdup(pei->valuestring) : NULL, - ims_vo_ps ? ims_vo_ps_local_nonprim : NULL, + ims_vo_ps ? ims_vo_psVariable : 0, backup_amf_info ? backup_amf_infoList : NULL, eps_interworking_info ? eps_interworking_info_local_nonprim : NULL, ue_srvcc_capability ? ue_srvcc_capability->valueint : 0, diff --git a/lib/sbi/openapi/model/amf3_gpp_access_registration_modification.h b/lib/sbi/openapi/model/amf3_gpp_access_registration_modification.h index 004f9cc25..87382dd49 100644 --- a/lib/sbi/openapi/model/amf3_gpp_access_registration_modification.h +++ b/lib/sbi/openapi/model/amf3_gpp_access_registration_modification.h @@ -26,7 +26,7 @@ typedef struct OpenAPI_amf3_gpp_access_registration_modification_s { struct OpenAPI_guami_s *guami; int purge_flag; char *pei; - struct OpenAPI_ims_vo_ps_s *ims_vo_ps; + OpenAPI_ims_vo_ps_e ims_vo_ps; OpenAPI_list_t *backup_amf_info; struct OpenAPI_eps_interworking_info_s *eps_interworking_info; int ue_srvcc_capability; @@ -37,7 +37,7 @@ OpenAPI_amf3_gpp_access_registration_modification_t *OpenAPI_amf3_gpp_access_reg OpenAPI_guami_t *guami, int purge_flag, char *pei, - OpenAPI_ims_vo_ps_t *ims_vo_ps, + OpenAPI_ims_vo_ps_e ims_vo_ps, OpenAPI_list_t *backup_amf_info, OpenAPI_eps_interworking_info_t *eps_interworking_info, int ue_srvcc_capability, diff --git a/lib/sbi/openapi/model/amf_dereg_info.c b/lib/sbi/openapi/model/amf_dereg_info.c index 9b4aeec9e..6c858836b 100644 --- a/lib/sbi/openapi/model/amf_dereg_info.c +++ b/lib/sbi/openapi/model/amf_dereg_info.c @@ -5,7 +5,7 @@ #include "amf_dereg_info.h" OpenAPI_amf_dereg_info_t *OpenAPI_amf_dereg_info_create( - OpenAPI_deregistration_reason_t *dereg_reason + OpenAPI_deregistration_reason_e dereg_reason ) { OpenAPI_amf_dereg_info_t *amf_dereg_info_local_var = OpenAPI_malloc(sizeof(OpenAPI_amf_dereg_info_t)); @@ -23,7 +23,6 @@ void OpenAPI_amf_dereg_info_free(OpenAPI_amf_dereg_info_t *amf_dereg_info) return; } OpenAPI_lnode_t *node; - OpenAPI_deregistration_reason_free(amf_dereg_info->dereg_reason); ogs_free(amf_dereg_info); } @@ -37,13 +36,7 @@ cJSON *OpenAPI_amf_dereg_info_convertToJSON(OpenAPI_amf_dereg_info_t *amf_dereg_ } item = cJSON_CreateObject(); - cJSON *dereg_reason_local_JSON = OpenAPI_deregistration_reason_convertToJSON(amf_dereg_info->dereg_reason); - if (dereg_reason_local_JSON == NULL) { - ogs_error("OpenAPI_amf_dereg_info_convertToJSON() failed [dereg_reason]"); - goto end; - } - cJSON_AddItemToObject(item, "deregReason", dereg_reason_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "deregReason", OpenAPI_deregistration_reason_ToString(amf_dereg_info->dereg_reason)) == NULL) { ogs_error("OpenAPI_amf_dereg_info_convertToJSON() failed [dereg_reason]"); goto end; } @@ -61,12 +54,16 @@ OpenAPI_amf_dereg_info_t *OpenAPI_amf_dereg_info_parseFromJSON(cJSON *amf_dereg_ goto end; } - OpenAPI_deregistration_reason_t *dereg_reason_local_nonprim = NULL; + OpenAPI_deregistration_reason_e dereg_reasonVariable; - dereg_reason_local_nonprim = OpenAPI_deregistration_reason_parseFromJSON(dereg_reason); + if (!cJSON_IsString(dereg_reason)) { + ogs_error("OpenAPI_amf_dereg_info_parseFromJSON() failed [dereg_reason]"); + goto end; + } + dereg_reasonVariable = OpenAPI_deregistration_reason_FromString(dereg_reason->valuestring); amf_dereg_info_local_var = OpenAPI_amf_dereg_info_create ( - dereg_reason_local_nonprim + dereg_reasonVariable ); return amf_dereg_info_local_var; diff --git a/lib/sbi/openapi/model/amf_dereg_info.h b/lib/sbi/openapi/model/amf_dereg_info.h index 67d2f6a09..1353ee7d8 100644 --- a/lib/sbi/openapi/model/amf_dereg_info.h +++ b/lib/sbi/openapi/model/amf_dereg_info.h @@ -20,11 +20,11 @@ extern "C" { typedef struct OpenAPI_amf_dereg_info_s OpenAPI_amf_dereg_info_t; typedef struct OpenAPI_amf_dereg_info_s { - struct OpenAPI_deregistration_reason_s *dereg_reason; + OpenAPI_deregistration_reason_e dereg_reason; } OpenAPI_amf_dereg_info_t; OpenAPI_amf_dereg_info_t *OpenAPI_amf_dereg_info_create( - OpenAPI_deregistration_reason_t *dereg_reason + OpenAPI_deregistration_reason_e dereg_reason ); void OpenAPI_amf_dereg_info_free(OpenAPI_amf_dereg_info_t *amf_dereg_info); OpenAPI_amf_dereg_info_t *OpenAPI_amf_dereg_info_parseFromJSON(cJSON *amf_dereg_infoJSON); diff --git a/lib/sbi/openapi/model/amf_non3_gpp_access_registration.c b/lib/sbi/openapi/model/amf_non3_gpp_access_registration.c index 6f638d097..090af5c38 100644 --- a/lib/sbi/openapi/model/amf_non3_gpp_access_registration.c +++ b/lib/sbi/openapi/model/amf_non3_gpp_access_registration.c @@ -9,7 +9,7 @@ OpenAPI_amf_non3_gpp_access_registration_t *OpenAPI_amf_non3_gpp_access_registra char *supported_features, int purge_flag, char *pei, - OpenAPI_ims_vo_ps_t *ims_vo_ps, + OpenAPI_ims_vo_ps_e ims_vo_ps, char *dereg_callback_uri, char *amf_service_name_dereg, char *pcscf_restoration_callback_uri, @@ -58,7 +58,6 @@ void OpenAPI_amf_non3_gpp_access_registration_free(OpenAPI_amf_non3_gpp_access_r ogs_free(amf_non3_gpp_access_registration->amf_instance_id); ogs_free(amf_non3_gpp_access_registration->supported_features); ogs_free(amf_non3_gpp_access_registration->pei); - OpenAPI_ims_vo_ps_free(amf_non3_gpp_access_registration->ims_vo_ps); ogs_free(amf_non3_gpp_access_registration->dereg_callback_uri); ogs_free(amf_non3_gpp_access_registration->amf_service_name_dereg); ogs_free(amf_non3_gpp_access_registration->pcscf_restoration_callback_uri); @@ -111,13 +110,7 @@ cJSON *OpenAPI_amf_non3_gpp_access_registration_convertToJSON(OpenAPI_amf_non3_g } } - cJSON *ims_vo_ps_local_JSON = OpenAPI_ims_vo_ps_convertToJSON(amf_non3_gpp_access_registration->ims_vo_ps); - if (ims_vo_ps_local_JSON == NULL) { - ogs_error("OpenAPI_amf_non3_gpp_access_registration_convertToJSON() failed [ims_vo_ps]"); - goto end; - } - cJSON_AddItemToObject(item, "imsVoPs", ims_vo_ps_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "imsVoPs", OpenAPI_ims_vo_ps_ToString(amf_non3_gpp_access_registration->ims_vo_ps)) == NULL) { ogs_error("OpenAPI_amf_non3_gpp_access_registration_convertToJSON() failed [ims_vo_ps]"); goto end; } @@ -283,9 +276,13 @@ OpenAPI_amf_non3_gpp_access_registration_t *OpenAPI_amf_non3_gpp_access_registra goto end; } - OpenAPI_ims_vo_ps_t *ims_vo_ps_local_nonprim = NULL; + OpenAPI_ims_vo_ps_e ims_vo_psVariable; - ims_vo_ps_local_nonprim = OpenAPI_ims_vo_ps_parseFromJSON(ims_vo_ps); + if (!cJSON_IsString(ims_vo_ps)) { + ogs_error("OpenAPI_amf_non3_gpp_access_registration_parseFromJSON() failed [ims_vo_ps]"); + goto end; + } + ims_vo_psVariable = OpenAPI_ims_vo_ps_FromString(ims_vo_ps->valuestring); cJSON *dereg_callback_uri = cJSON_GetObjectItemCaseSensitive(amf_non3_gpp_access_registrationJSON, "deregCallbackUri"); if (!dereg_callback_uri) { @@ -419,7 +416,7 @@ OpenAPI_amf_non3_gpp_access_registration_t *OpenAPI_amf_non3_gpp_access_registra supported_features ? ogs_strdup(supported_features->valuestring) : NULL, purge_flag ? purge_flag->valueint : 0, pei ? ogs_strdup(pei->valuestring) : NULL, - ims_vo_ps_local_nonprim, + ims_vo_psVariable, ogs_strdup(dereg_callback_uri->valuestring), amf_service_name_dereg ? ogs_strdup(amf_service_name_dereg->valuestring) : NULL, pcscf_restoration_callback_uri ? ogs_strdup(pcscf_restoration_callback_uri->valuestring) : NULL, diff --git a/lib/sbi/openapi/model/amf_non3_gpp_access_registration.h b/lib/sbi/openapi/model/amf_non3_gpp_access_registration.h index 668314d9b..805a3afd1 100644 --- a/lib/sbi/openapi/model/amf_non3_gpp_access_registration.h +++ b/lib/sbi/openapi/model/amf_non3_gpp_access_registration.h @@ -29,7 +29,7 @@ typedef struct OpenAPI_amf_non3_gpp_access_registration_s { char *supported_features; int purge_flag; char *pei; - struct OpenAPI_ims_vo_ps_s *ims_vo_ps; + OpenAPI_ims_vo_ps_e ims_vo_ps; char *dereg_callback_uri; char *amf_service_name_dereg; char *pcscf_restoration_callback_uri; @@ -49,7 +49,7 @@ OpenAPI_amf_non3_gpp_access_registration_t *OpenAPI_amf_non3_gpp_access_registra char *supported_features, int purge_flag, char *pei, - OpenAPI_ims_vo_ps_t *ims_vo_ps, + OpenAPI_ims_vo_ps_e ims_vo_ps, char *dereg_callback_uri, char *amf_service_name_dereg, char *pcscf_restoration_callback_uri, diff --git a/lib/sbi/openapi/model/amf_non3_gpp_access_registration_modification.c b/lib/sbi/openapi/model/amf_non3_gpp_access_registration_modification.c index aa93e6671..b3ea95089 100644 --- a/lib/sbi/openapi/model/amf_non3_gpp_access_registration_modification.c +++ b/lib/sbi/openapi/model/amf_non3_gpp_access_registration_modification.c @@ -8,7 +8,7 @@ OpenAPI_amf_non3_gpp_access_registration_modification_t *OpenAPI_amf_non3_gpp_ac OpenAPI_guami_t *guami, int purge_flag, char *pei, - OpenAPI_ims_vo_ps_t *ims_vo_ps, + OpenAPI_ims_vo_ps_e ims_vo_ps, OpenAPI_list_t *backup_amf_info ) { @@ -33,7 +33,6 @@ void OpenAPI_amf_non3_gpp_access_registration_modification_free(OpenAPI_amf_non3 OpenAPI_lnode_t *node; OpenAPI_guami_free(amf_non3_gpp_access_registration_modification->guami); ogs_free(amf_non3_gpp_access_registration_modification->pei); - OpenAPI_ims_vo_ps_free(amf_non3_gpp_access_registration_modification->ims_vo_ps); OpenAPI_list_for_each(amf_non3_gpp_access_registration_modification->backup_amf_info, node) { OpenAPI_backup_amf_info_free(node->data); } @@ -77,13 +76,7 @@ cJSON *OpenAPI_amf_non3_gpp_access_registration_modification_convertToJSON(OpenA } if (amf_non3_gpp_access_registration_modification->ims_vo_ps) { - cJSON *ims_vo_ps_local_JSON = OpenAPI_ims_vo_ps_convertToJSON(amf_non3_gpp_access_registration_modification->ims_vo_ps); - if (ims_vo_ps_local_JSON == NULL) { - ogs_error("OpenAPI_amf_non3_gpp_access_registration_modification_convertToJSON() failed [ims_vo_ps]"); - goto end; - } - cJSON_AddItemToObject(item, "imsVoPs", ims_vo_ps_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "imsVoPs", OpenAPI_ims_vo_ps_ToString(amf_non3_gpp_access_registration_modification->ims_vo_ps)) == NULL) { ogs_error("OpenAPI_amf_non3_gpp_access_registration_modification_convertToJSON() failed [ims_vo_ps]"); goto end; } @@ -146,9 +139,13 @@ OpenAPI_amf_non3_gpp_access_registration_modification_t *OpenAPI_amf_non3_gpp_ac cJSON *ims_vo_ps = cJSON_GetObjectItemCaseSensitive(amf_non3_gpp_access_registration_modificationJSON, "imsVoPs"); - OpenAPI_ims_vo_ps_t *ims_vo_ps_local_nonprim = NULL; + OpenAPI_ims_vo_ps_e ims_vo_psVariable; if (ims_vo_ps) { - ims_vo_ps_local_nonprim = OpenAPI_ims_vo_ps_parseFromJSON(ims_vo_ps); + if (!cJSON_IsString(ims_vo_ps)) { + ogs_error("OpenAPI_amf_non3_gpp_access_registration_modification_parseFromJSON() failed [ims_vo_ps]"); + goto end; + } + ims_vo_psVariable = OpenAPI_ims_vo_ps_FromString(ims_vo_ps->valuestring); } cJSON *backup_amf_info = cJSON_GetObjectItemCaseSensitive(amf_non3_gpp_access_registration_modificationJSON, "backupAmfInfo"); @@ -178,7 +175,7 @@ OpenAPI_amf_non3_gpp_access_registration_modification_t *OpenAPI_amf_non3_gpp_ac guami_local_nonprim, purge_flag ? purge_flag->valueint : 0, pei ? ogs_strdup(pei->valuestring) : NULL, - ims_vo_ps ? ims_vo_ps_local_nonprim : NULL, + ims_vo_ps ? ims_vo_psVariable : 0, backup_amf_info ? backup_amf_infoList : NULL ); diff --git a/lib/sbi/openapi/model/amf_non3_gpp_access_registration_modification.h b/lib/sbi/openapi/model/amf_non3_gpp_access_registration_modification.h index 07d3b86fb..8c2a27523 100644 --- a/lib/sbi/openapi/model/amf_non3_gpp_access_registration_modification.h +++ b/lib/sbi/openapi/model/amf_non3_gpp_access_registration_modification.h @@ -25,7 +25,7 @@ typedef struct OpenAPI_amf_non3_gpp_access_registration_modification_s { struct OpenAPI_guami_s *guami; int purge_flag; char *pei; - struct OpenAPI_ims_vo_ps_s *ims_vo_ps; + OpenAPI_ims_vo_ps_e ims_vo_ps; OpenAPI_list_t *backup_amf_info; } OpenAPI_amf_non3_gpp_access_registration_modification_t; @@ -33,7 +33,7 @@ OpenAPI_amf_non3_gpp_access_registration_modification_t *OpenAPI_amf_non3_gpp_ac OpenAPI_guami_t *guami, int purge_flag, char *pei, - OpenAPI_ims_vo_ps_t *ims_vo_ps, + OpenAPI_ims_vo_ps_e ims_vo_ps, OpenAPI_list_t *backup_amf_info ); void OpenAPI_amf_non3_gpp_access_registration_modification_free(OpenAPI_amf_non3_gpp_access_registration_modification_t *amf_non3_gpp_access_registration_modification); diff --git a/lib/sbi/openapi/model/app_session_context.c b/lib/sbi/openapi/model/app_session_context.c new file mode 100644 index 000000000..936e09fc0 --- /dev/null +++ b/lib/sbi/openapi/model/app_session_context.c @@ -0,0 +1,157 @@ + +#include +#include +#include +#include "app_session_context.h" + +OpenAPI_app_session_context_t *OpenAPI_app_session_context_create( + OpenAPI_app_session_context_req_data_t *asc_req_data, + OpenAPI_app_session_context_resp_data_t *asc_resp_data, + OpenAPI_events_notification_t *evs_notif + ) +{ + OpenAPI_app_session_context_t *app_session_context_local_var = OpenAPI_malloc(sizeof(OpenAPI_app_session_context_t)); + if (!app_session_context_local_var) { + return NULL; + } + app_session_context_local_var->asc_req_data = asc_req_data; + app_session_context_local_var->asc_resp_data = asc_resp_data; + app_session_context_local_var->evs_notif = evs_notif; + + return app_session_context_local_var; +} + +void OpenAPI_app_session_context_free(OpenAPI_app_session_context_t *app_session_context) +{ + if (NULL == app_session_context) { + return; + } + OpenAPI_lnode_t *node; + OpenAPI_app_session_context_req_data_free(app_session_context->asc_req_data); + OpenAPI_app_session_context_resp_data_free(app_session_context->asc_resp_data); + OpenAPI_events_notification_free(app_session_context->evs_notif); + ogs_free(app_session_context); +} + +cJSON *OpenAPI_app_session_context_convertToJSON(OpenAPI_app_session_context_t *app_session_context) +{ + cJSON *item = NULL; + + if (app_session_context == NULL) { + ogs_error("OpenAPI_app_session_context_convertToJSON() failed [AppSessionContext]"); + return NULL; + } + + item = cJSON_CreateObject(); + if (app_session_context->asc_req_data) { + cJSON *asc_req_data_local_JSON = OpenAPI_app_session_context_req_data_convertToJSON(app_session_context->asc_req_data); + if (asc_req_data_local_JSON == NULL) { + ogs_error("OpenAPI_app_session_context_convertToJSON() failed [asc_req_data]"); + goto end; + } + cJSON_AddItemToObject(item, "ascReqData", asc_req_data_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_app_session_context_convertToJSON() failed [asc_req_data]"); + goto end; + } + } + + if (app_session_context->asc_resp_data) { + cJSON *asc_resp_data_local_JSON = OpenAPI_app_session_context_resp_data_convertToJSON(app_session_context->asc_resp_data); + if (asc_resp_data_local_JSON == NULL) { + ogs_error("OpenAPI_app_session_context_convertToJSON() failed [asc_resp_data]"); + goto end; + } + cJSON_AddItemToObject(item, "ascRespData", asc_resp_data_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_app_session_context_convertToJSON() failed [asc_resp_data]"); + goto end; + } + } + + if (app_session_context->evs_notif) { + cJSON *evs_notif_local_JSON = OpenAPI_events_notification_convertToJSON(app_session_context->evs_notif); + if (evs_notif_local_JSON == NULL) { + ogs_error("OpenAPI_app_session_context_convertToJSON() failed [evs_notif]"); + goto end; + } + cJSON_AddItemToObject(item, "evsNotif", evs_notif_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_app_session_context_convertToJSON() failed [evs_notif]"); + goto end; + } + } + +end: + return item; +} + +OpenAPI_app_session_context_t *OpenAPI_app_session_context_parseFromJSON(cJSON *app_session_contextJSON) +{ + OpenAPI_app_session_context_t *app_session_context_local_var = NULL; + cJSON *asc_req_data = cJSON_GetObjectItemCaseSensitive(app_session_contextJSON, "ascReqData"); + + OpenAPI_app_session_context_req_data_t *asc_req_data_local_nonprim = NULL; + if (asc_req_data) { + asc_req_data_local_nonprim = OpenAPI_app_session_context_req_data_parseFromJSON(asc_req_data); + } + + cJSON *asc_resp_data = cJSON_GetObjectItemCaseSensitive(app_session_contextJSON, "ascRespData"); + + OpenAPI_app_session_context_resp_data_t *asc_resp_data_local_nonprim = NULL; + if (asc_resp_data) { + asc_resp_data_local_nonprim = OpenAPI_app_session_context_resp_data_parseFromJSON(asc_resp_data); + } + + cJSON *evs_notif = cJSON_GetObjectItemCaseSensitive(app_session_contextJSON, "evsNotif"); + + OpenAPI_events_notification_t *evs_notif_local_nonprim = NULL; + if (evs_notif) { + evs_notif_local_nonprim = OpenAPI_events_notification_parseFromJSON(evs_notif); + } + + app_session_context_local_var = OpenAPI_app_session_context_create ( + asc_req_data ? asc_req_data_local_nonprim : NULL, + asc_resp_data ? asc_resp_data_local_nonprim : NULL, + evs_notif ? evs_notif_local_nonprim : NULL + ); + + return app_session_context_local_var; +end: + return NULL; +} + +OpenAPI_app_session_context_t *OpenAPI_app_session_context_copy(OpenAPI_app_session_context_t *dst, OpenAPI_app_session_context_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_app_session_context_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_app_session_context_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_app_session_context_free(dst); + dst = OpenAPI_app_session_context_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/app_session_context.h b/lib/sbi/openapi/model/app_session_context.h new file mode 100644 index 000000000..ffdea79ec --- /dev/null +++ b/lib/sbi/openapi/model/app_session_context.h @@ -0,0 +1,45 @@ +/* + * app_session_context.h + * + * Represents an Individual Application Session Context resource. + */ + +#ifndef _OpenAPI_app_session_context_H_ +#define _OpenAPI_app_session_context_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" +#include "app_session_context_req_data.h" +#include "app_session_context_resp_data.h" +#include "events_notification.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_app_session_context_s OpenAPI_app_session_context_t; +typedef struct OpenAPI_app_session_context_s { + struct OpenAPI_app_session_context_req_data_s *asc_req_data; + struct OpenAPI_app_session_context_resp_data_s *asc_resp_data; + struct OpenAPI_events_notification_s *evs_notif; +} OpenAPI_app_session_context_t; + +OpenAPI_app_session_context_t *OpenAPI_app_session_context_create( + OpenAPI_app_session_context_req_data_t *asc_req_data, + OpenAPI_app_session_context_resp_data_t *asc_resp_data, + OpenAPI_events_notification_t *evs_notif + ); +void OpenAPI_app_session_context_free(OpenAPI_app_session_context_t *app_session_context); +OpenAPI_app_session_context_t *OpenAPI_app_session_context_parseFromJSON(cJSON *app_session_contextJSON); +cJSON *OpenAPI_app_session_context_convertToJSON(OpenAPI_app_session_context_t *app_session_context); +OpenAPI_app_session_context_t *OpenAPI_app_session_context_copy(OpenAPI_app_session_context_t *dst, OpenAPI_app_session_context_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_app_session_context_H_ */ + diff --git a/lib/sbi/openapi/model/app_session_context_req_data.c b/lib/sbi/openapi/model/app_session_context_req_data.c new file mode 100644 index 000000000..eee3acb3c --- /dev/null +++ b/lib/sbi/openapi/model/app_session_context_req_data.c @@ -0,0 +1,771 @@ + +#include +#include +#include +#include "app_session_context_req_data.h" + +OpenAPI_app_session_context_req_data_t *OpenAPI_app_session_context_req_data_create( + char *af_app_id, + char *af_charg_id, + OpenAPI_af_requested_data_e af_req_data, + OpenAPI_af_routing_requirement_t *af_rout_req, + char *asp_id, + char *bdt_ref_id, + char *dnn, + OpenAPI_events_subsc_req_data_t *ev_subsc, + char *mcptt_id, + char *mc_video_id, + OpenAPI_list_t* med_components, + char *ip_domain, + char *mps_id, + char *mcs_id, + OpenAPI_preemption_control_information_e preempt_control_info, + OpenAPI_reserv_priority_e res_prio, + OpenAPI_service_info_status_e serv_inf_status, + char *notif_uri, + char *serv_urn, + OpenAPI_snssai_t *slice_info, + char *spon_id, + OpenAPI_sponsoring_status_e spon_status, + char *supi, + char *gpsi, + char *supp_feat, + char *ue_ipv4, + char *ue_ipv6, + char *ue_mac, + OpenAPI_port_management_container_t *tsn_port_man_cont_dstt, + OpenAPI_list_t *tsn_port_man_cont_nwtts + ) +{ + OpenAPI_app_session_context_req_data_t *app_session_context_req_data_local_var = OpenAPI_malloc(sizeof(OpenAPI_app_session_context_req_data_t)); + if (!app_session_context_req_data_local_var) { + return NULL; + } + app_session_context_req_data_local_var->af_app_id = af_app_id; + app_session_context_req_data_local_var->af_charg_id = af_charg_id; + app_session_context_req_data_local_var->af_req_data = af_req_data; + app_session_context_req_data_local_var->af_rout_req = af_rout_req; + app_session_context_req_data_local_var->asp_id = asp_id; + app_session_context_req_data_local_var->bdt_ref_id = bdt_ref_id; + app_session_context_req_data_local_var->dnn = dnn; + app_session_context_req_data_local_var->ev_subsc = ev_subsc; + app_session_context_req_data_local_var->mcptt_id = mcptt_id; + app_session_context_req_data_local_var->mc_video_id = mc_video_id; + app_session_context_req_data_local_var->med_components = med_components; + app_session_context_req_data_local_var->ip_domain = ip_domain; + app_session_context_req_data_local_var->mps_id = mps_id; + app_session_context_req_data_local_var->mcs_id = mcs_id; + app_session_context_req_data_local_var->preempt_control_info = preempt_control_info; + app_session_context_req_data_local_var->res_prio = res_prio; + app_session_context_req_data_local_var->serv_inf_status = serv_inf_status; + app_session_context_req_data_local_var->notif_uri = notif_uri; + app_session_context_req_data_local_var->serv_urn = serv_urn; + app_session_context_req_data_local_var->slice_info = slice_info; + app_session_context_req_data_local_var->spon_id = spon_id; + app_session_context_req_data_local_var->spon_status = spon_status; + app_session_context_req_data_local_var->supi = supi; + app_session_context_req_data_local_var->gpsi = gpsi; + app_session_context_req_data_local_var->supp_feat = supp_feat; + app_session_context_req_data_local_var->ue_ipv4 = ue_ipv4; + app_session_context_req_data_local_var->ue_ipv6 = ue_ipv6; + app_session_context_req_data_local_var->ue_mac = ue_mac; + app_session_context_req_data_local_var->tsn_port_man_cont_dstt = tsn_port_man_cont_dstt; + app_session_context_req_data_local_var->tsn_port_man_cont_nwtts = tsn_port_man_cont_nwtts; + + return app_session_context_req_data_local_var; +} + +void OpenAPI_app_session_context_req_data_free(OpenAPI_app_session_context_req_data_t *app_session_context_req_data) +{ + if (NULL == app_session_context_req_data) { + return; + } + OpenAPI_lnode_t *node; + ogs_free(app_session_context_req_data->af_app_id); + ogs_free(app_session_context_req_data->af_charg_id); + OpenAPI_af_routing_requirement_free(app_session_context_req_data->af_rout_req); + ogs_free(app_session_context_req_data->asp_id); + ogs_free(app_session_context_req_data->bdt_ref_id); + ogs_free(app_session_context_req_data->dnn); + OpenAPI_events_subsc_req_data_free(app_session_context_req_data->ev_subsc); + ogs_free(app_session_context_req_data->mcptt_id); + ogs_free(app_session_context_req_data->mc_video_id); + OpenAPI_list_for_each(app_session_context_req_data->med_components, node) { + OpenAPI_map_t *localKeyValue = (OpenAPI_map_t*)node->data; + OpenAPI_media_component_free(localKeyValue->value); + ogs_free(localKeyValue); + } + OpenAPI_list_free(app_session_context_req_data->med_components); + ogs_free(app_session_context_req_data->ip_domain); + ogs_free(app_session_context_req_data->mps_id); + ogs_free(app_session_context_req_data->mcs_id); + ogs_free(app_session_context_req_data->notif_uri); + ogs_free(app_session_context_req_data->serv_urn); + OpenAPI_snssai_free(app_session_context_req_data->slice_info); + ogs_free(app_session_context_req_data->spon_id); + ogs_free(app_session_context_req_data->supi); + ogs_free(app_session_context_req_data->gpsi); + ogs_free(app_session_context_req_data->supp_feat); + ogs_free(app_session_context_req_data->ue_ipv4); + ogs_free(app_session_context_req_data->ue_ipv6); + ogs_free(app_session_context_req_data->ue_mac); + OpenAPI_port_management_container_free(app_session_context_req_data->tsn_port_man_cont_dstt); + OpenAPI_list_for_each(app_session_context_req_data->tsn_port_man_cont_nwtts, node) { + OpenAPI_port_management_container_free(node->data); + } + OpenAPI_list_free(app_session_context_req_data->tsn_port_man_cont_nwtts); + ogs_free(app_session_context_req_data); +} + +cJSON *OpenAPI_app_session_context_req_data_convertToJSON(OpenAPI_app_session_context_req_data_t *app_session_context_req_data) +{ + cJSON *item = NULL; + + if (app_session_context_req_data == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [AppSessionContextReqData]"); + return NULL; + } + + item = cJSON_CreateObject(); + if (app_session_context_req_data->af_app_id) { + if (cJSON_AddStringToObject(item, "afAppId", app_session_context_req_data->af_app_id) == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [af_app_id]"); + goto end; + } + } + + if (app_session_context_req_data->af_charg_id) { + if (cJSON_AddStringToObject(item, "afChargId", app_session_context_req_data->af_charg_id) == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [af_charg_id]"); + goto end; + } + } + + if (app_session_context_req_data->af_req_data) { + if (cJSON_AddStringToObject(item, "afReqData", OpenAPI_af_requested_data_ToString(app_session_context_req_data->af_req_data)) == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [af_req_data]"); + goto end; + } + } + + if (app_session_context_req_data->af_rout_req) { + cJSON *af_rout_req_local_JSON = OpenAPI_af_routing_requirement_convertToJSON(app_session_context_req_data->af_rout_req); + if (af_rout_req_local_JSON == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [af_rout_req]"); + goto end; + } + cJSON_AddItemToObject(item, "afRoutReq", af_rout_req_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [af_rout_req]"); + goto end; + } + } + + if (app_session_context_req_data->asp_id) { + if (cJSON_AddStringToObject(item, "aspId", app_session_context_req_data->asp_id) == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [asp_id]"); + goto end; + } + } + + if (app_session_context_req_data->bdt_ref_id) { + if (cJSON_AddStringToObject(item, "bdtRefId", app_session_context_req_data->bdt_ref_id) == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [bdt_ref_id]"); + goto end; + } + } + + if (app_session_context_req_data->dnn) { + if (cJSON_AddStringToObject(item, "dnn", app_session_context_req_data->dnn) == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [dnn]"); + goto end; + } + } + + if (app_session_context_req_data->ev_subsc) { + cJSON *ev_subsc_local_JSON = OpenAPI_events_subsc_req_data_convertToJSON(app_session_context_req_data->ev_subsc); + if (ev_subsc_local_JSON == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [ev_subsc]"); + goto end; + } + cJSON_AddItemToObject(item, "evSubsc", ev_subsc_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [ev_subsc]"); + goto end; + } + } + + if (app_session_context_req_data->mcptt_id) { + if (cJSON_AddStringToObject(item, "mcpttId", app_session_context_req_data->mcptt_id) == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [mcptt_id]"); + goto end; + } + } + + if (app_session_context_req_data->mc_video_id) { + if (cJSON_AddStringToObject(item, "mcVideoId", app_session_context_req_data->mc_video_id) == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [mc_video_id]"); + goto end; + } + } + + if (app_session_context_req_data->med_components) { + cJSON *med_components = cJSON_AddObjectToObject(item, "medComponents"); + if (med_components == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [med_components]"); + goto end; + } + cJSON *localMapObject = med_components; + OpenAPI_lnode_t *med_components_node; + if (app_session_context_req_data->med_components) { + OpenAPI_list_for_each(app_session_context_req_data->med_components, med_components_node) { + OpenAPI_map_t *localKeyValue = (OpenAPI_map_t*)med_components_node->data; + cJSON *itemLocal = OpenAPI_media_component_convertToJSON(localKeyValue->value); + if (itemLocal == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [med_components]"); + goto end; + } + cJSON_AddItemToObject(med_components, localKeyValue->key, itemLocal); + } + } + } + + if (app_session_context_req_data->ip_domain) { + if (cJSON_AddStringToObject(item, "ipDomain", app_session_context_req_data->ip_domain) == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [ip_domain]"); + goto end; + } + } + + if (app_session_context_req_data->mps_id) { + if (cJSON_AddStringToObject(item, "mpsId", app_session_context_req_data->mps_id) == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [mps_id]"); + goto end; + } + } + + if (app_session_context_req_data->mcs_id) { + if (cJSON_AddStringToObject(item, "mcsId", app_session_context_req_data->mcs_id) == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [mcs_id]"); + goto end; + } + } + + if (app_session_context_req_data->preempt_control_info) { + if (cJSON_AddStringToObject(item, "preemptControlInfo", OpenAPI_preemption_control_information_ToString(app_session_context_req_data->preempt_control_info)) == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [preempt_control_info]"); + goto end; + } + } + + if (app_session_context_req_data->res_prio) { + if (cJSON_AddStringToObject(item, "resPrio", OpenAPI_reserv_priority_ToString(app_session_context_req_data->res_prio)) == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [res_prio]"); + goto end; + } + } + + if (app_session_context_req_data->serv_inf_status) { + if (cJSON_AddStringToObject(item, "servInfStatus", OpenAPI_service_info_status_ToString(app_session_context_req_data->serv_inf_status)) == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [serv_inf_status]"); + goto end; + } + } + + if (cJSON_AddStringToObject(item, "notifUri", app_session_context_req_data->notif_uri) == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [notif_uri]"); + goto end; + } + + if (app_session_context_req_data->serv_urn) { + if (cJSON_AddStringToObject(item, "servUrn", app_session_context_req_data->serv_urn) == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [serv_urn]"); + goto end; + } + } + + if (app_session_context_req_data->slice_info) { + cJSON *slice_info_local_JSON = OpenAPI_snssai_convertToJSON(app_session_context_req_data->slice_info); + if (slice_info_local_JSON == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [slice_info]"); + goto end; + } + cJSON_AddItemToObject(item, "sliceInfo", slice_info_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [slice_info]"); + goto end; + } + } + + if (app_session_context_req_data->spon_id) { + if (cJSON_AddStringToObject(item, "sponId", app_session_context_req_data->spon_id) == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [spon_id]"); + goto end; + } + } + + if (app_session_context_req_data->spon_status) { + if (cJSON_AddStringToObject(item, "sponStatus", OpenAPI_sponsoring_status_ToString(app_session_context_req_data->spon_status)) == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [spon_status]"); + goto end; + } + } + + if (app_session_context_req_data->supi) { + if (cJSON_AddStringToObject(item, "supi", app_session_context_req_data->supi) == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [supi]"); + goto end; + } + } + + if (app_session_context_req_data->gpsi) { + if (cJSON_AddStringToObject(item, "gpsi", app_session_context_req_data->gpsi) == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [gpsi]"); + goto end; + } + } + + if (cJSON_AddStringToObject(item, "suppFeat", app_session_context_req_data->supp_feat) == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [supp_feat]"); + goto end; + } + + if (app_session_context_req_data->ue_ipv4) { + if (cJSON_AddStringToObject(item, "ueIpv4", app_session_context_req_data->ue_ipv4) == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [ue_ipv4]"); + goto end; + } + } + + if (app_session_context_req_data->ue_ipv6) { + if (cJSON_AddStringToObject(item, "ueIpv6", app_session_context_req_data->ue_ipv6) == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [ue_ipv6]"); + goto end; + } + } + + if (app_session_context_req_data->ue_mac) { + if (cJSON_AddStringToObject(item, "ueMac", app_session_context_req_data->ue_mac) == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [ue_mac]"); + goto end; + } + } + + if (app_session_context_req_data->tsn_port_man_cont_dstt) { + cJSON *tsn_port_man_cont_dstt_local_JSON = OpenAPI_port_management_container_convertToJSON(app_session_context_req_data->tsn_port_man_cont_dstt); + if (tsn_port_man_cont_dstt_local_JSON == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [tsn_port_man_cont_dstt]"); + goto end; + } + cJSON_AddItemToObject(item, "tsnPortManContDstt", tsn_port_man_cont_dstt_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [tsn_port_man_cont_dstt]"); + goto end; + } + } + + if (app_session_context_req_data->tsn_port_man_cont_nwtts) { + cJSON *tsn_port_man_cont_nwttsList = cJSON_AddArrayToObject(item, "tsnPortManContNwtts"); + if (tsn_port_man_cont_nwttsList == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [tsn_port_man_cont_nwtts]"); + goto end; + } + + OpenAPI_lnode_t *tsn_port_man_cont_nwtts_node; + if (app_session_context_req_data->tsn_port_man_cont_nwtts) { + OpenAPI_list_for_each(app_session_context_req_data->tsn_port_man_cont_nwtts, tsn_port_man_cont_nwtts_node) { + cJSON *itemLocal = OpenAPI_port_management_container_convertToJSON(tsn_port_man_cont_nwtts_node->data); + if (itemLocal == NULL) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed [tsn_port_man_cont_nwtts]"); + goto end; + } + cJSON_AddItemToArray(tsn_port_man_cont_nwttsList, itemLocal); + } + } + } + +end: + return item; +} + +OpenAPI_app_session_context_req_data_t *OpenAPI_app_session_context_req_data_parseFromJSON(cJSON *app_session_context_req_dataJSON) +{ + OpenAPI_app_session_context_req_data_t *app_session_context_req_data_local_var = NULL; + cJSON *af_app_id = cJSON_GetObjectItemCaseSensitive(app_session_context_req_dataJSON, "afAppId"); + + if (af_app_id) { + if (!cJSON_IsString(af_app_id)) { + ogs_error("OpenAPI_app_session_context_req_data_parseFromJSON() failed [af_app_id]"); + goto end; + } + } + + cJSON *af_charg_id = cJSON_GetObjectItemCaseSensitive(app_session_context_req_dataJSON, "afChargId"); + + if (af_charg_id) { + if (!cJSON_IsString(af_charg_id)) { + ogs_error("OpenAPI_app_session_context_req_data_parseFromJSON() failed [af_charg_id]"); + goto end; + } + } + + cJSON *af_req_data = cJSON_GetObjectItemCaseSensitive(app_session_context_req_dataJSON, "afReqData"); + + OpenAPI_af_requested_data_e af_req_dataVariable; + if (af_req_data) { + if (!cJSON_IsString(af_req_data)) { + ogs_error("OpenAPI_app_session_context_req_data_parseFromJSON() failed [af_req_data]"); + goto end; + } + af_req_dataVariable = OpenAPI_af_requested_data_FromString(af_req_data->valuestring); + } + + cJSON *af_rout_req = cJSON_GetObjectItemCaseSensitive(app_session_context_req_dataJSON, "afRoutReq"); + + OpenAPI_af_routing_requirement_t *af_rout_req_local_nonprim = NULL; + if (af_rout_req) { + af_rout_req_local_nonprim = OpenAPI_af_routing_requirement_parseFromJSON(af_rout_req); + } + + cJSON *asp_id = cJSON_GetObjectItemCaseSensitive(app_session_context_req_dataJSON, "aspId"); + + if (asp_id) { + if (!cJSON_IsString(asp_id)) { + ogs_error("OpenAPI_app_session_context_req_data_parseFromJSON() failed [asp_id]"); + goto end; + } + } + + cJSON *bdt_ref_id = cJSON_GetObjectItemCaseSensitive(app_session_context_req_dataJSON, "bdtRefId"); + + if (bdt_ref_id) { + if (!cJSON_IsString(bdt_ref_id)) { + ogs_error("OpenAPI_app_session_context_req_data_parseFromJSON() failed [bdt_ref_id]"); + goto end; + } + } + + cJSON *dnn = cJSON_GetObjectItemCaseSensitive(app_session_context_req_dataJSON, "dnn"); + + if (dnn) { + if (!cJSON_IsString(dnn)) { + ogs_error("OpenAPI_app_session_context_req_data_parseFromJSON() failed [dnn]"); + goto end; + } + } + + cJSON *ev_subsc = cJSON_GetObjectItemCaseSensitive(app_session_context_req_dataJSON, "evSubsc"); + + OpenAPI_events_subsc_req_data_t *ev_subsc_local_nonprim = NULL; + if (ev_subsc) { + ev_subsc_local_nonprim = OpenAPI_events_subsc_req_data_parseFromJSON(ev_subsc); + } + + cJSON *mcptt_id = cJSON_GetObjectItemCaseSensitive(app_session_context_req_dataJSON, "mcpttId"); + + if (mcptt_id) { + if (!cJSON_IsString(mcptt_id)) { + ogs_error("OpenAPI_app_session_context_req_data_parseFromJSON() failed [mcptt_id]"); + goto end; + } + } + + cJSON *mc_video_id = cJSON_GetObjectItemCaseSensitive(app_session_context_req_dataJSON, "mcVideoId"); + + if (mc_video_id) { + if (!cJSON_IsString(mc_video_id)) { + ogs_error("OpenAPI_app_session_context_req_data_parseFromJSON() failed [mc_video_id]"); + goto end; + } + } + + cJSON *med_components = cJSON_GetObjectItemCaseSensitive(app_session_context_req_dataJSON, "medComponents"); + + OpenAPI_list_t *med_componentsList; + if (med_components) { + cJSON *med_components_local_map; + if (!cJSON_IsObject(med_components)) { + ogs_error("OpenAPI_app_session_context_req_data_parseFromJSON() failed [med_components]"); + goto end; + } + med_componentsList = OpenAPI_list_create(); + OpenAPI_map_t *localMapKeyPair = NULL; + cJSON_ArrayForEach(med_components_local_map, med_components) { + cJSON *localMapObject = med_components_local_map; + if (!cJSON_IsObject(med_components_local_map)) { + ogs_error("OpenAPI_app_session_context_req_data_parseFromJSON() failed [med_components]"); + goto end; + } + localMapKeyPair = OpenAPI_map_create( + localMapObject->string, OpenAPI_media_component_parseFromJSON(localMapObject)); + OpenAPI_list_add(med_componentsList, localMapKeyPair); + } + } + + cJSON *ip_domain = cJSON_GetObjectItemCaseSensitive(app_session_context_req_dataJSON, "ipDomain"); + + if (ip_domain) { + if (!cJSON_IsString(ip_domain)) { + ogs_error("OpenAPI_app_session_context_req_data_parseFromJSON() failed [ip_domain]"); + goto end; + } + } + + cJSON *mps_id = cJSON_GetObjectItemCaseSensitive(app_session_context_req_dataJSON, "mpsId"); + + if (mps_id) { + if (!cJSON_IsString(mps_id)) { + ogs_error("OpenAPI_app_session_context_req_data_parseFromJSON() failed [mps_id]"); + goto end; + } + } + + cJSON *mcs_id = cJSON_GetObjectItemCaseSensitive(app_session_context_req_dataJSON, "mcsId"); + + if (mcs_id) { + if (!cJSON_IsString(mcs_id)) { + ogs_error("OpenAPI_app_session_context_req_data_parseFromJSON() failed [mcs_id]"); + goto end; + } + } + + cJSON *preempt_control_info = cJSON_GetObjectItemCaseSensitive(app_session_context_req_dataJSON, "preemptControlInfo"); + + OpenAPI_preemption_control_information_e preempt_control_infoVariable; + if (preempt_control_info) { + if (!cJSON_IsString(preempt_control_info)) { + ogs_error("OpenAPI_app_session_context_req_data_parseFromJSON() failed [preempt_control_info]"); + goto end; + } + preempt_control_infoVariable = OpenAPI_preemption_control_information_FromString(preempt_control_info->valuestring); + } + + cJSON *res_prio = cJSON_GetObjectItemCaseSensitive(app_session_context_req_dataJSON, "resPrio"); + + OpenAPI_reserv_priority_e res_prioVariable; + if (res_prio) { + if (!cJSON_IsString(res_prio)) { + ogs_error("OpenAPI_app_session_context_req_data_parseFromJSON() failed [res_prio]"); + goto end; + } + res_prioVariable = OpenAPI_reserv_priority_FromString(res_prio->valuestring); + } + + cJSON *serv_inf_status = cJSON_GetObjectItemCaseSensitive(app_session_context_req_dataJSON, "servInfStatus"); + + OpenAPI_service_info_status_e serv_inf_statusVariable; + if (serv_inf_status) { + if (!cJSON_IsString(serv_inf_status)) { + ogs_error("OpenAPI_app_session_context_req_data_parseFromJSON() failed [serv_inf_status]"); + goto end; + } + serv_inf_statusVariable = OpenAPI_service_info_status_FromString(serv_inf_status->valuestring); + } + + cJSON *notif_uri = cJSON_GetObjectItemCaseSensitive(app_session_context_req_dataJSON, "notifUri"); + if (!notif_uri) { + ogs_error("OpenAPI_app_session_context_req_data_parseFromJSON() failed [notif_uri]"); + goto end; + } + + + if (!cJSON_IsString(notif_uri)) { + ogs_error("OpenAPI_app_session_context_req_data_parseFromJSON() failed [notif_uri]"); + goto end; + } + + cJSON *serv_urn = cJSON_GetObjectItemCaseSensitive(app_session_context_req_dataJSON, "servUrn"); + + if (serv_urn) { + if (!cJSON_IsString(serv_urn)) { + ogs_error("OpenAPI_app_session_context_req_data_parseFromJSON() failed [serv_urn]"); + goto end; + } + } + + cJSON *slice_info = cJSON_GetObjectItemCaseSensitive(app_session_context_req_dataJSON, "sliceInfo"); + + OpenAPI_snssai_t *slice_info_local_nonprim = NULL; + if (slice_info) { + slice_info_local_nonprim = OpenAPI_snssai_parseFromJSON(slice_info); + } + + cJSON *spon_id = cJSON_GetObjectItemCaseSensitive(app_session_context_req_dataJSON, "sponId"); + + if (spon_id) { + if (!cJSON_IsString(spon_id)) { + ogs_error("OpenAPI_app_session_context_req_data_parseFromJSON() failed [spon_id]"); + goto end; + } + } + + cJSON *spon_status = cJSON_GetObjectItemCaseSensitive(app_session_context_req_dataJSON, "sponStatus"); + + OpenAPI_sponsoring_status_e spon_statusVariable; + if (spon_status) { + if (!cJSON_IsString(spon_status)) { + ogs_error("OpenAPI_app_session_context_req_data_parseFromJSON() failed [spon_status]"); + goto end; + } + spon_statusVariable = OpenAPI_sponsoring_status_FromString(spon_status->valuestring); + } + + cJSON *supi = cJSON_GetObjectItemCaseSensitive(app_session_context_req_dataJSON, "supi"); + + if (supi) { + if (!cJSON_IsString(supi)) { + ogs_error("OpenAPI_app_session_context_req_data_parseFromJSON() failed [supi]"); + goto end; + } + } + + cJSON *gpsi = cJSON_GetObjectItemCaseSensitive(app_session_context_req_dataJSON, "gpsi"); + + if (gpsi) { + if (!cJSON_IsString(gpsi)) { + ogs_error("OpenAPI_app_session_context_req_data_parseFromJSON() failed [gpsi]"); + goto end; + } + } + + cJSON *supp_feat = cJSON_GetObjectItemCaseSensitive(app_session_context_req_dataJSON, "suppFeat"); + if (!supp_feat) { + ogs_error("OpenAPI_app_session_context_req_data_parseFromJSON() failed [supp_feat]"); + goto end; + } + + + if (!cJSON_IsString(supp_feat)) { + ogs_error("OpenAPI_app_session_context_req_data_parseFromJSON() failed [supp_feat]"); + goto end; + } + + cJSON *ue_ipv4 = cJSON_GetObjectItemCaseSensitive(app_session_context_req_dataJSON, "ueIpv4"); + + if (ue_ipv4) { + if (!cJSON_IsString(ue_ipv4)) { + ogs_error("OpenAPI_app_session_context_req_data_parseFromJSON() failed [ue_ipv4]"); + goto end; + } + } + + cJSON *ue_ipv6 = cJSON_GetObjectItemCaseSensitive(app_session_context_req_dataJSON, "ueIpv6"); + + if (ue_ipv6) { + if (!cJSON_IsString(ue_ipv6)) { + ogs_error("OpenAPI_app_session_context_req_data_parseFromJSON() failed [ue_ipv6]"); + goto end; + } + } + + cJSON *ue_mac = cJSON_GetObjectItemCaseSensitive(app_session_context_req_dataJSON, "ueMac"); + + if (ue_mac) { + if (!cJSON_IsString(ue_mac)) { + ogs_error("OpenAPI_app_session_context_req_data_parseFromJSON() failed [ue_mac]"); + goto end; + } + } + + cJSON *tsn_port_man_cont_dstt = cJSON_GetObjectItemCaseSensitive(app_session_context_req_dataJSON, "tsnPortManContDstt"); + + OpenAPI_port_management_container_t *tsn_port_man_cont_dstt_local_nonprim = NULL; + if (tsn_port_man_cont_dstt) { + tsn_port_man_cont_dstt_local_nonprim = OpenAPI_port_management_container_parseFromJSON(tsn_port_man_cont_dstt); + } + + cJSON *tsn_port_man_cont_nwtts = cJSON_GetObjectItemCaseSensitive(app_session_context_req_dataJSON, "tsnPortManContNwtts"); + + OpenAPI_list_t *tsn_port_man_cont_nwttsList; + if (tsn_port_man_cont_nwtts) { + cJSON *tsn_port_man_cont_nwtts_local_nonprimitive; + if (!cJSON_IsArray(tsn_port_man_cont_nwtts)) { + ogs_error("OpenAPI_app_session_context_req_data_parseFromJSON() failed [tsn_port_man_cont_nwtts]"); + goto end; + } + + tsn_port_man_cont_nwttsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(tsn_port_man_cont_nwtts_local_nonprimitive, tsn_port_man_cont_nwtts ) { + if (!cJSON_IsObject(tsn_port_man_cont_nwtts_local_nonprimitive)) { + ogs_error("OpenAPI_app_session_context_req_data_parseFromJSON() failed [tsn_port_man_cont_nwtts]"); + goto end; + } + OpenAPI_port_management_container_t *tsn_port_man_cont_nwttsItem = OpenAPI_port_management_container_parseFromJSON(tsn_port_man_cont_nwtts_local_nonprimitive); + + OpenAPI_list_add(tsn_port_man_cont_nwttsList, tsn_port_man_cont_nwttsItem); + } + } + + app_session_context_req_data_local_var = OpenAPI_app_session_context_req_data_create ( + af_app_id ? ogs_strdup(af_app_id->valuestring) : NULL, + af_charg_id ? ogs_strdup(af_charg_id->valuestring) : NULL, + af_req_data ? af_req_dataVariable : 0, + af_rout_req ? af_rout_req_local_nonprim : NULL, + asp_id ? ogs_strdup(asp_id->valuestring) : NULL, + bdt_ref_id ? ogs_strdup(bdt_ref_id->valuestring) : NULL, + dnn ? ogs_strdup(dnn->valuestring) : NULL, + ev_subsc ? ev_subsc_local_nonprim : NULL, + mcptt_id ? ogs_strdup(mcptt_id->valuestring) : NULL, + mc_video_id ? ogs_strdup(mc_video_id->valuestring) : NULL, + med_components ? med_componentsList : NULL, + ip_domain ? ogs_strdup(ip_domain->valuestring) : NULL, + mps_id ? ogs_strdup(mps_id->valuestring) : NULL, + mcs_id ? ogs_strdup(mcs_id->valuestring) : NULL, + preempt_control_info ? preempt_control_infoVariable : 0, + res_prio ? res_prioVariable : 0, + serv_inf_status ? serv_inf_statusVariable : 0, + ogs_strdup(notif_uri->valuestring), + serv_urn ? ogs_strdup(serv_urn->valuestring) : NULL, + slice_info ? slice_info_local_nonprim : NULL, + spon_id ? ogs_strdup(spon_id->valuestring) : NULL, + spon_status ? spon_statusVariable : 0, + supi ? ogs_strdup(supi->valuestring) : NULL, + gpsi ? ogs_strdup(gpsi->valuestring) : NULL, + ogs_strdup(supp_feat->valuestring), + ue_ipv4 ? ogs_strdup(ue_ipv4->valuestring) : NULL, + ue_ipv6 ? ogs_strdup(ue_ipv6->valuestring) : NULL, + ue_mac ? ogs_strdup(ue_mac->valuestring) : NULL, + tsn_port_man_cont_dstt ? tsn_port_man_cont_dstt_local_nonprim : NULL, + tsn_port_man_cont_nwtts ? tsn_port_man_cont_nwttsList : NULL + ); + + return app_session_context_req_data_local_var; +end: + return NULL; +} + +OpenAPI_app_session_context_req_data_t *OpenAPI_app_session_context_req_data_copy(OpenAPI_app_session_context_req_data_t *dst, OpenAPI_app_session_context_req_data_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_app_session_context_req_data_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_app_session_context_req_data_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_app_session_context_req_data_free(dst); + dst = OpenAPI_app_session_context_req_data_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/app_session_context_req_data.h b/lib/sbi/openapi/model/app_session_context_req_data.h new file mode 100644 index 000000000..054888f02 --- /dev/null +++ b/lib/sbi/openapi/model/app_session_context_req_data.h @@ -0,0 +1,106 @@ +/* + * app_session_context_req_data.h + * + * Identifies the service requirements of an Individual Application Session Context. + */ + +#ifndef _OpenAPI_app_session_context_req_data_H_ +#define _OpenAPI_app_session_context_req_data_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" +#include "af_requested_data.h" +#include "af_routing_requirement.h" +#include "events_subsc_req_data.h" +#include "media_component.h" +#include "port_management_container.h" +#include "preemption_control_information.h" +#include "reserv_priority.h" +#include "service_info_status.h" +#include "snssai.h" +#include "sponsoring_status.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_app_session_context_req_data_s OpenAPI_app_session_context_req_data_t; +typedef struct OpenAPI_app_session_context_req_data_s { + char *af_app_id; + char *af_charg_id; + OpenAPI_af_requested_data_e af_req_data; + struct OpenAPI_af_routing_requirement_s *af_rout_req; + char *asp_id; + char *bdt_ref_id; + char *dnn; + struct OpenAPI_events_subsc_req_data_s *ev_subsc; + char *mcptt_id; + char *mc_video_id; + OpenAPI_list_t* med_components; + char *ip_domain; + char *mps_id; + char *mcs_id; + OpenAPI_preemption_control_information_e preempt_control_info; + OpenAPI_reserv_priority_e res_prio; + OpenAPI_service_info_status_e serv_inf_status; + char *notif_uri; + char *serv_urn; + struct OpenAPI_snssai_s *slice_info; + char *spon_id; + OpenAPI_sponsoring_status_e spon_status; + char *supi; + char *gpsi; + char *supp_feat; + char *ue_ipv4; + char *ue_ipv6; + char *ue_mac; + struct OpenAPI_port_management_container_s *tsn_port_man_cont_dstt; + OpenAPI_list_t *tsn_port_man_cont_nwtts; +} OpenAPI_app_session_context_req_data_t; + +OpenAPI_app_session_context_req_data_t *OpenAPI_app_session_context_req_data_create( + char *af_app_id, + char *af_charg_id, + OpenAPI_af_requested_data_e af_req_data, + OpenAPI_af_routing_requirement_t *af_rout_req, + char *asp_id, + char *bdt_ref_id, + char *dnn, + OpenAPI_events_subsc_req_data_t *ev_subsc, + char *mcptt_id, + char *mc_video_id, + OpenAPI_list_t* med_components, + char *ip_domain, + char *mps_id, + char *mcs_id, + OpenAPI_preemption_control_information_e preempt_control_info, + OpenAPI_reserv_priority_e res_prio, + OpenAPI_service_info_status_e serv_inf_status, + char *notif_uri, + char *serv_urn, + OpenAPI_snssai_t *slice_info, + char *spon_id, + OpenAPI_sponsoring_status_e spon_status, + char *supi, + char *gpsi, + char *supp_feat, + char *ue_ipv4, + char *ue_ipv6, + char *ue_mac, + OpenAPI_port_management_container_t *tsn_port_man_cont_dstt, + OpenAPI_list_t *tsn_port_man_cont_nwtts + ); +void OpenAPI_app_session_context_req_data_free(OpenAPI_app_session_context_req_data_t *app_session_context_req_data); +OpenAPI_app_session_context_req_data_t *OpenAPI_app_session_context_req_data_parseFromJSON(cJSON *app_session_context_req_dataJSON); +cJSON *OpenAPI_app_session_context_req_data_convertToJSON(OpenAPI_app_session_context_req_data_t *app_session_context_req_data); +OpenAPI_app_session_context_req_data_t *OpenAPI_app_session_context_req_data_copy(OpenAPI_app_session_context_req_data_t *dst, OpenAPI_app_session_context_req_data_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_app_session_context_req_data_H_ */ + diff --git a/lib/sbi/openapi/model/app_session_context_resp_data.c b/lib/sbi/openapi/model/app_session_context_resp_data.c new file mode 100644 index 000000000..1bc076c7f --- /dev/null +++ b/lib/sbi/openapi/model/app_session_context_resp_data.c @@ -0,0 +1,176 @@ + +#include +#include +#include +#include "app_session_context_resp_data.h" + +OpenAPI_app_session_context_resp_data_t *OpenAPI_app_session_context_resp_data_create( + OpenAPI_serv_auth_info_e serv_auth_info, + OpenAPI_list_t *ue_ids, + char *supp_feat + ) +{ + OpenAPI_app_session_context_resp_data_t *app_session_context_resp_data_local_var = OpenAPI_malloc(sizeof(OpenAPI_app_session_context_resp_data_t)); + if (!app_session_context_resp_data_local_var) { + return NULL; + } + app_session_context_resp_data_local_var->serv_auth_info = serv_auth_info; + app_session_context_resp_data_local_var->ue_ids = ue_ids; + app_session_context_resp_data_local_var->supp_feat = supp_feat; + + return app_session_context_resp_data_local_var; +} + +void OpenAPI_app_session_context_resp_data_free(OpenAPI_app_session_context_resp_data_t *app_session_context_resp_data) +{ + if (NULL == app_session_context_resp_data) { + return; + } + OpenAPI_lnode_t *node; + OpenAPI_list_for_each(app_session_context_resp_data->ue_ids, node) { + OpenAPI_ue_identity_info_free(node->data); + } + OpenAPI_list_free(app_session_context_resp_data->ue_ids); + ogs_free(app_session_context_resp_data->supp_feat); + ogs_free(app_session_context_resp_data); +} + +cJSON *OpenAPI_app_session_context_resp_data_convertToJSON(OpenAPI_app_session_context_resp_data_t *app_session_context_resp_data) +{ + cJSON *item = NULL; + + if (app_session_context_resp_data == NULL) { + ogs_error("OpenAPI_app_session_context_resp_data_convertToJSON() failed [AppSessionContextRespData]"); + return NULL; + } + + item = cJSON_CreateObject(); + if (app_session_context_resp_data->serv_auth_info) { + if (cJSON_AddStringToObject(item, "servAuthInfo", OpenAPI_serv_auth_info_ToString(app_session_context_resp_data->serv_auth_info)) == NULL) { + ogs_error("OpenAPI_app_session_context_resp_data_convertToJSON() failed [serv_auth_info]"); + goto end; + } + } + + if (app_session_context_resp_data->ue_ids) { + cJSON *ue_idsList = cJSON_AddArrayToObject(item, "ueIds"); + if (ue_idsList == NULL) { + ogs_error("OpenAPI_app_session_context_resp_data_convertToJSON() failed [ue_ids]"); + goto end; + } + + OpenAPI_lnode_t *ue_ids_node; + if (app_session_context_resp_data->ue_ids) { + OpenAPI_list_for_each(app_session_context_resp_data->ue_ids, ue_ids_node) { + cJSON *itemLocal = OpenAPI_ue_identity_info_convertToJSON(ue_ids_node->data); + if (itemLocal == NULL) { + ogs_error("OpenAPI_app_session_context_resp_data_convertToJSON() failed [ue_ids]"); + goto end; + } + cJSON_AddItemToArray(ue_idsList, itemLocal); + } + } + } + + if (app_session_context_resp_data->supp_feat) { + if (cJSON_AddStringToObject(item, "suppFeat", app_session_context_resp_data->supp_feat) == NULL) { + ogs_error("OpenAPI_app_session_context_resp_data_convertToJSON() failed [supp_feat]"); + goto end; + } + } + +end: + return item; +} + +OpenAPI_app_session_context_resp_data_t *OpenAPI_app_session_context_resp_data_parseFromJSON(cJSON *app_session_context_resp_dataJSON) +{ + OpenAPI_app_session_context_resp_data_t *app_session_context_resp_data_local_var = NULL; + cJSON *serv_auth_info = cJSON_GetObjectItemCaseSensitive(app_session_context_resp_dataJSON, "servAuthInfo"); + + OpenAPI_serv_auth_info_e serv_auth_infoVariable; + if (serv_auth_info) { + if (!cJSON_IsString(serv_auth_info)) { + ogs_error("OpenAPI_app_session_context_resp_data_parseFromJSON() failed [serv_auth_info]"); + goto end; + } + serv_auth_infoVariable = OpenAPI_serv_auth_info_FromString(serv_auth_info->valuestring); + } + + cJSON *ue_ids = cJSON_GetObjectItemCaseSensitive(app_session_context_resp_dataJSON, "ueIds"); + + OpenAPI_list_t *ue_idsList; + if (ue_ids) { + cJSON *ue_ids_local_nonprimitive; + if (!cJSON_IsArray(ue_ids)) { + ogs_error("OpenAPI_app_session_context_resp_data_parseFromJSON() failed [ue_ids]"); + goto end; + } + + ue_idsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(ue_ids_local_nonprimitive, ue_ids ) { + if (!cJSON_IsObject(ue_ids_local_nonprimitive)) { + ogs_error("OpenAPI_app_session_context_resp_data_parseFromJSON() failed [ue_ids]"); + goto end; + } + OpenAPI_ue_identity_info_t *ue_idsItem = OpenAPI_ue_identity_info_parseFromJSON(ue_ids_local_nonprimitive); + + OpenAPI_list_add(ue_idsList, ue_idsItem); + } + } + + cJSON *supp_feat = cJSON_GetObjectItemCaseSensitive(app_session_context_resp_dataJSON, "suppFeat"); + + if (supp_feat) { + if (!cJSON_IsString(supp_feat)) { + ogs_error("OpenAPI_app_session_context_resp_data_parseFromJSON() failed [supp_feat]"); + goto end; + } + } + + app_session_context_resp_data_local_var = OpenAPI_app_session_context_resp_data_create ( + serv_auth_info ? serv_auth_infoVariable : 0, + ue_ids ? ue_idsList : NULL, + supp_feat ? ogs_strdup(supp_feat->valuestring) : NULL + ); + + return app_session_context_resp_data_local_var; +end: + return NULL; +} + +OpenAPI_app_session_context_resp_data_t *OpenAPI_app_session_context_resp_data_copy(OpenAPI_app_session_context_resp_data_t *dst, OpenAPI_app_session_context_resp_data_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_app_session_context_resp_data_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_app_session_context_resp_data_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_app_session_context_resp_data_free(dst); + dst = OpenAPI_app_session_context_resp_data_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/app_session_context_resp_data.h b/lib/sbi/openapi/model/app_session_context_resp_data.h new file mode 100644 index 000000000..377a43fb5 --- /dev/null +++ b/lib/sbi/openapi/model/app_session_context_resp_data.h @@ -0,0 +1,44 @@ +/* + * app_session_context_resp_data.h + * + * Describes the authorization data of an Individual Application Session Context created by the PCF. + */ + +#ifndef _OpenAPI_app_session_context_resp_data_H_ +#define _OpenAPI_app_session_context_resp_data_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" +#include "serv_auth_info.h" +#include "ue_identity_info.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_app_session_context_resp_data_s OpenAPI_app_session_context_resp_data_t; +typedef struct OpenAPI_app_session_context_resp_data_s { + OpenAPI_serv_auth_info_e serv_auth_info; + OpenAPI_list_t *ue_ids; + char *supp_feat; +} OpenAPI_app_session_context_resp_data_t; + +OpenAPI_app_session_context_resp_data_t *OpenAPI_app_session_context_resp_data_create( + OpenAPI_serv_auth_info_e serv_auth_info, + OpenAPI_list_t *ue_ids, + char *supp_feat + ); +void OpenAPI_app_session_context_resp_data_free(OpenAPI_app_session_context_resp_data_t *app_session_context_resp_data); +OpenAPI_app_session_context_resp_data_t *OpenAPI_app_session_context_resp_data_parseFromJSON(cJSON *app_session_context_resp_dataJSON); +cJSON *OpenAPI_app_session_context_resp_data_convertToJSON(OpenAPI_app_session_context_resp_data_t *app_session_context_resp_data); +OpenAPI_app_session_context_resp_data_t *OpenAPI_app_session_context_resp_data_copy(OpenAPI_app_session_context_resp_data_t *dst, OpenAPI_app_session_context_resp_data_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_app_session_context_resp_data_H_ */ + diff --git a/lib/sbi/openapi/model/app_session_context_update_data.c b/lib/sbi/openapi/model/app_session_context_update_data.c new file mode 100644 index 000000000..a875fe83d --- /dev/null +++ b/lib/sbi/openapi/model/app_session_context_update_data.c @@ -0,0 +1,528 @@ + +#include +#include +#include +#include "app_session_context_update_data.h" + +OpenAPI_app_session_context_update_data_t *OpenAPI_app_session_context_update_data_create( + char *af_app_id, + OpenAPI_af_routing_requirement_rm_t *af_rout_req, + char *asp_id, + char *bdt_ref_id, + OpenAPI_events_subsc_req_data_rm_t *ev_subsc, + char *mcptt_id, + char *mc_video_id, + OpenAPI_list_t* med_components, + char *mps_id, + char *mcs_id, + OpenAPI_preemption_control_information_rm_t *preempt_control_info, + OpenAPI_reserv_priority_e res_prio, + OpenAPI_service_info_status_e serv_inf_status, + OpenAPI_sip_forking_indication_e sip_fork_ind, + char *spon_id, + OpenAPI_sponsoring_status_e spon_status, + OpenAPI_port_management_container_t *tsn_port_man_cont_dstt, + OpenAPI_list_t *tsn_port_man_cont_nwtts + ) +{ + OpenAPI_app_session_context_update_data_t *app_session_context_update_data_local_var = OpenAPI_malloc(sizeof(OpenAPI_app_session_context_update_data_t)); + if (!app_session_context_update_data_local_var) { + return NULL; + } + app_session_context_update_data_local_var->af_app_id = af_app_id; + app_session_context_update_data_local_var->af_rout_req = af_rout_req; + app_session_context_update_data_local_var->asp_id = asp_id; + app_session_context_update_data_local_var->bdt_ref_id = bdt_ref_id; + app_session_context_update_data_local_var->ev_subsc = ev_subsc; + app_session_context_update_data_local_var->mcptt_id = mcptt_id; + app_session_context_update_data_local_var->mc_video_id = mc_video_id; + app_session_context_update_data_local_var->med_components = med_components; + app_session_context_update_data_local_var->mps_id = mps_id; + app_session_context_update_data_local_var->mcs_id = mcs_id; + app_session_context_update_data_local_var->preempt_control_info = preempt_control_info; + app_session_context_update_data_local_var->res_prio = res_prio; + app_session_context_update_data_local_var->serv_inf_status = serv_inf_status; + app_session_context_update_data_local_var->sip_fork_ind = sip_fork_ind; + app_session_context_update_data_local_var->spon_id = spon_id; + app_session_context_update_data_local_var->spon_status = spon_status; + app_session_context_update_data_local_var->tsn_port_man_cont_dstt = tsn_port_man_cont_dstt; + app_session_context_update_data_local_var->tsn_port_man_cont_nwtts = tsn_port_man_cont_nwtts; + + return app_session_context_update_data_local_var; +} + +void OpenAPI_app_session_context_update_data_free(OpenAPI_app_session_context_update_data_t *app_session_context_update_data) +{ + if (NULL == app_session_context_update_data) { + return; + } + OpenAPI_lnode_t *node; + ogs_free(app_session_context_update_data->af_app_id); + OpenAPI_af_routing_requirement_rm_free(app_session_context_update_data->af_rout_req); + ogs_free(app_session_context_update_data->asp_id); + ogs_free(app_session_context_update_data->bdt_ref_id); + OpenAPI_events_subsc_req_data_rm_free(app_session_context_update_data->ev_subsc); + ogs_free(app_session_context_update_data->mcptt_id); + ogs_free(app_session_context_update_data->mc_video_id); + OpenAPI_list_for_each(app_session_context_update_data->med_components, node) { + OpenAPI_map_t *localKeyValue = (OpenAPI_map_t*)node->data; + OpenAPI_media_component_rm_free(localKeyValue->value); + ogs_free(localKeyValue); + } + OpenAPI_list_free(app_session_context_update_data->med_components); + ogs_free(app_session_context_update_data->mps_id); + ogs_free(app_session_context_update_data->mcs_id); + OpenAPI_preemption_control_information_rm_free(app_session_context_update_data->preempt_control_info); + ogs_free(app_session_context_update_data->spon_id); + OpenAPI_port_management_container_free(app_session_context_update_data->tsn_port_man_cont_dstt); + OpenAPI_list_for_each(app_session_context_update_data->tsn_port_man_cont_nwtts, node) { + OpenAPI_port_management_container_free(node->data); + } + OpenAPI_list_free(app_session_context_update_data->tsn_port_man_cont_nwtts); + ogs_free(app_session_context_update_data); +} + +cJSON *OpenAPI_app_session_context_update_data_convertToJSON(OpenAPI_app_session_context_update_data_t *app_session_context_update_data) +{ + cJSON *item = NULL; + + if (app_session_context_update_data == NULL) { + ogs_error("OpenAPI_app_session_context_update_data_convertToJSON() failed [AppSessionContextUpdateData]"); + return NULL; + } + + item = cJSON_CreateObject(); + if (app_session_context_update_data->af_app_id) { + if (cJSON_AddStringToObject(item, "afAppId", app_session_context_update_data->af_app_id) == NULL) { + ogs_error("OpenAPI_app_session_context_update_data_convertToJSON() failed [af_app_id]"); + goto end; + } + } + + if (app_session_context_update_data->af_rout_req) { + cJSON *af_rout_req_local_JSON = OpenAPI_af_routing_requirement_rm_convertToJSON(app_session_context_update_data->af_rout_req); + if (af_rout_req_local_JSON == NULL) { + ogs_error("OpenAPI_app_session_context_update_data_convertToJSON() failed [af_rout_req]"); + goto end; + } + cJSON_AddItemToObject(item, "afRoutReq", af_rout_req_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_app_session_context_update_data_convertToJSON() failed [af_rout_req]"); + goto end; + } + } + + if (app_session_context_update_data->asp_id) { + if (cJSON_AddStringToObject(item, "aspId", app_session_context_update_data->asp_id) == NULL) { + ogs_error("OpenAPI_app_session_context_update_data_convertToJSON() failed [asp_id]"); + goto end; + } + } + + if (app_session_context_update_data->bdt_ref_id) { + if (cJSON_AddStringToObject(item, "bdtRefId", app_session_context_update_data->bdt_ref_id) == NULL) { + ogs_error("OpenAPI_app_session_context_update_data_convertToJSON() failed [bdt_ref_id]"); + goto end; + } + } + + if (app_session_context_update_data->ev_subsc) { + cJSON *ev_subsc_local_JSON = OpenAPI_events_subsc_req_data_rm_convertToJSON(app_session_context_update_data->ev_subsc); + if (ev_subsc_local_JSON == NULL) { + ogs_error("OpenAPI_app_session_context_update_data_convertToJSON() failed [ev_subsc]"); + goto end; + } + cJSON_AddItemToObject(item, "evSubsc", ev_subsc_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_app_session_context_update_data_convertToJSON() failed [ev_subsc]"); + goto end; + } + } + + if (app_session_context_update_data->mcptt_id) { + if (cJSON_AddStringToObject(item, "mcpttId", app_session_context_update_data->mcptt_id) == NULL) { + ogs_error("OpenAPI_app_session_context_update_data_convertToJSON() failed [mcptt_id]"); + goto end; + } + } + + if (app_session_context_update_data->mc_video_id) { + if (cJSON_AddStringToObject(item, "mcVideoId", app_session_context_update_data->mc_video_id) == NULL) { + ogs_error("OpenAPI_app_session_context_update_data_convertToJSON() failed [mc_video_id]"); + goto end; + } + } + + if (app_session_context_update_data->med_components) { + cJSON *med_components = cJSON_AddObjectToObject(item, "medComponents"); + if (med_components == NULL) { + ogs_error("OpenAPI_app_session_context_update_data_convertToJSON() failed [med_components]"); + goto end; + } + cJSON *localMapObject = med_components; + OpenAPI_lnode_t *med_components_node; + if (app_session_context_update_data->med_components) { + OpenAPI_list_for_each(app_session_context_update_data->med_components, med_components_node) { + OpenAPI_map_t *localKeyValue = (OpenAPI_map_t*)med_components_node->data; + cJSON *itemLocal = OpenAPI_media_component_rm_convertToJSON(localKeyValue->value); + if (itemLocal == NULL) { + ogs_error("OpenAPI_app_session_context_update_data_convertToJSON() failed [med_components]"); + goto end; + } + cJSON_AddItemToObject(med_components, localKeyValue->key, itemLocal); + } + } + } + + if (app_session_context_update_data->mps_id) { + if (cJSON_AddStringToObject(item, "mpsId", app_session_context_update_data->mps_id) == NULL) { + ogs_error("OpenAPI_app_session_context_update_data_convertToJSON() failed [mps_id]"); + goto end; + } + } + + if (app_session_context_update_data->mcs_id) { + if (cJSON_AddStringToObject(item, "mcsId", app_session_context_update_data->mcs_id) == NULL) { + ogs_error("OpenAPI_app_session_context_update_data_convertToJSON() failed [mcs_id]"); + goto end; + } + } + + if (app_session_context_update_data->preempt_control_info) { + cJSON *preempt_control_info_local_JSON = OpenAPI_preemption_control_information_rm_convertToJSON(app_session_context_update_data->preempt_control_info); + if (preempt_control_info_local_JSON == NULL) { + ogs_error("OpenAPI_app_session_context_update_data_convertToJSON() failed [preempt_control_info]"); + goto end; + } + cJSON_AddItemToObject(item, "preemptControlInfo", preempt_control_info_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_app_session_context_update_data_convertToJSON() failed [preempt_control_info]"); + goto end; + } + } + + if (app_session_context_update_data->res_prio) { + if (cJSON_AddStringToObject(item, "resPrio", OpenAPI_reserv_priority_ToString(app_session_context_update_data->res_prio)) == NULL) { + ogs_error("OpenAPI_app_session_context_update_data_convertToJSON() failed [res_prio]"); + goto end; + } + } + + if (app_session_context_update_data->serv_inf_status) { + if (cJSON_AddStringToObject(item, "servInfStatus", OpenAPI_service_info_status_ToString(app_session_context_update_data->serv_inf_status)) == NULL) { + ogs_error("OpenAPI_app_session_context_update_data_convertToJSON() failed [serv_inf_status]"); + goto end; + } + } + + if (app_session_context_update_data->sip_fork_ind) { + if (cJSON_AddStringToObject(item, "sipForkInd", OpenAPI_sip_forking_indication_ToString(app_session_context_update_data->sip_fork_ind)) == NULL) { + ogs_error("OpenAPI_app_session_context_update_data_convertToJSON() failed [sip_fork_ind]"); + goto end; + } + } + + if (app_session_context_update_data->spon_id) { + if (cJSON_AddStringToObject(item, "sponId", app_session_context_update_data->spon_id) == NULL) { + ogs_error("OpenAPI_app_session_context_update_data_convertToJSON() failed [spon_id]"); + goto end; + } + } + + if (app_session_context_update_data->spon_status) { + if (cJSON_AddStringToObject(item, "sponStatus", OpenAPI_sponsoring_status_ToString(app_session_context_update_data->spon_status)) == NULL) { + ogs_error("OpenAPI_app_session_context_update_data_convertToJSON() failed [spon_status]"); + goto end; + } + } + + if (app_session_context_update_data->tsn_port_man_cont_dstt) { + cJSON *tsn_port_man_cont_dstt_local_JSON = OpenAPI_port_management_container_convertToJSON(app_session_context_update_data->tsn_port_man_cont_dstt); + if (tsn_port_man_cont_dstt_local_JSON == NULL) { + ogs_error("OpenAPI_app_session_context_update_data_convertToJSON() failed [tsn_port_man_cont_dstt]"); + goto end; + } + cJSON_AddItemToObject(item, "tsnPortManContDstt", tsn_port_man_cont_dstt_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_app_session_context_update_data_convertToJSON() failed [tsn_port_man_cont_dstt]"); + goto end; + } + } + + if (app_session_context_update_data->tsn_port_man_cont_nwtts) { + cJSON *tsn_port_man_cont_nwttsList = cJSON_AddArrayToObject(item, "tsnPortManContNwtts"); + if (tsn_port_man_cont_nwttsList == NULL) { + ogs_error("OpenAPI_app_session_context_update_data_convertToJSON() failed [tsn_port_man_cont_nwtts]"); + goto end; + } + + OpenAPI_lnode_t *tsn_port_man_cont_nwtts_node; + if (app_session_context_update_data->tsn_port_man_cont_nwtts) { + OpenAPI_list_for_each(app_session_context_update_data->tsn_port_man_cont_nwtts, tsn_port_man_cont_nwtts_node) { + cJSON *itemLocal = OpenAPI_port_management_container_convertToJSON(tsn_port_man_cont_nwtts_node->data); + if (itemLocal == NULL) { + ogs_error("OpenAPI_app_session_context_update_data_convertToJSON() failed [tsn_port_man_cont_nwtts]"); + goto end; + } + cJSON_AddItemToArray(tsn_port_man_cont_nwttsList, itemLocal); + } + } + } + +end: + return item; +} + +OpenAPI_app_session_context_update_data_t *OpenAPI_app_session_context_update_data_parseFromJSON(cJSON *app_session_context_update_dataJSON) +{ + OpenAPI_app_session_context_update_data_t *app_session_context_update_data_local_var = NULL; + cJSON *af_app_id = cJSON_GetObjectItemCaseSensitive(app_session_context_update_dataJSON, "afAppId"); + + if (af_app_id) { + if (!cJSON_IsString(af_app_id)) { + ogs_error("OpenAPI_app_session_context_update_data_parseFromJSON() failed [af_app_id]"); + goto end; + } + } + + cJSON *af_rout_req = cJSON_GetObjectItemCaseSensitive(app_session_context_update_dataJSON, "afRoutReq"); + + OpenAPI_af_routing_requirement_rm_t *af_rout_req_local_nonprim = NULL; + if (af_rout_req) { + af_rout_req_local_nonprim = OpenAPI_af_routing_requirement_rm_parseFromJSON(af_rout_req); + } + + cJSON *asp_id = cJSON_GetObjectItemCaseSensitive(app_session_context_update_dataJSON, "aspId"); + + if (asp_id) { + if (!cJSON_IsString(asp_id)) { + ogs_error("OpenAPI_app_session_context_update_data_parseFromJSON() failed [asp_id]"); + goto end; + } + } + + cJSON *bdt_ref_id = cJSON_GetObjectItemCaseSensitive(app_session_context_update_dataJSON, "bdtRefId"); + + if (bdt_ref_id) { + if (!cJSON_IsString(bdt_ref_id)) { + ogs_error("OpenAPI_app_session_context_update_data_parseFromJSON() failed [bdt_ref_id]"); + goto end; + } + } + + cJSON *ev_subsc = cJSON_GetObjectItemCaseSensitive(app_session_context_update_dataJSON, "evSubsc"); + + OpenAPI_events_subsc_req_data_rm_t *ev_subsc_local_nonprim = NULL; + if (ev_subsc) { + ev_subsc_local_nonprim = OpenAPI_events_subsc_req_data_rm_parseFromJSON(ev_subsc); + } + + cJSON *mcptt_id = cJSON_GetObjectItemCaseSensitive(app_session_context_update_dataJSON, "mcpttId"); + + if (mcptt_id) { + if (!cJSON_IsString(mcptt_id)) { + ogs_error("OpenAPI_app_session_context_update_data_parseFromJSON() failed [mcptt_id]"); + goto end; + } + } + + cJSON *mc_video_id = cJSON_GetObjectItemCaseSensitive(app_session_context_update_dataJSON, "mcVideoId"); + + if (mc_video_id) { + if (!cJSON_IsString(mc_video_id)) { + ogs_error("OpenAPI_app_session_context_update_data_parseFromJSON() failed [mc_video_id]"); + goto end; + } + } + + cJSON *med_components = cJSON_GetObjectItemCaseSensitive(app_session_context_update_dataJSON, "medComponents"); + + OpenAPI_list_t *med_componentsList; + if (med_components) { + cJSON *med_components_local_map; + if (!cJSON_IsObject(med_components)) { + ogs_error("OpenAPI_app_session_context_update_data_parseFromJSON() failed [med_components]"); + goto end; + } + med_componentsList = OpenAPI_list_create(); + OpenAPI_map_t *localMapKeyPair = NULL; + cJSON_ArrayForEach(med_components_local_map, med_components) { + cJSON *localMapObject = med_components_local_map; + if (!cJSON_IsObject(med_components_local_map)) { + ogs_error("OpenAPI_app_session_context_update_data_parseFromJSON() failed [med_components]"); + goto end; + } + localMapKeyPair = OpenAPI_map_create( + localMapObject->string, OpenAPI_media_component_rm_parseFromJSON(localMapObject)); + OpenAPI_list_add(med_componentsList, localMapKeyPair); + } + } + + cJSON *mps_id = cJSON_GetObjectItemCaseSensitive(app_session_context_update_dataJSON, "mpsId"); + + if (mps_id) { + if (!cJSON_IsString(mps_id)) { + ogs_error("OpenAPI_app_session_context_update_data_parseFromJSON() failed [mps_id]"); + goto end; + } + } + + cJSON *mcs_id = cJSON_GetObjectItemCaseSensitive(app_session_context_update_dataJSON, "mcsId"); + + if (mcs_id) { + if (!cJSON_IsString(mcs_id)) { + ogs_error("OpenAPI_app_session_context_update_data_parseFromJSON() failed [mcs_id]"); + goto end; + } + } + + cJSON *preempt_control_info = cJSON_GetObjectItemCaseSensitive(app_session_context_update_dataJSON, "preemptControlInfo"); + + OpenAPI_preemption_control_information_rm_t *preempt_control_info_local_nonprim = NULL; + if (preempt_control_info) { + preempt_control_info_local_nonprim = OpenAPI_preemption_control_information_rm_parseFromJSON(preempt_control_info); + } + + cJSON *res_prio = cJSON_GetObjectItemCaseSensitive(app_session_context_update_dataJSON, "resPrio"); + + OpenAPI_reserv_priority_e res_prioVariable; + if (res_prio) { + if (!cJSON_IsString(res_prio)) { + ogs_error("OpenAPI_app_session_context_update_data_parseFromJSON() failed [res_prio]"); + goto end; + } + res_prioVariable = OpenAPI_reserv_priority_FromString(res_prio->valuestring); + } + + cJSON *serv_inf_status = cJSON_GetObjectItemCaseSensitive(app_session_context_update_dataJSON, "servInfStatus"); + + OpenAPI_service_info_status_e serv_inf_statusVariable; + if (serv_inf_status) { + if (!cJSON_IsString(serv_inf_status)) { + ogs_error("OpenAPI_app_session_context_update_data_parseFromJSON() failed [serv_inf_status]"); + goto end; + } + serv_inf_statusVariable = OpenAPI_service_info_status_FromString(serv_inf_status->valuestring); + } + + cJSON *sip_fork_ind = cJSON_GetObjectItemCaseSensitive(app_session_context_update_dataJSON, "sipForkInd"); + + OpenAPI_sip_forking_indication_e sip_fork_indVariable; + if (sip_fork_ind) { + if (!cJSON_IsString(sip_fork_ind)) { + ogs_error("OpenAPI_app_session_context_update_data_parseFromJSON() failed [sip_fork_ind]"); + goto end; + } + sip_fork_indVariable = OpenAPI_sip_forking_indication_FromString(sip_fork_ind->valuestring); + } + + cJSON *spon_id = cJSON_GetObjectItemCaseSensitive(app_session_context_update_dataJSON, "sponId"); + + if (spon_id) { + if (!cJSON_IsString(spon_id)) { + ogs_error("OpenAPI_app_session_context_update_data_parseFromJSON() failed [spon_id]"); + goto end; + } + } + + cJSON *spon_status = cJSON_GetObjectItemCaseSensitive(app_session_context_update_dataJSON, "sponStatus"); + + OpenAPI_sponsoring_status_e spon_statusVariable; + if (spon_status) { + if (!cJSON_IsString(spon_status)) { + ogs_error("OpenAPI_app_session_context_update_data_parseFromJSON() failed [spon_status]"); + goto end; + } + spon_statusVariable = OpenAPI_sponsoring_status_FromString(spon_status->valuestring); + } + + cJSON *tsn_port_man_cont_dstt = cJSON_GetObjectItemCaseSensitive(app_session_context_update_dataJSON, "tsnPortManContDstt"); + + OpenAPI_port_management_container_t *tsn_port_man_cont_dstt_local_nonprim = NULL; + if (tsn_port_man_cont_dstt) { + tsn_port_man_cont_dstt_local_nonprim = OpenAPI_port_management_container_parseFromJSON(tsn_port_man_cont_dstt); + } + + cJSON *tsn_port_man_cont_nwtts = cJSON_GetObjectItemCaseSensitive(app_session_context_update_dataJSON, "tsnPortManContNwtts"); + + OpenAPI_list_t *tsn_port_man_cont_nwttsList; + if (tsn_port_man_cont_nwtts) { + cJSON *tsn_port_man_cont_nwtts_local_nonprimitive; + if (!cJSON_IsArray(tsn_port_man_cont_nwtts)) { + ogs_error("OpenAPI_app_session_context_update_data_parseFromJSON() failed [tsn_port_man_cont_nwtts]"); + goto end; + } + + tsn_port_man_cont_nwttsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(tsn_port_man_cont_nwtts_local_nonprimitive, tsn_port_man_cont_nwtts ) { + if (!cJSON_IsObject(tsn_port_man_cont_nwtts_local_nonprimitive)) { + ogs_error("OpenAPI_app_session_context_update_data_parseFromJSON() failed [tsn_port_man_cont_nwtts]"); + goto end; + } + OpenAPI_port_management_container_t *tsn_port_man_cont_nwttsItem = OpenAPI_port_management_container_parseFromJSON(tsn_port_man_cont_nwtts_local_nonprimitive); + + OpenAPI_list_add(tsn_port_man_cont_nwttsList, tsn_port_man_cont_nwttsItem); + } + } + + app_session_context_update_data_local_var = OpenAPI_app_session_context_update_data_create ( + af_app_id ? ogs_strdup(af_app_id->valuestring) : NULL, + af_rout_req ? af_rout_req_local_nonprim : NULL, + asp_id ? ogs_strdup(asp_id->valuestring) : NULL, + bdt_ref_id ? ogs_strdup(bdt_ref_id->valuestring) : NULL, + ev_subsc ? ev_subsc_local_nonprim : NULL, + mcptt_id ? ogs_strdup(mcptt_id->valuestring) : NULL, + mc_video_id ? ogs_strdup(mc_video_id->valuestring) : NULL, + med_components ? med_componentsList : NULL, + mps_id ? ogs_strdup(mps_id->valuestring) : NULL, + mcs_id ? ogs_strdup(mcs_id->valuestring) : NULL, + preempt_control_info ? preempt_control_info_local_nonprim : NULL, + res_prio ? res_prioVariable : 0, + serv_inf_status ? serv_inf_statusVariable : 0, + sip_fork_ind ? sip_fork_indVariable : 0, + spon_id ? ogs_strdup(spon_id->valuestring) : NULL, + spon_status ? spon_statusVariable : 0, + tsn_port_man_cont_dstt ? tsn_port_man_cont_dstt_local_nonprim : NULL, + tsn_port_man_cont_nwtts ? tsn_port_man_cont_nwttsList : NULL + ); + + return app_session_context_update_data_local_var; +end: + return NULL; +} + +OpenAPI_app_session_context_update_data_t *OpenAPI_app_session_context_update_data_copy(OpenAPI_app_session_context_update_data_t *dst, OpenAPI_app_session_context_update_data_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_app_session_context_update_data_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_app_session_context_update_data_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_app_session_context_update_data_free(dst); + dst = OpenAPI_app_session_context_update_data_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/app_session_context_update_data.h b/lib/sbi/openapi/model/app_session_context_update_data.h new file mode 100644 index 000000000..4efa4005c --- /dev/null +++ b/lib/sbi/openapi/model/app_session_context_update_data.h @@ -0,0 +1,81 @@ +/* + * app_session_context_update_data.h + * + * Identifies the modifications to an Individual Application Session Context and may include the modifications to the sub-resource Events Subscription. + */ + +#ifndef _OpenAPI_app_session_context_update_data_H_ +#define _OpenAPI_app_session_context_update_data_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" +#include "af_routing_requirement_rm.h" +#include "events_subsc_req_data_rm.h" +#include "media_component_rm.h" +#include "port_management_container.h" +#include "preemption_control_information_rm.h" +#include "reserv_priority.h" +#include "service_info_status.h" +#include "sip_forking_indication.h" +#include "sponsoring_status.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_app_session_context_update_data_s OpenAPI_app_session_context_update_data_t; +typedef struct OpenAPI_app_session_context_update_data_s { + char *af_app_id; + struct OpenAPI_af_routing_requirement_rm_s *af_rout_req; + char *asp_id; + char *bdt_ref_id; + struct OpenAPI_events_subsc_req_data_rm_s *ev_subsc; + char *mcptt_id; + char *mc_video_id; + OpenAPI_list_t* med_components; + char *mps_id; + char *mcs_id; + struct OpenAPI_preemption_control_information_rm_s *preempt_control_info; + OpenAPI_reserv_priority_e res_prio; + OpenAPI_service_info_status_e serv_inf_status; + OpenAPI_sip_forking_indication_e sip_fork_ind; + char *spon_id; + OpenAPI_sponsoring_status_e spon_status; + struct OpenAPI_port_management_container_s *tsn_port_man_cont_dstt; + OpenAPI_list_t *tsn_port_man_cont_nwtts; +} OpenAPI_app_session_context_update_data_t; + +OpenAPI_app_session_context_update_data_t *OpenAPI_app_session_context_update_data_create( + char *af_app_id, + OpenAPI_af_routing_requirement_rm_t *af_rout_req, + char *asp_id, + char *bdt_ref_id, + OpenAPI_events_subsc_req_data_rm_t *ev_subsc, + char *mcptt_id, + char *mc_video_id, + OpenAPI_list_t* med_components, + char *mps_id, + char *mcs_id, + OpenAPI_preemption_control_information_rm_t *preempt_control_info, + OpenAPI_reserv_priority_e res_prio, + OpenAPI_service_info_status_e serv_inf_status, + OpenAPI_sip_forking_indication_e sip_fork_ind, + char *spon_id, + OpenAPI_sponsoring_status_e spon_status, + OpenAPI_port_management_container_t *tsn_port_man_cont_dstt, + OpenAPI_list_t *tsn_port_man_cont_nwtts + ); +void OpenAPI_app_session_context_update_data_free(OpenAPI_app_session_context_update_data_t *app_session_context_update_data); +OpenAPI_app_session_context_update_data_t *OpenAPI_app_session_context_update_data_parseFromJSON(cJSON *app_session_context_update_dataJSON); +cJSON *OpenAPI_app_session_context_update_data_convertToJSON(OpenAPI_app_session_context_update_data_t *app_session_context_update_data); +OpenAPI_app_session_context_update_data_t *OpenAPI_app_session_context_update_data_copy(OpenAPI_app_session_context_update_data_t *dst, OpenAPI_app_session_context_update_data_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_app_session_context_update_data_H_ */ + diff --git a/lib/sbi/openapi/model/binding_level.c b/lib/sbi/openapi/model/binding_level.c new file mode 100644 index 000000000..74c742460 --- /dev/null +++ b/lib/sbi/openapi/model/binding_level.c @@ -0,0 +1,30 @@ + +#include +#include +#include +#include "binding_level.h" + +char* OpenAPI_binding_level_ToString(OpenAPI_binding_level_e binding_level) +{ + const char *binding_levelArray[] = { "NULL", "NF_SET", "NF_INSTANCE" }; + size_t sizeofArray = sizeof(binding_levelArray) / sizeof(binding_levelArray[0]); + if (binding_level < sizeofArray) + return (char *)binding_levelArray[binding_level]; + else + return (char *)"Unknown"; +} + +OpenAPI_binding_level_e OpenAPI_binding_level_FromString(char* binding_level) +{ + int stringToReturn = 0; + const char *binding_levelArray[] = { "NULL", "NF_SET", "NF_INSTANCE" }; + size_t sizeofArray = sizeof(binding_levelArray) / sizeof(binding_levelArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(binding_level, binding_levelArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; + } + return 0; +} + diff --git a/lib/sbi/openapi/model/binding_level.h b/lib/sbi/openapi/model/binding_level.h new file mode 100644 index 000000000..023906529 --- /dev/null +++ b/lib/sbi/openapi/model/binding_level.h @@ -0,0 +1,31 @@ +/* + * binding_level.h + * + * + */ + +#ifndef _OpenAPI_binding_level_H_ +#define _OpenAPI_binding_level_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { OpenAPI_binding_level_NULL = 0, OpenAPI_binding_level_NF_SET, OpenAPI_binding_level_NF_INSTANCE } OpenAPI_binding_level_e; + +char* OpenAPI_binding_level_ToString(OpenAPI_binding_level_e binding_level); + +OpenAPI_binding_level_e OpenAPI_binding_level_FromString(char* binding_level); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_binding_level_H_ */ + diff --git a/lib/sbi/openapi/model/binding_resp.c b/lib/sbi/openapi/model/binding_resp.c new file mode 100644 index 000000000..8c7db7c89 --- /dev/null +++ b/lib/sbi/openapi/model/binding_resp.c @@ -0,0 +1,155 @@ + +#include +#include +#include +#include "binding_resp.h" + +OpenAPI_binding_resp_t *OpenAPI_binding_resp_create( + char *pcf_sm_fqdn, + OpenAPI_list_t *pcf_sm_ip_end_points + ) +{ + OpenAPI_binding_resp_t *binding_resp_local_var = OpenAPI_malloc(sizeof(OpenAPI_binding_resp_t)); + if (!binding_resp_local_var) { + return NULL; + } + binding_resp_local_var->pcf_sm_fqdn = pcf_sm_fqdn; + binding_resp_local_var->pcf_sm_ip_end_points = pcf_sm_ip_end_points; + + return binding_resp_local_var; +} + +void OpenAPI_binding_resp_free(OpenAPI_binding_resp_t *binding_resp) +{ + if (NULL == binding_resp) { + return; + } + OpenAPI_lnode_t *node; + ogs_free(binding_resp->pcf_sm_fqdn); + OpenAPI_list_for_each(binding_resp->pcf_sm_ip_end_points, node) { + OpenAPI_ip_end_point_free(node->data); + } + OpenAPI_list_free(binding_resp->pcf_sm_ip_end_points); + ogs_free(binding_resp); +} + +cJSON *OpenAPI_binding_resp_convertToJSON(OpenAPI_binding_resp_t *binding_resp) +{ + cJSON *item = NULL; + + if (binding_resp == NULL) { + ogs_error("OpenAPI_binding_resp_convertToJSON() failed [BindingResp]"); + return NULL; + } + + item = cJSON_CreateObject(); + if (binding_resp->pcf_sm_fqdn) { + if (cJSON_AddStringToObject(item, "pcfSmFqdn", binding_resp->pcf_sm_fqdn) == NULL) { + ogs_error("OpenAPI_binding_resp_convertToJSON() failed [pcf_sm_fqdn]"); + goto end; + } + } + + if (binding_resp->pcf_sm_ip_end_points) { + cJSON *pcf_sm_ip_end_pointsList = cJSON_AddArrayToObject(item, "pcfSmIpEndPoints"); + if (pcf_sm_ip_end_pointsList == NULL) { + ogs_error("OpenAPI_binding_resp_convertToJSON() failed [pcf_sm_ip_end_points]"); + goto end; + } + + OpenAPI_lnode_t *pcf_sm_ip_end_points_node; + if (binding_resp->pcf_sm_ip_end_points) { + OpenAPI_list_for_each(binding_resp->pcf_sm_ip_end_points, pcf_sm_ip_end_points_node) { + cJSON *itemLocal = OpenAPI_ip_end_point_convertToJSON(pcf_sm_ip_end_points_node->data); + if (itemLocal == NULL) { + ogs_error("OpenAPI_binding_resp_convertToJSON() failed [pcf_sm_ip_end_points]"); + goto end; + } + cJSON_AddItemToArray(pcf_sm_ip_end_pointsList, itemLocal); + } + } + } + +end: + return item; +} + +OpenAPI_binding_resp_t *OpenAPI_binding_resp_parseFromJSON(cJSON *binding_respJSON) +{ + OpenAPI_binding_resp_t *binding_resp_local_var = NULL; + cJSON *pcf_sm_fqdn = cJSON_GetObjectItemCaseSensitive(binding_respJSON, "pcfSmFqdn"); + + if (pcf_sm_fqdn) { + if (!cJSON_IsString(pcf_sm_fqdn)) { + ogs_error("OpenAPI_binding_resp_parseFromJSON() failed [pcf_sm_fqdn]"); + goto end; + } + } + + cJSON *pcf_sm_ip_end_points = cJSON_GetObjectItemCaseSensitive(binding_respJSON, "pcfSmIpEndPoints"); + + OpenAPI_list_t *pcf_sm_ip_end_pointsList; + if (pcf_sm_ip_end_points) { + cJSON *pcf_sm_ip_end_points_local_nonprimitive; + if (!cJSON_IsArray(pcf_sm_ip_end_points)) { + ogs_error("OpenAPI_binding_resp_parseFromJSON() failed [pcf_sm_ip_end_points]"); + goto end; + } + + pcf_sm_ip_end_pointsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(pcf_sm_ip_end_points_local_nonprimitive, pcf_sm_ip_end_points ) { + if (!cJSON_IsObject(pcf_sm_ip_end_points_local_nonprimitive)) { + ogs_error("OpenAPI_binding_resp_parseFromJSON() failed [pcf_sm_ip_end_points]"); + goto end; + } + OpenAPI_ip_end_point_t *pcf_sm_ip_end_pointsItem = OpenAPI_ip_end_point_parseFromJSON(pcf_sm_ip_end_points_local_nonprimitive); + + OpenAPI_list_add(pcf_sm_ip_end_pointsList, pcf_sm_ip_end_pointsItem); + } + } + + binding_resp_local_var = OpenAPI_binding_resp_create ( + pcf_sm_fqdn ? ogs_strdup(pcf_sm_fqdn->valuestring) : NULL, + pcf_sm_ip_end_points ? pcf_sm_ip_end_pointsList : NULL + ); + + return binding_resp_local_var; +end: + return NULL; +} + +OpenAPI_binding_resp_t *OpenAPI_binding_resp_copy(OpenAPI_binding_resp_t *dst, OpenAPI_binding_resp_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_binding_resp_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_binding_resp_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_binding_resp_free(dst); + dst = OpenAPI_binding_resp_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/binding_resp.h b/lib/sbi/openapi/model/binding_resp.h new file mode 100644 index 000000000..d56a6ec6c --- /dev/null +++ b/lib/sbi/openapi/model/binding_resp.h @@ -0,0 +1,41 @@ +/* + * binding_resp.h + * + * + */ + +#ifndef _OpenAPI_binding_resp_H_ +#define _OpenAPI_binding_resp_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" +#include "ip_end_point.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_binding_resp_s OpenAPI_binding_resp_t; +typedef struct OpenAPI_binding_resp_s { + char *pcf_sm_fqdn; + OpenAPI_list_t *pcf_sm_ip_end_points; +} OpenAPI_binding_resp_t; + +OpenAPI_binding_resp_t *OpenAPI_binding_resp_create( + char *pcf_sm_fqdn, + OpenAPI_list_t *pcf_sm_ip_end_points + ); +void OpenAPI_binding_resp_free(OpenAPI_binding_resp_t *binding_resp); +OpenAPI_binding_resp_t *OpenAPI_binding_resp_parseFromJSON(cJSON *binding_respJSON); +cJSON *OpenAPI_binding_resp_convertToJSON(OpenAPI_binding_resp_t *binding_resp); +OpenAPI_binding_resp_t *OpenAPI_binding_resp_copy(OpenAPI_binding_resp_t *dst, OpenAPI_binding_resp_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_binding_resp_H_ */ + diff --git a/lib/sbi/openapi/model/deregistration_data.c b/lib/sbi/openapi/model/deregistration_data.c index e80fa2fcf..5c7cbb87f 100644 --- a/lib/sbi/openapi/model/deregistration_data.c +++ b/lib/sbi/openapi/model/deregistration_data.c @@ -5,7 +5,7 @@ #include "deregistration_data.h" OpenAPI_deregistration_data_t *OpenAPI_deregistration_data_create( - OpenAPI_deregistration_reason_t *dereg_reason, + OpenAPI_deregistration_reason_e dereg_reason, OpenAPI_access_type_e access_type, int pdu_session_id, char *new_smf_instance_id @@ -29,7 +29,6 @@ void OpenAPI_deregistration_data_free(OpenAPI_deregistration_data_t *deregistrat return; } OpenAPI_lnode_t *node; - OpenAPI_deregistration_reason_free(deregistration_data->dereg_reason); ogs_free(deregistration_data->new_smf_instance_id); ogs_free(deregistration_data); } @@ -44,13 +43,7 @@ cJSON *OpenAPI_deregistration_data_convertToJSON(OpenAPI_deregistration_data_t * } item = cJSON_CreateObject(); - cJSON *dereg_reason_local_JSON = OpenAPI_deregistration_reason_convertToJSON(deregistration_data->dereg_reason); - if (dereg_reason_local_JSON == NULL) { - ogs_error("OpenAPI_deregistration_data_convertToJSON() failed [dereg_reason]"); - goto end; - } - cJSON_AddItemToObject(item, "deregReason", dereg_reason_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "deregReason", OpenAPI_deregistration_reason_ToString(deregistration_data->dereg_reason)) == NULL) { ogs_error("OpenAPI_deregistration_data_convertToJSON() failed [dereg_reason]"); goto end; } @@ -89,9 +82,13 @@ OpenAPI_deregistration_data_t *OpenAPI_deregistration_data_parseFromJSON(cJSON * goto end; } - OpenAPI_deregistration_reason_t *dereg_reason_local_nonprim = NULL; + OpenAPI_deregistration_reason_e dereg_reasonVariable; - dereg_reason_local_nonprim = OpenAPI_deregistration_reason_parseFromJSON(dereg_reason); + if (!cJSON_IsString(dereg_reason)) { + ogs_error("OpenAPI_deregistration_data_parseFromJSON() failed [dereg_reason]"); + goto end; + } + dereg_reasonVariable = OpenAPI_deregistration_reason_FromString(dereg_reason->valuestring); cJSON *access_type = cJSON_GetObjectItemCaseSensitive(deregistration_dataJSON, "accessType"); @@ -123,7 +120,7 @@ OpenAPI_deregistration_data_t *OpenAPI_deregistration_data_parseFromJSON(cJSON * } deregistration_data_local_var = OpenAPI_deregistration_data_create ( - dereg_reason_local_nonprim, + dereg_reasonVariable, access_type ? access_typeVariable : 0, pdu_session_id ? pdu_session_id->valuedouble : 0, new_smf_instance_id ? ogs_strdup(new_smf_instance_id->valuestring) : NULL diff --git a/lib/sbi/openapi/model/deregistration_data.h b/lib/sbi/openapi/model/deregistration_data.h index 3a257ba10..dfac711a3 100644 --- a/lib/sbi/openapi/model/deregistration_data.h +++ b/lib/sbi/openapi/model/deregistration_data.h @@ -21,14 +21,14 @@ extern "C" { typedef struct OpenAPI_deregistration_data_s OpenAPI_deregistration_data_t; typedef struct OpenAPI_deregistration_data_s { - struct OpenAPI_deregistration_reason_s *dereg_reason; + OpenAPI_deregistration_reason_e dereg_reason; OpenAPI_access_type_e access_type; int pdu_session_id; char *new_smf_instance_id; } OpenAPI_deregistration_data_t; OpenAPI_deregistration_data_t *OpenAPI_deregistration_data_create( - OpenAPI_deregistration_reason_t *dereg_reason, + OpenAPI_deregistration_reason_e dereg_reason, OpenAPI_access_type_e access_type, int pdu_session_id, char *new_smf_instance_id diff --git a/lib/sbi/openapi/model/deregistration_reason.c b/lib/sbi/openapi/model/deregistration_reason.c index 46c902001..ebfed5953 100644 --- a/lib/sbi/openapi/model/deregistration_reason.c +++ b/lib/sbi/openapi/model/deregistration_reason.c @@ -4,82 +4,27 @@ #include #include "deregistration_reason.h" -OpenAPI_deregistration_reason_t *OpenAPI_deregistration_reason_create( - ) +char* OpenAPI_deregistration_reason_ToString(OpenAPI_deregistration_reason_e deregistration_reason) { - OpenAPI_deregistration_reason_t *deregistration_reason_local_var = OpenAPI_malloc(sizeof(OpenAPI_deregistration_reason_t)); - if (!deregistration_reason_local_var) { - return NULL; - } - - return deregistration_reason_local_var; + const char *deregistration_reasonArray[] = { "NULL", "UE_INITIAL_REGISTRATION", "UE_REGISTRATION_AREA_CHANGE", "SUBSCRIPTION_WITHDRAWN", "_5GS_TO_EPS_MOBILITY", "_5GS_TO_EPS_MOBILITY_UE_INITIAL_REGISTRATION", "REREGISTRATION_REQUIRED", "SMF_CONTEXT_TRANSFERRED" }; + size_t sizeofArray = sizeof(deregistration_reasonArray) / sizeof(deregistration_reasonArray[0]); + if (deregistration_reason < sizeofArray) + return (char *)deregistration_reasonArray[deregistration_reason]; + else + return (char *)"Unknown"; } -void OpenAPI_deregistration_reason_free(OpenAPI_deregistration_reason_t *deregistration_reason) +OpenAPI_deregistration_reason_e OpenAPI_deregistration_reason_FromString(char* deregistration_reason) { - if (NULL == deregistration_reason) { - return; + int stringToReturn = 0; + const char *deregistration_reasonArray[] = { "NULL", "UE_INITIAL_REGISTRATION", "UE_REGISTRATION_AREA_CHANGE", "SUBSCRIPTION_WITHDRAWN", "_5GS_TO_EPS_MOBILITY", "_5GS_TO_EPS_MOBILITY_UE_INITIAL_REGISTRATION", "REREGISTRATION_REQUIRED", "SMF_CONTEXT_TRANSFERRED" }; + size_t sizeofArray = sizeof(deregistration_reasonArray) / sizeof(deregistration_reasonArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(deregistration_reason, deregistration_reasonArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; } - OpenAPI_lnode_t *node; - ogs_free(deregistration_reason); -} - -cJSON *OpenAPI_deregistration_reason_convertToJSON(OpenAPI_deregistration_reason_t *deregistration_reason) -{ - cJSON *item = NULL; - - if (deregistration_reason == NULL) { - ogs_error("OpenAPI_deregistration_reason_convertToJSON() failed [DeregistrationReason]"); - return NULL; - } - - item = cJSON_CreateObject(); -end: - return item; -} - -OpenAPI_deregistration_reason_t *OpenAPI_deregistration_reason_parseFromJSON(cJSON *deregistration_reasonJSON) -{ - OpenAPI_deregistration_reason_t *deregistration_reason_local_var = NULL; - deregistration_reason_local_var = OpenAPI_deregistration_reason_create ( - ); - - return deregistration_reason_local_var; -end: - return NULL; -} - -OpenAPI_deregistration_reason_t *OpenAPI_deregistration_reason_copy(OpenAPI_deregistration_reason_t *dst, OpenAPI_deregistration_reason_t *src) -{ - cJSON *item = NULL; - char *content = NULL; - - ogs_assert(src); - item = OpenAPI_deregistration_reason_convertToJSON(src); - if (!item) { - ogs_error("OpenAPI_deregistration_reason_convertToJSON() failed"); - return NULL; - } - - content = cJSON_Print(item); - cJSON_Delete(item); - - if (!content) { - ogs_error("cJSON_Print() failed"); - return NULL; - } - - item = cJSON_Parse(content); - ogs_free(content); - if (!item) { - ogs_error("cJSON_Parse() failed"); - return NULL; - } - - OpenAPI_deregistration_reason_free(dst); - dst = OpenAPI_deregistration_reason_parseFromJSON(item); - cJSON_Delete(item); - - return dst; + return 0; } diff --git a/lib/sbi/openapi/model/deregistration_reason.h b/lib/sbi/openapi/model/deregistration_reason.h index 4262cd700..150fc15ce 100644 --- a/lib/sbi/openapi/model/deregistration_reason.h +++ b/lib/sbi/openapi/model/deregistration_reason.h @@ -17,16 +17,11 @@ extern "C" { #endif -typedef struct OpenAPI_deregistration_reason_s OpenAPI_deregistration_reason_t; -typedef struct OpenAPI_deregistration_reason_s { -} OpenAPI_deregistration_reason_t; +typedef enum { OpenAPI_deregistration_reason_NULL = 0, OpenAPI_deregistration_reason_UE_INITIAL_REGISTRATION, OpenAPI_deregistration_reason_UE_REGISTRATION_AREA_CHANGE, OpenAPI_deregistration_reason_SUBSCRIPTION_WITHDRAWN, OpenAPI_deregistration_reason__5GS_TO_EPS_MOBILITY, OpenAPI_deregistration_reason__5GS_TO_EPS_MOBILITY_UE_INITIAL_REGISTRATION, OpenAPI_deregistration_reason_REREGISTRATION_REQUIRED, OpenAPI_deregistration_reason_SMF_CONTEXT_TRANSFERRED } OpenAPI_deregistration_reason_e; -OpenAPI_deregistration_reason_t *OpenAPI_deregistration_reason_create( - ); -void OpenAPI_deregistration_reason_free(OpenAPI_deregistration_reason_t *deregistration_reason); -OpenAPI_deregistration_reason_t *OpenAPI_deregistration_reason_parseFromJSON(cJSON *deregistration_reasonJSON); -cJSON *OpenAPI_deregistration_reason_convertToJSON(OpenAPI_deregistration_reason_t *deregistration_reason); -OpenAPI_deregistration_reason_t *OpenAPI_deregistration_reason_copy(OpenAPI_deregistration_reason_t *dst, OpenAPI_deregistration_reason_t *src); +char* OpenAPI_deregistration_reason_ToString(OpenAPI_deregistration_reason_e deregistration_reason); + +OpenAPI_deregistration_reason_e OpenAPI_deregistration_reason_FromString(char* deregistration_reason); #ifdef __cplusplus } diff --git a/lib/sbi/openapi/model/dnai_change_type.c b/lib/sbi/openapi/model/dnai_change_type.c index 70a8ad368..32947a5b5 100644 --- a/lib/sbi/openapi/model/dnai_change_type.c +++ b/lib/sbi/openapi/model/dnai_change_type.c @@ -4,82 +4,27 @@ #include #include "dnai_change_type.h" -OpenAPI_dnai_change_type_t *OpenAPI_dnai_change_type_create( - ) +char* OpenAPI_dnai_change_type_ToString(OpenAPI_dnai_change_type_e dnai_change_type) { - OpenAPI_dnai_change_type_t *dnai_change_type_local_var = OpenAPI_malloc(sizeof(OpenAPI_dnai_change_type_t)); - if (!dnai_change_type_local_var) { - return NULL; - } - - return dnai_change_type_local_var; + const char *dnai_change_typeArray[] = { "NULL", "EARLY", "EARLY_LATE", "LATE" }; + size_t sizeofArray = sizeof(dnai_change_typeArray) / sizeof(dnai_change_typeArray[0]); + if (dnai_change_type < sizeofArray) + return (char *)dnai_change_typeArray[dnai_change_type]; + else + return (char *)"Unknown"; } -void OpenAPI_dnai_change_type_free(OpenAPI_dnai_change_type_t *dnai_change_type) +OpenAPI_dnai_change_type_e OpenAPI_dnai_change_type_FromString(char* dnai_change_type) { - if (NULL == dnai_change_type) { - return; + int stringToReturn = 0; + const char *dnai_change_typeArray[] = { "NULL", "EARLY", "EARLY_LATE", "LATE" }; + size_t sizeofArray = sizeof(dnai_change_typeArray) / sizeof(dnai_change_typeArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(dnai_change_type, dnai_change_typeArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; } - OpenAPI_lnode_t *node; - ogs_free(dnai_change_type); -} - -cJSON *OpenAPI_dnai_change_type_convertToJSON(OpenAPI_dnai_change_type_t *dnai_change_type) -{ - cJSON *item = NULL; - - if (dnai_change_type == NULL) { - ogs_error("OpenAPI_dnai_change_type_convertToJSON() failed [DnaiChangeType]"); - return NULL; - } - - item = cJSON_CreateObject(); -end: - return item; -} - -OpenAPI_dnai_change_type_t *OpenAPI_dnai_change_type_parseFromJSON(cJSON *dnai_change_typeJSON) -{ - OpenAPI_dnai_change_type_t *dnai_change_type_local_var = NULL; - dnai_change_type_local_var = OpenAPI_dnai_change_type_create ( - ); - - return dnai_change_type_local_var; -end: - return NULL; -} - -OpenAPI_dnai_change_type_t *OpenAPI_dnai_change_type_copy(OpenAPI_dnai_change_type_t *dst, OpenAPI_dnai_change_type_t *src) -{ - cJSON *item = NULL; - char *content = NULL; - - ogs_assert(src); - item = OpenAPI_dnai_change_type_convertToJSON(src); - if (!item) { - ogs_error("OpenAPI_dnai_change_type_convertToJSON() failed"); - return NULL; - } - - content = cJSON_Print(item); - cJSON_Delete(item); - - if (!content) { - ogs_error("cJSON_Print() failed"); - return NULL; - } - - item = cJSON_Parse(content); - ogs_free(content); - if (!item) { - ogs_error("cJSON_Parse() failed"); - return NULL; - } - - OpenAPI_dnai_change_type_free(dst); - dst = OpenAPI_dnai_change_type_parseFromJSON(item); - cJSON_Delete(item); - - return dst; + return 0; } diff --git a/lib/sbi/openapi/model/dnai_change_type.h b/lib/sbi/openapi/model/dnai_change_type.h index 9da883d07..a4d8b3a87 100644 --- a/lib/sbi/openapi/model/dnai_change_type.h +++ b/lib/sbi/openapi/model/dnai_change_type.h @@ -1,7 +1,7 @@ /* * dnai_change_type.h * - * Possible values are - EARLY: Early notification of UP path reconfiguration. - EARLY_LATE: Early and late notification of UP path reconfiguration. This value shall only be present in the subscription to the DNAI change event. - LATE: Late notification of UP path reconfiguration. + * */ #ifndef _OpenAPI_dnai_change_type_H_ @@ -17,16 +17,11 @@ extern "C" { #endif -typedef struct OpenAPI_dnai_change_type_s OpenAPI_dnai_change_type_t; -typedef struct OpenAPI_dnai_change_type_s { -} OpenAPI_dnai_change_type_t; +typedef enum { OpenAPI_dnai_change_type_NULL = 0, OpenAPI_dnai_change_type_EARLY, OpenAPI_dnai_change_type_EARLY_LATE, OpenAPI_dnai_change_type_LATE } OpenAPI_dnai_change_type_e; -OpenAPI_dnai_change_type_t *OpenAPI_dnai_change_type_create( - ); -void OpenAPI_dnai_change_type_free(OpenAPI_dnai_change_type_t *dnai_change_type); -OpenAPI_dnai_change_type_t *OpenAPI_dnai_change_type_parseFromJSON(cJSON *dnai_change_typeJSON); -cJSON *OpenAPI_dnai_change_type_convertToJSON(OpenAPI_dnai_change_type_t *dnai_change_type); -OpenAPI_dnai_change_type_t *OpenAPI_dnai_change_type_copy(OpenAPI_dnai_change_type_t *dst, OpenAPI_dnai_change_type_t *src); +char* OpenAPI_dnai_change_type_ToString(OpenAPI_dnai_change_type_e dnai_change_type); + +OpenAPI_dnai_change_type_e OpenAPI_dnai_change_type_FromString(char* dnai_change_type); #ifdef __cplusplus } diff --git a/lib/sbi/openapi/model/events_notification.c b/lib/sbi/openapi/model/events_notification.c new file mode 100644 index 000000000..89a6ef842 --- /dev/null +++ b/lib/sbi/openapi/model/events_notification.c @@ -0,0 +1,756 @@ + +#include +#include +#include +#include "events_notification.h" + +OpenAPI_events_notification_t *OpenAPI_events_notification_create( + OpenAPI_access_type_e access_type, + OpenAPI_acc_net_charging_address_t *an_charg_addr, + OpenAPI_list_t *an_charg_ids, + OpenAPI_an_gw_address_t *an_gw_addr, + char *ev_subs_uri, + OpenAPI_list_t *ev_notifs, + OpenAPI_list_t *failed_resourc_alloc_reports, + int no_net_loc_supp, + OpenAPI_list_t *out_of_cred_reports, + OpenAPI_plmn_id_t *plmn_id, + OpenAPI_list_t *qnc_reports, + OpenAPI_list_t *qos_mon_reports, + OpenAPI_list_t *ran_nas_rel_causes, + OpenAPI_rat_type_e rat_type, + OpenAPI_user_location_t *ue_loc, + char *ue_time_zone, + OpenAPI_accumulated_usage_t *usg_rep, + OpenAPI_tsn_bridge_info_t *tsn_bridge_info, + OpenAPI_port_management_container_t *tsn_port_man_cont_dstt, + OpenAPI_list_t *tsn_port_man_cont_nwtts + ) +{ + OpenAPI_events_notification_t *events_notification_local_var = OpenAPI_malloc(sizeof(OpenAPI_events_notification_t)); + if (!events_notification_local_var) { + return NULL; + } + events_notification_local_var->access_type = access_type; + events_notification_local_var->an_charg_addr = an_charg_addr; + events_notification_local_var->an_charg_ids = an_charg_ids; + events_notification_local_var->an_gw_addr = an_gw_addr; + events_notification_local_var->ev_subs_uri = ev_subs_uri; + events_notification_local_var->ev_notifs = ev_notifs; + events_notification_local_var->failed_resourc_alloc_reports = failed_resourc_alloc_reports; + events_notification_local_var->no_net_loc_supp = no_net_loc_supp; + events_notification_local_var->out_of_cred_reports = out_of_cred_reports; + events_notification_local_var->plmn_id = plmn_id; + events_notification_local_var->qnc_reports = qnc_reports; + events_notification_local_var->qos_mon_reports = qos_mon_reports; + events_notification_local_var->ran_nas_rel_causes = ran_nas_rel_causes; + events_notification_local_var->rat_type = rat_type; + events_notification_local_var->ue_loc = ue_loc; + events_notification_local_var->ue_time_zone = ue_time_zone; + events_notification_local_var->usg_rep = usg_rep; + events_notification_local_var->tsn_bridge_info = tsn_bridge_info; + events_notification_local_var->tsn_port_man_cont_dstt = tsn_port_man_cont_dstt; + events_notification_local_var->tsn_port_man_cont_nwtts = tsn_port_man_cont_nwtts; + + return events_notification_local_var; +} + +void OpenAPI_events_notification_free(OpenAPI_events_notification_t *events_notification) +{ + if (NULL == events_notification) { + return; + } + OpenAPI_lnode_t *node; + OpenAPI_acc_net_charging_address_free(events_notification->an_charg_addr); + OpenAPI_list_for_each(events_notification->an_charg_ids, node) { + OpenAPI_access_net_charging_identifier_free(node->data); + } + OpenAPI_list_free(events_notification->an_charg_ids); + OpenAPI_an_gw_address_free(events_notification->an_gw_addr); + ogs_free(events_notification->ev_subs_uri); + OpenAPI_list_for_each(events_notification->ev_notifs, node) { + OpenAPI_af_event_notification_free(node->data); + } + OpenAPI_list_free(events_notification->ev_notifs); + OpenAPI_list_for_each(events_notification->failed_resourc_alloc_reports, node) { + OpenAPI_resources_allocation_info_free(node->data); + } + OpenAPI_list_free(events_notification->failed_resourc_alloc_reports); + OpenAPI_list_for_each(events_notification->out_of_cred_reports, node) { + OpenAPI_out_of_credit_information_free(node->data); + } + OpenAPI_list_free(events_notification->out_of_cred_reports); + OpenAPI_plmn_id_free(events_notification->plmn_id); + OpenAPI_list_for_each(events_notification->qnc_reports, node) { + OpenAPI_qos_notification_control_info_free(node->data); + } + OpenAPI_list_free(events_notification->qnc_reports); + OpenAPI_list_for_each(events_notification->qos_mon_reports, node) { + OpenAPI_qos_monitoring_report_free(node->data); + } + OpenAPI_list_free(events_notification->qos_mon_reports); + OpenAPI_list_for_each(events_notification->ran_nas_rel_causes, node) { + OpenAPI_ran_nas_rel_cause_free(node->data); + } + OpenAPI_list_free(events_notification->ran_nas_rel_causes); + OpenAPI_user_location_free(events_notification->ue_loc); + ogs_free(events_notification->ue_time_zone); + OpenAPI_accumulated_usage_free(events_notification->usg_rep); + OpenAPI_tsn_bridge_info_free(events_notification->tsn_bridge_info); + OpenAPI_port_management_container_free(events_notification->tsn_port_man_cont_dstt); + OpenAPI_list_for_each(events_notification->tsn_port_man_cont_nwtts, node) { + OpenAPI_port_management_container_free(node->data); + } + OpenAPI_list_free(events_notification->tsn_port_man_cont_nwtts); + ogs_free(events_notification); +} + +cJSON *OpenAPI_events_notification_convertToJSON(OpenAPI_events_notification_t *events_notification) +{ + cJSON *item = NULL; + + if (events_notification == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [EventsNotification]"); + return NULL; + } + + item = cJSON_CreateObject(); + if (events_notification->access_type) { + if (cJSON_AddStringToObject(item, "accessType", OpenAPI_access_type_ToString(events_notification->access_type)) == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [access_type]"); + goto end; + } + } + + if (events_notification->an_charg_addr) { + cJSON *an_charg_addr_local_JSON = OpenAPI_acc_net_charging_address_convertToJSON(events_notification->an_charg_addr); + if (an_charg_addr_local_JSON == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [an_charg_addr]"); + goto end; + } + cJSON_AddItemToObject(item, "anChargAddr", an_charg_addr_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [an_charg_addr]"); + goto end; + } + } + + if (events_notification->an_charg_ids) { + cJSON *an_charg_idsList = cJSON_AddArrayToObject(item, "anChargIds"); + if (an_charg_idsList == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [an_charg_ids]"); + goto end; + } + + OpenAPI_lnode_t *an_charg_ids_node; + if (events_notification->an_charg_ids) { + OpenAPI_list_for_each(events_notification->an_charg_ids, an_charg_ids_node) { + cJSON *itemLocal = OpenAPI_access_net_charging_identifier_convertToJSON(an_charg_ids_node->data); + if (itemLocal == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [an_charg_ids]"); + goto end; + } + cJSON_AddItemToArray(an_charg_idsList, itemLocal); + } + } + } + + if (events_notification->an_gw_addr) { + cJSON *an_gw_addr_local_JSON = OpenAPI_an_gw_address_convertToJSON(events_notification->an_gw_addr); + if (an_gw_addr_local_JSON == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [an_gw_addr]"); + goto end; + } + cJSON_AddItemToObject(item, "anGwAddr", an_gw_addr_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [an_gw_addr]"); + goto end; + } + } + + if (cJSON_AddStringToObject(item, "evSubsUri", events_notification->ev_subs_uri) == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [ev_subs_uri]"); + goto end; + } + + cJSON *ev_notifsList = cJSON_AddArrayToObject(item, "evNotifs"); + if (ev_notifsList == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [ev_notifs]"); + goto end; + } + + OpenAPI_lnode_t *ev_notifs_node; + if (events_notification->ev_notifs) { + OpenAPI_list_for_each(events_notification->ev_notifs, ev_notifs_node) { + cJSON *itemLocal = OpenAPI_af_event_notification_convertToJSON(ev_notifs_node->data); + if (itemLocal == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [ev_notifs]"); + goto end; + } + cJSON_AddItemToArray(ev_notifsList, itemLocal); + } + } + + if (events_notification->failed_resourc_alloc_reports) { + cJSON *failed_resourc_alloc_reportsList = cJSON_AddArrayToObject(item, "failedResourcAllocReports"); + if (failed_resourc_alloc_reportsList == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [failed_resourc_alloc_reports]"); + goto end; + } + + OpenAPI_lnode_t *failed_resourc_alloc_reports_node; + if (events_notification->failed_resourc_alloc_reports) { + OpenAPI_list_for_each(events_notification->failed_resourc_alloc_reports, failed_resourc_alloc_reports_node) { + cJSON *itemLocal = OpenAPI_resources_allocation_info_convertToJSON(failed_resourc_alloc_reports_node->data); + if (itemLocal == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [failed_resourc_alloc_reports]"); + goto end; + } + cJSON_AddItemToArray(failed_resourc_alloc_reportsList, itemLocal); + } + } + } + + if (events_notification->no_net_loc_supp) { + if (cJSON_AddBoolToObject(item, "noNetLocSupp", events_notification->no_net_loc_supp) == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [no_net_loc_supp]"); + goto end; + } + } + + if (events_notification->out_of_cred_reports) { + cJSON *out_of_cred_reportsList = cJSON_AddArrayToObject(item, "outOfCredReports"); + if (out_of_cred_reportsList == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [out_of_cred_reports]"); + goto end; + } + + OpenAPI_lnode_t *out_of_cred_reports_node; + if (events_notification->out_of_cred_reports) { + OpenAPI_list_for_each(events_notification->out_of_cred_reports, out_of_cred_reports_node) { + cJSON *itemLocal = OpenAPI_out_of_credit_information_convertToJSON(out_of_cred_reports_node->data); + if (itemLocal == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [out_of_cred_reports]"); + goto end; + } + cJSON_AddItemToArray(out_of_cred_reportsList, itemLocal); + } + } + } + + if (events_notification->plmn_id) { + cJSON *plmn_id_local_JSON = OpenAPI_plmn_id_convertToJSON(events_notification->plmn_id); + if (plmn_id_local_JSON == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [plmn_id]"); + goto end; + } + cJSON_AddItemToObject(item, "plmnId", plmn_id_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [plmn_id]"); + goto end; + } + } + + if (events_notification->qnc_reports) { + cJSON *qnc_reportsList = cJSON_AddArrayToObject(item, "qncReports"); + if (qnc_reportsList == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [qnc_reports]"); + goto end; + } + + OpenAPI_lnode_t *qnc_reports_node; + if (events_notification->qnc_reports) { + OpenAPI_list_for_each(events_notification->qnc_reports, qnc_reports_node) { + cJSON *itemLocal = OpenAPI_qos_notification_control_info_convertToJSON(qnc_reports_node->data); + if (itemLocal == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [qnc_reports]"); + goto end; + } + cJSON_AddItemToArray(qnc_reportsList, itemLocal); + } + } + } + + if (events_notification->qos_mon_reports) { + cJSON *qos_mon_reportsList = cJSON_AddArrayToObject(item, "qosMonReports"); + if (qos_mon_reportsList == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [qos_mon_reports]"); + goto end; + } + + OpenAPI_lnode_t *qos_mon_reports_node; + if (events_notification->qos_mon_reports) { + OpenAPI_list_for_each(events_notification->qos_mon_reports, qos_mon_reports_node) { + cJSON *itemLocal = OpenAPI_qos_monitoring_report_convertToJSON(qos_mon_reports_node->data); + if (itemLocal == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [qos_mon_reports]"); + goto end; + } + cJSON_AddItemToArray(qos_mon_reportsList, itemLocal); + } + } + } + + if (events_notification->ran_nas_rel_causes) { + cJSON *ran_nas_rel_causesList = cJSON_AddArrayToObject(item, "ranNasRelCauses"); + if (ran_nas_rel_causesList == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [ran_nas_rel_causes]"); + goto end; + } + + OpenAPI_lnode_t *ran_nas_rel_causes_node; + if (events_notification->ran_nas_rel_causes) { + OpenAPI_list_for_each(events_notification->ran_nas_rel_causes, ran_nas_rel_causes_node) { + cJSON *itemLocal = OpenAPI_ran_nas_rel_cause_convertToJSON(ran_nas_rel_causes_node->data); + if (itemLocal == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [ran_nas_rel_causes]"); + goto end; + } + cJSON_AddItemToArray(ran_nas_rel_causesList, itemLocal); + } + } + } + + if (events_notification->rat_type) { + if (cJSON_AddStringToObject(item, "ratType", OpenAPI_rat_type_ToString(events_notification->rat_type)) == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [rat_type]"); + goto end; + } + } + + if (events_notification->ue_loc) { + cJSON *ue_loc_local_JSON = OpenAPI_user_location_convertToJSON(events_notification->ue_loc); + if (ue_loc_local_JSON == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [ue_loc]"); + goto end; + } + cJSON_AddItemToObject(item, "ueLoc", ue_loc_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [ue_loc]"); + goto end; + } + } + + if (events_notification->ue_time_zone) { + if (cJSON_AddStringToObject(item, "ueTimeZone", events_notification->ue_time_zone) == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [ue_time_zone]"); + goto end; + } + } + + if (events_notification->usg_rep) { + cJSON *usg_rep_local_JSON = OpenAPI_accumulated_usage_convertToJSON(events_notification->usg_rep); + if (usg_rep_local_JSON == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [usg_rep]"); + goto end; + } + cJSON_AddItemToObject(item, "usgRep", usg_rep_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [usg_rep]"); + goto end; + } + } + + if (events_notification->tsn_bridge_info) { + cJSON *tsn_bridge_info_local_JSON = OpenAPI_tsn_bridge_info_convertToJSON(events_notification->tsn_bridge_info); + if (tsn_bridge_info_local_JSON == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [tsn_bridge_info]"); + goto end; + } + cJSON_AddItemToObject(item, "tsnBridgeInfo", tsn_bridge_info_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [tsn_bridge_info]"); + goto end; + } + } + + if (events_notification->tsn_port_man_cont_dstt) { + cJSON *tsn_port_man_cont_dstt_local_JSON = OpenAPI_port_management_container_convertToJSON(events_notification->tsn_port_man_cont_dstt); + if (tsn_port_man_cont_dstt_local_JSON == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [tsn_port_man_cont_dstt]"); + goto end; + } + cJSON_AddItemToObject(item, "tsnPortManContDstt", tsn_port_man_cont_dstt_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [tsn_port_man_cont_dstt]"); + goto end; + } + } + + if (events_notification->tsn_port_man_cont_nwtts) { + cJSON *tsn_port_man_cont_nwttsList = cJSON_AddArrayToObject(item, "tsnPortManContNwtts"); + if (tsn_port_man_cont_nwttsList == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [tsn_port_man_cont_nwtts]"); + goto end; + } + + OpenAPI_lnode_t *tsn_port_man_cont_nwtts_node; + if (events_notification->tsn_port_man_cont_nwtts) { + OpenAPI_list_for_each(events_notification->tsn_port_man_cont_nwtts, tsn_port_man_cont_nwtts_node) { + cJSON *itemLocal = OpenAPI_port_management_container_convertToJSON(tsn_port_man_cont_nwtts_node->data); + if (itemLocal == NULL) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed [tsn_port_man_cont_nwtts]"); + goto end; + } + cJSON_AddItemToArray(tsn_port_man_cont_nwttsList, itemLocal); + } + } + } + +end: + return item; +} + +OpenAPI_events_notification_t *OpenAPI_events_notification_parseFromJSON(cJSON *events_notificationJSON) +{ + OpenAPI_events_notification_t *events_notification_local_var = NULL; + cJSON *access_type = cJSON_GetObjectItemCaseSensitive(events_notificationJSON, "accessType"); + + OpenAPI_access_type_e access_typeVariable; + if (access_type) { + if (!cJSON_IsString(access_type)) { + ogs_error("OpenAPI_events_notification_parseFromJSON() failed [access_type]"); + goto end; + } + access_typeVariable = OpenAPI_access_type_FromString(access_type->valuestring); + } + + cJSON *an_charg_addr = cJSON_GetObjectItemCaseSensitive(events_notificationJSON, "anChargAddr"); + + OpenAPI_acc_net_charging_address_t *an_charg_addr_local_nonprim = NULL; + if (an_charg_addr) { + an_charg_addr_local_nonprim = OpenAPI_acc_net_charging_address_parseFromJSON(an_charg_addr); + } + + cJSON *an_charg_ids = cJSON_GetObjectItemCaseSensitive(events_notificationJSON, "anChargIds"); + + OpenAPI_list_t *an_charg_idsList; + if (an_charg_ids) { + cJSON *an_charg_ids_local_nonprimitive; + if (!cJSON_IsArray(an_charg_ids)) { + ogs_error("OpenAPI_events_notification_parseFromJSON() failed [an_charg_ids]"); + goto end; + } + + an_charg_idsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(an_charg_ids_local_nonprimitive, an_charg_ids ) { + if (!cJSON_IsObject(an_charg_ids_local_nonprimitive)) { + ogs_error("OpenAPI_events_notification_parseFromJSON() failed [an_charg_ids]"); + goto end; + } + OpenAPI_access_net_charging_identifier_t *an_charg_idsItem = OpenAPI_access_net_charging_identifier_parseFromJSON(an_charg_ids_local_nonprimitive); + + OpenAPI_list_add(an_charg_idsList, an_charg_idsItem); + } + } + + cJSON *an_gw_addr = cJSON_GetObjectItemCaseSensitive(events_notificationJSON, "anGwAddr"); + + OpenAPI_an_gw_address_t *an_gw_addr_local_nonprim = NULL; + if (an_gw_addr) { + an_gw_addr_local_nonprim = OpenAPI_an_gw_address_parseFromJSON(an_gw_addr); + } + + cJSON *ev_subs_uri = cJSON_GetObjectItemCaseSensitive(events_notificationJSON, "evSubsUri"); + if (!ev_subs_uri) { + ogs_error("OpenAPI_events_notification_parseFromJSON() failed [ev_subs_uri]"); + goto end; + } + + + if (!cJSON_IsString(ev_subs_uri)) { + ogs_error("OpenAPI_events_notification_parseFromJSON() failed [ev_subs_uri]"); + goto end; + } + + cJSON *ev_notifs = cJSON_GetObjectItemCaseSensitive(events_notificationJSON, "evNotifs"); + if (!ev_notifs) { + ogs_error("OpenAPI_events_notification_parseFromJSON() failed [ev_notifs]"); + goto end; + } + + OpenAPI_list_t *ev_notifsList; + + cJSON *ev_notifs_local_nonprimitive; + if (!cJSON_IsArray(ev_notifs)) { + ogs_error("OpenAPI_events_notification_parseFromJSON() failed [ev_notifs]"); + goto end; + } + + ev_notifsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(ev_notifs_local_nonprimitive, ev_notifs ) { + if (!cJSON_IsObject(ev_notifs_local_nonprimitive)) { + ogs_error("OpenAPI_events_notification_parseFromJSON() failed [ev_notifs]"); + goto end; + } + OpenAPI_af_event_notification_t *ev_notifsItem = OpenAPI_af_event_notification_parseFromJSON(ev_notifs_local_nonprimitive); + + OpenAPI_list_add(ev_notifsList, ev_notifsItem); + } + + cJSON *failed_resourc_alloc_reports = cJSON_GetObjectItemCaseSensitive(events_notificationJSON, "failedResourcAllocReports"); + + OpenAPI_list_t *failed_resourc_alloc_reportsList; + if (failed_resourc_alloc_reports) { + cJSON *failed_resourc_alloc_reports_local_nonprimitive; + if (!cJSON_IsArray(failed_resourc_alloc_reports)) { + ogs_error("OpenAPI_events_notification_parseFromJSON() failed [failed_resourc_alloc_reports]"); + goto end; + } + + failed_resourc_alloc_reportsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(failed_resourc_alloc_reports_local_nonprimitive, failed_resourc_alloc_reports ) { + if (!cJSON_IsObject(failed_resourc_alloc_reports_local_nonprimitive)) { + ogs_error("OpenAPI_events_notification_parseFromJSON() failed [failed_resourc_alloc_reports]"); + goto end; + } + OpenAPI_resources_allocation_info_t *failed_resourc_alloc_reportsItem = OpenAPI_resources_allocation_info_parseFromJSON(failed_resourc_alloc_reports_local_nonprimitive); + + OpenAPI_list_add(failed_resourc_alloc_reportsList, failed_resourc_alloc_reportsItem); + } + } + + cJSON *no_net_loc_supp = cJSON_GetObjectItemCaseSensitive(events_notificationJSON, "noNetLocSupp"); + + if (no_net_loc_supp) { + if (!cJSON_IsBool(no_net_loc_supp)) { + ogs_error("OpenAPI_events_notification_parseFromJSON() failed [no_net_loc_supp]"); + goto end; + } + } + + cJSON *out_of_cred_reports = cJSON_GetObjectItemCaseSensitive(events_notificationJSON, "outOfCredReports"); + + OpenAPI_list_t *out_of_cred_reportsList; + if (out_of_cred_reports) { + cJSON *out_of_cred_reports_local_nonprimitive; + if (!cJSON_IsArray(out_of_cred_reports)) { + ogs_error("OpenAPI_events_notification_parseFromJSON() failed [out_of_cred_reports]"); + goto end; + } + + out_of_cred_reportsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(out_of_cred_reports_local_nonprimitive, out_of_cred_reports ) { + if (!cJSON_IsObject(out_of_cred_reports_local_nonprimitive)) { + ogs_error("OpenAPI_events_notification_parseFromJSON() failed [out_of_cred_reports]"); + goto end; + } + OpenAPI_out_of_credit_information_t *out_of_cred_reportsItem = OpenAPI_out_of_credit_information_parseFromJSON(out_of_cred_reports_local_nonprimitive); + + OpenAPI_list_add(out_of_cred_reportsList, out_of_cred_reportsItem); + } + } + + cJSON *plmn_id = cJSON_GetObjectItemCaseSensitive(events_notificationJSON, "plmnId"); + + OpenAPI_plmn_id_t *plmn_id_local_nonprim = NULL; + if (plmn_id) { + plmn_id_local_nonprim = OpenAPI_plmn_id_parseFromJSON(plmn_id); + } + + cJSON *qnc_reports = cJSON_GetObjectItemCaseSensitive(events_notificationJSON, "qncReports"); + + OpenAPI_list_t *qnc_reportsList; + if (qnc_reports) { + cJSON *qnc_reports_local_nonprimitive; + if (!cJSON_IsArray(qnc_reports)) { + ogs_error("OpenAPI_events_notification_parseFromJSON() failed [qnc_reports]"); + goto end; + } + + qnc_reportsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(qnc_reports_local_nonprimitive, qnc_reports ) { + if (!cJSON_IsObject(qnc_reports_local_nonprimitive)) { + ogs_error("OpenAPI_events_notification_parseFromJSON() failed [qnc_reports]"); + goto end; + } + OpenAPI_qos_notification_control_info_t *qnc_reportsItem = OpenAPI_qos_notification_control_info_parseFromJSON(qnc_reports_local_nonprimitive); + + OpenAPI_list_add(qnc_reportsList, qnc_reportsItem); + } + } + + cJSON *qos_mon_reports = cJSON_GetObjectItemCaseSensitive(events_notificationJSON, "qosMonReports"); + + OpenAPI_list_t *qos_mon_reportsList; + if (qos_mon_reports) { + cJSON *qos_mon_reports_local_nonprimitive; + if (!cJSON_IsArray(qos_mon_reports)) { + ogs_error("OpenAPI_events_notification_parseFromJSON() failed [qos_mon_reports]"); + goto end; + } + + qos_mon_reportsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(qos_mon_reports_local_nonprimitive, qos_mon_reports ) { + if (!cJSON_IsObject(qos_mon_reports_local_nonprimitive)) { + ogs_error("OpenAPI_events_notification_parseFromJSON() failed [qos_mon_reports]"); + goto end; + } + OpenAPI_qos_monitoring_report_t *qos_mon_reportsItem = OpenAPI_qos_monitoring_report_parseFromJSON(qos_mon_reports_local_nonprimitive); + + OpenAPI_list_add(qos_mon_reportsList, qos_mon_reportsItem); + } + } + + cJSON *ran_nas_rel_causes = cJSON_GetObjectItemCaseSensitive(events_notificationJSON, "ranNasRelCauses"); + + OpenAPI_list_t *ran_nas_rel_causesList; + if (ran_nas_rel_causes) { + cJSON *ran_nas_rel_causes_local_nonprimitive; + if (!cJSON_IsArray(ran_nas_rel_causes)) { + ogs_error("OpenAPI_events_notification_parseFromJSON() failed [ran_nas_rel_causes]"); + goto end; + } + + ran_nas_rel_causesList = OpenAPI_list_create(); + + cJSON_ArrayForEach(ran_nas_rel_causes_local_nonprimitive, ran_nas_rel_causes ) { + if (!cJSON_IsObject(ran_nas_rel_causes_local_nonprimitive)) { + ogs_error("OpenAPI_events_notification_parseFromJSON() failed [ran_nas_rel_causes]"); + goto end; + } + OpenAPI_ran_nas_rel_cause_t *ran_nas_rel_causesItem = OpenAPI_ran_nas_rel_cause_parseFromJSON(ran_nas_rel_causes_local_nonprimitive); + + OpenAPI_list_add(ran_nas_rel_causesList, ran_nas_rel_causesItem); + } + } + + cJSON *rat_type = cJSON_GetObjectItemCaseSensitive(events_notificationJSON, "ratType"); + + OpenAPI_rat_type_e rat_typeVariable; + if (rat_type) { + if (!cJSON_IsString(rat_type)) { + ogs_error("OpenAPI_events_notification_parseFromJSON() failed [rat_type]"); + goto end; + } + rat_typeVariable = OpenAPI_rat_type_FromString(rat_type->valuestring); + } + + cJSON *ue_loc = cJSON_GetObjectItemCaseSensitive(events_notificationJSON, "ueLoc"); + + OpenAPI_user_location_t *ue_loc_local_nonprim = NULL; + if (ue_loc) { + ue_loc_local_nonprim = OpenAPI_user_location_parseFromJSON(ue_loc); + } + + cJSON *ue_time_zone = cJSON_GetObjectItemCaseSensitive(events_notificationJSON, "ueTimeZone"); + + if (ue_time_zone) { + if (!cJSON_IsString(ue_time_zone)) { + ogs_error("OpenAPI_events_notification_parseFromJSON() failed [ue_time_zone]"); + goto end; + } + } + + cJSON *usg_rep = cJSON_GetObjectItemCaseSensitive(events_notificationJSON, "usgRep"); + + OpenAPI_accumulated_usage_t *usg_rep_local_nonprim = NULL; + if (usg_rep) { + usg_rep_local_nonprim = OpenAPI_accumulated_usage_parseFromJSON(usg_rep); + } + + cJSON *tsn_bridge_info = cJSON_GetObjectItemCaseSensitive(events_notificationJSON, "tsnBridgeInfo"); + + OpenAPI_tsn_bridge_info_t *tsn_bridge_info_local_nonprim = NULL; + if (tsn_bridge_info) { + tsn_bridge_info_local_nonprim = OpenAPI_tsn_bridge_info_parseFromJSON(tsn_bridge_info); + } + + cJSON *tsn_port_man_cont_dstt = cJSON_GetObjectItemCaseSensitive(events_notificationJSON, "tsnPortManContDstt"); + + OpenAPI_port_management_container_t *tsn_port_man_cont_dstt_local_nonprim = NULL; + if (tsn_port_man_cont_dstt) { + tsn_port_man_cont_dstt_local_nonprim = OpenAPI_port_management_container_parseFromJSON(tsn_port_man_cont_dstt); + } + + cJSON *tsn_port_man_cont_nwtts = cJSON_GetObjectItemCaseSensitive(events_notificationJSON, "tsnPortManContNwtts"); + + OpenAPI_list_t *tsn_port_man_cont_nwttsList; + if (tsn_port_man_cont_nwtts) { + cJSON *tsn_port_man_cont_nwtts_local_nonprimitive; + if (!cJSON_IsArray(tsn_port_man_cont_nwtts)) { + ogs_error("OpenAPI_events_notification_parseFromJSON() failed [tsn_port_man_cont_nwtts]"); + goto end; + } + + tsn_port_man_cont_nwttsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(tsn_port_man_cont_nwtts_local_nonprimitive, tsn_port_man_cont_nwtts ) { + if (!cJSON_IsObject(tsn_port_man_cont_nwtts_local_nonprimitive)) { + ogs_error("OpenAPI_events_notification_parseFromJSON() failed [tsn_port_man_cont_nwtts]"); + goto end; + } + OpenAPI_port_management_container_t *tsn_port_man_cont_nwttsItem = OpenAPI_port_management_container_parseFromJSON(tsn_port_man_cont_nwtts_local_nonprimitive); + + OpenAPI_list_add(tsn_port_man_cont_nwttsList, tsn_port_man_cont_nwttsItem); + } + } + + events_notification_local_var = OpenAPI_events_notification_create ( + access_type ? access_typeVariable : 0, + an_charg_addr ? an_charg_addr_local_nonprim : NULL, + an_charg_ids ? an_charg_idsList : NULL, + an_gw_addr ? an_gw_addr_local_nonprim : NULL, + ogs_strdup(ev_subs_uri->valuestring), + ev_notifsList, + failed_resourc_alloc_reports ? failed_resourc_alloc_reportsList : NULL, + no_net_loc_supp ? no_net_loc_supp->valueint : 0, + out_of_cred_reports ? out_of_cred_reportsList : NULL, + plmn_id ? plmn_id_local_nonprim : NULL, + qnc_reports ? qnc_reportsList : NULL, + qos_mon_reports ? qos_mon_reportsList : NULL, + ran_nas_rel_causes ? ran_nas_rel_causesList : NULL, + rat_type ? rat_typeVariable : 0, + ue_loc ? ue_loc_local_nonprim : NULL, + ue_time_zone ? ogs_strdup(ue_time_zone->valuestring) : NULL, + usg_rep ? usg_rep_local_nonprim : NULL, + tsn_bridge_info ? tsn_bridge_info_local_nonprim : NULL, + tsn_port_man_cont_dstt ? tsn_port_man_cont_dstt_local_nonprim : NULL, + tsn_port_man_cont_nwtts ? tsn_port_man_cont_nwttsList : NULL + ); + + return events_notification_local_var; +end: + return NULL; +} + +OpenAPI_events_notification_t *OpenAPI_events_notification_copy(OpenAPI_events_notification_t *dst, OpenAPI_events_notification_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_events_notification_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_events_notification_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_events_notification_free(dst); + dst = OpenAPI_events_notification_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/events_notification.h b/lib/sbi/openapi/model/events_notification.h new file mode 100644 index 000000000..d06353e61 --- /dev/null +++ b/lib/sbi/openapi/model/events_notification.h @@ -0,0 +1,92 @@ +/* + * events_notification.h + * + * describes the notification of a matched event + */ + +#ifndef _OpenAPI_events_notification_H_ +#define _OpenAPI_events_notification_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" +#include "acc_net_charging_address.h" +#include "access_net_charging_identifier.h" +#include "access_type.h" +#include "accumulated_usage.h" +#include "af_event_notification.h" +#include "an_gw_address.h" +#include "out_of_credit_information.h" +#include "plmn_id.h" +#include "port_management_container.h" +#include "qos_monitoring_report.h" +#include "qos_notification_control_info.h" +#include "ran_nas_rel_cause.h" +#include "rat_type.h" +#include "resources_allocation_info.h" +#include "tsn_bridge_info.h" +#include "user_location.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_events_notification_s OpenAPI_events_notification_t; +typedef struct OpenAPI_events_notification_s { + OpenAPI_access_type_e access_type; + struct OpenAPI_acc_net_charging_address_s *an_charg_addr; + OpenAPI_list_t *an_charg_ids; + struct OpenAPI_an_gw_address_s *an_gw_addr; + char *ev_subs_uri; + OpenAPI_list_t *ev_notifs; + OpenAPI_list_t *failed_resourc_alloc_reports; + int no_net_loc_supp; + OpenAPI_list_t *out_of_cred_reports; + struct OpenAPI_plmn_id_s *plmn_id; + OpenAPI_list_t *qnc_reports; + OpenAPI_list_t *qos_mon_reports; + OpenAPI_list_t *ran_nas_rel_causes; + OpenAPI_rat_type_e rat_type; + struct OpenAPI_user_location_s *ue_loc; + char *ue_time_zone; + struct OpenAPI_accumulated_usage_s *usg_rep; + struct OpenAPI_tsn_bridge_info_s *tsn_bridge_info; + struct OpenAPI_port_management_container_s *tsn_port_man_cont_dstt; + OpenAPI_list_t *tsn_port_man_cont_nwtts; +} OpenAPI_events_notification_t; + +OpenAPI_events_notification_t *OpenAPI_events_notification_create( + OpenAPI_access_type_e access_type, + OpenAPI_acc_net_charging_address_t *an_charg_addr, + OpenAPI_list_t *an_charg_ids, + OpenAPI_an_gw_address_t *an_gw_addr, + char *ev_subs_uri, + OpenAPI_list_t *ev_notifs, + OpenAPI_list_t *failed_resourc_alloc_reports, + int no_net_loc_supp, + OpenAPI_list_t *out_of_cred_reports, + OpenAPI_plmn_id_t *plmn_id, + OpenAPI_list_t *qnc_reports, + OpenAPI_list_t *qos_mon_reports, + OpenAPI_list_t *ran_nas_rel_causes, + OpenAPI_rat_type_e rat_type, + OpenAPI_user_location_t *ue_loc, + char *ue_time_zone, + OpenAPI_accumulated_usage_t *usg_rep, + OpenAPI_tsn_bridge_info_t *tsn_bridge_info, + OpenAPI_port_management_container_t *tsn_port_man_cont_dstt, + OpenAPI_list_t *tsn_port_man_cont_nwtts + ); +void OpenAPI_events_notification_free(OpenAPI_events_notification_t *events_notification); +OpenAPI_events_notification_t *OpenAPI_events_notification_parseFromJSON(cJSON *events_notificationJSON); +cJSON *OpenAPI_events_notification_convertToJSON(OpenAPI_events_notification_t *events_notification); +OpenAPI_events_notification_t *OpenAPI_events_notification_copy(OpenAPI_events_notification_t *dst, OpenAPI_events_notification_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_events_notification_H_ */ + diff --git a/lib/sbi/openapi/model/events_subsc_req_data.c b/lib/sbi/openapi/model/events_subsc_req_data.c new file mode 100644 index 000000000..2a8d10099 --- /dev/null +++ b/lib/sbi/openapi/model/events_subsc_req_data.c @@ -0,0 +1,286 @@ + +#include +#include +#include +#include "events_subsc_req_data.h" + +OpenAPI_events_subsc_req_data_t *OpenAPI_events_subsc_req_data_create( + OpenAPI_list_t *events, + char *notif_uri, + OpenAPI_list_t *req_qos_mon_params, + OpenAPI_qos_monitoring_information_t *qos_mon, + OpenAPI_required_access_info_e req_ani, + OpenAPI_usage_threshold_t *usg_thres, + char *notif_corre_id + ) +{ + OpenAPI_events_subsc_req_data_t *events_subsc_req_data_local_var = OpenAPI_malloc(sizeof(OpenAPI_events_subsc_req_data_t)); + if (!events_subsc_req_data_local_var) { + return NULL; + } + events_subsc_req_data_local_var->events = events; + events_subsc_req_data_local_var->notif_uri = notif_uri; + events_subsc_req_data_local_var->req_qos_mon_params = req_qos_mon_params; + events_subsc_req_data_local_var->qos_mon = qos_mon; + events_subsc_req_data_local_var->req_ani = req_ani; + events_subsc_req_data_local_var->usg_thres = usg_thres; + events_subsc_req_data_local_var->notif_corre_id = notif_corre_id; + + return events_subsc_req_data_local_var; +} + +void OpenAPI_events_subsc_req_data_free(OpenAPI_events_subsc_req_data_t *events_subsc_req_data) +{ + if (NULL == events_subsc_req_data) { + return; + } + OpenAPI_lnode_t *node; + OpenAPI_list_for_each(events_subsc_req_data->events, node) { + OpenAPI_af_event_subscription_free(node->data); + } + OpenAPI_list_free(events_subsc_req_data->events); + ogs_free(events_subsc_req_data->notif_uri); + OpenAPI_list_free(events_subsc_req_data->req_qos_mon_params); + OpenAPI_qos_monitoring_information_free(events_subsc_req_data->qos_mon); + OpenAPI_usage_threshold_free(events_subsc_req_data->usg_thres); + ogs_free(events_subsc_req_data->notif_corre_id); + ogs_free(events_subsc_req_data); +} + +cJSON *OpenAPI_events_subsc_req_data_convertToJSON(OpenAPI_events_subsc_req_data_t *events_subsc_req_data) +{ + cJSON *item = NULL; + + if (events_subsc_req_data == NULL) { + ogs_error("OpenAPI_events_subsc_req_data_convertToJSON() failed [EventsSubscReqData]"); + return NULL; + } + + item = cJSON_CreateObject(); + cJSON *eventsList = cJSON_AddArrayToObject(item, "events"); + if (eventsList == NULL) { + ogs_error("OpenAPI_events_subsc_req_data_convertToJSON() failed [events]"); + goto end; + } + + OpenAPI_lnode_t *events_node; + if (events_subsc_req_data->events) { + OpenAPI_list_for_each(events_subsc_req_data->events, events_node) { + cJSON *itemLocal = OpenAPI_af_event_subscription_convertToJSON(events_node->data); + if (itemLocal == NULL) { + ogs_error("OpenAPI_events_subsc_req_data_convertToJSON() failed [events]"); + goto end; + } + cJSON_AddItemToArray(eventsList, itemLocal); + } + } + + if (events_subsc_req_data->notif_uri) { + if (cJSON_AddStringToObject(item, "notifUri", events_subsc_req_data->notif_uri) == NULL) { + ogs_error("OpenAPI_events_subsc_req_data_convertToJSON() failed [notif_uri]"); + goto end; + } + } + + if (events_subsc_req_data->req_qos_mon_params) { + cJSON *req_qos_mon_params = cJSON_AddArrayToObject(item, "reqQosMonParams"); + if (req_qos_mon_params == NULL) { + ogs_error("OpenAPI_events_subsc_req_data_convertToJSON() failed [req_qos_mon_params]"); + goto end; + } + OpenAPI_lnode_t *req_qos_mon_params_node; + OpenAPI_list_for_each(events_subsc_req_data->req_qos_mon_params, req_qos_mon_params_node) { + if (cJSON_AddStringToObject(req_qos_mon_params, "", OpenAPI_requested_qos_monitoring_parameter_ToString((intptr_t)req_qos_mon_params_node->data)) == NULL) { + ogs_error("OpenAPI_events_subsc_req_data_convertToJSON() failed [req_qos_mon_params]"); + goto end; + } + } + } + + if (events_subsc_req_data->qos_mon) { + cJSON *qos_mon_local_JSON = OpenAPI_qos_monitoring_information_convertToJSON(events_subsc_req_data->qos_mon); + if (qos_mon_local_JSON == NULL) { + ogs_error("OpenAPI_events_subsc_req_data_convertToJSON() failed [qos_mon]"); + goto end; + } + cJSON_AddItemToObject(item, "qosMon", qos_mon_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_events_subsc_req_data_convertToJSON() failed [qos_mon]"); + goto end; + } + } + + if (events_subsc_req_data->req_ani) { + if (cJSON_AddStringToObject(item, "reqAni", OpenAPI_required_access_info_ToString(events_subsc_req_data->req_ani)) == NULL) { + ogs_error("OpenAPI_events_subsc_req_data_convertToJSON() failed [req_ani]"); + goto end; + } + } + + if (events_subsc_req_data->usg_thres) { + cJSON *usg_thres_local_JSON = OpenAPI_usage_threshold_convertToJSON(events_subsc_req_data->usg_thres); + if (usg_thres_local_JSON == NULL) { + ogs_error("OpenAPI_events_subsc_req_data_convertToJSON() failed [usg_thres]"); + goto end; + } + cJSON_AddItemToObject(item, "usgThres", usg_thres_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_events_subsc_req_data_convertToJSON() failed [usg_thres]"); + goto end; + } + } + + if (events_subsc_req_data->notif_corre_id) { + if (cJSON_AddStringToObject(item, "notifCorreId", events_subsc_req_data->notif_corre_id) == NULL) { + ogs_error("OpenAPI_events_subsc_req_data_convertToJSON() failed [notif_corre_id]"); + goto end; + } + } + +end: + return item; +} + +OpenAPI_events_subsc_req_data_t *OpenAPI_events_subsc_req_data_parseFromJSON(cJSON *events_subsc_req_dataJSON) +{ + OpenAPI_events_subsc_req_data_t *events_subsc_req_data_local_var = NULL; + cJSON *events = cJSON_GetObjectItemCaseSensitive(events_subsc_req_dataJSON, "events"); + if (!events) { + ogs_error("OpenAPI_events_subsc_req_data_parseFromJSON() failed [events]"); + goto end; + } + + OpenAPI_list_t *eventsList; + + cJSON *events_local_nonprimitive; + if (!cJSON_IsArray(events)) { + ogs_error("OpenAPI_events_subsc_req_data_parseFromJSON() failed [events]"); + goto end; + } + + eventsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(events_local_nonprimitive, events ) { + if (!cJSON_IsObject(events_local_nonprimitive)) { + ogs_error("OpenAPI_events_subsc_req_data_parseFromJSON() failed [events]"); + goto end; + } + OpenAPI_af_event_subscription_t *eventsItem = OpenAPI_af_event_subscription_parseFromJSON(events_local_nonprimitive); + + OpenAPI_list_add(eventsList, eventsItem); + } + + cJSON *notif_uri = cJSON_GetObjectItemCaseSensitive(events_subsc_req_dataJSON, "notifUri"); + + if (notif_uri) { + if (!cJSON_IsString(notif_uri)) { + ogs_error("OpenAPI_events_subsc_req_data_parseFromJSON() failed [notif_uri]"); + goto end; + } + } + + cJSON *req_qos_mon_params = cJSON_GetObjectItemCaseSensitive(events_subsc_req_dataJSON, "reqQosMonParams"); + + OpenAPI_list_t *req_qos_mon_paramsList; + if (req_qos_mon_params) { + cJSON *req_qos_mon_params_local_nonprimitive; + if (!cJSON_IsArray(req_qos_mon_params)) { + ogs_error("OpenAPI_events_subsc_req_data_parseFromJSON() failed [req_qos_mon_params]"); + goto end; + } + + req_qos_mon_paramsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(req_qos_mon_params_local_nonprimitive, req_qos_mon_params ) { + if (!cJSON_IsString(req_qos_mon_params_local_nonprimitive)) { + ogs_error("OpenAPI_events_subsc_req_data_parseFromJSON() failed [req_qos_mon_params]"); + goto end; + } + + OpenAPI_list_add(req_qos_mon_paramsList, (void *)OpenAPI_requested_qos_monitoring_parameter_FromString(req_qos_mon_params_local_nonprimitive->valuestring)); + } + } + + cJSON *qos_mon = cJSON_GetObjectItemCaseSensitive(events_subsc_req_dataJSON, "qosMon"); + + OpenAPI_qos_monitoring_information_t *qos_mon_local_nonprim = NULL; + if (qos_mon) { + qos_mon_local_nonprim = OpenAPI_qos_monitoring_information_parseFromJSON(qos_mon); + } + + cJSON *req_ani = cJSON_GetObjectItemCaseSensitive(events_subsc_req_dataJSON, "reqAni"); + + OpenAPI_required_access_info_e req_aniVariable; + if (req_ani) { + if (!cJSON_IsString(req_ani)) { + ogs_error("OpenAPI_events_subsc_req_data_parseFromJSON() failed [req_ani]"); + goto end; + } + req_aniVariable = OpenAPI_required_access_info_FromString(req_ani->valuestring); + } + + cJSON *usg_thres = cJSON_GetObjectItemCaseSensitive(events_subsc_req_dataJSON, "usgThres"); + + OpenAPI_usage_threshold_t *usg_thres_local_nonprim = NULL; + if (usg_thres) { + usg_thres_local_nonprim = OpenAPI_usage_threshold_parseFromJSON(usg_thres); + } + + cJSON *notif_corre_id = cJSON_GetObjectItemCaseSensitive(events_subsc_req_dataJSON, "notifCorreId"); + + if (notif_corre_id) { + if (!cJSON_IsString(notif_corre_id)) { + ogs_error("OpenAPI_events_subsc_req_data_parseFromJSON() failed [notif_corre_id]"); + goto end; + } + } + + events_subsc_req_data_local_var = OpenAPI_events_subsc_req_data_create ( + eventsList, + notif_uri ? ogs_strdup(notif_uri->valuestring) : NULL, + req_qos_mon_params ? req_qos_mon_paramsList : NULL, + qos_mon ? qos_mon_local_nonprim : NULL, + req_ani ? req_aniVariable : 0, + usg_thres ? usg_thres_local_nonprim : NULL, + notif_corre_id ? ogs_strdup(notif_corre_id->valuestring) : NULL + ); + + return events_subsc_req_data_local_var; +end: + return NULL; +} + +OpenAPI_events_subsc_req_data_t *OpenAPI_events_subsc_req_data_copy(OpenAPI_events_subsc_req_data_t *dst, OpenAPI_events_subsc_req_data_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_events_subsc_req_data_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_events_subsc_req_data_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_events_subsc_req_data_free(dst); + dst = OpenAPI_events_subsc_req_data_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/events_subsc_req_data.h b/lib/sbi/openapi/model/events_subsc_req_data.h new file mode 100644 index 000000000..06f704063 --- /dev/null +++ b/lib/sbi/openapi/model/events_subsc_req_data.h @@ -0,0 +1,55 @@ +/* + * events_subsc_req_data.h + * + * Identifies the events the application subscribes to. + */ + +#ifndef _OpenAPI_events_subsc_req_data_H_ +#define _OpenAPI_events_subsc_req_data_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" +#include "af_event_subscription.h" +#include "qos_monitoring_information.h" +#include "requested_qos_monitoring_parameter.h" +#include "required_access_info.h" +#include "usage_threshold.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_events_subsc_req_data_s OpenAPI_events_subsc_req_data_t; +typedef struct OpenAPI_events_subsc_req_data_s { + OpenAPI_list_t *events; + char *notif_uri; + OpenAPI_list_t *req_qos_mon_params; + struct OpenAPI_qos_monitoring_information_s *qos_mon; + OpenAPI_required_access_info_e req_ani; + struct OpenAPI_usage_threshold_s *usg_thres; + char *notif_corre_id; +} OpenAPI_events_subsc_req_data_t; + +OpenAPI_events_subsc_req_data_t *OpenAPI_events_subsc_req_data_create( + OpenAPI_list_t *events, + char *notif_uri, + OpenAPI_list_t *req_qos_mon_params, + OpenAPI_qos_monitoring_information_t *qos_mon, + OpenAPI_required_access_info_e req_ani, + OpenAPI_usage_threshold_t *usg_thres, + char *notif_corre_id + ); +void OpenAPI_events_subsc_req_data_free(OpenAPI_events_subsc_req_data_t *events_subsc_req_data); +OpenAPI_events_subsc_req_data_t *OpenAPI_events_subsc_req_data_parseFromJSON(cJSON *events_subsc_req_dataJSON); +cJSON *OpenAPI_events_subsc_req_data_convertToJSON(OpenAPI_events_subsc_req_data_t *events_subsc_req_data); +OpenAPI_events_subsc_req_data_t *OpenAPI_events_subsc_req_data_copy(OpenAPI_events_subsc_req_data_t *dst, OpenAPI_events_subsc_req_data_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_events_subsc_req_data_H_ */ + diff --git a/lib/sbi/openapi/model/events_subsc_req_data_rm.c b/lib/sbi/openapi/model/events_subsc_req_data_rm.c new file mode 100644 index 000000000..4600066ef --- /dev/null +++ b/lib/sbi/openapi/model/events_subsc_req_data_rm.c @@ -0,0 +1,286 @@ + +#include +#include +#include +#include "events_subsc_req_data_rm.h" + +OpenAPI_events_subsc_req_data_rm_t *OpenAPI_events_subsc_req_data_rm_create( + OpenAPI_list_t *events, + char *notif_uri, + OpenAPI_list_t *req_qos_mon_params, + OpenAPI_qos_monitoring_information_rm_t *qos_mon, + OpenAPI_required_access_info_e req_ani, + OpenAPI_usage_threshold_rm_t *usg_thres, + char *notif_corre_id + ) +{ + OpenAPI_events_subsc_req_data_rm_t *events_subsc_req_data_rm_local_var = OpenAPI_malloc(sizeof(OpenAPI_events_subsc_req_data_rm_t)); + if (!events_subsc_req_data_rm_local_var) { + return NULL; + } + events_subsc_req_data_rm_local_var->events = events; + events_subsc_req_data_rm_local_var->notif_uri = notif_uri; + events_subsc_req_data_rm_local_var->req_qos_mon_params = req_qos_mon_params; + events_subsc_req_data_rm_local_var->qos_mon = qos_mon; + events_subsc_req_data_rm_local_var->req_ani = req_ani; + events_subsc_req_data_rm_local_var->usg_thres = usg_thres; + events_subsc_req_data_rm_local_var->notif_corre_id = notif_corre_id; + + return events_subsc_req_data_rm_local_var; +} + +void OpenAPI_events_subsc_req_data_rm_free(OpenAPI_events_subsc_req_data_rm_t *events_subsc_req_data_rm) +{ + if (NULL == events_subsc_req_data_rm) { + return; + } + OpenAPI_lnode_t *node; + OpenAPI_list_for_each(events_subsc_req_data_rm->events, node) { + OpenAPI_af_event_subscription_free(node->data); + } + OpenAPI_list_free(events_subsc_req_data_rm->events); + ogs_free(events_subsc_req_data_rm->notif_uri); + OpenAPI_list_free(events_subsc_req_data_rm->req_qos_mon_params); + OpenAPI_qos_monitoring_information_rm_free(events_subsc_req_data_rm->qos_mon); + OpenAPI_usage_threshold_rm_free(events_subsc_req_data_rm->usg_thres); + ogs_free(events_subsc_req_data_rm->notif_corre_id); + ogs_free(events_subsc_req_data_rm); +} + +cJSON *OpenAPI_events_subsc_req_data_rm_convertToJSON(OpenAPI_events_subsc_req_data_rm_t *events_subsc_req_data_rm) +{ + cJSON *item = NULL; + + if (events_subsc_req_data_rm == NULL) { + ogs_error("OpenAPI_events_subsc_req_data_rm_convertToJSON() failed [EventsSubscReqDataRm]"); + return NULL; + } + + item = cJSON_CreateObject(); + cJSON *eventsList = cJSON_AddArrayToObject(item, "events"); + if (eventsList == NULL) { + ogs_error("OpenAPI_events_subsc_req_data_rm_convertToJSON() failed [events]"); + goto end; + } + + OpenAPI_lnode_t *events_node; + if (events_subsc_req_data_rm->events) { + OpenAPI_list_for_each(events_subsc_req_data_rm->events, events_node) { + cJSON *itemLocal = OpenAPI_af_event_subscription_convertToJSON(events_node->data); + if (itemLocal == NULL) { + ogs_error("OpenAPI_events_subsc_req_data_rm_convertToJSON() failed [events]"); + goto end; + } + cJSON_AddItemToArray(eventsList, itemLocal); + } + } + + if (events_subsc_req_data_rm->notif_uri) { + if (cJSON_AddStringToObject(item, "notifUri", events_subsc_req_data_rm->notif_uri) == NULL) { + ogs_error("OpenAPI_events_subsc_req_data_rm_convertToJSON() failed [notif_uri]"); + goto end; + } + } + + if (events_subsc_req_data_rm->req_qos_mon_params) { + cJSON *req_qos_mon_params = cJSON_AddArrayToObject(item, "reqQosMonParams"); + if (req_qos_mon_params == NULL) { + ogs_error("OpenAPI_events_subsc_req_data_rm_convertToJSON() failed [req_qos_mon_params]"); + goto end; + } + OpenAPI_lnode_t *req_qos_mon_params_node; + OpenAPI_list_for_each(events_subsc_req_data_rm->req_qos_mon_params, req_qos_mon_params_node) { + if (cJSON_AddStringToObject(req_qos_mon_params, "", OpenAPI_requested_qos_monitoring_parameter_ToString((intptr_t)req_qos_mon_params_node->data)) == NULL) { + ogs_error("OpenAPI_events_subsc_req_data_rm_convertToJSON() failed [req_qos_mon_params]"); + goto end; + } + } + } + + if (events_subsc_req_data_rm->qos_mon) { + cJSON *qos_mon_local_JSON = OpenAPI_qos_monitoring_information_rm_convertToJSON(events_subsc_req_data_rm->qos_mon); + if (qos_mon_local_JSON == NULL) { + ogs_error("OpenAPI_events_subsc_req_data_rm_convertToJSON() failed [qos_mon]"); + goto end; + } + cJSON_AddItemToObject(item, "qosMon", qos_mon_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_events_subsc_req_data_rm_convertToJSON() failed [qos_mon]"); + goto end; + } + } + + if (events_subsc_req_data_rm->req_ani) { + if (cJSON_AddStringToObject(item, "reqAni", OpenAPI_required_access_info_ToString(events_subsc_req_data_rm->req_ani)) == NULL) { + ogs_error("OpenAPI_events_subsc_req_data_rm_convertToJSON() failed [req_ani]"); + goto end; + } + } + + if (events_subsc_req_data_rm->usg_thres) { + cJSON *usg_thres_local_JSON = OpenAPI_usage_threshold_rm_convertToJSON(events_subsc_req_data_rm->usg_thres); + if (usg_thres_local_JSON == NULL) { + ogs_error("OpenAPI_events_subsc_req_data_rm_convertToJSON() failed [usg_thres]"); + goto end; + } + cJSON_AddItemToObject(item, "usgThres", usg_thres_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_events_subsc_req_data_rm_convertToJSON() failed [usg_thres]"); + goto end; + } + } + + if (events_subsc_req_data_rm->notif_corre_id) { + if (cJSON_AddStringToObject(item, "notifCorreId", events_subsc_req_data_rm->notif_corre_id) == NULL) { + ogs_error("OpenAPI_events_subsc_req_data_rm_convertToJSON() failed [notif_corre_id]"); + goto end; + } + } + +end: + return item; +} + +OpenAPI_events_subsc_req_data_rm_t *OpenAPI_events_subsc_req_data_rm_parseFromJSON(cJSON *events_subsc_req_data_rmJSON) +{ + OpenAPI_events_subsc_req_data_rm_t *events_subsc_req_data_rm_local_var = NULL; + cJSON *events = cJSON_GetObjectItemCaseSensitive(events_subsc_req_data_rmJSON, "events"); + if (!events) { + ogs_error("OpenAPI_events_subsc_req_data_rm_parseFromJSON() failed [events]"); + goto end; + } + + OpenAPI_list_t *eventsList; + + cJSON *events_local_nonprimitive; + if (!cJSON_IsArray(events)) { + ogs_error("OpenAPI_events_subsc_req_data_rm_parseFromJSON() failed [events]"); + goto end; + } + + eventsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(events_local_nonprimitive, events ) { + if (!cJSON_IsObject(events_local_nonprimitive)) { + ogs_error("OpenAPI_events_subsc_req_data_rm_parseFromJSON() failed [events]"); + goto end; + } + OpenAPI_af_event_subscription_t *eventsItem = OpenAPI_af_event_subscription_parseFromJSON(events_local_nonprimitive); + + OpenAPI_list_add(eventsList, eventsItem); + } + + cJSON *notif_uri = cJSON_GetObjectItemCaseSensitive(events_subsc_req_data_rmJSON, "notifUri"); + + if (notif_uri) { + if (!cJSON_IsString(notif_uri)) { + ogs_error("OpenAPI_events_subsc_req_data_rm_parseFromJSON() failed [notif_uri]"); + goto end; + } + } + + cJSON *req_qos_mon_params = cJSON_GetObjectItemCaseSensitive(events_subsc_req_data_rmJSON, "reqQosMonParams"); + + OpenAPI_list_t *req_qos_mon_paramsList; + if (req_qos_mon_params) { + cJSON *req_qos_mon_params_local_nonprimitive; + if (!cJSON_IsArray(req_qos_mon_params)) { + ogs_error("OpenAPI_events_subsc_req_data_rm_parseFromJSON() failed [req_qos_mon_params]"); + goto end; + } + + req_qos_mon_paramsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(req_qos_mon_params_local_nonprimitive, req_qos_mon_params ) { + if (!cJSON_IsString(req_qos_mon_params_local_nonprimitive)) { + ogs_error("OpenAPI_events_subsc_req_data_rm_parseFromJSON() failed [req_qos_mon_params]"); + goto end; + } + + OpenAPI_list_add(req_qos_mon_paramsList, (void *)OpenAPI_requested_qos_monitoring_parameter_FromString(req_qos_mon_params_local_nonprimitive->valuestring)); + } + } + + cJSON *qos_mon = cJSON_GetObjectItemCaseSensitive(events_subsc_req_data_rmJSON, "qosMon"); + + OpenAPI_qos_monitoring_information_rm_t *qos_mon_local_nonprim = NULL; + if (qos_mon) { + qos_mon_local_nonprim = OpenAPI_qos_monitoring_information_rm_parseFromJSON(qos_mon); + } + + cJSON *req_ani = cJSON_GetObjectItemCaseSensitive(events_subsc_req_data_rmJSON, "reqAni"); + + OpenAPI_required_access_info_e req_aniVariable; + if (req_ani) { + if (!cJSON_IsString(req_ani)) { + ogs_error("OpenAPI_events_subsc_req_data_rm_parseFromJSON() failed [req_ani]"); + goto end; + } + req_aniVariable = OpenAPI_required_access_info_FromString(req_ani->valuestring); + } + + cJSON *usg_thres = cJSON_GetObjectItemCaseSensitive(events_subsc_req_data_rmJSON, "usgThres"); + + OpenAPI_usage_threshold_rm_t *usg_thres_local_nonprim = NULL; + if (usg_thres) { + usg_thres_local_nonprim = OpenAPI_usage_threshold_rm_parseFromJSON(usg_thres); + } + + cJSON *notif_corre_id = cJSON_GetObjectItemCaseSensitive(events_subsc_req_data_rmJSON, "notifCorreId"); + + if (notif_corre_id) { + if (!cJSON_IsString(notif_corre_id)) { + ogs_error("OpenAPI_events_subsc_req_data_rm_parseFromJSON() failed [notif_corre_id]"); + goto end; + } + } + + events_subsc_req_data_rm_local_var = OpenAPI_events_subsc_req_data_rm_create ( + eventsList, + notif_uri ? ogs_strdup(notif_uri->valuestring) : NULL, + req_qos_mon_params ? req_qos_mon_paramsList : NULL, + qos_mon ? qos_mon_local_nonprim : NULL, + req_ani ? req_aniVariable : 0, + usg_thres ? usg_thres_local_nonprim : NULL, + notif_corre_id ? ogs_strdup(notif_corre_id->valuestring) : NULL + ); + + return events_subsc_req_data_rm_local_var; +end: + return NULL; +} + +OpenAPI_events_subsc_req_data_rm_t *OpenAPI_events_subsc_req_data_rm_copy(OpenAPI_events_subsc_req_data_rm_t *dst, OpenAPI_events_subsc_req_data_rm_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_events_subsc_req_data_rm_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_events_subsc_req_data_rm_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_events_subsc_req_data_rm_free(dst); + dst = OpenAPI_events_subsc_req_data_rm_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/events_subsc_req_data_rm.h b/lib/sbi/openapi/model/events_subsc_req_data_rm.h new file mode 100644 index 000000000..eff8f90ae --- /dev/null +++ b/lib/sbi/openapi/model/events_subsc_req_data_rm.h @@ -0,0 +1,55 @@ +/* + * events_subsc_req_data_rm.h + * + * this data type is defined in the same way as the EventsSubscReqData data type, but with the OpenAPI nullable property set to true. + */ + +#ifndef _OpenAPI_events_subsc_req_data_rm_H_ +#define _OpenAPI_events_subsc_req_data_rm_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" +#include "af_event_subscription.h" +#include "qos_monitoring_information_rm.h" +#include "requested_qos_monitoring_parameter.h" +#include "required_access_info.h" +#include "usage_threshold_rm.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_events_subsc_req_data_rm_s OpenAPI_events_subsc_req_data_rm_t; +typedef struct OpenAPI_events_subsc_req_data_rm_s { + OpenAPI_list_t *events; + char *notif_uri; + OpenAPI_list_t *req_qos_mon_params; + struct OpenAPI_qos_monitoring_information_rm_s *qos_mon; + OpenAPI_required_access_info_e req_ani; + struct OpenAPI_usage_threshold_rm_s *usg_thres; + char *notif_corre_id; +} OpenAPI_events_subsc_req_data_rm_t; + +OpenAPI_events_subsc_req_data_rm_t *OpenAPI_events_subsc_req_data_rm_create( + OpenAPI_list_t *events, + char *notif_uri, + OpenAPI_list_t *req_qos_mon_params, + OpenAPI_qos_monitoring_information_rm_t *qos_mon, + OpenAPI_required_access_info_e req_ani, + OpenAPI_usage_threshold_rm_t *usg_thres, + char *notif_corre_id + ); +void OpenAPI_events_subsc_req_data_rm_free(OpenAPI_events_subsc_req_data_rm_t *events_subsc_req_data_rm); +OpenAPI_events_subsc_req_data_rm_t *OpenAPI_events_subsc_req_data_rm_parseFromJSON(cJSON *events_subsc_req_data_rmJSON); +cJSON *OpenAPI_events_subsc_req_data_rm_convertToJSON(OpenAPI_events_subsc_req_data_rm_t *events_subsc_req_data_rm); +OpenAPI_events_subsc_req_data_rm_t *OpenAPI_events_subsc_req_data_rm_copy(OpenAPI_events_subsc_req_data_rm_t *dst, OpenAPI_events_subsc_req_data_rm_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_events_subsc_req_data_rm_H_ */ + diff --git a/lib/sbi/openapi/model/extended_problem_details.c b/lib/sbi/openapi/model/extended_problem_details.c new file mode 100644 index 000000000..565ab67fb --- /dev/null +++ b/lib/sbi/openapi/model/extended_problem_details.c @@ -0,0 +1,318 @@ + +#include +#include +#include +#include "extended_problem_details.h" + +OpenAPI_extended_problem_details_t *OpenAPI_extended_problem_details_create( + char *type, + char *title, + int status, + char *detail, + char *instance, + char *cause, + OpenAPI_list_t *invalid_params, + char *supported_features, + char *target_scp, + OpenAPI_acceptable_service_info_t *acceptable_serv_info + ) +{ + OpenAPI_extended_problem_details_t *extended_problem_details_local_var = OpenAPI_malloc(sizeof(OpenAPI_extended_problem_details_t)); + if (!extended_problem_details_local_var) { + return NULL; + } + extended_problem_details_local_var->type = type; + extended_problem_details_local_var->title = title; + extended_problem_details_local_var->status = status; + extended_problem_details_local_var->detail = detail; + extended_problem_details_local_var->instance = instance; + extended_problem_details_local_var->cause = cause; + extended_problem_details_local_var->invalid_params = invalid_params; + extended_problem_details_local_var->supported_features = supported_features; + extended_problem_details_local_var->target_scp = target_scp; + extended_problem_details_local_var->acceptable_serv_info = acceptable_serv_info; + + return extended_problem_details_local_var; +} + +void OpenAPI_extended_problem_details_free(OpenAPI_extended_problem_details_t *extended_problem_details) +{ + if (NULL == extended_problem_details) { + return; + } + OpenAPI_lnode_t *node; + ogs_free(extended_problem_details->type); + ogs_free(extended_problem_details->title); + ogs_free(extended_problem_details->detail); + ogs_free(extended_problem_details->instance); + ogs_free(extended_problem_details->cause); + OpenAPI_list_for_each(extended_problem_details->invalid_params, node) { + OpenAPI_invalid_param_free(node->data); + } + OpenAPI_list_free(extended_problem_details->invalid_params); + ogs_free(extended_problem_details->supported_features); + ogs_free(extended_problem_details->target_scp); + OpenAPI_acceptable_service_info_free(extended_problem_details->acceptable_serv_info); + ogs_free(extended_problem_details); +} + +cJSON *OpenAPI_extended_problem_details_convertToJSON(OpenAPI_extended_problem_details_t *extended_problem_details) +{ + cJSON *item = NULL; + + if (extended_problem_details == NULL) { + ogs_error("OpenAPI_extended_problem_details_convertToJSON() failed [ExtendedProblemDetails]"); + return NULL; + } + + item = cJSON_CreateObject(); + if (extended_problem_details->type) { + if (cJSON_AddStringToObject(item, "type", extended_problem_details->type) == NULL) { + ogs_error("OpenAPI_extended_problem_details_convertToJSON() failed [type]"); + goto end; + } + } + + if (extended_problem_details->title) { + if (cJSON_AddStringToObject(item, "title", extended_problem_details->title) == NULL) { + ogs_error("OpenAPI_extended_problem_details_convertToJSON() failed [title]"); + goto end; + } + } + + if (extended_problem_details->status) { + if (cJSON_AddNumberToObject(item, "status", extended_problem_details->status) == NULL) { + ogs_error("OpenAPI_extended_problem_details_convertToJSON() failed [status]"); + goto end; + } + } + + if (extended_problem_details->detail) { + if (cJSON_AddStringToObject(item, "detail", extended_problem_details->detail) == NULL) { + ogs_error("OpenAPI_extended_problem_details_convertToJSON() failed [detail]"); + goto end; + } + } + + if (extended_problem_details->instance) { + if (cJSON_AddStringToObject(item, "instance", extended_problem_details->instance) == NULL) { + ogs_error("OpenAPI_extended_problem_details_convertToJSON() failed [instance]"); + goto end; + } + } + + if (extended_problem_details->cause) { + if (cJSON_AddStringToObject(item, "cause", extended_problem_details->cause) == NULL) { + ogs_error("OpenAPI_extended_problem_details_convertToJSON() failed [cause]"); + goto end; + } + } + + if (extended_problem_details->invalid_params) { + cJSON *invalid_paramsList = cJSON_AddArrayToObject(item, "invalidParams"); + if (invalid_paramsList == NULL) { + ogs_error("OpenAPI_extended_problem_details_convertToJSON() failed [invalid_params]"); + goto end; + } + + OpenAPI_lnode_t *invalid_params_node; + if (extended_problem_details->invalid_params) { + OpenAPI_list_for_each(extended_problem_details->invalid_params, invalid_params_node) { + cJSON *itemLocal = OpenAPI_invalid_param_convertToJSON(invalid_params_node->data); + if (itemLocal == NULL) { + ogs_error("OpenAPI_extended_problem_details_convertToJSON() failed [invalid_params]"); + goto end; + } + cJSON_AddItemToArray(invalid_paramsList, itemLocal); + } + } + } + + if (extended_problem_details->supported_features) { + if (cJSON_AddStringToObject(item, "supportedFeatures", extended_problem_details->supported_features) == NULL) { + ogs_error("OpenAPI_extended_problem_details_convertToJSON() failed [supported_features]"); + goto end; + } + } + + if (extended_problem_details->target_scp) { + if (cJSON_AddStringToObject(item, "targetScp", extended_problem_details->target_scp) == NULL) { + ogs_error("OpenAPI_extended_problem_details_convertToJSON() failed [target_scp]"); + goto end; + } + } + + if (extended_problem_details->acceptable_serv_info) { + cJSON *acceptable_serv_info_local_JSON = OpenAPI_acceptable_service_info_convertToJSON(extended_problem_details->acceptable_serv_info); + if (acceptable_serv_info_local_JSON == NULL) { + ogs_error("OpenAPI_extended_problem_details_convertToJSON() failed [acceptable_serv_info]"); + goto end; + } + cJSON_AddItemToObject(item, "acceptableServInfo", acceptable_serv_info_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_extended_problem_details_convertToJSON() failed [acceptable_serv_info]"); + goto end; + } + } + +end: + return item; +} + +OpenAPI_extended_problem_details_t *OpenAPI_extended_problem_details_parseFromJSON(cJSON *extended_problem_detailsJSON) +{ + OpenAPI_extended_problem_details_t *extended_problem_details_local_var = NULL; + cJSON *type = cJSON_GetObjectItemCaseSensitive(extended_problem_detailsJSON, "type"); + + if (type) { + if (!cJSON_IsString(type)) { + ogs_error("OpenAPI_extended_problem_details_parseFromJSON() failed [type]"); + goto end; + } + } + + cJSON *title = cJSON_GetObjectItemCaseSensitive(extended_problem_detailsJSON, "title"); + + if (title) { + if (!cJSON_IsString(title)) { + ogs_error("OpenAPI_extended_problem_details_parseFromJSON() failed [title]"); + goto end; + } + } + + cJSON *status = cJSON_GetObjectItemCaseSensitive(extended_problem_detailsJSON, "status"); + + if (status) { + if (!cJSON_IsNumber(status)) { + ogs_error("OpenAPI_extended_problem_details_parseFromJSON() failed [status]"); + goto end; + } + } + + cJSON *detail = cJSON_GetObjectItemCaseSensitive(extended_problem_detailsJSON, "detail"); + + if (detail) { + if (!cJSON_IsString(detail)) { + ogs_error("OpenAPI_extended_problem_details_parseFromJSON() failed [detail]"); + goto end; + } + } + + cJSON *instance = cJSON_GetObjectItemCaseSensitive(extended_problem_detailsJSON, "instance"); + + if (instance) { + if (!cJSON_IsString(instance)) { + ogs_error("OpenAPI_extended_problem_details_parseFromJSON() failed [instance]"); + goto end; + } + } + + cJSON *cause = cJSON_GetObjectItemCaseSensitive(extended_problem_detailsJSON, "cause"); + + if (cause) { + if (!cJSON_IsString(cause)) { + ogs_error("OpenAPI_extended_problem_details_parseFromJSON() failed [cause]"); + goto end; + } + } + + cJSON *invalid_params = cJSON_GetObjectItemCaseSensitive(extended_problem_detailsJSON, "invalidParams"); + + OpenAPI_list_t *invalid_paramsList; + if (invalid_params) { + cJSON *invalid_params_local_nonprimitive; + if (!cJSON_IsArray(invalid_params)) { + ogs_error("OpenAPI_extended_problem_details_parseFromJSON() failed [invalid_params]"); + goto end; + } + + invalid_paramsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(invalid_params_local_nonprimitive, invalid_params ) { + if (!cJSON_IsObject(invalid_params_local_nonprimitive)) { + ogs_error("OpenAPI_extended_problem_details_parseFromJSON() failed [invalid_params]"); + goto end; + } + OpenAPI_invalid_param_t *invalid_paramsItem = OpenAPI_invalid_param_parseFromJSON(invalid_params_local_nonprimitive); + + OpenAPI_list_add(invalid_paramsList, invalid_paramsItem); + } + } + + cJSON *supported_features = cJSON_GetObjectItemCaseSensitive(extended_problem_detailsJSON, "supportedFeatures"); + + if (supported_features) { + if (!cJSON_IsString(supported_features)) { + ogs_error("OpenAPI_extended_problem_details_parseFromJSON() failed [supported_features]"); + goto end; + } + } + + cJSON *target_scp = cJSON_GetObjectItemCaseSensitive(extended_problem_detailsJSON, "targetScp"); + + if (target_scp) { + if (!cJSON_IsString(target_scp)) { + ogs_error("OpenAPI_extended_problem_details_parseFromJSON() failed [target_scp]"); + goto end; + } + } + + cJSON *acceptable_serv_info = cJSON_GetObjectItemCaseSensitive(extended_problem_detailsJSON, "acceptableServInfo"); + + OpenAPI_acceptable_service_info_t *acceptable_serv_info_local_nonprim = NULL; + if (acceptable_serv_info) { + acceptable_serv_info_local_nonprim = OpenAPI_acceptable_service_info_parseFromJSON(acceptable_serv_info); + } + + extended_problem_details_local_var = OpenAPI_extended_problem_details_create ( + type ? ogs_strdup(type->valuestring) : NULL, + title ? ogs_strdup(title->valuestring) : NULL, + status ? status->valuedouble : 0, + detail ? ogs_strdup(detail->valuestring) : NULL, + instance ? ogs_strdup(instance->valuestring) : NULL, + cause ? ogs_strdup(cause->valuestring) : NULL, + invalid_params ? invalid_paramsList : NULL, + supported_features ? ogs_strdup(supported_features->valuestring) : NULL, + target_scp ? ogs_strdup(target_scp->valuestring) : NULL, + acceptable_serv_info ? acceptable_serv_info_local_nonprim : NULL + ); + + return extended_problem_details_local_var; +end: + return NULL; +} + +OpenAPI_extended_problem_details_t *OpenAPI_extended_problem_details_copy(OpenAPI_extended_problem_details_t *dst, OpenAPI_extended_problem_details_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_extended_problem_details_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_extended_problem_details_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_extended_problem_details_free(dst); + dst = OpenAPI_extended_problem_details_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/extended_problem_details.h b/lib/sbi/openapi/model/extended_problem_details.h new file mode 100644 index 000000000..d8b823c6f --- /dev/null +++ b/lib/sbi/openapi/model/extended_problem_details.h @@ -0,0 +1,60 @@ +/* + * extended_problem_details.h + * + * Extends ProblemDetails to also include the acceptable service info. + */ + +#ifndef _OpenAPI_extended_problem_details_H_ +#define _OpenAPI_extended_problem_details_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" +#include "acceptable_service_info.h" +#include "extended_problem_details_all_of.h" +#include "invalid_param.h" +#include "problem_details.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_extended_problem_details_s OpenAPI_extended_problem_details_t; +typedef struct OpenAPI_extended_problem_details_s { + char *type; + char *title; + int status; + char *detail; + char *instance; + char *cause; + OpenAPI_list_t *invalid_params; + char *supported_features; + char *target_scp; + struct OpenAPI_acceptable_service_info_s *acceptable_serv_info; +} OpenAPI_extended_problem_details_t; + +OpenAPI_extended_problem_details_t *OpenAPI_extended_problem_details_create( + char *type, + char *title, + int status, + char *detail, + char *instance, + char *cause, + OpenAPI_list_t *invalid_params, + char *supported_features, + char *target_scp, + OpenAPI_acceptable_service_info_t *acceptable_serv_info + ); +void OpenAPI_extended_problem_details_free(OpenAPI_extended_problem_details_t *extended_problem_details); +OpenAPI_extended_problem_details_t *OpenAPI_extended_problem_details_parseFromJSON(cJSON *extended_problem_detailsJSON); +cJSON *OpenAPI_extended_problem_details_convertToJSON(OpenAPI_extended_problem_details_t *extended_problem_details); +OpenAPI_extended_problem_details_t *OpenAPI_extended_problem_details_copy(OpenAPI_extended_problem_details_t *dst, OpenAPI_extended_problem_details_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_extended_problem_details_H_ */ + diff --git a/lib/sbi/openapi/model/extended_problem_details_all_of.c b/lib/sbi/openapi/model/extended_problem_details_all_of.c new file mode 100644 index 000000000..00d515c6c --- /dev/null +++ b/lib/sbi/openapi/model/extended_problem_details_all_of.c @@ -0,0 +1,109 @@ + +#include +#include +#include +#include "extended_problem_details_all_of.h" + +OpenAPI_extended_problem_details_all_of_t *OpenAPI_extended_problem_details_all_of_create( + OpenAPI_acceptable_service_info_t *acceptable_serv_info + ) +{ + OpenAPI_extended_problem_details_all_of_t *extended_problem_details_all_of_local_var = OpenAPI_malloc(sizeof(OpenAPI_extended_problem_details_all_of_t)); + if (!extended_problem_details_all_of_local_var) { + return NULL; + } + extended_problem_details_all_of_local_var->acceptable_serv_info = acceptable_serv_info; + + return extended_problem_details_all_of_local_var; +} + +void OpenAPI_extended_problem_details_all_of_free(OpenAPI_extended_problem_details_all_of_t *extended_problem_details_all_of) +{ + if (NULL == extended_problem_details_all_of) { + return; + } + OpenAPI_lnode_t *node; + OpenAPI_acceptable_service_info_free(extended_problem_details_all_of->acceptable_serv_info); + ogs_free(extended_problem_details_all_of); +} + +cJSON *OpenAPI_extended_problem_details_all_of_convertToJSON(OpenAPI_extended_problem_details_all_of_t *extended_problem_details_all_of) +{ + cJSON *item = NULL; + + if (extended_problem_details_all_of == NULL) { + ogs_error("OpenAPI_extended_problem_details_all_of_convertToJSON() failed [ExtendedProblemDetails_allOf]"); + return NULL; + } + + item = cJSON_CreateObject(); + if (extended_problem_details_all_of->acceptable_serv_info) { + cJSON *acceptable_serv_info_local_JSON = OpenAPI_acceptable_service_info_convertToJSON(extended_problem_details_all_of->acceptable_serv_info); + if (acceptable_serv_info_local_JSON == NULL) { + ogs_error("OpenAPI_extended_problem_details_all_of_convertToJSON() failed [acceptable_serv_info]"); + goto end; + } + cJSON_AddItemToObject(item, "acceptableServInfo", acceptable_serv_info_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_extended_problem_details_all_of_convertToJSON() failed [acceptable_serv_info]"); + goto end; + } + } + +end: + return item; +} + +OpenAPI_extended_problem_details_all_of_t *OpenAPI_extended_problem_details_all_of_parseFromJSON(cJSON *extended_problem_details_all_ofJSON) +{ + OpenAPI_extended_problem_details_all_of_t *extended_problem_details_all_of_local_var = NULL; + cJSON *acceptable_serv_info = cJSON_GetObjectItemCaseSensitive(extended_problem_details_all_ofJSON, "acceptableServInfo"); + + OpenAPI_acceptable_service_info_t *acceptable_serv_info_local_nonprim = NULL; + if (acceptable_serv_info) { + acceptable_serv_info_local_nonprim = OpenAPI_acceptable_service_info_parseFromJSON(acceptable_serv_info); + } + + extended_problem_details_all_of_local_var = OpenAPI_extended_problem_details_all_of_create ( + acceptable_serv_info ? acceptable_serv_info_local_nonprim : NULL + ); + + return extended_problem_details_all_of_local_var; +end: + return NULL; +} + +OpenAPI_extended_problem_details_all_of_t *OpenAPI_extended_problem_details_all_of_copy(OpenAPI_extended_problem_details_all_of_t *dst, OpenAPI_extended_problem_details_all_of_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_extended_problem_details_all_of_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_extended_problem_details_all_of_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_extended_problem_details_all_of_free(dst); + dst = OpenAPI_extended_problem_details_all_of_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/extended_problem_details_all_of.h b/lib/sbi/openapi/model/extended_problem_details_all_of.h new file mode 100644 index 000000000..0569c574d --- /dev/null +++ b/lib/sbi/openapi/model/extended_problem_details_all_of.h @@ -0,0 +1,39 @@ +/* + * extended_problem_details_all_of.h + * + * + */ + +#ifndef _OpenAPI_extended_problem_details_all_of_H_ +#define _OpenAPI_extended_problem_details_all_of_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" +#include "acceptable_service_info.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_extended_problem_details_all_of_s OpenAPI_extended_problem_details_all_of_t; +typedef struct OpenAPI_extended_problem_details_all_of_s { + struct OpenAPI_acceptable_service_info_s *acceptable_serv_info; +} OpenAPI_extended_problem_details_all_of_t; + +OpenAPI_extended_problem_details_all_of_t *OpenAPI_extended_problem_details_all_of_create( + OpenAPI_acceptable_service_info_t *acceptable_serv_info + ); +void OpenAPI_extended_problem_details_all_of_free(OpenAPI_extended_problem_details_all_of_t *extended_problem_details_all_of); +OpenAPI_extended_problem_details_all_of_t *OpenAPI_extended_problem_details_all_of_parseFromJSON(cJSON *extended_problem_details_all_ofJSON); +cJSON *OpenAPI_extended_problem_details_all_of_convertToJSON(OpenAPI_extended_problem_details_all_of_t *extended_problem_details_all_of); +OpenAPI_extended_problem_details_all_of_t *OpenAPI_extended_problem_details_all_of_copy(OpenAPI_extended_problem_details_all_of_t *dst, OpenAPI_extended_problem_details_all_of_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_extended_problem_details_all_of_H_ */ + diff --git a/lib/sbi/openapi/model/flow_status.c b/lib/sbi/openapi/model/flow_status.c index 600253596..2f64ba74f 100644 --- a/lib/sbi/openapi/model/flow_status.c +++ b/lib/sbi/openapi/model/flow_status.c @@ -4,82 +4,27 @@ #include #include "flow_status.h" -OpenAPI_flow_status_t *OpenAPI_flow_status_create( - ) +char* OpenAPI_flow_status_ToString(OpenAPI_flow_status_e flow_status) { - OpenAPI_flow_status_t *flow_status_local_var = OpenAPI_malloc(sizeof(OpenAPI_flow_status_t)); - if (!flow_status_local_var) { - return NULL; - } - - return flow_status_local_var; + const char *flow_statusArray[] = { "NULL", "ENABLED_UPLINK", "ENABLED_DOWNLINK", "ENABLED", "DISABLED", "REMOVED" }; + size_t sizeofArray = sizeof(flow_statusArray) / sizeof(flow_statusArray[0]); + if (flow_status < sizeofArray) + return (char *)flow_statusArray[flow_status]; + else + return (char *)"Unknown"; } -void OpenAPI_flow_status_free(OpenAPI_flow_status_t *flow_status) +OpenAPI_flow_status_e OpenAPI_flow_status_FromString(char* flow_status) { - if (NULL == flow_status) { - return; + int stringToReturn = 0; + const char *flow_statusArray[] = { "NULL", "ENABLED_UPLINK", "ENABLED_DOWNLINK", "ENABLED", "DISABLED", "REMOVED" }; + size_t sizeofArray = sizeof(flow_statusArray) / sizeof(flow_statusArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(flow_status, flow_statusArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; } - OpenAPI_lnode_t *node; - ogs_free(flow_status); -} - -cJSON *OpenAPI_flow_status_convertToJSON(OpenAPI_flow_status_t *flow_status) -{ - cJSON *item = NULL; - - if (flow_status == NULL) { - ogs_error("OpenAPI_flow_status_convertToJSON() failed [FlowStatus]"); - return NULL; - } - - item = cJSON_CreateObject(); -end: - return item; -} - -OpenAPI_flow_status_t *OpenAPI_flow_status_parseFromJSON(cJSON *flow_statusJSON) -{ - OpenAPI_flow_status_t *flow_status_local_var = NULL; - flow_status_local_var = OpenAPI_flow_status_create ( - ); - - return flow_status_local_var; -end: - return NULL; -} - -OpenAPI_flow_status_t *OpenAPI_flow_status_copy(OpenAPI_flow_status_t *dst, OpenAPI_flow_status_t *src) -{ - cJSON *item = NULL; - char *content = NULL; - - ogs_assert(src); - item = OpenAPI_flow_status_convertToJSON(src); - if (!item) { - ogs_error("OpenAPI_flow_status_convertToJSON() failed"); - return NULL; - } - - content = cJSON_Print(item); - cJSON_Delete(item); - - if (!content) { - ogs_error("cJSON_Print() failed"); - return NULL; - } - - item = cJSON_Parse(content); - ogs_free(content); - if (!item) { - ogs_error("cJSON_Parse() failed"); - return NULL; - } - - OpenAPI_flow_status_free(dst); - dst = OpenAPI_flow_status_parseFromJSON(item); - cJSON_Delete(item); - - return dst; + return 0; } diff --git a/lib/sbi/openapi/model/flow_status.h b/lib/sbi/openapi/model/flow_status.h index 3a6ea6a5d..b61a3c411 100644 --- a/lib/sbi/openapi/model/flow_status.h +++ b/lib/sbi/openapi/model/flow_status.h @@ -17,16 +17,11 @@ extern "C" { #endif -typedef struct OpenAPI_flow_status_s OpenAPI_flow_status_t; -typedef struct OpenAPI_flow_status_s { -} OpenAPI_flow_status_t; +typedef enum { OpenAPI_flow_status_NULL = 0, OpenAPI_flow_status_ENABLED_UPLINK, OpenAPI_flow_status_ENABLED_DOWNLINK, OpenAPI_flow_status_ENABLED, OpenAPI_flow_status_DISABLED, OpenAPI_flow_status_REMOVED } OpenAPI_flow_status_e; -OpenAPI_flow_status_t *OpenAPI_flow_status_create( - ); -void OpenAPI_flow_status_free(OpenAPI_flow_status_t *flow_status); -OpenAPI_flow_status_t *OpenAPI_flow_status_parseFromJSON(cJSON *flow_statusJSON); -cJSON *OpenAPI_flow_status_convertToJSON(OpenAPI_flow_status_t *flow_status); -OpenAPI_flow_status_t *OpenAPI_flow_status_copy(OpenAPI_flow_status_t *dst, OpenAPI_flow_status_t *src); +char* OpenAPI_flow_status_ToString(OpenAPI_flow_status_e flow_status); + +OpenAPI_flow_status_e OpenAPI_flow_status_FromString(char* flow_status); #ifdef __cplusplus } diff --git a/lib/sbi/openapi/model/flow_usage.c b/lib/sbi/openapi/model/flow_usage.c new file mode 100644 index 000000000..111d1471f --- /dev/null +++ b/lib/sbi/openapi/model/flow_usage.c @@ -0,0 +1,30 @@ + +#include +#include +#include +#include "flow_usage.h" + +char* OpenAPI_flow_usage_ToString(OpenAPI_flow_usage_e flow_usage) +{ + const char *flow_usageArray[] = { "NULL", "NO_INFO", "RTCP", "AF_SIGNALLING" }; + size_t sizeofArray = sizeof(flow_usageArray) / sizeof(flow_usageArray[0]); + if (flow_usage < sizeofArray) + return (char *)flow_usageArray[flow_usage]; + else + return (char *)"Unknown"; +} + +OpenAPI_flow_usage_e OpenAPI_flow_usage_FromString(char* flow_usage) +{ + int stringToReturn = 0; + const char *flow_usageArray[] = { "NULL", "NO_INFO", "RTCP", "AF_SIGNALLING" }; + size_t sizeofArray = sizeof(flow_usageArray) / sizeof(flow_usageArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(flow_usage, flow_usageArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; + } + return 0; +} + diff --git a/lib/sbi/openapi/model/flow_usage.h b/lib/sbi/openapi/model/flow_usage.h new file mode 100644 index 000000000..e1e9b0a38 --- /dev/null +++ b/lib/sbi/openapi/model/flow_usage.h @@ -0,0 +1,31 @@ +/* + * flow_usage.h + * + * + */ + +#ifndef _OpenAPI_flow_usage_H_ +#define _OpenAPI_flow_usage_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { OpenAPI_flow_usage_NULL = 0, OpenAPI_flow_usage_NO_INFO, OpenAPI_flow_usage_RTCP, OpenAPI_flow_usage_AF_SIGNALLING } OpenAPI_flow_usage_e; + +char* OpenAPI_flow_usage_ToString(OpenAPI_flow_usage_e flow_usage); + +OpenAPI_flow_usage_e OpenAPI_flow_usage_FromString(char* flow_usage); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_flow_usage_H_ */ + diff --git a/lib/sbi/openapi/model/flows.c b/lib/sbi/openapi/model/flows.c new file mode 100644 index 000000000..b1a64f013 --- /dev/null +++ b/lib/sbi/openapi/model/flows.c @@ -0,0 +1,191 @@ + +#include +#include +#include +#include "flows.h" + +OpenAPI_flows_t *OpenAPI_flows_create( + OpenAPI_list_t *cont_vers, + OpenAPI_list_t *f_nums, + int med_comp_n + ) +{ + OpenAPI_flows_t *flows_local_var = OpenAPI_malloc(sizeof(OpenAPI_flows_t)); + if (!flows_local_var) { + return NULL; + } + flows_local_var->cont_vers = cont_vers; + flows_local_var->f_nums = f_nums; + flows_local_var->med_comp_n = med_comp_n; + + return flows_local_var; +} + +void OpenAPI_flows_free(OpenAPI_flows_t *flows) +{ + if (NULL == flows) { + return; + } + OpenAPI_lnode_t *node; + OpenAPI_list_for_each(flows->cont_vers, node) { + ogs_free(node->data); + } + OpenAPI_list_free(flows->cont_vers); + OpenAPI_list_for_each(flows->f_nums, node) { + ogs_free(node->data); + } + OpenAPI_list_free(flows->f_nums); + ogs_free(flows); +} + +cJSON *OpenAPI_flows_convertToJSON(OpenAPI_flows_t *flows) +{ + cJSON *item = NULL; + + if (flows == NULL) { + ogs_error("OpenAPI_flows_convertToJSON() failed [Flows]"); + return NULL; + } + + item = cJSON_CreateObject(); + if (flows->cont_vers) { + cJSON *cont_vers = cJSON_AddArrayToObject(item, "contVers"); + if (cont_vers == NULL) { + ogs_error("OpenAPI_flows_convertToJSON() failed [cont_vers]"); + goto end; + } + + OpenAPI_lnode_t *cont_vers_node; + OpenAPI_list_for_each(flows->cont_vers, cont_vers_node) { + if (cJSON_AddNumberToObject(cont_vers, "", *(double *)cont_vers_node->data) == NULL) { + ogs_error("OpenAPI_flows_convertToJSON() failed [cont_vers]"); + goto end; + } + } + } + + if (flows->f_nums) { + cJSON *f_nums = cJSON_AddArrayToObject(item, "fNums"); + if (f_nums == NULL) { + ogs_error("OpenAPI_flows_convertToJSON() failed [f_nums]"); + goto end; + } + + OpenAPI_lnode_t *f_nums_node; + OpenAPI_list_for_each(flows->f_nums, f_nums_node) { + if (cJSON_AddNumberToObject(f_nums, "", *(double *)f_nums_node->data) == NULL) { + ogs_error("OpenAPI_flows_convertToJSON() failed [f_nums]"); + goto end; + } + } + } + + if (cJSON_AddNumberToObject(item, "medCompN", flows->med_comp_n) == NULL) { + ogs_error("OpenAPI_flows_convertToJSON() failed [med_comp_n]"); + goto end; + } + +end: + return item; +} + +OpenAPI_flows_t *OpenAPI_flows_parseFromJSON(cJSON *flowsJSON) +{ + OpenAPI_flows_t *flows_local_var = NULL; + cJSON *cont_vers = cJSON_GetObjectItemCaseSensitive(flowsJSON, "contVers"); + + OpenAPI_list_t *cont_versList; + if (cont_vers) { + cJSON *cont_vers_local; + if (!cJSON_IsArray(cont_vers)) { + ogs_error("OpenAPI_flows_parseFromJSON() failed [cont_vers]"); + goto end; + } + cont_versList = OpenAPI_list_create(); + + cJSON_ArrayForEach(cont_vers_local, cont_vers) { + if (!cJSON_IsNumber(cont_vers_local)) { + ogs_error("OpenAPI_flows_parseFromJSON() failed [cont_vers]"); + goto end; + } + OpenAPI_list_add(cont_versList, &cont_vers_local->valuedouble); + } + } + + cJSON *f_nums = cJSON_GetObjectItemCaseSensitive(flowsJSON, "fNums"); + + OpenAPI_list_t *f_numsList; + if (f_nums) { + cJSON *f_nums_local; + if (!cJSON_IsArray(f_nums)) { + ogs_error("OpenAPI_flows_parseFromJSON() failed [f_nums]"); + goto end; + } + f_numsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(f_nums_local, f_nums) { + if (!cJSON_IsNumber(f_nums_local)) { + ogs_error("OpenAPI_flows_parseFromJSON() failed [f_nums]"); + goto end; + } + OpenAPI_list_add(f_numsList, &f_nums_local->valuedouble); + } + } + + cJSON *med_comp_n = cJSON_GetObjectItemCaseSensitive(flowsJSON, "medCompN"); + if (!med_comp_n) { + ogs_error("OpenAPI_flows_parseFromJSON() failed [med_comp_n]"); + goto end; + } + + + if (!cJSON_IsNumber(med_comp_n)) { + ogs_error("OpenAPI_flows_parseFromJSON() failed [med_comp_n]"); + goto end; + } + + flows_local_var = OpenAPI_flows_create ( + cont_vers ? cont_versList : NULL, + f_nums ? f_numsList : NULL, + med_comp_n->valuedouble + ); + + return flows_local_var; +end: + return NULL; +} + +OpenAPI_flows_t *OpenAPI_flows_copy(OpenAPI_flows_t *dst, OpenAPI_flows_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_flows_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_flows_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_flows_free(dst); + dst = OpenAPI_flows_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/flows.h b/lib/sbi/openapi/model/flows.h new file mode 100644 index 000000000..aaf6363a1 --- /dev/null +++ b/lib/sbi/openapi/model/flows.h @@ -0,0 +1,42 @@ +/* + * flows.h + * + * Identifies the flows + */ + +#ifndef _OpenAPI_flows_H_ +#define _OpenAPI_flows_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_flows_s OpenAPI_flows_t; +typedef struct OpenAPI_flows_s { + OpenAPI_list_t *cont_vers; + OpenAPI_list_t *f_nums; + int med_comp_n; +} OpenAPI_flows_t; + +OpenAPI_flows_t *OpenAPI_flows_create( + OpenAPI_list_t *cont_vers, + OpenAPI_list_t *f_nums, + int med_comp_n + ); +void OpenAPI_flows_free(OpenAPI_flows_t *flows); +OpenAPI_flows_t *OpenAPI_flows_parseFromJSON(cJSON *flowsJSON); +cJSON *OpenAPI_flows_convertToJSON(OpenAPI_flows_t *flows); +OpenAPI_flows_t *OpenAPI_flows_copy(OpenAPI_flows_t *dst, OpenAPI_flows_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_flows_H_ */ + diff --git a/lib/sbi/openapi/model/ims_vo_ps.c b/lib/sbi/openapi/model/ims_vo_ps.c index 4f42cc65c..9381e5faa 100644 --- a/lib/sbi/openapi/model/ims_vo_ps.c +++ b/lib/sbi/openapi/model/ims_vo_ps.c @@ -4,82 +4,27 @@ #include #include "ims_vo_ps.h" -OpenAPI_ims_vo_ps_t *OpenAPI_ims_vo_ps_create( - ) +char* OpenAPI_ims_vo_ps_ToString(OpenAPI_ims_vo_ps_e ims_vo_ps) { - OpenAPI_ims_vo_ps_t *ims_vo_ps_local_var = OpenAPI_malloc(sizeof(OpenAPI_ims_vo_ps_t)); - if (!ims_vo_ps_local_var) { - return NULL; - } - - return ims_vo_ps_local_var; + const char *ims_vo_psArray[] = { "NULL", "HOMOGENEOUS_SUPPORT", "HOMOGENEOUS_NON_SUPPORT", "NON_HOMOGENEOUS_OR_UNKNOWN" }; + size_t sizeofArray = sizeof(ims_vo_psArray) / sizeof(ims_vo_psArray[0]); + if (ims_vo_ps < sizeofArray) + return (char *)ims_vo_psArray[ims_vo_ps]; + else + return (char *)"Unknown"; } -void OpenAPI_ims_vo_ps_free(OpenAPI_ims_vo_ps_t *ims_vo_ps) +OpenAPI_ims_vo_ps_e OpenAPI_ims_vo_ps_FromString(char* ims_vo_ps) { - if (NULL == ims_vo_ps) { - return; + int stringToReturn = 0; + const char *ims_vo_psArray[] = { "NULL", "HOMOGENEOUS_SUPPORT", "HOMOGENEOUS_NON_SUPPORT", "NON_HOMOGENEOUS_OR_UNKNOWN" }; + size_t sizeofArray = sizeof(ims_vo_psArray) / sizeof(ims_vo_psArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(ims_vo_ps, ims_vo_psArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; } - OpenAPI_lnode_t *node; - ogs_free(ims_vo_ps); -} - -cJSON *OpenAPI_ims_vo_ps_convertToJSON(OpenAPI_ims_vo_ps_t *ims_vo_ps) -{ - cJSON *item = NULL; - - if (ims_vo_ps == NULL) { - ogs_error("OpenAPI_ims_vo_ps_convertToJSON() failed [ImsVoPs]"); - return NULL; - } - - item = cJSON_CreateObject(); -end: - return item; -} - -OpenAPI_ims_vo_ps_t *OpenAPI_ims_vo_ps_parseFromJSON(cJSON *ims_vo_psJSON) -{ - OpenAPI_ims_vo_ps_t *ims_vo_ps_local_var = NULL; - ims_vo_ps_local_var = OpenAPI_ims_vo_ps_create ( - ); - - return ims_vo_ps_local_var; -end: - return NULL; -} - -OpenAPI_ims_vo_ps_t *OpenAPI_ims_vo_ps_copy(OpenAPI_ims_vo_ps_t *dst, OpenAPI_ims_vo_ps_t *src) -{ - cJSON *item = NULL; - char *content = NULL; - - ogs_assert(src); - item = OpenAPI_ims_vo_ps_convertToJSON(src); - if (!item) { - ogs_error("OpenAPI_ims_vo_ps_convertToJSON() failed"); - return NULL; - } - - content = cJSON_Print(item); - cJSON_Delete(item); - - if (!content) { - ogs_error("cJSON_Print() failed"); - return NULL; - } - - item = cJSON_Parse(content); - ogs_free(content); - if (!item) { - ogs_error("cJSON_Parse() failed"); - return NULL; - } - - OpenAPI_ims_vo_ps_free(dst); - dst = OpenAPI_ims_vo_ps_parseFromJSON(item); - cJSON_Delete(item); - - return dst; + return 0; } diff --git a/lib/sbi/openapi/model/ims_vo_ps.h b/lib/sbi/openapi/model/ims_vo_ps.h index 4b777a4ea..22ca73434 100644 --- a/lib/sbi/openapi/model/ims_vo_ps.h +++ b/lib/sbi/openapi/model/ims_vo_ps.h @@ -17,16 +17,11 @@ extern "C" { #endif -typedef struct OpenAPI_ims_vo_ps_s OpenAPI_ims_vo_ps_t; -typedef struct OpenAPI_ims_vo_ps_s { -} OpenAPI_ims_vo_ps_t; +typedef enum { OpenAPI_ims_vo_ps_NULL = 0, OpenAPI_ims_vo_ps_HOMOGENEOUS_SUPPORT, OpenAPI_ims_vo_ps_HOMOGENEOUS_NON_SUPPORT, OpenAPI_ims_vo_ps_NON_HOMOGENEOUS_OR_UNKNOWN } OpenAPI_ims_vo_ps_e; -OpenAPI_ims_vo_ps_t *OpenAPI_ims_vo_ps_create( - ); -void OpenAPI_ims_vo_ps_free(OpenAPI_ims_vo_ps_t *ims_vo_ps); -OpenAPI_ims_vo_ps_t *OpenAPI_ims_vo_ps_parseFromJSON(cJSON *ims_vo_psJSON); -cJSON *OpenAPI_ims_vo_ps_convertToJSON(OpenAPI_ims_vo_ps_t *ims_vo_ps); -OpenAPI_ims_vo_ps_t *OpenAPI_ims_vo_ps_copy(OpenAPI_ims_vo_ps_t *dst, OpenAPI_ims_vo_ps_t *src); +char* OpenAPI_ims_vo_ps_ToString(OpenAPI_ims_vo_ps_e ims_vo_ps); + +OpenAPI_ims_vo_ps_e OpenAPI_ims_vo_ps_FromString(char* ims_vo_ps); #ifdef __cplusplus } diff --git a/lib/sbi/openapi/model/media_component.c b/lib/sbi/openapi/model/media_component.c new file mode 100644 index 000000000..edbcc95c5 --- /dev/null +++ b/lib/sbi/openapi/model/media_component.c @@ -0,0 +1,859 @@ + +#include +#include +#include +#include "media_component.h" + +OpenAPI_media_component_t *OpenAPI_media_component_create( + char *af_app_id, + OpenAPI_af_routing_requirement_t *af_rout_req, + char *qos_reference, + OpenAPI_list_t *alt_ser_reqs, + int cont_ver, + OpenAPI_list_t *codecs, + float des_max_latency, + float des_max_loss, + char *flus_id, + OpenAPI_flow_status_e f_status, + char *mar_bw_dl, + char *mar_bw_ul, + int max_packet_loss_rate_dl, + int max_packet_loss_rate_ul, + char *max_supp_bw_dl, + char *max_supp_bw_ul, + int med_comp_n, + OpenAPI_list_t* med_sub_comps, + OpenAPI_media_type_e med_type, + char *min_des_bw_dl, + char *min_des_bw_ul, + char *mir_bw_dl, + char *mir_bw_ul, + OpenAPI_preemption_capability_e preempt_cap, + OpenAPI_preemption_vulnerability_e preempt_vuln, + OpenAPI_priority_sharing_indicator_e prio_sharing_ind, + OpenAPI_reserv_priority_e res_prio, + char *rr_bw, + char *rs_bw, + int sharing_key_dl, + int sharing_key_ul, + OpenAPI_tsn_qos_container_t *tsn_qos, + OpenAPI_tscai_input_container_t *tscai_input_dl, + OpenAPI_tscai_input_container_t *tscai_input_ul + ) +{ + OpenAPI_media_component_t *media_component_local_var = OpenAPI_malloc(sizeof(OpenAPI_media_component_t)); + if (!media_component_local_var) { + return NULL; + } + media_component_local_var->af_app_id = af_app_id; + media_component_local_var->af_rout_req = af_rout_req; + media_component_local_var->qos_reference = qos_reference; + media_component_local_var->alt_ser_reqs = alt_ser_reqs; + media_component_local_var->cont_ver = cont_ver; + media_component_local_var->codecs = codecs; + media_component_local_var->des_max_latency = des_max_latency; + media_component_local_var->des_max_loss = des_max_loss; + media_component_local_var->flus_id = flus_id; + media_component_local_var->f_status = f_status; + media_component_local_var->mar_bw_dl = mar_bw_dl; + media_component_local_var->mar_bw_ul = mar_bw_ul; + media_component_local_var->max_packet_loss_rate_dl = max_packet_loss_rate_dl; + media_component_local_var->max_packet_loss_rate_ul = max_packet_loss_rate_ul; + media_component_local_var->max_supp_bw_dl = max_supp_bw_dl; + media_component_local_var->max_supp_bw_ul = max_supp_bw_ul; + media_component_local_var->med_comp_n = med_comp_n; + media_component_local_var->med_sub_comps = med_sub_comps; + media_component_local_var->med_type = med_type; + media_component_local_var->min_des_bw_dl = min_des_bw_dl; + media_component_local_var->min_des_bw_ul = min_des_bw_ul; + media_component_local_var->mir_bw_dl = mir_bw_dl; + media_component_local_var->mir_bw_ul = mir_bw_ul; + media_component_local_var->preempt_cap = preempt_cap; + media_component_local_var->preempt_vuln = preempt_vuln; + media_component_local_var->prio_sharing_ind = prio_sharing_ind; + media_component_local_var->res_prio = res_prio; + media_component_local_var->rr_bw = rr_bw; + media_component_local_var->rs_bw = rs_bw; + media_component_local_var->sharing_key_dl = sharing_key_dl; + media_component_local_var->sharing_key_ul = sharing_key_ul; + media_component_local_var->tsn_qos = tsn_qos; + media_component_local_var->tscai_input_dl = tscai_input_dl; + media_component_local_var->tscai_input_ul = tscai_input_ul; + + return media_component_local_var; +} + +void OpenAPI_media_component_free(OpenAPI_media_component_t *media_component) +{ + if (NULL == media_component) { + return; + } + OpenAPI_lnode_t *node; + ogs_free(media_component->af_app_id); + OpenAPI_af_routing_requirement_free(media_component->af_rout_req); + ogs_free(media_component->qos_reference); + OpenAPI_list_for_each(media_component->alt_ser_reqs, node) { + ogs_free(node->data); + } + OpenAPI_list_free(media_component->alt_ser_reqs); + OpenAPI_list_for_each(media_component->codecs, node) { + ogs_free(node->data); + } + OpenAPI_list_free(media_component->codecs); + ogs_free(media_component->flus_id); + ogs_free(media_component->mar_bw_dl); + ogs_free(media_component->mar_bw_ul); + ogs_free(media_component->max_supp_bw_dl); + ogs_free(media_component->max_supp_bw_ul); + OpenAPI_list_for_each(media_component->med_sub_comps, node) { + OpenAPI_map_t *localKeyValue = (OpenAPI_map_t*)node->data; + OpenAPI_media_sub_component_free(localKeyValue->value); + ogs_free(localKeyValue); + } + OpenAPI_list_free(media_component->med_sub_comps); + ogs_free(media_component->min_des_bw_dl); + ogs_free(media_component->min_des_bw_ul); + ogs_free(media_component->mir_bw_dl); + ogs_free(media_component->mir_bw_ul); + ogs_free(media_component->rr_bw); + ogs_free(media_component->rs_bw); + OpenAPI_tsn_qos_container_free(media_component->tsn_qos); + OpenAPI_tscai_input_container_free(media_component->tscai_input_dl); + OpenAPI_tscai_input_container_free(media_component->tscai_input_ul); + ogs_free(media_component); +} + +cJSON *OpenAPI_media_component_convertToJSON(OpenAPI_media_component_t *media_component) +{ + cJSON *item = NULL; + + if (media_component == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [MediaComponent]"); + return NULL; + } + + item = cJSON_CreateObject(); + if (media_component->af_app_id) { + if (cJSON_AddStringToObject(item, "afAppId", media_component->af_app_id) == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [af_app_id]"); + goto end; + } + } + + if (media_component->af_rout_req) { + cJSON *af_rout_req_local_JSON = OpenAPI_af_routing_requirement_convertToJSON(media_component->af_rout_req); + if (af_rout_req_local_JSON == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [af_rout_req]"); + goto end; + } + cJSON_AddItemToObject(item, "afRoutReq", af_rout_req_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [af_rout_req]"); + goto end; + } + } + + if (media_component->qos_reference) { + if (cJSON_AddStringToObject(item, "qosReference", media_component->qos_reference) == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [qos_reference]"); + goto end; + } + } + + if (media_component->alt_ser_reqs) { + cJSON *alt_ser_reqs = cJSON_AddArrayToObject(item, "altSerReqs"); + if (alt_ser_reqs == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [alt_ser_reqs]"); + goto end; + } + + OpenAPI_lnode_t *alt_ser_reqs_node; + OpenAPI_list_for_each(media_component->alt_ser_reqs, alt_ser_reqs_node) { + if (cJSON_AddStringToObject(alt_ser_reqs, "", (char*)alt_ser_reqs_node->data) == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [alt_ser_reqs]"); + goto end; + } + } + } + + if (media_component->cont_ver) { + if (cJSON_AddNumberToObject(item, "contVer", media_component->cont_ver) == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [cont_ver]"); + goto end; + } + } + + if (media_component->codecs) { + cJSON *codecs = cJSON_AddArrayToObject(item, "codecs"); + if (codecs == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [codecs]"); + goto end; + } + + OpenAPI_lnode_t *codecs_node; + OpenAPI_list_for_each(media_component->codecs, codecs_node) { + if (cJSON_AddStringToObject(codecs, "", (char*)codecs_node->data) == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [codecs]"); + goto end; + } + } + } + + if (media_component->des_max_latency) { + if (cJSON_AddNumberToObject(item, "desMaxLatency", media_component->des_max_latency) == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [des_max_latency]"); + goto end; + } + } + + if (media_component->des_max_loss) { + if (cJSON_AddNumberToObject(item, "desMaxLoss", media_component->des_max_loss) == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [des_max_loss]"); + goto end; + } + } + + if (media_component->flus_id) { + if (cJSON_AddStringToObject(item, "flusId", media_component->flus_id) == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [flus_id]"); + goto end; + } + } + + if (media_component->f_status) { + if (cJSON_AddStringToObject(item, "fStatus", OpenAPI_flow_status_ToString(media_component->f_status)) == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [f_status]"); + goto end; + } + } + + if (media_component->mar_bw_dl) { + if (cJSON_AddStringToObject(item, "marBwDl", media_component->mar_bw_dl) == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [mar_bw_dl]"); + goto end; + } + } + + if (media_component->mar_bw_ul) { + if (cJSON_AddStringToObject(item, "marBwUl", media_component->mar_bw_ul) == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [mar_bw_ul]"); + goto end; + } + } + + if (media_component->max_packet_loss_rate_dl) { + if (cJSON_AddNumberToObject(item, "maxPacketLossRateDl", media_component->max_packet_loss_rate_dl) == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [max_packet_loss_rate_dl]"); + goto end; + } + } + + if (media_component->max_packet_loss_rate_ul) { + if (cJSON_AddNumberToObject(item, "maxPacketLossRateUl", media_component->max_packet_loss_rate_ul) == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [max_packet_loss_rate_ul]"); + goto end; + } + } + + if (media_component->max_supp_bw_dl) { + if (cJSON_AddStringToObject(item, "maxSuppBwDl", media_component->max_supp_bw_dl) == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [max_supp_bw_dl]"); + goto end; + } + } + + if (media_component->max_supp_bw_ul) { + if (cJSON_AddStringToObject(item, "maxSuppBwUl", media_component->max_supp_bw_ul) == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [max_supp_bw_ul]"); + goto end; + } + } + + if (cJSON_AddNumberToObject(item, "medCompN", media_component->med_comp_n) == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [med_comp_n]"); + goto end; + } + + if (media_component->med_sub_comps) { + cJSON *med_sub_comps = cJSON_AddObjectToObject(item, "medSubComps"); + if (med_sub_comps == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [med_sub_comps]"); + goto end; + } + cJSON *localMapObject = med_sub_comps; + OpenAPI_lnode_t *med_sub_comps_node; + if (media_component->med_sub_comps) { + OpenAPI_list_for_each(media_component->med_sub_comps, med_sub_comps_node) { + OpenAPI_map_t *localKeyValue = (OpenAPI_map_t*)med_sub_comps_node->data; + cJSON *itemLocal = OpenAPI_media_sub_component_convertToJSON(localKeyValue->value); + if (itemLocal == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [med_sub_comps]"); + goto end; + } + cJSON_AddItemToObject(med_sub_comps, localKeyValue->key, itemLocal); + } + } + } + + if (media_component->med_type) { + if (cJSON_AddStringToObject(item, "medType", OpenAPI_media_type_ToString(media_component->med_type)) == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [med_type]"); + goto end; + } + } + + if (media_component->min_des_bw_dl) { + if (cJSON_AddStringToObject(item, "minDesBwDl", media_component->min_des_bw_dl) == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [min_des_bw_dl]"); + goto end; + } + } + + if (media_component->min_des_bw_ul) { + if (cJSON_AddStringToObject(item, "minDesBwUl", media_component->min_des_bw_ul) == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [min_des_bw_ul]"); + goto end; + } + } + + if (media_component->mir_bw_dl) { + if (cJSON_AddStringToObject(item, "mirBwDl", media_component->mir_bw_dl) == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [mir_bw_dl]"); + goto end; + } + } + + if (media_component->mir_bw_ul) { + if (cJSON_AddStringToObject(item, "mirBwUl", media_component->mir_bw_ul) == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [mir_bw_ul]"); + goto end; + } + } + + if (media_component->preempt_cap) { + if (cJSON_AddStringToObject(item, "preemptCap", OpenAPI_preemption_capability_ToString(media_component->preempt_cap)) == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [preempt_cap]"); + goto end; + } + } + + if (media_component->preempt_vuln) { + if (cJSON_AddStringToObject(item, "preemptVuln", OpenAPI_preemption_vulnerability_ToString(media_component->preempt_vuln)) == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [preempt_vuln]"); + goto end; + } + } + + if (media_component->prio_sharing_ind) { + if (cJSON_AddStringToObject(item, "prioSharingInd", OpenAPI_priority_sharing_indicator_ToString(media_component->prio_sharing_ind)) == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [prio_sharing_ind]"); + goto end; + } + } + + if (media_component->res_prio) { + if (cJSON_AddStringToObject(item, "resPrio", OpenAPI_reserv_priority_ToString(media_component->res_prio)) == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [res_prio]"); + goto end; + } + } + + if (media_component->rr_bw) { + if (cJSON_AddStringToObject(item, "rrBw", media_component->rr_bw) == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [rr_bw]"); + goto end; + } + } + + if (media_component->rs_bw) { + if (cJSON_AddStringToObject(item, "rsBw", media_component->rs_bw) == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [rs_bw]"); + goto end; + } + } + + if (media_component->sharing_key_dl) { + if (cJSON_AddNumberToObject(item, "sharingKeyDl", media_component->sharing_key_dl) == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [sharing_key_dl]"); + goto end; + } + } + + if (media_component->sharing_key_ul) { + if (cJSON_AddNumberToObject(item, "sharingKeyUl", media_component->sharing_key_ul) == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [sharing_key_ul]"); + goto end; + } + } + + if (media_component->tsn_qos) { + cJSON *tsn_qos_local_JSON = OpenAPI_tsn_qos_container_convertToJSON(media_component->tsn_qos); + if (tsn_qos_local_JSON == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [tsn_qos]"); + goto end; + } + cJSON_AddItemToObject(item, "tsnQos", tsn_qos_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [tsn_qos]"); + goto end; + } + } + + if (media_component->tscai_input_dl) { + cJSON *tscai_input_dl_local_JSON = OpenAPI_tscai_input_container_convertToJSON(media_component->tscai_input_dl); + if (tscai_input_dl_local_JSON == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [tscai_input_dl]"); + goto end; + } + cJSON_AddItemToObject(item, "tscaiInputDl", tscai_input_dl_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [tscai_input_dl]"); + goto end; + } + } + + if (media_component->tscai_input_ul) { + cJSON *tscai_input_ul_local_JSON = OpenAPI_tscai_input_container_convertToJSON(media_component->tscai_input_ul); + if (tscai_input_ul_local_JSON == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [tscai_input_ul]"); + goto end; + } + cJSON_AddItemToObject(item, "tscaiInputUl", tscai_input_ul_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_media_component_convertToJSON() failed [tscai_input_ul]"); + goto end; + } + } + +end: + return item; +} + +OpenAPI_media_component_t *OpenAPI_media_component_parseFromJSON(cJSON *media_componentJSON) +{ + OpenAPI_media_component_t *media_component_local_var = NULL; + cJSON *af_app_id = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "afAppId"); + + if (af_app_id) { + if (!cJSON_IsString(af_app_id)) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [af_app_id]"); + goto end; + } + } + + cJSON *af_rout_req = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "afRoutReq"); + + OpenAPI_af_routing_requirement_t *af_rout_req_local_nonprim = NULL; + if (af_rout_req) { + af_rout_req_local_nonprim = OpenAPI_af_routing_requirement_parseFromJSON(af_rout_req); + } + + cJSON *qos_reference = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "qosReference"); + + if (qos_reference) { + if (!cJSON_IsString(qos_reference)) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [qos_reference]"); + goto end; + } + } + + cJSON *alt_ser_reqs = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "altSerReqs"); + + OpenAPI_list_t *alt_ser_reqsList; + if (alt_ser_reqs) { + cJSON *alt_ser_reqs_local; + if (!cJSON_IsArray(alt_ser_reqs)) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [alt_ser_reqs]"); + goto end; + } + alt_ser_reqsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(alt_ser_reqs_local, alt_ser_reqs) { + if (!cJSON_IsString(alt_ser_reqs_local)) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [alt_ser_reqs]"); + goto end; + } + OpenAPI_list_add(alt_ser_reqsList, ogs_strdup(alt_ser_reqs_local->valuestring)); + } + } + + cJSON *cont_ver = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "contVer"); + + if (cont_ver) { + if (!cJSON_IsNumber(cont_ver)) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [cont_ver]"); + goto end; + } + } + + cJSON *codecs = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "codecs"); + + OpenAPI_list_t *codecsList; + if (codecs) { + cJSON *codecs_local; + if (!cJSON_IsArray(codecs)) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [codecs]"); + goto end; + } + codecsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(codecs_local, codecs) { + if (!cJSON_IsString(codecs_local)) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [codecs]"); + goto end; + } + OpenAPI_list_add(codecsList, ogs_strdup(codecs_local->valuestring)); + } + } + + cJSON *des_max_latency = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "desMaxLatency"); + + if (des_max_latency) { + if (!cJSON_IsNumber(des_max_latency)) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [des_max_latency]"); + goto end; + } + } + + cJSON *des_max_loss = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "desMaxLoss"); + + if (des_max_loss) { + if (!cJSON_IsNumber(des_max_loss)) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [des_max_loss]"); + goto end; + } + } + + cJSON *flus_id = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "flusId"); + + if (flus_id) { + if (!cJSON_IsString(flus_id)) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [flus_id]"); + goto end; + } + } + + cJSON *f_status = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "fStatus"); + + OpenAPI_flow_status_e f_statusVariable; + if (f_status) { + if (!cJSON_IsString(f_status)) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [f_status]"); + goto end; + } + f_statusVariable = OpenAPI_flow_status_FromString(f_status->valuestring); + } + + cJSON *mar_bw_dl = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "marBwDl"); + + if (mar_bw_dl) { + if (!cJSON_IsString(mar_bw_dl)) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [mar_bw_dl]"); + goto end; + } + } + + cJSON *mar_bw_ul = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "marBwUl"); + + if (mar_bw_ul) { + if (!cJSON_IsString(mar_bw_ul)) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [mar_bw_ul]"); + goto end; + } + } + + cJSON *max_packet_loss_rate_dl = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "maxPacketLossRateDl"); + + if (max_packet_loss_rate_dl) { + if (!cJSON_IsNumber(max_packet_loss_rate_dl)) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [max_packet_loss_rate_dl]"); + goto end; + } + } + + cJSON *max_packet_loss_rate_ul = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "maxPacketLossRateUl"); + + if (max_packet_loss_rate_ul) { + if (!cJSON_IsNumber(max_packet_loss_rate_ul)) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [max_packet_loss_rate_ul]"); + goto end; + } + } + + cJSON *max_supp_bw_dl = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "maxSuppBwDl"); + + if (max_supp_bw_dl) { + if (!cJSON_IsString(max_supp_bw_dl)) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [max_supp_bw_dl]"); + goto end; + } + } + + cJSON *max_supp_bw_ul = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "maxSuppBwUl"); + + if (max_supp_bw_ul) { + if (!cJSON_IsString(max_supp_bw_ul)) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [max_supp_bw_ul]"); + goto end; + } + } + + cJSON *med_comp_n = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "medCompN"); + if (!med_comp_n) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [med_comp_n]"); + goto end; + } + + + if (!cJSON_IsNumber(med_comp_n)) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [med_comp_n]"); + goto end; + } + + cJSON *med_sub_comps = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "medSubComps"); + + OpenAPI_list_t *med_sub_compsList; + if (med_sub_comps) { + cJSON *med_sub_comps_local_map; + if (!cJSON_IsObject(med_sub_comps)) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [med_sub_comps]"); + goto end; + } + med_sub_compsList = OpenAPI_list_create(); + OpenAPI_map_t *localMapKeyPair = NULL; + cJSON_ArrayForEach(med_sub_comps_local_map, med_sub_comps) { + cJSON *localMapObject = med_sub_comps_local_map; + if (!cJSON_IsObject(med_sub_comps_local_map)) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [med_sub_comps]"); + goto end; + } + localMapKeyPair = OpenAPI_map_create( + localMapObject->string, OpenAPI_media_sub_component_parseFromJSON(localMapObject)); + OpenAPI_list_add(med_sub_compsList, localMapKeyPair); + } + } + + cJSON *med_type = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "medType"); + + OpenAPI_media_type_e med_typeVariable; + if (med_type) { + if (!cJSON_IsString(med_type)) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [med_type]"); + goto end; + } + med_typeVariable = OpenAPI_media_type_FromString(med_type->valuestring); + } + + cJSON *min_des_bw_dl = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "minDesBwDl"); + + if (min_des_bw_dl) { + if (!cJSON_IsString(min_des_bw_dl)) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [min_des_bw_dl]"); + goto end; + } + } + + cJSON *min_des_bw_ul = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "minDesBwUl"); + + if (min_des_bw_ul) { + if (!cJSON_IsString(min_des_bw_ul)) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [min_des_bw_ul]"); + goto end; + } + } + + cJSON *mir_bw_dl = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "mirBwDl"); + + if (mir_bw_dl) { + if (!cJSON_IsString(mir_bw_dl)) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [mir_bw_dl]"); + goto end; + } + } + + cJSON *mir_bw_ul = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "mirBwUl"); + + if (mir_bw_ul) { + if (!cJSON_IsString(mir_bw_ul)) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [mir_bw_ul]"); + goto end; + } + } + + cJSON *preempt_cap = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "preemptCap"); + + OpenAPI_preemption_capability_e preempt_capVariable; + if (preempt_cap) { + if (!cJSON_IsString(preempt_cap)) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [preempt_cap]"); + goto end; + } + preempt_capVariable = OpenAPI_preemption_capability_FromString(preempt_cap->valuestring); + } + + cJSON *preempt_vuln = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "preemptVuln"); + + OpenAPI_preemption_vulnerability_e preempt_vulnVariable; + if (preempt_vuln) { + if (!cJSON_IsString(preempt_vuln)) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [preempt_vuln]"); + goto end; + } + preempt_vulnVariable = OpenAPI_preemption_vulnerability_FromString(preempt_vuln->valuestring); + } + + cJSON *prio_sharing_ind = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "prioSharingInd"); + + OpenAPI_priority_sharing_indicator_e prio_sharing_indVariable; + if (prio_sharing_ind) { + if (!cJSON_IsString(prio_sharing_ind)) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [prio_sharing_ind]"); + goto end; + } + prio_sharing_indVariable = OpenAPI_priority_sharing_indicator_FromString(prio_sharing_ind->valuestring); + } + + cJSON *res_prio = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "resPrio"); + + OpenAPI_reserv_priority_e res_prioVariable; + if (res_prio) { + if (!cJSON_IsString(res_prio)) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [res_prio]"); + goto end; + } + res_prioVariable = OpenAPI_reserv_priority_FromString(res_prio->valuestring); + } + + cJSON *rr_bw = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "rrBw"); + + if (rr_bw) { + if (!cJSON_IsString(rr_bw)) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [rr_bw]"); + goto end; + } + } + + cJSON *rs_bw = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "rsBw"); + + if (rs_bw) { + if (!cJSON_IsString(rs_bw)) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [rs_bw]"); + goto end; + } + } + + cJSON *sharing_key_dl = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "sharingKeyDl"); + + if (sharing_key_dl) { + if (!cJSON_IsNumber(sharing_key_dl)) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [sharing_key_dl]"); + goto end; + } + } + + cJSON *sharing_key_ul = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "sharingKeyUl"); + + if (sharing_key_ul) { + if (!cJSON_IsNumber(sharing_key_ul)) { + ogs_error("OpenAPI_media_component_parseFromJSON() failed [sharing_key_ul]"); + goto end; + } + } + + cJSON *tsn_qos = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "tsnQos"); + + OpenAPI_tsn_qos_container_t *tsn_qos_local_nonprim = NULL; + if (tsn_qos) { + tsn_qos_local_nonprim = OpenAPI_tsn_qos_container_parseFromJSON(tsn_qos); + } + + cJSON *tscai_input_dl = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "tscaiInputDl"); + + OpenAPI_tscai_input_container_t *tscai_input_dl_local_nonprim = NULL; + if (tscai_input_dl) { + tscai_input_dl_local_nonprim = OpenAPI_tscai_input_container_parseFromJSON(tscai_input_dl); + } + + cJSON *tscai_input_ul = cJSON_GetObjectItemCaseSensitive(media_componentJSON, "tscaiInputUl"); + + OpenAPI_tscai_input_container_t *tscai_input_ul_local_nonprim = NULL; + if (tscai_input_ul) { + tscai_input_ul_local_nonprim = OpenAPI_tscai_input_container_parseFromJSON(tscai_input_ul); + } + + media_component_local_var = OpenAPI_media_component_create ( + af_app_id ? ogs_strdup(af_app_id->valuestring) : NULL, + af_rout_req ? af_rout_req_local_nonprim : NULL, + qos_reference ? ogs_strdup(qos_reference->valuestring) : NULL, + alt_ser_reqs ? alt_ser_reqsList : NULL, + cont_ver ? cont_ver->valuedouble : 0, + codecs ? codecsList : NULL, + des_max_latency ? des_max_latency->valuedouble : 0, + des_max_loss ? des_max_loss->valuedouble : 0, + flus_id ? ogs_strdup(flus_id->valuestring) : NULL, + f_status ? f_statusVariable : 0, + mar_bw_dl ? ogs_strdup(mar_bw_dl->valuestring) : NULL, + mar_bw_ul ? ogs_strdup(mar_bw_ul->valuestring) : NULL, + max_packet_loss_rate_dl ? max_packet_loss_rate_dl->valuedouble : 0, + max_packet_loss_rate_ul ? max_packet_loss_rate_ul->valuedouble : 0, + max_supp_bw_dl ? ogs_strdup(max_supp_bw_dl->valuestring) : NULL, + max_supp_bw_ul ? ogs_strdup(max_supp_bw_ul->valuestring) : NULL, + med_comp_n->valuedouble, + med_sub_comps ? med_sub_compsList : NULL, + med_type ? med_typeVariable : 0, + min_des_bw_dl ? ogs_strdup(min_des_bw_dl->valuestring) : NULL, + min_des_bw_ul ? ogs_strdup(min_des_bw_ul->valuestring) : NULL, + mir_bw_dl ? ogs_strdup(mir_bw_dl->valuestring) : NULL, + mir_bw_ul ? ogs_strdup(mir_bw_ul->valuestring) : NULL, + preempt_cap ? preempt_capVariable : 0, + preempt_vuln ? preempt_vulnVariable : 0, + prio_sharing_ind ? prio_sharing_indVariable : 0, + res_prio ? res_prioVariable : 0, + rr_bw ? ogs_strdup(rr_bw->valuestring) : NULL, + rs_bw ? ogs_strdup(rs_bw->valuestring) : NULL, + sharing_key_dl ? sharing_key_dl->valuedouble : 0, + sharing_key_ul ? sharing_key_ul->valuedouble : 0, + tsn_qos ? tsn_qos_local_nonprim : NULL, + tscai_input_dl ? tscai_input_dl_local_nonprim : NULL, + tscai_input_ul ? tscai_input_ul_local_nonprim : NULL + ); + + return media_component_local_var; +end: + return NULL; +} + +OpenAPI_media_component_t *OpenAPI_media_component_copy(OpenAPI_media_component_t *dst, OpenAPI_media_component_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_media_component_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_media_component_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_media_component_free(dst); + dst = OpenAPI_media_component_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/media_component.h b/lib/sbi/openapi/model/media_component.h new file mode 100644 index 000000000..a6e52b618 --- /dev/null +++ b/lib/sbi/openapi/model/media_component.h @@ -0,0 +1,114 @@ +/* + * media_component.h + * + * Identifies a media component. + */ + +#ifndef _OpenAPI_media_component_H_ +#define _OpenAPI_media_component_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" +#include "af_routing_requirement.h" +#include "flow_status.h" +#include "media_sub_component.h" +#include "media_type.h" +#include "preemption_capability.h" +#include "preemption_vulnerability.h" +#include "priority_sharing_indicator.h" +#include "reserv_priority.h" +#include "tscai_input_container.h" +#include "tsn_qos_container.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_media_component_s OpenAPI_media_component_t; +typedef struct OpenAPI_media_component_s { + char *af_app_id; + struct OpenAPI_af_routing_requirement_s *af_rout_req; + char *qos_reference; + OpenAPI_list_t *alt_ser_reqs; + int cont_ver; + OpenAPI_list_t *codecs; + float des_max_latency; + float des_max_loss; + char *flus_id; + OpenAPI_flow_status_e f_status; + char *mar_bw_dl; + char *mar_bw_ul; + int max_packet_loss_rate_dl; + int max_packet_loss_rate_ul; + char *max_supp_bw_dl; + char *max_supp_bw_ul; + int med_comp_n; + OpenAPI_list_t* med_sub_comps; + OpenAPI_media_type_e med_type; + char *min_des_bw_dl; + char *min_des_bw_ul; + char *mir_bw_dl; + char *mir_bw_ul; + OpenAPI_preemption_capability_e preempt_cap; + OpenAPI_preemption_vulnerability_e preempt_vuln; + OpenAPI_priority_sharing_indicator_e prio_sharing_ind; + OpenAPI_reserv_priority_e res_prio; + char *rr_bw; + char *rs_bw; + int sharing_key_dl; + int sharing_key_ul; + struct OpenAPI_tsn_qos_container_s *tsn_qos; + struct OpenAPI_tscai_input_container_s *tscai_input_dl; + struct OpenAPI_tscai_input_container_s *tscai_input_ul; +} OpenAPI_media_component_t; + +OpenAPI_media_component_t *OpenAPI_media_component_create( + char *af_app_id, + OpenAPI_af_routing_requirement_t *af_rout_req, + char *qos_reference, + OpenAPI_list_t *alt_ser_reqs, + int cont_ver, + OpenAPI_list_t *codecs, + float des_max_latency, + float des_max_loss, + char *flus_id, + OpenAPI_flow_status_e f_status, + char *mar_bw_dl, + char *mar_bw_ul, + int max_packet_loss_rate_dl, + int max_packet_loss_rate_ul, + char *max_supp_bw_dl, + char *max_supp_bw_ul, + int med_comp_n, + OpenAPI_list_t* med_sub_comps, + OpenAPI_media_type_e med_type, + char *min_des_bw_dl, + char *min_des_bw_ul, + char *mir_bw_dl, + char *mir_bw_ul, + OpenAPI_preemption_capability_e preempt_cap, + OpenAPI_preemption_vulnerability_e preempt_vuln, + OpenAPI_priority_sharing_indicator_e prio_sharing_ind, + OpenAPI_reserv_priority_e res_prio, + char *rr_bw, + char *rs_bw, + int sharing_key_dl, + int sharing_key_ul, + OpenAPI_tsn_qos_container_t *tsn_qos, + OpenAPI_tscai_input_container_t *tscai_input_dl, + OpenAPI_tscai_input_container_t *tscai_input_ul + ); +void OpenAPI_media_component_free(OpenAPI_media_component_t *media_component); +OpenAPI_media_component_t *OpenAPI_media_component_parseFromJSON(cJSON *media_componentJSON); +cJSON *OpenAPI_media_component_convertToJSON(OpenAPI_media_component_t *media_component); +OpenAPI_media_component_t *OpenAPI_media_component_copy(OpenAPI_media_component_t *dst, OpenAPI_media_component_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_media_component_H_ */ + diff --git a/lib/sbi/openapi/model/media_component_resources_status.c b/lib/sbi/openapi/model/media_component_resources_status.c new file mode 100644 index 000000000..3ff189f23 --- /dev/null +++ b/lib/sbi/openapi/model/media_component_resources_status.c @@ -0,0 +1,30 @@ + +#include +#include +#include +#include "media_component_resources_status.h" + +char* OpenAPI_media_component_resources_status_ToString(OpenAPI_media_component_resources_status_e media_component_resources_status) +{ + const char *media_component_resources_statusArray[] = { "NULL", "ACTIVE", "INACTIVE" }; + size_t sizeofArray = sizeof(media_component_resources_statusArray) / sizeof(media_component_resources_statusArray[0]); + if (media_component_resources_status < sizeofArray) + return (char *)media_component_resources_statusArray[media_component_resources_status]; + else + return (char *)"Unknown"; +} + +OpenAPI_media_component_resources_status_e OpenAPI_media_component_resources_status_FromString(char* media_component_resources_status) +{ + int stringToReturn = 0; + const char *media_component_resources_statusArray[] = { "NULL", "ACTIVE", "INACTIVE" }; + size_t sizeofArray = sizeof(media_component_resources_statusArray) / sizeof(media_component_resources_statusArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(media_component_resources_status, media_component_resources_statusArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; + } + return 0; +} + diff --git a/lib/sbi/openapi/model/media_component_resources_status.h b/lib/sbi/openapi/model/media_component_resources_status.h new file mode 100644 index 000000000..d37636266 --- /dev/null +++ b/lib/sbi/openapi/model/media_component_resources_status.h @@ -0,0 +1,31 @@ +/* + * media_component_resources_status.h + * + * + */ + +#ifndef _OpenAPI_media_component_resources_status_H_ +#define _OpenAPI_media_component_resources_status_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { OpenAPI_media_component_resources_status_NULL = 0, OpenAPI_media_component_resources_status_ACTIVE, OpenAPI_media_component_resources_status_INACTIVE } OpenAPI_media_component_resources_status_e; + +char* OpenAPI_media_component_resources_status_ToString(OpenAPI_media_component_resources_status_e media_component_resources_status); + +OpenAPI_media_component_resources_status_e OpenAPI_media_component_resources_status_FromString(char* media_component_resources_status); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_media_component_resources_status_H_ */ + diff --git a/lib/sbi/openapi/model/media_component_rm.c b/lib/sbi/openapi/model/media_component_rm.c new file mode 100644 index 000000000..6525be804 --- /dev/null +++ b/lib/sbi/openapi/model/media_component_rm.c @@ -0,0 +1,865 @@ + +#include +#include +#include +#include "media_component_rm.h" + +OpenAPI_media_component_rm_t *OpenAPI_media_component_rm_create( + char *af_app_id, + OpenAPI_af_routing_requirement_rm_t *af_rout_req, + char *qos_reference, + OpenAPI_list_t *alt_ser_reqs, + int cont_ver, + OpenAPI_list_t *codecs, + float des_max_latency, + float des_max_loss, + char *flus_id, + OpenAPI_flow_status_e f_status, + char *mar_bw_dl, + char *mar_bw_ul, + int max_packet_loss_rate_dl, + int max_packet_loss_rate_ul, + char *max_supp_bw_dl, + char *max_supp_bw_ul, + int med_comp_n, + OpenAPI_list_t* med_sub_comps, + OpenAPI_media_type_e med_type, + char *min_des_bw_dl, + char *min_des_bw_ul, + char *mir_bw_dl, + char *mir_bw_ul, + OpenAPI_preemption_capability_rm_t *preempt_cap, + OpenAPI_preemption_vulnerability_rm_t *preempt_vuln, + OpenAPI_priority_sharing_indicator_e prio_sharing_ind, + OpenAPI_reserv_priority_e res_prio, + char *rr_bw, + char *rs_bw, + int sharing_key_dl, + int sharing_key_ul, + OpenAPI_tsn_qos_container_rm_t *tsn_qos, + OpenAPI_tscai_input_container_t *tscai_input_dl, + OpenAPI_tscai_input_container_t *tscai_input_ul + ) +{ + OpenAPI_media_component_rm_t *media_component_rm_local_var = OpenAPI_malloc(sizeof(OpenAPI_media_component_rm_t)); + if (!media_component_rm_local_var) { + return NULL; + } + media_component_rm_local_var->af_app_id = af_app_id; + media_component_rm_local_var->af_rout_req = af_rout_req; + media_component_rm_local_var->qos_reference = qos_reference; + media_component_rm_local_var->alt_ser_reqs = alt_ser_reqs; + media_component_rm_local_var->cont_ver = cont_ver; + media_component_rm_local_var->codecs = codecs; + media_component_rm_local_var->des_max_latency = des_max_latency; + media_component_rm_local_var->des_max_loss = des_max_loss; + media_component_rm_local_var->flus_id = flus_id; + media_component_rm_local_var->f_status = f_status; + media_component_rm_local_var->mar_bw_dl = mar_bw_dl; + media_component_rm_local_var->mar_bw_ul = mar_bw_ul; + media_component_rm_local_var->max_packet_loss_rate_dl = max_packet_loss_rate_dl; + media_component_rm_local_var->max_packet_loss_rate_ul = max_packet_loss_rate_ul; + media_component_rm_local_var->max_supp_bw_dl = max_supp_bw_dl; + media_component_rm_local_var->max_supp_bw_ul = max_supp_bw_ul; + media_component_rm_local_var->med_comp_n = med_comp_n; + media_component_rm_local_var->med_sub_comps = med_sub_comps; + media_component_rm_local_var->med_type = med_type; + media_component_rm_local_var->min_des_bw_dl = min_des_bw_dl; + media_component_rm_local_var->min_des_bw_ul = min_des_bw_ul; + media_component_rm_local_var->mir_bw_dl = mir_bw_dl; + media_component_rm_local_var->mir_bw_ul = mir_bw_ul; + media_component_rm_local_var->preempt_cap = preempt_cap; + media_component_rm_local_var->preempt_vuln = preempt_vuln; + media_component_rm_local_var->prio_sharing_ind = prio_sharing_ind; + media_component_rm_local_var->res_prio = res_prio; + media_component_rm_local_var->rr_bw = rr_bw; + media_component_rm_local_var->rs_bw = rs_bw; + media_component_rm_local_var->sharing_key_dl = sharing_key_dl; + media_component_rm_local_var->sharing_key_ul = sharing_key_ul; + media_component_rm_local_var->tsn_qos = tsn_qos; + media_component_rm_local_var->tscai_input_dl = tscai_input_dl; + media_component_rm_local_var->tscai_input_ul = tscai_input_ul; + + return media_component_rm_local_var; +} + +void OpenAPI_media_component_rm_free(OpenAPI_media_component_rm_t *media_component_rm) +{ + if (NULL == media_component_rm) { + return; + } + OpenAPI_lnode_t *node; + ogs_free(media_component_rm->af_app_id); + OpenAPI_af_routing_requirement_rm_free(media_component_rm->af_rout_req); + ogs_free(media_component_rm->qos_reference); + OpenAPI_list_for_each(media_component_rm->alt_ser_reqs, node) { + ogs_free(node->data); + } + OpenAPI_list_free(media_component_rm->alt_ser_reqs); + OpenAPI_list_for_each(media_component_rm->codecs, node) { + ogs_free(node->data); + } + OpenAPI_list_free(media_component_rm->codecs); + ogs_free(media_component_rm->flus_id); + ogs_free(media_component_rm->mar_bw_dl); + ogs_free(media_component_rm->mar_bw_ul); + ogs_free(media_component_rm->max_supp_bw_dl); + ogs_free(media_component_rm->max_supp_bw_ul); + OpenAPI_list_for_each(media_component_rm->med_sub_comps, node) { + OpenAPI_map_t *localKeyValue = (OpenAPI_map_t*)node->data; + OpenAPI_media_sub_component_rm_free(localKeyValue->value); + ogs_free(localKeyValue); + } + OpenAPI_list_free(media_component_rm->med_sub_comps); + ogs_free(media_component_rm->min_des_bw_dl); + ogs_free(media_component_rm->min_des_bw_ul); + ogs_free(media_component_rm->mir_bw_dl); + ogs_free(media_component_rm->mir_bw_ul); + OpenAPI_preemption_capability_rm_free(media_component_rm->preempt_cap); + OpenAPI_preemption_vulnerability_rm_free(media_component_rm->preempt_vuln); + ogs_free(media_component_rm->rr_bw); + ogs_free(media_component_rm->rs_bw); + OpenAPI_tsn_qos_container_rm_free(media_component_rm->tsn_qos); + OpenAPI_tscai_input_container_free(media_component_rm->tscai_input_dl); + OpenAPI_tscai_input_container_free(media_component_rm->tscai_input_ul); + ogs_free(media_component_rm); +} + +cJSON *OpenAPI_media_component_rm_convertToJSON(OpenAPI_media_component_rm_t *media_component_rm) +{ + cJSON *item = NULL; + + if (media_component_rm == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [MediaComponentRm]"); + return NULL; + } + + item = cJSON_CreateObject(); + if (media_component_rm->af_app_id) { + if (cJSON_AddStringToObject(item, "afAppId", media_component_rm->af_app_id) == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [af_app_id]"); + goto end; + } + } + + if (media_component_rm->af_rout_req) { + cJSON *af_rout_req_local_JSON = OpenAPI_af_routing_requirement_rm_convertToJSON(media_component_rm->af_rout_req); + if (af_rout_req_local_JSON == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [af_rout_req]"); + goto end; + } + cJSON_AddItemToObject(item, "afRoutReq", af_rout_req_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [af_rout_req]"); + goto end; + } + } + + if (media_component_rm->qos_reference) { + if (cJSON_AddStringToObject(item, "qosReference", media_component_rm->qos_reference) == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [qos_reference]"); + goto end; + } + } + + if (media_component_rm->alt_ser_reqs) { + cJSON *alt_ser_reqs = cJSON_AddArrayToObject(item, "altSerReqs"); + if (alt_ser_reqs == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [alt_ser_reqs]"); + goto end; + } + + OpenAPI_lnode_t *alt_ser_reqs_node; + OpenAPI_list_for_each(media_component_rm->alt_ser_reqs, alt_ser_reqs_node) { + if (cJSON_AddStringToObject(alt_ser_reqs, "", (char*)alt_ser_reqs_node->data) == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [alt_ser_reqs]"); + goto end; + } + } + } + + if (media_component_rm->cont_ver) { + if (cJSON_AddNumberToObject(item, "contVer", media_component_rm->cont_ver) == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [cont_ver]"); + goto end; + } + } + + if (media_component_rm->codecs) { + cJSON *codecs = cJSON_AddArrayToObject(item, "codecs"); + if (codecs == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [codecs]"); + goto end; + } + + OpenAPI_lnode_t *codecs_node; + OpenAPI_list_for_each(media_component_rm->codecs, codecs_node) { + if (cJSON_AddStringToObject(codecs, "", (char*)codecs_node->data) == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [codecs]"); + goto end; + } + } + } + + if (media_component_rm->des_max_latency) { + if (cJSON_AddNumberToObject(item, "desMaxLatency", media_component_rm->des_max_latency) == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [des_max_latency]"); + goto end; + } + } + + if (media_component_rm->des_max_loss) { + if (cJSON_AddNumberToObject(item, "desMaxLoss", media_component_rm->des_max_loss) == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [des_max_loss]"); + goto end; + } + } + + if (media_component_rm->flus_id) { + if (cJSON_AddStringToObject(item, "flusId", media_component_rm->flus_id) == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [flus_id]"); + goto end; + } + } + + if (media_component_rm->f_status) { + if (cJSON_AddStringToObject(item, "fStatus", OpenAPI_flow_status_ToString(media_component_rm->f_status)) == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [f_status]"); + goto end; + } + } + + if (media_component_rm->mar_bw_dl) { + if (cJSON_AddStringToObject(item, "marBwDl", media_component_rm->mar_bw_dl) == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [mar_bw_dl]"); + goto end; + } + } + + if (media_component_rm->mar_bw_ul) { + if (cJSON_AddStringToObject(item, "marBwUl", media_component_rm->mar_bw_ul) == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [mar_bw_ul]"); + goto end; + } + } + + if (media_component_rm->max_packet_loss_rate_dl) { + if (cJSON_AddNumberToObject(item, "maxPacketLossRateDl", media_component_rm->max_packet_loss_rate_dl) == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [max_packet_loss_rate_dl]"); + goto end; + } + } + + if (media_component_rm->max_packet_loss_rate_ul) { + if (cJSON_AddNumberToObject(item, "maxPacketLossRateUl", media_component_rm->max_packet_loss_rate_ul) == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [max_packet_loss_rate_ul]"); + goto end; + } + } + + if (media_component_rm->max_supp_bw_dl) { + if (cJSON_AddStringToObject(item, "maxSuppBwDl", media_component_rm->max_supp_bw_dl) == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [max_supp_bw_dl]"); + goto end; + } + } + + if (media_component_rm->max_supp_bw_ul) { + if (cJSON_AddStringToObject(item, "maxSuppBwUl", media_component_rm->max_supp_bw_ul) == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [max_supp_bw_ul]"); + goto end; + } + } + + if (cJSON_AddNumberToObject(item, "medCompN", media_component_rm->med_comp_n) == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [med_comp_n]"); + goto end; + } + + if (media_component_rm->med_sub_comps) { + cJSON *med_sub_comps = cJSON_AddObjectToObject(item, "medSubComps"); + if (med_sub_comps == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [med_sub_comps]"); + goto end; + } + cJSON *localMapObject = med_sub_comps; + OpenAPI_lnode_t *med_sub_comps_node; + if (media_component_rm->med_sub_comps) { + OpenAPI_list_for_each(media_component_rm->med_sub_comps, med_sub_comps_node) { + OpenAPI_map_t *localKeyValue = (OpenAPI_map_t*)med_sub_comps_node->data; + cJSON *itemLocal = OpenAPI_media_sub_component_rm_convertToJSON(localKeyValue->value); + if (itemLocal == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [med_sub_comps]"); + goto end; + } + cJSON_AddItemToObject(med_sub_comps, localKeyValue->key, itemLocal); + } + } + } + + if (media_component_rm->med_type) { + if (cJSON_AddStringToObject(item, "medType", OpenAPI_media_type_ToString(media_component_rm->med_type)) == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [med_type]"); + goto end; + } + } + + if (media_component_rm->min_des_bw_dl) { + if (cJSON_AddStringToObject(item, "minDesBwDl", media_component_rm->min_des_bw_dl) == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [min_des_bw_dl]"); + goto end; + } + } + + if (media_component_rm->min_des_bw_ul) { + if (cJSON_AddStringToObject(item, "minDesBwUl", media_component_rm->min_des_bw_ul) == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [min_des_bw_ul]"); + goto end; + } + } + + if (media_component_rm->mir_bw_dl) { + if (cJSON_AddStringToObject(item, "mirBwDl", media_component_rm->mir_bw_dl) == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [mir_bw_dl]"); + goto end; + } + } + + if (media_component_rm->mir_bw_ul) { + if (cJSON_AddStringToObject(item, "mirBwUl", media_component_rm->mir_bw_ul) == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [mir_bw_ul]"); + goto end; + } + } + + if (media_component_rm->preempt_cap) { + cJSON *preempt_cap_local_JSON = OpenAPI_preemption_capability_rm_convertToJSON(media_component_rm->preempt_cap); + if (preempt_cap_local_JSON == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [preempt_cap]"); + goto end; + } + cJSON_AddItemToObject(item, "preemptCap", preempt_cap_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [preempt_cap]"); + goto end; + } + } + + if (media_component_rm->preempt_vuln) { + cJSON *preempt_vuln_local_JSON = OpenAPI_preemption_vulnerability_rm_convertToJSON(media_component_rm->preempt_vuln); + if (preempt_vuln_local_JSON == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [preempt_vuln]"); + goto end; + } + cJSON_AddItemToObject(item, "preemptVuln", preempt_vuln_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [preempt_vuln]"); + goto end; + } + } + + if (media_component_rm->prio_sharing_ind) { + if (cJSON_AddStringToObject(item, "prioSharingInd", OpenAPI_priority_sharing_indicator_ToString(media_component_rm->prio_sharing_ind)) == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [prio_sharing_ind]"); + goto end; + } + } + + if (media_component_rm->res_prio) { + if (cJSON_AddStringToObject(item, "resPrio", OpenAPI_reserv_priority_ToString(media_component_rm->res_prio)) == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [res_prio]"); + goto end; + } + } + + if (media_component_rm->rr_bw) { + if (cJSON_AddStringToObject(item, "rrBw", media_component_rm->rr_bw) == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [rr_bw]"); + goto end; + } + } + + if (media_component_rm->rs_bw) { + if (cJSON_AddStringToObject(item, "rsBw", media_component_rm->rs_bw) == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [rs_bw]"); + goto end; + } + } + + if (media_component_rm->sharing_key_dl) { + if (cJSON_AddNumberToObject(item, "sharingKeyDl", media_component_rm->sharing_key_dl) == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [sharing_key_dl]"); + goto end; + } + } + + if (media_component_rm->sharing_key_ul) { + if (cJSON_AddNumberToObject(item, "sharingKeyUl", media_component_rm->sharing_key_ul) == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [sharing_key_ul]"); + goto end; + } + } + + if (media_component_rm->tsn_qos) { + cJSON *tsn_qos_local_JSON = OpenAPI_tsn_qos_container_rm_convertToJSON(media_component_rm->tsn_qos); + if (tsn_qos_local_JSON == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [tsn_qos]"); + goto end; + } + cJSON_AddItemToObject(item, "tsnQos", tsn_qos_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [tsn_qos]"); + goto end; + } + } + + if (media_component_rm->tscai_input_dl) { + cJSON *tscai_input_dl_local_JSON = OpenAPI_tscai_input_container_convertToJSON(media_component_rm->tscai_input_dl); + if (tscai_input_dl_local_JSON == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [tscai_input_dl]"); + goto end; + } + cJSON_AddItemToObject(item, "tscaiInputDl", tscai_input_dl_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [tscai_input_dl]"); + goto end; + } + } + + if (media_component_rm->tscai_input_ul) { + cJSON *tscai_input_ul_local_JSON = OpenAPI_tscai_input_container_convertToJSON(media_component_rm->tscai_input_ul); + if (tscai_input_ul_local_JSON == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [tscai_input_ul]"); + goto end; + } + cJSON_AddItemToObject(item, "tscaiInputUl", tscai_input_ul_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed [tscai_input_ul]"); + goto end; + } + } + +end: + return item; +} + +OpenAPI_media_component_rm_t *OpenAPI_media_component_rm_parseFromJSON(cJSON *media_component_rmJSON) +{ + OpenAPI_media_component_rm_t *media_component_rm_local_var = NULL; + cJSON *af_app_id = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "afAppId"); + + if (af_app_id) { + if (!cJSON_IsString(af_app_id)) { + ogs_error("OpenAPI_media_component_rm_parseFromJSON() failed [af_app_id]"); + goto end; + } + } + + cJSON *af_rout_req = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "afRoutReq"); + + OpenAPI_af_routing_requirement_rm_t *af_rout_req_local_nonprim = NULL; + if (af_rout_req) { + af_rout_req_local_nonprim = OpenAPI_af_routing_requirement_rm_parseFromJSON(af_rout_req); + } + + cJSON *qos_reference = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "qosReference"); + + if (qos_reference) { + if (!cJSON_IsString(qos_reference)) { + ogs_error("OpenAPI_media_component_rm_parseFromJSON() failed [qos_reference]"); + goto end; + } + } + + cJSON *alt_ser_reqs = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "altSerReqs"); + + OpenAPI_list_t *alt_ser_reqsList; + if (alt_ser_reqs) { + cJSON *alt_ser_reqs_local; + if (!cJSON_IsArray(alt_ser_reqs)) { + ogs_error("OpenAPI_media_component_rm_parseFromJSON() failed [alt_ser_reqs]"); + goto end; + } + alt_ser_reqsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(alt_ser_reqs_local, alt_ser_reqs) { + if (!cJSON_IsString(alt_ser_reqs_local)) { + ogs_error("OpenAPI_media_component_rm_parseFromJSON() failed [alt_ser_reqs]"); + goto end; + } + OpenAPI_list_add(alt_ser_reqsList, ogs_strdup(alt_ser_reqs_local->valuestring)); + } + } + + cJSON *cont_ver = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "contVer"); + + if (cont_ver) { + if (!cJSON_IsNumber(cont_ver)) { + ogs_error("OpenAPI_media_component_rm_parseFromJSON() failed [cont_ver]"); + goto end; + } + } + + cJSON *codecs = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "codecs"); + + OpenAPI_list_t *codecsList; + if (codecs) { + cJSON *codecs_local; + if (!cJSON_IsArray(codecs)) { + ogs_error("OpenAPI_media_component_rm_parseFromJSON() failed [codecs]"); + goto end; + } + codecsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(codecs_local, codecs) { + if (!cJSON_IsString(codecs_local)) { + ogs_error("OpenAPI_media_component_rm_parseFromJSON() failed [codecs]"); + goto end; + } + OpenAPI_list_add(codecsList, ogs_strdup(codecs_local->valuestring)); + } + } + + cJSON *des_max_latency = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "desMaxLatency"); + + if (des_max_latency) { + if (!cJSON_IsNumber(des_max_latency)) { + ogs_error("OpenAPI_media_component_rm_parseFromJSON() failed [des_max_latency]"); + goto end; + } + } + + cJSON *des_max_loss = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "desMaxLoss"); + + if (des_max_loss) { + if (!cJSON_IsNumber(des_max_loss)) { + ogs_error("OpenAPI_media_component_rm_parseFromJSON() failed [des_max_loss]"); + goto end; + } + } + + cJSON *flus_id = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "flusId"); + + if (flus_id) { + if (!cJSON_IsString(flus_id)) { + ogs_error("OpenAPI_media_component_rm_parseFromJSON() failed [flus_id]"); + goto end; + } + } + + cJSON *f_status = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "fStatus"); + + OpenAPI_flow_status_e f_statusVariable; + if (f_status) { + if (!cJSON_IsString(f_status)) { + ogs_error("OpenAPI_media_component_rm_parseFromJSON() failed [f_status]"); + goto end; + } + f_statusVariable = OpenAPI_flow_status_FromString(f_status->valuestring); + } + + cJSON *mar_bw_dl = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "marBwDl"); + + if (mar_bw_dl) { + if (!cJSON_IsString(mar_bw_dl)) { + ogs_error("OpenAPI_media_component_rm_parseFromJSON() failed [mar_bw_dl]"); + goto end; + } + } + + cJSON *mar_bw_ul = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "marBwUl"); + + if (mar_bw_ul) { + if (!cJSON_IsString(mar_bw_ul)) { + ogs_error("OpenAPI_media_component_rm_parseFromJSON() failed [mar_bw_ul]"); + goto end; + } + } + + cJSON *max_packet_loss_rate_dl = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "maxPacketLossRateDl"); + + if (max_packet_loss_rate_dl) { + if (!cJSON_IsNumber(max_packet_loss_rate_dl)) { + ogs_error("OpenAPI_media_component_rm_parseFromJSON() failed [max_packet_loss_rate_dl]"); + goto end; + } + } + + cJSON *max_packet_loss_rate_ul = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "maxPacketLossRateUl"); + + if (max_packet_loss_rate_ul) { + if (!cJSON_IsNumber(max_packet_loss_rate_ul)) { + ogs_error("OpenAPI_media_component_rm_parseFromJSON() failed [max_packet_loss_rate_ul]"); + goto end; + } + } + + cJSON *max_supp_bw_dl = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "maxSuppBwDl"); + + if (max_supp_bw_dl) { + if (!cJSON_IsString(max_supp_bw_dl)) { + ogs_error("OpenAPI_media_component_rm_parseFromJSON() failed [max_supp_bw_dl]"); + goto end; + } + } + + cJSON *max_supp_bw_ul = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "maxSuppBwUl"); + + if (max_supp_bw_ul) { + if (!cJSON_IsString(max_supp_bw_ul)) { + ogs_error("OpenAPI_media_component_rm_parseFromJSON() failed [max_supp_bw_ul]"); + goto end; + } + } + + cJSON *med_comp_n = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "medCompN"); + if (!med_comp_n) { + ogs_error("OpenAPI_media_component_rm_parseFromJSON() failed [med_comp_n]"); + goto end; + } + + + if (!cJSON_IsNumber(med_comp_n)) { + ogs_error("OpenAPI_media_component_rm_parseFromJSON() failed [med_comp_n]"); + goto end; + } + + cJSON *med_sub_comps = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "medSubComps"); + + OpenAPI_list_t *med_sub_compsList; + if (med_sub_comps) { + cJSON *med_sub_comps_local_map; + if (!cJSON_IsObject(med_sub_comps)) { + ogs_error("OpenAPI_media_component_rm_parseFromJSON() failed [med_sub_comps]"); + goto end; + } + med_sub_compsList = OpenAPI_list_create(); + OpenAPI_map_t *localMapKeyPair = NULL; + cJSON_ArrayForEach(med_sub_comps_local_map, med_sub_comps) { + cJSON *localMapObject = med_sub_comps_local_map; + if (!cJSON_IsObject(med_sub_comps_local_map)) { + ogs_error("OpenAPI_media_component_rm_parseFromJSON() failed [med_sub_comps]"); + goto end; + } + localMapKeyPair = OpenAPI_map_create( + localMapObject->string, OpenAPI_media_sub_component_rm_parseFromJSON(localMapObject)); + OpenAPI_list_add(med_sub_compsList, localMapKeyPair); + } + } + + cJSON *med_type = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "medType"); + + OpenAPI_media_type_e med_typeVariable; + if (med_type) { + if (!cJSON_IsString(med_type)) { + ogs_error("OpenAPI_media_component_rm_parseFromJSON() failed [med_type]"); + goto end; + } + med_typeVariable = OpenAPI_media_type_FromString(med_type->valuestring); + } + + cJSON *min_des_bw_dl = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "minDesBwDl"); + + if (min_des_bw_dl) { + if (!cJSON_IsString(min_des_bw_dl)) { + ogs_error("OpenAPI_media_component_rm_parseFromJSON() failed [min_des_bw_dl]"); + goto end; + } + } + + cJSON *min_des_bw_ul = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "minDesBwUl"); + + if (min_des_bw_ul) { + if (!cJSON_IsString(min_des_bw_ul)) { + ogs_error("OpenAPI_media_component_rm_parseFromJSON() failed [min_des_bw_ul]"); + goto end; + } + } + + cJSON *mir_bw_dl = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "mirBwDl"); + + if (mir_bw_dl) { + if (!cJSON_IsString(mir_bw_dl)) { + ogs_error("OpenAPI_media_component_rm_parseFromJSON() failed [mir_bw_dl]"); + goto end; + } + } + + cJSON *mir_bw_ul = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "mirBwUl"); + + if (mir_bw_ul) { + if (!cJSON_IsString(mir_bw_ul)) { + ogs_error("OpenAPI_media_component_rm_parseFromJSON() failed [mir_bw_ul]"); + goto end; + } + } + + cJSON *preempt_cap = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "preemptCap"); + + OpenAPI_preemption_capability_rm_t *preempt_cap_local_nonprim = NULL; + if (preempt_cap) { + preempt_cap_local_nonprim = OpenAPI_preemption_capability_rm_parseFromJSON(preempt_cap); + } + + cJSON *preempt_vuln = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "preemptVuln"); + + OpenAPI_preemption_vulnerability_rm_t *preempt_vuln_local_nonprim = NULL; + if (preempt_vuln) { + preempt_vuln_local_nonprim = OpenAPI_preemption_vulnerability_rm_parseFromJSON(preempt_vuln); + } + + cJSON *prio_sharing_ind = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "prioSharingInd"); + + OpenAPI_priority_sharing_indicator_e prio_sharing_indVariable; + if (prio_sharing_ind) { + if (!cJSON_IsString(prio_sharing_ind)) { + ogs_error("OpenAPI_media_component_rm_parseFromJSON() failed [prio_sharing_ind]"); + goto end; + } + prio_sharing_indVariable = OpenAPI_priority_sharing_indicator_FromString(prio_sharing_ind->valuestring); + } + + cJSON *res_prio = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "resPrio"); + + OpenAPI_reserv_priority_e res_prioVariable; + if (res_prio) { + if (!cJSON_IsString(res_prio)) { + ogs_error("OpenAPI_media_component_rm_parseFromJSON() failed [res_prio]"); + goto end; + } + res_prioVariable = OpenAPI_reserv_priority_FromString(res_prio->valuestring); + } + + cJSON *rr_bw = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "rrBw"); + + if (rr_bw) { + if (!cJSON_IsString(rr_bw)) { + ogs_error("OpenAPI_media_component_rm_parseFromJSON() failed [rr_bw]"); + goto end; + } + } + + cJSON *rs_bw = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "rsBw"); + + if (rs_bw) { + if (!cJSON_IsString(rs_bw)) { + ogs_error("OpenAPI_media_component_rm_parseFromJSON() failed [rs_bw]"); + goto end; + } + } + + cJSON *sharing_key_dl = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "sharingKeyDl"); + + if (sharing_key_dl) { + if (!cJSON_IsNumber(sharing_key_dl)) { + ogs_error("OpenAPI_media_component_rm_parseFromJSON() failed [sharing_key_dl]"); + goto end; + } + } + + cJSON *sharing_key_ul = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "sharingKeyUl"); + + if (sharing_key_ul) { + if (!cJSON_IsNumber(sharing_key_ul)) { + ogs_error("OpenAPI_media_component_rm_parseFromJSON() failed [sharing_key_ul]"); + goto end; + } + } + + cJSON *tsn_qos = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "tsnQos"); + + OpenAPI_tsn_qos_container_rm_t *tsn_qos_local_nonprim = NULL; + if (tsn_qos) { + tsn_qos_local_nonprim = OpenAPI_tsn_qos_container_rm_parseFromJSON(tsn_qos); + } + + cJSON *tscai_input_dl = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "tscaiInputDl"); + + OpenAPI_tscai_input_container_t *tscai_input_dl_local_nonprim = NULL; + if (tscai_input_dl) { + tscai_input_dl_local_nonprim = OpenAPI_tscai_input_container_parseFromJSON(tscai_input_dl); + } + + cJSON *tscai_input_ul = cJSON_GetObjectItemCaseSensitive(media_component_rmJSON, "tscaiInputUl"); + + OpenAPI_tscai_input_container_t *tscai_input_ul_local_nonprim = NULL; + if (tscai_input_ul) { + tscai_input_ul_local_nonprim = OpenAPI_tscai_input_container_parseFromJSON(tscai_input_ul); + } + + media_component_rm_local_var = OpenAPI_media_component_rm_create ( + af_app_id ? ogs_strdup(af_app_id->valuestring) : NULL, + af_rout_req ? af_rout_req_local_nonprim : NULL, + qos_reference ? ogs_strdup(qos_reference->valuestring) : NULL, + alt_ser_reqs ? alt_ser_reqsList : NULL, + cont_ver ? cont_ver->valuedouble : 0, + codecs ? codecsList : NULL, + des_max_latency ? des_max_latency->valuedouble : 0, + des_max_loss ? des_max_loss->valuedouble : 0, + flus_id ? ogs_strdup(flus_id->valuestring) : NULL, + f_status ? f_statusVariable : 0, + mar_bw_dl ? ogs_strdup(mar_bw_dl->valuestring) : NULL, + mar_bw_ul ? ogs_strdup(mar_bw_ul->valuestring) : NULL, + max_packet_loss_rate_dl ? max_packet_loss_rate_dl->valuedouble : 0, + max_packet_loss_rate_ul ? max_packet_loss_rate_ul->valuedouble : 0, + max_supp_bw_dl ? ogs_strdup(max_supp_bw_dl->valuestring) : NULL, + max_supp_bw_ul ? ogs_strdup(max_supp_bw_ul->valuestring) : NULL, + med_comp_n->valuedouble, + med_sub_comps ? med_sub_compsList : NULL, + med_type ? med_typeVariable : 0, + min_des_bw_dl ? ogs_strdup(min_des_bw_dl->valuestring) : NULL, + min_des_bw_ul ? ogs_strdup(min_des_bw_ul->valuestring) : NULL, + mir_bw_dl ? ogs_strdup(mir_bw_dl->valuestring) : NULL, + mir_bw_ul ? ogs_strdup(mir_bw_ul->valuestring) : NULL, + preempt_cap ? preempt_cap_local_nonprim : NULL, + preempt_vuln ? preempt_vuln_local_nonprim : NULL, + prio_sharing_ind ? prio_sharing_indVariable : 0, + res_prio ? res_prioVariable : 0, + rr_bw ? ogs_strdup(rr_bw->valuestring) : NULL, + rs_bw ? ogs_strdup(rs_bw->valuestring) : NULL, + sharing_key_dl ? sharing_key_dl->valuedouble : 0, + sharing_key_ul ? sharing_key_ul->valuedouble : 0, + tsn_qos ? tsn_qos_local_nonprim : NULL, + tscai_input_dl ? tscai_input_dl_local_nonprim : NULL, + tscai_input_ul ? tscai_input_ul_local_nonprim : NULL + ); + + return media_component_rm_local_var; +end: + return NULL; +} + +OpenAPI_media_component_rm_t *OpenAPI_media_component_rm_copy(OpenAPI_media_component_rm_t *dst, OpenAPI_media_component_rm_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_media_component_rm_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_media_component_rm_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_media_component_rm_free(dst); + dst = OpenAPI_media_component_rm_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/media_component_rm.h b/lib/sbi/openapi/model/media_component_rm.h new file mode 100644 index 000000000..afc2b033a --- /dev/null +++ b/lib/sbi/openapi/model/media_component_rm.h @@ -0,0 +1,114 @@ +/* + * media_component_rm.h + * + * This data type is defined in the same way as the MediaComponent data type, but with the OpenAPI nullable property set to true + */ + +#ifndef _OpenAPI_media_component_rm_H_ +#define _OpenAPI_media_component_rm_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" +#include "af_routing_requirement_rm.h" +#include "flow_status.h" +#include "media_sub_component_rm.h" +#include "media_type.h" +#include "preemption_capability_rm.h" +#include "preemption_vulnerability_rm.h" +#include "priority_sharing_indicator.h" +#include "reserv_priority.h" +#include "tscai_input_container.h" +#include "tsn_qos_container_rm.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_media_component_rm_s OpenAPI_media_component_rm_t; +typedef struct OpenAPI_media_component_rm_s { + char *af_app_id; + struct OpenAPI_af_routing_requirement_rm_s *af_rout_req; + char *qos_reference; + OpenAPI_list_t *alt_ser_reqs; + int cont_ver; + OpenAPI_list_t *codecs; + float des_max_latency; + float des_max_loss; + char *flus_id; + OpenAPI_flow_status_e f_status; + char *mar_bw_dl; + char *mar_bw_ul; + int max_packet_loss_rate_dl; + int max_packet_loss_rate_ul; + char *max_supp_bw_dl; + char *max_supp_bw_ul; + int med_comp_n; + OpenAPI_list_t* med_sub_comps; + OpenAPI_media_type_e med_type; + char *min_des_bw_dl; + char *min_des_bw_ul; + char *mir_bw_dl; + char *mir_bw_ul; + struct OpenAPI_preemption_capability_rm_s *preempt_cap; + struct OpenAPI_preemption_vulnerability_rm_s *preempt_vuln; + OpenAPI_priority_sharing_indicator_e prio_sharing_ind; + OpenAPI_reserv_priority_e res_prio; + char *rr_bw; + char *rs_bw; + int sharing_key_dl; + int sharing_key_ul; + struct OpenAPI_tsn_qos_container_rm_s *tsn_qos; + struct OpenAPI_tscai_input_container_s *tscai_input_dl; + struct OpenAPI_tscai_input_container_s *tscai_input_ul; +} OpenAPI_media_component_rm_t; + +OpenAPI_media_component_rm_t *OpenAPI_media_component_rm_create( + char *af_app_id, + OpenAPI_af_routing_requirement_rm_t *af_rout_req, + char *qos_reference, + OpenAPI_list_t *alt_ser_reqs, + int cont_ver, + OpenAPI_list_t *codecs, + float des_max_latency, + float des_max_loss, + char *flus_id, + OpenAPI_flow_status_e f_status, + char *mar_bw_dl, + char *mar_bw_ul, + int max_packet_loss_rate_dl, + int max_packet_loss_rate_ul, + char *max_supp_bw_dl, + char *max_supp_bw_ul, + int med_comp_n, + OpenAPI_list_t* med_sub_comps, + OpenAPI_media_type_e med_type, + char *min_des_bw_dl, + char *min_des_bw_ul, + char *mir_bw_dl, + char *mir_bw_ul, + OpenAPI_preemption_capability_rm_t *preempt_cap, + OpenAPI_preemption_vulnerability_rm_t *preempt_vuln, + OpenAPI_priority_sharing_indicator_e prio_sharing_ind, + OpenAPI_reserv_priority_e res_prio, + char *rr_bw, + char *rs_bw, + int sharing_key_dl, + int sharing_key_ul, + OpenAPI_tsn_qos_container_rm_t *tsn_qos, + OpenAPI_tscai_input_container_t *tscai_input_dl, + OpenAPI_tscai_input_container_t *tscai_input_ul + ); +void OpenAPI_media_component_rm_free(OpenAPI_media_component_rm_t *media_component_rm); +OpenAPI_media_component_rm_t *OpenAPI_media_component_rm_parseFromJSON(cJSON *media_component_rmJSON); +cJSON *OpenAPI_media_component_rm_convertToJSON(OpenAPI_media_component_rm_t *media_component_rm); +OpenAPI_media_component_rm_t *OpenAPI_media_component_rm_copy(OpenAPI_media_component_rm_t *dst, OpenAPI_media_component_rm_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_media_component_rm_H_ */ + diff --git a/lib/sbi/openapi/model/media_sub_component.c b/lib/sbi/openapi/model/media_sub_component.c new file mode 100644 index 000000000..fefb4fb3a --- /dev/null +++ b/lib/sbi/openapi/model/media_sub_component.c @@ -0,0 +1,369 @@ + +#include +#include +#include +#include "media_sub_component.h" + +OpenAPI_media_sub_component_t *OpenAPI_media_sub_component_create( + OpenAPI_af_sig_protocol_e af_sig_protocol, + OpenAPI_list_t *ethf_descs, + int f_num, + OpenAPI_list_t *f_descs, + OpenAPI_flow_status_e f_status, + char *mar_bw_dl, + char *mar_bw_ul, + char *tos_tr_cl, + OpenAPI_flow_usage_e flow_usage, + OpenAPI_tscai_input_container_t *tscai_input_dl, + OpenAPI_tscai_input_container_t *tscai_input_ul + ) +{ + OpenAPI_media_sub_component_t *media_sub_component_local_var = OpenAPI_malloc(sizeof(OpenAPI_media_sub_component_t)); + if (!media_sub_component_local_var) { + return NULL; + } + media_sub_component_local_var->af_sig_protocol = af_sig_protocol; + media_sub_component_local_var->ethf_descs = ethf_descs; + media_sub_component_local_var->f_num = f_num; + media_sub_component_local_var->f_descs = f_descs; + media_sub_component_local_var->f_status = f_status; + media_sub_component_local_var->mar_bw_dl = mar_bw_dl; + media_sub_component_local_var->mar_bw_ul = mar_bw_ul; + media_sub_component_local_var->tos_tr_cl = tos_tr_cl; + media_sub_component_local_var->flow_usage = flow_usage; + media_sub_component_local_var->tscai_input_dl = tscai_input_dl; + media_sub_component_local_var->tscai_input_ul = tscai_input_ul; + + return media_sub_component_local_var; +} + +void OpenAPI_media_sub_component_free(OpenAPI_media_sub_component_t *media_sub_component) +{ + if (NULL == media_sub_component) { + return; + } + OpenAPI_lnode_t *node; + OpenAPI_list_for_each(media_sub_component->ethf_descs, node) { + OpenAPI_eth_flow_description_free(node->data); + } + OpenAPI_list_free(media_sub_component->ethf_descs); + OpenAPI_list_for_each(media_sub_component->f_descs, node) { + ogs_free(node->data); + } + OpenAPI_list_free(media_sub_component->f_descs); + ogs_free(media_sub_component->mar_bw_dl); + ogs_free(media_sub_component->mar_bw_ul); + ogs_free(media_sub_component->tos_tr_cl); + OpenAPI_tscai_input_container_free(media_sub_component->tscai_input_dl); + OpenAPI_tscai_input_container_free(media_sub_component->tscai_input_ul); + ogs_free(media_sub_component); +} + +cJSON *OpenAPI_media_sub_component_convertToJSON(OpenAPI_media_sub_component_t *media_sub_component) +{ + cJSON *item = NULL; + + if (media_sub_component == NULL) { + ogs_error("OpenAPI_media_sub_component_convertToJSON() failed [MediaSubComponent]"); + return NULL; + } + + item = cJSON_CreateObject(); + if (media_sub_component->af_sig_protocol) { + if (cJSON_AddStringToObject(item, "afSigProtocol", OpenAPI_af_sig_protocol_ToString(media_sub_component->af_sig_protocol)) == NULL) { + ogs_error("OpenAPI_media_sub_component_convertToJSON() failed [af_sig_protocol]"); + goto end; + } + } + + if (media_sub_component->ethf_descs) { + cJSON *ethf_descsList = cJSON_AddArrayToObject(item, "ethfDescs"); + if (ethf_descsList == NULL) { + ogs_error("OpenAPI_media_sub_component_convertToJSON() failed [ethf_descs]"); + goto end; + } + + OpenAPI_lnode_t *ethf_descs_node; + if (media_sub_component->ethf_descs) { + OpenAPI_list_for_each(media_sub_component->ethf_descs, ethf_descs_node) { + cJSON *itemLocal = OpenAPI_eth_flow_description_convertToJSON(ethf_descs_node->data); + if (itemLocal == NULL) { + ogs_error("OpenAPI_media_sub_component_convertToJSON() failed [ethf_descs]"); + goto end; + } + cJSON_AddItemToArray(ethf_descsList, itemLocal); + } + } + } + + if (cJSON_AddNumberToObject(item, "fNum", media_sub_component->f_num) == NULL) { + ogs_error("OpenAPI_media_sub_component_convertToJSON() failed [f_num]"); + goto end; + } + + if (media_sub_component->f_descs) { + cJSON *f_descs = cJSON_AddArrayToObject(item, "fDescs"); + if (f_descs == NULL) { + ogs_error("OpenAPI_media_sub_component_convertToJSON() failed [f_descs]"); + goto end; + } + + OpenAPI_lnode_t *f_descs_node; + OpenAPI_list_for_each(media_sub_component->f_descs, f_descs_node) { + if (cJSON_AddStringToObject(f_descs, "", (char*)f_descs_node->data) == NULL) { + ogs_error("OpenAPI_media_sub_component_convertToJSON() failed [f_descs]"); + goto end; + } + } + } + + if (media_sub_component->f_status) { + if (cJSON_AddStringToObject(item, "fStatus", OpenAPI_flow_status_ToString(media_sub_component->f_status)) == NULL) { + ogs_error("OpenAPI_media_sub_component_convertToJSON() failed [f_status]"); + goto end; + } + } + + if (media_sub_component->mar_bw_dl) { + if (cJSON_AddStringToObject(item, "marBwDl", media_sub_component->mar_bw_dl) == NULL) { + ogs_error("OpenAPI_media_sub_component_convertToJSON() failed [mar_bw_dl]"); + goto end; + } + } + + if (media_sub_component->mar_bw_ul) { + if (cJSON_AddStringToObject(item, "marBwUl", media_sub_component->mar_bw_ul) == NULL) { + ogs_error("OpenAPI_media_sub_component_convertToJSON() failed [mar_bw_ul]"); + goto end; + } + } + + if (media_sub_component->tos_tr_cl) { + if (cJSON_AddStringToObject(item, "tosTrCl", media_sub_component->tos_tr_cl) == NULL) { + ogs_error("OpenAPI_media_sub_component_convertToJSON() failed [tos_tr_cl]"); + goto end; + } + } + + if (media_sub_component->flow_usage) { + if (cJSON_AddStringToObject(item, "flowUsage", OpenAPI_flow_usage_ToString(media_sub_component->flow_usage)) == NULL) { + ogs_error("OpenAPI_media_sub_component_convertToJSON() failed [flow_usage]"); + goto end; + } + } + + if (media_sub_component->tscai_input_dl) { + cJSON *tscai_input_dl_local_JSON = OpenAPI_tscai_input_container_convertToJSON(media_sub_component->tscai_input_dl); + if (tscai_input_dl_local_JSON == NULL) { + ogs_error("OpenAPI_media_sub_component_convertToJSON() failed [tscai_input_dl]"); + goto end; + } + cJSON_AddItemToObject(item, "tscaiInputDl", tscai_input_dl_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_media_sub_component_convertToJSON() failed [tscai_input_dl]"); + goto end; + } + } + + if (media_sub_component->tscai_input_ul) { + cJSON *tscai_input_ul_local_JSON = OpenAPI_tscai_input_container_convertToJSON(media_sub_component->tscai_input_ul); + if (tscai_input_ul_local_JSON == NULL) { + ogs_error("OpenAPI_media_sub_component_convertToJSON() failed [tscai_input_ul]"); + goto end; + } + cJSON_AddItemToObject(item, "tscaiInputUl", tscai_input_ul_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_media_sub_component_convertToJSON() failed [tscai_input_ul]"); + goto end; + } + } + +end: + return item; +} + +OpenAPI_media_sub_component_t *OpenAPI_media_sub_component_parseFromJSON(cJSON *media_sub_componentJSON) +{ + OpenAPI_media_sub_component_t *media_sub_component_local_var = NULL; + cJSON *af_sig_protocol = cJSON_GetObjectItemCaseSensitive(media_sub_componentJSON, "afSigProtocol"); + + OpenAPI_af_sig_protocol_e af_sig_protocolVariable; + if (af_sig_protocol) { + if (!cJSON_IsString(af_sig_protocol)) { + ogs_error("OpenAPI_media_sub_component_parseFromJSON() failed [af_sig_protocol]"); + goto end; + } + af_sig_protocolVariable = OpenAPI_af_sig_protocol_FromString(af_sig_protocol->valuestring); + } + + cJSON *ethf_descs = cJSON_GetObjectItemCaseSensitive(media_sub_componentJSON, "ethfDescs"); + + OpenAPI_list_t *ethf_descsList; + if (ethf_descs) { + cJSON *ethf_descs_local_nonprimitive; + if (!cJSON_IsArray(ethf_descs)) { + ogs_error("OpenAPI_media_sub_component_parseFromJSON() failed [ethf_descs]"); + goto end; + } + + ethf_descsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(ethf_descs_local_nonprimitive, ethf_descs ) { + if (!cJSON_IsObject(ethf_descs_local_nonprimitive)) { + ogs_error("OpenAPI_media_sub_component_parseFromJSON() failed [ethf_descs]"); + goto end; + } + OpenAPI_eth_flow_description_t *ethf_descsItem = OpenAPI_eth_flow_description_parseFromJSON(ethf_descs_local_nonprimitive); + + OpenAPI_list_add(ethf_descsList, ethf_descsItem); + } + } + + cJSON *f_num = cJSON_GetObjectItemCaseSensitive(media_sub_componentJSON, "fNum"); + if (!f_num) { + ogs_error("OpenAPI_media_sub_component_parseFromJSON() failed [f_num]"); + goto end; + } + + + if (!cJSON_IsNumber(f_num)) { + ogs_error("OpenAPI_media_sub_component_parseFromJSON() failed [f_num]"); + goto end; + } + + cJSON *f_descs = cJSON_GetObjectItemCaseSensitive(media_sub_componentJSON, "fDescs"); + + OpenAPI_list_t *f_descsList; + if (f_descs) { + cJSON *f_descs_local; + if (!cJSON_IsArray(f_descs)) { + ogs_error("OpenAPI_media_sub_component_parseFromJSON() failed [f_descs]"); + goto end; + } + f_descsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(f_descs_local, f_descs) { + if (!cJSON_IsString(f_descs_local)) { + ogs_error("OpenAPI_media_sub_component_parseFromJSON() failed [f_descs]"); + goto end; + } + OpenAPI_list_add(f_descsList, ogs_strdup(f_descs_local->valuestring)); + } + } + + cJSON *f_status = cJSON_GetObjectItemCaseSensitive(media_sub_componentJSON, "fStatus"); + + OpenAPI_flow_status_e f_statusVariable; + if (f_status) { + if (!cJSON_IsString(f_status)) { + ogs_error("OpenAPI_media_sub_component_parseFromJSON() failed [f_status]"); + goto end; + } + f_statusVariable = OpenAPI_flow_status_FromString(f_status->valuestring); + } + + cJSON *mar_bw_dl = cJSON_GetObjectItemCaseSensitive(media_sub_componentJSON, "marBwDl"); + + if (mar_bw_dl) { + if (!cJSON_IsString(mar_bw_dl)) { + ogs_error("OpenAPI_media_sub_component_parseFromJSON() failed [mar_bw_dl]"); + goto end; + } + } + + cJSON *mar_bw_ul = cJSON_GetObjectItemCaseSensitive(media_sub_componentJSON, "marBwUl"); + + if (mar_bw_ul) { + if (!cJSON_IsString(mar_bw_ul)) { + ogs_error("OpenAPI_media_sub_component_parseFromJSON() failed [mar_bw_ul]"); + goto end; + } + } + + cJSON *tos_tr_cl = cJSON_GetObjectItemCaseSensitive(media_sub_componentJSON, "tosTrCl"); + + if (tos_tr_cl) { + if (!cJSON_IsString(tos_tr_cl)) { + ogs_error("OpenAPI_media_sub_component_parseFromJSON() failed [tos_tr_cl]"); + goto end; + } + } + + cJSON *flow_usage = cJSON_GetObjectItemCaseSensitive(media_sub_componentJSON, "flowUsage"); + + OpenAPI_flow_usage_e flow_usageVariable; + if (flow_usage) { + if (!cJSON_IsString(flow_usage)) { + ogs_error("OpenAPI_media_sub_component_parseFromJSON() failed [flow_usage]"); + goto end; + } + flow_usageVariable = OpenAPI_flow_usage_FromString(flow_usage->valuestring); + } + + cJSON *tscai_input_dl = cJSON_GetObjectItemCaseSensitive(media_sub_componentJSON, "tscaiInputDl"); + + OpenAPI_tscai_input_container_t *tscai_input_dl_local_nonprim = NULL; + if (tscai_input_dl) { + tscai_input_dl_local_nonprim = OpenAPI_tscai_input_container_parseFromJSON(tscai_input_dl); + } + + cJSON *tscai_input_ul = cJSON_GetObjectItemCaseSensitive(media_sub_componentJSON, "tscaiInputUl"); + + OpenAPI_tscai_input_container_t *tscai_input_ul_local_nonprim = NULL; + if (tscai_input_ul) { + tscai_input_ul_local_nonprim = OpenAPI_tscai_input_container_parseFromJSON(tscai_input_ul); + } + + media_sub_component_local_var = OpenAPI_media_sub_component_create ( + af_sig_protocol ? af_sig_protocolVariable : 0, + ethf_descs ? ethf_descsList : NULL, + f_num->valuedouble, + f_descs ? f_descsList : NULL, + f_status ? f_statusVariable : 0, + mar_bw_dl ? ogs_strdup(mar_bw_dl->valuestring) : NULL, + mar_bw_ul ? ogs_strdup(mar_bw_ul->valuestring) : NULL, + tos_tr_cl ? ogs_strdup(tos_tr_cl->valuestring) : NULL, + flow_usage ? flow_usageVariable : 0, + tscai_input_dl ? tscai_input_dl_local_nonprim : NULL, + tscai_input_ul ? tscai_input_ul_local_nonprim : NULL + ); + + return media_sub_component_local_var; +end: + return NULL; +} + +OpenAPI_media_sub_component_t *OpenAPI_media_sub_component_copy(OpenAPI_media_sub_component_t *dst, OpenAPI_media_sub_component_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_media_sub_component_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_media_sub_component_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_media_sub_component_free(dst); + dst = OpenAPI_media_sub_component_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/media_sub_component.h b/lib/sbi/openapi/model/media_sub_component.h new file mode 100644 index 000000000..9e0644dd0 --- /dev/null +++ b/lib/sbi/openapi/model/media_sub_component.h @@ -0,0 +1,63 @@ +/* + * media_sub_component.h + * + * Identifies a media subcomponent + */ + +#ifndef _OpenAPI_media_sub_component_H_ +#define _OpenAPI_media_sub_component_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" +#include "af_sig_protocol.h" +#include "eth_flow_description.h" +#include "flow_status.h" +#include "flow_usage.h" +#include "tscai_input_container.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_media_sub_component_s OpenAPI_media_sub_component_t; +typedef struct OpenAPI_media_sub_component_s { + OpenAPI_af_sig_protocol_e af_sig_protocol; + OpenAPI_list_t *ethf_descs; + int f_num; + OpenAPI_list_t *f_descs; + OpenAPI_flow_status_e f_status; + char *mar_bw_dl; + char *mar_bw_ul; + char *tos_tr_cl; + OpenAPI_flow_usage_e flow_usage; + struct OpenAPI_tscai_input_container_s *tscai_input_dl; + struct OpenAPI_tscai_input_container_s *tscai_input_ul; +} OpenAPI_media_sub_component_t; + +OpenAPI_media_sub_component_t *OpenAPI_media_sub_component_create( + OpenAPI_af_sig_protocol_e af_sig_protocol, + OpenAPI_list_t *ethf_descs, + int f_num, + OpenAPI_list_t *f_descs, + OpenAPI_flow_status_e f_status, + char *mar_bw_dl, + char *mar_bw_ul, + char *tos_tr_cl, + OpenAPI_flow_usage_e flow_usage, + OpenAPI_tscai_input_container_t *tscai_input_dl, + OpenAPI_tscai_input_container_t *tscai_input_ul + ); +void OpenAPI_media_sub_component_free(OpenAPI_media_sub_component_t *media_sub_component); +OpenAPI_media_sub_component_t *OpenAPI_media_sub_component_parseFromJSON(cJSON *media_sub_componentJSON); +cJSON *OpenAPI_media_sub_component_convertToJSON(OpenAPI_media_sub_component_t *media_sub_component); +OpenAPI_media_sub_component_t *OpenAPI_media_sub_component_copy(OpenAPI_media_sub_component_t *dst, OpenAPI_media_sub_component_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_media_sub_component_H_ */ + diff --git a/lib/sbi/openapi/model/media_sub_component_rm.c b/lib/sbi/openapi/model/media_sub_component_rm.c new file mode 100644 index 000000000..22ca873d8 --- /dev/null +++ b/lib/sbi/openapi/model/media_sub_component_rm.c @@ -0,0 +1,369 @@ + +#include +#include +#include +#include "media_sub_component_rm.h" + +OpenAPI_media_sub_component_rm_t *OpenAPI_media_sub_component_rm_create( + OpenAPI_af_sig_protocol_e af_sig_protocol, + OpenAPI_list_t *ethf_descs, + int f_num, + OpenAPI_list_t *f_descs, + OpenAPI_flow_status_e f_status, + char *mar_bw_dl, + char *mar_bw_ul, + char *tos_tr_cl, + OpenAPI_flow_usage_e flow_usage, + OpenAPI_tscai_input_container_t *tscai_input_dl, + OpenAPI_tscai_input_container_t *tscai_input_ul + ) +{ + OpenAPI_media_sub_component_rm_t *media_sub_component_rm_local_var = OpenAPI_malloc(sizeof(OpenAPI_media_sub_component_rm_t)); + if (!media_sub_component_rm_local_var) { + return NULL; + } + media_sub_component_rm_local_var->af_sig_protocol = af_sig_protocol; + media_sub_component_rm_local_var->ethf_descs = ethf_descs; + media_sub_component_rm_local_var->f_num = f_num; + media_sub_component_rm_local_var->f_descs = f_descs; + media_sub_component_rm_local_var->f_status = f_status; + media_sub_component_rm_local_var->mar_bw_dl = mar_bw_dl; + media_sub_component_rm_local_var->mar_bw_ul = mar_bw_ul; + media_sub_component_rm_local_var->tos_tr_cl = tos_tr_cl; + media_sub_component_rm_local_var->flow_usage = flow_usage; + media_sub_component_rm_local_var->tscai_input_dl = tscai_input_dl; + media_sub_component_rm_local_var->tscai_input_ul = tscai_input_ul; + + return media_sub_component_rm_local_var; +} + +void OpenAPI_media_sub_component_rm_free(OpenAPI_media_sub_component_rm_t *media_sub_component_rm) +{ + if (NULL == media_sub_component_rm) { + return; + } + OpenAPI_lnode_t *node; + OpenAPI_list_for_each(media_sub_component_rm->ethf_descs, node) { + OpenAPI_eth_flow_description_free(node->data); + } + OpenAPI_list_free(media_sub_component_rm->ethf_descs); + OpenAPI_list_for_each(media_sub_component_rm->f_descs, node) { + ogs_free(node->data); + } + OpenAPI_list_free(media_sub_component_rm->f_descs); + ogs_free(media_sub_component_rm->mar_bw_dl); + ogs_free(media_sub_component_rm->mar_bw_ul); + ogs_free(media_sub_component_rm->tos_tr_cl); + OpenAPI_tscai_input_container_free(media_sub_component_rm->tscai_input_dl); + OpenAPI_tscai_input_container_free(media_sub_component_rm->tscai_input_ul); + ogs_free(media_sub_component_rm); +} + +cJSON *OpenAPI_media_sub_component_rm_convertToJSON(OpenAPI_media_sub_component_rm_t *media_sub_component_rm) +{ + cJSON *item = NULL; + + if (media_sub_component_rm == NULL) { + ogs_error("OpenAPI_media_sub_component_rm_convertToJSON() failed [MediaSubComponentRm]"); + return NULL; + } + + item = cJSON_CreateObject(); + if (media_sub_component_rm->af_sig_protocol) { + if (cJSON_AddStringToObject(item, "afSigProtocol", OpenAPI_af_sig_protocol_ToString(media_sub_component_rm->af_sig_protocol)) == NULL) { + ogs_error("OpenAPI_media_sub_component_rm_convertToJSON() failed [af_sig_protocol]"); + goto end; + } + } + + if (media_sub_component_rm->ethf_descs) { + cJSON *ethf_descsList = cJSON_AddArrayToObject(item, "ethfDescs"); + if (ethf_descsList == NULL) { + ogs_error("OpenAPI_media_sub_component_rm_convertToJSON() failed [ethf_descs]"); + goto end; + } + + OpenAPI_lnode_t *ethf_descs_node; + if (media_sub_component_rm->ethf_descs) { + OpenAPI_list_for_each(media_sub_component_rm->ethf_descs, ethf_descs_node) { + cJSON *itemLocal = OpenAPI_eth_flow_description_convertToJSON(ethf_descs_node->data); + if (itemLocal == NULL) { + ogs_error("OpenAPI_media_sub_component_rm_convertToJSON() failed [ethf_descs]"); + goto end; + } + cJSON_AddItemToArray(ethf_descsList, itemLocal); + } + } + } + + if (cJSON_AddNumberToObject(item, "fNum", media_sub_component_rm->f_num) == NULL) { + ogs_error("OpenAPI_media_sub_component_rm_convertToJSON() failed [f_num]"); + goto end; + } + + if (media_sub_component_rm->f_descs) { + cJSON *f_descs = cJSON_AddArrayToObject(item, "fDescs"); + if (f_descs == NULL) { + ogs_error("OpenAPI_media_sub_component_rm_convertToJSON() failed [f_descs]"); + goto end; + } + + OpenAPI_lnode_t *f_descs_node; + OpenAPI_list_for_each(media_sub_component_rm->f_descs, f_descs_node) { + if (cJSON_AddStringToObject(f_descs, "", (char*)f_descs_node->data) == NULL) { + ogs_error("OpenAPI_media_sub_component_rm_convertToJSON() failed [f_descs]"); + goto end; + } + } + } + + if (media_sub_component_rm->f_status) { + if (cJSON_AddStringToObject(item, "fStatus", OpenAPI_flow_status_ToString(media_sub_component_rm->f_status)) == NULL) { + ogs_error("OpenAPI_media_sub_component_rm_convertToJSON() failed [f_status]"); + goto end; + } + } + + if (media_sub_component_rm->mar_bw_dl) { + if (cJSON_AddStringToObject(item, "marBwDl", media_sub_component_rm->mar_bw_dl) == NULL) { + ogs_error("OpenAPI_media_sub_component_rm_convertToJSON() failed [mar_bw_dl]"); + goto end; + } + } + + if (media_sub_component_rm->mar_bw_ul) { + if (cJSON_AddStringToObject(item, "marBwUl", media_sub_component_rm->mar_bw_ul) == NULL) { + ogs_error("OpenAPI_media_sub_component_rm_convertToJSON() failed [mar_bw_ul]"); + goto end; + } + } + + if (media_sub_component_rm->tos_tr_cl) { + if (cJSON_AddStringToObject(item, "tosTrCl", media_sub_component_rm->tos_tr_cl) == NULL) { + ogs_error("OpenAPI_media_sub_component_rm_convertToJSON() failed [tos_tr_cl]"); + goto end; + } + } + + if (media_sub_component_rm->flow_usage) { + if (cJSON_AddStringToObject(item, "flowUsage", OpenAPI_flow_usage_ToString(media_sub_component_rm->flow_usage)) == NULL) { + ogs_error("OpenAPI_media_sub_component_rm_convertToJSON() failed [flow_usage]"); + goto end; + } + } + + if (media_sub_component_rm->tscai_input_dl) { + cJSON *tscai_input_dl_local_JSON = OpenAPI_tscai_input_container_convertToJSON(media_sub_component_rm->tscai_input_dl); + if (tscai_input_dl_local_JSON == NULL) { + ogs_error("OpenAPI_media_sub_component_rm_convertToJSON() failed [tscai_input_dl]"); + goto end; + } + cJSON_AddItemToObject(item, "tscaiInputDl", tscai_input_dl_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_media_sub_component_rm_convertToJSON() failed [tscai_input_dl]"); + goto end; + } + } + + if (media_sub_component_rm->tscai_input_ul) { + cJSON *tscai_input_ul_local_JSON = OpenAPI_tscai_input_container_convertToJSON(media_sub_component_rm->tscai_input_ul); + if (tscai_input_ul_local_JSON == NULL) { + ogs_error("OpenAPI_media_sub_component_rm_convertToJSON() failed [tscai_input_ul]"); + goto end; + } + cJSON_AddItemToObject(item, "tscaiInputUl", tscai_input_ul_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_media_sub_component_rm_convertToJSON() failed [tscai_input_ul]"); + goto end; + } + } + +end: + return item; +} + +OpenAPI_media_sub_component_rm_t *OpenAPI_media_sub_component_rm_parseFromJSON(cJSON *media_sub_component_rmJSON) +{ + OpenAPI_media_sub_component_rm_t *media_sub_component_rm_local_var = NULL; + cJSON *af_sig_protocol = cJSON_GetObjectItemCaseSensitive(media_sub_component_rmJSON, "afSigProtocol"); + + OpenAPI_af_sig_protocol_e af_sig_protocolVariable; + if (af_sig_protocol) { + if (!cJSON_IsString(af_sig_protocol)) { + ogs_error("OpenAPI_media_sub_component_rm_parseFromJSON() failed [af_sig_protocol]"); + goto end; + } + af_sig_protocolVariable = OpenAPI_af_sig_protocol_FromString(af_sig_protocol->valuestring); + } + + cJSON *ethf_descs = cJSON_GetObjectItemCaseSensitive(media_sub_component_rmJSON, "ethfDescs"); + + OpenAPI_list_t *ethf_descsList; + if (ethf_descs) { + cJSON *ethf_descs_local_nonprimitive; + if (!cJSON_IsArray(ethf_descs)) { + ogs_error("OpenAPI_media_sub_component_rm_parseFromJSON() failed [ethf_descs]"); + goto end; + } + + ethf_descsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(ethf_descs_local_nonprimitive, ethf_descs ) { + if (!cJSON_IsObject(ethf_descs_local_nonprimitive)) { + ogs_error("OpenAPI_media_sub_component_rm_parseFromJSON() failed [ethf_descs]"); + goto end; + } + OpenAPI_eth_flow_description_t *ethf_descsItem = OpenAPI_eth_flow_description_parseFromJSON(ethf_descs_local_nonprimitive); + + OpenAPI_list_add(ethf_descsList, ethf_descsItem); + } + } + + cJSON *f_num = cJSON_GetObjectItemCaseSensitive(media_sub_component_rmJSON, "fNum"); + if (!f_num) { + ogs_error("OpenAPI_media_sub_component_rm_parseFromJSON() failed [f_num]"); + goto end; + } + + + if (!cJSON_IsNumber(f_num)) { + ogs_error("OpenAPI_media_sub_component_rm_parseFromJSON() failed [f_num]"); + goto end; + } + + cJSON *f_descs = cJSON_GetObjectItemCaseSensitive(media_sub_component_rmJSON, "fDescs"); + + OpenAPI_list_t *f_descsList; + if (f_descs) { + cJSON *f_descs_local; + if (!cJSON_IsArray(f_descs)) { + ogs_error("OpenAPI_media_sub_component_rm_parseFromJSON() failed [f_descs]"); + goto end; + } + f_descsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(f_descs_local, f_descs) { + if (!cJSON_IsString(f_descs_local)) { + ogs_error("OpenAPI_media_sub_component_rm_parseFromJSON() failed [f_descs]"); + goto end; + } + OpenAPI_list_add(f_descsList, ogs_strdup(f_descs_local->valuestring)); + } + } + + cJSON *f_status = cJSON_GetObjectItemCaseSensitive(media_sub_component_rmJSON, "fStatus"); + + OpenAPI_flow_status_e f_statusVariable; + if (f_status) { + if (!cJSON_IsString(f_status)) { + ogs_error("OpenAPI_media_sub_component_rm_parseFromJSON() failed [f_status]"); + goto end; + } + f_statusVariable = OpenAPI_flow_status_FromString(f_status->valuestring); + } + + cJSON *mar_bw_dl = cJSON_GetObjectItemCaseSensitive(media_sub_component_rmJSON, "marBwDl"); + + if (mar_bw_dl) { + if (!cJSON_IsString(mar_bw_dl)) { + ogs_error("OpenAPI_media_sub_component_rm_parseFromJSON() failed [mar_bw_dl]"); + goto end; + } + } + + cJSON *mar_bw_ul = cJSON_GetObjectItemCaseSensitive(media_sub_component_rmJSON, "marBwUl"); + + if (mar_bw_ul) { + if (!cJSON_IsString(mar_bw_ul)) { + ogs_error("OpenAPI_media_sub_component_rm_parseFromJSON() failed [mar_bw_ul]"); + goto end; + } + } + + cJSON *tos_tr_cl = cJSON_GetObjectItemCaseSensitive(media_sub_component_rmJSON, "tosTrCl"); + + if (tos_tr_cl) { + if (!cJSON_IsString(tos_tr_cl)) { + ogs_error("OpenAPI_media_sub_component_rm_parseFromJSON() failed [tos_tr_cl]"); + goto end; + } + } + + cJSON *flow_usage = cJSON_GetObjectItemCaseSensitive(media_sub_component_rmJSON, "flowUsage"); + + OpenAPI_flow_usage_e flow_usageVariable; + if (flow_usage) { + if (!cJSON_IsString(flow_usage)) { + ogs_error("OpenAPI_media_sub_component_rm_parseFromJSON() failed [flow_usage]"); + goto end; + } + flow_usageVariable = OpenAPI_flow_usage_FromString(flow_usage->valuestring); + } + + cJSON *tscai_input_dl = cJSON_GetObjectItemCaseSensitive(media_sub_component_rmJSON, "tscaiInputDl"); + + OpenAPI_tscai_input_container_t *tscai_input_dl_local_nonprim = NULL; + if (tscai_input_dl) { + tscai_input_dl_local_nonprim = OpenAPI_tscai_input_container_parseFromJSON(tscai_input_dl); + } + + cJSON *tscai_input_ul = cJSON_GetObjectItemCaseSensitive(media_sub_component_rmJSON, "tscaiInputUl"); + + OpenAPI_tscai_input_container_t *tscai_input_ul_local_nonprim = NULL; + if (tscai_input_ul) { + tscai_input_ul_local_nonprim = OpenAPI_tscai_input_container_parseFromJSON(tscai_input_ul); + } + + media_sub_component_rm_local_var = OpenAPI_media_sub_component_rm_create ( + af_sig_protocol ? af_sig_protocolVariable : 0, + ethf_descs ? ethf_descsList : NULL, + f_num->valuedouble, + f_descs ? f_descsList : NULL, + f_status ? f_statusVariable : 0, + mar_bw_dl ? ogs_strdup(mar_bw_dl->valuestring) : NULL, + mar_bw_ul ? ogs_strdup(mar_bw_ul->valuestring) : NULL, + tos_tr_cl ? ogs_strdup(tos_tr_cl->valuestring) : NULL, + flow_usage ? flow_usageVariable : 0, + tscai_input_dl ? tscai_input_dl_local_nonprim : NULL, + tscai_input_ul ? tscai_input_ul_local_nonprim : NULL + ); + + return media_sub_component_rm_local_var; +end: + return NULL; +} + +OpenAPI_media_sub_component_rm_t *OpenAPI_media_sub_component_rm_copy(OpenAPI_media_sub_component_rm_t *dst, OpenAPI_media_sub_component_rm_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_media_sub_component_rm_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_media_sub_component_rm_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_media_sub_component_rm_free(dst); + dst = OpenAPI_media_sub_component_rm_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/media_sub_component_rm.h b/lib/sbi/openapi/model/media_sub_component_rm.h new file mode 100644 index 000000000..76033e78e --- /dev/null +++ b/lib/sbi/openapi/model/media_sub_component_rm.h @@ -0,0 +1,63 @@ +/* + * media_sub_component_rm.h + * + * This data type is defined in the same way as the MediaSubComponent data type, but with the OpenAPI nullable property set to true. Removable attributes marBwDl and marBwUl are defined with the corresponding removable data type. + */ + +#ifndef _OpenAPI_media_sub_component_rm_H_ +#define _OpenAPI_media_sub_component_rm_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" +#include "af_sig_protocol.h" +#include "eth_flow_description.h" +#include "flow_status.h" +#include "flow_usage.h" +#include "tscai_input_container.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_media_sub_component_rm_s OpenAPI_media_sub_component_rm_t; +typedef struct OpenAPI_media_sub_component_rm_s { + OpenAPI_af_sig_protocol_e af_sig_protocol; + OpenAPI_list_t *ethf_descs; + int f_num; + OpenAPI_list_t *f_descs; + OpenAPI_flow_status_e f_status; + char *mar_bw_dl; + char *mar_bw_ul; + char *tos_tr_cl; + OpenAPI_flow_usage_e flow_usage; + struct OpenAPI_tscai_input_container_s *tscai_input_dl; + struct OpenAPI_tscai_input_container_s *tscai_input_ul; +} OpenAPI_media_sub_component_rm_t; + +OpenAPI_media_sub_component_rm_t *OpenAPI_media_sub_component_rm_create( + OpenAPI_af_sig_protocol_e af_sig_protocol, + OpenAPI_list_t *ethf_descs, + int f_num, + OpenAPI_list_t *f_descs, + OpenAPI_flow_status_e f_status, + char *mar_bw_dl, + char *mar_bw_ul, + char *tos_tr_cl, + OpenAPI_flow_usage_e flow_usage, + OpenAPI_tscai_input_container_t *tscai_input_dl, + OpenAPI_tscai_input_container_t *tscai_input_ul + ); +void OpenAPI_media_sub_component_rm_free(OpenAPI_media_sub_component_rm_t *media_sub_component_rm); +OpenAPI_media_sub_component_rm_t *OpenAPI_media_sub_component_rm_parseFromJSON(cJSON *media_sub_component_rmJSON); +cJSON *OpenAPI_media_sub_component_rm_convertToJSON(OpenAPI_media_sub_component_rm_t *media_sub_component_rm); +OpenAPI_media_sub_component_rm_t *OpenAPI_media_sub_component_rm_copy(OpenAPI_media_sub_component_rm_t *dst, OpenAPI_media_sub_component_rm_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_media_sub_component_rm_H_ */ + diff --git a/lib/sbi/openapi/model/media_type.c b/lib/sbi/openapi/model/media_type.c new file mode 100644 index 000000000..eee726c5a --- /dev/null +++ b/lib/sbi/openapi/model/media_type.c @@ -0,0 +1,30 @@ + +#include +#include +#include +#include "media_type.h" + +char* OpenAPI_media_type_ToString(OpenAPI_media_type_e media_type) +{ + const char *media_typeArray[] = { "NULL", "AUDIO", "VIDEO", "DATA", "APPLICATION", "CONTROL", "TEXT", "MESSAGE", "OTHER" }; + size_t sizeofArray = sizeof(media_typeArray) / sizeof(media_typeArray[0]); + if (media_type < sizeofArray) + return (char *)media_typeArray[media_type]; + else + return (char *)"Unknown"; +} + +OpenAPI_media_type_e OpenAPI_media_type_FromString(char* media_type) +{ + int stringToReturn = 0; + const char *media_typeArray[] = { "NULL", "AUDIO", "VIDEO", "DATA", "APPLICATION", "CONTROL", "TEXT", "MESSAGE", "OTHER" }; + size_t sizeofArray = sizeof(media_typeArray) / sizeof(media_typeArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(media_type, media_typeArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; + } + return 0; +} + diff --git a/lib/sbi/openapi/model/media_type.h b/lib/sbi/openapi/model/media_type.h new file mode 100644 index 000000000..5d29a3702 --- /dev/null +++ b/lib/sbi/openapi/model/media_type.h @@ -0,0 +1,31 @@ +/* + * media_type.h + * + * + */ + +#ifndef _OpenAPI_media_type_H_ +#define _OpenAPI_media_type_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { OpenAPI_media_type_NULL = 0, OpenAPI_media_type_AUDIO, OpenAPI_media_type_VIDEO, OpenAPI_media_type_DATA, OpenAPI_media_type_APPLICATION, OpenAPI_media_type_CONTROL, OpenAPI_media_type_TEXT, OpenAPI_media_type_MESSAGE, OpenAPI_media_type_OTHER } OpenAPI_media_type_e; + +char* OpenAPI_media_type_ToString(OpenAPI_media_type_e media_type); + +OpenAPI_media_type_e OpenAPI_media_type_FromString(char* media_type); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_media_type_H_ */ + diff --git a/lib/sbi/openapi/model/new_tsn_bridge.c b/lib/sbi/openapi/model/new_tsn_bridge.c new file mode 100644 index 000000000..5a97eff52 --- /dev/null +++ b/lib/sbi/openapi/model/new_tsn_bridge.c @@ -0,0 +1,184 @@ + +#include +#include +#include +#include "new_tsn_bridge.h" + +OpenAPI_new_tsn_bridge_t *OpenAPI_new_tsn_bridge_create( + OpenAPI_tsn_bridge_info_t *tsn_bridge_info, + OpenAPI_port_management_container_t *tsn_port_man_cont_dstt, + OpenAPI_list_t *tsn_port_man_cont_nwtts + ) +{ + OpenAPI_new_tsn_bridge_t *new_tsn_bridge_local_var = OpenAPI_malloc(sizeof(OpenAPI_new_tsn_bridge_t)); + if (!new_tsn_bridge_local_var) { + return NULL; + } + new_tsn_bridge_local_var->tsn_bridge_info = tsn_bridge_info; + new_tsn_bridge_local_var->tsn_port_man_cont_dstt = tsn_port_man_cont_dstt; + new_tsn_bridge_local_var->tsn_port_man_cont_nwtts = tsn_port_man_cont_nwtts; + + return new_tsn_bridge_local_var; +} + +void OpenAPI_new_tsn_bridge_free(OpenAPI_new_tsn_bridge_t *new_tsn_bridge) +{ + if (NULL == new_tsn_bridge) { + return; + } + OpenAPI_lnode_t *node; + OpenAPI_tsn_bridge_info_free(new_tsn_bridge->tsn_bridge_info); + OpenAPI_port_management_container_free(new_tsn_bridge->tsn_port_man_cont_dstt); + OpenAPI_list_for_each(new_tsn_bridge->tsn_port_man_cont_nwtts, node) { + OpenAPI_port_management_container_free(node->data); + } + OpenAPI_list_free(new_tsn_bridge->tsn_port_man_cont_nwtts); + ogs_free(new_tsn_bridge); +} + +cJSON *OpenAPI_new_tsn_bridge_convertToJSON(OpenAPI_new_tsn_bridge_t *new_tsn_bridge) +{ + cJSON *item = NULL; + + if (new_tsn_bridge == NULL) { + ogs_error("OpenAPI_new_tsn_bridge_convertToJSON() failed [NewTsnBridge]"); + return NULL; + } + + item = cJSON_CreateObject(); + cJSON *tsn_bridge_info_local_JSON = OpenAPI_tsn_bridge_info_convertToJSON(new_tsn_bridge->tsn_bridge_info); + if (tsn_bridge_info_local_JSON == NULL) { + ogs_error("OpenAPI_new_tsn_bridge_convertToJSON() failed [tsn_bridge_info]"); + goto end; + } + cJSON_AddItemToObject(item, "tsnBridgeInfo", tsn_bridge_info_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_new_tsn_bridge_convertToJSON() failed [tsn_bridge_info]"); + goto end; + } + + if (new_tsn_bridge->tsn_port_man_cont_dstt) { + cJSON *tsn_port_man_cont_dstt_local_JSON = OpenAPI_port_management_container_convertToJSON(new_tsn_bridge->tsn_port_man_cont_dstt); + if (tsn_port_man_cont_dstt_local_JSON == NULL) { + ogs_error("OpenAPI_new_tsn_bridge_convertToJSON() failed [tsn_port_man_cont_dstt]"); + goto end; + } + cJSON_AddItemToObject(item, "tsnPortManContDstt", tsn_port_man_cont_dstt_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_new_tsn_bridge_convertToJSON() failed [tsn_port_man_cont_dstt]"); + goto end; + } + } + + if (new_tsn_bridge->tsn_port_man_cont_nwtts) { + cJSON *tsn_port_man_cont_nwttsList = cJSON_AddArrayToObject(item, "tsnPortManContNwtts"); + if (tsn_port_man_cont_nwttsList == NULL) { + ogs_error("OpenAPI_new_tsn_bridge_convertToJSON() failed [tsn_port_man_cont_nwtts]"); + goto end; + } + + OpenAPI_lnode_t *tsn_port_man_cont_nwtts_node; + if (new_tsn_bridge->tsn_port_man_cont_nwtts) { + OpenAPI_list_for_each(new_tsn_bridge->tsn_port_man_cont_nwtts, tsn_port_man_cont_nwtts_node) { + cJSON *itemLocal = OpenAPI_port_management_container_convertToJSON(tsn_port_man_cont_nwtts_node->data); + if (itemLocal == NULL) { + ogs_error("OpenAPI_new_tsn_bridge_convertToJSON() failed [tsn_port_man_cont_nwtts]"); + goto end; + } + cJSON_AddItemToArray(tsn_port_man_cont_nwttsList, itemLocal); + } + } + } + +end: + return item; +} + +OpenAPI_new_tsn_bridge_t *OpenAPI_new_tsn_bridge_parseFromJSON(cJSON *new_tsn_bridgeJSON) +{ + OpenAPI_new_tsn_bridge_t *new_tsn_bridge_local_var = NULL; + cJSON *tsn_bridge_info = cJSON_GetObjectItemCaseSensitive(new_tsn_bridgeJSON, "tsnBridgeInfo"); + if (!tsn_bridge_info) { + ogs_error("OpenAPI_new_tsn_bridge_parseFromJSON() failed [tsn_bridge_info]"); + goto end; + } + + OpenAPI_tsn_bridge_info_t *tsn_bridge_info_local_nonprim = NULL; + + tsn_bridge_info_local_nonprim = OpenAPI_tsn_bridge_info_parseFromJSON(tsn_bridge_info); + + cJSON *tsn_port_man_cont_dstt = cJSON_GetObjectItemCaseSensitive(new_tsn_bridgeJSON, "tsnPortManContDstt"); + + OpenAPI_port_management_container_t *tsn_port_man_cont_dstt_local_nonprim = NULL; + if (tsn_port_man_cont_dstt) { + tsn_port_man_cont_dstt_local_nonprim = OpenAPI_port_management_container_parseFromJSON(tsn_port_man_cont_dstt); + } + + cJSON *tsn_port_man_cont_nwtts = cJSON_GetObjectItemCaseSensitive(new_tsn_bridgeJSON, "tsnPortManContNwtts"); + + OpenAPI_list_t *tsn_port_man_cont_nwttsList; + if (tsn_port_man_cont_nwtts) { + cJSON *tsn_port_man_cont_nwtts_local_nonprimitive; + if (!cJSON_IsArray(tsn_port_man_cont_nwtts)) { + ogs_error("OpenAPI_new_tsn_bridge_parseFromJSON() failed [tsn_port_man_cont_nwtts]"); + goto end; + } + + tsn_port_man_cont_nwttsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(tsn_port_man_cont_nwtts_local_nonprimitive, tsn_port_man_cont_nwtts ) { + if (!cJSON_IsObject(tsn_port_man_cont_nwtts_local_nonprimitive)) { + ogs_error("OpenAPI_new_tsn_bridge_parseFromJSON() failed [tsn_port_man_cont_nwtts]"); + goto end; + } + OpenAPI_port_management_container_t *tsn_port_man_cont_nwttsItem = OpenAPI_port_management_container_parseFromJSON(tsn_port_man_cont_nwtts_local_nonprimitive); + + OpenAPI_list_add(tsn_port_man_cont_nwttsList, tsn_port_man_cont_nwttsItem); + } + } + + new_tsn_bridge_local_var = OpenAPI_new_tsn_bridge_create ( + tsn_bridge_info_local_nonprim, + tsn_port_man_cont_dstt ? tsn_port_man_cont_dstt_local_nonprim : NULL, + tsn_port_man_cont_nwtts ? tsn_port_man_cont_nwttsList : NULL + ); + + return new_tsn_bridge_local_var; +end: + return NULL; +} + +OpenAPI_new_tsn_bridge_t *OpenAPI_new_tsn_bridge_copy(OpenAPI_new_tsn_bridge_t *dst, OpenAPI_new_tsn_bridge_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_new_tsn_bridge_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_new_tsn_bridge_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_new_tsn_bridge_free(dst); + dst = OpenAPI_new_tsn_bridge_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/new_tsn_bridge.h b/lib/sbi/openapi/model/new_tsn_bridge.h new file mode 100644 index 000000000..8c34d60a3 --- /dev/null +++ b/lib/sbi/openapi/model/new_tsn_bridge.h @@ -0,0 +1,44 @@ +/* + * new_tsn_bridge.h + * + * Contains the new 5GS Bridge information and may contain the DS-TT port and/or NW-TT port management information. + */ + +#ifndef _OpenAPI_new_tsn_bridge_H_ +#define _OpenAPI_new_tsn_bridge_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" +#include "port_management_container.h" +#include "tsn_bridge_info.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_new_tsn_bridge_s OpenAPI_new_tsn_bridge_t; +typedef struct OpenAPI_new_tsn_bridge_s { + struct OpenAPI_tsn_bridge_info_s *tsn_bridge_info; + struct OpenAPI_port_management_container_s *tsn_port_man_cont_dstt; + OpenAPI_list_t *tsn_port_man_cont_nwtts; +} OpenAPI_new_tsn_bridge_t; + +OpenAPI_new_tsn_bridge_t *OpenAPI_new_tsn_bridge_create( + OpenAPI_tsn_bridge_info_t *tsn_bridge_info, + OpenAPI_port_management_container_t *tsn_port_man_cont_dstt, + OpenAPI_list_t *tsn_port_man_cont_nwtts + ); +void OpenAPI_new_tsn_bridge_free(OpenAPI_new_tsn_bridge_t *new_tsn_bridge); +OpenAPI_new_tsn_bridge_t *OpenAPI_new_tsn_bridge_parseFromJSON(cJSON *new_tsn_bridgeJSON); +cJSON *OpenAPI_new_tsn_bridge_convertToJSON(OpenAPI_new_tsn_bridge_t *new_tsn_bridge); +OpenAPI_new_tsn_bridge_t *OpenAPI_new_tsn_bridge_copy(OpenAPI_new_tsn_bridge_t *dst, OpenAPI_new_tsn_bridge_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_new_tsn_bridge_H_ */ + diff --git a/lib/sbi/openapi/model/out_of_credit_information.c b/lib/sbi/openapi/model/out_of_credit_information.c new file mode 100644 index 000000000..8a489e55a --- /dev/null +++ b/lib/sbi/openapi/model/out_of_credit_information.c @@ -0,0 +1,160 @@ + +#include +#include +#include +#include "out_of_credit_information.h" + +OpenAPI_out_of_credit_information_t *OpenAPI_out_of_credit_information_create( + OpenAPI_final_unit_action_t *fin_unit_act, + OpenAPI_list_t *flows + ) +{ + OpenAPI_out_of_credit_information_t *out_of_credit_information_local_var = OpenAPI_malloc(sizeof(OpenAPI_out_of_credit_information_t)); + if (!out_of_credit_information_local_var) { + return NULL; + } + out_of_credit_information_local_var->fin_unit_act = fin_unit_act; + out_of_credit_information_local_var->flows = flows; + + return out_of_credit_information_local_var; +} + +void OpenAPI_out_of_credit_information_free(OpenAPI_out_of_credit_information_t *out_of_credit_information) +{ + if (NULL == out_of_credit_information) { + return; + } + OpenAPI_lnode_t *node; + OpenAPI_final_unit_action_free(out_of_credit_information->fin_unit_act); + OpenAPI_list_for_each(out_of_credit_information->flows, node) { + OpenAPI_flows_free(node->data); + } + OpenAPI_list_free(out_of_credit_information->flows); + ogs_free(out_of_credit_information); +} + +cJSON *OpenAPI_out_of_credit_information_convertToJSON(OpenAPI_out_of_credit_information_t *out_of_credit_information) +{ + cJSON *item = NULL; + + if (out_of_credit_information == NULL) { + ogs_error("OpenAPI_out_of_credit_information_convertToJSON() failed [OutOfCreditInformation]"); + return NULL; + } + + item = cJSON_CreateObject(); + cJSON *fin_unit_act_local_JSON = OpenAPI_final_unit_action_convertToJSON(out_of_credit_information->fin_unit_act); + if (fin_unit_act_local_JSON == NULL) { + ogs_error("OpenAPI_out_of_credit_information_convertToJSON() failed [fin_unit_act]"); + goto end; + } + cJSON_AddItemToObject(item, "finUnitAct", fin_unit_act_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_out_of_credit_information_convertToJSON() failed [fin_unit_act]"); + goto end; + } + + if (out_of_credit_information->flows) { + cJSON *flowsList = cJSON_AddArrayToObject(item, "flows"); + if (flowsList == NULL) { + ogs_error("OpenAPI_out_of_credit_information_convertToJSON() failed [flows]"); + goto end; + } + + OpenAPI_lnode_t *flows_node; + if (out_of_credit_information->flows) { + OpenAPI_list_for_each(out_of_credit_information->flows, flows_node) { + cJSON *itemLocal = OpenAPI_flows_convertToJSON(flows_node->data); + if (itemLocal == NULL) { + ogs_error("OpenAPI_out_of_credit_information_convertToJSON() failed [flows]"); + goto end; + } + cJSON_AddItemToArray(flowsList, itemLocal); + } + } + } + +end: + return item; +} + +OpenAPI_out_of_credit_information_t *OpenAPI_out_of_credit_information_parseFromJSON(cJSON *out_of_credit_informationJSON) +{ + OpenAPI_out_of_credit_information_t *out_of_credit_information_local_var = NULL; + cJSON *fin_unit_act = cJSON_GetObjectItemCaseSensitive(out_of_credit_informationJSON, "finUnitAct"); + if (!fin_unit_act) { + ogs_error("OpenAPI_out_of_credit_information_parseFromJSON() failed [fin_unit_act]"); + goto end; + } + + OpenAPI_final_unit_action_t *fin_unit_act_local_nonprim = NULL; + + fin_unit_act_local_nonprim = OpenAPI_final_unit_action_parseFromJSON(fin_unit_act); + + cJSON *flows = cJSON_GetObjectItemCaseSensitive(out_of_credit_informationJSON, "flows"); + + OpenAPI_list_t *flowsList; + if (flows) { + cJSON *flows_local_nonprimitive; + if (!cJSON_IsArray(flows)) { + ogs_error("OpenAPI_out_of_credit_information_parseFromJSON() failed [flows]"); + goto end; + } + + flowsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(flows_local_nonprimitive, flows ) { + if (!cJSON_IsObject(flows_local_nonprimitive)) { + ogs_error("OpenAPI_out_of_credit_information_parseFromJSON() failed [flows]"); + goto end; + } + OpenAPI_flows_t *flowsItem = OpenAPI_flows_parseFromJSON(flows_local_nonprimitive); + + OpenAPI_list_add(flowsList, flowsItem); + } + } + + out_of_credit_information_local_var = OpenAPI_out_of_credit_information_create ( + fin_unit_act_local_nonprim, + flows ? flowsList : NULL + ); + + return out_of_credit_information_local_var; +end: + return NULL; +} + +OpenAPI_out_of_credit_information_t *OpenAPI_out_of_credit_information_copy(OpenAPI_out_of_credit_information_t *dst, OpenAPI_out_of_credit_information_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_out_of_credit_information_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_out_of_credit_information_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_out_of_credit_information_free(dst); + dst = OpenAPI_out_of_credit_information_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/out_of_credit_information.h b/lib/sbi/openapi/model/out_of_credit_information.h new file mode 100644 index 000000000..3f705fd2e --- /dev/null +++ b/lib/sbi/openapi/model/out_of_credit_information.h @@ -0,0 +1,42 @@ +/* + * out_of_credit_information.h + * + * Indicates the SDFs without available credit and the corresponding termination action. + */ + +#ifndef _OpenAPI_out_of_credit_information_H_ +#define _OpenAPI_out_of_credit_information_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" +#include "final_unit_action.h" +#include "flows.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_out_of_credit_information_s OpenAPI_out_of_credit_information_t; +typedef struct OpenAPI_out_of_credit_information_s { + struct OpenAPI_final_unit_action_s *fin_unit_act; + OpenAPI_list_t *flows; +} OpenAPI_out_of_credit_information_t; + +OpenAPI_out_of_credit_information_t *OpenAPI_out_of_credit_information_create( + OpenAPI_final_unit_action_t *fin_unit_act, + OpenAPI_list_t *flows + ); +void OpenAPI_out_of_credit_information_free(OpenAPI_out_of_credit_information_t *out_of_credit_information); +OpenAPI_out_of_credit_information_t *OpenAPI_out_of_credit_information_parseFromJSON(cJSON *out_of_credit_informationJSON); +cJSON *OpenAPI_out_of_credit_information_convertToJSON(OpenAPI_out_of_credit_information_t *out_of_credit_information); +OpenAPI_out_of_credit_information_t *OpenAPI_out_of_credit_information_copy(OpenAPI_out_of_credit_information_t *dst, OpenAPI_out_of_credit_information_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_out_of_credit_information_H_ */ + diff --git a/lib/sbi/openapi/model/parameter_combination.c b/lib/sbi/openapi/model/parameter_combination.c new file mode 100644 index 000000000..ca7fdfa8e --- /dev/null +++ b/lib/sbi/openapi/model/parameter_combination.c @@ -0,0 +1,149 @@ + +#include +#include +#include +#include "parameter_combination.h" + +OpenAPI_parameter_combination_t *OpenAPI_parameter_combination_create( + char *supi, + char *dnn, + OpenAPI_snssai_t *snssai + ) +{ + OpenAPI_parameter_combination_t *parameter_combination_local_var = OpenAPI_malloc(sizeof(OpenAPI_parameter_combination_t)); + if (!parameter_combination_local_var) { + return NULL; + } + parameter_combination_local_var->supi = supi; + parameter_combination_local_var->dnn = dnn; + parameter_combination_local_var->snssai = snssai; + + return parameter_combination_local_var; +} + +void OpenAPI_parameter_combination_free(OpenAPI_parameter_combination_t *parameter_combination) +{ + if (NULL == parameter_combination) { + return; + } + OpenAPI_lnode_t *node; + ogs_free(parameter_combination->supi); + ogs_free(parameter_combination->dnn); + OpenAPI_snssai_free(parameter_combination->snssai); + ogs_free(parameter_combination); +} + +cJSON *OpenAPI_parameter_combination_convertToJSON(OpenAPI_parameter_combination_t *parameter_combination) +{ + cJSON *item = NULL; + + if (parameter_combination == NULL) { + ogs_error("OpenAPI_parameter_combination_convertToJSON() failed [ParameterCombination]"); + return NULL; + } + + item = cJSON_CreateObject(); + if (parameter_combination->supi) { + if (cJSON_AddStringToObject(item, "supi", parameter_combination->supi) == NULL) { + ogs_error("OpenAPI_parameter_combination_convertToJSON() failed [supi]"); + goto end; + } + } + + if (parameter_combination->dnn) { + if (cJSON_AddStringToObject(item, "dnn", parameter_combination->dnn) == NULL) { + ogs_error("OpenAPI_parameter_combination_convertToJSON() failed [dnn]"); + goto end; + } + } + + if (parameter_combination->snssai) { + cJSON *snssai_local_JSON = OpenAPI_snssai_convertToJSON(parameter_combination->snssai); + if (snssai_local_JSON == NULL) { + ogs_error("OpenAPI_parameter_combination_convertToJSON() failed [snssai]"); + goto end; + } + cJSON_AddItemToObject(item, "snssai", snssai_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_parameter_combination_convertToJSON() failed [snssai]"); + goto end; + } + } + +end: + return item; +} + +OpenAPI_parameter_combination_t *OpenAPI_parameter_combination_parseFromJSON(cJSON *parameter_combinationJSON) +{ + OpenAPI_parameter_combination_t *parameter_combination_local_var = NULL; + cJSON *supi = cJSON_GetObjectItemCaseSensitive(parameter_combinationJSON, "supi"); + + if (supi) { + if (!cJSON_IsString(supi)) { + ogs_error("OpenAPI_parameter_combination_parseFromJSON() failed [supi]"); + goto end; + } + } + + cJSON *dnn = cJSON_GetObjectItemCaseSensitive(parameter_combinationJSON, "dnn"); + + if (dnn) { + if (!cJSON_IsString(dnn)) { + ogs_error("OpenAPI_parameter_combination_parseFromJSON() failed [dnn]"); + goto end; + } + } + + cJSON *snssai = cJSON_GetObjectItemCaseSensitive(parameter_combinationJSON, "snssai"); + + OpenAPI_snssai_t *snssai_local_nonprim = NULL; + if (snssai) { + snssai_local_nonprim = OpenAPI_snssai_parseFromJSON(snssai); + } + + parameter_combination_local_var = OpenAPI_parameter_combination_create ( + supi ? ogs_strdup(supi->valuestring) : NULL, + dnn ? ogs_strdup(dnn->valuestring) : NULL, + snssai ? snssai_local_nonprim : NULL + ); + + return parameter_combination_local_var; +end: + return NULL; +} + +OpenAPI_parameter_combination_t *OpenAPI_parameter_combination_copy(OpenAPI_parameter_combination_t *dst, OpenAPI_parameter_combination_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_parameter_combination_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_parameter_combination_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_parameter_combination_free(dst); + dst = OpenAPI_parameter_combination_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/parameter_combination.h b/lib/sbi/openapi/model/parameter_combination.h new file mode 100644 index 000000000..e0c3c4bf6 --- /dev/null +++ b/lib/sbi/openapi/model/parameter_combination.h @@ -0,0 +1,43 @@ +/* + * parameter_combination.h + * + * + */ + +#ifndef _OpenAPI_parameter_combination_H_ +#define _OpenAPI_parameter_combination_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" +#include "snssai.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_parameter_combination_s OpenAPI_parameter_combination_t; +typedef struct OpenAPI_parameter_combination_s { + char *supi; + char *dnn; + struct OpenAPI_snssai_s *snssai; +} OpenAPI_parameter_combination_t; + +OpenAPI_parameter_combination_t *OpenAPI_parameter_combination_create( + char *supi, + char *dnn, + OpenAPI_snssai_t *snssai + ); +void OpenAPI_parameter_combination_free(OpenAPI_parameter_combination_t *parameter_combination); +OpenAPI_parameter_combination_t *OpenAPI_parameter_combination_parseFromJSON(cJSON *parameter_combinationJSON); +cJSON *OpenAPI_parameter_combination_convertToJSON(OpenAPI_parameter_combination_t *parameter_combination); +OpenAPI_parameter_combination_t *OpenAPI_parameter_combination_copy(OpenAPI_parameter_combination_t *dst, OpenAPI_parameter_combination_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_parameter_combination_H_ */ + diff --git a/lib/sbi/openapi/model/pcf_binding.c b/lib/sbi/openapi/model/pcf_binding.c new file mode 100644 index 000000000..595139c7a --- /dev/null +++ b/lib/sbi/openapi/model/pcf_binding.c @@ -0,0 +1,728 @@ + +#include +#include +#include +#include "pcf_binding.h" + +OpenAPI_pcf_binding_t *OpenAPI_pcf_binding_create( + char *supi, + char *gpsi, + char *ipv4_addr, + char *ipv6_prefix, + OpenAPI_list_t *add_ipv6_prefixes, + char *ip_domain, + char *mac_addr48, + OpenAPI_list_t *add_mac_addrs, + char *dnn, + char *pcf_fqdn, + OpenAPI_list_t *pcf_ip_end_points, + char *pcf_diam_host, + char *pcf_diam_realm, + char *pcf_sm_fqdn, + OpenAPI_list_t *pcf_sm_ip_end_points, + OpenAPI_snssai_t *snssai, + char *supp_feat, + char *pcf_id, + char *pcf_set_id, + char *recovery_time, + OpenAPI_parameter_combination_t *para_com, + OpenAPI_binding_level_e bind_level, + OpenAPI_list_t *ipv4_frame_route_list, + OpenAPI_list_t *ipv6_frame_route_list + ) +{ + OpenAPI_pcf_binding_t *pcf_binding_local_var = OpenAPI_malloc(sizeof(OpenAPI_pcf_binding_t)); + if (!pcf_binding_local_var) { + return NULL; + } + pcf_binding_local_var->supi = supi; + pcf_binding_local_var->gpsi = gpsi; + pcf_binding_local_var->ipv4_addr = ipv4_addr; + pcf_binding_local_var->ipv6_prefix = ipv6_prefix; + pcf_binding_local_var->add_ipv6_prefixes = add_ipv6_prefixes; + pcf_binding_local_var->ip_domain = ip_domain; + pcf_binding_local_var->mac_addr48 = mac_addr48; + pcf_binding_local_var->add_mac_addrs = add_mac_addrs; + pcf_binding_local_var->dnn = dnn; + pcf_binding_local_var->pcf_fqdn = pcf_fqdn; + pcf_binding_local_var->pcf_ip_end_points = pcf_ip_end_points; + pcf_binding_local_var->pcf_diam_host = pcf_diam_host; + pcf_binding_local_var->pcf_diam_realm = pcf_diam_realm; + pcf_binding_local_var->pcf_sm_fqdn = pcf_sm_fqdn; + pcf_binding_local_var->pcf_sm_ip_end_points = pcf_sm_ip_end_points; + pcf_binding_local_var->snssai = snssai; + pcf_binding_local_var->supp_feat = supp_feat; + pcf_binding_local_var->pcf_id = pcf_id; + pcf_binding_local_var->pcf_set_id = pcf_set_id; + pcf_binding_local_var->recovery_time = recovery_time; + pcf_binding_local_var->para_com = para_com; + pcf_binding_local_var->bind_level = bind_level; + pcf_binding_local_var->ipv4_frame_route_list = ipv4_frame_route_list; + pcf_binding_local_var->ipv6_frame_route_list = ipv6_frame_route_list; + + return pcf_binding_local_var; +} + +void OpenAPI_pcf_binding_free(OpenAPI_pcf_binding_t *pcf_binding) +{ + if (NULL == pcf_binding) { + return; + } + OpenAPI_lnode_t *node; + ogs_free(pcf_binding->supi); + ogs_free(pcf_binding->gpsi); + ogs_free(pcf_binding->ipv4_addr); + ogs_free(pcf_binding->ipv6_prefix); + OpenAPI_list_for_each(pcf_binding->add_ipv6_prefixes, node) { + ogs_free(node->data); + } + OpenAPI_list_free(pcf_binding->add_ipv6_prefixes); + ogs_free(pcf_binding->ip_domain); + ogs_free(pcf_binding->mac_addr48); + OpenAPI_list_for_each(pcf_binding->add_mac_addrs, node) { + ogs_free(node->data); + } + OpenAPI_list_free(pcf_binding->add_mac_addrs); + ogs_free(pcf_binding->dnn); + ogs_free(pcf_binding->pcf_fqdn); + OpenAPI_list_for_each(pcf_binding->pcf_ip_end_points, node) { + OpenAPI_ip_end_point_free(node->data); + } + OpenAPI_list_free(pcf_binding->pcf_ip_end_points); + ogs_free(pcf_binding->pcf_diam_host); + ogs_free(pcf_binding->pcf_diam_realm); + ogs_free(pcf_binding->pcf_sm_fqdn); + OpenAPI_list_for_each(pcf_binding->pcf_sm_ip_end_points, node) { + OpenAPI_ip_end_point_free(node->data); + } + OpenAPI_list_free(pcf_binding->pcf_sm_ip_end_points); + OpenAPI_snssai_free(pcf_binding->snssai); + ogs_free(pcf_binding->supp_feat); + ogs_free(pcf_binding->pcf_id); + ogs_free(pcf_binding->pcf_set_id); + ogs_free(pcf_binding->recovery_time); + OpenAPI_parameter_combination_free(pcf_binding->para_com); + OpenAPI_list_for_each(pcf_binding->ipv4_frame_route_list, node) { + ogs_free(node->data); + } + OpenAPI_list_free(pcf_binding->ipv4_frame_route_list); + OpenAPI_list_for_each(pcf_binding->ipv6_frame_route_list, node) { + ogs_free(node->data); + } + OpenAPI_list_free(pcf_binding->ipv6_frame_route_list); + ogs_free(pcf_binding); +} + +cJSON *OpenAPI_pcf_binding_convertToJSON(OpenAPI_pcf_binding_t *pcf_binding) +{ + cJSON *item = NULL; + + if (pcf_binding == NULL) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed [PcfBinding]"); + return NULL; + } + + item = cJSON_CreateObject(); + if (pcf_binding->supi) { + if (cJSON_AddStringToObject(item, "supi", pcf_binding->supi) == NULL) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed [supi]"); + goto end; + } + } + + if (pcf_binding->gpsi) { + if (cJSON_AddStringToObject(item, "gpsi", pcf_binding->gpsi) == NULL) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed [gpsi]"); + goto end; + } + } + + if (pcf_binding->ipv4_addr) { + if (cJSON_AddStringToObject(item, "ipv4Addr", pcf_binding->ipv4_addr) == NULL) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed [ipv4_addr]"); + goto end; + } + } + + if (pcf_binding->ipv6_prefix) { + if (cJSON_AddStringToObject(item, "ipv6Prefix", pcf_binding->ipv6_prefix) == NULL) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed [ipv6_prefix]"); + goto end; + } + } + + if (pcf_binding->add_ipv6_prefixes) { + cJSON *add_ipv6_prefixes = cJSON_AddArrayToObject(item, "addIpv6Prefixes"); + if (add_ipv6_prefixes == NULL) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed [add_ipv6_prefixes]"); + goto end; + } + + OpenAPI_lnode_t *add_ipv6_prefixes_node; + OpenAPI_list_for_each(pcf_binding->add_ipv6_prefixes, add_ipv6_prefixes_node) { + if (cJSON_AddStringToObject(add_ipv6_prefixes, "", (char*)add_ipv6_prefixes_node->data) == NULL) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed [add_ipv6_prefixes]"); + goto end; + } + } + } + + if (pcf_binding->ip_domain) { + if (cJSON_AddStringToObject(item, "ipDomain", pcf_binding->ip_domain) == NULL) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed [ip_domain]"); + goto end; + } + } + + if (pcf_binding->mac_addr48) { + if (cJSON_AddStringToObject(item, "macAddr48", pcf_binding->mac_addr48) == NULL) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed [mac_addr48]"); + goto end; + } + } + + if (pcf_binding->add_mac_addrs) { + cJSON *add_mac_addrs = cJSON_AddArrayToObject(item, "addMacAddrs"); + if (add_mac_addrs == NULL) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed [add_mac_addrs]"); + goto end; + } + + OpenAPI_lnode_t *add_mac_addrs_node; + OpenAPI_list_for_each(pcf_binding->add_mac_addrs, add_mac_addrs_node) { + if (cJSON_AddStringToObject(add_mac_addrs, "", (char*)add_mac_addrs_node->data) == NULL) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed [add_mac_addrs]"); + goto end; + } + } + } + + if (cJSON_AddStringToObject(item, "dnn", pcf_binding->dnn) == NULL) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed [dnn]"); + goto end; + } + + if (pcf_binding->pcf_fqdn) { + if (cJSON_AddStringToObject(item, "pcfFqdn", pcf_binding->pcf_fqdn) == NULL) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed [pcf_fqdn]"); + goto end; + } + } + + if (pcf_binding->pcf_ip_end_points) { + cJSON *pcf_ip_end_pointsList = cJSON_AddArrayToObject(item, "pcfIpEndPoints"); + if (pcf_ip_end_pointsList == NULL) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed [pcf_ip_end_points]"); + goto end; + } + + OpenAPI_lnode_t *pcf_ip_end_points_node; + if (pcf_binding->pcf_ip_end_points) { + OpenAPI_list_for_each(pcf_binding->pcf_ip_end_points, pcf_ip_end_points_node) { + cJSON *itemLocal = OpenAPI_ip_end_point_convertToJSON(pcf_ip_end_points_node->data); + if (itemLocal == NULL) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed [pcf_ip_end_points]"); + goto end; + } + cJSON_AddItemToArray(pcf_ip_end_pointsList, itemLocal); + } + } + } + + if (pcf_binding->pcf_diam_host) { + if (cJSON_AddStringToObject(item, "pcfDiamHost", pcf_binding->pcf_diam_host) == NULL) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed [pcf_diam_host]"); + goto end; + } + } + + if (pcf_binding->pcf_diam_realm) { + if (cJSON_AddStringToObject(item, "pcfDiamRealm", pcf_binding->pcf_diam_realm) == NULL) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed [pcf_diam_realm]"); + goto end; + } + } + + if (pcf_binding->pcf_sm_fqdn) { + if (cJSON_AddStringToObject(item, "pcfSmFqdn", pcf_binding->pcf_sm_fqdn) == NULL) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed [pcf_sm_fqdn]"); + goto end; + } + } + + if (pcf_binding->pcf_sm_ip_end_points) { + cJSON *pcf_sm_ip_end_pointsList = cJSON_AddArrayToObject(item, "pcfSmIpEndPoints"); + if (pcf_sm_ip_end_pointsList == NULL) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed [pcf_sm_ip_end_points]"); + goto end; + } + + OpenAPI_lnode_t *pcf_sm_ip_end_points_node; + if (pcf_binding->pcf_sm_ip_end_points) { + OpenAPI_list_for_each(pcf_binding->pcf_sm_ip_end_points, pcf_sm_ip_end_points_node) { + cJSON *itemLocal = OpenAPI_ip_end_point_convertToJSON(pcf_sm_ip_end_points_node->data); + if (itemLocal == NULL) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed [pcf_sm_ip_end_points]"); + goto end; + } + cJSON_AddItemToArray(pcf_sm_ip_end_pointsList, itemLocal); + } + } + } + + cJSON *snssai_local_JSON = OpenAPI_snssai_convertToJSON(pcf_binding->snssai); + if (snssai_local_JSON == NULL) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed [snssai]"); + goto end; + } + cJSON_AddItemToObject(item, "snssai", snssai_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed [snssai]"); + goto end; + } + + if (pcf_binding->supp_feat) { + if (cJSON_AddStringToObject(item, "suppFeat", pcf_binding->supp_feat) == NULL) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed [supp_feat]"); + goto end; + } + } + + if (pcf_binding->pcf_id) { + if (cJSON_AddStringToObject(item, "pcfId", pcf_binding->pcf_id) == NULL) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed [pcf_id]"); + goto end; + } + } + + if (pcf_binding->pcf_set_id) { + if (cJSON_AddStringToObject(item, "pcfSetId", pcf_binding->pcf_set_id) == NULL) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed [pcf_set_id]"); + goto end; + } + } + + if (pcf_binding->recovery_time) { + if (cJSON_AddStringToObject(item, "recoveryTime", pcf_binding->recovery_time) == NULL) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed [recovery_time]"); + goto end; + } + } + + if (pcf_binding->para_com) { + cJSON *para_com_local_JSON = OpenAPI_parameter_combination_convertToJSON(pcf_binding->para_com); + if (para_com_local_JSON == NULL) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed [para_com]"); + goto end; + } + cJSON_AddItemToObject(item, "paraCom", para_com_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed [para_com]"); + goto end; + } + } + + if (pcf_binding->bind_level) { + if (cJSON_AddStringToObject(item, "bindLevel", OpenAPI_binding_level_ToString(pcf_binding->bind_level)) == NULL) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed [bind_level]"); + goto end; + } + } + + if (pcf_binding->ipv4_frame_route_list) { + cJSON *ipv4_frame_route_list = cJSON_AddArrayToObject(item, "ipv4FrameRouteList"); + if (ipv4_frame_route_list == NULL) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed [ipv4_frame_route_list]"); + goto end; + } + + OpenAPI_lnode_t *ipv4_frame_route_list_node; + OpenAPI_list_for_each(pcf_binding->ipv4_frame_route_list, ipv4_frame_route_list_node) { + if (cJSON_AddStringToObject(ipv4_frame_route_list, "", (char*)ipv4_frame_route_list_node->data) == NULL) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed [ipv4_frame_route_list]"); + goto end; + } + } + } + + if (pcf_binding->ipv6_frame_route_list) { + cJSON *ipv6_frame_route_list = cJSON_AddArrayToObject(item, "ipv6FrameRouteList"); + if (ipv6_frame_route_list == NULL) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed [ipv6_frame_route_list]"); + goto end; + } + + OpenAPI_lnode_t *ipv6_frame_route_list_node; + OpenAPI_list_for_each(pcf_binding->ipv6_frame_route_list, ipv6_frame_route_list_node) { + if (cJSON_AddStringToObject(ipv6_frame_route_list, "", (char*)ipv6_frame_route_list_node->data) == NULL) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed [ipv6_frame_route_list]"); + goto end; + } + } + } + +end: + return item; +} + +OpenAPI_pcf_binding_t *OpenAPI_pcf_binding_parseFromJSON(cJSON *pcf_bindingJSON) +{ + OpenAPI_pcf_binding_t *pcf_binding_local_var = NULL; + cJSON *supi = cJSON_GetObjectItemCaseSensitive(pcf_bindingJSON, "supi"); + + if (supi) { + if (!cJSON_IsString(supi)) { + ogs_error("OpenAPI_pcf_binding_parseFromJSON() failed [supi]"); + goto end; + } + } + + cJSON *gpsi = cJSON_GetObjectItemCaseSensitive(pcf_bindingJSON, "gpsi"); + + if (gpsi) { + if (!cJSON_IsString(gpsi)) { + ogs_error("OpenAPI_pcf_binding_parseFromJSON() failed [gpsi]"); + goto end; + } + } + + cJSON *ipv4_addr = cJSON_GetObjectItemCaseSensitive(pcf_bindingJSON, "ipv4Addr"); + + if (ipv4_addr) { + if (!cJSON_IsString(ipv4_addr)) { + ogs_error("OpenAPI_pcf_binding_parseFromJSON() failed [ipv4_addr]"); + goto end; + } + } + + cJSON *ipv6_prefix = cJSON_GetObjectItemCaseSensitive(pcf_bindingJSON, "ipv6Prefix"); + + if (ipv6_prefix) { + if (!cJSON_IsString(ipv6_prefix)) { + ogs_error("OpenAPI_pcf_binding_parseFromJSON() failed [ipv6_prefix]"); + goto end; + } + } + + cJSON *add_ipv6_prefixes = cJSON_GetObjectItemCaseSensitive(pcf_bindingJSON, "addIpv6Prefixes"); + + OpenAPI_list_t *add_ipv6_prefixesList; + if (add_ipv6_prefixes) { + cJSON *add_ipv6_prefixes_local; + if (!cJSON_IsArray(add_ipv6_prefixes)) { + ogs_error("OpenAPI_pcf_binding_parseFromJSON() failed [add_ipv6_prefixes]"); + goto end; + } + add_ipv6_prefixesList = OpenAPI_list_create(); + + cJSON_ArrayForEach(add_ipv6_prefixes_local, add_ipv6_prefixes) { + if (!cJSON_IsString(add_ipv6_prefixes_local)) { + ogs_error("OpenAPI_pcf_binding_parseFromJSON() failed [add_ipv6_prefixes]"); + goto end; + } + OpenAPI_list_add(add_ipv6_prefixesList, ogs_strdup(add_ipv6_prefixes_local->valuestring)); + } + } + + cJSON *ip_domain = cJSON_GetObjectItemCaseSensitive(pcf_bindingJSON, "ipDomain"); + + if (ip_domain) { + if (!cJSON_IsString(ip_domain)) { + ogs_error("OpenAPI_pcf_binding_parseFromJSON() failed [ip_domain]"); + goto end; + } + } + + cJSON *mac_addr48 = cJSON_GetObjectItemCaseSensitive(pcf_bindingJSON, "macAddr48"); + + if (mac_addr48) { + if (!cJSON_IsString(mac_addr48)) { + ogs_error("OpenAPI_pcf_binding_parseFromJSON() failed [mac_addr48]"); + goto end; + } + } + + cJSON *add_mac_addrs = cJSON_GetObjectItemCaseSensitive(pcf_bindingJSON, "addMacAddrs"); + + OpenAPI_list_t *add_mac_addrsList; + if (add_mac_addrs) { + cJSON *add_mac_addrs_local; + if (!cJSON_IsArray(add_mac_addrs)) { + ogs_error("OpenAPI_pcf_binding_parseFromJSON() failed [add_mac_addrs]"); + goto end; + } + add_mac_addrsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(add_mac_addrs_local, add_mac_addrs) { + if (!cJSON_IsString(add_mac_addrs_local)) { + ogs_error("OpenAPI_pcf_binding_parseFromJSON() failed [add_mac_addrs]"); + goto end; + } + OpenAPI_list_add(add_mac_addrsList, ogs_strdup(add_mac_addrs_local->valuestring)); + } + } + + cJSON *dnn = cJSON_GetObjectItemCaseSensitive(pcf_bindingJSON, "dnn"); + if (!dnn) { + ogs_error("OpenAPI_pcf_binding_parseFromJSON() failed [dnn]"); + goto end; + } + + + if (!cJSON_IsString(dnn)) { + ogs_error("OpenAPI_pcf_binding_parseFromJSON() failed [dnn]"); + goto end; + } + + cJSON *pcf_fqdn = cJSON_GetObjectItemCaseSensitive(pcf_bindingJSON, "pcfFqdn"); + + if (pcf_fqdn) { + if (!cJSON_IsString(pcf_fqdn)) { + ogs_error("OpenAPI_pcf_binding_parseFromJSON() failed [pcf_fqdn]"); + goto end; + } + } + + cJSON *pcf_ip_end_points = cJSON_GetObjectItemCaseSensitive(pcf_bindingJSON, "pcfIpEndPoints"); + + OpenAPI_list_t *pcf_ip_end_pointsList; + if (pcf_ip_end_points) { + cJSON *pcf_ip_end_points_local_nonprimitive; + if (!cJSON_IsArray(pcf_ip_end_points)) { + ogs_error("OpenAPI_pcf_binding_parseFromJSON() failed [pcf_ip_end_points]"); + goto end; + } + + pcf_ip_end_pointsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(pcf_ip_end_points_local_nonprimitive, pcf_ip_end_points ) { + if (!cJSON_IsObject(pcf_ip_end_points_local_nonprimitive)) { + ogs_error("OpenAPI_pcf_binding_parseFromJSON() failed [pcf_ip_end_points]"); + goto end; + } + OpenAPI_ip_end_point_t *pcf_ip_end_pointsItem = OpenAPI_ip_end_point_parseFromJSON(pcf_ip_end_points_local_nonprimitive); + + OpenAPI_list_add(pcf_ip_end_pointsList, pcf_ip_end_pointsItem); + } + } + + cJSON *pcf_diam_host = cJSON_GetObjectItemCaseSensitive(pcf_bindingJSON, "pcfDiamHost"); + + if (pcf_diam_host) { + if (!cJSON_IsString(pcf_diam_host)) { + ogs_error("OpenAPI_pcf_binding_parseFromJSON() failed [pcf_diam_host]"); + goto end; + } + } + + cJSON *pcf_diam_realm = cJSON_GetObjectItemCaseSensitive(pcf_bindingJSON, "pcfDiamRealm"); + + if (pcf_diam_realm) { + if (!cJSON_IsString(pcf_diam_realm)) { + ogs_error("OpenAPI_pcf_binding_parseFromJSON() failed [pcf_diam_realm]"); + goto end; + } + } + + cJSON *pcf_sm_fqdn = cJSON_GetObjectItemCaseSensitive(pcf_bindingJSON, "pcfSmFqdn"); + + if (pcf_sm_fqdn) { + if (!cJSON_IsString(pcf_sm_fqdn)) { + ogs_error("OpenAPI_pcf_binding_parseFromJSON() failed [pcf_sm_fqdn]"); + goto end; + } + } + + cJSON *pcf_sm_ip_end_points = cJSON_GetObjectItemCaseSensitive(pcf_bindingJSON, "pcfSmIpEndPoints"); + + OpenAPI_list_t *pcf_sm_ip_end_pointsList; + if (pcf_sm_ip_end_points) { + cJSON *pcf_sm_ip_end_points_local_nonprimitive; + if (!cJSON_IsArray(pcf_sm_ip_end_points)) { + ogs_error("OpenAPI_pcf_binding_parseFromJSON() failed [pcf_sm_ip_end_points]"); + goto end; + } + + pcf_sm_ip_end_pointsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(pcf_sm_ip_end_points_local_nonprimitive, pcf_sm_ip_end_points ) { + if (!cJSON_IsObject(pcf_sm_ip_end_points_local_nonprimitive)) { + ogs_error("OpenAPI_pcf_binding_parseFromJSON() failed [pcf_sm_ip_end_points]"); + goto end; + } + OpenAPI_ip_end_point_t *pcf_sm_ip_end_pointsItem = OpenAPI_ip_end_point_parseFromJSON(pcf_sm_ip_end_points_local_nonprimitive); + + OpenAPI_list_add(pcf_sm_ip_end_pointsList, pcf_sm_ip_end_pointsItem); + } + } + + cJSON *snssai = cJSON_GetObjectItemCaseSensitive(pcf_bindingJSON, "snssai"); + if (!snssai) { + ogs_error("OpenAPI_pcf_binding_parseFromJSON() failed [snssai]"); + goto end; + } + + OpenAPI_snssai_t *snssai_local_nonprim = NULL; + + snssai_local_nonprim = OpenAPI_snssai_parseFromJSON(snssai); + + cJSON *supp_feat = cJSON_GetObjectItemCaseSensitive(pcf_bindingJSON, "suppFeat"); + + if (supp_feat) { + if (!cJSON_IsString(supp_feat)) { + ogs_error("OpenAPI_pcf_binding_parseFromJSON() failed [supp_feat]"); + goto end; + } + } + + cJSON *pcf_id = cJSON_GetObjectItemCaseSensitive(pcf_bindingJSON, "pcfId"); + + if (pcf_id) { + if (!cJSON_IsString(pcf_id)) { + ogs_error("OpenAPI_pcf_binding_parseFromJSON() failed [pcf_id]"); + goto end; + } + } + + cJSON *pcf_set_id = cJSON_GetObjectItemCaseSensitive(pcf_bindingJSON, "pcfSetId"); + + if (pcf_set_id) { + if (!cJSON_IsString(pcf_set_id)) { + ogs_error("OpenAPI_pcf_binding_parseFromJSON() failed [pcf_set_id]"); + goto end; + } + } + + cJSON *recovery_time = cJSON_GetObjectItemCaseSensitive(pcf_bindingJSON, "recoveryTime"); + + if (recovery_time) { + if (!cJSON_IsString(recovery_time)) { + ogs_error("OpenAPI_pcf_binding_parseFromJSON() failed [recovery_time]"); + goto end; + } + } + + cJSON *para_com = cJSON_GetObjectItemCaseSensitive(pcf_bindingJSON, "paraCom"); + + OpenAPI_parameter_combination_t *para_com_local_nonprim = NULL; + if (para_com) { + para_com_local_nonprim = OpenAPI_parameter_combination_parseFromJSON(para_com); + } + + cJSON *bind_level = cJSON_GetObjectItemCaseSensitive(pcf_bindingJSON, "bindLevel"); + + OpenAPI_binding_level_e bind_levelVariable; + if (bind_level) { + if (!cJSON_IsString(bind_level)) { + ogs_error("OpenAPI_pcf_binding_parseFromJSON() failed [bind_level]"); + goto end; + } + bind_levelVariable = OpenAPI_binding_level_FromString(bind_level->valuestring); + } + + cJSON *ipv4_frame_route_list = cJSON_GetObjectItemCaseSensitive(pcf_bindingJSON, "ipv4FrameRouteList"); + + OpenAPI_list_t *ipv4_frame_route_listList; + if (ipv4_frame_route_list) { + cJSON *ipv4_frame_route_list_local; + if (!cJSON_IsArray(ipv4_frame_route_list)) { + ogs_error("OpenAPI_pcf_binding_parseFromJSON() failed [ipv4_frame_route_list]"); + goto end; + } + ipv4_frame_route_listList = OpenAPI_list_create(); + + cJSON_ArrayForEach(ipv4_frame_route_list_local, ipv4_frame_route_list) { + if (!cJSON_IsString(ipv4_frame_route_list_local)) { + ogs_error("OpenAPI_pcf_binding_parseFromJSON() failed [ipv4_frame_route_list]"); + goto end; + } + OpenAPI_list_add(ipv4_frame_route_listList, ogs_strdup(ipv4_frame_route_list_local->valuestring)); + } + } + + cJSON *ipv6_frame_route_list = cJSON_GetObjectItemCaseSensitive(pcf_bindingJSON, "ipv6FrameRouteList"); + + OpenAPI_list_t *ipv6_frame_route_listList; + if (ipv6_frame_route_list) { + cJSON *ipv6_frame_route_list_local; + if (!cJSON_IsArray(ipv6_frame_route_list)) { + ogs_error("OpenAPI_pcf_binding_parseFromJSON() failed [ipv6_frame_route_list]"); + goto end; + } + ipv6_frame_route_listList = OpenAPI_list_create(); + + cJSON_ArrayForEach(ipv6_frame_route_list_local, ipv6_frame_route_list) { + if (!cJSON_IsString(ipv6_frame_route_list_local)) { + ogs_error("OpenAPI_pcf_binding_parseFromJSON() failed [ipv6_frame_route_list]"); + goto end; + } + OpenAPI_list_add(ipv6_frame_route_listList, ogs_strdup(ipv6_frame_route_list_local->valuestring)); + } + } + + pcf_binding_local_var = OpenAPI_pcf_binding_create ( + supi ? ogs_strdup(supi->valuestring) : NULL, + gpsi ? ogs_strdup(gpsi->valuestring) : NULL, + ipv4_addr ? ogs_strdup(ipv4_addr->valuestring) : NULL, + ipv6_prefix ? ogs_strdup(ipv6_prefix->valuestring) : NULL, + add_ipv6_prefixes ? add_ipv6_prefixesList : NULL, + ip_domain ? ogs_strdup(ip_domain->valuestring) : NULL, + mac_addr48 ? ogs_strdup(mac_addr48->valuestring) : NULL, + add_mac_addrs ? add_mac_addrsList : NULL, + ogs_strdup(dnn->valuestring), + pcf_fqdn ? ogs_strdup(pcf_fqdn->valuestring) : NULL, + pcf_ip_end_points ? pcf_ip_end_pointsList : NULL, + pcf_diam_host ? ogs_strdup(pcf_diam_host->valuestring) : NULL, + pcf_diam_realm ? ogs_strdup(pcf_diam_realm->valuestring) : NULL, + pcf_sm_fqdn ? ogs_strdup(pcf_sm_fqdn->valuestring) : NULL, + pcf_sm_ip_end_points ? pcf_sm_ip_end_pointsList : NULL, + snssai_local_nonprim, + supp_feat ? ogs_strdup(supp_feat->valuestring) : NULL, + pcf_id ? ogs_strdup(pcf_id->valuestring) : NULL, + pcf_set_id ? ogs_strdup(pcf_set_id->valuestring) : NULL, + recovery_time ? ogs_strdup(recovery_time->valuestring) : NULL, + para_com ? para_com_local_nonprim : NULL, + bind_level ? bind_levelVariable : 0, + ipv4_frame_route_list ? ipv4_frame_route_listList : NULL, + ipv6_frame_route_list ? ipv6_frame_route_listList : NULL + ); + + return pcf_binding_local_var; +end: + return NULL; +} + +OpenAPI_pcf_binding_t *OpenAPI_pcf_binding_copy(OpenAPI_pcf_binding_t *dst, OpenAPI_pcf_binding_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_pcf_binding_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_pcf_binding_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_pcf_binding_free(dst); + dst = OpenAPI_pcf_binding_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/pcf_binding.h b/lib/sbi/openapi/model/pcf_binding.h new file mode 100644 index 000000000..1dda1c9ff --- /dev/null +++ b/lib/sbi/openapi/model/pcf_binding.h @@ -0,0 +1,88 @@ +/* + * pcf_binding.h + * + * + */ + +#ifndef _OpenAPI_pcf_binding_H_ +#define _OpenAPI_pcf_binding_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" +#include "binding_level.h" +#include "ip_end_point.h" +#include "parameter_combination.h" +#include "snssai.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_pcf_binding_s OpenAPI_pcf_binding_t; +typedef struct OpenAPI_pcf_binding_s { + char *supi; + char *gpsi; + char *ipv4_addr; + char *ipv6_prefix; + OpenAPI_list_t *add_ipv6_prefixes; + char *ip_domain; + char *mac_addr48; + OpenAPI_list_t *add_mac_addrs; + char *dnn; + char *pcf_fqdn; + OpenAPI_list_t *pcf_ip_end_points; + char *pcf_diam_host; + char *pcf_diam_realm; + char *pcf_sm_fqdn; + OpenAPI_list_t *pcf_sm_ip_end_points; + struct OpenAPI_snssai_s *snssai; + char *supp_feat; + char *pcf_id; + char *pcf_set_id; + char *recovery_time; + struct OpenAPI_parameter_combination_s *para_com; + OpenAPI_binding_level_e bind_level; + OpenAPI_list_t *ipv4_frame_route_list; + OpenAPI_list_t *ipv6_frame_route_list; +} OpenAPI_pcf_binding_t; + +OpenAPI_pcf_binding_t *OpenAPI_pcf_binding_create( + char *supi, + char *gpsi, + char *ipv4_addr, + char *ipv6_prefix, + OpenAPI_list_t *add_ipv6_prefixes, + char *ip_domain, + char *mac_addr48, + OpenAPI_list_t *add_mac_addrs, + char *dnn, + char *pcf_fqdn, + OpenAPI_list_t *pcf_ip_end_points, + char *pcf_diam_host, + char *pcf_diam_realm, + char *pcf_sm_fqdn, + OpenAPI_list_t *pcf_sm_ip_end_points, + OpenAPI_snssai_t *snssai, + char *supp_feat, + char *pcf_id, + char *pcf_set_id, + char *recovery_time, + OpenAPI_parameter_combination_t *para_com, + OpenAPI_binding_level_e bind_level, + OpenAPI_list_t *ipv4_frame_route_list, + OpenAPI_list_t *ipv6_frame_route_list + ); +void OpenAPI_pcf_binding_free(OpenAPI_pcf_binding_t *pcf_binding); +OpenAPI_pcf_binding_t *OpenAPI_pcf_binding_parseFromJSON(cJSON *pcf_bindingJSON); +cJSON *OpenAPI_pcf_binding_convertToJSON(OpenAPI_pcf_binding_t *pcf_binding); +OpenAPI_pcf_binding_t *OpenAPI_pcf_binding_copy(OpenAPI_pcf_binding_t *dst, OpenAPI_pcf_binding_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_pcf_binding_H_ */ + diff --git a/lib/sbi/openapi/model/pcf_binding_patch.c b/lib/sbi/openapi/model/pcf_binding_patch.c new file mode 100644 index 000000000..336b7219b --- /dev/null +++ b/lib/sbi/openapi/model/pcf_binding_patch.c @@ -0,0 +1,381 @@ + +#include +#include +#include +#include "pcf_binding_patch.h" + +OpenAPI_pcf_binding_patch_t *OpenAPI_pcf_binding_patch_create( + char *ipv4_addr, + char *ip_domain, + char *ipv6_prefix, + OpenAPI_list_t *add_ipv6_prefixes, + char *mac_addr48, + OpenAPI_list_t *add_mac_addrs, + char *pcf_id, + char *pcf_fqdn, + OpenAPI_list_t *pcf_ip_end_points, + char *pcf_diam_host, + char *pcf_diam_realm + ) +{ + OpenAPI_pcf_binding_patch_t *pcf_binding_patch_local_var = OpenAPI_malloc(sizeof(OpenAPI_pcf_binding_patch_t)); + if (!pcf_binding_patch_local_var) { + return NULL; + } + pcf_binding_patch_local_var->ipv4_addr = ipv4_addr; + pcf_binding_patch_local_var->ip_domain = ip_domain; + pcf_binding_patch_local_var->ipv6_prefix = ipv6_prefix; + pcf_binding_patch_local_var->add_ipv6_prefixes = add_ipv6_prefixes; + pcf_binding_patch_local_var->mac_addr48 = mac_addr48; + pcf_binding_patch_local_var->add_mac_addrs = add_mac_addrs; + pcf_binding_patch_local_var->pcf_id = pcf_id; + pcf_binding_patch_local_var->pcf_fqdn = pcf_fqdn; + pcf_binding_patch_local_var->pcf_ip_end_points = pcf_ip_end_points; + pcf_binding_patch_local_var->pcf_diam_host = pcf_diam_host; + pcf_binding_patch_local_var->pcf_diam_realm = pcf_diam_realm; + + return pcf_binding_patch_local_var; +} + +void OpenAPI_pcf_binding_patch_free(OpenAPI_pcf_binding_patch_t *pcf_binding_patch) +{ + if (NULL == pcf_binding_patch) { + return; + } + OpenAPI_lnode_t *node; + ogs_free(pcf_binding_patch->ipv4_addr); + ogs_free(pcf_binding_patch->ip_domain); + ogs_free(pcf_binding_patch->ipv6_prefix); + OpenAPI_list_for_each(pcf_binding_patch->add_ipv6_prefixes, node) { + ogs_free(node->data); + } + OpenAPI_list_free(pcf_binding_patch->add_ipv6_prefixes); + ogs_free(pcf_binding_patch->mac_addr48); + OpenAPI_list_for_each(pcf_binding_patch->add_mac_addrs, node) { + ogs_free(node->data); + } + OpenAPI_list_free(pcf_binding_patch->add_mac_addrs); + ogs_free(pcf_binding_patch->pcf_id); + ogs_free(pcf_binding_patch->pcf_fqdn); + OpenAPI_list_for_each(pcf_binding_patch->pcf_ip_end_points, node) { + OpenAPI_ip_end_point_free(node->data); + } + OpenAPI_list_free(pcf_binding_patch->pcf_ip_end_points); + ogs_free(pcf_binding_patch->pcf_diam_host); + ogs_free(pcf_binding_patch->pcf_diam_realm); + ogs_free(pcf_binding_patch); +} + +cJSON *OpenAPI_pcf_binding_patch_convertToJSON(OpenAPI_pcf_binding_patch_t *pcf_binding_patch) +{ + cJSON *item = NULL; + + if (pcf_binding_patch == NULL) { + ogs_error("OpenAPI_pcf_binding_patch_convertToJSON() failed [PcfBindingPatch]"); + return NULL; + } + + item = cJSON_CreateObject(); + if (pcf_binding_patch->ipv4_addr) { + if (cJSON_AddStringToObject(item, "ipv4Addr", pcf_binding_patch->ipv4_addr) == NULL) { + ogs_error("OpenAPI_pcf_binding_patch_convertToJSON() failed [ipv4_addr]"); + goto end; + } + } + + if (pcf_binding_patch->ip_domain) { + if (cJSON_AddStringToObject(item, "ipDomain", pcf_binding_patch->ip_domain) == NULL) { + ogs_error("OpenAPI_pcf_binding_patch_convertToJSON() failed [ip_domain]"); + goto end; + } + } + + if (pcf_binding_patch->ipv6_prefix) { + if (cJSON_AddStringToObject(item, "ipv6Prefix", pcf_binding_patch->ipv6_prefix) == NULL) { + ogs_error("OpenAPI_pcf_binding_patch_convertToJSON() failed [ipv6_prefix]"); + goto end; + } + } + + if (pcf_binding_patch->add_ipv6_prefixes) { + cJSON *add_ipv6_prefixes = cJSON_AddArrayToObject(item, "addIpv6Prefixes"); + if (add_ipv6_prefixes == NULL) { + ogs_error("OpenAPI_pcf_binding_patch_convertToJSON() failed [add_ipv6_prefixes]"); + goto end; + } + + OpenAPI_lnode_t *add_ipv6_prefixes_node; + OpenAPI_list_for_each(pcf_binding_patch->add_ipv6_prefixes, add_ipv6_prefixes_node) { + if (cJSON_AddStringToObject(add_ipv6_prefixes, "", (char*)add_ipv6_prefixes_node->data) == NULL) { + ogs_error("OpenAPI_pcf_binding_patch_convertToJSON() failed [add_ipv6_prefixes]"); + goto end; + } + } + } + + if (pcf_binding_patch->mac_addr48) { + if (cJSON_AddStringToObject(item, "macAddr48", pcf_binding_patch->mac_addr48) == NULL) { + ogs_error("OpenAPI_pcf_binding_patch_convertToJSON() failed [mac_addr48]"); + goto end; + } + } + + if (pcf_binding_patch->add_mac_addrs) { + cJSON *add_mac_addrs = cJSON_AddArrayToObject(item, "addMacAddrs"); + if (add_mac_addrs == NULL) { + ogs_error("OpenAPI_pcf_binding_patch_convertToJSON() failed [add_mac_addrs]"); + goto end; + } + + OpenAPI_lnode_t *add_mac_addrs_node; + OpenAPI_list_for_each(pcf_binding_patch->add_mac_addrs, add_mac_addrs_node) { + if (cJSON_AddStringToObject(add_mac_addrs, "", (char*)add_mac_addrs_node->data) == NULL) { + ogs_error("OpenAPI_pcf_binding_patch_convertToJSON() failed [add_mac_addrs]"); + goto end; + } + } + } + + if (pcf_binding_patch->pcf_id) { + if (cJSON_AddStringToObject(item, "pcfId", pcf_binding_patch->pcf_id) == NULL) { + ogs_error("OpenAPI_pcf_binding_patch_convertToJSON() failed [pcf_id]"); + goto end; + } + } + + if (pcf_binding_patch->pcf_fqdn) { + if (cJSON_AddStringToObject(item, "pcfFqdn", pcf_binding_patch->pcf_fqdn) == NULL) { + ogs_error("OpenAPI_pcf_binding_patch_convertToJSON() failed [pcf_fqdn]"); + goto end; + } + } + + if (pcf_binding_patch->pcf_ip_end_points) { + cJSON *pcf_ip_end_pointsList = cJSON_AddArrayToObject(item, "pcfIpEndPoints"); + if (pcf_ip_end_pointsList == NULL) { + ogs_error("OpenAPI_pcf_binding_patch_convertToJSON() failed [pcf_ip_end_points]"); + goto end; + } + + OpenAPI_lnode_t *pcf_ip_end_points_node; + if (pcf_binding_patch->pcf_ip_end_points) { + OpenAPI_list_for_each(pcf_binding_patch->pcf_ip_end_points, pcf_ip_end_points_node) { + cJSON *itemLocal = OpenAPI_ip_end_point_convertToJSON(pcf_ip_end_points_node->data); + if (itemLocal == NULL) { + ogs_error("OpenAPI_pcf_binding_patch_convertToJSON() failed [pcf_ip_end_points]"); + goto end; + } + cJSON_AddItemToArray(pcf_ip_end_pointsList, itemLocal); + } + } + } + + if (pcf_binding_patch->pcf_diam_host) { + if (cJSON_AddStringToObject(item, "pcfDiamHost", pcf_binding_patch->pcf_diam_host) == NULL) { + ogs_error("OpenAPI_pcf_binding_patch_convertToJSON() failed [pcf_diam_host]"); + goto end; + } + } + + if (pcf_binding_patch->pcf_diam_realm) { + if (cJSON_AddStringToObject(item, "pcfDiamRealm", pcf_binding_patch->pcf_diam_realm) == NULL) { + ogs_error("OpenAPI_pcf_binding_patch_convertToJSON() failed [pcf_diam_realm]"); + goto end; + } + } + +end: + return item; +} + +OpenAPI_pcf_binding_patch_t *OpenAPI_pcf_binding_patch_parseFromJSON(cJSON *pcf_binding_patchJSON) +{ + OpenAPI_pcf_binding_patch_t *pcf_binding_patch_local_var = NULL; + cJSON *ipv4_addr = cJSON_GetObjectItemCaseSensitive(pcf_binding_patchJSON, "ipv4Addr"); + + if (ipv4_addr) { + if (!cJSON_IsString(ipv4_addr)) { + ogs_error("OpenAPI_pcf_binding_patch_parseFromJSON() failed [ipv4_addr]"); + goto end; + } + } + + cJSON *ip_domain = cJSON_GetObjectItemCaseSensitive(pcf_binding_patchJSON, "ipDomain"); + + if (ip_domain) { + if (!cJSON_IsString(ip_domain)) { + ogs_error("OpenAPI_pcf_binding_patch_parseFromJSON() failed [ip_domain]"); + goto end; + } + } + + cJSON *ipv6_prefix = cJSON_GetObjectItemCaseSensitive(pcf_binding_patchJSON, "ipv6Prefix"); + + if (ipv6_prefix) { + if (!cJSON_IsString(ipv6_prefix)) { + ogs_error("OpenAPI_pcf_binding_patch_parseFromJSON() failed [ipv6_prefix]"); + goto end; + } + } + + cJSON *add_ipv6_prefixes = cJSON_GetObjectItemCaseSensitive(pcf_binding_patchJSON, "addIpv6Prefixes"); + + OpenAPI_list_t *add_ipv6_prefixesList; + if (add_ipv6_prefixes) { + cJSON *add_ipv6_prefixes_local; + if (!cJSON_IsArray(add_ipv6_prefixes)) { + ogs_error("OpenAPI_pcf_binding_patch_parseFromJSON() failed [add_ipv6_prefixes]"); + goto end; + } + add_ipv6_prefixesList = OpenAPI_list_create(); + + cJSON_ArrayForEach(add_ipv6_prefixes_local, add_ipv6_prefixes) { + if (!cJSON_IsString(add_ipv6_prefixes_local)) { + ogs_error("OpenAPI_pcf_binding_patch_parseFromJSON() failed [add_ipv6_prefixes]"); + goto end; + } + OpenAPI_list_add(add_ipv6_prefixesList, ogs_strdup(add_ipv6_prefixes_local->valuestring)); + } + } + + cJSON *mac_addr48 = cJSON_GetObjectItemCaseSensitive(pcf_binding_patchJSON, "macAddr48"); + + if (mac_addr48) { + if (!cJSON_IsString(mac_addr48)) { + ogs_error("OpenAPI_pcf_binding_patch_parseFromJSON() failed [mac_addr48]"); + goto end; + } + } + + cJSON *add_mac_addrs = cJSON_GetObjectItemCaseSensitive(pcf_binding_patchJSON, "addMacAddrs"); + + OpenAPI_list_t *add_mac_addrsList; + if (add_mac_addrs) { + cJSON *add_mac_addrs_local; + if (!cJSON_IsArray(add_mac_addrs)) { + ogs_error("OpenAPI_pcf_binding_patch_parseFromJSON() failed [add_mac_addrs]"); + goto end; + } + add_mac_addrsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(add_mac_addrs_local, add_mac_addrs) { + if (!cJSON_IsString(add_mac_addrs_local)) { + ogs_error("OpenAPI_pcf_binding_patch_parseFromJSON() failed [add_mac_addrs]"); + goto end; + } + OpenAPI_list_add(add_mac_addrsList, ogs_strdup(add_mac_addrs_local->valuestring)); + } + } + + cJSON *pcf_id = cJSON_GetObjectItemCaseSensitive(pcf_binding_patchJSON, "pcfId"); + + if (pcf_id) { + if (!cJSON_IsString(pcf_id)) { + ogs_error("OpenAPI_pcf_binding_patch_parseFromJSON() failed [pcf_id]"); + goto end; + } + } + + cJSON *pcf_fqdn = cJSON_GetObjectItemCaseSensitive(pcf_binding_patchJSON, "pcfFqdn"); + + if (pcf_fqdn) { + if (!cJSON_IsString(pcf_fqdn)) { + ogs_error("OpenAPI_pcf_binding_patch_parseFromJSON() failed [pcf_fqdn]"); + goto end; + } + } + + cJSON *pcf_ip_end_points = cJSON_GetObjectItemCaseSensitive(pcf_binding_patchJSON, "pcfIpEndPoints"); + + OpenAPI_list_t *pcf_ip_end_pointsList; + if (pcf_ip_end_points) { + cJSON *pcf_ip_end_points_local_nonprimitive; + if (!cJSON_IsArray(pcf_ip_end_points)) { + ogs_error("OpenAPI_pcf_binding_patch_parseFromJSON() failed [pcf_ip_end_points]"); + goto end; + } + + pcf_ip_end_pointsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(pcf_ip_end_points_local_nonprimitive, pcf_ip_end_points ) { + if (!cJSON_IsObject(pcf_ip_end_points_local_nonprimitive)) { + ogs_error("OpenAPI_pcf_binding_patch_parseFromJSON() failed [pcf_ip_end_points]"); + goto end; + } + OpenAPI_ip_end_point_t *pcf_ip_end_pointsItem = OpenAPI_ip_end_point_parseFromJSON(pcf_ip_end_points_local_nonprimitive); + + OpenAPI_list_add(pcf_ip_end_pointsList, pcf_ip_end_pointsItem); + } + } + + cJSON *pcf_diam_host = cJSON_GetObjectItemCaseSensitive(pcf_binding_patchJSON, "pcfDiamHost"); + + if (pcf_diam_host) { + if (!cJSON_IsString(pcf_diam_host)) { + ogs_error("OpenAPI_pcf_binding_patch_parseFromJSON() failed [pcf_diam_host]"); + goto end; + } + } + + cJSON *pcf_diam_realm = cJSON_GetObjectItemCaseSensitive(pcf_binding_patchJSON, "pcfDiamRealm"); + + if (pcf_diam_realm) { + if (!cJSON_IsString(pcf_diam_realm)) { + ogs_error("OpenAPI_pcf_binding_patch_parseFromJSON() failed [pcf_diam_realm]"); + goto end; + } + } + + pcf_binding_patch_local_var = OpenAPI_pcf_binding_patch_create ( + ipv4_addr ? ogs_strdup(ipv4_addr->valuestring) : NULL, + ip_domain ? ogs_strdup(ip_domain->valuestring) : NULL, + ipv6_prefix ? ogs_strdup(ipv6_prefix->valuestring) : NULL, + add_ipv6_prefixes ? add_ipv6_prefixesList : NULL, + mac_addr48 ? ogs_strdup(mac_addr48->valuestring) : NULL, + add_mac_addrs ? add_mac_addrsList : NULL, + pcf_id ? ogs_strdup(pcf_id->valuestring) : NULL, + pcf_fqdn ? ogs_strdup(pcf_fqdn->valuestring) : NULL, + pcf_ip_end_points ? pcf_ip_end_pointsList : NULL, + pcf_diam_host ? ogs_strdup(pcf_diam_host->valuestring) : NULL, + pcf_diam_realm ? ogs_strdup(pcf_diam_realm->valuestring) : NULL + ); + + return pcf_binding_patch_local_var; +end: + return NULL; +} + +OpenAPI_pcf_binding_patch_t *OpenAPI_pcf_binding_patch_copy(OpenAPI_pcf_binding_patch_t *dst, OpenAPI_pcf_binding_patch_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_pcf_binding_patch_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_pcf_binding_patch_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_pcf_binding_patch_free(dst); + dst = OpenAPI_pcf_binding_patch_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/pcf_binding_patch.h b/lib/sbi/openapi/model/pcf_binding_patch.h new file mode 100644 index 000000000..9b62c7deb --- /dev/null +++ b/lib/sbi/openapi/model/pcf_binding_patch.h @@ -0,0 +1,59 @@ +/* + * pcf_binding_patch.h + * + * + */ + +#ifndef _OpenAPI_pcf_binding_patch_H_ +#define _OpenAPI_pcf_binding_patch_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" +#include "ip_end_point.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_pcf_binding_patch_s OpenAPI_pcf_binding_patch_t; +typedef struct OpenAPI_pcf_binding_patch_s { + char *ipv4_addr; + char *ip_domain; + char *ipv6_prefix; + OpenAPI_list_t *add_ipv6_prefixes; + char *mac_addr48; + OpenAPI_list_t *add_mac_addrs; + char *pcf_id; + char *pcf_fqdn; + OpenAPI_list_t *pcf_ip_end_points; + char *pcf_diam_host; + char *pcf_diam_realm; +} OpenAPI_pcf_binding_patch_t; + +OpenAPI_pcf_binding_patch_t *OpenAPI_pcf_binding_patch_create( + char *ipv4_addr, + char *ip_domain, + char *ipv6_prefix, + OpenAPI_list_t *add_ipv6_prefixes, + char *mac_addr48, + OpenAPI_list_t *add_mac_addrs, + char *pcf_id, + char *pcf_fqdn, + OpenAPI_list_t *pcf_ip_end_points, + char *pcf_diam_host, + char *pcf_diam_realm + ); +void OpenAPI_pcf_binding_patch_free(OpenAPI_pcf_binding_patch_t *pcf_binding_patch); +OpenAPI_pcf_binding_patch_t *OpenAPI_pcf_binding_patch_parseFromJSON(cJSON *pcf_binding_patchJSON); +cJSON *OpenAPI_pcf_binding_patch_convertToJSON(OpenAPI_pcf_binding_patch_t *pcf_binding_patch); +OpenAPI_pcf_binding_patch_t *OpenAPI_pcf_binding_patch_copy(OpenAPI_pcf_binding_patch_t *dst, OpenAPI_pcf_binding_patch_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_pcf_binding_patch_H_ */ + diff --git a/lib/sbi/openapi/model/pcscf_restoration_request_data.c b/lib/sbi/openapi/model/pcscf_restoration_request_data.c new file mode 100644 index 000000000..3d981ee4e --- /dev/null +++ b/lib/sbi/openapi/model/pcscf_restoration_request_data.c @@ -0,0 +1,209 @@ + +#include +#include +#include +#include "pcscf_restoration_request_data.h" + +OpenAPI_pcscf_restoration_request_data_t *OpenAPI_pcscf_restoration_request_data_create( + char *dnn, + char *ip_domain, + OpenAPI_snssai_t *slice_info, + char *supi, + char *ue_ipv4, + char *ue_ipv6 + ) +{ + OpenAPI_pcscf_restoration_request_data_t *pcscf_restoration_request_data_local_var = OpenAPI_malloc(sizeof(OpenAPI_pcscf_restoration_request_data_t)); + if (!pcscf_restoration_request_data_local_var) { + return NULL; + } + pcscf_restoration_request_data_local_var->dnn = dnn; + pcscf_restoration_request_data_local_var->ip_domain = ip_domain; + pcscf_restoration_request_data_local_var->slice_info = slice_info; + pcscf_restoration_request_data_local_var->supi = supi; + pcscf_restoration_request_data_local_var->ue_ipv4 = ue_ipv4; + pcscf_restoration_request_data_local_var->ue_ipv6 = ue_ipv6; + + return pcscf_restoration_request_data_local_var; +} + +void OpenAPI_pcscf_restoration_request_data_free(OpenAPI_pcscf_restoration_request_data_t *pcscf_restoration_request_data) +{ + if (NULL == pcscf_restoration_request_data) { + return; + } + OpenAPI_lnode_t *node; + ogs_free(pcscf_restoration_request_data->dnn); + ogs_free(pcscf_restoration_request_data->ip_domain); + OpenAPI_snssai_free(pcscf_restoration_request_data->slice_info); + ogs_free(pcscf_restoration_request_data->supi); + ogs_free(pcscf_restoration_request_data->ue_ipv4); + ogs_free(pcscf_restoration_request_data->ue_ipv6); + ogs_free(pcscf_restoration_request_data); +} + +cJSON *OpenAPI_pcscf_restoration_request_data_convertToJSON(OpenAPI_pcscf_restoration_request_data_t *pcscf_restoration_request_data) +{ + cJSON *item = NULL; + + if (pcscf_restoration_request_data == NULL) { + ogs_error("OpenAPI_pcscf_restoration_request_data_convertToJSON() failed [PcscfRestorationRequestData]"); + return NULL; + } + + item = cJSON_CreateObject(); + if (pcscf_restoration_request_data->dnn) { + if (cJSON_AddStringToObject(item, "dnn", pcscf_restoration_request_data->dnn) == NULL) { + ogs_error("OpenAPI_pcscf_restoration_request_data_convertToJSON() failed [dnn]"); + goto end; + } + } + + if (pcscf_restoration_request_data->ip_domain) { + if (cJSON_AddStringToObject(item, "ipDomain", pcscf_restoration_request_data->ip_domain) == NULL) { + ogs_error("OpenAPI_pcscf_restoration_request_data_convertToJSON() failed [ip_domain]"); + goto end; + } + } + + if (pcscf_restoration_request_data->slice_info) { + cJSON *slice_info_local_JSON = OpenAPI_snssai_convertToJSON(pcscf_restoration_request_data->slice_info); + if (slice_info_local_JSON == NULL) { + ogs_error("OpenAPI_pcscf_restoration_request_data_convertToJSON() failed [slice_info]"); + goto end; + } + cJSON_AddItemToObject(item, "sliceInfo", slice_info_local_JSON); + if (item->child == NULL) { + ogs_error("OpenAPI_pcscf_restoration_request_data_convertToJSON() failed [slice_info]"); + goto end; + } + } + + if (pcscf_restoration_request_data->supi) { + if (cJSON_AddStringToObject(item, "supi", pcscf_restoration_request_data->supi) == NULL) { + ogs_error("OpenAPI_pcscf_restoration_request_data_convertToJSON() failed [supi]"); + goto end; + } + } + + if (pcscf_restoration_request_data->ue_ipv4) { + if (cJSON_AddStringToObject(item, "ueIpv4", pcscf_restoration_request_data->ue_ipv4) == NULL) { + ogs_error("OpenAPI_pcscf_restoration_request_data_convertToJSON() failed [ue_ipv4]"); + goto end; + } + } + + if (pcscf_restoration_request_data->ue_ipv6) { + if (cJSON_AddStringToObject(item, "ueIpv6", pcscf_restoration_request_data->ue_ipv6) == NULL) { + ogs_error("OpenAPI_pcscf_restoration_request_data_convertToJSON() failed [ue_ipv6]"); + goto end; + } + } + +end: + return item; +} + +OpenAPI_pcscf_restoration_request_data_t *OpenAPI_pcscf_restoration_request_data_parseFromJSON(cJSON *pcscf_restoration_request_dataJSON) +{ + OpenAPI_pcscf_restoration_request_data_t *pcscf_restoration_request_data_local_var = NULL; + cJSON *dnn = cJSON_GetObjectItemCaseSensitive(pcscf_restoration_request_dataJSON, "dnn"); + + if (dnn) { + if (!cJSON_IsString(dnn)) { + ogs_error("OpenAPI_pcscf_restoration_request_data_parseFromJSON() failed [dnn]"); + goto end; + } + } + + cJSON *ip_domain = cJSON_GetObjectItemCaseSensitive(pcscf_restoration_request_dataJSON, "ipDomain"); + + if (ip_domain) { + if (!cJSON_IsString(ip_domain)) { + ogs_error("OpenAPI_pcscf_restoration_request_data_parseFromJSON() failed [ip_domain]"); + goto end; + } + } + + cJSON *slice_info = cJSON_GetObjectItemCaseSensitive(pcscf_restoration_request_dataJSON, "sliceInfo"); + + OpenAPI_snssai_t *slice_info_local_nonprim = NULL; + if (slice_info) { + slice_info_local_nonprim = OpenAPI_snssai_parseFromJSON(slice_info); + } + + cJSON *supi = cJSON_GetObjectItemCaseSensitive(pcscf_restoration_request_dataJSON, "supi"); + + if (supi) { + if (!cJSON_IsString(supi)) { + ogs_error("OpenAPI_pcscf_restoration_request_data_parseFromJSON() failed [supi]"); + goto end; + } + } + + cJSON *ue_ipv4 = cJSON_GetObjectItemCaseSensitive(pcscf_restoration_request_dataJSON, "ueIpv4"); + + if (ue_ipv4) { + if (!cJSON_IsString(ue_ipv4)) { + ogs_error("OpenAPI_pcscf_restoration_request_data_parseFromJSON() failed [ue_ipv4]"); + goto end; + } + } + + cJSON *ue_ipv6 = cJSON_GetObjectItemCaseSensitive(pcscf_restoration_request_dataJSON, "ueIpv6"); + + if (ue_ipv6) { + if (!cJSON_IsString(ue_ipv6)) { + ogs_error("OpenAPI_pcscf_restoration_request_data_parseFromJSON() failed [ue_ipv6]"); + goto end; + } + } + + pcscf_restoration_request_data_local_var = OpenAPI_pcscf_restoration_request_data_create ( + dnn ? ogs_strdup(dnn->valuestring) : NULL, + ip_domain ? ogs_strdup(ip_domain->valuestring) : NULL, + slice_info ? slice_info_local_nonprim : NULL, + supi ? ogs_strdup(supi->valuestring) : NULL, + ue_ipv4 ? ogs_strdup(ue_ipv4->valuestring) : NULL, + ue_ipv6 ? ogs_strdup(ue_ipv6->valuestring) : NULL + ); + + return pcscf_restoration_request_data_local_var; +end: + return NULL; +} + +OpenAPI_pcscf_restoration_request_data_t *OpenAPI_pcscf_restoration_request_data_copy(OpenAPI_pcscf_restoration_request_data_t *dst, OpenAPI_pcscf_restoration_request_data_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_pcscf_restoration_request_data_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_pcscf_restoration_request_data_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_pcscf_restoration_request_data_free(dst); + dst = OpenAPI_pcscf_restoration_request_data_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/pcscf_restoration_request_data.h b/lib/sbi/openapi/model/pcscf_restoration_request_data.h new file mode 100644 index 000000000..e3abacca6 --- /dev/null +++ b/lib/sbi/openapi/model/pcscf_restoration_request_data.h @@ -0,0 +1,49 @@ +/* + * pcscf_restoration_request_data.h + * + * Indicates P-CSCF restoration. + */ + +#ifndef _OpenAPI_pcscf_restoration_request_data_H_ +#define _OpenAPI_pcscf_restoration_request_data_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" +#include "snssai.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_pcscf_restoration_request_data_s OpenAPI_pcscf_restoration_request_data_t; +typedef struct OpenAPI_pcscf_restoration_request_data_s { + char *dnn; + char *ip_domain; + struct OpenAPI_snssai_s *slice_info; + char *supi; + char *ue_ipv4; + char *ue_ipv6; +} OpenAPI_pcscf_restoration_request_data_t; + +OpenAPI_pcscf_restoration_request_data_t *OpenAPI_pcscf_restoration_request_data_create( + char *dnn, + char *ip_domain, + OpenAPI_snssai_t *slice_info, + char *supi, + char *ue_ipv4, + char *ue_ipv6 + ); +void OpenAPI_pcscf_restoration_request_data_free(OpenAPI_pcscf_restoration_request_data_t *pcscf_restoration_request_data); +OpenAPI_pcscf_restoration_request_data_t *OpenAPI_pcscf_restoration_request_data_parseFromJSON(cJSON *pcscf_restoration_request_dataJSON); +cJSON *OpenAPI_pcscf_restoration_request_data_convertToJSON(OpenAPI_pcscf_restoration_request_data_t *pcscf_restoration_request_data); +OpenAPI_pcscf_restoration_request_data_t *OpenAPI_pcscf_restoration_request_data_copy(OpenAPI_pcscf_restoration_request_data_t *dst, OpenAPI_pcscf_restoration_request_data_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_pcscf_restoration_request_data_H_ */ + diff --git a/lib/sbi/openapi/model/preemption_capability_rm.c b/lib/sbi/openapi/model/preemption_capability_rm.c new file mode 100644 index 000000000..eb120e226 --- /dev/null +++ b/lib/sbi/openapi/model/preemption_capability_rm.c @@ -0,0 +1,85 @@ + +#include +#include +#include +#include "preemption_capability_rm.h" + +OpenAPI_preemption_capability_rm_t *OpenAPI_preemption_capability_rm_create( + ) +{ + OpenAPI_preemption_capability_rm_t *preemption_capability_rm_local_var = OpenAPI_malloc(sizeof(OpenAPI_preemption_capability_rm_t)); + if (!preemption_capability_rm_local_var) { + return NULL; + } + + return preemption_capability_rm_local_var; +} + +void OpenAPI_preemption_capability_rm_free(OpenAPI_preemption_capability_rm_t *preemption_capability_rm) +{ + if (NULL == preemption_capability_rm) { + return; + } + OpenAPI_lnode_t *node; + ogs_free(preemption_capability_rm); +} + +cJSON *OpenAPI_preemption_capability_rm_convertToJSON(OpenAPI_preemption_capability_rm_t *preemption_capability_rm) +{ + cJSON *item = NULL; + + if (preemption_capability_rm == NULL) { + ogs_error("OpenAPI_preemption_capability_rm_convertToJSON() failed [PreemptionCapabilityRm]"); + return NULL; + } + + item = cJSON_CreateObject(); +end: + return item; +} + +OpenAPI_preemption_capability_rm_t *OpenAPI_preemption_capability_rm_parseFromJSON(cJSON *preemption_capability_rmJSON) +{ + OpenAPI_preemption_capability_rm_t *preemption_capability_rm_local_var = NULL; + preemption_capability_rm_local_var = OpenAPI_preemption_capability_rm_create ( + ); + + return preemption_capability_rm_local_var; +end: + return NULL; +} + +OpenAPI_preemption_capability_rm_t *OpenAPI_preemption_capability_rm_copy(OpenAPI_preemption_capability_rm_t *dst, OpenAPI_preemption_capability_rm_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_preemption_capability_rm_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_preemption_capability_rm_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_preemption_capability_rm_free(dst); + dst = OpenAPI_preemption_capability_rm_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/preemption_capability_rm.h b/lib/sbi/openapi/model/preemption_capability_rm.h new file mode 100644 index 000000000..d4a230d96 --- /dev/null +++ b/lib/sbi/openapi/model/preemption_capability_rm.h @@ -0,0 +1,38 @@ +/* + * preemption_capability_rm.h + * + * + */ + +#ifndef _OpenAPI_preemption_capability_rm_H_ +#define _OpenAPI_preemption_capability_rm_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" +#include "null_value.h" +#include "preemption_capability.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_preemption_capability_rm_s OpenAPI_preemption_capability_rm_t; +typedef struct OpenAPI_preemption_capability_rm_s { +} OpenAPI_preemption_capability_rm_t; + +OpenAPI_preemption_capability_rm_t *OpenAPI_preemption_capability_rm_create( + ); +void OpenAPI_preemption_capability_rm_free(OpenAPI_preemption_capability_rm_t *preemption_capability_rm); +OpenAPI_preemption_capability_rm_t *OpenAPI_preemption_capability_rm_parseFromJSON(cJSON *preemption_capability_rmJSON); +cJSON *OpenAPI_preemption_capability_rm_convertToJSON(OpenAPI_preemption_capability_rm_t *preemption_capability_rm); +OpenAPI_preemption_capability_rm_t *OpenAPI_preemption_capability_rm_copy(OpenAPI_preemption_capability_rm_t *dst, OpenAPI_preemption_capability_rm_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_preemption_capability_rm_H_ */ + diff --git a/lib/sbi/openapi/model/preemption_control_information.c b/lib/sbi/openapi/model/preemption_control_information.c new file mode 100644 index 000000000..465b5e338 --- /dev/null +++ b/lib/sbi/openapi/model/preemption_control_information.c @@ -0,0 +1,30 @@ + +#include +#include +#include +#include "preemption_control_information.h" + +char* OpenAPI_preemption_control_information_ToString(OpenAPI_preemption_control_information_e preemption_control_information) +{ + const char *preemption_control_informationArray[] = { "NULL", "MOST_RECENT", "LEAST_RECENT", "HIGHEST_BW" }; + size_t sizeofArray = sizeof(preemption_control_informationArray) / sizeof(preemption_control_informationArray[0]); + if (preemption_control_information < sizeofArray) + return (char *)preemption_control_informationArray[preemption_control_information]; + else + return (char *)"Unknown"; +} + +OpenAPI_preemption_control_information_e OpenAPI_preemption_control_information_FromString(char* preemption_control_information) +{ + int stringToReturn = 0; + const char *preemption_control_informationArray[] = { "NULL", "MOST_RECENT", "LEAST_RECENT", "HIGHEST_BW" }; + size_t sizeofArray = sizeof(preemption_control_informationArray) / sizeof(preemption_control_informationArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(preemption_control_information, preemption_control_informationArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; + } + return 0; +} + diff --git a/lib/sbi/openapi/model/preemption_control_information.h b/lib/sbi/openapi/model/preemption_control_information.h new file mode 100644 index 000000000..f7c5971ef --- /dev/null +++ b/lib/sbi/openapi/model/preemption_control_information.h @@ -0,0 +1,31 @@ +/* + * preemption_control_information.h + * + * + */ + +#ifndef _OpenAPI_preemption_control_information_H_ +#define _OpenAPI_preemption_control_information_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { OpenAPI_preemption_control_information_NULL = 0, OpenAPI_preemption_control_information_MOST_RECENT, OpenAPI_preemption_control_information_LEAST_RECENT, OpenAPI_preemption_control_information_HIGHEST_BW } OpenAPI_preemption_control_information_e; + +char* OpenAPI_preemption_control_information_ToString(OpenAPI_preemption_control_information_e preemption_control_information); + +OpenAPI_preemption_control_information_e OpenAPI_preemption_control_information_FromString(char* preemption_control_information); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_preemption_control_information_H_ */ + diff --git a/lib/sbi/openapi/model/preemption_control_information_rm.c b/lib/sbi/openapi/model/preemption_control_information_rm.c new file mode 100644 index 000000000..b2e170944 --- /dev/null +++ b/lib/sbi/openapi/model/preemption_control_information_rm.c @@ -0,0 +1,85 @@ + +#include +#include +#include +#include "preemption_control_information_rm.h" + +OpenAPI_preemption_control_information_rm_t *OpenAPI_preemption_control_information_rm_create( + ) +{ + OpenAPI_preemption_control_information_rm_t *preemption_control_information_rm_local_var = OpenAPI_malloc(sizeof(OpenAPI_preemption_control_information_rm_t)); + if (!preemption_control_information_rm_local_var) { + return NULL; + } + + return preemption_control_information_rm_local_var; +} + +void OpenAPI_preemption_control_information_rm_free(OpenAPI_preemption_control_information_rm_t *preemption_control_information_rm) +{ + if (NULL == preemption_control_information_rm) { + return; + } + OpenAPI_lnode_t *node; + ogs_free(preemption_control_information_rm); +} + +cJSON *OpenAPI_preemption_control_information_rm_convertToJSON(OpenAPI_preemption_control_information_rm_t *preemption_control_information_rm) +{ + cJSON *item = NULL; + + if (preemption_control_information_rm == NULL) { + ogs_error("OpenAPI_preemption_control_information_rm_convertToJSON() failed [PreemptionControlInformationRm]"); + return NULL; + } + + item = cJSON_CreateObject(); +end: + return item; +} + +OpenAPI_preemption_control_information_rm_t *OpenAPI_preemption_control_information_rm_parseFromJSON(cJSON *preemption_control_information_rmJSON) +{ + OpenAPI_preemption_control_information_rm_t *preemption_control_information_rm_local_var = NULL; + preemption_control_information_rm_local_var = OpenAPI_preemption_control_information_rm_create ( + ); + + return preemption_control_information_rm_local_var; +end: + return NULL; +} + +OpenAPI_preemption_control_information_rm_t *OpenAPI_preemption_control_information_rm_copy(OpenAPI_preemption_control_information_rm_t *dst, OpenAPI_preemption_control_information_rm_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_preemption_control_information_rm_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_preemption_control_information_rm_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_preemption_control_information_rm_free(dst); + dst = OpenAPI_preemption_control_information_rm_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/preemption_control_information_rm.h b/lib/sbi/openapi/model/preemption_control_information_rm.h new file mode 100644 index 000000000..bbab91024 --- /dev/null +++ b/lib/sbi/openapi/model/preemption_control_information_rm.h @@ -0,0 +1,38 @@ +/* + * preemption_control_information_rm.h + * + * + */ + +#ifndef _OpenAPI_preemption_control_information_rm_H_ +#define _OpenAPI_preemption_control_information_rm_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" +#include "null_value.h" +#include "preemption_control_information.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_preemption_control_information_rm_s OpenAPI_preemption_control_information_rm_t; +typedef struct OpenAPI_preemption_control_information_rm_s { +} OpenAPI_preemption_control_information_rm_t; + +OpenAPI_preemption_control_information_rm_t *OpenAPI_preemption_control_information_rm_create( + ); +void OpenAPI_preemption_control_information_rm_free(OpenAPI_preemption_control_information_rm_t *preemption_control_information_rm); +OpenAPI_preemption_control_information_rm_t *OpenAPI_preemption_control_information_rm_parseFromJSON(cJSON *preemption_control_information_rmJSON); +cJSON *OpenAPI_preemption_control_information_rm_convertToJSON(OpenAPI_preemption_control_information_rm_t *preemption_control_information_rm); +OpenAPI_preemption_control_information_rm_t *OpenAPI_preemption_control_information_rm_copy(OpenAPI_preemption_control_information_rm_t *dst, OpenAPI_preemption_control_information_rm_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_preemption_control_information_rm_H_ */ + diff --git a/lib/sbi/openapi/model/preemption_vulnerability_rm.c b/lib/sbi/openapi/model/preemption_vulnerability_rm.c new file mode 100644 index 000000000..4c990d92b --- /dev/null +++ b/lib/sbi/openapi/model/preemption_vulnerability_rm.c @@ -0,0 +1,85 @@ + +#include +#include +#include +#include "preemption_vulnerability_rm.h" + +OpenAPI_preemption_vulnerability_rm_t *OpenAPI_preemption_vulnerability_rm_create( + ) +{ + OpenAPI_preemption_vulnerability_rm_t *preemption_vulnerability_rm_local_var = OpenAPI_malloc(sizeof(OpenAPI_preemption_vulnerability_rm_t)); + if (!preemption_vulnerability_rm_local_var) { + return NULL; + } + + return preemption_vulnerability_rm_local_var; +} + +void OpenAPI_preemption_vulnerability_rm_free(OpenAPI_preemption_vulnerability_rm_t *preemption_vulnerability_rm) +{ + if (NULL == preemption_vulnerability_rm) { + return; + } + OpenAPI_lnode_t *node; + ogs_free(preemption_vulnerability_rm); +} + +cJSON *OpenAPI_preemption_vulnerability_rm_convertToJSON(OpenAPI_preemption_vulnerability_rm_t *preemption_vulnerability_rm) +{ + cJSON *item = NULL; + + if (preemption_vulnerability_rm == NULL) { + ogs_error("OpenAPI_preemption_vulnerability_rm_convertToJSON() failed [PreemptionVulnerabilityRm]"); + return NULL; + } + + item = cJSON_CreateObject(); +end: + return item; +} + +OpenAPI_preemption_vulnerability_rm_t *OpenAPI_preemption_vulnerability_rm_parseFromJSON(cJSON *preemption_vulnerability_rmJSON) +{ + OpenAPI_preemption_vulnerability_rm_t *preemption_vulnerability_rm_local_var = NULL; + preemption_vulnerability_rm_local_var = OpenAPI_preemption_vulnerability_rm_create ( + ); + + return preemption_vulnerability_rm_local_var; +end: + return NULL; +} + +OpenAPI_preemption_vulnerability_rm_t *OpenAPI_preemption_vulnerability_rm_copy(OpenAPI_preemption_vulnerability_rm_t *dst, OpenAPI_preemption_vulnerability_rm_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_preemption_vulnerability_rm_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_preemption_vulnerability_rm_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_preemption_vulnerability_rm_free(dst); + dst = OpenAPI_preemption_vulnerability_rm_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/preemption_vulnerability_rm.h b/lib/sbi/openapi/model/preemption_vulnerability_rm.h new file mode 100644 index 000000000..c3fb3684d --- /dev/null +++ b/lib/sbi/openapi/model/preemption_vulnerability_rm.h @@ -0,0 +1,38 @@ +/* + * preemption_vulnerability_rm.h + * + * + */ + +#ifndef _OpenAPI_preemption_vulnerability_rm_H_ +#define _OpenAPI_preemption_vulnerability_rm_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" +#include "null_value.h" +#include "preemption_vulnerability.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_preemption_vulnerability_rm_s OpenAPI_preemption_vulnerability_rm_t; +typedef struct OpenAPI_preemption_vulnerability_rm_s { +} OpenAPI_preemption_vulnerability_rm_t; + +OpenAPI_preemption_vulnerability_rm_t *OpenAPI_preemption_vulnerability_rm_create( + ); +void OpenAPI_preemption_vulnerability_rm_free(OpenAPI_preemption_vulnerability_rm_t *preemption_vulnerability_rm); +OpenAPI_preemption_vulnerability_rm_t *OpenAPI_preemption_vulnerability_rm_parseFromJSON(cJSON *preemption_vulnerability_rmJSON); +cJSON *OpenAPI_preemption_vulnerability_rm_convertToJSON(OpenAPI_preemption_vulnerability_rm_t *preemption_vulnerability_rm); +OpenAPI_preemption_vulnerability_rm_t *OpenAPI_preemption_vulnerability_rm_copy(OpenAPI_preemption_vulnerability_rm_t *dst, OpenAPI_preemption_vulnerability_rm_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_preemption_vulnerability_rm_H_ */ + diff --git a/lib/sbi/openapi/model/priority_sharing_indicator.c b/lib/sbi/openapi/model/priority_sharing_indicator.c new file mode 100644 index 000000000..0d83f1b09 --- /dev/null +++ b/lib/sbi/openapi/model/priority_sharing_indicator.c @@ -0,0 +1,30 @@ + +#include +#include +#include +#include "priority_sharing_indicator.h" + +char* OpenAPI_priority_sharing_indicator_ToString(OpenAPI_priority_sharing_indicator_e priority_sharing_indicator) +{ + const char *priority_sharing_indicatorArray[] = { "NULL", "ENABLED", "DISABLED" }; + size_t sizeofArray = sizeof(priority_sharing_indicatorArray) / sizeof(priority_sharing_indicatorArray[0]); + if (priority_sharing_indicator < sizeofArray) + return (char *)priority_sharing_indicatorArray[priority_sharing_indicator]; + else + return (char *)"Unknown"; +} + +OpenAPI_priority_sharing_indicator_e OpenAPI_priority_sharing_indicator_FromString(char* priority_sharing_indicator) +{ + int stringToReturn = 0; + const char *priority_sharing_indicatorArray[] = { "NULL", "ENABLED", "DISABLED" }; + size_t sizeofArray = sizeof(priority_sharing_indicatorArray) / sizeof(priority_sharing_indicatorArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(priority_sharing_indicator, priority_sharing_indicatorArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; + } + return 0; +} + diff --git a/lib/sbi/openapi/model/priority_sharing_indicator.h b/lib/sbi/openapi/model/priority_sharing_indicator.h new file mode 100644 index 000000000..06ac0cf19 --- /dev/null +++ b/lib/sbi/openapi/model/priority_sharing_indicator.h @@ -0,0 +1,31 @@ +/* + * priority_sharing_indicator.h + * + * + */ + +#ifndef _OpenAPI_priority_sharing_indicator_H_ +#define _OpenAPI_priority_sharing_indicator_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { OpenAPI_priority_sharing_indicator_NULL = 0, OpenAPI_priority_sharing_indicator_ENABLED, OpenAPI_priority_sharing_indicator_DISABLED } OpenAPI_priority_sharing_indicator_e; + +char* OpenAPI_priority_sharing_indicator_ToString(OpenAPI_priority_sharing_indicator_e priority_sharing_indicator); + +OpenAPI_priority_sharing_indicator_e OpenAPI_priority_sharing_indicator_FromString(char* priority_sharing_indicator); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_priority_sharing_indicator_H_ */ + diff --git a/lib/sbi/openapi/model/qos_monitoring_information.c b/lib/sbi/openapi/model/qos_monitoring_information.c new file mode 100644 index 000000000..f1f16e9bf --- /dev/null +++ b/lib/sbi/openapi/model/qos_monitoring_information.c @@ -0,0 +1,142 @@ + +#include +#include +#include +#include "qos_monitoring_information.h" + +OpenAPI_qos_monitoring_information_t *OpenAPI_qos_monitoring_information_create( + int rep_thresh_dl, + int rep_thresh_ul, + int rep_thresh_rp + ) +{ + OpenAPI_qos_monitoring_information_t *qos_monitoring_information_local_var = OpenAPI_malloc(sizeof(OpenAPI_qos_monitoring_information_t)); + if (!qos_monitoring_information_local_var) { + return NULL; + } + qos_monitoring_information_local_var->rep_thresh_dl = rep_thresh_dl; + qos_monitoring_information_local_var->rep_thresh_ul = rep_thresh_ul; + qos_monitoring_information_local_var->rep_thresh_rp = rep_thresh_rp; + + return qos_monitoring_information_local_var; +} + +void OpenAPI_qos_monitoring_information_free(OpenAPI_qos_monitoring_information_t *qos_monitoring_information) +{ + if (NULL == qos_monitoring_information) { + return; + } + OpenAPI_lnode_t *node; + ogs_free(qos_monitoring_information); +} + +cJSON *OpenAPI_qos_monitoring_information_convertToJSON(OpenAPI_qos_monitoring_information_t *qos_monitoring_information) +{ + cJSON *item = NULL; + + if (qos_monitoring_information == NULL) { + ogs_error("OpenAPI_qos_monitoring_information_convertToJSON() failed [QosMonitoringInformation]"); + return NULL; + } + + item = cJSON_CreateObject(); + if (qos_monitoring_information->rep_thresh_dl) { + if (cJSON_AddNumberToObject(item, "repThreshDl", qos_monitoring_information->rep_thresh_dl) == NULL) { + ogs_error("OpenAPI_qos_monitoring_information_convertToJSON() failed [rep_thresh_dl]"); + goto end; + } + } + + if (qos_monitoring_information->rep_thresh_ul) { + if (cJSON_AddNumberToObject(item, "repThreshUl", qos_monitoring_information->rep_thresh_ul) == NULL) { + ogs_error("OpenAPI_qos_monitoring_information_convertToJSON() failed [rep_thresh_ul]"); + goto end; + } + } + + if (qos_monitoring_information->rep_thresh_rp) { + if (cJSON_AddNumberToObject(item, "repThreshRp", qos_monitoring_information->rep_thresh_rp) == NULL) { + ogs_error("OpenAPI_qos_monitoring_information_convertToJSON() failed [rep_thresh_rp]"); + goto end; + } + } + +end: + return item; +} + +OpenAPI_qos_monitoring_information_t *OpenAPI_qos_monitoring_information_parseFromJSON(cJSON *qos_monitoring_informationJSON) +{ + OpenAPI_qos_monitoring_information_t *qos_monitoring_information_local_var = NULL; + cJSON *rep_thresh_dl = cJSON_GetObjectItemCaseSensitive(qos_monitoring_informationJSON, "repThreshDl"); + + if (rep_thresh_dl) { + if (!cJSON_IsNumber(rep_thresh_dl)) { + ogs_error("OpenAPI_qos_monitoring_information_parseFromJSON() failed [rep_thresh_dl]"); + goto end; + } + } + + cJSON *rep_thresh_ul = cJSON_GetObjectItemCaseSensitive(qos_monitoring_informationJSON, "repThreshUl"); + + if (rep_thresh_ul) { + if (!cJSON_IsNumber(rep_thresh_ul)) { + ogs_error("OpenAPI_qos_monitoring_information_parseFromJSON() failed [rep_thresh_ul]"); + goto end; + } + } + + cJSON *rep_thresh_rp = cJSON_GetObjectItemCaseSensitive(qos_monitoring_informationJSON, "repThreshRp"); + + if (rep_thresh_rp) { + if (!cJSON_IsNumber(rep_thresh_rp)) { + ogs_error("OpenAPI_qos_monitoring_information_parseFromJSON() failed [rep_thresh_rp]"); + goto end; + } + } + + qos_monitoring_information_local_var = OpenAPI_qos_monitoring_information_create ( + rep_thresh_dl ? rep_thresh_dl->valuedouble : 0, + rep_thresh_ul ? rep_thresh_ul->valuedouble : 0, + rep_thresh_rp ? rep_thresh_rp->valuedouble : 0 + ); + + return qos_monitoring_information_local_var; +end: + return NULL; +} + +OpenAPI_qos_monitoring_information_t *OpenAPI_qos_monitoring_information_copy(OpenAPI_qos_monitoring_information_t *dst, OpenAPI_qos_monitoring_information_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_qos_monitoring_information_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_qos_monitoring_information_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_qos_monitoring_information_free(dst); + dst = OpenAPI_qos_monitoring_information_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/qos_monitoring_information.h b/lib/sbi/openapi/model/qos_monitoring_information.h new file mode 100644 index 000000000..db1e9f781 --- /dev/null +++ b/lib/sbi/openapi/model/qos_monitoring_information.h @@ -0,0 +1,42 @@ +/* + * qos_monitoring_information.h + * + * Indicates the QoS Monitoring information to report, i.e. UL and/or DL and or round trip delay. + */ + +#ifndef _OpenAPI_qos_monitoring_information_H_ +#define _OpenAPI_qos_monitoring_information_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_qos_monitoring_information_s OpenAPI_qos_monitoring_information_t; +typedef struct OpenAPI_qos_monitoring_information_s { + int rep_thresh_dl; + int rep_thresh_ul; + int rep_thresh_rp; +} OpenAPI_qos_monitoring_information_t; + +OpenAPI_qos_monitoring_information_t *OpenAPI_qos_monitoring_information_create( + int rep_thresh_dl, + int rep_thresh_ul, + int rep_thresh_rp + ); +void OpenAPI_qos_monitoring_information_free(OpenAPI_qos_monitoring_information_t *qos_monitoring_information); +OpenAPI_qos_monitoring_information_t *OpenAPI_qos_monitoring_information_parseFromJSON(cJSON *qos_monitoring_informationJSON); +cJSON *OpenAPI_qos_monitoring_information_convertToJSON(OpenAPI_qos_monitoring_information_t *qos_monitoring_information); +OpenAPI_qos_monitoring_information_t *OpenAPI_qos_monitoring_information_copy(OpenAPI_qos_monitoring_information_t *dst, OpenAPI_qos_monitoring_information_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_qos_monitoring_information_H_ */ + diff --git a/lib/sbi/openapi/model/qos_monitoring_information_rm.c b/lib/sbi/openapi/model/qos_monitoring_information_rm.c new file mode 100644 index 000000000..488e726c0 --- /dev/null +++ b/lib/sbi/openapi/model/qos_monitoring_information_rm.c @@ -0,0 +1,142 @@ + +#include +#include +#include +#include "qos_monitoring_information_rm.h" + +OpenAPI_qos_monitoring_information_rm_t *OpenAPI_qos_monitoring_information_rm_create( + int rep_thresh_dl, + int rep_thresh_ul, + int rep_thresh_rp + ) +{ + OpenAPI_qos_monitoring_information_rm_t *qos_monitoring_information_rm_local_var = OpenAPI_malloc(sizeof(OpenAPI_qos_monitoring_information_rm_t)); + if (!qos_monitoring_information_rm_local_var) { + return NULL; + } + qos_monitoring_information_rm_local_var->rep_thresh_dl = rep_thresh_dl; + qos_monitoring_information_rm_local_var->rep_thresh_ul = rep_thresh_ul; + qos_monitoring_information_rm_local_var->rep_thresh_rp = rep_thresh_rp; + + return qos_monitoring_information_rm_local_var; +} + +void OpenAPI_qos_monitoring_information_rm_free(OpenAPI_qos_monitoring_information_rm_t *qos_monitoring_information_rm) +{ + if (NULL == qos_monitoring_information_rm) { + return; + } + OpenAPI_lnode_t *node; + ogs_free(qos_monitoring_information_rm); +} + +cJSON *OpenAPI_qos_monitoring_information_rm_convertToJSON(OpenAPI_qos_monitoring_information_rm_t *qos_monitoring_information_rm) +{ + cJSON *item = NULL; + + if (qos_monitoring_information_rm == NULL) { + ogs_error("OpenAPI_qos_monitoring_information_rm_convertToJSON() failed [QosMonitoringInformationRm]"); + return NULL; + } + + item = cJSON_CreateObject(); + if (qos_monitoring_information_rm->rep_thresh_dl) { + if (cJSON_AddNumberToObject(item, "repThreshDl", qos_monitoring_information_rm->rep_thresh_dl) == NULL) { + ogs_error("OpenAPI_qos_monitoring_information_rm_convertToJSON() failed [rep_thresh_dl]"); + goto end; + } + } + + if (qos_monitoring_information_rm->rep_thresh_ul) { + if (cJSON_AddNumberToObject(item, "repThreshUl", qos_monitoring_information_rm->rep_thresh_ul) == NULL) { + ogs_error("OpenAPI_qos_monitoring_information_rm_convertToJSON() failed [rep_thresh_ul]"); + goto end; + } + } + + if (qos_monitoring_information_rm->rep_thresh_rp) { + if (cJSON_AddNumberToObject(item, "repThreshRp", qos_monitoring_information_rm->rep_thresh_rp) == NULL) { + ogs_error("OpenAPI_qos_monitoring_information_rm_convertToJSON() failed [rep_thresh_rp]"); + goto end; + } + } + +end: + return item; +} + +OpenAPI_qos_monitoring_information_rm_t *OpenAPI_qos_monitoring_information_rm_parseFromJSON(cJSON *qos_monitoring_information_rmJSON) +{ + OpenAPI_qos_monitoring_information_rm_t *qos_monitoring_information_rm_local_var = NULL; + cJSON *rep_thresh_dl = cJSON_GetObjectItemCaseSensitive(qos_monitoring_information_rmJSON, "repThreshDl"); + + if (rep_thresh_dl) { + if (!cJSON_IsNumber(rep_thresh_dl)) { + ogs_error("OpenAPI_qos_monitoring_information_rm_parseFromJSON() failed [rep_thresh_dl]"); + goto end; + } + } + + cJSON *rep_thresh_ul = cJSON_GetObjectItemCaseSensitive(qos_monitoring_information_rmJSON, "repThreshUl"); + + if (rep_thresh_ul) { + if (!cJSON_IsNumber(rep_thresh_ul)) { + ogs_error("OpenAPI_qos_monitoring_information_rm_parseFromJSON() failed [rep_thresh_ul]"); + goto end; + } + } + + cJSON *rep_thresh_rp = cJSON_GetObjectItemCaseSensitive(qos_monitoring_information_rmJSON, "repThreshRp"); + + if (rep_thresh_rp) { + if (!cJSON_IsNumber(rep_thresh_rp)) { + ogs_error("OpenAPI_qos_monitoring_information_rm_parseFromJSON() failed [rep_thresh_rp]"); + goto end; + } + } + + qos_monitoring_information_rm_local_var = OpenAPI_qos_monitoring_information_rm_create ( + rep_thresh_dl ? rep_thresh_dl->valuedouble : 0, + rep_thresh_ul ? rep_thresh_ul->valuedouble : 0, + rep_thresh_rp ? rep_thresh_rp->valuedouble : 0 + ); + + return qos_monitoring_information_rm_local_var; +end: + return NULL; +} + +OpenAPI_qos_monitoring_information_rm_t *OpenAPI_qos_monitoring_information_rm_copy(OpenAPI_qos_monitoring_information_rm_t *dst, OpenAPI_qos_monitoring_information_rm_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_qos_monitoring_information_rm_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_qos_monitoring_information_rm_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_qos_monitoring_information_rm_free(dst); + dst = OpenAPI_qos_monitoring_information_rm_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/qos_monitoring_information_rm.h b/lib/sbi/openapi/model/qos_monitoring_information_rm.h new file mode 100644 index 000000000..226f37a01 --- /dev/null +++ b/lib/sbi/openapi/model/qos_monitoring_information_rm.h @@ -0,0 +1,42 @@ +/* + * qos_monitoring_information_rm.h + * + * this data type is defined in the same way as the QosMonitoringInformation data type, but with the OpenAPI nullable property set to true. + */ + +#ifndef _OpenAPI_qos_monitoring_information_rm_H_ +#define _OpenAPI_qos_monitoring_information_rm_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_qos_monitoring_information_rm_s OpenAPI_qos_monitoring_information_rm_t; +typedef struct OpenAPI_qos_monitoring_information_rm_s { + int rep_thresh_dl; + int rep_thresh_ul; + int rep_thresh_rp; +} OpenAPI_qos_monitoring_information_rm_t; + +OpenAPI_qos_monitoring_information_rm_t *OpenAPI_qos_monitoring_information_rm_create( + int rep_thresh_dl, + int rep_thresh_ul, + int rep_thresh_rp + ); +void OpenAPI_qos_monitoring_information_rm_free(OpenAPI_qos_monitoring_information_rm_t *qos_monitoring_information_rm); +OpenAPI_qos_monitoring_information_rm_t *OpenAPI_qos_monitoring_information_rm_parseFromJSON(cJSON *qos_monitoring_information_rmJSON); +cJSON *OpenAPI_qos_monitoring_information_rm_convertToJSON(OpenAPI_qos_monitoring_information_rm_t *qos_monitoring_information_rm); +OpenAPI_qos_monitoring_information_rm_t *OpenAPI_qos_monitoring_information_rm_copy(OpenAPI_qos_monitoring_information_rm_t *dst, OpenAPI_qos_monitoring_information_rm_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_qos_monitoring_information_rm_H_ */ + diff --git a/lib/sbi/openapi/model/qos_monitoring_report.c b/lib/sbi/openapi/model/qos_monitoring_report.c index 0e0784287..5db369628 100644 --- a/lib/sbi/openapi/model/qos_monitoring_report.c +++ b/lib/sbi/openapi/model/qos_monitoring_report.c @@ -5,7 +5,7 @@ #include "qos_monitoring_report.h" OpenAPI_qos_monitoring_report_t *OpenAPI_qos_monitoring_report_create( - OpenAPI_list_t *ref_pcc_rule_ids, + OpenAPI_list_t *flows, OpenAPI_list_t *ul_delays, OpenAPI_list_t *dl_delays, OpenAPI_list_t *rt_delays @@ -15,7 +15,7 @@ OpenAPI_qos_monitoring_report_t *OpenAPI_qos_monitoring_report_create( if (!qos_monitoring_report_local_var) { return NULL; } - qos_monitoring_report_local_var->ref_pcc_rule_ids = ref_pcc_rule_ids; + qos_monitoring_report_local_var->flows = flows; qos_monitoring_report_local_var->ul_delays = ul_delays; qos_monitoring_report_local_var->dl_delays = dl_delays; qos_monitoring_report_local_var->rt_delays = rt_delays; @@ -29,10 +29,10 @@ void OpenAPI_qos_monitoring_report_free(OpenAPI_qos_monitoring_report_t *qos_mon return; } OpenAPI_lnode_t *node; - OpenAPI_list_for_each(qos_monitoring_report->ref_pcc_rule_ids, node) { - ogs_free(node->data); + OpenAPI_list_for_each(qos_monitoring_report->flows, node) { + OpenAPI_flows_free(node->data); } - OpenAPI_list_free(qos_monitoring_report->ref_pcc_rule_ids); + OpenAPI_list_free(qos_monitoring_report->flows); OpenAPI_list_for_each(qos_monitoring_report->ul_delays, node) { ogs_free(node->data); } @@ -58,18 +58,24 @@ cJSON *OpenAPI_qos_monitoring_report_convertToJSON(OpenAPI_qos_monitoring_report } item = cJSON_CreateObject(); - cJSON *ref_pcc_rule_ids = cJSON_AddArrayToObject(item, "refPccRuleIds"); - if (ref_pcc_rule_ids == NULL) { - ogs_error("OpenAPI_qos_monitoring_report_convertToJSON() failed [ref_pcc_rule_ids]"); - goto end; - } - - OpenAPI_lnode_t *ref_pcc_rule_ids_node; - OpenAPI_list_for_each(qos_monitoring_report->ref_pcc_rule_ids, ref_pcc_rule_ids_node) { - if (cJSON_AddStringToObject(ref_pcc_rule_ids, "", (char*)ref_pcc_rule_ids_node->data) == NULL) { - ogs_error("OpenAPI_qos_monitoring_report_convertToJSON() failed [ref_pcc_rule_ids]"); + if (qos_monitoring_report->flows) { + cJSON *flowsList = cJSON_AddArrayToObject(item, "flows"); + if (flowsList == NULL) { + ogs_error("OpenAPI_qos_monitoring_report_convertToJSON() failed [flows]"); goto end; } + + OpenAPI_lnode_t *flows_node; + if (qos_monitoring_report->flows) { + OpenAPI_list_for_each(qos_monitoring_report->flows, flows_node) { + cJSON *itemLocal = OpenAPI_flows_convertToJSON(flows_node->data); + if (itemLocal == NULL) { + ogs_error("OpenAPI_qos_monitoring_report_convertToJSON() failed [flows]"); + goto end; + } + cJSON_AddItemToArray(flowsList, itemLocal); + } + } } if (qos_monitoring_report->ul_delays) { @@ -127,27 +133,27 @@ end: OpenAPI_qos_monitoring_report_t *OpenAPI_qos_monitoring_report_parseFromJSON(cJSON *qos_monitoring_reportJSON) { OpenAPI_qos_monitoring_report_t *qos_monitoring_report_local_var = NULL; - cJSON *ref_pcc_rule_ids = cJSON_GetObjectItemCaseSensitive(qos_monitoring_reportJSON, "refPccRuleIds"); - if (!ref_pcc_rule_ids) { - ogs_error("OpenAPI_qos_monitoring_report_parseFromJSON() failed [ref_pcc_rule_ids]"); - goto end; - } + cJSON *flows = cJSON_GetObjectItemCaseSensitive(qos_monitoring_reportJSON, "flows"); - OpenAPI_list_t *ref_pcc_rule_idsList; - - cJSON *ref_pcc_rule_ids_local; - if (!cJSON_IsArray(ref_pcc_rule_ids)) { - ogs_error("OpenAPI_qos_monitoring_report_parseFromJSON() failed [ref_pcc_rule_ids]"); - goto end; - } - ref_pcc_rule_idsList = OpenAPI_list_create(); - - cJSON_ArrayForEach(ref_pcc_rule_ids_local, ref_pcc_rule_ids) { - if (!cJSON_IsString(ref_pcc_rule_ids_local)) { - ogs_error("OpenAPI_qos_monitoring_report_parseFromJSON() failed [ref_pcc_rule_ids]"); + OpenAPI_list_t *flowsList; + if (flows) { + cJSON *flows_local_nonprimitive; + if (!cJSON_IsArray(flows)) { + ogs_error("OpenAPI_qos_monitoring_report_parseFromJSON() failed [flows]"); goto end; } - OpenAPI_list_add(ref_pcc_rule_idsList, ogs_strdup(ref_pcc_rule_ids_local->valuestring)); + + flowsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(flows_local_nonprimitive, flows ) { + if (!cJSON_IsObject(flows_local_nonprimitive)) { + ogs_error("OpenAPI_qos_monitoring_report_parseFromJSON() failed [flows]"); + goto end; + } + OpenAPI_flows_t *flowsItem = OpenAPI_flows_parseFromJSON(flows_local_nonprimitive); + + OpenAPI_list_add(flowsList, flowsItem); + } } cJSON *ul_delays = cJSON_GetObjectItemCaseSensitive(qos_monitoring_reportJSON, "ulDelays"); @@ -211,7 +217,7 @@ OpenAPI_qos_monitoring_report_t *OpenAPI_qos_monitoring_report_parseFromJSON(cJS } qos_monitoring_report_local_var = OpenAPI_qos_monitoring_report_create ( - ref_pcc_rule_idsList, + flows ? flowsList : NULL, ul_delays ? ul_delaysList : NULL, dl_delays ? dl_delaysList : NULL, rt_delays ? rt_delaysList : NULL diff --git a/lib/sbi/openapi/model/qos_monitoring_report.h b/lib/sbi/openapi/model/qos_monitoring_report.h index 0285f86ad..d787751ad 100644 --- a/lib/sbi/openapi/model/qos_monitoring_report.h +++ b/lib/sbi/openapi/model/qos_monitoring_report.h @@ -1,7 +1,7 @@ /* * qos_monitoring_report.h * - * + * QoS Monitoring reporting information */ #ifndef _OpenAPI_qos_monitoring_report_H_ @@ -12,6 +12,7 @@ #include "../include/list.h" #include "../include/keyValuePair.h" #include "../include/binary.h" +#include "flows.h" #ifdef __cplusplus extern "C" { @@ -19,14 +20,14 @@ extern "C" { typedef struct OpenAPI_qos_monitoring_report_s OpenAPI_qos_monitoring_report_t; typedef struct OpenAPI_qos_monitoring_report_s { - OpenAPI_list_t *ref_pcc_rule_ids; + OpenAPI_list_t *flows; OpenAPI_list_t *ul_delays; OpenAPI_list_t *dl_delays; OpenAPI_list_t *rt_delays; } OpenAPI_qos_monitoring_report_t; OpenAPI_qos_monitoring_report_t *OpenAPI_qos_monitoring_report_create( - OpenAPI_list_t *ref_pcc_rule_ids, + OpenAPI_list_t *flows, OpenAPI_list_t *ul_delays, OpenAPI_list_t *dl_delays, OpenAPI_list_t *rt_delays diff --git a/lib/sbi/openapi/model/qos_notification_control_info.c b/lib/sbi/openapi/model/qos_notification_control_info.c index 88fc49109..3fcbacd00 100644 --- a/lib/sbi/openapi/model/qos_notification_control_info.c +++ b/lib/sbi/openapi/model/qos_notification_control_info.c @@ -5,20 +5,18 @@ #include "qos_notification_control_info.h" OpenAPI_qos_notification_control_info_t *OpenAPI_qos_notification_control_info_create( - OpenAPI_list_t *ref_pcc_rule_ids, OpenAPI_qos_notif_type_t *notif_type, - int cont_ver, - char *alt_qos_param_id + OpenAPI_list_t *flows, + char *alt_ser_req ) { OpenAPI_qos_notification_control_info_t *qos_notification_control_info_local_var = OpenAPI_malloc(sizeof(OpenAPI_qos_notification_control_info_t)); if (!qos_notification_control_info_local_var) { return NULL; } - qos_notification_control_info_local_var->ref_pcc_rule_ids = ref_pcc_rule_ids; qos_notification_control_info_local_var->notif_type = notif_type; - qos_notification_control_info_local_var->cont_ver = cont_ver; - qos_notification_control_info_local_var->alt_qos_param_id = alt_qos_param_id; + qos_notification_control_info_local_var->flows = flows; + qos_notification_control_info_local_var->alt_ser_req = alt_ser_req; return qos_notification_control_info_local_var; } @@ -29,12 +27,12 @@ void OpenAPI_qos_notification_control_info_free(OpenAPI_qos_notification_control return; } OpenAPI_lnode_t *node; - OpenAPI_list_for_each(qos_notification_control_info->ref_pcc_rule_ids, node) { - ogs_free(node->data); - } - OpenAPI_list_free(qos_notification_control_info->ref_pcc_rule_ids); OpenAPI_qos_notif_type_free(qos_notification_control_info->notif_type); - ogs_free(qos_notification_control_info->alt_qos_param_id); + OpenAPI_list_for_each(qos_notification_control_info->flows, node) { + OpenAPI_flows_free(node->data); + } + OpenAPI_list_free(qos_notification_control_info->flows); + ogs_free(qos_notification_control_info->alt_ser_req); ogs_free(qos_notification_control_info); } @@ -48,20 +46,6 @@ cJSON *OpenAPI_qos_notification_control_info_convertToJSON(OpenAPI_qos_notificat } item = cJSON_CreateObject(); - cJSON *ref_pcc_rule_ids = cJSON_AddArrayToObject(item, "refPccRuleIds"); - if (ref_pcc_rule_ids == NULL) { - ogs_error("OpenAPI_qos_notification_control_info_convertToJSON() failed [ref_pcc_rule_ids]"); - goto end; - } - - OpenAPI_lnode_t *ref_pcc_rule_ids_node; - OpenAPI_list_for_each(qos_notification_control_info->ref_pcc_rule_ids, ref_pcc_rule_ids_node) { - if (cJSON_AddStringToObject(ref_pcc_rule_ids, "", (char*)ref_pcc_rule_ids_node->data) == NULL) { - ogs_error("OpenAPI_qos_notification_control_info_convertToJSON() failed [ref_pcc_rule_ids]"); - goto end; - } - } - cJSON *notif_type_local_JSON = OpenAPI_qos_notif_type_convertToJSON(qos_notification_control_info->notif_type); if (notif_type_local_JSON == NULL) { ogs_error("OpenAPI_qos_notification_control_info_convertToJSON() failed [notif_type]"); @@ -73,16 +57,29 @@ cJSON *OpenAPI_qos_notification_control_info_convertToJSON(OpenAPI_qos_notificat goto end; } - if (qos_notification_control_info->cont_ver) { - if (cJSON_AddNumberToObject(item, "contVer", qos_notification_control_info->cont_ver) == NULL) { - ogs_error("OpenAPI_qos_notification_control_info_convertToJSON() failed [cont_ver]"); + if (qos_notification_control_info->flows) { + cJSON *flowsList = cJSON_AddArrayToObject(item, "flows"); + if (flowsList == NULL) { + ogs_error("OpenAPI_qos_notification_control_info_convertToJSON() failed [flows]"); goto end; } + + OpenAPI_lnode_t *flows_node; + if (qos_notification_control_info->flows) { + OpenAPI_list_for_each(qos_notification_control_info->flows, flows_node) { + cJSON *itemLocal = OpenAPI_flows_convertToJSON(flows_node->data); + if (itemLocal == NULL) { + ogs_error("OpenAPI_qos_notification_control_info_convertToJSON() failed [flows]"); + goto end; + } + cJSON_AddItemToArray(flowsList, itemLocal); + } + } } - if (qos_notification_control_info->alt_qos_param_id) { - if (cJSON_AddStringToObject(item, "altQosParamId", qos_notification_control_info->alt_qos_param_id) == NULL) { - ogs_error("OpenAPI_qos_notification_control_info_convertToJSON() failed [alt_qos_param_id]"); + if (qos_notification_control_info->alt_ser_req) { + if (cJSON_AddStringToObject(item, "altSerReq", qos_notification_control_info->alt_ser_req) == NULL) { + ogs_error("OpenAPI_qos_notification_control_info_convertToJSON() failed [alt_ser_req]"); goto end; } } @@ -94,29 +91,6 @@ end: OpenAPI_qos_notification_control_info_t *OpenAPI_qos_notification_control_info_parseFromJSON(cJSON *qos_notification_control_infoJSON) { OpenAPI_qos_notification_control_info_t *qos_notification_control_info_local_var = NULL; - cJSON *ref_pcc_rule_ids = cJSON_GetObjectItemCaseSensitive(qos_notification_control_infoJSON, "refPccRuleIds"); - if (!ref_pcc_rule_ids) { - ogs_error("OpenAPI_qos_notification_control_info_parseFromJSON() failed [ref_pcc_rule_ids]"); - goto end; - } - - OpenAPI_list_t *ref_pcc_rule_idsList; - - cJSON *ref_pcc_rule_ids_local; - if (!cJSON_IsArray(ref_pcc_rule_ids)) { - ogs_error("OpenAPI_qos_notification_control_info_parseFromJSON() failed [ref_pcc_rule_ids]"); - goto end; - } - ref_pcc_rule_idsList = OpenAPI_list_create(); - - cJSON_ArrayForEach(ref_pcc_rule_ids_local, ref_pcc_rule_ids) { - if (!cJSON_IsString(ref_pcc_rule_ids_local)) { - ogs_error("OpenAPI_qos_notification_control_info_parseFromJSON() failed [ref_pcc_rule_ids]"); - goto end; - } - OpenAPI_list_add(ref_pcc_rule_idsList, ogs_strdup(ref_pcc_rule_ids_local->valuestring)); - } - cJSON *notif_type = cJSON_GetObjectItemCaseSensitive(qos_notification_control_infoJSON, "notifType"); if (!notif_type) { ogs_error("OpenAPI_qos_notification_control_info_parseFromJSON() failed [notif_type]"); @@ -127,29 +101,42 @@ OpenAPI_qos_notification_control_info_t *OpenAPI_qos_notification_control_info_p notif_type_local_nonprim = OpenAPI_qos_notif_type_parseFromJSON(notif_type); - cJSON *cont_ver = cJSON_GetObjectItemCaseSensitive(qos_notification_control_infoJSON, "contVer"); + cJSON *flows = cJSON_GetObjectItemCaseSensitive(qos_notification_control_infoJSON, "flows"); - if (cont_ver) { - if (!cJSON_IsNumber(cont_ver)) { - ogs_error("OpenAPI_qos_notification_control_info_parseFromJSON() failed [cont_ver]"); + OpenAPI_list_t *flowsList; + if (flows) { + cJSON *flows_local_nonprimitive; + if (!cJSON_IsArray(flows)) { + ogs_error("OpenAPI_qos_notification_control_info_parseFromJSON() failed [flows]"); goto end; } + + flowsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(flows_local_nonprimitive, flows ) { + if (!cJSON_IsObject(flows_local_nonprimitive)) { + ogs_error("OpenAPI_qos_notification_control_info_parseFromJSON() failed [flows]"); + goto end; + } + OpenAPI_flows_t *flowsItem = OpenAPI_flows_parseFromJSON(flows_local_nonprimitive); + + OpenAPI_list_add(flowsList, flowsItem); + } } - cJSON *alt_qos_param_id = cJSON_GetObjectItemCaseSensitive(qos_notification_control_infoJSON, "altQosParamId"); + cJSON *alt_ser_req = cJSON_GetObjectItemCaseSensitive(qos_notification_control_infoJSON, "altSerReq"); - if (alt_qos_param_id) { - if (!cJSON_IsString(alt_qos_param_id)) { - ogs_error("OpenAPI_qos_notification_control_info_parseFromJSON() failed [alt_qos_param_id]"); + if (alt_ser_req) { + if (!cJSON_IsString(alt_ser_req)) { + ogs_error("OpenAPI_qos_notification_control_info_parseFromJSON() failed [alt_ser_req]"); goto end; } } qos_notification_control_info_local_var = OpenAPI_qos_notification_control_info_create ( - ref_pcc_rule_idsList, notif_type_local_nonprim, - cont_ver ? cont_ver->valuedouble : 0, - alt_qos_param_id ? ogs_strdup(alt_qos_param_id->valuestring) : NULL + flows ? flowsList : NULL, + alt_ser_req ? ogs_strdup(alt_ser_req->valuestring) : NULL ); return qos_notification_control_info_local_var; diff --git a/lib/sbi/openapi/model/qos_notification_control_info.h b/lib/sbi/openapi/model/qos_notification_control_info.h index 2b03fd7e6..027d6c9f2 100644 --- a/lib/sbi/openapi/model/qos_notification_control_info.h +++ b/lib/sbi/openapi/model/qos_notification_control_info.h @@ -1,7 +1,7 @@ /* * qos_notification_control_info.h * - * + * Indicates whether the QoS targets for a GRB flow are not guaranteed or guaranteed again */ #ifndef _OpenAPI_qos_notification_control_info_H_ @@ -12,6 +12,7 @@ #include "../include/list.h" #include "../include/keyValuePair.h" #include "../include/binary.h" +#include "flows.h" #include "qos_notif_type.h" #ifdef __cplusplus @@ -20,17 +21,15 @@ extern "C" { typedef struct OpenAPI_qos_notification_control_info_s OpenAPI_qos_notification_control_info_t; typedef struct OpenAPI_qos_notification_control_info_s { - OpenAPI_list_t *ref_pcc_rule_ids; struct OpenAPI_qos_notif_type_s *notif_type; - int cont_ver; - char *alt_qos_param_id; + OpenAPI_list_t *flows; + char *alt_ser_req; } OpenAPI_qos_notification_control_info_t; OpenAPI_qos_notification_control_info_t *OpenAPI_qos_notification_control_info_create( - OpenAPI_list_t *ref_pcc_rule_ids, OpenAPI_qos_notif_type_t *notif_type, - int cont_ver, - char *alt_qos_param_id + OpenAPI_list_t *flows, + char *alt_ser_req ); void OpenAPI_qos_notification_control_info_free(OpenAPI_qos_notification_control_info_t *qos_notification_control_info); OpenAPI_qos_notification_control_info_t *OpenAPI_qos_notification_control_info_parseFromJSON(cJSON *qos_notification_control_infoJSON); diff --git a/lib/sbi/openapi/model/registration_data_set_name.c b/lib/sbi/openapi/model/registration_data_set_name.c index 4f6a4e2ae..af3552d8d 100644 --- a/lib/sbi/openapi/model/registration_data_set_name.c +++ b/lib/sbi/openapi/model/registration_data_set_name.c @@ -4,82 +4,27 @@ #include #include "registration_data_set_name.h" -OpenAPI_registration_data_set_name_t *OpenAPI_registration_data_set_name_create( - ) +char* OpenAPI_registration_data_set_name_ToString(OpenAPI_registration_data_set_name_e registration_data_set_name) { - OpenAPI_registration_data_set_name_t *registration_data_set_name_local_var = OpenAPI_malloc(sizeof(OpenAPI_registration_data_set_name_t)); - if (!registration_data_set_name_local_var) { - return NULL; - } - - return registration_data_set_name_local_var; + const char *registration_data_set_nameArray[] = { "NULL", "AMF_3GPP", "AMF_NON_3GPP", "SMF_PDU_SESSIONS", "SMSF_3GPP", "SMSF_NON_3GPP" }; + size_t sizeofArray = sizeof(registration_data_set_nameArray) / sizeof(registration_data_set_nameArray[0]); + if (registration_data_set_name < sizeofArray) + return (char *)registration_data_set_nameArray[registration_data_set_name]; + else + return (char *)"Unknown"; } -void OpenAPI_registration_data_set_name_free(OpenAPI_registration_data_set_name_t *registration_data_set_name) +OpenAPI_registration_data_set_name_e OpenAPI_registration_data_set_name_FromString(char* registration_data_set_name) { - if (NULL == registration_data_set_name) { - return; + int stringToReturn = 0; + const char *registration_data_set_nameArray[] = { "NULL", "AMF_3GPP", "AMF_NON_3GPP", "SMF_PDU_SESSIONS", "SMSF_3GPP", "SMSF_NON_3GPP" }; + size_t sizeofArray = sizeof(registration_data_set_nameArray) / sizeof(registration_data_set_nameArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(registration_data_set_name, registration_data_set_nameArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; } - OpenAPI_lnode_t *node; - ogs_free(registration_data_set_name); -} - -cJSON *OpenAPI_registration_data_set_name_convertToJSON(OpenAPI_registration_data_set_name_t *registration_data_set_name) -{ - cJSON *item = NULL; - - if (registration_data_set_name == NULL) { - ogs_error("OpenAPI_registration_data_set_name_convertToJSON() failed [RegistrationDataSetName]"); - return NULL; - } - - item = cJSON_CreateObject(); -end: - return item; -} - -OpenAPI_registration_data_set_name_t *OpenAPI_registration_data_set_name_parseFromJSON(cJSON *registration_data_set_nameJSON) -{ - OpenAPI_registration_data_set_name_t *registration_data_set_name_local_var = NULL; - registration_data_set_name_local_var = OpenAPI_registration_data_set_name_create ( - ); - - return registration_data_set_name_local_var; -end: - return NULL; -} - -OpenAPI_registration_data_set_name_t *OpenAPI_registration_data_set_name_copy(OpenAPI_registration_data_set_name_t *dst, OpenAPI_registration_data_set_name_t *src) -{ - cJSON *item = NULL; - char *content = NULL; - - ogs_assert(src); - item = OpenAPI_registration_data_set_name_convertToJSON(src); - if (!item) { - ogs_error("OpenAPI_registration_data_set_name_convertToJSON() failed"); - return NULL; - } - - content = cJSON_Print(item); - cJSON_Delete(item); - - if (!content) { - ogs_error("cJSON_Print() failed"); - return NULL; - } - - item = cJSON_Parse(content); - ogs_free(content); - if (!item) { - ogs_error("cJSON_Parse() failed"); - return NULL; - } - - OpenAPI_registration_data_set_name_free(dst); - dst = OpenAPI_registration_data_set_name_parseFromJSON(item); - cJSON_Delete(item); - - return dst; + return 0; } diff --git a/lib/sbi/openapi/model/registration_data_set_name.h b/lib/sbi/openapi/model/registration_data_set_name.h index 31bd04b5a..806485d6f 100644 --- a/lib/sbi/openapi/model/registration_data_set_name.h +++ b/lib/sbi/openapi/model/registration_data_set_name.h @@ -17,16 +17,11 @@ extern "C" { #endif -typedef struct OpenAPI_registration_data_set_name_s OpenAPI_registration_data_set_name_t; -typedef struct OpenAPI_registration_data_set_name_s { -} OpenAPI_registration_data_set_name_t; +typedef enum { OpenAPI_registration_data_set_name_NULL = 0, OpenAPI_registration_data_set_name_AMF_3GPP, OpenAPI_registration_data_set_name_AMF_NON_3GPP, OpenAPI_registration_data_set_name_SMF_PDU_SESSIONS, OpenAPI_registration_data_set_name_SMSF_3GPP, OpenAPI_registration_data_set_name_SMSF_NON_3GPP } OpenAPI_registration_data_set_name_e; -OpenAPI_registration_data_set_name_t *OpenAPI_registration_data_set_name_create( - ); -void OpenAPI_registration_data_set_name_free(OpenAPI_registration_data_set_name_t *registration_data_set_name); -OpenAPI_registration_data_set_name_t *OpenAPI_registration_data_set_name_parseFromJSON(cJSON *registration_data_set_nameJSON); -cJSON *OpenAPI_registration_data_set_name_convertToJSON(OpenAPI_registration_data_set_name_t *registration_data_set_name); -OpenAPI_registration_data_set_name_t *OpenAPI_registration_data_set_name_copy(OpenAPI_registration_data_set_name_t *dst, OpenAPI_registration_data_set_name_t *src); +char* OpenAPI_registration_data_set_name_ToString(OpenAPI_registration_data_set_name_e registration_data_set_name); + +OpenAPI_registration_data_set_name_e OpenAPI_registration_data_set_name_FromString(char* registration_data_set_name); #ifdef __cplusplus } diff --git a/lib/sbi/openapi/model/registration_reason.c b/lib/sbi/openapi/model/registration_reason.c index cfdfd73d5..a4e0b6830 100644 --- a/lib/sbi/openapi/model/registration_reason.c +++ b/lib/sbi/openapi/model/registration_reason.c @@ -4,82 +4,27 @@ #include #include "registration_reason.h" -OpenAPI_registration_reason_t *OpenAPI_registration_reason_create( - ) +char* OpenAPI_registration_reason_ToString(OpenAPI_registration_reason_e registration_reason) { - OpenAPI_registration_reason_t *registration_reason_local_var = OpenAPI_malloc(sizeof(OpenAPI_registration_reason_t)); - if (!registration_reason_local_var) { - return NULL; - } - - return registration_reason_local_var; + const char *registration_reasonArray[] = { "NULL", "SMF_CONTEXT_TRANSFERRED" }; + size_t sizeofArray = sizeof(registration_reasonArray) / sizeof(registration_reasonArray[0]); + if (registration_reason < sizeofArray) + return (char *)registration_reasonArray[registration_reason]; + else + return (char *)"Unknown"; } -void OpenAPI_registration_reason_free(OpenAPI_registration_reason_t *registration_reason) +OpenAPI_registration_reason_e OpenAPI_registration_reason_FromString(char* registration_reason) { - if (NULL == registration_reason) { - return; + int stringToReturn = 0; + const char *registration_reasonArray[] = { "NULL", "SMF_CONTEXT_TRANSFERRED" }; + size_t sizeofArray = sizeof(registration_reasonArray) / sizeof(registration_reasonArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(registration_reason, registration_reasonArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; } - OpenAPI_lnode_t *node; - ogs_free(registration_reason); -} - -cJSON *OpenAPI_registration_reason_convertToJSON(OpenAPI_registration_reason_t *registration_reason) -{ - cJSON *item = NULL; - - if (registration_reason == NULL) { - ogs_error("OpenAPI_registration_reason_convertToJSON() failed [RegistrationReason]"); - return NULL; - } - - item = cJSON_CreateObject(); -end: - return item; -} - -OpenAPI_registration_reason_t *OpenAPI_registration_reason_parseFromJSON(cJSON *registration_reasonJSON) -{ - OpenAPI_registration_reason_t *registration_reason_local_var = NULL; - registration_reason_local_var = OpenAPI_registration_reason_create ( - ); - - return registration_reason_local_var; -end: - return NULL; -} - -OpenAPI_registration_reason_t *OpenAPI_registration_reason_copy(OpenAPI_registration_reason_t *dst, OpenAPI_registration_reason_t *src) -{ - cJSON *item = NULL; - char *content = NULL; - - ogs_assert(src); - item = OpenAPI_registration_reason_convertToJSON(src); - if (!item) { - ogs_error("OpenAPI_registration_reason_convertToJSON() failed"); - return NULL; - } - - content = cJSON_Print(item); - cJSON_Delete(item); - - if (!content) { - ogs_error("cJSON_Print() failed"); - return NULL; - } - - item = cJSON_Parse(content); - ogs_free(content); - if (!item) { - ogs_error("cJSON_Parse() failed"); - return NULL; - } - - OpenAPI_registration_reason_free(dst); - dst = OpenAPI_registration_reason_parseFromJSON(item); - cJSON_Delete(item); - - return dst; + return 0; } diff --git a/lib/sbi/openapi/model/registration_reason.h b/lib/sbi/openapi/model/registration_reason.h index 785af9de6..61822020d 100644 --- a/lib/sbi/openapi/model/registration_reason.h +++ b/lib/sbi/openapi/model/registration_reason.h @@ -17,16 +17,11 @@ extern "C" { #endif -typedef struct OpenAPI_registration_reason_s OpenAPI_registration_reason_t; -typedef struct OpenAPI_registration_reason_s { -} OpenAPI_registration_reason_t; +typedef enum { OpenAPI_registration_reason_NULL = 0, OpenAPI_registration_reason_SMF_CONTEXT_TRANSFERRED } OpenAPI_registration_reason_e; -OpenAPI_registration_reason_t *OpenAPI_registration_reason_create( - ); -void OpenAPI_registration_reason_free(OpenAPI_registration_reason_t *registration_reason); -OpenAPI_registration_reason_t *OpenAPI_registration_reason_parseFromJSON(cJSON *registration_reasonJSON); -cJSON *OpenAPI_registration_reason_convertToJSON(OpenAPI_registration_reason_t *registration_reason); -OpenAPI_registration_reason_t *OpenAPI_registration_reason_copy(OpenAPI_registration_reason_t *dst, OpenAPI_registration_reason_t *src); +char* OpenAPI_registration_reason_ToString(OpenAPI_registration_reason_e registration_reason); + +OpenAPI_registration_reason_e OpenAPI_registration_reason_FromString(char* registration_reason); #ifdef __cplusplus } diff --git a/lib/sbi/openapi/model/required_access_info.c b/lib/sbi/openapi/model/required_access_info.c new file mode 100644 index 000000000..168548ab4 --- /dev/null +++ b/lib/sbi/openapi/model/required_access_info.c @@ -0,0 +1,30 @@ + +#include +#include +#include +#include "required_access_info.h" + +char* OpenAPI_required_access_info_ToString(OpenAPI_required_access_info_e required_access_info) +{ + const char *required_access_infoArray[] = { "NULL", "USER_LOCATION", "UE_TIME_ZONE" }; + size_t sizeofArray = sizeof(required_access_infoArray) / sizeof(required_access_infoArray[0]); + if (required_access_info < sizeofArray) + return (char *)required_access_infoArray[required_access_info]; + else + return (char *)"Unknown"; +} + +OpenAPI_required_access_info_e OpenAPI_required_access_info_FromString(char* required_access_info) +{ + int stringToReturn = 0; + const char *required_access_infoArray[] = { "NULL", "USER_LOCATION", "UE_TIME_ZONE" }; + size_t sizeofArray = sizeof(required_access_infoArray) / sizeof(required_access_infoArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(required_access_info, required_access_infoArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; + } + return 0; +} + diff --git a/lib/sbi/openapi/model/required_access_info.h b/lib/sbi/openapi/model/required_access_info.h new file mode 100644 index 000000000..d4cb5a263 --- /dev/null +++ b/lib/sbi/openapi/model/required_access_info.h @@ -0,0 +1,31 @@ +/* + * required_access_info.h + * + * + */ + +#ifndef _OpenAPI_required_access_info_H_ +#define _OpenAPI_required_access_info_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { OpenAPI_required_access_info_NULL = 0, OpenAPI_required_access_info_USER_LOCATION, OpenAPI_required_access_info_UE_TIME_ZONE } OpenAPI_required_access_info_e; + +char* OpenAPI_required_access_info_ToString(OpenAPI_required_access_info_e required_access_info); + +OpenAPI_required_access_info_e OpenAPI_required_access_info_FromString(char* required_access_info); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_required_access_info_H_ */ + diff --git a/lib/sbi/openapi/model/reserv_priority.c b/lib/sbi/openapi/model/reserv_priority.c new file mode 100644 index 000000000..586455656 --- /dev/null +++ b/lib/sbi/openapi/model/reserv_priority.c @@ -0,0 +1,30 @@ + +#include +#include +#include +#include "reserv_priority.h" + +char* OpenAPI_reserv_priority_ToString(OpenAPI_reserv_priority_e reserv_priority) +{ + const char *reserv_priorityArray[] = { "NULL", "PRIO_1", "PRIO_2", "PRIO_3", "PRIO_4", "PRIO_5", "PRIO_6", "PRIO_7", "PRIO_8", "PRIO_9", "PRIO_10", "PRIO_11", "PRIO_12", "PRIO_13", "PRIO_14", "PRIO_15", "PRIO_16" }; + size_t sizeofArray = sizeof(reserv_priorityArray) / sizeof(reserv_priorityArray[0]); + if (reserv_priority < sizeofArray) + return (char *)reserv_priorityArray[reserv_priority]; + else + return (char *)"Unknown"; +} + +OpenAPI_reserv_priority_e OpenAPI_reserv_priority_FromString(char* reserv_priority) +{ + int stringToReturn = 0; + const char *reserv_priorityArray[] = { "NULL", "PRIO_1", "PRIO_2", "PRIO_3", "PRIO_4", "PRIO_5", "PRIO_6", "PRIO_7", "PRIO_8", "PRIO_9", "PRIO_10", "PRIO_11", "PRIO_12", "PRIO_13", "PRIO_14", "PRIO_15", "PRIO_16" }; + size_t sizeofArray = sizeof(reserv_priorityArray) / sizeof(reserv_priorityArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(reserv_priority, reserv_priorityArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; + } + return 0; +} + diff --git a/lib/sbi/openapi/model/reserv_priority.h b/lib/sbi/openapi/model/reserv_priority.h new file mode 100644 index 000000000..349c5b771 --- /dev/null +++ b/lib/sbi/openapi/model/reserv_priority.h @@ -0,0 +1,31 @@ +/* + * reserv_priority.h + * + * + */ + +#ifndef _OpenAPI_reserv_priority_H_ +#define _OpenAPI_reserv_priority_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { OpenAPI_reserv_priority_NULL = 0, OpenAPI_reserv_priority_PRIO_1, OpenAPI_reserv_priority_PRIO_2, OpenAPI_reserv_priority_PRIO_3, OpenAPI_reserv_priority_PRIO_4, OpenAPI_reserv_priority_PRIO_5, OpenAPI_reserv_priority_PRIO_6, OpenAPI_reserv_priority_PRIO_7, OpenAPI_reserv_priority_PRIO_8, OpenAPI_reserv_priority_PRIO_9, OpenAPI_reserv_priority_PRIO_10, OpenAPI_reserv_priority_PRIO_11, OpenAPI_reserv_priority_PRIO_12, OpenAPI_reserv_priority_PRIO_13, OpenAPI_reserv_priority_PRIO_14, OpenAPI_reserv_priority_PRIO_15, OpenAPI_reserv_priority_PRIO_16 } OpenAPI_reserv_priority_e; + +char* OpenAPI_reserv_priority_ToString(OpenAPI_reserv_priority_e reserv_priority); + +OpenAPI_reserv_priority_e OpenAPI_reserv_priority_FromString(char* reserv_priority); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_reserv_priority_H_ */ + diff --git a/lib/sbi/openapi/model/resources_allocation_info.c b/lib/sbi/openapi/model/resources_allocation_info.c new file mode 100644 index 000000000..e035942cf --- /dev/null +++ b/lib/sbi/openapi/model/resources_allocation_info.c @@ -0,0 +1,157 @@ + +#include +#include +#include +#include "resources_allocation_info.h" + +OpenAPI_resources_allocation_info_t *OpenAPI_resources_allocation_info_create( + OpenAPI_media_component_resources_status_e mc_resourc_status, + OpenAPI_list_t *flows + ) +{ + OpenAPI_resources_allocation_info_t *resources_allocation_info_local_var = OpenAPI_malloc(sizeof(OpenAPI_resources_allocation_info_t)); + if (!resources_allocation_info_local_var) { + return NULL; + } + resources_allocation_info_local_var->mc_resourc_status = mc_resourc_status; + resources_allocation_info_local_var->flows = flows; + + return resources_allocation_info_local_var; +} + +void OpenAPI_resources_allocation_info_free(OpenAPI_resources_allocation_info_t *resources_allocation_info) +{ + if (NULL == resources_allocation_info) { + return; + } + OpenAPI_lnode_t *node; + OpenAPI_list_for_each(resources_allocation_info->flows, node) { + OpenAPI_flows_free(node->data); + } + OpenAPI_list_free(resources_allocation_info->flows); + ogs_free(resources_allocation_info); +} + +cJSON *OpenAPI_resources_allocation_info_convertToJSON(OpenAPI_resources_allocation_info_t *resources_allocation_info) +{ + cJSON *item = NULL; + + if (resources_allocation_info == NULL) { + ogs_error("OpenAPI_resources_allocation_info_convertToJSON() failed [ResourcesAllocationInfo]"); + return NULL; + } + + item = cJSON_CreateObject(); + if (cJSON_AddStringToObject(item, "mcResourcStatus", OpenAPI_media_component_resources_status_ToString(resources_allocation_info->mc_resourc_status)) == NULL) { + ogs_error("OpenAPI_resources_allocation_info_convertToJSON() failed [mc_resourc_status]"); + goto end; + } + + if (resources_allocation_info->flows) { + cJSON *flowsList = cJSON_AddArrayToObject(item, "flows"); + if (flowsList == NULL) { + ogs_error("OpenAPI_resources_allocation_info_convertToJSON() failed [flows]"); + goto end; + } + + OpenAPI_lnode_t *flows_node; + if (resources_allocation_info->flows) { + OpenAPI_list_for_each(resources_allocation_info->flows, flows_node) { + cJSON *itemLocal = OpenAPI_flows_convertToJSON(flows_node->data); + if (itemLocal == NULL) { + ogs_error("OpenAPI_resources_allocation_info_convertToJSON() failed [flows]"); + goto end; + } + cJSON_AddItemToArray(flowsList, itemLocal); + } + } + } + +end: + return item; +} + +OpenAPI_resources_allocation_info_t *OpenAPI_resources_allocation_info_parseFromJSON(cJSON *resources_allocation_infoJSON) +{ + OpenAPI_resources_allocation_info_t *resources_allocation_info_local_var = NULL; + cJSON *mc_resourc_status = cJSON_GetObjectItemCaseSensitive(resources_allocation_infoJSON, "mcResourcStatus"); + if (!mc_resourc_status) { + ogs_error("OpenAPI_resources_allocation_info_parseFromJSON() failed [mc_resourc_status]"); + goto end; + } + + OpenAPI_media_component_resources_status_e mc_resourc_statusVariable; + + if (!cJSON_IsString(mc_resourc_status)) { + ogs_error("OpenAPI_resources_allocation_info_parseFromJSON() failed [mc_resourc_status]"); + goto end; + } + mc_resourc_statusVariable = OpenAPI_media_component_resources_status_FromString(mc_resourc_status->valuestring); + + cJSON *flows = cJSON_GetObjectItemCaseSensitive(resources_allocation_infoJSON, "flows"); + + OpenAPI_list_t *flowsList; + if (flows) { + cJSON *flows_local_nonprimitive; + if (!cJSON_IsArray(flows)) { + ogs_error("OpenAPI_resources_allocation_info_parseFromJSON() failed [flows]"); + goto end; + } + + flowsList = OpenAPI_list_create(); + + cJSON_ArrayForEach(flows_local_nonprimitive, flows ) { + if (!cJSON_IsObject(flows_local_nonprimitive)) { + ogs_error("OpenAPI_resources_allocation_info_parseFromJSON() failed [flows]"); + goto end; + } + OpenAPI_flows_t *flowsItem = OpenAPI_flows_parseFromJSON(flows_local_nonprimitive); + + OpenAPI_list_add(flowsList, flowsItem); + } + } + + resources_allocation_info_local_var = OpenAPI_resources_allocation_info_create ( + mc_resourc_statusVariable, + flows ? flowsList : NULL + ); + + return resources_allocation_info_local_var; +end: + return NULL; +} + +OpenAPI_resources_allocation_info_t *OpenAPI_resources_allocation_info_copy(OpenAPI_resources_allocation_info_t *dst, OpenAPI_resources_allocation_info_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_resources_allocation_info_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_resources_allocation_info_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_resources_allocation_info_free(dst); + dst = OpenAPI_resources_allocation_info_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/resources_allocation_info.h b/lib/sbi/openapi/model/resources_allocation_info.h new file mode 100644 index 000000000..29657450f --- /dev/null +++ b/lib/sbi/openapi/model/resources_allocation_info.h @@ -0,0 +1,42 @@ +/* + * resources_allocation_info.h + * + * describes the status of the PCC rule(s) related to certain media components. + */ + +#ifndef _OpenAPI_resources_allocation_info_H_ +#define _OpenAPI_resources_allocation_info_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" +#include "flows.h" +#include "media_component_resources_status.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_resources_allocation_info_s OpenAPI_resources_allocation_info_t; +typedef struct OpenAPI_resources_allocation_info_s { + OpenAPI_media_component_resources_status_e mc_resourc_status; + OpenAPI_list_t *flows; +} OpenAPI_resources_allocation_info_t; + +OpenAPI_resources_allocation_info_t *OpenAPI_resources_allocation_info_create( + OpenAPI_media_component_resources_status_e mc_resourc_status, + OpenAPI_list_t *flows + ); +void OpenAPI_resources_allocation_info_free(OpenAPI_resources_allocation_info_t *resources_allocation_info); +OpenAPI_resources_allocation_info_t *OpenAPI_resources_allocation_info_parseFromJSON(cJSON *resources_allocation_infoJSON); +cJSON *OpenAPI_resources_allocation_info_convertToJSON(OpenAPI_resources_allocation_info_t *resources_allocation_info); +OpenAPI_resources_allocation_info_t *OpenAPI_resources_allocation_info_copy(OpenAPI_resources_allocation_info_t *dst, OpenAPI_resources_allocation_info_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_resources_allocation_info_H_ */ + diff --git a/lib/sbi/openapi/model/serv_auth_info.c b/lib/sbi/openapi/model/serv_auth_info.c new file mode 100644 index 000000000..dc4a1a9e3 --- /dev/null +++ b/lib/sbi/openapi/model/serv_auth_info.c @@ -0,0 +1,30 @@ + +#include +#include +#include +#include "serv_auth_info.h" + +char* OpenAPI_serv_auth_info_ToString(OpenAPI_serv_auth_info_e serv_auth_info) +{ + const char *serv_auth_infoArray[] = { "NULL", "TP_NOT_KNOWN", "TP_EXPIRED", "TP_NOT_YET_OCURRED" }; + size_t sizeofArray = sizeof(serv_auth_infoArray) / sizeof(serv_auth_infoArray[0]); + if (serv_auth_info < sizeofArray) + return (char *)serv_auth_infoArray[serv_auth_info]; + else + return (char *)"Unknown"; +} + +OpenAPI_serv_auth_info_e OpenAPI_serv_auth_info_FromString(char* serv_auth_info) +{ + int stringToReturn = 0; + const char *serv_auth_infoArray[] = { "NULL", "TP_NOT_KNOWN", "TP_EXPIRED", "TP_NOT_YET_OCURRED" }; + size_t sizeofArray = sizeof(serv_auth_infoArray) / sizeof(serv_auth_infoArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(serv_auth_info, serv_auth_infoArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; + } + return 0; +} + diff --git a/lib/sbi/openapi/model/serv_auth_info.h b/lib/sbi/openapi/model/serv_auth_info.h new file mode 100644 index 000000000..66b8384b8 --- /dev/null +++ b/lib/sbi/openapi/model/serv_auth_info.h @@ -0,0 +1,31 @@ +/* + * serv_auth_info.h + * + * + */ + +#ifndef _OpenAPI_serv_auth_info_H_ +#define _OpenAPI_serv_auth_info_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { OpenAPI_serv_auth_info_NULL = 0, OpenAPI_serv_auth_info_TP_NOT_KNOWN, OpenAPI_serv_auth_info_TP_EXPIRED, OpenAPI_serv_auth_info_TP_NOT_YET_OCURRED } OpenAPI_serv_auth_info_e; + +char* OpenAPI_serv_auth_info_ToString(OpenAPI_serv_auth_info_e serv_auth_info); + +OpenAPI_serv_auth_info_e OpenAPI_serv_auth_info_FromString(char* serv_auth_info); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_serv_auth_info_H_ */ + diff --git a/lib/sbi/openapi/model/service_info_status.c b/lib/sbi/openapi/model/service_info_status.c new file mode 100644 index 000000000..5b38698e2 --- /dev/null +++ b/lib/sbi/openapi/model/service_info_status.c @@ -0,0 +1,30 @@ + +#include +#include +#include +#include "service_info_status.h" + +char* OpenAPI_service_info_status_ToString(OpenAPI_service_info_status_e service_info_status) +{ + const char *service_info_statusArray[] = { "NULL", "FINAL", "PRELIMINARY" }; + size_t sizeofArray = sizeof(service_info_statusArray) / sizeof(service_info_statusArray[0]); + if (service_info_status < sizeofArray) + return (char *)service_info_statusArray[service_info_status]; + else + return (char *)"Unknown"; +} + +OpenAPI_service_info_status_e OpenAPI_service_info_status_FromString(char* service_info_status) +{ + int stringToReturn = 0; + const char *service_info_statusArray[] = { "NULL", "FINAL", "PRELIMINARY" }; + size_t sizeofArray = sizeof(service_info_statusArray) / sizeof(service_info_statusArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(service_info_status, service_info_statusArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; + } + return 0; +} + diff --git a/lib/sbi/openapi/model/service_info_status.h b/lib/sbi/openapi/model/service_info_status.h new file mode 100644 index 000000000..15f267ddc --- /dev/null +++ b/lib/sbi/openapi/model/service_info_status.h @@ -0,0 +1,31 @@ +/* + * service_info_status.h + * + * + */ + +#ifndef _OpenAPI_service_info_status_H_ +#define _OpenAPI_service_info_status_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { OpenAPI_service_info_status_NULL = 0, OpenAPI_service_info_status_FINAL, OpenAPI_service_info_status_PRELIMINARY } OpenAPI_service_info_status_e; + +char* OpenAPI_service_info_status_ToString(OpenAPI_service_info_status_e service_info_status); + +OpenAPI_service_info_status_e OpenAPI_service_info_status_FromString(char* service_info_status); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_service_info_status_H_ */ + diff --git a/lib/sbi/openapi/model/sip_forking_indication.c b/lib/sbi/openapi/model/sip_forking_indication.c new file mode 100644 index 000000000..f91c3eeac --- /dev/null +++ b/lib/sbi/openapi/model/sip_forking_indication.c @@ -0,0 +1,30 @@ + +#include +#include +#include +#include "sip_forking_indication.h" + +char* OpenAPI_sip_forking_indication_ToString(OpenAPI_sip_forking_indication_e sip_forking_indication) +{ + const char *sip_forking_indicationArray[] = { "NULL", "SINGLE_DIALOGUE", "SEVERAL_DIALOGUES" }; + size_t sizeofArray = sizeof(sip_forking_indicationArray) / sizeof(sip_forking_indicationArray[0]); + if (sip_forking_indication < sizeofArray) + return (char *)sip_forking_indicationArray[sip_forking_indication]; + else + return (char *)"Unknown"; +} + +OpenAPI_sip_forking_indication_e OpenAPI_sip_forking_indication_FromString(char* sip_forking_indication) +{ + int stringToReturn = 0; + const char *sip_forking_indicationArray[] = { "NULL", "SINGLE_DIALOGUE", "SEVERAL_DIALOGUES" }; + size_t sizeofArray = sizeof(sip_forking_indicationArray) / sizeof(sip_forking_indicationArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(sip_forking_indication, sip_forking_indicationArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; + } + return 0; +} + diff --git a/lib/sbi/openapi/model/sip_forking_indication.h b/lib/sbi/openapi/model/sip_forking_indication.h new file mode 100644 index 000000000..bc0948d13 --- /dev/null +++ b/lib/sbi/openapi/model/sip_forking_indication.h @@ -0,0 +1,31 @@ +/* + * sip_forking_indication.h + * + * + */ + +#ifndef _OpenAPI_sip_forking_indication_H_ +#define _OpenAPI_sip_forking_indication_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { OpenAPI_sip_forking_indication_NULL = 0, OpenAPI_sip_forking_indication_SINGLE_DIALOGUE, OpenAPI_sip_forking_indication_SEVERAL_DIALOGUES } OpenAPI_sip_forking_indication_e; + +char* OpenAPI_sip_forking_indication_ToString(OpenAPI_sip_forking_indication_e sip_forking_indication); + +OpenAPI_sip_forking_indication_e OpenAPI_sip_forking_indication_FromString(char* sip_forking_indication); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_sip_forking_indication_H_ */ + diff --git a/lib/sbi/openapi/model/smf_registration.c b/lib/sbi/openapi/model/smf_registration.c index ceadab258..bc6eed50d 100644 --- a/lib/sbi/openapi/model/smf_registration.c +++ b/lib/sbi/openapi/model/smf_registration.c @@ -17,7 +17,7 @@ OpenAPI_smf_registration_t *OpenAPI_smf_registration_create( char *pgw_fqdn, int epdg_ind, char *dereg_callback_uri, - OpenAPI_registration_reason_t *registration_reason, + OpenAPI_registration_reason_e registration_reason, char *registration_time, OpenAPI_context_info_t *context_info ) @@ -60,7 +60,6 @@ void OpenAPI_smf_registration_free(OpenAPI_smf_registration_t *smf_registration) OpenAPI_plmn_id_free(smf_registration->plmn_id); ogs_free(smf_registration->pgw_fqdn); ogs_free(smf_registration->dereg_callback_uri); - OpenAPI_registration_reason_free(smf_registration->registration_reason); ogs_free(smf_registration->registration_time); OpenAPI_context_info_free(smf_registration->context_info); ogs_free(smf_registration); @@ -165,13 +164,7 @@ cJSON *OpenAPI_smf_registration_convertToJSON(OpenAPI_smf_registration_t *smf_re } if (smf_registration->registration_reason) { - cJSON *registration_reason_local_JSON = OpenAPI_registration_reason_convertToJSON(smf_registration->registration_reason); - if (registration_reason_local_JSON == NULL) { - ogs_error("OpenAPI_smf_registration_convertToJSON() failed [registration_reason]"); - goto end; - } - cJSON_AddItemToObject(item, "registrationReason", registration_reason_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "registrationReason", OpenAPI_registration_reason_ToString(smf_registration->registration_reason)) == NULL) { ogs_error("OpenAPI_smf_registration_convertToJSON() failed [registration_reason]"); goto end; } @@ -322,9 +315,13 @@ OpenAPI_smf_registration_t *OpenAPI_smf_registration_parseFromJSON(cJSON *smf_re cJSON *registration_reason = cJSON_GetObjectItemCaseSensitive(smf_registrationJSON, "registrationReason"); - OpenAPI_registration_reason_t *registration_reason_local_nonprim = NULL; + OpenAPI_registration_reason_e registration_reasonVariable; if (registration_reason) { - registration_reason_local_nonprim = OpenAPI_registration_reason_parseFromJSON(registration_reason); + if (!cJSON_IsString(registration_reason)) { + ogs_error("OpenAPI_smf_registration_parseFromJSON() failed [registration_reason]"); + goto end; + } + registration_reasonVariable = OpenAPI_registration_reason_FromString(registration_reason->valuestring); } cJSON *registration_time = cJSON_GetObjectItemCaseSensitive(smf_registrationJSON, "registrationTime"); @@ -356,7 +353,7 @@ OpenAPI_smf_registration_t *OpenAPI_smf_registration_parseFromJSON(cJSON *smf_re pgw_fqdn ? ogs_strdup(pgw_fqdn->valuestring) : NULL, epdg_ind ? epdg_ind->valueint : 0, dereg_callback_uri ? ogs_strdup(dereg_callback_uri->valuestring) : NULL, - registration_reason ? registration_reason_local_nonprim : NULL, + registration_reason ? registration_reasonVariable : 0, registration_time ? ogs_strdup(registration_time->valuestring) : NULL, context_info ? context_info_local_nonprim : NULL ); diff --git a/lib/sbi/openapi/model/smf_registration.h b/lib/sbi/openapi/model/smf_registration.h index 4769b4dc9..34c20d892 100644 --- a/lib/sbi/openapi/model/smf_registration.h +++ b/lib/sbi/openapi/model/smf_registration.h @@ -35,7 +35,7 @@ typedef struct OpenAPI_smf_registration_s { char *pgw_fqdn; int epdg_ind; char *dereg_callback_uri; - struct OpenAPI_registration_reason_s *registration_reason; + OpenAPI_registration_reason_e registration_reason; char *registration_time; struct OpenAPI_context_info_s *context_info; } OpenAPI_smf_registration_t; @@ -53,7 +53,7 @@ OpenAPI_smf_registration_t *OpenAPI_smf_registration_create( char *pgw_fqdn, int epdg_ind, char *dereg_callback_uri, - OpenAPI_registration_reason_t *registration_reason, + OpenAPI_registration_reason_e registration_reason, char *registration_time, OpenAPI_context_info_t *context_info ); diff --git a/lib/sbi/openapi/model/spatial_validity.c b/lib/sbi/openapi/model/spatial_validity.c new file mode 100644 index 000000000..0664f54a1 --- /dev/null +++ b/lib/sbi/openapi/model/spatial_validity.c @@ -0,0 +1,139 @@ + +#include +#include +#include +#include "spatial_validity.h" + +OpenAPI_spatial_validity_t *OpenAPI_spatial_validity_create( + OpenAPI_list_t* presence_info_list + ) +{ + OpenAPI_spatial_validity_t *spatial_validity_local_var = OpenAPI_malloc(sizeof(OpenAPI_spatial_validity_t)); + if (!spatial_validity_local_var) { + return NULL; + } + spatial_validity_local_var->presence_info_list = presence_info_list; + + return spatial_validity_local_var; +} + +void OpenAPI_spatial_validity_free(OpenAPI_spatial_validity_t *spatial_validity) +{ + if (NULL == spatial_validity) { + return; + } + OpenAPI_lnode_t *node; + OpenAPI_list_for_each(spatial_validity->presence_info_list, node) { + OpenAPI_map_t *localKeyValue = (OpenAPI_map_t*)node->data; + OpenAPI_presence_info_free(localKeyValue->value); + ogs_free(localKeyValue); + } + OpenAPI_list_free(spatial_validity->presence_info_list); + ogs_free(spatial_validity); +} + +cJSON *OpenAPI_spatial_validity_convertToJSON(OpenAPI_spatial_validity_t *spatial_validity) +{ + cJSON *item = NULL; + + if (spatial_validity == NULL) { + ogs_error("OpenAPI_spatial_validity_convertToJSON() failed [SpatialValidity]"); + return NULL; + } + + item = cJSON_CreateObject(); + cJSON *presence_info_list = cJSON_AddObjectToObject(item, "presenceInfoList"); + if (presence_info_list == NULL) { + ogs_error("OpenAPI_spatial_validity_convertToJSON() failed [presence_info_list]"); + goto end; + } + cJSON *localMapObject = presence_info_list; + OpenAPI_lnode_t *presence_info_list_node; + if (spatial_validity->presence_info_list) { + OpenAPI_list_for_each(spatial_validity->presence_info_list, presence_info_list_node) { + OpenAPI_map_t *localKeyValue = (OpenAPI_map_t*)presence_info_list_node->data; + cJSON *itemLocal = OpenAPI_presence_info_convertToJSON(localKeyValue->value); + if (itemLocal == NULL) { + ogs_error("OpenAPI_spatial_validity_convertToJSON() failed [presence_info_list]"); + goto end; + } + cJSON_AddItemToObject(presence_info_list, localKeyValue->key, itemLocal); + } + } + +end: + return item; +} + +OpenAPI_spatial_validity_t *OpenAPI_spatial_validity_parseFromJSON(cJSON *spatial_validityJSON) +{ + OpenAPI_spatial_validity_t *spatial_validity_local_var = NULL; + cJSON *presence_info_list = cJSON_GetObjectItemCaseSensitive(spatial_validityJSON, "presenceInfoList"); + if (!presence_info_list) { + ogs_error("OpenAPI_spatial_validity_parseFromJSON() failed [presence_info_list]"); + goto end; + } + + OpenAPI_list_t *presence_info_listList; + + cJSON *presence_info_list_local_map; + if (!cJSON_IsObject(presence_info_list)) { + ogs_error("OpenAPI_spatial_validity_parseFromJSON() failed [presence_info_list]"); + goto end; + } + presence_info_listList = OpenAPI_list_create(); + OpenAPI_map_t *localMapKeyPair = NULL; + cJSON_ArrayForEach(presence_info_list_local_map, presence_info_list) { + cJSON *localMapObject = presence_info_list_local_map; + if (!cJSON_IsObject(presence_info_list_local_map)) { + ogs_error("OpenAPI_spatial_validity_parseFromJSON() failed [presence_info_list]"); + goto end; + } + localMapKeyPair = OpenAPI_map_create( + localMapObject->string, OpenAPI_presence_info_parseFromJSON(localMapObject)); + OpenAPI_list_add(presence_info_listList, localMapKeyPair); + } + + spatial_validity_local_var = OpenAPI_spatial_validity_create ( + presence_info_listList + ); + + return spatial_validity_local_var; +end: + return NULL; +} + +OpenAPI_spatial_validity_t *OpenAPI_spatial_validity_copy(OpenAPI_spatial_validity_t *dst, OpenAPI_spatial_validity_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_spatial_validity_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_spatial_validity_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_spatial_validity_free(dst); + dst = OpenAPI_spatial_validity_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/spatial_validity.h b/lib/sbi/openapi/model/spatial_validity.h new file mode 100644 index 000000000..a901b598d --- /dev/null +++ b/lib/sbi/openapi/model/spatial_validity.h @@ -0,0 +1,39 @@ +/* + * spatial_validity.h + * + * describes explicitly the route to an Application location + */ + +#ifndef _OpenAPI_spatial_validity_H_ +#define _OpenAPI_spatial_validity_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" +#include "presence_info.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_spatial_validity_s OpenAPI_spatial_validity_t; +typedef struct OpenAPI_spatial_validity_s { + OpenAPI_list_t* presence_info_list; +} OpenAPI_spatial_validity_t; + +OpenAPI_spatial_validity_t *OpenAPI_spatial_validity_create( + OpenAPI_list_t* presence_info_list + ); +void OpenAPI_spatial_validity_free(OpenAPI_spatial_validity_t *spatial_validity); +OpenAPI_spatial_validity_t *OpenAPI_spatial_validity_parseFromJSON(cJSON *spatial_validityJSON); +cJSON *OpenAPI_spatial_validity_convertToJSON(OpenAPI_spatial_validity_t *spatial_validity); +OpenAPI_spatial_validity_t *OpenAPI_spatial_validity_copy(OpenAPI_spatial_validity_t *dst, OpenAPI_spatial_validity_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_spatial_validity_H_ */ + diff --git a/lib/sbi/openapi/model/spatial_validity_rm.c b/lib/sbi/openapi/model/spatial_validity_rm.c new file mode 100644 index 000000000..204f9edc7 --- /dev/null +++ b/lib/sbi/openapi/model/spatial_validity_rm.c @@ -0,0 +1,139 @@ + +#include +#include +#include +#include "spatial_validity_rm.h" + +OpenAPI_spatial_validity_rm_t *OpenAPI_spatial_validity_rm_create( + OpenAPI_list_t* presence_info_list + ) +{ + OpenAPI_spatial_validity_rm_t *spatial_validity_rm_local_var = OpenAPI_malloc(sizeof(OpenAPI_spatial_validity_rm_t)); + if (!spatial_validity_rm_local_var) { + return NULL; + } + spatial_validity_rm_local_var->presence_info_list = presence_info_list; + + return spatial_validity_rm_local_var; +} + +void OpenAPI_spatial_validity_rm_free(OpenAPI_spatial_validity_rm_t *spatial_validity_rm) +{ + if (NULL == spatial_validity_rm) { + return; + } + OpenAPI_lnode_t *node; + OpenAPI_list_for_each(spatial_validity_rm->presence_info_list, node) { + OpenAPI_map_t *localKeyValue = (OpenAPI_map_t*)node->data; + OpenAPI_presence_info_free(localKeyValue->value); + ogs_free(localKeyValue); + } + OpenAPI_list_free(spatial_validity_rm->presence_info_list); + ogs_free(spatial_validity_rm); +} + +cJSON *OpenAPI_spatial_validity_rm_convertToJSON(OpenAPI_spatial_validity_rm_t *spatial_validity_rm) +{ + cJSON *item = NULL; + + if (spatial_validity_rm == NULL) { + ogs_error("OpenAPI_spatial_validity_rm_convertToJSON() failed [SpatialValidityRm]"); + return NULL; + } + + item = cJSON_CreateObject(); + cJSON *presence_info_list = cJSON_AddObjectToObject(item, "presenceInfoList"); + if (presence_info_list == NULL) { + ogs_error("OpenAPI_spatial_validity_rm_convertToJSON() failed [presence_info_list]"); + goto end; + } + cJSON *localMapObject = presence_info_list; + OpenAPI_lnode_t *presence_info_list_node; + if (spatial_validity_rm->presence_info_list) { + OpenAPI_list_for_each(spatial_validity_rm->presence_info_list, presence_info_list_node) { + OpenAPI_map_t *localKeyValue = (OpenAPI_map_t*)presence_info_list_node->data; + cJSON *itemLocal = OpenAPI_presence_info_convertToJSON(localKeyValue->value); + if (itemLocal == NULL) { + ogs_error("OpenAPI_spatial_validity_rm_convertToJSON() failed [presence_info_list]"); + goto end; + } + cJSON_AddItemToObject(presence_info_list, localKeyValue->key, itemLocal); + } + } + +end: + return item; +} + +OpenAPI_spatial_validity_rm_t *OpenAPI_spatial_validity_rm_parseFromJSON(cJSON *spatial_validity_rmJSON) +{ + OpenAPI_spatial_validity_rm_t *spatial_validity_rm_local_var = NULL; + cJSON *presence_info_list = cJSON_GetObjectItemCaseSensitive(spatial_validity_rmJSON, "presenceInfoList"); + if (!presence_info_list) { + ogs_error("OpenAPI_spatial_validity_rm_parseFromJSON() failed [presence_info_list]"); + goto end; + } + + OpenAPI_list_t *presence_info_listList; + + cJSON *presence_info_list_local_map; + if (!cJSON_IsObject(presence_info_list)) { + ogs_error("OpenAPI_spatial_validity_rm_parseFromJSON() failed [presence_info_list]"); + goto end; + } + presence_info_listList = OpenAPI_list_create(); + OpenAPI_map_t *localMapKeyPair = NULL; + cJSON_ArrayForEach(presence_info_list_local_map, presence_info_list) { + cJSON *localMapObject = presence_info_list_local_map; + if (!cJSON_IsObject(presence_info_list_local_map)) { + ogs_error("OpenAPI_spatial_validity_rm_parseFromJSON() failed [presence_info_list]"); + goto end; + } + localMapKeyPair = OpenAPI_map_create( + localMapObject->string, OpenAPI_presence_info_parseFromJSON(localMapObject)); + OpenAPI_list_add(presence_info_listList, localMapKeyPair); + } + + spatial_validity_rm_local_var = OpenAPI_spatial_validity_rm_create ( + presence_info_listList + ); + + return spatial_validity_rm_local_var; +end: + return NULL; +} + +OpenAPI_spatial_validity_rm_t *OpenAPI_spatial_validity_rm_copy(OpenAPI_spatial_validity_rm_t *dst, OpenAPI_spatial_validity_rm_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_spatial_validity_rm_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_spatial_validity_rm_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_spatial_validity_rm_free(dst); + dst = OpenAPI_spatial_validity_rm_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/spatial_validity_rm.h b/lib/sbi/openapi/model/spatial_validity_rm.h new file mode 100644 index 000000000..c14ad9c31 --- /dev/null +++ b/lib/sbi/openapi/model/spatial_validity_rm.h @@ -0,0 +1,39 @@ +/* + * spatial_validity_rm.h + * + * this data type is defined in the same way as the SpatialValidity data type, but with the OpenAPI nullable property set to true + */ + +#ifndef _OpenAPI_spatial_validity_rm_H_ +#define _OpenAPI_spatial_validity_rm_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" +#include "presence_info.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_spatial_validity_rm_s OpenAPI_spatial_validity_rm_t; +typedef struct OpenAPI_spatial_validity_rm_s { + OpenAPI_list_t* presence_info_list; +} OpenAPI_spatial_validity_rm_t; + +OpenAPI_spatial_validity_rm_t *OpenAPI_spatial_validity_rm_create( + OpenAPI_list_t* presence_info_list + ); +void OpenAPI_spatial_validity_rm_free(OpenAPI_spatial_validity_rm_t *spatial_validity_rm); +OpenAPI_spatial_validity_rm_t *OpenAPI_spatial_validity_rm_parseFromJSON(cJSON *spatial_validity_rmJSON); +cJSON *OpenAPI_spatial_validity_rm_convertToJSON(OpenAPI_spatial_validity_rm_t *spatial_validity_rm); +OpenAPI_spatial_validity_rm_t *OpenAPI_spatial_validity_rm_copy(OpenAPI_spatial_validity_rm_t *dst, OpenAPI_spatial_validity_rm_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_spatial_validity_rm_H_ */ + diff --git a/lib/sbi/openapi/model/sponsoring_status.c b/lib/sbi/openapi/model/sponsoring_status.c new file mode 100644 index 000000000..9b2478092 --- /dev/null +++ b/lib/sbi/openapi/model/sponsoring_status.c @@ -0,0 +1,30 @@ + +#include +#include +#include +#include "sponsoring_status.h" + +char* OpenAPI_sponsoring_status_ToString(OpenAPI_sponsoring_status_e sponsoring_status) +{ + const char *sponsoring_statusArray[] = { "NULL", "SPONSOR_DISABLED", "SPONSOR_ENABLED" }; + size_t sizeofArray = sizeof(sponsoring_statusArray) / sizeof(sponsoring_statusArray[0]); + if (sponsoring_status < sizeofArray) + return (char *)sponsoring_statusArray[sponsoring_status]; + else + return (char *)"Unknown"; +} + +OpenAPI_sponsoring_status_e OpenAPI_sponsoring_status_FromString(char* sponsoring_status) +{ + int stringToReturn = 0; + const char *sponsoring_statusArray[] = { "NULL", "SPONSOR_DISABLED", "SPONSOR_ENABLED" }; + size_t sizeofArray = sizeof(sponsoring_statusArray) / sizeof(sponsoring_statusArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(sponsoring_status, sponsoring_statusArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; + } + return 0; +} + diff --git a/lib/sbi/openapi/model/sponsoring_status.h b/lib/sbi/openapi/model/sponsoring_status.h new file mode 100644 index 000000000..4417004d4 --- /dev/null +++ b/lib/sbi/openapi/model/sponsoring_status.h @@ -0,0 +1,31 @@ +/* + * sponsoring_status.h + * + * + */ + +#ifndef _OpenAPI_sponsoring_status_H_ +#define _OpenAPI_sponsoring_status_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { OpenAPI_sponsoring_status_NULL = 0, OpenAPI_sponsoring_status_SPONSOR_DISABLED, OpenAPI_sponsoring_status_SPONSOR_ENABLED } OpenAPI_sponsoring_status_e; + +char* OpenAPI_sponsoring_status_ToString(OpenAPI_sponsoring_status_e sponsoring_status); + +OpenAPI_sponsoring_status_e OpenAPI_sponsoring_status_FromString(char* sponsoring_status); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_sponsoring_status_H_ */ + diff --git a/lib/sbi/openapi/model/termination_cause.c b/lib/sbi/openapi/model/termination_cause.c new file mode 100644 index 000000000..abfb0e1f2 --- /dev/null +++ b/lib/sbi/openapi/model/termination_cause.c @@ -0,0 +1,30 @@ + +#include +#include +#include +#include "termination_cause.h" + +char* OpenAPI_termination_cause_ToString(OpenAPI_termination_cause_e termination_cause) +{ + const char *termination_causeArray[] = { "NULL", "ALL_SDF_DEACTIVATION", "PDU_SESSION_TERMINATION", "PS_TO_CS_HO" }; + size_t sizeofArray = sizeof(termination_causeArray) / sizeof(termination_causeArray[0]); + if (termination_cause < sizeofArray) + return (char *)termination_causeArray[termination_cause]; + else + return (char *)"Unknown"; +} + +OpenAPI_termination_cause_e OpenAPI_termination_cause_FromString(char* termination_cause) +{ + int stringToReturn = 0; + const char *termination_causeArray[] = { "NULL", "ALL_SDF_DEACTIVATION", "PDU_SESSION_TERMINATION", "PS_TO_CS_HO" }; + size_t sizeofArray = sizeof(termination_causeArray) / sizeof(termination_causeArray[0]); + while (stringToReturn < sizeofArray) { + if (strcmp(termination_cause, termination_causeArray[stringToReturn]) == 0) { + return stringToReturn; + } + stringToReturn++; + } + return 0; +} + diff --git a/lib/sbi/openapi/model/termination_cause.h b/lib/sbi/openapi/model/termination_cause.h new file mode 100644 index 000000000..a27b05129 --- /dev/null +++ b/lib/sbi/openapi/model/termination_cause.h @@ -0,0 +1,31 @@ +/* + * termination_cause.h + * + * + */ + +#ifndef _OpenAPI_termination_cause_H_ +#define _OpenAPI_termination_cause_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { OpenAPI_termination_cause_NULL = 0, OpenAPI_termination_cause_ALL_SDF_DEACTIVATION, OpenAPI_termination_cause_PDU_SESSION_TERMINATION, OpenAPI_termination_cause_PS_TO_CS_HO } OpenAPI_termination_cause_e; + +char* OpenAPI_termination_cause_ToString(OpenAPI_termination_cause_e termination_cause); + +OpenAPI_termination_cause_e OpenAPI_termination_cause_FromString(char* termination_cause); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_termination_cause_H_ */ + diff --git a/lib/sbi/openapi/model/termination_info.c b/lib/sbi/openapi/model/termination_info.c new file mode 100644 index 000000000..fd3581f52 --- /dev/null +++ b/lib/sbi/openapi/model/termination_info.c @@ -0,0 +1,128 @@ + +#include +#include +#include +#include "termination_info.h" + +OpenAPI_termination_info_t *OpenAPI_termination_info_create( + OpenAPI_termination_cause_e term_cause, + char *res_uri + ) +{ + OpenAPI_termination_info_t *termination_info_local_var = OpenAPI_malloc(sizeof(OpenAPI_termination_info_t)); + if (!termination_info_local_var) { + return NULL; + } + termination_info_local_var->term_cause = term_cause; + termination_info_local_var->res_uri = res_uri; + + return termination_info_local_var; +} + +void OpenAPI_termination_info_free(OpenAPI_termination_info_t *termination_info) +{ + if (NULL == termination_info) { + return; + } + OpenAPI_lnode_t *node; + ogs_free(termination_info->res_uri); + ogs_free(termination_info); +} + +cJSON *OpenAPI_termination_info_convertToJSON(OpenAPI_termination_info_t *termination_info) +{ + cJSON *item = NULL; + + if (termination_info == NULL) { + ogs_error("OpenAPI_termination_info_convertToJSON() failed [TerminationInfo]"); + return NULL; + } + + item = cJSON_CreateObject(); + if (cJSON_AddStringToObject(item, "termCause", OpenAPI_termination_cause_ToString(termination_info->term_cause)) == NULL) { + ogs_error("OpenAPI_termination_info_convertToJSON() failed [term_cause]"); + goto end; + } + + if (cJSON_AddStringToObject(item, "resUri", termination_info->res_uri) == NULL) { + ogs_error("OpenAPI_termination_info_convertToJSON() failed [res_uri]"); + goto end; + } + +end: + return item; +} + +OpenAPI_termination_info_t *OpenAPI_termination_info_parseFromJSON(cJSON *termination_infoJSON) +{ + OpenAPI_termination_info_t *termination_info_local_var = NULL; + cJSON *term_cause = cJSON_GetObjectItemCaseSensitive(termination_infoJSON, "termCause"); + if (!term_cause) { + ogs_error("OpenAPI_termination_info_parseFromJSON() failed [term_cause]"); + goto end; + } + + OpenAPI_termination_cause_e term_causeVariable; + + if (!cJSON_IsString(term_cause)) { + ogs_error("OpenAPI_termination_info_parseFromJSON() failed [term_cause]"); + goto end; + } + term_causeVariable = OpenAPI_termination_cause_FromString(term_cause->valuestring); + + cJSON *res_uri = cJSON_GetObjectItemCaseSensitive(termination_infoJSON, "resUri"); + if (!res_uri) { + ogs_error("OpenAPI_termination_info_parseFromJSON() failed [res_uri]"); + goto end; + } + + + if (!cJSON_IsString(res_uri)) { + ogs_error("OpenAPI_termination_info_parseFromJSON() failed [res_uri]"); + goto end; + } + + termination_info_local_var = OpenAPI_termination_info_create ( + term_causeVariable, + ogs_strdup(res_uri->valuestring) + ); + + return termination_info_local_var; +end: + return NULL; +} + +OpenAPI_termination_info_t *OpenAPI_termination_info_copy(OpenAPI_termination_info_t *dst, OpenAPI_termination_info_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_termination_info_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_termination_info_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_termination_info_free(dst); + dst = OpenAPI_termination_info_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/termination_info.h b/lib/sbi/openapi/model/termination_info.h new file mode 100644 index 000000000..427803954 --- /dev/null +++ b/lib/sbi/openapi/model/termination_info.h @@ -0,0 +1,41 @@ +/* + * termination_info.h + * + * indicates the cause for requesting the deletion of the Individual Application Session Context resource + */ + +#ifndef _OpenAPI_termination_info_H_ +#define _OpenAPI_termination_info_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" +#include "termination_cause.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_termination_info_s OpenAPI_termination_info_t; +typedef struct OpenAPI_termination_info_s { + OpenAPI_termination_cause_e term_cause; + char *res_uri; +} OpenAPI_termination_info_t; + +OpenAPI_termination_info_t *OpenAPI_termination_info_create( + OpenAPI_termination_cause_e term_cause, + char *res_uri + ); +void OpenAPI_termination_info_free(OpenAPI_termination_info_t *termination_info); +OpenAPI_termination_info_t *OpenAPI_termination_info_parseFromJSON(cJSON *termination_infoJSON); +cJSON *OpenAPI_termination_info_convertToJSON(OpenAPI_termination_info_t *termination_info); +OpenAPI_termination_info_t *OpenAPI_termination_info_copy(OpenAPI_termination_info_t *dst, OpenAPI_termination_info_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_termination_info_H_ */ + diff --git a/lib/sbi/openapi/model/traffic_control_data.c b/lib/sbi/openapi/model/traffic_control_data.c index c02396250..2240ef8e4 100644 --- a/lib/sbi/openapi/model/traffic_control_data.c +++ b/lib/sbi/openapi/model/traffic_control_data.c @@ -6,7 +6,7 @@ OpenAPI_traffic_control_data_t *OpenAPI_traffic_control_data_create( char *tc_id, - OpenAPI_flow_status_t *flow_status, + OpenAPI_flow_status_e flow_status, OpenAPI_redirect_information_t *redirect_info, OpenAPI_list_t *add_redirect_info, int mute_notif, @@ -50,7 +50,6 @@ void OpenAPI_traffic_control_data_free(OpenAPI_traffic_control_data_t *traffic_c } OpenAPI_lnode_t *node; ogs_free(traffic_control_data->tc_id); - OpenAPI_flow_status_free(traffic_control_data->flow_status); OpenAPI_redirect_information_free(traffic_control_data->redirect_info); OpenAPI_list_for_each(traffic_control_data->add_redirect_info, node) { OpenAPI_redirect_information_free(node->data); @@ -85,13 +84,7 @@ cJSON *OpenAPI_traffic_control_data_convertToJSON(OpenAPI_traffic_control_data_t } if (traffic_control_data->flow_status) { - cJSON *flow_status_local_JSON = OpenAPI_flow_status_convertToJSON(traffic_control_data->flow_status); - if (flow_status_local_JSON == NULL) { - ogs_error("OpenAPI_traffic_control_data_convertToJSON() failed [flow_status]"); - goto end; - } - cJSON_AddItemToObject(item, "flowStatus", flow_status_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "flowStatus", OpenAPI_flow_status_ToString(traffic_control_data->flow_status)) == NULL) { ogs_error("OpenAPI_traffic_control_data_convertToJSON() failed [flow_status]"); goto end; } @@ -258,9 +251,13 @@ OpenAPI_traffic_control_data_t *OpenAPI_traffic_control_data_parseFromJSON(cJSON cJSON *flow_status = cJSON_GetObjectItemCaseSensitive(traffic_control_dataJSON, "flowStatus"); - OpenAPI_flow_status_t *flow_status_local_nonprim = NULL; + OpenAPI_flow_status_e flow_statusVariable; if (flow_status) { - flow_status_local_nonprim = OpenAPI_flow_status_parseFromJSON(flow_status); + if (!cJSON_IsString(flow_status)) { + ogs_error("OpenAPI_traffic_control_data_parseFromJSON() failed [flow_status]"); + goto end; + } + flow_statusVariable = OpenAPI_flow_status_FromString(flow_status->valuestring); } cJSON *redirect_info = cJSON_GetObjectItemCaseSensitive(traffic_control_dataJSON, "redirectInfo"); @@ -393,7 +390,7 @@ OpenAPI_traffic_control_data_t *OpenAPI_traffic_control_data_parseFromJSON(cJSON traffic_control_data_local_var = OpenAPI_traffic_control_data_create ( ogs_strdup(tc_id->valuestring), - flow_status ? flow_status_local_nonprim : NULL, + flow_status ? flow_statusVariable : 0, redirect_info ? redirect_info_local_nonprim : NULL, add_redirect_info ? add_redirect_infoList : NULL, mute_notif ? mute_notif->valueint : 0, diff --git a/lib/sbi/openapi/model/traffic_control_data.h b/lib/sbi/openapi/model/traffic_control_data.h index 499be1629..68e5acb59 100644 --- a/lib/sbi/openapi/model/traffic_control_data.h +++ b/lib/sbi/openapi/model/traffic_control_data.h @@ -27,7 +27,7 @@ extern "C" { typedef struct OpenAPI_traffic_control_data_s OpenAPI_traffic_control_data_t; typedef struct OpenAPI_traffic_control_data_s { char *tc_id; - struct OpenAPI_flow_status_s *flow_status; + OpenAPI_flow_status_e flow_status; struct OpenAPI_redirect_information_s *redirect_info; OpenAPI_list_t *add_redirect_info; int mute_notif; @@ -44,7 +44,7 @@ typedef struct OpenAPI_traffic_control_data_s { OpenAPI_traffic_control_data_t *OpenAPI_traffic_control_data_create( char *tc_id, - OpenAPI_flow_status_t *flow_status, + OpenAPI_flow_status_e flow_status, OpenAPI_redirect_information_t *redirect_info, OpenAPI_list_t *add_redirect_info, int mute_notif, diff --git a/lib/sbi/openapi/model/traffic_influ_data.c b/lib/sbi/openapi/model/traffic_influ_data.c index 22cce92cb..70c1b3414 100644 --- a/lib/sbi/openapi/model/traffic_influ_data.c +++ b/lib/sbi/openapi/model/traffic_influ_data.c @@ -22,7 +22,7 @@ OpenAPI_traffic_influ_data_t *OpenAPI_traffic_influ_data_create( OpenAPI_network_area_info_2_t *nw_area_info, char *up_path_chg_notif_uri, OpenAPI_list_t *subscribed_events, - OpenAPI_dnai_change_type_t *dnai_chg_type, + OpenAPI_dnai_change_type_e dnai_chg_type, int af_ack_ind, int addr_preser_ind, char *supported_features @@ -93,7 +93,6 @@ void OpenAPI_traffic_influ_data_free(OpenAPI_traffic_influ_data_t *traffic_influ OpenAPI_subscribed_event_free(node->data); } OpenAPI_list_free(traffic_influ_data->subscribed_events); - OpenAPI_dnai_change_type_free(traffic_influ_data->dnai_chg_type); ogs_free(traffic_influ_data->supported_features); ogs_free(traffic_influ_data); } @@ -305,13 +304,7 @@ cJSON *OpenAPI_traffic_influ_data_convertToJSON(OpenAPI_traffic_influ_data_t *tr } if (traffic_influ_data->dnai_chg_type) { - cJSON *dnai_chg_type_local_JSON = OpenAPI_dnai_change_type_convertToJSON(traffic_influ_data->dnai_chg_type); - if (dnai_chg_type_local_JSON == NULL) { - ogs_error("OpenAPI_traffic_influ_data_convertToJSON() failed [dnai_chg_type]"); - goto end; - } - cJSON_AddItemToObject(item, "dnaiChgType", dnai_chg_type_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "dnaiChgType", OpenAPI_dnai_change_type_ToString(traffic_influ_data->dnai_chg_type)) == NULL) { ogs_error("OpenAPI_traffic_influ_data_convertToJSON() failed [dnai_chg_type]"); goto end; } @@ -566,9 +559,13 @@ OpenAPI_traffic_influ_data_t *OpenAPI_traffic_influ_data_parseFromJSON(cJSON *tr cJSON *dnai_chg_type = cJSON_GetObjectItemCaseSensitive(traffic_influ_dataJSON, "dnaiChgType"); - OpenAPI_dnai_change_type_t *dnai_chg_type_local_nonprim = NULL; + OpenAPI_dnai_change_type_e dnai_chg_typeVariable; if (dnai_chg_type) { - dnai_chg_type_local_nonprim = OpenAPI_dnai_change_type_parseFromJSON(dnai_chg_type); + if (!cJSON_IsString(dnai_chg_type)) { + ogs_error("OpenAPI_traffic_influ_data_parseFromJSON() failed [dnai_chg_type]"); + goto end; + } + dnai_chg_typeVariable = OpenAPI_dnai_change_type_FromString(dnai_chg_type->valuestring); } cJSON *af_ack_ind = cJSON_GetObjectItemCaseSensitive(traffic_influ_dataJSON, "afAckInd"); @@ -616,7 +613,7 @@ OpenAPI_traffic_influ_data_t *OpenAPI_traffic_influ_data_parseFromJSON(cJSON *tr nw_area_info ? nw_area_info_local_nonprim : NULL, up_path_chg_notif_uri ? ogs_strdup(up_path_chg_notif_uri->valuestring) : NULL, subscribed_events ? subscribed_eventsList : NULL, - dnai_chg_type ? dnai_chg_type_local_nonprim : NULL, + dnai_chg_type ? dnai_chg_typeVariable : 0, af_ack_ind ? af_ack_ind->valueint : 0, addr_preser_ind ? addr_preser_ind->valueint : 0, supported_features ? ogs_strdup(supported_features->valuestring) : NULL diff --git a/lib/sbi/openapi/model/traffic_influ_data.h b/lib/sbi/openapi/model/traffic_influ_data.h index 4cc7d0d46..c176aece6 100644 --- a/lib/sbi/openapi/model/traffic_influ_data.h +++ b/lib/sbi/openapi/model/traffic_influ_data.h @@ -44,7 +44,7 @@ typedef struct OpenAPI_traffic_influ_data_s { struct OpenAPI_network_area_info_2_s *nw_area_info; char *up_path_chg_notif_uri; OpenAPI_list_t *subscribed_events; - struct OpenAPI_dnai_change_type_s *dnai_chg_type; + OpenAPI_dnai_change_type_e dnai_chg_type; int af_ack_ind; int addr_preser_ind; char *supported_features; @@ -68,7 +68,7 @@ OpenAPI_traffic_influ_data_t *OpenAPI_traffic_influ_data_create( OpenAPI_network_area_info_2_t *nw_area_info, char *up_path_chg_notif_uri, OpenAPI_list_t *subscribed_events, - OpenAPI_dnai_change_type_t *dnai_chg_type, + OpenAPI_dnai_change_type_e dnai_chg_type, int af_ack_ind, int addr_preser_ind, char *supported_features diff --git a/lib/sbi/openapi/model/tsn_qos_container.c b/lib/sbi/openapi/model/tsn_qos_container.c new file mode 100644 index 000000000..94610ee50 --- /dev/null +++ b/lib/sbi/openapi/model/tsn_qos_container.c @@ -0,0 +1,142 @@ + +#include +#include +#include +#include "tsn_qos_container.h" + +OpenAPI_tsn_qos_container_t *OpenAPI_tsn_qos_container_create( + int max_tsc_burst_size, + int tsc_pack_delay, + int tsc_prio_level + ) +{ + OpenAPI_tsn_qos_container_t *tsn_qos_container_local_var = OpenAPI_malloc(sizeof(OpenAPI_tsn_qos_container_t)); + if (!tsn_qos_container_local_var) { + return NULL; + } + tsn_qos_container_local_var->max_tsc_burst_size = max_tsc_burst_size; + tsn_qos_container_local_var->tsc_pack_delay = tsc_pack_delay; + tsn_qos_container_local_var->tsc_prio_level = tsc_prio_level; + + return tsn_qos_container_local_var; +} + +void OpenAPI_tsn_qos_container_free(OpenAPI_tsn_qos_container_t *tsn_qos_container) +{ + if (NULL == tsn_qos_container) { + return; + } + OpenAPI_lnode_t *node; + ogs_free(tsn_qos_container); +} + +cJSON *OpenAPI_tsn_qos_container_convertToJSON(OpenAPI_tsn_qos_container_t *tsn_qos_container) +{ + cJSON *item = NULL; + + if (tsn_qos_container == NULL) { + ogs_error("OpenAPI_tsn_qos_container_convertToJSON() failed [TsnQosContainer]"); + return NULL; + } + + item = cJSON_CreateObject(); + if (tsn_qos_container->max_tsc_burst_size) { + if (cJSON_AddNumberToObject(item, "maxTscBurstSize", tsn_qos_container->max_tsc_burst_size) == NULL) { + ogs_error("OpenAPI_tsn_qos_container_convertToJSON() failed [max_tsc_burst_size]"); + goto end; + } + } + + if (tsn_qos_container->tsc_pack_delay) { + if (cJSON_AddNumberToObject(item, "tscPackDelay", tsn_qos_container->tsc_pack_delay) == NULL) { + ogs_error("OpenAPI_tsn_qos_container_convertToJSON() failed [tsc_pack_delay]"); + goto end; + } + } + + if (tsn_qos_container->tsc_prio_level) { + if (cJSON_AddNumberToObject(item, "tscPrioLevel", tsn_qos_container->tsc_prio_level) == NULL) { + ogs_error("OpenAPI_tsn_qos_container_convertToJSON() failed [tsc_prio_level]"); + goto end; + } + } + +end: + return item; +} + +OpenAPI_tsn_qos_container_t *OpenAPI_tsn_qos_container_parseFromJSON(cJSON *tsn_qos_containerJSON) +{ + OpenAPI_tsn_qos_container_t *tsn_qos_container_local_var = NULL; + cJSON *max_tsc_burst_size = cJSON_GetObjectItemCaseSensitive(tsn_qos_containerJSON, "maxTscBurstSize"); + + if (max_tsc_burst_size) { + if (!cJSON_IsNumber(max_tsc_burst_size)) { + ogs_error("OpenAPI_tsn_qos_container_parseFromJSON() failed [max_tsc_burst_size]"); + goto end; + } + } + + cJSON *tsc_pack_delay = cJSON_GetObjectItemCaseSensitive(tsn_qos_containerJSON, "tscPackDelay"); + + if (tsc_pack_delay) { + if (!cJSON_IsNumber(tsc_pack_delay)) { + ogs_error("OpenAPI_tsn_qos_container_parseFromJSON() failed [tsc_pack_delay]"); + goto end; + } + } + + cJSON *tsc_prio_level = cJSON_GetObjectItemCaseSensitive(tsn_qos_containerJSON, "tscPrioLevel"); + + if (tsc_prio_level) { + if (!cJSON_IsNumber(tsc_prio_level)) { + ogs_error("OpenAPI_tsn_qos_container_parseFromJSON() failed [tsc_prio_level]"); + goto end; + } + } + + tsn_qos_container_local_var = OpenAPI_tsn_qos_container_create ( + max_tsc_burst_size ? max_tsc_burst_size->valuedouble : 0, + tsc_pack_delay ? tsc_pack_delay->valuedouble : 0, + tsc_prio_level ? tsc_prio_level->valuedouble : 0 + ); + + return tsn_qos_container_local_var; +end: + return NULL; +} + +OpenAPI_tsn_qos_container_t *OpenAPI_tsn_qos_container_copy(OpenAPI_tsn_qos_container_t *dst, OpenAPI_tsn_qos_container_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_tsn_qos_container_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_tsn_qos_container_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_tsn_qos_container_free(dst); + dst = OpenAPI_tsn_qos_container_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/tsn_qos_container.h b/lib/sbi/openapi/model/tsn_qos_container.h new file mode 100644 index 000000000..3763036aa --- /dev/null +++ b/lib/sbi/openapi/model/tsn_qos_container.h @@ -0,0 +1,42 @@ +/* + * tsn_qos_container.h + * + * Indicates TSC Traffic QoS. + */ + +#ifndef _OpenAPI_tsn_qos_container_H_ +#define _OpenAPI_tsn_qos_container_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_tsn_qos_container_s OpenAPI_tsn_qos_container_t; +typedef struct OpenAPI_tsn_qos_container_s { + int max_tsc_burst_size; + int tsc_pack_delay; + int tsc_prio_level; +} OpenAPI_tsn_qos_container_t; + +OpenAPI_tsn_qos_container_t *OpenAPI_tsn_qos_container_create( + int max_tsc_burst_size, + int tsc_pack_delay, + int tsc_prio_level + ); +void OpenAPI_tsn_qos_container_free(OpenAPI_tsn_qos_container_t *tsn_qos_container); +OpenAPI_tsn_qos_container_t *OpenAPI_tsn_qos_container_parseFromJSON(cJSON *tsn_qos_containerJSON); +cJSON *OpenAPI_tsn_qos_container_convertToJSON(OpenAPI_tsn_qos_container_t *tsn_qos_container); +OpenAPI_tsn_qos_container_t *OpenAPI_tsn_qos_container_copy(OpenAPI_tsn_qos_container_t *dst, OpenAPI_tsn_qos_container_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_tsn_qos_container_H_ */ + diff --git a/lib/sbi/openapi/model/tsn_qos_container_rm.c b/lib/sbi/openapi/model/tsn_qos_container_rm.c new file mode 100644 index 000000000..bae4b4140 --- /dev/null +++ b/lib/sbi/openapi/model/tsn_qos_container_rm.c @@ -0,0 +1,142 @@ + +#include +#include +#include +#include "tsn_qos_container_rm.h" + +OpenAPI_tsn_qos_container_rm_t *OpenAPI_tsn_qos_container_rm_create( + int max_tsc_burst_size, + int tsc_pack_delay, + int tsc_prio_level + ) +{ + OpenAPI_tsn_qos_container_rm_t *tsn_qos_container_rm_local_var = OpenAPI_malloc(sizeof(OpenAPI_tsn_qos_container_rm_t)); + if (!tsn_qos_container_rm_local_var) { + return NULL; + } + tsn_qos_container_rm_local_var->max_tsc_burst_size = max_tsc_burst_size; + tsn_qos_container_rm_local_var->tsc_pack_delay = tsc_pack_delay; + tsn_qos_container_rm_local_var->tsc_prio_level = tsc_prio_level; + + return tsn_qos_container_rm_local_var; +} + +void OpenAPI_tsn_qos_container_rm_free(OpenAPI_tsn_qos_container_rm_t *tsn_qos_container_rm) +{ + if (NULL == tsn_qos_container_rm) { + return; + } + OpenAPI_lnode_t *node; + ogs_free(tsn_qos_container_rm); +} + +cJSON *OpenAPI_tsn_qos_container_rm_convertToJSON(OpenAPI_tsn_qos_container_rm_t *tsn_qos_container_rm) +{ + cJSON *item = NULL; + + if (tsn_qos_container_rm == NULL) { + ogs_error("OpenAPI_tsn_qos_container_rm_convertToJSON() failed [TsnQosContainerRm]"); + return NULL; + } + + item = cJSON_CreateObject(); + if (tsn_qos_container_rm->max_tsc_burst_size) { + if (cJSON_AddNumberToObject(item, "maxTscBurstSize", tsn_qos_container_rm->max_tsc_burst_size) == NULL) { + ogs_error("OpenAPI_tsn_qos_container_rm_convertToJSON() failed [max_tsc_burst_size]"); + goto end; + } + } + + if (tsn_qos_container_rm->tsc_pack_delay) { + if (cJSON_AddNumberToObject(item, "tscPackDelay", tsn_qos_container_rm->tsc_pack_delay) == NULL) { + ogs_error("OpenAPI_tsn_qos_container_rm_convertToJSON() failed [tsc_pack_delay]"); + goto end; + } + } + + if (tsn_qos_container_rm->tsc_prio_level) { + if (cJSON_AddNumberToObject(item, "tscPrioLevel", tsn_qos_container_rm->tsc_prio_level) == NULL) { + ogs_error("OpenAPI_tsn_qos_container_rm_convertToJSON() failed [tsc_prio_level]"); + goto end; + } + } + +end: + return item; +} + +OpenAPI_tsn_qos_container_rm_t *OpenAPI_tsn_qos_container_rm_parseFromJSON(cJSON *tsn_qos_container_rmJSON) +{ + OpenAPI_tsn_qos_container_rm_t *tsn_qos_container_rm_local_var = NULL; + cJSON *max_tsc_burst_size = cJSON_GetObjectItemCaseSensitive(tsn_qos_container_rmJSON, "maxTscBurstSize"); + + if (max_tsc_burst_size) { + if (!cJSON_IsNumber(max_tsc_burst_size)) { + ogs_error("OpenAPI_tsn_qos_container_rm_parseFromJSON() failed [max_tsc_burst_size]"); + goto end; + } + } + + cJSON *tsc_pack_delay = cJSON_GetObjectItemCaseSensitive(tsn_qos_container_rmJSON, "tscPackDelay"); + + if (tsc_pack_delay) { + if (!cJSON_IsNumber(tsc_pack_delay)) { + ogs_error("OpenAPI_tsn_qos_container_rm_parseFromJSON() failed [tsc_pack_delay]"); + goto end; + } + } + + cJSON *tsc_prio_level = cJSON_GetObjectItemCaseSensitive(tsn_qos_container_rmJSON, "tscPrioLevel"); + + if (tsc_prio_level) { + if (!cJSON_IsNumber(tsc_prio_level)) { + ogs_error("OpenAPI_tsn_qos_container_rm_parseFromJSON() failed [tsc_prio_level]"); + goto end; + } + } + + tsn_qos_container_rm_local_var = OpenAPI_tsn_qos_container_rm_create ( + max_tsc_burst_size ? max_tsc_burst_size->valuedouble : 0, + tsc_pack_delay ? tsc_pack_delay->valuedouble : 0, + tsc_prio_level ? tsc_prio_level->valuedouble : 0 + ); + + return tsn_qos_container_rm_local_var; +end: + return NULL; +} + +OpenAPI_tsn_qos_container_rm_t *OpenAPI_tsn_qos_container_rm_copy(OpenAPI_tsn_qos_container_rm_t *dst, OpenAPI_tsn_qos_container_rm_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_tsn_qos_container_rm_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_tsn_qos_container_rm_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_tsn_qos_container_rm_free(dst); + dst = OpenAPI_tsn_qos_container_rm_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/tsn_qos_container_rm.h b/lib/sbi/openapi/model/tsn_qos_container_rm.h new file mode 100644 index 000000000..6c62973f0 --- /dev/null +++ b/lib/sbi/openapi/model/tsn_qos_container_rm.h @@ -0,0 +1,42 @@ +/* + * tsn_qos_container_rm.h + * + * Indicates removable TSC Traffic QoS. + */ + +#ifndef _OpenAPI_tsn_qos_container_rm_H_ +#define _OpenAPI_tsn_qos_container_rm_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_tsn_qos_container_rm_s OpenAPI_tsn_qos_container_rm_t; +typedef struct OpenAPI_tsn_qos_container_rm_s { + int max_tsc_burst_size; + int tsc_pack_delay; + int tsc_prio_level; +} OpenAPI_tsn_qos_container_rm_t; + +OpenAPI_tsn_qos_container_rm_t *OpenAPI_tsn_qos_container_rm_create( + int max_tsc_burst_size, + int tsc_pack_delay, + int tsc_prio_level + ); +void OpenAPI_tsn_qos_container_rm_free(OpenAPI_tsn_qos_container_rm_t *tsn_qos_container_rm); +OpenAPI_tsn_qos_container_rm_t *OpenAPI_tsn_qos_container_rm_parseFromJSON(cJSON *tsn_qos_container_rmJSON); +cJSON *OpenAPI_tsn_qos_container_rm_convertToJSON(OpenAPI_tsn_qos_container_rm_t *tsn_qos_container_rm); +OpenAPI_tsn_qos_container_rm_t *OpenAPI_tsn_qos_container_rm_copy(OpenAPI_tsn_qos_container_rm_t *dst, OpenAPI_tsn_qos_container_rm_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_tsn_qos_container_rm_H_ */ + diff --git a/lib/sbi/openapi/model/ue_identity_info.c b/lib/sbi/openapi/model/ue_identity_info.c new file mode 100644 index 000000000..6b1ff0551 --- /dev/null +++ b/lib/sbi/openapi/model/ue_identity_info.c @@ -0,0 +1,145 @@ + +#include +#include +#include +#include "ue_identity_info.h" + +OpenAPI_ue_identity_info_t *OpenAPI_ue_identity_info_create( + char *gpsi, + char *pei, + char *supi + ) +{ + OpenAPI_ue_identity_info_t *ue_identity_info_local_var = OpenAPI_malloc(sizeof(OpenAPI_ue_identity_info_t)); + if (!ue_identity_info_local_var) { + return NULL; + } + ue_identity_info_local_var->gpsi = gpsi; + ue_identity_info_local_var->pei = pei; + ue_identity_info_local_var->supi = supi; + + return ue_identity_info_local_var; +} + +void OpenAPI_ue_identity_info_free(OpenAPI_ue_identity_info_t *ue_identity_info) +{ + if (NULL == ue_identity_info) { + return; + } + OpenAPI_lnode_t *node; + ogs_free(ue_identity_info->gpsi); + ogs_free(ue_identity_info->pei); + ogs_free(ue_identity_info->supi); + ogs_free(ue_identity_info); +} + +cJSON *OpenAPI_ue_identity_info_convertToJSON(OpenAPI_ue_identity_info_t *ue_identity_info) +{ + cJSON *item = NULL; + + if (ue_identity_info == NULL) { + ogs_error("OpenAPI_ue_identity_info_convertToJSON() failed [UeIdentityInfo]"); + return NULL; + } + + item = cJSON_CreateObject(); + if (ue_identity_info->gpsi) { + if (cJSON_AddStringToObject(item, "gpsi", ue_identity_info->gpsi) == NULL) { + ogs_error("OpenAPI_ue_identity_info_convertToJSON() failed [gpsi]"); + goto end; + } + } + + if (ue_identity_info->pei) { + if (cJSON_AddStringToObject(item, "pei", ue_identity_info->pei) == NULL) { + ogs_error("OpenAPI_ue_identity_info_convertToJSON() failed [pei]"); + goto end; + } + } + + if (ue_identity_info->supi) { + if (cJSON_AddStringToObject(item, "supi", ue_identity_info->supi) == NULL) { + ogs_error("OpenAPI_ue_identity_info_convertToJSON() failed [supi]"); + goto end; + } + } + +end: + return item; +} + +OpenAPI_ue_identity_info_t *OpenAPI_ue_identity_info_parseFromJSON(cJSON *ue_identity_infoJSON) +{ + OpenAPI_ue_identity_info_t *ue_identity_info_local_var = NULL; + cJSON *gpsi = cJSON_GetObjectItemCaseSensitive(ue_identity_infoJSON, "gpsi"); + + if (gpsi) { + if (!cJSON_IsString(gpsi)) { + ogs_error("OpenAPI_ue_identity_info_parseFromJSON() failed [gpsi]"); + goto end; + } + } + + cJSON *pei = cJSON_GetObjectItemCaseSensitive(ue_identity_infoJSON, "pei"); + + if (pei) { + if (!cJSON_IsString(pei)) { + ogs_error("OpenAPI_ue_identity_info_parseFromJSON() failed [pei]"); + goto end; + } + } + + cJSON *supi = cJSON_GetObjectItemCaseSensitive(ue_identity_infoJSON, "supi"); + + if (supi) { + if (!cJSON_IsString(supi)) { + ogs_error("OpenAPI_ue_identity_info_parseFromJSON() failed [supi]"); + goto end; + } + } + + ue_identity_info_local_var = OpenAPI_ue_identity_info_create ( + gpsi ? ogs_strdup(gpsi->valuestring) : NULL, + pei ? ogs_strdup(pei->valuestring) : NULL, + supi ? ogs_strdup(supi->valuestring) : NULL + ); + + return ue_identity_info_local_var; +end: + return NULL; +} + +OpenAPI_ue_identity_info_t *OpenAPI_ue_identity_info_copy(OpenAPI_ue_identity_info_t *dst, OpenAPI_ue_identity_info_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_ue_identity_info_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_ue_identity_info_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_ue_identity_info_free(dst); + dst = OpenAPI_ue_identity_info_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/ue_identity_info.h b/lib/sbi/openapi/model/ue_identity_info.h new file mode 100644 index 000000000..f037727eb --- /dev/null +++ b/lib/sbi/openapi/model/ue_identity_info.h @@ -0,0 +1,42 @@ +/* + * ue_identity_info.h + * + * Represents 5GS-Level UE identities. + */ + +#ifndef _OpenAPI_ue_identity_info_H_ +#define _OpenAPI_ue_identity_info_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_ue_identity_info_s OpenAPI_ue_identity_info_t; +typedef struct OpenAPI_ue_identity_info_s { + char *gpsi; + char *pei; + char *supi; +} OpenAPI_ue_identity_info_t; + +OpenAPI_ue_identity_info_t *OpenAPI_ue_identity_info_create( + char *gpsi, + char *pei, + char *supi + ); +void OpenAPI_ue_identity_info_free(OpenAPI_ue_identity_info_t *ue_identity_info); +OpenAPI_ue_identity_info_t *OpenAPI_ue_identity_info_parseFromJSON(cJSON *ue_identity_infoJSON); +cJSON *OpenAPI_ue_identity_info_convertToJSON(OpenAPI_ue_identity_info_t *ue_identity_info); +OpenAPI_ue_identity_info_t *OpenAPI_ue_identity_info_copy(OpenAPI_ue_identity_info_t *dst, OpenAPI_ue_identity_info_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_ue_identity_info_H_ */ + diff --git a/lib/sbi/openapi/model/up_path_chg_event.c b/lib/sbi/openapi/model/up_path_chg_event.c index f37f6c9bb..73edde50e 100644 --- a/lib/sbi/openapi/model/up_path_chg_event.c +++ b/lib/sbi/openapi/model/up_path_chg_event.c @@ -7,7 +7,7 @@ OpenAPI_up_path_chg_event_t *OpenAPI_up_path_chg_event_create( char *notification_uri, char *notif_corre_id, - OpenAPI_dnai_change_type_t *dnai_chg_type, + OpenAPI_dnai_change_type_e dnai_chg_type, int af_ack_ind ) { @@ -31,7 +31,6 @@ void OpenAPI_up_path_chg_event_free(OpenAPI_up_path_chg_event_t *up_path_chg_eve OpenAPI_lnode_t *node; ogs_free(up_path_chg_event->notification_uri); ogs_free(up_path_chg_event->notif_corre_id); - OpenAPI_dnai_change_type_free(up_path_chg_event->dnai_chg_type); ogs_free(up_path_chg_event); } @@ -55,13 +54,7 @@ cJSON *OpenAPI_up_path_chg_event_convertToJSON(OpenAPI_up_path_chg_event_t *up_p goto end; } - cJSON *dnai_chg_type_local_JSON = OpenAPI_dnai_change_type_convertToJSON(up_path_chg_event->dnai_chg_type); - if (dnai_chg_type_local_JSON == NULL) { - ogs_error("OpenAPI_up_path_chg_event_convertToJSON() failed [dnai_chg_type]"); - goto end; - } - cJSON_AddItemToObject(item, "dnaiChgType", dnai_chg_type_local_JSON); - if (item->child == NULL) { + if (cJSON_AddStringToObject(item, "dnaiChgType", OpenAPI_dnai_change_type_ToString(up_path_chg_event->dnai_chg_type)) == NULL) { ogs_error("OpenAPI_up_path_chg_event_convertToJSON() failed [dnai_chg_type]"); goto end; } @@ -110,9 +103,13 @@ OpenAPI_up_path_chg_event_t *OpenAPI_up_path_chg_event_parseFromJSON(cJSON *up_p goto end; } - OpenAPI_dnai_change_type_t *dnai_chg_type_local_nonprim = NULL; + OpenAPI_dnai_change_type_e dnai_chg_typeVariable; - dnai_chg_type_local_nonprim = OpenAPI_dnai_change_type_parseFromJSON(dnai_chg_type); + if (!cJSON_IsString(dnai_chg_type)) { + ogs_error("OpenAPI_up_path_chg_event_parseFromJSON() failed [dnai_chg_type]"); + goto end; + } + dnai_chg_typeVariable = OpenAPI_dnai_change_type_FromString(dnai_chg_type->valuestring); cJSON *af_ack_ind = cJSON_GetObjectItemCaseSensitive(up_path_chg_eventJSON, "afAckInd"); @@ -126,7 +123,7 @@ OpenAPI_up_path_chg_event_t *OpenAPI_up_path_chg_event_parseFromJSON(cJSON *up_p up_path_chg_event_local_var = OpenAPI_up_path_chg_event_create ( ogs_strdup(notification_uri->valuestring), ogs_strdup(notif_corre_id->valuestring), - dnai_chg_type_local_nonprim, + dnai_chg_typeVariable, af_ack_ind ? af_ack_ind->valueint : 0 ); diff --git a/lib/sbi/openapi/model/up_path_chg_event.h b/lib/sbi/openapi/model/up_path_chg_event.h index 0d62501aa..7ef0433a9 100644 --- a/lib/sbi/openapi/model/up_path_chg_event.h +++ b/lib/sbi/openapi/model/up_path_chg_event.h @@ -22,14 +22,14 @@ typedef struct OpenAPI_up_path_chg_event_s OpenAPI_up_path_chg_event_t; typedef struct OpenAPI_up_path_chg_event_s { char *notification_uri; char *notif_corre_id; - struct OpenAPI_dnai_change_type_s *dnai_chg_type; + OpenAPI_dnai_change_type_e dnai_chg_type; int af_ack_ind; } OpenAPI_up_path_chg_event_t; OpenAPI_up_path_chg_event_t *OpenAPI_up_path_chg_event_create( char *notification_uri, char *notif_corre_id, - OpenAPI_dnai_change_type_t *dnai_chg_type, + OpenAPI_dnai_change_type_e dnai_chg_type, int af_ack_ind ); void OpenAPI_up_path_chg_event_free(OpenAPI_up_path_chg_event_t *up_path_chg_event); diff --git a/lib/sbi/openapi/model/usage_threshold_rm.c b/lib/sbi/openapi/model/usage_threshold_rm.c new file mode 100644 index 000000000..66671db54 --- /dev/null +++ b/lib/sbi/openapi/model/usage_threshold_rm.c @@ -0,0 +1,161 @@ + +#include +#include +#include +#include "usage_threshold_rm.h" + +OpenAPI_usage_threshold_rm_t *OpenAPI_usage_threshold_rm_create( + int duration, + long total_volume, + long downlink_volume, + long uplink_volume + ) +{ + OpenAPI_usage_threshold_rm_t *usage_threshold_rm_local_var = OpenAPI_malloc(sizeof(OpenAPI_usage_threshold_rm_t)); + if (!usage_threshold_rm_local_var) { + return NULL; + } + usage_threshold_rm_local_var->duration = duration; + usage_threshold_rm_local_var->total_volume = total_volume; + usage_threshold_rm_local_var->downlink_volume = downlink_volume; + usage_threshold_rm_local_var->uplink_volume = uplink_volume; + + return usage_threshold_rm_local_var; +} + +void OpenAPI_usage_threshold_rm_free(OpenAPI_usage_threshold_rm_t *usage_threshold_rm) +{ + if (NULL == usage_threshold_rm) { + return; + } + OpenAPI_lnode_t *node; + ogs_free(usage_threshold_rm); +} + +cJSON *OpenAPI_usage_threshold_rm_convertToJSON(OpenAPI_usage_threshold_rm_t *usage_threshold_rm) +{ + cJSON *item = NULL; + + if (usage_threshold_rm == NULL) { + ogs_error("OpenAPI_usage_threshold_rm_convertToJSON() failed [UsageThresholdRm]"); + return NULL; + } + + item = cJSON_CreateObject(); + if (usage_threshold_rm->duration) { + if (cJSON_AddNumberToObject(item, "duration", usage_threshold_rm->duration) == NULL) { + ogs_error("OpenAPI_usage_threshold_rm_convertToJSON() failed [duration]"); + goto end; + } + } + + if (usage_threshold_rm->total_volume) { + if (cJSON_AddNumberToObject(item, "totalVolume", usage_threshold_rm->total_volume) == NULL) { + ogs_error("OpenAPI_usage_threshold_rm_convertToJSON() failed [total_volume]"); + goto end; + } + } + + if (usage_threshold_rm->downlink_volume) { + if (cJSON_AddNumberToObject(item, "downlinkVolume", usage_threshold_rm->downlink_volume) == NULL) { + ogs_error("OpenAPI_usage_threshold_rm_convertToJSON() failed [downlink_volume]"); + goto end; + } + } + + if (usage_threshold_rm->uplink_volume) { + if (cJSON_AddNumberToObject(item, "uplinkVolume", usage_threshold_rm->uplink_volume) == NULL) { + ogs_error("OpenAPI_usage_threshold_rm_convertToJSON() failed [uplink_volume]"); + goto end; + } + } + +end: + return item; +} + +OpenAPI_usage_threshold_rm_t *OpenAPI_usage_threshold_rm_parseFromJSON(cJSON *usage_threshold_rmJSON) +{ + OpenAPI_usage_threshold_rm_t *usage_threshold_rm_local_var = NULL; + cJSON *duration = cJSON_GetObjectItemCaseSensitive(usage_threshold_rmJSON, "duration"); + + if (duration) { + if (!cJSON_IsNumber(duration)) { + ogs_error("OpenAPI_usage_threshold_rm_parseFromJSON() failed [duration]"); + goto end; + } + } + + cJSON *total_volume = cJSON_GetObjectItemCaseSensitive(usage_threshold_rmJSON, "totalVolume"); + + if (total_volume) { + if (!cJSON_IsNumber(total_volume)) { + ogs_error("OpenAPI_usage_threshold_rm_parseFromJSON() failed [total_volume]"); + goto end; + } + } + + cJSON *downlink_volume = cJSON_GetObjectItemCaseSensitive(usage_threshold_rmJSON, "downlinkVolume"); + + if (downlink_volume) { + if (!cJSON_IsNumber(downlink_volume)) { + ogs_error("OpenAPI_usage_threshold_rm_parseFromJSON() failed [downlink_volume]"); + goto end; + } + } + + cJSON *uplink_volume = cJSON_GetObjectItemCaseSensitive(usage_threshold_rmJSON, "uplinkVolume"); + + if (uplink_volume) { + if (!cJSON_IsNumber(uplink_volume)) { + ogs_error("OpenAPI_usage_threshold_rm_parseFromJSON() failed [uplink_volume]"); + goto end; + } + } + + usage_threshold_rm_local_var = OpenAPI_usage_threshold_rm_create ( + duration ? duration->valuedouble : 0, + total_volume ? total_volume->valuedouble : 0, + downlink_volume ? downlink_volume->valuedouble : 0, + uplink_volume ? uplink_volume->valuedouble : 0 + ); + + return usage_threshold_rm_local_var; +end: + return NULL; +} + +OpenAPI_usage_threshold_rm_t *OpenAPI_usage_threshold_rm_copy(OpenAPI_usage_threshold_rm_t *dst, OpenAPI_usage_threshold_rm_t *src) +{ + cJSON *item = NULL; + char *content = NULL; + + ogs_assert(src); + item = OpenAPI_usage_threshold_rm_convertToJSON(src); + if (!item) { + ogs_error("OpenAPI_usage_threshold_rm_convertToJSON() failed"); + return NULL; + } + + content = cJSON_Print(item); + cJSON_Delete(item); + + if (!content) { + ogs_error("cJSON_Print() failed"); + return NULL; + } + + item = cJSON_Parse(content); + ogs_free(content); + if (!item) { + ogs_error("cJSON_Parse() failed"); + return NULL; + } + + OpenAPI_usage_threshold_rm_free(dst); + dst = OpenAPI_usage_threshold_rm_parseFromJSON(item); + cJSON_Delete(item); + + return dst; +} + diff --git a/lib/sbi/openapi/model/usage_threshold_rm.h b/lib/sbi/openapi/model/usage_threshold_rm.h new file mode 100644 index 000000000..ec0a53fab --- /dev/null +++ b/lib/sbi/openapi/model/usage_threshold_rm.h @@ -0,0 +1,44 @@ +/* + * usage_threshold_rm.h + * + * + */ + +#ifndef _OpenAPI_usage_threshold_rm_H_ +#define _OpenAPI_usage_threshold_rm_H_ + +#include +#include "../external/cJSON.h" +#include "../include/list.h" +#include "../include/keyValuePair.h" +#include "../include/binary.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OpenAPI_usage_threshold_rm_s OpenAPI_usage_threshold_rm_t; +typedef struct OpenAPI_usage_threshold_rm_s { + int duration; + long total_volume; + long downlink_volume; + long uplink_volume; +} OpenAPI_usage_threshold_rm_t; + +OpenAPI_usage_threshold_rm_t *OpenAPI_usage_threshold_rm_create( + int duration, + long total_volume, + long downlink_volume, + long uplink_volume + ); +void OpenAPI_usage_threshold_rm_free(OpenAPI_usage_threshold_rm_t *usage_threshold_rm); +OpenAPI_usage_threshold_rm_t *OpenAPI_usage_threshold_rm_parseFromJSON(cJSON *usage_threshold_rmJSON); +cJSON *OpenAPI_usage_threshold_rm_convertToJSON(OpenAPI_usage_threshold_rm_t *usage_threshold_rm); +OpenAPI_usage_threshold_rm_t *OpenAPI_usage_threshold_rm_copy(OpenAPI_usage_threshold_rm_t *dst, OpenAPI_usage_threshold_rm_t *src); + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenAPI_usage_threshold_rm_H_ */ + diff --git a/lib/sbi/path.c b/lib/sbi/path.c index 318ff77e4..d02171d4b 100644 --- a/lib/sbi/path.c +++ b/lib/sbi/path.c @@ -213,3 +213,17 @@ void ogs_nnrf_disc_send_nf_discover(ogs_sbi_nf_instance_t *nf_instance, ogs_assert(request); ogs_sbi_client_send_request(client, client->cb, request, data); } + +void ogs_sbi_send_response(ogs_sbi_stream_t *stream, int status) +{ + ogs_sbi_message_t sendmsg; + ogs_sbi_response_t *response = NULL; + + ogs_assert(stream); + + memset(&sendmsg, 0, sizeof(sendmsg)); + + response = ogs_sbi_build_response(&sendmsg, status); + ogs_assert(response); + ogs_sbi_server_send_response(stream, response); +} diff --git a/lib/sbi/path.h b/lib/sbi/path.h index 8e2a8a2b2..559ea7d4e 100644 --- a/lib/sbi/path.h +++ b/lib/sbi/path.h @@ -43,6 +43,10 @@ void ogs_nnrf_nfm_send_nf_status_unsubscribe( void ogs_nnrf_disc_send_nf_discover(ogs_sbi_nf_instance_t *nf_instance, OpenAPI_nf_type_e target_nf_type, void *data); +#define ogs_sbi_send_http_status_no_content(__sTREAM) \ + ogs_sbi_send_response(__sTREAM, OGS_SBI_HTTP_STATUS_NO_CONTENT); +void ogs_sbi_send_response(ogs_sbi_stream_t *stream, int status); + #ifdef __cplusplus } #endif diff --git a/lib/sbi/support/README.md b/lib/sbi/support/README.md index 4b53e9a6e..6ffc11b53 100644 --- a/lib/sbi/support/README.md +++ b/lib/sbi/support/README.md @@ -11,13 +11,13 @@ $ npm install @openapitools/openapi-generator-cli -g - VERSION: 4.3.1-SNAPSHOT $ git clone https://github.com/OpenAPITools/openapi-generator.git $ cd openapi-generator -$ git checkoutt 15d58dc89b11d17f52c2daadfae9736e442f3b1a +$ git checkout 15d58dc89b11d17f52c2daadfae9736e442f3b1a $ mvn clean package - VERSION: 0.69.1 $ git clone https://github.com/uncrustify/uncrustify.git $ cd uncrustify -$ git tag uncrustify-0.69.1 +$ git checkout uncrustify-0.69.1 $ mkdir build $ cd build $ cmake .. diff --git a/lib/sbi/support/generator.sh b/lib/sbi/support/generator.sh index 981383f30..c6186e489 100755 --- a/lib/sbi/support/generator.sh +++ b/lib/sbi/support/generator.sh @@ -7,9 +7,11 @@ export C_POST_PROCESS_FILE="${HOME}/Documents/git/my/uncrustify/build/uncrustify export UNCRUSTIFY_CONFIG=../openapi/.openapi-generator/uncrustify-0.66.1.cfg openapi_generator_cli="java -jar ${HOME}/Documents/git/my/openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar" +$openapi_generator_cli generate -i ./modified/TS29521_Nbsf_Management.yaml -c ../openapi/.openapi-generator/config.yaml -g c -o ../openapi $openapi_generator_cli generate -i ./modified/TS29531_Nnssf_NSSelection.yaml -c ../openapi/.openapi-generator/config.yaml -g c -o ../openapi $openapi_generator_cli generate -i ./modified/TS29507_Npcf_AMPolicyControl.yaml -c ../openapi/.openapi-generator/config.yaml -g c -o ../openapi $openapi_generator_cli generate -i ./modified/TS29512_Npcf_SMPolicyControl.yaml -c ../openapi/.openapi-generator/config.yaml -g c -o ../openapi +$openapi_generator_cli generate -i ./modified/TS29514_Npcf_PolicyAuthorization.yaml -c ../openapi/.openapi-generator/config.yaml -g c -o ../openapi $openapi_generator_cli generate -i ./modified/TS29503_Nudm_SDM.yaml -c ../openapi/.openapi-generator/config.yaml -g c -o ../openapi $openapi_generator_cli generate -i ./modified/TS29503_Nudm_UECM.yaml -c ../openapi/.openapi-generator/config.yaml -g c -o ../openapi $openapi_generator_cli generate -i ./modified/TS29503_Nudm_UEAU.yaml -c ../openapi/.openapi-generator/config.yaml -g c -o ../openapi diff --git a/lib/sbi/support/modified/TS29503_Nudm_UECM.yaml b/lib/sbi/support/modified/TS29503_Nudm_UECM.yaml index f34a30877..6fe8fc5c1 100644 --- a/lib/sbi/support/modified/TS29503_Nudm_UECM.yaml +++ b/lib/sbi/support/modified/TS29503_Nudm_UECM.yaml @@ -1777,17 +1777,17 @@ components: # ENUMS: ImsVoPs: - anyOf: - - type: string +# anyOf: +# - type: string enum: - HOMOGENEOUS_SUPPORT - HOMOGENEOUS_NON_SUPPORT - NON_HOMOGENEOUS_OR_UNKNOWN - - type: string + type: string DeregistrationReason: - anyOf: - - type: string +# anyOf: +# - type: string enum: - UE_INITIAL_REGISTRATION - UE_REGISTRATION_AREA_CHANGE @@ -1796,23 +1796,23 @@ components: - 5GS_TO_EPS_MOBILITY_UE_INITIAL_REGISTRATION - REREGISTRATION_REQUIRED - SMF_CONTEXT_TRANSFERRED - - type: string + type: string RegistrationReason: - anyOf: - - type: string +# anyOf: +# - type: string enum: - SMF_CONTEXT_TRANSFERRED - - type: string + type: string RegistrationDataSetName: - anyOf: - - type: string +# anyOf: +# - type: string enum: - AMF_3GPP - AMF_NON_3GPP - SMF_PDU_SESSIONS - SMSF_3GPP - SMSF_NON_3GPP - - type: string + type: string diff --git a/lib/sbi/support/modified/TS29514_Npcf_PolicyAuthorization.yaml b/lib/sbi/support/modified/TS29514_Npcf_PolicyAuthorization.yaml index bf4bdbb4b..1f10585bb 100644 --- a/lib/sbi/support/modified/TS29514_Npcf_PolicyAuthorization.yaml +++ b/lib/sbi/support/modified/TS29514_Npcf_PolicyAuthorization.yaml @@ -1519,8 +1519,8 @@ components: # ENUMERATIONS DATA TYPES # MediaType: - anyOf: - - type: string +# anyOf: +# - type: string enum: - AUDIO - VIDEO @@ -1530,11 +1530,11 @@ components: - TEXT - MESSAGE - OTHER - - type: string + type: string # ReservPriority: - anyOf: - - type: string +# anyOf: +# - type: string enum: - PRIO_1 - PRIO_2 @@ -1552,24 +1552,24 @@ components: - PRIO_14 - PRIO_15 - PRIO_16 - - type: string + type: string # ServAuthInfo: - anyOf: - - type: string +# anyOf: +# - type: string enum: - TP_NOT_KNOWN - TP_EXPIRED - TP_NOT_YET_OCURRED - - type: string + type: string # SponsoringStatus: - anyOf: - - type: string +# anyOf: +# - type: string enum: - SPONSOR_DISABLED - SPONSOR_ENABLED - - type: string + type: string # AfEvent: anyOf: @@ -1592,14 +1592,14 @@ components: - type: string # AfNotifMethod: - anyOf: - - type: string +# anyOf: +# - type: string enum: - EVENT_DETECTION - ONE_TIME - PERIODIC - PDU_SESSION_RELEASE - - type: string + type: string # QosNotifType: anyOf: @@ -1610,91 +1610,91 @@ components: - type: string # TerminationCause: - anyOf: - - type: string +# anyOf: +# - type: string enum: - ALL_SDF_DEACTIVATION - PDU_SESSION_TERMINATION - PS_TO_CS_HO - - type: string + type: string # MediaComponentResourcesStatus: - anyOf: - - type: string +# anyOf: +# - type: string enum: - ACTIVE - INACTIVE - - type: string + type: string # # FlowUsage: - anyOf: - - type: string +# anyOf: +# - type: string enum: - NO_INFO - RTCP - AF_SIGNALLING - - type: string + type: string FlowStatus: - anyOf: - - type: string +# anyOf: +# - type: string enum: - ENABLED-UPLINK - ENABLED-DOWNLINK - ENABLED - DISABLED - REMOVED - - type: string + type: string # RequiredAccessInfo: - anyOf: - - type: string +# anyOf: +# - type: string enum: - USER_LOCATION - UE_TIME_ZONE - - type: string + type: string # SipForkingIndication: - anyOf: - - type: string +# anyOf: +# - type: string enum: - SINGLE_DIALOGUE - SEVERAL_DIALOGUES - - type: string + type: string # AfRequestedData: - anyOf: - - type: string +# anyOf: +# - type: string enum: - UE_IDENTITY - - type: string + type: string # ServiceInfoStatus: - anyOf: - - type: string +# anyOf: +# - type: string enum: - FINAL - PRELIMINARY - - type: string + type: string # PreemptionControlInformation: - anyOf: - - type: string +# anyOf: +# - type: string enum: - MOST_RECENT - LEAST_RECENT - HIGHEST_BW - - type: string + type: string # PrioritySharingIndicator: - anyOf: - - type: string +# anyOf: +# - type: string enum: - ENABLED - DISABLED - - type: string + type: string # PreemptionControlInformationRm: anyOf: diff --git a/lib/sbi/support/modified/TS29521_Nbsf_Management.yaml b/lib/sbi/support/modified/TS29521_Nbsf_Management.yaml new file mode 100644 index 000000000..00bebf70e --- /dev/null +++ b/lib/sbi/support/modified/TS29521_Nbsf_Management.yaml @@ -0,0 +1,472 @@ +openapi: 3.0.0 +info: + version: 1.1.1 + title: Nbsf_Management + description: | + Binding Support Management Service API. + © 2021, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). + All rights reserved. +externalDocs: + description: 3GPP TS 29.521 V16.7.0; 5G System; Binding Support Management Service. + url: 'http://www.3gpp.org/ftp/Specs/archive/29_series/29.521/' +servers: + - url: '{apiRoot}/nbsf-management/v1' + variables: + apiRoot: + default: https://example.com + description: apiRoot as defined in subclause 4.4 of 3GPP TS 29.501. +security: + - {} + - oAuth2ClientCredentials: + - nbsf-management +paths: + /pcfBindings: + post: + summary: Create a new Individual PCF binding information + operationId: CreatePCFBinding + tags: + - PCF Bindings (Collection) + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/PcfBinding' + responses: + '201': + description: The creation of an individual PCF session binding. + content: + application/json: + schema: + $ref: '#/components/schemas/PcfBinding' + headers: + Location: + description: 'Contains the URI of the newly created resource, according to the structure: {apiRoot}/nbsf-management/v1/pcfBindings/{bindingId}' + required: true + schema: + type: string + '400': + $ref: 'TS29571_CommonData.yaml#/components/responses/400' + '401': + $ref: 'TS29571_CommonData.yaml#/components/responses/401' + '403': + description: The existing PCF binding information stored in the BSF for the indicated combination is returned. + content: + application/json: + schema: + $ref: '#/components/schemas/ExtProblemDetails' + '404': + $ref: 'TS29571_CommonData.yaml#/components/responses/404' + '411': + $ref: 'TS29571_CommonData.yaml#/components/responses/411' + '413': + $ref: 'TS29571_CommonData.yaml#/components/responses/413' + '415': + $ref: 'TS29571_CommonData.yaml#/components/responses/415' + '429': + $ref: 'TS29571_CommonData.yaml#/components/responses/429' + '500': + $ref: 'TS29571_CommonData.yaml#/components/responses/500' + '503': + $ref: 'TS29571_CommonData.yaml#/components/responses/503' + default: + $ref: 'TS29571_CommonData.yaml#/components/responses/default' + get: + summary: Read PCF Bindings information + operationId: GetPCFBindings + tags: + - PCF Bindings (Collection) + parameters: + - name: ipv4Addr + in: query + description: The IPv4 Address of the served UE. + required: false + schema: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Ipv4Addr' + - name: ipv6Prefix + in: query + description: The IPv6 Address of the served UE. The NF service consumer shall append '/128' to the IPv6 address in the attribute value. E.g. '2001:db8:85a3::8a2e:370:7334/128'. + required: false + schema: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Ipv6Prefix' + - name: macAddr48 + in: query + description: The MAC Address of the served UE. + required: false + schema: + $ref: 'TS29571_CommonData.yaml#/components/schemas/MacAddr48' + - name: dnn + in: query + description: DNN. + required: false + schema: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Dnn' + - name: supi + in: query + description: Subscription Permanent Identifier. + required: false + schema: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Supi' + - name: gpsi + in: query + description: Generic Public Subscription Identifier + required: false + schema: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Gpsi' + - name: snssai + in: query + description: The identification of slice. + required: false + content: + application/json: + schema: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Snssai' + - name: ipDomain + in: query + description: The IPv4 address domain identifier. + required: false + schema: + type: string + - name: supp-feat + in: query + description: To filter irrelevant responses related to unsupported features + schema: + $ref: 'TS29571_CommonData.yaml#/components/schemas/SupportedFeatures' + responses: + '200': + description: The individual PCF session binding session binding information resource matching the query parameter(s) is returned. + content: + application/json: + schema: + $ref: '#/components/schemas/PcfBinding' + '204': + description: There is no PCF session binding information matching the query parameter(s). + '400': + $ref: 'TS29571_CommonData.yaml#/components/responses/400' + '401': + $ref: 'TS29571_CommonData.yaml#/components/responses/401' + '403': + $ref: 'TS29571_CommonData.yaml#/components/responses/403' + '404': + $ref: 'TS29571_CommonData.yaml#/components/responses/404' + '406': + $ref: 'TS29571_CommonData.yaml#/components/responses/406' + '414': + $ref: 'TS29571_CommonData.yaml#/components/responses/414' + '429': + $ref: 'TS29571_CommonData.yaml#/components/responses/429' + '500': + $ref: 'TS29571_CommonData.yaml#/components/responses/500' + '503': + $ref: 'TS29571_CommonData.yaml#/components/responses/503' + default: + $ref: 'TS29571_CommonData.yaml#/components/responses/default' + /pcfBindings/{bindingId}: + delete: + summary: Delete an existing Individual PCF Binding information + operationId: DeleteIndPCFBinding + tags: + - Individual PCF Binding (Document) + parameters: + - name: bindingId + in: path + description: Represents the individual PCF Session Binding. + required: true + schema: + type: string + responses: + '204': + description: No Content. The Individual PCF session binding information resource is deleted. + '307': + description: Temporary Redirect + content: + application/problem+json: + schema: + $ref: 'TS29571_CommonData.yaml#/components/schemas/ProblemDetails' + headers: + Location: + description: 'An alternative URI of the resource located on an alternative BSF (service) instance.' + required: true + schema: + type: string + 3gpp-Sbi-Target-Nf-Id: + description: 'Identifier of the target NF (service) instance towards which the request is redirected' + schema: + type: string + '308': + description: Permanent Redirect + content: + application/problem+json: + schema: + $ref: 'TS29571_CommonData.yaml#/components/schemas/ProblemDetails' + headers: + Location: + description: 'An alternative URI of the resource located on an alternative BSF (service) instance.' + required: true + schema: + type: string + 3gpp-Sbi-Target-Nf-Id: + description: 'Identifier of the target NF (service) instance towards which the request is redirected' + schema: + type: string + '400': + $ref: 'TS29571_CommonData.yaml#/components/responses/400' + '401': + $ref: 'TS29571_CommonData.yaml#/components/responses/401' + '403': + $ref: 'TS29571_CommonData.yaml#/components/responses/403' + '404': + $ref: 'TS29571_CommonData.yaml#/components/responses/404' + '429': + $ref: 'TS29571_CommonData.yaml#/components/responses/429' + '500': + $ref: 'TS29571_CommonData.yaml#/components/responses/500' + '503': + $ref: 'TS29571_CommonData.yaml#/components/responses/503' + default: + $ref: 'TS29571_CommonData.yaml#/components/responses/default' + patch: + summary: Update an existing Individual PCF Binding information + operationId: UpdateIndPCFBinding + tags: + - Individual PCF Binding (Document) + parameters: + - name: bindingId + in: path + description: Represents the individual PCF Session Binding. + required: true + schema: + type: string + requestBody: + description: Parameters to update the existing session binding + required: true + content: + application/merge-patch+json: + schema: + $ref: '#/components/schemas/PcfBindingPatch' + responses: + '200': + description: OK (Successful update of the session binding) + content: + application/json: + schema: + $ref: '#/components/schemas/PcfBinding' + '307': + description: Temporary Redirect + content: + application/problem+json: + schema: + $ref: 'TS29571_CommonData.yaml#/components/schemas/ProblemDetails' + headers: + Location: + description: 'An alternative URI of the resource located on an alternative BSF (service) instance.' + required: true + schema: + type: string + 3gpp-Sbi-Target-Nf-Id: + description: 'Identifier of the target NF (service) instance towards which the request is redirected' + schema: + type: string + '308': + description: Permanent Redirect + content: + application/problem+json: + schema: + $ref: 'TS29571_CommonData.yaml#/components/schemas/ProblemDetails' + headers: + Location: + description: 'An alternative URI of the resource located on an alternative BSF (service) instance.' + required: true + schema: + type: string + 3gpp-Sbi-Target-Nf-Id: + description: 'Identifier of the target NF (service) instance towards which the request is redirected' + schema: + type: string + '400': + $ref: 'TS29571_CommonData.yaml#/components/responses/400' + '401': + $ref: 'TS29571_CommonData.yaml#/components/responses/401' + '403': + $ref: 'TS29571_CommonData.yaml#/components/responses/403' + '404': + $ref: 'TS29571_CommonData.yaml#/components/responses/404' + '411': + $ref: 'TS29571_CommonData.yaml#/components/responses/411' + '413': + $ref: 'TS29571_CommonData.yaml#/components/responses/413' + '415': + $ref: 'TS29571_CommonData.yaml#/components/responses/415' + '429': + $ref: 'TS29571_CommonData.yaml#/components/responses/429' + '500': + $ref: 'TS29571_CommonData.yaml#/components/responses/500' + '503': + $ref: 'TS29571_CommonData.yaml#/components/responses/503' + default: + $ref: 'TS29571_CommonData.yaml#/components/responses/default' +components: + securitySchemes: + oAuth2ClientCredentials: + type: oauth2 + flows: + clientCredentials: + tokenUrl: '{nrfApiRoot}/oauth2/token' + scopes: + nbsf-management: Access to the Nbsf_Management API + schemas: + PcfBinding: + type: object + properties: + supi: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Supi' + gpsi: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Gpsi' + ipv4Addr: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Ipv4Addr' + ipv6Prefix: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Ipv6Prefix' + addIpv6Prefixes: + type: array + items: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Ipv6Prefix' + minItems: 1 + description: The additional IPv6 Address Prefixes of the served UE. + ipDomain: + type: string + macAddr48: + $ref: 'TS29571_CommonData.yaml#/components/schemas/MacAddr48' + addMacAddrs: + type: array + items: + $ref: 'TS29571_CommonData.yaml#/components/schemas/MacAddr48' + minItems: 1 + description: The additional MAC Addresses of the served UE. + dnn: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Dnn' + pcfFqdn: + $ref: 'TS29510_Nnrf_NFManagement.yaml#/components/schemas/Fqdn' + pcfIpEndPoints: + type: array + items: + $ref: 'TS29510_Nnrf_NFManagement.yaml#/components/schemas/IpEndPoint' + minItems: 1 + description: IP end points of the PCF hosting the Npcf_PolicyAuthorization service. + pcfDiamHost: + $ref: 'TS29571_CommonData.yaml#/components/schemas/DiameterIdentity' + pcfDiamRealm: + $ref: 'TS29571_CommonData.yaml#/components/schemas/DiameterIdentity' + pcfSmFqdn: + $ref: 'TS29510_Nnrf_NFManagement.yaml#/components/schemas/Fqdn' + pcfSmIpEndPoints: + type: array + items: + $ref: 'TS29510_Nnrf_NFManagement.yaml#/components/schemas/IpEndPoint' + minItems: 1 + description: IP end points of the PCF hosting the Npcf_SMPolicyControl service. + snssai: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Snssai' + suppFeat: + $ref: 'TS29571_CommonData.yaml#/components/schemas/SupportedFeatures' + pcfId: + $ref: 'TS29571_CommonData.yaml#/components/schemas/NfInstanceId' + pcfSetId: + $ref: 'TS29571_CommonData.yaml#/components/schemas/NfSetId' + recoveryTime: + $ref: 'TS29571_CommonData.yaml#/components/schemas/DateTime' + paraCom: + $ref: '#/components/schemas/ParameterCombination' + bindLevel: + $ref: '#/components/schemas/BindingLevel' + ipv4FrameRouteList: + type: array + items: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Ipv4AddrMask' + minItems: 1 + ipv6FrameRouteList: + type: array + items: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Ipv6Prefix' + minItems: 1 + required: + - dnn + - snssai + PcfBindingPatch: + type: object + properties: + ipv4Addr: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Ipv4AddrRm' + ipDomain: + type: string + nullable: true + ipv6Prefix: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Ipv6PrefixRm' + addIpv6Prefixes: + type: array + items: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Ipv6Prefix' + minItems: 1 + description: The additional IPv6 Address Prefixes of the served UE. + nullable: true + macAddr48: + $ref: 'TS29571_CommonData.yaml#/components/schemas/MacAddr48Rm' + addMacAddrs: + type: array + items: + $ref: 'TS29571_CommonData.yaml#/components/schemas/MacAddr48' + minItems: 1 + description: The additional MAC Addresses of the served UE. + nullable: true + pcfId: + $ref: 'TS29571_CommonData.yaml#/components/schemas/NfInstanceId' + pcfFqdn: + $ref: 'TS29510_Nnrf_NFManagement.yaml#/components/schemas/Fqdn' + pcfIpEndPoints: + type: array + items: + $ref: 'TS29510_Nnrf_NFManagement.yaml#/components/schemas/IpEndPoint' + minItems: 1 + description: IP end points of the PCF hosting the Npcf_PolicyAuthorization service. + pcfDiamHost: + $ref: 'TS29571_CommonData.yaml#/components/schemas/DiameterIdentity' + pcfDiamRealm: + $ref: 'TS29571_CommonData.yaml#/components/schemas/DiameterIdentity' + ParameterCombination: + type: object + properties: + supi: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Supi' + dnn: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Dnn' + snssai: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Snssai' + ExtProblemDetails: + allOf: + - $ref: 'TS29571_CommonData.yaml#/components/schemas/ProblemDetails' + - $ref: '#/components/schemas/BindingResp' + BindingResp: + type: object + properties: + pcfSmFqdn: + $ref: 'TS29510_Nnrf_NFManagement.yaml#/components/schemas/Fqdn' + pcfSmIpEndPoints: + type: array + items: + $ref: 'TS29510_Nnrf_NFManagement.yaml#/components/schemas/IpEndPoint' + minItems: 1 + description: IP end points of the PCF hosting the Npcf_SMPolicyControl service. + BindingLevel: +# anyOf: +# - type: string + enum: + - NF_SET + - NF_INSTANCE + type: string +# description: > +# This string provides forward-compatibility with future +# extensions to the enumeration but is not used to encode +# content defined in the present version of this API. +# description: > +# Possible values are +# - "NF_SET" +# - "NF_INSTANCE" diff --git a/lib/sbi/support/modified/TS29571_CommonData.yaml b/lib/sbi/support/modified/TS29571_CommonData.yaml index f62e00479..7baa2d1d2 100644 --- a/lib/sbi/support/modified/TS29571_CommonData.yaml +++ b/lib/sbi/support/modified/TS29571_CommonData.yaml @@ -790,22 +790,22 @@ components: - $ref: '#/components/schemas/SscMode' - $ref: '#/components/schemas/NullValue' DnaiChangeType: - anyOf: - - type: string +# anyOf: +# - type: string enum: - EARLY - EARLY_LATE - LATE type: string - description: > - This string provides forward-compatibility with future - extensions to the enumeration but is not used to encode - content defined in the present version of this API. - description: > - Possible values are - - EARLY: Early notification of UP path reconfiguration. - - EARLY_LATE: Early and late notification of UP path reconfiguration. This value shall only be present in the subscription to the DNAI change event. - - LATE: Late notification of UP path reconfiguration. +# description: > +# This string provides forward-compatibility with future +# extensions to the enumeration but is not used to encode +# content defined in the present version of this API. +# description: > +# Possible values are +# - EARLY: Early notification of UP path reconfiguration. +# - EARLY_LATE: Early and late notification of UP path reconfiguration. This value shall only be present in the subscription to the DNAI change event. +# - LATE: Late notification of UP path reconfiguration. DnaiChangeTypeRm: anyOf: - $ref: '#/components/schemas/DnaiChangeType' diff --git a/lib/sbi/support/standard/TS29521_Nbsf_Management.yaml b/lib/sbi/support/standard/TS29521_Nbsf_Management.yaml new file mode 100644 index 000000000..167d574b5 --- /dev/null +++ b/lib/sbi/support/standard/TS29521_Nbsf_Management.yaml @@ -0,0 +1,472 @@ +openapi: 3.0.0 +info: + version: 1.1.1 + title: Nbsf_Management + description: | + Binding Support Management Service API. + © 2021, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). + All rights reserved. +externalDocs: + description: 3GPP TS 29.521 V16.7.0; 5G System; Binding Support Management Service. + url: 'http://www.3gpp.org/ftp/Specs/archive/29_series/29.521/' +servers: + - url: '{apiRoot}/nbsf-management/v1' + variables: + apiRoot: + default: https://example.com + description: apiRoot as defined in subclause 4.4 of 3GPP TS 29.501. +security: + - {} + - oAuth2ClientCredentials: + - nbsf-management +paths: + /pcfBindings: + post: + summary: Create a new Individual PCF binding information + operationId: CreatePCFBinding + tags: + - PCF Bindings (Collection) + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/PcfBinding' + responses: + '201': + description: The creation of an individual PCF session binding. + content: + application/json: + schema: + $ref: '#/components/schemas/PcfBinding' + headers: + Location: + description: 'Contains the URI of the newly created resource, according to the structure: {apiRoot}/nbsf-management/v1/pcfBindings/{bindingId}' + required: true + schema: + type: string + '400': + $ref: 'TS29571_CommonData.yaml#/components/responses/400' + '401': + $ref: 'TS29571_CommonData.yaml#/components/responses/401' + '403': + description: The existing PCF binding information stored in the BSF for the indicated combination is returned. + content: + application/json: + schema: + $ref: '#/components/schemas/ExtProblemDetails' + '404': + $ref: 'TS29571_CommonData.yaml#/components/responses/404' + '411': + $ref: 'TS29571_CommonData.yaml#/components/responses/411' + '413': + $ref: 'TS29571_CommonData.yaml#/components/responses/413' + '415': + $ref: 'TS29571_CommonData.yaml#/components/responses/415' + '429': + $ref: 'TS29571_CommonData.yaml#/components/responses/429' + '500': + $ref: 'TS29571_CommonData.yaml#/components/responses/500' + '503': + $ref: 'TS29571_CommonData.yaml#/components/responses/503' + default: + $ref: 'TS29571_CommonData.yaml#/components/responses/default' + get: + summary: Read PCF Bindings information + operationId: GetPCFBindings + tags: + - PCF Bindings (Collection) + parameters: + - name: ipv4Addr + in: query + description: The IPv4 Address of the served UE. + required: false + schema: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Ipv4Addr' + - name: ipv6Prefix + in: query + description: The IPv6 Address of the served UE. The NF service consumer shall append '/128' to the IPv6 address in the attribute value. E.g. '2001:db8:85a3::8a2e:370:7334/128'. + required: false + schema: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Ipv6Prefix' + - name: macAddr48 + in: query + description: The MAC Address of the served UE. + required: false + schema: + $ref: 'TS29571_CommonData.yaml#/components/schemas/MacAddr48' + - name: dnn + in: query + description: DNN. + required: false + schema: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Dnn' + - name: supi + in: query + description: Subscription Permanent Identifier. + required: false + schema: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Supi' + - name: gpsi + in: query + description: Generic Public Subscription Identifier + required: false + schema: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Gpsi' + - name: snssai + in: query + description: The identification of slice. + required: false + content: + application/json: + schema: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Snssai' + - name: ipDomain + in: query + description: The IPv4 address domain identifier. + required: false + schema: + type: string + - name: supp-feat + in: query + description: To filter irrelevant responses related to unsupported features + schema: + $ref: 'TS29571_CommonData.yaml#/components/schemas/SupportedFeatures' + responses: + '200': + description: The individual PCF session binding session binding information resource matching the query parameter(s) is returned. + content: + application/json: + schema: + $ref: '#/components/schemas/PcfBinding' + '204': + description: There is no PCF session binding information matching the query parameter(s). + '400': + $ref: 'TS29571_CommonData.yaml#/components/responses/400' + '401': + $ref: 'TS29571_CommonData.yaml#/components/responses/401' + '403': + $ref: 'TS29571_CommonData.yaml#/components/responses/403' + '404': + $ref: 'TS29571_CommonData.yaml#/components/responses/404' + '406': + $ref: 'TS29571_CommonData.yaml#/components/responses/406' + '414': + $ref: 'TS29571_CommonData.yaml#/components/responses/414' + '429': + $ref: 'TS29571_CommonData.yaml#/components/responses/429' + '500': + $ref: 'TS29571_CommonData.yaml#/components/responses/500' + '503': + $ref: 'TS29571_CommonData.yaml#/components/responses/503' + default: + $ref: 'TS29571_CommonData.yaml#/components/responses/default' + /pcfBindings/{bindingId}: + delete: + summary: Delete an existing Individual PCF Binding information + operationId: DeleteIndPCFBinding + tags: + - Individual PCF Binding (Document) + parameters: + - name: bindingId + in: path + description: Represents the individual PCF Session Binding. + required: true + schema: + type: string + responses: + '204': + description: No Content. The Individual PCF session binding information resource is deleted. + '307': + description: Temporary Redirect + content: + application/problem+json: + schema: + $ref: 'TS29571_CommonData.yaml#/components/schemas/ProblemDetails' + headers: + Location: + description: 'An alternative URI of the resource located on an alternative BSF (service) instance.' + required: true + schema: + type: string + 3gpp-Sbi-Target-Nf-Id: + description: 'Identifier of the target NF (service) instance towards which the request is redirected' + schema: + type: string + '308': + description: Permanent Redirect + content: + application/problem+json: + schema: + $ref: 'TS29571_CommonData.yaml#/components/schemas/ProblemDetails' + headers: + Location: + description: 'An alternative URI of the resource located on an alternative BSF (service) instance.' + required: true + schema: + type: string + 3gpp-Sbi-Target-Nf-Id: + description: 'Identifier of the target NF (service) instance towards which the request is redirected' + schema: + type: string + '400': + $ref: 'TS29571_CommonData.yaml#/components/responses/400' + '401': + $ref: 'TS29571_CommonData.yaml#/components/responses/401' + '403': + $ref: 'TS29571_CommonData.yaml#/components/responses/403' + '404': + $ref: 'TS29571_CommonData.yaml#/components/responses/404' + '429': + $ref: 'TS29571_CommonData.yaml#/components/responses/429' + '500': + $ref: 'TS29571_CommonData.yaml#/components/responses/500' + '503': + $ref: 'TS29571_CommonData.yaml#/components/responses/503' + default: + $ref: 'TS29571_CommonData.yaml#/components/responses/default' + patch: + summary: Update an existing Individual PCF Binding information + operationId: UpdateIndPCFBinding + tags: + - Individual PCF Binding (Document) + parameters: + - name: bindingId + in: path + description: Represents the individual PCF Session Binding. + required: true + schema: + type: string + requestBody: + description: Parameters to update the existing session binding + required: true + content: + application/merge-patch+json: + schema: + $ref: '#/components/schemas/PcfBindingPatch' + responses: + '200': + description: OK (Successful update of the session binding) + content: + application/json: + schema: + $ref: '#/components/schemas/PcfBinding' + '307': + description: Temporary Redirect + content: + application/problem+json: + schema: + $ref: 'TS29571_CommonData.yaml#/components/schemas/ProblemDetails' + headers: + Location: + description: 'An alternative URI of the resource located on an alternative BSF (service) instance.' + required: true + schema: + type: string + 3gpp-Sbi-Target-Nf-Id: + description: 'Identifier of the target NF (service) instance towards which the request is redirected' + schema: + type: string + '308': + description: Permanent Redirect + content: + application/problem+json: + schema: + $ref: 'TS29571_CommonData.yaml#/components/schemas/ProblemDetails' + headers: + Location: + description: 'An alternative URI of the resource located on an alternative BSF (service) instance.' + required: true + schema: + type: string + 3gpp-Sbi-Target-Nf-Id: + description: 'Identifier of the target NF (service) instance towards which the request is redirected' + schema: + type: string + '400': + $ref: 'TS29571_CommonData.yaml#/components/responses/400' + '401': + $ref: 'TS29571_CommonData.yaml#/components/responses/401' + '403': + $ref: 'TS29571_CommonData.yaml#/components/responses/403' + '404': + $ref: 'TS29571_CommonData.yaml#/components/responses/404' + '411': + $ref: 'TS29571_CommonData.yaml#/components/responses/411' + '413': + $ref: 'TS29571_CommonData.yaml#/components/responses/413' + '415': + $ref: 'TS29571_CommonData.yaml#/components/responses/415' + '429': + $ref: 'TS29571_CommonData.yaml#/components/responses/429' + '500': + $ref: 'TS29571_CommonData.yaml#/components/responses/500' + '503': + $ref: 'TS29571_CommonData.yaml#/components/responses/503' + default: + $ref: 'TS29571_CommonData.yaml#/components/responses/default' +components: + securitySchemes: + oAuth2ClientCredentials: + type: oauth2 + flows: + clientCredentials: + tokenUrl: '{nrfApiRoot}/oauth2/token' + scopes: + nbsf-management: Access to the Nbsf_Management API + schemas: + PcfBinding: + type: object + properties: + supi: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Supi' + gpsi: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Gpsi' + ipv4Addr: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Ipv4Addr' + ipv6Prefix: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Ipv6Prefix' + addIpv6Prefixes: + type: array + items: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Ipv6Prefix' + minItems: 1 + description: The additional IPv6 Address Prefixes of the served UE. + ipDomain: + type: string + macAddr48: + $ref: 'TS29571_CommonData.yaml#/components/schemas/MacAddr48' + addMacAddrs: + type: array + items: + $ref: 'TS29571_CommonData.yaml#/components/schemas/MacAddr48' + minItems: 1 + description: The additional MAC Addresses of the served UE. + dnn: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Dnn' + pcfFqdn: + $ref: 'TS29510_Nnrf_NFManagement.yaml#/components/schemas/Fqdn' + pcfIpEndPoints: + type: array + items: + $ref: 'TS29510_Nnrf_NFManagement.yaml#/components/schemas/IpEndPoint' + minItems: 1 + description: IP end points of the PCF hosting the Npcf_PolicyAuthorization service. + pcfDiamHost: + $ref: 'TS29571_CommonData.yaml#/components/schemas/DiameterIdentity' + pcfDiamRealm: + $ref: 'TS29571_CommonData.yaml#/components/schemas/DiameterIdentity' + pcfSmFqdn: + $ref: 'TS29510_Nnrf_NFManagement.yaml#/components/schemas/Fqdn' + pcfSmIpEndPoints: + type: array + items: + $ref: 'TS29510_Nnrf_NFManagement.yaml#/components/schemas/IpEndPoint' + minItems: 1 + description: IP end points of the PCF hosting the Npcf_SMPolicyControl service. + snssai: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Snssai' + suppFeat: + $ref: 'TS29571_CommonData.yaml#/components/schemas/SupportedFeatures' + pcfId: + $ref: 'TS29571_CommonData.yaml#/components/schemas/NfInstanceId' + pcfSetId: + $ref: 'TS29571_CommonData.yaml#/components/schemas/NfSetId' + recoveryTime: + $ref: 'TS29571_CommonData.yaml#/components/schemas/DateTime' + paraCom: + $ref: '#/components/schemas/ParameterCombination' + bindLevel: + $ref: '#/components/schemas/BindingLevel' + ipv4FrameRouteList: + type: array + items: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Ipv4AddrMask' + minItems: 1 + ipv6FrameRouteList: + type: array + items: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Ipv6Prefix' + minItems: 1 + required: + - dnn + - snssai + PcfBindingPatch: + type: object + properties: + ipv4Addr: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Ipv4AddrRm' + ipDomain: + type: string + nullable: true + ipv6Prefix: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Ipv6PrefixRm' + addIpv6Prefixes: + type: array + items: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Ipv6Prefix' + minItems: 1 + description: The additional IPv6 Address Prefixes of the served UE. + nullable: true + macAddr48: + $ref: 'TS29571_CommonData.yaml#/components/schemas/MacAddr48Rm' + addMacAddrs: + type: array + items: + $ref: 'TS29571_CommonData.yaml#/components/schemas/MacAddr48' + minItems: 1 + description: The additional MAC Addresses of the served UE. + nullable: true + pcfId: + $ref: 'TS29571_CommonData.yaml#/components/schemas/NfInstanceId' + pcfFqdn: + $ref: 'TS29510_Nnrf_NFManagement.yaml#/components/schemas/Fqdn' + pcfIpEndPoints: + type: array + items: + $ref: 'TS29510_Nnrf_NFManagement.yaml#/components/schemas/IpEndPoint' + minItems: 1 + description: IP end points of the PCF hosting the Npcf_PolicyAuthorization service. + pcfDiamHost: + $ref: 'TS29571_CommonData.yaml#/components/schemas/DiameterIdentity' + pcfDiamRealm: + $ref: 'TS29571_CommonData.yaml#/components/schemas/DiameterIdentity' + ParameterCombination: + type: object + properties: + supi: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Supi' + dnn: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Dnn' + snssai: + $ref: 'TS29571_CommonData.yaml#/components/schemas/Snssai' + ExtProblemDetails: + allOf: + - $ref: 'TS29571_CommonData.yaml#/components/schemas/ProblemDetails' + - $ref: '#/components/schemas/BindingResp' + BindingResp: + type: object + properties: + pcfSmFqdn: + $ref: 'TS29510_Nnrf_NFManagement.yaml#/components/schemas/Fqdn' + pcfSmIpEndPoints: + type: array + items: + $ref: 'TS29510_Nnrf_NFManagement.yaml#/components/schemas/IpEndPoint' + minItems: 1 + description: IP end points of the PCF hosting the Npcf_SMPolicyControl service. + BindingLevel: + anyOf: + - type: string + enum: + - NF_SET + - NF_INSTANCE + - type: string + description: > + This string provides forward-compatibility with future + extensions to the enumeration but is not used to encode + content defined in the present version of this API. + description: > + Possible values are + - "NF_SET" + - "NF_INSTANCE" diff --git a/src/amf/amf-sm.c b/src/amf/amf-sm.c index d9a29d603..2a65afe2b 100644 --- a/src/amf/amf-sm.c +++ b/src/amf/amf-sm.c @@ -202,9 +202,10 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) #if 0 CASE(OGS_SBI_RESOURCE_NAME_DEREG_NOTIFY) break; - CASE(OGS_SBI_RESOURCE_NAME_AM_POLICY_NOTIFY) - break; #endif + CASE(OGS_SBI_RESOURCE_NAME_AM_POLICY_NOTIFY) + ogs_sbi_send_http_status_no_content(stream); + break; DEFAULT ogs_error("Invalid resource name [%s]", diff --git a/src/amf/gmm-handler.c b/src/amf/gmm-handler.c index d9ce678b4..2b231a6e4 100644 --- a/src/amf/gmm-handler.c +++ b/src/amf/gmm-handler.c @@ -861,7 +861,7 @@ int gmm_handle_ul_nas_transport(amf_ue_t *amf_ue, { ogs_slice_data_t *selected_slice = NULL; amf_sess_t *sess = NULL; - amf_nsmf_pdusession_update_sm_context_param_t param; + amf_nsmf_pdusession_sm_context_param_t param; ogs_nas_payload_container_type_t *payload_container_type = NULL; ogs_nas_payload_container_t *payload_container = NULL; diff --git a/src/amf/ngap-handler.c b/src/amf/ngap-handler.c index a11f3ddaf..b05be017e 100644 --- a/src/amf/ngap-handler.c +++ b/src/amf/ngap-handler.c @@ -757,7 +757,7 @@ void ngap_handle_initial_context_setup_response( ran_ue_t *ran_ue = NULL; amf_sess_t *sess = NULL; uint64_t amf_ue_ngap_id; - amf_nsmf_pdusession_update_sm_context_param_t param; + amf_nsmf_pdusession_sm_context_param_t param; bool paging_ongoing = false; @@ -1390,7 +1390,7 @@ void ngap_handle_pdu_session_resource_setup_response( amf_ue_t *amf_ue = NULL; ran_ue_t *ran_ue = NULL; uint64_t amf_ue_ngap_id; - amf_nsmf_pdusession_update_sm_context_param_t param; + amf_nsmf_pdusession_sm_context_param_t param; NGAP_SuccessfulOutcome_t *successfulOutcome = NULL; NGAP_PDUSessionResourceSetupResponse_t *PDUSessionResourceSetupResponse; @@ -1563,7 +1563,7 @@ void ngap_handle_pdu_session_resource_modify_response( amf_ue_t *amf_ue = NULL; ran_ue_t *ran_ue = NULL; uint64_t amf_ue_ngap_id; - amf_nsmf_pdusession_update_sm_context_param_t param; + amf_nsmf_pdusession_sm_context_param_t param; NGAP_SuccessfulOutcome_t *successfulOutcome = NULL; NGAP_PDUSessionResourceModifyResponse_t *PDUSessionResourceModifyResponse; @@ -1736,7 +1736,7 @@ void ngap_handle_pdu_session_resource_release_response( amf_ue_t *amf_ue = NULL; ran_ue_t *ran_ue = NULL; uint64_t amf_ue_ngap_id; - amf_nsmf_pdusession_update_sm_context_param_t param; + amf_nsmf_pdusession_sm_context_param_t param; NGAP_SuccessfulOutcome_t *successfulOutcome = NULL; NGAP_PDUSessionResourceReleaseResponse_t @@ -2058,7 +2058,7 @@ void ngap_handle_path_switch_request( NGAP_PDUSessionResourceToBeSwitchedDLItem_t *PDUSessionItem = NULL; OCTET_STRING_t *transfer = NULL; - amf_nsmf_pdusession_update_sm_context_param_t param; + amf_nsmf_pdusession_sm_context_param_t param; ogs_assert(gnb); ogs_assert(gnb->sctp.sock); @@ -2354,7 +2354,7 @@ void ngap_handle_handover_required( NGAP_SourceToTarget_TransparentContainer_t *SourceToTarget_TransparentContainer = NULL; - amf_nsmf_pdusession_update_sm_context_param_t param; + amf_nsmf_pdusession_sm_context_param_t param; ogs_assert(gnb); ogs_assert(gnb->sctp.sock); @@ -2646,7 +2646,7 @@ void ngap_handle_handover_request_ack( amf_ue_t *amf_ue = NULL; ran_ue_t *source_ue = NULL, *target_ue = NULL; uint64_t amf_ue_ngap_id; - amf_nsmf_pdusession_update_sm_context_param_t param; + amf_nsmf_pdusession_sm_context_param_t param; NGAP_SuccessfulOutcome_t *successfulOutcome = NULL; NGAP_HandoverRequestAcknowledge_t *HandoverRequestAcknowledge = NULL; @@ -2981,7 +2981,7 @@ void ngap_handle_handover_cancel( amf_sess_t *sess = NULL; ran_ue_t *source_ue = NULL, *target_ue = NULL; uint64_t amf_ue_ngap_id; - amf_nsmf_pdusession_update_sm_context_param_t param; + amf_nsmf_pdusession_sm_context_param_t param; NGAP_InitiatingMessage_t *initiatingMessage = NULL; NGAP_HandoverCancel_t *HandoverCancel = NULL; @@ -3226,7 +3226,7 @@ void ngap_handle_handover_notification( amf_sess_t *sess = NULL; ran_ue_t *source_ue = NULL, *target_ue = NULL; uint64_t amf_ue_ngap_id; - amf_nsmf_pdusession_update_sm_context_param_t param; + amf_nsmf_pdusession_sm_context_param_t param; NGAP_InitiatingMessage_t *initiatingMessage = NULL; NGAP_HandoverNotify_t *HandoverNotify = NULL; diff --git a/src/amf/nsmf-build.c b/src/amf/nsmf-build.c index db444981f..bfdd56d86 100644 --- a/src/amf/nsmf-build.c +++ b/src/amf/nsmf-build.c @@ -159,7 +159,7 @@ ogs_sbi_request_t *amf_nsmf_pdusession_build_create_sm_context( ogs_sbi_request_t *amf_nsmf_pdusession_build_update_sm_context( amf_sess_t *sess, void *data) { - amf_nsmf_pdusession_update_sm_context_param_t *param = data; + amf_nsmf_pdusession_sm_context_param_t *param = data; ogs_sbi_message_t message; ogs_sbi_request_t *request = NULL; @@ -274,12 +274,15 @@ ogs_sbi_request_t *amf_nsmf_pdusession_build_update_sm_context( ogs_sbi_request_t *amf_nsmf_pdusession_build_release_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; amf_ue_t *amf_ue = NULL; OpenAPI_sm_context_release_data_t SmContextReleaseData; + OpenAPI_ng_ap_cause_t ngApCause; OpenAPI_user_location_t ueLocation; ogs_assert(sess); @@ -298,6 +301,19 @@ ogs_sbi_request_t *amf_nsmf_pdusession_build_release_sm_context( memset(&SmContextReleaseData, 0, sizeof(SmContextReleaseData)); + if (param) { + SmContextReleaseData.cause = param->cause; + + if (param->ngApCause.group) { + SmContextReleaseData.ng_ap_cause = &ngApCause; + memset(&ngApCause, 0, sizeof(ngApCause)); + ngApCause.group = param->ngApCause.group; + ngApCause.value = param->ngApCause.value; + } + + SmContextReleaseData._5g_mm_cause_value = param->gmm_cause; + } + memset(&ueLocation, 0, sizeof(ueLocation)); ueLocation.nr_location = ogs_sbi_build_nr_location( &amf_ue->nr_tai, &amf_ue->nr_cgi); diff --git a/src/amf/nsmf-build.h b/src/amf/nsmf-build.h index 90f02832a..9172ad0f2 100644 --- a/src/amf/nsmf-build.h +++ b/src/amf/nsmf-build.h @@ -26,7 +26,7 @@ extern "C" { #endif -typedef struct amf_nsmf_pdusession_update_sm_context_param_s { +typedef struct amf_nsmf_pdusession_sm_context_param_s { ogs_pkbuf_t *n1smbuf; ogs_pkbuf_t *n2smbuf; OpenAPI_n2_sm_info_type_e n2SmInfoType; @@ -46,11 +46,12 @@ typedef struct amf_nsmf_pdusession_update_sm_context_param_s { int release; OpenAPI_cause_e cause; + int gmm_cause; OpenAPI_ho_state_e hoState; OpenAPI_ng_ran_target_id_t *targetId; NGAP_TargetID_t *TargetID; -} amf_nsmf_pdusession_update_sm_context_param_t; +} amf_nsmf_pdusession_sm_context_param_t; ogs_sbi_request_t *amf_nsmf_pdusession_build_create_sm_context( amf_sess_t *sess, void *data); diff --git a/src/amf/sbi-path.c b/src/amf/sbi-path.c index 65af898d7..919caba6e 100644 --- a/src/amf/sbi-path.c +++ b/src/amf/sbi-path.c @@ -282,7 +282,7 @@ void amf_sess_sbi_discover_by_nsi( void amf_sbi_send_activating_session(amf_sess_t *sess, int state) { - amf_nsmf_pdusession_update_sm_context_param_t param; + amf_nsmf_pdusession_sm_context_param_t param; ogs_assert(sess); @@ -297,7 +297,7 @@ void amf_sbi_send_activating_session(amf_sess_t *sess, int state) void amf_sbi_send_deactivate_session( amf_sess_t *sess, int state, int group, int cause) { - amf_nsmf_pdusession_update_sm_context_param_t param; + amf_nsmf_pdusession_sm_context_param_t param; ogs_assert(sess); diff --git a/src/bsf/app.c b/src/bsf/app.c new file mode 100644 index 000000000..98bb4ef67 --- /dev/null +++ b/src/bsf/app.c @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-app.h" + +int app_initialize(const char *const argv[]) +{ + int rv; + + rv = bsf_initialize(); + if (rv != OGS_OK) { + ogs_error("Failed to intialize BSF"); + return rv; + } + ogs_info("BSF initialize...done"); + + return OGS_OK; +} + +void app_terminate(void) +{ + bsf_terminate(); + ogs_info("BSF terminate...done"); +} diff --git a/src/bsf/bsf-sm.c b/src/bsf/bsf-sm.c new file mode 100644 index 000000000..1fd8d4ef0 --- /dev/null +++ b/src/bsf/bsf-sm.c @@ -0,0 +1,354 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "sbi-path.h" +#include "nnrf-handler.h" +#include "nbsf-handler.h" + +void bsf_state_initial(ogs_fsm_t *s, bsf_event_t *e) +{ + bsf_sm_debug(e); + + ogs_assert(s); + + OGS_FSM_TRAN(s, &bsf_state_operational); +} + +void bsf_state_final(ogs_fsm_t *s, bsf_event_t *e) +{ + bsf_sm_debug(e); + + ogs_assert(s); +} + +void bsf_state_operational(ogs_fsm_t *s, bsf_event_t *e) +{ + int rv; + + bsf_sess_t *sess = NULL; + + ogs_sbi_stream_t *stream = NULL; + ogs_sbi_request_t *request = NULL; + + ogs_sbi_nf_instance_t *nf_instance = NULL; + ogs_sbi_subscription_t *subscription = NULL; + ogs_sbi_response_t *response = NULL; + ogs_sbi_message_t message; + ogs_sbi_xact_t *sbi_xact = NULL; + + bsf_sm_debug(e); + + ogs_assert(s); + + switch (e->id) { + case OGS_FSM_ENTRY_SIG: + break; + + case OGS_FSM_EXIT_SIG: + break; + + case BSF_EVT_SBI_SERVER: + request = e->sbi.request; + ogs_assert(request); + stream = e->sbi.data; + ogs_assert(stream); + + rv = ogs_sbi_parse_request(&message, request); + if (rv != OGS_OK) { + /* 'sbi_message' buffer is released in ogs_sbi_parse_request() */ + ogs_error("cannot parse HTTP sbi_message"); + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + NULL, "cannot parse HTTP sbi_message", NULL); + break; + } + + if (strcmp(message.h.api.version, OGS_SBI_API_V1) != 0) { + ogs_error("Not supported version [%s]", message.h.api.version); + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + &message, "Not supported version", NULL); + ogs_sbi_message_free(&message); + break; + } + + SWITCH(message.h.service.name) + CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) + + SWITCH(message.h.resource.component[0]) + CASE(OGS_SBI_RESOURCE_NAME_NF_STATUS_NOTIFY) + SWITCH(message.h.method) + CASE(OGS_SBI_HTTP_METHOD_POST) + bsf_nnrf_handle_nf_status_notify(stream, &message); + break; + + DEFAULT + ogs_error("Invalid HTTP method [%s]", message.h.method); + ogs_sbi_server_send_error(stream, + OGS_SBI_HTTP_STATUS_FORBIDDEN, &message, + "Invalid HTTP method", message.h.method); + END + break; + + DEFAULT + ogs_error("Invalid resource name [%s]", + message.h.resource.component[0]); + ogs_sbi_server_send_error(stream, + OGS_SBI_HTTP_STATUS_BAD_REQUEST, &message, + "Invalid resource name", + message.h.resource.component[0]); + END + break; + + 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 = bsf_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 = bsf_sess_find_by_snssai_and_dnn( + &s_nssai, message.PcfBinding->dnn); + if (!sess) { + sess = bsf_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 = bsf_sess_find_by_ipv4addr( + message.param.ipv4addr); + if (!sess && message.param.ipv6prefix) + sess = bsf_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_sbi_server_send_error(stream, + OGS_SBI_HTTP_STATUS_NOT_FOUND, + &message, "Not found", message.h.uri); + break; + } + + bsf_nbsf_management_handle_pcf_binding(sess, stream, &message); + break; + + DEFAULT + ogs_error("Invalid resource name [%s]", + message.h.resource.component[0]); + ogs_sbi_server_send_error(stream, + OGS_SBI_HTTP_STATUS_BAD_REQUEST, &message, + "Invalid resource name", + message.h.resource.component[0]); + END + break; + + DEFAULT + ogs_error("Invalid API name [%s]", message.h.service.name); + ogs_sbi_server_send_error(stream, + OGS_SBI_HTTP_STATUS_BAD_REQUEST, &message, + "Invalid API name", message.h.service.name); + END + + /* In lib/sbi/server.c, notify_completed() releases 'request' buffer. */ + ogs_sbi_message_free(&message); + break; + + case BSF_EVT_SBI_CLIENT: + ogs_assert(e); + + response = e->sbi.response; + ogs_assert(response); + rv = ogs_sbi_parse_response(&message, response); + if (rv != OGS_OK) { + ogs_error("cannot parse HTTP response"); + ogs_sbi_message_free(&message); + ogs_sbi_response_free(response); + break; + } + + if (strcmp(message.h.api.version, OGS_SBI_API_V1) != 0) { + ogs_error("Not supported version [%s]", message.h.api.version); + ogs_sbi_message_free(&message); + ogs_sbi_response_free(response); + break; + } + + SWITCH(message.h.service.name) + CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) + + SWITCH(message.h.resource.component[0]) + CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) + nf_instance = e->sbi.data; + ogs_assert(nf_instance); + ogs_assert(OGS_FSM_STATE(&nf_instance->sm)); + + e->sbi.message = &message; + ogs_fsm_dispatch(&nf_instance->sm, e); + break; + + CASE(OGS_SBI_RESOURCE_NAME_SUBSCRIPTIONS) + subscription = e->sbi.data; + ogs_assert(subscription); + + SWITCH(message.h.method) + CASE(OGS_SBI_HTTP_METHOD_POST) + if (message.res_status == OGS_SBI_HTTP_STATUS_CREATED || + message.res_status == OGS_SBI_HTTP_STATUS_OK) { + bsf_nnrf_handle_nf_status_subscribe( + subscription, &message); + } else { + ogs_error("HTTP response error : %d", + message.res_status); + } + break; + + CASE(OGS_SBI_HTTP_METHOD_DELETE) + if (message.res_status == OGS_SBI_HTTP_STATUS_NO_CONTENT) { + ogs_sbi_subscription_remove(subscription); + } 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; + + CASE(OGS_SBI_SERVICE_NAME_NNRF_DISC) + SWITCH(message.h.resource.component[0]) + CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) + sbi_xact = e->sbi.data; + ogs_assert(sbi_xact); + + SWITCH(message.h.method) + CASE(OGS_SBI_HTTP_METHOD_GET) + if (message.res_status == OGS_SBI_HTTP_STATUS_OK) + bsf_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(); + END + + ogs_sbi_message_free(&message); + ogs_sbi_response_free(response); + break; + + case BSF_EVT_SBI_TIMER: + ogs_assert(e); + + switch(e->timer_id) { + case BSF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: + case BSF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: + case BSF_TIMER_NF_INSTANCE_NO_HEARTBEAT: + case BSF_TIMER_NF_INSTANCE_VALIDITY: + nf_instance = e->sbi.data; + ogs_assert(nf_instance); + ogs_assert(OGS_FSM_STATE(&nf_instance->sm)); + + ogs_fsm_dispatch(&nf_instance->sm, e); + if (OGS_FSM_CHECK(&nf_instance->sm, bsf_nf_state_exception)) + ogs_error("State machine exception [%d]", e->timer_id); + break; + + case BSF_TIMER_SUBSCRIPTION_VALIDITY: + subscription = e->sbi.data; + ogs_assert(subscription); + + ogs_nnrf_nfm_send_nf_status_subscribe(subscription->client, + bsf_self()->nf_type, subscription->req_nf_instance_id, + subscription->subscr_cond.nf_type); + + ogs_info("Subscription validity expired [%s]", subscription->id); + ogs_sbi_subscription_remove(subscription); + break; + + case BSF_TIMER_SBI_CLIENT_WAIT: + sbi_xact = e->sbi.data; + ogs_assert(sbi_xact); + + stream = sbi_xact->assoc_stream; + /* Here, we should not use ogs_assert(stream) + * since 'namf-comm' service has no an associated stream. */ + + ogs_sbi_xact_remove(sbi_xact); + + ogs_error("Cannot receive SBI message"); + if (stream) { + ogs_sbi_server_send_error(stream, + OGS_SBI_HTTP_STATUS_GATEWAY_TIMEOUT, NULL, + "Cannot receive SBI message", NULL); + } + break; + + default: + ogs_error("Unknown timer[%s:%d]", + bsf_timer_get_name(e->timer_id), e->timer_id); + } + break; + + default: + ogs_error("No handler for event %s", bsf_event_get_name(e)); + break; + } +} diff --git a/src/bsf/bsf-sm.h b/src/bsf/bsf-sm.h new file mode 100644 index 000000000..e4808f16e --- /dev/null +++ b/src/bsf/bsf-sm.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef BSF_SM_H +#define BSF_SM_H + +#include "event.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void bsf_state_initial(ogs_fsm_t *s, bsf_event_t *e); +void bsf_state_final(ogs_fsm_t *s, bsf_event_t *e); +void bsf_state_operational(ogs_fsm_t *s, bsf_event_t *e); +void bsf_state_exception(ogs_fsm_t *s, bsf_event_t *e); + +void bsf_nf_fsm_init(ogs_sbi_nf_instance_t *nf_instance); +void bsf_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance); + +void bsf_nf_state_initial(ogs_fsm_t *s, bsf_event_t *e); +void bsf_nf_state_final(ogs_fsm_t *s, bsf_event_t *e); +void bsf_nf_state_will_register(ogs_fsm_t *s, bsf_event_t *e); +void bsf_nf_state_registered(ogs_fsm_t *s, bsf_event_t *e); +void bsf_nf_state_de_registered(ogs_fsm_t *s, bsf_event_t *e); +void bsf_nf_state_exception(ogs_fsm_t *s, bsf_event_t *e); + +#define bsf_sm_debug(__pe) \ + ogs_debug("%s(): %s", __func__, bsf_event_get_name(__pe)) + +#ifdef __cplusplus +} +#endif + +#endif /* BSF_SM_H */ diff --git a/src/bsf/context.c b/src/bsf/context.c new file mode 100644 index 000000000..be6aee19e --- /dev/null +++ b/src/bsf/context.c @@ -0,0 +1,336 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "context.h" + +static bsf_context_t self; + +int __bsf_log_domain; + +static OGS_POOL(bsf_sess_pool, bsf_sess_t); + +static int context_initialized = 0; + +static void clear_ipv4addr(bsf_sess_t *sess); +static void clear_ipv6prefix(bsf_sess_t *sess); + +void bsf_context_init(void) +{ + ogs_assert(context_initialized == 0); + + /* Initialize BSF context */ + memset(&self, 0, sizeof(bsf_context_t)); + + ogs_log_install_domain(&__bsf_log_domain, "bsf", ogs_core()->log.level); + + ogs_pool_init(&bsf_sess_pool, ogs_app()->pool.sess); + + self.ipv4addr_hash = ogs_hash_make(); + self.ipv6prefix_hash = ogs_hash_make(); + + context_initialized = 1; +} + +void bsf_context_final(void) +{ + ogs_assert(context_initialized == 1); + + bsf_sess_remove_all(); + + ogs_assert(self.ipv4addr_hash); + ogs_hash_destroy(self.ipv4addr_hash); + ogs_assert(self.ipv6prefix_hash); + ogs_hash_destroy(self.ipv6prefix_hash); + + ogs_pool_final(&bsf_sess_pool); + + context_initialized = 0; +} + +bsf_context_t *bsf_self(void) +{ + return &self; +} + +static int bsf_context_prepare(void) +{ + self.nf_type = OpenAPI_nf_type_BSF; + + return OGS_OK; +} + +static int bsf_context_validation(void) +{ + return OGS_OK; +} + +int bsf_context_parse_config(void) +{ + int rv; + yaml_document_t *document = NULL; + ogs_yaml_iter_t root_iter; + + document = ogs_app()->document; + ogs_assert(document); + + rv = bsf_context_prepare(); + if (rv != OGS_OK) return rv; + + ogs_yaml_iter_init(&root_iter, document); + while (ogs_yaml_iter_next(&root_iter)) { + const char *root_key = ogs_yaml_iter_key(&root_iter); + ogs_assert(root_key); + if (!strcmp(root_key, "bsf")) { + ogs_yaml_iter_t bsf_iter; + ogs_yaml_iter_recurse(&root_iter, &bsf_iter); + while (ogs_yaml_iter_next(&bsf_iter)) { + const char *bsf_key = ogs_yaml_iter_key(&bsf_iter); + ogs_assert(bsf_key); + if (!strcmp(bsf_key, "sbi")) { + /* handle config in sbi library */ + } else + ogs_warn("unknown key `%s`", bsf_key); + } + } + } + + rv = bsf_context_validation(); + if (rv != OGS_OK) return rv; + + return OGS_OK; +} + +bsf_sess_t *bsf_sess_add_by_snssai_and_dnn(ogs_s_nssai_t *s_nssai, char *dnn) +{ + bsf_sess_t *sess = NULL; + + ogs_assert(s_nssai); + ogs_assert(s_nssai->sst); + ogs_assert(dnn); + + ogs_pool_alloc(&bsf_sess_pool, &sess); + if (!sess) { + ogs_error("Maximum number of session[%lld] reached", + (long long)ogs_app()->pool.sess); + return NULL; + } + memset(sess, 0, sizeof *sess); + + /* SBI Features */ + OGS_SBI_FEATURES_SET(sess->management_features, + OGS_SBI_NBSF_MANAGEMENT_BINDING_UPDATE); + + sess->s_nssai.sst = s_nssai->sst; + sess->s_nssai.sd.v = s_nssai->sd.v; + + sess->dnn = ogs_strdup(dnn); + ogs_assert(sess->dnn); + + sess->binding_id = ogs_msprintf("%d", + (int)ogs_pool_index(&bsf_sess_pool, sess)); + ogs_assert(sess->binding_id); + + ogs_list_add(&self.sess_list, sess); + + return sess; +} + +void bsf_sess_remove(bsf_sess_t *sess) +{ + int i; + + ogs_assert(sess); + + ogs_list_remove(&self.sess_list, sess); + + /* Free SBI object memory */ + ogs_sbi_object_free(&sess->sbi); + + ogs_assert(sess->binding_id); + ogs_free(sess->binding_id); + + if (sess->supi) + ogs_free(sess->supi); + if (sess->gpsi) + ogs_free(sess->gpsi); + + clear_ipv4addr(sess); + clear_ipv6prefix(sess); + + ogs_assert(sess->dnn); + ogs_free(sess->dnn); + + if (sess->pcf_fqdn) + ogs_free(sess->pcf_fqdn); + + for (i = 0; i < sess->num_of_pcf_ip; i++) { + if (sess->pcf_ip[i].addr) + ogs_free(sess->pcf_ip[i].addr); + if (sess->pcf_ip[i].addr6) + ogs_free(sess->pcf_ip[i].addr6); + } + sess->num_of_pcf_ip = 0; + + ogs_pool_free(&bsf_sess_pool, sess); +} + +void bsf_sess_remove_all(void) +{ + bsf_sess_t *sess = NULL, *next_sess = NULL; + + ogs_list_for_each_safe(&self.sess_list, next_sess, sess) + bsf_sess_remove(sess); +} + +static void clear_ipv4addr(bsf_sess_t *sess) +{ + ogs_assert(sess); + + if (sess->ipv4addr_string) { + ogs_hash_set(self.ipv4addr_hash, + &sess->ipv4addr, sizeof(sess->ipv4addr), NULL); + ogs_free(sess->ipv4addr_string); + } +} + +static void clear_ipv6prefix(bsf_sess_t *sess) +{ + ogs_assert(sess); + + if (sess->ipv6prefix_string) { + ogs_hash_set(self.ipv6prefix_hash, + &sess->ipv6prefix, (sess->ipv6prefix.len >> 3) + 1, NULL); + ogs_free(sess->ipv6prefix_string); + } +} + +bool bsf_sess_set_ipv4addr(bsf_sess_t *sess, char *ipv4addr_string) +{ + int rv; + + ogs_assert(sess); + ogs_assert(ipv4addr_string); + + clear_ipv4addr(sess); + + rv = ogs_ipv4_from_string(&sess->ipv4addr, ipv4addr_string); + ogs_expect_or_return_val(rv == OGS_OK, false); + + sess->ipv4addr_string = ogs_strdup(ipv4addr_string); + ogs_expect_or_return_val(sess->ipv4addr_string, false); + + ogs_hash_set(self.ipv4addr_hash, + &sess->ipv4addr, sizeof(sess->ipv4addr), sess); + + return true; +} + +bool bsf_sess_set_ipv6prefix(bsf_sess_t *sess, char *ipv6prefix_string) +{ + int rv; + + ogs_assert(sess); + ogs_assert(ipv6prefix_string); + + clear_ipv6prefix(sess); + + rv = ogs_ipv6prefix_from_string( + sess->ipv6prefix.addr6, &sess->ipv6prefix.len, ipv6prefix_string); + ogs_expect_or_return_val(rv == OGS_OK, false); + + ogs_assert(sess->ipv6prefix.len == OGS_IPV6_128_PREFIX_LEN); + + sess->ipv6prefix_string = ogs_strdup(ipv6prefix_string); + ogs_expect_or_return_val(sess->ipv6prefix_string, false); + + ogs_hash_set(self.ipv6prefix_hash, + &sess->ipv6prefix, (sess->ipv6prefix.len >> 3) + 1, sess); + + return true; +} + +bsf_sess_t *bsf_sess_find(uint32_t index) +{ + return ogs_pool_find(&bsf_sess_pool, index); +} + +bsf_sess_t *bsf_sess_find_by_snssai_and_dnn(ogs_s_nssai_t *s_nssai, char *dnn) +{ + bsf_sess_t *sess = NULL; + + ogs_assert(s_nssai); + ogs_assert(dnn); + + ogs_list_for_each(&self.sess_list, sess) + if (sess->s_nssai.sst == s_nssai->sst && + sess->dnn && strcmp(sess->dnn, dnn) == 0) + return sess; + + return NULL; +} + +bsf_sess_t *bsf_sess_find_by_binding_id(char *binding_id) +{ + ogs_assert(binding_id); + return bsf_sess_find(atoll(binding_id)); +} + +bsf_sess_t *bsf_sess_find_by_ipv4addr(char *ipv4addr_string) +{ + uint32_t ipv4addr; + int rv; + + ogs_assert(ipv4addr_string); + + rv = ogs_ipv4_from_string(&ipv4addr, ipv4addr_string); + ogs_expect_or_return_val(rv == OGS_OK, NULL); + + return ogs_hash_get(self.ipv4addr_hash, &ipv4addr, sizeof(ipv4addr)); +} + +bsf_sess_t *bsf_sess_find_by_ipv6prefix(char *ipv6prefix_string) +{ + int rv; + struct { + uint8_t len; + uint8_t addr6[OGS_IPV6_LEN]; + } ipv6prefix; + + ogs_assert(ipv6prefix_string); + + rv = ogs_ipv6prefix_from_string( + ipv6prefix.addr6, &ipv6prefix.len, ipv6prefix_string); + ogs_expect_or_return_val(rv == OGS_OK, NULL); + + ogs_assert(ipv6prefix.len == OGS_IPV6_128_PREFIX_LEN); + + return ogs_hash_get(self.ipv6prefix_hash, + &ipv6prefix, (ipv6prefix.len >> 3) + 1); +} + +void bsf_sess_select_nf(bsf_sess_t *sess, OpenAPI_nf_type_e nf_type) +{ + ogs_assert(sess); + ogs_assert(nf_type); + + if (nf_type == OpenAPI_nf_type_NRF) + ogs_sbi_select_nrf(&sess->sbi, bsf_nf_state_registered); + else + ogs_sbi_select_first_nf(&sess->sbi, nf_type, bsf_nf_state_registered); +} diff --git a/src/bsf/context.h b/src/bsf/context.h new file mode 100644 index 000000000..f5fc5dd2f --- /dev/null +++ b/src/bsf/context.h @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef BSF_CONTEXT_H +#define BSF_CONTEXT_H + +#include "ogs-sbi.h" +#include "ogs-app.h" + +#include "timer.h" +#include "bsf-sm.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern int __bsf_log_domain; + +#undef OGS_LOG_DOMAIN +#define OGS_LOG_DOMAIN __bsf_log_domain + +typedef struct bsf_context_s { + OpenAPI_nf_type_e nf_type; + + ogs_hash_t *ipv4addr_hash; + ogs_hash_t *ipv6prefix_hash; + + ogs_list_t sess_list; +} bsf_context_t; + +#define BSF_NF_INSTANCE_CLEAR(_cAUSE, _nFInstance) \ + do { \ + ogs_assert(_nFInstance); \ + if ((_nFInstance)->reference_count == 1) { \ + ogs_info("[%s] (%s) NF removed", (_nFInstance)->id, (_cAUSE)); \ + bsf_nf_fsm_fini((_nFInstance)); \ + } else { \ + /* There is an assocation with other context */ \ + ogs_info("[%s:%d] (%s) NF suspended", \ + _nFInstance->id, _nFInstance->reference_count, (_cAUSE)); \ + OGS_FSM_TRAN(&_nFInstance->sm, bsf_nf_state_de_registered); \ + ogs_fsm_dispatch(&_nFInstance->sm, NULL); \ + } \ + ogs_sbi_nf_instance_remove(_nFInstance); \ + } while(0) + +typedef struct bsf_sess_s bsf_sess_t; + +typedef struct bsf_sess_s { + ogs_sbi_object_t sbi; + + char *binding_id; + + char *supi; + char *gpsi; + + char *ipv4addr_string; + char *ipv6prefix_string; + + uint32_t ipv4addr; + struct { + uint8_t len; + uint8_t addr6[OGS_IPV6_LEN]; + } ipv6prefix; + + ogs_s_nssai_t s_nssai; + char *dnn; + + /* PCF address information */ + char *pcf_fqdn; + + int num_of_pcf_ip; + struct { + char *addr; + char *addr6; + int port; + } pcf_ip[OGS_SBI_MAX_NUM_OF_IP_ADDRESS]; + + /* SBI Features */ + uint64_t management_features; + +} bsf_sess_t; + +void bsf_context_init(void); +void bsf_context_final(void); +bsf_context_t *bsf_self(void); + +int bsf_context_parse_config(void); + +bsf_sess_t *bsf_sess_add_by_snssai_and_dnn(ogs_s_nssai_t *s_nssai, char *dnn); +void bsf_sess_remove(bsf_sess_t *sess); +void bsf_sess_remove_all(void); + +bool bsf_sess_set_ipv4addr(bsf_sess_t *sess, char *ipv4addr); +bool bsf_sess_set_ipv6prefix(bsf_sess_t *sess, char *ipv6prefix); + +bsf_sess_t *bsf_sess_find(uint32_t index); +bsf_sess_t *bsf_sess_find_by_snssai_and_dnn(ogs_s_nssai_t *s_nssai, char *dnn); +bsf_sess_t *bsf_sess_find_by_binding_id(char *binding_id); +bsf_sess_t *bsf_sess_find_by_ipv4addr(char *ipv4addr_string); +bsf_sess_t *bsf_sess_find_by_ipv6prefix(char *ipv6prefix_string); + +void bsf_sess_select_nf(bsf_sess_t *sess, OpenAPI_nf_type_e nf_type); + +#ifdef __cplusplus +} +#endif + +#endif /* BSF_CONTEXT_H */ diff --git a/src/bsf/event.c b/src/bsf/event.c new file mode 100644 index 000000000..7f65f76c3 --- /dev/null +++ b/src/bsf/event.c @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "event.h" +#include "context.h" + +static OGS_POOL(pool, bsf_event_t); + +void bsf_event_init(void) +{ + ogs_pool_init(&pool, ogs_app()->pool.event); +} + +void bsf_event_final(void) +{ + ogs_pool_final(&pool); +} + +bsf_event_t *bsf_event_new(bsf_event_e id) +{ + bsf_event_t *e = NULL; + + ogs_pool_alloc(&pool, &e); + ogs_assert(e); + memset(e, 0, sizeof(*e)); + + e->id = id; + + return e; +} + +void bsf_event_free(bsf_event_t *e) +{ + ogs_assert(e); + ogs_pool_free(&pool, e); +} + +const char *bsf_event_get_name(bsf_event_t *e) +{ + if (e == NULL) + return OGS_FSM_NAME_INIT_SIG; + + switch (e->id) { + case OGS_FSM_ENTRY_SIG: + return OGS_FSM_NAME_ENTRY_SIG; + case OGS_FSM_EXIT_SIG: + return OGS_FSM_NAME_EXIT_SIG; + + case BSF_EVT_SBI_SERVER: + return "BSF_EVT_SBI_SERVER"; + case BSF_EVT_SBI_CLIENT: + return "BSF_EVT_SBI_CLIENT"; + case BSF_EVT_SBI_TIMER: + return "BSF_EVT_SBI_TIMER"; + + default: + break; + } + + return "UNKNOWN_EVENT"; +} diff --git a/src/bsf/event.h b/src/bsf/event.h new file mode 100644 index 000000000..f466b06c1 --- /dev/null +++ b/src/bsf/event.h @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef BSF_EVENT_H +#define BSF_EVENT_H + +#include "ogs-core.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct bsf_sess_s bsf_sess_t; +typedef struct ogs_sbi_request_s ogs_sbi_request_t; +typedef struct ogs_sbi_response_s ogs_sbi_response_t; +typedef struct ogs_sbi_message_s ogs_sbi_message_t; +typedef struct ogs_sbi_subscription_s ogs_sbi_subscription_t; + +typedef enum { + BSF_EVT_BASE = OGS_FSM_USER_SIG, + + BSF_EVT_SBI_SERVER, + BSF_EVT_SBI_CLIENT, + BSF_EVT_SBI_TIMER, + + BSF_EVT_TOP, + +} bsf_event_e; + +typedef struct bsf_event_s { + int id; + ogs_pkbuf_t *pkbuf; + int timer_id; + + struct { + ogs_sbi_request_t *request; + ogs_sbi_response_t *response; + void *data; + int state; + + ogs_sbi_message_t *message; + } sbi; + + bsf_sess_t *sess; +} bsf_event_t; + +void bsf_event_init(void); +void bsf_event_final(void); + +bsf_event_t *bsf_event_new(bsf_event_e id); +void bsf_event_free(bsf_event_t *e); + +const char *bsf_event_get_name(bsf_event_t *e); + +#ifdef __cplusplus +} +#endif + +#endif /* BSF_EVENT_H */ diff --git a/src/bsf/init.c b/src/bsf/init.c new file mode 100644 index 000000000..548f68322 --- /dev/null +++ b/src/bsf/init.c @@ -0,0 +1,142 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "context.h" +#include "sbi-path.h" + +static ogs_thread_t *thread; +static void bsf_main(void *data); + +static int initialized = 0; + +int bsf_initialize() +{ + int rv; + + bsf_context_init(); + bsf_event_init(); + ogs_sbi_context_init(); + + rv = ogs_sbi_context_parse_config("bsf", "nrf"); + if (rv != OGS_OK) return rv; + + rv = bsf_context_parse_config(); + if (rv != OGS_OK) return rv; + + rv = ogs_log_config_domain( + ogs_app()->logger.domain, ogs_app()->logger.level); + if (rv != OGS_OK) return rv; + + rv = bsf_sbi_open(); + if (rv != 0) return OGS_ERROR; + + thread = ogs_thread_create(bsf_main, NULL); + if (!thread) return OGS_ERROR; + + initialized = 1; + + return OGS_OK; +} + +static ogs_timer_t *t_termination_holding = NULL; + +static void event_termination(void) +{ + ogs_sbi_nf_instance_t *nf_instance = NULL; + + /* Sending NF Instance De-registeration to NRF */ + ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) + bsf_nf_fsm_fini(nf_instance); + + /* Starting holding timer */ + t_termination_holding = ogs_timer_add(ogs_app()->timer_mgr, NULL, NULL); + ogs_assert(t_termination_holding); +#define TERMINATION_HOLDING_TIME ogs_time_from_msec(300) + ogs_timer_start(t_termination_holding, TERMINATION_HOLDING_TIME); + + /* Sending termination event to the queue */ + ogs_queue_term(ogs_app()->queue); + ogs_pollset_notify(ogs_app()->pollset); +} + +void bsf_terminate(void) +{ + if (!initialized) return; + + /* Daemon terminating */ + event_termination(); + ogs_thread_destroy(thread); + ogs_timer_delete(t_termination_holding); + + bsf_sbi_close(); + + bsf_context_final(); + + ogs_sbi_context_final(); + + bsf_event_final(); /* Destroy event */ +} + +static void bsf_main(void *data) +{ + ogs_fsm_t bsf_sm; + int rv; + + ogs_fsm_create(&bsf_sm, bsf_state_initial, bsf_state_final); + ogs_fsm_init(&bsf_sm, 0); + + for ( ;; ) { + ogs_pollset_poll(ogs_app()->pollset, + ogs_timer_mgr_next(ogs_app()->timer_mgr)); + + /* + * After ogs_pollset_poll(), ogs_timer_mgr_expire() must be called. + * + * The reason is why ogs_timer_mgr_next() can get the corrent value + * when ogs_timer_stop() is called internally in ogs_timer_mgr_expire(). + * + * You should not use event-queue before ogs_timer_mgr_expire(). + * In this case, ogs_timer_mgr_expire() does not work + * because 'if rv == OGS_DONE' statement is exiting and + * not calling ogs_timer_mgr_expire(). + */ + ogs_timer_mgr_expire(ogs_app()->timer_mgr); + + for ( ;; ) { + bsf_event_t *e = NULL; + + rv = ogs_queue_trypop(ogs_app()->queue, (void**)&e); + ogs_assert(rv != OGS_ERROR); + + if (rv == OGS_DONE) + goto done; + + if (rv == OGS_RETRY) + break; + + ogs_assert(e); + ogs_fsm_dispatch(&bsf_sm, e); + bsf_event_free(e); + } + } +done: + + ogs_fsm_fini(&bsf_sm, 0); + ogs_fsm_delete(&bsf_sm); +} diff --git a/src/bsf/meson.build b/src/bsf/meson.build new file mode 100644 index 000000000..6f51df030 --- /dev/null +++ b/src/bsf/meson.build @@ -0,0 +1,59 @@ +# Copyright (C) 2019,2020 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +libbsf_sources = files(''' + context.c + event.c + timer.c + + nnrf-build.c + nnrf-handler.c + nf-sm.c + + nbsf-handler.c + + sbi-path.c + bsf-sm.c + + init.c +'''.split()) + +libbsf = static_library('bsf', + sources : libbsf_sources, + dependencies : [libapp_dep, + libcrypt_dep, + libsbi_dep], + install : false) + +libbsf_dep = declare_dependency( + link_with : libbsf, + dependencies : [libapp_dep, + libcrypt_dep, + libsbi_dep]) + +bsf_sources = files(''' + app.c + ../main.c +'''.split()) + +executable('open5gs-bsfd', + sources : bsf_sources, + c_args : '-DDEFAULT_CONFIG_FILENAME="@0@/bsf.yaml"'.format(open5gs_sysconfdir), + include_directories : srcinc, + dependencies : libbsf_dep, + install_rpath : libdir, + install : true) diff --git a/src/bsf/nbsf-handler.c b/src/bsf/nbsf-handler.c new file mode 100644 index 000000000..2d5d3aea0 --- /dev/null +++ b/src/bsf/nbsf-handler.c @@ -0,0 +1,289 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "sbi-path.h" +#include "nbsf-handler.h" + +bool bsf_nbsf_management_handle_pcf_binding( + bsf_sess_t *sess, ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) +{ + int status = 0; + char *strerror = NULL; + ogs_sbi_server_t *server = NULL; + + ogs_sbi_message_t sendmsg; + ogs_sbi_header_t header; + ogs_sbi_response_t *response = NULL; + + OpenAPI_pcf_binding_t *RecvPcfBinding = NULL; + OpenAPI_pcf_binding_t SendPcfBinding; + OpenAPI_snssai_t Snssai; + char fqdn[OGS_MAX_FQDN_LEN+1]; + int fqdn_len; + uint64_t supported_features = 0; + + ogs_assert(stream); + ogs_assert(recvmsg); + server = ogs_sbi_server_from_stream(stream); + ogs_assert(server); + + if (recvmsg->h.resource.component[1]) { + SWITCH(recvmsg->h.method) + CASE(OGS_SBI_HTTP_METHOD_DELETE) + memset(&sendmsg, 0, sizeof(sendmsg)); + + response = ogs_sbi_build_response( + &sendmsg, OGS_SBI_HTTP_STATUS_NO_CONTENT); + ogs_assert(response); + ogs_sbi_server_send_response(stream, response); + + ogs_free(sendmsg.http.location); + + bsf_sess_remove(sess); + break; + + CASE(OGS_SBI_HTTP_METHOD_PATCH) + break; + + DEFAULT + strerror = ogs_msprintf("Invalid HTTP method [%s]", + recvmsg->h.method); + status = OGS_SBI_HTTP_STATUS_BAD_REQUEST; + goto cleanup; + END + } else { + OpenAPI_list_t *PcfIpEndPointList = NULL; + OpenAPI_lnode_t *node = NULL; + int i; + + SWITCH(recvmsg->h.method) + CASE(OGS_SBI_HTTP_METHOD_POST) + + RecvPcfBinding = recvmsg->PcfBinding; + ogs_assert(RecvPcfBinding); + + if (!RecvPcfBinding->ipv4_addr && !RecvPcfBinding->ipv6_prefix) { + strerror = ogs_msprintf( + "No IPv4 address or IPv6 prefix[%p:%p]", + RecvPcfBinding->ipv4_addr, + RecvPcfBinding->ipv6_prefix); + status = OGS_SBI_HTTP_STATUS_BAD_REQUEST; + goto cleanup; + } + + if (!RecvPcfBinding->pcf_fqdn && + !RecvPcfBinding->pcf_ip_end_points) { + strerror = ogs_msprintf("No PCF address information [%p:%p]", + RecvPcfBinding->pcf_fqdn, + RecvPcfBinding->pcf_ip_end_points); + status = OGS_SBI_HTTP_STATUS_BAD_REQUEST; + goto cleanup; + } + + if (RecvPcfBinding->ipv4_addr) + bsf_sess_set_ipv4addr(sess, RecvPcfBinding->ipv4_addr); + if (RecvPcfBinding->ipv6_prefix) + bsf_sess_set_ipv6prefix(sess, RecvPcfBinding->ipv6_prefix); + + if (RecvPcfBinding->pcf_fqdn) { + ogs_fqdn_parse(fqdn, + RecvPcfBinding->pcf_fqdn, + strlen(RecvPcfBinding->pcf_fqdn)); + + if (sess->pcf_fqdn) + ogs_free(sess->pcf_fqdn); + sess->pcf_fqdn = ogs_strdup(fqdn); + } + + PcfIpEndPointList = RecvPcfBinding->pcf_ip_end_points; + + if (PcfIpEndPointList) { + for (i = 0; i < sess->num_of_pcf_ip; i++) { + if (sess->pcf_ip[i].addr) + ogs_free(sess->pcf_ip[i].addr); + if (sess->pcf_ip[i].addr6) + ogs_free(sess->pcf_ip[i].addr6); + } + sess->num_of_pcf_ip = 0; + + OpenAPI_list_for_each(PcfIpEndPointList, node) { + OpenAPI_ip_end_point_t *IpEndPoint = node->data; + int port = 0; + + if (!IpEndPoint) continue; + + if (sess->num_of_pcf_ip < OGS_SBI_MAX_NUM_OF_IP_ADDRESS) { + port = IpEndPoint->port; + if (!port) { + if (ogs_sbi_default_uri_scheme() == + OpenAPI_uri_scheme_http) + port = OGS_SBI_HTTP_PORT; + else if (ogs_sbi_default_uri_scheme() == + OpenAPI_uri_scheme_https) + port = OGS_SBI_HTTPS_PORT; + else { + ogs_fatal("Invalid scheme [%d]", + ogs_sbi_default_uri_scheme()); + ogs_assert_if_reached(); + } + } + + if (IpEndPoint->ipv4_address || + IpEndPoint->ipv6_address) { + if (IpEndPoint->ipv4_address) { + sess->pcf_ip[sess->num_of_pcf_ip].addr = + ogs_strdup(IpEndPoint->ipv4_address); + } + if (IpEndPoint->ipv6_address) { + sess->pcf_ip[sess->num_of_pcf_ip].addr6 = + ogs_strdup(IpEndPoint->ipv6_address); + } + sess->pcf_ip[sess->num_of_pcf_ip].port = port; + sess->num_of_pcf_ip++; + } + } + } + } + + if (RecvPcfBinding->supi) { + if (sess->supi) + ogs_free(sess->supi); + sess->supi = ogs_strdup(RecvPcfBinding->supi); + } + if (RecvPcfBinding->gpsi) { + if (sess->gpsi) + ogs_free(sess->gpsi); + sess->gpsi = ogs_strdup(RecvPcfBinding->gpsi); + } + + memset(&header, 0, sizeof(header)); + header.service.name = + (char *)OGS_SBI_SERVICE_NAME_NBSF_MANAGEMENT; + header.api.version = (char *)OGS_SBI_API_V1; + header.resource.component[0] = + (char *)OGS_SBI_RESOURCE_NAME_PCF_BINDINGS; + header.resource.component[1] = sess->binding_id; + + if (RecvPcfBinding->supp_feat) { + supported_features = + ogs_uint64_from_string(RecvPcfBinding->supp_feat); + sess->management_features &= supported_features; + } else { + sess->management_features = 0; + } + + memset(&sendmsg, 0, sizeof(sendmsg)); + sendmsg.PcfBinding = RecvPcfBinding; + sendmsg.http.location = ogs_sbi_server_uri(server, &header); + + response = ogs_sbi_build_response( + &sendmsg, OGS_SBI_HTTP_STATUS_CREATED); + ogs_assert(response); + ogs_sbi_server_send_response(stream, response); + + ogs_free(sendmsg.http.location); + break; + + CASE(OGS_SBI_HTTP_METHOD_GET) + if (sess->num_of_pcf_ip) { + memset(&Snssai, 0, sizeof(Snssai)); + Snssai.sst = sess->s_nssai.sst; + Snssai.sd = ogs_s_nssai_sd_to_string(sess->s_nssai.sd); + + memset(&SendPcfBinding, 0, sizeof(SendPcfBinding)); + + SendPcfBinding.dnn = sess->dnn; + SendPcfBinding.snssai = &Snssai; + + PcfIpEndPointList = OpenAPI_list_create(); + ogs_assert(PcfIpEndPointList); + + if (sess->pcf_fqdn && strlen(sess->pcf_fqdn)) { + memset(fqdn, 0, sizeof(fqdn)); + fqdn_len = ogs_fqdn_build(fqdn, + sess->pcf_fqdn, strlen(sess->pcf_fqdn)); + SendPcfBinding.pcf_fqdn = ogs_memdup(fqdn, fqdn_len); + } + + for (i = 0; i < sess->num_of_pcf_ip; i++) { + OpenAPI_ip_end_point_t *PcfIpEndPoint = NULL; + + ogs_assert(sess->pcf_ip[i].addr || sess->pcf_ip[i].addr6); + + PcfIpEndPoint = ogs_calloc(1, sizeof(*PcfIpEndPoint)); + ogs_assert(PcfIpEndPoint); + PcfIpEndPoint->ipv4_address = sess->pcf_ip[i].addr; + PcfIpEndPoint->ipv6_address = sess->pcf_ip[i].addr6; + PcfIpEndPoint->port = sess->pcf_ip[i].port; + + OpenAPI_list_add(PcfIpEndPointList, PcfIpEndPoint); + } + + if (PcfIpEndPointList->count) + SendPcfBinding.pcf_ip_end_points = PcfIpEndPointList; + else + OpenAPI_list_free(PcfIpEndPointList); + + memset(&sendmsg, 0, sizeof(sendmsg)); + sendmsg.PcfBinding = &SendPcfBinding; + + response = ogs_sbi_build_response( + &sendmsg, OGS_SBI_HTTP_STATUS_OK); + ogs_assert(response); + + ogs_sbi_server_send_response(stream, response); + + OpenAPI_list_for_each(SendPcfBinding.pcf_ip_end_points, node) { + OpenAPI_ip_end_point_t *PcfIpEndPoint = node->data; + if (PcfIpEndPoint) + ogs_free(PcfIpEndPoint); + } + OpenAPI_list_free(SendPcfBinding.pcf_ip_end_points); + + if (SendPcfBinding.pcf_fqdn) + ogs_free(SendPcfBinding.pcf_fqdn); + } else { + memset(&sendmsg, 0, sizeof(sendmsg)); + response = ogs_sbi_build_response( + &sendmsg, OGS_SBI_HTTP_STATUS_NO_CONTENT); + ogs_assert(response); + + ogs_sbi_server_send_response(stream, response); + } + break; + + DEFAULT + strerror = ogs_msprintf("Invalid HTTP method [%s]", + recvmsg->h.method); + status = OGS_SBI_HTTP_STATUS_BAD_REQUEST; + goto cleanup; + END + } + + return true; + +cleanup: + ogs_assert(strerror); + ogs_assert(status); + ogs_error("%s", strerror); + ogs_sbi_server_send_error(stream, status, recvmsg, strerror, NULL); + ogs_free(strerror); + + return false; +} diff --git a/src/bsf/nbsf-handler.h b/src/bsf/nbsf-handler.h new file mode 100644 index 000000000..0d76d59c0 --- /dev/null +++ b/src/bsf/nbsf-handler.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef BSF_NBSF_HANDLER_H +#define BSF_NBSF_HANDLER_H + +#include "context.h" + +#ifdef __cplusplus +extern "C" { +#endif + +bool bsf_nbsf_management_handle_pcf_binding( + bsf_sess_t *sess, ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); + +#ifdef __cplusplus +} +#endif + +#endif /* BSF_NBSF_HANDLER_H */ diff --git a/src/bsf/nf-sm.c b/src/bsf/nf-sm.c new file mode 100644 index 000000000..9bf7d9951 --- /dev/null +++ b/src/bsf/nf-sm.c @@ -0,0 +1,406 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "context.h" + +#include "sbi-path.h" +#include "nnrf-handler.h" + +void bsf_nf_fsm_init(ogs_sbi_nf_instance_t *nf_instance) +{ + bsf_event_t e; + + ogs_assert(nf_instance); + + memset(&e, 0, sizeof(e)); + e.sbi.data = nf_instance; + + ogs_fsm_create(&nf_instance->sm, + bsf_nf_state_initial, bsf_nf_state_final); + ogs_fsm_init(&nf_instance->sm, &e); +} + +void bsf_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance) +{ + bsf_event_t e; + + ogs_assert(nf_instance); + + memset(&e, 0, sizeof(e)); + e.sbi.data = nf_instance; + + ogs_fsm_fini(&nf_instance->sm, &e); + ogs_fsm_delete(&nf_instance->sm); +} + +void bsf_nf_state_initial(ogs_fsm_t *s, bsf_event_t *e) +{ + ogs_sbi_nf_instance_t *nf_instance = NULL; + + ogs_assert(s); + ogs_assert(e); + + bsf_sm_debug(e); + + nf_instance = e->sbi.data; + ogs_assert(nf_instance); + ogs_assert(nf_instance->id); + + ogs_assert(nf_instance->t_registration_interval); + nf_instance->t_registration_interval->cb = + bsf_timer_nf_instance_registration_interval; + ogs_assert(nf_instance->t_heartbeat_interval); + nf_instance->t_heartbeat_interval->cb = + bsf_timer_nf_instance_heartbeat_interval; + ogs_assert(nf_instance->t_no_heartbeat); + nf_instance->t_no_heartbeat->cb = bsf_timer_nf_instance_no_heartbeat; + ogs_assert(nf_instance->t_validity); + nf_instance->t_validity->cb = bsf_timer_nf_instance_validity; + + if (NF_INSTANCE_IS_SELF(nf_instance->id)) { + OGS_FSM_TRAN(s, &bsf_nf_state_will_register); + } else { + OGS_FSM_TRAN(s, &bsf_nf_state_registered); + } +} + +void bsf_nf_state_final(ogs_fsm_t *s, bsf_event_t *e) +{ + ogs_assert(s); + ogs_assert(e); + + bsf_sm_debug(e); +} + +void bsf_nf_state_will_register(ogs_fsm_t *s, bsf_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); + + bsf_sm_debug(e); + + nf_instance = e->sbi.data; + ogs_assert(nf_instance); + + switch (e->id) { + case OGS_FSM_ENTRY_SIG: + if (NF_INSTANCE_IS_SELF(nf_instance->id)) + ogs_timer_start(nf_instance->t_registration_interval, + ogs_app()->time.message.sbi.nf_register_interval); + + bsf_nnrf_nfm_send_nf_register(nf_instance); + break; + + case OGS_FSM_EXIT_SIG: + if (NF_INSTANCE_IS_SELF(nf_instance->id)) + ogs_timer_stop(nf_instance->t_registration_interval); + break; + + case BSF_EVT_SBI_CLIENT: + message = e->sbi.message; + ogs_assert(message); + + SWITCH(message->h.service.name) + CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) + + SWITCH(message->h.resource.component[0]) + CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) + + if (message->res_status == OGS_SBI_HTTP_STATUS_OK || + message->res_status == OGS_SBI_HTTP_STATUS_CREATED) { + bsf_nnrf_handle_nf_register(nf_instance, message); + OGS_FSM_TRAN(s, &bsf_nf_state_registered); + } else { + ogs_error("[%s] HTTP Response Status Code [%d]", + nf_instance->id, message->res_status); + OGS_FSM_TRAN(s, &bsf_nf_state_exception); + } + break; + + DEFAULT + ogs_error("[%s] Invalid resource name [%s]", + nf_instance->id, message->h.resource.component[0]); + END + break; + + DEFAULT + ogs_error("[%s] Invalid API name [%s]", + nf_instance->id, message->h.service.name); + END + break; + + case BSF_EVT_SBI_TIMER: + switch(e->timer_id) { + case BSF_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); + + if (NF_INSTANCE_IS_SELF(nf_instance->id)) + ogs_timer_start(nf_instance->t_registration_interval, + ogs_app()->time.message.sbi.nf_register_interval); + + bsf_nnrf_nfm_send_nf_register(nf_instance); + break; + + default: + ogs_error("[%s] Unknown timer[%s:%d]", nf_instance->id, + bsf_timer_get_name(e->timer_id), e->timer_id); + } + break; + + default: + ogs_error("[%s] Unknown event %s", + nf_instance->id, bsf_event_get_name(e)); + break; + } +} + +void bsf_nf_state_registered(ogs_fsm_t *s, bsf_event_t *e) +{ + ogs_sbi_nf_instance_t *nf_instance = NULL; + ogs_sbi_client_t *client = NULL; + ogs_sbi_message_t *message = NULL; + ogs_assert(s); + ogs_assert(e); + + bsf_sm_debug(e); + + nf_instance = e->sbi.data; + ogs_assert(nf_instance); + + switch (e->id) { + case OGS_FSM_ENTRY_SIG: + if (NF_INSTANCE_IS_SELF(nf_instance->id)) { + ogs_info("[%s] NF registred [Heartbeat:%ds]", + nf_instance->id, nf_instance->time.heartbeat_interval); + + client = nf_instance->client; + ogs_assert(client); + + if (nf_instance->time.heartbeat_interval) { + ogs_timer_start(nf_instance->t_heartbeat_interval, + ogs_time_from_sec(nf_instance->time.heartbeat_interval)); + ogs_timer_start(nf_instance->t_no_heartbeat, + ogs_time_from_sec( + nf_instance->time.heartbeat_interval + + ogs_app()->time.nf_instance.no_heartbeat_margin)); + } + } + + break; + + case OGS_FSM_EXIT_SIG: + if (NF_INSTANCE_IS_SELF(nf_instance->id)) { + ogs_info("[%s] NF de-registered", nf_instance->id); + + if (nf_instance->time.heartbeat_interval) { + ogs_timer_stop(nf_instance->t_heartbeat_interval); + ogs_timer_stop(nf_instance->t_no_heartbeat); + } + + if (!OGS_FSM_CHECK(&nf_instance->sm, bsf_nf_state_exception)) { + ogs_nnrf_nfm_send_nf_de_register(nf_instance); + } + } + break; + + case BSF_EVT_SBI_CLIENT: + message = e->sbi.message; + ogs_assert(message); + + SWITCH(message->h.service.name) + CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) + + SWITCH(message->h.resource.component[0]) + CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) + + if (message->res_status == OGS_SBI_HTTP_STATUS_NO_CONTENT || + message->res_status == OGS_SBI_HTTP_STATUS_OK) { + if (nf_instance->time.heartbeat_interval) + ogs_timer_start(nf_instance->t_no_heartbeat, + ogs_time_from_sec( + nf_instance->time.heartbeat_interval + + ogs_app()->time.nf_instance. + no_heartbeat_margin)); + } else { + ogs_warn("[%s] HTTP response error [%d]", + nf_instance->id, message->res_status); + OGS_FSM_TRAN(s, &bsf_nf_state_exception); + } + + break; + + DEFAULT + ogs_error("[%s] Invalid resource name [%s]", + nf_instance->id, message->h.resource.component[0]); + END + break; + + DEFAULT + ogs_error("[%s] Invalid API name [%s]", + nf_instance->id, message->h.service.name); + END + break; + + case BSF_EVT_SBI_TIMER: + switch(e->timer_id) { + case BSF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: + if (nf_instance->time.heartbeat_interval) + ogs_timer_start(nf_instance->t_heartbeat_interval, + ogs_time_from_sec(nf_instance->time.heartbeat_interval)); + + ogs_nnrf_nfm_send_nf_update(nf_instance); + break; + + case BSF_TIMER_NF_INSTANCE_NO_HEARTBEAT: + ogs_error("[%s] No heartbeat", nf_instance->id); + OGS_FSM_TRAN(s, &bsf_nf_state_will_register); + break; + + case BSF_TIMER_NF_INSTANCE_VALIDITY: + if (NF_INSTANCE_IS_OTHERS(nf_instance->id)) { + ogs_info("[%s] NF expired", nf_instance->id); + OGS_FSM_TRAN(s, &bsf_nf_state_de_registered); + } + break; + + default: + ogs_error("[%s] Unknown timer[%s:%d]", nf_instance->id, + bsf_timer_get_name(e->timer_id), e->timer_id); + break; + } + break; + + default: + ogs_error("[%s] Unknown event %s", + nf_instance->id, bsf_event_get_name(e)); + break; + } +} + +void bsf_nf_state_de_registered(ogs_fsm_t *s, bsf_event_t *e) +{ + ogs_sbi_nf_instance_t *nf_instance = NULL; + ogs_assert(s); + ogs_assert(e); + + bsf_sm_debug(e); + + nf_instance = e->sbi.data; + ogs_assert(nf_instance); + + switch (e->id) { + case OGS_FSM_ENTRY_SIG: + if (NF_INSTANCE_IS_SELF(nf_instance->id)) { + ogs_info("[%s] NF de-registered", nf_instance->id); + } + break; + + case OGS_FSM_EXIT_SIG: + break; + + default: + ogs_error("[%s] Unknown event %s", + nf_instance->id, bsf_event_get_name(e)); + break; + } +} + +void bsf_nf_state_exception(ogs_fsm_t *s, bsf_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); + + bsf_sm_debug(e); + + nf_instance = e->sbi.data; + ogs_assert(nf_instance); + + switch (e->id) { + case OGS_FSM_ENTRY_SIG: + if (NF_INSTANCE_IS_SELF(nf_instance->id)) + ogs_timer_start(nf_instance->t_registration_interval, + ogs_app()->time.message.sbi. + nf_register_interval_in_exception); + break; + + case OGS_FSM_EXIT_SIG: + if (NF_INSTANCE_IS_SELF(nf_instance->id)) + ogs_timer_stop(nf_instance->t_registration_interval); + break; + + case BSF_EVT_SBI_TIMER: + switch(e->timer_id) { + case BSF_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_FSM_TRAN(s, &bsf_nf_state_will_register); + break; + + default: + ogs_error("[%s] Unknown timer[%s:%d]", nf_instance->id, + bsf_timer_get_name(e->timer_id), e->timer_id); + break; + } + break; + + case BSF_EVT_SBI_CLIENT: + message = e->sbi.message; + ogs_assert(message); + + SWITCH(message->h.service.name) + CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) + + SWITCH(message->h.resource.component[0]) + CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) + break; + DEFAULT + ogs_error("Invalid resource name [%s]", + message->h.resource.component[0]); + END + break; + DEFAULT + ogs_error("Invalid API name [%s]", message->h.service.name); + END + break; + + default: + ogs_error("[%s] Unknown event %s", + nf_instance->id, bsf_event_get_name(e)); + break; + } +} diff --git a/src/bsf/nnrf-build.c b/src/bsf/nnrf-build.c new file mode 100644 index 000000000..711ae4a6f --- /dev/null +++ b/src/bsf/nnrf-build.c @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "nnrf-build.h" + +ogs_sbi_request_t *bsf_nnrf_nfm_build_register( + ogs_sbi_nf_instance_t *nf_instance) +{ + ogs_sbi_message_t message; + ogs_sbi_request_t *request = NULL; + ogs_sbi_client_t *client = NULL; + + OpenAPI_nf_profile_t *NFProfile = NULL; + + ogs_assert(nf_instance); + client = nf_instance->client; + ogs_assert(client); + + memset(&message, 0, sizeof(message)); + message.h.method = (char *)OGS_SBI_HTTP_METHOD_PUT; + message.h.service.name = (char *)OGS_SBI_SERVICE_NAME_NNRF_NFM; + message.h.api.version = (char *)OGS_SBI_API_V1; + message.h.resource.component[0] = + (char *)OGS_SBI_RESOURCE_NAME_NF_INSTANCES; + message.h.resource.component[1] = ogs_sbi_self()->nf_instance_id; + + message.http.content_encoding = (char*)ogs_sbi_self()->content_encoding; + + NFProfile = ogs_nnrf_nfm_build_nf_profile(nf_instance); + ogs_assert(NFProfile); + + message.NFProfile = NFProfile; + + request = ogs_sbi_build_request(&message); + + ogs_sbi_nnrf_free_nf_profile(NFProfile); + + return request; +} diff --git a/src/bsf/nnrf-build.h b/src/bsf/nnrf-build.h new file mode 100644 index 000000000..29d13e5d2 --- /dev/null +++ b/src/bsf/nnrf-build.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef BSF_NNRF_BUILD_H +#define BSF_NNRF_BUILD_H + +#include "context.h" + +#ifdef __cplusplus +extern "C" { +#endif + +ogs_sbi_request_t *bsf_nnrf_nfm_build_register( + ogs_sbi_nf_instance_t *nf_instance); + +#ifdef __cplusplus +} +#endif + +#endif /* BSF_NNRF_BUILD_H */ diff --git a/src/bsf/nnrf-handler.c b/src/bsf/nnrf-handler.c new file mode 100644 index 000000000..a3eb45d2f --- /dev/null +++ b/src/bsf/nnrf-handler.c @@ -0,0 +1,335 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "sbi-path.h" +#include "nnrf-handler.h" + +void bsf_nnrf_handle_nf_register( + ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_message_t *recvmsg) +{ + OpenAPI_nf_profile_t *NFProfile = NULL; + ogs_sbi_client_t *client = NULL; + + ogs_assert(recvmsg); + ogs_assert(nf_instance); + client = nf_instance->client; + ogs_assert(client); + + NFProfile = recvmsg->NFProfile; + if (!NFProfile) { + ogs_error("No NFProfile"); + return; + } + + /* TIME : Update heartbeat from NRF */ + if (NFProfile->nf_profile_changes_ind == true) { + if (NFProfile->heart_beat_timer) + nf_instance->time.heartbeat_interval = NFProfile->heart_beat_timer; + } else { + nf_instance->time.heartbeat_interval = NFProfile->heart_beat_timer; + } +} + +void bsf_nnrf_handle_nf_status_subscribe( + ogs_sbi_subscription_t *subscription, ogs_sbi_message_t *recvmsg) +{ + OpenAPI_subscription_data_t *SubscriptionData = NULL; + ogs_sbi_client_t *client = NULL; + + ogs_assert(recvmsg); + ogs_assert(subscription); + client = subscription->client; + ogs_assert(client); + + SubscriptionData = recvmsg->SubscriptionData; + if (!SubscriptionData) { + ogs_error("No SubscriptionData"); + return; + } + + if (!SubscriptionData->subscription_id) { + ogs_error("No SubscriptionId"); + return; + } + ogs_sbi_subscription_set_id( + subscription, SubscriptionData->subscription_id); + + if (SubscriptionData->validity_time) { +#define VALIDITY_MINIMUM (10LL * OGS_USEC_PER_SEC) /* 10 seconds */ + ogs_time_t time, duration; + if (ogs_sbi_time_from_string( + &time, SubscriptionData->validity_time) == true) { + duration = time - ogs_time_now(); + if (duration < VALIDITY_MINIMUM) { + duration = VALIDITY_MINIMUM; + ogs_warn("[%s] Forced to %lld seconds", subscription->id, + (long long)ogs_time_sec(VALIDITY_MINIMUM)); + } + subscription->t_validity = ogs_timer_add(ogs_app()->timer_mgr, + bsf_timer_subscription_validity, subscription); + ogs_assert(subscription->t_validity); + ogs_timer_start(subscription->t_validity, duration); + } else { + ogs_error("Cannot parse validitiyTime [%s]", + SubscriptionData->validity_time); + } + } +} + +bool bsf_nnrf_handle_nf_status_notify( + ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) +{ + int rv; + bool handled; + + ogs_sbi_response_t *response = NULL; + OpenAPI_notification_data_t *NotificationData = NULL; + ogs_sbi_nf_instance_t *nf_instance = NULL; + + ogs_sbi_message_t message; + ogs_sbi_header_t header; + + ogs_assert(stream); + ogs_assert(recvmsg); + + NotificationData = recvmsg->NotificationData; + if (!NotificationData) { + ogs_error("No NotificationData"); + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + recvmsg, "No NotificationData", NULL); + return false; + } + + if (!NotificationData->nf_instance_uri) { + ogs_error("No nfInstanceUri"); + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + recvmsg, "No nfInstanceUri", NULL); + return false; + } + + memset(&header, 0, sizeof(header)); + header.uri = NotificationData->nf_instance_uri; + + rv = ogs_sbi_parse_header(&message, &header); + if (rv != OGS_OK) { + ogs_error("Cannot parse nfInstanceUri [%s]", header.uri); + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + recvmsg, "Cannot parse nfInstanceUri", header.uri); + return false; + } + + if (!message.h.resource.component[1]) { + ogs_error("No nfInstanceId [%s]", header.uri); + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + recvmsg, "Cannot parse nfInstanceUri", header.uri); + ogs_sbi_header_free(&header); + return false; + } + + if (NF_INSTANCE_IS_SELF(message.h.resource.component[1])) { + ogs_warn("[%s] The notification is not allowed", + message.h.resource.component[1]); + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, + recvmsg, "The notification is not allowed", + message.h.resource.component[1]); + ogs_sbi_header_free(&header); + return false; + } + + if (NotificationData->event == + OpenAPI_notification_event_type_NF_REGISTERED) { + + OpenAPI_nf_profile_t *NFProfile = NULL; + + NFProfile = NotificationData->nf_profile; + if (!NFProfile) { + ogs_error("No NFProfile"); + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + recvmsg, "No NFProfile", NULL); + ogs_sbi_header_free(&header); + return false; + } + + nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); + if (!nf_instance) { + nf_instance = ogs_sbi_nf_instance_add( + message.h.resource.component[1]); + ogs_assert(nf_instance); + + bsf_nf_fsm_init(nf_instance); + + ogs_info("[%s] (NRF-notify) NF registered", nf_instance->id); + + } else { + OGS_FSM_TRAN(&nf_instance->sm, bsf_nf_state_registered); + ogs_fsm_dispatch(&nf_instance->sm, NULL); + + ogs_warn("[%s] (NRF-notify) NF has already been added", + message.h.resource.component[1]); + + } + + handled = ogs_sbi_nnrf_handle_nf_profile( + nf_instance, NFProfile, stream, recvmsg); + if (!handled) { + BSF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); + ogs_sbi_header_free(&header); + return false; + } + + ogs_info("[%s] (NRF-notify) NF Profile updated", nf_instance->id); + + handled = ogs_sbi_client_associate(nf_instance); + if (!handled) { + ogs_error("[%s] Cannot associate NF EndPoint", nf_instance->id); + ogs_sbi_server_send_error(stream, + OGS_SBI_HTTP_STATUS_BAD_REQUEST, + recvmsg, "Cannot find NF EndPoint", nf_instance->id); + BSF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); + ogs_sbi_header_free(&header); + return false; + } + + } else if (NotificationData->event == + OpenAPI_notification_event_type_NF_DEREGISTERED) { + nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); + if (nf_instance) { + BSF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); + } else { + ogs_warn("[%s] (NRF-notify) Not found", + message.h.resource.component[1]); + ogs_sbi_server_send_error(stream, + OGS_SBI_HTTP_STATUS_NOT_FOUND, + recvmsg, "Not found", message.h.resource.component[1]); + ogs_sbi_header_free(&header); + return false; + } + } else { + char *eventstr = OpenAPI_notification_event_type_ToString( + NotificationData->event); + ogs_error("Not supported event [%d:%s]", + NotificationData->event, eventstr ? eventstr : "Unknown"); + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + recvmsg, "Not supported event", + eventstr ? eventstr : "Unknown"); + ogs_sbi_header_free(&header); + return false; + } + + response = ogs_sbi_build_response(recvmsg, OGS_SBI_HTTP_STATUS_NO_CONTENT); + ogs_assert(response); + ogs_sbi_server_send_response(stream, response); + + ogs_sbi_header_free(&header); + return true; +} + +void bsf_nnrf_handle_nf_discover( + ogs_sbi_xact_t *xact, ogs_sbi_message_t *recvmsg) +{ + ogs_sbi_object_t *sbi_object = NULL; + ogs_sbi_nf_instance_t *nf_instance = NULL; + + OpenAPI_search_result_t *SearchResult = NULL; + OpenAPI_lnode_t *node = NULL; + bool handled; + + ogs_assert(xact); + sbi_object = xact->sbi_object; + ogs_assert(sbi_object); + ogs_assert(recvmsg); + + SearchResult = recvmsg->SearchResult; + if (!SearchResult) { + ogs_error("No SearchResult"); + return; + } + + OpenAPI_list_for_each(SearchResult->nf_instances, node) { + OpenAPI_nf_profile_t *NFProfile = NULL; + + if (!node->data) continue; + + NFProfile = node->data; + + nf_instance = ogs_sbi_nf_instance_find(NFProfile->nf_instance_id); + if (!nf_instance) { + nf_instance = ogs_sbi_nf_instance_add(NFProfile->nf_instance_id); + ogs_assert(nf_instance); + + bsf_nf_fsm_init(nf_instance); + + ogs_info("[%s] (NF-discover) NF registered", nf_instance->id); + } else { + OGS_FSM_TRAN(&nf_instance->sm, bsf_nf_state_registered); + ogs_fsm_dispatch(&nf_instance->sm, NULL); + + ogs_warn("[%s] (NF-discover) NF has already been added", + NFProfile->nf_instance_id); + } + + if (NF_INSTANCE_IS_OTHERS(nf_instance->id)) { + bsf_sess_t *sess = NULL; + + handled = ogs_sbi_nnrf_handle_nf_profile( + nf_instance, NFProfile, NULL, NULL); + if (!handled) { + ogs_error("ogs_sbi_nnrf_handle_nf_profile() failed [%s]", + nf_instance->id); + BSF_NF_INSTANCE_CLEAR("NRF-discover", nf_instance); + continue; + } + + handled = ogs_sbi_client_associate(nf_instance); + if (!handled) { + ogs_error("[%s] Cannot assciate NF EndPoint", nf_instance->id); + BSF_NF_INSTANCE_CLEAR("NRF-discover", nf_instance); + continue; + } + + sess = (bsf_sess_t *)sbi_object; + ogs_assert(sess); + bsf_sess_select_nf(sess, nf_instance->nf_type); + + /* TIME : Update validity from NRF */ + if (SearchResult->validity_period) { + nf_instance->time.validity_duration = + SearchResult->validity_period; + + ogs_assert(nf_instance->t_validity); + ogs_timer_start(nf_instance->t_validity, + ogs_time_from_sec(nf_instance->time.validity_duration)); + + } else + ogs_warn("[%s] NF Instance validity-time should not 0", + nf_instance->id); + + ogs_info("[%s] (NF-discover) NF Profile updated", nf_instance->id); + } + } + + ogs_assert(xact->target_nf_type); + nf_instance = OGS_SBI_NF_INSTANCE(sbi_object, xact->target_nf_type); + if (!nf_instance) { + ogs_error("(NF discover) No [%s]", + OpenAPI_nf_type_ToString(xact->target_nf_type)); + } else { + bsf_sbi_send(nf_instance, xact); + } +} diff --git a/src/bsf/nnrf-handler.h b/src/bsf/nnrf-handler.h new file mode 100644 index 000000000..fcad53b00 --- /dev/null +++ b/src/bsf/nnrf-handler.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef BSF_NNRF_HANDLER_H +#define BSF_NNRF_HANDLER_H + +#include "context.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void bsf_nnrf_handle_nf_register( + ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_message_t *recvmsg); +void bsf_nnrf_handle_nf_status_subscribe( + ogs_sbi_subscription_t *subscription, ogs_sbi_message_t *recvmsg); + +bool bsf_nnrf_handle_nf_status_notify( + ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); + +void bsf_nnrf_handle_nf_discover( + ogs_sbi_xact_t *xact, ogs_sbi_message_t *recvmsg); + +#ifdef __cplusplus +} +#endif + +#endif /* BSF_NNRF_HANDLER_H */ diff --git a/src/bsf/sbi-path.c b/src/bsf/sbi-path.c new file mode 100644 index 000000000..54a459a9c --- /dev/null +++ b/src/bsf/sbi-path.c @@ -0,0 +1,185 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "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(BSF_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) { + ogs_warn("ogs_queue_push() failed:%d", (int)rv); + bsf_event_free(e); + return OGS_ERROR; + } + + return OGS_OK; +} + +static int client_cb(ogs_sbi_response_t *response, void *data) +{ + bsf_event_t *e = NULL; + int rv; + + ogs_assert(response); + + e = bsf_event_new(BSF_EVT_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_warn("ogs_queue_push() failed:%d", (int)rv); + bsf_event_free(e); + return OGS_ERROR; + } + + return OGS_OK; +} + +int bsf_sbi_open(void) +{ + ogs_sbi_nf_instance_t *nf_instance = NULL; + + if (ogs_sbi_server_start_all(server_cb) != OGS_OK) + return OGS_ERROR; + + /* + * The connection between NF and NRF is a little special. + * + * NF and NRF share nf_instance. I get the NRF EndPoint(client) information + * the configuration file via lib/sbi/context.c. + * And, the NFService information will be transmitted to NRF. + * + * ogs_sbi_self()->nf_instance_id means NF's InstanceId. + */ + ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) { + ogs_sbi_nf_service_t *service = NULL; + ogs_sbi_client_t *client = NULL; + + /* Build NF instance information. It will be transmitted to NRF. */ + ogs_sbi_nf_instance_build_default(nf_instance, bsf_self()->nf_type); + + /* Build NF service information. It will be transmitted to NRF. */ + service = ogs_sbi_nf_service_build_default(nf_instance, + (char*)OGS_SBI_SERVICE_NAME_NBSF_MANAGEMENT); + ogs_assert(service); + ogs_sbi_nf_service_add_version(service, (char*)OGS_SBI_API_V1, + (char*)OGS_SBI_API_V1_0_0, NULL); + + /* Client callback is only used when NF sends to NRF */ + client = nf_instance->client; + ogs_assert(client); + client->cb = client_cb; + + /* NFRegister is sent and the response is received + * by the above client callback. */ + bsf_nf_fsm_init(nf_instance); + } + + return OGS_OK; +} + +void bsf_sbi_close(void) +{ + ogs_sbi_server_stop_all(); +} + +void bsf_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 = bsf_nnrf_nfm_build_register(nf_instance); + if (!request) { + ogs_error("bsf_nnrf_nfm_send_nf_register() failed"); + return; + } + ogs_sbi_client_send_request(client, client->cb, request, nf_instance); +} + +void bsf_sbi_send(ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_xact_t *xact) +{ + ogs_sbi_send(nf_instance, client_cb, xact); +} + +void bsf_sbi_discover_and_send(OpenAPI_nf_type_e target_nf_type, + bsf_sess_t *sess, ogs_sbi_stream_t *stream, void *data, + ogs_sbi_request_t *(*build)(bsf_sess_t *sess, void *data)) +{ + ogs_sbi_xact_t *xact = NULL; + + ogs_assert(target_nf_type); + + ogs_assert(sess); + ogs_assert(stream); + ogs_assert(build); + + xact = ogs_sbi_xact_add(target_nf_type, &sess->sbi, + (ogs_sbi_build_f)build, sess, data, + bsf_timer_sbi_client_wait_expire); + if (!xact) { + ogs_error("bsf_sbi_discover_and_send() failed"); + ogs_sbi_server_send_error(stream, + OGS_SBI_HTTP_STATUS_GATEWAY_TIMEOUT, NULL, + "Cannot discover", sess->dnn); + return; + } + + xact->assoc_stream = stream; + + if (ogs_sbi_discover_and_send(xact, + (ogs_fsm_handler_t)bsf_nf_state_registered, client_cb) != true) { + ogs_error("bsf_sbi_discover_and_send() failed"); + ogs_sbi_server_send_error(stream, + OGS_SBI_HTTP_STATUS_GATEWAY_TIMEOUT, NULL, + "Cannot discover", sess->dnn); + return; + } +} + +void bsf_sbi_send_response(ogs_sbi_stream_t *stream, int status) +{ + ogs_sbi_message_t sendmsg; + ogs_sbi_response_t *response = NULL; + + ogs_assert(stream); + + memset(&sendmsg, 0, sizeof(sendmsg)); + + response = ogs_sbi_build_response(&sendmsg, status); + ogs_assert(response); + ogs_sbi_server_send_response(stream, response); +} diff --git a/src/bsf/sbi-path.h b/src/bsf/sbi-path.h new file mode 100644 index 000000000..408374783 --- /dev/null +++ b/src/bsf/sbi-path.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef BSF_SBI_PATH_H +#define BSF_SBI_PATH_H + +#include "nnrf-build.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int bsf_sbi_open(void); +void bsf_sbi_close(void); + +void bsf_nnrf_nfm_send_nf_register(ogs_sbi_nf_instance_t *nf_instance); + +void bsf_sbi_send(ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_xact_t *xact); + +void bsf_sbi_discover_and_send(OpenAPI_nf_type_e target_nf_type, + bsf_sess_t *sess, ogs_sbi_stream_t *stream, void *data, + ogs_sbi_request_t *(*build)(bsf_sess_t *sess, void *data)); + +void bsf_sbi_send_response(ogs_sbi_stream_t *stream, int status); + +#ifdef __cplusplus +} +#endif + +#endif /* BSF_SBI_PATH_H */ diff --git a/src/bsf/timer.c b/src/bsf/timer.c new file mode 100644 index 000000000..c3bbb8864 --- /dev/null +++ b/src/bsf/timer.c @@ -0,0 +1,118 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "timer.h" +#include "event.h" +#include "context.h" + +const char *bsf_timer_get_name(bsf_timer_e id) +{ + switch (id) { + case BSF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: + return "BSF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL"; + case BSF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: + return "BSF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL"; + case BSF_TIMER_NF_INSTANCE_NO_HEARTBEAT: + return "BSF_TIMER_NF_INSTANCE_NO_HEARTBEAT"; + case BSF_TIMER_NF_INSTANCE_VALIDITY: + return "BSF_TIMER_NF_INSTANCE_VALIDITY"; + case BSF_TIMER_SUBSCRIPTION_VALIDITY: + return "BSF_TIMER_SUBSCRIPTION_VALIDITY"; + case BSF_TIMER_SBI_CLIENT_WAIT: + return "BSF_TIMER_SBI_CLIENT_WAIT"; + default: + break; + } + + return "UNKNOWN_TIMER"; +} + +static void timer_send_event(int timer_id, void *data) +{ + int rv; + bsf_event_t *e = NULL; + ogs_assert(data); + + switch (timer_id) { + case BSF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: + case BSF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: + case BSF_TIMER_NF_INSTANCE_NO_HEARTBEAT: + case BSF_TIMER_NF_INSTANCE_VALIDITY: + case BSF_TIMER_SUBSCRIPTION_VALIDITY: + e = bsf_event_new(BSF_EVT_SBI_TIMER); + ogs_assert(e); + e->timer_id = timer_id; + e->sbi.data = data; + break; + case BSF_TIMER_SBI_CLIENT_WAIT: + e = bsf_event_new(BSF_EVT_SBI_TIMER); + if (!e) { + ogs_sbi_xact_t *sbi_xact = data; + ogs_assert(sbi_xact); + + ogs_error("timer_send_event() failed"); + ogs_sbi_xact_remove(sbi_xact); + return; + } + e->timer_id = timer_id; + e->sbi.data = data; + break; + default: + ogs_fatal("Unknown timer id[%d]", timer_id); + ogs_assert_if_reached(); + break; + } + + rv = ogs_queue_push(ogs_app()->queue, e); + if (rv != OGS_OK) { + ogs_warn("ogs_queue_push() failed [%d] in %s", + (int)rv, bsf_timer_get_name(e->timer_id)); + bsf_event_free(e); + } +} + +void bsf_timer_nf_instance_registration_interval(void *data) +{ + timer_send_event(BSF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL, data); +} + +void bsf_timer_nf_instance_heartbeat_interval(void *data) +{ + timer_send_event(BSF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL, data); +} + +void bsf_timer_nf_instance_no_heartbeat(void *data) +{ + timer_send_event(BSF_TIMER_NF_INSTANCE_NO_HEARTBEAT, data); +} + +void bsf_timer_nf_instance_validity(void *data) +{ + timer_send_event(BSF_TIMER_NF_INSTANCE_VALIDITY, data); +} + +void bsf_timer_subscription_validity(void *data) +{ + timer_send_event(BSF_TIMER_SUBSCRIPTION_VALIDITY, data); +} + +void bsf_timer_sbi_client_wait_expire(void *data) +{ + timer_send_event(BSF_TIMER_SBI_CLIENT_WAIT, data); +} diff --git a/src/bsf/timer.h b/src/bsf/timer.h new file mode 100644 index 000000000..1c7b11d3c --- /dev/null +++ b/src/bsf/timer.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef BSF_TIMER_H +#define BSF_TIMER_H + +#include "ogs-core.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* forward declaration */ +typedef enum { + BSF_TIMER_BASE = 0, + + BSF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL, + BSF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL, + BSF_TIMER_NF_INSTANCE_NO_HEARTBEAT, + BSF_TIMER_NF_INSTANCE_VALIDITY, + BSF_TIMER_SUBSCRIPTION_VALIDITY, + BSF_TIMER_SBI_CLIENT_WAIT, + + MAX_NUM_OF_BSF_TIMER, + +} bsf_timer_e; + +const char *bsf_timer_get_name(bsf_timer_e id); + +void bsf_timer_nf_instance_registration_interval(void *data); +void bsf_timer_nf_instance_heartbeat_interval(void *data); +void bsf_timer_nf_instance_no_heartbeat(void *data); +void bsf_timer_nf_instance_validity(void *data); +void bsf_timer_subscription_validity(void *data); +void bsf_timer_sbi_client_wait_expire(void *data); + +#ifdef __cplusplus +} +#endif + +#endif /* BSF_TIMER_H */ diff --git a/src/meson.build b/src/meson.build index 3d6a6a8b3..e86a1896b 100644 --- a/src/meson.build +++ b/src/meson.build @@ -40,6 +40,7 @@ subdir('udr') subdir('udm') subdir('pcf') subdir('nssf') +subdir('bsf') subdir('ausf') subdir('upf') subdir('smf') diff --git a/src/pcf/context.c b/src/pcf/context.c index 810534151..4fa017b2f 100644 --- a/src/pcf/context.c +++ b/src/pcf/context.c @@ -28,6 +28,9 @@ static OGS_POOL(pcf_sess_pool, pcf_sess_t); static int context_initialized = 0; +static void clear_ipv4addr(pcf_sess_t *sess); +static void clear_ipv6prefix(pcf_sess_t *sess); + void pcf_context_init(void) { ogs_assert(context_initialized == 0); @@ -42,7 +45,10 @@ void pcf_context_init(void) ogs_pool_init(&pcf_sess_pool, ogs_app()->pool.sess); ogs_list_init(&self.pcf_ue_list); + self.supi_hash = ogs_hash_make(); + self.ipv4addr_hash = ogs_hash_make(); + self.ipv6prefix_hash = ogs_hash_make(); context_initialized = 1; } @@ -55,6 +61,10 @@ void pcf_context_final(void) ogs_assert(self.supi_hash); ogs_hash_destroy(self.supi_hash); + ogs_assert(self.ipv4addr_hash); + ogs_hash_destroy(self.ipv4addr_hash); + ogs_assert(self.ipv6prefix_hash); + ogs_hash_destroy(self.ipv6prefix_hash); ogs_pool_final(&pcf_sess_pool); ogs_pool_final(&pcf_ue_pool); @@ -182,6 +192,13 @@ void pcf_ue_remove(pcf_ue_t *pcf_ue) if (pcf_ue->notification_uri) ogs_free(pcf_ue->notification_uri); + if (pcf_ue->namf.client) + ogs_sbi_client_remove(pcf_ue->namf.client); + + if (pcf_ue->gpsi) + ogs_free(pcf_ue->gpsi); + if (pcf_ue->pei) + ogs_free(pcf_ue->pei); ogs_pool_free(&pcf_ue_pool, pcf_ue); } @@ -224,11 +241,19 @@ pcf_sess_t *pcf_sess_add(pcf_ue_t *pcf_ue, uint8_t psi) /* SBI Features */ OGS_SBI_FEATURES_SET(sess->smpolicycontrol_features, OGS_SBI_NPCF_SMPOLICYCONTROL_DN_AUTHORIZATION); + OGS_SBI_FEATURES_SET(sess->management_features, + OGS_SBI_NBSF_MANAGEMENT_BINDING_UPDATE); + OGS_SBI_FEATURES_SET(sess->policyauthorization_features, + OGS_SBI_NPCF_POLICYAUTHORIZATION_IMS_SBI); sess->sm_policy_id = ogs_msprintf("%d", (int)ogs_pool_index(&pcf_sess_pool, sess)); ogs_assert(sess->sm_policy_id); + sess->app_session_id = ogs_msprintf("%d", + (int)ogs_pool_index(&pcf_sess_pool, sess)); + ogs_assert(sess->app_session_id); + sess->pcf_ue = pcf_ue; sess->psi = psi; @@ -265,11 +290,22 @@ void pcf_sess_remove(pcf_sess_t *sess) ogs_assert(sess->sm_policy_id); ogs_free(sess->sm_policy_id); + ogs_assert(sess->app_session_id); + ogs_free(sess->app_session_id); + + if (sess->binding_id) + ogs_free(sess->binding_id); + if (sess->dnn) ogs_free(sess->dnn); if (sess->notification_uri) ogs_free(sess->notification_uri); + if (sess->nsmf.client) + ogs_sbi_client_remove(sess->nsmf.client); + + clear_ipv4addr(sess); + clear_ipv6prefix(sess); if (sess->subscribed_sess_ambr) OpenAPI_ambr_free(sess->subscribed_sess_ambr); @@ -289,16 +325,88 @@ void pcf_sess_remove_all(pcf_ue_t *pcf_ue) pcf_sess_remove(sess); } -pcf_sess_t *pcf_sess_find_by_sm_policy_id(pcf_ue_t *pcf_ue, char *sm_policy_id) +static void clear_ipv4addr(pcf_sess_t *sess) { - pcf_sess_t *sess = NULL; + ogs_assert(sess); + if (sess->ipv4addr_string) { + ogs_hash_set(self.ipv4addr_hash, + &sess->ipv4addr, sizeof(sess->ipv4addr), NULL); + ogs_free(sess->ipv4addr_string); + } +} + +static void clear_ipv6prefix(pcf_sess_t *sess) +{ + ogs_assert(sess); + + if (sess->ipv6prefix_string) { + ogs_hash_set(self.ipv6prefix_hash, + &sess->ipv6prefix, (sess->ipv6prefix.len >> 3) + 1, NULL); + ogs_free(sess->ipv6prefix_string); + } +} + +bool pcf_sess_set_ipv4addr(pcf_sess_t *sess, char *ipv4addr_string) +{ + int rv; + + ogs_assert(sess); + ogs_assert(ipv4addr_string); + + clear_ipv4addr(sess); + + rv = ogs_ipv4_from_string(&sess->ipv4addr, ipv4addr_string); + ogs_expect_or_return_val(rv == OGS_OK, false); + + sess->ipv4addr_string = ogs_strdup(ipv4addr_string); + ogs_expect_or_return_val(sess->ipv4addr_string, false); + + ogs_hash_set(self.ipv4addr_hash, + &sess->ipv4addr, sizeof(sess->ipv4addr), sess); + + return true; +} + +bool pcf_sess_set_ipv6prefix(pcf_sess_t *sess, char *ipv6prefix_string) +{ + int rv; + + ogs_assert(sess); + ogs_assert(ipv6prefix_string); + + clear_ipv6prefix(sess); + + rv = ogs_ipv6prefix_from_string( + sess->ipv6prefix.addr6, &sess->ipv6prefix.len, ipv6prefix_string); + ogs_expect_or_return_val(rv == OGS_OK, false); + + ogs_assert(sess->ipv6prefix.len == OGS_IPV6_128_PREFIX_LEN); + + sess->ipv6prefix_string = ogs_strdup(ipv6prefix_string); + ogs_expect_or_return_val(sess->ipv6prefix_string, false); + + ogs_hash_set(self.ipv6prefix_hash, + &sess->ipv6prefix, (sess->ipv6prefix.len >> 3) + 1, sess); + + return true; +} + +pcf_sess_t *pcf_sess_find(uint32_t index) +{ + return ogs_pool_find(&pcf_sess_pool, index); +} + +pcf_sess_t *pcf_sess_find_by_sm_policy_id(char *sm_policy_id) +{ ogs_assert(sm_policy_id); + return pcf_sess_find(atoll(sm_policy_id)); +} - ogs_list_for_each(&pcf_ue->sess_list, sess) - if (!strcmp(sess->sm_policy_id, sm_policy_id)) return sess; - - return NULL; +pcf_sess_t *pcf_sess_find_by_app_session_id(char *app_session_id) +{ + ogs_assert(app_session_id); + return pcf_sess_find(atoll(app_session_id)); } pcf_sess_t *pcf_sess_find_by_psi(pcf_ue_t *pcf_ue, uint8_t psi) @@ -311,6 +419,60 @@ pcf_sess_t *pcf_sess_find_by_psi(pcf_ue_t *pcf_ue, uint8_t psi) return NULL; } +pcf_sess_t *pcf_sess_find_by_ipv4addr(char *ipv4addr_string) +{ + uint32_t ipv4addr; + int rv; + + ogs_assert(ipv4addr_string); + + rv = ogs_ipv4_from_string(&ipv4addr, ipv4addr_string); + ogs_expect_or_return_val(rv == OGS_OK, NULL); + + return ogs_hash_get(self.ipv4addr_hash, &ipv4addr, sizeof(ipv4addr)); +} + +pcf_sess_t *pcf_sess_find_by_ipv6addr(char *ipv6addr_string) +{ + int rv; + ogs_sockaddr_t tmp; + struct { + uint8_t len; + uint8_t addr6[OGS_IPV6_LEN]; + } ipv6prefix; + + ogs_assert(ipv6addr_string); + + rv = ogs_inet_pton(AF_INET6, ipv6addr_string, &tmp); + ogs_expect_or_return_val(rv == OGS_OK, NULL); + + memcpy(ipv6prefix.addr6, tmp.sin6.sin6_addr.s6_addr, OGS_IPV6_LEN); + ipv6prefix.len = OGS_IPV6_128_PREFIX_LEN; + + return ogs_hash_get(self.ipv6prefix_hash, + &ipv6prefix, (ipv6prefix.len >> 3) + 1); +} + +pcf_sess_t *pcf_sess_find_by_ipv6prefix(char *ipv6prefix_string) +{ + int rv; + struct { + uint8_t len; + uint8_t addr6[OGS_IPV6_LEN]; + } ipv6prefix; + + ogs_assert(ipv6prefix_string); + + rv = ogs_ipv6prefix_from_string( + ipv6prefix.addr6, &ipv6prefix.len, ipv6prefix_string); + ogs_expect_or_return_val(rv == OGS_OK, NULL); + + ogs_assert(ipv6prefix.len == OGS_IPV6_128_PREFIX_LEN); + + return ogs_hash_get(self.ipv6prefix_hash, + &ipv6prefix, (ipv6prefix.len >> 3) + 1); +} + pcf_ue_t *pcf_ue_cycle(pcf_ue_t *pcf_ue) { return ogs_pool_cycle(&pcf_ue_pool, pcf_ue); diff --git a/src/pcf/context.h b/src/pcf/context.h index 8d6192577..75eeccf48 100644 --- a/src/pcf/context.h +++ b/src/pcf/context.h @@ -45,6 +45,8 @@ typedef struct pcf_context_s { ogs_list_t pcf_ue_list; ogs_hash_t *supi_hash; + ogs_hash_t *ipv4addr_hash; + ogs_hash_t *ipv6prefix_hash; } pcf_context_t; #define PCF_NF_INSTANCE_CLEAR(_cAUSE, _nFInstance) \ @@ -71,11 +73,19 @@ struct pcf_ue_s { char *supi; char *notification_uri; + struct { + ogs_sbi_client_t *client; + } namf; + + char *gpsi; + OpenAPI_access_type_e access_type; + char *pei; ogs_guami_t guami; OpenAPI_rat_type_e rat_type; - uint64_t am_policy_control_features; /* SBI Features */ + /* SBI Features */ + uint64_t am_policy_control_features; OpenAPI_policy_association_request_t *policy_association_request; OpenAPI_ambr_t *subscribed_ue_ambr; @@ -89,14 +99,37 @@ struct pcf_sess_s { char *sm_policy_id; + /* BSF sends the RESPONSE + * of [POST] /nbsf-management/v1/PcfBindings */ + char *binding_id; + uint8_t psi; /* PDU Session Identity */ uint8_t pdu_session_type; char *dnn; + char *notification_uri; + struct { + ogs_sbi_client_t *client; + } nsmf; + + char *ipv4addr_string; + char *ipv6prefix_string; + + uint32_t ipv4addr; + struct { + uint8_t len; + uint8_t addr6[OGS_IPV6_LEN]; + } ipv6prefix; + + char *app_session_id; + ogs_s_nssai_t s_nssai; - uint64_t smpolicycontrol_features; /* SBI Features */ + /* SBI Features */ + uint64_t smpolicycontrol_features; + uint64_t management_features; + uint64_t policyauthorization_features; OpenAPI_ambr_t *subscribed_sess_ambr; OpenAPI_subscribed_default_qos_t *subscribed_default_qos; @@ -120,9 +153,18 @@ pcf_ue_t *pcf_ue_find_by_association_id(char *association_id); pcf_sess_t *pcf_sess_add(pcf_ue_t *pcf_ue, uint8_t psi); void pcf_sess_remove(pcf_sess_t *sess); void pcf_sess_remove_all(pcf_ue_t *pcf_ue); -pcf_sess_t *pcf_sess_find_by_sm_policy_id(pcf_ue_t *pcf_ue, char *sm_policy_id); + +bool pcf_sess_set_ipv4addr(pcf_sess_t *sess, char *ipv4addr); +bool pcf_sess_set_ipv6prefix(pcf_sess_t *sess, char *ipv6prefix); + +pcf_sess_t *pcf_sess_find(uint32_t index); +pcf_sess_t *pcf_sess_find_by_sm_policy_id(char *sm_policy_id); +pcf_sess_t *pcf_sess_find_by_app_session_id(char *app_session_id); pcf_sess_t *pcf_sess_find_by_psi(pcf_ue_t *pcf_ue, uint8_t psi); pcf_sess_t *pcf_sess_find_by_dnn(pcf_ue_t *pcf_ue, char *dnn); +pcf_sess_t *pcf_sess_find_by_ipv4addr(char *ipv4addr_string); +pcf_sess_t *pcf_sess_find_by_ipv6addr(char *ipv6addr_string); +pcf_sess_t *pcf_sess_find_by_ipv6prefix(char *ipv6prefix_string); pcf_ue_t *pcf_ue_cycle(pcf_ue_t *pcf_ue); pcf_sess_t *pcf_sess_cycle(pcf_sess_t *sess); diff --git a/src/pcf/meson.build b/src/pcf/meson.build index ec4b30a61..d6e04010d 100644 --- a/src/pcf/meson.build +++ b/src/pcf/meson.build @@ -29,6 +29,12 @@ libpcf_sources = files(''' nudr-build.c nudr-handler.c + nbsf-build.c + nbsf-handler.c + + namf-build.c + nsmf-build.c + am-sm.c sm-sm.c diff --git a/src/pcf/namf-build.c b/src/pcf/namf-build.c new file mode 100644 index 000000000..4e99fab39 --- /dev/null +++ b/src/pcf/namf-build.c @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "namf-build.h" + +ogs_sbi_request_t *pcf_namf_callback_build_am_policy_control( + pcf_ue_t *pcf_ue, void *data) +{ + ogs_sbi_message_t message; + ogs_sbi_request_t *request = NULL; + + OpenAPI_policy_update_t PolicyUpdate; + + ogs_assert(pcf_ue); + ogs_assert(pcf_ue->notification_uri); + + memset(&PolicyUpdate, 0, sizeof(PolicyUpdate)); + + memset(&message, 0, sizeof(message)); + message.h.method = (char *)OGS_SBI_HTTP_METHOD_POST; + message.h.uri = pcf_ue->notification_uri; + + message.PolicyUpdate = &PolicyUpdate; + + request = ogs_sbi_build_request(&message); + ogs_assert(request); + + return request; +} diff --git a/src/pcf/namf-build.h b/src/pcf/namf-build.h new file mode 100644 index 000000000..acf7058ba --- /dev/null +++ b/src/pcf/namf-build.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef PCF_NAMF_BUILD_H +#define PCF_NAMF_BUILD_H + +#include "context.h" + +#ifdef __cplusplus +extern "C" { +#endif + +ogs_sbi_request_t *pcf_namf_callback_build_am_policy_control( + pcf_ue_t *pcf_ue, void *data); + +#ifdef __cplusplus +} +#endif + +#endif /* PCF_NAMF_BUILD_H */ diff --git a/src/pcf/nbsf-build.c b/src/pcf/nbsf-build.c new file mode 100644 index 000000000..42aa32551 --- /dev/null +++ b/src/pcf/nbsf-build.c @@ -0,0 +1,165 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "nbsf-build.h" + +ogs_sbi_request_t *pcf_nbsf_management_build_register( + pcf_sess_t *sess, void *data) +{ + pcf_ue_t *pcf_ue = NULL; + + ogs_sbi_message_t message; + ogs_sbi_request_t *request = NULL; + + OpenAPI_pcf_binding_t PcfBinding; + OpenAPI_list_t *PcfIpEndPointList = NULL; + OpenAPI_snssai_t sNssai; + OpenAPI_lnode_t *node = NULL; + + ogs_sbi_nf_instance_t *nf_instance = NULL; + ogs_sbi_nf_service_t *nf_service = NULL; + + int i, fqdn_len; + char fqdn[OGS_MAX_FQDN_LEN]; + + ogs_assert(sess); + pcf_ue = sess->pcf_ue; + ogs_assert(pcf_ue); + + memset(&message, 0, sizeof(message)); + message.h.method = (char *)OGS_SBI_HTTP_METHOD_POST; + message.h.service.name = (char *)OGS_SBI_SERVICE_NAME_NBSF_MANAGEMENT; + message.h.api.version = (char *)OGS_SBI_API_V1; + message.h.resource.component[0] = + (char *)OGS_SBI_RESOURCE_NAME_PCF_BINDINGS; + + memset(&PcfBinding, 0, sizeof(PcfBinding)); + + PcfBinding.supi = pcf_ue->supi; + PcfBinding.gpsi = pcf_ue->gpsi; + + PcfBinding.ipv4_addr = sess->ipv4addr_string; + PcfBinding.ipv6_prefix = sess->ipv6prefix_string; + + ogs_assert(sess->dnn); + PcfBinding.dnn = sess->dnn; + + nf_instance = ogs_sbi_nf_instance_find(ogs_sbi_self()->nf_instance_id); + ogs_assert(nf_instance); + nf_service = ogs_list_first(&nf_instance->nf_service_list); + ogs_assert(nf_service); + + if (strlen(nf_service->fqdn)) { + memset(fqdn, 0, sizeof(fqdn)); + fqdn_len = ogs_fqdn_build(fqdn, + nf_service->fqdn, strlen(nf_service->fqdn)); + PcfBinding.pcf_fqdn = ogs_memdup(fqdn, fqdn_len); + } + + PcfIpEndPointList = OpenAPI_list_create(); + ogs_assert(PcfIpEndPointList); + + for (i = 0; i < nf_service->num_of_addr; i++) { + ogs_sockaddr_t *ipv4 = NULL; + ogs_sockaddr_t *ipv6 = NULL; + + OpenAPI_ip_end_point_t *IpEndPoint = NULL; + + ipv4 = nf_service->addr[i].ipv4; + ipv6 = nf_service->addr[i].ipv6; + + if (ipv4 || ipv6) { + IpEndPoint = ogs_calloc(1, sizeof(*IpEndPoint)); + ogs_assert(IpEndPoint); + if (ipv4) IpEndPoint->ipv4_address = ogs_ipstrdup(ipv4); + if (ipv6) IpEndPoint->ipv6_address = ogs_ipstrdup(ipv6); + IpEndPoint->port = nf_service->addr[i].port; + OpenAPI_list_add(PcfIpEndPointList, IpEndPoint); + } + } + + if (PcfIpEndPointList->count) + PcfBinding.pcf_ip_end_points = PcfIpEndPointList; + else + OpenAPI_list_free(PcfIpEndPointList); + + ogs_assert(sess->s_nssai.sst); + memset(&sNssai, 0, sizeof(sNssai)); + sNssai.sst = sess->s_nssai.sst; + sNssai.sd = ogs_s_nssai_sd_to_string(sess->s_nssai.sd); + PcfBinding.snssai = &sNssai; + + if (sess->management_features) { + PcfBinding.supp_feat = ogs_uint64_to_string(sess->management_features); + } + + message.PcfBinding = &PcfBinding; + + request = ogs_sbi_build_request(&message); + ogs_assert(request); + + if (sNssai.sd) + ogs_free(sNssai.sd); + + if (PcfBinding.supp_feat) + ogs_free(PcfBinding.supp_feat); + + OpenAPI_list_for_each(PcfBinding.pcf_ip_end_points, node) { + OpenAPI_ip_end_point_t *PcfIpEndPoint = node->data; + ogs_assert(PcfIpEndPoint); + if (PcfIpEndPoint->ipv4_address) + ogs_free(PcfIpEndPoint->ipv4_address); + if (PcfIpEndPoint->ipv6_address) + ogs_free(PcfIpEndPoint->ipv6_address); + ogs_free(PcfIpEndPoint); + } + OpenAPI_list_free(PcfBinding.pcf_ip_end_points); + + if (PcfBinding.pcf_fqdn) + ogs_free(PcfBinding.pcf_fqdn); + + return request; +} + +ogs_sbi_request_t *pcf_nbsf_management_build_de_register( + pcf_sess_t *sess, void *data) +{ + pcf_ue_t *pcf_ue = NULL; + + ogs_sbi_message_t message; + ogs_sbi_request_t *request = NULL; + + ogs_assert(sess); + pcf_ue = sess->pcf_ue; + ogs_assert(pcf_ue); + ogs_assert(sess->binding_id); + + memset(&message, 0, sizeof(message)); + message.h.method = (char *)OGS_SBI_HTTP_METHOD_DELETE; + message.h.service.name = (char *)OGS_SBI_SERVICE_NAME_NBSF_MANAGEMENT; + message.h.api.version = (char *)OGS_SBI_API_V1; + message.h.resource.component[0] = + (char *)OGS_SBI_RESOURCE_NAME_PCF_BINDINGS; + message.h.resource.component[1] = sess->binding_id; + + request = ogs_sbi_build_request(&message); + ogs_assert(request); + + return request; +} diff --git a/src/pcf/nbsf-build.h b/src/pcf/nbsf-build.h new file mode 100644 index 000000000..55a20cfce --- /dev/null +++ b/src/pcf/nbsf-build.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef PCF_NBSF_BUILD_H +#define PCF_NBSF_BUILD_H + +#include "context.h" + +#ifdef __cplusplus +extern "C" { +#endif + +ogs_sbi_request_t *pcf_nbsf_management_build_register( + pcf_sess_t *sess, void *data); +ogs_sbi_request_t *pcf_nbsf_management_build_de_register( + pcf_sess_t *sess, void *data); + +#ifdef __cplusplus +} +#endif + +#endif /* PCF_NBSF_BUILD_H */ diff --git a/src/pcf/nbsf-handler.c b/src/pcf/nbsf-handler.c new file mode 100644 index 000000000..15b4f0166 --- /dev/null +++ b/src/pcf/nbsf-handler.c @@ -0,0 +1,506 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "sbi-path.h" + +#include "nbsf-handler.h" + +bool pcf_nbsf_management_handle_register( + pcf_sess_t *sess, ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) +{ + int i, j, rv, status = 0; + char *strerror = NULL; + pcf_ue_t *pcf_ue = NULL; + ogs_sbi_server_t *server = NULL; + + ogs_sbi_message_t sendmsg; + ogs_sbi_header_t header; + ogs_sbi_response_t *response = NULL; + + ogs_sbi_message_t message; + + ogs_session_data_t session_data; + + ogs_session_t *session = NULL; + + OpenAPI_sm_policy_decision_t SmPolicyDecision; + + OpenAPI_lnode_t *node = NULL, *node2 = NULL; + + OpenAPI_list_t *SessRuleList = NULL; + OpenAPI_map_t *SessRuleMap = NULL; + OpenAPI_session_rule_t *SessionRule = NULL; + + OpenAPI_ambr_t AuthSessAmbr; + OpenAPI_authorized_default_qos_t AuthDefQos; + + OpenAPI_list_t *PccRuleList = NULL; + OpenAPI_map_t *PccRuleMap = NULL; + OpenAPI_pcc_rule_t *PccRule = NULL; + OpenAPI_flow_information_t *FlowInformation = NULL; + + OpenAPI_list_t *QosDecisionList = NULL; + OpenAPI_map_t *QosDecisionMap = NULL; + OpenAPI_qos_data_t *QosData = NULL; + + OpenAPI_list_t *PolicyCtrlReqTriggers = NULL; + + ogs_assert(sess); + pcf_ue = sess->pcf_ue; + ogs_assert(pcf_ue); + ogs_assert(stream); + server = ogs_sbi_server_from_stream(stream); + ogs_assert(server); + + ogs_assert(recvmsg); + + memset(&session_data, 0, sizeof(ogs_session_data_t)); + + ogs_assert(pcf_ue->supi); + ogs_assert(sess->dnn); + + if (!recvmsg->http.location) { + strerror = ogs_msprintf("[%s:%d] No http.location", + pcf_ue->supi, sess->psi); + status = OGS_SBI_HTTP_STATUS_BAD_REQUEST; + goto cleanup; + } + + if (!recvmsg->PcfBinding) { + strerror = ogs_msprintf("[%s:%d] No PcfBinding", + pcf_ue->supi, sess->psi); + status = OGS_SBI_HTTP_STATUS_BAD_REQUEST; + goto cleanup; + } + + memset(&header, 0, sizeof(header)); + header.uri = recvmsg->http.location; + + rv = ogs_sbi_parse_header(&message, &header); + if (rv != OGS_OK) { + strerror = ogs_msprintf("[%s:%d] Cannot parse http.location [%s]", + pcf_ue->supi, sess->psi, recvmsg->http.location); + goto cleanup; + } + + if (!message.h.resource.component[1]) { + strerror = ogs_msprintf("[%s:%d] No Binding ID [%s]", + pcf_ue->supi, sess->psi, recvmsg->http.location); + + ogs_sbi_header_free(&header); + goto cleanup; + } + + if (sess->binding_id) + ogs_free(sess->binding_id); + sess->binding_id = ogs_strdup(message.h.resource.component[1]); + + ogs_sbi_header_free(&header); + + rv = ogs_dbi_session_data( + pcf_ue->supi, &sess->s_nssai, sess->dnn, &session_data); + if (rv != OGS_OK) { + strerror = ogs_msprintf("[%s:%d] Cannot find SUPI in DB", + pcf_ue->supi, sess->psi); + status = OGS_SBI_HTTP_STATUS_NOT_FOUND; + goto cleanup; + } + + session = &session_data.session; + + if (!session->qos.index) { + strerror = ogs_msprintf("[%s:%d] No 5QI", pcf_ue->supi, sess->psi); + status = OGS_SBI_HTTP_STATUS_BAD_REQUEST; + goto cleanup; + } + if (!session->qos.arp.priority_level) { + strerror = ogs_msprintf("[%s:%d] No Priority Level", + pcf_ue->supi, sess->psi); + status = OGS_SBI_HTTP_STATUS_BAD_REQUEST; + goto cleanup; + } + + if (!session->ambr.uplink && !session->ambr.downlink) { + strerror = ogs_msprintf("[%s:%d] No Session-AMBR", + pcf_ue->supi, sess->psi); + status = OGS_SBI_HTTP_STATUS_BAD_REQUEST; + goto cleanup; + } + + memset(&SmPolicyDecision, 0, sizeof(SmPolicyDecision)); + + PolicyCtrlReqTriggers = OpenAPI_list_create(); + ogs_assert(PolicyCtrlReqTriggers); + + /************************************************************** + * Session Rule + *************************************************************/ + SessRuleList = OpenAPI_list_create(); + ogs_assert(SessRuleList); + + SessionRule = ogs_calloc(1, sizeof(*SessionRule)); + ogs_assert(SessionRule); + + /* Only 1 SessionRule is used */ + SessionRule->sess_rule_id = (char *)"1"; + + if (OGS_SBI_FEATURES_IS_SET(sess->smpolicycontrol_features, + OGS_SBI_NPCF_SMPOLICYCONTROL_DN_AUTHORIZATION)) { + if (sess->subscribed_sess_ambr) { + ogs_bitrate_t subscribed_sess_ambr; + + subscribed_sess_ambr.uplink = ogs_sbi_bitrate_from_string( + sess->subscribed_sess_ambr->uplink); + subscribed_sess_ambr.downlink = ogs_sbi_bitrate_from_string( + sess->subscribed_sess_ambr->downlink); + if (((subscribed_sess_ambr.uplink / 1024) != + (session->ambr.uplink / 1024)) || + ((subscribed_sess_ambr.downlink / 1024) != + (session->ambr.downlink / 1024))) { + + OpenAPI_list_add(PolicyCtrlReqTriggers, + (void *)OpenAPI_policy_control_request_trigger_SE_AMBR_CH); + } + + memset(&AuthSessAmbr, 0, sizeof(AuthSessAmbr)); + AuthSessAmbr.uplink = ogs_sbi_bitrate_to_string( + session->ambr.uplink, OGS_SBI_BITRATE_KBPS); + AuthSessAmbr.downlink = ogs_sbi_bitrate_to_string( + session->ambr.downlink, OGS_SBI_BITRATE_KBPS); + SessionRule->auth_sess_ambr = &AuthSessAmbr; + } + } + + if (sess->subscribed_default_qos) { + bool triggered = false; + + memset(&AuthDefQos, 0, sizeof(AuthDefQos)); + AuthDefQos.arp = ogs_calloc(1, sizeof(OpenAPI_arp_t)); + ogs_assert(AuthDefQos.arp); + + AuthDefQos._5qi = session->qos.index; + AuthDefQos.priority_level = session->qos.arp.priority_level; + + if (session->qos.arp.pre_emption_capability == + OGS_5GC_PRE_EMPTION_ENABLED) + AuthDefQos.arp->preempt_cap = + OpenAPI_preemption_capability_MAY_PREEMPT; + else if (session->qos.arp.pre_emption_capability == + OGS_5GC_PRE_EMPTION_DISABLED) + AuthDefQos.arp->preempt_cap = + OpenAPI_preemption_capability_NOT_PREEMPT; + ogs_assert(AuthDefQos.arp->preempt_cap); + + if (session->qos.arp.pre_emption_vulnerability == + OGS_5GC_PRE_EMPTION_ENABLED) + AuthDefQos.arp->preempt_vuln = + OpenAPI_preemption_vulnerability_PREEMPTABLE; + else if (session->qos.arp.pre_emption_vulnerability == + OGS_5GC_PRE_EMPTION_DISABLED) + AuthDefQos.arp->preempt_vuln = + OpenAPI_preemption_vulnerability_NOT_PREEMPTABLE; + ogs_assert(AuthDefQos.arp->preempt_vuln); + AuthDefQos.arp->priority_level = session->qos.arp.priority_level; + + SessionRule->auth_def_qos = &AuthDefQos; + + if (sess->subscribed_default_qos->_5qi != AuthDefQos._5qi) + triggered = true; + if (sess->subscribed_default_qos->priority_level != + AuthDefQos.priority_level) + triggered = true; + if (sess->subscribed_default_qos->arp) { + if (sess->subscribed_default_qos->arp->priority_level != + AuthDefQos.arp->priority_level) + triggered = true; + if (sess->subscribed_default_qos->arp->preempt_cap != + AuthDefQos.arp->preempt_cap) + triggered = true; + if (sess->subscribed_default_qos->arp->preempt_vuln != + AuthDefQos.arp->preempt_vuln) + triggered = true; + + } + + if (triggered) + OpenAPI_list_add(PolicyCtrlReqTriggers, + (void *)OpenAPI_policy_control_request_trigger_DEF_QOS_CH); + + } + + SessRuleMap = OpenAPI_map_create( + SessionRule->sess_rule_id, SessionRule); + ogs_assert(SessRuleMap); + + OpenAPI_list_add(SessRuleList, SessRuleMap); + + if (SessRuleList->count) + SmPolicyDecision.sess_rules = SessRuleList; + + /************************************************************** + * PCC Rule & QoS Decision + *************************************************************/ + PccRuleList = OpenAPI_list_create(); + ogs_assert(PccRuleList); + + QosDecisionList = OpenAPI_list_create(); + ogs_assert(QosDecisionList); + + for (i = 0; i < session_data.num_of_pcc_rule; i++) { + OpenAPI_list_t *FlowInformationList = NULL; + ogs_pcc_rule_t *pcc_rule = &session_data.pcc_rule[i]; + + ogs_assert(pcc_rule); + + PccRule = ogs_calloc(1, sizeof(*PccRule)); + ogs_assert(PccRule); + QosData = ogs_calloc(1, sizeof(*QosData)); + ogs_assert(QosData); + + /* + * At this point, only 1 QosData is used for PccRule. + * Therefore, QoS ID uses the same value as PCC Rule ID. + */ + PccRule->pcc_rule_id = pcc_rule->id; + QosData->qos_id = pcc_rule->id; + + PccRule->ref_qos_data = OpenAPI_list_create(); + ogs_assert(PccRule->ref_qos_data); + + OpenAPI_list_add(PccRule->ref_qos_data, QosData->qos_id); + + PccRule->precedence = pcc_rule->precedence; + + FlowInformationList = OpenAPI_list_create(); + ogs_assert(FlowInformationList); + + for (j = 0; j < pcc_rule->num_of_flow; j++) { + ogs_flow_t *flow = &pcc_rule->flow[j]; + ogs_assert(flow); + + FlowInformation = ogs_calloc(1, sizeof(*FlowInformation)); + ogs_assert(FlowInformation); + + if (flow->direction == OGS_FLOW_UPLINK_ONLY) + FlowInformation->flow_direction = + OpenAPI_flow_direction_UPLINK; + else if (flow->direction == OGS_FLOW_DOWNLINK_ONLY) + FlowInformation->flow_direction = + OpenAPI_flow_direction_DOWNLINK; + else { + ogs_fatal("Unsupported direction [%d]", flow->direction); + ogs_assert_if_reached(); + } + + ogs_assert(flow->description); + FlowInformation->flow_description = flow->description; + + OpenAPI_list_add(FlowInformationList, FlowInformation); + } + + if (FlowInformationList->count) + PccRule->flow_infos = FlowInformationList; + else + OpenAPI_list_free(FlowInformationList); + + PccRuleMap = OpenAPI_map_create(PccRule->pcc_rule_id, PccRule); + ogs_assert(PccRuleMap); + + OpenAPI_list_add(PccRuleList, PccRuleMap); + + QosData->_5qi = pcc_rule->qos.index; + QosData->priority_level = pcc_rule->qos.arp.priority_level; + + QosData->arp = ogs_calloc(1, sizeof(OpenAPI_arp_t)); + ogs_assert(QosData->arp); + + if (pcc_rule->qos.arp.pre_emption_capability == + OGS_5GC_PRE_EMPTION_ENABLED) + QosData->arp->preempt_cap = + OpenAPI_preemption_capability_MAY_PREEMPT; + else if (pcc_rule->qos.arp.pre_emption_capability == + OGS_5GC_PRE_EMPTION_DISABLED) + QosData->arp->preempt_cap = + OpenAPI_preemption_capability_NOT_PREEMPT; + ogs_assert(pcc_rule->qos.arp.pre_emption_capability); + + if (pcc_rule->qos.arp.pre_emption_vulnerability == + OGS_5GC_PRE_EMPTION_ENABLED) + QosData->arp->preempt_vuln = + OpenAPI_preemption_vulnerability_PREEMPTABLE; + else if (pcc_rule->qos.arp.pre_emption_vulnerability == + OGS_5GC_PRE_EMPTION_DISABLED) + QosData->arp->preempt_vuln = + OpenAPI_preemption_vulnerability_NOT_PREEMPTABLE; + ogs_assert(pcc_rule->qos.arp.pre_emption_vulnerability); + QosData->arp->priority_level = pcc_rule->qos.arp.priority_level; + + if (pcc_rule->qos.mbr.uplink) + QosData->maxbr_ul = ogs_sbi_bitrate_to_string( + pcc_rule->qos.mbr.uplink, OGS_SBI_BITRATE_KBPS); + if (pcc_rule->qos.mbr.downlink) + QosData->maxbr_dl = ogs_sbi_bitrate_to_string( + pcc_rule->qos.mbr.downlink, OGS_SBI_BITRATE_KBPS); + + if (pcc_rule->qos.gbr.uplink) + QosData->gbr_ul = ogs_sbi_bitrate_to_string( + pcc_rule->qos.gbr.uplink, OGS_SBI_BITRATE_KBPS); + if (pcc_rule->qos.gbr.downlink) + QosData->gbr_dl = ogs_sbi_bitrate_to_string( + pcc_rule->qos.gbr.downlink, OGS_SBI_BITRATE_KBPS); + + QosDecisionMap = OpenAPI_map_create(QosData->qos_id, QosData); + ogs_assert(QosDecisionMap); + + OpenAPI_list_add(QosDecisionList, QosDecisionMap); + } + + if (PccRuleList->count) + SmPolicyDecision.pcc_rules = PccRuleList; + + if (QosDecisionList->count) + SmPolicyDecision.qos_decs = QosDecisionList; + + /* Policy Control Request Triggers */ + if (PolicyCtrlReqTriggers->count) + SmPolicyDecision.policy_ctrl_req_triggers = PolicyCtrlReqTriggers; + + /* Supported Features */ + if (sess->smpolicycontrol_features) { + SmPolicyDecision.supp_feat = + ogs_uint64_to_string(sess->smpolicycontrol_features); + } + + memset(&header, 0, sizeof(header)); + header.service.name = (char *)OGS_SBI_SERVICE_NAME_NPCF_SMPOLICYCONTROL; + header.api.version = (char *)OGS_SBI_API_V1; + header.resource.component[0] = (char *)OGS_SBI_RESOURCE_NAME_POLICIES; + header.resource.component[1] = sess->sm_policy_id; + + memset(&sendmsg, 0, sizeof(sendmsg)); + sendmsg.SmPolicyDecision = &SmPolicyDecision; + sendmsg.http.location = ogs_sbi_server_uri(server, &header); + + response = ogs_sbi_build_response( + &sendmsg, OGS_SBI_HTTP_STATUS_CREATED); + ogs_assert(response); + ogs_sbi_server_send_response(stream, response); + + ogs_free(sendmsg.http.location); + + OpenAPI_list_for_each(SessRuleList, node) { + SessRuleMap = node->data; + if (SessRuleMap) { + SessionRule = SessRuleMap->value; + if (SessionRule) { + if (SessionRule->auth_sess_ambr) { + if (SessionRule->auth_sess_ambr->uplink) + ogs_free(SessionRule->auth_sess_ambr->uplink); + if (SessionRule->auth_sess_ambr->downlink) + ogs_free(SessionRule->auth_sess_ambr->downlink); + } + if (SessionRule->auth_def_qos) { + ogs_free(SessionRule->auth_def_qos->arp); + + } + ogs_free(SessionRule); + } + ogs_free(SessRuleMap); + } + } + OpenAPI_list_free(SessRuleList); + + OpenAPI_list_for_each(PccRuleList, node) { + PccRuleMap = node->data; + if (PccRuleMap) { + PccRule = PccRuleMap->value; + if (PccRule) { + if (PccRule->ref_qos_data) + OpenAPI_list_free(PccRule->ref_qos_data); + if (PccRule->flow_infos) { + OpenAPI_list_for_each(PccRule->flow_infos, node2) { + FlowInformation = node2->data; + if (FlowInformation) ogs_free(FlowInformation); + } + OpenAPI_list_free(PccRule->flow_infos); + } + ogs_free(PccRule); + } + ogs_free(PccRuleMap); + } + } + OpenAPI_list_free(PccRuleList); + + OpenAPI_list_for_each(QosDecisionList, node) { + QosDecisionMap = node->data; + if (QosDecisionMap) { + QosData = QosDecisionMap->value; + if (QosData) { + if (QosData->arp) ogs_free(QosData->arp); + if (QosData->maxbr_ul) ogs_free(QosData->maxbr_ul); + if (QosData->maxbr_dl) ogs_free(QosData->maxbr_dl); + if (QosData->gbr_ul) ogs_free(QosData->gbr_ul); + if (QosData->gbr_dl) ogs_free(QosData->gbr_dl); + + ogs_free(QosData); + } + ogs_free(QosDecisionMap); + } + } + OpenAPI_list_free(QosDecisionList); + + OpenAPI_list_free(PolicyCtrlReqTriggers); + + if (SmPolicyDecision.supp_feat) + ogs_free(SmPolicyDecision.supp_feat); + + ogs_session_data_free(&session_data); + + return true; + +cleanup: + ogs_assert(strerror); + ogs_assert(status); + ogs_error("%s", strerror); + ogs_sbi_server_send_error(stream, status, recvmsg, strerror, NULL); + ogs_free(strerror); + + ogs_session_data_free(&session_data); + + return false; +} + +bool pcf_nbsf_management_handle_de_register( + pcf_sess_t *sess, ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) +{ + ogs_sbi_message_t sendmsg; + ogs_sbi_response_t *response = NULL; + + ogs_assert(sess); + ogs_assert(stream); + + memset(&sendmsg, 0, sizeof(sendmsg)); + + response = ogs_sbi_build_response( + &sendmsg, OGS_SBI_HTTP_STATUS_NO_CONTENT); + ogs_assert(response); + ogs_sbi_server_send_response(stream, response); + + return true; +} diff --git a/src/pcf/nbsf-handler.h b/src/pcf/nbsf-handler.h new file mode 100644 index 000000000..a1f55c2f9 --- /dev/null +++ b/src/pcf/nbsf-handler.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef PCF_NBSF_HANDLER_H +#define PCF_NBSF_HANDLER_H + +#include "context.h" + +#ifdef __cplusplus +extern "C" { +#endif + +bool pcf_nbsf_management_handle_register( + pcf_sess_t *sess, ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); +bool pcf_nbsf_management_handle_de_register( + pcf_sess_t *sess, ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); + +#ifdef __cplusplus +} +#endif + +#endif /* PCF_NBSF_HANDLER_H */ diff --git a/src/pcf/nf-sm.c b/src/pcf/nf-sm.c index 6061692e5..96071c530 100644 --- a/src/pcf/nf-sm.c +++ b/src/pcf/nf-sm.c @@ -210,6 +210,8 @@ void pcf_nf_state_registered(ogs_fsm_t *s, pcf_event_t *e) ogs_app()->time.nf_instance.no_heartbeat_margin)); } + ogs_nnrf_nfm_send_nf_status_subscribe(client, + pcf_self()->nf_type, nf_instance->id, OpenAPI_nf_type_BSF); ogs_nnrf_nfm_send_nf_status_subscribe(client, pcf_self()->nf_type, nf_instance->id, OpenAPI_nf_type_UDR); } diff --git a/src/pcf/npcf-handler.c b/src/pcf/npcf-handler.c index c961f8d5c..642901509 100644 --- a/src/pcf/npcf-handler.c +++ b/src/pcf/npcf-handler.c @@ -29,6 +29,9 @@ bool pcf_npcf_am_policy_contrtol_handle_create(pcf_ue_t *pcf_ue, uint64_t supported_features = 0; + ogs_sbi_client_t *client = NULL; + ogs_sockaddr_t *addr = NULL; + ogs_assert(pcf_ue); ogs_assert(stream); ogs_assert(message); @@ -62,15 +65,43 @@ bool pcf_npcf_am_policy_contrtol_handle_create(pcf_ue_t *pcf_ue, return false; } + addr = ogs_sbi_getaddr_from_uri(PolicyAssociationRequest->notification_uri); + if (!addr) { + ogs_error("[%s] Invalid URI [%s]", + pcf_ue->supi, PolicyAssociationRequest->notification_uri); + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + message, "[%s] Invalid URI", pcf_ue->supi); + return false; + } + if (pcf_ue->notification_uri) ogs_free(pcf_ue->notification_uri); pcf_ue->notification_uri = ogs_strdup( PolicyAssociationRequest->notification_uri); + client = ogs_sbi_client_find(addr); + if (!client) { + client = ogs_sbi_client_add(addr); + ogs_assert(client); + } + OGS_SETUP_SBI_CLIENT(&pcf_ue->namf, client); + + ogs_freeaddrinfo(addr); + supported_features = ogs_uint64_from_string(PolicyAssociationRequest->supp_feat); pcf_ue->am_policy_control_features &= supported_features; + if (pcf_ue->gpsi) + ogs_free(pcf_ue->gpsi); + pcf_ue->gpsi = ogs_strdup(PolicyAssociationRequest->gpsi); + + pcf_ue->access_type = PolicyAssociationRequest->access_type; + + if (pcf_ue->pei) + ogs_free(pcf_ue->pei); + pcf_ue->pei = ogs_strdup(PolicyAssociationRequest->pei); + Guami = PolicyAssociationRequest->guami; if (Guami && Guami->amf_id && Guami->plmn_id && Guami->plmn_id->mnc && Guami->plmn_id->mcc) { @@ -107,6 +138,9 @@ bool pcf_npcf_smpolicycontrtol_handle_create(pcf_sess_t *sess, uint64_t supported_features = 0; + ogs_sbi_client_t *client = NULL; + ogs_sockaddr_t *addr = NULL; + ogs_assert(sess); pcf_ue = sess->pcf_ue; ogs_assert(stream); @@ -153,6 +187,17 @@ bool pcf_npcf_smpolicycontrtol_handle_create(pcf_sess_t *sess, goto cleanup; } + if (!SmPolicyContextData->ipv4_address && + !SmPolicyContextData->ipv6_address_prefix) { + strerror = ogs_msprintf( + "[%s:%d] No IPv4 address[%p] or IPv6 prefix[%p]", + pcf_ue->supi, sess->psi, + SmPolicyContextData->ipv4_address, + SmPolicyContextData->ipv6_address_prefix); + status = OGS_SBI_HTTP_STATUS_BAD_REQUEST; + goto cleanup; + } + sliceInfo = SmPolicyContextData->slice_info; if (!sliceInfo) { strerror = ogs_msprintf("[%s:%d] No sliceInfo", @@ -161,6 +206,21 @@ bool pcf_npcf_smpolicycontrtol_handle_create(pcf_sess_t *sess, goto cleanup; } + if (!sliceInfo->sst) { + strerror = ogs_msprintf("[%s:%d] No sliceInfo->sst", + pcf_ue->supi, sess->psi); + status = OGS_SBI_HTTP_STATUS_BAD_REQUEST; + goto cleanup; + } + + addr = ogs_sbi_getaddr_from_uri(SmPolicyContextData->notification_uri); + if (!addr) { + strerror = ogs_msprintf("[%s:%d] Invalid URI [%s]", + pcf_ue->supi, sess->psi, SmPolicyContextData->notification_uri); + status = OGS_SBI_HTTP_STATUS_BAD_REQUEST; + goto cleanup; + } + if (SmPolicyContextData->supp_feat) { supported_features = ogs_uint64_from_string(SmPolicyContextData->supp_feat); @@ -179,6 +239,23 @@ bool pcf_npcf_smpolicycontrtol_handle_create(pcf_sess_t *sess, ogs_free(sess->notification_uri); sess->notification_uri = ogs_strdup(SmPolicyContextData->notification_uri); + client = ogs_sbi_client_find(addr); + if (!client) { + client = ogs_sbi_client_add(addr); + ogs_assert(client); + } + OGS_SETUP_SBI_CLIENT(&sess->nsmf, client); + + ogs_freeaddrinfo(addr); + + if (SmPolicyContextData->ipv4_address) + ogs_assert(true == + pcf_sess_set_ipv4addr(sess, SmPolicyContextData->ipv4_address)); + if (SmPolicyContextData->ipv6_address_prefix) + ogs_assert(true == + pcf_sess_set_ipv6prefix( + sess, SmPolicyContextData->ipv6_address_prefix)); + sess->s_nssai.sst = sliceInfo->sst; sess->s_nssai.sd = ogs_s_nssai_sd_from_string(sliceInfo->sd); @@ -204,3 +281,219 @@ cleanup: return false; } + +bool pcf_npcf_smpolicycontrtol_handle_delete(pcf_sess_t *sess, + ogs_sbi_stream_t *stream, ogs_sbi_message_t *message) +{ + int status = 0; + char *strerror = NULL; + pcf_ue_t *pcf_ue = NULL; + + OpenAPI_sm_policy_delete_data_t *SmPolicyDeleteData = NULL; + + ogs_assert(sess); + pcf_ue = sess->pcf_ue; + ogs_assert(stream); + ogs_assert(message); + + SmPolicyDeleteData = message->SmPolicyDeleteData; + if (!SmPolicyDeleteData) { + strerror = ogs_msprintf("[%s:%d] No SmPolicyDeleteData", + pcf_ue->supi, sess->psi); + status = OGS_SBI_HTTP_STATUS_BAD_REQUEST; + goto cleanup; + } + + pcf_sess_sbi_discover_and_send(OpenAPI_nf_type_BSF, sess, stream, NULL, + pcf_nbsf_management_build_de_register); + + return true; + +cleanup: + ogs_assert(status); + ogs_assert(strerror); + ogs_error("%s", strerror); + ogs_sbi_server_send_error(stream, status, message, strerror, NULL); + ogs_free(strerror); + + return false; +} + +bool pcf_npcf_policyauthorization_handle_create(pcf_sess_t *sess, + ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) +{ + int status = 0; + char *strerror = NULL; + pcf_ue_t *pcf_ue = NULL; + + OpenAPI_app_session_context_t *AppSessionContext = NULL; + OpenAPI_app_session_context_req_data_t *AscReqData = NULL; + + uint64_t supported_features = 0; + + ogs_sbi_server_t *server = NULL; + ogs_sbi_header_t header; + ogs_sbi_message_t sendmsg; + ogs_sbi_response_t *response = NULL; + + ogs_ims_data_t ims_data; + ogs_media_component_t *media_component = NULL; + ogs_media_sub_component_t *sub = NULL; + + OpenAPI_list_t *MediaComponentList = NULL; + OpenAPI_map_t *MediaComponentMap = NULL; + OpenAPI_media_component_t *MediaComponent = NULL; + + OpenAPI_list_t *SubComponentList = NULL; + OpenAPI_map_t *SubComponentMap = NULL; + OpenAPI_media_sub_component_t *SubComponent = NULL; + + OpenAPI_list_t *fDescList = NULL; + + OpenAPI_lnode_t *node = NULL, *node2 = NULL, *node3 = NULL; + + ogs_assert(sess); + pcf_ue = sess->pcf_ue; + ogs_assert(stream); + ogs_assert(recvmsg); + + ogs_assert(sess->app_session_id); + + server = ogs_sbi_server_from_stream(stream); + ogs_assert(server); + + AppSessionContext = recvmsg->AppSessionContext; + if (!AppSessionContext) { + strerror = ogs_msprintf("[%s:%d] No AppSessionContext", + pcf_ue->supi, sess->psi); + status = OGS_SBI_HTTP_STATUS_BAD_REQUEST; + goto cleanup; + } + + AscReqData = AppSessionContext->asc_req_data; + if (!AscReqData) { + strerror = ogs_msprintf("[%s:%d] No AscReqData", + pcf_ue->supi, sess->psi); + status = OGS_SBI_HTTP_STATUS_BAD_REQUEST; + goto cleanup; + } + + if (!AscReqData->supp_feat) { + strerror = ogs_msprintf("[%s:%d] No AscReqData->suppFeat", + pcf_ue->supi, sess->psi); + status = OGS_SBI_HTTP_STATUS_BAD_REQUEST; + goto cleanup; + } + + if (!AscReqData->notif_uri) { + strerror = ogs_msprintf("[%s:%d] No AscReqData->notifUri", + pcf_ue->supi, sess->psi); + status = OGS_SBI_HTTP_STATUS_BAD_REQUEST; + goto cleanup; + } + + if (!AscReqData->med_components) { + strerror = ogs_msprintf("[%s:%d] No AscReqData->MediaCompoenent", + pcf_ue->supi, sess->psi); + status = OGS_SBI_HTTP_STATUS_BAD_REQUEST; + goto cleanup; + } + + supported_features = ogs_uint64_from_string(AscReqData->supp_feat); + sess->policyauthorization_features &= supported_features; + + memset(&ims_data, 0, sizeof(ims_data)); + media_component = &ims_data. + media_component[ims_data.num_of_media_component]; + + MediaComponentList = AscReqData->med_components; + OpenAPI_list_for_each(MediaComponentList, node) { + MediaComponentMap = node->data; + if (MediaComponentMap) { + MediaComponent = MediaComponentMap->value; + if (MediaComponent) { + media_component->media_component_number = + MediaComponent->med_comp_n; + media_component->media_type = MediaComponent->med_type; + if (MediaComponent->mar_bw_dl) + media_component->max_requested_bandwidth_dl = + ogs_sbi_bitrate_from_string(MediaComponent->mar_bw_dl); + if (MediaComponent->mar_bw_ul) + media_component->max_requested_bandwidth_ul = + ogs_sbi_bitrate_from_string(MediaComponent->mar_bw_ul); + if (MediaComponent->mir_bw_dl) + media_component->min_requested_bandwidth_dl = + ogs_sbi_bitrate_from_string(MediaComponent->mir_bw_dl); + if (MediaComponent->mir_bw_ul) + media_component->min_requested_bandwidth_ul = + ogs_sbi_bitrate_from_string(MediaComponent->mir_bw_ul); + media_component->flow_status = MediaComponent->f_status; + + sub = &media_component->sub[media_component->num_of_sub]; + + SubComponentList = MediaComponent->med_sub_comps; + OpenAPI_list_for_each(SubComponentList, node2) { + SubComponentMap = node2->data; + if (SubComponentMap) { + SubComponent = SubComponentMap->value; + if (SubComponent) { + sub->flow_number = SubComponent->f_num; + sub->flow_usage = SubComponent->flow_usage; + + fDescList = SubComponent->f_descs; + OpenAPI_list_for_each(fDescList, node3) { + ogs_flow_t *flow = &sub->flow[sub->num_of_flow]; + if (node3->data) { + flow->description = ogs_strdup(node3->data); + ogs_assert(flow->description); + + sub->num_of_flow++; + } + } + } + } + media_component->num_of_sub++; + } + } + } + ims_data.num_of_media_component++; + } + + memset(&sendmsg, 0, sizeof(sendmsg)); + + memset(&header, 0, sizeof(header)); + header.service.name = (char *)OGS_SBI_SERVICE_NAME_NPCF_POLICYAUTHORIZATION; + header.api.version = (char *)OGS_SBI_API_V1; + header.resource.component[0] = (char *)OGS_SBI_RESOURCE_NAME_APP_SESSIONS; + header.resource.component[1] = (char *)sess->app_session_id; + sendmsg.http.location = ogs_sbi_server_uri(server, &header); + ogs_assert(sendmsg.http.location); + + sendmsg.AppSessionContext = recvmsg->AppSessionContext; + + response = ogs_sbi_build_response(&sendmsg, OGS_SBI_HTTP_STATUS_CREATED); + ogs_assert(response); + ogs_sbi_server_send_response(stream, response); + + ogs_free(sendmsg.http.location); + +#if 0 + pcf_sbi_send_smpolicycontrol_notify(sess); + pcf_sbi_send_am_policy_control_notify(pcf_ue); +#endif + + ogs_ims_data_free(&ims_data); + + return true; + +cleanup: + ogs_assert(status); + ogs_assert(strerror); + ogs_error("%s", strerror); + ogs_sbi_server_send_error(stream, status, recvmsg, strerror, NULL); + ogs_free(strerror); + + ogs_ims_data_free(&ims_data); + + return false; +} diff --git a/src/pcf/npcf-handler.h b/src/pcf/npcf-handler.h index 7e65978b8..ab5db4955 100644 --- a/src/pcf/npcf-handler.h +++ b/src/pcf/npcf-handler.h @@ -31,6 +31,11 @@ bool pcf_npcf_am_policy_contrtol_handle_create(pcf_ue_t *pcf_ue, bool pcf_npcf_smpolicycontrtol_handle_create(pcf_sess_t *sess, ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); +bool pcf_npcf_smpolicycontrtol_handle_delete(pcf_sess_t *sess, + ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); + +bool pcf_npcf_policyauthorization_handle_create(pcf_sess_t *sess, + ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); #ifdef __cplusplus } diff --git a/src/pcf/nsmf-build.c b/src/pcf/nsmf-build.c new file mode 100644 index 000000000..ac105a43b --- /dev/null +++ b/src/pcf/nsmf-build.c @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "nsmf-build.h" + +ogs_sbi_request_t *pcf_nsmf_callback_build_smpolicycontrol( + pcf_sess_t *sess, void *data) +{ + ogs_sbi_message_t message; + ogs_sbi_request_t *request = NULL; + + OpenAPI_sm_policy_notification_t SmPolicyNotification; + + ogs_assert(sess); + ogs_assert(sess->notification_uri); + + memset(&SmPolicyNotification, 0, sizeof(SmPolicyNotification)); + + memset(&message, 0, sizeof(message)); + message.h.method = (char *)OGS_SBI_HTTP_METHOD_POST; + message.h.uri = sess->notification_uri; + + message.SmPolicyNotification = &SmPolicyNotification; + + request = ogs_sbi_build_request(&message); + ogs_assert(request); + + return request; +} diff --git a/src/pcf/nsmf-build.h b/src/pcf/nsmf-build.h new file mode 100644 index 000000000..a40e96cbc --- /dev/null +++ b/src/pcf/nsmf-build.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef PCF_NSMF_BUILD_H +#define PCF_NSMF_BUILD_H + +#include "context.h" + +#ifdef __cplusplus +extern "C" { +#endif + +ogs_sbi_request_t *pcf_nsmf_callback_build_smpolicycontrol( + pcf_sess_t *sess, void *data); + +#ifdef __cplusplus +} +#endif + +#endif /* PCF_NSMF_BUILD_H */ diff --git a/src/pcf/nudr-handler.c b/src/pcf/nudr-handler.c index 014ed0f92..496cdaa3f 100644 --- a/src/pcf/nudr-handler.c +++ b/src/pcf/nudr-handler.c @@ -17,6 +17,8 @@ * along with this program. If not, see . */ +#include "sbi-path.h" + #include "nudr-handler.h" bool pcf_nudr_dr_handle_query_am_data( @@ -167,17 +169,11 @@ cleanup: bool pcf_nudr_dr_handle_query_sm_data( pcf_sess_t *sess, ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) { - int i, j, rv, status = 0; + int status = 0; char *strerror = NULL; pcf_ue_t *pcf_ue = NULL; ogs_sbi_server_t *server = NULL; - ogs_sbi_message_t sendmsg; - ogs_sbi_header_t header; - ogs_sbi_response_t *response = NULL; - - ogs_session_data_t session_data; - ogs_assert(sess); pcf_ue = sess->pcf_ue; ogs_assert(pcf_ue); @@ -187,34 +183,8 @@ bool pcf_nudr_dr_handle_query_sm_data( ogs_assert(recvmsg); - memset(&session_data, 0, sizeof(ogs_session_data_t)); - SWITCH(recvmsg->h.resource.component[3]) CASE(OGS_SBI_RESOURCE_NAME_SM_DATA) - ogs_session_t *session = NULL; - - OpenAPI_sm_policy_decision_t SmPolicyDecision; - - OpenAPI_lnode_t *node = NULL, *node2 = NULL; - - OpenAPI_list_t *SessRuleList = NULL; - OpenAPI_map_t *SessRuleMap = NULL; - OpenAPI_session_rule_t *SessionRule = NULL; - - OpenAPI_ambr_t AuthSessAmbr; - OpenAPI_authorized_default_qos_t AuthDefQos; - - OpenAPI_list_t *PccRuleList = NULL; - OpenAPI_map_t *PccRuleMap = NULL; - OpenAPI_pcc_rule_t *PccRule = NULL; - OpenAPI_flow_information_t *FlowInformation = NULL; - - OpenAPI_list_t *QosDecisionList = NULL; - OpenAPI_map_t *QosDecisionMap = NULL; - OpenAPI_qos_data_t *QosData = NULL; - - OpenAPI_list_t *PolicyCtrlReqTriggers = NULL; - if (!recvmsg->SmPolicyData) { strerror = ogs_msprintf("[%s:%d] No SmPolicyData", pcf_ue->supi, sess->psi); @@ -222,367 +192,8 @@ bool pcf_nudr_dr_handle_query_sm_data( goto cleanup; } - ogs_assert(pcf_ue->supi); - ogs_assert(sess->dnn); - - rv = ogs_dbi_session_data( - pcf_ue->supi, &sess->s_nssai, sess->dnn, &session_data); - if (rv != OGS_OK) { - strerror = ogs_msprintf("[%s:%d] Cannot find SUPI in DB", - pcf_ue->supi, sess->psi); - status = OGS_SBI_HTTP_STATUS_NOT_FOUND; - goto cleanup; - } - - session = &session_data.session; - - if (!session->qos.index) { - strerror = ogs_msprintf("[%s:%d] No 5QI", pcf_ue->supi, sess->psi); - status = OGS_SBI_HTTP_STATUS_BAD_REQUEST; - goto cleanup; - } - if (!session->qos.arp.priority_level) { - strerror = ogs_msprintf("[%s:%d] No Priority Level", - pcf_ue->supi, sess->psi); - status = OGS_SBI_HTTP_STATUS_BAD_REQUEST; - goto cleanup; - } - - if (!session->ambr.uplink && !session->ambr.downlink) { - strerror = ogs_msprintf("[%s:%d] No Session-AMBR", - pcf_ue->supi, sess->psi); - status = OGS_SBI_HTTP_STATUS_BAD_REQUEST; - goto cleanup; - } - - memset(&SmPolicyDecision, 0, sizeof(SmPolicyDecision)); - - PolicyCtrlReqTriggers = OpenAPI_list_create(); - ogs_assert(PolicyCtrlReqTriggers); - - /************************************************************** - * Session Rule - *************************************************************/ - SessRuleList = OpenAPI_list_create(); - ogs_assert(SessRuleList); - - SessionRule = ogs_calloc(1, sizeof(*SessionRule)); - ogs_assert(SessionRule); - - /* Only 1 SessionRule is used */ - SessionRule->sess_rule_id = (char *)"1"; - - if (OGS_SBI_FEATURES_IS_SET(sess->smpolicycontrol_features, - OGS_SBI_NPCF_SMPOLICYCONTROL_DN_AUTHORIZATION)) { - if (sess->subscribed_sess_ambr) { - ogs_bitrate_t subscribed_sess_ambr; - - subscribed_sess_ambr.uplink = ogs_sbi_bitrate_from_string( - sess->subscribed_sess_ambr->uplink); - subscribed_sess_ambr.downlink = ogs_sbi_bitrate_from_string( - sess->subscribed_sess_ambr->downlink); - if (((subscribed_sess_ambr.uplink / 1024) != - (session->ambr.uplink / 1024)) || - ((subscribed_sess_ambr.downlink / 1024) != - (session->ambr.downlink / 1024))) { - - OpenAPI_list_add(PolicyCtrlReqTriggers, - (void *)OpenAPI_policy_control_request_trigger_SE_AMBR_CH); - } - - memset(&AuthSessAmbr, 0, sizeof(AuthSessAmbr)); - AuthSessAmbr.uplink = ogs_sbi_bitrate_to_string( - session->ambr.uplink, OGS_SBI_BITRATE_KBPS); - AuthSessAmbr.downlink = ogs_sbi_bitrate_to_string( - session->ambr.downlink, OGS_SBI_BITRATE_KBPS); - SessionRule->auth_sess_ambr = &AuthSessAmbr; - } - } - - if (sess->subscribed_default_qos) { - bool triggered = false; - - memset(&AuthDefQos, 0, sizeof(AuthDefQos)); - AuthDefQos.arp = ogs_calloc(1, sizeof(OpenAPI_arp_t)); - ogs_assert(AuthDefQos.arp); - - AuthDefQos._5qi = session->qos.index; - AuthDefQos.priority_level = session->qos.arp.priority_level; - - if (session->qos.arp.pre_emption_capability == - OGS_5GC_PRE_EMPTION_ENABLED) - AuthDefQos.arp->preempt_cap = - OpenAPI_preemption_capability_MAY_PREEMPT; - else if (session->qos.arp.pre_emption_capability == - OGS_5GC_PRE_EMPTION_DISABLED) - AuthDefQos.arp->preempt_cap = - OpenAPI_preemption_capability_NOT_PREEMPT; - ogs_assert(AuthDefQos.arp->preempt_cap); - - if (session->qos.arp.pre_emption_vulnerability == - OGS_5GC_PRE_EMPTION_ENABLED) - AuthDefQos.arp->preempt_vuln = - OpenAPI_preemption_vulnerability_PREEMPTABLE; - else if (session->qos.arp.pre_emption_vulnerability == - OGS_5GC_PRE_EMPTION_DISABLED) - AuthDefQos.arp->preempt_vuln = - OpenAPI_preemption_vulnerability_NOT_PREEMPTABLE; - ogs_assert(AuthDefQos.arp->preempt_vuln); - AuthDefQos.arp->priority_level = session->qos.arp.priority_level; - - SessionRule->auth_def_qos = &AuthDefQos; - - if (sess->subscribed_default_qos->_5qi != AuthDefQos._5qi) - triggered = true; - if (sess->subscribed_default_qos->priority_level != - AuthDefQos.priority_level) - triggered = true; - if (sess->subscribed_default_qos->arp) { - if (sess->subscribed_default_qos->arp->priority_level != - AuthDefQos.arp->priority_level) - triggered = true; - if (sess->subscribed_default_qos->arp->preempt_cap != - AuthDefQos.arp->preempt_cap) - triggered = true; - if (sess->subscribed_default_qos->arp->preempt_vuln != - AuthDefQos.arp->preempt_vuln) - triggered = true; - - } - - if (triggered) - OpenAPI_list_add(PolicyCtrlReqTriggers, - (void *)OpenAPI_policy_control_request_trigger_DEF_QOS_CH); - - } - - SessRuleMap = OpenAPI_map_create( - SessionRule->sess_rule_id, SessionRule); - ogs_assert(SessRuleMap); - - OpenAPI_list_add(SessRuleList, SessRuleMap); - - if (SessRuleList->count) - SmPolicyDecision.sess_rules = SessRuleList; - - /************************************************************** - * PCC Rule & QoS Decision - *************************************************************/ - PccRuleList = OpenAPI_list_create(); - ogs_assert(PccRuleList); - - QosDecisionList = OpenAPI_list_create(); - ogs_assert(QosDecisionList); - - for (i = 0; i < session_data.num_of_pcc_rule; i++) { - OpenAPI_list_t *FlowInformationList = NULL; - ogs_pcc_rule_t *pcc_rule = &session_data.pcc_rule[i]; - - ogs_assert(pcc_rule); - - PccRule = ogs_calloc(1, sizeof(*PccRule)); - ogs_assert(PccRule); - QosData = ogs_calloc(1, sizeof(*QosData)); - ogs_assert(QosData); - - /* - * At this point, only 1 QosData is used for PccRule. - * Therefore, QoS ID uses the same value as PCC Rule ID. - */ - PccRule->pcc_rule_id = pcc_rule->id; - QosData->qos_id = pcc_rule->id; - - PccRule->ref_qos_data = OpenAPI_list_create(); - ogs_assert(PccRule->ref_qos_data); - - OpenAPI_list_add(PccRule->ref_qos_data, QosData->qos_id); - - PccRule->precedence = pcc_rule->precedence; - - FlowInformationList = OpenAPI_list_create(); - ogs_assert(FlowInformationList); - - for (j = 0; j < pcc_rule->num_of_flow; j++) { - ogs_flow_t *flow = &pcc_rule->flow[j]; - ogs_assert(flow); - - FlowInformation = ogs_calloc(1, sizeof(*FlowInformation)); - ogs_assert(FlowInformation); - - if (flow->direction == OGS_FLOW_UPLINK_ONLY) - FlowInformation->flow_direction = - OpenAPI_flow_direction_UPLINK; - else if (flow->direction == OGS_FLOW_DOWNLINK_ONLY) - FlowInformation->flow_direction = - OpenAPI_flow_direction_DOWNLINK; - else { - ogs_fatal("Unsupported direction [%d]", flow->direction); - ogs_assert_if_reached(); - } - - ogs_assert(flow->description); - FlowInformation->flow_description = flow->description; - - OpenAPI_list_add(FlowInformationList, FlowInformation); - } - - if (FlowInformationList->count) - PccRule->flow_infos = FlowInformationList; - else - OpenAPI_list_free(FlowInformationList); - - PccRuleMap = OpenAPI_map_create(PccRule->pcc_rule_id, PccRule); - ogs_assert(PccRuleMap); - - OpenAPI_list_add(PccRuleList, PccRuleMap); - - QosData->_5qi = pcc_rule->qos.index; - QosData->priority_level = pcc_rule->qos.arp.priority_level; - - QosData->arp = ogs_calloc(1, sizeof(OpenAPI_arp_t)); - ogs_assert(QosData->arp); - - if (pcc_rule->qos.arp.pre_emption_capability == - OGS_5GC_PRE_EMPTION_ENABLED) - QosData->arp->preempt_cap = - OpenAPI_preemption_capability_MAY_PREEMPT; - else if (pcc_rule->qos.arp.pre_emption_capability == - OGS_5GC_PRE_EMPTION_DISABLED) - QosData->arp->preempt_cap = - OpenAPI_preemption_capability_NOT_PREEMPT; - ogs_assert(pcc_rule->qos.arp.pre_emption_capability); - - if (pcc_rule->qos.arp.pre_emption_vulnerability == - OGS_5GC_PRE_EMPTION_ENABLED) - QosData->arp->preempt_vuln = - OpenAPI_preemption_vulnerability_PREEMPTABLE; - else if (pcc_rule->qos.arp.pre_emption_vulnerability == - OGS_5GC_PRE_EMPTION_DISABLED) - QosData->arp->preempt_vuln = - OpenAPI_preemption_vulnerability_NOT_PREEMPTABLE; - ogs_assert(pcc_rule->qos.arp.pre_emption_vulnerability); - QosData->arp->priority_level = pcc_rule->qos.arp.priority_level; - - if (pcc_rule->qos.mbr.uplink) - QosData->maxbr_ul = ogs_sbi_bitrate_to_string( - pcc_rule->qos.mbr.uplink, OGS_SBI_BITRATE_KBPS); - if (pcc_rule->qos.mbr.downlink) - QosData->maxbr_dl = ogs_sbi_bitrate_to_string( - pcc_rule->qos.mbr.downlink, OGS_SBI_BITRATE_KBPS); - - if (pcc_rule->qos.gbr.uplink) - QosData->gbr_ul = ogs_sbi_bitrate_to_string( - pcc_rule->qos.gbr.uplink, OGS_SBI_BITRATE_KBPS); - if (pcc_rule->qos.gbr.downlink) - QosData->gbr_dl = ogs_sbi_bitrate_to_string( - pcc_rule->qos.gbr.downlink, OGS_SBI_BITRATE_KBPS); - - QosDecisionMap = OpenAPI_map_create(QosData->qos_id, QosData); - ogs_assert(QosDecisionMap); - - OpenAPI_list_add(QosDecisionList, QosDecisionMap); - } - - if (PccRuleList->count) - SmPolicyDecision.pcc_rules = PccRuleList; - - if (QosDecisionList->count) - SmPolicyDecision.qos_decs = QosDecisionList; - - /* Policy Control Request Triggers */ - if (PolicyCtrlReqTriggers->count) - SmPolicyDecision.policy_ctrl_req_triggers = PolicyCtrlReqTriggers; - - /* Supported Features */ - if (sess->smpolicycontrol_features) { - SmPolicyDecision.supp_feat = - ogs_uint64_to_string(sess->smpolicycontrol_features); - } - - memset(&header, 0, sizeof(header)); - header.service.name = (char *)OGS_SBI_SERVICE_NAME_NPCF_SMPOLICYCONTROL; - header.api.version = (char *)OGS_SBI_API_V1; - header.resource.component[0] = (char *)OGS_SBI_RESOURCE_NAME_POLICIES; - header.resource.component[1] = sess->sm_policy_id; - - memset(&sendmsg, 0, sizeof(sendmsg)); - sendmsg.SmPolicyDecision = &SmPolicyDecision; - sendmsg.http.location = ogs_sbi_server_uri(server, &header); - - response = ogs_sbi_build_response( - &sendmsg, OGS_SBI_HTTP_STATUS_CREATED); - ogs_assert(response); - ogs_sbi_server_send_response(stream, response); - - ogs_free(sendmsg.http.location); - - OpenAPI_list_for_each(SessRuleList, node) { - SessRuleMap = node->data; - if (SessRuleMap) { - SessionRule = SessRuleMap->value; - if (SessionRule) { - if (SessionRule->auth_sess_ambr) { - if (SessionRule->auth_sess_ambr->uplink) - ogs_free(SessionRule->auth_sess_ambr->uplink); - if (SessionRule->auth_sess_ambr->downlink) - ogs_free(SessionRule->auth_sess_ambr->downlink); - } - if (SessionRule->auth_def_qos) { - ogs_free(SessionRule->auth_def_qos->arp); - - } - ogs_free(SessionRule); - } - ogs_free(SessRuleMap); - } - } - OpenAPI_list_free(SessRuleList); - - OpenAPI_list_for_each(PccRuleList, node) { - PccRuleMap = node->data; - if (PccRuleMap) { - PccRule = PccRuleMap->value; - if (PccRule) { - if (PccRule->ref_qos_data) - OpenAPI_list_free(PccRule->ref_qos_data); - if (PccRule->flow_infos) { - OpenAPI_list_for_each(PccRule->flow_infos, node2) { - FlowInformation = node2->data; - if (FlowInformation) ogs_free(FlowInformation); - } - OpenAPI_list_free(PccRule->flow_infos); - } - ogs_free(PccRule); - } - ogs_free(PccRuleMap); - } - } - OpenAPI_list_free(PccRuleList); - - OpenAPI_list_for_each(QosDecisionList, node) { - QosDecisionMap = node->data; - if (QosDecisionMap) { - QosData = QosDecisionMap->value; - if (QosData) { - if (QosData->arp) ogs_free(QosData->arp); - if (QosData->maxbr_ul) ogs_free(QosData->maxbr_ul); - if (QosData->maxbr_dl) ogs_free(QosData->maxbr_dl); - if (QosData->gbr_ul) ogs_free(QosData->gbr_ul); - if (QosData->gbr_dl) ogs_free(QosData->gbr_dl); - - ogs_free(QosData); - } - ogs_free(QosDecisionMap); - } - } - OpenAPI_list_free(QosDecisionList); - - OpenAPI_list_free(PolicyCtrlReqTriggers); - - if (SmPolicyDecision.supp_feat) - ogs_free(SmPolicyDecision.supp_feat); - - ogs_session_data_free(&session_data); + pcf_sess_sbi_discover_and_send(OpenAPI_nf_type_BSF, sess, stream, NULL, + pcf_nbsf_management_build_register); return true; @@ -598,7 +209,5 @@ cleanup: ogs_sbi_server_send_error(stream, status, recvmsg, strerror, NULL); ogs_free(strerror); - ogs_session_data_free(&session_data); - return false; } diff --git a/src/pcf/pcf-sm.c b/src/pcf/pcf-sm.c index 4ca177e8e..6fdd656b8 100644 --- a/src/pcf/pcf-sm.c +++ b/src/pcf/pcf-sm.c @@ -99,8 +99,7 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e) break; DEFAULT - ogs_error("Invalid HTTP method [%s]", - message.h.method); + ogs_error("Invalid HTTP method [%s]", message.h.method); ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, &message, "Invalid HTTP method", message.h.method); @@ -155,23 +154,30 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e) break; CASE(OGS_SBI_SERVICE_NAME_NPCF_SMPOLICYCONTROL) - SWITCH(message.h.method) - CASE(OGS_SBI_HTTP_METHOD_POST) - if (message.SmPolicyContextData && - message.SmPolicyContextData->supi) { - pcf_ue = pcf_ue_find_by_supi( - message.SmPolicyContextData->supi); - if (pcf_ue) { - if (message.SmPolicyContextData->pdu_session_id) { - sess = pcf_sess_find_by_psi(pcf_ue, - message.SmPolicyContextData->pdu_session_id); - if (!sess) { - sess = pcf_sess_add(pcf_ue, - message.SmPolicyContextData->pdu_session_id); - ogs_assert(sess); + SWITCH(message.h.resource.component[0]) + CASE(OGS_SBI_RESOURCE_NAME_SM_POLICIES) + if (!message.h.resource.component[1]) { + if (message.SmPolicyContextData && + message.SmPolicyContextData->supi) { + pcf_ue = pcf_ue_find_by_supi( + message.SmPolicyContextData->supi); + if (pcf_ue) { + if (message.SmPolicyContextData->pdu_session_id) { + sess = pcf_sess_find_by_psi(pcf_ue, message. + SmPolicyContextData->pdu_session_id); + if (!sess) { + sess = pcf_sess_add(pcf_ue, message. + SmPolicyContextData->pdu_session_id); + ogs_assert(sess); + ogs_debug("[%s:%d] PCF session added", + pcf_ue->supi, sess->psi); + } } } } + } else { + sess = pcf_sess_find_by_sm_policy_id( + message.h.resource.component[1]); } break; @@ -179,10 +185,57 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e) END if (!sess) { - ogs_error("Not found [%s]", message.h.method); + ogs_error("Not found [%s]", message.h.uri); ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_NOT_FOUND, - &message, "Not found", message.h.method); + &message, "Not found", message.h.uri); + break; + } + + ogs_assert(OGS_FSM_STATE(&sess->sm)); + + e->sess = sess; + e->sbi.message = &message; + ogs_fsm_dispatch(&sess->sm, e); + if (OGS_FSM_CHECK(&sess->sm, pcf_sm_state_exception)) { + ogs_error("[%s:%d] State machine exception", + pcf_ue->supi, sess->psi); + pcf_sess_remove(sess); + } + break; + + CASE(OGS_SBI_SERVICE_NAME_NPCF_POLICYAUTHORIZATION) + SWITCH(message.h.resource.component[0]) + CASE(OGS_SBI_RESOURCE_NAME_APP_SESSIONS) + if (!message.h.resource.component[1]) { + if (message.AppSessionContext && + message.AppSessionContext->asc_req_data && + (message.AppSessionContext->asc_req_data->ue_ipv4 || + message.AppSessionContext->asc_req_data->ue_ipv6)) { + + if (!sess && + message.AppSessionContext->asc_req_data->ue_ipv4) + sess = pcf_sess_find_by_ipv4addr(message. + AppSessionContext->asc_req_data->ue_ipv4); + if (!sess && + message.AppSessionContext->asc_req_data->ue_ipv6) + sess = pcf_sess_find_by_ipv6addr(message. + AppSessionContext->asc_req_data->ue_ipv6); + } + } else { + sess = pcf_sess_find_by_app_session_id( + message.h.resource.component[1]); + } + break; + + DEFAULT + END + + if (!sess) { + ogs_error("Not found [%s]", message.h.uri); + ogs_sbi_server_send_error(stream, + OGS_SBI_HTTP_STATUS_NOT_FOUND, + &message, "Not found", message.h.uri); break; } @@ -361,7 +414,7 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e) e->sbi.message = &message; ogs_fsm_dispatch(&sess->sm, e); - if (OGS_FSM_CHECK(&sess->sm, pcf_am_state_exception)) { + if (OGS_FSM_CHECK(&sess->sm, pcf_sm_state_exception)) { ogs_error("[%s:%d] State machine exception", pcf_ue->supi, sess->psi); pcf_sess_remove(sess); @@ -382,6 +435,51 @@ void pcf_state_operational(ogs_fsm_t *s, pcf_event_t *e) END break; + CASE(OGS_SBI_SERVICE_NAME_NBSF_MANAGEMENT) + + SWITCH(message.h.resource.component[0]) + CASE(OGS_SBI_RESOURCE_NAME_PCF_BINDINGS) + + sbi_xact = e->sbi.data; + ogs_assert(sbi_xact); + + sess = (pcf_sess_t *)sbi_xact->sbi_object; + ogs_assert(sess); + + e->sbi.data = sbi_xact->assoc_stream; + + ogs_sbi_xact_remove(sbi_xact); + + sess = pcf_sess_cycle(sess); + ogs_assert(sess); + + pcf_ue = sess->pcf_ue; + ogs_assert(pcf_ue); + pcf_ue = pcf_ue_cycle(pcf_ue); + ogs_assert(pcf_ue); + + e->sess = sess; + e->sbi.message = &message; + + ogs_fsm_dispatch(&sess->sm, e); + if (OGS_FSM_CHECK(&sess->sm, pcf_sm_state_exception)) { + ogs_error("[%s:%d] State machine exception", + pcf_ue->supi, sess->psi); + pcf_sess_remove(sess); + } else if (OGS_FSM_CHECK(&sess->sm, pcf_sm_state_deleted)) { + ogs_debug("[%s:%d] PCF session removed", + pcf_ue->supi, sess->psi); + pcf_sess_remove(sess); + } + break; + + DEFAULT + ogs_error("Invalid resource name [%s]", + message.h.resource.component[0]); + ogs_assert_if_reached(); + END + break; + DEFAULT ogs_error("Invalid API name [%s]", message.h.service.name); ogs_assert_if_reached(); diff --git a/src/pcf/pcf-sm.h b/src/pcf/pcf-sm.h index a2929bb39..9de1431b5 100644 --- a/src/pcf/pcf-sm.h +++ b/src/pcf/pcf-sm.h @@ -48,6 +48,7 @@ void pcf_am_state_exception(ogs_fsm_t *s, pcf_event_t *e); void pcf_sm_state_initial(ogs_fsm_t *s, pcf_event_t *e); void pcf_sm_state_final(ogs_fsm_t *s, pcf_event_t *e); void pcf_sm_state_operational(ogs_fsm_t *s, pcf_event_t *e); +void pcf_sm_state_deleted(ogs_fsm_t *s, pcf_event_t *e); void pcf_sm_state_exception(ogs_fsm_t *s, pcf_event_t *e); #define pcf_sm_debug(__pe) \ diff --git a/src/pcf/sbi-path.c b/src/pcf/sbi-path.c index d58ca1824..ac4478127 100644 --- a/src/pcf/sbi-path.c +++ b/src/pcf/sbi-path.c @@ -190,3 +190,56 @@ void pcf_sess_sbi_discover_and_send(OpenAPI_nf_type_e target_nf_type, return; } } + +static int client_notify_cb(ogs_sbi_response_t *response, void *data) +{ + int rv; + + ogs_sbi_message_t message; + + ogs_assert(response); + + rv = ogs_sbi_parse_response(&message, response); + if (rv != OGS_OK) { + ogs_error("cannot parse HTTP response"); + ogs_sbi_message_free(&message); + ogs_sbi_response_free(response); + return OGS_ERROR; + } + + if (message.res_status != OGS_SBI_HTTP_STATUS_NO_CONTENT) + ogs_error("SmContextStatusNotification failed [%d]", + message.res_status); + + ogs_sbi_message_free(&message); + ogs_sbi_response_free(response); + return OGS_OK; +} + +void pcf_sbi_send_am_policy_control_notify(pcf_ue_t *pcf_ue) +{ + ogs_sbi_request_t *request = NULL; + ogs_sbi_client_t *client = NULL; + + ogs_assert(pcf_ue); + client = pcf_ue->namf.client; + ogs_assert(client); + + request = pcf_namf_callback_build_am_policy_control(pcf_ue, NULL); + ogs_assert(request); + ogs_sbi_client_send_request(client, client_notify_cb, request, NULL); +} + +void pcf_sbi_send_smpolicycontrol_notify(pcf_sess_t *sess) +{ + ogs_sbi_request_t *request = NULL; + ogs_sbi_client_t *client = NULL; + + ogs_assert(sess); + client = sess->nsmf.client; + ogs_assert(client); + + request = pcf_nsmf_callback_build_smpolicycontrol(sess, NULL); + ogs_assert(request); + ogs_sbi_client_send_request(client, client_notify_cb, request, NULL); +} diff --git a/src/pcf/sbi-path.h b/src/pcf/sbi-path.h index ab5931b75..d455adb6d 100644 --- a/src/pcf/sbi-path.h +++ b/src/pcf/sbi-path.h @@ -22,15 +22,14 @@ #include "nnrf-build.h" #include "nudr-build.h" +#include "nbsf-build.h" +#include "namf-build.h" +#include "nsmf-build.h" #ifdef __cplusplus extern "C" { #endif -#if 0 -#include "nudr-build.h" -#endif - int pcf_sbi_open(void); void pcf_sbi_close(void); @@ -44,6 +43,9 @@ void pcf_sess_sbi_discover_and_send(OpenAPI_nf_type_e target_nf_type, pcf_sess_t *sess, ogs_sbi_stream_t *stream, void *data, ogs_sbi_request_t *(*build)(pcf_sess_t *sess, void *data)); +void pcf_sbi_send_am_policy_control_notify(pcf_ue_t *pcf_ue); +void pcf_sbi_send_smpolicycontrol_notify(pcf_sess_t *sess); + #ifdef __cplusplus } #endif diff --git a/src/pcf/sm-sm.c b/src/pcf/sm-sm.c index 05720d6a1..296c64af7 100644 --- a/src/pcf/sm-sm.c +++ b/src/pcf/sm-sm.c @@ -22,6 +22,7 @@ #include "npcf-handler.h" #include "nudr-handler.h" +#include "nbsf-handler.h" void pcf_sm_state_initial(ogs_fsm_t *s, pcf_event_t *e) { @@ -66,23 +67,63 @@ void pcf_sm_state_operational(ogs_fsm_t *s, pcf_event_t *e) stream = e->sbi.data; ogs_assert(stream); - SWITCH(message->h.method) - CASE(OGS_SBI_HTTP_METHOD_POST) - handled = pcf_npcf_smpolicycontrtol_handle_create( - sess, stream, message); - if (!handled) { - ogs_error("[%s:%d] Cannot handle SBI message", - pcf_ue->supi, sess->psi); - OGS_FSM_TRAN(s, pcf_sm_state_exception); + SWITCH(message->h.service.name) + CASE(OGS_SBI_SERVICE_NAME_NPCF_SMPOLICYCONTROL) + if (!message->h.resource.component[1]) { + handled = pcf_npcf_smpolicycontrtol_handle_create( + sess, stream, message); + if (!handled) { + ogs_error("[%s:%d] " + "pcf_npcf_smpolicycontrtol_handle_create() failed", + pcf_ue->supi, sess->psi); + OGS_FSM_TRAN(s, pcf_sm_state_exception); + } + } else { + SWITCH(message->h.resource.component[2]) + CASE(OGS_SBI_RESOURCE_NAME_DELETE) + handled = pcf_npcf_smpolicycontrtol_handle_delete( + sess, stream, message); + if (!handled) { + ogs_error("[%s:%d] " + "pcf_npcf_smpolicycontrtol_handle_delete() failed", + pcf_ue->supi, sess->psi); + OGS_FSM_TRAN(s, pcf_sm_state_exception); + } + break; + + DEFAULT + ogs_error("[%s:%d] Invalid HTTP URI [%s]", + pcf_ue->supi, sess->psi, message->h.uri); + ogs_sbi_server_send_error(stream, + OGS_SBI_HTTP_STATUS_FORBIDDEN, message, + "Invalid HTTP method", message->h.uri); + END + } + break; + + CASE(OGS_SBI_SERVICE_NAME_NPCF_POLICYAUTHORIZATION) + if (!message->h.resource.component[1]) { + handled = pcf_npcf_policyauthorization_handle_create( + sess, stream, message); + } else { + SWITCH(message->h.resource.component[2]) + CASE(OGS_SBI_RESOURCE_NAME_DELETE) + ogs_fatal("TODO"); + break; + DEFAULT + ogs_error("[%s:%d] Invalid HTTP URI [%s]", + pcf_ue->supi, sess->psi, message->h.uri); + ogs_sbi_server_send_error(stream, + OGS_SBI_HTTP_STATUS_FORBIDDEN, message, + "Invalid HTTP method", message->h.uri); + END } break; DEFAULT - ogs_error("[%s:%d] Invalid HTTP method [%s]", - pcf_ue->supi, sess->psi, message->h.method); - ogs_sbi_server_send_error(stream, - OGS_SBI_HTTP_STATUS_FORBIDDEN, message, - "Invalid HTTP method", message->h.method); + ogs_error("[%s:%d] Invalid API name [%s]", + pcf_ue->supi, sess->psi, message->h.service.name); + ogs_assert_if_reached(); END break; @@ -132,12 +173,59 @@ void pcf_sm_state_operational(ogs_fsm_t *s, pcf_event_t *e) END break; + 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]) { + SWITCH(message->h.method) + CASE(OGS_SBI_HTTP_METHOD_DELETE) + if (message->res_status != + OGS_SBI_HTTP_STATUS_NO_CONTENT) { + ogs_error("[%s:%d] HTTP response error [%d]", + pcf_ue->supi, sess->psi, message->res_status); + ogs_sbi_server_send_error(stream, + message->res_status, + NULL, "HTTP response error", pcf_ue->supi); + OGS_FSM_TRAN(s, pcf_sm_state_exception); + break; + } + + pcf_nbsf_management_handle_de_register( + sess, stream, message); + OGS_FSM_TRAN(s, pcf_sm_state_deleted); + break; + DEFAULT + ogs_error("[%s:%d] Unknown method [%s]", + pcf_ue->supi, sess->psi, message->h.method); + ogs_assert_if_reached(); + END + break; + } else { + SWITCH(message->h.method) + CASE(OGS_SBI_HTTP_METHOD_POST) + pcf_nbsf_management_handle_register( + sess, stream, message); + break; + DEFAULT + ogs_error("[%s:%d] Unknown method [%s]", + pcf_ue->supi, sess->psi, message->h.method); + ogs_assert_if_reached(); + END + } + break; + + DEFAULT + ogs_error("[%s:%d] Invalid resource name [%s]", + pcf_ue->supi, sess->psi, + message->h.resource.component[0]); + ogs_assert_if_reached(); + END + break; + DEFAULT ogs_error("[%s:%d] Invalid API name [%s]", pcf_ue->supi, sess->psi, message->h.service.name); - ogs_sbi_server_send_error(stream, - OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, - "Invalid API name", message->h.resource.component[0]); + ogs_assert_if_reached(); END break; @@ -148,6 +236,35 @@ void pcf_sm_state_operational(ogs_fsm_t *s, pcf_event_t *e) } } +void pcf_sm_state_deleted(ogs_fsm_t *s, pcf_event_t *e) +{ + pcf_ue_t *pcf_ue = NULL; + pcf_sess_t *sess = NULL; + + ogs_assert(s); + ogs_assert(e); + + pcf_sm_debug(e); + + sess = e->sess; + ogs_assert(sess); + pcf_ue = sess->pcf_ue; + ogs_assert(pcf_ue); + + switch (e->id) { + case OGS_FSM_ENTRY_SIG: + break; + + case OGS_FSM_EXIT_SIG: + break; + + default: + ogs_error("[%s:%d] Unknown event %s", + pcf_ue->supi, sess->psi, pcf_event_get_name(e)); + break; + } +} + void pcf_sm_state_exception(ogs_fsm_t *s, pcf_event_t *e) { pcf_ue_t *pcf_ue = NULL; diff --git a/src/pcrf/pcrf-context.c b/src/pcrf/pcrf-context.c index 92f5ef430..d4e064358 100644 --- a/src/pcrf/pcrf-context.c +++ b/src/pcrf/pcrf-context.c @@ -265,7 +265,7 @@ int pcrf_context_parse_config(void) int pcrf_db_qos_data( char *imsi_bcd, char *apn, ogs_session_data_t *session_data) { - int rv; + int rv, i; char *supi = NULL; ogs_s_nssai_t s_nssai; @@ -283,6 +283,12 @@ int pcrf_db_qos_data( rv = ogs_dbi_session_data(supi, &s_nssai, apn, session_data); + /* For EPC, we need to inialize Flow-Status in Pcc-Rule */ + for (i = 0; i < session_data->num_of_pcc_rule; i++) { + ogs_pcc_rule_t *pcc_rule = &session_data->pcc_rule[i]; + pcc_rule->flow_status = OGS_DIAM_RX_FLOW_STATUS_ENABLED; + } + ogs_free(supi); ogs_thread_mutex_unlock(&self.db_lock); diff --git a/src/pcrf/pcrf-gx-path.c b/src/pcrf/pcrf-gx-path.c index 08169a440..eee46b05b 100644 --- a/src/pcrf/pcrf-gx-path.c +++ b/src/pcrf/pcrf-gx-path.c @@ -63,11 +63,11 @@ static void pcrf_gx_raa_cb(void *data, struct msg **msg); static int encode_pcc_rule_definition( struct avp *avp, ogs_pcc_rule_t *pcc_rule, int flow_presence); static int matched_flow(ogs_pcc_rule_t *pcc_rule, - ogs_diam_rx_media_component_t *media_component); + ogs_media_component_t *media_component); static int install_flow(ogs_pcc_rule_t *pcc_rule, - ogs_diam_rx_media_component_t *media_component); + ogs_media_component_t *media_component); static int update_qos(ogs_pcc_rule_t *pcc_rule, - ogs_diam_rx_media_component_t *media_component); + ogs_media_component_t *media_component); static __inline__ struct sess_state *new_state(os0_t sid) { @@ -733,13 +733,13 @@ int pcrf_gx_send_rar( } /* Match Media-Component with PCC Rule */ - for (i = 0; i < rx_message->num_of_media_component; i++) { + for (i = 0; i < rx_message->ims_data.num_of_media_component; i++) { int flow_presence = 0; ogs_pcc_rule_t *pcc_rule = NULL; ogs_pcc_rule_t *db_pcc_rule = NULL; uint8_t qos_index = 0; - ogs_diam_rx_media_component_t *media_component = - &rx_message->media_component[i]; + ogs_media_component_t *media_component = + &rx_message->ims_data.media_component[i]; if (media_component->media_component_number == 0) { continue; @@ -853,9 +853,7 @@ int pcrf_gx_send_rar( ogs_error("install_flow() failed"); goto out; } - } - } /* Update QoS */ @@ -1401,7 +1399,7 @@ static int flow_rx_to_gx(ogs_flow_t *rx_flow, ogs_flow_t *gx_flow) } static int matched_flow(ogs_pcc_rule_t *pcc_rule, - ogs_diam_rx_media_component_t *media_component) + ogs_media_component_t *media_component) { int rv; int i, j, k; @@ -1412,7 +1410,7 @@ static int matched_flow(ogs_pcc_rule_t *pcc_rule, ogs_assert(media_component); for (i = 0; i < media_component->num_of_sub; i++) { - ogs_diam_rx_media_sub_component_t *sub = &media_component->sub[i]; + ogs_media_sub_component_t *sub = &media_component->sub[i]; if (sub->flow_number == 0) { continue; @@ -1429,7 +1427,7 @@ static int matched_flow(ogs_pcc_rule_t *pcc_rule, } for (i = 0; i < media_component->num_of_sub; i++) { - ogs_diam_rx_media_sub_component_t *sub = &media_component->sub[i]; + ogs_media_sub_component_t *sub = &media_component->sub[i]; if (sub->flow_number == 0) { continue; @@ -1462,7 +1460,7 @@ static int matched_flow(ogs_pcc_rule_t *pcc_rule, } static int install_flow(ogs_pcc_rule_t *pcc_rule, - ogs_diam_rx_media_component_t *media_component) + ogs_media_component_t *media_component) { int rv; int i, j; @@ -1477,7 +1475,7 @@ static int install_flow(ogs_pcc_rule_t *pcc_rule, pcc_rule->num_of_flow = 0; for (i = 0; i < media_component->num_of_sub; i++) { - ogs_diam_rx_media_sub_component_t *sub = &media_component->sub[i]; + ogs_media_sub_component_t *sub = &media_component->sub[i]; if (sub->flow_number == 0) { continue; @@ -1502,7 +1500,7 @@ static int install_flow(ogs_pcc_rule_t *pcc_rule, } static int update_qos(ogs_pcc_rule_t *pcc_rule, - ogs_diam_rx_media_component_t *media_component) + ogs_media_component_t *media_component) { int rv; int i, j; @@ -1516,7 +1514,7 @@ static int update_qos(ogs_pcc_rule_t *pcc_rule, pcc_rule->qos.gbr.uplink = 0; for (i = 0; i < media_component->num_of_sub; i++) { - ogs_diam_rx_media_sub_component_t *sub = &media_component->sub[i]; + ogs_media_sub_component_t *sub = &media_component->sub[i]; if (sub->flow_number == 0) { continue; diff --git a/src/pcrf/pcrf-rx-path.c b/src/pcrf/pcrf-rx-path.c index b14cb5998..73c4022d2 100644 --- a/src/pcrf/pcrf-rx-path.c +++ b/src/pcrf/pcrf-rx-path.c @@ -103,6 +103,9 @@ static int pcrf_rx_aar_cb( struct msg **msg, struct avp *avp, size_t sidlen; ogs_diam_rx_message_t rx_message; + ogs_media_component_t *media_component = NULL; + ogs_media_sub_component_t *sub = NULL; + ogs_flow_t *flow = NULL; char buf[OGS_ADDRSTRLEN]; os0_t gx_sid = NULL; @@ -218,9 +221,8 @@ static int pcrf_rx_aar_cb( struct msg **msg, struct avp *avp, break; /* Gwt Media-Component-Description */ case OGS_DIAM_RX_AVP_CODE_MEDIA_COMPONENT_DESCRIPTION: - { - ogs_diam_rx_media_component_t *media_component = &rx_message. - media_component[rx_message.num_of_media_component]; + media_component = &rx_message.ims_data. + media_component[rx_message.ims_data.num_of_media_component]; ret = fd_msg_browse(avpch1, MSG_BRW_FIRST_CHILD, &avpch2, NULL); ogs_assert(ret == 0); @@ -257,10 +259,11 @@ static int pcrf_rx_aar_cb( struct msg **msg, struct avp *avp, media_component->min_requested_bandwidth_ul = hdr->avp_value->i32; break; + case OGS_DIAM_RX_AVP_CODE_FLOW_STATUS: + media_component->flow_status = hdr->avp_value->i32; + break; case OGS_DIAM_RX_AVP_CODE_MEDIA_SUB_COMPONENT: - { - ogs_diam_rx_media_sub_component_t *sub = &media_component-> - sub[media_component->num_of_sub]; + sub = &media_component->sub[media_component->num_of_sub]; ret = fd_msg_browse(avpch2, MSG_BRW_FIRST_CHILD, &avpch3, NULL); @@ -278,9 +281,7 @@ static int pcrf_rx_aar_cb( struct msg **msg, struct avp *avp, hdr->avp_value->i32; break; case OGS_DIAM_RX_AVP_CODE_FLOW_DESCRIPTION: - { - ogs_flow_t *flow = &sub->flow - [sub->num_of_flow]; + flow = &sub->flow[sub->num_of_flow]; /* IE (IPV4-local-addr field ) is not supported on * the LTE pre release-11 UEs. In order for the call @@ -384,7 +385,6 @@ static int pcrf_rx_aar_cb( struct msg **msg, struct avp *avp, sub->num_of_flow++; break; - } default: ogs_error("Not supported(%d)", hdr->avp_code); @@ -395,7 +395,6 @@ static int pcrf_rx_aar_cb( struct msg **msg, struct avp *avp, media_component->num_of_sub++; break; - } default: ogs_warn("Not supported(%d)", hdr->avp_code); break; @@ -404,9 +403,8 @@ static int pcrf_rx_aar_cb( struct msg **msg, struct avp *avp, fd_msg_browse(avpch2, MSG_BRW_NEXT, &avpch2, NULL); } - rx_message.num_of_media_component++; + rx_message.ims_data.num_of_media_component++; break; - } default: ogs_warn("Not supported(%d)", hdr->avp_code); break; @@ -467,7 +465,7 @@ static int pcrf_rx_aar_cb( struct msg **msg, struct avp *avp, ogs_diam_logger_self()->stats.nb_echoed++; ogs_assert(pthread_mutex_unlock(&ogs_diam_logger_self()->stats_lock) == 0); - ogs_diam_rx_message_free(&rx_message); + ogs_ims_data_free(&rx_message.ims_data); return 0; @@ -493,7 +491,7 @@ out: ogs_assert(ret == 0); state_cleanup(sess_data, NULL, NULL); - ogs_diam_rx_message_free(&rx_message); + ogs_ims_data_free(&rx_message.ims_data); return 0; } @@ -788,7 +786,7 @@ static int pcrf_rx_str_cb( struct msg **msg, struct avp *avp, ogs_assert(pthread_mutex_unlock(&ogs_diam_logger_self()->stats_lock) == 0); state_cleanup(sess_data, NULL, NULL); - ogs_diam_rx_message_free(&rx_message); + ogs_ims_data_free(&rx_message.ims_data); return 0; @@ -816,7 +814,7 @@ out: ogs_debug("[PCRF] Session-Termination-Answer"); state_cleanup(sess_data, NULL, NULL); - ogs_diam_rx_message_free(&rx_message); + ogs_ims_data_free(&rx_message.ims_data); return 0; } diff --git a/src/smf/gsm-handler.c b/src/smf/gsm-handler.c index d354e7bca..b71de8277 100644 --- a/src/smf/gsm-handler.c +++ b/src/smf/gsm-handler.c @@ -65,7 +65,8 @@ int gsm_handle_pdu_session_establishment_request( } smf_sbi_discover_and_send(OpenAPI_nf_type_UDM, sess, stream, - (char *)OGS_SBI_RESOURCE_NAME_SM_DATA, smf_nudm_sdm_build_get); + 0, (char *)OGS_SBI_RESOURCE_NAME_SM_DATA, + smf_nudm_sdm_build_get); return OGS_OK; } diff --git a/src/smf/gsm-sm.c b/src/smf/gsm-sm.c index abb78fb2c..00ed74832 100644 --- a/src/smf/gsm-sm.c +++ b/src/smf/gsm-sm.c @@ -52,6 +52,8 @@ void smf_gsm_state_operational(ogs_fsm_t *s, smf_event_t *e) ogs_sbi_stream_t *stream = NULL; ogs_sbi_message_t *sbi_message = NULL; + int state = 0; + ogs_assert(s); ogs_assert(e); @@ -151,22 +153,66 @@ void smf_gsm_state_operational(ogs_fsm_t *s, smf_event_t *e) stream = e->sbi.data; ogs_assert(stream); + state = e->sbi.state; + SWITCH(sbi_message->h.resource.component[0]) CASE(OGS_SBI_RESOURCE_NAME_SM_POLICIES) - if (sbi_message->res_status != OGS_SBI_HTTP_STATUS_CREATED) { - strerror = ogs_msprintf("[%s:%d] HTTP response error [%d]", - smf_ue->supi, sess->psi, sbi_message->res_status); - ogs_assert(strerror); + if (!sbi_message->h.resource.component[1]) { + if (sbi_message->res_status != + OGS_SBI_HTTP_STATUS_CREATED) { + strerror = ogs_msprintf( + "[%s:%d] HTTP response error [%d]", + smf_ue->supi, sess->psi, + sbi_message->res_status); + ogs_assert(strerror); - ogs_error("%s", strerror); - ogs_sbi_server_send_error(stream, sbi_message->res_status, - sbi_message, strerror, NULL); - ogs_free(strerror); - break; + ogs_error("%s", strerror); + ogs_sbi_server_send_error(stream, + sbi_message->res_status, + sbi_message, strerror, NULL); + ogs_free(strerror); + break; + } + + smf_npcf_smpolicycontrol_handle_create( + sess, stream, state, sbi_message); + } else { + SWITCH(sbi_message->h.resource.component[2]) + CASE(OGS_SBI_RESOURCE_NAME_DELETE) + if (sbi_message->res_status != + OGS_SBI_HTTP_STATUS_NO_CONTENT) { + strerror = ogs_msprintf( + "[%s:%d] HTTP response error [%d]", + smf_ue->supi, sess->psi, + sbi_message->res_status); + ogs_assert(strerror); + + ogs_error("%s", strerror); + ogs_sbi_server_send_error(stream, + sbi_message->res_status, + sbi_message, strerror, NULL); + ogs_free(strerror); + break; + } + + smf_npcf_smpolicycontrol_handle_delete( + sess, stream, state, sbi_message); + break; + + DEFAULT + strerror = ogs_msprintf("[%s:%d] " + "Unknown resource name [%s]", + smf_ue->supi, sess->psi, + sbi_message->h.resource.component[2]); + ogs_assert(strerror); + + ogs_error("%s", strerror); + ogs_sbi_server_send_error(stream, + OGS_SBI_HTTP_STATUS_BAD_REQUEST, + sbi_message, strerror, NULL); + ogs_free(strerror); + END } - - smf_npcf_smpolicycontrol_handle_create( - sess, stream, sbi_message); break; DEFAULT @@ -227,24 +273,36 @@ void smf_gsm_state_operational(ogs_fsm_t *s, smf_event_t *e) break; case OGS_NAS_5GS_PDU_SESSION_MODIFICATION_COMPLETE: - smf_sbi_send_response(stream, OGS_SBI_HTTP_STATUS_NO_CONTENT); + ogs_sbi_send_http_status_no_content(stream); break; case OGS_NAS_5GS_PDU_SESSION_RELEASE_REQUEST: - ogs_assert(OGS_OK == - smf_5gc_pfcp_send_session_deletion_request( - sess, stream, OGS_PFCP_DELETE_TRIGGER_UE_REQUESTED)); + { + smf_npcf_smpolicycontrol_param_t param; + + memset(¶m, 0, sizeof(param)); + + param.ran_nas_release.gsm_cause = + OGS_5GSM_CAUSE_REGULAR_DEACTIVATION; + param.ran_nas_release.ngap_cause.group = NGAP_Cause_PR_nas; + param.ran_nas_release.ngap_cause.value = + NGAP_CauseNas_normal_release; + + smf_sbi_discover_and_send(OpenAPI_nf_type_PCF, sess, stream, + OGS_PFCP_DELETE_TRIGGER_UE_REQUESTED, ¶m, + smf_npcf_smpolicycontrol_build_delete); + } break; case OGS_NAS_5GS_PDU_SESSION_RELEASE_COMPLETE: - smf_sbi_send_response(stream, OGS_SBI_HTTP_STATUS_NO_CONTENT); + ogs_sbi_send_http_status_no_content(stream); /* * Race condition for PDU session release complete * - CLIENT : /nsmf-pdusession/v1/sm-contexts/{smContextRef}/modify * - SERVER : /namf-callback/v1/{supi}/sm-context-status/{psi}) * - * smf_sbi_send_response(stream, OGS_SBI_HTTP_STATUS_NO_CONTENT); + * ogs_sbi_send_http_status_no_content(stream); * smf_sbi_send_sm_context_status_notify(sess); * * When executed as above, @@ -307,12 +365,12 @@ void smf_gsm_state_operational(ogs_fsm_t *s, smf_event_t *e) sess->ngap_state.pdu_session_resource_release = SMF_NGAP_STATE_NONE; if (ngap_state == SMF_NGAP_STATE_DELETE_TRIGGER_UE_REQUESTED) { - smf_sbi_send_response(stream, OGS_SBI_HTTP_STATUS_NO_CONTENT); + ogs_sbi_send_http_status_no_content(stream); } else if (ngap_state == SMF_NGAP_STATE_ERROR_INDICATION_RECEIVED_FROM_5G_AN) { smf_n1_n2_message_transfer_param_t param; - smf_sbi_send_response(stream, OGS_SBI_HTTP_STATUS_NO_CONTENT); + ogs_sbi_send_http_status_no_content(stream); memset(¶m, 0, sizeof(param)); param.state = SMF_NETWORK_TRIGGERED_SERVICE_REQUEST; diff --git a/src/smf/n4-handler.c b/src/smf/n4-handler.c index 607a64945..7ebea49e0 100644 --- a/src/smf/n4-handler.c +++ b/src/smf/n4-handler.c @@ -351,7 +351,7 @@ void smf_5gc_n4_handle_session_modification_response( } else { sess->paging.ue_requested_pdu_session_establishment_done = true; - smf_sbi_send_http_status_no_content(stream); + ogs_sbi_send_http_status_no_content(stream); } } else if (flags & OGS_PFCP_MODIFY_DEACTIVATE) { @@ -876,8 +876,7 @@ void smf_n4_handle_session_report_request( memset(¶m, 0, sizeof(param)); param.state = SMF_NETWORK_TRIGGERED_SERVICE_REQUEST; param.n2smbuf = - ngap_build_pdu_session_resource_setup_request_transfer( - sess); + ngap_build_pdu_session_resource_setup_request_transfer(sess); ogs_assert(param.n2smbuf); param.n1n2_failure_txf_notif_uri = true; diff --git a/src/smf/namf-handler.c b/src/smf/namf-handler.c index 7090b78c1..fc39af785 100644 --- a/src/smf/namf-handler.c +++ b/src/smf/namf-handler.c @@ -214,6 +214,6 @@ bool smf_namf_comm_handler_n1_n2_message_transfer_failure_notify( * Procedure for pause of charging at SMF is specified in clause 4.4.4. */ - smf_sbi_send_http_status_no_content(stream); + ogs_sbi_send_http_status_no_content(stream); return true; } diff --git a/src/smf/ngap-handler.c b/src/smf/ngap-handler.c index e0e706f96..ad306fcb7 100644 --- a/src/smf/ngap-handler.c +++ b/src/smf/ngap-handler.c @@ -144,7 +144,7 @@ int ngap_handle_pdu_session_resource_setup_response_transfer( 0)); } else { /* ACTIVATED Is NOT Included in RESPONSE */ - smf_sbi_send_http_status_no_content(stream); + ogs_sbi_send_http_status_no_content(stream); } rv = OGS_OK; @@ -351,7 +351,7 @@ int ngap_handle_path_switch_request_transfer( 0)); } else { /* ACTIVATED Is NOT Included in RESPONSE */ - smf_sbi_send_http_status_no_content(stream); + ogs_sbi_send_http_status_no_content(stream); } rv = OGS_OK; diff --git a/src/smf/npcf-build.c b/src/smf/npcf-build.c index 89513c5b1..572151e6d 100644 --- a/src/smf/npcf-build.c +++ b/src/smf/npcf-build.c @@ -69,6 +69,15 @@ ogs_sbi_request_t *smf_npcf_smpolicycontrol_build_create( SmPolicyContextData.notification_uri = ogs_sbi_server_uri(server, &header); ogs_assert(SmPolicyContextData.notification_uri); + if (sess->ipv4) + SmPolicyContextData.ipv4_address = + ogs_ipv4_to_string(sess->ipv4->addr[0]); + + if (sess->ipv6) { + SmPolicyContextData.ipv6_address_prefix = ogs_ipv6prefix_to_string( + (uint8_t *)sess->ipv6->addr, OGS_IPV6_128_PREFIX_LEN); + } + memset(&SubsSessAmbr, 0, sizeof(SubsSessAmbr)); if (OGS_SBI_FEATURES_IS_SET(sess->smpolicycontrol_features, OGS_SBI_NPCF_SMPOLICYCONTROL_DN_AUTHORIZATION)) { @@ -137,5 +146,123 @@ ogs_sbi_request_t *smf_npcf_smpolicycontrol_build_create( if (SmPolicyContextData.supp_feat) ogs_free(SmPolicyContextData.supp_feat); + if (SmPolicyContextData.ipv4_address) + ogs_free(SmPolicyContextData.ipv4_address); + if (SmPolicyContextData.ipv6_address_prefix) + ogs_free(SmPolicyContextData.ipv6_address_prefix); + + return request; +} + +ogs_sbi_request_t *smf_npcf_smpolicycontrol_build_delete( + smf_sess_t *sess, void *data) +{ + smf_npcf_smpolicycontrol_param_t *param = data; + + smf_ue_t *smf_ue = NULL; + + ogs_sbi_message_t message; + ogs_sbi_request_t *request = NULL; + + OpenAPI_sm_policy_delete_data_t SmPolicyDeleteData; + OpenAPI_list_t *ranNasRelCauseList = NULL; + OpenAPI_ran_nas_rel_cause_t *ranNasRelCause = NULL; + OpenAPI_user_location_t ueLocation; + OpenAPI_lnode_t *node = NULL; + + ogs_assert(sess); + ogs_assert(sess->sm_context_ref); + smf_ue = sess->smf_ue; + ogs_assert(smf_ue); + ogs_assert(sess->policy_association_id); + + memset(&message, 0, sizeof(message)); + message.h.method = (char *)OGS_SBI_HTTP_METHOD_POST; + message.h.service.name = (char *)OGS_SBI_SERVICE_NAME_NPCF_SMPOLICYCONTROL; + message.h.api.version = (char *)OGS_SBI_API_V1; + message.h.resource.component[0] = (char *)OGS_SBI_RESOURCE_NAME_SM_POLICIES; + message.h.resource.component[1] = sess->policy_association_id; + message.h.resource.component[2] = (char *)OGS_SBI_RESOURCE_NAME_DELETE; + + memset(&SmPolicyDeleteData, 0, sizeof(SmPolicyDeleteData)); + + memset(&ueLocation, 0, sizeof(ueLocation)); + + if (param) { + if (param->ran_nas_release.gmm_cause || + 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 (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); + + ngApCause->group = param->ran_nas_release.ngap_cause.group; + ngApCause->value = param->ran_nas_release.ngap_cause.value; + } + + ranNasRelCause->_5g_mm_cause = param->ran_nas_release.gmm_cause; + ranNasRelCause->_5g_sm_cause = param->ran_nas_release.gsm_cause; + + OpenAPI_list_add(ranNasRelCauseList, ranNasRelCause); + } + + if (param->ue_location) { + ueLocation.nr_location = ogs_sbi_build_nr_location( + &sess->nr_tai, &sess->nr_cgi); + ogs_assert(ueLocation.nr_location); + ueLocation.nr_location->ue_location_timestamp = + ogs_sbi_gmtime_string(sess->ue_location_timestamp); + + SmPolicyDeleteData.user_location_info = &ueLocation; + } + if (param->ue_timezone) { + SmPolicyDeleteData.ue_time_zone = + ogs_sbi_timezone_string(ogs_timezone()); + } + } + + SmPolicyDeleteData.serving_network = + ogs_sbi_build_plmn_id_nid(&sess->plmn_id); + + SmPolicyDeleteData.ran_nas_rel_causes = ranNasRelCauseList; + + message.SmPolicyDeleteData = &SmPolicyDeleteData; + + request = ogs_sbi_build_request(&message); + ogs_assert(request); + + if (ueLocation.nr_location) { + if (ueLocation.nr_location->ue_location_timestamp) + ogs_free(ueLocation.nr_location->ue_location_timestamp); + ogs_sbi_free_nr_location(ueLocation.nr_location); + } + if (SmPolicyDeleteData.ue_time_zone) + ogs_free(SmPolicyDeleteData.ue_time_zone); + + OpenAPI_list_for_each(ranNasRelCauseList, node) { + ranNasRelCause = node->data; + if (ranNasRelCause) { + if (ranNasRelCause->ng_ap_cause) { + ogs_free(ranNasRelCause->ng_ap_cause); + } + ogs_free(ranNasRelCause); + } + } + + OpenAPI_list_free(ranNasRelCauseList); + + if (SmPolicyDeleteData.serving_network) + ogs_sbi_free_plmn_id_nid(SmPolicyDeleteData.serving_network); + return request; } diff --git a/src/smf/npcf-build.h b/src/smf/npcf-build.h index c9a39c552..029dbcc09 100644 --- a/src/smf/npcf-build.h +++ b/src/smf/npcf-build.h @@ -26,8 +26,31 @@ extern "C" { #endif +typedef struct smf_npcf_smpolicycontrol_param_s { + struct { + struct { + int group; + int value; + } ngap_cause; + int gmm_cause; + int gsm_cause; + } ran_nas_release; + OpenAPI_pdu_session_rel_cause_e pdu_sess_rel_cause; + + union { + struct { + ED3(uint8_t ue_location:1;, + uint8_t ue_timezone:1;, + uint8_t spare:6;) + }; + uint8_t indications; + }; +} smf_npcf_smpolicycontrol_param_t; + ogs_sbi_request_t *smf_npcf_smpolicycontrol_build_create( smf_sess_t *sess, void *data); +ogs_sbi_request_t *smf_npcf_smpolicycontrol_build_delete( + smf_sess_t *sess, void *data); #ifdef __cplusplus } diff --git a/src/smf/npcf-handler.c b/src/smf/npcf-handler.c index 39aab7886..0a15e3782 100644 --- a/src/smf/npcf-handler.c +++ b/src/smf/npcf-handler.c @@ -24,7 +24,8 @@ #include "nas-path.h" bool smf_npcf_smpolicycontrol_handle_create( - smf_sess_t *sess, ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) + smf_sess_t *sess, ogs_sbi_stream_t *stream, int state, + ogs_sbi_message_t *recvmsg) { int rv; char buf1[OGS_ADDRSTRLEN]; @@ -404,9 +405,6 @@ bool smf_npcf_smpolicycontrol_handle_create( up2cp_far = sess->up2cp_far; ogs_assert(up2cp_far); - /* Set UE IP Address to the Default DL PDR */ - smf_sess_set_ue_ip(sess); - ogs_pfcp_paa_to_ue_ip_addr(&sess->session.paa, &dl_pdr->ue_ip_addr, &dl_pdr->ue_ip_addr_len); dl_pdr->ue_ip_addr.sd = OGS_PFCP_UE_IP_DST; @@ -502,3 +500,17 @@ cleanup: return false; } + +bool smf_npcf_smpolicycontrol_handle_delete( + smf_sess_t *sess, ogs_sbi_stream_t *stream, int state, + ogs_sbi_message_t *recvmsg) +{ + int trigger = state; + + ogs_assert(trigger); + + ogs_assert(OGS_OK == + smf_5gc_pfcp_send_session_deletion_request(sess, stream, trigger)); + + return true; +} diff --git a/src/smf/npcf-handler.h b/src/smf/npcf-handler.h index 56c271915..961f49a74 100644 --- a/src/smf/npcf-handler.h +++ b/src/smf/npcf-handler.h @@ -27,7 +27,11 @@ extern "C" { #include "context.h" bool smf_npcf_smpolicycontrol_handle_create( - smf_sess_t *sess, ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); + smf_sess_t *sess, ogs_sbi_stream_t *stream, int state, + ogs_sbi_message_t *recvmsg); +bool smf_npcf_smpolicycontrol_handle_delete( + smf_sess_t *sess, ogs_sbi_stream_t *stream, int state, + ogs_sbi_message_t *recvmsg); #ifdef __cplusplus } diff --git a/src/smf/nsmf-handler.c b/src/smf/nsmf-handler.c index b74e6704d..a775b6111 100644 --- a/src/smf/nsmf-handler.c +++ b/src/smf/nsmf-handler.c @@ -347,11 +347,20 @@ bool smf_nsmf_handle_update_sm_context( /********************************************************* * Handle DEACTIVATED ********************************************************/ - ogs_assert(OGS_OK == - smf_5gc_pfcp_send_session_modification_request( - sess, stream, - OGS_PFCP_MODIFY_DL_ONLY|OGS_PFCP_MODIFY_DEACTIVATE, - 0)); + if (ogs_list_count(&sess->bearer_list) == 0) { + /* If there is no Qos-Flow, + * we assume that there is no PFCP context in the UPF. + * + * PFCP deactivation is skipped. */ + smf_sbi_send_sm_context_updated_data_up_cnx_state( + sess, stream, OpenAPI_up_cnx_state_DEACTIVATED); + } else { + ogs_assert(OGS_OK == + smf_5gc_pfcp_send_session_modification_request( + sess, stream, + OGS_PFCP_MODIFY_DL_ONLY|OGS_PFCP_MODIFY_DEACTIVATE, + 0)); + } } else if (SmContextUpdateData->up_cnx_state == OpenAPI_up_cnx_state_ACTIVATING) { @@ -539,9 +548,16 @@ bool smf_nsmf_handle_update_sm_context( return false; } } else if (SmContextUpdateData->release) { - ogs_assert(OGS_OK == - smf_5gc_pfcp_send_session_deletion_request(sess, stream, - OGS_PFCP_DELETE_TRIGGER_AMF_UPDATE_SM_CONTEXT)); + smf_npcf_smpolicycontrol_param_t param; + + memset(¶m, 0, sizeof(param)); + + param.ue_location = true; + param.ue_timezone = true; + + smf_sbi_discover_and_send(OpenAPI_nf_type_PCF, sess, stream, + OGS_PFCP_DELETE_TRIGGER_AMF_UPDATE_SM_CONTEXT, ¶m, + smf_npcf_smpolicycontrol_build_delete); } else { ogs_error("[%s:%d] No UpdateData", smf_ue->supi, sess->psi); smf_sbi_send_sm_context_update_error(stream, @@ -556,12 +572,16 @@ bool smf_nsmf_handle_update_sm_context( bool smf_nsmf_handle_release_sm_context( smf_sess_t *sess, ogs_sbi_stream_t *stream, ogs_sbi_message_t *message) { + smf_npcf_smpolicycontrol_param_t param; + OpenAPI_sm_context_release_data_t *SmContextReleaseData = NULL; ogs_assert(stream); ogs_assert(message); ogs_assert(sess); + memset(¶m, 0, sizeof(param)); + SmContextReleaseData = message->SmContextReleaseData; if (SmContextReleaseData) { if (SmContextReleaseData->ue_location && @@ -586,12 +606,24 @@ bool smf_nsmf_handle_release_sm_context( ogs_plmn_id_hexdump(&sess->nr_cgi.plmn_id), (long long)sess->nr_cgi.cell_id); } + + param.ue_location = true; + param.ue_timezone = true; } + + if (SmContextReleaseData->ng_ap_cause) { + param.ran_nas_release.ngap_cause.group = + SmContextReleaseData->ng_ap_cause->group; + param.ran_nas_release.ngap_cause.value = + SmContextReleaseData->ng_ap_cause->value; + } + param.ran_nas_release.gmm_cause = + SmContextReleaseData->_5g_mm_cause_value; } - ogs_assert(OGS_OK == - smf_5gc_pfcp_send_session_deletion_request(sess, stream, - OGS_PFCP_DELETE_TRIGGER_AMF_RELEASE_SM_CONTEXT)); + smf_sbi_discover_and_send(OpenAPI_nf_type_PCF, sess, stream, + OGS_PFCP_DELETE_TRIGGER_AMF_RELEASE_SM_CONTEXT, ¶m, + smf_npcf_smpolicycontrol_build_delete); return true; } diff --git a/src/smf/nudm-handler.c b/src/smf/nudm-handler.c index 76c08b8ad..749c54557 100644 --- a/src/smf/nudm-handler.c +++ b/src/smf/nudm-handler.c @@ -241,6 +241,9 @@ bool smf_nudm_sdm_handle_get(smf_sess_t *sess, ogs_sbi_stream_t *stream, return false; } + /* Set UE IP Address to the Default DL PDR */ + smf_sess_set_ue_ip(sess); + /********************************************************************* * Send HTTP_STATUS_CREATED(/nsmf-pdusession/v1/sm-context) to the AMF *********************************************************************/ @@ -257,6 +260,7 @@ bool smf_nudm_sdm_handle_get(smf_sess_t *sess, ogs_sbi_stream_t *stream, header.resource.component[1] = sess->sm_context_ref; sendmsg.http.location = ogs_sbi_server_uri(server, &header); + ogs_assert(sendmsg.http.location); sendmsg.SmContextCreatedData = &SmContextCreatedData; @@ -266,8 +270,8 @@ bool smf_nudm_sdm_handle_get(smf_sess_t *sess, ogs_sbi_stream_t *stream, ogs_free(sendmsg.http.location); - smf_sbi_discover_and_send(OpenAPI_nf_type_PCF, sess, stream, NULL, - smf_npcf_smpolicycontrol_build_create); + smf_sbi_discover_and_send(OpenAPI_nf_type_PCF, sess, stream, + 0, NULL, smf_npcf_smpolicycontrol_build_create); return true; diff --git a/src/smf/sbi-path.c b/src/smf/sbi-path.c index f6bfe5617..6d1fbb0d2 100644 --- a/src/smf/sbi-path.c +++ b/src/smf/sbi-path.c @@ -138,7 +138,7 @@ void smf_sbi_send(ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_xact_t *xact) } void smf_sbi_discover_and_send(OpenAPI_nf_type_e target_nf_type, - smf_sess_t *sess, ogs_sbi_stream_t *stream, void *data, + smf_sess_t *sess, ogs_sbi_stream_t *stream, int state, void *data, ogs_sbi_request_t *(*build)(smf_sess_t *sess, void *data)) { ogs_sbi_xact_t *xact = NULL; @@ -164,6 +164,7 @@ void smf_sbi_discover_and_send(OpenAPI_nf_type_e target_nf_type, return; } + xact->state = state; xact->assoc_stream = stream; if (ogs_sbi_discover_and_send(xact, @@ -204,20 +205,6 @@ void smf_namf_comm_send_n1_n2_message_transfer( (ogs_fsm_handler_t)smf_nf_state_registered, client_cb); } -void smf_sbi_send_response(ogs_sbi_stream_t *stream, int status) -{ - ogs_sbi_message_t sendmsg; - ogs_sbi_response_t *response = NULL; - - ogs_assert(stream); - - memset(&sendmsg, 0, sizeof(sendmsg)); - - response = ogs_sbi_build_response(&sendmsg, status); - ogs_assert(response); - ogs_sbi_server_send_response(stream, response); -} - void smf_sbi_send_sm_context_create_error( ogs_sbi_stream_t *stream, int status, const char *title, const char *detail, diff --git a/src/smf/sbi-path.h b/src/smf/sbi-path.h index e46ceb4a8..d7196f097 100644 --- a/src/smf/sbi-path.h +++ b/src/smf/sbi-path.h @@ -39,16 +39,12 @@ void smf_nnrf_nfm_send_nf_register(ogs_sbi_nf_instance_t *nf_instance); void smf_sbi_send(ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_xact_t *xact); void smf_sbi_discover_and_send(OpenAPI_nf_type_e target_nf_type, - smf_sess_t *sess, ogs_sbi_stream_t *stream, void *data, + smf_sess_t *sess, ogs_sbi_stream_t *stream, int state, void *data, ogs_sbi_request_t *(*build)(smf_sess_t *sess, void *data)); void smf_namf_comm_send_n1_n2_message_transfer( smf_sess_t *sess, smf_n1_n2_message_transfer_param_t *param); -#define smf_sbi_send_http_status_no_content(__sTREAM) \ - smf_sbi_send_response(__sTREAM, OGS_SBI_HTTP_STATUS_NO_CONTENT); -void smf_sbi_send_response(ogs_sbi_stream_t *stream, int status); - void smf_sbi_send_sm_context_create_error( ogs_sbi_stream_t *stream, int status, const char *title, const char *detail, diff --git a/src/smf/smf-sm.c b/src/smf/smf-sm.c index 0ead6790a..167afee7f 100644 --- a/src/smf/smf-sm.c +++ b/src/smf/smf-sm.c @@ -374,19 +374,16 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) smf_namf_comm_handler_n1_n2_message_transfer_failure_notify( stream, &sbi_message); break; + CASE(OGS_SBI_RESOURCE_NAME_SM_POLICY_NOTIFY) + ogs_sbi_send_http_status_no_content(stream); + break; DEFAULT - SWITCH(sbi_message.h.resource.component[1]) - CASE(OGS_SBI_RESOURCE_NAME_SM_POLICY_NOTIFY) - /* TODO */ - - DEFAULT - ogs_error("Invalid resource name [%s]", - sbi_message.h.resource.component[1]); - ogs_sbi_server_send_error(stream, - OGS_SBI_HTTP_STATUS_BAD_REQUEST, &sbi_message, - "Invalid resource name", - sbi_message.h.resource.component[1]); - END + ogs_error("Invalid resource name [%s]", + sbi_message.h.resource.component[0]); + ogs_sbi_server_send_error(stream, + OGS_SBI_HTTP_STATUS_BAD_REQUEST, &sbi_message, + "Invalid resource name", + sbi_message.h.resource.component[0]); END break; diff --git a/src/udr/nudr-handler.c b/src/udr/nudr-handler.c index 1499e5d18..735340c21 100644 --- a/src/udr/nudr-handler.c +++ b/src/udr/nudr-handler.c @@ -737,7 +737,7 @@ bool udr_nudr_dr_handle_subscription_provisioned( ogs_ipv4_to_string(session->ue_ip.addr); if (session->ue_ip.ipv6) ipAddress->ipv6_addr = - ogs_ipv6_to_string(session->ue_ip.addr6); + ogs_ipv6addr_to_string(session->ue_ip.addr6); if (ipAddress->ipv4_addr || ipAddress->ipv6_addr) OpenAPI_list_add(staticIpAddress, ipAddress); diff --git a/tests/af/af-sm.c b/tests/af/af-sm.c new file mode 100644 index 000000000..1bf03c3b2 --- /dev/null +++ b/tests/af/af-sm.c @@ -0,0 +1,361 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "sbi-path.h" +#include "nnrf-handler.h" +#include "nbsf-handler.h" +#include "npcf-handler.h" + +void af_state_initial(ogs_fsm_t *s, af_event_t *e) +{ + af_sm_debug(e); + + ogs_assert(s); + + OGS_FSM_TRAN(s, &af_state_operational); +} + +void af_state_final(ogs_fsm_t *s, af_event_t *e) +{ + af_sm_debug(e); + + ogs_assert(s); +} + +void af_state_operational(ogs_fsm_t *s, af_event_t *e) +{ + int rv; + + af_sess_t *sess = NULL; + + ogs_sbi_stream_t *stream = NULL; + ogs_sbi_request_t *request = NULL; + + ogs_sbi_nf_instance_t *nf_instance = NULL; + ogs_sbi_subscription_t *subscription = NULL; + ogs_sbi_response_t *response = NULL; + ogs_sbi_message_t message; + ogs_sbi_xact_t *sbi_xact = NULL; + + af_sm_debug(e); + + ogs_assert(s); + + switch (e->id) { + case OGS_FSM_ENTRY_SIG: + break; + + case OGS_FSM_EXIT_SIG: + break; + + case AF_EVT_SBI_SERVER: + request = e->sbi.request; + ogs_assert(request); + stream = e->sbi.data; + ogs_assert(stream); + + rv = ogs_sbi_parse_request(&message, request); + if (rv != OGS_OK) { + /* 'sbi_message' buffer is released in ogs_sbi_parse_request() */ + ogs_error("cannot parse HTTP sbi_message"); + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + NULL, "cannot parse HTTP sbi_message", NULL); + break; + } + + if (strcmp(message.h.api.version, OGS_SBI_API_V1) != 0) { + ogs_error("Not supported version [%s]", message.h.api.version); + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + &message, "Not supported version", NULL); + ogs_sbi_message_free(&message); + break; + } + + SWITCH(message.h.service.name) + CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) + + SWITCH(message.h.resource.component[0]) + CASE(OGS_SBI_RESOURCE_NAME_NF_STATUS_NOTIFY) + SWITCH(message.h.method) + CASE(OGS_SBI_HTTP_METHOD_POST) + af_nnrf_handle_nf_status_notify(stream, &message); + break; + + DEFAULT + ogs_error("Invalid HTTP method [%s]", message.h.method); + ogs_sbi_server_send_error(stream, + OGS_SBI_HTTP_STATUS_FORBIDDEN, &message, + "Invalid HTTP method", message.h.method); + END + break; + + DEFAULT + ogs_error("Invalid resource name [%s]", + message.h.resource.component[0]); + ogs_sbi_server_send_error(stream, + OGS_SBI_HTTP_STATUS_BAD_REQUEST, &message, + "Invalid resource name", + message.h.resource.component[0]); + END + break; + + DEFAULT + ogs_error("Invalid API name [%s]", message.h.service.name); + ogs_sbi_server_send_error(stream, + OGS_SBI_HTTP_STATUS_BAD_REQUEST, &message, + "Invalid API name", message.h.service.name); + END + + /* In lib/sbi/server.c, notify_completed() releases 'request' buffer. */ + ogs_sbi_message_free(&message); + break; + + case AF_EVT_SBI_CLIENT: + ogs_assert(e); + + response = e->sbi.response; + ogs_assert(response); + rv = ogs_sbi_parse_response(&message, response); + if (rv != OGS_OK) { + ogs_error("cannot parse HTTP response"); + ogs_sbi_message_free(&message); + ogs_sbi_response_free(response); + break; + } + + if (strcmp(message.h.api.version, OGS_SBI_API_V1) != 0) { + ogs_error("Not supported version [%s]", message.h.api.version); + ogs_sbi_message_free(&message); + ogs_sbi_response_free(response); + break; + } + + SWITCH(message.h.service.name) + CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) + + SWITCH(message.h.resource.component[0]) + CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) + nf_instance = e->sbi.data; + ogs_assert(nf_instance); + ogs_assert(OGS_FSM_STATE(&nf_instance->sm)); + + e->sbi.message = &message; + ogs_fsm_dispatch(&nf_instance->sm, e); + break; + + CASE(OGS_SBI_RESOURCE_NAME_SUBSCRIPTIONS) + subscription = e->sbi.data; + ogs_assert(subscription); + + SWITCH(message.h.method) + CASE(OGS_SBI_HTTP_METHOD_POST) + if (message.res_status == OGS_SBI_HTTP_STATUS_CREATED || + message.res_status == OGS_SBI_HTTP_STATUS_OK) { + af_nnrf_handle_nf_status_subscribe( + subscription, &message); + } else { + ogs_error("HTTP response error : %d", + message.res_status); + } + break; + + CASE(OGS_SBI_HTTP_METHOD_DELETE) + if (message.res_status == OGS_SBI_HTTP_STATUS_NO_CONTENT) { + ogs_sbi_subscription_remove(subscription); + } 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; + + CASE(OGS_SBI_SERVICE_NAME_NNRF_DISC) + SWITCH(message.h.resource.component[0]) + CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) + sbi_xact = e->sbi.data; + ogs_assert(sbi_xact); + + SWITCH(message.h.method) + CASE(OGS_SBI_HTTP_METHOD_GET) + if (message.res_status == OGS_SBI_HTTP_STATUS_OK) + af_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; + + CASE(OGS_SBI_SERVICE_NAME_NBSF_MANAGEMENT) + SWITCH(message.h.resource.component[0]) + CASE(OGS_SBI_RESOURCE_NAME_PCF_BINDINGS) + sbi_xact = e->sbi.data; + ogs_assert(sbi_xact); + + sess = (af_sess_t *)sbi_xact->sbi_object; + ogs_assert(sess); + + ogs_sbi_xact_remove(sbi_xact); + + SWITCH(message.h.method) + CASE(OGS_SBI_HTTP_METHOD_GET) + if (message.res_status == OGS_SBI_HTTP_STATUS_OK) + af_nbsf_management_handle_pcf_binding(sess, &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; + + CASE(OGS_SBI_SERVICE_NAME_NPCF_POLICYAUTHORIZATION) + SWITCH(message.h.resource.component[0]) + CASE(OGS_SBI_RESOURCE_NAME_APP_SESSIONS) + sess = e->sbi.data; + ogs_assert(sess); + + if (message.res_status == OGS_SBI_HTTP_STATUS_CREATED) + af_npcf_policyauthorization_handle_create(sess, &message); + else + ogs_error("HTTP response error [%d]", message.res_status); + 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(); + END + + ogs_sbi_message_free(&message); + ogs_sbi_response_free(response); + break; + + case AF_EVT_SBI_TIMER: + ogs_assert(e); + + switch(e->timer_id) { + case AF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: + case AF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: + case AF_TIMER_NF_INSTANCE_NO_HEARTBEAT: + case AF_TIMER_NF_INSTANCE_VALIDITY: + nf_instance = e->sbi.data; + ogs_assert(nf_instance); + ogs_assert(OGS_FSM_STATE(&nf_instance->sm)); + + ogs_fsm_dispatch(&nf_instance->sm, e); + if (OGS_FSM_CHECK(&nf_instance->sm, af_nf_state_exception)) + ogs_error("State machine exception [%d]", e->timer_id); + break; + + case AF_TIMER_SUBSCRIPTION_VALIDITY: + subscription = e->sbi.data; + ogs_assert(subscription); + + ogs_nnrf_nfm_send_nf_status_subscribe(subscription->client, + af_self()->nf_type, subscription->req_nf_instance_id, + subscription->subscr_cond.nf_type); + + ogs_info("Subscription validity expired [%s]", subscription->id); + ogs_sbi_subscription_remove(subscription); + break; + + case AF_TIMER_SBI_CLIENT_WAIT: + sbi_xact = e->sbi.data; + ogs_assert(sbi_xact); + + stream = sbi_xact->assoc_stream; + /* Here, we should not use ogs_assert(stream) + * since 'namf-comm' service has no an associated stream. */ + + ogs_sbi_xact_remove(sbi_xact); + + ogs_error("Cannot receive SBI message"); + if (stream) { + ogs_sbi_server_send_error(stream, + OGS_SBI_HTTP_STATUS_GATEWAY_TIMEOUT, NULL, + "Cannot receive SBI message", NULL); + } + break; + + default: + ogs_error("Unknown timer[%s:%d]", + af_timer_get_name(e->timer_id), e->timer_id); + } + break; + + case AF_EVT_SBI_LOCAL: + ogs_assert(e); + + switch(e->local_id) { + case AF_LOCAL_DISCOVER_AND_SEND: + af_sbi_discover_and_send(e->local.target_nf_type, + e->sess, e->local.data, e->local.build); + break; + case AF_LOCAL_SEND_TO_PCF: + af_sbi_send_to_pcf(e->sess, e->local.data, e->local.build); + break; + default: + ogs_error("Unknown local[%s:%d]", + af_local_get_name(e->local_id), e->local_id); + } + break; + + default: + ogs_error("No handler for event %s", af_event_get_name(e)); + break; + } +} diff --git a/tests/af/af-sm.h b/tests/af/af-sm.h new file mode 100644 index 000000000..7fa09e683 --- /dev/null +++ b/tests/af/af-sm.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef AF_SM_H +#define AF_SM_H + +#include "event.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void af_state_initial(ogs_fsm_t *s, af_event_t *e); +void af_state_final(ogs_fsm_t *s, af_event_t *e); +void af_state_operational(ogs_fsm_t *s, af_event_t *e); +void af_state_exception(ogs_fsm_t *s, af_event_t *e); + +void af_nf_fsm_init(ogs_sbi_nf_instance_t *nf_instance); +void af_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance); + +void af_nf_state_initial(ogs_fsm_t *s, af_event_t *e); +void af_nf_state_final(ogs_fsm_t *s, af_event_t *e); +void af_nf_state_will_register(ogs_fsm_t *s, af_event_t *e); +void af_nf_state_registered(ogs_fsm_t *s, af_event_t *e); +void af_nf_state_de_registered(ogs_fsm_t *s, af_event_t *e); +void af_nf_state_exception(ogs_fsm_t *s, af_event_t *e); + +#define af_sm_debug(__pe) \ + ogs_debug("%s(): %s", __func__, af_event_get_name(__pe)) + +#ifdef __cplusplus +} +#endif + +#endif /* AF_SM_H */ diff --git a/tests/af/context.c b/tests/af/context.c new file mode 100644 index 000000000..ac0d16582 --- /dev/null +++ b/tests/af/context.c @@ -0,0 +1,322 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "context.h" + +static af_context_t self; + +int __af_log_domain; + +static OGS_POOL(af_sess_pool, af_sess_t); + +static int context_initialized = 0; + +static void clear_pcf_app_session_id(af_sess_t *sess); + +void af_context_init(void) +{ + ogs_assert(context_initialized == 0); + + /* Initialize AF context */ + memset(&self, 0, sizeof(af_context_t)); + + ogs_log_install_domain(&__af_log_domain, "af", ogs_core()->log.level); + + ogs_pool_init(&af_sess_pool, ogs_app()->pool.sess); + + self.supi_hash = ogs_hash_make(); + self.ipv4_hash = ogs_hash_make(); + self.ipv6_hash = ogs_hash_make(); + self.pcf_app_session_id_hash = ogs_hash_make(); + + context_initialized = 1; +} + +void af_context_final(void) +{ + ogs_assert(context_initialized == 1); + + af_sess_remove_all(); + + ogs_assert(self.supi_hash); + ogs_hash_destroy(self.supi_hash); + ogs_assert(self.ipv4_hash); + ogs_hash_destroy(self.ipv4_hash); + ogs_assert(self.ipv6_hash); + ogs_hash_destroy(self.ipv6_hash); + ogs_assert(self.pcf_app_session_id_hash); + ogs_hash_destroy(self.pcf_app_session_id_hash); + + ogs_pool_final(&af_sess_pool); + + context_initialized = 0; +} + +af_context_t *af_self(void) +{ + return &self; +} + +static int af_context_prepare(void) +{ + self.nf_type = OpenAPI_nf_type_AF; + + return OGS_OK; +} + +static int af_context_validation(void) +{ + return OGS_OK; +} + +int af_context_parse_config(void) +{ + int rv; + yaml_document_t *document = NULL; + ogs_yaml_iter_t root_iter; + + document = ogs_app()->document; + ogs_assert(document); + + rv = af_context_prepare(); + if (rv != OGS_OK) return rv; + + ogs_yaml_iter_init(&root_iter, document); + while (ogs_yaml_iter_next(&root_iter)) { + const char *root_key = ogs_yaml_iter_key(&root_iter); + ogs_assert(root_key); + if (!strcmp(root_key, "af")) { + ogs_yaml_iter_t af_iter; + ogs_yaml_iter_recurse(&root_iter, &af_iter); + while (ogs_yaml_iter_next(&af_iter)) { + const char *af_key = ogs_yaml_iter_key(&af_iter); + ogs_assert(af_key); + if (!strcmp(af_key, "sbi")) { + /* handle config in sbi library */ + } else + ogs_warn("unknown key `%s`", af_key); + } + } + } + + rv = af_context_validation(); + if (rv != OGS_OK) return rv; + + return OGS_OK; +} + +af_sess_t *af_sess_add_by_ue_address(ogs_ip_t *ue_address) +{ + af_sess_t *sess = NULL; + + ogs_assert(ue_address); + ogs_assert(ue_address->ipv4 || ue_address->ipv6); + + ogs_pool_alloc(&af_sess_pool, &sess); + ogs_expect_or_return_val(sess, NULL); + memset(sess, 0, sizeof *sess); + + sess->af_app_session_id = ogs_msprintf("%d", + (int)ogs_pool_index(&af_sess_pool, sess)); + + if (ue_address->ipv4 && ue_address->addr) { + sess->ipv4addr = ogs_ipv4_to_string(ue_address->addr); + ogs_expect_or_return_val(sess->ipv4addr, NULL); + } + + if (ue_address->ipv6 && ue_address->addr6) { + sess->ipv6addr = ogs_ipv6addr_to_string(ue_address->addr6); + ogs_expect_or_return_val(sess->ipv6addr, NULL); + sess->ipv6prefix = ogs_ipv6prefix_to_string( + ue_address->addr6, OGS_IPV6_128_PREFIX_LEN); + } + + OGS_SBI_FEATURES_SET(sess->policyauthorization_features, + OGS_SBI_NPCF_POLICYAUTHORIZATION_IMS_SBI); + + ogs_list_add(&self.sess_list, sess); + + return sess; +} + +void af_sess_remove(af_sess_t *sess) +{ + int i; + + ogs_assert(sess); + + ogs_list_remove(&self.sess_list, sess); + + /* Free SBI object memory */ + ogs_sbi_object_free(&sess->sbi); + + if (sess->af_app_session_id) + ogs_free(sess->af_app_session_id); + + clear_pcf_app_session_id(sess); + + if (sess->ipv4addr) + ogs_free(sess->ipv4addr); + if (sess->ipv6addr) + ogs_free(sess->ipv6addr); + if (sess->ipv6prefix) + ogs_free(sess->ipv6prefix); + + if (sess->supi) + ogs_free(sess->supi); + if (sess->gpsi) + ogs_free(sess->gpsi); + + if (sess->dnn) + ogs_free(sess->dnn); + + if (sess->pcf.fqdn) + ogs_free(sess->pcf.fqdn); + + for (i = 0; i < sess->pcf.num_of_ip; i++) { + if (sess->pcf.ip[i].addr) + ogs_freeaddrinfo(sess->pcf.ip[i].addr); + if (sess->pcf.ip[i].addr6) + ogs_freeaddrinfo(sess->pcf.ip[i].addr6); + } + sess->pcf.num_of_ip = 0; + + if (sess->pcf.client) + ogs_sbi_client_remove(sess->pcf.client); + + ogs_pool_free(&af_sess_pool, sess); +} + +void af_sess_remove_all(void) +{ + af_sess_t *sess = NULL, *next_sess = NULL; + + ogs_list_for_each_safe(&self.sess_list, next_sess, sess) + af_sess_remove(sess); +} + +static void clear_pcf_app_session_id(af_sess_t *sess) +{ + ogs_assert(sess); + + if (sess->pcf_app_session_id) { + ogs_hash_set(self.pcf_app_session_id_hash, + &sess->pcf_app_session_id, sizeof(sess->pcf_app_session_id), NULL); + ogs_free(sess->pcf_app_session_id); + } +} + +bool af_sess_set_pcf_app_session_id(af_sess_t *sess, char *pcf_app_session_id) +{ + ogs_assert(sess); + ogs_assert(pcf_app_session_id); + + clear_pcf_app_session_id(sess); + + sess->pcf_app_session_id = ogs_strdup(pcf_app_session_id); + ogs_expect_or_return_val(sess->pcf_app_session_id, false); + + ogs_hash_set(self.pcf_app_session_id_hash, + &sess->pcf_app_session_id, sizeof(sess->pcf_app_session_id), sess); + + return true; +} + +af_sess_t *af_sess_find(uint32_t index) +{ + return ogs_pool_find(&af_sess_pool, index); +} + +af_sess_t *af_sess_find_by_af_app_session_id(char *af_app_session_id) +{ + ogs_assert(af_app_session_id); + return af_sess_find(atoll(af_app_session_id)); +} + +void af_sess_select_nf(af_sess_t *sess, OpenAPI_nf_type_e nf_type) +{ + ogs_assert(sess); + ogs_assert(nf_type); + + if (nf_type == OpenAPI_nf_type_NRF) + ogs_sbi_select_nrf(&sess->sbi, af_nf_state_registered); + else + ogs_sbi_select_first_nf(&sess->sbi, nf_type, af_nf_state_registered); +} + +static ogs_sbi_client_t *find_client_by_fqdn(char *fqdn, int port) +{ + int rv; + ogs_sockaddr_t *addr = NULL; + ogs_sbi_client_t *client = NULL; + + rv = ogs_getaddrinfo(&addr, AF_UNSPEC, fqdn, + port ? port : OGS_SBI_HTTPS_PORT, 0); + if (rv != OGS_OK) { + ogs_error("Invalid NFProfile.fqdn"); + return NULL; + } + + client = ogs_sbi_client_find(addr); + if (!client) { + client = ogs_sbi_client_add(addr); + ogs_assert(client); + } + + ogs_freeaddrinfo(addr); + + return client; +} + +void af_sess_associate_pcf_client(af_sess_t *sess) +{ + ogs_sbi_client_t *client = NULL; + ogs_sockaddr_t *addr = NULL; + + ogs_assert(sess); + + if (sess->pcf.fqdn && strlen(sess->pcf.fqdn)) + client = find_client_by_fqdn(sess->pcf.fqdn, 0); + + if (!client) { + /* At this point, CLIENT selection method is very simple. */ + if (sess->pcf.num_of_ip) { + addr = sess->pcf.ip[0].addr6; + if (!addr) + addr = sess->pcf.ip[0].addr; + } + + if (addr) { + client = ogs_sbi_client_find(addr); + if (!client) { + client = ogs_sbi_client_add(addr); + ogs_assert(client); + } + } + } + + if (client) { + if (sess->pcf.client && sess->pcf.client != client) { + ogs_warn("PCF EndPoint updated"); + ogs_sbi_client_remove(sess->pcf.client); + } + + OGS_SETUP_SBI_CLIENT(&sess->pcf, client); + } +} diff --git a/tests/af/context.h b/tests/af/context.h new file mode 100644 index 000000000..afc85cd98 --- /dev/null +++ b/tests/af/context.h @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef AF_CONTEXT_H +#define AF_CONTEXT_H + +#include "ogs-sbi.h" +#include "ogs-app.h" + +#include "event.h" +#include "timer.h" +#include "local.h" +#include "af-sm.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern int __af_log_domain; + +#undef OGS_LOG_DOMAIN +#define OGS_LOG_DOMAIN __af_log_domain + +typedef struct af_context_s { + OpenAPI_nf_type_e nf_type; + + ogs_hash_t *supi_hash; /* hash table (SUPI) */ + ogs_hash_t *ipv4_hash; /* hash table (IPv4 Address) */ + ogs_hash_t *ipv6_hash; /* hash table (IPv6 Address) */ + ogs_hash_t *pcf_app_session_id_hash; /* hash table (AppSessionId) */ + + ogs_list_t sess_list; +} af_context_t; + +#define AF_NF_INSTANCE_CLEAR(_cAUSE, _nFInstance) \ + do { \ + ogs_assert(_nFInstance); \ + if ((_nFInstance)->reference_count == 1) { \ + ogs_info("[%s] (%s) NF removed", (_nFInstance)->id, (_cAUSE)); \ + af_nf_fsm_fini((_nFInstance)); \ + } else { \ + /* There is an assocation with other context */ \ + ogs_info("[%s:%d] (%s) NF suspended", \ + _nFInstance->id, _nFInstance->reference_count, (_cAUSE)); \ + OGS_FSM_TRAN(&_nFInstance->sm, af_nf_state_de_registered); \ + ogs_fsm_dispatch(&_nFInstance->sm, NULL); \ + } \ + ogs_sbi_nf_instance_remove(_nFInstance); \ + } while(0) + +typedef struct af_sess_s af_sess_t; + +typedef struct af_sess_s { + ogs_sbi_object_t sbi; + + uint64_t policyauthorization_features; + + char *af_app_session_id; + char *pcf_app_session_id; + + char *ipv4addr; + char *ipv6addr; + char *ipv6prefix; + + char *supi; + char *gpsi; + + ogs_s_nssai_t s_nssai; + char *dnn; + + struct { + char *fqdn; + + int num_of_ip; + struct { + ogs_sockaddr_t *addr; + ogs_sockaddr_t *addr6; + int port; + } ip[OGS_SBI_MAX_NUM_OF_IP_ADDRESS]; + + ogs_sbi_client_t *client; + } pcf; + +} af_sess_t; + +void af_context_init(void); +void af_context_final(void); +af_context_t *af_self(void); + +int af_context_parse_config(void); + +af_sess_t *af_sess_add_by_ue_address(ogs_ip_t *ue_address); +void af_sess_remove(af_sess_t *sess); +void af_sess_remove_all(void); + +bool af_sess_set_pcf_app_session_id(af_sess_t *sess, char *pcf_app_session_id); + +af_sess_t *af_sess_find(uint32_t index); +af_sess_t *af_sess_find_by_af_app_session_id(char *af_app_session_id); +af_sess_t *af_sess_find_by_pcf_app_session_id(char *pcf_app_session_id); + +void af_sess_select_nf(af_sess_t *sess, OpenAPI_nf_type_e nf_type); + +void af_sess_associate_pcf_client(af_sess_t *sess); + +#ifdef __cplusplus +} +#endif + +#endif /* AF_CONTEXT_H */ diff --git a/tests/af/event.c b/tests/af/event.c new file mode 100644 index 000000000..f2e8cfedf --- /dev/null +++ b/tests/af/event.c @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "context.h" + +static OGS_POOL(pool, af_event_t); + +void af_event_init(void) +{ + ogs_pool_init(&pool, ogs_app()->pool.event); +} + +void af_event_final(void) +{ + ogs_pool_final(&pool); +} + +af_event_t *af_event_new(af_event_e id) +{ + af_event_t *e = NULL; + + ogs_pool_alloc(&pool, &e); + ogs_assert(e); + memset(e, 0, sizeof(*e)); + + e->id = id; + + return e; +} + +void af_event_free(af_event_t *e) +{ + ogs_assert(e); + ogs_pool_free(&pool, e); +} + +const char *af_event_get_name(af_event_t *e) +{ + if (e == NULL) + return OGS_FSM_NAME_INIT_SIG; + + switch (e->id) { + case OGS_FSM_ENTRY_SIG: + return OGS_FSM_NAME_ENTRY_SIG; + case OGS_FSM_EXIT_SIG: + return OGS_FSM_NAME_EXIT_SIG; + + case AF_EVT_SBI_SERVER: + return "AF_EVT_SBI_SERVER"; + case AF_EVT_SBI_CLIENT: + return "AF_EVT_SBI_CLIENT"; + case AF_EVT_SBI_TIMER: + return "AF_EVT_SBI_TIMER"; + case AF_EVT_SBI_LOCAL: + return "AF_EVT_SBI_LOCAL"; + + default: + break; + } + + return "UNKNOWN_EVENT"; +} diff --git a/tests/af/event.h b/tests/af/event.h new file mode 100644 index 000000000..22178d8ee --- /dev/null +++ b/tests/af/event.h @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef AF_EVENT_H +#define AF_EVENT_H + +#include "ogs-core.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct af_sess_s af_sess_t; +typedef struct ogs_sbi_request_s ogs_sbi_request_t; +typedef struct ogs_sbi_response_s ogs_sbi_response_t; +typedef struct ogs_sbi_message_s ogs_sbi_message_t; +typedef struct ogs_sbi_subscription_s ogs_sbi_subscription_t; + +typedef enum { + AF_EVT_BASE = OGS_FSM_USER_SIG, + + AF_EVT_SBI_SERVER, + AF_EVT_SBI_CLIENT, + AF_EVT_SBI_TIMER, + AF_EVT_SBI_LOCAL, + + AF_EVT_TOP, + +} af_event_e; + +typedef struct af_event_s { + int id; + ogs_pkbuf_t *pkbuf; + int timer_id; + int local_id; + + struct { + OpenAPI_nf_type_e target_nf_type; + void *data; + ogs_sbi_request_t *(*build)(af_sess_t *sess, void *data); + } local; + + struct { + ogs_sbi_request_t *request; + ogs_sbi_response_t *response; + void *data; + int state; + + ogs_sbi_message_t *message; + } sbi; + + af_sess_t *sess; +} af_event_t; + +void af_event_init(void); +void af_event_final(void); + +af_event_t *af_event_new(af_event_e id); +void af_event_free(af_event_t *e); + +const char *af_event_get_name(af_event_t *e); + +#ifdef __cplusplus +} +#endif + +#endif /* AF_EVENT_H */ diff --git a/tests/af/init.c b/tests/af/init.c new file mode 100644 index 000000000..82338821e --- /dev/null +++ b/tests/af/init.c @@ -0,0 +1,142 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "init.h" +#include "sbi-path.h" + +static ogs_thread_t *thread; +static void af_main(void *data); + +static int initialized = 0; + +int af_initialize() +{ + int rv; + + af_context_init(); + af_event_init(); + ogs_sbi_context_init(); + + rv = ogs_sbi_context_parse_config("af", "nrf"); + if (rv != OGS_OK) return rv; + + rv = af_context_parse_config(); + if (rv != OGS_OK) return rv; + + rv = ogs_log_config_domain( + ogs_app()->logger.domain, ogs_app()->logger.level); + if (rv != OGS_OK) return rv; + + rv = af_sbi_open(); + if (rv != 0) return OGS_ERROR; + + thread = ogs_thread_create(af_main, NULL); + if (!thread) return OGS_ERROR; + + initialized = 1; + + return OGS_OK; +} + +static ogs_timer_t *t_termination_holding = NULL; + +static void event_termination(void) +{ + ogs_sbi_nf_instance_t *nf_instance = NULL; + + /* Sending NF Instance De-registeration to NRF */ + ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) + af_nf_fsm_fini(nf_instance); + + /* Starting holding timer */ + t_termination_holding = ogs_timer_add(ogs_app()->timer_mgr, NULL, NULL); + ogs_assert(t_termination_holding); +#define TERMINATION_HOLDING_TIME ogs_time_from_msec(300) + ogs_timer_start(t_termination_holding, TERMINATION_HOLDING_TIME); + + /* Sending termination event to the queue */ + ogs_queue_term(ogs_app()->queue); + ogs_pollset_notify(ogs_app()->pollset); +} + +void af_terminate(void) +{ + if (!initialized) return; + + /* Daemon terminating */ + event_termination(); + ogs_thread_destroy(thread); + ogs_timer_delete(t_termination_holding); + + af_sbi_close(); + + af_context_final(); + + ogs_sbi_context_final(); + + af_event_final(); /* Destroy event */ +} + +static void af_main(void *data) +{ + ogs_fsm_t af_sm; + int rv; + + ogs_fsm_create(&af_sm, af_state_initial, af_state_final); + ogs_fsm_init(&af_sm, 0); + + for ( ;; ) { + ogs_pollset_poll(ogs_app()->pollset, + ogs_timer_mgr_next(ogs_app()->timer_mgr)); + + /* + * After ogs_pollset_poll(), ogs_timer_mgr_expire() must be called. + * + * The reason is why ogs_timer_mgr_next() can get the corrent value + * when ogs_timer_stop() is called internally in ogs_timer_mgr_expire(). + * + * You should not use event-queue before ogs_timer_mgr_expire(). + * In this case, ogs_timer_mgr_expire() does not work + * because 'if rv == OGS_DONE' statement is exiting and + * not calling ogs_timer_mgr_expire(). + */ + ogs_timer_mgr_expire(ogs_app()->timer_mgr); + + for ( ;; ) { + af_event_t *e = NULL; + + rv = ogs_queue_trypop(ogs_app()->queue, (void**)&e); + ogs_assert(rv != OGS_ERROR); + + if (rv == OGS_DONE) + goto done; + + if (rv == OGS_RETRY) + break; + + ogs_assert(e); + ogs_fsm_dispatch(&af_sm, e); + af_event_free(e); + } + } +done: + + ogs_fsm_fini(&af_sm, 0); + ogs_fsm_delete(&af_sm); +} diff --git a/tests/af/init.h b/tests/af/init.h new file mode 100644 index 000000000..e351f7f2d --- /dev/null +++ b/tests/af/init.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef AF_INIT_H +#define AF_INIT_H + +#include "ogs-app.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int af_initialize(void); +void af_terminate(void); + +#ifdef __cplusplus +} +#endif + +#endif /* AF_INIT_H */ diff --git a/tests/af/local.c b/tests/af/local.c new file mode 100644 index 000000000..5c56d9c68 --- /dev/null +++ b/tests/af/local.c @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "context.h" + +const char *af_local_get_name(af_local_e id) +{ + switch (id) { + case AF_LOCAL_DISCOVER_AND_SEND: + return "AF_LOCAL_DISCOVER_AND_SEND"; + default: + break; + } + + return "UNKNOWN_LOCAL"; +} + +void af_local_discover_and_send(OpenAPI_nf_type_e target_nf_type, + af_sess_t *sess, void *data, + ogs_sbi_request_t *(*build)(af_sess_t *sess, void *data)) +{ + int rv; + af_event_t *e = NULL; + + e = af_event_new(AF_EVT_SBI_LOCAL); + ogs_assert(e); + + e->local_id = AF_LOCAL_DISCOVER_AND_SEND; + e->sess = sess; + + e->local.target_nf_type = target_nf_type; + e->local.data = data; + e->local.build = build; + + rv = ogs_queue_push(ogs_app()->queue, e); + if (rv != OGS_OK) { + ogs_warn("ogs_queue_push() failed [%d] in %s", + (int)rv, af_timer_get_name(e->timer_id)); + af_event_free(e); + } else { + ogs_pollset_notify(ogs_app()->pollset); + } +} + +void af_local_send_to_pcf( + af_sess_t *sess, void *data, + ogs_sbi_request_t *(*build)(af_sess_t *sess, void *data)) +{ + int rv; + af_event_t *e = NULL; + + e = af_event_new(AF_EVT_SBI_LOCAL); + ogs_assert(e); + + e->local_id = AF_LOCAL_SEND_TO_PCF; + e->sess = sess; + + e->local.data = data; + e->local.build = build; + + rv = ogs_queue_push(ogs_app()->queue, e); + if (rv != OGS_OK) { + ogs_warn("ogs_queue_push() failed [%d] in %s", + (int)rv, af_timer_get_name(e->timer_id)); + af_event_free(e); + } else { + ogs_pollset_notify(ogs_app()->pollset); + } +} diff --git a/tests/af/local.h b/tests/af/local.h new file mode 100644 index 000000000..dc5a04f04 --- /dev/null +++ b/tests/af/local.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef AF_LOCAL_H +#define AF_LOCAL_H + +#include "sbi-path.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* forward declaration */ +typedef enum { + AF_LOCAL_BASE = 0, + + AF_LOCAL_DISCOVER_AND_SEND, + AF_LOCAL_SEND_TO_PCF, + + MAX_NUM_OF_AF_LOCAL, + +} af_local_e; + +const char *af_local_get_name(af_local_e id); + +void af_local_discover_and_send(OpenAPI_nf_type_e target_nf_type, + af_sess_t *sess, void *data, + ogs_sbi_request_t *(*build)(af_sess_t *sess, void *data)); + +void af_local_send_to_pcf( + af_sess_t *sess, void *data, + ogs_sbi_request_t *(*build)(af_sess_t *sess, void *data)); + +#ifdef __cplusplus +} +#endif + +#endif /* AF_LOCAL_H */ diff --git a/tests/af/meson.build b/tests/af/meson.build new file mode 100644 index 000000000..80d1f4b10 --- /dev/null +++ b/tests/af/meson.build @@ -0,0 +1,51 @@ +# Copyright (C) 2019,2020 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +libaf_sources = files(''' + context.c + event.c + timer.c + local.c + + nnrf-build.c + nnrf-handler.c + nf-sm.c + + nbsf-build.c + nbsf-handler.c + + npcf-build.c + npcf-handler.c + + sbi-path.c + af-sm.c + + init.c +'''.split()) + +libaf = static_library('af', + sources : libaf_sources, + dependencies : [libapp_dep, + libcrypt_dep, + libsbi_dep], + install : false) + +libaf_dep = declare_dependency( + link_with : libaf, + dependencies : [libapp_dep, + libcrypt_dep, + libsbi_dep]) diff --git a/tests/af/nbsf-build.c b/tests/af/nbsf-build.c new file mode 100644 index 000000000..ff8c7de01 --- /dev/null +++ b/tests/af/nbsf-build.c @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "nbsf-build.h" + +ogs_sbi_request_t *af_nbsf_management_build_discover( + af_sess_t *sess, void *data) +{ + ogs_sbi_message_t message; + ogs_sbi_request_t *request = NULL; + + ogs_assert(sess); + + memset(&message, 0, sizeof(message)); + message.h.method = (char *)OGS_SBI_HTTP_METHOD_GET; + message.h.service.name = (char *)OGS_SBI_SERVICE_NAME_NBSF_MANAGEMENT; + message.h.api.version = (char *)OGS_SBI_API_V1; + message.h.resource.component[0] = + (char *)OGS_SBI_RESOURCE_NAME_PCF_BINDINGS; + + message.param.ipv4addr = sess->ipv4addr; + message.param.ipv6prefix = sess->ipv6prefix; + + request = ogs_sbi_build_request(&message); + ogs_assert(request); + + return request; +} diff --git a/tests/af/nbsf-build.h b/tests/af/nbsf-build.h new file mode 100644 index 000000000..671a10b16 --- /dev/null +++ b/tests/af/nbsf-build.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef AF_NBSF_BUILD_H +#define AF_NBSF_BUILD_H + +#include "context.h" + +#ifdef __cplusplus +extern "C" { +#endif + +ogs_sbi_request_t *af_nbsf_management_build_discover( + af_sess_t *sess, void *data); + +#ifdef __cplusplus +} +#endif + +#endif /* AF_NBSF_BUILD_H */ diff --git a/tests/af/nbsf-handler.c b/tests/af/nbsf-handler.c new file mode 100644 index 000000000..f2505e411 --- /dev/null +++ b/tests/af/nbsf-handler.c @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "sbi-path.h" +#include "nbsf-handler.h" + +void af_nbsf_management_handle_pcf_binding( + af_sess_t *sess, ogs_sbi_message_t *recvmsg) +{ + int i, rv; + + OpenAPI_pcf_binding_t *PcfBinding = NULL; + OpenAPI_list_t *PcfIpEndPointList = NULL; + OpenAPI_lnode_t *node = NULL; + char fqdn[OGS_MAX_FQDN_LEN]; + + ogs_assert(sess); + ogs_assert(recvmsg); + + PcfBinding = recvmsg->PcfBinding; + ogs_assert(PcfBinding); + + if (!PcfBinding->pcf_fqdn && + !PcfBinding->pcf_ip_end_points) { + ogs_error("No PCF address information [%p:%p]", + PcfBinding->pcf_fqdn, PcfBinding->pcf_ip_end_points); + return; + } + + if (PcfBinding->pcf_fqdn) { + ogs_fqdn_parse(fqdn, + PcfBinding->pcf_fqdn, + strlen(PcfBinding->pcf_fqdn)); + if (sess->pcf.fqdn) + ogs_free(sess->pcf.fqdn); + sess->pcf.fqdn = ogs_strdup(fqdn); + ogs_assert(sess->pcf.fqdn); + } + + PcfIpEndPointList = PcfBinding->pcf_ip_end_points; + + for (i = 0; i < sess->pcf.num_of_ip; i++) { + if (sess->pcf.ip[i].addr) + ogs_freeaddrinfo(sess->pcf.ip[i].addr); + if (sess->pcf.ip[i].addr6) + ogs_freeaddrinfo(sess->pcf.ip[i].addr6); + } + sess->pcf.num_of_ip = 0; + + OpenAPI_list_for_each(PcfIpEndPointList, node) { + OpenAPI_ip_end_point_t *IpEndPoint = node->data; + ogs_sockaddr_t *addr = NULL, *addr6 = NULL; + int port = 0; + + if (!IpEndPoint) continue; + + if (sess->pcf.num_of_ip < OGS_SBI_MAX_NUM_OF_IP_ADDRESS) { + port = IpEndPoint->port; + if (!port) { + if (ogs_sbi_default_uri_scheme() == + OpenAPI_uri_scheme_http) + port = OGS_SBI_HTTP_PORT; + else if (ogs_sbi_default_uri_scheme() == + OpenAPI_uri_scheme_https) + port = OGS_SBI_HTTPS_PORT; + else { + ogs_fatal("Invalid scheme [%d]", + ogs_sbi_default_uri_scheme()); + ogs_assert_if_reached(); + } + } + + if (IpEndPoint->ipv4_address) { + rv = ogs_getaddrinfo(&addr, AF_UNSPEC, + IpEndPoint->ipv4_address, port, 0); + if (rv != OGS_OK) continue; + } + if (IpEndPoint->ipv6_address) { + rv = ogs_getaddrinfo(&addr6, AF_UNSPEC, + IpEndPoint->ipv6_address, port, 0); + if (rv != OGS_OK) continue; + } + + if (addr || addr6) { + sess->pcf.ip[sess->pcf.num_of_ip].port = port; + sess->pcf.ip[sess->pcf.num_of_ip].addr = addr; + sess->pcf.ip[sess->pcf.num_of_ip].addr6 = addr6; + sess->pcf.num_of_ip++; + } + } + } + + if (PcfBinding->supi) { + if (sess->supi) + ogs_free(sess->supi); + sess->supi = ogs_strdup(PcfBinding->supi); + } + if (PcfBinding->gpsi) { + if (sess->gpsi) + ogs_free(sess->gpsi); + sess->gpsi = ogs_strdup(PcfBinding->gpsi); + } + + af_sess_associate_pcf_client(sess); +} diff --git a/tests/af/nbsf-handler.h b/tests/af/nbsf-handler.h new file mode 100644 index 000000000..c413cffe6 --- /dev/null +++ b/tests/af/nbsf-handler.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef AF_NBSF_HANDLER_H +#define AF_NBSF_HANDLER_H + +#include "context.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void af_nbsf_management_handle_pcf_binding( + af_sess_t *sess, ogs_sbi_message_t *recvmsg); + +#ifdef __cplusplus +} +#endif + +#endif /* AF_NBSF_HANDLER_H */ diff --git a/tests/af/nf-sm.c b/tests/af/nf-sm.c new file mode 100644 index 000000000..6bfbbe2d0 --- /dev/null +++ b/tests/af/nf-sm.c @@ -0,0 +1,409 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "context.h" + +#include "sbi-path.h" +#include "nnrf-handler.h" + +void af_nf_fsm_init(ogs_sbi_nf_instance_t *nf_instance) +{ + af_event_t e; + + ogs_assert(nf_instance); + + memset(&e, 0, sizeof(e)); + e.sbi.data = nf_instance; + + ogs_fsm_create(&nf_instance->sm, + af_nf_state_initial, af_nf_state_final); + ogs_fsm_init(&nf_instance->sm, &e); +} + +void af_nf_fsm_fini(ogs_sbi_nf_instance_t *nf_instance) +{ + af_event_t e; + + ogs_assert(nf_instance); + + memset(&e, 0, sizeof(e)); + e.sbi.data = nf_instance; + + ogs_fsm_fini(&nf_instance->sm, &e); + ogs_fsm_delete(&nf_instance->sm); +} + +void af_nf_state_initial(ogs_fsm_t *s, af_event_t *e) +{ + ogs_sbi_nf_instance_t *nf_instance = NULL; + + ogs_assert(s); + ogs_assert(e); + + af_sm_debug(e); + + nf_instance = e->sbi.data; + ogs_assert(nf_instance); + ogs_assert(nf_instance->id); + + ogs_assert(nf_instance->t_registration_interval); + nf_instance->t_registration_interval->cb = + af_timer_nf_instance_registration_interval; + ogs_assert(nf_instance->t_heartbeat_interval); + nf_instance->t_heartbeat_interval->cb = + af_timer_nf_instance_heartbeat_interval; + ogs_assert(nf_instance->t_no_heartbeat); + nf_instance->t_no_heartbeat->cb = af_timer_nf_instance_no_heartbeat; + ogs_assert(nf_instance->t_validity); + nf_instance->t_validity->cb = af_timer_nf_instance_validity; + + if (NF_INSTANCE_IS_SELF(nf_instance->id)) { + OGS_FSM_TRAN(s, &af_nf_state_will_register); + } else { + OGS_FSM_TRAN(s, &af_nf_state_registered); + } +} + +void af_nf_state_final(ogs_fsm_t *s, af_event_t *e) +{ + ogs_assert(s); + ogs_assert(e); + + af_sm_debug(e); +} + +void af_nf_state_will_register(ogs_fsm_t *s, af_event_t *e) +{ + ogs_sbi_nf_instance_t *nf_instance = NULL; + ogs_sbi_client_t *client = NULL; + ogs_sbi_message_t *message = NULL; + ogs_sockaddr_t *addr = NULL; + + ogs_assert(s); + ogs_assert(e); + + af_sm_debug(e); + + nf_instance = e->sbi.data; + ogs_assert(nf_instance); + + switch (e->id) { + case OGS_FSM_ENTRY_SIG: + if (NF_INSTANCE_IS_SELF(nf_instance->id)) + ogs_timer_start(nf_instance->t_registration_interval, + ogs_app()->time.message.sbi.nf_register_interval); + + af_nnrf_nfm_send_nf_register(nf_instance); + break; + + case OGS_FSM_EXIT_SIG: + if (NF_INSTANCE_IS_SELF(nf_instance->id)) + ogs_timer_stop(nf_instance->t_registration_interval); + break; + + case AF_EVT_SBI_CLIENT: + message = e->sbi.message; + ogs_assert(message); + + SWITCH(message->h.service.name) + CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) + + SWITCH(message->h.resource.component[0]) + CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) + + if (message->res_status == OGS_SBI_HTTP_STATUS_OK || + message->res_status == OGS_SBI_HTTP_STATUS_CREATED) { + af_nnrf_handle_nf_register(nf_instance, message); + OGS_FSM_TRAN(s, &af_nf_state_registered); + } else { + ogs_error("[%s] HTTP Response Status Code [%d]", + nf_instance->id, message->res_status); + OGS_FSM_TRAN(s, &af_nf_state_exception); + } + break; + + DEFAULT + ogs_error("[%s] Invalid resource name [%s]", + nf_instance->id, message->h.resource.component[0]); + END + break; + + DEFAULT + ogs_error("[%s] Invalid API name [%s]", + nf_instance->id, message->h.service.name); + END + break; + + case AF_EVT_SBI_TIMER: + switch(e->timer_id) { + case AF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: + client = nf_instance->client; + ogs_assert(client); + addr = client->node.addr; + ogs_assert(addr); + + ogs_warn("[%s] Retry to registration with NRF", nf_instance->id); + + if (NF_INSTANCE_IS_SELF(nf_instance->id)) + ogs_timer_start(nf_instance->t_registration_interval, + ogs_app()->time.message.sbi.nf_register_interval); + + af_nnrf_nfm_send_nf_register(nf_instance); + break; + + default: + ogs_error("[%s] Unknown timer[%s:%d]", nf_instance->id, + af_timer_get_name(e->timer_id), e->timer_id); + } + break; + + default: + ogs_error("[%s] Unknown event %s", + nf_instance->id, af_event_get_name(e)); + break; + } +} + +void af_nf_state_registered(ogs_fsm_t *s, af_event_t *e) +{ + ogs_sbi_nf_instance_t *nf_instance = NULL; + ogs_sbi_client_t *client = NULL; + ogs_sbi_message_t *message = NULL; + ogs_assert(s); + ogs_assert(e); + + af_sm_debug(e); + + nf_instance = e->sbi.data; + ogs_assert(nf_instance); + + switch (e->id) { + case OGS_FSM_ENTRY_SIG: + if (NF_INSTANCE_IS_SELF(nf_instance->id)) { + ogs_info("[%s] NF registred [Heartbeat:%ds]", + nf_instance->id, nf_instance->time.heartbeat_interval); + + client = nf_instance->client; + ogs_assert(client); + + if (nf_instance->time.heartbeat_interval) { + ogs_timer_start(nf_instance->t_heartbeat_interval, + ogs_time_from_sec(nf_instance->time.heartbeat_interval)); + ogs_timer_start(nf_instance->t_no_heartbeat, + ogs_time_from_sec( + nf_instance->time.heartbeat_interval + + ogs_app()->time.nf_instance.no_heartbeat_margin)); + } + + ogs_nnrf_nfm_send_nf_status_subscribe(client, + af_self()->nf_type, nf_instance->id, OpenAPI_nf_type_BSF); + } + + break; + + case OGS_FSM_EXIT_SIG: + if (NF_INSTANCE_IS_SELF(nf_instance->id)) { + ogs_info("[%s] NF de-registered", nf_instance->id); + + if (nf_instance->time.heartbeat_interval) { + ogs_timer_stop(nf_instance->t_heartbeat_interval); + ogs_timer_stop(nf_instance->t_no_heartbeat); + } + + if (!OGS_FSM_CHECK(&nf_instance->sm, af_nf_state_exception)) { + ogs_nnrf_nfm_send_nf_de_register(nf_instance); + } + } + break; + + case AF_EVT_SBI_CLIENT: + message = e->sbi.message; + ogs_assert(message); + + SWITCH(message->h.service.name) + CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) + + SWITCH(message->h.resource.component[0]) + CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) + + if (message->res_status == OGS_SBI_HTTP_STATUS_NO_CONTENT || + message->res_status == OGS_SBI_HTTP_STATUS_OK) { + if (nf_instance->time.heartbeat_interval) + ogs_timer_start(nf_instance->t_no_heartbeat, + ogs_time_from_sec( + nf_instance->time.heartbeat_interval + + ogs_app()->time.nf_instance. + no_heartbeat_margin)); + } else { + ogs_warn("[%s] HTTP response error [%d]", + nf_instance->id, message->res_status); + OGS_FSM_TRAN(s, &af_nf_state_exception); + } + + break; + + DEFAULT + ogs_error("[%s] Invalid resource name [%s]", + nf_instance->id, message->h.resource.component[0]); + END + break; + + DEFAULT + ogs_error("[%s] Invalid API name [%s]", + nf_instance->id, message->h.service.name); + END + break; + + case AF_EVT_SBI_TIMER: + switch(e->timer_id) { + case AF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: + if (nf_instance->time.heartbeat_interval) + ogs_timer_start(nf_instance->t_heartbeat_interval, + ogs_time_from_sec(nf_instance->time.heartbeat_interval)); + + ogs_nnrf_nfm_send_nf_update(nf_instance); + break; + + case AF_TIMER_NF_INSTANCE_NO_HEARTBEAT: + ogs_error("[%s] No heartbeat", nf_instance->id); + OGS_FSM_TRAN(s, &af_nf_state_will_register); + break; + + case AF_TIMER_NF_INSTANCE_VALIDITY: + if (NF_INSTANCE_IS_OTHERS(nf_instance->id)) { + ogs_info("[%s] NF expired", nf_instance->id); + OGS_FSM_TRAN(s, &af_nf_state_de_registered); + } + break; + + default: + ogs_error("[%s] Unknown timer[%s:%d]", nf_instance->id, + af_timer_get_name(e->timer_id), e->timer_id); + break; + } + break; + + default: + ogs_error("[%s] Unknown event %s", + nf_instance->id, af_event_get_name(e)); + break; + } +} + +void af_nf_state_de_registered(ogs_fsm_t *s, af_event_t *e) +{ + ogs_sbi_nf_instance_t *nf_instance = NULL; + ogs_assert(s); + ogs_assert(e); + + af_sm_debug(e); + + nf_instance = e->sbi.data; + ogs_assert(nf_instance); + + switch (e->id) { + case OGS_FSM_ENTRY_SIG: + if (NF_INSTANCE_IS_SELF(nf_instance->id)) { + ogs_info("[%s] NF de-registered", nf_instance->id); + } + break; + + case OGS_FSM_EXIT_SIG: + break; + + default: + ogs_error("[%s] Unknown event %s", + nf_instance->id, af_event_get_name(e)); + break; + } +} + +void af_nf_state_exception(ogs_fsm_t *s, af_event_t *e) +{ + ogs_sbi_nf_instance_t *nf_instance = NULL; + ogs_sbi_client_t *client = NULL; + ogs_sbi_message_t *message = NULL; + ogs_sockaddr_t *addr = NULL; + ogs_assert(s); + ogs_assert(e); + + af_sm_debug(e); + + nf_instance = e->sbi.data; + ogs_assert(nf_instance); + + switch (e->id) { + case OGS_FSM_ENTRY_SIG: + if (NF_INSTANCE_IS_SELF(nf_instance->id)) + ogs_timer_start(nf_instance->t_registration_interval, + ogs_app()->time.message.sbi. + nf_register_interval_in_exception); + break; + + case OGS_FSM_EXIT_SIG: + if (NF_INSTANCE_IS_SELF(nf_instance->id)) + ogs_timer_stop(nf_instance->t_registration_interval); + break; + + case AF_EVT_SBI_TIMER: + switch(e->timer_id) { + case AF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: + client = nf_instance->client; + ogs_assert(client); + addr = client->node.addr; + ogs_assert(addr); + + ogs_warn("[%s] Retry to registration with NRF", nf_instance->id); + + OGS_FSM_TRAN(s, &af_nf_state_will_register); + break; + + default: + ogs_error("[%s] Unknown timer[%s:%d]", nf_instance->id, + af_timer_get_name(e->timer_id), e->timer_id); + break; + } + break; + + case AF_EVT_SBI_CLIENT: + message = e->sbi.message; + ogs_assert(message); + + SWITCH(message->h.service.name) + CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) + + SWITCH(message->h.resource.component[0]) + CASE(OGS_SBI_RESOURCE_NAME_NF_INSTANCES) + break; + DEFAULT + ogs_error("Invalid resource name [%s]", + message->h.resource.component[0]); + END + break; + DEFAULT + ogs_error("Invalid API name [%s]", message->h.service.name); + END + break; + + default: + ogs_error("[%s] Unknown event %s", + nf_instance->id, af_event_get_name(e)); + break; + } +} diff --git a/tests/af/nnrf-build.c b/tests/af/nnrf-build.c new file mode 100644 index 000000000..001a1d410 --- /dev/null +++ b/tests/af/nnrf-build.c @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "nnrf-build.h" + +ogs_sbi_request_t *af_nnrf_nfm_build_register( + ogs_sbi_nf_instance_t *nf_instance) +{ + ogs_sbi_message_t message; + ogs_sbi_request_t *request = NULL; + ogs_sbi_client_t *client = NULL; + + OpenAPI_nf_profile_t *NFProfile = NULL; + + ogs_assert(nf_instance); + client = nf_instance->client; + ogs_assert(client); + + memset(&message, 0, sizeof(message)); + message.h.method = (char *)OGS_SBI_HTTP_METHOD_PUT; + message.h.service.name = (char *)OGS_SBI_SERVICE_NAME_NNRF_NFM; + message.h.api.version = (char *)OGS_SBI_API_V1; + message.h.resource.component[0] = + (char *)OGS_SBI_RESOURCE_NAME_NF_INSTANCES; + message.h.resource.component[1] = ogs_sbi_self()->nf_instance_id; + + message.http.content_encoding = (char*)ogs_sbi_self()->content_encoding; + + NFProfile = ogs_nnrf_nfm_build_nf_profile(nf_instance); + ogs_assert(NFProfile); + + message.NFProfile = NFProfile; + + request = ogs_sbi_build_request(&message); + + ogs_sbi_nnrf_free_nf_profile(NFProfile); + + return request; +} diff --git a/tests/af/nnrf-build.h b/tests/af/nnrf-build.h new file mode 100644 index 000000000..1e2814ed5 --- /dev/null +++ b/tests/af/nnrf-build.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef AF_NNRF_BUILD_H +#define AF_NNRF_BUILD_H + +#include "context.h" + +#ifdef __cplusplus +extern "C" { +#endif + +ogs_sbi_request_t *af_nnrf_nfm_build_register( + ogs_sbi_nf_instance_t *nf_instance); + +#ifdef __cplusplus +} +#endif + +#endif /* AF_NNRF_BUILD_H */ diff --git a/tests/af/nnrf-handler.c b/tests/af/nnrf-handler.c new file mode 100644 index 000000000..7d8377fe5 --- /dev/null +++ b/tests/af/nnrf-handler.c @@ -0,0 +1,335 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "sbi-path.h" +#include "nnrf-handler.h" + +void af_nnrf_handle_nf_register( + ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_message_t *recvmsg) +{ + OpenAPI_nf_profile_t *NFProfile = NULL; + ogs_sbi_client_t *client = NULL; + + ogs_assert(recvmsg); + ogs_assert(nf_instance); + client = nf_instance->client; + ogs_assert(client); + + NFProfile = recvmsg->NFProfile; + if (!NFProfile) { + ogs_error("No NFProfile"); + return; + } + + /* TIME : Update heartbeat from NRF */ + if (NFProfile->nf_profile_changes_ind == true) { + if (NFProfile->heart_beat_timer) + nf_instance->time.heartbeat_interval = NFProfile->heart_beat_timer; + } else { + nf_instance->time.heartbeat_interval = NFProfile->heart_beat_timer; + } +} + +void af_nnrf_handle_nf_status_subscribe( + ogs_sbi_subscription_t *subscription, ogs_sbi_message_t *recvmsg) +{ + OpenAPI_subscription_data_t *SubscriptionData = NULL; + ogs_sbi_client_t *client = NULL; + + ogs_assert(recvmsg); + ogs_assert(subscription); + client = subscription->client; + ogs_assert(client); + + SubscriptionData = recvmsg->SubscriptionData; + if (!SubscriptionData) { + ogs_error("No SubscriptionData"); + return; + } + + if (!SubscriptionData->subscription_id) { + ogs_error("No SubscriptionId"); + return; + } + ogs_sbi_subscription_set_id( + subscription, SubscriptionData->subscription_id); + + if (SubscriptionData->validity_time) { +#define VALIDITY_MINIMUM (10LL * OGS_USEC_PER_SEC) /* 10 seconds */ + ogs_time_t time, duration; + if (ogs_sbi_time_from_string( + &time, SubscriptionData->validity_time) == true) { + duration = time - ogs_time_now(); + if (duration < VALIDITY_MINIMUM) { + duration = VALIDITY_MINIMUM; + ogs_warn("[%s] Forced to %lld seconds", subscription->id, + (long long)ogs_time_sec(VALIDITY_MINIMUM)); + } + subscription->t_validity = ogs_timer_add(ogs_app()->timer_mgr, + af_timer_subscription_validity, subscription); + ogs_assert(subscription->t_validity); + ogs_timer_start(subscription->t_validity, duration); + } else { + ogs_error("Cannot parse validitiyTime [%s]", + SubscriptionData->validity_time); + } + } +} + +bool af_nnrf_handle_nf_status_notify( + ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) +{ + int rv; + bool handled; + + ogs_sbi_response_t *response = NULL; + OpenAPI_notification_data_t *NotificationData = NULL; + ogs_sbi_nf_instance_t *nf_instance = NULL; + + ogs_sbi_message_t message; + ogs_sbi_header_t header; + + ogs_assert(stream); + ogs_assert(recvmsg); + + NotificationData = recvmsg->NotificationData; + if (!NotificationData) { + ogs_error("No NotificationData"); + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + recvmsg, "No NotificationData", NULL); + return false; + } + + if (!NotificationData->nf_instance_uri) { + ogs_error("No nfInstanceUri"); + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + recvmsg, "No nfInstanceUri", NULL); + return false; + } + + memset(&header, 0, sizeof(header)); + header.uri = NotificationData->nf_instance_uri; + + rv = ogs_sbi_parse_header(&message, &header); + if (rv != OGS_OK) { + ogs_error("Cannot parse nfInstanceUri [%s]", header.uri); + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + recvmsg, "Cannot parse nfInstanceUri", header.uri); + return false; + } + + if (!message.h.resource.component[1]) { + ogs_error("No nfInstanceId [%s]", header.uri); + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + recvmsg, "Cannot parse nfInstanceUri", header.uri); + ogs_sbi_header_free(&header); + return false; + } + + if (NF_INSTANCE_IS_SELF(message.h.resource.component[1])) { + ogs_warn("[%s] The notification is not allowed", + message.h.resource.component[1]); + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, + recvmsg, "The notification is not allowed", + message.h.resource.component[1]); + ogs_sbi_header_free(&header); + return false; + } + + if (NotificationData->event == + OpenAPI_notification_event_type_NF_REGISTERED) { + + OpenAPI_nf_profile_t *NFProfile = NULL; + + NFProfile = NotificationData->nf_profile; + if (!NFProfile) { + ogs_error("No NFProfile"); + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + recvmsg, "No NFProfile", NULL); + ogs_sbi_header_free(&header); + return false; + } + + nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); + if (!nf_instance) { + nf_instance = ogs_sbi_nf_instance_add( + message.h.resource.component[1]); + ogs_assert(nf_instance); + + af_nf_fsm_init(nf_instance); + + ogs_info("[%s] (NRF-notify) NF registered", nf_instance->id); + + } else { + OGS_FSM_TRAN(&nf_instance->sm, af_nf_state_registered); + ogs_fsm_dispatch(&nf_instance->sm, NULL); + + ogs_warn("[%s] (NRF-notify) NF has already been added", + message.h.resource.component[1]); + + } + + handled = ogs_sbi_nnrf_handle_nf_profile( + nf_instance, NFProfile, stream, recvmsg); + if (!handled) { + AF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); + ogs_sbi_header_free(&header); + return false; + } + + ogs_info("[%s] (NRF-notify) NF Profile updated", nf_instance->id); + + handled = ogs_sbi_client_associate(nf_instance); + if (!handled) { + ogs_error("[%s] Cannot associate NF EndPoint", nf_instance->id); + ogs_sbi_server_send_error(stream, + OGS_SBI_HTTP_STATUS_BAD_REQUEST, + recvmsg, "Cannot find NF EndPoint", nf_instance->id); + AF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); + ogs_sbi_header_free(&header); + return false; + } + + } else if (NotificationData->event == + OpenAPI_notification_event_type_NF_DEREGISTERED) { + nf_instance = ogs_sbi_nf_instance_find(message.h.resource.component[1]); + if (nf_instance) { + AF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); + } else { + ogs_warn("[%s] (NRF-notify) Not found", + message.h.resource.component[1]); + ogs_sbi_server_send_error(stream, + OGS_SBI_HTTP_STATUS_NOT_FOUND, + recvmsg, "Not found", message.h.resource.component[1]); + ogs_sbi_header_free(&header); + return false; + } + } else { + char *eventstr = OpenAPI_notification_event_type_ToString( + NotificationData->event); + ogs_error("Not supported event [%d:%s]", + NotificationData->event, eventstr ? eventstr : "Unknown"); + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + recvmsg, "Not supported event", + eventstr ? eventstr : "Unknown"); + ogs_sbi_header_free(&header); + return false; + } + + response = ogs_sbi_build_response(recvmsg, OGS_SBI_HTTP_STATUS_NO_CONTENT); + ogs_assert(response); + ogs_sbi_server_send_response(stream, response); + + ogs_sbi_header_free(&header); + return true; +} + +void af_nnrf_handle_nf_discover( + ogs_sbi_xact_t *xact, ogs_sbi_message_t *recvmsg) +{ + ogs_sbi_object_t *sbi_object = NULL; + ogs_sbi_nf_instance_t *nf_instance = NULL; + + OpenAPI_search_result_t *SearchResult = NULL; + OpenAPI_lnode_t *node = NULL; + bool handled; + + ogs_assert(xact); + sbi_object = xact->sbi_object; + ogs_assert(sbi_object); + ogs_assert(recvmsg); + + SearchResult = recvmsg->SearchResult; + if (!SearchResult) { + ogs_error("No SearchResult"); + return; + } + + OpenAPI_list_for_each(SearchResult->nf_instances, node) { + OpenAPI_nf_profile_t *NFProfile = NULL; + + if (!node->data) continue; + + NFProfile = node->data; + + nf_instance = ogs_sbi_nf_instance_find(NFProfile->nf_instance_id); + if (!nf_instance) { + nf_instance = ogs_sbi_nf_instance_add(NFProfile->nf_instance_id); + ogs_assert(nf_instance); + + af_nf_fsm_init(nf_instance); + + ogs_info("[%s] (NF-discover) NF registered", nf_instance->id); + } else { + OGS_FSM_TRAN(&nf_instance->sm, af_nf_state_registered); + ogs_fsm_dispatch(&nf_instance->sm, NULL); + + ogs_warn("[%s] (NF-discover) NF has already been added", + NFProfile->nf_instance_id); + } + + if (NF_INSTANCE_IS_OTHERS(nf_instance->id)) { + af_sess_t *sess = NULL; + + handled = ogs_sbi_nnrf_handle_nf_profile( + nf_instance, NFProfile, NULL, NULL); + if (!handled) { + ogs_error("ogs_sbi_nnrf_handle_nf_profile() failed [%s]", + nf_instance->id); + AF_NF_INSTANCE_CLEAR("NRF-discover", nf_instance); + continue; + } + + handled = ogs_sbi_client_associate(nf_instance); + if (!handled) { + ogs_error("[%s] Cannot assciate NF EndPoint", nf_instance->id); + AF_NF_INSTANCE_CLEAR("NRF-discover", nf_instance); + continue; + } + + sess = (af_sess_t *)sbi_object; + ogs_assert(sess); + af_sess_select_nf(sess, nf_instance->nf_type); + + /* TIME : Update validity from NRF */ + if (SearchResult->validity_period) { + nf_instance->time.validity_duration = + SearchResult->validity_period; + + ogs_assert(nf_instance->t_validity); + ogs_timer_start(nf_instance->t_validity, + ogs_time_from_sec(nf_instance->time.validity_duration)); + + } else + ogs_warn("[%s] NF Instance validity-time should not 0", + nf_instance->id); + + ogs_info("[%s] (NF-discover) NF Profile updated", nf_instance->id); + } + } + + ogs_assert(xact->target_nf_type); + nf_instance = OGS_SBI_NF_INSTANCE(sbi_object, xact->target_nf_type); + if (!nf_instance) { + ogs_error("(NF discover) No [%s]", + OpenAPI_nf_type_ToString(xact->target_nf_type)); + } else { + af_sbi_send(nf_instance, xact); + } +} diff --git a/tests/af/nnrf-handler.h b/tests/af/nnrf-handler.h new file mode 100644 index 000000000..b666a7abc --- /dev/null +++ b/tests/af/nnrf-handler.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef AF_NNRF_HANDLER_H +#define AF_NNRF_HANDLER_H + +#include "context.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void af_nnrf_handle_nf_register( + ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_message_t *recvmsg); +void af_nnrf_handle_nf_status_subscribe( + ogs_sbi_subscription_t *subscription, ogs_sbi_message_t *recvmsg); + +bool af_nnrf_handle_nf_status_notify( + ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); + +void af_nnrf_handle_nf_discover( + ogs_sbi_xact_t *xact, ogs_sbi_message_t *recvmsg); + +#ifdef __cplusplus +} +#endif + +#endif /* AF_NNRF_HANDLER_H */ diff --git a/tests/af/npcf-build.c b/tests/af/npcf-build.c new file mode 100644 index 000000000..291c1752b --- /dev/null +++ b/tests/af/npcf-build.c @@ -0,0 +1,264 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "npcf-build.h" + +ogs_sbi_request_t *af_npcf_policyauthorization_build_create( + af_sess_t *sess, void *data) +{ + ogs_sbi_message_t message; + ogs_sbi_request_t *request = NULL; + ogs_sbi_server_t *server = NULL; + ogs_sbi_header_t header; + + OpenAPI_app_session_context_t AppSessionContext; + OpenAPI_app_session_context_req_data_t AscReqData; + OpenAPI_snssai_t sNssai; + + OpenAPI_list_t *MediaComponentList = NULL; + OpenAPI_map_t *MediaComponentMap = NULL; + OpenAPI_media_component_t *MediaComponent = NULL; + + OpenAPI_list_t *SubComponentList = NULL; + OpenAPI_map_t *SubComponentMap = NULL; + OpenAPI_media_sub_component_t *SubComponent = NULL; + + OpenAPI_list_t *fDescList = NULL; + OpenAPI_list_t *codecList = NULL; + + int i, j; + OpenAPI_lnode_t *node = NULL, *node2 = NULL, *node3 = NULL; + + ogs_assert(sess); + ogs_assert(sess->af_app_session_id); + + memset(&message, 0, sizeof(message)); + message.h.method = (char *)OGS_SBI_HTTP_METHOD_POST; + message.h.service.name = + (char *)OGS_SBI_SERVICE_NAME_NPCF_POLICYAUTHORIZATION; + message.h.api.version = (char *)OGS_SBI_API_V1; + message.h.resource.component[0] = + (char *)OGS_SBI_RESOURCE_NAME_APP_SESSIONS; + + message.AppSessionContext = &AppSessionContext; + + memset(&AppSessionContext, 0, sizeof(AppSessionContext)); + AppSessionContext.asc_req_data = &AscReqData; + + memset(&AscReqData, 0, sizeof(AscReqData)); + + server = ogs_list_first(&ogs_sbi_self()->server_list); + ogs_assert(server); + + memset(&header, 0, sizeof(header)); + header.service.name = (char *)OGS_SBI_SERVICE_NAME_NPCF_POLICYAUTHORIZATION; + header.api.version = (char *)OGS_SBI_API_V1; + header.resource.component[0] = (char *)OGS_SBI_RESOURCE_NAME_APP_SESSIONS; + header.resource.component[1] = (char *)sess->af_app_session_id; + header.resource.component[2] = (char *)OGS_SBI_RESOURCE_NAME_NOTIFY; + AscReqData.notif_uri = ogs_sbi_server_uri(server, &header); + ogs_assert(AscReqData.notif_uri); + + AscReqData.supp_feat = + ogs_uint64_to_string(sess->policyauthorization_features); + ogs_assert(AscReqData.supp_feat); + + AscReqData.ue_ipv4 = sess->ipv4addr; + AscReqData.ue_ipv6 = sess->ipv6addr; + + AscReqData.dnn = sess->dnn; + + memset(&sNssai, 0, sizeof(sNssai)); + if (sess->s_nssai.sst) { + sNssai.sst = sess->s_nssai.sst; + sNssai.sd = ogs_s_nssai_sd_to_string(sess->s_nssai.sd); + AscReqData.slice_info = &sNssai; + } + + AscReqData.supi = sess->supi; + AscReqData.gpsi = sess->gpsi; + + AscReqData.af_app_id = (char *)"IMS Services"; + AscReqData.res_prio = OpenAPI_reserv_priority_PRIO_1; + + /* Media Component */ + i = 0, j = 0; + + MediaComponentList = OpenAPI_list_create(); + ogs_assert(MediaComponentList); + + MediaComponent = ogs_calloc(1, sizeof(*MediaComponent)); + ogs_assert(MediaComponent); + + MediaComponent->med_comp_n = (++i); + MediaComponent->f_status = OpenAPI_flow_status_ENABLED; + MediaComponent->mar_bw_dl = ogs_sbi_bitrate_to_string( + 41000, OGS_SBI_BITRATE_KBPS); + MediaComponent->mar_bw_ul = ogs_sbi_bitrate_to_string( + 41000, OGS_SBI_BITRATE_KBPS); + MediaComponent->med_type = OpenAPI_media_type_AUDIO; + MediaComponent->rr_bw = ogs_sbi_bitrate_to_string( + 2000, OGS_SBI_BITRATE_BPS); + MediaComponent->rs_bw = ogs_sbi_bitrate_to_string( + 600, OGS_SBI_BITRATE_BPS); + + /* Codec */ + codecList = OpenAPI_list_create(); + ogs_assert(codecList); + OpenAPI_list_add(codecList, + ogs_strdup("downlink\noffer\n" + "m=audio 49000 RTP/AVP 116 99 97 105 100\r\nb=AS:41\r\n" + "b=RS:512\r\nb=RR:1537\r\na=maxptime:240\r\n" + "a=des:qos mandatory local sendrecv\r\na=curr:qos local none\r\n" + "a=des:qos option")); + OpenAPI_list_add(codecList, + ogs_strdup("uplink\nanswer\nm=audio 50020 RTP/AVP 99 105\r\n" + "b=AS:41\r\nb=RS:600\r\nb=RR:2000\r\na=rtpmap:99 AMR-WB/16000/1\r\n" + "a=fmtp:99 mode-change-capability=2;max-red=0\r\n" + "a=rtpmap:105 telephone-event/16")); + ogs_assert(codecList->count); + MediaComponent->codecs = codecList; + + MediaComponentMap = OpenAPI_map_create( + ogs_msprintf("%d", MediaComponent->med_comp_n), MediaComponent); + ogs_assert(MediaComponentMap); + + OpenAPI_list_add(MediaComponentList, MediaComponentMap); + + ogs_assert(MediaComponentList->count); + AscReqData.med_components = MediaComponentList; + + /* Sub Component */ + SubComponentList = OpenAPI_list_create(); + ogs_assert(SubComponentList); + + /* Sub Component #1 */ + SubComponent = ogs_calloc(1, sizeof(*SubComponent)); + ogs_assert(SubComponent); + + SubComponent->f_num = (++j); + SubComponent->flow_usage = OpenAPI_flow_usage_NO_INFO; + + SubComponentMap = OpenAPI_map_create( + ogs_msprintf("%d", SubComponent->f_num), SubComponent); + ogs_assert(SubComponentMap); + + OpenAPI_list_add(SubComponentList, SubComponentMap); + + /* Flow Description */ + fDescList = OpenAPI_list_create(); + ogs_assert(fDescList); + OpenAPI_list_add(fDescList, + ogs_strdup("permit out 17 from 172.20.166.84 to 10.45.0.2 20001")); + OpenAPI_list_add(fDescList, + ogs_strdup("permit in 17 from 10.45.0.2 to 172.20.166.84 20360")); + ogs_assert(fDescList->count); + SubComponent->f_descs = fDescList; + + /* Sub Component #2 */ + SubComponent = ogs_calloc(1, sizeof(*SubComponent)); + ogs_assert(SubComponent); + + SubComponent->f_num = (++j); + SubComponent->flow_usage = OpenAPI_flow_usage_NO_INFO; + + SubComponentMap = OpenAPI_map_create( + ogs_msprintf("%d", SubComponent->f_num), SubComponent); + ogs_assert(SubComponentMap); + + OpenAPI_list_add(SubComponentList, SubComponentMap); + + /* Flow Description */ + fDescList = OpenAPI_list_create(); + ogs_assert(fDescList); + OpenAPI_list_add(fDescList, + ogs_strdup("permit out 17 from 172.20.166.84 to 10.45.0.2 20002")); + OpenAPI_list_add(fDescList, + ogs_strdup("permit in 17 from 10.45.0.2 to 172.20.166.84 20361")); + ogs_assert(fDescList->count); + SubComponent->f_descs = fDescList; + + ogs_assert(SubComponentList->count); + MediaComponent->med_sub_comps = SubComponentList; + + request = ogs_sbi_build_request(&message); + ogs_assert(request); + + ogs_free(AscReqData.notif_uri); + + ogs_free(AscReqData.supp_feat); + + if (sNssai.sd) + ogs_free(sNssai.sd); + + MediaComponentList = AscReqData.med_components; + OpenAPI_list_for_each(MediaComponentList, node) { + MediaComponentMap = node->data; + if (MediaComponentMap) { + MediaComponent = MediaComponentMap->value; + if (MediaComponent) { + + if (MediaComponent->mar_bw_dl) + ogs_free(MediaComponent->mar_bw_dl); + if (MediaComponent->mar_bw_ul) + ogs_free(MediaComponent->mar_bw_ul); + if (MediaComponent->rr_bw) + ogs_free(MediaComponent->rr_bw); + if (MediaComponent->rs_bw) + ogs_free(MediaComponent->rs_bw); + + codecList = MediaComponent->codecs; + OpenAPI_list_for_each(codecList, node2) { + if (node2->data) ogs_free(node2->data); + } + OpenAPI_list_free(codecList); + + SubComponentList = MediaComponent->med_sub_comps; + OpenAPI_list_for_each(SubComponentList, node2) { + SubComponentMap = node2->data; + if (SubComponentMap) { + SubComponent = SubComponentMap->value; + if (SubComponent) { + + fDescList = SubComponent->f_descs; + OpenAPI_list_for_each(fDescList, node3) { + if (node3->data) ogs_free(node3->data); + } + OpenAPI_list_free(fDescList); + + ogs_free(SubComponent); + } + if (SubComponentMap->key) + ogs_free(SubComponentMap->key); + ogs_free(SubComponentMap); + } + } + OpenAPI_list_free(SubComponentList); + + ogs_free(MediaComponent); + } + if (MediaComponentMap->key) + ogs_free(MediaComponentMap->key); + ogs_free(MediaComponentMap); + } + } + OpenAPI_list_free(MediaComponentList); + + return request; +} diff --git a/tests/af/npcf-build.h b/tests/af/npcf-build.h new file mode 100644 index 000000000..8243551b8 --- /dev/null +++ b/tests/af/npcf-build.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef AF_NPCF_BUILD_H +#define AF_NPCF_BUILD_H + +#include "context.h" + +#ifdef __cplusplus +extern "C" { +#endif + +ogs_sbi_request_t *af_npcf_policyauthorization_build_create( + af_sess_t *sess, void *data); + +#ifdef __cplusplus +} +#endif + +#endif /* AF_NPCF_BUILD_H */ diff --git a/tests/af/npcf-handler.c b/tests/af/npcf-handler.c new file mode 100644 index 000000000..1764a0ec9 --- /dev/null +++ b/tests/af/npcf-handler.c @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "sbi-path.h" +#include "npcf-handler.h" + +void af_npcf_policyauthorization_handle_create( + af_sess_t *sess, ogs_sbi_message_t *recvmsg) +{ + int rv; + + ogs_sbi_message_t message; + ogs_sbi_header_t header; + + if (!recvmsg->http.location) { + ogs_error("[%s:%s] No http.location", + sess->ipv4addr ? sess->ipv4addr : "Unknown", + sess->ipv6addr ? sess->ipv6addr : "Unknown"); + return; + } + + memset(&header, 0, sizeof(header)); + header.uri = recvmsg->http.location; + + rv = ogs_sbi_parse_header(&message, &header); + if (rv != OGS_OK) { + ogs_error("[%s:%s] Cannot parse http.location [%s]", + sess->ipv4addr ? sess->ipv4addr : "Unknown", + sess->ipv6addr ? sess->ipv6addr : "Unknown", + recvmsg->http.location); + return; + } + + if (!message.h.resource.component[1]) { + ogs_error("[%s:%s] No AppSessionId[%s]", + sess->ipv4addr ? sess->ipv4addr : "Unknown", + sess->ipv6addr ? sess->ipv6addr : "Unknown", + recvmsg->http.location); + + ogs_sbi_header_free(&header); + return; + } + + af_sess_set_pcf_app_session_id(sess, message.h.resource.component[1]); + + ogs_sbi_header_free(&header); +} diff --git a/tests/af/npcf-handler.h b/tests/af/npcf-handler.h new file mode 100644 index 000000000..d7251b311 --- /dev/null +++ b/tests/af/npcf-handler.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef AF_NPCF_HANDLER_H +#define AF_NPCF_HANDLER_H + +#include "context.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void af_npcf_policyauthorization_handle_create( + af_sess_t *sess, ogs_sbi_message_t *recvmsg); + +#ifdef __cplusplus +} +#endif + +#endif /* AF_NPCF_HANDLER_H */ diff --git a/tests/af/sbi-path.c b/tests/af/sbi-path.c new file mode 100644 index 000000000..980302319 --- /dev/null +++ b/tests/af/sbi-path.c @@ -0,0 +1,179 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "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(AF_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) { + ogs_warn("ogs_queue_push() failed:%d", (int)rv); + af_event_free(e); + return OGS_ERROR; + } + + return OGS_OK; +} + +static int client_cb(ogs_sbi_response_t *response, void *data) +{ + af_event_t *e = NULL; + int rv; + + ogs_assert(response); + + e = af_event_new(AF_EVT_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_warn("ogs_queue_push() failed:%d", (int)rv); + af_event_free(e); + return OGS_ERROR; + } + + return OGS_OK; +} + +int af_sbi_open(void) +{ + ogs_sbi_nf_instance_t *nf_instance = NULL; + + if (ogs_sbi_server_start_all(server_cb) != OGS_OK) + return OGS_ERROR; + + /* + * The connection between NF and NRF is a little special. + * + * NF and NRF share nf_instance. I get the NRF EndPoint(client) information + * the configuration file via lib/sbi/context.c. + * And, the NFService information will be transmitted to NRF. + * + * ogs_sbi_self()->nf_instance_id means NF's InstanceId. + */ + ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) { + ogs_sbi_nf_service_t *service = NULL; + ogs_sbi_client_t *client = NULL; + + /* Build NF instance information. It will be transmitted to NRF. */ + ogs_sbi_nf_instance_build_default(nf_instance, af_self()->nf_type); + + /* Build NF service information. It will be transmitted to NRF. */ + service = ogs_sbi_nf_service_build_default(nf_instance, + (char*)OGS_SBI_SERVICE_NAME_NAF_EVENTEXPOSURE); + ogs_assert(service); + ogs_sbi_nf_service_add_version(service, (char*)OGS_SBI_API_V1, + (char*)OGS_SBI_API_V1_0_0, NULL); + + /* Client callback is only used when NF sends to NRF */ + client = nf_instance->client; + ogs_assert(client); + client->cb = client_cb; + + /* NFRegister is sent and the response is received + * by the above client callback. */ + af_nf_fsm_init(nf_instance); + } + + return OGS_OK; +} + +void af_sbi_close(void) +{ + ogs_sbi_server_stop_all(); +} + +void af_nnrf_nfm_send_nf_register(ogs_sbi_nf_instance_t *nf_instance) +{ + ogs_sbi_request_t *request = NULL; + ogs_sbi_client_t *client = NULL; + + ogs_assert(nf_instance); + client = nf_instance->client; + ogs_assert(client); + + request = af_nnrf_nfm_build_register(nf_instance); + if (!request) { + ogs_error("af_nnrf_nfm_send_nf_register() failed"); + return; + } + ogs_sbi_client_send_request(client, client->cb, request, nf_instance); +} + +void af_sbi_send(ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_xact_t *xact) +{ + ogs_sbi_send(nf_instance, client_cb, xact); +} + +void af_sbi_discover_and_send(OpenAPI_nf_type_e target_nf_type, + af_sess_t *sess, void *data, + ogs_sbi_request_t *(*build)(af_sess_t *sess, void *data)) +{ + ogs_sbi_xact_t *xact = NULL; + + ogs_assert(target_nf_type); + + ogs_assert(sess); + ogs_assert(build); + + xact = ogs_sbi_xact_add(target_nf_type, &sess->sbi, + (ogs_sbi_build_f)build, sess, data, + af_timer_sbi_client_wait_expire); + if (!xact) { + ogs_error("af_sbi_discover_and_send() failed"); + return; + } + + if (ogs_sbi_discover_and_send(xact, + (ogs_fsm_handler_t)af_nf_state_registered, client_cb) != true) { + ogs_error("af_sbi_discover_and_send() failed"); + return; + } +} + +void af_sbi_send_to_pcf( + af_sess_t *sess, void *data, + ogs_sbi_request_t *(*build)(af_sess_t *sess, void *data)) +{ + ogs_sbi_request_t *request = NULL; + ogs_sbi_client_t *client = NULL; + + ogs_assert(sess); + ogs_assert(build); + client = sess->pcf.client; + ogs_assert(client); + + request = (*build)(sess, data); + ogs_assert(request); + ogs_sbi_client_send_request(client, client_cb, request, sess); +} diff --git a/tests/af/sbi-path.h b/tests/af/sbi-path.h new file mode 100644 index 000000000..73effe823 --- /dev/null +++ b/tests/af/sbi-path.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef AF_SBI_PATH_H +#define AF_SBI_PATH_H + +#include "nnrf-build.h" +#include "nbsf-build.h" +#include "npcf-build.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int af_sbi_open(void); +void af_sbi_close(void); + +void af_nnrf_nfm_send_nf_register(ogs_sbi_nf_instance_t *nf_instance); + +void af_sbi_send(ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_xact_t *xact); + +void af_sbi_discover_and_send(OpenAPI_nf_type_e target_nf_type, + af_sess_t *sess, void *data, + ogs_sbi_request_t *(*build)(af_sess_t *sess, void *data)); + +void af_sbi_send_to_pcf( + af_sess_t *sess, void *data, + ogs_sbi_request_t *(*build)(af_sess_t *sess, void *data)); + +#ifdef __cplusplus +} +#endif + +#endif /* AF_SBI_PATH_H */ diff --git a/tests/af/timer.c b/tests/af/timer.c new file mode 100644 index 000000000..3a0fd038e --- /dev/null +++ b/tests/af/timer.c @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "context.h" + +const char *af_timer_get_name(af_timer_e id) +{ + switch (id) { + case AF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: + return "AF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL"; + case AF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: + return "AF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL"; + case AF_TIMER_NF_INSTANCE_NO_HEARTBEAT: + return "AF_TIMER_NF_INSTANCE_NO_HEARTBEAT"; + case AF_TIMER_NF_INSTANCE_VALIDITY: + return "AF_TIMER_NF_INSTANCE_VALIDITY"; + case AF_TIMER_SUBSCRIPTION_VALIDITY: + return "AF_TIMER_SUBSCRIPTION_VALIDITY"; + case AF_TIMER_SBI_CLIENT_WAIT: + return "AF_TIMER_SBI_CLIENT_WAIT"; + default: + break; + } + + return "UNKNOWN_TIMER"; +} + +static void timer_send_event(int timer_id, void *data) +{ + int rv; + af_event_t *e = NULL; + ogs_assert(data); + + switch (timer_id) { + case AF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: + case AF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL: + case AF_TIMER_NF_INSTANCE_NO_HEARTBEAT: + case AF_TIMER_NF_INSTANCE_VALIDITY: + case AF_TIMER_SUBSCRIPTION_VALIDITY: + e = af_event_new(AF_EVT_SBI_TIMER); + ogs_assert(e); + e->timer_id = timer_id; + e->sbi.data = data; + break; + case AF_TIMER_SBI_CLIENT_WAIT: + e = af_event_new(AF_EVT_SBI_TIMER); + if (!e) { + ogs_sbi_xact_t *sbi_xact = data; + ogs_assert(sbi_xact); + + ogs_error("timer_send_event() failed"); + ogs_sbi_xact_remove(sbi_xact); + return; + } + e->timer_id = timer_id; + e->sbi.data = data; + break; + default: + ogs_fatal("Unknown timer id[%d]", timer_id); + ogs_assert_if_reached(); + break; + } + + rv = ogs_queue_push(ogs_app()->queue, e); + if (rv != OGS_OK) { + ogs_warn("ogs_queue_push() failed [%d] in %s", + (int)rv, af_timer_get_name(e->timer_id)); + af_event_free(e); + } +} + +void af_timer_nf_instance_registration_interval(void *data) +{ + timer_send_event(AF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL, data); +} + +void af_timer_nf_instance_heartbeat_interval(void *data) +{ + timer_send_event(AF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL, data); +} + +void af_timer_nf_instance_no_heartbeat(void *data) +{ + timer_send_event(AF_TIMER_NF_INSTANCE_NO_HEARTBEAT, data); +} + +void af_timer_nf_instance_validity(void *data) +{ + timer_send_event(AF_TIMER_NF_INSTANCE_VALIDITY, data); +} + +void af_timer_subscription_validity(void *data) +{ + timer_send_event(AF_TIMER_SUBSCRIPTION_VALIDITY, data); +} + +void af_timer_sbi_client_wait_expire(void *data) +{ + timer_send_event(AF_TIMER_SBI_CLIENT_WAIT, data); +} diff --git a/tests/af/timer.h b/tests/af/timer.h new file mode 100644 index 000000000..2246d15eb --- /dev/null +++ b/tests/af/timer.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef AF_TIMER_H +#define AF_TIMER_H + +#include "ogs-core.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* forward declaration */ +typedef enum { + AF_TIMER_BASE = 0, + + AF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL, + AF_TIMER_NF_INSTANCE_HEARTBEAT_INTERVAL, + AF_TIMER_NF_INSTANCE_NO_HEARTBEAT, + AF_TIMER_NF_INSTANCE_VALIDITY, + AF_TIMER_SUBSCRIPTION_VALIDITY, + AF_TIMER_SBI_CLIENT_WAIT, + + MAX_NUM_OF_AF_TIMER, + +} af_timer_e; + +const char *af_timer_get_name(af_timer_e id); + +void af_timer_nf_instance_registration_interval(void *data); +void af_timer_nf_instance_heartbeat_interval(void *data); +void af_timer_nf_instance_no_heartbeat(void *data); +void af_timer_nf_instance_validity(void *data); +void af_timer_subscription_validity(void *data); +void af_timer_sbi_client_wait_expire(void *data); + +#ifdef __cplusplus +} +#endif + +#endif /* AF_TIMER_H */ diff --git a/tests/app/5gc-init.c b/tests/app/5gc-init.c index 57ff013f3..0b8158f1e 100644 --- a/tests/app/5gc-init.c +++ b/tests/app/5gc-init.c @@ -27,6 +27,7 @@ static ogs_thread_t *ausf_thread = NULL; static ogs_thread_t *udm_thread = NULL; static ogs_thread_t *pcf_thread = NULL; static ogs_thread_t *nssf_thread = NULL; +static ogs_thread_t *bsf_thread = NULL; static ogs_thread_t *udr_thread = NULL; int app_initialize(const char *const argv[]) @@ -68,6 +69,8 @@ int app_initialize(const char *const argv[]) pcf_thread = test_child_create("pcf", argv_out); if (ogs_app()->parameter.no_nssf == 0) nssf_thread = test_child_create("nssf", argv_out); + if (ogs_app()->parameter.no_bsf == 0) + bsf_thread = test_child_create("bsf", argv_out); if (ogs_app()->parameter.no_udr == 0) udr_thread = test_child_create("udr", argv_out); @@ -90,6 +93,7 @@ void app_terminate(void) if (udr_thread) ogs_thread_destroy(udr_thread); if (nssf_thread) ogs_thread_destroy(nssf_thread); + if (bsf_thread) ogs_thread_destroy(bsf_thread); if (pcf_thread) ogs_thread_destroy(pcf_thread); if (udm_thread) ogs_thread_destroy(udm_thread); if (ausf_thread) ogs_thread_destroy(ausf_thread); diff --git a/tests/app/app-init.c b/tests/app/app-init.c index 6bce4b69c..12cd78712 100644 --- a/tests/app/app-init.c +++ b/tests/app/app-init.c @@ -32,6 +32,7 @@ static ogs_thread_t *ausf_thread = NULL; static ogs_thread_t *udm_thread = NULL; static ogs_thread_t *pcf_thread = NULL; static ogs_thread_t *nssf_thread = NULL; +static ogs_thread_t *bsf_thread = NULL; static ogs_thread_t *udr_thread = NULL; int app_initialize(const char *const argv[]) @@ -84,6 +85,8 @@ int app_initialize(const char *const argv[]) pcf_thread = test_child_create("pcf", argv_out); if (ogs_app()->parameter.no_nssf == 0) nssf_thread = test_child_create("nssf", argv_out); + if (ogs_app()->parameter.no_bsf == 0) + bsf_thread = test_child_create("bsf", argv_out); if (ogs_app()->parameter.no_udr == 0) udr_thread = test_child_create("udr", argv_out); @@ -109,6 +112,7 @@ void app_terminate(void) if (upf_thread) ogs_thread_destroy(upf_thread); if (udr_thread) ogs_thread_destroy(udr_thread); + if (bsf_thread) ogs_thread_destroy(bsf_thread); if (nssf_thread) ogs_thread_destroy(nssf_thread); if (pcf_thread) ogs_thread_destroy(pcf_thread); if (udm_thread) ogs_thread_destroy(udm_thread); diff --git a/tests/common/meson.build b/tests/common/meson.build index c88aa62e7..6fa69f731 100644 --- a/tests/common/meson.build +++ b/tests/common/meson.build @@ -68,7 +68,8 @@ libtestcommon = static_library('testcomon', libnas_eps_dep, libnas_5gs_dep, libdiameter_rx_dep, - libdiameter_cx_dep], + libdiameter_cx_dep, + libaf_dep], install : false) libtestcommon_dep = declare_dependency( @@ -85,4 +86,5 @@ libtestcommon_dep = declare_dependency( libnas_eps_dep, libnas_5gs_dep, libdiameter_rx_dep, - libdiameter_cx_dep]) + libdiameter_cx_dep, + libaf_dep]) diff --git a/tests/meson.build b/tests/meson.build index d2ebe12f1..4f0422754 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -21,6 +21,7 @@ subdir('core') subdir('crypt') subdir('sctp') subdir('unit') +subdir('af') subdir('common') subdir('app') subdir('registration') diff --git a/tests/vonr/abts-main.c b/tests/vonr/abts-main.c index b3ff6104f..e48fa8611 100644 --- a/tests/vonr/abts-main.c +++ b/tests/vonr/abts-main.c @@ -18,15 +18,18 @@ */ #include "test-app.h" +#include "af/init.h" abts_suite *test_qos_flow(abts_suite *suite); abts_suite *test_session(abts_suite *suite); +abts_suite *test_af(abts_suite *suite); const struct testlist { abts_suite *(*func)(abts_suite *suite); } alltests[] = { {test_qos_flow}, {test_session}, + {test_af}, {NULL}, }; @@ -34,6 +37,8 @@ static void terminate(void) { ogs_msleep(50); + af_terminate(); + test_child_terminate(); app_terminate(); @@ -51,6 +56,9 @@ static void initialize(const char *const argv[]) rv = app_initialize(argv); ogs_assert(rv == OGS_OK); + + rv = af_initialize(); + ogs_assert(rv == OGS_OK); } int main(int argc, const char *const argv[]) diff --git a/tests/vonr/af-test.c b/tests/vonr/af-test.c new file mode 100644 index 000000000..f9874d4e2 --- /dev/null +++ b/tests/vonr/af-test.c @@ -0,0 +1,357 @@ +/* + * Copyright (C) 2019,2020 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "test-common.h" +#include "af/sbi-path.h" + +static void test1_func(abts_case *tc, void *data) +{ + int rv; + ogs_socknode_t *ngap; + ogs_socknode_t *gtpu; + ogs_pkbuf_t *gmmbuf; + ogs_pkbuf_t *gsmbuf; + ogs_pkbuf_t *nasbuf; + ogs_pkbuf_t *sendbuf; + ogs_pkbuf_t *recvbuf; + ogs_ngap_message_t message; + int i; + + uint8_t tmp[OGS_MAX_SDU_LEN]; + char *_gtp_payload = "34ff0024" + "0000000100000085 010002004500001c 0c0b000040015a7a 0a2d00010a2d0002" + "00000964cd7c291f"; + + ogs_nas_5gs_mobile_identity_suci_t mobile_identity_suci; + test_ue_t *test_ue = NULL; + test_sess_t *sess = NULL; + test_bearer_t *qos_flow = NULL; + + af_sess_t *af_sess = NULL; + + bson_t *doc = NULL; + + /* Setup Test UE & Session Context */ + memset(&mobile_identity_suci, 0, sizeof(mobile_identity_suci)); + + mobile_identity_suci.h.supi_format = OGS_NAS_5GS_SUPI_FORMAT_IMSI; + mobile_identity_suci.h.type = OGS_NAS_5GS_MOBILE_IDENTITY_SUCI; + mobile_identity_suci.routing_indicator1 = 0; + mobile_identity_suci.routing_indicator2 = 0xf; + mobile_identity_suci.routing_indicator3 = 0xf; + mobile_identity_suci.routing_indicator4 = 0xf; + mobile_identity_suci.protection_scheme_id = OGS_NAS_5GS_NULL_SCHEME; + mobile_identity_suci.home_network_pki_value = 0; + mobile_identity_suci.scheme_output[0] = 0; + mobile_identity_suci.scheme_output[1] = 0; + mobile_identity_suci.scheme_output[2] = 0x20; + mobile_identity_suci.scheme_output[3] = 0x31; + mobile_identity_suci.scheme_output[4] = 0x90; + + test_ue = test_ue_add_by_suci(&mobile_identity_suci, 13); + ogs_assert(test_ue); + + test_ue->nr_cgi.cell_id = 0x40001; + + test_ue->nas.registration.tsc = 0; + test_ue->nas.registration.ksi = OGS_NAS_KSI_NO_KEY_IS_AVAILABLE; + test_ue->nas.registration.follow_on_request = 1; + test_ue->nas.registration.value = OGS_NAS_5GS_REGISTRATION_TYPE_INITIAL; + + test_ue->k_string = "465b5ce8b199b49faa5f0a2ee238a6bc"; + test_ue->opc_string = "e8ed289deba952e4283b54e88e6183ca"; + + /* gNB connects to AMF */ + ngap = testngap_client(AF_INET); + ABTS_PTR_NOTNULL(tc, ngap); + + /* gNB connects to UPF */ + gtpu = test_gtpu_server(1, AF_INET); + ABTS_PTR_NOTNULL(tc, gtpu); + + /* Send NG-Setup Reqeust */ + sendbuf = testngap_build_ng_setup_request(0x4000, 22); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive NG-Setup Response */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(test_ue, recvbuf); + + /********** Insert Subscriber in Database */ + doc = test_db_new_ims(test_ue); + ABTS_PTR_NOTNULL(tc, doc); + ABTS_INT_EQUAL(tc, OGS_OK, test_db_insert_ue(test_ue, doc)); + + /* Send Registration request */ + test_ue->registration_request_param.guti = 1; + gmmbuf = testgmm_build_registration_request(test_ue, NULL); + ABTS_PTR_NOTNULL(tc, gmmbuf); + + test_ue->registration_request_param.gmm_capability = 1; + test_ue->registration_request_param.requested_nssai = 1; + test_ue->registration_request_param.last_visited_registered_tai = 1; + test_ue->registration_request_param.ue_usage_setting = 1; + nasbuf = testgmm_build_registration_request(test_ue, NULL); + ABTS_PTR_NOTNULL(tc, nasbuf); + + sendbuf = testngap_build_initial_ue_message(test_ue, gmmbuf, false, true); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Identity request */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(test_ue, recvbuf); + + /* Send Identity response */ + gmmbuf = testgmm_build_identity_response(test_ue); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Authentication request */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(test_ue, recvbuf); + + /* Send Authentication response */ + gmmbuf = testgmm_build_authentication_response(test_ue); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Security mode command */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(test_ue, recvbuf); + + /* Send Security mode complete */ + gmmbuf = testgmm_build_security_mode_complete(test_ue, nasbuf); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive InitialContextSetupRequest + + * Registration accept */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(test_ue, recvbuf); + ABTS_INT_EQUAL(tc, + NGAP_ProcedureCode_id_InitialContextSetup, + test_ue->ngap_procedure_code); + + /* Send UERadioCapabilityInfoIndication */ + sendbuf = testngap_build_ue_radio_capability_info_indication(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send InitialContextSetupResponse */ + sendbuf = testngap_build_initial_context_setup_response(test_ue, false); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send Registration complete */ + gmmbuf = testgmm_build_registration_complete(test_ue); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive Configuration update command */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(test_ue, recvbuf); + + /* Send PDU session establishment request */ + sess = test_sess_add_by_dnn_and_psi(test_ue, "internet", 5); + ogs_assert(sess); + + sess->ul_nas_transport_param.request_type = + OGS_NAS_5GS_REQUEST_TYPE_INITIAL; + sess->ul_nas_transport_param.dnn = 1; + sess->ul_nas_transport_param.s_nssai = 1; + + sess->pdu_session_establishment_param.ssc_mode = 1; + sess->pdu_session_establishment_param.epco = 1; + + gsmbuf = testgsm_build_pdu_session_establishment_request(sess); + ABTS_PTR_NOTNULL(tc, gsmbuf); + gmmbuf = testgmm_build_ul_nas_transport(sess, + OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive PDUSessionResourceSetupRequest + + * DL NAS transport + + * PDU session establishment accept */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(test_ue, recvbuf); + ABTS_INT_EQUAL(tc, + NGAP_ProcedureCode_id_PDUSessionResourceSetup, + test_ue->ngap_procedure_code); + + /* Send GTP-U ICMP Packet */ + qos_flow = test_qos_flow_find_by_qfi(sess, 1); + ogs_assert(qos_flow); + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Send PDUSessionResourceSetupResponse */ + sendbuf = testngap_sess_build_pdu_session_resource_setup_response(sess); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = testgnb_gtpu_read(gtpu); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Send GTP-U ICMP Packet */ + rv = test_gtpu_send_ping(gtpu, qos_flow, TEST_PING_IPV4); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U ICMP Packet */ + recvbuf = testgnb_gtpu_read(gtpu); + ABTS_PTR_NOTNULL(tc, recvbuf); + ogs_pkbuf_free(recvbuf); + + /* Send GTP-U Router Solicitation */ + rv = test_gtpu_send_slacc_rs(gtpu, qos_flow); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive GTP-U Router Advertisement */ + recvbuf = test_gtpu_read(gtpu); + ABTS_PTR_NOTNULL(tc, recvbuf); + testgtpu_recv(test_ue, recvbuf); + +#if 0 + /* Send PDU session establishment request */ + sess = test_sess_add_by_dnn_and_psi(test_ue, "ims", 6); + ogs_assert(sess); + + sess->ul_nas_transport_param.request_type = + OGS_NAS_5GS_REQUEST_TYPE_INITIAL; + sess->ul_nas_transport_param.dnn = 1; + sess->ul_nas_transport_param.s_nssai = 1; + + sess->pdu_session_establishment_param.ssc_mode = 1; + sess->pdu_session_establishment_param.epco = 1; + + gsmbuf = testgsm_build_pdu_session_establishment_request(sess); + ABTS_PTR_NOTNULL(tc, gsmbuf); + gmmbuf = testgmm_build_ul_nas_transport(sess, + OGS_NAS_PAYLOAD_CONTAINER_N1_SM_INFORMATION, gsmbuf); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive PDU session establishment accept */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(test_ue, recvbuf); + + /* Send PDUSessionResourceSetupResponse */ + sendbuf = testngap_sess_build_pdu_session_resource_setup_response(sess); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); +#endif + + /* Add AF-Session */ + af_sess = af_sess_add_by_ue_address(&sess->ue_ip); + ogs_assert(af_sess); + +#if 0 + af_local_discover_and_send(OpenAPI_nf_type_BSF, af_sess, NULL, + af_nbsf_management_build_discover); + + /* Wait for PCF-Discovery */ + ogs_msleep(100); + + af_local_send_to_pcf(af_sess, NULL, + af_npcf_policyauthorization_build_create); + + ogs_msleep(300); +#endif + + /* Send De-registration request */ + gmmbuf = testgmm_build_de_registration_request(test_ue, 1); + ABTS_PTR_NOTNULL(tc, gmmbuf); + sendbuf = testngap_build_uplink_nas_transport(test_ue, gmmbuf); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + /* Receive UEContextReleaseCommand */ + recvbuf = testgnb_ngap_read(ngap); + ABTS_PTR_NOTNULL(tc, recvbuf); + testngap_recv(test_ue, recvbuf); + ABTS_INT_EQUAL(tc, + NGAP_ProcedureCode_id_UEContextRelease, + test_ue->ngap_procedure_code); + + /* Send UEContextReleaseComplete */ + sendbuf = testngap_build_ue_context_release_complete(test_ue); + ABTS_PTR_NOTNULL(tc, sendbuf); + rv = testgnb_ngap_send(ngap, sendbuf); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_msleep(300); + + /********** Remove Subscriber in Database */ + ABTS_INT_EQUAL(tc, OGS_OK, test_db_remove_ue(test_ue)); + + /* gNB disonncect from UPF */ + testgnb_gtpu_close(gtpu); + + /* gNB disonncect from AMF */ + testgnb_ngap_close(ngap); + + /* Clear Test UE Context */ + test_ue_remove(test_ue); +} + +abts_suite *test_af(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, test1_func, NULL); + + return suite; +} diff --git a/tests/vonr/meson.build b/tests/vonr/meson.build index a5cc30f02..d0c6768cb 100644 --- a/tests/vonr/meson.build +++ b/tests/vonr/meson.build @@ -19,6 +19,7 @@ test5gc_vonr_sources = files(''' abts-main.c qos-flow-test.c session-test.c + af-test.c '''.split()) test5gc_vonr_exe = executable('vonr',