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.
- Loading branch information
Showing
15 changed files
with
462 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package ie | ||
|
||
import ( | ||
"bytes" | ||
"encoding/binary" | ||
"errors" | ||
) | ||
|
||
type Report int | ||
|
||
const ( | ||
UISR Report = iota | ||
SESR | ||
TMIR | ||
UPIR | ||
ERIR | ||
USAR | ||
DLDR | ||
) | ||
|
||
type ReportType struct { | ||
IEType uint16 | ||
Length uint16 | ||
Reports []Report | ||
} | ||
|
||
func NewReportType(reports []Report) (ReportType, error) { | ||
return ReportType{ | ||
IEType: uint16(ReportTypeIEType), | ||
Length: 1, | ||
Reports: reports, | ||
}, nil | ||
} | ||
|
||
func (reportType ReportType) Serialize() []byte { | ||
buf := new(bytes.Buffer) | ||
|
||
// Octets 1 to 2: Type | ||
binary.Write(buf, binary.BigEndian, uint16(ReportTypeIEType)) | ||
|
||
// Octets 3 to 4: Length | ||
binary.Write(buf, binary.BigEndian, uint16(reportType.Length)) | ||
|
||
// Octet 5: Reports | ||
// Bit 1: DLDR, Bit 2: USAR, Bit 3: ERIR, Bit 4: UPIR, Bit 5: TMIR, Bit 6: SESR, Bit 7: UISR, Bit 8: Spare | ||
var reportsByte byte = 0 | ||
for _, report := range reportType.Reports { | ||
reportsByte |= 1 << report | ||
} | ||
buf.WriteByte(reportsByte) | ||
|
||
return buf.Bytes() | ||
} | ||
|
||
func (reportType ReportType) IsZeroValue() bool { | ||
return reportType.Length == 0 | ||
} | ||
|
||
func DeserializeReportType(ieType uint16, ieLength uint16, ieValue []byte) (ReportType, error) { | ||
if len(ieValue) != int(ieLength) { | ||
return ReportType{}, errors.New("invalid length for ReportType") | ||
} | ||
|
||
var reports []Report | ||
reportsByte := ieValue[0] | ||
|
||
for i := 0; i < 8; i++ { | ||
if reportsByte&(1<<i) != 0 { | ||
reports = append(reports, Report(i)) | ||
} | ||
} | ||
|
||
return ReportType{ | ||
IEType: ieType, | ||
Length: ieLength, | ||
Reports: reports, | ||
}, 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,75 @@ | ||
package ie_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/dot-5g/pfcp/ie" | ||
) | ||
|
||
func TestGivenCorrectValueWhenNewReportTypeThenFieldsSetCorrectly(t *testing.T) { | ||
reports := []ie.Report{ie.UISR, ie.SESR} | ||
|
||
reportType, err := ie.NewReportType(reports) | ||
|
||
if err != nil { | ||
t.Fatalf("Unexpected error: %v", err) | ||
} | ||
|
||
if reportType.IEType != uint16(ie.ReportTypeIEType) { | ||
t.Errorf("Expected IE type %d, got %d", ie.ReportTypeIEType, reportType.IEType) | ||
} | ||
|
||
if reportType.Length != 1 { | ||
t.Errorf("Expected length 1, got %d", reportType.Length) | ||
} | ||
|
||
if len(reportType.Reports) != 2 { | ||
t.Errorf("Expected 2 reports, got %d", len(reportType.Reports)) | ||
} | ||
|
||
if reportType.Reports[0] != ie.UISR { | ||
t.Errorf("Expected report %d, got %d", ie.UISR, reportType.Reports[0]) | ||
} | ||
|
||
if reportType.Reports[1] != ie.SESR { | ||
t.Errorf("Expected report %d, got %d", ie.SESR, reportType.Reports[1]) | ||
} | ||
} | ||
|
||
func TestGivenSerializedWhenDeserializeReportTypeThenFieldsSetCorrectly(t *testing.T) { | ||
reports := []ie.Report{ie.UISR, ie.SESR} | ||
|
||
reportType, err := ie.NewReportType(reports) | ||
|
||
if err != nil { | ||
t.Fatalf("Unexpected error: %v", err) | ||
} | ||
|
||
serializedReportType := reportType.Serialize() | ||
|
||
deserializedReportType, err := ie.DeserializeReportType(39, 1, serializedReportType[4:]) | ||
if err != nil { | ||
t.Fatalf("Unexpected error: %v", err) | ||
} | ||
|
||
if deserializedReportType.IEType != uint16(ie.ReportTypeIEType) { | ||
t.Errorf("Expected IE type %d, got %d", ie.ReportTypeIEType, deserializedReportType.IEType) | ||
} | ||
|
||
if deserializedReportType.Length != 1 { | ||
t.Errorf("Expected length 1, got %d", deserializedReportType.Length) | ||
} | ||
|
||
if len(deserializedReportType.Reports) != 2 { | ||
t.Errorf("Expected 2 reports, got %d", len(deserializedReportType.Reports)) | ||
} | ||
|
||
if deserializedReportType.Reports[0] != ie.UISR { | ||
t.Errorf("Expected report %d, got %d", ie.UISR, deserializedReportType.Reports[0]) | ||
} | ||
|
||
if deserializedReportType.Reports[1] != ie.SESR { | ||
t.Errorf("Expected report %d, got %d", ie.SESR, deserializedReportType.Reports[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
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,45 @@ | ||
package messages | ||
|
||
import "github.com/dot-5g/pfcp/ie" | ||
|
||
type PFCPSessionReportRequest struct { | ||
ReportType ie.ReportType // Mandatory | ||
} | ||
|
||
type PFCPSessionReportResponse struct { | ||
Cause ie.Cause // Mandatory | ||
} | ||
|
||
func DeserializePFCPSessionReportRequest(data []byte) (PFCPMessage, error) { | ||
ies, err := ie.ParseInformationElements(data) | ||
var reportType ie.ReportType | ||
|
||
for _, elem := range ies { | ||
if reportTypeIE, ok := elem.(ie.ReportType); ok { | ||
reportType = reportTypeIE | ||
continue | ||
} | ||
|
||
} | ||
|
||
return PFCPSessionReportRequest{ | ||
ReportType: reportType, | ||
}, err | ||
} | ||
|
||
func DeserializePFCPSessionReportResponse(data []byte) (PFCPMessage, error) { | ||
ies, err := ie.ParseInformationElements(data) | ||
var cause ie.Cause | ||
|
||
for _, elem := range ies { | ||
if causeIE, ok := elem.(ie.Cause); ok { | ||
cause = causeIE | ||
continue | ||
} | ||
|
||
} | ||
|
||
return PFCPSessionReportResponse{ | ||
Cause: cause, | ||
}, err | ||
} |
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
Oops, something went wrong.