2 # SPDX-License-Identifier: ISC
4 # Copyright (c) 2022 by VMware, Inc. ("VMware")
5 # Shreenidhi A R <rshreenidhi@vmware.com>
6 # Used Copyright (c) 2018 by Network Device Education Foundation, Inc. ("NetDEF")
10 Following tests are covered.
11 5. Verify BGP default originate route-map with OUT route-map
12 6. Verify BGP default originate route-map with IN route-map
13 8. Verify BGP default route after removing default-originate
14 9. Verify default-originate route with GR
20 from time
import sleep
21 from copy
import deepcopy
22 from lib
.topolog
import logger
24 # pylint: disable=C0413
25 # Import topogen and topotest helpers
26 from lib
.topogen
import Topogen
, get_topogen
27 from lib
.topojson
import build_config_from_json
28 from lib
.topolog
import logger
31 verify_bgp_convergence
,
32 verify_graceful_restart
,
40 get_prefix_count_route
,
42 verify_rib_default_route
,
43 verify_fib_default_route
,
44 verify_bgp_advertised_routes_from_neighbor
,
45 verify_bgp_received_routes_from_neighbor
,
47 from lib
.common_config
import (
53 shutdown_bringup_interface
,
55 required_linux_kernel_version
,
60 get_frr_ipv6_linklocal
,
65 reset_config_on_routers
,
72 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.staticd
]
74 # Save the Current Working Directory to find configuration files.
75 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
76 sys
.path
.append(os
.path
.join(CWD
, "../"))
77 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
79 # Required to instantiate the topology builder class.
81 # pylint: disable=C0413
82 # Import topogen and topotest helpers
89 NETWORK1_1
= {"ipv4": "1.1.1.1/32", "ipv6": "1::1/128"}
90 NETWORK1_2
= {"ipv4": "1.1.1.2/32", "ipv6": "1::2/128"}
91 NETWORK2_1
= {"ipv4": "2.1.1.1/32", "ipv6": "2::1/128"}
92 NETWORK2_2
= {"ipv4": "2.1.1.2/32", "ipv6": "2::2/128"}
93 NETWORK3_1
= {"ipv4": "3.1.1.1/32", "ipv6": "3::1/128"}
94 NETWORK3_2
= {"ipv4": "3.1.1.2/32", "ipv6": "3::2/128"}
95 NETWORK4_1
= {"ipv4": "4.1.1.1/32", "ipv6": "4::1/128"}
96 NETWORK4_2
= {"ipv4": "4.1.1.2/32", "ipv6": "4::2/128"}
97 NETWORK5_1
= {"ipv4": "5.1.1.1/32", "ipv6": "5::1/128"}
98 NETWORK5_2
= {"ipv4": "5.1.1.2/32", "ipv6": "5::2/128"}
99 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
100 NEXT_HOP_IP
= {"ipv4": "Null0", "ipv6": "Null0"}
105 IPV4_RM1
= "RMVIPV41"
106 IPV6_RM1
= "RMVIPV61"
108 IPV4_RM2
= "RMVIPV42"
109 IPV6_RM2
= "RMVIPV62"
118 r1_ipv4_loopback
= "1.0.1.0/24"
119 r2_ipv4_loopback
= "1.0.2.0/24"
120 r3_ipv4_loopback
= "1.0.3.0/24"
121 r4_ipv4_loopback
= "1.0.4.0/24"
122 r1_ipv6_loopback
= "2001:db8:f::1:0/120"
123 r2_ipv6_loopback
= "2001:db8:f::2:0/120"
124 r3_ipv6_loopback
= "2001:db8:f::3:0/120"
125 r4_ipv6_loopback
= "2001:db8:f::4:0/120"
127 r0_connected_address_ipv4
= "192.168.0.0/24"
128 r0_connected_address_ipv6
= "fd00::/64"
129 r1_connected_address_ipv4
= "192.168.1.0/24"
130 r1_connected_address_ipv6
= "fd00:0:0:1::/64"
131 r3_connected_address_ipv4
= "192.168.2.0/24"
132 r3_connected_address_ipv6
= "fd00:0:0:2::/64"
133 r4_connected_address_ipv4
= "192.168.3.0/24"
134 r4_connected_address_ipv6
= "fd00:0:0:3::/64"
137 def setup_module(mod
):
139 Sets up the pytest environment
144 # Required linux kernel version for this suite to run.
145 result
= required_linux_kernel_version("4.15")
146 if result
is not True:
147 pytest
.skip("Kernel requirements are not met")
149 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
150 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
151 logger
.info("=" * 40)
153 logger
.info("Running setup_module to create topology")
155 # This function initiates the topology build with Topogen...
156 json_file
= "{}/bgp_default_originate_topo1.json".format(CWD
)
157 tgen
= Topogen(json_file
, mod
.__name
__)
159 topo
= tgen
.json_topo
160 # ... and here it calls Mininet initialization functions.
162 # Starting topology, create tmp files which are loaded to routers
163 # to start daemons and then start routers
166 # Creating configuration from JSON
167 build_config_from_json(tgen
, topo
)
170 global BGP_CONVERGENCE
171 global DEFAULT_ROUTES
172 global DEFAULT_ROUTE_NXT_HOP_R1
, DEFAULT_ROUTE_NXT_HOP_R3
173 global R0_NETWORK_LOOPBACK
, R0_NETWORK_LOOPBACK_NXTHOP
, R1_NETWORK_LOOPBACK
, R1_NETWORK_LOOPBACK_NXTHOP
174 global R0_NETWORK_CONNECTED
, R0_NETWORK_CONNECTED_NXTHOP
, R1_NETWORK_CONNECTED
, R1_NETWORK_CONNECTED_NXTHOP
175 global R4_NETWORK_LOOPBACK
, R4_NETWORK_LOOPBACK_NXTHOP
, R3_NETWORK_LOOPBACK
, R3_NETWORK_LOOPBACK_NXTHOP
176 global R4_NETWORK_CONNECTED
, R4_NETWORK_CONNECTED_NXTHOP
, R3_NETWORK_CONNECTED
, R3_NETWORK_CONNECTED_NXTHOP
178 ADDR_TYPES
= check_address_types()
179 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
180 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
183 # There are the global varibles used through out the file these are acheived only after building the topology.
185 r0_loopback_address_ipv4
= topo
["routers"]["r0"]["links"]["lo"]["ipv4"]
186 r0_loopback_address_ipv4_nxt_hop
= topo
["routers"]["r0"]["links"]["r1"][
189 r0_loopback_address_ipv6
= topo
["routers"]["r0"]["links"]["lo"]["ipv6"]
190 r0_loopback_address_ipv6_nxt_hop
= topo
["routers"]["r0"]["links"]["r1"][
194 r1_loopback_address_ipv4
= topo
["routers"]["r1"]["links"]["lo"]["ipv4"]
195 r1_loopback_address_ipv4_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"][
198 r1_loopback_address_ipv6
= topo
["routers"]["r1"]["links"]["lo"]["ipv6"]
199 r1_loopback_address_ipv6_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"][
203 r4_loopback_address_ipv4
= topo
["routers"]["r4"]["links"]["lo"]["ipv4"]
204 r4_loopback_address_ipv4_nxt_hop
= topo
["routers"]["r4"]["links"]["r3"][
207 r4_loopback_address_ipv6
= topo
["routers"]["r4"]["links"]["lo"]["ipv6"]
208 r4_loopback_address_ipv6_nxt_hop
= topo
["routers"]["r4"]["links"]["r3"][
212 r3_loopback_address_ipv4
= topo
["routers"]["r3"]["links"]["lo"]["ipv4"]
213 r3_loopback_address_ipv4_nxt_hop
= topo
["routers"]["r3"]["links"]["r2"][
216 r3_loopback_address_ipv6
= topo
["routers"]["r3"]["links"]["lo"]["ipv6"]
217 r3_loopback_address_ipv6_nxt_hop
= topo
["routers"]["r3"]["links"]["r2"][
221 R0_NETWORK_LOOPBACK
= {
222 "ipv4": r0_loopback_address_ipv4
,
223 "ipv6": r0_loopback_address_ipv6
,
225 R0_NETWORK_LOOPBACK_NXTHOP
= {
226 "ipv4": r0_loopback_address_ipv4_nxt_hop
,
227 "ipv6": r0_loopback_address_ipv6_nxt_hop
,
230 R1_NETWORK_LOOPBACK
= {
231 "ipv4": r1_loopback_address_ipv4
,
232 "ipv6": r1_loopback_address_ipv6
,
234 R1_NETWORK_LOOPBACK_NXTHOP
= {
235 "ipv4": r1_loopback_address_ipv4_nxt_hop
,
236 "ipv6": r1_loopback_address_ipv6_nxt_hop
,
239 R0_NETWORK_CONNECTED
= {
240 "ipv4": r0_connected_address_ipv4
,
241 "ipv6": r0_connected_address_ipv6
,
243 R0_NETWORK_CONNECTED_NXTHOP
= {
244 "ipv4": r0_loopback_address_ipv4_nxt_hop
,
245 "ipv6": r0_loopback_address_ipv6_nxt_hop
,
248 R1_NETWORK_CONNECTED
= {
249 "ipv4": r1_connected_address_ipv4
,
250 "ipv6": r1_connected_address_ipv6
,
252 R1_NETWORK_CONNECTED_NXTHOP
= {
253 "ipv4": r1_loopback_address_ipv4_nxt_hop
,
254 "ipv6": r1_loopback_address_ipv6_nxt_hop
,
257 R4_NETWORK_LOOPBACK
= {
258 "ipv4": r4_loopback_address_ipv4
,
259 "ipv6": r4_loopback_address_ipv6
,
261 R4_NETWORK_LOOPBACK_NXTHOP
= {
262 "ipv4": r4_loopback_address_ipv4_nxt_hop
,
263 "ipv6": r4_loopback_address_ipv6_nxt_hop
,
266 R3_NETWORK_LOOPBACK
= {
267 "ipv4": r3_loopback_address_ipv4
,
268 "ipv6": r3_loopback_address_ipv6
,
270 R3_NETWORK_LOOPBACK_NXTHOP
= {
271 "ipv4": r3_loopback_address_ipv4_nxt_hop
,
272 "ipv6": r3_loopback_address_ipv6_nxt_hop
,
275 R4_NETWORK_CONNECTED
= {
276 "ipv4": r4_connected_address_ipv4
,
277 "ipv6": r4_connected_address_ipv6
,
279 R4_NETWORK_CONNECTED_NXTHOP
= {
280 "ipv4": r4_loopback_address_ipv4_nxt_hop
,
281 "ipv6": r4_loopback_address_ipv6_nxt_hop
,
284 R3_NETWORK_CONNECTED
= {
285 "ipv4": r3_connected_address_ipv4
,
286 "ipv6": r3_connected_address_ipv6
,
288 R3_NETWORK_CONNECTED_NXTHOP
= {
289 "ipv4": r3_loopback_address_ipv4_nxt_hop
,
290 "ipv6": r3_loopback_address_ipv6_nxt_hop
,
293 # populating the nexthop for default routes
295 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
297 interface
= topo
["routers"]["r1"]["links"]["r2"]["interface"]
298 ipv6_link_local
= get_frr_ipv6_linklocal(tgen
, "r1", intf
=interface
)
299 ipv4_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"]["ipv4"].split("/")[0]
300 ipv6_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"]["ipv6"].split("/")[0]
301 DEFAULT_ROUTE_NXT_HOP_R1
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local
}
303 interface
= topo
["routers"]["r3"]["links"]["r2"]["interface"]
304 ipv6_link_local
= get_frr_ipv6_linklocal(tgen
, "r3", intf
=interface
)
305 ipv4_nxt_hop
= topo
["routers"]["r3"]["links"]["r2"]["ipv4"].split("/")[0]
306 ipv6_nxt_hop
= topo
["routers"]["r3"]["links"]["r2"]["ipv6"].split("/")[0]
307 DEFAULT_ROUTE_NXT_HOP_R3
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local
}
309 logger
.info("Running setup_module() done")
312 def teardown_module():
313 """Teardown the pytest environment"""
315 logger
.info("Running teardown_module to delete topology")
319 # Stop toplogy and Remove tmp files
323 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
325 logger
.info("=" * 40)
328 #####################################################
332 #####################################################
335 def configure_gr_followed_by_clear(tgen
, topo
, input_dict
, tc_name
, dut
, peer
):
337 This function groups the repetitive function calls into one function.
339 result
= create_router_bgp(tgen
, topo
, input_dict
)
340 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
344 #####################################################
348 #####################################################
351 def test_verify_bgp_default_originate_route_map_in_OUT_p1(request
):
353 test_verify_bgp_default_originate_route_map_in_OUT_p1
356 global BGP_CONVERGENCE
359 tc_name
= request
.node
.name
360 write_test_header(tc_name
)
362 # Don't run this test if we have any failure.
363 if tgen
.routers_have_failure():
364 check_router_status(tgen
)
365 reset_config_on_routers(tgen
)
367 if BGP_CONVERGENCE
!= True:
368 pytest
.skip("skipped because of BGP Convergence failure")
370 step("Configure IPv4 and IPv6 , EBGP neighbor between R3 and R2")
371 step("Configure IPv4 and IPv6 IBGP neighbor between R3 and R4")
372 r0_local_as
= topo
["routers"]["r0"]["bgp"]["local_as"]
373 r1_local_as
= topo
["routers"]["r1"]["bgp"]["local_as"]
374 r2_local_as
= topo
["routers"]["r2"]["bgp"]["local_as"]
375 r3_local_as
= topo
["routers"]["r3"]["bgp"]["local_as"]
376 r4_local_as
= topo
["routers"]["r4"]["bgp"]["local_as"]
380 "local_as": r0_local_as
,
385 "local_as": r1_local_as
,
390 "local_as": r2_local_as
,
404 result
= modify_as_number(tgen
, topo
, input_dict
)
406 assert result
is True
407 except AssertionError:
408 logger
.info("Expected behaviour: {}".format(result
))
409 logger
.info("BGP config is not created because of invalid ASNs")
410 step("After changing the BGP AS Path Verify the BGP Convergence")
411 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
412 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
417 "Configure 2 IPv4 and 2 IPv6, Static route on R4 with next-hop as Null0 IPv4 route Sv41, Sv42, IPv6 route Sv61 Sv62"
419 for addr_type
in ADDR_TYPES
:
420 static_routes_input
= {
424 "network": [NETWORK1_1
[addr_type
]],
425 "next_hop": NEXT_HOP_IP
[addr_type
],
428 "network": [NETWORK2_1
[addr_type
]],
429 "next_hop": NEXT_HOP_IP
[addr_type
],
434 result
= create_static_routes(tgen
, static_routes_input
)
435 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
439 step("verify IPv4 and IPv6 static route are configured and up on R4")
440 for addr_type
in ADDR_TYPES
:
441 static_routes_input
= {
445 "network": [NETWORK1_1
[addr_type
]],
446 "next_hop": NEXT_HOP_IP
[addr_type
],
449 "network": [NETWORK2_1
[addr_type
]],
450 "next_hop": NEXT_HOP_IP
[addr_type
],
455 result
= verify_fib_routes(tgen
, addr_type
, "r4", static_routes_input
)
456 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
460 step("Configure redistribute static knob on R4 , for R4 to R3 neighbor ")
461 redistribute_static
= {
465 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
466 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
471 result
= create_router_bgp(tgen
, topo
, redistribute_static
)
472 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
476 {"network": NETWORK1_1
["ipv4"], "nexthop": NEXT_HOP_IP
["ipv4"]},
477 {"network": NETWORK2_1
["ipv4"], "nexthop": NEXT_HOP_IP
["ipv4"]},
480 {"network": NETWORK1_1
["ipv6"], "nexthop": NEXT_HOP_IP
["ipv4"]},
481 {"network": NETWORK2_1
["ipv6"], "nexthop": NEXT_HOP_IP
["ipv4"]},
484 result
= verify_bgp_advertised_routes_from_neighbor(
485 tgen
, topo
, dut
="r4", peer
="r3", expected_routes
=expected_routes
487 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
490 "After redistribute static verify the routes is recevied in router R3 in RIB and FIB"
492 for addr_type
in ADDR_TYPES
:
493 static_routes_input
= {
497 "network": [NETWORK1_1
[addr_type
]],
498 "next_hop": NEXT_HOP_IP
[addr_type
],
501 "network": [NETWORK2_1
[addr_type
]],
502 "next_hop": NEXT_HOP_IP
[addr_type
],
507 result
= verify_fib_routes(tgen
, addr_type
, "r3", static_routes_input
)
508 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
511 result
= verify_bgp_rib(tgen
, addr_type
, "r3", static_routes_input
)
512 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
517 "Configure IPv4 prefix-list Pv4 and and IPv6 prefix-list Pv6 on R3 to match BGP route Sv41, IPv6 route Sv61 with permit option "
526 "network": NETWORK1_1
["ipv4"],
535 "network": NETWORK1_1
["ipv6"],
543 result
= create_prefix_lists(tgen
, input_dict_3
)
544 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
546 step("verify IPv4 and IPv6 Prefix list got configured on R3")
547 input_dict
= {"r3": {"prefix_lists": ["Pv4", "Pv6"]}}
548 result
= verify_prefix_lists(tgen
, input_dict
)
549 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
552 "Configure IPv4 and IPv6 route-map RMv4 and RMv6 matching prefix-list Pv4 and Pv6 with permit option "
561 "match": {"ipv4": {"prefix_lists": "Pv4"}},
568 "match": {"ipv6": {"prefix_lists": "Pv6"}},
574 result
= create_route_maps(tgen
, input_dict_3
)
575 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
578 "Configure IPv4 prefix-list Pv42 and and IPv6 prefix-list Pv62 on R3 to match BGP route Sv42, IPv6 route Sv62 with deny option"
585 {"seqid": "1", "network": NETWORK2_1
["ipv4"], "action": "deny"}
590 {"seqid": "1", "network": NETWORK2_1
["ipv6"], "action": "deny"}
596 result
= create_prefix_lists(tgen
, input_dict_3
)
597 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
599 step("verify IPv4 and IPv6 Prefix list got configured on R3")
600 input_dict
= {"r3": {"prefix_lists": ["Pv42", "Pv62"]}}
601 result
= verify_prefix_lists(tgen
, input_dict
)
602 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
605 "Configure IPv4 and IPv6 route-map (RMv42 and RMv62 )matching prefix-list Pv42 and Pv62 with permit option "
614 "match": {"ipv4": {"prefix_lists": "Pv42"}},
621 "match": {"ipv6": {"prefix_lists": "Pv62"}},
627 result
= create_route_maps(tgen
, input_dict_3
)
628 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
631 "Apply IPv4 and IPv6 route-map RMv4 and RMv6 with default-originate on R3 , for R3 to R2 peers and Apply IPv4 and IPv6 out route-map RMv42 and RMv62 on R3 , for R3 to R2 peers "
633 local_as
= get_dut_as_number(tgen
, "r3")
634 default_originate_config
= {
637 "local_as": local_as
,
640 "unicast": {"default_originate": {"r2": {"route_map": "RM4"}}}
643 "unicast": {"default_originate": {"r2": {"route_map": "RM6"}}}
649 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
650 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
653 updated_topo
["routers"]["r0"]["bgp"]["local_as"] = get_dut_as_number(tgen
, "r0")
654 updated_topo
["routers"]["r1"]["bgp"]["local_as"] = get_dut_as_number(tgen
, "r1")
655 updated_topo
["routers"]["r2"]["bgp"]["local_as"] = get_dut_as_number(tgen
, "r2")
656 updated_topo
["routers"]["r3"]["bgp"]["local_as"] = get_dut_as_number(tgen
, "r3")
657 updated_topo
["routers"]["r4"]["bgp"]["local_as"] = get_dut_as_number(tgen
, "r4")
660 "Apply IPv4 and IPv6 route-map RMv42 and RMv62 on R3 (OUT Direction), for R3 to R2 peers "
673 {"name": "RMv42", "direction": "out"}
688 {"name": "RMv62", "direction": "out"}
701 result
= create_router_bgp(tgen
, updated_topo
, input_dict_4
)
702 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
705 After applying route-map on neighbor verify default BGP route IPv4 IPv6 route populated in R2 BGP and routing table , verify using "show ip bgp json" "show ipv6 bgp json" "show ip route json" "show ip route json"
706 Sv42 and Sv62 route should not be present on R2
709 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
710 for addr_type
in ADDR_TYPES
:
711 static_routes_input
= {
715 "network": [DEFAULT_ROUTES
[addr_type
]],
716 "next_hop": DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
722 result
= verify_fib_routes(
727 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
729 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
733 result
= verify_bgp_rib(
738 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
740 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
744 for addr_type
in ADDR_TYPES
:
745 static_routes_input
= {
749 "network": [NETWORK1_1
[addr_type
]],
750 "next_hop": NEXT_HOP_IP
[addr_type
],
753 "network": [NETWORK2_1
[addr_type
]],
754 "next_hop": NEXT_HOP_IP
[addr_type
],
760 result
= verify_fib_routes(
761 tgen
, addr_type
, "r2", static_routes_input
, expected
=False
765 ), "Testcase {} : Failed \n Static routes are not expected due to conditions \nError: {}".format(
769 result
= verify_bgp_rib(
770 tgen
, addr_type
, "r2", static_routes_input
, expected
=False
774 ), "Testcase {} : Failed \n Static routes are not expected due to conditions\n Error: {}".format(
778 step("Change IPv4 prefix-list Pv42 and and IPv6 prefix-list Pv62 deny to permit")
786 "network": NETWORK2_1
["ipv4"],
795 "network": NETWORK2_1
["ipv6"],
803 result
= create_prefix_lists(tgen
, input_dict_3
)
804 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
806 step("verify IPv4 and IPv6 Prefix list got configured on R3")
807 input_dict
= {"r3": {"prefix_lists": ["Pv42", "Pv62"]}}
808 result
= verify_prefix_lists(tgen
, input_dict
)
809 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
811 NOTE
= """Default BGP route and IPv4 ( Sv42) , IPv6 (Sv62) route populated in R2 BGP and routing table"""
813 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
814 for addr_type
in ADDR_TYPES
:
815 static_routes_input
= {
819 "network": [DEFAULT_ROUTES
[addr_type
]],
820 "next_hop": DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
826 result
= verify_fib_routes(
831 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
833 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
837 result
= verify_bgp_rib(
842 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
844 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
848 for addr_type
in ADDR_TYPES
:
849 static_routes_input
= {
853 "network": [NETWORK2_1
[addr_type
]],
854 "next_hop": NEXT_HOP_IP
[addr_type
],
860 result
= verify_fib_routes(tgen
, addr_type
, "r2", static_routes_input
)
861 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
865 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
866 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
870 step("IPv4 prefix-list Pv4 and and IPv6 prefix-list Pv6 permit to deny ")
876 {"seqid": "1", "network": NETWORK1_1
["ipv4"], "action": "deny"}
881 {"seqid": "1", "network": NETWORK1_1
["ipv6"], "action": "deny"}
887 result
= create_prefix_lists(tgen
, input_dict_3
)
888 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
891 Verify default-originate route (IPv4 and IPv6 ) not present on R2
892 IPv4 ( Sv42) , IPv6 (Sv62) route populated in R2 BGP
895 for addr_type
in ADDR_TYPES
:
896 static_routes_input
= {
900 "network": [DEFAULT_ROUTES
[addr_type
]],
901 "next_hop": DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
907 result
= verify_fib_routes(
912 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
917 ), "Testcase {} : Failed \n default-route in FIB is not expected due to conditions \n Error: {}".format(
921 result
= verify_bgp_rib(
926 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
931 ), "Testcase {} : Failed \n default-route in RIB is not expected due to conditions \n Error: {}".format(
934 for addr_type
in ADDR_TYPES
:
935 static_routes_input
= {
939 "network": [NETWORK2_1
[addr_type
]],
940 "next_hop": NEXT_HOP_IP
[addr_type
],
946 result
= verify_fib_routes(tgen
, addr_type
, "r2", static_routes_input
)
947 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
951 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
952 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
956 write_test_footer(tc_name
)
958 def test_verify_bgp_default_originate_route_map_in_IN_p1(request
):
959 """Verify BGP default originate route-map with IN route-map"""
961 global BGP_CONVERGENCE
964 tc_name
= request
.node
.name
965 write_test_header(tc_name
)
967 # Don't run this test if we have any failure.
968 if tgen
.routers_have_failure():
969 check_router_status(tgen
)
970 reset_config_on_routers(tgen
)
972 if BGP_CONVERGENCE
!= True:
973 pytest
.skip("skipped because of BGP Convergence failure")
975 step("Configure IPv4 and IPv6 , EBGP neighbor between R1 and R2")
976 step("Configure IPv4 and IPv6 , IBGP neighbor between R1 and R0")
977 r0_local_as
= topo
["routers"]["r0"]["bgp"]["local_as"]
978 r1_local_as
= topo
["routers"]["r1"]["bgp"]["local_as"]
979 r2_local_as
= topo
["routers"]["r2"]["bgp"]["local_as"]
980 r3_local_as
= topo
["routers"]["r3"]["bgp"]["local_as"]
981 r4_local_as
= topo
["routers"]["r4"]["bgp"]["local_as"]
995 "local_as": r2_local_as
,
1000 "local_as": r3_local_as
,
1005 "local_as": r4_local_as
,
1009 result
= modify_as_number(tgen
, topo
, input_dict
)
1011 assert result
is True
1012 except AssertionError:
1013 logger
.info("Expected behaviour: {}".format(result
))
1014 logger
.info("BGP config is not created because of invalid ASNs")
1015 step("After changing the BGP AS Path Verify the BGP Convergence")
1017 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
1018 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
1023 "Configure 2 IPv4 and 2 IPv6, Static route on R0 with next-hop as Null0 IPv4 route Sv41, Sv42, IPv6 route Sv61 Sv62"
1025 for addr_type
in ADDR_TYPES
:
1026 static_routes_input
= {
1030 "network": [NETWORK1_1
[addr_type
]],
1031 "next_hop": NEXT_HOP_IP
[addr_type
],
1034 "network": [NETWORK2_1
[addr_type
]],
1035 "next_hop": NEXT_HOP_IP
[addr_type
],
1040 result
= create_static_routes(tgen
, static_routes_input
)
1041 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1045 step("verifyIPv4 and IPv6 static routes are configure and up on R0 ")
1046 for addr_type
in ADDR_TYPES
:
1047 static_routes_input
= {
1051 "network": [NETWORK1_1
[addr_type
]],
1052 "next_hop": NEXT_HOP_IP
[addr_type
],
1055 "network": [NETWORK2_1
[addr_type
]],
1056 "next_hop": NEXT_HOP_IP
[addr_type
],
1061 result
= verify_fib_routes(tgen
, addr_type
, "r0", static_routes_input
)
1062 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1067 "Configure redistribute static knob on R0 , for R0 to R1 IPv4 and IPv6 neighbor"
1069 redistribute_static
= {
1073 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1074 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1079 result
= create_router_bgp(tgen
, topo
, redistribute_static
)
1080 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1082 step("Verify IPv4 and IPv6 route received on R1 ")
1083 for addr_type
in ADDR_TYPES
:
1084 static_routes_input
= {
1088 "network": [NETWORK1_1
[addr_type
]],
1089 "next_hop": NEXT_HOP_IP
[addr_type
],
1092 "network": [NETWORK2_1
[addr_type
]],
1093 "next_hop": NEXT_HOP_IP
[addr_type
],
1098 result
= verify_fib_routes(tgen
, addr_type
, "r1", static_routes_input
)
1099 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1103 result
= verify_bgp_rib(tgen
, addr_type
, "r1", static_routes_input
)
1104 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1109 "Configure IPv4 prefix-list Pv4 and and IPv6 prefix-list Pv6 on R1 to match BGP route Sv41, Sv42, IPv6 route Sv61 Sv62"
1118 "network": NETWORK1_1
["ipv4"],
1123 "network": NETWORK2_1
["ipv4"],
1132 "network": NETWORK1_1
["ipv6"],
1137 "network": NETWORK2_1
["ipv6"],
1145 result
= create_prefix_lists(tgen
, input_dict_3
)
1146 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1148 step("verify IPv4 and IPv6 Prefix list got configured on R1")
1149 input_dict
= {"r1": {"prefix_lists": ["Pv4", "Pv6"]}}
1150 result
= verify_prefix_lists(tgen
, input_dict
)
1151 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1154 "Configure IPv4 and IPv6 route-map RMv4 and RMv6 matching prefix-list Pv4 and Pv6 with deny option on R1"
1163 "match": {"ipv4": {"prefix_lists": "Pv4"}},
1170 "match": {"ipv6": {"prefix_lists": "Pv6"}},
1176 result
= create_route_maps(tgen
, input_dict_3
)
1177 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1179 step("Apply route-map IN direction in R1 (R1 to R0) IPv4 and IPv6 neighbor")
1181 updated_topo
["routers"]["r0"]["bgp"]["local_as"] = get_dut_as_number(tgen
, "r0")
1182 updated_topo
["routers"]["r1"]["bgp"]["local_as"] = get_dut_as_number(tgen
, "r1")
1183 updated_topo
["routers"]["r2"]["bgp"]["local_as"] = get_dut_as_number(tgen
, "r2")
1184 updated_topo
["routers"]["r3"]["bgp"]["local_as"] = get_dut_as_number(tgen
, "r3")
1185 updated_topo
["routers"]["r4"]["bgp"]["local_as"] = get_dut_as_number(tgen
, "r4")
1187 local_as_r1
= get_dut_as_number(tgen
, dut
="r1")
1233 result
= create_router_bgp(tgen
, updated_topo
, input_dict_4
)
1234 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1236 STEP
= "After applying route-map verify that IPv4 route Sv41, Sv42, IPv6 route Sv61 Sv62 should not present on R1 BGP and routing table "
1240 "After applying route-map verify that IPv4 route Sv41, Sv42, IPv6 route Sv61 Sv62 should not present on R1 "
1242 for addr_type
in ADDR_TYPES
:
1243 static_routes_input
= {
1247 "network": [NETWORK1_1
[addr_type
]],
1248 "next_hop": NEXT_HOP_IP
[addr_type
],
1251 "network": [NETWORK2_1
[addr_type
]],
1252 "next_hop": NEXT_HOP_IP
[addr_type
],
1258 result
= verify_fib_routes(
1259 tgen
, addr_type
, "r1", static_routes_input
, expected
=False
1263 ), "Testcase {} : Failed \n default-route in FIB is not expected due to conditions \nError: {}".format(
1267 result
= verify_bgp_rib(
1268 tgen
, addr_type
, "r1", static_routes_input
, expected
=False
1272 ), "Testcase {} : Failed \n default-route in FIB is not expected due to conditions \nError: {}".format(
1275 # Routes should come to dut but not the shown in RIB thus verifying using show ip bgp nbr xxx received route
1277 " Verify the received routes \n using 'show ip bgp nbr xxx received route' in Router R1"
1281 {"network": NETWORK1_1
["ipv4"], "nexthop": NEXT_HOP_IP
["ipv4"]},
1282 {"network": NETWORK2_1
["ipv4"], "nexthop": NEXT_HOP_IP
["ipv4"]},
1285 {"network": NETWORK1_1
["ipv6"], "nexthop": NEXT_HOP_IP
["ipv6"]},
1286 {"network": NETWORK2_1
["ipv6"], "nexthop": NEXT_HOP_IP
["ipv6"]},
1289 result
= verify_bgp_received_routes_from_neighbor(
1290 tgen
, topo
, dut
="r1", peer
="r0", expected_routes
=expected_routes
1292 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1294 step("Configure default-originate on R1 for R1 to R2 IPv4 and IPv6 neighbor ")
1295 local_as_r1
= get_dut_as_number(tgen
, dut
="r1")
1296 default_originate_config
= {
1299 "local_as": local_as_r1
,
1301 "ipv4": {"unicast": {"default_originate": {"r2": {}}}},
1302 "ipv6": {"unicast": {"default_originate": {"r2": {}}}},
1307 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
1308 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1311 "Verify Default originate knob is configured and default route advertised to R2 , verify on R1 "
1315 {"network": "0.0.0.0/0", "nexthop": ""},
1318 {"network": "::/0", "nexthop": ""},
1321 result
= verify_bgp_advertised_routes_from_neighbor(
1322 tgen
, topo
, dut
="r1", peer
="r2", expected_routes
=expected_routes
1324 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1326 step("Verify the Default route Route in FIB in R2")
1327 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1329 for addr_type
in ADDR_TYPES
:
1330 static_routes_input
= {
1334 "network": [DEFAULT_ROUTES
[addr_type
]],
1335 "next_hop": DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1340 result
= verify_fib_routes(
1344 static_routes_input
,
1345 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1347 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1351 step("Change route-map RMv4 and RMv6 from deny to permit")
1359 "match": {"ipv4": {"prefix_lists": "Pv4"}},
1366 "match": {"ipv6": {"prefix_lists": "Pv6"}},
1372 result
= create_route_maps(tgen
, input_dict_3
)
1373 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1375 NOTE
= """After changing route-map to permit verify that IPv4 routes Sv41, Sv42, IPv6 routes Sv61 Sv62 present on R1 BGP and routing table , using "show ip route " "show ip bgp nbr xxx received route " "show ipv6 route " "show ipv6 bgp nbr xxx receied route """
1378 "ipv4": [{"network": NETWORK1_1
["ipv4"], "nexthop": NEXT_HOP_IP
["ipv4"]}],
1379 "ipv6": [{"network": NETWORK1_1
["ipv6"], "nexthop": NEXT_HOP_IP
["ipv4"]}],
1381 result
= verify_bgp_received_routes_from_neighbor(
1382 tgen
, topo
, dut
="r1", peer
="r0", expected_routes
=expected_routes
1384 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1385 for addr_type
in ADDR_TYPES
:
1386 static_routes_input
= {
1390 "network": [NETWORK1_1
[addr_type
]],
1391 "next_hop": NEXT_HOP_IP
[addr_type
],
1394 "network": [NETWORK2_1
[addr_type
]],
1395 "next_hop": NEXT_HOP_IP
[addr_type
],
1400 result
= verify_bgp_rib(tgen
, addr_type
, "r1", static_routes_input
)
1401 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1404 result
= verify_fib_routes(tgen
, addr_type
, "r1", static_routes_input
)
1405 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1409 step("Configure default static route (IPv4 and IPv6) on R2 nexthop as R1 ")
1411 r1_r2_ipv4_neighbor
= topo
["routers"]["r1"]["links"]["r2"]["ipv4"].split("/")[0]
1412 r1_r2_ipv6_neighbor
= topo
["routers"]["r1"]["links"]["r2"]["ipv6"].split("/")[0]
1413 NEXT_HOP_IP_R1
["ipv4"] = r1_r2_ipv4_neighbor
1414 NEXT_HOP_IP_R1
["ipv6"] = r1_r2_ipv6_neighbor
1415 static_routes_input
= {
1419 "network": "0.0.0.0/0",
1420 "next_hop": NEXT_HOP_IP_R1
["ipv4"],
1423 "network": "0::0/0",
1424 "next_hop": NEXT_HOP_IP_R1
["ipv6"],
1429 result
= create_static_routes(tgen
, static_routes_input
)
1430 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1433 "Verify Static default route is taking preference over BGP default routes , BGP default route is inactive IN RIB and static is up and installed in RIB and FIB "
1435 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1436 ipv4_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"]["ipv4"].split("/")[0]
1437 ipv6_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"]["ipv6"].split("/")[0]
1438 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1439 DEFAULT_ROUTE_NXT_HOP
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_nxt_hop
}
1441 for addr_type
in ADDR_TYPES
:
1442 static_routes_input
= {
1446 "network": [DEFAULT_ROUTES
[addr_type
]],
1447 "next_hop": DEFAULT_ROUTE_NXT_HOP
[addr_type
],
1448 "protocol": "static",
1453 result
= verify_bgp_rib(
1457 static_routes_input
,
1458 next_hop
=DEFAULT_ROUTE_NXT_HOP
[addr_type
],
1460 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1463 result
= verify_fib_routes(
1467 static_routes_input
,
1468 next_hop
=DEFAULT_ROUTE_NXT_HOP
[addr_type
],
1470 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1473 write_test_footer(tc_name
)
1475 def test_verify_default_originate_after_removing_default_originate_p1(request
):
1476 """Verify BGP default route after removing default-originate"""
1478 tgen
= get_topogen()
1479 global BGP_CONVERGENCE
1482 tc_name
= request
.node
.name
1483 write_test_header(tc_name
)
1484 tgen
= get_topogen()
1485 # Don't run this test if we have any failure.
1486 if tgen
.routers_have_failure():
1487 check_router_status(tgen
)
1488 reset_config_on_routers(tgen
)
1490 if BGP_CONVERGENCE
!= True:
1491 pytest
.skip("skipped because of BGP Convergence failure")
1493 step("Configure EBGP between R0 to R1 and IBGP between R1 to R2")
1494 step("Configure EBGP between R2 to R3 and IBGP between R3 to R4")
1495 r0_local_as
= topo
["routers"]["r0"]["bgp"]["local_as"]
1496 r1_local_as
= topo
["routers"]["r1"]["bgp"]["local_as"]
1497 r2_local_as
= topo
["routers"]["r2"]["bgp"]["local_as"]
1498 r3_local_as
= topo
["routers"]["r3"]["bgp"]["local_as"]
1499 r4_local_as
= topo
["routers"]["r4"]["bgp"]["local_as"]
1503 "local_as": r0_local_as
,
1527 result
= modify_as_number(tgen
, topo
, input_dict
)
1529 assert result
is True
1530 except AssertionError:
1531 logger
.info("Expected behaviour: {}".format(result
))
1532 logger
.info("BGP config is not created because of invalid ASNs")
1533 step("After changing the BGP AS Path Verify the BGP Convergence")
1534 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
1535 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
1539 step("Configure IPv4 and IPv6 static route on R0 and R4")
1540 for addr_type
in ADDR_TYPES
:
1541 static_routes_input
= {
1545 "network": [NETWORK1_1
[addr_type
]],
1546 "next_hop": NEXT_HOP_IP
[addr_type
],
1553 "network": [NETWORK2_1
[addr_type
]],
1554 "next_hop": NEXT_HOP_IP
[addr_type
],
1559 result
= create_static_routes(tgen
, static_routes_input
)
1560 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1564 step("verify IPv4 and IPv6 static route are configured and up on R0 and R4")
1565 for addr_type
in ADDR_TYPES
:
1566 static_routes_input
= {
1570 "network": [NETWORK1_1
[addr_type
]],
1571 "next_hop": NEXT_HOP_IP
[addr_type
],
1576 result
= verify_fib_routes(tgen
, addr_type
, "r0", static_routes_input
)
1577 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1580 for addr_type
in ADDR_TYPES
:
1581 static_routes_input
= {
1585 "network": [NETWORK2_1
[addr_type
]],
1586 "next_hop": NEXT_HOP_IP
[addr_type
],
1591 result
= verify_fib_routes(tgen
, addr_type
, "r4", static_routes_input
)
1592 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1596 "Configure redistribute connected and static on R0 (R0-R1) on R4 ( R4-R3) IPv4 and IPv6 address family "
1598 redistribute_static
= {
1605 {"redist_type": "static"},
1606 {"redist_type": "connected"},
1613 {"redist_type": "static"},
1614 {"redist_type": "connected"},
1627 {"redist_type": "static"},
1628 {"redist_type": "connected"},
1635 {"redist_type": "static"},
1636 {"redist_type": "connected"},
1647 "unicast": {"redistribute": [{"redist_type": "connected"}]}
1650 "unicast": {"redistribute": [{"redist_type": "connected"}]}
1659 "unicast": {"redistribute": [{"redist_type": "connected"}]}
1662 "unicast": {"redistribute": [{"redist_type": "connected"}]}
1668 result
= create_router_bgp(tgen
, topo
, redistribute_static
)
1669 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1671 step("verify IPv4 and IPv6 static route are configured and up on R1 and R3")
1672 for addr_type
in ADDR_TYPES
:
1673 static_routes_input
= {
1677 "network": [NETWORK1_1
[addr_type
]],
1678 "next_hop": NEXT_HOP_IP
[addr_type
],
1681 "network": [R0_NETWORK_LOOPBACK
[addr_type
]],
1682 "next_hop": R0_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
1685 "network": [R0_NETWORK_CONNECTED
[addr_type
]],
1686 "next_hop": R0_NETWORK_CONNECTED_NXTHOP
[addr_type
],
1689 "network": [R1_NETWORK_LOOPBACK
[addr_type
]],
1690 "next_hop": R1_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
1693 "network": [R1_NETWORK_CONNECTED
[addr_type
]],
1694 "next_hop": R1_NETWORK_CONNECTED_NXTHOP
[addr_type
],
1700 result
= verify_fib_routes(tgen
, addr_type
, "r1", static_routes_input
)
1701 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1704 result
= verify_bgp_rib(tgen
, addr_type
, "r1", static_routes_input
)
1705 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1709 step("verify IPv4 and IPv6 static route are configured and up on R1 and R3")
1710 for addr_type
in ADDR_TYPES
:
1711 static_routes_input
= {
1715 "network": [NETWORK2_1
[addr_type
]],
1716 "next_hop": NEXT_HOP_IP
[addr_type
],
1719 "network": [R3_NETWORK_LOOPBACK
[addr_type
]],
1720 "next_hop": R3_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
1723 "network": [R3_NETWORK_CONNECTED
[addr_type
]],
1724 "next_hop": R3_NETWORK_CONNECTED_NXTHOP
[addr_type
],
1727 "network": [R4_NETWORK_LOOPBACK
[addr_type
]],
1728 "next_hop": R4_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
1731 "network": [R4_NETWORK_CONNECTED
[addr_type
]],
1732 "next_hop": R4_NETWORK_CONNECTED_NXTHOP
[addr_type
],
1738 result
= verify_fib_routes(tgen
, addr_type
, "r3", static_routes_input
)
1739 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1743 result
= verify_bgp_rib(tgen
, addr_type
, "r3", static_routes_input
)
1744 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1749 "Configure default-originate on R1 for R1 to R2 neighbor for IPv4 and IPv6 peer "
1751 local_as
= get_dut_as_number(tgen
, dut
="r1")
1752 default_originate_config
= {
1755 "local_as": local_as
,
1757 "ipv4": {"unicast": {"default_originate": {"r2": {}}}},
1758 "ipv6": {"unicast": {"default_originate": {"r2": {}}}},
1763 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
1764 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1766 "Verify all the static , connected and loopback routes from R0,R1,R3 and R4 is receieved on R2 "
1768 for addr_type
in ADDR_TYPES
:
1769 static_routes_input
= {
1773 "network": [NETWORK1_1
[addr_type
]],
1774 "next_hop": NEXT_HOP_IP
[addr_type
],
1777 "network": [NETWORK2_1
[addr_type
]],
1778 "next_hop": NEXT_HOP_IP
[addr_type
],
1781 "network": [R0_NETWORK_LOOPBACK
[addr_type
]],
1782 "next_hop": R0_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
1785 "network": [R0_NETWORK_CONNECTED
[addr_type
]],
1786 "next_hop": R0_NETWORK_CONNECTED_NXTHOP
[addr_type
],
1789 "network": [R1_NETWORK_LOOPBACK
[addr_type
]],
1790 "next_hop": R1_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
1793 "network": [R1_NETWORK_CONNECTED
[addr_type
]],
1794 "next_hop": R1_NETWORK_CONNECTED_NXTHOP
[addr_type
],
1797 "network": [R3_NETWORK_LOOPBACK
[addr_type
]],
1798 "next_hop": R3_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
1801 "network": [R3_NETWORK_CONNECTED
[addr_type
]],
1802 "next_hop": R3_NETWORK_CONNECTED_NXTHOP
[addr_type
],
1805 "network": [R4_NETWORK_LOOPBACK
[addr_type
]],
1806 "next_hop": R4_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
1809 "network": [R4_NETWORK_CONNECTED
[addr_type
]],
1810 "next_hop": R4_NETWORK_CONNECTED_NXTHOP
[addr_type
],
1816 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
1817 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1820 result
= verify_fib_routes(tgen
, addr_type
, "r2", static_routes_input
)
1821 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1825 step("Verify the Default Originate on R2 nexthop as R1")
1827 interface
= topo
["routers"]["r1"]["links"]["r2"]["interface"]
1828 ipv6_link_local
= get_frr_ipv6_linklocal(tgen
, "r1", intf
=interface
)
1829 ipv4_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"]["ipv4"].split("/")[0]
1830 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1831 DEFAULT_ROUTE_NXT_HOP
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local
}
1833 result
= verify_rib_default_route(
1837 routes
=DEFAULT_ROUTES
,
1838 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP
,
1843 ), "Testcase {} : Failed \n Error: After Deactivating the BGP neighbor the default route is expected but found in RIB -> {}".format(
1847 result
= verify_fib_default_route(
1851 routes
=DEFAULT_ROUTES
,
1852 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP
,
1857 ), "Testcase {} : Failed \n Error: After Deactivating the BGP neighbor the default route is expected but found in FIB -> {}".format(
1862 "Configure default-originate on R3 for R3 to R2 neighbor for IPv4 and IPv6 peer "
1864 local_as
= get_dut_as_number(tgen
, dut
="r3")
1865 default_originate_config
= {
1868 "local_as": local_as
,
1870 "ipv4": {"unicast": {"default_originate": {"r2": {}}}},
1871 "ipv6": {"unicast": {"default_originate": {"r2": {}}}},
1876 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
1877 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1878 STEP
= """After configuring the Default Originate From R3 --> R2
1879 Both Default routes from R1 and R3 Should present in R2 BGP RIB
1880 The Deafult Route from iBGP is prefferedover EBGP thus
1881 Default Route From R1->r2 should only present in R2 FIB """
1884 interface
= topo
["routers"]["r3"]["links"]["r2"]["interface"]
1885 ipv6_link_local
= get_frr_ipv6_linklocal(tgen
, "r3", intf
=interface
)
1886 ipv4_nxt_hop
= topo
["routers"]["r3"]["links"]["r2"]["ipv4"].split("/")[0]
1887 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1888 DEFAULT_ROUTE_NXT_HOP
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local
}
1889 result
= verify_fib_default_route(
1893 routes
=DEFAULT_ROUTES
,
1894 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP
,
1899 ), "Testcase {} : Failed \n Error: Only IBGP default originate is expected in FIB over EBGP {}".format(
1903 result
= verify_rib_default_route(
1907 routes
=DEFAULT_ROUTES
,
1908 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP
,
1911 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1914 "No change on static and connected routes which got advertised from R0, R1, R3 and R4"
1916 for addr_type
in ADDR_TYPES
:
1917 static_routes_input
= {
1921 "network": [NETWORK1_1
[addr_type
]],
1922 "next_hop": NEXT_HOP_IP
[addr_type
],
1925 "network": [NETWORK2_1
[addr_type
]],
1926 "next_hop": NEXT_HOP_IP
[addr_type
],
1929 "network": [R0_NETWORK_LOOPBACK
[addr_type
]],
1930 "next_hop": R0_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
1933 "network": [R0_NETWORK_CONNECTED
[addr_type
]],
1934 "next_hop": R0_NETWORK_CONNECTED_NXTHOP
[addr_type
],
1937 "network": [R1_NETWORK_LOOPBACK
[addr_type
]],
1938 "next_hop": R1_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
1941 "network": [R1_NETWORK_CONNECTED
[addr_type
]],
1942 "next_hop": R1_NETWORK_CONNECTED_NXTHOP
[addr_type
],
1945 "network": [R3_NETWORK_LOOPBACK
[addr_type
]],
1946 "next_hop": R3_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
1949 "network": [R3_NETWORK_CONNECTED
[addr_type
]],
1950 "next_hop": R3_NETWORK_CONNECTED_NXTHOP
[addr_type
],
1953 "network": [R4_NETWORK_LOOPBACK
[addr_type
]],
1954 "next_hop": R4_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
1957 "network": [R4_NETWORK_CONNECTED
[addr_type
]],
1958 "next_hop": R4_NETWORK_CONNECTED_NXTHOP
[addr_type
],
1964 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
1965 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1968 result
= verify_fib_routes(tgen
, addr_type
, "r2", static_routes_input
)
1969 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1974 " Remove default-originate on R1 for R1 to R2 neighbor for IPv4 and IPv6 peer "
1976 local_as
= get_dut_as_number(tgen
, dut
="r1")
1977 default_originate_config
= {
1980 "local_as": local_as
,
1983 "unicast": {"default_originate": {"r2": {"delete": True}}}
1986 "unicast": {"default_originate": {"r2": {"delete": True}}}
1992 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
1993 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1995 step("Verify the Default Originate reoute from R1 to r2 is removed in R2 ")
1996 interface
= topo
["routers"]["r1"]["links"]["r2"]["interface"]
1997 ipv6_link_local
= get_frr_ipv6_linklocal(tgen
, "r1", intf
=interface
)
1998 ipv4_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"]["ipv4"].split("/")[0]
1999 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
2000 DEFAULT_ROUTE_NXT_HOP
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local
}
2001 result
= verify_fib_default_route(
2005 routes
=DEFAULT_ROUTES
,
2006 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP
,
2011 ), "Testcase {} : Failed \n After removing the default originate the route should not be present in FIB \n Error: {}".format(
2015 result
= verify_rib_default_route(
2019 routes
=DEFAULT_ROUTES
,
2020 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP
,
2025 ), "Testcase {} : Failed \n After removing the default originate the route should not be present in RIB \n Error: {}".format(
2029 NOTE
= """ after removing the Default originate from R1-->R2
2030 Verify the BGP Default route received from R3 is present in both BGP RIB and FIB on R2
2032 interface
= topo
["routers"]["r3"]["links"]["r2"]["interface"]
2033 ipv6_link_local
= get_frr_ipv6_linklocal(tgen
, "r3", intf
=interface
)
2034 ipv4_nxt_hop
= topo
["routers"]["r3"]["links"]["r2"]["ipv4"].split("/")[0]
2035 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
2036 DEFAULT_ROUTE_NXT_HOP
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local
}
2037 result
= verify_fib_default_route(
2041 routes
=DEFAULT_ROUTES
,
2042 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP
,
2045 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2047 result
= verify_rib_default_route(
2051 routes
=DEFAULT_ROUTES
,
2052 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP
,
2055 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2058 "No change on static and connected routes which got advertised from R0, R1, R3 and R4"
2060 for addr_type
in ADDR_TYPES
:
2061 static_routes_input
= {
2065 "network": [NETWORK1_1
[addr_type
]],
2066 "next_hop": NEXT_HOP_IP
[addr_type
],
2069 "network": [NETWORK2_1
[addr_type
]],
2070 "next_hop": NEXT_HOP_IP
[addr_type
],
2073 "network": [R0_NETWORK_LOOPBACK
[addr_type
]],
2074 "next_hop": R0_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
2077 "network": [R0_NETWORK_CONNECTED
[addr_type
]],
2078 "next_hop": R0_NETWORK_CONNECTED_NXTHOP
[addr_type
],
2081 "network": [R1_NETWORK_LOOPBACK
[addr_type
]],
2082 "next_hop": R1_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
2085 "network": [R1_NETWORK_CONNECTED
[addr_type
]],
2086 "next_hop": R1_NETWORK_CONNECTED_NXTHOP
[addr_type
],
2089 "network": [R3_NETWORK_LOOPBACK
[addr_type
]],
2090 "next_hop": R3_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
2093 "network": [R3_NETWORK_CONNECTED
[addr_type
]],
2094 "next_hop": R3_NETWORK_CONNECTED_NXTHOP
[addr_type
],
2097 "network": [R4_NETWORK_LOOPBACK
[addr_type
]],
2098 "next_hop": R4_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
2101 "network": [R4_NETWORK_CONNECTED
[addr_type
]],
2102 "next_hop": R4_NETWORK_CONNECTED_NXTHOP
[addr_type
],
2108 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
2109 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2112 result
= verify_fib_routes(tgen
, addr_type
, "r2", static_routes_input
)
2113 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2118 "Remove default-originate on R3 for R3 to R2 neighbor for IPv4 and IPv6 peer "
2120 local_as
= get_dut_as_number(tgen
, dut
="r3")
2121 default_originate_config
= {
2124 "local_as": local_as
,
2127 "unicast": {"default_originate": {"r2": {"delete": True}}}
2130 "unicast": {"default_originate": {"r2": {"delete": True}}}
2136 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
2137 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2140 "After removing default originate , verify default IPv4 and IPv6 BGP routes removed on R2 from R1 ( next-hop as R3) "
2142 interface
= topo
["routers"]["r3"]["links"]["r2"]["interface"]
2143 ipv6_link_local
= get_frr_ipv6_linklocal(tgen
, "r3", intf
=interface
)
2144 ipv4_nxt_hop
= topo
["routers"]["r3"]["links"]["r2"]["ipv4"].split("/")[0]
2145 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
2146 DEFAULT_ROUTE_NXT_HOP
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local
}
2147 result
= verify_fib_default_route(
2151 routes
=DEFAULT_ROUTES
,
2152 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP
,
2157 ), "Testcase {} : Failed \n After removing the default originate the route should not be present in FIB \n Error: {}".format(
2161 result
= verify_rib_default_route(
2165 routes
=DEFAULT_ROUTES
,
2166 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP
,
2171 ), "Testcase {} : Failed \n After removing the default originate the route should not be present in RIB \n Error: {}".format(
2175 "No change on static and connected routes which got advertised from R0, R1, R3 and R4"
2177 for addr_type
in ADDR_TYPES
:
2178 static_routes_input
= {
2182 "network": [NETWORK1_1
[addr_type
]],
2183 "next_hop": NEXT_HOP_IP
[addr_type
],
2186 "network": [NETWORK2_1
[addr_type
]],
2187 "next_hop": NEXT_HOP_IP
[addr_type
],
2190 "network": [R0_NETWORK_LOOPBACK
[addr_type
]],
2191 "next_hop": R0_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
2194 "network": [R0_NETWORK_CONNECTED
[addr_type
]],
2195 "next_hop": R0_NETWORK_CONNECTED_NXTHOP
[addr_type
],
2198 "network": [R1_NETWORK_LOOPBACK
[addr_type
]],
2199 "next_hop": R1_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
2202 "network": [R1_NETWORK_CONNECTED
[addr_type
]],
2203 "next_hop": R1_NETWORK_CONNECTED_NXTHOP
[addr_type
],
2206 "network": [R3_NETWORK_LOOPBACK
[addr_type
]],
2207 "next_hop": R3_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
2210 "network": [R3_NETWORK_CONNECTED
[addr_type
]],
2211 "next_hop": R3_NETWORK_CONNECTED_NXTHOP
[addr_type
],
2214 "network": [R4_NETWORK_LOOPBACK
[addr_type
]],
2215 "next_hop": R4_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
2218 "network": [R4_NETWORK_CONNECTED
[addr_type
]],
2219 "next_hop": R4_NETWORK_CONNECTED_NXTHOP
[addr_type
],
2225 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
2226 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2229 result
= verify_fib_routes(tgen
, addr_type
, "r2", static_routes_input
)
2230 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2233 write_test_footer(tc_name
)
2235 def test_verify_default_originate_route_with_GR_p1(request
):
2236 """ "Verify default-originate route with GR "
2238 tgen
= get_topogen()
2239 global BGP_CONVERGENCE
2242 tc_name
= request
.node
.name
2243 write_test_header(tc_name
)
2244 tgen
= get_topogen()
2245 # Don't run this test if we have any failure.
2246 if tgen
.routers_have_failure():
2247 check_router_status(tgen
)
2248 reset_config_on_routers(tgen
)
2250 if BGP_CONVERGENCE
!= True:
2251 pytest
.skip("skipped because of BGP Convergence failure")
2254 step("Configure IPV4 and IPV6 IBGP between R1 and R2 ")
2255 step("Configure IPV4 and IPV6 EBGP between R2 to R3 ")
2256 r0_local_as
= topo
['routers']['r0']['bgp']['local_as']
2257 r1_local_as
= topo
['routers']['r1']['bgp']['local_as']
2258 r2_local_as
= topo
['routers']['r2']['bgp']['local_as']
2259 r3_local_as
= topo
['routers']['r3']['bgp']['local_as']
2260 r4_local_as
= topo
['routers']['r4']['bgp']['local_as']
2264 "local_as": r0_local_as
,
2279 "local_as": r3_local_as
,
2284 "local_as": r4_local_as
,
2288 result
= modify_as_number(tgen
, topo
, input_dict
)
2290 assert result
is True
2291 except AssertionError:
2292 logger
.info("Expected behaviour: {}".format(result
))
2293 logger
.info("BGP config is not created because of invalid ASNs")
2294 step("After changing the BGP AS Path Verify the BGP Convergence")
2295 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
2296 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
2301 "Configure per peer Graceful restart on R2 ( restarting router) and R3 helper router "
2306 "local_as": get_dut_as_number(tgen
, "r2"),
2307 "graceful-restart": {
2308 "graceful-restart": True,
2309 "preserve-fw-state": True,
2315 "local_as": get_dut_as_number(tgen
, "r3"),
2316 "graceful-restart": {"graceful-restart-helper": True},
2321 configure_gr_followed_by_clear(tgen
, topo
, input_dict
, tc_name
, dut
="r2", peer
="r3")
2323 step("verify Graceful restart at R2")
2324 for addr_type
in ADDR_TYPES
:
2325 result
= verify_graceful_restart(
2326 tgen
, topo
, addr_type
, input_dict
, dut
="r2", peer
="r3"
2328 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
2331 "Configure default-originate on R1 for R1-R2 neighbor for IPv4 and IPv6 BGP peers "
2333 local_as
= get_dut_as_number(tgen
, dut
="r1")
2334 default_originate_config
= {
2337 "local_as": local_as
,
2341 "default_originate":{
2351 "default_originate":{
2363 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
2364 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2368 "R2 received default-originate routes and advertised it to R3 , verify on R2 and R3"
2370 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
2372 "After configuring default-originate command , verify default routes are advertised on R2 "
2374 for addr_type
in ADDR_TYPES
:
2375 static_routes_input
= {
2379 "network": [DEFAULT_ROUTES
[addr_type
]],
2380 "next_hop": DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
2386 result
= verify_fib_routes(tgen
, addr_type
, "r2", static_routes_input
,next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
])
2387 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2391 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
,next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
])
2392 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2397 step(" Kill BGPd session on R2")
2398 kill_router_daemons(tgen
, "r2", ["bgpd"])
2399 start_router_daemons(tgen
, "r2", ["bgpd"])
2401 step("verify default route is relearned after clear bgp on R2 on BGP RIB and")
2402 for addr_type
in ADDR_TYPES
:
2403 static_routes_input
= {
2407 "network": [DEFAULT_ROUTES
[addr_type
]],
2408 "next_hop": DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
2414 result
= verify_fib_routes(tgen
, addr_type
, "r2", static_routes_input
,next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
])
2415 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2419 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
,next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
])
2420 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2423 write_test_footer(tc_name
)
2425 if __name__
== "__main__":
2426 args
= ["-s"] + sys
.argv
[1:]
2427 sys
.exit(pytest
.main(args
))