2018-11-18 19:01:52 +00:00
|
|
|
// +build linux
|
|
|
|
|
|
|
|
package netlink
|
|
|
|
|
|
|
|
import (
|
2021-04-03 09:27:23 +00:00
|
|
|
"flag"
|
2021-04-03 11:24:35 +00:00
|
|
|
"net"
|
|
|
|
"testing"
|
2018-11-18 19:01:52 +00:00
|
|
|
)
|
|
|
|
|
2019-03-24 00:25:57 +00:00
|
|
|
func TestDevLinkGetDeviceList(t *testing.T) {
|
|
|
|
minKernelRequired(t, 4, 12)
|
|
|
|
setUpNetlinkTestWithKModule(t, "devlink")
|
|
|
|
_, err := DevLinkGetDeviceList()
|
2018-11-18 19:01:52 +00:00
|
|
|
if err != nil {
|
2019-03-24 00:25:57 +00:00
|
|
|
t.Fatal(err)
|
2018-11-18 19:01:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-24 00:25:57 +00:00
|
|
|
func TestDevLinkGetDeviceByName(t *testing.T) {
|
2018-11-18 19:01:52 +00:00
|
|
|
minKernelRequired(t, 4, 12)
|
|
|
|
setUpNetlinkTestWithKModule(t, "devlink")
|
2019-03-24 00:25:57 +00:00
|
|
|
_, err := DevLinkGetDeviceByName("foo", "bar")
|
2018-11-18 19:01:52 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
2019-03-24 01:41:55 +00:00
|
|
|
|
|
|
|
func TestDevLinkSetEswitchMode(t *testing.T) {
|
|
|
|
minKernelRequired(t, 4, 12)
|
|
|
|
setUpNetlinkTestWithKModule(t, "devlink")
|
|
|
|
dev, err := DevLinkGetDeviceByName("foo", "bar")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
err = DevLinkSetEswitchMode(dev, "switchdev")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
err = DevLinkSetEswitchMode(dev, "legacy")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
2020-06-15 09:05:23 +00:00
|
|
|
|
|
|
|
func TestDevLinkGetAllPortList(t *testing.T) {
|
|
|
|
minKernelRequired(t, 5, 4)
|
|
|
|
ports, err := DevLinkGetAllPortList()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
t.Log("devlink port count = ", len(ports))
|
|
|
|
for _, port := range ports {
|
|
|
|
t.Log(*port)
|
|
|
|
}
|
|
|
|
}
|
2020-06-15 09:32:49 +00:00
|
|
|
|
2021-04-03 09:27:23 +00:00
|
|
|
func TestDevLinkAddDelSfPort(t *testing.T) {
|
|
|
|
var addAttrs DevLinkPortAddAttrs
|
|
|
|
minKernelRequired(t, 5, 13)
|
|
|
|
if bus == "" || device == "" {
|
|
|
|
t.Log("devlink bus and device are empty, skipping test")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
dev, err := DevLinkGetDeviceByName(bus, device)
|
2020-06-15 09:32:49 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
2021-04-03 09:27:23 +00:00
|
|
|
return
|
2020-06-15 09:32:49 +00:00
|
|
|
}
|
2021-04-03 09:27:23 +00:00
|
|
|
addAttrs.SfNumberValid = true
|
|
|
|
addAttrs.SfNumber = uint32(sfnum)
|
|
|
|
addAttrs.PfNumber = 0
|
|
|
|
port, err2 := DevLinkPortAdd(dev.BusName, dev.DeviceName, 7, addAttrs)
|
|
|
|
if err2 != nil {
|
|
|
|
t.Fatal(err2)
|
|
|
|
return
|
2020-06-15 09:32:49 +00:00
|
|
|
}
|
2021-04-03 09:27:23 +00:00
|
|
|
t.Log(*port)
|
|
|
|
if port.Fn != nil {
|
2021-04-03 11:24:35 +00:00
|
|
|
t.Log("function attributes = ", *port.Fn)
|
|
|
|
}
|
|
|
|
err2 = DevLinkPortDel(dev.BusName, dev.DeviceName, port.PortIndex)
|
|
|
|
if err2 != nil {
|
|
|
|
t.Fatal(err2)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDevLinkSfPortFnSet(t *testing.T) {
|
|
|
|
var addAttrs DevLinkPortAddAttrs
|
|
|
|
var stateAttr DevlinkPortFnSetAttrs
|
|
|
|
|
|
|
|
minKernelRequired(t, 5, 12)
|
|
|
|
if bus == "" || device == "" {
|
|
|
|
t.Log("devlink bus and device are empty, skipping test")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
dev, err := DevLinkGetDeviceByName(bus, device)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
addAttrs.SfNumberValid = true
|
|
|
|
addAttrs.SfNumber = uint32(sfnum)
|
|
|
|
addAttrs.PfNumber = 0
|
|
|
|
port, err2 := DevLinkPortAdd(dev.BusName, dev.DeviceName, 7, addAttrs)
|
|
|
|
if err2 != nil {
|
|
|
|
t.Fatal(err2)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
t.Log(*port)
|
|
|
|
if port.Fn != nil {
|
|
|
|
t.Log("function attributes = ", *port.Fn)
|
|
|
|
}
|
|
|
|
macAttr := DevlinkPortFnSetAttrs{
|
|
|
|
FnAttrs: DevlinkPortFn{
|
|
|
|
HwAddr: net.HardwareAddr{0x00, 0x11, 0x22, 0x33, 0x44, 0x55},
|
|
|
|
},
|
|
|
|
HwAddrValid: true,
|
|
|
|
}
|
|
|
|
err2 = DevlinkPortFnSet(dev.BusName, dev.DeviceName, port.PortIndex, macAttr)
|
|
|
|
if err2 != nil {
|
|
|
|
t.Log("function mac set err = ", err2)
|
|
|
|
}
|
|
|
|
stateAttr.FnAttrs.State = 1
|
|
|
|
stateAttr.StateValid = true
|
|
|
|
err2 = DevlinkPortFnSet(dev.BusName, dev.DeviceName, port.PortIndex, stateAttr)
|
|
|
|
if err2 != nil {
|
|
|
|
t.Log("function state set err = ", err2)
|
|
|
|
}
|
|
|
|
|
|
|
|
port, err3 := DevLinkGetPortByIndex(dev.BusName, dev.DeviceName, port.PortIndex)
|
|
|
|
if err3 == nil {
|
|
|
|
t.Log(*port)
|
|
|
|
t.Log(*port.Fn)
|
2021-04-03 09:27:23 +00:00
|
|
|
}
|
|
|
|
err2 = DevLinkPortDel(dev.BusName, dev.DeviceName, port.PortIndex)
|
|
|
|
if err2 != nil {
|
|
|
|
t.Fatal(err2)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var bus string
|
|
|
|
var device string
|
|
|
|
var sfnum uint
|
|
|
|
|
|
|
|
func init() {
|
2021-04-03 11:24:35 +00:00
|
|
|
flag.StringVar(&bus, "bus", "", "devlink device bus name")
|
|
|
|
flag.StringVar(&device, "device", "", "devlink device devicename")
|
|
|
|
flag.UintVar(&sfnum, "sfnum", 0, "devlink port sfnumber")
|
2020-06-15 09:32:49 +00:00
|
|
|
}
|