Skip to content

Commit

Permalink
Refactor path for configuration file, option(s) and Docker image
Browse files Browse the repository at this point in the history
Signed-off-by: Arrobo, Gabriel <[email protected]>
  • Loading branch information
gab-arrobo committed Nov 1, 2024
1 parent 9e22362 commit b957ed0
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 102 deletions.
13 changes: 5 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

FROM golang:1.23.2-bookworm AS builder

LABEL maintainer="Aether SD-Core <[email protected]>"

RUN apt-get update && \
apt-get -y install --no-install-recommends \
apt-transport-https \
Expand All @@ -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 <[email protected]>" \
description="ONF open source 5G Core Network" \
version="Stage 3"

ARG DEBUG_TOOLS
Expand All @@ -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/.
21 changes: 11 additions & 10 deletions factory/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -131,30 +132,30 @@ 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 {
// first slice Created
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")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion factory/config.example.yaml → factory/udr_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion factory/udr_config_with_custom_webui_url.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
53 changes: 25 additions & 28 deletions service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"os"
"os/exec"
"os/signal"
"path/filepath"
"sync"
"syscall"
"time"
Expand All @@ -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"
Expand All @@ -39,20 +39,17 @@ type UDR struct{}
type (
// Config information.
Config struct {
udrcfg string
cfg string
}
)

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,
},
}

Expand All @@ -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 {
Expand Down Expand Up @@ -157,8 +155,6 @@ func (udr *UDR) Start() {

go metrics.InitMetrics()

udrLogPath := util.UdrLogPath

self := context.UDR_Self()
util.InitUdrContext(self)

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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() {
Expand All @@ -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
}
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion service/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 6 additions & 6 deletions udr.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2024-present Intel Corporation
// Copyright 2019 free5GC.org
//
// SPDX-License-Identifier: Apache-2.0
//

package main

Expand All @@ -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 <udr_config_file.conf>"
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)
}
}

Expand Down
12 changes: 5 additions & 7 deletions util/init_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand All @@ -44,19 +42,19 @@ 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"
}
}
}
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)
}
}
20 changes: 0 additions & 20 deletions util/path.go

This file was deleted.

Loading

0 comments on commit b957ed0

Please sign in to comment.