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 pytestmark
= [pytest
.mark
.bgpd
]
103 # Reading the data from JSON File for topology and configuration creation
104 jsonFile
= "{}/bgp_large_community_topo_2.json".format(CWD
)
107 with
open(jsonFile
, "r") as topoJson
:
108 topo
= json
.load(topoJson
)
110 assert False, "Could not read file {}".format(jsonFile
)
113 bgp_convergence
= False
115 NETWORKS
= {"ipv4": ["200.50.2.0/32"], "ipv6": ["1::1/128"]}
118 class GenerateTopo(Topo
):
120 Test topology builder
122 * `Topo`: Topology object
125 def build(self
, *_args
, **_opts
):
127 tgen
= get_topogen(self
)
129 # Building topology from json file
130 build_topo_from_json(tgen
, topo
)
133 def setup_module(mod
):
135 Sets up the pytest environment
140 # Required linux kernel version for this suite to run.
141 result
= required_linux_kernel_version("4.15")
142 if result
is not True:
143 pytest
.skip("Kernel requirements are not met")
145 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
146 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
147 logger
.info("=" * 40)
149 logger
.info("Running setup_module to create topology")
151 # This function initiates the topology build with Topogen...
152 tgen
= Topogen(GenerateTopo
, mod
.__name
__)
153 # ... and here it calls Mininet initialization functions.
155 # Starting topology, create tmp files which are loaded to routers
156 # to start deamons and then start routers
159 # Creating configuration from JSON
160 build_config_from_json(tgen
, topo
)
162 # Checking BGP convergence
163 global bgp_convergence
, ADDR_TYPES
165 # Don"t run this test if we have any failure.
166 if tgen
.routers_have_failure():
167 pytest
.skip(tgen
.errors
)
169 # Api call verify whether BGP is converged
171 bgp_convergence
= verify_bgp_convergence(tgen
, topo
)
172 assert bgp_convergence
is True, "setup_module :Failed \n Error:" " {}".format(
175 ADDR_TYPES
= check_address_types()
177 logger
.info("Running setup_module() done")
180 def teardown_module(mod
):
182 Teardown the pytest environment
187 logger
.info("Running teardown_module to delete topology")
191 # Stop toplogy and Remove tmp files
195 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
197 logger
.info("=" * 40)
200 #####################################################
204 #####################################################
207 def test_create_bgp_standard_large_community_list(request
):
209 Create standard large-community-list and verify it can permit
210 or deny large community attribute only in the correct canonical
215 tc_name
= request
.node
.name
216 write_test_header(tc_name
)
218 # Don"t run this test if we have any failure.
219 if tgen
.routers_have_failure():
220 pytest
.skip(tgen
.errors
)
222 reset_config_on_routers(tgen
)
224 step("Create srtandard large community list")
227 "bgp_community_lists": [
229 "community_type": "standard",
232 "value": "2:1:1 2:1:2 1:2:3",
236 "community_type": "standard",
239 "value": "3:1:1 3:1:2",
245 result
= create_bgp_community_lists(tgen
, input_dict
)
246 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
248 step("Verify BGP large community is created")
249 result
= verify_create_community_list(tgen
, input_dict
)
250 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
252 step("Create srtandard large community list with in-correct values")
255 "bgp_community_lists": [
257 "community_type": "standard",
259 "name": "LC_1_STD_ERR",
266 result
= create_bgp_community_lists(tgen
, input_dict
)
267 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
270 step("Verify BGP large community is created")
271 result
= verify_create_community_list(tgen
, input_dict
)
272 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
274 write_test_footer(tc_name
)
277 def test_create_bgp_expanded_large_community_list(request
):
279 Create expanded large-community-list and verify it can permit
280 or deny large community attribute both in the correct canonical
281 format as well as REG_EX
285 tc_name
= request
.node
.name
286 write_test_header(tc_name
)
288 # Don"t run this test if we have any failure.
289 if tgen
.routers_have_failure():
290 pytest
.skip(tgen
.errors
)
292 # Creating configuration from JSON
293 reset_config_on_routers(tgen
)
295 step("Create expanded large community list")
298 "bgp_community_lists": [
300 "community_type": "expanded",
303 "value": "1:1:200 1:2:* 3:2:1",
309 result
= create_bgp_community_lists(tgen
, input_dict
)
310 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
312 step("Verify BGP large community is created")
313 result
= verify_create_community_list(tgen
, input_dict
)
314 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
316 write_test_footer(tc_name
)
319 def test_modify_large_community_lists_referenced_by_rmap(request
):
321 This test is to verify that we can modify a large-community-list
322 is in use, add/remove attribute value and it takes immediate effect.
326 tc_name
= request
.node
.name
327 write_test_header(tc_name
)
329 # Don"t run this test if we have any failure.
330 if tgen
.routers_have_failure():
331 pytest
.skip(tgen
.errors
)
333 # Creating configuration from JSON
334 reset_config_on_routers(tgen
)
336 step("Create standard large community list")
339 "bgp_community_lists": [
341 "community_type": "standard",
344 "value": "1:2:1 1:3:1 2:1:1 2:2:2 3:3:3",
350 result
= create_bgp_community_lists(tgen
, input_dict_1
)
351 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
353 step("Create route map")
363 "num": "1:2:1 1:3:1 2:10:1 3:3:3 4:4:4 5:5:5",
364 "action": "additive",
377 "set": {"large_comm_list": {"id": "LC_DEL", "delete": True}},
383 result
= create_route_maps(tgen
, input_dict_2
)
384 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
386 step("Configure neighbor for route map and advertise networks")
393 "advertise_networks": [{"network": "200.50.2.0/32"}],
412 "advertise_networks": [{"network": "1::1/128"}],
442 {"name": "RM_R4_IN", "direction": "in"}
457 {"name": "RM_R4_IN", "direction": "in"}
469 result
= create_router_bgp(tgen
, topo
, input_dict_3
)
470 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
472 step("Verify Community-list")
474 input_dict_4
= {"largeCommunity": "2:10:1 4:4:4 5:5:5"}
476 for adt
in ADDR_TYPES
:
477 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_4
)
478 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
482 write_test_footer(tc_name
)
485 def test_large_community_lists_with_rmap_apply_and_remove(request
):
487 This test is to verify that large community attribute gets advertised when
488 route-map is applied to a neighbor and cleared when route-map is removed
492 tc_name
= request
.node
.name
493 write_test_header(tc_name
)
495 # Don"t run this test if we have any failure.
496 if tgen
.routers_have_failure():
497 pytest
.skip(tgen
.errors
)
499 # Creating configuration from JSON
500 reset_config_on_routers(tgen
)
502 step("Create route map")
512 "num": "200:200:1 200:200:10 200:200:20000",
513 "action": "additive",
521 result
= create_route_maps(tgen
, input_dict_1
)
522 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
524 step("Configure neighbor for route map and advertise networks")
531 "advertise_networks": [{"network": "200.50.2.0/32"}]
535 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
550 {"name": "RM_LC1", "direction": "out"}
565 {"name": "RM_LC1", "direction": "out"}
577 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
578 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
580 step("Verify large-community-list")
582 input_dict_4
= {"largeCommunity": "200:200:1 200:200:10 200:200:20000"}
584 for adt
in ADDR_TYPES
:
585 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_4
)
586 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
590 step("Delete route map reference by community-list")
591 input_dict_3
= {"r4": {"route_maps": ["RM_LC1"]}}
592 result
= delete_route_maps(tgen
, input_dict_3
)
593 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
595 step("Verify route map is deleted")
596 result
= verify_route_maps(tgen
, input_dict_3
)
597 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
599 step("Verify large-community-list")
600 for adt
in ADDR_TYPES
:
601 result
= verify_bgp_community(
602 tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_4
, expected
=False
604 assert result
is not True, (
605 "Testcase {} : Failed \n "
606 "largeCommunity is still present after deleting route-map \n Error: {}".format(
611 write_test_footer(tc_name
)
614 def test_duplicate_large_community_list_attributes_not_transitive(request
):
616 This test is to verify that duplicate BGP Large Community values
617 are NOT be transmitted.
621 tc_name
= request
.node
.name
622 write_test_header(tc_name
)
624 # Don"t run this test if we have any failure.
625 if tgen
.routers_have_failure():
626 pytest
.skip(tgen
.errors
)
628 # Creating configuration from JSON
629 reset_config_on_routers(tgen
)
631 step("Create route map")
641 "num": "0:0:1 0:0:10 0:0:100 2:0:1 2:0:2 2:0:3"
643 "action": "additive",
654 "num": "0:0:1 0:0:10 0:0:10000 2:0:1 2:0:2",
655 "action": "additive",
663 result
= create_route_maps(tgen
, input_dict_1
)
664 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
666 step("Configure neighbor for route map and advertise networks")
673 "advertise_networks": [{"network": "200.50.2.0/32"}]
677 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
692 {"name": "RM_R4_IN", "direction": "in"}
719 {"name": "RM_R4_IN", "direction": "in"}
743 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
744 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
746 step("Verify large-community-list")
749 "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"
751 for adt
in ADDR_TYPES
:
752 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_4
)
753 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
757 write_test_footer(tc_name
)
760 def test_large_community_lists_with_rmap_set_none(request
):
762 This test is to verify if we want to remove all the large-community
763 attributes from a set of prefix we can set the value as NONE.
767 tc_name
= request
.node
.name
768 write_test_header(tc_name
)
770 # Don"t run this test if we have any failure.
771 if tgen
.routers_have_failure():
772 pytest
.skip(tgen
.errors
)
774 # Creating configuration from JSON
775 reset_config_on_routers(tgen
)
777 step("Create route map")
787 "num": "0:0:1 0:0:10 0:0:100 2:0:1 2:0:2 2:0:3"
789 "action": "additive",
802 "set": {"large_community": {"num": "none"}},
808 result
= create_route_maps(tgen
, input_dict_1
)
809 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
811 step("Configure neighbor for route map")
818 "advertise_networks": [{"network": "200.50.2.0/32"}]
822 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
837 {"name": "RM_R4_IN", "direction": "in"}
852 {"name": "RM_R4_IN", "direction": "in"}
873 {"name": "RM_R6_IN", "direction": "in"}
888 {"name": "RM_R6_IN", "direction": "in"}
900 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
901 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
903 step("Verify Community-list")
905 for adt
in ADDR_TYPES
:
906 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], expected
=False)
907 assert result
is not True, (
908 "Testcase {} : Failed \n "
909 "Community-list is still present \n Error: {}".format(tc_name
, result
)
912 write_test_footer(tc_name
)
915 def test_lcomm_lists_with_redistribute_static_connected_rmap(request
):
917 This test is to verify redistribute connected and static ipv4 routes
918 in BGP process with a route-map appending/removing L-comm attributes.
922 tc_name
= request
.node
.name
923 write_test_header(tc_name
)
925 # Don"t run this test if we have any failure.
926 if tgen
.routers_have_failure():
927 pytest
.skip(tgen
.errors
)
929 # Creating configuration from JSON
930 reset_config_on_routers(tgen
)
932 step("create static routes")
936 {"network": "200.50.2.0/32", "next_hop": "10.0.0.6"},
937 {"network": "1::1/128", "next_hop": "fd00:0:0:1::2"},
941 result
= create_static_routes(tgen
, input_dict
)
942 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
944 step("redistribute static routes")
953 "redist_type": "static",
954 "attribute": "route-map RM_R2_OUT",
957 "redist_type": "connected",
958 "attribute": "route-map RM_R2_OUT",
967 "redist_type": "static",
968 "attribute": "route-map RM_R2_OUT",
971 "redist_type": "connected",
972 "attribute": "route-map RM_R2_OUT",
981 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
982 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
984 step("Create route map")
991 "set": {"large_community": {"num": "55:55:55 555:555:555"}},
997 result
= create_route_maps(tgen
, input_dict_3
)
998 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1000 step("Verify large-community-list for static and connected ipv4 route on" " r2")
1002 input_dict_5
= {"largeCommunity": "55:55:55 555:555:555"}
1004 if "ipv4" in ADDR_TYPES
:
1006 networks
= ["200.50.2.0/32", "1.0.1.17/32"]
1007 result
= verify_bgp_community(tgen
, "ipv4", dut
, networks
, input_dict_5
)
1008 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1012 step("Verify large-community-list for static and connected ipv4 route" " on r4")
1014 networks
= ["200.50.2.0/32", "1.0.1.17/32"]
1015 result
= verify_bgp_community(tgen
, "ipv4", dut
, networks
, input_dict_5
)
1016 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1020 if "ipv6" in ADDR_TYPES
:
1021 step("Verify large-community-list for static and connected ipv6 route" " on r2")
1023 networks
= ["1::1/128", "2001:db8:f::1:17/128"]
1024 result
= verify_bgp_community(tgen
, "ipv6", dut
, networks
, input_dict_5
)
1025 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1029 step("Verify large-community-list for static and connected ipv6 route" " on r4")
1031 networks
= ["1::1/128", "2001:db8:f::1:17/128"]
1032 result
= verify_bgp_community(tgen
, "ipv6", dut
, networks
, input_dict_5
)
1033 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1037 write_test_footer(tc_name
)
1040 def test_large_community_lists_with_rmap_set_delete(request
):
1042 This test is to verify if we want to remove specific large-community
1043 values from a set of prefix we can make use of DELETE operation based
1047 tgen
= get_topogen()
1048 tc_name
= request
.node
.name
1049 write_test_header(tc_name
)
1051 # Don"t run this test if we have any failure.
1052 if tgen
.routers_have_failure():
1053 pytest
.skip(tgen
.errors
)
1055 # Creating configuration from JSON
1056 reset_config_on_routers(tgen
)
1058 step("configure route_map")
1061 "bgp_community_lists": [
1063 "community_type": "standard",
1066 "value": "1:2:1 1:1:10 1:3:100",
1072 result
= create_bgp_community_lists(tgen
, input_dict_2
)
1073 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1075 step("Create route map")
1083 "set": {"large_comm_list": {"id": "Test", "delete": True}},
1095 "large_community": {
1096 "num": "1:2:1 1:1:10 1:3:100 2:1:1 2:2:2 2:3:3"
1098 "action": "additive",
1106 result
= create_route_maps(tgen
, input_dict_3
)
1107 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1109 step("Configure neighbor for route map and advertise networks")
1116 "advertise_networks": [{"network": "200.50.2.0/32"}]
1120 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
1135 {"name": "RM_R4_IN", "direction": "in"}
1150 {"name": "RM_R4_IN", "direction": "in"}
1171 {"name": "RM_R6_IN", "direction": "in"}
1186 {"name": "RM_R6_IN", "direction": "in"}
1198 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
1199 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1201 step("Verify large-community-list")
1203 input_dict_5
= {"largeCommunity": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"}
1204 for adt
in ADDR_TYPES
:
1205 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_5
)
1206 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1210 write_test_footer(tc_name
)
1213 def test_large_community_lists_with_no_send_community(request
):
1215 This test is to verify if we want to remove specific large-community
1216 values from a set of prefix we can make use of DELETE operation based
1220 tgen
= get_topogen()
1221 tc_name
= request
.node
.name
1222 write_test_header(tc_name
)
1224 # Don"t run this test if we have any failure.
1225 if tgen
.routers_have_failure():
1226 pytest
.skip(tgen
.errors
)
1228 # Creating configuration from JSON
1229 reset_config_on_routers(tgen
)
1231 step("Create route map")
1240 "large_community": {"num": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"}
1247 result
= create_route_maps(tgen
, input_dict_2
)
1248 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1250 step("Configure neighbor for route map and advertise networks")
1257 "advertise_networks": [{"network": "200.50.2.0/32"}]
1261 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
1277 "name": "RM_R6_OUT",
1295 "name": "RM_R6_OUT",
1309 result
= create_router_bgp(tgen
, topo
, input_dict_3
)
1310 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1312 step("Verify large-community-list")
1314 input_dict_4
= {"largeCommunity": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"}
1315 for adt
in ADDR_TYPES
:
1316 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_4
)
1317 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1321 step("Configure neighbor for no-send-community")
1330 "dest_link": {"r5": {"no_send_community": "large"}}
1339 "dest_link": {"r5": {"no_send_community": "large"}}
1348 result
= create_router_bgp(tgen
, topo
, input_dict_5
)
1349 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1351 step("Verify Community-list")
1352 for adt
in ADDR_TYPES
:
1353 result
= verify_bgp_community(
1354 tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_4
, expected
=False
1356 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
1360 write_test_footer(tc_name
)
1363 def test_create_large_community_lists_with_no_attribute_values(request
):
1365 This test is to verify that large-community lists can not be
1366 configured without providing specific L-community values
1367 (for match/delete operation in a route-map).
1370 tgen
= get_topogen()
1371 tc_name
= request
.node
.name
1372 write_test_header(tc_name
)
1374 # Don"t run this test if we have any failure.
1375 if tgen
.routers_have_failure():
1376 pytest
.skip(tgen
.errors
)
1378 # Creating configuration from JSON
1379 reset_config_on_routers(tgen
)
1381 step("Create standard large commumity-list")
1384 "bgp_community_lists": [
1386 "community_type": "standard",
1394 result
= create_bgp_community_lists(tgen
, input_dict_1
)
1395 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
1399 write_test_footer(tc_name
)
1402 def test_large_community_lists_with_rmap_match_exact(request
):
1404 This test is to verify that Match_EXACT clause should pass
1405 only if all of the L-comm values configured (horizontally)
1406 in the community list is present in the prefix. There must
1407 be no additional L-communities in the prefix.
1410 tgen
= get_topogen()
1411 tc_name
= request
.node
.name
1412 write_test_header(tc_name
)
1414 # Don"t run this test if we have any failure.
1415 if tgen
.routers_have_failure():
1416 pytest
.skip(tgen
.errors
)
1418 # Creating configuration from JSON
1419 reset_config_on_routers(tgen
)
1421 step("Create route map")
1430 "large_community": {"num": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"}
1437 result
= create_route_maps(tgen
, input_dict_2
)
1438 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1440 step("Configure neighbor for route map and advertise networks")
1447 "advertise_networks": [{"network": "200.50.2.0/32"}]
1451 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
1467 "name": "RM_R4_OUT",
1485 "name": "RM_R4_OUT",
1500 result
= create_router_bgp(tgen
, topo
, input_dict_3
)
1501 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1503 step("Create standard large commumity-list")
1506 "bgp_community_lists": [
1508 "community_type": "standard",
1511 "value": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5",
1517 result
= create_bgp_community_lists(tgen
, input_dict_4
)
1518 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1520 step("Verify BGP large community is created")
1521 result
= verify_create_community_list(tgen
, input_dict_4
)
1522 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1524 step("Create route map")
1533 "large-community-list": ["EXACT"],
1534 "match_exact": True,
1541 result
= create_route_maps(tgen
, input_dict_5
)
1542 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1544 step("Configure neighbor for route map")
1556 {"name": "RM_R4_IN", "direction": "in"}
1571 {"name": "RM_R4_IN", "direction": "in"}
1583 result
= create_router_bgp(tgen
, topo
, input_dict_6
)
1584 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1586 step("Verify large-community-list")
1588 input_dict_4
= {"largeCommunity": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"}
1589 for adt
in ADDR_TYPES
:
1590 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_4
)
1591 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1595 write_test_footer(tc_name
)
1598 def test_large_community_lists_with_rmap_match_all(request
):
1600 This test is to verify that Match_ALL clause should pass
1601 only if ALL of the L-comm values configured (horizontally)
1602 in the community list are present in the prefix. There
1603 could be additional L-communities in the prefix that are
1604 not present in the L-comm list.
1607 tgen
= get_topogen()
1608 tc_name
= request
.node
.name
1609 write_test_header(tc_name
)
1611 # Don"t run this test if we have any failure.
1612 if tgen
.routers_have_failure():
1613 pytest
.skip(tgen
.errors
)
1615 # Creating configuration from JSON
1616 reset_config_on_routers(tgen
)
1618 step("Create route map")
1626 "large_community": {
1627 "num": "1:1:1 1:2:3 2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"
1635 result
= create_route_maps(tgen
, input_dict_2
)
1636 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1638 step("Configure neighbor for route map")
1645 "advertise_networks": [{"network": "200.50.2.0/32"}]
1649 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
1665 "name": "RM_R4_OUT",
1683 "name": "RM_R4_OUT",
1697 result
= create_router_bgp(tgen
, topo
, input_dict_3
)
1698 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1700 step("Create standard large commumity-list")
1703 "bgp_community_lists": [
1705 "community_type": "standard",
1708 "value": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5",
1714 result
= create_bgp_community_lists(tgen
, input_dict_4
)
1715 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1717 step("Verify BGP large community is created")
1718 result
= verify_create_community_list(tgen
, input_dict_4
)
1719 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1721 step("Create route map")
1729 "match": {"large-community-list": {"id": "ALL"}},
1735 result
= create_route_maps(tgen
, input_dict_5
)
1736 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1738 step("Configure neighbor for route map")
1750 {"name": "RM_R4_IN", "direction": "in"}
1765 {"name": "RM_R4_IN", "direction": "in"}
1777 result
= create_router_bgp(tgen
, topo
, input_dict_6
)
1778 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1780 step("Verify large-community-list")
1782 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"}
1783 for adt
in ADDR_TYPES
:
1784 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_4
)
1785 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1789 write_test_footer(tc_name
)
1792 def test_large_community_lists_with_rmap_match_any(request
):
1794 This test is to verify that Match_ANY clause should pass
1795 only if at-least any one L-comm value configured(vertically)
1796 in large-community list, is present in prefixes.
1799 tgen
= get_topogen()
1800 tc_name
= request
.node
.name
1801 write_test_header(tc_name
)
1803 # Don"t run this test if we have any failure.
1804 if tgen
.routers_have_failure():
1805 pytest
.skip(tgen
.errors
)
1807 # Creating configuration from JSON
1808 reset_config_on_routers(tgen
)
1810 step("Create route map")
1819 "large_community": {"num": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"}
1826 result
= create_route_maps(tgen
, input_dict_2
)
1827 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1829 step("Configure neighbor for route map")
1836 "advertise_networks": [{"network": "200.50.2.0/32"}]
1840 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
1856 "name": "RM_R4_OUT",
1874 "name": "RM_R4_OUT",
1888 result
= create_router_bgp(tgen
, topo
, input_dict_3
)
1889 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1891 step("Create standard large commumity-list")
1894 "bgp_community_lists": [
1896 "community_type": "standard",
1903 "community_type": "standard",
1910 "community_type": "standard",
1917 "community_type": "standard",
1926 result
= create_bgp_community_lists(tgen
, input_dict_4
)
1927 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1929 step("Verify BGP large community is created")
1930 result
= verify_create_community_list(tgen
, input_dict_4
)
1931 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1933 step("Create route map")
1941 "match": {"large-community-list": {"id": "ANY"}},
1947 result
= create_route_maps(tgen
, input_dict_5
)
1948 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1950 step("Configure neighbor for route map")
1962 {"name": "RM_R4_IN", "direction": "in"}
1977 {"name": "RM_R4_IN", "direction": "in"}
1989 result
= create_router_bgp(tgen
, topo
, input_dict_6
)
1990 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1992 step("Verify large-community-list")
1994 input_dict_7
= {"largeCommunity": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"}
1995 for adt
in ADDR_TYPES
:
1996 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_7
)
1997 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2001 write_test_footer(tc_name
)
2004 def test_large_community_lists_with_rmap_match_regex(request
):
2006 This test is to verify large-community lists" operation in a route-map
2007 with match RegEx statements. Match clause should pass only if the
2008 complete string of L-comm values are matched
2011 tgen
= get_topogen()
2012 tc_name
= request
.node
.name
2013 write_test_header(tc_name
)
2015 # Don"t run this test if we have any failure.
2016 if tgen
.routers_have_failure():
2017 pytest
.skip(tgen
.errors
)
2019 # Creating configuration from JSON
2020 reset_config_on_routers(tgen
)
2022 step("Create route map")
2031 "large_community": {
2032 "num": "1:1:1 1:1:2 2:1:3 2:1:4 2:1:5",
2034 "community": {"num": "1:1 1:2 1:3 1:4 1:5"},
2041 result
= create_route_maps(tgen
, input_dict_2
)
2042 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2044 step("Configure neighbor for route map")
2051 "advertise_networks": [{"network": "200.50.2.0/32"}]
2055 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
2071 "name": "RM_R4_OUT",
2089 "name": "RM_R4_OUT",
2103 result
= create_router_bgp(tgen
, topo
, input_dict_3
)
2104 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2106 step("Create standard large commumity-list")
2109 "bgp_community_lists": [
2111 "community_type": "standard",
2114 "value": "1:1:1 2:1:3 2:1:4 2:1:5",
2118 "community_type": "expanded",
2121 "value": "1:1:1 2:1:[3-5]",
2127 result
= create_bgp_community_lists(tgen
, input_dict_4
)
2128 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2130 step("Verify BGP large community is created")
2131 result
= verify_create_community_list(tgen
, input_dict_4
)
2132 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2134 step("Create route map")
2143 "large_community_list": {
2152 result
= create_route_maps(tgen
, input_dict_5
)
2153 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2155 step("Configure neighbor for route map")
2167 {"name": "RM_R4_IN", "direction": "in"}
2182 {"name": "RM_R4_IN", "direction": "in"}
2194 result
= create_router_bgp(tgen
, topo
, input_dict_6
)
2195 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2197 step("Verify large-community-list")
2199 input_dict_7
= {"largeCommunity": "1:1:1 1:1:2 2:1:3 2:1:4 2:1:5"}
2200 for adt
in ADDR_TYPES
:
2201 result
= verify_bgp_community(tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_7
)
2202 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2206 step("Delete route map reference by community-list")
2207 input_dict_3
= {"r4": {"route_maps": ["RM_R4_IN"]}}
2208 result
= delete_route_maps(tgen
, input_dict_3
)
2209 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2211 result
= verify_route_maps(tgen
, input_dict_3
)
2212 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2214 step("Create route map")
2223 "large_community_list": {
2232 result
= create_route_maps(tgen
, input_dict_5
)
2233 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2235 step("clear ip bgp")
2236 result
= clear_bgp_and_verify(tgen
, topo
, "r4")
2237 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
2239 step("Verify large-community-list")
2241 input_dict_7
= {"largeCommunity": "1:1:1 1:1:2 2:1:3 2:1:4 2:1:5"}
2242 for adt
in ADDR_TYPES
:
2243 result
= verify_bgp_community(
2244 tgen
, adt
, dut
, NETWORKS
[adt
], input_dict_7
, expected
=False
2246 assert result
is not True, (
2247 "Testcase {} : Failed \n "
2248 "largeCommunity is still present \n Error: {}".format(tc_name
, result
)
2251 write_test_footer(tc_name
)
2254 if __name__
== "__main__":
2255 args
= ["-s"] + sys
.argv
[1:]
2256 sys
.exit(pytest
.main(args
))