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