From 8ffa286bed63b2f3685869d22450b53c6b9bac43 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Sat, 6 Jul 2024 12:43:37 +0000 Subject: [PATCH 01/41] feat: update r17 openapi --- go.mod | 12 +++++-- go.sum | 32 ++++++++++++++----- internal/context/context.go | 2 +- internal/sbi/api_uecontextmanagement.go | 2 +- internal/sbi/consumer/consumer.go | 10 +++--- internal/sbi/consumer/nf_discovery.go | 2 +- internal/sbi/consumer/nrf_service.go | 4 +-- internal/sbi/consumer/udm_service.go | 4 +-- internal/sbi/consumer/udr_service.go | 2 +- internal/sbi/processor/generate_auth_data.go | 2 +- .../processor/subscriber_data_management.go | 2 +- .../sbi/processor/ue_context_management.go | 2 +- 12 files changed, 50 insertions(+), 26 deletions(-) diff --git a/go.mod b/go.mod index 6897ec0..ae3051d 100644 --- a/go.mod +++ b/go.mod @@ -5,13 +5,13 @@ go 1.21 require ( github.com/antihax/optional v1.0.0 github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d - github.com/free5gc/openapi v1.0.8 + github.com/free5gc/openapi v1.0.9-0.20240423070630-14913ab805dc github.com/free5gc/util v1.0.6 github.com/gin-gonic/gin v1.9.1 github.com/google/uuid v1.3.0 github.com/h2non/gock v1.2.0 github.com/pkg/errors v0.9.1 - github.com/sirupsen/logrus v1.8.1 + github.com/sirupsen/logrus v1.9.3 github.com/stretchr/testify v1.8.4 github.com/urfave/cli v1.22.5 go.uber.org/mock v0.4.0 @@ -24,8 +24,11 @@ require ( github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect + github.com/felixge/httpsnoop v1.0.4 // indirect github.com/gabriel-vasile/mimetype v1.4.2 // indirect github.com/gin-contrib/sse v0.1.0 // indirect + github.com/go-logr/logr v1.4.1 // indirect + github.com/go-logr/stdr v1.2.2 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.14.0 // indirect @@ -46,6 +49,11 @@ require ( github.com/tim-ywliu/nested-logrus-formatter v1.3.2 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.11 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.49.0 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect + go.opentelemetry.io/otel v1.24.0 // indirect + go.opentelemetry.io/otel/metric v1.24.0 // indirect + go.opentelemetry.io/otel/trace v1.24.0 // indirect golang.org/x/arch v0.3.0 // indirect golang.org/x/net v0.23.0 // indirect golang.org/x/oauth2 v0.15.0 // indirect diff --git a/go.sum b/go.sum index 8b07968..cb6fe2a 100644 --- a/go.sum +++ b/go.sum @@ -15,8 +15,10 @@ github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/free5gc/openapi v1.0.8 h1:QjfQdB6VVA1GRnzOJ7nILzrI7gMiY0lH64JHVW7vF34= -github.com/free5gc/openapi v1.0.8/go.mod h1:w6y9P/uySczc1d9OJZAEuB2FImR/z60Wg2BekPAVt3M= +github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= +github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= +github.com/free5gc/openapi v1.0.9-0.20240423070630-14913ab805dc h1:dBHbIEMOfNr9gnDVRwbN3P4bZ/Y8K8X9hO4qs37Hncs= +github.com/free5gc/openapi v1.0.9-0.20240423070630-14913ab805dc/go.mod h1:oy68rqnHakRLUCuEOXcis7/PWGBuil+UaXMeTBeYY8Y= github.com/free5gc/util v1.0.6 h1:dBt9drcXtYKE/cY5XuQcuffgsYclPIpIArhSeS6M+DQ= github.com/free5gc/util v1.0.6/go.mod h1:eSGN7POUM8LNTvg/E591XR6447a6/w1jFWGKNZPHcXw= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= @@ -25,6 +27,11 @@ github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= +github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= @@ -42,8 +49,8 @@ github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiu github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -79,12 +86,11 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= -github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= -github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= +github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= @@ -103,6 +109,16 @@ github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZ github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU= github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.49.0 h1:RtcvQ4iw3w9NBB5yRwgA4sSa82rfId7n4atVpvKx3bY= +go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.49.0/go.mod h1:f/PbKbRd4cdUICWell6DmzvVJ7QrmBgFrRHjXmAXbK4= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 h1:jq9TW8u3so/bN+JPT166wjOI6/vQPF6Xe7nMNIltagk= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0/go.mod h1:p8pYQP+m5XfbZm9fxtSKAbM6oIllS7s2AfxrChvc7iw= +go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo= +go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo= +go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI= +go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco= +go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI= +go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU= go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= @@ -123,11 +139,11 @@ golang.org/x/oauth2 v0.15.0/go.mod h1:q48ptWNTY5XWf+JNten23lcvHpLJ0ZSxF5ttTHKVCA golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= diff --git a/internal/context/context.go b/internal/context/context.go index 922efd5..dee4c06 100644 --- a/internal/context/context.go +++ b/internal/context/context.go @@ -12,8 +12,8 @@ import ( "github.com/google/uuid" "github.com/free5gc/openapi" - "github.com/free5gc/openapi/Nnrf_NFDiscovery" "github.com/free5gc/openapi/models" + Nnrf_NFDiscovery "github.com/free5gc/openapi/nrf/NFDiscovery" "github.com/free5gc/openapi/oauth" "github.com/free5gc/udm/internal/logger" "github.com/free5gc/udm/pkg/factory" diff --git a/internal/sbi/api_uecontextmanagement.go b/internal/sbi/api_uecontextmanagement.go index 7725449..5519be9 100644 --- a/internal/sbi/api_uecontextmanagement.go +++ b/internal/sbi/api_uecontextmanagement.go @@ -8,8 +8,8 @@ import ( "github.com/gin-gonic/gin" "github.com/free5gc/openapi" - "github.com/free5gc/openapi/Nudr_DataRepository" "github.com/free5gc/openapi/models" + Nudr_DataRepository "github.com/free5gc/openapi/udr/DataRepository" "github.com/free5gc/udm/internal/logger" ) diff --git a/internal/sbi/consumer/consumer.go b/internal/sbi/consumer/consumer.go index 64d9e71..2e72bc4 100644 --- a/internal/sbi/consumer/consumer.go +++ b/internal/sbi/consumer/consumer.go @@ -1,11 +1,11 @@ package consumer import ( - "github.com/free5gc/openapi/Nnrf_NFDiscovery" - "github.com/free5gc/openapi/Nnrf_NFManagement" - "github.com/free5gc/openapi/Nudm_SubscriberDataManagement" - "github.com/free5gc/openapi/Nudm_UEContextManagement" - "github.com/free5gc/openapi/Nudr_DataRepository" + Nnrf_NFDiscovery "github.com/free5gc/openapi/nrf/NFDiscovery" + Nnrf_NFManagement "github.com/free5gc/openapi/nrf/NFManagement" + Nudm_SubscriberDataManagement "github.com/free5gc/openapi/udm/SubscriberDataManagement" + Nudm_UEContextManagement "github.com/free5gc/openapi/udm/UEContextManagement" + Nudr_DataRepository "github.com/free5gc/openapi/udr/DataRepository" "github.com/free5gc/udm/pkg/app" ) diff --git a/internal/sbi/consumer/nf_discovery.go b/internal/sbi/consumer/nf_discovery.go index 8b30abf..82fb00c 100644 --- a/internal/sbi/consumer/nf_discovery.go +++ b/internal/sbi/consumer/nf_discovery.go @@ -4,8 +4,8 @@ import ( "fmt" "net/http" - "github.com/free5gc/openapi/Nnrf_NFDiscovery" "github.com/free5gc/openapi/models" + Nnrf_NFDiscovery "github.com/free5gc/openapi/nrf/NFDiscovery" udm_context "github.com/free5gc/udm/internal/context" "github.com/free5gc/udm/internal/logger" "github.com/free5gc/udm/internal/util" diff --git a/internal/sbi/consumer/nrf_service.go b/internal/sbi/consumer/nrf_service.go index 3f5ec28..6b97c25 100644 --- a/internal/sbi/consumer/nrf_service.go +++ b/internal/sbi/consumer/nrf_service.go @@ -11,9 +11,9 @@ import ( "github.com/pkg/errors" "github.com/free5gc/openapi" - "github.com/free5gc/openapi/Nnrf_NFDiscovery" - "github.com/free5gc/openapi/Nnrf_NFManagement" "github.com/free5gc/openapi/models" + Nnrf_NFDiscovery "github.com/free5gc/openapi/nrf/NFDiscovery" + Nnrf_NFManagement "github.com/free5gc/openapi/nrf/NFManagement" udm_context "github.com/free5gc/udm/internal/context" "github.com/free5gc/udm/internal/logger" ) diff --git a/internal/sbi/consumer/udm_service.go b/internal/sbi/consumer/udm_service.go index 4bb5109..fde12be 100644 --- a/internal/sbi/consumer/udm_service.go +++ b/internal/sbi/consumer/udm_service.go @@ -3,8 +3,8 @@ package consumer import ( "sync" - "github.com/free5gc/openapi/Nudm_SubscriberDataManagement" - "github.com/free5gc/openapi/Nudm_UEContextManagement" + Nudm_SubscriberDataManagement "github.com/free5gc/openapi/udm/SubscriberDataManagement" + Nudm_UEContextManagement "github.com/free5gc/openapi/udm/UEContextManagement" ) type nudmService struct { diff --git a/internal/sbi/consumer/udr_service.go b/internal/sbi/consumer/udr_service.go index 7f7df94..2afb875 100644 --- a/internal/sbi/consumer/udr_service.go +++ b/internal/sbi/consumer/udr_service.go @@ -5,7 +5,7 @@ import ( "strings" "sync" - "github.com/free5gc/openapi/Nudr_DataRepository" + Nudr_DataRepository "github.com/free5gc/openapi/udr/DataRepository" udm_context "github.com/free5gc/udm/internal/context" "github.com/free5gc/udm/internal/logger" ) diff --git a/internal/sbi/processor/generate_auth_data.go b/internal/sbi/processor/generate_auth_data.go index 7135558..21ebf32 100644 --- a/internal/sbi/processor/generate_auth_data.go +++ b/internal/sbi/processor/generate_auth_data.go @@ -16,8 +16,8 @@ import ( "github.com/gin-gonic/gin" "github.com/free5gc/openapi" - "github.com/free5gc/openapi/Nudr_DataRepository" "github.com/free5gc/openapi/models" + Nudr_DataRepository "github.com/free5gc/openapi/udr/DataRepository" "github.com/free5gc/udm/internal/logger" "github.com/free5gc/udm/pkg/suci" "github.com/free5gc/util/milenage" diff --git a/internal/sbi/processor/subscriber_data_management.go b/internal/sbi/processor/subscriber_data_management.go index 9efeced..704ac34 100644 --- a/internal/sbi/processor/subscriber_data_management.go +++ b/internal/sbi/processor/subscriber_data_management.go @@ -8,8 +8,8 @@ import ( "github.com/gin-gonic/gin" "github.com/free5gc/openapi" - "github.com/free5gc/openapi/Nudr_DataRepository" "github.com/free5gc/openapi/models" + Nudr_DataRepository "github.com/free5gc/openapi/udr/DataRepository" udm_context "github.com/free5gc/udm/internal/context" "github.com/free5gc/udm/internal/logger" ) diff --git a/internal/sbi/processor/ue_context_management.go b/internal/sbi/processor/ue_context_management.go index 091e650..9ab3b45 100644 --- a/internal/sbi/processor/ue_context_management.go +++ b/internal/sbi/processor/ue_context_management.go @@ -8,8 +8,8 @@ import ( "github.com/gin-gonic/gin" "github.com/free5gc/openapi" - "github.com/free5gc/openapi/Nudr_DataRepository" "github.com/free5gc/openapi/models" + Nudr_DataRepository "github.com/free5gc/openapi/udr/DataRepository" udm_context "github.com/free5gc/udm/internal/context" "github.com/free5gc/udm/internal/logger" ) From 31cec69f6a6192a821f8faa40583f7512fcaad22 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Tue, 16 Jul 2024 09:35:01 +0000 Subject: [PATCH 02/41] feat: update context.go & search_nf_service.go --- internal/context/context.go | 16 ++++++++-------- internal/util/search_nf_service.go | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/internal/context/context.go b/internal/context/context.go index dee4c06..bcd7c34 100644 --- a/internal/context/context.go +++ b/internal/context/context.go @@ -32,7 +32,7 @@ const ( ) func Init() { - GetSelf().NfService = make(map[models.ServiceName]models.NfService) + GetSelf().NfService = make(map[models.ServiceName]models.NrfNfManagementNfService) GetSelf().EeSubscriptionIDGenerator = idgenerator.NewGenerator(1, math.MaxInt32) InitUdmContext(GetSelf()) } @@ -50,7 +50,7 @@ type UDMContext struct { RegisterIPv4 string // IP register to NRF BindingIPv4 string UriScheme models.UriScheme - NfService map[models.ServiceName]models.NfService + NfService map[models.ServiceName]models.NrfNfManagementNfService NFDiscoveryClient *Nnrf_NFDiscovery.APIClient UdmUePool sync.Map // map[supi]*UdmUeContext NrfUri string @@ -467,10 +467,10 @@ func (context *UDMContext) InitNFService(serviceName []string, version string) { versionUri := "v" + tmpVersion[0] for index, nameString := range serviceName { name := models.ServiceName(nameString) - context.NfService[name] = models.NfService{ + context.NfService[name] = models.NrfNfManagementNfService{ ServiceInstanceId: strconv.Itoa(index), ServiceName: name, - Versions: &[]models.NfServiceVersion{ + Versions: []models.NfServiceVersion{ { ApiFullVersion: version, ApiVersionInUri: versionUri, @@ -479,10 +479,10 @@ func (context *UDMContext) InitNFService(serviceName []string, version string) { Scheme: context.UriScheme, NfServiceStatus: models.NfServiceStatus_REGISTERED, ApiPrefix: context.GetIPv4Uri(), - IpEndPoints: &[]models.IpEndPoint{ + IpEndPoints: []models.IpEndPoint{ { Ipv4Address: context.RegisterIPv4, - Transport: models.TransportProtocol_TCP, + Transport: models.NrfNfManagementTransportProtocol_TCP, Port: int32(context.SBIPort), }, }, @@ -490,13 +490,13 @@ func (context *UDMContext) InitNFService(serviceName []string, version string) { } } -func (c *UDMContext) GetTokenCtx(serviceName models.ServiceName, targetNF models.NfType) ( +func (c *UDMContext) GetTokenCtx(serviceName models.ServiceName, targetNF models.NrfNfManagementNfType) ( context.Context, *models.ProblemDetails, error, ) { if !c.OAuth2Required { return context.TODO(), nil, nil } - return oauth.GetTokenCtx(models.NfType_UDM, targetNF, + return oauth.GetTokenCtx(models.NrfNfManagementNfType_UDM, targetNF, c.NfId, c.NrfUri, string(serviceName)) } diff --git a/internal/util/search_nf_service.go b/internal/util/search_nf_service.go index 7a75ed9..0f241bc 100644 --- a/internal/util/search_nf_service.go +++ b/internal/util/search_nf_service.go @@ -10,7 +10,7 @@ func SearchNFServiceUri(nfProfile models.NfProfile, serviceName models.ServiceNa nfServiceStatus models.NfServiceStatus, ) (nfUri string) { if nfProfile.NfServices != nil { - for _, service := range *nfProfile.NfServices { + for _, service := range nfProfile.NfServices { if service.ServiceName == serviceName && service.NfServiceStatus == nfServiceStatus { if nfProfile.Fqdn != "" { nfUri = nfProfile.Fqdn @@ -19,7 +19,7 @@ func SearchNFServiceUri(nfProfile models.NfProfile, serviceName models.ServiceNa } else if service.ApiPrefix != "" { nfUri = service.ApiPrefix } else if service.IpEndPoints != nil { - point := (*service.IpEndPoints)[0] + point := (service.IpEndPoints)[0] if point.Ipv4Address != "" { nfUri = getSbiUri(service.Scheme, point.Ipv4Address, point.Port) } else if len(nfProfile.Ipv4Addresses) != 0 { From 84bf661eeca8f4aa2fbbffeede1ecc6c1cf30c25 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Wed, 17 Jul 2024 12:01:58 +0000 Subject: [PATCH 03/41] feat: update pp, sdm, uecm, ueau processor openapi --- internal/sbi/api_uecontextmanagement.go | 10 +- internal/sbi/processor/generate_auth_data.go | 45 +-- internal/sbi/processor/parameter_provision.go | 26 +- .../processor/subscriber_data_management.go | 356 +++++------------- .../sbi/processor/ue_context_management.go | 19 +- 5 files changed, 138 insertions(+), 318 deletions(-) diff --git a/internal/sbi/api_uecontextmanagement.go b/internal/sbi/api_uecontextmanagement.go index 5519be9..f667099 100644 --- a/internal/sbi/api_uecontextmanagement.go +++ b/internal/sbi/api_uecontextmanagement.go @@ -4,7 +4,6 @@ import ( "net/http" "strings" - "github.com/antihax/optional" "github.com/gin-gonic/gin" "github.com/free5gc/openapi" @@ -128,11 +127,10 @@ func (s *Server) HandleGetAmfNon3gppAccess(c *gin.Context) { ueId := c.Param("ueId") supportedFeatures := c.Query("supported-features") - - var queryAmfContextNon3gppParamOpts Nudr_DataRepository.QueryAmfContextNon3gppParamOpts - queryAmfContextNon3gppParamOpts.SupportedFeatures = optional.NewString(supportedFeatures) - - s.Processor().GetAmfNon3gppAccessProcedure(c, queryAmfContextNon3gppParamOpts, ueId) + var queryAmfContextNon3gppRequest Nudr_DataRepository.QueryAmfContextNon3gppRequest + queryAmfContextNon3gppRequest.SupportedFeatures = &supportedFeatures + queryAmfContextNon3gppRequest.UeId = &ueId + s.Processor().GetAmfNon3gppAccessProcedure(c, queryAmfContextNon3gppRequest, ueId) } // Register - register as AMF for non-3GPP access diff --git a/internal/sbi/processor/generate_auth_data.go b/internal/sbi/processor/generate_auth_data.go index 21ebf32..8ab1c90 100644 --- a/internal/sbi/processor/generate_auth_data.go +++ b/internal/sbi/processor/generate_auth_data.go @@ -12,7 +12,6 @@ import ( "strings" "time" - "github.com/antihax/optional" "github.com/gin-gonic/gin" "github.com/free5gc/openapi" @@ -85,9 +84,9 @@ func (p *Processor) ConfirmAuthDataProcedure(c *gin.Context, c.JSON(int(pd.Status), pd) return } - var createAuthParam Nudr_DataRepository.CreateAuthenticationStatusParamOpts - optInterface := optional.NewInterface(authEvent) - createAuthParam.AuthEvent = optInterface + var createAuthStatusRequest Nudr_DataRepository.CreateAuthenticationStatusRequest + createAuthStatusRequest.AuthEvent = &authEvent + createAuthStatusRequest.UeId = &supi client, err := p.Consumer().CreateUDMClientToUDR(supi) if err != nil { @@ -96,26 +95,16 @@ func (p *Processor) ConfirmAuthDataProcedure(c *gin.Context, return } - resp, err := client.AuthenticationStatusDocumentApi.CreateAuthenticationStatus( - ctx, supi, &createAuthParam) + createAuthStatusResponse, err := client.AuthenticationStatusDocumentApi.CreateAuthenticationStatus( + ctx, &createAuthStatusRequest) if err != nil { - problemDetails := &models.ProblemDetails{ - Status: int32(resp.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) logger.UeauLog.Errorln("ConfirmAuth err:", err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } - defer func() { - if rspCloseErr := resp.Body.Close(); rspCloseErr != nil { - logger.UeauLog.Errorf("CreateAuthenticationStatus response body cannot close: %+v", rspCloseErr) - } - }() - c.Status(http.StatusCreated) + c.JSON(http.StatusCreated, createAuthStatusResponse) } func (p *Processor) GenerateAuthDataProcedure( @@ -153,15 +142,15 @@ func (p *Processor) GenerateAuthDataProcedure( c.JSON(int(problemDetails.Status), problemDetails) return } - authSubs, res, err := client.AuthenticationDataDocumentApi.QueryAuthSubsData(ctx, supi, nil) + var queryAuthSubsDataRequest Nudr_DataRepository.QueryAuthSubsDataRequest + queryAuthSubsDataRequest.UeId = &supi + + authSubs, err := client.AuthenticationDataDocumentApi.QueryAuthSubsData(ctx, &queryAuthSubsDataRequest) + if err != nil { - problemDetails := &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: authenticationRejected, - Detail: err.Error(), - } - switch res.StatusCode { + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + switch problemDetails.Status { case http.StatusNotFound: logger.UeauLog.Warnf("Return from UDR QueryAuthSubsData error") default: @@ -170,11 +159,6 @@ func (p *Processor) GenerateAuthDataProcedure( c.JSON(int(problemDetails.Status), problemDetails) return } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("QueryAuthSubsData response body cannot close: %+v", rspCloseErr) - } - }() /* K, RAND, CK, IK: 128 bits (16 bytes) (hex len = 32) @@ -185,7 +169,6 @@ func (p *Processor) GenerateAuthDataProcedure( hasK, hasOP, hasOPC := false, false, false var kStr, opStr, opcStr string var k, op, opc []byte - if authSubs.PermanentKey != nil { kStr = authSubs.PermanentKey.PermanentKeyValue if len(kStr) == keyStrLen { diff --git a/internal/sbi/processor/parameter_provision.go b/internal/sbi/processor/parameter_provision.go index bd72ea1..d4da027 100644 --- a/internal/sbi/processor/parameter_provision.go +++ b/internal/sbi/processor/parameter_provision.go @@ -3,18 +3,18 @@ package processor import ( "net/http" + Nudr_DataRepository "github.com/free5gc/openapi/udr/DataRepository" "github.com/gin-gonic/gin" "github.com/free5gc/openapi" "github.com/free5gc/openapi/models" - "github.com/free5gc/udm/internal/logger" ) func (p *Processor) UpdateProcedure(c *gin.Context, updateRequest models.PpData, gpsi string, ) { - ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) + ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NrfNfManagementNfType_UDR) if err != nil { c.JSON(int(pd.Status), pd) return @@ -25,21 +25,19 @@ func (p *Processor) UpdateProcedure(c *gin.Context, c.JSON(int(problemDetails.Status), problemDetails) return } - - res, err := clientAPI.ProvisionedParameterDataDocumentApi.ModifyPpData(ctx, gpsi, nil) + var modifyPpDataRequest Nudr_DataRepository.ModifyPpDataRequest + modifyPpDataRequest.UeId = &gpsi + modifyPpDataRsp, err := clientAPI.ProvisionedParameterDataDocumentApi.ModifyPpData(ctx, &modifyPpDataRequest) if err != nil { - problemDetails := &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.PpLog.Errorf("ModifyPpData response body cannot close: %+v", rspCloseErr) - } - }() + + if modifyPpDataRsp.PatchResult.Report != nil { + c.JSON(http.StatusOK, modifyPpDataRsp) + return + } + c.Status(http.StatusNoContent) } diff --git a/internal/sbi/processor/subscriber_data_management.go b/internal/sbi/processor/subscriber_data_management.go index 704ac34..95fc58e 100644 --- a/internal/sbi/processor/subscriber_data_management.go +++ b/internal/sbi/processor/subscriber_data_management.go @@ -15,13 +15,15 @@ import ( ) func (p *Processor) GetAmDataProcedure(c *gin.Context, supi string, plmnID string, supportedFeatures string) { - ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) + ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NrfNfManagementNfType_UDR) if err != nil { c.JSON(int(pd.Status), pd) return } - var queryAmDataParamOpts Nudr_DataRepository.QueryAmDataParamOpts - queryAmDataParamOpts.SupportedFeatures = optional.NewString(supportedFeatures) + var queryAmDataRequest Nudr_DataRepository.QueryAmDataRequest + queryAmDataRequest.SupportedFeatures = &supportedFeatures + queryAmDataRequest.UeId = &supi + queryAmDataRequest.ServingPlmnId = &plmnID clientAPI, err := p.Consumer().CreateUDMClientToUDR(supi) if err != nil { @@ -29,53 +31,34 @@ func (p *Processor) GetAmDataProcedure(c *gin.Context, supi string, plmnID strin c.JSON(int(problemDetails.Status), problemDetails) return } - - accessAndMobilitySubscriptionDataResp, res, err := clientAPI.AccessAndMobilitySubscriptionDataDocumentApi. - QueryAmData(ctx, supi, plmnID, &queryAmDataParamOpts) + accessAndMobilitySubscriptionDataResp, err := clientAPI.AccessAndMobilitySubscriptionDataDocumentApi. + QueryAmData(ctx, &queryAmDataRequest) if err != nil { - if res == nil { - logger.SdmLog.Errorf(err.Error()) - } else if err.Error() != res.Status { - logger.SdmLog.Errorf("Response State: %+v", err.Error()) - } else { - problemDetails := &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - c.JSON(int(problemDetails.Status), problemDetails) - return - } + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("QueryAmData response body cannot close: %+v", rspCloseErr) - } - }() - if res.StatusCode == http.StatusOK { + if accessAndMobilitySubscriptionDataResp != nil { udmUe, ok := p.Context().UdmUeFindBySupi(supi) if !ok { udmUe = p.Context().NewUdmUe(supi) } - udmUe.SetAMSubsriptionData(&accessAndMobilitySubscriptionDataResp) + udmUe.SetAMSubsriptionData(&accessAndMobilitySubscriptionDataResp.AccessAndMobilitySubscriptionData) c.JSON(http.StatusOK, accessAndMobilitySubscriptionDataResp) - } else { - problemDetails := &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "DATA_NOT_FOUND", - } - c.JSON(int(problemDetails.Status), problemDetails) } } func (p *Processor) GetIdTranslationResultProcedure(c *gin.Context, gpsi string) { - ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) + ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NrfNfManagementNfType_UDR) + if err != nil { c.JSON(int(pd.Status), pd) } var idTranslationResult models.IdTranslationResult - var getIdentityDataParamOpts Nudr_DataRepository.GetIdentityDataParamOpts + var getIdentityDataRequest Nudr_DataRepository.GetIdentityDataRequest + + getIdentityDataRequest.UeId = &gpsi clientAPI, err := p.Consumer().CreateUDMClientToUDR(gpsi) if err != nil { @@ -84,46 +67,21 @@ func (p *Processor) GetIdTranslationResultProcedure(c *gin.Context, gpsi string) return } - idTranslationResultResp, res, err := clientAPI.QueryIdentityDataBySUPIOrGPSIDocumentApi.GetIdentityData( - ctx, gpsi, &getIdentityDataParamOpts) + idTranslationResultResp, err := clientAPI.QueryIdentityDataBySUPIOrGPSIDocumentApi.GetIdentityData( + ctx, &getIdentityDataRequest) if err != nil { - if res == nil { - logger.SdmLog.Errorf(err.Error()) - } else if err.Error() != res.Status { - logger.SdmLog.Errorf("Response State: %+v", err.Error()) - } else { - problemDetails := &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - c.JSON(int(problemDetails.Status), problemDetails) - return - } + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("GetIdentityData response body cannot close: %+v", rspCloseErr) - } - }() - - if res.StatusCode == http.StatusOK { - if idList := idTranslationResultResp; idList.SupiList != nil { - // GetCorrespondingSupi get corresponding Supi(here IMSI) matching the given Gpsi from the queried SUPI list from UDR - idTranslationResult.Supi = udm_context.GetCorrespondingSupi(idList) - idTranslationResult.Gpsi = gpsi - c.JSON(http.StatusOK, idTranslationResult) - } else { - problemDetails := &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "USER_NOT_FOUND", - } - c.JSON(int(problemDetails.Status), problemDetails) - } + if idList := idTranslationResultResp.IdentityData; idList.SupiList != nil { + // GetCorrespondingSupi get corresponding Supi(here IMSI) matching the given Gpsi from the queried SUPI list from UDR + idTranslationResult.Supi = udm_context.GetCorrespondingSupi(idList) + idTranslationResult.Gpsi = gpsi + c.JSON(http.StatusOK, idTranslationResult) } else { problemDetails := &models.ProblemDetails{ Status: http.StatusNotFound, - Cause: "DATA_NOT_FOUND", + Cause: "USER_NOT_FOUND", } c.JSON(int(problemDetails.Status), problemDetails) } @@ -135,7 +93,7 @@ func (p *Processor) GetSupiProcedure(c *gin.Context, dataSetNames []string, supportedFeatures string, ) { - ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) + ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NrfNfManagementNfType_UDR) if err != nil { c.JSON(int(pd.Status), pd) return @@ -162,137 +120,79 @@ func (p *Processor) GetSupiProcedure(c *gin.Context, pduSessionMap := make(map[string]models.PduSession) var pgwInfoArray []models.PgwInfo - var queryAmDataParamOpts Nudr_DataRepository.QueryAmDataParamOpts - queryAmDataParamOpts.SupportedFeatures = optional.NewString(supportedFeatures) - var querySmfSelectDataParamOpts Nudr_DataRepository.QuerySmfSelectDataParamOpts - var queryTraceDataParamOpts Nudr_DataRepository.QueryTraceDataParamOpts - var querySmDataParamOpts Nudr_DataRepository.QuerySmDataParamOpts + var queryAmDataRequest Nudr_DataRepository.QueryAmDataRequest + var querySmfSelectDataRequest Nudr_DataRepository.QuerySmfSelectDataRequest + var queryTraceDataRequest Nudr_DataRepository.QueryTraceDataRequest + var querySmDataRequest Nudr_DataRepository.QuerySmDataRequest - queryAmDataParamOpts.SupportedFeatures = optional.NewString(supportedFeatures) - querySmfSelectDataParamOpts.SupportedFeatures = optional.NewString(supportedFeatures) + queryAmDataRequest.SupportedFeatures = &supportedFeatures + queryAmDataRequest.UeId = &supi + queryAmDataRequest.ServingPlmnId = &plmnID + + querySmfSelectDataRequest.SupportedFeatures = &supportedFeatures + querySmfSelectDataRequest.UeId = &supi + querySmfSelectDataRequest.ServingPlmnId = &plmnID p.Context().CreateSubsDataSetsForUe(supi, subsDataSetBody) if p.containDataSetName(dataSetNames, string(models.DataSetName_AM)) { var body models.AccessAndMobilitySubscriptionData p.Context().CreateAccessMobilitySubsDataForUe(supi, body) - amData, res, err := clientAPI.AccessAndMobilitySubscriptionDataDocumentApi.QueryAmData( - ctx, supi, plmnID, &queryAmDataParamOpts) + amDataRsp, err := clientAPI.AccessAndMobilitySubscriptionDataDocumentApi.QueryAmData( + ctx, &queryAmDataRequest) if err != nil { - if res == nil { - logger.SdmLog.Errorf(err.Error()) - } else if err.Error() != res.Status { - logger.SdmLog.Errorf("Response State: %+v", err.Error()) - } else { - problemDetails := &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - - c.JSON(int(problemDetails.Status), problemDetails) - return - } - } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("QueryAmData response body cannot close: %+v", rspCloseErr) - } - }() - if res.StatusCode == http.StatusOK { - udmUe, ok := p.Context().UdmUeFindBySupi(supi) - if !ok { - udmUe = p.Context().NewUdmUe(supi) - } - udmUe.SetAMSubsriptionData(&amData) - subscriptionDataSets.AmData = &amData - } else { - problemDetails := &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "DATA_NOT_FOUND", - } + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } + + udmUe, ok := p.Context().UdmUeFindBySupi(supi) + if !ok { + udmUe = p.Context().NewUdmUe(supi) + } + udmUe.SetAMSubsriptionData(&amDataRsp.AccessAndMobilitySubscriptionData) + subscriptionDataSets.AmData = &amDataRsp.AccessAndMobilitySubscriptionData } if p.containDataSetName(dataSetNames, string(models.DataSetName_SMF_SEL)) { var smfSelSubsbody models.SmfSelectionSubscriptionData p.Context().CreateSmfSelectionSubsDataforUe(supi, smfSelSubsbody) - smfSelData, res, err := clientAPI.SMFSelectionSubscriptionDataDocumentApi.QuerySmfSelectData(ctx, - supi, plmnID, &querySmfSelectDataParamOpts) + smfSelDataRsp, err := clientAPI.SMFSelectionSubscriptionDataDocumentApi.QuerySmfSelectData(ctx, + &querySmfSelectDataRequest) if err != nil { - if res == nil { - logger.SdmLog.Errorln(err.Error()) - } else if err.Error() != res.Status { - logger.SdmLog.Errorln(err.Error()) - } else { - problemDetails := &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - - c.JSON(int(problemDetails.Status), problemDetails) - return - } - } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("QuerySmfSelectData response body cannot close: %+v", rspCloseErr) - } - }() - if res.StatusCode == http.StatusOK { - udmUe, ok := p.Context().UdmUeFindBySupi(supi) - if !ok { - udmUe = p.Context().NewUdmUe(supi) - } - udmUe.SetSmfSelectionSubsData(&smfSelData) - subscriptionDataSets.SmfSelData = &smfSelData - } else { - problemDetails := &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "DATA_NOT_FOUND", - } + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } - } - if p.containDataSetName(dataSetNames, string(models.DataSetName_UEC_SMF)) { + udmUe, ok := p.Context().UdmUeFindBySupi(supi) + if !ok { + udmUe = p.Context().NewUdmUe(supi) + } + udmUe.SetSmfSelectionSubsData(&smfSelDataRsp.SmfSelectionSubscriptionData) + subscriptionDataSets.SmfSelData = &smfSelDataRsp.SmfSelectionSubscriptionData + + } + if p.containDataSetName(dataSetNames, string(models.SdmDataSetName_UEC_SMF)) { var UeContextInSmfbody models.UeContextInSmfData - var querySmfRegListParamOpts Nudr_DataRepository.QuerySmfRegListParamOpts - querySmfRegListParamOpts.SupportedFeatures = optional.NewString(supportedFeatures) + var querySmfRegListRequest Nudr_DataRepository.QuerySmfRegListRequest + querySmfRegListRequest.SupportedFeatures = &supportedFeatures + querySmfRegListRequest.UeId = &supi p.Context().CreateUeContextInSmfDataforUe(supi, UeContextInSmfbody) - pdusess, res, err := clientAPI.SMFRegistrationsCollectionApi.QuerySmfRegList( - ctx, supi, &querySmfRegListParamOpts) + pdusess, err := clientAPI.SMFRegistrationsCollectionApi.QuerySmfRegList( + ctx, &querySmfRegListRequest) if err != nil { - if res == nil { - logger.SdmLog.Errorf(err.Error()) - } else if err.Error() != res.Status { - logger.SdmLog.Errorf("Response State: %+v", err.Error()) - } else { - problemDetails := &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - - c.JSON(int(problemDetails.Status), problemDetails) - return - } + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + + c.JSON(int(problemDetails.Status), problemDetails) + return } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("QuerySmfRegList response body cannot close: %+v", rspCloseErr) - } - }() - for _, element := range pdusess { + for _, element := range pdusess.SmfRegistration { var pduSession models.PduSession pduSession.Dnn = element.Dnn pduSession.SmfInstanceId = element.SmfInstanceId @@ -301,7 +201,7 @@ func (p *Processor) GetSupiProcedure(c *gin.Context, } ueContextInSmfDataResp.PduSessions = pduSessionMap - for _, element := range pdusess { + for _, element := range pdusess.SmfRegistration { var pgwInfo models.PgwInfo pgwInfo.Dnn = element.Dnn pgwInfo.PgwFqdn = element.PgwFqdn @@ -310,18 +210,13 @@ func (p *Processor) GetSupiProcedure(c *gin.Context, } ueContextInSmfDataResp.PgwInfo = pgwInfoArray - if res.StatusCode == http.StatusOK { - udmUe, ok := p.Context().UdmUeFindBySupi(supi) - if !ok { - udmUe = p.Context().NewUdmUe(supi) - } - udmUe.UeCtxtInSmfData = &ueContextInSmfDataResp - subscriptionDataSets.UecSmfData = &ueContextInSmfDataResp - } else { - var problemDetails models.ProblemDetails - problemDetails.Cause = "DATA_NOT_FOUND" - logger.SdmLog.Errorf(problemDetails.Cause) + udmUe, ok := p.Context().UdmUeFindBySupi(supi) + if !ok { + udmUe = p.Context().NewUdmUe(supi) } + udmUe.UeCtxtInSmfData = &ueContextInSmfDataResp + subscriptionDataSets.UecSmfData = &ueContextInSmfDataResp + } // TODO: UE Context in SMSF Data @@ -333,94 +228,49 @@ func (p *Processor) GetSupiProcedure(c *gin.Context, // } if p.containDataSetName(dataSetNames, string(models.DataSetName_SM)) { - sessionManagementSubscriptionData, res, err := clientAPI.SessionManagementSubscriptionDataApi. - QuerySmData(ctx, supi, plmnID, &querySmDataParamOpts) + querySmDataRequest.UeId = &supi + querySmDataRequest.ServingPlmnId = &plmnID + sessionManagementSubscriptionDataRsp, err := clientAPI.SessionManagementSubscriptionDataApi. + QuerySmData(ctx, &querySmDataRequest) if err != nil { - if res == nil { - logger.SdmLog.Errorf(err.Error()) - } else if err.Error() != res.Status { - logger.SdmLog.Errorf("Response State: %+v", err.Error()) - } else { - problemDetails := &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - - c.JSON(int(problemDetails.Status), problemDetails) - return - } - } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("QuerySmData response body cannot close: %+v", rspCloseErr) - } - }() - if res.StatusCode == http.StatusOK { - udmUe, ok := p.Context().UdmUeFindBySupi(supi) - if !ok { - udmUe = p.Context().NewUdmUe(supi) - } - smData, _, _, _ := p.Context().ManageSmData(sessionManagementSubscriptionData, "", "") - udmUe.SetSMSubsData(smData) - subscriptionDataSets.SmData = sessionManagementSubscriptionData - } else { - problemDetails := &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "DATA_NOT_FOUND", - } + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } + + udmUe, ok := p.Context().UdmUeFindBySupi(supi) + if !ok { + udmUe = p.Context().NewUdmUe(supi) + } + smData, _, _, _ := p.Context().ManageSmData(sessionManagementSubscriptionDataRsp.SmSubsData.IndividualSmSubsData, "", "") + udmUe.SetSMSubsData(smData) + subscriptionDataSets.SmData = sessionManagementSubscriptionDataRsp.SmSubsData.IndividualSmSubsData + } if p.containDataSetName(dataSetNames, string(models.DataSetName_TRACE)) { var TraceDatabody models.TraceData p.Context().CreateTraceDataforUe(supi, TraceDatabody) - traceData, res, err := clientAPI.TraceDataDocumentApi.QueryTraceData( - ctx, supi, plmnID, &queryTraceDataParamOpts) + queryTraceDataRequest.UeId = &supi + queryTraceDataRequest.ServingPlmnId = &plmnID + traceDataRsp, err := clientAPI.TraceDataDocumentApi.QueryTraceData( + ctx, &queryTraceDataRequest) if err != nil { - if res == nil { - logger.SdmLog.Errorf(err.Error()) - } else if err.Error() != res.Status { - logger.SdmLog.Errorf("Response State: %+v", err.Error()) - } else { - problemDetails := &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - c.JSON(int(problemDetails.Status), problemDetails) - return - } problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("QueryTraceData response body cannot close: %+v", rspCloseErr) - } - }() - if res.StatusCode == http.StatusOK { - udmUe, ok := p.Context().UdmUeFindBySupi(supi) - if !ok { - udmUe = p.Context().NewUdmUe(supi) - } - udmUe.TraceData = &traceData - udmUe.TraceDataResponse.TraceData = &traceData - subscriptionDataSets.TraceData = &traceData - } else { - problemDetails := &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "DATA_NOT_FOUND", - } - c.JSON(int(problemDetails.Status), problemDetails) - return + udmUe, ok := p.Context().UdmUeFindBySupi(supi) + if !ok { + udmUe = p.Context().NewUdmUe(supi) } + udmUe.TraceData = &traceDataRsp.TraceData + udmUe.TraceDataResponse.TraceData = &traceDataRsp.TraceData + subscriptionDataSets.TraceData = &traceDataRsp.TraceData + } // TODO: SMS Management Subscription Data diff --git a/internal/sbi/processor/ue_context_management.go b/internal/sbi/processor/ue_context_management.go index 9ab3b45..5d1b6e8 100644 --- a/internal/sbi/processor/ue_context_management.go +++ b/internal/sbi/processor/ue_context_management.go @@ -52,7 +52,7 @@ func (p *Processor) GetAmf3gppAccessProcedure(c *gin.Context, ueID string, suppo } func (p *Processor) GetAmfNon3gppAccessProcedure(c *gin.Context, queryAmfContextNon3gppParamOpts Nudr_DataRepository. - QueryAmfContextNon3gppParamOpts, ueID string, + QueryAmfContextNon3gppRequest, ueID String ) { ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) if err != nil { @@ -64,25 +64,16 @@ func (p *Processor) GetAmfNon3gppAccessProcedure(c *gin.Context, queryAmfContext c.JSON(int(problemDetails.Status), problemDetails) return } + amfNon3GppAccessRegistrationResponse, err := clientAPI.AMFNon3GPPAccessRegistrationDocumentApi. + QueryAmfContextNon3gpp(ctx, &queryAmfContextNon3gppParamOpts) - amfNon3GppAccessRegistration, resp, err := clientAPI.AMFNon3GPPAccessRegistrationDocumentApi. - QueryAmfContextNon3gpp(ctx, ueID, &queryAmfContextNon3gppParamOpts) if err != nil { - problemDetails := &models.ProblemDetails{ - Status: int32(resp.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } - defer func() { - if rspCloseErr := resp.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("QueryAmfContext3gpp response body cannot close: %+v", rspCloseErr) - } - }() - c.JSON(http.StatusOK, amfNon3GppAccessRegistration) + c.JSON(http.StatusOK, amfNon3GppAccessRegistrationResponse) } func (p *Processor) RegistrationAmf3gppAccessProcedure(c *gin.Context, From b0b2b8ba2ba231c600ab7802c65c735b78bb2a19 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Mon, 22 Jul 2024 07:08:24 +0000 Subject: [PATCH 04/41] feat: update processor/ue_context_management.go R17 openapi --- .../sbi/processor/ue_context_management.go | 213 +++++++++--------- 1 file changed, 104 insertions(+), 109 deletions(-) diff --git a/internal/sbi/processor/ue_context_management.go b/internal/sbi/processor/ue_context_management.go index 5d1b6e8..75df857 100644 --- a/internal/sbi/processor/ue_context_management.go +++ b/internal/sbi/processor/ue_context_management.go @@ -4,7 +4,6 @@ import ( "net/http" "strconv" - "github.com/antihax/optional" "github.com/gin-gonic/gin" "github.com/free5gc/openapi" @@ -16,13 +15,14 @@ import ( // ue_context_managemanet_service func (p *Processor) GetAmf3gppAccessProcedure(c *gin.Context, ueID string, supportedFeatures string) { - ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) + ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NrfNfManagementNfType_UDR) if err != nil { c.JSON(int(pd.Status), pd) return } - var queryAmfContext3gppParamOpts Nudr_DataRepository.QueryAmfContext3gppParamOpts - queryAmfContext3gppParamOpts.SupportedFeatures = optional.NewString(supportedFeatures) + var queryAmfContext3gppRequest Nudr_DataRepository.QueryAmfContext3gppRequest + queryAmfContext3gppRequest.UeId = &ueID + queryAmfContext3gppRequest.SupportedFeatures = &supportedFeatures clientAPI, err := p.Consumer().CreateUDMClientToUDR(ueID) if err != nil { @@ -31,30 +31,25 @@ func (p *Processor) GetAmf3gppAccessProcedure(c *gin.Context, ueID string, suppo return } - amf3GppAccessRegistration, resp, err := clientAPI.AMF3GPPAccessRegistrationDocumentApi. - QueryAmfContext3gpp(ctx, ueID, &queryAmfContext3gppParamOpts) + amf3GppAccessRegistration, err := clientAPI.AMF3GPPAccessRegistrationDocumentApi. + QueryAmfContext3gpp(ctx, &queryAmfContext3gppRequest) if err != nil { - problemDetails := &models.ProblemDetails{ - Status: int32(resp.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), + problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + if !ok { + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } - c.JSON(int(problemDetails.Status), problemDetails) + c.JSON(int(problem.Status), problem) return } - defer func() { - if rspCloseErr := resp.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("QueryAmfContext3gpp response body cannot close: %+v", rspCloseErr) - } - }() c.JSON(http.StatusOK, amf3GppAccessRegistration) } func (p *Processor) GetAmfNon3gppAccessProcedure(c *gin.Context, queryAmfContextNon3gppParamOpts Nudr_DataRepository. - QueryAmfContextNon3gppRequest, ueID String -) { - ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) + QueryAmfContextNon3gppRequest, ueID string) { + ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NrfNfManagementNfType_UDR) if err != nil { c.JSON(int(pd.Status), pd) } @@ -68,8 +63,13 @@ func (p *Processor) GetAmfNon3gppAccessProcedure(c *gin.Context, queryAmfContext QueryAmfContextNon3gpp(ctx, &queryAmfContextNon3gppParamOpts) if err != nil { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + if !ok { + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return + } + c.JSON(int(problem.Status), problem) return } @@ -80,7 +80,7 @@ func (p *Processor) RegistrationAmf3gppAccessProcedure(c *gin.Context, registerRequest models.Amf3GppAccessRegistration, ueID string, ) { - ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) + ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NrfNfManagementNfType_UDR) if err != nil { c.JSON(int(pd.Status), pd) return @@ -103,26 +103,21 @@ func (p *Processor) RegistrationAmf3gppAccessProcedure(c *gin.Context, return } - var createAmfContext3gppParamOpts Nudr_DataRepository.CreateAmfContext3gppParamOpts - optInterface := optional.NewInterface(registerRequest) - createAmfContext3gppParamOpts.Amf3GppAccessRegistration = optInterface - resp, err := clientAPI.AMF3GPPAccessRegistrationDocumentApi.CreateAmfContext3gpp(ctx, - ueID, &createAmfContext3gppParamOpts) + var createAmfContext3gppRequest Nudr_DataRepository.CreateAmfContext3gppRequest + createAmfContext3gppRequest.UeId = &ueID + createAmfContext3gppRequest.Amf3GppAccessRegistration = ®isterRequest + _, err = clientAPI.AMF3GPPAccessRegistrationDocumentApi.CreateAmfContext3gpp(ctx, + &createAmfContext3gppRequest) if err != nil { - logger.UecmLog.Errorln("CreateAmfContext3gpp error : ", err) - problemDetails := &models.ProblemDetails{ - Status: int32(resp.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), + problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + if !ok { + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } - c.JSON(int(problemDetails.Status), problemDetails) + c.JSON(int(problem.Status), problem) return } - defer func() { - if rspCloseErr := resp.Body.Close(); rspCloseErr != nil { - logger.UecmLog.Errorf("CreateAmfContext3gpp response body cannot close: %+v", rspCloseErr) - } - }() // TS 23.502 4.2.2.2.2 14d: UDM initiate a Nudm_UECM_DeregistrationNotification to the old AMF // corresponding to the same (e.g. 3GPP) access, if one exists @@ -163,7 +158,7 @@ func (p *Processor) RegisterAmfNon3gppAccessProcedure(c *gin.Context, registerRequest models.AmfNon3GppAccessRegistration, ueID string, ) { - ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) + ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NrfNfManagementNfType_UDR) if err != nil { c.JSON(int(pd.Status), pd) return @@ -183,27 +178,23 @@ func (p *Processor) RegisterAmfNon3gppAccessProcedure(c *gin.Context, return } - var createAmfContextNon3gppParamOpts Nudr_DataRepository.CreateAmfContextNon3gppParamOpts - optInterface := optional.NewInterface(registerRequest) - createAmfContextNon3gppParamOpts.AmfNon3GppAccessRegistration = optInterface + var createAmfContextNon3gppRequest Nudr_DataRepository.CreateAmfContextNon3gppRequest + createAmfContextNon3gppRequest.UeId = &ueID + createAmfContextNon3gppRequest.AmfNon3GppAccessRegistration = ®isterRequest + + _, err = clientAPI.AMFNon3GPPAccessRegistrationDocumentApi.CreateAmfContextNon3gpp( + ctx, &createAmfContextNon3gppRequest) - resp, err := clientAPI.AMFNon3GPPAccessRegistrationDocumentApi.CreateAmfContextNon3gpp( - ctx, ueID, &createAmfContextNon3gppParamOpts) if err != nil { - problemDetails := &models.ProblemDetails{ - Status: int32(resp.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), + problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + if !ok { + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } - - c.JSON(int(problemDetails.Status), problemDetails) + c.JSON(int(problem.Status), problem) return } - defer func() { - if rspCloseErr := resp.Body.Close(); rspCloseErr != nil { - logger.UecmLog.Errorf("CreateAmfContext3gpp response body cannot close: %+v", rspCloseErr) - } - }() // TS 23.502 4.2.2.2.2 14d: UDM initiate a Nudm_UECM_DeregistrationNotification to the old AMF // corresponding to the same (e.g. 3GPP) access, if one exists @@ -227,7 +218,7 @@ func (p *Processor) UpdateAmf3gppAccessProcedure(c *gin.Context, request models.Amf3GppAccessRegistrationModification, ueID string, ) { - ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) + ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NrfNfManagementNfType_UDR) if err != nil { c.JSON(int(pd.Status), pd) return @@ -305,15 +296,20 @@ func (p *Processor) UpdateAmf3gppAccessProcedure(c *gin.Context, return } - resp, err := clientAPI.AMF3GPPAccessRegistrationDocumentApi.AmfContext3gpp(ctx, ueID, - patchItemReqArray) + var amfContext3gppRequest Nudr_DataRepository.AmfContext3gppRequest + amfContext3gppRequest.UeId = &ueID + amfContext3gppRequest.PatchItem = patchItemReqArray + _, err = clientAPI.AMF3GPPAccessRegistrationDocumentApi.AmfContext3gpp(ctx, + &amfContext3gppRequest) + if err != nil { - problemDetails := &models.ProblemDetails{ - Status: int32(resp.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), + problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + if !ok { + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } - c.JSON(int(problemDetails.Status), problemDetails) + c.JSON(int(problem.Status), problem) return } @@ -322,12 +318,6 @@ func (p *Processor) UpdateAmf3gppAccessProcedure(c *gin.Context, udmUe.Amf3GppAccessRegistration = nil } - defer func() { - if rspCloseErr := resp.Body.Close(); rspCloseErr != nil { - logger.UecmLog.Errorf("AmfContext3gpp response body cannot close: %+v", rspCloseErr) - } - }() - c.Status(http.StatusNoContent) } @@ -335,7 +325,7 @@ func (p *Processor) UpdateAmfNon3gppAccessProcedure(c *gin.Context, request models.AmfNon3GppAccessRegistrationModification, ueID string, ) { - ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) + ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NrfNfManagementNfType_UDR) if err != nil { c.JSON(int(pd.Status), pd) return @@ -412,23 +402,22 @@ func (p *Processor) UpdateAmfNon3gppAccessProcedure(c *gin.Context, c.JSON(int(problemDetails.Status), problemDetails) return } + var amfContextNon3gppRequest Nudr_DataRepository.AmfContextNon3gppRequest + amfContextNon3gppRequest.UeId = &ueID + amfContextNon3gppRequest.PatchItem = patchItemReqArray + _, err = clientAPI.AMFNon3GPPAccessRegistrationDocumentApi.AmfContextNon3gpp(ctx, + &amfContextNon3gppRequest) - resp, err := clientAPI.AMFNon3GPPAccessRegistrationDocumentApi.AmfContextNon3gpp(ctx, - ueID, patchItemReqArray) if err != nil { - problemDetails := &models.ProblemDetails{ - Status: int32(resp.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), + problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + if !ok { + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } - c.JSON(int(problemDetails.Status), problemDetails) + c.JSON(int(problem.Status), problem) return } - defer func() { - if rspCloseErr := resp.Body.Close(); rspCloseErr != nil { - logger.UecmLog.Errorf("AmfContextNon3gpp response body cannot close: %+v", rspCloseErr) - } - }() c.Status(http.StatusNoContent) } @@ -437,11 +426,12 @@ func (p *Processor) DeregistrationSmfRegistrationsProcedure(c *gin.Context, ueID string, pduSessionID string, ) { - ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) + ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NrfNfManagementNfType_UDR) if err != nil { c.JSON(int(pd.Status), pd) return } + clientAPI, err := p.Consumer().CreateUDMClientToUDR(ueID) if err != nil { problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) @@ -449,21 +439,30 @@ func (p *Processor) DeregistrationSmfRegistrationsProcedure(c *gin.Context, return } - resp, err := clientAPI.SMFRegistrationDocumentApi.DeleteSmfContext(ctx, ueID, pduSessionID) + var pduSessionIDInt32 int32 + num, err := strconv.ParseInt(pduSessionID, 10, 32) if err != nil { - problemDetails := &models.ProblemDetails{ - Status: int32(resp.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } - defer func() { - if rspCloseErr := resp.Body.Close(); rspCloseErr != nil { - logger.UecmLog.Errorf("DeleteSmfContext response body cannot close: %+v", rspCloseErr) + + pduSessionIDInt32 = int32(num) + var deleteSmfRegistrationRequest Nudr_DataRepository.DeleteSmfRegistrationRequest + deleteSmfRegistrationRequest.UeId = &ueID + deleteSmfRegistrationRequest.PduSessionId = &pduSessionIDInt32 + _, err = clientAPI.SMFRegistrationDocumentApi.DeleteSmfRegistration(ctx, &deleteSmfRegistrationRequest) + + if err != nil { + problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + if !ok { + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } - }() + c.JSON(int(problem.Status), problem) + return + } c.Status(http.StatusNoContent) } @@ -474,7 +473,7 @@ func (p *Processor) RegistrationSmfRegistrationsProcedure( ueID string, pduSessionID string, ) { - ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) + ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NrfNfManagementNfType_UDR) if err != nil { c.JSON(int(pd.Status), pd) return @@ -491,9 +490,10 @@ func (p *Processor) RegistrationSmfRegistrationsProcedure( } pduID32 := int32(pduID64) - var createSmfContextNon3gppParamOpts Nudr_DataRepository.CreateSmfContextNon3gppParamOpts - optInterface := optional.NewInterface(*smfRegistration) - createSmfContextNon3gppParamOpts.SmfRegistration = optInterface + var createSmfContext3gppRequest Nudr_DataRepository.CreateOrUpdateSmfRegistrationRequest + createSmfContext3gppRequest.UeId = &ueID + createSmfContext3gppRequest.SmfRegistration = smfRegistration + createSmfContext3gppRequest.PduSessionId = &pduID32 clientAPI, err := p.Consumer().CreateUDMClientToUDR(ueID) if err != nil { @@ -501,23 +501,18 @@ func (p *Processor) RegistrationSmfRegistrationsProcedure( c.JSON(int(problemDetails.Status), problemDetails) return } + _, err = clientAPI.SMFRegistrationDocumentApi.CreateOrUpdateSmfRegistration(ctx, &createSmfContext3gppRequest) - resp, err := clientAPI.SMFRegistrationDocumentApi.CreateSmfContextNon3gpp(ctx, ueID, - pduID32, &createSmfContextNon3gppParamOpts) if err != nil { - problemDetails := &models.ProblemDetails{ - Status: int32(resp.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), + problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + if !ok { + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return } - c.JSON(int(problemDetails.Status), problemDetails) + c.JSON(int(problem.Status), problem) return } - defer func() { - if rspCloseErr := resp.Body.Close(); rspCloseErr != nil { - logger.UecmLog.Errorf("CreateSmfContextNon3gpp response body cannot close: %+v", rspCloseErr) - } - }() if contextExisted { c.Status(http.StatusNoContent) From f5d7d3bbc80fb65a265ca2867631ffdc68d5b712 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Mon, 22 Jul 2024 07:25:45 +0000 Subject: [PATCH 05/41] feat: update processor/parameter_provision.go problemdetail --- internal/sbi/processor/parameter_provision.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/sbi/processor/parameter_provision.go b/internal/sbi/processor/parameter_provision.go index d4da027..fd085c1 100644 --- a/internal/sbi/processor/parameter_provision.go +++ b/internal/sbi/processor/parameter_provision.go @@ -28,9 +28,15 @@ func (p *Processor) UpdateProcedure(c *gin.Context, var modifyPpDataRequest Nudr_DataRepository.ModifyPpDataRequest modifyPpDataRequest.UeId = &gpsi modifyPpDataRsp, err := clientAPI.ProvisionedParameterDataDocumentApi.ModifyPpData(ctx, &modifyPpDataRequest) + if err != nil { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + if !ok { + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return + } + c.JSON(int(problem.Status), problem) return } From 1c2353bff131286af025dfa166bfd4148e483941 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Mon, 22 Jul 2024 07:29:29 +0000 Subject: [PATCH 06/41] feat: update processor/generate_auth_date.go problemdetail --- internal/sbi/processor/generate_auth_data.go | 25 +++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/internal/sbi/processor/generate_auth_data.go b/internal/sbi/processor/generate_auth_data.go index 8ab1c90..9756dd1 100644 --- a/internal/sbi/processor/generate_auth_data.go +++ b/internal/sbi/processor/generate_auth_data.go @@ -79,7 +79,7 @@ func (p *Processor) ConfirmAuthDataProcedure(c *gin.Context, authEvent models.AuthEvent, supi string, ) { - ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) + ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NrfNfManagementNfType_UDR) if err != nil { c.JSON(int(pd.Status), pd) return @@ -98,9 +98,14 @@ func (p *Processor) ConfirmAuthDataProcedure(c *gin.Context, createAuthStatusResponse, err := client.AuthenticationStatusDocumentApi.CreateAuthenticationStatus( ctx, &createAuthStatusRequest) if err != nil { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + if !ok { + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return + } logger.UeauLog.Errorln("ConfirmAuth err:", err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + c.JSON(int(problem.Status), problem) return } @@ -112,7 +117,7 @@ func (p *Processor) GenerateAuthDataProcedure( authInfoRequest models.AuthenticationInfoRequest, supiOrSuci string, ) { - ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) + ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NrfNfManagementNfType_UDR) if err != nil { c.JSON(int(pd.Status), pd) return @@ -148,15 +153,19 @@ func (p *Processor) GenerateAuthDataProcedure( authSubs, err := client.AuthenticationDataDocumentApi.QueryAuthSubsData(ctx, &queryAuthSubsDataRequest) if err != nil { - - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - switch problemDetails.Status { + problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + if !ok { + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return + } + switch problem.Status { case http.StatusNotFound: logger.UeauLog.Warnf("Return from UDR QueryAuthSubsData error") default: logger.UeauLog.Errorln("Return from UDR QueryAuthSubsData error") } - c.JSON(int(problemDetails.Status), problemDetails) + c.JSON(int(problem.Status), problem) return } From 9caaec91ce4e62d24eb15af070cf15625d364dda Mon Sep 17 00:00:00 2001 From: ubuntu Date: Mon, 22 Jul 2024 10:09:55 +0000 Subject: [PATCH 07/41] feat: update processor/notifier.go R17 openapi --- internal/sbi/processor/notifier.go | 71 +++++++------------ .../sbi/processor/ue_context_management.go | 10 +-- 2 files changed, 29 insertions(+), 52 deletions(-) diff --git a/internal/sbi/processor/notifier.go b/internal/sbi/processor/notifier.go index 4e16b71..bd92fde 100644 --- a/internal/sbi/processor/notifier.go +++ b/internal/sbi/processor/notifier.go @@ -1,11 +1,12 @@ package processor import ( - "net/http" - "github.com/gin-gonic/gin" + "github.com/free5gc/openapi" "github.com/free5gc/openapi/models" + "github.com/free5gc/openapi/udm/SubscriberDataManagement" + "github.com/free5gc/openapi/udm/UEContextManagement" "github.com/free5gc/udm/internal/logger" ) @@ -13,7 +14,7 @@ func (p *Processor) DataChangeNotificationProcedure(c *gin.Context, notifyItems []models.NotifyItem, supi string, ) { - ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDM_SDM, models.NfType_UDM) + ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDM_SDM, models.NrfNfManagementNfType_UDM) if err != nil { c.JSON(int(pd.Status), pd) return @@ -28,73 +29,49 @@ func (p *Processor) DataChangeNotificationProcedure(c *gin.Context, onDataChangeNotificationurl := subscriptionDataSubscription.OriginalCallbackReference dataChangeNotification := models.ModificationNotification{} dataChangeNotification.NotifyItems = notifyItems - - httpResponse, err := clientAPI.DataChangeNotificationCallbackDocumentApi.OnDataChangeNotification( - ctx, onDataChangeNotificationurl, dataChangeNotification) + var subDataChangeNotificationPostRequest SubscriberDataManagement.SubscribeDatachangeNotificationPostRequest + subDataChangeNotificationPostRequest.ModificationNotification = &dataChangeNotification + _, err = clientAPI.SubscriptionCreationApi.SubscribeDatachangeNotificationPost( + ctx, onDataChangeNotificationurl, &subDataChangeNotificationPostRequest) if err != nil { - if httpResponse == nil { + problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + if !ok { logger.HttpLog.Error(err.Error()) - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Detail: err.Error(), - } + problemDetails = openapi.ProblemDetailsSystemFailure(err.Error()) } else { logger.HttpLog.Errorln(err.Error()) - - problemDetails = &models.ProblemDetails{ - Status: int32(httpResponse.StatusCode), - Detail: err.Error(), - } + problemDetails = &problem } } - defer func() { - if rspCloseErr := httpResponse.Body.Close(); rspCloseErr != nil { - logger.HttpLog.Errorf("OnDataChangeNotification response body cannot close: %+v", rspCloseErr) - } - }() } c.JSON(int(problemDetails.Status), problemDetails) } func (p *Processor) SendOnDeregistrationNotification(ueId string, onDeregistrationNotificationUrl string, - deregistData models.DeregistrationData, + deregistData models.UdmUecmDeregistrationData, ) *models.ProblemDetails { - ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDM_UECM, models.NfType_UDM) + ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDM_UECM, models.NrfNfManagementNfType_UDM) if err != nil { return pd } clientAPI := p.Consumer().GetUECMClient("SendOnDeregistrationNotification") + var call3GppRegistrationDeregistrationNotificationPostRequest UEContextManagement.Call3GppRegistrationDeregistrationNotificationPostRequest + call3GppRegistrationDeregistrationNotificationPostRequest.UdmUecmDeregistrationData = &deregistData + _, err = clientAPI.AMFRegistrationFor3GPPAccessApi. + Call3GppRegistrationDeregistrationNotificationPost(ctx, + onDeregistrationNotificationUrl, + &call3GppRegistrationDeregistrationNotificationPostRequest) - httpResponse, err := clientAPI.DeregistrationNotificationCallbackApi.DeregistrationNotify( - ctx, onDeregistrationNotificationUrl, deregistData) if err != nil { - if httpResponse == nil { - logger.HttpLog.Error(err.Error()) - problemDetails := &models.ProblemDetails{ - Status: http.StatusInternalServerError, - Cause: "DEREGISTRATION_NOTIFICATION_ERROR", - Detail: err.Error(), - } - - return problemDetails - } else { - logger.HttpLog.Errorln(err.Error()) - problemDetails := &models.ProblemDetails{ - Status: int32(httpResponse.StatusCode), - Cause: "DEREGISTRATION_NOTIFICATION_ERROR", - Detail: err.Error(), - } - + problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + if !ok { + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) return problemDetails } + return &problem } - defer func() { - if rspCloseErr := httpResponse.Body.Close(); rspCloseErr != nil { - logger.HttpLog.Errorf("DeregistrationNotify response body cannot close: %+v", rspCloseErr) - } - }() return nil } diff --git a/internal/sbi/processor/ue_context_management.go b/internal/sbi/processor/ue_context_management.go index 75df857..e546309 100644 --- a/internal/sbi/processor/ue_context_management.go +++ b/internal/sbi/processor/ue_context_management.go @@ -126,11 +126,11 @@ func (p *Processor) RegistrationAmf3gppAccessProcedure(c *gin.Context, // Based on TS 23.502 4.2.2.2.2, If the serving NF removal reason indicated by the UDM is Initial Registration, // the old AMF invokes the Nsmf_PDUSession_ReleaseSMContext (SM Context ID). Thus we give different // dereg cause based on registration parameter from serving AMF - deregReason := models.DeregistrationReason_UE_REGISTRATION_AREA_CHANGE + deregReason := models.UdmUecmDeregistrationReason_UE_REGISTRATION_AREA_CHANGE if registerRequest.InitialRegistrationInd { - deregReason = models.DeregistrationReason_UE_INITIAL_REGISTRATION + deregReason = models.UdmUecmDeregistrationReason_UE_INITIAL_REGISTRATION } - deregistData := models.DeregistrationData{ + deregistData := models.UdmUecmDeregistrationData{ DeregReason: deregReason, AccessType: models.AccessType__3_GPP_ACCESS, } @@ -199,8 +199,8 @@ func (p *Processor) RegisterAmfNon3gppAccessProcedure(c *gin.Context, // TS 23.502 4.2.2.2.2 14d: UDM initiate a Nudm_UECM_DeregistrationNotification to the old AMF // corresponding to the same (e.g. 3GPP) access, if one exists if oldAmfNon3GppAccessRegContext != nil { - deregistData := models.DeregistrationData{ - DeregReason: models.DeregistrationReason_UE_INITIAL_REGISTRATION, + deregistData := models.UdmUecmDeregistrationData{ + DeregReason: models.UdmUecmDeregistrationReason_UE_INITIAL_REGISTRATION, AccessType: models.AccessType_NON_3_GPP_ACCESS, } p.SendOnDeregistrationNotification(ueID, oldAmfNon3GppAccessRegContext.DeregCallbackUri, From ce26cabdc17f49857d220c98df4d93e8c5115fea Mon Sep 17 00:00:00 2001 From: ubuntu Date: Fri, 26 Jul 2024 08:01:57 +0000 Subject: [PATCH 08/41] feat: update processor/subscriber_data_management.go R17 openapi --- go.mod | 3 +- go.sum | 6 +- internal/context/context.go | 18 +- .../processor/subscriber_data_management.go | 742 +++++++----------- 4 files changed, 292 insertions(+), 477 deletions(-) diff --git a/go.mod b/go.mod index ae3051d..9e45931 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,8 @@ module github.com/free5gc/udm go 1.21 require ( - github.com/antihax/optional v1.0.0 github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d - github.com/free5gc/openapi v1.0.9-0.20240423070630-14913ab805dc + github.com/free5gc/openapi v1.0.9-0.20240718074746-f272c26db1c3 github.com/free5gc/util v1.0.6 github.com/gin-gonic/gin v1.9.1 github.com/google/uuid v1.3.0 diff --git a/go.sum b/go.sum index cb6fe2a..d474fcd 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,4 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/antihax/optional v1.0.0 h1:xK2lYat7ZLaVVcIuj82J8kIro4V6kDe0AUDFboUCwcg= -github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d h1:Byv0BzEl3/e6D5CLfI0j/7hiIEtvGVFPCZ7Ei2oq8iQ= github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= @@ -17,8 +15,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= -github.com/free5gc/openapi v1.0.9-0.20240423070630-14913ab805dc h1:dBHbIEMOfNr9gnDVRwbN3P4bZ/Y8K8X9hO4qs37Hncs= -github.com/free5gc/openapi v1.0.9-0.20240423070630-14913ab805dc/go.mod h1:oy68rqnHakRLUCuEOXcis7/PWGBuil+UaXMeTBeYY8Y= +github.com/free5gc/openapi v1.0.9-0.20240718074746-f272c26db1c3 h1:IY37zQ+nXFGhCNy0V0jXTMVG00j61dtC67GMg+8j2kU= +github.com/free5gc/openapi v1.0.9-0.20240718074746-f272c26db1c3/go.mod h1:oy68rqnHakRLUCuEOXcis7/PWGBuil+UaXMeTBeYY8Y= github.com/free5gc/util v1.0.6 h1:dBt9drcXtYKE/cY5XuQcuffgsYclPIpIArhSeS6M+DQ= github.com/free5gc/util v1.0.6/go.mod h1:eSGN7POUM8LNTvg/E591XR6447a6/w1jFWGKNZPHcXw= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= diff --git a/internal/context/context.go b/internal/context/context.go index bcd7c34..61ddbe8 100644 --- a/internal/context/context.go +++ b/internal/context/context.go @@ -32,7 +32,7 @@ const ( ) func Init() { - GetSelf().NfService = make(map[models.ServiceName]models.NrfNfManagementNfService) + GetSelf().NfService = make(map[models.ServiceName]models.NfService) GetSelf().EeSubscriptionIDGenerator = idgenerator.NewGenerator(1, math.MaxInt32) InitUdmContext(GetSelf()) } @@ -50,14 +50,14 @@ type UDMContext struct { RegisterIPv4 string // IP register to NRF BindingIPv4 string UriScheme models.UriScheme - NfService map[models.ServiceName]models.NrfNfManagementNfService + NfService map[models.ServiceName]models.NfService NFDiscoveryClient *Nnrf_NFDiscovery.APIClient UdmUePool sync.Map // map[supi]*UdmUeContext NrfUri string NrfCertPem string GpsiSupiList models.IdentityData - SharedSubsDataMap map[string]models.SharedData // sharedDataIds as key - SubscriptionOfSharedDataChange sync.Map // subscriptionID as key + SharedSubsDataMap map[string]models.UdmSdmSharedData // sharedDataIds as key + SubscriptionOfSharedDataChange sync.Map // subscriptionID as key SuciProfiles []suci.SuciProfile EeSubscriptionIDGenerator *idgenerator.IDGenerator OAuth2Required bool @@ -170,15 +170,15 @@ func (context *UDMContext) ManageSmData(smDatafromUDR []models.SessionManagement } // HandleGetSharedData related functions -func MappingSharedData(sharedDatafromUDR []models.SharedData) (mp map[string]models.SharedData) { - sharedSubsDataMap := make(map[string]models.SharedData) +func MappingSharedData(sharedDatafromUDR []models.UdmSdmSharedData) (mp map[string]models.UdmSdmSharedData) { + sharedSubsDataMap := make(map[string]models.UdmSdmSharedData) for i := 0; i < len(sharedDatafromUDR); i++ { sharedSubsDataMap[sharedDatafromUDR[i].SharedDataId] = sharedDatafromUDR[i] } return sharedSubsDataMap } -func ObtainRequiredSharedData(Sharedids []string, response []models.SharedData) (sharedDatas []models.SharedData) { +func ObtainRequiredSharedData(Sharedids []string, response []models.UdmSdmSharedData) (sharedDatas []models.UdmSdmSharedData) { sharedSubsDataMap := MappingSharedData(response) Allkeys := make([]string, len(sharedSubsDataMap)) MatchedKeys := make([]string, len(Sharedids)) @@ -196,7 +196,7 @@ func ObtainRequiredSharedData(Sharedids []string, response []models.SharedData) counter += 1 } - shared_Data := make([]models.SharedData, len(MatchedKeys)) + shared_Data := make([]models.UdmSdmSharedData, len(MatchedKeys)) if len(MatchedKeys) != 1 { for i := 0; i < len(MatchedKeys); i++ { shared_Data[i] = sharedSubsDataMap[MatchedKeys[i]] @@ -467,7 +467,7 @@ func (context *UDMContext) InitNFService(serviceName []string, version string) { versionUri := "v" + tmpVersion[0] for index, nameString := range serviceName { name := models.ServiceName(nameString) - context.NfService[name] = models.NrfNfManagementNfService{ + context.NfService[name] = models.NfService{ ServiceInstanceId: strconv.Itoa(index), ServiceName: name, Versions: []models.NfServiceVersion{ diff --git a/internal/sbi/processor/subscriber_data_management.go b/internal/sbi/processor/subscriber_data_management.go index 95fc58e..5e14fc2 100644 --- a/internal/sbi/processor/subscriber_data_management.go +++ b/internal/sbi/processor/subscriber_data_management.go @@ -4,11 +4,11 @@ import ( "net/http" "strconv" - "github.com/antihax/optional" "github.com/gin-gonic/gin" "github.com/free5gc/openapi" "github.com/free5gc/openapi/models" + "github.com/free5gc/openapi/udm/SubscriberDataManagement" Nudr_DataRepository "github.com/free5gc/openapi/udr/DataRepository" udm_context "github.com/free5gc/udm/internal/context" "github.com/free5gc/udm/internal/logger" @@ -34,8 +34,13 @@ func (p *Processor) GetAmDataProcedure(c *gin.Context, supi string, plmnID strin accessAndMobilitySubscriptionDataResp, err := clientAPI.AccessAndMobilitySubscriptionDataDocumentApi. QueryAmData(ctx, &queryAmDataRequest) if err != nil { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + if !ok { + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return + } + c.JSON(int(problem.Status), problem) return } @@ -70,9 +75,16 @@ func (p *Processor) GetIdTranslationResultProcedure(c *gin.Context, gpsi string) idTranslationResultResp, err := clientAPI.QueryIdentityDataBySUPIOrGPSIDocumentApi.GetIdentityData( ctx, &getIdentityDataRequest) if err != nil { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + if !ok { + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return + } + c.JSON(int(problem.Status), problem) + return } + if idList := idTranslationResultResp.IdentityData; idList.SupiList != nil { // GetCorrespondingSupi get corresponding Supi(here IMSI) matching the given Gpsi from the queried SUPI list from UDR idTranslationResult.Supi = udm_context.GetCorrespondingSupi(idList) @@ -81,7 +93,7 @@ func (p *Processor) GetIdTranslationResultProcedure(c *gin.Context, gpsi string) } else { problemDetails := &models.ProblemDetails{ Status: http.StatusNotFound, - Cause: "USER_NOT_FOUND", + Cause: "DATA_NOT_FOUND", } c.JSON(int(problemDetails.Status), problemDetails) } @@ -141,9 +153,13 @@ func (p *Processor) GetSupiProcedure(c *gin.Context, amDataRsp, err := clientAPI.AccessAndMobilitySubscriptionDataDocumentApi.QueryAmData( ctx, &queryAmDataRequest) if err != nil { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - - c.JSON(int(problemDetails.Status), problemDetails) + problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + if !ok { + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return + } + c.JSON(int(problem.Status), problem) return } @@ -162,9 +178,13 @@ func (p *Processor) GetSupiProcedure(c *gin.Context, smfSelDataRsp, err := clientAPI.SMFSelectionSubscriptionDataDocumentApi.QuerySmfSelectData(ctx, &querySmfSelectDataRequest) if err != nil { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - - c.JSON(int(problemDetails.Status), problemDetails) + problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + if !ok { + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return + } + c.JSON(int(problem.Status), problem) return } @@ -186,9 +206,13 @@ func (p *Processor) GetSupiProcedure(c *gin.Context, pdusess, err := clientAPI.SMFRegistrationsCollectionApi.QuerySmfRegList( ctx, &querySmfRegListRequest) if err != nil { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - - c.JSON(int(problemDetails.Status), problemDetails) + problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + if !ok { + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return + } + c.JSON(int(problem.Status), problem) return } @@ -233,9 +257,13 @@ func (p *Processor) GetSupiProcedure(c *gin.Context, sessionManagementSubscriptionDataRsp, err := clientAPI.SessionManagementSubscriptionDataApi. QuerySmData(ctx, &querySmDataRequest) if err != nil { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - - c.JSON(int(problemDetails.Status), problemDetails) + problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + if !ok { + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return + } + c.JSON(int(problem.Status), problem) return } @@ -258,8 +286,13 @@ func (p *Processor) GetSupiProcedure(c *gin.Context, traceDataRsp, err := clientAPI.TraceDataDocumentApi.QueryTraceData( ctx, &queryTraceDataRequest) if err != nil { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + if !ok { + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return + } + c.JSON(int(problem.Status), problem) return } @@ -281,7 +314,7 @@ func (p *Processor) GetSupiProcedure(c *gin.Context, } func (p *Processor) GetSharedDataProcedure(c *gin.Context, sharedDataIds []string, supportedFeatures string) { - ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) + ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NrfNfManagementNfType_UDR) if err != nil { c.JSON(int(pd.Status), pd) return @@ -293,45 +326,26 @@ func (p *Processor) GetSharedDataProcedure(c *gin.Context, sharedDataIds []strin return } - var getSharedDataParamOpts Nudr_DataRepository.GetSharedDataParamOpts - getSharedDataParamOpts.SupportedFeatures = optional.NewString(supportedFeatures) + var getSharedDataRequest Nudr_DataRepository.GetSharedDataRequest + getSharedDataRequest.SupportedFeatures = &supportedFeatures + getSharedDataRequest.SharedDataIds = sharedDataIds - sharedDataResp, res, err := clientAPI.RetrievalOfSharedDataApi.GetSharedData(ctx, sharedDataIds, - &getSharedDataParamOpts) + sharedDataResp, err := clientAPI.RetrievalOfSharedDataApi.GetSharedData(ctx, + &getSharedDataRequest) if err != nil { - if res == nil { - logger.SdmLog.Warnln(err) - } else if err.Error() != res.Status { - logger.SdmLog.Warnln(err) - } else { - logger.SdmLog.Warnln(err) - problemDetails := &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - + problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + if !ok { + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } + c.JSON(int(problem.Status), problem) + return } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("GetShareData response body cannot close: %+v", rspCloseErr) - } - }() - if res.StatusCode == http.StatusOK { - p.Context().SharedSubsDataMap = udm_context.MappingSharedData(sharedDataResp) - sharedData := udm_context.ObtainRequiredSharedData(sharedDataIds, sharedDataResp) - c.JSON(http.StatusOK, sharedData) - } else { - problemDetails := &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "DATA_NOT_FOUND", - } - c.JSON(int(problemDetails.Status), problemDetails) - } + p.Context().SharedSubsDataMap = udm_context.MappingSharedData(sharedDataResp.UdmSdmSharedData) + sharedData := udm_context.ObtainRequiredSharedData(sharedDataIds, sharedDataResp.UdmSdmSharedData) + c.JSON(http.StatusOK, sharedData) } func (p *Processor) GetSmDataProcedure( @@ -342,7 +356,7 @@ func (p *Processor) GetSmDataProcedure( Snssai string, supportedFeatures string, ) { - ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) + ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NrfNfManagementNfType_UDR) if err != nil { c.JSON(int(pd.Status), pd) } @@ -355,84 +369,76 @@ func (p *Processor) GetSmDataProcedure( return } - var querySmDataParamOpts Nudr_DataRepository.QuerySmDataParamOpts - querySmDataParamOpts.SingleNssai = optional.NewInterface(Snssai) + var querySmDataRequest Nudr_DataRepository.QuerySmDataRequest + modelSnassai, err := openapi.SnssaiHexToModels(Snssai) + if err != nil { + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return + } + querySmDataRequest.SingleNssai = modelSnassai + querySmDataRequest.UeId = &supi + querySmDataRequest.ServingPlmnId = &plmnID - sessionManagementSubscriptionDataResp, res, err := clientAPI.SessionManagementSubscriptionDataApi. - QuerySmData(ctx, supi, plmnID, &querySmDataParamOpts) + sessionManagementSubscriptionDataResp, err := clientAPI.SessionManagementSubscriptionDataApi. + QuerySmData(ctx, &querySmDataRequest) if err != nil { - if res == nil { - logger.SdmLog.Warnln(err) - } else if err.Error() != res.Status { - logger.SdmLog.Warnln(err) - } else { - logger.SdmLog.Warnln(err) - problemDetails := &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } + problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + if !ok { + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } + c.JSON(int(problem.Status), problem) + return } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("QuerySmData response body cannot close: %+v", rspCloseErr) - } - }() - if res.StatusCode == http.StatusOK { - udmUe, ok := p.Context().UdmUeFindBySupi(supi) - if !ok { - udmUe = p.Context().NewUdmUe(supi) - } - smData, snssaikey, AllDnnConfigsbyDnn, AllDnns := p.Context().ManageSmData( - sessionManagementSubscriptionDataResp, Snssai, Dnn) - udmUe.SetSMSubsData(smData) + udmUe, ok := p.Context().UdmUeFindBySupi(supi) + if !ok { + udmUe = p.Context().NewUdmUe(supi) + } + smData, snssaikey, AllDnnConfigsbyDnn, AllDnns := p.Context().ManageSmData( + sessionManagementSubscriptionDataResp.SmSubsData.IndividualSmSubsData, Snssai, Dnn) + udmUe.SetSMSubsData(smData) - rspSMSubDataList := make([]models.SessionManagementSubscriptionData, 0, 4) + rspSMSubDataList := make([]models.SessionManagementSubscriptionData, 0, 4) + udmUe.SmSubsDataLock.RLock() + for _, eachSMSubData := range udmUe.SessionManagementSubsData { + rspSMSubDataList = append(rspSMSubDataList, eachSMSubData) + } + udmUe.SmSubsDataLock.RUnlock() + + switch { + case Snssai == "" && Dnn == "": + c.JSON(http.StatusOK, AllDnns) + case Snssai != "" && Dnn == "": udmUe.SmSubsDataLock.RLock() - for _, eachSMSubData := range udmUe.SessionManagementSubsData { - rspSMSubDataList = append(rspSMSubDataList, eachSMSubData) - } - udmUe.SmSubsDataLock.RUnlock() - - switch { - case Snssai == "" && Dnn == "": - c.JSON(http.StatusOK, AllDnns) - case Snssai != "" && Dnn == "": - udmUe.SmSubsDataLock.RLock() - defer udmUe.SmSubsDataLock.RUnlock() - c.JSON(http.StatusOK, udmUe.SessionManagementSubsData[snssaikey].DnnConfigurations) - case Snssai == "" && Dnn != "": - c.JSON(http.StatusOK, AllDnnConfigsbyDnn) - case Snssai != "" && Dnn != "": - c.JSON(http.StatusOK, rspSMSubDataList) - default: - udmUe.SmSubsDataLock.RLock() - defer udmUe.SmSubsDataLock.RUnlock() - c.JSON(http.StatusOK, udmUe.SessionManagementSubsData) - } - } else { - problemDetails := &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "DATA_NOT_FOUND", - } - c.JSON(int(problemDetails.Status), problemDetails) - return + defer udmUe.SmSubsDataLock.RUnlock() + c.JSON(http.StatusOK, udmUe.SessionManagementSubsData[snssaikey].DnnConfigurations) + case Snssai == "" && Dnn != "": + c.JSON(http.StatusOK, AllDnnConfigsbyDnn) + case Snssai != "" && Dnn != "": + c.JSON(http.StatusOK, rspSMSubDataList) + default: + udmUe.SmSubsDataLock.RLock() + defer udmUe.SmSubsDataLock.RUnlock() + c.JSON(http.StatusOK, udmUe.SessionManagementSubsData) } + } func (p *Processor) GetNssaiProcedure(c *gin.Context, supi string, plmnID string, supportedFeatures string) { - ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) + ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NrfNfManagementNfType_UDR) if err != nil { c.JSON(int(pd.Status), pd) return } - var queryAmDataParamOpts Nudr_DataRepository.QueryAmDataParamOpts - queryAmDataParamOpts.SupportedFeatures = optional.NewString(supportedFeatures) + var queryAmDataRequest Nudr_DataRepository.QueryAmDataRequest + queryAmDataRequest.SupportedFeatures = &supportedFeatures + queryAmDataRequest.UeId = &supi + queryAmDataRequest.ServingPlmnId = &plmnID + var nssaiResp models.Nssai clientAPI, err := p.Consumer().CreateUDMClientToUDR(supi) if err != nil { @@ -441,57 +447,41 @@ func (p *Processor) GetNssaiProcedure(c *gin.Context, supi string, plmnID string return } - accessAndMobilitySubscriptionDataResp, res, err := clientAPI.AccessAndMobilitySubscriptionDataDocumentApi. - QueryAmData(ctx, supi, plmnID, &queryAmDataParamOpts) + accessAndMobilitySubscriptionDataResp, err := clientAPI.AccessAndMobilitySubscriptionDataDocumentApi. + QueryAmData(ctx, &queryAmDataRequest) if err != nil { - if res == nil { - logger.SdmLog.Warnln(err) - } else if err.Error() != res.Status { - logger.SdmLog.Warnln(err) - } else { - logger.SdmLog.Warnln(err) - problemDetails := &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - + problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + if !ok { + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } + c.JSON(int(problem.Status), problem) + return } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("QueryAmData response body cannot close: %+v", rspCloseErr) - } - }() - nssaiResp = *accessAndMobilitySubscriptionDataResp.Nssai + nssaiResp = *accessAndMobilitySubscriptionDataResp.AccessAndMobilitySubscriptionData.Nssai - if res.StatusCode == http.StatusOK { - udmUe, ok := p.Context().UdmUeFindBySupi(supi) - if !ok { - udmUe = p.Context().NewUdmUe(supi) - } - udmUe.Nssai = &nssaiResp - c.JSON(http.StatusOK, udmUe.Nssai) - } else { - problemDetails := &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "DATA_NOT_FOUND", - } - c.JSON(int(problemDetails.Status), problemDetails) + udmUe, ok := p.Context().UdmUeFindBySupi(supi) + if !ok { + udmUe = p.Context().NewUdmUe(supi) } + udmUe.Nssai = &nssaiResp + c.JSON(http.StatusOK, udmUe.Nssai) + } func (p *Processor) GetSmfSelectDataProcedure(c *gin.Context, supi string, plmnID string, supportedFeatures string) { - ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) + ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NrfNfManagementNfType_UDR) if err != nil { c.JSON(int(pd.Status), pd) return } - var querySmfSelectDataParamOpts Nudr_DataRepository.QuerySmfSelectDataParamOpts - querySmfSelectDataParamOpts.SupportedFeatures = optional.NewString(supportedFeatures) + var querySmfSelectDataRequest Nudr_DataRepository.QuerySmfSelectDataRequest + querySmfSelectDataRequest.SupportedFeatures = &supportedFeatures + querySmfSelectDataRequest.UeId = &supi + querySmfSelectDataRequest.ServingPlmnId = &plmnID + var body models.SmfSelectionSubscriptionData clientAPI, err := p.Consumer().CreateUDMClientToUDR(supi) @@ -503,107 +493,62 @@ func (p *Processor) GetSmfSelectDataProcedure(c *gin.Context, supi string, plmnI p.Context().CreateSmfSelectionSubsDataforUe(supi, body) - smfSelectionSubscriptionDataResp, res, err := clientAPI.SMFSelectionSubscriptionDataDocumentApi. - QuerySmfSelectData(ctx, supi, plmnID, &querySmfSelectDataParamOpts) - if err != nil { - if res == nil { - logger.SdmLog.Warnln(err) - } else if err.Error() != res.Status { - logger.SdmLog.Warnln(err) - } else { - logger.SdmLog.Warnln(err) - problemDetails := &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } + smfSelectionSubscriptionDataResp, err := clientAPI.SMFSelectionSubscriptionDataDocumentApi. + QuerySmfSelectData(ctx, &querySmfSelectDataRequest) + if err != nil { + problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + if !ok { + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + c.JSON(int(problem.Status), problem) return } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("QuerySmfSelectData response body cannot close: %+v", rspCloseErr) - } - }() - if res.StatusCode == http.StatusOK { - udmUe, ok := p.Context().UdmUeFindBySupi(supi) - if !ok { - udmUe = p.Context().NewUdmUe(supi) - } - udmUe.SetSmfSelectionSubsData(&smfSelectionSubscriptionDataResp) - c.JSON(http.StatusOK, udmUe.SmfSelSubsData) - } else { - problemDetails := &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "DATA_NOT_FOUND", - } - c.JSON(int(problemDetails.Status), problemDetails) + udmUe, ok := p.Context().UdmUeFindBySupi(supi) + if !ok { + udmUe = p.Context().NewUdmUe(supi) } + udmUe.SetSmfSelectionSubsData(&smfSelectionSubscriptionDataResp.SmfSelectionSubscriptionData) + c.JSON(http.StatusOK, udmUe.SmfSelSubsData) + } func (p *Processor) SubscribeToSharedDataProcedure(c *gin.Context, sdmSubscription *models.SdmSubscription) { - ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDM_SDM, models.NfType_UDM) + ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDM_SDM, models.NrfNfManagementNfType_UDM) if err != nil { c.JSON(int(pd.Status), pd) return } - + var subscibeToShareDataRequest SubscriberDataManagement.SubscribeToSharedDataRequest + subscibeToShareDataRequest.SdmSubscription = sdmSubscription udmClientAPI := p.Consumer().GetSDMClient("subscribeToSharedData") - sdmSubscriptionResp, res, err := udmClientAPI.SubscriptionCreationForSharedDataApi.SubscribeToSharedData( - ctx, *sdmSubscription) - if err != nil { - if res == nil { - logger.SdmLog.Warnln(err) - } else if err.Error() != res.Status { - logger.SdmLog.Warnln(err) - } else { - problemDetails := &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } + sdmSubscriptionResp, err := udmClientAPI.SubscriptionCreationForSharedDataApi.SubscribeToSharedData( + ctx, &subscibeToShareDataRequest) + + if err != nil { + problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + if !ok { + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } + c.JSON(int(problem.Status), problem) + return } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("SubscribeToSharedData response body cannot close: %+v", rspCloseErr) - } - }() - - if res.StatusCode == http.StatusCreated { - p.Context().CreateSubstoNotifSharedData(sdmSubscriptionResp.SubscriptionId, &sdmSubscriptionResp) - reourceUri := p.Context(). - GetSDMUri() + - "//shared-data-subscriptions/" + sdmSubscriptionResp.SubscriptionId - c.Header("Location", reourceUri) - c.JSON(http.StatusOK, sdmSubscriptionResp) - } else if res.StatusCode == http.StatusNotFound { - problemDetails := &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "DATA_NOT_FOUND", - } - - c.JSON(int(problemDetails.Status), problemDetails) - } else { - problemDetails := &models.ProblemDetails{ - Status: http.StatusNotImplemented, - Cause: "UNSUPPORTED_RESOURCE_URI", - } - c.JSON(int(problemDetails.Status), problemDetails) - } + p.Context().CreateSubstoNotifSharedData(sdmSubscriptionResp.SdmSubscription.SubscriptionId, &sdmSubscriptionResp.SdmSubscription) + reourceUri := p.Context(). + GetSDMUri() + + "//shared-data-subscriptions/" + sdmSubscriptionResp.SdmSubscription.SubscriptionId + c.Header("Location", reourceUri) + c.JSON(http.StatusOK, sdmSubscriptionResp.SdmSubscription) } func (p *Processor) SubscribeProcedure(c *gin.Context, sdmSubscription *models.SdmSubscription, supi string) { - ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) + ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NrfNfManagementNfType_UDR) if err != nil { c.JSON(int(pd.Status), pd) return @@ -614,100 +559,60 @@ func (p *Processor) SubscribeProcedure(c *gin.Context, sdmSubscription *models.S c.JSON(int(problemDetails.Status), problemDetails) return } - - sdmSubscriptionResp, res, err := clientAPI.SDMSubscriptionsCollectionApi.CreateSdmSubscriptions( - ctx, supi, *sdmSubscription) + var createSdmSubscriptionsRequest Nudr_DataRepository.CreateSdmSubscriptionsRequest + createSdmSubscriptionsRequest.SdmSubscription = sdmSubscription + sdmSubscriptionResp, err := clientAPI.SDMSubscriptionsCollectionApi.CreateSdmSubscriptions( + ctx, &createSdmSubscriptionsRequest) if err != nil { - if res == nil { - logger.SdmLog.Warnln(err) - } else if err.Error() != res.Status { - logger.SdmLog.Warnln(err) - } else { - logger.SdmLog.Warnln(err) - problemDetails := &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } + problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + if !ok { + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } + c.JSON(int(problem.Status), problem) + return } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("CreateSdmSubscriptions response body cannot close: %+v", rspCloseErr) - } - }() - if res.StatusCode == http.StatusCreated { - udmUe, _ := p.Context().UdmUeFindBySupi(supi) - if udmUe == nil { - udmUe = p.Context().NewUdmUe(supi) - } - udmUe.CreateSubscriptiontoNotifChange(sdmSubscriptionResp.SubscriptionId, &sdmSubscriptionResp) - c.Header("Location", udmUe.GetLocationURI2(udm_context.LocationUriSdmSubscription, supi)) - c.JSON(http.StatusCreated, sdmSubscriptionResp) - } else if res.StatusCode == http.StatusNotFound { - problemDetails := &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "DATA_NOT_FOUND", - } - c.JSON(int(problemDetails.Status), problemDetails) - } else { - problemDetails := &models.ProblemDetails{ - Status: http.StatusNotImplemented, - Cause: "UNSUPPORTED_RESOURCE_URI", - } - c.JSON(int(problemDetails.Status), problemDetails) + udmUe, _ := p.Context().UdmUeFindBySupi(supi) + if udmUe == nil { + udmUe = p.Context().NewUdmUe(supi) } + udmUe.CreateSubscriptiontoNotifChange(sdmSubscriptionResp.SdmSubscription.SubscriptionId, &sdmSubscriptionResp.SdmSubscription) + c.Header("Location", udmUe.GetLocationURI2(udm_context.LocationUriSdmSubscription, supi)) + c.JSON(http.StatusCreated, sdmSubscriptionResp.SdmSubscription) + } func (p *Processor) UnsubscribeForSharedDataProcedure(c *gin.Context, subscriptionID string) { - ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDM_SDM, models.NfType_UDM) + ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDM_SDM, models.NrfNfManagementNfType_UDM) if err != nil { c.JSON(int(pd.Status), pd) return } udmClientAPI := p.Consumer().GetSDMClient("unsubscribeForSharedData") - - res, err := udmClientAPI.SubscriptionDeletionForSharedDataApi.UnsubscribeForSharedData( - ctx, subscriptionID) - if err != nil { - if res == nil { - logger.SdmLog.Warnln(err) - } else if err.Error() != res.Status { - logger.SdmLog.Warnln(err) - } else { - logger.SdmLog.Warnln(err) - problemDetails := &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } + var unsubscribeForSharedDataRequest SubscriberDataManagement.UnsubscribeForSharedDataRequest + unsubscribeForSharedDataRequest.SubscriptionId = &subscriptionID + _, err = udmClientAPI.SubscriptionDeletionForSharedDataApi.UnsubscribeForSharedData( + ctx, &unsubscribeForSharedDataRequest) + if err != nil { + problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + if !ok { + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } + c.JSON(int(problem.Status), problem) + return } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("UnsubscribeForSharedData response body cannot close: %+v", rspCloseErr) - } - }() - if res.StatusCode == http.StatusNoContent { - c.Status(http.StatusNoContent) - } else { - problemDetails := &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "DATA_NOT_FOUND", - } - c.JSON(int(problemDetails.Status), problemDetails) - } + c.Status(http.StatusNoContent) + } func (p *Processor) UnsubscribeProcedure(c *gin.Context, supi string, subscriptionID string) { - ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) + ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NrfNfManagementNfType_UDR) if err != nil { c.JSON(int(pd.Status), pd) return @@ -718,39 +623,22 @@ func (p *Processor) UnsubscribeProcedure(c *gin.Context, supi string, subscripti c.JSON(int(problemDetails.Status), problemDetails) return } - - res, err := clientAPI.SDMSubscriptionDocumentApi.RemovesdmSubscriptions(ctx, supi, subscriptionID) + var removesdmSubscriptionRequest Nudr_DataRepository.RemovesdmSubscriptionsRequest + removesdmSubscriptionRequest.UeId = &supi + removesdmSubscriptionRequest.SubsId = &subscriptionID + _, err = clientAPI.SDMSubscriptionDocumentApi.RemovesdmSubscriptions(ctx, &removesdmSubscriptionRequest) if err != nil { - if res == nil { - logger.SdmLog.Warnln(err) - } else if err.Error() != res.Status { - logger.SdmLog.Warnln(err) - } else { - logger.SdmLog.Warnln(err) - problemDetails := &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } + problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + if !ok { + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } + c.JSON(int(problem.Status), problem) + return } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("RemovesdmSubscriptions response body cannot close: %+v", rspCloseErr) - } - }() - if res.StatusCode == http.StatusNoContent { - c.Status(http.StatusNoContent) - } else { - problemDetails := &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "USER_NOT_FOUND", - } - c.JSON(int(problemDetails.Status), problemDetails) - } + c.Status(http.StatusNoContent) } func (p *Processor) ModifyProcedure(c *gin.Context, @@ -758,7 +646,7 @@ func (p *Processor) ModifyProcedure(c *gin.Context, supi string, subscriptionID string, ) { - ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) + ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NrfNfManagementNfType_UDR) if err != nil { c.JSON(int(pd.Status), pd) return @@ -771,43 +659,25 @@ func (p *Processor) ModifyProcedure(c *gin.Context, } sdmSubscription := models.SdmSubscription{} - body := Nudr_DataRepository.UpdatesdmsubscriptionsParamOpts{ - SdmSubscription: optional.NewInterface(sdmSubscription), - } - - res, err := clientAPI.SDMSubscriptionDocumentApi.Updatesdmsubscriptions( - ctx, supi, subscriptionID, &body) - if err != nil { - if res == nil { - logger.SdmLog.Warnln(err) - } else if err.Error() != res.Status { - logger.SdmLog.Warnln(err) - } else { - problemDetails := &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } + var updatesdmsubscriptionsRequest Nudr_DataRepository.UpdatesdmsubscriptionsRequest + updatesdmsubscriptionsRequest.SdmSubscription = &sdmSubscription + updatesdmsubscriptionsRequest.SubsId = &subscriptionID + updatesdmsubscriptionsRequest.UeId = &supi + + _, err = clientAPI.SDMSubscriptionDocumentApi.Updatesdmsubscriptions( + ctx, &updatesdmsubscriptionsRequest) + if err != nil { + problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + if !ok { + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } + c.JSON(int(problem.Status), problem) + return } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("Updatesdmsubscriptions response body cannot close: %+v", rspCloseErr) - } - }() - if res.StatusCode == http.StatusOK { - c.JSON(http.StatusOK, sdmSubscription) - } else { - problemDetails := &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "USER_NOT_FOUND", - } - - c.JSON(int(problemDetails.Status), problemDetails) - } + c.JSON(http.StatusOK, sdmSubscription) } // TS 29.503 5.2.2.7.3 @@ -817,7 +687,7 @@ func (p *Processor) ModifyForSharedDataProcedure(c *gin.Context, supi string, subscriptionID string, ) { - ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) + ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NrfNfManagementNfType_UDR) if err != nil { c.JSON(int(pd.Status), pd) return @@ -831,52 +701,37 @@ func (p *Processor) ModifyForSharedDataProcedure(c *gin.Context, var sdmSubscription models.SdmSubscription sdmSubs := models.SdmSubscription{} - body := Nudr_DataRepository.UpdatesdmsubscriptionsParamOpts{ - SdmSubscription: optional.NewInterface(sdmSubs), - } - - res, err := clientAPI.SDMSubscriptionDocumentApi.Updatesdmsubscriptions( - ctx, supi, subscriptionID, &body) - if err != nil { - if res == nil { - logger.SdmLog.Warnln(err) - } else if err.Error() != res.Status { - logger.SdmLog.Warnln(err) - } else { - problemDetails := &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } + var updatesdmsubscriptionsRequest Nudr_DataRepository.UpdatesdmsubscriptionsRequest + updatesdmsubscriptionsRequest.SubsId = &subscriptionID + updatesdmsubscriptionsRequest.UeId = &supi + updatesdmsubscriptionsRequest.SdmSubscription = &sdmSubs + + _, err = clientAPI.SDMSubscriptionDocumentApi.Updatesdmsubscriptions( + ctx, &updatesdmsubscriptionsRequest) + if err != nil { + problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + if !ok { + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } + c.JSON(int(problem.Status), problem) + return } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("Updatesdmsubscriptions response body cannot close: %+v", rspCloseErr) - } - }() - if res.StatusCode == http.StatusOK { - c.JSON(http.StatusOK, sdmSubscription) - } else { - problemDetails := &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "USER_NOT_FOUND", - } - c.JSON(int(problemDetails.Status), problemDetails) - } + c.JSON(http.StatusOK, sdmSubscription) } func (p *Processor) GetTraceDataProcedure(c *gin.Context, supi string, plmnID string) { - ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) + ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NrfNfManagementNfType_UDR) if err != nil { c.JSON(int(pd.Status), pd) return } var body models.TraceData - var queryTraceDataParamOpts Nudr_DataRepository.QueryTraceDataParamOpts + var queryTraceDataRequest Nudr_DataRepository.QueryTraceDataRequest + queryTraceDataRequest.UeId = &supi + queryTraceDataRequest.ServingPlmnId = &plmnID clientAPI, err := p.Consumer().CreateUDMClientToUDR(supi) if err != nil { @@ -887,54 +742,36 @@ func (p *Processor) GetTraceDataProcedure(c *gin.Context, supi string, plmnID st p.Context().CreateTraceDataforUe(supi, body) - traceDataRes, res, err := clientAPI.TraceDataDocumentApi.QueryTraceData( - ctx, supi, plmnID, &queryTraceDataParamOpts) - if err != nil { - if res == nil { - logger.SdmLog.Warnln(err) - } else if err.Error() != res.Status { - logger.SdmLog.Warnln(err) - } else { - problemDetails := &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } + traceDataRes, err := clientAPI.TraceDataDocumentApi.QueryTraceData( + ctx, &queryTraceDataRequest) + if err != nil { + problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + if !ok { + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } + c.JSON(int(problem.Status), problem) + return } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("QueryTraceData response body cannot close: %+v", rspCloseErr) - } - }() - - if res.StatusCode == http.StatusOK { - udmUe, ok := p.Context().UdmUeFindBySupi(supi) - if !ok { - udmUe = p.Context().NewUdmUe(supi) - } - udmUe.TraceData = &traceDataRes - udmUe.TraceDataResponse.TraceData = &traceDataRes - - c.JSON(http.StatusOK, udmUe.TraceDataResponse.TraceData) - } else { - problemDetails := &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "USER_NOT_FOUND", - } - c.JSON(int(problemDetails.Status), problemDetails) + udmUe, ok := p.Context().UdmUeFindBySupi(supi) + if !ok { + udmUe = p.Context().NewUdmUe(supi) } + udmUe.TraceData = &traceDataRes.TraceData + udmUe.TraceDataResponse.TraceData = &traceDataRes.TraceData + + c.JSON(http.StatusOK, udmUe.TraceDataResponse.TraceData) } func (p *Processor) GetUeContextInSmfDataProcedure(c *gin.Context, supi string, supportedFeatures string) { var body models.UeContextInSmfData var ueContextInSmfData models.UeContextInSmfData var pgwInfoArray []models.PgwInfo - var querySmfRegListParamOpts Nudr_DataRepository.QuerySmfRegListParamOpts - querySmfRegListParamOpts.SupportedFeatures = optional.NewString(supportedFeatures) + var querySmfRegListRequest Nudr_DataRepository.QuerySmfRegListRequest + querySmfRegListRequest.SupportedFeatures = &supportedFeatures + querySmfRegListRequest.UeId = &supi clientAPI, err := p.Consumer().CreateUDMClientToUDR(supi) if err != nil { @@ -946,38 +783,26 @@ func (p *Processor) GetUeContextInSmfDataProcedure(c *gin.Context, supi string, pduSessionMap := make(map[string]models.PduSession) p.Context().CreateUeContextInSmfDataforUe(supi, body) - ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NfType_UDR) + ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NrfNfManagementNfType_UDR) if err != nil { c.JSON(int(pd.Status), pd) return } - pdusess, res, err := clientAPI.SMFRegistrationsCollectionApi.QuerySmfRegList( - ctx, supi, &querySmfRegListParamOpts) + pdusessRes, err := clientAPI.SMFRegistrationsCollectionApi.QuerySmfRegList( + ctx, &querySmfRegListRequest) if err != nil { - if res == nil { - logger.SdmLog.Infoln(err) - } else if err.Error() != res.Status { - logger.SdmLog.Infoln(err) - } else { - logger.SdmLog.Infoln(err) - problemDetails := &models.ProblemDetails{ - Status: int32(res.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), - } - + problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + if !ok { + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } + c.JSON(int(problem.Status), problem) + return } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("QuerySmfRegList response body cannot close: %+v", rspCloseErr) - } - }() - for _, element := range pdusess { + for _, element := range pdusessRes.SmfRegistration { var pduSession models.PduSession pduSession.Dnn = element.Dnn pduSession.SmfInstanceId = element.SmfInstanceId @@ -986,7 +811,7 @@ func (p *Processor) GetUeContextInSmfDataProcedure(c *gin.Context, supi string, } ueContextInSmfData.PduSessions = pduSessionMap - for _, element := range pdusess { + for _, element := range pdusessRes.SmfRegistration { var pgwInfo models.PgwInfo pgwInfo.Dnn = element.Dnn pgwInfo.PgwFqdn = element.PgwFqdn @@ -995,20 +820,13 @@ func (p *Processor) GetUeContextInSmfDataProcedure(c *gin.Context, supi string, } ueContextInSmfData.PgwInfo = pgwInfoArray - if res.StatusCode == http.StatusOK { - udmUe, ok := p.Context().UdmUeFindBySupi(supi) - if !ok { - udmUe = p.Context().NewUdmUe(supi) - } - udmUe.UeCtxtInSmfData = &ueContextInSmfData - c.JSON(http.StatusOK, udmUe.UeCtxtInSmfData) - } else { - problemDetails := &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "DATA_NOT_FOUND", - } - c.JSON(int(problemDetails.Status), problemDetails) + udmUe, ok := p.Context().UdmUeFindBySupi(supi) + if !ok { + udmUe = p.Context().NewUdmUe(supi) } + udmUe.UeCtxtInSmfData = &ueContextInSmfData + c.JSON(http.StatusOK, udmUe.UeCtxtInSmfData) + } func (p *Processor) containDataSetName(dataSetNames []string, target string) bool { From f275877399c7949ded2b65379490dfdb27b952df Mon Sep 17 00:00:00 2001 From: ubuntu Date: Fri, 26 Jul 2024 09:49:27 +0000 Subject: [PATCH 09/41] fix: consumer nrf_service wrong function call --- internal/context/context.go | 6 +- internal/sbi/consumer/nf_discovery.go | 69 ---------------- internal/sbi/consumer/nrf_service.go | 110 +++++++++++++++----------- internal/sbi/consumer/udr_service.go | 14 ++-- internal/util/search_nf_service.go | 2 +- 5 files changed, 74 insertions(+), 127 deletions(-) delete mode 100644 internal/sbi/consumer/nf_discovery.go diff --git a/internal/context/context.go b/internal/context/context.go index 61ddbe8..df7649a 100644 --- a/internal/context/context.go +++ b/internal/context/context.go @@ -32,7 +32,7 @@ const ( ) func Init() { - GetSelf().NfService = make(map[models.ServiceName]models.NfService) + GetSelf().NfService = make(map[models.ServiceName]models.NrfNfManagementNfService) GetSelf().EeSubscriptionIDGenerator = idgenerator.NewGenerator(1, math.MaxInt32) InitUdmContext(GetSelf()) } @@ -50,7 +50,7 @@ type UDMContext struct { RegisterIPv4 string // IP register to NRF BindingIPv4 string UriScheme models.UriScheme - NfService map[models.ServiceName]models.NfService + NfService map[models.ServiceName]models.NrfNfManagementNfService NFDiscoveryClient *Nnrf_NFDiscovery.APIClient UdmUePool sync.Map // map[supi]*UdmUeContext NrfUri string @@ -467,7 +467,7 @@ func (context *UDMContext) InitNFService(serviceName []string, version string) { versionUri := "v" + tmpVersion[0] for index, nameString := range serviceName { name := models.ServiceName(nameString) - context.NfService[name] = models.NfService{ + context.NfService[name] = models.NrfNfManagementNfService{ ServiceInstanceId: strconv.Itoa(index), ServiceName: name, Versions: []models.NfServiceVersion{ diff --git a/internal/sbi/consumer/nf_discovery.go b/internal/sbi/consumer/nf_discovery.go deleted file mode 100644 index 82fb00c..0000000 --- a/internal/sbi/consumer/nf_discovery.go +++ /dev/null @@ -1,69 +0,0 @@ -package consumer - -import ( - "fmt" - "net/http" - - "github.com/free5gc/openapi/models" - Nnrf_NFDiscovery "github.com/free5gc/openapi/nrf/NFDiscovery" - udm_context "github.com/free5gc/udm/internal/context" - "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/util" -) - -func SendNFIntances(nrfUri string, targetNfType, requestNfType models.NfType, - param Nnrf_NFDiscovery.SearchNFInstancesParamOpts, -) (result models.SearchResult, err error) { - configuration := Nnrf_NFDiscovery.NewConfiguration() - configuration.SetBasePath(nrfUri) // addr - clientNRF := Nnrf_NFDiscovery.NewAPIClient(configuration) - - ctx, _, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_DISC, models.NfType_NRF) - if err != nil { - return - } - - result, res, err1 := clientNRF.NFInstancesStoreApi.SearchNFInstances(ctx, targetNfType, - requestNfType, ¶m) - if err1 != nil { - err = err1 - return - } - defer func() { - if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.ConsumerLog.Errorf("SearchNFInstances response body cannot close: %+v", rspCloseErr) - } - }() - - if res != nil && res.StatusCode == http.StatusTemporaryRedirect { - err = fmt.Errorf("Temporary Redirect For Non NRF Consumer") - } - return -} - -func SendNFIntancesUDR(id string, types int) string { - self := udm_context.GetSelf() - targetNfType := models.NfType_UDR - requestNfType := models.NfType_UDM - localVarOptionals := Nnrf_NFDiscovery.SearchNFInstancesParamOpts{ - // DataSet: optional.NewInterface(models.DataSetId_SUBSCRIPTION), - } - // switch types { - // case NFDiscoveryToUDRParamSupi: - // localVarOptionals.Supi = optional.NewString(id) - // case NFDiscoveryToUDRParamExtGroupId: - // localVarOptionals.ExternalGroupIdentity = optional.NewString(id) - // case NFDiscoveryToUDRParamGpsi: - // localVarOptionals.Gpsi = optional.NewString(id) - // } - fmt.Println(self.NrfUri) - result, err := SendNFIntances(self.NrfUri, targetNfType, requestNfType, localVarOptionals) - if err != nil { - logger.ConsumerLog.Error(err.Error()) - return "" - } - for _, profile := range result.NfInstances { - return util.SearchNFServiceUri(profile, models.ServiceName_NUDR_DR, models.NfServiceStatus_REGISTERED) - } - return "" -} diff --git a/internal/sbi/consumer/nrf_service.go b/internal/sbi/consumer/nrf_service.go index 6b97c25..df212a6 100644 --- a/internal/sbi/consumer/nrf_service.go +++ b/internal/sbi/consumer/nrf_service.go @@ -3,7 +3,6 @@ package consumer import ( "context" "fmt" - "net/http" "strings" "sync" "time" @@ -16,6 +15,7 @@ import ( Nnrf_NFManagement "github.com/free5gc/openapi/nrf/NFManagement" udm_context "github.com/free5gc/udm/internal/context" "github.com/free5gc/udm/internal/logger" + "github.com/free5gc/udm/internal/util" ) type nnrfService struct { @@ -73,7 +73,7 @@ func (s *nnrfService) getNFDiscClient(uri string) *Nnrf_NFDiscovery.APIClient { } func (s *nnrfService) SendSearchNFInstances( - nrfUri string, targetNfType, requestNfType models.NfType, param Nnrf_NFDiscovery.SearchNFInstancesParamOpts) ( + nrfUri string, param Nnrf_NFDiscovery.SearchNFInstancesRequest) ( *models.SearchResult, error, ) { // Set client and set url @@ -81,31 +81,53 @@ func (s *nnrfService) SendSearchNFInstances( client := s.getNFDiscClient(udmContext.NrfUri) - ctx, _, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_DISC, models.NfType_NRF) + ctx, _, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_DISC, models.NrfNfManagementNfType_NRF) if err != nil { return nil, err } - result, res, err := client.NFInstancesStoreApi.SearchNFInstances(ctx, targetNfType, requestNfType, ¶m) - if err != nil { + searchNfInstancesRsp, err1 := client.NFInstancesStoreApi.SearchNFInstances(ctx, ¶m) + result := searchNfInstancesRsp.SearchResult + if err1 != nil { logger.ConsumerLog.Errorf("SearchNFInstances failed: %+v", err) } - defer func() { - if resCloseErr := res.Body.Close(); resCloseErr != nil { - logger.ConsumerLog.Errorf("NFInstancesStoreApi response body cannot close: %+v", resCloseErr) - } - }() - if res != nil && res.StatusCode == http.StatusTemporaryRedirect { - return nil, fmt.Errorf("Temporary Redirect For Non NRF Consumer") - } return &result, nil } +func (s *nnrfService) SendNFIntancesUDR(id string, types int) string { + self := udm_context.GetSelf() + targetNfType := models.NrfNfManagementNfType_UDR + requestNfType := models.NrfNfManagementNfType_UDM + searchNFinstanceRequest := Nnrf_NFDiscovery.SearchNFInstancesRequest{ + // DataSet: optional.NewInterface(models.DataSetId_SUBSCRIPTION), + } + searchNFinstanceRequest.RequesterNfType = &requestNfType + searchNFinstanceRequest.TargetNfType = &targetNfType + // switch types { + // case NFDiscoveryToUDRParamSupi: + // localVarOptionals.Supi = optional.NewString(id) + // case NFDiscoveryToUDRParamExtGroupId: + // localVarOptionals.ExternalGroupIdentity = optional.NewString(id) + // case NFDiscoveryToUDRParamGpsi: + // localVarOptionals.Gpsi = optional.NewString(id) + // } + fmt.Println(self.NrfUri) + result, err := s.SendSearchNFInstances(self.NrfUri, searchNFinstanceRequest) + if err != nil { + logger.ConsumerLog.Error(err.Error()) + return "" + } + for _, profile := range result.NfInstances { + return util.SearchNFServiceUri(profile, models.ServiceName_NUDR_DR, models.NfServiceStatus_REGISTERED) + } + return "" +} + func (s *nnrfService) SendDeregisterNFInstance() (problemDetails *models.ProblemDetails, err error) { logger.ConsumerLog.Infof("Send Deregister NFInstance") - ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_NFM, models.NfType_NRF) + ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_NFM, models.NrfNfManagementNfType_NRF) if err != nil { return pd, err } @@ -113,20 +135,13 @@ func (s *nnrfService) SendDeregisterNFInstance() (problemDetails *models.Problem udmContext := s.consumer.Context() client := s.getNFManagementClient(udmContext.NrfUri) - var res *http.Response + var derigisterNfInstanceRequest Nnrf_NFManagement.DeregisterNFInstanceRequest + derigisterNfInstanceRequest.NfInstanceID = &udmContext.NfId + res, err := client.NFInstanceIDDocumentApi.DeregisterNFInstance(ctx, &derigisterNfInstanceRequest) - res, err = client.NFInstanceIDDocumentApi.DeregisterNFInstance(ctx, udmContext.NfId) if err == nil { return problemDetails, err } else if res != nil { - defer func() { - if resCloseErr := res.Body.Close(); resCloseErr != nil { - logger.ConsumerLog.Errorf("DeregisterNFInstance response cannot close: %+v", resCloseErr) - } - }() - if res.Status != err.Error() { - return problemDetails, err - } problem := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) problemDetails = &problem } else { @@ -144,34 +159,35 @@ func (s *nnrfService) RegisterNFInstance(ctx context.Context) ( if err != nil { return "", "", errors.Wrap(err, "RegisterNFInstance buildNfProfile()") } - - var nf models.NfProfile - var res *http.Response + var registerNfInstanceRequest Nnrf_NFManagement.RegisterNFInstanceRequest + registerNfInstanceRequest.NfInstanceID = &udmContext.NfId + registerNfInstanceRequest.NrfNfManagementNfProfile = &nfProfile for { - nf, res, err = client.NFInstanceIDDocumentApi.RegisterNFInstance(ctx, udmContext.NfId, nfProfile) + res, err := client.NFInstanceIDDocumentApi.RegisterNFInstance(ctx, ®isterNfInstanceRequest) + + var status int32 if err != nil || res == nil { - logger.ConsumerLog.Errorf("UDM register to NRF Error[%v]", err) - time.Sleep(2 * time.Second) - continue - } - defer func() { - if resCloseErr := res.Body.Close(); resCloseErr != nil { - logger.ConsumerLog.Errorf("RegisterNFInstance response body cannot close: %+v", resCloseErr) + problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + if !ok { + logger.ConsumerLog.Errorf("UDM register to NRF Error[%v]", err) + time.Sleep(2 * time.Second) + continue } - }() - status := res.StatusCode - if status == http.StatusOK { + status = problem.Status + } + + if res.Location == "" { // NFUpdate break - } else if status == http.StatusCreated { + } else if res.Location != "" { // NFRegister - resourceUri := res.Header.Get("Location") + resourceUri := res.Location resouceNrfUri = resourceUri[:strings.Index(resourceUri, "/nnrf-nfm/")] retrieveNfInstanceID = resourceUri[strings.LastIndex(resourceUri, "/")+1:] oauth2 := false - if nf.CustomInfo != nil { - v, ok := nf.CustomInfo["oauth2"].(bool) + if res.NrfNfManagementNfProfile.CustomInfo != nil { + v, ok := res.NrfNfManagementNfProfile.CustomInfo["oauth2"].(bool) if ok { oauth2 = v logger.MainLog.Infoln("OAuth2 setting receive from NRF:", oauth2) @@ -191,17 +207,17 @@ func (s *nnrfService) RegisterNFInstance(ctx context.Context) ( return resouceNrfUri, retrieveNfInstanceID, err } -func (s *nnrfService) buildNfProfile(udmContext *udm_context.UDMContext) (profile models.NfProfile, err error) { +func (s *nnrfService) buildNfProfile(udmContext *udm_context.UDMContext) (profile models.NrfNfManagementNfProfile, err error) { profile.NfInstanceId = udmContext.NfId - profile.NfType = models.NfType_UDM - profile.NfStatus = models.NfStatus_REGISTERED + profile.NfType = models.NrfNfManagementNfType_UDM + profile.NfStatus = models.NrfNfManagementNfStatus_REGISTERED profile.Ipv4Addresses = append(profile.Ipv4Addresses, udmContext.RegisterIPv4) - services := []models.NfService{} + services := []models.NrfNfManagementNfService{} for _, nfService := range udmContext.NfService { services = append(services, nfService) } if len(services) > 0 { - profile.NfServices = &services + profile.NfServices = services } profile.UdmInfo = &models.UdmInfo{ // Todo diff --git a/internal/sbi/consumer/udr_service.go b/internal/sbi/consumer/udr_service.go index 2afb875..c326880 100644 --- a/internal/sbi/consumer/udr_service.go +++ b/internal/sbi/consumer/udr_service.go @@ -54,12 +54,12 @@ func (s *nudrService) getUdrURI(id string) string { ue, ok := udm_context.GetSelf().UdmUeFindBySupi(id) if ok { if ue.UdrUri == "" { - ue.UdrUri = SendNFIntancesUDR(id, NFDiscoveryToUDRParamSupi) + ue.UdrUri = s.consumer.SendNFIntancesUDR(id, NFDiscoveryToUDRParamSupi) } return ue.UdrUri } else { ue = udm_context.GetSelf().NewUdmUe(id) - ue.UdrUri = SendNFIntancesUDR(id, NFDiscoveryToUDRParamSupi) + ue.UdrUri = s.consumer.SendNFIntancesUDR(id, NFDiscoveryToUDRParamSupi) return ue.UdrUri } } else if strings.Contains(id, "pei") { @@ -68,13 +68,13 @@ func (s *nudrService) getUdrURI(id string) string { ue := value.(*udm_context.UdmUeContext) if ue.Amf3GppAccessRegistration != nil && ue.Amf3GppAccessRegistration.Pei == id { if ue.UdrUri == "" { - ue.UdrUri = SendNFIntancesUDR(ue.Supi, NFDiscoveryToUDRParamSupi) + ue.UdrUri = s.consumer.SendNFIntancesUDR(ue.Supi, NFDiscoveryToUDRParamSupi) } udrURI = ue.UdrUri return false } else if ue.AmfNon3GppAccessRegistration != nil && ue.AmfNon3GppAccessRegistration.Pei == id { if ue.UdrUri == "" { - ue.UdrUri = SendNFIntancesUDR(ue.Supi, NFDiscoveryToUDRParamSupi) + ue.UdrUri = s.consumer.SendNFIntancesUDR(ue.Supi, NFDiscoveryToUDRParamSupi) } udrURI = ue.UdrUri return false @@ -84,10 +84,10 @@ func (s *nudrService) getUdrURI(id string) string { return udrURI } else if strings.Contains(id, "extgroupid") { // extra group id - return SendNFIntancesUDR(id, NFDiscoveryToUDRParamExtGroupId) + return s.consumer.SendNFIntancesUDR(id, NFDiscoveryToUDRParamExtGroupId) } else if strings.Contains(id, "msisdn") || strings.Contains(id, "extid") { // gpsi - return SendNFIntancesUDR(id, NFDiscoveryToUDRParamGpsi) + return s.consumer.SendNFIntancesUDR(id, NFDiscoveryToUDRParamGpsi) } - return SendNFIntancesUDR("", NFDiscoveryToUDRParamNone) + return s.consumer.SendNFIntancesUDR("", NFDiscoveryToUDRParamNone) } diff --git a/internal/util/search_nf_service.go b/internal/util/search_nf_service.go index 0f241bc..298a397 100644 --- a/internal/util/search_nf_service.go +++ b/internal/util/search_nf_service.go @@ -6,7 +6,7 @@ import ( "github.com/free5gc/openapi/models" ) -func SearchNFServiceUri(nfProfile models.NfProfile, serviceName models.ServiceName, +func SearchNFServiceUri(nfProfile models.NrfNfDiscoveryNfProfile, serviceName models.ServiceName, nfServiceStatus models.NfServiceStatus, ) (nfUri string) { if nfProfile.NfServices != nil { From 8104a2d5e06ae4db48200d2f47aa727007d30c97 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Fri, 26 Jul 2024 10:09:50 +0000 Subject: [PATCH 10/41] feat: modify GenerateAuthDataProcedure --- internal/sbi/processor/generate_auth_data.go | 81 ++++---------------- 1 file changed, 15 insertions(+), 66 deletions(-) diff --git a/internal/sbi/processor/generate_auth_data.go b/internal/sbi/processor/generate_auth_data.go index 9756dd1..99a8a31 100644 --- a/internal/sbi/processor/generate_auth_data.go +++ b/internal/sbi/processor/generate_auth_data.go @@ -175,17 +175,15 @@ func (p *Processor) GenerateAuthDataProcedure( AMF: 16 bits (2 bytes) (hex len = 4) TS33.102 - Annex H */ - hasK, hasOP, hasOPC := false, false, false - var kStr, opStr, opcStr string + hasOPC := false + var kStr, opcStr string var k, op, opc []byte - if authSubs.PermanentKey != nil { - kStr = authSubs.PermanentKey.PermanentKeyValue + if authSubs.AuthenticationSubscription.EncPermanentKey != "" { + kStr = authSubs.AuthenticationSubscription.EncPermanentKey if len(kStr) == keyStrLen { k, err = hex.DecodeString(kStr) if err != nil { logger.UeauLog.Errorln("err:", err) - } else { - hasK = true } } else { problemDetails := &models.ProblemDetails{ @@ -208,35 +206,8 @@ func (p *Processor) GenerateAuthDataProcedure( return } - if authSubs.Milenage != nil { - if authSubs.Milenage.Op != nil && authSubs.Milenage.Op.OpValue != "" { - opStr = authSubs.Milenage.Op.OpValue - if len(opStr) == opStrLen { - op, err = hex.DecodeString(opStr) - if err != nil { - logger.UeauLog.Errorln("err:", err) - } else { - hasOP = true - } - } else { - logger.UeauLog.Errorln("opStr length is ", len(opStr)) - } - } else { - logger.UeauLog.Infoln("Nil Op") - } - } else { - problemDetails := &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: authenticationRejected, - } - - logger.UeauLog.Infoln("Nil Milenage") - c.JSON(int(problemDetails.Status), problemDetails) - return - } - - if authSubs.Opc != nil && authSubs.Opc.OpcValue != "" { - opcStr = authSubs.Opc.OpcValue + if authSubs.AuthenticationSubscription.EncOpcKey != "" { + opcStr = authSubs.AuthenticationSubscription.EncOpcKey if len(opcStr) == opcStrLen { opc, err = hex.DecodeString(opcStr) if err != nil { @@ -251,7 +222,7 @@ func (p *Processor) GenerateAuthDataProcedure( logger.UeauLog.Infoln("Nil Opc") } - if !hasOPC && !hasOP { + if !hasOPC { problemDetails := &models.ProblemDetails{ Status: http.StatusForbidden, Cause: authenticationRejected, @@ -260,25 +231,7 @@ func (p *Processor) GenerateAuthDataProcedure( return } - if !hasOPC { - if hasK && hasOP { - opc, err = milenage.GenerateOPC(k, op) - if err != nil { - logger.UeauLog.Errorln("milenage GenerateOPC err:", err) - } - } else { - problemDetails := &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: authenticationRejected, - } - - logger.UeauLog.Errorln("Unable to derive OPC") - c.JSON(int(problemDetails.Status), problemDetails) - return - } - } - - sqnStr := p.strictHex(authSubs.SequenceNumber, 12) + sqnStr := p.strictHex(authSubs.AuthenticationSubscription.SequenceNumber.Sqn, 12) logger.UeauLog.Traceln("sqnStr", sqnStr) sqn, err := hex.DecodeString(sqnStr) if err != nil { @@ -309,7 +262,7 @@ func (p *Processor) GenerateAuthDataProcedure( return } - amfStr := p.strictHex(authSubs.AuthenticationManagementField, 4) + amfStr := p.strictHex(authSubs.AuthenticationSubscription.AuthenticationManagementField, 4) logger.UeauLog.Traceln("amfStr", amfStr) AMF, err := hex.DecodeString(amfStr) if err != nil { @@ -445,10 +398,11 @@ func (p *Processor) GenerateAuthDataProcedure( }, } - var rsp *http.Response - - rsp, err = client.AuthenticationDataDocumentApi.ModifyAuthentication( - ctx, supi, patchItemArray) + var modifyAuthenticationSubscriptionRequest Nudr_DataRepository.ModifyAuthenticationSubscriptionRequest + modifyAuthenticationSubscriptionRequest.UeId = &supi + modifyAuthenticationSubscriptionRequest.PatchItem = patchItemArray + _, err = client.AuthenticationSubscriptionDocumentApi.ModifyAuthenticationSubscription( + ctx, &modifyAuthenticationSubscriptionRequest) if err != nil { problemDetails := &models.ProblemDetails{ Status: http.StatusForbidden, @@ -460,11 +414,6 @@ func (p *Processor) GenerateAuthDataProcedure( c.JSON(int(problemDetails.Status), problemDetails) return } - defer func() { - if rspCloseErr := rsp.Body.Close(); rspCloseErr != nil { - logger.SdmLog.Errorf("ModifyAuthentication response body cannot close: %+v", rspCloseErr) - } - }() // Run milenage macA, macS := make([]byte, 8), make([]byte, 8) @@ -498,7 +447,7 @@ func (p *Processor) GenerateAuthDataProcedure( logger.UeauLog.Tracef("AUTN=[%x]", AUTN) var av models.AuthenticationVector - if authSubs.AuthenticationMethod == models.AuthMethod__5_G_AKA { + if authSubs.AuthenticationSubscription.AuthenticationMethod == models.AuthMethod__5_G_AKA { response.AuthType = models.AuthType__5_G_AKA // derive XRES* From 4676be3bfd42694c8c802f90441b3357a8bd3b96 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Fri, 26 Jul 2024 10:38:28 +0000 Subject: [PATCH 11/41] feat: update server route --- internal/sbi/api_eventexposure.go | 6 ++--- internal/sbi/api_parameterprovision.go | 2 +- internal/sbi/api_subscriberdatamanagement.go | 28 ++++++++++---------- internal/sbi/api_uecontextmanagement.go | 28 ++++++++++---------- internal/sbi/server.go | 2 +- 5 files changed, 33 insertions(+), 33 deletions(-) diff --git a/internal/sbi/api_eventexposure.go b/internal/sbi/api_eventexposure.go index b34ab88..db06efb 100644 --- a/internal/sbi/api_eventexposure.go +++ b/internal/sbi/api_eventexposure.go @@ -21,21 +21,21 @@ func (s *Server) getEventExposureRoutes() []Route { }, { - "HTTPCreateEeSubscription", + "CreateEeSubscription", strings.ToUpper("Post"), "/:ueIdentity/ee-subscriptions", s.HandleCreateEeSubscription, }, { - "HTTPDeleteEeSubscription", + "DeleteEeSubscription", strings.ToUpper("Delete"), "/:ueIdentity/ee-subscriptions/:subscriptionId", s.HandleDeleteEeSubscription, }, { - "HTTPUpdateEeSubscription", + "UpdateEeSubscription", strings.ToUpper("Patch"), "/:ueIdentity/ee-subscriptions/:subscriptionId", s.HandleUpdateEeSubscription, diff --git a/internal/sbi/api_parameterprovision.go b/internal/sbi/api_parameterprovision.go index 2e695ca..aef8ba0 100644 --- a/internal/sbi/api_parameterprovision.go +++ b/internal/sbi/api_parameterprovision.go @@ -23,7 +23,7 @@ func (s *Server) getParameterProvisionRoutes() []Route { { "Update", strings.ToUpper("Patch"), - "/:gpsi/pp-data", + "/:ueId/pp-data", s.HandleUpdate, }, } diff --git a/internal/sbi/api_subscriberdatamanagement.go b/internal/sbi/api_subscriberdatamanagement.go index 52a3cbd..c286d76 100644 --- a/internal/sbi/api_subscriberdatamanagement.go +++ b/internal/sbi/api_subscriberdatamanagement.go @@ -417,9 +417,9 @@ func (s *Server) TwoLayerPathHandlerFunc(c *gin.Context) { return } - // for "/:gpsi/id-translation-result" + // for "/:ueId/id-translation-result" if op == "id-translation-result" && strings.ToUpper("Get") == c.Request.Method { - c.Params = append(c.Params, gin.Param{Key: "gpsi", Value: c.Param("supi")}) + c.Params = append(c.Params, gin.Param{Key: "ueId", Value: c.Param("supi")}) s.HandleGetIdTranslationResult(c) return } @@ -438,10 +438,10 @@ func (s *Server) TwoLayerPathHandlerFunc(c *gin.Context) { func (s *Server) ThreeLayerPathHandlerFunc(c *gin.Context) { op := c.Param("subscriptionId") - // for "/:supi/sdm-subscriptions/:subscriptionId" + // for "/:ueId/sdm-subscriptions/:subscriptionId" if op == "sdm-subscriptions" && strings.ToUpper("Delete") == c.Request.Method { var tmpParams gin.Params - tmpParams = append(tmpParams, gin.Param{Key: "supi", Value: c.Param("supi")}) + tmpParams = append(tmpParams, gin.Param{Key: "ueId", Value: c.Param("supi")}) tmpParams = append(tmpParams, gin.Param{Key: "subscriptionId", Value: c.Param("thirdLayer")}) c.Params = tmpParams s.HandleUnsubscribe(c) @@ -454,10 +454,10 @@ func (s *Server) ThreeLayerPathHandlerFunc(c *gin.Context) { return } - // for "/:supi/sdm-subscriptions/:subscriptionId" + // for "/:ueId/sdm-subscriptions/:subscriptionId" if op == "sdm-subscriptions" && strings.ToUpper("Patch") == c.Request.Method { var tmpParams gin.Params - tmpParams = append(tmpParams, gin.Param{Key: "supi", Value: c.Param("supi")}) + tmpParams = append(tmpParams, gin.Param{Key: "ueId", Value: c.Param("supi")}) tmpParams = append(tmpParams, gin.Param{Key: "subscriptionId", Value: c.Param("thirdLayer")}) c.Params = tmpParams s.HandleModify(c) @@ -470,7 +470,7 @@ func (s *Server) ThreeLayerPathHandlerFunc(c *gin.Context) { func (s *Server) getOneLayerRoutes() []Route { return []Route{ { - "GetSupi", + "GetDataSets", strings.ToUpper("Get"), "/:supi", s.HandleGetSupi, @@ -502,14 +502,14 @@ func (s *Server) getTwoLayerRoutes() []Route { }, { - "GetSmfSelectData", + "GetSmfSelData", strings.ToUpper("Get"), "/:supi/smf-select-data", s.HandleGetSmfSelectData, }, { - "GetSmsMngData", + "GetSmsMngtData", strings.ToUpper("Get"), "/:supi/sms-mng-data", s.HandleGetSmsMngData, @@ -530,7 +530,7 @@ func (s *Server) getTwoLayerRoutes() []Route { }, { - "GetNssai", + "GetNSSAI", strings.ToUpper("Get"), "/:supi/nssai", s.HandleGetNssai, @@ -539,26 +539,26 @@ func (s *Server) getTwoLayerRoutes() []Route { { "Subscribe", strings.ToUpper("Post"), - "/:supi/sdm-subscriptions", + "/:ueId/sdm-subscriptions", s.HandleSubscribe, }, { - "GetTraceData", + "GetTraceConfigData", strings.ToUpper("Get"), "/:supi/trace-data", s.HandleGetTraceData, }, { - "GetUeContextInSmfData", + "GetUeCtxInSmfData", strings.ToUpper("Get"), "/:supi/ue-context-in-smf-data", s.HandleGetUeContextInSmfData, }, { - "GetUeContextInSmsfData", + "GetUeCtxInSmsfData", strings.ToUpper("Get"), "/:supi/ue-context-in-smsf-data", s.HandleGetUeContextInSmsfData, diff --git a/internal/sbi/api_uecontextmanagement.go b/internal/sbi/api_uecontextmanagement.go index f667099..ce9ffe8 100644 --- a/internal/sbi/api_uecontextmanagement.go +++ b/internal/sbi/api_uecontextmanagement.go @@ -22,98 +22,98 @@ func (s *Server) getUEContextManagementRoutes() []Route { }, { - "GetAmf3gppAccess", + "Get3GppRegistration", strings.ToUpper("Get"), "/:ueId/registrations/amf-3gpp-access", s.HandleGetAmf3gppAccess, }, { - "GetAmfNon3gppAccess", + "GetNon3GppRegistration", strings.ToUpper("Get"), "/:ueId/registrations/amf-non-3gpp-access", s.HandleGetAmfNon3gppAccess, }, { - "RegistrationAmf3gppAccess", + "Call3GppRegistration", strings.ToUpper("Put"), "/:ueId/registrations/amf-3gpp-access", s.HandleRegistrationAmf3gppAccess, }, { - "Register", + "Non3GppRegistration", strings.ToUpper("Put"), "/:ueId/registrations/amf-non-3gpp-access", s.HandleRegistrationAmfNon3gppAccess, }, { - "UpdateAmf3gppAccess", + "Update3GppRegistration", strings.ToUpper("Patch"), "/:ueId/registrations/amf-3gpp-access", s.HandleUpdateAmf3gppAccess, }, { - "UpdateAmfNon3gppAccess", + "UpdateNon3GppRegistration", strings.ToUpper("Patch"), "/:ueId/registrations/amf-non-3gpp-access", s.HandleUpdateAmfNon3gppAccess, }, { - "DeregistrationSmfRegistrations", + "SmfDeregistration", strings.ToUpper("Delete"), "/:ueId/registrations/smf-registrations/:pduSessionId", s.HandleDeregistrationSmfRegistrations, }, { - "RegistrationSmfRegistrations", + "Registration", strings.ToUpper("Put"), "/:ueId/registrations/smf-registrations/:pduSessionId", s.HandleRegistrationSmfRegistrations, }, { - "GetSmsf3gppAccess", + "Get3GppSmsfRegistration", strings.ToUpper("Get"), "/:ueId/registrations/smsf-3gpp-access", s.HandleGetSmsf3gppAccess, }, { - "DeregistrationSmsf3gppAccess", + "Call3GppSmsfDeregistration", strings.ToUpper("Delete"), "/:ueId/registrations/smsf-3gpp-access", s.HandleDeregistrationSmsf3gppAccess, }, { - "DeregistrationSmsfNon3gppAccess", + "Non3GppSmsfDeregistration", strings.ToUpper("Delete"), "/:ueId/registrations/smsf-non-3gpp-access", s.HandleDeregistrationSmsfNon3gppAccess, }, { - "GetSmsfNon3gppAccess", + "GetNon3GppSmsfRegistration", strings.ToUpper("Get"), "/:ueId/registrations/smsf-non-3gpp-access", s.HandleGetSmsfNon3gppAccess, }, { - "UpdateSMSFReg3GPP", + "Call3GppSmsfRegistration", strings.ToUpper("Put"), "/:ueId/registrations/smsf-3gpp-access", s.HandleUpdateSMSFReg3GPP, }, { - "RegistrationSmsfNon3gppAccess", + "Non3GppSmsfRegistration", strings.ToUpper("Put"), "/:ueId/registrations/smsf-non-3gpp-access", s.HandleRegistrationSmsfNon3gppAccess, diff --git a/internal/sbi/server.go b/internal/sbi/server.go index 86a8e7f..e4a08a3 100644 --- a/internal/sbi/server.go +++ b/internal/sbi/server.go @@ -164,7 +164,7 @@ func newRouter(s *Server) *gin.Engine { }) AddService(udmUEAUGroup, udmUEAURoutes) - genAuthDataPath := "/:supi/security-information/generate-auth-data" + genAuthDataPath := "/:supiOrSuci/security-information/generate-auth-data" udmUEAUGroup.Any(genAuthDataPath, s.GenAuthDataHandlerFunc) // UECM From f45ec10f056c997d5a89770002bf6d34d1229b48 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Fri, 26 Jul 2024 11:34:24 +0000 Subject: [PATCH 12/41] fix: lint error --- internal/sbi/processor/generate_auth_data.go | 1 - internal/sbi/processor/notifier.go | 4 ++-- internal/sbi/processor/parameter_provision.go | 3 +-- .../processor/subscriber_data_management.go | 21 ++++++------------- .../sbi/processor/ue_context_management.go | 9 ++------ 5 files changed, 11 insertions(+), 27 deletions(-) diff --git a/internal/sbi/processor/generate_auth_data.go b/internal/sbi/processor/generate_auth_data.go index 99a8a31..3217691 100644 --- a/internal/sbi/processor/generate_auth_data.go +++ b/internal/sbi/processor/generate_auth_data.go @@ -151,7 +151,6 @@ func (p *Processor) GenerateAuthDataProcedure( queryAuthSubsDataRequest.UeId = &supi authSubs, err := client.AuthenticationDataDocumentApi.QueryAuthSubsData(ctx, &queryAuthSubsDataRequest) - if err != nil { problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) if !ok { diff --git a/internal/sbi/processor/notifier.go b/internal/sbi/processor/notifier.go index bd92fde..a481bc4 100644 --- a/internal/sbi/processor/notifier.go +++ b/internal/sbi/processor/notifier.go @@ -57,13 +57,13 @@ func (p *Processor) SendOnDeregistrationNotification(ueId string, onDeregistrati } clientAPI := p.Consumer().GetUECMClient("SendOnDeregistrationNotification") - var call3GppRegistrationDeregistrationNotificationPostRequest UEContextManagement.Call3GppRegistrationDeregistrationNotificationPostRequest + var call3GppRegistrationDeregistrationNotificationPostRequest UEContextManagement. + Call3GppRegistrationDeregistrationNotificationPostRequest call3GppRegistrationDeregistrationNotificationPostRequest.UdmUecmDeregistrationData = &deregistData _, err = clientAPI.AMFRegistrationFor3GPPAccessApi. Call3GppRegistrationDeregistrationNotificationPost(ctx, onDeregistrationNotificationUrl, &call3GppRegistrationDeregistrationNotificationPostRequest) - if err != nil { problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) if !ok { diff --git a/internal/sbi/processor/parameter_provision.go b/internal/sbi/processor/parameter_provision.go index fd085c1..f64c12c 100644 --- a/internal/sbi/processor/parameter_provision.go +++ b/internal/sbi/processor/parameter_provision.go @@ -3,11 +3,11 @@ package processor import ( "net/http" - Nudr_DataRepository "github.com/free5gc/openapi/udr/DataRepository" "github.com/gin-gonic/gin" "github.com/free5gc/openapi" "github.com/free5gc/openapi/models" + Nudr_DataRepository "github.com/free5gc/openapi/udr/DataRepository" ) func (p *Processor) UpdateProcedure(c *gin.Context, @@ -28,7 +28,6 @@ func (p *Processor) UpdateProcedure(c *gin.Context, var modifyPpDataRequest Nudr_DataRepository.ModifyPpDataRequest modifyPpDataRequest.UeId = &gpsi modifyPpDataRsp, err := clientAPI.ProvisionedParameterDataDocumentApi.ModifyPpData(ctx, &modifyPpDataRequest) - if err != nil { problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) if !ok { diff --git a/internal/sbi/processor/subscriber_data_management.go b/internal/sbi/processor/subscriber_data_management.go index 5e14fc2..0fb571e 100644 --- a/internal/sbi/processor/subscriber_data_management.go +++ b/internal/sbi/processor/subscriber_data_management.go @@ -56,7 +56,6 @@ func (p *Processor) GetAmDataProcedure(c *gin.Context, supi string, plmnID strin func (p *Processor) GetIdTranslationResultProcedure(c *gin.Context, gpsi string) { ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NrfNfManagementNfType_UDR) - if err != nil { c.JSON(int(pd.Status), pd) } @@ -194,7 +193,6 @@ func (p *Processor) GetSupiProcedure(c *gin.Context, } udmUe.SetSmfSelectionSubsData(&smfSelDataRsp.SmfSelectionSubscriptionData) subscriptionDataSets.SmfSelData = &smfSelDataRsp.SmfSelectionSubscriptionData - } if p.containDataSetName(dataSetNames, string(models.SdmDataSetName_UEC_SMF)) { var UeContextInSmfbody models.UeContextInSmfData @@ -240,7 +238,6 @@ func (p *Processor) GetSupiProcedure(c *gin.Context, } udmUe.UeCtxtInSmfData = &ueContextInSmfDataResp subscriptionDataSets.UecSmfData = &ueContextInSmfDataResp - } // TODO: UE Context in SMSF Data @@ -271,10 +268,10 @@ func (p *Processor) GetSupiProcedure(c *gin.Context, if !ok { udmUe = p.Context().NewUdmUe(supi) } - smData, _, _, _ := p.Context().ManageSmData(sessionManagementSubscriptionDataRsp.SmSubsData.IndividualSmSubsData, "", "") + smData, _, _, _ := p.Context(). + ManageSmData(sessionManagementSubscriptionDataRsp.SmSubsData.IndividualSmSubsData, "", "") udmUe.SetSMSubsData(smData) subscriptionDataSets.SmData = sessionManagementSubscriptionDataRsp.SmSubsData.IndividualSmSubsData - } if p.containDataSetName(dataSetNames, string(models.DataSetName_TRACE)) { @@ -303,7 +300,6 @@ func (p *Processor) GetSupiProcedure(c *gin.Context, udmUe.TraceData = &traceDataRsp.TraceData udmUe.TraceDataResponse.TraceData = &traceDataRsp.TraceData subscriptionDataSets.TraceData = &traceDataRsp.TraceData - } // TODO: SMS Management Subscription Data @@ -425,7 +421,6 @@ func (p *Processor) GetSmDataProcedure( defer udmUe.SmSubsDataLock.RUnlock() c.JSON(http.StatusOK, udmUe.SessionManagementSubsData) } - } func (p *Processor) GetNssaiProcedure(c *gin.Context, supi string, plmnID string, supportedFeatures string) { @@ -468,7 +463,6 @@ func (p *Processor) GetNssaiProcedure(c *gin.Context, supi string, plmnID string } udmUe.Nssai = &nssaiResp c.JSON(http.StatusOK, udmUe.Nssai) - } func (p *Processor) GetSmfSelectDataProcedure(c *gin.Context, supi string, plmnID string, supportedFeatures string) { @@ -512,7 +506,6 @@ func (p *Processor) GetSmfSelectDataProcedure(c *gin.Context, supi string, plmnI } udmUe.SetSmfSelectionSubsData(&smfSelectionSubscriptionDataResp.SmfSelectionSubscriptionData) c.JSON(http.StatusOK, udmUe.SmfSelSubsData) - } func (p *Processor) SubscribeToSharedDataProcedure(c *gin.Context, sdmSubscription *models.SdmSubscription) { @@ -527,7 +520,6 @@ func (p *Processor) SubscribeToSharedDataProcedure(c *gin.Context, sdmSubscripti sdmSubscriptionResp, err := udmClientAPI.SubscriptionCreationForSharedDataApi.SubscribeToSharedData( ctx, &subscibeToShareDataRequest) - if err != nil { problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) if !ok { @@ -539,7 +531,8 @@ func (p *Processor) SubscribeToSharedDataProcedure(c *gin.Context, sdmSubscripti return } - p.Context().CreateSubstoNotifSharedData(sdmSubscriptionResp.SdmSubscription.SubscriptionId, &sdmSubscriptionResp.SdmSubscription) + p.Context().CreateSubstoNotifSharedData(sdmSubscriptionResp.SdmSubscription.SubscriptionId, + &sdmSubscriptionResp.SdmSubscription) reourceUri := p.Context(). GetSDMUri() + "//shared-data-subscriptions/" + sdmSubscriptionResp.SdmSubscription.SubscriptionId @@ -578,10 +571,10 @@ func (p *Processor) SubscribeProcedure(c *gin.Context, sdmSubscription *models.S if udmUe == nil { udmUe = p.Context().NewUdmUe(supi) } - udmUe.CreateSubscriptiontoNotifChange(sdmSubscriptionResp.SdmSubscription.SubscriptionId, &sdmSubscriptionResp.SdmSubscription) + udmUe.CreateSubscriptiontoNotifChange(sdmSubscriptionResp.SdmSubscription.SubscriptionId, + &sdmSubscriptionResp.SdmSubscription) c.Header("Location", udmUe.GetLocationURI2(udm_context.LocationUriSdmSubscription, supi)) c.JSON(http.StatusCreated, sdmSubscriptionResp.SdmSubscription) - } func (p *Processor) UnsubscribeForSharedDataProcedure(c *gin.Context, subscriptionID string) { @@ -608,7 +601,6 @@ func (p *Processor) UnsubscribeForSharedDataProcedure(c *gin.Context, subscripti } c.Status(http.StatusNoContent) - } func (p *Processor) UnsubscribeProcedure(c *gin.Context, supi string, subscriptionID string) { @@ -826,7 +818,6 @@ func (p *Processor) GetUeContextInSmfDataProcedure(c *gin.Context, supi string, } udmUe.UeCtxtInSmfData = &ueContextInSmfData c.JSON(http.StatusOK, udmUe.UeCtxtInSmfData) - } func (p *Processor) containDataSetName(dataSetNames []string, target string) bool { diff --git a/internal/sbi/processor/ue_context_management.go b/internal/sbi/processor/ue_context_management.go index e546309..e661dda 100644 --- a/internal/sbi/processor/ue_context_management.go +++ b/internal/sbi/processor/ue_context_management.go @@ -48,7 +48,8 @@ func (p *Processor) GetAmf3gppAccessProcedure(c *gin.Context, ueID string, suppo } func (p *Processor) GetAmfNon3gppAccessProcedure(c *gin.Context, queryAmfContextNon3gppParamOpts Nudr_DataRepository. - QueryAmfContextNon3gppRequest, ueID string) { + QueryAmfContextNon3gppRequest, ueID string, +) { ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NrfNfManagementNfType_UDR) if err != nil { c.JSON(int(pd.Status), pd) @@ -61,7 +62,6 @@ func (p *Processor) GetAmfNon3gppAccessProcedure(c *gin.Context, queryAmfContext } amfNon3GppAccessRegistrationResponse, err := clientAPI.AMFNon3GPPAccessRegistrationDocumentApi. QueryAmfContextNon3gpp(ctx, &queryAmfContextNon3gppParamOpts) - if err != nil { problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) if !ok { @@ -184,7 +184,6 @@ func (p *Processor) RegisterAmfNon3gppAccessProcedure(c *gin.Context, _, err = clientAPI.AMFNon3GPPAccessRegistrationDocumentApi.CreateAmfContextNon3gpp( ctx, &createAmfContextNon3gppRequest) - if err != nil { problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) if !ok { @@ -301,7 +300,6 @@ func (p *Processor) UpdateAmf3gppAccessProcedure(c *gin.Context, amfContext3gppRequest.PatchItem = patchItemReqArray _, err = clientAPI.AMF3GPPAccessRegistrationDocumentApi.AmfContext3gpp(ctx, &amfContext3gppRequest) - if err != nil { problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) if !ok { @@ -407,7 +405,6 @@ func (p *Processor) UpdateAmfNon3gppAccessProcedure(c *gin.Context, amfContextNon3gppRequest.PatchItem = patchItemReqArray _, err = clientAPI.AMFNon3GPPAccessRegistrationDocumentApi.AmfContextNon3gpp(ctx, &amfContextNon3gppRequest) - if err != nil { problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) if !ok { @@ -452,7 +449,6 @@ func (p *Processor) DeregistrationSmfRegistrationsProcedure(c *gin.Context, deleteSmfRegistrationRequest.UeId = &ueID deleteSmfRegistrationRequest.PduSessionId = &pduSessionIDInt32 _, err = clientAPI.SMFRegistrationDocumentApi.DeleteSmfRegistration(ctx, &deleteSmfRegistrationRequest) - if err != nil { problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) if !ok { @@ -502,7 +498,6 @@ func (p *Processor) RegistrationSmfRegistrationsProcedure( return } _, err = clientAPI.SMFRegistrationDocumentApi.CreateOrUpdateSmfRegistration(ctx, &createSmfContext3gppRequest) - if err != nil { problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) if !ok { From da36e98aa453771f4d03ced213c04ca58c5f4ff9 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Fri, 26 Jul 2024 11:40:57 +0000 Subject: [PATCH 13/41] fix: lint error --- internal/context/context.go | 4 +++- internal/sbi/consumer/nrf_service.go | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/context/context.go b/internal/context/context.go index df7649a..99dd97e 100644 --- a/internal/context/context.go +++ b/internal/context/context.go @@ -178,7 +178,9 @@ func MappingSharedData(sharedDatafromUDR []models.UdmSdmSharedData) (mp map[stri return sharedSubsDataMap } -func ObtainRequiredSharedData(Sharedids []string, response []models.UdmSdmSharedData) (sharedDatas []models.UdmSdmSharedData) { +func ObtainRequiredSharedData(Sharedids []string, response []models.UdmSdmSharedData) ( + sharedDatas []models.UdmSdmSharedData, +) { sharedSubsDataMap := MappingSharedData(response) Allkeys := make([]string, len(sharedSubsDataMap)) MatchedKeys := make([]string, len(Sharedids)) diff --git a/internal/sbi/consumer/nrf_service.go b/internal/sbi/consumer/nrf_service.go index df212a6..dc65887 100644 --- a/internal/sbi/consumer/nrf_service.go +++ b/internal/sbi/consumer/nrf_service.go @@ -163,7 +163,8 @@ func (s *nnrfService) RegisterNFInstance(ctx context.Context) ( registerNfInstanceRequest.NfInstanceID = &udmContext.NfId registerNfInstanceRequest.NrfNfManagementNfProfile = &nfProfile for { - res, err := client.NFInstanceIDDocumentApi.RegisterNFInstance(ctx, ®isterNfInstanceRequest) + var res *Nnrf_NFManagement.RegisterNFInstanceResponse + res, err = client.NFInstanceIDDocumentApi.RegisterNFInstance(ctx, ®isterNfInstanceRequest) var status int32 if err != nil || res == nil { @@ -207,7 +208,9 @@ func (s *nnrfService) RegisterNFInstance(ctx context.Context) ( return resouceNrfUri, retrieveNfInstanceID, err } -func (s *nnrfService) buildNfProfile(udmContext *udm_context.UDMContext) (profile models.NrfNfManagementNfProfile, err error) { +func (s *nnrfService) buildNfProfile(udmContext *udm_context.UDMContext) ( + profile models.NrfNfManagementNfProfile, err error, +) { profile.NfInstanceId = udmContext.NfId profile.NfType = models.NrfNfManagementNfType_UDM profile.NfStatus = models.NrfNfManagementNfStatus_REGISTERED From 930f734b47319ac7f0bceac9e2f7a1512d4fd64b Mon Sep 17 00:00:00 2001 From: ubuntu Date: Wed, 31 Jul 2024 05:36:40 +0000 Subject: [PATCH 14/41] feat: add generate_auth_data_test --- .../sbi/processor/generate_auth_data_test.go | 78 ++++++++++ pkg/mockapp/mock.go | 145 ++++++++++++++++++ 2 files changed, 223 insertions(+) create mode 100644 internal/sbi/processor/generate_auth_data_test.go create mode 100644 pkg/mockapp/mock.go diff --git a/internal/sbi/processor/generate_auth_data_test.go b/internal/sbi/processor/generate_auth_data_test.go new file mode 100644 index 0000000..e7723a8 --- /dev/null +++ b/internal/sbi/processor/generate_auth_data_test.go @@ -0,0 +1,78 @@ +package processor + +import ( + "net/http/httptest" + "testing" + + "github.com/free5gc/openapi" + "github.com/free5gc/openapi/models" + Nudr_DataRepository "github.com/free5gc/openapi/udr/DataRepository" + udm_context "github.com/free5gc/udm/internal/context" + "github.com/free5gc/udm/internal/sbi/consumer" + mockapp "github.com/free5gc/udm/pkg/mockapp" + "github.com/gin-gonic/gin" + "github.com/h2non/gock" + "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" +) + +func TestGenerateAuthDataProcedure(t *testing.T) { + defer gock.Off() // Flush pending mocks after test execution + + gock.InterceptClient(openapi.GetHttpClient()) + defer gock.RestoreClient(openapi.GetHttpClient()) + + queryRes := Nudr_DataRepository.QueryAuthSubsDataResponse{ + AuthenticationSubscription: models.AuthenticationSubscription{ + AuthenticationMethod: models.AuthMethod__5_G_AKA, + EncPermanentKey: "8baf473f2f8fd09487cccbd7097c6862", + ProtectionParameterId: "8baf473f2f8fd09487cccbd7097c6862", + SequenceNumber: &models.SequenceNumber{Sqn: "000000000023"}, + AuthenticationManagementField: "8000", + AlgorithmId: "128-EEA0", + EncOpcKey: "8e27b6af0e692e750f32667a3b14605d", + EncTopcKey: "8e27b6", + }, + } + + gock.New("http://127.0.0.4:8000/nudr-dr/v2"). + Get("/subscription-data/imsi-208930000000001/authentication-data/authentication-subscription"). + Reply(200). + AddHeader("Content-Type", "application/json"). + JSON(queryRes) + + gock.New("http://127.0.0.4:8000"). + Patch("/nudr-dr/v2/subscription-data/imsi-208930000000001/authentication-data/authentication-subscription"). + Reply(204). + JSON(map[string]string{}) + + ctrl := gomock.NewController(t) + defer ctrl.Finish() + mockApp := mockapp.NewMockApp(ctrl) + testConsumer, err := consumer.NewConsumer(mockApp) + require.NoError(t, err) + testProcessor, err := NewProcessor(mockApp) + require.NoError(t, err) + udm_context.GetSelf().NrfUri = "http://127.0.0.10:8000" + ue := new(udm_context.UdmUeContext) + ue.Init() + ue.Supi = "imsi-208930000000001" + ue.UdrUri = "http://127.0.0.4:8000" + udm_context.GetSelf().UdmUePool.Store("imsi-208930000000001", ue) + + mockApp.EXPECT().Consumer().Return(testConsumer).AnyTimes() + mockApp.EXPECT().Context().Return( + &udm_context.UDMContext{ + OAuth2Required: false, + NrfUri: "http://127.0.0.10:8000", + NfId: "1", + }, + ).AnyTimes() + + authInfoReq := models.AuthenticationInfoRequest{ + ServingNetworkName: "internet", + } + httpRecorder := httptest.NewRecorder() + c, _ := gin.CreateTestContext(httpRecorder) + testProcessor.GenerateAuthDataProcedure(c, authInfoReq, "imsi-208930000000001") +} diff --git a/pkg/mockapp/mock.go b/pkg/mockapp/mock.go new file mode 100644 index 0000000..399967f --- /dev/null +++ b/pkg/mockapp/mock.go @@ -0,0 +1,145 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: app.go +// +// Generated by this command: +// +// mockgen -source=app.go -destination=mock.go -package=app +// + +// Package app is a generated GoMock package. +package service + +import ( + reflect "reflect" + + context "github.com/free5gc/udm/internal/context" + consumer "github.com/free5gc/udm/internal/sbi/consumer" + factory "github.com/free5gc/udm/pkg/factory" + gomock "go.uber.org/mock/gomock" +) + +// MockApp is a mock of App interface. +type MockApp struct { + ctrl *gomock.Controller + recorder *MockAppMockRecorder +} + +// MockAppMockRecorder is the mock recorder for MockApp. +type MockAppMockRecorder struct { + mock *MockApp +} + +// NewMockApp creates a new mock instance. +func NewMockApp(ctrl *gomock.Controller) *MockApp { + mock := &MockApp{ctrl: ctrl} + mock.recorder = &MockAppMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockApp) EXPECT() *MockAppMockRecorder { + return m.recorder +} + +// Config mocks base method. +func (m *MockApp) Config() *factory.Config { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Config") + ret0, _ := ret[0].(*factory.Config) + return ret0 +} + +// Config indicates an expected call of Config. +func (mr *MockAppMockRecorder) Config() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Config", reflect.TypeOf((*MockApp)(nil).Config)) +} + +// Context mocks base method. +func (m *MockApp) Context() *context.UDMContext { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Context") + ret0, _ := ret[0].(*context.UDMContext) + return ret0 +} + +// Context indicates an expected call of Context. +func (mr *MockAppMockRecorder) Context() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Context", reflect.TypeOf((*MockApp)(nil).Context)) +} + +// Consumer mocks base method. +func (m *MockApp) Consumer() *consumer.Consumer { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Consumer") + ret0, _ := ret[0].(*consumer.Consumer) + return ret0 +} + +// Consumer indicates an expected call of Consumer. +func (mr *MockAppMockRecorder) Consumer() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Consumer", reflect.TypeOf((*MockApp)(nil).Consumer)) +} + + +// SetLogEnable mocks base method. +func (m *MockApp) SetLogEnable(enable bool) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "SetLogEnable", enable) +} + +// SetLogEnable indicates an expected call of SetLogEnable. +func (mr *MockAppMockRecorder) SetLogEnable(enable any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetLogEnable", reflect.TypeOf((*MockApp)(nil).SetLogEnable), enable) +} + +// SetLogLevel mocks base method. +func (m *MockApp) SetLogLevel(level string) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "SetLogLevel", level) +} + +// SetLogLevel indicates an expected call of SetLogLevel. +func (mr *MockAppMockRecorder) SetLogLevel(level any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetLogLevel", reflect.TypeOf((*MockApp)(nil).SetLogLevel), level) +} + +// SetReportCaller mocks base method. +func (m *MockApp) SetReportCaller(reportCaller bool) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "SetReportCaller", reportCaller) +} + +// SetReportCaller indicates an expected call of SetReportCaller. +func (mr *MockAppMockRecorder) SetReportCaller(reportCaller any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetReportCaller", reflect.TypeOf((*MockApp)(nil).SetReportCaller), reportCaller) +} + +// Start mocks base method. +func (m *MockApp) Start() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Start") +} + +// Start indicates an expected call of Start. +func (mr *MockAppMockRecorder) Start() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Start", reflect.TypeOf((*MockApp)(nil).Start)) +} + +// Terminate mocks base method. +func (m *MockApp) Terminate() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Terminate") +} + +// Terminate indicates an expected call of Terminate. +func (mr *MockAppMockRecorder) Terminate() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Terminate", reflect.TypeOf((*MockApp)(nil).Terminate)) +} \ No newline at end of file From 4d35c61f07823ad9e5ec0e4e6bcab31818076f9f Mon Sep 17 00:00:00 2001 From: "CTFang@WireLab" Date: Wed, 31 Jul 2024 06:35:32 +0000 Subject: [PATCH 15/41] fix: test and linter --- internal/sbi/processor/generate_auth_data.go | 6 +- .../sbi/processor/generate_auth_data_test.go | 66 ++++++++++++++----- 2 files changed, 54 insertions(+), 18 deletions(-) diff --git a/internal/sbi/processor/generate_auth_data.go b/internal/sbi/processor/generate_auth_data.go index 3217691..fafad12 100644 --- a/internal/sbi/processor/generate_auth_data.go +++ b/internal/sbi/processor/generate_auth_data.go @@ -188,6 +188,7 @@ func (p *Processor) GenerateAuthDataProcedure( problemDetails := &models.ProblemDetails{ Status: http.StatusForbidden, Cause: authenticationRejected, + Detail: "len(kStr) != keyStrLen", } logger.UeauLog.Errorln("kStr length is ", len(kStr)) @@ -198,6 +199,7 @@ func (p *Processor) GenerateAuthDataProcedure( problemDetails := &models.ProblemDetails{ Status: http.StatusForbidden, Cause: authenticationRejected, + Detail: "EncPermanentKey == ''", } logger.UeauLog.Errorln("Nil PermanentKey") @@ -315,10 +317,10 @@ func (p *Processor) GenerateAuthDataProcedure( problemDetails := &models.ProblemDetails{ Status: http.StatusForbidden, Cause: authenticationRejected, - Detail: deCodeErr.Error(), + Detail: err.Error(), } - logger.UeauLog.Errorln("err:", deCodeErr) + logger.UeauLog.Errorln("err:", err) c.JSON(int(problemDetails.Status), problemDetails) return } diff --git a/internal/sbi/processor/generate_auth_data_test.go b/internal/sbi/processor/generate_auth_data_test.go index e7723a8..591e8f9 100644 --- a/internal/sbi/processor/generate_auth_data_test.go +++ b/internal/sbi/processor/generate_auth_data_test.go @@ -1,19 +1,20 @@ package processor import ( + "io" "net/http/httptest" "testing" + "github.com/gin-gonic/gin" + "github.com/h2non/gock" + "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" + "github.com/free5gc/openapi" "github.com/free5gc/openapi/models" - Nudr_DataRepository "github.com/free5gc/openapi/udr/DataRepository" udm_context "github.com/free5gc/udm/internal/context" "github.com/free5gc/udm/internal/sbi/consumer" mockapp "github.com/free5gc/udm/pkg/mockapp" - "github.com/gin-gonic/gin" - "github.com/h2non/gock" - "github.com/stretchr/testify/require" - "go.uber.org/mock/gomock" ) func TestGenerateAuthDataProcedure(t *testing.T) { @@ -22,17 +23,15 @@ func TestGenerateAuthDataProcedure(t *testing.T) { gock.InterceptClient(openapi.GetHttpClient()) defer gock.RestoreClient(openapi.GetHttpClient()) - queryRes := Nudr_DataRepository.QueryAuthSubsDataResponse{ - AuthenticationSubscription: models.AuthenticationSubscription{ - AuthenticationMethod: models.AuthMethod__5_G_AKA, - EncPermanentKey: "8baf473f2f8fd09487cccbd7097c6862", - ProtectionParameterId: "8baf473f2f8fd09487cccbd7097c6862", - SequenceNumber: &models.SequenceNumber{Sqn: "000000000023"}, - AuthenticationManagementField: "8000", - AlgorithmId: "128-EEA0", - EncOpcKey: "8e27b6af0e692e750f32667a3b14605d", - EncTopcKey: "8e27b6", - }, + queryRes := models.AuthenticationSubscription{ + AuthenticationMethod: models.AuthMethod__5_G_AKA, + EncPermanentKey: "8baf473f2f8fd09487cccbd7097c6862", + ProtectionParameterId: "8baf473f2f8fd09487cccbd7097c6862", + SequenceNumber: &models.SequenceNumber{Sqn: "000000000023"}, + AuthenticationManagementField: "8000", + AlgorithmId: "128-EEA0", + EncOpcKey: "8e27b6af0e692e750f32667a3b14605d", + EncTopcKey: "8e27b6", } gock.New("http://127.0.0.4:8000/nudr-dr/v2"). @@ -75,4 +74,39 @@ func TestGenerateAuthDataProcedure(t *testing.T) { httpRecorder := httptest.NewRecorder() c, _ := gin.CreateTestContext(httpRecorder) testProcessor.GenerateAuthDataProcedure(c, authInfoReq, "imsi-208930000000001") + + httpResp := httpRecorder.Result() + if errClose := httpResp.Body.Close(); errClose != nil { + t.Fatalf("Failed to close response body: %+v", errClose) + } + + rawBytes, errReadAll := io.ReadAll(httpResp.Body) + if errReadAll != nil { + t.Fatalf("Failed to read response body: %+v", errReadAll) + } + + var res models.AuthenticationInfoResult + err = openapi.Deserialize(&res, rawBytes, httpResp.Header.Get("Content-Type")) + if err != nil { + t.Fatalf("Failed to deserialize response body: %+v", err) + } + + expectResponse := models.AuthenticationInfoResult{ + AuthType: "5G_AKA", + AuthenticationVector: &models.AuthenticationVector{ + AvType: "5G_HE_AKA", + // Rand: "6823f0dc9da02a61f6224d278a6f65b0", + // Autn: "1a7692538cf2800082662b9daa0396c5", + // XresStar: "10e6e9e7d4ed291e7b2dc81e41f1da17", + // Kausf: "b0066a373555e6cd3efabfd14dfbc0bd91f5792445e2d80748daeb0a629d9b09", + }, + Supi: "imsi-208930000000001", + } + + require.Equal(t, 200, httpResp.StatusCode) + + // Since GenerateAuthData have randomness, only check fix value + require.Equal(t, expectResponse.AuthType, res.AuthType) + require.Equal(t, expectResponse.Supi, res.Supi) + require.Equal(t, expectResponse.AuthenticationVector.AvType, res.AuthenticationVector.AvType) } From 81bc7214825626706fcf3964c453f8e187608ac7 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Fri, 9 Aug 2024 09:34:35 +0000 Subject: [PATCH 16/41] fix: nrf_deregistration error type assertion --- internal/sbi/consumer/nrf_service.go | 20 ++++++-------------- pkg/service/init.go | 26 +++++++++++++++++++------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/internal/sbi/consumer/nrf_service.go b/internal/sbi/consumer/nrf_service.go index dc65887..a1b644d 100644 --- a/internal/sbi/consumer/nrf_service.go +++ b/internal/sbi/consumer/nrf_service.go @@ -124,12 +124,12 @@ func (s *nnrfService) SendNFIntancesUDR(id string, types int) string { return "" } -func (s *nnrfService) SendDeregisterNFInstance() (problemDetails *models.ProblemDetails, err error) { +func (s *nnrfService) SendDeregisterNFInstance() (err error) { logger.ConsumerLog.Infof("Send Deregister NFInstance") - ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_NFM, models.NrfNfManagementNfType_NRF) + ctx, _, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_NFM, models.NrfNfManagementNfType_NRF) if err != nil { - return pd, err + return err } udmContext := s.consumer.Context() @@ -137,17 +137,9 @@ func (s *nnrfService) SendDeregisterNFInstance() (problemDetails *models.Problem var derigisterNfInstanceRequest Nnrf_NFManagement.DeregisterNFInstanceRequest derigisterNfInstanceRequest.NfInstanceID = &udmContext.NfId - res, err := client.NFInstanceIDDocumentApi.DeregisterNFInstance(ctx, &derigisterNfInstanceRequest) - - if err == nil { - return problemDetails, err - } else if res != nil { - problem := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) - problemDetails = &problem - } else { - err = openapi.ReportError("server no response") - } - return problemDetails, err + _, err = client.NFInstanceIDDocumentApi.DeregisterNFInstance(ctx, &derigisterNfInstanceRequest) + + return err } func (s *nnrfService) RegisterNFInstance(ctx context.Context) ( diff --git a/pkg/service/init.go b/pkg/service/init.go index a844682..add4c81 100644 --- a/pkg/service/init.go +++ b/pkg/service/init.go @@ -9,6 +9,8 @@ import ( "github.com/sirupsen/logrus" + "github.com/free5gc/openapi" + "github.com/free5gc/openapi/nrf/NFManagement" udm_context "github.com/free5gc/udm/internal/context" "github.com/free5gc/udm/internal/logger" "github.com/free5gc/udm/internal/sbi" @@ -147,14 +149,24 @@ func (a *UdmApp) terminateProcedure() { a.CallServerStop() // deregister with NRF - problemDetails, err := a.Consumer().SendDeregisterNFInstance() - if problemDetails != nil { - logger.MainLog.Errorf("Deregister NF instance Failed Problem[%+v]", problemDetails) - } else if err != nil { - logger.MainLog.Errorf("Deregister NF instance Error[%+v]", err) - } else { - logger.MainLog.Infof("Deregister from NRF successfully") + err := a.Consumer().SendDeregisterNFInstance() + if err != nil { + switch apiErr := err.(type) { + case openapi.GenericOpenAPIError: + switch errModel := apiErr.Model().(type) { + case NFManagement.DeregisterNFInstanceError: + pd := &errModel.ProblemDetails + logger.InitLog.Errorf("Deregister NF instance Failed Problem[%+v]", pd) + case error: + logger.InitLog.Errorf("Deregister NF instance Error[%+v]", err) + } + case error: + logger.InitLog.Errorf("Deregister NF instance Error[%+v]", err) + } } + + logger.InitLog.Infof("Deregister from NRF successfully") + logger.MainLog.Infof("UDM SBI Server terminated") } From 363af77a7e865614b4b76bfdf6adf835a97c03ab Mon Sep 17 00:00:00 2001 From: ubuntu Date: Fri, 9 Aug 2024 12:27:59 +0000 Subject: [PATCH 17/41] fix: gin context parameter --- internal/sbi/api_parameterprovision.go | 2 +- internal/sbi/api_subscriberdatamanagement.go | 11 ++++------- internal/sbi/api_ueauthentication.go | 1 - 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/internal/sbi/api_parameterprovision.go b/internal/sbi/api_parameterprovision.go index aef8ba0..2971bd3 100644 --- a/internal/sbi/api_parameterprovision.go +++ b/internal/sbi/api_parameterprovision.go @@ -60,7 +60,7 @@ func (s *Server) HandleUpdate(c *gin.Context) { return } - gpsi := c.Params.ByName("gpsi") + gpsi := c.Params.ByName("ueId") if gpsi == "" { problemDetails := &models.ProblemDetails{ Status: http.StatusBadRequest, diff --git a/internal/sbi/api_subscriberdatamanagement.go b/internal/sbi/api_subscriberdatamanagement.go index c286d76..c8a2acd 100644 --- a/internal/sbi/api_subscriberdatamanagement.go +++ b/internal/sbi/api_subscriberdatamanagement.go @@ -205,7 +205,7 @@ func (s *Server) HandleSubscribe(c *gin.Context) { logger.SdmLog.Infof("Handle Subscribe") - supi := c.Params.ByName("supi") + supi := c.Params.ByName("ueId") s.Processor().SubscribeProcedure(c, &sdmSubscriptionReq, supi) } @@ -214,7 +214,7 @@ func (s *Server) HandleSubscribe(c *gin.Context) { func (s *Server) HandleUnsubscribe(c *gin.Context) { logger.SdmLog.Infof("Handle Unsubscribe") - supi := c.Params.ByName("supi") + supi := c.Params.ByName("ueId") subscriptionID := c.Params.ByName("subscriptionId") s.Processor().UnsubscribeProcedure(c, supi, subscriptionID) @@ -259,7 +259,7 @@ func (s *Server) HandleModify(c *gin.Context) { logger.SdmLog.Infof("Handle Modify") - supi := c.Params.ByName("supi") + supi := c.Params.ByName("ueId") subscriptionID := c.Params.ByName("subscriptionId") s.Processor().ModifyProcedure(c, &sdmSubsModificationReq, supi, subscriptionID) @@ -377,7 +377,7 @@ func (s *Server) HandleGetIdTranslationResult(c *gin.Context) { logger.SdmLog.Infof("Handle GetIdTranslationResultRequest") - gpsi := c.Params.ByName("gpsi") + gpsi := c.Params.ByName("ueId") s.Processor().GetIdTranslationResultProcedure(c, gpsi) } @@ -419,7 +419,6 @@ func (s *Server) TwoLayerPathHandlerFunc(c *gin.Context) { // for "/:ueId/id-translation-result" if op == "id-translation-result" && strings.ToUpper("Get") == c.Request.Method { - c.Params = append(c.Params, gin.Param{Key: "ueId", Value: c.Param("supi")}) s.HandleGetIdTranslationResult(c) return } @@ -441,7 +440,6 @@ func (s *Server) ThreeLayerPathHandlerFunc(c *gin.Context) { // for "/:ueId/sdm-subscriptions/:subscriptionId" if op == "sdm-subscriptions" && strings.ToUpper("Delete") == c.Request.Method { var tmpParams gin.Params - tmpParams = append(tmpParams, gin.Param{Key: "ueId", Value: c.Param("supi")}) tmpParams = append(tmpParams, gin.Param{Key: "subscriptionId", Value: c.Param("thirdLayer")}) c.Params = tmpParams s.HandleUnsubscribe(c) @@ -457,7 +455,6 @@ func (s *Server) ThreeLayerPathHandlerFunc(c *gin.Context) { // for "/:ueId/sdm-subscriptions/:subscriptionId" if op == "sdm-subscriptions" && strings.ToUpper("Patch") == c.Request.Method { var tmpParams gin.Params - tmpParams = append(tmpParams, gin.Param{Key: "ueId", Value: c.Param("supi")}) tmpParams = append(tmpParams, gin.Param{Key: "subscriptionId", Value: c.Param("thirdLayer")}) c.Params = tmpParams s.HandleModify(c) diff --git a/internal/sbi/api_ueauthentication.go b/internal/sbi/api_ueauthentication.go index 68b61c5..d44f281 100644 --- a/internal/sbi/api_ueauthentication.go +++ b/internal/sbi/api_ueauthentication.go @@ -103,7 +103,6 @@ func (s *Server) HandleGenerateAuthData(c *gin.Context) { } func (s *Server) GenAuthDataHandlerFunc(c *gin.Context) { - c.Params = append(c.Params, gin.Param{Key: "supiOrSuci", Value: c.Param("supi")}) if strings.ToUpper("Post") == c.Request.Method { s.HandleGenerateAuthData(c) return From fc69b8a1fa1f5459ef7a8f089683c0cc1e0e7bd8 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Tue, 13 Aug 2024 09:33:43 +0000 Subject: [PATCH 18/41] feat: add notimplement route & fix gin context parameter --- internal/sbi/api_parameterprovision.go | 121 ++++++++++++ internal/sbi/api_subscriberdatamanagement.go | 177 +++++++++++++++++- internal/sbi/api_ueauthentication.go | 55 ++++++ internal/sbi/api_uecontextmanagement.go | 187 +++++++++++++++++++ 4 files changed, 539 insertions(+), 1 deletion(-) diff --git a/internal/sbi/api_parameterprovision.go b/internal/sbi/api_parameterprovision.go index 2971bd3..582897b 100644 --- a/internal/sbi/api_parameterprovision.go +++ b/internal/sbi/api_parameterprovision.go @@ -26,6 +26,83 @@ func (s *Server) getParameterProvisionRoutes() []Route { "/:ueId/pp-data", s.HandleUpdate, }, + + { + "Create5GMBSGroup", + strings.ToUpper("Put"), + "/mbs-group-membership/:extGroupId", + s.HandleCreate5GMBSGroup, + }, + + { + "Create5GVNGroup", + strings.ToUpper("Put"), + "/5g-vn-groups/:extGroupId", + s.HandleCreate5GVNGroup, + }, + + { + "CreatePPDataEntry", + strings.ToUpper("Put"), + "/:ueId/pp-data-store/:afInstanceId", + s.HandleCreatePPDataEntry, + }, + + { + "Delete5GMBSGroup", + strings.ToUpper("Delete"), + "/mbs-group-membership/:extGroupId", + s.HandleDelete5GMBSGroup, + }, + + { + "Delete5GVNGroup", + strings.ToUpper("Delete"), + "/5g-vn-groups/:extGroupId", + s.HandleDelete5GVNGroup, + }, + + { + "DeletePPDataEntry", + strings.ToUpper("Delete"), + "/:ueId/pp-data-store/:afInstanceId", + s.HandleDeletePPDataEntry, + }, + + { + "Get5GMBSGroup", + strings.ToUpper("Get"), + "/mbs-group-membership/:extGroupId", + s.HandleGet5GMBSGroup, + }, + + { + "Get5GVNGroup", + strings.ToUpper("Get"), + "/5g-vn-groups/:extGroupId", + s.HandleGet5GVNGroup, + }, + + { + "GetPPDataEntry", + strings.ToUpper("Get"), + "/:ueId/pp-data-store/:afInstanceId", + s.HandleGetPPDataEntry, + }, + + { + "Modify5GMBSGroup", + strings.ToUpper("Patch"), + "/mbs-group-membership/:extGroupId", + s.HandleModify5GMBSGroup, + }, + + { + "Modify5GVNGroup", + strings.ToUpper("Patch"), + "/5g-vn-groups/:extGroupId", + s.HandleModify5GVNGroup, + }, } } @@ -75,3 +152,47 @@ func (s *Server) HandleUpdate(c *gin.Context) { // step 3: handle the message s.Processor().UpdateProcedure(c, ppDataReq, gpsi) } + +func (s *Server) HandleCreate5GMBSGroup(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleCreate5GVNGroup(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleCreatePPDataEntry(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleDelete5GMBSGroup(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleDelete5GVNGroup(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleDeletePPDataEntry(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleGet5GMBSGroup(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleGet5GVNGroup(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleGetPPDataEntry(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleModify5GMBSGroup(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleModify5GVNGroup(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} diff --git a/internal/sbi/api_subscriberdatamanagement.go b/internal/sbi/api_subscriberdatamanagement.go index c8a2acd..df045c0 100644 --- a/internal/sbi/api_subscriberdatamanagement.go +++ b/internal/sbi/api_subscriberdatamanagement.go @@ -382,6 +382,70 @@ func (s *Server) HandleGetIdTranslationResult(c *gin.Context) { s.Processor().GetIdTranslationResultProcedure(c, gpsi) } +func (s *Server) HandleGetMultipleIdentifiers(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleGetGroupIdentifiers(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleGetLcsBcaData(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleGetLcsMoData(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleGetLcsPrivacyData(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleGetMbsData(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleGetProseData(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleGetUcData(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleGetUeCtxInAmfData(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleGetV2xData(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleGetIndividualSharedData(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleCAGAck(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleGetEcrData(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleSNSSAIsAck(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleUpdateSORInfo(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleUpuAck(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + func (s *Server) OneLayerPathHandlerFunc(c *gin.Context) { supi := c.Param("supi") oneLayerPathRouter := s.getOneLayerRoutes() @@ -419,10 +483,17 @@ func (s *Server) TwoLayerPathHandlerFunc(c *gin.Context) { // for "/:ueId/id-translation-result" if op == "id-translation-result" && strings.ToUpper("Get") == c.Request.Method { + c.Params = append(c.Params, gin.Param{Key: "ueId", Value: c.Param("supi")}) s.HandleGetIdTranslationResult(c) return } + // for "/shared-data/:sharedDataId" + if supi == "shared-data" && strings.ToUpper("Get") == c.Request.Method { + s.HandleGetIndividualSharedData(c) + return + } + twoLayerPathRouter := s.getTwoLayerRoutes() for _, route := range twoLayerPathRouter { if strings.Contains(route.Pattern, op) && route.Method == c.Request.Method { @@ -436,10 +507,12 @@ func (s *Server) TwoLayerPathHandlerFunc(c *gin.Context) { func (s *Server) ThreeLayerPathHandlerFunc(c *gin.Context) { op := c.Param("subscriptionId") + thirdLayer := c.Param("thirdLayer") // for "/:ueId/sdm-subscriptions/:subscriptionId" if op == "sdm-subscriptions" && strings.ToUpper("Delete") == c.Request.Method { var tmpParams gin.Params + tmpParams = append(tmpParams, gin.Param{Key: "ueId", Value: c.Param("supi")}) tmpParams = append(tmpParams, gin.Param{Key: "subscriptionId", Value: c.Param("thirdLayer")}) c.Params = tmpParams s.HandleUnsubscribe(c) @@ -447,14 +520,46 @@ func (s *Server) ThreeLayerPathHandlerFunc(c *gin.Context) { } // for "/:supi/am-data/sor-ack" - if op == "am-data" && strings.ToUpper("Put") == c.Request.Method { + if op == "am-data" && strings.ToUpper("Put") == c.Request.Method && thirdLayer == "sor-ack" { s.HandleInfo(c) return } + // for "/:supi/am-data/cag-ack" + if op == "am-data" && strings.ToUpper("Put") == c.Request.Method && thirdLayer == "cag-ack" { + s.HandleCAGAck(c) + return + } + + // for "/:supi/am-data/ecr-data" + if op == "am-data" && strings.ToUpper("Get") == c.Request.Method && thirdLayer == "ecr-data" { + s.HandleGetEcrData(c) + return + } + + // for "/:supi/am-data/subscribed-snssais-ack" + if op == "am-data" && strings.ToUpper("Put") == c.Request.Method && + thirdLayer == "subscribed-snssais-ack" { + s.HandleSNSSAIsAck(c) + return + } + + // for "/:supi/am-data/update-sor" + if op == "am-data" && strings.ToUpper("Post") == c.Request.Method && thirdLayer == "update-sor" { + s.HandleUpdateSORInfo(c) + return + } + + // for "/:supi/am-data/upu-ack" + if op == "am-data" && strings.ToUpper("Put") == c.Request.Method && thirdLayer == "upu-ack" { + s.HandleUpuAck(c) + return + } + // for "/:ueId/sdm-subscriptions/:subscriptionId" if op == "sdm-subscriptions" && strings.ToUpper("Patch") == c.Request.Method { var tmpParams gin.Params + tmpParams = append(tmpParams, gin.Param{Key: "ueId", Value: c.Param("supi")}) tmpParams = append(tmpParams, gin.Param{Key: "subscriptionId", Value: c.Param("thirdLayer")}) c.Params = tmpParams s.HandleModify(c) @@ -486,6 +591,13 @@ func (s *Server) getOneLayerRoutes() []Route { "/shared-data-subscriptions", s.HandleSubscribeToSharedData, }, + + { + "GetMultipleIdentifiers", + strings.ToUpper("Get"), + "/multiple-identifiers", + s.HandleGetMultipleIdentifiers, + }, } } @@ -560,5 +672,68 @@ func (s *Server) getTwoLayerRoutes() []Route { "/:supi/ue-context-in-smsf-data", s.HandleGetUeContextInSmsfData, }, + + { + "GetGroupIdentifiers", + strings.ToUpper("Get"), + "/group-data/group-identifiers", + s.HandleGetGroupIdentifiers, + }, + + { + "GetLcsBcaData", + strings.ToUpper("Get"), + "/:supi/lcs-bca-data", + s.HandleGetLcsBcaData, + }, + + { + "GetLcsMoData", + strings.ToUpper("Get"), + "/:supi/lcs-mo-data", + s.HandleGetLcsMoData, + }, + + { + "GetLcsPrivacyData", + strings.ToUpper("Get"), + "/:ueId/lcs-privacy-data", + s.HandleGetLcsPrivacyData, + }, + + { + "GetMbsData", + strings.ToUpper("Get"), + "/:supi/5mbs-data", + s.HandleGetMbsData, + }, + + { + "GetProseData", + strings.ToUpper("Get"), + "/:supi/prose-data", + s.HandleGetProseData, + }, + + { + "GetUcData", + strings.ToUpper("Get"), + "/:supi/uc-data", + s.HandleGetUcData, + }, + + { + "GetUeCtxInAmfData", + strings.ToUpper("Get"), + "/:supi/ue-context-in-amf-data", + s.HandleGetUeCtxInAmfData, + }, + + { + "GetV2xData", + strings.ToUpper("Get"), + "/:supi/v2x-data", + s.HandleGetV2xData, + }, } } diff --git a/internal/sbi/api_ueauthentication.go b/internal/sbi/api_ueauthentication.go index d44f281..f80c802 100644 --- a/internal/sbi/api_ueauthentication.go +++ b/internal/sbi/api_ueauthentication.go @@ -26,6 +26,41 @@ func (s *Server) getUEAuthenticationRoutes() []Route { "/:supi/auth-events", s.HandleConfirmAuth, }, + + { + "DeleteAuth", + strings.ToUpper("Put"), + "/:supi/auth-events/:authEventId", + s.HandleDeleteAuth, + }, + + { + "GenerateAv", + strings.ToUpper("Post"), + "/:supi/hss-security-information/:hssAuthType/generate-av", + s.HandleGenerateAv, + }, + + { + "GenerateGbaAv", + strings.ToUpper("Post"), + "/:supi/gba-security-information/generate-av", + s.HandleGenerateGbaAv, + }, + + { + "GenerateProseAV", + strings.ToUpper("Post"), + "/:supiOrSuci/prose-security-information/generate-av", + s.HandleGenerateProseAV, + }, + + { + "GetRgAuthData", + strings.ToUpper("Get"), + "/:supiOrSuci/security-information-rg", + s.HandleGetRgAuthData, + }, } } @@ -110,3 +145,23 @@ func (s *Server) GenAuthDataHandlerFunc(c *gin.Context) { c.String(http.StatusNotFound, "404 page not found") } + +func (s *Server) HandleDeleteAuth(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleGenerateAv(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleGenerateGbaAv(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleGenerateProseAV(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleGetRgAuthData(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} diff --git a/internal/sbi/api_uecontextmanagement.go b/internal/sbi/api_uecontextmanagement.go index ce9ffe8..f78ac4f 100644 --- a/internal/sbi/api_uecontextmanagement.go +++ b/internal/sbi/api_uecontextmanagement.go @@ -118,6 +118,125 @@ func (s *Server) getUEContextManagementRoutes() []Route { "/:ueId/registrations/smsf-non-3gpp-access", s.HandleRegistrationSmsfNon3gppAccess, }, + + { + "DeregAMF", + strings.ToUpper("Post"), + "/:ueId/registrations/amf-3gpp-access/dereg-amf", + s.HandleDeregAMF, + }, + + { + "GetIpSmGwRegistration", + strings.ToUpper("Get"), + "/:ueId/registrations/ip-sm-gw", + s.HandleGetIpSmGwRegistration, + }, + + { + "GetLocationInfo", + strings.ToUpper("Get"), + "/:ueId/registrations/location", + s.HandleGetLocationInfo, + }, + + { + "GetNwdafRegistration", + strings.ToUpper("Get"), + "/:ueId/registrations/nwdaf-registrations", + s.HandleGetNwdafRegistration, + }, + + { + "GetRegistrations", + strings.ToUpper("Get"), + "/:ueId/registrations", + s.HandleGetRegistrations, + }, + + { + "GetSmfRegistration", + strings.ToUpper("Get"), + "/:ueId/registrations/smf-registrations", + s.HandleGetSmfRegistration, + }, + + { + "IpSmGwDeregistration", + strings.ToUpper("Delete"), + "/:ueId/registrations/ip-sm-gw", + s.HandleIpSmGwDeregistration, + }, + + { + "IpSmGwRegistration", + strings.ToUpper("Put"), + "/:ueId/registrations/ip-sm-gw", + s.HandleIpSmGwRegistration, + }, + + { + "NwdafDeregistration", + strings.ToUpper("Delete"), + "/:ueId/registrations/nwdaf-registrations/:nwdafRegistrationId", + s.HandleNwdafDeregistration, + }, + + { + "NwdafRegistration", + strings.ToUpper("Put"), + "/:ueId/registrations/nwdaf-registrations/:nwdafRegistrationId", + s.HandleNwdafRegistration, + }, + + { + "PeiUpdate", + strings.ToUpper("Post"), + "/:ueId/registrations/amf-3gpp-access/pei-update", + s.HandlePeiUpdate, + }, + + { + "RetrieveSmfRegistration", + strings.ToUpper("Get"), + "/:ueId/registrations/smf-registrations/:pduSessionId", + s.HandleRetrieveSmfRegistration, + }, + + { + "SendRoutingInfoSm", + strings.ToUpper("Post"), + "/:ueId/registrations/send-routing-info-sm", + s.HandleSendRoutingInfoSm, + }, + + { + "TriggerPCSCFRestoration", + strings.ToUpper("Post"), + "/restore-pcscf", + s.HandleTriggerPCSCFRestoration, + }, + + { + "UpdateNwdafRegistration", + strings.ToUpper("Patch"), + "/:ueId/registrations/nwdaf-registrations/:nwdafRegistrationId", + s.HandleUpdateNwdafRegistration, + }, + + { + "UpdateRoamingInformation", + strings.ToUpper("Post"), + "/:ueId/registrations/amf-3gpp-access/roaming-info-update", + s.HandleUpdateRoamingInformation, + }, + + { + "UpdateSmfRegistration", + strings.ToUpper("Patch"), + "/:ueId/registrations/smf-registrations/:pduSessionId", + s.HandleUpdateSmfRegistration, + }, } } @@ -372,3 +491,71 @@ func (s *Server) HandleGetAmf3gppAccess(c *gin.Context) { s.Processor().GetAmf3gppAccessProcedure(c, ueID, supportedFeatures) } + +func (s *Server) HandleDeregAMF(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleGetIpSmGwRegistration(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleGetLocationInfo(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleGetNwdafRegistration(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleGetRegistrations(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleGetSmfRegistration(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleIpSmGwDeregistration(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleIpSmGwRegistration(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleNwdafDeregistration(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleNwdafRegistration(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandlePeiUpdate(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleRetrieveSmfRegistration(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleSendRoutingInfoSm(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleTriggerPCSCFRestoration(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleUpdateNwdafRegistration(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleUpdateRoamingInformation(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleUpdateSmfRegistration(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} From ef45d07f356cf3c0f90827e3e39979f893a15789 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Tue, 13 Aug 2024 09:59:57 +0000 Subject: [PATCH 19/41] feat: add r17 new service server route & r17 new service api --- internal/sbi/api_mt.go | 40 +++++++++++++++++ internal/sbi/api_niddauthentication.go | 29 ++++++++++++ internal/sbi/api_reportsmdeliverystatus.go | 29 ++++++++++++ .../sbi/api_servicespecificauthorization.go | 40 +++++++++++++++++ internal/sbi/api_ueid.go | 29 ++++++++++++ internal/sbi/server.go | 45 +++++++++++++++++++ pkg/factory/config.go | 5 +++ 7 files changed, 217 insertions(+) create mode 100644 internal/sbi/api_mt.go create mode 100644 internal/sbi/api_niddauthentication.go create mode 100644 internal/sbi/api_reportsmdeliverystatus.go create mode 100644 internal/sbi/api_servicespecificauthorization.go create mode 100644 internal/sbi/api_ueid.go diff --git a/internal/sbi/api_mt.go b/internal/sbi/api_mt.go new file mode 100644 index 0000000..da6621b --- /dev/null +++ b/internal/sbi/api_mt.go @@ -0,0 +1,40 @@ +package sbi + +import ( + "net/http" + + "github.com/gin-gonic/gin" +) + +func (s *Server) getMTRoutes() []Route { + return []Route{ + { + "Index", + "GET", + "/", + s.HandleIndex, + }, + + { + "ProvideLocationInfo", + "Post", + "/:supi/loc-info/provide-loc-info", + s.HandleProvideLocationInfo, + }, + + { + "QueryUeInfo", + "GET", + "/:supi", + s.HandleQueryUeInfo, + }, + } +} + +func (s *Server) HandleProvideLocationInfo(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleQueryUeInfo(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} diff --git a/internal/sbi/api_niddauthentication.go b/internal/sbi/api_niddauthentication.go new file mode 100644 index 0000000..f973921 --- /dev/null +++ b/internal/sbi/api_niddauthentication.go @@ -0,0 +1,29 @@ +package sbi + +import ( + "net/http" + + "github.com/gin-gonic/gin" +) + +func (s *Server) getNIDDAuthenticationRoutes() []Route { + return []Route{ + { + "Index", + "GET", + "/", + s.HandleIndex, + }, + + { + "AuthorizeNiddData", + "Post", + "/:ueIdentity/authorize", + s.HandleAuthorizeNiddData, + }, + } +} + +func (s *Server) HandleAuthorizeNiddData(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} diff --git a/internal/sbi/api_reportsmdeliverystatus.go b/internal/sbi/api_reportsmdeliverystatus.go new file mode 100644 index 0000000..fd9a582 --- /dev/null +++ b/internal/sbi/api_reportsmdeliverystatus.go @@ -0,0 +1,29 @@ +package sbi + +import ( + "net/http" + + "github.com/gin-gonic/gin" +) + +func (s *Server) getReportSMDeliveryStatusRoutes() []Route { + return []Route{ + { + "Index", + "GET", + "/", + s.HandleIndex, + }, + + { + "ReportSMDeliveryStatus", + "Post", + "/:ueIdentity/sm-delivery-status", + s.HandleReportSMDeliveryStatus, + }, + } +} + +func (s *Server) HandleReportSMDeliveryStatus(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} diff --git a/internal/sbi/api_servicespecificauthorization.go b/internal/sbi/api_servicespecificauthorization.go new file mode 100644 index 0000000..adb5094 --- /dev/null +++ b/internal/sbi/api_servicespecificauthorization.go @@ -0,0 +1,40 @@ +package sbi + +import ( + "net/http" + + "github.com/gin-gonic/gin" +) + +func (s *Server) getServiceSpecificAuthorizationRoutes() []Route { + return []Route{ + { + "Index", + "GET", + "/", + s.HandleIndex, + }, + + { + "ServiceSpecificAuthorization", + "Post", + "/:ueIdentity/:serviceType/authorize", + s.HandleServiceSpecificAuthorization, + }, + + { + "ServiceSpecificAuthorizationRemoval", + "Post", + "/:ueIdentity/:serviceType/remove", + s.HandleServiceSpecificAuthorizationRemoval, + }, + } +} + +func (s *Server) HandleServiceSpecificAuthorization(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} + +func (s *Server) HandleServiceSpecificAuthorizationRemoval(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} diff --git a/internal/sbi/api_ueid.go b/internal/sbi/api_ueid.go new file mode 100644 index 0000000..a2a1120 --- /dev/null +++ b/internal/sbi/api_ueid.go @@ -0,0 +1,29 @@ +package sbi + +import ( + "net/http" + + "github.com/gin-gonic/gin" +) + +func (s *Server) getUEIDRoutes() []Route { + return []Route{ + { + "Index", + "GET", + "/", + s.HandleIndex, + }, + + { + "Deconceal", + "Post", + "/deconceal", + s.HandleDeconceal, + }, + } +} + +func (s *Server) HandleDeconceal(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} diff --git a/internal/sbi/server.go b/internal/sbi/server.go index e4a08a3..1ebd60a 100644 --- a/internal/sbi/server.go +++ b/internal/sbi/server.go @@ -203,5 +203,50 @@ func newRouter(s *Server) *gin.Engine { }) AddService(udmPPGroup, udmPPRoutes) + // MT + udmMTRoutes := s.getMTRoutes() + udmMTGroup := s.router.Group(factory.UdmMtResUrdPrefix) + routerAuthorizationCheck = util.NewRouterAuthorizationCheck(models.ServiceName_NUDM_MT) + udmMTGroup.Use(func(c *gin.Context) { + routerAuthorizationCheck.Check(c, udm_context.GetSelf()) + }) + AddService(udmMTGroup, udmMTRoutes) + + // NIDDAU + udmNIDDAURoutes := s.getNIDDAuthenticationRoutes() + udmNIDDAUGroup := s.router.Group(factory.UdmNiddauResUriPrefix) + routerAuthorizationCheck = util.NewRouterAuthorizationCheck(models.ServiceName_NUDM_NIDDAU) + udmNIDDAUGroup.Use(func(c *gin.Context) { + routerAuthorizationCheck.Check(c, udm_context.GetSelf()) + }) + AddService(udmNIDDAUGroup, udmNIDDAURoutes) + + // RSDS + udmRSDSRoutes := s.getReportSMDeliveryStatusRoutes() + udmRSDSGroup := s.router.Group(factory.UdmRsdsResUriPrefix) + routerAuthorizationCheck = util.NewRouterAuthorizationCheck(models.ServiceName_NUDM_RSDS) + udmRSDSGroup.Use(func(c *gin.Context) { + routerAuthorizationCheck.Check(c, udm_context.GetSelf()) + }) + AddService(udmRSDSGroup, udmRSDSRoutes) + + // SSAU + udmSSAURoutes := s.getServiceSpecificAuthorizationRoutes() + udmSSAUGroup := s.router.Group(factory.UdmSsauResUriPrefix) + routerAuthorizationCheck = util.NewRouterAuthorizationCheck(models.ServiceName_NUDM_SSAU) + udmSSAUGroup.Use(func(c *gin.Context) { + routerAuthorizationCheck.Check(c, udm_context.GetSelf()) + }) + AddService(udmSSAUGroup, udmSSAURoutes) + + // UEID + udmUEIDRoutes := s.getUEIDRoutes() + udmUEIDGroup := s.router.Group(factory.UdmUeidResUriPrefix) + routerAuthorizationCheck = util.NewRouterAuthorizationCheck(models.ServiceName_NUDM_UEID) + udmUEIDGroup.Use(func(c *gin.Context) { + routerAuthorizationCheck.Check(c, udm_context.GetSelf()) + }) + AddService(udmUEIDGroup, udmUEIDRoutes) + return router } diff --git a/pkg/factory/config.go b/pkg/factory/config.go index 3aeb89a..447c904 100644 --- a/pkg/factory/config.go +++ b/pkg/factory/config.go @@ -35,6 +35,11 @@ const ( UdmUecmResUriPrefix = "/nudm-uecm/v1" UdmPpResUriPrefix = "/nudm-pp/v1" UdmUeauResUriPrefix = "/nudm-ueau/v1" + UdmMtResUrdPrefix = "/nudm-mt/v1" + UdmNiddauResUriPrefix = "/nudm-niddau/v1" + UdmRsdsResUriPrefix = "/nudm-rsds/v1" + UdmSsauResUriPrefix = "/nudm-ssau/v1" + UdmUeidResUriPrefix = "/nudm-ueid/v1" ) type Config struct { From 833df6225ccd59cfa1594550ec38e9191adf29fa Mon Sep 17 00:00:00 2001 From: ubuntu Date: Wed, 14 Aug 2024 10:52:50 +0000 Subject: [PATCH 20/41] chore: update openapi version --- go.mod | 5 ++--- go.sum | 10 ++++------ internal/context/context.go | 8 ++++---- internal/sbi/api_eventexposure.go | 2 +- internal/sbi/consumer/nf_management_test.go | 6 ++++-- internal/sbi/processor/event_exposure.go | 9 ++++----- internal/sbi/processor/generate_auth_data.go | 7 +++---- internal/sbi/processor/generate_auth_data_test.go | 8 ++++---- internal/sbi/processor/subscriber_data_management.go | 4 ++-- 9 files changed, 28 insertions(+), 31 deletions(-) diff --git a/go.mod b/go.mod index 9e45931..914dbd2 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.21 require ( github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d - github.com/free5gc/openapi v1.0.9-0.20240718074746-f272c26db1c3 + github.com/free5gc/openapi v1.0.9-0.20240814064656-cbf3ade43540 github.com/free5gc/util v1.0.6 github.com/gin-gonic/gin v1.9.1 github.com/google/uuid v1.3.0 @@ -32,7 +32,7 @@ require ( github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.14.0 // indirect github.com/goccy/go-json v0.10.2 // indirect - github.com/golang-jwt/jwt v3.2.2+incompatible // indirect + github.com/golang-jwt/jwt/v5 v5.2.1 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect github.com/json-iterator/go v1.1.12 // indirect @@ -60,6 +60,5 @@ require ( golang.org/x/text v0.14.0 // indirect google.golang.org/appengine v1.6.8 // indirect google.golang.org/protobuf v1.33.0 // indirect - gopkg.in/h2non/gock.v1 v1.1.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index d474fcd..2472623 100644 --- a/go.sum +++ b/go.sum @@ -15,8 +15,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= -github.com/free5gc/openapi v1.0.9-0.20240718074746-f272c26db1c3 h1:IY37zQ+nXFGhCNy0V0jXTMVG00j61dtC67GMg+8j2kU= -github.com/free5gc/openapi v1.0.9-0.20240718074746-f272c26db1c3/go.mod h1:oy68rqnHakRLUCuEOXcis7/PWGBuil+UaXMeTBeYY8Y= +github.com/free5gc/openapi v1.0.9-0.20240814064656-cbf3ade43540 h1:8/Wxn6tJVcOrSEyAuSsyc6ye4gkU8tLLa8PtozCkK0U= +github.com/free5gc/openapi v1.0.9-0.20240814064656-cbf3ade43540/go.mod h1:aKw6uGzEibGDrn9++w4/JpWxaaUBo7GaqsvuFKU9fl4= github.com/free5gc/util v1.0.6 h1:dBt9drcXtYKE/cY5XuQcuffgsYclPIpIArhSeS6M+DQ= github.com/free5gc/util v1.0.6/go.mod h1:eSGN7POUM8LNTvg/E591XR6447a6/w1jFWGKNZPHcXw= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= @@ -40,8 +40,8 @@ github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= -github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY= -github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= +github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk= +github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= @@ -167,8 +167,6 @@ google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGm google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/h2non/gock.v1 v1.1.2 h1:jBbHXgGBK/AoPVfJh5x4r/WxIrElvbLel8TCZkkZJoY= -gopkg.in/h2non/gock.v1 v1.1.2/go.mod h1:n7UGz/ckNChHiK05rDoiC4MYSunEC/lyaUm2WWaDva0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/internal/context/context.go b/internal/context/context.go index 99dd97e..dbf5a17 100644 --- a/internal/context/context.go +++ b/internal/context/context.go @@ -76,13 +76,13 @@ type UdmUeContext struct { TraceDataResponse models.TraceDataResponse TraceData *models.TraceData SessionManagementSubsData map[string]models.SessionManagementSubscriptionData - SubsDataSets *models.SubscriptionDataSets + SubsDataSets *models.UdmSdmSubscriptionDataSets SubscribeToNotifChange map[string]*models.SdmSubscription SubscribeToNotifSharedDataChange *models.SdmSubscription PduSessionID string UdrUri string UdmSubsToNotify map[string]*models.SubscriptionDataSubscriptions - EeSubscriptions map[string]*models.EeSubscription // subscriptionID as key + EeSubscriptions map[string]*models.UdmEeEeSubscription // subscriptionID as key amSubsDataLock sync.Mutex smfSelSubsDataLock sync.Mutex SmSubsDataLock sync.RWMutex @@ -90,7 +90,7 @@ type UdmUeContext struct { func (ue *UdmUeContext) Init() { ue.UdmSubsToNotify = make(map[string]*models.SubscriptionDataSubscriptions) - ue.EeSubscriptions = make(map[string]*models.EeSubscription) + ue.EeSubscriptions = make(map[string]*models.UdmEeEeSubscription) ue.SubscribeToNotifChange = make(map[string]*models.SdmSubscription) } @@ -221,7 +221,7 @@ func GetCorrespondingSupi(list models.IdentityData) (id string) { } // functions related to Retrieval of multiple datasets(GetSupi) -func (context *UDMContext) CreateSubsDataSetsForUe(supi string, body models.SubscriptionDataSets) { +func (context *UDMContext) CreateSubsDataSetsForUe(supi string, body models.UdmSdmSubscriptionDataSets) { ue, ok := context.UdmUeFindBySupi(supi) if !ok { ue = context.NewUdmUe(supi) diff --git a/internal/sbi/api_eventexposure.go b/internal/sbi/api_eventexposure.go index db06efb..4af2ff8 100644 --- a/internal/sbi/api_eventexposure.go +++ b/internal/sbi/api_eventexposure.go @@ -45,7 +45,7 @@ func (s *Server) getEventExposureRoutes() []Route { // HTTPCreateEeSubscription - Subscribe func (s *Server) HandleCreateEeSubscription(c *gin.Context) { - var eesubscription models.EeSubscription + var eesubscription models.UdmEeEeSubscription requestBody, err := c.GetRawData() if err != nil { diff --git a/internal/sbi/consumer/nf_management_test.go b/internal/sbi/consumer/nf_management_test.go index b185799..fd98fcc 100644 --- a/internal/sbi/consumer/nf_management_test.go +++ b/internal/sbi/consumer/nf_management_test.go @@ -16,8 +16,10 @@ import ( func TestSendRegisterNFInstance(t *testing.T) { defer gock.Off() // Flush pending mocks after test execution - gock.InterceptClient(openapi.GetHttpClient()) - defer gock.RestoreClient(openapi.GetHttpClient()) + openapi.InterceptH2CClient() + defer openapi.RestoreH2CClient() + // gock.InterceptClient(openapi.GetHttpClient()) + // defer gock.RestoreClient(openapi.GetHttpClient()) gock.New("http://127.0.0.10:8000"). Put("/nnrf-nfm/v1/nf-instances/1"). diff --git a/internal/sbi/processor/event_exposure.go b/internal/sbi/processor/event_exposure.go index ad083df..4807683 100644 --- a/internal/sbi/processor/event_exposure.go +++ b/internal/sbi/processor/event_exposure.go @@ -14,7 +14,7 @@ import ( // EE service func (p *Processor) CreateEeSubscriptionProcedure(c *gin.Context, ueIdentity string, - eesubscription models.EeSubscription, + eesubscription models.UdmEeEeSubscription, ) { udmSelf := p.Context() logger.EeLog.Debugf("udIdentity: %s", ueIdentity) @@ -34,10 +34,9 @@ func (p *Processor) CreateEeSubscriptionProcedure(c *gin.Context, ueIdentity str c.JSON(int(problemDetails.Status), problemDetails) return } - subscriptionID := strconv.Itoa(int(id)) ue.EeSubscriptions[subscriptionID] = &eesubscription - createdEeSubscription := &models.CreatedEeSubscription{ + createdEeSubscription := &models.UdmEeCreatedEeSubscription{ EeSubscription: &eesubscription, } c.JSON(http.StatusCreated, createdEeSubscription) @@ -60,7 +59,7 @@ func (p *Processor) CreateEeSubscriptionProcedure(c *gin.Context, ueIdentity str return } subscriptionID := strconv.Itoa(int(id)) - createdEeSubscription := &models.CreatedEeSubscription{ + createdEeSubscription := &models.UdmEeCreatedEeSubscription{ EeSubscription: &eesubscription, } @@ -84,7 +83,7 @@ func (p *Processor) CreateEeSubscriptionProcedure(c *gin.Context, ueIdentity str return } subscriptionID := strconv.Itoa(int(id)) - createdEeSubscription := &models.CreatedEeSubscription{ + createdEeSubscription := &models.UdmEeCreatedEeSubscription{ EeSubscription: &eesubscription, } udmSelf.UdmUePool.Range(func(key, value interface{}) bool { diff --git a/internal/sbi/processor/generate_auth_data.go b/internal/sbi/processor/generate_auth_data.go index fafad12..82729a2 100644 --- a/internal/sbi/processor/generate_auth_data.go +++ b/internal/sbi/processor/generate_auth_data.go @@ -124,7 +124,7 @@ func (p *Processor) GenerateAuthDataProcedure( } logger.UeauLog.Traceln("In GenerateAuthDataProcedure") - response := &models.AuthenticationInfoResult{} + response := &models.UdmUeauAuthenticationInfoResult{} rand.New(rand.NewSource(time.Now().UnixNano())) supi, err := suci.ToSupi(supiOrSuci, p.Context().SuciProfiles) if err != nil { @@ -449,7 +449,7 @@ func (p *Processor) GenerateAuthDataProcedure( var av models.AuthenticationVector if authSubs.AuthenticationSubscription.AuthenticationMethod == models.AuthMethod__5_G_AKA { - response.AuthType = models.AuthType__5_G_AKA + response.AuthType = models.UdmUeauAuthType__5_G_AKA // derive XRES* key := append(CK, IK...) @@ -483,8 +483,7 @@ func (p *Processor) GenerateAuthDataProcedure( av.Kausf = hex.EncodeToString(kdfValForKausf) av.AvType = models.AvType__5_G_HE_AKA } else { // EAP-AKA' - response.AuthType = models.AuthType_EAP_AKA_PRIME - + response.AuthType = models.UdmUeauAuthType_EAP_AKA_PRIME // derive CK' and IK' key := append(CK, IK...) FC := ueauth.FC_FOR_CK_PRIME_IK_PRIME_DERIVATION diff --git a/internal/sbi/processor/generate_auth_data_test.go b/internal/sbi/processor/generate_auth_data_test.go index 591e8f9..d8f8e52 100644 --- a/internal/sbi/processor/generate_auth_data_test.go +++ b/internal/sbi/processor/generate_auth_data_test.go @@ -20,8 +20,8 @@ import ( func TestGenerateAuthDataProcedure(t *testing.T) { defer gock.Off() // Flush pending mocks after test execution - gock.InterceptClient(openapi.GetHttpClient()) - defer gock.RestoreClient(openapi.GetHttpClient()) + openapi.InterceptH2CClient() + defer openapi.RestoreH2CClient() queryRes := models.AuthenticationSubscription{ AuthenticationMethod: models.AuthMethod__5_G_AKA, @@ -85,13 +85,13 @@ func TestGenerateAuthDataProcedure(t *testing.T) { t.Fatalf("Failed to read response body: %+v", errReadAll) } - var res models.AuthenticationInfoResult + var res models.UdmUeauAuthenticationInfoResult err = openapi.Deserialize(&res, rawBytes, httpResp.Header.Get("Content-Type")) if err != nil { t.Fatalf("Failed to deserialize response body: %+v", err) } - expectResponse := models.AuthenticationInfoResult{ + expectResponse := models.UdmUeauAuthenticationInfoResult{ AuthType: "5G_AKA", AuthenticationVector: &models.AuthenticationVector{ AvType: "5G_HE_AKA", diff --git a/internal/sbi/processor/subscriber_data_management.go b/internal/sbi/processor/subscriber_data_management.go index 0fb571e..ab7d990 100644 --- a/internal/sbi/processor/subscriber_data_management.go +++ b/internal/sbi/processor/subscriber_data_management.go @@ -126,7 +126,7 @@ func (p *Processor) GetSupiProcedure(c *gin.Context, return } - var subscriptionDataSets, subsDataSetBody models.SubscriptionDataSets + var subscriptionDataSets, subsDataSetBody models.UdmSdmSubscriptionDataSets var ueContextInSmfDataResp models.UeContextInSmfData pduSessionMap := make(map[string]models.PduSession) var pgwInfoArray []models.PgwInfo @@ -271,7 +271,7 @@ func (p *Processor) GetSupiProcedure(c *gin.Context, smData, _, _, _ := p.Context(). ManageSmData(sessionManagementSubscriptionDataRsp.SmSubsData.IndividualSmSubsData, "", "") udmUe.SetSMSubsData(smData) - subscriptionDataSets.SmData = sessionManagementSubscriptionDataRsp.SmSubsData.IndividualSmSubsData + subscriptionDataSets.SmData = &sessionManagementSubscriptionDataRsp.SmSubsData } if p.containDataSetName(dataSetNames, string(models.DataSetName_TRACE)) { From cb2b65a617471793aaf12293940b69e08d452ff0 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Tue, 3 Sep 2024 06:14:50 +0000 Subject: [PATCH 21/41] fix: remove unuse line --- internal/sbi/consumer/nf_management_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/internal/sbi/consumer/nf_management_test.go b/internal/sbi/consumer/nf_management_test.go index fd98fcc..05c7f86 100644 --- a/internal/sbi/consumer/nf_management_test.go +++ b/internal/sbi/consumer/nf_management_test.go @@ -18,8 +18,6 @@ func TestSendRegisterNFInstance(t *testing.T) { openapi.InterceptH2CClient() defer openapi.RestoreH2CClient() - // gock.InterceptClient(openapi.GetHttpClient()) - // defer gock.RestoreClient(openapi.GetHttpClient()) gock.New("http://127.0.0.10:8000"). Put("/nnrf-nfm/v1/nf-instances/1"). From fb824b1d1b7f06b231674ac41391e87d09f7fb65 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Tue, 10 Sep 2024 10:23:03 +0000 Subject: [PATCH 22/41] fix: PR comment change --- internal/sbi/api_eventexposure.go | 7 +- internal/sbi/api_httpcallback.go | 3 +- internal/sbi/api_mt.go | 4 +- internal/sbi/api_niddauthentication.go | 2 +- internal/sbi/api_parameterprovision.go | 25 ++++--- internal/sbi/api_reportsmdeliverystatus.go | 2 +- .../sbi/api_servicespecificauthorization.go | 4 +- internal/sbi/api_subscriberdatamanagement.go | 72 +++++++++---------- internal/sbi/api_ueauthentication.go | 15 ++-- internal/sbi/api_uecontextmanagement.go | 63 ++++++++-------- internal/sbi/api_ueid.go | 2 +- internal/sbi/consumer/nrf_service.go | 28 ++------ internal/sbi/consumer/udr_service.go | 14 ++-- 13 files changed, 109 insertions(+), 132 deletions(-) diff --git a/internal/sbi/api_eventexposure.go b/internal/sbi/api_eventexposure.go index 4af2ff8..4027c7d 100644 --- a/internal/sbi/api_eventexposure.go +++ b/internal/sbi/api_eventexposure.go @@ -2,7 +2,6 @@ package sbi import ( "net/http" - "strings" "github.com/gin-gonic/gin" @@ -22,21 +21,21 @@ func (s *Server) getEventExposureRoutes() []Route { { "CreateEeSubscription", - strings.ToUpper("Post"), + http.MethodPost, "/:ueIdentity/ee-subscriptions", s.HandleCreateEeSubscription, }, { "DeleteEeSubscription", - strings.ToUpper("Delete"), + http.MethodDelete, "/:ueIdentity/ee-subscriptions/:subscriptionId", s.HandleDeleteEeSubscription, }, { "UpdateEeSubscription", - strings.ToUpper("Patch"), + http.MethodPatch, "/:ueIdentity/ee-subscriptions/:subscriptionId", s.HandleUpdateEeSubscription, }, diff --git a/internal/sbi/api_httpcallback.go b/internal/sbi/api_httpcallback.go index 6c79ce6..85a07e9 100644 --- a/internal/sbi/api_httpcallback.go +++ b/internal/sbi/api_httpcallback.go @@ -2,7 +2,6 @@ package sbi import ( "net/http" - "strings" "github.com/gin-gonic/gin" @@ -22,7 +21,7 @@ func (s *Server) getHttpCallBackRoutes() []Route { { "DataChangeNotificationToNF", - strings.ToUpper("Post"), + http.MethodPost, "/sdm-subscriptions", s.HandleDataChangeNotificationToNF, }, diff --git a/internal/sbi/api_mt.go b/internal/sbi/api_mt.go index da6621b..844e59b 100644 --- a/internal/sbi/api_mt.go +++ b/internal/sbi/api_mt.go @@ -17,14 +17,14 @@ func (s *Server) getMTRoutes() []Route { { "ProvideLocationInfo", - "Post", + http.MethodPost, "/:supi/loc-info/provide-loc-info", s.HandleProvideLocationInfo, }, { "QueryUeInfo", - "GET", + http.MethodGet, "/:supi", s.HandleQueryUeInfo, }, diff --git a/internal/sbi/api_niddauthentication.go b/internal/sbi/api_niddauthentication.go index f973921..a0f9223 100644 --- a/internal/sbi/api_niddauthentication.go +++ b/internal/sbi/api_niddauthentication.go @@ -17,7 +17,7 @@ func (s *Server) getNIDDAuthenticationRoutes() []Route { { "AuthorizeNiddData", - "Post", + http.MethodPost, "/:ueIdentity/authorize", s.HandleAuthorizeNiddData, }, diff --git a/internal/sbi/api_parameterprovision.go b/internal/sbi/api_parameterprovision.go index 582897b..3045d35 100644 --- a/internal/sbi/api_parameterprovision.go +++ b/internal/sbi/api_parameterprovision.go @@ -2,7 +2,6 @@ package sbi import ( "net/http" - "strings" "github.com/gin-gonic/gin" @@ -22,84 +21,84 @@ func (s *Server) getParameterProvisionRoutes() []Route { { "Update", - strings.ToUpper("Patch"), + http.MethodPatch, "/:ueId/pp-data", s.HandleUpdate, }, { "Create5GMBSGroup", - strings.ToUpper("Put"), + http.MethodPut, "/mbs-group-membership/:extGroupId", s.HandleCreate5GMBSGroup, }, { "Create5GVNGroup", - strings.ToUpper("Put"), + http.MethodPut, "/5g-vn-groups/:extGroupId", s.HandleCreate5GVNGroup, }, { "CreatePPDataEntry", - strings.ToUpper("Put"), + http.MethodPut, "/:ueId/pp-data-store/:afInstanceId", s.HandleCreatePPDataEntry, }, { "Delete5GMBSGroup", - strings.ToUpper("Delete"), + http.MethodDelete, "/mbs-group-membership/:extGroupId", s.HandleDelete5GMBSGroup, }, { "Delete5GVNGroup", - strings.ToUpper("Delete"), + http.MethodDelete, "/5g-vn-groups/:extGroupId", s.HandleDelete5GVNGroup, }, { "DeletePPDataEntry", - strings.ToUpper("Delete"), + http.MethodDelete, "/:ueId/pp-data-store/:afInstanceId", s.HandleDeletePPDataEntry, }, { "Get5GMBSGroup", - strings.ToUpper("Get"), + http.MethodGet, "/mbs-group-membership/:extGroupId", s.HandleGet5GMBSGroup, }, { "Get5GVNGroup", - strings.ToUpper("Get"), + http.MethodGet, "/5g-vn-groups/:extGroupId", s.HandleGet5GVNGroup, }, { "GetPPDataEntry", - strings.ToUpper("Get"), + http.MethodGet, "/:ueId/pp-data-store/:afInstanceId", s.HandleGetPPDataEntry, }, { "Modify5GMBSGroup", - strings.ToUpper("Patch"), + http.MethodPatch, "/mbs-group-membership/:extGroupId", s.HandleModify5GMBSGroup, }, { "Modify5GVNGroup", - strings.ToUpper("Patch"), + http.MethodPatch, "/5g-vn-groups/:extGroupId", s.HandleModify5GVNGroup, }, diff --git a/internal/sbi/api_reportsmdeliverystatus.go b/internal/sbi/api_reportsmdeliverystatus.go index fd9a582..598fd9a 100644 --- a/internal/sbi/api_reportsmdeliverystatus.go +++ b/internal/sbi/api_reportsmdeliverystatus.go @@ -17,7 +17,7 @@ func (s *Server) getReportSMDeliveryStatusRoutes() []Route { { "ReportSMDeliveryStatus", - "Post", + http.MethodPost, "/:ueIdentity/sm-delivery-status", s.HandleReportSMDeliveryStatus, }, diff --git a/internal/sbi/api_servicespecificauthorization.go b/internal/sbi/api_servicespecificauthorization.go index adb5094..ddfb3e3 100644 --- a/internal/sbi/api_servicespecificauthorization.go +++ b/internal/sbi/api_servicespecificauthorization.go @@ -17,14 +17,14 @@ func (s *Server) getServiceSpecificAuthorizationRoutes() []Route { { "ServiceSpecificAuthorization", - "Post", + http.MethodPost, "/:ueIdentity/:serviceType/authorize", s.HandleServiceSpecificAuthorization, }, { "ServiceSpecificAuthorizationRemoval", - "Post", + http.MethodPost, "/:ueIdentity/:serviceType/remove", s.HandleServiceSpecificAuthorizationRemoval, }, diff --git a/internal/sbi/api_subscriberdatamanagement.go b/internal/sbi/api_subscriberdatamanagement.go index df045c0..b873888 100644 --- a/internal/sbi/api_subscriberdatamanagement.go +++ b/internal/sbi/api_subscriberdatamanagement.go @@ -457,7 +457,7 @@ func (s *Server) OneLayerPathHandlerFunc(c *gin.Context) { } // special case for :supi - if c.Request.Method == strings.ToUpper("Get") { + if c.Request.Method == http.MethodGet { s.HandleGetSupi(c) return } @@ -470,26 +470,26 @@ func (s *Server) TwoLayerPathHandlerFunc(c *gin.Context) { op := c.Param("subscriptionId") // for "/shared-data-subscriptions/:subscriptionId" - if supi == "shared-data-subscriptions" && strings.ToUpper("Delete") == c.Request.Method { + if supi == "shared-data-subscriptions" && http.MethodDelete == c.Request.Method { s.HandleUnsubscribeForSharedData(c) return } // for "/shared-data-subscriptions/:subscriptionId" - if supi == "shared-data-subscriptions" && strings.ToUpper("Patch") == c.Request.Method { + if supi == "shared-data-subscriptions" && http.MethodPatch == c.Request.Method { s.HandleModifyForSharedData(c) return } // for "/:ueId/id-translation-result" - if op == "id-translation-result" && strings.ToUpper("Get") == c.Request.Method { + if op == "id-translation-result" && http.MethodGet == c.Request.Method { c.Params = append(c.Params, gin.Param{Key: "ueId", Value: c.Param("supi")}) s.HandleGetIdTranslationResult(c) return } // for "/shared-data/:sharedDataId" - if supi == "shared-data" && strings.ToUpper("Get") == c.Request.Method { + if supi == "shared-data" && http.MethodGet == c.Request.Method { s.HandleGetIndividualSharedData(c) return } @@ -510,7 +510,7 @@ func (s *Server) ThreeLayerPathHandlerFunc(c *gin.Context) { thirdLayer := c.Param("thirdLayer") // for "/:ueId/sdm-subscriptions/:subscriptionId" - if op == "sdm-subscriptions" && strings.ToUpper("Delete") == c.Request.Method { + if op == "sdm-subscriptions" && http.MethodDelete == c.Request.Method { var tmpParams gin.Params tmpParams = append(tmpParams, gin.Param{Key: "ueId", Value: c.Param("supi")}) tmpParams = append(tmpParams, gin.Param{Key: "subscriptionId", Value: c.Param("thirdLayer")}) @@ -520,44 +520,44 @@ func (s *Server) ThreeLayerPathHandlerFunc(c *gin.Context) { } // for "/:supi/am-data/sor-ack" - if op == "am-data" && strings.ToUpper("Put") == c.Request.Method && thirdLayer == "sor-ack" { + if op == "am-data" && http.MethodPut == c.Request.Method && thirdLayer == "sor-ack" { s.HandleInfo(c) return } // for "/:supi/am-data/cag-ack" - if op == "am-data" && strings.ToUpper("Put") == c.Request.Method && thirdLayer == "cag-ack" { + if op == "am-data" && http.MethodPut == c.Request.Method && thirdLayer == "cag-ack" { s.HandleCAGAck(c) return } // for "/:supi/am-data/ecr-data" - if op == "am-data" && strings.ToUpper("Get") == c.Request.Method && thirdLayer == "ecr-data" { + if op == "am-data" && http.MethodGet == c.Request.Method && thirdLayer == "ecr-data" { s.HandleGetEcrData(c) return } // for "/:supi/am-data/subscribed-snssais-ack" - if op == "am-data" && strings.ToUpper("Put") == c.Request.Method && + if op == "am-data" && http.MethodPut == c.Request.Method && thirdLayer == "subscribed-snssais-ack" { s.HandleSNSSAIsAck(c) return } // for "/:supi/am-data/update-sor" - if op == "am-data" && strings.ToUpper("Post") == c.Request.Method && thirdLayer == "update-sor" { + if op == "am-data" && http.MethodPost == c.Request.Method && thirdLayer == "update-sor" { s.HandleUpdateSORInfo(c) return } // for "/:supi/am-data/upu-ack" - if op == "am-data" && strings.ToUpper("Put") == c.Request.Method && thirdLayer == "upu-ack" { + if op == "am-data" && http.MethodPut == c.Request.Method && thirdLayer == "upu-ack" { s.HandleUpuAck(c) return } // for "/:ueId/sdm-subscriptions/:subscriptionId" - if op == "sdm-subscriptions" && strings.ToUpper("Patch") == c.Request.Method { + if op == "sdm-subscriptions" && http.MethodPatch == c.Request.Method { var tmpParams gin.Params tmpParams = append(tmpParams, gin.Param{Key: "ueId", Value: c.Param("supi")}) tmpParams = append(tmpParams, gin.Param{Key: "subscriptionId", Value: c.Param("thirdLayer")}) @@ -573,28 +573,28 @@ func (s *Server) getOneLayerRoutes() []Route { return []Route{ { "GetDataSets", - strings.ToUpper("Get"), + http.MethodGet, "/:supi", s.HandleGetSupi, }, { "GetSharedData", - strings.ToUpper("Get"), + http.MethodGet, "/shared-data", s.HandleGetSharedData, }, { "SubscribeToSharedData", - strings.ToUpper("Post"), + http.MethodPost, "/shared-data-subscriptions", s.HandleSubscribeToSharedData, }, { "GetMultipleIdentifiers", - strings.ToUpper("Get"), + http.MethodGet, "/multiple-identifiers", s.HandleGetMultipleIdentifiers, }, @@ -605,133 +605,133 @@ func (s *Server) getTwoLayerRoutes() []Route { return []Route{ { "GetAmData", - strings.ToUpper("Get"), + http.MethodGet, "/:supi/am-data", s.HandleGetAmData, }, { "GetSmfSelData", - strings.ToUpper("Get"), + http.MethodGet, "/:supi/smf-select-data", s.HandleGetSmfSelectData, }, { "GetSmsMngtData", - strings.ToUpper("Get"), + http.MethodGet, "/:supi/sms-mng-data", s.HandleGetSmsMngData, }, { "GetSmsData", - strings.ToUpper("Get"), + http.MethodGet, "/:supi/sms-data", s.HandleGetSmsData, }, { "GetSmData", - strings.ToUpper("Get"), + http.MethodGet, "/:supi/sm-data", s.HandleGetSmData, }, { "GetNSSAI", - strings.ToUpper("Get"), + http.MethodGet, "/:supi/nssai", s.HandleGetNssai, }, { "Subscribe", - strings.ToUpper("Post"), + http.MethodPost, "/:ueId/sdm-subscriptions", s.HandleSubscribe, }, { "GetTraceConfigData", - strings.ToUpper("Get"), + http.MethodGet, "/:supi/trace-data", s.HandleGetTraceData, }, { "GetUeCtxInSmfData", - strings.ToUpper("Get"), + http.MethodGet, "/:supi/ue-context-in-smf-data", s.HandleGetUeContextInSmfData, }, { "GetUeCtxInSmsfData", - strings.ToUpper("Get"), + http.MethodGet, "/:supi/ue-context-in-smsf-data", s.HandleGetUeContextInSmsfData, }, { "GetGroupIdentifiers", - strings.ToUpper("Get"), + http.MethodGet, "/group-data/group-identifiers", s.HandleGetGroupIdentifiers, }, { "GetLcsBcaData", - strings.ToUpper("Get"), + http.MethodGet, "/:supi/lcs-bca-data", s.HandleGetLcsBcaData, }, { "GetLcsMoData", - strings.ToUpper("Get"), + http.MethodGet, "/:supi/lcs-mo-data", s.HandleGetLcsMoData, }, { "GetLcsPrivacyData", - strings.ToUpper("Get"), + http.MethodGet, "/:ueId/lcs-privacy-data", s.HandleGetLcsPrivacyData, }, { "GetMbsData", - strings.ToUpper("Get"), + http.MethodGet, "/:supi/5mbs-data", s.HandleGetMbsData, }, { "GetProseData", - strings.ToUpper("Get"), + http.MethodGet, "/:supi/prose-data", s.HandleGetProseData, }, { "GetUcData", - strings.ToUpper("Get"), + http.MethodGet, "/:supi/uc-data", s.HandleGetUcData, }, { "GetUeCtxInAmfData", - strings.ToUpper("Get"), + http.MethodGet, "/:supi/ue-context-in-amf-data", s.HandleGetUeCtxInAmfData, }, { "GetV2xData", - strings.ToUpper("Get"), + http.MethodGet, "/:supi/v2x-data", s.HandleGetV2xData, }, diff --git a/internal/sbi/api_ueauthentication.go b/internal/sbi/api_ueauthentication.go index f80c802..0c2d5e4 100644 --- a/internal/sbi/api_ueauthentication.go +++ b/internal/sbi/api_ueauthentication.go @@ -2,7 +2,6 @@ package sbi import ( "net/http" - "strings" "github.com/gin-gonic/gin" @@ -22,42 +21,42 @@ func (s *Server) getUEAuthenticationRoutes() []Route { { "ConfirmAuth", - strings.ToUpper("Post"), + http.MethodPost, "/:supi/auth-events", s.HandleConfirmAuth, }, { "DeleteAuth", - strings.ToUpper("Put"), + http.MethodPut, "/:supi/auth-events/:authEventId", s.HandleDeleteAuth, }, { "GenerateAv", - strings.ToUpper("Post"), + http.MethodPost, "/:supi/hss-security-information/:hssAuthType/generate-av", s.HandleGenerateAv, }, { "GenerateGbaAv", - strings.ToUpper("Post"), + http.MethodPost, "/:supi/gba-security-information/generate-av", s.HandleGenerateGbaAv, }, { "GenerateProseAV", - strings.ToUpper("Post"), + http.MethodPost, "/:supiOrSuci/prose-security-information/generate-av", s.HandleGenerateProseAV, }, { "GetRgAuthData", - strings.ToUpper("Get"), + http.MethodGet, "/:supiOrSuci/security-information-rg", s.HandleGetRgAuthData, }, @@ -138,7 +137,7 @@ func (s *Server) HandleGenerateAuthData(c *gin.Context) { } func (s *Server) GenAuthDataHandlerFunc(c *gin.Context) { - if strings.ToUpper("Post") == c.Request.Method { + if http.MethodPost == c.Request.Method { s.HandleGenerateAuthData(c) return } diff --git a/internal/sbi/api_uecontextmanagement.go b/internal/sbi/api_uecontextmanagement.go index f78ac4f..ad48839 100644 --- a/internal/sbi/api_uecontextmanagement.go +++ b/internal/sbi/api_uecontextmanagement.go @@ -2,7 +2,6 @@ package sbi import ( "net/http" - "strings" "github.com/gin-gonic/gin" @@ -23,217 +22,217 @@ func (s *Server) getUEContextManagementRoutes() []Route { { "Get3GppRegistration", - strings.ToUpper("Get"), + http.MethodGet, "/:ueId/registrations/amf-3gpp-access", s.HandleGetAmf3gppAccess, }, { "GetNon3GppRegistration", - strings.ToUpper("Get"), + http.MethodGet, "/:ueId/registrations/amf-non-3gpp-access", s.HandleGetAmfNon3gppAccess, }, { "Call3GppRegistration", - strings.ToUpper("Put"), + http.MethodPut, "/:ueId/registrations/amf-3gpp-access", s.HandleRegistrationAmf3gppAccess, }, { "Non3GppRegistration", - strings.ToUpper("Put"), + http.MethodPut, "/:ueId/registrations/amf-non-3gpp-access", s.HandleRegistrationAmfNon3gppAccess, }, { "Update3GppRegistration", - strings.ToUpper("Patch"), + http.MethodPatch, "/:ueId/registrations/amf-3gpp-access", s.HandleUpdateAmf3gppAccess, }, { "UpdateNon3GppRegistration", - strings.ToUpper("Patch"), + http.MethodPatch, "/:ueId/registrations/amf-non-3gpp-access", s.HandleUpdateAmfNon3gppAccess, }, { "SmfDeregistration", - strings.ToUpper("Delete"), + http.MethodDelete, "/:ueId/registrations/smf-registrations/:pduSessionId", s.HandleDeregistrationSmfRegistrations, }, { "Registration", - strings.ToUpper("Put"), + http.MethodPut, "/:ueId/registrations/smf-registrations/:pduSessionId", s.HandleRegistrationSmfRegistrations, }, { "Get3GppSmsfRegistration", - strings.ToUpper("Get"), + http.MethodGet, "/:ueId/registrations/smsf-3gpp-access", s.HandleGetSmsf3gppAccess, }, { "Call3GppSmsfDeregistration", - strings.ToUpper("Delete"), + http.MethodDelete, "/:ueId/registrations/smsf-3gpp-access", s.HandleDeregistrationSmsf3gppAccess, }, { "Non3GppSmsfDeregistration", - strings.ToUpper("Delete"), + http.MethodDelete, "/:ueId/registrations/smsf-non-3gpp-access", s.HandleDeregistrationSmsfNon3gppAccess, }, { "GetNon3GppSmsfRegistration", - strings.ToUpper("Get"), + http.MethodGet, "/:ueId/registrations/smsf-non-3gpp-access", s.HandleGetSmsfNon3gppAccess, }, { "Call3GppSmsfRegistration", - strings.ToUpper("Put"), + http.MethodPut, "/:ueId/registrations/smsf-3gpp-access", s.HandleUpdateSMSFReg3GPP, }, { "Non3GppSmsfRegistration", - strings.ToUpper("Put"), + http.MethodPut, "/:ueId/registrations/smsf-non-3gpp-access", s.HandleRegistrationSmsfNon3gppAccess, }, { "DeregAMF", - strings.ToUpper("Post"), + http.MethodPost, "/:ueId/registrations/amf-3gpp-access/dereg-amf", s.HandleDeregAMF, }, { "GetIpSmGwRegistration", - strings.ToUpper("Get"), + http.MethodGet, "/:ueId/registrations/ip-sm-gw", s.HandleGetIpSmGwRegistration, }, { "GetLocationInfo", - strings.ToUpper("Get"), + http.MethodGet, "/:ueId/registrations/location", s.HandleGetLocationInfo, }, { "GetNwdafRegistration", - strings.ToUpper("Get"), + http.MethodGet, "/:ueId/registrations/nwdaf-registrations", s.HandleGetNwdafRegistration, }, { "GetRegistrations", - strings.ToUpper("Get"), + http.MethodGet, "/:ueId/registrations", s.HandleGetRegistrations, }, { "GetSmfRegistration", - strings.ToUpper("Get"), + http.MethodGet, "/:ueId/registrations/smf-registrations", s.HandleGetSmfRegistration, }, { "IpSmGwDeregistration", - strings.ToUpper("Delete"), + http.MethodDelete, "/:ueId/registrations/ip-sm-gw", s.HandleIpSmGwDeregistration, }, { "IpSmGwRegistration", - strings.ToUpper("Put"), + http.MethodPut, "/:ueId/registrations/ip-sm-gw", s.HandleIpSmGwRegistration, }, { "NwdafDeregistration", - strings.ToUpper("Delete"), + http.MethodDelete, "/:ueId/registrations/nwdaf-registrations/:nwdafRegistrationId", s.HandleNwdafDeregistration, }, { "NwdafRegistration", - strings.ToUpper("Put"), + http.MethodPut, "/:ueId/registrations/nwdaf-registrations/:nwdafRegistrationId", s.HandleNwdafRegistration, }, { "PeiUpdate", - strings.ToUpper("Post"), + http.MethodPost, "/:ueId/registrations/amf-3gpp-access/pei-update", s.HandlePeiUpdate, }, { "RetrieveSmfRegistration", - strings.ToUpper("Get"), + http.MethodGet, "/:ueId/registrations/smf-registrations/:pduSessionId", s.HandleRetrieveSmfRegistration, }, { "SendRoutingInfoSm", - strings.ToUpper("Post"), + http.MethodPost, "/:ueId/registrations/send-routing-info-sm", s.HandleSendRoutingInfoSm, }, { "TriggerPCSCFRestoration", - strings.ToUpper("Post"), + http.MethodPost, "/restore-pcscf", s.HandleTriggerPCSCFRestoration, }, { "UpdateNwdafRegistration", - strings.ToUpper("Patch"), + http.MethodPatch, "/:ueId/registrations/nwdaf-registrations/:nwdafRegistrationId", s.HandleUpdateNwdafRegistration, }, { "UpdateRoamingInformation", - strings.ToUpper("Post"), + http.MethodPost, "/:ueId/registrations/amf-3gpp-access/roaming-info-update", s.HandleUpdateRoamingInformation, }, { "UpdateSmfRegistration", - strings.ToUpper("Patch"), + http.MethodPatch, "/:ueId/registrations/smf-registrations/:pduSessionId", s.HandleUpdateSmfRegistration, }, diff --git a/internal/sbi/api_ueid.go b/internal/sbi/api_ueid.go index a2a1120..804cb64 100644 --- a/internal/sbi/api_ueid.go +++ b/internal/sbi/api_ueid.go @@ -17,7 +17,7 @@ func (s *Server) getUEIDRoutes() []Route { { "Deconceal", - "Post", + http.MethodPost, "/deconceal", s.HandleDeconceal, }, diff --git a/internal/sbi/consumer/nrf_service.go b/internal/sbi/consumer/nrf_service.go index a1b644d..82cdc96 100644 --- a/internal/sbi/consumer/nrf_service.go +++ b/internal/sbi/consumer/nrf_service.go @@ -2,7 +2,6 @@ package consumer import ( "context" - "fmt" "strings" "sync" "time" @@ -95,7 +94,7 @@ func (s *nnrfService) SendSearchNFInstances( return &result, nil } -func (s *nnrfService) SendNFIntancesUDR(id string, types int) string { +func (s *nnrfService) SendNFInstancesUDR(id string, types int) string { self := udm_context.GetSelf() targetNfType := models.NrfNfManagementNfType_UDR requestNfType := models.NrfNfManagementNfType_UDM @@ -104,15 +103,7 @@ func (s *nnrfService) SendNFIntancesUDR(id string, types int) string { } searchNFinstanceRequest.RequesterNfType = &requestNfType searchNFinstanceRequest.TargetNfType = &targetNfType - // switch types { - // case NFDiscoveryToUDRParamSupi: - // localVarOptionals.Supi = optional.NewString(id) - // case NFDiscoveryToUDRParamExtGroupId: - // localVarOptionals.ExternalGroupIdentity = optional.NewString(id) - // case NFDiscoveryToUDRParamGpsi: - // localVarOptionals.Gpsi = optional.NewString(id) - // } - fmt.Println(self.NrfUri) + result, err := s.SendSearchNFInstances(self.NrfUri, searchNFinstanceRequest) if err != nil { logger.ConsumerLog.Error(err.Error()) @@ -158,21 +149,19 @@ func (s *nnrfService) RegisterNFInstance(ctx context.Context) ( var res *Nnrf_NFManagement.RegisterNFInstanceResponse res, err = client.NFInstanceIDDocumentApi.RegisterNFInstance(ctx, ®isterNfInstanceRequest) - var status int32 if err != nil || res == nil { problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) if !ok { - logger.ConsumerLog.Errorf("UDM register to NRF Error[%v]", err) + logger.ConsumerLog.Errorf("UDM register to NRF Error[%v]", problem) time.Sleep(2 * time.Second) continue } - status = problem.Status } if res.Location == "" { // NFUpdate break - } else if res.Location != "" { + } else { // http.statusCreated // NFRegister resourceUri := res.Location resouceNrfUri = resourceUri[:strings.Index(resourceUri, "/nnrf-nfm/")] @@ -192,9 +181,6 @@ func (s *nnrfService) RegisterNFInstance(ctx context.Context) ( } break - } else { - fmt.Println(fmt.Errorf("handler returned wrong status code %d", status)) - fmt.Println("NRF return wrong status code", status) } } return resouceNrfUri, retrieveNfInstanceID, err @@ -207,12 +193,8 @@ func (s *nnrfService) buildNfProfile(udmContext *udm_context.UDMContext) ( profile.NfType = models.NrfNfManagementNfType_UDM profile.NfStatus = models.NrfNfManagementNfStatus_REGISTERED profile.Ipv4Addresses = append(profile.Ipv4Addresses, udmContext.RegisterIPv4) - services := []models.NrfNfManagementNfService{} for _, nfService := range udmContext.NfService { - services = append(services, nfService) - } - if len(services) > 0 { - profile.NfServices = services + profile.NfServices = append(profile.NfServices, nfService) } profile.UdmInfo = &models.UdmInfo{ // Todo diff --git a/internal/sbi/consumer/udr_service.go b/internal/sbi/consumer/udr_service.go index c326880..766925a 100644 --- a/internal/sbi/consumer/udr_service.go +++ b/internal/sbi/consumer/udr_service.go @@ -54,12 +54,12 @@ func (s *nudrService) getUdrURI(id string) string { ue, ok := udm_context.GetSelf().UdmUeFindBySupi(id) if ok { if ue.UdrUri == "" { - ue.UdrUri = s.consumer.SendNFIntancesUDR(id, NFDiscoveryToUDRParamSupi) + ue.UdrUri = s.consumer.SendNFInstancesUDR(id, NFDiscoveryToUDRParamSupi) } return ue.UdrUri } else { ue = udm_context.GetSelf().NewUdmUe(id) - ue.UdrUri = s.consumer.SendNFIntancesUDR(id, NFDiscoveryToUDRParamSupi) + ue.UdrUri = s.consumer.SendNFInstancesUDR(id, NFDiscoveryToUDRParamSupi) return ue.UdrUri } } else if strings.Contains(id, "pei") { @@ -68,13 +68,13 @@ func (s *nudrService) getUdrURI(id string) string { ue := value.(*udm_context.UdmUeContext) if ue.Amf3GppAccessRegistration != nil && ue.Amf3GppAccessRegistration.Pei == id { if ue.UdrUri == "" { - ue.UdrUri = s.consumer.SendNFIntancesUDR(ue.Supi, NFDiscoveryToUDRParamSupi) + ue.UdrUri = s.consumer.SendNFInstancesUDR(ue.Supi, NFDiscoveryToUDRParamSupi) } udrURI = ue.UdrUri return false } else if ue.AmfNon3GppAccessRegistration != nil && ue.AmfNon3GppAccessRegistration.Pei == id { if ue.UdrUri == "" { - ue.UdrUri = s.consumer.SendNFIntancesUDR(ue.Supi, NFDiscoveryToUDRParamSupi) + ue.UdrUri = s.consumer.SendNFInstancesUDR(ue.Supi, NFDiscoveryToUDRParamSupi) } udrURI = ue.UdrUri return false @@ -84,10 +84,10 @@ func (s *nudrService) getUdrURI(id string) string { return udrURI } else if strings.Contains(id, "extgroupid") { // extra group id - return s.consumer.SendNFIntancesUDR(id, NFDiscoveryToUDRParamExtGroupId) + return s.consumer.SendNFInstancesUDR(id, NFDiscoveryToUDRParamExtGroupId) } else if strings.Contains(id, "msisdn") || strings.Contains(id, "extid") { // gpsi - return s.consumer.SendNFIntancesUDR(id, NFDiscoveryToUDRParamGpsi) + return s.consumer.SendNFInstancesUDR(id, NFDiscoveryToUDRParamGpsi) } - return s.consumer.SendNFIntancesUDR("", NFDiscoveryToUDRParamNone) + return s.consumer.SendNFInstancesUDR("", NFDiscoveryToUDRParamNone) } From d5c5546c6ce96ab307a0b86cda057322a7e5491f Mon Sep 17 00:00:00 2001 From: ubuntu Date: Tue, 10 Sep 2024 11:14:31 +0000 Subject: [PATCH 23/41] fix: PR comment --- internal/util/search_nf_service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/util/search_nf_service.go b/internal/util/search_nf_service.go index 298a397..2dbe25b 100644 --- a/internal/util/search_nf_service.go +++ b/internal/util/search_nf_service.go @@ -33,7 +33,7 @@ func SearchNFServiceUri(nfProfile models.NrfNfDiscoveryNfProfile, serviceName mo } } - return + return nfUri } func getSbiUri(scheme models.UriScheme, ipv4Address string, port int32) (uri string) { From cc855f7811ad00df5f6fc271ef1ff0e049da6724 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Wed, 11 Sep 2024 05:51:05 +0000 Subject: [PATCH 24/41] fix: PR comment --- internal/sbi/consumer/nrf_service.go | 2 +- internal/sbi/server.go | 19 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/internal/sbi/consumer/nrf_service.go b/internal/sbi/consumer/nrf_service.go index 82cdc96..2debf2a 100644 --- a/internal/sbi/consumer/nrf_service.go +++ b/internal/sbi/consumer/nrf_service.go @@ -118,7 +118,7 @@ func (s *nnrfService) SendNFInstancesUDR(id string, types int) string { func (s *nnrfService) SendDeregisterNFInstance() (err error) { logger.ConsumerLog.Infof("Send Deregister NFInstance") - ctx, _, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_NFM, models.NrfNfManagementNfType_NRF) + ctx, _, err := s.consumer.Context().GetTokenCtx(models.ServiceName_NNRF_NFM, models.NrfNfManagementNfType_NRF) if err != nil { return err } diff --git a/internal/sbi/server.go b/internal/sbi/server.go index 1ebd60a..0757e2a 100644 --- a/internal/sbi/server.go +++ b/internal/sbi/server.go @@ -13,7 +13,6 @@ import ( "github.com/sirupsen/logrus" "github.com/free5gc/openapi/models" - udm_context "github.com/free5gc/udm/internal/context" "github.com/free5gc/udm/internal/logger" "github.com/free5gc/udm/internal/sbi/consumer" "github.com/free5gc/udm/internal/sbi/processor" @@ -160,7 +159,7 @@ func newRouter(s *Server) *gin.Engine { udmUEAUGroup := s.router.Group(factory.UdmUeauResUriPrefix) routerAuthorizationCheck = util.NewRouterAuthorizationCheck(models.ServiceName_NUDM_UEAU) udmUEAUGroup.Use(func(c *gin.Context) { - routerAuthorizationCheck.Check(c, udm_context.GetSelf()) + routerAuthorizationCheck.Check(c, s.Context()) }) AddService(udmUEAUGroup, udmUEAURoutes) @@ -172,7 +171,7 @@ func newRouter(s *Server) *gin.Engine { udmUECMGroup := s.router.Group(factory.UdmUecmResUriPrefix) routerAuthorizationCheck = util.NewRouterAuthorizationCheck(models.ServiceName_NUDM_UECM) udmUECMGroup.Use(func(c *gin.Context) { - routerAuthorizationCheck.Check(c, udm_context.GetSelf()) + routerAuthorizationCheck.Check(c, s.Context()) }) AddService(udmUECMGroup, udmUECMRoutes) @@ -181,7 +180,7 @@ func newRouter(s *Server) *gin.Engine { udmSDMGroup := s.router.Group(factory.UdmSdmResUriPrefix) routerAuthorizationCheck = util.NewRouterAuthorizationCheck(models.ServiceName_NUDM_SDM) udmSDMGroup.Use(func(c *gin.Context) { - routerAuthorizationCheck.Check(c, udm_context.GetSelf()) + routerAuthorizationCheck.Check(c, s.Context()) }) AddService(udmSDMGroup, udmSDMRoutes) @@ -199,7 +198,7 @@ func newRouter(s *Server) *gin.Engine { udmPPGroup := s.router.Group(factory.UdmPpResUriPrefix) routerAuthorizationCheck = util.NewRouterAuthorizationCheck(models.ServiceName_NUDM_PP) udmPPGroup.Use(func(c *gin.Context) { - routerAuthorizationCheck.Check(c, udm_context.GetSelf()) + routerAuthorizationCheck.Check(c, s.Context()) }) AddService(udmPPGroup, udmPPRoutes) @@ -208,7 +207,7 @@ func newRouter(s *Server) *gin.Engine { udmMTGroup := s.router.Group(factory.UdmMtResUrdPrefix) routerAuthorizationCheck = util.NewRouterAuthorizationCheck(models.ServiceName_NUDM_MT) udmMTGroup.Use(func(c *gin.Context) { - routerAuthorizationCheck.Check(c, udm_context.GetSelf()) + routerAuthorizationCheck.Check(c, s.Context()) }) AddService(udmMTGroup, udmMTRoutes) @@ -217,7 +216,7 @@ func newRouter(s *Server) *gin.Engine { udmNIDDAUGroup := s.router.Group(factory.UdmNiddauResUriPrefix) routerAuthorizationCheck = util.NewRouterAuthorizationCheck(models.ServiceName_NUDM_NIDDAU) udmNIDDAUGroup.Use(func(c *gin.Context) { - routerAuthorizationCheck.Check(c, udm_context.GetSelf()) + routerAuthorizationCheck.Check(c, s.Context()) }) AddService(udmNIDDAUGroup, udmNIDDAURoutes) @@ -226,7 +225,7 @@ func newRouter(s *Server) *gin.Engine { udmRSDSGroup := s.router.Group(factory.UdmRsdsResUriPrefix) routerAuthorizationCheck = util.NewRouterAuthorizationCheck(models.ServiceName_NUDM_RSDS) udmRSDSGroup.Use(func(c *gin.Context) { - routerAuthorizationCheck.Check(c, udm_context.GetSelf()) + routerAuthorizationCheck.Check(c, s.Context()) }) AddService(udmRSDSGroup, udmRSDSRoutes) @@ -235,7 +234,7 @@ func newRouter(s *Server) *gin.Engine { udmSSAUGroup := s.router.Group(factory.UdmSsauResUriPrefix) routerAuthorizationCheck = util.NewRouterAuthorizationCheck(models.ServiceName_NUDM_SSAU) udmSSAUGroup.Use(func(c *gin.Context) { - routerAuthorizationCheck.Check(c, udm_context.GetSelf()) + routerAuthorizationCheck.Check(c, s.Context()) }) AddService(udmSSAUGroup, udmSSAURoutes) @@ -244,7 +243,7 @@ func newRouter(s *Server) *gin.Engine { udmUEIDGroup := s.router.Group(factory.UdmUeidResUriPrefix) routerAuthorizationCheck = util.NewRouterAuthorizationCheck(models.ServiceName_NUDM_UEID) udmUEIDGroup.Use(func(c *gin.Context) { - routerAuthorizationCheck.Check(c, udm_context.GetSelf()) + routerAuthorizationCheck.Check(c, s.Context()) }) AddService(udmUEIDGroup, udmUEIDRoutes) From 037ec8f37f3688f0436d729a7167d2b82c579856 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Wed, 11 Sep 2024 08:44:02 +0000 Subject: [PATCH 25/41] fix: PR comment --- internal/sbi/api_eventexposure.go | 2 +- internal/sbi/api_httpcallback.go | 2 +- internal/sbi/api_mt.go | 2 +- internal/sbi/api_niddauthentication.go | 2 +- internal/sbi/api_parameterprovision.go | 2 +- internal/sbi/api_reportsmdeliverystatus.go | 2 +- internal/sbi/api_servicespecificauthorization.go | 2 +- internal/sbi/api_subscriberdatamanagement.go | 2 +- internal/sbi/api_ueauthentication.go | 2 +- internal/sbi/api_uecontextmanagement.go | 2 +- internal/sbi/api_ueid.go | 2 +- internal/sbi/consumer/nrf_service.go | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/internal/sbi/api_eventexposure.go b/internal/sbi/api_eventexposure.go index 4027c7d..b6902ea 100644 --- a/internal/sbi/api_eventexposure.go +++ b/internal/sbi/api_eventexposure.go @@ -14,7 +14,7 @@ func (s *Server) getEventExposureRoutes() []Route { return []Route{ { "Index", - "GET", + http.MethodGet, "/", s.HandleIndex, }, diff --git a/internal/sbi/api_httpcallback.go b/internal/sbi/api_httpcallback.go index 85a07e9..cf1a2e9 100644 --- a/internal/sbi/api_httpcallback.go +++ b/internal/sbi/api_httpcallback.go @@ -14,7 +14,7 @@ func (s *Server) getHttpCallBackRoutes() []Route { return []Route{ { "Index", - "GET", + http.MethodGET, "/", s.HandleIndex, }, diff --git a/internal/sbi/api_mt.go b/internal/sbi/api_mt.go index 844e59b..6c196bd 100644 --- a/internal/sbi/api_mt.go +++ b/internal/sbi/api_mt.go @@ -10,7 +10,7 @@ func (s *Server) getMTRoutes() []Route { return []Route{ { "Index", - "GET", + http.MethodGet, "/", s.HandleIndex, }, diff --git a/internal/sbi/api_niddauthentication.go b/internal/sbi/api_niddauthentication.go index a0f9223..897938c 100644 --- a/internal/sbi/api_niddauthentication.go +++ b/internal/sbi/api_niddauthentication.go @@ -10,7 +10,7 @@ func (s *Server) getNIDDAuthenticationRoutes() []Route { return []Route{ { "Index", - "GET", + http.MethodGet, "/", s.HandleIndex, }, diff --git a/internal/sbi/api_parameterprovision.go b/internal/sbi/api_parameterprovision.go index 3045d35..b69adaf 100644 --- a/internal/sbi/api_parameterprovision.go +++ b/internal/sbi/api_parameterprovision.go @@ -14,7 +14,7 @@ func (s *Server) getParameterProvisionRoutes() []Route { return []Route{ { "Index", - "GET", + http.MethodGet, "/", s.HandleIndex, }, diff --git a/internal/sbi/api_reportsmdeliverystatus.go b/internal/sbi/api_reportsmdeliverystatus.go index 598fd9a..07d5481 100644 --- a/internal/sbi/api_reportsmdeliverystatus.go +++ b/internal/sbi/api_reportsmdeliverystatus.go @@ -10,7 +10,7 @@ func (s *Server) getReportSMDeliveryStatusRoutes() []Route { return []Route{ { "Index", - "GET", + http.MethodGet, "/", s.HandleIndex, }, diff --git a/internal/sbi/api_servicespecificauthorization.go b/internal/sbi/api_servicespecificauthorization.go index ddfb3e3..3dd8c33 100644 --- a/internal/sbi/api_servicespecificauthorization.go +++ b/internal/sbi/api_servicespecificauthorization.go @@ -10,7 +10,7 @@ func (s *Server) getServiceSpecificAuthorizationRoutes() []Route { return []Route{ { "Index", - "GET", + http.MethodGet, "/", s.HandleIndex, }, diff --git a/internal/sbi/api_subscriberdatamanagement.go b/internal/sbi/api_subscriberdatamanagement.go index b873888..0067916 100644 --- a/internal/sbi/api_subscriberdatamanagement.go +++ b/internal/sbi/api_subscriberdatamanagement.go @@ -17,7 +17,7 @@ func (s *Server) getSubscriberDataManagementRoutes() []Route { return []Route{ { "Index", - "GET", + http.MethodGet, "/", s.HandleIndex, }, diff --git a/internal/sbi/api_ueauthentication.go b/internal/sbi/api_ueauthentication.go index 0c2d5e4..edff540 100644 --- a/internal/sbi/api_ueauthentication.go +++ b/internal/sbi/api_ueauthentication.go @@ -14,7 +14,7 @@ func (s *Server) getUEAuthenticationRoutes() []Route { return []Route{ { "Index", - "GET", + http.MethodGet, "/", s.HandleIndex, }, diff --git a/internal/sbi/api_uecontextmanagement.go b/internal/sbi/api_uecontextmanagement.go index ad48839..10b7e9b 100644 --- a/internal/sbi/api_uecontextmanagement.go +++ b/internal/sbi/api_uecontextmanagement.go @@ -15,7 +15,7 @@ func (s *Server) getUEContextManagementRoutes() []Route { return []Route{ { "Index", - "GET", + http.MethodGet, "/", s.HandleIndex, }, diff --git a/internal/sbi/api_ueid.go b/internal/sbi/api_ueid.go index 804cb64..5225f5b 100644 --- a/internal/sbi/api_ueid.go +++ b/internal/sbi/api_ueid.go @@ -10,7 +10,7 @@ func (s *Server) getUEIDRoutes() []Route { return []Route{ { "Index", - "GET", + http.MethodGet, "/", s.HandleIndex, }, diff --git a/internal/sbi/consumer/nrf_service.go b/internal/sbi/consumer/nrf_service.go index 2debf2a..40aa820 100644 --- a/internal/sbi/consumer/nrf_service.go +++ b/internal/sbi/consumer/nrf_service.go @@ -80,7 +80,7 @@ func (s *nnrfService) SendSearchNFInstances( client := s.getNFDiscClient(udmContext.NrfUri) - ctx, _, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_DISC, models.NrfNfManagementNfType_NRF) + ctx, _, err := s.consumer.Context().GetTokenCtx(models.ServiceName_NNRF_DISC, models.NrfNfManagementNfType_NRF) if err != nil { return nil, err } From 1e2b8fe50be88fd0aff84e36e5e730be7bd95fb4 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Wed, 11 Sep 2024 09:12:56 +0000 Subject: [PATCH 26/41] fix: PR comment --- internal/sbi/api_httpcallback.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/sbi/api_httpcallback.go b/internal/sbi/api_httpcallback.go index cf1a2e9..be7e58a 100644 --- a/internal/sbi/api_httpcallback.go +++ b/internal/sbi/api_httpcallback.go @@ -14,7 +14,7 @@ func (s *Server) getHttpCallBackRoutes() []Route { return []Route{ { "Index", - http.MethodGET, + http.MethodGet, "/", s.HandleIndex, }, From f82f577ed5d41323d96815cc1f97d73d0b5121b5 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Thu, 17 Oct 2024 08:01:15 +0000 Subject: [PATCH 27/41] feat: modify ueau route with different layer --- internal/sbi/api_ueauthentication.go | 108 ++++++++++++++------------- internal/sbi/consumer/nrf_service.go | 10 +-- internal/sbi/server.go | 10 ++- 3 files changed, 68 insertions(+), 60 deletions(-) diff --git a/internal/sbi/api_ueauthentication.go b/internal/sbi/api_ueauthentication.go index edff540..efe3447 100644 --- a/internal/sbi/api_ueauthentication.go +++ b/internal/sbi/api_ueauthentication.go @@ -18,48 +18,6 @@ func (s *Server) getUEAuthenticationRoutes() []Route { "/", s.HandleIndex, }, - - { - "ConfirmAuth", - http.MethodPost, - "/:supi/auth-events", - s.HandleConfirmAuth, - }, - - { - "DeleteAuth", - http.MethodPut, - "/:supi/auth-events/:authEventId", - s.HandleDeleteAuth, - }, - - { - "GenerateAv", - http.MethodPost, - "/:supi/hss-security-information/:hssAuthType/generate-av", - s.HandleGenerateAv, - }, - - { - "GenerateGbaAv", - http.MethodPost, - "/:supi/gba-security-information/generate-av", - s.HandleGenerateGbaAv, - }, - - { - "GenerateProseAV", - http.MethodPost, - "/:supiOrSuci/prose-security-information/generate-av", - s.HandleGenerateProseAV, - }, - - { - "GetRgAuthData", - http.MethodGet, - "/:supiOrSuci/security-information-rg", - s.HandleGetRgAuthData, - }, } } @@ -136,15 +94,6 @@ func (s *Server) HandleGenerateAuthData(c *gin.Context) { s.Processor().GenerateAuthDataProcedure(c, authInfoReq, supiOrSuci) } -func (s *Server) GenAuthDataHandlerFunc(c *gin.Context) { - if http.MethodPost == c.Request.Method { - s.HandleGenerateAuthData(c) - return - } - - c.String(http.StatusNotFound, "404 page not found") -} - func (s *Server) HandleDeleteAuth(c *gin.Context) { c.JSON(http.StatusNotImplemented, gin.H{}) } @@ -164,3 +113,60 @@ func (s *Server) HandleGenerateProseAV(c *gin.Context) { func (s *Server) HandleGetRgAuthData(c *gin.Context) { c.JSON(http.StatusNotImplemented, gin.H{}) } + +func (s *Server) UEAUTwoLayerPathHandlerFunc(c *gin.Context) { + twoLayer := c.Param("twoLayer") + + // for "/:supi/auth-events" + if twoLayer == "auth-events" && http.MethodPost == c.Request.Method { + s.HandleConfirmAuth(c) + return + } + + // for "/:supiOrSuci/security-information-rg" + if twoLayer == "security-information-rg" && http.MethodGet == c.Request.Method { + var tmpParams gin.Params + tmpParams = append(tmpParams, gin.Param{Key: "supiOrSuci", Value: c.Param("supi")}) + c.Params = tmpParams + s.HandleGetRgAuthData(c) + return + } + + c.String(http.StatusNotFound, "404 page not found") +} + +func (s *Server) UEAUThreeLayerPathHandlerFunc(c *gin.Context) { + twoLayer := c.Param("subscriptionId") + + // for "/:supi/auth-events/:authEventId" + if twoLayer == "auth-events" && http.MethodPut == c.Request.Method { + s.HandleDeleteAuth(c) + return + } + + // for "/:supi/gba-security-information/generate-av" + if twoLayer == "gba-security-information" && http.MethodPost == c.Request.Method { + s.HandleGenerateGbaAv(c) + return + } + + // for "/:supiOrSuci/prose-security-information/generate-av" + if twoLayer == "prose-security-information" && http.MethodPost == c.Request.Method { + var tmpParams gin.Params + tmpParams = append(tmpParams, gin.Param{Key: "supiOrSuci", Value: c.Param("supi")}) + c.Params = tmpParams + s.HandleGenerateProseAV(c) + return + } + + // for "/:supiOrSuci/security-information/generate-auth-data" + if twoLayer == "security-information" && http.MethodPost == c.Request.Method { + var tmpParams gin.Params + tmpParams = append(tmpParams, gin.Param{Key: "supiOrSuci", Value: c.Param("supi")}) + c.Params = tmpParams + s.HandleGenerateAuthData(c) + return + } + + c.String(http.StatusNotFound, "404 page not found") +} diff --git a/internal/sbi/consumer/nrf_service.go b/internal/sbi/consumer/nrf_service.go index 40aa820..8648a0b 100644 --- a/internal/sbi/consumer/nrf_service.go +++ b/internal/sbi/consumer/nrf_service.go @@ -8,7 +8,6 @@ import ( "github.com/pkg/errors" - "github.com/free5gc/openapi" "github.com/free5gc/openapi/models" Nnrf_NFDiscovery "github.com/free5gc/openapi/nrf/NFDiscovery" Nnrf_NFManagement "github.com/free5gc/openapi/nrf/NFManagement" @@ -150,12 +149,9 @@ func (s *nnrfService) RegisterNFInstance(ctx context.Context) ( res, err = client.NFInstanceIDDocumentApi.RegisterNFInstance(ctx, ®isterNfInstanceRequest) if err != nil || res == nil { - problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) - if !ok { - logger.ConsumerLog.Errorf("UDM register to NRF Error[%v]", problem) - time.Sleep(2 * time.Second) - continue - } + logger.ConsumerLog.Errorf("UDM register to NRF Error[%v]", err.Error()) + time.Sleep(2 * time.Second) + continue } if res.Location == "" { diff --git a/internal/sbi/server.go b/internal/sbi/server.go index 0757e2a..4f7a3eb 100644 --- a/internal/sbi/server.go +++ b/internal/sbi/server.go @@ -163,8 +163,14 @@ func newRouter(s *Server) *gin.Engine { }) AddService(udmUEAUGroup, udmUEAURoutes) - genAuthDataPath := "/:supiOrSuci/security-information/generate-auth-data" - udmUEAUGroup.Any(genAuthDataPath, s.GenAuthDataHandlerFunc) + ueauTwoLayerPath := "/:supi/:twoLayer" + udmUEAUGroup.Any(ueauTwoLayerPath, s.UEAUTwoLayerPathHandlerFunc) + + ueauThreeLayerPath := "/:supi/:twoLayer/:thirdLayer" + udmUEAUGroup.Any(ueauThreeLayerPath, s.UEAUThreeLayerPathHandlerFunc) + + generateAvPath := "/:supi/hss-security-information/:hssAuthType/generate-av" + udmUEAUGroup.Any(generateAvPath, s.HandleGenerateAv) // UECM udmUECMRoutes := s.getUEContextManagementRoutes() From 560775abf45124fbee344d141108a23d59535d54 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Thu, 17 Oct 2024 09:32:33 +0000 Subject: [PATCH 28/41] fix: ctrl^C not terminate --- internal/sbi/consumer/nrf_service.go | 9 ++++++++- internal/sbi/server.go | 3 ++- pkg/service/init.go | 8 ++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/internal/sbi/consumer/nrf_service.go b/internal/sbi/consumer/nrf_service.go index 8648a0b..fe0ba23 100644 --- a/internal/sbi/consumer/nrf_service.go +++ b/internal/sbi/consumer/nrf_service.go @@ -144,8 +144,15 @@ func (s *nnrfService) RegisterNFInstance(ctx context.Context) ( var registerNfInstanceRequest Nnrf_NFManagement.RegisterNFInstanceRequest registerNfInstanceRequest.NfInstanceID = &udmContext.NfId registerNfInstanceRequest.NrfNfManagementNfProfile = &nfProfile + var res *Nnrf_NFManagement.RegisterNFInstanceResponse for { - var res *Nnrf_NFManagement.RegisterNFInstanceResponse + + select { + case <-ctx.Done(): + return "", "", errors.Errorf("Context Cancel before RegisterNFInstance") + default: + } + res, err = client.NFInstanceIDDocumentApi.RegisterNFInstance(ctx, ®isterNfInstanceRequest) if err != nil || res == nil { diff --git a/internal/sbi/server.go b/internal/sbi/server.go index 4f7a3eb..fc17957 100644 --- a/internal/sbi/server.go +++ b/internal/sbi/server.go @@ -28,6 +28,7 @@ type ServerUdm interface { Consumer() *consumer.Consumer Processor() *processor.Processor + CancelContext() context.Context } type Server struct { @@ -60,7 +61,7 @@ func (s *Server) Run(traceCtx context.Context, wg *sync.WaitGroup) error { logger.SBILog.Info("Starting server...") var err error - _, s.Context().NfId, err = s.Consumer().RegisterNFInstance(context.Background()) + _, s.Context().NfId, err = s.Consumer().RegisterNFInstance(s.CancelContext()) if err != nil { logger.InitLog.Errorf("UDM register to NRF Error[%s]", err.Error()) } diff --git a/pkg/service/init.go b/pkg/service/init.go index add4c81..59e96a5 100644 --- a/pkg/service/init.go +++ b/pkg/service/init.go @@ -175,6 +175,10 @@ func (a *UdmApp) WaitRoutineStopped() { logger.MainLog.Infof("UDM App is terminated") } +func (a *UdmApp) CancelContext() context.Context { + return a.ctx +} + func (a *UdmApp) Config() *factory.Config { return a.cfg } @@ -183,10 +187,6 @@ func (a *UdmApp) Context() *udm_context.UDMContext { return a.udmCtx } -func (a *UdmApp) CancelContext() context.Context { - return a.ctx -} - func (a *UdmApp) Consumer() *consumer.Consumer { return a.consumer } From 6db4653bd4b83d2d3833c63b6b6d923cf87da300 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Thu, 17 Oct 2024 09:36:30 +0000 Subject: [PATCH 29/41] fix: lint error --- internal/sbi/consumer/nrf_service.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/sbi/consumer/nrf_service.go b/internal/sbi/consumer/nrf_service.go index fe0ba23..e8d2cfc 100644 --- a/internal/sbi/consumer/nrf_service.go +++ b/internal/sbi/consumer/nrf_service.go @@ -146,7 +146,6 @@ func (s *nnrfService) RegisterNFInstance(ctx context.Context) ( registerNfInstanceRequest.NrfNfManagementNfProfile = &nfProfile var res *Nnrf_NFManagement.RegisterNFInstanceResponse for { - select { case <-ctx.Done(): return "", "", errors.Errorf("Context Cancel before RegisterNFInstance") From 29ebf2d26371159490ce549976c86dfa197e5594 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Sun, 20 Oct 2024 10:09:04 +0000 Subject: [PATCH 30/41] fix: type error & update api version --- internal/sbi/api_ueauthentication.go | 2 +- pkg/factory/config.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/sbi/api_ueauthentication.go b/internal/sbi/api_ueauthentication.go index efe3447..74141c1 100644 --- a/internal/sbi/api_ueauthentication.go +++ b/internal/sbi/api_ueauthentication.go @@ -136,7 +136,7 @@ func (s *Server) UEAUTwoLayerPathHandlerFunc(c *gin.Context) { } func (s *Server) UEAUThreeLayerPathHandlerFunc(c *gin.Context) { - twoLayer := c.Param("subscriptionId") + twoLayer := c.Param("twoLayer") // for "/:supi/auth-events/:authEventId" if twoLayer == "auth-events" && http.MethodPut == c.Request.Method { diff --git a/pkg/factory/config.go b/pkg/factory/config.go index 447c904..a09eb3b 100644 --- a/pkg/factory/config.go +++ b/pkg/factory/config.go @@ -29,7 +29,7 @@ const ( UdmAuthResUriPrefix = "/nudm-auth/v1" UdmfUpuprotectionResUriPrefix = "/nudm-upuprotection/v1" UdmEcmResUriPrefix = "/nudm-ecm/v1" - UdmSdmResUriPrefix = "/nudm-sdm/v1" + UdmSdmResUriPrefix = "/nudm-sdm/v2" UdmEeResUriPrefix = "/nudm-ee/v1" UdmDrResUriPrefix = "/nudr-dr/v1" UdmUecmResUriPrefix = "/nudm-uecm/v1" From 7633aa9883ee0142b464561604d64472759e9000 Mon Sep 17 00:00:00 2001 From: "CTFang@WireLab" Date: Sun, 20 Oct 2024 12:21:25 +0000 Subject: [PATCH 31/41] fix: two layer params name --- internal/sbi/api_subscriberdatamanagement.go | 5 +++-- internal/sbi/processor/subscriber_data_management.go | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/sbi/api_subscriberdatamanagement.go b/internal/sbi/api_subscriberdatamanagement.go index 0067916..8564186 100644 --- a/internal/sbi/api_subscriberdatamanagement.go +++ b/internal/sbi/api_subscriberdatamanagement.go @@ -205,8 +205,7 @@ func (s *Server) HandleSubscribe(c *gin.Context) { logger.SdmLog.Infof("Handle Subscribe") - supi := c.Params.ByName("ueId") - + supi := c.Params.ByName("supi") s.Processor().SubscribeProcedure(c, &sdmSubscriptionReq, supi) } @@ -469,6 +468,8 @@ func (s *Server) TwoLayerPathHandlerFunc(c *gin.Context) { supi := c.Param("supi") op := c.Param("subscriptionId") + logger.ConsumerLog.Errorln("TwoLayerPathHandlerFunc, ", supi, op) + // for "/shared-data-subscriptions/:subscriptionId" if supi == "shared-data-subscriptions" && http.MethodDelete == c.Request.Method { s.HandleUnsubscribeForSharedData(c) diff --git a/internal/sbi/processor/subscriber_data_management.go b/internal/sbi/processor/subscriber_data_management.go index ab7d990..a3cd0fc 100644 --- a/internal/sbi/processor/subscriber_data_management.go +++ b/internal/sbi/processor/subscriber_data_management.go @@ -554,6 +554,7 @@ func (p *Processor) SubscribeProcedure(c *gin.Context, sdmSubscription *models.S } var createSdmSubscriptionsRequest Nudr_DataRepository.CreateSdmSubscriptionsRequest createSdmSubscriptionsRequest.SdmSubscription = sdmSubscription + createSdmSubscriptionsRequest.UeId = &supi sdmSubscriptionResp, err := clientAPI.SDMSubscriptionsCollectionApi.CreateSdmSubscriptions( ctx, &createSdmSubscriptionsRequest) if err != nil { From 01a17fc9f6b354966dcbc0c8b4d7df793f1aaf01 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Sun, 20 Oct 2024 13:21:11 +0000 Subject: [PATCH 32/41] fix: log level --- internal/sbi/api_subscriberdatamanagement.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/sbi/api_subscriberdatamanagement.go b/internal/sbi/api_subscriberdatamanagement.go index 8564186..081eb25 100644 --- a/internal/sbi/api_subscriberdatamanagement.go +++ b/internal/sbi/api_subscriberdatamanagement.go @@ -468,7 +468,7 @@ func (s *Server) TwoLayerPathHandlerFunc(c *gin.Context) { supi := c.Param("supi") op := c.Param("subscriptionId") - logger.ConsumerLog.Errorln("TwoLayerPathHandlerFunc, ", supi, op) + logger.ConsumerLog.Infoln("TwoLayerPathHandlerFunc, ", supi, op) // for "/shared-data-subscriptions/:subscriptionId" if supi == "shared-data-subscriptions" && http.MethodDelete == c.Request.Method { From 59a3ec42c922e3391ea5d6a1720f3a108cfc34c1 Mon Sep 17 00:00:00 2001 From: "CTFang@WireLab" Date: Fri, 25 Oct 2024 04:16:58 +0000 Subject: [PATCH 33/41] fix: add logs and minor adjustment --- go.mod | 2 +- go.sum | 4 ++-- .../sbi/processor/subscriber_data_management.go | 16 +++++++++++----- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 914dbd2..17ffb6b 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.21 require ( github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d - github.com/free5gc/openapi v1.0.9-0.20240814064656-cbf3ade43540 + github.com/free5gc/openapi v1.0.9-0.20241024114001-1414ef920de2 github.com/free5gc/util v1.0.6 github.com/gin-gonic/gin v1.9.1 github.com/google/uuid v1.3.0 diff --git a/go.sum b/go.sum index 2472623..f0636e3 100644 --- a/go.sum +++ b/go.sum @@ -15,8 +15,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= -github.com/free5gc/openapi v1.0.9-0.20240814064656-cbf3ade43540 h1:8/Wxn6tJVcOrSEyAuSsyc6ye4gkU8tLLa8PtozCkK0U= -github.com/free5gc/openapi v1.0.9-0.20240814064656-cbf3ade43540/go.mod h1:aKw6uGzEibGDrn9++w4/JpWxaaUBo7GaqsvuFKU9fl4= +github.com/free5gc/openapi v1.0.9-0.20241024114001-1414ef920de2 h1:rMZE/FZtEbOiAZISVs9M093g4I2SGdpcxDYp2htt6Ws= +github.com/free5gc/openapi v1.0.9-0.20241024114001-1414ef920de2/go.mod h1:aKw6uGzEibGDrn9++w4/JpWxaaUBo7GaqsvuFKU9fl4= github.com/free5gc/util v1.0.6 h1:dBt9drcXtYKE/cY5XuQcuffgsYclPIpIArhSeS6M+DQ= github.com/free5gc/util v1.0.6/go.mod h1:eSGN7POUM8LNTvg/E591XR6447a6/w1jFWGKNZPHcXw= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= diff --git a/internal/sbi/processor/subscriber_data_management.go b/internal/sbi/processor/subscriber_data_management.go index a3cd0fc..d17b641 100644 --- a/internal/sbi/processor/subscriber_data_management.go +++ b/internal/sbi/processor/subscriber_data_management.go @@ -1,6 +1,7 @@ package processor import ( + "encoding/json" "net/http" "strconv" @@ -355,30 +356,35 @@ func (p *Processor) GetSmDataProcedure( ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NrfNfManagementNfType_UDR) if err != nil { c.JSON(int(pd.Status), pd) + return } logger.SdmLog.Infof("getSmDataProcedure: SUPI[%s] PLMNID[%s] DNN[%s] SNssai[%s]", supi, plmnID, Dnn, Snssai) clientAPI, err := p.Consumer().CreateUDMClientToUDR(supi) if err != nil { + logger.ProcLog.Errorf("CreateUDMClientToUDR Error: %+v", err) problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } - var querySmDataRequest Nudr_DataRepository.QuerySmDataRequest - modelSnassai, err := openapi.SnssaiHexToModels(Snssai) - if err != nil { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + var modelSnassai models.Snssai + if errUnmarshal := json.Unmarshal([]byte(Snssai), &modelSnassai); errUnmarshal != nil { + logger.ProcLog.Errorf("modelSnassai Unmarshal Error: %+v", errUnmarshal) + problemDetails := openapi.ProblemDetailsSystemFailure(errUnmarshal.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } - querySmDataRequest.SingleNssai = modelSnassai + + var querySmDataRequest Nudr_DataRepository.QuerySmDataRequest + querySmDataRequest.SingleNssai = &modelSnassai querySmDataRequest.UeId = &supi querySmDataRequest.ServingPlmnId = &plmnID sessionManagementSubscriptionDataResp, err := clientAPI.SessionManagementSubscriptionDataApi. QuerySmData(ctx, &querySmDataRequest) if err != nil { + logger.ProcLog.Errorf("QuerySmData Error: %+v", err) problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) if !ok { problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) From a6036f2d3c38f5686349dfc3ff7d76bebf007ee7 Mon Sep 17 00:00:00 2001 From: "CTFang@WireLab" Date: Fri, 25 Oct 2024 07:08:00 +0000 Subject: [PATCH 34/41] fix: GetAmDataProcedure response type --- internal/sbi/processor/subscriber_data_management.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/sbi/processor/subscriber_data_management.go b/internal/sbi/processor/subscriber_data_management.go index d17b641..147dd9a 100644 --- a/internal/sbi/processor/subscriber_data_management.go +++ b/internal/sbi/processor/subscriber_data_management.go @@ -51,8 +51,10 @@ func (p *Processor) GetAmDataProcedure(c *gin.Context, supi string, plmnID strin udmUe = p.Context().NewUdmUe(supi) } udmUe.SetAMSubsriptionData(&accessAndMobilitySubscriptionDataResp.AccessAndMobilitySubscriptionData) - c.JSON(http.StatusOK, accessAndMobilitySubscriptionDataResp) + c.JSON(http.StatusOK, accessAndMobilitySubscriptionDataResp.AccessAndMobilitySubscriptionData) + return } + c.String(http.StatusInternalServerError, "accessAndMobilitySubscriptionDataResp is nil") } func (p *Processor) GetIdTranslationResultProcedure(c *gin.Context, gpsi string) { From c5027da1d9e0af3575bba9540336ee769e2d1376 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Wed, 23 Oct 2024 14:14:44 +0000 Subject: [PATCH 35/41] fix: procedure rsp type --- internal/sbi/processor/generate_auth_data.go | 4 ++-- internal/sbi/processor/parameter_provision.go | 2 +- internal/sbi/processor/ue_context_management.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/sbi/processor/generate_auth_data.go b/internal/sbi/processor/generate_auth_data.go index 82729a2..07eb22b 100644 --- a/internal/sbi/processor/generate_auth_data.go +++ b/internal/sbi/processor/generate_auth_data.go @@ -95,7 +95,7 @@ func (p *Processor) ConfirmAuthDataProcedure(c *gin.Context, return } - createAuthStatusResponse, err := client.AuthenticationStatusDocumentApi.CreateAuthenticationStatus( + _, err = client.AuthenticationStatusDocumentApi.CreateAuthenticationStatus( ctx, &createAuthStatusRequest) if err != nil { problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) @@ -109,7 +109,7 @@ func (p *Processor) ConfirmAuthDataProcedure(c *gin.Context, return } - c.JSON(http.StatusCreated, createAuthStatusResponse) + c.Status(http.StatusCreated) } func (p *Processor) GenerateAuthDataProcedure( diff --git a/internal/sbi/processor/parameter_provision.go b/internal/sbi/processor/parameter_provision.go index f64c12c..840f6c1 100644 --- a/internal/sbi/processor/parameter_provision.go +++ b/internal/sbi/processor/parameter_provision.go @@ -40,7 +40,7 @@ func (p *Processor) UpdateProcedure(c *gin.Context, } if modifyPpDataRsp.PatchResult.Report != nil { - c.JSON(http.StatusOK, modifyPpDataRsp) + c.JSON(http.StatusOK, modifyPpDataRsp.PatchResult) return } diff --git a/internal/sbi/processor/ue_context_management.go b/internal/sbi/processor/ue_context_management.go index e661dda..6c44589 100644 --- a/internal/sbi/processor/ue_context_management.go +++ b/internal/sbi/processor/ue_context_management.go @@ -44,7 +44,7 @@ func (p *Processor) GetAmf3gppAccessProcedure(c *gin.Context, ueID string, suppo return } - c.JSON(http.StatusOK, amf3GppAccessRegistration) + c.JSON(http.StatusOK, amf3GppAccessRegistration.Amf3GppAccessRegistration) } func (p *Processor) GetAmfNon3gppAccessProcedure(c *gin.Context, queryAmfContextNon3gppParamOpts Nudr_DataRepository. @@ -73,7 +73,7 @@ func (p *Processor) GetAmfNon3gppAccessProcedure(c *gin.Context, queryAmfContext return } - c.JSON(http.StatusOK, amfNon3GppAccessRegistrationResponse) + c.JSON(http.StatusOK, amfNon3GppAccessRegistrationResponse.AmfNon3GppAccessRegistration) } func (p *Processor) RegistrationAmf3gppAccessProcedure(c *gin.Context, From cd7c6e5c66bc44b164c3114adae805e62d82db87 Mon Sep 17 00:00:00 2001 From: "CTFang@WireLab" Date: Fri, 25 Oct 2024 16:09:29 +0000 Subject: [PATCH 36/41] fix: AuthEvents response type --- internal/sbi/processor/generate_auth_data.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/sbi/processor/generate_auth_data.go b/internal/sbi/processor/generate_auth_data.go index 07eb22b..a24ede7 100644 --- a/internal/sbi/processor/generate_auth_data.go +++ b/internal/sbi/processor/generate_auth_data.go @@ -109,7 +109,8 @@ func (p *Processor) ConfirmAuthDataProcedure(c *gin.Context, return } - c.Status(http.StatusCreated) + // AuthEvent in response body is optional + c.JSON(http.StatusCreated, gin.H{}) } func (p *Processor) GenerateAuthDataProcedure( From 2248934b254fa2a64a38091165aae10ac5af11e2 Mon Sep 17 00:00:00 2001 From: "CTFang@WireLab" Date: Sun, 27 Oct 2024 14:12:28 +0000 Subject: [PATCH 37/41] fix: authentication subscription patchItem sequence number --- internal/sbi/processor/generate_auth_data.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/sbi/processor/generate_auth_data.go b/internal/sbi/processor/generate_auth_data.go index a24ede7..5005817 100644 --- a/internal/sbi/processor/generate_auth_data.go +++ b/internal/sbi/processor/generate_auth_data.go @@ -153,6 +153,7 @@ func (p *Processor) GenerateAuthDataProcedure( authSubs, err := client.AuthenticationDataDocumentApi.QueryAuthSubsData(ctx, &queryAuthSubsDataRequest) if err != nil { + logger.ProcLog.Errorf("Error on QueryAuthSubsData: %+v", err) problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) if !ok { problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) @@ -394,12 +395,16 @@ func (p *Processor) GenerateAuthDataProcedure( SQNheStr = p.strictHex(SQNheStr, 12) patchItemArray := []models.PatchItem{ { - Op: models.PatchOperation_REPLACE, - Path: "/sequenceNumber", - Value: SQNheStr, + Op: models.PatchOperation_REPLACE, + Path: "/sequenceNumber", + Value: models.SequenceNumber{ + Sqn: SQNheStr, + }, }, } + logger.ProcLog.Infoln("ModifyAuthenticationSubscriptionRequest: ", patchItemArray) + var modifyAuthenticationSubscriptionRequest Nudr_DataRepository.ModifyAuthenticationSubscriptionRequest modifyAuthenticationSubscriptionRequest.UeId = &supi modifyAuthenticationSubscriptionRequest.PatchItem = patchItemArray From 1f9b3935e23ce841c826aa7d992d30e846a65e81 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Mon, 28 Oct 2024 08:34:13 +0000 Subject: [PATCH 38/41] fix: type assertion generic error --- internal/sbi/processor/generate_auth_data.go | 10 +- internal/sbi/processor/notifier.go | 23 +-- internal/sbi/processor/parameter_provision.go | 14 +- .../processor/subscriber_data_management.go | 146 ++++++++++-------- .../sbi/processor/ue_context_management.go | 52 ++++--- 5 files changed, 134 insertions(+), 111 deletions(-) diff --git a/internal/sbi/processor/generate_auth_data.go b/internal/sbi/processor/generate_auth_data.go index 5005817..f61677b 100644 --- a/internal/sbi/processor/generate_auth_data.go +++ b/internal/sbi/processor/generate_auth_data.go @@ -98,14 +98,14 @@ func (p *Processor) ConfirmAuthDataProcedure(c *gin.Context, _, err = client.AuthenticationStatusDocumentApi.CreateAuthenticationStatus( ctx, &createAuthStatusRequest) if err != nil { - problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + apiError, ok := err.(openapi.GenericOpenAPIError) if !ok { problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } logger.UeauLog.Errorln("ConfirmAuth err:", err.Error()) - c.JSON(int(problem.Status), problem) + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } @@ -154,19 +154,19 @@ func (p *Processor) GenerateAuthDataProcedure( authSubs, err := client.AuthenticationDataDocumentApi.QueryAuthSubsData(ctx, &queryAuthSubsDataRequest) if err != nil { logger.ProcLog.Errorf("Error on QueryAuthSubsData: %+v", err) - problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + apiError, ok := err.(openapi.GenericOpenAPIError) if !ok { problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } - switch problem.Status { + switch apiError.ErrorStatus { case http.StatusNotFound: logger.UeauLog.Warnf("Return from UDR QueryAuthSubsData error") default: logger.UeauLog.Errorln("Return from UDR QueryAuthSubsData error") } - c.JSON(int(problem.Status), problem) + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } diff --git a/internal/sbi/processor/notifier.go b/internal/sbi/processor/notifier.go index a481bc4..a940967 100644 --- a/internal/sbi/processor/notifier.go +++ b/internal/sbi/processor/notifier.go @@ -34,13 +34,15 @@ func (p *Processor) DataChangeNotificationProcedure(c *gin.Context, _, err = clientAPI.SubscriptionCreationApi.SubscribeDatachangeNotificationPost( ctx, onDataChangeNotificationurl, &subDataChangeNotificationPostRequest) if err != nil { - problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) - if !ok { + if apiErr, ok := err.(openapi.GenericOpenAPIError); ok { + // API error + if subDataChangeNoti_err, ok2 := apiErr. + Model().(SubscriberDataManagement.SubscribeDatachangeNotificationPostError); ok2 { + problemDetails = &subDataChangeNoti_err.ProblemDetails + } + } else { logger.HttpLog.Error(err.Error()) problemDetails = openapi.ProblemDetailsSystemFailure(err.Error()) - } else { - logger.HttpLog.Errorln(err.Error()) - problemDetails = &problem } } } @@ -65,12 +67,13 @@ func (p *Processor) SendOnDeregistrationNotification(ueId string, onDeregistrati onDeregistrationNotificationUrl, &call3GppRegistrationDeregistrationNotificationPostRequest) if err != nil { - problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - return problemDetails + if apiErr, ok := err.(openapi.GenericOpenAPIError); ok { + // API error + if deregisterNoti_err, ok2 := apiErr. + Model().(UEContextManagement.Call3GppRegistrationDeregistrationNotificationPostError); ok2 { + return &deregisterNoti_err.ProblemDetails + } } - return &problem } return nil diff --git a/internal/sbi/processor/parameter_provision.go b/internal/sbi/processor/parameter_provision.go index 840f6c1..29e78e0 100644 --- a/internal/sbi/processor/parameter_provision.go +++ b/internal/sbi/processor/parameter_provision.go @@ -29,13 +29,15 @@ func (p *Processor) UpdateProcedure(c *gin.Context, modifyPpDataRequest.UeId = &gpsi modifyPpDataRsp, err := clientAPI.ProvisionedParameterDataDocumentApi.ModifyPpData(ctx, &modifyPpDataRequest) if err != nil { - problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) - return + if apiErr, ok := err.(openapi.GenericOpenAPIError); ok { + if modification_err, ok2 := apiErr.Model().(Nudr_DataRepository.ModifyPpDataError); ok2 { + problem := modification_err.ProblemDetails + c.JSON(int(problem.Status), problem) + return + } } - c.JSON(int(problem.Status), problem) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } diff --git a/internal/sbi/processor/subscriber_data_management.go b/internal/sbi/processor/subscriber_data_management.go index 147dd9a..776e5d8 100644 --- a/internal/sbi/processor/subscriber_data_management.go +++ b/internal/sbi/processor/subscriber_data_management.go @@ -35,13 +35,13 @@ func (p *Processor) GetAmDataProcedure(c *gin.Context, supi string, plmnID strin accessAndMobilitySubscriptionDataResp, err := clientAPI.AccessAndMobilitySubscriptionDataDocumentApi. QueryAmData(ctx, &queryAmDataRequest) if err != nil { - problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + apiError, ok := err.(openapi.GenericOpenAPIError) if !ok { problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } - c.JSON(int(problem.Status), problem) + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } @@ -77,13 +77,15 @@ func (p *Processor) GetIdTranslationResultProcedure(c *gin.Context, gpsi string) idTranslationResultResp, err := clientAPI.QueryIdentityDataBySUPIOrGPSIDocumentApi.GetIdentityData( ctx, &getIdentityDataRequest) if err != nil { - problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) - return + if apiErr, ok := err.(openapi.GenericOpenAPIError); ok { + if getIdTransError, ok2 := apiErr.Model().(Nudr_DataRepository.GetIdentityDataError); ok2 { + problem := getIdTransError.ProblemDetails + c.JSON(int(problem.Status), problem) + return + } } - c.JSON(int(problem.Status), problem) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -155,13 +157,13 @@ func (p *Processor) GetSupiProcedure(c *gin.Context, amDataRsp, err := clientAPI.AccessAndMobilitySubscriptionDataDocumentApi.QueryAmData( ctx, &queryAmDataRequest) if err != nil { - problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + apiError, ok := err.(openapi.GenericOpenAPIError) if !ok { problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } - c.JSON(int(problem.Status), problem) + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } @@ -180,13 +182,13 @@ func (p *Processor) GetSupiProcedure(c *gin.Context, smfSelDataRsp, err := clientAPI.SMFSelectionSubscriptionDataDocumentApi.QuerySmfSelectData(ctx, &querySmfSelectDataRequest) if err != nil { - problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + apiError, ok := err.(openapi.GenericOpenAPIError) if !ok { problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } - c.JSON(int(problem.Status), problem) + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } @@ -207,13 +209,13 @@ func (p *Processor) GetSupiProcedure(c *gin.Context, pdusess, err := clientAPI.SMFRegistrationsCollectionApi.QuerySmfRegList( ctx, &querySmfRegListRequest) if err != nil { - problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + apiError, ok := err.(openapi.GenericOpenAPIError) if !ok { problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } - c.JSON(int(problem.Status), problem) + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } @@ -257,13 +259,13 @@ func (p *Processor) GetSupiProcedure(c *gin.Context, sessionManagementSubscriptionDataRsp, err := clientAPI.SessionManagementSubscriptionDataApi. QuerySmData(ctx, &querySmDataRequest) if err != nil { - problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + apiError, ok := err.(openapi.GenericOpenAPIError) if !ok { problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } - c.JSON(int(problem.Status), problem) + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } @@ -286,13 +288,13 @@ func (p *Processor) GetSupiProcedure(c *gin.Context, traceDataRsp, err := clientAPI.TraceDataDocumentApi.QueryTraceData( ctx, &queryTraceDataRequest) if err != nil { - problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + apiError, ok := err.(openapi.GenericOpenAPIError) if !ok { problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } - c.JSON(int(problem.Status), problem) + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } @@ -332,13 +334,15 @@ func (p *Processor) GetSharedDataProcedure(c *gin.Context, sharedDataIds []strin sharedDataResp, err := clientAPI.RetrievalOfSharedDataApi.GetSharedData(ctx, &getSharedDataRequest) if err != nil { - problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) - return + if apiErr, ok := err.(openapi.GenericOpenAPIError); ok { + if getShareDataError, ok2 := apiErr.Model().(Nudr_DataRepository.GetSharedDataError); ok2 { + problem := getShareDataError.ProblemDetails + c.JSON(int(problem.Status), problem) + return + } } - c.JSON(int(problem.Status), problem) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -387,13 +391,13 @@ func (p *Processor) GetSmDataProcedure( QuerySmData(ctx, &querySmDataRequest) if err != nil { logger.ProcLog.Errorf("QuerySmData Error: %+v", err) - problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + apiError, ok := err.(openapi.GenericOpenAPIError) if !ok { problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } - c.JSON(int(problem.Status), problem) + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } @@ -453,13 +457,13 @@ func (p *Processor) GetNssaiProcedure(c *gin.Context, supi string, plmnID string accessAndMobilitySubscriptionDataResp, err := clientAPI.AccessAndMobilitySubscriptionDataDocumentApi. QueryAmData(ctx, &queryAmDataRequest) if err != nil { - problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + apiError, ok := err.(openapi.GenericOpenAPIError) if !ok { problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } - c.JSON(int(problem.Status), problem) + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } @@ -498,13 +502,13 @@ func (p *Processor) GetSmfSelectDataProcedure(c *gin.Context, supi string, plmnI smfSelectionSubscriptionDataResp, err := clientAPI.SMFSelectionSubscriptionDataDocumentApi. QuerySmfSelectData(ctx, &querySmfSelectDataRequest) if err != nil { - problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + apiError, ok := err.(openapi.GenericOpenAPIError) if !ok { problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } - c.JSON(int(problem.Status), problem) + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } @@ -529,13 +533,15 @@ func (p *Processor) SubscribeToSharedDataProcedure(c *gin.Context, sdmSubscripti sdmSubscriptionResp, err := udmClientAPI.SubscriptionCreationForSharedDataApi.SubscribeToSharedData( ctx, &subscibeToShareDataRequest) if err != nil { - problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) - return + if apiErr, ok := err.(openapi.GenericOpenAPIError); ok { + if subToShareDataErr, ok2 := apiErr.Model().(SubscriberDataManagement.SubscribeToSharedDataError); ok2 { + problem := subToShareDataErr.ProblemDetails + c.JSON(int(problem.Status), problem) + return + } } - c.JSON(int(problem.Status), problem) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -566,13 +572,13 @@ func (p *Processor) SubscribeProcedure(c *gin.Context, sdmSubscription *models.S sdmSubscriptionResp, err := clientAPI.SDMSubscriptionsCollectionApi.CreateSdmSubscriptions( ctx, &createSdmSubscriptionsRequest) if err != nil { - problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + apiError, ok := err.(openapi.GenericOpenAPIError) if !ok { problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } - c.JSON(int(problem.Status), problem) + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } @@ -599,13 +605,15 @@ func (p *Processor) UnsubscribeForSharedDataProcedure(c *gin.Context, subscripti _, err = udmClientAPI.SubscriptionDeletionForSharedDataApi.UnsubscribeForSharedData( ctx, &unsubscribeForSharedDataRequest) if err != nil { - problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) - return + if apiErr, ok := err.(openapi.GenericOpenAPIError); ok { + if subToShareDataErr, ok2 := apiErr.Model().(SubscriberDataManagement.UnsubscribeForSharedDataError); ok2 { + problem := subToShareDataErr.ProblemDetails + c.JSON(int(problem.Status), problem) + return + } } - c.JSON(int(problem.Status), problem) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -629,13 +637,15 @@ func (p *Processor) UnsubscribeProcedure(c *gin.Context, supi string, subscripti removesdmSubscriptionRequest.SubsId = &subscriptionID _, err = clientAPI.SDMSubscriptionDocumentApi.RemovesdmSubscriptions(ctx, &removesdmSubscriptionRequest) if err != nil { - problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) - return + if apiErr, ok := err.(openapi.GenericOpenAPIError); ok { + if removeSubErr, ok2 := apiErr.Model().(Nudr_DataRepository.RemovesdmSubscriptionsError); ok2 { + problem := removeSubErr.ProblemDetails + c.JSON(int(problem.Status), problem) + return + } } - c.JSON(int(problem.Status), problem) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -668,13 +678,15 @@ func (p *Processor) ModifyProcedure(c *gin.Context, _, err = clientAPI.SDMSubscriptionDocumentApi.Updatesdmsubscriptions( ctx, &updatesdmsubscriptionsRequest) if err != nil { - problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) - return + if apiErr, ok := err.(openapi.GenericOpenAPIError); ok { + if updateSubErr, ok2 := apiErr.Model().(Nudr_DataRepository.UpdatesdmsubscriptionsError); ok2 { + problem := updateSubErr.ProblemDetails + c.JSON(int(problem.Status), problem) + return + } } - c.JSON(int(problem.Status), problem) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -710,13 +722,15 @@ func (p *Processor) ModifyForSharedDataProcedure(c *gin.Context, _, err = clientAPI.SDMSubscriptionDocumentApi.Updatesdmsubscriptions( ctx, &updatesdmsubscriptionsRequest) if err != nil { - problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) - return + if apiErr, ok := err.(openapi.GenericOpenAPIError); ok { + if updateShareSubErr, ok2 := apiErr.Model().(Nudr_DataRepository.UpdatesdmsubscriptionsError); ok2 { + problem := updateShareSubErr.ProblemDetails + c.JSON(int(problem.Status), problem) + return + } } - c.JSON(int(problem.Status), problem) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -746,13 +760,13 @@ func (p *Processor) GetTraceDataProcedure(c *gin.Context, supi string, plmnID st traceDataRes, err := clientAPI.TraceDataDocumentApi.QueryTraceData( ctx, &queryTraceDataRequest) if err != nil { - problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + apiError, ok := err.(openapi.GenericOpenAPIError) if !ok { problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } - c.JSON(int(problem.Status), problem) + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } @@ -793,13 +807,13 @@ func (p *Processor) GetUeContextInSmfDataProcedure(c *gin.Context, supi string, pdusessRes, err := clientAPI.SMFRegistrationsCollectionApi.QuerySmfRegList( ctx, &querySmfRegListRequest) if err != nil { - problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + apiError, ok := err.(openapi.GenericOpenAPIError) if !ok { problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } - c.JSON(int(problem.Status), problem) + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } diff --git a/internal/sbi/processor/ue_context_management.go b/internal/sbi/processor/ue_context_management.go index 6c44589..0669afd 100644 --- a/internal/sbi/processor/ue_context_management.go +++ b/internal/sbi/processor/ue_context_management.go @@ -34,13 +34,13 @@ func (p *Processor) GetAmf3gppAccessProcedure(c *gin.Context, ueID string, suppo amf3GppAccessRegistration, err := clientAPI.AMF3GPPAccessRegistrationDocumentApi. QueryAmfContext3gpp(ctx, &queryAmfContext3gppRequest) if err != nil { - problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + apiError, ok := err.(openapi.GenericOpenAPIError) if !ok { problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } - c.JSON(int(problem.Status), problem) + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } @@ -63,13 +63,13 @@ func (p *Processor) GetAmfNon3gppAccessProcedure(c *gin.Context, queryAmfContext amfNon3GppAccessRegistrationResponse, err := clientAPI.AMFNon3GPPAccessRegistrationDocumentApi. QueryAmfContextNon3gpp(ctx, &queryAmfContextNon3gppParamOpts) if err != nil { - problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + apiError, ok := err.(openapi.GenericOpenAPIError) if !ok { problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } - c.JSON(int(problem.Status), problem) + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } @@ -109,13 +109,13 @@ func (p *Processor) RegistrationAmf3gppAccessProcedure(c *gin.Context, _, err = clientAPI.AMF3GPPAccessRegistrationDocumentApi.CreateAmfContext3gpp(ctx, &createAmfContext3gppRequest) if err != nil { - problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + apiError, ok := err.(openapi.GenericOpenAPIError) if !ok { problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } - c.JSON(int(problem.Status), problem) + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } @@ -185,13 +185,13 @@ func (p *Processor) RegisterAmfNon3gppAccessProcedure(c *gin.Context, _, err = clientAPI.AMFNon3GPPAccessRegistrationDocumentApi.CreateAmfContextNon3gpp( ctx, &createAmfContextNon3gppRequest) if err != nil { - problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + apiError, ok := err.(openapi.GenericOpenAPIError) if !ok { problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } - c.JSON(int(problem.Status), problem) + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } @@ -301,13 +301,15 @@ func (p *Processor) UpdateAmf3gppAccessProcedure(c *gin.Context, _, err = clientAPI.AMF3GPPAccessRegistrationDocumentApi.AmfContext3gpp(ctx, &amfContext3gppRequest) if err != nil { - problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) - return + if apiErr, ok := err.(openapi.GenericOpenAPIError); ok { + if amfContext3gppErr, ok2 := apiErr.Model().(Nudr_DataRepository.AmfContext3gppError); ok2 { + problem := amfContext3gppErr.ProblemDetails + c.JSON(int(problem.Status), problem) + return + } } - c.JSON(int(problem.Status), problem) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -406,13 +408,15 @@ func (p *Processor) UpdateAmfNon3gppAccessProcedure(c *gin.Context, _, err = clientAPI.AMFNon3GPPAccessRegistrationDocumentApi.AmfContextNon3gpp(ctx, &amfContextNon3gppRequest) if err != nil { - problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) - return + if apiErr, ok := err.(openapi.GenericOpenAPIError); ok { + if amfContextNon3gppErr, ok2 := apiErr.Model().(Nudr_DataRepository.AmfContextNon3gppError); ok2 { + problem := amfContextNon3gppErr.ProblemDetails + c.JSON(int(problem.Status), problem) + return + } } - c.JSON(int(problem.Status), problem) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -450,13 +454,13 @@ func (p *Processor) DeregistrationSmfRegistrationsProcedure(c *gin.Context, deleteSmfRegistrationRequest.PduSessionId = &pduSessionIDInt32 _, err = clientAPI.SMFRegistrationDocumentApi.DeleteSmfRegistration(ctx, &deleteSmfRegistrationRequest) if err != nil { - problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + apiError, ok := err.(openapi.GenericOpenAPIError) if !ok { problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } - c.JSON(int(problem.Status), problem) + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } @@ -499,13 +503,13 @@ func (p *Processor) RegistrationSmfRegistrationsProcedure( } _, err = clientAPI.SMFRegistrationDocumentApi.CreateOrUpdateSmfRegistration(ctx, &createSmfContext3gppRequest) if err != nil { - problem, ok := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) + apiError, ok := err.(openapi.GenericOpenAPIError) if !ok { problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } - c.JSON(int(problem.Status), problem) + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } From 26c22240c1bf288ca51c76d1769226b6393df9c6 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Fri, 1 Nov 2024 15:55:06 +0000 Subject: [PATCH 39/41] feat: update openapi hash --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 17ffb6b..49d10b2 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.21 require ( github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d - github.com/free5gc/openapi v1.0.9-0.20241024114001-1414ef920de2 + github.com/free5gc/openapi v1.0.9-0.20241030114155-51c7fcd04b72 github.com/free5gc/util v1.0.6 github.com/gin-gonic/gin v1.9.1 github.com/google/uuid v1.3.0 diff --git a/go.sum b/go.sum index f0636e3..0a7b788 100644 --- a/go.sum +++ b/go.sum @@ -15,8 +15,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= -github.com/free5gc/openapi v1.0.9-0.20241024114001-1414ef920de2 h1:rMZE/FZtEbOiAZISVs9M093g4I2SGdpcxDYp2htt6Ws= -github.com/free5gc/openapi v1.0.9-0.20241024114001-1414ef920de2/go.mod h1:aKw6uGzEibGDrn9++w4/JpWxaaUBo7GaqsvuFKU9fl4= +github.com/free5gc/openapi v1.0.9-0.20241030114155-51c7fcd04b72 h1:8O4DYHXmr5mdSjy9c+YGR9roYCVsCTvxHN0iH708n48= +github.com/free5gc/openapi v1.0.9-0.20241030114155-51c7fcd04b72/go.mod h1:aKw6uGzEibGDrn9++w4/JpWxaaUBo7GaqsvuFKU9fl4= github.com/free5gc/util v1.0.6 h1:dBt9drcXtYKE/cY5XuQcuffgsYclPIpIArhSeS6M+DQ= github.com/free5gc/util v1.0.6/go.mod h1:eSGN7POUM8LNTvg/E591XR6447a6/w1jFWGKNZPHcXw= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= From 19a9e8733ebfce91004bd7e76a882b233217f15a Mon Sep 17 00:00:00 2001 From: ubuntu Date: Wed, 13 Nov 2024 03:14:49 +0000 Subject: [PATCH 40/41] feat: update openapi hash --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 49d10b2..97ef3ab 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.21 require ( github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d - github.com/free5gc/openapi v1.0.9-0.20241030114155-51c7fcd04b72 + github.com/free5gc/openapi v1.0.9-0.20241112160830-092c679ef6cd github.com/free5gc/util v1.0.6 github.com/gin-gonic/gin v1.9.1 github.com/google/uuid v1.3.0 diff --git a/go.sum b/go.sum index 0a7b788..5e07d71 100644 --- a/go.sum +++ b/go.sum @@ -15,8 +15,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= -github.com/free5gc/openapi v1.0.9-0.20241030114155-51c7fcd04b72 h1:8O4DYHXmr5mdSjy9c+YGR9roYCVsCTvxHN0iH708n48= -github.com/free5gc/openapi v1.0.9-0.20241030114155-51c7fcd04b72/go.mod h1:aKw6uGzEibGDrn9++w4/JpWxaaUBo7GaqsvuFKU9fl4= +github.com/free5gc/openapi v1.0.9-0.20241112160830-092c679ef6cd h1:VRxE3QzfL1uU8ZnR9Y1aXtslHPeMIVoHb3wU0yOz2AI= +github.com/free5gc/openapi v1.0.9-0.20241112160830-092c679ef6cd/go.mod h1:aKw6uGzEibGDrn9++w4/JpWxaaUBo7GaqsvuFKU9fl4= github.com/free5gc/util v1.0.6 h1:dBt9drcXtYKE/cY5XuQcuffgsYclPIpIArhSeS6M+DQ= github.com/free5gc/util v1.0.6/go.mod h1:eSGN7POUM8LNTvg/E591XR6447a6/w1jFWGKNZPHcXw= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= From 07d6320c108b6809c977ecbfb7a4f1bc7f9b4802 Mon Sep 17 00:00:00 2001 From: ubuntu Date: Mon, 25 Nov 2024 08:48:10 +0000 Subject: [PATCH 41/41] fix: change apiError logic & add terminate log else logic --- internal/sbi/processor/generate_auth_data.go | 28 +++--- .../processor/subscriber_data_management.go | 96 +++++++++---------- .../sbi/processor/ue_context_management.go | 48 +++++----- pkg/service/init.go | 4 +- 4 files changed, 88 insertions(+), 88 deletions(-) diff --git a/internal/sbi/processor/generate_auth_data.go b/internal/sbi/processor/generate_auth_data.go index f61677b..4542c9c 100644 --- a/internal/sbi/processor/generate_auth_data.go +++ b/internal/sbi/processor/generate_auth_data.go @@ -99,13 +99,13 @@ func (p *Processor) ConfirmAuthDataProcedure(c *gin.Context, ctx, &createAuthStatusRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } logger.UeauLog.Errorln("ConfirmAuth err:", err.Error()) - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -155,18 +155,18 @@ func (p *Processor) GenerateAuthDataProcedure( if err != nil { logger.ProcLog.Errorf("Error on QueryAuthSubsData: %+v", err) apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) + switch apiError.ErrorStatus { + case http.StatusNotFound: + logger.UeauLog.Warnf("Return from UDR QueryAuthSubsData error") + default: + logger.UeauLog.Errorln("Return from UDR QueryAuthSubsData error") + } return } - switch apiError.ErrorStatus { - case http.StatusNotFound: - logger.UeauLog.Warnf("Return from UDR QueryAuthSubsData error") - default: - logger.UeauLog.Errorln("Return from UDR QueryAuthSubsData error") - } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } diff --git a/internal/sbi/processor/subscriber_data_management.go b/internal/sbi/processor/subscriber_data_management.go index 776e5d8..e3dab56 100644 --- a/internal/sbi/processor/subscriber_data_management.go +++ b/internal/sbi/processor/subscriber_data_management.go @@ -36,12 +36,12 @@ func (p *Processor) GetAmDataProcedure(c *gin.Context, supi string, plmnID strin QueryAmData(ctx, &queryAmDataRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -158,12 +158,12 @@ func (p *Processor) GetSupiProcedure(c *gin.Context, ctx, &queryAmDataRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -183,12 +183,12 @@ func (p *Processor) GetSupiProcedure(c *gin.Context, &querySmfSelectDataRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -210,12 +210,12 @@ func (p *Processor) GetSupiProcedure(c *gin.Context, ctx, &querySmfRegListRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -260,12 +260,12 @@ func (p *Processor) GetSupiProcedure(c *gin.Context, QuerySmData(ctx, &querySmDataRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -289,12 +289,12 @@ func (p *Processor) GetSupiProcedure(c *gin.Context, ctx, &queryTraceDataRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -392,12 +392,12 @@ func (p *Processor) GetSmDataProcedure( if err != nil { logger.ProcLog.Errorf("QuerySmData Error: %+v", err) apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -458,12 +458,12 @@ func (p *Processor) GetNssaiProcedure(c *gin.Context, supi string, plmnID string QueryAmData(ctx, &queryAmDataRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -503,12 +503,12 @@ func (p *Processor) GetSmfSelectDataProcedure(c *gin.Context, supi string, plmnI QuerySmfSelectData(ctx, &querySmfSelectDataRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -573,12 +573,12 @@ func (p *Processor) SubscribeProcedure(c *gin.Context, sdmSubscription *models.S ctx, &createSdmSubscriptionsRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -761,12 +761,12 @@ func (p *Processor) GetTraceDataProcedure(c *gin.Context, supi string, plmnID st ctx, &queryTraceDataRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -808,12 +808,12 @@ func (p *Processor) GetUeContextInSmfDataProcedure(c *gin.Context, supi string, ctx, &querySmfRegListRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } diff --git a/internal/sbi/processor/ue_context_management.go b/internal/sbi/processor/ue_context_management.go index 0669afd..ccb91eb 100644 --- a/internal/sbi/processor/ue_context_management.go +++ b/internal/sbi/processor/ue_context_management.go @@ -35,12 +35,12 @@ func (p *Processor) GetAmf3gppAccessProcedure(c *gin.Context, ueID string, suppo QueryAmfContext3gpp(ctx, &queryAmfContext3gppRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -64,12 +64,12 @@ func (p *Processor) GetAmfNon3gppAccessProcedure(c *gin.Context, queryAmfContext QueryAmfContextNon3gpp(ctx, &queryAmfContextNon3gppParamOpts) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -110,12 +110,12 @@ func (p *Processor) RegistrationAmf3gppAccessProcedure(c *gin.Context, &createAmfContext3gppRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -186,12 +186,12 @@ func (p *Processor) RegisterAmfNon3gppAccessProcedure(c *gin.Context, ctx, &createAmfContextNon3gppRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -455,12 +455,12 @@ func (p *Processor) DeregistrationSmfRegistrationsProcedure(c *gin.Context, _, err = clientAPI.SMFRegistrationDocumentApi.DeleteSmfRegistration(ctx, &deleteSmfRegistrationRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } @@ -504,12 +504,12 @@ func (p *Processor) RegistrationSmfRegistrationsProcedure( _, err = clientAPI.SMFRegistrationDocumentApi.CreateOrUpdateSmfRegistration(ctx, &createSmfContext3gppRequest) if err != nil { apiError, ok := err.(openapi.GenericOpenAPIError) - if !ok { - problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) - c.JSON(int(problemDetails.Status), problemDetails) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) return } - c.JSON(apiError.ErrorStatus, apiError.RawBody) + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) return } diff --git a/pkg/service/init.go b/pkg/service/init.go index 59e96a5..666dee2 100644 --- a/pkg/service/init.go +++ b/pkg/service/init.go @@ -163,10 +163,10 @@ func (a *UdmApp) terminateProcedure() { case error: logger.InitLog.Errorf("Deregister NF instance Error[%+v]", err) } + } else { + logger.InitLog.Infof("Deregister from NRF successfully") } - logger.InitLog.Infof("Deregister from NRF successfully") - logger.MainLog.Infof("UDM SBI Server terminated") }