]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bfd_topo3/test_bfd_topo3.py
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[mirror_frr.git] / tests / topotests / bfd_topo3 / test_bfd_topo3.py
1 #!/usr/bin/env python
2
3 #
4 # test_bfd_topo3.py
5 # Part of NetDEF Topology Tests
6 #
7 # Copyright (c) 2020 by
8 # Network Device Education Foundation, Inc. ("NetDEF")
9 #
10 # Permission to use, copy, modify, and/or distribute this software
11 # for any purpose with or without fee is hereby granted, provided
12 # that the above copyright notice and this permission notice appear
13 # in all copies.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
16 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
18 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
19 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
21 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22 # OF THIS SOFTWARE.
23 #
24
25 """
26 test_bfd_topo3.py: Test the FRR BFD daemon multi hop.
27 """
28
29 import os
30 import sys
31 import json
32 from functools import partial
33 import pytest
34
35 # Save the Current Working Directory to find configuration files.
36 CWD = os.path.dirname(os.path.realpath(__file__))
37 sys.path.append(os.path.join(CWD, "../"))
38
39 # pylint: disable=C0413
40 # Import topogen and topotest helpers
41 from lib import topotest
42 from lib.topogen import Topogen, TopoRouter, get_topogen
43 from lib.topolog import logger
44
45 pytestmark = [pytest.mark.bfdd, pytest.mark.bgpd]
46
47
48 def setup_module(mod):
49 "Sets up the pytest environment"
50 topodef = {
51 "s1": ("r1", "r2"),
52 "s2": ("r2", "r3"),
53 "s3": ("r3", "r4"),
54 "s4": ("r4", "r5", "r6"),
55 }
56 tgen = Topogen(topodef, mod.__name__)
57 tgen.start_topology()
58
59 router_list = tgen.routers()
60 for rname, router in router_list.items():
61 daemon_file = "{}/{}/bfdd.conf".format(CWD, rname)
62 if os.path.isfile(daemon_file):
63 router.load_config(TopoRouter.RD_BFD, daemon_file)
64
65 daemon_file = "{}/{}/zebra.conf".format(CWD, rname)
66 if os.path.isfile(daemon_file):
67 router.load_config(TopoRouter.RD_ZEBRA, daemon_file)
68
69 daemon_file = "{}/{}/bgpd.conf".format(CWD, rname)
70 if os.path.isfile(daemon_file):
71 router.load_config(TopoRouter.RD_BGP, daemon_file)
72
73 daemon_file = "{}/{}/staticd.conf".format(CWD, rname)
74 if os.path.isfile(daemon_file):
75 router.load_config(TopoRouter.RD_STATIC, daemon_file)
76
77 # Initialize all routers.
78 tgen.start_router()
79
80
81 def test_wait_bgp_convergence():
82 "Wait for BGP to converge"
83 tgen = get_topogen()
84 if tgen.routers_have_failure():
85 pytest.skip(tgen.errors)
86
87 logger.info("waiting for protocols to converge")
88
89 def expect_loopback_route(router, iptype, route, proto):
90 "Wait until route is present on RIB for protocol."
91 logger.info("waiting route {} in {}".format(route, router))
92 test_func = partial(
93 topotest.router_json_cmp,
94 tgen.gears[router],
95 "show {} route json".format(iptype),
96 {route: [{"protocol": proto}]},
97 )
98 _, result = topotest.run_and_expect(test_func, None, count=130, wait=1)
99 assertmsg = '"{}" OSPF convergence failure'.format(router)
100 assert result is None, assertmsg
101
102 # Wait for R1 <-> R2 convergence.
103 expect_loopback_route("r1", "ip", "10.254.254.2/32", "bgp")
104 # Wait for R1 <-> R3 convergence.
105 expect_loopback_route("r1", "ip", "10.254.254.3/32", "bgp")
106 # Wait for R1 <-> R4 convergence.
107 expect_loopback_route("r1", "ip", "10.254.254.4/32", "bgp")
108 # Wait for R1 <-> R5 convergence.
109 expect_loopback_route("r1", "ip", "10.254.254.5/32", "bgp")
110 # Wait for R1 <-> R6 convergence.
111 expect_loopback_route("r1", "ip", "10.254.254.6/32", "bgp")
112
113 # Wait for R2 <-> R1 convergence.
114 expect_loopback_route("r2", "ip", "10.254.254.1/32", "bgp")
115 # Wait for R2 <-> R3 convergence.
116 expect_loopback_route("r2", "ip", "10.254.254.3/32", "bgp")
117 # Wait for R2 <-> R4 convergence.
118 expect_loopback_route("r2", "ip", "10.254.254.4/32", "bgp")
119 # Wait for R2 <-> R5 convergence.
120 expect_loopback_route("r2", "ip", "10.254.254.5/32", "bgp")
121 # Wait for R2 <-> R6 convergence.
122 expect_loopback_route("r2", "ip", "10.254.254.6/32", "bgp")
123
124 # Wait for R3 <-> R1 convergence.
125 expect_loopback_route("r3", "ip", "10.254.254.1/32", "bgp")
126 # Wait for R3 <-> R2 convergence.
127 expect_loopback_route("r3", "ip", "10.254.254.2/32", "bgp")
128 # Wait for R3 <-> R4 convergence.
129 expect_loopback_route("r3", "ip", "10.254.254.4/32", "bgp")
130 # Wait for R3 <-> R5 convergence.
131 expect_loopback_route("r3", "ip", "10.254.254.5/32", "bgp")
132 # Wait for R3 <-> R6 convergence.
133 expect_loopback_route("r3", "ip", "10.254.254.6/32", "bgp")
134
135 # Wait for R4 <-> R1 convergence.
136 expect_loopback_route("r4", "ip", "10.254.254.1/32", "bgp")
137 # Wait for R4 <-> R2 convergence.
138 expect_loopback_route("r4", "ip", "10.254.254.2/32", "bgp")
139 # Wait for R4 <-> R3 convergence.
140 expect_loopback_route("r4", "ip", "10.254.254.3/32", "bgp")
141 # Wait for R4 <-> R5 convergence.
142 expect_loopback_route("r4", "ip", "10.254.254.5/32", "static")
143 # Wait for R4 <-> R6 convergence.
144 expect_loopback_route("r4", "ip", "10.254.254.6/32", "static")
145
146 # Wait for R5 <-> R6 convergence.
147 expect_loopback_route("r3", "ipv6", "2001:db8:5::/64", "static")
148 # Wait for R6 <-> R5 convergence.
149 expect_loopback_route("r6", "ipv6", "2001:db8:1::/64", "static")
150
151
152 def test_wait_bfd_convergence():
153 "Wait for BFD to converge"
154 tgen = get_topogen()
155 if tgen.routers_have_failure():
156 pytest.skip(tgen.errors)
157
158 logger.info("test BFD configurations")
159
160 def expect_bfd_configuration(router):
161 "Load JSON file and compare with 'show bfd peer json'"
162 logger.info("waiting BFD configuration on router {}".format(router))
163 bfd_config = json.loads(open("{}/{}/bfd-peers.json".format(CWD, router)).read())
164 test_func = partial(
165 topotest.router_json_cmp,
166 tgen.gears[router],
167 "show bfd peers json",
168 bfd_config,
169 )
170 _, result = topotest.run_and_expect(test_func, None, count=130, wait=1)
171 assertmsg = '"{}" BFD configuration failure'.format(router)
172 assert result is None, assertmsg
173
174 expect_bfd_configuration("r1")
175 expect_bfd_configuration("r2")
176 expect_bfd_configuration("r3")
177 expect_bfd_configuration("r4")
178 expect_bfd_configuration("r5")
179 expect_bfd_configuration("r6")
180
181
182 def test_static_route_monitoring():
183 "Test static route monitoring output."
184 tgen = get_topogen()
185 if tgen.routers_have_failure():
186 pytest.skip(tgen.errors)
187
188 logger.info("test BFD static route status")
189
190 def expect_static_bfd_output(router, filename):
191 "Load JSON file and compare with 'show bfd peer json'"
192 logger.info("waiting BFD configuration on router {}".format(router))
193 bfd_config = json.loads(
194 open("{}/{}/{}.json".format(CWD, router, filename)).read()
195 )
196 test_func = partial(
197 topotest.router_json_cmp,
198 tgen.gears[router],
199 "show bfd static route json",
200 bfd_config,
201 )
202 _, result = topotest.run_and_expect(test_func, None, count=20, wait=1)
203 assertmsg = '"{}" BFD static route status failure'.format(router)
204 assert result is None, assertmsg
205
206 expect_static_bfd_output("r3", "bfd-static")
207 expect_static_bfd_output("r6", "bfd-static")
208
209 logger.info("Setting r4 link down ...")
210
211 tgen.gears["r4"].link_enable("r4-eth0", False)
212
213 expect_static_bfd_output("r3", "bfd-static-down")
214 expect_static_bfd_output("r6", "bfd-static-down")
215
216
217 def test_expect_static_rib_removal():
218 "Test that route got removed from RIB (staticd and bgpd)."
219
220 tgen = get_topogen()
221 if tgen.routers_have_failure():
222 pytest.skip(tgen.errors)
223
224 def expect_route_missing(router, iptype, route):
225 "Wait until route is present on RIB for protocol."
226 logger.info("waiting route {} to disapear in {}".format(route, router))
227 test_func = partial(
228 topotest.router_json_cmp,
229 tgen.gears[router],
230 "show {} route json".format(iptype),
231 {route: None},
232 )
233 rv, result = topotest.run_and_expect(test_func, None, count=20, wait=1)
234 assertmsg = '"{}" convergence failure'.format(router)
235 assert result is None, assertmsg
236
237 expect_route_missing("r1", "ip", "10.254.254.5/32")
238 expect_route_missing("r2", "ip", "10.254.254.5/32")
239 expect_route_missing("r3", "ip", "10.254.254.5/32")
240 expect_route_missing("r3", "ipv6", "2001:db8:5::/64")
241 expect_route_missing("r6", "ipv6", "2001:db8:1::/64")
242
243
244 def teardown_module(_mod):
245 "Teardown the pytest environment"
246 tgen = get_topogen()
247 tgen.stop_topology()
248
249
250 def test_memory_leak():
251 "Run the memory leak test and report results."
252 tgen = get_topogen()
253 if not tgen.is_memleak_enabled():
254 pytest.skip("Memory leak test/report is disabled")
255
256 tgen.report_memory_leaks()
257
258
259 if __name__ == "__main__":
260 args = ["-s"] + sys.argv[1:]
261 sys.exit(pytest.main(args))