]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_default_originate/test_default_originate_conditional_routemap.py
Merge pull request #12830 from anlancs/fix/doc-ripd-rst
[mirror_frr.git] / tests / topotests / bgp_default_originate / test_default_originate_conditional_routemap.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 scenerios are covered.
11 1. When there is change in route-map policy associated with default-originate, changes does not reflect.
12 2. When route-map associated with default-originate is deleted, default route doesn't get withdrawn
13 3. Update message is not being sent when only route-map is removed from the default-originate config.
14 4. SNT counter gets incremented on change of every policy associated with default-originate
15 5. Route-map with multiple match clauses causes inconsistencies with default-originate.
16 6. BGP-Default originate behaviour with BGP attributes
17 """
18 import os
19 import sys
20 import time
21 import pytest
22 from copy import deepcopy
23 from lib.topolog import logger
24
25 # pylint: disable=C0413
26 # Import topogen and topotest helpers
27 from lib.topogen import Topogen, get_topogen
28 from lib.topojson import build_config_from_json
29 from lib.topolog import logger
30
31 from lib.bgp import (
32 verify_bgp_convergence,
33 create_router_bgp,
34 get_prefix_count_route,
35 modify_as_number,
36 verify_bgp_rib,
37 get_dut_as_number,
38 verify_rib_default_route,
39 verify_fib_default_route,
40 )
41 from lib.common_config import (
42 verify_fib_routes,
43 step,
44 required_linux_kernel_version,
45 create_route_maps,
46 interface_status,
47 create_prefix_lists,
48 get_frr_ipv6_linklocal,
49 start_topology,
50 write_test_header,
51 verify_prefix_lists,
52 check_address_types,
53 write_test_footer,
54 reset_config_on_routers,
55 create_static_routes,
56 check_router_status,
57 delete_route_maps,
58 )
59
60 # Save the Current Working Directory to find configuration files.
61 CWD = os.path.dirname(os.path.realpath(__file__))
62 sys.path.append(os.path.join(CWD, "../"))
63 sys.path.append(os.path.join(CWD, "../lib/"))
64
65 pytestmark = [pytest.mark.bgpd, pytest.mark.staticd]
66
67 # Required to instantiate the topology builder class.
68
69 # pylint: disable=C0413
70 # Import topogen and topotest helpers
71
72 # Global variables
73 topo = None
74 NETWORK1_1 = {"ipv4": "198.51.1.1/32", "ipv6": "2001:DB8::1:1/128"}
75 DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
76 NEXT_HOP_IP = {"ipv4": "Null0", "ipv6": "Null0"}
77
78 def setup_module(mod):
79 """
80 Sets up the pytest environment
81
82 * `mod`: module name
83 """
84
85 # Required linux kernel version for this suite to run.
86 result = required_linux_kernel_version("4.15")
87 if result is not True:
88 pytest.skip("Kernel requirements are not met")
89
90 testsuite_run_time = time.asctime(time.localtime(time.time()))
91 logger.info("Testsuite start time: {}".format(testsuite_run_time))
92 logger.info("=" * 40)
93
94 logger.info("Running setup_module to create topology")
95
96 # This function initiates the topology build with Topogen...
97 json_file = "{}/bgp_default_originate_topo1.json".format(CWD)
98 tgen = Topogen(json_file, mod.__name__)
99 global topo
100 topo = tgen.json_topo
101 # ... and here it calls Mininet initialization functions.
102
103 # Starting topology, create tmp files which are loaded to routers
104 # to start daemons and then start routers
105 start_topology(tgen)
106
107 # Creating configuration from JSON
108 build_config_from_json(tgen, topo)
109
110 global ADDR_TYPES
111 global BGP_CONVERGENCE
112 global DEFAULT_ROUTES
113 global DEFAULT_ROUTE_NXT_HOP_R1, DEFAULT_ROUTE_NXT_HOP_R3
114 ADDR_TYPES = check_address_types()
115 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
116 assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error: {}".format(
117 BGP_CONVERGENCE
118 )
119
120 DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
121
122 interface = topo["routers"]["r1"]["links"]["r2"]["interface"]
123 ipv6_link_local = get_frr_ipv6_linklocal(tgen, "r1", intf=interface)
124 ipv4_nxt_hop = topo["routers"]["r1"]["links"]["r2"]["ipv4"].split("/")[0]
125 ipv6_nxt_hop = topo["routers"]["r1"]["links"]["r2"]["ipv6"].split("/")[0]
126 DEFAULT_ROUTE_NXT_HOP_R1 = {"ipv4": ipv4_nxt_hop, "ipv6": ipv6_link_local}
127
128 interface = topo["routers"]["r3"]["links"]["r2"]["interface"]
129 ipv6_link_local = get_frr_ipv6_linklocal(tgen, "r3", intf=interface)
130 ipv4_nxt_hop = topo["routers"]["r3"]["links"]["r2"]["ipv4"].split("/")[0]
131 ipv6_nxt_hop = topo["routers"]["r3"]["links"]["r2"]["ipv6"].split("/")[0]
132 DEFAULT_ROUTE_NXT_HOP_R3 = {"ipv4": ipv4_nxt_hop, "ipv6": ipv6_link_local}
133
134 logger.info("Running setup_module() done")
135
136
137 def teardown_module():
138 """Teardown the pytest environment"""
139
140 logger.info("Running teardown_module to delete topology")
141
142 tgen = get_topogen()
143
144 # Stop toplogy and Remove tmp files
145 tgen.stop_topology()
146
147 logger.info(
148 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
149 )
150 logger.info("=" * 40)
151
152
153 #####################################################
154 #
155 # Testcases
156 #
157 #####################################################
158
159
160 def test_default_originate_delete_conditional_routemap(request):
161 """
162 "scenerio covered":
163 1. When there is change in route-map policy associated with default-originate, changes does not reflect.
164 2. When route-map associated with default-originate is deleted, default route doesn't get withdrawn
165 3. Update message is not being sent when only route-map is removed from the default-originate config.
166 4. SNT counter gets incremented on change of every policy associated with default-originate
167 5. Route-map with multiple match clauses causes inconsistencies with default-originate.
168 """
169 tgen = get_topogen()
170 global BGP_CONVERGENCE
171 global topo
172 tc_name = request.node.name
173 write_test_header(tc_name)
174 tgen = get_topogen()
175 if tgen.routers_have_failure():
176 check_router_status(tgen)
177 reset_config_on_routers(tgen)
178
179 if BGP_CONVERGENCE != True:
180 pytest.skip("skipped because of BGP Convergence failure")
181
182 step("Configure IPv4 and IPv6 , IBGP neighbor between R1 and R2")
183 step("Configure IPv4 and IPv6 , EBGP neighbor between R1 and R0")
184 input_dict = {
185 "r0": {
186 "bgp": {
187 "local_as": 999,
188 }
189 },
190 "r1": {
191 "bgp": {
192 "local_as": 1000,
193 }
194 },
195 "r2": {
196 "bgp": {
197 "local_as": 1000,
198 }
199 },
200 "r3": {
201 "bgp": {
202 "local_as": 2000,
203 }
204 },
205 "r4": {
206 "bgp": {
207 "local_as": 3000,
208 }
209 },
210 }
211 result = modify_as_number(tgen, topo, input_dict)
212 try:
213 assert result is True
214 except AssertionError:
215 logger.info("Expected behaviour: {}".format(result))
216 logger.info("BGP config is not created because of invalid ASNs")
217
218 step("After changing the BGP remote as , Verify the BGP Convergence")
219 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
220 assert (
221 BGP_CONVERGENCE is True
222 ), "Complete convergence is expected after changing ASN ....! ERROR :Failed \n Error: {}".format(
223 BGP_CONVERGENCE
224 )
225
226 step("Configure 1 IPv4 and 1 IPv6 Static route on R0 with next-hop as Null0")
227 for addr_type in ADDR_TYPES:
228 static_routes_input = {
229 "r0": {
230 "static_routes": [
231 {
232 "network": [NETWORK1_1[addr_type]],
233 "next_hop": NEXT_HOP_IP[addr_type],
234 }
235 ]
236 }
237 }
238 result = create_static_routes(tgen, static_routes_input)
239 assert (
240 result is True
241 ), "Testcase {} : Failed to configure the static route \n Error: {}".format(
242 tc_name, result
243 )
244
245 step("verify IPv4 and IPv6 static route are configured and up on R0")
246 for addr_type in ADDR_TYPES:
247 static_routes_input = {
248 "r0": {
249 "static_routes": [
250 {
251 "network": [NETWORK1_1[addr_type]],
252 "next_hop": NEXT_HOP_IP[addr_type],
253 },
254 ]
255 }
256 }
257 result = verify_fib_routes(tgen, addr_type, "r0", static_routes_input)
258 assert (
259 result is True
260 ), "Testcase {} : routes {} not found in R0 FIB \n Error: {}".format(
261 tc_name, static_routes_input, result
262 )
263
264 step(
265 "Configure redistribute static on IPv4 and IPv6 address family on R0 for R0 to R1 neighbor "
266 )
267 redistribute_static = {
268 "r0": {
269 "bgp": {
270 "address_family": {
271 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
272 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
273 }
274 }
275 }
276 }
277 result = create_router_bgp(tgen, topo, redistribute_static)
278 assert (
279 result is True
280 ), "Testcase {} : Failed to configure redistribute configuration....! \n Error: {}".format(
281 tc_name, result
282 )
283
284 step("verify IPv4 and IPv6 static route are received on R1")
285 for addr_type in ADDR_TYPES:
286 static_routes_input = {
287 "r0": {
288 "static_routes": [
289 {
290 "network": [NETWORK1_1[addr_type]],
291 "next_hop": NEXT_HOP_IP[addr_type],
292 },
293 ]
294 }
295 }
296 result = verify_fib_routes(tgen, addr_type, "r1", static_routes_input)
297 assert (
298 result is True
299 ), "Testcase {} : Failed... Routes {} expected in r1 FIB after configuring the redistribute config on R0 \n Error: {}".format(
300 tc_name, static_routes_input, result
301 )
302
303 result = verify_bgp_rib(tgen, addr_type, "r1", static_routes_input)
304 assert (
305 result is True
306 ), "Testcase {} : Failed... Routes {} expected in r1 RIB after configuring the redistribute config on R0\n Error: {}".format(
307 tc_name, static_routes_input, result
308 )
309
310 step(
311 "Configure IPv4 prefix-list 'Pv4' and and IPv6 prefix-list 'Pv6' on R1 to match BGP route Sv41, IPv6 route Sv61 permit "
312 )
313 input_dict_3 = {
314 "r1": {
315 "prefix_lists": {
316 "ipv4": {
317 "Pv4": [
318 {
319 "seqid": "1",
320 "network": NETWORK1_1["ipv4"],
321 "action": "permit",
322 },
323 ]
324 },
325 "ipv6": {
326 "Pv6": [
327 {
328 "seqid": "1",
329 "network": NETWORK1_1["ipv6"],
330 "action": "permit",
331 },
332 ]
333 },
334 }
335 }
336 }
337 result = create_prefix_lists(tgen, input_dict_3)
338 assert (
339 result is True
340 ), "Testcase {} : Failed to configure the prefix list \n Error: {}".format(
341 tc_name, result
342 )
343
344 step(
345 "Configure IPV4 and IPv6 route-map (RMv4 and RMv6) matching prefix-list (Pv4 and Pv6) respectively on R1"
346 )
347 input_dict_3 = {
348 "r1": {
349 "route_maps": {
350 "RMv4": [
351 {
352 "action": "permit",
353 "seq_id": "1",
354 "match": {"ipv4": {"prefix_lists": "Pv4"}},
355 "set": {
356 "path": {
357 "as_num": "5555",
358 "as_action": "prepend",
359 }
360 },
361 },
362 ],
363 "RMv6": [
364 {
365 "action": "permit",
366 "seq_id": "1",
367 "match": {"ipv6": {"prefix_lists": "Pv6"}},
368 "set": {
369 "path": {
370 "as_num": "5555",
371 "as_action": "prepend",
372 }
373 },
374 },
375 ],
376 }
377 }
378 }
379 result = create_route_maps(tgen, input_dict_3)
380 assert (
381 result is True
382 ), "Testcase {} : Failed to configure the route map \n Error: {}".format(
383 tc_name, result
384 )
385
386 step(
387 "Configure default-originate with route-map (RMv4 and RMv6) on R1, on BGP IPv4 and IPv6 address family "
388 )
389 local_as = get_dut_as_number(tgen, dut="r1")
390 default_originate_config = {
391 "r1": {
392 "bgp": {
393 "local_as": local_as,
394 "address_family": {
395 "ipv4": {
396 "unicast": {"default_originate": {"r2": {"route_map": "RMv4"}}}
397 },
398 "ipv6": {
399 "unicast": {"default_originate": {"r2": {"route_map": "RMv6"}}}
400 },
401 },
402 }
403 }
404 }
405 result = create_router_bgp(tgen, topo, default_originate_config)
406 assert (
407 result is True
408 ), "Testcase {} : Failed to configure the default originate \n Error: {}".format(
409 tc_name, result
410 )
411
412 step(
413 "After configuring default-originate command , verify default routes are advertised on R2 "
414 )
415 DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
416 result = verify_rib_default_route(
417 tgen,
418 topo,
419 dut="r2",
420 routes=DEFAULT_ROUTES,
421 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R1,
422 metric=0,
423 expected_aspath="5555",
424 )
425 assert (
426 result is True
427 ), "Testcase {} : Failed to configure the default originate \n Error: {}".format(
428 tc_name, result
429 )
430
431 result = verify_fib_default_route(
432 tgen,
433 topo,
434 dut="r2",
435 routes=DEFAULT_ROUTES,
436 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R1,
437 expected=True,
438 )
439 assert (
440 result is True
441 ), "Testcase {} : Failed to configure the default originate \n Error: {}".format(
442 tc_name, result
443 )
444
445 step("Changing the as-path policy of the existing route-map")
446 input_dict_3 = {
447 "r1": {
448 "route_maps": {
449 "RMv4": [
450 {
451 "action": "permit",
452 "seq_id": "1",
453 "match": {"ipv4": {"prefix_lists": "Pv4"}},
454 "set": {
455 "path": {
456 "as_num": "6666",
457 "as_action": "prepend",
458 }
459 },
460 },
461 ],
462 "RMv6": [
463 {
464 "action": "permit",
465 "seq_id": "1",
466 "match": {"ipv6": {"prefix_lists": "Pv6"}},
467 "set": {
468 "path": {
469 "as_num": "6666",
470 "as_action": "prepend",
471 }
472 },
473 },
474 ],
475 }
476 }
477 }
478 result = create_route_maps(tgen, input_dict_3)
479 assert (
480 result is True
481 ), "Testcase {} : Failed to configure the route map \n Error: {}".format(
482 tc_name, result
483 )
484
485 step(
486 "Verify prefix sent count on R1 towards R2 \n Send count shoud not be incremented on change of existing (AS-path) policy "
487 )
488 snapshot = get_prefix_count_route(
489 tgen, topo, dut="r1", peer="r2", link="r1", sent=True, received=False
490 )
491
492 ipv4_prefix_count = False
493 ipv6_prefix_count = False
494 if snapshot["ipv4_count"] == 2:
495 ipv4_prefix_count = True
496 if snapshot["ipv6_count"] == 2:
497 ipv6_prefix_count = True
498
499 assert (
500 ipv4_prefix_count is True
501 ), "Testcase {} : Failed Error: Expected sent Prefix is 2 but obtained {} ".format(
502 tc_name, ipv4_prefix_count
503 )
504 assert (
505 ipv6_prefix_count is True
506 ), "Testcase {} : Failed Error: Expected sent Prefix is 2 but obtained {} ".format(
507 tc_name, ipv6_prefix_count
508 )
509
510 step(
511 "After changing the as-path policy verify the new policy is advertised to router R2"
512 )
513 DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
514 result = verify_rib_default_route(
515 tgen,
516 topo,
517 dut="r2",
518 routes=DEFAULT_ROUTES,
519 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R1,
520 metric=0,
521 expected_aspath="6666",
522 )
523 assert (
524 result is True
525 ), "Testcase {} : Default route with expected attributes is not found in BGP RIB \n Error: {}".format(
526 tc_name, result
527 )
528
529 result = verify_fib_default_route(
530 tgen,
531 topo,
532 dut="r2",
533 routes=DEFAULT_ROUTES,
534 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R1,
535 expected=True,
536 )
537 assert (
538 result is True
539 ), "Testcase {} : Default route with expected attributes is not found in BGP FIB \n Error: {}".format(
540 tc_name, result
541 )
542
543 step("Remove the as-path policy from the route-map")
544 input_dict_3 = {
545 "r1": {
546 "route_maps": {
547 "RMv4": [
548 {
549 "action": "permit",
550 "seq_id": "1",
551 "match": {"ipv4": {"prefix_lists": "Pv4"}},
552 "set": {
553 "path": {
554 "as_num": "6666",
555 "as_action": "prepend",
556 "delete": True,
557 }
558 },
559 },
560 ],
561 "RMv6": [
562 {
563 "action": "permit",
564 "seq_id": "1",
565 "match": {"ipv6": {"prefix_lists": "Pv6"}},
566 "set": {
567 "path": {
568 "as_num": "6666",
569 "as_action": "prepend",
570 "delete": True,
571 }
572 },
573 },
574 ],
575 }
576 }
577 }
578 result = create_route_maps(tgen, input_dict_3)
579 assert (
580 result is True
581 ), "Testcase {} : Failed to configure the route map \n Error: {}".format(
582 tc_name, result
583 )
584
585 step(
586 "After removing the route policy (AS-Path) verify that as-path is removed in r2 "
587 )
588 DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
589
590 result = verify_rib_default_route(
591 tgen,
592 topo,
593 dut="r2",
594 routes=DEFAULT_ROUTES,
595 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R1,
596 )
597 assert result is True, "Testcase {} : Failed ... ! \n Error: {}".format(
598 tc_name, result
599 )
600
601 result = verify_fib_default_route(
602 tgen,
603 topo,
604 dut="r2",
605 routes=DEFAULT_ROUTES,
606 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R1,
607 expected=True,
608 )
609 assert result is True, "Testcase {} : Failed .... !\n Error: {}".format(
610 tc_name, result
611 )
612
613 step("Delete the route-map ")
614
615 delete_routemap = {"r1": {"route_maps": ["RMv4", "RMv6"]}}
616 result = delete_route_maps(tgen, delete_routemap)
617 assert (
618 result is True
619 ), "Testcase {} : Failed to delete the route-map\n Error: {}".format(
620 tc_name, result
621 )
622
623 step(
624 "After deleting route-map , verify the default route in FIB and RIB are removed "
625 )
626 DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
627 result = verify_rib_default_route(
628 tgen,
629 topo,
630 dut="r2",
631 routes=DEFAULT_ROUTES,
632 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R1,
633 metric=0,
634 expected=False,
635 )
636 assert (
637 result is not True
638 ), "Testcase {} : After removing the route-map the default-route is not removed from R2 RIB\n Error: {}".format(
639 tc_name, result
640 )
641
642 result = verify_fib_default_route(
643 tgen,
644 topo,
645 dut="r2",
646 routes=DEFAULT_ROUTES,
647 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R1,
648 expected=False,
649 )
650 assert (
651 result is not True
652 ), "Testcase {} : After removing the route-map the default-route is not removed from R2 FIB \n Error: {}".format(
653 tc_name, result
654 )
655
656 step("Create route-map with with sequnce number 10 ")
657 input_dict_3 = {
658 "r1": {
659 "route_maps": {
660 "RMv4": [
661 {
662 "action": "permit",
663 "seq_id": "10",
664 "match": {"ipv4": {"prefix_lists": "Pv4"}},
665 "set": {
666 "path": {
667 "as_num": "9999",
668 "as_action": "prepend",
669 }
670 },
671 },
672 ],
673 "RMv6": [
674 {
675 "action": "permit",
676 "seq_id": "10",
677 "match": {"ipv6": {"prefix_lists": "Pv6"}},
678 "set": {
679 "path": {
680 "as_num": "9999",
681 "as_action": "prepend",
682 }
683 },
684 },
685 ],
686 }
687 }
688 }
689 result = create_route_maps(tgen, input_dict_3)
690 assert (
691 result is True
692 ), "Testcase {} : Failed to configure the route map \n Error: {}".format(
693 tc_name, result
694 )
695
696 step(
697 "After Configuring the route-map the dut is expected to receive the route policy (as-path) as 99999"
698 )
699 DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
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 metric=0,
707 expected_aspath="9999",
708 )
709 assert result is True, "Testcase {} : Failed...! \n Error: {}".format(
710 tc_name, result
711 )
712
713 result = verify_fib_default_route(
714 tgen,
715 topo,
716 dut="r2",
717 routes=DEFAULT_ROUTES,
718 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R1,
719 expected=True,
720 )
721 assert result is True, "Testcase {} : Failed ...!\n Error: {}".format(
722 tc_name, result
723 )
724
725 step("Create another route-map with seq number less than the previous i. <10 ")
726 input_dict_3 = {
727 "r1": {
728 "route_maps": {
729 "RMv4": [
730 {
731 "action": "permit",
732 "seq_id": "5",
733 "match": {"ipv4": {"prefix_lists": "Pv4"}},
734 "set": {
735 "path": {
736 "as_num": "7777",
737 "as_action": "prepend",
738 }
739 },
740 },
741 ],
742 "RMv6": [
743 {
744 "action": "permit",
745 "seq_id": "5",
746 "match": {"ipv6": {"prefix_lists": "Pv6"}},
747 "set": {
748 "path": {
749 "as_num": "7777",
750 "as_action": "prepend",
751 }
752 },
753 },
754 ],
755 }
756 }
757 }
758 result = create_route_maps(tgen, input_dict_3)
759 assert (
760 result is True
761 ), "Testcase {} : Failed to configure the route map \n Error: {}".format(
762 tc_name, result
763 )
764
765 step(
766 "On creating new route-map the route-map with lower seq id should be considered "
767 )
768 DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
769 result = verify_rib_default_route(
770 tgen,
771 topo,
772 dut="r2",
773 routes=DEFAULT_ROUTES,
774 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R1,
775 metric=0,
776 expected_aspath="7777",
777 )
778 assert (
779 result is True
780 ), "Testcase {} : Route-map with lowest prefix is not considered \n Error: {}".format(
781 tc_name, result
782 )
783
784 result = verify_fib_default_route(
785 tgen,
786 topo,
787 dut="r2",
788 routes=DEFAULT_ROUTES,
789 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R1,
790 expected=True,
791 )
792 assert (
793 result is True
794 ), "Testcase {} : Route-map with lowest prefix is not considered \n Error: {}".format(
795 tc_name, result
796 )
797
798 write_test_footer(tc_name)
799
800
801 def test_verify_default_originate_after_BGP_attributes_p1(request):
802 """
803 "Verify different BGP attributes with default-originate route "
804 """
805 tgen = get_topogen()
806 global BGP_CONVERGENCE
807 global topo
808 # test case name
809 tc_name = request.node.name
810 write_test_header(tc_name)
811 # Don't run this test if we have any failure.
812 if tgen.routers_have_failure():
813 check_router_status(tgen)
814 reset_config_on_routers(tgen)
815
816 if BGP_CONVERGENCE != True:
817 pytest.skip("skipped because of BGP Convergence failure")
818
819 step("Configure IPv4 and IPv6 , EBGP neighbor between R3 and R2")
820 step("Configure IPv4 and IPv6 IBGP neighbor between R3 and R4")
821 r0_local_as = topo['routers']['r0']['bgp']['local_as']
822 r1_local_as = topo['routers']['r1']['bgp']['local_as']
823 r2_local_as = topo['routers']['r2']['bgp']['local_as']
824 r3_local_as = topo['routers']['r3']['bgp']['local_as']
825 r4_local_as = topo['routers']['r4']['bgp']['local_as']
826 input_dict = {
827 "r0": {
828 "bgp": {
829 "local_as": r0_local_as,
830 }
831 },
832 "r1": {
833 "bgp": {
834 "local_as": r1_local_as,
835 }
836 },
837 "r2": {
838 "bgp": {
839 "local_as": r2_local_as,
840 }
841 },
842 "r3": {
843 "bgp": {
844 "local_as": 4000,
845 }
846 },
847 "r4": {
848 "bgp": {
849 "local_as": 4000,
850 }
851 },
852 }
853 result = modify_as_number(tgen, topo, input_dict)
854
855 try:
856 assert result is True
857 except AssertionError:
858 logger.info("Expected behaviour: {}".format(result))
859 logger.info("BGP config is not created because of invalid ASNs")
860 step("After changing the BGP AS Path Verify the BGP Convergence")
861
862 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
863 assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error: {}".format(
864 BGP_CONVERGENCE
865 )
866
867 step(
868 "Configure one IPv4 and one IPv6, Static route on R4 with next-hop as Null0 IPv4 route Sv41, IPv6 route Sv61 "
869 )
870 for addr_type in ADDR_TYPES:
871 static_routes_input = {
872 "r4": {
873 "static_routes": [
874 {
875 "network": [NETWORK1_1[addr_type]],
876 "next_hop": NEXT_HOP_IP[addr_type],
877 }
878 ]
879 }
880 }
881 result = create_static_routes(tgen, static_routes_input)
882 assert result is True, "Testcase {} : Failed \n Error: {}".format(
883 tc_name, result
884 )
885 step("Verify IPv4 and IPv6 static routes configured on R4 in FIB")
886 for addr_type in ADDR_TYPES:
887 static_routes_input = {
888 "r4": {
889 "static_routes": [
890 {
891 "network": [NETWORK1_1[addr_type]],
892 "next_hop": NEXT_HOP_IP[addr_type],
893 }
894 ]
895 }
896 }
897 result = verify_fib_routes(tgen, addr_type, "r4", static_routes_input)
898 assert result is True, "Testcase {} : Failed \n Error: {}".format(
899 tc_name, result
900 )
901
902 step(
903 "Configure redistribute static knob on R4 , for R4 to R3 neighbor for IPv4 and IPv6 address family "
904 )
905 redistribute_static = {
906 "r4": {
907 "bgp": {
908 "address_family": {
909 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
910 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
911 }
912 }
913 }
914 }
915 result = create_router_bgp(tgen, topo, redistribute_static)
916 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
917
918 step(
919 "Verify After configuring redistribute static , verify route received in BGP table of R3"
920 )
921 for addr_type in ADDR_TYPES:
922 static_routes_input = {
923 "r3": {
924 "static_routes": [
925 {
926 "network": [NETWORK1_1[addr_type]],
927 "next_hop": NEXT_HOP_IP[addr_type],
928 }
929 ]
930 }
931 }
932 result = verify_fib_routes(tgen, addr_type, "r3", static_routes_input)
933 assert result is True, "Testcase {} : Failed \n Error: {}".format(
934 tc_name, result
935 )
936
937 result = verify_bgp_rib(tgen, addr_type, "r3", static_routes_input)
938 assert result is True, "Testcase {} : Failed \n Error: {}".format(
939 tc_name, result
940 )
941
942 NOTE = """Configure 2 IPv4 prefix-list Pv41 Pv42 and and 2 IPv6 prefix-list Pv61 Pv62 on R3 to match BGP IPv4 route Sv41, 200.1.1.1/24 , IPv6 route Sv61 and 200::1/64"""
943 step(NOTE)
944 input_dict_3 = {
945 "r3": {
946 "prefix_lists": {
947 "ipv4": {
948 "Pv41": [
949 {
950 "seqid": "1",
951 "network": NETWORK1_1["ipv4"],
952 "action": "permit",
953 }
954 ],
955 "Pv42": [
956 {"seqid": "1", "network": "200.1.1.1/24", "action": "permit"}
957 ],
958 },
959 "ipv6": {
960 "Pv61": [
961 {
962 "seqid": "1",
963 "network": NETWORK1_1["ipv6"],
964 "action": "permit",
965 }
966 ],
967 "Pv62": [
968 {"seqid": " 1", "network": "200::1/64", "action": "permit"}
969 ],
970 },
971 }
972 }
973 }
974 result = create_prefix_lists(tgen, input_dict_3)
975 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
976
977 step("verify IPv4 and IPv6 Prefix list got configured on R3")
978 input_dict = {"r3": {"prefix_lists": ["Pv41", "Pv61", "Pv42", "Pv62"]}}
979 result = verify_prefix_lists(tgen, input_dict)
980 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
981
982 step(
983 "Configure 2 sequence of route-map for IPv4 seq1 permit Pv41 and seq2 permit Pv42 and for IPv6 seq1 permit Pv61 , seq2 permit Pv62 on R3"
984 )
985 input_dict_3 = {
986 "r3": {
987 "route_maps": {
988 "RMv4": [
989 {
990 "action": "permit",
991 "seq_id": "1",
992 "match": {"ipv4": {"prefix_lists": "Pv41"}},
993 },
994 {
995 "action": "permit",
996 "seq_id": "2",
997 "match": {"ipv4": {"prefix_lists": "Pv42"}},
998 },
999 ],
1000 "RMv6": [
1001 {
1002 "action": "permit",
1003 "seq_id": "1",
1004 "match": {"ipv6": {"prefix_lists": "Pv61"}},
1005 },
1006 {
1007 "action": "permit",
1008 "seq_id": "2",
1009 "match": {"ipv6": {"prefix_lists": "Pv62"}},
1010 },
1011 ],
1012 }
1013 }
1014 }
1015 result = create_route_maps(tgen, input_dict_3)
1016 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1017
1018 step(
1019 "Apply on route-map seq1 set as-path prepend to 200 and route-map seq2 set as-path prepend to 300 for IPv4 and IPv6 route-map "
1020 )
1021 route_map = {
1022 "r3": {
1023 "route_maps": {
1024 "RMv4": [
1025 {
1026 "action": "permit",
1027 "seq_id": "1",
1028 "set": {
1029 "path": {
1030 "as_num": "200",
1031 "as_action": "prepend",
1032 }
1033 }
1034
1035 },
1036 {
1037 "action": "permit",
1038 "seq_id": "2",
1039 "set": {
1040 "path": {
1041 "as_num": "300",
1042 "as_action": "prepend",
1043 }
1044 }
1045 },
1046 ],
1047 "RMv6": [
1048 {
1049 "action": "permit",
1050 "seq_id": "1",
1051 "set": {
1052 "path": {
1053 "as_num": "200",
1054 "as_action": "prepend",
1055 }
1056 }
1057 },
1058 {
1059 "action": "permit",
1060 "seq_id": "2",
1061 "set": {
1062 "path": {
1063 "as_num": "300",
1064 "as_action": "prepend",
1065 }
1066 }
1067 },
1068 ],
1069 }
1070 }
1071 }
1072
1073 result = create_route_maps(tgen, route_map)
1074 assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result)
1075
1076 step(
1077 " Configure default-originate with IPv4 and IPv6 route-map on R3 for R3-R2 IPv4 and IPv6 BGP neighbor"
1078 )
1079
1080 local_as = get_dut_as_number(tgen, dut="r3")
1081 default_originate_config = {
1082 "r3": {
1083 "bgp": {
1084 "local_as": local_as,
1085 "address_family": {
1086 "ipv4": {
1087 "unicast": {"default_originate": {"r2": {"route_map": "RMv4"}}}
1088 },
1089 "ipv6": {
1090 "unicast": {"default_originate": {"r2": {"route_map": "RMv6"}}}
1091 },
1092 },
1093 }
1094 }
1095 }
1096 result = create_router_bgp(tgen, topo, default_originate_config)
1097 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1098
1099 step(
1100 "Verify IPv4 and IPv6 default route received on R2 with both the AS path on R2"
1101 )
1102 DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1103
1104 result = verify_rib_default_route(
1105 tgen,
1106 topo,
1107 dut="r2",
1108 routes=DEFAULT_ROUTES,
1109 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3,
1110 metric=0,
1111 expected_aspath="4000 200",
1112 )
1113
1114 step(
1115 "Modify AS prepend path adding one more value 500 in route-map sequence 1 and 600 for route-map sequence 2 for IPv4 and IPv6 route-map"
1116 )
1117 route_map = {
1118 "r3": {
1119 "route_maps": {
1120 "RMv4": [
1121 {
1122 "action": "permit",
1123 "seq_id": "1",
1124 "set": {
1125 "path": {
1126 "as_num": "500",
1127 "as_action": "prepend",
1128 }
1129 }
1130
1131 },
1132 {
1133 "action": "permit",
1134 "seq_id": "2",
1135 "set": {
1136 "path": {
1137 "as_num": "600",
1138 "as_action": "prepend",
1139 }
1140 }
1141 },
1142 ],
1143 "RMv6": [
1144 {
1145 "action": "permit",
1146 "seq_id": "1",
1147 "set": {
1148 "path": {
1149 "as_num": "500",
1150 "as_action": "prepend",
1151 }
1152 }
1153 },
1154 {
1155 "action": "permit",
1156 "seq_id": "2",
1157 "set": {
1158 "path": {
1159 "as_num": "600",
1160 "as_action": "prepend",
1161 }
1162 }
1163 },
1164 ],
1165 }
1166 }
1167 }
1168
1169 result = create_route_maps(tgen, route_map)
1170 assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result)
1171 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1172
1173
1174 step("As path 500 added to IPv4 and IPv6 default -originate route received on R2")
1175 result = verify_rib_default_route(
1176 tgen,
1177 topo,
1178 dut="r2",
1179 routes=DEFAULT_ROUTES,
1180 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3,
1181 metric=0,
1182 expected_aspath="4000 500",
1183 )
1184 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1185
1186 step(
1187 "Apply on route-map seq1 set metric value to 70 and route-map seq2 set metric 80 IPv4 and IPv6 route-map"
1188 )
1189 route_map = {
1190 "r3": {
1191 "route_maps": {
1192 "RMv4": [
1193 {
1194 "action": "permit",
1195 "seq_id": "1",
1196 "set": {
1197 "metric": 70,
1198 },
1199 },
1200 {
1201 "action": "permit",
1202 "seq_id": "2",
1203 "set": {
1204 "metric": 80,
1205 },
1206 },
1207 ],
1208 "RMv6": [
1209 {
1210 "action": "permit",
1211 "seq_id": "1",
1212 "set": {
1213 "metric": 70,
1214 },
1215 },
1216 {
1217 "action": "permit",
1218 "seq_id": "2",
1219 "set": {
1220 "metric": 80,
1221 },
1222 },
1223 ],
1224 }
1225 }
1226 }
1227
1228 result = create_route_maps(tgen, route_map)
1229 assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result)
1230
1231 step(
1232 "Verify Configured metric value received on R2 along with as-path for IPv4 and IPv6 default routes "
1233 )
1234
1235
1236 DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "::/0"}
1237 result = verify_rib_default_route(
1238 tgen,
1239 topo,
1240 dut="r2",
1241 routes=DEFAULT_ROUTES,
1242 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3,
1243 metric=70,
1244 expected_aspath="4000 500",
1245 )
1246
1247
1248 step(
1249 "Modify route-map seq1 configure metric 50 and route-map seq2 configure metric 100 IPv4 and IPv6 route-map "
1250 )
1251 route_map = {
1252 "r3": {
1253 "route_maps": {
1254 "RMv4": [
1255 {
1256 "action": "permit",
1257 "seq_id": "1",
1258 "set": {
1259 "metric": 50,
1260 },
1261 },
1262 {
1263 "action": "permit",
1264 "seq_id": "2",
1265 "set": {
1266 "metric": 100,
1267 },
1268 },
1269 ],
1270 "RMv6": [
1271 {
1272 "action": "permit",
1273 "seq_id": "1",
1274 "set": {
1275 "metric": 50,
1276 },
1277 },
1278 {
1279 "action": "permit",
1280 "seq_id": "2",
1281 "set": {
1282 "metric": 100,
1283 },
1284 },
1285 ],
1286 }
1287 }
1288 }
1289
1290 result = create_route_maps(tgen, route_map)
1291 assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result)
1292
1293 step(
1294 "Verify Configured metric value received on R2 along with as-path for IPv4 and IPv6 default routes "
1295 )
1296
1297
1298 result = verify_rib_default_route(
1299 tgen,
1300 topo,
1301 dut="r2",
1302 routes=DEFAULT_ROUTES,
1303 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3,
1304 metric=50,
1305 expected_aspath="4000 500",
1306 )
1307 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1308
1309 step("Delete AS-prepend from IP4 and IPv6 route-map configured on R3 ")
1310 route_map = {
1311 "r3": {
1312 "route_maps": {
1313 "RMv4": [
1314 {
1315 "action": "permit",
1316 "seq_id": "1",
1317
1318 "set": {
1319 "path": {
1320 "as_num": "500",
1321 "as_action": "prepend",
1322 "delete": True,
1323 },
1324 "delete": True,
1325 },
1326 },
1327 {
1328 "action": "permit",
1329 "seq_id": "2",
1330 "set": {
1331 "path": {
1332 "as_num": "600",
1333 "as_action": "prepend",
1334 "delete": True,
1335 },
1336 "delete": True,
1337 },
1338 },
1339 ],
1340 "RMv6": [
1341 {
1342 "action": "permit",
1343 "seq_id": "1",
1344 "set": {
1345 "path": {
1346 "as_num": "500",
1347 "as_action": "prepend",
1348 "delete": True,
1349 },
1350 "delete": True,
1351 },
1352 },
1353 {
1354 "action": "permit",
1355 "seq_id": "2",
1356 "set": {
1357 "path": {
1358 "as_num": "600",
1359 "as_action": "prepend",
1360 "delete": True,
1361 },
1362 "delete": True,
1363 },
1364 },
1365 ],
1366 }
1367 }
1368 }
1369
1370 result = create_route_maps(tgen, route_map)
1371 assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result)
1372
1373 step(
1374 "Verify AS-prepend is deleted from default originate route and metric value only present on R2 for IPv4 and IPv6 default routes "
1375 )
1376
1377
1378
1379
1380 result = verify_rib_default_route(
1381 tgen,
1382 topo,
1383 dut="r2",
1384 routes=DEFAULT_ROUTES,
1385 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3,
1386 metric=50,
1387 expected_aspath="4000",
1388 )
1389 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1390
1391
1392 step("Delete metric value from IP4 and IPv6 route-map configured on R3 ")
1393 route_map = {
1394 "r3": {
1395 "route_maps": {
1396 "RMv4": [
1397 {
1398 "action": "permit",
1399 "seq_id": "1",
1400 "set": {"metric": 50, "delete": True},
1401 },
1402 {
1403 "action": "permit",
1404 "seq_id": "2",
1405 "set": {"metric": 100, "delete": True},
1406 },
1407 ],
1408 "RMv6": [
1409 {
1410 "action": "permit",
1411 "seq_id": "1",
1412 "set": {"metric": 50, "delete": True},
1413 },
1414 {
1415 "action": "permit",
1416 "seq_id": "2",
1417 "set": {"metric": 100, "delete": True},
1418 },
1419 ],
1420 }
1421 }
1422 }
1423
1424 result = create_route_maps(tgen, route_map)
1425 assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result)
1426
1427 step(
1428 "Verify Metric value deleted from IPv4 and IPv6 default route on R2 ,verify default routes "
1429 )
1430
1431
1432
1433 result = verify_rib_default_route(
1434 tgen,
1435 topo,
1436 dut="r2",
1437 routes=DEFAULT_ROUTES,
1438 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3,
1439 metric=0,
1440 expected_aspath="4000",
1441 )
1442
1443 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1444 step("Change IPv4 and IPv6 , EBGP to IBGP neighbor between R3 and R2")
1445 step("Change IPv4 and IPv6 IBGP to EBGP neighbor between R3 and R4")
1446 r0_local_as = topo['routers']['r0']['bgp']['local_as']
1447 r1_local_as = topo['routers']['r1']['bgp']['local_as']
1448 r2_local_as = topo['routers']['r2']['bgp']['local_as']
1449 r3_local_as = topo['routers']['r3']['bgp']['local_as']
1450 r4_local_as = topo['routers']['r4']['bgp']['local_as']
1451 input_dict = {
1452 "r0": {
1453 "bgp": {
1454 "local_as": r0_local_as,
1455 }
1456 },
1457 "r1": {
1458 "bgp": {
1459 "local_as": r1_local_as,
1460 }
1461 },
1462
1463 "r2": {
1464 "bgp": {
1465 "local_as": 1111,
1466 }
1467 },
1468 "r3": {
1469 "bgp": {
1470 "local_as": 1111,
1471 }
1472 },
1473 "r4": {
1474 "bgp": {
1475 "local_as": 5555,
1476 }
1477 },
1478 }
1479 result = modify_as_number(tgen, topo, input_dict)
1480 try:
1481 assert result is True
1482 except AssertionError:
1483 logger.info("Expected behaviour: {}".format(result))
1484 logger.info("BGP config is not created because of invalid ASNs")
1485 step("After changing the BGP AS Path Verify the BGP Convergence")
1486 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
1487 assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error: {}".format(
1488 BGP_CONVERGENCE
1489 )
1490 step(
1491 "Configure one IPv4 and one IPv6, Static route on R4 with next-hop as Null0 IPv4 route Sv41, IPv6 route Sv61 "
1492 )
1493 for addr_type in ADDR_TYPES:
1494 static_routes_input = {
1495 "r4": {
1496 "static_routes": [
1497 {
1498 "network": [NETWORK1_1[addr_type]],
1499 "next_hop": NEXT_HOP_IP[addr_type],
1500 }
1501 ]
1502 }
1503 }
1504 result = create_static_routes(tgen, static_routes_input)
1505 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1506 tc_name, result
1507 )
1508 step("Verify IPv4 and IPv6 static routes configured on R4 in FIB")
1509 for addr_type in ADDR_TYPES:
1510 static_routes_input = {
1511 "r4": {
1512 "static_routes": [
1513 {
1514 "network": [NETWORK1_1[addr_type]],
1515 "next_hop": NEXT_HOP_IP[addr_type],
1516 }
1517 ]
1518 }
1519 }
1520 result = verify_fib_routes(tgen, addr_type, "r4", static_routes_input)
1521 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1522 tc_name, result
1523 )
1524
1525 step(
1526 "Configure redistribute static knob on R4 , for R4 to R3 neighbor for IPv4 and IPv6 address family "
1527 )
1528 redistribute_static = {
1529 "r4": {
1530 "bgp": {
1531 "address_family": {
1532 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1533 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1534 }
1535 }
1536 }
1537 }
1538 result = create_router_bgp(tgen, topo, redistribute_static)
1539 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1540
1541 step(
1542 "Verify After configuring redistribute static , verify route received in BGP table of R3"
1543 )
1544 for addr_type in ADDR_TYPES:
1545 static_routes_input = {
1546 "r3": {
1547 "static_routes": [
1548 {
1549 "network": [NETWORK1_1[addr_type]],
1550 "next_hop": NEXT_HOP_IP[addr_type],
1551 }
1552 ]
1553 }
1554 }
1555 result = verify_fib_routes(tgen, addr_type, "r3", static_routes_input)
1556 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1557 tc_name, result
1558 )
1559
1560 result = verify_bgp_rib(tgen, addr_type, "r3", static_routes_input)
1561 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1562 tc_name, result
1563 )
1564 step(
1565 " Configure default-originate with IPv4 and IPv6 route-map on R3 for R3-R2 IPv4 and IPv6 BGP neighbor"
1566 )
1567 local_as = get_dut_as_number(tgen, dut="r3")
1568 default_originate_config = {
1569 "r3": {
1570 "bgp": {
1571 "local_as": local_as,
1572 "address_family": {
1573 "ipv4": {
1574 "unicast": {"default_originate": {"r2": {"route_map": "RMv4"}}}
1575 },
1576 "ipv6": {
1577 "unicast": {"default_originate": {"r2": {"route_map": "RMv6"}}}
1578 },
1579 },
1580 }
1581 }
1582 }
1583 result = create_router_bgp(tgen, topo, default_originate_config)
1584 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1585
1586 step(
1587 "Verify IPv4 and IPv6 default route received on R2 with both the AS path on R2"
1588 )
1589 DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1590 result = verify_rib_default_route(
1591 tgen,
1592 topo,
1593 dut="r2",
1594 routes=DEFAULT_ROUTES,
1595 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3,
1596 )
1597 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1598
1599 step(
1600 "Configure local -preference to 50 on IPv4 and IPv6 route map seq1 and 60 on seq2"
1601 )
1602 route_map = {
1603 "r3": {
1604 "route_maps": {
1605 "RMv4": [
1606 {
1607 "action": "permit",
1608 "seq_id": "1",
1609 "set": {
1610 "locPrf": 50,
1611 },
1612 },
1613 {
1614 "action": "permit",
1615 "seq_id": "2",
1616 "set": {
1617 "locPrf": 60,
1618 },
1619 },
1620 ],
1621 "RMv6": [
1622 {
1623 "action": "permit",
1624 "seq_id": "1",
1625 "set": {
1626 "locPrf": 50,
1627 },
1628 },
1629 {
1630 "action": "permit",
1631 "seq_id": "2",
1632 "set": {
1633 "locPrf": 60,
1634 },
1635 },
1636 ],
1637 }
1638 }
1639 }
1640
1641 result = create_route_maps(tgen, route_map)
1642 assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result)
1643
1644 step(
1645 "Verify Configured metric value received on R2 along with as-path for IPv4 and IPv6 default routes "
1646 )
1647
1648
1649
1650 result = verify_rib_default_route(
1651 tgen,
1652 topo,
1653 dut="r2",
1654 routes=DEFAULT_ROUTES,
1655 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3,
1656 locPrf=50,
1657 )
1658
1659
1660 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1661
1662 step(
1663 "Modify local preference value to 150 on IPv4 and IPv6 route map seq1 and 160 on seq2"
1664 )
1665 route_map = {
1666 "r3": {
1667 "route_maps": {
1668 "RMv4": [
1669 {
1670 "action": "permit",
1671 "seq_id": "1",
1672 "set": {
1673 "locPrf": 150,
1674 },
1675 },
1676 {
1677 "action": "permit",
1678 "seq_id": "2",
1679 "set": {
1680 "locPrf": 160,
1681 },
1682 },
1683 ],
1684 "RMv6": [
1685 {
1686 "action": "permit",
1687 "seq_id": "1",
1688 "set": {
1689 "locPrf": 150,
1690 },
1691 },
1692 {
1693 "action": "permit",
1694 "seq_id": "2",
1695 "set": {
1696 "locPrf": 160,
1697 },
1698 },
1699 ],
1700 }
1701 }
1702 }
1703
1704 result = create_route_maps(tgen, route_map)
1705 assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result)
1706
1707 step(
1708 "Verify Modified local-preference value received on R2 for IPv4 and IPv6 default routes "
1709 )
1710
1711
1712
1713
1714 DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "::/0"}
1715 result = verify_rib_default_route(
1716 tgen,
1717 topo,
1718 dut="r2",
1719 routes=DEFAULT_ROUTES,
1720 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3,
1721 locPrf=150,
1722 )
1723
1724 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1725 # updating the topology with the updated AS-Number to avoid conflict in con configuring the AS
1726 updated_topo = topo
1727 updated_topo['routers']['r0']['bgp']['local_as']=get_dut_as_number(tgen,"r0")
1728 updated_topo['routers']['r1']['bgp']['local_as']=get_dut_as_number(tgen,"r1")
1729 updated_topo['routers']['r2']['bgp']['local_as']=get_dut_as_number(tgen,"r2")
1730 updated_topo['routers']['r3']['bgp']['local_as']=get_dut_as_number(tgen,"r3")
1731 updated_topo['routers']['r4']['bgp']['local_as']=get_dut_as_number(tgen,"r4")
1732
1733 step("Shut IPv4/IPv6 BGP neighbor from R4 ( R4-R3) using 'neighbor x.x.x.x shut' command ")
1734 local_as = get_dut_as_number(tgen, dut="r4")
1735 shut_neighbor = {
1736 "r4": {
1737 "bgp": {
1738 "local_as": local_as,
1739 "address_family": {
1740 "ipv4": {
1741 "unicast": {
1742 "neighbor": {
1743 "r3": {
1744 "dest_link": {
1745 "r4": {"shutdown":True}
1746 }
1747 }
1748 }
1749 }
1750 },
1751 "ipv6": {
1752 "unicast": {
1753 "neighbor": {
1754 "r3": {
1755 "dest_link": {
1756 "r4": {"shutdown":True}
1757 }
1758 }
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']['r3']['links']['r4']['interface']
1770 input_dict = {
1771 "r1": {
1772 "interface_list": [interface],
1773 "status": "down"
1774 }
1775 }
1776
1777 result = interface_status(tgen, topo, input_dict)
1778 assert result is True, "Testcase {} : Shut down the interface failed ! \n Error: {}".format(tc_name, result)
1779
1780 step("After shutting the interface verify the BGP convergence")
1781 result = verify_bgp_convergence(tgen,topo,expected=False)
1782 assert result is not True, "Testcase {} : Failed \n After shutting Down BGP convergence should Fail and return False \n Error: {}".format(tc_name, result)
1783
1784 step("verify default route deleted from R2 ")
1785 result = verify_rib_default_route(
1786 tgen,
1787 topo,
1788 dut="r2",
1789 routes=DEFAULT_ROUTES,
1790 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3,
1791 expected=False)
1792 assert result is not True, "Testcase {} : Failed \n Error: After Shut down interface the default route is NOT expected but found in RIB -> {}".format( tc_name, result)
1793
1794 result = verify_fib_default_route(
1795 tgen,
1796 topo,
1797 dut="r2",
1798 routes=DEFAULT_ROUTES,
1799 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3,
1800 expected=False)
1801 assert result is not True, "Testcase {} : Failed \n Error: After Shut down interface the default route is NOT expected but found in FIB -> {}".format( tc_name, result)
1802
1803
1804 step("no Shut IPv4/IPv6 BGP neighbor from R4 ( R4-R3) using 'neighbor x.x.x.x shut' command ")
1805 local_as = get_dut_as_number(tgen, dut="r4")
1806 shut_neighbor = {
1807 "r4": {
1808 "bgp": {
1809 "local_as": local_as,
1810 "address_family": {
1811 "ipv4": {
1812 "unicast": {
1813 "neighbor": {
1814 "r3": {
1815 "dest_link": {
1816 "r4": {"shutdown":False}
1817 }
1818 }
1819 }
1820 }
1821 },
1822 "ipv6": {
1823 "unicast": {
1824 "neighbor": {
1825 "r3": {
1826 "dest_link": {
1827 "r4": {"shutdown":False}
1828 }
1829 }
1830 }
1831 }
1832 }
1833 }
1834 }
1835 }
1836 }
1837 result = create_router_bgp(tgen, updated_topo, shut_neighbor)
1838 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1839
1840 interface = topo['routers']['r3']['links']['r4']['interface']
1841 input_dict = {
1842 "r1": {
1843 "interface_list": [interface],
1844 "status": "up"
1845 }
1846 }
1847
1848 result = interface_status(tgen, topo, input_dict)
1849 assert result is True, "Testcase {} : Bring up interface failed ! \n Error: {}".format(tc_name, result)
1850
1851 step("After no shutting the interface verify the BGP convergence")
1852 result = verify_bgp_convergence(tgen,topo,expected=True)
1853 assert result is True, "Testcase {} : Failed \n After shutting Down BGP convergence should Fail and return False \n Error: {}".format(tc_name, result)
1854
1855 step("After no shut neighbor , verify default route relearn on R2")
1856 result = verify_rib_default_route(
1857 tgen,
1858 topo,
1859 dut="r2",
1860 routes=DEFAULT_ROUTES,
1861 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3,
1862 expected=True)
1863 assert result is True, "Testcase {} : Failed \n Error: After no Shut down interface the default route is expected but found in RIB -> {}".format( tc_name, result)
1864
1865 result = verify_fib_default_route(
1866 tgen,
1867 topo,
1868 dut="r2",
1869 routes=DEFAULT_ROUTES,
1870 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3,
1871 expected=True)
1872 assert result is True, "Testcase {} : Failed \n Error: After Shut down interface the default route is expected but found in FIB -> {}".format( tc_name, result)
1873
1874
1875
1876 step("Remove IPv4/IPv6 static route configure on R4")
1877 for addr_type in ADDR_TYPES:
1878 static_routes_input = {
1879 "r4": {
1880 "static_routes": [
1881 {
1882 "network": [NETWORK1_1[addr_type]],
1883 "next_hop": NEXT_HOP_IP[addr_type],
1884 "delete": True
1885 }
1886 ]
1887 }
1888 }
1889 result = create_static_routes(tgen, static_routes_input)
1890 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1891 tc_name, result
1892 )
1893 step("Verify IPv4 and IPv6 static routes removed on R4 in FIB")
1894 for addr_type in ADDR_TYPES:
1895 static_routes_input = {
1896 "r4": {
1897 "static_routes": [
1898 {
1899 "network": [NETWORK1_1[addr_type]],
1900 "next_hop": NEXT_HOP_IP[addr_type],
1901 }
1902 ]
1903 }
1904 }
1905 result = verify_fib_routes(tgen, addr_type, "r4", static_routes_input, expected=False)
1906 assert result is not True, "Testcase {} : Failed \n Error: {}".format(
1907 tc_name, result
1908 )
1909 result = verify_bgp_rib(tgen, addr_type, "r4", static_routes_input, expected=False)
1910 assert result is not True, "Testcase {} : Failed \n Error: {}".format(
1911 tc_name, result
1912 )
1913
1914 step("After removing static route , verify default route removed on R2")
1915 result = verify_rib_default_route(
1916 tgen,
1917 topo,
1918 dut="r2",
1919 routes=DEFAULT_ROUTES,
1920 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3,
1921 expected= False)
1922 assert result is not True, "Testcase {} : Failed \n Error: After removing static the default route is NOT expected but found in RIB -> {}".format( tc_name, result)
1923
1924 result = verify_fib_default_route(
1925 tgen,
1926 topo,
1927 dut="r2",
1928 routes=DEFAULT_ROUTES,
1929 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3,
1930 expected= False)
1931 assert result is not True, "Testcase {} : Failed \n Error: After removing static the default route is NOT expected but found in FIB -> {}".format( tc_name, result)
1932
1933
1934 step("Configuring the static route back in r4")
1935 for addr_type in ADDR_TYPES:
1936 static_routes_input = {
1937 "r4": {
1938 "static_routes": [
1939 {
1940 "network": [NETWORK1_1[addr_type]],
1941 "next_hop": NEXT_HOP_IP[addr_type],
1942 }
1943 ]
1944 }
1945 }
1946 result = create_static_routes(tgen, static_routes_input)
1947 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1948 tc_name, result
1949 )
1950 step("Verify IPv4 and IPv6 static routes configured on R4 in FIB")
1951 for addr_type in ADDR_TYPES:
1952 static_routes_input = {
1953 "r4": {
1954 "static_routes": [
1955 {
1956 "network": [NETWORK1_1[addr_type]],
1957 "next_hop": NEXT_HOP_IP[addr_type],
1958 }
1959 ]
1960 }
1961 }
1962 result = verify_fib_routes(tgen, addr_type, "r4", static_routes_input, expected=True)
1963 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1964 tc_name, result
1965 )
1966 result = verify_bgp_rib(tgen, addr_type, "r4", static_routes_input, expected=True)
1967 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1968 tc_name, result
1969 )
1970
1971 step("After adding static route back , verify default route learned on R2")
1972 result = verify_rib_default_route(
1973 tgen,
1974 topo,
1975 dut="r2",
1976 routes=DEFAULT_ROUTES,
1977 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3,
1978 expected= True)
1979 assert result is True, "Testcase {} : Failed \n Error: After removing static the default route is expected but found in RIB -> {}".format( tc_name, result)
1980
1981 result = verify_fib_default_route(
1982 tgen,
1983 topo,
1984 dut="r2",
1985 routes=DEFAULT_ROUTES,
1986 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3,
1987 expected= True)
1988 assert result is True, "Testcase {} : Failed \n Error: After removing static the default route is expected but found in FIB -> {}".format( tc_name, result)
1989
1990 step("Deactivate IPv4 and IPv6 neighbor configured from R4 ( R4-R3)")
1991
1992 configure_bgp_on_r1 = {
1993 "r4": {
1994 "bgp": {
1995 "address_family": {
1996 "ipv4": {
1997 "unicast": {
1998 "neighbor": {
1999 "r3": {"dest_link": {"r4": {"deactivate": "ipv4"}}}
2000 }
2001 },
2002
2003 },"ipv6": {
2004 "unicast": {
2005 "neighbor": {
2006 "r3": {"dest_link": {"r4": {"deactivate": "ipv6"}}}
2007 }
2008 },
2009
2010 }
2011 }
2012 }
2013 }
2014 }
2015 result = create_router_bgp(tgen, updated_topo, configure_bgp_on_r1)
2016 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
2017
2018 step("After deactivating the BGP neighbor , verify default route removed on R2")
2019 result = verify_rib_default_route(
2020 tgen,
2021 topo,
2022 dut="r2",
2023 routes=DEFAULT_ROUTES,
2024 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3,
2025 expected= False)
2026 assert result is not True, "Testcase {} : Failed \n Error: After Deactivating the BGP neighbor the default route is NOT expected but found in RIB -> {}".format( tc_name, result)
2027
2028 result = verify_fib_default_route(
2029 tgen,
2030 topo,
2031 dut="r2",
2032 routes=DEFAULT_ROUTES,
2033 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3,
2034 expected= False)
2035 assert result is not True, "Testcase {} : Failed \n Error: After Deactivating the BGP neighbor the default route is NOT expected but found in FIB -> {}".format( tc_name, result)
2036
2037 step("Activate IPv4 and IPv6 neighbor configured from R4 ( R4-R3)")
2038
2039 configure_bgp_on_r1 = {
2040 "r4": {
2041 "bgp": {
2042 "address_family": {
2043 "ipv4": {
2044 "unicast": {
2045 "neighbor": {
2046 "r3": {"dest_link": {"r4": {"activate": "ipv4"}}}
2047 }
2048 },
2049
2050 },"ipv6": {
2051 "unicast": {
2052 "neighbor": {
2053 "r3": {"dest_link": {"r4": {"activate": "ipv6"}}}
2054 }
2055 },
2056
2057 }
2058 }
2059 }
2060 }
2061 }
2062 result = create_router_bgp(tgen, updated_topo, configure_bgp_on_r1)
2063 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
2064
2065 step("Verify bgp convergence.")
2066 bgp_convergence = verify_bgp_convergence(tgen, updated_topo)
2067 assert bgp_convergence is True, "Testcase {} : Failed \n Error: {}".format(
2068 tc_name, bgp_convergence
2069 )
2070 step("After Activating the BGP neighbor , verify default route learned on R2")
2071 result = verify_rib_default_route(
2072 tgen,
2073 topo,
2074 dut="r2",
2075 routes=DEFAULT_ROUTES,
2076 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3,
2077 expected= True)
2078 assert result is True, "Testcase {} : Failed \n Error: After Deactivating the BGP neighbor the default route is expected but found in RIB -> {}".format( tc_name, result)
2079
2080 result = verify_fib_default_route(
2081 tgen,
2082 topo,
2083 dut="r2",
2084 routes=DEFAULT_ROUTES,
2085 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_R3,
2086 expected= True)
2087 assert result is True, "Testcase {} : Failed \n Error: After Deactivating the BGP neighbor the default route is expected but found in FIB -> {}".format( tc_name, result)
2088 write_test_footer(tc_name)
2089
2090 if __name__ == "__main__":
2091 args = ["-s"] + sys.argv[1:]
2092 sys.exit(pytest.main(args))