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