]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/bgp_local_asn/test_bgp_local_asn_topo1.py
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / tests / topotests / bgp_local_asn / test_bgp_local_asn_topo1.py
CommitLineData
a65b1a75 1#!/usr/bin/env python3
acddc0ed 2# SPDX-License-Identifier: ISC
a65b1a75
KK
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#
a65b1a75
KK
8
9##########################################################################################################
10#
11# Functionality Testcases
12#
13##########################################################################################################
14"""
151. Verify the BGP Local AS functionality by adding no-prepend and replace-as command in between eBGP Peers.
162. Verify the BGP Local AS functionality by configuring 4 Byte AS at R3 and 2 Byte AS at R2 & R4 in between eBGP Peers.
173. Verify that BGP Local AS functionality by performing graceful restart in between eBGP Peers.
184. Verify the BGP Local AS functionality by adding another AS & by same AS with AS-Prepend command in between eBGP Peers.
194. Verify the BGP Local AS functionality by adding no-prepend and replace-as command in between iBGP Peers.
205. Verify the BGP Local AS functionality with allowas-in in between iBGP Peers.
216. Verify that BGP Local AS functionality by performing shut/ noshut on the interfaces in between BGP neighbors.
227. Verify that BGP Local AS functionality by restarting BGP,Zebra and FRR services and
23 further restarting clear BGP * and shutdown BGP neighbor.
248. Verify the BGP Local AS functionality with different AS configurations.
259. Verify the BGP Local AS functionality with R3& R4 with different AS configurations.
26"""
27
28import os
29import sys
30import time
31import pytest
32from copy import deepcopy
33
34# Save the Current Working Directory to find configuration files.
35CWD = os.path.dirname(os.path.realpath(__file__))
36sys.path.append(os.path.join(CWD, "../"))
37sys.path.append(os.path.join(CWD, "../lib/"))
38
39# pylint: disable=C0413
40# Import topogen and topotest helpers
41from lib.topogen import Topogen, get_topogen
42from lib.topotest import version_cmp
43
44from 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 get_frr_ipv6_linklocal,
53 check_address_types,
54 check_router_status,
55 create_static_routes,
56 verify_fib_routes,
57 create_route_maps,
58 kill_router_daemons,
59 start_router_daemons,
60 shutdown_bringup_interface,
61)
62
63from lib.topolog import logger
64from lib.bgp import (
65 verify_bgp_convergence,
66 clear_bgp_and_verify,
67 verify_bgp_rib,
68 modify_as_number,
69 create_router_bgp,
70 verify_bgp_advertised_routes_from_neighbor,
71 verify_graceful_restart,
72 verify_r_bit,
73)
74from lib.topojson import build_config_from_json
75
76pytestmark = [pytest.mark.bgpd, pytest.mark.staticd]
77
78# Global variables
79NETWORK = {"ipv4": "10.1.1.0/32", "ipv6": "10:1::1:0/128"}
80NEXT_HOP_IP = {"ipv4": "Null0", "ipv6": "Null0"}
81NEXT_HOP_IP_GR = {"ipv4": "10.0.0.5", "ipv6": "fd00:0:0:1::2/64"}
82NEXT_HOP_IP_1 = {"ipv4": "10.0.0.101", "ipv6": "fd00::1"}
83NEXT_HOP_IP_2 = {"ipv4": "10.0.0.102", "ipv6": "fd00::2"}
84
85BGP_CONVERGENCE = False
86PREFERRED_NEXT_HOP = "link_local"
87KEEPALIVETIMER = 1
88HOLDDOWNTIMER = 3
89
90
91def setup_module(mod):
92 """
93 Sets up the pytest environment
94
95 * `mod`: module name
96 """
97
98 testsuite_run_time = time.asctime(time.localtime(time.time()))
99 logger.info("Testsuite start time: {}".format(testsuite_run_time))
100 logger.info("=" * 40)
101
102 logger.info("Running setup_module to create topology")
103
104 # This function initiates the topology build with Topogen...
105 json_file = "{}/bgp_local_asn_topo1.json".format(CWD)
106 tgen = Topogen(json_file, mod.__name__)
107 global topo
108 topo = tgen.json_topo
109 # ... and here it calls Mininet initialization functions.
110
111 # Starting topology, create tmp files which are loaded to routers
112 # to start daemons and then start routers
113 start_topology(tgen)
114
115 # Creating configuration from JSON
116 build_config_from_json(tgen, topo)
117
118 global BGP_CONVERGENCE
119 global ADDR_TYPES
120 ADDR_TYPES = check_address_types()
121
122 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
123 assert BGP_CONVERGENCE is True, "setup_module : Failed \n Error: {}".format(
124 BGP_CONVERGENCE
125 )
126
127 logger.info("Running setup_module() done")
128
129
130def teardown_module():
131 """Teardown the pytest environment"""
132
133 logger.info("Running teardown_module to delete topology")
134
135 tgen = get_topogen()
136
137 # Stop toplogy and Remove tmp files
138 tgen.stop_topology()
139
140 logger.info(
141 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
142 )
143 logger.info("=" * 40)
144
145
146##########################################################################################################
147#
148# Local APIs
149#
150##########################################################################################################
151
152
153def configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut, peer):
154 """
155 This function groups the repetitive function calls into one function.
156 """
157 result = create_router_bgp(tgen, topo, input_dict)
158 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
159
160 result = clear_bgp_and_verify(tgen, topo, dut)
161 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
162
163 return True
164
165
166def next_hop_per_address_family(
167 tgen, dut, peer, addr_type, next_hop_dict, preferred_next_hop=PREFERRED_NEXT_HOP
168):
169 """
170 This function returns link_local or global next_hop per address-family
171 """
172 intferface = topo["routers"][peer]["links"]["{}".format(dut)]["interface"]
173 if addr_type == "ipv6" and "link_local" in preferred_next_hop:
174 next_hop = get_frr_ipv6_linklocal(tgen, peer, intf=intferface)
175 else:
176 next_hop = next_hop_dict[addr_type]
177
178 return next_hop
179
180
181##########################################################################################################
182#
183# Testcases
184#
185##########################################################################################################
186
187
188def test_verify_bgp_local_as_in_EBGP_p0(request):
189 """
190 Verify the BGP Local AS functionality by adding no-prepend and
191 replace-as command in between eBGP Peers.
192 """
193 tgen = get_topogen()
194 global BGP_CONVERGENCE
195 if BGP_CONVERGENCE != True:
196 pytest.skip("skipped because of BGP Convergence failure")
197
198 # test case name
199 tc_name = request.node.name
200 write_test_header(tc_name)
201 if tgen.routers_have_failure():
202 check_router_status(tgen)
203 reset_config_on_routers(tgen)
204
205 step("Base config is done as part of JSON")
206 step("Configure local-as at R3 towards R4.")
207 for addr_type in ADDR_TYPES:
208 for neighbor in ["r2", "r4"]:
209 input_dict_r3 = {
210 "r3": {
211 "bgp": {
212 "local_as": "300",
213 "address_family": {
214 addr_type: {
215 "unicast": {
216 "neighbor": {
217 neighbor: {
218 "dest_link": {
219 "r3": {"local_asn": {"local_as": "110"}}
220 }
221 }
222 }
223 }
224 }
225 },
226 }
227 }
228 }
229 result = create_router_bgp(tgen, topo, input_dict_r3)
230 assert result is True, "Testcase {} :Failed \n Error: {}".format(
231 tc_name, result
232 )
233
234 for addr_type in ADDR_TYPES:
235 for dut, asn, neighbor in zip(["r2", "r4"], ["200", "400"], ["r3", "r3"]):
236 input_dict_r2_r4 = {
237 dut: {
238 "bgp": {
239 "local_as": asn,
240 "address_family": {
241 addr_type: {
242 "unicast": {
243 "neighbor": {
244 neighbor: {
245 "dest_link": {
246 dut: {"local_asn": {"remote_as": "110"}}
247 }
248 }
249 }
250 }
251 }
252 },
253 }
254 }
255 }
256 result = create_router_bgp(tgen, topo, input_dict_r2_r4)
257 assert result is True, "Testcase {} :Failed \n Error: {}".format(
258 tc_name, result
259 )
260
261 step("BGP neighborship is verified by following commands in R3 routers")
262 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
263 assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format(
264 BGP_CONVERGENCE
265 )
266
267 # configure static routes
268 step("Done in base config: Advertise prefix 10.1.1.0/32 from Router-1(AS-100).")
269 step(
270 "Done in base config: Advertise an ipv6 prefix 10:1::1:0/128 from Router-1(AS-100)."
271 )
272 step("Verify that Static routes are redistributed in BGP process")
273
274 dut = "r1"
275 protocol = "bgp"
276 for addr_type in ADDR_TYPES:
277 # Enable static routes
278 input_static_r1 = {
279 "r1": {
280 "static_routes": [
281 {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]}
282 ]
283 }
284 }
285
286 logger.info("Configure static routes")
287 result = create_static_routes(tgen, input_static_r1)
288 assert result is True, "Testcase {} : Failed \n Error: {}".format(
289 tc_name, result
290 )
291
292 step("configure redistribute static in Router BGP in R1")
293
294 input_static_redist_r1 = {
295 "r1": {
296 "bgp": {
297 "address_family": {
298 addr_type: {
299 "unicast": {"redistribute": [{"redist_type": "static"}]}
300 }
301 }
302 }
303 }
304 }
305 result = create_router_bgp(tgen, topo, input_static_redist_r1)
306 assert result is True, "Testcase {} : Failed \n Error: {}".format(
307 tc_name, result
308 )
309
310 step("Verify that Static routes are redistributed in BGP process")
311 for addr_type in ADDR_TYPES:
312 input_static_verify_r1 = {
313 "r1": {"static_routes": [{"network": NETWORK[addr_type]}]}
314 }
315
316 result = verify_rib(tgen, addr_type, "r1", input_static_verify_r1)
317 assert result is True, "Testcase {}: Failed \n Error: {}".format(
318 tc_name, result
319 )
320
321 for dut in ["r3", "r4"]:
322 result = verify_rib(tgen, addr_type, dut, input_static_r1)
323 assert result is True, "Testcase {}: Failed \n Error: {}".format(
324 tc_name, result
325 )
326
327 for dut, input_routes in zip(["r1"], [input_static_r1]):
328 result = verify_rib(tgen, addr_type, dut, input_routes)
329 assert result is True, "Testcase {}: Failed \n Error: {}".format(
330 tc_name, result
331 )
332
333 step(
334 "Verify that AS-110 is got added in the AS list 110 200 100 by following"
335 "commands at R3 router."
336 )
337 dut = "r3"
338 aspath = "110 200 100"
339 for addr_type in ADDR_TYPES:
340 input_static_r1 = {"r1": {"static_routes": [{"network": NETWORK[addr_type]}]}}
341 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
342 assert result is True, "Testcase {} : Failed \n Error: {}".format(
343 tc_name, result
344 )
345
346 step("Configure local-as with no-prepend at R3 towards R4 & R2.")
347 for addr_type in ADDR_TYPES:
348 for neighbor in ["r2", "r4"]:
349 input_dict_r3 = {
350 "r3": {
351 "bgp": {
352 "local_as": "300",
353 "address_family": {
354 addr_type: {
355 "unicast": {
356 "neighbor": {
357 neighbor: {
358 "dest_link": {
359 "r3": {
360 "local_asn": {
361 "local_as": "110",
362 "no_prepend": True,
363 }
364 }
365 }
366 }
367 }
368 }
369 }
370 },
371 }
372 }
373 }
374 result = create_router_bgp(tgen, topo, input_dict_r3)
375 assert result is True, "Testcase {} :Failed \n Error: {}".format(
376 tc_name, result
377 )
378
379 step("BGP neighborship is verified by following commands in R3 routers")
380 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
381 assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format(
382 BGP_CONVERGENCE
383 )
384
385 step("Verify advertised routes to R4 at R3")
386 expected_routes = {
387 "ipv4": [
388 {"network": "10.1.1.0/32", "nexthop": ""},
389 ],
390 "ipv6": [
391 {"network": "10:1::1:0/128", "nexthop": ""},
392 ],
393 }
394 result = verify_bgp_advertised_routes_from_neighbor(
395 tgen, topo, dut="r3", peer="r4", expected_routes=expected_routes
396 )
397 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
398
399 dut = "r3"
400 aspath = "200 100"
401 for addr_type in ADDR_TYPES:
402 input_static_r1 = {"r1": {"static_routes": [{"network": NETWORK[addr_type]}]}}
403 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
404 assert result is True, "Testcase {} : Failed \n Error: {}".format(
405 tc_name, result
406 )
407
408 step("Configure local-as with no-prepend and replace-as at R3 towards R4 & R2.")
409 for addr_type in ADDR_TYPES:
410 for neighbor in ["r2", "r4"]:
411 input_dict_r3 = {
412 "r3": {
413 "bgp": {
414 "local_as": "300",
415 "address_family": {
416 addr_type: {
417 "unicast": {
418 "neighbor": {
419 neighbor: {
420 "dest_link": {
421 "r3": {
422 "local_asn": {
423 "local_as": "110",
424 "no_prepend": True,
425 "replace_as": True,
426 }
427 }
428 }
429 }
430 }
431 }
432 }
433 },
434 }
435 }
436 }
437 result = create_router_bgp(tgen, topo, input_dict_r3)
438 assert result is True, "Testcase {} :Failed \n Error: {}".format(
439 tc_name, result
440 )
441
442 step("BGP neighborship is verified by following commands in R3 routers")
443 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
444 assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format(
445 BGP_CONVERGENCE
446 )
447
448 dut = "r4"
449 aspath = "110 200 100"
450 for addr_type in ADDR_TYPES:
451 input_static_r1 = {"r1": {"static_routes": [{"network": NETWORK[addr_type]}]}}
452 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
453 assert result is True, "Testcase {} : Failed \n Error: {}".format(
454 tc_name, result
455 )
456
457 write_test_footer(tc_name)
458
459
460def test_verify_bgp_local_as_in_EBGP_4B_AS_mid_2B_AS_p0(request):
461 """
462 Verify the BGP Local AS functionality by configuring 4 Byte AS
463 at R3 and 2 Byte AS at R2 & R4 in between eBGP Peers.
464 """
465 tgen = get_topogen()
466 global BGP_CONVERGENCE
467
468 if BGP_CONVERGENCE != True:
469 pytest.skip("skipped because of BGP Convergence failure")
470
471 # test case name
472 tc_name = request.node.name
473 write_test_header(tc_name)
474 if tgen.routers_have_failure():
475 check_router_status(tgen)
476 reset_config_on_routers(tgen)
477
478 step("Base config is done as part of JSON")
479 step("Configure local-as at R3 towards R4.")
480 for addr_type in ADDR_TYPES:
481 for neighbor in ["r2", "r4"]:
482 input_dict_r3 = {
483 "r3": {
484 "bgp": {
485 "local_as": "300",
486 "address_family": {
487 addr_type: {
488 "unicast": {
489 "neighbor": {
490 neighbor: {
491 "dest_link": {
492 "r3": {
493 "local_asn": {
494 "local_as": "12000110"
495 }
496 }
497 }
498 }
499 }
500 }
501 }
502 },
503 }
504 }
505 }
506 result = create_router_bgp(tgen, topo, input_dict_r3)
507 assert result is True, "Testcase {} :Failed \n Error: {}".format(
508 tc_name, result
509 )
510
511 for addr_type in ADDR_TYPES:
512 for dut, asn, neighbor in zip(["r2", "r4"], ["200", "400"], ["r3", "r3"]):
513 input_dict_r2_r4 = {
514 dut: {
515 "bgp": {
516 "local_as": asn,
517 "address_family": {
518 addr_type: {
519 "unicast": {
520 "neighbor": {
521 neighbor: {
522 "dest_link": {
523 dut: {
524 "local_asn": {
525 "remote_as": "12000110"
526 }
527 }
528 }
529 }
530 }
531 }
532 }
533 },
534 }
535 }
536 }
537 result = create_router_bgp(tgen, topo, input_dict_r2_r4)
538 assert result is True, "Testcase {} :Failed \n Error: {}".format(
539 tc_name, result
540 )
541
542 step("BGP neighborship is verified by following commands in R3 routers")
543 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
544 assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format(
545 BGP_CONVERGENCE
546 )
547
548 # configure static routes
549 step("Done in base config: Advertise prefix 10.1.1.0/32 from Router-1(AS-100).")
550 step(
551 "Done in base config: Advertise an ipv6 prefix 10:1::1:0/128 from Router-1(AS-100)."
552 )
553 step("Verify that Static routes are redistributed in BGP process")
554
555 dut = "r1"
556 protocol = "bgp"
557 for addr_type in ADDR_TYPES:
558 # Enable static routes
559 input_static_r1 = {
560 "r1": {
561 "static_routes": [
562 {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]}
563 ]
564 }
565 }
566
567 logger.info("Configure static routes")
568 result = create_static_routes(tgen, input_static_r1)
569 assert result is True, "Testcase {} : Failed \n Error: {}".format(
570 tc_name, result
571 )
572
573 step("configure redistribute static in Router BGP in R1")
574
575 input_static_redist_r1 = {
576 "r1": {
577 "bgp": {
578 "address_family": {
579 addr_type: {
580 "unicast": {"redistribute": [{"redist_type": "static"}]}
581 }
582 }
583 }
584 }
585 }
586 result = create_router_bgp(tgen, topo, input_static_redist_r1)
587 assert result is True, "Testcase {} : Failed \n Error: {}".format(
588 tc_name, result
589 )
590
591 step("Verify that Static routes are redistributed in BGP process")
592 for addr_type in ADDR_TYPES:
593 input_static_verify_r1 = {
594 "r1": {"static_routes": [{"network": NETWORK[addr_type]}]}
595 }
596
597 result = verify_rib(tgen, addr_type, "r1", input_static_verify_r1)
598 assert result is True, "Testcase {}: Failed \n Error: {}".format(
599 tc_name, result
600 )
601
602 for dut in ["r3", "r4"]:
603 result = verify_rib(tgen, addr_type, dut, input_static_r1)
604 assert result is True, "Testcase {}: Failed \n Error: {}".format(
605 tc_name, result
606 )
607
608 for dut, input_routes in zip(["r1"], [input_static_r1]):
609 result = verify_rib(tgen, addr_type, dut, input_routes)
610 assert result is True, "Testcase {}: Failed \n Error: {}".format(
611 tc_name, result
612 )
613
614 step(
615 "Verify that AS-12000110 is got added in the AS list 12000110 200 100 by following"
616 "commands at R3 router."
617 )
618 dut = "r3"
619 aspath = "12000110 200 100"
620 for addr_type in ADDR_TYPES:
621 input_static_r1 = {"r1": {"static_routes": [{"network": NETWORK[addr_type]}]}}
622 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
623 assert result is True, "Testcase {} : Failed \n Error: {}".format(
624 tc_name, result
625 )
626
627 step("Configure local-as with no-prepend at R3 towards R4 & R2.")
628 for addr_type in ADDR_TYPES:
629 for neighbor in ["r2", "r4"]:
630 input_dict_r3 = {
631 "r3": {
632 "bgp": {
633 "local_as": "300",
634 "address_family": {
635 addr_type: {
636 "unicast": {
637 "neighbor": {
638 neighbor: {
639 "dest_link": {
640 "r3": {
641 "local_asn": {
642 "local_as": "12000110",
643 "no_prepend": True,
644 }
645 }
646 }
647 }
648 }
649 }
650 }
651 },
652 }
653 }
654 }
655 result = create_router_bgp(tgen, topo, input_dict_r3)
656 assert result is True, "Testcase {} :Failed \n Error: {}".format(
657 tc_name, result
658 )
659
660 step("BGP neighborship is verified by following commands in R3 routers")
661 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
662 assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format(
663 BGP_CONVERGENCE
664 )
665
666 step("Verify advertised routes to R4 at R3")
667 expected_routes = {
668 "ipv4": [
669 {"network": "10.1.1.0/32", "nexthop": ""},
670 ],
671 "ipv6": [
672 {"network": "10:1::1:0/128", "nexthop": ""},
673 ],
674 }
675 result = verify_bgp_advertised_routes_from_neighbor(
676 tgen, topo, dut="r3", peer="r4", expected_routes=expected_routes
677 )
678 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
679
680 dut = "r3"
681 aspath = "200 100"
682 for addr_type in ADDR_TYPES:
683 input_static_r1 = {"r1": {"static_routes": [{"network": NETWORK[addr_type]}]}}
684 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
685 assert result is True, "Testcase {} : Failed \n Error: {}".format(
686 tc_name, result
687 )
688
689 step("Configure local-as with no-prepend and replace-as at R3 towards R4 & R2.")
690 for addr_type in ADDR_TYPES:
691 for neighbor in ["r2", "r4"]:
692 input_dict_r3 = {
693 "r3": {
694 "bgp": {
695 "local_as": "300",
696 "address_family": {
697 addr_type: {
698 "unicast": {
699 "neighbor": {
700 neighbor: {
701 "dest_link": {
702 "r3": {
703 "local_asn": {
704 "local_as": "12000110",
705 "no_prepend": True,
706 "replace_as": True,
707 }
708 }
709 }
710 }
711 }
712 }
713 }
714 },
715 }
716 }
717 }
718 result = create_router_bgp(tgen, topo, input_dict_r3)
719 assert result is True, "Testcase {} :Failed \n Error: {}".format(
720 tc_name, result
721 )
722
723 step("BGP neighborship is verified by following commands in R3 routers")
724 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
725 assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format(
726 BGP_CONVERGENCE
727 )
728
729 dut = "r4"
730 aspath = "12000110 200 100"
731 for addr_type in ADDR_TYPES:
732 input_static_r1 = {"r1": {"static_routes": [{"network": NETWORK[addr_type]}]}}
733 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
734 assert result is True, "Testcase {} : Failed \n Error: {}".format(
735 tc_name, result
736 )
737
738 write_test_footer(tc_name)
739
740
741def test_verify_bgp_local_as_GR_EBGP_p0(request):
742 """
743 Verify that BGP Local AS functionality by performing graceful restart in between eBGP Peers.
744 """
745 tgen = get_topogen()
746 global BGP_CONVERGENCE
747
748 if BGP_CONVERGENCE != True:
749 pytest.skip("skipped because of BGP Convergence failure")
750 # test case name
751 tc_name = request.node.name
752 write_test_header(tc_name)
753 if tgen.routers_have_failure():
754 check_router_status(tgen)
755 reset_config_on_routers(tgen)
756
757 step("Configure basic BGP Peerings between R1,R2,R3 and R4")
758 for addr_type in ADDR_TYPES:
759 # Enable static routes
760 input_dict_static_route = {
761 "r1": {
762 "static_routes": [
763 {
764 "network": NETWORK[addr_type],
765 "next_hop": NEXT_HOP_IP_GR[addr_type],
766 }
767 ]
768 }
769 }
770
771 logger.info("Configure static routes")
772 result = create_static_routes(tgen, input_dict_static_route)
773 assert result is True, "Testcase {} : Failed \n Error: {}".format(
774 tc_name, result
775 )
776
777 step("configure redistribute static in Router BGP in R1")
778 input_dict_static_route_redist = {
779 "r1": {
780 "bgp": [
781 {
782 "address_family": {
783 addr_type: {
784 "unicast": {"redistribute": [{"redist_type": "static"}]}
785 }
786 }
787 }
788 ]
789 }
790 }
791 result = create_router_bgp(tgen, topo, input_dict_static_route_redist)
792 assert result is True, "Testcase {} : Failed \n Error: {}".format(
793 tc_name, result
794 )
795 step("Verify IPv4 and IPv6 static routes received on R1")
796 result = verify_rib(tgen, addr_type, "r1", input_dict_static_route)
797 assert result is True, "Testcase {}: Failed \n Error: {}".format(
798 tc_name, result
799 )
800 result = verify_bgp_rib(tgen, addr_type, "r1", input_dict_static_route)
801 assert result is True, "Testcase {} : Failed \n Error: {}".format(
802 tc_name, result
803 )
804 result = verify_fib_routes(tgen, addr_type, "r1", input_dict_static_route)
805 assert result is True, "Testcase {} : Failed \n Error: {}".format(
806 tc_name, result
807 )
808
809 step("Configure local-as at R3 towards R2.")
810 for addr_type in ADDR_TYPES:
811 input_dict_r3_to_r2 = {
812 "r3": {
813 "bgp": [
814 {
815 "local_as": "300",
816 "address_family": {
817 addr_type: {
818 "unicast": {
819 "neighbor": {
820 "r2": {
821 "dest_link": {
822 "r3": {"local_asn": {"local_as": "110"}}
823 }
824 }
825 }
826 }
827 }
828 },
829 }
830 ]
831 }
832 }
833 result = create_router_bgp(tgen, topo, input_dict_r3_to_r2)
834 assert result is True, "Testcase {} :Failed \n Error: {}".format(
835 tc_name, result
836 )
837
838 step("Configure local-as at R3 towards R4.")
839 for addr_type in ADDR_TYPES:
840 input_dict_r3_to_r4 = {
841 "r3": {
842 "bgp": [
843 {
844 "local_as": "300",
845 "address_family": {
846 addr_type: {
847 "unicast": {
848 "neighbor": {
849 "r4": {
850 "dest_link": {
851 "r3": {"local_asn": {"local_as": "110"}}
852 }
853 }
854 }
855 }
856 }
857 },
858 }
859 ]
860 }
861 }
862 result = create_router_bgp(tgen, topo, input_dict_r3_to_r4)
863 assert result is True, "Testcase {} :Failed \n Error: {}".format(
864 tc_name, result
865 )
866
867 step("Configure remote-as at R2 towards R3.")
868 for addr_type in ADDR_TYPES:
869 input_dict_r2_to_r3 = {
870 "r2": {
871 "bgp": [
872 {
873 "local_as": "200",
874 "address_family": {
875 addr_type: {
876 "unicast": {
877 "neighbor": {
878 "r3": {
879 "dest_link": {
880 "r2": {
881 "local_asn": {"remote_as": "110"}
882 }
883 }
884 }
885 }
886 }
887 }
888 },
889 }
890 ]
891 }
892 }
893 result = create_router_bgp(tgen, topo, input_dict_r2_to_r3)
894 assert result is True, "Testcase {} :Failed \n Error: {}".format(
895 tc_name, result
896 )
897
898 step("Configure remote-as at R4 towards R3.")
899 for addr_type in ADDR_TYPES:
900 input_dict_r4_to_r3 = {
901 "r4": {
902 "bgp": [
903 {
904 "local_as": "400",
905 "address_family": {
906 addr_type: {
907 "unicast": {
908 "neighbor": {
909 "r3": {
910 "dest_link": {
911 "r4": {
912 "local_asn": {"remote_as": "110"}
913 }
914 }
915 }
916 }
917 }
918 }
919 },
920 }
921 ]
922 }
923 }
924 result = create_router_bgp(tgen, topo, input_dict_r4_to_r3)
925 assert result is True, "Testcase {} :Failed \n Error: {}".format(
926 tc_name, result
927 )
928
929 step("BGP neighborship is verified by following commands in R3 routers")
930 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
931 assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format(
932 BGP_CONVERGENCE
933 )
934
935 step("Verify IPv4 and IPv6 static routes received on R3 & R4")
936 for addr_type in ADDR_TYPES:
937 static_routes_input = {
938 "r1": {
939 "static_routes": [
940 {
941 "network": NETWORK[addr_type],
942 "next_hop": NEXT_HOP_IP_GR[addr_type],
943 }
944 ]
945 }
946 }
947 for dut in ["r3", "r4"]:
948 result = verify_fib_routes(tgen, addr_type, dut, static_routes_input)
949 assert result is True, "Testcase {} : Failed \n Error: {}".format(
950 tc_name, result
951 )
952
953 result = verify_bgp_rib(tgen, addr_type, dut, static_routes_input)
954 assert result is True, "Testcase {} : Failed \n Error: {}".format(
955 tc_name, result
956 )
957
958 step(
959 "Verify that AS-110 is got added in the AS list 110 200 100 by following "
960 " commands at R3 router."
961 )
962 dut = "r3"
963 aspath = "110 200 100"
964 for addr_type in ADDR_TYPES:
965 input_static_r1 = {"r1": {"static_routes": [{"network": NETWORK[addr_type]}]}}
966 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
967 assert result is True, "Testcase {} : Failed \n Error: {}".format(
968 tc_name, result
969 )
970
971 """
972 GR Steps : Helper BGP router R2, mark and unmark IPV4 routes
973 as stale as the restarting router R3 come up within the restart time
974 """
975 # Create route-map to prefer global next-hop
976 input_dict = {
977 "r2": {
978 "route_maps": {
979 "rmap_global": [
980 {"action": "permit", "set": {"ipv6": {"nexthop": "prefer-global"}}}
981 ]
982 }
983 },
984 "r3": {
985 "route_maps": {
986 "rmap_global": [
987 {"action": "permit", "set": {"ipv6": {"nexthop": "prefer-global"}}}
988 ]
989 }
990 },
991 }
992 result = create_route_maps(tgen, input_dict)
993 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
994
995 # Configure neighbor for route map
996 input_dict_neigh_rm = {
997 "r2": {
998 "bgp": {
999 "address_family": {
1000 "ipv6": {
1001 "unicast": {
1002 "neighbor": {
1003 "r3": {
1004 "dest_link": {
1005 "r2": {
1006 "route_maps": [
1007 {
1008 "name": "rmap_global",
1009 "direction": "in",
1010 }
1011 ]
1012 }
1013 }
1014 }
1015 }
1016 }
1017 }
1018 }
1019 }
1020 },
1021 "r3": {
1022 "bgp": {
1023 "address_family": {
1024 "ipv6": {
1025 "unicast": {
1026 "neighbor": {
1027 "r2": {
1028 "dest_link": {
1029 "r3": {
1030 "route_maps": [
1031 {
1032 "name": "rmap_global",
1033 "direction": "in",
1034 }
1035 ]
1036 }
1037 }
1038 }
1039 }
1040 }
1041 }
1042 }
1043 }
1044 },
1045 }
1046
1047 result = create_router_bgp(tgen, topo, input_dict_neigh_rm)
1048 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1049
1050 # Configure graceful-restart
1051 input_dict = {
1052 "r2": {
1053 "bgp": {
1054 "address_family": {
1055 "ipv4": {
1056 "unicast": {
1057 "neighbor": {
1058 "r3": {
1059 "dest_link": {
1060 "r2": {
1061 "graceful-restart-helper": True,
1062 "local_asn": {"remote_as": "110"},
1063 }
1064 }
1065 }
1066 }
1067 }
1068 },
1069 "ipv6": {
1070 "unicast": {
1071 "neighbor": {
1072 "r3": {
1073 "dest_link": {
1074 "r2": {
1075 "graceful-restart-helper": True,
1076 "local_asn": {"remote_as": "110"},
1077 }
1078 }
1079 }
1080 }
1081 }
1082 },
1083 }
1084 }
1085 },
1086 "r3": {
1087 "bgp": {
1088 "address_family": {
1089 "ipv4": {
1090 "unicast": {
1091 "neighbor": {
1092 "r2": {"dest_link": {"r3": {"graceful-restart": True}}}
1093 }
1094 }
1095 },
1096 "ipv6": {
1097 "unicast": {
1098 "neighbor": {
1099 "r2": {"dest_link": {"r3": {"graceful-restart": True}}}
1100 }
1101 }
1102 },
1103 }
1104 }
1105 },
1106 }
1107
1108 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r3", peer="r2")
1109 for addr_type in ADDR_TYPES:
1110 result = verify_graceful_restart(
1111 tgen, topo, addr_type, input_dict, dut="r3", peer="r2"
1112 )
1113 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1114
1115 # Verifying BGP RIB routes
1116 dut = "r2"
1117 peer = "r3"
1118 next_hop = next_hop_per_address_family(
1119 tgen, dut, peer, addr_type, NEXT_HOP_IP_2, preferred_next_hop="global"
1120 )
1121 input_topo = {key: topo["routers"][key] for key in ["r3"]}
1122 result = verify_bgp_rib(tgen, addr_type, dut, input_topo)
1123 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1124
1125 # Verifying RIB routes
1126 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, "bgp")
1127 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1128
1129 logger.info("[Phase 2] : R3 goes for reload ")
1130
1131 kill_router_daemons(tgen, "r3", ["bgpd"])
1132
1133 logger.info(
1134 "[Phase 3] : R3 is still down, restart time 120 sec."
1135 " So time verify the routes are present in BGP RIB"
1136 " and ZEBRA"
1137 )
1138
1139 for addr_type in ADDR_TYPES:
1140 # Verifying BGP RIB routes
1141 next_hop = next_hop_per_address_family(
1142 tgen, dut, peer, addr_type, NEXT_HOP_IP_2, preferred_next_hop="global"
1143 )
1144 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
1145 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1146
1147 # Verifying RIB routes
1148 protocol = "bgp"
1149 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
1150 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1151
1152 logger.info("[Phase 5] : R3 is about to come up now ")
1153 start_router_daemons(tgen, "r3", ["bgpd"])
1154
1155 logger.info("[Phase 5] : R3 is UP Now ! ")
1156
1157 for addr_type in ADDR_TYPES:
1158 result = verify_bgp_convergence(tgen, topo)
1159 assert (
1160 result is True
1161 ), "BGP Convergence after BGPd restart" " :Failed \n Error:{}".format(result)
1162
1163 # Verifying GR stats
1164 result = verify_graceful_restart(
1165 tgen, topo, addr_type, input_dict, dut="r3", peer="r2"
1166 )
1167 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1168
1169 result = verify_r_bit(tgen, topo, addr_type, input_dict, dut="r2", peer="r3")
1170 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1171
1172 # Verifying BGP RIB routes
1173 next_hop = next_hop_per_address_family(
1174 tgen, dut, peer, addr_type, NEXT_HOP_IP_2, preferred_next_hop="global"
1175 )
1176 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
1177 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1178
1179 # Verifying RIB routes
1180 protocol = "bgp"
1181 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
1182 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1183
1184 step("Configure local-as with no-prepend at R3 towards R2.")
1185 for addr_type in ADDR_TYPES:
1186 input_dict_no_prep_r3_to_r2 = {
1187 "r3": {
1188 "bgp": [
1189 {
1190 "local_as": "300",
1191 "address_family": {
1192 addr_type: {
1193 "unicast": {
1194 "neighbor": {
1195 "r2": {
1196 "dest_link": {
1197 "r3": {
1198 "local_asn": {
1199 "local_as": "110",
1200 "no_prepend": True,
1201 }
1202 }
1203 }
1204 }
1205 }
1206 }
1207 }
1208 },
1209 }
1210 ]
1211 }
1212 }
1213 result = create_router_bgp(tgen, topo, input_dict_no_prep_r3_to_r2)
1214 assert result is True, "Testcase {} :Failed \n Error: {}".format(
1215 tc_name, result
1216 )
1217
1218 step("Configure local-as with no-prepend at R3 towards R4.")
1219 for addr_type in ADDR_TYPES:
1220 input_dict_no_prep_r3_to_r4 = {
1221 "r3": {
1222 "bgp": [
1223 {
1224 "local_as": "300",
1225 "address_family": {
1226 addr_type: {
1227 "unicast": {
1228 "neighbor": {
1229 "r4": {
1230 "dest_link": {
1231 "r3": {
1232 "local_asn": {
1233 "local_as": "110",
1234 "no_prepend": True,
1235 }
1236 }
1237 }
1238 }
1239 }
1240 }
1241 }
1242 },
1243 }
1244 ]
1245 }
1246 }
1247 result = create_router_bgp(tgen, topo, input_dict_no_prep_r3_to_r4)
1248 assert result is True, "Testcase {} :Failed \n Error: {}".format(
1249 tc_name, result
1250 )
1251
1252 step("BGP neighborship is verified by following commands in R3 routers")
1253 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
1254 assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format(
1255 BGP_CONVERGENCE
1256 )
1257
1258 dut = "r3"
1259 aspath = "200 100"
1260 for addr_type in ADDR_TYPES:
1261 input_static_r1 = {"r2": {"static_routes": [{"network": NETWORK[addr_type]}]}}
1262 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
1263 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1264 tc_name, result
1265 )
1266
1267 step("Configure local-as with no-prepend and replace-as at R3 towards R2")
1268 for addr_type in ADDR_TYPES:
1269 input_dict_no_prep_rep_as_r3_to_r2 = {
1270 "r3": {
1271 "bgp": [
1272 {
1273 "local_as": "300",
1274 "address_family": {
1275 addr_type: {
1276 "unicast": {
1277 "neighbor": {
1278 "r2": {
1279 "dest_link": {
1280 "r3": {
1281 "local_asn": {
1282 "local_as": "110",
1283 "no_prepend": True,
1284 "replace_as": True,
1285 }
1286 }
1287 }
1288 }
1289 }
1290 }
1291 }
1292 },
1293 }
1294 ]
1295 }
1296 }
1297 result = create_router_bgp(tgen, topo, input_dict_no_prep_rep_as_r3_to_r2)
1298 assert result is True, "Testcase {} :Failed \n Error: {}".format(
1299 tc_name, result
1300 )
1301
1302 step("Configure local-as with no-prepend and replace-as at R3 towards R4")
1303 for addr_type in ADDR_TYPES:
1304 input_dict_no_prep_rep_as_r3_to_r4 = {
1305 "r3": {
1306 "bgp": [
1307 {
1308 "local_as": "300",
1309 "address_family": {
1310 addr_type: {
1311 "unicast": {
1312 "neighbor": {
1313 "r4": {
1314 "dest_link": {
1315 "r3": {
1316 "local_asn": {
1317 "local_as": "110",
1318 "no_prepend": True,
1319 "replace_as": True,
1320 }
1321 }
1322 }
1323 }
1324 }
1325 }
1326 }
1327 },
1328 }
1329 ]
1330 }
1331 }
1332 result = create_router_bgp(tgen, topo, input_dict_no_prep_rep_as_r3_to_r4)
1333 assert result is True, "Testcase {} :Failed \n Error: {}".format(
1334 tc_name, result
1335 )
1336
1337 step("BGP neighborship is verified by following commands in R3 routers")
1338 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
1339 assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format(
1340 BGP_CONVERGENCE
1341 )
1342
1343 dut = "r4"
1344 aspath = "110 200 100"
1345 for addr_type in ADDR_TYPES:
1346 input_static_r1 = {"r1": {"static_routes": [{"network": NETWORK[addr_type]}]}}
1347 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
1348 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1349 tc_name, result
1350 )
1351
1352 write_test_footer(tc_name)
1353
1354
1355def test_verify_bgp_local_as_in_EBGP_aspath_p0(request):
1356 """
1357 Verify the BGP Local AS functionality by adding another AS & by same AS with AS-Prepend command in between eBGP Peers.
1358 """
1359 tgen = get_topogen()
1360 global BGP_CONVERGENCE
1361
1362 if BGP_CONVERGENCE != True:
1363 pytest.skip("skipped because of BGP Convergence failure")
1364 # test case name
1365 tc_name = request.node.name
1366 write_test_header(tc_name)
1367 if tgen.routers_have_failure():
1368 check_router_status(tgen)
1369 reset_config_on_routers(tgen)
1370
1371 step("Configure basic BGP Peerings between R1,R2,R3 and R4")
1372 step("Configure local-as at R3 towards R4.")
1373 for addr_type in ADDR_TYPES:
1374 for neighbor in ["r2", "r4"]:
1375 input_dict_r3 = {
1376 "r3": {
1377 "bgp": {
1378 "local_as": "300",
1379 "address_family": {
1380 addr_type: {
1381 "unicast": {
1382 "neighbor": {
1383 neighbor: {
1384 "dest_link": {
1385 "r3": {"local_asn": {"local_as": "110"}}
1386 }
1387 }
1388 }
1389 }
1390 }
1391 },
1392 }
1393 }
1394 }
1395 result = create_router_bgp(tgen, topo, input_dict_r3)
1396 assert result is True, "Testcase {} :Failed \n Error: {}".format(
1397 tc_name, result
1398 )
1399
1400 for addr_type in ADDR_TYPES:
1401 for dut, asn, neighbor in zip(["r2", "r4"], ["200", "400"], ["r3", "r3"]):
1402 input_dict_r2_r4 = {
1403 dut: {
1404 "bgp": {
1405 "local_as": asn,
1406 "address_family": {
1407 addr_type: {
1408 "unicast": {
1409 "neighbor": {
1410 neighbor: {
1411 "dest_link": {
1412 dut: {"local_asn": {"remote_as": "110"}}
1413 }
1414 }
1415 }
1416 }
1417 }
1418 },
1419 }
1420 }
1421 }
1422 result = create_router_bgp(tgen, topo, input_dict_r2_r4)
1423 assert result is True, "Testcase {} :Failed \n Error: {}".format(
1424 tc_name, result
1425 )
1426
1427 step("BGP neighborship is verified by following commands in R3 routers")
1428 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
1429 assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format(
1430 BGP_CONVERGENCE
1431 )
1432
1433 # configure static routes
1434 step("Done in base config: Advertise prefix 10.1.1.0/32 from Router-1(AS-100).")
1435 step(
1436 "Done in base config: Advertise an ipv6 prefix 10:1::1:0/128 from Router-1(AS-100)."
1437 )
1438 step("Verify that Static routes are redistributed in BGP process")
1439
1440 dut = "r1"
1441 protocol = "bgp"
1442 for addr_type in ADDR_TYPES:
1443 # Enable static routes
1444 input_static_r1 = {
1445 "r1": {
1446 "static_routes": [
1447 {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]}
1448 ]
1449 }
1450 }
1451
1452 logger.info("Configure static routes")
1453 result = create_static_routes(tgen, input_static_r1)
1454 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1455 tc_name, result
1456 )
1457
1458 step("configure redistribute static in Router BGP in R1")
1459
1460 input_static_redist_r1 = {
1461 "r1": {
1462 "bgp": {
1463 "address_family": {
1464 addr_type: {
1465 "unicast": {"redistribute": [{"redist_type": "static"}]}
1466 }
1467 }
1468 }
1469 }
1470 }
1471 result = create_router_bgp(tgen, topo, input_static_redist_r1)
1472 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1473 tc_name, result
1474 )
1475
1476 step("Verify that Static routes are redistributed in BGP process")
1477 for addr_type in ADDR_TYPES:
1478 input_static_verify_r1 = {
1479 "r1": {"static_routes": [{"network": NETWORK[addr_type]}]}
1480 }
1481
1482 result = verify_rib(tgen, addr_type, "r1", input_static_verify_r1)
1483 assert result is True, "Testcase {}: Failed \n Error: {}".format(
1484 tc_name, result
1485 )
1486
1487 for dut in ["r3", "r4"]:
1488 result = verify_rib(tgen, addr_type, dut, input_static_r1)
1489 assert result is True, "Testcase {}: Failed \n Error: {}".format(
1490 tc_name, result
1491 )
1492
1493 for dut, input_routes in zip(["r1"], [input_static_r1]):
1494 result = verify_rib(tgen, addr_type, dut, input_routes)
1495 assert result is True, "Testcase {}: Failed \n Error: {}".format(
1496 tc_name, result
1497 )
1498
1499 step(
1500 "Verify that AS-110 is got added in the AS list 110 200 100 by following"
1501 "commands at R3 router."
1502 )
1503 dut = "r3"
1504 aspath = "110 200 100"
1505 for addr_type in ADDR_TYPES:
1506 input_static_r1 = {"r1": {"static_routes": [{"network": NETWORK[addr_type]}]}}
1507 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
1508 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1509 tc_name, result
1510 )
1511
1512 step("Configure local-as with no-prepend at R3 towards R4 & R2.")
1513 for addr_type in ADDR_TYPES:
1514 for neighbor in ["r2", "r4"]:
1515 input_dict_r3 = {
1516 "r3": {
1517 "bgp": {
1518 "local_as": "300",
1519 "address_family": {
1520 addr_type: {
1521 "unicast": {
1522 "neighbor": {
1523 neighbor: {
1524 "dest_link": {
1525 "r3": {
1526 "local_asn": {
1527 "local_as": "110",
1528 "no_prepend": True,
1529 }
1530 }
1531 }
1532 }
1533 }
1534 }
1535 }
1536 },
1537 }
1538 }
1539 }
1540 result = create_router_bgp(tgen, topo, input_dict_r3)
1541 assert result is True, "Testcase {} :Failed \n Error: {}".format(
1542 tc_name, result
1543 )
1544
1545 step("BGP neighborship is verified by following commands in R3 routers")
1546 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
1547 assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format(
1548 BGP_CONVERGENCE
1549 )
1550
1551 step("Verify advertised routes to R4 at R3")
1552 expected_routes = {
1553 "ipv4": [
1554 {"network": "10.1.1.0/32", "nexthop": ""},
1555 ],
1556 "ipv6": [
1557 {"network": "10:1::1:0/128", "nexthop": ""},
1558 ],
1559 }
1560 result = verify_bgp_advertised_routes_from_neighbor(
1561 tgen, topo, dut="r3", peer="r4", expected_routes=expected_routes
1562 )
1563 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1564
1565 dut = "r3"
1566 aspath = "200 100"
1567 for addr_type in ADDR_TYPES:
1568 input_static_r1 = {"r1": {"static_routes": [{"network": NETWORK[addr_type]}]}}
1569 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
1570 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1571 tc_name, result
1572 )
1573
1574 step("Configure a route-map on R3 to prepend AS 2 times.")
1575 for addr_type in ADDR_TYPES:
1576 input_dict_4 = {
1577 "r3": {
1578 "route_maps": {
1579 "ASP_{}".format(addr_type): [
1580 {
1581 "action": "permit",
1582 "set": {
1583 "path": {"as_num": "1000 1000", "as_action": "prepend"}
1584 },
1585 }
1586 ]
1587 }
1588 }
1589 }
1590 result = create_route_maps(tgen, input_dict_4)
1591 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1592 tc_name, result
1593 )
1594
1595 step("configure route map in out direction on R4")
1596 # Configure neighbor for route map
1597 input_dict_7 = {
1598 "r3": {
1599 "bgp": {
1600 "address_family": {
1601 addr_type: {
1602 "unicast": {
1603 "neighbor": {
1604 "r4": {
1605 "dest_link": {
1606 "r3": {
1607 "route_maps": [
1608 {
1609 "name": "ASP_{}".format(
1610 addr_type
1611 ),
1612 "direction": "out",
1613 }
1614 ]
1615 }
1616 }
1617 }
1618 }
1619 }
1620 }
1621 }
1622 }
1623 }
1624 }
1625
1626 result = create_router_bgp(tgen, topo, input_dict_7)
1627 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1628 tc_name, result
1629 )
1630
1631 step("Configure local-as with no-prepend and replace-as at R3 towards R4 & R2.")
1632 for addr_type in ADDR_TYPES:
1633 for neighbor in ["r2", "r4"]:
1634 input_dict_r3 = {
1635 "r3": {
1636 "bgp": {
1637 "local_as": "300",
1638 "address_family": {
1639 addr_type: {
1640 "unicast": {
1641 "neighbor": {
1642 neighbor: {
1643 "dest_link": {
1644 "r3": {
1645 "local_asn": {
1646 "local_as": "110",
1647 "no_prepend": True,
1648 "replace_as": True,
1649 }
1650 }
1651 }
1652 }
1653 }
1654 }
1655 }
1656 },
1657 }
1658 }
1659 }
1660 result = create_router_bgp(tgen, topo, input_dict_r3)
1661 assert result is True, "Testcase {} :Failed \n Error: {}".format(
1662 tc_name, result
1663 )
1664
1665 step("BGP neighborship is verified by following commands in R3 routers")
1666 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
1667 assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format(
1668 BGP_CONVERGENCE
1669 )
1670
1671 step(
1672 "Verify that AS-300 is got replaced with 200 in the AS list 110 1000 1000 200 100 by following"
1673 "commands at R3 router."
1674 )
1675 dut = "r4"
1676 aspath = "110 1000 1000 200 100"
1677 for addr_type in ADDR_TYPES:
1678 input_static_r1 = {"r1": {"static_routes": [{"network": NETWORK[addr_type]}]}}
1679 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
1680 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1681 tc_name, result
1682 )
1683 write_test_footer(tc_name)
1684
1685
1686def test_verify_bgp_local_as_in_iBGP_p0(request):
1687 """
1688 Verify the BGP Local AS functionality by adding no-prepend and replace-as command in between iBGP Peers.
1689 """
1690 tgen = get_topogen()
1691 global BGP_CONVERGENCE
1692 if BGP_CONVERGENCE != True:
1693 pytest.skip("skipped because of BGP Convergence failure")
1694 # test case name
1695 tc_name = request.node.name
1696 write_test_header(tc_name)
1697 if tgen.routers_have_failure():
1698 check_router_status(tgen)
1699 reset_config_on_routers(tgen)
1700
1701 step("Modify AS Number for R3")
1702 input_dict_modify_as_number = {"r3": {"bgp": {"local_as": 200}}}
1703 result = modify_as_number(tgen, topo, input_dict_modify_as_number)
1704
1705 step("Base config is done as part of JSON")
1706 for addr_type in ADDR_TYPES:
1707 # Enable static routes
1708 input_dict_static_route = {
1709 "r1": {
1710 "static_routes": [
1711 {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]}
1712 ]
1713 }
1714 }
1715
1716 logger.info("Configure static routes")
1717 result = create_static_routes(tgen, input_dict_static_route)
1718 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1719 tc_name, result
1720 )
1721
1722 step("configure redistribute static in Router BGP in R1")
1723 input_dict_static_route_redist = {
1724 "r1": {
1725 "bgp": [
1726 {
1727 "address_family": {
1728 addr_type: {
1729 "unicast": {"redistribute": [{"redist_type": "static"}]}
1730 }
1731 }
1732 }
1733 ]
1734 }
1735 }
1736 result = create_router_bgp(tgen, topo, input_dict_static_route_redist)
1737 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1738 tc_name, result
1739 )
1740
1741 step("Verify IPv4 and IPv6 static routes received on R1")
1742 result = verify_rib(tgen, addr_type, "r1", input_dict_static_route)
1743 assert result is True, "Testcase {}: Failed \n Error: {}".format(
1744 tc_name, result
1745 )
1746 result = verify_bgp_rib(tgen, addr_type, "r1", input_dict_static_route)
1747 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1748 tc_name, result
1749 )
1750 result = verify_fib_routes(tgen, addr_type, "r1", input_dict_static_route)
1751 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1752 tc_name, result
1753 )
1754
1755 step("Configure local-as at R3 towards R4.")
1756 for addr_type in ADDR_TYPES:
1757 input_dict_r3_to_r4 = {
1758 "r3": {
1759 "bgp": [
1760 {
1761 "local_as": "200",
1762 "address_family": {
1763 addr_type: {
1764 "unicast": {
1765 "neighbor": {
1766 "r4": {
1767 "dest_link": {
1768 "r3": {"local_asn": {"local_as": "110"}}
1769 }
1770 }
1771 }
1772 }
1773 }
1774 },
1775 }
1776 ]
1777 }
1778 }
1779 result = create_router_bgp(tgen, topo, input_dict_r3_to_r4)
1780 assert result is True, "Testcase {} :Failed \n Error: {}".format(
1781 tc_name, result
1782 )
1783
1784 step("Configure remote-as at R4 towards R3.")
1785 for addr_type in ADDR_TYPES:
1786 input_dict_r4_to_r3 = {
1787 "r4": {
1788 "bgp": [
1789 {
1790 "local_as": "400",
1791 "address_family": {
1792 addr_type: {
1793 "unicast": {
1794 "neighbor": {
1795 "r3": {
1796 "dest_link": {
1797 "r4": {
1798 "local_asn": {"remote_as": "110"}
1799 }
1800 }
1801 }
1802 }
1803 }
1804 }
1805 },
1806 }
1807 ]
1808 }
1809 }
1810 result = create_router_bgp(tgen, topo, input_dict_r4_to_r3)
1811 assert result is True, "Testcase {} :Failed \n Error: {}".format(
1812 tc_name, result
1813 )
1814
1815 step("Configure remote-as at R2 towards R3.")
1816 for addr_type in ADDR_TYPES:
1817 input_dict_r2_to_r3 = {
1818 "r2": {
1819 "bgp": [
1820 {
1821 "local_as": "200",
1822 "address_family": {
1823 addr_type: {
1824 "unicast": {
1825 "neighbor": {
1826 "r3": {
1827 "dest_link": {
1828 "r2": {
1829 "next_hop_self": True,
1830 "local_asn": {
1831 "remote_as": "200",
1832 },
1833 }
1834 }
1835 }
1836 }
1837 }
1838 }
1839 },
1840 }
1841 ]
1842 }
1843 }
1844 result = create_router_bgp(tgen, topo, input_dict_r2_to_r3)
1845 assert result is True, "Testcase {} :Failed \n Error: {}".format(
1846 tc_name, result
1847 )
1848
1849 step("BGP neighborship is verified by following commands in R3 routers")
1850 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
1851 assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format(
1852 BGP_CONVERGENCE
1853 )
1854
1855 step("Verify IPv4 and IPv6 static routes received on R3 & R4")
1856 for addr_type in ADDR_TYPES:
1857 static_routes_input = {
1858 "r1": {
1859 "static_routes": [
1860 {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]}
1861 ]
1862 }
1863 }
1864 for dut in ["r3", "r4"]:
1865 result = verify_fib_routes(tgen, addr_type, dut, static_routes_input)
1866 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1867 tc_name, result
1868 )
1869
1870 result = verify_bgp_rib(tgen, addr_type, dut, static_routes_input)
1871 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1872 tc_name, result
1873 )
1874
1875 step(
1876 "Verify that AS-110 is got added in the AS list 110 200 100 by following "
1877 " commands at R3 router."
1878 )
1879 dut = "r3"
1880 aspath = "100"
1881 for addr_type in ADDR_TYPES:
1882 input_static_r1 = {"r1": {"static_routes": [{"network": NETWORK[addr_type]}]}}
1883 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
1884 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1885 tc_name, result
1886 )
1887
1888 dut = "r4"
1889 aspath = "110 200 100"
1890 for addr_type in ADDR_TYPES:
1891 input_static_r1 = {"r1": {"static_routes": [{"network": NETWORK[addr_type]}]}}
1892 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
1893 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1894 tc_name, result
1895 )
1896
1897 step("Configure local-as with no-prepend at R3 towards R4.")
1898 for addr_type in ADDR_TYPES:
1899 input_dict_no_prep_r3_to_r4 = {
1900 "r3": {
1901 "bgp": [
1902 {
1903 "local_as": "200",
1904 "address_family": {
1905 addr_type: {
1906 "unicast": {
1907 "neighbor": {
1908 "r4": {
1909 "dest_link": {
1910 "r3": {
1911 "local_asn": {
1912 "local_as": "110",
1913 "no_prepend": True,
1914 }
1915 }
1916 }
1917 }
1918 }
1919 }
1920 }
1921 },
1922 }
1923 ]
1924 }
1925 }
1926 result = create_router_bgp(tgen, topo, input_dict_no_prep_r3_to_r4)
1927 assert result is True, "Testcase {} :Failed \n Error: {}".format(
1928 tc_name, result
1929 )
1930
1931 step("BGP neighborship is verified by following commands in R3 routers")
1932 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
1933 assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format(
1934 BGP_CONVERGENCE
1935 )
1936
1937 dut = "r3"
1938 aspath = "100"
1939 for addr_type in ADDR_TYPES:
1940 input_static_r1 = {"r1": {"static_routes": [{"network": NETWORK[addr_type]}]}}
1941 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
1942 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1943 tc_name, result
1944 )
1945
1946 step("Configure local-as with no-prepend and replace-as at R3 towards R4")
1947 for addr_type in ADDR_TYPES:
1948 input_dict_no_prep_rep_as_r3_to_r4 = {
1949 "r3": {
1950 "bgp": [
1951 {
1952 "local_as": "200",
1953 "address_family": {
1954 addr_type: {
1955 "unicast": {
1956 "neighbor": {
1957 "r4": {
1958 "dest_link": {
1959 "r3": {
1960 "local_asn": {
1961 "local_as": "110",
1962 "no_prepend": True,
1963 "replace_as": True,
1964 }
1965 }
1966 }
1967 }
1968 }
1969 }
1970 }
1971 },
1972 }
1973 ]
1974 }
1975 }
1976 result = create_router_bgp(tgen, topo, input_dict_no_prep_rep_as_r3_to_r4)
1977 assert result is True, "Testcase {} :Failed \n Error: {}".format(
1978 tc_name, result
1979 )
1980
1981 step("BGP neighborship is verified by following commands in R3 routers")
1982 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
1983 assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format(
1984 BGP_CONVERGENCE
1985 )
1986
1987 dut = "r4"
1988 aspath = "110 100"
1989 for addr_type in ADDR_TYPES:
1990 input_static_r1 = {"r1": {"static_routes": [{"network": NETWORK[addr_type]}]}}
1991 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
1992 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1993 tc_name, result
1994 )
1995
1996 write_test_footer(tc_name)
1997
1998
1999def test_verify_bgp_local_as_allow_as_in_iBGP_p0(request):
2000 """
2001 Verify the BGP Local AS functionality with allowas-in in between iBGP Peers.
2002 """
2003 tgen = get_topogen()
2004 global BGP_CONVERGENCE
2005 if BGP_CONVERGENCE != True:
2006 pytest.skip("skipped because of BGP Convergence failure")
2007 # test case name
2008 tc_name = request.node.name
2009 write_test_header(tc_name)
2010 if tgen.routers_have_failure():
2011 check_router_status(tgen)
2012 reset_config_on_routers(tgen)
2013
2014 step("Modidy AS Number for R4")
2015 input_dict_modify_as_number = {"r4": {"bgp": {"local_as": 100}}}
2016 result = modify_as_number(tgen, topo, input_dict_modify_as_number)
2017
2018 step("Base config is done as part of JSON")
2019 dut = "r1"
2020 for addr_type in ADDR_TYPES:
2021 # Enable static routes
2022 input_dict_static_route = {
2023 "r1": {
2024 "static_routes": [
2025 {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]}
2026 ]
2027 }
2028 }
2029
2030 logger.info("Configure static routes")
2031 result = create_static_routes(tgen, input_dict_static_route)
2032 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2033 tc_name, result
2034 )
2035
2036 step("configure redistribute static in Router BGP in R1")
2037 input_dict_static_route_redist = {
2038 "r1": {
2039 "bgp": [
2040 {
2041 "address_family": {
2042 addr_type: {
2043 "unicast": {"redistribute": [{"redist_type": "static"}]}
2044 }
2045 }
2046 }
2047 ]
2048 }
2049 }
2050 result = create_router_bgp(tgen, topo, input_dict_static_route_redist)
2051 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2052 tc_name, result
2053 )
2054
2055 step("Verify IPv4 and IPv6 static routes received on R1")
2056 result = verify_rib(tgen, addr_type, "r1", input_dict_static_route)
2057 assert result is True, "Testcase {}: Failed \n Error: {}".format(
2058 tc_name, result
2059 )
2060 result = verify_bgp_rib(tgen, addr_type, "r1", input_dict_static_route)
2061 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2062 tc_name, result
2063 )
2064 result = verify_fib_routes(tgen, addr_type, "r1", input_dict_static_route)
2065 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2066 tc_name, result
2067 )
2068
2069 step("Configure allow-as at R4")
2070 for addr_type in ADDR_TYPES:
2071 allow_as_config_r4 = {
2072 "r4": {
2073 "bgp": [
2074 {
2075 "address_family": {
2076 addr_type: {
2077 "unicast": {
2078 "neighbor": {
2079 "r3": {
2080 "dest_link": {
2081 "r4": {
2082 "allowas-in": {
2083 "number_occurences": 1
2084 }
2085 }
2086 }
2087 }
2088 }
2089 }
2090 }
2091 }
2092 }
2093 ]
2094 }
2095 }
2096
2097 step(
2098 "Configuring allow-as for {} address-family on router R4 ".format(addr_type)
2099 )
2100 result = create_router_bgp(tgen, topo, allow_as_config_r4)
2101 assert result is True, "Testcase {} :Failed \n Error: {}".format(
2102 tc_name, result
2103 )
2104
2105 # now modify the as in r4 and reconfig bgp in r3 with new remote as.
2106 topo1 = deepcopy(topo)
2107 topo1["routers"]["r4"]["bgp"]["local_as"] = "100"
2108
2109 delete_bgp = {"r3": {"bgp": {"delete": True}}}
2110 result = create_router_bgp(tgen, topo1, delete_bgp)
2111 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
2112 build_config_from_json(tgen, topo1, save_bkup=False)
2113
2114 step("Configure local-as at R3 towards R2.")
2115 for addr_type in ADDR_TYPES:
2116 input_dict_r3_to_r2 = {
2117 "r3": {
2118 "bgp": [
2119 {
2120 "local_as": "300",
2121 "address_family": {
2122 addr_type: {
2123 "unicast": {
2124 "neighbor": {
2125 "r2": {
2126 "dest_link": {
2127 "r3": {"local_asn": {"local_as": "110"}}
2128 }
2129 }
2130 }
2131 }
2132 }
2133 },
2134 }
2135 ]
2136 }
2137 }
2138 result = create_router_bgp(tgen, topo1, input_dict_r3_to_r2)
2139 assert result is True, "Testcase {} :Failed \n Error: {}".format(
2140 tc_name, result
2141 )
2142
2143 step("Configure local-as at R3 towards R4.")
2144 for addr_type in ADDR_TYPES:
2145 input_dict_r3_to_r4 = {
2146 "r3": {
2147 "bgp": [
2148 {
2149 "local_as": "300",
2150 "address_family": {
2151 addr_type: {
2152 "unicast": {
2153 "neighbor": {
2154 "r4": {
2155 "dest_link": {
2156 "r3": {"local_asn": {"local_as": "110"}}
2157 }
2158 }
2159 }
2160 }
2161 }
2162 },
2163 }
2164 ]
2165 }
2166 }
2167 result = create_router_bgp(tgen, topo1, input_dict_r3_to_r4)
2168 assert result is True, "Testcase {} :Failed \n Error: {}".format(
2169 tc_name, result
2170 )
2171
2172 step("Configure remote-as at R2 towards R3.")
2173 for addr_type in ADDR_TYPES:
2174 input_dict_r2_to_r3 = {
2175 "r2": {
2176 "bgp": [
2177 {
2178 "local_as": "200",
2179 "address_family": {
2180 addr_type: {
2181 "unicast": {
2182 "neighbor": {
2183 "r3": {
2184 "dest_link": {
2185 "r2": {
2186 "local_asn": {"remote_as": "110"}
2187 }
2188 }
2189 }
2190 }
2191 }
2192 }
2193 },
2194 }
2195 ]
2196 }
2197 }
2198 result = create_router_bgp(tgen, topo1, input_dict_r2_to_r3)
2199 assert result is True, "Testcase {} :Failed \n Error: {}".format(
2200 tc_name, result
2201 )
2202
2203 step("Configure remote-as at R4 towards R3.")
2204 for addr_type in ADDR_TYPES:
2205 input_dict_r4_to_r3 = {
2206 "r4": {
2207 "bgp": [
2208 {
2209 "local_as": "100",
2210 "address_family": {
2211 addr_type: {
2212 "unicast": {
2213 "neighbor": {
2214 "r3": {
2215 "dest_link": {
2216 "r4": {
2217 "local_asn": {"remote_as": "110"}
2218 }
2219 }
2220 }
2221 }
2222 }
2223 }
2224 },
2225 }
2226 ]
2227 }
2228 }
2229 result = create_router_bgp(tgen, topo1, input_dict_r4_to_r3)
2230 assert result is True, "Testcase {} :Failed \n Error: {}".format(
2231 tc_name, result
2232 )
2233
2234 step("BGP neighborship is verified by following commands in R3 routers")
2235 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo1)
2236 assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format(
2237 BGP_CONVERGENCE
2238 )
2239
2240 step("Verify IPv4 and IPv6 static routes received on R3 & R4")
2241 for addr_type in ADDR_TYPES:
2242 static_routes_input = {
2243 "r1": {
2244 "static_routes": [
2245 {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]}
2246 ]
2247 }
2248 }
2249 for dut in ["r3", "r4"]:
2250 result = verify_fib_routes(tgen, addr_type, dut, static_routes_input)
2251 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2252 tc_name, result
2253 )
2254
2255 result = verify_bgp_rib(tgen, addr_type, dut, static_routes_input)
2256 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2257 tc_name, result
2258 )
2259
2260 step(
2261 "Verify that AS-110 is got added in the AS list 110 200 100 by following "
2262 " commands at R3 router."
2263 )
2264 dut = "r3"
2265 aspath = "110 200 100"
2266 for addr_type in ADDR_TYPES:
2267 input_static_r1 = {"r1": {"static_routes": [{"network": NETWORK[addr_type]}]}}
2268 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
2269 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2270 tc_name, result
2271 )
2272
2273 step("Configure local-as with no-prepend at R3 towards R2.")
2274 for addr_type in ADDR_TYPES:
2275 input_dict_no_prep_r3_to_r2 = {
2276 "r3": {
2277 "bgp": [
2278 {
2279 "local_as": "300",
2280 "address_family": {
2281 addr_type: {
2282 "unicast": {
2283 "neighbor": {
2284 "r2": {
2285 "dest_link": {
2286 "r3": {
2287 "local_asn": {
2288 "local_as": "110",
2289 "no_prepend": True,
2290 }
2291 }
2292 }
2293 }
2294 }
2295 }
2296 }
2297 },
2298 }
2299 ]
2300 }
2301 }
2302 result = create_router_bgp(tgen, topo1, input_dict_no_prep_r3_to_r2)
2303 assert result is True, "Testcase {} :Failed \n Error: {}".format(
2304 tc_name, result
2305 )
2306
2307 step("Configure local-as with no-prepend at R3 towards R4.")
2308 for addr_type in ADDR_TYPES:
2309 input_dict_no_prep_r3_to_r4 = {
2310 "r3": {
2311 "bgp": [
2312 {
2313 "local_as": "300",
2314 "address_family": {
2315 addr_type: {
2316 "unicast": {
2317 "neighbor": {
2318 "r4": {
2319 "dest_link": {
2320 "r3": {
2321 "local_asn": {
2322 "local_as": "110",
2323 "no_prepend": True,
2324 }
2325 }
2326 }
2327 }
2328 }
2329 }
2330 }
2331 },
2332 }
2333 ]
2334 }
2335 }
2336 result = create_router_bgp(tgen, topo1, input_dict_no_prep_r3_to_r4)
2337 assert result is True, "Testcase {} :Failed \n Error: {}".format(
2338 tc_name, result
2339 )
2340
2341 step("BGP neighborship is verified by following commands in R3 routers")
2342 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo1)
2343 assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format(
2344 BGP_CONVERGENCE
2345 )
2346
2347 dut = "r3"
2348 aspath = "200 100"
2349 for addr_type in ADDR_TYPES:
2350 input_static_r1 = {"r2": {"static_routes": [{"network": NETWORK[addr_type]}]}}
2351 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
2352 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2353 tc_name, result
2354 )
2355
2356 step("Configure local-as with no-prepend and replace-as at R3 towards R2")
2357 for addr_type in ADDR_TYPES:
2358 input_dict_no_prep_rep_as_r3_to_r2 = {
2359 "r3": {
2360 "bgp": [
2361 {
2362 "local_as": "300",
2363 "address_family": {
2364 addr_type: {
2365 "unicast": {
2366 "neighbor": {
2367 "r2": {
2368 "dest_link": {
2369 "r3": {
2370 "local_asn": {
2371 "local_as": "110",
2372 "no_prepend": True,
2373 "replace_as": True,
2374 }
2375 }
2376 }
2377 }
2378 }
2379 }
2380 }
2381 },
2382 }
2383 ]
2384 }
2385 }
2386 result = create_router_bgp(tgen, topo1, input_dict_no_prep_rep_as_r3_to_r2)
2387 assert result is True, "Testcase {} :Failed \n Error: {}".format(
2388 tc_name, result
2389 )
2390
2391 step("Configure local-as with no-prepend and replace-as at R3 towards R4")
2392 for addr_type in ADDR_TYPES:
2393 input_dict_no_prep_rep_as_r3_to_r4 = {
2394 "r3": {
2395 "bgp": [
2396 {
2397 "local_as": "300",
2398 "address_family": {
2399 addr_type: {
2400 "unicast": {
2401 "neighbor": {
2402 "r4": {
2403 "dest_link": {
2404 "r3": {
2405 "local_asn": {
2406 "local_as": "110",
2407 "no_prepend": True,
2408 "replace_as": True,
2409 }
2410 }
2411 }
2412 }
2413 }
2414 }
2415 }
2416 },
2417 }
2418 ]
2419 }
2420 }
2421 result = create_router_bgp(tgen, topo1, input_dict_no_prep_rep_as_r3_to_r4)
2422 assert result is True, "Testcase {} :Failed \n Error: {}".format(
2423 tc_name, result
2424 )
2425
2426 step("BGP neighborship is verified by following commands in R3 routers")
2427 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo1)
2428 assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format(
2429 BGP_CONVERGENCE
2430 )
2431
2432 dut = "r4"
2433 aspath = "110 200 100"
2434 for addr_type in ADDR_TYPES:
2435 input_static_r1 = {"r1": {"static_routes": [{"network": NETWORK[addr_type]}]}}
2436 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
2437 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2438 tc_name, result
2439 )
2440
2441 write_test_footer(tc_name)
2442
2443
2444def test_verify_bgp_local_as_in_EBGP_port_reset_p0(request):
2445 """
2446 Verify that BGP Local AS functionality by performing shut/ noshut on the interfaces in between BGP neighbors.
2447 """
2448 tgen = get_topogen()
2449 global BGP_CONVERGENCE
2450 if BGP_CONVERGENCE != True:
2451 pytest.skip("skipped because of BGP Convergence failure")
2452
2453 # test case name
2454 tc_name = request.node.name
2455 write_test_header(tc_name)
2456 if tgen.routers_have_failure():
2457 check_router_status(tgen)
2458 reset_config_on_routers(tgen)
2459
2460 step("Base config is done as part of JSON")
2461 step("Configure local-as at R3 towards R4.")
2462 for addr_type in ADDR_TYPES:
2463 for neighbor in ["r2", "r4"]:
2464 input_dict_r3 = {
2465 "r3": {
2466 "bgp": {
2467 "local_as": "300",
2468 "address_family": {
2469 addr_type: {
2470 "unicast": {
2471 "neighbor": {
2472 neighbor: {
2473 "dest_link": {
2474 "r3": {"local_asn": {"local_as": "110"}}
2475 }
2476 }
2477 }
2478 }
2479 }
2480 },
2481 }
2482 }
2483 }
2484 result = create_router_bgp(tgen, topo, input_dict_r3)
2485 assert result is True, "Testcase {} :Failed \n Error: {}".format(
2486 tc_name, result
2487 )
2488
2489 for addr_type in ADDR_TYPES:
2490 for dut, asn, neighbor in zip(["r2", "r4"], ["200", "400"], ["r3", "r3"]):
2491 input_dict_r2_r4 = {
2492 dut: {
2493 "bgp": {
2494 "local_as": asn,
2495 "address_family": {
2496 addr_type: {
2497 "unicast": {
2498 "neighbor": {
2499 neighbor: {
2500 "dest_link": {
2501 dut: {"local_asn": {"remote_as": "110"}}
2502 }
2503 }
2504 }
2505 }
2506 }
2507 },
2508 }
2509 }
2510 }
2511 result = create_router_bgp(tgen, topo, input_dict_r2_r4)
2512 assert result is True, "Testcase {} :Failed \n Error: {}".format(
2513 tc_name, result
2514 )
2515
2516 step("BGP neighborship is verified by following commands in R3 routers")
2517 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
2518 assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format(
2519 BGP_CONVERGENCE
2520 )
2521
2522 # configure static routes
2523 step("Done in base config: Advertise prefix 10.1.1.0/32 from Router-1(AS-100).")
2524 step(
2525 "Done in base config: Advertise an ipv6 prefix 10:1::1:0/128 from Router-1(AS-100)."
2526 )
2527 step("Verify that Static routes are redistributed in BGP process")
2528 dut = "r1"
2529 protocol = "bgp"
2530 for addr_type in ADDR_TYPES:
2531 # Enable static routes
2532 input_static_r1 = {
2533 "r1": {
2534 "static_routes": [
2535 {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]}
2536 ]
2537 }
2538 }
2539
2540 logger.info("Configure static routes")
2541 result = create_static_routes(tgen, input_static_r1)
2542 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2543 tc_name, result
2544 )
2545
2546 step("configure redistribute static in Router BGP in R1")
2547 input_static_redist_r1 = {
2548 "r1": {
2549 "bgp": {
2550 "address_family": {
2551 addr_type: {
2552 "unicast": {"redistribute": [{"redist_type": "static"}]}
2553 }
2554 }
2555 }
2556 }
2557 }
2558 result = create_router_bgp(tgen, topo, input_static_redist_r1)
2559 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2560 tc_name, result
2561 )
2562
2563 step("Verify that Static routes are redistributed in BGP process")
2564 for addr_type in ADDR_TYPES:
2565 input_static_verify_r1 = {
2566 "r1": {"static_routes": [{"network": NETWORK[addr_type]}]}
2567 }
2568
2569 result = verify_rib(tgen, addr_type, "r1", input_static_verify_r1)
2570 assert result is True, "Testcase {}: Failed \n Error: {}".format(
2571 tc_name, result
2572 )
2573
2574 for dut in ["r3", "r4"]:
2575 result = verify_rib(tgen, addr_type, dut, input_static_r1)
2576 assert result is True, "Testcase {}: Failed \n Error: {}".format(
2577 tc_name, result
2578 )
2579
2580 for dut, input_routes in zip(["r1"], [input_static_r1]):
2581 result = verify_rib(tgen, addr_type, dut, input_routes)
2582 assert result is True, "Testcase {}: Failed \n Error: {}".format(
2583 tc_name, result
2584 )
2585
2586 step("Api call to modfiy BGP timers at R3")
2587 for addr_type in ADDR_TYPES:
2588 input_dict_r3_timers = {
2589 "r3": {
2590 "bgp": {
2591 "local_as": "300",
2592 "address_family": {
2593 addr_type: {
2594 "unicast": {
2595 "neighbor": {
2596 "r4": {
2597 "dest_link": {
2598 "r3": {
2599 "keepalivetimer": KEEPALIVETIMER,
2600 "holddowntimer": HOLDDOWNTIMER,
2601 }
2602 }
2603 }
2604 }
2605 }
2606 }
2607 },
2608 }
2609 }
2610 }
2611 result = create_router_bgp(tgen, topo, input_dict_r3_timers)
2612 assert result is True, "Testcase {} :Failed \n Error: {}".format(
2613 tc_name, result
2614 )
2615
2616 step(
2617 "Verify that AS-110 is got added in the AS list 110 200 100 by following"
2618 "commands at R3 router."
2619 )
2620 dut = "r3"
2621 aspath = "110 200 100"
2622 for addr_type in ADDR_TYPES:
2623 input_static_r1 = {"r1": {"static_routes": [{"network": NETWORK[addr_type]}]}}
2624 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
2625 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2626 tc_name, result
2627 )
2628
2629 step("Verify advertised routes at R3 towards R4")
2630 expected_routes = {
2631 "ipv4": [
2632 {"network": "10.1.1.0/32", "nexthop": ""},
2633 ],
2634 "ipv6": [
2635 {"network": "10:1::1:0/128", "nexthop": ""},
2636 ],
2637 }
2638 result = verify_bgp_advertised_routes_from_neighbor(
2639 tgen, topo, dut="r3", peer="r4", expected_routes=expected_routes
2640 )
2641 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
2642
2643 for count in range(1, 1):
2644 step("Iteration {}".format(count))
2645 step("Shut down connecting interface between R3<<>>R4 on R3.")
2646
2647 intf1 = topo["routers"]["r3"]["links"]["r4"]["interface"]
2648
2649 interfaces = [intf1]
2650 for intf in interfaces:
2651 shutdown_bringup_interface(tgen, "r3", intf, False)
2652
2653 step(
2654 "On R3, all BGP peering in respective vrf instances go down"
2655 " when the interface is shut"
2656 )
2657
2658 result = verify_bgp_convergence(tgen, topo, expected=False)
2659 assert result is not True, (
2660 "Testcase {} :Failed \n "
2661 "Expected Behaviour: BGP will not be converged \n "
2662 "Error {}".format(tc_name, result)
2663 )
2664
2665 step("BGP neighborship is verified after restart of r3")
2666 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
2667 assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error: {}".format(
2668 BGP_CONVERGENCE
2669 )
2670
2671 step(
2672 "Verify that AS-110 is got added in the AS list 110 200 100 by following"
2673 "commands at R3 router."
2674 )
2675 dut = "r3"
2676 aspath = "110 200 100"
2677 for addr_type in ADDR_TYPES:
2678 input_static_r1 = {"r1": {"static_routes": [{"network": NETWORK[addr_type]}]}}
2679 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
2680 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2681 tc_name, result
2682 )
2683
2684 step("Configure local-as with no-prepend at R3 towards R4 & R2.")
2685 for addr_type in ADDR_TYPES:
2686 for neighbor in ["r2", "r4"]:
2687 input_dict_r3 = {
2688 "r3": {
2689 "bgp": {
2690 "local_as": "300",
2691 "address_family": {
2692 addr_type: {
2693 "unicast": {
2694 "neighbor": {
2695 neighbor: {
2696 "dest_link": {
2697 "r3": {
2698 "local_asn": {
2699 "local_as": "110",
2700 "no_prepend": True,
2701 }
2702 }
2703 }
2704 }
2705 }
2706 }
2707 }
2708 },
2709 }
2710 }
2711 }
2712 result = create_router_bgp(tgen, topo, input_dict_r3)
2713 assert result is True, "Testcase {} :Failed \n Error: {}".format(
2714 tc_name, result
2715 )
2716
2717 step("BGP neighborship is verified by following commands in R3 routers")
2718 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
2719 assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format(
2720 BGP_CONVERGENCE
2721 )
2722
2723 dut = "r3"
2724 aspath = "200 100"
2725 for addr_type in ADDR_TYPES:
2726 input_static_r1 = {"r1": {"static_routes": [{"network": NETWORK[addr_type]}]}}
2727 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
2728 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2729 tc_name, result
2730 )
2731
2732 step("Configure local-as with no-prepend and replace-as at R3 towards R4 & R2.")
2733 for addr_type in ADDR_TYPES:
2734 for neighbor in ["r2", "r4"]:
2735 input_dict_r3 = {
2736 "r3": {
2737 "bgp": {
2738 "local_as": "300",
2739 "address_family": {
2740 addr_type: {
2741 "unicast": {
2742 "neighbor": {
2743 neighbor: {
2744 "dest_link": {
2745 "r3": {
2746 "local_asn": {
2747 "local_as": "110",
2748 "no_prepend": True,
2749 "replace_as": True,
2750 }
2751 }
2752 }
2753 }
2754 }
2755 }
2756 }
2757 },
2758 }
2759 }
2760 }
2761 result = create_router_bgp(tgen, topo, input_dict_r3)
2762 assert result is True, "Testcase {} :Failed \n Error: {}".format(
2763 tc_name, result
2764 )
2765
2766 step("BGP neighborship is verified by following commands in R3 routers")
2767 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
2768 assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format(
2769 BGP_CONVERGENCE
2770 )
2771
2772 dut = "r4"
2773 aspath = "110 200 100"
2774 for addr_type in ADDR_TYPES:
2775 input_static_r1 = {"r1": {"static_routes": [{"network": NETWORK[addr_type]}]}}
2776 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
2777 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2778 tc_name, result
2779 )
2780
2781 write_test_footer(tc_name)
2782
2783
2784def test_verify_bgp_local_as_in_EBGP_negative2_p0(request):
2785 """
2786 Verify the BGP Local AS functionality with different AS configurations.
2787 """
2788 tgen = get_topogen()
2789 global BGP_CONVERGENCE
2790 if BGP_CONVERGENCE != True:
2791 pytest.skip("skipped because of BGP Convergence failure")
2792
2793 # test case name
2794 tc_name = request.node.name
2795 write_test_header(tc_name)
2796 if tgen.routers_have_failure():
2797 check_router_status(tgen)
2798 reset_config_on_routers(tgen)
2799
2800 step("Base config is done as part of JSON")
2801 step("Configure local-as at R3 towards R4.")
2802 for addr_type in ADDR_TYPES:
2803 for neighbor in ["r2", "r4"]:
2804 input_dict_r3 = {
2805 "r3": {
2806 "bgp": {
2807 "local_as": "300",
2808 "address_family": {
2809 addr_type: {
2810 "unicast": {
2811 "neighbor": {
2812 neighbor: {
2813 "dest_link": {
2814 "r3": {"local_asn": {"local_as": "110"}}
2815 }
2816 }
2817 }
2818 }
2819 }
2820 },
2821 }
2822 }
2823 }
2824 result = create_router_bgp(tgen, topo, input_dict_r3)
2825 assert result is True, "Testcase {} :Failed \n Error: {}".format(
2826 tc_name, result
2827 )
2828
2829 for addr_type in ADDR_TYPES:
2830 for dut, asn, neighbor in zip(["r2", "r4"], ["200", "400"], ["r3", "r3"]):
2831 input_dict_r2_r4 = {
2832 dut: {
2833 "bgp": {
2834 "local_as": asn,
2835 "address_family": {
2836 addr_type: {
2837 "unicast": {
2838 "neighbor": {
2839 neighbor: {
2840 "dest_link": {
2841 dut: {"local_asn": {"remote_as": "110"}}
2842 }
2843 }
2844 }
2845 }
2846 }
2847 },
2848 }
2849 }
2850 }
2851 result = create_router_bgp(tgen, topo, input_dict_r2_r4)
2852 assert result is True, "Testcase {} :Failed \n Error: {}".format(
2853 tc_name, result
2854 )
2855
2856 step("BGP neighborship is verified by following commands in R3 routers")
2857 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
2858 assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format(
2859 BGP_CONVERGENCE
2860 )
2861
2862 # configure static routes
2863 step("Done in base config: Advertise prefix 10.1.1.0/32 from Router-1(AS-100).")
2864 step(
2865 "Done in base config: Advertise an ipv6 prefix 10:1::1:0/128 from Router-1(AS-100)."
2866 )
2867 step("Verify that Static routes are redistributed in BGP process")
2868
2869 dut = "r1"
2870 protocol = "bgp"
2871 for addr_type in ADDR_TYPES:
2872 # Enable static routes
2873 input_static_r1 = {
2874 "r1": {
2875 "static_routes": [
2876 {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]}
2877 ]
2878 }
2879 }
2880
2881 logger.info("Configure static routes")
2882 result = create_static_routes(tgen, input_static_r1)
2883 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2884 tc_name, result
2885 )
2886
2887 step("configure redistribute static in Router BGP in R1")
2888
2889 input_static_redist_r1 = {
2890 "r1": {
2891 "bgp": {
2892 "address_family": {
2893 addr_type: {
2894 "unicast": {"redistribute": [{"redist_type": "static"}]}
2895 }
2896 }
2897 }
2898 }
2899 }
2900 result = create_router_bgp(tgen, topo, input_static_redist_r1)
2901 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2902 tc_name, result
2903 )
2904
2905 step("Verify that Static routes are redistributed in BGP process")
2906 for addr_type in ADDR_TYPES:
2907 input_static_verify_r1 = {
2908 "r1": {"static_routes": [{"network": NETWORK[addr_type]}]}
2909 }
2910
2911 result = verify_rib(tgen, addr_type, "r1", input_static_verify_r1)
2912 assert result is True, "Testcase {}: Failed \n Error: {}".format(
2913 tc_name, result
2914 )
2915
2916 for dut in ["r3", "r4"]:
2917 result = verify_rib(tgen, addr_type, dut, input_static_r1)
2918 assert result is True, "Testcase {}: Failed \n Error: {}".format(
2919 tc_name, result
2920 )
2921
2922 for dut, input_routes in zip(["r1"], [input_static_r1]):
2923 result = verify_rib(tgen, addr_type, dut, input_routes)
2924 assert result is True, "Testcase {}: Failed \n Error: {}".format(
2925 tc_name, result
2926 )
2927
2928 step(
2929 "Verify that AS-110 is got added in the AS list 110 200 100 by following"
2930 "commands at R3 router."
2931 )
2932 dut = "r3"
2933 aspath = "110 200 100"
2934 for addr_type in ADDR_TYPES:
2935 input_static_r1 = {"r1": {"static_routes": [{"network": NETWORK[addr_type]}]}}
2936 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
2937 assert result is True, "Testcase {} : Failed \n Error: {}".format(
2938 tc_name, result
2939 )
2940
2941 step("Configure local-as with no-prepend at R3 towards R4 & R2.")
2942 for addr_type in ADDR_TYPES:
2943 for neighbor in ["r2", "r4"]:
2944 input_dict_r3 = {
2945 "r3": {
2946 "bgp": {
2947 "local_as": "300",
2948 "address_family": {
2949 addr_type: {
2950 "unicast": {
2951 "neighbor": {
2952 neighbor: {
2953 "dest_link": {
2954 "r3": {
2955 "local_asn": {
2956 "local_as": "110",
2957 "no_prepend": True,
2958 }
2959 }
2960 }
2961 }
2962 }
2963 }
2964 }
2965 },
2966 }
2967 }
2968 }
2969 result = create_router_bgp(tgen, topo, input_dict_r3)
2970 assert result is True, "Testcase {} :Failed \n Error: {}".format(
2971 tc_name, result
2972 )
2973
2974 step("BGP neighborship is verified by following commands in R3 routers")
2975 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
2976 assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format(
2977 BGP_CONVERGENCE
2978 )
2979
2980 step("Verify advertised routes to R4 at R3")
2981 expected_routes = {
2982 "ipv4": [
2983 {"network": "10.1.1.0/32", "nexthop": ""},
2984 ],
2985 "ipv6": [
2986 {"network": "10:1::1:0/128", "nexthop": ""},
2987 ],
2988 }
2989 result = verify_bgp_advertised_routes_from_neighbor(
2990 tgen, topo, dut="r3", peer="r4", expected_routes=expected_routes
2991 )
2992 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
2993
2994 step(
2995 "Verify that AS-110 is not prepended in the AS list 110 200 100 by following"
2996 "commands at R3 router."
2997 )
2998 dut = "r3"
2999 aspath = "200 100"
3000 for addr_type in ADDR_TYPES:
3001 input_static_r1 = {"r1": {"static_routes": [{"network": NETWORK[addr_type]}]}}
3002 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
3003 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3004 tc_name, result
3005 )
3006
3007 step("Configure local-as with no-prepend and replace-as at R3 towards R4 & R2.")
3008 for addr_type in ADDR_TYPES:
3009 for neighbor in ["r2", "r4"]:
3010 input_dict_r3 = {
3011 "r3": {
3012 "bgp": {
3013 "local_as": "300",
3014 "address_family": {
3015 addr_type: {
3016 "unicast": {
3017 "neighbor": {
3018 neighbor: {
3019 "dest_link": {
3020 "r3": {
3021 "local_asn": {
3022 "local_as": "110",
3023 "no_prepend": True,
3024 "replace_as": True,
3025 }
3026 }
3027 }
3028 }
3029 }
3030 }
3031 }
3032 },
3033 }
3034 }
3035 }
3036 result = create_router_bgp(tgen, topo, input_dict_r3)
3037 assert result is True, "Testcase {} :Failed \n Error: {}".format(
3038 tc_name, result
3039 )
3040
3041 step("BGP neighborship is verified by following commands in R3 routers")
3042 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
3043 assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format(
3044 BGP_CONVERGENCE
3045 )
3046 step("Verify that AS-300 is replaced with AS-110 at R3 router.")
3047 dut = "r4"
3048 aspath = "110 200 100"
3049 for addr_type in ADDR_TYPES:
3050 input_static_r1 = {"r1": {"static_routes": [{"network": NETWORK[addr_type]}]}}
3051 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
3052 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3053 tc_name, result
3054 )
3055
3056 # configure negative scenarios
3057 step("Configure local-as at R3 towards R4.")
3058 input_dict_r3 = {
3059 "r3": {
3060 "bgp": {
3061 "local_as": "300",
3062 "address_family": {
3063 "ipv4": {
3064 "unicast": {
3065 "neighbor": {
3066 "r4": {
3067 "dest_link": {
3068 "r3": {"local_asn": {"local_as": "300"}}
3069 }
3070 }
3071 }
3072 }
3073 }
3074 },
3075 }
3076 }
3077 }
3078 if "bgp" in topo["routers"]["r3"].keys():
3079 result = create_router_bgp(tgen, topo, input_dict_r3)
3080 assert result is not True, (
3081 "Testcase {} :Failed \n "
3082 "Expected Behaviour: Cannot have local-as same as BGP AS number \n "
3083 "Error {}".format(tc_name, result)
3084 )
3085
3086 step("Configure another local-as at R3 towards R4.")
3087 input_dict_r3 = {
3088 "r3": {
3089 "bgp": {
3090 "local_as": "110",
3091 "address_family": {
3092 "ipv4": {
3093 "unicast": {
3094 "neighbor": {
3095 "r4": {
3096 "dest_link": {
3097 "r3": {"local_asn": {"local_as": "110"}}
3098 }
3099 }
3100 }
3101 }
3102 }
3103 },
3104 }
3105 }
3106 }
3107 if "bgp" in topo["routers"]["r3"].keys():
3108 result = create_router_bgp(tgen, topo, input_dict_r3)
3109 assert result is not True, (
3110 "Testcase {} :Failed \n "
3111 "Expected Behaviour: Cannot have local-as same as BGP AS number \n "
3112 "Error {}".format(tc_name, result)
3113 )
3114
3115 step("BGP neighborship is verified by following commands in R3 routers")
3116 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
3117 assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format(
3118 BGP_CONVERGENCE
3119 )
3120
3121 write_test_footer(tc_name)
3122
3123
3124def test_verify_bgp_local_as_in_EBGP_negative3_p0(request):
3125 """
3126 Verify the BGP Local AS functionality with R3& R4 with different AS configurations.
3127 """
3128 tgen = get_topogen()
3129 global BGP_CONVERGENCE
3130
3131 if BGP_CONVERGENCE != True:
3132 pytest.skip("skipped because of BGP Convergence failure")
3133 # test case name
3134 tc_name = request.node.name
3135 write_test_header(tc_name)
3136 if tgen.routers_have_failure():
3137 check_router_status(tgen)
3138 reset_config_on_routers(tgen)
3139
3140 step("Configure basic BGP Peerings between R1,R2,R3 and R4")
3141 step("Configure local-as at R3 towards R4.")
3142 for addr_type in ADDR_TYPES:
3143 for neighbor in ["r2", "r4"]:
3144 input_dict_r3 = {
3145 "r3": {
3146 "bgp": {
3147 "local_as": "300",
3148 "address_family": {
3149 addr_type: {
3150 "unicast": {
3151 "neighbor": {
3152 neighbor: {
3153 "dest_link": {
3154 "r3": {"local_asn": {"local_as": "110"}}
3155 }
3156 }
3157 }
3158 }
3159 }
3160 },
3161 }
3162 }
3163 }
3164 result = create_router_bgp(tgen, topo, input_dict_r3)
3165 assert result is True, "Testcase {} :Failed \n Error: {}".format(
3166 tc_name, result
3167 )
3168
3169 for addr_type in ADDR_TYPES:
3170 for dut, asn, neighbor in zip(["r2", "r4"], ["200", "400"], ["r3", "r3"]):
3171 input_dict_r2_r4 = {
3172 dut: {
3173 "bgp": {
3174 "local_as": asn,
3175 "address_family": {
3176 addr_type: {
3177 "unicast": {
3178 "neighbor": {
3179 neighbor: {
3180 "dest_link": {
3181 dut: {"local_asn": {"remote_as": "110"}}
3182 }
3183 }
3184 }
3185 }
3186 }
3187 },
3188 }
3189 }
3190 }
3191 result = create_router_bgp(tgen, topo, input_dict_r2_r4)
3192 assert result is True, "Testcase {} :Failed \n Error: {}".format(
3193 tc_name, result
3194 )
3195
3196 step("BGP neighborship is verified by following commands in R3 routers")
3197 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
3198 assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format(
3199 BGP_CONVERGENCE
3200 )
3201
3202 # configure static routes
3203 step("Done in base config: Advertise prefix 10.1.1.0/32 from Router-1(AS-100).")
3204 step(
3205 "Done in base config: Advertise an ipv6 prefix 10:1::1:0/128 from Router-1(AS-100)."
3206 )
3207 step("Verify that Static routes are redistributed in BGP process")
3208
3209 dut = "r1"
3210 protocol = "bgp"
3211 for addr_type in ADDR_TYPES:
3212 # Enable static routes
3213 input_static_r1 = {
3214 "r1": {
3215 "static_routes": [
3216 {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]}
3217 ]
3218 }
3219 }
3220
3221 logger.info("Configure static routes")
3222 result = create_static_routes(tgen, input_static_r1)
3223 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3224 tc_name, result
3225 )
3226
3227 step("configure redistribute static in Router BGP in R1")
3228
3229 input_static_redist_r1 = {
3230 "r1": {
3231 "bgp": {
3232 "address_family": {
3233 addr_type: {
3234 "unicast": {"redistribute": [{"redist_type": "static"}]}
3235 }
3236 }
3237 }
3238 }
3239 }
3240 result = create_router_bgp(tgen, topo, input_static_redist_r1)
3241 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3242 tc_name, result
3243 )
3244
3245 step("Verify that Static routes are redistributed in BGP process")
3246 for addr_type in ADDR_TYPES:
3247 input_static_verify_r1 = {
3248 "r1": {"static_routes": [{"network": NETWORK[addr_type]}]}
3249 }
3250
3251 result = verify_rib(tgen, addr_type, "r1", input_static_verify_r1)
3252 assert result is True, "Testcase {}: Failed \n Error: {}".format(
3253 tc_name, result
3254 )
3255
3256 for dut in ["r3", "r4"]:
3257 result = verify_rib(tgen, addr_type, dut, input_static_r1)
3258 assert result is True, "Testcase {}: Failed \n Error: {}".format(
3259 tc_name, result
3260 )
3261
3262 for dut, input_routes in zip(["r1"], [input_static_r1]):
3263 result = verify_rib(tgen, addr_type, dut, input_routes)
3264 assert result is True, "Testcase {}: Failed \n Error: {}".format(
3265 tc_name, result
3266 )
3267
3268 step(
3269 "Verify that AS-110 is got added in the AS list 110 200 100 by following"
3270 "commands at R3 router."
3271 )
3272 dut = "r3"
3273 aspath = "110 200 100"
3274 for addr_type in ADDR_TYPES:
3275 input_static_r1 = {"r1": {"static_routes": [{"network": NETWORK[addr_type]}]}}
3276 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
3277 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3278 tc_name, result
3279 )
3280
3281 # Perform Negative scenarios
3282 step("Configure another local-as at R3 towards R4.")
3283 input_dict_r3 = {
3284 "r3": {
3285 "bgp": {
3286 "local_as": "300",
3287 "address_family": {
3288 "ipv4": {
3289 "unicast": {
3290 "neighbor": {
3291 "r4": {
3292 "dest_link": {
3293 "r3": {"local_asn": {"local_as": "300"}}
3294 }
3295 }
3296 }
3297 }
3298 }
3299 },
3300 }
3301 }
3302 }
3303 if "bgp" in topo["routers"]["r3"].keys():
3304 result = create_router_bgp(tgen, topo, input_dict_r3)
3305 assert result is not True, (
3306 "Testcase {} :Failed \n "
3307 "Expected Behaviour: Cannot have local-as same as BGP AS number \n "
3308 "Error {}".format(tc_name, result)
3309 )
3310
3311 write_test_footer(tc_name)
3312
3313
3314def test_verify_bgp_local_as_in_EBGP_restart_daemons_p0(request):
3315 """
3316 Verify that BGP Local AS functionality by restarting BGP,Zebra and FRR services and
3317 further restarting clear BGP * and shutdown BGP neighbor.
3318 """
3319 tgen = get_topogen()
3320 global BGP_CONVERGENCE
3321 if BGP_CONVERGENCE != True:
3322 pytest.skip("skipped because of BGP Convergence failure")
3323 # test case name
3324 tc_name = request.node.name
3325 write_test_header(tc_name)
3326 if tgen.routers_have_failure():
3327 check_router_status(tgen)
3328 reset_config_on_routers(tgen)
3329
3330 step("Base config is done as part of JSON")
3331 step("Configure local-as at R3 towards R4.")
3332 for addr_type in ADDR_TYPES:
3333 for neighbor in ["r2", "r4"]:
3334 input_dict_r3 = {
3335 "r3": {
3336 "bgp": {
3337 "local_as": "300",
3338 "address_family": {
3339 addr_type: {
3340 "unicast": {
3341 "neighbor": {
3342 neighbor: {
3343 "dest_link": {
3344 "r3": {"local_asn": {"local_as": "110"}}
3345 }
3346 }
3347 }
3348 }
3349 }
3350 },
3351 }
3352 }
3353 }
3354 result = create_router_bgp(tgen, topo, input_dict_r3)
3355 assert result is True, "Testcase {} :Failed \n Error: {}".format(
3356 tc_name, result
3357 )
3358
3359 for addr_type in ADDR_TYPES:
3360 for dut, asn, neighbor in zip(["r2", "r4"], ["200", "400"], ["r3", "r3"]):
3361 input_dict_r2_r4 = {
3362 dut: {
3363 "bgp": {
3364 "local_as": asn,
3365 "address_family": {
3366 addr_type: {
3367 "unicast": {
3368 "neighbor": {
3369 neighbor: {
3370 "dest_link": {
3371 dut: {"local_asn": {"remote_as": "110"}}
3372 }
3373 }
3374 }
3375 }
3376 }
3377 },
3378 }
3379 }
3380 }
3381 result = create_router_bgp(tgen, topo, input_dict_r2_r4)
3382 assert result is True, "Testcase {} :Failed \n Error: {}".format(
3383 tc_name, result
3384 )
3385
3386 step("BGP neighborship is verified by following commands in R3 routers")
3387 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
3388 assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format(
3389 BGP_CONVERGENCE
3390 )
3391
3392 # configure static routes
3393 step("Done in base config: Advertise prefix 10.1.1.0/32 from Router-1(AS-100).")
3394 step(
3395 "Done in base config: Advertise an ipv6 prefix 10:1::1:0/128 from Router-1(AS-100)."
3396 )
3397 step("Verify that Static routes are redistributed in BGP process")
3398 dut = "r1"
3399 protocol = "bgp"
3400 for addr_type in ADDR_TYPES:
3401 # Enable static routes
3402 input_static_r1 = {
3403 "r1": {
3404 "static_routes": [
3405 {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]}
3406 ]
3407 }
3408 }
3409
3410 logger.info("Configure static routes")
3411 result = create_static_routes(tgen, input_static_r1)
3412 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3413 tc_name, result
3414 )
3415
3416 step("configure redistribute static in Router BGP in R1")
3417 input_static_redist_r1 = {
3418 "r1": {
3419 "bgp": {
3420 "address_family": {
3421 addr_type: {
3422 "unicast": {"redistribute": [{"redist_type": "static"}]}
3423 }
3424 }
3425 }
3426 }
3427 }
3428 result = create_router_bgp(tgen, topo, input_static_redist_r1)
3429 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3430 tc_name, result
3431 )
3432
3433 step("Verify that Static routes are redistributed in BGP process")
3434 for addr_type in ADDR_TYPES:
3435 input_static_verify_r1 = {
3436 "r1": {"static_routes": [{"network": NETWORK[addr_type]}]}
3437 }
3438
3439 result = verify_rib(tgen, addr_type, "r1", input_static_verify_r1)
3440 assert result is True, "Testcase {}: Failed \n Error: {}".format(
3441 tc_name, result
3442 )
3443
3444 for dut in ["r3", "r4"]:
3445 result = verify_rib(tgen, addr_type, dut, input_static_r1)
3446 assert result is True, "Testcase {}: Failed \n Error: {}".format(
3447 tc_name, result
3448 )
3449
3450 for dut, input_routes in zip(["r1"], [input_static_r1]):
3451 result = verify_rib(tgen, addr_type, dut, input_routes)
3452 assert result is True, "Testcase {}: Failed \n Error: {}".format(
3453 tc_name, result
3454 )
3455
3456 step(
3457 "Verify that AS-110 is got added in the AS list 110 200 100 by following"
3458 "commands at R3 router."
3459 )
3460 dut = "r3"
3461 aspath = "110 200 100"
3462 for addr_type in ADDR_TYPES:
3463 input_static_r1 = {"r1": {"static_routes": [{"network": NETWORK[addr_type]}]}}
3464 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
3465 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3466 tc_name, result
3467 )
3468
3469 step("Kill BGPd daemon on R3.")
3470 kill_router_daemons(tgen, "r3", ["bgpd"])
3471
3472 step("Bring up BGPd daemon on R3.")
3473 start_router_daemons(tgen, "r3", ["bgpd"])
3474
3475 step(
3476 "Verify that AS-110 is got added in the AS list 110 200 100 by following"
3477 "commands at R3 router."
3478 )
3479 dut = "r3"
3480 aspath = "110 200 100"
3481 for addr_type in ADDR_TYPES:
3482 input_static_r1 = {"r1": {"static_routes": [{"network": NETWORK[addr_type]}]}}
3483 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
3484 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3485 tc_name, result
3486 )
3487
3488 step("Verify advertised routes at R3 towards R4")
3489 expected_routes = {
3490 "ipv4": [
3491 {"network": "10.1.1.0/32", "nexthop": ""},
3492 ],
3493 "ipv6": [
3494 {"network": "10:1::1:0/128", "nexthop": ""},
3495 ],
3496 }
3497 result = verify_bgp_advertised_routes_from_neighbor(
3498 tgen, topo, dut="r3", peer="r4", expected_routes=expected_routes
3499 )
3500 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
3501
3502 step("Configure local-as with no-prepend at R3 towards R4 & R2.")
3503 for addr_type in ADDR_TYPES:
3504 for neighbor in ["r2", "r4"]:
3505 input_dict_r3 = {
3506 "r3": {
3507 "bgp": {
3508 "local_as": "300",
3509 "address_family": {
3510 addr_type: {
3511 "unicast": {
3512 "neighbor": {
3513 neighbor: {
3514 "dest_link": {
3515 "r3": {
3516 "local_asn": {
3517 "local_as": "110",
3518 "no_prepend": True,
3519 }
3520 }
3521 }
3522 }
3523 }
3524 }
3525 }
3526 },
3527 }
3528 }
3529 }
3530 result = create_router_bgp(tgen, topo, input_dict_r3)
3531 assert result is True, "Testcase {} :Failed \n Error: {}".format(
3532 tc_name, result
3533 )
3534
3535 step("BGP neighborship is verified by following commands in R3 routers")
3536 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
3537 assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format(
3538 BGP_CONVERGENCE
3539 )
3540
3541 step(
3542 "Verify that AS-110 is not prepended in the AS list 200 100 by following "
3543 "commands at R3 router."
3544 )
3545 dut = "r3"
3546 aspath = "200 100"
3547 for addr_type in ADDR_TYPES:
3548 input_static_r1 = {"r1": {"static_routes": [{"network": NETWORK[addr_type]}]}}
3549 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
3550 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3551 tc_name, result
3552 )
3553
3554 step("Kill BGPd daemon on R3.")
3555 kill_router_daemons(tgen, "r3", ["bgpd"])
3556
3557 step("Bring up BGPd daemon on R3.")
3558 start_router_daemons(tgen, "r3", ["bgpd"])
3559
3560 step(
3561 "Verify that AS-110 is not prepended in the AS list 200 100 by following "
3562 "commands at R3 router."
3563 )
3564 dut = "r3"
3565 aspath = "200 100"
3566 for addr_type in ADDR_TYPES:
3567 input_static_r1 = {"r1": {"static_routes": [{"network": NETWORK[addr_type]}]}}
3568 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
3569 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3570 tc_name, result
3571 )
3572
3573 step("Configure local-as with no-prepend and replace-as at R3 towards R4 & R2.")
3574 for addr_type in ADDR_TYPES:
3575 for neighbor in ["r2", "r4"]:
3576 input_dict_r3 = {
3577 "r3": {
3578 "bgp": {
3579 "local_as": "300",
3580 "address_family": {
3581 addr_type: {
3582 "unicast": {
3583 "neighbor": {
3584 neighbor: {
3585 "dest_link": {
3586 "r3": {
3587 "local_asn": {
3588 "local_as": "110",
3589 "no_prepend": True,
3590 "replace_as": True,
3591 }
3592 }
3593 }
3594 }
3595 }
3596 }
3597 }
3598 },
3599 }
3600 }
3601 }
3602 result = create_router_bgp(tgen, topo, input_dict_r3)
3603 assert result is True, "Testcase {} :Failed \n Error: {}".format(
3604 tc_name, result
3605 )
3606
3607 step("BGP neighborship is verified by following commands in R3 routers")
3608 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
3609 assert BGP_CONVERGENCE is True, "BGP convergence :Failed \n Error: {}".format(
3610 BGP_CONVERGENCE
3611 )
3612
3613 step(
3614 "Verified that AS-300 is got replaced with original AS-110 at R4 by following commands"
3615 )
3616 dut = "r4"
3617 aspath = "110 200 100"
3618 for addr_type in ADDR_TYPES:
3619 input_static_r1 = {"r1": {"static_routes": [{"network": NETWORK[addr_type]}]}}
3620 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
3621 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3622 tc_name, result
3623 )
3624
3625 step(
3626 "Verified that AS-300 is got replaced with original AS-110 at R4 by following commands"
3627 )
3628 dut = "r4"
3629 aspath = "110 200 100"
3630 for addr_type in ADDR_TYPES:
3631 input_static_r1 = {"r1": {"static_routes": [{"network": NETWORK[addr_type]}]}}
3632 result = verify_bgp_rib(tgen, addr_type, dut, input_static_r1, aspath=aspath)
3633 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3634 tc_name, result
3635 )
3636
3637 write_test_footer(tc_name)
3638
3639
3640if __name__ == "__main__":
3641 args = ["-s"] + sys.argv[1:]
3642 sys.exit(pytest.main(args))