diff options
| author | Christian Breunig <christian@breunig.cc> | 2026-03-02 14:22:18 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-02 14:22:18 +0100 |
| commit | 0c7a2b861abd4c897a2cbe4a5564effca8f9cc01 (patch) | |
| tree | 33a331c192ef66c35cf65501697bbacc8d09e7b7 /python | |
| parent | ffdf35b749433b6efb2b0d9edfd163dbe9d35ee7 (diff) | |
| parent | 5e4a09815db5f4c43e20c54d8961034739b28dee (diff) | |
| download | vyos-1x-0c7a2b861abd4c897a2cbe4a5564effca8f9cc01.tar.gz vyos-1x-0c7a2b861abd4c897a2cbe4a5564effca8f9cc01.zip | |
Merge pull request #5015 from natali-rs1985/T8314
vpp: T8314: Migrate ipip interface to 'interfaces vpp ipip'
Diffstat (limited to 'python')
| -rw-r--r-- | python/vyos/ifconfig/vpp/__init__.py | 2 | ||||
| -rw-r--r-- | python/vyos/ifconfig/vpp/ipip.py | 109 | ||||
| -rw-r--r-- | python/vyos/vpp/interface/__init__.py | 2 | ||||
| -rw-r--r-- | python/vyos/vpp/interface/ipip.py | 94 |
4 files changed, 111 insertions, 96 deletions
diff --git a/python/vyos/ifconfig/vpp/__init__.py b/python/vyos/ifconfig/vpp/__init__.py index bda2f76c8..a7cfe79a4 100644 --- a/python/vyos/ifconfig/vpp/__init__.py +++ b/python/vyos/ifconfig/vpp/__init__.py @@ -17,10 +17,12 @@ from .bond import VPPBondInterface from .interface import VPPInterface +from .ipip import VPPIPIPInterface from .vxlan import VPPVXLANInterface __all__ = [ 'VPPBondInterface', 'VPPInterface', + 'VPPIPIPInterface', 'VPPVXLANInterface', ] diff --git a/python/vyos/ifconfig/vpp/ipip.py b/python/vyos/ifconfig/vpp/ipip.py new file mode 100644 index 000000000..fff79fd43 --- /dev/null +++ b/python/vyos/ifconfig/vpp/ipip.py @@ -0,0 +1,109 @@ +# VyOS implementation of VPP IPIP 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 VPPIPIPInterface(Interface, VPPInterface): + def __init__(self, ifname, config): + self.ifname = ifname + self.instance = int(ifname.removeprefix('vppipip')) + self.vpp_ifname = self.ifname.removeprefix('vpp') + + # 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.src_address = config.get('source_address') + self.dst_address = config.get('remote') + self.state = 'up' if 'disable' not in config else 'down' + + def _create(self): + pass + + def add_ipip(self): + """Create IPIP interface + https://github.com/FDio/vpp/blob/stable/2310/src/vnet/ipip/ipip.api + Example: + from vyos.ifconfig.vpp import VPPIPIPInterface + a = VPPIPIPInterface(ifname='vppipip0', config) + a.add_ipip() + """ + self.vpp.api.ipip_add_tunnel( + tunnel={ + 'src': self.src_address, + 'dst': self.dst_address, + '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_ipip(self): + """Delete IPIP interface + Example: + from vyos.ifconfig.vpp import VPPIPIPInterface + a = VPPIPIPInterface(ifname='vppipip0', config) + a.delete_ipip() + """ + return self.vpp.api.ipip_del_tunnel(sw_if_index=self.index) + + def kernel_add(self): + """Add LCP pair + Example: + from vyos.ifconfig.vpp import VPPIPIPInterface + a = VPPIPIPInterface(ifname='vppipip0', config) + a.kernel_add() + """ + self.vpp.lcp_pair_add(self.vpp_ifname, self.ifname, 'tun') + + def kernel_delete(self): + """Delete LCP pair + Example: + from vyos.ifconfig.vpp import VPPIPIPInterface + a = VPPIPIPInterface(ifname='vppipip0', config) + 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 ipip interface + self.delete_ipip() + + def update(self, config): + # Add ipip interface + self.add_ipip() + + # 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 f17a12d43..f970edb63 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 .ipip import IPIPInterface from .loopback import LoopbackInterface from .wireguard import WireguardInterface from .xconnect import XconnectInterface @@ -31,7 +30,6 @@ __all__ = [ 'GeneveInterface', 'GREInterface', 'Interface', - 'IPIPInterface', 'LoopbackInterface', 'WireguardInterface', 'XconnectInterface', diff --git a/python/vyos/vpp/interface/ipip.py b/python/vyos/vpp/interface/ipip.py deleted file mode 100644 index e6ed44537..000000000 --- a/python/vyos/vpp/interface/ipip.py +++ /dev/null @@ -1,94 +0,0 @@ -# VyOS implementation of VPP IPIP 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 -from vyos.vpp.interface.interface import Interface - - -def show(): - """Show IPIP interface - Example: - from vyos.vpp.interface import ipip - ipip.show() - """ - vpp = VPPControl() - return vpp.api.ipip_tunnel_dump() - - -class IPIPInterface(Interface): - def __init__( - self, - ifname, - source_address, - remote, - kernel_interface: str = '', - state: str = 'up', - ): - super().__init__(ifname) - self.instance = int(ifname.removeprefix('ipip')) - self.ifname = ifname - self.src_address = source_address - self.dst_address = remote - self.kernel_interface = kernel_interface - self.initial_state = state - - def add(self): - """Create IPIP interface - https://github.com/FDio/vpp/blob/stable/2310/src/vnet/ipip/ipip.api - Example: - from vyos.vpp.interface import IPIPInterface - a = IPIPInterface(ifname='ipip0', source_address='192.0.2.1', remote='192.0.2.5') - a.add() - """ - self.vpp.api.ipip_add_tunnel( - tunnel={ - 'src': self.src_address, - 'dst': self.dst_address, - 'instance': self.instance, - }, - ) - # Set interface state - self.set_state(self.initial_state) - - def delete(self): - """Delete IPIP interface - Example: - from vyos.vpp.interface import IPIPInterface - a = IPIPInterface(ifname='ipip0', source_address='192.0.2.1', remote='192.0.2.5') - a.delete() - """ - ipip_if_index = self.vpp.get_sw_if_index(f'ipip{self.instance}') - return self.vpp.api.ipip_del_tunnel(sw_if_index=ipip_if_index) - - def kernel_add(self): - """Add LCP pair - Example: - from vyos.vpp.interface import IPIPInterface - a = IPIPInterface(ifname='ipip0', source_address='192.0.2.1', remote='192.0.2.5') - 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 IPIPInterface - a = IPIPInterface(ifname='ipip0', source_address='192.0.2.1', remote='192.0.2.5') - a.kernel_delete() - """ - self.vpp.lcp_pair_del(self.ifname, self.kernel_interface) |
