Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,14 +348,15 @@ These selectors are applicable when "deviceType" is "auxNetDevice".

| Field | Required | Description | Type/Defaults | Example/Accepted values |
|---------------|----------|----------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------|--------------------------------------------------------------------------------------------------|
| "vendors" | N | Target device's vendor Hex code as string | `string` list Default: `null` | "vendors": ["8086", "15b3"] |
| "devices" | N | Parent PCI device Hex code as string | `string` list Default: `null` | "devices": ["154c", "1889", "1018"] |
| "drivers" | N | Target device driver names as string | `string` list Default: `null` | "drivers": ["vfio-pci"] |
| "pfNames" | N | functions from PF matches list of PF names | `string` list Default: `null` | "pfNames": ["enp2s2f0"] (See follow-up sections for some advance usage of "pfNames") |
| "rootDevices" | N | functions from PF matches list of PF PCI addresses | `string` list Default: `null` | "rootDevices": ["0000:86:00.0"] (See follow-up sections for some advance usage of "rootDevices") |
| "linkTypes" | N | The link type of the net device associated with the PCI device | `string` list Default: `null` | "linkTypes": ["ether"] |
| "isRdma" | N | Mount RDMA resources. Incompatible with vdpaType | `bool` values `true` or `false` Default: `false` | "isRdma": `true` |
| "auxTypes" | N | List of vendor specific auxiliary network device types. Device type can be determined by its name: <driver_name>.<kind_of_a_type>.<id> | `string` list Default: `null` | "auxTypes": ["sf", "eth"] |
| "vendors" | N | Target device's vendor Hex code as string | `string` list Default: `null` | "vendors": ["8086", "15b3"] |
| "devices" | N | Parent PCI device Hex code as string | `string` list Default: `null` | "devices": ["154c", "1889", "1018"] |
| "drivers" | N | Target device driver names as string | `string` list Default: `null` | "drivers": ["vfio-pci"] |
| "pfNames" | N | functions from PF matches list of PF names | `string` list Default: `null` | "pfNames": ["enp2s2f0"] (See follow-up sections for some advance usage of "pfNames") |
| "rootDevices" | N | functions from PF matches list of PF PCI addresses | `string` list Default: `null` | "rootDevices": ["0000:86:00.0"] (See follow-up sections for some advance usage of "rootDevices") |
| "linkTypes" | N | The link type of the net device associated with the PCI device | `string` list Default: `null` | "linkTypes": ["ether"] |
| "isRdma" | N | Mount RDMA resources. Incompatible with vdpaType | `bool` values `true` or `false` Default: `false` | "isRdma": `true` |
| "needVhostNet" | N | Share /dev/vhost-net and /dev/net/tun | `bool` values `true` or `false` Default: `false` | "needVhostNet": `true` |
| "auxTypes" | N | List of vendor-specific auxiliary network device types. Device type can be determined by its name: <driver_name>.<kind_of_a_type>.<id> | `string` list Default: `null` | "auxTypes": ["sf", "eth"] |

[//]: # (The tables above generated using: https://ozh.github.io/ascii-tables/)

Expand Down
8 changes: 8 additions & 0 deletions pkg/auxnetdevice/auxNetDevice.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ func NewAuxNetDevice(dev *ghw.PCIDevice, deviceID string, rFactory types.Resourc
glog.Warningf("RDMA resources for %s not found. Are RDMA modules loaded?", deviceID)
}
}

if nf.NeedVhostNet {
if infoprovider.VhostNetDeviceExist() {
infoProviders = append(infoProviders, infoprovider.NewVhostNetInfoProvider())
} else {
glog.Warningf("vhost-net is required in the configuration for %s but /dev/vhost-net doesn't exist", deviceID)
}
}
}

hostDev, err := devices.NewHostDeviceImpl(dev, deviceID, rFactory, rc, infoProviders)
Expand Down
134 changes: 134 additions & 0 deletions pkg/auxnetdevice/auxNetDevice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package auxnetdevice_test

import (
"path/filepath"
"testing"

"github.com/jaypipes/ghw"
Expand All @@ -28,6 +29,7 @@ import (

"github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/auxnetdevice"
"github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/factory"
"github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/infoprovider"
"github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/types"
tmocks "github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/types/mocks"
"github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/utils"
Expand Down Expand Up @@ -299,5 +301,137 @@ var _ = Describe("AuxNetDevice", func() {
fakeSriovnetProvider.AssertExpectations(t)
})
})

