Skip to content

Commit

Permalink
Bond: T6303: add system mac address on bond
Browse files Browse the repository at this point in the history
  • Loading branch information
fett0 committed May 4, 2024
1 parent 2159dfd commit 0b38e99
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
12 changes: 12 additions & 0 deletions interface-definitions/interfaces_bonding.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,18 @@
</properties>
<defaultValue>0</defaultValue>
</leafNode>
<leafNode name="system-mac">
<properties>
<help>System MAC address for 802.3ad</help>
<valueHelp>
<format>macaddr</format>
<description>MAC address</description>
</valueHelp>
<constraint>
<validator name="mac-address"/>
</constraint>
</properties>
</leafNode>
<leafNode name="lacp-rate">
<properties>
<help>Rate in which we will ask our link partner to transmit LACPDU packets</help>
Expand Down
29 changes: 29 additions & 0 deletions python/vyos/ifconfig/bond.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from vyos.ifconfig.interface import Interface
from vyos.utils.dict import dict_search
from vyos.utils.assertion import assert_list
from vyos.utils.assertion import assert_mac
from vyos.utils.assertion import assert_positive

@Interface.register
Expand Down Expand Up @@ -54,6 +55,12 @@ class BondIf(Interface):
'validate': lambda v: assert_list(v, ['slow', 'fast']),
'location': '/sys/class/net/{ifname}/bonding/lacp_rate',
},

'bond_system_mac': {
'validate': assert_mac,
'location': '/sys/class/net/{ifname}/bonding/ad_actor_system',
},

'bond_miimon': {
'validate': assert_positive,
'location': '/sys/class/net/{ifname}/bonding/miimon'
Expand Down Expand Up @@ -385,6 +392,24 @@ def set_mode(self, mode):
"""
return self.set_interface('bond_mode', mode)

def set_system_mac(self, mac):
"""
In an AD system, this specifies the mac-address for the actor in
protocol packet exchanges (LACPDUs). The value cannot be NULL or
multicast. It is preferred to have the local-admin bit set for this
mac but driver does not enforce it. If the value is not given then
system defaults to using the masters' mac address as actors' system
address.
This parameter has effect only in 802.3ad mode and is available through
SysFs interface.
Example:
>>> from vyos.ifconfig import BondIf
>>> BondIf('bond0').set_system_mac('00:50:ab:cd:ef:01')
"""
return self.set_interface('bond_system_mac', mac)

def update(self, config):
""" General helper function which works on a dictionary retrived by
get_config_dict(). It's main intention is to consolidate the scattered
Expand Down Expand Up @@ -433,6 +458,10 @@ def update(self, config):
if mode == '802.3ad':
self.set_lacp_rate(config.get('lacp_rate'))

# Add system mac address for 802.3ad
if mode == '802.3ad' and 'system_mac' in config:
self.set_system_mac(config.get('system_mac'))

if mode not in ['802.3ad', 'balance-tlb', 'balance-alb']:
tmp = dict_search('arp_monitor.interval', config)
value = tmp if (tmp != None) else '0'
Expand Down
17 changes: 17 additions & 0 deletions smoketest/scripts/cli/test_interfaces_bonding.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,23 @@ def test_bonding_uniq_member_description(self):
for member in self._members:
self.assertIn(member, slaves)

def test_bonding_system_mac(self):
# configure member interfaces and system-mac
system_mac = '00:50:ab:cd:ef:11'
for interface in self._interfaces:
for option in self._options.get(interface, []):
self.cli_set(self._base_path + [interface] + option.split())

self.cli_set(self._base_path + [interface, 'system-mac', system_mac])

self.cli_commit()

# verify config
for interface in self._interfaces:
slaves = read_file(f'/sys/class/net/{interface}/bonding/slaves').split()
for member in self._members:
self.assertIn(member, slaves)

def test_bonding_evpn_multihoming(self):
id = '5'
for interface in self._interfaces:
Expand Down

0 comments on commit 0b38e99

Please sign in to comment.