Skip to content
Merged
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
34 changes: 24 additions & 10 deletions tests/bgp/bgp_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 10 additions & 0 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 @@ -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 %}
Expand Down
11 changes: 8 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,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

Expand All @@ -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']
Expand All @@ -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
Expand All @@ -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")
Loading