Context("with needVhostNet", func() {
It("should provide expected environment variables and mounts", func() {
fs := &utils.FakeFilesystem{
Dirs: []string{
"sys/bus/pci/devices/0000:00:00.1/net/net0",
"sys/bus/pci/drivers/mlx5_core",
"dev/net/tun",
"dev/vhost-net",
},
Symlinks: map[string]string{
"sys/bus/pci/devices/0000:00:00.1/driver": "../../../../bus/pci/drivers/mlx5_core",
},
Files: map[string][]byte{"sys/bus/pci/devices/0000:00:00.1/numa_node": []byte("0")},
}
defer fs.Use()()

infoprovider.HostNet = filepath.Join(fs.RootDir, "dev/vhost-net")
infoprovider.HostTun = filepath.Join(fs.RootDir, "dev/net/tun")

utils.SetDefaultMockNetlinkProvider()
auxDevID := "mlx5_core.sf.0"
fakeSriovnetProvider := mocks.SriovnetProvider{}
fakeSriovnetProvider.
On("GetUplinkRepresentorFromAux", auxDevID).Return("net0", nil).
On("GetPfPciFromAux", auxDevID).Return("0000:00:00.1", nil).
On("GetSfIndexByAuxDev", auxDevID).Return(1, nil).
On("GetNetDevicesFromAux", auxDevID).Return([]string{"eth0"}, nil)
utils.SetSriovnetProviderInst(&fakeSriovnetProvider)

f := factory.NewResourceFactory("fake", "fake", true, false)
in := newPciDevice("0000:00:00.1")
rc := &types.ResourceConfig{
ResourceName: "fake",
ResourcePrefix: "fake",
DeviceType: types.AuxNetDeviceType,
SelectorObjs: []interface{}{&types.AuxNetDeviceSelectors{
GenericNetDeviceSelectors: types.GenericNetDeviceSelectors{
NeedVhostNet: true,
},
}}}

dev, err := auxnetdevice.NewAuxNetDevice(in, auxDevID, f, rc, 0)
Expect(err).NotTo(HaveOccurred())
Expect(dev).NotTo(BeNil())
Expect(dev.GetDriver()).To(Equal("mlx5_core"))
Expect(dev.GetNetName()).To(Equal("eth0"))

envs := dev.GetEnvVal()
Expect(envs).To(HaveLen(2))
// validate device ID env var
Expect(envs).To(HaveKey("generic"))
Expect(envs["generic"]).To(HaveKeyWithValue("deviceID", "mlx5_core.sf.0"))
// validate vhost env vars
Expect(envs).To(HaveKey("vhost"))
Expect(envs["vhost"]).To(HaveKeyWithValue("net-mount", "/dev/vhost-net"))
Expect(envs["vhost"]).To(HaveKeyWithValue("tun-mount", "/dev/net/tun"))

// validate mounts
devSpecs := dev.GetDeviceSpecs()
Expect(devSpecs).To(HaveLen(2))
Expect(devSpecs).To(ConsistOf(
And(HaveField("HostPath", "/dev/vhost-net"), HaveField("ContainerPath", "/dev/vhost-net")),
And(HaveField("HostPath", "/dev/net/tun"), HaveField("ContainerPath", "/dev/net/tun")),
))

Expect(dev.GetLinkType()).To(Equal("fakeLinkType"))
Expect(dev.GetFuncID()).To(Equal(1))
Expect(dev.GetAPIDevice().Topology.Nodes[0].ID).To(Equal(int64(0)))
Expect(dev.GetAuxType()).To(Equal("sf"))
fakeSriovnetProvider.AssertExpectations(t)
})

It("should not contain vhost related environment variables and mounts if vhost-net device does not exist", func() {
fs := &utils.FakeFilesystem{
Dirs: []string{
"sys/bus/pci/devices/0000:00:00.1/net/net0",
"sys/bus/pci/drivers/mlx5_core",
},
Symlinks: map[string]string{
"sys/bus/pci/devices/0000:00:00.1/driver": "../../../../bus/pci/drivers/mlx5_core",
},
Files: map[string][]byte{"sys/bus/pci/devices/0000:00:00.1/numa_node": []byte("0")},
}
defer fs.Use()()

infoprovider.HostNet = filepath.Join(fs.RootDir, "dev/vhost-net")
infoprovider.HostTun = filepath.Join(fs.RootDir, "dev/net/tun")

utils.SetDefaultMockNetlinkProvider()
auxDevID := "mlx5_core.sf.0"
fakeSriovnetProvider := mocks.SriovnetProvider{}
fakeSriovnetProvider.
On("GetUplinkRepresentorFromAux", auxDevID).Return("net0", nil).
On("GetPfPciFromAux", auxDevID).Return("0000:00:00.1", nil).
On("GetSfIndexByAuxDev", auxDevID).Return(1, nil).
On("GetNetDevicesFromAux", auxDevID).Return([]string{"eth0"}, nil)
utils.SetSriovnetProviderInst(&fakeSriovnetProvider)

f := factory.NewResourceFactory("fake", "fake", true, false)
in := newPciDevice("0000:00:00.1")
rc := &types.ResourceConfig{
ResourceName: "fake",
ResourcePrefix: "fake",
DeviceType: types.AuxNetDeviceType,
SelectorObjs: []interface{}{&types.AuxNetDeviceSelectors{
GenericNetDeviceSelectors: types.GenericNetDeviceSelectors{
NeedVhostNet: true,
},
}}}

dev, err := auxnetdevice.NewAuxNetDevice(in, auxDevID, f, rc, 0)
Expect(err).NotTo(HaveOccurred())
Expect(dev).NotTo(BeNil())
Expect(dev.GetDriver()).To(Equal("mlx5_core"))
Expect(dev.GetNetName()).To(Equal("eth0"))

envs := dev.GetEnvVal()
Expect(envs).To(HaveLen(1))
// validate device ID env var
Expect(envs).To(HaveKey("generic"))
Expect(envs["generic"]).To(HaveKeyWithValue("deviceID", "mlx5_core.sf.0"))

// validate no mounts
Expect(dev.GetDeviceSpecs()).To(BeEmpty())
Expect(dev.GetLinkType()).To(Equal("fakeLinkType"))
Expect(dev.GetFuncID()).To(Equal(1))
Expect(dev.GetAPIDevice().Topology.Nodes[0].ID).To(Equal(int64(0)))
Expect(dev.GetAuxType()).To(Equal("sf"))
fakeSriovnetProvider.AssertExpectations(t)
})
})
})
})
2 changes: 1 addition & 1 deletion pkg/netdevice/pciNetDevice.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func NewPciNetDevice(dev *ghw.PCIDevice,
if infoprovider.VhostNetDeviceExist() {
infoProviders = append(infoProviders, infoprovider.NewVhostNetInfoProvider())
} else {
glog.Errorf("GetDeviceSpecs(): vhost-net is required in the configuration but /dev/vhost-net doesn't exist")
glog.Warningf("vhost-net is required in the configuration for %s but /dev/vhost-net doesn't exist", dev.Address)
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/netdevice/pciNetDevice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,9 @@ var _ = Describe("PciNetDevice", func() {
ResourcePrefix: "fake",
SelectorObjs: []interface{}{&types.NetDeviceSelectors{},
&types.NetDeviceSelectors{
NeedVhostNet: true,
},
GenericNetDeviceSelectors: types.GenericNetDeviceSelectors{
NeedVhostNet: true,
}},
}}
no_vhost_net_selector_index := 0
vhost_net_selector_index := 1
Expand Down
18 changes: 9 additions & 9 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,22 +122,22 @@ type GenericPciDeviceSelectors struct {

// GenericNetDeviceSelectors contains common net device selectors fields
type GenericNetDeviceSelectors struct {
PfNames []string `json:"pfNames,omitempty"`
RootDevices []string `json:"rootDevices,omitempty"`
LinkTypes []string `json:"linkTypes,omitempty"`
IsRdma bool // the resource support rdma
AcpiIndexes []string `json:"acpiIndexes,omitempty"`
PfNames []string `json:"pfNames,omitempty"`
RootDevices []string `json:"rootDevices,omitempty"`
LinkTypes []string `json:"linkTypes,omitempty"`
IsRdma bool // the resource support rdma
AcpiIndexes []string `json:"acpiIndexes,omitempty"`
NeedVhostNet bool `json:"needVhostNet,omitempty"` // share vhost-net along the selected resource
}

// NetDeviceSelectors contains network device related selectors fields
type NetDeviceSelectors struct {
DeviceSelectors
GenericPciDeviceSelectors
GenericNetDeviceSelectors
DDPProfiles []string `json:"ddpProfiles,omitempty"`
NeedVhostNet bool // share vhost-net along the selected resource
VdpaType VdpaType `json:"vdpaType,omitempty"`
PKeys []string `json:"pKeys,omitempty"`
DDPProfiles []string `json:"ddpProfiles,omitempty"`
VdpaType VdpaType `json:"vdpaType,omitempty"`
PKeys []string `json:"pKeys,omitempty"`
}

// AccelDeviceSelectors contains accelerator(FPGA etc.) related selectors fields
Expand Down
Loading