Skip to content

Commit

Permalink
Add BBR testcases (#14117)
Browse files Browse the repository at this point in the history
What is the motivation for this PR?
Add a new case to verify the BBR initialized behavior.

How did you do it?
Add the following new case under test_bgp_bbr.py
test_bbr_status_consistent_after_reload

How did you verify/test it?
https://dev.azure.com/mssonic/internal/_build/results?buildId=619063&view=results
  • Loading branch information
Gfrom2016 committed Sep 23, 2024
1 parent ae3d4dd commit b6d4924
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 11 deletions.
9 changes: 8 additions & 1 deletion docs/testplan/BGP-BBR.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
The goal of the test to check that BBR feature works correctly. The feature is implemented on bgpcfgd. The bgpcfgd dynamicaly changes BGP configuration, which either enable or disabled BBR functionality. The BBR functionality is enablement to see DUT ASN in the routes aspath not more than once.

### Scope
The test is targeting a running SONIC system with fully functioning configuration. The purpose of the test is to test BBR feature, which includes bgpcfgd implementation and BGP.
The test is targeting a running SONIC system with fully functioning configuration. The purpose of the test is to test BBR feature and configuration, which includes bgpcfgd implementation and BGP.

### Testbed
The test could run on t1 testbed in virtual switch environment.
Expand Down Expand Up @@ -38,3 +38,10 @@ The test announces ipv4 and ipv6 routes from one of the T0s, and checks when DUT
2. Announce ipv4 and ipv6 routes fron one of the T0s to DUT. Each route must have patched aspath which contains DUT ASN once.
3. Check that DUT BGP rejected both routes to the routing table
4. Restore the BBR state how it was been before the test

### Test case # 4 - BBR status remains consistent after config reload
1. Set the BBR status in the config_db to the value specified by the `bbr_status` parameters using the redis-cli command.
2. Save the configuration using the `sudo config save -y` command.
3. Reload the configuration using the `config_reload` function.
4. Retrieve the BBR status and verified it matches the expected `bbr_status` value.
5. Restore the BBR status how it was been before the test.
64 changes: 54 additions & 10 deletions tests/bgp/test_bgp_bbr.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from jinja2 import Template
from natsort import natsorted
from tests.common.config_reload import config_reload
from tests.common.helpers.assertions import pytest_assert
from tests.common.helpers.constants import DEFAULT_NAMESPACE
from tests.common.helpers.parallel import reset_ansible_local_tmp
Expand Down Expand Up @@ -153,23 +154,41 @@ def config_bbr_enabled(duthosts, setup, rand_one_dut_hostname, restore_bbr_defau
enable_bbr(duthost, setup['tor1_namespace'])


def get_bbr_default_state(duthost):
bbr_supported = False
bbr_default_state = 'disabled'

# Check BBR configuration from config_db first
bbr_config_db_exist = int(duthost.shell('redis-cli -n 4 HEXISTS "BGP_BBR|all" "status"')["stdout"])
if bbr_config_db_exist:
# key exist, BBR is supported
bbr_supported = True
bbr_default_state = duthost.shell('redis-cli -n 4 HGET "BGP_BBR|all" "status"')["stdout"]
else:
# Check BBR configuration from constants.yml
constants = yaml.safe_load(duthost.shell('cat {}'.format(CONSTANTS_FILE))['stdout'])
try:
bbr_supported = constants['constants']['bgp']['bbr']['enabled']
if not bbr_supported:
return bbr_supported, bbr_default_state
bbr_default_state = constants['constants']['bgp']['bbr']['default_state']
except KeyError:
return bbr_supported, bbr_default_state

return bbr_supported, bbr_default_state


@pytest.fixture(scope='module')
def setup(duthosts, rand_one_dut_hostname, tbinfo, nbrhosts):
duthost = duthosts[rand_one_dut_hostname]

constants_stat = duthost.stat(path=CONSTANTS_FILE)
if not constants_stat['stat']['exists']:
pytest.skip('No file {} on DUT, BBR is not supported')
pytest.skip('No constants.yml file on DUT, BBR is not supported')

constants = yaml.safe_load(duthost.shell('cat {}'.format(CONSTANTS_FILE))['stdout'])
bbr_default_state = 'disabled'
try:
bbr_enabled = constants['constants']['bgp']['bbr']['enabled']
if not bbr_enabled:
pytest.skip('BGP BBR is not enabled')
bbr_default_state = constants['constants']['bgp']['bbr']['default_state']
except KeyError:
pytest.skip('No BBR configuration in {}, BBR is not supported.'.format(CONSTANTS_FILE))
bbr_supported, bbr_default_state = get_bbr_default_state(duthost)
if not bbr_supported:
pytest.skip('BGP BBR is not supported')

mg_facts = duthost.get_extended_minigraph_facts(tbinfo)

Expand Down Expand Up @@ -416,3 +435,28 @@ def test_bbr_disabled_dut_asn_in_aspath(duthosts, rand_one_dut_hostname, nbrhost
prepare_routes([bbr_route, bbr_route_v6])
for route in (bbr_route, bbr_route_v6):
check_bbr_route_propagation(duthost, nbrhosts, setup, route, accepted=False)


@pytest.mark.parametrize('bbr_status', ['enabled', 'disabled'])
def test_bbr_status_consistent_after_reload(duthosts, rand_one_dut_hostname, setup,
bbr_status, restore_bbr_default_state):
duthost = duthosts[rand_one_dut_hostname]
if setup['tor1_namespace']:
pytest.skip('Skip test for multi-asic environment')

# Set BBR status in config_db
duthost.shell('redis-cli -n 4 HSET "BGP_BBR|all" "status" "{}" '.format(bbr_status))
duthost.shell('sudo config save -y')
config_reload(duthost)

# Verify BBR status after config reload
bbr_status_after_reload = duthost.shell('redis-cli -n 4 HGET "BGP_BBR|all" "status"')["stdout"]
pytest_assert(bbr_status_after_reload == bbr_status, "BGP BBR status is not consistent after config reload")

# Check if BBR is enabled or disabled using the running configuration
bbr_status_running_config = duthost.shell("show runningconfiguration bgp | grep allowas", module_ignore_errors=True)\
['stdout'] # noqa E211
if bbr_status == 'enabled':
pytest_assert('allowas-in' in bbr_status_running_config, "BGP BBR is not enabled in running configuration")
else:
pytest_assert('allowas-in' not in bbr_status_running_config, "BGP BBR is not disabled in running configuration")

0 comments on commit b6d4924

Please sign in to comment.