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 SMF Set ID encoding #136

Merged
merged 1 commit into from
Dec 23, 2023
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
2 changes: 1 addition & 1 deletion ie/ie.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ func (i *IE) ValueAsString() (string, error) {
return string(i.Payload), nil
}

// ValueAsFQDN returns the value of IE as FQDN.
// ValueAsFQDN returns the value of IE as string, decoded as FQDN.
func (i *IE) ValueAsFQDN() (string, error) {
if i.IsGrouped() {
return "", &InvalidTypeError{Type: i.Type}
Expand Down
2 changes: 1 addition & 1 deletion ie/ie_string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func TestStringIEs(t *testing.T) {
description: "SMFSetID",
structured: ie.NewSMFSetID("go-pfcp"),
decoded: "go-pfcp",
decoderFunc: func(i *ie.IE) (string, error) { return i.SMFSetIDString() },
decoderFunc: func(i *ie.IE) (string, error) { return i.SMFSetID() },
}, {
description: "UEIPAddressPoolIdentity",
structured: ie.NewUEIPAddressPoolIdentity("go-pfcp"),
Expand Down
2 changes: 1 addition & 1 deletion ie/ie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2451,7 +2451,7 @@ func TestIEs(t *testing.T) {
}, {
"SMFSetID",
ie.NewSMFSetID("go-pfcp.epc.3gppnetwork.org"),
[]byte{0x00, 0xb4, 0x00, 0x1c, 0x00, 0x67, 0x6f, 0x2d, 0x70, 0x66, 0x63, 0x70, 0x2e, 0x65, 0x70, 0x63, 0x2e, 0x33, 0x67, 0x70, 0x70, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2e, 0x6f, 0x72, 0x67},
[]byte{0x00, 0xb4, 0x00, 0x1c, 0x07, 0x67, 0x6f, 0x2d, 0x70, 0x66, 0x63, 0x70, 0x03, 0x65, 0x70, 0x63, 0x0b, 0x33, 0x67, 0x70, 0x70, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x03, 0x6f, 0x72, 0x67},
}, {
"QuotaValidityTime",
ie.NewQuotaValidityTime(10 * time.Second),
Expand Down
32 changes: 5 additions & 27 deletions ie/smf-set-id.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,16 @@

package ie

import "io"

// NewSMFSetID creates a new SMFSetID IE.
func NewSMFSetID(id string) *IE {
l := len([]byte(id))
i := New(SMFSetID, make([]byte, 1+l))

i.Payload[0] = 0 // Spare
copy(i.Payload[1:], id)

return i
return newFQDNIE(SMFSetID, id)
}

// SMFSetID returns SMFSetID in []byte if the type of IE matches.
func (i *IE) SMFSetID() ([]byte, error) {
// SMFSetID returns SMFSetID in string if the type of IE matches.
func (i *IE) SMFSetID() (string, error) {
if i.Type != SMFSetID {
return nil, &InvalidTypeError{Type: i.Type}
}

return i.Payload, nil
}

// SMFSetIDString returns SMFSetID in string if the type of IE matches.
func (i *IE) SMFSetIDString() (string, error) {
v, err := i.SMFSetID()
if err != nil {
return "", err
}

if len(v) < 1 {
return "", io.ErrUnexpectedEOF
return "", &InvalidTypeError{Type: i.Type}
}

return string(v[1:]), nil
return i.ValueAsFQDN()
}
4 changes: 2 additions & 2 deletions message/association-setup-request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestAssociationSetupRequest(t *testing.T) {
0x00, 0x2b, 0x00, 0x02, 0x01, 0x02,
0x00, 0x59, 0x00, 0x01, 0x3f,
0x00, 0xb2, 0x00, 0x15, 0x03, 0x7f, 0x00, 0x00, 0x01, 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x00, 0xb4, 0x00, 0x1c, 0x00, 0x67, 0x6f, 0x2d, 0x70, 0x66, 0x63, 0x70, 0x2e, 0x65, 0x70, 0x63, 0x2e, 0x33, 0x67, 0x70, 0x70, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2e, 0x6f, 0x72, 0x67,
0x00, 0xb4, 0x00, 0x1c, 0x07, 0x67, 0x6f, 0x2d, 0x70, 0x66, 0x63, 0x70, 0x03, 0x65, 0x70, 0x63, 0x0b, 0x33, 0x67, 0x70, 0x70, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x03, 0x6f, 0x72, 0x67,
0x00, 0xb7, 0x00, 0x09,
0x00, 0xb9, 0x00, 0x05, 0x02, 0x7f, 0x00, 0x00, 0x01,
0x00, 0xe9, 0x00, 0x25,
Expand Down Expand Up @@ -165,7 +165,7 @@ func TestAssociationSetupRequest(t *testing.T) {
0x00,
0x00, 0xb2, 0x00, 0x15, 0x03, 0x7f, 0x00, 0x00, 0x01, 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x00, 0xb2, 0x00, 0x15, 0x03, 0x7f, 0x00, 0x00, 0x02, 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
0x00, 0xb4, 0x00, 0x1c, 0x00, 0x67, 0x6f, 0x2d, 0x70, 0x66, 0x63, 0x70, 0x2e, 0x65, 0x70, 0x63, 0x2e, 0x33, 0x67, 0x70, 0x70, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2e, 0x6f, 0x72, 0x67,
0x00, 0xb4, 0x00, 0x1c, 0x07, 0x67, 0x6f, 0x2d, 0x70, 0x66, 0x63, 0x70, 0x03, 0x65, 0x70, 0x63, 0x0b, 0x33, 0x67, 0x70, 0x70, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x03, 0x6f, 0x72, 0x67,
0x00, 0xb7, 0x00, 0x09,
0x00, 0xb9, 0x00, 0x05, 0x02, 0x7f, 0x00, 0x00, 0x01,
0x00, 0xe9, 0x00, 0x29,
Expand Down
Loading