Skip to content

Commit

Permalink
Refactor path for configuration file, option(s) and Docker image (#139)
Browse files Browse the repository at this point in the history
* Refactor path for configuration file, option(s) and Docker image

Signed-off-by: Arrobo, Gabriel <[email protected]>

* Change log from `error` to `fatal` because the NF cannot start without arguments

Signed-off-by: Arrobo, Gabriel <[email protected]>

* Fx email address

Signed-off-by: Arrobo, Gabriel <[email protected]>

* Update string value

Signed-off-by: Arrobo, Gabriel <[email protected]>

---------

Signed-off-by: Arrobo, Gabriel <[email protected]>
  • Loading branch information
gab-arrobo authored Nov 2, 2024
1 parent 0e4251a commit 958e8e9
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 86 deletions.
12 changes: 4 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 @@ -27,7 +25,8 @@ RUN make all

FROM alpine:3.20 AS nssf

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 +36,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/nssf

# Copy executable and default certs
COPY --from=builder /go/src/nssf/bin/* .
# Copy executable
COPY --from=builder /go/src/nssf/bin/* /usr/local/bin/.
9 changes: 3 additions & 6 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/google/uuid"
"github.com/omec-project/nssf/factory"
"github.com/omec-project/nssf/logger"
"github.com/omec-project/nssf/util"
"github.com/omec-project/openapi/models"
)

Expand Down Expand Up @@ -78,8 +77,6 @@ func InitNssfContext() {
nssfContext.RegisterIPv4 = nssfConfig.Configuration.Sbi.RegisterIPv4
nssfContext.SBIPort = nssfConfig.Configuration.Sbi.Port
nssfContext.BindingIPv4 = os.Getenv(nssfConfig.Configuration.Sbi.BindingIPv4)
nssfContext.Key = util.NSSF_KEY_PATH // default key path
nssfContext.PEM = util.NSSF_PEM_PATH // default PEM path
if tls := nssfConfig.Configuration.Sbi.TLS; tls != nil {
if tls.Key != "" {
nssfContext.Key = tls.Key
Expand All @@ -89,11 +86,11 @@ func InitNssfContext() {
}
}
if nssfContext.BindingIPv4 != "" {
logger.ContextLog.Info("Parsing ServerIPv4 address from ENV Variable.")
logger.ContextLog.Infoln("parsing ServerIPv4 address from ENV Variable")
} else {
nssfContext.BindingIPv4 = nssfConfig.Configuration.Sbi.BindingIPv4
if nssfContext.BindingIPv4 == "" {
logger.ContextLog.Warn("Error parsing ServerIPv4 address as string. Using the 0.0.0.0 address as default.")
logger.ContextLog.Warnln("error parsing ServerIPv4 address as string. Using the 0.0.0.0 address as default")
nssfContext.BindingIPv4 = "0.0.0.0"
}
}
Expand All @@ -103,7 +100,7 @@ func InitNssfContext() {
if nssfConfig.Configuration.NrfUri != "" {
nssfContext.NrfUri = nssfConfig.Configuration.NrfUri
} else {
logger.InitLog.Warn("NRF Uri is empty! Using localhost as NRF IPv4 address.")
logger.InitLog.Warnln("NRF Uri is empty. Using localhost as NRF IPv4 address")
nssfContext.NrfUri = fmt.Sprintf("%s://%s:%d", nssfContext.UriScheme, "127.0.0.1", port)
}

Expand Down
3 changes: 2 additions & 1 deletion factory/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ type Config struct {
Info *Info `yaml:"info"`
Configuration *Configuration `yaml:"configuration"`
Logger *utilLogger.Logger `yaml:"logger"`
Subscriptions []Subscription `yaml:"subscriptions,omitempty"`
CfgLocation string
Subscriptions []Subscription `yaml:"subscriptions,omitempty"`
}

type Info struct {
Expand Down
5 changes: 3 additions & 2 deletions nssf.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ func main() {
app := cli.NewApp()
app.Name = "nssf"
logger.AppLog.Infoln(app.Name)
app.Usage = "-free5gccfg common configuration file -nssfcfg nssf configuration file"
app.Usage = "Network Slice Selection Function"
app.UsageText = "nssf -cfg <nssf_config_file.conf>"
app.Action = action
app.Flags = NSSF.GetCliCmd()

if err := app.Run(os.Args); err != nil {
logger.AppLog.Errorf("NSSF Run Error: %v", err)
logger.AppLog.Fatalf("NSSF run error: %v", err)
}
}

Expand Down
58 changes: 28 additions & 30 deletions service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"os"
"os/exec"
"os/signal"
"path/filepath"
"sync"
"syscall"
"time"
Expand All @@ -29,11 +30,9 @@ import (
"github.com/omec-project/nssf/metrics"
"github.com/omec-project/nssf/nssaiavailability"
"github.com/omec-project/nssf/nsselection"
"github.com/omec-project/nssf/util"
"github.com/omec-project/openapi/models"
"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 @@ -44,20 +43,17 @@ type NSSF struct{}
type (
// Config information.
Config struct {
nssfcfg string
cfg string
}
)

var config Config

var nssfCLi = []cli.Flag{
cli.StringFlag{
Name: "free5gccfg",
Usage: "common config file",
},
cli.StringFlag{
Name: "nssfcfg",
Usage: "config file",
Name: "cfg",
Usage: "nssf config file",
Required: true,
},
}

Expand All @@ -72,18 +68,17 @@ func (*NSSF) GetCliCmd() (flags []cli.Flag) {

func (nssf *NSSF) Initialize(c *cli.Context) error {
config = Config{
nssfcfg: c.String("nssfcfg"),
cfg: c.String("cfg"),
}

if config.nssfcfg != "" {
if err := factory.InitConfigFactory(config.nssfcfg); err != nil {
return err
}
} else {
DefaultNssfConfigPath := path_util.Free5gcPath("free5gc/config/nssfcfg.yaml")
if err := factory.InitConfigFactory(DefaultNssfConfigPath); 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
}

nssf.setLogLevel()
Expand All @@ -92,6 +87,8 @@ func (nssf *NSSF) Initialize(c *cli.Context) error {
return err
}

factory.NssfConfig.CfgLocation = absPath

if os.Getenv("MANAGED_BY_CONFIG_POD") == "true" {
logger.InitLog.Infoln("MANAGED_BY_CONFIG_POD is true")
go manageGrpcClient(factory.NssfConfig.Configuration.WebuiUri)
Expand Down Expand Up @@ -217,7 +214,8 @@ func (nssf *NSSF) Start() {

go nssf.registerNF()

server, err := http2_util.NewServer(addr, util.NSSF_LOG_PATH, router)
sslLog := filepath.Dir(factory.NssfConfig.CfgLocation) + "/sslkey.log"
server, err := http2_util.NewServer(addr, sslLog, router)

if server == nil {
logger.InitLog.Errorf("initialize HTTP server failed: %+v", err)
Expand All @@ -241,10 +239,10 @@ func (nssf *NSSF) Start() {
}

func (nssf *NSSF) Exec(c *cli.Context) error {
logger.InitLog.Debugln("args:", c.String("nssfcfg"))
logger.InitLog.Debugln("args:", c.String("cfg"))
args := nssf.FilterCli(c)
logger.InitLog.Debugln("filter:", args)
command := exec.Command("./nssf", args...)
command := exec.Command("nssf", args...)

stdout, err := command.StdoutPipe()
if err != nil {
Expand Down Expand Up @@ -286,13 +284,13 @@ func (nssf *NSSF) Exec(c *cli.Context) error {
}

func (nssf *NSSF) Terminate() {
logger.InitLog.Infoln("terminating NSSF...")
logger.InitLog.Infoln("terminating NSSF")
// deregister with NRF
problemDetails, err := consumer.SendDeregisterNFInstance()
if problemDetails != nil {
logger.InitLog.Errorf("deregister NF instance Failed Problem[%+v]", problemDetails)
} else if err != nil {
logger.InitLog.Errorf("deregister NF instance Error[%+v]", err)
logger.InitLog.Errorf("deregister NF instance error[%+v]", err)
} else {
logger.InitLog.Infoln("deregister from NRF successfully")
}
Expand Down Expand Up @@ -324,7 +322,7 @@ func (nssf *NSSF) BuildAndSendRegisterNFInstance() (models.NfProfile, error) {
self := context.NSSF_Self()
profile, err := consumer.BuildNFProfile(self)
if err != nil {
logger.InitLog.Errorf("build NSSF Profile Error: %v", err)
logger.InitLog.Errorf("build NSSF profile error: %v", err)
return profile, err
}
logger.InitLog.Infof("NSSF Profile Registering to NRF: %v", profile)
Expand Down Expand Up @@ -359,22 +357,22 @@ func (nssf *NSSF) UpdateNF() {
// register with NRF full profile
nfProfile, err = nssf.BuildAndSendRegisterNFInstance()
if err != nil {
logger.InitLog.Errorf("NSSF update to NRF Error[%s]", err.Error())
logger.InitLog.Errorf("NSSF update to NRF error[%s]", err.Error())
}
}
} else if err != nil {
logger.InitLog.Errorf("NSSF update to NRF Error[%s]", err.Error())
logger.InitLog.Errorf("NSSF update to NRF error[%s]", err.Error())
nfProfile, err = nssf.BuildAndSendRegisterNFInstance()
if err != nil {
logger.InitLog.Errorf("NSSF update to NRF Error[%s]", err.Error())
logger.InitLog.Errorf("NSSF update to NRF error[%s]", err.Error())
}
}

if nfProfile.HeartBeatTimer != 0 {
// 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, nssf.UpdateNF)
}
Expand All @@ -397,7 +395,7 @@ func (nssf *NSSF) registerNF() {
logger.CfgLog.Infoln("sent register NFInstance with updated profile")
self.NrfUri = newNrfUri
} else {
logger.CfgLog.Errorf("send register NFInstance Error[%s]", err.Error())
logger.CfgLog.Errorf("send register NFInstance error[%s]", err.Error())
}
}
}
26 changes: 13 additions & 13 deletions test/conf/test_nssf_config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2019 free5GC.org
#
# SPDX-License-Identifier: Apache-2.0
#
#

info:
version: 1.0.0
Expand Down Expand Up @@ -39,46 +39,46 @@ configuration:
- snssai:
sst: 1
nsiInformationList:
- nrfId: http://free5gc-nrf-10.nctu.me:29510/nnrf-nfm/v1/nf-instances
- nrfId: http://nrf-10.aether.org:29510/nnrf-nfm/v1/nf-instances
nsiId: 10
- snssai:
sst: 1
sd: 1
nsiInformationList:
- nrfId: http://free5gc-nrf-11.nctu.me:29510/nnrf-nfm/v1/nf-instances
- nrfId: http://nrf-11.aether.org:29510/nnrf-nfm/v1/nf-instances
nsiId: 11
- snssai:
sst: 1
sd: 2
nsiInformationList:
- nrfId: http://free5gc-nrf-12-1.nctu.me:29510/nnrf-nfm/v1/nf-instances
- nrfId: http://nrf-12-1.aether.org:29510/nnrf-nfm/v1/nf-instances
nsiId: 12
- nrfId: http://free5gc-nrf-12-2.nctu.me:29510/nnrf-nfm/v1/nf-instances
- nrfId: http://nrf-12-2.aether.org:29510/nnrf-nfm/v1/nf-instances
nsiId: 12
- snssai:
sst: 1
sd: 3
nsiInformationList:
- nrfId: http://free5gc-nrf-13.nctu.me:29510/nnrf-nfm/v1/nf-instances
- nrfId: http://nrf-13.aether.org:29510/nnrf-nfm/v1/nf-instances
nsiId: 13
- snssai:
sst: 2
nsiInformationList:
- nrfId: http://free5gc-nrf-20.nctu.me:29510/nnrf-nfm/v1/nf-instances
- nrfId: http://nrf-20.aether.org:29510/nnrf-nfm/v1/nf-instances
nsiId: 20
- snssai:
sst: 2
sd: 1
nsiInformationList:
- nrfId: http://free5gc-nrf-21.nctu.me:29510/nnrf-nfm/v1/nf-instances
- nrfId: http://nrf-21.aether.org:29510/nnrf-nfm/v1/nf-instances
nsiId: 21
amfSetList:
- amfSetId: 1
amfList:
- ffa2e8d7-3275-49c7-8631-6af1df1d9d26
- 0e8831c3-6286-4689-ab27-1e2161e15cb1
- a1fba9ba-2e39-4e22-9c74-f749da571d0d
nrfAmfSet: http://free5gc-nrf.nctu.me:8081/nnrf-nfm/v1/nf-instances
nrfAmfSet: http://nrf.aether.org:8081/nnrf-nfm/v1/nf-instances
supportedNssaiAvailabilityData:
- tai:
plmnId:
Expand All @@ -104,7 +104,7 @@ configuration:
- sst: 1
sd: 2
- amfSetId: 2
nrfAmfSet: http://free5gc-nrf.nctu.me:8084/nnrf-nfm/v1/nf-instances
nrfAmfSet: http://nrf.aether.org:8084/nnrf-nfm/v1/nf-instances
supportedNssaiAvailabilityData:
- tai:
plmnId:
Expand Down Expand Up @@ -321,7 +321,7 @@ configuration:
subscriptions:
- subscriptionId: "1"
subscriptionData:
nfNssaiAvailabilityUri: "http://free5gc-amf1.nctu.me:29518/namf-nssaiavailability/v1/nssai-availability/notify"
nfNssaiAvailabilityUri: "http://amf1.aether.org:29518/namf-nssaiavailability/v1/nssai-availability/notify"
taiList:
- plmnId:
mcc: "466"
Expand All @@ -334,7 +334,7 @@ subscriptions:
event: "SNSSAI_STATUS_CHANGE_REPORT"
- subscriptionId: "3"
subscriptionData:
nfNssaiAvailabilityUri: "http://free5gc-amf3.nctu.me:29518/namf-nssaiavailability/v1/nssai-availability/notify"
nfNssaiAvailabilityUri: "http://amf3.aether.org:29518/namf-nssaiavailability/v1/nssai-availability/notify"
taiList:
- plmnId:
mcc: "466"
Expand All @@ -348,7 +348,7 @@ subscriptions:
expiry: "2020-06-24T16:35:31+08:00"
- subscriptionId: "4"
subscriptionData:
nfNssaiAvailabilityUri: "http://free5gc-amf4.nctu.me:29518/namf-nssaiavailability/v1/nssai-availability/notify"
nfNssaiAvailabilityUri: "http://amf4.aether.org:29518/namf-nssaiavailability/v1/nssai-availability/notify"
taiList:
- plmnId:
mcc: "466"
Expand Down
3 changes: 1 addition & 2 deletions test/param.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ import (
"flag"

"github.com/omec-project/nssf/plugin"
"github.com/omec-project/util/path_util"
)

var (
ConfigFileFromArgs string
DefaultConfigFile string = path_util.Free5gcPath("github.com/omec-project/nssf/test/conf/test_nssf_config.yaml")
DefaultConfigFile string = "conf/test_nssf_config.yaml"
)

type TestingUtil struct {
Expand Down
Loading

0 comments on commit 958e8e9

Please sign in to comment.