forked from usnistgov/ndn-dpdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassthru.go
59 lines (49 loc) · 1.53 KB
/
passthru.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
package ethface
import (
"errors"
"github.com/usnistgov/ndn-dpdk/core/macaddr"
"github.com/usnistgov/ndn-dpdk/iface"
"github.com/usnistgov/ndn-dpdk/iface/ethport"
"github.com/usnistgov/ndn-dpdk/ndn/packettransport"
)
// PassthruLocator describes a pass-through face.
type PassthruLocator struct {
ethport.FaceConfig
// Local is the local MAC address.
// This must be a 48-bit unicast address.
Local macaddr.Flag `json:"local,omitempty"`
}
// Scheme returns "passthru".
func (PassthruLocator) Scheme() string {
return ethport.SchemePassthru
}
// Validate checks Locator fields.
func (loc PassthruLocator) Validate() error {
if !loc.Local.Empty() && !macaddr.IsUnicast(loc.Local.HardwareAddr) {
return packettransport.ErrUnicastMacAddr
}
if loc.Local.Empty() && loc.Port == "" && loc.EthDev == nil {
return errors.New("either local or port must be specified")
}
return nil
}
// EthLocatorC implements ethport.Locator interface.
func (loc PassthruLocator) EthLocatorC() (c ethport.LocatorC) {
c.Remote.Bytes = [6]byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} // C.EthLocator_Classify
return
}
// CreateFace creates a pass-through face.
func (loc PassthruLocator) CreateFace() (face iface.Face, e error) {
port, e := loc.FaceConfig.FindPort(loc.Local.HardwareAddr)
if e != nil {
return nil, e
}
if loc.Local.Empty() {
loc.Local.HardwareAddr = port.EthDev().HardwareAddr()
}
loc.FaceConfig.HideFaceConfigFromJSON()
return ethport.NewFace(port, loc)
}
func init() {
iface.RegisterLocatorScheme[PassthruLocator](ethport.SchemePassthru)
}