]>
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 | """ | |
25 | Following tests are covered to test large-community/community functionality: | |
26 | 1. Verify if large community attribute can be configured only in correct | |
27 | canonical format. | |
28 | 2. Verify that the community attribute value, which we have advertised are | |
29 | received in correct format and values, at the receiving end. | |
30 | 3. Verify BGP Large Community attribute"s transitive property attribute. | |
31 | 4. Verify that BGP Large Communities attribute are malformed, if the length of | |
32 | the BGP Large Communities Attribute value, expressed in octets, | |
33 | is not a non-zero multiple of 12. | |
34 | 5. Verify if overriding large community values works fine. | |
35 | 6. Verify that large community values" aggregation works fine. | |
36 | 7. Standard community also work fine in conjunction with large-community. | |
37 | 8. Matching prefixes based on attributes other than prefix list and make use | |
38 | of set clause (IPV6). | |
39 | 9. Matching prefixes based on attributes other than prefix list and make use | |
40 | of set clause (IPV4). | |
41 | 10. Verify community and large-community list operations in route-map with all | |
42 | clause (exact, all, any, regex) works. | |
43 | 11. Verify that any value in BGP Large communities for boundary values. | |
44 | 12. Clear BGP neighbor-ship and check if large community and community | |
45 | attributes are getting re-populated. | |
46 | ||
47 | """ | |
48 | ||
49 | import pytest | |
50 | import time | |
51 | from os import path as os_path | |
52 | import sys | |
53 | from json import load as json_load | |
3dfd384e | 54 | |
85d47773 AP |
55 | # Required to instantiate the topology builder class. |
56 | from lib.topogen import Topogen, get_topogen | |
57 | from mininet.topo import Topo | |
58 | ||
59 | from lib.common_config import ( | |
787e7624 | 60 | start_topology, |
61 | write_test_header, | |
62 | write_test_footer, | |
63 | reset_config_on_routers, | |
64 | create_route_maps, | |
65 | create_bgp_community_lists, | |
66 | create_prefix_lists, | |
67 | verify_bgp_community, | |
68 | step, | |
69 | check_address_types, | |
701a0192 | 70 | required_linux_kernel_version, |
85d47773 AP |
71 | ) |
72 | from lib.topolog import logger | |
787e7624 | 73 | from lib.bgp import verify_bgp_convergence, create_router_bgp, clear_bgp_and_verify |
85d47773 AP |
74 | from lib.topojson import build_topo_from_json, build_config_from_json |
75 | ||
76 | # Save the Current Working Directory to find configuration files. | |
77 | CWD = os_path.dirname(os_path.realpath(__file__)) | |
78 | sys.path.append(os_path.join(CWD, "../")) | |
79 | sys.path.append(os_path.join(CWD, "../lib/")) | |
80 | ||
81 | # Reading the data from JSON File for topology and configuration creation | |
82 | jsonFile = "{}/bgp_large_community_topo_1.json".format(CWD) | |
83 | try: | |
84 | with open(jsonFile, "r") as topoJson: | |
85 | topo = json_load(topoJson) | |
86 | except IOError: | |
87 | logger.info("Could not read file:", jsonFile) | |
88 | ||
89 | # Global variables | |
90 | bgp_convergence = False | |
91 | NETWORK = { | |
92 | "ipv4": ["200.50.2.0", "200.50.2.1", "200.50.2.0"], | |
787e7624 | 93 | "ipv6": ["1::1", "1::2", "1::0"], |
85d47773 AP |
94 | } |
95 | MASK = {"ipv4": "32", "ipv6": "128"} | |
96 | NET_MASK = {"ipv4": "24", "ipv6": "120"} | |
97 | IPV4_NET = ["200.50.2.0"] | |
98 | IPV6_NET = ["1::0"] | |
99 | CONFIG_ROUTER_R1 = False | |
100 | CONFIG_ROUTER_R2 = False | |
101 | CONFIG_ROUTER_ADDITIVE = False | |
102 | ADDR_TYPES = [] | |
103 | LARGE_COMM = { | |
104 | "r1": "1:1:1 1:2:1 1:3:1 1:4:1 1:5:1", | |
105 | "r2": "2:1:1 2:2:1 2:3:1 2:4:1 2:5:1", | |
106 | "mal_1": "1:1 1:2 1:3 1:4 1:5", | |
107 | "pf_list_1": "0:0:1 0:0:10 0:0:100", | |
108 | "pf_list_2": "0:0:2 0:0:20 0:0:200", | |
109 | "agg_1": "0:0:1 0:0:2 0:0:10 0:0:20 0:0:100 0:0:200 2:1:1 " | |
787e7624 | 110 | "2:2:1 2:3:1 2:4:1 2:5:1", |
111 | "agg_2": "0:0:2 0:0:20 0:0:200 2:1:1 " "2:2:1 2:3:1 2:4:1 2:5:1", | |
85d47773 AP |
112 | } |
113 | STANDARD_COMM = { | |
114 | "r1": "1:1 1:2 1:3 1:4 1:5", | |
115 | "r2": "2:1 2:2 2:3 2:4 2:5", | |
116 | "mal_1": "1 2 3 4 5", | |
117 | "pf_list_1": "0:1 0:10 0:100", | |
118 | "pf_list_2": "0:2 0:20 0:200", | |
119 | "agg_1": "0:1 0:2 0:10 0:20 0:100 0:200 2:1 2:2 2:3 2:4 2:5", | |
787e7624 | 120 | "agg_2": "0:2 0:20 0:200 2:1 2:2 2:3 2:4 2:5", |
85d47773 AP |
121 | } |
122 | ||
123 | ||
124 | class CreateTopo(Topo): | |
125 | """ | |
126 | Test topology builder | |
127 | ||
128 | ||
129 | * `Topo`: Topology object | |
130 | """ | |
131 | ||
132 | def build(self, *_args, **_opts): | |
133 | """Build function""" | |
134 | tgen = get_topogen(self) | |
135 | ||
136 | # Building topology from json file | |
137 | build_topo_from_json(tgen, topo) | |
138 | ||
139 | ||
140 | def setup_module(mod): | |
141 | """ | |
142 | Sets up the pytest environment | |
143 | ||
144 | * `mod`: module name | |
145 | """ | |
3dfd384e | 146 | # Required linux kernel version for this suite to run. |
701a0192 | 147 | result = required_linux_kernel_version("4.15") |
955212d9 | 148 | if result is not True: |
149 | pytest.skip("Kernel requirements are not met") | |
3dfd384e | 150 | |
85d47773 AP |
151 | global ADDR_TYPES |
152 | testsuite_run_time = time.asctime(time.localtime(time.time())) | |
153 | logger.info("Testsuite start time: {}".format(testsuite_run_time)) | |
154 | logger.info("=" * 40) | |
155 | ||
156 | logger.info("Running setup_module to create topology") | |
157 | ||
158 | # This function initiates the topology build with Topogen... | |
159 | tgen = Topogen(CreateTopo, mod.__name__) | |
160 | # ... and here it calls Mininet initialization functions. | |
161 | ||
162 | # Starting topology, create tmp files which are loaded to routers | |
163 | # to start deamons and then start routers | |
164 | start_topology(tgen) | |
165 | ||
166 | # Creating configuration from JSON | |
167 | build_config_from_json(tgen, topo) | |
168 | ||
169 | # Checking BGP convergence | |
170 | global bgp_convergence | |
171 | ||
172 | # Don"t run this test if we have any failure. | |
173 | if tgen.routers_have_failure(): | |
174 | pytest.skip(tgen.errors) | |
175 | ||
176 | ##tgen.mininet_cli() | |
177 | # Api call verify whether BGP is converged | |
178 | bgp_convergence = verify_bgp_convergence(tgen, topo) | |
787e7624 | 179 | assert bgp_convergence is True, "setup_module :Failed \n Error:" " {}".format( |
180 | bgp_convergence | |
181 | ) | |
85d47773 AP |
182 | |
183 | ADDR_TYPES = check_address_types() | |
184 | logger.info("Running setup_module() done") | |
185 | ||
186 | ||
187 | def teardown_module(): | |
188 | """ | |
189 | Teardown the pytest environment | |
190 | ||
191 | * `mod`: module name | |
192 | """ | |
193 | ||
194 | logger.info("Running teardown_module to delete topology") | |
195 | ||
196 | tgen = get_topogen() | |
197 | ||
198 | # Stop toplogy and Remove tmp files | |
199 | tgen.stop_topology() | |
200 | ||
787e7624 | 201 | logger.info( |
202 | "Testsuite end time: {}".format(time.asctime(time.localtime(time.time()))) | |
203 | ) | |
85d47773 AP |
204 | logger.info("=" * 40) |
205 | ||
206 | ||
207 | def config_router_r1(tgen, topo, tc_name): | |
208 | global CONFIG_ROUTER_R1 | |
209 | ||
210 | input_dict_1 = { | |
211 | "r1": { | |
212 | "route_maps": { | |
213 | "LC1": [ | |
214 | { | |
215 | "action": "permit", | |
216 | "seq_id": "10", | |
217 | "set": { | |
787e7624 | 218 | "large_community": {"num": LARGE_COMM["r1"]}, |
219 | "community": {"num": STANDARD_COMM["r1"]}, | |
220 | }, | |
85d47773 AP |
221 | } |
222 | ] | |
223 | } | |
224 | } | |
225 | } | |
226 | ||
227 | step("Configuring LC1 on r1") | |
228 | result = create_route_maps(tgen, input_dict_1) | |
787e7624 | 229 | assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
230 | |
231 | # Configure neighbor for route map | |
232 | input_dict_2 = { | |
233 | "r1": { | |
234 | "bgp": { | |
235 | "address_family": { | |
236 | "ipv4": { | |
237 | "unicast": { | |
238 | "advertise_networks": [ | |
239 | { | |
787e7624 | 240 | "network": "%s/%s" |
241 | % (NETWORK["ipv4"][0], MASK["ipv4"]), | |
242 | "no_of_network": 4, | |
85d47773 AP |
243 | } |
244 | ], | |
245 | "neighbor": { | |
246 | "r2": { | |
247 | "dest_link": { | |
248 | "r1-link1": { | |
787e7624 | 249 | "route_maps": [ |
250 | {"name": "LC1", "direction": "out"} | |
251 | ] | |
85d47773 AP |
252 | } |
253 | } | |
254 | }, | |
255 | "r3": { | |
256 | "dest_link": { | |
257 | "r1-link1": { | |
787e7624 | 258 | "route_maps": [ |
259 | {"name": "LC1", "direction": "out"} | |
260 | ] | |
85d47773 AP |
261 | } |
262 | } | |
787e7624 | 263 | }, |
264 | }, | |
85d47773 AP |
265 | } |
266 | }, | |
267 | "ipv6": { | |
268 | "unicast": { | |
269 | "advertise_networks": [ | |
270 | { | |
787e7624 | 271 | "network": "%s/%s" |
272 | % (NETWORK["ipv6"][0], MASK["ipv6"]), | |
273 | "no_of_network": 4, | |
85d47773 AP |
274 | } |
275 | ], | |
276 | "neighbor": { | |
277 | "r2": { | |
278 | "dest_link": { | |
279 | "r1-link1": { | |
787e7624 | 280 | "route_maps": [ |
281 | {"name": "LC1", "direction": "out"} | |
282 | ] | |
85d47773 AP |
283 | } |
284 | } | |
285 | }, | |
286 | "r3": { | |
287 | "dest_link": { | |
288 | "r1-link1": { | |
787e7624 | 289 | "route_maps": [ |
290 | {"name": "LC1", "direction": "out"} | |
291 | ] | |
85d47773 AP |
292 | } |
293 | } | |
787e7624 | 294 | }, |
295 | }, | |
85d47773 | 296 | } |
787e7624 | 297 | }, |
85d47773 AP |
298 | } |
299 | } | |
300 | } | |
301 | } | |
302 | ||
303 | step("Applying LC1 on r1 neighbors and advertising networks") | |
304 | result = create_router_bgp(tgen, topo, input_dict_2) | |
787e7624 | 305 | assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
306 | |
307 | CONFIG_ROUTER_R1 = True | |
308 | ||
309 | ||
310 | def config_router_r2(tgen, topo, tc_name): | |
311 | global CONFIG_ROUTER_R2 | |
312 | ||
313 | input_dict = { | |
314 | "r2": { | |
315 | "route_maps": { | |
316 | "LC2": [ | |
317 | { | |
318 | "action": "permit", | |
319 | "seq_id": "10", | |
320 | "set": { | |
787e7624 | 321 | "large_community": {"num": LARGE_COMM["r2"]}, |
322 | "community": {"num": STANDARD_COMM["r2"]}, | |
323 | }, | |
85d47773 AP |
324 | } |
325 | ] | |
326 | } | |
327 | } | |
328 | } | |
329 | ||
330 | step("Configuring route-maps LC2 on r2") | |
331 | result = create_route_maps(tgen, input_dict) | |
787e7624 | 332 | assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
333 | |
334 | input_dict_1 = { | |
335 | "r2": { | |
336 | "bgp": { | |
337 | "address_family": { | |
338 | "ipv4": { | |
339 | "unicast": { | |
340 | "neighbor": { | |
341 | "r4": { | |
342 | "dest_link": { | |
343 | "r2-link1": { | |
787e7624 | 344 | "route_maps": [ |
345 | {"name": "LC2", "direction": "out"} | |
346 | ] | |
85d47773 AP |
347 | } |
348 | } | |
349 | } | |
350 | } | |
351 | } | |
352 | }, | |
353 | "ipv6": { | |
354 | "unicast": { | |
355 | "neighbor": { | |
356 | "r4": { | |
357 | "dest_link": { | |
358 | "r2-link1": { | |
787e7624 | 359 | "route_maps": [ |
360 | {"name": "LC2", "direction": "out"} | |
361 | ] | |
85d47773 AP |
362 | } |
363 | } | |
364 | } | |
365 | } | |
366 | } | |
787e7624 | 367 | }, |
85d47773 AP |
368 | } |
369 | } | |
370 | } | |
371 | } | |
372 | ||
373 | step("Applying LC2 on r2 neighbors in out direction") | |
374 | result = create_router_bgp(tgen, topo, input_dict_1) | |
787e7624 | 375 | assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
376 | |
377 | CONFIG_ROUTER_R2 = True | |
378 | ||
379 | ||
380 | def config_router_additive(tgen, topo, tc_name): | |
381 | global CONFIG_ROUTER_ADDITIVE | |
382 | ||
383 | input_dict = { | |
384 | "r2": { | |
385 | "route_maps": { | |
386 | "LC2": [ | |
387 | { | |
388 | "action": "permit", | |
389 | "seq_id": "10", | |
390 | "set": { | |
391 | "large_community": { | |
392 | "num": LARGE_COMM["r2"], | |
787e7624 | 393 | "action": "additive", |
85d47773 AP |
394 | }, |
395 | "community": { | |
396 | "num": STANDARD_COMM["r2"], | |
787e7624 | 397 | "action": "additive", |
398 | }, | |
399 | }, | |
85d47773 AP |
400 | } |
401 | ] | |
402 | } | |
403 | } | |
404 | } | |
405 | ||
406 | step("Configuring LC2 with community attributes as additive") | |
407 | result = create_route_maps(tgen, input_dict) | |
787e7624 | 408 | assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
409 | |
410 | # tgen.mininet_cli() | |
411 | CONFIG_ROUTER_ADDITIVE = True | |
412 | ||
413 | ||
414 | def config_for_as_path(tgen, topo, tc_name): | |
415 | config_router_r1(tgen, topo, tc_name) | |
416 | ||
417 | config_router_r2(tgen, topo, tc_name) | |
418 | ||
419 | # Create ipv6 prefix list | |
420 | input_dict_1 = { | |
421 | "r1": { | |
422 | "prefix_lists": { | |
423 | "ipv4": { | |
424 | "pf_list_1": [ | |
425 | { | |
426 | "seqid": "10", | |
787e7624 | 427 | "network": "%s/%s" % (NETWORK["ipv4"][0], MASK["ipv4"]), |
428 | "action": "permit", | |
85d47773 AP |
429 | } |
430 | ], | |
431 | "pf_list_2": [ | |
432 | { | |
433 | "seqid": "10", | |
787e7624 | 434 | "network": "%s/%s" % (NETWORK["ipv4"][1], MASK["ipv4"]), |
435 | "action": "permit", | |
85d47773 | 436 | } |
787e7624 | 437 | ], |
85d47773 AP |
438 | }, |
439 | "ipv6": { | |
440 | "pf_list_3": [ | |
441 | { | |
442 | "seqid": "10", | |
787e7624 | 443 | "network": "%s/%s" % (NETWORK["ipv6"][0], MASK["ipv6"]), |
444 | "action": "permit", | |
85d47773 AP |
445 | } |
446 | ], | |
447 | "pf_list_4": [ | |
448 | { | |
449 | "seqid": "10", | |
787e7624 | 450 | "network": "%s/%s" % (NETWORK["ipv6"][1], MASK["ipv6"]), |
451 | "action": "permit", | |
85d47773 | 452 | } |
787e7624 | 453 | ], |
454 | }, | |
85d47773 AP |
455 | } |
456 | } | |
457 | } | |
458 | ||
459 | step("Configuring prefix-lists on r1 to filter networks") | |
460 | result = create_prefix_lists(tgen, input_dict_1) | |
787e7624 | 461 | assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
462 | |
463 | input_dict_2 = { | |
464 | "r1": { | |
465 | "route_maps": { | |
466 | "LC1": [ | |
467 | { | |
468 | "action": "permit", | |
469 | "seq_id": 10, | |
787e7624 | 470 | "match": {"ipv4": {"prefix_lists": "pf_list_1"}}, |
85d47773 | 471 | "set": { |
787e7624 | 472 | "large_community": {"num": LARGE_COMM["pf_list_1"]}, |
473 | "community": {"num": STANDARD_COMM["pf_list_1"]}, | |
474 | }, | |
85d47773 AP |
475 | }, |
476 | { | |
477 | "action": "permit", | |
478 | "seq_id": 20, | |
787e7624 | 479 | "match": {"ipv6": {"prefix_lists": "pf_list_3"}}, |
85d47773 | 480 | "set": { |
787e7624 | 481 | "large_community": {"num": LARGE_COMM["pf_list_1"]}, |
482 | "community": {"num": STANDARD_COMM["pf_list_1"]}, | |
483 | }, | |
85d47773 AP |
484 | }, |
485 | { | |
486 | "action": "permit", | |
487 | "seq_id": 30, | |
787e7624 | 488 | "match": {"ipv4": {"prefix_lists": "pf_list_2"}}, |
85d47773 | 489 | "set": { |
787e7624 | 490 | "large_community": {"num": LARGE_COMM["pf_list_2"]}, |
491 | "community": {"num": STANDARD_COMM["pf_list_2"]}, | |
492 | }, | |
85d47773 AP |
493 | }, |
494 | { | |
495 | "action": "permit", | |
496 | "seq_id": 40, | |
787e7624 | 497 | "match": {"ipv6": {"prefix_lists": "pf_list_4"}}, |
85d47773 | 498 | "set": { |
787e7624 | 499 | "large_community": {"num": LARGE_COMM["pf_list_2"]}, |
500 | "community": {"num": STANDARD_COMM["pf_list_2"]}, | |
501 | }, | |
502 | }, | |
85d47773 AP |
503 | ] |
504 | } | |
505 | } | |
506 | } | |
507 | ||
787e7624 | 508 | step( |
509 | "Applying prefix-lists match in route-map LC1 on r1. Setting" | |
510 | " community attritbute for filtered networks" | |
511 | ) | |
85d47773 | 512 | result = create_route_maps(tgen, input_dict_2) |
787e7624 | 513 | assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
514 | |
515 | config_router_additive(tgen, topo, tc_name) | |
516 | ||
517 | input_dict_3 = { | |
518 | "r4": { | |
519 | "bgp_community_lists": [ | |
520 | { | |
521 | "community_type": "standard", | |
522 | "action": "permit", | |
523 | "name": "ANY", | |
524 | "value": LARGE_COMM["pf_list_1"], | |
787e7624 | 525 | "large": True, |
85d47773 AP |
526 | }, |
527 | { | |
528 | "community_type": "standard", | |
529 | "action": "permit", | |
530 | "name": "ANY", | |
531 | "value": STANDARD_COMM["pf_list_1"], | |
787e7624 | 532 | }, |
85d47773 AP |
533 | ] |
534 | } | |
535 | } | |
536 | ||
537 | step("Configuring bgp community lists on r4") | |
538 | result = create_bgp_community_lists(tgen, input_dict_3) | |
787e7624 | 539 | assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
540 | |
541 | input_dict_4 = { | |
542 | "r4": { | |
543 | "route_maps": { | |
544 | "LC4": [ | |
545 | { | |
546 | "action": "permit", | |
547 | "seq_id": "10", | |
548 | "match": { | |
549 | "large_community_list": {"id": "ANY"}, | |
787e7624 | 550 | "community_list": {"id": "ANY"}, |
85d47773 | 551 | }, |
787e7624 | 552 | "set": {"path": {"as_num": "4000000", "as_action": "prepend"}}, |
85d47773 AP |
553 | } |
554 | ] | |
555 | } | |
556 | } | |
557 | } | |
558 | ||
559 | step("Applying community list on route-map on r4") | |
560 | result = create_route_maps(tgen, input_dict_4) | |
787e7624 | 561 | assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
562 | |
563 | input_dict_5 = { | |
564 | "r4": { | |
565 | "bgp": { | |
566 | "address_family": { | |
567 | "ipv4": { | |
568 | "unicast": { | |
569 | "neighbor": { | |
570 | "r5": { | |
571 | "dest_link": { | |
572 | "r4-link1": { | |
787e7624 | 573 | "route_maps": [ |
574 | {"name": "LC4", "direction": "out"} | |
575 | ] | |
85d47773 AP |
576 | } |
577 | } | |
578 | } | |
579 | } | |
580 | } | |
581 | }, | |
582 | "ipv6": { | |
583 | "unicast": { | |
584 | "neighbor": { | |
585 | "r5": { | |
586 | "dest_link": { | |
587 | "r4-link1": { | |
787e7624 | 588 | "route_maps": [ |
589 | {"name": "LC4", "direction": "out"} | |
590 | ] | |
85d47773 AP |
591 | } |
592 | } | |
593 | } | |
594 | } | |
595 | } | |
787e7624 | 596 | }, |
85d47773 AP |
597 | } |
598 | } | |
599 | } | |
600 | } | |
601 | ||
602 | step("Applying route-map LC4 out from r4 to r5 ") | |
603 | result = create_router_bgp(tgen, topo, input_dict_5) | |
787e7624 | 604 | assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
605 | |
606 | ||
607 | ##################################################### | |
608 | # | |
609 | # Test cases | |
610 | # | |
611 | ##################################################### | |
612 | def test_large_community_set(request): | |
613 | """ | |
614 | Verify if large community attribute can be configured only in correct | |
615 | canonical format. | |
616 | """ | |
617 | tc_name = request.node.name | |
618 | write_test_header(tc_name) | |
619 | tgen = get_topogen() | |
620 | ||
621 | # Don"t run this test if we have any failure. | |
622 | if tgen.routers_have_failure(): | |
623 | pytest.skip(tgen.errors) | |
624 | ||
625 | # API call to modify router id | |
626 | # input_dict dictionary to be provided to configure route_map | |
627 | input_dict = { | |
628 | "r1": { | |
629 | "route_maps": { | |
630 | "LC1": [ | |
631 | { | |
632 | "action": "permit", | |
633 | "seq_id": "10", | |
634 | "set": { | |
635 | "large_community": {"num": LARGE_COMM["r1"]}, | |
787e7624 | 636 | "community": {"num": STANDARD_COMM["r1"]}, |
637 | }, | |
85d47773 AP |
638 | } |
639 | ] | |
640 | } | |
641 | } | |
642 | } | |
643 | ||
644 | step("Trying to set bgp communities") | |
645 | result = create_route_maps(tgen, input_dict) | |
787e7624 | 646 | assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
647 | |
648 | write_test_footer(tc_name) | |
649 | ||
650 | ||
651 | def test_large_community_advertise(request): | |
652 | """ | |
653 | Verify that the community attribute value, which we have advertised are | |
654 | received in correct format and values, at the receiving end. | |
655 | """ | |
656 | tc_name = request.node.name | |
657 | write_test_header(tc_name) | |
658 | tgen = get_topogen() | |
659 | ||
660 | # Don"t run this test if we have any failure. | |
661 | if tgen.routers_have_failure(): | |
662 | pytest.skip(tgen.errors) | |
663 | ||
664 | reset_config_on_routers(tgen) | |
665 | config_router_r1(tgen, topo, tc_name) | |
666 | ||
667 | input_dict = { | |
668 | "largeCommunity": LARGE_COMM["r1"], | |
669 | "community": STANDARD_COMM["r1"], | |
670 | } | |
671 | ||
672 | for adt in ADDR_TYPES: | |
787e7624 | 673 | result = verify_bgp_community(tgen, adt, "r2", [NETWORK[adt][0]], input_dict) |
85d47773 | 674 | assert result is True, "Test case {} : Failed \n Error: {}".format( |
787e7624 | 675 | tc_name, result |
676 | ) | |
85d47773 | 677 | |
787e7624 | 678 | result = verify_bgp_community(tgen, adt, "r3", [NETWORK[adt][0]], input_dict) |
85d47773 | 679 | assert result is True, "Test case {} : Failed \n Error: {}".format( |
787e7624 | 680 | tc_name, result |
681 | ) | |
85d47773 AP |
682 | |
683 | write_test_footer(tc_name) | |
684 | ||
685 | ||
686 | def test_large_community_transitive(request): | |
687 | """ | |
688 | Verify BGP Large Community attribute"s transitive property attribute. | |
689 | """ | |
690 | tc_name = request.node.name | |
691 | write_test_header(tc_name) | |
692 | tgen = get_topogen() | |
693 | ||
694 | # Don"t run this test if we have any failure. | |
695 | if tgen.routers_have_failure(): | |
696 | pytest.skip(tgen.errors) | |
697 | ||
698 | reset_config_on_routers(tgen) | |
699 | ||
700 | config_router_r1(tgen, topo, tc_name) | |
701 | ||
702 | input_dict_1 = { | |
703 | "largeCommunity": LARGE_COMM["r1"], | |
787e7624 | 704 | "community": STANDARD_COMM["r1"], |
85d47773 AP |
705 | } |
706 | ||
707 | for adt in ADDR_TYPES: | |
787e7624 | 708 | result = verify_bgp_community(tgen, adt, "r4", [NETWORK[adt][0]], input_dict_1) |
85d47773 | 709 | assert result is True, "Test case {} : Failed \n Error: {}".format( |
787e7624 | 710 | tc_name, result |
711 | ) | |
85d47773 AP |
712 | |
713 | write_test_footer(tc_name) | |
714 | ||
715 | ||
716 | def test_large_community_override(request): | |
717 | """ | |
718 | Verify if overriding large community values works fine. | |
719 | """ | |
720 | tc_name = request.node.name | |
721 | write_test_header(tc_name) | |
722 | tgen = get_topogen() | |
723 | ||
724 | # Don"t run this test if we have any failure. | |
725 | if tgen.routers_have_failure(): | |
726 | pytest.skip(tgen.errors) | |
727 | ||
728 | reset_config_on_routers(tgen) | |
729 | config_router_r1(tgen, topo, tc_name) | |
730 | ||
731 | config_router_r2(tgen, topo, tc_name) | |
732 | ||
733 | input_dict_3 = { | |
734 | "largeCommunity": LARGE_COMM["r2"], | |
787e7624 | 735 | "community": STANDARD_COMM["r2"], |
85d47773 AP |
736 | } |
737 | ||
738 | for adt in ADDR_TYPES: | |
787e7624 | 739 | result = verify_bgp_community(tgen, adt, "r4", [NETWORK[adt][1]], input_dict_3) |
740 | assert result is True, "Test case {} : Failed \n Error: {}".format( | |
741 | tc_name, result | |
742 | ) | |
85d47773 AP |
743 | |
744 | write_test_footer(tc_name) | |
745 | ||
746 | ||
747 | def test_large_community_additive(request): | |
748 | """ | |
749 | Verify that large community values" aggregation works fine. | |
750 | """ | |
751 | tc_name = request.node.name | |
752 | write_test_header(tc_name) | |
753 | tgen = get_topogen() | |
754 | ||
755 | # Don"t run this test if we have any failure. | |
756 | if tgen.routers_have_failure(): | |
757 | pytest.skip(tgen.errors) | |
758 | ||
759 | reset_config_on_routers(tgen) | |
760 | config_router_r1(tgen, topo, tc_name) | |
761 | ||
762 | config_router_r2(tgen, topo, tc_name) | |
763 | ||
764 | config_router_additive(tgen, topo, tc_name) | |
765 | ||
766 | input_dict_1 = { | |
767 | "largeCommunity": "%s %s" % (LARGE_COMM["r1"], LARGE_COMM["r2"]), | |
787e7624 | 768 | "community": "%s %s" % (STANDARD_COMM["r1"], STANDARD_COMM["r2"]), |
85d47773 AP |
769 | } |
770 | ||
771 | for adt in ADDR_TYPES: | |
787e7624 | 772 | result = verify_bgp_community(tgen, adt, "r4", [NETWORK[adt][0]], input_dict_1) |
773 | assert result is True, "Test case {} : Failed \n Error: {}".format( | |
774 | tc_name, result | |
775 | ) | |
85d47773 AP |
776 | |
777 | write_test_footer(tc_name) | |
778 | ||
779 | ||
780 | def test_large_community_match_as_path(request): | |
781 | """ | |
782 | Matching prefixes based on attributes other than prefix list and make use | |
783 | of set clause. | |
784 | """ | |
785 | ||
786 | tc_name = request.node.name | |
787 | write_test_header(tc_name) | |
788 | tgen = get_topogen() | |
789 | ||
790 | # Don"t run this test if we have any failure. | |
791 | if tgen.routers_have_failure(): | |
792 | pytest.skip(tgen.errors) | |
793 | ||
794 | reset_config_on_routers(tgen) | |
795 | config_for_as_path(tgen, topo, tc_name) | |
796 | ||
797 | input_dict = { | |
787e7624 | 798 | "largeCommunity": "%s %s" % (LARGE_COMM["pf_list_1"], LARGE_COMM["r2"]), |
799 | "community": "%s %s" % (STANDARD_COMM["pf_list_1"], STANDARD_COMM["r2"]), | |
85d47773 AP |
800 | } |
801 | ||
802 | input_dict_1 = { | |
787e7624 | 803 | "largeCommunity": "%s %s" % (LARGE_COMM["pf_list_2"], LARGE_COMM["r2"]), |
804 | "community": "%s %s" % (STANDARD_COMM["pf_list_2"], STANDARD_COMM["r2"]), | |
85d47773 AP |
805 | } |
806 | ||
807 | for adt in ADDR_TYPES: | |
787e7624 | 808 | result = verify_bgp_community(tgen, adt, "r5", [NETWORK[adt][0]], input_dict) |
809 | assert result is True, "Test case {} : Failed \n Error: {}".format( | |
810 | tc_name, result | |
811 | ) | |
85d47773 | 812 | |
787e7624 | 813 | result = verify_bgp_community( |
814 | tgen, adt, "r5", [NETWORK[adt][1]], input_dict_1, expected=False | |
815 | ) | |
85d47773 | 816 | |
787e7624 | 817 | assert result is not True, "Test case {} : Should fail \n Error: {}".format( |
818 | tc_name, result | |
819 | ) | |
85d47773 AP |
820 | |
821 | write_test_footer(tc_name) | |
822 | ||
823 | ||
824 | def test_large_community_match_all(request): | |
825 | """ | |
826 | Verify community and large-community list operations in route-map with all | |
827 | clause (exact, all, any, regex) works. | |
828 | """ | |
829 | tc_name = request.node.name | |
830 | write_test_header(tc_name) | |
831 | tgen = get_topogen() | |
832 | ||
833 | # Don"t run this test if we have any failure. | |
834 | if tgen.routers_have_failure(): | |
835 | pytest.skip(tgen.errors) | |
836 | ||
837 | reset_config_on_routers(tgen) | |
838 | config_router_r1(tgen, topo, tc_name) | |
839 | ||
840 | config_router_r2(tgen, topo, tc_name) | |
841 | ||
842 | config_router_additive(tgen, topo, tc_name) | |
843 | ||
844 | input_dict_1 = { | |
845 | "r4": { | |
846 | "bgp_community_lists": [ | |
847 | { | |
848 | "community_type": "standard", | |
849 | "action": "permit", | |
850 | "name": "ANY", | |
851 | "value": "1:1:1", | |
787e7624 | 852 | "large": True, |
85d47773 AP |
853 | }, |
854 | { | |
855 | "community_type": "standard", | |
856 | "action": "permit", | |
857 | "name": "ALL", | |
858 | "value": "1:1:1 1:2:1 1:3:1 1:4:1 1:5:1 2:1:1 2:2:1", | |
787e7624 | 859 | "large": True, |
85d47773 AP |
860 | }, |
861 | { | |
862 | "community_type": "expanded", | |
863 | "action": "permit", | |
864 | "name": "EXP_ALL", | |
865 | "value": "1:1:1 1:2:1 1:3:1 1:4:1 1:5:1 2:[1-5]:1", | |
787e7624 | 866 | "large": True, |
867 | }, | |
85d47773 AP |
868 | ] |
869 | } | |
870 | } | |
871 | ||
872 | step("Create bgp community lists for ANY, EXACT and EXP_ALL match") | |
873 | ||
874 | result = create_bgp_community_lists(tgen, input_dict_1) | |
787e7624 | 875 | assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
876 | |
877 | input_dict_2 = { | |
878 | "r4": { | |
879 | "route_maps": { | |
880 | "LC4": [ | |
881 | { | |
882 | "action": "permit", | |
883 | "seq_id": "10", | |
787e7624 | 884 | "match": {"large-community-list": {"id": "ANY"}}, |
85d47773 AP |
885 | }, |
886 | { | |
887 | "action": "permit", | |
888 | "seq_id": "20", | |
787e7624 | 889 | "match": {"large-community-list": {"id": "EXACT"}}, |
85d47773 AP |
890 | }, |
891 | { | |
892 | "action": "permit", | |
893 | "seq_id": "30", | |
787e7624 | 894 | "match": {"large-community-list": {"id": "EXP_ALL"}}, |
895 | }, | |
85d47773 AP |
896 | ] |
897 | } | |
898 | } | |
899 | } | |
900 | ||
901 | step("Applying bgp community lits on LC4 route-map") | |
902 | result = create_route_maps(tgen, input_dict_2) | |
787e7624 | 903 | assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
904 | |
905 | input_dict_3 = { | |
906 | "r4": { | |
907 | "bgp": { | |
908 | "address_family": { | |
909 | "ipv4": { | |
910 | "unicast": { | |
911 | "neighbor": { | |
912 | "r5": { | |
913 | "dest_link": { | |
914 | "r4-link1": { | |
787e7624 | 915 | "route_maps": [ |
916 | {"name": "LC4", "direction": "in"} | |
917 | ] | |
85d47773 AP |
918 | } |
919 | } | |
920 | } | |
921 | } | |
922 | } | |
923 | }, | |
924 | "ipv6": { | |
925 | "unicast": { | |
926 | "neighbor": { | |
927 | "r5": { | |
928 | "dest_link": { | |
929 | "r4-link1": { | |
787e7624 | 930 | "route_maps": [ |
931 | {"name": "LC4", "direction": "in"} | |
932 | ] | |
85d47773 AP |
933 | } |
934 | } | |
935 | } | |
936 | } | |
937 | } | |
787e7624 | 938 | }, |
85d47773 AP |
939 | } |
940 | } | |
941 | } | |
942 | } | |
943 | ||
944 | step("Apply route-mpa LC4 on r4 for r2 neighbor, direction 'in'") | |
945 | ||
946 | result = create_router_bgp(tgen, topo, input_dict_3) | |
787e7624 | 947 | assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
948 | |
949 | input_dict_4 = { | |
950 | "largeCommunity": "1:1:1 1:2:1 1:3:1 1:4:1 1:5:1 2:1:1 2:2:1 2:3:1 " | |
787e7624 | 951 | "2:4:1 2:5:1" |
85d47773 AP |
952 | } |
953 | ||
954 | for adt in ADDR_TYPES: | |
787e7624 | 955 | result = verify_bgp_community(tgen, adt, "r4", [NETWORK[adt][0]], input_dict_4) |
956 | assert result is True, "Test case {} : Should fail \n Error: {}".format( | |
957 | tc_name, result | |
958 | ) | |
85d47773 AP |
959 | |
960 | write_test_footer(tc_name) | |
961 | ||
962 | ||
787e7624 | 963 | # @pytest.mark.skip(reason="as-set not working for ipv6") |
85d47773 AP |
964 | def test_large_community_aggregate_network(request): |
965 | """ | |
966 | Restart router and check if large community and community | |
967 | attributes are getting re-populated. | |
968 | """ | |
969 | ||
970 | tc_name = request.node.name | |
971 | write_test_header(tc_name) | |
972 | ||
973 | tgen = get_topogen() | |
974 | ||
975 | # Don"t run this test if we have any failure. | |
976 | if tgen.routers_have_failure(): | |
977 | pytest.skip(tgen.errors) | |
978 | ||
979 | reset_config_on_routers(tgen) | |
980 | ||
981 | config_for_as_path(tgen, topo, tc_name) | |
982 | ||
983 | input_dict = { | |
984 | "community": STANDARD_COMM["agg_1"], | |
787e7624 | 985 | "largeCommunity": LARGE_COMM["agg_1"], |
85d47773 AP |
986 | } |
987 | ||
988 | input_dict_1 = { | |
989 | "r2": { | |
990 | "bgp": { | |
991 | "address_family": { | |
992 | "ipv4": { | |
993 | "unicast": { | |
994 | "aggregate_address": [ | |
995 | { | |
787e7624 | 996 | "network": "%s/%s" |
997 | % (NETWORK["ipv4"][2], NET_MASK["ipv4"]), | |
998 | "as_set": True, | |
85d47773 AP |
999 | } |
1000 | ] | |
1001 | } | |
1002 | }, | |
1003 | "ipv6": { | |
1004 | "unicast": { | |
1005 | "aggregate_address": [ | |
1006 | { | |
787e7624 | 1007 | "network": "%s/%s" |
1008 | % (NETWORK["ipv6"][2], NET_MASK["ipv6"]), | |
1009 | "as_set": True, | |
85d47773 AP |
1010 | } |
1011 | ] | |
1012 | } | |
787e7624 | 1013 | }, |
85d47773 AP |
1014 | } |
1015 | } | |
1016 | } | |
1017 | } | |
1018 | ||
1019 | step("Configuring aggregate address as-set on r2") | |
1020 | result = create_router_bgp(tgen, topo, input_dict_1) | |
787e7624 | 1021 | assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
1022 | |
1023 | for adt in ADDR_TYPES: | |
787e7624 | 1024 | result = verify_bgp_community( |
1025 | tgen, adt, "r4", ["%s/%s" % (NETWORK[adt][2], NET_MASK[adt])], input_dict | |
1026 | ) | |
1027 | assert result is True, "Test case {} : Failed \n Error: {}".format( | |
1028 | tc_name, result | |
1029 | ) | |
85d47773 AP |
1030 | |
1031 | input_dict_2 = { | |
1032 | "r1": { | |
1033 | "bgp": { | |
1034 | "address_family": { | |
1035 | "ipv4": { | |
1036 | "unicast": { | |
1037 | "advertise_networks": [ | |
1038 | { | |
787e7624 | 1039 | "network": "%s/%s" |
1040 | % (NETWORK["ipv4"][0], MASK["ipv4"]), | |
85d47773 | 1041 | "no_of_network": 1, |
787e7624 | 1042 | "delete": True, |
85d47773 AP |
1043 | } |
1044 | ] | |
1045 | } | |
1046 | }, | |
1047 | "ipv6": { | |
1048 | "unicast": { | |
1049 | "advertise_networks": [ | |
1050 | { | |
787e7624 | 1051 | "network": "%s/%s" |
1052 | % (NETWORK["ipv6"][0], MASK["ipv6"]), | |
85d47773 | 1053 | "no_of_network": 1, |
787e7624 | 1054 | "delete": True, |
85d47773 AP |
1055 | } |
1056 | ] | |
1057 | } | |
787e7624 | 1058 | }, |
85d47773 AP |
1059 | } |
1060 | } | |
1061 | } | |
1062 | } | |
1063 | ||
1064 | step("Stop advertising one of the networks") | |
1065 | result = create_router_bgp(tgen, topo, input_dict_2) | |
787e7624 | 1066 | assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) |
85d47773 AP |
1067 | |
1068 | input_dict_3 = { | |
1069 | "community": STANDARD_COMM["agg_2"], | |
787e7624 | 1070 | "largeCommunity": LARGE_COMM["agg_2"], |
85d47773 AP |
1071 | } |
1072 | ||
1073 | for adt in ADDR_TYPES: | |
1074 | step("Verifying bgp community values on r5 is also modified") | |
787e7624 | 1075 | result = verify_bgp_community( |
1076 | tgen, adt, "r4", ["%s/%s" % (NETWORK[adt][2], NET_MASK[adt])], input_dict_3 | |
1077 | ) | |
1078 | assert result is True, "Test case {} : Failed \n Error: {}".format( | |
1079 | tc_name, result | |
1080 | ) | |
85d47773 AP |
1081 | |
1082 | write_test_footer(tc_name) | |
1083 | ||
1084 | ||
1085 | def test_large_community_boundary_values(request): | |
1086 | """ | |
1087 | Verify that any value in BGP Large communities for boundary values. | |
1088 | """ | |
1089 | tc_name = request.node.name | |
1090 | write_test_header(tc_name) | |
1091 | tgen = get_topogen() | |
1092 | ||
1093 | # Don"t run this test if we have any failure. | |
1094 | if tgen.routers_have_failure(): | |
1095 | pytest.skip(tgen.errors) | |
1096 | ||
1097 | input_dict = { | |
1098 | "r4": { | |
1099 | "bgp_community_lists": [ | |
1100 | { | |
1101 | "community_type": "standard", | |
1102 | "action": "permit", | |
1103 | "name": "ANY", | |
787e7624 | 1104 | "value": "0:-1", |
85d47773 AP |
1105 | } |
1106 | ] | |
1107 | } | |
1108 | } | |
1109 | ||
1110 | step("Checking boundary value for community 0:-1") | |
1111 | result = create_bgp_community_lists(tgen, input_dict) | |
787e7624 | 1112 | assert result is not True, "Test case {} : Failed \n Error: {}".format( |
1113 | tc_name, result | |
1114 | ) | |
85d47773 AP |
1115 | |
1116 | step("Checking community attribute 0:65536") | |
1117 | input_dict_2 = { | |
1118 | "r4": { | |
1119 | "bgp_community_lists": [ | |
1120 | { | |
1121 | "community_type": "standard", | |
1122 | "action": "permit", | |
1123 | "name": "ANY", | |
787e7624 | 1124 | "value": "0:65536", |
85d47773 AP |
1125 | } |
1126 | ] | |
1127 | } | |
1128 | } | |
1129 | ||
1130 | step("Checking boundary value for community 0:65536") | |
1131 | result = create_bgp_community_lists(tgen, input_dict_2) | |
787e7624 | 1132 | assert result is not True, "Test case {} : Failed \n Error: {}".format( |
1133 | tc_name, result | |
1134 | ) | |
85d47773 AP |
1135 | |
1136 | step("Checking boundary value for community 0:4294967296") | |
1137 | input_dict_3 = { | |
1138 | "r4": { | |
1139 | "bgp_community_lists": [ | |
1140 | { | |
1141 | "community_type": "standard", | |
1142 | "action": "permit", | |
1143 | "name": "ANY", | |
1144 | "value": "0:4294967296", | |
787e7624 | 1145 | "large": True, |
85d47773 AP |
1146 | } |
1147 | ] | |
1148 | } | |
1149 | } | |
1150 | ||
1151 | result = create_bgp_community_lists(tgen, input_dict_3) | |
787e7624 | 1152 | assert result is not True, "Test case {} : Failed \n Error: {}".format( |
1153 | tc_name, result | |
1154 | ) | |
85d47773 AP |
1155 | step("Checking boundary value for community 0:-1:1") |
1156 | ||
1157 | input_dict_4 = { | |
1158 | "r4": { | |
1159 | "bgp_community_lists": [ | |
1160 | { | |
1161 | "community_type": "standard", | |
1162 | "action": "permit", | |
1163 | "name": "ANY", | |
1164 | "value": "0:-1:1", | |
787e7624 | 1165 | "large": True, |
85d47773 AP |
1166 | } |
1167 | ] | |
1168 | } | |
1169 | } | |
1170 | ||
1171 | result = create_bgp_community_lists(tgen, input_dict_4) | |
787e7624 | 1172 | assert result is not True, "Test case {} : Failed \n Error: {}".format( |
1173 | tc_name, result | |
1174 | ) | |
85d47773 AP |
1175 | |
1176 | ||
c850908b WC |
1177 | def test_large_community_invalid_chars(request): |
1178 | """ | |
1179 | BGP canonical lcommunities must only be digits | |
1180 | """ | |
1181 | tc_name = request.node.name | |
1182 | write_test_header(tc_name) | |
1183 | tgen = get_topogen() | |
1184 | ||
1185 | # Don"t run this test if we have any failure. | |
1186 | if tgen.routers_have_failure(): | |
1187 | pytest.skip(tgen.errors) | |
1188 | ||
1189 | input_dict = { | |
1190 | "r4": { | |
1191 | "bgp_community_lists": [ | |
1192 | { | |
1193 | "community_type": "standard", | |
1194 | "action": "permit", | |
1195 | "name": "ANY", | |
1196 | "value": "1:a:2", | |
1197 | "large": True, | |
1198 | } | |
1199 | ] | |
1200 | } | |
1201 | } | |
1202 | ||
1203 | step("Checking boundary value for community 1:a:2") | |
1204 | result = create_bgp_community_lists(tgen, input_dict) | |
1205 | assert result is not True, "Test case {} : Failed \n Error: {}".format( | |
1206 | tc_name, result | |
1207 | ) | |
1208 | ||
1209 | ||
85d47773 AP |
1210 | def test_large_community_after_clear_bgp(request): |
1211 | """ | |
1212 | Clear BGP neighbor-ship and check if large community and community | |
1213 | attributes are getting re-populated. | |
1214 | """ | |
1215 | tc_name = request.node.name | |
1216 | write_test_header(tc_name) | |
1217 | tgen = get_topogen() | |
1218 | ||
1219 | # Don"t run this test if we have any failure. | |
1220 | if tgen.routers_have_failure(): | |
1221 | pytest.skip(tgen.errors) | |
1222 | ||
1223 | reset_config_on_routers(tgen) | |
1224 | config_router_r1(tgen, topo, tc_name) | |
1225 | ||
787e7624 | 1226 | input_dict = {"largeCommunity": LARGE_COMM["r1"], "community": STANDARD_COMM["r1"]} |
85d47773 AP |
1227 | |
1228 | for adt in ADDR_TYPES: | |
787e7624 | 1229 | result = verify_bgp_community(tgen, adt, "r2", [NETWORK[adt][0]], input_dict) |
1230 | assert result is True, "Test case {} : Failed \n Error: {}".format( | |
1231 | tc_name, result | |
1232 | ) | |
85d47773 AP |
1233 | |
1234 | step("Clearing BGP on r1") | |
1235 | clear_bgp_and_verify(tgen, topo, "r1") | |
1236 | ||
1237 | for adt in ADDR_TYPES: | |
787e7624 | 1238 | result = verify_bgp_community(tgen, adt, "r2", [NETWORK[adt][0]], input_dict) |
1239 | assert result is True, "Test case {} : Failed \n Error: {}".format( | |
1240 | tc_name, result | |
1241 | ) | |
85d47773 AP |
1242 | |
1243 | write_test_footer(tc_name) | |
1244 | ||
1245 | ||
1246 | if __name__ == "__main__": | |
1247 | args = ["-s"] + sys.argv[1:] | |
1248 | sys.exit(pytest.main(args)) |