Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions tests/bgp/bgp_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,35 @@ 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: If True, check IPv6 routes; otherwise check IPv4 routes
"""
if ipv6:
if isinstance(vm_host, EosHost):
# Use 'show bgp ipv6 unicast community no-export' for EOS IPv6
out = vm_host.eos_command(commands=['show bgp ipv6 unicast community no-export'])["stdout"]
# Match IPv6 prefixes (e.g., fc00:1::/64)
return re.findall(r'[0-9a-fA-F:]+\/\d+\s+[0-9a-fA-F:]+.*', out[0])
elif isinstance(vm_host, SonicHost):
out = vm_host.command("vtysh -c 'show bgp ipv6 unicast community no-export'")["stdout"]
return re.findall(r'[0-9a-fA-F:]+\/\d+\s+[0-9a-fA-F:]+.*', 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.")
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)
else:
raise TypeError(f"Unsupported host type: {type(vm_host)}. Expected EosHost or SonicHost.")


def apply_default_bgp_config(duthost, copy=False):
Expand Down
14 changes: 10 additions & 4 deletions tests/bgp/templates/bgp_no_export.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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
!
Expand Down Expand Up @@ -79,19 +82,22 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
address-family ipv4
neighbor {{ neighbor_addr }} activate
maximum-paths 64
{% if 'LeafRouter' in DEVICE_METADATA['localhost']['type'] %}
{%- if 'ToRRouter' in DEVICE_NEIGHBOR_METADATA[bgp_session['name']]['type'] %}
{% if 'LeafRouter' in DEVICE_METADATA['localhost']['type'] and 'ToRRouter' in DEVICE_NEIGHBOR_METADATA[bgp_session['name']]['type'] %}
neighbor {{ neighbor_addr }} route-map TO_TIER0_V4 out
neighbor {{ neighbor_addr }} send-community
neighbor {{ neighbor_addr }} allowas-in 1
{% endif %}
exit-address-family
{% endif %}
exit-address-family
{% endif %}
{% if neighbor_addr | ipv6 %}
address-family ipv6
neighbor {{ neighbor_addr }} activate
maximum-paths 64
{% if 'LeafRouter' in DEVICE_METADATA['localhost']['type'] and '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 %}
exit-address-family
{% endif %}
{% endif %}
Expand Down
8 changes: 5 additions & 3 deletions tests/bgp/test_bgp_bounce.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,7 +17,7 @@
]


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

Expand All @@ -33,6 +34,7 @@ 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
ipv6_only = 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')])
Expand All @@ -48,7 +50,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=ipv6_only)
pytest_assert(not no_export_route_num, "Routes has no_export attribute")

# Apply bgp no export config
Expand All @@ -58,5 +60,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=ipv6_only)
pytest_assert(no_export_route_num, "Routes received on T1 are no-export")
Loading