diff options
| author | Viacheslav Hletenko <v.gletenko@vyos.io> | 2026-03-02 17:21:21 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-02 17:21:21 +0200 |
| commit | 00361b88005948802344adbe6184057cee91cde4 (patch) | |
| tree | 76124d6c8502666c6fe91c2433ee938a2ef09feb /python | |
| parent | ef710a5acbd7af9f60ba63716912b0c9a20f5329 (diff) | |
| parent | 61d607295fa826e707b82432c46668a2fb94ab22 (diff) | |
| download | vyos-1x-00361b88005948802344adbe6184057cee91cde4.tar.gz vyos-1x-00361b88005948802344adbe6184057cee91cde4.zip | |
Merge pull request #5019 from natali-rs1985/T8324
vpp: T8324: Migrate loopback interface to 'interfaces vpp loopback'
Diffstat (limited to 'python')
| -rw-r--r-- | python/vyos/ifconfig/vpp/__init__.py | 2 | ||||
| -rw-r--r-- | python/vyos/ifconfig/vpp/loopback.py | 105 | ||||
| -rw-r--r-- | python/vyos/vpp/interface/__init__.py | 2 | ||||
| -rw-r--r-- | python/vyos/vpp/interface/loopback.py | 72 |
4 files changed, 107 insertions, 74 deletions
diff --git a/python/vyos/ifconfig/vpp/__init__.py b/python/vyos/ifconfig/vpp/__init__.py index a7cfe79a4..b0a477c28 100644 --- a/python/vyos/ifconfig/vpp/__init__.py +++ b/python/vyos/ifconfig/vpp/__init__.py @@ -18,11 +18,13 @@ from .bond import VPPBondInterface from .interface import VPPInterface from .ipip import VPPIPIPInterface +from .loopback import VPPLoopbackInterface from .vxlan import VPPVXLANInterface __all__ = [ 'VPPBondInterface', 'VPPInterface', 'VPPIPIPInterface', + 'VPPLoopbackInterface', 'VPPVXLANInterface', ] diff --git a/python/vyos/ifconfig/vpp/loopback.py b/python/vyos/ifconfig/vpp/loopback.py new file mode 100644 index 000000000..36a30cb58 --- /dev/null +++ b/python/vyos/ifconfig/vpp/loopback.py @@ -0,0 +1,105 @@ +# VyOS implementation of VPP Loopback 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.ifconfig import Interface +from vyos.ifconfig.vpp.interface import VPPInterface + + +class VPPLoopbackInterface(Interface, VPPInterface): + """Interface Loopback""" + + def __init__(self, ifname, config): + self.ifname = ifname + self.instance = int(ifname.removeprefix('vpplo')) + self.vpp_ifname = f'loop{self.instance}' + + # Initialize Interface (kernel) and VPP part + super().__init__(ifname) + VPPInterface.__init__(self, self.vpp_ifname) + + self.index = self.vpp.get_sw_if_index(self.vpp_ifname) + self.state = 'up' if 'disable' not in config else 'down' + + def _create(self): + pass + + def add(self): + """Create Loopback interface + https://github.com/FDio/vpp/blob/stable/2306/src/vnet/interface.api + Example: + from vyos.ifconfig.vpp import VPPLoopbackInterface + a = VPPLoopbackInterface(ifname='vpplo1', config) + a.add() + """ + self.vpp.api.create_loopback_instance( + is_specified=True, user_instance=self.instance + ) + # Add LCP pair (kernel) interface + self.kernel_add() + # Set interface state + self.set_state(self.state) + self.set_admin_state(self.state) + self.index = self.vpp.get_sw_if_index(self.vpp_ifname) + + def delete(self): + """Delete Loopback interface + Example: + from vyos.ifconfig.vpp import VPPLoopbackInterface + a = VPPLoopbackInterface(ifname='vpplo1', config) + a.delete() + """ + return self.vpp.api.delete_loopback(sw_if_index=self.index) + + def kernel_add(self): + """Add LCP pair + Example: + from vyos.ifconfig.vpp import VPPLoopbackInterface + a = VPPLoopbackInterface(ifname='vpplo1') + a.kernel_add() + """ + self.vpp.lcp_pair_add(self.vpp_ifname, self.ifname) + + def kernel_delete(self): + """Delete LCP pair + Example: + from vyos.ifconfig.vpp import VPPLoopbackInterface + a = VPPLoopbackInterface(ifname='vpplo1') + a.kernel_delete() + """ + self.vpp.lcp_pair_del(self.vpp_ifname, self.ifname) + + def remove(self): + if self.index: + # Delete lcp pair interface + if self.vpp.lcp_pair_find(vpp_name_hw=self.vpp_ifname): + self.kernel_delete() + + # Delete loopback interface + self.delete() + + def update(self, config): + # Add loopback interface + self.add() + + # Set rx-mode + rx_mode = config.get('vpp_settings', {}).get('interface_rx_mode') + if rx_mode: + self.set_rx_mode(rx_mode) + + # Apply all settings to the lcp pair (kernel) interface + super().update(config) diff --git a/python/vyos/vpp/interface/__init__.py b/python/vyos/vpp/interface/__init__.py index f970edb63..4ae96f486 100644 --- a/python/vyos/vpp/interface/__init__.py +++ b/python/vyos/vpp/interface/__init__.py @@ -20,7 +20,6 @@ from .ethernet import EthernetInterface from .geneve import GeneveInterface from .gre import GREInterface from .interface import Interface -from .loopback import LoopbackInterface from .wireguard import WireguardInterface from .xconnect import XconnectInterface @@ -30,7 +29,6 @@ __all__ = [ 'GeneveInterface', 'GREInterface', 'Interface', - 'LoopbackInterface', 'WireguardInterface', 'XconnectInterface', ] diff --git a/python/vyos/vpp/interface/loopback.py b/python/vyos/vpp/interface/loopback.py deleted file mode 100644 index 357423780..000000000 --- a/python/vyos/vpp/interface/loopback.py +++ /dev/null @@ -1,72 +0,0 @@ -# VyOS implementation of VPP Loopback 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.interface.interface import Interface - - -class LoopbackInterface(Interface): - """Interface Loopback""" - - def __init__(self, ifname, kernel_interface: str = '', state: str = 'up'): - super().__init__(ifname) - self.instance = int(ifname.removeprefix('lo')) - self.ifname = f'loop{self.instance}' - self.kernel_interface = kernel_interface - self.initial_state = state - - def add(self): - """Create Loopback interface - https://github.com/FDio/vpp/blob/stable/2306/src/vnet/interface.api - Example: - from vyos.vpp.interface import LoopbackInterface - a = LoopbackInterface(ifname='lo1') - a.add() - """ - self.vpp.api.create_loopback_instance( - is_specified=True, user_instance=self.instance - ) - # Set interface state - self.set_state(self.initial_state) - - def delete(self): - """Delete Loopback interface - Example: - from vyos.vpp.interface import LoopbackInterface - a = LoopbackInterface(ifname='lo1') - a.delete() - """ - loopback_if_index = self.vpp.get_sw_if_index(f'loop{self.instance}') - return self.vpp.api.delete_loopback(sw_if_index=loopback_if_index) - - def kernel_add(self): - """Add LCP pair - Example: - from vyos.vpp.interface import LoopbackInterface - a = LoopbackInterface(ifname='lo1') - 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 LoopbackInterface - a = LoopbackInterface(ifname='lo1') - a.kernel_delete() - """ - self.vpp.lcp_pair_del(self.ifname, self.kernel_interface) |
