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