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 is" " 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(
390 step("Random shut of the nexthop interfaces")
391 randnum
= random
.randint(0, 7)
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"],
398 intf
= topo
["routers"]["r2"]["links"]["r1-link{}".format(randnum
)]["interface"]
399 shutdown_bringup_interface(tgen
, dut
, intf
, False)
401 step("Random no shut of the nexthop interfaces")
403 shutdown_bringup_interface(tgen
, dut
, intf
, True)
406 "After random shut/no shut of nexthop , only that "
407 "nexthop deleted/added from all the routes , other nexthop remain "
412 for addr_type
in ADDR_TYPES
:
417 "network": PREFIX1
[addr_type
],
418 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
428 next_hop
=nh_all
[addr_type
],
433 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name
)
435 step("Remove random static route with all the nexthop")
437 randnum
= random
.randint(1, 7)
438 for addr_type
in ADDR_TYPES
:
443 "network": PREFIX1
[addr_type
],
444 "next_hop": NEXT_HOP_IP
["nh" + str(randnum
)][addr_type
],
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(
457 "After delete of random route , that route only got deleted from"
458 " RIB/FIB other route are showing properly"
460 nh
= NEXT_HOP_IP
["nh{}".format(randnum
)][addr_type
]
472 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name
)
474 for addr_type
in ADDR_TYPES
:
479 "network": PREFIX1
[addr_type
],
480 "next_hop": NEXT_HOP_IP
["nh" + str(randnum
)][addr_type
],
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(
491 step("Reload the FRR router")
492 # stop/start -> restart FRR router and verify
493 stop_router(tgen
, "r2")
494 start_router(tgen
, "r2")
497 "After reload of FRR router , static route "
498 "installed in RIB and FIB properly ."
500 for addr_type
in ADDR_TYPES
:
501 # Enable static routes
507 "network": PREFIX1
[addr_type
],
508 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
513 logger
.info("Verifying %s routes on r2", addr_type
)
521 next_hop
=nh_all
[addr_type
],
526 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name
)
528 step("Remove the redistribute static knob")
529 for addr_type
in ADDR_TYPES
:
537 {"redist_type": "static", "delete": True}
545 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
546 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
551 "After removing the BGP neighbor or redistribute static knob , "
552 "verify route got clear from RIB and FIB of R3 routes "
557 tgen
, addr_type
, dut
, input_dict_4
, protocol
=protocol
, expected
=False
561 ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
565 write_test_footer(tc_name
)
568 def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc6_ebgp(request
):
570 Verify static route functionality with 8 next hop different AD
574 tc_name
= request
.node
.name
575 write_test_header(tc_name
)
577 # Don't run this test if we have any failure.
578 if tgen
.routers_have_failure():
579 pytest
.skip(tgen
.errors
)
581 step("Configure 8 interfaces / links between R1 and R2 ,")
582 step("Configure 8 interlaces/links between R2 and R3")
584 "Configure IBGP IPv4 peering over loopback interface between"
587 step("Configure redistribute static in BGP on R2 router")
588 reset_config_on_routers(tgen
)
589 NEXT_HOP_IP
= populate_nh()
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
])
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"
602 for addr_type
in ADDR_TYPES
:
603 for nhp
in range(1, 9):
608 "network": PREFIX1
[addr_type
],
609 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
610 "admin_distance": 10 * nhp
,
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(
620 logger
.info("Verifying %s routes on r2", addr_type
)
623 "On R2, static route installed in RIB using "
624 "show ip route with 8 next hop , lowest AD nexthop is active"
630 "network": PREFIX1
[addr_type
],
631 "next_hop": NEXT_HOP_IP
["nh1"][addr_type
],
632 "admin_distance": 10,
639 nh
= NEXT_HOP_IP
["nh1"][addr_type
]
641 tgen
, addr_type
, dut
, input_dict_4
, next_hop
=nh
, protocol
=protocol
, fib
=True
645 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name
)
648 for nhp
in range(2, 9):
649 nh
.append(NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
])
663 ), "Testcase {} : Failed \nError: Routes " " are missing in RIB".format(tc_name
)
666 "Remove the static route configured with nexthop N1 to N8, one"
667 "by one from running config"
670 for addr_type
in ADDR_TYPES
:
671 # delete static routes
672 for nhp
in range(1, 9):
677 "network": PREFIX1
[addr_type
],
678 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
679 "admin_distance": 10 * nhp
,
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(
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"
702 next_hop
=nh_all
[addr_type
],
708 ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
712 step("Configure the static route with nexthop N1 to N8, one by one")
714 for addr_type
in ADDR_TYPES
:
716 for nhp
in range(1, 9):
721 "network": PREFIX1
[addr_type
],
722 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
723 "admin_distance": 10 * nhp
,
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(
735 " After configuring them, route is always active with lowest AD"
736 " value and all the nexthop populated in RIB and FIB again"
738 for addr_type
in ADDR_TYPES
:
743 "network": PREFIX1
[addr_type
],
744 "next_hop": NEXT_HOP_IP
["nh1"][addr_type
],
745 "admin_distance": 10,
752 nh
= NEXT_HOP_IP
["nh1"][addr_type
]
754 tgen
, addr_type
, dut
, input_dict_4
, next_hop
=nh
, protocol
=protocol
, fib
=True
758 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name
)
760 for nhp
in range(2, 9):
761 nh
.append(NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
])
775 ), "Testcase {} : Failed \nError: Routes " " are missing in RIB".format(tc_name
)
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
]
787 "network": PREFIX1
[addr_type
],
788 "next_hop": NEXT_HOP_IP
["nh" + str(randnum
+ 1)][addr_type
],
804 ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
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
]
814 tgen
, addr_type
, dut
, input_dict_5
, next_hop
=nhip
, protocol
=protocol
818 ), "Testcase {} : Failed \n" "Error: Routes are missing in RIB".format(tc_name
)
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
)
827 ), "Testcase {}: Failed \n " "Error: Routes are missing in RIB".format(tc_name
)
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
)
836 ), "Testcase {}: Failed \n " "Error: Routes are missing in RIB".format(tc_name
)
838 step("Reload the FRR router")
839 # stop/start -> restart FRR router and verify
840 stop_router(tgen
, "r2")
842 start_router(tgen
, "r2")
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
)
849 ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
853 write_test_footer(tc_name
)
856 def test_static_route_8nh_diff_AD_ebgp_ecmp_p1_tc8_ebgp(request
):
858 Verify static route with 8 next hop with different AD value and 8
861 tc_name
= request
.node
.name
862 write_test_header(tc_name
)
864 # Don't run this test if we have any failure.
865 if tgen
.routers_have_failure():
866 pytest
.skip(tgen
.errors
)
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")
872 reset_config_on_routers(tgen
)
873 NEXT_HOP_IP
= populate_nh()
875 step("Configure redistribute static in BGP on R2 router")
876 for addr_type
in ADDR_TYPES
:
882 "unicast": {"redistribute": [{"redist_type": "static"}]}
888 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
889 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
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"
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):
911 "network": PREFIX1
[addr_type
],
912 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
913 "admin_distance": 10 * nhp
,
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(
923 logger
.info("Verifying %s routes on r2", addr_type
)
926 "On R2, static route installed in RIB using "
927 "show ip route with 8 next hop , lowest AD nexthop is active"
933 "network": PREFIX1
[addr_type
],
934 "next_hop": NEXT_HOP_IP
["nh1"][addr_type
],
935 "admin_distance": 10,
942 nh
= NEXT_HOP_IP
["nh1"][addr_type
]
944 tgen
, addr_type
, dut
, input_dict_4
, next_hop
=nh
, protocol
=protocol
, fib
=True
948 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name
)
951 for nhp
in range(2, 9):
952 nh
.append(NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
])
965 ), "Testcase {} : Failed \nError: Routes " " are missing in RIB".format(tc_name
)
968 "Remove the static route configured with nexthop N1 to N8, one"
969 "by one from running config"
972 for addr_type
in ADDR_TYPES
:
973 # delete static routes
974 for nhp
in range(1, 9):
979 "network": PREFIX1
[addr_type
],
980 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
981 "admin_distance": 10 * nhp
,
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(
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"
1004 next_hop
=nh_all
[addr_type
],
1010 ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
1014 step("Configure the static route with nexthop N1 to N8, one by one")
1016 for addr_type
in ADDR_TYPES
:
1018 for nhp
in range(1, 9):
1023 "network": PREFIX1
[addr_type
],
1024 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
1025 "admin_distance": 10 * nhp
,
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(
1037 " After configuring them, route is always active with lowest AD"
1038 " value and all the nexthop populated in RIB and FIB again"
1040 for addr_type
in ADDR_TYPES
:
1045 "network": PREFIX1
[addr_type
],
1046 "next_hop": NEXT_HOP_IP
["nh1"][addr_type
],
1047 "admin_distance": 10,
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
1060 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name
)
1062 for nhp
in range(2, 9):
1063 nh
.append(NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
])
1064 result
= verify_rib(
1076 ), "Testcase {} : Failed \nError: Routes " " are missing in RIB".format(tc_name
)
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
]
1088 "network": PREFIX1
[addr_type
],
1089 "next_hop": NEXT_HOP_IP
["nh" + str(randnum
+ 1)][addr_type
],
1094 result
= verify_rib(
1105 ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
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
1119 ), "Testcase {} : Failed \n" "Error: Routes are missing in RIB".format(tc_name
)
1124 step("Reload the FRR router")
1125 # stop/start -> restart FRR router and verify
1126 stop_router(tgen
, "r2")
1128 start_router(tgen
, "r2")
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
)
1135 ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
1139 write_test_footer(tc_name
)
1142 def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc10_ebgp(request
):
1144 Verify 8 static route functionality with 8 next hop different AD'
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()
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
)
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"
1166 "Configure nexthop AD in such way for static route S1 , N1 is"
1167 "preferred and for S2 , N2 is preferred and so on .."
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
])
1175 for addr_type
in ADDR_TYPES
:
1176 for nhp
in range(1, 9):
1181 "network": PREFIX1
[addr_type
],
1182 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
1183 "admin_distance": 10 * nhp
,
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(
1197 "network": PREFIX2
[addr_type
],
1198 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
1199 "admin_distance": 10 * nhp
,
1204 logger
.info("Configure static routes")
1205 result
= create_static_routes(tgen
, second_rte
)
1206 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1209 logger
.info("Verifying %s routes on r2", addr_type
)
1212 "On R2, static route installed in RIB using "
1213 "show ip route with 8 next hop , lowest AD nexthop is active"
1219 "network": PREFIX1
[addr_type
],
1220 "next_hop": NEXT_HOP_IP
["nh1"][addr_type
],
1221 "admin_distance": 10,
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
1234 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name
)
1236 step("Verify that highest AD nexthop are inactive")
1238 for nhp
in range(2, 9):
1239 nh
.append(NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
])
1240 result
= verify_rib(
1253 ), "Testcase {} : Failed \nError: Routes " " are missing in RIB".format(tc_name
)
1255 step("Configure redistribute static in BGP on R2 router")
1256 for addr_type
in ADDR_TYPES
:
1262 "unicast": {"redistribute": [{"redist_type": "static"}]}
1268 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
1269 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1274 "Remove the static route configured with nexthop N1 to N8, one"
1275 "by one from running config"
1278 for addr_type
in ADDR_TYPES
:
1279 # delete static routes
1280 for nhp
in range(1, 9):
1285 "network": PREFIX1
[addr_type
],
1286 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
1287 "admin_distance": 10 * nhp
,
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(
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"
1306 result
= verify_rib(
1317 ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
1321 step("Configure the static route with nexthop N1 to N8, one by one")
1322 for addr_type
in ADDR_TYPES
:
1324 for nhp
in range(1, 9):
1329 "network": PREFIX1
[addr_type
],
1330 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
1331 "admin_distance": 10 * nhp
,
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(
1344 " After configuring them, route is always active with lowest AD"
1345 " value and all the nexthop populated in RIB and FIB again"
1347 for addr_type
in ADDR_TYPES
:
1352 "network": PREFIX1
[addr_type
],
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
1361 assert result
is True, (
1362 "Testcase {} : Failed \nError: Route with "
1363 "lowest AD is missing in RIB".format(tc_name
)
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
]
1376 "network": PREFIX1
[addr_type
],
1377 "next_hop": NEXT_HOP_IP
["nh" + str(randnum
+ 1)][addr_type
],
1382 result
= verify_rib(
1393 ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
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
1407 ), "Testcase {} : Failed \n" "Error: Routes are missing in RIB".format(tc_name
)
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):
1417 "network": PREFIX1
[addr_type
],
1418 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
1419 "admin_distance": 10 * nhp
,
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(
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"
1436 nh
= NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
]
1437 result
= verify_rib(
1446 assert result
is not True, (
1447 "Testcase {} : Failed \nError: Route "
1448 " is still present in RIB".format(tc_name
)
1451 step("Reconfigure the deleted routes and verify they are installed")
1452 for nhp
in range(1, 9):
1457 "network": PREFIX1
[addr_type
],
1458 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
1459 "admin_distance": 10 * nhp
,
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(
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
)
1479 step("Reload the FRR router")
1480 # stop/start -> restart FRR router and verify
1481 stop_router(tgen
, "r2")
1483 start_router(tgen
, "r2")
1485 step("After reloading, verify that routes are still present in R2.")
1486 result
= verify_rib(
1497 ), "Testcase {} : Failed \nError: Route " " is missing in RIB".format(
1501 write_test_footer(tc_name
)
1504 def test_static_route_delete_p0_tc11_ebgp(request
):
1506 Delete the static route and verify the RIB and FIB state
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()
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
)
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"
1527 "Configure nexthop AD in such way for static route S1 , N1 is"
1528 "preferred and for S2 , N2 is preferred and so on .."
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
])
1536 for addr_type
in ADDR_TYPES
:
1537 for nhp
in range(1, 9):
1542 "network": PREFIX1
[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
, input_dict_4
)
1551 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1558 "network": PREFIX2
[addr_type
],
1559 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
1560 "admin_distance": 10 * nhp
,
1565 logger
.info("Configure static routes")
1566 result
= create_static_routes(tgen
, second_rte
)
1567 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1570 logger
.info("Verifying %s routes on r2", addr_type
)
1573 "On R2, static route installed in RIB using "
1574 "show ip route with 8 next hop , lowest AD nexthop is active"
1580 "network": PREFIX1
[addr_type
],
1581 "next_hop": NEXT_HOP_IP
["nh1"][addr_type
],
1582 "admin_distance": 10,
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
1595 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name
)
1597 step("Verify that highest AD nexthop are inactive")
1599 for nhp
in range(2, 9):
1600 nh
.append(NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
])
1601 result
= verify_rib(
1613 ), "Testcase {} : Failed \nError: Routes " " are missing in RIB".format(tc_name
)
1615 step("Configure redistribute static in BGP on R2 router")
1616 for addr_type
in ADDR_TYPES
:
1622 "unicast": {"redistribute": [{"redist_type": "static"}]}
1628 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
1629 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1633 step("Remove the redistribute static knob")
1634 for addr_type
in ADDR_TYPES
:
1642 {"redist_type": "static", "delete": True}
1650 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
1651 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1656 "Verify after removing the redistribute static from BGP all the"
1657 "routes got delete from RIB and FIB of R3 "
1662 result
= verify_rib(
1663 tgen
, addr_type
, dut
, input_dict_4
, protocol
=protocol
, expected
=False
1667 ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
1671 for addr_type
in ADDR_TYPES
:
1672 for nhp
in range(1, 9):
1677 "network": PREFIX1
[addr_type
],
1678 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
1679 "admin_distance": 10 * nhp
,
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(
1694 "network": PREFIX2
[addr_type
],
1695 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
1696 "admin_distance": 10 * nhp
,
1701 logger
.info("Configure static routes")
1702 result
= create_static_routes(tgen
, second_rte
)
1703 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1706 logger
.info("Verifying %s routes on r2", addr_type
)
1709 " After removing all the routes and nexthop from R2 , "
1710 " verify R2 RIB and FIB is cleared"
1716 "network": PREFIX1
[addr_type
],
1717 "next_hop": NEXT_HOP_IP
["nh1"][addr_type
],
1718 "admin_distance": 10,
1725 nh
= NEXT_HOP_IP
["nh1"][addr_type
]
1726 result
= verify_rib(
1738 ), "Testcase {} : Failed \nError: Routes are" " still active in RIB".format(
1742 write_test_footer(tc_name
)
1745 if __name__
== "__main__":
1746 args
= ["-s"] + sys
.argv
[1:]
1747 sys
.exit(pytest
.main(args
))