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 10. Verify default-originate route after BGP and FRR process restart
12 11. Verify default-originate route after shut/no shut and clear BGP neighbor
18 from lib
.topolog
import logger
20 # pylint: disable=C0413
21 # Import topogen and topotest helpers
22 from lib
.topogen
import Topogen
, get_topogen
23 from lib
.topojson
import build_config_from_json
24 from lib
.topolog
import logger
27 verify_bgp_convergence
,
33 verify_rib_default_route
,
34 verify_fib_default_route
,
36 from lib
.common_config
import (
42 shutdown_bringup_interface
,
44 required_linux_kernel_version
,
49 get_frr_ipv6_linklocal
,
54 reset_config_on_routers
,
59 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.staticd
]
61 # Save the Current Working Directory to find configuration files.
62 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
63 sys
.path
.append(os
.path
.join(CWD
, "../"))
64 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
66 # Required to instantiate the topology builder class.
68 # pylint: disable=C0413
69 # Import topogen and topotest helpers
76 NETWORK1_1
= {"ipv4": "198.51.1.1/32", "ipv6": "2001:DB8::1:1/128"}
77 NETWORK2_1
= {"ipv4": "198.51.1.2/32", "ipv6": "2001:DB8::1:2/128"}
78 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
79 NEXT_HOP_IP
= {"ipv4": "Null0", "ipv6": "Null0"}
81 r0_connected_address_ipv4
= "192.168.0.0/24"
82 r0_connected_address_ipv6
= "fd00::/64"
83 r1_connected_address_ipv4
= "192.168.1.0/24"
84 r1_connected_address_ipv6
= "fd00:0:0:1::/64"
85 r3_connected_address_ipv4
= "192.168.2.0/24"
86 r3_connected_address_ipv6
= "fd00:0:0:2::/64"
87 r4_connected_address_ipv4
= "192.168.3.0/24"
88 r4_connected_address_ipv6
= "fd00:0:0:3::/64"
91 def setup_module(mod
):
93 Sets up the pytest environment
98 # Required linux kernel version for this suite to run.
99 result
= required_linux_kernel_version("4.15")
100 if result
is not True:
101 pytest
.skip("Kernel requirements are not met")
103 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
104 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
105 logger
.info("=" * 40)
107 logger
.info("Running setup_module to create topology")
109 # This function initiates the topology build with Topogen...
110 json_file
= "{}/bgp_default_originate_topo1.json".format(CWD
)
111 tgen
= Topogen(json_file
, mod
.__name
__)
113 topo
= tgen
.json_topo
114 # ... and here it calls micronet initialization functions.
115 # Starting topology, create tmp files which are loaded to routers
116 # 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_R1
, DEFAULT_ROUTE_NXT_HOP_R3
125 global R0_NETWORK_LOOPBACK
, R0_NETWORK_LOOPBACK_NXTHOP
, R1_NETWORK_LOOPBACK
126 global R0_NETWORK_CONNECTED
, R0_NETWORK_CONNECTED_NXTHOP
, R1_NETWORK_CONNECTED
, R1_NETWORK_CONNECTED_NXTHOP
127 global R4_NETWORK_LOOPBACK
, R4_NETWORK_LOOPBACK_NXTHOP
, R3_NETWORK_LOOPBACK
128 global R4_NETWORK_CONNECTED
, R4_NETWORK_CONNECTED_NXTHOP
, R3_NETWORK_CONNECTED
, R3_NETWORK_CONNECTED_NXTHOP
130 ADDR_TYPES
= check_address_types()
131 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
132 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
135 # There are the global varibles used through out the file these are acheived only after building the topology.
137 r0_loopback_address_ipv4
= topo
["routers"]["r0"]["links"]["lo"]["ipv4"]
138 r0_loopback_address_ipv4_nxt_hop
= topo
["routers"]["r0"]["links"]["r1"][
141 r0_loopback_address_ipv6
= topo
["routers"]["r0"]["links"]["lo"]["ipv6"]
142 r0_loopback_address_ipv6_nxt_hop
= topo
["routers"]["r0"]["links"]["r1"][
146 r1_loopback_address_ipv4
= topo
["routers"]["r1"]["links"]["lo"]["ipv4"]
147 r1_loopback_address_ipv4_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"][
150 r1_loopback_address_ipv6
= topo
["routers"]["r1"]["links"]["lo"]["ipv6"]
151 r1_loopback_address_ipv6_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"][
155 r4_loopback_address_ipv4
= topo
["routers"]["r4"]["links"]["lo"]["ipv4"]
156 r4_loopback_address_ipv4_nxt_hop
= topo
["routers"]["r4"]["links"]["r3"][
159 r4_loopback_address_ipv6
= topo
["routers"]["r4"]["links"]["lo"]["ipv6"]
160 r4_loopback_address_ipv6_nxt_hop
= topo
["routers"]["r4"]["links"]["r3"][
164 r3_loopback_address_ipv4
= topo
["routers"]["r3"]["links"]["lo"]["ipv4"]
165 r3_loopback_address_ipv4_nxt_hop
= topo
["routers"]["r3"]["links"]["r2"][
168 r3_loopback_address_ipv6
= topo
["routers"]["r3"]["links"]["lo"]["ipv6"]
169 r3_loopback_address_ipv6_nxt_hop
= topo
["routers"]["r3"]["links"]["r2"][
173 R0_NETWORK_LOOPBACK
= {
174 "ipv4": r0_loopback_address_ipv4
,
175 "ipv6": r0_loopback_address_ipv6
,
177 R0_NETWORK_LOOPBACK_NXTHOP
= {
178 "ipv4": r0_loopback_address_ipv4_nxt_hop
,
179 "ipv6": r0_loopback_address_ipv6_nxt_hop
,
182 R1_NETWORK_LOOPBACK
= {
183 "ipv4": r1_loopback_address_ipv4
,
184 "ipv6": r1_loopback_address_ipv6
,
187 R0_NETWORK_CONNECTED
= {
188 "ipv4": r0_connected_address_ipv4
,
189 "ipv6": r0_connected_address_ipv6
,
191 R0_NETWORK_CONNECTED_NXTHOP
= {
192 "ipv4": r0_loopback_address_ipv4_nxt_hop
,
193 "ipv6": r0_loopback_address_ipv6_nxt_hop
,
196 R1_NETWORK_CONNECTED
= {
197 "ipv4": r1_connected_address_ipv4
,
198 "ipv6": r1_connected_address_ipv6
,
200 R1_NETWORK_CONNECTED_NXTHOP
= {
201 "ipv4": r1_loopback_address_ipv4_nxt_hop
,
202 "ipv6": r1_loopback_address_ipv6_nxt_hop
,
205 R4_NETWORK_LOOPBACK
= {
206 "ipv4": r4_loopback_address_ipv4
,
207 "ipv6": r4_loopback_address_ipv6
,
209 R4_NETWORK_LOOPBACK_NXTHOP
= {
210 "ipv4": r4_loopback_address_ipv4_nxt_hop
,
211 "ipv6": r4_loopback_address_ipv6_nxt_hop
,
214 R3_NETWORK_LOOPBACK
= {
215 "ipv4": r3_loopback_address_ipv4
,
216 "ipv6": r3_loopback_address_ipv6
,
218 R4_NETWORK_CONNECTED
= {
219 "ipv4": r4_connected_address_ipv4
,
220 "ipv6": r4_connected_address_ipv6
,
222 R4_NETWORK_CONNECTED_NXTHOP
= {
223 "ipv4": r4_loopback_address_ipv4_nxt_hop
,
224 "ipv6": r4_loopback_address_ipv6_nxt_hop
,
227 R3_NETWORK_CONNECTED
= {
228 "ipv4": r3_connected_address_ipv4
,
229 "ipv6": r3_connected_address_ipv6
,
231 R3_NETWORK_CONNECTED_NXTHOP
= {
232 "ipv4": r3_loopback_address_ipv4_nxt_hop
,
233 "ipv6": r3_loopback_address_ipv6_nxt_hop
,
236 # populating the nexthop for default routes
237 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
239 interface
= topo
["routers"]["r1"]["links"]["r2"]["interface"]
240 ipv6_link_local
= get_frr_ipv6_linklocal(tgen
, "r1", intf
=interface
)
241 ipv4_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"]["ipv4"].split("/")[0]
242 ipv6_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"]["ipv6"].split("/")[0]
243 DEFAULT_ROUTE_NXT_HOP_R1
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local
}
245 interface
= topo
["routers"]["r3"]["links"]["r2"]["interface"]
246 ipv6_link_local
= get_frr_ipv6_linklocal(tgen
, "r3", intf
=interface
)
247 ipv4_nxt_hop
= topo
["routers"]["r3"]["links"]["r2"]["ipv4"].split("/")[0]
248 ipv6_nxt_hop
= topo
["routers"]["r3"]["links"]["r2"]["ipv6"].split("/")[0]
249 DEFAULT_ROUTE_NXT_HOP_R3
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local
}
251 logger
.info("Running setup_module() done")
254 def teardown_module():
255 """Teardown the pytest environment"""
257 logger
.info("Running teardown_module to delete topology")
261 # Stop toplogy and Remove tmp files
265 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
267 logger
.info("=" * 40)
270 #####################################################
274 #####################################################
277 def test_verify_default_originate_after_BGP_and_FRR_restart_p2(request
):
279 Summary: "Verify default-originate route after BGP and FRR process restart "
282 global BGP_CONVERGENCE
285 tc_name
= request
.node
.name
286 write_test_header(tc_name
)
288 # Don't run this test if we have any failure.
289 if tgen
.routers_have_failure():
290 check_router_status(tgen
)
291 reset_config_on_routers(tgen
)
293 if BGP_CONVERGENCE
!= True:
294 pytest
.skip("skipped because of BGP Convergence failure")
296 step("Configure EBGP between R0 to R1 and IBGP between R1 to R2")
297 step("Configure EBGP between R2 to R3 and IBGP between R3 to R4")
325 result
= modify_as_number(tgen
, topo
, input_dict
)
327 assert result
is True
328 except AssertionError:
329 logger
.info("Expected behaviour: {}".format(result
))
330 logger
.info("BGP config is not created because of invalid ASNs")
331 step("After changing the BGP AS Path Verify the BGP Convergence")
332 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
334 BGP_CONVERGENCE
is True
335 ), " Failed convergence after chaning the AS number :Failed \n Error: {}".format(
339 step("Configure IPv4 and IPv6 static route (Sv4 , Sv6) on R0 and (S1v4, S1v6)on R4")
340 for addr_type
in ADDR_TYPES
:
341 static_routes_input
= {
345 "network": [NETWORK1_1
[addr_type
]],
346 "next_hop": NEXT_HOP_IP
[addr_type
],
351 result
= create_static_routes(tgen
, static_routes_input
)
354 ), "Testcase {} : Failed to configure the static route on R0 \n Error: {}".format(
358 for addr_type
in ADDR_TYPES
:
359 static_routes_input
= {
363 "network": [NETWORK2_1
[addr_type
]],
364 "next_hop": NEXT_HOP_IP
[addr_type
],
369 result
= create_static_routes(tgen
, static_routes_input
)
372 ), "Testcase {} : Failed to configure the static route on R4 \n Error: {}".format(
376 step("verify IPv4 and IPv6 static route are configured and up on R0")
377 for addr_type
in ADDR_TYPES
:
378 static_routes_input
= {
382 "network": [NETWORK1_1
[addr_type
]],
383 "next_hop": NEXT_HOP_IP
[addr_type
],
388 result
= verify_fib_routes(tgen
, addr_type
, "r0", static_routes_input
)
391 ), "Testcase {} : Failed Route {} not found in R0 FIB \n Error: {}".format(
392 tc_name
, NETWORK1_1
, result
395 step("verify IPv4 and IPv6 static route are configured and up on R4")
396 for addr_type
in ADDR_TYPES
:
397 static_routes_input
= {
401 "network": [NETWORK2_1
[addr_type
]],
402 "next_hop": NEXT_HOP_IP
[addr_type
],
407 result
= verify_fib_routes(tgen
, addr_type
, "r4", static_routes_input
)
410 ), "Testcase {} : Failed Route {} not found in R4 FIB \n Error: {}".format(
411 tc_name
, NETWORK2_1
, result
415 "Configure redistribute connected and static on R0 (R0-R1) on R4 ( R4-R3) IPv4 and IPv6 address family"
417 redistribute_static
= {
424 {"redist_type": "static"},
425 {"redist_type": "connected"},
432 {"redist_type": "static"},
433 {"redist_type": "connected"},
446 {"redist_type": "static"},
447 {"redist_type": "connected"},
454 {"redist_type": "static"},
455 {"redist_type": "connected"},
463 result
= create_router_bgp(tgen
, topo
, redistribute_static
)
466 ), "Testcase {} : Failed to configure the static route \n Error: {}".format(
470 step("verify IPv4 and IPv6 static route are configured and up on R1")
471 for addr_type
in ADDR_TYPES
:
472 static_routes_input
= {
476 "network": [NETWORK1_1
[addr_type
]],
477 "next_hop": NEXT_HOP_IP
[addr_type
],
480 "network": [R0_NETWORK_LOOPBACK
[addr_type
]],
481 "next_hop": R0_NETWORK_LOOPBACK
[addr_type
],
484 "network": [R0_NETWORK_CONNECTED
[addr_type
]],
485 "next_hop": R0_NETWORK_CONNECTED_NXTHOP
[addr_type
],
490 result
= verify_bgp_rib(tgen
, addr_type
, "r1", static_routes_input
)
493 ), "Testcase {} : Failed : Redistributed routes from R0 is not learned in Router R1 RIB \n Error: {}".format(
496 static_routes_input
= {
500 "network": [NETWORK1_1
[addr_type
]],
501 "next_hop": NEXT_HOP_IP
[addr_type
],
504 "network": [R0_NETWORK_LOOPBACK
[addr_type
]],
505 "next_hop": R0_NETWORK_LOOPBACK
[addr_type
],
508 "network": [R0_NETWORK_CONNECTED
[addr_type
]],
509 "next_hop": R0_NETWORK_CONNECTED_NXTHOP
[addr_type
],
512 "network": [R1_NETWORK_LOOPBACK
[addr_type
]],
513 "next_hop": R1_NETWORK_LOOPBACK
[addr_type
],
516 "network": [R1_NETWORK_CONNECTED
[addr_type
]],
517 "next_hop": R1_NETWORK_CONNECTED_NXTHOP
[addr_type
],
523 result
= verify_fib_routes(tgen
, addr_type
, "r1", static_routes_input
)
526 ), "Testcase {} : Failed : Redistributed routes from R0 is not learned in Router R1 FIB \n Error: {}".format(
530 step("verify IPv4 and IPv6 static route are configured and up on R3")
531 for addr_type
in ADDR_TYPES
:
532 static_routes_input
= {
536 "network": [NETWORK2_1
[addr_type
]],
537 "next_hop": NEXT_HOP_IP
[addr_type
],
540 "network": [R4_NETWORK_LOOPBACK
[addr_type
]],
541 "next_hop": R4_NETWORK_LOOPBACK
[addr_type
],
544 "network": [R4_NETWORK_CONNECTED
[addr_type
]],
545 "next_hop": R4_NETWORK_CONNECTED_NXTHOP
[addr_type
],
550 result
= verify_bgp_rib(tgen
, addr_type
, "r3", static_routes_input
)
553 ), "Testcase {} : Failed : Redistributed routes from R4 is not learned in Router R3 RIB \n Error: {}".format(
556 static_routes_input
= {
560 "network": [NETWORK2_1
[addr_type
]],
561 "next_hop": NEXT_HOP_IP
[addr_type
],
564 "network": [R3_NETWORK_LOOPBACK
[addr_type
]],
565 "next_hop": R3_NETWORK_LOOPBACK
[addr_type
],
568 "network": [R3_NETWORK_CONNECTED
[addr_type
]],
569 "next_hop": R3_NETWORK_CONNECTED_NXTHOP
[addr_type
],
572 "network": [R4_NETWORK_LOOPBACK
[addr_type
]],
573 "next_hop": R4_NETWORK_LOOPBACK
[addr_type
],
576 "network": [R4_NETWORK_CONNECTED
[addr_type
]],
577 "next_hop": R4_NETWORK_CONNECTED_NXTHOP
[addr_type
],
583 result
= verify_fib_routes(tgen
, addr_type
, "r3", static_routes_input
)
586 ), "Testcase {} : Redistributed routes from R4 is not learned in Router R3 FIB \n Error: {}".format(
590 step("Configure IPv4 and IPv6 prefix-list on R1 for (Sv4 , Sv6) route")
598 "network": NETWORK1_1
["ipv4"],
607 "network": NETWORK1_1
["ipv6"],
615 result
= create_prefix_lists(tgen
, input_dict_3
)
618 ), "Testcase {} : Failed to configure the prefix lists \n Error: {}".format(
622 step("Verify the Prefix - lists")
623 input_dict
= {"r3": {"prefix_lists": ["Pv4", "Pv6"]}}
624 result
= verify_prefix_lists(tgen
, input_dict
)
627 ), "Testcase {} : Failed to verify the prefix lists in router R3 \n Error: {}".format(
631 step("Configure IPv4 (RMv4) and IPv6 (RMv6) route-map on R1")
639 "match": {"ipv4": {"prefix_lists": "Pv4"}},
646 "match": {"ipv6": {"prefix_lists": "Pv6"}},
652 result
= create_route_maps(tgen
, input_dict_3
)
655 ), "Testcase {} : Failed to configure the route-map \n Error: {}".format(
660 " Configure default originate with route-map RMv4 and RMv6 for IPv4 and IPv6 bgp neighbors on R1 ( R1-R2) "
662 local_as
= get_dut_as_number(tgen
, dut
="r1")
663 default_originate_config
= {
666 "local_as": local_as
,
669 "unicast": {"default_originate": {"r2": {"route_map": "RMv4"}}}
672 "unicast": {"default_originate": {"r2": {"route_map": "RMv6"}}}
678 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
681 ), "Testcase {} : Failed to configure the default-originate in R1 towards R2 \n Error: {}".format(
685 step("verify IPv4 and IPv6 default route received on R2 with R1 nexthop ")
686 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
687 result
= verify_fib_default_route(
691 routes
=DEFAULT_ROUTES
,
692 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
696 ), "Testcase {} : Failed : Default routes are not learned in R2 FIB \n Error: {}".format(
700 result
= verify_rib_default_route(
704 routes
=DEFAULT_ROUTES
,
705 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
709 ), "Testcase {} : Failed : Default routes are not learned in R2 RIB\n Error: {}".format(
714 "Configure redistribute connected and static on R1 IPv4 and IPv6 address family"
716 redistribute_static
= {
721 "unicast": {"redistribute": [{"redist_type": "connected"}]}
724 "unicast": {"redistribute": [{"redist_type": "connected"}]}
730 result
= create_router_bgp(tgen
, topo
, redistribute_static
)
731 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
734 "Verify IPv4 and IPv6 static and loopback route advertised from R4 and R0 are received on R2"
736 for addr_type
in ADDR_TYPES
:
737 static_routes_input
= {
741 "network": [NETWORK1_1
[addr_type
]],
742 "next_hop": NEXT_HOP_IP
[addr_type
],
745 "network": [NETWORK2_1
[addr_type
]],
746 "next_hop": NEXT_HOP_IP
[addr_type
],
749 "network": [R0_NETWORK_LOOPBACK
[addr_type
]],
750 "next_hop": R0_NETWORK_LOOPBACK
[addr_type
],
753 "network": [R0_NETWORK_CONNECTED
[addr_type
]],
754 "next_hop": R0_NETWORK_CONNECTED_NXTHOP
[addr_type
],
757 "network": [R4_NETWORK_LOOPBACK
[addr_type
]],
758 "next_hop": R4_NETWORK_LOOPBACK
[addr_type
],
761 "network": [R4_NETWORK_CONNECTED
[addr_type
]],
762 "next_hop": R4_NETWORK_CONNECTED_NXTHOP
[addr_type
],
768 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
769 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
773 result
= verify_fib_routes(tgen
, addr_type
, "r2", static_routes_input
)
774 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
778 step(" Configure default-originate on R3 for R3 to R2 IPv4 and IPv6 BGP neighbors ")
779 local_as
= get_dut_as_number(tgen
, dut
="r3")
780 default_originate_config
= {
783 "local_as": local_as
,
785 "ipv4": {"unicast": {"default_originate": {"r2": {}}}},
786 "ipv6": {"unicast": {"default_originate": {"r2": {}}}},
791 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
792 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
794 STEP
= """After configuring the Default Originate From R3 --> R2
795 Both Default routes from R1 and R3 Should present in R2 BGP RIB.
796 'The Deafult Route from iBGP is preffered over EBGP' thus
797 Default Route From R1->r2 should only present in R2 FIB """
800 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
801 result
= verify_fib_default_route(
805 routes
=DEFAULT_ROUTES
,
806 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
811 ), "Testcase {} : Failed \n IBGP default route should be preffered over EBGP default-originate \n Error: {}".format(
815 result
= verify_rib_default_route(
819 routes
=DEFAULT_ROUTES
,
820 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
823 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
825 step("Verify the default route from R1 is recieved both on RIB and FIB on R2")
827 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
828 result
= verify_fib_default_route(
832 routes
=DEFAULT_ROUTES
,
833 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
836 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
838 result
= verify_rib_default_route(
842 routes
=DEFAULT_ROUTES
,
843 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
846 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
849 "Verify the static and loopback route advertised from R0 and R4 are received on R2 "
851 for addr_type
in ADDR_TYPES
:
852 static_routes_input
= {
856 "network": [NETWORK1_1
[addr_type
]],
857 "next_hop": NEXT_HOP_IP
[addr_type
],
860 "network": [NETWORK2_1
[addr_type
]],
861 "next_hop": NEXT_HOP_IP
[addr_type
],
864 "network": [R0_NETWORK_LOOPBACK
[addr_type
]],
865 "next_hop": R0_NETWORK_LOOPBACK
[addr_type
],
868 "network": [R0_NETWORK_CONNECTED
[addr_type
]],
869 "next_hop": R0_NETWORK_CONNECTED_NXTHOP
[addr_type
],
872 "network": [R4_NETWORK_LOOPBACK
[addr_type
]],
873 "next_hop": R4_NETWORK_LOOPBACK
[addr_type
],
876 "network": [R4_NETWORK_CONNECTED
[addr_type
]],
877 "next_hop": R4_NETWORK_CONNECTED_NXTHOP
[addr_type
],
883 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
884 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
888 result
= verify_fib_routes(tgen
, addr_type
, "r2", static_routes_input
)
889 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
893 step(" BGP Daemon restart operation")
894 routers
= ["r1", "r2"]
897 "Restart BGPD process on {}, when all the processes are running use watchfrr ".format(
901 kill_router_daemons(tgen
, dut
, ["bgpd"])
902 start_router_daemons(tgen
, dut
, ["bgpd"])
904 step("After restarting the BGP daomon Verify the default originate ")
905 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
906 result
= verify_fib_default_route(
910 routes
=DEFAULT_ROUTES
,
911 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
916 ), "Testcase {} : Failed \n IBGP default route should be prefeered over EBGP \n Error: {}".format(
920 result
= verify_rib_default_route(
924 routes
=DEFAULT_ROUTES
,
925 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
928 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
933 "Verify the default route from R1 is is recieved both on RIB and FIB on R2"
936 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
937 result
= verify_fib_default_route(
941 routes
=DEFAULT_ROUTES
,
942 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
945 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
949 result
= verify_rib_default_route(
953 routes
=DEFAULT_ROUTES
,
954 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
957 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
962 "Verify the static and loopback route advertised from R0 and R4 are received on R2 "
964 for addr_type
in ADDR_TYPES
:
965 static_routes_input
= {
969 "network": [NETWORK1_1
[addr_type
]],
970 "next_hop": NEXT_HOP_IP
[addr_type
],
973 "network": [NETWORK2_1
[addr_type
]],
974 "next_hop": NEXT_HOP_IP
[addr_type
],
977 "network": [R0_NETWORK_LOOPBACK
[addr_type
]],
978 "next_hop": R0_NETWORK_LOOPBACK
[addr_type
],
981 "network": [R0_NETWORK_CONNECTED
[addr_type
]],
982 "next_hop": R0_NETWORK_CONNECTED_NXTHOP
[addr_type
],
985 "network": [R4_NETWORK_LOOPBACK
[addr_type
]],
986 "next_hop": R4_NETWORK_LOOPBACK
[addr_type
],
989 "network": [R4_NETWORK_CONNECTED
[addr_type
]],
990 "next_hop": R4_NETWORK_CONNECTED_NXTHOP
[addr_type
],
996 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
997 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1001 result
= verify_fib_routes(tgen
, addr_type
, "r2", static_routes_input
)
1002 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1006 step(" Restarting FRR routers operation")
1008 NOTE : Verify that iBGP default route is preffered over eBGP default route
1010 routers
= ["r1", "r2"]
1013 "Restart FRR router process on {}, when all the processes are running use watchfrr ".format(
1018 stop_router(tgen
, dut
)
1019 start_router(tgen
, dut
)
1021 result
= verify_bgp_convergence(tgen
, topo
)
1024 ), " Testcase {} : After Restarting {} Convergence Failed".format(tc_name
, dut
)
1026 step("After restarting the FRR Router Verify the default originate ")
1027 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1028 result
= verify_fib_default_route(
1032 routes
=DEFAULT_ROUTES
,
1033 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
1036 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1040 result
= verify_rib_default_route(
1044 routes
=DEFAULT_ROUTES
,
1045 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
1048 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1053 "Verify the default route from R1 is is recieved both on RIB and FIB on R2"
1056 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1057 result
= verify_rib_default_route(
1061 routes
=DEFAULT_ROUTES
,
1062 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1065 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1069 result
= verify_fib_default_route(
1073 routes
=DEFAULT_ROUTES
,
1074 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1079 ), "Testcase {} : Failed\n IBGP default route should be preffered over EBGP default route \n Error: {}".format(
1084 "Verify the static and loopback route advertised from R0 and R4 are received on R2 "
1086 for addr_type
in ADDR_TYPES
:
1087 static_routes_input
= {
1091 "network": [NETWORK1_1
[addr_type
]],
1092 "next_hop": NEXT_HOP_IP
[addr_type
],
1095 "network": [NETWORK2_1
[addr_type
]],
1096 "next_hop": NEXT_HOP_IP
[addr_type
],
1099 "network": [R0_NETWORK_LOOPBACK
[addr_type
]],
1100 "next_hop": R0_NETWORK_LOOPBACK
[addr_type
],
1103 "network": [R0_NETWORK_CONNECTED
[addr_type
]],
1104 "next_hop": R0_NETWORK_CONNECTED_NXTHOP
[addr_type
],
1107 "network": [R4_NETWORK_LOOPBACK
[addr_type
]],
1108 "next_hop": R4_NETWORK_LOOPBACK
[addr_type
],
1111 "network": [R4_NETWORK_CONNECTED
[addr_type
]],
1112 "next_hop": R4_NETWORK_CONNECTED_NXTHOP
[addr_type
],
1118 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
1119 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1123 result
= verify_fib_routes(tgen
, addr_type
, "r2", static_routes_input
)
1124 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1128 write_test_footer(tc_name
)
1131 def test_verify_default_originate_after_shut_no_shut_bgp_neighbor_p1(request
):
1133 Summary: "Verify default-originate route after shut/no shut and clear BGP neighbor "
1135 tgen
= get_topogen()
1136 global BGP_CONVERGENCE
1139 tc_name
= request
.node
.name
1140 write_test_header(tc_name
)
1141 tgen
= get_topogen()
1142 # Don't run this test if we have any failure.
1143 if tgen
.routers_have_failure():
1144 check_router_status(tgen
)
1145 reset_config_on_routers(tgen
)
1147 if BGP_CONVERGENCE
!= True:
1148 pytest
.skip("skipped because of BGP Convergence failure")
1150 step("Configure EBGP between R0 to R1 and IBGP between R1 to R2")
1151 step("Configure EBGP between R2 to R3 and IBGP between R3 to R4")
1179 result
= modify_as_number(tgen
, topo
, input_dict
)
1181 assert result
is True
1182 except AssertionError:
1183 logger
.info("Expected behaviour: {}".format(result
))
1184 logger
.info("BGP config is not created because of invalid ASNs")
1185 step("After changing the BGP AS Path Verify the BGP Convergence")
1186 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
1187 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
1191 step("Configure one IPv4 and one IPv6 static route on R0 and R4")
1192 for addr_type
in ADDR_TYPES
:
1193 static_routes_input
= {
1197 "network": [NETWORK1_1
[addr_type
]],
1198 "next_hop": NEXT_HOP_IP
[addr_type
],
1203 result
= create_static_routes(tgen
, static_routes_input
)
1204 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1208 for addr_type
in ADDR_TYPES
:
1209 static_routes_input
= {
1213 "network": [NETWORK2_1
[addr_type
]],
1214 "next_hop": NEXT_HOP_IP
[addr_type
],
1219 result
= create_static_routes(tgen
, static_routes_input
)
1220 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1224 step("Verify IPv4 and IPv6 static route configured on R0 and R4")
1225 for addr_type
in ADDR_TYPES
:
1226 static_routes_input
= {
1230 "network": [NETWORK1_1
[addr_type
]],
1231 "next_hop": NEXT_HOP_IP
[addr_type
],
1236 result
= verify_fib_routes(tgen
, addr_type
, "r0", static_routes_input
)
1237 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1240 for addr_type
in ADDR_TYPES
:
1241 static_routes_input
= {
1245 "network": [NETWORK2_1
[addr_type
]],
1246 "next_hop": NEXT_HOP_IP
[addr_type
],
1251 result
= verify_fib_routes(tgen
, addr_type
, "r4", static_routes_input
)
1252 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1257 "Configure redistribute connected and static on R0 (R0-R1) on R4 ( R4-R3) IPv4 and IPv6 address family"
1259 redistribute_static
= {
1267 "redist_type": "static",
1270 "redist_type": "connected",
1279 "redist_type": "static",
1282 "redist_type": "connected",
1297 "redist_type": "static",
1300 "redist_type": "connected",
1309 "redist_type": "static",
1312 "redist_type": "connected",
1327 "redist_type": "connected",
1336 "redist_type": "connected",
1345 result
= create_router_bgp(tgen
, topo
, redistribute_static
)
1346 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1348 step("Verify IPv4 and IPv6 static route configured on R1 from R0")
1349 for addr_type
in ADDR_TYPES
:
1350 static_routes_input
= {
1354 "network": [NETWORK1_1
[addr_type
]],
1355 "next_hop": NEXT_HOP_IP
[addr_type
],
1358 "network": [R0_NETWORK_LOOPBACK
[addr_type
]],
1359 "next_hop": R0_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
1362 "network": [R0_NETWORK_CONNECTED
[addr_type
]],
1363 "next_hop": R0_NETWORK_CONNECTED_NXTHOP
[addr_type
],
1368 result
= verify_bgp_rib(tgen
, addr_type
, "r1", static_routes_input
)
1369 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1372 result
= verify_fib_routes(tgen
, addr_type
, "r1", static_routes_input
)
1373 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1377 step("Verify IPv4 and IPv6 static route configured on R3 from R4")
1378 for addr_type
in ADDR_TYPES
:
1379 static_routes_input
= {
1383 "network": [NETWORK2_1
[addr_type
]],
1384 "next_hop": NEXT_HOP_IP
[addr_type
],
1387 "network": [R4_NETWORK_LOOPBACK
[addr_type
]],
1388 "next_hop": R4_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
1391 "network": [R4_NETWORK_CONNECTED
[addr_type
]],
1392 "next_hop": R4_NETWORK_CONNECTED_NXTHOP
[addr_type
],
1397 result
= verify_bgp_rib(tgen
, addr_type
, "r3", static_routes_input
)
1398 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1401 result
= verify_fib_routes(tgen
, addr_type
, "r3", static_routes_input
)
1402 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1407 "Configure default-originate on R1 for R1 to R2 neighbor for IPv4 and IPv6 peer "
1409 local_as
= get_dut_as_number(tgen
, dut
="r1")
1410 default_originate_config
= {
1413 "local_as": local_as
,
1415 "ipv4": {"unicast": {"default_originate": {"r2": {}}}},
1416 "ipv6": {"unicast": {"default_originate": {"r2": {}}}},
1421 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
1422 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1424 step("Verify IPv4 and IPv6 bgp default route received on R2 nexthop as R1")
1425 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1427 "After configuring default-originate command , verify default routes are advertised on R2 from R0 and R4"
1429 for addr_type
in ADDR_TYPES
:
1430 static_routes_input
= {
1434 "network": [DEFAULT_ROUTES
[addr_type
]],
1435 "next_hop": DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1441 result
= verify_fib_routes(
1445 static_routes_input
,
1446 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1448 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1452 result
= verify_bgp_rib(
1456 static_routes_input
,
1457 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1459 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1463 for addr_type
in ADDR_TYPES
:
1464 static_routes_input
= {
1468 "network": [NETWORK1_1
[addr_type
]],
1469 "next_hop": NEXT_HOP_IP
[addr_type
],
1472 "network": [NETWORK2_1
[addr_type
]],
1473 "next_hop": NEXT_HOP_IP
[addr_type
],
1476 "network": [R0_NETWORK_LOOPBACK
[addr_type
]],
1477 "next_hop": R0_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
1480 "network": [R0_NETWORK_CONNECTED
[addr_type
]],
1481 "next_hop": R0_NETWORK_CONNECTED_NXTHOP
[addr_type
],
1484 "network": [R4_NETWORK_LOOPBACK
[addr_type
]],
1485 "next_hop": R4_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
1488 "network": [R4_NETWORK_CONNECTED
[addr_type
]],
1489 "next_hop": R4_NETWORK_CONNECTED_NXTHOP
[addr_type
],
1495 result
= verify_fib_routes(tgen
, addr_type
, "r2", static_routes_input
)
1496 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1500 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
1501 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1506 "Configure default-originate on R3 for R3 to R2 neighbor for IPv4 and IPv6 peer"
1508 local_as
= get_dut_as_number(tgen
, dut
="r3")
1509 default_originate_config
= {
1512 "local_as": local_as
,
1514 "ipv4": {"unicast": {"default_originate": {"r2": {}}}},
1515 "ipv6": {"unicast": {"default_originate": {"r2": {}}}},
1520 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
1521 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1523 STEP
= """After configuring the Default Originate From R3 --> R2
1524 Both Default routes from R1 and R3 Should present in R2 BGP RIB.
1525 'The Deafult Route from iBGP is preffered over EBGP' thus
1526 Default Route From R1->r2 should only present in R2 FIB """
1529 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1530 result
= verify_fib_default_route(
1534 routes
=DEFAULT_ROUTES
,
1535 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1540 ), "Testcase {} : Failed \n IBGP default route should be preffered over EBGP \n Error: {}".format(
1544 result
= verify_rib_default_route(
1548 routes
=DEFAULT_ROUTES
,
1549 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1552 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1554 step("Verify the default route from R1 is recieved both on RIB and FIB on R2")
1556 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1557 result
= verify_fib_default_route(
1561 routes
=DEFAULT_ROUTES
,
1562 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
1565 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1567 result
= verify_rib_default_route(
1571 routes
=DEFAULT_ROUTES
,
1572 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
1575 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1578 "After configuring default-originate command , verify static ,connected and loopback routes are advertised on R2 from R0 and R4"
1580 for addr_type
in ADDR_TYPES
:
1581 static_routes_input
= {
1585 "network": [NETWORK1_1
[addr_type
]],
1586 "next_hop": NEXT_HOP_IP
[addr_type
],
1589 "network": [NETWORK2_1
[addr_type
]],
1590 "next_hop": NEXT_HOP_IP
[addr_type
],
1593 "network": [R0_NETWORK_LOOPBACK
[addr_type
]],
1594 "next_hop": R0_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
1597 "network": [R0_NETWORK_CONNECTED
[addr_type
]],
1598 "next_hop": R0_NETWORK_CONNECTED_NXTHOP
[addr_type
],
1601 "network": [R4_NETWORK_LOOPBACK
[addr_type
]],
1602 "next_hop": R4_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
1605 "network": [R4_NETWORK_CONNECTED
[addr_type
]],
1606 "next_hop": R4_NETWORK_CONNECTED_NXTHOP
[addr_type
],
1612 result
= verify_fib_routes(tgen
, addr_type
, "r2", static_routes_input
)
1613 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1617 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
1618 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1621 # updating the topology with the updated AS-Number to avoid conflict in con configuring the AS
1623 updated_topo
["routers"]["r0"]["bgp"]["local_as"] = get_dut_as_number(tgen
, "r0")
1624 updated_topo
["routers"]["r1"]["bgp"]["local_as"] = get_dut_as_number(tgen
, "r1")
1625 updated_topo
["routers"]["r2"]["bgp"]["local_as"] = get_dut_as_number(tgen
, "r2")
1626 updated_topo
["routers"]["r3"]["bgp"]["local_as"] = get_dut_as_number(tgen
, "r3")
1627 updated_topo
["routers"]["r4"]["bgp"]["local_as"] = get_dut_as_number(tgen
, "r4")
1630 "Shut R1 to R2 IPv4 and IPv6 BGP neighbor from R1 IPv4 and IPv6 address family "
1633 local_as
= get_dut_as_number(tgen
, dut
="r1")
1637 "local_as": local_as
,
1642 "r2": {"dest_link": {"r1": {"shutdown": True}}}
1649 "r2": {"dest_link": {"r1": {"shutdown": True}}}
1657 result
= create_router_bgp(tgen
, updated_topo
, shut_neighbor
)
1658 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1660 interface
= topo
["routers"]["r2"]["links"]["r1"]["interface"]
1661 input_dict
= {"r2": {"interface_list": [interface
], "status": "down"}}
1663 result
= interface_status(tgen
, topo
, input_dict
)
1666 ), "Testcase {} : Bring down interface failed ! \n Error: {}".format(
1671 "Verify IPv4 and IPv6 default static and loopback route which received from R1 are deleted from R2"
1673 for addr_type
in ADDR_TYPES
:
1674 static_routes_input
= {
1678 "network": [NETWORK1_1
[addr_type
]],
1679 "next_hop": NEXT_HOP_IP
[addr_type
],
1682 "network": [R0_NETWORK_LOOPBACK
[addr_type
]],
1683 "next_hop": R0_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
1686 "network": [R0_NETWORK_CONNECTED
[addr_type
]],
1687 "next_hop": R0_NETWORK_CONNECTED_NXTHOP
[addr_type
],
1692 result
= verify_bgp_rib(
1693 tgen
, addr_type
, "r2", static_routes_input
, expected
=False
1697 ), "Testcase {} : Failed \n after shutting down interface routes are not expected \n Error: {}".format(
1700 result
= verify_fib_routes(
1701 tgen
, addr_type
, "r2", static_routes_input
, expected
=False
1705 ), "Testcase {} : Failed \n after shutting down interface routes are not expected \n Error: {}".format(
1709 step("verify that No impact on IPv4 IPv6 and default route received from R3 ")
1710 for addr_type
in ADDR_TYPES
:
1711 static_routes_input
= {
1715 "network": [NETWORK2_1
[addr_type
]],
1716 "next_hop": NEXT_HOP_IP
[addr_type
],
1719 "network": [R4_NETWORK_LOOPBACK
[addr_type
]],
1720 "next_hop": R4_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
1723 "network": [R4_NETWORK_CONNECTED
[addr_type
]],
1724 "next_hop": R4_NETWORK_CONNECTED_NXTHOP
[addr_type
],
1730 result
= verify_fib_routes(tgen
, addr_type
, "r2", static_routes_input
)
1731 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1735 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
1736 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1740 "No-Shut R1 to R2 IPv4 and IPv6 BGP neighbor from R1 IPv4 and IPv6 address family "
1742 local_as
= get_dut_as_number(tgen
, dut
="r1")
1746 "local_as": local_as
,
1751 "r2": {"dest_link": {"r1": {"shutdown": False}}}
1758 "r2": {"dest_link": {"r1": {"shutdown": False}}}
1766 result
= create_router_bgp(tgen
, updated_topo
, shut_neighbor
)
1767 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1769 interface
= topo
["routers"]["r2"]["links"]["r1"]["interface"]
1770 input_dict
= {"r2": {"interface_list": [interface
], "status": "up"}}
1772 result
= interface_status(tgen
, topo
, input_dict
)
1775 ), "Testcase {} : Bring up interface failed ! \n Error: {}".format(tc_name
, result
)
1778 "After no shut Verify IPv4 and IPv6 bgp default route next hop as R1 , static ,connected and loopback received on R2 from r0 and r4 "
1781 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1782 for addr_type
in ADDR_TYPES
:
1783 static_routes_input
= {
1787 "network": [DEFAULT_ROUTES
[addr_type
]],
1788 "next_hop": DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1794 result
= verify_fib_routes(
1798 static_routes_input
,
1799 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1801 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1805 result
= verify_bgp_rib(
1809 static_routes_input
,
1810 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1812 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1815 for addr_type
in ADDR_TYPES
:
1816 static_routes_input
= {
1820 "network": [NETWORK1_1
[addr_type
]],
1821 "next_hop": NEXT_HOP_IP
[addr_type
],
1824 "network": [NETWORK2_1
[addr_type
]],
1825 "next_hop": NEXT_HOP_IP
[addr_type
],
1828 "network": [R0_NETWORK_LOOPBACK
[addr_type
]],
1829 "next_hop": R0_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
1832 "network": [R0_NETWORK_CONNECTED
[addr_type
]],
1833 "next_hop": R0_NETWORK_CONNECTED_NXTHOP
[addr_type
],
1836 "network": [R4_NETWORK_LOOPBACK
[addr_type
]],
1837 "next_hop": R4_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
1840 "network": [R4_NETWORK_CONNECTED
[addr_type
]],
1841 "next_hop": R4_NETWORK_CONNECTED_NXTHOP
[addr_type
],
1847 result
= verify_fib_routes(tgen
, addr_type
, "r2", static_routes_input
)
1848 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1852 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
1853 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1857 "Shut R3 to R2 IPv4 and IPv6 BGP neighbor from R2 IPv4 and IPv6 address family"
1859 local_as
= get_dut_as_number(tgen
, dut
="r3")
1863 "local_as": local_as
,
1868 "r2": {"dest_link": {"r3": {"shutdown": True}}}
1875 "r2": {"dest_link": {"r3": {"shutdown": True}}}
1883 result
= create_router_bgp(tgen
, updated_topo
, shut_neighbor
)
1884 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1886 interface
= topo
["routers"]["r2"]["links"]["r3"]["interface"]
1887 input_dict
= {"r2": {"interface_list": [interface
], "status": "down"}}
1889 result
= interface_status(tgen
, topo
, input_dict
)
1892 ), "Testcase {} : Bring down interface failed ! \n Error: {}".format(
1897 "Verify IPv4 and IPv6 default static and loopback route which received from R3 are deleted from R2 "
1899 for addr_type
in ADDR_TYPES
:
1900 static_routes_input
= {
1904 "network": [NETWORK2_1
[addr_type
]],
1905 "next_hop": NEXT_HOP_IP
[addr_type
],
1908 "network": [R4_NETWORK_LOOPBACK
[addr_type
]],
1909 "next_hop": R4_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
1912 "network": [R4_NETWORK_CONNECTED
[addr_type
]],
1913 "next_hop": R4_NETWORK_CONNECTED_NXTHOP
[addr_type
],
1918 result
= verify_bgp_rib(
1919 tgen
, addr_type
, "r2", static_routes_input
, expected
=False
1923 ), "Testcase {} : Failed\n After shutting down the interface routes are not expected \n Error: {}".format(
1926 result
= verify_fib_routes(
1927 tgen
, addr_type
, "r2", static_routes_input
, expected
=False
1931 ), "Testcase {} : Failed \n After shutting down the interface routes are not expected \n Error: {}".format(
1935 step("Verify that Default route is removed i.e advertised from R3")
1936 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1937 result
= verify_fib_default_route(
1941 routes
=DEFAULT_ROUTES
,
1942 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1947 ), "Testcase {} : Failed \n After shutting down the interface Default route are not expected \n Error: {}".format(
1951 result
= verify_rib_default_route(
1955 routes
=DEFAULT_ROUTES
,
1956 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1961 ), "Testcase {} : Failed \n After shutting down the interface Default route are not expected \n Error: {}".format(
1965 step("Verify that No impact on IPv4 IPv6 and default route received from R1")
1967 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1968 for addr_type
in ADDR_TYPES
:
1969 static_routes_input
= {
1973 "network": [DEFAULT_ROUTES
[addr_type
]],
1974 "next_hop": DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1980 result
= verify_fib_routes(
1984 static_routes_input
,
1985 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1987 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1991 result
= verify_bgp_rib(
1995 static_routes_input
,
1996 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1998 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2002 for addr_type
in ADDR_TYPES
:
2003 static_routes_input
= {
2007 "network": [NETWORK1_1
[addr_type
]],
2008 "next_hop": NEXT_HOP_IP
[addr_type
],
2011 "network": [R0_NETWORK_LOOPBACK
[addr_type
]],
2012 "next_hop": R0_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
2015 "network": [R0_NETWORK_CONNECTED
[addr_type
]],
2016 "next_hop": R0_NETWORK_CONNECTED_NXTHOP
[addr_type
],
2022 result
= verify_fib_routes(tgen
, addr_type
, "r2", static_routes_input
)
2023 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2027 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
2028 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2033 "No-Shut R3 to R2 IPv4 and IPv6 BGP neighbor from R2 IPv4 and IPv6 address family"
2035 local_as
= get_dut_as_number(tgen
, dut
="r3")
2039 "local_as": local_as
,
2044 "r2": {"dest_link": {"r3": {"shutdown": False}}}
2051 "r2": {"dest_link": {"r3": {"shutdown": False}}}
2059 result
= create_router_bgp(tgen
, updated_topo
, shut_neighbor
)
2060 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2062 interface
= topo
["routers"]["r2"]["links"]["r3"]["interface"]
2063 input_dict
= {"r2": {"interface_list": [interface
], "status": "up"}}
2065 result
= interface_status(tgen
, topo
, input_dict
)
2068 ), "Testcase {} : Bring up interface failed ! \n Error: {}".format(tc_name
, result
)
2071 "Verify that a static ,connected and loopback routes are received from R0 and R4 on R2 "
2073 for addr_type
in ADDR_TYPES
:
2074 static_routes_input
= {
2078 "network": [NETWORK1_1
[addr_type
]],
2079 "next_hop": NEXT_HOP_IP
[addr_type
],
2082 "network": [NETWORK2_1
[addr_type
]],
2083 "next_hop": NEXT_HOP_IP
[addr_type
],
2086 "network": [R0_NETWORK_LOOPBACK
[addr_type
]],
2087 "next_hop": R0_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
2090 "network": [R0_NETWORK_CONNECTED
[addr_type
]],
2091 "next_hop": R0_NETWORK_CONNECTED_NXTHOP
[addr_type
],
2094 "network": [R4_NETWORK_LOOPBACK
[addr_type
]],
2095 "next_hop": R4_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
2098 "network": [R4_NETWORK_CONNECTED
[addr_type
]],
2099 "next_hop": R4_NETWORK_CONNECTED_NXTHOP
[addr_type
],
2105 result
= verify_fib_routes(tgen
, addr_type
, "r2", static_routes_input
)
2106 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2110 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
2111 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2114 step("verify that default route is received on R2 from R1")
2115 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
2116 result
= verify_rib_default_route(
2120 routes
=DEFAULT_ROUTES
,
2121 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
2124 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2125 result
= verify_fib_default_route(
2129 routes
=DEFAULT_ROUTES
,
2130 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
2133 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2135 step("verify that default route is received on R2 from R3")
2137 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
2139 result
= verify_rib_default_route(
2143 routes
=DEFAULT_ROUTES
,
2144 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
2147 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2148 result
= verify_fib_default_route(
2152 routes
=DEFAULT_ROUTES
,
2153 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
2156 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
2159 step("Clear IPv4 and IP6 BGP session from R2 and R1 one by one ")
2160 routers
= ["r1", "r2"]
2162 for addr_type
in ADDR_TYPES
:
2164 clear_bgp(tgen
, addr_type
, dut
)
2166 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
2167 result
= verify_rib_default_route(
2171 routes
=DEFAULT_ROUTES
,
2172 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
2175 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2178 result
= verify_fib_default_route(
2182 routes
=DEFAULT_ROUTES
,
2183 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
2186 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2189 step("verify that default route is received on R2 from R3")
2191 interface
= topo
["routers"]["r3"]["links"]["r2"]["interface"]
2192 ipv6_link_local
= get_frr_ipv6_linklocal(tgen
, "r3", intf
=interface
)
2193 ipv4_nxt_hop
= topo
["routers"]["r3"]["links"]["r2"]["ipv4"].split("/")[0]
2194 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
2195 DEFAULT_ROUTE_NXT_HOP
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local
}
2197 result
= verify_rib_default_route(
2201 routes
=DEFAULT_ROUTES
,
2202 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
2205 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2208 result
= verify_fib_default_route(
2212 routes
=DEFAULT_ROUTES
,
2213 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
2216 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
2221 "Verify the static , loopback and connected routes received from r0 and r4"
2223 for addr_type
in ADDR_TYPES
:
2224 static_routes_input
= {
2228 "network": [NETWORK1_1
[addr_type
]],
2229 "next_hop": NEXT_HOP_IP
[addr_type
],
2232 "network": [NETWORK2_1
[addr_type
]],
2233 "next_hop": NEXT_HOP_IP
[addr_type
],
2236 "network": [R0_NETWORK_LOOPBACK
[addr_type
]],
2237 "next_hop": R0_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
2240 "network": [R0_NETWORK_CONNECTED
[addr_type
]],
2241 "next_hop": R0_NETWORK_CONNECTED_NXTHOP
[addr_type
],
2244 "network": [R4_NETWORK_LOOPBACK
[addr_type
]],
2245 "next_hop": R4_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
2248 "network": [R4_NETWORK_CONNECTED
[addr_type
]],
2249 "next_hop": R4_NETWORK_CONNECTED_NXTHOP
[addr_type
],
2255 result
= verify_fib_routes(tgen
, addr_type
, "r2", static_routes_input
)
2256 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2260 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
2261 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2265 step("Shut BGP neighbor interface R2 (R2 to R1) link ")
2266 intf_r2_r1
= topo
["routers"]["r2"]["links"]["r1"]["interface"]
2267 shutdown_bringup_interface(tgen
, "r2", intf_r2_r1
, False)
2269 step("Verify the bgp Convergence ")
2270 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
, expected
=False)
2272 BGP_CONVERGENCE
is not True
2273 ), " :Failed After shutting interface BGP convergence is expected to be faileed \n Error: {}".format(
2277 step("Verify that default route from R1 got deleted from BGP and RIB table")
2278 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
2280 result
= verify_rib_default_route(
2284 routes
=DEFAULT_ROUTES
,
2285 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
2290 ), "Testcase {} : Failed\n After shuting interface default route should be removed from RIB \n Error: {}".format(
2294 step("No - Shut BGP neighbor interface R2 (R2 to R1) link ")
2295 intf_r2_r1
= topo
["routers"]["r2"]["links"]["r1"]["interface"]
2296 shutdown_bringup_interface(tgen
, "r2", intf_r2_r1
, True)
2298 step("Verify the bgp Convergence ")
2299 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
2300 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
2303 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
2304 result
= verify_rib_default_route(
2308 routes
=DEFAULT_ROUTES
,
2309 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
2312 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2313 result
= verify_fib_default_route(
2317 routes
=DEFAULT_ROUTES
,
2318 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
2321 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2322 step("verify that default route is received on R2 from R3")
2324 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
2325 result
= verify_rib_default_route(
2329 routes
=DEFAULT_ROUTES
,
2330 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
2333 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2334 result
= verify_fib_default_route(
2338 routes
=DEFAULT_ROUTES
,
2339 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
2342 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
2346 step("Verify the static , loopback and connected routes received from r0 and r4")
2347 for addr_type
in ADDR_TYPES
:
2348 static_routes_input
= {
2352 "network": [NETWORK1_1
[addr_type
]],
2353 "next_hop": NEXT_HOP_IP
[addr_type
],
2356 "network": [NETWORK2_1
[addr_type
]],
2357 "next_hop": NEXT_HOP_IP
[addr_type
],
2360 "network": [R0_NETWORK_LOOPBACK
[addr_type
]],
2361 "next_hop": R0_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
2364 "network": [R0_NETWORK_CONNECTED
[addr_type
]],
2365 "next_hop": R0_NETWORK_CONNECTED_NXTHOP
[addr_type
],
2368 "network": [R4_NETWORK_LOOPBACK
[addr_type
]],
2369 "next_hop": R4_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
2372 "network": [R4_NETWORK_CONNECTED
[addr_type
]],
2373 "next_hop": R4_NETWORK_CONNECTED_NXTHOP
[addr_type
],
2379 result
= verify_fib_routes(tgen
, addr_type
, "r2", static_routes_input
)
2380 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2384 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
2385 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2389 step("Shut link from R3 to R2 from R3")
2390 intf_r3_r2
= topo
["routers"]["r3"]["links"]["r2"]["interface"]
2391 shutdown_bringup_interface(tgen
, "r3", intf_r3_r2
, False)
2393 step("Verify the bgp Convergence ")
2394 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
, expected
=False)
2396 BGP_CONVERGENCE
is not True
2397 ), " :Failed \nAfter Shuting the interface BGP convegence is expected to be failed \n Error: {}".format(
2401 step("Verify that default route from R3 got deleted from BGP and RIB table")
2402 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
2404 result
= verify_rib_default_route(
2408 routes
=DEFAULT_ROUTES
,
2409 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
2412 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
2415 step("No-Shut link from R3 to R2 from R3")
2417 ipv4_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"]["ipv4"].split("/")[0]
2418 ipv6_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"]["ipv6"].split("/")[0]
2420 DEFAULT_ROUTE_NXT_HOP_1
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_nxt_hop
}
2422 ipv4_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"]["ipv4"].split("/")[0]
2423 ipv6_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"]["ipv6"].split("/")[0]
2425 DEFAULT_ROUTE_NXT_HOP_3
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_nxt_hop
}
2427 intf_r3_r2
= topo
["routers"]["r3"]["links"]["r2"]["interface"]
2428 shutdown_bringup_interface(tgen
, "r3", intf_r3_r2
, True)
2430 step("Verify the bgp Convergence ")
2431 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
, expected
=True)
2432 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
2435 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
2437 result
= verify_rib_default_route(
2441 routes
=DEFAULT_ROUTES
,
2442 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
2445 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2446 result
= verify_fib_default_route(
2450 routes
=DEFAULT_ROUTES
,
2451 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
2454 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2455 step("verify that default route is received on R2 from R3")
2457 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
2459 result
= verify_rib_default_route(
2463 routes
=DEFAULT_ROUTES
,
2464 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
2467 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2468 result
= verify_fib_default_route(
2472 routes
=DEFAULT_ROUTES
,
2473 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
2476 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
2480 step("Verify the static , loopback and connected routes received from r0 and r4")
2481 for addr_type
in ADDR_TYPES
:
2482 static_routes_input
= {
2486 "network": [NETWORK1_1
[addr_type
]],
2487 "next_hop": NEXT_HOP_IP
[addr_type
],
2490 "network": [NETWORK2_1
[addr_type
]],
2491 "next_hop": NEXT_HOP_IP
[addr_type
],
2494 "network": [R0_NETWORK_LOOPBACK
[addr_type
]],
2495 "next_hop": R0_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
2498 "network": [R0_NETWORK_CONNECTED
[addr_type
]],
2499 "next_hop": R0_NETWORK_CONNECTED_NXTHOP
[addr_type
],
2502 "network": [R4_NETWORK_LOOPBACK
[addr_type
]],
2503 "next_hop": R4_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
2506 "network": [R4_NETWORK_CONNECTED
[addr_type
]],
2507 "next_hop": R4_NETWORK_CONNECTED_NXTHOP
[addr_type
],
2513 result
= verify_fib_routes(tgen
, addr_type
, "r2", static_routes_input
)
2514 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2518 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
2519 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2523 write_test_footer(tc_name
)
2526 if __name__
== "__main__":
2527 args
= ["-s"] + sys
.argv
[1:]
2528 sys
.exit(pytest
.main(args
))