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