3 # Copyright (c) 2022 by VMware, Inc. ("VMware")
4 # Used Copyright (c) 2018 by Network Device Education Foundation, Inc. ("NetDEF")
7 # Permission to use, copy, modify, and/or distribute this software
8 # for any purpose with or without fee is hereby granted, provided
9 # that the above copyright notice and this permission notice appear
11 # Shreenidhi A R <rshreenidhi@vmware.com>
12 # THE SOFTWARE IS PROVIDED "AS IS" AND VMWARE DISCLAIMS ALL WARRANTIES
13 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL VMWARE BE LIABLE FOR
15 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
16 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
17 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
18 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22 Following tests are covered.
23 1. Verify BGP default-originate route with IBGP peer
24 2. Verify BGP default-originate route with EBGP peer
25 3. Verify BGP default route when default-originate configured with route-map over IBGP peer
26 4. Verify BGP default route when default-originate configured with route-map over EBGP peer"
33 from time
import sleep
34 from copy
import deepcopy
35 from lib
.topolog
import logger
37 # pylint: disable=C0413
38 # Import topogen and topotest helpers
39 from lib
.topogen
import Topogen
, get_topogen
40 from lib
.topojson
import build_config_from_json
41 from lib
.topolog
import logger
44 verify_bgp_convergence
,
45 verify_graceful_restart
,
53 get_prefix_count_route
,
55 verify_rib_default_route
,
56 verify_fib_default_route
,
57 verify_bgp_advertised_routes_from_neighbor
,
58 verify_bgp_received_routes_from_neighbor
,
60 from lib
.common_config
import (
66 shutdown_bringup_interface
,
68 required_linux_kernel_version
,
73 get_frr_ipv6_linklocal
,
78 reset_config_on_routers
,
85 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.staticd
]
87 # Save the Current Working Directory to find configuration files.
88 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
89 sys
.path
.append(os
.path
.join(CWD
, "../"))
90 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
92 # Required to instantiate the topology builder class.
94 # pylint: disable=C0413
95 # Import topogen and topotest helpers
102 NETWORK1_1
= {"ipv4": "1.1.1.1/32", "ipv6": "1::1/128"}
103 NETWORK1_2
= {"ipv4": "1.1.1.2/32", "ipv6": "1::2/128"}
104 NETWORK2_1
= {"ipv4": "2.1.1.1/32", "ipv6": "2::1/128"}
105 NETWORK2_2
= {"ipv4": "2.1.1.2/32", "ipv6": "2::2/128"}
106 NETWORK3_1
= {"ipv4": "3.1.1.1/32", "ipv6": "3::1/128"}
107 NETWORK3_2
= {"ipv4": "3.1.1.2/32", "ipv6": "3::2/128"}
108 NETWORK4_1
= {"ipv4": "4.1.1.1/32", "ipv6": "4::1/128"}
109 NETWORK4_2
= {"ipv4": "4.1.1.2/32", "ipv6": "4::2/128"}
110 NETWORK5_1
= {"ipv4": "5.1.1.1/32", "ipv6": "5::1/128"}
111 NETWORK5_2
= {"ipv4": "5.1.1.2/32", "ipv6": "5::2/128"}
112 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
113 NEXT_HOP_IP
= {"ipv4": "Null0", "ipv6": "Null0"}
118 IPV4_RM1
= "RMVIPV41"
119 IPV6_RM1
= "RMVIPV61"
121 IPV4_RM2
= "RMVIPV42"
122 IPV6_RM2
= "RMVIPV62"
131 r1_ipv4_loopback
= "1.0.1.0/24"
132 r2_ipv4_loopback
= "1.0.2.0/24"
133 r3_ipv4_loopback
= "1.0.3.0/24"
134 r4_ipv4_loopback
= "1.0.4.0/24"
135 r1_ipv6_loopback
= "2001:db8:f::1:0/120"
136 r2_ipv6_loopback
= "2001:db8:f::2:0/120"
137 r3_ipv6_loopback
= "2001:db8:f::3:0/120"
138 r4_ipv6_loopback
= "2001:db8:f::4:0/120"
140 r0_connected_address_ipv4
= "192.168.0.0/24"
141 r0_connected_address_ipv6
= "fd00::/64"
142 r1_connected_address_ipv4
= "192.168.1.0/24"
143 r1_connected_address_ipv6
= "fd00:0:0:1::/64"
144 r3_connected_address_ipv4
= "192.168.2.0/24"
145 r3_connected_address_ipv6
= "fd00:0:0:2::/64"
146 r4_connected_address_ipv4
= "192.168.3.0/24"
147 r4_connected_address_ipv6
= "fd00:0:0:3::/64"
150 def setup_module(mod
):
152 Sets up the pytest environment
157 # Required linux kernel version for this suite to run.
158 result
= required_linux_kernel_version("4.15")
159 if result
is not True:
160 pytest
.skip("Kernel requirements are not met")
162 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
163 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
164 logger
.info("=" * 40)
166 logger
.info("Running setup_module to create topology")
168 # This function initiates the topology build with Topogen...
169 json_file
= "{}/bgp_default_originate_topo1.json".format(CWD
)
170 tgen
= Topogen(json_file
, mod
.__name
__)
172 topo
= tgen
.json_topo
173 # ... and here it calls Mininet initialization functions.
175 # Starting topology, create tmp files which are loaded to routers
176 # to start daemons and then start routers
179 # Creating configuration from JSON
180 build_config_from_json(tgen
, topo
)
183 global BGP_CONVERGENCE
184 global DEFAULT_ROUTES
185 global DEFAULT_ROUTE_NXT_HOP_R1
, DEFAULT_ROUTE_NXT_HOP_R3
186 global R0_NETWORK_LOOPBACK
, R0_NETWORK_LOOPBACK_NXTHOP
, R1_NETWORK_LOOPBACK
, R1_NETWORK_LOOPBACK_NXTHOP
187 global R0_NETWORK_CONNECTED
, R0_NETWORK_CONNECTED_NXTHOP
, R1_NETWORK_CONNECTED
, R1_NETWORK_CONNECTED_NXTHOP
188 global R4_NETWORK_LOOPBACK
, R4_NETWORK_LOOPBACK_NXTHOP
, R3_NETWORK_LOOPBACK
, R3_NETWORK_LOOPBACK_NXTHOP
189 global R4_NETWORK_CONNECTED
, R4_NETWORK_CONNECTED_NXTHOP
, R3_NETWORK_CONNECTED
, R3_NETWORK_CONNECTED_NXTHOP
191 ADDR_TYPES
= check_address_types()
192 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
193 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
196 # There are the global varibles used through out the file these are acheived only after building the topology.
198 r0_loopback_address_ipv4
= topo
["routers"]["r0"]["links"]["lo"]["ipv4"]
199 r0_loopback_address_ipv4_nxt_hop
= topo
["routers"]["r0"]["links"]["r1"][
202 r0_loopback_address_ipv6
= topo
["routers"]["r0"]["links"]["lo"]["ipv6"]
203 r0_loopback_address_ipv6_nxt_hop
= topo
["routers"]["r0"]["links"]["r1"][
207 r1_loopback_address_ipv4
= topo
["routers"]["r1"]["links"]["lo"]["ipv4"]
208 r1_loopback_address_ipv4_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"][
211 r1_loopback_address_ipv6
= topo
["routers"]["r1"]["links"]["lo"]["ipv6"]
212 r1_loopback_address_ipv6_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"][
216 r4_loopback_address_ipv4
= topo
["routers"]["r4"]["links"]["lo"]["ipv4"]
217 r4_loopback_address_ipv4_nxt_hop
= topo
["routers"]["r4"]["links"]["r3"][
220 r4_loopback_address_ipv6
= topo
["routers"]["r4"]["links"]["lo"]["ipv6"]
221 r4_loopback_address_ipv6_nxt_hop
= topo
["routers"]["r4"]["links"]["r3"][
225 r3_loopback_address_ipv4
= topo
["routers"]["r3"]["links"]["lo"]["ipv4"]
226 r3_loopback_address_ipv4_nxt_hop
= topo
["routers"]["r3"]["links"]["r2"][
229 r3_loopback_address_ipv6
= topo
["routers"]["r3"]["links"]["lo"]["ipv6"]
230 r3_loopback_address_ipv6_nxt_hop
= topo
["routers"]["r3"]["links"]["r2"][
234 R0_NETWORK_LOOPBACK
= {
235 "ipv4": r0_loopback_address_ipv4
,
236 "ipv6": r0_loopback_address_ipv6
,
238 R0_NETWORK_LOOPBACK_NXTHOP
= {
239 "ipv4": r0_loopback_address_ipv4_nxt_hop
,
240 "ipv6": r0_loopback_address_ipv6_nxt_hop
,
243 R1_NETWORK_LOOPBACK
= {
244 "ipv4": r1_loopback_address_ipv4
,
245 "ipv6": r1_loopback_address_ipv6
,
247 R1_NETWORK_LOOPBACK_NXTHOP
= {
248 "ipv4": r1_loopback_address_ipv4_nxt_hop
,
249 "ipv6": r1_loopback_address_ipv6_nxt_hop
,
252 R0_NETWORK_CONNECTED
= {
253 "ipv4": r0_connected_address_ipv4
,
254 "ipv6": r0_connected_address_ipv6
,
256 R0_NETWORK_CONNECTED_NXTHOP
= {
257 "ipv4": r0_loopback_address_ipv4_nxt_hop
,
258 "ipv6": r0_loopback_address_ipv6_nxt_hop
,
261 R1_NETWORK_CONNECTED
= {
262 "ipv4": r1_connected_address_ipv4
,
263 "ipv6": r1_connected_address_ipv6
,
265 R1_NETWORK_CONNECTED_NXTHOP
= {
266 "ipv4": r1_loopback_address_ipv4_nxt_hop
,
267 "ipv6": r1_loopback_address_ipv6_nxt_hop
,
270 R4_NETWORK_LOOPBACK
= {
271 "ipv4": r4_loopback_address_ipv4
,
272 "ipv6": r4_loopback_address_ipv6
,
274 R4_NETWORK_LOOPBACK_NXTHOP
= {
275 "ipv4": r4_loopback_address_ipv4_nxt_hop
,
276 "ipv6": r4_loopback_address_ipv6_nxt_hop
,
279 R3_NETWORK_LOOPBACK
= {
280 "ipv4": r3_loopback_address_ipv4
,
281 "ipv6": r3_loopback_address_ipv6
,
283 R3_NETWORK_LOOPBACK_NXTHOP
= {
284 "ipv4": r3_loopback_address_ipv4_nxt_hop
,
285 "ipv6": r3_loopback_address_ipv6_nxt_hop
,
288 R4_NETWORK_CONNECTED
= {
289 "ipv4": r4_connected_address_ipv4
,
290 "ipv6": r4_connected_address_ipv6
,
292 R4_NETWORK_CONNECTED_NXTHOP
= {
293 "ipv4": r4_loopback_address_ipv4_nxt_hop
,
294 "ipv6": r4_loopback_address_ipv6_nxt_hop
,
297 R3_NETWORK_CONNECTED
= {
298 "ipv4": r3_connected_address_ipv4
,
299 "ipv6": r3_connected_address_ipv6
,
301 R3_NETWORK_CONNECTED_NXTHOP
= {
302 "ipv4": r3_loopback_address_ipv4_nxt_hop
,
303 "ipv6": r3_loopback_address_ipv6_nxt_hop
,
306 # populating the nexthop for default routes
308 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
310 interface
= topo
["routers"]["r1"]["links"]["r2"]["interface"]
311 ipv6_link_local
= get_frr_ipv6_linklocal(tgen
, "r1", intf
=interface
)
312 ipv4_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"]["ipv4"].split("/")[0]
313 ipv6_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"]["ipv6"].split("/")[0]
314 DEFAULT_ROUTE_NXT_HOP_R1
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local
}
316 interface
= topo
["routers"]["r3"]["links"]["r2"]["interface"]
317 ipv6_link_local
= get_frr_ipv6_linklocal(tgen
, "r3", intf
=interface
)
318 ipv4_nxt_hop
= topo
["routers"]["r3"]["links"]["r2"]["ipv4"].split("/")[0]
319 ipv6_nxt_hop
= topo
["routers"]["r3"]["links"]["r2"]["ipv6"].split("/")[0]
320 DEFAULT_ROUTE_NXT_HOP_R3
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local
}
322 logger
.info("Running setup_module() done")
325 def teardown_module():
326 """Teardown the pytest environment"""
328 logger
.info("Running teardown_module to delete topology")
332 # Stop toplogy and Remove tmp files
336 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
338 logger
.info("=" * 40)
340 #####################################################
344 #####################################################
346 def test_verify_bgp_default_originate_in_IBGP_p0(request
):
348 Verify BGP default-originate route with IBGP peer
351 global BGP_CONVERGENCE
354 tc_name
= request
.node
.name
355 write_test_header(tc_name
)
357 # Don't run this test if we have any failure.
358 if tgen
.routers_have_failure():
359 check_router_status(tgen
)
360 reset_config_on_routers(tgen
)
362 if BGP_CONVERGENCE
!= True:
363 pytest
.skip("skipped because of BGP Convergence failure")
365 step("Configure IPv4 and IPv6 , IBGP neighbor between R1 and R2")
366 step("Configure IPv4 and IPv6 Loopback interface on R1, R0 and R2")
367 step("Configure IPv4 and IPv6 EBGP neighbor between R0 and R1")
369 r0_local_as
= topo
["routers"]["r0"]["bgp"]["local_as"]
370 r1_local_as
= topo
["routers"]["r1"]["bgp"]["local_as"]
371 r2_local_as
= topo
["routers"]["r2"]["bgp"]["local_as"]
372 r3_local_as
= topo
["routers"]["r3"]["bgp"]["local_as"]
373 r4_local_as
= topo
["routers"]["r4"]["bgp"]["local_as"]
393 "local_as": r3_local_as
,
398 "local_as": r4_local_as
,
402 result
= modify_as_number(tgen
, topo
, input_dict
)
404 assert result
is True
405 except AssertionError:
406 logger
.info("Expected behaviour: {}".format(result
))
407 logger
.info("BGP config is not created because of invalid ASNs")
409 step("After changing the BGP AS Path Verify the BGP Convergence")
410 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
411 assert BGP_CONVERGENCE
is True, " Complete Convergence is expected after changing the ASN but failed to converge --> :Failed \n Error: {}".format(
415 step("Configure IPv4 and IPv6 static route on R1 next-hop as NULL0")
416 for addr_type
in ADDR_TYPES
:
417 static_routes_input
= {
421 "network": [NETWORK1_1
[addr_type
]],
422 "next_hop": NEXT_HOP_IP
[addr_type
],
427 result
= create_static_routes(tgen
, static_routes_input
)
428 assert result
is True, "Testcase {} : Failed to configure the static routes {} on router R1 \n Error: {}".format(
429 tc_name
,static_routes_input
, result
431 step("verify IPv4 and IPv6 static route are configured and up on R1")
432 for addr_type
in ADDR_TYPES
:
433 static_routes_input
= {
437 "network": [NETWORK1_1
[addr_type
]],
438 "next_hop": NEXT_HOP_IP
[addr_type
],
443 result
= verify_fib_routes(tgen
, addr_type
, "r1", static_routes_input
)
444 assert result
is True, "Testcase {} : Failed \n After configuring the static routes {} , the routes are not found in FIB \n Error: {}".format(
445 tc_name
,static_routes_input
, result
449 "Configure redistribute static and connected on R0 and R1, for IPv4 and IPv6 address family "
451 redistribute_static
= {
458 {"redist_type": "static"},
459 {"redist_type": "connected"},
466 {"redist_type": "static"},
467 {"redist_type": "connected"},
480 {"redist_type": "static"},
481 {"redist_type": "connected"},
488 {"redist_type": "static"},
489 {"redist_type": "connected"},
497 result
= create_router_bgp(tgen
, topo
, redistribute_static
)
498 assert result
is True, "Testcase {} : Failed to configure the redistribute static configuration \n Error: {}".format(tc_name
, result
)
501 "After configuring redistribute command , verify static and connected routes ( loopback connected routes) are advertised on R2"
504 for addr_type
in ADDR_TYPES
:
505 static_routes_input
= {
509 "network": [NETWORK1_1
[addr_type
]],
510 "next_hop": NEXT_HOP_IP
[addr_type
],
513 "network": [R0_NETWORK_LOOPBACK
[addr_type
]],
514 "next_hop": R0_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
517 "network": [R0_NETWORK_CONNECTED
[addr_type
]],
518 "next_hop": R0_NETWORK_CONNECTED_NXTHOP
[addr_type
],
521 "network": [R1_NETWORK_LOOPBACK
[addr_type
]],
522 "next_hop": R1_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
525 "network": [R1_NETWORK_CONNECTED
[addr_type
]],
526 "next_hop": R1_NETWORK_CONNECTED_NXTHOP
[addr_type
],
531 result
= verify_fib_routes(tgen
, addr_type
, "r2", static_routes_input
)
532 assert result
is True, "Testcase {} : After redistributing static routes the routes {} expected in FIB but NOT FOUND ......! \n Error: {}".format(
533 tc_name
, static_routes_input
,result
536 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
537 assert result
is True, "Testcase {} : After redistributing static routes the routes {} expected in RIB but NOT FOUND ......! \n Error: {}".format(
538 tc_name
, static_routes_input
, result
542 "Taking the snapshot of the prefix count before configuring the default originate"
544 snapshot1
= get_prefix_count_route(tgen
, topo
, dut
="r2", peer
="r1")
547 "Configure Default originate on R1 for R1 to R2, for IPv4 and IPv6 BGP address family "
549 local_as
= get_dut_as_number(tgen
, dut
="r1")
550 default_originate_config
= {
553 "local_as": local_as
,
555 "ipv4": {"unicast": {"default_originate": {"r2": {}}}},
556 "ipv6": {"unicast": {"default_originate": {"r2": {}}}},
561 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
562 assert result
is True, "Testcase {} : Failed Configuring default originate configuration. \n Error: {}".format(tc_name
, result
)
565 "After configuring default-originate command , verify default routes are advertised on R2 "
566 " R1 static and loopback routes received on R2 BGP and FIB"
568 for addr_type
in ADDR_TYPES
:
569 static_routes_input
= {
573 "network": [NETWORK1_1
[addr_type
]],
574 "next_hop": NEXT_HOP_IP
[addr_type
],
577 "network": [R1_NETWORK_LOOPBACK
[addr_type
]],
578 "next_hop": R1_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
581 "network": [R1_NETWORK_CONNECTED
[addr_type
]],
582 "next_hop": R1_NETWORK_CONNECTED_NXTHOP
[addr_type
],
588 result
= verify_fib_routes(tgen
, addr_type
, "r2", static_routes_input
)
589 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(
593 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
594 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(
598 "Verify default route for IPv4 and IPv6 present with path=igp metric =0 , local-preference= 100 "
600 result
= verify_rib_default_route(
604 routes
=DEFAULT_ROUTES
,
605 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
609 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
611 "Taking the snapshot2 of the prefix count after configuring the default originate"
613 snapshot2
= get_prefix_count_route(tgen
, topo
, dut
="r2", peer
="r1")
615 step("verifying the prefix count incrementing or not ")
616 isIPv4prefix_incremented
= False
617 isIPv6prefix_incremented
= False
618 if snapshot1
["ipv4_count"] < snapshot2
["ipv4_count"]:
619 isIPv4prefix_incremented
= True
620 if snapshot1
["ipv6_count"] < snapshot2
["ipv6_count"]:
621 isIPv6prefix_incremented
= True
624 isIPv4prefix_incremented
is True
625 ), "Testcase {} : Failed Error: IPV4 Prefix is not incremented on receiveing ".format(
630 isIPv6prefix_incremented
is True
631 ), "Testcase {} : Failed Error: IPV6 Prefix is not incremented on receiveing ".format(
634 write_test_footer(tc_name
)
637 def test_verify_bgp_default_originate_in_EBGP_p0(request
):
639 Verify BGP default-originate route with EBGP peer
642 global BGP_CONVERGENCE
645 tc_name
= request
.node
.name
646 write_test_header(tc_name
)
648 # Don't run this test if we have any failure.
649 if tgen
.routers_have_failure():
650 check_router_status(tgen
)
651 reset_config_on_routers(tgen
)
653 if BGP_CONVERGENCE
!= True:
654 pytest
.skip("skipped because of BGP Convergence failure")
656 step("Configure IPv4 and IPv6 , EBGP neighbor between R3 and R2")
657 step("Configure lPv4 and IPv6 Loopback interface on R3, R4 and R2")
658 step("Configure IPv4 and IPv6 IBGP neighbor between R4 and R3")
659 r0_local_as
= topo
["routers"]["r0"]["bgp"]["local_as"]
660 r1_local_as
= topo
["routers"]["r1"]["bgp"]["local_as"]
661 r2_local_as
= topo
["routers"]["r2"]["bgp"]["local_as"]
662 r3_local_as
= topo
["routers"]["r3"]["bgp"]["local_as"]
663 r4_local_as
= topo
["routers"]["r4"]["bgp"]["local_as"]
668 "local_as": r0_local_as
,
673 "local_as": r1_local_as
,
678 "local_as": r2_local_as
,
692 result
= modify_as_number(tgen
, topo
, input_dict
)
694 assert result
is True
695 except AssertionError:
696 logger
.info("Expected behaviour: {}".format(result
))
697 logger
.info("BGP config is not created because of invalid ASNs")
698 step("After changing the BGP AS Path Verify the BGP Convergence")
700 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
701 assert BGP_CONVERGENCE
is True, "Complete convergence is expeceted after changing the ASN os the routes ..! :Failed \n Error: {}".format(
705 step(" Configure IPv4 and IPv6 static route on R3 next-hop on R4 interface")
706 for addr_type
in ADDR_TYPES
:
707 static_routes_input
= {
711 "network": [NETWORK1_1
[addr_type
]],
712 "next_hop": NEXT_HOP_IP
[addr_type
],
717 result
= create_static_routes(tgen
, static_routes_input
)
718 assert result
is True, "Testcase {} : Failed to configure the static routes ....! Failed \n Error: {}".format(
721 step("verify IPv4 and IPv6 static route are configured and up on R1")
722 for addr_type
in ADDR_TYPES
:
723 static_routes_input
= {
727 "network": [NETWORK1_1
[addr_type
]],
728 "next_hop": NEXT_HOP_IP
[addr_type
],
733 result
= verify_fib_routes(tgen
, addr_type
, "r3", static_routes_input
)
734 assert result
is True, "Testcase {} : Route is not found in {} in FIB ......! Failed \n Error: {}".format(
735 tc_name
, static_routes_input
,result
739 "Configure redistribute static and connected on R3 and R4 for IPv4 and IPv6 address family "
741 redistribute_static
= {
748 {"redist_type": "static"},
749 {"redist_type": "connected"},
756 {"redist_type": "static"},
757 {"redist_type": "connected"},
770 {"redist_type": "static"},
771 {"redist_type": "connected"},
778 {"redist_type": "static"},
779 {"redist_type": "connected"},
787 result
= create_router_bgp(tgen
, topo
, redistribute_static
)
788 assert result
is True, "Testcase {} : Failed to configure redistribute configuratin \n Error: {}".format(tc_name
, result
)
791 "After configuring redistribute command , verify static and connected routes ( loopback connected routes) are advertised on R2"
793 for addr_type
in ADDR_TYPES
:
794 static_routes_input
= {
798 "network": [NETWORK1_1
[addr_type
]],
799 "next_hop": NEXT_HOP_IP
[addr_type
],
802 "network": [R3_NETWORK_LOOPBACK
[addr_type
]],
803 "next_hop": R3_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
806 "network": [R3_NETWORK_CONNECTED
[addr_type
]],
807 "next_hop": R3_NETWORK_CONNECTED_NXTHOP
[addr_type
],
810 "network": [R4_NETWORK_LOOPBACK
[addr_type
]],
811 "next_hop": R4_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
814 "network": [R4_NETWORK_CONNECTED
[addr_type
]],
815 "next_hop": R4_NETWORK_CONNECTED_NXTHOP
[addr_type
],
820 result
= verify_fib_routes(tgen
, addr_type
, "r2", static_routes_input
)
821 assert result
is True, "Testcase {} : static & and connected routes are expected but not found in FIB .... ! \n Error: {}".format(
824 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
825 assert result
is True, "Testcase {} : static & and connected routes are expected but not found in RIB .... ! \n Error: {}".format(
828 snapshot1
= get_prefix_count_route(tgen
, topo
, dut
="r2", peer
="r3")
830 "Configure Default originate on R3 for R3 to R2, on IPv4 and IPv6 BGP address family"
832 local_as
= get_dut_as_number(tgen
, dut
="r3")
833 default_originate_config
= {
836 "local_as": local_as
,
838 "ipv4": {"unicast": {"default_originate": {"r2": {}}}},
839 "ipv6": {"unicast": {"default_originate": {"r2": {}}}},
844 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
845 assert result
is True, "Testcase {} : Failed to configure the default originate configuration \n Error: {}".format(tc_name
, result
)
848 "After configuring default-originate command , verify default routes are advertised on R2 on both BGP RIB and FIB"
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": [DEFAULT_ROUTES
[addr_type
]],
861 "next_hop": DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
867 result
= verify_fib_routes(tgen
, addr_type
, "r2", static_routes_input
)
868 assert result
is True, "Testcase {} : static route from R1 {} and default route from R3 is expected in R2 FIB .....! NOT FOUND \n Error: {}".format(
869 tc_name
, NETWORK1_1
,result
872 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
873 assert result
is True, "Testcase {} : static route from R1 {} and default route from R3 is expected in R2 RIB .....! NOT FOUND \n Error: {}".format(
874 tc_name
,NETWORK1_1
, result
878 "Verify default route for IPv4 and IPv6 present with path = ebgp as path, metric =0 "
880 # local preference will bgp not applicable for eBGP
881 result
= verify_rib_default_route(
885 routes
=DEFAULT_ROUTES
,
886 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
888 expected_aspath
="4000",
890 assert result
is True, "Testcase {} : Default route from R3 is expected with attributes in R2 RIB .....! NOT FOUND Error: {}".format(tc_name
, result
)
893 "Taking the snapshot2 of the prefix count after configuring the default originate"
895 snapshot2
= get_prefix_count_route(tgen
, topo
, dut
="r2", peer
="r3")
897 "Verify out-prefix count is incremented default route on IPv4 and IPv6 neighbor"
899 isIPv4prefix_incremented
= False
900 isIPv6prefix_incremented
= False
901 if snapshot1
["ipv4_count"] < snapshot2
["ipv4_count"]:
902 isIPv4prefix_incremented
= True
903 if snapshot1
["ipv6_count"] < snapshot2
["ipv6_count"]:
904 isIPv6prefix_incremented
= True
907 isIPv4prefix_incremented
is True
908 ), "Testcase {} : Failed Error: IPV4 Prefix is not incremented on receiveing ".format(
913 isIPv6prefix_incremented
is True
914 ), "Testcase {} : Failed Error: IPV6 Prefix is not incremented on receiveing ".format(
917 write_test_footer(tc_name
)
920 def test_verify_bgp_default_originate_in_IBGP_with_route_map_p0(request
):
922 test_verify_bgp_default_originate_in_IBGP_with_route_map_p0
925 global BGP_CONVERGENCE
928 tc_name
= request
.node
.name
929 write_test_header(tc_name
)
931 # Don't run this test if we have any failure.
932 if tgen
.routers_have_failure():
933 check_router_status(tgen
)
934 reset_config_on_routers(tgen
)
936 if BGP_CONVERGENCE
!= True:
937 pytest
.skip("skipped because of BGP Convergence failure")
939 step("Configure IPv4 and IPv6 , IBGP neighbor between R1 and R2")
940 step("Configure IPv4 and IPv6 , EBGP neighbor between R1 and R0")
941 r0_local_as
= topo
["routers"]["r0"]["bgp"]["local_as"]
942 r1_local_as
= topo
["routers"]["r1"]["bgp"]["local_as"]
943 r2_local_as
= topo
["routers"]["r2"]["bgp"]["local_as"]
944 r3_local_as
= topo
["routers"]["r3"]["bgp"]["local_as"]
945 r4_local_as
= topo
["routers"]["r4"]["bgp"]["local_as"]
950 "local_as": r0_local_as
,
965 "local_as": r3_local_as
,
970 "local_as": r4_local_as
,
974 result
= modify_as_number(tgen
, topo
, input_dict
)
976 assert result
is True
977 except AssertionError:
978 logger
.info("Expected behaviour: {}".format(result
))
979 logger
.info("BGP config is not created because of invalid ASNs")
981 step("After changing the BGP AS Path Verify the BGP Convergence")
982 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
983 assert BGP_CONVERGENCE
is True, "Complete convergence is expected after changing ASN ....! ERROR :Failed \n Error: {}".format(
987 step("Configure 2 IPv4 and 2 IPv6 Static route on R0 with next-hop as Null0")
988 for addr_type
in ADDR_TYPES
:
989 static_routes_input
= {
993 "network": [NETWORK1_1
[addr_type
]],
994 "next_hop": NEXT_HOP_IP
[addr_type
],
997 "network": [NETWORK2_1
[addr_type
]],
998 "next_hop": NEXT_HOP_IP
[addr_type
],
1003 result
= create_static_routes(tgen
, static_routes_input
)
1004 assert result
is True, "Testcase {} : Static Configuration is Failed \n Error: {}".format(
1008 step("verify IPv4 and IPv6 static route are configured and up on R0")
1009 for addr_type
in ADDR_TYPES
:
1010 static_routes_input
= {
1014 "network": [NETWORK1_1
[addr_type
]],
1015 "next_hop": NEXT_HOP_IP
[addr_type
],
1018 "network": [NETWORK2_1
[addr_type
]],
1019 "next_hop": NEXT_HOP_IP
[addr_type
],
1024 result
= verify_fib_routes(tgen
, addr_type
, "r0", static_routes_input
)
1025 assert result
is True, "Testcase {} : routes {} unable is not found in R0 FIB \n Error: {}".format(
1026 tc_name
, static_routes_input
,result
1030 "Configure redistribute static on IPv4 and IPv6 address family on R0 for R0 to R1 neighbor "
1032 redistribute_static
= {
1036 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1037 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1042 result
= create_router_bgp(tgen
, topo
, redistribute_static
)
1043 assert result
is True, "Testcase {} : Failed to configure redistribute static configuration....! \n Error: {}".format(tc_name
, result
)
1045 step("verify IPv4 and IPv6 static route are configured and up on R1")
1046 for addr_type
in ADDR_TYPES
:
1047 static_routes_input
= {
1051 "network": [NETWORK1_1
[addr_type
]],
1052 "next_hop": NEXT_HOP_IP
[addr_type
],
1055 "network": [NETWORK2_1
[addr_type
]],
1056 "next_hop": NEXT_HOP_IP
[addr_type
],
1061 result
= verify_fib_routes(tgen
, addr_type
, "r1", static_routes_input
)
1062 assert result
is True, "Testcase {} : Failed... Routes {} expected in r0 FIB after configuring the redistribute config \n Error: {}".format(
1063 tc_name
,static_routes_input
, result
1066 result
= verify_bgp_rib(tgen
, addr_type
, "r1", static_routes_input
)
1067 assert result
is True, "Testcase {} : Failed... Routes {} expected in r0 RIB after configuring the redistribute config \n Error: {}".format(
1068 tc_name
, static_routes_input
,result
1072 "Configure IPv4 prefix-list Pv4 and and IPv6 prefix-list Pv6 on R1 to match BGP route Sv41, Sv42, IPv6 route Sv61 Sv62 permit "
1081 "network": NETWORK1_1
["ipv4"],
1086 "network": NETWORK2_1
["ipv4"],
1095 "network": NETWORK1_1
["ipv6"],
1100 "network": NETWORK2_1
["ipv6"],
1108 result
= create_prefix_lists(tgen
, input_dict_3
)
1109 assert result
is True, "Testcase {} : Failed to configure the prefix list \n Error: {}".format(tc_name
, result
)
1112 "Configure IPV4 and IPv6 route-map (RMv4 and RMv6 ) matching prefix-list (Pv4 and Pv6) respectively on R1"
1121 "match": {"ipv4": {"prefix_lists": "Pv4"}},
1128 "match": {"ipv6": {"prefix_lists": "Pv6"}},
1134 result
= create_route_maps(tgen
, input_dict_3
)
1135 assert result
is True, "Testcase {} : Failed to configure the route map \n Error: {}".format(tc_name
, result
)
1138 "Configure default-originate with route-map (RMv4 and RMv6) on R1, on BGP IPv4 and IPv6 address family "
1140 local_as
= get_dut_as_number(tgen
, dut
="r1")
1141 default_originate_config
= {
1144 "local_as": local_as
,
1147 "unicast": {"default_originate": {"r2": {"route_map": "RMv4"}}}
1150 "unicast": {"default_originate": {"r2": {"route_map": "RMv6"}}}
1156 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
1157 assert result
is True, "Testcase {} : Failed to configure the default originate \n Error: {}".format(tc_name
, result
)
1159 step("Verify the default route is received in BGP RIB and FIB")
1161 "After configuring default-originate command , verify default routes are advertised on R2 "
1163 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1164 for addr_type
in ADDR_TYPES
:
1165 static_routes_input
= {
1169 "network": [DEFAULT_ROUTES
[addr_type
]],
1170 "next_hop": DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1175 result
= verify_fib_routes(
1179 static_routes_input
,
1180 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1182 assert result
is True, "Testcase {} : Failed...! Expected default route from R1 not found in FIB \n Error: {}".format(
1186 result
= verify_bgp_rib(
1190 static_routes_input
,
1191 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1193 assert result
is True, "Testcase {} : Failed...! Expected default route from R1 not found in RIB \n Error: {}".format(
1196 step("Remove route-map RMv4 and RMv6 from default-originate command in R1")
1197 NOTE
= """ Configuring the default-originate should remove the previously applied default originate with condtional route-map"""
1198 local_as
= get_dut_as_number(tgen
, dut
="r1")
1199 default_originate_config
= {
1202 "local_as": local_as
,
1204 "ipv4": {"unicast": {"default_originate": {"r2": {}}}},
1205 "ipv6": {"unicast": {"default_originate": {"r2": {}}}},
1210 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
1211 assert result
is True, "Testcase {} : Failed to remove the default originate conditional route-map \n Error: {}".format(tc_name
, result
)
1214 "Verify BGP RIB and FIB After removing route-map , default route still present on R2"
1216 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1217 for addr_type
in ADDR_TYPES
:
1218 static_routes_input
= {
1222 "network": [DEFAULT_ROUTES
[addr_type
]],
1223 "next_hop": DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1229 result
= verify_fib_routes(
1233 static_routes_input
,
1234 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1236 assert result
is True, "Testcase {} : Failed Default route from R1 is not found in FIB \n Error: {}".format(
1240 result
= verify_bgp_rib(
1244 static_routes_input
,
1245 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1247 assert result
is True, "Testcase {} : Failed Default route from R1 is not found in RIB \n Error: {}".format(
1251 step("Configure default-originate with route-map (RMv4 and RMv6) on R1 ")
1252 local_as
= get_dut_as_number(tgen
, dut
="r1")
1253 default_originate_config
= {
1256 "local_as": local_as
,
1260 "default_originate": {
1262 "route_map": "RMv4",
1269 "default_originate": {
1271 "route_map": "RMv6",
1280 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
1281 assert result
is True, "Testcase {} : Failed to configure the Default originate route-map \n Error: {}".format(tc_name
, result
)
1284 "After configuring default-originate command , verify default routes are advertised on R2 "
1286 for addr_type
in ADDR_TYPES
:
1287 static_routes_input
= {
1291 "network": [DEFAULT_ROUTES
[addr_type
]],
1292 "next_hop": DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1298 result
= verify_fib_routes(
1302 static_routes_input
,
1303 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1305 assert result
is True, "Testcase {} : Failed Default Route from R1 is not found in FIB \n Error: {}".format(
1309 result
= verify_bgp_rib(
1313 static_routes_input
,
1314 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1316 assert result
is True, "Testcase {} : Failed Default Route from R1 is not found in RIB \n Error: {}".format(
1320 step("Delete prefix list using no prefix-list")
1328 "network": NETWORK1_1
["ipv4"],
1334 "network": NETWORK2_1
["ipv4"],
1344 "network": NETWORK1_1
["ipv6"],
1350 "network": NETWORK2_1
["ipv6"],
1359 result
= create_prefix_lists(tgen
, input_dict_3
)
1360 assert result
is True, "Testcase {} : Failed to delete the prefix list Error: {}".format(tc_name
, result
)
1363 "Verify BGP RIB and FIB After deleting prefix-list , verify IPv4 and IPv6 default route got removed from DUT "
1365 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1366 for addr_type
in ADDR_TYPES
:
1367 static_routes_input
= {
1371 "network": [DEFAULT_ROUTES
[addr_type
]],
1372 "next_hop": DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1377 result
= verify_fib_routes(
1381 static_routes_input
,
1382 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1387 ), "Testcase {} : Failed\n After deleteing prefix default route is not expected in FIB \n Error: {}".format(
1391 result
= verify_bgp_rib(
1395 static_routes_input
,
1396 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1401 ), "Testcase {} : Failed \n After deleteing prefix default route is not expected in RIB \n Error: {}".format(
1405 step("Configure prefix-list and delete route-map using no route-map")
1413 "network": NETWORK1_1
["ipv4"],
1418 "network": NETWORK2_1
["ipv4"],
1427 "network": NETWORK1_1
["ipv6"],
1432 "network": NETWORK2_1
["ipv6"],
1440 result
= create_prefix_lists(tgen
, input_dict_3
)
1441 assert result
is True, "Testcase {} : Failed to configure the prefix lists Error: {}".format(tc_name
, result
)
1444 "After configuring the Prefixlist cross checking the BGP Default route is configured again , before deleting the route map"
1447 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1448 for addr_type
in ADDR_TYPES
:
1449 static_routes_input
= {
1453 "network": [DEFAULT_ROUTES
[addr_type
]],
1454 "next_hop": DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1459 result
= verify_fib_routes(
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 FIB but not found \n Error: {}".format(
1471 result
= verify_bgp_rib(
1475 static_routes_input
,
1476 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1479 assert result
is True, "Testcase {} : Failed Default route from R1 is expected in RIB but not found \n Error: {}".format(
1483 step("Deleting the routemap")
1484 input_dict
= {"r1": {"route_maps": ["RMv4", "RMv6"]}}
1485 result
= delete_route_maps(tgen
, input_dict
)
1486 assert result
is True, "Testcase {} : Failed to delete the Route-map \n Error: {}".format(tc_name
, result
)
1489 "Verify BGP RIB and FIB ,After deleting route-map , verify IPv4 and IPv6 default route got removed from DUT"
1491 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1492 for addr_type
in ADDR_TYPES
:
1493 static_routes_input
= {
1497 "network": [DEFAULT_ROUTES
[addr_type
]],
1498 "next_hop": DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1504 result
= verify_fib_routes(
1508 static_routes_input
,
1509 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1514 ), "Testcase {} : Failed \n After deleteing route-map default route is not expected in FIB \nError: {}".format(
1518 result
= verify_bgp_rib(
1522 static_routes_input
,
1523 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1528 ), "Testcase {} : Failed \n After deleteing route-map default route is not expected in RIB \n Error: {}".format(
1532 write_test_footer(tc_name
)
1535 def test_verify_bgp_default_originate_in_EBGP_with_route_map_p0(request
):
1537 test_verify_bgp_default_originate_in_EBGP_with_route_map_p0
1539 tgen
= get_topogen()
1540 global BGP_CONVERGENCE
1543 tc_name
= request
.node
.name
1544 write_test_header(tc_name
)
1545 tgen
= get_topogen()
1546 # Don't run this test if we have any failure.
1547 if tgen
.routers_have_failure():
1548 check_router_status(tgen
)
1549 reset_config_on_routers(tgen
)
1551 if BGP_CONVERGENCE
!= True:
1552 pytest
.skip("skipped because of BGP Convergence failure")
1554 step("Configure IPv4 and IPv6 , EBGP neighbor between R3 and R2")
1555 step("Configure IPv4 and IPv6 IBGP neighbor between R3 and R4")
1556 r0_local_as
= topo
["routers"]["r0"]["bgp"]["local_as"]
1557 r1_local_as
= topo
["routers"]["r1"]["bgp"]["local_as"]
1558 r2_local_as
= topo
["routers"]["r2"]["bgp"]["local_as"]
1559 r3_local_as
= topo
["routers"]["r3"]["bgp"]["local_as"]
1560 r4_local_as
= topo
["routers"]["r4"]["bgp"]["local_as"]
1565 "local_as": r0_local_as
,
1570 "local_as": r1_local_as
,
1575 "local_as": r2_local_as
,
1589 result
= modify_as_number(tgen
, topo
, input_dict
)
1591 assert result
is True
1592 except AssertionError:
1593 logger
.info("Expected behaviour: {}".format(result
))
1594 logger
.info("BGP config is not created because of invalid ASNs")
1595 step("After changing the BGP AS Path Verify the BGP Convergence")
1596 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
1597 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
1602 "Configure 2 IPv4 and 2 IPv6, Static route on R4 with next-hop as Null0 IPv4 route Sv41, Sv42, IPv6 route Sv61 Sv62"
1604 for addr_type
in ADDR_TYPES
:
1605 static_routes_input
= {
1609 "network": [NETWORK1_1
[addr_type
]],
1610 "next_hop": NEXT_HOP_IP
[addr_type
],
1613 "network": [NETWORK2_1
[addr_type
]],
1614 "next_hop": NEXT_HOP_IP
[addr_type
],
1619 result
= create_static_routes(tgen
, static_routes_input
)
1620 assert result
is True, "Testcase {} : Failed to configure the static routes \n Error: {}".format(
1623 step("verify IPv4 and IPv6 static route are configured and up on R4")
1624 for addr_type
in ADDR_TYPES
:
1625 static_routes_input
= {
1629 "network": [NETWORK1_1
[addr_type
]],
1630 "next_hop": NEXT_HOP_IP
[addr_type
],
1633 "network": [NETWORK2_1
[addr_type
]],
1634 "next_hop": NEXT_HOP_IP
[addr_type
],
1639 result
= verify_fib_routes(tgen
, addr_type
, "r4", static_routes_input
)
1640 assert result
is True, "Testcase {} : Failed Static route {} is not found in R4 FIB \n Error: {}".format(
1641 tc_name
, static_routes_input
,result
1645 "Configure redistribute static on IPv4 and IPv6 address family on R4 for R4 to R3 neighbo"
1647 redistribute_static
= {
1651 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1652 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1657 result
= create_router_bgp(tgen
, topo
, redistribute_static
)
1658 assert result
is True, "Testcase {} : Failed to configure the redistribute static \n Error: {}".format(tc_name
, result
)
1660 step("verify IPv4 and IPv6 static route are configured and up on R3")
1661 for addr_type
in ADDR_TYPES
:
1662 static_routes_input
= {
1666 "network": [NETWORK1_1
[addr_type
]],
1667 "next_hop": NEXT_HOP_IP
[addr_type
],
1670 "network": [NETWORK2_1
[addr_type
]],
1671 "next_hop": NEXT_HOP_IP
[addr_type
],
1676 result
= verify_fib_routes(tgen
, addr_type
, "r3", static_routes_input
)
1677 assert result
is True, "Testcase {} : Failed static routes from R1 and R3 is not found in FIB \n Error: {}".format(
1680 result
= verify_bgp_rib(tgen
, addr_type
, "r3", static_routes_input
)
1681 assert result
is True, "Testcase {} : Failed static routes from R1 and R3 is not found in RIB \n Error: {}".format(
1686 "Configure IPv4 prefix-list Pv4 and and IPv6 prefix-list Pv6 on R3 so new route which is not present on R3"
1695 "network": NETWORK3_1
["ipv4"],
1704 "network": NETWORK3_1
["ipv6"],
1712 result
= create_prefix_lists(tgen
, input_dict_3
)
1713 assert result
is True, "Testcase {} : Failed to configure the prefix lists \n Error: {}".format(tc_name
, result
)
1715 step("verify IPv4 and IPv6 Prefix list got configured on R3")
1716 input_dict
= {"r3": {"prefix_lists": ["Pv4", "Pv6"]}}
1717 result
= verify_prefix_lists(tgen
, input_dict
)
1718 assert result
is True, "Testcase {} : Failed ..! configured prefix lists {} are not found \n Error: {}".format(tc_name
,input_dict
, result
)
1721 "Configure IPv4 and IPv6 route-map ( RMv4 and RMv6 ) matching prefix-list (Pv4 and Pv6 ) respectively on R3"
1730 "match": {"ipv4": {"prefix_lists": "Pv4"}},
1737 "match": {"ipv6": {"prefix_lists": "Pv6"}},
1743 result
= create_route_maps(tgen
, input_dict_3
)
1744 assert result
is True, "Testcase {} : Failed to configure the route-map \n Error: {}".format(tc_name
, result
)
1746 "Taking the snapshot of the prefix count before configuring the default originate"
1748 snapshot1
= get_prefix_count_route(tgen
, topo
, dut
="r2", peer
="r3")
1750 "Configure default-originate with IPv4 and IPv6 route-map (RMv4 and RMv6) on R3"
1752 local_as
= get_dut_as_number(tgen
, dut
="r3")
1753 default_originate_config
= {
1756 "local_as": local_as
,
1759 "unicast": {"default_originate": {"r2": {"route_map": "RMv4"}}}
1762 "unicast": {"default_originate": {"r2": {"route_map": "RMv6"}}}
1768 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
1769 assert result
is True, "Testcase {} : Failed to configure default-originate \n Error: {}".format(tc_name
, result
)
1771 step("Verify the default route is NOT received in BGP RIB and FIB on R2 ")
1773 "After configuring default-originate command , verify default routes are not Received on R2 "
1775 for addr_type
in ADDR_TYPES
:
1776 static_routes_input
= {
1780 "network": [DEFAULT_ROUTES
[addr_type
]],
1781 "next_hop": DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
1787 result
= verify_fib_routes(
1791 static_routes_input
,
1792 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
1797 ), "Testcase {} : Failed \n Default route is not expected due to deny in prefix list \nError: {}".format(
1801 result
= verify_bgp_rib(
1805 static_routes_input
,
1806 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
1811 ), "Testcase {} : Failed \nDefault route is not expected due to deny in prefix list\n Error: {}".format(
1815 step("Add route Sv41, Sv42, IPv6 route Sv61 Sv62 on prefix list Pv4 and Pv6")
1823 "network": NETWORK1_1
["ipv4"],
1828 "network": NETWORK2_1
["ipv4"],
1837 "network": NETWORK1_1
["ipv6"],
1842 "network": NETWORK2_1
["ipv6"],
1850 result
= create_prefix_lists(tgen
, input_dict_3
)
1851 assert result
is True, "Testcase {} : Failed to configure the prefix lists Error: {}".format(tc_name
, result
)
1853 step("Verify BGP default route for IPv4 and IPv6 is received on R2")
1855 for addr_type
in ADDR_TYPES
:
1856 static_routes_input
= {
1860 "network": [DEFAULT_ROUTES
[addr_type
]],
1861 "next_hop": DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
1867 result
= verify_fib_routes(
1871 static_routes_input
,
1872 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
1874 assert result
is True, "Testcase {} : Failed Default routes are expected in R2 FIB from R3 but not found ....! \n Error: {}".format(
1878 result
= verify_bgp_rib(
1882 static_routes_input
,
1883 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
1885 assert result
is True, "Testcase {} : Failed Default routes are expected in R2 RIB from R3 but not found ....! \n Error: {}".format(
1889 step("Remove route Sv41, Sv42, IPv6 route Sv61 Sv62 on prefix list Pv4 and Pv6")
1897 "network": NETWORK1_1
["ipv4"],
1903 "network": NETWORK2_1
["ipv4"],
1913 "network": NETWORK1_1
["ipv6"],
1919 "network": NETWORK2_1
["ipv6"],
1928 result
= create_prefix_lists(tgen
, input_dict_3
)
1929 assert result
is True, "Testcase {} : Failed to remove prefix-lists from R3 Error: {}".format(tc_name
, result
)
1932 "After Removing route BGP default route for IPv4 and IPv6 is NOT received on R2"
1934 for addr_type
in ADDR_TYPES
:
1935 static_routes_input
= {
1939 "network": [DEFAULT_ROUTES
[addr_type
]],
1940 "next_hop": DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
1946 result
= verify_fib_routes(
1950 static_routes_input
,
1951 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
1956 ), "Testcase {} : Failed \n After Removing route in prefix list the default route is not expected in FIB \n Error: {}".format(
1960 result
= verify_bgp_rib(
1964 static_routes_input
,
1965 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
1970 ), "Testcase {} : Failed \n After Removing route in prefix list the default route is not expected in RIB\n Error: {}".format(
1974 step(" Add route Sv41, Sv42, IPv6 route Sv61 Sv62 on prefix list Pv4 and Pv6")
1982 "network": NETWORK1_1
["ipv4"],
1987 "network": NETWORK2_1
["ipv4"],
1996 "network": NETWORK1_1
["ipv6"],
2001 "network": NETWORK2_1
["ipv6"],
2009 result
= create_prefix_lists(tgen
, input_dict_3
)
2010 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
2012 step("Verify BGP default route for IPv4 and IPv6 is received on R2")
2014 for addr_type
in ADDR_TYPES
:
2015 static_routes_input
= {
2019 "network": [DEFAULT_ROUTES
[addr_type
]],
2020 "next_hop": DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2026 result
= verify_fib_routes(
2030 static_routes_input
,
2031 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2033 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2037 result
= verify_bgp_rib(
2041 static_routes_input
,
2042 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2044 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2048 step("Change IPv4 and IPv6 prefix-list permit and deny ")
2054 {"seqid": "1", "network": NETWORK1_1
["ipv4"], "action": "deny"},
2055 {"seqid": "2", "network": NETWORK2_1
["ipv4"], "action": "deny"},
2060 {"seqid": "1", "network": NETWORK1_1
["ipv6"], "action": "deny"},
2061 {"seqid": "2", "network": NETWORK2_1
["ipv6"], "action": "deny"},
2067 result
= create_prefix_lists(tgen
, input_dict_3
)
2068 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
2070 step("Verify BGP default route for IPv4 and IPv6 is not received on R2")
2072 for addr_type
in ADDR_TYPES
:
2073 static_routes_input
= {
2077 "network": [DEFAULT_ROUTES
[addr_type
]],
2078 "next_hop": DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2084 result
= verify_fib_routes(
2088 static_routes_input
,
2089 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2094 ), "Testcase {} : Failed \n after denying the prefix list default route is not expected in FIB \n Error: {}".format(
2098 result
= verify_bgp_rib(
2102 static_routes_input
,
2103 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2108 ), "Testcase {} : Failed \n after denying the prefix list default route is not expected in RIB \n Error: {}".format(
2112 step("Change IPv4 and IPv6 prefix-list deny to permit ")
2120 "network": NETWORK1_1
["ipv4"],
2125 "network": NETWORK2_1
["ipv4"],
2134 "network": NETWORK1_1
["ipv6"],
2139 "network": NETWORK2_1
["ipv6"],
2147 result
= create_prefix_lists(tgen
, input_dict_3
)
2148 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
2150 step("Verify BGP default route for IPv4 and IPv6 is received on R2")
2151 for addr_type
in ADDR_TYPES
:
2152 static_routes_input
= {
2156 "network": [DEFAULT_ROUTES
[addr_type
]],
2157 "next_hop": DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2163 result
= verify_fib_routes(
2167 static_routes_input
,
2168 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2170 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2174 result
= verify_bgp_rib(
2178 static_routes_input
,
2179 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2181 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2186 "Taking the snapshot2 of the prefix count after configuring the default originate"
2188 snapshot2
= get_prefix_count_route(tgen
, topo
, dut
="r2", peer
="r3")
2190 step("verifying the prefix count incrementing or not ")
2191 isIPv4prefix_incremented
= False
2192 isIPv6prefix_incremented
= False
2193 if snapshot1
["ipv4_count"] < snapshot2
["ipv4_count"]:
2194 isIPv4prefix_incremented
= True
2195 if snapshot1
["ipv6_count"] < snapshot2
["ipv6_count"]:
2196 isIPv6prefix_incremented
= True
2199 isIPv4prefix_incremented
is True
2200 ), "Testcase {} : Failed Error: IPV4 Prefix is not incremented on receiveing ".format(
2205 isIPv6prefix_incremented
is True
2206 ), "Testcase {} : Failed Error: IPV6 Prefix is not incremented on receiveing ".format(
2211 "Configure another IPv4 and IPv6 route-map and match same prefix-list (Sv41, Sv42, IPv6 route Sv61 Sv62) with deny statement "
2220 "match": {"ipv4": {"prefix_lists": "Pv4"}},
2227 "match": {"ipv6": {"prefix_lists": "Pv6"}},
2233 result
= create_route_maps(tgen
, input_dict_3
)
2234 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2236 step("Attach route-map on IPv4 and IP6 BGP neighbor on fly")
2237 local_as
= get_dut_as_number(tgen
, dut
="r3")
2238 default_originate_config
= {
2241 "local_as": local_as
,
2244 "unicast": {"default_originate": {"r2": {"route_map": "RMv41"}}}
2247 "unicast": {"default_originate": {"r2": {"route_map": "RMv61"}}}
2253 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
2254 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2257 "After attaching route-map verify IPv4 and IPv6 default route is withdrawn from the R2"
2259 for addr_type
in ADDR_TYPES
:
2260 static_routes_input
= {
2264 "network": [DEFAULT_ROUTES
[addr_type
]],
2265 "next_hop": DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2271 result
= verify_fib_routes(
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 result
= verify_bgp_rib(
2287 static_routes_input
,
2288 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2291 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
2295 step("Change the recently added Routemap from deny to permit")
2303 "match": {"ipv4": {"prefix_lists": "Pv4"}},
2310 "match": {"ipv6": {"prefix_lists": "Pv6"}},
2316 result
= create_route_maps(tgen
, input_dict_3
)
2317 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2319 step("Verify IPv4 and IPv6 default route is advertised from the R2")
2320 for addr_type
in ADDR_TYPES
:
2321 static_routes_input
= {
2325 "network": [DEFAULT_ROUTES
[addr_type
]],
2326 "next_hop": DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2332 result
= verify_fib_routes(
2336 static_routes_input
,
2337 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2339 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2343 result
= verify_bgp_rib(
2347 static_routes_input
,
2348 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2350 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2355 "Delete default-originate route-map command while configuring ( neighbor x.x.x default-originate) for IPv4 and IPv6 BGP neighbor "
2357 """ Configuring the Default originate on neighbor must remove the previously assigned deault-originate with routemap config """
2358 local_as
= get_dut_as_number(tgen
, dut
="r3")
2359 default_originate_config
= {
2362 "local_as": local_as
,
2364 "ipv4": {"unicast": {"default_originate": {"r2": {}}}},
2365 "ipv6": {"unicast": {"default_originate": {"r2": {}}}},
2370 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
2371 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2374 "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"
2376 for addr_type
in ADDR_TYPES
:
2377 static_routes_input
= {
2381 "network": [DEFAULT_ROUTES
[addr_type
]],
2382 "next_hop": DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2388 result
= verify_fib_routes(
2392 static_routes_input
,
2393 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2395 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2399 result
= verify_bgp_rib(
2403 static_routes_input
,
2404 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2406 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2411 "Configure default-originate with conditional route-map command on IPv4 and IPv6 address family "
2413 local_as
= get_dut_as_number(tgen
, dut
="r3")
2414 default_originate_config
= {
2417 "local_as": local_as
,
2420 "unicast": {"default_originate": {"r2": {"route_map": "RMv41"}}}
2423 "unicast": {"default_originate": {"r2": {"route_map": "RMv61"}}}
2429 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
2430 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2433 "Verify in running config from BGP that default-originate with route-map command is present and default route for IPv4 and IPv6 present"
2435 for addr_type
in ADDR_TYPES
:
2436 static_routes_input
= {
2440 "network": [DEFAULT_ROUTES
[addr_type
]],
2441 "next_hop": DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2447 result
= verify_fib_routes(
2451 static_routes_input
,
2452 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2454 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2458 result
= verify_bgp_rib(
2462 static_routes_input
,
2463 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2465 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2470 "Delete default originate with 'no bgp default-originate' from IPV4 and IPV6 address family "
2472 local_as
= get_dut_as_number(tgen
, dut
="r3")
2473 default_originate_config
= {
2476 "local_as": local_as
,
2479 "unicast": {"default_originate": {"r2": {"delete": True}}}
2482 "unicast": {"default_originate": {"r2": {"delete": True}}}
2488 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
2489 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2492 " 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"
2494 for addr_type
in ADDR_TYPES
:
2495 static_routes_input
= {
2499 "network": [DEFAULT_ROUTES
[addr_type
]],
2500 "next_hop": DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2506 result
= verify_fib_routes(
2510 static_routes_input
,
2511 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2516 ), "Testcase {} : Failed \n Default Route is not expected in FIB \nError: {}".format(
2520 result
= verify_bgp_rib(
2524 static_routes_input
,
2525 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
2530 ), "Testcase {} : Failed \n Default Route is not expected in RIB\nError: {}".format(
2534 write_test_footer(tc_name
)
2537 if __name__
== "__main__":
2538 args
= ["-s"] + sys
.argv
[1:]
2539 sys
.exit(pytest
.main(args
))