-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathattr_qer.go
167 lines (153 loc) · 2.98 KB
/
attr_qer.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
156
157
158
159
160
161
162
163
164
165
166
167
package gtp5gnl
import (
"github.com/khirono/go-nl"
)
const (
QER_ID = iota + 3
QER_GATE
QER_MBR
QER_GBR
QER_CORR_ID
QER_RQI
QER_QFI
QER_PPI
QER_RCSR // deplicated
QER_RELATED_TO_PDR
QER_SEID
)
type QER struct {
ID uint32
Gate uint8
MBR MBR
GBR GBR
CorrID uint32
RQI uint8
QFI uint8
PPI uint8
PDRIDs []uint16
SEID *uint64
}
func DecodeQER(b []byte) (*QER, error) {
qer := new(QER)
for len(b) > 0 {
hdr, n, err := nl.DecodeAttrHdr(b)
if err != nil {
return nil, err
}
attrLen := int(hdr.Len)
switch hdr.MaskedType() {
case QER_ID:
qer.ID = native.Uint32(b[n:attrLen])
case QER_GATE:
qer.Gate = b[n]
case QER_MBR:
mbr, err := DecodeMBR(b[n:attrLen])
if err != nil {
return nil, err
}
qer.MBR = mbr
case QER_GBR:
gbr, err := DecodeGBR(b[n:attrLen])
if err != nil {
return nil, err
}
qer.GBR = gbr
case QER_CORR_ID:
qer.CorrID = native.Uint32(b[n:attrLen])
case QER_RQI:
qer.RQI = b[n]
case QER_QFI:
qer.QFI = b[n]
case QER_PPI:
qer.PPI = b[n]
case QER_RELATED_TO_PDR:
d := b[n:attrLen]
for len(d) > 0 {
v := native.Uint16(d)
qer.PDRIDs = append(qer.PDRIDs, v)
d = d[2:]
}
case QER_SEID:
v := native.Uint64(b[n:attrLen])
qer.SEID = &v
}
b = b[hdr.Len.Align():]
}
return qer, nil
}
const (
QER_MBR_UL_HIGH32 = iota + 1
QER_MBR_UL_LOW8
QER_MBR_DL_HIGH32
QER_MBR_DL_LOW8
)
type MBR struct {
ULHigh uint32
ULLow uint8
UL_Kbps uint64 // for viewer-friendly
DLHigh uint32
DLLow uint8
DL_Kbps uint64 // for viewer-friendly
}
func DecodeMBR(b []byte) (MBR, error) {
var mbr MBR
for len(b) > 0 {
hdr, n, err := nl.DecodeAttrHdr(b)
if err != nil {
return mbr, err
}
attrLen := int(hdr.Len)
switch hdr.MaskedType() {
case QER_MBR_UL_HIGH32:
mbr.ULHigh = native.Uint32(b[n:attrLen])
case QER_MBR_UL_LOW8:
mbr.ULLow = b[n]
case QER_MBR_DL_HIGH32:
mbr.DLHigh = native.Uint32(b[n:attrLen])
case QER_MBR_DL_LOW8:
mbr.DLLow = b[n]
}
b = b[hdr.Len.Align():]
}
mbr.UL_Kbps = uint64(mbr.ULHigh)<<8 + uint64(mbr.ULLow)
mbr.DL_Kbps = uint64(mbr.DLHigh)<<8 + uint64(mbr.DLLow)
return mbr, nil
}
const (
QER_GBR_UL_HIGH32 = iota + 1
QER_GBR_UL_LOW8
QER_GBR_DL_HIGH32
QER_GBR_DL_LOW8
)
type GBR struct {
ULHigh uint32
ULLow uint8
UL_Kbps uint64 // for viewer-friendly
DLHigh uint32
DLLow uint8
DL_Kbps uint64 // for viewer-friendly
}
func DecodeGBR(b []byte) (GBR, error) {
var gbr GBR
for len(b) > 0 {
hdr, n, err := nl.DecodeAttrHdr(b)
if err != nil {
return gbr, err
}
attrLen := int(hdr.Len)
switch hdr.MaskedType() {
case QER_GBR_UL_HIGH32:
gbr.ULHigh = native.Uint32(b[n:attrLen])
case QER_GBR_UL_LOW8:
gbr.ULLow = b[n]
case QER_GBR_DL_HIGH32:
gbr.DLHigh = native.Uint32(b[n:attrLen])
case QER_GBR_DL_LOW8:
gbr.DLLow = b[n]
}
b = b[hdr.Len.Align():]
}
gbr.UL_Kbps = uint64(gbr.ULHigh)<<8 + uint64(gbr.ULLow)
gbr.DL_Kbps = uint64(gbr.DLHigh)<<8 + uint64(gbr.DLLow)
return gbr, nil
}