From 20016e12fbb9911a67a29d2552bc5e285a5b2a85 Mon Sep 17 00:00:00 2001 From: ntut-xuan Date: Tue, 30 Jul 2024 05:03:53 +0000 Subject: [PATCH 01/12] Fix: Panic when MBRUL/MBRDL/GBRUL/GBRDL without unit --- internal/context/datapath.go | 64 +++++++++++++++++++++++++++++++----- internal/util/qos_convert.go | 11 +++++-- 2 files changed, 64 insertions(+), 11 deletions(-) diff --git a/internal/context/datapath.go b/internal/context/datapath.go index 292f9209..6d894682 100644 --- a/internal/context/datapath.go +++ b/internal/context/datapath.go @@ -434,6 +434,18 @@ func (dataPath *DataPath) ActivateTunnelAndPDR(smContext *SMContext, precedence sessionRule := smContext.SelectedSessionRule() + bitRateKbpsULMBR, err := util.BitRateTokbps(sessionRule.AuthSessAmbr.Uplink) + + if err != nil { + logger.PduSessLog.Error("Cannot get the unit of ULMBR, please check the settings in web console") + } + + bitRateKbpsDLMBR, err := util.BitRateTokbps(sessionRule.AuthSessAmbr.Downlink) + + if err != nil { + logger.PduSessLog.Error("Cannot get the unit of DLMBR, please check the settings in web console") + } + // Activate PDR for curDataPathNode := firstDPNode; curDataPathNode != nil; curDataPathNode = curDataPathNode.Next() { var defaultQER *QER @@ -449,8 +461,8 @@ func (dataPath *DataPath) ActivateTunnelAndPDR(smContext *SMContext, precedence 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 } @@ -836,6 +848,42 @@ func (p *DataPath) AddQoS(smContext *SMContext, qfi uint8, qos *models.QosData) currentUUID := node.UPF.GetUUID() id := getQosIdKey(currentUUID, qfi) + bitRateKbpsQoSGBRUL, err := util.BitRateTokbps(qos.GbrUl) + + if err != nil { + logger.PduSessLog.Error("Cannot get the unit of GBRUL, please check the settings in web console") + } + + bitRateKbpsQoSGBRDL, err := util.BitRateTokbps(qos.GbrDl) + + if err != nil { + logger.PduSessLog.Error("Cannot get the unit of GBRDL, please check the settings in web console") + } + + bitRateKbpsQoSMBRUL, err := util.BitRateTokbps(qos.MaxbrUl) + + if err != nil { + logger.PduSessLog.Error("Cannot get the unit of MBRUL, please check the settings in web console") + } + + bitRateKbpsQoSMBRDL, err := util.BitRateTokbps(qos.MaxbrDl) + + if err != nil { + logger.PduSessLog.Error("Cannot get the unit of MBRDL, please check the settings in web console") + } + + bitRateKbpsSessionAmbrMBRUL, err := util.BitRateTokbps(qos.MaxbrUl) + + if err != nil { + logger.PduSessLog.Error("Cannot get the unit of MBRUL, please check the settings in web console") + } + + bitRateKbpsSessionAmbrMBRDL, err := util.BitRateTokbps(qos.MaxbrDl) + + if err != nil { + logger.PduSessLog.Error("Cannot get the unit of MBRDL, please check the settings in web console") + } + if qerId, ok := smContext.QerUpfMap[id]; !ok { if newQER, err := node.UPF.AddQER(); err != nil { logger.PduSessLog.Errorln("new QER failed") @@ -850,18 +898,18 @@ func (p *DataPath) AddQoS(smContext *SMContext, qfi uint8, qos *models.QosData) } if isGBRFlow(qos) { 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 { // 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 diff --git a/internal/util/qos_convert.go b/internal/util/qos_convert.go index 602814a1..c9adcd60 100644 --- a/internal/util/qos_convert.go +++ b/internal/util/qos_convert.go @@ -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) @@ -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 { From 3c015b8ee1cb8e3880a21dc340fdc10854eca302 Mon Sep 17 00:00:00 2001 From: ntut-xuan Date: Tue, 30 Jul 2024 06:19:31 +0000 Subject: [PATCH 02/12] Chore: Arrange block --- internal/context/datapath.go | 93 +++++++++++++++++------------------- internal/util/qos_convert.go | 2 +- 2 files changed, 46 insertions(+), 49 deletions(-) diff --git a/internal/context/datapath.go b/internal/context/datapath.go index 6d894682..fc8515d5 100644 --- a/internal/context/datapath.go +++ b/internal/context/datapath.go @@ -434,18 +434,6 @@ func (dataPath *DataPath) ActivateTunnelAndPDR(smContext *SMContext, precedence sessionRule := smContext.SelectedSessionRule() - bitRateKbpsULMBR, err := util.BitRateTokbps(sessionRule.AuthSessAmbr.Uplink) - - if err != nil { - logger.PduSessLog.Error("Cannot get the unit of ULMBR, please check the settings in web console") - } - - bitRateKbpsDLMBR, err := util.BitRateTokbps(sessionRule.AuthSessAmbr.Downlink) - - if err != nil { - logger.PduSessLog.Error("Cannot get the unit of DLMBR, please check the settings in web console") - } - // Activate PDR for curDataPathNode := firstDPNode; curDataPathNode != nil; curDataPathNode = curDataPathNode.Next() { var defaultQER *QER @@ -456,6 +444,16 @@ func (dataPath *DataPath) ActivateTunnelAndPDR(smContext *SMContext, precedence logger.PduSessLog.Errorln("new QER failed") return } else { + bitRateKbpsULMBR, err := util.BitRateTokbps(sessionRule.AuthSessAmbr.Uplink) + if err != nil { + logger.PduSessLog.Errorln("Cannot get the unit of ULMBR, please check the settings in web console") + return + } + bitRateKbpsDLMBR, err := util.BitRateTokbps(sessionRule.AuthSessAmbr.Downlink) + if err != nil { + logger.PduSessLog.Errorln("Cannot get the unit of DLMBR, please check the settings in web console") + return + } newQER.GateStatus = &pfcpType.GateStatus{ ULGate: pfcpType.GateOpen, DLGate: pfcpType.GateOpen, @@ -848,42 +846,6 @@ func (p *DataPath) AddQoS(smContext *SMContext, qfi uint8, qos *models.QosData) currentUUID := node.UPF.GetUUID() id := getQosIdKey(currentUUID, qfi) - bitRateKbpsQoSGBRUL, err := util.BitRateTokbps(qos.GbrUl) - - if err != nil { - logger.PduSessLog.Error("Cannot get the unit of GBRUL, please check the settings in web console") - } - - bitRateKbpsQoSGBRDL, err := util.BitRateTokbps(qos.GbrDl) - - if err != nil { - logger.PduSessLog.Error("Cannot get the unit of GBRDL, please check the settings in web console") - } - - bitRateKbpsQoSMBRUL, err := util.BitRateTokbps(qos.MaxbrUl) - - if err != nil { - logger.PduSessLog.Error("Cannot get the unit of MBRUL, please check the settings in web console") - } - - bitRateKbpsQoSMBRDL, err := util.BitRateTokbps(qos.MaxbrDl) - - if err != nil { - logger.PduSessLog.Error("Cannot get the unit of MBRDL, please check the settings in web console") - } - - bitRateKbpsSessionAmbrMBRUL, err := util.BitRateTokbps(qos.MaxbrUl) - - if err != nil { - logger.PduSessLog.Error("Cannot get the unit of MBRUL, please check the settings in web console") - } - - bitRateKbpsSessionAmbrMBRDL, err := util.BitRateTokbps(qos.MaxbrDl) - - if err != nil { - logger.PduSessLog.Error("Cannot get the unit of MBRDL, please check the settings in web console") - } - if qerId, ok := smContext.QerUpfMap[id]; !ok { if newQER, err := node.UPF.AddQER(); err != nil { logger.PduSessLog.Errorln("new QER failed") @@ -897,6 +859,30 @@ func (p *DataPath) AddQoS(smContext *SMContext, qfi uint8, qos *models.QosData) DLGate: pfcpType.GateOpen, } if isGBRFlow(qos) { + bitRateKbpsQoSGBRUL, err := util.BitRateTokbps(qos.GbrUl) + if err != nil { + logger.PduSessLog.Panicln("Cannot get the unit of GBRUL, please check the settings in web console") + return + } + + bitRateKbpsQoSGBRDL, err := util.BitRateTokbps(qos.GbrDl) + if err != nil { + logger.PduSessLog.Panicln("Cannot get the unit of GBRDL, please check the settings in web console") + return + } + + bitRateKbpsQoSMBRUL, err := util.BitRateTokbps(qos.MaxbrUl) + if err != nil { + logger.PduSessLog.Panicln("Cannot get the unit of MBRUL, please check the settings in web console") + return + } + + bitRateKbpsQoSMBRDL, err := util.BitRateTokbps(qos.MaxbrDl) + if err != nil { + logger.PduSessLog.Panicln("Cannot get the unit of MBRDL, please check the settings in web console") + return + } + newQER.GBR = &pfcpType.GBR{ ULGBR: bitRateKbpsQoSGBRUL, DLGBR: bitRateKbpsQoSGBRDL, @@ -906,6 +892,17 @@ func (p *DataPath) AddQoS(smContext *SMContext, qfi uint8, qos *models.QosData) DLMBR: bitRateKbpsQoSMBRDL, } } else { + bitRateKbpsSessionAmbrMBRUL, err := util.BitRateTokbps(qos.MaxbrUl) + if err != nil { + logger.PduSessLog.Error("Cannot get the unit of MBRUL, please check the settings in web console") + return + } + bitRateKbpsSessionAmbrMBRDL, err := util.BitRateTokbps(qos.MaxbrDl) + + if err != 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: bitRateKbpsSessionAmbrMBRUL, diff --git a/internal/util/qos_convert.go b/internal/util/qos_convert.go index c9adcd60..a376bca2 100644 --- a/internal/util/qos_convert.go +++ b/internal/util/qos_convert.go @@ -21,7 +21,7 @@ func BitRateTokbps(bitrate string) (uint64, error) { } if len(s) == 1 { - return 0, errors.New("cannot get the unit of ULMBR/DLMBR/ULGBR/DLGBR, please check the settings in web console") + return uint64(digit * 1000), errors.New("cannot get the unit of ULMBR/DLMBR/ULGBR/DLGBR, we use Mbps for default unit, please check the settings in web console") } switch s[1] { From e0d7e357a6ae806383d424ba3c5cf6e0b037e22a Mon Sep 17 00:00:00 2001 From: ntut-xuan Date: Tue, 30 Jul 2024 06:21:42 +0000 Subject: [PATCH 03/12] Revert: no default unit --- internal/util/qos_convert.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/util/qos_convert.go b/internal/util/qos_convert.go index a376bca2..c9adcd60 100644 --- a/internal/util/qos_convert.go +++ b/internal/util/qos_convert.go @@ -21,7 +21,7 @@ func BitRateTokbps(bitrate string) (uint64, error) { } if len(s) == 1 { - return uint64(digit * 1000), errors.New("cannot get the unit of ULMBR/DLMBR/ULGBR/DLGBR, we use Mbps for default unit, please check the settings in web console") + return 0, errors.New("cannot get the unit of ULMBR/DLMBR/ULGBR/DLGBR, please check the settings in web console") } switch s[1] { From c36495a2747620b44ada63eddacfa5b45a111312 Mon Sep 17 00:00:00 2001 From: "CTFang@WireLab" Date: Thu, 1 Aug 2024 07:49:05 +0000 Subject: [PATCH 04/12] fix: allow empty slice in config --- pkg/factory/config.go | 28 +++++----- pkg/factory/config_test.go | 106 +++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+), 12 deletions(-) create mode 100644 pkg/factory/config_test.go diff --git a/pkg/factory/config.go b/pkg/factory/config.go index 6c7e9fdd..b0ee3267 100644 --- a/pkg/factory/config.go +++ b/pkg/factory/config.go @@ -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 } } @@ -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 + } } } @@ -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 } } @@ -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 + } } } diff --git a/pkg/factory/config_test.go b/pkg/factory/config_test.go new file mode 100644 index 00000000..67b56b95 --- /dev/null +++ b/pkg/factory/config_test.go @@ -0,0 +1,106 @@ +package factory_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/free5gc/openapi/models" + "github.com/free5gc/smf/pkg/factory" +) + +func TestSnssaiInfoItem(t *testing.T) { + testcase := []struct { + Name string + Snssai *models.Snssai + DnnInfos []*factory.SnssaiDnnInfoItem + }{ + { + Name: "Default", + Snssai: &models.Snssai{ + Sst: int32(1), + Sd: "010203", + }, + DnnInfos: []*factory.SnssaiDnnInfoItem{ + { + Dnn: "internet", + DNS: &factory.DNS{ + IPv4Addr: "8.8.8.8", + }, + }, + }, + }, + { + Name: "Empty SD", + Snssai: &models.Snssai{ + Sst: int32(1), + }, + DnnInfos: []*factory.SnssaiDnnInfoItem{ + { + Dnn: "internet2", + DNS: &factory.DNS{ + IPv4Addr: "1.1.1.1", + }, + }, + }, + }, + } + + for _, tc := range testcase { + t.Run(tc.Name, func(t *testing.T) { + snssaiInfoItem := factory.SnssaiInfoItem{ + SNssai: tc.Snssai, + DnnInfos: tc.DnnInfos, + } + + ok, err := snssaiInfoItem.Validate() + require.True(t, ok) + require.Nil(t, err) + }) + } +} + +func TestSnssaiUpfInfoItem(t *testing.T) { + testcase := []struct { + Name string + Snssai *models.Snssai + DnnInfos []*factory.DnnUpfInfoItem + }{ + { + Name: "Default", + Snssai: &models.Snssai{ + Sst: int32(1), + Sd: "010203", + }, + DnnInfos: []*factory.DnnUpfInfoItem{ + { + Dnn: "internet", + }, + }, + }, + { + Name: "Empty SD", + Snssai: &models.Snssai{ + Sst: int32(1), + }, + DnnInfos: []*factory.DnnUpfInfoItem{ + { + Dnn: "internet2", + }, + }, + }, + } + + for _, tc := range testcase { + t.Run(tc.Name, func(t *testing.T) { + snssaiInfoItem := factory.SnssaiUpfInfoItem{ + SNssai: tc.Snssai, + DnnUpfInfoList: tc.DnnInfos, + } + + ok, err := snssaiInfoItem.Validate() + require.True(t, ok) + require.Nil(t, err) + }) + } +} From dbfa15d61746591c9a905fb26d4adba3758fd31e Mon Sep 17 00:00:00 2001 From: ntut-xuan Date: Tue, 6 Aug 2024 07:05:40 +0000 Subject: [PATCH 05/12] Fix: lint --- internal/context/datapath.go | 43 ++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/internal/context/datapath.go b/internal/context/datapath.go index fc8515d5..2e5049e9 100644 --- a/internal/context/datapath.go +++ b/internal/context/datapath.go @@ -444,13 +444,16 @@ func (dataPath *DataPath) ActivateTunnelAndPDR(smContext *SMContext, precedence logger.PduSessLog.Errorln("new QER failed") return } else { - bitRateKbpsULMBR, err := util.BitRateTokbps(sessionRule.AuthSessAmbr.Uplink) - if err != nil { + 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, err := util.BitRateTokbps(sessionRule.AuthSessAmbr.Downlink) - if err != nil { + 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 } @@ -859,26 +862,31 @@ func (p *DataPath) AddQoS(smContext *SMContext, qfi uint8, qos *models.QosData) DLGate: pfcpType.GateOpen, } if isGBRFlow(qos) { - bitRateKbpsQoSGBRUL, err := util.BitRateTokbps(qos.GbrUl) - if err != nil { + 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, err := util.BitRateTokbps(qos.GbrDl) - if err != nil { + 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, err := util.BitRateTokbps(qos.MaxbrUl) - if err != nil { + 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, err := util.BitRateTokbps(qos.MaxbrDl) - if err != nil { + 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 } @@ -892,14 +900,17 @@ func (p *DataPath) AddQoS(smContext *SMContext, qfi uint8, qos *models.QosData) DLMBR: bitRateKbpsQoSMBRDL, } } else { - bitRateKbpsSessionAmbrMBRUL, err := util.BitRateTokbps(qos.MaxbrUl) - if err != nil { + 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, err := util.BitRateTokbps(qos.MaxbrDl) + bitRateKbpsSessionAmbrMBRDL, bitRateConvertErr = util.BitRateTokbps(qos.MaxbrDl) - if err != nil { + if bitRateConvertErr != nil { logger.PduSessLog.Error("Cannot get the unit of MBRDL, please check the settings in web console") return } From cb6bcb208f111b95f8d0c2dfa1b254fb839c4c62 Mon Sep 17 00:00:00 2001 From: ntut-xuan Date: Wed, 7 Aug 2024 07:14:24 +0000 Subject: [PATCH 06/12] Feat: Add tests --- internal/util/tests/qos_convert_test.go | 36 +++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 internal/util/tests/qos_convert_test.go diff --git a/internal/util/tests/qos_convert_test.go b/internal/util/tests/qos_convert_test.go new file mode 100644 index 00000000..ec7b54f2 --- /dev/null +++ b/internal/util/tests/qos_convert_test.go @@ -0,0 +1,36 @@ +package qos_convert_test + +import ( + "testing" + + "github.com/free5gc/smf/internal/util" +) + +func TestBitRateToKbpsWithValidBitRateShouldReturnValidKbpsBitRate(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 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.") +} From c2f2ec6363bbb0c03c2e468a837a2fd67dc3d3c1 Mon Sep 17 00:00:00 2001 From: ntut-xuan Date: Wed, 7 Aug 2024 07:25:04 +0000 Subject: [PATCH 07/12] Feat: Add tests --- internal/util/tests/qos_convert_test.go | 70 ++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/internal/util/tests/qos_convert_test.go b/internal/util/tests/qos_convert_test.go index ec7b54f2..2a2732a3 100644 --- a/internal/util/tests/qos_convert_test.go +++ b/internal/util/tests/qos_convert_test.go @@ -6,7 +6,41 @@ import ( "github.com/free5gc/smf/internal/util" ) -func TestBitRateToKbpsWithValidBitRateShouldReturnValidKbpsBitRate(t *testing.T) { +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 @@ -23,6 +57,40 @@ func TestBitRateToKbpsWithValidBitRateShouldReturnValidKbpsBitRate(t *testing.T) 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`. From d15b10d62e90c5758f4f8fb929bd70b57a1cf6df Mon Sep 17 00:00:00 2001 From: "CTFang@WireLab" Date: Wed, 7 Aug 2024 08:33:10 +0000 Subject: [PATCH 08/12] fix: move testing file --- internal/util/{tests => }/qos_convert_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename internal/util/{tests => }/qos_convert_test.go (99%) diff --git a/internal/util/tests/qos_convert_test.go b/internal/util/qos_convert_test.go similarity index 99% rename from internal/util/tests/qos_convert_test.go rename to internal/util/qos_convert_test.go index 2a2732a3..b8aa4af0 100644 --- a/internal/util/tests/qos_convert_test.go +++ b/internal/util/qos_convert_test.go @@ -1,4 +1,4 @@ -package qos_convert_test +package util_test import ( "testing" From 358a132018dfc2b8ba86595ddcaa253dc9114bf4 Mon Sep 17 00:00:00 2001 From: ming-hsien Date: Tue, 20 Aug 2024 09:05:48 +0000 Subject: [PATCH 09/12] fix: Missing ambrQER QFI setting --- internal/context/datapath.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/context/datapath.go b/internal/context/datapath.go index 2e5049e9..3b540813 100644 --- a/internal/context/datapath.go +++ b/internal/context/datapath.go @@ -457,6 +457,7 @@ func (dataPath *DataPath) ActivateTunnelAndPDR(smContext *SMContext, precedence 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, From 5c2a162c3ecfcec0bcd23dfceafe58005df93237 Mon Sep 17 00:00:00 2001 From: yzlin Date: Wed, 18 Sep 2024 03:36:49 +0000 Subject: [PATCH 10/12] fix: swap source and destination when createing flowDescription of ULCL paths --- internal/sbi/processor/ulcl_procedure.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/sbi/processor/ulcl_procedure.go b/internal/sbi/processor/ulcl_procedure.go index b721a779..839c0b53 100644 --- a/internal/sbi/processor/ulcl_procedure.go +++ b/internal/sbi/processor/ulcl_procedure.go @@ -149,11 +149,11 @@ func EstablishULCL(smContext *context.SMContext) { // new IPFilterRule with action:"permit" and diection:"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 { From b8bce67515a9cc0ba00e14ebfbec94a822acacd4 Mon Sep 17 00:00:00 2001 From: ming-hsien Date: Wed, 18 Sep 2024 08:13:40 +0000 Subject: [PATCH 11/12] fix: segfault when removing gNB and UPF --- internal/sbi/processor/association.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/sbi/processor/association.go b/internal/sbi/processor/association.go index 9b60b233..10c2bf5f 100644 --- a/internal/sbi/processor/association.go +++ b/internal/sbi/processor/association.go @@ -255,6 +255,7 @@ func (p *Processor) requestAMFToReleasePDUResources( N1N2MessageTransfer(ctx, smContext.Supi, n1n2Request, smContext.CommunicationClientApiPrefix) if err != nil { logger.ConsumerLog.Warnf("N1N2MessageTransfer for RequestAMFToReleasePDUResources failed: %+v", err) + return false, true } switch *statusCode { From bf3240195702a3523e81ba354dcef234a0987d4e Mon Sep 17 00:00:00 2001 From: Louis Royer Date: Thu, 19 Sep 2024 11:45:42 +0200 Subject: [PATCH 12/12] fix: swap source and destination when updating flowDescription of ULCL paths; add missing precedence --- internal/sbi/processor/ulcl_procedure.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/sbi/processor/ulcl_procedure.go b/internal/sbi/processor/ulcl_procedure.go index 839c0b53..f19d9455 100644 --- a/internal/sbi/processor/ulcl_procedure.go +++ b/internal/sbi/processor/ulcl_procedure.go @@ -147,7 +147,7 @@ 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.Src = dest.DestinationIP if dstPort, err := flowdesc.ParsePorts(dest.DestinationPort); err != nil { @@ -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 { @@ -328,6 +328,7 @@ func UpdateRANAndIUPFUpLink(smContext *context.SMContext) { FlowDescription: []byte(FlowDespcriptionStr), } } + UPLinkPDR.Precedence = 30 pfcpState := &PFCPState{ upf: curDPNode.UPF,