diff --git a/go.mod b/go.mod index 6897ec0..97ef3ab 100644 --- a/go.mod +++ b/go.mod @@ -3,15 +3,14 @@ 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.8 + 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 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,13 +23,16 @@ 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 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 @@ -46,6 +48,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 @@ -53,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 8b07968..5e07d71 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= @@ -15,8 +13,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.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= @@ -25,6 +25,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= @@ -35,15 +40,15 @@ 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= 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 +84,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 +107,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 +137,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= @@ -153,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 922efd5..dbf5a17 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" @@ -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,14 +50,14 @@ 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 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 @@ -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) } @@ -170,15 +170,17 @@ 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 +198,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]] @@ -219,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) @@ -467,10 +469,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 +481,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 +492,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/sbi/api_eventexposure.go b/internal/sbi/api_eventexposure.go index b34ab88..b6902ea 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" @@ -15,28 +14,28 @@ func (s *Server) getEventExposureRoutes() []Route { return []Route{ { "Index", - "GET", + http.MethodGet, "/", s.HandleIndex, }, { - "HTTPCreateEeSubscription", - strings.ToUpper("Post"), + "CreateEeSubscription", + http.MethodPost, "/:ueIdentity/ee-subscriptions", s.HandleCreateEeSubscription, }, { - "HTTPDeleteEeSubscription", - strings.ToUpper("Delete"), + "DeleteEeSubscription", + http.MethodDelete, "/:ueIdentity/ee-subscriptions/:subscriptionId", s.HandleDeleteEeSubscription, }, { - "HTTPUpdateEeSubscription", - strings.ToUpper("Patch"), + "UpdateEeSubscription", + http.MethodPatch, "/:ueIdentity/ee-subscriptions/:subscriptionId", s.HandleUpdateEeSubscription, }, @@ -45,7 +44,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/api_httpcallback.go b/internal/sbi/api_httpcallback.go index 6c79ce6..be7e58a 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" @@ -15,14 +14,14 @@ func (s *Server) getHttpCallBackRoutes() []Route { return []Route{ { "Index", - "GET", + http.MethodGet, "/", s.HandleIndex, }, { "DataChangeNotificationToNF", - strings.ToUpper("Post"), + http.MethodPost, "/sdm-subscriptions", s.HandleDataChangeNotificationToNF, }, diff --git a/internal/sbi/api_mt.go b/internal/sbi/api_mt.go new file mode 100644 index 0000000..6c196bd --- /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", + http.MethodGet, + "/", + s.HandleIndex, + }, + + { + "ProvideLocationInfo", + http.MethodPost, + "/:supi/loc-info/provide-loc-info", + s.HandleProvideLocationInfo, + }, + + { + "QueryUeInfo", + http.MethodGet, + "/: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..897938c --- /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", + http.MethodGet, + "/", + s.HandleIndex, + }, + + { + "AuthorizeNiddData", + http.MethodPost, + "/:ueIdentity/authorize", + s.HandleAuthorizeNiddData, + }, + } +} + +func (s *Server) HandleAuthorizeNiddData(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} diff --git a/internal/sbi/api_parameterprovision.go b/internal/sbi/api_parameterprovision.go index 2e695ca..b69adaf 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" @@ -15,17 +14,94 @@ func (s *Server) getParameterProvisionRoutes() []Route { return []Route{ { "Index", - "GET", + http.MethodGet, "/", s.HandleIndex, }, { "Update", - strings.ToUpper("Patch"), - "/:gpsi/pp-data", + http.MethodPatch, + "/:ueId/pp-data", s.HandleUpdate, }, + + { + "Create5GMBSGroup", + http.MethodPut, + "/mbs-group-membership/:extGroupId", + s.HandleCreate5GMBSGroup, + }, + + { + "Create5GVNGroup", + http.MethodPut, + "/5g-vn-groups/:extGroupId", + s.HandleCreate5GVNGroup, + }, + + { + "CreatePPDataEntry", + http.MethodPut, + "/:ueId/pp-data-store/:afInstanceId", + s.HandleCreatePPDataEntry, + }, + + { + "Delete5GMBSGroup", + http.MethodDelete, + "/mbs-group-membership/:extGroupId", + s.HandleDelete5GMBSGroup, + }, + + { + "Delete5GVNGroup", + http.MethodDelete, + "/5g-vn-groups/:extGroupId", + s.HandleDelete5GVNGroup, + }, + + { + "DeletePPDataEntry", + http.MethodDelete, + "/:ueId/pp-data-store/:afInstanceId", + s.HandleDeletePPDataEntry, + }, + + { + "Get5GMBSGroup", + http.MethodGet, + "/mbs-group-membership/:extGroupId", + s.HandleGet5GMBSGroup, + }, + + { + "Get5GVNGroup", + http.MethodGet, + "/5g-vn-groups/:extGroupId", + s.HandleGet5GVNGroup, + }, + + { + "GetPPDataEntry", + http.MethodGet, + "/:ueId/pp-data-store/:afInstanceId", + s.HandleGetPPDataEntry, + }, + + { + "Modify5GMBSGroup", + http.MethodPatch, + "/mbs-group-membership/:extGroupId", + s.HandleModify5GMBSGroup, + }, + + { + "Modify5GVNGroup", + http.MethodPatch, + "/5g-vn-groups/:extGroupId", + s.HandleModify5GVNGroup, + }, } } @@ -60,7 +136,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, @@ -75,3 +151,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_reportsmdeliverystatus.go b/internal/sbi/api_reportsmdeliverystatus.go new file mode 100644 index 0000000..07d5481 --- /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", + http.MethodGet, + "/", + s.HandleIndex, + }, + + { + "ReportSMDeliveryStatus", + http.MethodPost, + "/: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..3dd8c33 --- /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", + http.MethodGet, + "/", + s.HandleIndex, + }, + + { + "ServiceSpecificAuthorization", + http.MethodPost, + "/:ueIdentity/:serviceType/authorize", + s.HandleServiceSpecificAuthorization, + }, + + { + "ServiceSpecificAuthorizationRemoval", + http.MethodPost, + "/: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_subscriberdatamanagement.go b/internal/sbi/api_subscriberdatamanagement.go index 52a3cbd..081eb25 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, }, @@ -206,7 +206,6 @@ func (s *Server) HandleSubscribe(c *gin.Context) { logger.SdmLog.Infof("Handle Subscribe") supi := c.Params.ByName("supi") - s.Processor().SubscribeProcedure(c, &sdmSubscriptionReq, supi) } @@ -214,7 +213,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 +258,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,11 +376,75 @@ 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) } +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() @@ -393,7 +456,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 } @@ -405,25 +468,33 @@ func (s *Server) TwoLayerPathHandlerFunc(c *gin.Context) { supi := c.Param("supi") op := c.Param("subscriptionId") + logger.ConsumerLog.Infoln("TwoLayerPathHandlerFunc, ", supi, op) + // 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 "/:gpsi/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")}) + // for "/:ueId/id-translation-result" + 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" && http.MethodGet == 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 { @@ -437,11 +508,12 @@ func (s *Server) TwoLayerPathHandlerFunc(c *gin.Context) { func (s *Server) ThreeLayerPathHandlerFunc(c *gin.Context) { op := c.Param("subscriptionId") + thirdLayer := c.Param("thirdLayer") - // for "/:supi/sdm-subscriptions/:subscriptionId" - if op == "sdm-subscriptions" && strings.ToUpper("Delete") == c.Request.Method { + // for "/:ueId/sdm-subscriptions/:subscriptionId" + if op == "sdm-subscriptions" && http.MethodDelete == 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) @@ -449,15 +521,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" && http.MethodPut == c.Request.Method && thirdLayer == "sor-ack" { s.HandleInfo(c) return } - // for "/:supi/sdm-subscriptions/:subscriptionId" - if op == "sdm-subscriptions" && strings.ToUpper("Patch") == c.Request.Method { + // for "/:supi/am-data/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" && http.MethodGet == c.Request.Method && thirdLayer == "ecr-data" { + s.HandleGetEcrData(c) + return + } + + // for "/:supi/am-data/subscribed-snssais-ack" + 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" && http.MethodPost == c.Request.Method && thirdLayer == "update-sor" { + s.HandleUpdateSORInfo(c) + return + } + + // for "/:supi/am-data/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" && http.MethodPatch == 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,25 +573,32 @@ func (s *Server) ThreeLayerPathHandlerFunc(c *gin.Context) { func (s *Server) getOneLayerRoutes() []Route { return []Route{ { - "GetSupi", - strings.ToUpper("Get"), + "GetDataSets", + 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", + http.MethodGet, + "/multiple-identifiers", + s.HandleGetMultipleIdentifiers, + }, } } @@ -496,72 +606,135 @@ func (s *Server) getTwoLayerRoutes() []Route { return []Route{ { "GetAmData", - strings.ToUpper("Get"), + http.MethodGet, "/:supi/am-data", s.HandleGetAmData, }, { - "GetSmfSelectData", - strings.ToUpper("Get"), + "GetSmfSelData", + http.MethodGet, "/:supi/smf-select-data", s.HandleGetSmfSelectData, }, { - "GetSmsMngData", - strings.ToUpper("Get"), + "GetSmsMngtData", + 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"), + "GetNSSAI", + http.MethodGet, "/:supi/nssai", s.HandleGetNssai, }, { "Subscribe", - strings.ToUpper("Post"), - "/:supi/sdm-subscriptions", + http.MethodPost, + "/:ueId/sdm-subscriptions", s.HandleSubscribe, }, { - "GetTraceData", - strings.ToUpper("Get"), + "GetTraceConfigData", + http.MethodGet, "/:supi/trace-data", s.HandleGetTraceData, }, { - "GetUeContextInSmfData", - strings.ToUpper("Get"), + "GetUeCtxInSmfData", + http.MethodGet, "/:supi/ue-context-in-smf-data", s.HandleGetUeContextInSmfData, }, { - "GetUeContextInSmsfData", - strings.ToUpper("Get"), + "GetUeCtxInSmsfData", + http.MethodGet, "/:supi/ue-context-in-smsf-data", s.HandleGetUeContextInSmsfData, }, + + { + "GetGroupIdentifiers", + http.MethodGet, + "/group-data/group-identifiers", + s.HandleGetGroupIdentifiers, + }, + + { + "GetLcsBcaData", + http.MethodGet, + "/:supi/lcs-bca-data", + s.HandleGetLcsBcaData, + }, + + { + "GetLcsMoData", + http.MethodGet, + "/:supi/lcs-mo-data", + s.HandleGetLcsMoData, + }, + + { + "GetLcsPrivacyData", + http.MethodGet, + "/:ueId/lcs-privacy-data", + s.HandleGetLcsPrivacyData, + }, + + { + "GetMbsData", + http.MethodGet, + "/:supi/5mbs-data", + s.HandleGetMbsData, + }, + + { + "GetProseData", + http.MethodGet, + "/:supi/prose-data", + s.HandleGetProseData, + }, + + { + "GetUcData", + http.MethodGet, + "/:supi/uc-data", + s.HandleGetUcData, + }, + + { + "GetUeCtxInAmfData", + http.MethodGet, + "/:supi/ue-context-in-amf-data", + s.HandleGetUeCtxInAmfData, + }, + + { + "GetV2xData", + http.MethodGet, + "/:supi/v2x-data", + s.HandleGetV2xData, + }, } } diff --git a/internal/sbi/api_ueauthentication.go b/internal/sbi/api_ueauthentication.go index 68b61c5..74141c1 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" @@ -15,17 +14,10 @@ func (s *Server) getUEAuthenticationRoutes() []Route { return []Route{ { "Index", - "GET", + http.MethodGet, "/", s.HandleIndex, }, - - { - "ConfirmAuth", - strings.ToUpper("Post"), - "/:supi/auth-events", - s.HandleConfirmAuth, - }, } } @@ -102,9 +94,76 @@ func (s *Server) HandleGenerateAuthData(c *gin.Context) { s.Processor().GenerateAuthDataProcedure(c, authInfoReq, supiOrSuci) } -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 { +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{}) +} + +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("twoLayer") + + // 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 } diff --git a/internal/sbi/api_uecontextmanagement.go b/internal/sbi/api_uecontextmanagement.go index 7725449..10b7e9b 100644 --- a/internal/sbi/api_uecontextmanagement.go +++ b/internal/sbi/api_uecontextmanagement.go @@ -2,14 +2,12 @@ package sbi import ( "net/http" - "strings" - "github.com/antihax/optional" "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" ) @@ -17,108 +15,227 @@ func (s *Server) getUEContextManagementRoutes() []Route { return []Route{ { "Index", - "GET", + http.MethodGet, "/", s.HandleIndex, }, { - "GetAmf3gppAccess", - strings.ToUpper("Get"), + "Get3GppRegistration", + http.MethodGet, "/:ueId/registrations/amf-3gpp-access", s.HandleGetAmf3gppAccess, }, { - "GetAmfNon3gppAccess", - strings.ToUpper("Get"), + "GetNon3GppRegistration", + http.MethodGet, "/:ueId/registrations/amf-non-3gpp-access", s.HandleGetAmfNon3gppAccess, }, { - "RegistrationAmf3gppAccess", - strings.ToUpper("Put"), + "Call3GppRegistration", + http.MethodPut, "/:ueId/registrations/amf-3gpp-access", s.HandleRegistrationAmf3gppAccess, }, { - "Register", - strings.ToUpper("Put"), + "Non3GppRegistration", + http.MethodPut, "/:ueId/registrations/amf-non-3gpp-access", s.HandleRegistrationAmfNon3gppAccess, }, { - "UpdateAmf3gppAccess", - strings.ToUpper("Patch"), + "Update3GppRegistration", + http.MethodPatch, "/:ueId/registrations/amf-3gpp-access", s.HandleUpdateAmf3gppAccess, }, { - "UpdateAmfNon3gppAccess", - strings.ToUpper("Patch"), + "UpdateNon3GppRegistration", + http.MethodPatch, "/:ueId/registrations/amf-non-3gpp-access", s.HandleUpdateAmfNon3gppAccess, }, { - "DeregistrationSmfRegistrations", - strings.ToUpper("Delete"), + "SmfDeregistration", + http.MethodDelete, "/:ueId/registrations/smf-registrations/:pduSessionId", s.HandleDeregistrationSmfRegistrations, }, { - "RegistrationSmfRegistrations", - strings.ToUpper("Put"), + "Registration", + http.MethodPut, "/:ueId/registrations/smf-registrations/:pduSessionId", s.HandleRegistrationSmfRegistrations, }, { - "GetSmsf3gppAccess", - strings.ToUpper("Get"), + "Get3GppSmsfRegistration", + http.MethodGet, "/:ueId/registrations/smsf-3gpp-access", s.HandleGetSmsf3gppAccess, }, { - "DeregistrationSmsf3gppAccess", - strings.ToUpper("Delete"), + "Call3GppSmsfDeregistration", + http.MethodDelete, "/:ueId/registrations/smsf-3gpp-access", s.HandleDeregistrationSmsf3gppAccess, }, { - "DeregistrationSmsfNon3gppAccess", - strings.ToUpper("Delete"), + "Non3GppSmsfDeregistration", + http.MethodDelete, "/:ueId/registrations/smsf-non-3gpp-access", s.HandleDeregistrationSmsfNon3gppAccess, }, { - "GetSmsfNon3gppAccess", - strings.ToUpper("Get"), + "GetNon3GppSmsfRegistration", + http.MethodGet, "/:ueId/registrations/smsf-non-3gpp-access", s.HandleGetSmsfNon3gppAccess, }, { - "UpdateSMSFReg3GPP", - strings.ToUpper("Put"), + "Call3GppSmsfRegistration", + http.MethodPut, "/:ueId/registrations/smsf-3gpp-access", s.HandleUpdateSMSFReg3GPP, }, { - "RegistrationSmsfNon3gppAccess", - strings.ToUpper("Put"), + "Non3GppSmsfRegistration", + http.MethodPut, "/:ueId/registrations/smsf-non-3gpp-access", s.HandleRegistrationSmsfNon3gppAccess, }, + + { + "DeregAMF", + http.MethodPost, + "/:ueId/registrations/amf-3gpp-access/dereg-amf", + s.HandleDeregAMF, + }, + + { + "GetIpSmGwRegistration", + http.MethodGet, + "/:ueId/registrations/ip-sm-gw", + s.HandleGetIpSmGwRegistration, + }, + + { + "GetLocationInfo", + http.MethodGet, + "/:ueId/registrations/location", + s.HandleGetLocationInfo, + }, + + { + "GetNwdafRegistration", + http.MethodGet, + "/:ueId/registrations/nwdaf-registrations", + s.HandleGetNwdafRegistration, + }, + + { + "GetRegistrations", + http.MethodGet, + "/:ueId/registrations", + s.HandleGetRegistrations, + }, + + { + "GetSmfRegistration", + http.MethodGet, + "/:ueId/registrations/smf-registrations", + s.HandleGetSmfRegistration, + }, + + { + "IpSmGwDeregistration", + http.MethodDelete, + "/:ueId/registrations/ip-sm-gw", + s.HandleIpSmGwDeregistration, + }, + + { + "IpSmGwRegistration", + http.MethodPut, + "/:ueId/registrations/ip-sm-gw", + s.HandleIpSmGwRegistration, + }, + + { + "NwdafDeregistration", + http.MethodDelete, + "/:ueId/registrations/nwdaf-registrations/:nwdafRegistrationId", + s.HandleNwdafDeregistration, + }, + + { + "NwdafRegistration", + http.MethodPut, + "/:ueId/registrations/nwdaf-registrations/:nwdafRegistrationId", + s.HandleNwdafRegistration, + }, + + { + "PeiUpdate", + http.MethodPost, + "/:ueId/registrations/amf-3gpp-access/pei-update", + s.HandlePeiUpdate, + }, + + { + "RetrieveSmfRegistration", + http.MethodGet, + "/:ueId/registrations/smf-registrations/:pduSessionId", + s.HandleRetrieveSmfRegistration, + }, + + { + "SendRoutingInfoSm", + http.MethodPost, + "/:ueId/registrations/send-routing-info-sm", + s.HandleSendRoutingInfoSm, + }, + + { + "TriggerPCSCFRestoration", + http.MethodPost, + "/restore-pcscf", + s.HandleTriggerPCSCFRestoration, + }, + + { + "UpdateNwdafRegistration", + http.MethodPatch, + "/:ueId/registrations/nwdaf-registrations/:nwdafRegistrationId", + s.HandleUpdateNwdafRegistration, + }, + + { + "UpdateRoamingInformation", + http.MethodPost, + "/:ueId/registrations/amf-3gpp-access/roaming-info-update", + s.HandleUpdateRoamingInformation, + }, + + { + "UpdateSmfRegistration", + http.MethodPatch, + "/:ueId/registrations/smf-registrations/:pduSessionId", + s.HandleUpdateSmfRegistration, + }, } } @@ -128,11 +245,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 @@ -374,3 +490,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{}) +} diff --git a/internal/sbi/api_ueid.go b/internal/sbi/api_ueid.go new file mode 100644 index 0000000..5225f5b --- /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", + http.MethodGet, + "/", + s.HandleIndex, + }, + + { + "Deconceal", + http.MethodPost, + "/deconceal", + s.HandleDeconceal, + }, + } +} + +func (s *Server) HandleDeconceal(c *gin.Context) { + c.JSON(http.StatusNotImplemented, gin.H{}) +} 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 deleted file mode 100644 index 8b30abf..0000000 --- a/internal/sbi/consumer/nf_discovery.go +++ /dev/null @@ -1,69 +0,0 @@ -package consumer - -import ( - "fmt" - "net/http" - - "github.com/free5gc/openapi/Nnrf_NFDiscovery" - "github.com/free5gc/openapi/models" - 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/nf_management_test.go b/internal/sbi/consumer/nf_management_test.go index b185799..05c7f86 100644 --- a/internal/sbi/consumer/nf_management_test.go +++ b/internal/sbi/consumer/nf_management_test.go @@ -16,8 +16,8 @@ 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.New("http://127.0.0.10:8000"). Put("/nnrf-nfm/v1/nf-instances/1"). diff --git a/internal/sbi/consumer/nrf_service.go b/internal/sbi/consumer/nrf_service.go index 3f5ec28..e8d2cfc 100644 --- a/internal/sbi/consumer/nrf_service.go +++ b/internal/sbi/consumer/nrf_service.go @@ -2,20 +2,18 @@ package consumer import ( "context" - "fmt" - "net/http" "strings" "sync" "time" "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" + "github.com/free5gc/udm/internal/util" ) type nnrfService struct { @@ -73,7 +71,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,58 +79,57 @@ func (s *nnrfService) SendSearchNFInstances( client := s.getNFDiscClient(udmContext.NrfUri) - ctx, _, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_DISC, models.NfType_NRF) + ctx, _, err := s.consumer.Context().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) SendDeregisterNFInstance() (problemDetails *models.ProblemDetails, err error) { +func (s *nnrfService) SendNFInstancesUDR(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 + + 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() (err error) { logger.ConsumerLog.Infof("Send Deregister NFInstance") - ctx, pd, err := udm_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_NFM, models.NfType_NRF) + ctx, _, err := s.consumer.Context().GetTokenCtx(models.ServiceName_NNRF_NFM, models.NrfNfManagementNfType_NRF) if err != nil { - return pd, err + return err } udmContext := s.consumer.Context() client := s.getNFManagementClient(udmContext.NrfUri) - var res *http.Response + var derigisterNfInstanceRequest Nnrf_NFManagement.DeregisterNFInstanceRequest + derigisterNfInstanceRequest.NfInstanceID = &udmContext.NfId + _, 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 { - err = openapi.ReportError("server no response") - } - return problemDetails, err + return err } func (s *nnrfService) RegisterNFInstance(ctx context.Context) ( @@ -144,34 +141,37 @@ 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 + var res *Nnrf_NFManagement.RegisterNFInstanceResponse for { - nf, res, err = client.NFInstanceIDDocumentApi.RegisterNFInstance(ctx, udmContext.NfId, nfProfile) + select { + case <-ctx.Done(): + return "", "", errors.Errorf("Context Cancel before RegisterNFInstance") + default: + } + + res, err = client.NFInstanceIDDocumentApi.RegisterNFInstance(ctx, ®isterNfInstanceRequest) + if err != nil || res == nil { - logger.ConsumerLog.Errorf("UDM register to NRF Error[%v]", err) + logger.ConsumerLog.Errorf("UDM register to NRF Error[%v]", err.Error()) 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) - } - }() - status := res.StatusCode - if status == http.StatusOK { + + if res.Location == "" { // NFUpdate break - } else if status == http.StatusCreated { + } else { // http.statusCreated // 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) @@ -183,25 +183,20 @@ 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 } -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{} 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/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..766925a 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" ) @@ -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.SendNFInstancesUDR(id, NFDiscoveryToUDRParamSupi) } return ue.UdrUri } else { ue = udm_context.GetSelf().NewUdmUe(id) - ue.UdrUri = 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 = 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 = 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 SendNFIntancesUDR(id, NFDiscoveryToUDRParamExtGroupId) + return s.consumer.SendNFInstancesUDR(id, NFDiscoveryToUDRParamExtGroupId) } else if strings.Contains(id, "msisdn") || strings.Contains(id, "extid") { // gpsi - return SendNFIntancesUDR(id, NFDiscoveryToUDRParamGpsi) + return s.consumer.SendNFInstancesUDR(id, NFDiscoveryToUDRParamGpsi) } - return SendNFIntancesUDR("", NFDiscoveryToUDRParamNone) + return s.consumer.SendNFInstancesUDR("", NFDiscoveryToUDRParamNone) } 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 7135558..4542c9c 100644 --- a/internal/sbi/processor/generate_auth_data.go +++ b/internal/sbi/processor/generate_auth_data.go @@ -12,12 +12,11 @@ import ( "strings" "time" - "github.com/antihax/optional" "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" @@ -80,14 +79,14 @@ 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 } - 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,22 @@ func (p *Processor) ConfirmAuthDataProcedure(c *gin.Context, return } - resp, err := client.AuthenticationStatusDocumentApi.CreateAuthenticationStatus( - ctx, supi, &createAuthParam) + _, 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(), + apiError, ok := err.(openapi.GenericOpenAPIError) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) + return } - logger.UeauLog.Errorln("ConfirmAuth err:", err.Error()) + problemDetails := openapi.ProblemDetailsSystemFailure(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) + // AuthEvent in response body is optional + c.JSON(http.StatusCreated, gin.H{}) } func (p *Processor) GenerateAuthDataProcedure( @@ -123,14 +118,14 @@ 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 } 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 { @@ -153,28 +148,27 @@ func (p *Processor) GenerateAuthDataProcedure( c.JSON(int(problemDetails.Status), problemDetails) return } - authSubs, res, err := client.AuthenticationDataDocumentApi.QueryAuthSubsData(ctx, supi, nil) - if err != nil { - problemDetails := &models.ProblemDetails{ - Status: http.StatusForbidden, - Cause: authenticationRejected, - Detail: err.Error(), - } + var queryAuthSubsDataRequest Nudr_DataRepository.QueryAuthSubsDataRequest + queryAuthSubsDataRequest.UeId = &supi - switch res.StatusCode { - case http.StatusNotFound: - logger.UeauLog.Warnf("Return from UDR QueryAuthSubsData error") - default: - logger.UeauLog.Errorln("Return from UDR QueryAuthSubsData error") + authSubs, err := client.AuthenticationDataDocumentApi.QueryAuthSubsData(ctx, &queryAuthSubsDataRequest) + if err != nil { + logger.ProcLog.Errorf("Error on QueryAuthSubsData: %+v", err) + apiError, ok := err.(openapi.GenericOpenAPIError) + 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 } + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) 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) @@ -182,23 +176,21 @@ 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{ Status: http.StatusForbidden, Cause: authenticationRejected, + Detail: "len(kStr) != keyStrLen", } logger.UeauLog.Errorln("kStr length is ", len(kStr)) @@ -209,6 +201,7 @@ func (p *Processor) GenerateAuthDataProcedure( problemDetails := &models.ProblemDetails{ Status: http.StatusForbidden, Cause: authenticationRejected, + Detail: "EncPermanentKey == ''", } logger.UeauLog.Errorln("Nil PermanentKey") @@ -216,35 +209,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 { @@ -259,7 +225,7 @@ func (p *Processor) GenerateAuthDataProcedure( logger.UeauLog.Infoln("Nil Opc") } - if !hasOPC && !hasOP { + if !hasOPC { problemDetails := &models.ProblemDetails{ Status: http.StatusForbidden, Cause: authenticationRejected, @@ -268,25 +234,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 { @@ -317,7 +265,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 { @@ -371,10 +319,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 } @@ -447,16 +395,21 @@ 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, + }, }, } - var rsp *http.Response + logger.ProcLog.Infoln("ModifyAuthenticationSubscriptionRequest: ", patchItemArray) - 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, @@ -468,11 +421,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) @@ -506,8 +454,8 @@ func (p *Processor) GenerateAuthDataProcedure( logger.UeauLog.Tracef("AUTN=[%x]", AUTN) var av models.AuthenticationVector - if authSubs.AuthenticationMethod == models.AuthMethod__5_G_AKA { - response.AuthType = models.AuthType__5_G_AKA + if authSubs.AuthenticationSubscription.AuthenticationMethod == models.AuthMethod__5_G_AKA { + response.AuthType = models.UdmUeauAuthType__5_G_AKA // derive XRES* key := append(CK, IK...) @@ -541,8 +489,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 new file mode 100644 index 0000000..d8f8e52 --- /dev/null +++ b/internal/sbi/processor/generate_auth_data_test.go @@ -0,0 +1,112 @@ +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" + udm_context "github.com/free5gc/udm/internal/context" + "github.com/free5gc/udm/internal/sbi/consumer" + mockapp "github.com/free5gc/udm/pkg/mockapp" +) + +func TestGenerateAuthDataProcedure(t *testing.T) { + defer gock.Off() // Flush pending mocks after test execution + + openapi.InterceptH2CClient() + defer openapi.RestoreH2CClient() + + 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"). + 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") + + 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.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.UdmUeauAuthenticationInfoResult{ + 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) +} diff --git a/internal/sbi/processor/notifier.go b/internal/sbi/processor/notifier.go index 4e16b71..a940967 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,52 @@ 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 { - logger.HttpLog.Error(err.Error()) - problemDetails = &models.ProblemDetails{ - Status: http.StatusForbidden, - Detail: err.Error(), + 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.Errorln(err.Error()) - - problemDetails = &models.ProblemDetails{ - Status: int32(httpResponse.StatusCode), - Detail: err.Error(), - } + logger.HttpLog.Error(err.Error()) + problemDetails = openapi.ProblemDetailsSystemFailure(err.Error()) } } - 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") - - httpResponse, err := clientAPI.DeregistrationNotificationCallbackApi.DeregistrationNotify( - ctx, onDeregistrationNotificationUrl, deregistData) + var call3GppRegistrationDeregistrationNotificationPostRequest UEContextManagement. + Call3GppRegistrationDeregistrationNotificationPostRequest + call3GppRegistrationDeregistrationNotificationPostRequest.UdmUecmDeregistrationData = &deregistData + _, err = clientAPI.AMFRegistrationFor3GPPAccessApi. + Call3GppRegistrationDeregistrationNotificationPost(ctx, + onDeregistrationNotificationUrl, + &call3GppRegistrationDeregistrationNotificationPostRequest) 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(), + if apiErr, ok := err.(openapi.GenericOpenAPIError); ok { + // API error + if deregisterNoti_err, ok2 := apiErr. + Model().(UEContextManagement.Call3GppRegistrationDeregistrationNotificationPostError); ok2 { + return &deregisterNoti_err.ProblemDetails } - - return problemDetails } } - 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/parameter_provision.go b/internal/sbi/processor/parameter_provision.go index bd72ea1..29e78e0 100644 --- a/internal/sbi/processor/parameter_provision.go +++ b/internal/sbi/processor/parameter_provision.go @@ -7,14 +7,14 @@ import ( "github.com/free5gc/openapi" "github.com/free5gc/openapi/models" - "github.com/free5gc/udm/internal/logger" + Nudr_DataRepository "github.com/free5gc/openapi/udr/DataRepository" ) 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,26 @@ 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(), + 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 + } } + 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.PatchResult) + return + } + c.Status(http.StatusNoContent) } diff --git a/internal/sbi/processor/subscriber_data_management.go b/internal/sbi/processor/subscriber_data_management.go index 9efeced..e3dab56 100644 --- a/internal/sbi/processor/subscriber_data_management.go +++ b/internal/sbi/processor/subscriber_data_management.go @@ -1,27 +1,30 @@ package processor import ( + "encoding/json" "net/http" "strconv" - "github.com/antihax/optional" "github.com/gin-gonic/gin" "github.com/free5gc/openapi" - "github.com/free5gc/openapi/Nudr_DataRepository" "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" ) 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 +32,40 @@ 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) + apiError, ok := err.(openapi.GenericOpenAPIError) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) 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) - c.JSON(http.StatusOK, accessAndMobilitySubscriptionDataResp) - } else { - problemDetails := &models.ProblemDetails{ - Status: http.StatusNotFound, - Cause: "DATA_NOT_FOUND", - } - c.JSON(int(problemDetails.Status), problemDetails) + udmUe.SetAMSubsriptionData(&accessAndMobilitySubscriptionDataResp.AccessAndMobilitySubscriptionData) + c.JSON(http.StatusOK, accessAndMobilitySubscriptionDataResp.AccessAndMobilitySubscriptionData) + return } + c.String(http.StatusInternalServerError, "accessAndMobilitySubscriptionDataResp is nil") } 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,42 +74,26 @@ 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(), + 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(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("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, @@ -135,7 +109,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 @@ -157,142 +131,95 @@ 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 - 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) + apiError, ok := err.(openapi.GenericOpenAPIError) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) 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) + apiError, ok := err.(openapi.GenericOpenAPIError) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) 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) + apiError, ok := err.(openapi.GenericOpenAPIError) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) 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 +228,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 +237,12 @@ 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 +254,57 @@ 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) + apiError, ok := err.(openapi.GenericOpenAPIError) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) 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 } 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) + apiError, ok := err.(openapi.GenericOpenAPIError) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) 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 @@ -431,7 +315,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 @@ -443,45 +327,28 @@ 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(), + 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(problemDetails.Status), problemDetails) - 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", } + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) + return } + + p.Context().SharedSubsDataMap = udm_context.MappingSharedData(sharedDataResp.UdmSdmSharedData) + sharedData := udm_context.ObtainRequiredSharedData(sharedDataIds, sharedDataResp.UdmSdmSharedData) + c.JSON(http.StatusOK, sharedData) } func (p *Processor) GetSmDataProcedure( @@ -492,97 +359,93 @@ 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) + 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 querySmDataParamOpts Nudr_DataRepository.QuerySmDataParamOpts - querySmDataParamOpts.SingleNssai = optional.NewInterface(Snssai) + 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 + } + + var querySmDataRequest Nudr_DataRepository.QuerySmDataRequest + 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(), - } - c.JSON(int(problemDetails.Status), problemDetails) + logger.ProcLog.Errorf("QuerySmData Error: %+v", err) + apiError, ok := err.(openapi.GenericOpenAPIError) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) 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("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 { @@ -591,57 +454,40 @@ 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(), - } - - c.JSON(int(problemDetails.Status), problemDetails) + apiError, ok := err.(openapi.GenericOpenAPIError) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) 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) - } - }() - 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) @@ -653,107 +499,63 @@ 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) + smfSelectionSubscriptionDataResp, err := clientAPI.SMFSelectionSubscriptionDataDocumentApi. + QuerySmfSelectData(ctx, &querySmfSelectDataRequest) 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(), - } - c.JSON(int(problemDetails.Status), problemDetails) + apiError, ok := err.(openapi.GenericOpenAPIError) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) 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("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) + sdmSubscriptionResp, err := udmClientAPI.SubscriptionCreationForSharedDataApi.SubscribeToSharedData( + ctx, &subscibeToShareDataRequest) 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(), + 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(problemDetails.Status), problemDetails) - 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", - } - + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) + return } + + 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 @@ -764,100 +566,62 @@ 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 + createSdmSubscriptionsRequest.UeId = &supi + 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(), - } - c.JSON(int(problemDetails.Status), problemDetails) + apiError, ok := err.(openapi.GenericOpenAPIError) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) 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("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 { + 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(problemDetails.Status), problemDetails) - 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", } + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) + return } + + 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 @@ -868,39 +632,24 @@ 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(), + 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(problemDetails.Status), problemDetails) - 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", } + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) + return } + + c.Status(http.StatusNoContent) } func (p *Processor) ModifyProcedure(c *gin.Context, @@ -908,7 +657,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 @@ -921,43 +670,27 @@ 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 { + 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(problemDetails.Status), problemDetails) - 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", - } - + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) + return } + + c.JSON(http.StatusOK, sdmSubscription) } // TS 29.503 5.2.2.7.3 @@ -967,7 +700,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 @@ -981,52 +714,39 @@ 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 { + 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(problemDetails.Status), problemDetails) - 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", } + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) + return } + + 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 { @@ -1037,54 +757,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) + traceDataRes, err := clientAPI.TraceDataDocumentApi.QueryTraceData( + ctx, &queryTraceDataRequest) 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(), - } - c.JSON(int(problemDetails.Status), problemDetails) + apiError, ok := err.(openapi.GenericOpenAPIError) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) 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 = &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 { @@ -1096,38 +798,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(), - } - - c.JSON(int(problemDetails.Status), problemDetails) + apiError, ok := err.(openapi.GenericOpenAPIError) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) 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 pdusessRes.SmfRegistration { var pduSession models.PduSession pduSession.Dnn = element.Dnn pduSession.SmfInstanceId = element.SmfInstanceId @@ -1136,7 +826,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 @@ -1145,20 +835,12 @@ 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 { diff --git a/internal/sbi/processor/ue_context_management.go b/internal/sbi/processor/ue_context_management.go index 091e650..ccb91eb 100644 --- a/internal/sbi/processor/ue_context_management.go +++ b/internal/sbi/processor/ue_context_management.go @@ -4,25 +4,25 @@ import ( "net/http" "strconv" - "github.com/antihax/optional" "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" ) // 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,26 @@ 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(), + apiError, ok := err.(openapi.GenericOpenAPIError) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) + return } + 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, amf3GppAccessRegistration) + c.JSON(http.StatusOK, amf3GppAccessRegistration.Amf3GppAccessRegistration) } 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) + ctx, pd, err := p.Context().GetTokenCtx(models.ServiceName_NUDR_DR, models.NrfNfManagementNfType_UDR) if err != nil { c.JSON(int(pd.Status), pd) } @@ -64,32 +60,27 @@ func (p *Processor) GetAmfNon3gppAccessProcedure(c *gin.Context, queryAmfContext c.JSON(int(problemDetails.Status), problemDetails) return } - - amfNon3GppAccessRegistration, resp, err := clientAPI.AMFNon3GPPAccessRegistrationDocumentApi. - QueryAmfContextNon3gpp(ctx, ueID, &queryAmfContextNon3gppParamOpts) + amfNon3GppAccessRegistrationResponse, err := clientAPI.AMFNon3GPPAccessRegistrationDocumentApi. + QueryAmfContextNon3gpp(ctx, &queryAmfContextNon3gppParamOpts) if err != nil { - problemDetails := &models.ProblemDetails{ - Status: int32(resp.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), + apiError, ok := err.(openapi.GenericOpenAPIError) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) + return } + 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.AmfNon3GppAccessRegistration) } 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 @@ -112,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(), + apiError, ok := err.(openapi.GenericOpenAPIError) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) + return } + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) 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 @@ -140,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, } @@ -172,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 @@ -192,33 +178,28 @@ 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 - resp, err := clientAPI.AMFNon3GPPAccessRegistrationDocumentApi.CreateAmfContextNon3gpp( - ctx, ueID, &createAmfContextNon3gppParamOpts) + _, err = clientAPI.AMFNon3GPPAccessRegistrationDocumentApi.CreateAmfContextNon3gpp( + ctx, &createAmfContextNon3gppRequest) if err != nil { - problemDetails := &models.ProblemDetails{ - Status: int32(resp.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), + apiError, ok := err.(openapi.GenericOpenAPIError) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) + return } - + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) 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 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, @@ -236,7 +217,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 @@ -314,14 +295,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(), + 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 + } } + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } @@ -331,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) } @@ -344,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 @@ -421,23 +402,23 @@ func (p *Processor) UpdateAmfNon3gppAccessProcedure(c *gin.Context, c.JSON(int(problemDetails.Status), problemDetails) return } - - resp, err := clientAPI.AMFNon3GPPAccessRegistrationDocumentApi.AmfContextNon3gpp(ctx, - ueID, patchItemReqArray) + var amfContextNon3gppRequest Nudr_DataRepository.AmfContextNon3gppRequest + amfContextNon3gppRequest.UeId = &ueID + amfContextNon3gppRequest.PatchItem = patchItemReqArray + _, err = clientAPI.AMFNon3GPPAccessRegistrationDocumentApi.AmfContextNon3gpp(ctx, + &amfContextNon3gppRequest) if err != nil { - problemDetails := &models.ProblemDetails{ - Status: int32(resp.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), + 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 + } } + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) return } - defer func() { - if rspCloseErr := resp.Body.Close(); rspCloseErr != nil { - logger.UecmLog.Errorf("AmfContextNon3gpp response body cannot close: %+v", rspCloseErr) - } - }() c.Status(http.StatusNoContent) } @@ -446,11 +427,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()) @@ -458,21 +440,29 @@ 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 { + apiError, ok := err.(openapi.GenericOpenAPIError) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) + return } - }() + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) + c.JSON(int(problemDetails.Status), problemDetails) + return + } c.Status(http.StatusNoContent) } @@ -483,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 @@ -500,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 { @@ -510,23 +501,17 @@ func (p *Processor) RegistrationSmfRegistrationsProcedure( c.JSON(int(problemDetails.Status), problemDetails) return } - - resp, err := clientAPI.SMFRegistrationDocumentApi.CreateSmfContextNon3gpp(ctx, ueID, - pduID32, &createSmfContextNon3gppParamOpts) + _, err = clientAPI.SMFRegistrationDocumentApi.CreateOrUpdateSmfRegistration(ctx, &createSmfContext3gppRequest) if err != nil { - problemDetails := &models.ProblemDetails{ - Status: int32(resp.StatusCode), - Cause: err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails).Cause, - Detail: err.Error(), + apiError, ok := err.(openapi.GenericOpenAPIError) + if ok { + c.JSON(apiError.ErrorStatus, apiError.RawBody) + return } + problemDetails := openapi.ProblemDetailsSystemFailure(err.Error()) c.JSON(int(problemDetails.Status), problemDetails) 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) diff --git a/internal/sbi/server.go b/internal/sbi/server.go index 86a8e7f..fc17957 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" @@ -29,6 +28,7 @@ type ServerUdm interface { Consumer() *consumer.Consumer Processor() *processor.Processor + CancelContext() context.Context } type Server struct { @@ -61,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()) } @@ -160,19 +160,25 @@ 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) - genAuthDataPath := "/:supi/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() 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 +187,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,9 +205,54 @@ 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) + // 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, s.Context()) + }) + 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, s.Context()) + }) + 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, s.Context()) + }) + 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, s.Context()) + }) + 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, s.Context()) + }) + AddService(udmUEIDGroup, udmUEIDRoutes) + return router } diff --git a/internal/util/search_nf_service.go b/internal/util/search_nf_service.go index 7a75ed9..2dbe25b 100644 --- a/internal/util/search_nf_service.go +++ b/internal/util/search_nf_service.go @@ -6,11 +6,11 @@ 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 { - 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 { @@ -33,7 +33,7 @@ func SearchNFServiceUri(nfProfile models.NfProfile, serviceName models.ServiceNa } } - return + return nfUri } func getSbiUri(scheme models.UriScheme, ipv4Address string, port int32) (uri string) { diff --git a/pkg/factory/config.go b/pkg/factory/config.go index 3aeb89a..a09eb3b 100644 --- a/pkg/factory/config.go +++ b/pkg/factory/config.go @@ -29,12 +29,17 @@ 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" 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 { 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 diff --git a/pkg/service/init.go b/pkg/service/init.go index a844682..666dee2 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) + 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) + } } else { - logger.MainLog.Infof("Deregister from NRF successfully") + logger.InitLog.Infof("Deregister from NRF successfully") } + logger.MainLog.Infof("UDM SBI Server terminated") } @@ -163,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 } @@ -171,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 }