forked from usnistgov/ndn-dpdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
74 lines (61 loc) · 2.3 KB
/
config.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
package socketface
import (
"slices"
"github.com/usnistgov/ndn-dpdk/core/nnduration"
"github.com/usnistgov/ndn-dpdk/dpdk/eal"
"github.com/usnistgov/ndn-dpdk/dpdk/ringbuffer"
"github.com/usnistgov/ndn-dpdk/iface"
"github.com/usnistgov/ndn-dpdk/ndn/sockettransport"
)
// Config contains socket face configuration.
type Config struct {
iface.Config
// sockettransport.Config fields.
// See ndn-dpdk/ndn/sockettransport package for their semantics and defaults.
RedialBackoffInitial nnduration.Milliseconds `json:"redialBackoffInitial,omitempty"`
RedialBackoffMaximum nnduration.Milliseconds `json:"redialBackoffMaximum,omitempty"`
}
func (cfg Config) transportConfig() sockettransport.Config {
return sockettransport.Config{
MTU: cfg.MTU,
RedialBackoffInitial: cfg.RedialBackoffInitial.Duration(),
RedialBackoffMaximum: cfg.RedialBackoffMaximum.Duration(),
}
}
// GlobalConfig contains global options applied to all socket faces.
type GlobalConfig struct {
// Socket chooses a NUMA socket to create RX/TX threads for socket faces.
// Default is the first NUMA socket.
// If the specified NUMA socket does not exist, it uses the default.
Socket eal.NumaSocket `json:"socket"`
// RxConns configures net.Conn RX implementation.
RxConns struct {
// RingCapacity is the capacity of a ring buffer for packets that are received from net.Conn
// but have not been picked up by C code.
RingCapacity int `json:"ringCapacity"`
} `json:"rxConns"`
// RxEpoll configures epoll RX implementation, available for UDP sockets only.
// If this is disabled, UDP sockets will use net.Conn RX implementation.
RxEpoll struct {
Disabled bool `json:"disabled"`
} `json:"rxEpoll"`
// TxSyscall configures syscall TX implementation, available for UDP sockets only.
// If this is disabled, UDP sockets will use net.Conn TX implementation.
TxSyscall struct {
Disabled bool `json:"disabled"`
} `json:"txSyscall"`
}
func (cfg GlobalConfig) Apply() {
if !slices.Contains(eal.Sockets, cfg.Socket) {
cfg.Socket = eal.NumaSocket{}
}
cfg.RxConns.RingCapacity = ringbuffer.AlignCapacity(cfg.RxConns.RingCapacity, 64, 4096, 65536)
gCfg = cfg
}
func (cfg GlobalConfig) numaSocket() eal.NumaSocket {
return eal.RewriteAnyNumaSocketFirst.Rewrite(cfg.Socket)
}
var gCfg GlobalConfig
func init() {
GlobalConfig{}.Apply()
}