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
68 # Save the Current Working Directory to find configuration files.
69 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
70 sys
.path
.append(os
.path
.join(CWD
, "../"))
71 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
73 # pylint: disable=C0413
74 # Import topogen and topotest helpers
75 # Import topoJson from lib, to create topology and initial configuration
76 from lib
.topogen
import Topogen
, get_topogen
77 from mininet
.topo
import Topo
79 from lib
.common_config
import (
83 reset_config_on_routers
,
85 create_bgp_community_lists
,
89 verify_create_community_list
,
94 required_linux_kernel_version
,
96 from lib
.topolog
import logger
97 from lib
.bgp
import verify_bgp_convergence
, create_router_bgp
, clear_bgp_and_verify
98 from lib
.topojson
import build_topo_from_json
, build_config_from_json
100 # Reading the data from JSON File for topology and configuration creation
101 jsonFile
= "{}/bgp_large_community_topo_2.json".format(CWD
)
104 with
open(jsonFile
, "r") as topoJson
:
105 topo
= json
.load(topoJson
)
107 assert False, "Could not read file {}".format(jsonFile
)
110 bgp_convergence
= False
112 NETWORKS
= {"ipv4": ["200.50.2.0/32"], "ipv6": ["1::1/128"]}
115 class GenerateTopo(Topo
):
117 Test topology builder
119 * `Topo`: Topology object
122 def build(self
, *_args
, **_opts
):
124 tgen
= get_topogen(self
)
126 # Building topology from json file
127 build_topo_from_json(tgen
, topo
)
130 def setup_module(mod
):
132 Sets up the pytest environment
137 # Required linux kernel version for this suite to run.
138 result
= required_linux_kernel_version("4.15")
139 if result
is not True:
140 pytest
.skip("Kernel requirements are not met")
142 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
143 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
144 logger
.info("=" * 40)
146 logger
.info("Running setup_module to create topology")
148 # This function initiates the topology build with Topogen...
149 tgen
= Topogen(GenerateTopo
, mod
.__name
__)
150 # ... and here it calls Mininet initialization functions.
152 # Starting topology, create tmp files which are loaded to routers
153 # to start deamons and then start routers
156 # Creating configuration from JSON
157 build_config_from_json(tgen
, topo
)
159 # Checking BGP convergence
160 global bgp_convergence
, ADDR_TYPES
162 # Don"t run this test if we have any failure.
163 if tgen
.routers_have_failure():
164 pytest
.skip(tgen
.errors
)
166 # Api call verify whether BGP is converged
168 bgp_convergence
= verify_bgp_convergence(tgen
, topo
)
169 assert bgp_convergence
is True, "setup_module :Failed \n Error:" " {}".format(
172 ADDR_TYPES
= check_address_types()
174 logger
.info("Running setup_module() done")
177 def teardown_module(mod
):
179 Teardown the pytest environment
184 logger
.info("Running teardown_module to delete topology")
188 # Stop toplogy and Remove tmp files
192 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
194 logger
.info("=" * 40)
197 #####################################################
201 #####################################################
204 def test_create_bgp_standard_large_community_list(request
):
206 Create standard large-community-list and verify it can permit
207 or deny large community attribute only in the correct canonical
212 tc_name
= request
.node
.name
213 write_test_header(tc_name
)
215 # Don"t run this test if we have any failure.
216 if tgen
.routers_have_failure():
217 pytest
.skip(tgen
.errors
)
219 reset_config_on_routers(tgen
)
221 step("Create srtandard large community list")
224 "bgp_community_lists": [
226 "community_type": "standard",
229 "value": "2:1:1 2:1:2 1:2:3",
233 "community_type": "standard",
236 "value": "3:1:1 3:1:2",
242 result
= create_bgp_community_lists(tgen
, input_dict
)
243 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
245 step("Verify BGP large community is created")
246 result
= verify_create_community_list(tgen
, input_dict
)
247 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
249 step("Create srtandard large community list with in-correct values")
252 "bgp_community_lists": [
254 "community_type": "standard",
256 "name": "LC_1_STD_ERR",
263 result
= create_bgp_community_lists(tgen
, input_dict
)
264 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
267 step("Verify BGP large community is created")
268 result
= verify_create_community_list(tgen
, input_dict
)
269 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
271 write_test_footer(tc_name
)
274 def test_create_bgp_expanded_large_community_list(request
):
276 Create expanded large-community-list and verify it can permit
277 or deny large community attribute both in the correct canonical
278 format as well as REG_EX
282 tc_name
= request
.node
.name
283 write_test_header(tc_name
)
285 # Don"t run this test if we have any failure.
286 if tgen
.routers_have_failure():
287 pytest
.skip(tgen
.errors
)
289 # Creating configuration from JSON
290 reset_config_on_routers(tgen
)
292 step("Create expanded large community list")
295 "bgp_community_lists": [
297 "community_type": "expanded",
300 "value": "1:1:200 1:2:* 3:2:1",
306 result
= create_bgp_community_lists(tgen
, input_dict
)
307 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
309 step("Verify BGP large community is created")
310 result
= verify_create_community_list(tgen
, input_dict
)
311 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
313 write_test_footer(tc_name
)
316 def test_modify_large_community_lists_referenced_by_rmap(request
):
318 This test is to verify that we can modify a large-community-list
319 is in use, add/remove attribute value and it takes immediate effect.
323 tc_name
= request
.node
.name
324 write_test_header(tc_name
)
326 # Don"t run this test if we have any failure.
327 if tgen
.routers_have_failure():
328 pytest
.skip(tgen
.errors
)
330 # Creating configuration from JSON
331 reset_config_on_routers(tgen
)
333 step("Create standard large community list")
336 "bgp_community_lists": [
338 "community_type": "standard",
341 "value": "1:2:1 1:3:1 2:1:1 2:2:2 3:3:3",
347 result
= create_bgp_community_lists(tgen
, input_dict_1
)
348 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
350 step("Create route map")
360 "num": "1:2:1 1:3:1 2:10:1 3:3:3 4:4:4 5:5:5",
361 "action": "additive",
374 "set": {"large_comm_list": {"id": "LC_DEL", "delete": True}},
380 result
= create_route_maps(tgen
, input_dict_2
)
381 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
383 step("Configure neighbor for route map and advertise networks")
390 "advertise_networks": [{"network": "200.50.2.0/32"}],
409 "advertise_networks": [{"network": "1::1/128"}],
439 {"name": "RM_R4_IN", "direction": "in"}
454 {"name": "RM_R4_IN", "direction": "in"}
466 result
= create_router_bgp(tgen
, topo
, input_dict_3
)
467 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
469 step("Verify Community-list")
471 input_dict_4
= {"largeCommunity": "2:10:1 4:4:4 5:5:5"}
473 for adt
in ADDR_TYPES
:
474 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_4
)
475 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
479 write_test_footer(tc_name
)
482 def test_large_community_lists_with_rmap_apply_and_remove(request
):
484 This test is to verify that large community attribute gets advertised when
485 route-map is applied to a neighbor and cleared when route-map is removed
489 tc_name
= request
.node
.name
490 write_test_header(tc_name
)
492 # Don"t run this test if we have any failure.
493 if tgen
.routers_have_failure():
494 pytest
.skip(tgen
.errors
)
496 # Creating configuration from JSON
497 reset_config_on_routers(tgen
)
499 step("Create route map")
509 "num": "200:200:1 200:200:10 200:200:20000",
510 "action": "additive",
518 result
= create_route_maps(tgen
, input_dict_1
)
519 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
521 step("Configure neighbor for route map and advertise networks")
528 "advertise_networks": [{"network": "200.50.2.0/32"}]
532 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
547 {"name": "RM_LC1", "direction": "out"}
562 {"name": "RM_LC1", "direction": "out"}
574 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
575 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
577 step("Verify large-community-list")
579 input_dict_4
= {"largeCommunity": "200:200:1 200:200:10 200:200:20000"}
581 for adt
in ADDR_TYPES
:
582 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_4
)
583 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
587 step("Delete route map reference by community-list")
588 input_dict_3
= {"r4": {"route_maps": ["RM_LC1"]}}
589 result
= delete_route_maps(tgen
, input_dict_3
)
590 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
592 step("Verify route map is deleted")
593 result
= verify_route_maps(tgen
, input_dict_3
)
594 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
596 step("Verify large-community-list")
597 for adt
in ADDR_TYPES
:
598 result
= verify_bgp_community(
599 tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_4
, expected
=False
601 assert result
is not True, (
602 "Testcase {} : Failed \n "
603 "largeCommunity is still present after deleting route-map \n Error: {}".format(
608 write_test_footer(tc_name
)
611 def test_duplicate_large_community_list_attributes_not_transitive(request
):
613 This test is to verify that duplicate BGP Large Community values
614 are NOT be transmitted.
618 tc_name
= request
.node
.name
619 write_test_header(tc_name
)
621 # Don"t run this test if we have any failure.
622 if tgen
.routers_have_failure():
623 pytest
.skip(tgen
.errors
)
625 # Creating configuration from JSON
626 reset_config_on_routers(tgen
)
628 step("Create route map")
638 "num": "0:0:1 0:0:10 0:0:100 2:0:1 2:0:2 2:0:3"
640 "action": "additive",
651 "num": "0:0:1 0:0:10 0:0:10000 2:0:1 2:0:2",
652 "action": "additive",
660 result
= create_route_maps(tgen
, input_dict_1
)
661 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
663 step("Configure neighbor for route map and advertise networks")
670 "advertise_networks": [{"network": "200.50.2.0/32"}]
674 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
689 {"name": "RM_R4_IN", "direction": "in"}
716 {"name": "RM_R4_IN", "direction": "in"}
740 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
741 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
743 step("Verify large-community-list")
746 "largeCommunity": "0:0:1 0:0:10 0:0:100 0:0:10000 2:0:1 2:0:2 2:0:3 2:0:4 2:0:5"
748 for adt
in ADDR_TYPES
:
749 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_4
)
750 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
754 write_test_footer(tc_name
)
757 def test_large_community_lists_with_rmap_set_none(request
):
759 This test is to verify if we want to remove all the large-community
760 attributes from a set of prefix we can set the value as NONE.
764 tc_name
= request
.node
.name
765 write_test_header(tc_name
)
767 # Don"t run this test if we have any failure.
768 if tgen
.routers_have_failure():
769 pytest
.skip(tgen
.errors
)
771 # Creating configuration from JSON
772 reset_config_on_routers(tgen
)
774 step("Create route map")
784 "num": "0:0:1 0:0:10 0:0:100 2:0:1 2:0:2 2:0:3"
786 "action": "additive",
799 "set": {"large_community": {"num": "none"}},
805 result
= create_route_maps(tgen
, input_dict_1
)
806 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
808 step("Configure neighbor for route map")
815 "advertise_networks": [{"network": "200.50.2.0/32"}]
819 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
834 {"name": "RM_R4_IN", "direction": "in"}
849 {"name": "RM_R4_IN", "direction": "in"}
870 {"name": "RM_R6_IN", "direction": "in"}
885 {"name": "RM_R6_IN", "direction": "in"}
897 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
898 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
900 step("Verify Community-list")
902 for adt
in ADDR_TYPES
:
903 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], expected
=False)
904 assert result
is not True, (
905 "Testcase {} : Failed \n "
906 "Community-list is still present \n Error: {}".format(tc_name
, result
)
909 write_test_footer(tc_name
)
912 def test_lcomm_lists_with_redistribute_static_connected_rmap(request
):
914 This test is to verify redistribute connected and static ipv4 routes
915 in BGP process with a route-map appending/removing L-comm attributes.
919 tc_name
= request
.node
.name
920 write_test_header(tc_name
)
922 # Don"t run this test if we have any failure.
923 if tgen
.routers_have_failure():
924 pytest
.skip(tgen
.errors
)
926 # Creating configuration from JSON
927 reset_config_on_routers(tgen
)
929 step("create static routes")
933 {"network": "200.50.2.0/32", "next_hop": "10.0.0.6"},
934 {"network": "1::1/128", "next_hop": "fd00:0:0:1::2"},
938 result
= create_static_routes(tgen
, input_dict
)
939 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
941 step("redistribute static routes")
950 "redist_type": "static",
951 "attribute": "route-map RM_R2_OUT",
954 "redist_type": "connected",
955 "attribute": "route-map RM_R2_OUT",
964 "redist_type": "static",
965 "attribute": "route-map RM_R2_OUT",
968 "redist_type": "connected",
969 "attribute": "route-map RM_R2_OUT",
978 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
979 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
981 step("Create route map")
988 "set": {"large_community": {"num": "55:55:55 555:555:555"}},
994 result
= create_route_maps(tgen
, input_dict_3
)
995 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
997 step("Verify large-community-list for static and connected ipv4 route on" " r2")
999 input_dict_5
= {"largeCommunity": "55:55:55 555:555:555"}
1001 if "ipv4" in ADDR_TYPES
:
1003 networks
= ["200.50.2.0/32", "1.0.1.17/32"]
1004 result
= verify_bgp_community(tgen
, "ipv4", dut
, networks
, input_dict_5
)
1005 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1009 step("Verify large-community-list for static and connected ipv4 route" " on r4")
1011 networks
= ["200.50.2.0/32", "1.0.1.17/32"]
1012 result
= verify_bgp_community(tgen
, "ipv4", dut
, networks
, input_dict_5
)
1013 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1017 if "ipv6" in ADDR_TYPES
:
1018 step("Verify large-community-list for static and connected ipv6 route" " on r2")
1020 networks
= ["1::1/128", "2001:db8:f::1:17/128"]
1021 result
= verify_bgp_community(tgen
, "ipv6", dut
, networks
, input_dict_5
)
1022 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1026 step("Verify large-community-list for static and connected ipv6 route" " on r4")
1028 networks
= ["1::1/128", "2001:db8:f::1:17/128"]
1029 result
= verify_bgp_community(tgen
, "ipv6", dut
, networks
, input_dict_5
)
1030 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1034 write_test_footer(tc_name
)
1037 def test_large_community_lists_with_rmap_set_delete(request
):
1039 This test is to verify if we want to remove specific large-community
1040 values from a set of prefix we can make use of DELETE operation based
1044 tgen
= get_topogen()
1045 tc_name
= request
.node
.name
1046 write_test_header(tc_name
)
1048 # Don"t run this test if we have any failure.
1049 if tgen
.routers_have_failure():
1050 pytest
.skip(tgen
.errors
)
1052 # Creating configuration from JSON
1053 reset_config_on_routers(tgen
)
1055 step("configure route_map")
1058 "bgp_community_lists": [
1060 "community_type": "standard",
1063 "value": "1:2:1 1:1:10 1:3:100",
1069 result
= create_bgp_community_lists(tgen
, input_dict_2
)
1070 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1072 step("Create route map")
1080 "set": {"large_comm_list": {"id": "Test", "delete": True}},
1092 "large_community": {
1093 "num": "1:2:1 1:1:10 1:3:100 2:1:1 2:2:2 2:3:3"
1095 "action": "additive",
1103 result
= create_route_maps(tgen
, input_dict_3
)
1104 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1106 step("Configure neighbor for route map and advertise networks")
1113 "advertise_networks": [{"network": "200.50.2.0/32"}]
1117 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
1132 {"name": "RM_R4_IN", "direction": "in"}
1147 {"name": "RM_R4_IN", "direction": "in"}
1168 {"name": "RM_R6_IN", "direction": "in"}
1183 {"name": "RM_R6_IN", "direction": "in"}
1195 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
1196 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1198 step("Verify large-community-list")
1200 input_dict_5
= {"largeCommunity": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"}
1201 for adt
in ADDR_TYPES
:
1202 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_5
)
1203 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1207 write_test_footer(tc_name
)
1210 def test_large_community_lists_with_no_send_community(request
):
1212 This test is to verify if we want to remove specific large-community
1213 values from a set of prefix we can make use of DELETE operation based
1217 tgen
= get_topogen()
1218 tc_name
= request
.node
.name
1219 write_test_header(tc_name
)
1221 # Don"t run this test if we have any failure.
1222 if tgen
.routers_have_failure():
1223 pytest
.skip(tgen
.errors
)
1225 # Creating configuration from JSON
1226 reset_config_on_routers(tgen
)
1228 step("Create route map")
1237 "large_community": {"num": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"}
1244 result
= create_route_maps(tgen
, input_dict_2
)
1245 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1247 step("Configure neighbor for route map and advertise networks")
1254 "advertise_networks": [{"network": "200.50.2.0/32"}]
1258 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
1274 "name": "RM_R6_OUT",
1292 "name": "RM_R6_OUT",
1306 result
= create_router_bgp(tgen
, topo
, input_dict_3
)
1307 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1309 step("Verify large-community-list")
1311 input_dict_4
= {"largeCommunity": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"}
1312 for adt
in ADDR_TYPES
:
1313 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_4
)
1314 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1318 step("Configure neighbor for no-send-community")
1327 "dest_link": {"r5": {"no_send_community": "large"}}
1336 "dest_link": {"r5": {"no_send_community": "large"}}
1345 result
= create_router_bgp(tgen
, topo
, input_dict_5
)
1346 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1348 step("Verify Community-list")
1349 for adt
in ADDR_TYPES
:
1350 result
= verify_bgp_community(
1351 tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_4
, expected
=False
1353 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
1357 write_test_footer(tc_name
)
1360 def test_create_large_community_lists_with_no_attribute_values(request
):
1362 This test is to verify that large-community lists can not be
1363 configured without providing specific L-community values
1364 (for match/delete operation in a route-map).
1367 tgen
= get_topogen()
1368 tc_name
= request
.node
.name
1369 write_test_header(tc_name
)
1371 # Don"t run this test if we have any failure.
1372 if tgen
.routers_have_failure():
1373 pytest
.skip(tgen
.errors
)
1375 # Creating configuration from JSON
1376 reset_config_on_routers(tgen
)
1378 step("Create standard large commumity-list")
1381 "bgp_community_lists": [
1383 "community_type": "standard",
1391 result
= create_bgp_community_lists(tgen
, input_dict_1
)
1392 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
1396 write_test_footer(tc_name
)
1399 def test_large_community_lists_with_rmap_match_exact(request
):
1401 This test is to verify that Match_EXACT clause should pass
1402 only if all of the L-comm values configured (horizontally)
1403 in the community list is present in the prefix. There must
1404 be no additional L-communities in the prefix.
1407 tgen
= get_topogen()
1408 tc_name
= request
.node
.name
1409 write_test_header(tc_name
)
1411 # Don"t run this test if we have any failure.
1412 if tgen
.routers_have_failure():
1413 pytest
.skip(tgen
.errors
)
1415 # Creating configuration from JSON
1416 reset_config_on_routers(tgen
)
1418 step("Create route map")
1427 "large_community": {"num": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"}
1434 result
= create_route_maps(tgen
, input_dict_2
)
1435 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1437 step("Configure neighbor for route map and advertise networks")
1444 "advertise_networks": [{"network": "200.50.2.0/32"}]
1448 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
1464 "name": "RM_R4_OUT",
1482 "name": "RM_R4_OUT",
1497 result
= create_router_bgp(tgen
, topo
, input_dict_3
)
1498 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1500 step("Create standard large commumity-list")
1503 "bgp_community_lists": [
1505 "community_type": "standard",
1508 "value": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5",
1514 result
= create_bgp_community_lists(tgen
, input_dict_4
)
1515 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1517 step("Verify BGP large community is created")
1518 result
= verify_create_community_list(tgen
, input_dict_4
)
1519 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1521 step("Create route map")
1530 "large-community-list": ["EXACT"],
1531 "match_exact": True,
1538 result
= create_route_maps(tgen
, input_dict_5
)
1539 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1541 step("Configure neighbor for route map")
1553 {"name": "RM_R4_IN", "direction": "in"}
1568 {"name": "RM_R4_IN", "direction": "in"}
1580 result
= create_router_bgp(tgen
, topo
, input_dict_6
)
1581 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1583 step("Verify large-community-list")
1585 input_dict_4
= {"largeCommunity": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"}
1586 for adt
in ADDR_TYPES
:
1587 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_4
)
1588 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1592 write_test_footer(tc_name
)
1595 def test_large_community_lists_with_rmap_match_all(request
):
1597 This test is to verify that Match_ALL clause should pass
1598 only if ALL of the L-comm values configured (horizontally)
1599 in the community list are present in the prefix. There
1600 could be additional L-communities in the prefix that are
1601 not present in the L-comm list.
1604 tgen
= get_topogen()
1605 tc_name
= request
.node
.name
1606 write_test_header(tc_name
)
1608 # Don"t run this test if we have any failure.
1609 if tgen
.routers_have_failure():
1610 pytest
.skip(tgen
.errors
)
1612 # Creating configuration from JSON
1613 reset_config_on_routers(tgen
)
1615 step("Create route map")
1623 "large_community": {
1624 "num": "1:1:1 1:2:3 2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"
1632 result
= create_route_maps(tgen
, input_dict_2
)
1633 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1635 step("Configure neighbor for route map")
1642 "advertise_networks": [{"network": "200.50.2.0/32"}]
1646 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
1662 "name": "RM_R4_OUT",
1680 "name": "RM_R4_OUT",
1694 result
= create_router_bgp(tgen
, topo
, input_dict_3
)
1695 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1697 step("Create standard large commumity-list")
1700 "bgp_community_lists": [
1702 "community_type": "standard",
1705 "value": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5",
1711 result
= create_bgp_community_lists(tgen
, input_dict_4
)
1712 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1714 step("Verify BGP large community is created")
1715 result
= verify_create_community_list(tgen
, input_dict_4
)
1716 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1718 step("Create route map")
1726 "match": {"large-community-list": {"id": "ALL"}},
1732 result
= create_route_maps(tgen
, input_dict_5
)
1733 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1735 step("Configure neighbor for route map")
1747 {"name": "RM_R4_IN", "direction": "in"}
1762 {"name": "RM_R4_IN", "direction": "in"}
1774 result
= create_router_bgp(tgen
, topo
, input_dict_6
)
1775 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1777 step("Verify large-community-list")
1779 input_dict_4
= {"largeCommunity": "1:1:1 1:2:3 2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"}
1780 for adt
in ADDR_TYPES
:
1781 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_4
)
1782 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1786 write_test_footer(tc_name
)
1789 def test_large_community_lists_with_rmap_match_any(request
):
1791 This test is to verify that Match_ANY clause should pass
1792 only if at-least any one L-comm value configured(vertically)
1793 in large-community list, is present in prefixes.
1796 tgen
= get_topogen()
1797 tc_name
= request
.node
.name
1798 write_test_header(tc_name
)
1800 # Don"t run this test if we have any failure.
1801 if tgen
.routers_have_failure():
1802 pytest
.skip(tgen
.errors
)
1804 # Creating configuration from JSON
1805 reset_config_on_routers(tgen
)
1807 step("Create route map")
1816 "large_community": {"num": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"}
1823 result
= create_route_maps(tgen
, input_dict_2
)
1824 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1826 step("Configure neighbor for route map")
1833 "advertise_networks": [{"network": "200.50.2.0/32"}]
1837 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
1853 "name": "RM_R4_OUT",
1871 "name": "RM_R4_OUT",
1885 result
= create_router_bgp(tgen
, topo
, input_dict_3
)
1886 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1888 step("Create standard large commumity-list")
1891 "bgp_community_lists": [
1893 "community_type": "standard",
1900 "community_type": "standard",
1907 "community_type": "standard",
1914 "community_type": "standard",
1923 result
= create_bgp_community_lists(tgen
, input_dict_4
)
1924 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1926 step("Verify BGP large community is created")
1927 result
= verify_create_community_list(tgen
, input_dict_4
)
1928 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1930 step("Create route map")
1938 "match": {"large-community-list": {"id": "ANY"}},
1944 result
= create_route_maps(tgen
, input_dict_5
)
1945 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1947 step("Configure neighbor for route map")
1959 {"name": "RM_R4_IN", "direction": "in"}
1974 {"name": "RM_R4_IN", "direction": "in"}
1986 result
= create_router_bgp(tgen
, topo
, input_dict_6
)
1987 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1989 step("Verify large-community-list")
1991 input_dict_7
= {"largeCommunity": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"}
1992 for adt
in ADDR_TYPES
:
1993 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_7
)
1994 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1998 write_test_footer(tc_name
)
2001 def test_large_community_lists_with_rmap_match_regex(request
):
2003 This test is to verify large-community lists" operation in a route-map
2004 with match RegEx statements. Match clause should pass only if the
2005 complete string of L-comm values are matched
2008 tgen
= get_topogen()
2009 tc_name
= request
.node
.name
2010 write_test_header(tc_name
)
2012 # Don"t run this test if we have any failure.
2013 if tgen
.routers_have_failure():
2014 pytest
.skip(tgen
.errors
)
2016 # Creating configuration from JSON
2017 reset_config_on_routers(tgen
)
2019 step("Create route map")
2028 "large_community": {
2029 "num": "1:1:1 1:1:2 2:1:3 2:1:4 2:1:5",
2031 "community": {"num": "1:1 1:2 1:3 1:4 1:5"},
2038 result
= create_route_maps(tgen
, input_dict_2
)
2039 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2041 step("Configure neighbor for route map")
2048 "advertise_networks": [{"network": "200.50.2.0/32"}]
2052 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
2068 "name": "RM_R4_OUT",
2086 "name": "RM_R4_OUT",
2100 result
= create_router_bgp(tgen
, topo
, input_dict_3
)
2101 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2103 step("Create standard large commumity-list")
2106 "bgp_community_lists": [
2108 "community_type": "standard",
2111 "value": "1:1:1 2:1:3 2:1:4 2:1:5",
2115 "community_type": "expanded",
2118 "value": "1:1:1 2:1:[3-5]",
2124 result
= create_bgp_community_lists(tgen
, input_dict_4
)
2125 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2127 step("Verify BGP large community is created")
2128 result
= verify_create_community_list(tgen
, input_dict_4
)
2129 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2131 step("Create route map")
2140 "large_community_list": {
2149 result
= create_route_maps(tgen
, input_dict_5
)
2150 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2152 step("Configure neighbor for route map")
2164 {"name": "RM_R4_IN", "direction": "in"}
2179 {"name": "RM_R4_IN", "direction": "in"}
2191 result
= create_router_bgp(tgen
, topo
, input_dict_6
)
2192 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2194 step("Verify large-community-list")
2196 input_dict_7
= {"largeCommunity": "1:1:1 1:1:2 2:1:3 2:1:4 2:1:5"}
2197 for adt
in ADDR_TYPES
:
2198 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_7
)
2199 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2203 step("Delete route map reference by community-list")
2204 input_dict_3
= {"r4": {"route_maps": ["RM_R4_IN"]}}
2205 result
= delete_route_maps(tgen
, input_dict_3
)
2206 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2208 result
= verify_route_maps(tgen
, input_dict_3
)
2209 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2211 step("Create route map")
2220 "large_community_list": {
2229 result
= create_route_maps(tgen
, input_dict_5
)
2230 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2232 step("clear ip bgp")
2233 result
= clear_bgp_and_verify(tgen
, topo
, "r4")
2234 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
2236 step("Verify large-community-list")
2238 input_dict_7
= {"largeCommunity": "1:1:1 1:1:2 2:1:3 2:1:4 2:1:5"}
2239 for adt
in ADDR_TYPES
:
2240 result
= verify_bgp_community(
2241 tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_7
, expected
=False
2243 assert result
is not True, (
2244 "Testcase {} : Failed \n "
2245 "largeCommunity is still present \n Error: {}".format(tc_name
, result
)
2248 write_test_footer(tc_name
)
2251 if __name__
== "__main__":
2252 args
= ["-s"] + sys
.argv
[1:]
2253 sys
.exit(pytest
.main(args
))