Skip to content

Commit

Permalink
feat: Store interface internal name & dev type as metadata (#1706)
Browse files Browse the repository at this point in the history
Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
  • Loading branch information
ondrej-fabry committed Aug 25, 2020
1 parent 72644e2 commit fd6a064
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 19 deletions.
2 changes: 2 additions & 0 deletions plugins/vpp/ifplugin/descriptor/interface_crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,8 @@ func (d *InterfaceDescriptor) Retrieve(correlate []adapter.InterfaceKVWithMetada
Vrf: intf.Interface.Vrf,
IPAddresses: intf.Interface.IpAddresses,
TAPHostIfName: tapHostIfName,
InternalName: intf.Meta.InternalName,
DevType: intf.Meta.DevType,
}
retrieved = append(retrieved, adapter.InterfaceKVWithMetadata{
Key: models.Key(intf.Interface),
Expand Down
2 changes: 2 additions & 0 deletions plugins/vpp/ifplugin/ifaceidx/ifaceidx.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ type IfaceMetadata struct {
Vrf uint32
IPAddresses []string // TODO: update from interfaceAddress descriptor with real IPs (not netalloc links)
TAPHostIfName string /* host interface name set for the Linux-side of the TAP interface; empty for non-TAPs */
InternalName string // internal VPP name
DevType string // device type
}

// GetIndex returns sw_if_index assigned to the interface.
Expand Down
4 changes: 4 additions & 0 deletions plugins/vpp/ifplugin/vppcalls/interface_handler_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type InterfaceMeta struct {
SupSwIfIndex uint32 `json:"sub_sw_if_index"`
L2Address net.HardwareAddr `json:"l2_address"`
InternalName string `json:"internal_name"`
DevType string `json:"dev_type"`
IsAdminStateUp bool `json:"is_admin_state_up"`
IsLinkStateUp bool `json:"is_link_state_up"`
LinkDuplex uint32 `json:"link_duplex"`
Expand All @@ -50,11 +51,14 @@ type InterfaceMeta struct {
LinkSpeed uint32 `json:"link_speed"`
SubID uint32 `json:"sub_id"`
Tag string `json:"tag"`

// dhcp
Dhcp *Dhcp `json:"dhcp"`

// vrf
VrfIPv4 uint32 `json:"vrf_ipv4"`
VrfIPv6 uint32 `json:"vrf_ipv6"`

// wmxnet3
Pci uint32 `json:"pci"`
}
Expand Down
12 changes: 6 additions & 6 deletions plugins/vpp/ifplugin/vppcalls/vpp1908/dump_interface_vppcalls.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ func (h *InterfaceVppHandler) dumpInterfaces(ifIdxs ...uint32) (map[uint32]*vppc
return nil, fmt.Errorf("failed to dump interface: %v", err)
}

ifaceName := strings.TrimRight(ifDetails.InterfaceName, "\x00")
internalName := strings.TrimRight(ifDetails.InterfaceName, "\x00")
l2addr := net.HardwareAddr(ifDetails.L2Address[:ifDetails.L2AddressLength])

details := &vppcalls.InterfaceDetails{
Interface: &interfaces.Interface{
Name: strings.TrimRight(ifDetails.Tag, "\x00"),
// the type may be amended later by further dumps
Type: guessInterfaceType(ifaceName),
Type: guessInterfaceType(internalName),
Enabled: ifDetails.AdminUpDown > 0,
PhysAddress: net.HardwareAddr(ifDetails.L2Address[:ifDetails.L2AddressLength]).String(),
Mtu: getMtu(ifDetails.LinkMtu),
Expand All @@ -111,7 +111,7 @@ func (h *InterfaceVppHandler) dumpInterfaces(ifIdxs ...uint32) (map[uint32]*vppc
SwIfIndex: ifDetails.SwIfIndex,
SupSwIfIndex: ifDetails.SupSwIfIndex,
L2Address: l2addr,
InternalName: ifaceName,
InternalName: internalName,
IsAdminStateUp: uintToBool(ifDetails.AdminUpDown),
IsLinkStateUp: uintToBool(ifDetails.LinkUpDown),
LinkDuplex: uint32(ifDetails.LinkDuplex),
Expand Down Expand Up @@ -140,18 +140,18 @@ func (h *InterfaceVppHandler) dumpInterfaces(ifIdxs ...uint32) (map[uint32]*vppc
// Fill name for physical interfaces (they are mostly without tag)
switch details.Interface.Type {
case interfaces.Interface_DPDK:
details.Interface.Name = ifaceName
details.Interface.Name = internalName
case interfaces.Interface_AF_PACKET:
details.Interface.Link = &interfaces.Interface_Afpacket{
Afpacket: &interfaces.AfpacketLink{
HostIfName: strings.TrimPrefix(ifaceName, "host-"),
HostIfName: strings.TrimPrefix(internalName, "host-"),
},
}
}
if details.Interface.Name == "" {
// untagged interface - generate a logical name for it
// (apart from local0 it will get removed by resync)
details.Interface.Name = untaggedIfPreffix + ifaceName
details.Interface.Name = untaggedIfPreffix + internalName
}
ifs[ifDetails.SwIfIndex] = details
}
Expand Down
14 changes: 8 additions & 6 deletions plugins/vpp/ifplugin/vppcalls/vpp2001/dump_interface_vppcalls.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,16 @@ func (h *InterfaceVppHandler) dumpInterfaces(ifIdxs ...uint32) (map[uint32]*vppc
return nil, fmt.Errorf("failed to dump interface: %v", err)
}

ifaceName := strings.TrimRight(ifDetails.InterfaceName, "\x00")
internalName := strings.TrimRight(ifDetails.InterfaceName, "\x00")
ifaceDevType := strings.TrimRight(ifDetails.InterfaceDevType, "\x00")
physAddr := make(net.HardwareAddr, macLength)
copy(physAddr, ifDetails.L2Address[:])

details := &vppcalls.InterfaceDetails{
Interface: &ifs.Interface{
Name: strings.TrimRight(ifDetails.Tag, "\x00"),
// the type may be amended later by further dumps
Type: guessInterfaceType(ifaceName),
Type: guessInterfaceType(internalName),
Enabled: isAdminStateUp(ifDetails.Flags),
PhysAddress: net.HardwareAddr(ifDetails.L2Address[:]).String(),
Mtu: getMtu(ifDetails.LinkMtu),
Expand All @@ -120,7 +121,8 @@ func (h *InterfaceVppHandler) dumpInterfaces(ifIdxs ...uint32) (map[uint32]*vppc
SwIfIndex: uint32(ifDetails.SwIfIndex),
SupSwIfIndex: ifDetails.SupSwIfIndex,
L2Address: physAddr,
InternalName: ifaceName,
InternalName: internalName,
DevType: ifaceDevType,
IsAdminStateUp: isAdminStateUp(ifDetails.Flags),
IsLinkStateUp: isLinkStateUp(ifDetails.Flags),
LinkDuplex: uint32(ifDetails.LinkDuplex),
Expand Down Expand Up @@ -149,18 +151,18 @@ func (h *InterfaceVppHandler) dumpInterfaces(ifIdxs ...uint32) (map[uint32]*vppc
// Fill name for physical interfaces (they are mostly without tag)
switch details.Interface.Type {
case ifs.Interface_DPDK:
details.Interface.Name = ifaceName
details.Interface.Name = internalName
case ifs.Interface_AF_PACKET:
details.Interface.Link = &ifs.Interface_Afpacket{
Afpacket: &ifs.AfpacketLink{
HostIfName: strings.TrimPrefix(ifaceName, "host-"),
HostIfName: strings.TrimPrefix(internalName, "host-"),
},
}
}
if details.Interface.Name == "" {
// untagged interface - generate a logical name for it
// (apart from local0 it will get removed by resync)
details.Interface.Name = untaggedIfPreffix + ifaceName
details.Interface.Name = untaggedIfPreffix + internalName
}
interfaces[uint32(ifDetails.SwIfIndex)] = details
}
Expand Down
16 changes: 9 additions & 7 deletions plugins/vpp/ifplugin/vppcalls/vpp2005/dump_interface_vppcalls.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,16 @@ func (h *InterfaceVppHandler) dumpInterfaces(ifIdxs ...uint32) (map[uint32]*vppc
return nil, fmt.Errorf("failed to dump interface: %v", err)
}

ifaceName := strings.TrimRight(ifDetails.InterfaceName, "\x00")
internalName := strings.TrimRight(ifDetails.InterfaceName, "\x00")
ifaceDevType := strings.TrimRight(ifDetails.InterfaceDevType, "\x00")
physAddr := make(net.HardwareAddr, macLength)
copy(physAddr, ifDetails.L2Address[:])

details := &vppcalls.InterfaceDetails{
Interface: &ifs.Interface{
Name: strings.TrimRight(ifDetails.Tag, "\x00"),
// the type may be amended later by further dumps
Type: guessInterfaceType(ifaceName),
Type: guessInterfaceType(ifaceDevType, internalName),
Enabled: isAdminStateUp(ifDetails.Flags),
PhysAddress: net.HardwareAddr(ifDetails.L2Address[:]).String(),
Mtu: getMtu(ifDetails.LinkMtu),
Expand All @@ -120,7 +121,8 @@ func (h *InterfaceVppHandler) dumpInterfaces(ifIdxs ...uint32) (map[uint32]*vppc
SwIfIndex: uint32(ifDetails.SwIfIndex),
SupSwIfIndex: ifDetails.SupSwIfIndex,
L2Address: physAddr,
InternalName: ifaceName,
InternalName: internalName,
DevType: ifaceDevType,
IsAdminStateUp: isAdminStateUp(ifDetails.Flags),
IsLinkStateUp: isLinkStateUp(ifDetails.Flags),
LinkDuplex: uint32(ifDetails.LinkDuplex),
Expand Down Expand Up @@ -149,18 +151,18 @@ func (h *InterfaceVppHandler) dumpInterfaces(ifIdxs ...uint32) (map[uint32]*vppc
// Fill name for physical interfaces (they are mostly without tag)
switch details.Interface.Type {
case ifs.Interface_DPDK:
details.Interface.Name = ifaceName
details.Interface.Name = internalName
case ifs.Interface_AF_PACKET:
details.Interface.Link = &ifs.Interface_Afpacket{
Afpacket: &ifs.AfpacketLink{
HostIfName: strings.TrimPrefix(ifaceName, "host-"),
HostIfName: strings.TrimPrefix(internalName, "host-"),
},
}
}
if details.Interface.Name == "" {
// untagged interface - generate a logical name for it
// (apart from local0 it will get removed by resync)
details.Interface.Name = untaggedIfPreffix + ifaceName
details.Interface.Name = untaggedIfPreffix + internalName
}
interfaces[uint32(ifDetails.SwIfIndex)] = details
}
Expand Down Expand Up @@ -928,7 +930,7 @@ func dhcpAddressToString(address vpp_dhcp.Address, maskWidth uint32, isIPv6 bool
// guessInterfaceType attempts to guess the correct interface type from its internal name (as given by VPP).
// This is required mainly for those interface types, that do not provide dump binary API,
// such as loopback of af_packet.
func guessInterfaceType(ifName string) ifs.Interface_Type {
func guessInterfaceType(ifDevType, ifName string) ifs.Interface_Type {
switch {
case strings.HasPrefix(ifName, "loop"),
strings.HasPrefix(ifName, "local"):
Expand Down

0 comments on commit fd6a064

Please sign in to comment.