]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/ospfv3_basic_functionality/test_ospfv3_asbr_summary_topo1.py
Merge pull request #9489 from opensourcerouting/pim-restruct-20210825
[mirror_frr.git] / tests / topotests / ospfv3_basic_functionality / test_ospfv3_asbr_summary_topo1.py
1 #!/usr/bin/python
2
3 #
4 # Copyright (c) 2021 by VMware, Inc. ("VMware")
5 # Used Copyright (c) 2018 by Network Device Education Foundation, Inc.
6 # ("NetDEF") in this file.
7 #
8 # Permission to use, copy, modify, and/or distribute this software
9 # for any purpose with or without fee is hereby granted, provided
10 # that the above copyright notice and this permission notice appear
11 # in all copies.
12 #
13 # THE SOFTWARE IS PROVIDED "AS IS" AND VMWARE DISCLAIMS ALL WARRANTIES
14 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL VMWARE BE LIABLE FOR
16 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
17 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
18 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
19 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20 # OF THIS SOFTWARE.
21 #
22
23
24 """OSPF Summarisation Functionality Automation."""
25 import os
26 import sys
27 import time
28 import pytest
29
30 # Save the Current Working Directory to find configuration files.
31 CWD = os.path.dirname(os.path.realpath(__file__))
32 sys.path.append(os.path.join(CWD, "../"))
33 sys.path.append(os.path.join(CWD, "../lib/"))
34
35 # pylint: disable=C0413
36 # Import topogen and topotest helpers
37 from lib.topogen import Topogen, get_topogen
38 import ipaddress
39 from time import sleep
40
41 # Import topoJson from lib, to create topology and initial configuration
42 from lib.common_config import (
43 start_topology,
44 write_test_header,
45 kill_router_daemons,
46 write_test_footer,
47 reset_config_on_routers,
48 stop_router,
49 start_router,
50 verify_rib,
51 create_static_routes,
52 step,
53 start_router_daemons,
54 create_route_maps,
55 shutdown_bringup_interface,
56 create_prefix_lists,
57 create_route_maps,
58 topo_daemons,
59 )
60 from lib.topolog import logger
61 from lib.topojson import build_config_from_json
62 from lib.ospf import (
63 verify_ospf6_neighbor,
64 clear_ospf,
65 verify_ospf6_rib,
66 create_router_ospf,
67 verify_ospf_summary,
68 )
69
70
71 # Global variables
72 topo = None
73
74 NETWORK = {
75 "ipv4": [
76 "11.0.20.1/32",
77 "11.0.20.2/32",
78 "11.0.20.3/32",
79 "11.0.20.4/32",
80 "11.0.20.5/32",
81 ],
82 "ipv6": [
83 "2011:0:20::1/128",
84 "2011:0:20::2/128",
85 "2011:0:20::3/128",
86 "2011:0:20::4/128",
87 "2011:0:20::5/128",
88 ],
89 }
90 NETWORK_11 = {
91 "ipv4": ["11.0.20.6/32", "11.0.20.7/32"],
92 "ipv6": ["2011:0:20::6/128", "2011:0:20::7/128"],
93 }
94
95 NETWORK2 = {
96 "ipv4": [
97 "12.0.20.1/32",
98 "12.0.20.2/32",
99 "12.0.20.3/32",
100 "12.0.20.4/32",
101 "12.0.20.5/32",
102 ],
103 "ipv6": [
104 "2012:0:20::1/128",
105 "2012:0:20::2/128",
106 "2012:0:20::3/128",
107 "2012:0:20::4/128",
108 "2012:0:20::5/128",
109 ],
110 }
111 SUMMARY = {
112 "ipv4": ["11.0.0.0/8", "12.0.0.0/8", "11.0.0.0/24"],
113 "ipv6": ["2011::/32", "2012::/32", "2011::/64", "2011::/24"],
114 }
115 """
116 TOPOOLOGY =
117 Please view in a fixed-width font such as Courier.
118 +---+ A0 +---+
119 +R1 +------------+R2 |
120 +-+-+- +--++
121 | -- -- |
122 | -- A0 -- |
123 A0| ---- |
124 | ---- | A0
125 | -- -- |
126 | -- -- |
127 +-+-+- +-+-+
128 +R0 +-------------+R3 |
129 +---+ A0 +---+
130
131 TESTCASES =
132 1. OSPF summarisation functionality.
133 2. OSPF summarisation with advertise and no advertise option
134 3. OSPF summarisation with route map modification of metric type.
135 4. OSPF CLI Show verify ospf ASBR summary config and show commands behaviours.
136 5. OSPF summarisation Chaos.
137 """
138
139
140 def setup_module(mod):
141 """
142 Sets up the pytest environment
143
144 * `mod`: module name
145 """
146 testsuite_run_time = time.asctime(time.localtime(time.time()))
147 logger.info("Testsuite start time: {}".format(testsuite_run_time))
148 logger.info("=" * 40)
149
150 logger.info("Running setup_module to create topology")
151
152 # This function initiates the topology build with Topogen...
153 json_file = "{}/ospfv3_asbr_summary_topo1.json".format(CWD)
154 tgen = Topogen(json_file, mod.__name__)
155 global topo
156 topo = tgen.json_topo
157 # ... and here it calls Mininet initialization functions.
158
159 # get list of daemons needs to be started for this suite.
160 daemons = topo_daemons(tgen, topo)
161
162 # Starting topology, create tmp files which are loaded to routers
163 # to start deamons and then start routers
164 start_topology(tgen, daemons)
165
166 # Creating configuration from JSON
167 build_config_from_json(tgen, topo)
168
169 # Don't run this test if we have any failure.
170 if tgen.routers_have_failure():
171 pytest.skip(tgen.errors)
172 # Api call verify whether OSPF is converged
173 ospf_covergence = verify_ospf6_neighbor(tgen, topo)
174 assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
175 ospf_covergence
176 )
177
178 logger.info("Running setup_module() done")
179
180
181 def teardown_module(mod):
182 """
183 Teardown the pytest environment.
184
185 * `mod`: module name
186 """
187
188 logger.info("Running teardown_module to delete topology")
189
190 tgen = get_topogen()
191
192 # Stop toplogy and Remove tmp files
193 tgen.stop_topology()
194
195 logger.info(
196 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
197 )
198 logger.info("=" * 40)
199
200
201 def red_static(dut, config=True):
202 """
203 Local 'def' for Redstribute static routes inside ospf.
204
205 Parameters
206 ----------
207 * `dut` : DUT on which configs have to be made.
208 * `config` : True or False, True by default for configure, set False for
209 unconfiguration.
210 """
211 global topo
212 tgen = get_topogen()
213 if config:
214 ospf_red = {dut: {"ospf6": {"redistribute": [{"redist_type": "static"}]}}}
215 else:
216 ospf_red = {
217 dut: {
218 "ospf6": {"redistribute": [{"redist_type": "static", "delete": True}]}
219 }
220 }
221 result = create_router_ospf(tgen, topo, ospf_red)
222 assert result is True, "Testcase : Failed \n Error: {}".format(result)
223
224
225 def red_connected(dut, config=True):
226 """
227 Local 'def' for Redstribute connected routes inside ospf
228
229 Parameters
230 ----------
231 * `dut` : DUT on which configs have to be made.
232 * `config` : True or False, True by default for configure, set False for
233 unconfiguration.
234 """
235 global topo
236 tgen = get_topogen()
237 if config:
238 ospf_red = {dut: {"ospf6": {"redistribute": [{"redist_type": "connected"}]}}}
239 else:
240 ospf_red = {
241 dut: {
242 "ospf6": {
243 "redistribute": [{"redist_type": "connected", "delete": True}]
244 }
245 }
246 }
247 result = create_router_ospf(tgen, topo, ospf_red)
248 assert result is True, "Testcase: Failed \n Error: {}".format(result)
249
250
251 # ##################################
252 # Test cases start here.
253 # ##################################
254
255
256 def test_ospfv3_type5_summary_tc42_p0(request):
257 """OSPF summarisation functionality."""
258 tc_name = request.node.name
259 write_test_header(tc_name)
260 tgen = get_topogen()
261
262 # Don't run this test if we have any failure.
263 if tgen.routers_have_failure():
264 pytest.skip(tgen.errors)
265
266 global topo
267 step("Bring up the base config as per the topology")
268 reset_config_on_routers(tgen)
269
270 protocol = "ospf"
271
272 step(
273 "Configure 5 static routes from the same network on R0"
274 "5 static routes from different networks and redistribute in R0"
275 )
276 input_dict_static_rtes = {
277 "r0": {
278 "static_routes": [
279 {"network": NETWORK["ipv6"], "next_hop": "blackhole"},
280 {"network": NETWORK2["ipv6"], "next_hop": "blackhole"},
281 ]
282 }
283 }
284 result = create_static_routes(tgen, input_dict_static_rtes)
285 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
286
287 dut = "r0"
288 red_static(dut)
289
290 step("Verify that routes are learnt on R1.")
291 dut = "r1"
292
293 result = verify_ospf6_rib(tgen, dut, input_dict_static_rtes)
294 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
295 result = verify_rib(tgen, "ipv6", dut, input_dict_static_rtes, protocol=protocol)
296 assert (
297 result is True
298 ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
299
300 step(
301 "Configure External Route summary in R0 to summarise 5"
302 " routes to one route. with aggregate timer as 6 sec"
303 )
304
305 ospf_summ_r1 = {
306 "r0": {
307 "ospf6": {
308 "summary-address": [
309 {"prefix": SUMMARY["ipv6"][0].split("/")[0], "mask": "32"}
310 ],
311 "aggr_timer": 6,
312 }
313 }
314 }
315 result = create_router_ospf(tgen, topo, ospf_summ_r1)
316 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
317
318 step(
319 "Verify that external routes are summarised to configured summary "
320 "address on R0 after 5 secs of delay timer expiry and only one "
321 "route is sent to R1."
322 )
323 input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv6"][0]}]}}
324 dut = "r1"
325
326 result = verify_ospf6_rib(tgen, dut, input_dict_summary)
327 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
328
329 result = verify_rib(tgen, "ipv6", dut, input_dict_summary, protocol=protocol)
330 assert (
331 result is True
332 ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
333
334 step("Verify that show ip ospf summary should show the summaries.")
335 input_dict = {
336 SUMMARY["ipv6"][0]: {
337 "Summary address": SUMMARY["ipv6"][0],
338 "Metric-type": "E2",
339 "Metric": 20,
340 "Tag": 0,
341 "External route count": 5,
342 }
343 }
344 dut = "r0"
345 result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
346 assert (
347 result is True
348 ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
349
350 step("Verify that originally advertised routes are withdraw from there" " peer.")
351 input_dict = {
352 "r0": {"static_routes": [{"network": NETWORK["ipv6"], "next_hop": "blackhole"}]}
353 }
354 dut = "r1"
355 result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
356 assert (
357 result is not True
358 ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
359 tc_name, result
360 )
361
362 result = verify_rib(
363 tgen, "ipv6", dut, input_dict, protocol=protocol, expected=False
364 )
365 assert (
366 result is not True
367 ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
368
369 step("Delete the configured summary")
370 ospf_summ_r1 = {
371 "r0": {
372 "ospf6": {
373 "summary-address": [
374 {
375 "prefix": SUMMARY["ipv6"][0].split("/")[0],
376 "mask": "32",
377 "del_aggr_timer": True,
378 "delete": True,
379 }
380 ]
381 }
382 }
383 }
384 result = create_router_ospf(tgen, topo, ospf_summ_r1)
385 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
386
387 step("Verify that summary lsa is withdrawn from R1 and deleted from R0.")
388 dut = "r1"
389 result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
390 assert (
391 result is not True
392 ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
393 tc_name, result
394 )
395
396 result = verify_rib(
397 tgen, "ipv6", dut, input_dict_summary, protocol=protocol, expected=False
398 )
399 assert (
400 result is not True
401 ), "Testcase {} : Failed" "Error: Summary Route still present in RIB".format(
402 tc_name
403 )
404
405 step("show ip ospf summary should not have any summary address.")
406 input_dict = {
407 SUMMARY["ipv6"][0]: {
408 "Summary address": SUMMARY["ipv6"][0],
409 "Metric-type": "E2",
410 "Metric": 20,
411 "Tag": 0,
412 "External route count": 5,
413 }
414 }
415 dut = "r0"
416 result = verify_ospf_summary(
417 tgen, topo, dut, input_dict, ospf="ospf6", expected=False
418 )
419 assert (
420 result is not True
421 ), "Testcase {} : Failed" "Error: Summary still present in DB".format(tc_name)
422
423 dut = "r1"
424 step("All 5 routes are advertised after deletion of configured summary.")
425
426 result = verify_ospf6_rib(tgen, dut, input_dict_static_rtes)
427 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
428
429 result = verify_rib(tgen, "ipv6", dut, input_dict_static_rtes, protocol=protocol)
430 assert (
431 result is True
432 ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
433
434 step("configure the summary again and delete static routes .")
435 ospf_summ_r1 = {
436 "r0": {
437 "ospf6": {
438 "summary-address": [
439 {"prefix": SUMMARY["ipv6"][0].split("/")[0], "mask": "32"}
440 ]
441 }
442 }
443 }
444 result = create_router_ospf(tgen, topo, ospf_summ_r1)
445 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
446
447 input_dict = {
448 SUMMARY["ipv6"][0]: {
449 "Summary address": SUMMARY["ipv6"][0],
450 "Metric-type": "E2",
451 "Metric": 20,
452 "Tag": 0,
453 "External route count": 5,
454 }
455 }
456 dut = "r0"
457 result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
458 assert (
459 result is True
460 ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
461
462 input_dict = {
463 "r0": {
464 "static_routes": [
465 {"network": NETWORK["ipv6"], "next_hop": "blackhole", "delete": True}
466 ]
467 }
468 }
469 result = create_static_routes(tgen, input_dict)
470 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
471
472 input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv6"][0]}]}}
473 step("Verify that summary route is withdrawn from R1.")
474
475 dut = "r1"
476 result = verify_ospf6_rib(tgen, dut, input_dict_summary, expected=False)
477 assert (
478 result is not True
479 ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
480 tc_name, result
481 )
482
483 result = verify_rib(
484 tgen, "ipv6", dut, input_dict_summary, protocol=protocol, expected=False
485 )
486 assert (
487 result is not True
488 ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
489
490 step("Add back static routes.")
491 input_dict_static_rtes = {
492 "r0": {"static_routes": [{"network": NETWORK["ipv6"], "next_hop": "blackhole"}]}
493 }
494 result = create_static_routes(tgen, input_dict_static_rtes)
495 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
496
497 step(
498 "Verify that external routes are summarised to configured summary"
499 " address on R0 and only one route is sent to R1."
500 )
501 dut = "r1"
502
503 result = verify_ospf6_rib(tgen, dut, input_dict_static_rtes, expected=False)
504 assert (
505 result is not True
506 ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
507 tc_name, result
508 )
509
510 result = verify_rib(
511 tgen, "ipv6", dut, input_dict_static_rtes, protocol=protocol, expected=False
512 )
513 assert (
514 result is not True
515 ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
516
517 input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv6"][0]}]}}
518 dut = "r1"
519
520 result = verify_ospf6_rib(tgen, dut, input_dict_summary)
521 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
522
523 result = verify_rib(tgen, "ipv6", dut, input_dict_summary, protocol=protocol)
524 assert (
525 result is True
526 ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
527
528 step("Verify that show ip ospf summary should show configure summaries.")
529
530 input_dict = {
531 SUMMARY["ipv6"][0]: {
532 "Summary address": SUMMARY["ipv6"][0],
533 "Metric-type": "E2",
534 "Metric": 20,
535 "Tag": 0,
536 "External route count": 5,
537 }
538 }
539 dut = "r0"
540 result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
541 assert (
542 result is True
543 ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
544
545 step("Configure new static route which is matching configured summary.")
546 input_dict_static_rtes = {
547 "r0": {
548 "static_routes": [{"network": NETWORK_11["ipv6"], "next_hop": "blackhole"}]
549 }
550 }
551 result = create_static_routes(tgen, input_dict_static_rtes)
552 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
553
554 # step("verify that summary lsa is not refreshed.")
555 # show ip ospf database command is not working, waiting for DEV fix.
556
557 step("Delete one of the static route.")
558 input_dict_static_rtes = {
559 "r0": {
560 "static_routes": [
561 {"network": NETWORK_11["ipv6"], "next_hop": "blackhole", "delete": True}
562 ]
563 }
564 }
565 result = create_static_routes(tgen, input_dict_static_rtes)
566 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
567
568 # step("verify that summary lsa is not refreshed.")
569 # show ip ospf database command is not working, waiting for DEV fix.
570
571 # step("Verify that deleted static route is removed from ospf LSDB.")
572 # show ip ospf database command is not working, waiting for DEV fix.
573
574 step(
575 "Configure redistribute connected and configure ospf external"
576 " summary address to summarise the connected routes."
577 )
578
579 dut = "r0"
580 red_connected(dut)
581 clear_ospf(tgen, dut, ospf="ospf6")
582
583 ip = topo["routers"]["r0"]["links"]["r3"]["ipv6"]
584
585 ip_net = str(ipaddress.ip_interface(u"{}".format(ip)).network)
586 ospf_summ_r1 = {
587 "r0": {
588 "ospf6": {
589 "summary-address": [{"prefix": ip_net.split("/")[0], "mask": "8"}]
590 }
591 }
592 }
593 result = create_router_ospf(tgen, topo, ospf_summ_r1)
594 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
595
596 step(
597 "Verify that external routes are summarised to configured "
598 "summary address on R0 and only one route is sent to R1."
599 )
600
601 input_dict_summary = {"r0": {"static_routes": [{"network": "fd00::/64"}]}}
602 dut = "r1"
603 result = verify_ospf6_rib(tgen, dut, input_dict_summary)
604 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
605
606 result = verify_rib(tgen, "ipv6", dut, input_dict_summary, protocol=protocol)
607 assert (
608 result is True
609 ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
610
611 step("Shut one of the interface")
612 intf = topo["routers"]["r0"]["links"]["r3-link0"]["interface"]
613 shutdown_bringup_interface(tgen, dut, intf, False)
614
615 # step("verify that summary lsa is not refreshed.")
616 # show ip ospf database command is not working, waiting for DEV fix.
617
618 # step("Verify that deleted connected route is removed from ospf LSDB.")
619 # show ip ospf database command is not working, waiting for DEV fix.
620
621 step("Un do shut the interface")
622 shutdown_bringup_interface(tgen, dut, intf, True)
623
624 # step("verify that summary lsa is not refreshed.")
625 # show ip ospf database command is not working, waiting for DEV fix.
626
627 # step("Verify that deleted connected route is removed from ospf LSDB.")
628 # show ip ospf database command is not working, waiting for DEV fix.
629
630 step("Delete OSPF process.")
631 ospf_del = {"r0": {"ospf6": {"delete": True}}}
632 result = create_router_ospf(tgen, topo, ospf_del)
633 assert result is True, "Testcase : Failed \n Error: {}".format(result)
634
635 step("Reconfigure ospf process with summary")
636 reset_config_on_routers(tgen)
637
638 input_dict_static_rtes = {
639 "r0": {
640 "static_routes": [
641 {"network": NETWORK["ipv6"], "next_hop": "blackhole"},
642 {"network": NETWORK2["ipv6"], "next_hop": "blackhole"},
643 ]
644 }
645 }
646 result = create_static_routes(tgen, input_dict_static_rtes)
647 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
648
649 dut = "r0"
650 red_static(dut)
651 red_connected(dut)
652 ospf_summ_r1 = {
653 "r0": {
654 "ospf6": {
655 "summary-address": [
656 {"prefix": SUMMARY["ipv6"][0].split("/")[0], "mask": "32"}
657 ]
658 }
659 }
660 }
661 result = create_router_ospf(tgen, topo, ospf_summ_r1)
662 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
663 step(
664 "Verify that external routes are summarised to configured summary "
665 "address on R0 and only one route is sent to R1."
666 )
667
668 input_dict = {
669 SUMMARY["ipv6"][0]: {
670 "Summary address": SUMMARY["ipv6"][0],
671 "Metric-type": "E2",
672 "Metric": 20,
673 "Tag": 0,
674 "External route count": 5,
675 }
676 }
677 dut = "r0"
678 result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
679 assert (
680 result is True
681 ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
682
683 input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv6"][0]}]}}
684
685 dut = "r1"
686 result = verify_ospf6_rib(tgen, dut, input_dict_summary)
687 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
688
689 result = verify_rib(tgen, "ipv6", dut, input_dict_summary, protocol=protocol)
690 assert (
691 result is True
692 ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
693
694 ospf_summ_r1 = {
695 "r0": {
696 "ospf6": {
697 "summary-address": [
698 {"prefix": SUMMARY["ipv6"][0].split("/")[0], "mask": "32"}
699 ]
700 }
701 }
702 }
703 result = create_router_ospf(tgen, topo, ospf_summ_r1)
704 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
705
706 # step("verify that summary lsa is not refreshed.")
707 # show ip ospf database command is not working, waiting for DEV fix.
708
709 step("Delete the redistribute command in ospf.")
710 dut = "r0"
711 red_connected(dut, config=False)
712 red_static(dut, config=False)
713
714 step("Verify that summary route is withdrawn from the peer.")
715
716 dut = "r1"
717 result = verify_ospf6_rib(tgen, dut, input_dict_summary, expected=False)
718 assert (
719 result is not True
720 ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
721 tc_name, result
722 )
723
724 result = verify_rib(
725 tgen, "ipv6", dut, input_dict_summary, protocol=protocol, expected=False
726 )
727 assert (
728 result is not True
729 ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
730
731 ospf_summ_r1 = {
732 "r0": {
733 "ospf6": {
734 "summary-address": [
735 {
736 "prefix": SUMMARY["ipv6"][0].split("/")[0],
737 "mask": "32",
738 "metric": "1234",
739 }
740 ]
741 }
742 }
743 }
744 result = create_router_ospf(tgen, topo, ospf_summ_r1)
745 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
746
747 write_test_footer(tc_name)
748
749
750 def test_ospfv3_type5_summary_tc46_p0(request):
751 """OSPF summarisation with advertise and no advertise option"""
752 tc_name = request.node.name
753 write_test_header(tc_name)
754 tgen = get_topogen()
755
756 # Don't run this test if we have any failure.
757 if tgen.routers_have_failure():
758 pytest.skip(tgen.errors)
759
760 global topo
761 step("Bring up the base config as per the topology")
762 step("Configure OSPF on all the routers of the topology.")
763 reset_config_on_routers(tgen)
764
765 protocol = "ospf"
766
767 step(
768 "Configure 5 static routes from the same network on R0"
769 "5 static routes from different networks and redistribute in R0"
770 )
771 input_dict_static_rtes = {
772 "r0": {
773 "static_routes": [
774 {"network": NETWORK["ipv6"], "next_hop": "blackhole"},
775 {"network": NETWORK2["ipv6"], "next_hop": "blackhole"},
776 ]
777 }
778 }
779 result = create_static_routes(tgen, input_dict_static_rtes)
780 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
781
782 dut = "r0"
783 red_static(dut)
784
785 step("Verify that routes are learnt on R1.")
786 dut = "r1"
787
788 result = verify_ospf6_rib(tgen, dut, input_dict_static_rtes)
789 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
790 result = verify_rib(tgen, "ipv6", dut, input_dict_static_rtes, protocol=protocol)
791 assert (
792 result is True
793 ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
794
795 step(
796 "Configure External Route summary in R0 to summarise 5"
797 " routes to one route with no advertise option."
798 )
799 ospf_summ_r1 = {
800 "r0": {
801 "ospf6": {
802 "summary-address": [
803 {
804 "prefix": SUMMARY["ipv6"][0].split("/")[0],
805 "mask": "32",
806 "advertise": False,
807 }
808 ]
809 }
810 }
811 }
812 result = create_router_ospf(tgen, topo, ospf_summ_r1)
813 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
814
815 step(
816 "Verify that external routes are summarised to configured summary"
817 " address on R0 and summary route is not advertised to neighbor as"
818 " no advertise is configured.."
819 )
820
821 input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv6"][0]}]}}
822 dut = "r1"
823
824 result = verify_ospf6_rib(tgen, dut, input_dict_summary, expected=False)
825 assert (
826 result is not True
827 ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
828 tc_name, result
829 )
830
831 result = verify_rib(
832 tgen, "ipv6", dut, input_dict_summary, protocol=protocol, expected=False
833 )
834 assert (
835 result is not True
836 ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
837
838 step("Verify that show ip ospf summary should show the " "configured summaries.")
839 input_dict = {
840 SUMMARY["ipv6"][0]: {
841 "Summary address": SUMMARY["ipv6"][0],
842 "External route count": 5,
843 }
844 }
845 dut = "r0"
846 result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
847 assert (
848 result is True
849 ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
850
851 step("Delete the configured summary")
852 ospf_summ_r1 = {
853 "r0": {
854 "ospf6": {
855 "summary-address": [
856 {
857 "prefix": SUMMARY["ipv6"][0].split("/")[0],
858 "mask": "32",
859 "delete": True,
860 }
861 ]
862 }
863 }
864 }
865 result = create_router_ospf(tgen, topo, ospf_summ_r1)
866 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
867
868 step("Summary has 5 sec delay timer, sleep 5 secs...")
869 sleep(5)
870
871 step("Verify that summary lsa is withdrawn from R1 and deleted from R0.")
872 dut = "r1"
873 result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
874 assert (
875 result is not True
876 ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
877 tc_name, result
878 )
879
880 result = verify_rib(
881 tgen, "ipv6", dut, input_dict_summary, protocol=protocol, expected=False
882 )
883 assert (
884 result is not True
885 ), "Testcase {} : Failed" "Error: Summary Route still present in RIB".format(
886 tc_name
887 )
888
889 step("show ip ospf summary should not have any summary address.")
890 input_dict = {
891 SUMMARY["ipv6"][0]: {
892 "Summary address": SUMMARY["ipv6"][0],
893 "Metric-type": "E2",
894 "Metric": 20,
895 "Tag": 1234,
896 "External route count": 5,
897 }
898 }
899 dut = "r0"
900 result = verify_ospf_summary(
901 tgen, topo, dut, input_dict, ospf="ospf6", expected=False
902 )
903 assert (
904 result is not True
905 ), "Testcase {} : Failed" "Error: Summary still present in DB".format(tc_name)
906
907 step("Reconfigure summary with no advertise.")
908 ospf_summ_r1 = {
909 "r0": {
910 "ospf6": {
911 "summary-address": [
912 {
913 "prefix": SUMMARY["ipv6"][0].split("/")[0],
914 "mask": "32",
915 "advertise": False,
916 }
917 ]
918 }
919 }
920 }
921 result = create_router_ospf(tgen, topo, ospf_summ_r1)
922 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
923
924 step(
925 "Verify that external routes are summarised to configured summary"
926 " address on R0 and summary route is not advertised to neighbor as"
927 " no advertise is configured.."
928 )
929
930 input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv6"][0]}]}}
931 dut = "r1"
932
933 result = verify_ospf6_rib(tgen, dut, input_dict_summary, expected=False)
934 assert (
935 result is not True
936 ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
937 tc_name, result
938 )
939
940 result = verify_rib(
941 tgen, "ipv6", dut, input_dict_summary, protocol=protocol, expected=False
942 )
943 assert (
944 result is not True
945 ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
946
947 step("Verify that show ip ospf summary should show the " "configured summaries.")
948 input_dict = {
949 SUMMARY["ipv6"][0]: {
950 "Summary address": SUMMARY["ipv6"][0],
951 "External route count": 5,
952 }
953 }
954 dut = "r0"
955 result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
956 assert (
957 result is True
958 ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
959
960 step(
961 "Change summary address from no advertise to advertise "
962 "(summary-address 10.0.0.0 255.255.0.0)"
963 )
964
965 ospf_summ_r1 = {
966 "r0": {
967 "ospf6": {
968 "summary-address": [
969 {
970 "prefix": SUMMARY["ipv6"][0].split("/")[0],
971 "mask": "32",
972 "advertise": False,
973 }
974 ]
975 }
976 }
977 }
978 result = create_router_ospf(tgen, topo, ospf_summ_r1)
979 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
980
981 ospf_summ_r1 = {
982 "r0": {
983 "ospf6": {
984 "summary-address": [
985 {"prefix": SUMMARY["ipv6"][0].split("/")[0], "mask": "32"}
986 ]
987 }
988 }
989 }
990 result = create_router_ospf(tgen, topo, ospf_summ_r1)
991 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
992
993 step(
994 "Verify that external routes are summarised to configured summary "
995 "address on R0 after 5 secs of delay timer expiry and only one "
996 "route is sent to R1."
997 )
998 input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv6"][0]}]}}
999 dut = "r1"
1000
1001 result = verify_ospf6_rib(tgen, dut, input_dict_summary)
1002 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1003
1004 result = verify_rib(tgen, "ipv6", dut, input_dict_summary, protocol=protocol)
1005 assert (
1006 result is True
1007 ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
1008
1009 step("Verify that show ip ospf summary should show the summaries.")
1010 input_dict = {
1011 SUMMARY["ipv6"][0]: {
1012 "Summary address": SUMMARY["ipv6"][0],
1013 "Metric-type": "E2",
1014 "Metric": 20,
1015 "Tag": 0,
1016 "External route count": 5,
1017 }
1018 }
1019 dut = "r0"
1020 result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
1021 assert (
1022 result is True
1023 ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
1024
1025 step("Verify that originally advertised routes are withdraw from there" " peer.")
1026 input_dict = {
1027 "r0": {"static_routes": [{"network": NETWORK["ipv6"], "next_hop": "blackhole"}]}
1028 }
1029 dut = "r1"
1030 result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
1031 assert (
1032 result is not True
1033 ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
1034 tc_name, result
1035 )
1036
1037 result = verify_rib(
1038 tgen, "ipv6", dut, input_dict, protocol=protocol, expected=False
1039 )
1040 assert (
1041 result is not True
1042 ), "Testcase {} : Failed" "Error: Routes is present in RIB".format(tc_name)
1043
1044 write_test_footer(tc_name)
1045
1046
1047 def test_ospfv3_type5_summary_tc48_p0(request):
1048 """OSPF summarisation with route map modification of metric type."""
1049 tc_name = request.node.name
1050 write_test_header(tc_name)
1051 tgen = get_topogen()
1052
1053 # Don't run this test if we have any failure.
1054 if tgen.routers_have_failure():
1055 pytest.skip(tgen.errors)
1056
1057 global topo
1058 step("Bring up the base config as per the topology")
1059 reset_config_on_routers(tgen)
1060
1061 protocol = "ospf"
1062
1063 step(
1064 "Configure 5 static routes from the same network on R0"
1065 "5 static routes from different networks and redistribute in R0"
1066 )
1067 input_dict_static_rtes = {
1068 "r0": {
1069 "static_routes": [
1070 {"network": NETWORK["ipv6"], "next_hop": "blackhole"},
1071 {"network": NETWORK2["ipv6"], "next_hop": "blackhole"},
1072 ]
1073 }
1074 }
1075 result = create_static_routes(tgen, input_dict_static_rtes)
1076 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1077
1078 dut = "r0"
1079 red_static(dut)
1080
1081 step("Verify that routes are learnt on R1.")
1082 dut = "r1"
1083
1084 result = verify_ospf6_rib(tgen, dut, input_dict_static_rtes)
1085 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1086 result = verify_rib(tgen, "ipv6", dut, input_dict_static_rtes, protocol=protocol)
1087 assert (
1088 result is True
1089 ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
1090
1091 step(
1092 "Configure External Route summary in R0 to summarise 5" " routes to one route."
1093 )
1094
1095 ospf_summ_r1 = {
1096 "r0": {
1097 "ospf6": {
1098 "summary-address": [
1099 {"prefix": SUMMARY["ipv6"][0].split("/")[0], "mask": "32"}
1100 ]
1101 }
1102 }
1103 }
1104 result = create_router_ospf(tgen, topo, ospf_summ_r1)
1105 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1106
1107 step(
1108 "Verify that external routes are summarised to configured summary "
1109 "address on R0 after 5 secs of delay timer expiry and only one "
1110 "route is sent to R1."
1111 )
1112 input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv6"][0]}]}}
1113 dut = "r1"
1114
1115 result = verify_ospf6_rib(tgen, dut, input_dict_summary)
1116 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1117
1118 result = verify_rib(tgen, "ipv6", dut, input_dict_summary, protocol=protocol)
1119 assert (
1120 result is True
1121 ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
1122
1123 step("Verify that show ip ospf summary should show the summaries.")
1124 input_dict = {
1125 SUMMARY["ipv6"][0]: {
1126 "Summary address": SUMMARY["ipv6"][0],
1127 "Metric-type": "E2",
1128 "Metric": 20,
1129 "Tag": 0,
1130 "External route count": 5,
1131 }
1132 }
1133 dut = "r0"
1134 result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
1135 assert (
1136 result is True
1137 ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
1138
1139 step("Verify that originally advertised routes are withdraw from there" " peer.")
1140 input_dict = {
1141 "r0": {"static_routes": [{"network": NETWORK["ipv6"], "next_hop": "blackhole"}]}
1142 }
1143 dut = "r1"
1144 result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
1145 assert (
1146 result is not True
1147 ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
1148 tc_name, result
1149 )
1150
1151 result = verify_rib(
1152 tgen, "ipv6", dut, input_dict, protocol=protocol, expected=False
1153 )
1154 assert (
1155 result is not True
1156 ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
1157
1158 step(
1159 "Configure route map and & rule to permit configured summary address,"
1160 " redistribute static & connected routes with the route map."
1161 )
1162 step("Configure prefixlist to permit the static routes, add to route map.")
1163 # Create ip prefix list
1164 pfx_list = {
1165 "r0": {
1166 "prefix_lists": {
1167 "ipv6": {
1168 "pf_list_1_ipv6": [
1169 {"seqid": 10, "network": "any", "action": "permit"}
1170 ]
1171 }
1172 }
1173 }
1174 }
1175 result = create_prefix_lists(tgen, pfx_list)
1176 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1177
1178 routemaps = {
1179 "r0": {
1180 "route_maps": {
1181 "rmap_ipv6": [
1182 {
1183 "action": "permit",
1184 "seq_id": "1",
1185 "match": {"ipv6": {"prefix_lists": "pf_list_1_ipv6"}},
1186 }
1187 ]
1188 }
1189 }
1190 }
1191 result = create_route_maps(tgen, routemaps)
1192 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1193
1194 ospf_red_r1 = {
1195 "r0": {
1196 "ospf6": {
1197 "redistribute": [{"redist_type": "static", "route_map": "rmap_ipv6"}]
1198 }
1199 }
1200 }
1201 result = create_router_ospf(tgen, topo, ospf_red_r1)
1202 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1203
1204 step(
1205 "Verify that external routes are summarised to configured"
1206 "summary address on R0 and only one route is sent to R1. Verify that "
1207 "show ip ospf summary should show the configure summaries."
1208 )
1209
1210 input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv6"][0]}]}}
1211 dut = "r1"
1212
1213 result = verify_ospf6_rib(tgen, dut, input_dict_summary)
1214 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1215
1216 result = verify_rib(tgen, "ipv6", dut, input_dict_summary, protocol=protocol)
1217 assert (
1218 result is True
1219 ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
1220
1221 input_dict = {
1222 SUMMARY["ipv6"][0]: {
1223 "Summary address": SUMMARY["ipv6"][0],
1224 "Metric-type": "E2",
1225 "Metric": 20,
1226 "Tag": 0,
1227 "External route count": 5,
1228 }
1229 }
1230 dut = "r0"
1231 result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
1232 assert (
1233 result is True
1234 ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
1235
1236 step("Configure metric type as 1 in route map.")
1237
1238 routemaps = {
1239 "r0": {
1240 "route_maps": {
1241 "rmap_ipv6": [
1242 {
1243 "seq_id": "1",
1244 "action": "permit",
1245 "set": {"metric-type": "type-1"},
1246 }
1247 ]
1248 }
1249 }
1250 }
1251 result = create_route_maps(tgen, routemaps)
1252 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1253
1254 step(
1255 "Verify that external routes(static / connected) are summarised"
1256 " to configured summary address with metric type 2."
1257 )
1258 input_dict = {
1259 SUMMARY["ipv6"][0]: {
1260 "Summary address": SUMMARY["ipv6"][0],
1261 "Metric-type": "E2",
1262 "Metric": 20,
1263 "Tag": 0,
1264 "External route count": 5,
1265 }
1266 }
1267 dut = "r0"
1268 result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
1269 assert (
1270 result is True
1271 ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
1272
1273 step("Un configure metric type from route map.")
1274
1275 routemaps = {
1276 "r0": {
1277 "route_maps": {
1278 "rmap_ipv6": [
1279 {
1280 "action": "permit",
1281 "seq_id": "1",
1282 "set": {"metric-type": "type-1", "delete": True},
1283 }
1284 ]
1285 }
1286 }
1287 }
1288 result = create_route_maps(tgen, routemaps)
1289 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1290
1291 step(
1292 "Verify that external routes(static / connected) are summarised"
1293 " to configured summary address with metric type 2."
1294 )
1295 input_dict = {
1296 SUMMARY["ipv6"][0]: {
1297 "Summary address": SUMMARY["ipv6"][0],
1298 "Metric-type": "E2",
1299 "Metric": 20,
1300 "Tag": 0,
1301 "External route count": 5,
1302 }
1303 }
1304 dut = "r0"
1305 result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
1306 assert (
1307 result is True
1308 ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
1309
1310 step("Change rule from permit to deny in prefix list.")
1311 pfx_list = {
1312 "r0": {
1313 "prefix_lists": {
1314 "ipv6": {
1315 "pf_list_1_ipv6": [
1316 {"seqid": 10, "network": "any", "action": "deny"}
1317 ]
1318 }
1319 }
1320 }
1321 }
1322 result = create_prefix_lists(tgen, pfx_list)
1323 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1324
1325 step(
1326 "Verify that previously originated summary lsa "
1327 "is withdrawn from the neighbor."
1328 )
1329 input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv6"][0]}]}}
1330 dut = "r1"
1331
1332 step("summary route has delay of 5 secs, wait for 5 secs")
1333
1334 sleep(5)
1335
1336 result = verify_ospf6_rib(tgen, dut, input_dict_summary, expected=False)
1337 assert (
1338 result is not True
1339 ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
1340 tc_name, result
1341 )
1342
1343 result = verify_rib(
1344 tgen, "ipv6", dut, input_dict_summary, protocol=protocol, expected=False
1345 )
1346 assert (
1347 result is not True
1348 ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
1349
1350 write_test_footer(tc_name)
1351
1352
1353 def test_ospfv3_type5_summary_tc51_p2(request):
1354 """OSPF CLI Show.
1355
1356 verify ospf ASBR summary config and show commands behaviours.
1357 """
1358 tc_name = request.node.name
1359 write_test_header(tc_name)
1360 tgen = get_topogen()
1361
1362 # Don't run this test if we have any failure.
1363 if tgen.routers_have_failure():
1364 pytest.skip(tgen.errors)
1365
1366 global topo
1367 step("Bring up the base config as per the topology")
1368 reset_config_on_routers(tgen)
1369
1370 step("Configure all the supported OSPF ASBR summary commands on DUT.")
1371 ospf_summ_r1 = {
1372 "r0": {
1373 "ospf6": {
1374 "summary-address": [
1375 {
1376 "prefix": SUMMARY["ipv6"][0].split("/")[0],
1377 "mask": "32",
1378 "tag": 4294967295,
1379 },
1380 {
1381 "prefix": SUMMARY["ipv6"][0].split("/")[0],
1382 "mask": "16",
1383 "advertise": True,
1384 },
1385 {
1386 "prefix": SUMMARY["ipv6"][0].split("/")[0],
1387 "mask": "24",
1388 "advertise": False,
1389 },
1390 {
1391 "prefix": SUMMARY["ipv6"][0].split("/")[0],
1392 "mask": "24",
1393 "advertise": False,
1394 },
1395 ]
1396 }
1397 }
1398 }
1399 result = create_router_ospf(tgen, topo, ospf_summ_r1)
1400 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1401
1402 step("Configure and re configure all the commands 10 times in a loop.")
1403
1404 for itrate in range(0, 10):
1405 ospf_summ_r1 = {
1406 "r0": {
1407 "ospf6": {
1408 "summary-address": [
1409 {
1410 "prefix": SUMMARY["ipv6"][0].split("/")[0],
1411 "mask": "8",
1412 "tag": 4294967295,
1413 },
1414 {
1415 "prefix": SUMMARY["ipv6"][0].split("/")[0],
1416 "mask": "16",
1417 "advertise": True,
1418 },
1419 {
1420 "prefix": SUMMARY["ipv6"][0].split("/")[0],
1421 "mask": "24",
1422 "advertise": False,
1423 },
1424 {
1425 "prefix": SUMMARY["ipv6"][0].split("/")[0],
1426 "mask": "24",
1427 "advertise": False,
1428 },
1429 ]
1430 }
1431 }
1432 }
1433 result = create_router_ospf(tgen, topo, ospf_summ_r1)
1434 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1435 tc_name, result
1436 )
1437
1438 ospf_summ_r1 = {
1439 "r0": {
1440 "ospf6": {
1441 "summary-address": [
1442 {
1443 "prefix": SUMMARY["ipv6"][0].split("/")[0],
1444 "mask": "8",
1445 "tag": 4294967295,
1446 "delete": True,
1447 },
1448 {
1449 "prefix": SUMMARY["ipv6"][0].split("/")[0],
1450 "mask": "16",
1451 "advertise": True,
1452 "delete": True,
1453 },
1454 {
1455 "prefix": SUMMARY["ipv6"][0].split("/")[0],
1456 "mask": "24",
1457 "advertise": False,
1458 "delete": True,
1459 },
1460 {
1461 "prefix": SUMMARY["ipv6"][0].split("/")[0],
1462 "mask": "24",
1463 "advertise": False,
1464 "delete": True,
1465 },
1466 ]
1467 }
1468 }
1469 }
1470 result = create_router_ospf(tgen, topo, ospf_summ_r1)
1471 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1472
1473 step("Verify the show commands")
1474
1475 input_dict = {
1476 SUMMARY["ipv6"][3]: {
1477 "Summary address": SUMMARY["ipv6"][3],
1478 "Metric-type": "E2",
1479 "Metric": 20,
1480 "Tag": 0,
1481 "External route count": 0,
1482 }
1483 }
1484 dut = "r0"
1485 result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
1486 assert (
1487 result is True
1488 ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
1489
1490 write_test_footer(tc_name)
1491
1492
1493 def test_ospfv3_type5_summary_tc49_p2(request):
1494 """OSPF summarisation Chaos."""
1495 tc_name = request.node.name
1496 write_test_header(tc_name)
1497 tgen = get_topogen()
1498
1499 # Don't run this test if we have any failure.
1500 if tgen.routers_have_failure():
1501 pytest.skip(tgen.errors)
1502
1503 global topo
1504 step("Bring up the base config as per the topology")
1505 reset_config_on_routers(tgen)
1506
1507 protocol = "ospf"
1508
1509 step(
1510 "Configure 5 static routes from the same network on R0"
1511 "5 static routes from different networks and redistribute in R0"
1512 )
1513 input_dict_static_rtes = {
1514 "r0": {
1515 "static_routes": [
1516 {"network": NETWORK["ipv6"], "next_hop": "blackhole"},
1517 {"network": NETWORK2["ipv6"], "next_hop": "blackhole"},
1518 ]
1519 }
1520 }
1521 result = create_static_routes(tgen, input_dict_static_rtes)
1522 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1523
1524 dut = "r0"
1525 red_static(dut)
1526
1527 step("Verify that routes are learnt on R1.")
1528 dut = "r1"
1529
1530 result = verify_ospf6_rib(tgen, dut, input_dict_static_rtes)
1531 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1532 result = verify_rib(tgen, "ipv6", dut, input_dict_static_rtes, protocol=protocol)
1533 assert (
1534 result is True
1535 ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
1536
1537 step(
1538 "Configure External Route summary in R0 to summarise 5" " routes to one route."
1539 )
1540
1541 ospf_summ_r1 = {
1542 "r0": {
1543 "ospf6": {
1544 "summary-address": [
1545 {"prefix": SUMMARY["ipv6"][0].split("/")[0], "mask": "32"}
1546 ]
1547 }
1548 }
1549 }
1550 result = create_router_ospf(tgen, topo, ospf_summ_r1)
1551 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1552
1553 step(
1554 "Verify that external routes are summarised to configured summary "
1555 "address on R0 after 5 secs of delay timer expiry and only one "
1556 "route is sent to R1."
1557 )
1558 input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv6"][0]}]}}
1559 dut = "r1"
1560
1561 result = verify_ospf6_rib(tgen, dut, input_dict_summary)
1562 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1563
1564 result = verify_rib(tgen, "ipv6", dut, input_dict_summary, protocol=protocol)
1565 assert (
1566 result is True
1567 ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
1568
1569 step("Verify that show ip ospf summary should show the summaries.")
1570 input_dict = {
1571 SUMMARY["ipv6"][0]: {
1572 "Summary address": SUMMARY["ipv6"][0],
1573 "Metric-type": "E2",
1574 "Metric": 20,
1575 "Tag": 0,
1576 "External route count": 5,
1577 }
1578 }
1579 dut = "r0"
1580 result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
1581 assert (
1582 result is True
1583 ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
1584
1585 step("Verify that originally advertised routes are withdraw from there" " peer.")
1586 input_dict = {
1587 "r0": {"static_routes": [{"network": NETWORK["ipv6"], "next_hop": "blackhole"}]}
1588 }
1589 dut = "r1"
1590 result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
1591 assert (
1592 result is not True
1593 ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
1594 tc_name, result
1595 )
1596
1597 result = verify_rib(
1598 tgen, "ipv6", dut, input_dict, protocol=protocol, expected=False
1599 )
1600 assert (
1601 result is not True
1602 ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
1603
1604 step("Reload the FRR router")
1605 # stop/start -> restart FRR router and verify
1606 stop_router(tgen, "r0")
1607 start_router(tgen, "r0")
1608
1609 step(
1610 "Verify that external routes are summarised to configured summary "
1611 "address on R0 after 5 secs of delay timer expiry and only one "
1612 "route is sent to R1."
1613 )
1614 input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv6"][0]}]}}
1615 dut = "r1"
1616
1617 result = verify_ospf6_rib(tgen, dut, input_dict_summary)
1618 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1619
1620 result = verify_rib(tgen, "ipv6", dut, input_dict_summary, protocol=protocol)
1621 assert (
1622 result is True
1623 ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
1624
1625 step("Verify that show ip ospf summary should show the summaries.")
1626 input_dict = {
1627 SUMMARY["ipv6"][0]: {
1628 "Summary address": SUMMARY["ipv6"][0],
1629 "Metric-type": "E2",
1630 "Metric": 20,
1631 "Tag": 0,
1632 "External route count": 5,
1633 }
1634 }
1635 dut = "r0"
1636 result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
1637 assert (
1638 result is True
1639 ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
1640
1641 step("Verify that originally advertised routes are withdraw from there" " peer.")
1642 input_dict = {
1643 "r0": {"static_routes": [{"network": NETWORK["ipv6"], "next_hop": "blackhole"}]}
1644 }
1645 dut = "r1"
1646 result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
1647 assert (
1648 result is not True
1649 ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
1650 tc_name, result
1651 )
1652
1653 result = verify_rib(
1654 tgen, "ipv6", dut, input_dict, protocol=protocol, expected=False
1655 )
1656 assert (
1657 result is not True
1658 ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
1659
1660 step("Kill OSPF6d daemon on R0.")
1661 kill_router_daemons(tgen, "r0", ["ospf6d"])
1662
1663 step("Bring up OSPF6d daemon on R0.")
1664 start_router_daemons(tgen, "r0", ["ospf6d"])
1665
1666 step("Verify OSPF neighbors are up after bringing back ospf6d in R0")
1667 # Api call verify whether OSPF is converged
1668 ospf_covergence = verify_ospf6_neighbor(tgen, topo)
1669 assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
1670 ospf_covergence
1671 )
1672
1673 step(
1674 "Verify that external routes are summarised to configured summary "
1675 "address on R0 after 5 secs of delay timer expiry and only one "
1676 "route is sent to R1."
1677 )
1678 input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv6"][0]}]}}
1679 dut = "r1"
1680
1681 result = verify_ospf6_rib(tgen, dut, input_dict_summary)
1682 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1683
1684 result = verify_rib(tgen, "ipv6", dut, input_dict_summary, protocol=protocol)
1685 assert (
1686 result is True
1687 ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
1688
1689 step("Verify that show ip ospf summary should show the summaries.")
1690 input_dict = {
1691 SUMMARY["ipv6"][0]: {
1692 "Summary address": SUMMARY["ipv6"][0],
1693 "Metric-type": "E2",
1694 "Metric": 20,
1695 "Tag": 0,
1696 "External route count": 5,
1697 }
1698 }
1699 dut = "r0"
1700 result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
1701 assert (
1702 result is True
1703 ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
1704
1705 step("Verify that originally advertised routes are withdraw from there" " peer.")
1706 input_dict = {
1707 "r0": {"static_routes": [{"network": NETWORK["ipv6"], "next_hop": "blackhole"}]}
1708 }
1709 dut = "r1"
1710 result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
1711 assert (
1712 result is not True
1713 ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
1714 tc_name, result
1715 )
1716
1717 result = verify_rib(
1718 tgen, "ipv6", dut, input_dict, protocol=protocol, expected=False
1719 )
1720 assert (
1721 result is not True
1722 ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
1723
1724 step("restart zebrad")
1725 kill_router_daemons(tgen, "r0", ["zebra"])
1726
1727 step("Bring up zebra daemon on R0.")
1728 start_router_daemons(tgen, "r0", ["zebra"])
1729
1730 step(
1731 "Verify that external routes are summarised to configured summary "
1732 "address on R0 after 5 secs of delay timer expiry and only one "
1733 "route is sent to R1."
1734 )
1735 input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv6"][0]}]}}
1736 dut = "r1"
1737
1738 result = verify_ospf6_rib(tgen, dut, input_dict_summary)
1739 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1740
1741 result = verify_rib(tgen, "ipv6", dut, input_dict_summary, protocol=protocol)
1742 assert (
1743 result is True
1744 ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name)
1745
1746 step("Verify that show ip ospf summary should show the summaries.")
1747 input_dict = {
1748 SUMMARY["ipv6"][0]: {
1749 "Summary address": SUMMARY["ipv6"][0],
1750 "Metric-type": "E2",
1751 "Metric": 20,
1752 "Tag": 0,
1753 "External route count": 5,
1754 }
1755 }
1756 dut = "r0"
1757 result = verify_ospf_summary(tgen, topo, dut, input_dict, ospf="ospf6")
1758 assert (
1759 result is True
1760 ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name)
1761
1762 step("Verify that originally advertised routes are withdraw from there" " peer.")
1763 input_dict = {
1764 "r0": {"static_routes": [{"network": NETWORK["ipv6"], "next_hop": "blackhole"}]}
1765 }
1766 dut = "r1"
1767 result = verify_ospf6_rib(tgen, dut, input_dict, expected=False)
1768 assert (
1769 result is not True
1770 ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format(
1771 tc_name, result
1772 )
1773
1774 result = verify_rib(
1775 tgen, "ipv6", dut, input_dict, protocol=protocol, expected=False
1776 )
1777 assert (
1778 result is not True
1779 ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name)
1780
1781 write_test_footer(tc_name)
1782
1783
1784 if __name__ == "__main__":
1785 args = ["-s"] + sys.argv[1:]
1786 sys.exit(pytest.main(args))