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