From c5c5021aed8ac1baaaf0896193e1c89f125c2103 Mon Sep 17 00:00:00 2001 From: Nataliia Solomko Date: Fri, 27 Feb 2026 16:51:46 +0200 Subject: vpp: T8325: Migrate gre interface to 'interfaces vpp gre' --- python/vyos/ifconfig/vpp/__init__.py | 2 + python/vyos/ifconfig/vpp/gre.py | 138 +++++++++++++++++++++++++++++++++ python/vyos/vpp/interface/__init__.py | 2 - python/vyos/vpp/interface/gre.py | 140 ---------------------------------- python/vyos/vpp/interface/xconnect.py | 4 +- 5 files changed, 142 insertions(+), 144 deletions(-) create mode 100644 python/vyos/ifconfig/vpp/gre.py delete mode 100644 python/vyos/vpp/interface/gre.py (limited to 'python') diff --git a/python/vyos/ifconfig/vpp/__init__.py b/python/vyos/ifconfig/vpp/__init__.py index b0a477c28..7abe402c6 100644 --- a/python/vyos/ifconfig/vpp/__init__.py +++ b/python/vyos/ifconfig/vpp/__init__.py @@ -16,6 +16,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. from .bond import VPPBondInterface +from .gre import VPPGREInterface from .interface import VPPInterface from .ipip import VPPIPIPInterface from .loopback import VPPLoopbackInterface @@ -23,6 +24,7 @@ from .vxlan import VPPVXLANInterface __all__ = [ 'VPPBondInterface', + 'VPPGREInterface', 'VPPInterface', 'VPPIPIPInterface', 'VPPLoopbackInterface', diff --git a/python/vyos/ifconfig/vpp/gre.py b/python/vyos/ifconfig/vpp/gre.py new file mode 100644 index 000000000..e281574a2 --- /dev/null +++ b/python/vyos/ifconfig/vpp/gre.py @@ -0,0 +1,138 @@ +# VyOS implementation of VPP GRE 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 VPPGREInterface(Interface, VPPInterface): + """ + Class representing a GRE (Generic Routing Encapsulation) interface. + """ + + # Mapping of tunnel types https://github.com/FDio/vpp/blob/stable/2406/src/plugins/gre/gre.api#L25-L35 + TUNNEL_TYPE_MAP = { + 'l3': 0, + 'teb': 1, + 'erspan': 2, + } + + MODE_MAP = { + 'point-to-point': 0, + 'point-to-multipoint': 1, + } + + def __init__(self, ifname, config): + self.ifname = ifname + self.instance = int(ifname.removeprefix('vppgre')) + self.vpp_ifname = f'gre{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' + self.src_address = config.get('source_address') + self.dst_address = config.get('remote') + self.tunnel_type = self.TUNNEL_TYPE_MAP.get(config.get('tunnel_type'), 0) + self.mode = self.MODE_MAP.get(config.get('mode'), 0) + + def _create(self): + pass + + def get_gre(self): + tunnels = self.vpp.api.gre_tunnel_dump(sw_if_index=self.index) + return tunnels if tunnels else None + + def add_gre(self): + """Create GRE interface + https://github.com/FDio/vpp/blob/stable/2406/src/plugins/gre/gre.api + Example: + from vyos.ifconfig.vpp import VPPGREInterface + a = VPPGREInterface(ifname='vppgre0', config) + a.add_gre() + """ + self.vpp.api.gre_tunnel_add_del( + is_add=True, + tunnel={ + 'src': self.src_address, + 'dst': self.dst_address, + 'instance': self.instance, + 'mode': self.mode, + 'type': self.tunnel_type, + }, + ) + # 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_gre(self): + """Delete GRE interface + Example: + from vyos.ifconfig.vpp import VPPGREInterface + a = VPPGREInterface(ifname='vppgre0', config) + a.delete_gre() + """ + gre = self.get_gre() + if gre: + return self.vpp.api.gre_tunnel_add_del( + is_add=False, + tunnel={'src': gre.tunnel.src, 'dst': gre.tunnel.dst}, + ) + + def kernel_add(self): + """Add LCP pair + Example: + from vyos.ifconfig.vpp import VPPGREInterface + a = VPPGREInterface(ifname='vppgre0', 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 VPPGREInterface + a = VPPGREInterface(ifname='vppgre0', 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 gre interface + self.delete_gre() + + def update(self, config): + # Add gre interface + self.add_gre() + + # Set rx-mode + rx_mode = config.get('vpp_settings', {}).get('interface_rx_mode') + if rx_mode: + self.set_rx_mode(rx_mode) + + super().update(config) diff --git a/python/vyos/vpp/interface/__init__.py b/python/vyos/vpp/interface/__init__.py index 4ae96f486..cdfb0c0b8 100644 --- a/python/vyos/vpp/interface/__init__.py +++ b/python/vyos/vpp/interface/__init__.py @@ -18,7 +18,6 @@ from .bridge import BridgeInterface from .ethernet import EthernetInterface from .geneve import GeneveInterface -from .gre import GREInterface from .interface import Interface from .wireguard import WireguardInterface from .xconnect import XconnectInterface @@ -27,7 +26,6 @@ __all__ = [ 'BridgeInterface', 'EthernetInterface', 'GeneveInterface', - 'GREInterface', 'Interface', 'WireguardInterface', 'XconnectInterface', diff --git a/python/vyos/vpp/interface/gre.py b/python/vyos/vpp/interface/gre.py deleted file mode 100644 index bc278d2a0..000000000 --- a/python/vyos/vpp/interface/gre.py +++ /dev/null @@ -1,140 +0,0 @@ -# VyOS implementation of VPP GRE 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 GRE interface - Example: - from vyos.vpp.interface import gre - gre.show() - """ - vpp = VPPControl() - return vpp.api.gre_tunnel_dump() - - -class GREInterface(Interface): - """ - Class representing a GRE (Generic Routing Encapsulation) interface. - - Attributes: - ifname (str): The interface name. - source_address (str): The source IP address for the GRE tunnel. - remote (str): The remote IP address for the GRE tunnel. - tunnel_type (str): The type of GRE tunnel. Defaults to 'l3'. - mode (str): The mode of the GRE tunnel. Options are 'point-to-point' and 'point-to-multipoint'. Defaults to 'point-to-point'. - kernel_interface (str): The associated kernel interface. Defaults to an empty string. - instance (int): The instance number derived from the interface name. - vpp (VPPControl): An instance of the VPPControl class for interacting with the VPP API. - """ - - # Mapping of tunnel types https://github.com/FDio/vpp/blob/stable/2406/src/plugins/gre/gre.api#L25-L35 - TUNNEL_TYPE_MAP = { - 'l3': 0, - 'teb': 1, - 'erspan': 2, - } - - MODE_MAP = { - 'point-to-point': 0, - 'point-to-multipoint': 1, - } - - def __init__( - self, - ifname, - source_address, - remote, - tunnel_type: str = 'l3', - mode: str = 'point-to-point', - kernel_interface: str = '', - state: str = 'up', - ): - """ - Initialize a GREInterface instance. - - Args: - ifname (str): The interface name. - source_address (str): The source IP address for the GRE tunnel. - remote (str): The remote IP address for the GRE tunnel. - mode (str): The mode of the GRE tunnel. Options are 'point-to-point' and 'point-to-multipoint'. Defaults to 'point-to-point'. - tunnel_type (str): The type of GRE tunnel. Defaults to 'l3'. - kernel_interface (str): The associated kernel interface. Defaults to an empty string. - state (str): The state of the interface. Defaults to 'up'. - """ - super().__init__(ifname) - self.instance = int(ifname.removeprefix('gre')) - self.ifname = ifname - self.src_address = source_address - self.dst_address = remote - self.tunnel_type = self.TUNNEL_TYPE_MAP[tunnel_type] - self.mode = self.MODE_MAP[mode] - self.kernel_interface = kernel_interface - self.initial_state = state - - def add(self): - """Create GRE interface - https://github.com/FDio/vpp/blob/stable/2406/src/plugins/gre/gre.api - Example: - from vyos.vpp.interface import GREInterface - a = GREInterface(ifname='gre0', source_address='192.0.2.1', remote='203.0.113.25', tunnel_type='l3') - a.add() - """ - self.vpp.api.gre_tunnel_add_del( - is_add=True, - tunnel={ - 'src': self.src_address, - 'dst': self.dst_address, - 'instance': self.instance, - 'mode': self.mode, - 'type': self.tunnel_type, - }, - ) - # Set interface state - self.set_state(self.initial_state) - - def delete(self): - """Delete GRE interface - Example: - from vyos.vpp.interface import GREInterface - a = GREInterface(ifname='gre0', source_address='192.0.2.1', remote='203.0.113.25') - a.delete() - """ - return self.vpp.api.gre_tunnel_add_del( - is_add=False, tunnel={'src': self.src_address, 'dst': self.dst_address} - ) - - def kernel_add(self): - """Add LCP pair - Example: - from vyos.vpp.interface import GREInterface - a = GREInterface(ifname='gre0', source_address='192.0.2.1', remote='203.0.113.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 GREInterface - a = GREInterface(ifname='gre0', source_address='192.0.2.1', remote='203.0.113.25') - a.kernel_delete() - """ - self.vpp.lcp_pair_del(self.ifname, self.kernel_interface) diff --git a/python/vyos/vpp/interface/xconnect.py b/python/vyos/vpp/interface/xconnect.py index 603f7f90b..dd61d7146 100644 --- a/python/vyos/vpp/interface/xconnect.py +++ b/python/vyos/vpp/interface/xconnect.py @@ -41,7 +41,7 @@ class XconnectInterface: a = XconnectInterface(ifname='xcon0', members=['eth0', 'vxlan0']) a.add_l2_xconnect() """ - interface_transform_filter = ('vxlan', 'gre') + interface_transform_filter = ('vxlan', 'geneve') first_member = self.members[0].removeprefix('vpp') second_member = self.members[1].removeprefix('vpp') # Check if member in required filter to transform 'vxlanX' => 'vxlan_tunnelX' @@ -72,7 +72,7 @@ class XconnectInterface: a = XconnectInterface(ifname='xcon0', members=['eth0', 'vxlan0']) a.del_l2_xconnect() """ - interface_transform_filter = ('vxlan', 'gre') + interface_transform_filter = ('vxlan', 'geneve') first_member = self.members[0].removeprefix('vpp') second_member = self.members[1].removeprefix('vpp') # Check if member in required filter to transform 'vxlanX' => 'vxlan_tunnelX' -- cgit v1.2.3 From 99f617c88e57453315ee97cba88d3de1a24a5f01 Mon Sep 17 00:00:00 2001 From: Nataliia Solomko Date: Mon, 2 Mar 2026 11:42:17 +0200 Subject: vpp: T8327: Remove support for GRE "point-to-multipoint" mode Disabled "point-to-multipoint" mode for GRE interfaces, along with related "mode" node. This mode relies on the 'teib' feature, which is not implemented yet. --- interface-definitions/vpp_interface_gre.xml.in | 4 ++- python/vyos/ifconfig/vpp/gre.py | 4 +-- smoketest/configs/assert/vpp | 23 ++++++------- src/conf_mode/vpp_interfaces_gre.py | 47 +++++++++++++------------- src/migration-scripts/vpp/5-to-6 | 8 ++++- 5 files changed, 47 insertions(+), 39 deletions(-) (limited to 'python') diff --git a/interface-definitions/vpp_interface_gre.xml.in b/interface-definitions/vpp_interface_gre.xml.in index 7b145ffdc..7636c6e2f 100644 --- a/interface-definitions/vpp_interface_gre.xml.in +++ b/interface-definitions/vpp_interface_gre.xml.in @@ -20,6 +20,8 @@ #include #include + + GRE tunnel type diff --git a/python/vyos/ifconfig/vpp/gre.py b/python/vyos/ifconfig/vpp/gre.py index e281574a2..7ab600998 100644 --- a/python/vyos/ifconfig/vpp/gre.py +++ b/python/vyos/ifconfig/vpp/gre.py @@ -34,7 +34,7 @@ class VPPGREInterface(Interface, VPPInterface): MODE_MAP = { 'point-to-point': 0, - 'point-to-multipoint': 1, + # 'point-to-multipoint': 1, } def __init__(self, ifname, config): @@ -51,7 +51,7 @@ class VPPGREInterface(Interface, VPPInterface): self.src_address = config.get('source_address') self.dst_address = config.get('remote') self.tunnel_type = self.TUNNEL_TYPE_MAP.get(config.get('tunnel_type'), 0) - self.mode = self.MODE_MAP.get(config.get('mode'), 0) + self.mode = self.MODE_MAP['point-to-point'] def _create(self): pass diff --git a/smoketest/configs/assert/vpp b/smoketest/configs/assert/vpp index 152ffd111..1e89dc324 100644 --- a/smoketest/configs/assert/vpp +++ b/smoketest/configs/assert/vpp @@ -22,18 +22,17 @@ set system syslog local facility local7 level 'debug' set interfaces vpp bonding vppbond0 hash-policy 'layer2+3' set interfaces vpp bonding vppbond0 member interface 'eth4' set interfaces vpp bonding vppbond0 mode '802.3ad' -set vpp interfaces gre gre10 description 'Layer-3' -set vpp interfaces gre gre10 mode 'point-to-point' -set vpp interfaces gre gre10 remote '192.0.2.2' -set vpp interfaces gre gre10 source-address '192.0.2.1' -set vpp interfaces gre gre10 tunnel-type 'l3' -set vpp interfaces gre gre11 description 'L2-bridge-to-eth2' -set vpp interfaces gre gre11 remote '192.0.2.123' -set vpp interfaces gre gre11 source-address '192.0.2.1' -set vpp interfaces gre gre11 tunnel-type 'teb' -set vpp interfaces ipip ipip20 remote '192.0.2.2' -set vpp interfaces ipip ipip20 source-address '192.0.2.1' -set vpp interfaces loopback lo12 description 'Loop12' +set interfaces vpp gre vppgre10 description 'Layer-3' +set interfaces vpp gre vppgre10 remote '192.0.2.2' +set interfaces vpp gre vppgre10 source-address '192.0.2.1' +set interfaces vpp gre vppgre10 tunnel-type 'l3' +set interfaces vpp gre vppgre11 description 'L2-bridge-to-eth2' +set interfaces vpp gre vppgre11 remote '192.0.2.123' +set interfaces vpp gre vppgre11 source-address '192.0.2.1' +set interfaces vpp gre vppgre11 tunnel-type 'teb' +set interfaces vpp ipip vppipip20 remote '192.0.2.2' +set interfaces vpp ipip vppipip20 source-address '192.0.2.1' +set interfaces vpp loopback vpplo12 description 'Loop12' set interfaces vpp vxlan vppvxlan10 remote '192.0.2.2' set interfaces vpp vxlan vppvxlan10 source-address '192.0.2.1' set interfaces vpp vxlan vppvxlan10 vni '10' diff --git a/src/conf_mode/vpp_interfaces_gre.py b/src/conf_mode/vpp_interfaces_gre.py index de3ab2d39..453845bcf 100644 --- a/src/conf_mode/vpp_interfaces_gre.py +++ b/src/conf_mode/vpp_interfaces_gre.py @@ -106,11 +106,11 @@ def verify(config): if not is_systemd_service_active('vpp.service'): raise ConfigError( - 'Cannot configure VPP bonding interface: vpp.service is not running' + 'Cannot configure VPP GRE interface: vpp.service is not running' ) # source-address and remote are mandatory options - required_keys = {'source_address', 'remote', 'mode', 'tunnel_type'} + required_keys = {'source_address', 'remote', 'tunnel_type'} if not all(key in config for key in required_keys): missing_keys = required_keys - set(config.keys()) raise ConfigError( @@ -122,27 +122,28 @@ def verify(config): if config.get('source_address') == config.get('remote'): raise ConfigError('Remote address must not be the same as source address') - # check multipoint mode - if config.get('mode') == 'point-to-multipoint': - # For multipoint mode, remote IP must be 0.0.0.0 - if config.get('remote') != '0.0.0.0': - raise ConfigError('For point-to-multipoint mode, remote must be 0.0.0.0') - - # Only one multipoint GRE tunnel is allowed from the same source address - # set interfaces vpp gre vppgre0 mode 'point-to-multipoint' - # set interfaces vpp gre vppgre0 remote '0.0.0.0' - # set interfaces vpp gre vppgre0 source-address '192.0.2.1' - # set interfaces vpp gre vppgre1 mode 'point-to-multipoint' - # set interfaces vpp gre vppgre1 remote '0.0.0.0' - # set interfaces vpp gre vppgre1 source-address '192.0.2.1' - for other_iface, other_iface_config in config['gre_interfaces'].items(): - if other_iface == config['ifname']: - continue - if other_iface_config['mode'] == 'point-to-multipoint': - if config['source_address'] == other_iface_config.get('source_address'): - raise ConfigError( - 'Only one multipoint GRE tunnel is allowed from the same source address' - ) + # Disable checks as point-to-multipoint mode does not work without 'teib' feature that is not implemented yet + # # check multipoint mode + # if config.get('mode') == 'point-to-multipoint': + # # For multipoint mode, remote IP must be 0.0.0.0 + # if config.get('remote') != '0.0.0.0': + # raise ConfigError('For point-to-multipoint mode, remote must be 0.0.0.0') + # + # # Only one multipoint GRE tunnel is allowed from the same source address + # # set interfaces vpp gre vppgre0 mode 'point-to-multipoint' + # # set interfaces vpp gre vppgre0 remote '0.0.0.0' + # # set interfaces vpp gre vppgre0 source-address '192.0.2.1' + # # set interfaces vpp gre vppgre1 mode 'point-to-multipoint' + # # set interfaces vpp gre vppgre1 remote '0.0.0.0' + # # set interfaces vpp gre vppgre1 source-address '192.0.2.1' + # for other_iface, other_iface_config in config['gre_interfaces'].items(): + # if other_iface == config['ifname']: + # continue + # if other_iface_config['mode'] == 'point-to-multipoint': + # if config['source_address'] == other_iface_config.get('source_address'): + # raise ConfigError( + # 'Only one multipoint GRE tunnel is allowed from the same source address' + # ) def generate(config): diff --git a/src/migration-scripts/vpp/5-to-6 b/src/migration-scripts/vpp/5-to-6 index ed043de03..03c20d970 100644 --- a/src/migration-scripts/vpp/5-to-6 +++ b/src/migration-scripts/vpp/5-to-6 @@ -45,7 +45,7 @@ # # Migrate loopback interface from vpp section to 'interfaces vpp loopback' (T8324) # -# Migrate gre interface to 'interfaces vpp gre' (T8325) +# Migrate gre interface to 'interfaces vpp gre', remove interfaces with mode "point-to-multipoint" (T8325) # from vyos.configtree import ConfigTree @@ -476,6 +476,12 @@ def _migrate_vpp_gre_interface(config: ConfigTree) -> None: config.set(new_base) for ifname in config.list_nodes(base): + if config.exists(base + [ifname, 'mode']): + if config.return_value(base + [ifname, 'mode']) == 'point-to-multipoint': + config.delete(base + [ifname]) + continue + config.delete(base + [ifname, 'mode']) + _migrate_interface(config, 'gre', ifname) _migrate_members_bridge(config, ifname) -- cgit v1.2.3