Add extra bond parameters

Add bond parameters corresponding to:

* IFLA_BOND_AD_ACTOR_SYS_PRIO
* IFLA_BOND_AD_USER_PORT_KEY
* IFLA_BOND_AD_ACTOR_SYSTEM
* IFLA_BOND_TLB_DYNAMIC_LB

These are available in new(ish) kernels.
This commit is contained in:
Stuart McLaren 2017-05-30 17:44:38 +01:00 committed by Vish Ishaya
parent 7d9b424492
commit 7bd45e5974
4 changed files with 72 additions and 4 deletions

10
link.go
View File

@ -593,7 +593,11 @@ type Bond struct {
LacpRate BondLacpRate
AdSelect BondAdSelect
// looking at iproute tool AdInfo can only be retrived. It can't be set.
AdInfo *BondAdInfo
AdInfo *BondAdInfo
AdActorSysPrio int
AdUserPortKey int
AdActorSystem net.HardwareAddr
TlbDynamicLb int
}
func NewLinkBond(atr LinkAttrs) *Bond {
@ -621,6 +625,10 @@ func NewLinkBond(atr LinkAttrs) *Bond {
PackersPerSlave: -1,
LacpRate: -1,
AdSelect: -1,
AdActorSysPrio: -1,
AdUserPortKey: -1,
AdActorSystem: nil,
TlbDynamicLb: -1,
}
}

View File

@ -669,6 +669,18 @@ func addBondAttrs(bond *Bond, linkInfo *nl.RtAttr) {
if bond.AdSelect >= 0 {
nl.NewRtAttrChild(data, nl.IFLA_BOND_AD_SELECT, nl.Uint8Attr(uint8(bond.AdSelect)))
}
if bond.AdActorSysPrio >= 0 {
nl.NewRtAttrChild(data, nl.IFLA_BOND_AD_ACTOR_SYS_PRIO, nl.Uint16Attr(uint16(bond.AdActorSysPrio)))
}
if bond.AdUserPortKey >= 0 {
nl.NewRtAttrChild(data, nl.IFLA_BOND_AD_USER_PORT_KEY, nl.Uint16Attr(uint16(bond.AdUserPortKey)))
}
if bond.AdActorSystem != nil {
nl.NewRtAttrChild(data, nl.IFLA_BOND_AD_ACTOR_SYSTEM, []byte(bond.AdActorSystem))
}
if bond.TlbDynamicLb >= 0 {
nl.NewRtAttrChild(data, nl.IFLA_BOND_TLB_DYNAMIC_LB, nl.Uint8Attr(uint8(bond.TlbDynamicLb)))
}
}
// LinkAdd adds a new link device. The type and features of the device
@ -1463,6 +1475,14 @@ func parseBondData(link Link, data []syscall.NetlinkRouteAttr) {
bond.AdSelect = BondAdSelect(data[i].Value[0])
case nl.IFLA_BOND_AD_INFO:
// TODO: implement
case nl.IFLA_BOND_AD_ACTOR_SYS_PRIO:
bond.AdActorSysPrio = int(native.Uint16(data[i].Value[0:2]))
case nl.IFLA_BOND_AD_USER_PORT_KEY:
bond.AdUserPortKey = int(native.Uint16(data[i].Value[0:2]))
case nl.IFLA_BOND_AD_ACTOR_SYSTEM:
bond.AdActorSystem = net.HardwareAddr(data[i].Value[0:6])
case nl.IFLA_BOND_TLB_DYNAMIC_LB:
bond.TlbDynamicLb = int(data[i].Value[0])
}
}
}

View File

@ -136,6 +136,30 @@ func testLinkAddDel(t *testing.T, link Link) {
if bond.Mode != other.Mode {
t.Fatalf("Got unexpected mode: %d, expected: %d", other.Mode, bond.Mode)
}
// Mode specific checks
if os.Getenv("TRAVIS_BUILD_DIR") != "" {
t.Log("Kernel in travis is too old for this check")
} else {
switch mode := bondModeToString[bond.Mode]; mode {
case "802.3ad":
if bond.AdSelect != other.AdSelect {
t.Fatalf("Got unexpected AdSelect: %d, expected: %d", other.AdSelect, bond.AdSelect)
}
if bond.AdActorSysPrio != other.AdActorSysPrio {
t.Fatalf("Got unexpected AdActorSysPrio: %d, expected: %d", other.AdActorSysPrio, bond.AdActorSysPrio)
}
if bond.AdUserPortKey != other.AdUserPortKey {
t.Fatalf("Got unexpected AdUserPortKey: %d, expected: %d", other.AdUserPortKey, bond.AdUserPortKey)
}
if bytes.Compare(bond.AdActorSystem, other.AdActorSystem) != 0 {
t.Fatalf("Got unexpected AdActorSystem: %d, expected: %d", other.AdActorSystem, bond.AdActorSystem)
}
case "balance-tlb":
if bond.TlbDynamicLb != other.TlbDynamicLb {
t.Fatalf("Got unexpected TlbDynamicLb: %d, expected: %d", other.TlbDynamicLb, bond.TlbDynamicLb)
}
}
}
}
if _, ok := link.(*Iptun); ok {
@ -345,9 +369,21 @@ func TestLinkAddDelBond(t *testing.T) {
tearDown := setUpNetlinkTest(t)
defer tearDown()
bond := NewLinkBond(LinkAttrs{Name: "foo"})
bond.Mode = StringToBondModeMap["802.3ad"]
testLinkAddDel(t, bond)
modes := []string{"802.3ad", "balance-tlb"}
for _, mode := range modes {
bond := NewLinkBond(LinkAttrs{Name: "foo"})
bond.Mode = StringToBondModeMap[mode]
switch mode {
case "802.3ad":
bond.AdSelect = BondAdSelect(BOND_AD_SELECT_BANDWIDTH)
bond.AdActorSysPrio = 1
bond.AdUserPortKey = 1
bond.AdActorSystem, _ = net.ParseMAC("06:aa:bb:cc:dd:ee")
case "balance-tlb":
bond.TlbDynamicLb = 1
}
testLinkAddDel(t, bond)
}
}
func TestLinkAddVethWithDefaultTxQLen(t *testing.T) {

View File

@ -154,6 +154,10 @@ const (
IFLA_BOND_AD_LACP_RATE
IFLA_BOND_AD_SELECT
IFLA_BOND_AD_INFO
IFLA_BOND_AD_ACTOR_SYS_PRIO
IFLA_BOND_AD_USER_PORT_KEY
IFLA_BOND_AD_ACTOR_SYSTEM
IFLA_BOND_TLB_DYNAMIC_LB
)
const (