2 # SPDX-License-Identifier: ISC
4 # test_bgp_roles_filtering.py
5 # Part of NetDEF Topology Tests
7 # Copyright (c) 2022 by Eugene Bogomazov <eb@qrator.net>
8 # Copyright (c) 2017 by
9 # Network Device Education Foundation, Inc. ("NetDEF")
13 test_bgp_roles_filtering: test leaks prevention and mitigation with roles
22 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
23 sys
.path
.append(os
.path
.join(CWD
, "../"))
25 # pylint: disable=C0413
26 from lib
import topotest
27 from lib
.bgp
import verify_bgp_convergence_from_running_config
28 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
29 from lib
.topolog
import logger
31 pytestmark
= [pytest
.mark
.bgpd
]
34 topodef
= {f
"s{i}": (f
"r{i}", "r10") for i
in range(1, 8)}
37 @pytest.fixture(scope
="module")
39 tgen
= Topogen(topodef
, request
.module
.__name
__)
41 router_list
= tgen
.routers()
42 for rname
, router
in router_list
.items():
43 router
.load_config(TopoRouter
.RD_ZEBRA
, "zebra.conf")
44 router
.load_config(TopoRouter
.RD_BGP
, "bgpd.conf")
50 @pytest.fixture(autouse
=True)
51 def skip_on_failure(tgen
):
52 if tgen
.routers_have_failure():
53 pytest
.skip("skipped because of previous test failure")
56 def test_r10_routes(tgen
):
57 # provider-undefine pair bur strict-mode was set
58 def _routes_half_converged():
59 routes
= json
.loads(tgen
.gears
["r10"].vtysh_cmd("show bgp ipv4 json"))["routes"]
60 output
= sorted(routes
.keys())
70 return output
== expected
72 success
, result
= topotest
.run_and_expect(
73 _routes_half_converged
, True, count
=20, wait
=3
75 assert success
, "Routes did not converged"
77 routes_with_otc
= list()
78 for number
in range(1, 8):
79 prefix
= f
"192.0.2.{number}/32"
80 route_details
= json
.loads(
81 tgen
.gears
["r10"].vtysh_cmd(f
"show bgp ipv4 {prefix} json")
83 if route_details
["paths"][0].get("otc") is not None:
84 routes_with_otc
.append(prefix
)
85 assert routes_with_otc
== [
93 def test_r1_routes(tgen
):
94 routes
= json
.loads(tgen
.gears
["r1"].vtysh_cmd("show bgp ipv4 json"))["routes"]
95 routes_list
= sorted(routes
.keys())
96 assert routes_list
== [
104 def test_r6_routes(tgen
):
105 routes
= json
.loads(tgen
.gears
["r6"].vtysh_cmd("show bgp ipv4 json"))["routes"]
106 routes_list
= sorted(routes
.keys())
107 assert routes_list
== [
111 "192.0.2.6/32", # own
115 def test_r4_routes(tgen
):
116 routes
= json
.loads(tgen
.gears
["r4"].vtysh_cmd("show bgp ipv4 json"))["routes"]
117 routes_list
= sorted(routes
.keys())
118 assert routes_list
== [
129 if __name__
== "__main__":
130 args
= ["-s"] + sys
.argv
[1:]
131 sys
.exit(pytest
.main(args
))