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