Skip to content

Commit

Permalink
tests: Check if Paths-Limit capability is working dynamically
Browse files Browse the repository at this point in the history
Signed-off-by: Donatas Abraitis <[email protected]>
  • Loading branch information
ton31337 committed Mar 12, 2024
1 parent b7fc920 commit cb9b049
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 25 deletions.
1 change: 1 addition & 0 deletions tests/topotests/bgp_dynamic_capability/r1/frr.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/topotests/bgp_dynamic_capability/r2/frr.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]

Expand All @@ -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": {
Expand All @@ -69,6 +71,13 @@ def _bgp_converge():
"rxAdvertisedAndReceived": True,
}
},
"pathsLimit": {
"ipv4Unicast": {
"advertisedAndReceived": True,
"advertisedPathsLimit": 10,
"receivedPathsLimit": 20,
}
},
},
"addressFamilyInfo": {
"ipv4Unicast": {
Expand All @@ -80,26 +89,36 @@ 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(
"""
configure terminal
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": {
Expand All @@ -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": {
Expand All @@ -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": {
Expand All @@ -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,
Expand All @@ -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(
"""
Expand All @@ -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": {
Expand All @@ -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,
}
},
},
Expand All @@ -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"
Expand Down

0 comments on commit cb9b049

Please sign in to comment.