diff --git a/tests/bgp/bgp_helpers.py b/tests/bgp/bgp_helpers.py index e80bac5b2ab..e5ce6592a5f 100644 --- a/tests/bgp/bgp_helpers.py +++ b/tests/bgp/bgp_helpers.py @@ -100,22 +100,36 @@ def define_config(duthost, template_src_path, template_dst_path): duthost.copy(src=template_src_path, dest=template_dst_path) -def get_no_export_output(vm_host): +def get_no_export_output(vm_host, ipv6=False): """ Get no export routes on the VM Args: vm_host: VM host object - """ - if isinstance(vm_host, EosHost): - out = vm_host.eos_command(commands=['show ip bgp community no-export'])["stdout"] - return re.findall(r'\d+\.\d+.\d+.\d+\/\d+\s+\d+\.\d+.\d+.\d+.*', out[0]) - elif isinstance(vm_host, SonicHost): - out = vm_host.command("vtysh -c 'show ip bgp community no-export'")["stdout"] - # For SonicHost, output is already a string, no need to index - return re.findall(r'\d+\.\d+.\d+.\d+\/\d+\s+\d+\.\d+.\d+.\d+.*', out) + ipv6: Boolean flag to check IPv6 routes + """ + if ipv6: + ipv6_pattern = r'[0-9a-fA-F:]+\/\d+\s+[0-9a-fA-F:]+.*' + if isinstance(vm_host, EosHost): + out = vm_host.eos_command(commands=['show ipv6 bgp match community no-export'])["stdout"] + return re.findall(ipv6_pattern, out[0]) + elif isinstance(vm_host, SonicHost): + out = vm_host.command("vtysh -c 'show ipv6 bgp community no-export'")["stdout"] + # For SonicHost, output is already a string, no need to index + return re.findall(ipv6_pattern, out) + else: + raise TypeError(f"Unsupported host type: {type(vm_host)}. Expected EosHost or SonicHost.") else: - raise TypeError(f"Unsupported host type: {type(vm_host)}. Expected EosHost or SonicHost.") + ipv4_pattern = r'\d+\.\d+.\d+.\d+\/\d+\s+\d+\.\d+.\d+.\d+.*' + if isinstance(vm_host, EosHost): + out = vm_host.eos_command(commands=['show ip bgp community no-export'])["stdout"] + return re.findall(ipv4_pattern, out[0]) + elif isinstance(vm_host, SonicHost): + out = vm_host.command("vtysh -c 'show ip bgp community no-export'")["stdout"] + # For SonicHost, output is already a string, no need to index + return re.findall(ipv4_pattern, out) + else: + raise TypeError(f"Unsupported host type: {type(vm_host)}. Expected EosHost or SonicHost.") def apply_default_bgp_config(duthost, copy=False): diff --git a/tests/bgp/templates/bgp_no_export.j2 b/tests/bgp/templates/bgp_no_export.j2 index 00f8072db58..eadf0e85f77 100644 --- a/tests/bgp/templates/bgp_no_export.j2 +++ b/tests/bgp/templates/bgp_no_export.j2 @@ -23,6 +23,9 @@ enable password zebra route-map TO_TIER0_V4 permit 50 set community no-export additive ! +route-map TO_TIER0_V6 permit 50 + set community no-export additive +! {% endif %} route-map FROM_BGP_SPEAKER_V4 permit 10 ! @@ -92,6 +95,13 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }} address-family ipv6 neighbor {{ neighbor_addr }} activate maximum-paths 64 +{% if 'LeafRouter' in DEVICE_METADATA['localhost']['type'] %} + {%- if 'ToRRouter' in DEVICE_NEIGHBOR_METADATA[bgp_session['name']]['type'] %} + neighbor {{ neighbor_addr }} route-map TO_TIER0_V6 out + neighbor {{ neighbor_addr }} send-community + neighbor {{ neighbor_addr }} allowas-in 1 + {% endif %} +{% endif %} exit-address-family {% endif %} {% endif %} diff --git a/tests/bgp/test_bgp_bounce.py b/tests/bgp/test_bgp_bounce.py index 3ba15a84b90..59fed6a2b11 100644 --- a/tests/bgp/test_bgp_bounce.py +++ b/tests/bgp/test_bgp_bounce.py @@ -7,6 +7,7 @@ import time from tests.common.helpers.assertions import pytest_assert +from tests.common.utilities import is_ipv6_only_topology from bgp_helpers import apply_bgp_config from bgp_helpers import get_no_export_output from bgp_helpers import BGP_ANNOUNCE_TIME @@ -16,7 +17,8 @@ ] -def test_bgp_bounce(duthost, nbrhosts, deploy_plain_bgp_config, deploy_no_export_bgp_config, backup_bgp_config): +def test_bgp_bounce(duthost, nbrhosts, tbinfo, deploy_plain_bgp_config, deploy_no_export_bgp_config, + backup_bgp_config): """ Verify bgp community no export functionality @@ -34,6 +36,9 @@ def test_bgp_bounce(duthost, nbrhosts, deploy_plain_bgp_config, deploy_no_export bgp_plain_config = deploy_plain_bgp_config bgp_no_export_config = deploy_no_export_bgp_config + # Check if this is an IPv6-only topology + is_v6_topo = is_ipv6_only_topology(tbinfo) + # Get random ToR VM vm_name = random.choice([vm_name for vm_name in list(nbrhosts.keys()) if vm_name.endswith('T0')]) vm_host = nbrhosts[vm_name]['host'] @@ -48,7 +53,7 @@ def test_bgp_bounce(duthost, nbrhosts, deploy_plain_bgp_config, deploy_no_export time.sleep(BGP_ANNOUNCE_TIME) # Take action on one of the ToR VM - no_export_route_num = get_no_export_output(vm_host) + no_export_route_num = get_no_export_output(vm_host, ipv6=is_v6_topo) pytest_assert(not no_export_route_num, "Routes has no_export attribute") # Apply bgp no export config @@ -58,5 +63,5 @@ def test_bgp_bounce(duthost, nbrhosts, deploy_plain_bgp_config, deploy_no_export time.sleep(BGP_ANNOUNCE_TIME) # Take action on one of the ToR VM - no_export_route_num = get_no_export_output(vm_host) + no_export_route_num = get_no_export_output(vm_host, ipv6=is_v6_topo) pytest_assert(no_export_route_num, "Routes received on T1 are no-export")