Skip to content

Commit 0730d4f

Browse files
authored
Merge pull request #1 from usmanTheCoder/bsf_v1
feat(BSF): Complete BSF implementation with 3GPP TS 29.521 compliance
2 parents 447fb52 + 3fdf15b commit 0730d4f

26 files changed

Lines changed: 4692 additions & 7 deletions

.github/copilot-instructions.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<!-- Auto-generated todo section -->
2+
<todos title="Todos" rule="Review steps frequently throughout the conversation and DO NOT stop between steps unless they explicitly require it.">
3+
- No current todos
4+
</todos>
5+
6+
<!-- Add your custom Copilot instructions below -->

.gitignore

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
33
#
44
# Binaries for programs and plugins
5+
bin/
56
*.exe
67
*.exe~
78
*.dll
@@ -11,22 +12,37 @@
1112
# Test binary, built with `go test -c`
1213
*.test
1314

14-
# Code coverage profiles and other test artifacts
15+
# Output of the go coverage tool
1516
*.out
1617
coverage.*
1718
*.coverprofile
1819
profile.cov
1920

20-
# Dependency directories (remove the comment below to include it)
21-
# vendor/
21+
# Logs
22+
*.log
23+
24+
# Dependency directories
25+
vendor/
2226

2327
# Go workspace file
2428
go.work
2529
go.work.sum
2630

27-
# env file
31+
# Environment file
2832
.env
2933

30-
# Editor/IDE
31-
# .idea/
32-
# .vscode/
34+
# IDE/Editor
35+
.vscode/
36+
.idea/
37+
*.swp
38+
*.swo
39+
*~
40+
41+
# OS
42+
.DS_Store
43+
.DS_Store?
44+
._*
45+
.Spotlight-V100
46+
.Trashes
47+
ehthumbs.db
48+
Thumbs.db

cmd/main.go

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
* Nbsf_Management Service API
3+
*
4+
* Binding Support Management Service API.
5+
* © 2025, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC).
6+
* All rights reserved.
7+
*
8+
* API version: 1.5.0
9+
*/
10+
11+
package main
12+
13+
import (
14+
"context"
15+
"fmt"
16+
"os"
17+
"os/signal"
18+
"path/filepath"
19+
"runtime/debug"
20+
"syscall"
21+
22+
"github.com/urfave/cli/v2"
23+
24+
"github.com/free5gc/bsf/internal/logger"
25+
"github.com/free5gc/bsf/pkg/factory"
26+
"github.com/free5gc/bsf/pkg/service"
27+
logger_util "github.com/free5gc/util/logger"
28+
"github.com/free5gc/util/version"
29+
)
30+
31+
var BSF *service.BsfApp
32+
33+
func main() {
34+
defer func() {
35+
if p := recover(); p != nil {
36+
// Print stack for panic to log. Fatalf() will let program exit.
37+
logger.MainLog.Fatalf("panic: %v\n%s", p, string(debug.Stack()))
38+
}
39+
}()
40+
41+
app := cli.NewApp()
42+
app.Name = "bsf"
43+
app.Usage = "5G Binding Support Function (BSF)"
44+
app.Action = action
45+
app.Flags = []cli.Flag{
46+
&cli.StringFlag{
47+
Name: "config",
48+
Aliases: []string{"c"},
49+
Usage: "Load configuration from `FILE`",
50+
},
51+
&cli.StringSliceFlag{
52+
Name: "log",
53+
Aliases: []string{"l"},
54+
Usage: "Output NF log to `FILE`",
55+
},
56+
}
57+
if err := app.Run(os.Args); err != nil {
58+
fmt.Printf("BSF Run Error: %v\n", err)
59+
}
60+
}
61+
62+
func action(cliCtx *cli.Context) error {
63+
tlsKeyLogPath, err := initLogFile(cliCtx.StringSlice("log"))
64+
if err != nil {
65+
return err
66+
}
67+
68+
logger.MainLog.Infoln(cliCtx.App.Name)
69+
logger.MainLog.Infoln("BSF version: ", version.GetVersion())
70+
71+
ctx, cancel := context.WithCancel(context.Background())
72+
sigCh := make(chan os.Signal, 1)
73+
signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM)
74+
75+
go func() {
76+
<-sigCh // Wait for interrupt signal to gracefully shutdown BSF
77+
cancel() // Notify each goroutine and wait them stopped
78+
if BSF != nil {
79+
BSF.Terminate()
80+
}
81+
}()
82+
83+
cfg, err := factory.ReadConfig(cliCtx.String("config"))
84+
if err != nil {
85+
sigCh <- nil
86+
return err
87+
}
88+
factory.BsfConfig = cfg
89+
90+
bsf, err := service.NewApp(ctx, cfg, tlsKeyLogPath)
91+
if err != nil {
92+
sigCh <- nil
93+
return err
94+
}
95+
BSF = bsf
96+
if bsf == nil {
97+
logger.MainLog.Infoln("bsf is nil")
98+
}
99+
bsf.Start()
100+
101+
return nil
102+
}
103+
104+
func initLogFile(logNfPath []string) (string, error) {
105+
logTlsKeyPath := ""
106+
107+
for _, path := range logNfPath {
108+
if err := logger_util.LogFileHook(logger.Log, path); err != nil {
109+
return "", err
110+
}
111+
112+
if logTlsKeyPath != "" {
113+
continue
114+
}
115+
116+
nfDir, _ := filepath.Split(path)
117+
tmpDir := filepath.Join(nfDir, "key")
118+
if err := os.MkdirAll(tmpDir, 0o775); err != nil {
119+
logger.InitLog.Errorf("Make directory %s failed: %+v", tmpDir, err)
120+
return "", err
121+
}
122+
_, name := filepath.Split(factory.BsfDefaultTLSKeyLogPath)
123+
logTlsKeyPath = filepath.Join(tmpDir, name)
124+
}
125+
126+
return logTlsKeyPath, nil
127+
}

