]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/env python | |
2 | # SPDX-License-Identifier: ISC | |
3 | # | |
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") | |
7 | # in this file. | |
8 | # | |
9 | """ | |
10 | Following tests are covered. | |
11 | 1. Verify BGP default-originate route with IBGP peer | |
12 | 2. Verify BGP default-originate route with EBGP peer | |
13 | 3. Verify BGP default route when default-originate configured with route-map over IBGP peer | |
14 | 4. Verify BGP default route when default-originate configured with route-map over EBGP peer" | |
15 | ||
16 | """ | |
17 | import os | |
18 | import sys | |
19 | import time | |
20 | import pytest | |
21 | from time import sleep | |
22 | from copy import deepcopy | |
23 | from lib.topolog import logger | |
24 | ||
25 | # pylint: disable=C0413 | |
26 | # Import topogen and topotest helpers | |
27 | from lib.topogen import Topogen, get_topogen | |
28 | from lib.topojson import build_config_from_json | |
29 | from lib.topolog import logger | |
30 | ||
31 | from lib.bgp import ( | |
32 | verify_bgp_convergence, | |
33 | verify_graceful_restart, | |
34 | create_router_bgp, | |
35 | verify_router_id, | |
36 | modify_as_number, | |
37 | verify_as_numbers, | |
38 | clear_bgp_and_verify, | |
39 | clear_bgp, | |
40 | verify_bgp_rib, | |
41 | get_prefix_count_route, | |
42 | get_dut_as_number, | |
43 | verify_rib_default_route, | |
44 | verify_fib_default_route, | |
45 | verify_bgp_advertised_routes_from_neighbor, | |
46 | verify_bgp_received_routes_from_neighbor, | |
47 | ) | |
48 | from lib.common_config import ( | |
49 | interface_status, | |
50 | verify_prefix_lists, | |
51 | verify_fib_routes, | |
52 | kill_router_daemons, | |
53 | start_router_daemons, | |
54 | shutdown_bringup_interface, | |
55 | step, | |
56 | required_linux_kernel_version, | |
57 | stop_router, | |
58 | start_router, | |
59 | create_route_maps, | |
60 | create_prefix_lists, | |
61 | get_frr_ipv6_linklocal, | |
62 | start_topology, | |
63 | write_test_header, | |
64 | check_address_types, | |
65 | write_test_footer, | |
66 | reset_config_on_routers, | |
67 | create_static_routes, | |
68 | check_router_status, | |
69 | delete_route_maps, | |
70 | ) | |
71 | ||
72 | ||
73 | pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] | |
74 | ||
75 | # Save the Current Working Directory to find configuration files. | |
76 | CWD = os.path.dirname(os.path.realpath(__file__)) | |
77 | sys.path.append(os.path.join(CWD, "../")) | |
78 | sys.path.append(os.path.join(CWD, "../lib/")) | |
79 | ||
80 | # Required to instantiate the topology builder class. | |
81 | ||
82 | # pylint: disable=C0413 | |
83 | # Import topogen and topotest helpers | |
84 | ||
85 | # Global variables | |
86 | topo = None | |
87 | KEEPALIVETIMER = 1 | |
88 | HOLDDOWNTIMER = 3 | |
89 | # Global variables | |
90 | NETWORK1_1 = {"ipv4": "1.1.1.1/32", "ipv6": "1::1/128"} | |
91 | NETWORK1_2 = {"ipv4": "1.1.1.2/32", "ipv6": "1::2/128"} | |
92 | NETWORK2_1 = {"ipv4": "2.1.1.1/32", "ipv6": "2::1/128"} | |
93 | NETWORK2_2 = {"ipv4": "2.1.1.2/32", "ipv6": "2::2/128"} | |
94 | NETWORK3_1 = {"ipv4": "3.1.1.1/32", "ipv6": "3::1/128"} | |
95 | NETWORK3_2 = {"ipv4": "3.1.1.2/32", "ipv6": "3::2/128"} | |
96 | NETWORK4_1 = {"ipv4": "4.1.1.1/32", "ipv6": "4::1/128"} | |
97 | NETWORK4_2 = {"ipv4": "4.1.1.2/32", "ipv6": "4::2/128"} | |
98 | NETWORK5_1 = {"ipv4": "5.1.1.1/32", "ipv6": "5::1/128"} | |
99 | NETWORK5_2 = {"ipv4": "5.1.1.2/32", "ipv6": "5::2/128"} | |
100 | DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"} | |
101 | NEXT_HOP_IP = {"ipv4": "Null0", "ipv6": "Null0"} | |
102 | ||
103 | IPV4_RM = "RMVIPV4" | |
104 | IPV6_RM = "RMVIPV6" | |
105 | ||
106 | IPV4_RM1 = "RMVIPV41" | |
107 | IPV6_RM1 = "RMVIPV61" | |
108 | ||
109 | IPV4_RM2 = "RMVIPV42" | |
110 | IPV6_RM2 = "RMVIPV62" | |
111 | ||
112 | IPV4_PL_1 = "PV41" | |
113 | IPV4_PL_2 = "PV42" | |
114 | ||
115 | IPV6_PL_1 = "PV61" | |
116 | IPV6_PL_2 = "PV62" | |
117 | ||
118 | ||
119 | r1_ipv4_loopback = "1.0.1.0/24" | |
120 | r2_ipv4_loopback = "1.0.2.0/24" | |
121 | r3_ipv4_loopback = "1.0.3.0/24" | |
122 | r4_ipv4_loopback = "1.0.4.0/24" | |
123 | r1_ipv6_loopback = "2001:db8:f::1:0/120" | |
124 | r2_ipv6_loopback = "2001:db8:f::2:0/120" | |
125 | r3_ipv6_loopback = "2001:db8:f::3:0/120" | |
126 | r4_ipv6_loopback = "2001:db8:f::4:0/120" | |
127 | ||
128 | r0_connected_address_ipv4 = "192.168.0.0/24" | |
129 | r0_connected_address_ipv6 = "fd00::/64" | |
130 | r1_connected_address_ipv4 = "192.168.1.0/24" | |
131 | r1_connected_address_ipv6 = "fd00:0:0:1::/64" | |
132 | r3_connected_address_ipv4 = "192.168.2.0/24" | |
133 | r3_connected_address_ipv6 = "fd00:0:0:2::/64" | |
134 | r4_connected_address_ipv4 = "192.168.3.0/24" | |
135 | r4_connected_address_ipv6 = "fd00:0:0:3::/64" | |
136 | ||
137 | ||
138 | def setup_module(mod): | |
139 | """ | |
140 | Sets up the pytest environment | |
141 | ||
142 | * `mod`: module name | |
143 | """ | |
144 | ||
145 | # Required linux kernel version for this suite to run. | |
146 | result = required_linux_kernel_version("4.15") | |
147 | if result is not True: | |
148 | pytest.skip("Kernel requirements are not met") | |
149 | ||
150 | testsuite_run_time = time.asctime(time.localtime(time.time())) | |
151 | logger.info("Testsuite start time: {}".format(testsuite_run_time)) | |
152 | logger.info("=" * 40) | |
153 | ||
154 | logger.info("Running setup_module to create topology") | |
155 | ||
156 | # This function initiates the topology build with Topogen... | |
157 | json_file = "{}/bgp_default_originate_topo1.json".format(CWD) | |
158 | tgen = Topogen(json_file, mod.__name__) | |
159 | global topo | |
160 | topo = tgen.json_topo | |
161 | # ... and here it calls Mininet initialization functions. | |
162 | ||
163 | # Starting topology, create tmp files which are loaded to routers | |
164 | # to start daemons and then start routers | |
165 | start_topology(tgen) | |
166 | ||
167 | # Creating configuration from JSON | |
168 | build_config_from_json(tgen, topo) | |
169 | ||
170 | global ADDR_TYPES | |
171 | global BGP_CONVERGENCE | |
172 | global DEFAULT_ROUTES | |
173 | global DEFAULT_ROUTE_NXT_HOP_R1, DEFAULT_ROUTE_NXT_HOP_R3 | |
174 | global R0_NETWORK_LOOPBACK, R0_NETWORK_LOOPBACK_NXTHOP, R1_NETWORK_LOOPBACK, R1_NETWORK_LOOPBACK_NXTHOP | |
175 | global R0_NETWORK_CONNECTED, R0_NETWORK_CONNECTED_NXTHOP, R1_NETWORK_CONNECTED, R1_NETWORK_CONNECTED_NXTHOP | |
176 | global R4_NETWORK_LOOPBACK, R4_NETWORK_LOOPBACK_NXTHOP, R3_NETWORK_LOOPBACK, R3_NETWORK_LOOPBACK_NXTHOP | |
177 | global R4_NETWORK_CONNECTED, R4_NETWORK_CONNECTED_NXTHOP, R3_NETWORK_CONNECTED, R3_NETWORK_CONNECTED_NXTHOP | |
178 | ||
179 | ADDR_TYPES = check_address_types() | |
180 | BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo) | |
181 | assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error: {}".format( | |
182 | BGP_CONVERGENCE | |
183 | ) | |
184 | # There are the global varibles used through out the file these are acheived only after building the topology. | |
185 | ||
186 | r0_loopback_address_ipv4 = topo["routers"]["r0"]["links"]["lo"]["ipv4"] | |
187 | r0_loopback_address_ipv4_nxt_hop = topo["routers"]["r0"]["links"]["r1"][ | |
188 | "ipv4" | |
189 | ].split("/")[0] | |
190 | r0_loopback_address_ipv6 = topo["routers"]["r0"]["links"]["lo"]["ipv6"] | |
191 | r0_loopback_address_ipv6_nxt_hop = topo["routers"]["r0"]["links"]["r1"][ | |
192 | "ipv6" | |
193 | ].split("/")[0] | |
194 | ||
195 | r1_loopback_address_ipv4 = topo["routers"]["r1"]["links"]["lo"]["ipv4"] | |
196 | r1_loopback_address_ipv4_nxt_hop = topo["routers"]["r1"]["links"]["r2"][ | |
197 | "ipv4" | |
198 | ].split("/")[0] | |
199 | r1_loopback_address_ipv6 = topo["routers"]["r1"]["links"]["lo"]["ipv6"] | |
200 | r1_loopback_address_ipv6_nxt_hop = topo["routers"]["r1"]["links"]["r2"][ | |
201 | "ipv6" | |
202 | ].split("/")[0] | |
203 | ||
204 | r4_loopback_address_ipv4 = topo["routers"]["r4"]["links"]["lo"]["ipv4"] | |
205 | r4_loopback_address_ipv4_nxt_hop = topo["routers"]["r4"]["links"]["r3"][ | |
206 | "ipv4" | |
207 | ].split("/")[0] | |
208 | r4_loopback_address_ipv6 = topo["routers"]["r4"]["links"]["lo"]["ipv6"] | |
209 | r4_loopback_address_ipv6_nxt_hop = topo["routers"]["r4"]["links"]["r3"][ | |
210 | "ipv6" | |
211 | ].split("/")[0] | |
212 | ||
213 | r3_loopback_address_ipv4 = topo["routers"]["r3"]["links"]["lo"]["ipv4"] | |
214 | r3_loopback_address_ipv4_nxt_hop = topo["routers"]["r3"]["links"]["r2"][ | |
215 | "ipv4" | |
216 | ].split("/")[0] | |
217 | r3_loopback_address_ipv6 = topo["routers"]["r3"]["links"]["lo"]["ipv6"] | |
218 | r3_loopback_address_ipv6_nxt_hop = topo["routers"]["r3"]["links"]["r2"][ | |
219 | "ipv6" | |
220 | ].split("/")[0] | |
221 | ||
222 | R0_NETWORK_LOOPBACK = { | |
223 | "ipv4": r0_loopback_address_ipv4, | |
224 | "ipv6": r0_loopback_address_ipv6, | |
225 | } | |
226 | R0_NETWORK_LOOPBACK_NXTHOP = { | |
227 | "ipv4": r0_loopback_address_ipv4_nxt_hop, | |
228 | "ipv6": r0_loopback_address_ipv6_nxt_hop, | |
229 | } | |
230 | ||
231 | R1_NETWORK_LOOPBACK = { | |
232 | "ipv4": r1_loopback_address_ipv4, | |
233 | "ipv6": r1_loopback_address_ipv6, | |
234 | } | |
235 | R1_NETWORK_LOOPBACK_NXTHOP = { | |
236 | "ipv4": r1_loopback_address_ipv4_nxt_hop, | |
237 | "ipv6": r1_loopback_address_ipv6_nxt_hop, | |
238 | } | |
239 | ||
240 | R0_NETWORK_CONNECTED = { | |
241 | "ipv4": r0_connected_address_ipv4, | |
242 | "ipv6": r0_connected_address_ipv6, | |
243 | } | |
244 | R0_NETWORK_CONNECTED_NXTHOP = { | |
245 | "ipv4": r0_loopback_address_ipv4_nxt_hop, | |
246 | "ipv6": r0_loopback_address_ipv6_nxt_hop, | |
247 | } | |
248 | ||
249 | R1_NETWORK_CONNECTED = { | |
250 | "ipv4": r1_connected_address_ipv4, | |
251 | "ipv6": r1_connected_address_ipv6, | |
252 | } | |
253 | R1_NETWORK_CONNECTED_NXTHOP = { | |
254 | "ipv4": r1_loopback_address_ipv4_nxt_hop, | |
255 | "ipv6": r1_loopback_address_ipv6_nxt_hop, | |
256 | } | |
257 | ||
258 | R4_NETWORK_LOOPBACK = { | |
259 | "ipv4": r4_loopback_address_ipv4, | |
260 | "ipv6": r4_loopback_address_ipv6, | |
261 | } | |
262 | R4_NETWORK_LOOPBACK_NXTHOP = { | |
263 | "ipv4": r4_loopback_address_ipv4_nxt_hop, | |
264 | "ipv6": r4_loopback_address_ipv6_nxt_hop, | |
265 | } | |
266 | ||
267 | R3_NETWORK_LOOPBACK = { | |
268 | "ipv4": r3_loopback_address_ipv4, | |
269 | "ipv6": r3_loopback_address_ipv6, | |
270 | } | |
271 | R3_NETWORK_LOOPBACK_NXTHOP = { | |
272 | "ipv4": r3_loopback_address_ipv4_nxt_hop, | |
273 | "ipv6": r3_loopback_address_ipv6_nxt_hop, | |
274 | } | |
275 | ||
276 | R4_NETWORK_CONNECTED = { | |
277 | "ipv4": r4_connected_address_ipv4, | |
278 | "ipv6": r4_connected_address_ipv6, | |
279 | } | |
280 | R4_NETWORK_CONNECTED_NXTHOP = { | |
281 | "ipv4": r4_loopback_address_ipv4_nxt_hop, | |
282 | "ipv6": r4_loopback_address_ipv6_nxt_hop, | |
283 | } | |
284 | ||
285 | R3_NETWORK_CONNECTED = { | |
286 | "ipv4": r3_connected_address_ipv4, | |
287 | "ipv6": r3_connected_address_ipv6, | |
288 | } | |
289 | R3_NETWORK_CONNECTED_NXTHOP = { | |
290 | "ipv4": r3_loopback_address_ipv4_nxt_hop, | |
291 | "ipv6": r3_loopback_address_ipv6_nxt_hop, | |
292 | } | |
293 | ||
294 | # populating the nexthop for default routes | |
295 | ||
296 | DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"} | |
297 | ||
298 | interface = topo["routers"]["r1"]["links"]["r2"]["interface"] | |
299 | ipv6_link_local = get_frr_ipv6_linklocal(tgen, "r1", intf=interface) | |
300 | ipv4_nxt_hop = topo["routers"]["r1"]["links"]["r2"]["ipv4"].split("/")[0] | |
301 | ipv6_nxt_hop = topo["routers"]["r1"]["links"]["r2"]["ipv6"].split("/")[0] | |
302 | DEFAULT_ROUTE_NXT_HOP_R1 = {"ipv4": ipv4_nxt_hop, "ipv6": ipv6_link_local} | |
303 | ||
304 | interface = topo["routers"]["r3"]["links"]["r2"]["interface"] | |
305 | ipv6_link_local = get_frr_ipv6_linklocal(tgen, "r3", intf=interface) | |
306 | ipv4_nxt_hop = topo["routers"]["r3"]["links"]["r2"]["ipv4"].split("/")[0] | |
307 | ipv6_nxt_hop = topo["routers"]["r3"]["links"]["r2"]["ipv6"].split("/")[0] | |
308 | DEFAULT_ROUTE_NXT_HOP_R3 = {"ipv4": ipv4_nxt_hop, "ipv6": ipv6_link_local} | |
309 | ||
310 | logger.info("Running setup_module() done") | |
311 | ||
312 | ||
313 | def teardown_module(): | |
314 | """Teardown the pytest environment""" | |
315 | ||
316 | logger.info("Running teardown_module to delete topology") | |
317 | ||
318 | tgen = get_topogen() | |
319 | ||
320 | # Stop toplogy and Remove tmp files | |
321 | tgen.stop_topology() | |
322 | ||
323 | logger.info( | |
324 | "Testsuite end time: {}".format(time.asctime(time.localtime(time.time()))) | |
325 | ) | |
326 | logger.info("=" * 40) | |
327 | ||
328 | ##################################################### | |
329 | # | |
330 | # Testcases | |
331 | # | |
332 | ##################################################### | |
333 | ||
334 | def test_verify_bgp_default_originate_in_IBGP_p0(request): | |
335 | """ | |
336 | Verify BGP default-originate route with IBGP peer | |
337 | """ | |
338 | tgen = get_topogen() | |
339 | global BGP_CONVERGENCE | |
340 | global topo | |
341 | # test case name | |
342 | tc_name = request.node.name | |
343 | write_test_header(tc_name) | |
344 | tgen = get_topogen() | |
345 | # Don't run this test if we have any failure. | |
346 | if tgen.routers_have_failure(): | |
347 | check_router_status(tgen) | |
348 | reset_config_on_routers(tgen) | |
349 | ||
350 | if BGP_CONVERGENCE != True: | |
351 | pytest.skip("skipped because of BGP Convergence failure") | |
352 | ||
353 | step("Configure IPv4 and IPv6 , IBGP neighbor between R1 and R2") | |
354 | step("Configure IPv4 and IPv6 Loopback interface on R1, R0 and R2") | |
355 | step("Configure IPv4 and IPv6 EBGP neighbor between R0 and R1") | |
356 | ||
357 | r0_local_as = topo["routers"]["r0"]["bgp"]["local_as"] | |
358 | r1_local_as = topo["routers"]["r1"]["bgp"]["local_as"] | |
359 | r2_local_as = topo["routers"]["r2"]["bgp"]["local_as"] | |
360 | r3_local_as = topo["routers"]["r3"]["bgp"]["local_as"] | |
361 | r4_local_as = topo["routers"]["r4"]["bgp"]["local_as"] | |
362 | ||
363 | input_dict = { | |
364 | "r0": { | |
365 | "bgp": { | |
366 | "local_as": 1000, | |
367 | } | |
368 | }, | |
369 | "r1": { | |
370 | "bgp": { | |
371 | "local_as": 2000, | |
372 | } | |
373 | }, | |
374 | "r2": { | |
375 | "bgp": { | |
376 | "local_as": 2000, | |
377 | } | |
378 | }, | |
379 | "r3": { | |
380 | "bgp": { | |
381 | "local_as": r3_local_as, | |
382 | } | |
383 | }, | |
384 | "r4": { | |
385 | "bgp": { | |
386 | "local_as": r4_local_as, | |
387 | } | |
388 | }, | |
389 | } | |
390 | result = modify_as_number(tgen, topo, input_dict) | |
391 | try: | |
392 | assert result is True | |
393 | except AssertionError: | |
394 | logger.info("Expected behaviour: {}".format(result)) | |
395 | logger.info("BGP config is not created because of invalid ASNs") | |
396 | ||
397 | step("After changing the BGP AS Path Verify the BGP Convergence") | |
398 | BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo) | |
399 | assert BGP_CONVERGENCE is True, " Complete Convergence is expected after changing the ASN but failed to converge --> :Failed \n Error: {}".format( | |
400 | BGP_CONVERGENCE | |
401 | ) | |
402 | ||
403 | step("Configure IPv4 and IPv6 static route on R1 next-hop as NULL0") | |
404 | for addr_type in ADDR_TYPES: | |
405 | static_routes_input = { | |
406 | "r1": { | |
407 | "static_routes": [ | |
408 | { | |
409 | "network": [NETWORK1_1[addr_type]], | |
410 | "next_hop": NEXT_HOP_IP[addr_type], | |
411 | } | |
412 | ] | |
413 | } | |
414 | } | |
415 | result = create_static_routes(tgen, static_routes_input) | |
416 | assert result is True, "Testcase {} : Failed to configure the static routes {} on router R1 \n Error: {}".format( | |
417 | tc_name,static_routes_input, result | |
418 | ) | |
419 | step("verify IPv4 and IPv6 static route are configured and up on R1") | |
420 | for addr_type in ADDR_TYPES: | |
421 | static_routes_input = { | |
422 | "r1": { | |
423 | "static_routes": [ | |
424 | { | |
425 | "network": [NETWORK1_1[addr_type]], | |
426 | "next_hop": NEXT_HOP_IP[addr_type], | |
427 | } | |
428 | ] | |
429 | } | |
430 | } | |
431 | result = verify_fib_routes(tgen, addr_type, "r1", static_routes_input) | |
432 | assert result is True, "Testcase {} : Failed \n After configuring the static routes {} , the routes are not found in FIB \n Error: {}".format( | |
433 | tc_name,static_routes_input, result | |
434 | ) | |
435 | ||
436 | step( | |
437 | "Configure redistribute static and connected on R0 and R1, for IPv4 and IPv6 address family " | |
438 | ) | |
439 | redistribute_static = { | |
440 | "r0": { | |
441 | "bgp": { | |
442 | "address_family": { | |
443 | "ipv4": { | |
444 | "unicast": { | |
445 | "redistribute": [ | |
446 | {"redist_type": "static"}, | |
447 | {"redist_type": "connected"}, | |
448 | ] | |
449 | } | |
450 | }, | |
451 | "ipv6": { | |
452 | "unicast": { | |
453 | "redistribute": [ | |
454 | {"redist_type": "static"}, | |
455 | {"redist_type": "connected"}, | |
456 | ] | |
457 | } | |
458 | }, | |
459 | } | |
460 | } | |
461 | }, | |
462 | "r1": { | |
463 | "bgp": { | |
464 | "address_family": { | |
465 | "ipv4": { | |
466 | "unicast": { | |
467 | "redistribute": [ | |
468 | {"redist_type": "static"}, | |
469 | {"redist_type": "connected"}, | |
470 | ] | |
471 | } | |
472 | }, | |
473 | "ipv6": { | |
474 | "unicast": { | |
475 | "redistribute": [ | |
476 | {"redist_type": "static"}, | |
477 | {"redist_type": "connected"}, | |
478 | ] | |
479 | } | |
480 | }, | |
481 | } | |
482 | } | |
483 | }, | |
484 | } | |
485 | result = create_router_bgp(tgen, topo, redistribute_static) | |
486 | assert result is True, "Testcase {} : Failed to configure the redistribute static configuration \n Error: {}".format(tc_name, result) | |
487 | ||
488 | step( | |
489 | "After configuring redistribute command , verify static and connected routes ( loopback connected routes) are advertised on R2" | |
490 | ) | |
491 | ||
492 | for addr_type in ADDR_TYPES: | |
493 | static_routes_input = { | |
494 | "r2": { | |
495 | "static_routes": [ | |
496 | { | |
497 | "network": [NETWORK1_1[addr_type]], | |
498 | "next_hop": NEXT_HOP_IP[addr_type], | |
499 | }, | |
500 | { | |
501 | "network": [R0_NETWORK_LOOPBACK[addr_type]], | |
502 | "next_hop": R0_NETWORK_LOOPBACK_NXTHOP[addr_type], | |
503 | }, | |
504 | { | |
505 | "network": [R0_NETWORK_CONNECTED[addr_type]], | |
506 | "next_hop": R0_NETWORK_CONNECTED_NXTHOP[addr_type], | |
507 | }, | |
508 | { | |
509 | "network": [R1_NETWORK_LOOPBACK[addr_type]], | |
510 | "next_hop": R1_NETWORK_LOOPBACK_NXTHOP[addr_type], | |
511 | }, | |
512 | { | |
513 | "network": [R1_NETWORK_CONNECTED[addr_type]], | |
514 | "next_hop": R1_NETWORK_CONNECTED_NXTHOP[addr_type], | |
515 | }, | |
516 | ] | |
517 | } | |
518 | } | |
519 | result = verify_fib_routes(tgen, addr_type, "r2", static_routes_input) | |
520 | assert result is True, "Testcase {} : After redistributing static routes the routes {} expected in FIB but NOT FOUND ......! \n Error: {}".format( | |
521 | tc_name, static_routes_input,result | |
522 | ) | |
523 | ||
524 | result = verify_bgp_rib(tgen, addr_type, "r2", static_routes_input) | |
525 | assert result is True, "Testcase {} : After redistributing static routes the routes {} expected in RIB but NOT FOUND ......! \n Error: {}".format( | |
526 | tc_name, static_routes_input , result | |
527 | ) | |
528 | ||
529 | step( | |
530 | "Taking the snapshot of the prefix count before configuring the default originate" | |
531 | ) | |
532 | snapshot1 = get_prefix_count_route(tgen, topo, dut="r2", peer="r1") | |
533 | ||
534 | step( | |
535 | "Configure Default originate on R1 for R1 to R2, for IPv4 and IPv6 BGP address family " | |
536 | ) | |
537 | local_as = get_dut_as_number(tgen, dut="r1") | |
538 | default_originate_config = { | |
539 | "r1": { | |
540 | "bgp": { | |
541 | "local_as": local_as, | |
542 | "address_family": { | |
543 | "ipv4": {"unicast": {"default_originate": {"r2": {}}}}, | |
544 | "ipv6": {"unicast": {"default_originate": {"r2": {}}}}, | |
545 | }, | |
546 | } | |
547 | } | |
548 | } | |
549 | result = create_router_bgp(tgen, topo, default_originate_config) | |
550 | assert result is True, "Testcase {} : Failed Configuring default originate configuration. \n Error: {}".format(tc_name, result) | |
551 | ||
552 | step( | |
553 | "After configuring default-originate command , verify default routes are advertised on R2 " | |
554 | " R1 static and loopback routes received on R2 BGP and FIB" | |
555 | ) | |
556 | for addr_type in ADDR_TYPES: | |
557 | static_routes_input = { | |
558 | "r2": { | |
559 | "static_routes": [ | |
560 | { | |
561 | "network": [NETWORK1_1[addr_type]], | |
562 | "next_hop": NEXT_HOP_IP[addr_type], | |
563 | }, | |
564 | { | |
565 | "network": [R1_NETWORK_LOOPBACK[addr_type]], | |
566 | "next_hop": R1_NETWORK_LOOPBACK_NXTHOP[addr_type], | |
567 | }, | |
568 | { | |
569 | "network": [R1_NETWORK_CONNECTED[addr_type]], | |
570 | "next_hop": R1_NETWORK_CONNECTED_NXTHOP[addr_type], | |
571 | }, | |
572 | ] | |
573 | } | |
574 | } | |
575 | ||
576 | result = verify_fib_routes(tgen, addr_type, "r2", static_routes_input) | |
577 | assert result is True, "Testcase {} : post configuring the BGP Default originate configuration static and connected routes should not be effected but impacted on FIB .......! FAILED \n Error: {}".format( | |
578 | tc_name, result | |
579 | ) | |
580 | ||
581 | result = verify_bgp_rib(tgen, addr_type, "r2", static_routes_input) | |
582 | assert result is True, "Testcase {} : Failedpost configuring the BGP Default originate configuration static and connected routes should not be effected but impacted on RIB......! FAILED \n Error: {}".format( | |
583 | tc_name, result | |
584 | ) | |
585 | step( | |
586 | "Verify default route for IPv4 and IPv6 present with path=igp metric =0 , local-preference= 100 " | |
587 | ) | |
588 | result = verify_rib_default_route( | |
589 | tgen, | |
590 | topo, | |
591 | dut="r2", | |
592 | routes=DEFAULT_ROUTES, | |
593 | expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R1, | |
594 | metric=0, | |
595 | locPrf=100, | |
596 | ) | |
597 | assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) | |
598 | step( | |
599 | "Taking the snapshot2 of the prefix count after configuring the default originate" | |
600 | ) | |
601 | snapshot2 = get_prefix_count_route(tgen, topo, dut="r2", peer="r1") | |
602 | ||
603 | step("verifying the prefix count incrementing or not ") | |
604 | isIPv4prefix_incremented = False | |
605 | isIPv6prefix_incremented = False | |
606 | if snapshot1["ipv4_count"] < snapshot2["ipv4_count"]: | |
607 | isIPv4prefix_incremented = True | |
608 | if snapshot1["ipv6_count"] < snapshot2["ipv6_count"]: | |
609 | isIPv6prefix_incremented = True | |
610 | ||
611 | assert ( | |
612 | isIPv4prefix_incremented is True | |
613 | ), "Testcase {} : Failed Error: IPV4 Prefix is not incremented on receiveing ".format( | |
614 | tc_name | |
615 | ) | |
616 | ||
617 | assert ( | |
618 | isIPv6prefix_incremented is True | |
619 | ), "Testcase {} : Failed Error: IPV6 Prefix is not incremented on receiveing ".format( | |
620 | tc_name | |
621 | ) | |
622 | write_test_footer(tc_name) | |
623 | ||
624 | ||
625 | def test_verify_bgp_default_originate_in_EBGP_p0(request): | |
626 | """ | |
627 | Verify BGP default-originate route with EBGP peer | |
628 | """ | |
629 | tgen = get_topogen() | |
630 | global BGP_CONVERGENCE | |
631 | global topo | |
632 | # test case name | |
633 | tc_name = request.node.name | |
634 | write_test_header(tc_name) | |
635 | tgen = get_topogen() | |
636 | # Don't run this test if we have any failure. | |
637 | if tgen.routers_have_failure(): | |
638 | check_router_status(tgen) | |
639 | reset_config_on_routers(tgen) | |
640 | ||
641 | if BGP_CONVERGENCE != True: | |
642 | pytest.skip("skipped because of BGP Convergence failure") | |
643 | ||
644 | step("Configure IPv4 and IPv6 , EBGP neighbor between R3 and R2") | |
645 | step("Configure lPv4 and IPv6 Loopback interface on R3, R4 and R2") | |
646 | step("Configure IPv4 and IPv6 IBGP neighbor between R4 and R3") | |
647 | r0_local_as = topo["routers"]["r0"]["bgp"]["local_as"] | |
648 | r1_local_as = topo["routers"]["r1"]["bgp"]["local_as"] | |
649 | r2_local_as = topo["routers"]["r2"]["bgp"]["local_as"] | |
650 | r3_local_as = topo["routers"]["r3"]["bgp"]["local_as"] | |
651 | r4_local_as = topo["routers"]["r4"]["bgp"]["local_as"] | |
652 | ||
653 | input_dict = { | |
654 | "r0": { | |
655 | "bgp": { | |
656 | "local_as": r0_local_as, | |
657 | } | |
658 | }, | |
659 | "r1": { | |
660 | "bgp": { | |
661 | "local_as": r1_local_as, | |
662 | } | |
663 | }, | |
664 | "r2": { | |
665 | "bgp": { | |
666 | "local_as": r2_local_as, | |
667 | } | |
668 | }, | |
669 | "r3": { | |
670 | "bgp": { | |
671 | "local_as": 4000, | |
672 | } | |
673 | }, | |
674 | "r4": { | |
675 | "bgp": { | |
676 | "local_as": 4000, | |
677 | } | |
678 | }, | |
679 | } | |
680 | result = modify_as_number(tgen, topo, input_dict) | |
681 | try: | |
682 | assert result is True | |
683 | except AssertionError: | |
684 | logger.info("Expected behaviour: {}".format(result)) | |
685 | logger.info("BGP config is not created because of invalid ASNs") | |
686 | step("After changing the BGP AS Path Verify the BGP Convergence") | |
687 | ||
688 | BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo) | |
689 | assert BGP_CONVERGENCE is True, "Complete convergence is expeceted after changing the ASN os the routes ..! :Failed \n Error: {}".format( | |
690 | BGP_CONVERGENCE | |
691 | ) | |
692 | ||
693 | step(" Configure IPv4 and IPv6 static route on R3 next-hop on R4 interface") | |
694 | for addr_type in ADDR_TYPES: | |
695 | static_routes_input = { | |
696 | "r3": { | |
697 | "static_routes": [ | |
698 | { | |
699 | "network": [NETWORK1_1[addr_type]], | |
700 | "next_hop": NEXT_HOP_IP[addr_type], | |
701 | } | |
702 | ] | |
703 | } | |
704 | } | |
705 | result = create_static_routes(tgen, static_routes_input) | |
706 | assert result is True, "Testcase {} : Failed to configure the static routes ....! Failed \n Error: {}".format( | |
707 | tc_name, result | |
708 | ) | |
709 | step("verify IPv4 and IPv6 static route are configured and up on R1") | |
710 | for addr_type in ADDR_TYPES: | |
711 | static_routes_input = { | |
712 | "r3": { | |
713 | "static_routes": [ | |
714 | { | |
715 | "network": [NETWORK1_1[addr_type]], | |
716 | "next_hop": NEXT_HOP_IP[addr_type], | |
717 | } | |
718 | ] | |
719 | } | |
720 | } | |
721 | result = verify_fib_routes(tgen, addr_type, "r3", static_routes_input) | |
722 | assert result is True, "Testcase {} : Route is not found in {} in FIB ......! Failed \n Error: {}".format( | |
723 | tc_name, static_routes_input,result | |
724 | ) | |
725 | ||
726 | step( | |
727 | "Configure redistribute static and connected on R3 and R4 for IPv4 and IPv6 address family " | |
728 | ) | |
729 | redistribute_static = { | |
730 | "r3": { | |
731 | "bgp": { | |
732 | "address_family": { | |
733 | "ipv4": { | |
734 | "unicast": { | |
735 | "redistribute": [ | |
736 | {"redist_type": "static"}, | |
737 | {"redist_type": "connected"}, | |
738 | ] | |
739 | } | |
740 | }, | |
741 | "ipv6": { | |
742 | "unicast": { | |
743 | "redistribute": [ | |
744 | {"redist_type": "static"}, | |
745 | {"redist_type": "connected"}, | |
746 | ] | |
747 | } | |
748 | }, | |
749 | } | |
750 | } | |
751 | }, | |
752 | "r4": { | |
753 | "bgp": { | |
754 | "address_family": { | |
755 | "ipv4": { | |
756 | "unicast": { | |
757 | "redistribute": [ | |
758 | {"redist_type": "static"}, | |
759 | {"redist_type": "connected"}, | |
760 | ] | |
761 | } | |
762 | }, | |
763 | "ipv6": { | |
764 | "unicast": { | |
765 | "redistribute": [ | |
766 | {"redist_type": "static"}, | |
767 | {"redist_type": "connected"}, | |
768 | ] | |
769 | } | |
770 | }, | |
771 | } | |
772 | } | |
773 | }, | |
774 | } | |
775 | result = create_router_bgp(tgen, topo, redistribute_static) | |
776 | assert result is True, "Testcase {} : Failed to configure redistribute configuratin \n Error: {}".format(tc_name, result) | |
777 | ||
778 | step( | |
779 | "After configuring redistribute command , verify static and connected routes ( loopback connected routes) are advertised on R2" | |
780 | ) | |
781 | for addr_type in ADDR_TYPES: | |
782 | static_routes_input = { | |
783 | "r2": { | |
784 | "static_routes": [ | |
785 | { | |
786 | "network": [NETWORK1_1[addr_type]], | |
787 | "next_hop": NEXT_HOP_IP[addr_type], | |
788 | }, | |
789 | { | |
790 | "network": [R3_NETWORK_LOOPBACK[addr_type]], | |
791 | "next_hop": R3_NETWORK_LOOPBACK_NXTHOP[addr_type], | |
792 | }, | |
793 | { | |
794 | "network": [R3_NETWORK_CONNECTED[addr_type]], | |
795 | "next_hop": R3_NETWORK_CONNECTED_NXTHOP[addr_type], | |
796 | }, | |
797 | { | |
798 | "network": [R4_NETWORK_LOOPBACK[addr_type]], | |
799 | "next_hop": R4_NETWORK_LOOPBACK_NXTHOP[addr_type], | |
800 | }, | |
801 | { | |
802 | "network": [R4_NETWORK_CONNECTED[addr_type]], | |
803 | "next_hop": R4_NETWORK_CONNECTED_NXTHOP[addr_type], | |
804 | }, | |
805 | ] | |
806 | } | |
807 | } | |
808 | result = verify_fib_routes(tgen, addr_type, "r2", static_routes_input) | |
809 | assert result is True, "Testcase {} : static & and connected routes are expected but not found in FIB .... ! \n Error: {}".format( | |
810 | tc_name, result | |
811 | ) | |
812 | result = verify_bgp_rib(tgen, addr_type, "r2", static_routes_input) | |
813 | assert result is True, "Testcase {} : static & and connected routes are expected but not found in RIB .... ! \n Error: {}".format( | |
814 | tc_name, result | |
815 | ) | |
816 | snapshot1 = get_prefix_count_route(tgen, topo, dut="r2", peer="r3") | |
817 | step( | |
818 | "Configure Default originate on R3 for R3 to R2, on IPv4 and IPv6 BGP address family" | |
819 | ) | |
820 | local_as = get_dut_as_number(tgen, dut="r3") | |
821 | default_originate_config = { | |
822 | "r3": { | |
823 | "bgp": { | |
824 | "local_as": local_as, | |
825 | "address_family": { | |
826 | "ipv4": {"unicast": {"default_originate": {"r2": {}}}}, | |
827 | "ipv6": {"unicast": {"default_originate": {"r2": {}}}}, | |
828 | }, | |
829 | } | |
830 | } | |
831 | } | |
832 | result = create_router_bgp(tgen, topo, default_originate_config) | |
833 | assert result is True, "Testcase {} : Failed to configure the default originate configuration \n Error: {}".format(tc_name, result) | |
834 | ||
835 | step( | |
836 | "After configuring default-originate command , verify default routes are advertised on R2 on both BGP RIB and FIB" | |
837 | ) | |
838 | ||
839 | for addr_type in ADDR_TYPES: | |
840 | static_routes_input = { | |
841 | "r2": { | |
842 | "static_routes": [ | |
843 | { | |
844 | "network": [NETWORK1_1[addr_type]], | |
845 | "next_hop": NEXT_HOP_IP[addr_type], | |
846 | }, | |
847 | { | |
848 | "network": [DEFAULT_ROUTES[addr_type]], | |
849 | "next_hop": DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
850 | }, | |
851 | ] | |
852 | } | |
853 | } | |
854 | ||
855 | result = verify_fib_routes(tgen, addr_type, "r2", static_routes_input) | |
856 | assert result is True, "Testcase {} : static route from R1 {} and default route from R3 is expected in R2 FIB .....! NOT FOUND \n Error: {}".format( | |
857 | tc_name, NETWORK1_1,result | |
858 | ) | |
859 | ||
860 | result = verify_bgp_rib(tgen, addr_type, "r2", static_routes_input) | |
861 | assert result is True, "Testcase {} : static route from R1 {} and default route from R3 is expected in R2 RIB .....! NOT FOUND \n Error: {}".format( | |
862 | tc_name,NETWORK1_1, result | |
863 | ) | |
864 | ||
865 | step( | |
866 | "Verify default route for IPv4 and IPv6 present with path = ebgp as path, metric =0 " | |
867 | ) | |
868 | # local preference will bgp not applicable for eBGP | |
869 | result = verify_rib_default_route( | |
870 | tgen, | |
871 | topo, | |
872 | dut="r2", | |
873 | routes=DEFAULT_ROUTES, | |
874 | expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3, | |
875 | metric=0, | |
876 | expected_aspath="4000", | |
877 | ) | |
878 | assert result is True, "Testcase {} : Default route from R3 is expected with attributes in R2 RIB .....! NOT FOUND Error: {}".format(tc_name, result) | |
879 | ||
880 | step( | |
881 | "Taking the snapshot2 of the prefix count after configuring the default originate" | |
882 | ) | |
883 | snapshot2 = get_prefix_count_route(tgen, topo, dut="r2", peer="r3") | |
884 | step( | |
885 | "Verify out-prefix count is incremented default route on IPv4 and IPv6 neighbor" | |
886 | ) | |
887 | isIPv4prefix_incremented = False | |
888 | isIPv6prefix_incremented = False | |
889 | if snapshot1["ipv4_count"] < snapshot2["ipv4_count"]: | |
890 | isIPv4prefix_incremented = True | |
891 | if snapshot1["ipv6_count"] < snapshot2["ipv6_count"]: | |
892 | isIPv6prefix_incremented = True | |
893 | ||
894 | assert ( | |
895 | isIPv4prefix_incremented is True | |
896 | ), "Testcase {} : Failed Error: IPV4 Prefix is not incremented on receiveing ".format( | |
897 | tc_name | |
898 | ) | |
899 | ||
900 | assert ( | |
901 | isIPv6prefix_incremented is True | |
902 | ), "Testcase {} : Failed Error: IPV6 Prefix is not incremented on receiveing ".format( | |
903 | tc_name | |
904 | ) | |
905 | write_test_footer(tc_name) | |
906 | ||
907 | ||
908 | def test_verify_bgp_default_originate_in_IBGP_with_route_map_p0(request): | |
909 | """ | |
910 | test_verify_bgp_default_originate_in_IBGP_with_route_map_p0 | |
911 | """ | |
912 | tgen = get_topogen() | |
913 | global BGP_CONVERGENCE | |
914 | global topo | |
915 | # test case name | |
916 | tc_name = request.node.name | |
917 | write_test_header(tc_name) | |
918 | tgen = get_topogen() | |
919 | # Don't run this test if we have any failure. | |
920 | if tgen.routers_have_failure(): | |
921 | check_router_status(tgen) | |
922 | reset_config_on_routers(tgen) | |
923 | ||
924 | if BGP_CONVERGENCE != True: | |
925 | pytest.skip("skipped because of BGP Convergence failure") | |
926 | ||
927 | step("Configure IPv4 and IPv6 , IBGP neighbor between R1 and R2") | |
928 | step("Configure IPv4 and IPv6 , EBGP neighbor between R1 and R0") | |
929 | r0_local_as = topo["routers"]["r0"]["bgp"]["local_as"] | |
930 | r1_local_as = topo["routers"]["r1"]["bgp"]["local_as"] | |
931 | r2_local_as = topo["routers"]["r2"]["bgp"]["local_as"] | |
932 | r3_local_as = topo["routers"]["r3"]["bgp"]["local_as"] | |
933 | r4_local_as = topo["routers"]["r4"]["bgp"]["local_as"] | |
934 | ||
935 | input_dict = { | |
936 | "r0": { | |
937 | "bgp": { | |
938 | "local_as": r0_local_as, | |
939 | } | |
940 | }, | |
941 | "r1": { | |
942 | "bgp": { | |
943 | "local_as": 1000, | |
944 | } | |
945 | }, | |
946 | "r2": { | |
947 | "bgp": { | |
948 | "local_as": 1000, | |
949 | } | |
950 | }, | |
951 | "r3": { | |
952 | "bgp": { | |
953 | "local_as": r3_local_as, | |
954 | } | |
955 | }, | |
956 | "r4": { | |
957 | "bgp": { | |
958 | "local_as": r4_local_as, | |
959 | } | |
960 | }, | |
961 | } | |
962 | result = modify_as_number(tgen, topo, input_dict) | |
963 | try: | |
964 | assert result is True | |
965 | except AssertionError: | |
966 | logger.info("Expected behaviour: {}".format(result)) | |
967 | logger.info("BGP config is not created because of invalid ASNs") | |
968 | ||
969 | step("After changing the BGP AS Path Verify the BGP Convergence") | |
970 | BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo) | |
971 | assert BGP_CONVERGENCE is True, "Complete convergence is expected after changing ASN ....! ERROR :Failed \n Error: {}".format( | |
972 | BGP_CONVERGENCE | |
973 | ) | |
974 | ||
975 | step("Configure 2 IPv4 and 2 IPv6 Static route on R0 with next-hop as Null0") | |
976 | for addr_type in ADDR_TYPES: | |
977 | static_routes_input = { | |
978 | "r0": { | |
979 | "static_routes": [ | |
980 | { | |
981 | "network": [NETWORK1_1[addr_type]], | |
982 | "next_hop": NEXT_HOP_IP[addr_type], | |
983 | }, | |
984 | { | |
985 | "network": [NETWORK2_1[addr_type]], | |
986 | "next_hop": NEXT_HOP_IP[addr_type], | |
987 | }, | |
988 | ] | |
989 | } | |
990 | } | |
991 | result = create_static_routes(tgen, static_routes_input) | |
992 | assert result is True, "Testcase {} : Static Configuration is Failed \n Error: {}".format( | |
993 | tc_name, result | |
994 | ) | |
995 | ||
996 | step("verify IPv4 and IPv6 static route are configured and up on R0") | |
997 | for addr_type in ADDR_TYPES: | |
998 | static_routes_input = { | |
999 | "r0": { | |
1000 | "static_routes": [ | |
1001 | { | |
1002 | "network": [NETWORK1_1[addr_type]], | |
1003 | "next_hop": NEXT_HOP_IP[addr_type], | |
1004 | }, | |
1005 | { | |
1006 | "network": [NETWORK2_1[addr_type]], | |
1007 | "next_hop": NEXT_HOP_IP[addr_type], | |
1008 | }, | |
1009 | ] | |
1010 | } | |
1011 | } | |
1012 | result = verify_fib_routes(tgen, addr_type, "r0", static_routes_input) | |
1013 | assert result is True, "Testcase {} : routes {} unable is not found in R0 FIB \n Error: {}".format( | |
1014 | tc_name, static_routes_input,result | |
1015 | ) | |
1016 | ||
1017 | step( | |
1018 | "Configure redistribute static on IPv4 and IPv6 address family on R0 for R0 to R1 neighbor " | |
1019 | ) | |
1020 | redistribute_static = { | |
1021 | "r0": { | |
1022 | "bgp": { | |
1023 | "address_family": { | |
1024 | "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}}, | |
1025 | "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}}, | |
1026 | } | |
1027 | } | |
1028 | } | |
1029 | } | |
1030 | result = create_router_bgp(tgen, topo, redistribute_static) | |
1031 | assert result is True, "Testcase {} : Failed to configure redistribute static configuration....! \n Error: {}".format(tc_name, result) | |
1032 | ||
1033 | step("verify IPv4 and IPv6 static route are configured and up on R1") | |
1034 | for addr_type in ADDR_TYPES: | |
1035 | static_routes_input = { | |
1036 | "r0": { | |
1037 | "static_routes": [ | |
1038 | { | |
1039 | "network": [NETWORK1_1[addr_type]], | |
1040 | "next_hop": NEXT_HOP_IP[addr_type], | |
1041 | }, | |
1042 | { | |
1043 | "network": [NETWORK2_1[addr_type]], | |
1044 | "next_hop": NEXT_HOP_IP[addr_type], | |
1045 | }, | |
1046 | ] | |
1047 | } | |
1048 | } | |
1049 | result = verify_fib_routes(tgen, addr_type, "r1", static_routes_input) | |
1050 | assert result is True, "Testcase {} : Failed... Routes {} expected in r0 FIB after configuring the redistribute config \n Error: {}".format( | |
1051 | tc_name,static_routes_input, result | |
1052 | ) | |
1053 | ||
1054 | result = verify_bgp_rib(tgen, addr_type, "r1", static_routes_input) | |
1055 | assert result is True, "Testcase {} : Failed... Routes {} expected in r0 RIB after configuring the redistribute config \n Error: {}".format( | |
1056 | tc_name, static_routes_input,result | |
1057 | ) | |
1058 | ||
1059 | step( | |
1060 | "Configure IPv4 prefix-list Pv4 and and IPv6 prefix-list Pv6 on R1 to match BGP route Sv41, Sv42, IPv6 route Sv61 Sv62 permit " | |
1061 | ) | |
1062 | input_dict_3 = { | |
1063 | "r1": { | |
1064 | "prefix_lists": { | |
1065 | "ipv4": { | |
1066 | "Pv4": [ | |
1067 | { | |
1068 | "seqid": "1", | |
1069 | "network": NETWORK1_1["ipv4"], | |
1070 | "action": "permit", | |
1071 | }, | |
1072 | { | |
1073 | "seqid": "2", | |
1074 | "network": NETWORK2_1["ipv4"], | |
1075 | "action": "permit", | |
1076 | }, | |
1077 | ] | |
1078 | }, | |
1079 | "ipv6": { | |
1080 | "Pv6": [ | |
1081 | { | |
1082 | "seqid": "1", | |
1083 | "network": NETWORK1_1["ipv6"], | |
1084 | "action": "permit", | |
1085 | }, | |
1086 | { | |
1087 | "seqid": "2", | |
1088 | "network": NETWORK2_1["ipv6"], | |
1089 | "action": "permit", | |
1090 | }, | |
1091 | ] | |
1092 | }, | |
1093 | } | |
1094 | } | |
1095 | } | |
1096 | result = create_prefix_lists(tgen, input_dict_3) | |
1097 | assert result is True, "Testcase {} : Failed to configure the prefix list \n Error: {}".format(tc_name, result) | |
1098 | ||
1099 | step( | |
1100 | "Configure IPV4 and IPv6 route-map (RMv4 and RMv6 ) matching prefix-list (Pv4 and Pv6) respectively on R1" | |
1101 | ) | |
1102 | input_dict_3 = { | |
1103 | "r1": { | |
1104 | "route_maps": { | |
1105 | "RMv4": [ | |
1106 | { | |
1107 | "action": "permit", | |
1108 | "seq_id": "1", | |
1109 | "match": {"ipv4": {"prefix_lists": "Pv4"}}, | |
1110 | }, | |
1111 | ], | |
1112 | "RMv6": [ | |
1113 | { | |
1114 | "action": "permit", | |
1115 | "seq_id": "1", | |
1116 | "match": {"ipv6": {"prefix_lists": "Pv6"}}, | |
1117 | }, | |
1118 | ], | |
1119 | } | |
1120 | } | |
1121 | } | |
1122 | result = create_route_maps(tgen, input_dict_3) | |
1123 | assert result is True, "Testcase {} : Failed to configure the route map \n Error: {}".format(tc_name, result) | |
1124 | ||
1125 | step( | |
1126 | "Configure default-originate with route-map (RMv4 and RMv6) on R1, on BGP IPv4 and IPv6 address family " | |
1127 | ) | |
1128 | local_as = get_dut_as_number(tgen, dut="r1") | |
1129 | default_originate_config = { | |
1130 | "r1": { | |
1131 | "bgp": { | |
1132 | "local_as": local_as, | |
1133 | "address_family": { | |
1134 | "ipv4": { | |
1135 | "unicast": {"default_originate": {"r2": {"route_map": "RMv4"}}} | |
1136 | }, | |
1137 | "ipv6": { | |
1138 | "unicast": {"default_originate": {"r2": {"route_map": "RMv6"}}} | |
1139 | }, | |
1140 | }, | |
1141 | } | |
1142 | } | |
1143 | } | |
1144 | result = create_router_bgp(tgen, topo, default_originate_config) | |
1145 | assert result is True, "Testcase {} : Failed to configure the default originate \n Error: {}".format(tc_name, result) | |
1146 | ||
1147 | step("Verify the default route is received in BGP RIB and FIB") | |
1148 | step( | |
1149 | "After configuring default-originate command , verify default routes are advertised on R2 " | |
1150 | ) | |
1151 | DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"} | |
1152 | for addr_type in ADDR_TYPES: | |
1153 | static_routes_input = { | |
1154 | "r2": { | |
1155 | "static_routes": [ | |
1156 | { | |
1157 | "network": [DEFAULT_ROUTES[addr_type]], | |
1158 | "next_hop": DEFAULT_ROUTE_NXT_HOP_R1[addr_type], | |
1159 | } | |
1160 | ] | |
1161 | } | |
1162 | } | |
1163 | result = verify_fib_routes( | |
1164 | tgen, | |
1165 | addr_type, | |
1166 | "r2", | |
1167 | static_routes_input, | |
1168 | next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type], | |
1169 | ) | |
1170 | assert result is True, "Testcase {} : Failed...! Expected default route from R1 not found in FIB \n Error: {}".format( | |
1171 | tc_name, result | |
1172 | ) | |
1173 | ||
1174 | result = verify_bgp_rib( | |
1175 | tgen, | |
1176 | addr_type, | |
1177 | "r2", | |
1178 | static_routes_input, | |
1179 | next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type], | |
1180 | ) | |
1181 | assert result is True, "Testcase {} : Failed...! Expected default route from R1 not found in RIB \n Error: {}".format( | |
1182 | tc_name, result | |
1183 | ) | |
1184 | step("Remove route-map RMv4 and RMv6 from default-originate command in R1") | |
1185 | NOTE = """ Configuring the default-originate should remove the previously applied default originate with condtional route-map""" | |
1186 | local_as = get_dut_as_number(tgen, dut="r1") | |
1187 | default_originate_config = { | |
1188 | "r1": { | |
1189 | "bgp": { | |
1190 | "local_as": local_as, | |
1191 | "address_family": { | |
1192 | "ipv4": {"unicast": {"default_originate": {"r2": {}}}}, | |
1193 | "ipv6": {"unicast": {"default_originate": {"r2": {}}}}, | |
1194 | }, | |
1195 | } | |
1196 | } | |
1197 | } | |
1198 | result = create_router_bgp(tgen, topo, default_originate_config) | |
1199 | assert result is True, "Testcase {} : Failed to remove the default originate conditional route-map \n Error: {}".format(tc_name, result) | |
1200 | ||
1201 | step( | |
1202 | "Verify BGP RIB and FIB After removing route-map , default route still present on R2" | |
1203 | ) | |
1204 | DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"} | |
1205 | for addr_type in ADDR_TYPES: | |
1206 | static_routes_input = { | |
1207 | "r2": { | |
1208 | "static_routes": [ | |
1209 | { | |
1210 | "network": [DEFAULT_ROUTES[addr_type]], | |
1211 | "next_hop": DEFAULT_ROUTE_NXT_HOP_R1[addr_type], | |
1212 | } | |
1213 | ] | |
1214 | } | |
1215 | } | |
1216 | ||
1217 | result = verify_fib_routes( | |
1218 | tgen, | |
1219 | addr_type, | |
1220 | "r2", | |
1221 | static_routes_input, | |
1222 | next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type], | |
1223 | ) | |
1224 | assert result is True, "Testcase {} : Failed Default route from R1 is not found in FIB \n Error: {}".format( | |
1225 | tc_name, result | |
1226 | ) | |
1227 | ||
1228 | result = verify_bgp_rib( | |
1229 | tgen, | |
1230 | addr_type, | |
1231 | "r2", | |
1232 | static_routes_input, | |
1233 | next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type], | |
1234 | ) | |
1235 | assert result is True, "Testcase {} : Failed Default route from R1 is not found in RIB \n Error: {}".format( | |
1236 | tc_name, result | |
1237 | ) | |
1238 | ||
1239 | step("Configure default-originate with route-map (RMv4 and RMv6) on R1 ") | |
1240 | local_as = get_dut_as_number(tgen, dut="r1") | |
1241 | default_originate_config = { | |
1242 | "r1": { | |
1243 | "bgp": { | |
1244 | "local_as": local_as, | |
1245 | "address_family": { | |
1246 | "ipv4": { | |
1247 | "unicast": { | |
1248 | "default_originate": { | |
1249 | "r2": { | |
1250 | "route_map": "RMv4", | |
1251 | } | |
1252 | } | |
1253 | } | |
1254 | }, | |
1255 | "ipv6": { | |
1256 | "unicast": { | |
1257 | "default_originate": { | |
1258 | "r2": { | |
1259 | "route_map": "RMv6", | |
1260 | } | |
1261 | } | |
1262 | } | |
1263 | }, | |
1264 | }, | |
1265 | } | |
1266 | } | |
1267 | } | |
1268 | result = create_router_bgp(tgen, topo, default_originate_config) | |
1269 | assert result is True, "Testcase {} : Failed to configure the Default originate route-map \n Error: {}".format(tc_name, result) | |
1270 | ||
1271 | step( | |
1272 | "After configuring default-originate command , verify default routes are advertised on R2 " | |
1273 | ) | |
1274 | for addr_type in ADDR_TYPES: | |
1275 | static_routes_input = { | |
1276 | "r2": { | |
1277 | "static_routes": [ | |
1278 | { | |
1279 | "network": [DEFAULT_ROUTES[addr_type]], | |
1280 | "next_hop": DEFAULT_ROUTE_NXT_HOP_R1[addr_type], | |
1281 | } | |
1282 | ] | |
1283 | } | |
1284 | } | |
1285 | ||
1286 | result = verify_fib_routes( | |
1287 | tgen, | |
1288 | addr_type, | |
1289 | "r2", | |
1290 | static_routes_input, | |
1291 | next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type], | |
1292 | ) | |
1293 | assert result is True, "Testcase {} : Failed Default Route from R1 is not found in FIB \n Error: {}".format( | |
1294 | tc_name, result | |
1295 | ) | |
1296 | ||
1297 | result = verify_bgp_rib( | |
1298 | tgen, | |
1299 | addr_type, | |
1300 | "r2", | |
1301 | static_routes_input, | |
1302 | next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type], | |
1303 | ) | |
1304 | assert result is True, "Testcase {} : Failed Default Route from R1 is not found in RIB \n Error: {}".format( | |
1305 | tc_name, result | |
1306 | ) | |
1307 | ||
1308 | step("Delete prefix list using no prefix-list") | |
1309 | input_dict_3 = { | |
1310 | "r1": { | |
1311 | "prefix_lists": { | |
1312 | "ipv4": { | |
1313 | "Pv4": [ | |
1314 | { | |
1315 | "seqid": "1", | |
1316 | "network": NETWORK1_1["ipv4"], | |
1317 | "action": "permit", | |
1318 | "delete": True, | |
1319 | }, | |
1320 | { | |
1321 | "seqid": "2", | |
1322 | "network": NETWORK2_1["ipv4"], | |
1323 | "action": "permit", | |
1324 | "delete": True, | |
1325 | }, | |
1326 | ] | |
1327 | }, | |
1328 | "ipv6": { | |
1329 | "Pv6": [ | |
1330 | { | |
1331 | "seqid": "1", | |
1332 | "network": NETWORK1_1["ipv6"], | |
1333 | "action": "permit", | |
1334 | "delete": True, | |
1335 | }, | |
1336 | { | |
1337 | "seqid": "2", | |
1338 | "network": NETWORK2_1["ipv6"], | |
1339 | "action": "permit", | |
1340 | "delete": True, | |
1341 | }, | |
1342 | ] | |
1343 | }, | |
1344 | } | |
1345 | } | |
1346 | } | |
1347 | result = create_prefix_lists(tgen, input_dict_3) | |
1348 | assert result is True, "Testcase {} : Failed to delete the prefix list Error: {}".format(tc_name, result) | |
1349 | ||
1350 | step( | |
1351 | "Verify BGP RIB and FIB After deleting prefix-list , verify IPv4 and IPv6 default route got removed from DUT " | |
1352 | ) | |
1353 | DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"} | |
1354 | for addr_type in ADDR_TYPES: | |
1355 | static_routes_input = { | |
1356 | "r2": { | |
1357 | "static_routes": [ | |
1358 | { | |
1359 | "network": [DEFAULT_ROUTES[addr_type]], | |
1360 | "next_hop": DEFAULT_ROUTE_NXT_HOP_R1[addr_type], | |
1361 | } | |
1362 | ] | |
1363 | } | |
1364 | } | |
1365 | result = verify_fib_routes( | |
1366 | tgen, | |
1367 | addr_type, | |
1368 | "r2", | |
1369 | static_routes_input, | |
1370 | next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type], | |
1371 | expected=False, | |
1372 | ) | |
1373 | assert ( | |
1374 | result is not True | |
1375 | ), "Testcase {} : Failed\n After deleteing prefix default route is not expected in FIB \n Error: {}".format( | |
1376 | tc_name, result | |
1377 | ) | |
1378 | ||
1379 | result = verify_bgp_rib( | |
1380 | tgen, | |
1381 | addr_type, | |
1382 | "r2", | |
1383 | static_routes_input, | |
1384 | next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type], | |
1385 | expected=False, | |
1386 | ) | |
1387 | assert ( | |
1388 | result is not True | |
1389 | ), "Testcase {} : Failed \n After deleteing prefix default route is not expected in RIB \n Error: {}".format( | |
1390 | tc_name, result | |
1391 | ) | |
1392 | ||
1393 | step("Configure prefix-list and delete route-map using no route-map") | |
1394 | input_dict_3 = { | |
1395 | "r1": { | |
1396 | "prefix_lists": { | |
1397 | "ipv4": { | |
1398 | "Pv4": [ | |
1399 | { | |
1400 | "seqid": "1", | |
1401 | "network": NETWORK1_1["ipv4"], | |
1402 | "action": "permit", | |
1403 | }, | |
1404 | { | |
1405 | "seqid": "2", | |
1406 | "network": NETWORK2_1["ipv4"], | |
1407 | "action": "permit", | |
1408 | }, | |
1409 | ] | |
1410 | }, | |
1411 | "ipv6": { | |
1412 | "Pv6": [ | |
1413 | { | |
1414 | "seqid": "1", | |
1415 | "network": NETWORK1_1["ipv6"], | |
1416 | "action": "permit", | |
1417 | }, | |
1418 | { | |
1419 | "seqid": "2", | |
1420 | "network": NETWORK2_1["ipv6"], | |
1421 | "action": "permit", | |
1422 | }, | |
1423 | ] | |
1424 | }, | |
1425 | } | |
1426 | } | |
1427 | } | |
1428 | result = create_prefix_lists(tgen, input_dict_3) | |
1429 | assert result is True, "Testcase {} : Failed to configure the prefix lists Error: {}".format(tc_name, result) | |
1430 | ||
1431 | step( | |
1432 | "After configuring the Prefixlist cross checking the BGP Default route is configured again , before deleting the route map" | |
1433 | ) | |
1434 | ||
1435 | DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"} | |
1436 | for addr_type in ADDR_TYPES: | |
1437 | static_routes_input = { | |
1438 | "r2": { | |
1439 | "static_routes": [ | |
1440 | { | |
1441 | "network": [DEFAULT_ROUTES[addr_type]], | |
1442 | "next_hop": DEFAULT_ROUTE_NXT_HOP_R1[addr_type], | |
1443 | } | |
1444 | ] | |
1445 | } | |
1446 | } | |
1447 | result = verify_fib_routes( | |
1448 | tgen, | |
1449 | addr_type, | |
1450 | "r2", | |
1451 | static_routes_input, | |
1452 | next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type], | |
1453 | expected=True, | |
1454 | ) | |
1455 | assert result is True, "Testcase {} : Failed Default route from R1 is expected in FIB but not found \n Error: {}".format( | |
1456 | tc_name, result | |
1457 | ) | |
1458 | ||
1459 | result = verify_bgp_rib( | |
1460 | tgen, | |
1461 | addr_type, | |
1462 | "r2", | |
1463 | static_routes_input, | |
1464 | next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type], | |
1465 | expected=True, | |
1466 | ) | |
1467 | assert result is True, "Testcase {} : Failed Default route from R1 is expected in RIB but not found \n Error: {}".format( | |
1468 | tc_name, result | |
1469 | ) | |
1470 | ||
1471 | step("Deleting the routemap") | |
1472 | input_dict = {"r1": {"route_maps": ["RMv4", "RMv6"]}} | |
1473 | result = delete_route_maps(tgen, input_dict) | |
1474 | assert result is True, "Testcase {} : Failed to delete the Route-map \n Error: {}".format(tc_name, result) | |
1475 | ||
1476 | step( | |
1477 | "Verify BGP RIB and FIB ,After deleting route-map , verify IPv4 and IPv6 default route got removed from DUT" | |
1478 | ) | |
1479 | DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"} | |
1480 | for addr_type in ADDR_TYPES: | |
1481 | static_routes_input = { | |
1482 | "r2": { | |
1483 | "static_routes": [ | |
1484 | { | |
1485 | "network": [DEFAULT_ROUTES[addr_type]], | |
1486 | "next_hop": DEFAULT_ROUTE_NXT_HOP_R1[addr_type], | |
1487 | } | |
1488 | ] | |
1489 | } | |
1490 | } | |
1491 | ||
1492 | result = verify_fib_routes( | |
1493 | tgen, | |
1494 | addr_type, | |
1495 | "r2", | |
1496 | static_routes_input, | |
1497 | next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type], | |
1498 | expected=False, | |
1499 | ) | |
1500 | assert ( | |
1501 | result is not True | |
1502 | ), "Testcase {} : Failed \n After deleteing route-map default route is not expected in FIB \nError: {}".format( | |
1503 | tc_name, result | |
1504 | ) | |
1505 | ||
1506 | result = verify_bgp_rib( | |
1507 | tgen, | |
1508 | addr_type, | |
1509 | "r2", | |
1510 | static_routes_input, | |
1511 | next_hop=DEFAULT_ROUTE_NXT_HOP_R1[addr_type], | |
1512 | expected=False, | |
1513 | ) | |
1514 | assert ( | |
1515 | result is not True | |
1516 | ), "Testcase {} : Failed \n After deleteing route-map default route is not expected in RIB \n Error: {}".format( | |
1517 | tc_name, result | |
1518 | ) | |
1519 | ||
1520 | write_test_footer(tc_name) | |
1521 | ||
1522 | ||
1523 | def test_verify_bgp_default_originate_in_EBGP_with_route_map_p0(request): | |
1524 | """ | |
1525 | test_verify_bgp_default_originate_in_EBGP_with_route_map_p0 | |
1526 | """ | |
1527 | tgen = get_topogen() | |
1528 | global BGP_CONVERGENCE | |
1529 | global topo | |
1530 | # test case name | |
1531 | tc_name = request.node.name | |
1532 | write_test_header(tc_name) | |
1533 | tgen = get_topogen() | |
1534 | # Don't run this test if we have any failure. | |
1535 | if tgen.routers_have_failure(): | |
1536 | check_router_status(tgen) | |
1537 | reset_config_on_routers(tgen) | |
1538 | ||
1539 | if BGP_CONVERGENCE != True: | |
1540 | pytest.skip("skipped because of BGP Convergence failure") | |
1541 | ||
1542 | step("Configure IPv4 and IPv6 , EBGP neighbor between R3 and R2") | |
1543 | step("Configure IPv4 and IPv6 IBGP neighbor between R3 and R4") | |
1544 | r0_local_as = topo["routers"]["r0"]["bgp"]["local_as"] | |
1545 | r1_local_as = topo["routers"]["r1"]["bgp"]["local_as"] | |
1546 | r2_local_as = topo["routers"]["r2"]["bgp"]["local_as"] | |
1547 | r3_local_as = topo["routers"]["r3"]["bgp"]["local_as"] | |
1548 | r4_local_as = topo["routers"]["r4"]["bgp"]["local_as"] | |
1549 | ||
1550 | input_dict = { | |
1551 | "r0": { | |
1552 | "bgp": { | |
1553 | "local_as": r0_local_as, | |
1554 | } | |
1555 | }, | |
1556 | "r1": { | |
1557 | "bgp": { | |
1558 | "local_as": r1_local_as, | |
1559 | } | |
1560 | }, | |
1561 | "r2": { | |
1562 | "bgp": { | |
1563 | "local_as": r2_local_as, | |
1564 | } | |
1565 | }, | |
1566 | "r3": { | |
1567 | "bgp": { | |
1568 | "local_as": 4000, | |
1569 | } | |
1570 | }, | |
1571 | "r4": { | |
1572 | "bgp": { | |
1573 | "local_as": 4000, | |
1574 | } | |
1575 | }, | |
1576 | } | |
1577 | result = modify_as_number(tgen, topo, input_dict) | |
1578 | try: | |
1579 | assert result is True | |
1580 | except AssertionError: | |
1581 | logger.info("Expected behaviour: {}".format(result)) | |
1582 | logger.info("BGP config is not created because of invalid ASNs") | |
1583 | step("After changing the BGP AS Path Verify the BGP Convergence") | |
1584 | BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo) | |
1585 | assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error: {}".format( | |
1586 | BGP_CONVERGENCE | |
1587 | ) | |
1588 | ||
1589 | step( | |
1590 | "Configure 2 IPv4 and 2 IPv6, Static route on R4 with next-hop as Null0 IPv4 route Sv41, Sv42, IPv6 route Sv61 Sv62" | |
1591 | ) | |
1592 | for addr_type in ADDR_TYPES: | |
1593 | static_routes_input = { | |
1594 | "r4": { | |
1595 | "static_routes": [ | |
1596 | { | |
1597 | "network": [NETWORK1_1[addr_type]], | |
1598 | "next_hop": NEXT_HOP_IP[addr_type], | |
1599 | }, | |
1600 | { | |
1601 | "network": [NETWORK2_1[addr_type]], | |
1602 | "next_hop": NEXT_HOP_IP[addr_type], | |
1603 | }, | |
1604 | ] | |
1605 | } | |
1606 | } | |
1607 | result = create_static_routes(tgen, static_routes_input) | |
1608 | assert result is True, "Testcase {} : Failed to configure the static routes \n Error: {}".format( | |
1609 | tc_name, result | |
1610 | ) | |
1611 | step("verify IPv4 and IPv6 static route are configured and up on R4") | |
1612 | for addr_type in ADDR_TYPES: | |
1613 | static_routes_input = { | |
1614 | "r4": { | |
1615 | "static_routes": [ | |
1616 | { | |
1617 | "network": [NETWORK1_1[addr_type]], | |
1618 | "next_hop": NEXT_HOP_IP[addr_type], | |
1619 | }, | |
1620 | { | |
1621 | "network": [NETWORK2_1[addr_type]], | |
1622 | "next_hop": NEXT_HOP_IP[addr_type], | |
1623 | }, | |
1624 | ] | |
1625 | } | |
1626 | } | |
1627 | result = verify_fib_routes(tgen, addr_type, "r4", static_routes_input) | |
1628 | assert result is True, "Testcase {} : Failed Static route {} is not found in R4 FIB \n Error: {}".format( | |
1629 | tc_name, static_routes_input,result | |
1630 | ) | |
1631 | ||
1632 | step( | |
1633 | "Configure redistribute static on IPv4 and IPv6 address family on R4 for R4 to R3 neighbo" | |
1634 | ) | |
1635 | redistribute_static = { | |
1636 | "r4": { | |
1637 | "bgp": { | |
1638 | "address_family": { | |
1639 | "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}}, | |
1640 | "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}}, | |
1641 | } | |
1642 | } | |
1643 | } | |
1644 | } | |
1645 | result = create_router_bgp(tgen, topo, redistribute_static) | |
1646 | assert result is True, "Testcase {} : Failed to configure the redistribute static \n Error: {}".format(tc_name, result) | |
1647 | ||
1648 | step("verify IPv4 and IPv6 static route are configured and up on R3") | |
1649 | for addr_type in ADDR_TYPES: | |
1650 | static_routes_input = { | |
1651 | "r3": { | |
1652 | "static_routes": [ | |
1653 | { | |
1654 | "network": [NETWORK1_1[addr_type]], | |
1655 | "next_hop": NEXT_HOP_IP[addr_type], | |
1656 | }, | |
1657 | { | |
1658 | "network": [NETWORK2_1[addr_type]], | |
1659 | "next_hop": NEXT_HOP_IP[addr_type], | |
1660 | }, | |
1661 | ] | |
1662 | } | |
1663 | } | |
1664 | result = verify_fib_routes(tgen, addr_type, "r3", static_routes_input) | |
1665 | assert result is True, "Testcase {} : Failed static routes from R1 and R3 is not found in FIB \n Error: {}".format( | |
1666 | tc_name, result | |
1667 | ) | |
1668 | result = verify_bgp_rib(tgen, addr_type, "r3", static_routes_input) | |
1669 | assert result is True, "Testcase {} : Failed static routes from R1 and R3 is not found in RIB \n Error: {}".format( | |
1670 | tc_name, result | |
1671 | ) | |
1672 | ||
1673 | step( | |
1674 | "Configure IPv4 prefix-list Pv4 and and IPv6 prefix-list Pv6 on R3 so new route which is not present on R3" | |
1675 | ) | |
1676 | input_dict_3 = { | |
1677 | "r3": { | |
1678 | "prefix_lists": { | |
1679 | "ipv4": { | |
1680 | "Pv4": [ | |
1681 | { | |
1682 | "seqid": "1", | |
1683 | "network": NETWORK3_1["ipv4"], | |
1684 | "action": "permit", | |
1685 | } | |
1686 | ] | |
1687 | }, | |
1688 | "ipv6": { | |
1689 | "Pv6": [ | |
1690 | { | |
1691 | "seqid": "1", | |
1692 | "network": NETWORK3_1["ipv6"], | |
1693 | "action": "permit", | |
1694 | } | |
1695 | ] | |
1696 | }, | |
1697 | } | |
1698 | } | |
1699 | } | |
1700 | result = create_prefix_lists(tgen, input_dict_3) | |
1701 | assert result is True, "Testcase {} : Failed to configure the prefix lists \n Error: {}".format(tc_name, result) | |
1702 | ||
1703 | step("verify IPv4 and IPv6 Prefix list got configured on R3") | |
1704 | input_dict = {"r3": {"prefix_lists": ["Pv4", "Pv6"]}} | |
1705 | result = verify_prefix_lists(tgen, input_dict) | |
1706 | assert result is True, "Testcase {} : Failed ..! configured prefix lists {} are not found \n Error: {}".format(tc_name,input_dict, result) | |
1707 | ||
1708 | step( | |
1709 | "Configure IPv4 and IPv6 route-map ( RMv4 and RMv6 ) matching prefix-list (Pv4 and Pv6 ) respectively on R3" | |
1710 | ) | |
1711 | input_dict_3 = { | |
1712 | "r3": { | |
1713 | "route_maps": { | |
1714 | "RMv4": [ | |
1715 | { | |
1716 | "action": "permit", | |
1717 | "seq_id": "1", | |
1718 | "match": {"ipv4": {"prefix_lists": "Pv4"}}, | |
1719 | }, | |
1720 | ], | |
1721 | "RMv6": [ | |
1722 | { | |
1723 | "action": "permit", | |
1724 | "seq_id": "1", | |
1725 | "match": {"ipv6": {"prefix_lists": "Pv6"}}, | |
1726 | }, | |
1727 | ], | |
1728 | } | |
1729 | } | |
1730 | } | |
1731 | result = create_route_maps(tgen, input_dict_3) | |
1732 | assert result is True, "Testcase {} : Failed to configure the route-map \n Error: {}".format(tc_name, result) | |
1733 | step( | |
1734 | "Taking the snapshot of the prefix count before configuring the default originate" | |
1735 | ) | |
1736 | snapshot1 = get_prefix_count_route(tgen, topo, dut="r2", peer="r3") | |
1737 | step( | |
1738 | "Configure default-originate with IPv4 and IPv6 route-map (RMv4 and RMv6) on R3" | |
1739 | ) | |
1740 | local_as = get_dut_as_number(tgen, dut="r3") | |
1741 | default_originate_config = { | |
1742 | "r3": { | |
1743 | "bgp": { | |
1744 | "local_as": local_as, | |
1745 | "address_family": { | |
1746 | "ipv4": { | |
1747 | "unicast": {"default_originate": {"r2": {"route_map": "RMv4"}}} | |
1748 | }, | |
1749 | "ipv6": { | |
1750 | "unicast": {"default_originate": {"r2": {"route_map": "RMv6"}}} | |
1751 | }, | |
1752 | }, | |
1753 | } | |
1754 | } | |
1755 | } | |
1756 | result = create_router_bgp(tgen, topo, default_originate_config) | |
1757 | assert result is True, "Testcase {} : Failed to configure default-originate \n Error: {}".format(tc_name, result) | |
1758 | ||
1759 | step("Verify the default route is NOT received in BGP RIB and FIB on R2 ") | |
1760 | step( | |
1761 | "After configuring default-originate command , verify default routes are not Received on R2 " | |
1762 | ) | |
1763 | for addr_type in ADDR_TYPES: | |
1764 | static_routes_input = { | |
1765 | "r2": { | |
1766 | "static_routes": [ | |
1767 | { | |
1768 | "network": [DEFAULT_ROUTES[addr_type]], | |
1769 | "next_hop": DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
1770 | } | |
1771 | ] | |
1772 | } | |
1773 | } | |
1774 | ||
1775 | result = verify_fib_routes( | |
1776 | tgen, | |
1777 | addr_type, | |
1778 | "r2", | |
1779 | static_routes_input, | |
1780 | next_hop=DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
1781 | expected=False, | |
1782 | ) | |
1783 | assert ( | |
1784 | result is not True | |
1785 | ), "Testcase {} : Failed \n Default route is not expected due to deny in prefix list \nError: {}".format( | |
1786 | tc_name, result | |
1787 | ) | |
1788 | ||
1789 | result = verify_bgp_rib( | |
1790 | tgen, | |
1791 | addr_type, | |
1792 | "r2", | |
1793 | static_routes_input, | |
1794 | next_hop=DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
1795 | expected=False, | |
1796 | ) | |
1797 | assert ( | |
1798 | result is not True | |
1799 | ), "Testcase {} : Failed \nDefault route is not expected due to deny in prefix list\n Error: {}".format( | |
1800 | tc_name, result | |
1801 | ) | |
1802 | ||
1803 | step("Add route Sv41, Sv42, IPv6 route Sv61 Sv62 on prefix list Pv4 and Pv6") | |
1804 | input_dict_3 = { | |
1805 | "r3": { | |
1806 | "prefix_lists": { | |
1807 | "ipv4": { | |
1808 | "Pv4": [ | |
1809 | { | |
1810 | "seqid": "1", | |
1811 | "network": NETWORK1_1["ipv4"], | |
1812 | "action": "permit", | |
1813 | }, | |
1814 | { | |
1815 | "seqid": "2", | |
1816 | "network": NETWORK2_1["ipv4"], | |
1817 | "action": "permit", | |
1818 | }, | |
1819 | ] | |
1820 | }, | |
1821 | "ipv6": { | |
1822 | "Pv6": [ | |
1823 | { | |
1824 | "seqid": "1", | |
1825 | "network": NETWORK1_1["ipv6"], | |
1826 | "action": "permit", | |
1827 | }, | |
1828 | { | |
1829 | "seqid": "2", | |
1830 | "network": NETWORK2_1["ipv6"], | |
1831 | "action": "permit", | |
1832 | }, | |
1833 | ] | |
1834 | }, | |
1835 | } | |
1836 | } | |
1837 | } | |
1838 | result = create_prefix_lists(tgen, input_dict_3) | |
1839 | assert result is True, "Testcase {} : Failed to configure the prefix lists Error: {}".format(tc_name, result) | |
1840 | ||
1841 | step("Verify BGP default route for IPv4 and IPv6 is received on R2") | |
1842 | ||
1843 | for addr_type in ADDR_TYPES: | |
1844 | static_routes_input = { | |
1845 | "r2": { | |
1846 | "static_routes": [ | |
1847 | { | |
1848 | "network": [DEFAULT_ROUTES[addr_type]], | |
1849 | "next_hop": DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
1850 | } | |
1851 | ] | |
1852 | } | |
1853 | } | |
1854 | ||
1855 | result = verify_fib_routes( | |
1856 | tgen, | |
1857 | addr_type, | |
1858 | "r2", | |
1859 | static_routes_input, | |
1860 | next_hop=DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
1861 | ) | |
1862 | assert result is True, "Testcase {} : Failed Default routes are expected in R2 FIB from R3 but not found ....! \n Error: {}".format( | |
1863 | tc_name, result | |
1864 | ) | |
1865 | ||
1866 | result = verify_bgp_rib( | |
1867 | tgen, | |
1868 | addr_type, | |
1869 | "r2", | |
1870 | static_routes_input, | |
1871 | next_hop=DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
1872 | ) | |
1873 | assert result is True, "Testcase {} : Failed Default routes are expected in R2 RIB from R3 but not found ....! \n Error: {}".format( | |
1874 | tc_name, result | |
1875 | ) | |
1876 | ||
1877 | step("Remove route Sv41, Sv42, IPv6 route Sv61 Sv62 on prefix list Pv4 and Pv6") | |
1878 | input_dict_3 = { | |
1879 | "r3": { | |
1880 | "prefix_lists": { | |
1881 | "ipv4": { | |
1882 | "Pv4": [ | |
1883 | { | |
1884 | "seqid": "1", | |
1885 | "network": NETWORK1_1["ipv4"], | |
1886 | "action": "permit", | |
1887 | "delete": True, | |
1888 | }, | |
1889 | { | |
1890 | "seqid": "2", | |
1891 | "network": NETWORK2_1["ipv4"], | |
1892 | "action": "permit", | |
1893 | "delete": True, | |
1894 | }, | |
1895 | ] | |
1896 | }, | |
1897 | "ipv6": { | |
1898 | "Pv6": [ | |
1899 | { | |
1900 | "seqid": "1", | |
1901 | "network": NETWORK1_1["ipv6"], | |
1902 | "action": "permit", | |
1903 | "delete": True, | |
1904 | }, | |
1905 | { | |
1906 | "seqid": "2", | |
1907 | "network": NETWORK2_1["ipv6"], | |
1908 | "action": "permit", | |
1909 | "delete": True, | |
1910 | }, | |
1911 | ] | |
1912 | }, | |
1913 | } | |
1914 | } | |
1915 | } | |
1916 | result = create_prefix_lists(tgen, input_dict_3) | |
1917 | assert result is True, "Testcase {} : Failed to remove prefix-lists from R3 Error: {}".format(tc_name, result) | |
1918 | ||
1919 | step( | |
1920 | "After Removing route BGP default route for IPv4 and IPv6 is NOT received on R2" | |
1921 | ) | |
1922 | for addr_type in ADDR_TYPES: | |
1923 | static_routes_input = { | |
1924 | "r2": { | |
1925 | "static_routes": [ | |
1926 | { | |
1927 | "network": [DEFAULT_ROUTES[addr_type]], | |
1928 | "next_hop": DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
1929 | } | |
1930 | ] | |
1931 | } | |
1932 | } | |
1933 | ||
1934 | result = verify_fib_routes( | |
1935 | tgen, | |
1936 | addr_type, | |
1937 | "r2", | |
1938 | static_routes_input, | |
1939 | next_hop=DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
1940 | expected=False, | |
1941 | ) | |
1942 | assert ( | |
1943 | result is not True | |
1944 | ), "Testcase {} : Failed \n After Removing route in prefix list the default route is not expected in FIB \n Error: {}".format( | |
1945 | tc_name, result | |
1946 | ) | |
1947 | ||
1948 | result = verify_bgp_rib( | |
1949 | tgen, | |
1950 | addr_type, | |
1951 | "r2", | |
1952 | static_routes_input, | |
1953 | next_hop=DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
1954 | expected=False, | |
1955 | ) | |
1956 | assert ( | |
1957 | result is not True | |
1958 | ), "Testcase {} : Failed \n After Removing route in prefix list the default route is not expected in RIB\n Error: {}".format( | |
1959 | tc_name, result | |
1960 | ) | |
1961 | ||
1962 | step(" Add route Sv41, Sv42, IPv6 route Sv61 Sv62 on prefix list Pv4 and Pv6") | |
1963 | input_dict_3 = { | |
1964 | "r3": { | |
1965 | "prefix_lists": { | |
1966 | "ipv4": { | |
1967 | "Pv4": [ | |
1968 | { | |
1969 | "seqid": "1", | |
1970 | "network": NETWORK1_1["ipv4"], | |
1971 | "action": "permit", | |
1972 | }, | |
1973 | { | |
1974 | "seqid": "2", | |
1975 | "network": NETWORK2_1["ipv4"], | |
1976 | "action": "permit", | |
1977 | }, | |
1978 | ] | |
1979 | }, | |
1980 | "ipv6": { | |
1981 | "Pv6": [ | |
1982 | { | |
1983 | "seqid": "1", | |
1984 | "network": NETWORK1_1["ipv6"], | |
1985 | "action": "permit", | |
1986 | }, | |
1987 | { | |
1988 | "seqid": "2", | |
1989 | "network": NETWORK2_1["ipv6"], | |
1990 | "action": "permit", | |
1991 | }, | |
1992 | ] | |
1993 | }, | |
1994 | } | |
1995 | } | |
1996 | } | |
1997 | result = create_prefix_lists(tgen, input_dict_3) | |
1998 | assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) | |
1999 | ||
2000 | step("Verify BGP default route for IPv4 and IPv6 is received on R2") | |
2001 | ||
2002 | for addr_type in ADDR_TYPES: | |
2003 | static_routes_input = { | |
2004 | "r2": { | |
2005 | "static_routes": [ | |
2006 | { | |
2007 | "network": [DEFAULT_ROUTES[addr_type]], | |
2008 | "next_hop": DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
2009 | } | |
2010 | ] | |
2011 | } | |
2012 | } | |
2013 | ||
2014 | result = verify_fib_routes( | |
2015 | tgen, | |
2016 | addr_type, | |
2017 | "r2", | |
2018 | static_routes_input, | |
2019 | next_hop=DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
2020 | ) | |
2021 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
2022 | tc_name, result | |
2023 | ) | |
2024 | ||
2025 | result = verify_bgp_rib( | |
2026 | tgen, | |
2027 | addr_type, | |
2028 | "r2", | |
2029 | static_routes_input, | |
2030 | next_hop=DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
2031 | ) | |
2032 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
2033 | tc_name, result | |
2034 | ) | |
2035 | ||
2036 | step("Change IPv4 and IPv6 prefix-list permit and deny ") | |
2037 | input_dict_3 = { | |
2038 | "r3": { | |
2039 | "prefix_lists": { | |
2040 | "ipv4": { | |
2041 | "Pv4": [ | |
2042 | {"seqid": "1", "network": NETWORK1_1["ipv4"], "action": "deny"}, | |
2043 | {"seqid": "2", "network": NETWORK2_1["ipv4"], "action": "deny"}, | |
2044 | ] | |
2045 | }, | |
2046 | "ipv6": { | |
2047 | "Pv6": [ | |
2048 | {"seqid": "1", "network": NETWORK1_1["ipv6"], "action": "deny"}, | |
2049 | {"seqid": "2", "network": NETWORK2_1["ipv6"], "action": "deny"}, | |
2050 | ] | |
2051 | }, | |
2052 | } | |
2053 | } | |
2054 | } | |
2055 | result = create_prefix_lists(tgen, input_dict_3) | |
2056 | assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) | |
2057 | ||
2058 | step("Verify BGP default route for IPv4 and IPv6 is not received on R2") | |
2059 | ||
2060 | for addr_type in ADDR_TYPES: | |
2061 | static_routes_input = { | |
2062 | "r2": { | |
2063 | "static_routes": [ | |
2064 | { | |
2065 | "network": [DEFAULT_ROUTES[addr_type]], | |
2066 | "next_hop": DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
2067 | } | |
2068 | ] | |
2069 | } | |
2070 | } | |
2071 | ||
2072 | result = verify_fib_routes( | |
2073 | tgen, | |
2074 | addr_type, | |
2075 | "r2", | |
2076 | static_routes_input, | |
2077 | next_hop=DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
2078 | expected=False, | |
2079 | ) | |
2080 | assert ( | |
2081 | result is not True | |
2082 | ), "Testcase {} : Failed \n after denying the prefix list default route is not expected in FIB \n Error: {}".format( | |
2083 | tc_name, result | |
2084 | ) | |
2085 | ||
2086 | result = verify_bgp_rib( | |
2087 | tgen, | |
2088 | addr_type, | |
2089 | "r2", | |
2090 | static_routes_input, | |
2091 | next_hop=DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
2092 | expected=False, | |
2093 | ) | |
2094 | assert ( | |
2095 | result is not True | |
2096 | ), "Testcase {} : Failed \n after denying the prefix list default route is not expected in RIB \n Error: {}".format( | |
2097 | tc_name, result | |
2098 | ) | |
2099 | ||
2100 | step("Change IPv4 and IPv6 prefix-list deny to permit ") | |
2101 | input_dict_3 = { | |
2102 | "r3": { | |
2103 | "prefix_lists": { | |
2104 | "ipv4": { | |
2105 | "Pv4": [ | |
2106 | { | |
2107 | "seqid": "1", | |
2108 | "network": NETWORK1_1["ipv4"], | |
2109 | "action": "permit", | |
2110 | }, | |
2111 | { | |
2112 | "seqid": "2", | |
2113 | "network": NETWORK2_1["ipv4"], | |
2114 | "action": "permit", | |
2115 | }, | |
2116 | ] | |
2117 | }, | |
2118 | "ipv6": { | |
2119 | "Pv6": [ | |
2120 | { | |
2121 | "seqid": "1", | |
2122 | "network": NETWORK1_1["ipv6"], | |
2123 | "action": "permit", | |
2124 | }, | |
2125 | { | |
2126 | "seqid": "2", | |
2127 | "network": NETWORK2_1["ipv6"], | |
2128 | "action": "permit", | |
2129 | }, | |
2130 | ] | |
2131 | }, | |
2132 | } | |
2133 | } | |
2134 | } | |
2135 | result = create_prefix_lists(tgen, input_dict_3) | |
2136 | assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result) | |
2137 | ||
2138 | step("Verify BGP default route for IPv4 and IPv6 is received on R2") | |
2139 | for addr_type in ADDR_TYPES: | |
2140 | static_routes_input = { | |
2141 | "r2": { | |
2142 | "static_routes": [ | |
2143 | { | |
2144 | "network": [DEFAULT_ROUTES[addr_type]], | |
2145 | "next_hop": DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
2146 | } | |
2147 | ] | |
2148 | } | |
2149 | } | |
2150 | ||
2151 | result = verify_fib_routes( | |
2152 | tgen, | |
2153 | addr_type, | |
2154 | "r2", | |
2155 | static_routes_input, | |
2156 | next_hop=DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
2157 | ) | |
2158 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
2159 | tc_name, result | |
2160 | ) | |
2161 | ||
2162 | result = verify_bgp_rib( | |
2163 | tgen, | |
2164 | addr_type, | |
2165 | "r2", | |
2166 | static_routes_input, | |
2167 | next_hop=DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
2168 | ) | |
2169 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
2170 | tc_name, result | |
2171 | ) | |
2172 | ||
2173 | step( | |
2174 | "Taking the snapshot2 of the prefix count after configuring the default originate" | |
2175 | ) | |
2176 | snapshot2 = get_prefix_count_route(tgen, topo, dut="r2", peer="r3") | |
2177 | ||
2178 | step("verifying the prefix count incrementing or not ") | |
2179 | isIPv4prefix_incremented = False | |
2180 | isIPv6prefix_incremented = False | |
2181 | if snapshot1["ipv4_count"] < snapshot2["ipv4_count"]: | |
2182 | isIPv4prefix_incremented = True | |
2183 | if snapshot1["ipv6_count"] < snapshot2["ipv6_count"]: | |
2184 | isIPv6prefix_incremented = True | |
2185 | ||
2186 | assert ( | |
2187 | isIPv4prefix_incremented is True | |
2188 | ), "Testcase {} : Failed Error: IPV4 Prefix is not incremented on receiveing ".format( | |
2189 | tc_name | |
2190 | ) | |
2191 | ||
2192 | assert ( | |
2193 | isIPv6prefix_incremented is True | |
2194 | ), "Testcase {} : Failed Error: IPV6 Prefix is not incremented on receiveing ".format( | |
2195 | tc_name | |
2196 | ) | |
2197 | ||
2198 | step( | |
2199 | "Configure another IPv4 and IPv6 route-map and match same prefix-list (Sv41, Sv42, IPv6 route Sv61 Sv62) with deny statement " | |
2200 | ) | |
2201 | input_dict_3 = { | |
2202 | "r3": { | |
2203 | "route_maps": { | |
2204 | "RMv41": [ | |
2205 | { | |
2206 | "action": "deny", | |
2207 | "seq_id": "1", | |
2208 | "match": {"ipv4": {"prefix_lists": "Pv4"}}, | |
2209 | }, | |
2210 | ], | |
2211 | "RMv61": [ | |
2212 | { | |
2213 | "action": "deny", | |
2214 | "seq_id": "1", | |
2215 | "match": {"ipv6": {"prefix_lists": "Pv6"}}, | |
2216 | }, | |
2217 | ], | |
2218 | } | |
2219 | } | |
2220 | } | |
2221 | result = create_route_maps(tgen, input_dict_3) | |
2222 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2223 | ||
2224 | step("Attach route-map on IPv4 and IP6 BGP neighbor on fly") | |
2225 | local_as = get_dut_as_number(tgen, dut="r3") | |
2226 | default_originate_config = { | |
2227 | "r3": { | |
2228 | "bgp": { | |
2229 | "local_as": local_as, | |
2230 | "address_family": { | |
2231 | "ipv4": { | |
2232 | "unicast": {"default_originate": {"r2": {"route_map": "RMv41"}}} | |
2233 | }, | |
2234 | "ipv6": { | |
2235 | "unicast": {"default_originate": {"r2": {"route_map": "RMv61"}}} | |
2236 | }, | |
2237 | }, | |
2238 | } | |
2239 | } | |
2240 | } | |
2241 | result = create_router_bgp(tgen, topo, default_originate_config) | |
2242 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2243 | ||
2244 | step( | |
2245 | "After attaching route-map verify IPv4 and IPv6 default route is withdrawn from the R2" | |
2246 | ) | |
2247 | for addr_type in ADDR_TYPES: | |
2248 | static_routes_input = { | |
2249 | "r2": { | |
2250 | "static_routes": [ | |
2251 | { | |
2252 | "network": [DEFAULT_ROUTES[addr_type]], | |
2253 | "next_hop": DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
2254 | } | |
2255 | ] | |
2256 | } | |
2257 | } | |
2258 | ||
2259 | result = verify_fib_routes( | |
2260 | tgen, | |
2261 | addr_type, | |
2262 | "r2", | |
2263 | static_routes_input, | |
2264 | next_hop=DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
2265 | expected=False, | |
2266 | ) | |
2267 | assert result is not True, "Testcase {} : Failed \n Error: {}".format( | |
2268 | tc_name, result | |
2269 | ) | |
2270 | ||
2271 | result = verify_bgp_rib( | |
2272 | tgen, | |
2273 | addr_type, | |
2274 | "r2", | |
2275 | static_routes_input, | |
2276 | next_hop=DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
2277 | expected=False, | |
2278 | ) | |
2279 | assert result is not True, "Testcase {} : Failed \n Error: {}".format( | |
2280 | tc_name, result | |
2281 | ) | |
2282 | ||
2283 | step("Change the recently added Routemap from deny to permit") | |
2284 | input_dict_3 = { | |
2285 | "r3": { | |
2286 | "route_maps": { | |
2287 | "RMv41": [ | |
2288 | { | |
2289 | "action": "permit", | |
2290 | "seq_id": "1", | |
2291 | "match": {"ipv4": {"prefix_lists": "Pv4"}}, | |
2292 | }, | |
2293 | ], | |
2294 | "RMv61": [ | |
2295 | { | |
2296 | "action": "permit", | |
2297 | "seq_id": "1", | |
2298 | "match": {"ipv6": {"prefix_lists": "Pv6"}}, | |
2299 | }, | |
2300 | ], | |
2301 | } | |
2302 | } | |
2303 | } | |
2304 | result = create_route_maps(tgen, input_dict_3) | |
2305 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2306 | ||
2307 | step("Verify IPv4 and IPv6 default route is advertised from the R2") | |
2308 | for addr_type in ADDR_TYPES: | |
2309 | static_routes_input = { | |
2310 | "r2": { | |
2311 | "static_routes": [ | |
2312 | { | |
2313 | "network": [DEFAULT_ROUTES[addr_type]], | |
2314 | "next_hop": DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
2315 | } | |
2316 | ] | |
2317 | } | |
2318 | } | |
2319 | ||
2320 | result = verify_fib_routes( | |
2321 | tgen, | |
2322 | addr_type, | |
2323 | "r2", | |
2324 | static_routes_input, | |
2325 | next_hop=DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
2326 | ) | |
2327 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
2328 | tc_name, result | |
2329 | ) | |
2330 | ||
2331 | result = verify_bgp_rib( | |
2332 | tgen, | |
2333 | addr_type, | |
2334 | "r2", | |
2335 | static_routes_input, | |
2336 | next_hop=DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
2337 | ) | |
2338 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
2339 | tc_name, result | |
2340 | ) | |
2341 | ||
2342 | step( | |
2343 | "Delete default-originate route-map command while configuring ( neighbor x.x.x default-originate) for IPv4 and IPv6 BGP neighbor " | |
2344 | ) | |
2345 | """ Configuring the Default originate on neighbor must remove the previously assigned deault-originate with routemap config """ | |
2346 | local_as = get_dut_as_number(tgen, dut="r3") | |
2347 | default_originate_config = { | |
2348 | "r3": { | |
2349 | "bgp": { | |
2350 | "local_as": local_as, | |
2351 | "address_family": { | |
2352 | "ipv4": {"unicast": {"default_originate": {"r2": {}}}}, | |
2353 | "ipv6": {"unicast": {"default_originate": {"r2": {}}}}, | |
2354 | }, | |
2355 | } | |
2356 | } | |
2357 | } | |
2358 | result = create_router_bgp(tgen, topo, default_originate_config) | |
2359 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2360 | ||
2361 | step( | |
2362 | "Verify in running config from BGP that default-originate with route-map command is removed and default-originate command is still present and default route for IPv4 and IPv6 present in RIB and FIB" | |
2363 | ) | |
2364 | for addr_type in ADDR_TYPES: | |
2365 | static_routes_input = { | |
2366 | "r2": { | |
2367 | "static_routes": [ | |
2368 | { | |
2369 | "network": [DEFAULT_ROUTES[addr_type]], | |
2370 | "next_hop": DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
2371 | } | |
2372 | ] | |
2373 | } | |
2374 | } | |
2375 | ||
2376 | result = verify_fib_routes( | |
2377 | tgen, | |
2378 | addr_type, | |
2379 | "r2", | |
2380 | static_routes_input, | |
2381 | next_hop=DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
2382 | ) | |
2383 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
2384 | tc_name, result | |
2385 | ) | |
2386 | ||
2387 | result = verify_bgp_rib( | |
2388 | tgen, | |
2389 | addr_type, | |
2390 | "r2", | |
2391 | static_routes_input, | |
2392 | next_hop=DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
2393 | ) | |
2394 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
2395 | tc_name, result | |
2396 | ) | |
2397 | ||
2398 | step( | |
2399 | "Configure default-originate with conditional route-map command on IPv4 and IPv6 address family " | |
2400 | ) | |
2401 | local_as = get_dut_as_number(tgen, dut="r3") | |
2402 | default_originate_config = { | |
2403 | "r3": { | |
2404 | "bgp": { | |
2405 | "local_as": local_as, | |
2406 | "address_family": { | |
2407 | "ipv4": { | |
2408 | "unicast": {"default_originate": {"r2": {"route_map": "RMv41"}}} | |
2409 | }, | |
2410 | "ipv6": { | |
2411 | "unicast": {"default_originate": {"r2": {"route_map": "RMv61"}}} | |
2412 | }, | |
2413 | }, | |
2414 | } | |
2415 | } | |
2416 | } | |
2417 | result = create_router_bgp(tgen, topo, default_originate_config) | |
2418 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2419 | ||
2420 | step( | |
2421 | "Verify in running config from BGP that default-originate with route-map command is present and default route for IPv4 and IPv6 present" | |
2422 | ) | |
2423 | for addr_type in ADDR_TYPES: | |
2424 | static_routes_input = { | |
2425 | "r2": { | |
2426 | "static_routes": [ | |
2427 | { | |
2428 | "network": [DEFAULT_ROUTES[addr_type]], | |
2429 | "next_hop": DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
2430 | } | |
2431 | ] | |
2432 | } | |
2433 | } | |
2434 | ||
2435 | result = verify_fib_routes( | |
2436 | tgen, | |
2437 | addr_type, | |
2438 | "r2", | |
2439 | static_routes_input, | |
2440 | next_hop=DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
2441 | ) | |
2442 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
2443 | tc_name, result | |
2444 | ) | |
2445 | ||
2446 | result = verify_bgp_rib( | |
2447 | tgen, | |
2448 | addr_type, | |
2449 | "r2", | |
2450 | static_routes_input, | |
2451 | next_hop=DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
2452 | ) | |
2453 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
2454 | tc_name, result | |
2455 | ) | |
2456 | ||
2457 | step( | |
2458 | "Delete default originate with 'no bgp default-originate' from IPV4 and IPV6 address family " | |
2459 | ) | |
2460 | local_as = get_dut_as_number(tgen, dut="r3") | |
2461 | default_originate_config = { | |
2462 | "r3": { | |
2463 | "bgp": { | |
2464 | "local_as": local_as, | |
2465 | "address_family": { | |
2466 | "ipv4": { | |
2467 | "unicast": {"default_originate": {"r2": {"delete": True}}} | |
2468 | }, | |
2469 | "ipv6": { | |
2470 | "unicast": {"default_originate": {"r2": {"delete": True}}} | |
2471 | }, | |
2472 | }, | |
2473 | } | |
2474 | } | |
2475 | } | |
2476 | result = create_router_bgp(tgen, topo, default_originate_config) | |
2477 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2478 | ||
2479 | step( | |
2480 | " Verify in running config from BGP that default-originate complete CLI is removed for IPV4 and IPV6 address family and default originate routes got deleted" | |
2481 | ) | |
2482 | for addr_type in ADDR_TYPES: | |
2483 | static_routes_input = { | |
2484 | "r2": { | |
2485 | "static_routes": [ | |
2486 | { | |
2487 | "network": [DEFAULT_ROUTES[addr_type]], | |
2488 | "next_hop": DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
2489 | } | |
2490 | ] | |
2491 | } | |
2492 | } | |
2493 | ||
2494 | result = verify_fib_routes( | |
2495 | tgen, | |
2496 | addr_type, | |
2497 | "r2", | |
2498 | static_routes_input, | |
2499 | next_hop=DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
2500 | expected=False, | |
2501 | ) | |
2502 | assert ( | |
2503 | result is not True | |
2504 | ), "Testcase {} : Failed \n Default Route is not expected in FIB \nError: {}".format( | |
2505 | tc_name, result | |
2506 | ) | |
2507 | ||
2508 | result = verify_bgp_rib( | |
2509 | tgen, | |
2510 | addr_type, | |
2511 | "r2", | |
2512 | static_routes_input, | |
2513 | next_hop=DEFAULT_ROUTE_NXT_HOP_R3[addr_type], | |
2514 | expected=False, | |
2515 | ) | |
2516 | assert ( | |
2517 | result is not True | |
2518 | ), "Testcase {} : Failed \n Default Route is not expected in RIB\nError: {}".format( | |
2519 | tc_name, result | |
2520 | ) | |
2521 | ||
2522 | write_test_footer(tc_name) | |
2523 | ||
2524 | ||
2525 | if __name__ == "__main__": | |
2526 | args = ["-s"] + sys.argv[1:] | |
2527 | sys.exit(pytest.main(args)) |