forked from usnistgov/ndn-dpdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemif.go
66 lines (53 loc) · 1.34 KB
/
memif.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
// Package memifface implements memif faces.
package memifface
import (
"fmt"
"github.com/usnistgov/ndn-dpdk/dpdk/ethdev"
"github.com/usnistgov/ndn-dpdk/iface"
"github.com/usnistgov/ndn-dpdk/iface/ethport"
"github.com/usnistgov/ndn-dpdk/ndn/memiftransport"
)
const schemeMemif = "memif"
// Locator describes a memif face.
type Locator struct {
memiftransport.Locator
}
var _ ethport.Locator = Locator{}
// Scheme returns "memif".
func (Locator) Scheme() string {
return schemeMemif
}
// EthLocatorC implements ethport.Locator interface.
func (loc Locator) EthLocatorC() (c ethport.LocatorC) {
return
}
// EthFaceConfig implements ethport.Locator interface.
func (loc Locator) EthFaceConfig() (cfg ethport.FaceConfig) {
return ethport.FaceConfig{
DisableTxMultiSegOffload: true,
}
}
// CreateFace creates a memif face.
func (loc Locator) CreateFace() (iface.Face, error) {
if e := loc.Locator.Validate(); e != nil {
return nil, e
}
loc.Locator.ApplyDefaults(memiftransport.RoleServer)
dev, e := ethdev.NewMemif(loc.Locator)
if e != nil {
return nil, e
}
port, e := ethport.New(ethport.Config{
EthDev: dev,
MTU: loc.Dataroom,
AutoClose: true,
})
if e != nil {
dev.Close()
return nil, fmt.Errorf("NewPort %w", e)
}
return ethport.NewFace(port, loc)
}
func init() {
iface.RegisterLocatorScheme[Locator](schemeMemif)
}