Skip to content

Commit

Permalink
Merge pull request #136 from wmnsk/smf-set-id
Browse files Browse the repository at this point in the history
Fix SMF Set ID encoding
  • Loading branch information
wmnsk authored Dec 23, 2023
2 parents 030dc55 + 2393690 commit 7d5c387
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 32 deletions.
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

0 comments on commit 7d5c387

Please sign in to comment.