2 # SPDX-License-Identifier: ISC
4 # Copyright (c) 2020 by VMware, Inc. ("VMware")
5 # Used Copyright (c) 2018 by Network Device Education Foundation,
6 # Inc. ("NetDEF") in this file.
10 Following tests are covered to test bgp recursive route and ebgp
11 multi-hop functionality:
13 1. Verify that BGP routes are installed in iBGP peer, only when there
14 is a recursive route for next-hop reachability.
15 2. Verify that any BGP prefix received with next hop as self-ip is
16 not installed in BGP RIB or FIB table.
17 3. Verify password authentication for eBGP and iBGP peers.
18 4. Verify that for a BGP prefix next-hop information doesn't change
19 when same prefix is received from another peer via recursive lookup.
20 5. Verify that BGP path attributes are present in CLI outputs and
21 JSON format, even if set to default.
22 6. Verifying the BGP peering between loopback and physical link's IP
24 7. Verify that BGP Active/Standby/Pre-emption/ECMP.
31 from time
import sleep
33 # Save the Current Working Directory to find configuration files.
34 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
35 sys
.path
.append(os
.path
.join(CWD
, "../"))
37 # pylint: disable=C0413
38 # Import topogen and topotest helpers
39 from lib
.topogen
import Topogen
, get_topogen
41 # Import topoJson from lib, to create topology and initial configuration
42 from lib
.common_config
import (
47 reset_config_on_routers
,
53 create_interface_in_kernel
,
54 shutdown_bringup_interface
,
56 from lib
.topolog
import logger
58 verify_bgp_convergence
,
61 verify_bgp_convergence_from_running_config
,
63 verify_bgp_attributes
,
66 from lib
.topojson
import build_config_from_json
69 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.staticd
]
73 BGP_CONVERGENCE
= False
76 ADDR_TYPES
= check_address_types()
78 "ipv4": ["100.1.1.1/32", "100.1.1.2/32"],
79 "ipv6": ["100::1/128", "100::2/128"],
83 "N1": {"ipv4": "20.20.20.20/24", "ipv6": "20:20::20:20/120"},
84 "N2": {"ipv4": "30.30.30.30/24", "ipv6": "30:30::30:30/120"},
85 "N3": {"ipv4": "40.40.40.40/24", "ipv6": "40:40::40:40/120"},
89 "4thOctate": {"ipv4": "10.0.1.250/24", "ipv6": "fd00:0:0:1::100/64"},
90 "3rdOctate": {"ipv4": "10.0.10.2/24", "ipv6": "fd00:0:0:10::2/64"},
94 "Lo_R1": {"ipv4": "1.1.1.1/32", "ipv6": "1:1::1:1/128"},
95 "Lo_R4": {"ipv4": "4.4.4.4/32", "ipv6": "4:4::4:4/128"},
99 def setup_module(mod
):
101 Sets up the pytest environment
106 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
107 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
108 logger
.info("=" * 40)
110 logger
.info("Running setup_module to create topology")
112 # This function initiates the topology build with Topogen...
113 json_file
= "{}/bgp_recursive_route_ebgp_multi_hop.json".format(CWD
)
114 tgen
= Topogen(json_file
, mod
.__name
__)
116 topo
= tgen
.json_topo
117 # ... and here it calls Mininet initialization functions.
119 # Starting topology, create tmp files which are loaded to routers
120 # to start daemons and then start routers
123 # Creating configuration from JSON
124 build_config_from_json(tgen
, topo
)
126 global BGP_CONVERGENCE
127 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
128 assert BGP_CONVERGENCE
is True, "setup_module : Failed \n Error : {}".format(
132 logger
.info("Running setup_module() done")
135 def teardown_module():
136 """Teardown the pytest environment"""
138 logger
.info("Running teardown_module to delete topology")
142 # Stop toplogy and Remove tmp files
146 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
148 logger
.info("=" * 40)
151 #####################################################
155 #####################################################
158 def test_recursive_routes_iBGP_peer_p1(request
):
160 Verify that BGP routes are installed in iBGP peer, only
161 when there is a recursive route for next-hop reachability.
164 tc_name
= request
.node
.name
165 write_test_header(tc_name
)
168 # Don"t run this test if we have any failure.
169 if tgen
.routers_have_failure():
170 pytest
.skip(tgen
.errors
)
172 step("Initial config :Configure BGP neighborship between R1 and R3.")
173 reset_config_on_routers(tgen
)
179 "Configure static routes on R1 pointing next-hop as connected"
180 "link between R1 & R3's IP"
182 for addr_type
in ADDR_TYPES
:
187 "network": NETWORK
[addr_type
],
188 "next_hop": topo
["routers"]["r3"]["links"]["r1"][
195 result
= create_static_routes(tgen
, input_dict_4
)
198 "Verify on router R1 that these static routes are "
199 "installed in RIB+FIB of R1"
206 next_hop
=topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0],
209 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
213 step("Redistribute these static routes in BGP on router R1")
218 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
219 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
224 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
227 "Verify on router R1 that these static routes are installed"
228 "in RIB table as well"
230 for addr_type
in ADDR_TYPES
:
235 "network": NETWORK
[addr_type
],
236 "next_hop": topo
["routers"]["r3"]["links"]["r1"][
243 result
= verify_bgp_rib(
248 next_hop
=topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0],
250 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
255 "Configure a static routes for next hop IP on R2 via multiple"
256 "recursive static routes"
259 create_interface_in_kernel(
260 tgen
, dut
, "lo", "40.40.40.50", netmask
="255.255.255.0", create
=True
262 create_interface_in_kernel(
263 tgen
, dut
, "lo", "40:40::40:50", netmask
="120", create
=True
265 for addr_type
in ADDR_TYPES
:
270 "network": topo
["routers"]["r3"]["links"]["r1"][addr_type
],
271 "next_hop": RECUR_NEXT_HOP
["N1"][addr_type
].split("/")[0],
274 "network": RECUR_NEXT_HOP
["N1"][addr_type
],
275 "next_hop": RECUR_NEXT_HOP
["N2"][addr_type
].split("/")[0],
278 "network": RECUR_NEXT_HOP
["N2"][addr_type
],
279 "next_hop": RECUR_NEXT_HOP
["N3"][addr_type
].split("/")[0],
284 result
= create_static_routes(tgen
, input_dict_3
)
285 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
289 step("verify if redistributed routes are now installed in FIB of R2")
295 next_hop
=topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0],
298 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
302 step("Delete 1 route from static recursive for the next-hop IP")
304 for addr_type
in ADDR_TYPES
:
309 "network": RECUR_NEXT_HOP
["N1"][addr_type
],
310 "next_hop": RECUR_NEXT_HOP
["N2"][addr_type
].split("/")[0],
316 result
= create_static_routes(tgen
, input_dict_3
)
317 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
321 step("Verify that redistributed routes are withdrawn from FIB of R2")
327 next_hop
=topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0],
333 ), "Testcase {} : Failed \n " "Routes are still present \n Error: {}".format(
337 step("Reconfigure the same static route on R2 again")
339 for addr_type
in ADDR_TYPES
:
344 "network": RECUR_NEXT_HOP
["N1"][addr_type
],
345 "next_hop": RECUR_NEXT_HOP
["N2"][addr_type
].split("/")[0],
350 result
= create_static_routes(tgen
, input_dict_3
)
351 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
355 step("Verify that redistributed routes are again installed" "in FIB of R2")
361 next_hop
=topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0],
364 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
368 step("Configure static route with changed next-hop from same subnet")
369 for addr_type
in ADDR_TYPES
:
374 "network": NETWORK
[addr_type
],
375 "next_hop": topo
["routers"]["r3"]["links"]["r1"][
381 "network": NETWORK
[addr_type
],
382 "next_hop": CHANGED_NEXT_HOP
["4thOctate"][addr_type
].split("/")[
389 result
= create_static_routes(tgen
, input_dict_4
)
390 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
394 result
= verify_rib(tgen
, addr_type
, "r1", input_dict_4
, protocol
="static")
395 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
400 "Verify that redistributed routes are not withdrawn as changed"
401 "next-hop IP, belongs to the same subnet"
403 result
= verify_rib(tgen
, addr_type
, "r2", input_dict_4
, protocol
="bgp")
404 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
408 step("Configure static route with changed next-hop from different subnet")
410 create_interface_in_kernel(
411 tgen
, dut
, "lo10", "10.0.10.10", netmask
="255.255.255.0", create
=True
413 create_interface_in_kernel(
414 tgen
, dut
, "lo10", "fd00:0:0:10::104", netmask
="64", create
=True
416 for addr_type
in ADDR_TYPES
:
421 "network": NETWORK
[addr_type
],
422 "next_hop": CHANGED_NEXT_HOP
["4thOctate"][addr_type
].split("/")[
428 "network": NETWORK
[addr_type
],
429 "next_hop": CHANGED_NEXT_HOP
["3rdOctate"][addr_type
].split("/")[
436 result
= create_static_routes(tgen
, input_dict_4
)
437 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
441 result
= verify_rib(tgen
, addr_type
, "r1", input_dict_4
, protocol
="static")
442 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
447 "Verify that redistributed routes are withdrawn as changed "
448 "next-hop IP, belongs to different subnet"
451 tgen
, addr_type
, "r2", input_dict_4
, protocol
="bgp", expected
=False
455 ), "Testcase {} : Failed \n " "Routes are still present \n Error: {}".format(
459 write_test_footer(tc_name
)
462 def test_next_hop_as_self_ip_p1(request
):
464 Verify that any BGP prefix received with next hop as
465 self-ip is not installed in BGP RIB or FIB table.
468 tc_name
= request
.node
.name
469 write_test_header(tc_name
)
472 # Don"t run this test if we have any failure.
473 if tgen
.routers_have_failure():
474 pytest
.skip(tgen
.errors
)
476 step("Initial config :Configure BGP neighborship between R1 and R3.")
477 reset_config_on_routers(tgen
)
480 "Configure static routes on R1 with a next-hop IP belonging"
481 "to the same subnet of R2's link IP."
484 create_interface_in_kernel(
488 topo
["routers"]["r4"]["links"]["r2"]["ipv4"].split("/")[0],
489 netmask
="255.255.255.0",
492 create_interface_in_kernel(
496 topo
["routers"]["r4"]["links"]["r2"]["ipv6"].split("/")[0],
500 for addr_type
in ADDR_TYPES
:
505 "network": NETWORK
[addr_type
],
506 "next_hop": topo
["routers"]["r2"]["links"]["r4"][
513 result
= create_static_routes(tgen
, input_dict_4
)
515 step("Verify that static routes are installed in RIB and FIB of R1")
521 next_hop
=topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
524 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
528 step("Redistribute static routes into BGP on R1")
533 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
534 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
539 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
542 "Verify that R2 denies the prefixes received in update message,"
543 "as next-hop IP belongs to connected interface"
545 for addr_type
in ADDR_TYPES
:
550 "network": NETWORK
[addr_type
],
551 "next_hop": topo
["routers"]["r2"]["links"]["r4"][
558 result
= verify_bgp_rib(
563 next_hop
=topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
568 ), "Testcase {} : Failed \n " "Routes are still present \n Error: {}".format(
572 step("Shut interface on R2 that has IP from the subnet as BGP next-hop")
573 intf_r2_r4
= topo
["routers"]["r2"]["links"]["r4"]["interface"]
574 shutdown_bringup_interface(tgen
, "r2", intf_r2_r4
)
576 for addr_type
in ADDR_TYPES
:
577 clear_bgp(tgen
, addr_type
, "r2")
579 "Verify that redistributed routes now appear only in BGP table,"
580 "as next-hop IP is no more active on R2"
582 for addr_type
in ADDR_TYPES
:
587 "network": NETWORK
[addr_type
],
588 "next_hop": topo
["routers"]["r2"]["links"]["r4"][
595 result
= verify_bgp_rib(
600 next_hop
=topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
602 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
606 step("No shutdown interface on R2 which was shut in previous step")
607 intf_r2_r4
= topo
["routers"]["r2"]["links"]["r4"]["interface"]
608 shutdown_bringup_interface(tgen
, "r2", intf_r2_r4
, ifaceaction
=True)
611 "Verify that R2 dosn't install prefixes RIB to FIB as next-hop"
612 "interface is up now"
614 for addr_type
in ADDR_TYPES
:
619 "network": NETWORK
[addr_type
],
620 "next_hop": topo
["routers"]["r2"]["links"]["r4"][
627 result
= verify_bgp_rib(
632 next_hop
=topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
634 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
642 next_hop
=topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
647 ), "Testcase {} : Failed \n " "Routes are still present \n Error: {}".format(
651 write_test_footer(tc_name
)
654 def test_next_hop_with_recursive_lookup_p1(request
):
656 Verify that for a BGP prefix next-hop information doesn't change
657 when same prefix is received from another peer via recursive lookup.
660 tc_name
= request
.node
.name
661 write_test_header(tc_name
)
664 # Don"t run this test if we have any failure.
665 if tgen
.routers_have_failure():
666 pytest
.skip(tgen
.errors
)
668 step("Initial config :Configure BGP neighborship between R1 and R3.")
669 reset_config_on_routers(tgen
)
671 step("Verify that BGP peering comes up.")
673 result
= verify_bgp_convergence_from_running_config(tgen
)
674 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
676 step("Do redistribute connected on router R3.")
682 "unicast": {"redistribute": [{"redist_type": "connected"}]}
685 "unicast": {"redistribute": [{"redist_type": "connected"}]}
692 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
693 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
695 step("Verify that R1 receives all connected")
696 for addr_type
in ADDR_TYPES
:
698 "ipv4": ["1.0.3.17/32", "10.0.1.0/24", "10.0.3.0/24"],
699 "ipv6": ["2001:db8:f::3:17/128", "fd00:0:0:1::/64", "fd00:0:0:3::/64"],
701 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
702 result
= verify_rib(tgen
, addr_type
, "r1", input_dict
, protocol
="bgp")
703 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
708 "Configure a BGP neighborship between R1 and R4, directly via "
711 r1_local_as
= topo
["routers"]["r1"]["bgp"]["local_as"]
712 r1_r3_addr
= topo
["routers"]["r1"]["links"]["r3"]
713 r4_local_as
= topo
["routers"]["r4"]["bgp"]["local_as"]
714 r4_r3_addr
= topo
["routers"]["r4"]["links"]["r3"]
717 for addr_type
in ADDR_TYPES
:
721 "router bgp {}".format(r1_local_as
),
722 "neighbor {} remote-as {}".format(
723 r4_r3_addr
[addr_type
].split("/")[0], r4_local_as
725 "neighbor {} timers {} {}".format(
726 r4_r3_addr
[addr_type
].split("/")[0],
730 "neighbor {} ebgp-multihop {}".format(
731 r4_r3_addr
[addr_type
].split("/")[0], ebgp_multi_hop
737 "router bgp {}".format(r4_local_as
),
738 "neighbor {} remote-as {}".format(
739 r1_r3_addr
[addr_type
].split("/")[0], r1_local_as
741 "neighbor {} timers {} {}".format(
742 r1_r3_addr
[addr_type
].split("/")[0],
746 "neighbor {} ebgp-multihop {}".format(
747 r1_r3_addr
[addr_type
].split("/")[0], ebgp_multi_hop
752 result
= apply_raw_config(tgen
, raw_config
)
753 assert result
is True, "Testcase {} : Failed Error : {}".format(tc_name
, result
)
755 for addr_type
in ADDR_TYPES
:
756 if addr_type
== "ipv4":
760 "router bgp {}".format(r1_local_as
),
761 "address-family {} unicast".format(addr_type
),
762 "no neighbor {} activate".format(
763 r4_r3_addr
["ipv6"].split("/")[0]
769 "router bgp {}".format(r4_local_as
),
770 "address-family {} unicast".format(addr_type
),
771 "no neighbor {} activate".format(
772 r1_r3_addr
["ipv6"].split("/")[0]
781 "router bgp {}".format(r1_local_as
),
782 "address-family {} unicast".format(addr_type
),
783 "neighbor {} activate".format(
784 r4_r3_addr
[addr_type
].split("/")[0]
790 "router bgp {}".format(r4_local_as
),
791 "address-family {} unicast".format(addr_type
),
792 "neighbor {} activate".format(
793 r1_r3_addr
[addr_type
].split("/")[0]
798 result
= apply_raw_config(tgen
, raw_config
)
799 assert result
is True, "Testcase {} : Failed Error : {}".format(tc_name
, result
)
801 step("Verify that BGP session between R1 and R4 comes up" "(recursively via R3).")
802 result
= verify_bgp_convergence_from_running_config(tgen
)
803 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
805 step("Do redistribute connected on router R4.")
811 "unicast": {"redistribute": [{"redist_type": "connected"}]}
814 "unicast": {"redistribute": [{"redist_type": "connected"}]}
821 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
822 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
825 "Verify that R1 now receives BGP prefix of link r3-r4 via 2 "
826 "next-hops R3 and R4. however do not install with NHT R4 in FIB."
828 for addr_type
in ADDR_TYPES
:
829 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
831 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
832 next_hop
= topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
835 tgen
, addr_type
, "r1", input_dict
, protocol
="bgp", next_hop
=next_hop
837 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
841 step("Clear bgp sessions from R1 using 'clear ip bgp *'")
842 for addr_type
in ADDR_TYPES
:
843 clear_bgp(tgen
, addr_type
, "r1")
846 "Verify that prefix of link r3-r4 is again learned via 2 "
847 "next-hops (from R3 and R4 directly)"
849 for addr_type
in ADDR_TYPES
:
850 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
852 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
853 next_hop
= topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
856 tgen
, addr_type
, "r1", input_dict
, protocol
="bgp", next_hop
=next_hop
858 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
862 step("Remove redistribution from router R3.")
871 {"redist_type": "connected", "delete": True}
878 {"redist_type": "connected", "delete": True}
887 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
888 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
891 "Verify that peering between R1-R4 goes down and prefix "
892 "of link r3-r4, with NHT R4 is withdrawn."
895 logger
.info("Sleeping for holddowntimer: {}".format(HOLD_DOWN_TIMER
))
896 sleep(HOLD_DOWN_TIMER
+ 1)
898 result
= verify_bgp_convergence_from_running_config(tgen
, expected
=False)
901 ), "Testcase {} : Failed \n" "BGP is converged \n Error : {}".format(
904 logger
.info("Expected behaviour: {}".format(result
))
906 for addr_type
in ADDR_TYPES
:
907 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
909 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
910 next_hop
= topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
913 tgen
, addr_type
, "r1", input_dict
, protocol
="bgp", next_hop
=next_hop
915 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
919 step("Re-apply redistribution on R3.")
927 "unicast": {"redistribute": [{"redist_type": "connected"}]}
930 "unicast": {"redistribute": [{"redist_type": "connected"}]}
937 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
938 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
941 "Verify that peering between R1-R4 goes down and prefix "
942 "of link r3-r4 with NHT R4 is withdrawn."
945 result
= verify_bgp_convergence_from_running_config(tgen
)
946 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
948 for addr_type
in ADDR_TYPES
:
949 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
951 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
952 next_hop
= topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
955 tgen
, addr_type
, "r1", input_dict
, protocol
="bgp", next_hop
=next_hop
957 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
961 step("Remove redistribution from router R4.")
971 {"redist_type": "connected", "delete": True}
978 {"redist_type": "connected", "delete": True}
987 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
988 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
991 "Verify that peering between R1-R4 doesn't go down but prefix "
992 "of link r3-r4 with NHT R4 is withdrawn."
995 logger
.info("Sleeping for holddowntimer: {}".format(HOLD_DOWN_TIMER
))
996 sleep(HOLD_DOWN_TIMER
+ 1)
998 result
= verify_bgp_convergence_from_running_config(tgen
)
999 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1001 for addr_type
in ADDR_TYPES
:
1002 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
1004 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
1005 next_hop
= topo
["routers"]["r4"]["links"]["r3"][addr_type
].split("/")[0]
1007 result
= verify_rib(
1018 ), "Testcase {} : Failed \n " "Route is still present \n Error : {}".format(
1022 step("Re-apply redistribution on R4.")
1032 {"redist_type": "connected", "delete": True}
1039 {"redist_type": "connected", "delete": True}
1048 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
1049 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1051 step("Verify that prefix of link r3-r4 is re-learned via NHT R4.")
1053 for addr_type
in ADDR_TYPES
:
1054 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
1056 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
1057 next_hop
= topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
1059 result
= verify_rib(
1060 tgen
, addr_type
, "r1", input_dict
, protocol
="bgp", next_hop
=next_hop
1062 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1066 step("Toggle the interface on R3.")
1068 intf_r3_r4
= topo
["routers"]["r3"]["links"]["r4"]["interface"]
1069 shutdown_bringup_interface(tgen
, "r3", intf_r3_r4
)
1072 "Verify that peering between R1-R4 goes down and comes up when "
1073 "interface is toggled. Also prefix of link r3-r4(via both NHTs) is"
1074 " withdrawn and re-learned accordingly."
1077 result
= verify_bgp_convergence_from_running_config(tgen
, expected
=False)
1080 ), "Testcase {} : Failed \n" "BGP is converged \n Error : {}".format(
1083 logger
.info("Expected behaviour: {}".format(result
))
1085 for addr_type
in ADDR_TYPES
:
1086 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
1088 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
1089 next_hop
= topo
["routers"]["r4"]["links"]["r3"][addr_type
].split("/")[0]
1091 result
= verify_rib(
1102 ), "Testcase {} : Failed \n " "Route is still present \n Error : {}".format(
1106 shutdown_bringup_interface(tgen
, "r3", intf_r3_r4
, True)
1108 result
= verify_bgp_convergence_from_running_config(tgen
)
1109 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1111 for addr_type
in ADDR_TYPES
:
1112 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
1114 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
1115 next_hop
= topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
1117 result
= verify_rib(
1118 tgen
, addr_type
, "r1", input_dict
, protocol
="bgp", next_hop
=next_hop
1120 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1124 step("Toggle the interface on R4.")
1126 intf_r4_r3
= topo
["routers"]["r4"]["links"]["r3"]["interface"]
1127 shutdown_bringup_interface(tgen
, "r4", intf_r4_r3
)
1130 "Verify that peering between R1-R4 goes down and comes up when"
1131 "interface is toggled. Also prefix of link r3-r4(via R4)"
1132 " is withdrawn and re-learned accordingly."
1135 result
= verify_bgp_convergence_from_running_config(tgen
, expected
=False)
1138 ), "Testcase {} : Failed \n" "BGP is converged \n Error : {}".format(
1141 logger
.info("Expected behaviour: {}".format(result
))
1143 for addr_type
in ADDR_TYPES
:
1144 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
1146 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
1147 next_hop
= topo
["routers"]["r4"]["links"]["r3"][addr_type
].split("/")[0]
1149 result
= verify_rib(
1160 ), "Testcase {} : Failed \n " "Route is still present \n Error : {}".format(
1164 shutdown_bringup_interface(tgen
, "r4", intf_r4_r3
, True)
1166 result
= verify_bgp_convergence_from_running_config(tgen
)
1167 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1169 for addr_type
in ADDR_TYPES
:
1170 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
1172 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
1173 next_hop
= topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
1175 result
= verify_rib(
1176 tgen
, addr_type
, "r1", input_dict
, protocol
="bgp", next_hop
=next_hop
1178 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1182 write_test_footer(tc_name
)
1185 def test_BGP_path_attributes_default_values_p1(request
):
1187 Verify that BGP path attributes are present in CLI
1188 outputs and JSON format, even if set to default.
1191 tc_name
= request
.node
.name
1192 write_test_header(tc_name
)
1193 tgen
= get_topogen()
1195 # Don"t run this test if we have any failure.
1196 if tgen
.routers_have_failure():
1197 pytest
.skip(tgen
.errors
)
1199 step("Initial config: Configure BGP neighborship, between R1-R2 & R1-R3")
1200 reset_config_on_routers(tgen
)
1202 step("Advertise a set of prefixes from R1 to both peers R2 and R3")
1203 for addr_type
in ADDR_TYPES
:
1206 "static_routes": [{"network": NETWORK
[addr_type
], "next_hop": "null0"}]
1209 result
= create_static_routes(tgen
, input_dict_1
)
1215 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1216 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1221 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
1224 "Verify that advertised prefixes are received on R4 and well"
1225 "known attributes are present in the CLI and JSON outputs with"
1226 "default values without any route-map config."
1228 for addr_type
in ADDR_TYPES
:
1229 input_dict_3
= {"r4": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
1230 result
= verify_bgp_rib(
1236 topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
1237 topo
["routers"]["r3"]["links"]["r4"][addr_type
].split("/")[0],
1240 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
1244 for addr_type
in ADDR_TYPES
:
1248 "rmap_pf": [{"set": {"origin": "incomplete", "aspath": "300 100"}}]
1253 result
= verify_bgp_attributes(
1258 rmap_name
="rmap_pf",
1259 input_dict
=input_dict_4
,
1261 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
1266 "Configure a route-map to set below attribute value as 500"
1267 "and apply on R4 in an inbound direction"
1269 for addr_type
in ADDR_TYPES
:
1277 "path": {"as_num": 500, "as_action": "prepend"},
1286 result
= create_route_maps(tgen
, input_dict_4
)
1287 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1301 "name": "Path_Attribue",
1319 "name": "Path_Attribue",
1334 result
= create_router_bgp(tgen
, topo
, input_dict_5
)
1335 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1338 "Verify that once the route-map is applied all the attributes"
1339 "part of route-map, changes value to 500"
1341 for addr_type
in ADDR_TYPES
:
1349 "aspath": "500 300 100",
1357 result
= verify_bgp_attributes(
1362 rmap_name
="rmap_pf",
1363 input_dict
=input_dict_4
,
1365 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
1369 step("Remove the route-map from R4")
1382 "name": "Path_Attribue",
1401 "name": "Path_Attribue",
1417 result
= create_router_bgp(tgen
, topo
, input_dict_5
)
1418 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1421 "Verify on R4 that well known attributes are present in the CLI &"
1422 "JSON outputs again with default values without route-map config"
1424 for addr_type
in ADDR_TYPES
:
1428 "rmap_pf": [{"set": {"aspath": "300 100", "origin": "incomplete"}}]
1432 result
= verify_bgp_attributes(
1437 rmap_name
="rmap_pf",
1438 input_dict
=input_dict_4
,
1441 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
1445 write_test_footer(tc_name
)
1448 def test_BGP_peering_bw_loopback_and_physical_p1(request
):
1450 Verifying the BGP peering between loopback and
1451 physical link's IP of 2 peer routers.
1454 tc_name
= request
.node
.name
1455 write_test_header(tc_name
)
1456 tgen
= get_topogen()
1458 # Don"t run this test if we have any failure.
1459 if tgen
.routers_have_failure():
1460 pytest
.skip(tgen
.errors
)
1462 step("Initial config :Configure BGP neighborship between R1 and R3.")
1463 reset_config_on_routers(tgen
)
1465 step("Configure a loopback interface on R1")
1467 create_interface_in_kernel(
1468 tgen
, dut
, "lo10", "1.1.1.1", netmask
="255.255.255.255", create
=True
1470 create_interface_in_kernel(
1471 tgen
, dut
, "lo10", "1:1::1:1", netmask
="128", create
=True
1474 step("Configure BGP session between R1's loopbak & R3")
1475 for addr_type
in ADDR_TYPES
:
1480 "network": Loopabck_IP
["Lo_R1"][addr_type
],
1481 "next_hop": topo
["routers"]["r1"]["links"]["r3"][
1488 result
= create_static_routes(tgen
, input_dict_1
)
1489 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1492 result
= verify_rib(
1498 next_hop
=topo
["routers"]["r1"]["links"]["r3"][addr_type
].split("/")[0],
1500 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1504 for addr_type
in ADDR_TYPES
:
1508 "router bgp {}".format(topo
["routers"]["r1"]["bgp"]["local_as"]),
1509 "address-family {} unicast".format(addr_type
),
1510 "neighbor {} update-source lo10".format(
1511 topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
1513 "neighbor {} timers 1 3".format(
1514 topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
1520 "router bgp {}".format(topo
["routers"]["r3"]["bgp"]["local_as"]),
1521 "address-family {} unicast".format(addr_type
),
1522 "no neighbor {} remote-as {}".format(
1523 topo
["routers"]["r1"]["links"]["r3"][addr_type
].split("/")[0],
1524 topo
["routers"]["r1"]["bgp"]["local_as"],
1526 "neighbor {} remote-as {}".format(
1527 Loopabck_IP
["Lo_R1"][addr_type
].split("/")[0],
1528 topo
["routers"]["r1"]["bgp"]["local_as"],
1530 "neighbor {} ebgp-multihop 3".format(
1531 Loopabck_IP
["Lo_R1"][addr_type
].split("/")[0]
1536 result
= apply_raw_config(tgen
, raw_config
)
1537 assert result
is True, "Testcase {} : Failed Error : {}".format(tc_name
, result
)
1539 for addr_type
in ADDR_TYPES
:
1540 if addr_type
== "ipv6":
1544 "router bgp {}".format(
1545 topo
["routers"]["r3"]["bgp"]["local_as"]
1547 "address-family {} unicast".format(addr_type
),
1548 "neighbor {} activate".format(
1549 Loopabck_IP
["Lo_R1"][addr_type
].split("/")[0]
1558 "router bgp {}".format(
1559 topo
["routers"]["r3"]["bgp"]["local_as"]
1561 "address-family {} unicast".format(addr_type
),
1562 "no neighbor {} activate".format(
1563 Loopabck_IP
["Lo_R1"]["ipv6"].split("/")[0]
1568 result
= apply_raw_config(tgen
, raw_config
)
1569 assert result
is True, "Testcase {} : Failed Error : {}".format(tc_name
, result
)
1571 step("Verify that BGP neighborship between R1 and R3 comes up")
1572 result
= verify_bgp_convergence_from_running_config(tgen
)
1573 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1575 step("Remove ebgp-multihop command from R3")
1576 for addr_type
in ADDR_TYPES
:
1580 "router bgp {}".format(topo
["routers"]["r3"]["bgp"]["local_as"]),
1581 "no neighbor {} ebgp-multihop 3".format(
1582 Loopabck_IP
["Lo_R1"][addr_type
].split("/")[0]
1587 result
= apply_raw_config(tgen
, raw_config
)
1588 assert result
is True, "Testcase {} : Failed Error : {}".format(tc_name
, result
)
1590 step("Verify that once eBGP multi-hop is removed, BGP session goes down")
1591 result
= verify_bgp_convergence_from_running_config(tgen
, expected
=False)
1594 ), "Testcase {} : Failed \n " "BGP is converged \n Error: {}".format(
1598 step("Add ebgp-multihop command on R3 again")
1599 for addr_type
in ADDR_TYPES
:
1603 "router bgp {}".format(topo
["routers"]["r3"]["bgp"]["local_as"]),
1604 "neighbor {} ebgp-multihop 3".format(
1605 Loopabck_IP
["Lo_R1"][addr_type
].split("/")[0]
1610 result
= apply_raw_config(tgen
, raw_config
)
1611 assert result
is True, "Testcase {} : Failed Error : {}".format(tc_name
, result
)
1613 step("Verify that BGP neighborship between R1 and R3 comes up")
1614 result
= verify_bgp_convergence_from_running_config(tgen
)
1615 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1617 step("Remove update-source command from R1")
1618 for addr_type
in ADDR_TYPES
:
1622 "router bgp {}".format(topo
["routers"]["r1"]["bgp"]["local_as"]),
1623 "no neighbor {} update-source lo10".format(
1624 topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
1629 result
= apply_raw_config(tgen
, raw_config
)
1630 assert result
is True, "Testcase {} : Failed Error : {}".format(tc_name
, result
)
1632 step("Verify that BGP session goes down, when update-source is removed")
1633 result
= verify_bgp_convergence_from_running_config(tgen
, expected
=False)
1636 ), "Testcase {} : Failed \n " "BGP is converged \n Error: {}".format(
1640 step("Add update-source command on R1 again")
1641 for addr_type
in ADDR_TYPES
:
1645 "router bgp {}".format(topo
["routers"]["r1"]["bgp"]["local_as"]),
1646 "neighbor {} update-source lo10".format(
1647 topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
1652 result
= apply_raw_config(tgen
, raw_config
)
1653 assert result
is True, "Testcase {} : Failed Error : {}".format(tc_name
, result
)
1655 step("Verify that BGP neighborship between R1 and R3 comes up")
1656 result
= verify_bgp_convergence_from_running_config(tgen
)
1657 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1659 step("Remove static route from R3")
1660 for addr_type
in ADDR_TYPES
:
1665 "network": Loopabck_IP
["Lo_R1"][addr_type
],
1666 "next_hop": topo
["routers"]["r1"]["links"]["r3"][
1674 result
= create_static_routes(tgen
, input_dict_1
)
1675 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1678 result
= verify_rib(
1684 next_hop
=topo
["routers"]["r1"]["links"]["r3"][addr_type
].split("/")[0],
1689 ), "Testcase {} : Failed \n " "Routes are still present \n Error: {}".format(
1694 step("Verify that BGP session goes down, when static route is removed")
1695 result
= verify_bgp_convergence_from_running_config(tgen
, expected
=False)
1698 ), "Testcase {} : Failed \n " "BGP is converged \n Error: {}".format(
1702 step("Add static route on R3 again")
1703 for addr_type
in ADDR_TYPES
:
1708 "network": Loopabck_IP
["Lo_R1"][addr_type
],
1709 "next_hop": topo
["routers"]["r1"]["links"]["r3"][
1716 result
= create_static_routes(tgen
, input_dict_1
)
1717 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1720 result
= verify_rib(
1726 next_hop
=topo
["routers"]["r1"]["links"]["r3"][addr_type
].split("/")[0],
1728 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1732 step("Verify that BGP neighborship between R1 and R3 comes up")
1733 result
= verify_bgp_convergence_from_running_config(tgen
)
1734 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1736 step("Toggle physical interface on R1")
1737 intf_r1_r3
= topo
["routers"]["r1"]["links"]["r3"]["interface"]
1738 shutdown_bringup_interface(tgen
, "r1", intf_r1_r3
)
1740 step("Verify that BGP neighborship between R1 and R3 goes down")
1741 result
= verify_bgp_convergence_from_running_config(tgen
, expected
=False)
1744 ), "Testcase {} : Failed \n " "BGP is converged \n Error: {}".format(
1748 intf_r1_r3
= topo
["routers"]["r1"]["links"]["r3"]["interface"]
1749 shutdown_bringup_interface(tgen
, "r1", intf_r1_r3
, True)
1751 step("Verify that BGP neighborship between R1 and R3 comes up")
1752 result
= verify_bgp_convergence_from_running_config(tgen
)
1753 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1755 write_test_footer(tc_name
)
1758 def test_BGP_active_standby_preemption_and_ecmp_p1(request
):
1760 Verify that BGP Active/Standby/Pre-emption/ECMP.
1763 tc_name
= request
.node
.name
1764 write_test_header(tc_name
)
1765 tgen
= get_topogen()
1767 # Don"t run this test if we have any failure.
1768 if tgen
.routers_have_failure():
1769 pytest
.skip(tgen
.errors
)
1771 step("Initial config :Configure BGP neighborship between R1 and R3.")
1772 reset_config_on_routers(tgen
)
1774 step("Change the AS number on R2 as 200")
1775 input_dict
= {"r2": {"bgp": {"local_as": 200}}}
1776 result
= modify_as_number(tgen
, topo
, input_dict
)
1777 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1779 step("Verify BGP converge after changing the AS number on R2")
1780 result
= verify_bgp_convergence_from_running_config(tgen
)
1781 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1783 step("Advertise a set of prefixes from R1 to both peers R2 & R3")
1784 for addr_type
in ADDR_TYPES
:
1787 "static_routes": [{"network": NETWORK
[addr_type
], "next_hop": "null0"}]
1790 result
= create_static_routes(tgen
, input_dict_1
)
1791 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1799 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1800 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1806 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
1807 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1809 step("Verify that R4 receives BGP prefixes via both peer routers R2 & R3")
1810 for addr_type
in ADDR_TYPES
:
1811 input_dict_3
= {"r4": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
1812 result
= verify_bgp_rib(
1818 topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
1819 topo
["routers"]["r3"]["links"]["r4"][addr_type
].split("/")[0],
1822 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
1827 "Configure a route-map to set as-path attribute and"
1828 "apply on R3 in an inbound direction:"
1837 "set": {"path": {"as_num": 123, "as_action": "prepend"}},
1843 result
= create_route_maps(tgen
, input_dict_4
)
1844 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1858 "name": "Path_Attribue",
1876 "name": "Path_Attribue",
1890 result
= create_router_bgp(tgen
, topo
, input_dict_5
)
1891 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1893 step("Verify on R4, BGP routes with shorter as-path are installed in FIB")
1894 for addr_type
in ADDR_TYPES
:
1897 input_dict_6
= {"r4": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
1898 result
= verify_rib(
1903 next_hop
=topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
1906 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1910 step("Shutdown BGP neighorship between R1-R2")
1912 intf_r4_r2
= topo
["routers"]["r4"]["links"]["r2"]["interface"]
1913 shutdown_bringup_interface(tgen
, dut
, intf_r4_r2
)
1916 "Verify that prefixes from next-hop via R2 are withdrawn"
1917 "and installed via next-hop as R3"
1919 result
= verify_rib(
1924 next_hop
=topo
["routers"]["r3"]["links"]["r4"][addr_type
].split("/")[0],
1927 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1929 step("Do a no shut for BGP neighorship between R2-R4")
1930 shutdown_bringup_interface(tgen
, dut
, intf_r4_r2
, ifaceaction
=True)
1933 "Verify that prefixes from next-hop via R3 are withdrawn"
1934 "from R4 and installed via next-hop as R2 (preemption)"
1936 result
= verify_rib(
1941 next_hop
=topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
1944 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1946 step("Remove the route-map from R3's neighbor statement")
1959 "name": "Path_Attribue",
1978 "name": "Path_Attribue",
1993 result
= create_router_bgp(tgen
, topo
, input_dict_5
)
1994 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1996 step("Configure multipath-relax and maximum-paths 2 on R4 for ECMP")
2001 "ipv4": {"unicast": {"maximum_paths": {"ebgp": 2}}},
2002 "ipv6": {"unicast": {"maximum_paths": {"ebgp": 2}}},
2007 result
= create_router_bgp(tgen
, topo
, input_dict_8
)
2008 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2011 "r4": {"bgp": {"local_as": "400", "bestpath": {"aspath": "multipath-relax"}}}
2014 result
= create_router_bgp(tgen
, topo
, maxpath_relax
)
2015 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2017 step("Verify FIB of R4, BGP prefixes with ECMP next-hop via R2 and R3")
2018 for addr_type
in ADDR_TYPES
:
2019 input_dict
= {"r4": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
2020 result
= verify_rib(
2026 topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
2027 topo
["routers"]["r3"]["links"]["r4"][addr_type
].split("/")[0],
2030 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
2034 step("Remove multipath-relax command from R4")
2036 del_maxpath_relax
= {
2040 "bestpath": {"aspath": "multipath-relax", "delete": True},
2045 result
= create_router_bgp(tgen
, topo
, del_maxpath_relax
)
2046 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2048 step("Verify that ECMP is no longer happening on R4.")
2049 for addr_type
in ADDR_TYPES
:
2050 input_dict
= {"r4": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
2051 result
= verify_rib(
2057 topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
2058 topo
["routers"]["r3"]["links"]["r4"][addr_type
].split("/")[0],
2064 ), "Testcase {} : Failed \n " "Routes are still present \n Error: {}".format(
2068 step("Reconfigure multipath-relax command on R4")
2069 result
= create_router_bgp(tgen
, topo
, maxpath_relax
)
2070 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2072 step("Verify FIB of R4, BGP prefixes with ECMP next-hop via R2 and R3")
2073 result
= verify_rib(
2079 topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
2080 topo
["routers"]["r3"]["links"]["r4"][addr_type
].split("/")[0],
2083 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2085 step("Remove maximum-path 2 command from R4")
2108 result
= create_router_bgp(tgen
, topo
, input_dict_8
)
2109 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2111 step("Verify that ECMP is no longer happening on R4")
2112 result
= verify_rib(
2118 topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
2119 topo
["routers"]["r3"]["links"]["r4"][addr_type
].split("/")[0],
2125 ), "Testcase {} : Failed \n " "Routes are still present \n Error: {}".format(
2129 step("Re-configure maximum-path 2 command on R4")
2152 result
= create_router_bgp(tgen
, topo
, input_dict_8
)
2153 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2155 step("Verify FIB of R4, BGP prefixes with ECMP next-hop via R2 and R3")
2156 result
= verify_rib(
2162 topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
2163 topo
["routers"]["r3"]["links"]["r4"][addr_type
].split("/")[0],
2166 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2168 write_test_footer(tc_name
)
2171 def test_password_authentication_for_eBGP_and_iBGP_peers_p1(request
):
2173 Verify password authentication for eBGP and iBGP peers.
2176 tc_name
= request
.node
.name
2177 write_test_header(tc_name
)
2178 tgen
= get_topogen()
2180 # Don"t run this test if we have any failure.
2181 if tgen
.routers_have_failure():
2182 pytest
.skip(tgen
.errors
)
2184 step("Initial config :Configure BGP neighborship between R1 and R3.")
2185 reset_config_on_routers(tgen
)
2188 "Add a static route on R1 for loopbacks IP's reachability of R2, R3"
2189 "and on R2 and R3 for loopback IP of R1"
2191 for addr_type
in ADDR_TYPES
:
2192 nh1
= topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
2193 nh2
= topo
["routers"]["r1"]["links"]["r2"][addr_type
].split("/")[0]
2194 nh3
= topo
["routers"]["r1"]["links"]["r3"][addr_type
].split("/")[0]
2195 nh4
= topo
["routers"]["r2"]["links"]["r1"][addr_type
].split("/")[0]
2200 "network": topo
["routers"]["r3"]["links"]["lo"][addr_type
],
2210 "network": topo
["routers"]["r1"]["links"]["lo"][addr_type
],
2220 "network": topo
["routers"]["r1"]["links"]["lo"][addr_type
],
2230 "network": topo
["routers"]["r2"]["links"]["lo"][addr_type
],
2236 dut_list
= ["r1", "r2", "r3", "r1"]
2237 nexthop_list
= [nh1
, nh2
, nh3
, nh4
]
2238 input_dict_list
= [input_dict_1
, input_dict_2
, input_dict_3
, input_dict_4
]
2239 for dut
, next_hop
, input_dict
in zip(dut_list
, nexthop_list
, input_dict_list
):
2240 result
= create_static_routes(tgen
, input_dict
)
2241 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
2245 step("Verify that static routes are installed in FIB of routers")
2246 result
= verify_rib(
2247 tgen
, addr_type
, dut
, input_dict
, next_hop
=next_hop
, protocol
="static"
2249 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
2253 step("Configure BGP sessions between R1-R2 and R1-R3 over loopback IPs")
2254 for routerN
in ["r1", "r3"]:
2255 for addr_type
in ADDR_TYPES
:
2258 elif routerN
== "r3":
2260 topo
["routers"][routerN
]["bgp"]["address_family"][addr_type
]["unicast"][
2262 ][bgp_neighbor
]["dest_link"] = {
2263 "lo": {"ebgp_multihop": 2, "source_link": "lo"}
2265 build_config_from_json(tgen
, topo
, save_bkup
=False)
2267 for routerN
in ["r1", "r2"]:
2268 for addr_type
in ADDR_TYPES
:
2271 elif routerN
== "r2":
2273 topo
["routers"][routerN
]["bgp"]["address_family"][addr_type
]["unicast"][
2275 ][bgp_neighbor
]["dest_link"] = {"lo": {"source_link": "lo"}}
2276 build_config_from_json(tgen
, topo
, save_bkup
=False)
2278 for routerN
in ["r1", "r2", "r3"]:
2279 for addr_type
in ADDR_TYPES
:
2280 for bgp_neighbor
in topo
["routers"][routerN
]["bgp"]["address_family"][
2282 ]["unicast"]["neighbor"].keys():
2283 if routerN
in ["r1", "r2", "r3"] and bgp_neighbor
== "r4":
2285 if addr_type
== "ipv4":
2286 topo
["routers"][routerN
]["bgp"]["address_family"][addr_type
][
2288 ]["neighbor"][bgp_neighbor
]["dest_link"] = {
2289 "lo": {"deactivate": "ipv6"}
2291 elif addr_type
== "ipv6":
2292 topo
["routers"][routerN
]["bgp"]["address_family"][addr_type
][
2294 ]["neighbor"][bgp_neighbor
]["dest_link"] = {
2295 "lo": {"deactivate": "ipv4"}
2297 build_config_from_json(tgen
, topo
, save_bkup
=False)
2299 result
= verify_bgp_convergence(tgen
, topo
)
2300 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2302 step("Configure authentication password on R1 for neighbor statements")
2303 for bgp_neighbor
in ["r2", "r3"]:
2304 for addr_type
in ADDR_TYPES
:
2305 topo
["routers"]["r1"]["bgp"]["address_family"][addr_type
]["unicast"][
2307 ][bgp_neighbor
]["dest_link"] = {"lo": {"password": "vmware"}}
2308 build_config_from_json(tgen
, topo
, save_bkup
=False)
2311 "Verify that both sessions go down as only R1 has password"
2312 "configured but not peer routers"
2314 result
= verify_bgp_convergence(tgen
, topo
, expected
=False)
2317 ), "Testcase {} : Failed \n " "BGP is converged \n Error: {}".format(
2321 step("configure same password on R2 and R3")
2322 for routerN
in ["r2", "r3"]:
2323 for addr_type
in ADDR_TYPES
:
2324 topo
["routers"][routerN
]["bgp"]["address_family"][addr_type
]["unicast"][
2326 ]["r1"]["dest_link"] = {"lo": {"password": "vmware"}}
2327 build_config_from_json(tgen
, topo
, save_bkup
=False)
2329 step("Verify that all BGP sessions come up due to identical passwords")
2330 result
= verify_bgp_convergence(tgen
, topo
)
2331 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2333 step("Configure same password on R2 and R3, but in CAPs.")
2334 for routerN
in ["r2", "r3"]:
2335 for addr_type
in ADDR_TYPES
:
2336 topo
["routers"][routerN
]["bgp"]["address_family"][addr_type
]["unicast"][
2338 ]["r1"]["dest_link"] = {"lo": {"password": "VMWARE"}}
2339 build_config_from_json(tgen
, topo
, save_bkup
=False)
2342 "Verify that BGP sessions do not come up as password"
2343 "strings are in CAPs on R2 and R3"
2345 result
= verify_bgp_convergence(tgen
, topo
, expected
=False)
2348 ), "Testcase {} : Failed \n " "BGP is converged \n Error: {}".format(
2352 step("Configure same password on R2 and R3 without CAPs")
2353 for routerN
in ["r2", "r3"]:
2354 for addr_type
in ADDR_TYPES
:
2355 topo
["routers"][routerN
]["bgp"]["address_family"][addr_type
]["unicast"][
2357 ]["r1"]["dest_link"] = {"lo": {"password": "vmware"}}
2358 build_config_from_json(tgen
, topo
, save_bkup
=False)
2360 step("Verify all BGP sessions come up again due to identical passwords")
2361 result
= verify_bgp_convergence(tgen
, topo
)
2362 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2364 step("Remove password from R1")
2365 for bgp_neighbor
in ["r2", "r3"]:
2366 for addr_type
in ADDR_TYPES
:
2367 topo
["routers"]["r1"]["bgp"]["address_family"][addr_type
]["unicast"][
2369 ][bgp_neighbor
]["dest_link"] = {"lo": {"no_password": "vmware"}}
2370 build_config_from_json(tgen
, topo
, save_bkup
=False)
2372 step("Verify if password is removed from R1, both sessions go down again")
2373 result
= verify_bgp_convergence(tgen
, topo
, expected
=False)
2376 ), "Testcase {} : Failed \n " "BGP is converged \n Error: {}".format(
2380 step("Configure alphanumeric password on R1 and peer routers R2,R3")
2381 for bgp_neighbor
in ["r2", "r3"]:
2382 for addr_type
in ADDR_TYPES
:
2383 topo
["routers"]["r1"]["bgp"]["address_family"][addr_type
]["unicast"][
2385 ][bgp_neighbor
]["dest_link"] = {"lo": {"password": "Vmware@123"}}
2386 build_config_from_json(tgen
, topo
, save_bkup
=False)
2388 for routerN
in ["r2", "r3"]:
2389 for addr_type
in ADDR_TYPES
:
2390 topo
["routers"][routerN
]["bgp"]["address_family"][addr_type
]["unicast"][
2392 ]["r1"]["dest_link"] = {"lo": {"password": "Vmware@123"}}
2393 build_config_from_json(tgen
, topo
, save_bkup
=False)
2396 "Verify that sessions Come up irrespective of characters"
2397 "used in password string"
2399 result
= verify_bgp_convergence(tgen
, topo
)
2400 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2402 write_test_footer(tc_name
)
2405 if __name__
== "__main__":
2406 args
= ["-s"] + sys
.argv
[1:]
2407 sys
.exit(pytest
.main(args
))