Skip to content

Commit

Permalink
Merge branch 'main' into feat/r17
Browse files Browse the repository at this point in the history
  • Loading branch information
pf-lin authored Sep 24, 2024
2 parents 40eac4b + 325c399 commit f4ea19b
Show file tree
Hide file tree
Showing 6 changed files with 308 additions and 31 deletions.
73 changes: 65 additions & 8 deletions internal/context/datapath.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,13 +444,27 @@ func (dataPath *DataPath) ActivateTunnelAndPDR(smContext *SMContext, precedence
logger.PduSessLog.Errorln("new QER failed")
return
} else {
var bitRateKbpsULMBR uint64
var bitRateKbpsDLMBR uint64
var bitRateConvertErr error
bitRateKbpsULMBR, bitRateConvertErr = util.BitRateTokbps(sessionRule.AuthSessAmbr.Uplink)
if bitRateConvertErr != nil {
logger.PduSessLog.Errorln("Cannot get the unit of ULMBR, please check the settings in web console")
return
}
bitRateKbpsDLMBR, bitRateConvertErr = util.BitRateTokbps(sessionRule.AuthSessAmbr.Downlink)
if bitRateConvertErr != nil {
logger.PduSessLog.Errorln("Cannot get the unit of DLMBR, please check the settings in web console")
return
}
newQER.QFI.QFI = sessionRule.DefQosQFI
newQER.GateStatus = &pfcpType.GateStatus{
ULGate: pfcpType.GateOpen,
DLGate: pfcpType.GateOpen,
}
newQER.MBR = &pfcpType.MBR{
ULMBR: util.BitRateTokbps(sessionRule.AuthSessAmbr.Uplink),
DLMBR: util.BitRateTokbps(sessionRule.AuthSessAmbr.Downlink),
ULMBR: bitRateKbpsULMBR,
DLMBR: bitRateKbpsDLMBR,
}
ambrQER = newQER
}
Expand Down Expand Up @@ -849,19 +863,62 @@ func (p *DataPath) AddQoS(smContext *SMContext, qfi uint8, qos *models.QosData)
DLGate: pfcpType.GateOpen,
}
if isGBRFlow(qos) {
var bitRateKbpsQoSGBRUL uint64
var bitRateKbpsQoSGBRDL uint64
var bitRateKbpsQoSMBRUL uint64
var bitRateKbpsQoSMBRDL uint64
var bitRateConvertErr error
bitRateKbpsQoSGBRUL, bitRateConvertErr = util.BitRateTokbps(qos.GbrUl)
if bitRateConvertErr != nil {
logger.PduSessLog.Panicln("Cannot get the unit of GBRUL, please check the settings in web console")
return
}

bitRateKbpsQoSGBRDL, bitRateConvertErr = util.BitRateTokbps(qos.GbrDl)
if bitRateConvertErr != nil {
logger.PduSessLog.Panicln("Cannot get the unit of GBRDL, please check the settings in web console")
return
}

bitRateKbpsQoSMBRUL, bitRateConvertErr = util.BitRateTokbps(qos.MaxbrUl)
if bitRateConvertErr != nil {
logger.PduSessLog.Panicln("Cannot get the unit of MBRUL, please check the settings in web console")
return
}

bitRateKbpsQoSMBRDL, bitRateConvertErr = util.BitRateTokbps(qos.MaxbrDl)
if bitRateConvertErr != nil {
logger.PduSessLog.Panicln("Cannot get the unit of MBRDL, please check the settings in web console")
return
}

newQER.GBR = &pfcpType.GBR{
ULGBR: util.BitRateTokbps(qos.GbrUl),
DLGBR: util.BitRateTokbps(qos.GbrDl),
ULGBR: bitRateKbpsQoSGBRUL,
DLGBR: bitRateKbpsQoSGBRDL,
}
newQER.MBR = &pfcpType.MBR{
ULMBR: util.BitRateTokbps(qos.MaxbrUl),
DLMBR: util.BitRateTokbps(qos.MaxbrDl),
ULMBR: bitRateKbpsQoSMBRUL,
DLMBR: bitRateKbpsQoSMBRDL,
}
} else {
var bitRateKbpsSessionAmbrMBRUL uint64
var bitRateKbpsSessionAmbrMBRDL uint64
var bitRateConvertErr error
bitRateKbpsSessionAmbrMBRUL, bitRateConvertErr = util.BitRateTokbps(qos.MaxbrUl)
if bitRateConvertErr != nil {
logger.PduSessLog.Error("Cannot get the unit of MBRUL, please check the settings in web console")
return
}
bitRateKbpsSessionAmbrMBRDL, bitRateConvertErr = util.BitRateTokbps(qos.MaxbrDl)

if bitRateConvertErr != nil {
logger.PduSessLog.Error("Cannot get the unit of MBRDL, please check the settings in web console")
return
}
// 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),
ULMBR: bitRateKbpsSessionAmbrMBRUL,
DLMBR: bitRateKbpsSessionAmbrMBRDL,
}
}
qer = newQER
Expand Down
17 changes: 9 additions & 8 deletions internal/sbi/processor/ulcl_procedure.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ func EstablishULCL(smContext *context.SMContext) {
DownLinkPDR := curDPNode.DownLinkTunnel.PDR
UPLinkPDR.State = context.RULE_INITIAL

// new IPFilterRule with action:"permit" and diection:"out"
// new IPFilterRule with action:"permit" and direction:"out"
FlowDespcription := flowdesc.NewIPFilterRule()
FlowDespcription.Dst = dest.DestinationIP
FlowDespcription.Src = dest.DestinationIP
if dstPort, err := flowdesc.ParsePorts(dest.DestinationPort); err != nil {
FlowDespcription.DstPorts = dstPort
FlowDespcription.SrcPorts = dstPort
}
FlowDespcription.Src = smContext.PDUAddress.To4().String()
FlowDespcription.Dst = smContext.PDUAddress.To4().String()

FlowDespcriptionStr, err := flowdesc.Encode(FlowDespcription)
if err != nil {
Expand Down Expand Up @@ -305,13 +305,13 @@ func UpdateRANAndIUPFUpLink(smContext *context.SMContext) {

if _, exist := bpMGR.UpdatedBranchingPoint[curDPNode.UPF]; exist {
// add SDF Filter
// new IPFilterRule with action:"permit" and diection:"out"
// new IPFilterRule with action:"permit" and direction:"out"
FlowDespcription := flowdesc.NewIPFilterRule()
FlowDespcription.Dst = dest.DestinationIP
FlowDespcription.Src = dest.DestinationIP
if dstPort, err := flowdesc.ParsePorts(dest.DestinationPort); err != nil {
FlowDespcription.DstPorts = dstPort
FlowDespcription.SrcPorts = dstPort
}
FlowDespcription.Src = smContext.PDUAddress.To4().String()
FlowDespcription.Dst = smContext.PDUAddress.To4().String()

FlowDespcriptionStr, err := flowdesc.Encode(FlowDespcription)
if err != nil {
Expand All @@ -328,6 +328,7 @@ func UpdateRANAndIUPFUpLink(smContext *context.SMContext) {
FlowDescription: []byte(FlowDespcriptionStr),
}
}
UPLinkPDR.Precedence = 30

pfcpState := &PFCPState{
upf: curDPNode.UPF,
Expand Down
11 changes: 8 additions & 3 deletions internal/util/qos_convert.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
package util

import (
"errors"
"strconv"
"strings"

"github.com/free5gc/ngap/ngapType"
)

func BitRateTokbps(bitrate string) uint64 {
func BitRateTokbps(bitrate string) (uint64, error) {
s := strings.Split(bitrate, " ")
var kbps uint64

var digit int

if n, err := strconv.Atoi(s[0]); err != nil {
return 0
return 0, nil
} else {
digit = n
}

if len(s) == 1 {
return 0, errors.New("cannot get the unit of ULMBR/DLMBR/ULGBR/DLGBR, please check the settings in web console")
}

switch s[1] {
case "bps":
kbps = uint64(digit / 1000)
Expand All @@ -31,7 +36,7 @@ func BitRateTokbps(bitrate string) uint64 {
case "Tbps":
kbps = uint64(digit * 1000000000)
}
return kbps
return kbps, nil
}

func BitRateTombps(bitrate string) uint16 {
Expand Down
104 changes: 104 additions & 0 deletions internal/util/qos_convert_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package util_test

import (
"testing"

"github.com/free5gc/smf/internal/util"
)

func TestBitRateToKbpsWithValidBpsBitRateShouldReturnValidKbpsBitRate(t *testing.T) {
var bitrate string = "1000 bps"
var correctBitRateKbps uint64 = 1

bitrateKbps, err := util.BitRateTokbps(bitrate)

t.Log("Check: err should be nil since act should work correctly.")
if err != nil {
t.Errorf("Error: err should be nil but it returns %s", err)
}
t.Log("Check: convert should act correctly.")
if bitrateKbps != correctBitRateKbps {
t.Errorf("Error: bitrate convert failed. Expect: %d. Actually: %d", correctBitRateKbps, bitrateKbps)
}
t.Log("Passed.")
}

func TestBitRateToKbpsWithValidKbpsBitRateShouldReturnValidKbpsBitRate(t *testing.T) {
var bitrate string = "1000 Kbps"
var correctBitRateKbps uint64 = 1000

bitrateKbps, err := util.BitRateTokbps(bitrate)

t.Log("Check: err should be nil since act should work correctly.")
if err != nil {
t.Errorf("Error: err should be nil but it returns %s", err)
}
t.Log("Check: convert should act correctly.")
if bitrateKbps != correctBitRateKbps {
t.Errorf("Error: bitrate convert failed. Expect: %d. Actually: %d", correctBitRateKbps, bitrateKbps)
}
t.Log("Passed.")
}

func TestBitRateToKbpsWithValidMbpsBitRateShouldReturnValidKbpsBitRate(t *testing.T) {
var bitrate string = "1000 Mbps"
var correctBitRateKbps uint64 = 1000000

bitrateKbps, err := util.BitRateTokbps(bitrate)

t.Log("Check: err should be nil since act should work correctly.")
if err != nil {
t.Errorf("Error: err should be nil but it returns %s", err)
}
t.Log("Check: convert should act correctly.")
if bitrateKbps != correctBitRateKbps {
t.Errorf("Error: bitrate convert failed. Expect: %d. Actually: %d", correctBitRateKbps, bitrateKbps)
}
t.Log("Passed.")
}

func TestBitRateToKbpsWithValidGbpsBitRateShouldReturnValidKbpsBitRate(t *testing.T) {
var bitrate string = "1000 Gbps"
var correctBitRateKbps uint64 = 1000000000

bitrateKbps, err := util.BitRateTokbps(bitrate)

t.Log("Check: err should be nil since act should work correctly.")
if err != nil {
t.Errorf("Error: err should be nil but it returns %s", err)
}
t.Log("Check: convert should act correctly.")
if bitrateKbps != correctBitRateKbps {
t.Errorf("Error: bitrate convert failed. Expect: %d. Actually: %d", correctBitRateKbps, bitrateKbps)
}
t.Log("Passed.")
}

func TestBitRateToKbpsWithValidTbpsBitRateShouldReturnValidKbpsBitRate(t *testing.T) {
var bitrate string = "1000 Tbps"
var correctBitRateKbps uint64 = 1000000000000

bitrateKbps, err := util.BitRateTokbps(bitrate)

t.Log("Check: err should be nil since act should work correctly.")
if err != nil {
t.Errorf("Error: err should be nil but it returns %s", err)
}
t.Log("Check: convert should act correctly.")
if bitrateKbps != correctBitRateKbps {
t.Errorf("Error: bitrate convert failed. Expect: %d. Actually: %d", correctBitRateKbps, bitrateKbps)
}
t.Log("Passed.")
}

func TestBitRateToKbpsWithInvalidBitRateShouldReturnError(t *testing.T) {
var bitrate string = "1000" // The unit is absent. It should raise error for `BitRateToKbps`.

_, err := util.BitRateTokbps(bitrate)

t.Log("Check: err should not be nil.")
if err == nil {
t.Error("Error: err should not be nil.")
}
t.Log("Passed.")
}
28 changes: 16 additions & 12 deletions pkg/factory/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (c *Configuration) validate() (bool, error) {
}

for _, snssaiInfo := range c.SNssaiInfo {
if result, err := snssaiInfo.validate(); err != nil {
if result, err := snssaiInfo.Validate(); err != nil {
return result, err
}
}
Expand Down Expand Up @@ -166,17 +166,19 @@ type SnssaiInfoItem struct {
DnnInfos []*SnssaiDnnInfoItem `yaml:"dnnInfos" valid:"required"`
}

func (s *SnssaiInfoItem) validate() (bool, error) {
func (s *SnssaiInfoItem) Validate() (bool, error) {
if snssai := s.SNssai; snssai != nil {
if result := (snssai.Sst >= 0 && snssai.Sst <= 255); !result {
err := errors.New("Invalid sNssai.Sst: " + strconv.Itoa(int(snssai.Sst)) + ", should be in range 0~255.")
return false, err
}

if result := govalidator.StringMatches(snssai.Sd, "^[0-9A-Fa-f]{6}$"); !result {
err := errors.New("Invalid sNssai.Sd: " + snssai.Sd +
", should be 3 bytes hex string and in range 000000~FFFFFF.")
return false, err
if snssai.Sd != "" {
if result := govalidator.StringMatches(snssai.Sd, "^[0-9A-Fa-f]{6}$"); !result {
err := errors.New("Invalid sNssai.Sd: " + snssai.Sd +
", should be 3 bytes hex string and in range 000000~FFFFFF.")
return false, err
}
}
}

Expand Down Expand Up @@ -489,7 +491,7 @@ func (u *UPNode) validate() (bool, error) {
})

for _, snssaiInfo := range u.SNssaiInfos {
if result, err := snssaiInfo.validate(); err != nil {
if result, err := snssaiInfo.Validate(); err != nil {
return result, err
}
}
Expand Down Expand Up @@ -547,17 +549,19 @@ type SnssaiUpfInfoItem struct {
DnnUpfInfoList []*DnnUpfInfoItem `json:"dnnUpfInfoList" yaml:"dnnUpfInfoList" valid:"required"`
}

func (s *SnssaiUpfInfoItem) validate() (bool, error) {
func (s *SnssaiUpfInfoItem) Validate() (bool, error) {
if s.SNssai != nil {
if result := (s.SNssai.Sst >= 0 && s.SNssai.Sst <= 255); !result {
err := errors.New("Invalid sNssai.Sst: " + strconv.Itoa(int(s.SNssai.Sst)) + ", should be in range 0~255.")
return false, err
}

if result := govalidator.StringMatches(s.SNssai.Sd, "^[0-9A-Fa-f]{6}$"); !result {
err := errors.New("Invalid sNssai.Sd: " + s.SNssai.Sd +
", should be 3 bytes hex string and in range 000000~FFFFFF.")
return false, err
if s.SNssai.Sd != "" {
if result := govalidator.StringMatches(s.SNssai.Sd, "^[0-9A-Fa-f]{6}$"); !result {
err := errors.New("Invalid sNssai.Sd: " + s.SNssai.Sd +
", should be 3 bytes hex string and in range 000000~FFFFFF.")
return false, err
}
}
}

Expand Down
Loading

0 comments on commit f4ea19b

Please sign in to comment.