Skip to content

Commit 650a191

Browse files
authored
Refactor path for configuration file, option(s) and Docker image (#344)
* Refactor path for configuration file, option(s) and Docker image Signed-off-by: Arrobo, Gabriel <[email protected]> * Remove unused variable Signed-off-by: Arrobo, Gabriel <[email protected]> * Add suggestion Signed-off-by: Arrobo, Gabriel <[email protected]> --------- Signed-off-by: Arrobo, Gabriel <[email protected]>
1 parent 7d3f7d4 commit 650a191

File tree

8 files changed

+40
-86
lines changed

8 files changed

+40
-86
lines changed

Dockerfile

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
FROM golang:1.23.2-bookworm AS builder
88

9-
LABEL maintainer="Aether SD-Core <[email protected]>"
10-
119
RUN apt-get update && \
1210
apt-get -y install --no-install-recommends \
1311
apt-transport-https \
@@ -27,7 +25,8 @@ RUN make all
2725

2826
FROM alpine:3.20 AS smf
2927

30-
LABEL description="ONF open source 5G Core Network" \
28+
LABEL maintainer="Aether SD-Core <[email protected]>" \
29+
description="ONF open source 5G Core Network" \
3130
version="Stage 3"
3231

3332
ARG DEBUG_TOOLS
@@ -39,8 +38,5 @@ RUN if [ "$DEBUG_TOOLS" = "true" ]; then \
3938
apk update && apk add --no-cache -U vim strace net-tools curl netcat-openbsd bind-tools tcpdump; \
4039
fi
4140

42-
# Set working dir
43-
WORKDIR /free5gc/smf
44-
45-
# Copy executable and default certs
46-
COPY --from=builder /go/src/smf/bin/* .
41+
# Copy executable
42+
COPY --from=builder /go/src/smf/bin/* /usr/local/bin/.

context/context.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/omec-project/smf/factory"
2323
"github.com/omec-project/smf/logger"
2424
"github.com/omec-project/smf/metrics"
25-
"github.com/omec-project/smf/util"
2625
"github.com/omec-project/util/drsm"
2726
)
2827

@@ -159,8 +158,6 @@ func InitSmfContext(config *factory.Config) *SMFContext {
159158
smfContext.URIScheme = models.UriScheme(sbi.Scheme)
160159
smfContext.RegisterIPv4 = factory.SMF_DEFAULT_IPV4 // default localhost
161160
smfContext.SBIPort = factory.SMF_DEFAULT_PORT_INT // default port
162-
smfContext.Key = util.SmfKeyPath // default key path
163-
smfContext.PEM = util.SmfPemPath // default PEM path
164161

165162
if sbi.RegisterIPv4 != "" {
166163
// smfContext.RegisterIPv4 = sbi.RegisterIPv4

factory/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type Config struct {
3333
Info *Info `yaml:"info"`
3434
Configuration *Configuration `yaml:"configuration"`
3535
Logger *utilLogger.Logger `yaml:"logger"`
36+
CfgLocation string
3637
}
3738

3839
type UpdateSmfConfig struct {

pdusession/dummy_server.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"github.com/omec-project/smf/pfcp/udp"
1313
"github.com/omec-project/util/http2_util"
1414
utilLogger "github.com/omec-project/util/logger"
15-
"github.com/omec-project/util/path_util"
1615
)
1716

1817
func DummyServer() {
@@ -22,9 +21,9 @@ func DummyServer() {
2221

2322
go udp.Run(pfcp.Dispatch)
2423

25-
smfKeyLogPath := path_util.Free5gcPath("free5gc/smfsslkey.log")
26-
smfPemPath := path_util.Free5gcPath("free5gc/support/TLS/smf.pem")
27-
smfkeyPath := path_util.Free5gcPath("free5gc/support/TLS/smf.key")
24+
smfKeyLogPath := "/opt/sslkey.log"
25+
smfPemPath := "/var/run/certs/tls.pem"
26+
smfkeyPath := "/var/run/certs/tls.key"
2827

2928
var server *http.Server
3029
if srv, err := http2_util.NewServer(":29502", smfKeyLogPath, router); err != nil {

service/init.go

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
_ "net/http/pprof" // Using package only for invoking initialization.
1313
"os"
1414
"os/signal"
15+
"path/filepath"
1516
"sync"
1617
"sync/atomic"
1718
"syscall"
@@ -38,10 +39,8 @@ import (
3839
"github.com/omec-project/smf/pfcp/message"
3940
"github.com/omec-project/smf/pfcp/udp"
4041
"github.com/omec-project/smf/pfcp/upf"
41-
"github.com/omec-project/smf/util"
4242
"github.com/omec-project/util/http2_util"
4343
utilLogger "github.com/omec-project/util/logger"
44-
"github.com/omec-project/util/path_util"
4544
"github.com/urfave/cli"
4645
"go.uber.org/zap"
4746
"go.uber.org/zap/zapcore"
@@ -52,7 +51,7 @@ type SMF struct{}
5251
type (
5352
// Config information.
5453
Config struct {
55-
smfcfg string
54+
cfg string
5655
uerouting string
5756
}
5857
)
@@ -63,16 +62,14 @@ var config Config
6362

6463
var smfCLi = []cli.Flag{
6564
cli.StringFlag{
66-
Name: "cfg",
67-
Usage: "common config file",
65+
Name: "cfg",
66+
Usage: "smf config file",
67+
Required: true,
6868
},
6969
cli.StringFlag{
70-
Name: "smfcfg",
71-
Usage: "config file",
72-
},
73-
cli.StringFlag{
74-
Name: "uerouting",
75-
Usage: "config file",
70+
Name: "uerouting",
71+
Usage: "uerouting config file",
72+
Required: true,
7673
},
7774
}
7875

@@ -98,30 +95,30 @@ func (*SMF) GetCliCmd() (flags []cli.Flag) {
9895

9996
func (smf *SMF) Initialize(c *cli.Context) error {
10097
config = Config{
101-
smfcfg: c.String("smfcfg"),
98+
cfg: c.String("cfg"),
10299
uerouting: c.String("uerouting"),
103100
}
104101

105-
if config.smfcfg != "" {
106-
if err := factory.InitConfigFactory(config.smfcfg); err != nil {
107-
return err
108-
}
109-
} else {
110-
DefaultSmfConfigPath := path_util.Free5gcPath("omec-project/smf/config/smfcfg.yaml")
111-
if err := factory.InitConfigFactory(DefaultSmfConfigPath); err != nil {
112-
return err
113-
}
102+
absPath, err := filepath.Abs(config.cfg)
103+
if err != nil {
104+
logger.CfgLog.Errorln(err)
105+
return err
114106
}
115107

116-
if config.uerouting != "" {
117-
if err := factory.InitRoutingConfigFactory(config.uerouting); err != nil {
118-
return err
119-
}
120-
} else {
121-
DefaultUERoutingPath := path_util.Free5gcPath("omec-project/smf/config/uerouting.yaml")
122-
if err := factory.InitRoutingConfigFactory(DefaultUERoutingPath); err != nil {
123-
return err
124-
}
108+
if err = factory.InitConfigFactory(absPath); err != nil {
109+
return err
110+
}
111+
112+
factory.SmfConfig.CfgLocation = absPath
113+
114+
ueRoutingPath, err := filepath.Abs(config.uerouting)
115+
if err != nil {
116+
logger.CfgLog.Errorln(err)
117+
return err
118+
}
119+
120+
if err := factory.InitRoutingConfigFactory(ueRoutingPath); err != nil {
121+
return err
125122
}
126123

127124
smf.setLogLevel()
@@ -408,7 +405,8 @@ func (smf *SMF) Start() {
408405
time.Sleep(1000 * time.Millisecond)
409406

410407
HTTPAddr := fmt.Sprintf("%s:%d", context.SMF_Self().BindingIPv4, context.SMF_Self().SBIPort)
411-
server, err := http2_util.NewServer(HTTPAddr, util.SmfLogPath, router)
408+
sslLog := filepath.Dir(factory.SmfConfig.CfgLocation) + "/sslkey.log"
409+
server, err := http2_util.NewServer(HTTPAddr, sslLog, router)
412410

413411
if server == nil {
414412
logger.InitLog.Errorln("initialize HTTP server failed:", err)

smf.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ func main() {
2929
app := cli.NewApp()
3030
app.Name = "smf"
3131
logger.AppLog.Infoln(app.Name)
32-
app.Usage = "-cfg common configuration file -smfcfg smf_configuration_file"
32+
app.Usage = "Session Management Function"
33+
app.UsageText = "smf -cfg <smf_config_file.conf> -uerouting <uerouting_config_file.conf>"
3334
app.Action = action
3435
app.Flags = SMF.GetCliCmd()
3536

3637
if err := app.Run(os.Args); err != nil {
37-
logger.AppLog.Errorf("SMF run error: %v", err)
38+
logger.AppLog.Fatalf("SMF run error: %v", err)
3839
}
3940
}
4041

util/path.go

Lines changed: 0 additions & 19 deletions
This file was deleted.

util/path_debug.go

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)