forked from omec-project/pfcp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
decode_test.go
85 lines (79 loc) · 2.33 KB
/
decode_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
85
// Copyright 2019 free5GC.org
//
// SPDX-License-Identifier: Apache-2.0
//
package pfcp_test
import (
"net"
"testing"
"github.com/stretchr/testify/require"
"github.com/free5gc/pfcp"
"github.com/free5gc/pfcp/pfcpType"
)
func TestUnmarshal(t *testing.T) {
var testCases = []struct {
name string
expectedMessage pfcp.Message
inputBuf []byte
}{
{
name: "Association Setup Request",
expectedMessage: pfcp.Message{
Header: pfcp.Header{
Version: 1,
MP: 0,
S: 0,
MessageType: pfcp.PFCP_ASSOCIATION_SETUP_REQUEST,
MessageLength: 13,
SEID: 0,
SequenceNumber: 1,
MessagePriority: 0,
},
Body: pfcp.PFCPAssociationSetupRequest{
NodeID: &pfcpType.NodeID{
NodeIdType: 0,
NodeIdValue: net.ParseIP("192.188.2.2").To4(),
},
},
},
inputBuf: []byte{0x20, 0x5, 0x0, 0xd, 0x0, 0x0, 0x1, 0x0, 0x0, 0x3c, 0x0, 0x5, 0x0, 0xc0, 0xbc, 0x2, 0x2},
},
{
name: "Session Establishment Request",
expectedMessage: pfcp.Message{
Header: pfcp.Header{
Version: 1,
MP: 0,
S: 1,
MessageType: pfcp.PFCP_SESSION_ESTABLISHMENT_REQUEST,
MessageLength: 44,
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},
},
},
},
},
inputBuf: []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) {
var msg pfcp.Message
err := msg.Unmarshal(tc.inputBuf)
require.Nilf(t, err, "decode %s failed", tc.name)
require.Equal(t, tc.expectedMessage, msg)
})
}
}