diff options
Diffstat (limited to 'tests')
9 files changed, 414 insertions, 0 deletions
diff --git a/tests/topotests/bgp_addpath_disable_rx/__init__.py b/tests/topotests/bgp_addpath_disable_rx/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/topotests/bgp_addpath_disable_rx/__init__.py diff --git a/tests/topotests/bgp_addpath_disable_rx/r1/frr.conf b/tests/topotests/bgp_addpath_disable_rx/r1/frr.conf new file mode 100644 index 0000000000..0c3fdad671 --- /dev/null +++ b/tests/topotests/bgp_addpath_disable_rx/r1/frr.conf @@ -0,0 +1,38 @@ +! +int r1-eth0 + ip address 192.168.137.1/24 +! +router bgp 65000 + bgp router-id 192.168.137.1 + no bgp ebgp-requires-policy + no bgp enforce-first + neighbor AS65100-V4 peer-group + neighbor AS65100-V4 remote-as 65100 + neighbor AS65100-V4 timers 1 3 + neighbor AS65200-V4 peer-group + neighbor AS65200-V4 remote-as 65200 + neighbor AS65200-V4 timers 1 3 + neighbor AS65600-V4 peer-group + neighbor AS65600-V4 remote-as 65600 + neighbor AS65600-V4 timers 1 3 + neighbor 192.168.137.100 peer-group AS65100-V4 + neighbor 192.168.137.201 peer-group AS65200-V4 + neighbor 192.168.137.202 peer-group AS65200-V4 + neighbor 192.168.137.60 peer-group AS65600-V4 + ! + address-family ipv4 unicast + neighbor AS65100-V4 addpath-tx-bestpath-per-AS + neighbor AS65100-V4 route-server-client + neighbor AS65200-V4 addpath-tx-bestpath-per-AS + neighbor AS65200-V4 disable-addpath-rx + neighbor AS65200-V4 route-server-client + neighbor AS65600-V4 addpath-tx-bestpath-per-AS + neighbor AS65600-V4 disable-addpath-rx + neighbor AS65600-V4 route-server-client + neighbor 192.168.137.201 disable-addpath-rx + neighbor 192.168.137.202 disable-addpath-rx + neighbor 192.168.137.60 disable-addpath-rx + exit-address-family +! +exit +! diff --git a/tests/topotests/bgp_addpath_disable_rx/r2/frr.conf b/tests/topotests/bgp_addpath_disable_rx/r2/frr.conf new file mode 100644 index 0000000000..daa252dc4b --- /dev/null +++ b/tests/topotests/bgp_addpath_disable_rx/r2/frr.conf @@ -0,0 +1,19 @@ +! +int r2-eth0 + ip address 192.168.137.60/24 +! +router bgp 65600 + bgp router-id 192.168.137.60 + no bgp ebgp-requires-policy + no bgp enforce-first-as + neighbor 192.168.137.1 remote-as 65000 + ! + address-family ipv4 unicast + neighbor 192.168.137.1 disable-addpath-rx + neighbor 192.168.137.1 prefix-list out out + exit-address-family +! +exit +! +ip prefix-list out seq 100 deny any +! diff --git a/tests/topotests/bgp_addpath_disable_rx/r3/frr.conf b/tests/topotests/bgp_addpath_disable_rx/r3/frr.conf new file mode 100644 index 0000000000..120c59fa21 --- /dev/null +++ b/tests/topotests/bgp_addpath_disable_rx/r3/frr.conf @@ -0,0 +1,20 @@ +! +int r3-eth0 + ip address 192.168.137.100/24 +! +int r3-eth1 + ip address 192.168.44.1/24 +! +router bgp 65100 + bgp router-id 192.168.137.100 + no bgp ebgp-requires-policy + no bgp enforce-first + neighbor 192.168.44.44 remote-as 65444 + neighbor 192.168.137.1 remote-as 65000 + ! + address-family ipv4 unicast + neighbor 192.168.44.44 disable-addpath-rx + exit-address-family +! +exit +! diff --git a/tests/topotests/bgp_addpath_disable_rx/r4/frr.conf b/tests/topotests/bgp_addpath_disable_rx/r4/frr.conf new file mode 100644 index 0000000000..b116d1c16a --- /dev/null +++ b/tests/topotests/bgp_addpath_disable_rx/r4/frr.conf @@ -0,0 +1,21 @@ +! +int r4-eth0 + ip address 192.168.137.201/24 +! +int r4-eth1 + ip address 192.168.54.21/24 +! +router bgp 65200 + bgp router-id 192.168.137.201 + no bgp enforce-first + no bgp ebgp-requires-policy + neighbor 192.168.54.44 remote-as 65444 + neighbor 192.168.137.1 remote-as 65000 + ! + address-family ipv4 unicast + neighbor 192.168.54.44 disable-addpath-rx + neighbor 192.168.137.1 disable-addpath-rx + exit-address-family +! +exit +! diff --git a/tests/topotests/bgp_addpath_disable_rx/r5/frr.conf b/tests/topotests/bgp_addpath_disable_rx/r5/frr.conf new file mode 100644 index 0000000000..926dd6fbf8 --- /dev/null +++ b/tests/topotests/bgp_addpath_disable_rx/r5/frr.conf @@ -0,0 +1,20 @@ +int r5-eth0 + ip address 192.168.137.202/24 +! +int r5-eth1 + ip address 192.168.54.22/24 +! +router bgp 65200 + bgp router-id 192.168.137.202 + no bgp ebgp-requires-policy + no bgp enforce-first + neighbor 192.168.54.44 remote-as 65444 + neighbor 192.168.137.1 remote-as 65000 + ! + address-family ipv4 unicast + neighbor 192.168.54.44 disable-addpath-rx + neighbor 192.168.137.1 disable-addpath-rx + exit-address-family +! +exit +! diff --git a/tests/topotests/bgp_addpath_disable_rx/r6/frr.conf b/tests/topotests/bgp_addpath_disable_rx/r6/frr.conf new file mode 100644 index 0000000000..3ef826da38 --- /dev/null +++ b/tests/topotests/bgp_addpath_disable_rx/r6/frr.conf @@ -0,0 +1,40 @@ +! +int r6-eth0 + ip address 192.168.44.44/24 +! +int r6-eth1 + ip address 192.168.54.44/24 +! +router bgp 65444 + bgp router-id 192.168.54.44 + no bgp network import-check + no bgp ebgp-requires-policy + neighbor 192.168.44.1 remote-as 65100 + neighbor 192.168.54.21 remote-as 65200 + neighbor 192.168.54.22 remote-as 65200 + ! + address-family ipv4 unicast + network 10.0.0.0/24 + neighbor 192.168.44.1 disable-addpath-rx + neighbor 192.168.44.1 route-map AS65100-OUT out + neighbor 192.168.54.21 disable-addpath-rx + neighbor 192.168.54.21 route-map AS65200-OUT out + neighbor 192.168.54.22 disable-addpath-rx + neighbor 192.168.54.22 route-map AS65200-OUT out + exit-address-family +! +exit +! +ip prefix-list out seq 2 permit 10.0.0.0/24 +ip prefix-list out seq 100 deny any +ip prefix-list v4_our_to65200 seq 100 deny any +! +route-map AS65200-OUT permit 10 + match ip address prefix-list v4_our_to65200 +exit +! +route-map AS65100-OUT permit 10 + match ip address prefix-list out + set as-path prepend 65444 +exit +! diff --git a/tests/topotests/bgp_addpath_disable_rx/test_bgp_addpath_disable_rx.py b/tests/topotests/bgp_addpath_disable_rx/test_bgp_addpath_disable_rx.py new file mode 100644 index 0000000000..421dc85af7 --- /dev/null +++ b/tests/topotests/bgp_addpath_disable_rx/test_bgp_addpath_disable_rx.py @@ -0,0 +1,131 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC + +# +# Copyright (c) 2025 by +# Donatas Abraitis <donatas@opensourcerouting.org> +# + +import os +import sys +import json +import pytest +import functools + +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +from lib import topotest +from lib.topogen import Topogen, get_topogen + +pytestmark = [pytest.mark.bgpd] + + +def build_topo(tgen): + r1 = tgen.add_router("r1") + r2 = tgen.add_router("r2") + r3 = tgen.add_router("r3") + r4 = tgen.add_router("r4") + r5 = tgen.add_router("r5") + r6 = tgen.add_router("r6") + + switch = tgen.add_switch("s1") + switch.add_link(r1) + switch.add_link(r2) + switch.add_link(r3) + switch.add_link(r4) + switch.add_link(r5) + + switch = tgen.add_switch("s2") + switch.add_link(r3) + switch.add_link(r6) + + switch = tgen.add_switch("s3") + switch.add_link(r4) + switch.add_link(r5) + switch.add_link(r6) + + +def setup_module(mod): + tgen = Topogen(build_topo, mod.__name__) + tgen.start_topology() + + for _, (rname, router) in enumerate(tgen.routers().items(), 1): + router.load_frr_config(os.path.join(CWD, "{}/frr.conf".format(rname))) + + tgen.start_router() + + +def teardown_module(mod): + tgen = get_topogen() + tgen.stop_topology() + + +def test_bgp_addpath_disable_rx(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r1 = tgen.gears["r1"] + r2 = tgen.gears["r2"] + r6 = tgen.gears["r6"] + + def _bgp_check_aspath(aspath): + output = json.loads(r2.vtysh_cmd("show bgp ipv4 10.0.0.0/24 json")) + expected = { + "paths": [ + { + "aspath": { + "string": aspath, + }, + } + ] + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial(_bgp_check_aspath, "65100 65444 65444") + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "10.0.0.0/24 should have aspath (65100 65444 65444)" + + # Send 10.0.0.0/24 from r6 towards r2. + # This should be the best path for r2 without any prepends. + r6.vtysh_cmd( + """ + configure terminal + ip prefix-list v4_our_to65200 seq 2 permit 10.0.0.0/24 + """ + ) + + test_func = functools.partial(_bgp_check_aspath, "65200 65444") + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "10.0.0.0/24 should have aspath (65200 65444)" + + # Drop 10.0.0.0/24 from r6 towards r2. + # This should be removed from r2 and the old path (65100 65444 65444) + # should be used. + r6.vtysh_cmd( + """ + configure terminal + no ip prefix-list v4_our_to65200 seq 2 permit 10.0.0.0/24 + """ + ) + + test_func = functools.partial(_bgp_check_aspath, "65100 65444 65444") + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "10.0.0.0/24 should have aspath (65100 65444 65444)" + + +def test_memory_leak(): + "Run the memory leak test and report results." + tgen = get_topogen() + if not tgen.is_memleak_enabled(): + pytest.skip("Memory leak test/report is disabled") + + tgen.report_memory_leaks() + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/bgp_vpn_5549_route_map/test_bgp_vpn_5549_route_map.py b/tests/topotests/bgp_vpn_5549_route_map/test_bgp_vpn_5549_route_map.py index 08d6e140a1..93764642d8 100644 --- a/tests/topotests/bgp_vpn_5549_route_map/test_bgp_vpn_5549_route_map.py +++ b/tests/topotests/bgp_vpn_5549_route_map/test_bgp_vpn_5549_route_map.py @@ -165,6 +165,131 @@ def test_bgp_vpn_5549(): assert result is None, "IPv6 nexthop is invalid" +def check_show_interface_rtadv_params_found(router): + output = json.loads(router.vtysh_cmd("show interface json")) + expected = { + "pe1-eth1": { + "ndAdvertisedReachableTimeMsecs": 0, + "ndAdvertisedRetransmitIntervalMsecs": 0, + "ndAdvertisedHopCountLimitHops": 64, + "ndRouterAdvertisementsIntervalSecs": 10, + "ndRouterAdvertisementsDoNotUseFastRetransmit": False, + "ndRouterAdvertisementsLifetimeTracksRaInterval": True, + "ndRouterAdvertisementDefaultRouterPreference": "medium", + "hostsUseStatelessAutoconfigForAddresses": True, + } + } + return topotest.json_cmp(output, expected) + + +def test_show_interface_rtadv_params_found(): + tgen = get_topogen() + + router = tgen.gears["pe1"] + test_func = functools.partial(check_show_interface_rtadv_params_found, router) + success, _ = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert success, "rtadv output is invalid" + + +def check_show_interface_rtadv_params_not_found(router): + output = json.loads(router.vtysh_cmd("show interface json")) + expected = { + "pe1-eth1": { + "ndAdvertisedReachableTimeMsecs": 0, + "ndAdvertisedRetransmitIntervalMsecs": 0, + } + } + + ret = topotest.json_cmp(output, expected) + if ret is None: + return "Unexpected: interface rtadv parameters found" + return None + + +def test_show_interface_rtadv_params_not_found(): + tgen = get_topogen() + + router = tgen.gears["pe1"] + router.vtysh_cmd( + "configure \n \ + router bgp 65001 \n \ + no neighbor 2001:db8:1::2 \n \ + exit \n \ + exit" + ) + + test_func = functools.partial(check_show_interface_rtadv_params_not_found, router) + success, _ = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert success, "not good" + + +def check_show_interface_rtadv_params_found_reapply(router): + output = json.loads(router.vtysh_cmd("show interface json")) + expected = { + "pe1-eth1": { + "ndAdvertisedReachableTimeMsecs": 0, + "ndAdvertisedRetransmitIntervalMsecs": 0, + } + } + return topotest.json_cmp(output, expected) + + +def test_show_interface_rtadv_params_found_reapply(): + tgen = get_topogen() + + router = tgen.gears["pe1"] + router.vtysh_cmd( + "configure \n \ + router bgp 65001 \n \ + neighbor 2001:db8:1::2 remote-as internal \n \ + neighbor 2001:db8:1::2 update-source 2001:db8:1::1 \n \ + neighbor 2001:db8:1::2 timers 1 3 \n \ + neighbor 2001:db8:1::2 timers connect 1 \n \ + neighbor 2001:db8:1::2 capability extended-nexthop \n \ + exit \n \ + exit" + ) + + test_func = functools.partial( + check_show_interface_rtadv_params_found_reapply, router + ) + success, _ = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert success, "rtadv output is invalid" + + +def check_show_interface_rtadv_params_not_found_after_reapply(router): + output = json.loads(router.vtysh_cmd("show interface json")) + + expected = { + "pe1-eth1": { + "ndAdvertisedReachableTimeMsecs": 0, + "ndAdvertisedRetransmitIntervalMsecs": 0, + } + } + + ret = topotest.json_cmp(output, expected) + if ret is None: + return "Unexpected: interface rtadv parameters found" + return None + + +def test_show_interface_rtadv_params_not_found_after_reapply(): + tgen = get_topogen() + + router = tgen.gears["pe1"] + router.vtysh_cmd( + "configure \n \ + no router bgp 65001 vrf RED \n \ + no router bgp 65001 \n \ + exit" + ) + test_func = functools.partial( + check_show_interface_rtadv_params_not_found_after_reapply, router + ) + success, _ = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert success, "not good" + + if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) |
