forked from ardzoht/omec-upf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upf.go
178 lines (148 loc) · 3.66 KB
/
upf.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
168
169
170
171
172
173
174
175
176
177
178
// SPDX-License-Identifier: Apache-2.0
// Copyright 2020 Intel Corporation
package pfcpiface
import (
"net"
"time"
"github.com/Showmax/go-fqdn"
)
// QosConfigVal : Qos configured value.
type QosConfigVal struct {
cbs uint32
pbs uint32
ebs uint32
burstDurationMs uint32
schedulePriority uint32
}
type SliceInfo struct {
name string
uplinkMbr uint64
downlinkMbr uint64
ulBurstBytes uint64
dlBurstBytes uint64
ueResList []UeResource
}
type UeResource struct {
name string
dnn string
}
type Upf struct {
enableUeIPAlloc bool
enableEndMarker bool
enableFlowMeasure bool
accessIface string
coreIface string
ippoolCidr string
AccessIP net.IP
CoreIP net.IP
NodeID string
ippool *IPPool
peers []string
dnn string
ReportNotifyChan chan uint64
sliceInfo *SliceInfo
readTimeout time.Duration
Datapath
maxReqRetries uint8
respTimeout time.Duration
enableHBTimer bool
hbInterval time.Duration
}
// to be replaced with go-pfcp structs
// Don't change these values.
const (
tunnelGTPUPort = 2152
// src-iface consts.
core = 0x2
access = 0x1
// far-id specific directions.
n3 = 0x0
n6 = 0x1
n9 = 0x2
)
func (u *Upf) isConnected() bool {
return u.Datapath.IsConnected(&u.AccessIP)
}
func (u *Upf) addSliceInfo(sliceInfo *SliceInfo) error {
if sliceInfo == nil {
return ErrInvalidArgument("sliceInfo", sliceInfo)
}
u.sliceInfo = sliceInfo
return u.Datapath.AddSliceInfo(sliceInfo)
}
func NewUPF(conf *Conf, fp Datapath) *Upf {
var (
err error
nodeID string
)
nodeID = conf.CPIface.NodeID
if conf.CPIface.UseFQDN && nodeID == "" {
nodeID, err = fqdn.FqdnHostname()
if err != nil {
log.Fatal("Unable to get hostname", err)
}
}
// TODO: Delete this once CI config is fixed
if nodeID != "" {
hosts, err := net.LookupHost(nodeID)
if err != nil {
log.Fatalf("Unable to resolve hostname %v %v", nodeID, err)
}
nodeID = hosts[0]
}
u := &Upf{
enableUeIPAlloc: conf.CPIface.EnableUeIPAlloc,
enableEndMarker: conf.EnableEndMarker,
enableFlowMeasure: conf.EnableFlowMeasure,
accessIface: conf.AccessIface.IfName,
coreIface: conf.CoreIface.IfName,
ippoolCidr: conf.CPIface.UEIPPool,
NodeID: nodeID,
Datapath: fp,
dnn: conf.CPIface.Dnn,
peers: conf.CPIface.Peers,
ReportNotifyChan: make(chan uint64, 1024),
maxReqRetries: conf.MaxReqRetries,
enableHBTimer: conf.EnableHBTimer,
readTimeout: time.Second * time.Duration(conf.ReadTimeout),
}
if len(conf.CPIface.Peers) > 0 {
u.peers = make([]string, len(conf.CPIface.Peers))
nc := copy(u.peers, conf.CPIface.Peers)
if nc == 0 {
log.Warn("Failed to parse cpiface peers, PFCP Agent will not initiate connection to N4 peers.")
}
}
if !conf.EnableP4rt {
u.AccessIP, err = GetUnicastAddressFromInterface(conf.AccessIface.IfName)
if err != nil {
log.Error(err)
return nil
}
u.CoreIP, err = GetUnicastAddressFromInterface(conf.CoreIface.IfName)
if err != nil {
log.Error(err)
return nil
}
}
u.respTimeout, err = time.ParseDuration(conf.RespTimeout)
if err != nil {
log.Fatal("Unable to parse resp_timeout")
}
if u.enableHBTimer {
if conf.HeartBeatInterval != "" {
u.hbInterval, err = time.ParseDuration(conf.HeartBeatInterval)
if err != nil {
log.Fatal("Unable to parse heart_beat_interval")
}
}
}
if u.enableUeIPAlloc {
u.ippool, err = NewIPPool(u.ippoolCidr)
if err != nil {
log.Fatal("ip pool init failed", err)
}
}
u.Datapath.SetUpfInfo(u, conf)
return u
}