/
sessions.go
68 lines (55 loc) · 1.34 KB
/
sessions.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
// SPDX-License-Identifier: Apache-2.0
// Copyright(c) 2020 Intel Corporation
package main
import (
"sync"
"github.com/omec-project/upf-epc/pfcpiface/metrics"
)
type notifyFlag struct {
flag bool
mux sync.Mutex
}
// PFCPSession implements one PFCP session.
type PFCPSession struct {
localSEID uint64
remoteSEID uint64
notificationFlag notifyFlag
pdrs []pdr
fars []far
qers []qer
metrics *metrics.Session
}
// NewPFCPSession allocates an session with ID.
func (pConn *PFCPConn) NewPFCPSession(rseid uint64) uint64 {
for i := 0; i < pConn.maxRetries; i++ {
lseid := pConn.rng.Uint64()
// Check if it already exists
if _, ok := pConn.sessions[lseid]; ok {
continue
}
s := PFCPSession{
localSEID: lseid,
remoteSEID: rseid,
pdrs: make([]pdr, 0, MaxItems),
fars: make([]far, 0, MaxItems),
qers: make([]qer, 0, MaxItems),
}
pConn.sessions[lseid] = &s
// Metrics update
s.metrics = metrics.NewSession(pConn.nodeID.remote)
pConn.SaveSessions(s.metrics)
return lseid
}
return 0
}
// RemoveSession removes session using lseid.
func (pConn *PFCPConn) RemoveSession(lseid uint64) {
s, ok := pConn.sessions[lseid]
if !ok {
return
}
// Metrics update
s.metrics.Delete()
pConn.SaveSessions(s.metrics)
delete(pConn.sessions, lseid)
}