diff options
| author | Viacheslav Hletenko <v.gletenko@vyos.io> | 2025-01-24 15:26:27 +0000 |
|---|---|---|
| committer | Viacheslav Hletenko <v.gletenko@vyos.io> | 2025-01-24 15:34:33 +0000 |
| commit | 9425dce22f1bc8393d5ea6b2ae39b4ef70b7fa50 (patch) | |
| tree | 26b8356d17e6d03a9e86f5dfc2e8443a460f21cb | |
| parent | 912128ab9a6d0272c67b199050c0a9b1bf79b24f (diff) | |
| download | vyos-1x-9425dce22f1bc8393d5ea6b2ae39b4ef70b7fa50.tar.gz vyos-1x-9425dce22f1bc8393d5ea6b2ae39b4ef70b7fa50.zip | |
GRE: Add ability to configure multipoint mode
Add ability to configure multipoint mode.
Remote IP address in this case has to be 0.0.0.0
Only one tunnel with the same source IP is allowed in the
point-to-multipoint mode
set vpp interfaces gre gre0 mode 'point-to-multipoint'
set vpp interfaces gre gre0 remote '0.0.0.0'
set vpp interfaces gre gre0 source-address '192.0.2.1'
| -rw-r--r-- | interface-definitions/vpp.xml.in | 21 | ||||
| -rw-r--r-- | python/vyos/vpp/interface/gre.py | 16 | ||||
| -rw-r--r-- | src/conf_mode/vpp_interfaces_gre.py | 19 |
3 files changed, 51 insertions, 5 deletions
diff --git a/interface-definitions/vpp.xml.in b/interface-definitions/vpp.xml.in index c946839db..e3a2f9aff 100644 --- a/interface-definitions/vpp.xml.in +++ b/interface-definitions/vpp.xml.in @@ -180,6 +180,27 @@ </valueHelp> </properties> <children> + <leafNode name="mode"> + <properties> + <help>GRE tunnel mode</help> + <completionHelp> + <list>point-to-point point-to-multipoint</list> + </completionHelp> + <valueHelp> + <format>point-to-point</format> + <description>Point to point mode</description> + </valueHelp> + <valueHelp> + <format>point-to-multipoint</format> + <description>Point to multipoint mode</description> + </valueHelp> + <constraint> + <regex>(point-to-point|point-to-multipoint)</regex> + </constraint> + <constraintErrorMessage>Invalid mode, must be one of: point-to-point or point-to-multipoint</constraintErrorMessage> + </properties> + <defaultValue>point-to-point</defaultValue> + </leafNode> <leafNode name="tunnel-type"> <properties> <help>GRE tunnel type</help> diff --git a/python/vyos/vpp/interface/gre.py b/python/vyos/vpp/interface/gre.py index 65559f294..8f3dbebae 100644 --- a/python/vyos/vpp/interface/gre.py +++ b/python/vyos/vpp/interface/gre.py @@ -38,6 +38,7 @@ class GREInterface: 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. @@ -45,9 +46,14 @@ class GREInterface: # 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, + 'l3': 0, + 'teb': 1, + 'erspan': 2, + } + + MODE_MAP = { + 'point-to-point': 0, + 'point-to-multipoint': 1, } def __init__( @@ -56,6 +62,7 @@ class GREInterface: source_address, remote, tunnel_type: str = 'l3', + mode: str = 'point-to-point', kernel_interface: str = '', ): """ @@ -65,6 +72,7 @@ class GREInterface: 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. """ @@ -73,6 +81,7 @@ class GREInterface: 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.vpp = VPPControl() @@ -90,6 +99,7 @@ class GREInterface: 'src': self.src_address, 'dst': self.dst_address, 'instance': self.instance, + 'mode': self.mode, 'type': self.tunnel_type, }, ) diff --git a/src/conf_mode/vpp_interfaces_gre.py b/src/conf_mode/vpp_interfaces_gre.py index 4cb1a71ea..334725994 100644 --- a/src/conf_mode/vpp_interfaces_gre.py +++ b/src/conf_mode/vpp_interfaces_gre.py @@ -124,13 +124,27 @@ def verify(config): return None # source-address and remote are mandatory options - required_keys = {'source_address', 'remote', 'tunnel_type'} + required_keys = {'source_address', 'remote', 'mode', 'tunnel_type'} if not all(key in config for key in required_keys): missing_keys = required_keys - set(config.keys()) raise ConfigError( f"Required options are missing: {', '.join(missing_keys).replace('_', '-')}" ) + # 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 + for ifname, iface in config.get('vpp_interfaces', {}).items(): + if iface.get('mode') == 'point-to-multipoint' and iface.get( + 'source_address' + ) == config.get('source_address'): + raise ConfigError( + 'Only one multipoint GRE tunnel is allowed from the same source address' + ) + # Change 'vpp interfaces gre greX kernel-interface vpp-tunX' # => 'vpp interfaces gre greX kernel-interface vpp-tunY' # check if we have kernel interface config 'vpp kernel-interface vpp-tunX' @@ -159,8 +173,9 @@ def apply(config): src_addr = config.get('source_address') dst_addr = config.get('remote') kernel_interface = config.get('kernel_interface', '') + mode = config.get('mode') tunnel_type = config.get('tunnel_type') - i = GREInterface(ifname, src_addr, dst_addr, tunnel_type, kernel_interface) + i = GREInterface(ifname, src_addr, dst_addr, tunnel_type, mode, kernel_interface) i.add() # Add kernel-interface (LCP) if interface is not exist |
