Skip to content

Commit

Permalink
Merge pull request #31 from free5gc/fix/allow-empty-sd
Browse files Browse the repository at this point in the history
fix: Allow empty sd in Slice snssai
  • Loading branch information
ianchen0119 authored Aug 16, 2024
2 parents 9dabfef + 13313a2 commit bc1afea
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/free5gc/util v1.0.6
github.com/gin-contrib/cors v1.6.0
github.com/gin-gonic/gin v1.9.1
github.com/go-playground/assert/v2 v2.2.0
github.com/google/uuid v1.4.0
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
github.com/pkg/errors v0.9.1
Expand Down
2 changes: 2 additions & 0 deletions internal/sbi/processor/ampolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,10 @@ func (p *Processor) HandlePostPolicies(
// TODO: set gin header
c.Header("Location", locationHeader)
c.JSON(http.StatusCreated, response)
return
} else if problemDetails != nil {
c.JSON(int(problemDetails.Status), problemDetails)
return
}

problemDetails = &models.ProblemDetails{
Expand Down
3 changes: 2 additions & 1 deletion internal/sbi/processor/smpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ func (p *Processor) HandleCreateSmPolicyRequest(
queryStrength := 2 // 2: case-insensitive, 3: case-sensitive
logger.SmPolicyLog.Tracef("Handle Create SM Policy Request")

if request.Supi == "" || request.SliceInfo == nil || len(request.SliceInfo.Sd) != 6 {
if request.Supi == "" || request.SliceInfo == nil {
problemDetail := util.GetProblemDetail("Errorneous/Missing Mandotory IE", util.ERROR_INITIAL_PARAMETERS)
logger.SmPolicyLog.Warnln("Errorneous/Missing Mandotory IE", util.ERROR_INITIAL_PARAMETERS)
c.JSON(int(problemDetail.Status), problemDetail)
return
}
logger.ProcLog.Debugf("Request SUPI:[%s], SNSSAI:[%v]", request.Supi, request.SliceInfo)

pcfSelf := p.Context()
var ue *pcf_context.UeContext
Expand Down
1 change: 1 addition & 0 deletions internal/util/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var policyTriggerArray = []models.PolicyControlRequestTrigger{
// }

// Convert Snssai form models to hexString(sst(2)+sd(6))
// TODO: In R17 openapi, it's would be replace by openapi.SnssaiModelsToHex
func SnssaiModelsToHex(snssai models.Snssai) string {
sst := fmt.Sprintf("%02x", snssai.Sst)
return sst + snssai.Sd
Expand Down
40 changes: 40 additions & 0 deletions internal/util/convert_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package util

import (
"testing"

"github.com/go-playground/assert/v2"

"github.com/free5gc/openapi/models"
)

func TestSnssaiModelsToHex(t *testing.T) {
tests := []struct {
name string
snssai models.Snssai
expectString string
}{
{
name: "01010202",
snssai: models.Snssai{
Sst: 1,
Sd: "010203",
},
expectString: "01010203",
},
{
name: "Empty SD",
snssai: models.Snssai{
Sst: 1,
},
expectString: "01",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
output := SnssaiModelsToHex(tt.snssai)
assert.Equal(t, tt.expectString, output)
})
}
}

0 comments on commit bc1afea

Please sign in to comment.