Skip to content

Commit

Permalink
Merge branch 'main' into sdm_subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
saileshvvr authored Jun 8, 2024
2 parents 216e322 + 8c1d9b6 commit 17836af
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 91 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/commit-msg-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: 'Commit Message Check'

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
name: Conventional Commits
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: webiny/[email protected]
6 changes: 3 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: [ '1.18', '1.21' ]
go: [ '1.21' ]
name: Go ${{ matrix.go }} sample
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}

Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: [ '1.18' ]
go: [ '1.21' ]
steps:
- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v4
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.45.2
version: v1.57.2

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func main() {
Usage: "Output NF log to `FILE`",
},
}
rand.Seed(time.Now().UnixNano())
rand.New(rand.NewSource(time.Now().UnixNano()))

if err := app.Run(os.Args); err != nil {
logger.MainLog.Errorf("SMF Run error: %v\n", err)
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/free5gc/smf

go 1.17
go 1.21

require (
github.com/antihax/optional v1.0.0
Expand Down Expand Up @@ -59,10 +59,10 @@ require (
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/oauth2 v0.0.0-20210810183815-faf39c7919d5 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/appengine v1.6.6 // indirect
google.golang.org/protobuf v1.33.0 // indirect
Expand Down
69 changes: 6 additions & 63 deletions go.sum

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions internal/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ type SMFContext struct {
}

func GenerateChargingID() int32 {
if id, err := smfContext.ChargingIDGenerator.Allocate(); err == nil {
return int32(id)
if smfContext.ChargingIDGenerator != nil {
if id, err := smfContext.ChargingIDGenerator.Allocate(); err == nil {
return int32(id)
}
}
return 0
}
Expand Down Expand Up @@ -261,6 +263,7 @@ func InitSmfContext(config *factory.Config) {

smfContext.Locality = configuration.Locality


smfContext.Ues = InitSmfUeData()

TeidGenerator = idgenerator.NewGenerator(1, math.MaxUint32)
Expand Down
6 changes: 6 additions & 0 deletions internal/context/datapath.go
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,12 @@ func (p *DataPath) AddQoS(smContext *SMContext, qfi uint8, qos *models.QosData)
ULMBR: util.BitRateTokbps(qos.MaxbrUl),
DLMBR: util.BitRateTokbps(qos.MaxbrDl),
}
} else {
// Non-GBR flow should follows session-AMBR
newQER.MBR = &pfcpType.MBR{
ULMBR: util.BitRateTokbps(smContext.DnnConfiguration.SessionAmbr.Uplink),
DLMBR: util.BitRateTokbps(smContext.DnnConfiguration.SessionAmbr.Downlink),
}
}
qer = newQER
}
Expand Down
4 changes: 0 additions & 4 deletions internal/context/ngap_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func HandlePDUSessionResourceSetupResponseTransfer(b []byte, ctx *SMContext) (er
resourceSetupResponseTransfer := ngapType.PDUSessionResourceSetupResponseTransfer{}

err = aper.UnmarshalWithParams(b, &resourceSetupResponseTransfer, "valueExt")

if err != nil {
return err
}
Expand Down Expand Up @@ -109,7 +108,6 @@ func HandlePDUSessionResourceSetupUnsuccessfulTransfer(b []byte, ctx *SMContext)
resourceSetupUnsuccessfulTransfer := ngapType.PDUSessionResourceSetupUnsuccessfulTransfer{}

err = aper.UnmarshalWithParams(b, &resourceSetupUnsuccessfulTransfer, "valueExt")

if err != nil {
return err
}
Expand Down Expand Up @@ -196,7 +194,6 @@ func HandlePathSwitchRequestSetupFailedTransfer(b []byte, ctx *SMContext) (err e
pathSwitchRequestSetupFailedTransfer := ngapType.PathSwitchRequestSetupFailedTransfer{}

err = aper.UnmarshalWithParams(b, &pathSwitchRequestSetupFailedTransfer, "valueExt")

if err != nil {
return err
}
Expand Down Expand Up @@ -229,7 +226,6 @@ func HandleHandoverRequestAcknowledgeTransfer(b []byte, ctx *SMContext) (err err
handoverRequestAcknowledgeTransfer := ngapType.HandoverRequestAcknowledgeTransfer{}

err = aper.UnmarshalWithParams(b, &handoverRequestAcknowledgeTransfer, "valueExt")

if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions internal/context/sm_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ func NewSMContext(id string, pduSessID int32) *SMContext {
smContext.ChargingInfo = make(map[uint32]*ChargingInfo)
smContext.ChargingID = GenerateChargingID()

if factory.SmfConfig.Configuration != nil {
if factory.SmfConfig != nil &&
factory.SmfConfig.Configuration != nil {
smContext.UrrReportTime = time.Duration(factory.SmfConfig.Configuration.UrrPeriod) * time.Second
smContext.UrrReportThreshold = factory.SmfConfig.Configuration.UrrThreshold
logger.CtxLog.Infof("UrrPeriod: %v", smContext.UrrReportTime)
Expand Down Expand Up @@ -401,7 +402,7 @@ func RemoveSMContext(ref string) {
}

// *** add unit test ***//
func GetSMContextBySEID(SEID uint64) *SMContext {
func GetSMContextBySEID(SEID uint64) *SMContext {>>>>>>> main

Check failure on line 405 in internal/context/sm_context.go

View workflow job for this annotation

GitHub Actions / lint (1.21)

syntax error: unexpected >>, expected }) (typecheck)

Check failure on line 405 in internal/context/sm_context.go

View workflow job for this annotation

GitHub Actions / lint (1.21)

syntax error: unexpected >>, expected }) (typecheck)

Check failure on line 405 in internal/context/sm_context.go

View workflow job for this annotation

GitHub Actions / lint (1.21)

syntax error: unexpected >>, expected }) (typecheck)

Check failure on line 405 in internal/context/sm_context.go

View workflow job for this annotation

GitHub Actions / lint (1.21)

syntax error: unexpected >>, expected } (typecheck)

Check failure on line 405 in internal/context/sm_context.go

View workflow job for this annotation

GitHub Actions / lint (1.21)

expected statement, found '>>' (typecheck)

Check failure on line 405 in internal/context/sm_context.go

View workflow job for this annotation

GitHub Actions / Go 1.21 sample

syntax error: unexpected >>, expected }
if value, ok := seidSMContextMap.Load(SEID); ok {
smContext := value.(*SMContext)
return smContext
Expand Down
6 changes: 6 additions & 0 deletions internal/context/sm_context_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,12 @@ func TestApplyPccRules(t *testing.T) {
},
}
smctx.SelectedSessionRuleID = "SessRuleId-1"
smctx.DnnConfiguration = models.DnnConfiguration{
SessionAmbr: &models.Ambr{
Uplink: "1 Gbps",
Downlink: "1 Gbps",
},
}
err := smctx.AllocUeIP()
require.NoError(t, err)
err = smctx.SelectDefaultDataPath()
Expand Down
13 changes: 13 additions & 0 deletions internal/sbi/oam/api_get_smf_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package oam

import (
"github.com/gin-gonic/gin"

"github.com/free5gc/smf/internal/sbi/producer"
)

func HTTPGetSMFUserPlaneInfo(c *gin.Context) {
HTTPResponse := producer.HandleGetSMFUserPlaneInfo()

c.JSON(HTTPResponse.Status, HTTPResponse.Body)
}
6 changes: 6 additions & 0 deletions internal/sbi/oam/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,10 @@ var routes = Routes{
"/ue-pdu-session-info/:smContextRef",
HTTPGetUEPDUSessionInfo,
},
{
"Get SMF Userplane Information",
"GET",
"/user-plane-info/",
HTTPGetSMFUserPlaneInfo,
},
}
10 changes: 10 additions & 0 deletions internal/sbi/producer/oam.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/free5gc/openapi/models"
"github.com/free5gc/smf/internal/context"
"github.com/free5gc/smf/pkg/factory"
"github.com/free5gc/util/httpwrapper"
)

