forked from usnistgov/ndn-dpdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgtp.go
103 lines (84 loc) · 2.49 KB
/
gtp.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
package ethface
import (
"errors"
"math"
"net/netip"
"github.com/usnistgov/ndn-dpdk/iface"
"github.com/usnistgov/ndn-dpdk/iface/ethport"
)
// Error conditions.
var (
ErrTEID = errors.New("invalid Tunnel Endpoint Identifier")
ErrQFI = errors.New("invalid QoS Flow Identifier")
)
const schemeGtp = "gtp"
// GtpLocator describes a GTP-U face.
type GtpLocator struct {
IPLocator
// UlTEID is the uplink/incoming tunnel endpoint identifier.
// This must fit in 32 bits.
UlTEID int `json:"ulTEID"`
// UlQFI is the uplink/incoming QoS flow identifier.
// This must fit in 6 bits.
UlQFI int `json:"ulQFI"`
// DlTEID is the downlink/outgoing tunnel endpoint identifier.
// This must fit in 32 bits.
DlTEID int `json:"dlTEID"`
// DlQFI is the downlink/outgoing QoS flow identifier.
// This must fit in 6 bits.
DlQFI int `json:"dlQFI"`
// InnerLocalIP is the inner local IPv4 address.
InnerLocalIP netip.Addr `json:"innerLocalIP"`
// InnerRemoteIP is the inner remote IPv4 address.
InnerRemoteIP netip.Addr `json:"innerRemoteIP"`
}
// Scheme returns "gtp".
func (GtpLocator) Scheme() string {
return schemeGtp
}
// Validate checks Locator fields.
func (loc GtpLocator) Validate() error {
if e := loc.IPLocator.Validate(); e != nil {
return e
}
local, remote := loc.InnerLocalIP.Unmap(), loc.InnerRemoteIP.Unmap()
switch {
case loc.UlTEID < 0, loc.UlTEID > math.MaxUint32:
return ErrTEID
case loc.UlQFI < 0, loc.UlQFI > 0b111111:
return ErrQFI
case loc.DlTEID < 0, loc.DlTEID > math.MaxUint32:
return ErrTEID
case loc.DlQFI < 0, loc.DlQFI > 0b111111:
return ErrQFI
case !local.Is4(), local.IsMulticast(), !remote.Is4(), remote.IsMulticast():
return ErrUnicastIP
}
return nil
}
// EthLocatorC implements ethport.Locator interface.
func (loc GtpLocator) EthLocatorC() (locC ethport.LocatorC) {
locC = loc.IPLocator.ipLocatorC()
locC.LocalUDP = ethport.UDPPortGTP
locC.RemoteUDP = ethport.UDPPortGTP
locC.IsGtp = true
locC.UlTEID = uint32(loc.UlTEID)
locC.UlQFI = uint8(loc.UlQFI)
locC.DlTEID = uint32(loc.DlTEID)
locC.DlQFI = uint8(loc.DlQFI)
locC.InnerLocalIP = loc.InnerLocalIP.As16()
locC.InnerRemoteIP = loc.InnerRemoteIP.As16()
return
}
// CreateFace creates a GTP-U face.
func (loc GtpLocator) CreateFace() (face iface.Face, e error) {
port, e := loc.FaceConfig.FindPort(loc.Local.HardwareAddr)
if e != nil {
return nil, e
}
loc.FaceConfig.HideFaceConfigFromJSON()
return ethport.NewFace(port, loc)
}
func init() {
iface.RegisterLocatorScheme[GtpLocator](schemeGtp)
}