Skip to content

Commit

Permalink
Refactor path for configuration file, opton(s) and Docker image (#335)
Browse files Browse the repository at this point in the history
Signed-off-by: Arrobo, Gabriel <[email protected]>
  • Loading branch information
gab-arrobo authored Oct 31, 2024
1 parent 8e90d0f commit 140ca64
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 105 deletions.
10 changes: 3 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,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,6 +25,7 @@ RUN make all

FROM alpine:3.20 AS amf

LABEL maintainer="Aether SD-Core <[email protected]>"
LABEL description="Aether open source 5G Core Network" \
version="Stage 3"

Expand All @@ -39,8 +38,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/amf

# Copy executable and default certs
COPY --from=builder /go/src/amf/bin/* .
# Copy executable
COPY --from=builder /go/src/amf/bin/* /usr/local/bin/.
6 changes: 3 additions & 3 deletions amf.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ func main() {
app := cli.NewApp()
app.Name = "amf"
logger.AppLog.Infoln(app.Name)
app.Usage = "-free5gccfg common configuration file -amfcfg amf configuration file"
app.Usage = "Access & Mobility Management function"
app.UsageText = "amf -cfg <amf_config_file.conf>"
app.Action = action
app.Flags = AMF.GetCliCmd()
if err := app.Run(os.Args); err != nil {
logger.AppLog.Errorf("AMF Run error: %v", err)
return
logger.AppLog.Fatalf("AMF run error: %v", err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func init() {
AMF_Self().ServedGuamiList = make([]models.Guami, 0, MaxNumOfServedGuamiList)
AMF_Self().PlmnSupportList = make([]factory.PlmnSupportItem, 0, MaxNumOfPLMNs)
AMF_Self().NfService = make(map[models.ServiceName]models.NfService)
AMF_Self().NetworkName.Full = "free5GC"
AMF_Self().NetworkName.Full = "aether"
if !AMF_Self().EnableDbStore {
tmsiGenerator = idgenerator.NewGenerator(1, math.MaxInt32)
amfStatusSubscriptionIDGenerator = idgenerator.NewGenerator(1, math.MaxInt32)
Expand Down
1 change: 1 addition & 0 deletions factory/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Config struct {
Info *Info `yaml:"info"`
Configuration *Configuration `yaml:"configuration"`
Logger *logger.Logger `yaml:"logger"`
CfgLocation string
Rcvd bool
}

Expand Down
42 changes: 21 additions & 21 deletions factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func InitConfigFactory(f string) error {
return nil
}

func UpdateAmfConfig(f string) error {
func UpdateConfig(f string) error {
if content, err := os.ReadFile(f); err != nil {
return err
} else {
Expand All @@ -54,69 +54,69 @@ func UpdateAmfConfig(f string) error {
}
// Checking which config has been changed
if !reflect.DeepEqual(AmfConfig.Configuration.AmfName, amfConfig.Configuration.AmfName) {
logger.CfgLog.Infoln("updated AMF Name is changed to ", amfConfig.Configuration.AmfName)
logger.CfgLog.Infoln("updated AMF Name is changed to:", amfConfig.Configuration.AmfName)
}
if !reflect.DeepEqual(AmfConfig.Configuration.NgapIpList, amfConfig.Configuration.NgapIpList) {
logger.CfgLog.Infoln("updated NgapList ", amfConfig.Configuration.NgapIpList)
logger.CfgLog.Infoln("updated NgapList:", amfConfig.Configuration.NgapIpList)
}
if !reflect.DeepEqual(AmfConfig.Configuration.Sbi, amfConfig.Configuration.Sbi) {
logger.CfgLog.Infoln("updated Sbi ", amfConfig.Configuration.Sbi)
logger.CfgLog.Infoln("updated Sbi:", amfConfig.Configuration.Sbi)
}
if !reflect.DeepEqual(AmfConfig.Configuration.NetworkFeatureSupport5GS, amfConfig.Configuration.NetworkFeatureSupport5GS) {
logger.CfgLog.Infoln("updated NetworkFeatureSupport5GS ", amfConfig.Configuration.NetworkFeatureSupport5GS)
logger.CfgLog.Infoln("updated NetworkFeatureSupport5GS:", amfConfig.Configuration.NetworkFeatureSupport5GS)
}
if !reflect.DeepEqual(AmfConfig.Configuration.ServiceNameList, amfConfig.Configuration.ServiceNameList) {
logger.CfgLog.Infoln("updated ServiceNameList ", amfConfig.Configuration.ServiceNameList)
logger.CfgLog.Infoln("updated ServiceNameList:", amfConfig.Configuration.ServiceNameList)
}

/* we will not update below 3 configs if its controlled by ROC */
/* TODO: document this as dynamic configmap updates for below 3 configs we dont support if its controlled by ROC*/
if os.Getenv("MANAGED_BY_CONFIG_POD") == "true" {
if !reflect.DeepEqual(AmfConfig.Configuration.ServedGumaiList, amfConfig.Configuration.ServedGumaiList) {
logger.CfgLog.Infoln("updated ServedGumaiList ", amfConfig.Configuration.ServedGumaiList)
logger.CfgLog.Infoln("updated ServedGumaiList:", amfConfig.Configuration.ServedGumaiList)
}
if !reflect.DeepEqual(AmfConfig.Configuration.SupportTAIList, amfConfig.Configuration.SupportTAIList) {
logger.CfgLog.Infoln("updated SupportTAIList ", amfConfig.Configuration.SupportTAIList)
logger.CfgLog.Infoln("updated SupportTAIList:", amfConfig.Configuration.SupportTAIList)
}
if !reflect.DeepEqual(AmfConfig.Configuration.PlmnSupportList, amfConfig.Configuration.PlmnSupportList) {
logger.CfgLog.Infoln("updated PlmnSupportList ", amfConfig.Configuration.PlmnSupportList)
logger.CfgLog.Infoln("updated PlmnSupportList:", amfConfig.Configuration.PlmnSupportList)
}
}
if !reflect.DeepEqual(AmfConfig.Configuration.SupportDnnList, amfConfig.Configuration.SupportDnnList) {
logger.CfgLog.Infoln("updated SupportDnnList ", amfConfig.Configuration.SupportDnnList)
logger.CfgLog.Infoln("updated SupportDnnList:", amfConfig.Configuration.SupportDnnList)
}
if !reflect.DeepEqual(AmfConfig.Configuration.NrfUri, amfConfig.Configuration.NrfUri) {
logger.CfgLog.Infoln("updated NrfUri ", amfConfig.Configuration.NrfUri)
logger.CfgLog.Infoln("updated NrfUri:", amfConfig.Configuration.NrfUri)
}
if !reflect.DeepEqual(AmfConfig.Configuration.Security, amfConfig.Configuration.Security) {
logger.CfgLog.Infoln("updated Security ", amfConfig.Configuration.Security)
logger.CfgLog.Infoln("updated Security:", amfConfig.Configuration.Security)
}
if !reflect.DeepEqual(AmfConfig.Configuration.NetworkName, amfConfig.Configuration.NetworkName) {
logger.CfgLog.Infoln("updated NetworkName ", amfConfig.Configuration.NetworkName)
logger.CfgLog.Infoln("updated NetworkName:", amfConfig.Configuration.NetworkName)
}
if !reflect.DeepEqual(AmfConfig.Configuration.T3502Value, amfConfig.Configuration.T3502Value) {
logger.CfgLog.Infoln("updated T3502Value ", amfConfig.Configuration.T3502Value)
logger.CfgLog.Infoln("updated T3502Value:", amfConfig.Configuration.T3502Value)
}
if !reflect.DeepEqual(AmfConfig.Configuration.T3512Value, amfConfig.Configuration.T3512Value) {
logger.CfgLog.Infoln("updated T3512Value ", amfConfig.Configuration.T3512Value)
logger.CfgLog.Infoln("updated T3512Value:", amfConfig.Configuration.T3512Value)
}
if !reflect.DeepEqual(AmfConfig.Configuration.Non3gppDeregistrationTimerValue, amfConfig.Configuration.Non3gppDeregistrationTimerValue) {
logger.CfgLog.Infoln("updated Non3gppDeregistrationTimerValue ", amfConfig.Configuration.Non3gppDeregistrationTimerValue)
logger.CfgLog.Infoln("updated Non3gppDeregistrationTimerValue:", amfConfig.Configuration.Non3gppDeregistrationTimerValue)
}
if !reflect.DeepEqual(AmfConfig.Configuration.T3513, amfConfig.Configuration.T3513) {
logger.CfgLog.Infoln("updated T3513 ", amfConfig.Configuration.T3513)
logger.CfgLog.Infoln("updated T3513:", amfConfig.Configuration.T3513)
}
if !reflect.DeepEqual(AmfConfig.Configuration.T3522, amfConfig.Configuration.T3522) {
logger.CfgLog.Infoln("updated T3522 ", amfConfig.Configuration.T3522)
logger.CfgLog.Infoln("updated T3522:", amfConfig.Configuration.T3522)
}
if !reflect.DeepEqual(AmfConfig.Configuration.T3550, amfConfig.Configuration.T3550) {
logger.CfgLog.Infoln("updated T3550 ", amfConfig.Configuration.T3550)
logger.CfgLog.Infoln("updated T3550:", amfConfig.Configuration.T3550)
}
if !reflect.DeepEqual(AmfConfig.Configuration.T3560, amfConfig.Configuration.T3560) {
logger.CfgLog.Infoln("updated T3560 ", amfConfig.Configuration.T3560)
logger.CfgLog.Infoln("updated T3560:", amfConfig.Configuration.T3560)
}
if !reflect.DeepEqual(AmfConfig.Configuration.T3565, amfConfig.Configuration.T3565) {
logger.CfgLog.Infoln("updated T3565 ", amfConfig.Configuration.T3565)
logger.CfgLog.Infoln("updated T3565:", amfConfig.Configuration.T3565)
}

amfConfig.Rcvd = true
Expand Down
2 changes: 1 addition & 1 deletion ngap/util/ngap_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func BuildNGSetupRequest() (pdu ngapType.NGAPPDU) {
ie.Value.RANNodeName = new(ngapType.RANNodeName)

rANNodeName := ie.Value.RANNodeName
rANNodeName.Value = "free5GC"
rANNodeName.Value = "aether"
nGSetupRequestIEs.List = append(nGSetupRequestIEs.List, ie)
// SupportedTAList
ie = ngapType.NGSetupRequestIEs{}
Expand Down
53 changes: 26 additions & 27 deletions service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"os"
"os/exec"
"os/signal"
"path/filepath"
"strconv"
"sync"
"syscall"
Expand Down Expand Up @@ -50,7 +51,6 @@ import (
"github.com/omec-project/util/fsm"
"github.com/omec-project/util/http2_util"
utilLogger "github.com/omec-project/util/logger"
"github.com/omec-project/util/path_util"
"github.com/spf13/viper"
"github.com/urfave/cli"
"go.uber.org/zap"
Expand All @@ -66,20 +66,17 @@ var RocUpdateConfigChannel chan bool
type (
// Config information.
Config struct {
amfcfg string
cfg string
}
)

var config Config

var amfCLi = []cli.Flag{
cli.StringFlag{
Name: "free5gccfg",
Usage: "common config file",
},
cli.StringFlag{
Name: "amfcfg",
Usage: "amf config file",
Name: "cfg",
Usage: "amf config file",
Required: true,
},
}

Expand All @@ -98,18 +95,17 @@ func (*AMF) GetCliCmd() (flags []cli.Flag) {

func (amf *AMF) Initialize(c *cli.Context) error {
config = Config{
amfcfg: c.String("amfcfg"),
cfg: c.String("cfg"),
}

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

amf.setLogLevel()
Expand All @@ -128,18 +124,20 @@ func (amf *AMF) Initialize(c *cli.Context) error {
return err
}

if _, err := os.Stat("/free5gc/config/amfcfg.conf"); err == nil {
viper.SetConfigName("amfcfg.conf")
if _, err := os.Stat(absPath); err == nil {
viper.SetConfigFile(absPath)
viper.SetConfigType("yaml")
viper.AddConfigPath("/free5gc/config")
err = viper.ReadInConfig() // Find and read the config file
if err != nil { // Handle errors reading the config file
return err
}
} else if os.IsNotExist(err) {
logger.AppLog.Errorln("amfcfg does not exists in /free5gc/config")
logger.AppLog.Errorln("file %s does not exists", absPath)
return err
}

factory.AmfConfig.CfgLocation = absPath

if os.Getenv("MANAGED_BY_CONFIG_POD") == "true" {
factory.AmfConfig.Configuration.ServedGumaiList = nil
factory.AmfConfig.Configuration.SupportTAIList = nil
Expand Down Expand Up @@ -212,8 +210,8 @@ func manageGrpcClient(webuiUri string, amf *AMF) {
func (amf *AMF) WatchConfig() {
viper.WatchConfig()
viper.OnConfigChange(func(e fsnotify.Event) {
logger.AppLog.Infoln("Config file changed:", e.Name)
if err := factory.UpdateAmfConfig("/free5gc/config/amfcfg.conf"); err != nil {
logger.AppLog.Infoln("config file changed:", e.Name)
if err := factory.UpdateConfig(factory.AmfConfig.CfgLocation); err != nil {
logger.AppLog.Errorln("error in loading updated configuration")
} else {
self := context.AMF_Self()
Expand Down Expand Up @@ -397,7 +395,8 @@ func (amf *AMF) Start() {
os.Exit(0)
}()

server, err := http2_util.NewServer(addr, util.AmfLogPath, router)
sslLog := filepath.Dir(factory.AmfConfig.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 @@ -423,10 +422,10 @@ func (amf *AMF) Start() {
func (amf *AMF) Exec(c *cli.Context) error {
// AMF.Initialize(cfgPath, c)

logger.InitLog.Debugln("args:", c.String("amfcfg"))
logger.InitLog.Debugln("args:", c.String("cfg"))
args := amf.FilterCli(c)
logger.InitLog.Debugln("filter:", args)
command := exec.Command("./amf", args...)
command := exec.Command("amf", args...)

stdout, err := command.StdoutPipe()
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions util/init_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ func InitAmfContext(context *context.AMFContext) {
}
context.RegisterIPv4 = factory.AMF_DEFAULT_IPV4 // default localhost
context.SBIPort = factory.AMF_DEFAULT_PORT_INT // default port
context.Key = AmfKeyPath // default key path
context.PEM = AmfPemPath // default PEM path
if sbi != nil {
if sbi.RegisterIPv4 != "" {
context.RegisterIPv4 = os.Getenv("POD_IP")
Expand Down
20 changes: 0 additions & 20 deletions util/path.go

This file was deleted.

20 changes: 0 additions & 20 deletions util/path_debug.go

This file was deleted.

5 changes: 2 additions & 3 deletions util/test/testAmfcfg.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 @@ -46,5 +46,4 @@ configuration:
cipheringOrder:
- NEA2
networkName:
full: free5GC
short: free
full: aether

0 comments on commit 140ca64

Please sign in to comment.