From 14c354242c463d6d53f6e9978d5fefa6855552ba Mon Sep 17 00:00:00 2001 From: brianchennn Date: Thu, 30 Mar 2023 12:13:25 +0000 Subject: [PATCH] refactor and update util to use new log formatter setting --- cmd/main.go | 83 +++---- go.mod | 39 +++- go.sum | 83 ++++--- internal/context/context.go | 70 +++++- internal/logger/logger.go | 97 +++----- internal/sbi/consumer/nf_discovery.go | 6 +- internal/sbi/consumer/nf_management.go | 2 +- internal/sbi/eventexposure/routers.go | 3 +- internal/sbi/parameterprovision/routers.go | 3 +- internal/sbi/producer/callback/callback.go | 2 +- internal/sbi/producer/event_exposure.go | 6 +- internal/sbi/producer/generate_auth_data.go | 9 +- internal/sbi/producer/parameter_provision.go | 3 +- .../producer/subscriber_data_management.go | 101 +++++---- .../sbi/producer/ue_context_management.go | 57 +++-- .../sbi/subscriberdatamanagement/routers.go | 3 +- internal/sbi/ueauthentication/routers.go | 3 +- internal/sbi/uecontextmanagement/routers.go | 3 +- pkg/factory/config.go | 134 ++++++++--- pkg/factory/factory.go | 40 ++-- pkg/service/init.go | 208 ++++-------------- 21 files changed, 500 insertions(+), 455 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index f4e071a..1ce895d 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -1,27 +1,26 @@ package main import ( - "fmt" "os" "path/filepath" "runtime/debug" - "github.com/asaskevich/govalidator" "github.com/urfave/cli" "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/util" + "github.com/free5gc/udm/pkg/factory" "github.com/free5gc/udm/pkg/service" + logger_util "github.com/free5gc/util/logger" "github.com/free5gc/util/version" ) -var UDM = &service.UDM{} +var UDM *service.UdmApp func main() { defer func() { if p := recover(); p != nil { // Print stack for panic to log. Fatalf() will let program exit. - logger.AppLog.Fatalf("panic: %v\n%s", p, string(debug.Stack())) + logger.MainLog.Fatalf("panic: %v\n%s", p, string(debug.Stack())) } }() @@ -29,57 +28,67 @@ func main() { app.Name = "udm" app.Usage = "5G Unified Data Management (UDM)" app.Action = action - app.Flags = UDM.GetCliCmd() + app.Flags = []cli.Flag{ + cli.StringFlag{ + Name: "config, c", + Usage: "Load configuration from `FILE`", + }, + cli.StringSliceFlag{ + Name: "log, l", + Usage: "Output NF log to `FILE`", + }, + } + if err := app.Run(os.Args); err != nil { - fmt.Printf("UDM Run error: %v\n", err) + logger.MainLog.Errorf("UDM Run error: %v\n", err) } } -func action(c *cli.Context) error { - if err := initLogFile(c.String("log"), c.String("log5gc")); err != nil { - logger.AppLog.Errorf("%+v", err) +func action(cliCtx *cli.Context) error { + tlsKeyLogPath, err := initLogFile(cliCtx.StringSlice("log")) + if err != nil { return err } - if err := UDM.Initialize(c); err != nil { - switch errType := err.(type) { - case govalidator.Errors: - validErrs := err.(govalidator.Errors).Errors() - for _, validErr := range validErrs { - logger.CfgLog.Errorf("%+v", validErr) - } - default: - logger.CfgLog.Errorf("%+v", errType) - } - logger.CfgLog.Errorf("[-- PLEASE REFER TO SAMPLE CONFIG FILE COMMENTS --]") - return fmt.Errorf("Failed to initialize !!") - } + logger.MainLog.Infoln("UDM version: ", version.GetVersion()) - logger.AppLog.Infoln(c.App.Name) - logger.AppLog.Infoln("UDM version: ", version.GetVersion()) + cfg, err := factory.ReadConfig(cliCtx.String("config")) + if err != nil { + return err + } + factory.UdmConfig = cfg + udm, err := service.NewApp(cfg) + if err != nil { + return err + } + UDM = udm - UDM.Start() + udm.Start(tlsKeyLogPath) return nil } -func initLogFile(logNfPath, log5gcPath string) error { - UDM.KeyLogPath = util.UdmDefaultKeyLogPath +func initLogFile(logNfPath []string) (string, error) { + logTlsKeyPath := "" - if err := logger.LogFileHook(logNfPath, log5gcPath); err != nil { - return err - } + for _, path := range logNfPath { + if err := logger_util.LogFileHook(logger.Log, path); err != nil { + return "", err + } - if logNfPath != "" { - nfDir, _ := filepath.Split(logNfPath) + if logTlsKeyPath != "" { + continue + } + + nfDir, _ := filepath.Split(path) tmpDir := filepath.Join(nfDir, "key") if err := os.MkdirAll(tmpDir, 0o775); err != nil { logger.InitLog.Errorf("Make directory %s failed: %+v", tmpDir, err) - return err + return "", err } - _, name := filepath.Split(util.UdmDefaultKeyLogPath) - UDM.KeyLogPath = filepath.Join(tmpDir, name) + _, name := filepath.Split(factory.UdmDefaultTLSKeyLogPath) + logTlsKeyPath = filepath.Join(tmpDir, name) } - return nil + return logTlsKeyPath, nil } diff --git a/go.mod b/go.mod index b60a786..19cd734 100644 --- a/go.mod +++ b/go.mod @@ -1,13 +1,12 @@ module github.com/free5gc/udm -go 1.14 +go 1.17 require ( github.com/antihax/optional v1.0.0 - github.com/antonfisher/nested-logrus-formatter v1.3.1 github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d - github.com/free5gc/openapi v1.0.4 - github.com/free5gc/util v1.0.3 + github.com/free5gc/openapi v1.0.6 + github.com/free5gc/util v1.0.5-0.20230306071612-a52909216bd2 github.com/gin-gonic/gin v1.7.7 github.com/google/uuid v1.3.0 github.com/sirupsen/logrus v1.8.1 @@ -15,3 +14,35 @@ require ( golang.org/x/crypto v0.1.0 gopkg.in/yaml.v2 v2.4.0 ) + +require ( + github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect + github.com/gin-contrib/sse v0.1.0 // indirect + github.com/go-playground/locales v0.13.0 // indirect + github.com/go-playground/universal-translator v0.17.0 // indirect + github.com/go-playground/validator/v10 v10.4.1 // indirect + github.com/golang-jwt/jwt v3.2.1+incompatible // indirect + github.com/golang/protobuf v1.5.2 // indirect + github.com/google/go-cmp v0.5.6 // indirect + github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/kr/pretty v0.2.0 // indirect + github.com/leodido/go-urn v1.2.0 // indirect + github.com/mattn/go-isatty v0.0.14 // indirect + github.com/mitchellh/mapstructure v1.4.3 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/stretchr/testify v1.8.0 // indirect + github.com/tim-ywliu/nested-logrus-formatter v1.3.2 // indirect + github.com/ugorji/go/codec v1.1.7 // indirect + golang.org/x/net v0.7.0 // indirect + golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect + golang.org/x/sys v0.5.0 // indirect + golang.org/x/text v0.7.0 // indirect + google.golang.org/appengine v1.6.7 // indirect + google.golang.org/protobuf v1.27.1 // indirect + gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect + gopkg.in/h2non/gock.v1 v1.1.2 // indirect +) diff --git a/go.sum b/go.sum index db4e580..d811e42 100644 --- a/go.sum +++ b/go.sum @@ -35,8 +35,6 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 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/antonfisher/nested-logrus-formatter v1.3.1 h1:NFJIr+pzwv5QLHTPyKz9UMEoHck02Q9L0FP13b/xSbQ= -github.com/antonfisher/nested-logrus-formatter v1.3.1/go.mod h1:6WTfyWFkBc9+zyBaKIqRrg/KwMqBbodBjgbHjDz7zjA= 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/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= @@ -45,8 +43,9 @@ github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5P github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= -github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU= +github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= 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= @@ -55,13 +54,12 @@ github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.m github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/evanphx/json-patch v0.5.2/go.mod h1:ZWS5hhDbVDyob71nXKNL0+PWn6ToqBHMikGIFbs31qQ= -github.com/free5gc/openapi v1.0.4 h1:bC6oqXy8Z+3e532xLMFmrTHvdyv4sNGDPezQSslw5gQ= -github.com/free5gc/openapi v1.0.4/go.mod h1:KRCnnp0GeK0Bl4gnrX79cQAidKXNENf8VRdG0y9R0Fc= -github.com/free5gc/util v1.0.3 h1:or/gqHCAi3j2YKd+nzViRnc/tl1tuuJAYxCao6IbOAU= -github.com/free5gc/util v1.0.3/go.mod h1:DL1Dnryh//Ps5B+hfXbhU1R07fVfrmPs4uuTO4g9yTg= +github.com/free5gc/openapi v1.0.6 h1:ytRjU/YZRI8UhKKyfajXSyGB6s1YDFkJ1weeAGJ8LXw= +github.com/free5gc/openapi v1.0.6/go.mod h1:iw/N0E+FlX44EEx24IBi2EdZW8v+bkj3ETWPGnlK9DI= +github.com/free5gc/util v1.0.5-0.20230306071612-a52909216bd2 h1:FG8KlJ46Epscj3F9XBAKuDGJD9kSKJdstCL9fttjUjE= +github.com/free5gc/util v1.0.5-0.20230306071612-a52909216bd2/go.mod h1:fgV0hXf5arxAWs8D9LfrrfNByZ1IDCWYlgBzncy5GtE= 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.7.3/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY= github.com/gin-gonic/gin v1.7.7 h1:3DoBmSbJbZAWqXJC3SLjAPfutPJJRN1U5pALB7EeTTs= github.com/gin-gonic/gin v1.7.7/go.mod h1:axIBovoeJpVj8S3BwE0uPMTeReE4+AfFtqpqaZ1qq1U= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= @@ -101,8 +99,10 @@ github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrU github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= -github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= @@ -113,8 +113,10 @@ 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.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 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= @@ -137,28 +139,35 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= -github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs= +github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= -github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag= +github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= +github.com/mitchellh/mapstructure v1.4.2/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mitchellh/mapstructure v1.4.3 h1:OVowDSCllw/YjdLkam3/sm7wEtOy59d8ndGgCcyj8cs= +github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 h1:W6apQkHrMkS0Muv8G/TipAy/FJl/rCYT0+EuS8+Z0z4= github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= @@ -168,22 +177,27 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= 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/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/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= 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/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.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= 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= +github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= +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/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs= @@ -271,17 +285,18 @@ golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81R golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.1.0 h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0= golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= +golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20210810183815-faf39c7919d5 h1:Ati8dO7+U7mxpkPSxBZQEvzHVUYB/MqCklCN8ig5w/o= golang.org/x/oauth2 v0.0.0-20210810183815-faf39c7919d5/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 h1:RerP+noqYHUQ8CMRcPlC2nvTa4dcBIjegkuWdcUDuqg= +golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -319,26 +334,28 @@ 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-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/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-20210630005230-0f9fa26af87c/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-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -411,8 +428,9 @@ google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7 google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/appengine v1.6.6 h1:lMO5rYAqUxkmaj76jAkRUvt5JZgFymx/+Q5Mzfivuhc= google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= +google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= @@ -463,11 +481,15 @@ google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2 google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= -google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -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/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/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= @@ -475,8 +497,9 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/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= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/internal/context/context.go b/internal/context/context.go index c392709..76cf5a6 100644 --- a/internal/context/context.go +++ b/internal/context/context.go @@ -3,13 +3,18 @@ package context import ( "fmt" "math" + "os" "strconv" "strings" "sync" + "github.com/google/uuid" + "github.com/free5gc/openapi" "github.com/free5gc/openapi/Nnrf_NFDiscovery" "github.com/free5gc/openapi/models" + "github.com/free5gc/udm/internal/logger" + "github.com/free5gc/udm/pkg/factory" "github.com/free5gc/udm/pkg/suci" "github.com/free5gc/util/idgenerator" ) @@ -24,9 +29,9 @@ const ( LocationUriSharedDataSubscription ) -func init() { - UDM_Self().NfService = make(map[models.ServiceName]models.NfService) - UDM_Self().EeSubscriptionIDGenerator = idgenerator.NewGenerator(1, math.MaxInt32) +func Init() { + Getself().NfService = make(map[models.ServiceName]models.NfService) + Getself().EeSubscriptionIDGenerator = idgenerator.NewGenerator(1, math.MaxInt32) } type UDMContext struct { @@ -72,7 +77,7 @@ type UdmUeContext struct { SmSubsDataLock sync.RWMutex } -func (ue *UdmUeContext) init() { +func (ue *UdmUeContext) Init() { ue.UdmSubsToNotify = make(map[string]*models.SubscriptionDataSubscriptions) ue.EeSubscriptions = make(map[string]*models.EeSubscription) ue.SubscribeToNotifChange = make(map[string]*models.SdmSubscription) @@ -84,6 +89,45 @@ type UdmNFContext struct { SubscribeToNotifSharedDataChange *models.SdmSubscription // SubscriptionID as key } +func InitUdmContext(context *UDMContext) { + config := factory.UdmConfig + logger.UtilLog.Info("udmconfig Info: Version[", config.Info.Version, "] Description[", config.Info.Description, "]") + configuration := config.Configuration + udmContext.NfId = uuid.New().String() + sbi := configuration.Sbi + udmContext.UriScheme = "" + udmContext.SBIPort = factory.UdmSbiDefaultPort + udmContext.RegisterIPv4 = factory.UdmSbiDefaultIPv4 + if sbi != nil { + if sbi.Scheme != "" { + udmContext.UriScheme = models.UriScheme(sbi.Scheme) + } + if sbi.RegisterIPv4 != "" { + udmContext.RegisterIPv4 = sbi.RegisterIPv4 + } + if sbi.Port != 0 { + udmContext.SBIPort = sbi.Port + } + + udmContext.BindingIPv4 = os.Getenv(sbi.BindingIPv4) + if udmContext.BindingIPv4 != "" { + logger.UtilLog.Info("Parsing ServerIPv4 address from ENV Variable.") + } else { + udmContext.BindingIPv4 = sbi.BindingIPv4 + if udmContext.BindingIPv4 == "" { + logger.UtilLog.Warn("Error parsing ServerIPv4 address as string. Using the 0.0.0.0 address as default.") + udmContext.BindingIPv4 = "0.0.0.0" + } + } + } + udmContext.NrfUri = configuration.NrfUri + servingNameList := configuration.ServiceNameList + + udmContext.SuciProfiles = configuration.SuciProfiles + + udmContext.InitNFService(servingNameList, config.Info.Version) +} + func (context *UDMContext) ManageSmData(smDatafromUDR []models.SessionManagementSubscriptionData, snssaiFromReq string, dnnFromReq string) (mp map[string]models.SessionManagementSubscriptionData, ind string, Dnns []models.DnnConfiguration, allDnns []map[string]models.DnnConfiguration, @@ -226,7 +270,7 @@ func (udmUeContext *UdmUeContext) SetSMSubsData(smSubsData map[string]models.Ses func (context *UDMContext) NewUdmUe(supi string) *UdmUeContext { ue := new(UdmUeContext) - ue.init() + ue.Init() ue.Supi = supi context.UdmUePool.Store(supi, ue) return ue @@ -342,11 +386,13 @@ func (context *UDMContext) GetAmfNon3gppRegContext(supi string) *models.AmfNon3G func (ue *UdmUeContext) GetLocationURI(types int) string { switch types { case LocationUriAmf3GppAccessRegistration: - return UDM_Self().GetIPv4Uri() + "/nudm-uecm/v1/" + ue.Supi + "/registrations/amf-3gpp-access" + return Getself().GetIPv4Uri() + factory.UdmUecmResUriPrefix + "/" + ue.Supi + "/registrations/amf-3gpp-access" case LocationUriAmfNon3GppAccessRegistration: - return UDM_Self().GetIPv4Uri() + "/nudm-uecm/v1/" + ue.Supi + "/registrations/amf-non-3gpp-access" + return Getself().GetIPv4Uri() + factory.UdmUecmResUriPrefix + "/" + ue.Supi + "/registrations/amf-non-3gpp-access" case LocationUriSmfRegistration: - return UDM_Self().GetIPv4Uri() + "/nudm-uecm/v1/" + ue.Supi + "/registrations/smf-registrations/" + ue.PduSessionID + + return Getself().GetIPv4Uri() + + factory.UdmUecmResUriPrefix + "/" + ue.Supi + "/registrations/smf-registrations/" + ue.PduSessionID } return "" } @@ -354,9 +400,9 @@ func (ue *UdmUeContext) GetLocationURI(types int) string { func (ue *UdmUeContext) GetLocationURI2(types int, supi string) string { switch types { case LocationUriSharedDataSubscription: - // return UDM_Self().GetIPv4Uri() + "/nudm-sdm/v1/shared-data-subscriptions/" + nf.SubscriptionID + // return Getself().GetIPv4Uri() + UdmSdmResUriPrefix +"/shared-data-subscriptions/" + nf.SubscriptionID case LocationUriSdmSubscription: - return UDM_Self().GetIPv4Uri() + "/nudm-sdm/v1/" + supi + "/sdm-subscriptions/" + return Getself().GetIPv4Uri() + factory.UdmSdmResUriPrefix + "/" + supi + "/sdm-subscriptions/" } return "" } @@ -401,7 +447,7 @@ func (context *UDMContext) GetIPv4Uri() string { // GetSDMUri ... get subscriber data management service uri func (context *UDMContext) GetSDMUri() string { - return context.GetIPv4Uri() + "/nudm-sdm/v1" + return context.GetIPv4Uri() + factory.UdmSdmResUriPrefix } func (context *UDMContext) InitNFService(serviceName []string, version string) { @@ -432,6 +478,6 @@ func (context *UDMContext) InitNFService(serviceName []string, version string) { } } -func UDM_Self() *UDMContext { +func Getself() *UDMContext { return &udmContext } diff --git a/internal/logger/logger.go b/internal/logger/logger.go index d0f72d1..d06d558 100644 --- a/internal/logger/logger.go +++ b/internal/logger/logger.go @@ -1,21 +1,20 @@ package logger import ( - "os" - "time" - - formatter "github.com/antonfisher/nested-logrus-formatter" "github.com/sirupsen/logrus" logger_util "github.com/free5gc/util/logger" ) var ( - log *logrus.Logger - AppLog *logrus.Entry + Log *logrus.Logger + NfLog *logrus.Entry + MainLog *logrus.Entry InitLog *logrus.Entry CfgLog *logrus.Entry - Handlelog *logrus.Entry + CtxLog *logrus.Entry + GinLog *logrus.Entry + ConsumerLog *logrus.Entry HttpLog *logrus.Entry UeauLog *logrus.Entry UecmLog *logrus.Entry @@ -25,71 +24,31 @@ var ( UtilLog *logrus.Entry SuciLog *logrus.Entry CallbackLog *logrus.Entry - ContextLog *logrus.Entry - ConsumerLog *logrus.Entry - GinLog *logrus.Entry + ProcLog *logrus.Entry ) func init() { - log = logrus.New() - log.SetReportCaller(false) - - log.Formatter = &formatter.Formatter{ - TimestampFormat: time.RFC3339Nano, - TrimMessages: true, - NoFieldsSpace: true, - HideKeys: true, - FieldsOrder: []string{"component", "category"}, - } - - AppLog = log.WithFields(logrus.Fields{"component": "UDM", "category": "App"}) - InitLog = log.WithFields(logrus.Fields{"component": "UDM", "category": "Init"}) - CfgLog = log.WithFields(logrus.Fields{"component": "UDM", "category": "CFG"}) - Handlelog = log.WithFields(logrus.Fields{"component": "UDM", "category": "HDLR"}) - HttpLog = log.WithFields(logrus.Fields{"component": "UDM", "category": "HTTP"}) - UeauLog = log.WithFields(logrus.Fields{"component": "UDM", "category": "UEAU"}) - UecmLog = log.WithFields(logrus.Fields{"component": "UDM", "category": "UECM"}) - SdmLog = log.WithFields(logrus.Fields{"component": "UDM", "category": "SDM"}) - PpLog = log.WithFields(logrus.Fields{"component": "UDM", "category": "PP"}) - EeLog = log.WithFields(logrus.Fields{"component": "UDM", "category": "EE"}) - UtilLog = log.WithFields(logrus.Fields{"component": "UDM", "category": "Util"}) - SuciLog = log.WithFields(logrus.Fields{"component": "UDM", "category": "Suci"}) - CallbackLog = log.WithFields(logrus.Fields{"component": "UDM", "category": "CB"}) - ContextLog = log.WithFields(logrus.Fields{"component": "UDM", "category": "CTX"}) - ConsumerLog = log.WithFields(logrus.Fields{"component": "UDM", "category": "Consumer"}) - GinLog = log.WithFields(logrus.Fields{"component": "UDM", "category": "GIN"}) -} - -func LogFileHook(logNfPath string, log5gcPath string) error { - if fullPath, err := logger_util.CreateFree5gcLogFile(log5gcPath); err == nil { - if fullPath != "" { - free5gcLogHook, hookErr := logger_util.NewFileHook(fullPath, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0o666) - if hookErr != nil { - return hookErr - } - log.Hooks.Add(free5gcLogHook) - } - } else { - return err - } - - if fullPath, err := logger_util.CreateNfLogFile(logNfPath, "udm.log"); err == nil { - selfLogHook, hookErr := logger_util.NewFileHook(fullPath, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0o666) - if hookErr != nil { - return hookErr - } - log.Hooks.Add(selfLogHook) - } else { - return err + fieldsOrder := []string{ + logger_util.FieldNF, + logger_util.FieldCategory, } - return nil -} - -func SetLogLevel(level logrus.Level) { - log.SetLevel(level) -} - -func SetReportCaller(enable bool) { - log.SetReportCaller(enable) + Log = logger_util.New(fieldsOrder) + NfLog = Log.WithField(logger_util.FieldNF, "UDM") + MainLog = NfLog.WithField(logger_util.FieldCategory, "Main") + InitLog = NfLog.WithField(logger_util.FieldCategory, "Init") + CfgLog = NfLog.WithField(logger_util.FieldCategory, "CFG") + CtxLog = NfLog.WithField(logger_util.FieldCategory, "CTX") + GinLog = NfLog.WithField(logger_util.FieldCategory, "GIN") + ConsumerLog = NfLog.WithField(logger_util.FieldCategory, "Consumer") + ProcLog = NfLog.WithField(logger_util.FieldCategory, "Proc") + HttpLog = NfLog.WithField(logger_util.FieldCategory, "HTTP") + UeauLog = NfLog.WithField(logger_util.FieldCategory, "UEAU") + UecmLog = NfLog.WithField(logger_util.FieldCategory, "UECM") + SdmLog = NfLog.WithField(logger_util.FieldCategory, "SDM") + PpLog = NfLog.WithField(logger_util.FieldCategory, "PP") + EeLog = NfLog.WithField(logger_util.FieldCategory, "EE") + UtilLog = NfLog.WithField(logger_util.FieldCategory, "Util") + SuciLog = NfLog.WithField(logger_util.FieldCategory, "Suci") + CallbackLog = NfLog.WithField(logger_util.FieldCategory, "Callback") } diff --git a/internal/sbi/consumer/nf_discovery.go b/internal/sbi/consumer/nf_discovery.go index 48552a1..ab8cf1f 100644 --- a/internal/sbi/consumer/nf_discovery.go +++ b/internal/sbi/consumer/nf_discovery.go @@ -34,7 +34,7 @@ func SendNFIntances(nrfUri string, targetNfType, requestNfType models.NfType, } defer func() { if rspCloseErr := res.Body.Close(); rspCloseErr != nil { - logger.Handlelog.Errorf("SearchNFInstances response body cannot close: %+v", rspCloseErr) + logger.ConsumerLog.Errorf("SearchNFInstances response body cannot close: %+v", rspCloseErr) } }() @@ -45,7 +45,7 @@ func SendNFIntances(nrfUri string, targetNfType, requestNfType models.NfType, } func SendNFIntancesUDR(id string, types int) string { - self := udm_context.UDM_Self() + self := udm_context.Getself() targetNfType := models.NfType_UDR requestNfType := models.NfType_UDM localVarOptionals := Nnrf_NFDiscovery.SearchNFInstancesParamOpts{ @@ -62,7 +62,7 @@ func SendNFIntancesUDR(id string, types int) string { fmt.Println(self.NrfUri) result, err := SendNFIntances(self.NrfUri, targetNfType, requestNfType, localVarOptionals) if err != nil { - logger.Handlelog.Error(err.Error()) + logger.ConsumerLog.Error(err.Error()) return "" } for _, profile := range result.NfInstances { diff --git a/internal/sbi/consumer/nf_management.go b/internal/sbi/consumer/nf_management.go index 73ea06d..6c3fc1e 100644 --- a/internal/sbi/consumer/nf_management.go +++ b/internal/sbi/consumer/nf_management.go @@ -81,7 +81,7 @@ func SendRegisterNFInstance(nrfUri, nfInstanceId string, profile models.NfProfil func SendDeregisterNFInstance() (problemDetails *models.ProblemDetails, err error) { logger.ConsumerLog.Infof("Send Deregister NFInstance") - udmSelf := udm_context.UDM_Self() + udmSelf := udm_context.Getself() // Set client and set url configuration := Nnrf_NFManagement.NewConfiguration() configuration.SetBasePath(udmSelf.NrfUri) diff --git a/internal/sbi/eventexposure/routers.go b/internal/sbi/eventexposure/routers.go index 281f4ec..f02d860 100644 --- a/internal/sbi/eventexposure/routers.go +++ b/internal/sbi/eventexposure/routers.go @@ -16,6 +16,7 @@ import ( "github.com/gin-gonic/gin" "github.com/free5gc/udm/internal/logger" + "github.com/free5gc/udm/pkg/factory" logger_util "github.com/free5gc/util/logger" ) @@ -42,7 +43,7 @@ func NewRouter() *gin.Engine { } func AddService(engine *gin.Engine) *gin.RouterGroup { - group := engine.Group("/nudm-ee/v1") + group := engine.Group(factory.UdmEeResUriPrefix) for _, route := range routes { switch route.Method { diff --git a/internal/sbi/parameterprovision/routers.go b/internal/sbi/parameterprovision/routers.go index 601518a..8c37a3e 100644 --- a/internal/sbi/parameterprovision/routers.go +++ b/internal/sbi/parameterprovision/routers.go @@ -16,6 +16,7 @@ import ( "github.com/gin-gonic/gin" "github.com/free5gc/udm/internal/logger" + "github.com/free5gc/udm/pkg/factory" logger_util "github.com/free5gc/util/logger" ) @@ -42,7 +43,7 @@ func NewRouter() *gin.Engine { } func AddService(engine *gin.Engine) *gin.RouterGroup { - group := engine.Group("/nudm-pp/v1") + group := engine.Group(factory.UdmPpResUriPrefix) for _, route := range routes { switch route.Method { diff --git a/internal/sbi/producer/callback/callback.go b/internal/sbi/producer/callback/callback.go index eac3a43..a9dcf98 100644 --- a/internal/sbi/producer/callback/callback.go +++ b/internal/sbi/producer/callback/callback.go @@ -12,7 +12,7 @@ import ( ) func DataChangeNotificationProcedure(notifyItems []models.NotifyItem, supi string) *models.ProblemDetails { - ue, _ := udm_context.UDM_Self().UdmUeFindBySupi(supi) + ue, _ := udm_context.Getself().UdmUeFindBySupi(supi) configuration := Nudm_SubscriberDataManagement.NewConfiguration() clientAPI := Nudm_SubscriberDataManagement.NewAPIClient(configuration) diff --git a/internal/sbi/producer/event_exposure.go b/internal/sbi/producer/event_exposure.go index a974b6e..d588978 100644 --- a/internal/sbi/producer/event_exposure.go +++ b/internal/sbi/producer/event_exposure.go @@ -35,7 +35,7 @@ func HandleCreateEeSubscription(request *httpwrapper.Request) *httpwrapper.Respo func CreateEeSubscriptionProcedure(ueIdentity string, eesubscription models.EeSubscription, ) (*models.CreatedEeSubscription, *models.ProblemDetails) { - udmSelf := udm_context.UDM_Self() + udmSelf := udm_context.Getself() logger.EeLog.Debugf("udIdentity: %s", ueIdentity) switch { @@ -135,7 +135,7 @@ func HandleDeleteEeSubscription(request *httpwrapper.Request) *httpwrapper.Respo // TODO: complete this procedure based on TS 29503 5.5 func DeleteEeSubscriptionProcedure(ueIdentity string, subscriptionID string) { - udmSelf := udm_context.UDM_Self() + udmSelf := udm_context.Getself() switch { case strings.HasPrefix(ueIdentity, "msisdn-"): @@ -186,7 +186,7 @@ func HandleUpdateEeSubscription(request *httpwrapper.Request) *httpwrapper.Respo func UpdateEeSubscriptionProcedure(ueIdentity string, subscriptionID string, patchList []models.PatchItem, ) *models.ProblemDetails { - udmSelf := udm_context.UDM_Self() + udmSelf := udm_context.Getself() switch { case strings.HasPrefix(ueIdentity, "msisdn-"): diff --git a/internal/sbi/producer/generate_auth_data.go b/internal/sbi/producer/generate_auth_data.go index e47161b..79cef93 100644 --- a/internal/sbi/producer/generate_auth_data.go +++ b/internal/sbi/producer/generate_auth_data.go @@ -20,7 +20,6 @@ import ( "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" "github.com/free5gc/udm/pkg/suci" "github.com/free5gc/util/httpwrapper" "github.com/free5gc/util/milenage" @@ -126,7 +125,7 @@ func ConfirmAuthDataProcedure(authEvent models.AuthEvent, supi string) (problemD client, err := createUDMClientToUDR(supi) if err != nil { - return util.ProblemDetailsSystemFailure(err.Error()) + return openapi.ProblemDetailsSystemFailure(err.Error()) } resp, err := client.AuthenticationStatusDocumentApi.CreateAuthenticationStatus( context.Background(), supi, &createAuthParam) @@ -156,7 +155,7 @@ func GenerateAuthDataProcedure(authInfoRequest models.AuthenticationInfoRequest, response = &models.AuthenticationInfoResult{} rand.Seed(time.Now().UnixNano()) - supi, err := suci.ToSupi(supiOrSuci, udm_context.UDM_Self().SuciProfiles) + supi, err := suci.ToSupi(supiOrSuci, udm_context.Getself().SuciProfiles) if err != nil { problemDetails = &models.ProblemDetails{ Status: http.StatusForbidden, @@ -172,7 +171,7 @@ func GenerateAuthDataProcedure(authInfoRequest models.AuthenticationInfoRequest, client, err := createUDMClientToUDR(supi) if err != nil { - return nil, util.ProblemDetailsSystemFailure(err.Error()) + return nil, openapi.ProblemDetailsSystemFailure(err.Error()) } authSubs, res, err := client.AuthenticationDataDocumentApi.QueryAuthSubsData(context.Background(), supi, nil) if err != nil { @@ -418,7 +417,7 @@ func GenerateAuthDataProcedure(authInfoRequest models.AuthenticationInfoRequest, keyIndex) } else { logger.UeauLog.Errorln("Re-Sync Failed UDM Public Key ", - udm_context.UDM_Self().SuciProfiles[keyIndex-1].PublicKey) + udm_context.Getself().SuciProfiles[keyIndex-1].PublicKey) } } logger.UeauLog.Errorln("MACS ", macS) diff --git a/internal/sbi/producer/parameter_provision.go b/internal/sbi/producer/parameter_provision.go index 56c1a42..2d4fea3 100644 --- a/internal/sbi/producer/parameter_provision.go +++ b/internal/sbi/producer/parameter_provision.go @@ -7,7 +7,6 @@ import ( "github.com/free5gc/openapi" "github.com/free5gc/openapi/models" "github.com/free5gc/udm/internal/logger" - "github.com/free5gc/udm/internal/util" "github.com/free5gc/util/httpwrapper" ) @@ -33,7 +32,7 @@ func HandleUpdateRequest(request *httpwrapper.Request) *httpwrapper.Response { func UpdateProcedure(updateRequest models.PpData, gpsi string) (problemDetails *models.ProblemDetails) { clientAPI, err := createUDMClientToUDR(gpsi) if err != nil { - return util.ProblemDetailsSystemFailure(err.Error()) + return openapi.ProblemDetailsSystemFailure(err.Error()) } res, err := clientAPI.ProvisionedParameterDataDocumentApi.ModifyPpData(context.Background(), gpsi, nil) if err != nil { diff --git a/internal/sbi/producer/subscriber_data_management.go b/internal/sbi/producer/subscriber_data_management.go index 0f0c0a6..6a5a6aa 100644 --- a/internal/sbi/producer/subscriber_data_management.go +++ b/internal/sbi/producer/subscriber_data_management.go @@ -16,7 +16,6 @@ import ( "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" "github.com/free5gc/util/httpwrapper" ) @@ -60,7 +59,7 @@ func getAmDataProcedure(supi string, plmnID string, supportedFeatures string) ( clientAPI, err := createUDMClientToUDR(supi) if err != nil { - return nil, util.ProblemDetailsSystemFailure(err.Error()) + return nil, openapi.ProblemDetailsSystemFailure(err.Error()) } accessAndMobilitySubscriptionDataResp, res, err := clientAPI.AccessAndMobilitySubscriptionDataDocumentApi. @@ -86,9 +85,9 @@ func getAmDataProcedure(supi string, plmnID string, supportedFeatures string) ( }() if res.StatusCode == http.StatusOK { - udmUe, ok := udm_context.UDM_Self().UdmUeFindBySupi(supi) + udmUe, ok := udm_context.Getself().UdmUeFindBySupi(supi) if !ok { - udmUe = udm_context.UDM_Self().NewUdmUe(supi) + udmUe = udm_context.Getself().NewUdmUe(supi) } udmUe.SetAMSubsriptionData(&accessAndMobilitySubscriptionDataResp) return &accessAndMobilitySubscriptionDataResp, nil @@ -135,7 +134,7 @@ func getIdTranslationResultProcedure(gpsi string) (response *models.IdTranslatio clientAPI, err := createUDMClientToUDR(gpsi) if err != nil { - return nil, util.ProblemDetailsSystemFailure(err.Error()) + return nil, openapi.ProblemDetailsSystemFailure(err.Error()) } idTranslationResultResp, res, err := clientAPI.QueryIdentityDataBySUPIOrGPSIDocumentApi.GetIdentityData( @@ -233,7 +232,7 @@ func getSupiProcedure(supi string, plmnID string, dataSetNames []string, support clientAPI, err := createUDMClientToUDR(supi) if err != nil { - return nil, util.ProblemDetailsSystemFailure(err.Error()) + return nil, openapi.ProblemDetailsSystemFailure(err.Error()) } var subscriptionDataSets, subsDataSetBody models.SubscriptionDataSets @@ -249,11 +248,11 @@ func getSupiProcedure(supi string, plmnID string, dataSetNames []string, support queryAmDataParamOpts.SupportedFeatures = optional.NewString(supportedFeatures) querySmfSelectDataParamOpts.SupportedFeatures = optional.NewString(supportedFeatures) - udm_context.UDM_Self().CreateSubsDataSetsForUe(supi, subsDataSetBody) + udm_context.Getself().CreateSubsDataSetsForUe(supi, subsDataSetBody) if containDataSetName(dataSetNames, string(models.DataSetName_AM)) { var body models.AccessAndMobilitySubscriptionData - udm_context.UDM_Self().CreateAccessMobilitySubsDataForUe(supi, body) + udm_context.Getself().CreateAccessMobilitySubsDataForUe(supi, body) amData, res, err := clientAPI.AccessAndMobilitySubscriptionDataDocumentApi.QueryAmData( context.Background(), supi, plmnID, &queryAmDataParamOpts) if err != nil { @@ -277,9 +276,9 @@ func getSupiProcedure(supi string, plmnID string, dataSetNames []string, support } }() if res.StatusCode == http.StatusOK { - udmUe, ok := udm_context.UDM_Self().UdmUeFindBySupi(supi) + udmUe, ok := udm_context.Getself().UdmUeFindBySupi(supi) if !ok { - udmUe = udm_context.UDM_Self().NewUdmUe(supi) + udmUe = udm_context.Getself().NewUdmUe(supi) } udmUe.SetAMSubsriptionData(&amData) subscriptionDataSets.AmData = &amData @@ -295,7 +294,7 @@ func getSupiProcedure(supi string, plmnID string, dataSetNames []string, support if containDataSetName(dataSetNames, string(models.DataSetName_SMF_SEL)) { var smfSelSubsbody models.SmfSelectionSubscriptionData - udm_context.UDM_Self().CreateSmfSelectionSubsDataforUe(supi, smfSelSubsbody) + udm_context.Getself().CreateSmfSelectionSubsDataforUe(supi, smfSelSubsbody) smfSelData, res, err := clientAPI.SMFSelectionSubscriptionDataDocumentApi.QuerySmfSelectData(context.Background(), supi, plmnID, &querySmfSelectDataParamOpts) if err != nil { @@ -319,9 +318,9 @@ func getSupiProcedure(supi string, plmnID string, dataSetNames []string, support } }() if res.StatusCode == http.StatusOK { - udmUe, ok := udm_context.UDM_Self().UdmUeFindBySupi(supi) + udmUe, ok := udm_context.Getself().UdmUeFindBySupi(supi) if !ok { - udmUe = udm_context.UDM_Self().NewUdmUe(supi) + udmUe = udm_context.Getself().NewUdmUe(supi) } udmUe.SetSmfSelectionSubsData(&smfSelData) subscriptionDataSets.SmfSelData = &smfSelData @@ -339,7 +338,7 @@ func getSupiProcedure(supi string, plmnID string, dataSetNames []string, support var UeContextInSmfbody models.UeContextInSmfData var querySmfRegListParamOpts Nudr.QuerySmfRegListParamOpts querySmfRegListParamOpts.SupportedFeatures = optional.NewString(supportedFeatures) - udm_context.UDM_Self().CreateUeContextInSmfDataforUe(supi, UeContextInSmfbody) + udm_context.Getself().CreateUeContextInSmfDataforUe(supi, UeContextInSmfbody) pdusess, res, err := clientAPI.SMFRegistrationsCollectionApi.QuerySmfRegList( context.Background(), supi, &querySmfRegListParamOpts) if err != nil { @@ -382,9 +381,9 @@ func getSupiProcedure(supi string, plmnID string, dataSetNames []string, support ueContextInSmfDataResp.PgwInfo = pgwInfoArray if res.StatusCode == http.StatusOK { - udmUe, ok := udm_context.UDM_Self().UdmUeFindBySupi(supi) + udmUe, ok := udm_context.Getself().UdmUeFindBySupi(supi) if !ok { - udmUe = udm_context.UDM_Self().NewUdmUe(supi) + udmUe = udm_context.Getself().NewUdmUe(supi) } udmUe.UeCtxtInSmfData = &ueContextInSmfDataResp subscriptionDataSets.UecSmfData = &ueContextInSmfDataResp @@ -427,11 +426,11 @@ func getSupiProcedure(supi string, plmnID string, dataSetNames []string, support } }() if res.StatusCode == http.StatusOK { - udmUe, ok := udm_context.UDM_Self().UdmUeFindBySupi(supi) + udmUe, ok := udm_context.Getself().UdmUeFindBySupi(supi) if !ok { - udmUe = udm_context.UDM_Self().NewUdmUe(supi) + udmUe = udm_context.Getself().NewUdmUe(supi) } - smData, _, _, _ := udm_context.UDM_Self().ManageSmData(sessionManagementSubscriptionData, "", "") + smData, _, _, _ := udm_context.Getself().ManageSmData(sessionManagementSubscriptionData, "", "") udmUe.SetSMSubsData(smData) subscriptionDataSets.SmData = sessionManagementSubscriptionData } else { @@ -446,7 +445,7 @@ func getSupiProcedure(supi string, plmnID string, dataSetNames []string, support if containDataSetName(dataSetNames, string(models.DataSetName_TRACE)) { var TraceDatabody models.TraceData - udm_context.UDM_Self().CreateTraceDataforUe(supi, TraceDatabody) + udm_context.Getself().CreateTraceDataforUe(supi, TraceDatabody) traceData, res, err := clientAPI.TraceDataDocumentApi.QueryTraceData( context.Background(), supi, plmnID, &queryTraceDataParamOpts) if err != nil { @@ -469,9 +468,9 @@ func getSupiProcedure(supi string, plmnID string, dataSetNames []string, support } }() if res.StatusCode == http.StatusOK { - udmUe, ok := udm_context.UDM_Self().UdmUeFindBySupi(supi) + udmUe, ok := udm_context.Getself().UdmUeFindBySupi(supi) if !ok { - udmUe = udm_context.UDM_Self().NewUdmUe(supi) + udmUe = udm_context.Getself().NewUdmUe(supi) } udmUe.TraceData = &traceData udmUe.TraceDataResponse.TraceData = &traceData @@ -524,7 +523,7 @@ func getSharedDataProcedure(sharedDataIds []string, supportedFeatures string) ( ) { clientAPI, err := createUDMClientToUDR("") if err != nil { - return nil, util.ProblemDetailsSystemFailure(err.Error()) + return nil, openapi.ProblemDetailsSystemFailure(err.Error()) } var getSharedDataParamOpts Nudr.GetSharedDataParamOpts @@ -555,7 +554,7 @@ func getSharedDataProcedure(sharedDataIds []string, supportedFeatures string) ( }() if res.StatusCode == http.StatusOK { - udm_context.UDM_Self().SharedSubsDataMap = udm_context.MappingSharedData(sharedDataResp) + udm_context.Getself().SharedSubsDataMap = udm_context.MappingSharedData(sharedDataResp) sharedData := udm_context.ObtainRequiredSharedData(sharedDataIds, sharedDataResp) return sharedData, nil } else { @@ -608,7 +607,7 @@ func getSmDataProcedure(supi string, plmnID string, Dnn string, Snssai string, s clientAPI, err := createUDMClientToUDR(supi) if err != nil { - return nil, util.ProblemDetailsSystemFailure(err.Error()) + return nil, openapi.ProblemDetailsSystemFailure(err.Error()) } var querySmDataParamOpts Nudr.QuerySmDataParamOpts @@ -639,11 +638,11 @@ func getSmDataProcedure(supi string, plmnID string, Dnn string, Snssai string, s }() if res.StatusCode == http.StatusOK { - udmUe, ok := udm_context.UDM_Self().UdmUeFindBySupi(supi) + udmUe, ok := udm_context.Getself().UdmUeFindBySupi(supi) if !ok { - udmUe = udm_context.UDM_Self().NewUdmUe(supi) + udmUe = udm_context.Getself().NewUdmUe(supi) } - smData, snssaikey, AllDnnConfigsbyDnn, AllDnns := udm_context.UDM_Self().ManageSmData( + smData, snssaikey, AllDnnConfigsbyDnn, AllDnns := udm_context.Getself().ManageSmData( sessionManagementSubscriptionDataResp, Snssai, Dnn) udmUe.SetSMSubsData(smData) @@ -721,7 +720,7 @@ func getNssaiProcedure(supi string, plmnID string, supportedFeatures string) ( var nssaiResp models.Nssai clientAPI, err := createUDMClientToUDR(supi) if err != nil { - return nil, util.ProblemDetailsSystemFailure(err.Error()) + return nil, openapi.ProblemDetailsSystemFailure(err.Error()) } accessAndMobilitySubscriptionDataResp, res, err := clientAPI.AccessAndMobilitySubscriptionDataDocumentApi. @@ -751,9 +750,9 @@ func getNssaiProcedure(supi string, plmnID string, supportedFeatures string) ( nssaiResp = *accessAndMobilitySubscriptionDataResp.Nssai if res.StatusCode == http.StatusOK { - udmUe, ok := udm_context.UDM_Self().UdmUeFindBySupi(supi) + udmUe, ok := udm_context.Getself().UdmUeFindBySupi(supi) if !ok { - udmUe = udm_context.UDM_Self().NewUdmUe(supi) + udmUe = udm_context.Getself().NewUdmUe(supi) } udmUe.Nssai = &nssaiResp return udmUe.Nssai, nil @@ -807,10 +806,10 @@ func getSmfSelectDataProcedure(supi string, plmnID string, supportedFeatures str clientAPI, err := createUDMClientToUDR(supi) if err != nil { - return nil, util.ProblemDetailsSystemFailure(err.Error()) + return nil, openapi.ProblemDetailsSystemFailure(err.Error()) } - udm_context.UDM_Self().CreateSmfSelectionSubsDataforUe(supi, body) + udm_context.Getself().CreateSmfSelectionSubsDataforUe(supi, body) smfSelectionSubscriptionDataResp, res, err := clientAPI.SMFSelectionSubscriptionDataDocumentApi. QuerySmfSelectData(context.Background(), supi, plmnID, &querySmfSelectDataParamOpts) @@ -837,9 +836,9 @@ func getSmfSelectDataProcedure(supi string, plmnID string, supportedFeatures str }() if res.StatusCode == http.StatusOK { - udmUe, ok := udm_context.UDM_Self().UdmUeFindBySupi(supi) + udmUe, ok := udm_context.Getself().UdmUeFindBySupi(supi) if !ok { - udmUe = udm_context.UDM_Self().NewUdmUe(supi) + udmUe = udm_context.Getself().NewUdmUe(supi) } udmUe.SetSmfSelectionSubsData(&smfSelectionSubscriptionDataResp) return udmUe.SmfSelSubsData, nil @@ -905,8 +904,8 @@ func subscribeToSharedDataProcedure(sdmSubscription *models.SdmSubscription) ( if res.StatusCode == http.StatusCreated { header = make(http.Header) - udm_context.UDM_Self().CreateSubstoNotifSharedData(sdmSubscriptionResp.SubscriptionId, &sdmSubscriptionResp) - reourceUri := udm_context.UDM_Self().GetSDMUri() + "//shared-data-subscriptions/" + sdmSubscriptionResp.SubscriptionId + udm_context.Getself().CreateSubstoNotifSharedData(sdmSubscriptionResp.SubscriptionId, &sdmSubscriptionResp) + reourceUri := udm_context.Getself().GetSDMUri() + "//shared-data-subscriptions/" + sdmSubscriptionResp.SubscriptionId header.Set("Location", reourceUri) return header, &sdmSubscriptionResp, nil } else if res.StatusCode == http.StatusNotFound { @@ -955,7 +954,7 @@ func subscribeProcedure(sdmSubscription *models.SdmSubscription, supi string) ( ) { clientAPI, err := createUDMClientToUDR(supi) if err != nil { - return nil, nil, util.ProblemDetailsSystemFailure(err.Error()) + return nil, nil, openapi.ProblemDetailsSystemFailure(err.Error()) } sdmSubscriptionResp, res, err := clientAPI.SDMSubscriptionsCollectionApi.CreateSdmSubscriptions( @@ -983,9 +982,9 @@ func subscribeProcedure(sdmSubscription *models.SdmSubscription, supi string) ( if res.StatusCode == http.StatusCreated { header = make(http.Header) - udmUe, _ := udm_context.UDM_Self().UdmUeFindBySupi(supi) + udmUe, _ := udm_context.Getself().UdmUeFindBySupi(supi) if udmUe == nil { - udmUe = udm_context.UDM_Self().NewUdmUe(supi) + udmUe = udm_context.Getself().NewUdmUe(supi) } udmUe.CreateSubscriptiontoNotifChange(sdmSubscriptionResp.SubscriptionId, &sdmSubscriptionResp) header.Set("Location", udmUe.GetLocationURI2(udm_context.LocationUriSdmSubscription, supi)) @@ -1084,7 +1083,7 @@ func HandleUnsubscribeRequest(request *httpwrapper.Request) *httpwrapper.Respons func unsubscribeProcedure(supi string, subscriptionID string) *models.ProblemDetails { clientAPI, err := createUDMClientToUDR(supi) if err != nil { - return util.ProblemDetailsSystemFailure(err.Error()) + return openapi.ProblemDetailsSystemFailure(err.Error()) } res, err := clientAPI.SDMSubscriptionDocumentApi.RemovesdmSubscriptions(context.Background(), supi, subscriptionID) @@ -1153,7 +1152,7 @@ func modifyProcedure(sdmSubsModification *models.SdmSubsModification, supi strin ) { clientAPI, err := createUDMClientToUDR(supi) if err != nil { - return nil, util.ProblemDetailsSystemFailure(err.Error()) + return nil, openapi.ProblemDetailsSystemFailure(err.Error()) } sdmSubscription := models.SdmSubscription{} @@ -1227,7 +1226,7 @@ func modifyForSharedDataProcedure(sdmSubsModification *models.SdmSubsModificatio ) (response *models.SdmSubscription, problemDetails *models.ProblemDetails) { clientAPI, err := createUDMClientToUDR(supi) if err != nil { - return nil, util.ProblemDetailsSystemFailure(err.Error()) + return nil, openapi.ProblemDetailsSystemFailure(err.Error()) } var sdmSubscription models.SdmSubscription @@ -1303,10 +1302,10 @@ func getTraceDataProcedure(supi string, plmnID string) ( clientAPI, err := createUDMClientToUDR(supi) if err != nil { - return nil, util.ProblemDetailsSystemFailure(err.Error()) + return nil, openapi.ProblemDetailsSystemFailure(err.Error()) } - udm_context.UDM_Self().CreateTraceDataforUe(supi, body) + udm_context.Getself().CreateTraceDataforUe(supi, body) traceDataRes, res, err := clientAPI.TraceDataDocumentApi.QueryTraceData( context.Background(), supi, plmnID, &queryTraceDataParamOpts) @@ -1332,9 +1331,9 @@ func getTraceDataProcedure(supi string, plmnID string) ( }() if res.StatusCode == http.StatusOK { - udmUe, ok := udm_context.UDM_Self().UdmUeFindBySupi(supi) + udmUe, ok := udm_context.Getself().UdmUeFindBySupi(supi) if !ok { - udmUe = udm_context.UDM_Self().NewUdmUe(supi) + udmUe = udm_context.Getself().NewUdmUe(supi) } udmUe.TraceData = &traceDataRes udmUe.TraceDataResponse.TraceData = &traceDataRes @@ -1386,11 +1385,11 @@ func getUeContextInSmfDataProcedure(supi string, supportedFeatures string) ( clientAPI, err := createUDMClientToUDR(supi) if err != nil { - return nil, util.ProblemDetailsSystemFailure(err.Error()) + return nil, openapi.ProblemDetailsSystemFailure(err.Error()) } pduSessionMap := make(map[string]models.PduSession) - udm_context.UDM_Self().CreateUeContextInSmfDataforUe(supi, body) + udm_context.Getself().CreateUeContextInSmfDataforUe(supi, body) pdusess, res, err := clientAPI.SMFRegistrationsCollectionApi.QuerySmfRegList( context.Background(), supi, &querySmfRegListParamOpts) @@ -1435,9 +1434,9 @@ func getUeContextInSmfDataProcedure(supi string, supportedFeatures string) ( ueContextInSmfData.PgwInfo = pgwInfoArray if res.StatusCode == http.StatusOK { - udmUe, ok := udm_context.UDM_Self().UdmUeFindBySupi(supi) + udmUe, ok := udm_context.Getself().UdmUeFindBySupi(supi) if !ok { - udmUe = udm_context.UDM_Self().NewUdmUe(supi) + udmUe = udm_context.Getself().NewUdmUe(supi) } udmUe.UeCtxtInSmfData = &ueContextInSmfData return udmUe.UeCtxtInSmfData, nil diff --git a/internal/sbi/producer/ue_context_management.go b/internal/sbi/producer/ue_context_management.go index 0d0be03..250e2ce 100644 --- a/internal/sbi/producer/ue_context_management.go +++ b/internal/sbi/producer/ue_context_management.go @@ -16,14 +16,13 @@ import ( "github.com/free5gc/udm/internal/logger" "github.com/free5gc/udm/internal/sbi/consumer" "github.com/free5gc/udm/internal/sbi/producer/callback" - "github.com/free5gc/udm/internal/util" "github.com/free5gc/util/httpwrapper" ) func createUDMClientToUDR(id string) (*Nudr_DataRepository.APIClient, error) { uri := getUdrURI(id) if uri == "" { - logger.Handlelog.Errorf("ID[%s] does not match any UDR", id) + logger.ProcLog.Errorf("ID[%s] does not match any UDR", id) return nil, fmt.Errorf("No UDR URI found") } cfg := Nudr_DataRepository.NewConfiguration() @@ -34,20 +33,20 @@ func createUDMClientToUDR(id string) (*Nudr_DataRepository.APIClient, error) { func getUdrURI(id string) string { if strings.Contains(id, "imsi") || strings.Contains(id, "nai") { // supi - ue, ok := udm_context.UDM_Self().UdmUeFindBySupi(id) + ue, ok := udm_context.Getself().UdmUeFindBySupi(id) if ok { if ue.UdrUri == "" { ue.UdrUri = consumer.SendNFIntancesUDR(id, consumer.NFDiscoveryToUDRParamSupi) } return ue.UdrUri } else { - ue = udm_context.UDM_Self().NewUdmUe(id) + ue = udm_context.Getself().NewUdmUe(id) ue.UdrUri = consumer.SendNFIntancesUDR(id, consumer.NFDiscoveryToUDRParamSupi) return ue.UdrUri } } else if strings.Contains(id, "pei") { var udrURI string - udm_context.UDM_Self().UdmUePool.Range(func(key, value interface{}) bool { + udm_context.Getself().UdmUePool.Range(func(key, value interface{}) bool { ue := value.(*udm_context.UdmUeContext) if ue.Amf3GppAccessRegistration != nil && ue.Amf3GppAccessRegistration.Pei == id { if ue.UdrUri == "" { @@ -108,7 +107,7 @@ func GetAmf3gppAccessProcedure(ueID string, supportedFeatures string) ( clientAPI, err := createUDMClientToUDR(ueID) if err != nil { - return nil, util.ProblemDetailsSystemFailure(err.Error()) + return nil, openapi.ProblemDetailsSystemFailure(err.Error()) } amf3GppAccessRegistration, resp, err := clientAPI.AMF3GPPAccessRegistrationDocumentApi. @@ -163,7 +162,7 @@ func GetAmfNon3gppAccessProcedure(queryAmfContextNon3gppParamOpts Nudr_DataRepos ) { clientAPI, err := createUDMClientToUDR(ueID) if err != nil { - return nil, util.ProblemDetailsSystemFailure(err.Error()) + return nil, openapi.ProblemDetailsSystemFailure(err.Error()) } amfNon3GppAccessRegistration, resp, err := clientAPI.AMFNon3GPPAccessRegistrationDocumentApi. @@ -214,16 +213,16 @@ func RegistrationAmf3gppAccessProcedure(registerRequest models.Amf3GppAccessRegi ) { // TODO: EPS interworking with N26 is not supported yet in this stage var oldAmf3GppAccessRegContext *models.Amf3GppAccessRegistration - if udm_context.UDM_Self().UdmAmf3gppRegContextExists(ueID) { - ue, _ := udm_context.UDM_Self().UdmUeFindBySupi(ueID) + if udm_context.Getself().UdmAmf3gppRegContextExists(ueID) { + ue, _ := udm_context.Getself().UdmUeFindBySupi(ueID) oldAmf3GppAccessRegContext = ue.Amf3GppAccessRegistration } - udm_context.UDM_Self().CreateAmf3gppRegContext(ueID, registerRequest) + udm_context.Getself().CreateAmf3gppRegContext(ueID, registerRequest) clientAPI, err := createUDMClientToUDR(ueID) if err != nil { - return nil, nil, util.ProblemDetailsSystemFailure(err.Error()) + return nil, nil, openapi.ProblemDetailsSystemFailure(err.Error()) } var createAmfContext3gppParamOpts Nudr_DataRepository.CreateAmfContext3gppParamOpts @@ -259,7 +258,7 @@ func RegistrationAmf3gppAccessProcedure(registerRequest models.Amf3GppAccessRegi return nil, nil, nil } else { header = make(http.Header) - udmUe, _ := udm_context.UDM_Self().UdmUeFindBySupi(ueID) + udmUe, _ := udm_context.Getself().UdmUeFindBySupi(ueID) header.Set("Location", udmUe.GetLocationURI(udm_context.LocationUriAmf3GppAccessRegistration)) return header, ®isterRequest, nil } @@ -292,16 +291,16 @@ func RegisterAmfNon3gppAccessProcedure(registerRequest models.AmfNon3GppAccessRe header http.Header, response *models.AmfNon3GppAccessRegistration, problemDetails *models.ProblemDetails, ) { var oldAmfNon3GppAccessRegContext *models.AmfNon3GppAccessRegistration - if udm_context.UDM_Self().UdmAmfNon3gppRegContextExists(ueID) { - ue, _ := udm_context.UDM_Self().UdmUeFindBySupi(ueID) + if udm_context.Getself().UdmAmfNon3gppRegContextExists(ueID) { + ue, _ := udm_context.Getself().UdmUeFindBySupi(ueID) oldAmfNon3GppAccessRegContext = ue.AmfNon3GppAccessRegistration } - udm_context.UDM_Self().CreateAmfNon3gppRegContext(ueID, registerRequest) + udm_context.Getself().CreateAmfNon3gppRegContext(ueID, registerRequest) clientAPI, err := createUDMClientToUDR(ueID) if err != nil { - return nil, nil, util.ProblemDetailsSystemFailure(err.Error()) + return nil, nil, openapi.ProblemDetailsSystemFailure(err.Error()) } var createAmfContextNon3gppParamOpts Nudr_DataRepository.CreateAmfContextNon3gppParamOpts @@ -336,7 +335,7 @@ func RegisterAmfNon3gppAccessProcedure(registerRequest models.AmfNon3GppAccessRe return nil, nil, nil } else { header = make(http.Header) - udmUe, _ := udm_context.UDM_Self().UdmUeFindBySupi(ueID) + udmUe, _ := udm_context.Getself().UdmUeFindBySupi(ueID) header.Set("Location", udmUe.GetLocationURI(udm_context.LocationUriAmfNon3GppAccessRegistration)) return header, ®isterRequest, nil } @@ -366,7 +365,7 @@ func UpdateAmf3gppAccessProcedure(request models.Amf3GppAccessRegistrationModifi problemDetails *models.ProblemDetails, ) { var patchItemReqArray []models.PatchItem - currentContext := udm_context.UDM_Self().GetAmf3gppRegContext(ueID) + currentContext := udm_context.Getself().GetAmf3gppRegContext(ueID) if currentContext == nil { logger.UecmLog.Errorln("[UpdateAmf3gppAccess] Empty Amf3gppRegContext") problemDetails = &models.ProblemDetails{ @@ -377,7 +376,7 @@ func UpdateAmf3gppAccessProcedure(request models.Amf3GppAccessRegistrationModifi } if request.Guami != nil { - udmUe, _ := udm_context.UDM_Self().UdmUeFindBySupi(ueID) + udmUe, _ := udm_context.Getself().UdmUeFindBySupi(ueID) if udmUe.SameAsStoredGUAMI3gpp(*request.Guami) { // deregistration logger.UecmLog.Infoln("UpdateAmf3gppAccess - deregistration") request.PurgeFlag = true @@ -431,7 +430,7 @@ func UpdateAmf3gppAccessProcedure(request models.Amf3GppAccessRegistrationModifi clientAPI, err := createUDMClientToUDR(ueID) if err != nil { - return util.ProblemDetailsSystemFailure(err.Error()) + return openapi.ProblemDetailsSystemFailure(err.Error()) } resp, err := clientAPI.AMF3GPPAccessRegistrationDocumentApi.AmfContext3gpp(context.Background(), ueID, @@ -447,7 +446,7 @@ func UpdateAmf3gppAccessProcedure(request models.Amf3GppAccessRegistrationModifi } if request.PurgeFlag { - udmUe, _ := udm_context.UDM_Self().UdmUeFindBySupi(ueID) + udmUe, _ := udm_context.Getself().UdmUeFindBySupi(ueID) udmUe.Amf3GppAccessRegistration = nil } @@ -484,7 +483,7 @@ func UpdateAmfNon3gppAccessProcedure(request models.AmfNon3GppAccessRegistration problemDetails *models.ProblemDetails, ) { var patchItemReqArray []models.PatchItem - currentContext := udm_context.UDM_Self().GetAmfNon3gppRegContext(ueID) + currentContext := udm_context.Getself().GetAmfNon3gppRegContext(ueID) if currentContext == nil { logger.UecmLog.Errorln("[UpdateAmfNon3gppAccess] Empty AmfNon3gppRegContext") problemDetails = &models.ProblemDetails{ @@ -495,7 +494,7 @@ func UpdateAmfNon3gppAccessProcedure(request models.AmfNon3GppAccessRegistration } if request.Guami != nil { - udmUe, _ := udm_context.UDM_Self().UdmUeFindBySupi(ueID) + udmUe, _ := udm_context.Getself().UdmUeFindBySupi(ueID) if udmUe.SameAsStoredGUAMINon3gpp(*request.Guami) { // deregistration logger.UecmLog.Infoln("UpdateAmfNon3gppAccess - deregistration") request.PurgeFlag = true @@ -548,7 +547,7 @@ func UpdateAmfNon3gppAccessProcedure(request models.AmfNon3GppAccessRegistration clientAPI, err := createUDMClientToUDR(ueID) if err != nil { - return util.ProblemDetailsSystemFailure(err.Error()) + return openapi.ProblemDetailsSystemFailure(err.Error()) } resp, err := clientAPI.AMFNon3GPPAccessRegistrationDocumentApi.AmfContextNon3gpp(context.Background(), @@ -592,7 +591,7 @@ func HandleDeregistrationSmfRegistrations(request *httpwrapper.Request) *httpwra func DeregistrationSmfRegistrationsProcedure(ueID string, pduSessionID string) (problemDetails *models.ProblemDetails) { clientAPI, err := createUDMClientToUDR(ueID) if err != nil { - return util.ProblemDetailsSystemFailure(err.Error()) + return openapi.ProblemDetailsSystemFailure(err.Error()) } resp, err := clientAPI.SMFRegistrationDocumentApi.DeleteSmfContext(context.Background(), ueID, pduSessionID) @@ -643,8 +642,8 @@ func RegistrationSmfRegistrationsProcedure(request *models.SmfRegistration, ueID header http.Header, response *models.SmfRegistration, problemDetails *models.ProblemDetails, ) { contextExisted := false - udm_context.UDM_Self().CreateSmfRegContext(ueID, pduSessionID) - if !udm_context.UDM_Self().UdmSmfRegContextNotExists(ueID) { + udm_context.Getself().CreateSmfRegContext(ueID, pduSessionID) + if !udm_context.Getself().UdmSmfRegContextNotExists(ueID) { contextExisted = true } @@ -660,7 +659,7 @@ func RegistrationSmfRegistrationsProcedure(request *models.SmfRegistration, ueID clientAPI, err := createUDMClientToUDR(ueID) if err != nil { - return nil, nil, util.ProblemDetailsSystemFailure(err.Error()) + return nil, nil, openapi.ProblemDetailsSystemFailure(err.Error()) } resp, err := clientAPI.SMFRegistrationDocumentApi.CreateSmfContextNon3gpp(context.Background(), ueID, @@ -684,7 +683,7 @@ func RegistrationSmfRegistrationsProcedure(request *models.SmfRegistration, ueID return nil, nil, nil } else { header = make(http.Header) - udmUe, _ := udm_context.UDM_Self().UdmUeFindBySupi(ueID) + udmUe, _ := udm_context.Getself().UdmUeFindBySupi(ueID) header.Set("Location", udmUe.GetLocationURI(udm_context.LocationUriSmfRegistration)) return header, request, nil } diff --git a/internal/sbi/subscriberdatamanagement/routers.go b/internal/sbi/subscriberdatamanagement/routers.go index 0d8a0e6..7624eb6 100644 --- a/internal/sbi/subscriberdatamanagement/routers.go +++ b/internal/sbi/subscriberdatamanagement/routers.go @@ -16,6 +16,7 @@ import ( "github.com/gin-gonic/gin" "github.com/free5gc/udm/internal/logger" + "github.com/free5gc/udm/pkg/factory" logger_util "github.com/free5gc/util/logger" ) @@ -125,7 +126,7 @@ func threeLayerPathHandlerFunc(c *gin.Context) { } func AddService(engine *gin.Engine) *gin.RouterGroup { - group := engine.Group("/nudm-sdm/v1") + group := engine.Group(factory.UdmSdmResUriPrefix) for _, route := range routes { switch route.Method { diff --git a/internal/sbi/ueauthentication/routers.go b/internal/sbi/ueauthentication/routers.go index ec25a32..dda263f 100644 --- a/internal/sbi/ueauthentication/routers.go +++ b/internal/sbi/ueauthentication/routers.go @@ -17,6 +17,7 @@ import ( "github.com/sirupsen/logrus" "github.com/free5gc/udm/internal/logger" + "github.com/free5gc/udm/pkg/factory" logger_util "github.com/free5gc/util/logger" ) @@ -59,7 +60,7 @@ func genAuthDataHandlerFunc(c *gin.Context) { } func AddService(engine *gin.Engine) *gin.RouterGroup { - group := engine.Group("/nudm-ueau/v1") + group := engine.Group(factory.UdmUeauResUriPrefix) for _, route := range routes { switch route.Method { diff --git a/internal/sbi/uecontextmanagement/routers.go b/internal/sbi/uecontextmanagement/routers.go index c609161..493d592 100644 --- a/internal/sbi/uecontextmanagement/routers.go +++ b/internal/sbi/uecontextmanagement/routers.go @@ -16,6 +16,7 @@ import ( "github.com/gin-gonic/gin" "github.com/free5gc/udm/internal/logger" + "github.com/free5gc/udm/pkg/factory" logger_util "github.com/free5gc/util/logger" ) @@ -42,7 +43,7 @@ func NewRouter() *gin.Engine { } func AddService(engine *gin.Engine) *gin.RouterGroup { - group := engine.Group("/nudm-uecm/v1") + group := engine.Group(factory.UdmUecmResUriPrefix) for _, route := range routes { switch route.Method { diff --git a/pkg/factory/config.go b/pkg/factory/config.go index d5ef6c8..0b67bf7 100644 --- a/pkg/factory/config.go +++ b/pkg/factory/config.go @@ -6,64 +6,69 @@ package factory import ( "fmt" + "sync" "github.com/asaskevich/govalidator" + "github.com/free5gc/udm/internal/logger" "github.com/free5gc/udm/pkg/suci" - logger_util "github.com/free5gc/util/logger" ) const ( - UdmExpectedConfigVersion = "1.0.2" - UdmSbiDefaultIPv4 = "127.0.0.3" - UdmSbiDefaultPort = 8000 + UdmDefaultTLSKeyLogPath = "./log/udmsslkey.log" + UdmDefaultCertPemPath = "./cert/udm.pem" + UdmDefaultPrivateKeyPath = "./cert/udm.key" + UdmDefaultConfigPath = "./config/udmcfg.yaml" + UdmSbiDefaultIPv4 = "127.0.0.3" + UdmSbiDefaultPort = 8000 + UdmSbiDefaultScheme = "https" + UdmDefaultNrfUri = "https://127.0.0.10:8000" + UdmSorprotectionResUriPrefix = "/nudm-sorprotection/v1" + UdmAuthResUriPrefix = "/nudm-auth/v1" + UdmfUpuprotectionResUriPrefix = "/nudm-upuprotection/v1" + UdmEcmResUriPrefix = "/nudm-ecm/v1" + UdmSdmResUriPrefix = "/nudm-sdm/v1" + UdmEeResUriPrefix = "/nudm-ee/v1" + UdmDrResUriPrefix = "/nudr-dr/v1" + UdmUecmResUriPrefix = "/nudm-uecm/v1" + UdmPpResUriPrefix = "/nudm-pp/v1" + UdmUeauResUriPrefix = "/nudm-ueau/v1" ) type Config struct { - Info *Info `yaml:"info" valid:"required"` - Configuration *Configuration `yaml:"configuration" valid:"required"` - Logger *logger_util.Logger `yaml:"logger" valid:"optional"` + Info *Info `yaml:"info" valid:"required"` + Configuration *Configuration `yaml:"configuration" valid:"required"` + Logger *Logger `yaml:"logger" valid:"required"` + sync.RWMutex } func (c *Config) Validate() (bool, error) { - if info := c.Info; info != nil { - if result, err := info.validate(); err != nil { - return result, err - } - } - if configuration := c.Configuration; configuration != nil { if result, err := configuration.validate(); err != nil { return result, err } } - if logger := c.Logger; logger != nil { - if result, err := logger.Validate(); err != nil { - return result, err - } - } - result, err := govalidator.ValidateStruct(c) return result, appendInvalid(err) } type Info struct { - Version string `yaml:"version,omitempty" valid:"type(string)"` + Version string `yaml:"version,omitempty" valid:"required,in(1.0.3)"` Description string `yaml:"description,omitempty" valid:"type(string)"` } -func (i *Info) validate() (bool, error) { - result, err := govalidator.ValidateStruct(i) - return result, appendInvalid(err) -} - type Configuration struct { Sbi *Sbi `yaml:"sbi,omitempty" valid:"required"` ServiceNameList []string `yaml:"serviceNameList,omitempty" valid:"required"` NrfUri string `yaml:"nrfUri,omitempty" valid:"required, url"` SuciProfiles []suci.SuciProfile `yaml:"SuciProfile,omitempty"` } +type Logger struct { + Enable bool `yaml:"enable" valid:"type(bool)"` + Level string `yaml:"level" valid:"required,in(trace|debug|info|warn|error|fatal|panic)"` + ReportCaller bool `yaml:"reportCaller" valid:"type(bool)"` +} func (c *Configuration) validate() (bool, error) { if sbi := c.Sbi; sbi != nil { @@ -167,8 +172,85 @@ func appendInvalid(err error) error { } func (c *Config) GetVersion() string { - if c.Info != nil && c.Info.Version != "" { + c.RLock() + defer c.RUnlock() + + if c.Info.Version != "" { return c.Info.Version } return "" } + +func (c *Config) SetLogEnable(enable bool) { + c.Lock() + defer c.Unlock() + + if c.Logger == nil { + logger.CfgLog.Warnf("Logger should not be nil") + c.Logger = &Logger{ + Enable: enable, + Level: "info", + } + } else { + c.Logger.Enable = enable + } +} + +func (c *Config) SetLogLevel(level string) { + c.Lock() + defer c.Unlock() + + if c.Logger == nil { + logger.CfgLog.Warnf("Logger should not be nil") + c.Logger = &Logger{ + Level: level, + } + } else { + c.Logger.Level = level + } +} + +func (c *Config) SetLogReportCaller(reportCaller bool) { + c.Lock() + defer c.Unlock() + + if c.Logger == nil { + logger.CfgLog.Warnf("Logger should not be nil") + c.Logger = &Logger{ + Level: "info", + ReportCaller: reportCaller, + } + } else { + c.Logger.ReportCaller = reportCaller + } +} + +func (c *Config) GetLogEnable() bool { + c.RLock() + defer c.RUnlock() + if c.Logger == nil { + logger.CfgLog.Warnf("Logger should not be nil") + return false + } + return c.Logger.Enable +} + +func (c *Config) GetLogLevel() string { + c.RLock() + defer c.RUnlock() + if c.Logger == nil { + logger.CfgLog.Warnf("Logger should not be nil") + return "info" + } + return c.Logger.Level +} + +func (c *Config) GetLogReportCaller() bool { + c.RLock() + defer c.RUnlock() + if c.Logger == nil { + logger.CfgLog.Warnf("Logger should not be nil") + return false + } + return c.Logger.ReportCaller +} diff --git a/pkg/factory/factory.go b/pkg/factory/factory.go index 0745635..c35621b 100644 --- a/pkg/factory/factory.go +++ b/pkg/factory/factory.go @@ -8,37 +8,45 @@ import ( "fmt" "io/ioutil" + "github.com/asaskevich/govalidator" "gopkg.in/yaml.v2" "github.com/free5gc/udm/internal/logger" ) -var UdmConfig Config +var UdmConfig *Config // TODO: Support configuration update from REST api -func InitConfigFactory(f string) error { +func InitConfigFactory(f string, cfg *Config) error { + if f == "" { + // Use default config path + f = UdmDefaultConfigPath + } if content, err := ioutil.ReadFile(f); err != nil { - return err + return fmt.Errorf("[Factory] %+v", err) } else { - UdmConfig = Config{} - - if yamlErr := yaml.Unmarshal(content, &UdmConfig); yamlErr != nil { - return yamlErr + logger.CfgLog.Infof("Read config from [%s]", f) + if yamlErr := yaml.Unmarshal(content, cfg); yamlErr != nil { + return fmt.Errorf("[Factory] %+v", yamlErr) } } return nil } -func CheckConfigVersion() error { - currentVersion := UdmConfig.GetVersion() - - if currentVersion != UdmExpectedConfigVersion { - return fmt.Errorf("config version is [%s], but expected is [%s].", - currentVersion, UdmExpectedConfigVersion) +func ReadConfig(cfgPath string) (*Config, error) { + cfg := &Config{} + if err := InitConfigFactory(cfgPath, cfg); err != nil { + return nil, fmt.Errorf("ReadConfig [%s] Error: %+v", cfgPath, err) + } + if _, err := cfg.Validate(); err != nil { + validErrs := err.(govalidator.Errors).Errors() + for _, validErr := range validErrs { + logger.CfgLog.Errorf("%+v", validErr) + } + logger.CfgLog.Errorf("[-- PLEASE REFER TO SAMPLE CONFIG FILE COMMENTS --]") + return nil, fmt.Errorf("Config validate Error") } - logger.CfgLog.Infof("config version [%s]", currentVersion) - - return nil + return cfg, nil } diff --git a/pkg/service/init.go b/pkg/service/init.go index f753866..aa30c42 100644 --- a/pkg/service/init.go +++ b/pkg/service/init.go @@ -1,19 +1,16 @@ package service import ( - "bufio" "fmt" + "io/ioutil" "os" - "os/exec" "os/signal" "runtime/debug" - "sync" "syscall" "github.com/sirupsen/logrus" - "github.com/urfave/cli" - "github.com/free5gc/udm/internal/context" + 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/eventexposure" @@ -22,114 +19,71 @@ import ( "github.com/free5gc/udm/internal/sbi/subscriberdatamanagement" "github.com/free5gc/udm/internal/sbi/ueauthentication" "github.com/free5gc/udm/internal/sbi/uecontextmanagement" - "github.com/free5gc/udm/internal/util" "github.com/free5gc/udm/pkg/factory" "github.com/free5gc/util/httpwrapper" logger_util "github.com/free5gc/util/logger" ) -type UDM struct { - KeyLogPath string +type UdmApp struct { + cfg *factory.Config + udmCtx *udm_context.UDMContext } -type ( - // Commands information. - Commands struct { - config string - } -) - -var commands Commands - -var cliCmd = []cli.Flag{ - cli.StringFlag{ - Name: "config, c", - Usage: "Load configuration from `FILE`", - }, - cli.StringFlag{ - Name: "log, l", - Usage: "Output NF log to `FILE`", - }, - cli.StringFlag{ - Name: "log5gc, lc", - Usage: "Output free5gc log to `FILE`", - }, +func NewApp(cfg *factory.Config) (*UdmApp, error) { + udm := &UdmApp{cfg: cfg} + udm.SetLogEnable(cfg.GetLogEnable()) + udm.SetLogLevel(cfg.GetLogLevel()) + udm.SetReportCaller(cfg.GetLogReportCaller()) + udm_context.Init() + udm.udmCtx = udm_context.Getself() + return udm, nil } -func (*UDM) GetCliCmd() (flags []cli.Flag) { - return cliCmd -} - -func (udm *UDM) Initialize(c *cli.Context) error { - commands = Commands{ - config: c.String("config"), +func (a *UdmApp) SetLogEnable(enable bool) { + logger.MainLog.Infof("Log enable is set to [%v]", enable) + if enable && logger.Log.Out == os.Stderr { + return + } else if !enable && logger.Log.Out == ioutil.Discard { + return } - if commands.config != "" { - if err := factory.InitConfigFactory(commands.config); err != nil { - return err - } + a.cfg.SetLogEnable(enable) + if enable { + logger.Log.SetOutput(os.Stderr) } else { - if err := factory.InitConfigFactory(util.UdmDefaultConfigPath); err != nil { - return err - } - } - - if err := factory.CheckConfigVersion(); err != nil { - return err - } - - if _, validErr := factory.UdmConfig.Validate(); validErr != nil { - return validErr + logger.Log.SetOutput(ioutil.Discard) } - - udm.SetLogLevel() - - return nil } -func (udm *UDM) SetLogLevel() { - if factory.UdmConfig.Logger == nil { - logger.InitLog.Warnln("UDM config without log level setting!!!") +func (a *UdmApp) SetLogLevel(level string) { + lvl, err := logrus.ParseLevel(level) + if err != nil { + logger.MainLog.Warnf("Log level [%s] is invalid", level) return } - if factory.UdmConfig.Logger.UDM != nil { - if factory.UdmConfig.Logger.UDM.DebugLevel != "" { - if level, err := logrus.ParseLevel(factory.UdmConfig.Logger.UDM.DebugLevel); err != nil { - logger.InitLog.Warnf("UDM Log level [%s] is invalid, set to [info] level", - factory.UdmConfig.Logger.UDM.DebugLevel) - logger.SetLogLevel(logrus.InfoLevel) - } else { - logger.InitLog.Infof("UDM Log level is set to [%s] level", level) - logger.SetLogLevel(level) - } - } else { - logger.InitLog.Infoln("UDM Log level is default set to [info] level") - logger.SetLogLevel(logrus.InfoLevel) - } - logger.SetReportCaller(factory.UdmConfig.Logger.UDM.ReportCaller) + logger.MainLog.Infof("Log level is set to [%s]", level) + if lvl == logger.Log.GetLevel() { + return } -} -func (udm *UDM) FilterCli(c *cli.Context) (args []string) { - for _, flag := range udm.GetCliCmd() { - name := flag.GetName() - value := fmt.Sprint(c.Generic(name)) - if value == "" { - continue - } + a.cfg.SetLogLevel(level) + logger.Log.SetLevel(lvl) +} - args = append(args, "--"+name, value) +func (a *UdmApp) SetReportCaller(reportCaller bool) { + logger.MainLog.Infof("Report Caller is set to [%v]", reportCaller) + if reportCaller == logger.Log.ReportCaller { + return } - return args + a.cfg.SetLogReportCaller(reportCaller) + logger.Log.SetReportCaller(reportCaller) } -func (udm *UDM) Start() { +func (a *UdmApp) Start(tlsKeyLogPath string) { config := factory.UdmConfig configuration := config.Configuration sbi := configuration.Sbi - serviceName := configuration.ServiceNameList logger.InitLog.Infof("UDM Config Info: Version[%s] Description[%s]", config.Info.Version, config.Info.Description) @@ -144,16 +98,15 @@ func (udm *UDM) Start() { ueauthentication.AddService(router) uecontextmanagement.AddService(router) - pemPath := util.UdmDefaultPemPath - keyPath := util.UdmDefaultKeyPath + pemPath := factory.UdmDefaultCertPemPath + keyPath := factory.UdmDefaultPrivateKeyPath if sbi.Tls != nil { pemPath = sbi.Tls.Pem keyPath = sbi.Tls.Key } - self := context.UDM_Self() - util.InitUDMContext(self) - context.UDM_Self().InitNFService(serviceName, config.Info.Version) + self := a.udmCtx + udm_context.InitUdmContext(self) addr := fmt.Sprintf("%s:%d", self.BindingIPv4, self.SBIPort) @@ -182,11 +135,11 @@ func (udm *UDM) Start() { }() <-signalChannel - udm.Terminate() + a.Terminate() os.Exit(0) }() - server, err := httpwrapper.NewHttp2Server(addr, udm.KeyLogPath, router) + server, err := httpwrapper.NewHttp2Server(addr, tlsKeyLogPath, router) if server == nil { logger.InitLog.Errorf("Initialize HTTP server failed: %+v", err) return @@ -208,74 +161,7 @@ func (udm *UDM) Start() { } } -func (udm *UDM) Exec(c *cli.Context) error { - // UDM.Initialize(cfgPath, c) - - logger.InitLog.Traceln("args:", c.String("udmcfg")) - args := udm.FilterCli(c) - logger.InitLog.Traceln("filter: ", args) - command := exec.Command("./udm", args...) - - stdout, err := command.StdoutPipe() - if err != nil { - logger.InitLog.Fatalln(err) - } - wg := sync.WaitGroup{} - wg.Add(3) - go func() { - defer func() { - if p := recover(); p != nil { - // Print stack for panic to log. Fatalf() will let program exit. - logger.InitLog.Fatalf("panic: %v\n%s", p, string(debug.Stack())) - } - }() - - in := bufio.NewScanner(stdout) - for in.Scan() { - fmt.Println(in.Text()) - } - wg.Done() - }() - - stderr, err := command.StderrPipe() - if err != nil { - logger.InitLog.Fatalln(err) - } - go func() { - defer func() { - if p := recover(); p != nil { - // Print stack for panic to log. Fatalf() will let program exit. - logger.InitLog.Fatalf("panic: %v\n%s", p, string(debug.Stack())) - } - }() - - in := bufio.NewScanner(stderr) - for in.Scan() { - fmt.Println(in.Text()) - } - wg.Done() - }() - - go func() { - defer func() { - if p := recover(); p != nil { - // Print stack for panic to log. Fatalf() will let program exit. - logger.InitLog.Fatalf("panic: %v\n%s", p, string(debug.Stack())) - } - }() - - if err = command.Start(); err != nil { - fmt.Printf("UDM Start error: %v", err) - } - wg.Done() - }() - - wg.Wait() - - return err -} - -func (udm *UDM) Terminate() { +func (a *UdmApp) Terminate() { logger.InitLog.Infof("Terminating UDM...") // deregister with NRF problemDetails, err := consumer.SendDeregisterNFInstance()