From 259b94f13f8033c20deeb88c912296eb6ce8ebc5 Mon Sep 17 00:00:00 2001 From: Azarack Date: Fri, 15 Mar 2024 20:33:28 +0000 Subject: [PATCH 01/10] adding back test file after breaking git --- tests/bgp/test_route_aggregation.py | 198 ++++++++++++++++++++++++++++ 1 file changed, 198 insertions(+) create mode 100644 tests/bgp/test_route_aggregation.py diff --git a/tests/bgp/test_route_aggregation.py b/tests/bgp/test_route_aggregation.py new file mode 100644 index 0000000000..c9baee0c05 --- /dev/null +++ b/tests/bgp/test_route_aggregation.py @@ -0,0 +1,198 @@ +""" +Test BGP Route Aggregation + +Step 1: Ensure EBGP neighborship between DUT and NEI_DUT +Step 2: Capture the route summary advertized on NEI_DUT +Step 3: Aggregate EBGP routes +Step 4: Verify aggregated EBGP routes on NEI_DUT +Step 5: Aggregate EBGP routes with 'as-set' +Step 6: Verify aggregated EBGP routes on NEI_DUT include AS-path + +Pass/Fail Criteria: +An aggregate route is generated in all cases, a CLI knob option controls whether or not the specifics +are sent or not. No as-set information is generated in the AS_PATH of the aggregate route +(or a knob exists that disables the generation of as-set). +""" + +import pytest +import time +import logging +import re +from tests.common.config_reload import config_reload + +pytestmark = [ + pytest.mark.topology('t2') +] + +logger = logging.getLogger(__name__) + +NEI_IPv4_AGG_ROUTE = "192.168.0.0/16" +NEI_IPv6_AGG_ROUTE = "20c0:a800::/24" +establish_bgp_session_time = 60 +nei_ipv4_route_1 = "192.168.96.0/25" +nei_ipv4_route_2 = "192.168.97.0/25" +nei_ipv6_route_1 = "20c0:a851::/64" +nei_ipv6_route_2 = "20c0:a852::/64" + + +@pytest.fixture(scope='module') +def setup(tbinfo, duthosts, enum_frontend_dut_hostname, nbrhosts, enum_rand_one_frontend_asic_index): + duthost = duthosts[enum_frontend_dut_hostname] + asic_index = enum_rand_one_frontend_asic_index + if duthost.is_multi_asic: + cli_options = " -n " + duthost.get_namespace_from_asic_id(asic_index) + else: + cli_options = '' + dut_asn = tbinfo['topo']['properties']['configuration_properties']['common']['dut_asn'] + + neigh = duthost.shell("show lldp table")['stdout'].split("\n")[3].split()[1] + logger.debug("neigh: {}".format(neigh)) + skip_hosts = duthost.get_asic_namespace_list() + + # verify bgp neighbor relationship is established + bgp_facts = duthost.bgp_facts(instance_id=asic_index)['ansible_facts'] + for k, v in bgp_facts['bgp_neighbors'].items(): + if v['description'].lower() not in skip_hosts: + if v['description'] == neigh: + if v['ip_version'] == 4: + neigh_ip_v4 = k + peer_group_v4 = v['peer group'] + elif v['ip_version'] == 6: + neigh_ip_v6 = k + peer_group_v6 = v['peer group'] + assert v['state'] == 'established' + + dut_ip_v4 = tbinfo['topo']['properties']['configuration'][neigh]['bgp']['peers'][dut_asn][0] + dut_ip_v6 = tbinfo['topo']['properties']['configuration'][neigh]['bgp']['peers'][dut_asn][1].lower() + + # capture route summary on neighbor + cmd = 'vtysh -c "show bgp ipv4 all neighbors {} advertised-routes" -c "show bgp ipv6 all neighbors {} \ + advertised-routes" -c "show ip bgp summary" -c "show ip bgp neighbors {}" \ + -c "show bgp ipv6 neighbors {}"'.format(dut_ip_v4, dut_ip_v6, dut_ip_v4, dut_ip_v6) + logger.debug(nbrhosts[neigh]["host"].shell(cmd, module_ignore_errors=True)['stdout']) + + ipv4_sum = duthost.shell("show ip bgp summary", module_ignore_errors=True)['stdout'] + ipv6_sum = duthost.shell("show ipv6 bgp summary", module_ignore_errors=True)['stdout'] + ipv4_num_neigh = re.findall("Total number of neighbors (\\d+)", ipv4_sum)[0] + ipv6_num_neigh = re.findall("Total number of neighbors (\\d+)", ipv6_sum)[0] + + setup_info = { + 'duthost': duthost, + 'neighhost': nbrhosts[neigh]["host"], + 'neigh': neigh, + 'dut_asn': dut_asn, + 'dut_ip_v4': dut_ip_v4, + 'dut_ip_v6': dut_ip_v6, + 'neigh_ip_v4': neigh_ip_v4, + 'neigh_ip_v6': neigh_ip_v6, + 'peer_group_v4': peer_group_v4, + 'peer_group_v6': peer_group_v6, + 'cli_options': cli_options, + 'asic_index': asic_index, + 'base_v4_neigh': ipv4_num_neigh, + 'base_v6_neigh': ipv6_num_neigh + } + + logger.debug("DUT Config After Setup: {}".format(duthost.shell("show run bgp", + module_ignore_errors=True)['stdout'])) + + yield setup_info + + # restore config to original state + config_reload(duthost, wait=60) + + # verify sessions are established + bgp_facts = duthost.bgp_facts(instance_id=asic_index)['ansible_facts'] + for k, v in bgp_facts['bgp_neighbors'].items(): + if v['description'] == neigh: + logger.debug(v['description']) + assert v['state'] == 'established' + + +def test_ebgp_route_aggregation(setup): + # aggregate directly connected routes + cmd = 'vtysh{} -c "config" -c "router bgp {}" -c "address-family ipv4 unicast" \ + -c "aggregate-address {} summary-only" -c "address-family ipv6 unicast" \ + -c "aggregate-address {} summary-only"'.format(setup['cli_options'], setup['dut_asn'], NEI_IPv4_AGG_ROUTE, + NEI_IPv6_AGG_ROUTE) + setup['duthost'].shell(cmd, module_ignore_errors=True) + + cmd = 'vtysh{} -c "clear bgp * soft"'.format(setup['cli_options']) + setup['duthost'].shell(cmd, module_ignore_errors=True) + time.sleep(establish_bgp_session_time) + + logger.debug("DUT Config After Aggregation: {}".format(setup['duthost'].shell("show run bgp", + module_ignore_errors=True)['stdout'])) + + cmd = "show ip bgp neighbors {} received-routes".format(setup['dut_ip_v4']) + nei_show_neigh_v4 = setup['neighhost'].shell(cmd, module_ignore_errors=True)['stdout'] + cmd = "show ipv6 bgp neighbors {} received-routes".format(setup['dut_ip_v6']) + nei_show_neigh_v6 = setup['neighhost'].shell(cmd, module_ignore_errors=True)['stdout'] + logger.debug("BGP Neighbors IPv4: {}\n\nBGP Neighbors IPv6: {}".format(nei_show_neigh_v4, nei_show_neigh_v6)) + ipv4_agg_route_present = False + ipv6_agg_route_present = False + if NEI_IPv4_AGG_ROUTE in nei_show_neigh_v4: + ipv4_agg_route_present = True + if NEI_IPv6_AGG_ROUTE in nei_show_neigh_v6: + ipv6_agg_route_present = True + assert ipv4_agg_route_present is True + assert ipv6_agg_route_present is True + + # verify individual routes are not being received + ipv4_route_present = False + ipv6_route_present = False + if nei_ipv4_route_1 in nei_show_neigh_v4: + ipv4_route_present = True + if nei_ipv6_route_1 in nei_show_neigh_v6: + ipv6_route_present = True + if nei_ipv4_route_2 in nei_show_neigh_v4: + ipv4_route_present = True + if nei_ipv6_route_2 in nei_show_neigh_v6: + ipv6_route_present = True + assert ipv4_route_present is False + assert ipv6_route_present is False + + # aggregate directly connected routes with as-set + cmd = 'vtysh{} -c "config" -c "router bgp {}" -c "address-family ipv4 unicast" \ + -c "no aggregate-address {} summary-only" -c "aggregate-address {} as-set summary-only" \ + -c "address-family ipv6 unicast" -c "no aggregate-address {} summary-only" \ + -c "aggregate-address {} as-set summary-only"'.format(setup['cli_options'], setup['dut_asn'], + NEI_IPv4_AGG_ROUTE, NEI_IPv4_AGG_ROUTE, + NEI_IPv6_AGG_ROUTE, NEI_IPv6_AGG_ROUTE) + setup['duthost'].shell(cmd, module_ignore_errors=True) + + cmd = 'vtysh{} -c "clear bgp * soft"'.format(setup['cli_options']) + setup['duthost'].shell(cmd, module_ignore_errors=True) + time.sleep(establish_bgp_session_time) + + logger.info("DUT Config After Aggregation With AS-set: {}".format(setup['duthost'].shell("show run bgp", + module_ignore_errors=True)['stdout'])) + + # verify routes are shared as expected + cmd = "show ip bgp neighbors {} received-routes".format(setup['dut_ip_v4']) + nei_show_neigh_v4 = setup['neighhost'].shell(cmd, module_ignore_errors=True)['stdout'] + cmd = "show ipv6 bgp neighbors {} received-routes".format(setup['dut_ip_v6']) + nei_show_neigh_v6 = setup['neighhost'].shell(cmd, module_ignore_errors=True)['stdout'] + logger.debug("BGP Neighbors IPv4: {}\n\nBGP Neighbors IPv6: {}".format(nei_show_neigh_v4, nei_show_neigh_v6)) + ipv4_agg_route_present = False + ipv6_agg_route_present = False + if NEI_IPv4_AGG_ROUTE in nei_show_neigh_v4: + ipv4_agg_route_present = True + if NEI_IPv6_AGG_ROUTE in nei_show_neigh_v6: + ipv6_agg_route_present = True + assert ipv4_agg_route_present is True + assert ipv6_agg_route_present is True + + # verify individual routes are not being received + ipv4_route_present = False + ipv6_route_present = False + if nei_ipv4_route_1 in nei_show_neigh_v4: + ipv4_route_present = True + if nei_ipv6_route_1 in nei_show_neigh_v6: + ipv6_route_present = True + if nei_ipv4_route_2 in nei_show_neigh_v4: + ipv4_route_present = True + if nei_ipv6_route_2 in nei_show_neigh_v6: + ipv6_route_present = True + assert ipv4_route_present is False + assert ipv6_route_present is False From 8dadefd76819db81a4b801540e036617d55d1694 Mon Sep 17 00:00:00 2001 From: Azarack Date: Tue, 19 Mar 2024 17:21:32 +0000 Subject: [PATCH 02/10] debug prints --- tests/bgp/test_route_aggregation.py | 55 +++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/tests/bgp/test_route_aggregation.py b/tests/bgp/test_route_aggregation.py index c9baee0c05..dc8e4f59e6 100644 --- a/tests/bgp/test_route_aggregation.py +++ b/tests/bgp/test_route_aggregation.py @@ -110,25 +110,74 @@ def setup(tbinfo, duthosts, enum_frontend_dut_hostname, nbrhosts, enum_rand_one_ def test_ebgp_route_aggregation(setup): + logger.debug("DUT BGP Sum: {}".format(setup['duthost'].shell("show ip bgp summary", + module_ignore_errors=True)['stdout'])) + logger.info("Neigh BGP Sum: {}".format(setup['neighhost'].shell("show ip bgp summary", + module_ignore_errors=True)['stdout'])) + logger.info("Neigh BGPv6 Sum: {}".format(setup['neighhost'].shell("show ipv6 bgp summary", + module_ignore_errors=True)['stdout'])) + + logger.debug("DUT BGP route: {}".format(setup['duthost'].shell("show ip route", + module_ignore_errors=True)['stdout'])) + logger.debug("DUT BGP IPv6 route: {}".format(setup['duthost'].shell("show ipv6 route", + module_ignore_errors=True)['stdout'])) + logger.debug("Neigh BGP route: {}".format(setup['neighhost'].shell("show ip route", + module_ignore_errors=True)['stdout'])) + logger.info("Neigh BGP IPv6 route: {}".format(setup['neighhost'].shell("show ipv6 route", + module_ignore_errors=True)['stdout'])) + + # # cmd = "show ip bgp neighbors {} received-routes".format(setup['dut_ip_v4']) + # cmd = "show ip route | grep via {}".format(setup['dut_ip_v4']) + # nei_show_neigh_v4 = setup['neighhost'].shell(cmd, module_ignore_errors=True)['stdout'] + # # cmd = "show ipv6 bgp neighbors {} received-routes".format(setup['dut_ip_v6']) + # cmd = "show ipv6 route | grep via {}".format(setup['dut_ip_v6']) + # nei_show_neigh_v6 = setup['neighhost'].shell(cmd, module_ignore_errors=True)['stdout'] + # logger.info("BGP Neighbors IPv4: {}\n\nBGP Neighbors IPv6: {}".format(nei_show_neigh_v4, nei_show_neigh_v6)) + + # aggregate directly connected routes cmd = 'vtysh{} -c "config" -c "router bgp {}" -c "address-family ipv4 unicast" \ -c "aggregate-address {} summary-only" -c "address-family ipv6 unicast" \ -c "aggregate-address {} summary-only"'.format(setup['cli_options'], setup['dut_asn'], NEI_IPv4_AGG_ROUTE, NEI_IPv6_AGG_ROUTE) - setup['duthost'].shell(cmd, module_ignore_errors=True) + logger.debug(setup['duthost'].shell(cmd, module_ignore_errors=True)) - cmd = 'vtysh{} -c "clear bgp * soft"'.format(setup['cli_options']) + cmd = 'vtysh{} -c "clear bgp *"'.format(setup['cli_options']) setup['duthost'].shell(cmd, module_ignore_errors=True) + cmd = 'vtysh -c "clear bgp *"' + setup['neighhost'].shell(cmd, module_ignore_errors=True) time.sleep(establish_bgp_session_time) logger.debug("DUT Config After Aggregation: {}".format(setup['duthost'].shell("show run bgp", module_ignore_errors=True)['stdout'])) + logger.info("Neigh Config After Aggregation: {}".format(setup['neighhost'].shell("show run bgp", + module_ignore_errors=True)['stdout'])) + logger.debug("DUT BGP Sum: {}".format(setup['duthost'].shell("show ip bgp summary", + module_ignore_errors=True)['stdout'])) + logger.info("Neigh BGP Sum: {}".format(setup['neighhost'].shell("show ip bgp summary", + module_ignore_errors=True)['stdout'])) + logger.info("Neigh BGPv6 Sum: {}".format(setup['neighhost'].shell("show ipv6 bgp summary", + module_ignore_errors=True)['stdout'])) + + logger.debug("DUT BGP route: {}".format(setup['duthost'].shell("show ip route", + module_ignore_errors=True)['stdout'])) + logger.debug("DUT BGP IPv6 route: {}".format(setup['duthost'].shell("show ipv6 route", + module_ignore_errors=True)['stdout'])) + logger.debug("Neigh BGP route: {}".format(setup['neighhost'].shell("show ip route", + module_ignore_errors=True)['stdout'])) + logger.info("Neigh BGP IPv6 route: {}".format(setup['neighhost'].shell("show ipv6 route", + module_ignore_errors=True)['stdout'])) cmd = "show ip bgp neighbors {} received-routes".format(setup['dut_ip_v4']) + logger.info(setup['neighhost'].shell(cmd, module_ignore_errors=True)) + cmd = "show ip route | grep \"via {}\"".format(setup['dut_ip_v4']) nei_show_neigh_v4 = setup['neighhost'].shell(cmd, module_ignore_errors=True)['stdout'] cmd = "show ipv6 bgp neighbors {} received-routes".format(setup['dut_ip_v6']) + logger.info(setup['neighhost'].shell(cmd, module_ignore_errors=True)) + cmd = "show ipv6 route | grep \"via {}\"".format(setup['dut_ip_v6']) nei_show_neigh_v6 = setup['neighhost'].shell(cmd, module_ignore_errors=True)['stdout'] - logger.debug("BGP Neighbors IPv4: {}\n\nBGP Neighbors IPv6: {}".format(nei_show_neigh_v4, nei_show_neigh_v6)) + logger.info("BGP Neighbors IPv4: {}\n\nBGP Neighbors IPv6: {}".format(nei_show_neigh_v4, nei_show_neigh_v6)) + logger.info("Neigh agg route: {} v6: {} dut ipv6 addr: {}".format(NEI_IPv4_AGG_ROUTE, NEI_IPv6_AGG_ROUTE, setup['dut_ip_v6'])) ipv4_agg_route_present = False ipv6_agg_route_present = False if NEI_IPv4_AGG_ROUTE in nei_show_neigh_v4: From 55c0d1e3ef8184a3fedf2cad889c015c5dabbd6d Mon Sep 17 00:00:00 2001 From: Azarack Date: Tue, 19 Mar 2024 17:52:21 +0000 Subject: [PATCH 03/10] adding id template --- tests/bgp/templates/bgp_id.template | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 tests/bgp/templates/bgp_id.template diff --git a/tests/bgp/templates/bgp_id.template b/tests/bgp/templates/bgp_id.template new file mode 100644 index 0000000000..09e68b310c --- /dev/null +++ b/tests/bgp/templates/bgp_id.template @@ -0,0 +1,4 @@ +Value router_id (\d+.\d+.\d+.\d+) + +Start + ^BGP router identifier\s+${router_id} \ No newline at end of file From a89ba54335aa176b10634b272d6d5c8fe455bad0 Mon Sep 17 00:00:00 2001 From: Azarack Date: Tue, 23 Apr 2024 20:11:12 +0000 Subject: [PATCH 04/10] rewrite of test case --- docs/testplan/BGP-Route-Aggregation.md | 56 ++++ tests/bgp/conftest.py | 74 ++++++ tests/bgp/test_route_aggregation.py | 346 +++++++++---------------- 3 files changed, 259 insertions(+), 217 deletions(-) create mode 100644 docs/testplan/BGP-Route-Aggregation.md diff --git a/docs/testplan/BGP-Route-Aggregation.md b/docs/testplan/BGP-Route-Aggregation.md new file mode 100644 index 0000000000..fcc240541d --- /dev/null +++ b/docs/testplan/BGP-Route-Aggregation.md @@ -0,0 +1,56 @@ +[Overview](#overview) + - [Scope](#scope) + - [Testbed](#testbed) +- [Setup configuration](#setup-configuration) +- [Test cases](#test-cases) + +# Test name + +BGP Route Aggregation + +## Overview + +The goal of this test is to verify that summary-only, as-set summary-only, and suppress map route aggregation +operates as expected. + +### Scope + +The test is targeting a running SONIC system with fully functioning configuration. The purpose of the test is to test route aggregation. + +### Related DUT CLI commands + +| Command | Comment | +| ------- | ------- | +|Configuration commands| +| N/A | | +|Show commands| +| show ip bgp summary | Dispaly current memory statistics, can be done with ipv6 too | + +### Related DUT configuration files + +N/A + +### Related SAI APIs + +N/A + +## Test structure +### Setup configuration + +This test requires BGP neighbors to be configured and established. + +### Configuration scripts + +N/A + +## Test cases +### Test case #1 - Route Aggregation + +#### Test objective + +Step 1: Configure DUT to use summary-only route aggregation +Step 2: Verify expected number of routes are shared to neighbor +Step 3: Configure DUT to use as-set summary-only route aggregation +Step 4: Verify expected number of routes are shared to neighbor +Step 5: Configure prefix list and route map and use sto aggregate routes +Step 6: Verify expected number of routes are shared to neighbor diff --git a/tests/bgp/conftest.py b/tests/bgp/conftest.py index 51ca412636..c5a1bfdb2b 100644 --- a/tests/bgp/conftest.py +++ b/tests/bgp/conftest.py @@ -706,3 +706,77 @@ def set_timeout_for_bgpmon(duthost): plt_reboot_ctrl = get_plt_reboot_ctrl(duthost, 'test_bgpmon.py', 'cold') if plt_reboot_ctrl: MAX_TIME_FOR_BGPMON = plt_reboot_ctrl.get('timeout', 180) + + +@pytest.fixture(scope='session') +def gather_info(tbinfo, duthost, nbrhosts): + asic_index = random.choice(duthost.get_frontend_asic_ids()) + logger.debug(f"ASIC index: {asic_index}") + if duthost.is_multi_asic: + cli_options = " -n " + duthost.get_namespace_from_asic_id(asic_index) + else: + cli_options = '' + dut_asn = tbinfo['topo']['properties']['configuration_properties']['common']['dut_asn'] + + neigh = duthost.shell("show lldp table")['stdout'].split("\n")[3].split()[1] + logger.debug("neigh: {}".format(neigh)) + skip_hosts = duthost.get_asic_namespace_list() + + # verify bgp neighbor relationship is established + bgp_facts = duthost.bgp_facts(instance_id=asic_index)['ansible_facts'] + for k, v in bgp_facts['bgp_neighbors'].items(): + if v['description'].lower() not in skip_hosts: + if v['description'] == neigh: + if v['ip_version'] == 4: + neigh_ip_v4 = k + peer_group_v4 = v['peer group'] + elif v['ip_version'] == 6: + neigh_ip_v6 = k + peer_group_v6 = v['peer group'] + assert v['state'] == 'established' + + dut_ip_v4 = tbinfo['topo']['properties']['configuration'][neigh]['bgp']['peers'][dut_asn][0] + dut_ip_v6 = tbinfo['topo']['properties']['configuration'][neigh]['bgp']['peers'][dut_asn][1].lower() + + # capture route summary on neighbor + cmd = 'vtysh -c "show bgp ipv4 all neighbors {} advertised-routes" -c "show bgp ipv6 all neighbors {} \ + advertised-routes" -c "show ip bgp summary" -c "show ip bgp neighbors {}" \ + -c "show bgp ipv6 neighbors {}"'.format(dut_ip_v4, dut_ip_v6, dut_ip_v4, dut_ip_v6) + logger.debug(nbrhosts[neigh]["host"].shell(cmd, module_ignore_errors=True)['stdout']) + + ipv4_sum = duthost.shell("show ip bgp summary", module_ignore_errors=True)['stdout'] + ipv6_sum = duthost.shell("show ipv6 bgp summary", module_ignore_errors=True)['stdout'] + ipv4_num_neigh = re.findall("Total number of neighbors (\\d+)", ipv4_sum)[0] + ipv6_num_neigh = re.findall("Total number of neighbors (\\d+)", ipv6_sum)[0] + + setup_info = { + 'duthost': duthost, + 'neighhost': nbrhosts[neigh]["host"], + 'neigh': neigh, + 'dut_asn': dut_asn, + 'dut_ip_v4': dut_ip_v4, + 'dut_ip_v6': dut_ip_v6, + 'neigh_ip_v4': neigh_ip_v4, + 'neigh_ip_v6': neigh_ip_v6, + 'peer_group_v4': peer_group_v4, + 'peer_group_v6': peer_group_v6, + 'cli_options': cli_options, + 'asic_index': asic_index, + 'base_v4_neigh': ipv4_num_neigh, + 'base_v6_neigh': ipv6_num_neigh + } + + logger.debug("DUT Config After Setup: {}".format(duthost.shell("show run bgp", + module_ignore_errors=True)['stdout'])) + + yield setup_info + + # restore config to original state + config_reload(duthost, wait=60) + + # verify sessions are established + bgp_facts = duthost.bgp_facts(instance_id=asic_index)['ansible_facts'] + for k, v in bgp_facts['bgp_neighbors'].items(): + if v['description'] == neigh: + logger.debug(v['description']) + assert v['state'] == 'established' diff --git a/tests/bgp/test_route_aggregation.py b/tests/bgp/test_route_aggregation.py index dc8e4f59e6..f4c1ec4f3f 100644 --- a/tests/bgp/test_route_aggregation.py +++ b/tests/bgp/test_route_aggregation.py @@ -17,8 +17,6 @@ import pytest import time import logging -import re -from tests.common.config_reload import config_reload pytestmark = [ pytest.mark.topology('t2') @@ -26,222 +24,136 @@ logger = logging.getLogger(__name__) -NEI_IPv4_AGG_ROUTE = "192.168.0.0/16" -NEI_IPv6_AGG_ROUTE = "20c0:a800::/24" -establish_bgp_session_time = 60 -nei_ipv4_route_1 = "192.168.96.0/25" -nei_ipv4_route_2 = "192.168.97.0/25" -nei_ipv6_route_1 = "20c0:a851::/64" -nei_ipv6_route_2 = "20c0:a852::/64" - - -@pytest.fixture(scope='module') -def setup(tbinfo, duthosts, enum_frontend_dut_hostname, nbrhosts, enum_rand_one_frontend_asic_index): - duthost = duthosts[enum_frontend_dut_hostname] - asic_index = enum_rand_one_frontend_asic_index - if duthost.is_multi_asic: - cli_options = " -n " + duthost.get_namespace_from_asic_id(asic_index) - else: - cli_options = '' - dut_asn = tbinfo['topo']['properties']['configuration_properties']['common']['dut_asn'] - - neigh = duthost.shell("show lldp table")['stdout'].split("\n")[3].split()[1] - logger.debug("neigh: {}".format(neigh)) - skip_hosts = duthost.get_asic_namespace_list() - - # verify bgp neighbor relationship is established - bgp_facts = duthost.bgp_facts(instance_id=asic_index)['ansible_facts'] - for k, v in bgp_facts['bgp_neighbors'].items(): - if v['description'].lower() not in skip_hosts: - if v['description'] == neigh: - if v['ip_version'] == 4: - neigh_ip_v4 = k - peer_group_v4 = v['peer group'] - elif v['ip_version'] == 6: - neigh_ip_v6 = k - peer_group_v6 = v['peer group'] - assert v['state'] == 'established' - - dut_ip_v4 = tbinfo['topo']['properties']['configuration'][neigh]['bgp']['peers'][dut_asn][0] - dut_ip_v6 = tbinfo['topo']['properties']['configuration'][neigh]['bgp']['peers'][dut_asn][1].lower() - - # capture route summary on neighbor - cmd = 'vtysh -c "show bgp ipv4 all neighbors {} advertised-routes" -c "show bgp ipv6 all neighbors {} \ - advertised-routes" -c "show ip bgp summary" -c "show ip bgp neighbors {}" \ - -c "show bgp ipv6 neighbors {}"'.format(dut_ip_v4, dut_ip_v6, dut_ip_v4, dut_ip_v6) - logger.debug(nbrhosts[neigh]["host"].shell(cmd, module_ignore_errors=True)['stdout']) - - ipv4_sum = duthost.shell("show ip bgp summary", module_ignore_errors=True)['stdout'] - ipv6_sum = duthost.shell("show ipv6 bgp summary", module_ignore_errors=True)['stdout'] - ipv4_num_neigh = re.findall("Total number of neighbors (\\d+)", ipv4_sum)[0] - ipv6_num_neigh = re.findall("Total number of neighbors (\\d+)", ipv6_sum)[0] - - setup_info = { - 'duthost': duthost, - 'neighhost': nbrhosts[neigh]["host"], - 'neigh': neigh, - 'dut_asn': dut_asn, - 'dut_ip_v4': dut_ip_v4, - 'dut_ip_v6': dut_ip_v6, - 'neigh_ip_v4': neigh_ip_v4, - 'neigh_ip_v6': neigh_ip_v6, - 'peer_group_v4': peer_group_v4, - 'peer_group_v6': peer_group_v6, - 'cli_options': cli_options, - 'asic_index': asic_index, - 'base_v4_neigh': ipv4_num_neigh, - 'base_v6_neigh': ipv6_num_neigh - } - - logger.debug("DUT Config After Setup: {}".format(duthost.shell("show run bgp", - module_ignore_errors=True)['stdout'])) - - yield setup_info - - # restore config to original state - config_reload(duthost, wait=60) - - # verify sessions are established - bgp_facts = duthost.bgp_facts(instance_id=asic_index)['ansible_facts'] - for k, v in bgp_facts['bgp_neighbors'].items(): - if v['description'] == neigh: - logger.debug(v['description']) - assert v['state'] == 'established' - - -def test_ebgp_route_aggregation(setup): - logger.debug("DUT BGP Sum: {}".format(setup['duthost'].shell("show ip bgp summary", - module_ignore_errors=True)['stdout'])) - logger.info("Neigh BGP Sum: {}".format(setup['neighhost'].shell("show ip bgp summary", - module_ignore_errors=True)['stdout'])) - logger.info("Neigh BGPv6 Sum: {}".format(setup['neighhost'].shell("show ipv6 bgp summary", - module_ignore_errors=True)['stdout'])) - - logger.debug("DUT BGP route: {}".format(setup['duthost'].shell("show ip route", - module_ignore_errors=True)['stdout'])) - logger.debug("DUT BGP IPv6 route: {}".format(setup['duthost'].shell("show ipv6 route", - module_ignore_errors=True)['stdout'])) - logger.debug("Neigh BGP route: {}".format(setup['neighhost'].shell("show ip route", - module_ignore_errors=True)['stdout'])) - logger.info("Neigh BGP IPv6 route: {}".format(setup['neighhost'].shell("show ipv6 route", - module_ignore_errors=True)['stdout'])) - - # # cmd = "show ip bgp neighbors {} received-routes".format(setup['dut_ip_v4']) - # cmd = "show ip route | grep via {}".format(setup['dut_ip_v4']) - # nei_show_neigh_v4 = setup['neighhost'].shell(cmd, module_ignore_errors=True)['stdout'] - # # cmd = "show ipv6 bgp neighbors {} received-routes".format(setup['dut_ip_v6']) - # cmd = "show ipv6 route | grep via {}".format(setup['dut_ip_v6']) - # nei_show_neigh_v6 = setup['neighhost'].shell(cmd, module_ignore_errors=True)['stdout'] - # logger.info("BGP Neighbors IPv4: {}\n\nBGP Neighbors IPv6: {}".format(nei_show_neigh_v4, nei_show_neigh_v6)) - - - # aggregate directly connected routes - cmd = 'vtysh{} -c "config" -c "router bgp {}" -c "address-family ipv4 unicast" \ - -c "aggregate-address {} summary-only" -c "address-family ipv6 unicast" \ - -c "aggregate-address {} summary-only"'.format(setup['cli_options'], setup['dut_asn'], NEI_IPv4_AGG_ROUTE, - NEI_IPv6_AGG_ROUTE) - logger.debug(setup['duthost'].shell(cmd, module_ignore_errors=True)) - - cmd = 'vtysh{} -c "clear bgp *"'.format(setup['cli_options']) - setup['duthost'].shell(cmd, module_ignore_errors=True) +NEI_IPv4_AGG_ROUTE = "1.1.0.0/16" +NEI_IPv6_AGG_ROUTE = "1:1:1::/48" +establish_bgp_session_time = 120 + + +def agg_configuration(config, asn, duthost, neighbor, cli_options, commandv4, commandv6): + remove_tag = "" + if not config: + remove_tag = "no " + cmd = 'vtysh{} -c "config" -c "router bgp {}" -c "{}address-family ipv4 unicast" \ + -c "aggregate-address {} {}" -c "{}address-family ipv6 unicast" \ + -c "aggregate-address {} {}"'.format(cli_options, asn, remove_tag, NEI_IPv4_AGG_ROUTE, commandv4, remove_tag, + NEI_IPv6_AGG_ROUTE, commandv6) + logger.debug(duthost.shell(cmd, module_ignore_errors=True)) + cmd = 'vtysh{} -c "clear bgp *"'.format(cli_options) + duthost.shell(cmd, module_ignore_errors=True) cmd = 'vtysh -c "clear bgp *"' - setup['neighhost'].shell(cmd, module_ignore_errors=True) + neighbor.shell(cmd, module_ignore_errors=True) time.sleep(establish_bgp_session_time) - logger.debug("DUT Config After Aggregation: {}".format(setup['duthost'].shell("show run bgp", - module_ignore_errors=True)['stdout'])) - logger.info("Neigh Config After Aggregation: {}".format(setup['neighhost'].shell("show run bgp", - module_ignore_errors=True)['stdout'])) - logger.debug("DUT BGP Sum: {}".format(setup['duthost'].shell("show ip bgp summary", - module_ignore_errors=True)['stdout'])) - logger.info("Neigh BGP Sum: {}".format(setup['neighhost'].shell("show ip bgp summary", - module_ignore_errors=True)['stdout'])) - logger.info("Neigh BGPv6 Sum: {}".format(setup['neighhost'].shell("show ipv6 bgp summary", - module_ignore_errors=True)['stdout'])) - - logger.debug("DUT BGP route: {}".format(setup['duthost'].shell("show ip route", - module_ignore_errors=True)['stdout'])) - logger.debug("DUT BGP IPv6 route: {}".format(setup['duthost'].shell("show ipv6 route", - module_ignore_errors=True)['stdout'])) - logger.debug("Neigh BGP route: {}".format(setup['neighhost'].shell("show ip route", - module_ignore_errors=True)['stdout'])) - logger.info("Neigh BGP IPv6 route: {}".format(setup['neighhost'].shell("show ipv6 route", - module_ignore_errors=True)['stdout'])) - - cmd = "show ip bgp neighbors {} received-routes".format(setup['dut_ip_v4']) - logger.info(setup['neighhost'].shell(cmd, module_ignore_errors=True)) - cmd = "show ip route | grep \"via {}\"".format(setup['dut_ip_v4']) - nei_show_neigh_v4 = setup['neighhost'].shell(cmd, module_ignore_errors=True)['stdout'] - cmd = "show ipv6 bgp neighbors {} received-routes".format(setup['dut_ip_v6']) - logger.info(setup['neighhost'].shell(cmd, module_ignore_errors=True)) - cmd = "show ipv6 route | grep \"via {}\"".format(setup['dut_ip_v6']) - nei_show_neigh_v6 = setup['neighhost'].shell(cmd, module_ignore_errors=True)['stdout'] - logger.info("BGP Neighbors IPv4: {}\n\nBGP Neighbors IPv6: {}".format(nei_show_neigh_v4, nei_show_neigh_v6)) - logger.info("Neigh agg route: {} v6: {} dut ipv6 addr: {}".format(NEI_IPv4_AGG_ROUTE, NEI_IPv6_AGG_ROUTE, setup['dut_ip_v6'])) - ipv4_agg_route_present = False - ipv6_agg_route_present = False - if NEI_IPv4_AGG_ROUTE in nei_show_neigh_v4: - ipv4_agg_route_present = True - if NEI_IPv6_AGG_ROUTE in nei_show_neigh_v6: - ipv6_agg_route_present = True - assert ipv4_agg_route_present is True - assert ipv6_agg_route_present is True - - # verify individual routes are not being received - ipv4_route_present = False - ipv6_route_present = False - if nei_ipv4_route_1 in nei_show_neigh_v4: - ipv4_route_present = True - if nei_ipv6_route_1 in nei_show_neigh_v6: - ipv6_route_present = True - if nei_ipv4_route_2 in nei_show_neigh_v4: - ipv4_route_present = True - if nei_ipv6_route_2 in nei_show_neigh_v6: - ipv6_route_present = True - assert ipv4_route_present is False - assert ipv6_route_present is False - - # aggregate directly connected routes with as-set - cmd = 'vtysh{} -c "config" -c "router bgp {}" -c "address-family ipv4 unicast" \ - -c "no aggregate-address {} summary-only" -c "aggregate-address {} as-set summary-only" \ - -c "address-family ipv6 unicast" -c "no aggregate-address {} summary-only" \ - -c "aggregate-address {} as-set summary-only"'.format(setup['cli_options'], setup['dut_asn'], - NEI_IPv4_AGG_ROUTE, NEI_IPv4_AGG_ROUTE, - NEI_IPv6_AGG_ROUTE, NEI_IPv6_AGG_ROUTE) - setup['duthost'].shell(cmd, module_ignore_errors=True) - - cmd = 'vtysh{} -c "clear bgp * soft"'.format(setup['cli_options']) - setup['duthost'].shell(cmd, module_ignore_errors=True) - time.sleep(establish_bgp_session_time) - logger.info("DUT Config After Aggregation With AS-set: {}".format(setup['duthost'].shell("show run bgp", - module_ignore_errors=True)['stdout'])) - - # verify routes are shared as expected - cmd = "show ip bgp neighbors {} received-routes".format(setup['dut_ip_v4']) - nei_show_neigh_v4 = setup['neighhost'].shell(cmd, module_ignore_errors=True)['stdout'] - cmd = "show ipv6 bgp neighbors {} received-routes".format(setup['dut_ip_v6']) - nei_show_neigh_v6 = setup['neighhost'].shell(cmd, module_ignore_errors=True)['stdout'] - logger.debug("BGP Neighbors IPv4: {}\n\nBGP Neighbors IPv6: {}".format(nei_show_neigh_v4, nei_show_neigh_v6)) - ipv4_agg_route_present = False - ipv6_agg_route_present = False - if NEI_IPv4_AGG_ROUTE in nei_show_neigh_v4: - ipv4_agg_route_present = True - if NEI_IPv6_AGG_ROUTE in nei_show_neigh_v6: - ipv6_agg_route_present = True - assert ipv4_agg_route_present is True - assert ipv6_agg_route_present is True - - # verify individual routes are not being received - ipv4_route_present = False - ipv6_route_present = False - if nei_ipv4_route_1 in nei_show_neigh_v4: - ipv4_route_present = True - if nei_ipv6_route_1 in nei_show_neigh_v6: - ipv6_route_present = True - if nei_ipv4_route_2 in nei_show_neigh_v4: - ipv4_route_present = True - if nei_ipv6_route_2 in nei_show_neigh_v6: - ipv6_route_present = True - assert ipv4_route_present is False - assert ipv6_route_present is False +def verify_route_agg(neighbor, num_matches, suppress): + output = neighbor.shell("show ip bgp summary", module_ignore_errors=True)['stdout'] + logger.debug(output) + assert num_matches == output.split("\n")[11].split()[9] + output = neighbor.shell("show ipv6 bgp summary", module_ignore_errors=True)['stdout'] + logger.debug(output) + assert num_matches == output.split("\n")[11].split()[9] + output = neighbor.shell("show ip route | grep \"*1.1.\"", module_ignore_errors=True)['stdout'] + logger.debug(output) + assert NEI_IPv4_AGG_ROUTE in output + assert "1.1.1.0/24" not in output + assert "1.1.2.0/24" not in output + assert "1.1.3.0/24" not in output + output = neighbor.shell("show ipv6 route | grep \"*1:1:\"", module_ignore_errors=True)['stdout'] + logger.debug(output) + assert NEI_IPv6_AGG_ROUTE in output + assert "1:1:1:1::/64" not in output + assert "1:1:1:2::/64" not in output + assert "1:1:1:3::/64" not in output + if not suppress: + assert "1.1.4.0/24" not in output + assert "1.1.5.0/24" not in output + assert "1:1:1:4::/64" not in output + assert "1:1:1:5::/64" not in output + + +def test_ebgp_route_aggregation(gather_info): + # Configure and Advertise Loopback Networks on DUT + gather_info['duthost'].shell("sudo config loopback add Loopback11") + gather_info['duthost'].shell("sudo config interface ip add Loopback11 1.1.1.1/24") + gather_info['duthost'].shell("sudo config interface ip add Loopback11 1:1:1:1::/64") + gather_info['duthost'].shell("sudo config loopback add Loopback12") + gather_info['duthost'].shell("sudo config interface ip add Loopback12 1.1.2.1/24") + gather_info['duthost'].shell("sudo config interface ip add Loopback12 1:1:1:2::/64") + gather_info['duthost'].shell("sudo config loopback add Loopback13") + gather_info['duthost'].shell("sudo config interface ip add Loopback13 1.1.3.1/24") + gather_info['duthost'].shell("sudo config interface ip add Loopback13 1:1:1:3::/64") + gather_info['duthost'].shell("sudo config loopback add Loopback14") + gather_info['duthost'].shell("sudo config interface ip add Loopback14 1.1.4.1/24") + gather_info['duthost'].shell("sudo config interface ip add Loopback14 1:1:1:4::/64") + gather_info['duthost'].shell("sudo config loopback add Loopback15") + gather_info['duthost'].shell("sudo config interface ip add Loopback15 1.1.5.1/24") + gather_info['duthost'].shell("sudo config interface ip add Loopback15 1:1:1:5::/64") + + cmd = 'vtysh{} -c "config" -c "router bgp {}" -c "address-family ipv4 unicast" \ + -c "network 1.1.1.0/24" -c "network 1.1.2.0/24" -c "network 1.1.3.0/24" -c "network 1.1.4.0/24" \ + -c "network 1.1.5.0/24" -c "address-family ipv6 unicast" -c "network 1:1:1:1::/64" -c "network 1:1:1:2::/64"\ + -c "network 1:1:1:3::/64" -c "network 1:1:1:4::/64" -c "network 1:1:1:5::/64"'.format( + gather_info['cli_options'], gather_info['dut_asn']) + logger.debug(gather_info['duthost'].shell(cmd, module_ignore_errors=True)) + logger.debug(gather_info['neighhost'].shell("show ip bgp summary", module_ignore_errors=True)['stdout']) + output = gather_info['neighhost'].shell("show ip bgp summary", module_ignore_errors=True)['stdout'].split("\n")[11] + assert "6" == output.split()[9] + output = gather_info['neighhost'].shell("show ipv6 bgp summary", module_ignore_errors=True)['stdout'].split("\n") + assert "6" == output[11].split()[9] + + # Configure summary-only route aggregation + agg_configuration(True, gather_info['dut_asn'], gather_info['duthost'], gather_info['neighhost'], + gather_info['cli_options'], "summary-only", "summary-only") + verify_route_agg(gather_info['neighhost'], "2", False) + + # Remove the aggregate configuration + agg_configuration(False, gather_info['dut_asn'], gather_info['duthost'], gather_info['neighhost'], + gather_info['cli_options'], "summary-only", "summary-only") + + # Configure as-set summary-only route aggregation + agg_configuration(True, gather_info['dut_asn'], gather_info['duthost'], gather_info['neighhost'], + gather_info['cli_options'], "as-set summary-only", "as-set summary-only") + verify_route_agg(gather_info['neighhost'], "2", False) + + # Remove the aggregate configuration + agg_configuration(False, gather_info['dut_asn'], gather_info['duthost'], gather_info['neighhost'], + gather_info['cli_options'], "as-set summary-only", "as-set summary-only") + + # Configure route aggregation with suppress-map + # Create prefix lists to be used + cmd = 'vtysh{} -c "config" -c "ip prefix-list SUPPRESS_V4 permit 1.1.1.0/24" \ + -c "ip prefix-list SUPPRESS_V4 permit 1.1.2.0/24" -c "ip prefix-list SUPPRESS_V4 permit 1.1.3.0/24" \ + -c "ipv6 prefix-list SUPPRESS_V6 permit 1:1:1:1::/64" \ + -c "ipv6 prefix-list SUPPRESS_V6 permit 1:1:1:2::/64" \ + -c "ipv6 prefix-list SUPPRESS_V6 permit 1:1:1:3::/64"' \ + .format(gather_info['cli_options']) + gather_info['duthost'].shell(cmd, module_ignore_errors=True) + + # Create route maps + cmd = 'vtysh{} -c "config" -c "route-map SUPPRESS_RM_V4 permit 10" -c "match ip address prefix-list SUPPRESS_V4"' \ + .format(gather_info['cli_options']) + gather_info['duthost'].shell(cmd, module_ignore_errors=True) + cmd = 'vtysh{} -c "config" -c "route-map SUPPRESS_RM_V6 permit 10" \ + -c "match ipv6 address prefix-list SUPPRESS_V6"' \ + .format(gather_info['cli_options']) + gather_info['duthost'].shell(cmd, module_ignore_errors=True) + agg_configuration(True, gather_info['dut_asn'], gather_info['duthost'], gather_info['neighhost'], + gather_info['cli_options'], "suppress-map SUPPRESS_RM_V4", "suppress-map SUPPRESS_RM_V6") + logger.debug(gather_info['neighhost'].shell("show ip bgp summary", module_ignore_errors=True)['stdout']) + logger.debug(gather_info['neighhost'].shell("show ipv6 bgp summary", module_ignore_errors=True)['stdout']) + logger.debug(gather_info['duthost'].shell('vtysh -c "show run bgp"', module_ignore_errors=True)['stdout']) + verify_route_agg(gather_info['neighhost'], "4", True) + + # Remove config for suppress-map + agg_configuration(False, gather_info['dut_asn'], gather_info['duthost'], gather_info['neighhost'], + gather_info['cli_options'], "suppress-map SUPPRESS_RM_V4", "suppress-map SUPPRESS_RM_V6") + cmd = 'vtysh{} -c "config" -c "no route-map SUPPRESS_RM_V4 permit 10"'.format(gather_info['cli_options']) + gather_info['duthost'].shell(cmd, module_ignore_errors=True) + cmd = 'vtysh{} -c "config" -c "no route-map SUPPRESS_RM_V6 permit 10"'.format(gather_info['cli_options']) + gather_info['duthost'].shell(cmd, module_ignore_errors=True) + cmd = 'vtysh{} -c "config" -c "no ip prefix-list SUPPRESS_V4 permit 1.1.1.0/24" \ + -c "no ip prefix-list SUPPRESS_V4 permit 1.1.2.0/24" -c "no ip prefix-list SUPPRESS_V4 permit 1.1.3.0/24" \ + -c "no ipv6 prefix-list SUPPRESS_V6 permit 1:1:1:1::/64" \ + -c "no ipv6 prefix-list SUPPRESS_V6 permit 1:1:1:2::/64" \ + -c "no ipv6 prefix-list SUPPRESS_V6 permit 1:1:1:3::/64"' \ + .format(gather_info['cli_options']) From 8479e4542ae46eedc18d51eb4604c39477dae3e1 Mon Sep 17 00:00:00 2001 From: Azarack Date: Tue, 23 Apr 2024 20:19:49 +0000 Subject: [PATCH 05/10] fixing lint error --- tests/bgp/templates/bgp_id.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bgp/templates/bgp_id.template b/tests/bgp/templates/bgp_id.template index 09e68b310c..09228b8096 100644 --- a/tests/bgp/templates/bgp_id.template +++ b/tests/bgp/templates/bgp_id.template @@ -1,4 +1,4 @@ Value router_id (\d+.\d+.\d+.\d+) Start - ^BGP router identifier\s+${router_id} \ No newline at end of file + ^BGP router identifier\s+${router_id} From d9776944855a77c0a817989ac226027856316844 Mon Sep 17 00:00:00 2001 From: Azarack Date: Fri, 17 May 2024 19:43:56 +0000 Subject: [PATCH 06/10] fix lint --- tests/bgp/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bgp/conftest.py b/tests/bgp/conftest.py index a4f24fe9eb..42a359dfc4 100644 --- a/tests/bgp/conftest.py +++ b/tests/bgp/conftest.py @@ -781,7 +781,7 @@ def gather_info(tbinfo, duthost, nbrhosts): logger.debug(v['description']) assert v['state'] == 'established' - + @pytest.fixture(scope="module") def is_quagga(duthosts, enum_rand_one_per_hwsku_frontend_hostname): """Return True if current bgp is using Quagga.""" From 81037c4aab6435e05bad454351f3b221370223ec Mon Sep 17 00:00:00 2001 From: Azarack Date: Thu, 23 May 2024 16:43:29 +0000 Subject: [PATCH 07/10] adjustments for as-set --- tests/bgp/test_route_aggregation.py | 144 ++++++++++++++++------------ 1 file changed, 83 insertions(+), 61 deletions(-) diff --git a/tests/bgp/test_route_aggregation.py b/tests/bgp/test_route_aggregation.py index f4c1ec4f3f..c5e68b4011 100644 --- a/tests/bgp/test_route_aggregation.py +++ b/tests/bgp/test_route_aggregation.py @@ -1,12 +1,12 @@ """ Test BGP Route Aggregation -Step 1: Ensure EBGP neighborship between DUT and NEI_DUT -Step 2: Capture the route summary advertized on NEI_DUT -Step 3: Aggregate EBGP routes -Step 4: Verify aggregated EBGP routes on NEI_DUT -Step 5: Aggregate EBGP routes with 'as-set' -Step 6: Verify aggregated EBGP routes on NEI_DUT include AS-path +Step 1: Ensure eBGP neighborship between DUT and NEI_DUT +Step 2: Capture the route summary advertized to NEI_DUT +Step 3: Aggregate eBGP routes +Step 4: Verify aggregated eBGP routes to NEI_DUT +Step 5: Aggregate eBGP routes with 'as-set' +Step 6: Verify aggregated eBGP routes to NEI_DUT include AS-path Pass/Fail Criteria: An aggregate route is generated in all cases, a CLI knob option controls whether or not the specifics @@ -29,49 +29,61 @@ establish_bgp_session_time = 120 -def agg_configuration(config, asn, duthost, neighbor, cli_options, commandv4, commandv6): +def agg_configuration(config, asn, duthost, cli_options, commandv4, commandv6): remove_tag = "" if not config: remove_tag = "no " - cmd = 'vtysh{} -c "config" -c "router bgp {}" -c "{}address-family ipv4 unicast" \ - -c "aggregate-address {} {}" -c "{}address-family ipv6 unicast" \ - -c "aggregate-address {} {}"'.format(cli_options, asn, remove_tag, NEI_IPv4_AGG_ROUTE, commandv4, remove_tag, - NEI_IPv6_AGG_ROUTE, commandv6) + cmd = 'vtysh{} -c "config" -c "router bgp {}" -c "address-family ipv4 unicast" \ + -c "{}aggregate-address {} {}" -c "address-family ipv6 unicast" \ + -c "{}aggregate-address {} {}"'.format(cli_options, asn, remove_tag, NEI_IPv4_AGG_ROUTE, commandv4, remove_tag, + NEI_IPv6_AGG_ROUTE, commandv6) logger.debug(duthost.shell(cmd, module_ignore_errors=True)) cmd = 'vtysh{} -c "clear bgp *"'.format(cli_options) duthost.shell(cmd, module_ignore_errors=True) - cmd = 'vtysh -c "clear bgp *"' - neighbor.shell(cmd, module_ignore_errors=True) time.sleep(establish_bgp_session_time) -def verify_route_agg(neighbor, num_matches, suppress): - output = neighbor.shell("show ip bgp summary", module_ignore_errors=True)['stdout'] - logger.debug(output) - assert num_matches == output.split("\n")[11].split()[9] - output = neighbor.shell("show ipv6 bgp summary", module_ignore_errors=True)['stdout'] - logger.debug(output) - assert num_matches == output.split("\n")[11].split()[9] - output = neighbor.shell("show ip route | grep \"*1.1.\"", module_ignore_errors=True)['stdout'] +def verify_route_agg(dut, neigh_ip_v4, neigh_ip_v6, num_matches, suppress): + output = dut.shell('show ip bgp neighbors {} advertised-routes | grep -c "*> 1.1."'.format(neigh_ip_v4), + module_ignore_errors=True)['stdout'] logger.debug(output) - assert NEI_IPv4_AGG_ROUTE in output - assert "1.1.1.0/24" not in output - assert "1.1.2.0/24" not in output - assert "1.1.3.0/24" not in output - output = neighbor.shell("show ipv6 route | grep \"*1:1:\"", module_ignore_errors=True)['stdout'] + assert num_matches == output + output = dut.shell('show ipv6 bgp neighbors {} advertised-routes | grep -c "*> 1.1."'.format(neigh_ip_v6), + module_ignore_errors=True)['stdout'] logger.debug(output) - assert NEI_IPv6_AGG_ROUTE in output - assert "1:1:1:1::/64" not in output - assert "1:1:1:2::/64" not in output - assert "1:1:1:3::/64" not in output - if not suppress: - assert "1.1.4.0/24" not in output - assert "1.1.5.0/24" not in output - assert "1:1:1:4::/64" not in output - assert "1:1:1:5::/64" not in output + assert num_matches == output + + output4 = dut.shell('show ip bgp neighbors {} advertised-routes | grep "*> 1.1."'.format(neigh_ip_v4), + module_ignore_errors=True)['stdout'] + logger.debug(output4) + output6 = dut.shell('show ipv6 bgp neighbors {} advertised-routes | grep "*> 1.1."'.format(neigh_ip_v6), + module_ignore_errors=True)['stdout'] + logger.debug(output6) + if suppress: + assert "1.1.1.0/24" not in output4 + assert "1.1.2.0/24" not in output4 + assert "1:1:1:1::/64" not in output6 + assert "1:1:1:2::/64" not in output6 + + +def check_baseline(dut, neigh_ip_v4, neigh_ip_v6, base_v4, base_v6): + output = dut.shell('show ip bgp neighbors {} advertised-routes | grep -c "*>"'.format(neigh_ip_v4), + module_ignore_errors=True)['stdout'] + logger.debug("output: {}".format(output)) + assert int(base_v4) + 5 == int(output) + output = dut.shell('show ipv6 bgp neighbors {} advertised-routes | grep -c "*>"'.format(neigh_ip_v6), + module_ignore_errors=True)['stdout'] + logger.debug("output: {}".format(output)) + assert int(base_v6) + 5 == int(output) def test_ebgp_route_aggregation(gather_info): + # precheck number of routes + num_v4_routes = gather_info['duthost'].shell('show ip bgp neighbors {} advertised-routes | grep -c "*>"'.format( + gather_info['neigh_ip_v4']))['stdout'] + num_v6_routes = gather_info['duthost'].shell('show ipv6 bgp neighbors {} advertised-routes | grep -c "*>"'.format( + gather_info['neigh_ip_v6']))['stdout'] + # Configure and Advertise Loopback Networks on DUT gather_info['duthost'].shell("sudo config loopback add Loopback11") gather_info['duthost'].shell("sudo config interface ip add Loopback11 1.1.1.1/24") @@ -89,45 +101,54 @@ def test_ebgp_route_aggregation(gather_info): gather_info['duthost'].shell("sudo config interface ip add Loopback15 1.1.5.1/24") gather_info['duthost'].shell("sudo config interface ip add Loopback15 1:1:1:5::/64") + cmd = 'vtysh -c "config" -c "route-map AGG_TEST_1 permit 10" -c "set as-path prepend 11111" -c "exit" -c "end"' + logger.debug(gather_info['duthost'].shell(cmd, module_ignore_errors=True)) + cmd = 'vtysh -c "config" -c "route-map AGG_TEST_2 permit 10" -c "set as-path prepend 22222" -c "exit" -c "end"' + logger.debug(gather_info['duthost'].shell(cmd, module_ignore_errors=True)) cmd = 'vtysh{} -c "config" -c "router bgp {}" -c "address-family ipv4 unicast" \ - -c "network 1.1.1.0/24" -c "network 1.1.2.0/24" -c "network 1.1.3.0/24" -c "network 1.1.4.0/24" \ - -c "network 1.1.5.0/24" -c "address-family ipv6 unicast" -c "network 1:1:1:1::/64" -c "network 1:1:1:2::/64"\ - -c "network 1:1:1:3::/64" -c "network 1:1:1:4::/64" -c "network 1:1:1:5::/64"'.format( + -c "network 1.1.1.0/24 route-map AGG_TEST_1" -c "network 1.1.2.0/24 route-map AGG_TEST_1" \ + -c "network 1.1.3.0/24 route-map AGG_TEST_2" -c "network 1.1.4.0/24 route-map AGG_TEST_2" \ + -c "network 1.1.5.0/24" -c "address-family ipv6 unicast" -c "network 1:1:1:1::/64 route-map AGG_TEST_1" \ + -c "network 1:1:1:2::/64 route-map AGG_TEST_1" -c "network 1:1:1:3::/64 route-map AGG_TEST_2" \ + -c "network 1:1:1:4::/64 route-map AGG_TEST_2" -c "network 1:1:1:5::/64 route-map AGG_TEST_2"'.format( gather_info['cli_options'], gather_info['dut_asn']) logger.debug(gather_info['duthost'].shell(cmd, module_ignore_errors=True)) - logger.debug(gather_info['neighhost'].shell("show ip bgp summary", module_ignore_errors=True)['stdout']) - output = gather_info['neighhost'].shell("show ip bgp summary", module_ignore_errors=True)['stdout'].split("\n")[11] - assert "6" == output.split()[9] - output = gather_info['neighhost'].shell("show ipv6 bgp summary", module_ignore_errors=True)['stdout'].split("\n") - assert "6" == output[11].split()[9] + verify_route_agg(gather_info['duthost'], gather_info['neigh_ip_v4'], gather_info['neigh_ip_v6'], "5", False) + check_baseline(gather_info['duthost'], gather_info['neigh_ip_v4'], gather_info['neigh_ip_v6'], num_v4_routes, + num_v6_routes) # Configure summary-only route aggregation - agg_configuration(True, gather_info['dut_asn'], gather_info['duthost'], gather_info['neighhost'], + agg_configuration(True, gather_info['dut_asn'], gather_info['duthost'], gather_info['cli_options'], "summary-only", "summary-only") - verify_route_agg(gather_info['neighhost'], "2", False) + verify_route_agg(gather_info['duthost'], gather_info['neigh_ip_v4'], gather_info['neigh_ip_v6'], "1", False) # Remove the aggregate configuration - agg_configuration(False, gather_info['dut_asn'], gather_info['duthost'], gather_info['neighhost'], + agg_configuration(False, gather_info['dut_asn'], gather_info['duthost'], gather_info['cli_options'], "summary-only", "summary-only") + verify_route_agg(gather_info['duthost'], gather_info['neigh_ip_v4'], gather_info['neigh_ip_v6'], "5", False) + check_baseline(gather_info['duthost'], gather_info['neigh_ip_v4'], gather_info['neigh_ip_v6'], num_v4_routes, + num_v6_routes) # Configure as-set summary-only route aggregation - agg_configuration(True, gather_info['dut_asn'], gather_info['duthost'], gather_info['neighhost'], + agg_configuration(True, gather_info['dut_asn'], gather_info['duthost'], gather_info['cli_options'], "as-set summary-only", "as-set summary-only") - verify_route_agg(gather_info['neighhost'], "2", False) + verify_route_agg(gather_info['duthost'], gather_info['neigh_ip_v4'], gather_info['neigh_ip_v6'], "1", False) # Remove the aggregate configuration - agg_configuration(False, gather_info['dut_asn'], gather_info['duthost'], gather_info['neighhost'], + agg_configuration(False, gather_info['dut_asn'], gather_info['duthost'], gather_info['cli_options'], "as-set summary-only", "as-set summary-only") + verify_route_agg(gather_info['duthost'], gather_info['neigh_ip_v4'], gather_info['neigh_ip_v6'], "5", False) + check_baseline(gather_info['duthost'], gather_info['neigh_ip_v4'], gather_info['neigh_ip_v6'], num_v4_routes, + num_v6_routes) # Configure route aggregation with suppress-map # Create prefix lists to be used - cmd = 'vtysh{} -c "config" -c "ip prefix-list SUPPRESS_V4 permit 1.1.1.0/24" \ - -c "ip prefix-list SUPPRESS_V4 permit 1.1.2.0/24" -c "ip prefix-list SUPPRESS_V4 permit 1.1.3.0/24" \ + cmd = 'vtysh{} -c "config" -c "ip prefix-list SUPPRESS_V4 permit 1.1.1.1/24" \ + -c "ip prefix-list SUPPRESS_V4 permit 1.1.2.1/24" \ -c "ipv6 prefix-list SUPPRESS_V6 permit 1:1:1:1::/64" \ - -c "ipv6 prefix-list SUPPRESS_V6 permit 1:1:1:2::/64" \ - -c "ipv6 prefix-list SUPPRESS_V6 permit 1:1:1:3::/64"' \ + -c "ipv6 prefix-list SUPPRESS_V6 permit 1:1:1:2::/64"' \ .format(gather_info['cli_options']) - gather_info['duthost'].shell(cmd, module_ignore_errors=True) + logger.debug(gather_info['duthost'].shell(cmd, module_ignore_errors=True)) # Create route maps cmd = 'vtysh{} -c "config" -c "route-map SUPPRESS_RM_V4 permit 10" -c "match ip address prefix-list SUPPRESS_V4"' \ @@ -137,23 +158,24 @@ def test_ebgp_route_aggregation(gather_info): -c "match ipv6 address prefix-list SUPPRESS_V6"' \ .format(gather_info['cli_options']) gather_info['duthost'].shell(cmd, module_ignore_errors=True) - agg_configuration(True, gather_info['dut_asn'], gather_info['duthost'], gather_info['neighhost'], + agg_configuration(True, gather_info['dut_asn'], gather_info['duthost'], gather_info['cli_options'], "suppress-map SUPPRESS_RM_V4", "suppress-map SUPPRESS_RM_V6") logger.debug(gather_info['neighhost'].shell("show ip bgp summary", module_ignore_errors=True)['stdout']) logger.debug(gather_info['neighhost'].shell("show ipv6 bgp summary", module_ignore_errors=True)['stdout']) logger.debug(gather_info['duthost'].shell('vtysh -c "show run bgp"', module_ignore_errors=True)['stdout']) - verify_route_agg(gather_info['neighhost'], "4", True) + verify_route_agg(gather_info['duthost'], gather_info['neigh_ip_v4'], gather_info['neigh_ip_v6'], "4", True) # Remove config for suppress-map - agg_configuration(False, gather_info['dut_asn'], gather_info['duthost'], gather_info['neighhost'], + agg_configuration(False, gather_info['dut_asn'], gather_info['duthost'], gather_info['cli_options'], "suppress-map SUPPRESS_RM_V4", "suppress-map SUPPRESS_RM_V6") cmd = 'vtysh{} -c "config" -c "no route-map SUPPRESS_RM_V4 permit 10"'.format(gather_info['cli_options']) gather_info['duthost'].shell(cmd, module_ignore_errors=True) cmd = 'vtysh{} -c "config" -c "no route-map SUPPRESS_RM_V6 permit 10"'.format(gather_info['cli_options']) gather_info['duthost'].shell(cmd, module_ignore_errors=True) - cmd = 'vtysh{} -c "config" -c "no ip prefix-list SUPPRESS_V4 permit 1.1.1.0/24" \ - -c "no ip prefix-list SUPPRESS_V4 permit 1.1.2.0/24" -c "no ip prefix-list SUPPRESS_V4 permit 1.1.3.0/24" \ + cmd = 'vtysh{} -c "config" -c "no ip prefix-list SUPPRESS_V4 permit 1.1.1.1/24" \ + -c "no ip prefix-list SUPPRESS_V4 permit 1.1.2.1/24" \ -c "no ipv6 prefix-list SUPPRESS_V6 permit 1:1:1:1::/64" \ - -c "no ipv6 prefix-list SUPPRESS_V6 permit 1:1:1:2::/64" \ - -c "no ipv6 prefix-list SUPPRESS_V6 permit 1:1:1:3::/64"' \ + -c "no ipv6 prefix-list SUPPRESS_V6 permit 1:1:1:2::/64"' \ .format(gather_info['cli_options']) + check_baseline(gather_info['duthost'], gather_info['neigh_ip_v4'], gather_info['neigh_ip_v6'], num_v4_routes, + num_v6_routes) From 3dce3f168a1e51e526a2d3775c2b63f338e828e4 Mon Sep 17 00:00:00 2001 From: Azarack Date: Thu, 23 May 2024 18:36:25 +0000 Subject: [PATCH 08/10] assing as check --- tests/bgp/test_route_aggregation.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/bgp/test_route_aggregation.py b/tests/bgp/test_route_aggregation.py index c5e68b4011..f07cdef8ca 100644 --- a/tests/bgp/test_route_aggregation.py +++ b/tests/bgp/test_route_aggregation.py @@ -43,7 +43,7 @@ def agg_configuration(config, asn, duthost, cli_options, commandv4, commandv6): time.sleep(establish_bgp_session_time) -def verify_route_agg(dut, neigh_ip_v4, neigh_ip_v6, num_matches, suppress): +def verify_route_agg(dut, neigh_ip_v4, neigh_ip_v6, num_matches, suppress, as_set=False): output = dut.shell('show ip bgp neighbors {} advertised-routes | grep -c "*> 1.1."'.format(neigh_ip_v4), module_ignore_errors=True)['stdout'] logger.debug(output) @@ -64,6 +64,11 @@ def verify_route_agg(dut, neigh_ip_v4, neigh_ip_v6, num_matches, suppress): assert "1.1.2.0/24" not in output4 assert "1:1:1:1::/64" not in output6 assert "1:1:1:2::/64" not in output6 + if as_set: + assert "11111" in output4 + assert "22222" in output4 + assert "11111" in output6 + assert "22222" in output6 def check_baseline(dut, neigh_ip_v4, neigh_ip_v6, base_v4, base_v6): @@ -120,6 +125,7 @@ def test_ebgp_route_aggregation(gather_info): # Configure summary-only route aggregation agg_configuration(True, gather_info['dut_asn'], gather_info['duthost'], gather_info['cli_options'], "summary-only", "summary-only") + logger.debug(gather_info['duthost'].shell('vtysh -c "show run bgp"', module_ignore_errors=True)['stdout']) verify_route_agg(gather_info['duthost'], gather_info['neigh_ip_v4'], gather_info['neigh_ip_v6'], "1", False) # Remove the aggregate configuration @@ -132,7 +138,9 @@ def test_ebgp_route_aggregation(gather_info): # Configure as-set summary-only route aggregation agg_configuration(True, gather_info['dut_asn'], gather_info['duthost'], gather_info['cli_options'], "as-set summary-only", "as-set summary-only") - verify_route_agg(gather_info['duthost'], gather_info['neigh_ip_v4'], gather_info['neigh_ip_v6'], "1", False) + logger.debug(gather_info['duthost'].shell('vtysh -c "show run bgp"', module_ignore_errors=True)['stdout']) + verify_route_agg(gather_info['duthost'], gather_info['neigh_ip_v4'], gather_info['neigh_ip_v6'], "1", False, + as_set=True) # Remove the aggregate configuration agg_configuration(False, gather_info['dut_asn'], gather_info['duthost'], @@ -160,8 +168,6 @@ def test_ebgp_route_aggregation(gather_info): gather_info['duthost'].shell(cmd, module_ignore_errors=True) agg_configuration(True, gather_info['dut_asn'], gather_info['duthost'], gather_info['cli_options'], "suppress-map SUPPRESS_RM_V4", "suppress-map SUPPRESS_RM_V6") - logger.debug(gather_info['neighhost'].shell("show ip bgp summary", module_ignore_errors=True)['stdout']) - logger.debug(gather_info['neighhost'].shell("show ipv6 bgp summary", module_ignore_errors=True)['stdout']) logger.debug(gather_info['duthost'].shell('vtysh -c "show run bgp"', module_ignore_errors=True)['stdout']) verify_route_agg(gather_info['duthost'], gather_info['neigh_ip_v4'], gather_info['neigh_ip_v6'], "4", True) From bdc6af7ac8893627dd4dd0be0153a9b30648176f Mon Sep 17 00:00:00 2001 From: Azarack Date: Fri, 20 Sep 2024 17:06:26 +0000 Subject: [PATCH 09/10] refactor --- tests/bgp/test_route_aggregation.py | 35 ++++++++++++++++------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/tests/bgp/test_route_aggregation.py b/tests/bgp/test_route_aggregation.py index f07cdef8ca..42d4a4d33a 100644 --- a/tests/bgp/test_route_aggregation.py +++ b/tests/bgp/test_route_aggregation.py @@ -29,6 +29,23 @@ establish_bgp_session_time = 120 +def create_loopbacks(gather_info): + gather_info['duthost'].shell("sudo config loopback add Loopback11") + gather_info['duthost'].shell("sudo config interface ip add Loopback11 1.1.1.1/24") + gather_info['duthost'].shell("sudo config interface ip add Loopback11 1:1:1:1::/64") + gather_info['duthost'].shell("sudo config loopback add Loopback12") + gather_info['duthost'].shell("sudo config interface ip add Loopback12 1.1.2.1/24") + gather_info['duthost'].shell("sudo config interface ip add Loopback12 1:1:1:2::/64") + gather_info['duthost'].shell("sudo config loopback add Loopback13") + gather_info['duthost'].shell("sudo config interface ip add Loopback13 1.1.3.1/24") + gather_info['duthost'].shell("sudo config interface ip add Loopback13 1:1:1:3::/64") + gather_info['duthost'].shell("sudo config loopback add Loopback14") + gather_info['duthost'].shell("sudo config interface ip add Loopback14 1.1.4.1/24") + gather_info['duthost'].shell("sudo config interface ip add Loopback14 1:1:1:4::/64") + gather_info['duthost'].shell("sudo config loopback add Loopback15") + gather_info['duthost'].shell("sudo config interface ip add Loopback15 1.1.5.1/24") + gather_info['duthost'].shell("sudo config interface ip add Loopback15 1:1:1:5::/64") + def agg_configuration(config, asn, duthost, cli_options, commandv4, commandv6): remove_tag = "" if not config: @@ -90,26 +107,14 @@ def test_ebgp_route_aggregation(gather_info): gather_info['neigh_ip_v6']))['stdout'] # Configure and Advertise Loopback Networks on DUT - gather_info['duthost'].shell("sudo config loopback add Loopback11") - gather_info['duthost'].shell("sudo config interface ip add Loopback11 1.1.1.1/24") - gather_info['duthost'].shell("sudo config interface ip add Loopback11 1:1:1:1::/64") - gather_info['duthost'].shell("sudo config loopback add Loopback12") - gather_info['duthost'].shell("sudo config interface ip add Loopback12 1.1.2.1/24") - gather_info['duthost'].shell("sudo config interface ip add Loopback12 1:1:1:2::/64") - gather_info['duthost'].shell("sudo config loopback add Loopback13") - gather_info['duthost'].shell("sudo config interface ip add Loopback13 1.1.3.1/24") - gather_info['duthost'].shell("sudo config interface ip add Loopback13 1:1:1:3::/64") - gather_info['duthost'].shell("sudo config loopback add Loopback14") - gather_info['duthost'].shell("sudo config interface ip add Loopback14 1.1.4.1/24") - gather_info['duthost'].shell("sudo config interface ip add Loopback14 1:1:1:4::/64") - gather_info['duthost'].shell("sudo config loopback add Loopback15") - gather_info['duthost'].shell("sudo config interface ip add Loopback15 1.1.5.1/24") - gather_info['duthost'].shell("sudo config interface ip add Loopback15 1:1:1:5::/64") + create_loopbacks() + # Create the route maps to be used cmd = 'vtysh -c "config" -c "route-map AGG_TEST_1 permit 10" -c "set as-path prepend 11111" -c "exit" -c "end"' logger.debug(gather_info['duthost'].shell(cmd, module_ignore_errors=True)) cmd = 'vtysh -c "config" -c "route-map AGG_TEST_2 permit 10" -c "set as-path prepend 22222" -c "exit" -c "end"' logger.debug(gather_info['duthost'].shell(cmd, module_ignore_errors=True)) + # Assign the route maps to networks cmd = 'vtysh{} -c "config" -c "router bgp {}" -c "address-family ipv4 unicast" \ -c "network 1.1.1.0/24 route-map AGG_TEST_1" -c "network 1.1.2.0/24 route-map AGG_TEST_1" \ -c "network 1.1.3.0/24 route-map AGG_TEST_2" -c "network 1.1.4.0/24 route-map AGG_TEST_2" \ From 7b31c0fb1a8cb2758c3f6afc96444e4c274bae0c Mon Sep 17 00:00:00 2001 From: Azarack Date: Fri, 20 Sep 2024 17:10:44 +0000 Subject: [PATCH 10/10] fix flake error --- tests/bgp/test_route_aggregation.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/bgp/test_route_aggregation.py b/tests/bgp/test_route_aggregation.py index 42d4a4d33a..77a0a1b3f0 100644 --- a/tests/bgp/test_route_aggregation.py +++ b/tests/bgp/test_route_aggregation.py @@ -46,6 +46,7 @@ def create_loopbacks(gather_info): gather_info['duthost'].shell("sudo config interface ip add Loopback15 1.1.5.1/24") gather_info['duthost'].shell("sudo config interface ip add Loopback15 1:1:1:5::/64") + def agg_configuration(config, asn, duthost, cli_options, commandv4, commandv6): remove_tag = "" if not config: