Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
network: Rename VirtualEndpoint to VethEndpoint
Browse files Browse the repository at this point in the history
As this really represents a veth pair rather than a generic
virtual interface, rename VirtualEndpoint to VethEndpoint.

Signed-off-by: Archana Shinde <[email protected]>
  • Loading branch information
amshinde committed Oct 11, 2018
1 parent df8f21d commit 3c590b0
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 50 deletions.
10 changes: 5 additions & 5 deletions virtcontainers/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ const (
// PhysicalEndpointType is the physical network interface.
PhysicalEndpointType EndpointType = "physical"

// VirtualEndpointType is the virtual network interface.
VirtualEndpointType EndpointType = "virtual"
// VethEndpointType is the virtual network interface.
VethEndpointType EndpointType = "virtual"

// VhostUserEndpointType is the vhostuser network interface.
VhostUserEndpointType EndpointType = "vhost-user"
Expand All @@ -52,7 +52,7 @@ func (endpointType *EndpointType) Set(value string) error {
*endpointType = PhysicalEndpointType
return nil
case "virtual":
*endpointType = VirtualEndpointType
*endpointType = VethEndpointType
return nil
case "vhost-user":
*endpointType = VhostUserEndpointType
Expand All @@ -73,8 +73,8 @@ func (endpointType *EndpointType) String() string {
switch *endpointType {
case PhysicalEndpointType:
return string(PhysicalEndpointType)
case VirtualEndpointType:
return string(VirtualEndpointType)
case VethEndpointType:
return string(VethEndpointType)
case VhostUserEndpointType:
return string(VhostUserEndpointType)
case BridgedMacvlanEndpointType:
Expand Down
10 changes: 5 additions & 5 deletions virtcontainers/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func TestPhysicalEndpointTypeSet(t *testing.T) {
testEndpointTypeSet(t, "physical", PhysicalEndpointType)
}

func TestVirtualEndpointTypeSet(t *testing.T) {
testEndpointTypeSet(t, "virtual", VirtualEndpointType)
func TestVethEndpointTypeSet(t *testing.T) {
testEndpointTypeSet(t, "virtual", VethEndpointType)
}

func TestVhostUserEndpointTypeSet(t *testing.T) {
Expand Down Expand Up @@ -63,9 +63,9 @@ func TestPhysicalEndpointTypeString(t *testing.T) {
testEndpointTypeString(t, &endpointType, string(PhysicalEndpointType))
}

func TestVirtualEndpointTypeString(t *testing.T) {
endpointType := VirtualEndpointType
testEndpointTypeString(t, &endpointType, string(VirtualEndpointType))
func TestVethEndpointTypeString(t *testing.T) {
endpointType := VethEndpointType
testEndpointTypeString(t, &endpointType, string(VethEndpointType))
}

func TestVhostUserEndpointTypeString(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions virtcontainers/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ func (n *NetworkNamespace) UnmarshalJSON(b []byte) error {
"endpoint-type": "physical",
}).Info("endpoint unmarshalled")

case VirtualEndpointType:
var endpoint VirtualEndpoint
case VethEndpointType:
var endpoint VethEndpoint
err := json.Unmarshal(e.Data, &endpoint)
if err != nil {
return err
Expand Down Expand Up @@ -394,7 +394,7 @@ func getLinkForEndpoint(endpoint Endpoint, netHandle *netlink.Handle) (netlink.L
var link netlink.Link

switch ep := endpoint.(type) {
case *VirtualEndpoint:
case *VethEndpoint:
link = &netlink.Veth{}
case *BridgedMacvlanEndpoint:
link = &netlink.Macvlan{}
Expand Down Expand Up @@ -1117,7 +1117,7 @@ func createEndpoint(netInfo NetworkInfo, idx int, model NetInterworkingModel) (E
networkLogger().Infof("macvtap interface found")
endpoint, err = createMacvtapNetworkEndpoint(netInfo)
} else {
endpoint, err = createVirtualNetworkEndpoint(idx, netInfo.Iface.Name, model)
endpoint, err = createVethNetworkEndpoint(idx, netInfo.Iface.Name, model)
}
}

Expand Down
6 changes: 3 additions & 3 deletions virtcontainers/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ func (q *qemu) hotplugVFIODevice(device *config.VFIODev, op operation) error {
return nil
}

func (q *qemu) hotplugMacvtap(drive *VirtualEndpoint) error {
func (q *qemu) hotplugMacvtap(drive *VethEndpoint) error {
var (
VMFdNames []string
VhostFdNames []string
Expand All @@ -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)
}

func (q *qemu) hotplugNetDevice(drive *VirtualEndpoint, op operation) error {
func (q *qemu) hotplugNetDevice(drive *VethEndpoint, op operation) error {
err := q.qmpSetup()
if err != nil {
return err
Expand Down Expand Up @@ -914,7 +914,7 @@ func (q *qemu) hotplugDevice(devInfo interface{}, devType deviceType, op operati
memdev := devInfo.(*memoryDevice)
return q.hotplugMemory(memdev, op)
case netDev:
device := devInfo.(*VirtualEndpoint)
device := devInfo.(*VethEndpoint)
return nil, q.hotplugNetDevice(device, op)
default:
return nil, fmt.Errorf("cannot hotplug device: unsupported device type '%v'", devType)
Expand Down
2 changes: 1 addition & 1 deletion virtcontainers/qemu_arch_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ func networkModelToQemuType(model NetInterworkingModel) govmmQemu.NetDeviceType

func (q *qemuArchBase) appendNetwork(devices []govmmQemu.Device, endpoint Endpoint) []govmmQemu.Device {
switch ep := endpoint.(type) {
case *VirtualEndpoint, *BridgedMacvlanEndpoint:
case *VethEndpoint, *BridgedMacvlanEndpoint:
netPair := ep.NetworkPair()
devices = append(devices,
govmmQemu.NetDevice{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@ import (
"github.com/containernetworking/plugins/pkg/ns"
)

// VirtualEndpoint gathers a network pair and its properties.
type VirtualEndpoint struct {
// VethEndpoint gathers a network pair and its properties.
type VethEndpoint struct {
NetPair NetworkInterfacePair
EndpointProperties NetworkInfo
Physical bool
EndpointType EndpointType
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 {
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)
if err != nil {
return nil, err
}

endpoint := &VirtualEndpoint{
endpoint := &VethEndpoint{
// TODO This is too specific. We may need to create multiple
// end point types here and then decide how to connect them
// at the time of hypervisor attach and not here
NetPair: netPair,
EndpointType: VirtualEndpointType,
EndpointType: VethEndpointType,
}
if ifName != "" {
endpoint.NetPair.VirtIface.Name = ifName
Expand All @@ -45,44 +45,44 @@ func createVirtualNetworkEndpoint(idx int, ifName string, interworkingModel NetI
}

// Properties returns properties for the veth interface in the network pair.
func (endpoint *VirtualEndpoint) Properties() NetworkInfo {
func (endpoint *VethEndpoint) Properties() NetworkInfo {
return endpoint.EndpointProperties
}

// 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
}

// HardwareAddr returns the mac address that is assigned to the tap interface
// in th network pair.
func (endpoint *VirtualEndpoint) HardwareAddr() string {
func (endpoint *VethEndpoint) HardwareAddr() string {
return endpoint.NetPair.TAPIface.HardAddr
}

// Type identifies the endpoint as a virtual endpoint.
func (endpoint *VirtualEndpoint) Type() EndpointType {
// Type identifies the endpoint as a veth endpoint.
func (endpoint *VethEndpoint) Type() EndpointType {
return endpoint.EndpointType
}

// PciAddr returns the PCI address of the endpoint.
func (endpoint *VirtualEndpoint) PciAddr() string {
func (endpoint *VethEndpoint) PciAddr() string {
return endpoint.PCIAddr
}

// NetworkPair returns the network pair of the endpoint.
func (endpoint *VirtualEndpoint) NetworkPair() *NetworkInterfacePair {
func (endpoint *VethEndpoint) NetworkPair() *NetworkInterfacePair {
return &endpoint.NetPair
}

// SetProperties sets the properties for the endpoint.
func (endpoint *VirtualEndpoint) SetProperties(properties NetworkInfo) {
func (endpoint *VethEndpoint) SetProperties(properties NetworkInfo) {
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.
func (endpoint *VirtualEndpoint) Attach(h hypervisor) error {
func (endpoint *VethEndpoint) Attach(h hypervisor) error {
networkLogger().WithField("endpoint-type", "virtual").Info("Attaching endpoint")

if err := xconnectVMNetwork(endpoint, true, h.hypervisorConfig().NumVCPUs, h.hypervisorConfig().DisableVhostNet); err != nil {
Expand All @@ -93,9 +93,9 @@ func (endpoint *VirtualEndpoint) Attach(h hypervisor) error {
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.
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
// if it has not been created by virtcontainers.
if !netNsCreated {
Expand All @@ -109,8 +109,8 @@ func (endpoint *VirtualEndpoint) Detach(netNsCreated bool, netNsPath string) err
})
}

// HotAttach for the virtual endpoint uses hot plug device
func (endpoint *VirtualEndpoint) HotAttach(h hypervisor) error {
// HotAttach for the veth endpoint uses hot plug device
func (endpoint *VethEndpoint) HotAttach(h hypervisor) error {
networkLogger().Info("Hot attaching virtual endpoint")
if err := xconnectVMNetwork(endpoint, true, h.hypervisorConfig().NumVCPUs, h.hypervisorConfig().DisableVhostNet); err != nil {
networkLogger().WithError(err).Error("Error bridging virtual ep")
Expand All @@ -124,8 +124,8 @@ func (endpoint *VirtualEndpoint) HotAttach(h hypervisor) error {
return nil
}

// HotDetach for the virtual endpoint uses hot pull device
func (endpoint *VirtualEndpoint) HotDetach(h hypervisor, netNsCreated bool, netNsPath string) error {
// HotDetach for the veth endpoint uses hot pull device
func (endpoint *VethEndpoint) HotDetach(h hypervisor, netNsCreated bool, netNsPath string) error {
if !netNsCreated {
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
"testing"
)

func TestCreateVirtualNetworkEndpoint(t *testing.T) {
func TestCreateVethNetworkEndpoint(t *testing.T) {
macAddr := net.HardwareAddr{0x02, 0x00, 0xCA, 0xFE, 0x00, 0x04}

expected := &VirtualEndpoint{
expected := &VethEndpoint{
NetPair: NetworkInterfacePair{
ID: "uniqueTestID-4",
Name: "br4_kata",
Expand All @@ -27,10 +27,10 @@ func TestCreateVirtualNetworkEndpoint(t *testing.T) {
},
NetInterworkingModel: DefaultNetInterworkingModel,
},
EndpointType: VirtualEndpointType,
EndpointType: VethEndpointType,
}

result, err := createVirtualNetworkEndpoint(4, "", DefaultNetInterworkingModel)
result, err := createVethNetworkEndpoint(4, "", DefaultNetInterworkingModel)
if err != nil {
t.Fatal(err)
}
Expand All @@ -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}

expected := &VirtualEndpoint{
expected := &VethEndpoint{
NetPair: NetworkInterfacePair{
ID: "uniqueTestID-4",
Name: "br4_kata",
Expand All @@ -62,10 +62,10 @@ func TestCreateVirtualNetworkEndpointChooseIfaceName(t *testing.T) {
},
NetInterworkingModel: DefaultNetInterworkingModel,
},
EndpointType: VirtualEndpointType,
EndpointType: VethEndpointType,
}

result, err := createVirtualNetworkEndpoint(4, "eth1", DefaultNetInterworkingModel)
result, err := createVethNetworkEndpoint(4, "eth1", DefaultNetInterworkingModel)
if err != nil {
t.Fatal(err)
}
Expand All @@ -81,7 +81,7 @@ func TestCreateVirtualNetworkEndpointChooseIfaceName(t *testing.T) {
}
}

func TestCreateVirtualNetworkEndpointInvalidArgs(t *testing.T) {
func TestCreateVethNetworkEndpointInvalidArgs(t *testing.T) {
type endpointValues struct {
idx int
ifName string
Expand All @@ -94,7 +94,7 @@ func TestCreateVirtualNetworkEndpointInvalidArgs(t *testing.T) {
}

for _, d := range failingValues {
result, err := createVirtualNetworkEndpoint(d.idx, d.ifName, DefaultNetInterworkingModel)
result, err := createVethNetworkEndpoint(d.idx, d.ifName, DefaultNetInterworkingModel)
if err == nil {
t.Fatalf("expected invalid endpoint for %v, got %v", d, result)
}
Expand Down

0 comments on commit 3c590b0

Please sign in to comment.