]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_node_target_extcommunities/test_bgp_node_target_extcommunities.py
2 # SPDX-License-Identifier: ISC
4 # Copyright (c) 2023 by
5 # Donatas Abraitis <donatas@opensourcerouting.org>
9 Test if Node Target Extended Communities works.
11 At r1 we set NT to 192.168.1.3 and 192.168.1.4 (this is the R3/R4 router-id),
12 and that means 10.10.10.10/32 MUST be installed on R3 and R4, but not on R2,
13 because this route does not have NT:192.168.1.2.
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
.topogen
import Topogen
, TopoRouter
, get_topogen
29 pytestmark
= [pytest
.mark
.bgpd
]
33 for routern
in range(1, 5):
34 tgen
.add_router("r{}".format(routern
))
36 switch
= tgen
.add_switch("s1")
37 switch
.add_link(tgen
.gears
["r1"])
38 switch
.add_link(tgen
.gears
["r2"])
39 switch
.add_link(tgen
.gears
["r3"])
40 switch
.add_link(tgen
.gears
["r4"])
43 def setup_module(mod
):
44 tgen
= Topogen(build_topo
, mod
.__name
__)
47 router_list
= tgen
.routers()
49 for i
, (rname
, router
) in enumerate(router_list
.items(), 1):
50 router
.load_frr_config(os
.path
.join(CWD
, "{}/frr.conf".format(rname
)))
55 def teardown_module(mod
):
60 def test_bgp_node_target_extended_communities():
63 if tgen
.routers_have_failure():
64 pytest
.skip(tgen
.errors
)
72 output
= json
.loads(r1
.vtysh_cmd("show bgp summary json"))
78 "state": "Established",
82 "state": "Established",
86 "state": "Established",
91 return topotest
.json_cmp(output
, expected
)
93 test_func
= functools
.partial(_bgp_converge
)
94 _
, result
= topotest
.run_and_expect(test_func
, None, count
=30, wait
=1)
95 assert result
is None, "Failed announcing 10.10.10.10/32 to r2, r3, and r4"
97 def _bgp_check_route(router
, exists
):
98 output
= json
.loads(router
.vtysh_cmd("show bgp ipv4 unicast json"))
112 "10.10.10.10/32": None,
115 return topotest
.json_cmp(output
, expected
)
117 test_func
= functools
.partial(_bgp_check_route
, r3
, True)
118 _
, result
= topotest
.run_and_expect(test_func
, None, count
=30, wait
=1)
119 assert result
is None, "10.10.10.10/32 is not installed, but SHOULD be"
121 test_func
= functools
.partial(_bgp_check_route
, r4
, True)
122 _
, result
= topotest
.run_and_expect(test_func
, None, count
=30, wait
=1)
123 assert result
is None, "10.10.10.10/32 is not installed, but SHOULD be"
125 test_func
= functools
.partial(_bgp_check_route
, r2
, False)
126 _
, result
= topotest
.run_and_expect(test_func
, None, count
=30, wait
=1)
127 assert result
is None, "10.10.10.10/32 is installed, but SHOULD NOT be"
130 if __name__
== "__main__":
131 args
= ["-s"] + sys
.argv
[1:]
132 sys
.exit(pytest
.main(args
))