This repository has been archived by the owner on Aug 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
encode_test.go
84 lines (78 loc) · 2.29 KB
/
encode_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright 2019 free5GC.org
//
// SPDX-License-Identifier: Apache-2.0
//
package pfcp_test
import (
"net"
"testing"
"github.com/stretchr/testify/require"
"github.com/omec-project/pfcp"
"github.com/omec-project/pfcp/pfcpType"
)
func TestMarshal(t *testing.T) {
var testCases = []struct {
name string
message pfcp.Message
expectedBuf []byte
}{
{
name: "Association Setup Request",
message: pfcp.Message{
Header: pfcp.Header{
Version: 1,
MP: 0,
S: 0,
MessageType: pfcp.PFCP_ASSOCIATION_SETUP_REQUEST,
MessageLength: 0,
SEID: 0,
SequenceNumber: 1,
MessagePriority: 0,
},
Body: pfcp.PFCPAssociationSetupRequest{
NodeID: &pfcpType.NodeID{
NodeIdType: 0,
NodeIdValue: net.ParseIP("192.188.2.2").To4(),
},
},
},
expectedBuf: []byte{0x20, 0x5, 0x0, 0xd, 0x0, 0x0, 0x1, 0x0, 0x0, 0x3c, 0x0, 0x5, 0x0, 0xc0, 0xbc, 0x2, 0x2},
},
{
name: "Session Establishment Request",
message: pfcp.Message{
Header: pfcp.Header{
Version: 1,
MP: 0,
S: 1,
MessageType: pfcp.PFCP_SESSION_ESTABLISHMENT_REQUEST,
MessageLength: 0,
SEID: 0x02,
SequenceNumber: 1,
MessagePriority: 0,
},
Body: pfcp.PFCPSessionEstablishmentRequest{
NodeID: &pfcpType.NodeID{
NodeIdType: 0,
NodeIdValue: net.ParseIP("192.188.2.2").To4(),
},
CreatePDR: []*pfcp.CreatePDR{
{
PDRID: &pfcpType.PacketDetectionRuleID{RuleId: 1},
Precedence: &pfcpType.Precedence{PrecedenceValue: 32},
OuterHeaderRemoval: &pfcpType.OuterHeaderRemoval{OuterHeaderRemovalDescription: pfcpType.OuterHeaderRemovalGtpUUdpIpv4},
},
},
},
},
expectedBuf: []byte{0x21, 0x32, 0x0, 0x2c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2, 0x0, 0x0, 0x1, 0x0, 0x0, 0x3c, 0x0, 0x5, 0x0, 0xc0, 0xbc, 0x2, 0x2, 0x0, 0x1, 0x0, 0x13, 0x0, 0x38, 0x0, 0x2, 0x0, 0x1, 0x0, 0x1d, 0x0, 0x4, 0x0, 0x0, 0x0, 0x20, 0x0, 0x5f, 0x0, 0x1, 0x0},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
buf, err := tc.message.Marshal()
require.Nil(t, err, "encode message", tc.name, "failed")
require.Equal(t, tc.expectedBuf, buf)
})
}
}