]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bfd_topo3/test_bfd_topo3.py
5 # Part of NetDEF Topology Tests
7 # Copyright (c) 2020 by
8 # Network Device Education Foundation, Inc. ("NetDEF")
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
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
26 test_bfd_topo3.py: Test the FRR BFD daemon multi hop.
32 from functools
import partial
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
, "../"))
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
45 pytestmark
= [pytest
.mark
.bfdd
, pytest
.mark
.bgpd
]
48 def setup_module(mod
):
49 "Sets up the pytest environment"
54 "s4": ("r4", "r5", "r6"),
56 tgen
= Topogen(topodef
, mod
.__name
__)
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
)
65 daemon_file
= "{}/{}/zebra.conf".format(CWD
, rname
)
66 if os
.path
.isfile(daemon_file
):
67 router
.load_config(TopoRouter
.RD_ZEBRA
, daemon_file
)
69 daemon_file
= "{}/{}/bgpd.conf".format(CWD
, rname
)
70 if os
.path
.isfile(daemon_file
):
71 router
.load_config(TopoRouter
.RD_BGP
, daemon_file
)
73 daemon_file
= "{}/{}/staticd.conf".format(CWD
, rname
)
74 if os
.path
.isfile(daemon_file
):
75 router
.load_config(TopoRouter
.RD_STATIC
, daemon_file
)
77 # Initialize all routers.
81 def test_wait_bgp_convergence():
82 "Wait for BGP to converge"
84 if tgen
.routers_have_failure():
85 pytest
.skip(tgen
.errors
)
87 logger
.info("waiting for protocols to converge")
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
))
93 topotest
.router_json_cmp
,
95 "show {} route json".format(iptype
),
96 {route
: [{"protocol": proto
}]},
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
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")
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")
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")
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")
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")
152 def test_wait_bfd_convergence():
153 "Wait for BFD to converge"
155 if tgen
.routers_have_failure():
156 pytest
.skip(tgen
.errors
)
158 logger
.info("test BFD configurations")
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())
165 topotest
.router_json_cmp
,
167 "show bfd peers json",
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
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")
182 def test_static_route_monitoring():
183 "Test static route monitoring output."
185 if tgen
.routers_have_failure():
186 pytest
.skip(tgen
.errors
)
188 logger
.info("test BFD static route status")
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()
197 topotest
.router_json_cmp
,
199 "show bfd static route json",
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
206 expect_static_bfd_output("r3", "bfd-static")
207 expect_static_bfd_output("r6", "bfd-static")
209 logger
.info("Setting r4 link down ...")
211 tgen
.gears
["r4"].link_enable("r4-eth0", False)
213 expect_static_bfd_output("r3", "bfd-static-down")
214 expect_static_bfd_output("r6", "bfd-static-down")
217 def test_expect_static_rib_removal():
218 "Test that route got removed from RIB (staticd and bgpd)."
221 if tgen
.routers_have_failure():
222 pytest
.skip(tgen
.errors
)
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
))
228 topotest
.router_json_cmp
,
230 "show {} route json".format(iptype
),
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
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")
244 def teardown_module(_mod
):
245 "Teardown the pytest environment"
250 def test_memory_leak():
251 "Run the memory leak test and report results."
253 if not tgen
.is_memleak_enabled():
254 pytest
.skip("Memory leak test/report is disabled")
256 tgen
.report_memory_leaks()
259 if __name__
== "__main__":
260 args
= ["-s"] + sys
.argv
[1:]
261 sys
.exit(pytest
.main(args
))