From cb9b049d24ccf0839d12093502b78af636801520 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Tue, 12 Mar 2024 20:30:46 +0200 Subject: [PATCH] tests: Check if Paths-Limit capability is working dynamically Signed-off-by: Donatas Abraitis --- .../bgp_dynamic_capability/r1/frr.conf | 1 + .../bgp_dynamic_capability/r2/frr.conf | 1 + .../test_bgp_dynamic_capability_addpath.py | 161 +++++++++++++++--- 3 files changed, 138 insertions(+), 25 deletions(-) diff --git a/tests/topotests/bgp_dynamic_capability/r1/frr.conf b/tests/topotests/bgp_dynamic_capability/r1/frr.conf index aa5c3db9a68f..c9594626f50f 100644 --- a/tests/topotests/bgp_dynamic_capability/r1/frr.conf +++ b/tests/topotests/bgp_dynamic_capability/r1/frr.conf @@ -15,6 +15,7 @@ router bgp 65001 ! address-family ipv4 unicast neighbor 192.168.1.2 addpath-tx-all-paths + neighbor 192.168.1.2 addpath-rx-paths-limit 10 exit-address-family ! ip prefix-list r2 seq 5 permit 10.10.10.10/32 diff --git a/tests/topotests/bgp_dynamic_capability/r2/frr.conf b/tests/topotests/bgp_dynamic_capability/r2/frr.conf index 7f25665ed572..3cc1f1fc392c 100644 --- a/tests/topotests/bgp_dynamic_capability/r2/frr.conf +++ b/tests/topotests/bgp_dynamic_capability/r2/frr.conf @@ -16,6 +16,7 @@ router bgp 65002 neighbor 192.168.1.1 timers 1 3 neighbor 192.168.1.1 timers connect 1 neighbor 192.168.1.1 capability dynamic + neighbor 192.168.1.1 addpath-rx-paths-limit 20 ! address-family ipv4 unicast redistribute connected diff --git a/tests/topotests/bgp_dynamic_capability/test_bgp_dynamic_capability_addpath.py b/tests/topotests/bgp_dynamic_capability/test_bgp_dynamic_capability_addpath.py index 5202f51e28d1..df952313c20e 100644 --- a/tests/topotests/bgp_dynamic_capability/test_bgp_dynamic_capability_addpath.py +++ b/tests/topotests/bgp_dynamic_capability/test_bgp_dynamic_capability_addpath.py @@ -6,7 +6,11 @@ # """ -Test if Addpath capability is adjusted dynamically. +Test if Addpath/Paths-Limit capabilities are adjusted dynamically. +T1: Enable Addpath/Paths-Limit capabilities and check if they are exchanged dynamically +T2: Disable paths limit and check if it's exchanged dynamically +T3: Disable Addpath capability RX and check if it's exchanged dynamically +T4: Disable Addpath capability and check if it's exchanged dynamically """ import os @@ -24,7 +28,6 @@ # pylint: disable=C0413 from lib import topotest from lib.topogen import Topogen, TopoRouter, get_topogen -from lib.common_config import step pytestmark = [pytest.mark.bgpd] @@ -47,16 +50,15 @@ def teardown_module(mod): tgen.stop_topology() -def test_bgp_dynamic_capability_addpath(): +def test_bgp_addpath_paths_limit_converge(): tgen = get_topogen() if tgen.routers_have_failure(): pytest.skip(tgen.errors) r1 = tgen.gears["r1"] - r2 = tgen.gears["r2"] - def _bgp_converge(): + def _check(): output = json.loads(r1.vtysh_cmd("show bgp neighbor json")) expected = { "192.168.1.2": { @@ -69,6 +71,13 @@ def _bgp_converge(): "rxAdvertisedAndReceived": True, } }, + "pathsLimit": { + "ipv4Unicast": { + "advertisedAndReceived": True, + "advertisedPathsLimit": 10, + "receivedPathsLimit": 20, + } + }, }, "addressFamilyInfo": { "ipv4Unicast": { @@ -80,15 +89,24 @@ def _bgp_converge(): return topotest.json_cmp(output, expected) test_func = functools.partial( - _bgp_converge, + _check, ) _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) assert result is None, "Can't converge" - step("Enable Addpath capability and check if it's exchanged dynamically") - # Clear message stats to check if we receive a notification or not after we - # change the settings fo LLGR. +#### +# T1: Enable Addpath/Paths-Limit capabilities and check if they are exchanged dynamically +#### +def test_bgp_dynamic_capability_enable_addpath_paths_limit(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r1 = tgen.gears["r1"] + r2 = tgen.gears["r2"] + r1.vtysh_cmd("clear bgp 192.168.1.2 message-stats") r2.vtysh_cmd( """ @@ -96,10 +114,11 @@ def _bgp_converge(): router bgp address-family ipv4 unicast neighbor 192.168.1.1 addpath-tx-all-paths + neighbor 192.168.1.1 addpath-rx-paths-limit 21 """ ) - def _bgp_check_if_addpath_rx_tx_and_session_not_reset(): + def _check(): output = json.loads(r1.vtysh_cmd("show bgp neighbor json")) expected = { "192.168.1.2": { @@ -112,6 +131,13 @@ def _bgp_check_if_addpath_rx_tx_and_session_not_reset(): "rxAdvertisedAndReceived": True, } }, + "pathsLimit": { + "ipv4Unicast": { + "advertisedAndReceived": True, + "advertisedPathsLimit": 10, + "receivedPathsLimit": 21, + } + }, }, "addressFamilyInfo": { "ipv4Unicast": { @@ -120,33 +146,44 @@ def _bgp_check_if_addpath_rx_tx_and_session_not_reset(): }, "messageStats": { "notificationsRecv": 0, - "capabilityRecv": 1, + "capabilityRecv": 2, }, } } return topotest.json_cmp(output, expected) test_func = functools.partial( - _bgp_check_if_addpath_rx_tx_and_session_not_reset, + _check, ) _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) - assert result is None, "Session was reset after enabling Addpath capability" + assert ( + result is None + ), "Session was reset after enabling Addpath/Paths-Limit capabilities" - step("Disable Addpath capability RX and check if it's exchanged dynamically") - # Clear message stats to check if we receive a notification or not after we - # disable addpath-rx. +### +# T2: Disable paths limit and check if it's exchanged dynamically +### +def test_bgp_dynamic_capability_disable_paths_limit(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r1 = tgen.gears["r1"] + r2 = tgen.gears["r2"] + r1.vtysh_cmd("clear bgp 192.168.1.2 message-stats") r2.vtysh_cmd( """ configure terminal router bgp address-family ipv4 unicast - neighbor 192.168.1.1 disable-addpath-rx + no neighbor 192.168.1.1 addpath-rx-paths-limit """ ) - def _bgp_check_if_addpath_tx_and_session_not_reset(): + def _check(): output = json.loads(r1.vtysh_cmd("show bgp neighbor json")) expected = { "192.168.1.2": { @@ -159,6 +196,13 @@ def _bgp_check_if_addpath_tx_and_session_not_reset(): "rxAdvertised": True, } }, + "pathsLimit": { + "ipv4Unicast": { + "advertisedAndReceived": True, + "advertisedPathsLimit": 10, + "receivedPathsLimit": 0, + } + }, }, "messageStats": { "notificationsRecv": 0, @@ -169,13 +213,80 @@ def _bgp_check_if_addpath_tx_and_session_not_reset(): return topotest.json_cmp(output, expected) test_func = functools.partial( - _bgp_check_if_addpath_tx_and_session_not_reset, + _check, + ) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "Session was reset after disabling paths limit" + + +### +# T3: Disable Addpath capability RX and check if it's exchanged dynamically +### +def test_bgp_dynamic_capability_disable_addpath_rx(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r1 = tgen.gears["r1"] + r2 = tgen.gears["r2"] + + r1.vtysh_cmd("clear bgp 192.168.1.2 message-stats") + r2.vtysh_cmd( + """ + configure terminal + router bgp + address-family ipv4 unicast + neighbor 192.168.1.1 disable-addpath-rx + """ + ) + + def _check(): + output = json.loads(r1.vtysh_cmd("show bgp neighbor json")) + expected = { + "192.168.1.2": { + "bgpState": "Established", + "neighborCapabilities": { + "dynamic": "advertisedAndReceived", + "addPath": { + "ipv4Unicast": { + "rxAdvertisedAndReceived": True, + "txAdvertised": False, + } + }, + "pathsLimit": { + "ipv4Unicast": { + "advertisedAndReceived": True, + "advertisedPathsLimit": 10, + "receivedPathsLimit": 20, + } + }, + }, + "messageStats": { + "notificationsRecv": 0, + }, + } + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial( + _check, ) _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) assert result is None, "Session was reset after disabling Addpath RX flags" - # Clear message stats to check if we receive a notification or not after we - # disable Addpath capability. + +### +# T4: Disable Addpath capability and check if it's exchanged dynamically +### +def test_bgp_dynamic_capability_disable_addpath(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r1 = tgen.gears["r1"] + r1.vtysh_cmd("clear bgp 192.168.1.2 message-stats") r1.vtysh_cmd( """ @@ -186,7 +297,7 @@ def _bgp_check_if_addpath_tx_and_session_not_reset(): """ ) - def _bgp_check_if_addpath_capability_is_absent(): + def _check(): output = json.loads(r1.vtysh_cmd("show bgp neighbor json")) expected = { "192.168.1.2": { @@ -195,9 +306,9 @@ def _bgp_check_if_addpath_capability_is_absent(): "dynamic": "advertisedAndReceived", "addPath": { "ipv4Unicast": { - "txAdvertisedAndReceived": None, - "txAdvertised": None, + "rxAdvertisedAndReceived": True, "rxAdvertised": True, + "rxReceived": True, } }, }, @@ -209,7 +320,7 @@ def _bgp_check_if_addpath_capability_is_absent(): return topotest.json_cmp(output, expected) test_func = functools.partial( - _bgp_check_if_addpath_capability_is_absent, + _check, ) _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) assert result is None, "Failed to disable Addpath capability"