Expand Down Expand Up @@ -54,3 +55,12 @@ func HandleOAMGetUEPDUSessionInfo(smContextRef string) *httpwrapper.Response {
}
return httpResponse
}

func HandleGetSMFUserPlaneInfo() *httpwrapper.Response {
httpResponse := &httpwrapper.Response{
Header: nil,
Status: http.StatusOK,
Body: factory.SmfConfig.Configuration.UserPlaneInformation,
}
return httpResponse
}
2 changes: 1 addition & 1 deletion internal/sbi/producer/pdu_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func HandlePDUSessionSMContextCreate(isDone <-chan struct{},

upi := smf_context.GetUserPlaneInformation()
upi.Mu.RLock()
defer upi.Mu.RUnlock()
defer upi.Mu.RUnlock()>>>>>>> main

Check failure on line 70 in internal/sbi/producer/pdu_session.go

View workflow job for this annotation

GitHub Actions / lint (1.21)

expected operand, found '>>' (typecheck)

// DNN Information from config
smContext.DNNInfo = smf_context.RetrieveDnnInformation(smContext.SNssai, smContext.Dnn)
Expand Down
6 changes: 3 additions & 3 deletions pkg/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package factory

import (
"fmt"
"io/ioutil"
"os"

"github.com/asaskevich/govalidator"
"gopkg.in/yaml.v2"
Expand All @@ -26,7 +26,7 @@ func InitConfigFactory(f string, cfg *Config) error {
f = SmfDefaultConfigPath
}

if content, err := ioutil.ReadFile(f); err != nil {
if content, err := os.ReadFile(f); err != nil {
return fmt.Errorf("[Factory] %+v", err)
} else {
logger.CfgLog.Infof("Read config from [%s]", f)
Expand All @@ -43,7 +43,7 @@ func InitRoutingConfigFactory(f string, cfg *RoutingConfig) error {
// Use default config path
f = SmfDefaultUERoutingPath
}
if content, err := ioutil.ReadFile(f); err != nil {
if content, err := os.ReadFile(f); err != nil {
return err
} else {
logger.CfgLog.Infof("Read config from [%s]", f)
Expand Down
6 changes: 3 additions & 3 deletions pkg/service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package service
import (
"context"
"fmt"
"io/ioutil"
"io"
"os"
"os/signal"
"runtime/debug"
Expand Down Expand Up @@ -49,15 +49,15 @@ func (a *SmfApp) SetLogEnable(enable bool) {
logger.MainLog.Infof("Log enable is set to [%v]", enable)
if enable && logger.Log.Out == os.Stderr {
return
} else if !enable && logger.Log.Out == ioutil.Discard {
} else if !enable && logger.Log.Out == io.Discard {
return
}

a.cfg.SetLogEnable(enable)
if enable {
logger.Log.SetOutput(os.Stderr)
} else {
logger.Log.SetOutput(ioutil.Discard)
logger.Log.SetOutput(io.Discard)
}
}

Expand Down

0 comments on commit 17836af

Please sign in to comment.