-
Notifications
You must be signed in to change notification settings - Fork 29
/
decode.go
155 lines (151 loc) · 4.45 KB
/
decode.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package pfcp
import (
"fmt"
"github.com/free5gc/tlv"
)
func (m *Message) Unmarshal(data []byte) error {
if err := m.Header.UnmarshalBinary(data); err != nil {
return fmt.Errorf("pfcp: unmarshal msg failed: %s", err)
}
// Check Message Length field in header
if int(m.Header.MessageLength) != len(data)-4 {
return fmt.Errorf("Incorrect Message Length: Expected %d, got %d", m.Header.MessageLength, len(data)-4)
}
switch m.Header.MessageType {
case PFCP_HEARTBEAT_REQUEST:
Body := HeartbeatRequest{}
if err := tlv.Unmarshal(data[m.Header.Len():], &Body); err != nil {
return err
}
m.Body = Body
case PFCP_HEARTBEAT_RESPONSE:
Body := HeartbeatResponse{}
if err := tlv.Unmarshal(data[m.Header.Len():], &Body); err != nil {
return err
}
m.Body = Body
case PFCP_PFD_MANAGEMENT_REQUEST:
Body := PFCPPFDManagementRequest{}
if err := tlv.Unmarshal(data[m.Header.Len():], &Body); err != nil {
return err
}
m.Body = Body
case PFCP_PFD_MANAGEMENT_RESPONSE:
Body := PFCPPFDManagementResponse{}
if err := tlv.Unmarshal(data[m.Header.Len():], &Body); err != nil {
return err
}
m.Body = Body
case PFCP_ASSOCIATION_SETUP_REQUEST:
Body := PFCPAssociationSetupRequest{}
if err := tlv.Unmarshal(data[m.Header.Len():], &Body); err != nil {
return err
}
m.Body = Body
case PFCP_ASSOCIATION_SETUP_RESPONSE:
Body := PFCPAssociationSetupResponse{}
if err := tlv.Unmarshal(data[m.Header.Len():], &Body); err != nil {
return err
}
m.Body = Body
case PFCP_ASSOCIATION_UPDATE_REQUEST:
Body := PFCPAssociationUpdateRequest{}
if err := tlv.Unmarshal(data[m.Header.Len():], &Body); err != nil {
return err
}
m.Body = Body
case PFCP_ASSOCIATION_UPDATE_RESPONSE:
Body := PFCPAssociationUpdateResponse{}
if err := tlv.Unmarshal(data[m.Header.Len():], &Body); err != nil {
return err
}
m.Body = Body
case PFCP_ASSOCIATION_RELEASE_REQUEST:
Body := PFCPAssociationReleaseRequest{}
if err := tlv.Unmarshal(data[m.Header.Len():], &Body); err != nil {
return err
}
m.Body = Body
case PFCP_ASSOCIATION_RELEASE_RESPONSE:
Body := PFCPAssociationReleaseResponse{}
if err := tlv.Unmarshal(data[m.Header.Len():], &Body); err != nil {
return err
}
m.Body = Body
case PFCP_NODE_REPORT_REQUEST:
Body := PFCPNodeReportRequest{}
if err := tlv.Unmarshal(data[m.Header.Len():], &Body); err != nil {
return err
}
m.Body = Body
case PFCP_NODE_REPORT_RESPONSE:
Body := PFCPNodeReportResponse{}
if err := tlv.Unmarshal(data[m.Header.Len():], &Body); err != nil {
return err
}
m.Body = Body
case PFCP_SESSION_SET_DELETION_REQUEST:
Body := PFCPSessionSetDeletionRequest{}
if err := tlv.Unmarshal(data[m.Header.Len():], &Body); err != nil {
return err
}
m.Body = Body
case PFCP_SESSION_SET_DELETION_RESPONSE:
Body := PFCPSessionSetDeletionResponse{}
if err := tlv.Unmarshal(data[m.Header.Len():], &Body); err != nil {
return err
}
m.Body = Body
case PFCP_SESSION_ESTABLISHMENT_REQUEST:
Body := PFCPSessionEstablishmentRequest{}
if err := tlv.Unmarshal(data[m.Header.Len():], &Body); err != nil {
return err
}
m.Body = Body
case PFCP_SESSION_ESTABLISHMENT_RESPONSE:
Body := PFCPSessionEstablishmentResponse{}
if err := tlv.Unmarshal(data[m.Header.Len():], &Body); err != nil {
return err
}
m.Body = Body
case PFCP_SESSION_MODIFICATION_REQUEST:
Body := PFCPSessionModificationRequest{}
if err := tlv.Unmarshal(data[m.Header.Len():], &Body); err != nil {
return err
}
m.Body = Body
case PFCP_SESSION_MODIFICATION_RESPONSE:
Body := PFCPSessionModificationResponse{}
if err := tlv.Unmarshal(data[m.Header.Len():], &Body); err != nil {
return err
}
m.Body = Body
case PFCP_SESSION_DELETION_REQUEST:
Body := PFCPSessionDeletionRequest{}
if err := tlv.Unmarshal(data[m.Header.Len():], &Body); err != nil {
return err
}
m.Body = Body
case PFCP_SESSION_DELETION_RESPONSE:
Body := PFCPSessionDeletionResponse{}
if err := tlv.Unmarshal(data[m.Header.Len():], &Body); err != nil {
return err
}
m.Body = Body
case PFCP_SESSION_REPORT_REQUEST:
Body := PFCPSessionReportRequest{}
if err := tlv.Unmarshal(data[m.Header.Len():], &Body); err != nil {
return err
}
m.Body = Body
case PFCP_SESSION_REPORT_RESPONSE:
Body := PFCPSessionReportResponse{}
if err := tlv.Unmarshal(data[m.Header.Len():], &Body); err != nil {
return err
}
m.Body = Body
default:
return fmt.Errorf("pfcp: unmarshal msg type %d not supported", m.Header.MessageType)
}
return nil
}