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