4 # Copyright (c) 2019 by VMware, Inc. ("VMware")
5 # Used Copyright (c) 2018 by Network Device Education Foundation,
6 # Inc. ("NetDEF") in this file.
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
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
24 test_bgp_large_community_topo_1.py: Test BGP large community.
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
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
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
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
67 # Save the Current Working Directory to find configuration files.
68 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
69 sys
.path
.append(os
.path
.join(CWD
, "../"))
70 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
72 # pylint: disable=C0413
73 # Import topogen and topotest helpers
74 # Import topoJson from lib, to create topology and initial configuration
75 from lib
.topogen
import Topogen
, get_topogen
77 from lib
.common_config
import (
81 reset_config_on_routers
,
83 create_bgp_community_lists
,
86 verify_create_community_list
,
91 required_linux_kernel_version
,
93 from lib
.topolog
import logger
94 from lib
.bgp
import verify_bgp_convergence
, create_router_bgp
, clear_bgp_and_verify
95 from lib
.topojson
import build_config_from_json
98 pytestmark
= [pytest
.mark
.bgpd
]
102 bgp_convergence
= False
104 NETWORKS
= {"ipv4": ["200.50.2.0/32"], "ipv6": ["1::1/128"]}
107 def setup_module(mod
):
109 Sets up the pytest environment
114 # Required linux kernel version for this suite to run.
115 result
= required_linux_kernel_version("4.15")
116 if result
is not True:
117 pytest
.skip("Kernel requirements are not met")
119 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
120 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
121 logger
.info("=" * 40)
123 logger
.info("Running setup_module to create topology")
125 # This function initiates the topology build with Topogen...
126 json_file
= "{}/bgp_large_community_topo_2.json".format(CWD
)
127 tgen
= Topogen(json_file
, mod
.__name
__)
129 topo
= tgen
.json_topo
130 # ... and here it calls Mininet initialization functions.
132 # Starting topology, create tmp files which are loaded to routers
133 # to start deamons and then start routers
136 # Creating configuration from JSON
137 build_config_from_json(tgen
, topo
)
139 # Checking BGP convergence
140 global bgp_convergence
, ADDR_TYPES
142 # Don"t run this test if we have any failure.
143 if tgen
.routers_have_failure():
144 pytest
.skip(tgen
.errors
)
146 # Api call verify whether BGP is converged
148 bgp_convergence
= verify_bgp_convergence(tgen
, topo
)
149 assert bgp_convergence
is True, "setup_module :Failed \n Error:" " {}".format(
152 ADDR_TYPES
= check_address_types()
154 logger
.info("Running setup_module() done")
157 def teardown_module(mod
):
159 Teardown the pytest environment
164 logger
.info("Running teardown_module to delete topology")
168 # Stop toplogy and Remove tmp files
172 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
174 logger
.info("=" * 40)
177 #####################################################
181 #####################################################
184 def test_create_bgp_standard_large_community_list(request
):
186 Create standard large-community-list and verify it can permit
187 or deny large community attribute only in the correct canonical
192 tc_name
= request
.node
.name
193 write_test_header(tc_name
)
195 # Don"t run this test if we have any failure.
196 if tgen
.routers_have_failure():
197 pytest
.skip(tgen
.errors
)
199 reset_config_on_routers(tgen
)
201 step("Create srtandard large community list")
204 "bgp_community_lists": [
206 "community_type": "standard",
209 "value": "2:1:1 2:1:2 1:2:3",
213 "community_type": "standard",
216 "value": "3:1:1 3:1:2",
222 result
= create_bgp_community_lists(tgen
, input_dict
)
223 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
225 step("Verify BGP large community is created")
226 result
= verify_create_community_list(tgen
, input_dict
)
227 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
229 step("Create srtandard large community list with in-correct values")
232 "bgp_community_lists": [
234 "community_type": "standard",
236 "name": "LC_1_STD_ERR",
243 result
= create_bgp_community_lists(tgen
, input_dict
)
244 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
247 step("Verify BGP large community is created")
248 result
= verify_create_community_list(tgen
, input_dict
)
249 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
251 write_test_footer(tc_name
)
254 def test_create_bgp_expanded_large_community_list(request
):
256 Create expanded large-community-list and verify it can permit
257 or deny large community attribute both in the correct canonical
258 format as well as REG_EX
262 tc_name
= request
.node
.name
263 write_test_header(tc_name
)
265 # Don"t run this test if we have any failure.
266 if tgen
.routers_have_failure():
267 pytest
.skip(tgen
.errors
)
269 # Creating configuration from JSON
270 reset_config_on_routers(tgen
)
272 step("Create expanded large community list")
275 "bgp_community_lists": [
277 "community_type": "expanded",
280 "value": "1:1:200 1:2:* 3:2:1",
286 result
= create_bgp_community_lists(tgen
, input_dict
)
287 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
289 step("Verify BGP large community is created")
290 result
= verify_create_community_list(tgen
, input_dict
)
291 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
293 write_test_footer(tc_name
)
296 def test_modify_large_community_lists_referenced_by_rmap(request
):
298 This test is to verify that we can modify a large-community-list
299 is in use, add/remove attribute value and it takes immediate effect.
303 tc_name
= request
.node
.name
304 write_test_header(tc_name
)
306 # Don"t run this test if we have any failure.
307 if tgen
.routers_have_failure():
308 pytest
.skip(tgen
.errors
)
310 # Creating configuration from JSON
311 reset_config_on_routers(tgen
)
313 step("Create standard large community list")
316 "bgp_community_lists": [
318 "community_type": "standard",
321 "value": "1:2:1 1:3:1 2:1:1 2:2:2 3:3:3",
327 result
= create_bgp_community_lists(tgen
, input_dict_1
)
328 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
330 step("Create route map")
340 "num": "1:2:1 1:3:1 2:10:1 3:3:3 4:4:4 5:5:5",
341 "action": "additive",
354 "set": {"large_comm_list": {"id": "LC_DEL", "delete": True}},
360 result
= create_route_maps(tgen
, input_dict_2
)
361 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
363 step("Configure neighbor for route map and advertise networks")
370 "advertise_networks": [{"network": "200.50.2.0/32"}],
389 "advertise_networks": [{"network": "1::1/128"}],
419 {"name": "RM_R4_IN", "direction": "in"}
434 {"name": "RM_R4_IN", "direction": "in"}
446 result
= create_router_bgp(tgen
, topo
, input_dict_3
)
447 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
449 step("Verify Community-list")
451 input_dict_4
= {"largeCommunity": "2:10:1 4:4:4 5:5:5"}
453 for adt
in ADDR_TYPES
:
454 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_4
)
455 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
459 write_test_footer(tc_name
)
462 def test_large_community_lists_with_rmap_apply_and_remove(request
):
464 This test is to verify that large community attribute gets advertised when
465 route-map is applied to a neighbor and cleared when route-map is removed
469 tc_name
= request
.node
.name
470 write_test_header(tc_name
)
472 # Don"t run this test if we have any failure.
473 if tgen
.routers_have_failure():
474 pytest
.skip(tgen
.errors
)
476 # Creating configuration from JSON
477 reset_config_on_routers(tgen
)
479 step("Create route map")
489 "num": "200:200:1 200:200:10 200:200:20000",
490 "action": "additive",
498 result
= create_route_maps(tgen
, input_dict_1
)
499 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
501 step("Configure neighbor for route map and advertise networks")
508 "advertise_networks": [{"network": "200.50.2.0/32"}]
512 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
527 {"name": "RM_LC1", "direction": "out"}
542 {"name": "RM_LC1", "direction": "out"}
554 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
555 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
557 step("Verify large-community-list")
559 input_dict_4
= {"largeCommunity": "200:200:1 200:200:10 200:200:20000"}
561 for adt
in ADDR_TYPES
:
562 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_4
)
563 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
567 step("Delete route map reference by community-list")
568 input_dict_3
= {"r4": {"route_maps": ["RM_LC1"]}}
569 result
= delete_route_maps(tgen
, input_dict_3
)
570 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
572 step("Verify route map is deleted")
573 result
= verify_route_maps(tgen
, input_dict_3
)
574 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
576 step("Verify large-community-list")
577 for adt
in ADDR_TYPES
:
578 result
= verify_bgp_community(
579 tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_4
, expected
=False
581 assert result
is not True, (
582 "Testcase {} : Failed \n "
583 "largeCommunity is still present after deleting route-map \n Error: {}".format(
588 write_test_footer(tc_name
)
591 def test_duplicate_large_community_list_attributes_not_transitive(request
):
593 This test is to verify that duplicate BGP Large Community values
594 are NOT be transmitted.
598 tc_name
= request
.node
.name
599 write_test_header(tc_name
)
601 # Don"t run this test if we have any failure.
602 if tgen
.routers_have_failure():
603 pytest
.skip(tgen
.errors
)
605 # Creating configuration from JSON
606 reset_config_on_routers(tgen
)
608 step("Create route map")
618 "num": "0:0:1 0:0:10 0:0:100 2:0:1 2:0:2 2:0:3"
620 "action": "additive",
631 "num": "0:0:1 0:0:10 0:0:10000 2:0:1 2:0:2",
632 "action": "additive",
640 result
= create_route_maps(tgen
, input_dict_1
)
641 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
643 step("Configure neighbor for route map and advertise networks")
650 "advertise_networks": [{"network": "200.50.2.0/32"}]
654 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
669 {"name": "RM_R4_IN", "direction": "in"}
696 {"name": "RM_R4_IN", "direction": "in"}
720 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
721 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
723 step("Verify large-community-list")
726 "largeCommunity": "0:0:1 0:0:10 0:0:100 0:0:10000 2:0:1 2:0:2 2:0:3 2:0:4 2:0:5"
728 for adt
in ADDR_TYPES
:
729 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_4
)
730 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
734 write_test_footer(tc_name
)
737 def test_large_community_lists_with_rmap_set_none(request
):
739 This test is to verify if we want to remove all the large-community
740 attributes from a set of prefix we can set the value as NONE.
744 tc_name
= request
.node
.name
745 write_test_header(tc_name
)
747 # Don"t run this test if we have any failure.
748 if tgen
.routers_have_failure():
749 pytest
.skip(tgen
.errors
)
751 # Creating configuration from JSON
752 reset_config_on_routers(tgen
)
754 step("Create route map")
764 "num": "0:0:1 0:0:10 0:0:100 2:0:1 2:0:2 2:0:3"
766 "action": "additive",
779 "set": {"large_community": {"num": "none"}},
785 result
= create_route_maps(tgen
, input_dict_1
)
786 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
788 step("Configure neighbor for route map")
795 "advertise_networks": [{"network": "200.50.2.0/32"}]
799 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
814 {"name": "RM_R4_IN", "direction": "in"}
829 {"name": "RM_R4_IN", "direction": "in"}
850 {"name": "RM_R6_IN", "direction": "in"}
865 {"name": "RM_R6_IN", "direction": "in"}
877 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
878 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
880 step("Verify Community-list")
882 for adt
in ADDR_TYPES
:
883 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], expected
=False)
884 assert result
is not True, (
885 "Testcase {} : Failed \n "
886 "Community-list is still present \n Error: {}".format(tc_name
, result
)
889 write_test_footer(tc_name
)
892 def test_lcomm_lists_with_redistribute_static_connected_rmap(request
):
894 This test is to verify redistribute connected and static ipv4 routes
895 in BGP process with a route-map appending/removing L-comm attributes.
899 tc_name
= request
.node
.name
900 write_test_header(tc_name
)
902 # Don"t run this test if we have any failure.
903 if tgen
.routers_have_failure():
904 pytest
.skip(tgen
.errors
)
906 # Creating configuration from JSON
907 reset_config_on_routers(tgen
)
909 step("create static routes")
913 {"network": "200.50.2.0/32", "next_hop": "10.0.0.6"},
914 {"network": "1::1/128", "next_hop": "fd00:0:0:1::2"},
918 result
= create_static_routes(tgen
, input_dict
)
919 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
921 step("redistribute static routes")
930 "redist_type": "static",
931 "attribute": "route-map RM_R2_OUT",
934 "redist_type": "connected",
935 "attribute": "route-map RM_R2_OUT",
944 "redist_type": "static",
945 "attribute": "route-map RM_R2_OUT",
948 "redist_type": "connected",
949 "attribute": "route-map RM_R2_OUT",
958 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
959 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
961 step("Create route map")
968 "set": {"large_community": {"num": "55:55:55 555:555:555"}},
974 result
= create_route_maps(tgen
, input_dict_3
)
975 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
977 step("Verify large-community-list for static and connected ipv4 route on" " r2")
979 input_dict_5
= {"largeCommunity": "55:55:55 555:555:555"}
981 if "ipv4" in ADDR_TYPES
:
983 networks
= ["200.50.2.0/32", "1.0.1.17/32"]
984 result
= verify_bgp_community(tgen
, "ipv4", dut
, networks
, input_dict_5
)
985 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
989 step("Verify large-community-list for static and connected ipv4 route" " on r4")
991 networks
= ["200.50.2.0/32", "1.0.1.17/32"]
992 result
= verify_bgp_community(tgen
, "ipv4", dut
, networks
, input_dict_5
)
993 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
997 if "ipv6" in ADDR_TYPES
:
998 step("Verify large-community-list for static and connected ipv6 route" " on r2")
1000 networks
= ["1::1/128", "2001:db8:f::1:17/128"]
1001 result
= verify_bgp_community(tgen
, "ipv6", dut
, networks
, input_dict_5
)
1002 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1006 step("Verify large-community-list for static and connected ipv6 route" " on r4")
1008 networks
= ["1::1/128", "2001:db8:f::1:17/128"]
1009 result
= verify_bgp_community(tgen
, "ipv6", dut
, networks
, input_dict_5
)
1010 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1014 write_test_footer(tc_name
)
1017 def test_large_community_lists_with_rmap_set_delete(request
):
1019 This test is to verify if we want to remove specific large-community
1020 values from a set of prefix we can make use of DELETE operation based
1024 tgen
= get_topogen()
1025 tc_name
= request
.node
.name
1026 write_test_header(tc_name
)
1028 # Don"t run this test if we have any failure.
1029 if tgen
.routers_have_failure():
1030 pytest
.skip(tgen
.errors
)
1032 # Creating configuration from JSON
1033 reset_config_on_routers(tgen
)
1035 step("configure route_map")
1038 "bgp_community_lists": [
1040 "community_type": "standard",
1043 "value": "1:2:1 1:1:10 1:3:100",
1049 result
= create_bgp_community_lists(tgen
, input_dict_2
)
1050 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1052 step("Create route map")
1060 "set": {"large_comm_list": {"id": "Test", "delete": True}},
1072 "large_community": {
1073 "num": "1:2:1 1:1:10 1:3:100 2:1:1 2:2:2 2:3:3"
1075 "action": "additive",
1083 result
= create_route_maps(tgen
, input_dict_3
)
1084 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1086 step("Configure neighbor for route map and advertise networks")
1093 "advertise_networks": [{"network": "200.50.2.0/32"}]
1097 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
1112 {"name": "RM_R4_IN", "direction": "in"}
1127 {"name": "RM_R4_IN", "direction": "in"}
1148 {"name": "RM_R6_IN", "direction": "in"}
1163 {"name": "RM_R6_IN", "direction": "in"}
1175 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
1176 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1178 step("Verify large-community-list")
1180 input_dict_5
= {"largeCommunity": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"}
1181 for adt
in ADDR_TYPES
:
1182 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_5
)
1183 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1187 write_test_footer(tc_name
)
1190 def test_large_community_lists_with_no_send_community(request
):
1192 This test is to verify if we want to remove specific large-community
1193 values from a set of prefix we can make use of DELETE operation based
1197 tgen
= get_topogen()
1198 tc_name
= request
.node
.name
1199 write_test_header(tc_name
)
1201 # Don"t run this test if we have any failure.
1202 if tgen
.routers_have_failure():
1203 pytest
.skip(tgen
.errors
)
1205 # Creating configuration from JSON
1206 reset_config_on_routers(tgen
)
1208 step("Create route map")
1217 "large_community": {"num": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"}
1224 result
= create_route_maps(tgen
, input_dict_2
)
1225 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1227 step("Configure neighbor for route map and advertise networks")
1234 "advertise_networks": [{"network": "200.50.2.0/32"}]
1238 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
1254 "name": "RM_R6_OUT",
1272 "name": "RM_R6_OUT",
1286 result
= create_router_bgp(tgen
, topo
, input_dict_3
)
1287 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1289 step("Verify large-community-list")
1291 input_dict_4
= {"largeCommunity": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"}
1292 for adt
in ADDR_TYPES
:
1293 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_4
)
1294 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1298 step("Configure neighbor for no-send-community")
1307 "dest_link": {"r5": {"no_send_community": "large"}}
1316 "dest_link": {"r5": {"no_send_community": "large"}}
1325 result
= create_router_bgp(tgen
, topo
, input_dict_5
)
1326 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1328 step("Verify Community-list")
1329 for adt
in ADDR_TYPES
:
1330 result
= verify_bgp_community(
1331 tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_4
, expected
=False
1333 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
1337 write_test_footer(tc_name
)
1340 def test_create_large_community_lists_with_no_attribute_values(request
):
1342 This test is to verify that large-community lists can not be
1343 configured without providing specific L-community values
1344 (for match/delete operation in a route-map).
1347 tgen
= get_topogen()
1348 tc_name
= request
.node
.name
1349 write_test_header(tc_name
)
1351 # Don"t run this test if we have any failure.
1352 if tgen
.routers_have_failure():
1353 pytest
.skip(tgen
.errors
)
1355 # Creating configuration from JSON
1356 reset_config_on_routers(tgen
)
1358 step("Create standard large commumity-list")
1361 "bgp_community_lists": [
1363 "community_type": "standard",
1371 result
= create_bgp_community_lists(tgen
, input_dict_1
)
1372 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
1376 write_test_footer(tc_name
)
1379 def test_large_community_lists_with_rmap_match_exact(request
):
1381 This test is to verify that Match_EXACT clause should pass
1382 only if all of the L-comm values configured (horizontally)
1383 in the community list is present in the prefix. There must
1384 be no additional L-communities in the prefix.
1387 tgen
= get_topogen()
1388 tc_name
= request
.node
.name
1389 write_test_header(tc_name
)
1391 # Don"t run this test if we have any failure.
1392 if tgen
.routers_have_failure():
1393 pytest
.skip(tgen
.errors
)
1395 # Creating configuration from JSON
1396 reset_config_on_routers(tgen
)
1398 step("Create route map")
1407 "large_community": {"num": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"}
1414 result
= create_route_maps(tgen
, input_dict_2
)
1415 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1417 step("Configure neighbor for route map and advertise networks")
1424 "advertise_networks": [{"network": "200.50.2.0/32"}]
1428 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
1444 "name": "RM_R4_OUT",
1462 "name": "RM_R4_OUT",
1477 result
= create_router_bgp(tgen
, topo
, input_dict_3
)
1478 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1480 step("Create standard large commumity-list")
1483 "bgp_community_lists": [
1485 "community_type": "standard",
1488 "value": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5",
1494 result
= create_bgp_community_lists(tgen
, input_dict_4
)
1495 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1497 step("Verify BGP large community is created")
1498 result
= verify_create_community_list(tgen
, input_dict_4
)
1499 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1501 step("Create route map")
1510 "large-community-list": ["EXACT"],
1511 "match_exact": True,
1518 result
= create_route_maps(tgen
, input_dict_5
)
1519 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1521 step("Configure neighbor for route map")
1533 {"name": "RM_R4_IN", "direction": "in"}
1548 {"name": "RM_R4_IN", "direction": "in"}
1560 result
= create_router_bgp(tgen
, topo
, input_dict_6
)
1561 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1563 step("Verify large-community-list")
1565 input_dict_4
= {"largeCommunity": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"}
1566 for adt
in ADDR_TYPES
:
1567 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_4
)
1568 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1572 write_test_footer(tc_name
)
1575 def test_large_community_lists_with_rmap_match_all(request
):
1577 This test is to verify that Match_ALL clause should pass
1578 only if ALL of the L-comm values configured (horizontally)
1579 in the community list are present in the prefix. There
1580 could be additional L-communities in the prefix that are
1581 not present in the L-comm list.
1584 tgen
= get_topogen()
1585 tc_name
= request
.node
.name
1586 write_test_header(tc_name
)
1588 # Don"t run this test if we have any failure.
1589 if tgen
.routers_have_failure():
1590 pytest
.skip(tgen
.errors
)
1592 # Creating configuration from JSON
1593 reset_config_on_routers(tgen
)
1595 step("Create route map")
1603 "large_community": {
1604 "num": "1:1:1 1:2:3 2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"
1612 result
= create_route_maps(tgen
, input_dict_2
)
1613 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1615 step("Configure neighbor for route map")
1622 "advertise_networks": [{"network": "200.50.2.0/32"}]
1626 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
1642 "name": "RM_R4_OUT",
1660 "name": "RM_R4_OUT",
1674 result
= create_router_bgp(tgen
, topo
, input_dict_3
)
1675 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1677 step("Create standard large commumity-list")
1680 "bgp_community_lists": [
1682 "community_type": "standard",
1685 "value": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5",
1691 result
= create_bgp_community_lists(tgen
, input_dict_4
)
1692 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1694 step("Verify BGP large community is created")
1695 result
= verify_create_community_list(tgen
, input_dict_4
)
1696 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1698 step("Create route map")
1706 "match": {"large-community-list": {"id": "ALL"}},
1712 result
= create_route_maps(tgen
, input_dict_5
)
1713 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1715 step("Configure neighbor for route map")
1727 {"name": "RM_R4_IN", "direction": "in"}
1742 {"name": "RM_R4_IN", "direction": "in"}
1754 result
= create_router_bgp(tgen
, topo
, input_dict_6
)
1755 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1757 step("Verify large-community-list")
1759 input_dict_4
= {"largeCommunity": "1:1:1 1:2:3 2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"}
1760 for adt
in ADDR_TYPES
:
1761 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_4
)
1762 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1766 write_test_footer(tc_name
)
1769 def test_large_community_lists_with_rmap_match_any(request
):
1771 This test is to verify that Match_ANY clause should pass
1772 only if at-least any one L-comm value configured(vertically)
1773 in large-community list, is present in prefixes.
1776 tgen
= get_topogen()
1777 tc_name
= request
.node
.name
1778 write_test_header(tc_name
)
1780 # Don"t run this test if we have any failure.
1781 if tgen
.routers_have_failure():
1782 pytest
.skip(tgen
.errors
)
1784 # Creating configuration from JSON
1785 reset_config_on_routers(tgen
)
1787 step("Create route map")
1796 "large_community": {"num": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"}
1803 result
= create_route_maps(tgen
, input_dict_2
)
1804 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1806 step("Configure neighbor for route map")
1813 "advertise_networks": [{"network": "200.50.2.0/32"}]
1817 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
1833 "name": "RM_R4_OUT",
1851 "name": "RM_R4_OUT",
1865 result
= create_router_bgp(tgen
, topo
, input_dict_3
)
1866 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1868 step("Create standard large commumity-list")
1871 "bgp_community_lists": [
1873 "community_type": "standard",
1880 "community_type": "standard",
1887 "community_type": "standard",
1894 "community_type": "standard",
1903 result
= create_bgp_community_lists(tgen
, input_dict_4
)
1904 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1906 step("Verify BGP large community is created")
1907 result
= verify_create_community_list(tgen
, input_dict_4
)
1908 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1910 step("Create route map")
1918 "match": {"large-community-list": {"id": "ANY"}},
1924 result
= create_route_maps(tgen
, input_dict_5
)
1925 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1927 step("Configure neighbor for route map")
1939 {"name": "RM_R4_IN", "direction": "in"}
1954 {"name": "RM_R4_IN", "direction": "in"}
1966 result
= create_router_bgp(tgen
, topo
, input_dict_6
)
1967 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1969 step("Verify large-community-list")
1971 input_dict_7
= {"largeCommunity": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"}
1972 for adt
in ADDR_TYPES
:
1973 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_7
)
1974 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1978 write_test_footer(tc_name
)
1981 def test_large_community_lists_with_rmap_match_regex(request
):
1983 This test is to verify large-community lists" operation in a route-map
1984 with match RegEx statements. Match clause should pass only if the
1985 complete string of L-comm values are matched
1988 tgen
= get_topogen()
1989 tc_name
= request
.node
.name
1990 write_test_header(tc_name
)
1992 # Don"t run this test if we have any failure.
1993 if tgen
.routers_have_failure():
1994 pytest
.skip(tgen
.errors
)
1996 # Creating configuration from JSON
1997 reset_config_on_routers(tgen
)
1999 step("Create route map")
2008 "large_community": {
2009 "num": "1:1:1 1:1:2 2:1:3 2:1:4 2:1:5",
2011 "community": {"num": "1:1 1:2 1:3 1:4 1:5"},
2018 result
= create_route_maps(tgen
, input_dict_2
)
2019 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2021 step("Configure neighbor for route map")
2028 "advertise_networks": [{"network": "200.50.2.0/32"}]
2032 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
2048 "name": "RM_R4_OUT",
2066 "name": "RM_R4_OUT",
2080 result
= create_router_bgp(tgen
, topo
, input_dict_3
)
2081 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2083 step("Create standard large commumity-list")
2086 "bgp_community_lists": [
2088 "community_type": "standard",
2091 "value": "1:1:1 2:1:3 2:1:4 2:1:5",
2095 "community_type": "expanded",
2098 "value": "1:1:1 2:1:[3-5]",
2104 result
= create_bgp_community_lists(tgen
, input_dict_4
)
2105 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2107 step("Verify BGP large community is created")
2108 result
= verify_create_community_list(tgen
, input_dict_4
)
2109 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2111 step("Create route map")
2120 "large_community_list": {
2129 result
= create_route_maps(tgen
, input_dict_5
)
2130 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2132 step("Configure neighbor for route map")
2144 {"name": "RM_R4_IN", "direction": "in"}
2159 {"name": "RM_R4_IN", "direction": "in"}
2171 result
= create_router_bgp(tgen
, topo
, input_dict_6
)
2172 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2174 step("Verify large-community-list")
2176 input_dict_7
= {"largeCommunity": "1:1:1 1:1:2 2:1:3 2:1:4 2:1:5"}
2177 for adt
in ADDR_TYPES
:
2178 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_7
)
2179 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2183 step("Delete route map reference by community-list")
2184 input_dict_3
= {"r4": {"route_maps": ["RM_R4_IN"]}}
2185 result
= delete_route_maps(tgen
, input_dict_3
)
2186 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2188 result
= verify_route_maps(tgen
, input_dict_3
)
2189 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2191 step("Create route map")
2200 "large_community_list": {
2209 result
= create_route_maps(tgen
, input_dict_5
)
2210 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2212 step("clear ip bgp")
2213 result
= clear_bgp_and_verify(tgen
, topo
, "r4")
2214 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
2216 step("Verify large-community-list")
2218 input_dict_7
= {"largeCommunity": "1:1:1 1:1:2 2:1:3 2:1:4 2:1:5"}
2219 for adt
in ADDR_TYPES
:
2220 result
= verify_bgp_community(
2221 tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_7
, expected
=False
2223 assert result
is not True, (
2224 "Testcase {} : Failed \n "
2225 "largeCommunity is still present \n Error: {}".format(tc_name
, result
)
2228 write_test_footer(tc_name
)
2231 if __name__
== "__main__":
2232 args
= ["-s"] + sys
.argv
[1:]
2233 sys
.exit(pytest
.main(args
))