forked from wmnsk/go-pfcp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent-threshold.go
62 lines (57 loc) · 1.32 KB
/
event-threshold.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
// Copyright 2019-2020 go-pfcp authors. All rights reserved.
// Use of this source code is governed by a MIT-style license that can be
// found in the LICENSE file.
package ie
import (
"encoding/binary"
"io"
)
// NewEventThreshold creates a new EventThreshold IE.
func NewEventThreshold(quota uint32) *IE {
return newUint32ValIE(EventThreshold, quota)
}
// EventThreshold returns EventThreshold in uint32 if the type of IE matches.
func (i *IE) EventThreshold() (uint32, error) {
if len(i.Payload) < 4 {
return 0, io.ErrUnexpectedEOF
}
switch i.Type {
case EventThreshold:
return binary.BigEndian.Uint32(i.Payload[0:4]), nil
case CreateURR:
ies, err := i.CreateURR()
if err != nil {
return 0, err
}
for _, x := range ies {
if x.Type == EventThreshold {
return x.EventThreshold()
}
}
return 0, ErrIENotFound
case UpdateURR:
ies, err := i.UpdateURR()
if err != nil {
return 0, err
}
for _, x := range ies {
if x.Type == EventThreshold {
return x.EventThreshold()
}
}
return 0, ErrIENotFound
case AdditionalMonitoringTime:
ies, err := i.AdditionalMonitoringTime()
if err != nil {
return 0, err
}
for _, x := range ies {
if x.Type == EventThreshold {
return x.EventThreshold()
}
}
return 0, ErrIENotFound
default:
return 0, &InvalidTypeError{Type: i.Type}
}
}