From 1e3d37dad28012d902dca442d26f44ce95de1645 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Mon, 3 Jul 2023 22:15:31 +0300 Subject: [PATCH] blabla Signed-off-by: Donatas Abraitis --- .../bgp_redistribute_ospf/__init__.py | 0 .../bgp_redistribute_ospf/r1/frr.conf | 25 ++++ .../bgp_redistribute_ospf/r2/frr.conf | 18 +++ .../bgp_redistribute_ospf/r3/frr.conf | 32 +++++ .../test_bgp_redistribute_ospf.py | 135 ++++++++++++++++++ zebra/zebra_rib.c | 2 + 6 files changed, 212 insertions(+) create mode 100644 tests/topotests/bgp_redistribute_ospf/__init__.py create mode 100644 tests/topotests/bgp_redistribute_ospf/r1/frr.conf create mode 100644 tests/topotests/bgp_redistribute_ospf/r2/frr.conf create mode 100644 tests/topotests/bgp_redistribute_ospf/r3/frr.conf create mode 100644 tests/topotests/bgp_redistribute_ospf/test_bgp_redistribute_ospf.py diff --git a/tests/topotests/bgp_redistribute_ospf/__init__.py b/tests/topotests/bgp_redistribute_ospf/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/tests/topotests/bgp_redistribute_ospf/r1/frr.conf b/tests/topotests/bgp_redistribute_ospf/r1/frr.conf new file mode 100644 index 000000000000..54359e4383cc --- /dev/null +++ b/tests/topotests/bgp_redistribute_ospf/r1/frr.conf @@ -0,0 +1,25 @@ +! +int r1-eth0 + ip address 192.168.1.1/24 +! +int r1-eth1 + ip address 192.168.2.1/24 + ip ospf dead-interval 3 + ip ospf hello-interval 1 +! +int r1-eth2 + ip address 172.16.0.1/16 +! +router bgp 1 + no bgp ebgp-requires-policy + neighbor 192.168.1.2 remote-as external + address-family ipv4 unicast + network 172.16.0.0/16 + exit-address-family +! +router-id 0.0.0.1 +! +router ospf + network 192.168.2.0/24 area 0 + network 172.16.0.0/16 area 0 +! diff --git a/tests/topotests/bgp_redistribute_ospf/r2/frr.conf b/tests/topotests/bgp_redistribute_ospf/r2/frr.conf new file mode 100644 index 000000000000..9d4da0e3be4d --- /dev/null +++ b/tests/topotests/bgp_redistribute_ospf/r2/frr.conf @@ -0,0 +1,18 @@ +! +! +int r2-eth0 + ip address 192.168.2.2/24 + ip ospf dead-interval 3 + ip ospf hello-interval 1 +! +int r2-eth1 + ip address 192.168.3.1/24 + ip ospf dead-interval 3 + ip ospf hello-interval 1 +! +router-id 0.0.0.2 +! +router ospf + network 192.168.2.0/24 area 0 + network 192.168.3.0/24 area 0 +! diff --git a/tests/topotests/bgp_redistribute_ospf/r3/frr.conf b/tests/topotests/bgp_redistribute_ospf/r3/frr.conf new file mode 100644 index 000000000000..1130fe05031c --- /dev/null +++ b/tests/topotests/bgp_redistribute_ospf/r3/frr.conf @@ -0,0 +1,32 @@ +! +debug zebra events +debug zebra packet +debug zebra kernel +debug zebra rib detailed +debug bgp zebra + +! +int r3-eth0 + ip address 192.168.1.2/24 +! +int r3-eth1 + ip address 192.168.3.2/24 + ip ospf dead-interval 3 + ip ospf hello-interval 1 +! +router-id 0.0.0.3 +! +router bgp 100 + no bgp ebgp-requires-policy + neighbor 192.168.1.1 remote-as external + address-family ipv4 unicast + redistribute ospf route-map red + exit-address-family +! +router ospf + network 192.168.3.0/24 area 0 +exit +! +route-map red permit 10 +! set weight 0 +exit diff --git a/tests/topotests/bgp_redistribute_ospf/test_bgp_redistribute_ospf.py b/tests/topotests/bgp_redistribute_ospf/test_bgp_redistribute_ospf.py new file mode 100644 index 000000000000..e50668320f0a --- /dev/null +++ b/tests/topotests/bgp_redistribute_ospf/test_bgp_redistribute_ospf.py @@ -0,0 +1,135 @@ +#!/usr/bin/env python +# SPDX-License-Identifier: ISC + +# Copyright (c) 2023 by +# Donatas Abraitis +# + +""" +""" + +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, TopoRouter, get_topogen + +pytestmark = [pytest.mark.ospfd, pytest.mark.bgpd] + + +def build_topo(tgen): + for routern in range(1, 4): + tgen.add_router("r{}".format(routern)) + + switch = tgen.add_switch("s1") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r3"]) + + switch = tgen.add_switch("s2") + switch.add_link(tgen.gears["r1"]) + switch.add_link(tgen.gears["r2"]) + + switch = tgen.add_switch("s3") + switch.add_link(tgen.gears["r2"]) + switch.add_link(tgen.gears["r3"]) + + switch = tgen.add_switch("s4") + switch.add_link(tgen.gears["r1"]) + +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_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_node_target_extended_communities(): + tgen = get_topogen() + + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + r1 = tgen.gears["r1"] + r2 = tgen.gears["r2"] + r3 = tgen.gears["r3"] + r4 = tgen.gears["r4"] + + def _bgp_converge(): + output = json.loads(r1.vtysh_cmd("show bgp summary json")) + expected = { + "ipv4Unicast": { + "peers": { + "192.168.1.2": { + "pfxSnt": 1, + "state": "Established", + }, + "192.168.1.3": { + "pfxSnt": 1, + "state": "Established", + }, + "192.168.1.4": { + "pfxSnt": 1, + "state": "Established", + }, + } + } + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial(_bgp_converge) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "Failed announcing 10.10.10.10/32 to r2, r3, and r4" + + def _bgp_check_route(router, exists): + output = json.loads(router.vtysh_cmd("show bgp ipv4 unicast json")) + if exists: + expected = { + "routes": { + "10.10.10.10/32": [ + { + "valid": True, + } + ] + } + } + else: + expected = { + "routes": { + "10.10.10.10/32": None, + } + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial(_bgp_check_route, r3, True) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "10.10.10.10/32 is not installed, but SHOULD be" + + test_func = functools.partial(_bgp_check_route, r4, True) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "10.10.10.10/32 is not installed, but SHOULD be" + + test_func = functools.partial(_bgp_check_route, r2, False) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "10.10.10.10/32 is installed, but SHOULD NOT be" + + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 431c6b050038..e90fabfc15ad 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -1325,6 +1325,8 @@ static void rib_process(struct route_node *rn) } if (best != re) UNSET_FLAG(re->status, ROUTE_ENTRY_CHANGED); + else + redistribute_update(rn, re, NULL); } /* RNODE_FOREACH_RE */ /* If no FIB override route, use the selected route also for FIB */