diff --git a/Dockerfile b/Dockerfile index f6a11de..03a8a05 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 \ @@ -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 " \ + description="ONF open source 5G Core Network" \ version="Stage 3" ARG DEBUG_TOOLS @@ -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/. diff --git a/context/context.go b/context/context.go index 0fae25d..9c9e575 100644 --- a/context/context.go +++ b/context/context.go @@ -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" ) @@ -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 @@ -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" } } @@ -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) } diff --git a/factory/config.go b/factory/config.go index eb78b0b..84f141f 100644 --- a/factory/config.go +++ b/factory/config.go @@ -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 { diff --git a/nssf.go b/nssf.go index 5aafb77..37e4405 100644 --- a/nssf.go +++ b/nssf.go @@ -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 " 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) } } diff --git a/service/init.go b/service/init.go index c340b32..a414ff9 100644 --- a/service/init.go +++ b/service/init.go @@ -16,6 +16,7 @@ import ( "os" "os/exec" "os/signal" + "path/filepath" "sync" "syscall" "time" @@ -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" @@ -44,7 +43,7 @@ type NSSF struct{} type ( // Config information. Config struct { - nssfcfg string + cfg string } ) @@ -52,12 +51,9 @@ 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, }, } @@ -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() @@ -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) @@ -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) @@ -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 { @@ -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") } @@ -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) @@ -359,14 +357,14 @@ 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()) } } @@ -374,7 +372,7 @@ func (nssf *NSSF) 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, nssf.UpdateNF) } @@ -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()) } } } diff --git a/test/conf/test_nssf_config.yaml b/test/conf/test_nssf_config.yaml index 40ee7d3..e41f124 100644 --- a/test/conf/test_nssf_config.yaml +++ b/test/conf/test_nssf_config.yaml @@ -1,7 +1,7 @@ # Copyright 2019 free5GC.org # # SPDX-License-Identifier: Apache-2.0 -# +# info: version: 1.0.0 @@ -39,38 +39,38 @@ 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 @@ -78,7 +78,7 @@ configuration: - 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: @@ -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: @@ -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" @@ -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" @@ -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" diff --git a/test/param.go b/test/param.go index 83923b6..2feff94 100644 --- a/test/param.go +++ b/test/param.go @@ -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 { diff --git a/util/util.go b/util/util.go index 195d7b8..3a65460 100644 --- a/util/util.go +++ b/util/util.go @@ -17,7 +17,6 @@ import ( "github.com/omec-project/nssf/factory" "github.com/omec-project/nssf/logger" "github.com/omec-project/openapi/models" - "github.com/omec-project/util/path_util" ) // Title in Problem Details for NSSF HTTP APIs @@ -28,16 +27,6 @@ const ( UNSUPPORTED_RESOURCE = "Unsupported request resources" ) -// Path of HTTP2 key and log file -var ( - NSSF_LOG_PATH = path_util.Free5gcPath("omec-project/nssfsslkey.log") - NSSF_PEM_PATH = path_util.Free5gcPath("free5gc/support/TLS/nssf.pem") - NSSF_KEY_PATH = path_util.Free5gcPath("free5gc/support/TLS/nssf.key") -) - -// Default configuration file -var DEFAULT_CONFIG string = "free5gc/config/nssfcfg.yaml" - // Check if a slice contains an element func Contain(target interface{}, slice interface{}) bool { arr := reflect.ValueOf(slice) @@ -60,7 +49,7 @@ func CheckSupportedHplmn(homePlmnId models.PlmnId) bool { return true } } - logger.Util.Warnf("No Home PLMN %+v in NSSF configuration", homePlmnId) + logger.Util.Warnf("no Home PLMN %+v in NSSF configuration", homePlmnId) return false } @@ -75,9 +64,9 @@ func CheckSupportedTa(tai models.Tai) bool { } e, err := json.Marshal(tai) if err != nil { - logger.Util.Errorf("Marshal error in CheckSupportedTa: %+v", err) + logger.Util.Errorf("marshal error in CheckSupportedTa: %+v", err) } - logger.Util.Warnf("No TA %s in NSSF configuration", e) + logger.Util.Warnf("no TA %s in NSSF configuration", e) return false } @@ -99,7 +88,7 @@ func CheckSupportedSnssaiInPlmn(snssai models.Snssai, plmnId models.PlmnId) bool return false } } - logger.Util.Warnf("No supported S-NSSAI list of PLMNID %+v in NSSF configuration", plmnId) + logger.Util.Warnf("no supported S-NSSAI list of PLMNID %+v in NSSF configuration", plmnId) return false } @@ -131,7 +120,7 @@ func CheckSupportedNssaiInPlmn(nssai []models.Snssai, plmnId models.PlmnId) bool return true } } - logger.Util.Warnf("No supported S-NSSAI list of PLMNID %+v in NSSF configuration", plmnId) + logger.Util.Warnf("no supported S-NSSAI list of PLMNID %+v in NSSF configuration", plmnId) return false } @@ -188,7 +177,7 @@ func CheckSupportedSnssaiInAmfTa(snssai models.Snssai, nfId string, tai models.T } } - logger.Util.Warnf("No AMF %s in NSSF configuration", nfId) + logger.Util.Warnf("no AMF %s in NSSF configuration", nfId) return false } @@ -260,9 +249,9 @@ func GetAccessTypeFromConfig(tai models.Tai) models.AccessType { } e, err := json.Marshal(tai) if err != nil { - logger.Util.Errorf("Marshal error in GetAccessTypeFromConfig: %+v", err) + logger.Util.Errorf("marshal error in GetAccessTypeFromConfig: %+v", err) } - logger.Util.Warnf("No TA %s in NSSF configuration", e) + logger.Util.Warnf("no TA %s in NSSF configuration", e) return models.AccessType__3_GPP_ACCESS } @@ -281,9 +270,9 @@ func GetRestrictedSnssaiListFromConfig(tai models.Tai) []models.RestrictedSnssai } e, err := json.Marshal(tai) if err != nil { - logger.Util.Errorf("Marshal error in GetRestrictedSnssaiListFromConfig: %+v", err) + logger.Util.Errorf("marshal error in GetRestrictedSnssaiListFromConfig: %+v", err) } - logger.Util.Warnf("No TA %s in NSSF configuration", e) + logger.Util.Warnf("no TA %s in NSSF configuration", e) return nil } @@ -306,7 +295,7 @@ func AuthorizeOfAmfTaFromConfig(nfId string, tai models.Tai) (models.AuthorizedN } e, err1 := json.Marshal(tai) if err1 != nil { - logger.Util.Errorf("Marshal error in AuthorizeOfAmfTaFromConfig: %+v", err1) + logger.Util.Errorf("marshal error in AuthorizeOfAmfTaFromConfig: %+v", err1) } err := fmt.Errorf("no supported S-NSSAI list by AMF %s under TAI %s in NSSF configuration", nfId, e) return authorizedNssaiAvailabilityData, err @@ -407,7 +396,7 @@ func AddAllowedSnssai(allowedSnssai models.AllowedSnssai, accessType models.Acce if authorizedNetworkSliceInfo.AllowedNssaiList[i].AccessType == accessType { hitAllowedNssai = true if len(authorizedNetworkSliceInfo.AllowedNssaiList[i].AllowedSnssaiList) == allowedNssaiNum { - logger.Util.Infof("unable to add a new Allowed S-NSSAI since already eight S-NSSAIs in Allowed NSSAI") + logger.Util.Infoln("unable to add a new Allowed S-NSSAI since already eight S-NSSAIs in Allowed NSSAI") } else { authorizedNetworkSliceInfo.AllowedNssaiList[i].AllowedSnssaiList = append(authorizedNetworkSliceInfo.AllowedNssaiList[i].AllowedSnssaiList, allowedSnssai) } @@ -502,6 +491,6 @@ func AddAmfInformation(tai models.Tai, authorizedNetworkSliceInfo *models.Author } if !hitAmf { - logger.Util.Warnf("no candidate AMF or AMF Set can serve the UE") + logger.Util.Warnln("no candidate AMF or AMF Set can serve the UE") } }