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