]>
Commit | Line | Data |
---|---|---|
034c15b9 | 1 | #!/usr/bin/env python |
47a3a827 | 2 | # SPDX-License-Identifier: ISC |
034c15b9 A |
3 | # |
4 | # Copyright (c) 2022 by VMware, Inc. ("VMware") | |
47a3a827 | 5 | # Shreenidhi A R <rshreenidhi@vmware.com> |
034c15b9 A |
6 | # Used Copyright (c) 2018 by Network Device Education Foundation, Inc. ("NetDEF") |
7 | # in this file. | |
8 | # | |
034c15b9 A |
9 | import os |
10 | import sys | |
11 | import time | |
12 | import pytest | |
13 | from time import sleep | |
14 | from copy import deepcopy | |
15 | from lib.topolog import logger | |
16 | ||
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 | |
22 | ||
23 | from lib.bgp import ( | |
24 | verify_bgp_convergence, | |
25 | verify_graceful_restart, | |
26 | create_router_bgp, | |
27 | verify_router_id, | |
28 | modify_as_number, | |
29 | verify_as_numbers, | |
30 | clear_bgp_and_verify, | |
31 | clear_bgp, | |
32 | verify_bgp_rib, | |
33 | get_prefix_count_route, | |
34 | get_dut_as_number, | |
35 | verify_rib_default_route, | |
36 | verify_fib_default_route, | |
37 | verify_bgp_advertised_routes_from_neighbor, | |
38 | verify_bgp_received_routes_from_neighbor, | |
39 | ) | |
40 | from lib.common_config import ( | |
41 | interface_status, | |
42 | verify_prefix_lists, | |
43 | verify_rib, | |
44 | kill_router_daemons, | |
45 | start_router_daemons, | |
46 | shutdown_bringup_interface, | |
47 | step, | |
48 | required_linux_kernel_version, | |
49 | stop_router, | |
50 | start_router, | |
51 | create_route_maps, | |
52 | create_prefix_lists, | |
53 | get_frr_ipv6_linklocal, | |
54 | start_topology, | |
55 | write_test_header, | |
56 | check_address_types, | |
57 | write_test_footer, | |
58 | reset_config_on_routers, | |
59 | create_static_routes, | |
60 | check_router_status, | |
61 | delete_route_maps, | |
62 | ) | |
63 | ||
cbdecd68 DS |
64 | pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] |
65 | ||
034c15b9 A |
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/")) | |
70 | ||
71 | # Required to instantiate the topology builder class. | |
72 | # pylint: disable=C0413 | |
73 | # Import topogen and topotest helpers | |
74 | ||
75 | # Global variables | |
76 | topo = None | |
77 | KEEPALIVETIMER = 1 | |
78 | HOLDDOWNTIMER = 3 | |
79 | ||
80 | ||
81 | # Global variables | |
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"} | |
87 | ||
88 | ||
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" | |
97 | ||
98 | ||
99 | def setup_module(mod): | |
100 | """ | |
101 | Sets up the pytest environment | |
102 | ||
103 | * `mod`: module name | |
104 | """ | |
105 | ||
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") | |
110 | ||
111 | testsuite_run_time = time.asctime(time.localtime(time.time())) | |
112 | logger.info("Testsuite start time: {}".format(testsuite_run_time)) | |
113 | logger.info("=" * 40) | |
114 | ||
115 | logger.info("Running setup_module to create topology") | |
116 | ||
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__) | |
120 | global topo | |
121 | topo = tgen.json_topo | |
122 | # ... and here it calls Mininet initialization functions. | |
123 | ||
124 | # Starting topology, create tmp files which are loaded to routers | |
125 | # to start daemons and then start routers | |
126 | start_topology(tgen) | |
127 | ||
128 | # Creating configuration from JSON | |
129 | build_config_from_json(tgen, topo) | |
130 | ||
131 | global ADDR_TYPES | |
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 | |
139 | ||
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( | |
143 | BGP_CONVERGENCE | |
144 | ) | |
145 | # There are the global varibles used through out the file these are acheived only after building the topology. | |
146 | ||
147 | r0_loopback_address_ipv4 = topo["routers"]["r0"]["links"]["lo"]["ipv4"] | |
148 | r0_loopback_address_ipv4_nxt_hop = topo["routers"]["r0"]["links"]["r1"][ | |
149 | "ipv4" | |
150 | ].split("/")[0] | |
151 | r0_loopback_address_ipv6 = topo["routers"]["r0"]["links"]["lo"]["ipv6"] | |
152 | r0_loopback_address_ipv6_nxt_hop = topo["routers"]["r0"]["links"]["r1"][ | |
153 | "ipv6" | |
154 | ].split("/")[0] | |
155 | ||
156 | r1_loopback_address_ipv4 = topo["routers"]["r1"]["links"]["lo"]["ipv4"] | |
157 | r1_loopback_address_ipv4_nxt_hop = topo["routers"]["r1"]["links"]["r2"][ | |
158 | "ipv4" | |
159 | ].split("/")[0] | |
160 | r1_loopback_address_ipv6 = topo["routers"]["r1"]["links"]["lo"]["ipv6"] | |
161 | r1_loopback_address_ipv6_nxt_hop = topo["routers"]["r1"]["links"]["r2"][ | |
162 | "ipv6" | |
163 | ].split("/")[0] | |
164 | ||
165 | r4_loopback_address_ipv4 = topo["routers"]["r4"]["links"]["lo"]["ipv4"] | |
166 | r4_loopback_address_ipv4_nxt_hop = topo["routers"]["r4"]["links"]["r3"][ | |
167 | "ipv4" | |
168 | ].split("/")[0] | |
169 | r4_loopback_address_ipv6 = topo["routers"]["r4"]["links"]["lo"]["ipv6"] | |
170 | r4_loopback_address_ipv6_nxt_hop = topo["routers"]["r4"]["links"]["r3"][ | |
171 | "ipv6" | |
172 | ].split("/")[0] | |
173 | ||
174 | r3_loopback_address_ipv4 = topo["routers"]["r3"]["links"]["lo"]["ipv4"] | |
175 | r3_loopback_address_ipv4_nxt_hop = topo["routers"]["r3"]["links"]["r2"][ | |
176 | "ipv4" | |
177 | ].split("/")[0] | |
178 | r3_loopback_address_ipv6 = topo["routers"]["r3"]["links"]["lo"]["ipv6"] | |
179 | r3_loopback_address_ipv6_nxt_hop = topo["routers"]["r3"]["links"]["r2"][ | |
180 | "ipv6" | |
181 | ].split("/")[0] | |
182 | ||
183 | R1_NETWORK_LOOPBACK = { | |
184 | "ipv4": r1_loopback_address_ipv4, | |
185 | "ipv6": r1_loopback_address_ipv6, | |
186 | } | |
187 | R1_NETWORK_LOOPBACK_NXTHOP = { | |
188 | "ipv4": r1_loopback_address_ipv4_nxt_hop, | |
189 | "ipv6": r1_loopback_address_ipv6_nxt_hop, | |
190 | } | |
191 | ||
192 | R1_NETWORK_CONNECTED = { | |
193 | "ipv4": r1_connected_address_ipv4, | |
194 | "ipv6": r1_connected_address_ipv6, | |
195 | } | |
196 | R1_NETWORK_CONNECTED_NXTHOP = { | |
197 | "ipv4": r1_loopback_address_ipv4_nxt_hop, | |
198 | "ipv6": r1_loopback_address_ipv6_nxt_hop, | |
199 | } | |
200 | ||
201 | R3_NETWORK_LOOPBACK = { | |
202 | "ipv4": r3_loopback_address_ipv4, | |
203 | "ipv6": r3_loopback_address_ipv6, | |
204 | } | |
205 | R3_NETWORK_LOOPBACK_NXTHOP = { | |
206 | "ipv4": r3_loopback_address_ipv4_nxt_hop, | |
207 | "ipv6": r3_loopback_address_ipv6_nxt_hop, | |
208 | } | |
209 | ||
210 | R3_NETWORK_CONNECTED = { | |
211 | "ipv4": r3_connected_address_ipv4, | |
212 | "ipv6": r3_connected_address_ipv6, | |
213 | } | |
214 | R3_NETWORK_CONNECTED_NXTHOP = { | |
215 | "ipv4": r3_loopback_address_ipv4_nxt_hop, | |
216 | "ipv6": r3_loopback_address_ipv6_nxt_hop, | |
217 | } | |
218 | ||
219 | # populating the nexthop for default routes | |
220 | ||
221 | DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"} | |
222 | ||
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} | |
228 | ||
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} | |
234 | ||
235 | logger.info("Running setup_module() done") | |
236 | ||
237 | ||
238 | def teardown_module(): | |
239 | """Teardown the pytest environment""" | |
240 | ||
241 | logger.info("Running teardown_module to delete topology") | |
242 | ||
243 | tgen = get_topogen() | |
244 | ||
245 | # Stop toplogy and Remove tmp files | |
246 | tgen.stop_topology() | |
247 | ||
248 | logger.info( | |
249 | "Testsuite end time: {}".format(time.asctime(time.localtime(time.time()))) | |
250 | ) | |
251 | logger.info("=" * 40) | |
252 | ||
253 | ||
254 | ##################################################### | |
255 | # | |
256 | # Testcases | |
257 | # | |
258 | ##################################################### | |
259 | def test_verify_default_originate_route_with_non_default_VRF_p1(request): | |
260 | """ | |
261 | "Verify default-originate route with non-default VRF" | |
262 | """ | |
263 | tgen = get_topogen() | |
264 | global BGP_CONVERGENCE | |
265 | ||
266 | if BGP_CONVERGENCE != True: | |
267 | pytest.skip("skipped because of BGP Convergence failure") | |
268 | # test case name | |
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) | |
274 | ||
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)") | |
278 | step( | |
279 | "Configure IPv4 and IP6 loopback address on R1 default and R3 non-default (RED) VRF" | |
280 | ) | |
281 | step("After changing the BGP AS Path Verify the BGP Convergence") | |
282 | ||
283 | BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo) | |
284 | assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error: {}".format( | |
285 | BGP_CONVERGENCE | |
286 | ) | |
287 | step( | |
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)" | |
289 | ) | |
290 | for addr_type in ADDR_TYPES: | |
291 | static_routes_input = { | |
292 | "r1": { | |
293 | "static_routes": [ | |
294 | { | |
295 | "network": [NETWORK1_1[addr_type]], | |
296 | "next_hop": NEXT_HOP_IP[addr_type], | |
297 | } | |
298 | ] | |
299 | } | |
300 | } | |
301 | result = create_static_routes(tgen, static_routes_input) | |
302 | assert ( | |
303 | result is True | |
304 | ), "Testcase {} : Failed to configure the static routes in router R1 default vrf \n Error: {}".format( | |
305 | tc_name, result | |
306 | ) | |
307 | ||
308 | for addr_type in ADDR_TYPES: | |
309 | static_routes_input = { | |
310 | "r3": { | |
311 | "static_routes": [ | |
312 | { | |
313 | "network": [NETWORK2_1[addr_type]], | |
314 | "next_hop": NEXT_HOP_IP[addr_type], | |
315 | "vrf": "RED", | |
316 | } | |
317 | ] | |
318 | } | |
319 | } | |
320 | result = create_static_routes(tgen, static_routes_input) | |
321 | assert ( | |
322 | result is True | |
323 | ), "Testcase {} : Failed to configure static route in R3 non default vrf RED \n Error: {}".format( | |
324 | tc_name, result | |
325 | ) | |
326 | ||
327 | step( | |
328 | "Verify IPv4 and IPv6 static route configured on R1 default vrf and R3 non-default (RED) vrf" | |
329 | ) | |
330 | for addr_type in ADDR_TYPES: | |
331 | static_routes_input = { | |
332 | "r1": { | |
333 | "static_routes": [ | |
334 | { | |
335 | "network": [NETWORK1_1[addr_type]], | |
336 | "next_hop": NEXT_HOP_IP[addr_type], | |
337 | } | |
338 | ] | |
339 | } | |
340 | } | |
341 | result = verify_rib(tgen, addr_type, "r1", static_routes_input) | |
342 | assert ( | |
343 | result is True | |
344 | ), "Testcase {} : Failed: Routes configured on vrf is not seen in R1 default VRF FIB \n Error: {}".format( | |
345 | tc_name, result | |
346 | ) | |
347 | ||
348 | for addr_type in ADDR_TYPES: | |
349 | static_routes_input = { | |
350 | "r3": { | |
351 | "static_routes": [ | |
352 | { | |
353 | "network": [NETWORK2_1[addr_type]], | |
354 | "next_hop": NEXT_HOP_IP[addr_type], | |
355 | "vrf": "RED", | |
356 | } | |
357 | ] | |
358 | } | |
359 | } | |
360 | result = verify_rib(tgen, addr_type, "r3", static_routes_input) | |
361 | assert ( | |
362 | result is True | |
363 | ), "Testcase {} : Failed : Routes configured in non-defaul vrf in R3 FIB is \n Error: {}".format( | |
364 | tc_name, result | |
365 | ) | |
366 | ||
367 | step( | |
368 | "Configure redistribute connected and static on R1 (R1-R2) and on R3 ( R2-R3 RED VRF) IPv4 and IPv6 address family " | |
369 | ) | |
370 | redistribute_static = { | |
371 | "r1": { | |
372 | "bgp": { | |
373 | "address_family": { | |
374 | "ipv4": { | |
375 | "unicast": { | |
376 | "redistribute": [ | |
377 | {"redist_type": "static"}, | |
378 | {"redist_type": "connected"}, | |
379 | ] | |
380 | } | |
381 | }, | |
382 | "ipv6": { | |
383 | "unicast": { | |
384 | "redistribute": [ | |
385 | {"redist_type": "static"}, | |
386 | {"redist_type": "connected"}, | |
387 | ] | |
388 | } | |
389 | }, | |
390 | } | |
391 | } | |
392 | }, | |
393 | "r3": { | |
394 | "bgp": { | |
395 | "local_as": 3000, | |
396 | "vrf": "RED", | |
397 | "address_family": { | |
398 | "ipv4": { | |
399 | "unicast": { | |
400 | "redistribute": [ | |
401 | {"redist_type": "static"}, | |
402 | {"redist_type": "connected"}, | |
403 | ] | |
404 | } | |
405 | }, | |
406 | "ipv6": { | |
407 | "unicast": { | |
408 | "redistribute": [ | |
409 | {"redist_type": "static"}, | |
410 | {"redist_type": "connected"}, | |
411 | ] | |
412 | } | |
413 | }, | |
414 | }, | |
415 | } | |
416 | }, | |
417 | } | |
418 | result = create_router_bgp(tgen, topo, redistribute_static) | |
419 | assert ( | |
420 | result is True | |
421 | ), "Testcase {} : Failed to configure the redistribute on R1 and R3 \n Error: {}".format( | |
422 | tc_name, result | |
423 | ) | |
424 | ||
425 | step( | |
426 | "Verify IPv4 and IPv6 static route configured on R1 received as BGP routes on R2 default VRF " | |
427 | ) | |
428 | for addr_type in ADDR_TYPES: | |
429 | static_routes_input = { | |
430 | "r2": { | |
431 | "static_routes": [ | |
432 | { | |
433 | "network": [NETWORK1_1[addr_type]], | |
434 | "next_hop": NEXT_HOP_IP[addr_type], | |
435 | }, | |
436 | { | |
437 | "network": [R1_NETWORK_LOOPBACK[addr_type]], | |
438 | "next_hop": R1_NETWORK_LOOPBACK_NXTHOP[addr_type], | |
439 | }, | |
440 | { | |
441 | "network": [R1_NETWORK_CONNECTED[addr_type]], | |
442 | "next_hop": R1_NETWORK_CONNECTED_NXTHOP[addr_type], | |
443 | }, | |
444 | ] | |
445 | } | |
446 | } | |
447 | result = verify_bgp_rib(tgen, addr_type, "r2", static_routes_input) | |
448 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
449 | tc_name, result | |
450 | ) | |
451 | step( | |
452 | "Verify IPv4 and IPv6 static route configured on R3 received as BGP routes on R2 non-default VRF " | |
453 | ) | |
454 | for addr_type in ADDR_TYPES: | |
455 | static_routes_input = { | |
456 | "r3": { | |
457 | "static_routes": [ | |
458 | { | |
459 | "network": [NETWORK2_1[addr_type]], | |
460 | "next_hop": NEXT_HOP_IP[addr_type], | |
461 | "vrf": "RED", | |
462 | }, | |
463 | { | |
464 | "network": [R3_NETWORK_CONNECTED[addr_type]], | |
465 | "next_hop": R3_NETWORK_CONNECTED_NXTHOP[addr_type], | |
466 | "vrf": "RED", | |
467 | }, | |
468 | ] | |
469 | } | |
470 | } | |
471 | result = verify_bgp_rib(tgen, addr_type, "r2", static_routes_input) | |
472 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
473 | tc_name, result | |
474 | ) | |
475 | ||
476 | step( | |
477 | "Configure default-originate on R1 for R1 to R2 neighbor for IPv4 and IPv6 peer" | |
478 | ) | |
479 | local_as = get_dut_as_number(tgen, dut="r1") | |
480 | default_originate_config = { | |
481 | "r1": { | |
482 | "bgp": { | |
483 | "local_as": local_as, | |
484 | "address_family": { | |
485 | "ipv4": {"unicast": {"default_originate": {"r2": {}}}}, | |
486 | "ipv6": {"unicast": {"default_originate": {"r2": {}}}}, | |
487 | }, | |
488 | } | |
489 | } | |
490 | } | |
491 | result = create_router_bgp(tgen, topo, default_originate_config) | |
492 | assert ( | |
493 | result is True | |
494 | ), "Testcase {} : Failed to configure the default originate \n Error: {}".format( | |
495 | tc_name, result | |
496 | ) | |
497 | ||
498 | step( | |
499 | "After configuring default-originate command , verify default routes are advertised on R2 " | |
500 | ) | |
501 | DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"} | |
502 | for addr_type in ADDR_TYPES: | |
503 | static_routes_input = { | |
504 | "r2": { | |
505 | "static_routes": [ | |
506 | { | |
507 | "network": [DEFAULT_ROUTES[addr_type]], | |
508 | "next_hop": DEFAULT_ROUTE_NXT_HOP_R1[addr_type], | |
509 | } | |
510 | ] | |
511 | } | |
512 | } | |
513 | ||
514 | result = verify_rib( | |
515 | tgen, | |
516 | addr_type, | |
517 | "r2", | |
518 | static_routes_input, | |
519 | next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type], | |
520 | ) | |
521 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
522 | tc_name, result | |
523 | ) | |
524 | ||
525 | result = verify_bgp_rib( | |
526 | tgen, | |
527 | addr_type, | |
528 | "r2", | |
529 | static_routes_input, | |
530 | next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type], | |
531 | ) | |
532 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
533 | tc_name, result | |
534 | ) | |
535 | ||
536 | for addr_type in ADDR_TYPES: | |
537 | static_routes_input = { | |
538 | "r2": { | |
539 | "static_routes": [ | |
540 | { | |
541 | "network": [NETWORK1_1[addr_type]], | |
542 | "next_hop": NEXT_HOP_IP[addr_type], | |
543 | }, | |
544 | { | |
545 | "network": [R1_NETWORK_LOOPBACK[addr_type]], | |
546 | "next_hop": R1_NETWORK_LOOPBACK_NXTHOP[addr_type], | |
547 | }, | |
548 | { | |
549 | "network": [R1_NETWORK_CONNECTED[addr_type]], | |
550 | "next_hop": R1_NETWORK_CONNECTED_NXTHOP[addr_type], | |
551 | }, | |
552 | ] | |
553 | } | |
554 | } | |
555 | ||
556 | result = verify_bgp_rib( | |
557 | tgen, | |
558 | addr_type, | |
559 | "r2", | |
560 | static_routes_input, | |
561 | next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type], | |
562 | ) | |
563 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
564 | tc_name, result | |
565 | ) | |
566 | ||
567 | result = verify_rib( | |
568 | tgen, | |
569 | addr_type, | |
570 | "r2", | |
571 | static_routes_input, | |
572 | next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type], | |
573 | ) | |
574 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
575 | tc_name, result | |
576 | ) | |
577 | ||
578 | snapshot1 = get_prefix_count_route(tgen, topo, dut="r2", peer="r3", vrf="RED") | |
579 | ||
580 | step( | |
581 | "Configure default-originate on R3 for R3 to R2 neighbor (RED VRF) for IPv4 and IPv6 peer" | |
582 | ) | |
583 | ||
584 | default_originate_config = { | |
585 | "r3": { | |
586 | "bgp": { | |
587 | "local_as": "3000", | |
588 | "vrf": "RED", | |
589 | "address_family": { | |
590 | "ipv4": {"unicast": {"default_originate": {"r2": {}}}}, | |
591 | "ipv6": {"unicast": {"default_originate": {"r2": {}}}}, | |
592 | }, | |
593 | } | |
594 | } | |
595 | } | |
596 | result = create_router_bgp(tgen, topo, default_originate_config) | |
597 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
598 | ||
599 | step( | |
600 | "Verify IPv4 and IPv6 bgp default route and static route received on R2 VRF red nexthop as R3" | |
601 | ) | |
602 | DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"} | |
603 | for addr_type in ADDR_TYPES: | |
604 | static_routes_input = { | |
605 | "r2": { | |
606 | "static_routes": [ | |
607 | { | |
608 | "network": [NETWORK2_1[addr_type]], | |
609 | "next_hop": NEXT_HOP_IP[addr_type], | |
610 | "vrf": "RED", | |
611 | }, | |
612 | { | |
613 | "network": [DEFAULT_ROUTES[addr_type]], | |
614 | "next_hop": DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
615 | "vrf": "RED", | |
616 | }, | |
617 | ] | |
618 | } | |
619 | } | |
620 | result = verify_rib( | |
621 | tgen, | |
622 | addr_type, | |
623 | "r2", | |
624 | static_routes_input, | |
625 | next_hop=DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
626 | ) | |
627 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
628 | tc_name, result | |
629 | ) | |
630 | result = verify_bgp_rib( | |
631 | tgen, | |
632 | addr_type, | |
633 | "r2", | |
634 | static_routes_input, | |
635 | next_hop=DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
636 | ) | |
637 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
638 | tc_name, result | |
639 | ) | |
640 | ||
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 | |
650 | ||
651 | assert ( | |
652 | isIPv4prefix_incremented is True | |
653 | ), "Testcase {} : Failed Error: IPV4 Prefix is not incremented on receiveing ".format( | |
654 | tc_name | |
655 | ) | |
656 | ||
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") | |
660 | input_import_vrf = { | |
661 | "r2": { | |
662 | "bgp": [ | |
663 | { | |
664 | "local_as": local_as, | |
665 | "address_family": { | |
666 | "ipv4": {"unicast": {"import": {"vrf": "RED"}}}, | |
667 | "ipv6": {"unicast": {"import": {"vrf": "RED"}}}, | |
668 | }, | |
669 | } | |
670 | ] | |
671 | } | |
672 | } | |
673 | result = create_router_bgp(tgen, topo, input_import_vrf) | |
674 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
675 | step( | |
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" | |
677 | ) | |
678 | step("verifying the static routes connected and loop back routes") | |
679 | for addr_type in ADDR_TYPES: | |
680 | static_routes_input = { | |
681 | "r2": { | |
682 | "static_routes": [ | |
683 | { | |
684 | "network": [NETWORK1_1[addr_type]], | |
685 | "next_hop": NEXT_HOP_IP[addr_type], | |
686 | }, | |
687 | { | |
688 | "network": [NETWORK2_1[addr_type]], | |
689 | "next_hop": NEXT_HOP_IP[addr_type], | |
690 | }, | |
691 | { | |
692 | "network": [R1_NETWORK_LOOPBACK[addr_type]], | |
693 | "next_hop": R1_NETWORK_LOOPBACK_NXTHOP[addr_type], | |
694 | }, | |
695 | { | |
696 | "network": [R1_NETWORK_CONNECTED[addr_type]], | |
697 | "next_hop": R1_NETWORK_CONNECTED_NXTHOP[addr_type], | |
698 | }, | |
699 | { | |
700 | "network": [R3_NETWORK_CONNECTED[addr_type]], | |
701 | "next_hop": R3_NETWORK_CONNECTED_NXTHOP[addr_type], | |
702 | }, | |
703 | ] | |
704 | } | |
705 | } | |
706 | ||
707 | result = verify_rib(tgen, addr_type, "r2", static_routes_input) | |
708 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
709 | tc_name, result | |
710 | ) | |
711 | ||
712 | result = verify_bgp_rib(tgen, addr_type, "r2", static_routes_input) | |
713 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
714 | tc_name, result | |
715 | ) | |
716 | ||
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 | |
722 | """ | |
723 | step(STEP) | |
724 | DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"} | |
725 | for addr_type in ADDR_TYPES: | |
726 | static_routes_input = { | |
727 | "r2": { | |
728 | "static_routes": [ | |
729 | { | |
730 | "network": [DEFAULT_ROUTES[addr_type]], | |
731 | "next_hop": DEFAULT_ROUTE_NXT_HOP_R1[addr_type], | |
732 | } | |
733 | ] | |
734 | } | |
735 | } | |
736 | ||
737 | result = verify_rib(tgen, addr_type, "r2", static_routes_input) | |
738 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
739 | tc_name, result | |
740 | ) | |
741 | ||
742 | static_routes_input = { | |
743 | "r2": { | |
744 | "static_routes": [ | |
745 | { | |
746 | "network": [DEFAULT_ROUTES[addr_type]], | |
747 | "next_hop": DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
748 | }, | |
749 | { | |
750 | "network": [DEFAULT_ROUTES[addr_type]], | |
751 | "next_hop": DEFAULT_ROUTE_NXT_HOP_R1[addr_type], | |
752 | }, | |
753 | ] | |
754 | } | |
755 | } | |
756 | ||
757 | result = verify_bgp_rib(tgen, addr_type, "r2", static_routes_input) | |
758 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
759 | tc_name, result | |
760 | ) | |
761 | step( | |
762 | "Configure import VRF default on R2 (R2-R3) RED VRF for IPV4 and IPV6 BGP peer" | |
763 | ) | |
764 | step("Importing the default vrf in non-default VRF ") | |
765 | local_as = "2000" | |
766 | input_import_vrf = { | |
767 | "r2": { | |
768 | "bgp": [ | |
769 | { | |
770 | "local_as": local_as, | |
771 | "vrf": "RED", | |
772 | "address_family": { | |
773 | "ipv4": {"unicast": {"import": {"vrf": "default"}}}, | |
774 | "ipv6": {"unicast": {"import": {"vrf": "default"}}}, | |
775 | }, | |
776 | } | |
777 | ] | |
778 | } | |
779 | } | |
780 | result = create_router_bgp(tgen, topo, input_import_vrf) | |
781 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
782 | step( | |
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" | |
784 | ) | |
785 | for addr_type in ADDR_TYPES: | |
786 | static_routes_input = { | |
787 | "r2": { | |
788 | "static_routes": [ | |
789 | { | |
790 | "network": [NETWORK1_1[addr_type]], | |
791 | "next_hop": NEXT_HOP_IP[addr_type], | |
792 | "vrf": "RED", | |
793 | }, | |
794 | { | |
795 | "network": [NETWORK2_1[addr_type]], | |
796 | "next_hop": NEXT_HOP_IP[addr_type], | |
797 | "vrf": "RED", | |
798 | }, | |
799 | { | |
800 | "network": [R1_NETWORK_LOOPBACK[addr_type]], | |
801 | "next_hop": R1_NETWORK_LOOPBACK_NXTHOP[addr_type], | |
802 | "vrf": "RED", | |
803 | }, | |
804 | { | |
805 | "network": [R1_NETWORK_CONNECTED[addr_type]], | |
806 | "next_hop": R1_NETWORK_CONNECTED_NXTHOP[addr_type], | |
807 | "vrf": "RED", | |
808 | }, | |
809 | { | |
810 | "network": [R3_NETWORK_CONNECTED[addr_type]], | |
811 | "next_hop": R3_NETWORK_CONNECTED_NXTHOP[addr_type], | |
812 | "vrf": "RED", | |
813 | }, | |
814 | ] | |
815 | } | |
816 | } | |
817 | ||
818 | result = verify_rib(tgen, addr_type, "r2", static_routes_input) | |
819 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
820 | tc_name, result | |
821 | ) | |
822 | ||
823 | result = verify_bgp_rib(tgen, addr_type, "r2", static_routes_input) | |
824 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
825 | tc_name, result | |
826 | ) | |
827 | ||
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 | |
833 | """ | |
834 | step(STEP) | |
835 | for addr_type in ADDR_TYPES: | |
836 | static_routes_input = { | |
837 | "r2": { | |
838 | "static_routes": [ | |
839 | { | |
840 | "network": [DEFAULT_ROUTES[addr_type]], | |
841 | "next_hop": DEFAULT_ROUTE_NXT_HOP_R1[addr_type], | |
842 | "vrf": "RED", | |
843 | } | |
844 | ] | |
845 | } | |
846 | } | |
847 | ||
848 | result = verify_rib( | |
849 | tgen, | |
850 | addr_type, | |
851 | "r2", | |
852 | static_routes_input, | |
853 | next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type], | |
854 | ) | |
855 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
856 | tc_name, result | |
857 | ) | |
858 | ||
859 | static_routes_input = { | |
860 | "r2": { | |
861 | "static_routes": [ | |
862 | { | |
863 | "network": [DEFAULT_ROUTES[addr_type]], | |
864 | "next_hop": DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
865 | "vrf": "RED", | |
866 | } | |
867 | ] | |
868 | } | |
869 | } | |
870 | ||
871 | result = verify_rib( | |
872 | tgen, | |
873 | addr_type, | |
874 | "r2", | |
875 | static_routes_input, | |
876 | next_hop=DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
877 | expected=False, | |
878 | ) | |
879 | assert result is not True, "Testcase {} : Failed {} \n Error: {}".format( | |
880 | tc_name, STEP, result | |
881 | ) | |
882 | ||
883 | static_routes_input = { | |
884 | "r2": { | |
885 | "static_routes": [ | |
886 | { | |
887 | "network": [DEFAULT_ROUTES[addr_type]], | |
888 | "next_hop": DEFAULT_ROUTE_NXT_HOP_R1[addr_type], | |
889 | "vrf": "RED", | |
890 | }, | |
891 | { | |
892 | "network": [DEFAULT_ROUTES[addr_type]], | |
893 | "next_hop": DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
894 | "vrf": "RED", | |
895 | }, | |
896 | ] | |
897 | } | |
898 | } | |
899 | ||
900 | result = verify_bgp_rib(tgen, addr_type, "r2", static_routes_input) | |
901 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
902 | tc_name, result | |
903 | ) | |
904 | ||
905 | step( | |
906 | "Remove import VRF configure in step 8 and then remove import VRF configured on step 9" | |
907 | ) | |
908 | local_as = get_dut_as_number(tgen, "r2") | |
909 | input_import_vrf = { | |
910 | "r2": { | |
911 | "bgp": [ | |
912 | { | |
913 | "local_as": local_as, | |
914 | "address_family": { | |
915 | "ipv4": {"unicast": {"import": {"vrf": "RED", "delete": True}}}, | |
916 | "ipv6": {"unicast": {"import": {"vrf": "RED", "delete": True}}}, | |
917 | }, | |
918 | } | |
919 | ] | |
920 | } | |
921 | } | |
922 | result = create_router_bgp(tgen, topo, input_import_vrf) | |
923 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
924 | ||
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"} | |
927 | ||
928 | for addr_type in ADDR_TYPES: | |
929 | static_routes_input = { | |
930 | "r2": { | |
931 | "static_routes": [ | |
932 | { | |
933 | "network": [NETWORK2_1[addr_type]], | |
934 | "next_hop": NEXT_HOP_IP[addr_type], | |
935 | }, | |
936 | { | |
937 | "network": [R3_NETWORK_LOOPBACK[addr_type]], | |
938 | "next_hop": R3_NETWORK_LOOPBACK_NXTHOP[addr_type], | |
939 | }, | |
940 | { | |
941 | "network": [R3_NETWORK_CONNECTED[addr_type]], | |
942 | "next_hop": R3_NETWORK_CONNECTED_NXTHOP[addr_type], | |
943 | }, | |
944 | ] | |
945 | } | |
946 | } | |
947 | ||
948 | result = verify_rib(tgen, addr_type, "r2", static_routes_input, expected=False) | |
949 | assert ( | |
950 | result is not True | |
951 | ), "Testcase {} : Failed \n routes imported from non default VRF is not expected Error: {}".format( | |
952 | tc_name, result | |
953 | ) | |
954 | ||
955 | result = verify_bgp_rib( | |
956 | tgen, addr_type, "r2", static_routes_input, expected=False | |
957 | ) | |
958 | assert ( | |
959 | result is not True | |
960 | ), "Testcase {} : Failed \n routes imported from non default VRF is not expected \nError: {}".format( | |
961 | tc_name, result | |
962 | ) | |
963 | ||
964 | step( | |
965 | "Remove import VRF configure in step 8 and then remove import VRF configured on step 9" | |
966 | ) | |
967 | local_as = "2000" | |
968 | input_import_vrf = { | |
969 | "r2": { | |
970 | "bgp": [ | |
971 | { | |
972 | "local_as": local_as, | |
973 | "vrf": "RED", | |
974 | "address_family": { | |
975 | "ipv4": { | |
976 | "unicast": {"import": {"vrf": "default", "delete": True}} | |
977 | }, | |
978 | "ipv6": { | |
979 | "unicast": {"import": {"vrf": "default", "delete": True}} | |
980 | }, | |
981 | }, | |
982 | } | |
983 | ] | |
984 | } | |
985 | } | |
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"} | |
990 | ||
991 | for addr_type in ADDR_TYPES: | |
992 | static_routes_input = { | |
993 | "r2": { | |
994 | "static_routes": [ | |
995 | { | |
996 | "network": [NETWORK1_1[addr_type]], | |
997 | "next_hop": NEXT_HOP_IP[addr_type], | |
998 | "vrf": "RED", | |
999 | }, | |
1000 | { | |
1001 | "network": [R1_NETWORK_LOOPBACK[addr_type]], | |
1002 | "next_hop": R1_NETWORK_LOOPBACK_NXTHOP[addr_type], | |
1003 | "vrf": "RED", | |
1004 | }, | |
1005 | { | |
1006 | "network": [R1_NETWORK_CONNECTED[addr_type]], | |
1007 | "next_hop": R1_NETWORK_CONNECTED_NXTHOP[addr_type], | |
1008 | "vrf": "RED", | |
1009 | }, | |
1010 | ] | |
1011 | } | |
1012 | } | |
1013 | ||
1014 | result = verify_rib(tgen, addr_type, "r2", static_routes_input, expected=False) | |
1015 | assert ( | |
1016 | result is not True | |
1017 | ), "Testcase {} : Failed \n routes impoted from default VRF is not expected \n Error: {}".format( | |
1018 | tc_name, result | |
1019 | ) | |
1020 | ||
1021 | result = verify_bgp_rib( | |
1022 | tgen, addr_type, "r2", static_routes_input, expected=False | |
1023 | ) | |
1024 | assert ( | |
1025 | result is not True | |
1026 | ), "Testcase {} : Failed \n routes impoted from default VRF is not expected \n Error: {}".format( | |
1027 | tc_name, result | |
1028 | ) | |
1029 | ||
1030 | write_test_footer(tc_name) | |
1031 | ||
1032 | ||
1033 | def test_verify_default_originate_route_with_non_default_VRF_with_route_map_p1(request): | |
1034 | """ | |
1035 | "Verify default-originate route with non-default VRF with route-map import " | |
1036 | """ | |
1037 | tgen = get_topogen() | |
1038 | global BGP_CONVERGENCE | |
1039 | ||
1040 | if BGP_CONVERGENCE != True: | |
1041 | pytest.skip("skipped because of BGP Convergence failure") | |
1042 | # test case name | |
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) | |
1048 | ||
1049 | step("Configure IPV4 and IPV6 static route on R0 with Null nexthop") | |
1050 | STEP = """ | |
1051 | Configure IPV4 and IPV6 EBGP session between R0 and R1 | |
1052 | Configure IPV4 and IPV6 static route on R0 with Null nexthop """ | |
1053 | step(STEP) | |
1054 | input_dict = { | |
1055 | "r0": {"bgp": {"local_as": 222, "vrf": "default"}}, | |
1056 | "r1": {"bgp": {"local_as": 333, "vrf": "default"}}, | |
1057 | } | |
1058 | result = modify_as_number(tgen, topo, input_dict) | |
1059 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1060 | try: | |
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") | |
1066 | ||
1067 | BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo) | |
1068 | assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error: {}".format( | |
1069 | BGP_CONVERGENCE | |
1070 | ) | |
1071 | ||
1072 | step("Configuring static route at R0") | |
1073 | for addr_type in ADDR_TYPES: | |
1074 | static_routes_input = { | |
1075 | "r0": { | |
1076 | "static_routes": [ | |
1077 | { | |
1078 | "network": [NETWORK5_1[addr_type]], | |
1079 | "next_hop": NEXT_HOP_IP[addr_type], | |
1080 | } | |
1081 | ] | |
1082 | } | |
1083 | } | |
1084 | result = create_static_routes(tgen, static_routes_input) | |
1085 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
1086 | tc_name, result | |
1087 | ) | |
1088 | step(" Configure re-distribute static on R0 for R0 to R1 for IPV4 and IPV6 peer ") | |
1089 | redistribute_static = { | |
1090 | "r0": { | |
1091 | "bgp": { | |
1092 | "address_family": { | |
1093 | "ipv4": { | |
1094 | "unicast": { | |
1095 | "redistribute": [ | |
1096 | {"redist_type": "static"}, | |
1097 | {"redist_type": "connected"}, | |
1098 | ] | |
1099 | } | |
1100 | }, | |
1101 | "ipv6": { | |
1102 | "unicast": { | |
1103 | "redistribute": [ | |
1104 | {"redist_type": "static"}, | |
1105 | {"redist_type": "connected"}, | |
1106 | ] | |
1107 | } | |
1108 | }, | |
1109 | } | |
1110 | } | |
1111 | } | |
1112 | } | |
1113 | result = create_router_bgp(tgen, topo, redistribute_static) | |
1114 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1115 | ||
1116 | step( | |
1117 | "Configure default-originate on R1 for R1 to R2 neighbor for IPv4 and IPv6 peer" | |
1118 | ) | |
1119 | local_as = get_dut_as_number(tgen, dut="r1") | |
1120 | default_originate_config = { | |
1121 | "r1": { | |
1122 | "bgp": { | |
1123 | "local_as": local_as, | |
1124 | "address_family": { | |
1125 | "ipv4": {"unicast": {"default_originate": {"r2": {}}}}, | |
1126 | "ipv6": {"unicast": {"default_originate": {"r2": {}}}}, | |
1127 | }, | |
1128 | } | |
1129 | } | |
1130 | } | |
1131 | result = create_router_bgp(tgen, topo, default_originate_config) | |
1132 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1133 | ||
1134 | snapshot1 = get_prefix_count_route(tgen, topo, dut="r2", peer="r3", vrf="RED") | |
1135 | ||
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 = { | |
1139 | "r2": { | |
1140 | "static_routes": [ | |
1141 | { | |
1142 | "network": [NETWORK5_1[addr_type]], | |
1143 | "next_hop": NEXT_HOP_IP[addr_type], | |
1144 | }, | |
1145 | { | |
1146 | "network": [DEFAULT_ROUTES[addr_type]], | |
1147 | "next_hop": DEFAULT_ROUTE_NXT_HOP_R1[addr_type], | |
1148 | }, | |
1149 | ] | |
1150 | } | |
1151 | } | |
1152 | ||
1153 | result = verify_rib(tgen, addr_type, "r2", static_routes_input) | |
1154 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
1155 | tc_name, result | |
1156 | ) | |
1157 | ||
1158 | result = verify_bgp_rib(tgen, addr_type, "r2", static_routes_input) | |
1159 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
1160 | tc_name, result | |
1161 | ) | |
1162 | step( | |
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" | |
1164 | ) | |
1165 | input_dict_3 = { | |
1166 | "r2": { | |
1167 | "prefix_lists": { | |
1168 | "ipv4": { | |
1169 | "Pv4": [ | |
1170 | { | |
1171 | "seqid": "1", | |
1172 | "network": NETWORK5_1["ipv4"], | |
1173 | "action": "permit", | |
1174 | }, | |
1175 | {"seqid": "2", "network": "0.0.0.0/0", "action": "permit"}, | |
1176 | { | |
1177 | "seqid": "3", | |
1178 | "network": NETWORK2_1["ipv4"], | |
1179 | "action": "permit", | |
1180 | }, | |
1181 | ] | |
1182 | }, | |
1183 | "ipv6": { | |
1184 | "Pv6": [ | |
1185 | { | |
1186 | "seqid": "1", | |
1187 | "network": NETWORK5_1["ipv6"], | |
1188 | "action": "permit", | |
1189 | }, | |
1190 | {"seqid": "2", "network": "0::0/0", "action": "permit"}, | |
1191 | { | |
1192 | "seqid": "3", | |
1193 | "network": NETWORK2_1["ipv6"], | |
1194 | "action": "permit", | |
1195 | }, | |
1196 | ] | |
1197 | }, | |
1198 | } | |
1199 | } | |
1200 | } | |
1201 | result = create_prefix_lists(tgen, input_dict_3) | |
1202 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1203 | ||
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) | |
1208 | ||
1209 | step( | |
1210 | "Configure IPv4/IPv6 route-map on R2 with deny sequence using above prefix-list" | |
1211 | ) | |
1212 | input_dict_3 = { | |
1213 | "r2": { | |
1214 | "route_maps": { | |
1215 | "RMv4": [ | |
1216 | { | |
1217 | "action": "deny", | |
1218 | "seq_id": "1", | |
1219 | "match": {"ipv4": {"prefix_lists": "Pv4"}}, | |
1220 | }, | |
1221 | ], | |
1222 | "RMv6": [ | |
1223 | { | |
1224 | "action": "deny", | |
1225 | "seq_id": "1", | |
1226 | "match": {"ipv6": {"prefix_lists": "Pv6"}}, | |
1227 | }, | |
1228 | ], | |
1229 | } | |
1230 | } | |
1231 | } | |
1232 | result = create_route_maps(tgen, input_dict_3) | |
1233 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1234 | ||
1235 | STEP = """ | |
1236 | import Route-map anf non-default VRF into defailt vrf | |
1237 | import vrf route-map RM1 | |
1238 | import vrf red | |
1239 | """ | |
1240 | step(STEP) | |
1241 | ||
1242 | local_as = get_dut_as_number(tgen, "r2") | |
1243 | input_import_vrf = { | |
1244 | "r2": { | |
1245 | "bgp": [ | |
1246 | { | |
1247 | "local_as": local_as, | |
1248 | "address_family": { | |
1249 | "ipv4": {"unicast": {"import": {"vrf": "RED"}}}, | |
1250 | "ipv6": {"unicast": {"import": {"vrf": "RED"}}}, | |
1251 | }, | |
1252 | } | |
1253 | ] | |
1254 | } | |
1255 | } | |
1256 | result = create_router_bgp(tgen, topo, input_import_vrf) | |
1257 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1258 | step(STEP) | |
1259 | input_import_vrf = { | |
1260 | "r2": { | |
1261 | "bgp": [ | |
1262 | { | |
1263 | "local_as": local_as, | |
1264 | "address_family": { | |
1265 | "ipv4": {"unicast": {"import": {"vrf": "route-map RMv4"}}}, | |
1266 | "ipv6": {"unicast": {"import": {"vrf": "route-map RMv6"}}}, | |
1267 | }, | |
1268 | } | |
1269 | ] | |
1270 | } | |
1271 | } | |
1272 | result = create_router_bgp(tgen, topo, input_import_vrf) | |
1273 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1274 | step( | |
1275 | "Verify IPv4 and IPv6 routes present on VRF red ( static , default-originate) should not get advertised to default VRF " | |
1276 | ) | |
1277 | for addr_type in ADDR_TYPES: | |
1278 | static_routes_input = { | |
1279 | "r2": { | |
1280 | "static_routes": [ | |
1281 | { | |
1282 | "network": [NETWORK2_1[addr_type]], | |
1283 | "next_hop": NEXT_HOP_IP[addr_type], | |
1284 | }, | |
1285 | { | |
1286 | "network": [DEFAULT_ROUTES[addr_type]], | |
1287 | "next_hop": DEFAULT_ROUTE_NXT_HOP_R1[addr_type], | |
1288 | }, | |
1289 | ] | |
1290 | } | |
1291 | } | |
1292 | ||
1293 | result = verify_rib(tgen, addr_type, "r2", static_routes_input, expected=False) | |
1294 | assert ( | |
1295 | result is not True | |
1296 | ), "Testcase {} : Failed \n VRF red ( static , default-originate) should not get advertised to default VRF \n Error: {}".format( | |
1297 | tc_name, result | |
1298 | ) | |
1299 | ||
1300 | result = verify_bgp_rib( | |
1301 | tgen, addr_type, "r2", static_routes_input, expected=False | |
1302 | ) | |
1303 | assert ( | |
1304 | result is not True | |
1305 | ), "Testcase {} : Failed \n VRF red ( static , default-originate) should not get advertised to default VRF \nError: {}".format( | |
1306 | tc_name, result | |
1307 | ) | |
1308 | ||
1309 | step("Change route-map sequence deny to permit") | |
1310 | input_dict_3 = { | |
1311 | "r2": { | |
1312 | "route_maps": { | |
1313 | "RMv4": [ | |
1314 | { | |
1315 | "action": "permit", | |
1316 | "seq_id": "1", | |
1317 | "match": {"ipv4": {"prefix_lists": "Pv4"}}, | |
1318 | }, | |
1319 | ], | |
1320 | "RMv6": [ | |
1321 | { | |
1322 | "action": "permit", | |
1323 | "seq_id": "1", | |
1324 | "match": {"ipv6": {"prefix_lists": "Pv6"}}, | |
1325 | }, | |
1326 | ], | |
1327 | } | |
1328 | } | |
1329 | } | |
1330 | result = create_route_maps(tgen, input_dict_3) | |
1331 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1332 | ||
1333 | step( | |
1334 | "IPv4 and IPv6 routes present on VRF red ( static , default-originate) should get advertised to default VRF" | |
1335 | ) | |
1336 | for addr_type in ADDR_TYPES: | |
1337 | static_routes_input = { | |
1338 | "r2": { | |
1339 | "static_routes": [ | |
1340 | { | |
1341 | "network": [DEFAULT_ROUTES[addr_type]], | |
1342 | "next_hop": DEFAULT_ROUTE_NXT_HOP_R1[addr_type], | |
1343 | } | |
1344 | ] | |
1345 | } | |
1346 | } | |
1347 | ||
1348 | result = verify_rib(tgen, addr_type, "r2", static_routes_input) | |
1349 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
1350 | tc_name, result | |
1351 | ) | |
1352 | ||
1353 | result = verify_bgp_rib(tgen, addr_type, "r2", static_routes_input) | |
1354 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
1355 | tc_name, result | |
1356 | ) | |
1357 | ||
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 | |
1367 | ||
1368 | assert ( | |
1369 | isIPv4prefix_incremented is True | |
1370 | ), "Testcase {} : Failed Error: IPV4 Prefix is not incremented on receiveing ".format( | |
1371 | tc_name | |
1372 | ) | |
1373 | ||
1374 | ||
1375 | if __name__ == "__main__": | |
1376 | args = ["-s"] + sys.argv[1:] | |
1377 | sys.exit(pytest.main(args)) |