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.
10 -Verify static route ECMP functionality with 8 next hop
12 -Verify static route functionality with 8 next hop different AD value
14 -Verify static route with tag option
16 -Verify BGP did not install the static route when it receive route
26 from lib
.topotest
import version_cmp
28 # Save the Current Working Directory to find configuration files.
29 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
30 sys
.path
.append(os
.path
.join(CWD
, "../"))
31 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
32 # pylint: disable=C0413
33 # Import topogen and topotest helpers
34 from lib
.topogen
import Topogen
, get_topogen
36 from lib
.common_config
import (
40 reset_config_on_routers
,
45 shutdown_bringup_interface
,
51 from lib
.topolog
import logger
52 from lib
.bgp
import verify_bgp_convergence
, create_router_bgp
, verify_bgp_rib
53 from lib
.topojson
import build_config_from_json
55 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.staticd
]
58 BGP_CONVERGENCE
= False
59 ADDR_TYPES
= check_address_types()
82 PREFIX1
= {"ipv4": "110.0.20.1/32", "ipv6": "20::1/128"}
83 NETWORK2
= {"ipv4": ["11.0.20.1/32"], "ipv6": ["2::1/128"]}
87 def setup_module(mod
):
90 Set up the pytest environment.
94 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
95 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
98 logger
.info("Running setup_module to create topology")
100 # This function initiates the topology build with Topogen...
101 json_file
= "{}/static_routes_topo3_ebgp.json".format(CWD
)
102 tgen
= Topogen(json_file
, mod
.__name
__)
104 topo
= tgen
.json_topo
105 # ... and here it calls Mininet initialization functions.
107 # Starting topology, create tmp files which are loaded to routers
108 # to start daemons and then start routers
111 # Creating configuration from JSON
112 build_config_from_json(tgen
, topo
)
114 if version_cmp(platform
.release(), "4.19") < 0:
116 'These tests will not run. (have kernel "{}", '
117 "requires kernel >= 4.19)".format(platform
.release())
119 pytest
.skip(error_msg
)
121 # Checking BGP convergence
122 global BGP_CONVERGENCE
125 # Don't run this test if we have any failure.
126 if tgen
.routers_have_failure():
127 pytest
.skip(tgen
.errors
)
128 # Api call verify whether BGP is converged
129 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
130 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
134 logger
.info("Running setup_module() done")
137 def teardown_module(mod
):
139 Teardown the pytest environment
144 logger
.info("Running teardown_module to delete topology")
148 # Stop toplogy and Remove tmp files
152 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
154 logger
.info("=" * 40)
160 "ipv4": topo
["routers"]["r1"]["links"]["r2-link0"]["ipv4"].split("/")[0],
161 "ipv6": topo
["routers"]["r1"]["links"]["r2-link0"]["ipv6"].split("/")[0],
164 "ipv4": topo
["routers"]["r1"]["links"]["r2-link1"]["ipv4"].split("/")[0],
165 "ipv6": topo
["routers"]["r1"]["links"]["r2-link1"]["ipv6"].split("/")[0],
168 "ipv4": topo
["routers"]["r1"]["links"]["r2-link2"]["ipv4"].split("/")[0],
169 "ipv6": topo
["routers"]["r1"]["links"]["r2-link2"]["ipv6"].split("/")[0],
172 "ipv4": topo
["routers"]["r1"]["links"]["r2-link3"]["ipv4"].split("/")[0],
173 "ipv6": topo
["routers"]["r1"]["links"]["r2-link3"]["ipv6"].split("/")[0],
176 "ipv4": topo
["routers"]["r1"]["links"]["r2-link4"]["ipv4"].split("/")[0],
177 "ipv6": topo
["routers"]["r1"]["links"]["r2-link4"]["ipv6"].split("/")[0],
180 "ipv4": topo
["routers"]["r1"]["links"]["r2-link5"]["ipv4"].split("/")[0],
181 "ipv6": topo
["routers"]["r1"]["links"]["r2-link5"]["ipv6"].split("/")[0],
184 "ipv4": topo
["routers"]["r1"]["links"]["r2-link6"]["ipv4"].split("/")[0],
185 "ipv6": topo
["routers"]["r1"]["links"]["r2-link6"]["ipv6"].split("/")[0],
188 "ipv4": topo
["routers"]["r1"]["links"]["r2-link7"]["ipv4"].split("/")[0],
189 "ipv6": topo
["routers"]["r1"]["links"]["r2-link7"]["ipv6"].split("/")[0],
195 #####################################################
199 #####################################################
202 def test_staticroute_with_ecmp_p0_tc3_ebgp(request
):
204 Verify static route ECMP functionality with 8 next hop'
207 tc_name
= request
.node
.name
208 write_test_header(tc_name
)
211 # Don't run this test if we have any failure.
212 if tgen
.routers_have_failure():
213 pytest
.skip(tgen
.errors
)
215 reset_config_on_routers(tgen
)
216 NEXT_HOP_IP
= populate_nh()
218 step("Configure 8 interfaces / links between R1 and R2,")
220 "Configure IPv4 static route in R2 with 8 next hop"
221 "N1(21.1.1.2), N2(22.1.1.2), N3(23.1.1.2), N4(24.1.1.2),"
222 "N5(25.1.1.2), N6(26.1.1.2), N7(27.1.1.2),N8(28.1.1.2), Static"
223 "route next-hop present on R1"
226 step("Configure IBGP IPv4 peering between R2 and R3 router.")
228 for addr_type
in ADDR_TYPES
:
229 # Enable static routes
230 for nhp
in range(1, 9):
235 "network": PREFIX1
[addr_type
],
236 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
241 logger
.info("Configure static routes")
242 result
= create_static_routes(tgen
, input_dict_4
)
243 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
246 logger
.info("Verifying %s routes on r2", addr_type
)
248 NEXT_HOP_IP
["nh1"][addr_type
],
249 NEXT_HOP_IP
["nh2"][addr_type
],
250 NEXT_HOP_IP
["nh3"][addr_type
],
251 NEXT_HOP_IP
["nh4"][addr_type
],
252 NEXT_HOP_IP
["nh5"][addr_type
],
253 NEXT_HOP_IP
["nh6"][addr_type
],
254 NEXT_HOP_IP
["nh7"][addr_type
],
255 NEXT_HOP_IP
["nh8"][addr_type
],
261 tgen
, addr_type
, dut
, input_dict_4
, next_hop
=nh
, protocol
=protocol
265 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name
)
266 step("Configure redistribute static in BGP on R2 router")
267 for addr_type
in ADDR_TYPES
:
273 "unicast": {"redistribute": [{"redist_type": "static"}]}
279 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
280 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
285 "Remove the static route configured with nexthop N1 to N8, one"
286 "by one from running config"
288 for addr_type
in ADDR_TYPES
:
289 # delete static routes
290 for nhp
in range(1, 9):
295 "network": PREFIX1
[addr_type
],
296 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
303 logger
.info("Configure static routes")
304 result
= create_static_routes(tgen
, input_dict_4
)
305 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
320 ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
324 step("Configure the static route with nexthop N1 to N8, one by" "one")
326 for addr_type
in ADDR_TYPES
:
328 for nhp
in range(1, 9):
333 "network": PREFIX1
[addr_type
],
334 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
340 logger
.info("Configure static routes")
341 result
= create_static_routes(tgen
, input_dict_4
)
342 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
347 tgen
, addr_type
, dut
, input_dict_4
, next_hop
=nh
, protocol
=protocol
351 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name
)
353 step("Random shut of the nexthop interfaces")
354 randnum
= random
.randint(0, 7)
355 for addr_type
in ADDR_TYPES
:
356 intf
= topo
["routers"]["r2"]["links"]["r1-link" + str(randnum
)]["interface"]
357 shutdown_bringup_interface(tgen
, dut
, intf
, False)
358 nhip
= NEXT_HOP_IP
["nh" + str(randnum
+ 1)][addr_type
]
363 "network": PREFIX1
[addr_type
],
364 "next_hop": NEXT_HOP_IP
["nh" + str(randnum
+ 1)][addr_type
],
380 ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
384 step("Random no shut of the nexthop interfaces")
385 for addr_type
in ADDR_TYPES
:
386 intf
= topo
["routers"]["r2"]["links"]["r1-link" + str(randnum
)]["interface"]
387 shutdown_bringup_interface(tgen
, dut
, intf
, True)
388 nhip
= NEXT_HOP_IP
["nh" + str(randnum
+ 1)][addr_type
]
390 tgen
, addr_type
, dut
, input_dict_5
, next_hop
=nhip
, protocol
=protocol
394 ), "Testcase {} : Failed \n" "Error: Routes are missing in RIB".format(tc_name
)
396 step("Reload the FRR router")
397 # stop/start -> restart FRR router and verify
398 stop_router(tgen
, "r2")
399 start_router(tgen
, "r2")
402 tgen
, addr_type
, dut
, input_dict_4
, next_hop
=nh
, protocol
=protocol
406 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name
)
408 write_test_footer(tc_name
)
411 def test_staticroute_with_ecmp_with_diff_AD_p0_tc4_ebgp(request
):
413 Verify static route ECMP functionality with 8 next hop
416 tc_name
= request
.node
.name
417 write_test_header(tc_name
)
420 # Don't run this test if we have any failure.
421 if tgen
.routers_have_failure():
422 pytest
.skip(tgen
.errors
)
424 reset_config_on_routers(tgen
)
426 step("Configure 8 interfaces / links between R1 and R2,")
427 step("Configure IBGP IPv4 peering between R2 and R3 router.")
428 NEXT_HOP_IP
= populate_nh()
430 for addr_type
in ADDR_TYPES
:
431 nh_all
[addr_type
] = []
432 for nhp
in range(1, 9):
433 nh_all
[addr_type
].append(NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
])
435 "Configure IPv4 static route in R2 with 8 next hop"
436 "N1(21.1.1.2) AD 10, N2(22.1.1.2) AD 20, N3(23.1.1.2) AD 30,"
437 "N4(24.1.1.2) AD 40, N5(25.1.1.2) AD 50, N6(26.1.1.2) AD 60,"
438 "N7(27.1.1.2) AD 70, N8(28.1.1.2) AD 80, Static route next-hop"
441 for addr_type
in ADDR_TYPES
:
442 for nhp
in range(1, 9):
447 "network": PREFIX1
[addr_type
],
448 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
449 "admin_distance": 10 * nhp
,
454 logger
.info("Configure static routes")
455 result
= create_static_routes(tgen
, input_dict_4
)
456 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
459 logger
.info("Verifying %s routes on r2", addr_type
)
462 "On R2, static route installed in RIB using "
463 "show ip route with 8 next hop, lowest AD nexthop is active"
465 step("On R2, static route with lowest AD nexthop installed in FIB")
470 "network": PREFIX1
[addr_type
],
471 "next_hop": NEXT_HOP_IP
["nh1"][addr_type
],
472 "admin_distance": 10,
479 nh
= NEXT_HOP_IP
["nh1"][addr_type
]
481 tgen
, addr_type
, dut
, input_dict_4
, next_hop
=nh
, protocol
=protocol
, fib
=True
483 assert result
is True, (
484 "Testcase {} : Failed \nError: Route with "
485 " lowest AD is missing in RIB".format(tc_name
)
489 for nhp
in range(2, 9):
490 nh
.append(NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
])
501 assert result
is not True, (
502 "Testcase {} : Failed \nError: Routes "
503 " with high AD are active in RIB".format(tc_name
)
506 step("Configure redistribute static in BGP on R2 router")
507 for addr_type
in ADDR_TYPES
:
513 "unicast": {"redistribute": [{"redist_type": "static"}]}
520 logger
.info("Configuring redistribute static")
521 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
522 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
527 "After configuring them, route is always active with lowest AD"
528 "value and all the nexthop populated in RIB and FIB again "
534 "network": PREFIX1
[addr_type
],
535 "next_hop": NEXT_HOP_IP
["nh1"][addr_type
],
536 "admin_distance": 10,
543 nh
= NEXT_HOP_IP
["nh1"][addr_type
]
545 tgen
, addr_type
, dut
, input_dict_4
, next_hop
=nh
, protocol
=protocol
, fib
=True
547 assert result
is True, (
548 "Testcase {} : Failed \nError: Route with "
549 " lowest AD is missing in RIB".format(tc_name
)
553 "Remove the static route configured with nexthop N1 to N8, one"
554 "by one from running config"
557 for addr_type
in ADDR_TYPES
:
558 # delete static routes
559 for nhp
in range(1, 9):
564 "network": PREFIX1
[addr_type
],
565 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
566 "admin_distance": 10 * nhp
,
573 logger
.info("Configure static routes")
574 result
= create_static_routes(tgen
, input_dict_4
)
575 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
580 "After removing the static route with N1 to N8 one by one, "
581 "route become active with next preferred nexthop and nexthop which "
582 "got removed is not shown in RIB and FIB"
589 next_hop
=nh_all
[addr_type
],
595 ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
599 step("Configure the static route with nexthop N1 to N8, one by" "one")
600 for addr_type
in ADDR_TYPES
:
602 for nhp
in range(1, 9):
607 "network": PREFIX1
[addr_type
],
608 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
609 "admin_distance": 10 * nhp
,
614 logger
.info("Configure static routes")
615 result
= create_static_routes(tgen
, input_dict_4
)
616 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
620 step("On R2, static route with lowest AD nexthop installed in FIB")
625 "network": PREFIX1
[addr_type
],
626 "next_hop": NEXT_HOP_IP
["nh1"][addr_type
],
627 "admin_distance": 10,
634 nh
= NEXT_HOP_IP
["nh1"][addr_type
]
636 tgen
, addr_type
, dut
, input_dict_4
, next_hop
=nh
, protocol
=protocol
, fib
=True
638 assert result
is True, (
639 "Testcase {} : Failed \nError: Route with "
640 " lowest AD is missing in RIB".format(tc_name
)
644 for nhp
in range(2, 9):
645 nh
.append(NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
])
656 assert result
is not True, (
657 "Testcase {} : Failed \nError: Routes "
658 " with high AD are active in RIB".format(tc_name
)
661 step("Random shut of the nexthop interfaces")
662 randnum
= random
.randint(0, 7)
663 for addr_type
in ADDR_TYPES
:
664 intf
= topo
["routers"]["r2"]["links"]["r1-link" + str(randnum
)]["interface"]
665 shutdown_bringup_interface(tgen
, dut
, intf
, False)
666 nhip
= NEXT_HOP_IP
["nh" + str(randnum
+ 1)][addr_type
]
671 "network": PREFIX1
[addr_type
],
672 "next_hop": NEXT_HOP_IP
["nh" + str(randnum
+ 1)][addr_type
],
688 ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
692 step("Random no shut of the nexthop interfaces")
693 for addr_type
in ADDR_TYPES
:
694 intf
= topo
["routers"]["r2"]["links"]["r1-link" + str(randnum
)]["interface"]
695 shutdown_bringup_interface(tgen
, dut
, intf
, True)
696 nhip
= NEXT_HOP_IP
["nh" + str(randnum
+ 1)][addr_type
]
698 tgen
, addr_type
, dut
, input_dict_5
, next_hop
=nhip
, protocol
=protocol
702 ), "Testcase {} : Failed \n" "Error: Routes are missing in RIB".format(tc_name
)
704 step("Reload the FRR router")
705 # stop/start -> restart FRR router and verify
706 stop_router(tgen
, "r2")
707 start_router(tgen
, "r2")
710 "After reload of FRR router, static route installed "
711 "in RIB and FIB properly ."
713 for addr_type
in ADDR_TYPES
:
718 "network": PREFIX1
[addr_type
],
719 "next_hop": NEXT_HOP_IP
["nh1"][addr_type
],
720 "admin_distance": 10,
727 nh
= NEXT_HOP_IP
["nh1"][addr_type
]
729 tgen
, addr_type
, dut
, input_dict_4
, next_hop
=nh
, protocol
=protocol
, fib
=True
731 assert result
is True, (
732 "Testcase {} : Failed \nError: Route with "
733 " lowest AD is missing in RIB".format(tc_name
)
737 for nhp
in range(2, 9):
738 nh
.append(NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
])
749 assert result
is not True, (
750 "Testcase {} : Failed \nError: Routes "
751 " with high AD are active in RIB".format(tc_name
)
754 write_test_footer(tc_name
)
757 def test_bgp_local_nexthop_p1_tc14_ebgp(request
):
759 Verify BGP did not install the static route when it receive route
763 tc_name
= request
.node
.name
764 write_test_header(tc_name
)
767 step("Configure BGP IPv4 session between R2 and R3")
768 step("Configure IPv4 static route on R2")
769 reset_config_on_routers(tgen
)
771 for addr_type
in ADDR_TYPES
:
772 # Enable static routes
777 "network": NETWORK
[addr_type
],
778 "next_hop": topo
["routers"]["r3"]["links"]["r2-link0"][
786 logger
.info("Configure static routes")
787 result
= create_static_routes(tgen
, input_dict_4
)
788 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
792 step("Configure redistribute static in the BGP")
799 "unicast": {"redistribute": [{"redist_type": "static"}]}
805 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
806 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
810 step("Verify R2 BGP table has IPv4 route")
812 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_4
)
815 ), "Testcase {} : Failed \nError: Routes is" " missing in RIB of R2".format(
819 step(" Verify route did not install in the R3 BGP table, RIB/FIB")
821 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict_4
, expected
=False)
822 assert result
is not True, (
823 "Testcase {} : Failed \nError: Routes is"
824 " still present in BGP RIB of R2".format(tc_name
)
827 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_4
, expected
=False)
828 assert result
is not True, (
829 "Testcase {} : Failed \nError: Routes is"
830 " still present in RIB of R2".format(tc_name
)
833 write_test_footer(tc_name
)
836 def test_frr_intf_name_as_gw_gap_tc4_ebgp_p0(request
):
838 Verify static route configure with interface name as gateway'
841 tc_name
= request
.node
.name
842 write_test_header(tc_name
)
845 # Don't run this test if we have any failure.
846 if tgen
.routers_have_failure():
847 pytest
.skip(tgen
.errors
)
849 reset_config_on_routers(tgen
)
852 intf
= topo
["routers"]["r1"]["links"]["r2-link0"]["interface"]
853 nh
= topo
["routers"]["r1"]["links"]["r2-link0"]
855 "ipv4": [(dut
, intf
, ["1.1.1.1/32"], nh
["ipv4"].split("/")[0])],
856 "ipv6": [(dut
, intf
, ["4001::32/128"], nh
["ipv6"].split("/")[0])],
860 "Configure IPv4 and IPv6 static route in FRR with different next"
861 "hop (ens224 as nexthop))"
863 step("ip route 2.2.2.0/24 20.1.1.1 ens224 ----from FRR cli")
864 step("ipv6 route 2000::1/120 5000::1 ens224 ----from FRR cli")
866 for addr_type
in ADDR_TYPES
:
867 # Enable static routes
868 nh
= topo
["routers"]["r2"]["links"]["r1-link0"][addr_type
].split("/")[0]
872 {"network": ip_list
[addr_type
][0][2][0], "next_hop": nh
}
877 logger
.info("Configure static routes")
878 result
= create_static_routes(tgen
, input_dict_4
)
879 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
884 "IPv4 and IPv6 Static route added in FRR verify using "
885 "show ip route , nexthop is resolved using show nht"
889 tgen
, addr_type
, dut
, input_dict_4
, protocol
=protocol
, next_hop
=nh
893 ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name
)
899 "resolvedVia": "connected",
900 "nexthops": {"nexthop1": {"Interfcae": intf
}},
904 result
= verify_ip_nht(tgen
, input_dict_nh
)
907 ), "Testcase {} : Failed \nError: Nexthop is" " missing in RIB".format(tc_name
)
910 "Shut / no shut IPv4 and IPv6 static next hop interface from"
914 shutdown_bringup_interface(tgen
, dut
, intf
, False)
917 "After shut of nexthop interface, IPv4 and IPv6 route got removed "
918 "from RIB verify using show ip route show nht"
931 ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name
)
933 shutdown_bringup_interface(tgen
, dut
, intf
, True)
936 "After no shut route got added again in RIB /FIB using "
937 "show ip route nexthop is resolved using show nht"
939 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_4
, protocol
=protocol
)
940 assert result
is True, "Testcase {} : Failed".format(tc_name
)
942 for addr_type
in ADDR_TYPES
:
943 nh
= topo
["routers"]["r2"]["links"]["r1-link0"][addr_type
].split("/")[0]
948 "network": ip_list
[addr_type
][0][2][0],
956 logger
.info("Configure static routes")
957 result
= create_static_routes(tgen
, input_dict_4
)
958 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
963 "Removing FRR configured static route verify FRR route also "
977 ), "Testcase {} : Failed \nError: Routes" " still present in RIB".format(
981 write_test_footer(tc_name
)
984 def test_static_route_with_tag_p0_tc_13_ebgp(request
):
986 Verify static route with tag option
989 tc_name
= request
.node
.name
990 write_test_header(tc_name
)
993 # Don't run this test if we have any failure.
994 if tgen
.routers_have_failure():
995 pytest
.skip(tgen
.errors
)
997 step("Configure 8 links between R1 and R2")
998 step("Configure 1 links between R2 and R3")
999 NEXT_HOP_IP
= populate_nh()
1002 "Configure 2 IPv4 static route (S1 and S2) in R2 with same"
1003 "next hop N1 28.1.1.2"
1005 step("Configure static route S1 with tag 1 and static route S2 with" "tag2")
1006 step("S1= ip route 10.1.1.1/24 28.1.1.2 tag 1")
1007 step("S2= ip route 20.1.1.1/24 28.1.1.2 tag 2")
1008 step("Enable redistribute static in BGP with route-map")
1009 reset_config_on_routers(tgen
)
1011 for addr_type
in ADDR_TYPES
:
1012 # Enable static routes
1017 "network": NETWORK
[addr_type
],
1018 "next_hop": NEXT_HOP_IP
["nh1"][addr_type
],
1022 "network": NETWORK2
[addr_type
],
1023 "next_hop": NEXT_HOP_IP
["nh1"][addr_type
],
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(
1035 step("verify routes are present in RIB")
1038 nh
= NEXT_HOP_IP
["nh1"][addr_type
]
1039 result
= verify_rib(
1040 tgen
, addr_type
, dut
, input_dict_4
, next_hop
=nh
, protocol
=protocol
1044 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name
)
1046 step("Configure route-map on R2 with allow tag1 and deny tag2")
1052 "rmap_match_tag_1_{}".format(addr_type
): [
1056 "match": {addr_type
: {"tag": "4001"}},
1061 "match": {addr_type
: {"tag": "4002"}},
1067 result
= create_route_maps(tgen
, input_dict_3
)
1068 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1072 # Configure neighbor for route map
1085 "name": "rmap_match_tag_1_ipv4",
1093 "redistribute": [{"redist_type": "static"}],
1100 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
1101 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1106 "Verify static route S1 advetised in BGP table when tag1 permit"
1107 "in route-map else it is denied"
1114 "network": NETWORK2
[addr_type
],
1115 "next_hop": NEXT_HOP_IP
["nh1"][addr_type
],
1122 result
= verify_rib(
1123 tgen
, addr_type
, dut
, input_dict_0
, protocol
=protocol
, expected
=False
1125 assert result
is not True, (
1126 "Testcase {} : Failed \nError: Route with "
1127 "tag 4002 is still present in RIB".format(tc_name
)
1132 "r2": {"static_routes": [{"network": NETWORK
[addr_type
], "tag": 4001}]}
1135 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_0
, protocol
=protocol
)
1136 assert result
is True, (
1137 "Testcase {} : Failed \nError: Route with "
1138 "tag 4001 is missing in RIB".format(tc_name
)
1141 step("Modify the route-map to allow tag2 and deny tag1")
1146 "rmap_match_tag_1_{}".format(addr_type
): [
1150 "match": {addr_type
: {"tag": "4001"}},
1155 "match": {addr_type
: {"tag": "4002"}},
1161 result
= create_route_maps(tgen
, input_dict_3
)
1162 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1168 "Verify static route S2 advertised in BGP table when tag2"
1169 "permit in route-map else it is denied"
1173 "r2": {"static_routes": [{"network": NETWORK2
[addr_type
], "tag": 4002}]}
1176 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_0
, protocol
=protocol
)
1177 assert result
is True, (
1178 "Testcase {} : Failed \nError: Route with "
1179 "tag 4002 is missing in RIB".format(tc_name
)
1183 "r2": {"static_routes": [{"network": NETWORK
[addr_type
], "tag": 4001}]}
1185 result
= verify_rib(
1186 tgen
, addr_type
, dut
, input_dict_1
, protocol
=protocol
, expected
=False
1188 assert result
is not True, (
1189 "Testcase {} : Failed \nError: Route with "
1190 "tag 4001 is still present in RIB".format(tc_name
)
1193 step("Configure one static route with 2 ECMP nexthop N1 and N2")
1194 step("For N1 configure tag 1 and for N2 configure tag 2")
1195 step("S1= ip route 10.1.1.1/24 28.1.1.2 tag 1")
1196 step("S1= ip route 10.1.1.1/24 29.1.1.2 tag 2")
1197 step("configure the route-map to allow tag1 and deny tag 2")
1198 step("Modify the route-map to allow tag2 and deny tag1")
1200 for addr_type
in ADDR_TYPES
:
1201 # Enable static routes
1206 "network": NETWORK2
[addr_type
],
1207 "next_hop": NEXT_HOP_IP
["nh1"][addr_type
],
1211 "network": NETWORK2
[addr_type
],
1212 "next_hop": NEXT_HOP_IP
["nh2"][addr_type
],
1219 logger
.info("Configure static routes")
1220 result
= create_static_routes(tgen
, input_dict_4
)
1221 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1227 result
= verify_rib(
1228 tgen
, addr_type
, dut
, input_dict_4
, protocol
=protocol
, fib
=True
1232 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name
)
1234 step("shut/no shut of tag1 and tag2 nexthop")
1236 intf
= topo
["routers"]["r2"]["links"]["r1-link0"]["interface"]
1237 shutdown_bringup_interface(tgen
, dut
, intf
, False)
1239 shutdown_bringup_interface(tgen
, dut
, intf
, True)
1241 step("configure one static route with 3 next-hop")
1242 step("N1-tag1, N2-tag2, N3-tag3")
1243 step("S1= ip route 10.1.1.1/24 28.1.1.2 tag 1")
1244 step("S1= ip route 10.1.1.1/24 29.1.1.2 tag 2")
1245 step("S1= ip route 10.1.1.1/24 28.1.1.2 tag 3")
1247 for addr_type
in ADDR_TYPES
:
1248 # Enable static routes
1253 "network": NETWORK2
[addr_type
],
1254 "next_hop": NEXT_HOP_IP
["nh1"][addr_type
],
1258 "network": NETWORK2
[addr_type
],
1259 "next_hop": NEXT_HOP_IP
["nh2"][addr_type
],
1263 "network": NETWORK2
[addr_type
],
1264 "next_hop": NEXT_HOP_IP
["nh3"][addr_type
],
1271 logger
.info("Configure static routes")
1272 result
= create_static_routes(tgen
, input_dict_4
)
1273 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1279 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_4
, protocol
=protocol
)
1281 step("configure the route-map to allow tag2 & tag3 and deny tag1")
1286 "rmap_match_tag_1_{}".format(addr_type
): [
1290 "match": {addr_type
: {"tag": "4001"}},
1295 "match": {addr_type
: {"tag": "4002"}},
1300 "match": {addr_type
: {"tag": "4003"}},
1306 result
= create_route_maps(tgen
, input_dict_3
)
1307 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1312 "Verify static route advertised in BGP table with tag3"
1313 " nexthop if tag2 is down"
1317 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict_4
)
1318 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1322 step("shut / no shut of tag2 and tag3 next-hop")
1324 intf
= topo
["routers"]["r2"]["links"]["r1-link1"]["interface"]
1325 shutdown_bringup_interface(tgen
, dut
, intf
, False)
1327 intf
= topo
["routers"]["r2"]["links"]["r1-link2"]["interface"]
1328 shutdown_bringup_interface(tgen
, dut
, intf
, False)
1330 step("shut/no shut of tag2 and tag3 nexthop")
1331 intf
= topo
["routers"]["r2"]["links"]["r1-link1"]["interface"]
1332 shutdown_bringup_interface(tgen
, dut
, intf
, True)
1334 intf
= topo
["routers"]["r2"]["links"]["r1-link2"]["interface"]
1335 shutdown_bringup_interface(tgen
, dut
, intf
, True)
1337 step("Verify after shut/noshut of nexthop BGP table updated correctly")
1340 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict_4
)
1341 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1345 write_test_footer(tc_name
)
1348 if __name__
== "__main__":
1349 args
= ["-s"] + sys
.argv
[1:]
1350 sys
.exit(pytest
.main(args
))