diff options
| author | Christian Breunig <christian@breunig.cc> | 2026-03-04 20:30:20 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-04 20:30:20 +0100 |
| commit | 53488d0ef8ded005e75f853b6ca05342c3c8725d (patch) | |
| tree | caef839f6bb5f49ad6607a438755ca7585f6267c /python | |
| parent | ddaae274187916b3a7932372ee8944ddce8c5423 (diff) | |
| parent | d340acd74270728743807b1db4124b0fddcceec4 (diff) | |
| download | vyos-1x-53488d0ef8ded005e75f853b6ca05342c3c8725d.tar.gz vyos-1x-53488d0ef8ded005e75f853b6ca05342c3c8725d.zip | |
Merge pull request #5026 from natali-rs1985/T8339
vpp: T8339: Cleanup vpp interfaces and kernel-interfaces after migration
Diffstat (limited to 'python')
| -rw-r--r-- | python/vyos/vpp/config_verify.py | 70 | ||||
| -rw-r--r-- | python/vyos/vpp/interface/__init__.py | 28 | ||||
| -rw-r--r-- | python/vyos/vpp/interface/ethernet.py | 53 | ||||
| -rw-r--r-- | python/vyos/vpp/interface/geneve.py | 90 | ||||
| -rw-r--r-- | python/vyos/vpp/interface/interface.py | 49 | ||||
| -rw-r--r-- | python/vyos/vpp/interface/wireguard.py | 55 | ||||
| -rw-r--r-- | python/vyos/vpp/utils.py | 43 |
7 files changed, 0 insertions, 388 deletions
diff --git a/python/vyos/vpp/config_verify.py b/python/vyos/vpp/config_verify.py index d5bb70899..6f1774b2f 100644 --- a/python/vyos/vpp/config_verify.py +++ b/python/vyos/vpp/config_verify.py @@ -27,76 +27,6 @@ from vyos.vpp.config_resource_checks.resource_defaults import default_resource_m from vyos.vpp.utils import human_memory_to_bytes, bytes_to_human_memory -def verify_vpp_remove_kernel_interface(config: dict): - """Common verify for removed kernel-interfaces. - Verify that removed kernel interface are not used in 'vpp kernel-interfaces'. - - Example: - delete vpp interfaces gre|vxlan <tag>X kernel-interface vpp-tunX - set vpp kernel-interface vpp-tunX - """ - if ( - 'remove' in config - and 'kernel_interface_removed' in config - and 'vpp_kernel_interfaces' in config - ): - removed_interfaces = config['kernel_interface_removed'] - used_interfaces = config['vpp_kernel_interfaces'] - - for interface in removed_interfaces: - if interface in used_interfaces: - raise ConfigError( - f'"{interface}" is still in use within "vpp kernel-interfaces". ' - 'Please remove it before proceeding.' - ) - - -def verify_vpp_change_kernel_interface(config: dict): - """Common verify for changed kernel-interface - - Example: - set vpp interfaces gre|vxlan <tag> kernel-interface vpp-tunX' - commit - set vpp interfaces gre|vxlan <tag> kernel-interface vpp-tunY' - commit - - check if we have kernel interface config 'vpp kernel-interface vpp-tunX' - """ - kernel_interface_removed = config.get('kernel_interface_removed', []) - vpp_kernel_interfaces = config.get('vpp_kernel_interfaces', {}) - - for interface in kernel_interface_removed: - if interface in vpp_kernel_interfaces: - raise ConfigError( - f'interface "{interface}" is still in use within "vpp kernel-interfaces". ' - f'Please remove it "vpp kernel-interface {interface}" before proceeding.' - ) - - -def verify_vpp_exists_kernel_interface(config: dict): - """Verify is a kernel-interface already created by another VPP LCP pair - - Example: - set vpp interfaces vxlan vxlan10 kernel-interface vpp-tun10' - commit - set vpp interfaces vxlan vxlan20 kernel-interface vpp-tun10' - commit - """ - kernel_interface = config.get('kernel_interface', '') - vpp_interface = config.get('ifname', '') - candidate_kernel_interfaces = config.get('candidate_kernel_interfaces', []) - - for candidate_kernel_iface in candidate_kernel_interfaces: - if ( - vpp_interface != candidate_kernel_iface[0] - and kernel_interface == candidate_kernel_iface[1] - ): - raise ConfigError( - f'Kernel interface "{kernel_interface}" is already configured for {candidate_kernel_iface[0]}. ' - 'Duplicates are not allowed.' - ) - - def verify_vpp_remove_xconnect_interface(config: dict): if not 'deleted' in config: return diff --git a/python/vyos/vpp/interface/__init__.py b/python/vyos/vpp/interface/__init__.py deleted file mode 100644 index 3f8ae7954..000000000 --- a/python/vyos/vpp/interface/__init__.py +++ /dev/null @@ -1,28 +0,0 @@ -# -# Copyright (C) VyOS Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -from .ethernet import EthernetInterface -from .geneve import GeneveInterface -from .interface import Interface -from .wireguard import WireguardInterface - -__all__ = [ - 'EthernetInterface', - 'GeneveInterface', - 'Interface', - 'WireguardInterface', -] diff --git a/python/vyos/vpp/interface/ethernet.py b/python/vyos/vpp/interface/ethernet.py deleted file mode 100644 index 523211db8..000000000 --- a/python/vyos/vpp/interface/ethernet.py +++ /dev/null @@ -1,53 +0,0 @@ -# VyOS implementation of VPP Ethernet interface -# -# Copyright (C) VyOS Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -from vyos.vpp import VPPControl - - -class EthernetInterface: - """Interface Ethernet""" - - def __init__(self, ifname, kernel_interface: str = ''): - self.instance = int(ifname.removeprefix('eth')) - self.ifname = ifname - self.kernel_interface = kernel_interface - self.vpp = VPPControl() - - def add(self): - pass - - def delete(self): - pass - - def kernel_add(self): - """Add LCP pair - Example: - from vyos.vpp.interface import EthernetInterface - a = EthernetInterface(ifname='eth0') - a.kernel_add() - """ - self.vpp.lcp_pair_add(self.ifname, self.kernel_interface) - - def kernel_delete(self): - """Delete LCP pair - Example: - from vyos.vpp.interface import EthernetInterface - a = EthernetInterface(ifname='eth0') - a.kernel_delete() - """ - self.vpp.lcp_pair_del(self.ifname, self.kernel_interface) diff --git a/python/vyos/vpp/interface/geneve.py b/python/vyos/vpp/interface/geneve.py deleted file mode 100644 index 2d6347f12..000000000 --- a/python/vyos/vpp/interface/geneve.py +++ /dev/null @@ -1,90 +0,0 @@ -# VyOS implementation of Geneve interface -# -# Copyright (C) VyOS Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -from vyos.vpp import VPPControl - - -def show(): - """Show Geneve interface - Example: - from vyos.vpp.interface import geneve - geneve.show() - """ - vpp = VPPControl() - return vpp.api.geneve_tunnel_dump() - - -class GeneveInterface: - def __init__(self, ifname, source_address, remote, vni, kernel_interface: str = ''): - self.instance = int(ifname.removeprefix('geneve')) - self.ifname = f'geneve_tunnel{self.instance}' - self.src_address = source_address - self.dst_address = remote - self.vni = vni - self.kernel_interface = kernel_interface - self.vpp = VPPControl() - - def add(self): - """Create Geneve interface - https://github.com/FDio/vpp/blob/stable/2306/src/plugins/geneve/geneve.api - - Example: - from vyos.vpp.interface import GeneveInterface - a = GeneveInterface(ifname='geneve25', source_address='192.0.2.1', remote='203.0.113.25', vni=25) - a.add() - """ - return self.vpp.api.geneve_add_del_tunnel2( - is_add=True, - local_address=self.src_address, - remote_address=self.dst_address, - vni=self.vni, - l3_mode=False, - ) - - def delete(self): - """Delete Geneve interface - Example: - from vyos.vpp.interface import GeneveInterface - a = GeneveInterface(ifname='vxlan25', source_address='192.0.2.1', remote='203.0.113.25', vni=25) - a.delete() - """ - return self.vpp.api.geneve_add_del_tunnel2( - is_add=False, - local_address=self.src_address, - remote_address=self.dst_address, - vni=self.vni, - l3_mode=False, - ) - - def kernel_add(self): - """Add LCP pair - Example: - from vyos.vpp.interface import GeneveInterface - a = GeneveInterface(ifname='vxlan25', source_address='192.0.2.1', remote='203.0.113.25', vni=25) - a.kernel_add() - """ - self.vpp.lcp_pair_add(self.ifname, self.kernel_interface, 'tun') - - def kernel_delete(self): - """Delete LCP pair - Example: - from vyos.vpp.interface import GeneveInterface - a = GeneveInterface(ifname='vxlan25', source_address='192.0.2.1', remote='203.0.113.25', vni=25) - a.kernel_delete() - """ - self.vpp.lcp_pair_del(self.ifname, self.kernel_interface) diff --git a/python/vyos/vpp/interface/interface.py b/python/vyos/vpp/interface/interface.py deleted file mode 100644 index 05c1d14d6..000000000 --- a/python/vyos/vpp/interface/interface.py +++ /dev/null @@ -1,49 +0,0 @@ -# -# Copyright (C) VyOS Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -from vyos.vpp import VPPControl - - -class Interface: - def __init__(self, ifname): - self.ifname = ifname - self.vpp = VPPControl() - - def set_state(self, state: str): - """Set interface state to UP or DOWN - Args: - state (str): The state of the interface. Options are 'up' and 'down'. - Example: - from vyos.vpp.interface import Interface - a = Interface(ifname='eth0') - a.set_state(state='up') - """ - if state not in ['up', 'down']: - raise ValueError(f"Invalid state: {state}") - state_flag = 1 if state == 'up' else 0 - if_index = self.vpp.get_sw_if_index(self.ifname) - self.vpp.api.sw_interface_set_flags(sw_if_index=if_index, flags=state_flag) - - def get_state(self): - """Get interface state - Example: - from vyos.vpp.interface import Interface - a = Interface(ifname='eth0') - a.get_state() - """ - if_index = self.vpp.get_sw_if_index(self.ifname) - return self.vpp.api.sw_interface_dump(sw_if_index=if_index)[0]['flags'] diff --git a/python/vyos/vpp/interface/wireguard.py b/python/vyos/vpp/interface/wireguard.py deleted file mode 100644 index c2d36e1b0..000000000 --- a/python/vyos/vpp/interface/wireguard.py +++ /dev/null @@ -1,55 +0,0 @@ -# VyOS implementation of VPP Wireguard interface -# -# Copyright (C) VyOS Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -from vyos.vpp import VPPControl - - -class WireguardInterface: - """Interface Wireguard""" - - def __init__(self, ifname, listen_port=51820, kernel_interface: str = ''): - self.instance = int(ifname.removeprefix('wg')) - self.ifname = ifname - self.listen_port = listen_port - self.kernel_interface = kernel_interface - self.vpp = VPPControl() - - def add(self): - """Create Wireguard interface - https://github.com/FDio/vpp/blob/stable/2306/src/plugins/wireguard/wireguard.api - Example: - from vyos.vpp.interface import WireguardInterface - a = WireguardInterface(ifname='wg5', listen_port=51820, generate_key=True) - a.add() - """ - self.vpp.api.wireguard_interface_create( - generate_key=True, - interface={'user_instance': self.instance, 'listen_port': self.listen_port}, - ) - if self.kernel_interface: - self.vpp.lcp_pair_add(self.ifname, self.kernel_interface, 'tun') - - def delete(self): - """Delete Wireguard interface - Example: - from vyos.vpp.interface import WireguardInterface - a = WireguardInterface(ifname='wg5') - a.delete() - """ - wg_if_index = self.vpp.get_sw_if_index(f'wg{self.instance}') - return self.vpp.api.wireguard_interface_delete(sw_if_index=wg_if_index) diff --git a/python/vyos/vpp/utils.py b/python/vyos/vpp/utils.py index 5976b2189..0b514fd7c 100644 --- a/python/vyos/vpp/utils.py +++ b/python/vyos/vpp/utils.py @@ -104,11 +104,6 @@ def cli_ifaces_list(config_instance, mode: str = 'candidate') -> list[str]: for iface in config.get('settings', {}).get('interface', {}).keys(): vpp_ifaces.append(iface) - # Get a list of VPP interfaces - for iface_type in config.get('interfaces', {}).keys(): - for iface in config.get('interfaces', {}).get(iface_type, {}).keys(): - vpp_ifaces.append(iface) - # Get a list of interfaces VPP for iface_type in interfaces_config.keys(): for iface in interfaces_config.get(iface_type, {}).keys(): @@ -246,44 +241,6 @@ def vpp_ifaces_stats( return ifaces_stats -def cli_ifaces_lcp_kernel_list( - config_instance, mode: str = 'candidate' -) -> list[tuple[str, str]]: - """List of all VPP kernel-interfaces (CLI names, attached VPP interfaces) - - Args: - config_instance (VyOS Config): VyOS Config instance - mode (str, optional): `candidate` or `running`. Defaults to 'candidate'. - - Returns: - list[tuple[str, str]]: list of interfaces ([(vpp_iface, kernel_iface)]) - """ - - effective_mode: bool = True if mode == 'running' else False - - # Read a config - config = config_instance.get_config_dict( - ['vpp'], - key_mangling=('-', '_'), - effective=effective_mode, - get_first_key=True, - no_tag_node_value_mangle=True, - with_recursive_defaults=True, - ) - - lcp_kernel_ifaces: list[tuple[str, str]] = [] - - # Get a list with kernel interfaces - for ifaces_list in config.get('interfaces', {}).values(): - for iface_name, iface_settings in ifaces_list.items(): - if 'kernel_interface' in iface_settings: - lcp_kernel_ifaces.append( - (iface_name, iface_settings['kernel_interface']) - ) - - return lcp_kernel_ifaces - - def get_default_hugepage_size() -> int: """ Retrieve the system's default huge page size. |
