Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BBR testcases #14117

Merged
merged 4 commits into from
Sep 23, 2024
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
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')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is no constants.yml, is it a correct status? In my understanding, constants.yml should store many constans, right? If the file doesn't exist, it is in fatal condition, not just BBR is not supported, we have to fail the case, not just skip it, is it correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think constants file not exist should fail the case, it's not the bbr case's responsibility to make sure the file exists.


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")
Loading