From 1d44f067c1ff5ff330e03003216660b485afe51d Mon Sep 17 00:00:00 2001 From: newb1er Date: Thu, 4 Jul 2024 12:37:57 +0800 Subject: [PATCH 01/18] chore: change openapi version --- go.mod | 13 ++++++++-- go.sum | 37 +++++++++++++++++++--------- internal/sbi/consumer/consumer.go | 6 ++--- internal/sbi/consumer/nrf_service.go | 4 +-- 4 files changed, 42 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index 0138ae7..58f7795 100644 --- a/go.mod +++ b/go.mod @@ -10,19 +10,21 @@ require ( github.com/gin-gonic/gin v1.9.1 github.com/google/uuid v1.3.0 github.com/pkg/errors v0.9.1 - github.com/sirupsen/logrus v1.8.1 + github.com/sirupsen/logrus v1.9.3 github.com/urfave/cli v1.22.5 go.uber.org/mock v0.4.0 gopkg.in/yaml.v2 v2.4.0 ) require ( - github.com/antihax/optional v1.0.0 // indirect github.com/bytedance/sonic v1.9.1 // indirect github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // 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 @@ -43,6 +45,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/crypto v0.21.0 // indirect golang.org/x/net v0.23.0 // indirect @@ -54,3 +61,5 @@ require ( gopkg.in/h2non/gock.v1 v1.1.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) + +replace github.com/free5gc/openapi => github.com/free5gc/openapi v1.0.9-0.20240424093716-bda9387bb300 diff --git a/go.sum b/go.sum index f48442c..6117b1b 100644 --- a/go.sum +++ b/go.sum @@ -33,8 +33,6 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9 dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -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= @@ -60,8 +58,10 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/evanphx/json-patch v0.5.2 h1:xVCHIVMUu1wtM/VkR9jVZ45N3FhZfYMMYGorLCR8P3k= github.com/evanphx/json-patch v0.5.2/go.mod h1:ZWS5hhDbVDyob71nXKNL0+PWn6ToqBHMikGIFbs31qQ= -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.20240424093716-bda9387bb300 h1:zFEzWpBN2gLaepRVVhVeosUcrux7tVk41+Q0XHNWJXg= +github.com/free5gc/openapi v1.0.9-0.20240424093716-bda9387bb300/go.mod h1:oy68rqnHakRLUCuEOXcis7/PWGBuil+UaXMeTBeYY8Y= github.com/free5gc/util v1.0.6 h1:dBt9drcXtYKE/cY5XuQcuffgsYclPIpIArhSeS6M+DQ= github.com/free5gc/util v1.0.6/go.mod h1:eSGN7POUM8LNTvg/E591XR6447a6/w1jFWGKNZPHcXw= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= @@ -73,6 +73,11 @@ github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SU github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +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= @@ -120,8 +125,9 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +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/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= @@ -181,12 +187,11 @@ github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0 github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= 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.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= @@ -194,8 +199,9 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/tim-ywliu/nested-logrus-formatter v1.3.2 h1:jugNJ2/CNCI79SxOJCOhwUHeN3O7/7/bj+ZRGOFlCSw= github.com/tim-ywliu/nested-logrus-formatter v1.3.2/go.mod h1:oGPmcxZB65j9Wo7mCnQKSrKEJtVDqyjD666SGmyStXI= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= @@ -212,6 +218,16 @@ go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +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= @@ -307,7 +323,6 @@ golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -324,6 +339,7 @@ golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 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.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= @@ -380,7 +396,6 @@ golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= diff --git a/internal/sbi/consumer/consumer.go b/internal/sbi/consumer/consumer.go index 780cf24..9336c9a 100644 --- a/internal/sbi/consumer/consumer.go +++ b/internal/sbi/consumer/consumer.go @@ -2,7 +2,7 @@ package consumer import ( "github.com/free5gc/nssf/pkg/app" - "github.com/free5gc/openapi/Nnrf_NFManagement" + "github.com/free5gc/openapi/nrf/NFManagement" ) type Consumer struct { @@ -12,10 +12,10 @@ type Consumer struct { } func NewConsumer(nssf app.NssfApp) *Consumer { - configuration := Nnrf_NFManagement.NewConfiguration() + configuration := NFManagement.NewConfiguration() configuration.SetBasePath(nssf.Context().NrfUri) nrfService := &NrfService{ - nrfNfMgmtClient: Nnrf_NFManagement.NewAPIClient(configuration), + nrfNfMgmtClient: NFManagement.NewAPIClient(configuration), } return &Consumer{ diff --git a/internal/sbi/consumer/nrf_service.go b/internal/sbi/consumer/nrf_service.go index 987be87..3248ae6 100644 --- a/internal/sbi/consumer/nrf_service.go +++ b/internal/sbi/consumer/nrf_service.go @@ -16,12 +16,12 @@ import ( nssf_context "github.com/free5gc/nssf/internal/context" "github.com/free5gc/nssf/internal/logger" "github.com/free5gc/openapi" - "github.com/free5gc/openapi/Nnrf_NFManagement" "github.com/free5gc/openapi/models" + "github.com/free5gc/openapi/nrf/NFManagement" ) type NrfService struct { - nrfNfMgmtClient *Nnrf_NFManagement.APIClient + nrfNfMgmtClient *NFManagement.APIClient // NOTE: No mutex needed. One connection at a time. } From 924404db420230797de3f64013e03a3965503264 Mon Sep 17 00:00:00 2001 From: newb1er Date: Thu, 4 Jul 2024 13:06:10 +0800 Subject: [PATCH 02/18] chore: update consumer r17 models --- internal/context/context.go | 18 ++--- internal/sbi/consumer/nrf_service.go | 100 ++++++++++++--------------- 2 files changed, 54 insertions(+), 64 deletions(-) diff --git a/internal/context/context.go b/internal/context/context.go index 9f7f624..038c29d 100644 --- a/internal/context/context.go +++ b/internal/context/context.go @@ -59,7 +59,7 @@ type NSSFContext struct { // HttpIpv6Address string BindingIPv4 string SBIPort int - NfService map[models.ServiceName]models.NfService + NfService map[models.ServiceName]models.NrfNfManagementNfService NrfUri string NrfCertPem string SupportedPlmnList []models.PlmnId @@ -102,15 +102,15 @@ func InitNssfContext() { } func initNfService(serviceName []models.ServiceName, version string) ( - nfService map[models.ServiceName]models.NfService, + nfService map[models.ServiceName]models.NrfNfManagementNfService, ) { versionUri := "v" + strings.Split(version, ".")[0] - nfService = make(map[models.ServiceName]models.NfService) + nfService = make(map[models.ServiceName]models.NrfNfManagementNfService) for idx, name := range serviceName { - nfService[name] = models.NfService{ + nfService[name] = models.NrfNfManagementNfService{ ServiceInstanceId: strconv.Itoa(idx), ServiceName: name, - Versions: &[]models.NfServiceVersion{ + Versions: []models.NfServiceVersion{ { ApiFullVersion: version, ApiVersionInUri: versionUri, @@ -119,10 +119,10 @@ func initNfService(serviceName []models.ServiceName, version string) ( Scheme: nssfContext.UriScheme, NfServiceStatus: models.NfServiceStatus_REGISTERED, ApiPrefix: GetIpv4Uri(), - IpEndPoints: &[]models.IpEndPoint{ + IpEndPoints: []models.IpEndPoint{ { Ipv4Address: nssfContext.RegisterIPv4, - Transport: models.TransportProtocol_TCP, + Transport: models.NrfNfManagementTransportProtocol_TCP, Port: int32(nssfContext.SBIPort), }, }, @@ -140,13 +140,13 @@ func GetSelf() *NSSFContext { return &nssfContext } -func (c *NSSFContext) GetTokenCtx(serviceName models.ServiceName, targetNF models.NfType) ( +func (c *NSSFContext) 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_NSSF, targetNF, + return oauth.GetTokenCtx(models.NrfNfManagementNfType_NSSF, targetNF, c.NfId, c.NrfUri, string(serviceName)) } diff --git a/internal/sbi/consumer/nrf_service.go b/internal/sbi/consumer/nrf_service.go index 3248ae6..eb3b2bb 100644 --- a/internal/sbi/consumer/nrf_service.go +++ b/internal/sbi/consumer/nrf_service.go @@ -9,7 +9,6 @@ package consumer import ( "context" "fmt" - "net/http" "strings" "time" @@ -25,18 +24,20 @@ type NrfService struct { // NOTE: No mutex needed. One connection at a time. } -func (ns *NrfService) buildNFProfile(context *nssf_context.NSSFContext) (profile models.NfProfile, err error) { +func (ns *NrfService) buildNFProfile(context *nssf_context.NSSFContext) ( + profile models.NrfNfManagementNfProfile, err error, +) { profile.NfInstanceId = context.NfId - profile.NfType = models.NfType_NSSF - profile.NfStatus = models.NfStatus_REGISTERED - profile.PlmnList = &context.SupportedPlmnList + profile.NfType = models.NrfNfManagementNfType_NSSF + profile.NfStatus = models.NrfNfManagementNfStatus_REGISTERED + profile.PlmnList = context.SupportedPlmnList profile.Ipv4Addresses = []string{context.RegisterIPv4} - var services []models.NfService + var services []models.NrfNfManagementNfService for _, nfService := range context.NfService { services = append(services, nfService) } if len(services) > 0 { - profile.NfServices = &services + profile.NfServices = services } return } @@ -51,7 +52,7 @@ func (ns *NrfService) SendRegisterNFInstance(ctx context.Context, nssfCtx *nssf_ } apiClient := ns.nrfNfMgmtClient - var res *http.Response + var res *NFManagement.RegisterNFInstanceResponse var nf models.NfProfile finish := false for !finish { @@ -60,7 +61,12 @@ func (ns *NrfService) SendRegisterNFInstance(ctx context.Context, nssfCtx *nssf_ return "", "", fmt.Errorf("context done") default: - nf, res, err = apiClient.NFInstanceIDDocumentApi.RegisterNFInstance(ctx, nfInstanceId, profile) + req := &NFManagement.RegisterNFInstanceRequest{ + NfInstanceID: &nfInstanceId, + NrfNfManagementNfProfile: &profile, + } + + res, err = apiClient.NFInstanceIDDocumentApi.RegisterNFInstance(ctx, req) if err != nil || res == nil { // TODO : add log logger.ConsumerLog.Errorf("NSSF register to NRF Error[%s]", err.Error()) @@ -68,37 +74,24 @@ func (ns *NrfService) SendRegisterNFInstance(ctx context.Context, nssfCtx *nssf_ time.Sleep(retryInterval) continue } - defer func() { - if resCloseErr := res.Body.Close(); resCloseErr != nil { - logger.ConsumerLog.Errorf("NFInstanceIDDocumentApi response body cannot close: %+v", resCloseErr) - } - }() - status := res.StatusCode - if status == http.StatusOK { - // NFUpdate - finish = true - } else if status == http.StatusCreated { - // NFRegister - resourceUri := res.Header.Get("Location") - resourceNrfUri, _, _ = strings.Cut(resourceUri, "/nnrf-nfm/") - retrieveNfInstanceId = resourceUri[strings.LastIndex(resourceUri, "/")+1:] - - oauth2 := false - if nf.CustomInfo != nil { - v, ok := nf.CustomInfo["oauth2"].(bool) - if ok { - oauth2 = v - logger.MainLog.Infoln("OAuth2 setting receive from NRF:", oauth2) - } - } - nssf_context.GetSelf().OAuth2Required = oauth2 - if oauth2 && nssf_context.GetSelf().NrfCertPem == "" { - logger.CfgLog.Error("OAuth2 enable but no nrfCertPem provided in config.") + + resourceUri := res.Location + resourceNrfUri, _, _ = strings.Cut(resourceUri, "/nnrf-nfm/") + retrieveNfInstanceId = resourceUri[strings.LastIndex(resourceUri, "/")+1:] + + oauth2 := false + if nf.CustomInfo != nil { + v, ok := nf.CustomInfo["oauth2"].(bool) + if ok { + oauth2 = v + logger.MainLog.Infoln("OAuth2 setting receive from NRF:", oauth2) } - finish = true - } else { - fmt.Println("NRF return wrong status code", status) } + nssf_context.GetSelf().OAuth2Required = oauth2 + if oauth2 && nssf_context.GetSelf().NrfCertPem == "" { + logger.CfgLog.Error("OAuth2 enable but no nrfCertPem provided in config.") + } + finish = true } } return resourceNrfUri, retrieveNfInstanceId, err @@ -109,30 +102,27 @@ func (ns *NrfService) SendDeregisterNFInstance(nfInstanceId string) (*models.Pro var err error - ctx, pd, err := nssf_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_NFM, models.NfType_NRF) + ctx, pd, err := nssf_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_NFM, models.NrfNfManagementNfType_NRF) if err != nil { return pd, err } client := ns.nrfNfMgmtClient - var res *http.Response + req := &NFManagement.DeregisterNFInstanceRequest{ + NfInstanceID: &nfInstanceId, + } - res, err = client.NFInstanceIDDocumentApi.DeregisterNFInstance(ctx, nfInstanceId) - if err == nil { - return nil, err - } else if res != nil { - defer func() { - if resCloseErr := res.Body.Close(); resCloseErr != nil { - logger.ConsumerLog.Errorf("NFInstanceIDDocumentApi response body cannot close: %+v", resCloseErr) - } - }() - if res.Status != err.Error() { - return nil, err + _, err = client.NFInstanceIDDocumentApi.DeregisterNFInstance(ctx, req) + if err != nil { + if apiErr, ok := err.(openapi.GenericOpenAPIError); ok { + // API error + return apiErr.Model().(*models.ProblemDetails), err } - problem := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) - return &problem, err - } else { - return nil, openapi.ReportError("server no response") + + // Golang error + return nil, err } + + return nil, nil } From c4e0ac74bff7a562399d87e669183218c6c6f841 Mon Sep 17 00:00:00 2001 From: newb1er Date: Thu, 4 Jul 2024 13:43:21 +0800 Subject: [PATCH 03/18] chore: add support to new r17 model "ExtSnssai" --- internal/util/util.go | 76 ++++++++++++++++++++++++++++++------------- pkg/factory/config.go | 2 +- 2 files changed, 54 insertions(+), 24 deletions(-) diff --git a/internal/util/util.go b/internal/util/util.go index 0f76e8f..789946e 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -8,6 +8,7 @@ import ( "encoding/json" "fmt" "reflect" + "strings" "github.com/free5gc/nssf/internal/logger" "github.com/free5gc/nssf/pkg/factory" @@ -38,6 +39,15 @@ func Contain(target interface{}, slice interface{}) bool { return false } +func SnssaiEqualFold(s models.ExtSnssai, t models.Snssai) bool { + // TODO: Compare SdRanges and WildcardSd + if s.Sst == t.Sst && strings.EqualFold(s.Sd, t.Sd) { + return true + } + + return false +} + // Check whether UE's Home PLMN is configured/supported func CheckSupportedHplmn(homePlmnId models.PlmnId) bool { factory.NssfConfig.RLock() @@ -91,31 +101,55 @@ func CheckSupportedSnssaiInPlmn(snssai models.Snssai, plmnId models.PlmnId) bool } // Check whether S-NSSAIs in NSSAI are supported or not in PLMN -func CheckSupportedNssaiInPlmn(nssai []models.Snssai, plmnId models.PlmnId) bool { +func CheckSupportedNssaiInPlmn(nssai any, plmnId models.PlmnId) bool { factory.NssfConfig.RLock() defer factory.NssfConfig.RUnlock() for _, supportedNssaiInPlmn := range factory.NssfConfig.Configuration.SupportedNssaiInPlmnList { if *supportedNssaiInPlmn.PlmnId == plmnId { - for _, snssai := range nssai { - // Standard S-NSSAIs are supposed to be supported - // If not, disable following check and be sure to add supported standard S-NSSAI(s) in configuration - if CheckStandardSnssai(snssai) { - continue - } + if n, ok := nssai.([]models.ExtSnssai); ok { + for _, snssai := range n { + // Standard S-NSSAIs are supposed to be supported + // If not, disable following check and be sure to add supported standard S-NSSAI(s) in configuration + if CheckStandardSnssai(models.Snssai{Sst: snssai.Sst, Sd: snssai.Sd}) { + continue + } - hitSupportedNssai := false - for _, supportedSnssai := range supportedNssaiInPlmn.SupportedSnssaiList { - if openapi.SnssaiEqualFold(snssai, supportedSnssai) { - hitSupportedNssai = true - break + hitSupportedNssai := false + for _, supportedSnssai := range supportedNssaiInPlmn.SupportedSnssaiList { + if SnssaiEqualFold(snssai, supportedSnssai) { + hitSupportedNssai = true + break + } + } + + if !hitSupportedNssai { + return false } } + return true + } else if n, ok := nssai.([]models.Snssai); ok { + for _, snssai := range n { + if CheckStandardSnssai(snssai) { + continue + } + + hitSupportedNssai := false + for _, supportedSnssai := range supportedNssaiInPlmn.SupportedSnssaiList { + if openapi.SnssaiEqualFold(snssai, supportedSnssai) { + hitSupportedNssai = true + break + } + } - if !hitSupportedNssai { - return false + if !hitSupportedNssai { + return false + } } + return true + } else { + logger.UtilLog.Warnf("Unsupported type of NSSAI: %+v", nssai) + return false } - return true } } logger.UtilLog.Warnf("No supported S-NSSAI list of PLMNID %+v in NSSF configuration", plmnId) @@ -129,9 +163,7 @@ func CheckSupportedSnssaiInTa(snssai models.Snssai, tai models.Tai) bool { for _, taConfig := range factory.NssfConfig.Configuration.TaList { if reflect.DeepEqual(*taConfig.Tai, tai) { for _, supportedSnssai := range taConfig.SupportedSnssaiList { - if openapi.SnssaiEqualFold(supportedSnssai, snssai) { - return true - } + SnssaiEqualFold(supportedSnssai, snssai) } return false } @@ -203,11 +235,9 @@ func CheckStandardSnssai(snssai models.Snssai) bool { } // Check whether the NSSAI contains the specific S-NSSAI -func CheckSnssaiInNssai(targetSnssai models.Snssai, nssai []models.Snssai) bool { +func CheckSnssaiInNssai(targetSnssai models.Snssai, nssai []models.ExtSnssai) bool { for _, snssai := range nssai { - if openapi.SnssaiEqualFold(snssai, targetSnssai) { - return true - } + SnssaiEqualFold(snssai, targetSnssai) } return false } @@ -351,7 +381,7 @@ func AuthorizeOfTaListFromConfig(taiList []models.Tai) []models.AuthorizedNssaiA } // Get supported S-NSSAI list of the given NF ID and TAI from configuration -func GetSupportedSnssaiListFromConfig(nfId string, tai models.Tai) []models.Snssai { +func GetSupportedSnssaiListFromConfig(nfId string, tai models.Tai) []models.ExtSnssai { for _, amfConfig := range factory.NssfConfig.Configuration.AmfList { if amfConfig.NfId == nfId { for _, supportedNssaiAvailabilityData := range amfConfig.SupportedNssaiAvailabilityData { diff --git a/pkg/factory/config.go b/pkg/factory/config.go index 83e6e5e..9c81ac6 100644 --- a/pkg/factory/config.go +++ b/pkg/factory/config.go @@ -168,7 +168,7 @@ type AmfConfig struct { type TaConfig struct { Tai *models.Tai `yaml:"tai"` AccessType *models.AccessType `yaml:"accessType"` - SupportedSnssaiList []models.Snssai `yaml:"supportedSnssaiList"` + SupportedSnssaiList []models.ExtSnssai `yaml:"supportedSnssaiList"` RestrictedSnssaiList []models.RestrictedSnssai `yaml:"restrictedSnssaiList,omitempty"` } From aab3ab5d121a514a2c9f0a43c31fc9258cf8f5b9 Mon Sep 17 00:00:00 2001 From: newb1er Date: Thu, 4 Jul 2024 14:02:14 +0800 Subject: [PATCH 04/18] feat: two new nssai availability routes --- internal/sbi/api_nssaiavailability.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/internal/sbi/api_nssaiavailability.go b/internal/sbi/api_nssaiavailability.go index a037c28..8772450 100644 --- a/internal/sbi/api_nssaiavailability.go +++ b/internal/sbi/api_nssaiavailability.go @@ -62,6 +62,20 @@ func (s *Server) getNssaiAvailabilityRoutes() []Route { "/nssai-availability/subscriptions", s.NSSAIAvailabilityPost, }, + + { + "NSSAIAvailabilityPatchSubscriptions", + http.MethodPatch, + "/nssai-availability/subscriptions/:subscriptionId", + s.NSSAIAvailabilitySubscriptionPatch, + }, + + { + "NSSAIAvailabilityDiscoverOptions", + http.MethodOptions, + "/nssai-availability", + s.NSSAIAvailabilityOptions, + }, } } @@ -177,6 +191,10 @@ func (s *Server) NSSAIAvailabilityPut(c *gin.Context) { s.Processor().NssaiAvailabilityNfInstanceUpdate(c, nssaiAvailabilityInfo, nfId) } +func (s *Server) NSSAIAvailabilitySubscriptionPatch(c *gin.Context) { + c.Status(http.StatusNotImplemented) +} + func (s *Server) NSSAIAvailabilityPost(c *gin.Context) { var createData models.NssfEventSubscriptionCreateData @@ -211,6 +229,10 @@ func (s *Server) NSSAIAvailabilityPost(c *gin.Context) { s.Processor().NssaiAvailabilitySubscriptionCreate(c, createData) } +func (s *Server) NSSAIAvailabilityOptions(c *gin.Context) { + c.Status(http.StatusNotImplemented) +} + func (s *Server) NSSAIAvailabilityUnsubscribeDelete(c *gin.Context) { // Due to conflict of route matching, 'subscriptions' in the route is replaced with the existing wildcard ':nfId' nfID := c.Param("nfId") From 32a3b8d958f9c1f2d9afe20f16d7b294189ab02a Mon Sep 17 00:00:00 2001 From: newb1er Date: Sun, 7 Jul 2024 15:54:56 +0800 Subject: [PATCH 05/18] feat(nsselection): validate query string using gin binding & upgrade API query fields --- go.mod | 2 +- internal/sbi/api_nsselection.go | 51 +++++++++- .../nsselection_network_slice_information.go | 97 +++++-------------- 3 files changed, 76 insertions(+), 74 deletions(-) diff --git a/go.mod b/go.mod index 58f7795..83e7fda 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/free5gc/openapi v1.0.8 github.com/free5gc/util v1.0.6 github.com/gin-gonic/gin v1.9.1 + github.com/go-playground/validator/v10 v10.14.0 github.com/google/uuid v1.3.0 github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.9.3 @@ -27,7 +28,6 @@ require ( 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.1+incompatible // indirect github.com/golang/protobuf v1.5.0 // indirect diff --git a/internal/sbi/api_nsselection.go b/internal/sbi/api_nsselection.go index 2d3fd51..65c92c6 100644 --- a/internal/sbi/api_nsselection.go +++ b/internal/sbi/api_nsselection.go @@ -1,12 +1,17 @@ package sbi import ( + "fmt" "net/http" "strings" "github.com/gin-gonic/gin" + "github.com/go-playground/validator/v10" "github.com/free5gc/nssf/internal/logger" + "github.com/free5gc/nssf/internal/sbi/processor" + "github.com/free5gc/nssf/internal/util" + "github.com/free5gc/openapi/models" ) func (s *Server) getNsSelectionRoutes() []Route { @@ -29,9 +34,53 @@ func (s *Server) getNsSelectionRoutes() []Route { } } +func BindErrorInvalidParams(err error) []models.InvalidParam { + var invalidParams []models.InvalidParam + if errs, ok := err.(validator.ValidationErrors); ok { + for _, e := range errs { + ip := models.InvalidParam{ + Param: e.Field(), + } + + switch e.Tag() { + case "required": + ip.Reason = fmt.Sprintf("The `%s` field is required.", e.Field()) + case "oneof": + ip.Reason = fmt.Sprintf("The `%s` field must be one of '%s'.", e.Field(), e.Param()) + case "required_with": + ip.Reason = fmt.Sprintf("The `%s` field is required when `%s` is present.", e.Field(), e.Param()) + case "required_without": + ip.Reason = fmt.Sprintf("The `%s` field is required when `%s` is not present.", e.Field(), e.Param()) + default: + ip.Reason = fmt.Sprintf("Failed on the `%s` tag.", e.Tag()) + } + + invalidParams = append(invalidParams, ip) + } + } else { + logger.NsselLog.Errorf("Unknown error type: %+v", err) + } + + return invalidParams +} + func (s *Server) NetworkSliceInformationGet(c *gin.Context) { logger.NsselLog.Infof("Handle NSSelectionGet") - query := c.Request.URL.Query() + var query processor.NetworkSliceInformationGetQuery + if err := c.ShouldBindQuery(&query); err != nil { + logger.NsselLog.Errorf("BindQuery failed: %+v", err) + problemDetail := &models.ProblemDetails{ + Title: "Malformed Request", + Status: http.StatusBadRequest, + Detail: err.Error(), + Instance: "", + InvalidParams: BindErrorInvalidParams(err), + } + util.GinProblemJson(c, problemDetail) + return + } + + // query := c.Request.URL.Query() s.Processor().NSSelectionSliceInformationGet(c, query) } diff --git a/internal/sbi/processor/nsselection_network_slice_information.go b/internal/sbi/processor/nsselection_network_slice_information.go index 5ebb584..949bceb 100644 --- a/internal/sbi/processor/nsselection_network_slice_information.go +++ b/internal/sbi/processor/nsselection_network_slice_information.go @@ -10,75 +10,36 @@ package processor import ( - "encoding/json" "fmt" "math/rand" "net/http" - "net/url" - "strings" "github.com/gin-gonic/gin" "github.com/free5gc/nssf/internal/logger" - "github.com/free5gc/nssf/internal/plugin" "github.com/free5gc/nssf/internal/util" "github.com/free5gc/openapi" "github.com/free5gc/openapi/models" ) -// Parse NSSelectionGet query parameter -func parseQueryParameter(query url.Values) (plugin.NsselectionQueryParameter, error) { - var ( - param plugin.NsselectionQueryParameter - err error - ) +type NetworkSliceInformationGetQuery struct { + // nolint: lll + NfType models.NfType `form:"nf-type" binding:"required,oneof=NRF UDM AMF SMF AUSF NEF PCF SMSF NSSF UDR LMF GMLC 5G_EIR SEPP UPF N3IWF AF UDSF BSF CHF NWDAF PCSCF CBCF HSS UCMF SOR_AF SPAF MME SCSAS SCEF SCP NSSAAF ICSCF SCSCF DRA IMS_AS AANF 5G_DDNMF NSACF MFAF EASDF DCCF MB_SMF TSCTSF ADRF GBA_BSF CEF MB_UPF NSWOF PKMF MNPF SMS_GMSC SMS_IWMSC MBSF MBSTF PANF IP_SM_GW SMS_ROUTER"` - if query.Get("nf-type") != "" { - param.NfType = new(models.NfType) - *param.NfType = models.NfType(query.Get("nf-type")) - } + NfId string `form:"nf-id" binding:"required,uuid"` - param.NfId = query.Get("nf-id") + // nolint: lll + SliceInfoRequestForRegistration *models.SliceInfoForRegistration `form:"sliceInfoRequestForRegistration" binding:"omitempty"` - if query.Get("slice-info-request-for-registration") != "" { - param.SliceInfoRequestForRegistration = new(models.SliceInfoForRegistration) - err = json.NewDecoder(strings.NewReader( - query.Get("slice-info-request-for-registration"))).Decode(param.SliceInfoRequestForRegistration) - if err != nil { - return param, err - } - } + // nolint: lll + SliceInfoRequestForPduSession *models.SliceInfoForPduSession `form:"sliceInfoRequestForPduSession" binding:"omitempty"` - if query.Get("slice-info-request-for-pdu-session") != "" { - param.SliceInfoRequestForPduSession = new(models.SliceInfoForPduSession) - err = json.NewDecoder(strings.NewReader( - query.Get("slice-info-request-for-pdu-session"))).Decode(param.SliceInfoRequestForPduSession) - if err != nil { - return param, err - } - } - - if query.Get("home-plmn-id") != "" { - param.HomePlmnId = new(models.PlmnId) - err = json.NewDecoder(strings.NewReader(query.Get("home-plmn-id"))).Decode(param.HomePlmnId) - if err != nil { - return param, err - } - } - - if query.Get("tai") != "" { - param.Tai = new(models.Tai) - err = json.NewDecoder(strings.NewReader(query.Get("tai"))).Decode(param.Tai) - if err != nil { - return param, err - } - } + // nolint: lll + SliceInfoRequestForUeConfigurationUpdate *models.SliceInfoForUeConfigurationUpdate `form:"sliceInfoRequestForUeConfigurationUpdate" binding:"omitempty"` - if query.Get("supported-features") != "" { - param.SupportedFeatures = query.Get("supported-features") - } - - return param, err + HomePlmnId *models.PlmnId `form:"home-plmn-id" binding:"required_without=Tai,omitempty"` + Tai *models.Tai `form:"tai" binding:"required_without=HomePlmnId,omitempty"` + SupportedFeatures string `form:"supportedFeatures"` } // Check if the NF service consumer is authorized @@ -92,7 +53,10 @@ func checkNfServiceConsumer(nfType models.NfType) error { return nil } -func (p *Processor) NSSelectionSliceInformationGet(c *gin.Context, query url.Values) { +func (p *Processor) NSSelectionSliceInformationGet( + c *gin.Context, + param NetworkSliceInformationGetQuery, +) { var ( status int response *models.AuthorizedNetworkSliceInfo @@ -103,21 +67,8 @@ func (p *Processor) NSSelectionSliceInformationGet(c *gin.Context, query url.Val // if the consumer has sent too many requests in a configured amount of time // TODO: Check URI length and response with ProblemDetails of 414 URI Too Long if URI is too long - // Parse query parameter - param, err := parseQueryParameter(query) - if err != nil { - // status = http.StatusBadRequest - problemDetails = &models.ProblemDetails{ - Title: util.MALFORMED_REQUEST, - Status: http.StatusBadRequest, - Detail: "[Query Parameter] " + err.Error(), - } - util.GinProblemJson(c, problemDetails) - return - } - // Check permission of NF service consumer - err = checkNfServiceConsumer(*param.NfType) + err := checkNfServiceConsumer(param.NfType) if err != nil { // status = http.StatusForbidden problemDetails = &models.ProblemDetails{ @@ -157,6 +108,8 @@ func (p *Processor) NSSelectionSliceInformationGet(c *gin.Context, query url.Val status, response, problemDetails = nsselectionForPduSession(param) } + // TODO: Handle `SliceInfoRequestForUeConfigurationUpdate` + if problemDetails != nil { util.GinProblemJson(c, problemDetails) return @@ -175,7 +128,7 @@ func (p *Processor) NSSelectionSliceInformationGet(c *gin.Context, query url.Val // Set Allowed NSSAI with Subscribed S-NSSAI(s) which are marked as default S-NSSAI(s) func useDefaultSubscribedSnssai( - param plugin.NsselectionQueryParameter, authorizedNetworkSliceInfo *models.AuthorizedNetworkSliceInfo, + param NetworkSliceInformationGetQuery, authorizedNetworkSliceInfo *models.AuthorizedNetworkSliceInfo, ) { var mappingOfSnssai []models.MappingOfSnssai if param.HomePlmnId != nil { @@ -243,7 +196,7 @@ func useDefaultSubscribedSnssai( // Set Configured NSSAI with S-NSSAI(s) in Requested NSSAI which are marked as Default Configured NSSAI func useDefaultConfiguredNssai( - param plugin.NsselectionQueryParameter, authorizedNetworkSliceInfo *models.AuthorizedNetworkSliceInfo, + param NetworkSliceInformationGetQuery, authorizedNetworkSliceInfo *models.AuthorizedNetworkSliceInfo, ) { for _, requestedSnssai := range param.SliceInfoRequestForRegistration.RequestedNssai { // Check whether the Default Configured S-NSSAI is standard, which could be commonly decided by all roaming partners @@ -271,7 +224,7 @@ func useDefaultConfiguredNssai( // Set Configured NSSAI with Subscribed S-NSSAI(s) func setConfiguredNssai( - param plugin.NsselectionQueryParameter, authorizedNetworkSliceInfo *models.AuthorizedNetworkSliceInfo, + param NetworkSliceInformationGetQuery, authorizedNetworkSliceInfo *models.AuthorizedNetworkSliceInfo, ) { var mappingOfSnssai []models.MappingOfSnssai if param.HomePlmnId != nil { @@ -319,7 +272,7 @@ func setConfiguredNssai( // Network slice selection for registration // The function is executed when the IE, `slice-info-request-for-registration`, is provided in query parameters -func nsselectionForRegistration(param plugin.NsselectionQueryParameter) ( +func nsselectionForRegistration(param NetworkSliceInformationGetQuery) ( int, *models.AuthorizedNetworkSliceInfo, *models.ProblemDetails, ) { authorizedNetworkSliceInfo := &models.AuthorizedNetworkSliceInfo{} @@ -607,7 +560,7 @@ func selectNsiInformation(nsiInformationList []models.NsiInformation) models.Nsi // Network slice selection for PDU session // The function is executed when the IE, `slice-info-for-pdu-session`, is provided in query parameters -func nsselectionForPduSession(param plugin.NsselectionQueryParameter) ( +func nsselectionForPduSession(param NetworkSliceInformationGetQuery) ( int, *models.AuthorizedNetworkSliceInfo, *models.ProblemDetails, ) { var status int From e093e2a76c3f5fc8fb02b4e666b994fd11f91955 Mon Sep 17 00:00:00 2001 From: newb1er Date: Sun, 7 Jul 2024 15:56:58 +0800 Subject: [PATCH 06/18] refactor: move `bindInvalidParams` function into util package --- internal/sbi/api_nsselection.go | 34 +--------------------------- internal/util/error_response.go | 39 +++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 33 deletions(-) create mode 100644 internal/util/error_response.go diff --git a/internal/sbi/api_nsselection.go b/internal/sbi/api_nsselection.go index 65c92c6..47cc197 100644 --- a/internal/sbi/api_nsselection.go +++ b/internal/sbi/api_nsselection.go @@ -1,12 +1,10 @@ package sbi import ( - "fmt" "net/http" "strings" "github.com/gin-gonic/gin" - "github.com/go-playground/validator/v10" "github.com/free5gc/nssf/internal/logger" "github.com/free5gc/nssf/internal/sbi/processor" @@ -34,36 +32,6 @@ func (s *Server) getNsSelectionRoutes() []Route { } } -func BindErrorInvalidParams(err error) []models.InvalidParam { - var invalidParams []models.InvalidParam - if errs, ok := err.(validator.ValidationErrors); ok { - for _, e := range errs { - ip := models.InvalidParam{ - Param: e.Field(), - } - - switch e.Tag() { - case "required": - ip.Reason = fmt.Sprintf("The `%s` field is required.", e.Field()) - case "oneof": - ip.Reason = fmt.Sprintf("The `%s` field must be one of '%s'.", e.Field(), e.Param()) - case "required_with": - ip.Reason = fmt.Sprintf("The `%s` field is required when `%s` is present.", e.Field(), e.Param()) - case "required_without": - ip.Reason = fmt.Sprintf("The `%s` field is required when `%s` is not present.", e.Field(), e.Param()) - default: - ip.Reason = fmt.Sprintf("Failed on the `%s` tag.", e.Tag()) - } - - invalidParams = append(invalidParams, ip) - } - } else { - logger.NsselLog.Errorf("Unknown error type: %+v", err) - } - - return invalidParams -} - func (s *Server) NetworkSliceInformationGet(c *gin.Context) { logger.NsselLog.Infof("Handle NSSelectionGet") @@ -75,7 +43,7 @@ func (s *Server) NetworkSliceInformationGet(c *gin.Context) { Status: http.StatusBadRequest, Detail: err.Error(), Instance: "", - InvalidParams: BindErrorInvalidParams(err), + InvalidParams: util.BindErrorInvalidParamsMessages(err), } util.GinProblemJson(c, problemDetail) return diff --git a/internal/util/error_response.go b/internal/util/error_response.go new file mode 100644 index 0000000..b129e2b --- /dev/null +++ b/internal/util/error_response.go @@ -0,0 +1,39 @@ +package util + +import ( + "fmt" + + "github.com/free5gc/nssf/internal/logger" + "github.com/free5gc/openapi/models" + "github.com/go-playground/validator/v10" +) + +func BindErrorInvalidParamsMessages(err error) []models.InvalidParam { + var invalidParams []models.InvalidParam + if errs, ok := err.(validator.ValidationErrors); ok { + for _, e := range errs { + ip := models.InvalidParam{ + Param: e.Field(), + } + + switch e.Tag() { + case "required": + ip.Reason = fmt.Sprintf("The `%s` field is required.", e.Field()) + case "oneof": + ip.Reason = fmt.Sprintf("The `%s` field must be one of '%s'.", e.Field(), e.Param()) + case "required_with": + ip.Reason = fmt.Sprintf("The `%s` field is required when `%s` is present.", e.Field(), e.Param()) + case "required_without": + ip.Reason = fmt.Sprintf("The `%s` field is required when `%s` is not present.", e.Field(), e.Param()) + default: + ip.Reason = fmt.Sprintf("Failed on the `%s` tag.", e.Tag()) + } + + invalidParams = append(invalidParams, ip) + } + } else { + logger.NsselLog.Errorf("Unknown error type: %+v", err) + } + + return invalidParams +} From 06945f1167af7a23649cbadfacdfbfddb2d9e010 Mon Sep 17 00:00:00 2001 From: newb1er Date: Sun, 7 Jul 2024 16:22:25 +0800 Subject: [PATCH 07/18] feat(nssaiavailability): validate nfid on put S-NSSAIs --- internal/sbi/api_nssaiavailability.go | 18 ++++++++++++------ internal/util/error_response.go | 2 ++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/internal/sbi/api_nssaiavailability.go b/internal/sbi/api_nssaiavailability.go index 8772450..42d9e90 100644 --- a/internal/sbi/api_nssaiavailability.go +++ b/internal/sbi/api_nssaiavailability.go @@ -148,17 +148,23 @@ func (s *Server) NSSAIAvailabilityPatch(c *gin.Context) { s.Processor().NssaiAvailabilityNfInstancePatch(c, patchDocument, nfId) } +type NssaiAvailabilityPutParams struct { + NfId string `uri:"nfId" binding:"required,uuid"` +} + // NSSAIAvailabilityPut - Updates/replaces the NSSF // with the S-NSSAIs the NF service consumer (e.g AMF) supports per TA func (s *Server) NSSAIAvailabilityPut(c *gin.Context) { logger.NssaiavailLog.Infof("Handle NSSAIAvailabilityPut") - nfId := c.Params.ByName("nfId") - - if nfId == "" { + // nfId := c.Params.ByName("nfId") + var params NssaiAvailabilityPutParams + if err := c.ShouldBindUri(¶ms); err != nil { problemDetails := &models.ProblemDetails{ - Status: http.StatusBadRequest, - Cause: "UNSPECIFIED", // TODO: Check if this is the correct cause + Title: "Malformed Request", + Status: http.StatusBadRequest, + Cause: "MALFORMED_REQUEST", + InvalidParams: util.BindErrorInvalidParamsMessages(err), } util.GinProblemJson(c, problemDetails) @@ -188,7 +194,7 @@ func (s *Server) NSSAIAvailabilityPut(c *gin.Context) { return } - s.Processor().NssaiAvailabilityNfInstanceUpdate(c, nssaiAvailabilityInfo, nfId) + s.Processor().NssaiAvailabilityNfInstanceUpdate(c, nssaiAvailabilityInfo, params.NfId) } func (s *Server) NSSAIAvailabilitySubscriptionPatch(c *gin.Context) { diff --git a/internal/util/error_response.go b/internal/util/error_response.go index b129e2b..9536ecd 100644 --- a/internal/util/error_response.go +++ b/internal/util/error_response.go @@ -25,6 +25,8 @@ func BindErrorInvalidParamsMessages(err error) []models.InvalidParam { ip.Reason = fmt.Sprintf("The `%s` field is required when `%s` is present.", e.Field(), e.Param()) case "required_without": ip.Reason = fmt.Sprintf("The `%s` field is required when `%s` is not present.", e.Field(), e.Param()) + case "uuid": + ip.Reason = fmt.Sprintf("The `%s` field must be a valid UUID.", e.Field()) default: ip.Reason = fmt.Sprintf("Failed on the `%s` tag.", e.Tag()) } From c6b7daa0bccecefac3a46e698208041c4d209780 Mon Sep 17 00:00:00 2001 From: newb1er Date: Fri, 12 Jul 2024 10:23:03 +0800 Subject: [PATCH 08/18] fix: linter complain --- internal/util/error_response.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/util/error_response.go b/internal/util/error_response.go index 9536ecd..2b6f0cb 100644 --- a/internal/util/error_response.go +++ b/internal/util/error_response.go @@ -3,9 +3,10 @@ package util import ( "fmt" + "github.com/go-playground/validator/v10" + "github.com/free5gc/nssf/internal/logger" "github.com/free5gc/openapi/models" - "github.com/go-playground/validator/v10" ) func BindErrorInvalidParamsMessages(err error) []models.InvalidParam { From f4eb2e86a83644e5e610e59e35ab4744e9396c7f Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 10 Sep 2024 09:17:49 +0000 Subject: [PATCH 09/18] chore: update openapi version hash --- go.mod | 8 +++----- go.sum | 12 ++++++------ internal/plugin/nsselection_query_parameter.go | 2 +- internal/sbi/consumer/nrf_service.go | 2 +- .../nsselection_network_slice_information.go | 6 +++--- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/go.mod b/go.mod index 83e7fda..f8eb64e 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.21 require ( github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d github.com/evanphx/json-patch v0.5.2 - github.com/free5gc/openapi v1.0.8 + github.com/free5gc/openapi v1.0.9-0.20240823100026-6a9f667e914f github.com/free5gc/util v1.0.6 github.com/gin-gonic/gin v1.9.1 github.com/go-playground/validator/v10 v10.14.0 @@ -29,8 +29,9 @@ require ( github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/goccy/go-json v0.10.2 // indirect - github.com/golang-jwt/jwt v3.2.1+incompatible // indirect + github.com/golang-jwt/jwt/v5 v5.2.1 // indirect github.com/golang/protobuf v1.5.0 // indirect + github.com/h2non/gock v1.2.0 // indirect github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.2.4 // indirect @@ -58,8 +59,5 @@ require ( golang.org/x/text v0.14.0 // indirect google.golang.org/appengine v1.6.6 // 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 ) - -replace github.com/free5gc/openapi => github.com/free5gc/openapi v1.0.9-0.20240424093716-bda9387bb300 diff --git a/go.sum b/go.sum index 6117b1b..a2c4cce 100644 --- a/go.sum +++ b/go.sum @@ -60,8 +60,8 @@ github.com/evanphx/json-patch v0.5.2 h1:xVCHIVMUu1wtM/VkR9jVZ45N3FhZfYMMYGorLCR8 github.com/evanphx/json-patch v0.5.2/go.mod h1:ZWS5hhDbVDyob71nXKNL0+PWn6ToqBHMikGIFbs31qQ= 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.20240424093716-bda9387bb300 h1:zFEzWpBN2gLaepRVVhVeosUcrux7tVk41+Q0XHNWJXg= -github.com/free5gc/openapi v1.0.9-0.20240424093716-bda9387bb300/go.mod h1:oy68rqnHakRLUCuEOXcis7/PWGBuil+UaXMeTBeYY8Y= +github.com/free5gc/openapi v1.0.9-0.20240823100026-6a9f667e914f h1:b//Fa0CvIDU7fufqMcrEgbVUqpubokK/lFgkTxN3fGM= +github.com/free5gc/openapi v1.0.9-0.20240823100026-6a9f667e914f/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= @@ -88,8 +88,8 @@ github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= -github.com/golang-jwt/jwt v3.2.1+incompatible h1:73Z+4BJcrTC+KczS6WvTPvRGOp1WmfEP4Q1lOd9Z/+c= -github.com/golang-jwt/jwt v3.2.1+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/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -143,6 +143,8 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= +github.com/h2non/gock v1.2.0 h1:K6ol8rfrRkUOefooBC8elXoaNGYkpp7y2qcxGG6BzUE= +github.com/h2non/gock v1.2.0/go.mod h1:tNhoxHYW2W42cYkYb1WqzdbYIieALC99kpYr7rH/BQk= github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw= github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= @@ -478,8 +480,6 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= -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/plugin/nsselection_query_parameter.go b/internal/plugin/nsselection_query_parameter.go index 8162e2b..c9a3f92 100644 --- a/internal/plugin/nsselection_query_parameter.go +++ b/internal/plugin/nsselection_query_parameter.go @@ -9,7 +9,7 @@ import ( ) type NsselectionQueryParameter struct { - NfType *NfType `json:"nf-type"` + NfType *NrfNfManagementNfType `json:"nf-type"` NfId string `json:"nf-id"` diff --git a/internal/sbi/consumer/nrf_service.go b/internal/sbi/consumer/nrf_service.go index eb3b2bb..2a39b34 100644 --- a/internal/sbi/consumer/nrf_service.go +++ b/internal/sbi/consumer/nrf_service.go @@ -53,7 +53,7 @@ func (ns *NrfService) SendRegisterNFInstance(ctx context.Context, nssfCtx *nssf_ apiClient := ns.nrfNfMgmtClient var res *NFManagement.RegisterNFInstanceResponse - var nf models.NfProfile + var nf models.NrfNfManagementNfProfile finish := false for !finish { select { diff --git a/internal/sbi/processor/nsselection_network_slice_information.go b/internal/sbi/processor/nsselection_network_slice_information.go index 949bceb..55cb9fd 100644 --- a/internal/sbi/processor/nsselection_network_slice_information.go +++ b/internal/sbi/processor/nsselection_network_slice_information.go @@ -24,7 +24,7 @@ import ( type NetworkSliceInformationGetQuery struct { // nolint: lll - NfType models.NfType `form:"nf-type" binding:"required,oneof=NRF UDM AMF SMF AUSF NEF PCF SMSF NSSF UDR LMF GMLC 5G_EIR SEPP UPF N3IWF AF UDSF BSF CHF NWDAF PCSCF CBCF HSS UCMF SOR_AF SPAF MME SCSAS SCEF SCP NSSAAF ICSCF SCSCF DRA IMS_AS AANF 5G_DDNMF NSACF MFAF EASDF DCCF MB_SMF TSCTSF ADRF GBA_BSF CEF MB_UPF NSWOF PKMF MNPF SMS_GMSC SMS_IWMSC MBSF MBSTF PANF IP_SM_GW SMS_ROUTER"` + NfType models.NrfNfManagementNfType `form:"nf-type" binding:"required,oneof=NRF UDM AMF SMF AUSF NEF PCF SMSF NSSF UDR LMF GMLC 5G_EIR SEPP UPF N3IWF AF UDSF BSF CHF NWDAF PCSCF CBCF HSS UCMF SOR_AF SPAF MME SCSAS SCEF SCP NSSAAF ICSCF SCSCF DRA IMS_AS AANF 5G_DDNMF NSACF MFAF EASDF DCCF MB_SMF TSCTSF ADRF GBA_BSF CEF MB_UPF NSWOF PKMF MNPF SMS_GMSC SMS_IWMSC MBSF MBSTF PANF IP_SM_GW SMS_ROUTER"` NfId string `form:"nf-id" binding:"required,uuid"` @@ -45,8 +45,8 @@ type NetworkSliceInformationGetQuery struct { // Check if the NF service consumer is authorized // TODO: Check if the NF service consumer is legal with local configuration, or possibly after querying NRF through // `nf-id` e.g. Whether the V-NSSF is authorized -func checkNfServiceConsumer(nfType models.NfType) error { - if nfType != models.NfType_AMF && nfType != models.NfType_NSSF { +func checkNfServiceConsumer(nfType models.NrfNfManagementNfType) error { + if nfType != models.NrfNfManagementNfType_AMF && nfType != models.NrfNfManagementNfType_NSSF { return fmt.Errorf("`nf-type`:'%s' is not authorized to retrieve the slice selection information", string(nfType)) } From 74f5caa554a2a84319fdbaecb1c4fb2ba16e185f Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 10 Sep 2024 09:19:47 +0000 Subject: [PATCH 10/18] fix: represent http method using const instead of strings --- internal/sbi/api_nssaiavailability.go | 13 ++++++------- internal/sbi/api_nsselection.go | 5 ++--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/internal/sbi/api_nssaiavailability.go b/internal/sbi/api_nssaiavailability.go index 42d9e90..b509a69 100644 --- a/internal/sbi/api_nssaiavailability.go +++ b/internal/sbi/api_nssaiavailability.go @@ -2,7 +2,6 @@ package sbi import ( "net/http" - "strings" "github.com/gin-gonic/gin" @@ -17,7 +16,7 @@ func (s *Server) getNssaiAvailabilityRoutes() []Route { return []Route{ { "Health Check", - strings.ToUpper("Get"), + http.MethodGet, "/", func(ctx *gin.Context) { ctx.JSON(http.StatusOK, gin.H{"status": "Service Available"}) @@ -26,21 +25,21 @@ func (s *Server) getNssaiAvailabilityRoutes() []Route { { "NSSAIAvailabilityDelete", - strings.ToUpper("Delete"), + http.MethodDelete, "/nssai-availability/:nfId", s.NSSAIAvailabilityDelete, }, { "NSSAIAvailabilityPatch", - strings.ToUpper("Patch"), + http.MethodPatch, "/nssai-availability/:nfId", s.NSSAIAvailabilityPatch, }, { "NSSAIAvailabilityPut", - strings.ToUpper("Put"), + http.MethodPut, "/nssai-availability/:nfId", s.NSSAIAvailabilityPut, }, @@ -50,7 +49,7 @@ func (s *Server) getNssaiAvailabilityRoutes() []Route { // Simply replace 'subscriptions' with ':nfId' and check if ':nfId' is 'subscriptions' in handler function { "NSSAIAvailabilityUnsubscribe", - strings.ToUpper("Delete"), + http.MethodDelete, // "/nssai-availability/subscriptions/:subscriptionId", "/nssai-availability/:nfId/:subscriptionId", s.NSSAIAvailabilityUnsubscribeDelete, @@ -58,7 +57,7 @@ func (s *Server) getNssaiAvailabilityRoutes() []Route { { "NSSAIAvailabilityPost", - strings.ToUpper("Post"), + http.MethodPost, "/nssai-availability/subscriptions", s.NSSAIAvailabilityPost, }, diff --git a/internal/sbi/api_nsselection.go b/internal/sbi/api_nsselection.go index 47cc197..24434b2 100644 --- a/internal/sbi/api_nsselection.go +++ b/internal/sbi/api_nsselection.go @@ -2,7 +2,6 @@ package sbi import ( "net/http" - "strings" "github.com/gin-gonic/gin" @@ -16,7 +15,7 @@ func (s *Server) getNsSelectionRoutes() []Route { return []Route{ { "Health Check", - strings.ToUpper("Get"), + http.MethodGet, "/", func(ctx *gin.Context) { ctx.JSON(http.StatusOK, gin.H{"status": "Service Available"}) @@ -25,7 +24,7 @@ func (s *Server) getNsSelectionRoutes() []Route { { "NSSelectionGet", - strings.ToUpper("Get"), + http.MethodGet, "/network-slice-information", s.NetworkSliceInformationGet, }, From f2ae48cc96c3ebf39d608519364afe0158a08f7e Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 18 Sep 2024 02:49:15 +0000 Subject: [PATCH 11/18] fix: should return value after snssai comparison --- internal/util/util.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/util/util.go b/internal/util/util.go index 789946e..d181c51 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -163,7 +163,9 @@ func CheckSupportedSnssaiInTa(snssai models.Snssai, tai models.Tai) bool { for _, taConfig := range factory.NssfConfig.Configuration.TaList { if reflect.DeepEqual(*taConfig.Tai, tai) { for _, supportedSnssai := range taConfig.SupportedSnssaiList { - SnssaiEqualFold(supportedSnssai, snssai) + if SnssaiEqualFold(supportedSnssai, snssai) { + return true + } } return false } @@ -237,7 +239,9 @@ func CheckStandardSnssai(snssai models.Snssai) bool { // Check whether the NSSAI contains the specific S-NSSAI func CheckSnssaiInNssai(targetSnssai models.Snssai, nssai []models.ExtSnssai) bool { for _, snssai := range nssai { - SnssaiEqualFold(snssai, targetSnssai) + if SnssaiEqualFold(snssai, targetSnssai) { + return true + } } return false } From b8152410836bb342f875887f6c1bad1f7d42aef8 Mon Sep 17 00:00:00 2001 From: yccodr Date: Tue, 29 Oct 2024 16:16:49 +0800 Subject: [PATCH 12/18] chore: update nsselection version to 'v2' --- pkg/factory/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/factory/config.go b/pkg/factory/config.go index 9c81ac6..db6536b 100644 --- a/pkg/factory/config.go +++ b/pkg/factory/config.go @@ -26,7 +26,7 @@ const ( NssfSbiDefaultScheme = "https" NssfDefaultNrfUri = "https://127.0.0.10:8000" NssfNssaiavailResUriPrefix = "/nnssf-nssaiavailability/v1" - NssfNsselectResUriPrefix = "/nnssf-nsselection/v1" + NssfNsselectResUriPrefix = "/nnssf-nsselection/v2" ) type Config struct { From 57f293e62a87caa6d2000d623a0ba6713bbbf9a5 Mon Sep 17 00:00:00 2001 From: yccodr Date: Tue, 29 Oct 2024 16:44:57 +0800 Subject: [PATCH 13/18] fix: query key of getting ns info should be kebab case --- .../processor/nsselection_network_slice_information.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/sbi/processor/nsselection_network_slice_information.go b/internal/sbi/processor/nsselection_network_slice_information.go index 55cb9fd..24490a2 100644 --- a/internal/sbi/processor/nsselection_network_slice_information.go +++ b/internal/sbi/processor/nsselection_network_slice_information.go @@ -29,17 +29,17 @@ type NetworkSliceInformationGetQuery struct { NfId string `form:"nf-id" binding:"required,uuid"` // nolint: lll - SliceInfoRequestForRegistration *models.SliceInfoForRegistration `form:"sliceInfoRequestForRegistration" binding:"omitempty"` + SliceInfoRequestForRegistration *models.SliceInfoForRegistration `form:"slice-info-request-for-registration" binding:"omitempty"` // nolint: lll - SliceInfoRequestForPduSession *models.SliceInfoForPduSession `form:"sliceInfoRequestForPduSession" binding:"omitempty"` + SliceInfoRequestForPduSession *models.SliceInfoForPduSession `form:"slice-info-request-for-pdu-session" binding:"omitempty"` // nolint: lll - SliceInfoRequestForUeConfigurationUpdate *models.SliceInfoForUeConfigurationUpdate `form:"sliceInfoRequestForUeConfigurationUpdate" binding:"omitempty"` + SliceInfoRequestForUeConfigurationUpdate *models.SliceInfoForUeConfigurationUpdate `form:"slice-info-request-for-ue-configuration-update" binding:"omitempty"` HomePlmnId *models.PlmnId `form:"home-plmn-id" binding:"required_without=Tai,omitempty"` Tai *models.Tai `form:"tai" binding:"required_without=HomePlmnId,omitempty"` - SupportedFeatures string `form:"supportedFeatures"` + SupportedFeatures string `form:"supported-features"` } // Check if the NF service consumer is authorized From b3bf8f3008f08087e935d70ff1f1b0d108a1e0dd Mon Sep 17 00:00:00 2001 From: yccodr Date: Wed, 30 Oct 2024 03:38:57 +0800 Subject: [PATCH 14/18] chore: update openapi version --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index f8eb64e..ac08702 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.21 require ( github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d github.com/evanphx/json-patch v0.5.2 - github.com/free5gc/openapi v1.0.9-0.20240823100026-6a9f667e914f + github.com/free5gc/openapi v1.0.9-0.20241024114001-1414ef920de2 github.com/free5gc/util v1.0.6 github.com/gin-gonic/gin v1.9.1 github.com/go-playground/validator/v10 v10.14.0 diff --git a/go.sum b/go.sum index a2c4cce..5212743 100644 --- a/go.sum +++ b/go.sum @@ -60,8 +60,8 @@ github.com/evanphx/json-patch v0.5.2 h1:xVCHIVMUu1wtM/VkR9jVZ45N3FhZfYMMYGorLCR8 github.com/evanphx/json-patch v0.5.2/go.mod h1:ZWS5hhDbVDyob71nXKNL0+PWn6ToqBHMikGIFbs31qQ= 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.20240823100026-6a9f667e914f h1:b//Fa0CvIDU7fufqMcrEgbVUqpubokK/lFgkTxN3fGM= -github.com/free5gc/openapi v1.0.9-0.20240823100026-6a9f667e914f/go.mod h1:aKw6uGzEibGDrn9++w4/JpWxaaUBo7GaqsvuFKU9fl4= +github.com/free5gc/openapi v1.0.9-0.20241024114001-1414ef920de2 h1:rMZE/FZtEbOiAZISVs9M093g4I2SGdpcxDYp2htt6Ws= +github.com/free5gc/openapi v1.0.9-0.20241024114001-1414ef920de2/go.mod h1:aKw6uGzEibGDrn9++w4/JpWxaaUBo7GaqsvuFKU9fl4= github.com/free5gc/util v1.0.6 h1:dBt9drcXtYKE/cY5XuQcuffgsYclPIpIArhSeS6M+DQ= github.com/free5gc/util v1.0.6/go.mod h1:eSGN7POUM8LNTvg/E591XR6447a6/w1jFWGKNZPHcXw= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= From 872b5ea17496da6cb22b3aabfe9875af1f4d34ac Mon Sep 17 00:00:00 2001 From: yccodr Date: Tue, 5 Nov 2024 10:40:22 +0800 Subject: [PATCH 15/18] chore: upgrade openapi version --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index ac08702..3110429 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.21 require ( github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d github.com/evanphx/json-patch v0.5.2 - github.com/free5gc/openapi v1.0.9-0.20241024114001-1414ef920de2 + github.com/free5gc/openapi v1.0.9-0.20241105014927-c376b9f16133 github.com/free5gc/util v1.0.6 github.com/gin-gonic/gin v1.9.1 github.com/go-playground/validator/v10 v10.14.0 diff --git a/go.sum b/go.sum index 5212743..848b90d 100644 --- a/go.sum +++ b/go.sum @@ -60,8 +60,8 @@ github.com/evanphx/json-patch v0.5.2 h1:xVCHIVMUu1wtM/VkR9jVZ45N3FhZfYMMYGorLCR8 github.com/evanphx/json-patch v0.5.2/go.mod h1:ZWS5hhDbVDyob71nXKNL0+PWn6ToqBHMikGIFbs31qQ= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= -github.com/free5gc/openapi v1.0.9-0.20241024114001-1414ef920de2 h1:rMZE/FZtEbOiAZISVs9M093g4I2SGdpcxDYp2htt6Ws= -github.com/free5gc/openapi v1.0.9-0.20241024114001-1414ef920de2/go.mod h1:aKw6uGzEibGDrn9++w4/JpWxaaUBo7GaqsvuFKU9fl4= +github.com/free5gc/openapi v1.0.9-0.20241105014927-c376b9f16133 h1:kteBxWKtc15ngTG+BmGBTpW4xIddxPde01TlmcHcngg= +github.com/free5gc/openapi v1.0.9-0.20241105014927-c376b9f16133/go.mod h1:aKw6uGzEibGDrn9++w4/JpWxaaUBo7GaqsvuFKU9fl4= github.com/free5gc/util v1.0.6 h1:dBt9drcXtYKE/cY5XuQcuffgsYclPIpIArhSeS6M+DQ= github.com/free5gc/util v1.0.6/go.mod h1:eSGN7POUM8LNTvg/E591XR6447a6/w1jFWGKNZPHcXw= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= From 2bcd49f4f87e468d189af40abc35a534c5f5cc39 Mon Sep 17 00:00:00 2001 From: "CTFang@WireLab" Date: Sat, 9 Nov 2024 05:01:45 +0000 Subject: [PATCH 16/18] fix: SendDeregisterNFInstance() error type and request token parameter --- internal/sbi/consumer/nrf_service.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/sbi/consumer/nrf_service.go b/internal/sbi/consumer/nrf_service.go index 2a39b34..00a1b48 100644 --- a/internal/sbi/consumer/nrf_service.go +++ b/internal/sbi/consumer/nrf_service.go @@ -102,7 +102,7 @@ func (ns *NrfService) SendDeregisterNFInstance(nfInstanceId string) (*models.Pro var err error - ctx, pd, err := nssf_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_NFM, models.NrfNfManagementNfType_NRF) + ctx, pd, err := nssf_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_NFM, models.NrfNfManagementNfType_NSSF) if err != nil { return pd, err } @@ -117,7 +117,10 @@ func (ns *NrfService) SendDeregisterNFInstance(nfInstanceId string) (*models.Pro if err != nil { if apiErr, ok := err.(openapi.GenericOpenAPIError); ok { // API error - return apiErr.Model().(*models.ProblemDetails), err + if deregError, ok2 := apiErr.Model().(NFManagement.DeregisterNFInstanceError); ok2 { + return &deregError.ProblemDetails, err + } + return nil, err } // Golang error From 900da0b305f0c9af68bbad694f6f823d025c6f9b Mon Sep 17 00:00:00 2001 From: "CTFang@WireLab" Date: Thu, 14 Nov 2024 02:05:19 +0000 Subject: [PATCH 17/18] fix: nfProfile get from register and openapi hash --- go.mod | 2 +- go.sum | 4 ++-- internal/sbi/consumer/nrf_service.go | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 3110429..0d95874 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.21 require ( github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d github.com/evanphx/json-patch v0.5.2 - github.com/free5gc/openapi v1.0.9-0.20241105014927-c376b9f16133 + 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/go-playground/validator/v10 v10.14.0 diff --git a/go.sum b/go.sum index 848b90d..ee3a0a1 100644 --- a/go.sum +++ b/go.sum @@ -60,8 +60,8 @@ github.com/evanphx/json-patch v0.5.2 h1:xVCHIVMUu1wtM/VkR9jVZ45N3FhZfYMMYGorLCR8 github.com/evanphx/json-patch v0.5.2/go.mod h1:ZWS5hhDbVDyob71nXKNL0+PWn6ToqBHMikGIFbs31qQ= 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.20241105014927-c376b9f16133 h1:kteBxWKtc15ngTG+BmGBTpW4xIddxPde01TlmcHcngg= -github.com/free5gc/openapi v1.0.9-0.20241105014927-c376b9f16133/go.mod h1:aKw6uGzEibGDrn9++w4/JpWxaaUBo7GaqsvuFKU9fl4= +github.com/free5gc/openapi v1.0.9-0.20241112160830-092c679ef6cd h1:VRxE3QzfL1uU8ZnR9Y1aXtslHPeMIVoHb3wU0yOz2AI= +github.com/free5gc/openapi v1.0.9-0.20241112160830-092c679ef6cd/go.mod h1:aKw6uGzEibGDrn9++w4/JpWxaaUBo7GaqsvuFKU9fl4= github.com/free5gc/util v1.0.6 h1:dBt9drcXtYKE/cY5XuQcuffgsYclPIpIArhSeS6M+DQ= github.com/free5gc/util v1.0.6/go.mod h1:eSGN7POUM8LNTvg/E591XR6447a6/w1jFWGKNZPHcXw= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= diff --git a/internal/sbi/consumer/nrf_service.go b/internal/sbi/consumer/nrf_service.go index 00a1b48..0fe08c7 100644 --- a/internal/sbi/consumer/nrf_service.go +++ b/internal/sbi/consumer/nrf_service.go @@ -78,6 +78,7 @@ func (ns *NrfService) SendRegisterNFInstance(ctx context.Context, nssfCtx *nssf_ resourceUri := res.Location resourceNrfUri, _, _ = strings.Cut(resourceUri, "/nnrf-nfm/") retrieveNfInstanceId = resourceUri[strings.LastIndex(resourceUri, "/")+1:] + nf = res.NrfNfManagementNfProfile oauth2 := false if nf.CustomInfo != nil { @@ -98,11 +99,11 @@ func (ns *NrfService) SendRegisterNFInstance(ctx context.Context, nssfCtx *nssf_ } func (ns *NrfService) SendDeregisterNFInstance(nfInstanceId string) (*models.ProblemDetails, error) { - logger.ConsumerLog.Infof("Send Deregister NFInstance") + logger.ConsumerLog.Infof("Send Deregister NFInstance [%s]", nfInstanceId) var err error - ctx, pd, err := nssf_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_NFM, models.NrfNfManagementNfType_NSSF) + ctx, pd, err := nssf_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_NFM, models.NrfNfManagementNfType_NRF) if err != nil { return pd, err } From 2f4000532f030e3f77d22993d0a51674d0527325 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 14 Nov 2024 13:25:23 +0800 Subject: [PATCH 18/18] chore: remove commented code --- internal/sbi/api_nssaiavailability.go | 1 - internal/sbi/api_nsselection.go | 1 - internal/sbi/processor/nsselection_network_slice_information.go | 1 - 3 files changed, 3 deletions(-) diff --git a/internal/sbi/api_nssaiavailability.go b/internal/sbi/api_nssaiavailability.go index b509a69..711cd32 100644 --- a/internal/sbi/api_nssaiavailability.go +++ b/internal/sbi/api_nssaiavailability.go @@ -156,7 +156,6 @@ type NssaiAvailabilityPutParams struct { func (s *Server) NSSAIAvailabilityPut(c *gin.Context) { logger.NssaiavailLog.Infof("Handle NSSAIAvailabilityPut") - // nfId := c.Params.ByName("nfId") var params NssaiAvailabilityPutParams if err := c.ShouldBindUri(¶ms); err != nil { problemDetails := &models.ProblemDetails{ diff --git a/internal/sbi/api_nsselection.go b/internal/sbi/api_nsselection.go index 24434b2..99a18a9 100644 --- a/internal/sbi/api_nsselection.go +++ b/internal/sbi/api_nsselection.go @@ -48,6 +48,5 @@ func (s *Server) NetworkSliceInformationGet(c *gin.Context) { return } - // query := c.Request.URL.Query() s.Processor().NSSelectionSliceInformationGet(c, query) } diff --git a/internal/sbi/processor/nsselection_network_slice_information.go b/internal/sbi/processor/nsselection_network_slice_information.go index 24490a2..e6b78da 100644 --- a/internal/sbi/processor/nsselection_network_slice_information.go +++ b/internal/sbi/processor/nsselection_network_slice_information.go @@ -70,7 +70,6 @@ func (p *Processor) NSSelectionSliceInformationGet( // Check permission of NF service consumer err := checkNfServiceConsumer(param.NfType) if err != nil { - // status = http.StatusForbidden problemDetails = &models.ProblemDetails{ Title: util.UNAUTHORIZED_CONSUMER, Status: http.StatusForbidden,