Add the ability to set any mode/lb on bonds
This requires a schema change, adding 'mode' and 'load-balance' fields, a semantic invariant that 'load-balance' can only be set in the case of LACP and XOR bonds, a mapper from the mode/lb strings, ie. "round-robin" to their VPP numeric counterparts, a bunch of unit tests. Then in the reconciler, changing bonds (__bond_has_diff()) will invalidate any LCP or sub-interfaces built on them, so those will have to be pruned. create_bondethernet() will now create (or re-create) the bond with the correct flags. Unit-tests, YAML tests and the integration test all pass. Updated config-guide.
This commit is contained in:
@ -52,6 +52,70 @@ def is_bond_member(yaml, ifname):
|
||||
return False
|
||||
|
||||
|
||||
def get_mode(yaml, ifname):
|
||||
""" Return the mode of the BondEthernet as a string, defaulting to 'lacp'
|
||||
if no mode is given. Return None if the bond interface doesn't exist.
|
||||
|
||||
Return values: 'round-robin','active-backup','broadcast','lacp','xor'
|
||||
"""
|
||||
ifname, iface = get_by_name(yaml, ifname)
|
||||
if not iface:
|
||||
return None
|
||||
|
||||
if not 'mode' in iface:
|
||||
return 'lacp'
|
||||
return iface['mode']
|
||||
|
||||
|
||||
def mode_to_int(mode):
|
||||
""" Returns the integer representation in VPP of a given bondethernet mode,
|
||||
or -1 if 'mode' is not a valid string.
|
||||
|
||||
See src/vnet/bonding/bond.api and schema.yaml for valid pairs. """
|
||||
|
||||
ret = { 'round-robin': 1, 'active-backup': 2, 'xor': 3, 'broadcast': 4, 'lacp': 5 }
|
||||
try:
|
||||
return ret[mode]
|
||||
except:
|
||||
pass
|
||||
return -1
|
||||
|
||||
|
||||
def get_lb(yaml, ifname):
|
||||
""" Return the loadbalance strategy of the BondEthernet as a string. Only
|
||||
'xor' and 'lacp' modes have loadbalance strategies, so return None if
|
||||
those modes are not used.
|
||||
|
||||
Return values: 'l2', 'l23', 'l34', with 'l34' being the default if
|
||||
the bond is in xor/lacp mode without a load-balance strategy set
|
||||
explicitly."""
|
||||
ifname, iface = get_by_name(yaml, ifname)
|
||||
if not iface:
|
||||
return None
|
||||
mode = get_mode(yaml, ifname)
|
||||
if not mode in ['xor','lacp']:
|
||||
return None
|
||||
|
||||
if not 'load-balance' in iface:
|
||||
return 'l34'
|
||||
return iface['load-balance']
|
||||
|
||||
|
||||
def lb_to_int(lb):
|
||||
""" Returns the integer representation in VPP of a given load-balance strategy,
|
||||
or -1 if 'lb' is not a valid string.
|
||||
|
||||
See src/vnet/bonding/bond.api and schema.yaml for valid pairs, although
|
||||
bond.api defined more than we use in vppcfg. """
|
||||
|
||||
ret = { 'l2': 0, 'l34': 1, 'l23': 2, 'round-robin': 3, 'broadcast': 4, 'active-backup': 5 }
|
||||
try:
|
||||
return ret[lb]
|
||||
except:
|
||||
pass
|
||||
return -1
|
||||
|
||||
|
||||
def validate_bondethernets(yaml):
|
||||
result = True
|
||||
msgs = []
|
||||
@ -74,6 +138,9 @@ def validate_bondethernets(yaml):
|
||||
if instance > 4294967294:
|
||||
msgs.append("bondethernet %s has instance %d which is too large" % (ifname, instance))
|
||||
result = False
|
||||
if not get_mode(yaml, bond_ifname) in ['xor','lacp'] and 'load-balance' in iface:
|
||||
msgs.append("bondethernet %s can only have load-balance if in mode XOR or LACP" % (ifname))
|
||||
result = False
|
||||
|
||||
for member in iface['interfaces']:
|
||||
if (None, None) == interface.get_by_name(yaml, member):
|
||||
|
@ -31,7 +31,34 @@ class TestBondEthernetMethods(unittest.TestCase):
|
||||
|
||||
def test_enumerators(self):
|
||||
ifs = bondethernet.get_bondethernets(self.cfg)
|
||||
self.assertEqual(len(ifs), 1)
|
||||
self.assertEqual(len(ifs), 3)
|
||||
self.assertIn("BondEthernet0", ifs)
|
||||
self.assertIn("BondEthernet1", ifs)
|
||||
self.assertIn("BondEthernet2", ifs)
|
||||
self.assertNotIn("BondEthernet-noexist", ifs)
|
||||
|
||||
def test_get_mode(self):
|
||||
self.assertEqual('lacp', bondethernet.get_mode(self.cfg, "BondEthernet0"))
|
||||
self.assertEqual('xor', bondethernet.get_mode(self.cfg, "BondEthernet1"))
|
||||
|
||||
def test_mode_to_int(self):
|
||||
self.assertEqual(1, bondethernet.mode_to_int("round-robin"))
|
||||
self.assertEqual(2, bondethernet.mode_to_int("active-backup"))
|
||||
self.assertEqual(3, bondethernet.mode_to_int("xor"))
|
||||
self.assertEqual(4, bondethernet.mode_to_int("broadcast"))
|
||||
self.assertEqual(5, bondethernet.mode_to_int("lacp"))
|
||||
self.assertEqual(-1, bondethernet.mode_to_int("not-exist"))
|
||||
|
||||
def test_get_lb(self):
|
||||
self.assertEqual('l34', bondethernet.get_lb(self.cfg, "BondEthernet0"))
|
||||
self.assertEqual('l2', bondethernet.get_lb(self.cfg, "BondEthernet1"))
|
||||
self.assertIsNone(bondethernet.get_lb(self.cfg, "BondEthernet2"))
|
||||
|
||||
def test_lb_to_int(self):
|
||||
self.assertEqual(0, bondethernet.lb_to_int("l2"))
|
||||
self.assertEqual(1, bondethernet.lb_to_int("l34"))
|
||||
self.assertEqual(2, bondethernet.lb_to_int("l23"))
|
||||
self.assertEqual(3, bondethernet.lb_to_int("round-robin"))
|
||||
self.assertEqual(4, bondethernet.lb_to_int("broadcast"))
|
||||
self.assertEqual(5, bondethernet.lb_to_int("active-backup"))
|
||||
self.assertEqual(-1, bondethernet.lb_to_int("not-exist"))
|
||||
|
Reference in New Issue
Block a user