This repository has been archived by the owner on Apr 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
common_function.go
99 lines (88 loc) · 2.24 KB
/
common_function.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
package amf_context
import (
"encoding/binary"
"github.com/mohae/deepcopy"
"free5gc/lib/openapi/models"
"free5gc/src/amf/logger"
"reflect"
)
func CompareUserLocation(loc1 models.UserLocation, loc2 models.UserLocation) bool {
if loc1.EutraLocation != nil && loc2.EutraLocation != nil {
eutraloc1 := deepcopy.Copy(*loc1.EutraLocation).(models.EutraLocation)
eutraloc2 := deepcopy.Copy(*loc2.EutraLocation).(models.EutraLocation)
eutraloc1.UeLocationTimestamp = nil
eutraloc2.UeLocationTimestamp = nil
return reflect.DeepEqual(eutraloc1, eutraloc2)
}
if loc1.N3gaLocation != nil && loc2.N3gaLocation != nil {
return reflect.DeepEqual(loc1, loc2)
}
if loc1.NrLocation != nil && loc2.NrLocation != nil {
nrloc1 := deepcopy.Copy(*loc1.NrLocation).(models.NrLocation)
nrloc2 := deepcopy.Copy(*loc2.NrLocation).(models.NrLocation)
nrloc1.UeLocationTimestamp = nil
nrloc2.UeLocationTimestamp = nil
return reflect.DeepEqual(nrloc1, nrloc2)
}
return false
}
func InTaiList(servedTai models.Tai, taiList []models.Tai) bool {
for _, tai := range taiList {
if reflect.DeepEqual(tai, servedTai) {
return true
}
}
return false
}
func TacInAreas(targetTac string, areas []models.Area) bool {
for _, area := range areas {
for _, tac := range area.Tacs {
if targetTac == tac {
return true
}
}
}
return false
}
func GetSecurityCount(overflow uint16, sqn uint8) []uint8 {
var r = make([]byte, 4)
binary.BigEndian.PutUint16(r, overflow)
r[3] = sqn
r[2] = r[1]
r[1] = r[0]
r[0] = 0x00
return r
}
func AttachSourceUeTargetUe(sourceUe, targetUe *RanUe) {
if sourceUe == nil {
logger.ContextLog.Error("Source Ue is Nil")
return
}
if targetUe == nil {
logger.ContextLog.Error("Target Ue is Nil")
return
}
amfUe := sourceUe.AmfUe
if amfUe == nil {
logger.ContextLog.Error("AmfUe is Nil")
return
}
targetUe.AmfUe = amfUe
targetUe.SourceUe = sourceUe
sourceUe.TargetUe = targetUe
}
func DetachSourceUeTargetUe(ranUe *RanUe) {
if ranUe == nil {
logger.ContextLog.Error("ranUe is Nil")
return
}
if ranUe.TargetUe != nil {
targetUe := ranUe.TargetUe
ranUe.TargetUe = nil
targetUe.SourceUe = nil
} else if ranUe.SourceUe != nil {
source := ranUe.SourceUe
ranUe.SourceUe = nil
source.TargetUe = nil
}
}