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 1. Verify default-originate route with default static and network command
12 2. Verify default-originate route with aggregate summary command
13 3. Verfiy default-originate behaviour in ecmp
20 from copy
import deepcopy
21 from lib
.topolog
import logger
23 # pylint: disable=C0413
24 # Import topogen and topotest helpers
25 from lib
.topogen
import Topogen
, get_topogen
26 from lib
.topojson
import build_config_from_json
27 from lib
.topolog
import logger
30 verify_bgp_convergence
,
34 verify_rib_default_route
,
35 verify_fib_default_route
,
37 from lib
.common_config
import (
43 shutdown_bringup_interface
,
44 get_frr_ipv6_linklocal
,
50 reset_config_on_routers
,
55 # Save the Current Working Directory to find configuration files.
56 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
57 sys
.path
.append(os
.path
.join(CWD
, "../"))
58 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
60 # Required to instantiate the topology builder class.
62 # pylint: disable=C0413
63 # Import topogen and topotest helpers
67 NETWORK1_1
= {"ipv4": "198.51.1.1/32", "ipv6": "2001:DB8::1:1/128"}
68 NETWORK1_2
= {"ipv4": "198.51.1.2/32", "ipv6": "2001:DB8::1:2/128"}
69 NETWORK1_3
= {"ipv4": "198.51.1.3/32", "ipv6": "2001:DB8::1:3/128"}
70 NETWORK1_4
= {"ipv4": "198.51.1.4/32", "ipv6": "2001:DB8::1:4/128"}
71 NETWORK1_5
= {"ipv4": "198.51.1.5/32", "ipv6": "2001:DB8::1:5/128"}
76 {"network": "0.0.0.0/0"},
89 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
90 NEXT_HOP_IP
= {"ipv4": "Null0", "ipv6": "Null0"}
92 pytestmark
= [pytest
.mark
.bgpd
]
95 def setup_module(mod
):
97 Sets up the pytest environment
101 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
102 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
103 logger
.info("=" * 40)
105 logger
.info("Running setup_module to create topology")
107 # This function initiates the topology build with Topogen...
108 json_file
= "{}/bgp_default_originate_2links.json".format(CWD
)
109 tgen
= Topogen(json_file
, mod
.__name
__)
111 topo
= tgen
.json_topo
112 # ... and here it calls Mininet initialization functions.
114 # Starting topology, create tmp files which are loaded to routers
115 # to start daemons and then start routers
118 # Creating configuration from JSON
119 build_config_from_json(tgen
, topo
)
122 global BGP_CONVERGENCE
123 global DEFAULT_ROUTES
124 global DEFAULT_ROUTE_NXT_HOP_LINK1
, DEFAULT_ROUTE_NXT_HOP_LINK2
125 ADDR_TYPES
= check_address_types()
126 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
127 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
131 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
133 interface
= topo
["routers"]["r1"]["links"]["r2-link1"]["interface"]
134 ipv6_link_local
= get_frr_ipv6_linklocal(tgen
, "r1", intf
=interface
)
135 ipv4_nxt_hop
= topo
["routers"]["r1"]["links"]["r2-link1"]["ipv4"].split("/")[0]
136 ipv6_nxt_hop
= topo
["routers"]["r1"]["links"]["r2-link1"]["ipv6"].split("/")[0]
137 DEFAULT_ROUTE_NXT_HOP_LINK1
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local
}
139 interface
= topo
["routers"]["r1"]["links"]["r2-link2"]["interface"]
140 ipv6_link_local
= get_frr_ipv6_linklocal(tgen
, "r1", intf
=interface
)
141 ipv4_nxt_hop
= topo
["routers"]["r1"]["links"]["r2-link2"]["ipv4"].split("/")[0]
142 ipv6_nxt_hop
= topo
["routers"]["r1"]["links"]["r2-link2"]["ipv6"].split("/")[0]
143 DEFAULT_ROUTE_NXT_HOP_LINK2
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local
}
144 logger
.info("Running setup_module() done")
147 def teardown_module():
148 """Teardown the pytest environment"""
150 logger
.info("Running teardown_module to delete topology")
154 # Stop toplogy and Remove tmp files
158 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
160 logger
.info("=" * 40)
163 #####################################################
167 #####################################################
170 def get_rib_route_uptime(tgen
, addr_type
, dut
, input_dict
):
172 Verify route uptime in RIB using "show ip route"
176 * `tgen` : topogen object
177 * `addr_type` : ip type, ipv4/ipv6
178 * `dut`: Device Under Test, for which user wants to test the data
179 * `input_dict` : input dict, has details of static routes
180 * `route_uptime`: uptime of the routes
184 # Creating static routes for r1
189 "network": "147.10.13.4/32"
192 "network": "147.10.12.0/24"
195 "network": "147.10.13.4/32"
198 "network": "147.10.13.4/32"
201 "network": "147.10.13.4/32"
210 errormsg(str) or True
213 logger
.info("Entering lib API: get_rib_route_uptime()")
216 router_list
= tgen
.routers()
217 for routerInput
in input_dict
.keys():
218 for router
, rnode
in router_list
.items():
222 logger
.info("Checking router %s RIB:", router
)
224 # Verifying RIB routes
225 if addr_type
== "ipv4":
226 command
= "show ip route"
228 command
= "show ipv6 route"
230 if "static_routes" in input_dict
[routerInput
]:
231 static_routes
= input_dict
[routerInput
]["static_routes"]
233 for static_route
in static_routes
:
234 if "vrf" in static_route
and static_route
["vrf"] is not None:
237 "[DUT: {}]: Verifying routes for VRF:"
238 " {}".format(router
, static_route
["vrf"])
240 cmd
= "{} vrf {}".format(command
, static_route
["vrf"])
243 cmd
= "{}".format(command
)
245 cmd
= "{} json".format(cmd
)
247 rib_routes_json
= run_frr_cmd(rnode
, cmd
, isjson
=True)
249 if bool(rib_routes_json
) is False:
250 errormsg
= "No route found in rib of router {}..".format(router
)
252 network
= static_route
["network"]
253 route_time
.append(rib_routes_json
[network
][0]["uptime"])
255 logger
.info("Exiting lib API: get_rib_route_uptime()")
259 def verify_the_uptime(time_stamp_before
, time_stamp_after
, incremented
=None):
261 time_stamp_before : string the time stamp captured
262 time_stamp_after : string the time stamp captured
264 uptime_before
= datetime
.datetime
.strptime(time_stamp_before
[0], "%H:%M:%S")
265 uptime_after
= datetime
.datetime
.strptime(time_stamp_after
[0], "%H:%M:%S")
267 if incremented
== True:
268 if uptime_before
< uptime_after
:
270 " The Uptime [{}] is incremented than [{}].......PASSED ".format(
271 time_stamp_before
, time_stamp_after
277 " The Uptime [{}] is expected to be incremented than [{}].......FAILED ".format(
278 time_stamp_before
, time_stamp_after
284 " The Uptime [{}] is not incremented than [{}] ".format(
285 time_stamp_before
, time_stamp_after
291 def get_best_path_route_in_FIB(tgen
, topo
, dut
, network
):
293 API to verify the best route in FIB and return the ipv4 and ipv6 nexthop for the given route
300 dut : device under test :
301 network ; route (ip) to which the best route to be retrieved
304 on success : return dict with next hops for the best hop
305 on failure : return error message with boolean False
307 is_ipv4_best_path_found
= False
308 is_ipv6_best_path_found
= False
309 rnode
= tgen
.routers()[dut
]
310 ipv4_show_bgp_json
= run_frr_cmd(rnode
, "sh ip bgp json ", isjson
=True)
311 ipv6_show_bgp_json
= run_frr_cmd(
312 rnode
, "sh ip bgp ipv6 unicast json ", isjson
=True
314 output_dict
= {"ipv4": None, "ipv6": None}
315 ipv4_nxt_hop_count
= len(ipv4_show_bgp_json
["routes"][network
["ipv4"]])
316 for index
in range(ipv4_nxt_hop_count
):
317 if "bestpath" in ipv4_show_bgp_json
["routes"][network
["ipv4"]][index
].keys():
318 best_path_ip
= ipv4_show_bgp_json
["routes"][network
["ipv4"]][index
][
321 output_dict
["ipv4"] = best_path_ip
323 "[DUT [{}]] Best path for the route {} is {} ".format(
324 dut
, network
["ipv4"], best_path_ip
327 is_ipv4_best_path_found
= True
329 logger
.error("ERROR....! No Best Path Found in BGP RIB.... FAILED")
331 ipv6_nxt_hop_count
= len(ipv6_show_bgp_json
["routes"][network
["ipv6"]])
332 for index
in range(ipv6_nxt_hop_count
):
333 if "bestpath" in ipv6_show_bgp_json
["routes"][network
["ipv6"]][index
].keys():
335 ipv6_show_bgp_json
["routes"][network
["ipv6"]][index
]["nexthops"]
337 for i_index
in range(ip_add_count
):
340 in ipv6_show_bgp_json
["routes"][network
["ipv6"]][index
]["nexthops"][
344 best_path_ip
= ipv6_show_bgp_json
["routes"][network
["ipv6"]][index
][
347 output_dict
["ipv6"] = best_path_ip
349 "[DUT [{}]] Best path for the route {} is {} ".format(
350 dut
, network
["ipv6"], best_path_ip
355 logger
.error("ERROR....! No Best Path Found in BGP RIB.... FAILED")
356 if is_ipv4_best_path_found
:
359 logger
.error("ERROR...! Unable to find the Best Path in the RIB")
363 #####################################################
367 #####################################################
370 def test_verify_bgp_default_originate_with_default_static_route_p1(request
):
372 Summary: "Verify default-originate route with default static and network command "
376 global BGP_CONVERGENCE
, DEFAULT_ROUTE_NXT_HOP_LINK1
, DEFAULT_ROUTE_NXT_HOP_LINK2
, DEFAULT_ROUTES
378 if BGP_CONVERGENCE
!= True:
379 pytest
.skip("skipped because of BGP Convergence failure")
381 tc_name
= request
.node
.name
382 write_test_header(tc_name
)
383 if tgen
.routers_have_failure():
384 check_router_status(tgen
)
385 reset_config_on_routers(tgen
)
387 step("Configure 2 link between R1 and R2")
388 step("Configure IPV4 and IPV6 EBGP between R1 and R2 both the links")
389 step("Configure default-originate on R1 IPv4 and IPv6 BGP session link-1 only ")
390 local_as
= get_dut_as_number(tgen
, dut
="r1")
391 default_originate_config
= {
394 "local_as": local_as
,
398 "default_originate": {"r2": {"dest-link": "r1-link1"}}
403 "default_originate": {"r2": {"dest-link": "r1-link1"}}
410 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
411 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
413 step("Verify IPv4/IPv6 default originate routes present on R2 nexthop as link-1")
414 for addr_type
in ADDR_TYPES
:
415 static_routes_input
= {
419 "network": [DEFAULT_ROUTES
[addr_type
]],
420 "next_hop": DEFAULT_ROUTE_NXT_HOP_LINK1
[addr_type
],
426 result
= verify_fib_routes(
431 next_hop
=DEFAULT_ROUTE_NXT_HOP_LINK1
[addr_type
],
433 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
437 result
= verify_bgp_rib(
442 next_hop
=DEFAULT_ROUTE_NXT_HOP_LINK1
[addr_type
],
444 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
449 "Configure network command on R1 (0.0.0.0/0 and 0::0/0) for IPv4 and IPv6 address family "
451 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
452 for addr_type
in ADDR_TYPES
:
459 "advertise_networks": [
460 {"network": [DEFAULT_ROUTES
[addr_type
]]}
469 result
= create_router_bgp(tgen
, topo
, input_advertise
)
470 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
474 step("No change on IPv4/IPv6 default-originate route advertised from link1")
475 result
= verify_rib_default_route(
479 routes
=DEFAULT_ROUTES
,
480 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
482 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
483 result
= verify_fib_default_route(
487 routes
=DEFAULT_ROUTES
,
488 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
490 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
492 step("verify 0.0.0.0/0 and 0::0/0 route also get advertised from link-2 ")
493 result
= verify_rib_default_route(
497 routes
=DEFAULT_ROUTES
,
498 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
500 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
501 result
= verify_fib_default_route(
505 routes
=DEFAULT_ROUTES
,
506 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
508 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
511 "Before removing default originate from R1 link -1 IPv4 and IPv6 address family taking the uptime snapshot"
513 uptime_before_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
514 uptime_before_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
516 step("Remove default originate from R1 link -1 IPv4 and IPv6 address family ")
517 local_as
= get_dut_as_number(tgen
, dut
="r1")
518 default_originate_config
= {
521 "local_as": local_as
,
525 "default_originate": {
526 "r2": {"dest-link": "r1-link1", "delete": True}
532 "default_originate": {
533 "r2": {"dest-link": "r1-link1", "delete": True}
541 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
542 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
544 step("Routes must be learned from network command")
545 result
= verify_rib_default_route(
549 routes
=DEFAULT_ROUTES
,
550 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
552 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
553 result
= verify_fib_default_route(
557 routes
=DEFAULT_ROUTES
,
558 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
560 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
562 result
= verify_rib_default_route(
566 routes
=DEFAULT_ROUTES
,
567 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
569 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
570 result
= verify_fib_default_route(
574 routes
=DEFAULT_ROUTES
,
575 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
577 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
579 step("After removing the default originate on R1 taking the uptime snapshot")
580 uptime_after_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
581 uptime_after_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
584 "After removing the default-originate uptime should get reset for link-1 learn route"
586 result
= verify_the_uptime(uptime_before_ipv4
, uptime_after_ipv4
, incremented
=False)
587 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
589 result
= verify_the_uptime(uptime_before_ipv6
, uptime_after_ipv6
, incremented
=False)
590 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
592 step("Taking uptime snapshot before configuring default - originate")
593 uptime_before_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
594 uptime_before_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
597 "Configure default-originate on R1 link-1 again for IPv4 and IPv6 address family"
599 local_as
= get_dut_as_number(tgen
, dut
="r1")
600 default_originate_config
= {
603 "local_as": local_as
,
607 "default_originate": {
609 "dest-link": "r1-link1",
616 "default_originate": {
618 "dest-link": "r1-link1",
627 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
628 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
630 step("Verify No change on R2 routing and BGP table for both the links ")
631 result
= verify_rib_default_route(
635 routes
=DEFAULT_ROUTES
,
636 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
638 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
639 result
= verify_fib_default_route(
643 routes
=DEFAULT_ROUTES
,
644 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
646 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
648 result
= verify_rib_default_route(
652 routes
=DEFAULT_ROUTES
,
653 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
655 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
656 result
= verify_fib_default_route(
660 routes
=DEFAULT_ROUTES
,
661 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
663 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
665 step("Taking snapshot after configuring default - originate")
666 uptime_after_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
667 uptime_after_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
670 "After configuring the default-originate uptime should not get reset for link-1 learn route"
672 result
= verify_the_uptime(uptime_before_ipv4
, uptime_after_ipv4
, incremented
=True)
673 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
675 result
= verify_the_uptime(uptime_before_ipv6
, uptime_after_ipv6
, incremented
=True)
676 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
678 step("Taking uptime snapshot before removing network 0.0.0.0 ")
679 uptime_before_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
680 uptime_before_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
682 step("Remove network command from R1 IPv4/IPv6 address family ")
683 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
684 for addr_type
in ADDR_TYPES
:
691 "advertise_networks": [
693 "network": [DEFAULT_ROUTES
[addr_type
]],
704 result
= create_router_bgp(tgen
, topo
, input_advertise
)
705 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
710 "Verify 0.0.0.0/0 and 0::0/0 route get removed from link-2 and default-originate IPv4/IPv6 route learn on link-1"
712 result
= verify_rib_default_route(
716 routes
=DEFAULT_ROUTES
,
717 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
719 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
720 result
= verify_fib_default_route(
724 routes
=DEFAULT_ROUTES
,
725 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
727 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
729 result
= verify_rib_default_route(
733 routes
=DEFAULT_ROUTES
,
734 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
739 ), "Testcase {} : Failed \n Route from link2 is not expected \n Error: {}".format(
742 result
= verify_fib_default_route(
746 routes
=DEFAULT_ROUTES
,
747 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
752 ), "Testcase {} : Failed\n Route from link2 is not expected \n Error: {}".format(
756 uptime_after_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
757 uptime_after_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
760 "After removing default originate command on R1 verify that the uptime got reset on R2"
763 result
= verify_the_uptime(uptime_before_ipv4
, uptime_after_ipv4
, incremented
=False)
764 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
766 result
= verify_the_uptime(uptime_before_ipv6
, uptime_after_ipv6
, incremented
=False)
767 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
769 step("Taking uptime snapshot before configuring static route network")
770 uptime_before_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
771 uptime_before_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
774 "Configure static default route for IPv4 and IPv6 (0.0.0.0/0 next-hop Null0 and 0::0/0 next-hop Null0) on R1"
776 static_routes_input
= {
780 "network": "0.0.0.0/0",
781 "next_hop": NEXT_HOP_IP
["ipv4"],
785 "next_hop": NEXT_HOP_IP
["ipv6"],
790 result
= create_static_routes(tgen
, static_routes_input
)
791 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
793 step("verifyIPv4 and IPv6 static routes are configure and up on R1 ")
794 for addr_type
in ADDR_TYPES
:
795 static_routes_input
= {
799 "network": "0.0.0.0/0",
800 "next_hop": NEXT_HOP_IP
["ipv4"],
804 "next_hop": NEXT_HOP_IP
["ipv6"],
809 result
= verify_fib_routes(tgen
, addr_type
, "r1", static_routes_input
)
810 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
814 step("Configure redistribute static on IPv4 and IPv6 address family")
815 redistribute_static
= {
819 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
820 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
825 result
= create_router_bgp(tgen
, topo
, redistribute_static
)
826 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
828 step("Verify No change on IPv4/IPv6 default-originate route advertised from link1")
829 result
= verify_rib_default_route(
833 routes
=DEFAULT_ROUTES
,
834 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
836 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
837 result
= verify_fib_default_route(
841 routes
=DEFAULT_ROUTES
,
842 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
844 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
846 step("verify 0.0.0.0/0 and 0::0/0 route also get advertised from link-2 ")
847 result
= verify_rib_default_route(
851 routes
=DEFAULT_ROUTES
,
852 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
854 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
855 result
= verify_fib_default_route(
859 routes
=DEFAULT_ROUTES
,
860 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
865 ), "Testcase {} : Failed\n Best Path sould be advertised in routes\n Error: {}".format(
869 step("Taking uptime snapshot before removing default originate")
870 uptime_before_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
871 uptime_before_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
873 step("Remove default-originate from link-1 from IPv4 and IPv6 neighbor ")
874 local_as
= get_dut_as_number(tgen
, dut
="r1")
875 default_originate_config
= {
878 "local_as": local_as
,
882 "default_originate": {
883 "r2": {"dest-link": "r1-link1", "delete": True}
889 "default_originate": {
890 "r2": {"dest-link": "r1-link1", "delete": True}
898 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
899 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
901 step("Taking uptime snapshot after removing default originate")
902 uptime_after_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
903 uptime_after_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
905 step("verify the up time , up time should get reset ")
906 result
= verify_the_uptime(uptime_before_ipv4
, uptime_after_ipv4
, incremented
=False)
907 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
909 result
= verify_the_uptime(uptime_before_ipv6
, uptime_after_ipv6
, incremented
=False)
910 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
912 step("Verify No change on IPv4/IPv6 default-originate route advertised from link1")
913 result
= verify_rib_default_route(
917 routes
=DEFAULT_ROUTES
,
918 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
920 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
921 result
= verify_fib_default_route(
925 routes
=DEFAULT_ROUTES
,
926 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
928 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
930 result
= verify_rib_default_route(
934 routes
=DEFAULT_ROUTES
,
935 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
937 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
938 result
= verify_fib_default_route(
942 routes
=DEFAULT_ROUTES
,
943 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
945 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
947 step("Taking uptime snapshot before configuring default originate")
948 uptime_before_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
949 uptime_before_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
952 " Configure default-originate on link-1 again for IPv4 and IPv6 address family"
954 local_as
= get_dut_as_number(tgen
, dut
="r1")
955 default_originate_config
= {
958 "local_as": local_as
,
962 "default_originate": {
964 "dest-link": "r1-link1",
971 "default_originate": {
973 "dest-link": "r1-link1",
982 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
983 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
985 step("Verify No change on IPv4/IPv6 default-originate route advertised from link1")
986 result
= verify_rib_default_route(
990 routes
=DEFAULT_ROUTES
,
991 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
993 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
994 result
= verify_fib_default_route(
998 routes
=DEFAULT_ROUTES
,
999 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
1001 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1003 result
= verify_rib_default_route(
1007 routes
=DEFAULT_ROUTES
,
1008 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
1010 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1011 result
= verify_fib_default_route(
1015 routes
=DEFAULT_ROUTES
,
1016 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
1019 assert result
is not True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1021 step("Taking uptime snapshot after configuring default originate")
1022 uptime_after_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
1023 uptime_after_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
1025 step("After configuring the default originate the uptime should not get reset ")
1026 result
= verify_the_uptime(uptime_before_ipv4
, uptime_after_ipv4
, incremented
=False)
1027 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1028 result
= verify_the_uptime(uptime_before_ipv6
, uptime_after_ipv6
, incremented
=False)
1029 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1031 step("Taking uptime snapshot before removing redisctribute static ")
1032 uptime_before_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
1033 uptime_before_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
1035 step("Remove redistribute static from IPv4 and IPv6 address family ")
1039 "local_as": get_dut_as_number(tgen
, dut
="r1"),
1043 "redistribute": [{"redist_type": "static", "delete": True}]
1048 "redistribute": [{"redist_type": "static", "delete": True}]
1056 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
1057 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
1059 step("Verify No change on IPv4/IPv6 default-originate route advertised from link1")
1060 result
= verify_rib_default_route(
1064 routes
=DEFAULT_ROUTES
,
1065 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
1067 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1068 result
= verify_fib_default_route(
1072 routes
=DEFAULT_ROUTES
,
1073 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
1075 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1077 result
= verify_rib_default_route(
1081 routes
=DEFAULT_ROUTES
,
1082 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
1085 assert result
is not True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1086 result
= verify_fib_default_route(
1090 routes
=DEFAULT_ROUTES
,
1091 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
1094 assert result
is not True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1096 step("Taking uptime snapshot before removing redisctribute static ")
1097 uptime_after_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
1098 uptime_after_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
1100 step("After removing default originate the route uptime should get reset ")
1101 result
= verify_the_uptime(uptime_before_ipv4
, uptime_after_ipv4
, incremented
=True)
1102 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1104 result
= verify_the_uptime(uptime_before_ipv6
, uptime_after_ipv6
, incremented
=True)
1105 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1106 write_test_footer(tc_name
)
1109 def test_verify_bgp_default_originate_with_aggregate_summary_p1(request
):
1111 Summary: "Verify default-originate route with aggregate summary command"
1113 tgen
= get_topogen()
1114 global BGP_CONVERGENCE
1115 tc_name
= request
.node
.name
1116 write_test_header(tc_name
)
1117 if tgen
.routers_have_failure():
1118 check_router_status(tgen
)
1119 reset_config_on_routers(tgen
)
1120 if BGP_CONVERGENCE
!= True:
1121 pytest
.skip("skipped because of BGP Convergence failure")
1123 step("After changing the BGP AS Path Verify the BGP Convergence")
1124 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
1125 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
1129 step("Configure default-originate on R1 IPv4 and IPv6 BGP session link-1 only")
1130 local_as
= get_dut_as_number(tgen
, dut
="r1")
1131 default_originate_config
= {
1134 "local_as": local_as
,
1138 "default_originate": {"r2": {"dest-link": "r1-link1"}}
1143 "default_originate": {"r2": {"dest-link": "r1-link1"}}
1150 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
1151 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1154 "Verify IPv4/IPv6 default originate routes present on R2 nexthop as link-1,on R2"
1156 result
= verify_rib_default_route(
1160 routes
=DEFAULT_ROUTES
,
1161 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
1163 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1164 result
= verify_fib_default_route(
1168 routes
=DEFAULT_ROUTES
,
1169 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
1171 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1173 step("Configure 5 static route for IPv4 and IPv6 on R0")
1174 for addr_type
in ADDR_TYPES
:
1181 "advertise_networks": [
1183 "network": [NETWORK1_1
[addr_type
]],
1184 "next_hop": NEXT_HOP_IP
[addr_type
],
1187 "network": [NETWORK1_2
[addr_type
]],
1188 "next_hop": NEXT_HOP_IP
[addr_type
],
1191 "network": [NETWORK1_3
[addr_type
]],
1192 "next_hop": NEXT_HOP_IP
[addr_type
],
1195 "network": [NETWORK1_4
[addr_type
]],
1196 "next_hop": NEXT_HOP_IP
[addr_type
],
1199 "network": [NETWORK1_5
[addr_type
]],
1200 "next_hop": NEXT_HOP_IP
[addr_type
],
1210 result
= create_router_bgp(tgen
, topo
, input_advertise
)
1211 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
1215 step("Before configuring the aggregate route taking uptime snapshot ")
1216 uptime_before_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
1217 uptime_before_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
1219 step("Configure aggregate summary command for IPv4 and IPv6 address family ")
1220 local_as
= get_dut_as_number(tgen
, dut
="r1")
1224 "router bgp {}".format(local_as
),
1225 "address-family ipv4 unicast",
1226 "aggregate-address {} summary-only".format("0.0.0.0/0 "),
1227 "exit-address-family",
1228 "address-family ipv6 unicast",
1229 "aggregate-address {} summary-only".format("0::0/0"),
1230 "exit-address-family",
1234 result
= apply_raw_config(tgen
, raw_config
)
1235 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1238 "verify that no change on IPv4/IPv6 default-originate route advertised from link1 0.0.0.0/0 and 0::0/0 route also get advertised from link-2 on R2"
1240 result
= verify_rib_default_route(
1244 routes
=DEFAULT_ROUTES
,
1245 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
1247 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1248 result
= verify_fib_default_route(
1252 routes
=DEFAULT_ROUTES
,
1253 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
1255 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1257 result
= verify_rib_default_route(
1261 routes
=DEFAULT_ROUTES
,
1262 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
1264 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1265 result
= verify_fib_default_route(
1269 routes
=DEFAULT_ROUTES
,
1270 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
1272 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1274 step("After configuring the aggregate route taking uptime snapshot ")
1275 uptime_after_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
1276 uptime_after_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
1279 "After Configuring the aggregate route uptime should get reset for link-1 learn route"
1281 result
= verify_the_uptime(uptime_before_ipv4
, uptime_after_ipv4
, incremented
=False)
1282 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1284 result
= verify_the_uptime(uptime_before_ipv6
, uptime_after_ipv6
, incremented
=False)
1285 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1287 step("Before removing default originate taking uptime snapshot ")
1288 uptime_before_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
1289 uptime_before_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
1291 step("Remove default originate from R1 link -1 IPv4 and IPv6 address family")
1292 local_as
= get_dut_as_number(tgen
, dut
="r1")
1293 default_originate_config
= {
1296 "local_as": local_as
,
1300 "default_originate": {
1301 "r2": {"dest-link": "r1-link1", "delete": True}
1307 "default_originate": {
1308 "r2": {"dest-link": "r1-link1", "delete": True}
1316 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
1317 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1320 "verify that no change on IPv4/IPv6 default-originate route advertised from link1 0.0.0.0/0 and 0::0/0 route also get advertised from link-2 on R2"
1322 result
= verify_rib_default_route(
1326 routes
=DEFAULT_ROUTES
,
1327 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
1329 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1330 result
= verify_fib_default_route(
1334 routes
=DEFAULT_ROUTES
,
1335 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
1337 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1339 step("After removing default origin taking uptime snapshot ")
1340 uptime_after_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
1341 uptime_after_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
1344 "After removing the default-originate uptime should get reset for link-1 learn route"
1346 result
= verify_the_uptime(uptime_before_ipv4
, uptime_after_ipv4
, incremented
=False)
1347 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1349 result
= verify_the_uptime(uptime_before_ipv6
, uptime_after_ipv6
, incremented
=False)
1350 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1352 step("Before Configuring default origin taking uptime snapshot ")
1353 uptime_before_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
1354 uptime_before_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
1357 "Configure default-originate on R1 link-1 again for IPv4 and IPv6 address family"
1359 local_as
= get_dut_as_number(tgen
, dut
="r1")
1360 default_originate_config
= {
1363 "local_as": local_as
,
1367 "default_originate": {
1369 "dest-link": "r1-link1",
1376 "default_originate": {
1378 "dest-link": "r1-link1",
1387 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
1388 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1390 step("After Configuring default originate taking uptime snapshot")
1391 uptime_after_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
1392 uptime_after_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
1395 "After Configuring the default-originate uptime should get reset for link-1 learn route"
1397 result
= verify_the_uptime(uptime_before_ipv4
, uptime_after_ipv4
, incremented
=False)
1398 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1400 result
= verify_the_uptime(uptime_before_ipv6
, uptime_after_ipv6
, incremented
=False)
1401 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1403 step("Before removing aggregate -summary command taking the uptime snapshot ")
1404 uptime_before_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
1405 uptime_before_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
1407 step("remove aggregate summary command for IPv4 and IPv6 address family ")
1408 local_as
= get_dut_as_number(tgen
, dut
="r1")
1412 "router bgp {}".format(local_as
),
1413 "address-family ipv4 unicast",
1414 "no aggregate-address {} summary-only".format("0.0.0.0/0"),
1415 "exit-address-family",
1416 "address-family ipv6 unicast",
1417 "no aggregate-address {} summary-only".format("0::0/0"),
1418 "exit-address-family",
1422 result
= apply_raw_config(tgen
, raw_config
)
1423 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1425 step("Verify Default-originate IPv4/IPv6 route learn on link-1 ")
1426 result
= verify_rib_default_route(
1430 routes
=DEFAULT_ROUTES
,
1431 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
1433 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1434 result
= verify_fib_default_route(
1438 routes
=DEFAULT_ROUTES
,
1439 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
1441 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1443 step("Verify 0.0.0.0/0 and 0::0/0 route get removed from link-2 ")
1444 result
= verify_rib_default_route(
1448 routes
=DEFAULT_ROUTES
,
1449 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
1452 assert result
is not True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1453 result
= verify_fib_default_route(
1457 routes
=DEFAULT_ROUTES
,
1458 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
1461 assert result
is not True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1463 step("After removing aggregate -summary command taking the uptime snapshot ")
1464 uptime_after_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
1465 uptime_after_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
1467 step("After removing aggregate command uptime should get reset ")
1468 result
= verify_the_uptime(uptime_before_ipv4
, uptime_after_ipv4
, incremented
=False)
1469 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1471 result
= verify_the_uptime(uptime_before_ipv6
, uptime_after_ipv6
, incremented
=False)
1472 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1473 write_test_footer(tc_name
)
1476 def test_verify_default_originate_with_2way_ecmp_p2(request
):
1478 Summary: "Verify default-originate route with 3 way ECMP and traffic "
1481 tgen
= get_topogen()
1482 global BGP_CONVERGENCE
1483 global DEFAULT_ROUTES
1484 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1486 if BGP_CONVERGENCE
!= True:
1487 pytest
.skip("skipped because of BGP Convergence failure")
1489 tc_name
= request
.node
.name
1490 write_test_header(tc_name
)
1491 if tgen
.routers_have_failure():
1492 check_router_status(tgen
)
1493 reset_config_on_routers(tgen
)
1495 step("Populating next-hops details")
1496 r1_r2_ipv4_neighbor_ips
= []
1497 r1_r2_ipv6_neighbor_ips
= []
1499 for index
in range(1, 3):
1500 r1_link
= "r1-link" + str(index
)
1501 r1_r2_ipv4_neighbor_ips
.append(
1502 topo
["routers"]["r2"]["links"][r1_link
]["ipv4"].split("/")[0]
1504 r1_r2_ipv6_neighbor_ips
.append(
1505 topo
["routers"]["r2"]["links"][r1_link
]["ipv6"].split("/")[0]
1509 "Configure default-originate on R1 for all the neighbor of IPv4 and IPv6 peers "
1511 local_as
= get_dut_as_number(tgen
, dut
="r1")
1512 for index
in range(2):
1516 "router bgp {}".format(local_as
),
1517 "address-family ipv4 unicast",
1518 "neighbor {} default-originate".format(
1519 r1_r2_ipv4_neighbor_ips
[index
]
1521 "exit-address-family",
1522 "address-family ipv6 unicast",
1523 "neighbor {} default-originate ".format(
1524 r1_r2_ipv6_neighbor_ips
[index
]
1526 "exit-address-family",
1530 result
= apply_raw_config(tgen
, raw_config
)
1531 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1534 "After configuring default-originate command , verify default routes are advertised on R2 "
1538 for index
in range(1, 3):
1539 r2_link
= "r2-link" + str(index
)
1540 ipv4_nxt_hop
= topo
["routers"]["r1"]["links"][r2_link
]["ipv4"].split("/")[0]
1541 interface
= topo
["routers"]["r1"]["links"][r2_link
]["interface"]
1542 ipv6_link_local_nxt_hop
= get_frr_ipv6_linklocal(tgen
, "r1", intf
=interface
)
1543 DEFAULT_ROUTE_NXT_HOP
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local_nxt_hop
}
1545 result
= verify_rib_default_route(
1549 routes
=DEFAULT_ROUTES
,
1550 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP
,
1552 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1556 step("Ping R1 configure IPv4 and IPv6 loopback address from R2")
1557 pingaddr
= topo
["routers"]["r1"]["links"]["lo"]["ipv4"].split("/")[0]
1558 router
= tgen
.gears
["r2"]
1559 output
= router
.run("ping -c 4 -w 4 {}".format(pingaddr
))
1560 assert " 0% packet loss" in output
, "Ping R1->R2 FAILED"
1561 logger
.info("Ping from R1 to R2 ... success")
1563 step("Shuting up the active route")
1564 network
= {"ipv4": "0.0.0.0/0", "ipv6": "::/0"}
1565 ipv_dict
= get_best_path_route_in_FIB(tgen
, topo
, dut
="r2", network
=network
)
1566 dut_links
= topo
["routers"]["r1"]["links"]
1567 active_interface
= None
1568 for key
, values
in dut_links
.items():
1569 ipv4_address
= dut_links
[key
]["ipv4"].split("/")[0]
1570 ipv6_address
= dut_links
[key
]["ipv6"].split("/")[0]
1571 if ipv_dict
["ipv4"] == ipv4_address
and ipv_dict
["ipv6"] == ipv6_address
:
1572 active_interface
= dut_links
[key
]["interface"]
1575 "Shutting down the interface {} on router {} ".format(active_interface
, "r1")
1577 shutdown_bringup_interface(tgen
, "r1", active_interface
, False)
1579 step("Verify the complete convergence to fail after shutting the interface")
1580 result
= verify_bgp_convergence(tgen
, topo
, expected
=False)
1583 ), " Testcase {} : After shuting down the interface Convergence is expected to be Failed".format(
1588 "Verify routes from active best path is not received from r1 after shuting the interface"
1591 for index
in range(1, 3):
1592 r2_link
= "r2-link" + str(index
)
1593 ipv4_nxt_hop
= topo
["routers"]["r1"]["links"][r2_link
]["ipv4"].split("/")[0]
1594 interface
= topo
["routers"]["r1"]["links"][r2_link
]["interface"]
1595 ipv6_link_local_nxt_hop
= get_frr_ipv6_linklocal(tgen
, "r1", intf
=interface
)
1596 DEFAULT_ROUTE_NXT_HOP
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local_nxt_hop
}
1598 result
= verify_rib_default_route(
1602 routes
=DEFAULT_ROUTES
,
1603 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP
,
1606 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
1610 result
= verify_rib_default_route(
1614 routes
=DEFAULT_ROUTES
,
1615 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP
,
1617 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1621 step("Ping R1 configure IPv4 and IPv6 loopback address from R2")
1622 pingaddr
= topo
["routers"]["r1"]["links"]["lo"]["ipv4"].split("/")[0]
1623 router
= tgen
.gears
["r2"]
1624 output
= router
.run("ping -c 4 -w 4 {}".format(pingaddr
))
1625 assert " 0% packet loss" in output
, "Ping R1->R2 FAILED"
1626 logger
.info("Ping from R1 to R2 ... success")
1628 step("No Shuting up the active route")
1630 shutdown_bringup_interface(tgen
, "r1", active_interface
, True)
1632 step("Verify the complete convergence after bringup the interface")
1633 result
= verify_bgp_convergence(tgen
, topo
)
1636 ), " Testcase {} : After bringing up the interface complete convergence is expected ".format(
1640 step("Verify all the routes are received from r1 after no shuting the interface")
1642 for index
in range(1, 3):
1643 r2_link
= "r2-link" + str(index
)
1644 ipv4_nxt_hop
= topo
["routers"]["r1"]["links"][r2_link
]["ipv4"].split("/")[0]
1645 interface
= topo
["routers"]["r1"]["links"][r2_link
]["interface"]
1646 ipv6_link_local_nxt_hop
= get_frr_ipv6_linklocal(tgen
, "r1", intf
=interface
)
1647 DEFAULT_ROUTE_NXT_HOP
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local_nxt_hop
}
1649 result
= verify_rib_default_route(
1653 routes
=DEFAULT_ROUTES
,
1654 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP
,
1656 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1660 result
= verify_rib_default_route(
1664 routes
=DEFAULT_ROUTES
,
1665 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP
,
1667 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1672 "Configure IPv4 and IPv6 route-map with deny option on R2 to filter default route 0.0.0.0/0 and 0::0/0"
1674 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1682 "network": DEFAULT_ROUTES
["ipv4"],
1691 "network": DEFAULT_ROUTES
["ipv6"],
1699 result
= create_prefix_lists(tgen
, input_dict_3
)
1700 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1709 "match": {"ipv4": {"prefix_lists": "Pv4"}},
1716 "match": {"ipv6": {"prefix_lists": "Pv6"}},
1722 result
= create_route_maps(tgen
, input_dict_3
)
1723 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1725 step("Apply route-map IN direction of R2 ( R2-R1) for IPv4 and IPv6 BGP neighbors")
1727 for index
in range(1, 3):
1728 r2_link
= "r2-link" + str(index
)
1740 {"name": "RMv4", "direction": "in"}
1755 {"name": "RMv6", "direction": "in"}
1767 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
1768 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1772 step("After applying the route-map the routes are not expected in RIB ")
1774 for index
in range(1, 3):
1775 r2_link
= "r2-link" + str(index
)
1776 ipv4_nxt_hop
= topo
["routers"]["r1"]["links"][r2_link
]["ipv4"].split("/")[0]
1777 interface
= topo
["routers"]["r1"]["links"][r2_link
]["interface"]
1778 ipv6_link_local_nxt_hop
= get_frr_ipv6_linklocal(tgen
, "r1", intf
=interface
)
1779 DEFAULT_ROUTE_NXT_HOP
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local_nxt_hop
}
1781 result
= verify_rib_default_route(
1785 routes
=DEFAULT_ROUTES
,
1786 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP
,
1789 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
1793 write_test_footer(tc_name
)
1796 if __name__
== "__main__":
1797 args
= ["-s"] + sys
.argv
[1:]
1798 sys
.exit(pytest
.main(args
))