From ab6ef466c128ba48f85b13ba8d4be1476e844726 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Mon, 8 Mar 2021 19:38:11 +0100 Subject: bgp: T3391: migrate old IPv4 only maximum-paths config to new syntax --- data/templates/frr/bgp.frr.tmpl | 27 ++-------- .../include/bgp-afi-maximum-paths.xml.i | 51 ++++++++++-------- interface-definitions/protocols-bgp.xml.in | 31 ----------- smoketest/configs/bgp-big-as-cloud | 4 ++ smoketest/scripts/cli/test_protocols_bgp.py | 8 +-- src/migration-scripts/quagga/8-to-9 | 61 ++++++++++++++++++++++ 6 files changed, 102 insertions(+), 80 deletions(-) create mode 100755 src/migration-scripts/quagga/8-to-9 diff --git a/data/templates/frr/bgp.frr.tmpl b/data/templates/frr/bgp.frr.tmpl index b7abbff5c..3101de7ea 100644 --- a/data/templates/frr/bgp.frr.tmpl +++ b/data/templates/frr/bgp.frr.tmpl @@ -208,11 +208,11 @@ router bgp {{ asn }} aggregate-address {{ ip }}{{ ' as-set' if afi_config.aggregate_address[ip].as_set is defined }}{{ ' summary-only' if afi_config.aggregate_address[ip].summary_only is defined }} {% endfor %} {% endif %} -{% if afi_config.maximum_paths is defined and afi_config.maximum_paths is not none %} - maximum-paths {{ afi_config.maximum_paths }} +{% if afi_config.maximum_paths is defined and afi_config.maximum_paths.ebgp is defined and afi_config.maximum_paths.ebgp is not none %} + maximum-paths {{ afi_config.maximum_paths.ebgp }} {% endif %} -{% if afi_config.maximum_paths_ibgp is defined and afi_config.maximum_paths_ibgp is not none %} - maximum-paths ibgp {{ afi_config.maximum_paths_ibgp }} +{% if afi_config.maximum_paths is defined and afi_config.maximum_paths.ibgp is defined and afi_config.maximum_paths.ibgp is not none %} + maximum-paths ibgp {{ afi_config.maximum_paths.ibgp }} {% endif %} {% if afi_config.redistribute is defined and afi_config.redistribute is not none %} {% for protocol in afi_config.redistribute %} @@ -285,25 +285,6 @@ router bgp {{ asn }} {% endif %} exit-address-family {% endfor %} -{% endif %} - ! -{# set protocols bgp xxxx maximum-paths ibgp x, Generated by default for afi_4 #} -{# We don't have this parameter in afi_6. But this is supported in FRR #} -{% if maximum_paths is defined and maximum_paths is not none %} -{% if maximum_paths.ebgp is defined and maximum_paths.ebgp is not none %} - ! - address-family ipv4 unicast - maximum-paths {{ maximum_paths.ebgp }} - exit-address-family - ! -{% endif %} -{% if maximum_paths.ibgp is defined and maximum_paths.ibgp is not none %} - ! - address-family ipv4 unicast - maximum-paths ibgp {{ maximum_paths.ibgp }} - exit-address-family - ! -{% endif %} {% endif %} ! {% if peer_group is defined and peer_group is not none %} diff --git a/interface-definitions/include/bgp-afi-maximum-paths.xml.i b/interface-definitions/include/bgp-afi-maximum-paths.xml.i index 5ee0d13a3..62133c375 100644 --- a/interface-definitions/include/bgp-afi-maximum-paths.xml.i +++ b/interface-definitions/include/bgp-afi-maximum-paths.xml.i @@ -1,26 +1,33 @@ - + - Forward packets over multiple paths (eBGP) - - u32:1-256 - Number of paths to consider - - - - + Forward packets over multiple paths - - - - Forward packets over multiple paths (iBGP) - - u32:1-256 - Number of paths to consider - - - - - - + + + + eBGP maximum paths + + u32:1-256 + Number of paths to consider + + + + + + + + + iBGP maximum paths + + u32:1-256 + Number of paths to consider + + + + + + + + diff --git a/interface-definitions/protocols-bgp.xml.in b/interface-definitions/protocols-bgp.xml.in index c2a123313..96a0b1315 100644 --- a/interface-definitions/protocols-bgp.xml.in +++ b/interface-definitions/protocols-bgp.xml.in @@ -350,37 +350,6 @@ - - - BGP multipaths - - - - - Maximum ebgp multipaths - - u32:1-255 - EBGP multipaths - - - - - - - - - Maximum ibgp multipaths - - u32:1-255 - EBGP multipaths - - - - - - - - Listen for and accept BGP dynamic neighbors from range diff --git a/smoketest/configs/bgp-big-as-cloud b/smoketest/configs/bgp-big-as-cloud index df3ae015c..694243d1e 100644 --- a/smoketest/configs/bgp-big-as-cloud +++ b/smoketest/configs/bgp-big-as-cloud @@ -1186,6 +1186,10 @@ protocols { } } } + maximum-paths { + ebgp 8 + ibgp 16 + } neighbor 192.0.16.209 { address-family { ipv4-unicast { diff --git a/smoketest/scripts/cli/test_protocols_bgp.py b/smoketest/scripts/cli/test_protocols_bgp.py index f22b47551..9aa1541cf 100755 --- a/smoketest/scripts/cli/test_protocols_bgp.py +++ b/smoketest/scripts/cli/test_protocols_bgp.py @@ -237,10 +237,10 @@ class TestProtocolsBGP(unittest.TestCase): self.session.set(base_path + ['parameters', 'ebgp-requires-policy']) # AFI maximum path support - self.session.set(base_path + ['address-family', 'ipv4-unicast', 'maximum-paths', max_path_v4]) - self.session.set(base_path + ['address-family', 'ipv4-unicast', 'maximum-paths-ibgp', max_path_v4ibgp]) - self.session.set(base_path + ['address-family', 'ipv6-unicast', 'maximum-paths', max_path_v6]) - self.session.set(base_path + ['address-family', 'ipv6-unicast', 'maximum-paths-ibgp', max_path_v6ibgp]) + self.session.set(base_path + ['address-family', 'ipv4-unicast', 'maximum-paths', 'ebgp', max_path_v4]) + self.session.set(base_path + ['address-family', 'ipv4-unicast', 'maximum-paths', 'ibgp', max_path_v4ibgp]) + self.session.set(base_path + ['address-family', 'ipv6-unicast', 'maximum-paths', 'ebgp', max_path_v6]) + self.session.set(base_path + ['address-family', 'ipv6-unicast', 'maximum-paths', 'ibgp', max_path_v6ibgp]) # commit changes self.session.commit() diff --git a/src/migration-scripts/quagga/8-to-9 b/src/migration-scripts/quagga/8-to-9 new file mode 100755 index 000000000..15c44924f --- /dev/null +++ b/src/migration-scripts/quagga/8-to-9 @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2021 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# 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, see . + +# - T3391: Migrate "maximum-paths" setting from "protocols bgp asn maximum-paths" +# under the IPv4 address-family tree. Reason is we currently have no way in +# configuring this for IPv6 address-family. This mimics the FRR configuration. + +from sys import argv +from sys import exit +from vyos.configtree import ConfigTree + +if (len(argv) < 2): + print("Must specify file name!") + exit(1) + +file_name = argv[1] + +with open(file_name, 'r') as f: + config_file = f.read() + +base = ['protocols', 'bgp'] +config = ConfigTree(config_file) + +if not config.exists(base): + # Nothing to do + exit(0) + +# Check if BGP is actually configured and obtain the ASN +asn_list = config.list_nodes(base) +if asn_list: + # There's always just one BGP node, if any + bgp_base = base + [asn_list[0]] + + maximum_paths = bgp_base + ['maximum-paths'] + if config.exists(maximum_paths): + for bgp_type in ['ebgp', 'ibgp']: + if config.exists(maximum_paths + [bgp_type]): + new_base = bgp_base + ['address-family', 'ipv4-unicast', 'maximum-paths'] + config.set(new_base) + config.copy(maximum_paths + [bgp_type], new_base + [bgp_type]) + config.delete(maximum_paths) + +try: + with open(file_name, 'w') as f: + f.write(config.to_string()) +except OSError as e: + print("Failed to save the modified config: {}".format(e)) + exit(1) -- cgit v1.2.3