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")
13 from time
import sleep
14 from copy
import deepcopy
15 from lib
.topolog
import logger
17 # pylint: disable=C0413
18 # Import topogen and topotest helpers
19 from lib
.topogen
import Topogen
, get_topogen
20 from lib
.topojson
import build_config_from_json
21 from lib
.topolog
import logger
24 verify_bgp_convergence
,
25 verify_graceful_restart
,
33 get_prefix_count_route
,
35 verify_rib_default_route
,
36 verify_fib_default_route
,
37 verify_bgp_advertised_routes_from_neighbor
,
38 verify_bgp_received_routes_from_neighbor
,
40 from lib
.common_config
import (
46 shutdown_bringup_interface
,
48 required_linux_kernel_version
,
53 get_frr_ipv6_linklocal
,
58 reset_config_on_routers
,
64 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.staticd
]
66 # Save the Current Working Directory to find configuration files.
67 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
68 sys
.path
.append(os
.path
.join(CWD
, "../"))
69 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
71 # Required to instantiate the topology builder class.
72 # pylint: disable=C0413
73 # Import topogen and topotest helpers
82 NETWORK1_1
= {"ipv4": "198.51.1.1/32", "ipv6": "2001:DB8::1:1/128"}
83 NETWORK2_1
= {"ipv4": "198.51.1.2/32", "ipv6": "2001:DB8::1:2/128"}
84 NETWORK5_1
= {"ipv4": "198.51.1.3/32", "ipv6": "2001:DB8::1:3/128"}
85 NETWORK5_2
= {"ipv4": "198.51.1.4/32", "ipv6": "2001:DB8::1:4/128"}
86 NEXT_HOP_IP
= {"ipv4": "Null0", "ipv6": "Null0"}
89 r0_connected_address_ipv4
= "192.168.0.0/24"
90 r0_connected_address_ipv6
= "fd00::/64"
91 r1_connected_address_ipv4
= "192.168.1.0/24"
92 r1_connected_address_ipv6
= "fd00:0:0:1::/64"
93 r3_connected_address_ipv4
= "192.168.2.0/24"
94 r3_connected_address_ipv6
= "fd00:0:0:2::/64"
95 r4_connected_address_ipv4
= "192.168.3.0/24"
96 r4_connected_address_ipv6
= "fd00:0:0:3::/64"
99 def setup_module(mod
):
101 Sets up the pytest environment
106 # Required linux kernel version for this suite to run.
107 result
= required_linux_kernel_version("4.15")
108 if result
is not True:
109 pytest
.skip("Kernel requirements are not met")
111 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
112 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
113 logger
.info("=" * 40)
115 logger
.info("Running setup_module to create topology")
117 # This function initiates the topology build with Topogen...
118 json_file
= "{}/bgp_default_orginate_vrf.json".format(CWD
)
119 tgen
= Topogen(json_file
, mod
.__name
__)
121 topo
= tgen
.json_topo
122 # ... and here it calls Mininet initialization functions.
124 # Starting topology, create tmp files which are loaded to routers
125 # to start daemons and then start routers
128 # Creating configuration from JSON
129 build_config_from_json(tgen
, topo
)
132 global BGP_CONVERGENCE
133 global DEFAULT_ROUTES
134 global DEFAULT_ROUTE_NXT_HOP_R1
, DEFAULT_ROUTE_NXT_HOP_R3
135 global R1_NETWORK_LOOPBACK
, R1_NETWORK_LOOPBACK_NXTHOP
136 global R0_NETWORK_CONNECTED_NXTHOP
, R1_NETWORK_CONNECTED
, R1_NETWORK_CONNECTED_NXTHOP
137 global R3_NETWORK_LOOPBACK
, R3_NETWORK_LOOPBACK_NXTHOP
138 global R3_NETWORK_CONNECTED
, R3_NETWORK_CONNECTED_NXTHOP
140 ADDR_TYPES
= check_address_types()
141 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
142 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
145 # There are the global varibles used through out the file these are acheived only after building the topology.
147 r0_loopback_address_ipv4
= topo
["routers"]["r0"]["links"]["lo"]["ipv4"]
148 r0_loopback_address_ipv4_nxt_hop
= topo
["routers"]["r0"]["links"]["r1"][
151 r0_loopback_address_ipv6
= topo
["routers"]["r0"]["links"]["lo"]["ipv6"]
152 r0_loopback_address_ipv6_nxt_hop
= topo
["routers"]["r0"]["links"]["r1"][
156 r1_loopback_address_ipv4
= topo
["routers"]["r1"]["links"]["lo"]["ipv4"]
157 r1_loopback_address_ipv4_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"][
160 r1_loopback_address_ipv6
= topo
["routers"]["r1"]["links"]["lo"]["ipv6"]
161 r1_loopback_address_ipv6_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"][
165 r4_loopback_address_ipv4
= topo
["routers"]["r4"]["links"]["lo"]["ipv4"]
166 r4_loopback_address_ipv4_nxt_hop
= topo
["routers"]["r4"]["links"]["r3"][
169 r4_loopback_address_ipv6
= topo
["routers"]["r4"]["links"]["lo"]["ipv6"]
170 r4_loopback_address_ipv6_nxt_hop
= topo
["routers"]["r4"]["links"]["r3"][
174 r3_loopback_address_ipv4
= topo
["routers"]["r3"]["links"]["lo"]["ipv4"]
175 r3_loopback_address_ipv4_nxt_hop
= topo
["routers"]["r3"]["links"]["r2"][
178 r3_loopback_address_ipv6
= topo
["routers"]["r3"]["links"]["lo"]["ipv6"]
179 r3_loopback_address_ipv6_nxt_hop
= topo
["routers"]["r3"]["links"]["r2"][
183 R1_NETWORK_LOOPBACK
= {
184 "ipv4": r1_loopback_address_ipv4
,
185 "ipv6": r1_loopback_address_ipv6
,
187 R1_NETWORK_LOOPBACK_NXTHOP
= {
188 "ipv4": r1_loopback_address_ipv4_nxt_hop
,
189 "ipv6": r1_loopback_address_ipv6_nxt_hop
,
192 R1_NETWORK_CONNECTED
= {
193 "ipv4": r1_connected_address_ipv4
,
194 "ipv6": r1_connected_address_ipv6
,
196 R1_NETWORK_CONNECTED_NXTHOP
= {
197 "ipv4": r1_loopback_address_ipv4_nxt_hop
,
198 "ipv6": r1_loopback_address_ipv6_nxt_hop
,
201 R3_NETWORK_LOOPBACK
= {
202 "ipv4": r3_loopback_address_ipv4
,
203 "ipv6": r3_loopback_address_ipv6
,
205 R3_NETWORK_LOOPBACK_NXTHOP
= {
206 "ipv4": r3_loopback_address_ipv4_nxt_hop
,
207 "ipv6": r3_loopback_address_ipv6_nxt_hop
,
210 R3_NETWORK_CONNECTED
= {
211 "ipv4": r3_connected_address_ipv4
,
212 "ipv6": r3_connected_address_ipv6
,
214 R3_NETWORK_CONNECTED_NXTHOP
= {
215 "ipv4": r3_loopback_address_ipv4_nxt_hop
,
216 "ipv6": r3_loopback_address_ipv6_nxt_hop
,
219 # populating the nexthop for default routes
221 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
223 interface
= topo
["routers"]["r1"]["links"]["r2"]["interface"]
224 ipv6_link_local
= get_frr_ipv6_linklocal(tgen
, "r1", intf
=interface
)
225 ipv4_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"]["ipv4"].split("/")[0]
226 ipv6_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"]["ipv6"].split("/")[0]
227 DEFAULT_ROUTE_NXT_HOP_R1
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local
}
229 interface
= topo
["routers"]["r3"]["links"]["r2"]["interface"]
230 ipv6_link_local
= get_frr_ipv6_linklocal(tgen
, "r3", intf
=interface
)
231 ipv4_nxt_hop
= topo
["routers"]["r3"]["links"]["r2"]["ipv4"].split("/")[0]
232 ipv6_nxt_hop
= topo
["routers"]["r3"]["links"]["r2"]["ipv6"].split("/")[0]
233 DEFAULT_ROUTE_NXT_HOP_R3
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local
}
235 logger
.info("Running setup_module() done")
238 def teardown_module():
239 """Teardown the pytest environment"""
241 logger
.info("Running teardown_module to delete topology")
245 # Stop toplogy and Remove tmp files
249 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
251 logger
.info("=" * 40)
254 #####################################################
258 #####################################################
259 def test_verify_default_originate_route_with_non_default_VRF_p1(request
):
261 "Verify default-originate route with non-default VRF"
264 global BGP_CONVERGENCE
266 if BGP_CONVERGENCE
!= True:
267 pytest
.skip("skipped because of BGP Convergence failure")
269 tc_name
= request
.node
.name
270 write_test_header(tc_name
)
271 if tgen
.routers_have_failure():
272 check_router_status(tgen
)
273 reset_config_on_routers(tgen
)
275 # these steps are implemented as base toplopgy setup
276 step("Configure IPV4 and IPV6 IBGP between R1 and R2 default VRF")
277 step("Configure IPV4 and IPV6 EBGP between R2 to R3 non-default VRF (RED)")
279 "Configure IPv4 and IP6 loopback address on R1 default and R3 non-default (RED) VRF"
281 step("After changing the BGP AS Path Verify the BGP Convergence")
283 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
284 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
288 "Configure IPv4 and IPv6 static route on R1 default and R3 non-default (RED) VRF with nexthop as Null ( different static route on each side)"
290 for addr_type
in ADDR_TYPES
:
291 static_routes_input
= {
295 "network": [NETWORK1_1
[addr_type
]],
296 "next_hop": NEXT_HOP_IP
[addr_type
],
301 result
= create_static_routes(tgen
, static_routes_input
)
304 ), "Testcase {} : Failed to configure the static routes in router R1 default vrf \n Error: {}".format(
308 for addr_type
in ADDR_TYPES
:
309 static_routes_input
= {
313 "network": [NETWORK2_1
[addr_type
]],
314 "next_hop": NEXT_HOP_IP
[addr_type
],
320 result
= create_static_routes(tgen
, static_routes_input
)
323 ), "Testcase {} : Failed to configure static route in R3 non default vrf RED \n Error: {}".format(
328 "Verify IPv4 and IPv6 static route configured on R1 default vrf and R3 non-default (RED) vrf"
330 for addr_type
in ADDR_TYPES
:
331 static_routes_input
= {
335 "network": [NETWORK1_1
[addr_type
]],
336 "next_hop": NEXT_HOP_IP
[addr_type
],
341 result
= verify_rib(tgen
, addr_type
, "r1", static_routes_input
)
344 ), "Testcase {} : Failed: Routes configured on vrf is not seen in R1 default VRF FIB \n Error: {}".format(
348 for addr_type
in ADDR_TYPES
:
349 static_routes_input
= {
353 "network": [NETWORK2_1
[addr_type
]],
354 "next_hop": NEXT_HOP_IP
[addr_type
],
360 result
= verify_rib(tgen
, addr_type
, "r3", static_routes_input
)
363 ), "Testcase {} : Failed : Routes configured in non-defaul vrf in R3 FIB is \n Error: {}".format(
368 "Configure redistribute connected and static on R1 (R1-R2) and on R3 ( R2-R3 RED VRF) IPv4 and IPv6 address family "
370 redistribute_static
= {
377 {"redist_type": "static"},
378 {"redist_type": "connected"},
385 {"redist_type": "static"},
386 {"redist_type": "connected"},
401 {"redist_type": "static"},
402 {"redist_type": "connected"},
409 {"redist_type": "static"},
410 {"redist_type": "connected"},
418 result
= create_router_bgp(tgen
, topo
, redistribute_static
)
421 ), "Testcase {} : Failed to configure the redistribute on R1 and R3 \n Error: {}".format(
426 "Verify IPv4 and IPv6 static route configured on R1 received as BGP routes on R2 default VRF "
428 for addr_type
in ADDR_TYPES
:
429 static_routes_input
= {
433 "network": [NETWORK1_1
[addr_type
]],
434 "next_hop": NEXT_HOP_IP
[addr_type
],
437 "network": [R1_NETWORK_LOOPBACK
[addr_type
]],
438 "next_hop": R1_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
441 "network": [R1_NETWORK_CONNECTED
[addr_type
]],
442 "next_hop": R1_NETWORK_CONNECTED_NXTHOP
[addr_type
],
447 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
448 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
452 "Verify IPv4 and IPv6 static route configured on R3 received as BGP routes on R2 non-default VRF "
454 for addr_type
in ADDR_TYPES
:
455 static_routes_input
= {
459 "network": [NETWORK2_1
[addr_type
]],
460 "next_hop": NEXT_HOP_IP
[addr_type
],
464 "network": [R3_NETWORK_CONNECTED
[addr_type
]],
465 "next_hop": R3_NETWORK_CONNECTED_NXTHOP
[addr_type
],
471 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
472 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
477 "Configure default-originate on R1 for R1 to R2 neighbor for IPv4 and IPv6 peer"
479 local_as
= get_dut_as_number(tgen
, dut
="r1")
480 default_originate_config
= {
483 "local_as": local_as
,
485 "ipv4": {"unicast": {"default_originate": {"r2": {}}}},
486 "ipv6": {"unicast": {"default_originate": {"r2": {}}}},
491 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
494 ), "Testcase {} : Failed to configure the default originate \n Error: {}".format(
499 "After configuring default-originate command , verify default routes are advertised on R2 "
501 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
502 for addr_type
in ADDR_TYPES
:
503 static_routes_input
= {
507 "network": [DEFAULT_ROUTES
[addr_type
]],
508 "next_hop": DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
519 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
521 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
525 result
= verify_bgp_rib(
530 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
532 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
536 for addr_type
in ADDR_TYPES
:
537 static_routes_input
= {
541 "network": [NETWORK1_1
[addr_type
]],
542 "next_hop": NEXT_HOP_IP
[addr_type
],
545 "network": [R1_NETWORK_LOOPBACK
[addr_type
]],
546 "next_hop": R1_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
549 "network": [R1_NETWORK_CONNECTED
[addr_type
]],
550 "next_hop": R1_NETWORK_CONNECTED_NXTHOP
[addr_type
],
556 result
= verify_bgp_rib(
561 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
563 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
572 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
574 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
578 snapshot1
= get_prefix_count_route(tgen
, topo
, dut
="r2", peer
="r3", vrf
="RED")
581 "Configure default-originate on R3 for R3 to R2 neighbor (RED VRF) for IPv4 and IPv6 peer"
584 default_originate_config
= {
590 "ipv4": {"unicast": {"default_originate": {"r2": {}}}},
591 "ipv6": {"unicast": {"default_originate": {"r2": {}}}},
596 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
597 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
600 "Verify IPv4 and IPv6 bgp default route and static route received on R2 VRF red nexthop as R3"
602 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
603 for addr_type
in ADDR_TYPES
:
604 static_routes_input
= {
608 "network": [NETWORK2_1
[addr_type
]],
609 "next_hop": NEXT_HOP_IP
[addr_type
],
613 "network": [DEFAULT_ROUTES
[addr_type
]],
614 "next_hop": DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
625 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
627 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
630 result
= verify_bgp_rib(
635 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
637 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
641 step("verify Out-prefix count incremented for IPv4/IPv6 default route on VRF red")
642 snapshot2
= get_prefix_count_route(tgen
, topo
, dut
="r2", peer
="r3", vrf
="RED")
643 step("verifying the prefix count incrementing or not ")
644 isIPv4prefix_incremented
= False
645 isIPv6prefix_incremented
= False
646 if snapshot1
["ipv4_count"] < snapshot2
["ipv4_count"]:
647 isIPv4prefix_incremented
= True
648 if snapshot1
["ipv6_count"] < snapshot2
["ipv6_count"]:
649 isIPv6prefix_incremented
= True
652 isIPv4prefix_incremented
is True
653 ), "Testcase {} : Failed Error: IPV4 Prefix is not incremented on receiveing ".format(
657 step("Configure import VRF red on R2 for IPV4 and IPV6 BGP peer")
658 step("Importing the non-default vrf in default VRF ")
659 local_as
= get_dut_as_number(tgen
, "r2")
664 "local_as": local_as
,
666 "ipv4": {"unicast": {"import": {"vrf": "RED"}}},
667 "ipv6": {"unicast": {"import": {"vrf": "RED"}}},
673 result
= create_router_bgp(tgen
, topo
, input_import_vrf
)
674 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
676 "Verify VRF RED IPv4 and IPv6, default-originate, \n static and loopback route are imported to R2 default VRF table ,\n default-originate route coming from VRF red should not active on R2 default VRF table"
678 step("verifying the static routes connected and loop back routes")
679 for addr_type
in ADDR_TYPES
:
680 static_routes_input
= {
684 "network": [NETWORK1_1
[addr_type
]],
685 "next_hop": NEXT_HOP_IP
[addr_type
],
688 "network": [NETWORK2_1
[addr_type
]],
689 "next_hop": NEXT_HOP_IP
[addr_type
],
692 "network": [R1_NETWORK_LOOPBACK
[addr_type
]],
693 "next_hop": R1_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
696 "network": [R1_NETWORK_CONNECTED
[addr_type
]],
697 "next_hop": R1_NETWORK_CONNECTED_NXTHOP
[addr_type
],
700 "network": [R3_NETWORK_CONNECTED
[addr_type
]],
701 "next_hop": R3_NETWORK_CONNECTED_NXTHOP
[addr_type
],
707 result
= verify_rib(tgen
, addr_type
, "r2", static_routes_input
)
708 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
712 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
713 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
717 STEP
= """ After importing non defualt VRF into default vrf .
718 verify that the default originate from R1 --> R2(non -default) is preffered over R3 --> R2
719 because the Default Route prefers iBGP over eBGP over
720 Default Route from R1 Should be present in BGP RIB and FIB
721 Default Route from R3 Should be present only in BGP RIB not in FIB
724 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
725 for addr_type
in ADDR_TYPES
:
726 static_routes_input
= {
730 "network": [DEFAULT_ROUTES
[addr_type
]],
731 "next_hop": DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
737 result
= verify_rib(tgen
, addr_type
, "r2", static_routes_input
)
738 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
742 static_routes_input
= {
746 "network": [DEFAULT_ROUTES
[addr_type
]],
747 "next_hop": DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
750 "network": [DEFAULT_ROUTES
[addr_type
]],
751 "next_hop": DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
757 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
758 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
762 "Configure import VRF default on R2 (R2-R3) RED VRF for IPV4 and IPV6 BGP peer"
764 step("Importing the default vrf in non-default VRF ")
770 "local_as": local_as
,
773 "ipv4": {"unicast": {"import": {"vrf": "default"}}},
774 "ipv6": {"unicast": {"import": {"vrf": "default"}}},
780 result
= create_router_bgp(tgen
, topo
, input_import_vrf
)
781 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
783 "Default VR, IPv4 and IPv6 , default-originate, \n static and loopback route are imported to R2 VRF RED table \n, default-originate route coming from VRF red should not active on R2 default VRF table"
785 for addr_type
in ADDR_TYPES
:
786 static_routes_input
= {
790 "network": [NETWORK1_1
[addr_type
]],
791 "next_hop": NEXT_HOP_IP
[addr_type
],
795 "network": [NETWORK2_1
[addr_type
]],
796 "next_hop": NEXT_HOP_IP
[addr_type
],
800 "network": [R1_NETWORK_LOOPBACK
[addr_type
]],
801 "next_hop": R1_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
805 "network": [R1_NETWORK_CONNECTED
[addr_type
]],
806 "next_hop": R1_NETWORK_CONNECTED_NXTHOP
[addr_type
],
810 "network": [R3_NETWORK_CONNECTED
[addr_type
]],
811 "next_hop": R3_NETWORK_CONNECTED_NXTHOP
[addr_type
],
818 result
= verify_rib(tgen
, addr_type
, "r2", static_routes_input
)
819 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
823 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
824 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
828 STEP
= """ After importing defualt VRF into non default vrf .
829 verify that the default originate from R1 --> R2(non -default) is preffered over R3 --> R2
830 because the Default Route prefers iBGP over eBGP over
831 Default Route from R1 Should be present in BGP RIB and FIB
832 Default Route from R3 Should be present only in BGP RIB not in FIB
835 for addr_type
in ADDR_TYPES
:
836 static_routes_input
= {
840 "network": [DEFAULT_ROUTES
[addr_type
]],
841 "next_hop": DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
853 next_hop
=DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
855 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
859 static_routes_input
= {
863 "network": [DEFAULT_ROUTES
[addr_type
]],
864 "next_hop": DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
876 next_hop
=DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
879 assert result
is not True, "Testcase {} : Failed {} \n Error: {}".format(
880 tc_name
, STEP
, result
883 static_routes_input
= {
887 "network": [DEFAULT_ROUTES
[addr_type
]],
888 "next_hop": DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
892 "network": [DEFAULT_ROUTES
[addr_type
]],
893 "next_hop": DEFAULT_ROUTE_NXT_HOP_R3
[addr_type
],
900 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
901 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
906 "Remove import VRF configure in step 8 and then remove import VRF configured on step 9"
908 local_as
= get_dut_as_number(tgen
, "r2")
913 "local_as": local_as
,
915 "ipv4": {"unicast": {"import": {"vrf": "RED", "delete": True}}},
916 "ipv6": {"unicast": {"import": {"vrf": "RED", "delete": True}}},
922 result
= create_router_bgp(tgen
, topo
, input_import_vrf
)
923 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
925 step("Verify that the routes imported from non default VRF - RED is removed")
926 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
928 for addr_type
in ADDR_TYPES
:
929 static_routes_input
= {
933 "network": [NETWORK2_1
[addr_type
]],
934 "next_hop": NEXT_HOP_IP
[addr_type
],
937 "network": [R3_NETWORK_LOOPBACK
[addr_type
]],
938 "next_hop": R3_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
941 "network": [R3_NETWORK_CONNECTED
[addr_type
]],
942 "next_hop": R3_NETWORK_CONNECTED_NXTHOP
[addr_type
],
948 result
= verify_rib(tgen
, addr_type
, "r2", static_routes_input
, expected
=False)
951 ), "Testcase {} : Failed \n routes imported from non default VRF is not expected Error: {}".format(
955 result
= verify_bgp_rib(
956 tgen
, addr_type
, "r2", static_routes_input
, expected
=False
960 ), "Testcase {} : Failed \n routes imported from non default VRF is not expected \nError: {}".format(
965 "Remove import VRF configure in step 8 and then remove import VRF configured on step 9"
972 "local_as": local_as
,
976 "unicast": {"import": {"vrf": "default", "delete": True}}
979 "unicast": {"import": {"vrf": "default", "delete": True}}
986 result
= create_router_bgp(tgen
, topo
, input_import_vrf
)
987 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
988 step("Verify that the routes impoted from default VRF is removed")
989 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
991 for addr_type
in ADDR_TYPES
:
992 static_routes_input
= {
996 "network": [NETWORK1_1
[addr_type
]],
997 "next_hop": NEXT_HOP_IP
[addr_type
],
1001 "network": [R1_NETWORK_LOOPBACK
[addr_type
]],
1002 "next_hop": R1_NETWORK_LOOPBACK_NXTHOP
[addr_type
],
1006 "network": [R1_NETWORK_CONNECTED
[addr_type
]],
1007 "next_hop": R1_NETWORK_CONNECTED_NXTHOP
[addr_type
],
1014 result
= verify_rib(tgen
, addr_type
, "r2", static_routes_input
, expected
=False)
1017 ), "Testcase {} : Failed \n routes impoted from default VRF is not expected \n Error: {}".format(
1021 result
= verify_bgp_rib(
1022 tgen
, addr_type
, "r2", static_routes_input
, expected
=False
1026 ), "Testcase {} : Failed \n routes impoted from default VRF is not expected \n Error: {}".format(
1030 write_test_footer(tc_name
)
1033 def test_verify_default_originate_route_with_non_default_VRF_with_route_map_p1(request
):
1035 "Verify default-originate route with non-default VRF with route-map import "
1037 tgen
= get_topogen()
1038 global BGP_CONVERGENCE
1040 if BGP_CONVERGENCE
!= True:
1041 pytest
.skip("skipped because of BGP Convergence failure")
1043 tc_name
= request
.node
.name
1044 write_test_header(tc_name
)
1045 if tgen
.routers_have_failure():
1046 check_router_status(tgen
)
1047 reset_config_on_routers(tgen
)
1049 step("Configure IPV4 and IPV6 static route on R0 with Null nexthop")
1051 Configure IPV4 and IPV6 EBGP session between R0 and R1
1052 Configure IPV4 and IPV6 static route on R0 with Null nexthop """
1055 "r0": {"bgp": {"local_as": 222, "vrf": "default"}},
1056 "r1": {"bgp": {"local_as": 333, "vrf": "default"}},
1058 result
= modify_as_number(tgen
, topo
, input_dict
)
1059 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1061 assert result
is True
1062 except AssertionError:
1063 logger
.info("Expected behaviour: {}".format(result
))
1064 logger
.info("BGP config is not created because of invalid ASNs")
1065 step("After changing the BGP AS Path Verify the BGP Convergence")
1067 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
1068 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
1072 step("Configuring static route at R0")
1073 for addr_type
in ADDR_TYPES
:
1074 static_routes_input
= {
1078 "network": [NETWORK5_1
[addr_type
]],
1079 "next_hop": NEXT_HOP_IP
[addr_type
],
1084 result
= create_static_routes(tgen
, static_routes_input
)
1085 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1088 step(" Configure re-distribute static on R0 for R0 to R1 for IPV4 and IPV6 peer ")
1089 redistribute_static
= {
1096 {"redist_type": "static"},
1097 {"redist_type": "connected"},
1104 {"redist_type": "static"},
1105 {"redist_type": "connected"},
1113 result
= create_router_bgp(tgen
, topo
, redistribute_static
)
1114 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1117 "Configure default-originate on R1 for R1 to R2 neighbor for IPv4 and IPv6 peer"
1119 local_as
= get_dut_as_number(tgen
, dut
="r1")
1120 default_originate_config
= {
1123 "local_as": local_as
,
1125 "ipv4": {"unicast": {"default_originate": {"r2": {}}}},
1126 "ipv6": {"unicast": {"default_originate": {"r2": {}}}},
1131 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
1132 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1134 snapshot1
= get_prefix_count_route(tgen
, topo
, dut
="r2", peer
="r3", vrf
="RED")
1136 step("Verify IPv4 and IPv6 static received on R2 default VRF as BGP routes")
1137 for addr_type
in ADDR_TYPES
:
1138 static_routes_input
= {
1142 "network": [NETWORK5_1
[addr_type
]],
1143 "next_hop": NEXT_HOP_IP
[addr_type
],
1146 "network": [DEFAULT_ROUTES
[addr_type
]],
1147 "next_hop": DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1153 result
= verify_rib(tgen
, addr_type
, "r2", static_routes_input
)
1154 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1158 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
1159 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1163 " Configure IPv4 and IPv6 prefix-list of of route received from R1 on R2 and for 0.0.0.0/0 0::0/0 route"
1172 "network": NETWORK5_1
["ipv4"],
1175 {"seqid": "2", "network": "0.0.0.0/0", "action": "permit"},
1178 "network": NETWORK2_1
["ipv4"],
1187 "network": NETWORK5_1
["ipv6"],
1190 {"seqid": "2", "network": "0::0/0", "action": "permit"},
1193 "network": NETWORK2_1
["ipv6"],
1201 result
= create_prefix_lists(tgen
, input_dict_3
)
1202 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1204 step("verify IPv4 and IPv6 Prefix list got configured on R3")
1205 input_dict
= {"r2": {"prefix_lists": ["Pv4", "Pv6"]}}
1206 result
= verify_prefix_lists(tgen
, input_dict
)
1207 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1210 "Configure IPv4/IPv6 route-map on R2 with deny sequence using above prefix-list"
1219 "match": {"ipv4": {"prefix_lists": "Pv4"}},
1226 "match": {"ipv6": {"prefix_lists": "Pv6"}},
1232 result
= create_route_maps(tgen
, input_dict_3
)
1233 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1236 import Route-map anf non-default VRF into defailt vrf
1237 import vrf route-map RM1
1242 local_as
= get_dut_as_number(tgen
, "r2")
1243 input_import_vrf
= {
1247 "local_as": local_as
,
1249 "ipv4": {"unicast": {"import": {"vrf": "RED"}}},
1250 "ipv6": {"unicast": {"import": {"vrf": "RED"}}},
1256 result
= create_router_bgp(tgen
, topo
, input_import_vrf
)
1257 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1259 input_import_vrf
= {
1263 "local_as": local_as
,
1265 "ipv4": {"unicast": {"import": {"vrf": "route-map RMv4"}}},
1266 "ipv6": {"unicast": {"import": {"vrf": "route-map RMv6"}}},
1272 result
= create_router_bgp(tgen
, topo
, input_import_vrf
)
1273 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1275 "Verify IPv4 and IPv6 routes present on VRF red ( static , default-originate) should not get advertised to default VRF "
1277 for addr_type
in ADDR_TYPES
:
1278 static_routes_input
= {
1282 "network": [NETWORK2_1
[addr_type
]],
1283 "next_hop": NEXT_HOP_IP
[addr_type
],
1286 "network": [DEFAULT_ROUTES
[addr_type
]],
1287 "next_hop": DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1293 result
= verify_rib(tgen
, addr_type
, "r2", static_routes_input
, expected
=False)
1296 ), "Testcase {} : Failed \n VRF red ( static , default-originate) should not get advertised to default VRF \n Error: {}".format(
1300 result
= verify_bgp_rib(
1301 tgen
, addr_type
, "r2", static_routes_input
, expected
=False
1305 ), "Testcase {} : Failed \n VRF red ( static , default-originate) should not get advertised to default VRF \nError: {}".format(
1309 step("Change route-map sequence deny to permit")
1317 "match": {"ipv4": {"prefix_lists": "Pv4"}},
1324 "match": {"ipv6": {"prefix_lists": "Pv6"}},
1330 result
= create_route_maps(tgen
, input_dict_3
)
1331 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1334 "IPv4 and IPv6 routes present on VRF red ( static , default-originate) should get advertised to default VRF"
1336 for addr_type
in ADDR_TYPES
:
1337 static_routes_input
= {
1341 "network": [DEFAULT_ROUTES
[addr_type
]],
1342 "next_hop": DEFAULT_ROUTE_NXT_HOP_R1
[addr_type
],
1348 result
= verify_rib(tgen
, addr_type
, "r2", static_routes_input
)
1349 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1353 result
= verify_bgp_rib(tgen
, addr_type
, "r2", static_routes_input
)
1354 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1358 step("verify Out-prefix count incremented for IPv4/IPv6 default route on VRF red")
1359 snapshot2
= get_prefix_count_route(tgen
, topo
, dut
="r2", peer
="r3", vrf
="RED")
1360 step("verifying the prefix count incrementing or not ")
1361 isIPv4prefix_incremented
= False
1362 isIPv6prefix_incremented
= False
1363 if snapshot1
["ipv4_count"] <= snapshot2
["ipv4_count"]:
1364 isIPv4prefix_incremented
= True
1365 if snapshot1
["ipv6_count"] <= snapshot2
["ipv6_count"]:
1366 isIPv6prefix_incremented
= True
1369 isIPv4prefix_incremented
is True
1370 ), "Testcase {} : Failed Error: IPV4 Prefix is not incremented on receiveing ".format(
1375 if __name__
== "__main__":
1376 args
= ["-s"] + sys
.argv
[1:]
1377 sys
.exit(pytest
.main(args
))