3 # Copyright (c) 2022 by VMware, Inc. ("VMware")
4 # Used Copyright (c) 2018 by Network Device Education Foundation, Inc. ("NetDEF")
7 # Permission to use, copy, modify, and/or distribute this software
8 # for any purpose with or without fee is hereby granted, provided
9 # that the above copyright notice and this permission notice appear
11 # Shreenidhi A R <rshreenidhi@vmware.com>
12 # THE SOFTWARE IS PROVIDED "AS IS" AND VMWARE DISCLAIMS ALL WARRANTIES
13 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL VMWARE BE LIABLE FOR
15 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
16 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
17 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
18 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22 Following tests are covered.
23 1. Verify default-originate route with default static and network command
24 2. Verify default-originate route with aggregate summary command
25 3. Verfiy default-originate behaviour in ecmp
32 from copy
import deepcopy
33 from lib
.topolog
import logger
35 # pylint: disable=C0413
36 # Import topogen and topotest helpers
37 from lib
.topogen
import Topogen
, get_topogen
38 from lib
.topojson
import build_config_from_json
39 from lib
.topolog
import logger
42 verify_bgp_convergence
,
46 verify_rib_default_route
,
47 verify_fib_default_route
,
49 from lib
.common_config
import (
55 shutdown_bringup_interface
,
56 get_frr_ipv6_linklocal
,
62 reset_config_on_routers
,
67 # Save the Current Working Directory to find configuration files.
68 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
69 sys
.path
.append(os
.path
.join(CWD
, "../"))
70 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
72 # Required to instantiate the topology builder class.
74 # pylint: disable=C0413
75 # Import topogen and topotest helpers
79 NETWORK1_1
= {"ipv4": "198.51.1.1/32", "ipv6": "2001:DB8::1:1/128"}
80 NETWORK1_2
= {"ipv4": "198.51.1.2/32", "ipv6": "2001:DB8::1:2/128"}
81 NETWORK1_3
= {"ipv4": "198.51.1.3/32", "ipv6": "2001:DB8::1:3/128"}
82 NETWORK1_4
= {"ipv4": "198.51.1.4/32", "ipv6": "2001:DB8::1:4/128"}
83 NETWORK1_5
= {"ipv4": "198.51.1.5/32", "ipv6": "2001:DB8::1:5/128"}
88 {"network": "0.0.0.0/0"},
101 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
102 NEXT_HOP_IP
= {"ipv4": "Null0", "ipv6": "Null0"}
104 pytestmark
= [pytest
.mark
.bgpd
]
107 def setup_module(mod
):
109 Sets up the pytest environment
113 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
114 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
115 logger
.info("=" * 40)
117 logger
.info("Running setup_module to create topology")
119 # This function initiates the topology build with Topogen...
120 json_file
= "{}/bgp_default_originate_2links.json".format(CWD
)
121 tgen
= Topogen(json_file
, mod
.__name
__)
123 topo
= tgen
.json_topo
124 # ... and here it calls Mininet initialization functions.
126 # Starting topology, create tmp files which are loaded to routers
127 # to start daemons and then start routers
130 # Creating configuration from JSON
131 build_config_from_json(tgen
, topo
)
134 global BGP_CONVERGENCE
135 global DEFAULT_ROUTES
136 global DEFAULT_ROUTE_NXT_HOP_LINK1
, DEFAULT_ROUTE_NXT_HOP_LINK2
137 ADDR_TYPES
= check_address_types()
138 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
139 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
143 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
145 interface
= topo
["routers"]["r1"]["links"]["r2-link1"]["interface"]
146 ipv6_link_local
= get_frr_ipv6_linklocal(tgen
, "r1", intf
=interface
)
147 ipv4_nxt_hop
= topo
["routers"]["r1"]["links"]["r2-link1"]["ipv4"].split("/")[0]
148 ipv6_nxt_hop
= topo
["routers"]["r1"]["links"]["r2-link1"]["ipv6"].split("/")[0]
149 DEFAULT_ROUTE_NXT_HOP_LINK1
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local
}
151 interface
= topo
["routers"]["r1"]["links"]["r2-link2"]["interface"]
152 ipv6_link_local
= get_frr_ipv6_linklocal(tgen
, "r1", intf
=interface
)
153 ipv4_nxt_hop
= topo
["routers"]["r1"]["links"]["r2-link2"]["ipv4"].split("/")[0]
154 ipv6_nxt_hop
= topo
["routers"]["r1"]["links"]["r2-link2"]["ipv6"].split("/")[0]
155 DEFAULT_ROUTE_NXT_HOP_LINK2
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local
}
156 logger
.info("Running setup_module() done")
159 def teardown_module():
160 """Teardown the pytest environment"""
162 logger
.info("Running teardown_module to delete topology")
166 # Stop toplogy and Remove tmp files
170 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
172 logger
.info("=" * 40)
175 #####################################################
179 #####################################################
182 def get_rib_route_uptime(tgen
, addr_type
, dut
, input_dict
):
184 Verify route uptime in RIB using "show ip route"
188 * `tgen` : topogen object
189 * `addr_type` : ip type, ipv4/ipv6
190 * `dut`: Device Under Test, for which user wants to test the data
191 * `input_dict` : input dict, has details of static routes
192 * `route_uptime`: uptime of the routes
196 # Creating static routes for r1
201 "network": "147.10.13.4/32"
204 "network": "147.10.12.0/24"
207 "network": "147.10.13.4/32"
210 "network": "147.10.13.4/32"
213 "network": "147.10.13.4/32"
222 errormsg(str) or True
225 logger
.info("Entering lib API: get_rib_route_uptime()")
228 router_list
= tgen
.routers()
229 for routerInput
in input_dict
.keys():
230 for router
, rnode
in router_list
.items():
234 logger
.info("Checking router %s RIB:", router
)
236 # Verifying RIB routes
237 if addr_type
== "ipv4":
238 command
= "show ip route"
240 command
= "show ipv6 route"
242 if "static_routes" in input_dict
[routerInput
]:
243 static_routes
= input_dict
[routerInput
]["static_routes"]
245 for static_route
in static_routes
:
246 if "vrf" in static_route
and static_route
["vrf"] is not None:
249 "[DUT: {}]: Verifying routes for VRF:"
250 " {}".format(router
, static_route
["vrf"])
252 cmd
= "{} vrf {}".format(command
, static_route
["vrf"])
255 cmd
= "{}".format(command
)
257 cmd
= "{} json".format(cmd
)
259 rib_routes_json
= run_frr_cmd(rnode
, cmd
, isjson
=True)
261 if bool(rib_routes_json
) is False:
262 errormsg
= "No route found in rib of router {}..".format(router
)
264 network
= static_route
["network"]
265 route_time
.append(rib_routes_json
[network
][0]["uptime"])
267 logger
.info("Exiting lib API: get_rib_route_uptime()")
271 def verify_the_uptime(time_stamp_before
, time_stamp_after
, incremented
=None):
273 time_stamp_before : string the time stamp captured
274 time_stamp_after : string the time stamp captured
276 uptime_before
= datetime
.datetime
.strptime(time_stamp_before
[0], "%H:%M:%S")
277 uptime_after
= datetime
.datetime
.strptime(time_stamp_after
[0], "%H:%M:%S")
279 if incremented
== True:
280 if uptime_before
< uptime_after
:
282 " The Uptime [{}] is incremented than [{}].......PASSED ".format(
283 time_stamp_before
, time_stamp_after
289 " The Uptime [{}] is expected to be incremented than [{}].......FAILED ".format(
290 time_stamp_before
, time_stamp_after
296 " The Uptime [{}] is not incremented than [{}] ".format(
297 time_stamp_before
, time_stamp_after
303 def get_best_path_route_in_FIB(tgen
, topo
, dut
, network
):
305 API to verify the best route in FIB and return the ipv4 and ipv6 nexthop for the given route
312 dut : device under test :
313 network ; route (ip) to which the best route to be retrieved
316 on success : return dict with next hops for the best hop
317 on failure : return error message with boolean False
319 is_ipv4_best_path_found
= False
320 is_ipv6_best_path_found
= False
321 rnode
= tgen
.routers()[dut
]
322 ipv4_show_bgp_json
= run_frr_cmd(rnode
, "sh ip bgp json ", isjson
=True)
323 ipv6_show_bgp_json
= run_frr_cmd(
324 rnode
, "sh ip bgp ipv6 unicast json ", isjson
=True
326 output_dict
= {"ipv4": None, "ipv6": None}
327 ipv4_nxt_hop_count
= len(ipv4_show_bgp_json
["routes"][network
["ipv4"]])
328 for index
in range(ipv4_nxt_hop_count
):
329 if "bestpath" in ipv4_show_bgp_json
["routes"][network
["ipv4"]][index
].keys():
330 best_path_ip
= ipv4_show_bgp_json
["routes"][network
["ipv4"]][index
][
333 output_dict
["ipv4"] = best_path_ip
335 "[DUT [{}]] Best path for the route {} is {} ".format(
336 dut
, network
["ipv4"], best_path_ip
339 is_ipv4_best_path_found
= True
341 logger
.error("ERROR....! No Best Path Found in BGP RIB.... FAILED")
343 ipv6_nxt_hop_count
= len(ipv6_show_bgp_json
["routes"][network
["ipv6"]])
344 for index
in range(ipv6_nxt_hop_count
):
345 if "bestpath" in ipv6_show_bgp_json
["routes"][network
["ipv6"]][index
].keys():
347 ipv6_show_bgp_json
["routes"][network
["ipv6"]][index
]["nexthops"]
349 for i_index
in range(ip_add_count
):
352 in ipv6_show_bgp_json
["routes"][network
["ipv6"]][index
]["nexthops"][
356 best_path_ip
= ipv6_show_bgp_json
["routes"][network
["ipv6"]][index
][
359 output_dict
["ipv6"] = best_path_ip
361 "[DUT [{}]] Best path for the route {} is {} ".format(
362 dut
, network
["ipv6"], best_path_ip
367 logger
.error("ERROR....! No Best Path Found in BGP RIB.... FAILED")
368 if is_ipv4_best_path_found
:
371 logger
.error("ERROR...! Unable to find the Best Path in the RIB")
375 #####################################################
379 #####################################################
382 def test_verify_bgp_default_originate_with_default_static_route_p1(request
):
384 Summary: "Verify default-originate route with default static and network command "
388 global BGP_CONVERGENCE
, DEFAULT_ROUTE_NXT_HOP_LINK1
, DEFAULT_ROUTE_NXT_HOP_LINK2
, DEFAULT_ROUTES
390 if BGP_CONVERGENCE
!= True:
391 pytest
.skip("skipped because of BGP Convergence failure")
393 tc_name
= request
.node
.name
394 write_test_header(tc_name
)
395 if tgen
.routers_have_failure():
396 check_router_status(tgen
)
397 reset_config_on_routers(tgen
)
399 step("Configure 2 link between R1 and R2")
400 step("Configure IPV4 and IPV6 EBGP between R1 and R2 both the links")
401 step("Configure default-originate on R1 IPv4 and IPv6 BGP session link-1 only ")
402 local_as
= get_dut_as_number(tgen
, dut
="r1")
403 default_originate_config
= {
406 "local_as": local_as
,
410 "default_originate": {"r2": {"dest-link": "r1-link1"}}
415 "default_originate": {"r2": {"dest-link": "r1-link1"}}
422 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
423 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
425 step("Verify IPv4/IPv6 default originate routes present on R2 nexthop as link-1")
426 for addr_type
in ADDR_TYPES
:
427 static_routes_input
= {
431 "network": [DEFAULT_ROUTES
[addr_type
]],
432 "next_hop": DEFAULT_ROUTE_NXT_HOP_LINK1
[addr_type
],
438 result
= verify_fib_routes(
443 next_hop
=DEFAULT_ROUTE_NXT_HOP_LINK1
[addr_type
],
445 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
449 result
= verify_bgp_rib(
454 next_hop
=DEFAULT_ROUTE_NXT_HOP_LINK1
[addr_type
],
456 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
461 "Configure network command on R1 (0.0.0.0/0 and 0::0/0) for IPv4 and IPv6 address family "
463 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
464 for addr_type
in ADDR_TYPES
:
471 "advertise_networks": [
472 {"network": [DEFAULT_ROUTES
[addr_type
]]}
481 result
= create_router_bgp(tgen
, topo
, input_advertise
)
482 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
486 step("No change on IPv4/IPv6 default-originate route advertised from link1")
487 result
= verify_rib_default_route(
491 routes
=DEFAULT_ROUTES
,
492 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
494 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
495 result
= verify_fib_default_route(
499 routes
=DEFAULT_ROUTES
,
500 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
502 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
504 step("verify 0.0.0.0/0 and 0::0/0 route also get advertised from link-2 ")
505 result
= verify_rib_default_route(
509 routes
=DEFAULT_ROUTES
,
510 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
512 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
513 result
= verify_fib_default_route(
517 routes
=DEFAULT_ROUTES
,
518 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
520 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
523 "Before removing default originate from R1 link -1 IPv4 and IPv6 address family taking the uptime snapshot"
525 uptime_before_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
526 uptime_before_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
528 step("Remove default originate from R1 link -1 IPv4 and IPv6 address family ")
529 local_as
= get_dut_as_number(tgen
, dut
="r1")
530 default_originate_config
= {
533 "local_as": local_as
,
537 "default_originate": {
538 "r2": {"dest-link": "r1-link1", "delete": True}
544 "default_originate": {
545 "r2": {"dest-link": "r1-link1", "delete": True}
553 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
554 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
556 step("Routes must be learned from network command")
557 result
= verify_rib_default_route(
561 routes
=DEFAULT_ROUTES
,
562 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
564 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
565 result
= verify_fib_default_route(
569 routes
=DEFAULT_ROUTES
,
570 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
572 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
574 result
= verify_rib_default_route(
578 routes
=DEFAULT_ROUTES
,
579 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
581 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
582 result
= verify_fib_default_route(
586 routes
=DEFAULT_ROUTES
,
587 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
589 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
591 step("After removing the default originate on R1 taking the uptime snapshot")
592 uptime_after_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
593 uptime_after_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
596 "After removing the default-originate uptime should get reset for link-1 learn route"
598 result
= verify_the_uptime(uptime_before_ipv4
, uptime_after_ipv4
, incremented
=False)
599 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
601 result
= verify_the_uptime(uptime_before_ipv6
, uptime_after_ipv6
, incremented
=False)
602 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
604 step("Taking uptime snapshot before configuring default - originate")
605 uptime_before_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
606 uptime_before_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
609 "Configure default-originate on R1 link-1 again for IPv4 and IPv6 address family"
611 local_as
= get_dut_as_number(tgen
, dut
="r1")
612 default_originate_config
= {
615 "local_as": local_as
,
619 "default_originate": {
621 "dest-link": "r1-link1",
628 "default_originate": {
630 "dest-link": "r1-link1",
639 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
640 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
642 step("Verify No change on R2 routing and BGP table for both the links ")
643 result
= verify_rib_default_route(
647 routes
=DEFAULT_ROUTES
,
648 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
650 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
651 result
= verify_fib_default_route(
655 routes
=DEFAULT_ROUTES
,
656 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
658 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
660 result
= verify_rib_default_route(
664 routes
=DEFAULT_ROUTES
,
665 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
667 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
668 result
= verify_fib_default_route(
672 routes
=DEFAULT_ROUTES
,
673 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
675 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
677 step("Taking snapshot after configuring default - originate")
678 uptime_after_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
679 uptime_after_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
682 "After configuring the default-originate uptime should not get reset for link-1 learn route"
684 result
= verify_the_uptime(uptime_before_ipv4
, uptime_after_ipv4
, incremented
=True)
685 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
687 result
= verify_the_uptime(uptime_before_ipv6
, uptime_after_ipv6
, incremented
=True)
688 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
690 step("Taking uptime snapshot before removing network 0.0.0.0 ")
691 uptime_before_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
692 uptime_before_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
694 step("Remove network command from R1 IPv4/IPv6 address family ")
695 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
696 for addr_type
in ADDR_TYPES
:
703 "advertise_networks": [
705 "network": [DEFAULT_ROUTES
[addr_type
]],
716 result
= create_router_bgp(tgen
, topo
, input_advertise
)
717 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
722 "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"
724 result
= verify_rib_default_route(
728 routes
=DEFAULT_ROUTES
,
729 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
731 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
732 result
= verify_fib_default_route(
736 routes
=DEFAULT_ROUTES
,
737 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
739 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
741 result
= verify_rib_default_route(
745 routes
=DEFAULT_ROUTES
,
746 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
751 ), "Testcase {} : Failed \n Route from link2 is not expected \n Error: {}".format(
754 result
= verify_fib_default_route(
758 routes
=DEFAULT_ROUTES
,
759 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
764 ), "Testcase {} : Failed\n Route from link2 is not expected \n Error: {}".format(
768 uptime_after_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
769 uptime_after_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
772 "After removing default originate command on R1 verify that the uptime got reset on R2"
775 result
= verify_the_uptime(uptime_before_ipv4
, uptime_after_ipv4
, incremented
=False)
776 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
778 result
= verify_the_uptime(uptime_before_ipv6
, uptime_after_ipv6
, incremented
=False)
779 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
781 step("Taking uptime snapshot before configuring static route network")
782 uptime_before_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
783 uptime_before_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
786 "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"
788 static_routes_input
= {
792 "network": "0.0.0.0/0",
793 "next_hop": NEXT_HOP_IP
["ipv4"],
797 "next_hop": NEXT_HOP_IP
["ipv6"],
802 result
= create_static_routes(tgen
, static_routes_input
)
803 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
805 step("verifyIPv4 and IPv6 static routes are configure and up on R1 ")
806 for addr_type
in ADDR_TYPES
:
807 static_routes_input
= {
811 "network": "0.0.0.0/0",
812 "next_hop": NEXT_HOP_IP
["ipv4"],
816 "next_hop": NEXT_HOP_IP
["ipv6"],
821 result
= verify_fib_routes(tgen
, addr_type
, "r1", static_routes_input
)
822 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
826 step("Configure redistribute static on IPv4 and IPv6 address family")
827 redistribute_static
= {
831 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
832 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
837 result
= create_router_bgp(tgen
, topo
, redistribute_static
)
838 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
840 step("Verify No change on IPv4/IPv6 default-originate route advertised from link1")
841 result
= verify_rib_default_route(
845 routes
=DEFAULT_ROUTES
,
846 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
848 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
849 result
= verify_fib_default_route(
853 routes
=DEFAULT_ROUTES
,
854 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
856 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
858 step("verify 0.0.0.0/0 and 0::0/0 route also get advertised from link-2 ")
859 result
= verify_rib_default_route(
863 routes
=DEFAULT_ROUTES
,
864 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
866 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
867 result
= verify_fib_default_route(
871 routes
=DEFAULT_ROUTES
,
872 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
877 ), "Testcase {} : Failed\n Best Path sould be advertised in routes\n Error: {}".format(
881 step("Taking uptime snapshot before removing default originate")
882 uptime_before_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
883 uptime_before_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
885 step("Remove default-originate from link-1 from IPv4 and IPv6 neighbor ")
886 local_as
= get_dut_as_number(tgen
, dut
="r1")
887 default_originate_config
= {
890 "local_as": local_as
,
894 "default_originate": {
895 "r2": {"dest-link": "r1-link1", "delete": True}
901 "default_originate": {
902 "r2": {"dest-link": "r1-link1", "delete": True}
910 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
911 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
913 step("Taking uptime snapshot after removing default originate")
914 uptime_after_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
915 uptime_after_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
917 step("verify the up time , up time should get reset ")
918 result
= verify_the_uptime(uptime_before_ipv4
, uptime_after_ipv4
, incremented
=False)
919 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
921 result
= verify_the_uptime(uptime_before_ipv6
, uptime_after_ipv6
, incremented
=False)
922 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
924 step("Verify No change on IPv4/IPv6 default-originate route advertised from link1")
925 result
= verify_rib_default_route(
929 routes
=DEFAULT_ROUTES
,
930 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
932 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
933 result
= verify_fib_default_route(
937 routes
=DEFAULT_ROUTES
,
938 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
940 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
942 result
= verify_rib_default_route(
946 routes
=DEFAULT_ROUTES
,
947 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
949 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
950 result
= verify_fib_default_route(
954 routes
=DEFAULT_ROUTES
,
955 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
957 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
959 step("Taking uptime snapshot before configuring default originate")
960 uptime_before_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
961 uptime_before_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
964 " Configure default-originate on link-1 again for IPv4 and IPv6 address family"
966 local_as
= get_dut_as_number(tgen
, dut
="r1")
967 default_originate_config
= {
970 "local_as": local_as
,
974 "default_originate": {
976 "dest-link": "r1-link1",
983 "default_originate": {
985 "dest-link": "r1-link1",
994 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
995 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
997 step("Verify No change on IPv4/IPv6 default-originate route advertised from link1")
998 result
= verify_rib_default_route(
1002 routes
=DEFAULT_ROUTES
,
1003 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
1005 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1006 result
= verify_fib_default_route(
1010 routes
=DEFAULT_ROUTES
,
1011 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
1013 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1015 result
= verify_rib_default_route(
1019 routes
=DEFAULT_ROUTES
,
1020 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
1022 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1023 result
= verify_fib_default_route(
1027 routes
=DEFAULT_ROUTES
,
1028 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
1031 assert result
is not True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1033 step("Taking uptime snapshot after configuring default originate")
1034 uptime_after_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
1035 uptime_after_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
1037 step("After configuring the default originate the uptime should not get reset ")
1038 result
= verify_the_uptime(uptime_before_ipv4
, uptime_after_ipv4
, incremented
=False)
1039 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1040 result
= verify_the_uptime(uptime_before_ipv6
, uptime_after_ipv6
, incremented
=False)
1041 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1043 step("Taking uptime snapshot before removing redisctribute static ")
1044 uptime_before_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
1045 uptime_before_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
1047 step("Remove redistribute static from IPv4 and IPv6 address family ")
1051 "local_as": get_dut_as_number(tgen
, dut
="r1"),
1055 "redistribute": [{"redist_type": "static", "delete": True}]
1060 "redistribute": [{"redist_type": "static", "delete": True}]
1068 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
1069 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
1071 step("Verify No change on IPv4/IPv6 default-originate route advertised from link1")
1072 result
= verify_rib_default_route(
1076 routes
=DEFAULT_ROUTES
,
1077 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
1079 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1080 result
= verify_fib_default_route(
1084 routes
=DEFAULT_ROUTES
,
1085 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
1087 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1089 result
= verify_rib_default_route(
1093 routes
=DEFAULT_ROUTES
,
1094 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
1097 assert result
is not True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1098 result
= verify_fib_default_route(
1102 routes
=DEFAULT_ROUTES
,
1103 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
1106 assert result
is not True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1108 step("Taking uptime snapshot before removing redisctribute static ")
1109 uptime_after_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
1110 uptime_after_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
1112 step("After removing default originate the route uptime should get reset ")
1113 result
= verify_the_uptime(uptime_before_ipv4
, uptime_after_ipv4
, incremented
=True)
1114 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1116 result
= verify_the_uptime(uptime_before_ipv6
, uptime_after_ipv6
, incremented
=True)
1117 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1118 write_test_footer(tc_name
)
1121 def test_verify_bgp_default_originate_with_aggregate_summary_p1(request
):
1123 Summary: "Verify default-originate route with aggregate summary command"
1125 tgen
= get_topogen()
1126 global BGP_CONVERGENCE
1127 tc_name
= request
.node
.name
1128 write_test_header(tc_name
)
1129 if tgen
.routers_have_failure():
1130 check_router_status(tgen
)
1131 reset_config_on_routers(tgen
)
1132 if BGP_CONVERGENCE
!= True:
1133 pytest
.skip("skipped because of BGP Convergence failure")
1135 step("After changing the BGP AS Path Verify the BGP Convergence")
1136 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
1137 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
1141 step("Configure default-originate on R1 IPv4 and IPv6 BGP session link-1 only")
1142 local_as
= get_dut_as_number(tgen
, dut
="r1")
1143 default_originate_config
= {
1146 "local_as": local_as
,
1150 "default_originate": {"r2": {"dest-link": "r1-link1"}}
1155 "default_originate": {"r2": {"dest-link": "r1-link1"}}
1162 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
1163 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1166 "Verify IPv4/IPv6 default originate routes present on R2 nexthop as link-1,on R2"
1168 result
= verify_rib_default_route(
1172 routes
=DEFAULT_ROUTES
,
1173 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
1175 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1176 result
= verify_fib_default_route(
1180 routes
=DEFAULT_ROUTES
,
1181 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
1183 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1185 step("Configure 5 static route for IPv4 and IPv6 on R0")
1186 for addr_type
in ADDR_TYPES
:
1193 "advertise_networks": [
1195 "network": [NETWORK1_1
[addr_type
]],
1196 "next_hop": NEXT_HOP_IP
[addr_type
],
1199 "network": [NETWORK1_2
[addr_type
]],
1200 "next_hop": NEXT_HOP_IP
[addr_type
],
1203 "network": [NETWORK1_3
[addr_type
]],
1204 "next_hop": NEXT_HOP_IP
[addr_type
],
1207 "network": [NETWORK1_4
[addr_type
]],
1208 "next_hop": NEXT_HOP_IP
[addr_type
],
1211 "network": [NETWORK1_5
[addr_type
]],
1212 "next_hop": NEXT_HOP_IP
[addr_type
],
1222 result
= create_router_bgp(tgen
, topo
, input_advertise
)
1223 assert result
is True, "Testcase {} :Failed \n Error: {}".format(
1227 step("Before configuring the aggregate route taking uptime snapshot ")
1228 uptime_before_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
1229 uptime_before_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
1231 step("Configure aggregate summary command for IPv4 and IPv6 address family ")
1232 local_as
= get_dut_as_number(tgen
, dut
="r1")
1236 "router bgp {}".format(local_as
),
1237 "address-family ipv4 unicast",
1238 "aggregate-address {} summary-only".format("0.0.0.0/0 "),
1239 "exit-address-family",
1240 "address-family ipv6 unicast",
1241 "aggregate-address {} summary-only".format("0::0/0"),
1242 "exit-address-family",
1246 result
= apply_raw_config(tgen
, raw_config
)
1247 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1250 "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"
1252 result
= verify_rib_default_route(
1256 routes
=DEFAULT_ROUTES
,
1257 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
1259 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1260 result
= verify_fib_default_route(
1264 routes
=DEFAULT_ROUTES
,
1265 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
1267 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1269 result
= verify_rib_default_route(
1273 routes
=DEFAULT_ROUTES
,
1274 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
1276 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1277 result
= verify_fib_default_route(
1281 routes
=DEFAULT_ROUTES
,
1282 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
1284 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1286 step("After configuring the aggregate route taking uptime snapshot ")
1287 uptime_after_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
1288 uptime_after_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
1291 "After Configuring the aggregate route uptime should get reset for link-1 learn route"
1293 result
= verify_the_uptime(uptime_before_ipv4
, uptime_after_ipv4
, incremented
=False)
1294 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1296 result
= verify_the_uptime(uptime_before_ipv6
, uptime_after_ipv6
, incremented
=False)
1297 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1299 step("Before removing default originate taking uptime snapshot ")
1300 uptime_before_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
1301 uptime_before_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
1303 step("Remove default originate from R1 link -1 IPv4 and IPv6 address family")
1304 local_as
= get_dut_as_number(tgen
, dut
="r1")
1305 default_originate_config
= {
1308 "local_as": local_as
,
1312 "default_originate": {
1313 "r2": {"dest-link": "r1-link1", "delete": True}
1319 "default_originate": {
1320 "r2": {"dest-link": "r1-link1", "delete": True}
1328 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
1329 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1332 "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"
1334 result
= verify_rib_default_route(
1338 routes
=DEFAULT_ROUTES
,
1339 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
1341 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1342 result
= verify_fib_default_route(
1346 routes
=DEFAULT_ROUTES
,
1347 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
1349 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1351 step("After removing default origin taking uptime snapshot ")
1352 uptime_after_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
1353 uptime_after_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
1356 "After removing the default-originate uptime should get reset for link-1 learn route"
1358 result
= verify_the_uptime(uptime_before_ipv4
, uptime_after_ipv4
, incremented
=False)
1359 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1361 result
= verify_the_uptime(uptime_before_ipv6
, uptime_after_ipv6
, incremented
=False)
1362 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1364 step("Before Configuring default origin taking uptime snapshot ")
1365 uptime_before_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
1366 uptime_before_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
1369 "Configure default-originate on R1 link-1 again for IPv4 and IPv6 address family"
1371 local_as
= get_dut_as_number(tgen
, dut
="r1")
1372 default_originate_config
= {
1375 "local_as": local_as
,
1379 "default_originate": {
1381 "dest-link": "r1-link1",
1388 "default_originate": {
1390 "dest-link": "r1-link1",
1399 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
1400 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1402 step("After Configuring default originate taking uptime snapshot")
1403 uptime_after_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
1404 uptime_after_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
1407 "After Configuring the default-originate uptime should get reset for link-1 learn route"
1409 result
= verify_the_uptime(uptime_before_ipv4
, uptime_after_ipv4
, incremented
=False)
1410 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1412 result
= verify_the_uptime(uptime_before_ipv6
, uptime_after_ipv6
, incremented
=False)
1413 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1415 step("Before removing aggregate -summary command taking the uptime snapshot ")
1416 uptime_before_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
1417 uptime_before_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
1419 step("remove aggregate summary command for IPv4 and IPv6 address family ")
1420 local_as
= get_dut_as_number(tgen
, dut
="r1")
1424 "router bgp {}".format(local_as
),
1425 "address-family ipv4 unicast",
1426 "no aggregate-address {} summary-only".format("0.0.0.0/0"),
1427 "exit-address-family",
1428 "address-family ipv6 unicast",
1429 "no aggregate-address {} summary-only".format("0::0/0"),
1430 "exit-address-family",
1434 result
= apply_raw_config(tgen
, raw_config
)
1435 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1437 step("Verify Default-originate IPv4/IPv6 route learn on link-1 ")
1438 result
= verify_rib_default_route(
1442 routes
=DEFAULT_ROUTES
,
1443 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
1445 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1446 result
= verify_fib_default_route(
1450 routes
=DEFAULT_ROUTES
,
1451 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK1
,
1453 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1455 step("Verify 0.0.0.0/0 and 0::0/0 route get removed from link-2 ")
1456 result
= verify_rib_default_route(
1460 routes
=DEFAULT_ROUTES
,
1461 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
1464 assert result
is not True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1465 result
= verify_fib_default_route(
1469 routes
=DEFAULT_ROUTES
,
1470 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_LINK2
,
1473 assert result
is not True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1475 step("After removing aggregate -summary command taking the uptime snapshot ")
1476 uptime_after_ipv4
= get_rib_route_uptime(tgen
, "ipv4", "r2", ipv4_uptime_dict
)
1477 uptime_after_ipv6
= get_rib_route_uptime(tgen
, "ipv6", "r2", ipv6_uptime_dict
)
1479 step("After removing aggregate command uptime should get reset ")
1480 result
= verify_the_uptime(uptime_before_ipv4
, uptime_after_ipv4
, incremented
=False)
1481 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1483 result
= verify_the_uptime(uptime_before_ipv6
, uptime_after_ipv6
, incremented
=False)
1484 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1485 write_test_footer(tc_name
)
1488 def test_verify_default_originate_with_2way_ecmp_p2(request
):
1490 Summary: "Verify default-originate route with 3 way ECMP and traffic "
1493 tgen
= get_topogen()
1494 global BGP_CONVERGENCE
1495 global DEFAULT_ROUTES
1496 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1498 if BGP_CONVERGENCE
!= True:
1499 pytest
.skip("skipped because of BGP Convergence failure")
1501 tc_name
= request
.node
.name
1502 write_test_header(tc_name
)
1503 if tgen
.routers_have_failure():
1504 check_router_status(tgen
)
1505 reset_config_on_routers(tgen
)
1507 step("Populating next-hops details")
1508 r1_r2_ipv4_neighbor_ips
= []
1509 r1_r2_ipv6_neighbor_ips
= []
1511 for index
in range(1, 3):
1512 r1_link
= "r1-link" + str(index
)
1513 r1_r2_ipv4_neighbor_ips
.append(
1514 topo
["routers"]["r2"]["links"][r1_link
]["ipv4"].split("/")[0]
1516 r1_r2_ipv6_neighbor_ips
.append(
1517 topo
["routers"]["r2"]["links"][r1_link
]["ipv6"].split("/")[0]
1521 "Configure default-originate on R1 for all the neighbor of IPv4 and IPv6 peers "
1523 local_as
= get_dut_as_number(tgen
, dut
="r1")
1524 for index
in range(2):
1528 "router bgp {}".format(local_as
),
1529 "address-family ipv4 unicast",
1530 "neighbor {} default-originate".format(
1531 r1_r2_ipv4_neighbor_ips
[index
]
1533 "exit-address-family",
1534 "address-family ipv6 unicast",
1535 "neighbor {} default-originate ".format(
1536 r1_r2_ipv6_neighbor_ips
[index
]
1538 "exit-address-family",
1542 result
= apply_raw_config(tgen
, raw_config
)
1543 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1546 "After configuring default-originate command , verify default routes are advertised on R2 "
1550 for index
in range(1, 3):
1551 r2_link
= "r2-link" + str(index
)
1552 ipv4_nxt_hop
= topo
["routers"]["r1"]["links"][r2_link
]["ipv4"].split("/")[0]
1553 interface
= topo
["routers"]["r1"]["links"][r2_link
]["interface"]
1554 ipv6_link_local_nxt_hop
= get_frr_ipv6_linklocal(tgen
, "r1", intf
=interface
)
1555 DEFAULT_ROUTE_NXT_HOP
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local_nxt_hop
}
1557 result
= verify_rib_default_route(
1561 routes
=DEFAULT_ROUTES
,
1562 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP
,
1564 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1568 step("Ping R1 configure IPv4 and IPv6 loopback address from R2")
1569 pingaddr
= topo
["routers"]["r1"]["links"]["lo"]["ipv4"].split("/")[0]
1570 router
= tgen
.gears
["r2"]
1571 output
= router
.run("ping -c 4 -w 4 {}".format(pingaddr
))
1572 assert " 0% packet loss" in output
, "Ping R1->R2 FAILED"
1573 logger
.info("Ping from R1 to R2 ... success")
1575 step("Shuting up the active route")
1576 network
= {"ipv4": "0.0.0.0/0", "ipv6": "::/0"}
1577 ipv_dict
= get_best_path_route_in_FIB(tgen
, topo
, dut
="r2", network
=network
)
1578 dut_links
= topo
["routers"]["r1"]["links"]
1579 active_interface
= None
1580 for key
, values
in dut_links
.items():
1581 ipv4_address
= dut_links
[key
]["ipv4"].split("/")[0]
1582 ipv6_address
= dut_links
[key
]["ipv6"].split("/")[0]
1583 if ipv_dict
["ipv4"] == ipv4_address
and ipv_dict
["ipv6"] == ipv6_address
:
1584 active_interface
= dut_links
[key
]["interface"]
1587 "Shutting down the interface {} on router {} ".format(active_interface
, "r1")
1589 shutdown_bringup_interface(tgen
, "r1", active_interface
, False)
1591 step("Verify the complete convergence to fail after shutting the interface")
1592 result
= verify_bgp_convergence(tgen
, topo
, expected
=False)
1595 ), " Testcase {} : After shuting down the interface Convergence is expected to be Failed".format(
1600 "Verify routes from active best path is not received from r1 after shuting the interface"
1603 for index
in range(1, 3):
1604 r2_link
= "r2-link" + str(index
)
1605 ipv4_nxt_hop
= topo
["routers"]["r1"]["links"][r2_link
]["ipv4"].split("/")[0]
1606 interface
= topo
["routers"]["r1"]["links"][r2_link
]["interface"]
1607 ipv6_link_local_nxt_hop
= get_frr_ipv6_linklocal(tgen
, "r1", intf
=interface
)
1608 DEFAULT_ROUTE_NXT_HOP
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local_nxt_hop
}
1610 result
= verify_rib_default_route(
1614 routes
=DEFAULT_ROUTES
,
1615 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP
,
1618 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
1622 result
= verify_rib_default_route(
1626 routes
=DEFAULT_ROUTES
,
1627 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP
,
1629 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1633 step("Ping R1 configure IPv4 and IPv6 loopback address from R2")
1634 pingaddr
= topo
["routers"]["r1"]["links"]["lo"]["ipv4"].split("/")[0]
1635 router
= tgen
.gears
["r2"]
1636 output
= router
.run("ping -c 4 -w 4 {}".format(pingaddr
))
1637 assert " 0% packet loss" in output
, "Ping R1->R2 FAILED"
1638 logger
.info("Ping from R1 to R2 ... success")
1640 step("No Shuting up the active route")
1642 shutdown_bringup_interface(tgen
, "r1", active_interface
, True)
1644 step("Verify the complete convergence after bringup the interface")
1645 result
= verify_bgp_convergence(tgen
, topo
)
1648 ), " Testcase {} : After bringing up the interface complete convergence is expected ".format(
1652 step("Verify all the routes are received from r1 after no shuting the interface")
1654 for index
in range(1, 3):
1655 r2_link
= "r2-link" + str(index
)
1656 ipv4_nxt_hop
= topo
["routers"]["r1"]["links"][r2_link
]["ipv4"].split("/")[0]
1657 interface
= topo
["routers"]["r1"]["links"][r2_link
]["interface"]
1658 ipv6_link_local_nxt_hop
= get_frr_ipv6_linklocal(tgen
, "r1", intf
=interface
)
1659 DEFAULT_ROUTE_NXT_HOP
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local_nxt_hop
}
1661 result
= verify_rib_default_route(
1665 routes
=DEFAULT_ROUTES
,
1666 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP
,
1668 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1672 result
= verify_rib_default_route(
1676 routes
=DEFAULT_ROUTES
,
1677 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP
,
1679 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1684 "Configure IPv4 and IPv6 route-map with deny option on R2 to filter default route 0.0.0.0/0 and 0::0/0"
1686 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1694 "network": DEFAULT_ROUTES
["ipv4"],
1703 "network": DEFAULT_ROUTES
["ipv6"],
1711 result
= create_prefix_lists(tgen
, input_dict_3
)
1712 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1721 "match": {"ipv4": {"prefix_lists": "Pv4"}},
1728 "match": {"ipv6": {"prefix_lists": "Pv6"}},
1734 result
= create_route_maps(tgen
, input_dict_3
)
1735 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1737 step("Apply route-map IN direction of R2 ( R2-R1) for IPv4 and IPv6 BGP neighbors")
1739 for index
in range(1, 3):
1740 r2_link
= "r2-link" + str(index
)
1752 {"name": "RMv4", "direction": "in"}
1767 {"name": "RMv6", "direction": "in"}
1779 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
1780 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1784 step("After applying the route-map the routes are not expected in RIB ")
1786 for index
in range(1, 3):
1787 r2_link
= "r2-link" + str(index
)
1788 ipv4_nxt_hop
= topo
["routers"]["r1"]["links"][r2_link
]["ipv4"].split("/")[0]
1789 interface
= topo
["routers"]["r1"]["links"][r2_link
]["interface"]
1790 ipv6_link_local_nxt_hop
= get_frr_ipv6_linklocal(tgen
, "r1", intf
=interface
)
1791 DEFAULT_ROUTE_NXT_HOP
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local_nxt_hop
}
1793 result
= verify_rib_default_route(
1797 routes
=DEFAULT_ROUTES
,
1798 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP
,
1801 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
1805 write_test_footer(tc_name
)
1808 if __name__
== "__main__":
1809 args
= ["-s"] + sys
.argv
[1:]
1810 sys
.exit(pytest
.main(args
))