]>
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 pytestmark
= [pytest
.mark
.isisd
]
90 # Global multi-dimensional dictionary containing all expected outputs
94 class TemplateTopo(Topo
):
95 "Test topology builder"
97 def build(self
, *_args
, **_opts
):
99 tgen
= get_topogen(self
)
104 for router
in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]:
105 tgen
.add_router(router
)
110 switch
= tgen
.add_switch("s1")
111 switch
.add_link(tgen
.gears
["rt1"], nodeif
="eth-sw1")
112 switch
.add_link(tgen
.gears
["rt2"], nodeif
="eth-sw1")
113 switch
.add_link(tgen
.gears
["rt3"], nodeif
="eth-sw1")
115 switch
= tgen
.add_switch("s2")
116 switch
.add_link(tgen
.gears
["rt2"], nodeif
="eth-rt4")
117 switch
.add_link(tgen
.gears
["rt4"], nodeif
="eth-rt2")
119 switch
= tgen
.add_switch("s4")
120 switch
.add_link(tgen
.gears
["rt3"], nodeif
="eth-rt5")
121 switch
.add_link(tgen
.gears
["rt5"], nodeif
="eth-rt3")
123 switch
= tgen
.add_switch("s6")
124 switch
.add_link(tgen
.gears
["rt4"], nodeif
="eth-rt5")
125 switch
.add_link(tgen
.gears
["rt5"], nodeif
="eth-rt4")
127 switch
= tgen
.add_switch("s7")
128 switch
.add_link(tgen
.gears
["rt4"], nodeif
="eth-rt6")
129 switch
.add_link(tgen
.gears
["rt6"], nodeif
="eth-rt4")
131 switch
= tgen
.add_switch("s8")
132 switch
.add_link(tgen
.gears
["rt5"], nodeif
="eth-rt6")
133 switch
.add_link(tgen
.gears
["rt6"], nodeif
="eth-rt5")
136 def setup_module(mod
):
137 "Sets up the pytest environment"
138 tgen
= Topogen(TemplateTopo
, mod
.__name
__)
139 tgen
.start_topology()
141 router_list
= tgen
.routers()
143 # For all registered routers, load the zebra configuration file
144 for rname
, router
in router_list
.items():
146 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
149 TopoRouter
.RD_ISIS
, os
.path
.join(CWD
, "{}/isisd.conf".format(rname
))
155 def teardown_module(mod
):
156 "Teardown the pytest environment"
159 # This function tears down the whole topology.
163 def router_compare_json_output(rname
, command
, reference
):
164 "Compare router JSON output"
166 logger
.info('Comparing router "%s" "%s" output', rname
, command
)
169 filename
= "{}/{}/{}".format(CWD
, rname
, reference
)
170 expected
= json
.loads(open(filename
).read())
172 # Run test function until we get an result. Wait at most 60 seconds.
173 test_func
= partial(topotest
.router_json_cmp
, tgen
.gears
[rname
], command
, expected
)
174 _
, diff
= topotest
.run_and_expect(test_func
, None, count
=120, wait
=0.5)
175 assertmsg
= '"{}" JSON output mismatches the expected result'.format(rname
)
176 assert diff
is None, assertmsg
182 # Test initial network convergence
183 # Attach-bit defaults to on, so expect default route pointing to L1|L2 router
185 def test_isis_adjacencies_step1():
186 logger
.info("Test (step 1): check IS-IS adjacencies")
189 # Skip if previous fatal error condition is raised
190 if tgen
.routers_have_failure():
191 pytest
.skip(tgen
.errors
)
193 for rname
in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]:
194 router_compare_json_output(
196 "show yang operational-data /frr-interface:lib isisd",
197 "step1/show_yang_interface_isis_adjacencies.ref",
201 def test_rib_ipv4_step1():
202 logger
.info("Test (step 1): verify IPv4 RIB")
205 # Skip if previous fatal error condition is raised
206 if tgen
.routers_have_failure():
207 pytest
.skip(tgen
.errors
)
209 for rname
in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]:
210 router_compare_json_output(
211 rname
, "show ip route isis json", "step1/show_ip_route.ref"
215 def test_rib_ipv6_step1():
216 logger
.info("Test (step 1): verify IPv6 RIB")
219 # Skip if previous fatal error condition is raised
220 if tgen
.routers_have_failure():
221 pytest
.skip(tgen
.errors
)
223 for rname
in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]:
224 router_compare_json_output(
225 rname
, "show ipv6 route isis json", "step1/show_ipv6_route.ref"
233 # -Disable sending Attach bit on RT2 and RT4
236 # -RT1 should remove the default route pointing to RT2
237 # -RT6 should remove the default route pointing to RT4
239 def test_rib_ipv4_step2():
240 logger
.info("Test (step 2): verify IPv4 RIB")
243 # Skip if previous fatal error condition is raised
244 if tgen
.routers_have_failure():
245 pytest
.skip(tgen
.errors
)
247 logger
.info("Disabling setting the attached-bit on RT2 and RT4")
249 'vtysh -c "conf t" -c "router isis 1" -c "no attached-bit send"'
252 'vtysh -c "conf t" -c "router isis 1" -c "no attached-bit send"'
255 for rname
in ["rt1", "rt6"]:
256 router_compare_json_output(
257 rname
, "show ip route isis json", "step2/show_ip_route.ref"
261 def test_rib_ipv6_step2():
262 logger
.info("Test (step 2): verify IPv6 RIB")
265 # Skip if previous fatal error condition is raised
266 if tgen
.routers_have_failure():
267 pytest
.skip(tgen
.errors
)
269 for rname
in ["rt1", "rt6"]:
270 router_compare_json_output(
271 rname
, "show ipv6 route isis json", "step2/show_ipv6_route.ref"
279 # -restore attach-bit, enable sending attach-bit
280 # -disble processing a LSP with attach bit set
283 # -RT1 and RT6 should not install a default route
285 def test_rib_ipv4_step3():
286 logger
.info("Test (step 3): verify IPv4 RIB")
289 # Skip if previous fatal error condition is raised
290 if tgen
.routers_have_failure():
291 pytest
.skip(tgen
.errors
)
293 logger
.info("Enable setting the attached-bit on RT2 and RT4")
294 tgen
.net
["rt2"].cmd('vtysh -c "conf t" -c "router isis 1" -c "attached-bit send"')
295 tgen
.net
["rt4"].cmd('vtysh -c "conf t" -c "router isis 1" -c "attached-bit send"')
297 logger
.info("Disable processing received attached-bit in LSP on RT1 and RT6")
299 'vtysh -c "conf t" -c "router isis 1" -c "attached-bit receive ignore"'
302 'vtysh -c "conf t" -c "router isis 1" -c "attached-bit receive ignore"'
305 for rname
in ["rt1", "rt6"]:
306 router_compare_json_output(
307 rname
, "show ip route isis json", "step3/show_ip_route.ref"
311 def test_rib_ipv6_step3():
312 logger
.info("Test (step 3): verify IPv6 RIB")
315 # Skip if previous fatal error condition is raised
316 if tgen
.routers_have_failure():
317 pytest
.skip(tgen
.errors
)
319 for rname
in ["rt1", "rt6"]:
320 router_compare_json_output(
321 rname
, "show ipv6 route isis json", "step3/show_ipv6_route.ref"
329 # -restore back to default attach-bit config
332 # -RT1 and RT6 should add default route
333 # -no changes on other routers
335 def test_rib_ipv4_step4():
336 logger
.info("Test (step 4): verify IPv4 RIB")
339 # Skip if previous fatal error condition is raised
340 if tgen
.routers_have_failure():
341 pytest
.skip(tgen
.errors
)
344 "restore default processing on received attached-bit in LSP on RT1 and RT6"
347 'vtysh -c "conf t" -c "router isis 1" -c "no attached-bit receive ignore"'
350 'vtysh -c "conf t" -c "router isis 1" -c "no attached-bit receive ignore"'
353 for rname
in ["rt1", "rt6"]:
354 router_compare_json_output(
355 rname
, "show ip route isis json", "step4/show_ip_route.ref"
359 def test_rib_ipv6_step4():
360 logger
.info("Test (step 4): verify IPv6 RIB")
363 # Skip if previous fatal error condition is raised
364 if tgen
.routers_have_failure():
365 pytest
.skip(tgen
.errors
)
367 for rname
in ["rt1", "rt6"]:
368 router_compare_json_output(
369 rname
, "show ipv6 route isis json", "step4/show_ipv6_route.ref"
373 # Memory leak test template
374 def test_memory_leak():
375 "Run the memory leak test and report results."
377 if not tgen
.is_memleak_enabled():
378 pytest
.skip("Memory leak test/report is disabled")
380 tgen
.report_memory_leaks()
383 if __name__
== "__main__":
384 args
= ["-s"] + sys
.argv
[1:]
385 sys
.exit(pytest
.main(args
))