diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:53:30 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:53:30 +0000 |
commit | 2c7cac91ed6e7db0f6937923d2b57f97dbdbc337 (patch) | |
tree | c05dc0f8e6aa3accc84e3e5cffc933ed94941383 /tests/topotests/bgp_prefix_list_any/test_bgp_prefix_list_any.py | |
parent | Initial commit. (diff) | |
download | frr-2c7cac91ed6e7db0f6937923d2b57f97dbdbc337.tar.xz frr-2c7cac91ed6e7db0f6937923d2b57f97dbdbc337.zip |
Adding upstream version 8.4.4.upstream/8.4.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/topotests/bgp_prefix_list_any/test_bgp_prefix_list_any.py')
-rw-r--r-- | tests/topotests/bgp_prefix_list_any/test_bgp_prefix_list_any.py | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/tests/topotests/bgp_prefix_list_any/test_bgp_prefix_list_any.py b/tests/topotests/bgp_prefix_list_any/test_bgp_prefix_list_any.py new file mode 100644 index 0000000..0eb2447 --- /dev/null +++ b/tests/topotests/bgp_prefix_list_any/test_bgp_prefix_list_any.py @@ -0,0 +1,105 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC + +# Copyright (c) 2023 by +# Donatas Abraitis <donatas@opensourcerouting.org> +# + +""" +Test if route-map works correctly when modifying prefix-list +from deny to permit with any, and vice-versa. +""" + +import os +import sys +import json +import pytest +import functools + +pytestmark = pytest.mark.bgpd + +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, TopoRouter, get_topogen + +pytestmark = [pytest.mark.bgpd] + + +def setup_module(mod): + topodef = {"s1": ("r1", "r2")} + tgen = Topogen(topodef, mod.__name__) + tgen.start_topology() + + router_list = tgen.routers() + + for i, (rname, router) in enumerate(router_list.items(), 1): + router.load_config( + TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) + ) + router.load_config( + TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) + ) + + tgen.start_router() + + +def teardown_module(mod): + tgen = get_topogen() + tgen.stop_topology() + + +def test_bgp_route_map_prefix_list(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r2 = tgen.gears["r2"] + + def _bgp_prefixes_sent(count): + output = json.loads(r2.vtysh_cmd("show bgp summary json")) + expected = { + "ipv4Unicast": { + "peers": {"192.168.1.1": {"pfxSnt": count, "state": "Established"}} + }, + "ipv6Unicast": { + "peers": {"2001:db8:1::1": {"pfxSnt": count, "state": "Established"}} + }, + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial(_bgp_prefixes_sent, 4) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Can't converge initial topology" + + r2.vtysh_cmd( + """ + configure terminal + ip prefix-list r1-2 seq 5 deny any + ipv6 prefix-list r1-2 seq 5 deny any + """ + ) + + test_func = functools.partial(_bgp_prefixes_sent, 3) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Only 3 prefixes MUST be advertised, seeing more" + + r2.vtysh_cmd( + """ + configure terminal + ip prefix-list r1-2 seq 5 permit 10.10.10.10/32 + ipv6 prefix-list r1-2 seq 5 permit 2001:db8:10::10/128 + """ + ) + + test_func = functools.partial(_bgp_prefixes_sent, 4) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "More or less prefixes advertised to r1, MUST be 4" + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) |