diff options
6 files changed, 204 insertions, 0 deletions
diff --git a/tests/topotests/bgp_extcomm_list_delete/__init__.py b/tests/topotests/bgp_extcomm_list_delete/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/topotests/bgp_extcomm_list_delete/__init__.py diff --git a/tests/topotests/bgp_extcomm_list_delete/r1/bgpd.conf b/tests/topotests/bgp_extcomm_list_delete/r1/bgpd.conf new file mode 100644 index 0000000000..3394c1c568 --- /dev/null +++ b/tests/topotests/bgp_extcomm_list_delete/r1/bgpd.conf @@ -0,0 +1,20 @@ +router bgp 65000 + no bgp ebgp-requires-policy + no bgp network import-check + neighbor 192.168.255.2 remote-as 65001 + address-family ipv4 unicast + network 10.10.10.1/32 route-map r2-out-rt + network 10.10.10.2/32 route-map r2-out-soo + network 10.10.10.3/32 route-map r2-out-nt + redistribute connected + exit-address-family +! +route-map r2-out-rt permit 10 + set extcommunity rt 1.1.1.1:1 2.2.2.2:2 3.3.3.3:3 4.4.4.4:4 +! +route-map r2-out-soo permit 20 + set extcommunity soo 1.1.1.1:1 2.2.2.2:2 3.3.3.3:3 4.4.4.4:4 +! +route-map r2-out-nt permit 30 + set extcommunity nt 192.168.255.2:0 2.2.2.2:0 3.3.3.3:0 4.4.4.4:0 +! diff --git a/tests/topotests/bgp_extcomm_list_delete/r1/zebra.conf b/tests/topotests/bgp_extcomm_list_delete/r1/zebra.conf new file mode 100644 index 0000000000..e2c399e536 --- /dev/null +++ b/tests/topotests/bgp_extcomm_list_delete/r1/zebra.conf @@ -0,0 +1,6 @@ +! +interface r1-eth0 + ip address 192.168.255.1/24 +! +ip forwarding +! diff --git a/tests/topotests/bgp_extcomm_list_delete/r2/bgpd.conf b/tests/topotests/bgp_extcomm_list_delete/r2/bgpd.conf new file mode 100644 index 0000000000..ca497e6e05 --- /dev/null +++ b/tests/topotests/bgp_extcomm_list_delete/r2/bgpd.conf @@ -0,0 +1,10 @@ +router bgp 65001 + no bgp ebgp-requires-policy + neighbor 192.168.255.1 remote-as 65000 + neighbor 192.168.255.1 timers 3 10 + address-family ipv4 + neighbor 192.168.255.1 route-map r1-in in + exit-address-family +! +route-map r1-in permit 10 +! diff --git a/tests/topotests/bgp_extcomm_list_delete/r2/zebra.conf b/tests/topotests/bgp_extcomm_list_delete/r2/zebra.conf new file mode 100644 index 0000000000..606c17bec9 --- /dev/null +++ b/tests/topotests/bgp_extcomm_list_delete/r2/zebra.conf @@ -0,0 +1,6 @@ +! +interface r2-eth0 + ip address 192.168.255.2/24 +! +ip forwarding +! diff --git a/tests/topotests/bgp_extcomm_list_delete/test_bgp_extcomm-list_delete.py b/tests/topotests/bgp_extcomm_list_delete/test_bgp_extcomm-list_delete.py new file mode 100644 index 0000000000..eb05986fe1 --- /dev/null +++ b/tests/topotests/bgp_extcomm_list_delete/test_bgp_extcomm-list_delete.py @@ -0,0 +1,162 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC +# +# Copyright 2023 6WIND S.A. +# Authored by Farid Mihoub <farid.mihoub@6wind.com> +# + +""" +bgp_extcomm_list-delete.py: + +Test the following commands: +route-map test permit 10 + set extended-comm-list <arg> delete +""" + +import functools +import json +import os +import pytest +import re +import sys + +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +# pylint: disable=C0413 +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.topolog import logger +from lib import topotest + + +pytestmark = [pytest.mark.bgpd] + + +def build_topo(tgen): + for routern in range(1, 3): + tgen.add_router("r{}".format(routern)) + + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + + +def setup_module(mod): + tgen = Topogen(build_topo, 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_convergence(): + tgen = get_topogen() + r2 = tgen.gears["r2"] + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + def _bgp_converge(): + output = json.loads(r2.vtysh_cmd("show ip bgp neighbor 192.168.255.1 json")) + expected = { + "192.168.255.1": { + "bgpState": "Established", + "addressFamilyInfo": { + "ipv4Unicast": { + "acceptedPrefixCounter": 4, + } + }, + } + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial(_bgp_converge) + _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) + assert result is None, "Can't converge initially" + + +def _set_extcomm_list(gear, ecom_t, ecom): + "Set the extended community for deletion." + cmd = [ + "con t\n", + f"bgp extcommunity-list standard r1-{ecom_t} permit {ecom_t} {ecom}\n", + f"route-map r1-in permit 10\n", + f"set extended-comm-list r1-{ecom_t} delete\n", + ] + gear.vtysh_cmd("".join(cmd)) + + +def _bgp_extcomm_list_del_check(gear, prefix, ecom): + """ + Check the non-presense of the extended community for the given prefix. + """ + # get the extended community list attribute for the given prefix + output = json.loads(gear.vtysh_cmd(f"show ip bgp {prefix} json")) + ecoms = output.get("paths", [])[0].get("extendedCommunity", {}) + ecoms = ecoms.get("string") + + # ecoms might be None at the first time + if not ecoms: + return False + return re.search(ecom, ecoms) is None + + +def test_rt_extcomm_list_delete(): + tgen = get_topogen() + r2 = tgen.gears["r2"] + + # set the extended community for deletion + _set_extcomm_list(r2, "rt", "1.1.1.1:1") + + # check for the deletion of the extended community + test_func = functools.partial( + _bgp_extcomm_list_del_check, r2, "10.10.10.1/32", r"1.1.1.1:1") + _, result = topotest.run_and_expect(test_func, True, count=60, wait=0.5) + assert result, "RT extended community 1.1.1.1:1 was not stripped." + + +def test_soo_extcomm_list_delete(): + tgen = get_topogen() + r2 = tgen.gears["r2"] + + # set the extended community for deletion + _set_extcomm_list(r2, "soo", "2.2.2.2:2") + + # check for the deletion of the extended community + test_func = functools.partial( + _bgp_extcomm_list_del_check, r2, "10.10.10.2/32", r"2.2.2.2:2") + _, result = topotest.run_and_expect(test_func, True, count=60, wait=0.5) + assert result, "SoO extended community 2.2.2.2:2 was not stripped." + + +def test_nt_extcomm_list_delete(): + tgen = get_topogen() + r2 = tgen.gears["r2"] + + # set the extended community for deletion + _set_extcomm_list(r2, "nt", "3.3.3.3:0") + + # check for the deletion of the extended community + test_func = functools.partial( + _bgp_extcomm_list_del_check, r2, "10.10.10.3/32", r"3.3.3.3") + _, result = topotest.run_and_expect(test_func, True, count=60, wait=0.5) + assert result, "NT extended community 3.3.3.3:0 was not stripped." + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) |
