diff --git a/Dockerfile b/Dockerfile index 8eb08e0..a5fcd0c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,8 +6,6 @@ FROM golang:1.23.2-bookworm AS builder -LABEL maintainer="Aether SD-Core " - RUN apt-get update && \ apt-get -y install --no-install-recommends \ apt-transport-https \ @@ -22,12 +20,14 @@ RUN apt-get update && \ apt-get clean WORKDIR $GOPATH/src/udr + COPY . . RUN make all FROM alpine:3.20 AS udr -LABEL description="ONF open source 5G Core Network" \ +LABEL maintainer="Aether SD-Core " \ + description="ONF open source 5G Core Network" \ version="Stage 3" ARG DEBUG_TOOLS @@ -37,8 +37,5 @@ RUN if [ "$DEBUG_TOOLS" = "true" ]; then \ apk update && apk add --no-cache -U vim strace net-tools curl netcat-openbsd bind-tools; \ fi -# Set working dir -WORKDIR /free5gc/udr - -# Copy executable and default certs -COPY --from=builder /go/src/udr/bin/* . +# Copy executable +COPY --from=builder /go/src/udr/bin/* /usr/local/bin/. diff --git a/factory/config.go b/factory/config.go index bdc4259..638901f 100644 --- a/factory/config.go +++ b/factory/config.go @@ -25,6 +25,7 @@ type Config struct { Info *Info `yaml:"info"` Configuration *Configuration `yaml:"configuration"` Logger *utilLogger.Logger `yaml:"logger"` + CfgLocation string } type Info struct { @@ -108,15 +109,15 @@ func (c *Config) addSmPolicyInfo(nwSlice *protos.NetworkSlice, dbUpdateChannel c func (c *Config) updateConfig(commChannel chan *protos.NetworkSliceResponse, dbUpdateChannel chan *UpdateDb) bool { var minConfig bool for rsp := range commChannel { - logger.GrpcLog.Infoln("Received updateConfig in the udr app : ", rsp) + logger.GrpcLog.Infoln("received updateConfig in the udr app:", rsp) for _, ns := range rsp.NetworkSlice { - logger.GrpcLog.Infoln("Network Slice Name ", ns.Name) + logger.GrpcLog.Infoln("network slice name", ns.Name) if ns.Site != nil { - logger.GrpcLog.Infoln("Network Slice has site name present ") + logger.GrpcLog.Infoln("network slice has site name present") site := ns.Site - logger.GrpcLog.Infoln("Site name ", site.SiteName) + logger.GrpcLog.Infoln("site name", site.SiteName) if site.Plmn != nil { - logger.GrpcLog.Infoln("Plmn mcc ", site.Plmn.Mcc) + logger.GrpcLog.Infoln("plmn mcc", site.Plmn.Mcc) plmn := PlmnSupportItem{} plmn.PlmnId.Mnc = site.Plmn.Mnc plmn.PlmnId.Mcc = site.Plmn.Mcc @@ -131,12 +132,12 @@ func (c *Config) updateConfig(commChannel chan *protos.NetworkSliceResponse, dbU UdrConfig.Configuration.PlmnSupportList = append(UdrConfig.Configuration.PlmnSupportList, plmn) } } else { - logger.GrpcLog.Infoln("Plmn not present in the message ") + logger.GrpcLog.Infoln("plmn not present in the message") } } err := c.addSmPolicyInfo(ns, dbUpdateChannel) if err != nil { - logger.GrpcLog.Errorf("Error in adding sm policy info to db %v", err) + logger.GrpcLog.Errorf("error in adding sm policy info to db %v", err) } } if !minConfig { @@ -144,17 +145,17 @@ func (c *Config) updateConfig(commChannel chan *protos.NetworkSliceResponse, dbU if len(UdrConfig.Configuration.PlmnSupportList) > 0 { minConfig = true ConfigPodTrigger <- true - logger.GrpcLog.Infoln("Send config trigger to main routine") + logger.GrpcLog.Infoln("send config trigger to main routine") } } else { // all slices deleted if len(UdrConfig.Configuration.PlmnSupportList) == 0 { minConfig = false ConfigPodTrigger <- false - logger.GrpcLog.Infoln("Send config trigger to main routine") + logger.GrpcLog.Infoln("send config trigger to main routine") } else { ConfigPodTrigger <- true - logger.GrpcLog.Infoln("Send config trigger to main routine") + logger.GrpcLog.Infoln("send config trigger to main routine") } } } diff --git a/factory/config.example.yaml b/factory/udr_config.yaml similarity index 96% rename from factory/config.example.yaml rename to factory/udr_config.yaml index fcbead4..1bf1b48 100644 --- a/factory/config.example.yaml +++ b/factory/udr_config.yaml @@ -13,7 +13,7 @@ configuration: bindingIPv4: 0.0.0.0 port: 8000 mongodb: - name: free5gc + name: aether url: http://dummy authKeysDbName: authentication authUrl: http://dummy diff --git a/factory/udr_config_test.go b/factory/udr_config_test.go index 24d525e..acddd16 100644 --- a/factory/udr_config_test.go +++ b/factory/udr_config_test.go @@ -15,7 +15,7 @@ import ( // Webui URL is not set then default Webui URL value is returned func TestGetDefaultWebuiUrl(t *testing.T) { - if err := InitConfigFactory("config.example.yaml"); err != nil { + if err := InitConfigFactory("udr_config.yaml"); err != nil { logger.CfgLog.Errorf("error in InitConfigFactory: %v", err) } got := UdrConfig.Configuration.WebuiUri diff --git a/factory/udr_config_with_custom_webui_url.yaml b/factory/udr_config_with_custom_webui_url.yaml index ef46603..c14500c 100644 --- a/factory/udr_config_with_custom_webui_url.yaml +++ b/factory/udr_config_with_custom_webui_url.yaml @@ -13,7 +13,7 @@ configuration: bindingIPv4: 0.0.0.0 port: 8000 mongodb: - name: free5gc + name: aether url: http://dummy authKeysDbName: authentication authUrl: http://dummy diff --git a/service/init.go b/service/init.go index a23d736..3a90f77 100644 --- a/service/init.go +++ b/service/init.go @@ -13,6 +13,7 @@ import ( "os" "os/exec" "os/signal" + "path/filepath" "sync" "syscall" "time" @@ -28,7 +29,6 @@ import ( "github.com/omec-project/udr/util" "github.com/omec-project/util/http2_util" utilLogger "github.com/omec-project/util/logger" - "github.com/omec-project/util/path_util" "github.com/urfave/cli" "go.uber.org/zap" "go.uber.org/zap/zapcore" @@ -39,7 +39,7 @@ type UDR struct{} type ( // Config information. Config struct { - udrcfg string + cfg string } ) @@ -47,12 +47,9 @@ var config Config var udrCLi = []cli.Flag{ cli.StringFlag{ - Name: "free5gccfg", - Usage: "common config file", - }, - cli.StringFlag{ - Name: "udrcfg", - Usage: "config file", + Name: "cfg", + Usage: "udr config file", + Required: true, }, } @@ -67,20 +64,21 @@ func (*UDR) GetCliCmd() (flags []cli.Flag) { func (udr *UDR) Initialize(c *cli.Context) error { config = Config{ - udrcfg: c.String("udrcfg"), + cfg: c.String("cfg"), } - if config.udrcfg != "" { - if err := factory.InitConfigFactory(config.udrcfg); err != nil { - return err - } - } else { - DefaultUdrConfigPath := path_util.Free5gcPath("free5gc/config/udrcfg.yaml") - if err := factory.InitConfigFactory(DefaultUdrConfigPath); err != nil { - return err - } + absPath, err := filepath.Abs(config.cfg) + if err != nil { + logger.CfgLog.Errorln(err) + return err + } + + if err := factory.InitConfigFactory(absPath); err != nil { + return err } + factory.UdrConfig.CfgLocation = absPath + udr.setLogLevel() if err := factory.CheckConfigVersion(); err != nil { @@ -157,8 +155,6 @@ func (udr *UDR) Start() { go metrics.InitMetrics() - udrLogPath := util.UdrLogPath - self := context.UDR_Self() util.InitUdrContext(self) @@ -175,7 +171,8 @@ func (udr *UDR) Start() { go udr.registerNF() go udr.configUpdateDb() - server, err := http2_util.NewServer(addr, udrLogPath, router) + sslLog := filepath.Dir(factory.UdrConfig.CfgLocation) + "/sslkey.log" + server, err := http2_util.NewServer(addr, sslLog, router) if server == nil { logger.InitLog.Errorf("initialize HTTP server failed: %+v", err) return @@ -199,10 +196,10 @@ func (udr *UDR) Start() { func (udr *UDR) Exec(c *cli.Context) error { // UDR.Initialize(cfgPath, c) - logger.InitLog.Debugln("args:", c.String("udrcfg")) + logger.InitLog.Debugln("args:", c.String("cfg")) args := udr.FilterCli(c) logger.InitLog.Debugln("filter:", args) - command := exec.Command("./udr", args...) + command := exec.Command("udr", args...) if err := udr.Initialize(c); err != nil { return err @@ -262,7 +259,7 @@ func (udr *UDR) Terminate() { } else { logger.InitLog.Infoln("deregister from NRF successfully") } - logger.InitLog.Infoln("udr terminated") + logger.InitLog.Infoln("UDR terminated") } func (udr *UDR) configUpdateDb() { @@ -287,14 +284,14 @@ func (udr *UDR) StartKeepAliveTimer(nfProfile models.NfProfile) { if nfProfile.HeartBeatTimer == 0 { nfProfile.HeartBeatTimer = 60 } - logger.InitLog.Infof("started KeepAlive Timer: %v sec", nfProfile.HeartBeatTimer) + logger.InitLog.Infof("started KeepAlive timer: %v sec", nfProfile.HeartBeatTimer) // AfterFunc starts timer and waits for KeepAliveTimer to elapse and then calls udr.UpdateNF function KeepAliveTimer = time.AfterFunc(time.Duration(nfProfile.HeartBeatTimer)*time.Second, udr.UpdateNF) } func (udr *UDR) StopKeepAliveTimer() { if KeepAliveTimer != nil { - logger.InitLog.Infoln("stopped KeepAlive Timer") + logger.InitLog.Infoln("stopped KeepAlive timer") KeepAliveTimer.Stop() KeepAliveTimer = nil } @@ -303,7 +300,7 @@ func (udr *UDR) StopKeepAliveTimer() { func (udr *UDR) BuildAndSendRegisterNFInstance() (prof models.NfProfile, err error) { self := context.UDR_Self() profile := consumer.BuildNFInstance(self) - logger.InitLog.Infof("udr Profile Registering to NRF: %v", profile) + logger.InitLog.Infof("UDR profile registering to NRF: %v", profile) // Indefinite attempt to register until success profile, _, self.NfId, err = consumer.SendRegisterNFInstance(self.NrfUri, self.NfId, profile) return profile, err @@ -350,7 +347,7 @@ func (udr *UDR) UpdateNF() { // use hearbeattimer value with received timer value from NRF heartBeatTimer = nfProfile.HeartBeatTimer } - logger.InitLog.Debugf("restarted KeepAlive Timer: %v sec", heartBeatTimer) + logger.InitLog.Debugf("restarted KeepAlive timer: %v sec", heartBeatTimer) // restart timer with received HeartBeatTimer value KeepAliveTimer = time.AfterFunc(time.Duration(heartBeatTimer)*time.Second, udr.UpdateNF) } diff --git a/service/init_test.go b/service/init_test.go index 521c7a8..6da2637 100644 --- a/service/init_test.go +++ b/service/init_test.go @@ -25,7 +25,7 @@ func Test_nrf_url_is_not_overwritten_when_registering(t *testing.T) { svr.EnableHTTP2 = true svr.StartTLS() defer svr.Close() - if err := factory.InitConfigFactory("../factory/config.example.yaml"); err != nil { + if err := factory.InitConfigFactory("../factory/udr_config.yaml"); err != nil { t.Fatalf("Could not read example configuration file") } self := context.UDR_Self() diff --git a/udr.go b/udr.go index 3a37a3c..e6b8a10 100644 --- a/udr.go +++ b/udr.go @@ -1,7 +1,6 @@ +// Copyright 2024-present Intel Corporation // Copyright 2019 free5GC.org -// // SPDX-License-Identifier: Apache-2.0 -// package main @@ -10,21 +9,22 @@ import ( "os" "github.com/omec-project/udr/logger" - udr_service "github.com/omec-project/udr/service" + "github.com/omec-project/udr/service" "github.com/urfave/cli" ) -var UDR = &udr_service.UDR{} +var UDR = &service.UDR{} func main() { app := cli.NewApp() app.Name = "udr" logger.AppLog.Infoln(app.Name) - app.Usage = "-free5gccfg common configuration file -udrcfg udr configuration file" + app.Usage = "Unified Data Repository" + app.UsageText = "udr -cfg " app.Action = action app.Flags = UDR.GetCliCmd() if err := app.Run(os.Args); err != nil { - logger.AppLog.Errorf("UDR Run error: %v", err) + logger.AppLog.Fatalf("UDR run error: %v", err) } } diff --git a/util/init_context.go b/util/init_context.go index 303f868..c660f87 100644 --- a/util/init_context.go +++ b/util/init_context.go @@ -11,20 +11,18 @@ import ( "github.com/google/uuid" "github.com/omec-project/openapi/models" - udr_context "github.com/omec-project/udr/context" + "github.com/omec-project/udr/context" "github.com/omec-project/udr/factory" "github.com/omec-project/udr/logger" ) -func InitUdrContext(context *udr_context.UDRContext) { +func InitUdrContext(context *context.UDRContext) { config := factory.UdrConfig logger.UtilLog.Infof("udrconfig Info: Version[%s] Description[%s]", config.Info.Version, config.Info.Description) configuration := config.Configuration context.NfId = uuid.New().String() context.RegisterIPv4 = factory.UDR_DEFAULT_IPV4 // default localhost context.SBIPort = factory.UDR_DEFAULT_PORT_INT // default port - context.Key = UdrKeyPath // default key path - context.PEM = UdrPemPath // default PEM path if sbi := configuration.Sbi; sbi != nil { context.UriScheme = models.UriScheme(sbi.Scheme) if sbi.RegisterIPv4 != "" { @@ -44,11 +42,11 @@ func InitUdrContext(context *udr_context.UDRContext) { context.BindingIPv4 = os.Getenv(sbi.BindingIPv4) if context.BindingIPv4 != "" { - logger.UtilLog.Info("Parsing ServerIPv4 address from ENV Variable.") + logger.UtilLog.Infoln("parsing ServerIPv4 address from ENV variable") } else { context.BindingIPv4 = sbi.BindingIPv4 if context.BindingIPv4 == "" { - logger.UtilLog.Warn("Error parsing ServerIPv4 address as string. Using the 0.0.0.0 address as default.") + logger.UtilLog.Warnln("error parsing ServerIPv4 address as string. Using the 0.0.0.0 address as default") context.BindingIPv4 = "0.0.0.0" } } @@ -56,7 +54,7 @@ func InitUdrContext(context *udr_context.UDRContext) { if configuration.NrfUri != "" { context.NrfUri = configuration.NrfUri } else { - logger.UtilLog.Warn("NRF Uri is empty! Using localhost as NRF IPv4 address.") + logger.UtilLog.Warnln("NRF Uri is empty. Using localhost as NRF IPv4 address") context.NrfUri = fmt.Sprintf("%s://%s:%d", context.UriScheme, "127.0.0.1", 29510) } } diff --git a/util/path.go b/util/path.go deleted file mode 100644 index f467443..0000000 --- a/util/path.go +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2019 free5GC.org -// -// SPDX-License-Identifier: Apache-2.0 -// - -//go:build !debug -// +build !debug - -package util - -import ( - "github.com/omec-project/util/path_util" -) - -var ( - UdrLogPath = path_util.Free5gcPath("omec-project/udrsslkey.log") - UdrPemPath = path_util.Free5gcPath("free5gc/support/TLS/udr.pem") - UdrKeyPath = path_util.Free5gcPath("free5gc/support/TLS/udr.key") - DefaultUdrConfigPath = path_util.Free5gcPath("free5gc/config/udrcfg.yaml") -) diff --git a/util/path_debug.go b/util/path_debug.go deleted file mode 100644 index a49bd0d..0000000 --- a/util/path_debug.go +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2019 free5GC.org -// -// SPDX-License-Identifier: Apache-2.0 -// - -//go:build debug -// +build debug - -package util - -import ( - "github.com/omec-project/util/path_util" -) - -var ( - UdrLogPath = path_util.Free5gcPath("omec-project/udrsslkey.log") - UdrPemPath = path_util.Free5gcPath("free5gc/support/TLS/_debug.pem") - UdrKeyPath = path_util.Free5gcPath("free5gc/support/TLS/_debug.key") - DefaultUdrConfigPath = path_util.Free5gcPath("free5gc/config/udrcfg.yaml") -)