]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/static_routing_with_ebgp/test_static_routes_topo2_ebgp.py
bgpd: Allow self next-hop if `bgp allow-martian-nexthop` is enabled
[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 is" " 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(
386 tc_name
387 )
388
389 protocol = "static"
390 step("Random shut of the nexthop interfaces")
391 randnum = random.randint(0, 7)
392 # Shutdown interface
393 dut = "r2"
394 step(
395 " interface which is about to be shut no shut between r1 and r2 is " "%s",
396 topo["routers"]["r2"]["links"]["r1-link{}".format(randnum)]["interface"],
397 )
398 intf = topo["routers"]["r2"]["links"]["r1-link{}".format(randnum)]["interface"]
399 shutdown_bringup_interface(tgen, dut, intf, False)
400
401 step("Random no shut of the nexthop interfaces")
402 # Bringup interface
403 shutdown_bringup_interface(tgen, dut, intf, True)
404
405 step(
406 "After random shut/no shut of nexthop , only that "
407 "nexthop deleted/added from all the routes , other nexthop remain "
408 "unchanged"
409 )
410 dut = "r2"
411 protocol = "static"
412 for addr_type in ADDR_TYPES:
413 input_dict_4 = {
414 "r2": {
415 "static_routes": [
416 {
417 "network": PREFIX1[addr_type],
418 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
419 }
420 ]
421 }
422 }
423 result = verify_rib(
424 tgen,
425 addr_type,
426 dut,
427 input_dict_4,
428 next_hop=nh_all[addr_type],
429 protocol=protocol,
430 )
431 assert (
432 result is True
433 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
434
435 step("Remove random static route with all the nexthop")
436 dut = "r2"
437 randnum = random.randint(1, 7)
438 for addr_type in ADDR_TYPES:
439 input_dict_4 = {
440 "r2": {
441 "static_routes": [
442 {
443 "network": PREFIX1[addr_type],
444 "next_hop": NEXT_HOP_IP["nh" + str(randnum)][addr_type],
445 "delete": True,
446 }
447 ]
448 }
449 }
450 logger.info("Configure static routes")
451 result = create_static_routes(tgen, input_dict_4)
452 assert result is True, "Testcase {} : Failed \n Error: {}".format(
453 tc_name, result
454 )
455
456 step(
457 "After delete of random route , that route only got deleted from"
458 " RIB/FIB other route are showing properly"
459 )
460 nh = NEXT_HOP_IP["nh{}".format(randnum)][addr_type]
461 result = verify_rib(
462 tgen,
463 addr_type,
464 dut,
465 input_dict_4,
466 next_hop=nh,
467 protocol=protocol,
468 expected=False,
469 )
470 assert (
471 result is not True
472 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
473
474 for addr_type in ADDR_TYPES:
475 input_dict_4 = {
476 "r2": {
477 "static_routes": [
478 {
479 "network": PREFIX1[addr_type],
480 "next_hop": NEXT_HOP_IP["nh" + str(randnum)][addr_type],
481 }
482 ]
483 }
484 }
485 logger.info("Configure static routes")
486 result = create_static_routes(tgen, input_dict_4)
487 assert result is True, "Testcase {} : Failed \n Error: {}".format(
488 tc_name, result
489 )
490
491 step("Reload the FRR router")
492 # stop/start -> restart FRR router and verify
493 stop_router(tgen, "r2")
494 start_router(tgen, "r2")
495
496 step(
497 "After reload of FRR router , static route "
498 "installed in RIB and FIB properly ."
499 )
500 for addr_type in ADDR_TYPES:
501 # Enable static routes
502 nhp = 1
503 input_dict_4 = {
504 "r2": {
505 "static_routes": [
506 {
507 "network": PREFIX1[addr_type],
508 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
509 }
510 ]
511 }
512 }
513 logger.info("Verifying %s routes on r2", addr_type)
514 dut = "r2"
515 protocol = "static"
516 result = verify_rib(
517 tgen,
518 addr_type,
519 dut,
520 input_dict_4,
521 next_hop=nh_all[addr_type],
522 protocol=protocol,
523 )
524 assert (
525 result is True
526 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
527
528 step("Remove the redistribute static knob")
529 for addr_type in ADDR_TYPES:
530 input_dict_2 = {
531 "r2": {
532 "bgp": {
533 "address_family": {
534 addr_type: {
535 "unicast": {
536 "redistribute": [
537 {"redist_type": "static", "delete": True}
538 ]
539 }
540 }
541 }
542 }
543 }
544 }
545 result = create_router_bgp(tgen, topo, input_dict_2)
546 assert result is True, "Testcase {} : Failed \n Error: {}".format(
547 tc_name, result
548 )
549
550 step(
551 "After removing the BGP neighbor or redistribute static knob , "
552 "verify route got clear from RIB and FIB of R3 routes "
553 )
554 dut = "r3"
555 protocol = "bgp"
556 result = verify_rib(
557 tgen, addr_type, dut, input_dict_4, protocol=protocol, expected=False
558 )
559 assert (
560 result is not True
561 ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
562 tc_name
563 )
564
565 write_test_footer(tc_name)
566
567
568 def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc6_ebgp(request):
569 """
570 Verify static route functionality with 8 next hop different AD
571 value and BGP ECMP
572
573 """
574 tc_name = request.node.name
575 write_test_header(tc_name)
576 tgen = get_topogen()
577 # Don't run this test if we have any failure.
578 if tgen.routers_have_failure():
579 pytest.skip(tgen.errors)
580
581 step("Configure 8 interfaces / links between R1 and R2 ,")
582 step("Configure 8 interlaces/links between R2 and R3")
583 step(
584 "Configure IBGP IPv4 peering over loopback interface between"
585 "R2 and R3 router."
586 )
587 step("Configure redistribute static in BGP on R2 router")
588 reset_config_on_routers(tgen)
589 NEXT_HOP_IP = populate_nh()
590 nh_all = {}
591 for addr_type in ADDR_TYPES:
592 nh_all[addr_type] = []
593 for nhp in range(1, 9):
594 nh_all[addr_type].append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
595 step(
596 "Configure IPv4 static route in R2 with 8 next hop"
597 "N1(21.1.1.2) AD 10, N2(22.1.1.2) AD 20, N3(23.1.1.2) AD 30,"
598 "N4(24.1.1.2) AD 40, N5(25.1.1.2) AD 50, N6(26.1.1.2) AD 60,"
599 "N7(27.1.1.2) AD 70, N8(28.1.1.2) AD 80, Static route next-hop"
600 "present on R1"
601 )
602 for addr_type in ADDR_TYPES:
603 for nhp in range(1, 9):
604 input_dict_4 = {
605 "r2": {
606 "static_routes": [
607 {
608 "network": PREFIX1[addr_type],
609 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
610 "admin_distance": 10 * nhp,
611 }
612 ]
613 }
614 }
615 logger.info("Configure static routes")
616 result = create_static_routes(tgen, input_dict_4)
617 assert result is True, "Testcase {} : Failed \n Error: {}".format(
618 tc_name, result
619 )
620 logger.info("Verifying %s routes on r2", addr_type)
621
622 step(
623 "On R2, static route installed in RIB using "
624 "show ip route with 8 next hop , lowest AD nexthop is active"
625 )
626 input_dict_4 = {
627 "r2": {
628 "static_routes": [
629 {
630 "network": PREFIX1[addr_type],
631 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
632 "admin_distance": 10,
633 }
634 ]
635 }
636 }
637 dut = "r2"
638 protocol = "static"
639 nh = NEXT_HOP_IP["nh1"][addr_type]
640 result = verify_rib(
641 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol, fib=True
642 )
643 assert (
644 result is True
645 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
646
647 nh = []
648 for nhp in range(2, 9):
649 nh.append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
650 result = verify_rib(
651 tgen,
652 addr_type,
653 dut,
654 input_dict_4,
655 next_hop=nh,
656 protocol=protocol,
657 fib=True,
658 retry_timeout=6,
659 expected=False,
660 )
661 assert (
662 result is not True
663 ), "Testcase {} : Failed \nError: Routes " " are missing in RIB".format(tc_name)
664
665 step(
666 "Remove the static route configured with nexthop N1 to N8, one"
667 "by one from running config"
668 )
669
670 for addr_type in ADDR_TYPES:
671 # delete static routes
672 for nhp in range(1, 9):
673 input_dict_4 = {
674 "r2": {
675 "static_routes": [
676 {
677 "network": PREFIX1[addr_type],
678 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
679 "admin_distance": 10 * nhp,
680 "delete": True,
681 }
682 ]
683 }
684 }
685
686 logger.info("Configure static routes")
687 result = create_static_routes(tgen, input_dict_4)
688 assert result is True, "Testcase {} : Failed \n Error: {}".format(
689 tc_name, result
690 )
691
692 step(
693 "After removing the static route with N1 to N8 one by one , "
694 "route become active with next preferred nexthop and nexthop which "
695 "got removed is not shown in RIB and FIB"
696 )
697 result = verify_rib(
698 tgen,
699 addr_type,
700 dut,
701 input_dict_4,
702 next_hop=nh_all[addr_type],
703 protocol=protocol,
704 expected=False,
705 )
706 assert (
707 result is not True
708 ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
709 tc_name
710 )
711
712 step("Configure the static route with nexthop N1 to N8, one by one")
713
714 for addr_type in ADDR_TYPES:
715 # add static routes
716 for nhp in range(1, 9):
717 input_dict_4 = {
718 "r2": {
719 "static_routes": [
720 {
721 "network": PREFIX1[addr_type],
722 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
723 "admin_distance": 10 * nhp,
724 }
725 ]
726 }
727 }
728 logger.info("Configure static routes")
729 result = create_static_routes(tgen, input_dict_4)
730 assert result is True, "Testcase {} : Failed \n Error: {}".format(
731 tc_name, result
732 )
733
734 step(
735 " After configuring them, route is always active with lowest AD"
736 " value and all the nexthop populated in RIB and FIB again"
737 )
738 for addr_type in ADDR_TYPES:
739 input_dict_4 = {
740 "r2": {
741 "static_routes": [
742 {
743 "network": PREFIX1[addr_type],
744 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
745 "admin_distance": 10,
746 }
747 ]
748 }
749 }
750 dut = "r2"
751 protocol = "static"
752 nh = NEXT_HOP_IP["nh1"][addr_type]
753 result = verify_rib(
754 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol, fib=True
755 )
756 assert (
757 result is True
758 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
759 nh = []
760 for nhp in range(2, 9):
761 nh.append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
762 result = verify_rib(
763 tgen,
764 addr_type,
765 dut,
766 input_dict_4,
767 next_hop=nh,
768 protocol=protocol,
769 fib=True,
770 expected=False,
771 retry_timeout=6,
772 )
773 assert (
774 result is not True
775 ), "Testcase {} : Failed \nError: Routes " " are missing in RIB".format(tc_name)
776
777 step("Random shut of the nexthop interfaces")
778 randnum = random.randint(0, 7)
779 for addr_type in ADDR_TYPES:
780 intf = topo["routers"]["r2"]["links"]["r1-link" + str(randnum)]["interface"]
781 shutdown_bringup_interface(tgen, dut, intf, False)
782 nhip = NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type]
783 input_dict_5 = {
784 "r2": {
785 "static_routes": [
786 {
787 "network": PREFIX1[addr_type],
788 "next_hop": NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type],
789 }
790 ]
791 }
792 }
793 result = verify_rib(
794 tgen,
795 addr_type,
796 dut,
797 input_dict_5,
798 next_hop=nhip,
799 protocol=protocol,
800 expected=False,
801 )
802 assert (
803 result is not True
804 ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
805 tc_name
806 )
807
808 step("Random no shut of the nexthop interfaces")
809 for addr_type in ADDR_TYPES:
810 intf = topo["routers"]["r2"]["links"]["r1-link" + str(randnum)]["interface"]
811 shutdown_bringup_interface(tgen, dut, intf, True)
812 nhip = NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type]
813 result = verify_rib(
814 tgen, addr_type, dut, input_dict_5, next_hop=nhip, protocol=protocol
815 )
816 assert (
817 result is True
818 ), "Testcase {} : Failed \n" "Error: Routes are missing in RIB".format(tc_name)
819
820 dut = "r2"
821 protocol = "static"
822 for addr_type in ADDR_TYPES:
823 input_dict_4 = {"r2": {"static_routes": [{"network": PREFIX1[addr_type]}]}}
824 result = verify_rib(tgen, addr_type, dut, input_dict_4, protocol=protocol)
825 assert (
826 result is True
827 ), "Testcase {}: Failed \n " "Error: Routes are missing in RIB".format(tc_name)
828
829 protocol = "bgp"
830 dut = "r3"
831 for addr_type in ADDR_TYPES:
832 input_dict_4 = {"r2": {"static_routes": [{"network": PREFIX1[addr_type]}]}}
833 result = verify_rib(tgen, addr_type, dut, input_dict_4, protocol=protocol)
834 assert (
835 result is True
836 ), "Testcase {}: Failed \n " "Error: Routes are missing in RIB".format(tc_name)
837
838 step("Reload the FRR router")
839 # stop/start -> restart FRR router and verify
840 stop_router(tgen, "r2")
841
842 start_router(tgen, "r2")
843
844 for addr_type in ADDR_TYPES:
845 input_dict_4 = {"r2": {"static_routes": [{"network": PREFIX1[addr_type]}]}}
846 result = verify_rib(tgen, addr_type, dut, input_dict_4, protocol=protocol)
847 assert (
848 result is True
849 ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
850 tc_name
851 )
852
853 write_test_footer(tc_name)
854
855
856 def test_static_route_8nh_diff_AD_ebgp_ecmp_p1_tc8_ebgp(request):
857 """
858 Verify static route with 8 next hop with different AD value and 8
859 EBGP neighbors
860 """
861 tc_name = request.node.name
862 write_test_header(tc_name)
863 tgen = get_topogen()
864 # Don't run this test if we have any failure.
865 if tgen.routers_have_failure():
866 pytest.skip(tgen.errors)
867
868 step("Configure 8 interfaces / links between R1 and R2")
869 step("Configure 8 interlaces/links between R2 and R3")
870 step("Configure 8 EBGP IPv4 peering between R2 and R3")
871
872 reset_config_on_routers(tgen)
873 NEXT_HOP_IP = populate_nh()
874
875 step("Configure redistribute static in BGP on R2 router")
876 for addr_type in ADDR_TYPES:
877 input_dict_2 = {
878 "r2": {
879 "bgp": {
880 "address_family": {
881 addr_type: {
882 "unicast": {"redistribute": [{"redist_type": "static"}]}
883 }
884 }
885 }
886 }
887 }
888 result = create_router_bgp(tgen, topo, input_dict_2)
889 assert result is True, "Testcase {} : Failed \n Error: {}".format(
890 tc_name, result
891 )
892
893 step(
894 "Configure IPv4 static route in R2 with 8 next hop"
895 "N1(21.1.1.2) AD 10, N2(22.1.1.2) AD 20, N3(23.1.1.2) AD 30,"
896 "N4(24.1.1.2) AD 40, N5(25.1.1.2) AD 50, N6(26.1.1.2) AD 60,"
897 "N7(27.1.1.2) AD 70, N8(28.1.1.2) AD 80, Static route next-hop"
898 "present on R1"
899 )
900 nh_all = {}
901 for addr_type in ADDR_TYPES:
902 nh_all[addr_type] = []
903 for nhp in range(1, 9):
904 nh_all[addr_type].append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
905 for addr_type in ADDR_TYPES:
906 for nhp in range(1, 9):
907 input_dict_4 = {
908 "r2": {
909 "static_routes": [
910 {
911 "network": PREFIX1[addr_type],
912 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
913 "admin_distance": 10 * nhp,
914 }
915 ]
916 }
917 }
918 logger.info("Configure static routes")
919 result = create_static_routes(tgen, input_dict_4)
920 assert result is True, "Testcase {} : Failed \n Error: {}".format(
921 tc_name, result
922 )
923 logger.info("Verifying %s routes on r2", addr_type)
924
925 step(
926 "On R2, static route installed in RIB using "
927 "show ip route with 8 next hop , lowest AD nexthop is active"
928 )
929 input_dict_4 = {
930 "r2": {
931 "static_routes": [
932 {
933 "network": PREFIX1[addr_type],
934 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
935 "admin_distance": 10,
936 }
937 ]
938 }
939 }
940 dut = "r2"
941 protocol = "static"
942 nh = NEXT_HOP_IP["nh1"][addr_type]
943 result = verify_rib(
944 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol, fib=True
945 )
946 assert (
947 result is True
948 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
949
950 nh = []
951 for nhp in range(2, 9):
952 nh.append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
953 result = verify_rib(
954 tgen,
955 addr_type,
956 dut,
957 input_dict_4,
958 next_hop=nh,
959 protocol=protocol,
960 fib=True,
961 expected=False,
962 )
963 assert (
964 result is not True
965 ), "Testcase {} : Failed \nError: Routes " " are missing in RIB".format(tc_name)
966
967 step(
968 "Remove the static route configured with nexthop N1 to N8, one"
969 "by one from running config"
970 )
971
972 for addr_type in ADDR_TYPES:
973 # delete static routes
974 for nhp in range(1, 9):
975 input_dict_4 = {
976 "r2": {
977 "static_routes": [
978 {
979 "network": PREFIX1[addr_type],
980 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
981 "admin_distance": 10 * nhp,
982 "delete": True,
983 }
984 ]
985 }
986 }
987
988 logger.info("Configure static routes")
989 result = create_static_routes(tgen, input_dict_4)
990 assert result is True, "Testcase {} : Failed \n Error: {}".format(
991 tc_name, result
992 )
993
994 step(
995 "After removing the static route with N1 to N8 one by one , "
996 "route become active with next preferred nexthop and nexthop which "
997 "got removed is not shown in RIB and FIB"
998 )
999 result = verify_rib(
1000 tgen,
1001 addr_type,
1002 dut,
1003 input_dict_4,
1004 next_hop=nh_all[addr_type],
1005 protocol=protocol,
1006 expected=False,
1007 )
1008 assert (
1009 result is not True
1010 ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
1011 tc_name
1012 )
1013
1014 step("Configure the static route with nexthop N1 to N8, one by one")
1015
1016 for addr_type in ADDR_TYPES:
1017 # add static routes
1018 for nhp in range(1, 9):
1019 input_dict_4 = {
1020 "r2": {
1021 "static_routes": [
1022 {
1023 "network": PREFIX1[addr_type],
1024 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
1025 "admin_distance": 10 * nhp,
1026 }
1027 ]
1028 }
1029 }
1030 logger.info("Configure static routes")
1031 result = create_static_routes(tgen, input_dict_4)
1032 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1033 tc_name, result
1034 )
1035
1036 step(
1037 " After configuring them, route is always active with lowest AD"
1038 " value and all the nexthop populated in RIB and FIB again"
1039 )
1040 for addr_type in ADDR_TYPES:
1041 input_dict_4 = {
1042 "r2": {
1043 "static_routes": [
1044 {
1045 "network": PREFIX1[addr_type],
1046 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
1047 "admin_distance": 10,
1048 }
1049 ]
1050 }
1051 }
1052 dut = "r2"
1053 protocol = "static"
1054 nh = NEXT_HOP_IP["nh1"][addr_type]
1055 result = verify_rib(
1056 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol, fib=True
1057 )
1058 assert (
1059 result is True
1060 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
1061 nh = []
1062 for nhp in range(2, 9):
1063 nh.append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
1064 result = verify_rib(
1065 tgen,
1066 addr_type,
1067 dut,
1068 input_dict_4,
1069 next_hop=nh,
1070 protocol=protocol,
1071 fib=True,
1072 expected=False,
1073 )
1074 assert (
1075 result is not True
1076 ), "Testcase {} : Failed \nError: Routes " " are missing in RIB".format(tc_name)
1077
1078 step("Random shut of the nexthop interfaces")
1079 randnum = random.randint(0, 7)
1080 for addr_type in ADDR_TYPES:
1081 intf = topo["routers"]["r2"]["links"]["r1-link" + str(randnum)]["interface"]
1082 shutdown_bringup_interface(tgen, dut, intf, False)
1083 nhip = NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type]
1084 input_dict_5 = {
1085 "r2": {
1086 "static_routes": [
1087 {
1088 "network": PREFIX1[addr_type],
1089 "next_hop": NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type],
1090 }
1091 ]
1092 }
1093 }
1094 result = verify_rib(
1095 tgen,
1096 addr_type,
1097 dut,
1098 input_dict_5,
1099 next_hop=nhip,
1100 protocol=protocol,
1101 expected=False,
1102 )
1103 assert (
1104 result is not True
1105 ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
1106 tc_name
1107 )
1108
1109 step("Random no shut of the nexthop interfaces")
1110 for addr_type in ADDR_TYPES:
1111 intf = topo["routers"]["r2"]["links"]["r1-link" + str(randnum)]["interface"]
1112 shutdown_bringup_interface(tgen, dut, intf, True)
1113 nhip = NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type]
1114 result = verify_rib(
1115 tgen, addr_type, dut, input_dict_5, next_hop=nhip, protocol=protocol
1116 )
1117 assert (
1118 result is True
1119 ), "Testcase {} : Failed \n" "Error: Routes are missing in RIB".format(tc_name)
1120
1121 dut = "r2"
1122 protocol = "static"
1123
1124 step("Reload the FRR router")
1125 # stop/start -> restart FRR router and verify
1126 stop_router(tgen, "r2")
1127
1128 start_router(tgen, "r2")
1129
1130 for addr_type in ADDR_TYPES:
1131 input_dict_4 = {"r2": {"static_routes": [{"network": PREFIX1[addr_type]}]}}
1132 result = verify_rib(tgen, addr_type, dut, input_dict_4, protocol=protocol)
1133 assert (
1134 result is True
1135 ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
1136 tc_name
1137 )
1138
1139 write_test_footer(tc_name)
1140
1141
1142 def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc10_ebgp(request):
1143 """
1144 Verify 8 static route functionality with 8 next hop different AD'
1145
1146 """
1147 tc_name = request.node.name
1148 write_test_header(tc_name)
1149 tgen = get_topogen()
1150 # Don't run this test if we have any failure.
1151 if tgen.routers_have_failure():
1152 pytest.skip(tgen.errors)
1153 NEXT_HOP_IP = populate_nh()
1154
1155 step("Configure 8 interfaces / links between R1 and R2 ")
1156 step("Configure 8 IBGP IPv4 peering between R2 and R3 router.")
1157 reset_config_on_routers(tgen)
1158
1159 step(
1160 "Configure IPv4 static route in R2 with 8 next hop"
1161 "N1(21.1.1.2) AD 10, N2(22.1.1.2) AD 20, N3(23.1.1.2) AD 30,"
1162 "N4(24.1.1.2) AD 40, N5(25.1.1.2) AD 50, N6(26.1.1.2) AD 60,"
1163 "N7(27.1.1.2) AD 70, N8(28.1.1.2) AD 80"
1164 )
1165 step(
1166 "Configure nexthop AD in such way for static route S1 , N1 is"
1167 "preferred and for S2 , N2 is preferred and so on .."
1168 )
1169 nh_all = {}
1170 for addr_type in ADDR_TYPES:
1171 nh_all[addr_type] = []
1172 for nhp in range(1, 9):
1173 nh_all[addr_type].append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
1174
1175 for addr_type in ADDR_TYPES:
1176 for nhp in range(1, 9):
1177 input_dict_4 = {
1178 "r2": {
1179 "static_routes": [
1180 {
1181 "network": PREFIX1[addr_type],
1182 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
1183 "admin_distance": 10 * nhp,
1184 }
1185 ]
1186 }
1187 }
1188 logger.info("Configure static routes")
1189 result = create_static_routes(tgen, input_dict_4)
1190 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1191 tc_name, result
1192 )
1193 second_rte = {
1194 "r2": {
1195 "static_routes": [
1196 {
1197 "network": PREFIX2[addr_type],
1198 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
1199 "admin_distance": 10 * nhp,
1200 }
1201 ]
1202 }
1203 }
1204 logger.info("Configure static routes")
1205 result = create_static_routes(tgen, second_rte)
1206 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1207 tc_name, result
1208 )
1209 logger.info("Verifying %s routes on r2", addr_type)
1210
1211 step(
1212 "On R2, static route installed in RIB using "
1213 "show ip route with 8 next hop , lowest AD nexthop is active"
1214 )
1215 input_dict_4 = {
1216 "r2": {
1217 "static_routes": [
1218 {
1219 "network": PREFIX1[addr_type],
1220 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
1221 "admin_distance": 10,
1222 }
1223 ]
1224 }
1225 }
1226 dut = "r2"
1227 protocol = "static"
1228 nh = NEXT_HOP_IP["nh1"][addr_type]
1229 result = verify_rib(
1230 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol, fib=True
1231 )
1232 assert (
1233 result is True
1234 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
1235
1236 step("Verify that highest AD nexthop are inactive")
1237 nh = []
1238 for nhp in range(2, 9):
1239 nh.append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
1240 result = verify_rib(
1241 tgen,
1242 addr_type,
1243 dut,
1244 input_dict_4,
1245 next_hop=nh,
1246 protocol=protocol,
1247 fib=True,
1248 expected=False,
1249 retry_timeout=6,
1250 )
1251 assert (
1252 result is not True
1253 ), "Testcase {} : Failed \nError: Routes " " are missing in RIB".format(tc_name)
1254
1255 step("Configure redistribute static in BGP on R2 router")
1256 for addr_type in ADDR_TYPES:
1257 input_dict_2 = {
1258 "r2": {
1259 "bgp": {
1260 "address_family": {
1261 addr_type: {
1262 "unicast": {"redistribute": [{"redist_type": "static"}]}
1263 }
1264 }
1265 }
1266 }
1267 }
1268 result = create_router_bgp(tgen, topo, input_dict_2)
1269 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1270 tc_name, result
1271 )
1272
1273 step(
1274 "Remove the static route configured with nexthop N1 to N8, one"
1275 "by one from running config"
1276 )
1277
1278 for addr_type in ADDR_TYPES:
1279 # delete static routes
1280 for nhp in range(1, 9):
1281 input_dict_4 = {
1282 "r2": {
1283 "static_routes": [
1284 {
1285 "network": PREFIX1[addr_type],
1286 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
1287 "admin_distance": 10 * nhp,
1288 "delete": True,
1289 }
1290 ]
1291 }
1292 }
1293
1294 logger.info("Configure static routes")
1295 result = create_static_routes(tgen, input_dict_4)
1296 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1297 tc_name, result
1298 )
1299
1300 step(
1301 "After removing the static route with N1 to N8 one by one , "
1302 "route become active with next preferred nexthop and nexthop which"
1303 "got removed is not shown in RIB and FIB"
1304 )
1305
1306 result = verify_rib(
1307 tgen,
1308 addr_type,
1309 dut,
1310 input_dict_4,
1311 next_hop=nh,
1312 protocol=protocol,
1313 expected=False,
1314 )
1315 assert (
1316 result is not True
1317 ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
1318 tc_name
1319 )
1320
1321 step("Configure the static route with nexthop N1 to N8, one by one")
1322 for addr_type in ADDR_TYPES:
1323 # add static routes
1324 for nhp in range(1, 9):
1325 input_dict_4 = {
1326 "r2": {
1327 "static_routes": [
1328 {
1329 "network": PREFIX1[addr_type],
1330 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
1331 "admin_distance": 10 * nhp,
1332 }
1333 ]
1334 }
1335 }
1336
1337 logger.info("Configure static routes")
1338 result = create_static_routes(tgen, input_dict_4)
1339 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1340 tc_name, result
1341 )
1342
1343 step(
1344 " After configuring them, route is always active with lowest AD"
1345 " value and all the nexthop populated in RIB and FIB again"
1346 )
1347 for addr_type in ADDR_TYPES:
1348 input_dict_4 = {
1349 "r2": {
1350 "static_routes": [
1351 {
1352 "network": PREFIX1[addr_type],
1353 }
1354 ]
1355 }
1356 }
1357 nh = NEXT_HOP_IP["nh1"][addr_type]
1358 result = verify_rib(
1359 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol, fib=True
1360 )
1361 assert result is True, (
1362 "Testcase {} : Failed \nError: Route with "
1363 "lowest AD is missing in RIB".format(tc_name)
1364 )
1365
1366 step("Random shut of the nexthop interfaces")
1367 randnum = random.randint(0, 7)
1368 for addr_type in ADDR_TYPES:
1369 intf = topo["routers"]["r2"]["links"]["r1-link" + str(randnum)]["interface"]
1370 shutdown_bringup_interface(tgen, dut, intf, False)
1371 nhip = NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type]
1372 input_dict_5 = {
1373 "r2": {
1374 "static_routes": [
1375 {
1376 "network": PREFIX1[addr_type],
1377 "next_hop": NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type],
1378 }
1379 ]
1380 }
1381 }
1382 result = verify_rib(
1383 tgen,
1384 addr_type,
1385 dut,
1386 input_dict_5,
1387 next_hop=nhip,
1388 protocol=protocol,
1389 expected=False,
1390 )
1391 assert (
1392 result is not True
1393 ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
1394 tc_name
1395 )
1396
1397 step("Random no shut of the nexthop interfaces")
1398 for addr_type in ADDR_TYPES:
1399 intf = topo["routers"]["r2"]["links"]["r1-link" + str(randnum)]["interface"]
1400 shutdown_bringup_interface(tgen, dut, intf, True)
1401 nhip = NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type]
1402 result = verify_rib(
1403 tgen, addr_type, dut, input_dict_5, next_hop=nhip, protocol=protocol
1404 )
1405 assert (
1406 result is True
1407 ), "Testcase {} : Failed \n" "Error: Routes are missing in RIB".format(tc_name)
1408
1409 step("Remove random static route with all the nexthop")
1410 for addr_type in ADDR_TYPES:
1411 # delete static routes
1412 for nhp in range(1, 9):
1413 input_dict_4 = {
1414 "r2": {
1415 "static_routes": [
1416 {
1417 "network": PREFIX1[addr_type],
1418 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
1419 "admin_distance": 10 * nhp,
1420 "delete": True,
1421 }
1422 ]
1423 }
1424 }
1425 logger.info("Configure static routes")
1426 result = create_static_routes(tgen, input_dict_4)
1427 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1428 tc_name, result
1429 )
1430
1431 step(
1432 "After removing the static route with N1 to N8 one by one , "
1433 "route become active with next preferred nexthop and nexthop "
1434 "which got removed is not shown in RIB and FIB"
1435 )
1436 nh = NEXT_HOP_IP["nh" + str(nhp)][addr_type]
1437 result = verify_rib(
1438 tgen,
1439 addr_type,
1440 dut,
1441 input_dict_4,
1442 next_hop=nh,
1443 protocol=protocol,
1444 expected=False,
1445 )
1446 assert result is not True, (
1447 "Testcase {} : Failed \nError: Route "
1448 " is still present in RIB".format(tc_name)
1449 )
1450
1451 step("Reconfigure the deleted routes and verify they are installed")
1452 for nhp in range(1, 9):
1453 input_dict_4 = {
1454 "r2": {
1455 "static_routes": [
1456 {
1457 "network": PREFIX1[addr_type],
1458 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
1459 "admin_distance": 10 * nhp,
1460 }
1461 ]
1462 }
1463 }
1464 logger.info("Configure static routes")
1465 result = create_static_routes(tgen, input_dict_4)
1466 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1467 tc_name, result
1468 )
1469
1470 dut = "r2"
1471 protocol = "static"
1472 nh = NEXT_HOP_IP["nh1"][addr_type]
1473 result = verify_rib(tgen, addr_type, dut, input_dict_4, protocol=protocol)
1474 assert result is True, (
1475 "Testcase {} : Failed \nError: Route "
1476 " is still present in RIB".format(tc_name)
1477 )
1478
1479 step("Reload the FRR router")
1480 # stop/start -> restart FRR router and verify
1481 stop_router(tgen, "r2")
1482
1483 start_router(tgen, "r2")
1484
1485 step("After reloading, verify that routes are still present in R2.")
1486 result = verify_rib(
1487 tgen,
1488 addr_type,
1489 dut,
1490 second_rte,
1491 next_hop=nh,
1492 protocol=protocol,
1493 fib=True,
1494 )
1495 assert (
1496 result is True
1497 ), "Testcase {} : Failed \nError: Route " " is missing in RIB".format(
1498 tc_name
1499 )
1500
1501 write_test_footer(tc_name)
1502
1503
1504 def test_static_route_delete_p0_tc11_ebgp(request):
1505 """
1506 Delete the static route and verify the RIB and FIB state
1507 """
1508 tc_name = request.node.name
1509 write_test_header(tc_name)
1510 tgen = get_topogen()
1511 # Don't run this test if we have any failure.
1512 if tgen.routers_have_failure():
1513 pytest.skip(tgen.errors)
1514 NEXT_HOP_IP = populate_nh()
1515
1516 step("Configure 8 interfaces / links between R1 and R2 ")
1517 step("Configure 8 IBGP IPv4 peering between R2 and R3 router.")
1518 reset_config_on_routers(tgen)
1519
1520 step(
1521 "Configure IPv4 static route in R2 with 8 next hop"
1522 "N1(21.1.1.2) AD 10, N2(22.1.1.2) AD 20, N3(23.1.1.2) AD 30,"
1523 "N4(24.1.1.2) AD 40, N5(25.1.1.2) AD 50, N6(26.1.1.2) AD 60,"
1524 "N7(27.1.1.2) AD 70, N8(28.1.1.2) AD 80"
1525 )
1526 step(
1527 "Configure nexthop AD in such way for static route S1 , N1 is"
1528 "preferred and for S2 , N2 is preferred and so on .."
1529 )
1530 nh_all = {}
1531 for addr_type in ADDR_TYPES:
1532 nh_all[addr_type] = []
1533 for nhp in range(1, 9):
1534 nh_all[addr_type].append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
1535
1536 for addr_type in ADDR_TYPES:
1537 for nhp in range(1, 9):
1538 input_dict_4 = {
1539 "r2": {
1540 "static_routes": [
1541 {
1542 "network": PREFIX1[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, input_dict_4)
1551 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1552 tc_name, result
1553 )
1554 second_rte = {
1555 "r2": {
1556 "static_routes": [
1557 {
1558 "network": PREFIX2[addr_type],
1559 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
1560 "admin_distance": 10 * nhp,
1561 }
1562 ]
1563 }
1564 }
1565 logger.info("Configure static routes")
1566 result = create_static_routes(tgen, second_rte)
1567 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1568 tc_name, result
1569 )
1570 logger.info("Verifying %s routes on r2", addr_type)
1571
1572 step(
1573 "On R2, static route installed in RIB using "
1574 "show ip route with 8 next hop , lowest AD nexthop is active"
1575 )
1576 input_dict_4 = {
1577 "r2": {
1578 "static_routes": [
1579 {
1580 "network": PREFIX1[addr_type],
1581 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
1582 "admin_distance": 10,
1583 }
1584 ]
1585 }
1586 }
1587 dut = "r2"
1588 protocol = "static"
1589 nh = NEXT_HOP_IP["nh1"][addr_type]
1590 result = verify_rib(
1591 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol, fib=True
1592 )
1593 assert (
1594 result is True
1595 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
1596
1597 step("Verify that highest AD nexthop are inactive")
1598 nh = []
1599 for nhp in range(2, 9):
1600 nh.append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
1601 result = verify_rib(
1602 tgen,
1603 addr_type,
1604 dut,
1605 input_dict_4,
1606 next_hop=nh,
1607 protocol=protocol,
1608 fib=True,
1609 expected=False,
1610 )
1611 assert (
1612 result is not True
1613 ), "Testcase {} : Failed \nError: Routes " " are missing in RIB".format(tc_name)
1614
1615 step("Configure redistribute static in BGP on R2 router")
1616 for addr_type in ADDR_TYPES:
1617 input_dict_2 = {
1618 "r2": {
1619 "bgp": {
1620 "address_family": {
1621 addr_type: {
1622 "unicast": {"redistribute": [{"redist_type": "static"}]}
1623 }
1624 }
1625 }
1626 }
1627 }
1628 result = create_router_bgp(tgen, topo, input_dict_2)
1629 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1630 tc_name, result
1631 )
1632
1633 step("Remove the redistribute static knob")
1634 for addr_type in ADDR_TYPES:
1635 input_dict_2 = {
1636 "r2": {
1637 "bgp": {
1638 "address_family": {
1639 addr_type: {
1640 "unicast": {
1641 "redistribute": [
1642 {"redist_type": "static", "delete": True}
1643 ]
1644 }
1645 }
1646 }
1647 }
1648 }
1649 }
1650 result = create_router_bgp(tgen, topo, input_dict_2)
1651 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1652 tc_name, result
1653 )
1654
1655 step(
1656 "Verify after removing the redistribute static from BGP all the"
1657 "routes got delete from RIB and FIB of R3 "
1658 )
1659
1660 dut = "r3"
1661 protocol = "bgp"
1662 result = verify_rib(
1663 tgen, addr_type, dut, input_dict_4, protocol=protocol, expected=False
1664 )
1665 assert (
1666 result is not True
1667 ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
1668 tc_name
1669 )
1670
1671 for addr_type in ADDR_TYPES:
1672 for nhp in range(1, 9):
1673 input_dict_4 = {
1674 "r2": {
1675 "static_routes": [
1676 {
1677 "network": PREFIX1[addr_type],
1678 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
1679 "admin_distance": 10 * nhp,
1680 "delete": True,
1681 }
1682 ]
1683 }
1684 }
1685 logger.info("Configure static routes")
1686 result = create_static_routes(tgen, input_dict_4)
1687 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1688 tc_name, result
1689 )
1690 second_rte = {
1691 "r2": {
1692 "static_routes": [
1693 {
1694 "network": PREFIX2[addr_type],
1695 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
1696 "admin_distance": 10 * nhp,
1697 }
1698 ]
1699 }
1700 }
1701 logger.info("Configure static routes")
1702 result = create_static_routes(tgen, second_rte)
1703 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1704 tc_name, result
1705 )
1706 logger.info("Verifying %s routes on r2", addr_type)
1707
1708 step(
1709 " After removing all the routes and nexthop from R2 , "
1710 " verify R2 RIB and FIB is cleared"
1711 )
1712 input_dict_4 = {
1713 "r2": {
1714 "static_routes": [
1715 {
1716 "network": PREFIX1[addr_type],
1717 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
1718 "admin_distance": 10,
1719 }
1720 ]
1721 }
1722 }
1723 dut = "r2"
1724 protocol = "static"
1725 nh = NEXT_HOP_IP["nh1"][addr_type]
1726 result = verify_rib(
1727 tgen,
1728 addr_type,
1729 dut,
1730 input_dict_4,
1731 next_hop=nh,
1732 protocol=protocol,
1733 fib=True,
1734 expected=False,
1735 )
1736 assert (
1737 result is not True
1738 ), "Testcase {} : Failed \nError: Routes are" " still active in RIB".format(
1739 tc_name
1740 )
1741
1742 write_test_footer(tc_name)
1743
1744
1745 if __name__ == "__main__":
1746 args = ["-s"] + sys.argv[1:]
1747 sys.exit(pytest.main(args))