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