]>
Commit | Line | Data |
---|---|---|
85d47773 AP |
1 | #!/usr/bin/env python |
2 | ||
3 | # | |
4 | # Copyright (c) 2019 by VMware, Inc. ("VMware") | |
5 | # Used Copyright (c) 2018 by Network Device Education Foundation, | |
787e7624 | 6 | # Inc. ("NetDEF") in this file. |
85d47773 AP |
7 | # |
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 | |
11 | # in all copies. | |
12 | # | |
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 | |
20 | # OF THIS SOFTWARE. | |
21 | # | |
22 | ||
23 | """ | |
24 | test_bgp_large_community_topo_1.py: Test BGP large community. | |
25 | ||
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 | |
31 | as well as REG_EX. | |
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 | |
36 | is removed. | |
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 | |
55 | in the L-comm list. | |
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 | |
59 | statements. | |
60 | """ | |
61 | ||
62 | import os | |
63 | import sys | |
64 | import json | |
65 | import pytest | |
66 | import time | |
3dfd384e | 67 | |
85d47773 AP |
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/")) | |
72 | ||
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 | |
3dfd384e | 78 | |
85d47773 | 79 | from lib.common_config import ( |
787e7624 | 80 | start_topology, |
81 | write_test_header, | |
82 | write_test_footer, | |
83 | reset_config_on_routers, | |
84 | create_route_maps, | |
85 | create_bgp_community_lists, | |
86 | create_prefix_lists, | |
87 | verify_bgp_community, | |
88 | step, | |
89 | verify_create_community_list, | |
90 | delete_route_maps, | |
91 | verify_route_maps, | |
92 | create_static_routes, | |
93 | check_address_types, | |
701a0192 | 94 | required_linux_kernel_version, |
85d47773 AP |
95 | ) |
96 | from lib.topolog import logger | |
787e7624 | 97 | from lib.bgp import verify_bgp_convergence, create_router_bgp, clear_bgp_and_verify |
85d47773 AP |
98 | from lib.topojson import build_topo_from_json, build_config_from_json |
99 | ||
100 | # Reading the data from JSON File for topology and configuration creation | |
101 | jsonFile = "{}/bgp_large_community_topo_2.json".format(CWD) | |
102 | ||
103 | try: | |
104 | with open(jsonFile, "r") as topoJson: | |
105 | topo = json.load(topoJson) | |
106 | except IOError: | |
107 | assert False, "Could not read file {}".format(jsonFile) | |
108 | ||
109 | # Global variables | |
110 | bgp_convergence = False | |
111 | ||
112 | NETWORKS = {"ipv4": ["200.50.2.0/32"], "ipv6": ["1::1/128"]} | |
113 | ||
114 | ||
115 | class GenerateTopo(Topo): | |
116 | """ | |
117 | Test topology builder | |
118 | ||
119 | * `Topo`: Topology object | |
120 | """ | |
121 | ||
122 | def build(self, *_args, **_opts): | |
123 | "Build function" | |
124 | tgen = get_topogen(self) | |
125 | ||
126 | # Building topology from json file | |
127 | build_topo_from_json(tgen, topo) | |
128 | ||
787e7624 | 129 | |
85d47773 AP |
130 | def setup_module(mod): |
131 | """ | |
132 | Sets up the pytest environment | |
133 | ||
134 | * `mod`: module name | |
135 | """ | |
136 | ||
3dfd384e | 137 | # Required linux kernel version for this suite to run. |
701a0192 | 138 | result = required_linux_kernel_version("4.15") |
955212d9 | 139 | if result is not True: |
140 | pytest.skip("Kernel requirements are not met") | |
3dfd384e | 141 | |
85d47773 AP |
142 | testsuite_run_time = time.asctime(time.localtime(time.time())) |
143 | logger.info("Testsuite start time: {}".format(testsuite_run_time)) | |
787e7624 | 144 | logger.info("=" * 40) |
85d47773 AP |
145 | |
146 | logger.info("Running setup_module to create topology") | |
147 | ||
148 | # This function initiates the topology build with Topogen... | |
149 | tgen = Topogen(GenerateTopo, mod.__name__) | |
150 | # ... and here it calls Mininet initialization functions. | |
151 | ||
152 | # Starting topology, create tmp files which are loaded to routers | |
153 | # to start deamons and then start routers | |
154 | start_topology(tgen) | |
155 | ||
156 | # Creating configuration from JSON | |
157 | build_config_from_json(tgen, topo) | |
158 | ||
159 | # Checking BGP convergence | |
160 | global bgp_convergence, ADDR_TYPES | |
161 | ||
162 | # Don"t run this test if we have any failure. | |
163 | if tgen.routers_have_failure(): | |
164 | pytest.skip(tgen.errors) | |
165 | ||
166 | # Api call verify whether BGP is converged | |
167 | # Ipv4 | |
168 | bgp_convergence = verify_bgp_convergence(tgen, topo) | |
787e7624 | 169 | assert bgp_convergence is True, "setup_module :Failed \n Error:" " {}".format( |
170 | bgp_convergence | |
171 | ) | |
85d47773 AP |
172 | ADDR_TYPES = check_address_types() |
173 | ||
174 | logger.info("Running setup_module() done") | |
175 | ||
176 | ||
177 | def teardown_module(mod): | |
178 | """ | |
179 | Teardown the pytest environment | |
180 | ||
181 | * `mod`: module name | |
182 | """ | |
183 | ||
184 | logger.info("Running teardown_module to delete topology") | |
185 | ||
186 | tgen = get_topogen() | |
187 | ||
188 | # Stop toplogy and Remove tmp files | |
189 | tgen.stop_topology() | |
190 | ||
787e7624 | 191 | logger.info( |
192 | "Testsuite end time: {}".format(time.asctime(time.localtime(time.time()))) | |
193 | ) | |
194 | logger.info("=" * 40) | |
195 | ||
85d47773 AP |
196 | |
197 | ##################################################### | |
198 | # | |
199 | # Testcases | |
200 | # | |
201 | ##################################################### | |
202 | ||
203 | ||
204 | def test_create_bgp_standard_large_community_list(request): | |
205 | """ | |
206 | Create standard large-community-list and verify it can permit | |
207 | or deny large community attribute only in the correct canonical | |
208 | format. | |
209 | """ | |
210 | ||
211 | tgen = get_topogen() | |
212 | tc_name = request.node.name | |
213 | write_test_header(tc_name) | |
214 | ||
215 | # Don"t run this test if we have any failure. | |
216 | if tgen.routers_have_failure(): | |
217 | pytest.skip(tgen.errors) | |
218 | ||
219 | reset_config_on_routers(tgen) | |
220 | ||
221 | step("Create srtandard large community list") | |
222 | input_dict = { | |
223 | "r4": { | |
224 | "bgp_community_lists": [ | |
225 | { | |
226 | "community_type": "standard", | |
227 | "action": "permit", | |
228 | "name": "LC_1_STD", | |
229 | "value": "2:1:1 2:1:2 1:2:3", | |
787e7624 | 230 | "large": True, |
85d47773 AP |
231 | }, |
232 | { | |
233 | "community_type": "standard", | |
234 | "action": "permit", | |
235 | "name": "LC_2_STD", | |
236 | "value": "3:1:1 3:1:2", | |
787e7624 | 237 | "large": True, |
238 | }, | |
85d47773 AP |
239 | ] |
240 | } | |
241 | } | |
242 | result = create_bgp_community_lists(tgen, input_dict) | |
787e7624 | 243 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
244 | |
245 | step("Verify BGP large community is created") | |
246 | result = verify_create_community_list(tgen, input_dict) | |
787e7624 | 247 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
248 | |
249 | step("Create srtandard large community list with in-correct values") | |
250 | input_dict = { | |
251 | "r4": { | |
252 | "bgp_community_lists": [ | |
253 | { | |
254 | "community_type": "standard", | |
255 | "action": "permit", | |
256 | "name": "LC_1_STD_ERR", | |
257 | "value": "0:0:0", | |
787e7624 | 258 | "large": True, |
85d47773 AP |
259 | } |
260 | ] | |
261 | } | |
262 | } | |
263 | result = create_bgp_community_lists(tgen, input_dict) | |
787e7624 | 264 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
265 | |
266 | ## TODO should fail | |
267 | step("Verify BGP large community is created") | |
268 | result = verify_create_community_list(tgen, input_dict) | |
787e7624 | 269 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
270 | |
271 | write_test_footer(tc_name) | |
272 | ||
273 | ||
274 | def test_create_bgp_expanded_large_community_list(request): | |
275 | """ | |
276 | Create expanded large-community-list and verify it can permit | |
277 | or deny large community attribute both in the correct canonical | |
278 | format as well as REG_EX | |
279 | """ | |
280 | ||
281 | tgen = get_topogen() | |
282 | tc_name = request.node.name | |
283 | write_test_header(tc_name) | |
284 | ||
285 | # Don"t run this test if we have any failure. | |
286 | if tgen.routers_have_failure(): | |
287 | pytest.skip(tgen.errors) | |
288 | ||
289 | # Creating configuration from JSON | |
290 | reset_config_on_routers(tgen) | |
291 | ||
292 | step("Create expanded large community list") | |
293 | input_dict = { | |
294 | "r4": { | |
295 | "bgp_community_lists": [ | |
296 | { | |
297 | "community_type": "expanded", | |
298 | "action": "permit", | |
299 | "name": "LC_1_EXP", | |
300 | "value": "1:1:200 1:2:* 3:2:1", | |
787e7624 | 301 | "large": True, |
85d47773 AP |
302 | } |
303 | ] | |
304 | } | |
305 | } | |
306 | result = create_bgp_community_lists(tgen, input_dict) | |
787e7624 | 307 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
308 | |
309 | step("Verify BGP large community is created") | |
310 | result = verify_create_community_list(tgen, input_dict) | |
787e7624 | 311 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
312 | |
313 | write_test_footer(tc_name) | |
314 | ||
315 | ||
316 | def test_modify_large_community_lists_referenced_by_rmap(request): | |
317 | """ | |
318 | This test is to verify that we can modify a large-community-list | |
319 | is in use, add/remove attribute value and it takes immediate effect. | |
320 | """ | |
321 | ||
322 | tgen = get_topogen() | |
323 | tc_name = request.node.name | |
324 | write_test_header(tc_name) | |
325 | ||
326 | # Don"t run this test if we have any failure. | |
327 | if tgen.routers_have_failure(): | |
328 | pytest.skip(tgen.errors) | |
329 | ||
330 | # Creating configuration from JSON | |
331 | reset_config_on_routers(tgen) | |
332 | ||
333 | step("Create standard large community list") | |
334 | input_dict_1 = { | |
335 | "r4": { | |
336 | "bgp_community_lists": [ | |
337 | { | |
338 | "community_type": "standard", | |
339 | "action": "permit", | |
340 | "name": "LC_DEL", | |
341 | "value": "1:2:1 1:3:1 2:1:1 2:2:2 3:3:3", | |
787e7624 | 342 | "large": True, |
85d47773 AP |
343 | } |
344 | ] | |
345 | } | |
346 | } | |
347 | result = create_bgp_community_lists(tgen, input_dict_1) | |
787e7624 | 348 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
349 | |
350 | step("Create route map") | |
351 | input_dict_2 = { | |
352 | "r1": { | |
353 | "route_maps": { | |
354 | "RM_R2_OUT": [ | |
355 | { | |
356 | "action": "permit", | |
357 | "seq_id": "10", | |
358 | "set": { | |
359 | "large_community": { | |
360 | "num": "1:2:1 1:3:1 2:10:1 3:3:3 4:4:4 5:5:5", | |
787e7624 | 361 | "action": "additive", |
85d47773 | 362 | } |
787e7624 | 363 | }, |
85d47773 AP |
364 | } |
365 | ] | |
366 | } | |
367 | }, | |
368 | "r4": { | |
369 | "route_maps": { | |
370 | "RM_R4_IN": [ | |
371 | { | |
372 | "action": "permit", | |
373 | "seq_id": "10", | |
787e7624 | 374 | "set": {"large_comm_list": {"id": "LC_DEL", "delete": True}}, |
85d47773 AP |
375 | } |
376 | ] | |
377 | } | |
787e7624 | 378 | }, |
85d47773 AP |
379 | } |
380 | result = create_route_maps(tgen, input_dict_2) | |
787e7624 | 381 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
382 | |
383 | step("Configure neighbor for route map and advertise networks") | |
384 | input_dict_3 = { | |
385 | "r1": { | |
386 | "bgp": { | |
387 | "address_family": { | |
388 | "ipv4": { | |
389 | "unicast": { | |
787e7624 | 390 | "advertise_networks": [{"network": "200.50.2.0/32"}], |
85d47773 AP |
391 | "neighbor": { |
392 | "r2": { | |
393 | "dest_link": { | |
394 | "r1": { | |
787e7624 | 395 | "route_maps": [ |
396 | { | |
397 | "name": "RM_R2_OUT", | |
398 | "direction": "out", | |
399 | } | |
400 | ] | |
85d47773 AP |
401 | } |
402 | } | |
403 | } | |
787e7624 | 404 | }, |
85d47773 AP |
405 | } |
406 | }, | |
407 | "ipv6": { | |
408 | "unicast": { | |
787e7624 | 409 | "advertise_networks": [{"network": "1::1/128"}], |
85d47773 AP |
410 | "neighbor": { |
411 | "r2": { | |
412 | "dest_link": { | |
413 | "r1": { | |
787e7624 | 414 | "route_maps": [ |
415 | { | |
416 | "name": "RM_R2_OUT", | |
417 | "direction": "out", | |
418 | } | |
419 | ] | |
85d47773 AP |
420 | } |
421 | } | |
422 | } | |
787e7624 | 423 | }, |
85d47773 | 424 | } |
787e7624 | 425 | }, |
85d47773 AP |
426 | } |
427 | } | |
428 | }, | |
429 | "r4": { | |
430 | "bgp": { | |
431 | "address_family": { | |
432 | "ipv4": { | |
433 | "unicast": { | |
434 | "neighbor": { | |
435 | "r2": { | |
436 | "dest_link": { | |
437 | "r4": { | |
787e7624 | 438 | "route_maps": [ |
439 | {"name": "RM_R4_IN", "direction": "in"} | |
440 | ] | |
85d47773 AP |
441 | } |
442 | } | |
443 | } | |
444 | } | |
445 | } | |
446 | }, | |
447 | "ipv6": { | |
448 | "unicast": { | |
449 | "neighbor": { | |
450 | "r2": { | |
451 | "dest_link": { | |
452 | "r4": { | |
787e7624 | 453 | "route_maps": [ |
454 | {"name": "RM_R4_IN", "direction": "in"} | |
455 | ] | |
85d47773 AP |
456 | } |
457 | } | |
458 | } | |
459 | } | |
460 | } | |
787e7624 | 461 | }, |
85d47773 AP |
462 | } |
463 | } | |
787e7624 | 464 | }, |
85d47773 AP |
465 | } |
466 | result = create_router_bgp(tgen, topo, input_dict_3) | |
787e7624 | 467 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
468 | |
469 | step("Verify Community-list") | |
470 | dut = "r4" | |
787e7624 | 471 | input_dict_4 = {"largeCommunity": "2:10:1 4:4:4 5:5:5"} |
85d47773 AP |
472 | |
473 | for adt in ADDR_TYPES: | |
787e7624 | 474 | result = verify_bgp_community(tgen, adt, dut, NETWORKS[adt], input_dict_4) |
85d47773 | 475 | assert result is True, "Testcase {} : Failed \n Error: {}".format( |
787e7624 | 476 | tc_name, result |
477 | ) | |
85d47773 AP |
478 | |
479 | write_test_footer(tc_name) | |
480 | ||
481 | ||
482 | def test_large_community_lists_with_rmap_apply_and_remove(request): | |
483 | """ | |
484 | This test is to verify that large community attribute gets advertised when | |
485 | route-map is applied to a neighbor and cleared when route-map is removed | |
486 | """ | |
487 | ||
488 | tgen = get_topogen() | |
489 | tc_name = request.node.name | |
490 | write_test_header(tc_name) | |
491 | ||
492 | # Don"t run this test if we have any failure. | |
493 | if tgen.routers_have_failure(): | |
494 | pytest.skip(tgen.errors) | |
495 | ||
496 | # Creating configuration from JSON | |
497 | reset_config_on_routers(tgen) | |
498 | ||
499 | step("Create route map") | |
500 | input_dict_1 = { | |
501 | "r4": { | |
502 | "route_maps": { | |
503 | "RM_LC1": [ | |
504 | { | |
505 | "action": "permit", | |
506 | "seq_id": "10", | |
507 | "set": { | |
508 | "large_community": { | |
509 | "num": "200:200:1 200:200:10 200:200:20000", | |
787e7624 | 510 | "action": "additive", |
85d47773 | 511 | } |
787e7624 | 512 | }, |
85d47773 AP |
513 | } |
514 | ] | |
515 | } | |
516 | } | |
517 | } | |
518 | result = create_route_maps(tgen, input_dict_1) | |
787e7624 | 519 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
520 | |
521 | step("Configure neighbor for route map and advertise networks") | |
522 | input_dict_2 = { | |
523 | "r1": { | |
524 | "bgp": { | |
525 | "address_family": { | |
526 | "ipv4": { | |
527 | "unicast": { | |
787e7624 | 528 | "advertise_networks": [{"network": "200.50.2.0/32"}] |
85d47773 AP |
529 | } |
530 | }, | |
531 | "ipv6": { | |
787e7624 | 532 | "unicast": {"advertise_networks": [{"network": "1::1/128"}]} |
533 | }, | |
85d47773 AP |
534 | } |
535 | } | |
536 | }, | |
537 | "r4": { | |
538 | "bgp": { | |
539 | "address_family": { | |
540 | "ipv4": { | |
541 | "unicast": { | |
542 | "neighbor": { | |
543 | "r6": { | |
544 | "dest_link": { | |
545 | "r4": { | |
787e7624 | 546 | "route_maps": [ |
547 | {"name": "RM_LC1", "direction": "out"} | |
548 | ] | |
85d47773 AP |
549 | } |
550 | } | |
551 | } | |
552 | } | |
553 | } | |
554 | }, | |
555 | "ipv6": { | |
556 | "unicast": { | |
557 | "neighbor": { | |
558 | "r6": { | |
559 | "dest_link": { | |
560 | "r4": { | |
787e7624 | 561 | "route_maps": [ |
562 | {"name": "RM_LC1", "direction": "out"} | |
563 | ] | |
85d47773 AP |
564 | } |
565 | } | |
566 | } | |
567 | } | |
568 | } | |
787e7624 | 569 | }, |
85d47773 AP |
570 | } |
571 | } | |
787e7624 | 572 | }, |
85d47773 AP |
573 | } |
574 | result = create_router_bgp(tgen, topo, input_dict_2) | |
787e7624 | 575 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
576 | |
577 | step("Verify large-community-list") | |
578 | dut = "r6" | |
787e7624 | 579 | input_dict_4 = {"largeCommunity": "200:200:1 200:200:10 200:200:20000"} |
85d47773 AP |
580 | |
581 | for adt in ADDR_TYPES: | |
787e7624 | 582 | result = verify_bgp_community(tgen, adt, dut, NETWORKS[adt], input_dict_4) |
85d47773 | 583 | assert result is True, "Testcase {} : Failed \n Error: {}".format( |
787e7624 | 584 | tc_name, result |
585 | ) | |
85d47773 AP |
586 | |
587 | step("Delete route map reference by community-list") | |
787e7624 | 588 | input_dict_3 = {"r4": {"route_maps": ["RM_LC1"]}} |
85d47773 | 589 | result = delete_route_maps(tgen, input_dict_3) |
787e7624 | 590 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
591 | |
592 | step("Verify route map is deleted") | |
593 | result = verify_route_maps(tgen, input_dict_3) | |
787e7624 | 594 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
595 | |
596 | step("Verify large-community-list") | |
597 | for adt in ADDR_TYPES: | |
787e7624 | 598 | result = verify_bgp_community( |
599 | tgen, adt, dut, NETWORKS[adt], input_dict_4, expected=False | |
600 | ) | |
85d47773 | 601 | assert result is not True, "Testcase {} : Failed \n Error: {}".format( |
787e7624 | 602 | tc_name, result |
603 | ) | |
85d47773 AP |
604 | |
605 | write_test_footer(tc_name) | |
606 | ||
607 | ||
608 | def test_duplicate_large_community_list_attributes_not_transitive(request): | |
609 | """ | |
610 | This test is to verify that duplicate BGP Large Community values | |
611 | are NOT be transmitted. | |
612 | """ | |
613 | ||
614 | tgen = get_topogen() | |
615 | tc_name = request.node.name | |
616 | write_test_header(tc_name) | |
617 | ||
618 | # Don"t run this test if we have any failure. | |
619 | if tgen.routers_have_failure(): | |
620 | pytest.skip(tgen.errors) | |
621 | ||
622 | # Creating configuration from JSON | |
623 | reset_config_on_routers(tgen) | |
624 | ||
625 | step("Create route map") | |
626 | input_dict_1 = { | |
627 | "r4": { | |
628 | "route_maps": { | |
629 | "RM_R4_IN": [ | |
630 | { | |
631 | "action": "permit", | |
632 | "seq_id": "10", | |
633 | "set": { | |
634 | "large_community": { | |
635 | "num": "0:0:1 0:0:10 0:0:100 2:0:1 2:0:2 2:0:3" | |
787e7624 | 636 | " 2:0:4 2:0:5", |
637 | "action": "additive", | |
85d47773 | 638 | } |
787e7624 | 639 | }, |
85d47773 AP |
640 | } |
641 | ], | |
642 | "RM_R4_OUT": [ | |
643 | { | |
644 | "action": "permit", | |
645 | "seq_id": "10", | |
646 | "set": { | |
647 | "large_community": { | |
648 | "num": "0:0:1 0:0:10 0:0:10000 2:0:1 2:0:2", | |
787e7624 | 649 | "action": "additive", |
85d47773 | 650 | } |
787e7624 | 651 | }, |
85d47773 | 652 | } |
787e7624 | 653 | ], |
85d47773 AP |
654 | } |
655 | } | |
656 | } | |
657 | result = create_route_maps(tgen, input_dict_1) | |
787e7624 | 658 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
659 | |
660 | step("Configure neighbor for route map and advertise networks") | |
661 | input_dict_2 = { | |
662 | "r1": { | |
663 | "bgp": { | |
664 | "address_family": { | |
665 | "ipv4": { | |
666 | "unicast": { | |
787e7624 | 667 | "advertise_networks": [{"network": "200.50.2.0/32"}] |
85d47773 AP |
668 | } |
669 | }, | |
670 | "ipv6": { | |
787e7624 | 671 | "unicast": {"advertise_networks": [{"network": "1::1/128"}]} |
672 | }, | |
85d47773 AP |
673 | } |
674 | } | |
675 | }, | |
676 | "r4": { | |
677 | "bgp": { | |
678 | "address_family": { | |
679 | "ipv4": { | |
680 | "unicast": { | |
681 | "neighbor": { | |
682 | "r2": { | |
683 | "dest_link": { | |
684 | "r4": { | |
787e7624 | 685 | "route_maps": [ |
686 | {"name": "RM_R4_IN", "direction": "in"} | |
687 | ] | |
85d47773 AP |
688 | } |
689 | } | |
690 | }, | |
691 | "r6": { | |
692 | "dest_link": { | |
693 | "r4": { | |
787e7624 | 694 | "route_maps": [ |
695 | { | |
696 | "name": "RM_R4_OUT", | |
697 | "direction": "out", | |
698 | } | |
699 | ] | |
85d47773 AP |
700 | } |
701 | } | |
787e7624 | 702 | }, |
85d47773 AP |
703 | } |
704 | } | |
705 | }, | |
706 | "ipv6": { | |
707 | "unicast": { | |
708 | "neighbor": { | |
709 | "r2": { | |
710 | "dest_link": { | |
711 | "r4": { | |
787e7624 | 712 | "route_maps": [ |
713 | {"name": "RM_R4_IN", "direction": "in"} | |
714 | ] | |
85d47773 AP |
715 | } |
716 | } | |
717 | }, | |
718 | "r6": { | |
719 | "dest_link": { | |
720 | "r4": { | |
787e7624 | 721 | "route_maps": [ |
722 | { | |
723 | "name": "RM_R4_OUT", | |
724 | "direction": "out", | |
725 | } | |
726 | ] | |
85d47773 AP |
727 | } |
728 | } | |
787e7624 | 729 | }, |
85d47773 AP |
730 | } |
731 | } | |
787e7624 | 732 | }, |
85d47773 AP |
733 | } |
734 | } | |
787e7624 | 735 | }, |
85d47773 AP |
736 | } |
737 | result = create_router_bgp(tgen, topo, input_dict_2) | |
787e7624 | 738 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
739 | |
740 | step("Verify large-community-list") | |
741 | dut = "r6" | |
742 | input_dict_4 = { | |
787e7624 | 743 | "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" |
85d47773 AP |
744 | } |
745 | for adt in ADDR_TYPES: | |
787e7624 | 746 | result = verify_bgp_community(tgen, adt, dut, NETWORKS[adt], input_dict_4) |
85d47773 | 747 | assert result is True, "Testcase {} : Failed \n Error: {}".format( |
787e7624 | 748 | tc_name, result |
749 | ) | |
85d47773 AP |
750 | |
751 | write_test_footer(tc_name) | |
752 | ||
753 | ||
754 | def test_large_community_lists_with_rmap_set_none(request): | |
755 | """ | |
756 | This test is to verify if we want to remove all the large-community | |
757 | attributes from a set of prefix we can set the value as NONE. | |
758 | """ | |
759 | ||
760 | tgen = get_topogen() | |
761 | tc_name = request.node.name | |
762 | write_test_header(tc_name) | |
763 | ||
764 | # Don"t run this test if we have any failure. | |
765 | if tgen.routers_have_failure(): | |
766 | pytest.skip(tgen.errors) | |
767 | ||
768 | # Creating configuration from JSON | |
769 | reset_config_on_routers(tgen) | |
770 | ||
771 | step("Create route map") | |
772 | input_dict_1 = { | |
773 | "r4": { | |
774 | "route_maps": { | |
775 | "RM_R4_IN": [ | |
776 | { | |
777 | "action": "permit", | |
778 | "seq_id": "10", | |
779 | "set": { | |
780 | "large_community": { | |
781 | "num": "0:0:1 0:0:10 0:0:100 2:0:1 2:0:2 2:0:3" | |
787e7624 | 782 | " 2:0:4", |
783 | "action": "additive", | |
85d47773 | 784 | } |
787e7624 | 785 | }, |
85d47773 AP |
786 | } |
787 | ] | |
788 | } | |
789 | }, | |
790 | "r6": { | |
791 | "route_maps": { | |
792 | "RM_R6_IN": [ | |
793 | { | |
794 | "action": "permit", | |
795 | "seq_id": "10", | |
787e7624 | 796 | "set": {"large_community": {"num": "none"}}, |
85d47773 AP |
797 | } |
798 | ] | |
799 | } | |
787e7624 | 800 | }, |
85d47773 AP |
801 | } |
802 | result = create_route_maps(tgen, input_dict_1) | |
787e7624 | 803 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
804 | |
805 | step("Configure neighbor for route map") | |
806 | input_dict_2 = { | |
807 | "r1": { | |
808 | "bgp": { | |
809 | "address_family": { | |
810 | "ipv4": { | |
811 | "unicast": { | |
787e7624 | 812 | "advertise_networks": [{"network": "200.50.2.0/32"}] |
85d47773 AP |
813 | } |
814 | }, | |
815 | "ipv6": { | |
787e7624 | 816 | "unicast": {"advertise_networks": [{"network": "1::1/128"}]} |
817 | }, | |
85d47773 AP |
818 | } |
819 | } | |
820 | }, | |
821 | "r4": { | |
822 | "bgp": { | |
823 | "address_family": { | |
824 | "ipv4": { | |
825 | "unicast": { | |
826 | "neighbor": { | |
827 | "r2": { | |
828 | "dest_link": { | |
829 | "r4": { | |
787e7624 | 830 | "route_maps": [ |
831 | {"name": "RM_R4_IN", "direction": "in"} | |
832 | ] | |
85d47773 AP |
833 | } |
834 | } | |
835 | } | |
836 | } | |
837 | } | |
838 | }, | |
839 | "ipv6": { | |
840 | "unicast": { | |
841 | "neighbor": { | |
842 | "r2": { | |
843 | "dest_link": { | |
844 | "r4": { | |
787e7624 | 845 | "route_maps": [ |
846 | {"name": "RM_R4_IN", "direction": "in"} | |
847 | ] | |
85d47773 AP |
848 | } |
849 | } | |
850 | } | |
851 | } | |
852 | } | |
787e7624 | 853 | }, |
85d47773 AP |
854 | } |
855 | } | |
856 | }, | |
857 | "r6": { | |
858 | "bgp": { | |
859 | "address_family": { | |
860 | "ipv4": { | |
861 | "unicast": { | |
862 | "neighbor": { | |
863 | "r4": { | |
864 | "dest_link": { | |
865 | "r6": { | |
787e7624 | 866 | "route_maps": [ |
867 | {"name": "RM_R6_IN", "direction": "in"} | |
868 | ] | |
85d47773 AP |
869 | } |
870 | } | |
871 | } | |
872 | } | |
873 | } | |
874 | }, | |
875 | "ipv6": { | |
876 | "unicast": { | |
877 | "neighbor": { | |
878 | "r4": { | |
879 | "dest_link": { | |
880 | "r6": { | |
787e7624 | 881 | "route_maps": [ |
882 | {"name": "RM_R6_IN", "direction": "in"} | |
883 | ] | |
85d47773 AP |
884 | } |
885 | } | |
886 | } | |
887 | } | |
888 | } | |
787e7624 | 889 | }, |
85d47773 AP |
890 | } |
891 | } | |
787e7624 | 892 | }, |
85d47773 AP |
893 | } |
894 | result = create_router_bgp(tgen, topo, input_dict_2) | |
787e7624 | 895 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
896 | |
897 | step("Verify Community-list") | |
898 | dut = "r6" | |
899 | for adt in ADDR_TYPES: | |
787e7624 | 900 | result = verify_bgp_community(tgen, adt, dut, NETWORKS[adt], expected=False) |
85d47773 | 901 | assert result is not True, "Testcase {} : Failed \n Error: {}".format( |
787e7624 | 902 | tc_name, result |
903 | ) | |
85d47773 AP |
904 | |
905 | write_test_footer(tc_name) | |
906 | ||
907 | ||
908 | def test_lcomm_lists_with_redistribute_static_connected_rmap(request): | |
909 | """ | |
910 | This test is to verify redistribute connected and static ipv4 routes | |
911 | in BGP process with a route-map appending/removing L-comm attributes. | |
912 | """ | |
913 | ||
914 | tgen = get_topogen() | |
915 | tc_name = request.node.name | |
916 | write_test_header(tc_name) | |
917 | ||
918 | # Don"t run this test if we have any failure. | |
919 | if tgen.routers_have_failure(): | |
920 | pytest.skip(tgen.errors) | |
921 | ||
922 | # Creating configuration from JSON | |
923 | reset_config_on_routers(tgen) | |
924 | ||
925 | step("create static routes") | |
926 | input_dict = { | |
927 | "r1": { | |
928 | "static_routes": [ | |
787e7624 | 929 | {"network": "200.50.2.0/32", "next_hop": "10.0.0.6"}, |
930 | {"network": "1::1/128", "next_hop": "fd00:0:0:1::2"}, | |
85d47773 AP |
931 | ] |
932 | } | |
933 | } | |
934 | result = create_static_routes(tgen, input_dict) | |
787e7624 | 935 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
936 | |
937 | step("redistribute static routes") | |
938 | input_dict_1 = { | |
787e7624 | 939 | "r1": { |
85d47773 AP |
940 | "bgp": { |
941 | "address_family": { | |
942 | "ipv4": { | |
943 | "unicast": { | |
944 | "redistribute": [ | |
945 | { | |
946 | "redist_type": "static", | |
787e7624 | 947 | "attribute": "route-map RM_R2_OUT", |
85d47773 AP |
948 | }, |
949 | { | |
950 | "redist_type": "connected", | |
787e7624 | 951 | "attribute": "route-map RM_R2_OUT", |
952 | }, | |
85d47773 AP |
953 | ] |
954 | } | |
955 | }, | |
956 | "ipv6": { | |
957 | "unicast": { | |
958 | "redistribute": [ | |
959 | { | |
960 | "redist_type": "static", | |
787e7624 | 961 | "attribute": "route-map RM_R2_OUT", |
85d47773 AP |
962 | }, |
963 | { | |
964 | "redist_type": "connected", | |
787e7624 | 965 | "attribute": "route-map RM_R2_OUT", |
966 | }, | |
85d47773 AP |
967 | ] |
968 | } | |
787e7624 | 969 | }, |
85d47773 AP |
970 | } |
971 | } | |
972 | } | |
973 | } | |
974 | result = create_router_bgp(tgen, topo, input_dict_1) | |
787e7624 | 975 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
976 | |
977 | step("Create route map") | |
978 | input_dict_3 = { | |
979 | "r1": { | |
980 | "route_maps": { | |
787e7624 | 981 | "RM_R2_OUT": [ |
982 | { | |
983 | "action": "permit", | |
984 | "set": {"large_community": {"num": "55:55:55 555:555:555"}}, | |
985 | } | |
986 | ] | |
85d47773 | 987 | } |
787e7624 | 988 | } |
85d47773 AP |
989 | } |
990 | result = create_route_maps(tgen, input_dict_3) | |
787e7624 | 991 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 | 992 | |
787e7624 | 993 | step("Verify large-community-list for static and connected ipv4 route on" " r2") |
85d47773 | 994 | |
787e7624 | 995 | input_dict_5 = {"largeCommunity": "55:55:55 555:555:555"} |
85d47773 AP |
996 | |
997 | if "ipv4" in ADDR_TYPES: | |
998 | dut = "r2" | |
999 | networks = ["200.50.2.0/32", "1.0.1.17/32"] | |
787e7624 | 1000 | result = verify_bgp_community(tgen, "ipv4", dut, networks, input_dict_5) |
85d47773 | 1001 | assert result is True, "Testcase {} : Failed \n Error: {}".format( |
787e7624 | 1002 | tc_name, result |
1003 | ) | |
85d47773 | 1004 | |
787e7624 | 1005 | step("Verify large-community-list for static and connected ipv4 route" " on r4") |
85d47773 AP |
1006 | dut = "r4" |
1007 | networks = ["200.50.2.0/32", "1.0.1.17/32"] | |
787e7624 | 1008 | result = verify_bgp_community(tgen, "ipv4", dut, networks, input_dict_5) |
85d47773 | 1009 | assert result is True, "Testcase {} : Failed \n Error: {}".format( |
787e7624 | 1010 | tc_name, result |
1011 | ) | |
85d47773 AP |
1012 | |
1013 | if "ipv6" in ADDR_TYPES: | |
787e7624 | 1014 | step("Verify large-community-list for static and connected ipv6 route" " on r2") |
85d47773 AP |
1015 | dut = "r2" |
1016 | networks = ["1::1/128", "2001:db8:f::1:17/128"] | |
787e7624 | 1017 | result = verify_bgp_community(tgen, "ipv6", dut, networks, input_dict_5) |
85d47773 | 1018 | assert result is True, "Testcase {} : Failed \n Error: {}".format( |
787e7624 | 1019 | tc_name, result |
1020 | ) | |
85d47773 | 1021 | |
787e7624 | 1022 | step("Verify large-community-list for static and connected ipv6 route" " on r4") |
85d47773 AP |
1023 | dut = "r4" |
1024 | networks = ["1::1/128", "2001:db8:f::1:17/128"] | |
787e7624 | 1025 | result = verify_bgp_community(tgen, "ipv6", dut, networks, input_dict_5) |
85d47773 | 1026 | assert result is True, "Testcase {} : Failed \n Error: {}".format( |
787e7624 | 1027 | tc_name, result |
1028 | ) | |
85d47773 AP |
1029 | |
1030 | write_test_footer(tc_name) | |
1031 | ||
1032 | ||
1033 | def test_large_community_lists_with_rmap_set_delete(request): | |
1034 | """ | |
1035 | This test is to verify if we want to remove specific large-community | |
1036 | values from a set of prefix we can make use of DELETE operation based | |
1037 | on L-comm list | |
1038 | """ | |
1039 | ||
1040 | tgen = get_topogen() | |
1041 | tc_name = request.node.name | |
1042 | write_test_header(tc_name) | |
1043 | ||
1044 | # Don"t run this test if we have any failure. | |
1045 | if tgen.routers_have_failure(): | |
1046 | pytest.skip(tgen.errors) | |
1047 | ||
1048 | # Creating configuration from JSON | |
1049 | reset_config_on_routers(tgen) | |
1050 | ||
1051 | step("configure route_map") | |
1052 | input_dict_2 = { | |
1053 | "r6": { | |
1054 | "bgp_community_lists": [ | |
1055 | { | |
1056 | "community_type": "standard", | |
1057 | "action": "permit", | |
1058 | "name": "Test", | |
1059 | "value": "1:2:1 1:1:10 1:3:100", | |
787e7624 | 1060 | "large": True, |
85d47773 AP |
1061 | } |
1062 | ] | |
1063 | } | |
1064 | } | |
1065 | result = create_bgp_community_lists(tgen, input_dict_2) | |
787e7624 | 1066 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
1067 | |
1068 | step("Create route map") | |
1069 | input_dict_3 = { | |
1070 | "r6": { | |
1071 | "route_maps": { | |
1072 | "RM_R6_IN": [ | |
1073 | { | |
1074 | "action": "permit", | |
1075 | "seq_id": "10", | |
787e7624 | 1076 | "set": {"large_comm_list": {"id": "Test", "delete": True}}, |
85d47773 AP |
1077 | } |
1078 | ] | |
1079 | } | |
1080 | }, | |
1081 | "r4": { | |
1082 | "route_maps": { | |
1083 | "RM_R4_IN": [ | |
1084 | { | |
1085 | "action": "permit", | |
1086 | "seq_id": "10", | |
1087 | "set": { | |
1088 | "large_community": { | |
1089 | "num": "1:2:1 1:1:10 1:3:100 2:1:1 2:2:2 2:3:3" | |
787e7624 | 1090 | " 2:4:4 2:5:5", |
1091 | "action": "additive", | |
85d47773 | 1092 | } |
787e7624 | 1093 | }, |
85d47773 AP |
1094 | } |
1095 | ] | |
1096 | } | |
787e7624 | 1097 | }, |
85d47773 AP |
1098 | } |
1099 | result = create_route_maps(tgen, input_dict_3) | |
787e7624 | 1100 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
1101 | |
1102 | step("Configure neighbor for route map and advertise networks") | |
1103 | input_dict_4 = { | |
1104 | "r1": { | |
1105 | "bgp": { | |
1106 | "address_family": { | |
1107 | "ipv4": { | |
1108 | "unicast": { | |
787e7624 | 1109 | "advertise_networks": [{"network": "200.50.2.0/32"}] |
85d47773 AP |
1110 | } |
1111 | }, | |
1112 | "ipv6": { | |
787e7624 | 1113 | "unicast": {"advertise_networks": [{"network": "1::1/128"}]} |
1114 | }, | |
85d47773 AP |
1115 | } |
1116 | } | |
1117 | }, | |
1118 | "r4": { | |
1119 | "bgp": { | |
1120 | "address_family": { | |
1121 | "ipv4": { | |
1122 | "unicast": { | |
1123 | "neighbor": { | |
1124 | "r2": { | |
1125 | "dest_link": { | |
1126 | "r4": { | |
787e7624 | 1127 | "route_maps": [ |
1128 | {"name": "RM_R4_IN", "direction": "in"} | |
1129 | ] | |
85d47773 AP |
1130 | } |
1131 | } | |
1132 | } | |
1133 | } | |
1134 | } | |
1135 | }, | |
1136 | "ipv6": { | |
1137 | "unicast": { | |
1138 | "neighbor": { | |
1139 | "r2": { | |
1140 | "dest_link": { | |
1141 | "r4": { | |
787e7624 | 1142 | "route_maps": [ |
1143 | {"name": "RM_R4_IN", "direction": "in"} | |
1144 | ] | |
85d47773 AP |
1145 | } |
1146 | } | |
1147 | } | |
1148 | } | |
1149 | } | |
787e7624 | 1150 | }, |
85d47773 AP |
1151 | } |
1152 | } | |
1153 | }, | |
1154 | "r6": { | |
1155 | "bgp": { | |
1156 | "address_family": { | |
1157 | "ipv4": { | |
1158 | "unicast": { | |
1159 | "neighbor": { | |
1160 | "r4": { | |
1161 | "dest_link": { | |
1162 | "r6": { | |
787e7624 | 1163 | "route_maps": [ |
1164 | {"name": "RM_R6_IN", "direction": "in"} | |
1165 | ] | |
85d47773 AP |
1166 | } |
1167 | } | |
1168 | } | |
1169 | } | |
1170 | } | |
1171 | }, | |
1172 | "ipv6": { | |
1173 | "unicast": { | |
1174 | "neighbor": { | |
1175 | "r4": { | |
1176 | "dest_link": { | |
1177 | "r6": { | |
787e7624 | 1178 | "route_maps": [ |
1179 | {"name": "RM_R6_IN", "direction": "in"} | |
1180 | ] | |
85d47773 AP |
1181 | } |
1182 | } | |
1183 | } | |
1184 | } | |
1185 | } | |
787e7624 | 1186 | }, |
85d47773 AP |
1187 | } |
1188 | } | |
787e7624 | 1189 | }, |
85d47773 AP |
1190 | } |
1191 | result = create_router_bgp(tgen, topo, input_dict_4) | |
787e7624 | 1192 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
1193 | |
1194 | step("Verify large-community-list") | |
1195 | dut = "r6" | |
787e7624 | 1196 | input_dict_5 = {"largeCommunity": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"} |
85d47773 | 1197 | for adt in ADDR_TYPES: |
787e7624 | 1198 | result = verify_bgp_community(tgen, adt, dut, NETWORKS[adt], input_dict_5) |
85d47773 | 1199 | assert result is True, "Testcase {} : Failed \n Error: {}".format( |
787e7624 | 1200 | tc_name, result |
1201 | ) | |
85d47773 AP |
1202 | |
1203 | write_test_footer(tc_name) | |
1204 | ||
1205 | ||
1206 | def test_large_community_lists_with_no_send_community(request): | |
1207 | """ | |
1208 | This test is to verify if we want to remove specific large-community | |
1209 | values from a set of prefix we can make use of DELETE operation based | |
1210 | on L-comm list | |
1211 | """ | |
1212 | ||
1213 | tgen = get_topogen() | |
1214 | tc_name = request.node.name | |
1215 | write_test_header(tc_name) | |
1216 | ||
1217 | # Don"t run this test if we have any failure. | |
1218 | if tgen.routers_have_failure(): | |
1219 | pytest.skip(tgen.errors) | |
1220 | ||
1221 | # Creating configuration from JSON | |
1222 | reset_config_on_routers(tgen) | |
1223 | ||
1224 | step("Create route map") | |
1225 | input_dict_2 = { | |
1226 | "r5": { | |
1227 | "route_maps": { | |
1228 | "RM_R6_OUT": [ | |
1229 | { | |
1230 | "action": "permit", | |
1231 | "seq_id": "10", | |
1232 | "set": { | |
787e7624 | 1233 | "large_community": {"num": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"} |
1234 | }, | |
85d47773 AP |
1235 | } |
1236 | ] | |
1237 | } | |
1238 | } | |
1239 | } | |
1240 | result = create_route_maps(tgen, input_dict_2) | |
787e7624 | 1241 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
1242 | |
1243 | step("Configure neighbor for route map and advertise networks") | |
1244 | input_dict_3 = { | |
1245 | "r1": { | |
1246 | "bgp": { | |
1247 | "address_family": { | |
1248 | "ipv4": { | |
1249 | "unicast": { | |
787e7624 | 1250 | "advertise_networks": [{"network": "200.50.2.0/32"}] |
85d47773 AP |
1251 | } |
1252 | }, | |
1253 | "ipv6": { | |
787e7624 | 1254 | "unicast": {"advertise_networks": [{"network": "1::1/128"}]} |
1255 | }, | |
85d47773 AP |
1256 | } |
1257 | } | |
1258 | }, | |
1259 | "r5": { | |
1260 | "bgp": { | |
1261 | "address_family": { | |
1262 | "ipv4": { | |
1263 | "unicast": { | |
1264 | "neighbor": { | |
1265 | "r6": { | |
1266 | "dest_link": { | |
1267 | "r5": { | |
787e7624 | 1268 | "route_maps": [ |
1269 | { | |
1270 | "name": "RM_R6_OUT", | |
1271 | "direction": "out", | |
1272 | } | |
1273 | ] | |
85d47773 AP |
1274 | } |
1275 | } | |
1276 | } | |
1277 | } | |
1278 | } | |
1279 | }, | |
1280 | "ipv6": { | |
1281 | "unicast": { | |
1282 | "neighbor": { | |
1283 | "r6": { | |
1284 | "dest_link": { | |
1285 | "r5": { | |
787e7624 | 1286 | "route_maps": [ |
1287 | { | |
1288 | "name": "RM_R6_OUT", | |
1289 | "direction": "out", | |
1290 | } | |
1291 | ] | |
85d47773 AP |
1292 | } |
1293 | } | |
1294 | } | |
1295 | } | |
1296 | } | |
787e7624 | 1297 | }, |
85d47773 AP |
1298 | } |
1299 | } | |
787e7624 | 1300 | }, |
85d47773 AP |
1301 | } |
1302 | result = create_router_bgp(tgen, topo, input_dict_3) | |
787e7624 | 1303 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
1304 | |
1305 | step("Verify large-community-list") | |
1306 | dut = "r6" | |
787e7624 | 1307 | input_dict_4 = {"largeCommunity": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"} |
85d47773 | 1308 | for adt in ADDR_TYPES: |
787e7624 | 1309 | result = verify_bgp_community(tgen, adt, dut, NETWORKS[adt], input_dict_4) |
85d47773 | 1310 | assert result is True, "Testcase {} : Failed \n Error: {}".format( |
787e7624 | 1311 | tc_name, result |
1312 | ) | |
85d47773 AP |
1313 | |
1314 | step("Configure neighbor for no-send-community") | |
1315 | input_dict_5 = { | |
1316 | "r5": { | |
1317 | "bgp": { | |
1318 | "address_family": { | |
1319 | "ipv4": { | |
1320 | "unicast": { | |
1321 | "neighbor": { | |
1322 | "r6": { | |
787e7624 | 1323 | "dest_link": {"r5": {"no_send_community": "large"}} |
85d47773 AP |
1324 | } |
1325 | } | |
1326 | } | |
1327 | }, | |
1328 | "ipv6": { | |
1329 | "unicast": { | |
1330 | "neighbor": { | |
1331 | "r6": { | |
787e7624 | 1332 | "dest_link": {"r5": {"no_send_community": "large"}} |
85d47773 AP |
1333 | } |
1334 | } | |
1335 | } | |
787e7624 | 1336 | }, |
85d47773 AP |
1337 | } |
1338 | } | |
1339 | } | |
1340 | } | |
1341 | result = create_router_bgp(tgen, topo, input_dict_5) | |
787e7624 | 1342 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
1343 | |
1344 | step("Verify Community-list") | |
1345 | for adt in ADDR_TYPES: | |
787e7624 | 1346 | result = verify_bgp_community( |
1347 | tgen, adt, dut, NETWORKS[adt], input_dict_4, expected=False | |
1348 | ) | |
85d47773 | 1349 | assert result is not True, "Testcase {} : Failed \n Error: {}".format( |
787e7624 | 1350 | tc_name, result |
1351 | ) | |
85d47773 AP |
1352 | |
1353 | write_test_footer(tc_name) | |
1354 | ||
1355 | ||
1356 | def test_create_large_community_lists_with_no_attribute_values(request): | |
1357 | """ | |
1358 | This test is to verify that large-community lists can not be | |
1359 | configured without providing specific L-community values | |
1360 | (for match/delete operation in a route-map). | |
1361 | """ | |
1362 | ||
1363 | tgen = get_topogen() | |
1364 | tc_name = request.node.name | |
1365 | write_test_header(tc_name) | |
1366 | ||
1367 | # Don"t run this test if we have any failure. | |
1368 | if tgen.routers_have_failure(): | |
1369 | pytest.skip(tgen.errors) | |
1370 | ||
1371 | # Creating configuration from JSON | |
1372 | reset_config_on_routers(tgen) | |
1373 | ||
1374 | step("Create standard large commumity-list") | |
1375 | input_dict_1 = { | |
1376 | "r5": { | |
1377 | "bgp_community_lists": [ | |
1378 | { | |
1379 | "community_type": "standard", | |
1380 | "action": "permit", | |
1381 | "name": "Test1", | |
787e7624 | 1382 | "large": True, |
85d47773 AP |
1383 | } |
1384 | ] | |
1385 | } | |
1386 | } | |
1387 | result = create_bgp_community_lists(tgen, input_dict_1) | |
1388 | assert result is not True, "Testcase {} : Failed \n Error: {}".format( | |
787e7624 | 1389 | tc_name, result |
1390 | ) | |
85d47773 AP |
1391 | |
1392 | write_test_footer(tc_name) | |
1393 | ||
1394 | ||
1395 | def test_large_community_lists_with_rmap_match_exact(request): | |
1396 | """ | |
1397 | This test is to verify that Match_EXACT clause should pass | |
1398 | only if all of the L-comm values configured (horizontally) | |
1399 | in the community list is present in the prefix. There must | |
1400 | be no additional L-communities in the prefix. | |
1401 | """ | |
1402 | ||
1403 | tgen = get_topogen() | |
1404 | tc_name = request.node.name | |
1405 | write_test_header(tc_name) | |
1406 | ||
1407 | # Don"t run this test if we have any failure. | |
1408 | if tgen.routers_have_failure(): | |
1409 | pytest.skip(tgen.errors) | |
1410 | ||
1411 | # Creating configuration from JSON | |
1412 | reset_config_on_routers(tgen) | |
1413 | ||
1414 | step("Create route map") | |
1415 | input_dict_2 = { | |
1416 | "r2": { | |
1417 | "route_maps": { | |
1418 | "RM_R4_OUT": [ | |
1419 | { | |
1420 | "action": "permit", | |
1421 | "seq_id": "10", | |
1422 | "set": { | |
787e7624 | 1423 | "large_community": {"num": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"} |
1424 | }, | |
85d47773 AP |
1425 | } |
1426 | ] | |
1427 | } | |
1428 | } | |
1429 | } | |
1430 | result = create_route_maps(tgen, input_dict_2) | |
787e7624 | 1431 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
1432 | |
1433 | step("Configure neighbor for route map and advertise networks") | |
1434 | input_dict_3 = { | |
1435 | "r1": { | |
1436 | "bgp": { | |
1437 | "address_family": { | |
1438 | "ipv4": { | |
1439 | "unicast": { | |
787e7624 | 1440 | "advertise_networks": [{"network": "200.50.2.0/32"}] |
85d47773 AP |
1441 | } |
1442 | }, | |
1443 | "ipv6": { | |
787e7624 | 1444 | "unicast": {"advertise_networks": [{"network": "1::1/128"}]} |
1445 | }, | |
85d47773 AP |
1446 | } |
1447 | } | |
1448 | }, | |
1449 | "r2": { | |
1450 | "bgp": { | |
1451 | "address_family": { | |
1452 | "ipv4": { | |
1453 | "unicast": { | |
1454 | "neighbor": { | |
1455 | "r4": { | |
1456 | "dest_link": { | |
1457 | "r2": { | |
787e7624 | 1458 | "route_maps": [ |
1459 | { | |
1460 | "name": "RM_R4_OUT", | |
1461 | "direction": "out", | |
1462 | } | |
1463 | ] | |
85d47773 AP |
1464 | } |
1465 | } | |
1466 | } | |
1467 | } | |
1468 | } | |
1469 | }, | |
1470 | "ipv6": { | |
1471 | "unicast": { | |
1472 | "neighbor": { | |
1473 | "r4": { | |
1474 | "dest_link": { | |
1475 | "r2": { | |
787e7624 | 1476 | "route_maps": [ |
1477 | { | |
1478 | "name": "RM_R4_OUT", | |
1479 | "direction": "out", | |
1480 | } | |
1481 | ] | |
85d47773 AP |
1482 | } |
1483 | } | |
1484 | } | |
1485 | } | |
1486 | } | |
787e7624 | 1487 | }, |
85d47773 AP |
1488 | } |
1489 | } | |
787e7624 | 1490 | }, |
85d47773 AP |
1491 | } |
1492 | ||
1493 | result = create_router_bgp(tgen, topo, input_dict_3) | |
787e7624 | 1494 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
1495 | |
1496 | step("Create standard large commumity-list") | |
1497 | input_dict_4 = { | |
1498 | "r4": { | |
1499 | "bgp_community_lists": [ | |
1500 | { | |
1501 | "community_type": "standard", | |
1502 | "action": "permit", | |
1503 | "name": "EXACT", | |
1504 | "value": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5", | |
787e7624 | 1505 | "large": True, |
85d47773 AP |
1506 | } |
1507 | ] | |
1508 | } | |
1509 | } | |
1510 | result = create_bgp_community_lists(tgen, input_dict_4) | |
787e7624 | 1511 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
1512 | |
1513 | step("Verify BGP large community is created") | |
1514 | result = verify_create_community_list(tgen, input_dict_4) | |
787e7624 | 1515 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
1516 | |
1517 | step("Create route map") | |
1518 | input_dict_5 = { | |
1519 | "r4": { | |
1520 | "route_maps": { | |
1521 | "RM_R4_IN": [ | |
1522 | { | |
1523 | "action": "permit", | |
1524 | "seq_id": "10", | |
1525 | "match": { | |
1526 | "large-community-list": ["EXACT"], | |
787e7624 | 1527 | "match_exact": True, |
1528 | }, | |
85d47773 AP |
1529 | } |
1530 | ] | |
1531 | } | |
1532 | } | |
1533 | } | |
1534 | result = create_route_maps(tgen, input_dict_5) | |
787e7624 | 1535 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
1536 | |
1537 | step("Configure neighbor for route map") | |
1538 | input_dict_6 = { | |
1539 | "r4": { | |
1540 | "bgp": { | |
1541 | "address_family": { | |
1542 | "ipv4": { | |
1543 | "unicast": { | |
1544 | "neighbor": { | |
1545 | "r2": { | |
1546 | "dest_link": { | |
1547 | "r4": { | |
787e7624 | 1548 | "route_maps": [ |
1549 | {"name": "RM_R4_IN", "direction": "in"} | |
1550 | ] | |
85d47773 AP |
1551 | } |
1552 | } | |
1553 | } | |
1554 | } | |
1555 | } | |
1556 | }, | |
1557 | "ipv6": { | |
1558 | "unicast": { | |
1559 | "neighbor": { | |
1560 | "r2": { | |
1561 | "dest_link": { | |
1562 | "r4": { | |
787e7624 | 1563 | "route_maps": [ |
1564 | {"name": "RM_R4_IN", "direction": "in"} | |
1565 | ] | |
85d47773 AP |
1566 | } |
1567 | } | |
1568 | } | |
1569 | } | |
1570 | } | |
787e7624 | 1571 | }, |
85d47773 AP |
1572 | } |
1573 | } | |
1574 | } | |
1575 | } | |
1576 | result = create_router_bgp(tgen, topo, input_dict_6) | |
787e7624 | 1577 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
1578 | |
1579 | step("Verify large-community-list") | |
1580 | dut = "r4" | |
787e7624 | 1581 | input_dict_4 = {"largeCommunity": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"} |
85d47773 | 1582 | for adt in ADDR_TYPES: |
787e7624 | 1583 | result = verify_bgp_community(tgen, adt, dut, NETWORKS[adt], input_dict_4) |
85d47773 | 1584 | assert result is True, "Testcase {} : Failed \n Error: {}".format( |
787e7624 | 1585 | tc_name, result |
1586 | ) | |
85d47773 AP |
1587 | |
1588 | write_test_footer(tc_name) | |
1589 | ||
1590 | ||
1591 | def test_large_community_lists_with_rmap_match_all(request): | |
1592 | """ | |
1593 | This test is to verify that Match_ALL clause should pass | |
1594 | only if ALL of the L-comm values configured (horizontally) | |
1595 | in the community list are present in the prefix. There | |
1596 | could be additional L-communities in the prefix that are | |
1597 | not present in the L-comm list. | |
1598 | """ | |
1599 | ||
1600 | tgen = get_topogen() | |
1601 | tc_name = request.node.name | |
1602 | write_test_header(tc_name) | |
1603 | ||
1604 | # Don"t run this test if we have any failure. | |
1605 | if tgen.routers_have_failure(): | |
1606 | pytest.skip(tgen.errors) | |
1607 | ||
1608 | # Creating configuration from JSON | |
1609 | reset_config_on_routers(tgen) | |
1610 | ||
1611 | step("Create route map") | |
1612 | input_dict_2 = { | |
1613 | "r2": { | |
1614 | "route_maps": { | |
787e7624 | 1615 | "RM_R4_OUT": [ |
1616 | { | |
1617 | "action": "permit", | |
1618 | "set": { | |
1619 | "large_community": { | |
1620 | "num": "1:1:1 1:2:3 2:1:1 2:2:2 2:3:3 2:4:4 2:5:5" | |
1621 | } | |
1622 | }, | |
85d47773 | 1623 | } |
787e7624 | 1624 | ] |
85d47773 AP |
1625 | } |
1626 | } | |
1627 | } | |
1628 | result = create_route_maps(tgen, input_dict_2) | |
787e7624 | 1629 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
1630 | |
1631 | step("Configure neighbor for route map") | |
1632 | input_dict_3 = { | |
1633 | "r1": { | |
1634 | "bgp": { | |
1635 | "address_family": { | |
1636 | "ipv4": { | |
1637 | "unicast": { | |
787e7624 | 1638 | "advertise_networks": [{"network": "200.50.2.0/32"}] |
85d47773 AP |
1639 | } |
1640 | }, | |
1641 | "ipv6": { | |
787e7624 | 1642 | "unicast": {"advertise_networks": [{"network": "1::1/128"}]} |
1643 | }, | |
85d47773 AP |
1644 | } |
1645 | } | |
1646 | }, | |
1647 | "r2": { | |
1648 | "bgp": { | |
1649 | "address_family": { | |
1650 | "ipv4": { | |
1651 | "unicast": { | |
1652 | "neighbor": { | |
1653 | "r4": { | |
1654 | "dest_link": { | |
1655 | "r2": { | |
787e7624 | 1656 | "route_maps": [ |
1657 | { | |
1658 | "name": "RM_R4_OUT", | |
1659 | "direction": "out", | |
1660 | } | |
1661 | ] | |
85d47773 AP |
1662 | } |
1663 | } | |
1664 | } | |
1665 | } | |
1666 | } | |
1667 | }, | |
1668 | "ipv6": { | |
1669 | "unicast": { | |
1670 | "neighbor": { | |
1671 | "r4": { | |
1672 | "dest_link": { | |
1673 | "r2": { | |
787e7624 | 1674 | "route_maps": [ |
1675 | { | |
1676 | "name": "RM_R4_OUT", | |
1677 | "direction": "out", | |
1678 | } | |
1679 | ] | |
85d47773 AP |
1680 | } |
1681 | } | |
1682 | } | |
1683 | } | |
1684 | } | |
787e7624 | 1685 | }, |
85d47773 AP |
1686 | } |
1687 | } | |
787e7624 | 1688 | }, |
85d47773 AP |
1689 | } |
1690 | result = create_router_bgp(tgen, topo, input_dict_3) | |
787e7624 | 1691 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
1692 | |
1693 | step("Create standard large commumity-list") | |
1694 | input_dict_4 = { | |
1695 | "r3": { | |
1696 | "bgp_community_lists": [ | |
1697 | { | |
1698 | "community_type": "standard", | |
1699 | "action": "permit", | |
1700 | "name": "ALL", | |
1701 | "value": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5", | |
787e7624 | 1702 | "large": True, |
85d47773 AP |
1703 | } |
1704 | ] | |
1705 | } | |
1706 | } | |
1707 | result = create_bgp_community_lists(tgen, input_dict_4) | |
787e7624 | 1708 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
1709 | |
1710 | step("Verify BGP large community is created") | |
1711 | result = verify_create_community_list(tgen, input_dict_4) | |
787e7624 | 1712 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
1713 | |
1714 | step("Create route map") | |
1715 | input_dict_5 = { | |
1716 | "r4": { | |
1717 | "route_maps": { | |
1718 | "RM_R4_IN": [ | |
1719 | { | |
1720 | "action": "permit", | |
1721 | "seq_id": "10", | |
787e7624 | 1722 | "match": {"large-community-list": {"id": "ALL"}}, |
85d47773 AP |
1723 | } |
1724 | ] | |
1725 | } | |
1726 | } | |
1727 | } | |
1728 | result = create_route_maps(tgen, input_dict_5) | |
787e7624 | 1729 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
1730 | |
1731 | step("Configure neighbor for route map") | |
1732 | input_dict_6 = { | |
1733 | "r4": { | |
1734 | "bgp": { | |
1735 | "address_family": { | |
1736 | "ipv4": { | |
1737 | "unicast": { | |
1738 | "neighbor": { | |
1739 | "r2": { | |
1740 | "dest_link": { | |
1741 | "r4": { | |
787e7624 | 1742 | "route_maps": [ |
1743 | {"name": "RM_R4_IN", "direction": "in"} | |
1744 | ] | |
85d47773 AP |
1745 | } |
1746 | } | |
1747 | } | |
1748 | } | |
1749 | } | |
1750 | }, | |
1751 | "ipv6": { | |
1752 | "unicast": { | |
1753 | "neighbor": { | |
1754 | "r2": { | |
1755 | "dest_link": { | |
1756 | "r4": { | |
787e7624 | 1757 | "route_maps": [ |
1758 | {"name": "RM_R4_IN", "direction": "in"} | |
1759 | ] | |
85d47773 AP |
1760 | } |
1761 | } | |
1762 | } | |
1763 | } | |
1764 | } | |
787e7624 | 1765 | }, |
85d47773 AP |
1766 | } |
1767 | } | |
1768 | } | |
1769 | } | |
1770 | result = create_router_bgp(tgen, topo, input_dict_6) | |
787e7624 | 1771 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
1772 | |
1773 | step("Verify large-community-list") | |
1774 | dut = "r4" | |
787e7624 | 1775 | 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"} |
85d47773 | 1776 | for adt in ADDR_TYPES: |
787e7624 | 1777 | result = verify_bgp_community(tgen, adt, dut, NETWORKS[adt], input_dict_4) |
85d47773 | 1778 | assert result is True, "Testcase {} : Failed \n Error: {}".format( |
787e7624 | 1779 | tc_name, result |
1780 | ) | |
85d47773 AP |
1781 | |
1782 | write_test_footer(tc_name) | |
1783 | ||
1784 | ||
1785 | def test_large_community_lists_with_rmap_match_any(request): | |
1786 | """ | |
1787 | This test is to verify that Match_ANY clause should pass | |
1788 | only if at-least any one L-comm value configured(vertically) | |
1789 | in large-community list, is present in prefixes. | |
1790 | """ | |
1791 | ||
1792 | tgen = get_topogen() | |
1793 | tc_name = request.node.name | |
1794 | write_test_header(tc_name) | |
1795 | ||
1796 | # Don"t run this test if we have any failure. | |
1797 | if tgen.routers_have_failure(): | |
1798 | pytest.skip(tgen.errors) | |
1799 | ||
1800 | # Creating configuration from JSON | |
1801 | reset_config_on_routers(tgen) | |
1802 | ||
1803 | step("Create route map") | |
1804 | input_dict_2 = { | |
1805 | "r2": { | |
1806 | "route_maps": { | |
1807 | "RM_R4_OUT": [ | |
1808 | { | |
1809 | "action": "permit", | |
1810 | "seq_id": "10", | |
1811 | "set": { | |
787e7624 | 1812 | "large_community": {"num": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"} |
1813 | }, | |
85d47773 AP |
1814 | } |
1815 | ] | |
1816 | } | |
1817 | } | |
1818 | } | |
1819 | result = create_route_maps(tgen, input_dict_2) | |
787e7624 | 1820 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
1821 | |
1822 | step("Configure neighbor for route map") | |
1823 | input_dict_3 = { | |
1824 | "r1": { | |
1825 | "bgp": { | |
1826 | "address_family": { | |
1827 | "ipv4": { | |
1828 | "unicast": { | |
787e7624 | 1829 | "advertise_networks": [{"network": "200.50.2.0/32"}] |
85d47773 AP |
1830 | } |
1831 | }, | |
1832 | "ipv6": { | |
787e7624 | 1833 | "unicast": {"advertise_networks": [{"network": "1::1/128"}]} |
1834 | }, | |
85d47773 AP |
1835 | } |
1836 | } | |
1837 | }, | |
1838 | "r2": { | |
1839 | "bgp": { | |
1840 | "address_family": { | |
1841 | "ipv4": { | |
1842 | "unicast": { | |
1843 | "neighbor": { | |
1844 | "r4": { | |
1845 | "dest_link": { | |
1846 | "r2": { | |
787e7624 | 1847 | "route_maps": [ |
1848 | { | |
1849 | "name": "RM_R4_OUT", | |
1850 | "direction": "out", | |
1851 | } | |
1852 | ] | |
85d47773 AP |
1853 | } |
1854 | } | |
1855 | } | |
1856 | } | |
1857 | } | |
1858 | }, | |
1859 | "ipv6": { | |
1860 | "unicast": { | |
1861 | "neighbor": { | |
1862 | "r4": { | |
1863 | "dest_link": { | |
1864 | "r2": { | |
787e7624 | 1865 | "route_maps": [ |
1866 | { | |
1867 | "name": "RM_R4_OUT", | |
1868 | "direction": "out", | |
1869 | } | |
1870 | ] | |
85d47773 AP |
1871 | } |
1872 | } | |
1873 | } | |
1874 | } | |
1875 | } | |
787e7624 | 1876 | }, |
85d47773 AP |
1877 | } |
1878 | } | |
787e7624 | 1879 | }, |
85d47773 AP |
1880 | } |
1881 | result = create_router_bgp(tgen, topo, input_dict_3) | |
787e7624 | 1882 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
1883 | |
1884 | step("Create standard large commumity-list") | |
1885 | input_dict_4 = { | |
1886 | "r4": { | |
1887 | "bgp_community_lists": [ | |
1888 | { | |
1889 | "community_type": "standard", | |
1890 | "action": "permit", | |
1891 | "name": "ANY", | |
1892 | "value": "2:1:1", | |
787e7624 | 1893 | "large": True, |
85d47773 AP |
1894 | }, |
1895 | { | |
1896 | "community_type": "standard", | |
1897 | "action": "permit", | |
1898 | "name": "ANY", | |
1899 | "value": "2:2:1", | |
787e7624 | 1900 | "large": True, |
85d47773 AP |
1901 | }, |
1902 | { | |
1903 | "community_type": "standard", | |
1904 | "action": "permit", | |
1905 | "name": "ANY", | |
1906 | "value": "2:3:1", | |
787e7624 | 1907 | "large": True, |
85d47773 AP |
1908 | }, |
1909 | { | |
1910 | "community_type": "standard", | |
1911 | "action": "permit", | |
1912 | "name": "ANY", | |
1913 | "value": "2:4:1", | |
787e7624 | 1914 | "large": True, |
1915 | }, | |
85d47773 AP |
1916 | ] |
1917 | } | |
1918 | } | |
1919 | result = create_bgp_community_lists(tgen, input_dict_4) | |
787e7624 | 1920 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
1921 | |
1922 | step("Verify BGP large community is created") | |
1923 | result = verify_create_community_list(tgen, input_dict_4) | |
787e7624 | 1924 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
1925 | |
1926 | step("Create route map") | |
1927 | input_dict_5 = { | |
1928 | "r4": { | |
1929 | "route_maps": { | |
1930 | "RM_R4_IN": [ | |
1931 | { | |
1932 | "action": "permit", | |
1933 | "seq_id": "10", | |
787e7624 | 1934 | "match": {"large-community-list": {"id": "ANY"}}, |
85d47773 AP |
1935 | } |
1936 | ] | |
1937 | } | |
1938 | } | |
1939 | } | |
1940 | result = create_route_maps(tgen, input_dict_5) | |
787e7624 | 1941 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
1942 | |
1943 | step("Configure neighbor for route map") | |
1944 | input_dict_6 = { | |
1945 | "r4": { | |
1946 | "bgp": { | |
1947 | "address_family": { | |
1948 | "ipv4": { | |
1949 | "unicast": { | |
1950 | "neighbor": { | |
1951 | "r2": { | |
1952 | "dest_link": { | |
1953 | "r4": { | |
787e7624 | 1954 | "route_maps": [ |
1955 | {"name": "RM_R4_IN", "direction": "in"} | |
1956 | ] | |
85d47773 AP |
1957 | } |
1958 | } | |
1959 | } | |
1960 | } | |
1961 | } | |
1962 | }, | |
1963 | "ipv6": { | |
1964 | "unicast": { | |
1965 | "neighbor": { | |
1966 | "r2": { | |
1967 | "dest_link": { | |
1968 | "r4": { | |
787e7624 | 1969 | "route_maps": [ |
1970 | {"name": "RM_R4_IN", "direction": "in"} | |
1971 | ] | |
85d47773 AP |
1972 | } |
1973 | } | |
1974 | } | |
1975 | } | |
1976 | } | |
787e7624 | 1977 | }, |
85d47773 AP |
1978 | } |
1979 | } | |
1980 | } | |
1981 | } | |
1982 | result = create_router_bgp(tgen, topo, input_dict_6) | |
787e7624 | 1983 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
1984 | |
1985 | step("Verify large-community-list") | |
1986 | dut = "r4" | |
787e7624 | 1987 | input_dict_7 = {"largeCommunity": "2:1:1 2:2:2 2:3:3 2:4:4 2:5:5"} |
85d47773 | 1988 | for adt in ADDR_TYPES: |
787e7624 | 1989 | result = verify_bgp_community(tgen, adt, dut, NETWORKS[adt], input_dict_7) |
85d47773 | 1990 | assert result is True, "Testcase {} : Failed \n Error: {}".format( |
787e7624 | 1991 | tc_name, result |
1992 | ) | |
85d47773 AP |
1993 | |
1994 | write_test_footer(tc_name) | |
1995 | ||
1996 | ||
1997 | def test_large_community_lists_with_rmap_match_regex(request): | |
1998 | """ | |
1999 | This test is to verify large-community lists" operation in a route-map | |
2000 | with match RegEx statements. Match clause should pass only if the | |
2001 | complete string of L-comm values are matched | |
2002 | """ | |
2003 | ||
2004 | tgen = get_topogen() | |
2005 | tc_name = request.node.name | |
2006 | write_test_header(tc_name) | |
2007 | ||
2008 | # Don"t run this test if we have any failure. | |
2009 | if tgen.routers_have_failure(): | |
2010 | pytest.skip(tgen.errors) | |
2011 | ||
2012 | # Creating configuration from JSON | |
2013 | reset_config_on_routers(tgen) | |
2014 | ||
2015 | step("Create route map") | |
2016 | input_dict_2 = { | |
2017 | "r2": { | |
2018 | "route_maps": { | |
2019 | "RM_R4_OUT": [ | |
2020 | { | |
2021 | "action": "permit", | |
2022 | "seq_id": "10", | |
2023 | "set": { | |
2024 | "large_community": { | |
2025 | "num": "1:1:1 1:1:2 2:1:3 2:1:4 2:1:5", | |
2026 | }, | |
787e7624 | 2027 | "community": {"num": "1:1 1:2 1:3 1:4 1:5"}, |
2028 | }, | |
85d47773 AP |
2029 | } |
2030 | ] | |
2031 | } | |
2032 | } | |
2033 | } | |
2034 | result = create_route_maps(tgen, input_dict_2) | |
787e7624 | 2035 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
2036 | |
2037 | step("Configure neighbor for route map") | |
2038 | input_dict_3 = { | |
2039 | "r1": { | |
2040 | "bgp": { | |
2041 | "address_family": { | |
2042 | "ipv4": { | |
2043 | "unicast": { | |
787e7624 | 2044 | "advertise_networks": [{"network": "200.50.2.0/32"}] |
85d47773 AP |
2045 | } |
2046 | }, | |
2047 | "ipv6": { | |
787e7624 | 2048 | "unicast": {"advertise_networks": [{"network": "1::1/128"}]} |
2049 | }, | |
85d47773 AP |
2050 | } |
2051 | } | |
2052 | }, | |
2053 | "r2": { | |
2054 | "bgp": { | |
2055 | "address_family": { | |
2056 | "ipv4": { | |
2057 | "unicast": { | |
2058 | "neighbor": { | |
2059 | "r4": { | |
2060 | "dest_link": { | |
2061 | "r2": { | |
787e7624 | 2062 | "route_maps": [ |
2063 | { | |
2064 | "name": "RM_R4_OUT", | |
2065 | "direction": "out", | |
2066 | } | |
2067 | ] | |
85d47773 AP |
2068 | } |
2069 | } | |
2070 | } | |
2071 | } | |
2072 | } | |
2073 | }, | |
2074 | "ipv6": { | |
2075 | "unicast": { | |
2076 | "neighbor": { | |
2077 | "r4": { | |
2078 | "dest_link": { | |
2079 | "r2": { | |
787e7624 | 2080 | "route_maps": [ |
2081 | { | |
2082 | "name": "RM_R4_OUT", | |
2083 | "direction": "out", | |
2084 | } | |
2085 | ] | |
85d47773 AP |
2086 | } |
2087 | } | |
2088 | } | |
2089 | } | |
2090 | } | |
787e7624 | 2091 | }, |
85d47773 AP |
2092 | } |
2093 | } | |
787e7624 | 2094 | }, |
85d47773 | 2095 | } |
787e7624 | 2096 | result = create_router_bgp(tgen, topo, input_dict_3) |
2097 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
85d47773 AP |
2098 | |
2099 | step("Create standard large commumity-list") | |
2100 | input_dict_4 = { | |
2101 | "r4": { | |
2102 | "bgp_community_lists": [ | |
2103 | { | |
2104 | "community_type": "standard", | |
2105 | "action": "permit", | |
2106 | "name": "ALL", | |
2107 | "value": "1:1:1 2:1:3 2:1:4 2:1:5", | |
787e7624 | 2108 | "large": True, |
85d47773 AP |
2109 | }, |
2110 | { | |
2111 | "community_type": "expanded", | |
2112 | "action": "permit", | |
2113 | "name": "EXP_ALL", | |
2114 | "value": "1:1:1 2:1:[3-5]", | |
787e7624 | 2115 | "large": True, |
2116 | }, | |
85d47773 AP |
2117 | ] |
2118 | } | |
2119 | } | |
2120 | result = create_bgp_community_lists(tgen, input_dict_4) | |
787e7624 | 2121 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
2122 | |
2123 | step("Verify BGP large community is created") | |
2124 | result = verify_create_community_list(tgen, input_dict_4) | |
787e7624 | 2125 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
2126 | |
2127 | step("Create route map") | |
2128 | input_dict_5 = { | |
2129 | "r4": { | |
2130 | "route_maps": { | |
2131 | "RM_R4_IN": [ | |
2132 | { | |
2133 | "action": "permit", | |
2134 | "seq_id": "10", | |
9fa6ec14 | 2135 | "match": { |
2136 | "large_community_list": { | |
2137 | "id": "ALL", | |
2138 | }, | |
2139 | }, | |
85d47773 AP |
2140 | } |
2141 | ] | |
2142 | } | |
2143 | } | |
2144 | } | |
2145 | result = create_route_maps(tgen, input_dict_5) | |
787e7624 | 2146 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
2147 | |
2148 | step("Configure neighbor for route map") | |
2149 | input_dict_6 = { | |
2150 | "r4": { | |
2151 | "bgp": { | |
2152 | "address_family": { | |
2153 | "ipv4": { | |
2154 | "unicast": { | |
2155 | "neighbor": { | |
2156 | "r2": { | |
2157 | "dest_link": { | |
2158 | "r4": { | |
787e7624 | 2159 | "route_maps": [ |
2160 | {"name": "RM_R4_IN", "direction": "in"} | |
2161 | ] | |
85d47773 AP |
2162 | } |
2163 | } | |
2164 | } | |
2165 | } | |
2166 | } | |
2167 | }, | |
2168 | "ipv6": { | |
2169 | "unicast": { | |
2170 | "neighbor": { | |
2171 | "r2": { | |
2172 | "dest_link": { | |
2173 | "r4": { | |
787e7624 | 2174 | "route_maps": [ |
2175 | {"name": "RM_R4_IN", "direction": "in"} | |
2176 | ] | |
85d47773 AP |
2177 | } |
2178 | } | |
2179 | } | |
2180 | } | |
2181 | } | |
787e7624 | 2182 | }, |
85d47773 AP |
2183 | } |
2184 | } | |
2185 | } | |
2186 | } | |
2187 | result = create_router_bgp(tgen, topo, input_dict_6) | |
787e7624 | 2188 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
2189 | |
2190 | step("Verify large-community-list") | |
2191 | dut = "r4" | |
787e7624 | 2192 | input_dict_7 = {"largeCommunity": "1:1:1 1:1:2 2:1:3 2:1:4 2:1:5"} |
85d47773 | 2193 | for adt in ADDR_TYPES: |
787e7624 | 2194 | result = verify_bgp_community(tgen, adt, dut, NETWORKS[adt], input_dict_7) |
85d47773 | 2195 | assert result is True, "Testcase {} : Failed \n Error: {}".format( |
787e7624 | 2196 | tc_name, result |
2197 | ) | |
85d47773 AP |
2198 | |
2199 | step("Delete route map reference by community-list") | |
787e7624 | 2200 | input_dict_3 = {"r4": {"route_maps": ["RM_R4_IN"]}} |
85d47773 | 2201 | result = delete_route_maps(tgen, input_dict_3) |
787e7624 | 2202 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
2203 | |
2204 | result = verify_route_maps(tgen, input_dict_3) | |
787e7624 | 2205 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
2206 | |
2207 | step("Create route map") | |
2208 | input_dict_5 = { | |
2209 | "r4": { | |
2210 | "route_maps": { | |
2211 | "RM_R4_IN": [ | |
2212 | { | |
2213 | "action": "permit", | |
2214 | "seq_id": "20", | |
9fa6ec14 | 2215 | "match": { |
2216 | "large_community_list": { | |
2217 | "id": "EXP_ALL", | |
2218 | }, | |
2219 | }, | |
85d47773 AP |
2220 | } |
2221 | ] | |
2222 | } | |
2223 | } | |
2224 | } | |
2225 | result = create_route_maps(tgen, input_dict_5) | |
787e7624 | 2226 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
2227 | |
2228 | step("clear ip bgp") | |
787e7624 | 2229 | result = clear_bgp_and_verify(tgen, topo, "r4") |
2230 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
85d47773 AP |
2231 | |
2232 | step("Verify large-community-list") | |
2233 | dut = "r4" | |
787e7624 | 2234 | input_dict_7 = {"largeCommunity": "1:1:1 1:1:2 2:1:3 2:1:4 2:1:5"} |
85d47773 | 2235 | for adt in ADDR_TYPES: |
787e7624 | 2236 | result = verify_bgp_community( |
2237 | tgen, adt, dut, NETWORKS[adt], input_dict_7, expected=False | |
2238 | ) | |
2239 | assert result is not True, "Testcase {} : Failed \n Error: {}".format( | |
2240 | tc_name, result | |
2241 | ) | |
85d47773 AP |
2242 | |
2243 | write_test_footer(tc_name) | |
2244 | ||
2245 | ||
2246 | if __name__ == "__main__": | |
2247 | args = ["-s"] + sys.argv[1:] | |
2248 | sys.exit(pytest.main(args)) |