]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/isis_lsp_bits_topo1/test_isis_lsp_bits_topo1.py
4 # test_isis_lsp_bits_topo1.py
5 # Part of NetDEF Topology Tests
7 # Copyright (c) 2021 by Volta Networks
9 # Permission to use, copy, modify, and/or distribute this software
10 # for any purpose with or without fee is hereby granted, provided
11 # that the above copyright notice and this permission notice appear
14 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
15 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
17 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
18 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
19 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
20 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
25 test_isis_lsp_bits_topo1.py:
37 +---------+ | +---------+
39 | RT2 |eth-sw1 | eth-sw1| RT3 |
40 | 2.2.2.2 +----------+----------+ 3.3.3.3 |
41 | L1|L2 | 10.0.1.0/24 | L1|L2 |
42 +---------+ +---------+
45 10.0.2.0/24| |10.0.4.0/24
48 +---------+ +---------+
50 | RT4 | 10.0.6.0/24 | RT5 |
51 | 4.4.4.4 +---------------------+ 5.5.5.5 |
52 | L1|L2 |eth-rt5 eth-rt4| L1|L2 |
53 +---------+ +---------+
56 10.0.7.0/24| |10.0.8.0/24
60 +----------+ 6.6.6.6 +-----------+
71 from time
import sleep
72 from functools
import partial
74 # Save the Current Working Directory to find configuration files.
75 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
76 sys
.path
.append(os
.path
.join(CWD
, "../"))
78 # pylint: disable=C0413
79 # Import topogen and topotest helpers
80 from lib
import topotest
81 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
82 from lib
.topolog
import logger
84 # Required to instantiate the topology builder class.
85 from mininet
.topo
import Topo
87 # Global multi-dimensional dictionary containing all expected outputs
91 class TemplateTopo(Topo
):
92 "Test topology builder"
94 def build(self
, *_args
, **_opts
):
96 tgen
= get_topogen(self
)
101 for router
in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]:
102 tgen
.add_router(router
)
107 switch
= tgen
.add_switch("s1")
108 switch
.add_link(tgen
.gears
["rt1"], nodeif
="eth-sw1")
109 switch
.add_link(tgen
.gears
["rt2"], nodeif
="eth-sw1")
110 switch
.add_link(tgen
.gears
["rt3"], nodeif
="eth-sw1")
112 switch
= tgen
.add_switch("s2")
113 switch
.add_link(tgen
.gears
["rt2"], nodeif
="eth-rt4")
114 switch
.add_link(tgen
.gears
["rt4"], nodeif
="eth-rt2")
116 switch
= tgen
.add_switch("s4")
117 switch
.add_link(tgen
.gears
["rt3"], nodeif
="eth-rt5")
118 switch
.add_link(tgen
.gears
["rt5"], nodeif
="eth-rt3")
120 switch
= tgen
.add_switch("s6")
121 switch
.add_link(tgen
.gears
["rt4"], nodeif
="eth-rt5")
122 switch
.add_link(tgen
.gears
["rt5"], nodeif
="eth-rt4")
124 switch
= tgen
.add_switch("s7")
125 switch
.add_link(tgen
.gears
["rt4"], nodeif
="eth-rt6")
126 switch
.add_link(tgen
.gears
["rt6"], nodeif
="eth-rt4")
128 switch
= tgen
.add_switch("s8")
129 switch
.add_link(tgen
.gears
["rt5"], nodeif
="eth-rt6")
130 switch
.add_link(tgen
.gears
["rt6"], nodeif
="eth-rt5")
133 def setup_module(mod
):
134 "Sets up the pytest environment"
135 tgen
= Topogen(TemplateTopo
, mod
.__name
__)
136 tgen
.start_topology()
138 router_list
= tgen
.routers()
140 # For all registered routers, load the zebra configuration file
141 for rname
, router
in router_list
.items():
143 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
146 TopoRouter
.RD_ISIS
, os
.path
.join(CWD
, "{}/isisd.conf".format(rname
))
152 def teardown_module(mod
):
153 "Teardown the pytest environment"
156 # This function tears down the whole topology.
160 def router_compare_json_output(rname
, command
, reference
):
161 "Compare router JSON output"
163 logger
.info('Comparing router "%s" "%s" output', rname
, command
)
166 filename
= "{}/{}/{}".format(CWD
, rname
, reference
)
167 expected
= json
.loads(open(filename
).read())
169 # Run test function until we get an result. Wait at most 60 seconds.
170 test_func
= partial(topotest
.router_json_cmp
, tgen
.gears
[rname
], command
, expected
)
171 _
, diff
= topotest
.run_and_expect(test_func
, None, count
=120, wait
=0.5)
172 assertmsg
= '"{}" JSON output mismatches the expected result'.format(rname
)
173 assert diff
is None, assertmsg
179 # Test initial network convergence
180 # Attach-bit defaults to on, so expect default route pointing to L1|L2 router
182 def test_isis_adjacencies_step1():
183 logger
.info("Test (step 1): check IS-IS adjacencies")
186 # Skip if previous fatal error condition is raised
187 if tgen
.routers_have_failure():
188 pytest
.skip(tgen
.errors
)
190 for rname
in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]:
191 router_compare_json_output(
193 "show yang operational-data /frr-interface:lib isisd",
194 "step1/show_yang_interface_isis_adjacencies.ref",
198 def test_rib_ipv4_step1():
199 logger
.info("Test (step 1): verify IPv4 RIB")
202 # Skip if previous fatal error condition is raised
203 if tgen
.routers_have_failure():
204 pytest
.skip(tgen
.errors
)
206 for rname
in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]:
207 router_compare_json_output(
208 rname
, "show ip route isis json", "step1/show_ip_route.ref"
212 def test_rib_ipv6_step1():
213 logger
.info("Test (step 1): verify IPv6 RIB")
216 # Skip if previous fatal error condition is raised
217 if tgen
.routers_have_failure():
218 pytest
.skip(tgen
.errors
)
220 for rname
in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]:
221 router_compare_json_output(
222 rname
, "show ipv6 route isis json", "step1/show_ipv6_route.ref"
230 # -Disable sending Attach bit on RT2 and RT4
233 # -RT1 should remove the default route pointing to RT2
234 # -RT6 should remove the default route pointing to RT4
236 def test_rib_ipv4_step2():
237 logger
.info("Test (step 2): verify IPv4 RIB")
240 # Skip if previous fatal error condition is raised
241 if tgen
.routers_have_failure():
242 pytest
.skip(tgen
.errors
)
244 logger
.info("Disabling setting the attached-bit on RT2 and RT4")
246 'vtysh -c "conf t" -c "router isis 1" -c "no attached-bit send"'
249 'vtysh -c "conf t" -c "router isis 1" -c "no attached-bit send"'
252 for rname
in ["rt1", "rt6"]:
253 router_compare_json_output(
254 rname
, "show ip route isis json", "step2/show_ip_route.ref"
258 def test_rib_ipv6_step2():
259 logger
.info("Test (step 2): verify IPv6 RIB")
262 # Skip if previous fatal error condition is raised
263 if tgen
.routers_have_failure():
264 pytest
.skip(tgen
.errors
)
266 for rname
in ["rt1", "rt6"]:
267 router_compare_json_output(
268 rname
, "show ipv6 route isis json", "step2/show_ipv6_route.ref"
276 # -restore attach-bit, enable sending attach-bit
277 # -disble processing a LSP with attach bit set
280 # -RT1 and RT6 should not install a default route
282 def test_rib_ipv4_step3():
283 logger
.info("Test (step 3): verify IPv4 RIB")
286 # Skip if previous fatal error condition is raised
287 if tgen
.routers_have_failure():
288 pytest
.skip(tgen
.errors
)
290 logger
.info("Enable setting the attached-bit on RT2 and RT4")
291 tgen
.net
["rt2"].cmd('vtysh -c "conf t" -c "router isis 1" -c "attached-bit send"')
292 tgen
.net
["rt4"].cmd('vtysh -c "conf t" -c "router isis 1" -c "attached-bit send"')
294 logger
.info("Disable processing received attached-bit in LSP on RT1 and RT6")
296 'vtysh -c "conf t" -c "router isis 1" -c "attached-bit receive ignore"'
299 'vtysh -c "conf t" -c "router isis 1" -c "attached-bit receive ignore"'
302 for rname
in ["rt1", "rt6"]:
303 router_compare_json_output(
304 rname
, "show ip route isis json", "step3/show_ip_route.ref"
308 def test_rib_ipv6_step3():
309 logger
.info("Test (step 3): verify IPv6 RIB")
312 # Skip if previous fatal error condition is raised
313 if tgen
.routers_have_failure():
314 pytest
.skip(tgen
.errors
)
316 for rname
in ["rt1", "rt6"]:
317 router_compare_json_output(
318 rname
, "show ipv6 route isis json", "step3/show_ipv6_route.ref"
326 # -restore back to default attach-bit config
329 # -RT1 and RT6 should add default route
330 # -no changes on other routers
332 def test_rib_ipv4_step4():
333 logger
.info("Test (step 4): verify IPv4 RIB")
336 # Skip if previous fatal error condition is raised
337 if tgen
.routers_have_failure():
338 pytest
.skip(tgen
.errors
)
341 "restore default processing on received attached-bit in LSP on RT1 and RT6"
344 'vtysh -c "conf t" -c "router isis 1" -c "no attached-bit receive ignore"'
347 'vtysh -c "conf t" -c "router isis 1" -c "no attached-bit receive ignore"'
350 for rname
in ["rt1", "rt6"]:
351 router_compare_json_output(
352 rname
, "show ip route isis json", "step4/show_ip_route.ref"
356 def test_rib_ipv6_step4():
357 logger
.info("Test (step 4): verify IPv6 RIB")
360 # Skip if previous fatal error condition is raised
361 if tgen
.routers_have_failure():
362 pytest
.skip(tgen
.errors
)
364 for rname
in ["rt1", "rt6"]:
365 router_compare_json_output(
366 rname
, "show ipv6 route isis json", "step4/show_ipv6_route.ref"
370 # Memory leak test template
371 def test_memory_leak():
372 "Run the memory leak test and report results."
374 if not tgen
.is_memleak_enabled():
375 pytest
.skip("Memory leak test/report is disabled")
377 tgen
.report_memory_leaks()
380 if __name__
== "__main__":
381 args
= ["-s"] + sys
.argv
[1:]
382 sys
.exit(pytest
.main(args
))