Skip to content

Commit

Permalink
Merge pull request #35 from free5gc/feat/cgf-enable
Browse files Browse the repository at this point in the history
feat: CGF enable disable config
  • Loading branch information
ianchen0119 authored Sep 4, 2024
2 parents 516f992 + ac79c72 commit 0f1a647
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 9 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/fclairamb/ftpserverlib v0.21.0
github.com/fclairamb/go-log v0.4.1
github.com/fiorix/go-diameter v3.0.2+incompatible
github.com/free5gc/openapi v1.0.9-0.20240423011706-2d0028a9b5e1
github.com/free5gc/openapi v1.0.9-0.20240730084323-449098e08462
github.com/free5gc/util v1.0.6
github.com/gin-gonic/gin v1.9.1
github.com/google/uuid v1.3.0
Expand Down Expand Up @@ -48,7 +48,7 @@ require (
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang-jwt/jwt v3.2.1+incompatible // indirect
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.3 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ github.com/fiorix/go-diameter v3.0.2+incompatible h1:PLk2NkqMYILlEdeiz0hJVB3xcuu
github.com/fiorix/go-diameter v3.0.2+incompatible/go.mod h1:GgNrDCADT8o3k8zV1UsI473j8CFdLGY9ikZYDNEeYU8=
github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4=
github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20=
github.com/free5gc/openapi v1.0.9-0.20240423011706-2d0028a9b5e1 h1:FfC7eshpnGNBND5RZ5dBy3q59KKfKSxhsqGcxqvqbtw=
github.com/free5gc/openapi v1.0.9-0.20240423011706-2d0028a9b5e1/go.mod h1:hKziqKVGp/C4k7EN1sMn0fMflQX3DS8tqTgnhb/pemU=
github.com/free5gc/openapi v1.0.9-0.20240730084323-449098e08462 h1:bK9UWqOhoddpAW9RfZRp4DPZNnPfEUeHvo4I86YAuzA=
github.com/free5gc/openapi v1.0.9-0.20240730084323-449098e08462/go.mod h1:afeuEQ21QCQDxZHnFjCmYrq3gBi+cd/WDNSUbaMcILo=
github.com/free5gc/util v1.0.6 h1:dBt9drcXtYKE/cY5XuQcuffgsYclPIpIArhSeS6M+DQ=
github.com/free5gc/util v1.0.6/go.mod h1:eSGN7POUM8LNTvg/E591XR6447a6/w1jFWGKNZPHcXw=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
Expand Down Expand Up @@ -192,8 +192,8 @@ github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MG
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang-jwt/jwt v3.2.1+incompatible h1:73Z+4BJcrTC+KczS6WvTPvRGOp1WmfEP4Q1lOd9Z/+c=
github.com/golang-jwt/jwt v3.2.1+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down
6 changes: 6 additions & 0 deletions internal/cgf/cgf.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type FtpConfig struct {
}

var cgf *Cgf
var CGFEnable bool = false

func OpenServer(ctx context.Context, wg *sync.WaitGroup) *Cgf {
// Arguments vars
Expand Down Expand Up @@ -157,6 +158,11 @@ func Login() error {

func SendCDR(supi string) error {
logger.CfgLog.Debugln("SendCDR:", supi)
if !CGFEnable {
logger.CfgLog.Warningln("CGF Not enable: SendCDR() didn't do anything.")
return nil
}

if cgf.conn == nil {
err := Login()

Expand Down
5 changes: 5 additions & 0 deletions internal/sbi/consumer/nrf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ func (s *nnrfService) RegisterNFInstance(ctx context.Context) (
var nf models.NfProfile
var res *http.Response
for {
select {
case <-ctx.Done():
return "", "", errors.Errorf("Context Cancel before RegisterNFInstance")
default:
}
nf, res, err = client.NFInstanceIDDocumentApi.RegisterNFInstance(ctx, chfContext.NfId, nfProfile)
if err != nil || res == nil {
logger.ConsumerLog.Errorf("CHF register to NRF Error[%v]", err)
Expand Down
3 changes: 2 additions & 1 deletion internal/sbi/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type ServerChf interface {

Consumer() *consumer.Consumer
Processor() *processor.Processor
CancelContext() context.Context
}

type Server struct {
Expand Down Expand Up @@ -67,7 +68,7 @@ func NewServer(chf ServerChf, tlsKeyLogPath string) (*Server, error) {

func (s *Server) Run(traceCtx context.Context, wg *sync.WaitGroup) error {
var err error
_, s.Context().NfId, err = s.Consumer().RegisterNFInstance(context.Background())
_, s.Context().NfId, err = s.Consumer().RegisterNFInstance(s.CancelContext())
if err != nil {
logger.InitLog.Errorf("CHF register to NRF Error[%s]", err.Error())
}
Expand Down
1 change: 1 addition & 0 deletions pkg/factory/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ type Diameter struct {
}

type Cgf struct {
Enable bool `yaml:"enable,omitempty" valid:"type(bool)"`
HostIPv4 string `yaml:"hostIPv4,omitempty" valid:"required,host"`
Port int `yaml:"port,omitempty" valid:"required,port"`
ListenPort int `yaml:"listenPort,omitempty" valid:"required,port"`
Expand Down
7 changes: 5 additions & 2 deletions pkg/service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,11 @@ func (c *ChfApp) SetReportCaller(reportCaller bool) {
func (a *ChfApp) Start() {
logger.InitLog.Infoln("Server started")

a.wg.Add(1)
cgf.OpenServer(a.ctx, &a.wg)
if a.cfg.Configuration.Cgf.Enable {
cgf.CGFEnable = true
a.wg.Add(1)
cgf.OpenServer(a.ctx, &a.wg)
}

a.wg.Add(1)
rf.OpenServer(a.ctx, &a.wg)
Expand Down

0 comments on commit 0f1a647

Please sign in to comment.