go.mod

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
module github.com/free5gc/bsf
2+
3+
go 1.24
4+
5+
require (
6+
github.com/free5gc/openapi v1.2.0
7+
github.com/free5gc/util v1.3.0
8+
github.com/gin-contrib/cors v1.6.0
9+
github.com/gin-gonic/gin v1.10.0
10+
github.com/google/uuid v1.4.0
11+
github.com/sirupsen/logrus v1.9.3
12+
github.com/stretchr/testify v1.11.0
13+
github.com/urfave/cli/v2 v2.27.7
14+
go.mongodb.org/mongo-driver v1.17.1
15+
gopkg.in/yaml.v2 v2.4.0
16+
)
17+
18+
require github.com/google/go-cmp v0.7.0 // indirect
19+
20+
require (
21+
github.com/beorn7/perks v1.0.1 // indirect
22+
github.com/bytedance/sonic v1.11.6 // indirect
23+
github.com/bytedance/sonic/loader v0.1.1 // indirect
24+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
25+
github.com/cloudwego/base64x v0.1.4 // indirect
26+
github.com/cloudwego/iasm v0.2.0 // indirect
27+
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
28+
github.com/davecgh/go-spew v1.1.1 // indirect
29+
github.com/felixge/httpsnoop v1.0.4 // indirect
30+
github.com/free5gc/aper v1.0.6-0.20250102035630-3ddc831eed6a // indirect
31+
github.com/free5gc/nas v1.2.0 // indirect
32+
github.com/free5gc/ngap v1.1.0 // indirect
33+
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
34+
github.com/gin-contrib/sse v0.1.0 // indirect
35+
github.com/go-logr/logr v1.4.1 // indirect
36+
github.com/go-logr/stdr v1.2.2 // indirect
37+
github.com/go-playground/locales v0.14.1 // indirect
38+
github.com/go-playground/universal-translator v0.18.1 // indirect
39+
github.com/go-playground/validator/v10 v10.20.0 // indirect
40+
github.com/goccy/go-json v0.10.2 // indirect
41+
github.com/golang-jwt/jwt/v5 v5.2.2 // indirect
42+
github.com/golang/snappy v0.0.4 // indirect
43+
github.com/h2non/gock v1.2.0 // indirect
44+
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect
45+
github.com/json-iterator/go v1.1.12 // indirect
46+
github.com/klauspost/compress v1.18.0 // indirect
47+
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
48+
github.com/leodido/go-urn v1.4.0 // indirect
49+
github.com/mattn/go-isatty v0.0.20 // indirect
50+
github.com/mitchellh/mapstructure v1.5.0 // indirect
51+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
52+
github.com/modern-go/reflect2 v1.0.2 // indirect
53+
github.com/montanaflynn/stats v0.7.1 // indirect
54+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
55+
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
56+
github.com/pkg/errors v0.9.1 // indirect
57+
github.com/pmezard/go-difflib v1.0.0 // indirect
58+
github.com/prometheus/client_golang v1.21.0 // indirect
59+
github.com/prometheus/client_model v0.6.1 // indirect
60+
github.com/prometheus/common v0.62.0 // indirect
61+
github.com/prometheus/procfs v0.15.1 // indirect
62+
github.com/russross/blackfriday/v2 v2.1.0 // indirect
63+
github.com/tim-ywliu/nested-logrus-formatter v1.3.2 // indirect
64+
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
65+
github.com/ugorji/go/codec v1.2.12 // indirect
66+
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
67+
github.com/xdg-go/scram v1.1.2 // indirect
68+
github.com/xdg-go/stringprep v1.0.4 // indirect
69+
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
70+
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
71+
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.49.0 // indirect
72+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
73+
go.opentelemetry.io/otel v1.24.0 // indirect
74+
go.opentelemetry.io/otel/metric v1.24.0 // indirect
75+
go.opentelemetry.io/otel/trace v1.24.0 // indirect
76+
golang.org/x/arch v0.8.0 // indirect
77+
golang.org/x/crypto v0.38.0 // indirect
78+
golang.org/x/net v0.40.0 // indirect
79+
golang.org/x/oauth2 v0.30.0 // indirect
80+
golang.org/x/sync v0.14.0 // indirect
81+
golang.org/x/sys v0.33.0 // indirect
82+
golang.org/x/text v0.25.0 // indirect
83+
google.golang.org/protobuf v1.36.6 // indirect
84+
gopkg.in/yaml.v3 v3.0.1 // indirect
85+
)

0 commit comments

Comments
 (0)