]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/env python3 | |
2 | # SPDX-License-Identifier: ISC | |
3 | # | |
4 | # Copyright (c) 2022 by VMware, Inc. ("VMware") | |
5 | # Used Copyright (c) 2018 by Network Device Education Foundation, | |
6 | # Inc. ("NetDEF") in this file. | |
7 | # | |
8 | ||
9 | """ | |
10 | 1. Verify the BGP Local AS functionality by adding new AS when dynamically import routes | |
11 | from default vrf to non-default vrf with route map by adding AS by as-prepend command. | |
12 | 2. Verify the BGP Local AS functionality by adding new AS when dynamically import routes | |
13 | from non-default vrf to default vrf and further advertised to eBGP peers. | |
14 | """ | |
15 | ||
16 | import os | |
17 | import sys | |
18 | import time | |
19 | import pytest | |
20 | ||
21 | # Save the Current Working Directory to find configuration files. | |
22 | CWD = os.path.dirname(os.path.realpath(__file__)) | |
23 | sys.path.append(os.path.join(CWD, "../")) | |
24 | sys.path.append(os.path.join(CWD, "../lib/")) | |
25 | ||
26 | # pylint: disable=C0413 | |
27 | # Import topogen and topotest helpers | |
28 | from lib.topogen import Topogen, get_topogen | |
29 | from lib.topotest import version_cmp | |
30 | ||
31 | from lib.common_config import ( | |
32 | start_topology, | |
33 | write_test_header, | |
34 | create_static_routes, | |
35 | write_test_footer, | |
36 | reset_config_on_routers, | |
37 | verify_rib, | |
38 | step, | |
39 | check_address_types, | |
40 | check_router_status, | |
41 | create_static_routes, | |
42 | verify_fib_routes, | |
43 | create_route_maps, | |
44 | ) | |
45 | ||
46 | from lib.topolog import logger | |
47 | from lib.bgp import ( | |
48 | verify_bgp_convergence, | |
49 | verify_bgp_rib, | |
50 | create_router_bgp, | |
51 | ) | |
52 | from lib.topojson import build_config_from_json | |
53 | ||
54 | pytestmark = [pytest.mark.bgpd, pytest.mark.staticd] | |
55 | ||
56 | # Global variables | |
57 | BGP_CONVERGENCE = False | |
58 | ADDR_TYPES = check_address_types() | |
59 | NETWORK = {"ipv4": "10.1.1.0/32", "ipv6": "10:1::1:0/128"} | |
60 | NEXT_HOP_IP = {"ipv4": "Null0", "ipv6": "Null0"} | |
61 | ||
62 | ||
63 | def setup_module(mod): | |
64 | """ | |
65 | Sets up the pytest environment | |
66 | ||
67 | * `mod`: module name | |
68 | """ | |
69 | ||
70 | testsuite_run_time = time.asctime(time.localtime(time.time())) | |
71 | logger.info("Testsuite start time: {}".format(testsuite_run_time)) | |
72 | logger.info("=" * 40) | |
73 | ||
74 | logger.info("Running setup_module to create topology") | |
75 | ||
76 | # This function initiates the topology build with Topogen... | |
77 | json_file = "{}/bgp_local_asn_vrf_topo1.json".format(CWD) | |
78 | tgen = Topogen(json_file, mod.__name__) | |
79 | global topo | |
80 | topo = tgen.json_topo | |
81 | # ... and here it calls Mininet initialization functions. | |
82 | ||
83 | # Starting topology, create tmp files which are loaded to routers | |
84 | # to start daemons and then start routers | |
85 | start_topology(tgen) | |
86 | ||
87 | # Creating configuration from JSON | |
88 | build_config_from_json(tgen, topo) | |
89 | ||
90 | global BGP_CONVERGENCE | |
91 | global ADDR_TYPES | |
92 | ADDR_TYPES = check_address_types() | |
93 | ||
94 | BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo) | |
95 | assert BGP_CONVERGENCE is True, "setup_module : Failed \n Error: {}".format( | |
96 | BGP_CONVERGENCE | |
97 | ) | |
98 | ||
99 | logger.info("Running setup_module() done") | |
100 | ||
101 | ||
102 | def teardown_module(): | |
103 | """Teardown the pytest environment""" | |
104 | ||
105 | logger.info("Running teardown_module to delete topology") | |
106 | ||
107 | tgen = get_topogen() | |
108 | ||
109 | # Stop toplogy and Remove tmp files | |
110 | tgen.stop_topology() | |
111 | ||
112 | logger.info( | |
113 | "Testsuite end time: {}".format(time.asctime(time.localtime(time.time()))) | |
114 | ) | |
115 | logger.info("=" * 40) | |
116 | ||
117 | ||
118 | ################################################################################################ | |
119 | # | |
120 | # Testcases | |
121 | # | |
122 | ############################################################################################### | |
123 | ||
124 | ||
125 | def test_verify_local_asn_ipv4_import_from_default_to_non_default_VRF_p0(request): | |
126 | """ | |
127 | Verify the BGP Local AS functionality by adding new AS when dynamically import routes | |
128 | from default vrf to non-default vrf with route map by adding AS by as-prepend command. | |
129 | """ | |
130 | tgen = get_topogen() | |
131 | global BGP_CONVERGENCE | |
132 | if BGP_CONVERGENCE != True: | |
133 | pytest.skip("skipped because of BGP Convergence failure") | |
134 | ||
135 | # test case name | |
136 | tc_name = request.node.name | |
137 | write_test_header(tc_name) | |
138 | if tgen.routers_have_failure(): | |
139 | check_router_status(tgen) | |
140 | reset_config_on_routers(tgen) | |
141 | ||
142 | step("Base config is done as part of JSON") | |
143 | ||
144 | # configure static routes | |
145 | step("Advertise prefix 10.0.0.1/32 from Router-1(AS-100).") | |
146 | step("Advertise an ipv6 prefix 10::1/128 from Router-1(AS-100).") | |
147 | dut = "r2" | |
148 | for addr_type in ADDR_TYPES: | |
149 | # Enable static routes | |
150 | input_dict_static_route = { | |
151 | "r2": { | |
152 | "static_routes": [ | |
153 | {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]} | |
154 | ] | |
155 | } | |
156 | } | |
157 | ||
158 | logger.info("Configure static routes") | |
159 | result = create_static_routes(tgen, input_dict_static_route) | |
160 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
161 | tc_name, result | |
162 | ) | |
163 | ||
164 | step("configure redistribute static in Router BGP in R2") | |
165 | input_dict_static_route_redist = { | |
166 | "r2": { | |
167 | "bgp": [ | |
168 | { | |
169 | "address_family": { | |
170 | addr_type: { | |
171 | "unicast": {"redistribute": [{"redist_type": "static"}]} | |
172 | } | |
173 | } | |
174 | } | |
175 | ] | |
176 | } | |
177 | } | |
178 | result = create_router_bgp(tgen, topo, input_dict_static_route_redist) | |
179 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
180 | tc_name, result | |
181 | ) | |
182 | ||
183 | step("Configure import vrf BLUE on R3 under IPv4 Address Family") | |
184 | input_import_vrf_ipv4 = { | |
185 | "r3": { | |
186 | "bgp": [ | |
187 | { | |
188 | "local_as": 300, | |
189 | "vrf": "BLUE", | |
190 | "address_family": { | |
191 | "ipv4": {"unicast": {"import": {"vrf": "default"}}}, | |
192 | "ipv6": {"unicast": {"import": {"vrf": "default"}}}, | |
193 | }, | |
194 | } | |
195 | ] | |
196 | } | |
197 | } | |
198 | result = create_router_bgp(tgen, topo, input_import_vrf_ipv4) | |
199 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
200 | ||
201 | step("Verify IPv4 and IPv6 static routes received on R2") | |
202 | for addr_type in ADDR_TYPES: | |
203 | input_dict_static_route = { | |
204 | "r2": { | |
205 | "static_routes": [ | |
206 | {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]} | |
207 | ] | |
208 | } | |
209 | } | |
210 | result = verify_rib(tgen, addr_type, "r2", input_dict_static_route) | |
211 | assert result is True, "Testcase {}: Failed \n Error: {}".format( | |
212 | tc_name, result | |
213 | ) | |
214 | result = verify_bgp_rib(tgen, addr_type, "r2", input_dict_static_route) | |
215 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
216 | tc_name, result | |
217 | ) | |
218 | result = verify_fib_routes(tgen, addr_type, "r2", input_dict_static_route) | |
219 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
220 | tc_name, result | |
221 | ) | |
222 | ||
223 | step("Configure local-as at R3 towards R2.") | |
224 | for addr_type in ADDR_TYPES: | |
225 | input_dict_r3_to_r2 = { | |
226 | "r3": { | |
227 | "bgp": [ | |
228 | { | |
229 | "local_as": "300", | |
230 | "address_family": { | |
231 | addr_type: { | |
232 | "unicast": { | |
233 | "neighbor": { | |
234 | "r2": { | |
235 | "dest_link": { | |
236 | "r3": {"local_asn": {"local_as": "110"}} | |
237 | } | |
238 | } | |
239 | } | |
240 | } | |
241 | } | |
242 | }, | |
243 | } | |
244 | ] | |
245 | } | |
246 | } | |
247 | result = create_router_bgp(tgen, topo, input_dict_r3_to_r2) | |
248 | assert result is True, "Testcase {} :Failed \n Error: {}".format( | |
249 | tc_name, result | |
250 | ) | |
251 | ||
252 | step("Configure local-as at R3 towards R4.") | |
253 | for addr_type in ADDR_TYPES: | |
254 | input_dict_r3_to_r4 = { | |
255 | "r3": { | |
256 | "bgp": [ | |
257 | { | |
258 | "local_as": "300", | |
259 | "vrf": "BLUE", | |
260 | "address_family": { | |
261 | addr_type: { | |
262 | "unicast": { | |
263 | "neighbor": { | |
264 | "r4": { | |
265 | "dest_link": { | |
266 | "r3": {"local_asn": {"local_as": "110"}} | |
267 | } | |
268 | } | |
269 | } | |
270 | } | |
271 | } | |
272 | }, | |
273 | } | |
274 | ] | |
275 | } | |
276 | } | |
277 | result = create_router_bgp(tgen, topo, input_dict_r3_to_r4) | |
278 | assert result is True, "Testcase {} :Failed \n Error: {}".format( | |
279 | tc_name, result | |
280 | ) | |
281 | ||
282 | step("Configure remote-as at R2 towards R3.") | |
283 | for addr_type in ADDR_TYPES: | |
284 | input_dict_r2_to_r3 = { | |
285 | "r2": { | |
286 | "bgp": [ | |
287 | { | |
288 | "local_as": "200", | |
289 | "address_family": { | |
290 | addr_type: { | |
291 | "unicast": { | |
292 | "neighbor": { | |
293 | "r3": { | |
294 | "dest_link": { | |
295 | "r2": { | |
296 | "local_asn": {"remote_as": "110"} | |
297 | } | |
298 | } | |
299 | } | |
300 | } | |
301 | } | |
302 | } | |
303 | }, | |
304 | } | |
305 | ] | |
306 | } | |
307 | } | |
308 | result = create_router_bgp(tgen, topo, input_dict_r2_to_r3) | |
309 | assert result is True, "Testcase {} :Failed \n Error: {}".format( | |
310 | tc_name, result | |
311 | ) | |
312 | ||
313 | step("Configure remote-as at R4 towards R3.") | |
314 | for addr_type in ADDR_TYPES: | |
315 | input_dict_r4_to_r3 = { | |
316 | "r4": { | |
317 | "bgp": [ | |
318 | { | |
319 | "local_as": "400", | |
320 | "vrf": "BLUE", | |
321 | "address_family": { | |
322 | addr_type: { | |
323 | "unicast": { | |
324 | "neighbor": { | |
325 | "r3": { | |
326 | "dest_link": { | |
327 | "r4": { | |
328 | "local_asn": {"remote_as": "110"} | |
329 | } | |
330 | } | |
331 | } | |
332 | } | |
333 | } | |
334 | } | |
335 | }, | |
336 | } | |
337 | ] | |
338 | } | |
339 | } | |
340 | result = create_router_bgp(tgen, topo, input_dict_r4_to_r3) | |
341 | assert result is True, "Testcase {} :Failed \n Error: {}".format( | |
342 | tc_name, result | |
343 | ) | |
344 | ||
345 | step("BGP neighborship is verified by following commands in R3 routers") | |
346 | BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo) | |
347 | assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format( | |
348 | BGP_CONVERGENCE | |
349 | ) | |
350 | ||
351 | step("Verify IPv4 and IPv6 static routes received on R3 VRF BLUE & R4 VRF BLUE") | |
352 | for addr_type in ADDR_TYPES: | |
353 | static_routes_input = { | |
354 | "r2": { | |
355 | "static_routes": [ | |
356 | { | |
357 | "network": NETWORK[addr_type], | |
358 | "next_hop": NEXT_HOP_IP[addr_type], | |
359 | "vrf": "BLUE", | |
360 | } | |
361 | ] | |
362 | } | |
363 | } | |
364 | for dut in ["r3", "r4"]: | |
365 | result = verify_fib_routes(tgen, addr_type, dut, static_routes_input) | |
366 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
367 | tc_name, result | |
368 | ) | |
369 | ||
370 | result = verify_bgp_rib(tgen, addr_type, dut, static_routes_input) | |
371 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
372 | tc_name, result | |
373 | ) | |
374 | ||
375 | step( | |
376 | "Verify that AS-110 is got added in the AS list 110 200 100 by following " | |
377 | " commands at R3 router." | |
378 | ) | |
379 | dut = "r3" | |
380 | aspath = "110 200" | |
381 | for addr_type in ADDR_TYPES: | |
382 | input_static_r2 = { | |
383 | "r2": {"static_routes": [{"network": NETWORK[addr_type], "vrf": "BLUE"}]} | |
384 | } | |
385 | result = verify_bgp_rib(tgen, addr_type, dut, input_static_r2, aspath=aspath) | |
386 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
387 | tc_name, result | |
388 | ) | |
389 | ||
390 | step("Configure a route-map on R3 to prepend AS 2 times.") | |
391 | for addr_type in ADDR_TYPES: | |
392 | input_dict_4 = { | |
393 | "r3": { | |
394 | "route_maps": { | |
395 | "ASP_{}".format(addr_type): [ | |
396 | { | |
397 | "action": "permit", | |
398 | "set": { | |
399 | "path": {"as_num": "1000 1000", "as_action": "prepend"} | |
400 | }, | |
401 | } | |
402 | ] | |
403 | } | |
404 | } | |
405 | } | |
406 | result = create_route_maps(tgen, input_dict_4) | |
407 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
408 | tc_name, result | |
409 | ) | |
410 | ||
411 | step("configure route map in out direction on R4") | |
412 | # Configure neighbor for route map | |
413 | input_dict_7 = { | |
414 | "r3": { | |
415 | "bgp": { | |
416 | "local_as": "300", | |
417 | "vrf": "BLUE", | |
418 | "address_family": { | |
419 | addr_type: { | |
420 | "unicast": { | |
421 | "neighbor": { | |
422 | "r4": { | |
423 | "dest_link": { | |
424 | "r3": { | |
425 | "route_maps": [ | |
426 | { | |
427 | "name": "ASP_{}".format( | |
428 | addr_type | |
429 | ), | |
430 | "direction": "out", | |
431 | } | |
432 | ] | |
433 | } | |
434 | } | |
435 | } | |
436 | } | |
437 | } | |
438 | } | |
439 | }, | |
440 | } | |
441 | } | |
442 | } | |
443 | ||
444 | result = create_router_bgp(tgen, topo, input_dict_7) | |
445 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
446 | tc_name, result | |
447 | ) | |
448 | ||
449 | step("Configure local-as with no-prepend at R3 towards R2.") | |
450 | for addr_type in ADDR_TYPES: | |
451 | input_dict_no_prep_r3_to_r2 = { | |
452 | "r3": { | |
453 | "bgp": [ | |
454 | { | |
455 | "local_as": "300", | |
456 | "address_family": { | |
457 | addr_type: { | |
458 | "unicast": { | |
459 | "neighbor": { | |
460 | "r2": { | |
461 | "dest_link": { | |
462 | "r3": { | |
463 | "local_asn": { | |
464 | "local_as": "110", | |
465 | "no_prepend": True, | |
466 | } | |
467 | } | |
468 | } | |
469 | } | |
470 | } | |
471 | } | |
472 | } | |
473 | }, | |
474 | } | |
475 | ] | |
476 | } | |
477 | } | |
478 | result = create_router_bgp(tgen, topo, input_dict_no_prep_r3_to_r2) | |
479 | assert result is True, "Testcase {} :Failed \n Error: {}".format( | |
480 | tc_name, result | |
481 | ) | |
482 | ||
483 | step("Configure local-as with no-prepend at R3 towards R4.") | |
484 | for addr_type in ADDR_TYPES: | |
485 | input_dict_no_prep_r3_to_r4 = { | |
486 | "r3": { | |
487 | "bgp": [ | |
488 | { | |
489 | "local_as": "300", | |
490 | "vrf": "BLUE", | |
491 | "address_family": { | |
492 | addr_type: { | |
493 | "unicast": { | |
494 | "neighbor": { | |
495 | "r4": { | |
496 | "dest_link": { | |
497 | "r3": { | |
498 | "local_asn": { | |
499 | "local_as": "110", | |
500 | "no_prepend": True, | |
501 | } | |
502 | } | |
503 | } | |
504 | } | |
505 | } | |
506 | } | |
507 | } | |
508 | }, | |
509 | } | |
510 | ] | |
511 | } | |
512 | } | |
513 | result = create_router_bgp(tgen, topo, input_dict_no_prep_r3_to_r4) | |
514 | assert result is True, "Testcase {} :Failed \n Error: {}".format( | |
515 | tc_name, result | |
516 | ) | |
517 | ||
518 | step("BGP neighborship is verified by following commands in R3 routers") | |
519 | BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo) | |
520 | assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format( | |
521 | BGP_CONVERGENCE | |
522 | ) | |
523 | ||
524 | dut = "r3" | |
525 | aspath = "200" | |
526 | for addr_type in ADDR_TYPES: | |
527 | input_static_r2 = { | |
528 | "r2": {"static_routes": [{"network": NETWORK[addr_type], "vrf": "BLUE"}]} | |
529 | } | |
530 | result = verify_bgp_rib(tgen, addr_type, dut, input_static_r2, aspath=aspath) | |
531 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
532 | tc_name, result | |
533 | ) | |
534 | ||
535 | step("Configure local-as with no-prepend and replace-as at R3 towards R2") | |
536 | for addr_type in ADDR_TYPES: | |
537 | input_dict_no_prep_rep_as_r3_to_r2 = { | |
538 | "r3": { | |
539 | "bgp": [ | |
540 | { | |
541 | "local_as": "300", | |
542 | "address_family": { | |
543 | addr_type: { | |
544 | "unicast": { | |
545 | "neighbor": { | |
546 | "r2": { | |
547 | "dest_link": { | |
548 | "r3": { | |
549 | "local_asn": { | |
550 | "local_as": "110", | |
551 | "no_prepend": True, | |
552 | "replace_as": True, | |
553 | } | |
554 | } | |
555 | } | |
556 | } | |
557 | } | |
558 | } | |
559 | } | |
560 | }, | |
561 | } | |
562 | ] | |
563 | } | |
564 | } | |
565 | result = create_router_bgp(tgen, topo, input_dict_no_prep_rep_as_r3_to_r2) | |
566 | assert result is True, "Testcase {} :Failed \n Error: {}".format( | |
567 | tc_name, result | |
568 | ) | |
569 | ||
570 | step("Configure local-as with no-prepend and replace-as at R3 towards R4") | |
571 | for addr_type in ADDR_TYPES: | |
572 | input_dict_no_prep_rep_as_r3_to_r4 = { | |
573 | "r3": { | |
574 | "bgp": [ | |
575 | { | |
576 | "local_as": "300", | |
577 | "vrf": "BLUE", | |
578 | "address_family": { | |
579 | addr_type: { | |
580 | "unicast": { | |
581 | "neighbor": { | |
582 | "r4": { | |
583 | "dest_link": { | |
584 | "r3": { | |
585 | "local_asn": { | |
586 | "local_as": "110", | |
587 | "no_prepend": True, | |
588 | "replace_as": True, | |
589 | } | |
590 | } | |
591 | } | |
592 | } | |
593 | } | |
594 | } | |
595 | } | |
596 | }, | |
597 | } | |
598 | ] | |
599 | } | |
600 | } | |
601 | result = create_router_bgp(tgen, topo, input_dict_no_prep_rep_as_r3_to_r4) | |
602 | assert result is True, "Testcase {} :Failed \n Error: {}".format( | |
603 | tc_name, result | |
604 | ) | |
605 | ||
606 | step("BGP neighborship is verified by following commands in R3 routers") | |
607 | BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo) | |
608 | assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format( | |
609 | BGP_CONVERGENCE | |
610 | ) | |
611 | ||
612 | dut = "r4" | |
613 | aspath = "110 1000 1000 200" | |
614 | for addr_type in ADDR_TYPES: | |
615 | input_static_r2 = { | |
616 | "r2": {"static_routes": [{"network": NETWORK[addr_type], "vrf": "BLUE"}]} | |
617 | } | |
618 | result = verify_bgp_rib(tgen, addr_type, dut, input_static_r2, aspath=aspath) | |
619 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
620 | tc_name, result | |
621 | ) | |
622 | ||
623 | write_test_footer(tc_name) | |
624 | ||
625 | ||
626 | def test_verify_local_asn_ipv4_import_from_non_default_to_default_VRF_p0(request): | |
627 | """ | |
628 | Verify the BGP Local AS functionality by adding new AS when dynamically import routes | |
629 | from non-default vrf to default vrf and further advertised to eBGP peers. | |
630 | """ | |
631 | tgen = get_topogen() | |
632 | global BGP_CONVERGENCE | |
633 | if BGP_CONVERGENCE != True: | |
634 | pytest.skip("skipped because of BGP Convergence failure") | |
635 | ||
636 | # test case name | |
637 | tc_name = request.node.name | |
638 | write_test_header(tc_name) | |
639 | if tgen.routers_have_failure(): | |
640 | check_router_status(tgen) | |
641 | reset_config_on_routers(tgen) | |
642 | ||
643 | step("Resetting the config from JSON") | |
644 | reset_config_on_routers(tgen) | |
645 | ||
646 | step("Base config is done as part of JSON") | |
647 | # configure static routes | |
648 | step("Advertise prefix 10.0.0.1/32 from Router-1(AS-100).") | |
649 | step("Advertise an ipv6 prefix 10::1/128 from Router-1(AS-100).") | |
650 | dut = "r4" | |
651 | for addr_type in ADDR_TYPES: | |
652 | # Enable static routes | |
653 | input_dict_static_route = { | |
654 | "r4": { | |
655 | "static_routes": [ | |
656 | { | |
657 | "network": NETWORK[addr_type], | |
658 | "next_hop": NEXT_HOP_IP[addr_type], | |
659 | "vrf": "BLUE", | |
660 | } | |
661 | ] | |
662 | } | |
663 | } | |
664 | ||
665 | logger.info("Configure static routes") | |
666 | result = create_static_routes(tgen, input_dict_static_route) | |
667 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
668 | tc_name, result | |
669 | ) | |
670 | ||
671 | step("configure redistribute static in Router BGP in R4") | |
672 | input_dict_static_route_redist = { | |
673 | "r4": { | |
674 | "bgp": { | |
675 | "local_as": 400, | |
676 | "vrf": "BLUE", | |
677 | "address_family": { | |
678 | "ipv4": { | |
679 | "unicast": { | |
680 | "redistribute": [ | |
681 | {"redist_type": "static"}, | |
682 | {"redist_type": "connected"}, | |
683 | ] | |
684 | } | |
685 | }, | |
686 | "ipv6": { | |
687 | "unicast": { | |
688 | "redistribute": [ | |
689 | {"redist_type": "static"}, | |
690 | {"redist_type": "connected"}, | |
691 | ] | |
692 | } | |
693 | }, | |
694 | }, | |
695 | } | |
696 | } | |
697 | } | |
698 | result = create_router_bgp(tgen, topo, input_dict_static_route_redist) | |
699 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
700 | ||
701 | step( | |
702 | "Configure import from BLUE vrf to default vrf on R3 under IPv4 Address Family" | |
703 | ) | |
704 | input_import_vrf_ipv4 = { | |
705 | "r3": { | |
706 | "bgp": [ | |
707 | { | |
708 | "local_as": 300, | |
709 | "vrf": "default", | |
710 | "address_family": { | |
711 | "ipv4": {"unicast": {"import": {"vrf": "BLUE"}}}, | |
712 | "ipv6": {"unicast": {"import": {"vrf": "BLUE"}}}, | |
713 | }, | |
714 | } | |
715 | ] | |
716 | } | |
717 | } | |
718 | result = create_router_bgp(tgen, topo, input_import_vrf_ipv4) | |
719 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
720 | ||
721 | step("Verify IPv4 and IPv6 static routes received on R3 VRF BLUE & R4 VRF BLUE") | |
722 | for addr_type in ADDR_TYPES: | |
723 | static_routes_input = { | |
724 | "r4": { | |
725 | "static_routes": [ | |
726 | { | |
727 | "network": NETWORK[addr_type], | |
728 | "next_hop": NEXT_HOP_IP[addr_type], | |
729 | "vrf": "BLUE", | |
730 | } | |
731 | ] | |
732 | } | |
733 | } | |
734 | for dut in ["r3", "r4"]: | |
735 | result = verify_fib_routes(tgen, addr_type, dut, static_routes_input) | |
736 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
737 | tc_name, result | |
738 | ) | |
739 | ||
740 | result = verify_bgp_rib(tgen, addr_type, dut, static_routes_input) | |
741 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
742 | tc_name, result | |
743 | ) | |
744 | ||
745 | step("Configure local-as at R3 towards R2.") | |
746 | for addr_type in ADDR_TYPES: | |
747 | input_dict_r3_to_r2 = { | |
748 | "r3": { | |
749 | "bgp": [ | |
750 | { | |
751 | "local_as": "300", | |
752 | "address_family": { | |
753 | addr_type: { | |
754 | "unicast": { | |
755 | "neighbor": { | |
756 | "r2": { | |
757 | "dest_link": { | |
758 | "r3": {"local_asn": {"local_as": "110"}} | |
759 | } | |
760 | } | |
761 | } | |
762 | } | |
763 | } | |
764 | }, | |
765 | } | |
766 | ] | |
767 | } | |
768 | } | |
769 | result = create_router_bgp(tgen, topo, input_dict_r3_to_r2) | |
770 | assert result is True, "Testcase {} :Failed \n Error: {}".format( | |
771 | tc_name, result | |
772 | ) | |
773 | ||
774 | step("Configure local-as at R3 towards R4.") | |
775 | for addr_type in ADDR_TYPES: | |
776 | input_dict_r3_to_r4 = { | |
777 | "r3": { | |
778 | "bgp": [ | |
779 | { | |
780 | "local_as": "300", | |
781 | "vrf": "BLUE", | |
782 | "address_family": { | |
783 | addr_type: { | |
784 | "unicast": { | |
785 | "neighbor": { | |
786 | "r4": { | |
787 | "dest_link": { | |
788 | "r3": {"local_asn": {"local_as": "110"}} | |
789 | } | |
790 | } | |
791 | } | |
792 | } | |
793 | } | |
794 | }, | |
795 | } | |
796 | ] | |
797 | } | |
798 | } | |
799 | result = create_router_bgp(tgen, topo, input_dict_r3_to_r4) | |
800 | assert result is True, "Testcase {} :Failed \n Error: {}".format( | |
801 | tc_name, result | |
802 | ) | |
803 | ||
804 | step("Configure remote-as at R2 towards R3.") | |
805 | for addr_type in ADDR_TYPES: | |
806 | input_dict_r2_to_r3 = { | |
807 | "r2": { | |
808 | "bgp": [ | |
809 | { | |
810 | "local_as": "200", | |
811 | "address_family": { | |
812 | addr_type: { | |
813 | "unicast": { | |
814 | "neighbor": { | |
815 | "r3": { | |
816 | "dest_link": { | |
817 | "r2": { | |
818 | "local_asn": {"remote_as": "110"} | |
819 | } | |
820 | } | |
821 | } | |
822 | } | |
823 | } | |
824 | } | |
825 | }, | |
826 | } | |
827 | ] | |
828 | } | |
829 | } | |
830 | result = create_router_bgp(tgen, topo, input_dict_r2_to_r3) | |
831 | assert result is True, "Testcase {} :Failed \n Error: {}".format( | |
832 | tc_name, result | |
833 | ) | |
834 | ||
835 | step("Configure remote-as at R4 towards R3.") | |
836 | for addr_type in ADDR_TYPES: | |
837 | input_dict_r4_to_r3 = { | |
838 | "r4": { | |
839 | "bgp": [ | |
840 | { | |
841 | "local_as": "400", | |
842 | "vrf": "BLUE", | |
843 | "address_family": { | |
844 | addr_type: { | |
845 | "unicast": { | |
846 | "neighbor": { | |
847 | "r3": { | |
848 | "dest_link": { | |
849 | "r4": { | |
850 | "local_asn": {"remote_as": "110"} | |
851 | } | |
852 | } | |
853 | } | |
854 | } | |
855 | } | |
856 | } | |
857 | }, | |
858 | } | |
859 | ] | |
860 | } | |
861 | } | |
862 | result = create_router_bgp(tgen, topo, input_dict_r4_to_r3) | |
863 | assert result is True, "Testcase {} :Failed \n Error: {}".format( | |
864 | tc_name, result | |
865 | ) | |
866 | ||
867 | step("BGP neighborship is verified by following commands in R3 routers") | |
868 | BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo) | |
869 | assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format( | |
870 | BGP_CONVERGENCE | |
871 | ) | |
872 | ||
873 | step("Verify IPv4 and IPv6 static routes received on R2") | |
874 | for addr_type in ADDR_TYPES: | |
875 | input_dict_static_route_from_r4 = { | |
876 | "r4": { | |
877 | "static_routes": [ | |
878 | { | |
879 | "network": NETWORK[addr_type], | |
880 | "next_hop": NEXT_HOP_IP[addr_type], | |
881 | } | |
882 | ] | |
883 | } | |
884 | } | |
885 | result = verify_rib(tgen, addr_type, "r2", input_dict_static_route_from_r4) | |
886 | assert result is True, "Testcase {}: Failed \n Error: {}".format( | |
887 | tc_name, result | |
888 | ) | |
889 | result = verify_bgp_rib(tgen, addr_type, "r2", input_dict_static_route_from_r4) | |
890 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
891 | tc_name, result | |
892 | ) | |
893 | result = verify_fib_routes( | |
894 | tgen, addr_type, "r2", input_dict_static_route_from_r4 | |
895 | ) | |
896 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
897 | tc_name, result | |
898 | ) | |
899 | ||
900 | step( | |
901 | "Verify that AS-110 is got added in the AS list 110 400 by following " | |
902 | " commands at R3 router." | |
903 | ) | |
904 | dut = "r3" | |
905 | aspath = "110 400" | |
906 | for addr_type in ADDR_TYPES: | |
907 | input_static_r2 = {"r4": {"static_routes": [{"network": NETWORK[addr_type]}]}} | |
908 | result = verify_bgp_rib(tgen, addr_type, dut, input_static_r2, aspath=aspath) | |
909 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
910 | tc_name, result | |
911 | ) | |
912 | ||
913 | step("Configure local-as with no-prepend at R3 towards R2.") | |
914 | for addr_type in ADDR_TYPES: | |
915 | input_dict_no_prep_r3_to_r2 = { | |
916 | "r3": { | |
917 | "bgp": [ | |
918 | { | |
919 | "local_as": "300", | |
920 | "address_family": { | |
921 | addr_type: { | |
922 | "unicast": { | |
923 | "neighbor": { | |
924 | "r2": { | |
925 | "dest_link": { | |
926 | "r3": { | |
927 | "local_asn": { | |
928 | "local_as": "110", | |
929 | "no_prepend": True, | |
930 | } | |
931 | } | |
932 | } | |
933 | } | |
934 | } | |
935 | } | |
936 | } | |
937 | }, | |
938 | } | |
939 | ] | |
940 | } | |
941 | } | |
942 | result = create_router_bgp(tgen, topo, input_dict_no_prep_r3_to_r2) | |
943 | assert result is True, "Testcase {} :Failed \n Error: {}".format( | |
944 | tc_name, result | |
945 | ) | |
946 | ||
947 | step("Configure local-as with no-prepend at R3 towards R4.") | |
948 | for addr_type in ADDR_TYPES: | |
949 | input_dict_no_prep_r3_to_r4 = { | |
950 | "r3": { | |
951 | "bgp": [ | |
952 | { | |
953 | "local_as": "300", | |
954 | "vrf": "BLUE", | |
955 | "address_family": { | |
956 | addr_type: { | |
957 | "unicast": { | |
958 | "neighbor": { | |
959 | "r4": { | |
960 | "dest_link": { | |
961 | "r3": { | |
962 | "local_asn": { | |
963 | "local_as": "110", | |
964 | "no_prepend": True, | |
965 | } | |
966 | } | |
967 | } | |
968 | } | |
969 | } | |
970 | } | |
971 | } | |
972 | }, | |
973 | } | |
974 | ] | |
975 | } | |
976 | } | |
977 | result = create_router_bgp(tgen, topo, input_dict_no_prep_r3_to_r4) | |
978 | assert result is True, "Testcase {} :Failed \n Error: {}".format( | |
979 | tc_name, result | |
980 | ) | |
981 | ||
982 | step("BGP neighborship is verified by following commands in R3 routers") | |
983 | BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo) | |
984 | assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format( | |
985 | BGP_CONVERGENCE | |
986 | ) | |
987 | dut = "r3" | |
988 | aspath = "400" | |
989 | for addr_type in ADDR_TYPES: | |
990 | input_static_r2 = {"r4": {"static_routes": [{"network": NETWORK[addr_type]}]}} | |
991 | result = verify_bgp_rib(tgen, addr_type, dut, input_static_r2, aspath=aspath) | |
992 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
993 | tc_name, result | |
994 | ) | |
995 | ||
996 | step("Configure local-as with no-prepend and replace-as at R3 towards R2") | |
997 | for addr_type in ADDR_TYPES: | |
998 | input_dict_no_prep_rep_as_r3_to_r2 = { | |
999 | "r3": { | |
1000 | "bgp": [ | |
1001 | { | |
1002 | "local_as": "300", | |
1003 | "address_family": { | |
1004 | addr_type: { | |
1005 | "unicast": { | |
1006 | "neighbor": { | |
1007 | "r2": { | |
1008 | "dest_link": { | |
1009 | "r3": { | |
1010 | "local_asn": { | |
1011 | "local_as": "110", | |
1012 | "no_prepend": True, | |
1013 | "replace_as": True, | |
1014 | } | |
1015 | } | |
1016 | } | |
1017 | } | |
1018 | } | |
1019 | } | |
1020 | } | |
1021 | }, | |
1022 | } | |
1023 | ] | |
1024 | } | |
1025 | } | |
1026 | result = create_router_bgp(tgen, topo, input_dict_no_prep_rep_as_r3_to_r2) | |
1027 | assert result is True, "Testcase {} :Failed \n Error: {}".format( | |
1028 | tc_name, result | |
1029 | ) | |
1030 | ||
1031 | step("Configure local-as with no-prepend and replace-as at R3 towards R4") | |
1032 | for addr_type in ADDR_TYPES: | |
1033 | input_dict_no_prep_rep_as_r3_to_r4 = { | |
1034 | "r3": { | |
1035 | "bgp": [ | |
1036 | { | |
1037 | "local_as": "300", | |
1038 | "vrf": "BLUE", | |
1039 | "address_family": { | |
1040 | addr_type: { | |
1041 | "unicast": { | |
1042 | "neighbor": { | |
1043 | "r4": { | |
1044 | "dest_link": { | |
1045 | "r3": { | |
1046 | "local_asn": { | |
1047 | "local_as": "110", | |
1048 | "no_prepend": True, | |
1049 | "replace_as": True, | |
1050 | } | |
1051 | } | |
1052 | } | |
1053 | } | |
1054 | } | |
1055 | } | |
1056 | } | |
1057 | }, | |
1058 | } | |
1059 | ] | |
1060 | } | |
1061 | } | |
1062 | result = create_router_bgp(tgen, topo, input_dict_no_prep_rep_as_r3_to_r4) | |
1063 | assert result is True, "Testcase {} :Failed \n Error: {}".format( | |
1064 | tc_name, result | |
1065 | ) | |
1066 | ||
1067 | step("BGP neighborship is verified by following commands in R3 routers") | |
1068 | BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo) | |
1069 | assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format( | |
1070 | BGP_CONVERGENCE | |
1071 | ) | |
1072 | ||
1073 | dut = "r2" | |
1074 | aspath = "110 400" | |
1075 | for addr_type in ADDR_TYPES: | |
1076 | input_static_r2 = { | |
1077 | "r4": { | |
1078 | "static_routes": [ | |
1079 | { | |
1080 | "network": NETWORK[addr_type], | |
1081 | } | |
1082 | ] | |
1083 | } | |
1084 | } | |
1085 | result = verify_bgp_rib(tgen, addr_type, dut, input_static_r2, aspath=aspath) | |
1086 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
1087 | tc_name, result | |
1088 | ) | |
1089 | ||
1090 | write_test_footer(tc_name) | |
1091 | ||
1092 | ||
1093 | if __name__ == "__main__": | |
1094 | args = ["-s"] + sys.argv[1:] | |
1095 | sys.exit(pytest.main(args)) |