forked from usnistgov/ndn-dpdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathether.go
46 lines (37 loc) · 1.1 KB
/
ether.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
// Package ethface implements Ethernet-based faces.
package ethface
import (
"github.com/usnistgov/ndn-dpdk/iface"
"github.com/usnistgov/ndn-dpdk/iface/ethport"
"github.com/usnistgov/ndn-dpdk/ndn/packettransport"
)
const schemeEther = "ether"
// EtherLocator describes an Ethernet face.
type EtherLocator struct {
ethport.FaceConfig
// packettransport.Locator contains MAC addresses.
packettransport.Locator
}
// Scheme returns "ether".
func (EtherLocator) Scheme() string {
return schemeEther
}
// EthLocatorC implements ethport.Locator interface.
func (loc EtherLocator) EthLocatorC() (c ethport.LocatorC) {
copy(c.Local.Bytes[:], []uint8(loc.Local.HardwareAddr))
copy(c.Remote.Bytes[:], []uint8(loc.Remote.HardwareAddr))
c.Vlan = uint16(loc.VLAN)
return
}
// CreateFace creates an Ethernet face.
func (loc EtherLocator) 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[EtherLocator](schemeEther)
}