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