2 # SPDX-License-Identifier: ISC
5 # Copyright (c) 2019 by VMware, Inc. ("VMware")
6 # Used Copyright (c) 2018 by Network Device Education Foundation,
7 # Inc. ("NetDEF") in this file.
11 test_bgp_large_community_topo_1.py: Test BGP large community.
13 Following tests are covered:
14 1. Verify the standard large-community-lists can permit or deny
15 large community attribute only in the correct canonical format.
16 2. Verify the expanded large-community-lists can permit or deny
17 large community attribute both in the correct canonical format
19 3. Verify that we can modify a large-community-list is in use,
20 to add/remove attribute value and it takes immediate effect.
21 4. Verify that large community attribute gets advertised when
22 route-map is applied to a neighbor and cleared when route-map
24 5. Verify that duplicate BGP Large Community values are NOT be transmitted.
25 6. Verify if we want to remove all the large-community attributes from a
26 set of prefix we can set the value as NONE.
27 7. Redistribute connected and static routes in BGP process with a route-map
28 appending/removing L-comm attributes.
29 8. 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.
31 9. 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)
34 10. Verify that large-community lists can not be configured without providing
35 specific L-community values(for match/delete operation in a route-map).
36 11. 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.
39 12. 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
43 13. 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.
45 14. Verify large-community lists operation in a route-map with match RegEx
54 # Save the Current Working Directory to find configuration files.
55 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
56 sys
.path
.append(os
.path
.join(CWD
, "../"))
57 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
59 # pylint: disable=C0413
60 # Import topogen and topotest helpers
61 # Import topoJson from lib, to create topology and initial configuration
62 from lib
.topogen
import Topogen
, get_topogen
64 from lib
.common_config
import (
68 reset_config_on_routers
,
70 create_bgp_community_lists
,
73 verify_create_community_list
,
78 required_linux_kernel_version
,
80 from lib
.topolog
import logger
81 from lib
.bgp
import verify_bgp_convergence
, create_router_bgp
, clear_bgp_and_verify
82 from lib
.topojson
import build_config_from_json
85 pytestmark
= [pytest
.mark
.bgpd
]
89 bgp_convergence
= False
91 NETWORKS
= {"ipv4": ["200.50.2.0/32"], "ipv6": ["1::1/128"]}
94 def setup_module(mod
):
96 Sets up the pytest environment
101 # Required linux kernel version for this suite to run.
102 result
= required_linux_kernel_version("4.15")
103 if result
is not True:
104 pytest
.skip("Kernel requirements are not met")
106 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
107 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
108 logger
.info("=" * 40)
110 logger
.info("Running setup_module to create topology")
112 # This function initiates the topology build with Topogen...
113 json_file
= "{}/bgp_large_community_topo_2.json".format(CWD
)
114 tgen
= Topogen(json_file
, mod
.__name
__)
116 topo
= tgen
.json_topo
117 # ... and here it calls Mininet initialization functions.
119 # Starting topology, create tmp files which are loaded to routers
120 # to start daemons and then start routers
123 # Creating configuration from JSON
124 build_config_from_json(tgen
, topo
)
126 # Checking BGP convergence
127 global bgp_convergence
, ADDR_TYPES
129 # Don"t run this test if we have any failure.
130 if tgen
.routers_have_failure():
131 pytest
.skip(tgen
.errors
)
133 # Api call verify whether BGP is converged
135 bgp_convergence
= verify_bgp_convergence(tgen
, topo
)
136 assert bgp_convergence
is True, "setup_module :Failed \n Error:" " {}".format(
139 ADDR_TYPES
= check_address_types()
141 logger
.info("Running setup_module() done")
144 def teardown_module(mod
):
146 Teardown the pytest environment
151 logger
.info("Running teardown_module to delete topology")
155 # Stop toplogy and Remove tmp files
159 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
161 logger
.info("=" * 40)
164 #####################################################
168 #####################################################
171 def test_create_bgp_standard_large_community_list(request
):
173 Create standard large-community-list and verify it can permit
174 or deny large community attribute only in the correct canonical
179 tc_name
= request
.node
.name
180 write_test_header(tc_name
)
182 # Don"t run this test if we have any failure.
183 if tgen
.routers_have_failure():
184 pytest
.skip(tgen
.errors
)
186 reset_config_on_routers(tgen
)
188 step("Create srtandard large community list")
191 "bgp_community_lists": [
193 "community_type": "standard",
196 "value": "2:1:1 2:1:2 1:2:3",
200 "community_type": "standard",
203 "value": "3:1:1 3:1:2",
209 result
= create_bgp_community_lists(tgen
, input_dict
)
210 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
212 step("Verify BGP large community is created")
213 result
= verify_create_community_list(tgen
, input_dict
)
214 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
216 step("Create srtandard large community list with in-correct values")
219 "bgp_community_lists": [
221 "community_type": "standard",
223 "name": "LC_1_STD_ERR",
230 result
= create_bgp_community_lists(tgen
, input_dict
)
231 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
234 step("Verify BGP large community is created")
235 result
= verify_create_community_list(tgen
, input_dict
)
236 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
238 write_test_footer(tc_name
)
241 def test_create_bgp_expanded_large_community_list(request
):
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
249 tc_name
= request
.node
.name
250 write_test_header(tc_name
)
252 # Don"t run this test if we have any failure.
253 if tgen
.routers_have_failure():
254 pytest
.skip(tgen
.errors
)
256 # Creating configuration from JSON
257 reset_config_on_routers(tgen
)
259 step("Create expanded large community list")
262 "bgp_community_lists": [
264 "community_type": "expanded",
267 "value": "1:1:200 1:2:* 3:2:1",
273 result
= create_bgp_community_lists(tgen
, input_dict
)
274 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
276 step("Verify BGP large community is created")
277 result
= verify_create_community_list(tgen
, input_dict
)
278 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
280 write_test_footer(tc_name
)
283 def test_modify_large_community_lists_referenced_by_rmap(request
):
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.
290 tc_name
= request
.node
.name
291 write_test_header(tc_name
)
293 # Don"t run this test if we have any failure.
294 if tgen
.routers_have_failure():
295 pytest
.skip(tgen
.errors
)
297 # Creating configuration from JSON
298 reset_config_on_routers(tgen
)
300 step("Create standard large community list")
303 "bgp_community_lists": [
305 "community_type": "standard",
308 "value": "1:2:1 1:3:1 2:1:1 2:2:2 3:3:3",
314 result
= create_bgp_community_lists(tgen
, input_dict_1
)
315 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
317 step("Create route map")
327 "num": "1:2:1 1:3:1 2:10:1 3:3:3 4:4:4 5:5:5",
328 "action": "additive",
341 "set": {"large_comm_list": {"id": "LC_DEL", "delete": True}},
347 result
= create_route_maps(tgen
, input_dict_2
)
348 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
350 step("Configure neighbor for route map and advertise networks")
357 "advertise_networks": [{"network": "200.50.2.0/32"}],
376 "advertise_networks": [{"network": "1::1/128"}],
406 {"name": "RM_R4_IN", "direction": "in"}
421 {"name": "RM_R4_IN", "direction": "in"}
433 result
= create_router_bgp(tgen
, topo
, input_dict_3
)
434 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
436 step("Verify Community-list")
438 input_dict_4
= {"largeCommunity": "2:10:1 4:4:4 5:5:5"}
440 for adt
in ADDR_TYPES
:
441 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_4
)
442 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
446 write_test_footer(tc_name
)
449 def test_large_community_lists_with_rmap_apply_and_remove(request
):
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
456 tc_name
= request
.node
.name
457 write_test_header(tc_name
)
459 # Don"t run this test if we have any failure.
460 if tgen
.routers_have_failure():
461 pytest
.skip(tgen
.errors
)
463 # Creating configuration from JSON
464 reset_config_on_routers(tgen
)
466 step("Create route map")
476 "num": "200:200:1 200:200:10 200:200:20000",
477 "action": "additive",
485 result
= create_route_maps(tgen
, input_dict_1
)
486 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
488 step("Configure neighbor for route map and advertise networks")
495 "advertise_networks": [{"network": "200.50.2.0/32"}]
499 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
514 {"name": "RM_LC1", "direction": "out"}
529 {"name": "RM_LC1", "direction": "out"}
541 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
542 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
544 step("Verify large-community-list")
546 input_dict_4
= {"largeCommunity": "200:200:1 200:200:10 200:200:20000"}
548 for adt
in ADDR_TYPES
:
549 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_4
)
550 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
554 step("Delete route map reference by community-list")
555 input_dict_3
= {"r4": {"route_maps": ["RM_LC1"]}}
556 result
= delete_route_maps(tgen
, input_dict_3
)
557 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
559 step("Verify route map is deleted")
560 result
= verify_route_maps(tgen
, input_dict_3
)
561 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
563 step("Verify large-community-list")
564 for adt
in ADDR_TYPES
:
565 result
= verify_bgp_community(
566 tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_4
, expected
=False
568 assert result
is not True, (
569 "Testcase {} : Failed \n "
570 "largeCommunity is still present after deleting route-map \n Error: {}".format(
575 write_test_footer(tc_name
)
578 def test_duplicate_large_community_list_attributes_not_transitive(request
):
580 This test is to verify that duplicate BGP Large Community values
581 are NOT be transmitted.
585 tc_name
= request
.node
.name
586 write_test_header(tc_name
)
588 # Don"t run this test if we have any failure.
589 if tgen
.routers_have_failure():
590 pytest
.skip(tgen
.errors
)
592 # Creating configuration from JSON
593 reset_config_on_routers(tgen
)
595 step("Create route map")
605 "num": "0:0:1 0:0:10 0:0:100 2:0:1 2:0:2 2:0:3"
607 "action": "additive",
618 "num": "0:0:1 0:0:10 0:0:10000 2:0:1 2:0:2",
619 "action": "additive",
627 result
= create_route_maps(tgen
, input_dict_1
)
628 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
630 step("Configure neighbor for route map and advertise networks")
637 "advertise_networks": [{"network": "200.50.2.0/32"}]
641 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
656 {"name": "RM_R4_IN", "direction": "in"}
683 {"name": "RM_R4_IN", "direction": "in"}
707 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
708 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
710 step("Verify large-community-list")
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"
715 for adt
in ADDR_TYPES
:
716 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_4
)
717 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
721 write_test_footer(tc_name
)
724 def test_large_community_lists_with_rmap_set_none(request
):
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.
731 tc_name
= request
.node
.name
732 write_test_header(tc_name
)
734 # Don"t run this test if we have any failure.
735 if tgen
.routers_have_failure():
736 pytest
.skip(tgen
.errors
)
738 # Creating configuration from JSON
739 reset_config_on_routers(tgen
)
741 step("Create route map")
751 "num": "0:0:1 0:0:10 0:0:100 2:0:1 2:0:2 2:0:3"
753 "action": "additive",
766 "set": {"large_community": {"num": "none"}},
772 result
= create_route_maps(tgen
, input_dict_1
)
773 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
775 step("Configure neighbor for route map")
782 "advertise_networks": [{"network": "200.50.2.0/32"}]
786 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
801 {"name": "RM_R4_IN", "direction": "in"}
816 {"name": "RM_R4_IN", "direction": "in"}
837 {"name": "RM_R6_IN", "direction": "in"}
852 {"name": "RM_R6_IN", "direction": "in"}
864 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
865 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
867 step("Verify Community-list")
869 for adt
in ADDR_TYPES
:
870 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], expected
=False)
871 assert result
is not True, (
872 "Testcase {} : Failed \n "
873 "Community-list is still present \n Error: {}".format(tc_name
, result
)
876 write_test_footer(tc_name
)
879 def test_lcomm_lists_with_redistribute_static_connected_rmap(request
):
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.
886 tc_name
= request
.node
.name
887 write_test_header(tc_name
)
889 # Don"t run this test if we have any failure.
890 if tgen
.routers_have_failure():
891 pytest
.skip(tgen
.errors
)
893 # Creating configuration from JSON
894 reset_config_on_routers(tgen
)
896 step("create static routes")
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"},
905 result
= create_static_routes(tgen
, input_dict
)
906 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
908 step("redistribute static routes")
917 "redist_type": "static",
918 "attribute": "route-map RM_R2_OUT",
921 "redist_type": "connected",
922 "attribute": "route-map RM_R2_OUT",
931 "redist_type": "static",
932 "attribute": "route-map RM_R2_OUT",
935 "redist_type": "connected",
936 "attribute": "route-map RM_R2_OUT",
945 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
946 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
948 step("Create route map")
955 "set": {"large_community": {"num": "55:55:55 555:555:555"}},
961 result
= create_route_maps(tgen
, input_dict_3
)
962 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
964 step("Verify large-community-list for static and connected ipv4 route on" " r2")
966 input_dict_5
= {"largeCommunity": "55:55:55 555:555:555"}
968 if "ipv4" in ADDR_TYPES
:
970 networks
= ["200.50.2.0/32", "1.0.1.17/32"]
971 result
= verify_bgp_community(tgen
, "ipv4", dut
, networks
, input_dict_5
)
972 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
976 step("Verify large-community-list for static and connected ipv4 route" " on r4")
978 networks
= ["200.50.2.0/32", "1.0.1.17/32"]
979 result
= verify_bgp_community(tgen
, "ipv4", dut
, networks
, input_dict_5
)
980 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
984 if "ipv6" in ADDR_TYPES
:
985 step("Verify large-community-list for static and connected ipv6 route" " on r2")
987 networks
= ["1::1/128", "2001:db8:f::1:17/128"]
988 result
= verify_bgp_community(tgen
, "ipv6", dut
, networks
, input_dict_5
)
989 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
993 step("Verify large-community-list for static and connected ipv6 route" " on r4")
995 networks
= ["1::1/128", "2001:db8:f::1:17/128"]
996 result
= verify_bgp_community(tgen
, "ipv6", dut
, networks
, input_dict_5
)
997 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1001 write_test_footer(tc_name
)
1004 def test_large_community_lists_with_rmap_set_delete(request
):
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
1011 tgen
= get_topogen()
1012 tc_name
= request
.node
.name
1013 write_test_header(tc_name
)
1015 # Don"t run this test if we have any failure.
1016 if tgen
.routers_have_failure():
1017 pytest
.skip(tgen
.errors
)
1019 # Creating configuration from JSON
1020 reset_config_on_routers(tgen
)
1022 step("configure route_map")
1025 "bgp_community_lists": [
1027 "community_type": "standard",
1030 "value": "1:2:1 1:1:10 1:3:100",
1036 result
= create_bgp_community_lists(tgen
, input_dict_2
)
1037 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1039 step("Create route map")
1047 "set": {"large_comm_list": {"id": "Test", "delete": True}},
1059 "large_community": {
1060 "num": "1:2:1 1:1:10 1:3:100 2:1:1 2:2:2 2:3:3"
1062 "action": "additive",
1070 result
= create_route_maps(tgen
, input_dict_3
)
1071 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1073 step("Configure neighbor for route map and advertise networks")
1080 "advertise_networks": [{"network": "200.50.2.0/32"}]
1084 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
1099 {"name": "RM_R4_IN", "direction": "in"}
1114 {"name": "RM_R4_IN", "direction": "in"}
1135 {"name": "RM_R6_IN", "direction": "in"}
1150 {"name": "RM_R6_IN", "direction": "in"}
1162 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
1163 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1165 step("Verify large-community-list")
1167 input_dict_5
= {"largeCommunity": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"}
1168 for adt
in ADDR_TYPES
:
1169 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_5
)
1170 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1174 write_test_footer(tc_name
)
1177 def test_large_community_lists_with_no_send_community(request
):
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
1184 tgen
= get_topogen()
1185 tc_name
= request
.node
.name
1186 write_test_header(tc_name
)
1188 # Don"t run this test if we have any failure.
1189 if tgen
.routers_have_failure():
1190 pytest
.skip(tgen
.errors
)
1192 # Creating configuration from JSON
1193 reset_config_on_routers(tgen
)
1195 step("Create route map")
1204 "large_community": {"num": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"}
1211 result
= create_route_maps(tgen
, input_dict_2
)
1212 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1214 step("Configure neighbor for route map and advertise networks")
1221 "advertise_networks": [{"network": "200.50.2.0/32"}]
1225 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
1241 "name": "RM_R6_OUT",
1259 "name": "RM_R6_OUT",
1273 result
= create_router_bgp(tgen
, topo
, input_dict_3
)
1274 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1276 step("Verify large-community-list")
1278 input_dict_4
= {"largeCommunity": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"}
1279 for adt
in ADDR_TYPES
:
1280 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_4
)
1281 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1285 step("Configure neighbor for no-send-community")
1294 "dest_link": {"r5": {"no_send_community": "large"}}
1303 "dest_link": {"r5": {"no_send_community": "large"}}
1312 result
= create_router_bgp(tgen
, topo
, input_dict_5
)
1313 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1315 step("Verify Community-list")
1316 for adt
in ADDR_TYPES
:
1317 result
= verify_bgp_community(
1318 tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_4
, expected
=False
1320 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
1324 write_test_footer(tc_name
)
1327 def test_create_large_community_lists_with_no_attribute_values(request
):
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).
1334 tgen
= get_topogen()
1335 tc_name
= request
.node
.name
1336 write_test_header(tc_name
)
1338 # Don"t run this test if we have any failure.
1339 if tgen
.routers_have_failure():
1340 pytest
.skip(tgen
.errors
)
1342 # Creating configuration from JSON
1343 reset_config_on_routers(tgen
)
1345 step("Create standard large commumity-list")
1348 "bgp_community_lists": [
1350 "community_type": "standard",
1358 result
= create_bgp_community_lists(tgen
, input_dict_1
)
1359 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
1363 write_test_footer(tc_name
)
1366 def test_large_community_lists_with_rmap_match_exact(request
):
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.
1374 tgen
= get_topogen()
1375 tc_name
= request
.node
.name
1376 write_test_header(tc_name
)
1378 # Don"t run this test if we have any failure.
1379 if tgen
.routers_have_failure():
1380 pytest
.skip(tgen
.errors
)
1382 # Creating configuration from JSON
1383 reset_config_on_routers(tgen
)
1385 step("Create route map")
1394 "large_community": {"num": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"}
1401 result
= create_route_maps(tgen
, input_dict_2
)
1402 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1404 step("Configure neighbor for route map and advertise networks")
1411 "advertise_networks": [{"network": "200.50.2.0/32"}]
1415 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
1431 "name": "RM_R4_OUT",
1449 "name": "RM_R4_OUT",
1464 result
= create_router_bgp(tgen
, topo
, input_dict_3
)
1465 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1467 step("Create standard large commumity-list")
1470 "bgp_community_lists": [
1472 "community_type": "standard",
1475 "value": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5",
1481 result
= create_bgp_community_lists(tgen
, input_dict_4
)
1482 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1484 step("Verify BGP large community is created")
1485 result
= verify_create_community_list(tgen
, input_dict_4
)
1486 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1488 step("Create route map")
1497 "large-community-list": ["EXACT"],
1498 "match_exact": True,
1505 result
= create_route_maps(tgen
, input_dict_5
)
1506 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1508 step("Configure neighbor for route map")
1520 {"name": "RM_R4_IN", "direction": "in"}
1535 {"name": "RM_R4_IN", "direction": "in"}
1547 result
= create_router_bgp(tgen
, topo
, input_dict_6
)
1548 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1550 step("Verify large-community-list")
1552 input_dict_4
= {"largeCommunity": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"}
1553 for adt
in ADDR_TYPES
:
1554 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_4
)
1555 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1559 write_test_footer(tc_name
)
1562 def test_large_community_lists_with_rmap_match_all(request
):
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.
1571 tgen
= get_topogen()
1572 tc_name
= request
.node
.name
1573 write_test_header(tc_name
)
1575 # Don"t run this test if we have any failure.
1576 if tgen
.routers_have_failure():
1577 pytest
.skip(tgen
.errors
)
1579 # Creating configuration from JSON
1580 reset_config_on_routers(tgen
)
1582 step("Create route map")
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"
1599 result
= create_route_maps(tgen
, input_dict_2
)
1600 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1602 step("Configure neighbor for route map")
1609 "advertise_networks": [{"network": "200.50.2.0/32"}]
1613 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
1629 "name": "RM_R4_OUT",
1647 "name": "RM_R4_OUT",
1661 result
= create_router_bgp(tgen
, topo
, input_dict_3
)
1662 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1664 step("Create standard large commumity-list")
1667 "bgp_community_lists": [
1669 "community_type": "standard",
1672 "value": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5",
1678 result
= create_bgp_community_lists(tgen
, input_dict_4
)
1679 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1681 step("Verify BGP large community is created")
1682 result
= verify_create_community_list(tgen
, input_dict_4
)
1683 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1685 step("Create route map")
1693 "match": {"large-community-list": {"id": "ALL"}},
1699 result
= create_route_maps(tgen
, input_dict_5
)
1700 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1702 step("Configure neighbor for route map")
1714 {"name": "RM_R4_IN", "direction": "in"}
1729 {"name": "RM_R4_IN", "direction": "in"}
1741 result
= create_router_bgp(tgen
, topo
, input_dict_6
)
1742 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1744 step("Verify large-community-list")
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"}
1747 for adt
in ADDR_TYPES
:
1748 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_4
)
1749 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1753 write_test_footer(tc_name
)
1756 def test_large_community_lists_with_rmap_match_any(request
):
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.
1763 tgen
= get_topogen()
1764 tc_name
= request
.node
.name
1765 write_test_header(tc_name
)
1767 # Don"t run this test if we have any failure.
1768 if tgen
.routers_have_failure():
1769 pytest
.skip(tgen
.errors
)
1771 # Creating configuration from JSON
1772 reset_config_on_routers(tgen
)
1774 step("Create route map")
1783 "large_community": {"num": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"}
1790 result
= create_route_maps(tgen
, input_dict_2
)
1791 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1793 step("Configure neighbor for route map")
1800 "advertise_networks": [{"network": "200.50.2.0/32"}]
1804 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
1820 "name": "RM_R4_OUT",
1838 "name": "RM_R4_OUT",
1852 result
= create_router_bgp(tgen
, topo
, input_dict_3
)
1853 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1855 step("Create standard large commumity-list")
1858 "bgp_community_lists": [
1860 "community_type": "standard",
1867 "community_type": "standard",
1874 "community_type": "standard",
1881 "community_type": "standard",
1890 result
= create_bgp_community_lists(tgen
, input_dict_4
)
1891 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1893 step("Verify BGP large community is created")
1894 result
= verify_create_community_list(tgen
, input_dict_4
)
1895 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1897 step("Create route map")
1905 "match": {"large-community-list": {"id": "ANY"}},
1911 result
= create_route_maps(tgen
, input_dict_5
)
1912 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1914 step("Configure neighbor for route map")
1926 {"name": "RM_R4_IN", "direction": "in"}
1941 {"name": "RM_R4_IN", "direction": "in"}
1953 result
= create_router_bgp(tgen
, topo
, input_dict_6
)
1954 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1956 step("Verify large-community-list")
1958 input_dict_7
= {"largeCommunity": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"}
1959 for adt
in ADDR_TYPES
:
1960 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_7
)
1961 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1965 write_test_footer(tc_name
)
1968 def test_large_community_lists_with_rmap_match_regex(request
):
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
1975 tgen
= get_topogen()
1976 tc_name
= request
.node
.name
1977 write_test_header(tc_name
)
1979 # Don"t run this test if we have any failure.
1980 if tgen
.routers_have_failure():
1981 pytest
.skip(tgen
.errors
)
1983 # Creating configuration from JSON
1984 reset_config_on_routers(tgen
)
1986 step("Create route map")
1995 "large_community": {
1996 "num": "1:1:1 1:1:2 2:1:3 2:1:4 2:1:5",
1998 "community": {"num": "1:1 1:2 1:3 1:4 1:5"},
2005 result
= create_route_maps(tgen
, input_dict_2
)
2006 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2008 step("Configure neighbor for route map")
2015 "advertise_networks": [{"network": "200.50.2.0/32"}]
2019 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
2035 "name": "RM_R4_OUT",
2053 "name": "RM_R4_OUT",
2067 result
= create_router_bgp(tgen
, topo
, input_dict_3
)
2068 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2070 step("Create standard large commumity-list")
2073 "bgp_community_lists": [
2075 "community_type": "standard",
2078 "value": "1:1:1 2:1:3 2:1:4 2:1:5",
2082 "community_type": "expanded",
2085 "value": "1:1:1 2:1:[3-5]",
2091 result
= create_bgp_community_lists(tgen
, input_dict_4
)
2092 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2094 step("Verify BGP large community is created")
2095 result
= verify_create_community_list(tgen
, input_dict_4
)
2096 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2098 step("Create route map")
2107 "large_community_list": {
2116 result
= create_route_maps(tgen
, input_dict_5
)
2117 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2119 step("Configure neighbor for route map")
2131 {"name": "RM_R4_IN", "direction": "in"}
2146 {"name": "RM_R4_IN", "direction": "in"}
2158 result
= create_router_bgp(tgen
, topo
, input_dict_6
)
2159 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2161 step("Verify large-community-list")
2163 input_dict_7
= {"largeCommunity": "1:1:1 1:1:2 2:1:3 2:1:4 2:1:5"}
2164 for adt
in ADDR_TYPES
:
2165 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_7
)
2166 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2170 step("Delete route map reference by community-list")
2171 input_dict_3
= {"r4": {"route_maps": ["RM_R4_IN"]}}
2172 result
= delete_route_maps(tgen
, input_dict_3
)
2173 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2175 result
= verify_route_maps(tgen
, input_dict_3
)
2176 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2178 step("Create route map")
2187 "large_community_list": {
2196 result
= create_route_maps(tgen
, input_dict_5
)
2197 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2199 step("clear ip bgp")
2200 result
= clear_bgp_and_verify(tgen
, topo
, "r4")
2201 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
2203 step("Verify large-community-list")
2205 input_dict_7
= {"largeCommunity": "1:1:1 1:1:2 2:1:3 2:1:4 2:1:5"}
2206 for adt
in ADDR_TYPES
:
2207 result
= verify_bgp_community(
2208 tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_7
, expected
=False
2210 assert result
is not True, (
2211 "Testcase {} : Failed \n "
2212 "largeCommunity is still present \n Error: {}".format(tc_name
, result
)
2215 write_test_footer(tc_name
)
2218 if __name__
== "__main__":
2219 args
= ["-s"] + sys
.argv
[1:]
2220 sys
.exit(pytest
.main(args
))