]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/static_routing_with_ibgp/test_static_routes_topo1_ibgp.py
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[mirror_frr.git] / tests / topotests / static_routing_with_ibgp / test_static_routes_topo1_ibgp.py
1 #!/usr/bin/python
2
3 #
4 # Copyright (c) 2020 by VMware, Inc. ("VMware")
5 # Used Copyright (c) 2018 by Network Device Education Foundation,
6 # Inc. ("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 -Verify static route ECMP functionality with 2 next hop
25
26 -Verify static route functionality with 2 next hop and different AD
27 value
28
29 -Verify RIB status when same route advertise via BGP and static route
30
31 """
32 import sys
33 import time
34 import os
35 import pytest
36 import platform
37
38 # Save the Current Working Directory to find configuration files.
39 CWD = os.path.dirname(os.path.realpath(__file__))
40 sys.path.append(os.path.join(CWD, "../"))
41 sys.path.append(os.path.join(CWD, "../lib/"))
42 # pylint: disable=C0413
43 # Import topogen and topotest helpers
44 from lib.topogen import Topogen, get_topogen
45 from lib.topotest import version_cmp
46
47 # Import topoJson from lib, to create topology and initial configuration
48 from lib.common_config import (
49 start_topology,
50 write_test_header,
51 write_test_footer,
52 reset_config_on_routers,
53 verify_rib,
54 create_static_routes,
55 check_address_types,
56 step,
57 shutdown_bringup_interface,
58 stop_router,
59 start_router,
60 )
61 from lib.topolog import logger
62 from lib.bgp import verify_bgp_convergence, create_router_bgp, verify_bgp_rib
63 from lib.topojson import build_config_from_json
64
65 pytestmark = [pytest.mark.bgpd, pytest.mark.staticd]
66
67 # Global variables
68 BGP_CONVERGENCE = False
69 ADDR_TYPES = check_address_types()
70 NETWORK = {"ipv4": ["11.0.20.1/32", "11.0.20.2/32"], "ipv6": ["2::1/128", "2::2/128"]}
71 NETWORK2 = {"ipv4": "11.0.20.1/32", "ipv6": "2::1/128"}
72
73 PREFIX1 = {"ipv4": "110.0.20.1/32", "ipv6": "20::1/128"}
74
75
76 def setup_module(mod):
77 """
78
79 Set up the pytest environment.
80
81 * `mod`: module name
82 """
83 testsuite_run_time = time.asctime(time.localtime(time.time()))
84 logger.info("Testsuite start time: {}".format(testsuite_run_time))
85 logger.info("=" * 40)
86
87 logger.info("Running setup_module to create topology")
88
89 # This function initiates the topology build with Topogen...
90 json_file = "{}/static_routes_topo1_ibgp.json".format(CWD)
91 tgen = Topogen(json_file, mod.__name__)
92 global topo
93 topo = tgen.json_topo
94 # ... and here it calls Mininet initialization functions.
95
96 # Starting topology, create tmp files which are loaded to routers
97 # to start daemons and then start routers
98 start_topology(tgen)
99
100 # Creating configuration from JSON
101 build_config_from_json(tgen, topo)
102
103 if version_cmp(platform.release(), "4.19") < 0:
104 error_msg = (
105 'These tests will not run. (have kernel "{}", '
106 "requires kernel >= 4.19)".format(platform.release())
107 )
108 pytest.skip(error_msg)
109
110 # Checking BGP convergence
111 global BGP_CONVERGENCE
112 global ADDR_TYPES
113
114 # Don't run this test if we have any failure.
115 if tgen.routers_have_failure():
116 pytest.skip(tgen.errors)
117 # Api call verify whether BGP is converged
118 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
119 assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error: {}".format(
120 BGP_CONVERGENCE
121 )
122
123 logger.info("Running setup_module() done")
124
125
126 def teardown_module(mod):
127 """
128 Teardown the pytest environment
129
130 * `mod`: module name
131 """
132
133 logger.info("Running teardown_module to delete topology")
134
135 tgen = get_topogen()
136
137 # Stop toplogy and Remove tmp files
138 tgen.stop_topology()
139
140 logger.info(
141 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
142 )
143 logger.info("=" * 40)
144
145
146 def populate_nh():
147 NEXT_HOP_IP = {
148 "nh1": {
149 "ipv4": topo["routers"]["r1"]["links"]["r2-link0"]["ipv4"].split("/")[0],
150 "ipv6": topo["routers"]["r1"]["links"]["r2-link0"]["ipv6"].split("/")[0],
151 },
152 "nh2": {
153 "ipv4": topo["routers"]["r1"]["links"]["r2-link1"]["ipv4"].split("/")[0],
154 "ipv6": topo["routers"]["r1"]["links"]["r2-link1"]["ipv6"].split("/")[0],
155 },
156 }
157 return NEXT_HOP_IP
158
159
160 #####################################################
161 #
162 # Tests starting
163 #
164 #####################################################
165
166
167 def test_static_route_2nh_p0_tc_1_ibgp(request):
168 """
169 Verify static route ECMP functionality with 2 next hop
170
171 """
172 tc_name = request.node.name
173 write_test_header(tc_name)
174 tgen = get_topogen()
175 # Don't run this test if we have any failure.
176 if tgen.routers_have_failure():
177 pytest.skip(tgen.errors)
178
179 reset_config_on_routers(tgen)
180 NEXT_HOP_IP = populate_nh()
181
182 step(
183 "Configure IPv4 static route (10.1.1.1) in R2 with next hop N1"
184 "(28.1.1.2 ) and N2 (29.1.1.2) , Static route next-hop present on"
185 "R1"
186 )
187 step("ex :- ip route 10.1.1.1/24 28.1.1.2 & ip route 10.1.1.1/24 29.1.1.1")
188 for addr_type in ADDR_TYPES:
189 input_dict_4 = {
190 "r2": {
191 "static_routes": [
192 {
193 "network": NETWORK[addr_type],
194 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
195 },
196 {
197 "network": NETWORK[addr_type],
198 "next_hop": NEXT_HOP_IP["nh2"][addr_type],
199 },
200 ]
201 }
202 }
203
204 logger.info("Configure static routes")
205 result = create_static_routes(tgen, input_dict_4)
206 assert result is True, "Testcase {} : Failed \n Error: {}".format(
207 tc_name, result
208 )
209
210 step(
211 "On R2, static route installed in RIB using show ip route"
212 " with 2 ECMP next hop "
213 )
214 nh = [NEXT_HOP_IP["nh1"][addr_type], NEXT_HOP_IP["nh2"][addr_type]]
215 dut = "r2"
216 protocol = "static"
217 result = verify_rib(
218 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol
219 )
220 assert (
221 result is True
222 ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
223
224 step("Configure IBGP IPv4 peering between R2 and R3 router.")
225 step("Configure redistribute static in BGP on R2 router")
226
227 input_dict_2 = {
228 "r2": {
229 "bgp": {
230 "address_family": {
231 addr_type: {
232 "unicast": {"redistribute": [{"redist_type": "static"}]}
233 }
234 }
235 }
236 }
237 }
238 result = create_router_bgp(tgen, topo, input_dict_2)
239 assert result is True, "Testcase {} : Failed \n Error: {}".format(
240 tc_name, result
241 )
242
243 step("Remove the static route configured with nexthop N1 from running config")
244 input_dict_4 = {
245 "r2": {
246 "static_routes": [
247 {
248 "network": NETWORK[addr_type],
249 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
250 "delete": True,
251 }
252 ]
253 }
254 }
255 logger.info("Configure static routes")
256 result = create_static_routes(tgen, input_dict_4)
257 assert result is True, "Testcase {} : Failed \n Error: {}".format(
258 tc_name, result
259 )
260
261 step(
262 "On R2, after removing the static route with N1 , "
263 "route become active with nexthop N2 and vice versa."
264 )
265 nh = NEXT_HOP_IP["nh1"][addr_type]
266 result = verify_rib(
267 tgen,
268 addr_type,
269 dut,
270 input_dict_4,
271 next_hop=nh,
272 protocol=protocol,
273 expected=False,
274 )
275 assert (
276 result is not True
277 ), "Testcase {} : Failed \nError: Routes is" " still present in RIB".format(
278 tc_name
279 )
280
281 nh = [NEXT_HOP_IP["nh2"][addr_type]]
282 result = verify_rib(
283 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol
284 )
285 assert (
286 result is True
287 ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
288
289 step("Configure the static route with nexthop N1")
290
291 input_dict_4 = {
292 "r2": {
293 "static_routes": [
294 {
295 "network": NETWORK[addr_type],
296 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
297 }
298 ]
299 }
300 }
301
302 logger.info("Configure static routes")
303 result = create_static_routes(tgen, input_dict_4)
304 assert result is True, "Testcase {} : Failed \n Error: {}".format(
305 tc_name, result
306 )
307
308 step("Remove the static route configured with nexthop N2 from running config")
309
310 input_dict_4 = {
311 "r2": {
312 "static_routes": [
313 {
314 "network": NETWORK[addr_type],
315 "next_hop": NEXT_HOP_IP["nh2"][addr_type],
316 "delete": True,
317 }
318 ]
319 }
320 }
321
322 logger.info("Configure static routes")
323 result = create_static_routes(tgen, input_dict_4)
324 assert result is True, "Testcase {} : Failed \n Error: {}".format(
325 tc_name, result
326 )
327
328 step(
329 "On R2, after removing the static route with N2 , "
330 "route become active with nexthop N1 and vice versa."
331 )
332 nh = NEXT_HOP_IP["nh2"][addr_type]
333 result = verify_rib(
334 tgen,
335 addr_type,
336 dut,
337 input_dict_4,
338 next_hop=nh,
339 protocol=protocol,
340 expected=False,
341 )
342 assert (
343 result is not True
344 ), "Testcase {} : Failed \nError: Routes is" " still present in RIB".format(
345 tc_name
346 )
347
348 nh = [NEXT_HOP_IP["nh1"][addr_type]]
349 result = verify_rib(
350 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol
351 )
352 assert (
353 result is True
354 ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
355
356 step("Configure the static route with nexthop N2")
357 input_dict_4 = {
358 "r2": {
359 "static_routes": [
360 {
361 "network": NETWORK[addr_type],
362 "next_hop": NEXT_HOP_IP["nh2"][addr_type],
363 }
364 ]
365 }
366 }
367
368 logger.info("Configure static routes")
369 result = create_static_routes(tgen, input_dict_4)
370 assert result is True, "Testcase {} : Failed \n Error: {}".format(
371 tc_name, result
372 )
373
374 step("Shut nexthop interface N1")
375 intf = topo["routers"]["r2"]["links"]["r1-link0"]["interface"]
376
377 shutdown_bringup_interface(tgen, dut, intf, False)
378
379 step("Only one the nexthops should be active in RIB.")
380
381 nh = NEXT_HOP_IP["nh2"][addr_type]
382 result = verify_rib(
383 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol
384 )
385 assert (
386 result is True
387 ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
388
389 nh = NEXT_HOP_IP["nh1"][addr_type]
390 result = verify_rib(
391 tgen,
392 addr_type,
393 dut,
394 input_dict_4,
395 next_hop=nh,
396 protocol=protocol,
397 expected=False,
398 )
399 assert (
400 result is not True
401 ), "Testcase {} : Failed \nError: Routes is" " still present in RIB".format(
402 tc_name
403 )
404
405 dut = "r3"
406 result = verify_bgp_rib(
407 tgen, addr_type, dut, input_dict_4, next_hop=nh, expected=False
408 )
409 assert (
410 result is not True
411 ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
412 tc_name
413 )
414
415 result = verify_rib(
416 tgen,
417 addr_type,
418 dut,
419 input_dict_4,
420 protocol=protocol,
421 next_hop=nh,
422 expected=False,
423 )
424 assert (
425 result is not True
426 ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
427 tc_name
428 )
429
430 dut = "r2"
431 nh = [NEXT_HOP_IP["nh2"][addr_type]]
432 result = verify_rib(
433 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol
434 )
435 assert (
436 result is True
437 ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
438
439 dut = "r3"
440 result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
441 assert (
442 result is True
443 ), "Testcase {} : Failed \nError: Route is" " missing in RIB".format(tc_name)
444
445 result = verify_rib(
446 tgen, addr_type, dut, input_dict_4, protocol=protocol, expected=False
447 )
448 assert (
449 result is not True
450 ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
451 tc_name
452 )
453
454 dut = "r2"
455 step("No shut the nexthop interface N1")
456 shutdown_bringup_interface(tgen, dut, intf, True)
457
458 step(
459 "after shut of nexthop N1 , route become active "
460 "with nexthop N2 and vice versa."
461 )
462 nh = [NEXT_HOP_IP["nh1"][addr_type], NEXT_HOP_IP["nh2"][addr_type]]
463
464 result = verify_rib(
465 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol
466 )
467 assert (
468 result is True
469 ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
470
471 step("Shut nexthop interface N2")
472 intf = topo["routers"]["r2"]["links"]["r1-link1"]["interface"]
473 dut = "r2"
474 shutdown_bringup_interface(tgen, dut, intf, False)
475
476 step(
477 " after shut of nexthop N1 , route become active with "
478 "nexthop N2 and vice versa."
479 )
480 nh = NEXT_HOP_IP["nh2"][addr_type]
481
482 result = verify_rib(
483 tgen,
484 addr_type,
485 dut,
486 input_dict_4,
487 next_hop=nh,
488 protocol=protocol,
489 expected=False,
490 )
491 assert (
492 result is not True
493 ), "Testcase {} : Failed \nError: Routes is" " still present in RIB".format(
494 tc_name
495 )
496
497 nh = [NEXT_HOP_IP["nh1"][addr_type]]
498 dut = "r2"
499 protocol = "static"
500 result = verify_rib(
501 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol
502 )
503 assert (
504 result is True
505 ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
506
507 dut = "r3"
508 result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
509 assert (
510 result is True
511 ), "Testcase {} : Failed \nError: Route is" " missing in RIB".format(tc_name)
512
513 result = verify_rib(
514 tgen, addr_type, dut, input_dict_4, protocol=protocol, expected=False
515 )
516 assert (
517 result is not True
518 ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
519 tc_name
520 )
521
522 step("No shut nexthop interface N2")
523 dut = "r2"
524 shutdown_bringup_interface(tgen, dut, intf, True)
525
526 step(
527 "after shut of nexthop N1 , route become active "
528 "with nexthop N2 and vice versa."
529 )
530 nh = [NEXT_HOP_IP["nh1"][addr_type], NEXT_HOP_IP["nh2"][addr_type]]
531
532 result = verify_rib(
533 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol
534 )
535 assert (
536 result is True
537 ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
538
539 dut = "r3"
540 result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
541 assert (
542 result is True
543 ), "Testcase {} : Failed \nError: Route is" " missing in RIB".format(tc_name)
544
545 result = verify_rib(
546 tgen, addr_type, dut, input_dict_4, protocol=protocol, expected=False
547 )
548 assert (
549 result is not True
550 ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
551 tc_name
552 )
553
554 step("Reload the FRR router")
555 # stop/start -> restart FRR router and verify
556 stop_router(tgen, "r2")
557
558 start_router(tgen, "r2")
559
560 dut = "r2"
561 step(
562 "After reload of FRR router , static route installed"
563 " in RIB and FIB properly ."
564 )
565 result = verify_rib(
566 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol
567 )
568 assert (
569 result is True
570 ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
571
572 dut = "r3"
573 result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
574 assert (
575 result is True
576 ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
577 tc_name
578 )
579
580 result = verify_rib(
581 tgen, addr_type, dut, input_dict_4, protocol=protocol, expected=False
582 )
583 assert (
584 result is not True
585 ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
586 tc_name
587 )
588
589 write_test_footer(tc_name)
590
591
592 def test_static_route_2nh_admin_dist_p0_tc_2_ibgp(request):
593 """
594 Verify static route functionality with 2 next hop & different AD value
595
596 """
597 tc_name = request.node.name
598 write_test_header(tc_name)
599 tgen = get_topogen()
600 # Don't run this test if we have any failure.
601 if tgen.routers_have_failure():
602 pytest.skip(tgen.errors)
603
604 reset_config_on_routers(tgen)
605 NEXT_HOP_IP = populate_nh()
606 step(
607 "Configure IPv4 static route (10.1.1.1) in R2 with next hop N1"
608 "(28.1.1.2 ) AD 10 and N2 (29.1.1.2) AD 20 , Static route next-hop"
609 "present on R1 \n ex :- ip route 10.1.1.1/24 28.1.1.2 10 & "
610 "ip route 10.1.1.1/24 29.1.1.2 20"
611 )
612
613 reset_config_on_routers(tgen)
614 NEXT_HOP_IP = populate_nh()
615 for addr_type in ADDR_TYPES:
616 input_dict_4 = {
617 "r2": {
618 "static_routes": [
619 {
620 "network": NETWORK2[addr_type],
621 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
622 "admin_distance": 10,
623 },
624 {
625 "network": NETWORK2[addr_type],
626 "next_hop": NEXT_HOP_IP["nh2"][addr_type],
627 "admin_distance": 20,
628 },
629 ]
630 }
631 }
632 logger.info("Configure static routes")
633 result = create_static_routes(tgen, input_dict_4)
634 assert result is True, "Testcase {} : Failed \n Error: {}".format(
635 tc_name, result
636 )
637
638 step(
639 "On R2, static route installed in RIB using "
640 "show ip route with 2 next hop , lowest AD nexthop is active "
641 )
642 rte1_nh1 = {
643 "r2": {
644 "static_routes": [
645 {
646 "network": NETWORK2[addr_type],
647 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
648 "admin_distance": 10,
649 }
650 ]
651 }
652 }
653 nh = [NEXT_HOP_IP["nh1"][addr_type]]
654 dut = "r2"
655 protocol = "static"
656 result = verify_rib(
657 tgen, addr_type, dut, rte1_nh1, next_hop=nh, protocol=protocol, fib=True
658 )
659 assert (
660 result is True
661 ), "Testcase {} : Failed \nError: Routes is" "missing in RIB".format(tc_name)
662
663 rte2_nh2 = {
664 "r2": {
665 "static_routes": [
666 {
667 "network": NETWORK2[addr_type],
668 "next_hop": NEXT_HOP_IP["nh2"][addr_type],
669 "admin_distance": 20,
670 }
671 ]
672 }
673 }
674 nh = [NEXT_HOP_IP["nh2"][addr_type]]
675 dut = "r2"
676 protocol = "static"
677 result = verify_rib(
678 tgen,
679 addr_type,
680 dut,
681 rte2_nh2,
682 next_hop=nh,
683 protocol=protocol,
684 fib=True,
685 expected=False,
686 )
687 assert (
688 result is not True
689 ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(tc_name)
690
691 step("Configure IBGP IPv4 peering between R2 and R3 router.")
692 step("Explicit route is added in R3 for R2 nexthop rechability")
693 rt3_rtes = {
694 "r3": {
695 "static_routes": [
696 {
697 "network": NEXT_HOP_IP["nh1"][addr_type] + "/32",
698 "next_hop": topo["routers"]["r2"]["links"]["r3"][addr_type],
699 },
700 {
701 "network": NEXT_HOP_IP["nh2"][addr_type] + "/32",
702 "next_hop": topo["routers"]["r2"]["links"]["r3"][addr_type],
703 },
704 ]
705 }
706 }
707 logger.info("Configure static routes")
708 result = create_static_routes(tgen, rt3_rtes)
709 assert result is True, "Testcase {} : Failed \n Error: {}".format(
710 tc_name, result
711 )
712 step("Configure redistribute static in BGP on R2 router")
713
714 input_dict_2 = {
715 "r2": {
716 "bgp": {
717 "address_family": {
718 addr_type: {
719 "unicast": {"redistribute": [{"redist_type": "static"}]}
720 }
721 }
722 }
723 }
724 }
725 result = create_router_bgp(tgen, topo, input_dict_2)
726 assert result is True, "Testcase {} : Failed \n Error: {}".format(
727 tc_name, result
728 )
729
730 step("Remove the static route configured with nexthop N1 from running config")
731 rt1_nh1 = {
732 "r2": {
733 "static_routes": [
734 {
735 "network": NETWORK[addr_type],
736 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
737 "admin_distance": 10,
738 "delete": True,
739 }
740 ]
741 }
742 }
743
744 logger.info("Configure static routes")
745 result = create_static_routes(tgen, rt1_nh1)
746 assert result is True, "Testcase {} : Failed \n Error: {}".format(
747 tc_name, result
748 )
749
750 step(
751 "On R2, after removing the static route with N1 , "
752 "route become active with nexthop N2 and vice versa."
753 )
754 rte1_nh1 = {
755 "r2": {
756 "static_routes": [
757 {
758 "network": NETWORK2[addr_type],
759 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
760 "admin_distance": 10,
761 }
762 ]
763 }
764 }
765 nh = [NEXT_HOP_IP["nh1"][addr_type]]
766 dut = "r2"
767 protocol = "static"
768 result = verify_rib(
769 tgen,
770 addr_type,
771 dut,
772 rte1_nh1,
773 next_hop=nh,
774 protocol=protocol,
775 fib=True,
776 expected=False,
777 )
778 assert (
779 result is not True
780 ), "Testcase {} : Failed \nError: Routes is" "missing in RIB".format(tc_name)
781
782 rte2_nh2 = {
783 "r2": {
784 "static_routes": [
785 {
786 "network": NETWORK2[addr_type],
787 "next_hop": NEXT_HOP_IP["nh2"][addr_type],
788 "admin_distance": 20,
789 }
790 ]
791 }
792 }
793 nh = [NEXT_HOP_IP["nh2"][addr_type]]
794 result = verify_rib(
795 tgen, addr_type, dut, rte2_nh2, next_hop=nh, protocol=protocol, fib=True
796 )
797 assert (
798 result is True
799 ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(tc_name)
800
801 step("Configure the static route with nexthop N1")
802 rte1_nh1 = {
803 "r2": {
804 "static_routes": [
805 {
806 "network": NETWORK[addr_type],
807 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
808 "admin_distance": 10,
809 }
810 ]
811 }
812 }
813 logger.info("Configure static routes")
814 result = create_static_routes(tgen, rte1_nh1)
815 assert result is True, "Testcase {} : Failed \n Error: {}".format(
816 tc_name, result
817 )
818
819 step("Remove the static route configured with nexthop N2 from running config")
820 rte2_nh2 = {
821 "r2": {
822 "static_routes": [
823 {
824 "network": NETWORK[addr_type],
825 "next_hop": NEXT_HOP_IP["nh2"][addr_type],
826 "admin_distance": 20,
827 "delete": True,
828 }
829 ]
830 }
831 }
832 logger.info("Configure static routes")
833 result = create_static_routes(tgen, rte2_nh2)
834 assert result is True, "Testcase {} : Failed \n Error: {}".format(
835 tc_name, result
836 )
837
838 step(
839 "On R2, after removing the static route with N2 , "
840 "route become active with nexthop N1 and vice versa."
841 )
842 nh = NEXT_HOP_IP["nh2"][addr_type]
843 result = verify_rib(
844 tgen,
845 addr_type,
846 dut,
847 rte2_nh2,
848 next_hop=nh,
849 protocol=protocol,
850 expected=False,
851 )
852 assert (
853 result is not True
854 ), "Testcase {} : Failed \nError: Routes is" " still present in RIB".format(
855 tc_name
856 )
857
858 nh = [NEXT_HOP_IP["nh1"][addr_type]]
859 result = verify_rib(
860 tgen, addr_type, dut, rte1_nh1, next_hop=nh, protocol=protocol
861 )
862 assert (
863 result is True
864 ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
865
866 step("Configure the static route with nexthop N2")
867 rte2_nh2 = {
868 "r2": {
869 "static_routes": [
870 {
871 "network": NETWORK[addr_type],
872 "next_hop": NEXT_HOP_IP["nh2"][addr_type],
873 "admin_distance": 20,
874 }
875 ]
876 }
877 }
878
879 logger.info("Configure static routes")
880 result = create_static_routes(tgen, rte2_nh2)
881 assert result is True, "Testcase {} : Failed \n Error: {}".format(
882 tc_name, result
883 )
884
885 step("Shut nexthop interface N1")
886 intf = topo["routers"]["r2"]["links"]["r1-link0"]["interface"]
887
888 shutdown_bringup_interface(tgen, dut, intf, False)
889
890 step("after shut of nexthop N1 , route become active with nexthop N2")
891
892 nh = NEXT_HOP_IP["nh1"][addr_type]
893 result = verify_rib(
894 tgen,
895 addr_type,
896 dut,
897 rte1_nh1,
898 next_hop=nh,
899 protocol=protocol,
900 expected=False,
901 )
902 assert (
903 result is not True
904 ), "Testcase {} : Failed \nError: Routes is" " still present in RIB".format(
905 tc_name
906 )
907
908 nh = [NEXT_HOP_IP["nh2"][addr_type]]
909 result = verify_rib(
910 tgen, addr_type, dut, rte2_nh2, next_hop=nh, protocol=protocol, fib=True
911 )
912 assert (
913 result is True
914 ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
915
916 step("No shut the nexthop interface N1")
917 shutdown_bringup_interface(tgen, dut, intf, True)
918
919 step(
920 "after shut of nexthop N1 , route become active "
921 "with nexthop N2 and vice versa."
922 )
923 nh = [NEXT_HOP_IP["nh1"][addr_type]]
924
925 result = verify_rib(
926 tgen, addr_type, dut, rte1_nh1, next_hop=nh, protocol=protocol, fib=True
927 )
928 assert (
929 result is True
930 ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
931
932 step("Shut nexthop interface N2")
933 intf = topo["routers"]["r2"]["links"]["r1-link1"]["interface"]
934
935 shutdown_bringup_interface(tgen, dut, intf, False)
936
937 step(
938 " after shut of nexthop N1 , route become active with "
939 "nexthop N2 and vice versa."
940 )
941 nh = NEXT_HOP_IP["nh2"][addr_type]
942
943 result = verify_rib(
944 tgen,
945 addr_type,
946 dut,
947 rte2_nh2,
948 next_hop=nh,
949 protocol=protocol,
950 expected=False,
951 )
952 assert (
953 result is not True
954 ), "Testcase {} : Failed \nError: Routes is" " still present in RIB".format(
955 tc_name
956 )
957
958 nh = [NEXT_HOP_IP["nh1"][addr_type]]
959 result = verify_rib(
960 tgen, addr_type, dut, rte1_nh1, next_hop=nh, protocol=protocol
961 )
962 assert (
963 result is True
964 ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name)
965
966 step("No shut nexthop interface N2")
967 shutdown_bringup_interface(tgen, dut, intf, True)
968
969 step(
970 "after shut of nexthop N1 , route become active "
971 "with nexthop N2 and vice versa."
972 )
973 rte1_nh1 = {
974 "r2": {
975 "static_routes": [
976 {
977 "network": NETWORK2[addr_type],
978 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
979 "admin_distance": 10,
980 }
981 ]
982 }
983 }
984 nh = [NEXT_HOP_IP["nh1"][addr_type]]
985 dut = "r2"
986 protocol = "static"
987 result = verify_rib(
988 tgen, addr_type, dut, rte1_nh1, next_hop=nh, protocol=protocol, fib=True
989 )
990 assert (
991 result is True
992 ), "Testcase {} : Failed \nError: Routes is" "missing in RIB".format(tc_name)
993
994 rte2_nh2 = {
995 "r2": {
996 "static_routes": [
997 {
998 "network": NETWORK2[addr_type],
999 "next_hop": NEXT_HOP_IP["nh2"][addr_type],
1000 "admin_distance": 20,
1001 }
1002 ]
1003 }
1004 }
1005 nh = [NEXT_HOP_IP["nh2"][addr_type]]
1006 dut = "r2"
1007 protocol = "static"
1008 result = verify_rib(
1009 tgen,
1010 addr_type,
1011 dut,
1012 rte2_nh2,
1013 next_hop=nh,
1014 protocol=protocol,
1015 fib=True,
1016 expected=False,
1017 )
1018 assert (
1019 result is not True
1020 ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(tc_name)
1021
1022 dut = "r3"
1023 protocol = "bgp"
1024
1025 result = verify_rib(
1026 tgen,
1027 addr_type,
1028 dut,
1029 rte2_nh2,
1030 next_hop=nh,
1031 protocol=protocol,
1032 fib=True,
1033 expected=False,
1034 )
1035 assert (
1036 result is not True
1037 ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(tc_name)
1038
1039 dut = "r2"
1040 step("Reload the FRR router")
1041 # stop/start -> restart FRR router and verify
1042 stop_router(tgen, "r2")
1043
1044 start_router(tgen, "r2")
1045
1046 step(
1047 "After reload of FRR router , static route installed"
1048 " in RIB and FIB properly ."
1049 )
1050 rte1_nh1 = {
1051 "r2": {
1052 "static_routes": [
1053 {
1054 "network": NETWORK2[addr_type],
1055 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
1056 "admin_distance": 10,
1057 }
1058 ]
1059 }
1060 }
1061 nh = [NEXT_HOP_IP["nh1"][addr_type]]
1062 dut = "r2"
1063 protocol = "static"
1064 result = verify_rib(
1065 tgen, addr_type, dut, rte1_nh1, next_hop=nh, protocol=protocol, fib=True
1066 )
1067 assert (
1068 result is True
1069 ), "Testcase {} : Failed \nError: Routes is" "missing in RIB".format(tc_name)
1070
1071 dut = "r3"
1072 protocol = "bgp"
1073 result = verify_bgp_rib(tgen, addr_type, dut, rte1_nh1, next_hop=nh)
1074 assert (
1075 result is True
1076 ), "Testcase {} : Failed \nError: Routes is" "missing in RIB".format(tc_name)
1077
1078 rte2_nh2 = {
1079 "r2": {
1080 "static_routes": [
1081 {
1082 "network": NETWORK2[addr_type],
1083 "next_hop": NEXT_HOP_IP["nh2"][addr_type],
1084 "admin_distance": 20,
1085 }
1086 ]
1087 }
1088 }
1089 nh = [NEXT_HOP_IP["nh2"][addr_type]]
1090 dut = "r2"
1091 protocol = "static"
1092 result = verify_rib(
1093 tgen,
1094 addr_type,
1095 dut,
1096 rte2_nh2,
1097 next_hop=nh,
1098 protocol=protocol,
1099 fib=True,
1100 expected=False,
1101 )
1102 assert (
1103 result is not True
1104 ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(tc_name)
1105
1106 dut = "r3"
1107 protocol = "bgp"
1108 result = verify_bgp_rib(tgen, addr_type, dut, rte2_nh2, next_hop=nh)
1109 assert (
1110 result is True
1111 ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(tc_name)
1112
1113 result = verify_rib(
1114 tgen,
1115 addr_type,
1116 dut,
1117 rte2_nh2,
1118 next_hop=nh,
1119 protocol=protocol,
1120 fib=True,
1121 expected=False,
1122 )
1123 assert (
1124 result is not True
1125 ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(tc_name)
1126
1127 write_test_footer(tc_name)
1128
1129
1130 if __name__ == "__main__":
1131 args = ["-s"] + sys.argv[1:]
1132 sys.exit(pytest.main(args))