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