Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow empty SD value in SNSSAI #29

Merged
merged 3 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions nasConvert/Snssai.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import (
"github.com/free5gc/openapi/models"
)

// TS24.501 9.11.2.8 S-NSSAI
func SnssaiToModels(nasSnssai *nasType.SNSSAI) (snssai models.Snssai) {
sD := nasSnssai.GetSD()
snssai.Sd = hex.EncodeToString(sD[:])
if nasSnssai.GetLen() == uint8(4) {
sD := nasSnssai.GetSD()
snssai.Sd = hex.EncodeToString(sD[:])
}
snssai.Sst = int32(nasSnssai.GetSST())
return
}
Expand Down
84 changes: 84 additions & 0 deletions nasConvert/Snssai_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package nasConvert_test

import (
"testing"

"github.com/free5gc/nas/nasConvert"
"github.com/free5gc/nas/nasType"
"github.com/free5gc/openapi/models"
"github.com/stretchr/testify/require"
)

func TestSnssaiToModels(t *testing.T) {
testCase := []struct {
Name string
nasSnssai nasType.SNSSAI
expectSnssai models.Snssai
}{
{
Name: "Default",
nasSnssai: nasType.SNSSAI{
Iei: uint8(1),
Len: uint8(4),
Octet: [8]uint8{1, 1, 2, 3},
},
expectSnssai: models.Snssai{
Sst: int32(1),
Sd: "010203",
},
},
{
Name: "Empty SD",
nasSnssai: nasType.SNSSAI{
Iei: uint8(1),
Len: uint8(1),
Octet: [8]uint8{1},
},
expectSnssai: models.Snssai{
Sst: int32(1),
},
},
}

for _, tc := range testCase {
t.Run(tc.Name, func(t *testing.T) {
result := nasConvert.SnssaiToModels(&tc.nasSnssai)
require.Equal(t, tc.expectSnssai, result)
})
}
}

func TestSnssaiToNas(t *testing.T) {
testCase := []struct {
Name string
Snssai models.Snssai
nasSnssai []uint8
}{
{
Name: "Default",
Snssai: models.Snssai{
Sst: int32(1),
Sd: "010203",
},
nasSnssai: []uint8{
04, 01, 01, 02, 03,
},
},
{
Name: "Empty SD",
Snssai: models.Snssai{
Sst: int32(1),
},
nasSnssai: []uint8{
01, 01,
},
},
}

for _, tc := range testCase {
t.Run(tc.Name, func(t *testing.T) {
result := nasConvert.SnssaiToNas(tc.Snssai)
require.Equal(t, tc.nasSnssai, result)
})
}
}
Loading