]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/isis_sr_flex_algo_topo1/test_isis_sr_flex_algo_topo1.py
2 # SPDX-License-Identifier: ISC
5 # Part of NetDEF Topology Tests
7 # Copyright 2021 by LINE Corporation, Hiroki Shirokura <hiroki.shirokura@linecorp.com>
8 # Copyright 2023 6WIND S.A.
11 test_isis_sr_flex_algo_topo1.py:
13 [+] Flex-Algos 201 exclude red
14 [+] Flex-Algos 202 exclude blue
15 [+] Flex-Algos 203 exclude green
16 [+] Flex-Algos 204 include-any blue green
17 [+] Flex-Algos 205 include-any red green
18 [+] Flex-Algos 206 include-any red blue
19 [+] Flex-Algos 207 include-all yellow orange
21 +--------+ 10.12.0.0/24 +--------+
23 | RT1 |----------------| RT2 |
26 10.13.0.0/24 \\ / 10.23.0.0/24
29 orange +--------+ orange
41 from functools
import partial
43 # Save the Current Working Directory to find configuration files.
44 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
45 sys
.path
.append(os
.path
.join(CWD
, "../"))
47 # pylint: disable=C0413
48 # Import topogen and topotest helpers
49 from lib
import topotest
50 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
51 from lib
.topolog
import logger
54 pytestmark
= [pytest
.mark
.isisd
]
56 # Global multi-dimensional dictionary containing all expected outputs
63 def connect_routers(tgen
, left_idx
, right_idx
):
64 left
= "rt{}".format(left_idx
)
65 right
= "rt{}".format(right_idx
)
66 switch
= tgen
.add_switch("s-{}-{}".format(left
, right
))
67 switch
.add_link(tgen
.gears
[left
], nodeif
="eth-{}".format(right
))
68 switch
.add_link(tgen
.gears
[right
], nodeif
="eth-{}".format(left
))
69 l_addr
= "52:54:00:{}:{}:{}".format(left_idx
, right_idx
, left_idx
)
70 tgen
.gears
[left
].run("ip link set eth-{} down".format(right
))
71 tgen
.gears
[left
].run("ip link set eth-{} address {}".format(right
, l_addr
))
72 tgen
.gears
[left
].run("ip link set eth-{} up".format(right
))
73 r_addr
= "52:54:00:{}:{}:{}".format(left_idx
, right_idx
, right_idx
)
74 tgen
.gears
[right
].run("ip link set eth-{} down".format(left
))
75 tgen
.gears
[right
].run("ip link set eth-{} address {}".format(left
, r_addr
))
76 tgen
.gears
[right
].run("ip link set eth-{} up".format(left
))
78 tgen
.add_router("rt1")
79 tgen
.add_router("rt2")
80 tgen
.add_router("rt3")
81 connect_routers(tgen
, 1, 2)
82 connect_routers(tgen
, 2, 3)
83 connect_routers(tgen
, 3, 1)
86 # Populate multi-dimensional dictionary containing all expected outputs
90 "show_mpls_table.ref",
91 "show_isis_flex_algo.ref",
93 for rname
in ["rt1", "rt2", "rt3"]:
95 for step
in range(1, number_of_steps
+ 1):
96 outputs
[rname
][step
] = {}
97 for filename
in filenames
:
98 # Get snapshots relative to the expected network convergence
99 filename_pullpath
= "{}/{}/step{}/{}".format(CWD
, rname
, step
, filename
)
100 outputs
[rname
][step
][filename
] = open(filename_pullpath
).read()
103 def setup_module(mod
):
104 "Sets up the pytest environment"
105 tgen
= Topogen(build_topo
, mod
.__name
__)
106 frrdir
= tgen
.config
.get(tgen
.CONFIG_SECTION
, "frrdir")
107 if not os
.path
.isfile(os
.path
.join(frrdir
, "pathd")):
108 pytest
.skip("pathd daemon wasn't built")
109 tgen
.start_topology()
110 router_list
= tgen
.routers()
112 # For all registered routers, load the zebra configuration file
113 for rname
, router
in router_list
.items():
114 router
.load_config( TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
)))
115 router
.load_config( TopoRouter
.RD_ISIS
, os
.path
.join(CWD
, "{}/isisd.conf".format(rname
)))
119 def teardown_module(mod
):
120 "Teardown the pytest environment"
125 def setup_testcase(msg
):
128 if tgen
.routers_have_failure():
129 pytest
.skip(tgen
.errors
)
133 def router_compare_json_output(rname
, command
, reference
):
134 "Compare router JSON output"
136 logger
.info('Comparing router "%s" "%s" output', rname
, command
)
139 expected
= json
.loads(reference
)
141 # Run test function until we get an result. Wait at most 60 seconds.
142 test_func
= partial(topotest
.router_json_cmp
, tgen
.gears
[rname
], command
, expected
)
143 _
, diff
= topotest
.run_and_expect(test_func
, None, count
=120, wait
=0.5)
144 assertmsg
= '"{}" JSON output mismatches the expected result'.format(rname
)
145 assert diff
is None, assertmsg
148 def router_compare_output(rname
, command
, reference
):
149 "Compare router output"
151 logger
.info('Comparing router "%s" "%s" output', rname
, command
)
155 # Run test function until we get an result. Wait at most 60 seconds.
156 test_func
= partial(topotest
.router_output_cmp
, tgen
.gears
[rname
], command
, reference
)
157 result
, diff
= topotest
.run_and_expect(test_func
, "", count
=120, wait
=0.5)
158 assertmsg
= '{} command "{}" output mismatches the expected result:\n{}'.format(rname
, command
, diff
)
159 assert result
, assertmsg
165 # Test initial network convergenece
167 # All flex-algo are defined and its fib entries are installed
169 def test_step1_mpls_lfib():
170 logger
.info("Test (step 1)")
172 if tgen
.routers_have_failure():
173 pytest
.skip(tgen
.errors
)
177 for rname
in ["rt1", "rt2", "rt3"]:
178 router_compare_output(
179 rname
, "show isis flex-algo",
180 outputs
[rname
][1]["show_isis_flex_algo.ref"])
181 router_compare_json_output(
182 rname
, "show mpls table json",
183 outputs
[rname
][1]["show_mpls_table.ref"])
190 # - Disable flex-algo-203 definition advertisement on rt1
192 # Expected change(s):
196 # No change occurs because it refers to the FAD set in rt2.
198 def test_step2_mpls_lfib():
199 logger
.info("Test (step 2)")
201 if tgen
.routers_have_failure():
202 pytest
.skip(tgen
.errors
)
204 tgen
.gears
["rt1"].vtysh_cmd(
209 no advertise-definition
214 for rname
in ["rt1", "rt2", "rt3"]:
215 router_compare_output(
216 rname
, "show isis flex-algo",
217 outputs
[rname
][2]["show_isis_flex_algo.ref"])
218 router_compare_json_output(
219 rname
, "show mpls table json",
220 outputs
[rname
][2]["show_mpls_table.ref"])
227 # - Disable flex-algo-203 definition advertisement on rt2
229 # Expected change(s):
230 # - rt1,rt2,rt3 should uninstall all Prefix-SIDs of flex-algo-203
233 # When all FADs are disappeared, all their prefix sid routes are withdrawn.
235 def test_step3_mpls_lfib():
236 logger
.info("Test (step 3)")
238 if tgen
.routers_have_failure():
239 pytest
.skip(tgen
.errors
)
241 tgen
.gears
["rt2"].vtysh_cmd(
246 no advertise-definition
251 for rname
in ["rt1", "rt2", "rt3"]:
252 router_compare_output(
253 rname
, "show isis flex-algo",
254 outputs
[rname
][3]["show_isis_flex_algo.ref"])
255 router_compare_json_output(
256 rname
, "show mpls table json",
257 outputs
[rname
][3]["show_mpls_table.ref"])
264 # - Enable flex-algo-203 definition advertisement on rt2
266 # Expected change(s):
267 # - rt1,rt2,rt3 should install all Prefix-SIDs of flex-algo-203
270 # Since the FAD is restored, the reachability to the Prefix-SID is restored.
272 def test_step4_mpls_lfib():
273 logger
.info("Test (step 4)")
275 if tgen
.routers_have_failure():
276 pytest
.skip(tgen
.errors
)
278 tgen
.gears
["rt2"].vtysh_cmd(
288 for rname
in ["rt1", "rt2", "rt3"]:
289 router_compare_output(
290 rname
, "show isis flex-algo",
291 outputs
[rname
][4]["show_isis_flex_algo.ref"])
292 router_compare_json_output(
293 rname
, "show mpls table json",
294 outputs
[rname
][4]["show_mpls_table.ref"])
301 # - Enable flex-algo-203 definition advertisement on rt1
303 # Expected change(s):
307 # This does not affect the FIB, since there is already a FAD for rt2.
308 # However, the FAD owner will be changed from rt2 to rt1.
310 def test_step5_mpls_lfib():
311 logger
.info("Test (step 5)")
313 if tgen
.routers_have_failure():
314 pytest
.skip(tgen
.errors
)
316 tgen
.gears
["rt1"].vtysh_cmd(
326 for rname
in ["rt1", "rt2", "rt3"]:
327 router_compare_output(
328 rname
, "show isis flex-algo",
329 outputs
[rname
][5]["show_isis_flex_algo.ref"])
330 router_compare_json_output(
331 rname
, "show mpls table json",
332 outputs
[rname
][5]["show_mpls_table.ref"])
339 # - Disable flex-algo-203 SR-MPLS dataplane on rt1
340 # - Disable flex-algo-203 SR-MPLS dataplane on rt2
341 # - Disable flex-algo-203 SR-MPLS dataplane on rt3
343 # Expected change(s):
344 # - rt1,rt2,rt3 should uninstall all Prefix-SIDs of flex-algo-203
347 # Clear the Flex-Algo 203 whole settings on each routers. All routes related
348 # to it will be withdrawn.
350 def test_step6_mpls_lfib():
351 logger
.info("Test (step 6)")
353 if tgen
.routers_have_failure():
354 pytest
.skip(tgen
.errors
)
356 for rname
in ["rt1", "rt2", "rt3"]:
357 tgen
.gears
[rname
].vtysh_cmd(
367 for rname
in ["rt1", "rt2", "rt3"]:
368 router_compare_output(
369 rname
, "show isis flex-algo",
370 outputs
[rname
][6]["show_isis_flex_algo.ref"])
371 router_compare_json_output(
372 rname
, "show mpls table json",
373 outputs
[rname
][6]["show_mpls_table.ref"])
380 # - Disable flex-algo-203 all configuration on rt1
381 # - Disable flex-algo-203 all configuration on rt2
382 # - Disable flex-algo-203 all configuration on rt3
384 # Expected change(s):
385 # - rt1,rt2,rt3 should uninstall all Prefix-SIDs of flex-algo-203
388 # Clear the Flex-Algo 203 whole settings on each routers. All routes related
389 # to it will be withdrawn.
391 def test_step7_mpls_lfib():
392 logger
.info("Test (step 7)")
394 if tgen
.routers_have_failure():
395 pytest
.skip(tgen
.errors
)
397 for rname
in ["rt1", "rt2", "rt3"]:
398 tgen
.gears
[rname
].vtysh_cmd(
407 for rname
in ["rt1", "rt2", "rt3"]:
408 router_compare_output(
409 rname
, "show isis flex-algo",
410 outputs
[rname
][7]["show_isis_flex_algo.ref"])
411 router_compare_json_output(
412 rname
, "show mpls table json",
413 outputs
[rname
][7]["show_mpls_table.ref"])
419 # - Enable flex-algo-203 all configuration on rt1
420 # - Enable flex-algo-203 all configuration on rt2
421 # - Enable flex-algo-203 all configuration on rt3
423 # Expected change(s):
424 # - rt1,rt2,rt3 should install all Prefix-SIDs of flex-algo-203
427 # All configurations were backed.
429 def test_step8_mpls_lfib():
430 logger
.info("Test (step 8)")
432 if tgen
.routers_have_failure():
433 pytest
.skip(tgen
.errors
)
435 tgen
.gears
["rt1"].vtysh_cmd(
441 affinity exclude-any green
445 tgen
.gears
["rt2"].vtysh_cmd(
451 affinity exclude-any green
455 tgen
.gears
["rt3"].vtysh_cmd(
465 for rname
in ["rt1", "rt2", "rt3"]:
466 router_compare_output(
467 rname
, "show isis flex-algo",
468 outputs
[rname
][8]["show_isis_flex_algo.ref"])
469 router_compare_json_output(
470 rname
, "show mpls table json",
471 outputs
[rname
][8]["show_mpls_table.ref"])
478 # - Disable algorithm prefix-sid of algo-203 on rt1
480 # Expected change(s):
481 # - rt1 should uninstall all Prefix-SIDs of flex-algo-203
482 # - rt2 should uninstall Prefix-SIDs of rt1's flex-algo-203
483 # - rt3 should uninstall Prefix-SIDs of rt1's flex-algo-203
485 def test_step9_mpls_lfib():
486 logger
.info("Test (step 9)")
488 if tgen
.routers_have_failure():
489 pytest
.skip(tgen
.errors
)
491 tgen
.gears
["rt1"].vtysh_cmd(
495 no segment-routing prefix 1.1.1.1/32 algorithm 203 index 301
496 no segment-routing prefix 2001:db8:1000::1/128 algorithm 203 index 1301
501 for rname
in ["rt1", "rt2", "rt3"]:
502 router_compare_output(
503 rname
, "show isis flex-algo",
504 outputs
[rname
][9]["show_isis_flex_algo.ref"])
505 router_compare_json_output(
506 rname
, "show mpls table json",
507 outputs
[rname
][9]["show_mpls_table.ref"])
514 # - Enable algorithm prefix-sid of algo-203 on rt1
516 # Expected change(s):
517 # - rt1 should install all Prefix-SIDs of flex-algo-203
518 # - rt2 should install Prefix-SIDs of rt1's flex-algo-203
519 # - rt3 should install Prefix-SIDs of rt1's flex-algo-203
521 def test_step10_mpls_lfib():
522 logger
.info("Test (step 10)")
524 if tgen
.routers_have_failure():
525 pytest
.skip(tgen
.errors
)
527 tgen
.gears
["rt1"].vtysh_cmd(
531 segment-routing prefix 1.1.1.1/32 algorithm 203 index 301
532 segment-routing prefix 2001:db8:1000::1/128 algorithm 203 index 1301
537 for rname
in ["rt1", "rt2", "rt3"]:
538 router_compare_output(
539 rname
, "show isis flex-algo",
540 outputs
[rname
][10]["show_isis_flex_algo.ref"])
541 router_compare_json_output(
542 rname
, "show mpls table json",
543 outputs
[rname
][10]["show_mpls_table.ref"])
550 # - Update algorithm prefix-sid of algo-203 on rt1 from 301 to 311
552 # Expected change(s):
553 # - rt2 should update Prefix-SIDs of rt1's flex-algo-203 from 301 to 311
554 # - rt3 should update Prefix-SIDs of rt1's flex-algo-203 from 301 to 311
556 def test_step11_mpls_lfib():
557 logger
.info("Test (step 11)")
559 if tgen
.routers_have_failure():
560 pytest
.skip(tgen
.errors
)
562 tgen
.gears
["rt1"].vtysh_cmd(
566 segment-routing prefix 1.1.1.1/32 algorithm 203 index 311
567 segment-routing prefix 2001:db8:1000::1/128 algorithm 203 index 1311
572 for rname
in ["rt1", "rt2", "rt3"]:
573 router_compare_output(
574 rname
, "show isis flex-algo",
575 outputs
[rname
][11]["show_isis_flex_algo.ref"])
576 router_compare_json_output(
577 rname
, "show mpls table json",
578 outputs
[rname
][11]["show_mpls_table.ref"])
581 if __name__
== "__main__":
582 args
= ["-s"] + sys
.argv
[1:]
583 sys
.exit(pytest
.main(args
))