2 # SPDX-License-Identifier: ISC
4 # Copyright (c) 2022 by VMware, Inc. ("VMware")
5 # Shreenidhi A R <rshreenidhi@vmware.com>
6 # Used Copyright (c) 2018 by Network Device Education Foundation, Inc. ("NetDEF")
10 Following tests are covered.
11 1. Verify BGP default-originate route with IBGP peer
12 2. Verify BGP default-originate route with EBGP peer
13 3. Verify BGP default route when default-originate configured with route-map over IBGP peer
14 4. Verify BGP default route when default-originate configured with route-map over EBGP peer"
21 from time
import sleep
22 from copy
import deepcopy
23 from lib
.topolog
import logger
25 # pylint: disable=C0413
26 # Import topogen and topotest helpers
27 from lib
.topogen
import Topogen
, get_topogen
28 from lib
.topojson
import build_config_from_json
29 from lib
.topolog
import logger
32 verify_bgp_convergence
,
33 verify_graceful_restart
,
41 get_prefix_count_route
,
43 verify_rib_default_route
,
44 verify_fib_default_route
,
45 verify_bgp_advertised_routes_from_neighbor
,
46 verify_bgp_received_routes_from_neighbor
,
48 from lib
.common_config
import (
54 shutdown_bringup_interface
,
56 required_linux_kernel_version
,
61 get_frr_ipv6_linklocal
,
66 reset_config_on_routers
,
73 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.staticd
]
75 # Save the Current Working Directory to find configuration files.
76 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
77 sys
.path
.append(os
.path
.join(CWD
, "../"))
78 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
80 # Required to instantiate the topology builder class.
82 # pylint: disable=C0413
83 # Import topogen and topotest helpers
90 NETWORK1_1
= {"ipv4": "1.1.1.1/32", "ipv6": "1::1/128"}
91 NETWORK1_2
= {"ipv4": "1.1.1.2/32", "ipv6": "1::2/128"}
92 NETWORK2_1
= {"ipv4": "2.1.1.1/32", "ipv6": "2::1/128"}
93 NETWORK2_2
= {"ipv4": "2.1.1.2/32", "ipv6": "2::2/128"}
94 NETWORK3_1
= {"ipv4": "3.1.1.1/32", "ipv6": "3::1/128"}
95 NETWORK3_2
= {"ipv4": "3.1.1.2/32", "ipv6": "3::2/128"}
96 NETWORK4_1
= {"ipv4": "4.1.1.1/32", "ipv6": "4::1/128"}
97 NETWORK4_2
= {"ipv4": "4.1.1.2/32", "ipv6": "4::2/128"}
98 NETWORK5_1
= {"ipv4": "5.1.1.1/32", "ipv6": "5::1/128"}
99 NETWORK5_2
= {"ipv4": "5.1.1.2/32", "ipv6": "5::2/128"}
100 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
101 NEXT_HOP_IP
= {"ipv4": "Null0", "ipv6": "Null0"}
106 IPV4_RM1
= "RMVIPV41"
107 IPV6_RM1
= "RMVIPV61"
109 IPV4_RM2
= "RMVIPV42"
110 IPV6_RM2
= "RMVIPV62"
119 r1_ipv4_loopback
= "1.0.1.0/24"
120 r2_ipv4_loopback
= "1.0.2.0/24"
121 r3_ipv4_loopback
= "1.0.3.0/24"
122 r4_ipv4_loopback
= "1.0.4.0/24"
123 r1_ipv6_loopback
= "2001:db8:f::1:0/120"
124 r2_ipv6_loopback
= "2001:db8:f::2:0/120"
125 r3_ipv6_loopback
= "2001:db8:f::3:0/120"
126 r4_ipv6_loopback
= "2001:db8:f::4:0/120"
128 r0_connected_address_ipv4
= "192.168.0.0/24"
129 r0_connected_address_ipv6
= "fd00::/64"
130 r1_connected_address_ipv4
= "192.168.1.0/24"
131 r1_connected_address_ipv6
= "fd00:0:0:1::/64"
132 r3_connected_address_ipv4
= "192.168.2.0/24"
133 r3_connected_address_ipv6
= "fd00:0:0:2::/64"
134 r4_connected_address_ipv4
= "192.168.3.0/24"
135 r4_connected_address_ipv6
= "fd00:0:0:3::/64"
138 def setup_module(mod
):
140 Sets up the pytest environment
145 # Required linux kernel version for this suite to run.
146 result
= required_linux_kernel_version("4.15")
147 if result
is not True:
148 pytest
.skip("Kernel requirements are not met")
150 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
151 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
152 logger
.info("=" * 40)
154 logger
.info("Running setup_module to create topology")
156 # This function initiates the topology build with Topogen...
157 json_file
= "{}/bgp_default_originate_topo1.json".format(CWD
)
158 tgen
= Topogen(json_file
, mod
.__name
__)
160 topo
= tgen
.json_topo
161 # ... and here it calls Mininet initialization functions.
163 # Starting topology, create tmp files which are loaded to routers
164 # to start daemons and then start routers
167 # Creating configuration from JSON
168 build_config_from_json(tgen
, topo
)
171 global BGP_CONVERGENCE
172 global DEFAULT_ROUTES
173 global DEFAULT_ROUTE_NXT_HOP_R1
, DEFAULT_ROUTE_NXT_HOP_R3
174 global R0_NETWORK_LOOPBACK
, R0_NETWORK_LOOPBACK_NXTHOP
, R1_NETWORK_LOOPBACK
, R1_NETWORK_LOOPBACK_NXTHOP
175 global R0_NETWORK_CONNECTED
, R0_NETWORK_CONNECTED_NXTHOP
, R1_NETWORK_CONNECTED
, R1_NETWORK_CONNECTED_NXTHOP
176 global R4_NETWORK_LOOPBACK
, R4_NETWORK_LOOPBACK_NXTHOP
, R3_NETWORK_LOOPBACK
, R3_NETWORK_LOOPBACK_NXTHOP
177 global R4_NETWORK_CONNECTED
, R4_NETWORK_CONNECTED_NXTHOP
, R3_NETWORK_CONNECTED
, R3_NETWORK_CONNECTED_NXTHOP
179 ADDR_TYPES
= check_address_types()
180 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
181 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
184 # There are the global varibles used through out the file these are acheived only after building the topology.
186 r0_loopback_address_ipv4
= topo
["routers"]["r0"]["links"]["lo"]["ipv4"]
187 r0_loopback_address_ipv4_nxt_hop
= topo
["routers"]["r0"]["links"]["r1"][
190 r0_loopback_address_ipv6
= topo
["routers"]["r0"]["links"]["lo"]["ipv6"]
191 r0_loopback_address_ipv6_nxt_hop
= topo
["routers"]["r0"]["links"]["r1"][
195 r1_loopback_address_ipv4
= topo
["routers"]["r1"]["links"]["lo"]["ipv4"]
196 r1_loopback_address_ipv4_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"][
199 r1_loopback_address_ipv6
= topo
["routers"]["r1"]["links"]["lo"]["ipv6"]
200 r1_loopback_address_ipv6_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"][
204 r4_loopback_address_ipv4
= topo
["routers"]["r4"]["links"]["lo"]["ipv4"]
205 r4_loopback_address_ipv4_nxt_hop
= topo
["routers"]["r4"]["links"]["r3"][
208 r4_loopback_address_ipv6
= topo
["routers"]["r4"]["links"]["lo"]["ipv6"]
209 r4_loopback_address_ipv6_nxt_hop
= topo
["routers"]["r4"]["links"]["r3"][
213 r3_loopback_address_ipv4
= topo
["routers"]["r3"]["links"]["lo"]["ipv4"]
214 r3_loopback_address_ipv4_nxt_hop
= topo
["routers"]["r3"]["links"]["r2"][
217 r3_loopback_address_ipv6
= topo
["routers"]["r3"]["links"]["lo"]["ipv6"]
218 r3_loopback_address_ipv6_nxt_hop
= topo
["routers"]["r3"]["links"]["r2"][
222 R0_NETWORK_LOOPBACK
= {
223 "ipv4": r0_loopback_address_ipv4
,
224 "ipv6": r0_loopback_address_ipv6
,
226 R0_NETWORK_LOOPBACK_NXTHOP
= {
227 "ipv4": r0_loopback_address_ipv4_nxt_hop
,
228 "ipv6": r0_loopback_address_ipv6_nxt_hop
,
231 R1_NETWORK_LOOPBACK
= {
232 "ipv4": r1_loopback_address_ipv4
,
233 "ipv6": r1_loopback_address_ipv6
,
235 R1_NETWORK_LOOPBACK_NXTHOP
= {
236 "ipv4": r1_loopback_address_ipv4_nxt_hop
,
237 "ipv6": r1_loopback_address_ipv6_nxt_hop
,
240 R0_NETWORK_CONNECTED
= {
241 "ipv4": r0_connected_address_ipv4
,
242 "ipv6": r0_connected_address_ipv6
,
244 R0_NETWORK_CONNECTED_NXTHOP
= {
245 "ipv4": r0_loopback_address_ipv4_nxt_hop
,
246 "ipv6": r0_loopback_address_ipv6_nxt_hop
,
249 R1_NETWORK_CONNECTED
= {
250 "ipv4": r1_connected_address_ipv4
,
251 "ipv6": r1_connected_address_ipv6
,
253 R1_NETWORK_CONNECTED_NXTHOP
= {
254 "ipv4": r1_loopback_address_ipv4_nxt_hop
,
255 "ipv6": r1_loopback_address_ipv6_nxt_hop
,
258 R4_NETWORK_LOOPBACK
= {
259 "ipv4": r4_loopback_address_ipv4
,
260 "ipv6": r4_loopback_address_ipv6
,
262 R4_NETWORK_LOOPBACK_NXTHOP
= {
263 "ipv4": r4_loopback_address_ipv4_nxt_hop
,
264 "ipv6": r4_loopback_address_ipv6_nxt_hop
,
267 R3_NETWORK_LOOPBACK
= {
268 "ipv4": r3_loopback_address_ipv4
,
269 "ipv6": r3_loopback_address_ipv6
,
271 R3_NETWORK_LOOPBACK_NXTHOP
= {
272 "ipv4": r3_loopback_address_ipv4_nxt_hop
,
273 "ipv6": r3_loopback_address_ipv6_nxt_hop
,
276 R4_NETWORK_CONNECTED
= {
277 "ipv4": r4_connected_address_ipv4
,
278 "ipv6": r4_connected_address_ipv6
,
280 R4_NETWORK_CONNECTED_NXTHOP
= {
281 "ipv4": r4_loopback_address_ipv4_nxt_hop
,
282 "ipv6": r4_loopback_address_ipv6_nxt_hop
,
285 R3_NETWORK_CONNECTED
= {
286 "ipv4": r3_connected_address_ipv4
,
287 "ipv6": r3_connected_address_ipv6
,
289 R3_NETWORK_CONNECTED_NXTHOP
= {
290 "ipv4": r3_loopback_address_ipv4_nxt_hop
,
291 "ipv6": r3_loopback_address_ipv6_nxt_hop
,
294 # populating the nexthop for default routes
296 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
298 interface
= topo
["routers"]["r1"]["links"]["r2"]["interface"]
299 ipv6_link_local
= get_frr_ipv6_linklocal(tgen
, "r1", intf
=interface
)
300 ipv4_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"]["ipv4"].split("/")[0]
301 ipv6_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"]["ipv6"].split("/")[0]
302 DEFAULT_ROUTE_NXT_HOP_R1
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local
}
304 interface
= topo
["routers"]["r3"]["links"]["r2"]["interface"]
305 ipv6_link_local
= get_frr_ipv6_linklocal(tgen
, "r3", intf
=interface
)
306 ipv4_nxt_hop
= topo
["routers"]["r3"]["links"]["r2"]["ipv4"].split("/")[0]
307 ipv6_nxt_hop
= topo
["routers"]["r3"]["links"]["r2"]["ipv6"].split("/")[0]
308 DEFAULT_ROUTE_NXT_HOP_R3
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local
}
310 logger
.info("Running setup_module() done")
313 def teardown_module():
314 """Teardown the pytest environment"""
316 logger
.info("Running teardown_module to delete topology")
320 # Stop toplogy and Remove tmp files
324 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
326 logger
.info("=" * 40)
328 #####################################################
332 #####################################################
334 def test_verify_bgp_default_originate_in_IBGP_p0(request
):
336 Verify BGP default-originate route with IBGP peer
339 global BGP_CONVERGENCE
342 tc_name
= request
.node
.name
343 write_test_header(tc_name
)
345 # Don't run this test if we have any failure.
346 if tgen
.routers_have_failure():
347 check_router_status(tgen
)
348 reset_config_on_routers(tgen
)
350 if BGP_CONVERGENCE
!= True:
351 pytest
.skip("skipped because of BGP Convergence failure")
353 step("Configure IPv4 and IPv6 , IBGP neighbor between R1 and R2")
354 step("Configure IPv4 and IPv6 Loopback interface on R1, R0 and R2")
355 step("Configure IPv4 and IPv6 EBGP neighbor between R0 and R1")
357 r0_local_as
= topo
["routers"]["r0"]["bgp"]["local_as"]
358 r1_local_as
= topo
["routers"]["r1"]["bgp"]["local_as"]
359 r2_local_as
= topo
["routers"]["r2"]["bgp"]["local_as"]
360 r3_local_as
= topo
["routers"]["r3"]["bgp"]["local_as"]
361 r4_local_as
= topo
["routers"]["r4"]["bgp"]["local_as"]
381 "local_as": r3_local_as
,
386 "local_as": r4_local_as
,
390 result
= modify_as_number(tgen
, topo
, input_dict
)
392 assert result
is True
393 except AssertionError:
394 logger
.info("Expected behaviour: {}".format(result
))
395 logger
.info("BGP config is not created because of invalid ASNs")
397 step("After changing the BGP AS Path Verify the BGP Convergence")
398 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
399 assert BGP_CONVERGENCE
is True, " Complete Convergence is expected after changing the ASN but failed to converge --> :Failed \n Error: {}".format(
403 step("Configure IPv4 and IPv6 static route on R1 next-hop as NULL0")
404 for addr_type
in ADDR_TYPES
:
405 static_routes_input
= {
409 "network": [NETWORK1_1
[addr_type
]],
410 "next_hop": NEXT_HOP_IP
[addr_type
],
415 result
= create_static_routes(tgen
, static_routes_input
)
416 assert result
is True, "Testcase {} : Failed to configure the static routes {} on router R1 \n Error: {}".format(
417 tc_name
,static_routes_input
, result
419 step("verify IPv4 and IPv6 static route are configured and up on R1")
420 for addr_type
in ADDR_TYPES
:
421 static_routes_input
= {
425 "network": [NETWORK1_1
[addr_type
]],
426 "next_hop": NEXT_HOP_IP
[addr_type
],
431 result
= verify_fib_routes(tgen
, addr_type
, "r1", static_routes_input
)
432 assert result
is True, "Testcase {} : Failed \n After configuring the static routes {} , the routes are not found in FIB \n Error: {}".format(
433 tc_name
,static_routes_input
, result
437 "Configure redistribute static and connected on R0 and R1, for IPv4 and IPv6 address family "
439 redistribute_static
= {
446 {"redist_type": "static"},
447 {"redist_type": "connected"},
454 {"redist_type": "static"},
455 {"redist_type": "connected"},
468 {"redist_type": "static"},
469 {"redist_type": "connected"},
476 {"redist_type": "static"},
477 {"redist_type": "connected"},
485 result
= create_router_bgp(tgen
, topo
, redistribute_static
)
486 assert result
is True, "Testcase {} : Failed to configure the redistribute static configuration \n Error: {}".format(tc_name
, result
)
489 "After configuring redistribute command , verify static and connected routes ( loopback connected routes) are advertised on R2"
492 for addr_type
in ADDR_TYPES
:
493 static_routes_input
= {
497 "network": [NETWORK1_1
[addr_type
]],
498 "next_hop": NEXT_HOP_IP
[addr_type
],
501 "network": [R0_NETWORK_LOOPBACK
[addr_type
]],
502 "next_hop": R0_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
505 "network": [R0_NETWORK_CONNECTED
[addr_type
]],
506 "next_hop": R0_NETWORK_CONNECTED_NXTHOP
[addr_type
],
509 "network": [R1_NETWORK_LOOPBACK
[addr_type
]],
510 "next_hop": R1_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
513 "network": [R1_NETWORK_CONNECTED
[addr_type
]],
514 "next_hop": R1_NETWORK_CONNECTED_NXTHOP
[addr_type
],
519 result
= verify_fib_routes(tgen
, addr_type
, "r2", static_routes_input
)
520 assert result
is True, "Testcase {} : After redistributing static routes the routes {} expected in FIB but NOT FOUND ......! \n Error: {}".format(
521 tc_name
, static_routes_input
,result
524 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
525 assert result
is True, "Testcase {} : After redistributing static routes the routes {} expected in RIB but NOT FOUND ......! \n Error: {}".format(
526 tc_name
, static_routes_input
, result
530 "Taking the snapshot of the prefix count before configuring the default originate"
532 snapshot1
= get_prefix_count_route(tgen
, topo
, dut
="r2", peer
="r1")
535 "Configure Default originate on R1 for R1 to R2, for IPv4 and IPv6 BGP address family "
537 local_as
= get_dut_as_number(tgen
, dut
="r1")
538 default_originate_config
= {
541 "local_as": local_as
,
543 "ipv4": {"unicast": {"default_originate": {"r2": {}}}},
544 "ipv6": {"unicast": {"default_originate": {"r2": {}}}},
549 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
550 assert result
is True, "Testcase {} : Failed Configuring default originate configuration. \n Error: {}".format(tc_name
, result
)
553 "After configuring default-originate command , verify default routes are advertised on R2 "
554 " R1 static and loopback routes received on R2 BGP and FIB"
556 for addr_type
in ADDR_TYPES
:
557 static_routes_input
= {
561 "network": [NETWORK1_1
[addr_type
]],
562 "next_hop": NEXT_HOP_IP
[addr_type
],
565 "network": [R1_NETWORK_LOOPBACK
[addr_type
]],
566 "next_hop": R1_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
569 "network": [R1_NETWORK_CONNECTED
[addr_type
]],
570 "next_hop": R1_NETWORK_CONNECTED_NXTHOP
[addr_type
],
576 result
= verify_fib_routes(tgen
, addr_type
, "r2", static_routes_input
)
577 assert result
is True, "Testcase {} : post configuring the BGP Default originate configuration static and connected routes should not be effected but impacted on FIB .......! FAILED \n Error: {}".format(
581 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
582 assert result
is True, "Testcase {} : Failedpost configuring the BGP Default originate configuration static and connected routes should not be effected but impacted on RIB......! FAILED \n Error: {}".format(
586 "Verify default route for IPv4 and IPv6 present with path=igp metric =0 , local-preference= 100 "
588 result
= verify_rib_default_route(
592 routes
=DEFAULT_ROUTES
,
593 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
597 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
599 "Taking the snapshot2 of the prefix count after configuring the default originate"
601 snapshot2
= get_prefix_count_route(tgen
, topo
, dut
="r2", peer
="r1")
603 step("verifying the prefix count incrementing or not ")
604 isIPv4prefix_incremented
= False
605 isIPv6prefix_incremented
= False
606 if snapshot1
["ipv4_count"] < snapshot2
["ipv4_count"]:
607 isIPv4prefix_incremented
= True
608 if snapshot1
["ipv6_count"] < snapshot2
["ipv6_count"]:
609 isIPv6prefix_incremented
= True
612 isIPv4prefix_incremented
is True
613 ), "Testcase {} : Failed Error: IPV4 Prefix is not incremented on receiveing ".format(
618 isIPv6prefix_incremented
is True
619 ), "Testcase {} : Failed Error: IPV6 Prefix is not incremented on receiveing ".format(
622 write_test_footer(tc_name
)
625 def test_verify_bgp_default_originate_in_EBGP_p0(request
):
627 Verify BGP default-originate route with EBGP peer
630 global BGP_CONVERGENCE
633 tc_name
= request
.node
.name
634 write_test_header(tc_name
)
636 # Don't run this test if we have any failure.
637 if tgen
.routers_have_failure():
638 check_router_status(tgen
)
639 reset_config_on_routers(tgen
)
641 if BGP_CONVERGENCE
!= True:
642 pytest
.skip("skipped because of BGP Convergence failure")
644 step("Configure IPv4 and IPv6 , EBGP neighbor between R3 and R2")
645 step("Configure lPv4 and IPv6 Loopback interface on R3, R4 and R2")
646 step("Configure IPv4 and IPv6 IBGP neighbor between R4 and R3")
647 r0_local_as
= topo
["routers"]["r0"]["bgp"]["local_as"]
648 r1_local_as
= topo
["routers"]["r1"]["bgp"]["local_as"]
649 r2_local_as
= topo
["routers"]["r2"]["bgp"]["local_as"]
650 r3_local_as
= topo
["routers"]["r3"]["bgp"]["local_as"]
651 r4_local_as
= topo
["routers"]["r4"]["bgp"]["local_as"]
656 "local_as": r0_local_as
,
661 "local_as": r1_local_as
,
666 "local_as": r2_local_as
,
680 result
= modify_as_number(tgen
, topo
, input_dict
)
682 assert result
is True
683 except AssertionError:
684 logger
.info("Expected behaviour: {}".format(result
))
685 logger
.info("BGP config is not created because of invalid ASNs")
686 step("After changing the BGP AS Path Verify the BGP Convergence")
688 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
689 assert BGP_CONVERGENCE
is True, "Complete convergence is expeceted after changing the ASN os the routes ..! :Failed \n Error: {}".format(
693 step(" Configure IPv4 and IPv6 static route on R3 next-hop on R4 interface")
694 for addr_type
in ADDR_TYPES
:
695 static_routes_input
= {
699 "network": [NETWORK1_1
[addr_type
]],
700 "next_hop": NEXT_HOP_IP
[addr_type
],
705 result
= create_static_routes(tgen
, static_routes_input
)
706 assert result
is True, "Testcase {} : Failed to configure the static routes ....! Failed \n Error: {}".format(
709 step("verify IPv4 and IPv6 static route are configured and up on R1")
710 for addr_type
in ADDR_TYPES
:
711 static_routes_input
= {
715 "network": [NETWORK1_1
[addr_type
]],
716 "next_hop": NEXT_HOP_IP
[addr_type
],
721 result
= verify_fib_routes(tgen
, addr_type
, "r3", static_routes_input
)
722 assert result
is True, "Testcase {} : Route is not found in {} in FIB ......! Failed \n Error: {}".format(
723 tc_name
, static_routes_input
,result
727 "Configure redistribute static and connected on R3 and R4 for IPv4 and IPv6 address family "
729 redistribute_static
= {
736 {"redist_type": "static"},
737 {"redist_type": "connected"},
744 {"redist_type": "static"},
745 {"redist_type": "connected"},
758 {"redist_type": "static"},
759 {"redist_type": "connected"},
766 {"redist_type": "static"},
767 {"redist_type": "connected"},
775 result
= create_router_bgp(tgen
, topo
, redistribute_static
)
776 assert result
is True, "Testcase {} : Failed to configure redistribute configuratin \n Error: {}".format(tc_name
, result
)
779 "After configuring redistribute command , verify static and connected routes ( loopback connected routes) are advertised on R2"
781 for addr_type
in ADDR_TYPES
:
782 static_routes_input
= {
786 "network": [NETWORK1_1
[addr_type
]],
787 "next_hop": NEXT_HOP_IP
[addr_type
],
790 "network": [R3_NETWORK_LOOPBACK
[addr_type
]],
791 "next_hop": R3_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
794 "network": [R3_NETWORK_CONNECTED
[addr_type
]],
795 "next_hop": R3_NETWORK_CONNECTED_NXTHOP
[addr_type
],
798 "network": [R4_NETWORK_LOOPBACK
[addr_type
]],
799 "next_hop": R4_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
802 "network": [R4_NETWORK_CONNECTED
[addr_type
]],
803 "next_hop": R4_NETWORK_CONNECTED_NXTHOP
[addr_type
],
808 result
= verify_fib_routes(tgen
, addr_type
, "r2", static_routes_input
)
809 assert result
is True, "Testcase {} : static & and connected routes are expected but not found in FIB .... ! \n Error: {}".format(
812 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
813 assert result
is True, "Testcase {} : static & and connected routes are expected but not found in RIB .... ! \n Error: {}".format(
816 snapshot1
= get_prefix_count_route(tgen
, topo
, dut
="r2", peer
="r3")
818 "Configure Default originate on R3 for R3 to R2, on IPv4 and IPv6 BGP address family"
820 local_as
= get_dut_as_number(tgen
, dut
="r3")
821 default_originate_config
= {
824 "local_as": local_as
,
826 "ipv4": {"unicast": {"default_originate": {"r2": {}}}},
827 "ipv6": {"unicast": {"default_originate": {"r2": {}}}},
832 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
833 assert result
is True, "Testcase {} : Failed to configure the default originate configuration \n Error: {}".format(tc_name
, result
)
836 "After configuring default-originate command , verify default routes are advertised on R2 on both BGP RIB and FIB"
839 for addr_type
in ADDR_TYPES
:
840 static_routes_input
= {
844 "network": [NETWORK1_1
[addr_type
]],
845 "next_hop": NEXT_HOP_IP
[addr_type
],
848 "network": [DEFAULT_ROUTES
[addr_type
]],
849 "next_hop": DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
855 result
= verify_fib_routes(tgen
, addr_type
, "r2", static_routes_input
)
856 assert result
is True, "Testcase {} : static route from R1 {} and default route from R3 is expected in R2 FIB .....! NOT FOUND \n Error: {}".format(
857 tc_name
, NETWORK1_1
,result
860 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
861 assert result
is True, "Testcase {} : static route from R1 {} and default route from R3 is expected in R2 RIB .....! NOT FOUND \n Error: {}".format(
862 tc_name
,NETWORK1_1
, result
866 "Verify default route for IPv4 and IPv6 present with path = ebgp as path, metric =0 "
868 # local preference will bgp not applicable for eBGP
869 result
= verify_rib_default_route(
873 routes
=DEFAULT_ROUTES
,
874 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
876 expected_aspath
="4000",
878 assert result
is True, "Testcase {} : Default route from R3 is expected with attributes in R2 RIB .....! NOT FOUND Error: {}".format(tc_name
, result
)
881 "Taking the snapshot2 of the prefix count after configuring the default originate"
883 snapshot2
= get_prefix_count_route(tgen
, topo
, dut
="r2", peer
="r3")
885 "Verify out-prefix count is incremented default route on IPv4 and IPv6 neighbor"
887 isIPv4prefix_incremented
= False
888 isIPv6prefix_incremented
= False
889 if snapshot1
["ipv4_count"] < snapshot2
["ipv4_count"]:
890 isIPv4prefix_incremented
= True
891 if snapshot1
["ipv6_count"] < snapshot2
["ipv6_count"]:
892 isIPv6prefix_incremented
= True
895 isIPv4prefix_incremented
is True
896 ), "Testcase {} : Failed Error: IPV4 Prefix is not incremented on receiveing ".format(
901 isIPv6prefix_incremented
is True
902 ), "Testcase {} : Failed Error: IPV6 Prefix is not incremented on receiveing ".format(
905 write_test_footer(tc_name
)
908 def test_verify_bgp_default_originate_in_IBGP_with_route_map_p0(request
):
910 test_verify_bgp_default_originate_in_IBGP_with_route_map_p0
913 global BGP_CONVERGENCE
916 tc_name
= request
.node
.name
917 write_test_header(tc_name
)
919 # Don't run this test if we have any failure.
920 if tgen
.routers_have_failure():
921 check_router_status(tgen
)
922 reset_config_on_routers(tgen
)
924 if BGP_CONVERGENCE
!= True:
925 pytest
.skip("skipped because of BGP Convergence failure")
927 step("Configure IPv4 and IPv6 , IBGP neighbor between R1 and R2")
928 step("Configure IPv4 and IPv6 , EBGP neighbor between R1 and R0")
929 r0_local_as
= topo
["routers"]["r0"]["bgp"]["local_as"]
930 r1_local_as
= topo
["routers"]["r1"]["bgp"]["local_as"]
931 r2_local_as
= topo
["routers"]["r2"]["bgp"]["local_as"]
932 r3_local_as
= topo
["routers"]["r3"]["bgp"]["local_as"]
933 r4_local_as
= topo
["routers"]["r4"]["bgp"]["local_as"]
938 "local_as": r0_local_as
,
953 "local_as": r3_local_as
,
958 "local_as": r4_local_as
,
962 result
= modify_as_number(tgen
, topo
, input_dict
)
964 assert result
is True
965 except AssertionError:
966 logger
.info("Expected behaviour: {}".format(result
))
967 logger
.info("BGP config is not created because of invalid ASNs")
969 step("After changing the BGP AS Path Verify the BGP Convergence")
970 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
971 assert BGP_CONVERGENCE
is True, "Complete convergence is expected after changing ASN ....! ERROR :Failed \n Error: {}".format(
975 step("Configure 2 IPv4 and 2 IPv6 Static route on R0 with next-hop as Null0")
976 for addr_type
in ADDR_TYPES
:
977 static_routes_input
= {
981 "network": [NETWORK1_1
[addr_type
]],
982 "next_hop": NEXT_HOP_IP
[addr_type
],
985 "network": [NETWORK2_1
[addr_type
]],
986 "next_hop": NEXT_HOP_IP
[addr_type
],
991 result
= create_static_routes(tgen
, static_routes_input
)
992 assert result
is True, "Testcase {} : Static Configuration is Failed \n Error: {}".format(
996 step("verify IPv4 and IPv6 static route are configured and up on R0")
997 for addr_type
in ADDR_TYPES
:
998 static_routes_input
= {
1002 "network": [NETWORK1_1
[addr_type
]],
1003 "next_hop": NEXT_HOP_IP
[addr_type
],
1006 "network": [NETWORK2_1
[addr_type
]],
1007 "next_hop": NEXT_HOP_IP
[addr_type
],
1012 result
= verify_fib_routes(tgen
, addr_type
, "r0", static_routes_input
)
1013 assert result
is True, "Testcase {} : routes {} unable is not found in R0 FIB \n Error: {}".format(
1014 tc_name
, static_routes_input
,result
1018 "Configure redistribute static on IPv4 and IPv6 address family on R0 for R0 to R1 neighbor "
1020 redistribute_static
= {
1024 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1025 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1030 result
= create_router_bgp(tgen
, topo
, redistribute_static
)
1031 assert result
is True, "Testcase {} : Failed to configure redistribute static configuration....! \n Error: {}".format(tc_name
, result
)
1033 step("verify IPv4 and IPv6 static route are configured and up on R1")
1034 for addr_type
in ADDR_TYPES
:
1035 static_routes_input
= {
1039 "network": [NETWORK1_1
[addr_type
]],
1040 "next_hop": NEXT_HOP_IP
[addr_type
],
1043 "network": [NETWORK2_1
[addr_type
]],
1044 "next_hop": NEXT_HOP_IP
[addr_type
],
1049 result
= verify_fib_routes(tgen
, addr_type
, "r1", static_routes_input
)
1050 assert result
is True, "Testcase {} : Failed... Routes {} expected in r0 FIB after configuring the redistribute config \n Error: {}".format(
1051 tc_name
,static_routes_input
, result
1054 result
= verify_bgp_rib(tgen
, addr_type
, "r1", static_routes_input
)
1055 assert result
is True, "Testcase {} : Failed... Routes {} expected in r0 RIB after configuring the redistribute config \n Error: {}".format(
1056 tc_name
, static_routes_input
,result
1060 "Configure IPv4 prefix-list Pv4 and and IPv6 prefix-list Pv6 on R1 to match BGP route Sv41, Sv42, IPv6 route Sv61 Sv62 permit "
1069 "network": NETWORK1_1
["ipv4"],
1074 "network": NETWORK2_1
["ipv4"],
1083 "network": NETWORK1_1
["ipv6"],
1088 "network": NETWORK2_1
["ipv6"],
1096 result
= create_prefix_lists(tgen
, input_dict_3
)
1097 assert result
is True, "Testcase {} : Failed to configure the prefix list \n Error: {}".format(tc_name
, result
)
1100 "Configure IPV4 and IPv6 route-map (RMv4 and RMv6 ) matching prefix-list (Pv4 and Pv6) respectively on R1"
1109 "match": {"ipv4": {"prefix_lists": "Pv4"}},
1116 "match": {"ipv6": {"prefix_lists": "Pv6"}},
1122 result
= create_route_maps(tgen
, input_dict_3
)
1123 assert result
is True, "Testcase {} : Failed to configure the route map \n Error: {}".format(tc_name
, result
)
1126 "Configure default-originate with route-map (RMv4 and RMv6) on R1, on BGP IPv4 and IPv6 address family "
1128 local_as
= get_dut_as_number(tgen
, dut
="r1")
1129 default_originate_config
= {
1132 "local_as": local_as
,
1135 "unicast": {"default_originate": {"r2": {"route_map": "RMv4"}}}
1138 "unicast": {"default_originate": {"r2": {"route_map": "RMv6"}}}
1144 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
1145 assert result
is True, "Testcase {} : Failed to configure the default originate \n Error: {}".format(tc_name
, result
)
1147 step("Verify the default route is received in BGP RIB and FIB")
1149 "After configuring default-originate command , verify default routes are advertised on R2 "
1151 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1152 for addr_type
in ADDR_TYPES
:
1153 static_routes_input
= {
1157 "network": [DEFAULT_ROUTES
[addr_type
]],
1158 "next_hop": DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1163 result
= verify_fib_routes(
1167 static_routes_input
,
1168 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1170 assert result
is True, "Testcase {} : Failed...! Expected default route from R1 not found in FIB \n Error: {}".format(
1174 result
= verify_bgp_rib(
1178 static_routes_input
,
1179 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1181 assert result
is True, "Testcase {} : Failed...! Expected default route from R1 not found in RIB \n Error: {}".format(
1184 step("Remove route-map RMv4 and RMv6 from default-originate command in R1")
1185 NOTE
= """ Configuring the default-originate should remove the previously applied default originate with condtional route-map"""
1186 local_as
= get_dut_as_number(tgen
, dut
="r1")
1187 default_originate_config
= {
1190 "local_as": local_as
,
1192 "ipv4": {"unicast": {"default_originate": {"r2": {}}}},
1193 "ipv6": {"unicast": {"default_originate": {"r2": {}}}},
1198 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
1199 assert result
is True, "Testcase {} : Failed to remove the default originate conditional route-map \n Error: {}".format(tc_name
, result
)
1202 "Verify BGP RIB and FIB After removing route-map , default route still present on R2"
1204 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1205 for addr_type
in ADDR_TYPES
:
1206 static_routes_input
= {
1210 "network": [DEFAULT_ROUTES
[addr_type
]],
1211 "next_hop": DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1217 result
= verify_fib_routes(
1221 static_routes_input
,
1222 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1224 assert result
is True, "Testcase {} : Failed Default route from R1 is not found in FIB \n Error: {}".format(
1228 result
= verify_bgp_rib(
1232 static_routes_input
,
1233 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1235 assert result
is True, "Testcase {} : Failed Default route from R1 is not found in RIB \n Error: {}".format(
1239 step("Configure default-originate with route-map (RMv4 and RMv6) on R1 ")
1240 local_as
= get_dut_as_number(tgen
, dut
="r1")
1241 default_originate_config
= {
1244 "local_as": local_as
,
1248 "default_originate": {
1250 "route_map": "RMv4",
1257 "default_originate": {
1259 "route_map": "RMv6",
1268 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
1269 assert result
is True, "Testcase {} : Failed to configure the Default originate route-map \n Error: {}".format(tc_name
, result
)
1272 "After configuring default-originate command , verify default routes are advertised on R2 "
1274 for addr_type
in ADDR_TYPES
:
1275 static_routes_input
= {
1279 "network": [DEFAULT_ROUTES
[addr_type
]],
1280 "next_hop": DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1286 result
= verify_fib_routes(
1290 static_routes_input
,
1291 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1293 assert result
is True, "Testcase {} : Failed Default Route from R1 is not found in FIB \n Error: {}".format(
1297 result
= verify_bgp_rib(
1301 static_routes_input
,
1302 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1304 assert result
is True, "Testcase {} : Failed Default Route from R1 is not found in RIB \n Error: {}".format(
1308 step("Delete prefix list using no prefix-list")
1316 "network": NETWORK1_1
["ipv4"],
1322 "network": NETWORK2_1
["ipv4"],
1332 "network": NETWORK1_1
["ipv6"],
1338 "network": NETWORK2_1
["ipv6"],
1347 result
= create_prefix_lists(tgen
, input_dict_3
)
1348 assert result
is True, "Testcase {} : Failed to delete the prefix list Error: {}".format(tc_name
, result
)
1351 "Verify BGP RIB and FIB After deleting prefix-list , verify IPv4 and IPv6 default route got removed from DUT "
1353 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1354 for addr_type
in ADDR_TYPES
:
1355 static_routes_input
= {
1359 "network": [DEFAULT_ROUTES
[addr_type
]],
1360 "next_hop": DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1365 result
= verify_fib_routes(
1369 static_routes_input
,
1370 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1375 ), "Testcase {} : Failed\n After deleteing prefix default route is not expected in FIB \n Error: {}".format(
1379 result
= verify_bgp_rib(
1383 static_routes_input
,
1384 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1389 ), "Testcase {} : Failed \n After deleteing prefix default route is not expected in RIB \n Error: {}".format(
1393 step("Configure prefix-list and delete route-map using no route-map")
1401 "network": NETWORK1_1
["ipv4"],
1406 "network": NETWORK2_1
["ipv4"],
1415 "network": NETWORK1_1
["ipv6"],
1420 "network": NETWORK2_1
["ipv6"],
1428 result
= create_prefix_lists(tgen
, input_dict_3
)
1429 assert result
is True, "Testcase {} : Failed to configure the prefix lists Error: {}".format(tc_name
, result
)
1432 "After configuring the Prefixlist cross checking the BGP Default route is configured again , before deleting the route map"
1435 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1436 for addr_type
in ADDR_TYPES
:
1437 static_routes_input
= {
1441 "network": [DEFAULT_ROUTES
[addr_type
]],
1442 "next_hop": DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1447 result
= verify_fib_routes(
1451 static_routes_input
,
1452 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1455 assert result
is True, "Testcase {} : Failed Default route from R1 is expected in FIB but not found \n Error: {}".format(
1459 result
= verify_bgp_rib(
1463 static_routes_input
,
1464 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1467 assert result
is True, "Testcase {} : Failed Default route from R1 is expected in RIB but not found \n Error: {}".format(
1471 step("Deleting the routemap")
1472 input_dict
= {"r1": {"route_maps": ["RMv4", "RMv6"]}}
1473 result
= delete_route_maps(tgen
, input_dict
)
1474 assert result
is True, "Testcase {} : Failed to delete the Route-map \n Error: {}".format(tc_name
, result
)
1477 "Verify BGP RIB and FIB ,After deleting route-map , verify IPv4 and IPv6 default route got removed from DUT"
1479 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1480 for addr_type
in ADDR_TYPES
:
1481 static_routes_input
= {
1485 "network": [DEFAULT_ROUTES
[addr_type
]],
1486 "next_hop": DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1492 result
= verify_fib_routes(
1496 static_routes_input
,
1497 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1502 ), "Testcase {} : Failed \n After deleteing route-map default route is not expected in FIB \nError: {}".format(
1506 result
= verify_bgp_rib(
1510 static_routes_input
,
1511 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1516 ), "Testcase {} : Failed \n After deleteing route-map default route is not expected in RIB \n Error: {}".format(
1520 write_test_footer(tc_name
)
1523 def test_verify_bgp_default_originate_in_EBGP_with_route_map_p0(request
):
1525 test_verify_bgp_default_originate_in_EBGP_with_route_map_p0
1527 tgen
= get_topogen()
1528 global BGP_CONVERGENCE
1531 tc_name
= request
.node
.name
1532 write_test_header(tc_name
)
1533 tgen
= get_topogen()
1534 # Don't run this test if we have any failure.
1535 if tgen
.routers_have_failure():
1536 check_router_status(tgen
)
1537 reset_config_on_routers(tgen
)
1539 if BGP_CONVERGENCE
!= True:
1540 pytest
.skip("skipped because of BGP Convergence failure")
1542 step("Configure IPv4 and IPv6 , EBGP neighbor between R3 and R2")
1543 step("Configure IPv4 and IPv6 IBGP neighbor between R3 and R4")
1544 r0_local_as
= topo
["routers"]["r0"]["bgp"]["local_as"]
1545 r1_local_as
= topo
["routers"]["r1"]["bgp"]["local_as"]
1546 r2_local_as
= topo
["routers"]["r2"]["bgp"]["local_as"]
1547 r3_local_as
= topo
["routers"]["r3"]["bgp"]["local_as"]
1548 r4_local_as
= topo
["routers"]["r4"]["bgp"]["local_as"]
1553 "local_as": r0_local_as
,
1558 "local_as": r1_local_as
,
1563 "local_as": r2_local_as
,
1577 result
= modify_as_number(tgen
, topo
, input_dict
)
1579 assert result
is True
1580 except AssertionError:
1581 logger
.info("Expected behaviour: {}".format(result
))
1582 logger
.info("BGP config is not created because of invalid ASNs")
1583 step("After changing the BGP AS Path Verify the BGP Convergence")
1584 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
1585 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
1590 "Configure 2 IPv4 and 2 IPv6, Static route on R4 with next-hop as Null0 IPv4 route Sv41, Sv42, IPv6 route Sv61 Sv62"
1592 for addr_type
in ADDR_TYPES
:
1593 static_routes_input
= {
1597 "network": [NETWORK1_1
[addr_type
]],
1598 "next_hop": NEXT_HOP_IP
[addr_type
],
1601 "network": [NETWORK2_1
[addr_type
]],
1602 "next_hop": NEXT_HOP_IP
[addr_type
],
1607 result
= create_static_routes(tgen
, static_routes_input
)
1608 assert result
is True, "Testcase {} : Failed to configure the static routes \n Error: {}".format(
1611 step("verify IPv4 and IPv6 static route are configured and up on R4")
1612 for addr_type
in ADDR_TYPES
:
1613 static_routes_input
= {
1617 "network": [NETWORK1_1
[addr_type
]],
1618 "next_hop": NEXT_HOP_IP
[addr_type
],
1621 "network": [NETWORK2_1
[addr_type
]],
1622 "next_hop": NEXT_HOP_IP
[addr_type
],
1627 result
= verify_fib_routes(tgen
, addr_type
, "r4", static_routes_input
)
1628 assert result
is True, "Testcase {} : Failed Static route {} is not found in R4 FIB \n Error: {}".format(
1629 tc_name
, static_routes_input
,result
1633 "Configure redistribute static on IPv4 and IPv6 address family on R4 for R4 to R3 neighbo"
1635 redistribute_static
= {
1639 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1640 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1645 result
= create_router_bgp(tgen
, topo
, redistribute_static
)
1646 assert result
is True, "Testcase {} : Failed to configure the redistribute static \n Error: {}".format(tc_name
, result
)
1648 step("verify IPv4 and IPv6 static route are configured and up on R3")
1649 for addr_type
in ADDR_TYPES
:
1650 static_routes_input
= {
1654 "network": [NETWORK1_1
[addr_type
]],
1655 "next_hop": NEXT_HOP_IP
[addr_type
],
1658 "network": [NETWORK2_1
[addr_type
]],
1659 "next_hop": NEXT_HOP_IP
[addr_type
],
1664 result
= verify_fib_routes(tgen
, addr_type
, "r3", static_routes_input
)
1665 assert result
is True, "Testcase {} : Failed static routes from R1 and R3 is not found in FIB \n Error: {}".format(
1668 result
= verify_bgp_rib(tgen
, addr_type
, "r3", static_routes_input
)
1669 assert result
is True, "Testcase {} : Failed static routes from R1 and R3 is not found in RIB \n Error: {}".format(
1674 "Configure IPv4 prefix-list Pv4 and and IPv6 prefix-list Pv6 on R3 so new route which is not present on R3"
1683 "network": NETWORK3_1
["ipv4"],
1692 "network": NETWORK3_1
["ipv6"],
1700 result
= create_prefix_lists(tgen
, input_dict_3
)
1701 assert result
is True, "Testcase {} : Failed to configure the prefix lists \n Error: {}".format(tc_name
, result
)
1703 step("verify IPv4 and IPv6 Prefix list got configured on R3")
1704 input_dict
= {"r3": {"prefix_lists": ["Pv4", "Pv6"]}}
1705 result
= verify_prefix_lists(tgen
, input_dict
)
1706 assert result
is True, "Testcase {} : Failed ..! configured prefix lists {} are not found \n Error: {}".format(tc_name
,input_dict
, result
)
1709 "Configure IPv4 and IPv6 route-map ( RMv4 and RMv6 ) matching prefix-list (Pv4 and Pv6 ) respectively on R3"
1718 "match": {"ipv4": {"prefix_lists": "Pv4"}},
1725 "match": {"ipv6": {"prefix_lists": "Pv6"}},
1731 result
= create_route_maps(tgen
, input_dict_3
)
1732 assert result
is True, "Testcase {} : Failed to configure the route-map \n Error: {}".format(tc_name
, result
)
1734 "Taking the snapshot of the prefix count before configuring the default originate"
1736 snapshot1
= get_prefix_count_route(tgen
, topo
, dut
="r2", peer
="r3")
1738 "Configure default-originate with IPv4 and IPv6 route-map (RMv4 and RMv6) on R3"
1740 local_as
= get_dut_as_number(tgen
, dut
="r3")
1741 default_originate_config
= {
1744 "local_as": local_as
,
1747 "unicast": {"default_originate": {"r2": {"route_map": "RMv4"}}}
1750 "unicast": {"default_originate": {"r2": {"route_map": "RMv6"}}}
1756 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
1757 assert result
is True, "Testcase {} : Failed to configure default-originate \n Error: {}".format(tc_name
, result
)
1759 step("Verify the default route is NOT received in BGP RIB and FIB on R2 ")
1761 "After configuring default-originate command , verify default routes are not Received on R2 "
1763 for addr_type
in ADDR_TYPES
:
1764 static_routes_input
= {
1768 "network": [DEFAULT_ROUTES
[addr_type
]],
1769 "next_hop": DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
1775 result
= verify_fib_routes(
1779 static_routes_input
,
1780 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
1785 ), "Testcase {} : Failed \n Default route is not expected due to deny in prefix list \nError: {}".format(
1789 result
= verify_bgp_rib(
1793 static_routes_input
,
1794 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
1799 ), "Testcase {} : Failed \nDefault route is not expected due to deny in prefix list\n Error: {}".format(
1803 step("Add route Sv41, Sv42, IPv6 route Sv61 Sv62 on prefix list Pv4 and Pv6")
1811 "network": NETWORK1_1
["ipv4"],
1816 "network": NETWORK2_1
["ipv4"],
1825 "network": NETWORK1_1
["ipv6"],
1830 "network": NETWORK2_1
["ipv6"],
1838 result
= create_prefix_lists(tgen
, input_dict_3
)
1839 assert result
is True, "Testcase {} : Failed to configure the prefix lists Error: {}".format(tc_name
, result
)
1841 step("Verify BGP default route for IPv4 and IPv6 is received on R2")
1843 for addr_type
in ADDR_TYPES
:
1844 static_routes_input
= {
1848 "network": [DEFAULT_ROUTES
[addr_type
]],
1849 "next_hop": DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
1855 result
= verify_fib_routes(
1859 static_routes_input
,
1860 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
1862 assert result
is True, "Testcase {} : Failed Default routes are expected in R2 FIB from R3 but not found ....! \n Error: {}".format(
1866 result
= verify_bgp_rib(
1870 static_routes_input
,
1871 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
1873 assert result
is True, "Testcase {} : Failed Default routes are expected in R2 RIB from R3 but not found ....! \n Error: {}".format(
1877 step("Remove route Sv41, Sv42, IPv6 route Sv61 Sv62 on prefix list Pv4 and Pv6")
1885 "network": NETWORK1_1
["ipv4"],
1891 "network": NETWORK2_1
["ipv4"],
1901 "network": NETWORK1_1
["ipv6"],
1907 "network": NETWORK2_1
["ipv6"],
1916 result
= create_prefix_lists(tgen
, input_dict_3
)
1917 assert result
is True, "Testcase {} : Failed to remove prefix-lists from R3 Error: {}".format(tc_name
, result
)
1920 "After Removing route BGP default route for IPv4 and IPv6 is NOT received on R2"
1922 for addr_type
in ADDR_TYPES
:
1923 static_routes_input
= {
1927 "network": [DEFAULT_ROUTES
[addr_type
]],
1928 "next_hop": DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
1934 result
= verify_fib_routes(
1938 static_routes_input
,
1939 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
1944 ), "Testcase {} : Failed \n After Removing route in prefix list the default route is not expected in FIB \n Error: {}".format(
1948 result
= verify_bgp_rib(
1952 static_routes_input
,
1953 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
1958 ), "Testcase {} : Failed \n After Removing route in prefix list the default route is not expected in RIB\n Error: {}".format(
1962 step(" Add route Sv41, Sv42, IPv6 route Sv61 Sv62 on prefix list Pv4 and Pv6")
1970 "network": NETWORK1_1
["ipv4"],
1975 "network": NETWORK2_1
["ipv4"],
1984 "network": NETWORK1_1
["ipv6"],
1989 "network": NETWORK2_1
["ipv6"],
1997 result
= create_prefix_lists(tgen
, input_dict_3
)
1998 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
2000 step("Verify BGP default route for IPv4 and IPv6 is received on R2")
2002 for addr_type
in ADDR_TYPES
:
2003 static_routes_input
= {
2007 "network": [DEFAULT_ROUTES
[addr_type
]],
2008 "next_hop": DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2014 result
= verify_fib_routes(
2018 static_routes_input
,
2019 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2021 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2025 result
= verify_bgp_rib(
2029 static_routes_input
,
2030 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2032 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2036 step("Change IPv4 and IPv6 prefix-list permit and deny ")
2042 {"seqid": "1", "network": NETWORK1_1
["ipv4"], "action": "deny"},
2043 {"seqid": "2", "network": NETWORK2_1
["ipv4"], "action": "deny"},
2048 {"seqid": "1", "network": NETWORK1_1
["ipv6"], "action": "deny"},
2049 {"seqid": "2", "network": NETWORK2_1
["ipv6"], "action": "deny"},
2055 result
= create_prefix_lists(tgen
, input_dict_3
)
2056 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
2058 step("Verify BGP default route for IPv4 and IPv6 is not received on R2")
2060 for addr_type
in ADDR_TYPES
:
2061 static_routes_input
= {
2065 "network": [DEFAULT_ROUTES
[addr_type
]],
2066 "next_hop": DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2072 result
= verify_fib_routes(
2076 static_routes_input
,
2077 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2082 ), "Testcase {} : Failed \n after denying the prefix list default route is not expected in FIB \n Error: {}".format(
2086 result
= verify_bgp_rib(
2090 static_routes_input
,
2091 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2096 ), "Testcase {} : Failed \n after denying the prefix list default route is not expected in RIB \n Error: {}".format(
2100 step("Change IPv4 and IPv6 prefix-list deny to permit ")
2108 "network": NETWORK1_1
["ipv4"],
2113 "network": NETWORK2_1
["ipv4"],
2122 "network": NETWORK1_1
["ipv6"],
2127 "network": NETWORK2_1
["ipv6"],
2135 result
= create_prefix_lists(tgen
, input_dict_3
)
2136 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
2138 step("Verify BGP default route for IPv4 and IPv6 is received on R2")
2139 for addr_type
in ADDR_TYPES
:
2140 static_routes_input
= {
2144 "network": [DEFAULT_ROUTES
[addr_type
]],
2145 "next_hop": DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2151 result
= verify_fib_routes(
2155 static_routes_input
,
2156 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2158 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2162 result
= verify_bgp_rib(
2166 static_routes_input
,
2167 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2169 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2174 "Taking the snapshot2 of the prefix count after configuring the default originate"
2176 snapshot2
= get_prefix_count_route(tgen
, topo
, dut
="r2", peer
="r3")
2178 step("verifying the prefix count incrementing or not ")
2179 isIPv4prefix_incremented
= False
2180 isIPv6prefix_incremented
= False
2181 if snapshot1
["ipv4_count"] < snapshot2
["ipv4_count"]:
2182 isIPv4prefix_incremented
= True
2183 if snapshot1
["ipv6_count"] < snapshot2
["ipv6_count"]:
2184 isIPv6prefix_incremented
= True
2187 isIPv4prefix_incremented
is True
2188 ), "Testcase {} : Failed Error: IPV4 Prefix is not incremented on receiveing ".format(
2193 isIPv6prefix_incremented
is True
2194 ), "Testcase {} : Failed Error: IPV6 Prefix is not incremented on receiveing ".format(
2199 "Configure another IPv4 and IPv6 route-map and match same prefix-list (Sv41, Sv42, IPv6 route Sv61 Sv62) with deny statement "
2208 "match": {"ipv4": {"prefix_lists": "Pv4"}},
2215 "match": {"ipv6": {"prefix_lists": "Pv6"}},
2221 result
= create_route_maps(tgen
, input_dict_3
)
2222 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2224 step("Attach route-map on IPv4 and IP6 BGP neighbor on fly")
2225 local_as
= get_dut_as_number(tgen
, dut
="r3")
2226 default_originate_config
= {
2229 "local_as": local_as
,
2232 "unicast": {"default_originate": {"r2": {"route_map": "RMv41"}}}
2235 "unicast": {"default_originate": {"r2": {"route_map": "RMv61"}}}
2241 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
2242 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2245 "After attaching route-map verify IPv4 and IPv6 default route is withdrawn from the R2"
2247 for addr_type
in ADDR_TYPES
:
2248 static_routes_input
= {
2252 "network": [DEFAULT_ROUTES
[addr_type
]],
2253 "next_hop": DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2259 result
= verify_fib_routes(
2263 static_routes_input
,
2264 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2267 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
2271 result
= verify_bgp_rib(
2275 static_routes_input
,
2276 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2279 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
2283 step("Change the recently added Routemap from deny to permit")
2291 "match": {"ipv4": {"prefix_lists": "Pv4"}},
2298 "match": {"ipv6": {"prefix_lists": "Pv6"}},
2304 result
= create_route_maps(tgen
, input_dict_3
)
2305 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2307 step("Verify IPv4 and IPv6 default route is advertised from the R2")
2308 for addr_type
in ADDR_TYPES
:
2309 static_routes_input
= {
2313 "network": [DEFAULT_ROUTES
[addr_type
]],
2314 "next_hop": DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2320 result
= verify_fib_routes(
2324 static_routes_input
,
2325 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2327 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2331 result
= verify_bgp_rib(
2335 static_routes_input
,
2336 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2338 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2343 "Delete default-originate route-map command while configuring ( neighbor x.x.x default-originate) for IPv4 and IPv6 BGP neighbor "
2345 """ Configuring the Default originate on neighbor must remove the previously assigned deault-originate with routemap config """
2346 local_as
= get_dut_as_number(tgen
, dut
="r3")
2347 default_originate_config
= {
2350 "local_as": local_as
,
2352 "ipv4": {"unicast": {"default_originate": {"r2": {}}}},
2353 "ipv6": {"unicast": {"default_originate": {"r2": {}}}},
2358 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
2359 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2362 "Verify in running config from BGP that default-originate with route-map command is removed and default-originate command is still present and default route for IPv4 and IPv6 present in RIB and FIB"
2364 for addr_type
in ADDR_TYPES
:
2365 static_routes_input
= {
2369 "network": [DEFAULT_ROUTES
[addr_type
]],
2370 "next_hop": DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2376 result
= verify_fib_routes(
2380 static_routes_input
,
2381 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2383 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2387 result
= verify_bgp_rib(
2391 static_routes_input
,
2392 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2394 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2399 "Configure default-originate with conditional route-map command on IPv4 and IPv6 address family "
2401 local_as
= get_dut_as_number(tgen
, dut
="r3")
2402 default_originate_config
= {
2405 "local_as": local_as
,
2408 "unicast": {"default_originate": {"r2": {"route_map": "RMv41"}}}
2411 "unicast": {"default_originate": {"r2": {"route_map": "RMv61"}}}
2417 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
2418 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2421 "Verify in running config from BGP that default-originate with route-map command is present and default route for IPv4 and IPv6 present"
2423 for addr_type
in ADDR_TYPES
:
2424 static_routes_input
= {
2428 "network": [DEFAULT_ROUTES
[addr_type
]],
2429 "next_hop": DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2435 result
= verify_fib_routes(
2439 static_routes_input
,
2440 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2442 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2446 result
= verify_bgp_rib(
2450 static_routes_input
,
2451 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2453 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2458 "Delete default originate with 'no bgp default-originate' from IPV4 and IPV6 address family "
2460 local_as
= get_dut_as_number(tgen
, dut
="r3")
2461 default_originate_config
= {
2464 "local_as": local_as
,
2467 "unicast": {"default_originate": {"r2": {"delete": True}}}
2470 "unicast": {"default_originate": {"r2": {"delete": True}}}
2476 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
2477 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2480 " Verify in running config from BGP that default-originate complete CLI is removed for IPV4 and IPV6 address family and default originate routes got deleted"
2482 for addr_type
in ADDR_TYPES
:
2483 static_routes_input
= {
2487 "network": [DEFAULT_ROUTES
[addr_type
]],
2488 "next_hop": DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2494 result
= verify_fib_routes(
2498 static_routes_input
,
2499 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2504 ), "Testcase {} : Failed \n Default Route is not expected in FIB \nError: {}".format(
2508 result
= verify_bgp_rib(
2512 static_routes_input
,
2513 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2518 ), "Testcase {} : Failed \n Default Route is not expected in RIB\nError: {}".format(
2522 write_test_footer(tc_name
)
2525 if __name__
== "__main__":
2526 args
= ["-s"] + sys
.argv
[1:]
2527 sys
.exit(pytest
.main(args
))