]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/static_routing_with_ebgp/test_static_routes_topo2_ebgp.py
Merge pull request #12816 from gpnaveen/stc_rte_err_msg
[mirror_frr.git] / tests / topotests / static_routing_with_ebgp / test_static_routes_topo2_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 """
12 -Verify static route functionality with 8 next hop different AD value
13 and BGP ECMP
14
15 -Verify 8 static route functionality with 8 next hop different AD
16
17 -Verify static route with 8 next hop with different AD value and 8
18 EBGP neighbors
19
20 -Verify static route with 8 next hop with different AD value and 8
21 IBGP neighbors
22
23 -Delete the static route and verify the RIB and FIB state
24
25 -Verify 8 static route functionality with 8 ECMP next hop
26 """
27 import sys
28 import time
29 import os
30 import pytest
31 import platform
32 import random
33 from lib.topotest import version_cmp
34
35 # Save the Current Working Directory to find configuration files.
36 CWD = os.path.dirname(os.path.realpath(__file__))
37 sys.path.append(os.path.join(CWD, "../"))
38 sys.path.append(os.path.join(CWD, "../lib/"))
39 # pylint: disable=C0413
40 # Import topogen and topotest helpers
41 from lib.topogen import Topogen, get_topogen
42
43 # Import topoJson from lib, to create topology and initial configuration
44 from lib.common_config import (
45 start_topology,
46 write_test_header,
47 write_test_footer,
48 reset_config_on_routers,
49 verify_rib,
50 create_static_routes,
51 check_address_types,
52 step,
53 shutdown_bringup_interface,
54 stop_router,
55 start_router,
56 )
57 from lib.topolog import logger
58 from lib.bgp import verify_bgp_convergence, create_router_bgp, verify_bgp_rib
59 from lib.topojson import build_config_from_json
60
61 pytestmark = [pytest.mark.bgpd, pytest.mark.staticd]
62
63 # Global variables
64 BGP_CONVERGENCE = False
65 ADDR_TYPES = check_address_types()
66 NETWORK = {
67 "ipv4": [
68 "11.0.20.1/32",
69 "11.0.20.2/32",
70 "11.0.20.3/32",
71 "11.0.20.4/32",
72 "11.0.20.5/32",
73 "11.0.20.6/32",
74 "11.0.20.7/32",
75 "11.0.20.8/32",
76 ],
77 "ipv6": [
78 "2::1/128",
79 "2::2/128",
80 "2::3/128",
81 "2::4/128",
82 "2::5/128",
83 "2::6/128",
84 "2::7/128",
85 "2::8/128",
86 ],
87 }
88 PREFIX1 = {"ipv4": "110.0.20.1/32", "ipv6": "20::1/128"}
89 PREFIX2 = {"ipv4": "110.0.20.2/32", "ipv6": "20::2/128"}
90 NEXT_HOP_IP = []
91 topo_diag = """
92 Please view in a fixed-width font such as Courier.
93 +------+ +------+ +------+
94 | +--------------+ +--------------+ |
95 | | | | | |
96 | R1 +---8 links----+ R2 +---8 links----+ R3 |
97 | | | | | |
98 | +--------------+ +--------------+ |
99 +------+ +------+ +------+
100
101 """
102
103
104 def setup_module(mod):
105 """
106
107 Set up the pytest environment.
108
109 * `mod`: module name
110 """
111 testsuite_run_time = time.asctime(time.localtime(time.time()))
112 logger.info("Testsuite start time: {}".format(testsuite_run_time))
113 logger.info("=" * 40)
114
115 logger.info("Running setup_module to create topology")
116
117 # This function initiates the topology build with Topogen...
118 json_file = "{}/static_routes_topo2_ebgp.json".format(CWD)
119 tgen = Topogen(json_file, mod.__name__)
120 global topo
121 topo = tgen.json_topo
122 # ... and here it calls Mininet initialization functions.
123
124 # Starting topology, create tmp files which are loaded to routers
125 # to start daemons and then start routers
126 start_topology(tgen)
127
128 # Creating configuration from JSON
129 build_config_from_json(tgen, topo)
130
131 if version_cmp(platform.release(), "4.19") < 0:
132 error_msg = (
133 'These tests will not run. (have kernel "{}", '
134 "requires kernel >= 4.19)".format(platform.release())
135 )
136 pytest.skip(error_msg)
137
138 # Checking BGP convergence
139 global BGP_CONVERGENCE
140 global ADDR_TYPES
141 # Don't run this test if we have any failure.
142 if tgen.routers_have_failure():
143 pytest.skip(tgen.errors)
144 # Api call verify whether BGP is converged
145 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
146 assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error: {}".format(
147 BGP_CONVERGENCE
148 )
149
150 logger.info("Running setup_module() done")
151
152
153 def teardown_module(mod):
154 """
155 Teardown the pytest environment
156
157 * `mod`: module name
158 """
159
160 logger.info("Running teardown_module to delete topology")
161
162 tgen = get_topogen()
163
164 # Stop toplogy and Remove tmp files
165 tgen.stop_topology()
166
167 logger.info(
168 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
169 )
170 logger.info("=" * 40)
171
172
173 def populate_nh():
174 NEXT_HOP_IP = {
175 "nh1": {
176 "ipv4": topo["routers"]["r1"]["links"]["r2-link0"]["ipv4"].split("/")[0],
177 "ipv6": topo["routers"]["r1"]["links"]["r2-link0"]["ipv6"].split("/")[0],
178 },
179 "nh2": {
180 "ipv4": topo["routers"]["r1"]["links"]["r2-link1"]["ipv4"].split("/")[0],
181 "ipv6": topo["routers"]["r1"]["links"]["r2-link1"]["ipv6"].split("/")[0],
182 },
183 "nh3": {
184 "ipv4": topo["routers"]["r1"]["links"]["r2-link2"]["ipv4"].split("/")[0],
185 "ipv6": topo["routers"]["r1"]["links"]["r2-link2"]["ipv6"].split("/")[0],
186 },
187 "nh4": {
188 "ipv4": topo["routers"]["r1"]["links"]["r2-link3"]["ipv4"].split("/")[0],
189 "ipv6": topo["routers"]["r1"]["links"]["r2-link3"]["ipv6"].split("/")[0],
190 },
191 "nh5": {
192 "ipv4": topo["routers"]["r1"]["links"]["r2-link4"]["ipv4"].split("/")[0],
193 "ipv6": topo["routers"]["r1"]["links"]["r2-link4"]["ipv6"].split("/")[0],
194 },
195 "nh6": {
196 "ipv4": topo["routers"]["r1"]["links"]["r2-link5"]["ipv4"].split("/")[0],
197 "ipv6": topo["routers"]["r1"]["links"]["r2-link5"]["ipv6"].split("/")[0],
198 },
199 "nh7": {
200 "ipv4": topo["routers"]["r1"]["links"]["r2-link6"]["ipv4"].split("/")[0],
201 "ipv6": topo["routers"]["r1"]["links"]["r2-link6"]["ipv6"].split("/")[0],
202 },
203 "nh8": {
204 "ipv4": topo["routers"]["r1"]["links"]["r2-link7"]["ipv4"].split("/")[0],
205 "ipv6": topo["routers"]["r1"]["links"]["r2-link7"]["ipv6"].split("/")[0],
206 },
207 }
208 return NEXT_HOP_IP
209
210
211 #####################################################
212 #
213 # Testcases
214 #
215 #####################################################
216
217
218 def test_static_rte_with_8ecmp_nh_p1_tc9_ebgp(request):
219 """
220 Verify 8 static route functionality with 8 ECMP next hop
221
222 """
223 tc_name = request.node.name
224 write_test_header(tc_name)
225 tgen = get_topogen()
226 # Don't run this test if we have any failure.
227 if tgen.routers_have_failure():
228 pytest.skip(tgen.errors)
229 NEXT_HOP_IP = populate_nh()
230 step("Configure 8 interfaces / links between R1 and R2")
231 step("Configure 8 interfaces / links between R2 and R3")
232 step("Configure 8 IBGP IPv4 peering between R2 and R3 router.")
233 reset_config_on_routers(tgen)
234
235 step(
236 "Configure 8 IPv4 static route in R2 with 8 next hop"
237 "N1(21.1.1.2) , N2(22.1.1.2) , N3(23.1.1.2) , N4(24.1.1.2) ,"
238 "N5(25.1.1.2) , N6(26.1.1.2) , N7(27.1.1.2) , N8(28.1.1.2) ,"
239 "Static route next-hop present on R1"
240 )
241 nh_all = {}
242 for addr_type in ADDR_TYPES:
243 # Enable static routes
244 for nhp in range(1, 9):
245 input_dict_4 = {
246 "r2": {
247 "static_routes": [
248 {
249 "network": PREFIX1[addr_type],
250 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
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 logger.info("Verifying %s routes on r2", addr_type)
261 nh_all[addr_type] = [
262 NEXT_HOP_IP["nh1"][addr_type],
263 NEXT_HOP_IP["nh2"][addr_type],
264 NEXT_HOP_IP["nh3"][addr_type],
265 NEXT_HOP_IP["nh4"][addr_type],
266 NEXT_HOP_IP["nh5"][addr_type],
267 NEXT_HOP_IP["nh6"][addr_type],
268 NEXT_HOP_IP["nh7"][addr_type],
269 NEXT_HOP_IP["nh8"][addr_type],
270 ]
271
272 dut = "r2"
273 protocol = "static"
274 result = verify_rib(
275 tgen,
276 addr_type,
277 dut,
278 input_dict_4,
279 next_hop=nh_all[addr_type],
280 protocol=protocol,
281 )
282 assert (
283 result is True
284 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
285
286 step("Configure redistribute static in BGP on R2 router")
287 for addr_type in ADDR_TYPES:
288 input_dict_2 = {
289 "r2": {
290 "bgp": {
291 "address_family": {
292 addr_type: {
293 "unicast": {"redistribute": [{"redist_type": "static"}]}
294 }
295 }
296 }
297 }
298 }
299 result = create_router_bgp(tgen, topo, input_dict_2)
300 assert result is True, "Testcase {} : Failed \n Error: {}".format(
301 tc_name, result
302 )
303
304 dut = "r3"
305 protocol = "bgp"
306 result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
307 assert (
308 result is True
309 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
310
311 step(
312 "Remove the static route configured with nexthop N1 to N8, one"
313 "by one from running config"
314 )
315 dut = "r2"
316 protocol = "static"
317 step(
318 "After removing the static route with N1 to N8 one by one , "
319 "verify that entry is removed from RIB and FIB of R3 "
320 )
321 for addr_type in ADDR_TYPES:
322 for nhp in range(1, 9):
323 input_dict_4 = {
324 "r2": {
325 "static_routes": [
326 {
327 "network": PREFIX1[addr_type],
328 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
329 "delete": True,
330 }
331 ]
332 }
333 }
334 logger.info("Configure static routes")
335 result = create_static_routes(tgen, input_dict_4)
336 assert result is True, "Testcase {} : Failed \n Error: {}".format(
337 tc_name, result
338 )
339
340 step(
341 "After removing the static route with N1 to N8 one by one , "
342 "verify that entry is removed from RIB and FIB of R3 "
343 )
344 nh = NEXT_HOP_IP["nh" + str(nhp)][addr_type]
345 result = verify_rib(
346 tgen,
347 addr_type,
348 dut,
349 input_dict_4,
350 next_hop=nh,
351 protocol=protocol,
352 expected=False,
353 )
354 assert (
355 result is not True
356 ), "Testcase {} : Failed\nError: routes are still present in RIB".format(
357 tc_name
358 )
359
360 step("Configure the static route with nexthop N1 to N8, one by one")
361 for addr_type in ADDR_TYPES:
362 for nhp in range(1, 9):
363 input_dict_4 = {
364 "r2": {
365 "static_routes": [
366 {
367 "network": PREFIX1[addr_type],
368 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
369 }
370 ]
371 }
372 }
373 logger.info("Configure static routes")
374 result = create_static_routes(tgen, input_dict_4)
375 assert result is True, "Testcase {} : Failed \n Error: {}".format(
376 tc_name, result
377 )
378
379 nh = NEXT_HOP_IP["nh" + str(nhp)][addr_type]
380 result = verify_rib(
381 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol
382 )
383 assert (
384 result is True
385 ), "Testcase {} : Failed\nError: Routes are missing in RIB".format(tc_name)
386
387 protocol = "static"
388 step("Random shut of the nexthop interfaces")
389 randnum = random.randint(0, 7)
390 # Shutdown interface
391 dut = "r2"
392 step(
393 " interface which is about to be shut no shut between r1 and r2 is %s",
394 topo["routers"]["r2"]["links"]["r1-link{}".format(randnum)]["interface"],
395 )
396 intf = topo["routers"]["r2"]["links"]["r1-link{}".format(randnum)]["interface"]
397 shutdown_bringup_interface(tgen, dut, intf, False)
398
399 step("Random no shut of the nexthop interfaces")
400 # Bringup interface
401 shutdown_bringup_interface(tgen, dut, intf, True)
402
403 step(
404 "After random shut/no shut of nexthop , only that "
405 "nexthop deleted/added from all the routes , other nexthop remain "
406 "unchanged"
407 )
408 dut = "r2"
409 protocol = "static"
410 for addr_type in ADDR_TYPES:
411 input_dict_4 = {
412 "r2": {
413 "static_routes": [
414 {
415 "network": PREFIX1[addr_type],
416 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
417 }
418 ]
419 }
420 }
421 result = verify_rib(
422 tgen,
423 addr_type,
424 dut,
425 input_dict_4,
426 next_hop=nh_all[addr_type],
427 protocol=protocol,
428 )
429 assert (
430 result is True
431 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
432
433 step("Remove random static route with all the nexthop")
434 dut = "r2"
435 randnum = random.randint(1, 7)
436 for addr_type in ADDR_TYPES:
437 input_dict_4 = {
438 "r2": {
439 "static_routes": [
440 {
441 "network": PREFIX1[addr_type],
442 "next_hop": NEXT_HOP_IP["nh" + str(randnum)][addr_type],
443 "delete": True,
444 }
445 ]
446 }
447 }
448 logger.info("Configure static routes")
449 result = create_static_routes(tgen, input_dict_4)
450 assert result is True, "Testcase {} : Failed \n Error: {}".format(
451 tc_name, result
452 )
453
454 step(
455 "After delete of random route , that route only got deleted from"
456 " RIB/FIB other route are showing properly"
457 )
458 nh = NEXT_HOP_IP["nh{}".format(randnum)][addr_type]
459 result = verify_rib(
460 tgen,
461 addr_type,
462 dut,
463 input_dict_4,
464 next_hop=nh,
465 protocol=protocol,
466 expected=False,
467 )
468 assert (
469 result is not True
470 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
471
472 for addr_type in ADDR_TYPES:
473 input_dict_4 = {
474 "r2": {
475 "static_routes": [
476 {
477 "network": PREFIX1[addr_type],
478 "next_hop": NEXT_HOP_IP["nh" + str(randnum)][addr_type],
479 }
480 ]
481 }
482 }
483 logger.info("Configure static routes")
484 result = create_static_routes(tgen, input_dict_4)
485 assert result is True, "Testcase {} : Failed \n Error: {}".format(
486 tc_name, result
487 )
488
489 step("Reload the FRR router")
490 # stop/start -> restart FRR router and verify
491 stop_router(tgen, "r2")
492 start_router(tgen, "r2")
493
494 step(
495 "After reload of FRR router , static route "
496 "installed in RIB and FIB properly ."
497 )
498 for addr_type in ADDR_TYPES:
499 # Enable static routes
500 nhp = 1
501 input_dict_4 = {
502 "r2": {
503 "static_routes": [
504 {
505 "network": PREFIX1[addr_type],
506 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
507 }
508 ]
509 }
510 }
511 logger.info("Verifying %s routes on r2", addr_type)
512 dut = "r2"
513 protocol = "static"
514 result = verify_rib(
515 tgen,
516 addr_type,
517 dut,
518 input_dict_4,
519 next_hop=nh_all[addr_type],
520 protocol=protocol,
521 )
522 assert (
523 result is True
524 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
525
526 step("Remove the redistribute static knob")
527 for addr_type in ADDR_TYPES:
528 input_dict_2 = {
529 "r2": {
530 "bgp": {
531 "address_family": {
532 addr_type: {
533 "unicast": {
534 "redistribute": [
535 {"redist_type": "static", "delete": True}
536 ]
537 }
538 }
539 }
540 }
541 }
542 }
543 result = create_router_bgp(tgen, topo, input_dict_2)
544 assert result is True, "Testcase {} : Failed \n Error: {}".format(
545 tc_name, result
546 )
547
548 step(
549 "After removing the BGP neighbor or redistribute static knob , "
550 "verify route got clear from RIB and FIB of R3 routes "
551 )
552 dut = "r3"
553 protocol = "bgp"
554 result = verify_rib(
555 tgen, addr_type, dut, input_dict_4, protocol=protocol, expected=False
556 )
557 assert (
558 result is not True
559 ), "Testcase {} : Failed \nError: Routes are still present in RIB".format(
560 tc_name
561 )
562
563 write_test_footer(tc_name)
564
565
566 def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc6_ebgp(request):
567 """
568 Verify static route functionality with 8 next hop different AD
569 value and BGP ECMP
570
571 """
572 tc_name = request.node.name
573 write_test_header(tc_name)
574 tgen = get_topogen()
575 # Don't run this test if we have any failure.
576 if tgen.routers_have_failure():
577 pytest.skip(tgen.errors)
578
579 step("Configure 8 interfaces / links between R1 and R2 ,")
580 step("Configure 8 interlaces/links between R2 and R3")
581 step(
582 "Configure IBGP IPv4 peering over loopback interface between"
583 "R2 and R3 router."
584 )
585 step("Configure redistribute static in BGP on R2 router")
586 reset_config_on_routers(tgen)
587 NEXT_HOP_IP = populate_nh()
588 nh_all = {}
589 for addr_type in ADDR_TYPES:
590 nh_all[addr_type] = []
591 for nhp in range(1, 9):
592 nh_all[addr_type].append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
593 step(
594 "Configure IPv4 static route in R2 with 8 next hop"
595 "N1(21.1.1.2) AD 10, N2(22.1.1.2) AD 20, N3(23.1.1.2) AD 30,"
596 "N4(24.1.1.2) AD 40, N5(25.1.1.2) AD 50, N6(26.1.1.2) AD 60,"
597 "N7(27.1.1.2) AD 70, N8(28.1.1.2) AD 80, Static route next-hop"
598 "present on R1"
599 )
600 for addr_type in ADDR_TYPES:
601 for nhp in range(1, 9):
602 input_dict_4 = {
603 "r2": {
604 "static_routes": [
605 {
606 "network": PREFIX1[addr_type],
607 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
608 "admin_distance": 10 * nhp,
609 }
610 ]
611 }
612 }
613 logger.info("Configure static routes")
614 result = create_static_routes(tgen, input_dict_4)
615 assert result is True, "Testcase {} : Failed \n Error: {}".format(
616 tc_name, result
617 )
618 logger.info("Verifying %s routes on r2", addr_type)
619
620 step(
621 "On R2, static route installed in RIB using "
622 "show ip route with 8 next hop , lowest AD nexthop is active"
623 )
624 input_dict_4 = {
625 "r2": {
626 "static_routes": [
627 {
628 "network": PREFIX1[addr_type],
629 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
630 "admin_distance": 10,
631 }
632 ]
633 }
634 }
635 dut = "r2"
636 protocol = "static"
637 nh = NEXT_HOP_IP["nh1"][addr_type]
638 result = verify_rib(
639 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol, fib=True
640 )
641 assert (
642 result is True
643 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
644
645 nh = []
646 for nhp in range(2, 9):
647 nh.append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
648 result = verify_rib(
649 tgen,
650 addr_type,
651 dut,
652 input_dict_4,
653 next_hop=nh,
654 protocol=protocol,
655 fib=True,
656 retry_timeout=6,
657 expected=False,
658 )
659 assert (
660 result is not True
661 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
662
663 step(
664 "Remove the static route configured with nexthop N1 to N8, one"
665 "by one from running config"
666 )
667
668 for addr_type in ADDR_TYPES:
669 # delete static routes
670 for nhp in range(1, 9):
671 input_dict_4 = {
672 "r2": {
673 "static_routes": [
674 {
675 "network": PREFIX1[addr_type],
676 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
677 "admin_distance": 10 * nhp,
678 "delete": True,
679 }
680 ]
681 }
682 }
683
684 logger.info("Configure static routes")
685 result = create_static_routes(tgen, input_dict_4)
686 assert result is True, "Testcase {} : Failed \n Error: {}".format(
687 tc_name, result
688 )
689
690 step(
691 "After removing the static route with N1 to N8 one by one , "
692 "route become active with next preferred nexthop and nexthop which "
693 "got removed is not shown in RIB and FIB"
694 )
695 result = verify_rib(
696 tgen,
697 addr_type,
698 dut,
699 input_dict_4,
700 next_hop=nh_all[addr_type],
701 protocol=protocol,
702 expected=False,
703 )
704 assert (
705 result is not True
706 ), "Testcase {} : Failed \nError: Routes are still present in RIB".format(tc_name)
707
708 step("Configure the static route with nexthop N1 to N8, one by one")
709
710 for addr_type in ADDR_TYPES:
711 # add static routes
712 for nhp in range(1, 9):
713 input_dict_4 = {
714 "r2": {
715 "static_routes": [
716 {
717 "network": PREFIX1[addr_type],
718 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
719 "admin_distance": 10 * nhp,
720 }
721 ]
722 }
723 }
724 logger.info("Configure static routes")
725 result = create_static_routes(tgen, input_dict_4)
726 assert result is True, "Testcase {} : Failed \n Error: {}".format(
727 tc_name, result
728 )
729
730 step(
731 " After configuring them, route is always active with lowest AD"
732 " value and all the nexthop populated in RIB and FIB again"
733 )
734 for addr_type in ADDR_TYPES:
735 input_dict_4 = {
736 "r2": {
737 "static_routes": [
738 {
739 "network": PREFIX1[addr_type],
740 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
741 "admin_distance": 10,
742 }
743 ]
744 }
745 }
746 dut = "r2"
747 protocol = "static"
748 nh = NEXT_HOP_IP["nh1"][addr_type]
749 result = verify_rib(
750 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol, fib=True
751 )
752 assert (
753 result is True
754 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
755 nh = []
756 for nhp in range(2, 9):
757 nh.append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
758 result = verify_rib(
759 tgen,
760 addr_type,
761 dut,
762 input_dict_4,
763 next_hop=nh,
764 protocol=protocol,
765 fib=True,
766 expected=False,
767 retry_timeout=6,
768 )
769 assert (
770 result is not True
771 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
772
773 step("Random shut of the nexthop interfaces")
774 randnum = random.randint(0, 7)
775 for addr_type in ADDR_TYPES:
776 intf = topo["routers"]["r2"]["links"]["r1-link" + str(randnum)]["interface"]
777 shutdown_bringup_interface(tgen, dut, intf, False)
778 nhip = NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type]
779 input_dict_5 = {
780 "r2": {
781 "static_routes": [
782 {
783 "network": PREFIX1[addr_type],
784 "next_hop": NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type],
785 }
786 ]
787 }
788 }
789 result = verify_rib(
790 tgen,
791 addr_type,
792 dut,
793 input_dict_5,
794 next_hop=nhip,
795 protocol=protocol,
796 expected=False,
797 )
798 assert (
799 result is not True
800 ), "Testcase {} : Failed \n Error: Routes are still present in RIB".format(
801 tc_name
802 )
803
804 step("Random no shut of the nexthop interfaces")
805 for addr_type in ADDR_TYPES:
806 intf = topo["routers"]["r2"]["links"]["r1-link" + str(randnum)]["interface"]
807 shutdown_bringup_interface(tgen, dut, intf, True)
808 nhip = NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type]
809 result = verify_rib(
810 tgen, addr_type, dut, input_dict_5, next_hop=nhip, protocol=protocol
811 )
812 assert (
813 result is True
814 ), "Testcase {} : Failed \n Error: Routes are missing in RIB".format(tc_name)
815
816 dut = "r2"
817 protocol = "static"
818 for addr_type in ADDR_TYPES:
819 input_dict_4 = {"r2": {"static_routes": [{"network": PREFIX1[addr_type]}]}}
820 result = verify_rib(tgen, addr_type, dut, input_dict_4, protocol=protocol)
821 assert (
822 result is True
823 ), "Testcase {}: Failed \n Error: Routes are missing in RIB".format(tc_name)
824
825 protocol = "bgp"
826 dut = "r3"
827 for addr_type in ADDR_TYPES:
828 input_dict_4 = {"r2": {"static_routes": [{"network": PREFIX1[addr_type]}]}}
829 result = verify_rib(tgen, addr_type, dut, input_dict_4, protocol=protocol)
830 assert (
831 result is True
832 ), "Testcase {}: Failed \n Error: Routes are missing in RIB".format(tc_name)
833
834 step("Reload the FRR router")
835 # stop/start -> restart FRR router and verify
836 stop_router(tgen, "r2")
837
838 start_router(tgen, "r2")
839
840 for addr_type in ADDR_TYPES:
841 input_dict_4 = {"r2": {"static_routes": [{"network": PREFIX1[addr_type]}]}}
842 result = verify_rib(tgen, addr_type, dut, input_dict_4, protocol=protocol)
843 assert (
844 result is True
845 ), "Testcase {} : Failed \n Error: Routes are still present in RIB".format(
846 tc_name
847 )
848
849 write_test_footer(tc_name)
850
851
852 def test_static_route_8nh_diff_AD_ebgp_ecmp_p1_tc8_ebgp(request):
853 """
854 Verify static route with 8 next hop with different AD value and 8
855 EBGP neighbors
856 """
857 tc_name = request.node.name
858 write_test_header(tc_name)
859 tgen = get_topogen()
860 # Don't run this test if we have any failure.
861 if tgen.routers_have_failure():
862 pytest.skip(tgen.errors)
863
864 step("Configure 8 interfaces / links between R1 and R2")
865 step("Configure 8 interlaces/links between R2 and R3")
866 step("Configure 8 EBGP IPv4 peering between R2 and R3")
867
868 reset_config_on_routers(tgen)
869 NEXT_HOP_IP = populate_nh()
870
871 step("Configure redistribute static in BGP on R2 router")
872 for addr_type in ADDR_TYPES:
873 input_dict_2 = {
874 "r2": {
875 "bgp": {
876 "address_family": {
877 addr_type: {
878 "unicast": {"redistribute": [{"redist_type": "static"}]}
879 }
880 }
881 }
882 }
883 }
884 result = create_router_bgp(tgen, topo, input_dict_2)
885 assert result is True, "Testcase {} : Failed \n Error: {}".format(
886 tc_name, result
887 )
888
889 step(
890 "Configure IPv4 static route in R2 with 8 next hop"
891 "N1(21.1.1.2) AD 10, N2(22.1.1.2) AD 20, N3(23.1.1.2) AD 30,"
892 "N4(24.1.1.2) AD 40, N5(25.1.1.2) AD 50, N6(26.1.1.2) AD 60,"
893 "N7(27.1.1.2) AD 70, N8(28.1.1.2) AD 80, Static route next-hop"
894 "present on R1"
895 )
896 nh_all = {}
897 for addr_type in ADDR_TYPES:
898 nh_all[addr_type] = []
899 for nhp in range(1, 9):
900 nh_all[addr_type].append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
901 for addr_type in ADDR_TYPES:
902 for nhp in range(1, 9):
903 input_dict_4 = {
904 "r2": {
905 "static_routes": [
906 {
907 "network": PREFIX1[addr_type],
908 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
909 "admin_distance": 10 * nhp,
910 }
911 ]
912 }
913 }
914 logger.info("Configure static routes")
915 result = create_static_routes(tgen, input_dict_4)
916 assert result is True, "Testcase {} : Failed \n Error: {}".format(
917 tc_name, result
918 )
919 logger.info("Verifying %s routes on r2", addr_type)
920
921 step(
922 "On R2, static route installed in RIB using "
923 "show ip route with 8 next hop , lowest AD nexthop is active"
924 )
925 input_dict_4 = {
926 "r2": {
927 "static_routes": [
928 {
929 "network": PREFIX1[addr_type],
930 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
931 "admin_distance": 10,
932 }
933 ]
934 }
935 }
936 dut = "r2"
937 protocol = "static"
938 nh = NEXT_HOP_IP["nh1"][addr_type]
939 result = verify_rib(
940 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol, fib=True
941 )
942 assert (
943 result is True
944 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
945
946 nh = []
947 for nhp in range(2, 9):
948 nh.append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
949 result = verify_rib(
950 tgen,
951 addr_type,
952 dut,
953 input_dict_4,
954 next_hop=nh,
955 protocol=protocol,
956 fib=True,
957 expected=False,
958 )
959 assert (
960 result is not True
961 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
962
963 step(
964 "Remove the static route configured with nexthop N1 to N8, one"
965 "by one from running config"
966 )
967
968 for addr_type in ADDR_TYPES:
969 # delete static routes
970 for nhp in range(1, 9):
971 input_dict_4 = {
972 "r2": {
973 "static_routes": [
974 {
975 "network": PREFIX1[addr_type],
976 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
977 "admin_distance": 10 * nhp,
978 "delete": True,
979 }
980 ]
981 }
982 }
983
984 logger.info("Configure static routes")
985 result = create_static_routes(tgen, input_dict_4)
986 assert result is True, "Testcase {} : Failed \n Error: {}".format(
987 tc_name, result
988 )
989
990 step(
991 "After removing the static route with N1 to N8 one by one , "
992 "route become active with next preferred nexthop and nexthop which "
993 "got removed is not shown in RIB and FIB"
994 )
995 result = verify_rib(
996 tgen,
997 addr_type,
998 dut,
999 input_dict_4,
1000 next_hop=nh_all[addr_type],
1001 protocol=protocol,
1002 expected=False,
1003 )
1004 assert (
1005 result is not True
1006 ), "Testcase {} : Failed \nError: Routes are still present in RIB".format(tc_name)
1007
1008 step("Configure the static route with nexthop N1 to N8, one by one")
1009
1010 for addr_type in ADDR_TYPES:
1011 # add static routes
1012 for nhp in range(1, 9):
1013 input_dict_4 = {
1014 "r2": {
1015 "static_routes": [
1016 {
1017 "network": PREFIX1[addr_type],
1018 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
1019 "admin_distance": 10 * nhp,
1020 }
1021 ]
1022 }
1023 }
1024 logger.info("Configure static routes")
1025 result = create_static_routes(tgen, input_dict_4)
1026 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1027 tc_name, result
1028 )
1029
1030 step(
1031 " After configuring them, route is always active with lowest AD"
1032 " value and all the nexthop populated in RIB and FIB again"
1033 )
1034 for addr_type in ADDR_TYPES:
1035 input_dict_4 = {
1036 "r2": {
1037 "static_routes": [
1038 {
1039 "network": PREFIX1[addr_type],
1040 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
1041 "admin_distance": 10,
1042 }
1043 ]
1044 }
1045 }
1046 dut = "r2"
1047 protocol = "static"
1048 nh = NEXT_HOP_IP["nh1"][addr_type]
1049 result = verify_rib(
1050 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol, fib=True
1051 )
1052 assert (
1053 result is True
1054 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
1055 nh = []
1056 for nhp in range(2, 9):
1057 nh.append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
1058 result = verify_rib(
1059 tgen,
1060 addr_type,
1061 dut,
1062 input_dict_4,
1063 next_hop=nh,
1064 protocol=protocol,
1065 fib=True,
1066 expected=False,
1067 )
1068 assert (
1069 result is not True
1070 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
1071
1072 step("Random shut of the nexthop interfaces")
1073 randnum = random.randint(0, 7)
1074 for addr_type in ADDR_TYPES:
1075 intf = topo["routers"]["r2"]["links"]["r1-link" + str(randnum)]["interface"]
1076 shutdown_bringup_interface(tgen, dut, intf, False)
1077 nhip = NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type]
1078 input_dict_5 = {
1079 "r2": {
1080 "static_routes": [
1081 {
1082 "network": PREFIX1[addr_type],
1083 "next_hop": NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type],
1084 }
1085 ]
1086 }
1087 }
1088 result = verify_rib(
1089 tgen,
1090 addr_type,
1091 dut,
1092 input_dict_5,
1093 next_hop=nhip,
1094 protocol=protocol,
1095 expected=False,
1096 )
1097 assert (
1098 result is not True
1099 ), "Testcase {} : Failed \n Error: Routes are still present in RIB".format(
1100 tc_name
1101 )
1102
1103 step("Random no shut of the nexthop interfaces")
1104 for addr_type in ADDR_TYPES:
1105 intf = topo["routers"]["r2"]["links"]["r1-link" + str(randnum)]["interface"]
1106 shutdown_bringup_interface(tgen, dut, intf, True)
1107 nhip = NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type]
1108 result = verify_rib(
1109 tgen, addr_type, dut, input_dict_5, next_hop=nhip, protocol=protocol
1110 )
1111 assert (
1112 result is True
1113 ), "Testcase {} : Failed \n Error: Routes are missing in RIB".format(tc_name)
1114
1115 dut = "r2"
1116 protocol = "static"
1117
1118 step("Reload the FRR router")
1119 # stop/start -> restart FRR router and verify
1120 stop_router(tgen, "r2")
1121
1122 start_router(tgen, "r2")
1123
1124 for addr_type in ADDR_TYPES:
1125 input_dict_4 = {"r2": {"static_routes": [{"network": PREFIX1[addr_type]}]}}
1126 result = verify_rib(tgen, addr_type, dut, input_dict_4, protocol=protocol)
1127 assert (
1128 result is True
1129 ), "Testcase {} : Failed \n Error: Routes are still present in RIB".format(
1130 tc_name
1131 )
1132
1133 write_test_footer(tc_name)
1134
1135
1136 def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc10_ebgp(request):
1137 """
1138 Verify 8 static route functionality with 8 next hop different AD'
1139
1140 """
1141 tc_name = request.node.name
1142 write_test_header(tc_name)
1143 tgen = get_topogen()
1144 # Don't run this test if we have any failure.
1145 if tgen.routers_have_failure():
1146 pytest.skip(tgen.errors)
1147 NEXT_HOP_IP = populate_nh()
1148
1149 step("Configure 8 interfaces / links between R1 and R2 ")
1150 step("Configure 8 IBGP IPv4 peering between R2 and R3 router.")
1151 reset_config_on_routers(tgen)
1152
1153 step(
1154 "Configure IPv4 static route in R2 with 8 next hop"
1155 "N1(21.1.1.2) AD 10, N2(22.1.1.2) AD 20, N3(23.1.1.2) AD 30,"
1156 "N4(24.1.1.2) AD 40, N5(25.1.1.2) AD 50, N6(26.1.1.2) AD 60,"
1157 "N7(27.1.1.2) AD 70, N8(28.1.1.2) AD 80"
1158 )
1159 step(
1160 "Configure nexthop AD in such way for static route S1 , N1 is"
1161 "preferred and for S2 , N2 is preferred and so on .."
1162 )
1163 nh_all = {}
1164 for addr_type in ADDR_TYPES:
1165 nh_all[addr_type] = []
1166 for nhp in range(1, 9):
1167 nh_all[addr_type].append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
1168
1169 for addr_type in ADDR_TYPES:
1170 for nhp in range(1, 9):
1171 input_dict_4 = {
1172 "r2": {
1173 "static_routes": [
1174 {
1175 "network": PREFIX1[addr_type],
1176 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
1177 "admin_distance": 10 * nhp,
1178 }
1179 ]
1180 }
1181 }
1182 logger.info("Configure static routes")
1183 result = create_static_routes(tgen, input_dict_4)
1184 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1185 tc_name, result
1186 )
1187 second_rte = {
1188 "r2": {
1189 "static_routes": [
1190 {
1191 "network": PREFIX2[addr_type],
1192 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
1193 "admin_distance": 10 * nhp,
1194 }
1195 ]
1196 }
1197 }
1198 logger.info("Configure static routes")
1199 result = create_static_routes(tgen, second_rte)
1200 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1201 tc_name, result
1202 )
1203 logger.info("Verifying %s routes on r2", addr_type)
1204
1205 step(
1206 "On R2, static route installed in RIB using "
1207 "show ip route with 8 next hop , lowest AD nexthop is active"
1208 )
1209 input_dict_4 = {
1210 "r2": {
1211 "static_routes": [
1212 {
1213 "network": PREFIX1[addr_type],
1214 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
1215 "admin_distance": 10,
1216 }
1217 ]
1218 }
1219 }
1220 dut = "r2"
1221 protocol = "static"
1222 nh = NEXT_HOP_IP["nh1"][addr_type]
1223 result = verify_rib(
1224 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol, fib=True
1225 )
1226 assert (
1227 result is True
1228 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
1229
1230 step("Verify that highest AD nexthop are inactive")
1231 nh = []
1232 for nhp in range(2, 9):
1233 nh.append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
1234 result = verify_rib(
1235 tgen,
1236 addr_type,
1237 dut,
1238 input_dict_4,
1239 next_hop=nh,
1240 protocol=protocol,
1241 fib=True,
1242 expected=False,
1243 retry_timeout=6,
1244 )
1245 assert (
1246 result is not True
1247 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
1248
1249 step("Configure redistribute static in BGP on R2 router")
1250 for addr_type in ADDR_TYPES:
1251 input_dict_2 = {
1252 "r2": {
1253 "bgp": {
1254 "address_family": {
1255 addr_type: {
1256 "unicast": {"redistribute": [{"redist_type": "static"}]}
1257 }
1258 }
1259 }
1260 }
1261 }
1262 result = create_router_bgp(tgen, topo, input_dict_2)
1263 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1264 tc_name, result
1265 )
1266
1267 step(
1268 "Remove the static route configured with nexthop N1 to N8, one"
1269 "by one from running config"
1270 )
1271
1272 for addr_type in ADDR_TYPES:
1273 # delete static routes
1274 for nhp in range(1, 9):
1275 input_dict_4 = {
1276 "r2": {
1277 "static_routes": [
1278 {
1279 "network": PREFIX1[addr_type],
1280 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
1281 "admin_distance": 10 * nhp,
1282 "delete": True,
1283 }
1284 ]
1285 }
1286 }
1287
1288 logger.info("Configure static routes")
1289 result = create_static_routes(tgen, input_dict_4)
1290 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1291 tc_name, result
1292 )
1293
1294 step(
1295 "After removing the static route with N1 to N8 one by one , "
1296 "route become active with next preferred nexthop and nexthop which"
1297 "got removed is not shown in RIB and FIB"
1298 )
1299
1300 result = verify_rib(
1301 tgen,
1302 addr_type,
1303 dut,
1304 input_dict_4,
1305 next_hop=nh,
1306 protocol=protocol,
1307 expected=False,
1308 )
1309 assert (
1310 result is not True
1311 ), "Testcase {} : Failed \nError: Routes are still present in RIB".format(
1312 tc_name
1313 )
1314
1315 step("Configure the static route with nexthop N1 to N8, one by one")
1316 for addr_type in ADDR_TYPES:
1317 # add static routes
1318 for nhp in range(1, 9):
1319 input_dict_4 = {
1320 "r2": {
1321 "static_routes": [
1322 {
1323 "network": PREFIX1[addr_type],
1324 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
1325 "admin_distance": 10 * nhp,
1326 }
1327 ]
1328 }
1329 }
1330
1331 logger.info("Configure static routes")
1332 result = create_static_routes(tgen, input_dict_4)
1333 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1334 tc_name, result
1335 )
1336
1337 step(
1338 " After configuring them, route is always active with lowest AD"
1339 " value and all the nexthop populated in RIB and FIB again"
1340 )
1341 for addr_type in ADDR_TYPES:
1342 input_dict_4 = {"r2": {"static_routes": [{"network": PREFIX1[addr_type]}]}}
1343 nh = NEXT_HOP_IP["nh1"][addr_type]
1344 result = verify_rib(
1345 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol, fib=True
1346 )
1347 assert result is True, (
1348 "Testcase {} : Failed \nError: Route with "
1349 "lowest AD is missing in RIB".format(tc_name)
1350 )
1351
1352 step("Random shut of the nexthop interfaces")
1353 randnum = random.randint(0, 7)
1354 for addr_type in ADDR_TYPES:
1355 intf = topo["routers"]["r2"]["links"]["r1-link" + str(randnum)]["interface"]
1356 shutdown_bringup_interface(tgen, dut, intf, False)
1357 nhip = NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type]
1358 input_dict_5 = {
1359 "r2": {
1360 "static_routes": [
1361 {
1362 "network": PREFIX1[addr_type],
1363 "next_hop": NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type],
1364 }
1365 ]
1366 }
1367 }
1368 result = verify_rib(
1369 tgen,
1370 addr_type,
1371 dut,
1372 input_dict_5,
1373 next_hop=nhip,
1374 protocol=protocol,
1375 expected=False,
1376 )
1377 assert (
1378 result is not True
1379 ), "Testcase {} : Failed \n Error: Routes are still present in RIB".format(
1380 tc_name
1381 )
1382
1383 step("Random no shut of the nexthop interfaces")
1384 for addr_type in ADDR_TYPES:
1385 intf = topo["routers"]["r2"]["links"]["r1-link" + str(randnum)]["interface"]
1386 shutdown_bringup_interface(tgen, dut, intf, True)
1387 nhip = NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type]
1388 result = verify_rib(
1389 tgen, addr_type, dut, input_dict_5, next_hop=nhip, protocol=protocol
1390 )
1391 assert (
1392 result is True
1393 ), "Testcase {} : Failed \n Error: Routes are missing in RIB".format(tc_name)
1394
1395 step("Remove random static route with all the nexthop")
1396 for addr_type in ADDR_TYPES:
1397 # delete static routes
1398 for nhp in range(1, 9):
1399 input_dict_4 = {
1400 "r2": {
1401 "static_routes": [
1402 {
1403 "network": PREFIX1[addr_type],
1404 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
1405 "admin_distance": 10 * nhp,
1406 "delete": True,
1407 }
1408 ]
1409 }
1410 }
1411 logger.info("Configure static routes")
1412 result = create_static_routes(tgen, input_dict_4)
1413 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1414 tc_name, result
1415 )
1416
1417 step(
1418 "After removing the static route with N1 to N8 one by one , "
1419 "route become active with next preferred nexthop and nexthop "
1420 "which got removed is not shown in RIB and FIB"
1421 )
1422 nh = NEXT_HOP_IP["nh" + str(nhp)][addr_type]
1423 result = verify_rib(
1424 tgen,
1425 addr_type,
1426 dut,
1427 input_dict_4,
1428 next_hop=nh,
1429 protocol=protocol,
1430 expected=False,
1431 )
1432 assert result is not True, (
1433 "Testcase {} : Failed \nError: Route "
1434 " is still present in RIB".format(tc_name)
1435 )
1436
1437 step("Reconfigure the deleted routes and verify they are installed")
1438 for nhp in range(1, 9):
1439 input_dict_4 = {
1440 "r2": {
1441 "static_routes": [
1442 {
1443 "network": PREFIX1[addr_type],
1444 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
1445 "admin_distance": 10 * nhp,
1446 }
1447 ]
1448 }
1449 }
1450 logger.info("Configure static routes")
1451 result = create_static_routes(tgen, input_dict_4)
1452 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1453 tc_name, result
1454 )
1455
1456 dut = "r2"
1457 protocol = "static"
1458 nh = NEXT_HOP_IP["nh1"][addr_type]
1459 result = verify_rib(tgen, addr_type, dut, input_dict_4, protocol=protocol)
1460 assert result is True, (
1461 "Testcase {} : Failed \nError: Route "
1462 " is still present in RIB".format(tc_name)
1463 )
1464
1465 step("Reload the FRR router")
1466 # stop/start -> restart FRR router and verify
1467 stop_router(tgen, "r2")
1468
1469 start_router(tgen, "r2")
1470
1471 step("After reloading, verify that routes are still present in R2.")
1472 result = verify_rib(
1473 tgen,
1474 addr_type,
1475 dut,
1476 second_rte,
1477 next_hop=nh,
1478 protocol=protocol,
1479 fib=True,
1480 )
1481 assert (
1482 result is True
1483 ), "Testcase {} : Failed \nError: Route is missing in RIB".format(tc_name)
1484
1485 write_test_footer(tc_name)
1486
1487
1488 def test_static_route_delete_p0_tc11_ebgp(request):
1489 """
1490 Delete the static route and verify the RIB and FIB state
1491 """
1492 tc_name = request.node.name
1493 write_test_header(tc_name)
1494 tgen = get_topogen()
1495 # Don't run this test if we have any failure.
1496 if tgen.routers_have_failure():
1497 pytest.skip(tgen.errors)
1498 NEXT_HOP_IP = populate_nh()
1499
1500 step("Configure 8 interfaces / links between R1 and R2 ")
1501 step("Configure 8 IBGP IPv4 peering between R2 and R3 router.")
1502 reset_config_on_routers(tgen)
1503
1504 step(
1505 "Configure IPv4 static route in R2 with 8 next hop"
1506 "N1(21.1.1.2) AD 10, N2(22.1.1.2) AD 20, N3(23.1.1.2) AD 30,"
1507 "N4(24.1.1.2) AD 40, N5(25.1.1.2) AD 50, N6(26.1.1.2) AD 60,"
1508 "N7(27.1.1.2) AD 70, N8(28.1.1.2) AD 80"
1509 )
1510 step(
1511 "Configure nexthop AD in such way for static route S1 , N1 is"
1512 "preferred and for S2 , N2 is preferred and so on .."
1513 )
1514 nh_all = {}
1515 for addr_type in ADDR_TYPES:
1516 nh_all[addr_type] = []
1517 for nhp in range(1, 9):
1518 nh_all[addr_type].append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
1519
1520 for addr_type in ADDR_TYPES:
1521 for nhp in range(1, 9):
1522 input_dict_4 = {
1523 "r2": {
1524 "static_routes": [
1525 {
1526 "network": PREFIX1[addr_type],
1527 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
1528 "admin_distance": 10 * nhp,
1529 }
1530 ]
1531 }
1532 }
1533 logger.info("Configure static routes")
1534 result = create_static_routes(tgen, input_dict_4)
1535 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1536 tc_name, result
1537 )
1538 second_rte = {
1539 "r2": {
1540 "static_routes": [
1541 {
1542 "network": PREFIX2[addr_type],
1543 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
1544 "admin_distance": 10 * nhp,
1545 }
1546 ]
1547 }
1548 }
1549 logger.info("Configure static routes")
1550 result = create_static_routes(tgen, second_rte)
1551 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1552 tc_name, result
1553 )
1554 logger.info("Verifying %s routes on r2", addr_type)
1555
1556 step(
1557 "On R2, static route installed in RIB using "
1558 "show ip route with 8 next hop , lowest AD nexthop is active"
1559 )
1560 input_dict_4 = {
1561 "r2": {
1562 "static_routes": [
1563 {
1564 "network": PREFIX1[addr_type],
1565 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
1566 "admin_distance": 10,
1567 }
1568 ]
1569 }
1570 }
1571 dut = "r2"
1572 protocol = "static"
1573 nh = NEXT_HOP_IP["nh1"][addr_type]
1574 result = verify_rib(
1575 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol, fib=True
1576 )
1577 assert (
1578 result is True
1579 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
1580
1581 step("Verify that highest AD nexthop are inactive")
1582 nh = []
1583 for nhp in range(2, 9):
1584 nh.append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
1585 result = verify_rib(
1586 tgen,
1587 addr_type,
1588 dut,
1589 input_dict_4,
1590 next_hop=nh,
1591 protocol=protocol,
1592 fib=True,
1593 expected=False,
1594 )
1595 assert (
1596 result is not True
1597 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name)
1598
1599 step("Configure redistribute static in BGP on R2 router")
1600 for addr_type in ADDR_TYPES:
1601 input_dict_2 = {
1602 "r2": {
1603 "bgp": {
1604 "address_family": {
1605 addr_type: {
1606 "unicast": {"redistribute": [{"redist_type": "static"}]}
1607 }
1608 }
1609 }
1610 }
1611 }
1612 result = create_router_bgp(tgen, topo, input_dict_2)
1613 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1614 tc_name, result
1615 )
1616
1617 step("Remove the redistribute static knob")
1618 for addr_type in ADDR_TYPES:
1619 input_dict_2 = {
1620 "r2": {
1621 "bgp": {
1622 "address_family": {
1623 addr_type: {
1624 "unicast": {
1625 "redistribute": [
1626 {"redist_type": "static", "delete": True}
1627 ]
1628 }
1629 }
1630 }
1631 }
1632 }
1633 }
1634 result = create_router_bgp(tgen, topo, input_dict_2)
1635 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1636 tc_name, result
1637 )
1638
1639 step(
1640 "Verify after removing the redistribute static from BGP all the"
1641 "routes got delete from RIB and FIB of R3 "
1642 )
1643
1644 dut = "r3"
1645 protocol = "bgp"
1646 result = verify_rib(
1647 tgen, addr_type, dut, input_dict_4, protocol=protocol, expected=False
1648 )
1649 assert (
1650 result is not True
1651 ), "Testcase {} : Failed \nError: Routes are still present in RIB".format(
1652 tc_name
1653 )
1654
1655 for addr_type in ADDR_TYPES:
1656 for nhp in range(1, 9):
1657 input_dict_4 = {
1658 "r2": {
1659 "static_routes": [
1660 {
1661 "network": PREFIX1[addr_type],
1662 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
1663 "admin_distance": 10 * nhp,
1664 "delete": True,
1665 }
1666 ]
1667 }
1668 }
1669 logger.info("Configure static routes")
1670 result = create_static_routes(tgen, input_dict_4)
1671 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1672 tc_name, result
1673 )
1674 second_rte = {
1675 "r2": {
1676 "static_routes": [
1677 {
1678 "network": PREFIX2[addr_type],
1679 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
1680 "admin_distance": 10 * nhp,
1681 }
1682 ]
1683 }
1684 }
1685 logger.info("Configure static routes")
1686 result = create_static_routes(tgen, second_rte)
1687 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1688 tc_name, result
1689 )
1690 logger.info("Verifying %s routes on r2", addr_type)
1691
1692 step(
1693 " After removing all the routes and nexthop from R2 , "
1694 " verify R2 RIB and FIB is cleared"
1695 )
1696 input_dict_4 = {
1697 "r2": {
1698 "static_routes": [
1699 {
1700 "network": PREFIX1[addr_type],
1701 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
1702 "admin_distance": 10,
1703 }
1704 ]
1705 }
1706 }
1707 dut = "r2"
1708 protocol = "static"
1709 nh = NEXT_HOP_IP["nh1"][addr_type]
1710 result = verify_rib(
1711 tgen,
1712 addr_type,
1713 dut,
1714 input_dict_4,
1715 next_hop=nh,
1716 protocol=protocol,
1717 fib=True,
1718 expected=False,
1719 )
1720 assert (
1721 result is not True
1722 ), "Testcase {} : Failed \nError: Routes are still active in RIB".format(
1723 tc_name
1724 )
1725
1726 write_test_footer(tc_name)
1727
1728
1729 if __name__ == "__main__":
1730 args = ["-s"] + sys.argv[1:]
1731 sys.exit(pytest.main(args))