-
Notifications
You must be signed in to change notification settings - Fork 13
/
attr_urr.go
156 lines (143 loc) · 3.28 KB
/
attr_urr.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
package gtp5gnl
import (
"github.com/khirono/go-nl"
)
const (
URR_ID = iota + 3
URR_MEASUREMENT_METHOD
URR_REPORTING_TRIGGER
URR_MEASUREMENT_PERIOD
URR_MEASUREMENT_INFO
URR_SEID
URR_VOLUME_THRESHOLD
URR_VOLUME_QUOTA
URR_MULTI_SEID_URRID
URR_NUM
)
const (
URR_VOLUME_QUOTA_FLAG = iota + 1
URR_VOLUME_QUOTA_TOVOL
URR_VOLUME_QUOTA_UVOL
URR_VOLUME_QUOTA_DVOL
)
const (
URR_VOLUME_THRESHOLD_FLAG = iota + 1
URR_VOLUME_THRESHOLD_TOVOL
URR_VOLUME_THRESHOLD_UVOL
URR_VOLUME_THRESHOLD_DVOL
)
type VolumeThreshold struct {
flag uint8
totalVolume uint64
uplinkVolume uint64
downlinkVolume uint64
}
type VolumeQuota struct {
flag uint8
totalVolume uint64
uplinkVolume uint64
downlinkVolume uint64
}
type URR struct {
ID uint32
Method uint8
Trigger uint32
Period *uint32
Info *uint8
SEID *uint64
VolThreshold *VolumeThreshold
VolQuota *VolumeQuota
}
func DecodeURR(b []byte) (*URR, error) {
urr := new(URR)
for len(b) > 0 {
hdr, n, err := nl.DecodeAttrHdr(b)
if err != nil {
return nil, err
}
attrLen := int(hdr.Len)
switch hdr.MaskedType() {
case URR_ID:
urr.ID = native.Uint32(b[n:attrLen])
case URR_MEASUREMENT_METHOD:
urr.Method = uint8(b[n])
case URR_REPORTING_TRIGGER:
urr.Trigger = native.Uint32(b[n:attrLen])
case URR_MEASUREMENT_PERIOD:
v := native.Uint32(b[n:attrLen])
urr.Period = &v
case URR_MEASUREMENT_INFO:
v := uint8(b[n])
urr.Info = &v
case URR_SEID:
v := native.Uint64(b[n:attrLen])
urr.SEID = &v
case URR_VOLUME_THRESHOLD:
volthreshold, err := decodeVolumeThreshold(b[n:attrLen])
if err != nil {
return nil, err
}
urr.VolThreshold = &volthreshold
case URR_VOLUME_QUOTA:
volumequota, err := decodeVolumeQuota(b[n:attrLen])
if err != nil {
return nil, err
}
urr.VolQuota = &volumequota
}
b = b[hdr.Len.Align():]
}
return urr, nil
}
func decodeVolumeThreshold(b []byte) (VolumeThreshold, error) {
var volumethreshold VolumeThreshold
for len(b) > 0 {
hdr, n, err := nl.DecodeAttrHdr(b)
if err != nil {
return volumethreshold, err
}
attrLen := int(hdr.Len)
switch hdr.MaskedType() {
case URR_VOLUME_THRESHOLD_FLAG:
v := uint8(b[n])
volumethreshold.flag = v
case URR_VOLUME_THRESHOLD_TOVOL:
v := native.Uint64(b[n:attrLen])
volumethreshold.totalVolume = v
case URR_VOLUME_THRESHOLD_UVOL:
v := native.Uint64(b[n:attrLen])
volumethreshold.uplinkVolume = v
case URR_VOLUME_THRESHOLD_DVOL:
v := native.Uint64(b[n:attrLen])
volumethreshold.downlinkVolume = v
}
b = b[hdr.Len.Align():]
}
return volumethreshold, nil
}
func decodeVolumeQuota(b []byte) (VolumeQuota, error) {
var volumequota VolumeQuota
for len(b) > 0 {
hdr, n, err := nl.DecodeAttrHdr(b)
if err != nil {
return volumequota, err
}
attrLen := int(hdr.Len)
switch hdr.MaskedType() {
case URR_VOLUME_QUOTA_FLAG:
v := uint8(b[n])
volumequota.flag = v
case URR_VOLUME_QUOTA_TOVOL:
v := native.Uint64(b[n:attrLen])
volumequota.totalVolume = v
case URR_VOLUME_QUOTA_UVOL:
v := native.Uint64(b[n:attrLen])
volumequota.uplinkVolume = v
case URR_VOLUME_QUOTA_DVOL:
v := native.Uint64(b[n:attrLen])
volumequota.downlinkVolume = v
}
b = b[hdr.Len.Align():]
}
return volumequota, nil
}