network: Rename VirtualEndpoint to VethEndpoint

As this really represents a veth pair rather than a generic
virtual interface, rename VirtualEndpoint to VethEndpoint.

Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
This commit is contained in:
Archana Shinde 2018-10-09 10:44:08 -07:00
parent df8f21d9fe
commit 3c590b0e2c
7 changed files with 50 additions and 50 deletions

View File

@ -32,8 +32,8 @@ const (
// PhysicalEndpointType is the physical network interface. // PhysicalEndpointType is the physical network interface.
PhysicalEndpointType EndpointType = "physical" PhysicalEndpointType EndpointType = "physical"
// VirtualEndpointType is the virtual network interface. // VethEndpointType is the virtual network interface.
VirtualEndpointType EndpointType = "virtual" VethEndpointType EndpointType = "virtual"
// VhostUserEndpointType is the vhostuser network interface. // VhostUserEndpointType is the vhostuser network interface.
VhostUserEndpointType EndpointType = "vhost-user" VhostUserEndpointType EndpointType = "vhost-user"
@ -52,7 +52,7 @@ func (endpointType *EndpointType) Set(value string) error {
*endpointType = PhysicalEndpointType *endpointType = PhysicalEndpointType
return nil return nil
case "virtual": case "virtual":
*endpointType = VirtualEndpointType *endpointType = VethEndpointType
return nil return nil
case "vhost-user": case "vhost-user":
*endpointType = VhostUserEndpointType *endpointType = VhostUserEndpointType
@ -73,8 +73,8 @@ func (endpointType *EndpointType) String() string {
switch *endpointType { switch *endpointType {
case PhysicalEndpointType: case PhysicalEndpointType:
return string(PhysicalEndpointType) return string(PhysicalEndpointType)
case VirtualEndpointType: case VethEndpointType:
return string(VirtualEndpointType) return string(VethEndpointType)
case VhostUserEndpointType: case VhostUserEndpointType:
return string(VhostUserEndpointType) return string(VhostUserEndpointType)
case BridgedMacvlanEndpointType: case BridgedMacvlanEndpointType:

View File

@ -25,8 +25,8 @@ func TestPhysicalEndpointTypeSet(t *testing.T) {
testEndpointTypeSet(t, "physical", PhysicalEndpointType) testEndpointTypeSet(t, "physical", PhysicalEndpointType)
} }
func TestVirtualEndpointTypeSet(t *testing.T) { func TestVethEndpointTypeSet(t *testing.T) {
testEndpointTypeSet(t, "virtual", VirtualEndpointType) testEndpointTypeSet(t, "virtual", VethEndpointType)
} }
func TestVhostUserEndpointTypeSet(t *testing.T) { func TestVhostUserEndpointTypeSet(t *testing.T) {
@ -63,9 +63,9 @@ func TestPhysicalEndpointTypeString(t *testing.T) {
testEndpointTypeString(t, &endpointType, string(PhysicalEndpointType)) testEndpointTypeString(t, &endpointType, string(PhysicalEndpointType))
} }
func TestVirtualEndpointTypeString(t *testing.T) { func TestVethEndpointTypeString(t *testing.T) {
endpointType := VirtualEndpointType endpointType := VethEndpointType
testEndpointTypeString(t, &endpointType, string(VirtualEndpointType)) testEndpointTypeString(t, &endpointType, string(VethEndpointType))
} }
func TestVhostUserEndpointTypeString(t *testing.T) { func TestVhostUserEndpointTypeString(t *testing.T) {

View File

@ -232,8 +232,8 @@ func (n *NetworkNamespace) UnmarshalJSON(b []byte) error {
"endpoint-type": "physical", "endpoint-type": "physical",
}).Info("endpoint unmarshalled") }).Info("endpoint unmarshalled")
case VirtualEndpointType: case VethEndpointType:
var endpoint VirtualEndpoint var endpoint VethEndpoint
err := json.Unmarshal(e.Data, &endpoint) err := json.Unmarshal(e.Data, &endpoint)
if err != nil { if err != nil {
return err return err
@ -394,7 +394,7 @@ func getLinkForEndpoint(endpoint Endpoint, netHandle *netlink.Handle) (netlink.L
var link netlink.Link var link netlink.Link
switch ep := endpoint.(type) { switch ep := endpoint.(type) {
case *VirtualEndpoint: case *VethEndpoint:
link = &netlink.Veth{} link = &netlink.Veth{}
case *BridgedMacvlanEndpoint: case *BridgedMacvlanEndpoint:
link = &netlink.Macvlan{} link = &netlink.Macvlan{}
@ -1117,7 +1117,7 @@ func createEndpoint(netInfo NetworkInfo, idx int, model NetInterworkingModel) (E
networkLogger().Infof("macvtap interface found") networkLogger().Infof("macvtap interface found")
endpoint, err = createMacvtapNetworkEndpoint(netInfo) endpoint, err = createMacvtapNetworkEndpoint(netInfo)
} else { } else {
endpoint, err = createVirtualNetworkEndpoint(idx, netInfo.Iface.Name, model) endpoint, err = createVethNetworkEndpoint(idx, netInfo.Iface.Name, model)
} }
} }

View File

@ -833,7 +833,7 @@ func (q *qemu) hotplugVFIODevice(device *config.VFIODev, op operation) error {
return nil return nil
} }
func (q *qemu) hotplugMacvtap(drive *VirtualEndpoint) error { func (q *qemu) hotplugMacvtap(drive *VethEndpoint) error {
var ( var (
VMFdNames []string VMFdNames []string
VhostFdNames []string VhostFdNames []string
@ -857,7 +857,7 @@ func (q *qemu) hotplugMacvtap(drive *VirtualEndpoint) error {
return q.qmpMonitorCh.qmp.ExecuteNetdevAddByFds(q.qmpMonitorCh.ctx, "tap", drive.NetPair.Name, VMFdNames, VhostFdNames) return q.qmpMonitorCh.qmp.ExecuteNetdevAddByFds(q.qmpMonitorCh.ctx, "tap", drive.NetPair.Name, VMFdNames, VhostFdNames)
} }
func (q *qemu) hotplugNetDevice(drive *VirtualEndpoint, op operation) error { func (q *qemu) hotplugNetDevice(drive *VethEndpoint, op operation) error {
err := q.qmpSetup() err := q.qmpSetup()
if err != nil { if err != nil {
return err return err
@ -914,7 +914,7 @@ func (q *qemu) hotplugDevice(devInfo interface{}, devType deviceType, op operati
memdev := devInfo.(*memoryDevice) memdev := devInfo.(*memoryDevice)
return q.hotplugMemory(memdev, op) return q.hotplugMemory(memdev, op)
case netDev: case netDev:
device := devInfo.(*VirtualEndpoint) device := devInfo.(*VethEndpoint)
return nil, q.hotplugNetDevice(device, op) return nil, q.hotplugNetDevice(device, op)
default: default:
return nil, fmt.Errorf("cannot hotplug device: unsupported device type '%v'", devType) return nil, fmt.Errorf("cannot hotplug device: unsupported device type '%v'", devType)

View File

@ -441,7 +441,7 @@ func networkModelToQemuType(model NetInterworkingModel) govmmQemu.NetDeviceType
func (q *qemuArchBase) appendNetwork(devices []govmmQemu.Device, endpoint Endpoint) []govmmQemu.Device { func (q *qemuArchBase) appendNetwork(devices []govmmQemu.Device, endpoint Endpoint) []govmmQemu.Device {
switch ep := endpoint.(type) { switch ep := endpoint.(type) {
case *VirtualEndpoint, *BridgedMacvlanEndpoint: case *VethEndpoint, *BridgedMacvlanEndpoint:
netPair := ep.NetworkPair() netPair := ep.NetworkPair()
devices = append(devices, devices = append(devices,
govmmQemu.NetDevice{ govmmQemu.NetDevice{

View File

@ -11,8 +11,8 @@ import (
"github.com/containernetworking/plugins/pkg/ns" "github.com/containernetworking/plugins/pkg/ns"
) )
// VirtualEndpoint gathers a network pair and its properties. // VethEndpoint gathers a network pair and its properties.
type VirtualEndpoint struct { type VethEndpoint struct {
NetPair NetworkInterfacePair NetPair NetworkInterfacePair
EndpointProperties NetworkInfo EndpointProperties NetworkInfo
Physical bool Physical bool
@ -20,9 +20,9 @@ type VirtualEndpoint struct {
PCIAddr string PCIAddr string
} }
func createVirtualNetworkEndpoint(idx int, ifName string, interworkingModel NetInterworkingModel) (*VirtualEndpoint, error) { func createVethNetworkEndpoint(idx int, ifName string, interworkingModel NetInterworkingModel) (*VethEndpoint, error) {
if idx < 0 { if idx < 0 {
return &VirtualEndpoint{}, fmt.Errorf("invalid network endpoint index: %d", idx) return &VethEndpoint{}, fmt.Errorf("invalid network endpoint index: %d", idx)
} }
netPair, err := createNetworkInterfacePair(idx, ifName, interworkingModel) netPair, err := createNetworkInterfacePair(idx, ifName, interworkingModel)
@ -30,12 +30,12 @@ func createVirtualNetworkEndpoint(idx int, ifName string, interworkingModel NetI
return nil, err return nil, err
} }
endpoint := &VirtualEndpoint{ endpoint := &VethEndpoint{
// TODO This is too specific. We may need to create multiple // TODO This is too specific. We may need to create multiple
// end point types here and then decide how to connect them // end point types here and then decide how to connect them
// at the time of hypervisor attach and not here // at the time of hypervisor attach and not here
NetPair: netPair, NetPair: netPair,
EndpointType: VirtualEndpointType, EndpointType: VethEndpointType,
} }
if ifName != "" { if ifName != "" {
endpoint.NetPair.VirtIface.Name = ifName endpoint.NetPair.VirtIface.Name = ifName
@ -45,44 +45,44 @@ func createVirtualNetworkEndpoint(idx int, ifName string, interworkingModel NetI
} }
// Properties returns properties for the veth interface in the network pair. // Properties returns properties for the veth interface in the network pair.
func (endpoint *VirtualEndpoint) Properties() NetworkInfo { func (endpoint *VethEndpoint) Properties() NetworkInfo {
return endpoint.EndpointProperties return endpoint.EndpointProperties
} }
// Name returns name of the veth interface in the network pair. // Name returns name of the veth interface in the network pair.
func (endpoint *VirtualEndpoint) Name() string { func (endpoint *VethEndpoint) Name() string {
return endpoint.NetPair.VirtIface.Name return endpoint.NetPair.VirtIface.Name
} }
// HardwareAddr returns the mac address that is assigned to the tap interface // HardwareAddr returns the mac address that is assigned to the tap interface
// in th network pair. // in th network pair.
func (endpoint *VirtualEndpoint) HardwareAddr() string { func (endpoint *VethEndpoint) HardwareAddr() string {
return endpoint.NetPair.TAPIface.HardAddr return endpoint.NetPair.TAPIface.HardAddr
} }
// Type identifies the endpoint as a virtual endpoint. // Type identifies the endpoint as a veth endpoint.
func (endpoint *VirtualEndpoint) Type() EndpointType { func (endpoint *VethEndpoint) Type() EndpointType {
return endpoint.EndpointType return endpoint.EndpointType
} }
// PciAddr returns the PCI address of the endpoint. // PciAddr returns the PCI address of the endpoint.
func (endpoint *VirtualEndpoint) PciAddr() string { func (endpoint *VethEndpoint) PciAddr() string {
return endpoint.PCIAddr return endpoint.PCIAddr
} }
// NetworkPair returns the network pair of the endpoint. // NetworkPair returns the network pair of the endpoint.
func (endpoint *VirtualEndpoint) NetworkPair() *NetworkInterfacePair { func (endpoint *VethEndpoint) NetworkPair() *NetworkInterfacePair {
return &endpoint.NetPair return &endpoint.NetPair
} }
// SetProperties sets the properties for the endpoint. // SetProperties sets the properties for the endpoint.
func (endpoint *VirtualEndpoint) SetProperties(properties NetworkInfo) { func (endpoint *VethEndpoint) SetProperties(properties NetworkInfo) {
endpoint.EndpointProperties = properties endpoint.EndpointProperties = properties
} }
// Attach for virtual endpoint bridges the network pair and adds the // Attach for veth endpoint bridges the network pair and adds the
// tap interface of the network pair to the hypervisor. // tap interface of the network pair to the hypervisor.
func (endpoint *VirtualEndpoint) Attach(h hypervisor) error { func (endpoint *VethEndpoint) Attach(h hypervisor) error {
networkLogger().WithField("endpoint-type", "virtual").Info("Attaching endpoint") networkLogger().WithField("endpoint-type", "virtual").Info("Attaching endpoint")
if err := xconnectVMNetwork(endpoint, true, h.hypervisorConfig().NumVCPUs, h.hypervisorConfig().DisableVhostNet); err != nil { if err := xconnectVMNetwork(endpoint, true, h.hypervisorConfig().NumVCPUs, h.hypervisorConfig().DisableVhostNet); err != nil {
@ -93,9 +93,9 @@ func (endpoint *VirtualEndpoint) Attach(h hypervisor) error {
return h.addDevice(endpoint, netDev) return h.addDevice(endpoint, netDev)
} }
// Detach for the virtual endpoint tears down the tap and bridge // Detach for the veth endpoint tears down the tap and bridge
// created for the veth interface. // created for the veth interface.
func (endpoint *VirtualEndpoint) Detach(netNsCreated bool, netNsPath string) error { func (endpoint *VethEndpoint) Detach(netNsCreated bool, netNsPath string) error {
// The network namespace would have been deleted at this point // The network namespace would have been deleted at this point
// if it has not been created by virtcontainers. // if it has not been created by virtcontainers.
if !netNsCreated { if !netNsCreated {
@ -109,8 +109,8 @@ func (endpoint *VirtualEndpoint) Detach(netNsCreated bool, netNsPath string) err
}) })
} }
// HotAttach for the virtual endpoint uses hot plug device // HotAttach for the veth endpoint uses hot plug device
func (endpoint *VirtualEndpoint) HotAttach(h hypervisor) error { func (endpoint *VethEndpoint) HotAttach(h hypervisor) error {
networkLogger().Info("Hot attaching virtual endpoint") networkLogger().Info("Hot attaching virtual endpoint")
if err := xconnectVMNetwork(endpoint, true, h.hypervisorConfig().NumVCPUs, h.hypervisorConfig().DisableVhostNet); err != nil { if err := xconnectVMNetwork(endpoint, true, h.hypervisorConfig().NumVCPUs, h.hypervisorConfig().DisableVhostNet); err != nil {
networkLogger().WithError(err).Error("Error bridging virtual ep") networkLogger().WithError(err).Error("Error bridging virtual ep")
@ -124,8 +124,8 @@ func (endpoint *VirtualEndpoint) HotAttach(h hypervisor) error {
return nil return nil
} }
// HotDetach for the virtual endpoint uses hot pull device // HotDetach for the veth endpoint uses hot pull device
func (endpoint *VirtualEndpoint) HotDetach(h hypervisor, netNsCreated bool, netNsPath string) error { func (endpoint *VethEndpoint) HotDetach(h hypervisor, netNsCreated bool, netNsPath string) error {
if !netNsCreated { if !netNsCreated {
return nil return nil
} }

View File

@ -11,10 +11,10 @@ import (
"testing" "testing"
) )
func TestCreateVirtualNetworkEndpoint(t *testing.T) { func TestCreateVethNetworkEndpoint(t *testing.T) {
macAddr := net.HardwareAddr{0x02, 0x00, 0xCA, 0xFE, 0x00, 0x04} macAddr := net.HardwareAddr{0x02, 0x00, 0xCA, 0xFE, 0x00, 0x04}
expected := &VirtualEndpoint{ expected := &VethEndpoint{
NetPair: NetworkInterfacePair{ NetPair: NetworkInterfacePair{
ID: "uniqueTestID-4", ID: "uniqueTestID-4",
Name: "br4_kata", Name: "br4_kata",
@ -27,10 +27,10 @@ func TestCreateVirtualNetworkEndpoint(t *testing.T) {
}, },
NetInterworkingModel: DefaultNetInterworkingModel, NetInterworkingModel: DefaultNetInterworkingModel,
}, },
EndpointType: VirtualEndpointType, EndpointType: VethEndpointType,
} }
result, err := createVirtualNetworkEndpoint(4, "", DefaultNetInterworkingModel) result, err := createVethNetworkEndpoint(4, "", DefaultNetInterworkingModel)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -46,10 +46,10 @@ func TestCreateVirtualNetworkEndpoint(t *testing.T) {
} }
} }
func TestCreateVirtualNetworkEndpointChooseIfaceName(t *testing.T) { func TestCreateVethNetworkEndpointChooseIfaceName(t *testing.T) {
macAddr := net.HardwareAddr{0x02, 0x00, 0xCA, 0xFE, 0x00, 0x04} macAddr := net.HardwareAddr{0x02, 0x00, 0xCA, 0xFE, 0x00, 0x04}
expected := &VirtualEndpoint{ expected := &VethEndpoint{
NetPair: NetworkInterfacePair{ NetPair: NetworkInterfacePair{
ID: "uniqueTestID-4", ID: "uniqueTestID-4",
Name: "br4_kata", Name: "br4_kata",
@ -62,10 +62,10 @@ func TestCreateVirtualNetworkEndpointChooseIfaceName(t *testing.T) {
}, },
NetInterworkingModel: DefaultNetInterworkingModel, NetInterworkingModel: DefaultNetInterworkingModel,
}, },
EndpointType: VirtualEndpointType, EndpointType: VethEndpointType,
} }
result, err := createVirtualNetworkEndpoint(4, "eth1", DefaultNetInterworkingModel) result, err := createVethNetworkEndpoint(4, "eth1", DefaultNetInterworkingModel)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -81,7 +81,7 @@ func TestCreateVirtualNetworkEndpointChooseIfaceName(t *testing.T) {
} }
} }
func TestCreateVirtualNetworkEndpointInvalidArgs(t *testing.T) { func TestCreateVethNetworkEndpointInvalidArgs(t *testing.T) {
type endpointValues struct { type endpointValues struct {
idx int idx int
ifName string ifName string
@ -94,7 +94,7 @@ func TestCreateVirtualNetworkEndpointInvalidArgs(t *testing.T) {
} }
for _, d := range failingValues { for _, d := range failingValues {
result, err := createVirtualNetworkEndpoint(d.idx, d.ifName, DefaultNetInterworkingModel) result, err := createVethNetworkEndpoint(d.idx, d.ifName, DefaultNetInterworkingModel)
if err == nil { if err == nil {
t.Fatalf("expected invalid endpoint for %v, got %v", d, result) t.Fatalf("expected invalid endpoint for %v, got %v", d, result)
} }