From f5d2e2c4b334143cb3a84b515b5a13a0a1f3d0fb Mon Sep 17 00:00:00 2001 From: Yury Kulazhenkov Date: Tue, 13 Feb 2024 14:41:25 +0200 Subject: [PATCH] Add functions to work with devlink dev parameters Signed-off-by: Yury Kulazhenkov --- pkg/helper/mock/mock_helper.go | 29 ++++ .../internal/lib/netlink/mock/mock_netlink.go | 29 ++++ pkg/host/internal/lib/netlink/netlink.go | 22 +++ pkg/host/internal/network/network.go | 93 +++++++++++ pkg/host/internal/network/network_test.go | 155 ++++++++++++++++++ pkg/host/internal/network/suite_test.go | 21 +++ pkg/host/mock/mock_host.go | 29 ++++ pkg/host/types/interfaces.go | 7 + 8 files changed, 385 insertions(+) create mode 100644 pkg/host/internal/network/network_test.go create mode 100644 pkg/host/internal/network/suite_test.go diff --git a/pkg/helper/mock/mock_helper.go b/pkg/helper/mock/mock_helper.go index 95053f470..2b967572d 100644 --- a/pkg/helper/mock/mock_helper.go +++ b/pkg/helper/mock/mock_helper.go @@ -313,6 +313,21 @@ func (mr *MockHostHelpersInterfaceMockRecorder) GetCurrentKernelArgs() *gomock.C return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCurrentKernelArgs", reflect.TypeOf((*MockHostHelpersInterface)(nil).GetCurrentKernelArgs)) } +// GetDevlinkDeviceParam mocks base method. +func (m *MockHostHelpersInterface) GetDevlinkDeviceParam(pciAddr, paramName string) (string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetDevlinkDeviceParam", pciAddr, paramName) + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetDevlinkDeviceParam indicates an expected call of GetDevlinkDeviceParam. +func (mr *MockHostHelpersInterfaceMockRecorder) GetDevlinkDeviceParam(pciAddr, paramName interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDevlinkDeviceParam", reflect.TypeOf((*MockHostHelpersInterface)(nil).GetDevlinkDeviceParam), pciAddr, paramName) +} + // GetDriverByBusAndDevice mocks base method. func (m *MockHostHelpersInterface) GetDriverByBusAndDevice(bus, device string) (string, error) { m.ctrl.T.Helper() @@ -929,6 +944,20 @@ func (mr *MockHostHelpersInterfaceMockRecorder) SaveLastPfAppliedStatus(PfInfo i return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SaveLastPfAppliedStatus", reflect.TypeOf((*MockHostHelpersInterface)(nil).SaveLastPfAppliedStatus), PfInfo) } +// SetDevlinkDeviceParam mocks base method. +func (m *MockHostHelpersInterface) SetDevlinkDeviceParam(pciAddr, paramName, value string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetDevlinkDeviceParam", pciAddr, paramName, value) + ret0, _ := ret[0].(error) + return ret0 +} + +// SetDevlinkDeviceParam indicates an expected call of SetDevlinkDeviceParam. +func (mr *MockHostHelpersInterfaceMockRecorder) SetDevlinkDeviceParam(pciAddr, paramName, value interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetDevlinkDeviceParam", reflect.TypeOf((*MockHostHelpersInterface)(nil).SetDevlinkDeviceParam), pciAddr, paramName, value) +} + // SetNetdevMTU mocks base method. func (m *MockHostHelpersInterface) SetNetdevMTU(pciAddr string, mtu int) error { m.ctrl.T.Helper() diff --git a/pkg/host/internal/lib/netlink/mock/mock_netlink.go b/pkg/host/internal/lib/netlink/mock/mock_netlink.go index c687b7455..febef3395 100644 --- a/pkg/host/internal/lib/netlink/mock/mock_netlink.go +++ b/pkg/host/internal/lib/netlink/mock/mock_netlink.go @@ -116,6 +116,35 @@ func (mr *MockNetlinkLibMockRecorder) DevLinkSetEswitchMode(dev, newMode interfa return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DevLinkSetEswitchMode", reflect.TypeOf((*MockNetlinkLib)(nil).DevLinkSetEswitchMode), dev, newMode) } +// DevlinkGetDeviceParamByName mocks base method. +func (m *MockNetlinkLib) DevlinkGetDeviceParamByName(bus, device, param string) (*netlink0.DevlinkParam, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DevlinkGetDeviceParamByName", bus, device, param) + ret0, _ := ret[0].(*netlink0.DevlinkParam) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DevlinkGetDeviceParamByName indicates an expected call of DevlinkGetDeviceParamByName. +func (mr *MockNetlinkLibMockRecorder) DevlinkGetDeviceParamByName(bus, device, param interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DevlinkGetDeviceParamByName", reflect.TypeOf((*MockNetlinkLib)(nil).DevlinkGetDeviceParamByName), bus, device, param) +} + +// DevlinkSetDeviceParam mocks base method. +func (m *MockNetlinkLib) DevlinkSetDeviceParam(bus, device, param string, cmode uint8, value interface{}) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DevlinkSetDeviceParam", bus, device, param, cmode, value) + ret0, _ := ret[0].(error) + return ret0 +} + +// DevlinkSetDeviceParam indicates an expected call of DevlinkSetDeviceParam. +func (mr *MockNetlinkLibMockRecorder) DevlinkSetDeviceParam(bus, device, param, cmode, value interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DevlinkSetDeviceParam", reflect.TypeOf((*MockNetlinkLib)(nil).DevlinkSetDeviceParam), bus, device, param, cmode, value) +} + // LinkByName mocks base method. func (m *MockNetlinkLib) LinkByName(name string) (netlink.Link, error) { m.ctrl.T.Helper() diff --git a/pkg/host/internal/lib/netlink/netlink.go b/pkg/host/internal/lib/netlink/netlink.go index 782e39998..5d764ebf5 100644 --- a/pkg/host/internal/lib/netlink/netlink.go +++ b/pkg/host/internal/lib/netlink/netlink.go @@ -50,6 +50,14 @@ type NetlinkLib interface { // VDPANewDev adds new VDPA device // Equivalent to: `vdpa dev add name mgmtdev /mgmtName [params]` VDPANewDev(name, mgmtBus, mgmtName string, params netlink.VDPANewDevParams) error + // DevlinkGetDeviceParamByName returns specific parameter for devlink device + // Equivalent to: `devlink dev param show / name ` + DevlinkGetDeviceParamByName(bus string, device string, param string) (*netlink.DevlinkParam, error) + // DevlinkSetDeviceParam set specific parameter for devlink device + // Equivalent to: `devlink dev param set / name cmode value ` + // cmode argument should contain valid cmode value as uint8, modes are define in nl.DEVLINK_PARAM_CMODE_* constants + // value argument should have one of the following types: uint8, uint16, uint32, string, bool + DevlinkSetDeviceParam(bus string, device string, param string, cmode uint8, value interface{}) error } type libWrapper struct{} @@ -120,3 +128,17 @@ func (w *libWrapper) VDPADelDev(name string) error { func (w *libWrapper) VDPANewDev(name, mgmtBus, mgmtName string, params netlink.VDPANewDevParams) error { return netlink.VDPANewDev(name, mgmtBus, mgmtName, params) } + +// DevlinkGetDeviceParamByName returns specific parameter for devlink device +// Equivalent to: `devlink dev param show / name ` +func (w *libWrapper) DevlinkGetDeviceParamByName(bus string, device string, param string) (*netlink.DevlinkParam, error) { + return netlink.DevlinkGetDeviceParamByName(bus, device, param) +} + +// DevlinkSetDeviceParam set specific parameter for devlink device +// Equivalent to: `devlink dev param set / name cmode value ` +// cmode argument should contain valid cmode value as uint8, modes are define in nl.DEVLINK_PARAM_CMODE_* constants +// value argument should have one of the following types: uint8, uint16, uint32, string, bool +func (w *libWrapper) DevlinkSetDeviceParam(bus string, device string, param string, cmode uint8, value interface{}) error { + return netlink.DevlinkSetDeviceParam(bus, device, param, cmode, value) +} diff --git a/pkg/host/internal/network/network.go b/pkg/host/internal/network/network.go index 75f938228..b4a2a16ad 100644 --- a/pkg/host/internal/network/network.go +++ b/pkg/host/internal/network/network.go @@ -4,10 +4,12 @@ import ( "fmt" "os" "path/filepath" + "strconv" "strings" "time" "github.com/cenkalti/backoff" + "github.com/vishvananda/netlink/nl" "sigs.k8s.io/controller-runtime/pkg/log" "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/consts" @@ -193,3 +195,94 @@ func (n *network) GetNetDevLinkSpeed(ifaceName string) string { return fmt.Sprintf("%s Mb/s", strings.TrimSpace(string(data))) } + +// GetDevlinkDeviceParam returns devlink parameter for the device as a string, if the parameter has multiple values +// then the function will return only first one from the list. +func (n *network) GetDevlinkDeviceParam(pciAddr, paramName string) (string, error) { + funcLog := log.Log.WithValues("device", pciAddr, "param", paramName) + funcLog.V(2).Info("GetDevlinkDeviceParam(): get device parameter") + param, err := n.netlinkLib.DevlinkGetDeviceParamByName(consts.BusPci, pciAddr, paramName) + if err != nil { + funcLog.Error(err, "GetDevlinkDeviceParam(): fail to get devlink device param") + return "", err + } + if len(param.Values) == 0 { + err = fmt.Errorf("param %s has no value", paramName) + funcLog.Error(err, "GetDevlinkDeviceParam(): error") + return "", err + } + var value string + switch param.Type { + case nl.DEVLINK_PARAM_TYPE_U8, nl.DEVLINK_PARAM_TYPE_U16, nl.DEVLINK_PARAM_TYPE_U32: + var valData uint64 + switch v := param.Values[0].Data.(type) { + case uint8: + valData = uint64(v) + case uint16: + valData = uint64(v) + case uint32: + valData = uint64(v) + default: + return "", fmt.Errorf("unexpected uint type type") + } + value = strconv.FormatUint(valData, 10) + + case nl.DEVLINK_PARAM_TYPE_STRING: + value = param.Values[0].Data.(string) + case nl.DEVLINK_PARAM_TYPE_BOOL: + value = strconv.FormatBool(param.Values[0].Data.(bool)) + default: + return "", fmt.Errorf("unknown value type: %d", param.Type) + } + funcLog.V(2).Info("GetDevlinkDeviceParam(): result", "value", value) + return value, nil +} + +// SetDevlinkDeviceParam set devlink parameter for the device, accepts paramName and value +// as a string. Automatically set CMODE for the parameter and converts the value to the right +// type before submitting it. +func (n *network) SetDevlinkDeviceParam(pciAddr, paramName, value string) error { + funcLog := log.Log.WithValues("device", pciAddr, "param", paramName, "value", value) + funcLog.V(2).Info("SetDevlinkDeviceParam(): set device parameter") + param, err := n.netlinkLib.DevlinkGetDeviceParamByName(consts.BusPci, pciAddr, paramName) + if err != nil { + funcLog.Error(err, "SetDevlinkDeviceParam(): can't get existing param data") + return err + } + if len(param.Values) == 0 { + err = fmt.Errorf("param %s has no value", paramName) + funcLog.Error(err, "SetDevlinkDeviceParam(): error") + return err + } + targetCMOD := param.Values[0].CMODE + var typedValue interface{} + var v uint64 + switch param.Type { + case nl.DEVLINK_PARAM_TYPE_U8: + v, err = strconv.ParseUint(value, 10, 8) + typedValue = uint8(v) + case nl.DEVLINK_PARAM_TYPE_U16: + v, err = strconv.ParseUint(value, 10, 16) + typedValue = uint16(v) + case nl.DEVLINK_PARAM_TYPE_U32: + v, err = strconv.ParseUint(value, 10, 32) + typedValue = uint32(v) + case nl.DEVLINK_PARAM_TYPE_STRING: + err = nil + typedValue = value + case nl.DEVLINK_PARAM_TYPE_BOOL: + typedValue, err = strconv.ParseBool(value) + default: + return fmt.Errorf("parameter has unknown value type: %d", param.Type) + } + if err != nil { + err = fmt.Errorf("failed to convert value %s to the required type: %T, devlink paramType is: %d", value, typedValue, param.Type) + funcLog.Error(err, "SetDevlinkDeviceParam(): error") + return err + } + if err := n.netlinkLib.DevlinkSetDeviceParam(consts.BusPci, pciAddr, paramName, targetCMOD, typedValue); err != nil { + funcLog.Error(err, "SetDevlinkDeviceParam(): failed to set parameter") + return err + } + return nil +} diff --git a/pkg/host/internal/network/network_test.go b/pkg/host/internal/network/network_test.go new file mode 100644 index 000000000..cd604aeae --- /dev/null +++ b/pkg/host/internal/network/network_test.go @@ -0,0 +1,155 @@ +package network + +import ( + "fmt" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "github.com/vishvananda/netlink" + "github.com/vishvananda/netlink/nl" + + "github.com/golang/mock/gomock" + + hostMockPkg "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/helper/mock" + dputilsMockPkg "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/internal/lib/dputils/mock" + netlinkMockPkg "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/internal/lib/netlink/mock" + "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host/types" +) + +func getDevlinkParam(t uint8, value interface{}) *netlink.DevlinkParam { + return &netlink.DevlinkParam{ + Name: "test_param", + Type: t, + Values: []netlink.DevlinkParamValue{ + {Data: value, CMODE: nl.DEVLINK_PARAM_CMODE_DRIVERINIT}}, + } +} + +var _ = Describe("Network", func() { + var ( + n types.NetworkInterface + netlinkLibMock *netlinkMockPkg.MockNetlinkLib + dputilsLibMock *dputilsMockPkg.MockDPUtilsLib + hostMock *hostMockPkg.MockHostHelpersInterface + + testCtrl *gomock.Controller + testErr = fmt.Errorf("test") + ) + BeforeEach(func() { + testCtrl = gomock.NewController(GinkgoT()) + netlinkLibMock = netlinkMockPkg.NewMockNetlinkLib(testCtrl) + dputilsLibMock = dputilsMockPkg.NewMockDPUtilsLib(testCtrl) + hostMock = hostMockPkg.NewMockHostHelpersInterface(testCtrl) + + n = New(hostMock, dputilsLibMock, netlinkLibMock) + }) + + AfterEach(func() { + testCtrl.Finish() + }) + Context("GetDevlinkDeviceParam", func() { + It("get - string", func() { + netlinkLibMock.EXPECT().DevlinkGetDeviceParamByName("pci", "0000:d8:00.1", "param_name").Return( + getDevlinkParam(nl.DEVLINK_PARAM_TYPE_STRING, "test_value"), nil) + result, err := n.GetDevlinkDeviceParam("0000:d8:00.1", "param_name") + Expect(err).NotTo(HaveOccurred()) + Expect(result).To(Equal("test_value")) + }) + It("get - uint8", func() { + netlinkLibMock.EXPECT().DevlinkGetDeviceParamByName("pci", "0000:d8:00.1", "param_name").Return( + getDevlinkParam(nl.DEVLINK_PARAM_TYPE_U8, uint8(8)), nil) + result, err := n.GetDevlinkDeviceParam("0000:d8:00.1", "param_name") + Expect(err).NotTo(HaveOccurred()) + Expect(result).To(Equal("8")) + }) + It("get - uint16", func() { + netlinkLibMock.EXPECT().DevlinkGetDeviceParamByName("pci", "0000:d8:00.1", "param_name").Return( + getDevlinkParam(nl.DEVLINK_PARAM_TYPE_U16, uint16(16)), nil) + result, err := n.GetDevlinkDeviceParam("0000:d8:00.1", "param_name") + Expect(err).NotTo(HaveOccurred()) + Expect(result).To(Equal("16")) + }) + It("get - uint32", func() { + netlinkLibMock.EXPECT().DevlinkGetDeviceParamByName("pci", "0000:d8:00.1", "param_name").Return( + getDevlinkParam(nl.DEVLINK_PARAM_TYPE_U32, uint32(32)), nil) + result, err := n.GetDevlinkDeviceParam("0000:d8:00.1", "param_name") + Expect(err).NotTo(HaveOccurred()) + Expect(result).To(Equal("32")) + }) + It("get - bool", func() { + netlinkLibMock.EXPECT().DevlinkGetDeviceParamByName("pci", "0000:d8:00.1", "param_name").Return( + getDevlinkParam(nl.DEVLINK_PARAM_TYPE_BOOL, false), nil) + result, err := n.GetDevlinkDeviceParam("0000:d8:00.1", "param_name") + Expect(err).NotTo(HaveOccurred()) + Expect(result).To(Equal("false")) + }) + It("failed", func() { + netlinkLibMock.EXPECT().DevlinkGetDeviceParamByName("pci", "0000:d8:00.1", "param_name").Return(nil, testErr) + _, err := n.GetDevlinkDeviceParam("0000:d8:00.1", "param_name") + Expect(err).To(HaveOccurred()) + }) + }) + Context("SetDevlinkDeviceParam", func() { + It("set - string", func() { + netlinkLibMock.EXPECT().DevlinkGetDeviceParamByName("pci", "0000:d8:00.1", "param_name").Return( + getDevlinkParam(nl.DEVLINK_PARAM_TYPE_STRING, "test_value"), nil) + netlinkLibMock.EXPECT().DevlinkSetDeviceParam("pci", "0000:d8:00.1", "param_name", + uint8(nl.DEVLINK_PARAM_CMODE_DRIVERINIT), "test_value").Return(nil) + err := n.SetDevlinkDeviceParam("0000:d8:00.1", "param_name", "test_value") + Expect(err).NotTo(HaveOccurred()) + }) + It("set - uint8", func() { + netlinkLibMock.EXPECT().DevlinkGetDeviceParamByName("pci", "0000:d8:00.1", "param_name").Return( + getDevlinkParam(nl.DEVLINK_PARAM_TYPE_U8, uint8(8)), nil) + netlinkLibMock.EXPECT().DevlinkSetDeviceParam("pci", "0000:d8:00.1", "param_name", + uint8(nl.DEVLINK_PARAM_CMODE_DRIVERINIT), uint8(100)).Return(nil) + err := n.SetDevlinkDeviceParam("0000:d8:00.1", "param_name", "100") + Expect(err).NotTo(HaveOccurred()) + }) + It("set - uint16", func() { + netlinkLibMock.EXPECT().DevlinkGetDeviceParamByName("pci", "0000:d8:00.1", "param_name").Return( + getDevlinkParam(nl.DEVLINK_PARAM_TYPE_U16, uint16(16)), nil) + netlinkLibMock.EXPECT().DevlinkSetDeviceParam("pci", "0000:d8:00.1", "param_name", + uint8(nl.DEVLINK_PARAM_CMODE_DRIVERINIT), uint16(100)).Return(nil) + err := n.SetDevlinkDeviceParam("0000:d8:00.1", "param_name", "100") + Expect(err).NotTo(HaveOccurred()) + }) + It("set - uint32", func() { + netlinkLibMock.EXPECT().DevlinkGetDeviceParamByName("pci", "0000:d8:00.1", "param_name").Return( + getDevlinkParam(nl.DEVLINK_PARAM_TYPE_U32, uint32(32)), nil) + netlinkLibMock.EXPECT().DevlinkSetDeviceParam("pci", "0000:d8:00.1", "param_name", + uint8(nl.DEVLINK_PARAM_CMODE_DRIVERINIT), uint32(100)).Return(nil) + err := n.SetDevlinkDeviceParam("0000:d8:00.1", "param_name", "100") + Expect(err).NotTo(HaveOccurred()) + }) + It("set - bool", func() { + netlinkLibMock.EXPECT().DevlinkGetDeviceParamByName("pci", "0000:d8:00.1", "param_name").Return( + getDevlinkParam(nl.DEVLINK_PARAM_TYPE_BOOL, false), nil) + netlinkLibMock.EXPECT().DevlinkSetDeviceParam("pci", "0000:d8:00.1", "param_name", + uint8(nl.DEVLINK_PARAM_CMODE_DRIVERINIT), true).Return(nil) + err := n.SetDevlinkDeviceParam("0000:d8:00.1", "param_name", "true") + Expect(err).NotTo(HaveOccurred()) + }) + It("failed to get", func() { + netlinkLibMock.EXPECT().DevlinkGetDeviceParamByName("pci", "0000:d8:00.1", "param_name").Return( + nil, testErr) + err := n.SetDevlinkDeviceParam("0000:d8:00.1", "param_name", "true") + Expect(err).To(HaveOccurred()) + }) + It("failed to set", func() { + netlinkLibMock.EXPECT().DevlinkGetDeviceParamByName("pci", "0000:d8:00.1", "param_name").Return( + getDevlinkParam(nl.DEVLINK_PARAM_TYPE_BOOL, false), nil) + netlinkLibMock.EXPECT().DevlinkSetDeviceParam("pci", "0000:d8:00.1", "param_name", + uint8(nl.DEVLINK_PARAM_CMODE_DRIVERINIT), true).Return(testErr) + err := n.SetDevlinkDeviceParam("0000:d8:00.1", "param_name", "true") + Expect(err).To(HaveOccurred()) + }) + It("failed to convert type on set", func() { + netlinkLibMock.EXPECT().DevlinkGetDeviceParamByName("pci", "0000:d8:00.1", "param_name").Return( + getDevlinkParam(nl.DEVLINK_PARAM_TYPE_U8, 10), nil) + // uint8 overflow + err := n.SetDevlinkDeviceParam("0000:d8:00.1", "param_name", "10000") + Expect(err).To(HaveOccurred()) + }) + }) +}) diff --git a/pkg/host/internal/network/suite_test.go b/pkg/host/internal/network/suite_test.go new file mode 100644 index 000000000..b990eb503 --- /dev/null +++ b/pkg/host/internal/network/suite_test.go @@ -0,0 +1,21 @@ +package network + +import ( + "testing" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + "go.uber.org/zap/zapcore" + "sigs.k8s.io/controller-runtime/pkg/log" + "sigs.k8s.io/controller-runtime/pkg/log/zap" +) + +func TestNetwork(t *testing.T) { + log.SetLogger(zap.New( + zap.WriteTo(GinkgoWriter), + zap.Level(zapcore.Level(-2)), + zap.UseDevMode(true))) + RegisterFailHandler(Fail) + RunSpecs(t, "Package Network Suite") +} diff --git a/pkg/host/mock/mock_host.go b/pkg/host/mock/mock_host.go index ea69d9f42..992a813b9 100644 --- a/pkg/host/mock/mock_host.go +++ b/pkg/host/mock/mock_host.go @@ -268,6 +268,21 @@ func (mr *MockHostManagerInterfaceMockRecorder) GetCurrentKernelArgs() *gomock.C return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCurrentKernelArgs", reflect.TypeOf((*MockHostManagerInterface)(nil).GetCurrentKernelArgs)) } +// GetDevlinkDeviceParam mocks base method. +func (m *MockHostManagerInterface) GetDevlinkDeviceParam(pciAddr, paramName string) (string, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetDevlinkDeviceParam", pciAddr, paramName) + ret0, _ := ret[0].(string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetDevlinkDeviceParam indicates an expected call of GetDevlinkDeviceParam. +func (mr *MockHostManagerInterfaceMockRecorder) GetDevlinkDeviceParam(pciAddr, paramName interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDevlinkDeviceParam", reflect.TypeOf((*MockHostManagerInterface)(nil).GetDevlinkDeviceParam), pciAddr, paramName) +} + // GetDriverByBusAndDevice mocks base method. func (m *MockHostManagerInterface) GetDriverByBusAndDevice(bus, device string) (string, error) { m.ctrl.T.Helper() @@ -772,6 +787,20 @@ func (mr *MockHostManagerInterfaceMockRecorder) ResetSriovDevice(ifaceStatus int return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ResetSriovDevice", reflect.TypeOf((*MockHostManagerInterface)(nil).ResetSriovDevice), ifaceStatus) } +// SetDevlinkDeviceParam mocks base method. +func (m *MockHostManagerInterface) SetDevlinkDeviceParam(pciAddr, paramName, value string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SetDevlinkDeviceParam", pciAddr, paramName, value) + ret0, _ := ret[0].(error) + return ret0 +} + +// SetDevlinkDeviceParam indicates an expected call of SetDevlinkDeviceParam. +func (mr *MockHostManagerInterfaceMockRecorder) SetDevlinkDeviceParam(pciAddr, paramName, value interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetDevlinkDeviceParam", reflect.TypeOf((*MockHostManagerInterface)(nil).SetDevlinkDeviceParam), pciAddr, paramName, value) +} + // SetNetdevMTU mocks base method. func (m *MockHostManagerInterface) SetNetdevMTU(pciAddr string, mtu int) error { m.ctrl.T.Helper() diff --git a/pkg/host/types/interfaces.go b/pkg/host/types/interfaces.go index be0c824ad..06a9aedac 100644 --- a/pkg/host/types/interfaces.go +++ b/pkg/host/types/interfaces.go @@ -97,6 +97,13 @@ type NetworkInterface interface { GetNetDevMac(name string) string // GetNetDevLinkSpeed returns the network interface link speed GetNetDevLinkSpeed(name string) string + // GetDevlinkDeviceParam returns devlink parameter for the device as a string, if the parameter has multiple values + // then the function will return only first one from the list. + GetDevlinkDeviceParam(pciAddr, paramName string) (string, error) + // SetDevlinkDeviceParam set devlink parameter for the device, accepts paramName and value + // as a string. Automatically set CMODE for the parameter and converts the value to the right + // type before submitting it. + SetDevlinkDeviceParam(pciAddr, paramName, value string) error } type ServiceInterface interface {