4 # Copyright (c) 2020 by VMware, Inc. ("VMware")
5 # Used Copyright (c) 2018 by Network Device Education Foundation,
6 # Inc. ("NetDEF") in this file.
8 # Permission to use, copy, modify, and/or distribute this software
9 # for any purpose with or without fee is hereby granted, provided
10 # that the above copyright notice and this permission notice appear
13 # THE SOFTWARE IS PROVIDED "AS IS" AND VMWARE DISCLAIMS ALL WARRANTIES
14 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL VMWARE BE LIABLE FOR
16 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
17 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
18 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
19 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
23 -Verify static route ECMP functionality with 8 next hop
25 -Verify static route functionality with 8 next hop different AD value
27 -Verify static route with tag option
29 -Verify BGP did not install the static route when it receive route
39 from lib
.topotest
import version_cmp
41 # Save the Current Working Directory to find configuration files.
42 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
43 sys
.path
.append(os
.path
.join(CWD
, "../"))
44 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
45 # pylint: disable=C0413
46 # Import topogen and topotest helpers
47 from lib
.topogen
import Topogen
, get_topogen
49 from lib
.common_config
import (
53 reset_config_on_routers
,
58 shutdown_bringup_interface
,
64 from lib
.topolog
import logger
65 from lib
.bgp
import verify_bgp_convergence
, create_router_bgp
, verify_bgp_rib
66 from lib
.topojson
import build_config_from_json
68 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.staticd
]
71 BGP_CONVERGENCE
= False
72 ADDR_TYPES
= check_address_types()
95 PREFIX1
= {"ipv4": "110.0.20.1/32", "ipv6": "20::1/128"}
96 NETWORK2
= {"ipv4": ["11.0.20.1/32"], "ipv6": ["2::1/128"]}
100 def setup_module(mod
):
103 Set up the pytest environment.
107 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
108 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
109 logger
.info("=" * 40)
111 logger
.info("Running setup_module to create topology")
113 # This function initiates the topology build with Topogen...
114 json_file
= "{}/static_routes_topo3_ebgp.json".format(CWD
)
115 tgen
= Topogen(json_file
, mod
.__name
__)
117 topo
= tgen
.json_topo
118 # ... and here it calls Mininet initialization functions.
120 # Starting topology, create tmp files which are loaded to routers
121 # to start daemons and then start routers
124 # Creating configuration from JSON
125 build_config_from_json(tgen
, topo
)
127 if version_cmp(platform
.release(), "4.19") < 0:
129 'These tests will not run. (have kernel "{}", '
130 "requires kernel >= 4.19)".format(platform
.release())
132 pytest
.skip(error_msg
)
134 # Checking BGP convergence
135 global BGP_CONVERGENCE
138 # Don't run this test if we have any failure.
139 if tgen
.routers_have_failure():
140 pytest
.skip(tgen
.errors
)
141 # Api call verify whether BGP is converged
142 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
143 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
147 logger
.info("Running setup_module() done")
150 def teardown_module(mod
):
152 Teardown the pytest environment
157 logger
.info("Running teardown_module to delete topology")
161 # Stop toplogy and Remove tmp files
165 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
167 logger
.info("=" * 40)
173 "ipv4": topo
["routers"]["r1"]["links"]["r2-link0"]["ipv4"].split("/")[0],
174 "ipv6": topo
["routers"]["r1"]["links"]["r2-link0"]["ipv6"].split("/")[0],
177 "ipv4": topo
["routers"]["r1"]["links"]["r2-link1"]["ipv4"].split("/")[0],
178 "ipv6": topo
["routers"]["r1"]["links"]["r2-link1"]["ipv6"].split("/")[0],
181 "ipv4": topo
["routers"]["r1"]["links"]["r2-link2"]["ipv4"].split("/")[0],
182 "ipv6": topo
["routers"]["r1"]["links"]["r2-link2"]["ipv6"].split("/")[0],
185 "ipv4": topo
["routers"]["r1"]["links"]["r2-link3"]["ipv4"].split("/")[0],
186 "ipv6": topo
["routers"]["r1"]["links"]["r2-link3"]["ipv6"].split("/")[0],
189 "ipv4": topo
["routers"]["r1"]["links"]["r2-link4"]["ipv4"].split("/")[0],
190 "ipv6": topo
["routers"]["r1"]["links"]["r2-link4"]["ipv6"].split("/")[0],
193 "ipv4": topo
["routers"]["r1"]["links"]["r2-link5"]["ipv4"].split("/")[0],
194 "ipv6": topo
["routers"]["r1"]["links"]["r2-link5"]["ipv6"].split("/")[0],
197 "ipv4": topo
["routers"]["r1"]["links"]["r2-link6"]["ipv4"].split("/")[0],
198 "ipv6": topo
["routers"]["r1"]["links"]["r2-link6"]["ipv6"].split("/")[0],
201 "ipv4": topo
["routers"]["r1"]["links"]["r2-link7"]["ipv4"].split("/")[0],
202 "ipv6": topo
["routers"]["r1"]["links"]["r2-link7"]["ipv6"].split("/")[0],
208 #####################################################
212 #####################################################
215 def test_staticroute_with_ecmp_p0_tc3_ebgp(request
):
217 Verify static route ECMP functionality with 8 next hop'
220 tc_name
= request
.node
.name
221 write_test_header(tc_name
)
224 # Don't run this test if we have any failure.
225 if tgen
.routers_have_failure():
226 pytest
.skip(tgen
.errors
)
228 reset_config_on_routers(tgen
)
229 NEXT_HOP_IP
= populate_nh()
231 step("Configure 8 interfaces / links between R1 and R2,")
233 "Configure IPv4 static route in R2 with 8 next hop"
234 "N1(21.1.1.2), N2(22.1.1.2), N3(23.1.1.2), N4(24.1.1.2),"
235 "N5(25.1.1.2), N6(26.1.1.2), N7(27.1.1.2),N8(28.1.1.2), Static"
236 "route next-hop present on R1"
239 step("Configure IBGP IPv4 peering between R2 and R3 router.")
241 for addr_type
in ADDR_TYPES
:
242 # Enable static routes
243 for nhp
in range(1, 9):
248 "network": PREFIX1
[addr_type
],
249 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
254 logger
.info("Configure static routes")
255 result
= create_static_routes(tgen
, input_dict_4
)
256 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
259 logger
.info("Verifying %s routes on r2", addr_type
)
261 NEXT_HOP_IP
["nh1"][addr_type
],
262 NEXT_HOP_IP
["nh2"][addr_type
],
263 NEXT_HOP_IP
["nh3"][addr_type
],
264 NEXT_HOP_IP
["nh4"][addr_type
],
265 NEXT_HOP_IP
["nh5"][addr_type
],
266 NEXT_HOP_IP
["nh6"][addr_type
],
267 NEXT_HOP_IP
["nh7"][addr_type
],
268 NEXT_HOP_IP
["nh8"][addr_type
],
274 tgen
, addr_type
, dut
, input_dict_4
, next_hop
=nh
, protocol
=protocol
278 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name
)
279 step("Configure redistribute static in BGP on R2 router")
280 for addr_type
in ADDR_TYPES
:
286 "unicast": {"redistribute": [{"redist_type": "static"}]}
292 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
293 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
298 "Remove the static route configured with nexthop N1 to N8, one"
299 "by one from running config"
301 for addr_type
in ADDR_TYPES
:
302 # delete static routes
303 for nhp
in range(1, 9):
308 "network": PREFIX1
[addr_type
],
309 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
316 logger
.info("Configure static routes")
317 result
= create_static_routes(tgen
, input_dict_4
)
318 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
333 ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
337 step("Configure the static route with nexthop N1 to N8, one by" "one")
339 for addr_type
in ADDR_TYPES
:
341 for nhp
in range(1, 9):
346 "network": PREFIX1
[addr_type
],
347 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
353 logger
.info("Configure static routes")
354 result
= create_static_routes(tgen
, input_dict_4
)
355 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
360 tgen
, addr_type
, dut
, input_dict_4
, next_hop
=nh
, protocol
=protocol
364 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name
)
366 step("Random shut of the nexthop interfaces")
367 randnum
= random
.randint(0, 7)
368 for addr_type
in ADDR_TYPES
:
369 intf
= topo
["routers"]["r2"]["links"]["r1-link" + str(randnum
)]["interface"]
370 shutdown_bringup_interface(tgen
, dut
, intf
, False)
371 nhip
= NEXT_HOP_IP
["nh" + str(randnum
+ 1)][addr_type
]
376 "network": PREFIX1
[addr_type
],
377 "next_hop": NEXT_HOP_IP
["nh" + str(randnum
+ 1)][addr_type
],
393 ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
397 step("Random no shut of the nexthop interfaces")
398 for addr_type
in ADDR_TYPES
:
399 intf
= topo
["routers"]["r2"]["links"]["r1-link" + str(randnum
)]["interface"]
400 shutdown_bringup_interface(tgen
, dut
, intf
, True)
401 nhip
= NEXT_HOP_IP
["nh" + str(randnum
+ 1)][addr_type
]
403 tgen
, addr_type
, dut
, input_dict_5
, next_hop
=nhip
, protocol
=protocol
407 ), "Testcase {} : Failed \n" "Error: Routes are missing in RIB".format(tc_name
)
409 step("Reload the FRR router")
410 # stop/start -> restart FRR router and verify
411 stop_router(tgen
, "r2")
412 start_router(tgen
, "r2")
415 tgen
, addr_type
, dut
, input_dict_4
, next_hop
=nh
, protocol
=protocol
419 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name
)
421 write_test_footer(tc_name
)
424 def test_staticroute_with_ecmp_with_diff_AD_p0_tc4_ebgp(request
):
426 Verify static route ECMP functionality with 8 next hop
429 tc_name
= request
.node
.name
430 write_test_header(tc_name
)
433 # Don't run this test if we have any failure.
434 if tgen
.routers_have_failure():
435 pytest
.skip(tgen
.errors
)
437 reset_config_on_routers(tgen
)
439 step("Configure 8 interfaces / links between R1 and R2,")
440 step("Configure IBGP IPv4 peering between R2 and R3 router.")
441 NEXT_HOP_IP
= populate_nh()
443 for addr_type
in ADDR_TYPES
:
444 nh_all
[addr_type
] = []
445 for nhp
in range(1, 9):
446 nh_all
[addr_type
].append(NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
])
448 "Configure IPv4 static route in R2 with 8 next hop"
449 "N1(21.1.1.2) AD 10, N2(22.1.1.2) AD 20, N3(23.1.1.2) AD 30,"
450 "N4(24.1.1.2) AD 40, N5(25.1.1.2) AD 50, N6(26.1.1.2) AD 60,"
451 "N7(27.1.1.2) AD 70, N8(28.1.1.2) AD 80, Static route next-hop"
454 for addr_type
in ADDR_TYPES
:
455 for nhp
in range(1, 9):
460 "network": PREFIX1
[addr_type
],
461 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
462 "admin_distance": 10 * nhp
,
467 logger
.info("Configure static routes")
468 result
= create_static_routes(tgen
, input_dict_4
)
469 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
472 logger
.info("Verifying %s routes on r2", addr_type
)
475 "On R2, static route installed in RIB using "
476 "show ip route with 8 next hop, lowest AD nexthop is active"
478 step("On R2, static route with lowest AD nexthop installed in FIB")
483 "network": PREFIX1
[addr_type
],
484 "next_hop": NEXT_HOP_IP
["nh1"][addr_type
],
485 "admin_distance": 10,
492 nh
= NEXT_HOP_IP
["nh1"][addr_type
]
494 tgen
, addr_type
, dut
, input_dict_4
, next_hop
=nh
, protocol
=protocol
, fib
=True
496 assert result
is True, (
497 "Testcase {} : Failed \nError: Route with "
498 " lowest AD is missing in RIB".format(tc_name
)
502 for nhp
in range(2, 9):
503 nh
.append(NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
])
514 assert result
is not True, (
515 "Testcase {} : Failed \nError: Routes "
516 " with high AD are active in RIB".format(tc_name
)
519 step("Configure redistribute static in BGP on R2 router")
520 for addr_type
in ADDR_TYPES
:
526 "unicast": {"redistribute": [{"redist_type": "static"}]}
533 logger
.info("Configuring redistribute static")
534 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
535 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
540 "After configuring them, route is always active with lowest AD"
541 "value and all the nexthop populated in RIB and FIB again "
547 "network": PREFIX1
[addr_type
],
548 "next_hop": NEXT_HOP_IP
["nh1"][addr_type
],
549 "admin_distance": 10,
556 nh
= NEXT_HOP_IP
["nh1"][addr_type
]
558 tgen
, addr_type
, dut
, input_dict_4
, next_hop
=nh
, protocol
=protocol
, fib
=True
560 assert result
is True, (
561 "Testcase {} : Failed \nError: Route with "
562 " lowest AD is missing in RIB".format(tc_name
)
566 "Remove the static route configured with nexthop N1 to N8, one"
567 "by one from running config"
570 for addr_type
in ADDR_TYPES
:
571 # delete static routes
572 for nhp
in range(1, 9):
577 "network": PREFIX1
[addr_type
],
578 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
579 "admin_distance": 10 * nhp
,
586 logger
.info("Configure static routes")
587 result
= create_static_routes(tgen
, input_dict_4
)
588 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
593 "After removing the static route with N1 to N8 one by one, "
594 "route become active with next preferred nexthop and nexthop which "
595 "got removed is not shown in RIB and FIB"
602 next_hop
=nh_all
[addr_type
],
608 ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
612 step("Configure the static route with nexthop N1 to N8, one by" "one")
613 for addr_type
in ADDR_TYPES
:
615 for nhp
in range(1, 9):
620 "network": PREFIX1
[addr_type
],
621 "next_hop": NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
],
622 "admin_distance": 10 * nhp
,
627 logger
.info("Configure static routes")
628 result
= create_static_routes(tgen
, input_dict_4
)
629 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
633 step("On R2, static route with lowest AD nexthop installed in FIB")
638 "network": PREFIX1
[addr_type
],
639 "next_hop": NEXT_HOP_IP
["nh1"][addr_type
],
640 "admin_distance": 10,
647 nh
= NEXT_HOP_IP
["nh1"][addr_type
]
649 tgen
, addr_type
, dut
, input_dict_4
, next_hop
=nh
, protocol
=protocol
, fib
=True
651 assert result
is True, (
652 "Testcase {} : Failed \nError: Route with "
653 " lowest AD is missing in RIB".format(tc_name
)
657 for nhp
in range(2, 9):
658 nh
.append(NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
])
669 assert result
is not True, (
670 "Testcase {} : Failed \nError: Routes "
671 " with high AD are active in RIB".format(tc_name
)
674 step("Random shut of the nexthop interfaces")
675 randnum
= random
.randint(0, 7)
676 for addr_type
in ADDR_TYPES
:
677 intf
= topo
["routers"]["r2"]["links"]["r1-link" + str(randnum
)]["interface"]
678 shutdown_bringup_interface(tgen
, dut
, intf
, False)
679 nhip
= NEXT_HOP_IP
["nh" + str(randnum
+ 1)][addr_type
]
684 "network": PREFIX1
[addr_type
],
685 "next_hop": NEXT_HOP_IP
["nh" + str(randnum
+ 1)][addr_type
],
701 ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
705 step("Random no shut of the nexthop interfaces")
706 for addr_type
in ADDR_TYPES
:
707 intf
= topo
["routers"]["r2"]["links"]["r1-link" + str(randnum
)]["interface"]
708 shutdown_bringup_interface(tgen
, dut
, intf
, True)
709 nhip
= NEXT_HOP_IP
["nh" + str(randnum
+ 1)][addr_type
]
711 tgen
, addr_type
, dut
, input_dict_5
, next_hop
=nhip
, protocol
=protocol
715 ), "Testcase {} : Failed \n" "Error: Routes are missing in RIB".format(tc_name
)
717 step("Reload the FRR router")
718 # stop/start -> restart FRR router and verify
719 stop_router(tgen
, "r2")
720 start_router(tgen
, "r2")
723 "After reload of FRR router, static route installed "
724 "in RIB and FIB properly ."
726 for addr_type
in ADDR_TYPES
:
731 "network": PREFIX1
[addr_type
],
732 "next_hop": NEXT_HOP_IP
["nh1"][addr_type
],
733 "admin_distance": 10,
740 nh
= NEXT_HOP_IP
["nh1"][addr_type
]
742 tgen
, addr_type
, dut
, input_dict_4
, next_hop
=nh
, protocol
=protocol
, fib
=True
744 assert result
is True, (
745 "Testcase {} : Failed \nError: Route with "
746 " lowest AD is missing in RIB".format(tc_name
)
750 for nhp
in range(2, 9):
751 nh
.append(NEXT_HOP_IP
["nh" + str(nhp
)][addr_type
])
762 assert result
is not True, (
763 "Testcase {} : Failed \nError: Routes "
764 " with high AD are active in RIB".format(tc_name
)
767 write_test_footer(tc_name
)
770 def test_bgp_local_nexthop_p1_tc14_ebgp(request
):
772 Verify BGP did not install the static route when it receive route
776 tc_name
= request
.node
.name
777 write_test_header(tc_name
)
780 step("Configure BGP IPv4 session between R2 and R3")
781 step("Configure IPv4 static route on R2")
782 reset_config_on_routers(tgen
)
784 for addr_type
in ADDR_TYPES
:
785 # Enable static routes
790 "network": NETWORK
[addr_type
],
791 "next_hop": topo
["routers"]["r3"]["links"]["r2-link0"][
799 logger
.info("Configure static routes")
800 result
= create_static_routes(tgen
, input_dict_4
)
801 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
805 step("Configure redistribute static in the BGP")
812 "unicast": {"redistribute": [{"redist_type": "static"}]}
818 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
819 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
823 step("Verify R2 BGP table has IPv4 route")
825 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_4
)
828 ), "Testcase {} : Failed \nError: Routes is" " missing in RIB of R2".format(
832 step(" Verify route did not install in the R3 BGP table, RIB/FIB")
834 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict_4
, expected
=False)
835 assert result
is not True, (
836 "Testcase {} : Failed \nError: Routes is"
837 " still present in BGP RIB of R2".format(tc_name
)
840 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_4
, expected
=False)
841 assert result
is not True, (
842 "Testcase {} : Failed \nError: Routes is"
843 " still present in RIB of R2".format(tc_name
)
846 write_test_footer(tc_name
)
849 def test_frr_intf_name_as_gw_gap_tc4_ebgp_p0(request
):
851 Verify static route configure with interface name as gateway'
854 tc_name
= request
.node
.name
855 write_test_header(tc_name
)
858 # Don't run this test if we have any failure.
859 if tgen
.routers_have_failure():
860 pytest
.skip(tgen
.errors
)
862 reset_config_on_routers(tgen
)
865 intf
= topo
["routers"]["r1"]["links"]["r2-link0"]["interface"]
866 nh
= topo
["routers"]["r1"]["links"]["r2-link0"]
868 "ipv4": [(dut
, intf
, ["1.1.1.1/32"], nh
["ipv4"].split("/")[0])],
869 "ipv6": [(dut
, intf
, ["4001::32/128"], nh
["ipv6"].split("/")[0])],
873 "Configure IPv4 and IPv6 static route in FRR with different next"
874 "hop (ens224 as nexthop))"
876 step("ip route 2.2.2.0/24 20.1.1.1 ens224 ----from FRR cli")
877 step("ipv6 route 2000::1/120 5000::1 ens224 ----from FRR cli")
879 for addr_type
in ADDR_TYPES
:
880 # Enable static routes
881 nh
= topo
["routers"]["r2"]["links"]["r1-link0"][addr_type
].split("/")[0]
885 {"network": ip_list
[addr_type
][0][2][0], "next_hop": nh
}
890 logger
.info("Configure static routes")
891 result
= create_static_routes(tgen
, input_dict_4
)
892 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
897 "IPv4 and IPv6 Static route added in FRR verify using "
898 "show ip route , nexthop is resolved using show nht"
902 tgen
, addr_type
, dut
, input_dict_4
, protocol
=protocol
, next_hop
=nh
906 ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name
)
912 "resolvedVia": "connected",
913 "nexthops": {"nexthop1": {"Interfcae": intf
}},
917 result
= verify_ip_nht(tgen
, input_dict_nh
)
920 ), "Testcase {} : Failed \nError: Nexthop is" " missing in RIB".format(tc_name
)
923 "Shut / no shut IPv4 and IPv6 static next hop interface from"
927 shutdown_bringup_interface(tgen
, dut
, intf
, False)
930 "After shut of nexthop interface, IPv4 and IPv6 route got removed "
931 "from RIB verify using show ip route show nht"
944 ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(tc_name
)
946 shutdown_bringup_interface(tgen
, dut
, intf
, True)
949 "After no shut route got added again in RIB /FIB using "
950 "show ip route nexthop is resolved using show nht"
952 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_4
, protocol
=protocol
)
953 assert result
is True, "Testcase {} : Failed".format(tc_name
)
955 for addr_type
in ADDR_TYPES
:
956 nh
= topo
["routers"]["r2"]["links"]["r1-link0"][addr_type
].split("/")[0]
961 "network": ip_list
[addr_type
][0][2][0],
969 logger
.info("Configure static routes")
970 result
= create_static_routes(tgen
, input_dict_4
)
971 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
976 "Removing FRR configured static route verify FRR route also "
990 ), "Testcase {} : Failed \nError: Routes" " still present in RIB".format(
994 write_test_footer(tc_name
)
997 def test_static_route_with_tag_p0_tc_13_ebgp(request
):
999 Verify static route with tag option
1002 tc_name
= request
.node
.name
1003 write_test_header(tc_name
)
1004 tgen
= get_topogen()
1006 # Don't run this test if we have any failure.
1007 if tgen
.routers_have_failure():
1008 pytest
.skip(tgen
.errors
)
1010 step("Configure 8 links between R1 and R2")
1011 step("Configure 1 links between R2 and R3")
1012 NEXT_HOP_IP
= populate_nh()
1015 "Configure 2 IPv4 static route (S1 and S2) in R2 with same"
1016 "next hop N1 28.1.1.2"
1018 step("Configure static route S1 with tag 1 and static route S2 with" "tag2")
1019 step("S1= ip route 10.1.1.1/24 28.1.1.2 tag 1")
1020 step("S2= ip route 20.1.1.1/24 28.1.1.2 tag 2")
1021 step("Enable redistribute static in BGP with route-map")
1022 reset_config_on_routers(tgen
)
1024 for addr_type
in ADDR_TYPES
:
1025 # Enable static routes
1030 "network": NETWORK
[addr_type
],
1031 "next_hop": NEXT_HOP_IP
["nh1"][addr_type
],
1035 "network": NETWORK2
[addr_type
],
1036 "next_hop": NEXT_HOP_IP
["nh1"][addr_type
],
1043 logger
.info("Configure static routes")
1044 result
= create_static_routes(tgen
, input_dict_4
)
1045 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1048 step("verify routes are present in RIB")
1051 nh
= NEXT_HOP_IP
["nh1"][addr_type
]
1052 result
= verify_rib(
1053 tgen
, addr_type
, dut
, input_dict_4
, next_hop
=nh
, protocol
=protocol
1057 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name
)
1059 step("Configure route-map on R2 with allow tag1 and deny tag2")
1065 "rmap_match_tag_1_{}".format(addr_type
): [
1069 "match": {addr_type
: {"tag": "4001"}},
1074 "match": {addr_type
: {"tag": "4002"}},
1080 result
= create_route_maps(tgen
, input_dict_3
)
1081 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1085 # Configure neighbor for route map
1098 "name": "rmap_match_tag_1_ipv4",
1106 "redistribute": [{"redist_type": "static"}],
1113 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
1114 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1119 "Verify static route S1 advetised in BGP table when tag1 permit"
1120 "in route-map else it is denied"
1127 "network": NETWORK2
[addr_type
],
1128 "next_hop": NEXT_HOP_IP
["nh1"][addr_type
],
1135 result
= verify_rib(
1136 tgen
, addr_type
, dut
, input_dict_0
, protocol
=protocol
, expected
=False
1138 assert result
is not True, (
1139 "Testcase {} : Failed \nError: Route with "
1140 "tag 4002 is still present in RIB".format(tc_name
)
1145 "r2": {"static_routes": [{"network": NETWORK
[addr_type
], "tag": 4001}]}
1148 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_0
, protocol
=protocol
)
1149 assert result
is True, (
1150 "Testcase {} : Failed \nError: Route with "
1151 "tag 4001 is missing in RIB".format(tc_name
)
1154 step("Modify the route-map to allow tag2 and deny tag1")
1159 "rmap_match_tag_1_{}".format(addr_type
): [
1163 "match": {addr_type
: {"tag": "4001"}},
1168 "match": {addr_type
: {"tag": "4002"}},
1174 result
= create_route_maps(tgen
, input_dict_3
)
1175 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1181 "Verify static route S2 advertised in BGP table when tag2"
1182 "permit in route-map else it is denied"
1186 "r2": {"static_routes": [{"network": NETWORK2
[addr_type
], "tag": 4002}]}
1189 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_0
, protocol
=protocol
)
1190 assert result
is True, (
1191 "Testcase {} : Failed \nError: Route with "
1192 "tag 4002 is missing in RIB".format(tc_name
)
1196 "r2": {"static_routes": [{"network": NETWORK
[addr_type
], "tag": 4001}]}
1198 result
= verify_rib(
1199 tgen
, addr_type
, dut
, input_dict_1
, protocol
=protocol
, expected
=False
1201 assert result
is not True, (
1202 "Testcase {} : Failed \nError: Route with "
1203 "tag 4001 is still present in RIB".format(tc_name
)
1206 step("Configure one static route with 2 ECMP nexthop N1 and N2")
1207 step("For N1 configure tag 1 and for N2 configure tag 2")
1208 step("S1= ip route 10.1.1.1/24 28.1.1.2 tag 1")
1209 step("S1= ip route 10.1.1.1/24 29.1.1.2 tag 2")
1210 step("configure the route-map to allow tag1 and deny tag 2")
1211 step("Modify the route-map to allow tag2 and deny tag1")
1213 for addr_type
in ADDR_TYPES
:
1214 # Enable static routes
1219 "network": NETWORK2
[addr_type
],
1220 "next_hop": NEXT_HOP_IP
["nh1"][addr_type
],
1224 "network": NETWORK2
[addr_type
],
1225 "next_hop": NEXT_HOP_IP
["nh2"][addr_type
],
1232 logger
.info("Configure static routes")
1233 result
= create_static_routes(tgen
, input_dict_4
)
1234 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1240 result
= verify_rib(
1241 tgen
, addr_type
, dut
, input_dict_4
, protocol
=protocol
, fib
=True
1245 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name
)
1247 step("shut/no shut of tag1 and tag2 nexthop")
1249 intf
= topo
["routers"]["r2"]["links"]["r1-link0"]["interface"]
1250 shutdown_bringup_interface(tgen
, dut
, intf
, False)
1252 shutdown_bringup_interface(tgen
, dut
, intf
, True)
1254 step("configure one static route with 3 next-hop")
1255 step("N1-tag1, N2-tag2, N3-tag3")
1256 step("S1= ip route 10.1.1.1/24 28.1.1.2 tag 1")
1257 step("S1= ip route 10.1.1.1/24 29.1.1.2 tag 2")
1258 step("S1= ip route 10.1.1.1/24 28.1.1.2 tag 3")
1260 for addr_type
in ADDR_TYPES
:
1261 # Enable static routes
1266 "network": NETWORK2
[addr_type
],
1267 "next_hop": NEXT_HOP_IP
["nh1"][addr_type
],
1271 "network": NETWORK2
[addr_type
],
1272 "next_hop": NEXT_HOP_IP
["nh2"][addr_type
],
1276 "network": NETWORK2
[addr_type
],
1277 "next_hop": NEXT_HOP_IP
["nh3"][addr_type
],
1284 logger
.info("Configure static routes")
1285 result
= create_static_routes(tgen
, input_dict_4
)
1286 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1292 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_4
, protocol
=protocol
)
1294 step("configure the route-map to allow tag2 & tag3 and deny tag1")
1299 "rmap_match_tag_1_{}".format(addr_type
): [
1303 "match": {addr_type
: {"tag": "4001"}},
1308 "match": {addr_type
: {"tag": "4002"}},
1313 "match": {addr_type
: {"tag": "4003"}},
1319 result
= create_route_maps(tgen
, input_dict_3
)
1320 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1325 "Verify static route advertised in BGP table with tag3"
1326 " nexthop if tag2 is down"
1330 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict_4
)
1331 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1335 step("shut / no shut of tag2 and tag3 next-hop")
1337 intf
= topo
["routers"]["r2"]["links"]["r1-link1"]["interface"]
1338 shutdown_bringup_interface(tgen
, dut
, intf
, False)
1340 intf
= topo
["routers"]["r2"]["links"]["r1-link2"]["interface"]
1341 shutdown_bringup_interface(tgen
, dut
, intf
, False)
1343 step("shut/no shut of tag2 and tag3 nexthop")
1344 intf
= topo
["routers"]["r2"]["links"]["r1-link1"]["interface"]
1345 shutdown_bringup_interface(tgen
, dut
, intf
, True)
1347 intf
= topo
["routers"]["r2"]["links"]["r1-link2"]["interface"]
1348 shutdown_bringup_interface(tgen
, dut
, intf
, True)
1350 step("Verify after shut/noshut of nexthop BGP table updated correctly")
1353 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict_4
)
1354 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1358 write_test_footer(tc_name
)
1361 if __name__
== "__main__":
1362 args
= ["-s"] + sys
.argv
[1:]
1363 sys
.exit(pytest
.main(args
))