2 # SPDX-License-Identifier: ISC
5 # Copyright (c) 2020 by VMware, Inc. ("VMware")
6 # Used Copyright (c) 2018 by Network Device Education Foundation,
7 # Inc. ("NetDEF") in this file.
12 -Verify static route functionality with 8 next hop different AD value
15 -Verify 8 static route functionality with 8 next hop different AD
17 -Verify static route with 8 next hop with different AD value and 8
20 -Verify static route with 8 next hop with different AD value and 8
23 -Delete the static route and verify the RIB and FIB state
25 -Verify 8 static route functionality with 8 ECMP next hop
33 from lib
.topotest
import version_cmp
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
43 # Import topoJson from lib, to create topology and initial configuration
44 from lib
.common_config
import (
48 reset_config_on_routers
,
53 shutdown_bringup_interface
,
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
61 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.staticd
]
64 BGP_CONVERGENCE
= False
65 ADDR_TYPES
= check_address_types()
88 PREFIX1
= {"ipv4": "110.0.20.1/32", "ipv6": "20::1/128"}
89 PREFIX2
= {"ipv4": "110.0.20.2/32", "ipv6": "20::2/128"}
92 Please view in a fixed-width font such as Courier.
93 +------+ +------+ +------+
94 | +--------------+ +--------------+ |
96 | R1 +---8 links----+ R2 +---8 links----+ R3 |
98 | +--------------+ +--------------+ |
99 +------+ +------+ +------+
104 def setup_module(mod
):
107 Set up the pytest environment.
111 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
112 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
113 logger
.info("=" * 40)
115 logger
.info("Running setup_module to create topology")
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
__)
121 topo
= tgen
.json_topo
122 # ... and here it calls Mininet initialization functions.
124 # Starting topology, create tmp files which are loaded to routers
125 # to start daemons and then start routers
128 # Creating configuration from JSON
129 build_config_from_json(tgen
, topo
)
131 if version_cmp(platform
.release(), "4.19") < 0:
133 'These tests will not run. (have kernel "{}", '
134 "requires kernel >= 4.19)".format(platform
.release())
136 pytest
.skip(error_msg
)
138 # Checking BGP convergence
139 global BGP_CONVERGENCE
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(
150 logger
.info("Running setup_module() done")
153 def teardown_module(mod
):
155 Teardown the pytest environment
160 logger
.info("Running teardown_module to delete topology")
164 # Stop toplogy and Remove tmp files
168 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
170 logger
.info("=" * 40)
176 "ipv4": topo
["routers"]["r1"]["links"]["r2-link0"]["ipv4"].split("/")[0],
177 "ipv6": topo
["routers"]["r1"]["links"]["r2-link0"]["ipv6"].split("/")[0],
180 "ipv4": topo
["routers"]["r1"]["links"]["r2-link1"]["ipv4"].split("/")[0],
181 "ipv6": topo
["routers"]["r1"]["links"]["r2-link1"]["ipv6"].split("/")[0],
184 "ipv4": topo
["routers"]["r1"]["links"]["r2-link2"]["ipv4"].split("/")[0],
185 "ipv6": topo
["routers"]["r1"]["links"]["r2-link2"]["ipv6"].split("/")[0],
188 "ipv4": topo
["routers"]["r1"]["links"]["r2-link3"]["ipv4"].split("/")[0],
189 "ipv6": topo
["routers"]["r1"]["links"]["r2-link3"]["ipv6"].split("/")[0],
192 "ipv4": topo
["routers"]["r1"]["links"]["r2-link4"]["ipv4"].split("/")[0],
193 "ipv6": topo
["routers"]["r1"]["links"]["r2-link4"]["ipv6"].split("/")[0],
196 "ipv4": topo
["routers"]["r1"]["links"]["r2-link5"]["ipv4"].split("/")[0],
197 "ipv6": topo
["routers"]["r1"]["links"]["r2-link5"]["ipv6"].split("/")[0],
200 "ipv4": topo
["routers"]["r1"]["links"]["r2-link6"]["ipv4"].split("/")[0],
201 "ipv6": topo
["routers"]["r1"]["links"]["r2-link6"]["ipv6"].split("/")[0],
204 "ipv4": topo
["routers"]["r1"]["links"]["r2-link7"]["ipv4"].split("/")[0],
205 "ipv6": topo
["routers"]["r1"]["links"]["r2-link7"]["ipv6"].split("/")[0],
211 #####################################################
215 #####################################################
218 def test_static_rte_with_8ecmp_nh_p1_tc9_ebgp(request
):
220 Verify 8 static route functionality with 8 ECMP next hop
223 tc_name
= request
.node
.name
224 write_test_header(tc_name
)
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
)
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"
242 for addr_type
in ADDR_TYPES
:
243 # Enable static routes
244 for nhp
in range(1, 9):
249 "network": PREFIX1
[addr_type
],
250 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
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(
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
],
279 next_hop
=nh_all
[addr_type
],
284 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name
)
286 step("Configure redistribute static in BGP on R2 router")
287 for addr_type
in ADDR_TYPES
:
293 "unicast": {"redistribute": [{"redist_type": "static"}]}
299 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
300 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
306 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict_4
)
309 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name
)
312 "Remove the static route configured with nexthop N1 to N8, one"
313 "by one from running config"
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 "
321 for addr_type
in ADDR_TYPES
:
322 for nhp
in range(1, 9):
327 "network": PREFIX1
[addr_type
],
328 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
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(
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 "
344 nh
= NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
]
356 ), "Testcase {} : Failed\nError: routes are still present in RIB".format(
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):
367 "network": PREFIX1
[addr_type
],
368 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
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(
379 nh
= NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
]
381 tgen
, addr_type
, dut
, input_dict_4
, next_hop
=nh
, protocol
=protocol
385 ), "Testcase {} : Failed\nError: Routes are missing in RIB".format(tc_name
)
388 step("Random shut of the nexthop interfaces")
389 randnum
= random
.randint(0, 7)
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"],
396 intf
= topo
["routers"]["r2"]["links"]["r1-link{}".format(randnum
)]["interface"]
397 shutdown_bringup_interface(tgen
, dut
, intf
, False)
399 step("Random no shut of the nexthop interfaces")
401 shutdown_bringup_interface(tgen
, dut
, intf
, True)
404 "After random shut/no shut of nexthop , only that "
405 "nexthop deleted/added from all the routes , other nexthop remain "
410 for addr_type
in ADDR_TYPES
:
415 "network": PREFIX1
[addr_type
],
416 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
426 next_hop
=nh_all
[addr_type
],
431 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name
)
433 step("Remove random static route with all the nexthop")
435 randnum
= random
.randint(1, 7)
436 for addr_type
in ADDR_TYPES
:
441 "network": PREFIX1
[addr_type
],
442 "next_hop": NEXT_HOP_IP
["nh" + str(randnum
)][addr_type
],
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(
455 "After delete of random route , that route only got deleted from"
456 " RIB/FIB other route are showing properly"
458 nh
= NEXT_HOP_IP
["nh{}".format(randnum
)][addr_type
]
470 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name
)
472 for addr_type
in ADDR_TYPES
:
477 "network": PREFIX1
[addr_type
],
478 "next_hop": NEXT_HOP_IP
["nh" + str(randnum
)][addr_type
],
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(
489 step("Reload the FRR router")
490 # stop/start -> restart FRR router and verify
491 stop_router(tgen
, "r2")
492 start_router(tgen
, "r2")
495 "After reload of FRR router , static route "
496 "installed in RIB and FIB properly ."
498 for addr_type
in ADDR_TYPES
:
499 # Enable static routes
505 "network": PREFIX1
[addr_type
],
506 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
511 logger
.info("Verifying %s routes on r2", addr_type
)
519 next_hop
=nh_all
[addr_type
],
524 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name
)
526 step("Remove the redistribute static knob")
527 for addr_type
in ADDR_TYPES
:
535 {"redist_type": "static", "delete": True}
543 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
544 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
549 "After removing the BGP neighbor or redistribute static knob , "
550 "verify route got clear from RIB and FIB of R3 routes "
555 tgen
, addr_type
, dut
, input_dict_4
, protocol
=protocol
, expected
=False
559 ), "Testcase {} : Failed \nError: Routes are still present in RIB".format(
563 write_test_footer(tc_name
)
566 def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc6_ebgp(request
):
568 Verify static route functionality with 8 next hop different AD
572 tc_name
= request
.node
.name
573 write_test_header(tc_name
)
575 # Don't run this test if we have any failure.
576 if tgen
.routers_have_failure():
577 pytest
.skip(tgen
.errors
)
579 step("Configure 8 interfaces / links between R1 and R2 ,")
580 step("Configure 8 interlaces/links between R2 and R3")
582 "Configure IBGP IPv4 peering over loopback interface between"
585 step("Configure redistribute static in BGP on R2 router")
586 reset_config_on_routers(tgen
)
587 NEXT_HOP_IP
= populate_nh()
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
])
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"
600 for addr_type
in ADDR_TYPES
:
601 for nhp
in range(1, 9):
606 "network": PREFIX1
[addr_type
],
607 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
608 "admin_distance": 10 * nhp
,
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(
618 logger
.info("Verifying %s routes on r2", addr_type
)
621 "On R2, static route installed in RIB using "
622 "show ip route with 8 next hop , lowest AD nexthop is active"
628 "network": PREFIX1
[addr_type
],
629 "next_hop": NEXT_HOP_IP
["nh1"][addr_type
],
630 "admin_distance": 10,
637 nh
= NEXT_HOP_IP
["nh1"][addr_type
]
639 tgen
, addr_type
, dut
, input_dict_4
, next_hop
=nh
, protocol
=protocol
, fib
=True
643 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name
)
646 for nhp
in range(2, 9):
647 nh
.append(NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
])
661 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name
)
664 "Remove the static route configured with nexthop N1 to N8, one"
665 "by one from running config"
668 for addr_type
in ADDR_TYPES
:
669 # delete static routes
670 for nhp
in range(1, 9):
675 "network": PREFIX1
[addr_type
],
676 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
677 "admin_distance": 10 * nhp
,
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(
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"
700 next_hop
=nh_all
[addr_type
],
706 ), "Testcase {} : Failed \nError: Routes are still present in RIB".format(tc_name
)
708 step("Configure the static route with nexthop N1 to N8, one by one")
710 for addr_type
in ADDR_TYPES
:
712 for nhp
in range(1, 9):
717 "network": PREFIX1
[addr_type
],
718 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
719 "admin_distance": 10 * nhp
,
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(
731 " After configuring them, route is always active with lowest AD"
732 " value and all the nexthop populated in RIB and FIB again"
734 for addr_type
in ADDR_TYPES
:
739 "network": PREFIX1
[addr_type
],
740 "next_hop": NEXT_HOP_IP
["nh1"][addr_type
],
741 "admin_distance": 10,
748 nh
= NEXT_HOP_IP
["nh1"][addr_type
]
750 tgen
, addr_type
, dut
, input_dict_4
, next_hop
=nh
, protocol
=protocol
, fib
=True
754 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name
)
756 for nhp
in range(2, 9):
757 nh
.append(NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
])
771 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name
)
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
]
783 "network": PREFIX1
[addr_type
],
784 "next_hop": NEXT_HOP_IP
["nh" + str(randnum
+ 1)][addr_type
],
800 ), "Testcase {} : Failed \n Error: Routes are still present in RIB".format(
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
]
810 tgen
, addr_type
, dut
, input_dict_5
, next_hop
=nhip
, protocol
=protocol
814 ), "Testcase {} : Failed \n Error: Routes are missing in RIB".format(tc_name
)
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
)
823 ), "Testcase {}: Failed \n Error: Routes are missing in RIB".format(tc_name
)
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
)
832 ), "Testcase {}: Failed \n Error: Routes are missing in RIB".format(tc_name
)
834 step("Reload the FRR router")
835 # stop/start -> restart FRR router and verify
836 stop_router(tgen
, "r2")
838 start_router(tgen
, "r2")
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
)
845 ), "Testcase {} : Failed \n Error: Routes are still present in RIB".format(
849 write_test_footer(tc_name
)
852 def test_static_route_8nh_diff_AD_ebgp_ecmp_p1_tc8_ebgp(request
):
854 Verify static route with 8 next hop with different AD value and 8
857 tc_name
= request
.node
.name
858 write_test_header(tc_name
)
860 # Don't run this test if we have any failure.
861 if tgen
.routers_have_failure():
862 pytest
.skip(tgen
.errors
)
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")
868 reset_config_on_routers(tgen
)
869 NEXT_HOP_IP
= populate_nh()
871 step("Configure redistribute static in BGP on R2 router")
872 for addr_type
in ADDR_TYPES
:
878 "unicast": {"redistribute": [{"redist_type": "static"}]}
884 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
885 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
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"
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):
907 "network": PREFIX1
[addr_type
],
908 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
909 "admin_distance": 10 * nhp
,
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(
919 logger
.info("Verifying %s routes on r2", addr_type
)
922 "On R2, static route installed in RIB using "
923 "show ip route with 8 next hop , lowest AD nexthop is active"
929 "network": PREFIX1
[addr_type
],
930 "next_hop": NEXT_HOP_IP
["nh1"][addr_type
],
931 "admin_distance": 10,
938 nh
= NEXT_HOP_IP
["nh1"][addr_type
]
940 tgen
, addr_type
, dut
, input_dict_4
, next_hop
=nh
, protocol
=protocol
, fib
=True
944 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name
)
947 for nhp
in range(2, 9):
948 nh
.append(NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
])
961 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name
)
964 "Remove the static route configured with nexthop N1 to N8, one"
965 "by one from running config"
968 for addr_type
in ADDR_TYPES
:
969 # delete static routes
970 for nhp
in range(1, 9):
975 "network": PREFIX1
[addr_type
],
976 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
977 "admin_distance": 10 * nhp
,
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(
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"
1000 next_hop
=nh_all
[addr_type
],
1006 ), "Testcase {} : Failed \nError: Routes are still present in RIB".format(tc_name
)
1008 step("Configure the static route with nexthop N1 to N8, one by one")
1010 for addr_type
in ADDR_TYPES
:
1012 for nhp
in range(1, 9):
1017 "network": PREFIX1
[addr_type
],
1018 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
1019 "admin_distance": 10 * nhp
,
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(
1031 " After configuring them, route is always active with lowest AD"
1032 " value and all the nexthop populated in RIB and FIB again"
1034 for addr_type
in ADDR_TYPES
:
1039 "network": PREFIX1
[addr_type
],
1040 "next_hop": NEXT_HOP_IP
["nh1"][addr_type
],
1041 "admin_distance": 10,
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
1054 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name
)
1056 for nhp
in range(2, 9):
1057 nh
.append(NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
])
1058 result
= verify_rib(
1070 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name
)
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
]
1082 "network": PREFIX1
[addr_type
],
1083 "next_hop": NEXT_HOP_IP
["nh" + str(randnum
+ 1)][addr_type
],
1088 result
= verify_rib(
1099 ), "Testcase {} : Failed \n Error: Routes are still present in RIB".format(
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
1113 ), "Testcase {} : Failed \n Error: Routes are missing in RIB".format(tc_name
)
1118 step("Reload the FRR router")
1119 # stop/start -> restart FRR router and verify
1120 stop_router(tgen
, "r2")
1122 start_router(tgen
, "r2")
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
)
1129 ), "Testcase {} : Failed \n Error: Routes are still present in RIB".format(
1133 write_test_footer(tc_name
)
1136 def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc10_ebgp(request
):
1138 Verify 8 static route functionality with 8 next hop different AD'
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()
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
)
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"
1160 "Configure nexthop AD in such way for static route S1 , N1 is"
1161 "preferred and for S2 , N2 is preferred and so on .."
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
])
1169 for addr_type
in ADDR_TYPES
:
1170 for nhp
in range(1, 9):
1175 "network": PREFIX1
[addr_type
],
1176 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
1177 "admin_distance": 10 * nhp
,
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(
1191 "network": PREFIX2
[addr_type
],
1192 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
1193 "admin_distance": 10 * nhp
,
1198 logger
.info("Configure static routes")
1199 result
= create_static_routes(tgen
, second_rte
)
1200 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1203 logger
.info("Verifying %s routes on r2", addr_type
)
1206 "On R2, static route installed in RIB using "
1207 "show ip route with 8 next hop , lowest AD nexthop is active"
1213 "network": PREFIX1
[addr_type
],
1214 "next_hop": NEXT_HOP_IP
["nh1"][addr_type
],
1215 "admin_distance": 10,
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
1228 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name
)
1230 step("Verify that highest AD nexthop are inactive")
1232 for nhp
in range(2, 9):
1233 nh
.append(NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
])
1234 result
= verify_rib(
1247 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name
)
1249 step("Configure redistribute static in BGP on R2 router")
1250 for addr_type
in ADDR_TYPES
:
1256 "unicast": {"redistribute": [{"redist_type": "static"}]}
1262 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
1263 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1268 "Remove the static route configured with nexthop N1 to N8, one"
1269 "by one from running config"
1272 for addr_type
in ADDR_TYPES
:
1273 # delete static routes
1274 for nhp
in range(1, 9):
1279 "network": PREFIX1
[addr_type
],
1280 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
1281 "admin_distance": 10 * nhp
,
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(
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"
1300 result
= verify_rib(
1311 ), "Testcase {} : Failed \nError: Routes are still present in RIB".format(
1315 step("Configure the static route with nexthop N1 to N8, one by one")
1316 for addr_type
in ADDR_TYPES
:
1318 for nhp
in range(1, 9):
1323 "network": PREFIX1
[addr_type
],
1324 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
1325 "admin_distance": 10 * nhp
,
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(
1338 " After configuring them, route is always active with lowest AD"
1339 " value and all the nexthop populated in RIB and FIB again"
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
1347 assert result
is True, (
1348 "Testcase {} : Failed \nError: Route with "
1349 "lowest AD is missing in RIB".format(tc_name
)
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
]
1362 "network": PREFIX1
[addr_type
],
1363 "next_hop": NEXT_HOP_IP
["nh" + str(randnum
+ 1)][addr_type
],
1368 result
= verify_rib(
1379 ), "Testcase {} : Failed \n Error: Routes are still present in RIB".format(
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
1393 ), "Testcase {} : Failed \n Error: Routes are missing in RIB".format(tc_name
)
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):
1403 "network": PREFIX1
[addr_type
],
1404 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
1405 "admin_distance": 10 * nhp
,
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(
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"
1422 nh
= NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
]
1423 result
= verify_rib(
1432 assert result
is not True, (
1433 "Testcase {} : Failed \nError: Route "
1434 " is still present in RIB".format(tc_name
)
1437 step("Reconfigure the deleted routes and verify they are installed")
1438 for nhp
in range(1, 9):
1443 "network": PREFIX1
[addr_type
],
1444 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
1445 "admin_distance": 10 * nhp
,
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(
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
)
1465 step("Reload the FRR router")
1466 # stop/start -> restart FRR router and verify
1467 stop_router(tgen
, "r2")
1469 start_router(tgen
, "r2")
1471 step("After reloading, verify that routes are still present in R2.")
1472 result
= verify_rib(
1483 ), "Testcase {} : Failed \nError: Route is missing in RIB".format(tc_name
)
1485 write_test_footer(tc_name
)
1488 def test_static_route_delete_p0_tc11_ebgp(request
):
1490 Delete the static route and verify the RIB and FIB state
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()
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
)
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"
1511 "Configure nexthop AD in such way for static route S1 , N1 is"
1512 "preferred and for S2 , N2 is preferred and so on .."
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
])
1520 for addr_type
in ADDR_TYPES
:
1521 for nhp
in range(1, 9):
1526 "network": PREFIX1
[addr_type
],
1527 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
1528 "admin_distance": 10 * nhp
,
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(
1542 "network": PREFIX2
[addr_type
],
1543 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
1544 "admin_distance": 10 * nhp
,
1549 logger
.info("Configure static routes")
1550 result
= create_static_routes(tgen
, second_rte
)
1551 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1554 logger
.info("Verifying %s routes on r2", addr_type
)
1557 "On R2, static route installed in RIB using "
1558 "show ip route with 8 next hop , lowest AD nexthop is active"
1564 "network": PREFIX1
[addr_type
],
1565 "next_hop": NEXT_HOP_IP
["nh1"][addr_type
],
1566 "admin_distance": 10,
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
1579 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name
)
1581 step("Verify that highest AD nexthop are inactive")
1583 for nhp
in range(2, 9):
1584 nh
.append(NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
])
1585 result
= verify_rib(
1597 ), "Testcase {} : Failed \nError: Routes are missing in RIB".format(tc_name
)
1599 step("Configure redistribute static in BGP on R2 router")
1600 for addr_type
in ADDR_TYPES
:
1606 "unicast": {"redistribute": [{"redist_type": "static"}]}
1612 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
1613 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1617 step("Remove the redistribute static knob")
1618 for addr_type
in ADDR_TYPES
:
1626 {"redist_type": "static", "delete": True}
1634 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
1635 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1640 "Verify after removing the redistribute static from BGP all the"
1641 "routes got delete from RIB and FIB of R3 "
1646 result
= verify_rib(
1647 tgen
, addr_type
, dut
, input_dict_4
, protocol
=protocol
, expected
=False
1651 ), "Testcase {} : Failed \nError: Routes are still present in RIB".format(
1655 for addr_type
in ADDR_TYPES
:
1656 for nhp
in range(1, 9):
1661 "network": PREFIX1
[addr_type
],
1662 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
1663 "admin_distance": 10 * nhp
,
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(
1678 "network": PREFIX2
[addr_type
],
1679 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
1680 "admin_distance": 10 * nhp
,
1685 logger
.info("Configure static routes")
1686 result
= create_static_routes(tgen
, second_rte
)
1687 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1690 logger
.info("Verifying %s routes on r2", addr_type
)
1693 " After removing all the routes and nexthop from R2 , "
1694 " verify R2 RIB and FIB is cleared"
1700 "network": PREFIX1
[addr_type
],
1701 "next_hop": NEXT_HOP_IP
["nh1"][addr_type
],
1702 "admin_distance": 10,
1709 nh
= NEXT_HOP_IP
["nh1"][addr_type
]
1710 result
= verify_rib(
1722 ), "Testcase {} : Failed \nError: Routes are still active in RIB".format(
1726 write_test_footer(tc_name
)
1729 if __name__
== "__main__":
1730 args
= ["-s"] + sys
.argv
[1:]
1731 sys
.exit(pytest
.main(args
))