This repository has been archived by the owner on Oct 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Adds optional up function features IE
- Loading branch information
Showing
10 changed files
with
280 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
package ie | ||
|
||
import ( | ||
"encoding/binary" | ||
"fmt" | ||
) | ||
|
||
type UPFunctionFeatures struct { | ||
IEType uint16 | ||
Length uint16 | ||
SupportedFeatures []byte | ||
AdditionalSupportedFeatures1 []byte | ||
AdditionalSupportedFeatures2 []byte | ||
} | ||
|
||
type UPFeature int | ||
|
||
const ( | ||
BUCP UPFeature = iota | ||
DDND | ||
DLBD | ||
TRST | ||
FTUP | ||
PFDM | ||
HEEU | ||
TREU | ||
EMPU | ||
PDIU | ||
UDBC | ||
QUOAC | ||
TRACE | ||
FRRT | ||
PFDE | ||
EPFAR | ||
DPDRA | ||
ADPDP | ||
UEIP | ||
SSET | ||
MNOP | ||
MTE | ||
BUNDL | ||
GCOM | ||
MPAS | ||
RTTL | ||
VTIME | ||
NORP | ||
IPTV | ||
IP6PL | ||
TSCU | ||
MPTCP | ||
ATSSSLL | ||
QFQM | ||
GPQM | ||
MTEDT | ||
CIOT | ||
ETHAR | ||
DDDS | ||
RDS | ||
RTTWP | ||
NumberOfUPFeatures | ||
) | ||
|
||
func NewUPFunctionFeatures(supportedFeatures []UPFeature) UPFunctionFeatures { | ||
featureBytes := make([]byte, 2) | ||
|
||
for _, feature := range supportedFeatures { | ||
if feature < NumberOfUPFeatures { | ||
byteIndex := feature / 8 | ||
bitPosition := feature % 8 | ||
featureBytes[byteIndex] |= 1 << bitPosition | ||
} | ||
} | ||
|
||
return UPFunctionFeatures{ | ||
IEType: 43, | ||
Length: uint16(len(featureBytes)), | ||
SupportedFeatures: featureBytes, | ||
AdditionalSupportedFeatures1: nil, | ||
AdditionalSupportedFeatures2: nil, | ||
} | ||
} | ||
|
||
func (ie UPFunctionFeatures) Serialize() []byte { | ||
totalLength := 4 + ie.Length | ||
serialized := make([]byte, totalLength) | ||
|
||
binary.BigEndian.PutUint16(serialized[0:2], ie.IEType) | ||
binary.BigEndian.PutUint16(serialized[2:4], ie.Length) | ||
|
||
copy(serialized[4:], ie.SupportedFeatures) | ||
|
||
return serialized | ||
} | ||
|
||
func (ie UPFunctionFeatures) GetFeatures() []UPFeature { | ||
features := make([]UPFeature, 0) | ||
|
||
for i, byteValue := range ie.SupportedFeatures { | ||
for j := 0; j < 8; j++ { | ||
if byteValue&(1<<j) > 0 { | ||
features = append(features, UPFeature(i*8+j)) | ||
} | ||
} | ||
} | ||
|
||
return features | ||
} | ||
|
||
func (ie UPFunctionFeatures) IsZeroValue() bool { | ||
return ie.Length == 0 | ||
} | ||
|
||
func DeserializeUPFunctionFeatures(ieType uint16, ieLength uint16, ieValue []byte) (UPFunctionFeatures, error) { | ||
if ieType != 43 { | ||
return UPFunctionFeatures{}, fmt.Errorf("incorrect IE type") | ||
} | ||
if len(ieValue) != int(ieLength) { | ||
return UPFunctionFeatures{}, fmt.Errorf("incorrect length: expected %d, got %d", ieLength, len(ieValue)) | ||
} | ||
|
||
upFuncFeatures := UPFunctionFeatures{ | ||
IEType: ieType, | ||
Length: ieLength, | ||
SupportedFeatures: make([]byte, 0), | ||
AdditionalSupportedFeatures1: make([]byte, 0), | ||
AdditionalSupportedFeatures2: make([]byte, 0), | ||
} | ||
|
||
if ieLength >= 1 { | ||
upFuncFeatures.SupportedFeatures = append(upFuncFeatures.SupportedFeatures, ieValue[0]) | ||
} | ||
if ieLength >= 2 { | ||
upFuncFeatures.SupportedFeatures = append(upFuncFeatures.SupportedFeatures, ieValue[1]) | ||
} | ||
|
||
return upFuncFeatures, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package ie_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/dot-5g/pfcp/ie" | ||
) | ||
|
||
func TestGivenSerializedWhenDeserializedThenDeserializedCorrectly(t *testing.T) { | ||
features := [](ie.UPFeature){ | ||
ie.BUCP, | ||
ie.TRACE, | ||
} | ||
|
||
upFunctionFeatures := ie.NewUPFunctionFeatures(features) | ||
serializedUPFunctionFeatures := upFunctionFeatures.Serialize() | ||
|
||
deserializedUPFunctionFeatures, err := ie.DeserializeUPFunctionFeatures(43, 2, serializedUPFunctionFeatures[4:]) | ||
if err != nil { | ||
t.Fatalf("Error deserializing UPFunctionFeatures: %v", err) | ||
} | ||
|
||
if deserializedUPFunctionFeatures.IEType != 43 { | ||
t.Errorf("Expected IE type 43, got %d", deserializedUPFunctionFeatures.IEType) | ||
} | ||
|
||
if deserializedUPFunctionFeatures.Length != 2 { | ||
t.Errorf("Expected IE length 2, got %d", deserializedUPFunctionFeatures.Length) | ||
} | ||
|
||
if len(deserializedUPFunctionFeatures.SupportedFeatures) != 2 { | ||
t.Errorf("Expected 2 supported features, got %d", len(deserializedUPFunctionFeatures.SupportedFeatures)) | ||
} | ||
|
||
deserializedFeatures := deserializedUPFunctionFeatures.GetFeatures() | ||
|
||
if len(deserializedFeatures) != 2 { | ||
t.Errorf("Expected 2 features, got %d", len(deserializedFeatures)) | ||
} | ||
|
||
if deserializedFeatures[0] != ie.BUCP { | ||
t.Errorf("Expected BUCP feature, got %v", deserializedFeatures[0]) | ||
} | ||
|
||
if deserializedFeatures[1] != ie.TRACE { | ||
t.Errorf("Expected TRACE feature, got %v", deserializedFeatures[1]) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.