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