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
23 """Following tests are covered to test route-map functionality.
25 Create route map to match prefix-list and permit inbound
26 and outbound prefixes and set criteria on match
28 Test modify set/match clauses in a route-map to see
29 if it takes immediate effect.
31 Delete the route maps.
33 Test modify/remove prefix-lists referenced by a
34 route-map for match statement.
36 Remove prefix-list referencec by route-map match cluase
37 and verifying it reflecting as intended
39 Add and remove community-list referencec by route-map match cluase
40 and verifying it reflecting as intended
42 Test multiple match statements as part of a route-map"s single
43 sequence number. (Logical OR-ed of multiple match statements)
45 Test multiple match statements as part of a route-map"s single
46 sequence number. (Logical AND of multiple match statements)
48 Test add/remove route-maps to specific neighbor and see if
49 it takes effect as intended
51 Test clear BGP sessions and interface flaps to see if
52 route-map properties are intact.
54 Verify if a blank sequence number can be create(without any
55 match/set clause) and check if it allows all the traffic/prefixes
57 Create route map setting local preference and weight to eBGP peeer
58 and metric to ibgp peer and verifying it should not get advertised
60 Test multiple set statements as part of a route-map"s
61 single sequence number.
63 Verify route-maps continue clause functionality.
65 Verify route-maps goto clause functionality.
67 Verify route-maps call clause functionality.
69 Create route map deny inbound and outbound prefixes on
70 match prefix list and set criteria on match
72 Create route map to permit inbound prefixes with filter
73 match tag and set criteria
75 Create route map to deny outbound prefixes with filter match tag,
79 #################################
81 #################################
92 | iBGP +-------+ eBGP +-------+
93 +---------- | R3 |----------| R4 |
111 from time
import sleep
113 # Save the Current Working Directory to find configuration files.
114 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
115 sys
.path
.append(os
.path
.join(CWD
, "../"))
117 # pylint: disable=C0413
118 # Import topogen and topotest helpers
119 from lib
import topotest
120 from lib
.topogen
import Topogen
, get_topogen
121 from mininet
.topo
import Topo
123 # Required to instantiate the topology builder class.
124 from lib
.common_config
import (
128 create_static_routes
,
131 create_bgp_community_lists
,
137 verify_bgp_community
,
138 shutdown_bringup_interface
,
140 reset_config_on_routers
,
141 verify_create_community_list
,
143 from lib
.topolog
import logger
144 from lib
.bgp
import (
145 verify_bgp_convergence
,
147 clear_bgp_and_verify
,
148 verify_bgp_attributes
,
150 from lib
.topojson
import build_topo_from_json
, build_config_from_json
152 # Reading the data from JSON File for topology and configuration creation
153 jsonFile
= "{}/bgp_route_map_topo2.json".format(CWD
)
156 with
open(jsonFile
, "r") as topoJson
:
157 topo
= json
.load(topoJson
)
159 assert False, "Could not read file {}".format(jsonFile
)
163 bgp_convergence
= False
164 NETWORK
= {"ipv4": ["11.0.20.1/32", "11.0.20.2/32"], "ipv6": ["2::1/128", "2::2/128"]}
166 bgp_convergence
= False
167 BGP_CONVERGENCE
= False
168 ADDR_TYPES
= check_address_types()
171 class BGPRmapTopo(Topo
):
175 * `Topo`: Topology object
178 def build(self
, *_args
, **_opts
):
179 """Build function."""
180 tgen
= get_topogen(self
)
182 # Building topology and configuration from json file
183 build_topo_from_json(tgen
, topo
)
186 def setup_module(mod
):
189 Set up the pytest environment
192 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
193 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
194 logger
.info("=" * 40)
196 logger
.info("Running setup_module to create topology")
198 # This function initiates the topology build with Topogen...
199 tgen
= Topogen(BGPRmapTopo
, mod
.__name
__)
200 # ... and here it calls Mininet initialization functions.
202 # Starting topology, create tmp files which are loaded to routers
203 # to start deamons and then start routers
206 # Creating configuration from JSON
207 build_config_from_json(tgen
, topo
)
209 # Checking BGP convergence
210 global bgp_convergence
213 # Don"t run this test if we have any failure.
214 if tgen
.routers_have_failure():
215 pytest
.skip(tgen
.errors
)
217 # Api call verify whether BGP is converged
218 bgp_convergence
= verify_bgp_convergence(tgen
, topo
)
219 assert bgp_convergence
is True, "setup_module :Failed \n Error:" " {}".format(
222 logger
.info("Running setup_module() done")
225 def teardown_module(mod
):
228 Teardown the pytest environment.
231 logger
.info("Running teardown_module to delete topology")
234 # Stop toplogy and Remove tmp files
238 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
240 logger
.info("=" * 40)
243 #####################################################
245 #####################################################
248 def test_rmap_match_prefix_list_permit_in_and_outbound_prefixes_p0():
251 Create route map to match prefix-list and permit inbound
252 and outbound prefixes and set criteria on match
255 global bgp_convergence
257 if bgp_convergence
is not True:
258 pytest
.skip("skipped because of BGP Convergence failure")
261 tc_name
= inspect
.stack()[0][3]
262 write_test_header(tc_name
)
263 reset_config_on_routers(tgen
)
265 # Create ip prefix list
291 result
= create_prefix_lists(tgen
, input_dict_2
)
292 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
293 for addr_type
in ADDR_TYPES
:
298 "rmap_match_pf_1_{}".format(addr_type
): [
303 addr_type
: {"prefix_lists": "pf_list_1_" + addr_type
}
305 "set": {"locPrf": 150, "weight": 100},
308 "rmap_match_pf_2_{}".format(addr_type
): [
313 addr_type
: {"prefix_lists": "pf_list_1_" + addr_type
}
315 "set": {"metric": 50},
321 result
= create_route_maps(tgen
, input_dict_3
)
322 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
326 # Configure neighbor for route map
339 "name": "rmap_match_pf_1_ipv4",
351 "name": "rmap_match_pf_2_ipv4",
369 "name": "rmap_match_pf_1_ipv6",
381 "name": "rmap_match_pf_2_ipv6",
396 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
397 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
399 # Verifying RIB routes
402 input_dict
= topo
["routers"]
405 for addr_type
in ADDR_TYPES
:
406 result4
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
407 assert result4
is True, "Testcase {} : Failed \n Error: {}".format(
411 # Verifying BGP set attributes
414 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
415 "ipv6": ["1::1/128", "1::2/128"],
418 for addr_type
in ADDR_TYPES
:
419 rmap_name
= "rmap_match_pf_1_{}".format(addr_type
)
420 result4
= verify_bgp_attributes(
421 tgen
, addr_type
, dut
, routes
[addr_type
], rmap_name
, input_dict_3
423 assert result4
is True, "Testcase {} : Failed \n Error: {}".format(
427 # Verifying RIB routes
431 for addr_type
in ADDR_TYPES
:
432 result4
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
433 assert result4
is True, "Testcase {} : Failed \n Error: {}".format(
437 # Verifying BGP set attributes
440 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
441 "ipv6": ["1::1/128", "1::2/128"],
444 for addr_type
in ADDR_TYPES
:
445 rmap_name
= "rmap_match_pf_2_{}".format(addr_type
)
446 result
= verify_bgp_attributes(
447 tgen
, addr_type
, dut
, routes
[addr_type
], rmap_name
, input_dict_3
449 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
452 write_test_footer(tc_name
)
454 # Uncomment next line for debugging
458 def test_modify_set_match_clauses_in_rmap_p0():
461 Test modify set/match clauses in a route-map to see
462 if it takes immediate effect.
466 global bgp_convergence
468 if bgp_convergence
is not True:
469 pytest
.skip("skipped because of BGP Convergence failure")
472 tc_name
= inspect
.stack()[0][3]
473 write_test_header(tc_name
)
474 reset_config_on_routers(tgen
)
476 # Create ip prefix list
490 {"seqid": 10, "network": "any", "action": "permit"}
502 {"seqid": 10, "network": "any", "action": "permit"}
508 result
= create_prefix_lists(tgen
, input_dict_2
)
509 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
512 for addr_type
in ADDR_TYPES
:
516 "rmap_match_pf_1_{}".format(addr_type
): [
522 "prefix_lists": "pf_list_1_{}".format(addr_type
)
530 "rmap_match_pf_2_{}".format(addr_type
): [
536 "prefix_lists": "pf_list_1_{}".format(addr_type
)
539 "set": {"metric": 50},
545 result
= create_route_maps(tgen
, input_dict_3
)
546 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
550 # Configure neighbor for route map
563 "name": "rmap_match_pf_1_ipv4",
575 "name": "rmap_match_pf_2_ipv4",
593 "name": "rmap_match_pf_1_ipv6",
605 "name": "rmap_match_pf_2_ipv6",
619 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
620 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
622 # Verifying RIB routes
625 input_dict
= topo
["routers"]
626 for addr_type
in ADDR_TYPES
:
627 result
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
628 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
632 # Verifying BGP set attributes
635 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
636 "ipv6": ["1::1/128", "1::2/128"],
639 for addr_type
in ADDR_TYPES
:
640 rmap_name
= "rmap_match_pf_1_{}".format(addr_type
)
641 result4
= verify_bgp_attributes(
642 tgen
, addr_type
, dut
, routes
[addr_type
], rmap_name
, input_dict_3
644 assert result4
is True, "Testcase {} : Failed \n Error: {}".format(
648 # Verifying RIB routes
652 for addr_type
in ADDR_TYPES
:
653 result4
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
654 assert result4
is True, "Testcase {} : Failed \n Error: {}".format(
658 # Verifying BGP set attributes
661 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
662 "ipv6": ["1::1/128", "1::2/128"],
664 for addr_type
in ADDR_TYPES
:
665 rmap_name
= "rmap_match_pf_2_{}".format(addr_type
)
666 result
= verify_bgp_attributes(
667 tgen
, addr_type
, dut
, routes
[addr_type
], rmap_name
, input_dict_3
669 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
673 # Modify set/match clause of in-used route map
674 for addr_type
in ADDR_TYPES
:
678 "rmap_match_pf_1_{}".format(addr_type
): [
684 "prefix_lists": "pf_list_1_{}".format(addr_type
)
692 "rmap_match_pf_2_{}".format(addr_type
): [
698 "prefix_lists": "pf_list_1_{}".format(addr_type
)
701 "set": {"metric": 2000},
707 result
= create_route_maps(tgen
, input_dict_3
)
708 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
712 # Verifying RIB routes
715 for addr_type
in ADDR_TYPES
:
716 result
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
717 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
721 # Verifying BGP set attributes
724 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
725 "ipv6": ["1::1/128", "1::2/128"],
727 for addr_type
in ADDR_TYPES
:
728 rmap_name
= "rmap_match_pf_1_{}".format(addr_type
)
729 result
= verify_bgp_attributes(
730 tgen
, addr_type
, dut
, routes
[addr_type
], rmap_name
, input_dict_3
732 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
736 # Verifying RIB routes
739 for addr_type
in ADDR_TYPES
:
740 result
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
741 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
745 # Verifying BGP set attributes
748 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
749 "ipv6": ["1::1/128", "1::2/128"],
751 for addr_type
in ADDR_TYPES
:
752 rmap_name
= "rmap_match_pf_2_{}".format(addr_type
)
753 result
= verify_bgp_attributes(
754 tgen
, addr_type
, dut
, routes
[addr_type
], rmap_name
, input_dict_3
756 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
760 write_test_footer(tc_name
)
762 # Uncomment next line for debugging
766 def test_delete_route_maps_p1():
769 Delete the route maps.
773 global bgp_convergence
775 if bgp_convergence
is not True:
776 pytest
.skip("skipped because of BGP Convergence failure")
779 tc_name
= inspect
.stack()[0][3]
780 write_test_header(tc_name
)
781 reset_config_on_routers(tgen
)
784 for addr_type
in ADDR_TYPES
:
788 "rmap_match_tag_1_{}".format(addr_type
): [
789 {"action": "deny", "match": {addr_type
: {"tag": "4001"}}}
794 result
= create_route_maps(tgen
, input_dict_3
)
795 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
800 for addr_type
in ADDR_TYPES
:
801 input_dict
= {"r3": {"route_maps": ["rmap_match_tag_1_{}".format(addr_type
)]}}
802 result
= delete_route_maps(tgen
, input_dict
)
803 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
807 result
= verify_route_maps(tgen
, input_dict
)
808 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
809 write_test_footer(tc_name
)
811 # Uncomment next line for debugging
815 def test_modify_prefix_list_referenced_by_rmap_p0():
818 Test modify/remove prefix-lists referenced by a
819 route-map for match statement.
823 global bgp_convergence
825 if bgp_convergence
is not True:
826 pytest
.skip("skipped because of BGP Convergence failure")
829 tc_name
= inspect
.stack()[0][3]
830 write_test_header(tc_name
)
831 reset_config_on_routers(tgen
)
833 # Create ip prefix list
858 result
= create_prefix_lists(tgen
, input_dict_2
)
859 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
862 for addr_type
in ADDR_TYPES
:
866 "rmap_match_pf_1_{}".format(addr_type
): [
872 "prefix_lists": "pf_list_1_{}".format(addr_type
)
875 "set": {"locPrf": 150, "weight": 100},
878 "rmap_match_pf_2_{}".format(addr_type
): [
884 "prefix_lists": "pf_list_1_{}".format(addr_type
)
887 "set": {"metric": 50},
893 result
= create_route_maps(tgen
, input_dict_3
)
894 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
898 # Configure neighbor for route map
911 "name": "rmap_match_pf_1_ipv4",
923 "name": "rmap_match_pf_2_ipv4",
941 "name": "rmap_match_pf_1_ipv6",
953 "name": "rmap_match_pf_2_ipv6",
968 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
969 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
971 # Verifying RIB routes
974 input_dict
= topo
["routers"]
975 for addr_type
in ADDR_TYPES
:
976 result
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
977 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
981 # Verifying BGP set attributes
984 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
985 "ipv6": ["1::1/128", "1::2/128"],
987 for addr_type
in ADDR_TYPES
:
988 rmap_name
= "rmap_match_pf_1_{}".format(addr_type
)
989 result
= verify_bgp_attributes(
990 tgen
, addr_type
, dut
, routes
[addr_type
], rmap_name
, input_dict_3
992 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
996 # Verifying RIB routes
999 for addr_type
in ADDR_TYPES
:
1000 result
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
1001 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1005 # Verifying BGP set attributes
1008 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
1009 "ipv6": ["1::1/128", "1::2/128"],
1012 for addr_type
in ADDR_TYPES
:
1013 rmap_name
= "rmap_match_pf_2_{}".format(addr_type
)
1014 result
= verify_bgp_attributes(
1015 tgen
, addr_type
, dut
, routes
[addr_type
], rmap_name
, input_dict_3
1017 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1021 # Modify ip prefix list
1027 {"seqid": 10, "network": "any", "action": "deny"}
1032 {"seqid": 100, "network": "any", "action": "deny"}
1038 result
= create_prefix_lists(tgen
, input_dict_2
)
1039 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1042 # Verifying RIB routes
1045 for addr_type
in ADDR_TYPES
:
1046 result
= verify_rib(
1047 tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
, expected
=False
1049 assert result
is not True, "Testcase {} : Failed \n"
1050 "routes are not present \n Error: {}".format(tc_name
, result
)
1051 logger
.info("Expected behaviour: {}".format(result
))
1053 # Verifying RIB routes
1056 for addr_type
in ADDR_TYPES
:
1057 result
= verify_rib(
1058 tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
, expected
=False
1060 assert result
is not True, "Testcase {} : Failed \n"
1061 "Expected behaviour: routes are not present \n "
1062 "Error: {}".format(tc_name
, result
)
1064 write_test_footer(tc_name
)
1066 # Uncomment next line for debugging
1067 # tgen.mininet_cli()
1070 def test_remove_prefix_list_referenced_by_rmap_p0():
1073 Remove prefix-list referencec by route-map match cluase
1074 and verifying it reflecting as intended
1076 tgen
= get_topogen()
1077 global bgp_convergence
1079 if bgp_convergence
is not True:
1080 pytest
.skip("skipped because of BGP Convergence failure")
1083 tc_name
= inspect
.stack()[0][3]
1084 write_test_header(tc_name
)
1085 reset_config_on_routers(tgen
)
1087 # Create ip prefix list
1093 {"seqid": 10, "network": "any", "action": "permit"}
1098 {"seqid": 100, "network": "any", "action": "permit"}
1104 result
= create_prefix_lists(tgen
, input_dict_2
)
1105 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1108 for addr_type
in ADDR_TYPES
:
1112 "rmap_match_pf_1_{}".format(addr_type
): [
1118 "prefix_lists": "pf_list_1_{}".format(addr_type
)
1126 "rmap_match_pf_2_{}".format(addr_type
): [
1132 "prefix_lists": "pf_list_1_{}".format(addr_type
)
1135 "set": {"metric": 50},
1141 result
= create_route_maps(tgen
, input_dict_3
)
1142 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1146 # Configure neighbor for route map
1147 for addr_type
in ADDR_TYPES
:
1160 "name": "rmap_match_pf_1_ipv4",
1172 "name": "rmap_match_pf_2_ipv4",
1190 "name": "rmap_match_pf_1_ipv6",
1202 "name": "rmap_match_pf_2_ipv6",
1216 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
1217 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1221 # Verifying RIB routes
1224 input_dict
= topo
["routers"]
1225 for addr_type
in ADDR_TYPES
:
1226 result
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
1227 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1231 # Verifying BGP set attributes
1234 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
1235 "ipv6": ["1::1/128", "1::2/128"],
1237 for addr_type
in ADDR_TYPES
:
1238 rmap_name
= "rmap_match_pf_1_{}".format(addr_type
)
1239 result
= verify_bgp_attributes(
1240 tgen
, addr_type
, dut
, routes
[addr_type
], rmap_name
, input_dict_3
1242 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1246 # Verifying RIB routes
1249 for addr_type
in ADDR_TYPES
:
1250 result
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
1251 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1255 # Verifying BGP set attributes
1258 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
1259 "ipv6": ["1::1/128", "1::2/128"],
1261 for addr_type
in ADDR_TYPES
:
1262 rmap_name
= "rmap_match_pf_2_{}".format(addr_type
)
1263 result
= verify_bgp_attributes(
1264 tgen
, addr_type
, dut
, routes
[addr_type
], rmap_name
, input_dict_3
1266 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1270 # Remove/Delete prefix list
1297 result
= create_prefix_lists(tgen
, input_dict_3
)
1298 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1300 result
= verify_prefix_lists(tgen
, input_dict_3
)
1301 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1303 # Api call to clear bgp, so config changes would be reflected
1305 result
= clear_bgp_and_verify(tgen
, topo
, dut
)
1306 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1308 # Verifying RIB routes
1311 for addr_type
in ADDR_TYPES
:
1312 result
= verify_rib(
1313 tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
, expected
=False
1315 assert result
is not True, "Testcase {} : Failed \n"
1316 "routes are not present \n Error: {}".format(tc_name
, result
)
1317 logger
.info("Expected behaviour: {}".format(result
))
1319 # Verifying RIB routes
1322 for addr_type
in ADDR_TYPES
:
1323 result
= verify_rib(
1324 tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
, expected
=False
1326 assert result
is not True, "Testcase {} : Failed \n"
1327 "routes are not present \n Error: {}".format(tc_name
, result
)
1328 logger
.info("Expected behaviour: {}".format(result
))
1330 write_test_footer(tc_name
)
1332 # Uncomment next line for debugging
1333 # tgen.mininet_cli()
1336 def test_add_and_remove_community_list_referenced_by_rmap_p0():
1339 Add and remove community-list referencec by route-map match cluase
1340 and verifying it reflecting as intended
1342 tgen
= get_topogen()
1343 global bgp_convergence
1345 if bgp_convergence
is not True:
1346 pytest
.skip("skipped because of BGP Convergence failure")
1349 tc_name
= inspect
.stack()[0][3]
1350 write_test_header(tc_name
)
1351 reset_config_on_routers(tgen
)
1353 # Creating configuration from JSON
1354 # build_config_from_json(tgen, topo)
1357 for addr_type
in ADDR_TYPES
:
1361 "rm_r1_out_{}".format(addr_type
): [
1365 "large_community": {"num": "1:1:1 1:2:3 2:1:1 2:2:2"}
1372 result
= create_route_maps(tgen
, input_dict_5
)
1373 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1377 # Configure neighbor for route map
1390 "name": "rm_r1_out_ipv4",
1408 "name": "rm_r1_out_ipv6",
1423 result
= create_router_bgp(tgen
, topo
, input_dict_6
)
1424 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1426 for addr_type
in ADDR_TYPES
:
1427 # Create standard large commumity-list
1430 "bgp_community_lists": [
1432 "community_type": "standard",
1434 "name": "rmap_lcomm_{}".format(addr_type
),
1435 "value": "1:1:1 1:2:3 2:1:1 2:2:2",
1441 result
= create_bgp_community_lists(tgen
, input_dict_1
)
1442 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1446 # Verify BGP large community is created
1447 result
= verify_create_community_list(tgen
, input_dict_1
)
1448 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1450 for addr_type
in ADDR_TYPES
:
1455 "rm_r3_in_{}".format(addr_type
): [
1460 "large-community-list": {
1461 "id": "rmap_lcomm_" + addr_type
1470 result
= create_route_maps(tgen
, input_dict_2
)
1471 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1475 # Configure neighbor for route map
1488 "name": "rm_r3_in_ipv4",
1506 "name": "rm_r3_in_ipv6",
1520 result
= create_router_bgp(tgen
, topo
, input_dict_3
)
1522 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1525 # Verifying RIB routes
1528 input_dict
= topo
["routers"]
1529 for addr_type
in ADDR_TYPES
:
1530 result
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
1531 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1535 # Verify large-community-list
1538 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
1539 "ipv6": ["1::1/128", "1::2/128"],
1541 input_dict_4
= {"largeCommunity": "1:1:1 1:2:3 2:1:1 2:2:2"}
1542 for addr_type
in ADDR_TYPES
:
1543 result
= verify_bgp_community(
1544 tgen
, addr_type
, dut
, networks
[addr_type
], input_dict_4
1546 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1549 write_test_footer(tc_name
)
1551 # Uncomment next line for debugging
1552 # tgen.mininet_cli()
1555 def test_multiple_match_statement_in_route_map_logical_ORed_p0():
1558 Test multiple match statements as part of a route-map"s single
1559 sequence number. (Logical OR-ed of multiple match statements)
1561 tgen
= get_topogen()
1562 global bgp_convergence
1564 if bgp_convergence
is not True:
1565 pytest
.skip("skipped because of BGP Convergence failure")
1568 tc_name
= inspect
.stack()[0][3]
1569 write_test_header(tc_name
)
1570 reset_config_on_routers(tgen
)
1572 # Api call to advertise networks
1578 "unicast": {"advertise_networks": [{"network": "10.0.30.1/32"}]}
1581 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
1588 result
= create_router_bgp(tgen
, topo
, input_dict_nw1
)
1589 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1591 # Api call to advertise networks
1597 "unicast": {"advertise_networks": [{"network": "20.0.30.1/32"}]}
1600 "unicast": {"advertise_networks": [{"network": "2::1/128"}]}
1607 result
= create_router_bgp(tgen
, topo
, input_dict_nw2
)
1608 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1610 # Create ip prefix list
1616 {"seqid": 10, "network": "any", "action": "permit"}
1621 {"seqid": 100, "network": "any", "action": "permit"}
1627 result
= create_prefix_lists(tgen
, input_dict_2
)
1628 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1630 # Create ip prefix list
1636 {"seqid": 10, "network": "any", "action": "permit"}
1641 {"seqid": 100, "network": "any", "action": "permit"}
1647 result
= create_prefix_lists(tgen
, input_dict_2
)
1648 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1650 input_dict_3_addr_type
= {}
1652 for addr_type
in ADDR_TYPES
:
1656 "rmap_match_pf_1_{}".format(addr_type
): [
1662 "prefix_lists": "pf_list_1_{}".format(addr_type
)
1665 "set": {"locPrf": 150},
1671 input_dict_3_addr_type
[addr_type
] = input_dict_3
1672 result
= create_route_maps(tgen
, input_dict_3
)
1673 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1678 for addr_type
in ADDR_TYPES
:
1682 "rmap_match_pf_1_{}".format(addr_type
): [
1688 "prefix_lists": "pf_list_1_{}".format(addr_type
)
1691 "set": {"locPrf": 200},
1697 input_dict_3_addr_type
[addr_type
] = input_dict_3
1698 result
= create_route_maps(tgen
, input_dict_3
)
1699 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1703 # Configure neighbor for route map
1716 "name": "rmap_match_pf_1_ipv4",
1734 "name": "rmap_match_pf_1_ipv6",
1749 result
= create_router_bgp(tgen
, topo
, input_dict_6
)
1750 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1752 # Verifying RIB routes
1755 input_dict
= topo
["routers"]
1756 for addr_type
in ADDR_TYPES
:
1757 result
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
1758 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1762 # Verifying BGP set attributes
1764 routes
= {"ipv4": ["10.0.30.1/32"], "ipv6": ["1::1/128"]}
1765 for addr_type
in ADDR_TYPES
:
1766 rmap_name
= "rmap_match_pf_1_{}".format(addr_type
)
1767 result
= verify_bgp_attributes(
1773 input_dict_3_addr_type
[addr_type
],
1775 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1779 # Verifying BGP set attributes
1780 routes
= {"ipv4": ["20.0.30.1/32"], "ipv6": ["2::1/128"]}
1781 for addr_type
in ADDR_TYPES
:
1782 result
= verify_bgp_attributes(
1783 tgen
, addr_type
, dut
, routes
[addr_type
], rmap_name
, input_dict_3
1785 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1789 write_test_footer(tc_name
)
1791 # Uncomment next line for debugging
1792 # tgen.mininet_cli()
1795 def test_multiple_match_statement_in_route_map_logical_ANDed_p1():
1798 Test multiple match statements as part of a route-map"s single
1799 sequence number. (Logical AND of multiple match statements)
1801 tgen
= get_topogen()
1802 global bgp_convergence
1804 if bgp_convergence
is not True:
1805 pytest
.skip("skipped because of BGP Convergence failure")
1808 tc_name
= inspect
.stack()[0][3]
1809 write_test_header(tc_name
)
1810 reset_config_on_routers(tgen
)
1813 for addr_type
in ADDR_TYPES
:
1817 "rm_r1_out_{}".format(addr_type
): [
1821 "large_community": {"num": "1:1:1 1:2:3 2:1:1 2:2:2"}
1828 result
= create_route_maps(tgen
, input_dict_5
)
1829 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1833 # Configure neighbor for route map
1834 for addr_type
in ADDR_TYPES
:
1847 "name": "rm_r1_out_{}".format(
1863 result
= create_router_bgp(tgen
, topo
, input_dict_6
)
1864 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1868 # Create ip prefix list
1874 {"seqid": 10, "network": "any", "action": "permit"}
1879 {"seqid": 100, "network": "any", "action": "permit"}
1885 result
= create_prefix_lists(tgen
, input_dict_2
)
1887 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1889 for addr_type
in ADDR_TYPES
:
1890 # Create standard large commumity-list
1893 "bgp_community_lists": [
1895 "community_type": "standard",
1897 "name": "rmap_lcomm_{}".format(addr_type
),
1898 "value": "1:1:1 1:2:3 2:1:1 2:2:2",
1904 result
= create_bgp_community_lists(tgen
, input_dict_1
)
1905 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1909 # Verify BGP large community is created
1910 result
= verify_create_community_list(tgen
, input_dict_1
)
1911 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1914 for addr_type
in ADDR_TYPES
:
1918 "rmap_match_pf_1_{}".format(addr_type
): [
1924 "prefix_lists": "pf_list_1_{}".format(addr_type
)
1935 result
= create_route_maps(tgen
, input_dict_3
)
1936 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1940 for addr_type
in ADDR_TYPES
:
1945 "rmap_match_pf_1_{}".format(addr_type
): [
1951 "large_community_list": {
1952 "id": "rmap_lcomm_" + addr_type
1964 result
= create_route_maps(tgen
, input_dict_3
)
1965 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1968 # Configure neighbor for route map
1969 for addr_type
in ADDR_TYPES
:
1982 "name": "rmap_match_pf_1_{}".format(
1998 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
1999 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2003 # Verifying RIB routes
2006 input_dict
= topo
["routers"]
2007 for addr_type
in ADDR_TYPES
:
2008 result
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
2009 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2013 # Verifying BGP set attributes
2016 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
2017 "ipv6": ["1::1/128", "1::2/128"],
2019 for addr_type
in ADDR_TYPES
:
2020 rmap_name
= "rmap_match_pf_1_{}".format(addr_type
)
2021 result
= verify_bgp_attributes(
2022 tgen
, addr_type
, dut
, routes
[addr_type
], rmap_name
, input_dict_3
2024 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2028 write_test_footer(tc_name
)
2030 # Uncomment next line for debugging
2031 # tgen.mininet_cli()
2034 def test_add_remove_rmap_to_specific_neighbor_p0():
2037 Test add/remove route-maps to specific neighbor and see if
2038 it takes effect as intended
2040 tgen
= get_topogen()
2041 global bgp_convergence
2043 if bgp_convergence
is not True:
2044 pytest
.skip("skipped because of BGP Convergence failure")
2047 tc_name
= inspect
.stack()[0][3]
2048 write_test_header(tc_name
)
2049 reset_config_on_routers(tgen
)
2051 # Create ip prefix list
2057 {"seqid": 10, "network": "any", "action": "deny"}
2062 {"seqid": 100, "network": "any", "action": "deny"}
2068 result
= create_prefix_lists(tgen
, input_dict_2
)
2069 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2072 for addr_type
in ADDR_TYPES
:
2076 "rmap_match_pf_1_{}".format(addr_type
): [
2082 "prefix_lists": "pf_list_1_{}".format(addr_type
)
2093 result
= create_route_maps(tgen
, input_dict_3
)
2094 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2098 # Configure neighbor for route map
2111 "name": "rmap_match_pf_1_ipv4",
2129 "name": "rmap_match_pf_1_ipv6",
2144 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
2145 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2147 # Verifying RIB routes
2150 input_dict
= topo
["routers"]
2151 for addr_type
in ADDR_TYPES
:
2152 result
= verify_rib(
2153 tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
, expected
=False
2155 assert result
is not True, "Testcase {} : Failed \n Error"
2156 "Routes are still present: {}".format(tc_name
, result
)
2157 logger
.info("Expected behaviour: {}".format(result
))
2159 # Remove applied rmap from neighbor
2172 "name": "rmap_match_pf_1_ipv4",
2191 "name": "rmap_match_pf_1_ipv6",
2207 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
2208 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2210 # Verifying RIB routes
2213 input_dict
= topo
["routers"]
2214 for addr_type
in ADDR_TYPES
:
2215 result
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
2216 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2220 write_test_footer(tc_name
)
2222 # Uncomment next line for debugging
2223 # tgen.mininet_cli()
2226 def test_clear_bgp_and_flap_interface_to_verify_rmap_properties_p0():
2229 Test clear BGP sessions and interface flaps to see if
2230 route-map properties are intact.
2232 tgen
= get_topogen()
2233 global bgp_convergence
2235 if bgp_convergence
is not True:
2236 pytest
.skip("skipped because of BGP Convergence failure")
2239 tc_name
= inspect
.stack()[0][3]
2240 write_test_header(tc_name
)
2241 reset_config_on_routers(tgen
)
2243 # Create ip prefix list
2249 {"seqid": 10, "network": "any", "action": "permit"}
2254 {"seqid": 100, "network": "any", "action": "permit"}
2260 result
= create_prefix_lists(tgen
, input_dict_2
)
2261 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2264 for addr_type
in ADDR_TYPES
:
2268 "rmap_match_pf_1_{}".format(addr_type
): [
2274 "prefix_lists": "pf_list_1_{}".format(addr_type
)
2277 "set": {"locPrf": 150, "weight": 100},
2283 result
= create_route_maps(tgen
, input_dict_3
)
2284 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2288 # Configure neighbor for route map
2301 "name": "rmap_match_pf_1_ipv4",
2319 "name": "rmap_match_pf_1_ipv6",
2334 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
2335 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2337 # Verifying RIB routes
2340 input_dict
= topo
["routers"]
2341 for addr_type
in ADDR_TYPES
:
2342 result
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
2343 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2347 # Verifying BGP set attributes
2350 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
2351 "ipv6": ["1::1/128", "1::2/128"],
2353 for addr_type
in ADDR_TYPES
:
2354 rmap_name
= "rmap_match_pf_1_{}".format(addr_type
)
2355 result
= verify_bgp_attributes(
2356 tgen
, addr_type
, dut
, routes
[addr_type
], rmap_name
, input_dict_3
2358 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2362 # clear bgp, so config changes would be reflected
2364 result
= clear_bgp_and_verify(tgen
, topo
, dut
)
2365 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2367 # Verifying RIB routes
2370 input_dict
= topo
["routers"]
2371 for addr_type
in ADDR_TYPES
:
2372 result
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
2373 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2377 # Verifying BGP set attributes
2380 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
2381 "ipv6": ["1::1/128", "1::2/128"],
2383 for addr_type
in ADDR_TYPES
:
2384 rmap_name
= "rmap_match_pf_1_{}".format(addr_type
)
2385 result
= verify_bgp_attributes(
2386 tgen
, addr_type
, dut
, routes
[addr_type
], rmap_name
, input_dict_3
2388 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2392 # Flap interface to see if route-map properties are intact
2393 # Shutdown interface
2396 shutdown_bringup_interface(tgen
, dut
, intf
, False)
2403 shutdown_bringup_interface(tgen
, dut
, intf
, True)
2405 # Verify BGP convergence once interface is up
2406 result
= verify_bgp_convergence(tgen
, topo
)
2407 assert result
is True, "setup_module :Failed \n Error:" " {}".format(result
)
2409 # Verifying RIB routes
2412 input_dict
= topo
["routers"]
2413 for addr_type
in ADDR_TYPES
:
2414 result
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
2415 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2419 # Verifying BGP set attributes
2422 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
2423 "ipv6": ["1::1/128", "1::2/128"],
2425 for addr_type
in ADDR_TYPES
:
2426 rmap_name
= "rmap_match_pf_1_{}".format(addr_type
)
2427 result
= verify_bgp_attributes(
2428 tgen
, addr_type
, dut
, routes
[addr_type
], rmap_name
, input_dict_3
2430 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2434 write_test_footer(tc_name
)
2436 # Uncomment next line for debugging
2437 # tgen.mininet_cli()
2440 def test_rmap_without_match_and_set_clause_p0():
2443 Verify if a blank sequence number can be create(without any
2444 match/set clause) and check if it allows all the traffic/prefixes
2446 tgen
= get_topogen()
2447 global bgp_convergence
2449 if bgp_convergence
is not True:
2450 pytest
.skip("skipped because of BGP Convergence failure")
2453 tc_name
= inspect
.stack()[0][3]
2454 write_test_header(tc_name
)
2455 reset_config_on_routers(tgen
)
2458 for addr_type
in ADDR_TYPES
:
2462 "rmap_no_match_set_1_{}".format(addr_type
): [
2463 {"action": "permit", "seq_id": "5"}
2465 "rmap_no_match_set_2_{}".format(addr_type
): [
2466 {"action": "deny", "seq_id": "5"}
2471 result
= create_route_maps(tgen
, input_dict_3
)
2472 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2476 # Configure neighbor for route map
2489 "name": "rmap_no_match_set_1_ipv4",
2501 "name": "rmap_no_match_set_2_ipv4",
2519 "name": "rmap_no_match_set_1_ipv6",
2531 "name": "rmap_no_match_set_2_ipv6",
2546 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
2547 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2549 # Verifying RIB routes
2552 input_dict
= topo
["routers"]
2553 for addr_type
in ADDR_TYPES
:
2554 result
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
2555 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2559 # Verifying RIB routes
2562 for addr_type
in ADDR_TYPES
:
2563 result
= verify_rib(
2564 tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
, expected
=False
2566 assert result
is not True, "Testcase {} : Failed \n"
2567 "routes are not present \n Error: {}".format(tc_name
, result
)
2568 logger
.info("Expected behaviour: {}".format(result
))
2570 write_test_footer(tc_name
)
2571 # Uncomment next line for debugging
2572 # tgen.mininet_cli()
2575 def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0():
2578 Create route map setting local preference and weight to eBGP peeer
2579 and metric to ibgp peer and verifying it should not get advertised
2581 tgen
= get_topogen()
2582 global bgp_convergence
2584 if bgp_convergence
is not True:
2585 pytest
.skip("skipped because of BGP Convergence failure")
2588 tc_name
= inspect
.stack()[0][3]
2589 write_test_header(tc_name
)
2590 reset_config_on_routers(tgen
)
2592 # Create ip prefix list
2598 {"seqid": 10, "network": "any", "action": "permit"}
2603 {"seqid": 100, "network": "any", "action": "permit"}
2609 result
= create_prefix_lists(tgen
, input_dict_2
)
2610 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2613 input_dict_3_addr_type
= {}
2614 for addr_type
in ADDR_TYPES
:
2618 "rmap_match_pf_1_{}".format(addr_type
): [
2623 "prefix_lists": "pf_list_1_{}".format(addr_type
)
2626 "set": {"metric": 50},
2629 "rmap_match_pf_2_{}".format(addr_type
): [
2634 "prefix_lists": "pf_list_1_{}".format(addr_type
)
2637 "set": {"locPrf": 150},
2640 "rmap_match_pf_3_{}".format(addr_type
): [
2645 "prefix_lists": "pf_list_1_{}".format(addr_type
)
2648 "set": {"weight": 1000},
2654 input_dict_3_addr_type
[addr_type
] = input_dict_3
2655 result
= create_route_maps(tgen
, input_dict_3
)
2656 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2660 # Configure neighbor for route map
2673 "name": "rmap_match_pf_1_ipv4",
2685 "name": "rmap_match_pf_2_ipv4",
2697 "name": "rmap_match_pf_3_ipv4",
2715 "name": "rmap_match_pf_1_ipv6",
2727 "name": "rmap_match_pf_2_ipv6",
2739 "name": "rmap_match_pf_3_ipv6",
2754 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
2755 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2757 # Verifying RIB routes
2760 input_dict
= topo
["routers"]
2761 for addr_type
in ADDR_TYPES
:
2762 result
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
2763 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2767 # Verifying BGP set attributes
2770 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
2771 "ipv6": ["1::1/128", "1::2/128"],
2773 rmap_name
= "rmap_match_pf_1"
2774 for addr_type
in ADDR_TYPES
:
2775 rmap_name
= "rmap_match_pf_1_{}".format(addr_type
)
2776 result
= verify_bgp_attributes(
2777 tgen
, addr_type
, dut
, routes
[addr_type
], rmap_name
, input_dict_3
2779 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2783 # Verifying RIB routes
2786 for addr_type
in ADDR_TYPES
:
2787 result
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
2788 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2792 # Verifying BGP set attributes
2795 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
2796 "ipv6": ["1::1/128", "1::2/128"],
2798 rmap_name
= "rmap_match_pf_2"
2799 for addr_type
in ADDR_TYPES
:
2800 rmap_name
= "rmap_match_pf_2_{}".format(addr_type
)
2802 result
= verify_bgp_attributes(
2808 input_dict_3_addr_type
[addr_type
],
2811 assert result
is not True, "Testcase {} : Failed \n"
2812 "Attributes are not set \n Error: {}".format(tc_name
, result
)
2813 logger
.info("Expected behaviour: {}".format(result
))
2815 # Verifying RIB routes
2818 for addr_type
in ADDR_TYPES
:
2819 result
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
2820 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2823 # Verifying BGP set attributes
2826 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
2827 "ipv6": ["1::1/128", "1::2/128"],
2830 rmap_name
= "rmap_match_pf_3"
2831 for addr_type
in ADDR_TYPES
:
2832 rmap_name
= "rmap_match_pf_3_{}".format(addr_type
)
2833 result
= verify_bgp_attributes(
2839 input_dict_3_addr_type
[addr_type
],
2842 assert result
is not True, "Testcase {} : Failed \n"
2843 "Attributes are not set \n Error: {}".format(tc_name
, result
)
2844 logger
.info("Expected behaviour: {}".format(result
))
2846 write_test_footer(tc_name
)
2848 # Uncomment next line for debugging
2849 # tgen.mininet_cli()
2852 def test_multiple_set_on_single_sequence_in_rmap_p0():
2855 Test multiple set statements as part of a route-map"s
2856 single sequence number.
2858 tgen
= get_topogen()
2859 global bgp_convergence
2861 if bgp_convergence
is not True:
2862 pytest
.skip("skipped because of BGP Convergence failure")
2865 tc_name
= inspect
.stack()[0][3]
2866 write_test_header(tc_name
)
2867 reset_config_on_routers(tgen
)
2869 # Create ip prefix list
2875 {"seqid": 10, "network": "any", "action": "permit"}
2880 {"seqid": 100, "network": "any", "action": "permit"}
2886 result
= create_prefix_lists(tgen
, input_dict_2
)
2887 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2890 for addr_type
in ADDR_TYPES
:
2894 "rmap_match_pf_1_{}".format(addr_type
): [
2899 "prefix_lists": "pf_list_1_{}".format(addr_type
)
2902 "set": {"locPrf": 150, "weight": 100, "metric": 50},
2908 result
= create_route_maps(tgen
, input_dict_3
)
2909 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2913 # Configure neighbor for route map
2926 "name": "rmap_match_pf_1_ipv4",
2944 "name": "rmap_match_pf_1_ipv6",
2958 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
2959 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2961 # Verifying RIB routes
2964 input_dict
= topo
["routers"]
2965 for addr_type
in ADDR_TYPES
:
2966 result
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
2967 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2971 # Verifying BGP set attributes
2974 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
2975 "ipv6": ["1::1/128", "1::2/128"],
2978 rmap_name
= "rmap_match_pf_1"
2979 for addr_type
in ADDR_TYPES
:
2980 rmap_name
= "rmap_match_pf_1_{}".format(addr_type
)
2981 result
= verify_bgp_attributes(
2982 tgen
, addr_type
, dut
, routes
[addr_type
], rmap_name
, input_dict_3
2984 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
2988 write_test_footer(tc_name
)
2990 # Uncomment next line for debugging
2991 # tgen.mininet_cli()
2994 def test_route_maps_with_continue_clause_p0():
2997 Verify route-maps continue clause functionality.
2999 tgen
= get_topogen()
3000 global bgp_convergence
3002 if bgp_convergence
is not True:
3003 pytest
.skip("skipped because of BGP Convergence failure")
3006 tc_name
= inspect
.stack()[0][3]
3007 write_test_header(tc_name
)
3008 reset_config_on_routers(tgen
)
3010 # Create ip prefix list
3016 {"seqid": 10, "network": "any", "action": "permit"}
3021 {"seqid": 100, "network": "any", "action": "permit"}
3027 result
= create_prefix_lists(tgen
, input_dict_2
)
3028 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
3031 for addr_type
in ADDR_TYPES
:
3035 "rmap_match_pf_1_{}".format(addr_type
): [
3041 "prefix_lists": "pf_list_1_{}".format(addr_type
)
3044 "set": {"locPrf": 150},
3052 "prefix_lists": "pf_list_1_{}".format(addr_type
)
3055 "set": {"metric": 200},
3062 "prefix_lists": "pf_list_1_{}".format(addr_type
)
3065 "set": {"metric": 100},
3071 result
= create_route_maps(tgen
, input_dict_3
)
3072 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
3076 # Configure neighbor for route map
3089 "name": "rmap_match_pf_1_ipv4",
3107 "name": "rmap_match_pf_1_ipv6",
3121 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
3122 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
3124 # Verifying RIB routes
3127 input_dict
= topo
["routers"]
3128 for addr_type
in ADDR_TYPES
:
3129 result
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
3130 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
3134 # Verifying BGP set attributes
3136 rmap_name
= "rmap_match_pf_1"
3138 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
3139 "ipv6": ["1::1/128", "1::2/128"],
3141 seq_id
= {"ipv4": ["10", "30"], "ipv6": ["10", "30"]}
3142 for addr_type
in ADDR_TYPES
:
3143 rmap_name
= "rmap_match_pf_1_{}".format(addr_type
)
3144 result
= verify_bgp_attributes(
3153 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
3157 write_test_footer(tc_name
)
3159 # Uncomment next line for debugging
3160 # tgen.mininet_cli()
3163 def test_route_maps_with_goto_clause_p0():
3166 Verify route-maps goto clause functionality.
3168 tgen
= get_topogen()
3169 global bgp_convergence
3171 if bgp_convergence
is not True:
3172 pytest
.skip("skipped because of BGP Convergence failure")
3175 tc_name
= inspect
.stack()[0][3]
3176 write_test_header(tc_name
)
3177 reset_config_on_routers(tgen
)
3179 # Create ip prefix list
3185 {"seqid": 10, "network": "any", "action": "permit"}
3190 {"seqid": 100, "network": "any", "action": "permit"}
3196 result
= create_prefix_lists(tgen
, input_dict_2
)
3197 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
3200 for addr_type
in ADDR_TYPES
:
3204 "rmap_match_pf_1_{}".format(addr_type
): [
3210 "prefix_lists": "pf_list_1_{}".format(addr_type
)
3220 "prefix_lists": "pf_list_1_{}".format(addr_type
)
3223 "set": {"metric": 100},
3230 "prefix_lists": "pf_list_1_{}".format(addr_type
)
3233 "set": {"metric": 200},
3239 result
= create_route_maps(tgen
, input_dict_3
)
3240 # tgen.mininet_cli()
3241 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
3245 # Configure neighbor for route map
3258 "name": "rmap_match_pf_1_ipv4",
3276 "name": "rmap_match_pf_1_ipv6",
3290 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
3291 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
3293 # Verifying RIB routes
3296 input_dict
= topo
["routers"]
3297 for addr_type
in ADDR_TYPES
:
3298 result
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
3299 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
3303 # Verifying BGP set attributes
3305 rmap_name
= "rmap_match_pf_1"
3307 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
3308 "ipv6": ["1::1/128", "1::2/128"],
3310 seq_id
= {"ipv4": ["10", "30"], "ipv6": ["10", "30"]}
3311 for addr_type
in ADDR_TYPES
:
3312 rmap_name
= "rmap_match_pf_1_{}".format(addr_type
)
3313 result
= verify_bgp_attributes(
3322 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
3326 write_test_footer(tc_name
)
3328 # Uncomment next line for debugging
3329 # tgen.mininet_cli()
3332 def test_route_maps_with_call_clause_p0():
3335 Verify route-maps call clause functionality.
3337 tgen
= get_topogen()
3338 global bgp_convergence
3340 if bgp_convergence
is not True:
3341 pytest
.skip("skipped because of BGP Convergence failure")
3344 tc_name
= inspect
.stack()[0][3]
3345 write_test_header(tc_name
)
3346 reset_config_on_routers(tgen
)
3348 # Create ip prefix list
3354 {"seqid": 10, "network": "any", "action": "permit"}
3359 {"seqid": 100, "network": "any", "action": "permit"}
3365 result
= create_prefix_lists(tgen
, input_dict_2
)
3366 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
3369 for addr_type
in ADDR_TYPES
:
3373 "rmap_match_pf_1_{}".format(addr_type
): [
3378 "prefix_lists": "pf_list_1_{}".format(addr_type
)
3381 "set": {"locPrf": 150},
3382 "call": "rmap_match_pf_2_{}".format(addr_type
),
3385 "rmap_match_pf_2_{}".format(addr_type
): [
3390 "prefix_lists": "pf_list_1_{}".format(addr_type
)
3393 "set": {"metric": 200},
3399 result
= create_route_maps(tgen
, input_dict_3
)
3400 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
3404 # Configure neighbor for route map
3417 "name": "rmap_match_pf_1_ipv4",
3435 "name": "rmap_match_pf_1_ipv6",
3449 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
3450 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
3452 # Verifying RIB routes
3455 input_dict
= topo
["routers"]
3456 for addr_type
in ADDR_TYPES
:
3457 result
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
3458 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
3462 # Verifying BGP set attributes
3465 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
3466 "ipv6": ["1::1/128", "1::2/128"],
3468 rmap_name
= "rmap_match_pf_1"
3469 for addr_type
in ADDR_TYPES
:
3470 rmap_name
= "rmap_match_pf_1_{}".format(addr_type
)
3471 result
= verify_bgp_attributes(
3472 tgen
, addr_type
, dut
, routes
[addr_type
], rmap_name
, input_dict_3
3474 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
3478 rmap_name
= "rmap_match_pf_2"
3479 for addr_type
in ADDR_TYPES
:
3480 rmap_name
= "rmap_match_pf_2_{}".format(addr_type
)
3481 result
= verify_bgp_attributes(
3482 tgen
, addr_type
, dut
, routes
[addr_type
], rmap_name
, input_dict_3
3484 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
3488 write_test_footer(tc_name
)
3490 # Uncomment next line for debugging
3491 # tgen.mininet_cli()
3494 def test_create_rmap_match_prefix_list_to_deny_in_and_outbound_prefixes_p0():
3497 Create route map deny inbound and outbound prefixes on
3498 match prefix list and set criteria on match
3500 tgen
= get_topogen()
3501 global bgp_convergence
3503 if bgp_convergence
is not True:
3504 pytest
.skip("skipped because of BGP Convergence failure")
3507 tc_name
= inspect
.stack()[0][3]
3508 write_test_header(tc_name
)
3509 reset_config_on_routers(tgen
)
3511 # Create ip prefix list
3517 {"seqid": 10, "network": "any", "action": "permit"}
3522 {"seqid": 100, "network": "any", "action": "permit"}
3528 result
= create_prefix_lists(tgen
, input_dict_2
)
3529 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
3532 for addr_type
in ADDR_TYPES
:
3536 "rmap_match_pf_1_{}".format(addr_type
): [
3541 "prefix_lists": "pf_list_1_{}".format(addr_type
)
3549 "rmap_match_pf_2_{}".format(addr_type
): [
3554 "prefix_lists": "pf_list_1_{}".format(addr_type
)
3557 "set": {"metric": 50},
3563 result
= create_route_maps(tgen
, input_dict_3
)
3564 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
3568 # Configure neighbor for route map
3581 "name": "rmap_match_pf_1_ipv4",
3593 "name": "rmap_match_pf_2_ipv6",
3611 "name": "rmap_match_pf_1_ipv4",
3623 "name": "rmap_match_pf_2_ipv6",
3637 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
3638 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
3640 # Verifying RIB routes
3643 input_dict
= topo
["routers"]
3644 for addr_type
in ADDR_TYPES
:
3645 result
= verify_rib(
3646 tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
, expected
=False
3648 assert result
is not True, "Testcase {} : Failed \n"
3649 "routes are not present \n Error: {}".format(tc_name
, result
)
3650 logger
.info("Expected behaviour: {}".format(result
))
3652 # Verifying RIB routes
3655 for addr_type
in ADDR_TYPES
:
3656 result
= verify_rib(
3657 tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
, expected
=False
3659 assert result
is not True, "Testcase {} : Failed \n"
3660 "routes are not present \n Error: {}".format(tc_name
, result
)
3661 logger
.info("Expected behaviour: {}".format(result
))
3663 write_test_footer(tc_name
)
3665 # Uncomment next line for debugging
3666 # tgen.mininet_cli()
3669 def test_create_rmap_to_match_tag_permit_inbound_prefixes_p0():
3672 Create route map to permit inbound prefixes with filter
3673 match tag and set criteria
3675 tgen
= get_topogen()
3676 global bgp_convergence
3678 if bgp_convergence
is not True:
3679 pytest
.skip("skipped because of BGP Convergence failure")
3682 tc_name
= inspect
.stack()[0][3]
3683 write_test_header(tc_name
)
3684 reset_config_on_routers(tgen
)
3686 for addr_type
in ADDR_TYPES
:
3687 # Create Static routes
3691 {"network": NETWORK
[addr_type
], "next_hop": "Null0", "tag": 4001}
3696 result
= create_static_routes(tgen
, input_dict
)
3697 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
3701 # Api call to redistribute static routes
3710 {"redist_type": "static"},
3711 {"redist_type": "connected"},
3718 {"redist_type": "static"},
3719 {"redist_type": "connected"},
3728 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
3729 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
3737 "rmap_match_tag_1_{}".format(addr_type
): [
3738 {"action": "permit", "match": {addr_type
: {"tag": "4001"}}}
3743 result
= create_route_maps(tgen
, input_dict_3
)
3744 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
3748 # Configure neighbor for route map
3761 "name": "rmap_match_tag_1_ipv4",
3779 "name": "rmap_match_tag_1_ipv6",
3793 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
3794 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
3796 # Verifying RIB routes
3800 for addr_type
in ADDR_TYPES
:
3804 {"network": NETWORK
[addr_type
], "next_hop": "Null0", "tag": 4001}
3808 result
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
3809 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
3813 write_test_footer(tc_name
)
3815 # Uncomment next line for debugging
3816 # tgen.mininet_cli()
3819 def test_create_rmap_to_match_tag_deny_outbound_prefixes_p0():
3822 Create route map to deny outbound prefixes with filter match tag,
3825 tgen
= get_topogen()
3826 global bgp_convergence
3828 if bgp_convergence
is not True:
3829 pytest
.skip("skipped because of BGP Convergence failure")
3832 tc_name
= inspect
.stack()[0][3]
3833 write_test_header(tc_name
)
3834 reset_config_on_routers(tgen
)
3836 for addr_type
in ADDR_TYPES
:
3837 # Create Static routes
3841 {"network": NETWORK
[addr_type
], "next_hop": "Null0", "tag": 4001}
3846 result
= create_static_routes(tgen
, input_dict
)
3847 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
3851 # Api call to redistribute static routes
3860 {"redist_type": "static"},
3861 {"redist_type": "connected"},
3868 {"redist_type": "static"},
3869 {"redist_type": "connected"},
3878 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
3879 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
3887 "rmap_match_tag_1_{}".format(addr_type
): [
3888 {"action": "deny", "match": {addr_type
: {"tag": "4001"}}}
3893 result
= create_route_maps(tgen
, input_dict_3
)
3894 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
3898 # Configure neighbor for route map
3911 "name": "rmap_match_tag_1_ipv4",
3929 "name": "rmap_match_tag_1_ipv6",
3943 result
= create_router_bgp(tgen
, topo
, input_dict_4
)
3944 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
3946 # Verifying RIB routes
3950 for addr_type
in ADDR_TYPES
:
3954 {"network": NETWORK
[addr_type
], "next_hop": "Null0", "tag": 4001}
3958 result
= verify_rib(
3959 tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
, expected
=False
3961 assert result
is not True, "Testcase {} : Failed \n"
3962 "routes are denied \n Error: {}".format(tc_name
, result
)
3963 logger
.info("Expected behaviour: {}".format(result
))
3965 write_test_footer(tc_name
)
3967 # Uncomment next line for debugging
3968 # tgen.mininet_cli()
3971 if __name__
== "__main__":
3972 args
= ["-s"] + sys
.argv
[1:]
3973 sys
.exit(pytest
.main(args
))