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