Skip to content

Commit

Permalink
T6944: adds option to enable switchdev mode on ethernet interface
Browse files Browse the repository at this point in the history
  • Loading branch information
nvollmar committed Dec 13, 2024
1 parent 4221687 commit f0fbec7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
6 changes: 6 additions & 0 deletions interface-definitions/interfaces_ethernet.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@
</properties>
<defaultValue>auto</defaultValue>
</leafNode>
<leafNode name="switchdev">
<properties>
<help>Enables switchdev mode on interface</help>
<valueless/>
</properties>
</leafNode>
#include <include/interface/eapol.xml.i>
<node name="evpn">
<properties>
Expand Down
27 changes: 27 additions & 0 deletions python/vyos/ifconfig/ethernet.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# License along with this library. If not, see <http://www.gnu.org/licenses/>.

import os
import re

from glob import glob

Expand Down Expand Up @@ -417,12 +418,38 @@ def set_ring_buffer(self, rx_tx, size):
print(f'could not set "{rx_tx}" ring-buffer for {ifname}')
return output

def set_switchdev(self, enable):
ifname = self.config['ifname']
if not bool(re.match(r"^eth[0-9]+$", ifname)):
print(f'switchdev mode is only possible on physical interfaces!')
return

addr, code = self._popen(f'ethtool -i {ifname} | grep bus-info | awk \'{{print $2}}\'')
if code != 0:
print(f'could not resolve PCIe address of {ifname}')
return

enabled = False
state, code = self._popen(f'devlink dev eswitch show pci/0000:01:00.1 | awk \'{{print $3}}\'')
if code == 0 and state == 'switchdev':
enabled = True

if enable and not enabled:
output, code = self._popen(f'/sbin/devlink dev eswitch set pci/{addr} mode switchdev')
if code != 0:
raise ConfigError(f'{ifname} does not support switchdev mode')
elif not enable and enabled:
self._cmd(f'/sbin/devlink dev eswitch set pci/{addr} mode legacy')

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
interface setup code and provide a single point of entry when workin
on any interface. """

# enable switchdev mode for additional offload options
self.set_switchdev('switchdev' in config)

# disable ethernet flow control (pause frames)
value = 'off' if 'disable_flow_control' in config else 'on'
self.set_flow_control(value)
Expand Down
10 changes: 10 additions & 0 deletions smoketest/scripts/cli/test_interfaces_ethernet.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,5 +222,15 @@ def test_ethtool_evpn_uplink_tarcking(self):
frrconfig = self.getFRRconfig(f'interface {interface}', daemon='zebra')
self.assertIn(f' evpn mh uplink', frrconfig)

def test_switchdev(self):
interface = self._interfaces[0]
self.cli_set(self._base_path + [interface, 'switchdev'])

# check validate() - virtual interfaces do not support switchdev
with self.assertRaises(ConfigSessionError):
self.cli_commit()

self.cli_delete(self._base_path + [interface, 'switchdev'])

if __name__ == '__main__':
unittest.main(verbosity=2)

0 comments on commit f0fbec7

Please sign in to comment.