3 # Copyright (c) 2020 by VMware, Inc. ("VMware")
4 # Used Copyright (c) 2018 by Network Device Education Foundation,
5 # Inc. ("NetDEF") in this file.
7 # Permission to use, copy, modify, and/or distribute this software
8 # for any purpose with or without fee is hereby granted, provided
9 # that the above copyright notice and this permission notice appear
12 # THE SOFTWARE IS PROVIDED "AS IS" AND VMWARE DISCLAIMS ALL WARRANTIES
13 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL VMWARE BE LIABLE FOR
15 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
16 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
17 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
18 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
23 Following tests are covered to test bgp recursive route and ebgp
24 multi-hop functionality:
26 1. Verify that BGP routes are installed in iBGP peer, only when there
27 is a recursive route for next-hop reachability.
28 2. Verify that any BGP prefix received with next hop as self-ip is
29 not installed in BGP RIB or FIB table.
30 3. Verify password authentication for eBGP and iBGP peers.
31 4. Verify that for a BGP prefix next-hop information doesn't change
32 when same prefix is received from another peer via recursive lookup.
33 5. Verify that BGP path attributes are present in CLI outputs and
34 JSON format, even if set to default.
35 6. Verifying the BGP peering between loopback and physical link's IP
37 7. Verify that BGP Active/Standby/Pre-emption/ECMP.
44 from time
import sleep
46 # Save the Current Working Directory to find configuration files.
47 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
48 sys
.path
.append(os
.path
.join(CWD
, "../"))
50 # pylint: disable=C0413
51 # Import topogen and topotest helpers
52 from lib
.topogen
import Topogen
, get_topogen
54 # Import topoJson from lib, to create topology and initial configuration
55 from lib
.common_config
import (
60 reset_config_on_routers
,
66 create_interface_in_kernel
,
67 shutdown_bringup_interface
,
69 from lib
.topolog
import logger
71 verify_bgp_convergence
,
74 verify_bgp_convergence_from_running_config
,
76 verify_bgp_attributes
,
79 from lib
.topojson
import build_config_from_json
82 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.staticd
]
86 BGP_CONVERGENCE
= False
89 ADDR_TYPES
= check_address_types()
91 "ipv4": ["100.1.1.1/32", "100.1.1.2/32"],
92 "ipv6": ["100::1/128", "100::2/128"],
96 "N1": {"ipv4": "20.20.20.20/24", "ipv6": "20:20::20:20/120"},
97 "N2": {"ipv4": "30.30.30.30/24", "ipv6": "30:30::30:30/120"},
98 "N3": {"ipv4": "40.40.40.40/24", "ipv6": "40:40::40:40/120"},
102 "4thOctate": {"ipv4": "10.0.1.250/24", "ipv6": "fd00:0:0:1::100/64"},
103 "3rdOctate": {"ipv4": "10.0.10.2/24", "ipv6": "fd00:0:0:10::2/64"},
107 "Lo_R1": {"ipv4": "1.1.1.1/32", "ipv6": "1:1::1:1/128"},
108 "Lo_R4": {"ipv4": "4.4.4.4/32", "ipv6": "4:4::4:4/128"},
112 def setup_module(mod
):
114 Sets up the pytest environment
119 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
120 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
121 logger
.info("=" * 40)
123 logger
.info("Running setup_module to create topology")
125 # This function initiates the topology build with Topogen...
126 json_file
= "{}/bgp_recursive_route_ebgp_multi_hop.json".format(CWD
)
127 tgen
= Topogen(json_file
, mod
.__name
__)
129 topo
= tgen
.json_topo
130 # ... and here it calls Mininet initialization functions.
132 # Starting topology, create tmp files which are loaded to routers
133 # to start deamons and then start routers
136 # Creating configuration from JSON
137 build_config_from_json(tgen
, topo
)
139 global BGP_CONVERGENCE
140 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
141 assert BGP_CONVERGENCE
is True, "setup_module : Failed \n Error : {}".format(
145 logger
.info("Running setup_module() done")
148 def teardown_module():
149 """Teardown the pytest environment"""
151 logger
.info("Running teardown_module to delete topology")
155 # Stop toplogy and Remove tmp files
159 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
161 logger
.info("=" * 40)
164 #####################################################
168 #####################################################
171 def test_recursive_routes_iBGP_peer_p1(request
):
173 Verify that BGP routes are installed in iBGP peer, only
174 when there is a recursive route for next-hop reachability.
177 tc_name
= request
.node
.name
178 write_test_header(tc_name
)
181 # Don"t run this test if we have any failure.
182 if tgen
.routers_have_failure():
183 pytest
.skip(tgen
.errors
)
185 step("Initial config :Configure BGP neighborship between R1 and R3.")
186 reset_config_on_routers(tgen
)
192 "Configure static routes on R1 pointing next-hop as connected"
193 "link between R1 & R3's IP"
195 for addr_type
in ADDR_TYPES
:
200 "network": NETWORK
[addr_type
],
201 "next_hop": topo
["routers"]["r3"]["links"]["r1"][
208 result
= create_static_routes(tgen
, input_dict_4
)
211 "Verify on router R1 that these static routes are "
212 "installed in RIB+FIB of R1"
219 next_hop
=topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0],
222 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
226 step("Redistribute these static routes in BGP on router R1")
231 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
232 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
237 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
240 "Verify on router R1 that these static routes are installed"
241 "in RIB table as well"
243 for addr_type
in ADDR_TYPES
:
248 "network": NETWORK
[addr_type
],
249 "next_hop": topo
["routers"]["r3"]["links"]["r1"][
256 result
= verify_bgp_rib(
261 next_hop
=topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0],
263 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
268 "Configure a static routes for next hop IP on R2 via multiple"
269 "recursive static routes"
272 create_interface_in_kernel(
273 tgen
, dut
, "lo", "40.40.40.50", netmask
="255.255.255.0", create
=True
275 create_interface_in_kernel(
276 tgen
, dut
, "lo", "40:40::40:50", netmask
="120", create
=True
278 for addr_type
in ADDR_TYPES
:
283 "network": topo
["routers"]["r3"]["links"]["r1"][addr_type
],
284 "next_hop": RECUR_NEXT_HOP
["N1"][addr_type
].split("/")[0],
287 "network": RECUR_NEXT_HOP
["N1"][addr_type
],
288 "next_hop": RECUR_NEXT_HOP
["N2"][addr_type
].split("/")[0],
291 "network": RECUR_NEXT_HOP
["N2"][addr_type
],
292 "next_hop": RECUR_NEXT_HOP
["N3"][addr_type
].split("/")[0],
297 result
= create_static_routes(tgen
, input_dict_3
)
298 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
302 step("verify if redistributed routes are now installed in FIB of R2")
308 next_hop
=topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0],
311 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
315 step("Delete 1 route from static recursive for the next-hop IP")
317 for addr_type
in ADDR_TYPES
:
322 "network": RECUR_NEXT_HOP
["N1"][addr_type
],
323 "next_hop": RECUR_NEXT_HOP
["N2"][addr_type
].split("/")[0],
329 result
= create_static_routes(tgen
, input_dict_3
)
330 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
334 step("Verify that redistributed routes are withdrawn from FIB of R2")
340 next_hop
=topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0],
346 ), "Testcase {} : Failed \n " "Routes are still present \n Error: {}".format(
350 step("Reconfigure the same static route on R2 again")
352 for addr_type
in ADDR_TYPES
:
357 "network": RECUR_NEXT_HOP
["N1"][addr_type
],
358 "next_hop": RECUR_NEXT_HOP
["N2"][addr_type
].split("/")[0],
363 result
= create_static_routes(tgen
, input_dict_3
)
364 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
368 step("Verify that redistributed routes are again installed" "in FIB of R2")
374 next_hop
=topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0],
377 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
381 step("Configure static route with changed next-hop from same subnet")
382 for addr_type
in ADDR_TYPES
:
387 "network": NETWORK
[addr_type
],
388 "next_hop": topo
["routers"]["r3"]["links"]["r1"][
394 "network": NETWORK
[addr_type
],
395 "next_hop": CHANGED_NEXT_HOP
["4thOctate"][addr_type
].split("/")[
402 result
= create_static_routes(tgen
, input_dict_4
)
403 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
407 result
= verify_rib(tgen
, addr_type
, "r1", input_dict_4
, protocol
="static")
408 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
413 "Verify that redistributed routes are not withdrawn as changed"
414 "next-hop IP, belongs to the same subnet"
416 result
= verify_rib(tgen
, addr_type
, "r2", input_dict_4
, protocol
="bgp")
417 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
421 step("Configure static route with changed next-hop from different subnet")
423 create_interface_in_kernel(
424 tgen
, dut
, "lo10", "10.0.10.10", netmask
="255.255.255.0", create
=True
426 create_interface_in_kernel(
427 tgen
, dut
, "lo10", "fd00:0:0:10::104", netmask
="64", create
=True
429 for addr_type
in ADDR_TYPES
:
434 "network": NETWORK
[addr_type
],
435 "next_hop": CHANGED_NEXT_HOP
["4thOctate"][addr_type
].split("/")[
441 "network": NETWORK
[addr_type
],
442 "next_hop": CHANGED_NEXT_HOP
["3rdOctate"][addr_type
].split("/")[
449 result
= create_static_routes(tgen
, input_dict_4
)
450 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
454 result
= verify_rib(tgen
, addr_type
, "r1", input_dict_4
, protocol
="static")
455 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
460 "Verify that redistributed routes are withdrawn as changed "
461 "next-hop IP, belongs to different subnet"
464 tgen
, addr_type
, "r2", input_dict_4
, protocol
="bgp", expected
=False
468 ), "Testcase {} : Failed \n " "Routes are still present \n Error: {}".format(
472 write_test_footer(tc_name
)
475 def test_next_hop_as_self_ip_p1(request
):
477 Verify that any BGP prefix received with next hop as
478 self-ip is not installed in BGP RIB or FIB table.
481 tc_name
= request
.node
.name
482 write_test_header(tc_name
)
485 # Don"t run this test if we have any failure.
486 if tgen
.routers_have_failure():
487 pytest
.skip(tgen
.errors
)
489 step("Initial config :Configure BGP neighborship between R1 and R3.")
490 reset_config_on_routers(tgen
)
493 "Configure static routes on R1 with a next-hop IP belonging"
494 "to the same subnet of R2's link IP."
497 create_interface_in_kernel(
501 topo
["routers"]["r4"]["links"]["r2"]["ipv4"].split("/")[0],
502 netmask
="255.255.255.0",
505 create_interface_in_kernel(
509 topo
["routers"]["r4"]["links"]["r2"]["ipv6"].split("/")[0],
513 for addr_type
in ADDR_TYPES
:
518 "network": NETWORK
[addr_type
],
519 "next_hop": topo
["routers"]["r2"]["links"]["r4"][
526 result
= create_static_routes(tgen
, input_dict_4
)
528 step("Verify that static routes are installed in RIB and FIB of R1")
534 next_hop
=topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
537 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
541 step("Redistribute static routes into BGP on R1")
546 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
547 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
552 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
555 "Verify that R2 denies the prefixes received in update message,"
556 "as next-hop IP belongs to connected interface"
558 for addr_type
in ADDR_TYPES
:
563 "network": NETWORK
[addr_type
],
564 "next_hop": topo
["routers"]["r2"]["links"]["r4"][
571 result
= verify_bgp_rib(
576 next_hop
=topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
581 ), "Testcase {} : Failed \n " "Routes are still present \n Error: {}".format(
585 step("Shut interface on R2 that has IP from the subnet as BGP next-hop")
586 intf_r2_r4
= topo
["routers"]["r2"]["links"]["r4"]["interface"]
587 shutdown_bringup_interface(tgen
, "r2", intf_r2_r4
)
589 for addr_type
in ADDR_TYPES
:
590 clear_bgp(tgen
, addr_type
, "r2")
592 "Verify that redistributed routes now appear only in BGP table,"
593 "as next-hop IP is no more active on R2"
595 for addr_type
in ADDR_TYPES
:
600 "network": NETWORK
[addr_type
],
601 "next_hop": topo
["routers"]["r2"]["links"]["r4"][
608 result
= verify_bgp_rib(
613 next_hop
=topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
615 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
619 step("No shutdown interface on R2 which was shut in previous step")
620 intf_r2_r4
= topo
["routers"]["r2"]["links"]["r4"]["interface"]
621 shutdown_bringup_interface(tgen
, "r2", intf_r2_r4
, ifaceaction
=True)
624 "Verify that R2 dosn't install prefixes RIB to FIB as next-hop"
625 "interface is up now"
627 for addr_type
in ADDR_TYPES
:
632 "network": NETWORK
[addr_type
],
633 "next_hop": topo
["routers"]["r2"]["links"]["r4"][
640 result
= verify_bgp_rib(
645 next_hop
=topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
647 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
655 next_hop
=topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
660 ), "Testcase {} : Failed \n " "Routes are still present \n Error: {}".format(
664 write_test_footer(tc_name
)
667 def test_next_hop_with_recursive_lookup_p1(request
):
669 Verify that for a BGP prefix next-hop information doesn't change
670 when same prefix is received from another peer via recursive lookup.
673 tc_name
= request
.node
.name
674 write_test_header(tc_name
)
677 # Don"t run this test if we have any failure.
678 if tgen
.routers_have_failure():
679 pytest
.skip(tgen
.errors
)
681 step("Initial config :Configure BGP neighborship between R1 and R3.")
682 reset_config_on_routers(tgen
)
684 step("Verify that BGP peering comes up.")
686 result
= verify_bgp_convergence_from_running_config(tgen
)
687 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
689 step("Do redistribute connected on router R3.")
695 "unicast": {"redistribute": [{"redist_type": "connected"}]}
698 "unicast": {"redistribute": [{"redist_type": "connected"}]}
705 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
706 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
708 step("Verify that R1 receives all connected")
709 for addr_type
in ADDR_TYPES
:
711 "ipv4": ["1.0.3.17/32", "10.0.1.0/24", "10.0.3.0/24"],
712 "ipv6": ["2001:db8:f::3:17/128", "fd00:0:0:1::/64", "fd00:0:0:3::/64"],
714 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
715 result
= verify_rib(tgen
, addr_type
, "r1", input_dict
, protocol
="bgp")
716 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
721 "Configure a BGP neighborship between R1 and R4, directly via "
724 r1_local_as
= topo
["routers"]["r1"]["bgp"]["local_as"]
725 r1_r3_addr
= topo
["routers"]["r1"]["links"]["r3"]
726 r4_local_as
= topo
["routers"]["r4"]["bgp"]["local_as"]
727 r4_r3_addr
= topo
["routers"]["r4"]["links"]["r3"]
730 for addr_type
in ADDR_TYPES
:
734 "router bgp {}".format(r1_local_as
),
735 "neighbor {} remote-as {}".format(
736 r4_r3_addr
[addr_type
].split("/")[0], r4_local_as
738 "neighbor {} timers {} {}".format(
739 r4_r3_addr
[addr_type
].split("/")[0],
743 "neighbor {} ebgp-multihop {}".format(
744 r4_r3_addr
[addr_type
].split("/")[0], ebgp_multi_hop
750 "router bgp {}".format(r4_local_as
),
751 "neighbor {} remote-as {}".format(
752 r1_r3_addr
[addr_type
].split("/")[0], r1_local_as
754 "neighbor {} timers {} {}".format(
755 r1_r3_addr
[addr_type
].split("/")[0],
759 "neighbor {} ebgp-multihop {}".format(
760 r1_r3_addr
[addr_type
].split("/")[0], ebgp_multi_hop
765 result
= apply_raw_config(tgen
, raw_config
)
766 assert result
is True, "Testcase {} : Failed Error : {}".format(tc_name
, result
)
768 for addr_type
in ADDR_TYPES
:
769 if addr_type
== "ipv4":
773 "router bgp {}".format(r1_local_as
),
774 "address-family {} unicast".format(addr_type
),
775 "no neighbor {} activate".format(
776 r4_r3_addr
["ipv6"].split("/")[0]
782 "router bgp {}".format(r4_local_as
),
783 "address-family {} unicast".format(addr_type
),
784 "no neighbor {} activate".format(
785 r1_r3_addr
["ipv6"].split("/")[0]
794 "router bgp {}".format(r1_local_as
),
795 "address-family {} unicast".format(addr_type
),
796 "neighbor {} activate".format(
797 r4_r3_addr
[addr_type
].split("/")[0]
803 "router bgp {}".format(r4_local_as
),
804 "address-family {} unicast".format(addr_type
),
805 "neighbor {} activate".format(
806 r1_r3_addr
[addr_type
].split("/")[0]
811 result
= apply_raw_config(tgen
, raw_config
)
812 assert result
is True, "Testcase {} : Failed Error : {}".format(tc_name
, result
)
814 step("Verify that BGP session between R1 and R4 comes up" "(recursively via R3).")
815 result
= verify_bgp_convergence_from_running_config(tgen
)
816 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
818 step("Do redistribute connected on router R4.")
824 "unicast": {"redistribute": [{"redist_type": "connected"}]}
827 "unicast": {"redistribute": [{"redist_type": "connected"}]}
834 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
835 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
838 "Verify that R1 now receives BGP prefix of link r3-r4 via 2 "
839 "next-hops R3 and R4. however do not install with NHT R4 in FIB."
841 for addr_type
in ADDR_TYPES
:
842 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
844 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
845 next_hop
= topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
848 tgen
, addr_type
, "r1", input_dict
, protocol
="bgp", next_hop
=next_hop
850 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
854 step("Clear bgp sessions from R1 using 'clear ip bgp *'")
855 for addr_type
in ADDR_TYPES
:
856 clear_bgp(tgen
, addr_type
, "r1")
859 "Verify that prefix of link r3-r4 is again learned via 2 "
860 "next-hops (from R3 and R4 directly)"
862 for addr_type
in ADDR_TYPES
:
863 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
865 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
866 next_hop
= topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
869 tgen
, addr_type
, "r1", input_dict
, protocol
="bgp", next_hop
=next_hop
871 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
875 step("Remove redistribution from router R3.")
884 {"redist_type": "connected", "delete": True}
891 {"redist_type": "connected", "delete": True}
900 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
901 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
904 "Verify that peering between R1-R4 goes down and prefix "
905 "of link r3-r4, with NHT R4 is withdrawn."
908 logger
.info("Sleeping for holddowntimer: {}".format(HOLD_DOWN_TIMER
))
909 sleep(HOLD_DOWN_TIMER
+ 1)
911 result
= verify_bgp_convergence_from_running_config(tgen
, expected
=False)
914 ), "Testcase {} : Failed \n" "BGP is converged \n Error : {}".format(
917 logger
.info("Expected behaviour: {}".format(result
))
919 for addr_type
in ADDR_TYPES
:
920 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
922 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
923 next_hop
= topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
926 tgen
, addr_type
, "r1", input_dict
, protocol
="bgp", next_hop
=next_hop
928 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
932 step("Re-apply redistribution on R3.")
940 "unicast": {"redistribute": [{"redist_type": "connected"}]}
943 "unicast": {"redistribute": [{"redist_type": "connected"}]}
950 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
951 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
954 "Verify that peering between R1-R4 goes down and prefix "
955 "of link r3-r4 with NHT R4 is withdrawn."
958 result
= verify_bgp_convergence_from_running_config(tgen
)
959 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
961 for addr_type
in ADDR_TYPES
:
962 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
964 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
965 next_hop
= topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
968 tgen
, addr_type
, "r1", input_dict
, protocol
="bgp", next_hop
=next_hop
970 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
974 step("Remove redistribution from router R4.")
984 {"redist_type": "connected", "delete": True}
991 {"redist_type": "connected", "delete": True}
1000 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
1001 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1004 "Verify that peering between R1-R4 doesn't go down but prefix "
1005 "of link r3-r4 with NHT R4 is withdrawn."
1008 logger
.info("Sleeping for holddowntimer: {}".format(HOLD_DOWN_TIMER
))
1009 sleep(HOLD_DOWN_TIMER
+ 1)
1011 result
= verify_bgp_convergence_from_running_config(tgen
)
1012 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1014 for addr_type
in ADDR_TYPES
:
1015 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
1017 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
1018 next_hop
= topo
["routers"]["r4"]["links"]["r3"][addr_type
].split("/")[0]
1020 result
= verify_rib(
1031 ), "Testcase {} : Failed \n " "Route is still present \n Error : {}".format(
1035 step("Re-apply redistribution on R4.")
1045 {"redist_type": "connected", "delete": True}
1052 {"redist_type": "connected", "delete": True}
1061 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
1062 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1064 step("Verify that prefix of link r3-r4 is re-learned via NHT R4.")
1066 for addr_type
in ADDR_TYPES
:
1067 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
1069 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
1070 next_hop
= topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
1072 result
= verify_rib(
1073 tgen
, addr_type
, "r1", input_dict
, protocol
="bgp", next_hop
=next_hop
1075 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1079 step("Toggle the interface on R3.")
1081 intf_r3_r4
= topo
["routers"]["r3"]["links"]["r4"]["interface"]
1082 shutdown_bringup_interface(tgen
, "r3", intf_r3_r4
)
1085 "Verify that peering between R1-R4 goes down and comes up when "
1086 "interface is toggled. Also prefix of link r3-r4(via both NHTs) is"
1087 " withdrawn and re-learned accordingly."
1090 result
= verify_bgp_convergence_from_running_config(tgen
, expected
=False)
1093 ), "Testcase {} : Failed \n" "BGP is converged \n Error : {}".format(
1096 logger
.info("Expected behaviour: {}".format(result
))
1098 for addr_type
in ADDR_TYPES
:
1099 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
1101 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
1102 next_hop
= topo
["routers"]["r4"]["links"]["r3"][addr_type
].split("/")[0]
1104 result
= verify_rib(
1115 ), "Testcase {} : Failed \n " "Route is still present \n Error : {}".format(
1119 shutdown_bringup_interface(tgen
, "r3", intf_r3_r4
, True)
1121 result
= verify_bgp_convergence_from_running_config(tgen
)
1122 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1124 for addr_type
in ADDR_TYPES
:
1125 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
1127 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
1128 next_hop
= topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
1130 result
= verify_rib(
1131 tgen
, addr_type
, "r1", input_dict
, protocol
="bgp", next_hop
=next_hop
1133 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1137 step("Toggle the interface on R4.")
1139 intf_r4_r3
= topo
["routers"]["r4"]["links"]["r3"]["interface"]
1140 shutdown_bringup_interface(tgen
, "r4", intf_r4_r3
)
1143 "Verify that peering between R1-R4 goes down and comes up when"
1144 "interface is toggled. Also prefix of link r3-r4(via R4)"
1145 " is withdrawn and re-learned accordingly."
1148 result
= verify_bgp_convergence_from_running_config(tgen
, expected
=False)
1151 ), "Testcase {} : Failed \n" "BGP is converged \n Error : {}".format(
1154 logger
.info("Expected behaviour: {}".format(result
))
1156 for addr_type
in ADDR_TYPES
:
1157 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
1159 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
1160 next_hop
= topo
["routers"]["r4"]["links"]["r3"][addr_type
].split("/")[0]
1162 result
= verify_rib(
1173 ), "Testcase {} : Failed \n " "Route is still present \n Error : {}".format(
1177 shutdown_bringup_interface(tgen
, "r4", intf_r4_r3
, True)
1179 result
= verify_bgp_convergence_from_running_config(tgen
)
1180 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1182 for addr_type
in ADDR_TYPES
:
1183 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
1185 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
1186 next_hop
= topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
1188 result
= verify_rib(
1189 tgen
, addr_type
, "r1", input_dict
, protocol
="bgp", next_hop
=next_hop
1191 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1195 write_test_footer(tc_name
)
1198 def test_BGP_path_attributes_default_values_p1(request
):
1200 Verify that BGP path attributes are present in CLI
1201 outputs and JSON format, even if set to default.
1204 tc_name
= request
.node
.name
1205 write_test_header(tc_name
)
1206 tgen
= get_topogen()
1208 # Don"t run this test if we have any failure.
1209 if tgen
.routers_have_failure():
1210 pytest
.skip(tgen
.errors
)
1212 step("Initial config: Configure BGP neighborship, between R1-R2 & R1-R3")
1213 reset_config_on_routers(tgen
)
1215 step("Advertise a set of prefixes from R1 to both peers R2 and R3")
1216 for addr_type
in ADDR_TYPES
:
1219 "static_routes": [{"network": NETWORK
[addr_type
], "next_hop": "null0"}]
1222 result
= create_static_routes(tgen
, input_dict_1
)
1228 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1229 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1234 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
1237 "Verify that advertised prefixes are received on R4 and well"
1238 "known attributes are present in the CLI and JSON outputs with"
1239 "default values without any route-map config."
1241 for addr_type
in ADDR_TYPES
:
1242 input_dict_3
= {"r4": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
1243 result
= verify_bgp_rib(
1249 topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
1250 topo
["routers"]["r3"]["links"]["r4"][addr_type
].split("/")[0],
1253 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
1257 for addr_type
in ADDR_TYPES
:
1261 "rmap_pf": [{"set": {"origin": "incomplete", "aspath": "300 100"}}]
1266 result
= verify_bgp_attributes(
1271 rmap_name
="rmap_pf",
1272 input_dict
=input_dict_4
,
1274 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
1279 "Configure a route-map to set below attribute value as 500"
1280 "and apply on R4 in an inbound direction"
1282 for addr_type
in ADDR_TYPES
:
1290 "path": {"as_num": 500, "as_action": "prepend"},
1299 result
= create_route_maps(tgen
, input_dict_4
)
1300 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1314 "name": "Path_Attribue",
1332 "name": "Path_Attribue",
1347 result
= create_router_bgp(tgen
, topo
, input_dict_5
)
1348 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1351 "Verify that once the route-map is applied all the attributes"
1352 "part of route-map, changes value to 500"
1354 for addr_type
in ADDR_TYPES
:
1362 "aspath": "500 300 100",
1370 result
= verify_bgp_attributes(
1375 rmap_name
="rmap_pf",
1376 input_dict
=input_dict_4
,
1378 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
1382 step("Remove the route-map from R4")
1395 "name": "Path_Attribue",
1414 "name": "Path_Attribue",
1430 result
= create_router_bgp(tgen
, topo
, input_dict_5
)
1431 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1434 "Verify on R4 that well known attributes are present in the CLI &"
1435 "JSON outputs again with default values without route-map config"
1437 for addr_type
in ADDR_TYPES
:
1441 "rmap_pf": [{"set": {"aspath": "300 100", "origin": "incomplete"}}]
1445 result
= verify_bgp_attributes(
1450 rmap_name
="rmap_pf",
1451 input_dict
=input_dict_4
,
1454 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
1458 write_test_footer(tc_name
)
1461 def test_BGP_peering_bw_loopback_and_physical_p1(request
):
1463 Verifying the BGP peering between loopback and
1464 physical link's IP of 2 peer routers.
1467 tc_name
= request
.node
.name
1468 write_test_header(tc_name
)
1469 tgen
= get_topogen()
1471 # Don"t run this test if we have any failure.
1472 if tgen
.routers_have_failure():
1473 pytest
.skip(tgen
.errors
)
1475 step("Initial config :Configure BGP neighborship between R1 and R3.")
1476 reset_config_on_routers(tgen
)
1478 step("Configure a loopback interface on R1")
1480 create_interface_in_kernel(
1481 tgen
, dut
, "lo10", "1.1.1.1", netmask
="255.255.255.255", create
=True
1483 create_interface_in_kernel(
1484 tgen
, dut
, "lo10", "1:1::1:1", netmask
="128", create
=True
1487 step("Configure BGP session between R1's loopbak & R3")
1488 for addr_type
in ADDR_TYPES
:
1493 "network": Loopabck_IP
["Lo_R1"][addr_type
],
1494 "next_hop": topo
["routers"]["r1"]["links"]["r3"][
1501 result
= create_static_routes(tgen
, input_dict_1
)
1502 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1505 result
= verify_rib(
1511 next_hop
=topo
["routers"]["r1"]["links"]["r3"][addr_type
].split("/")[0],
1513 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1517 for addr_type
in ADDR_TYPES
:
1521 "router bgp {}".format(topo
["routers"]["r1"]["bgp"]["local_as"]),
1522 "address-family {} unicast".format(addr_type
),
1523 "neighbor {} update-source lo10".format(
1524 topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
1526 "neighbor {} timers 1 3".format(
1527 topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
1533 "router bgp {}".format(topo
["routers"]["r3"]["bgp"]["local_as"]),
1534 "address-family {} unicast".format(addr_type
),
1535 "no neighbor {} remote-as {}".format(
1536 topo
["routers"]["r1"]["links"]["r3"][addr_type
].split("/")[0],
1537 topo
["routers"]["r1"]["bgp"]["local_as"],
1539 "neighbor {} remote-as {}".format(
1540 Loopabck_IP
["Lo_R1"][addr_type
].split("/")[0],
1541 topo
["routers"]["r1"]["bgp"]["local_as"],
1543 "neighbor {} ebgp-multihop 3".format(
1544 Loopabck_IP
["Lo_R1"][addr_type
].split("/")[0]
1549 result
= apply_raw_config(tgen
, raw_config
)
1550 assert result
is True, "Testcase {} : Failed Error : {}".format(tc_name
, result
)
1552 for addr_type
in ADDR_TYPES
:
1553 if addr_type
== "ipv6":
1557 "router bgp {}".format(
1558 topo
["routers"]["r3"]["bgp"]["local_as"]
1560 "address-family {} unicast".format(addr_type
),
1561 "neighbor {} activate".format(
1562 Loopabck_IP
["Lo_R1"][addr_type
].split("/")[0]
1571 "router bgp {}".format(
1572 topo
["routers"]["r3"]["bgp"]["local_as"]
1574 "address-family {} unicast".format(addr_type
),
1575 "no neighbor {} activate".format(
1576 Loopabck_IP
["Lo_R1"]["ipv6"].split("/")[0]
1581 result
= apply_raw_config(tgen
, raw_config
)
1582 assert result
is True, "Testcase {} : Failed Error : {}".format(tc_name
, result
)
1584 step("Verify that BGP neighborship between R1 and R3 comes up")
1585 result
= verify_bgp_convergence_from_running_config(tgen
)
1586 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1588 step("Remove ebgp-multihop command from R3")
1589 for addr_type
in ADDR_TYPES
:
1593 "router bgp {}".format(topo
["routers"]["r3"]["bgp"]["local_as"]),
1594 "no neighbor {} ebgp-multihop 3".format(
1595 Loopabck_IP
["Lo_R1"][addr_type
].split("/")[0]
1600 result
= apply_raw_config(tgen
, raw_config
)
1601 assert result
is True, "Testcase {} : Failed Error : {}".format(tc_name
, result
)
1603 step("Verify that once eBGP multi-hop is removed, BGP session goes down")
1604 result
= verify_bgp_convergence_from_running_config(tgen
, expected
=False)
1607 ), "Testcase {} : Failed \n " "BGP is converged \n Error: {}".format(
1611 step("Add ebgp-multihop command on R3 again")
1612 for addr_type
in ADDR_TYPES
:
1616 "router bgp {}".format(topo
["routers"]["r3"]["bgp"]["local_as"]),
1617 "neighbor {} ebgp-multihop 3".format(
1618 Loopabck_IP
["Lo_R1"][addr_type
].split("/")[0]
1623 result
= apply_raw_config(tgen
, raw_config
)
1624 assert result
is True, "Testcase {} : Failed Error : {}".format(tc_name
, result
)
1626 step("Verify that BGP neighborship between R1 and R3 comes up")
1627 result
= verify_bgp_convergence_from_running_config(tgen
)
1628 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1630 step("Remove update-source command from R1")
1631 for addr_type
in ADDR_TYPES
:
1635 "router bgp {}".format(topo
["routers"]["r1"]["bgp"]["local_as"]),
1636 "no neighbor {} update-source lo10".format(
1637 topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
1642 result
= apply_raw_config(tgen
, raw_config
)
1643 assert result
is True, "Testcase {} : Failed Error : {}".format(tc_name
, result
)
1645 step("Verify that BGP session goes down, when update-source is removed")
1646 result
= verify_bgp_convergence_from_running_config(tgen
, expected
=False)
1649 ), "Testcase {} : Failed \n " "BGP is converged \n Error: {}".format(
1653 step("Add update-source command on R1 again")
1654 for addr_type
in ADDR_TYPES
:
1658 "router bgp {}".format(topo
["routers"]["r1"]["bgp"]["local_as"]),
1659 "neighbor {} update-source lo10".format(
1660 topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
1665 result
= apply_raw_config(tgen
, raw_config
)
1666 assert result
is True, "Testcase {} : Failed Error : {}".format(tc_name
, result
)
1668 step("Verify that BGP neighborship between R1 and R3 comes up")
1669 result
= verify_bgp_convergence_from_running_config(tgen
)
1670 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1672 step("Remove static route from R3")
1673 for addr_type
in ADDR_TYPES
:
1678 "network": Loopabck_IP
["Lo_R1"][addr_type
],
1679 "next_hop": topo
["routers"]["r1"]["links"]["r3"][
1687 result
= create_static_routes(tgen
, input_dict_1
)
1688 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1691 result
= verify_rib(
1697 next_hop
=topo
["routers"]["r1"]["links"]["r3"][addr_type
].split("/")[0],
1702 ), "Testcase {} : Failed \n " "Routes are still present \n Error: {}".format(
1707 step("Verify that BGP session goes down, when static route is removed")
1708 result
= verify_bgp_convergence_from_running_config(tgen
, expected
=False)
1711 ), "Testcase {} : Failed \n " "BGP is converged \n Error: {}".format(
1715 step("Add static route on R3 again")
1716 for addr_type
in ADDR_TYPES
:
1721 "network": Loopabck_IP
["Lo_R1"][addr_type
],
1722 "next_hop": topo
["routers"]["r1"]["links"]["r3"][
1729 result
= create_static_routes(tgen
, input_dict_1
)
1730 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1733 result
= verify_rib(
1739 next_hop
=topo
["routers"]["r1"]["links"]["r3"][addr_type
].split("/")[0],
1741 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1745 step("Verify that BGP neighborship between R1 and R3 comes up")
1746 result
= verify_bgp_convergence_from_running_config(tgen
)
1747 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1749 step("Toggle physical interface on R1")
1750 intf_r1_r3
= topo
["routers"]["r1"]["links"]["r3"]["interface"]
1751 shutdown_bringup_interface(tgen
, "r1", intf_r1_r3
)
1753 step("Verify that BGP neighborship between R1 and R3 goes down")
1754 result
= verify_bgp_convergence_from_running_config(tgen
, expected
=False)
1757 ), "Testcase {} : Failed \n " "BGP is converged \n Error: {}".format(
1761 intf_r1_r3
= topo
["routers"]["r1"]["links"]["r3"]["interface"]
1762 shutdown_bringup_interface(tgen
, "r1", intf_r1_r3
, True)
1764 step("Verify that BGP neighborship between R1 and R3 comes up")
1765 result
= verify_bgp_convergence_from_running_config(tgen
)
1766 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1768 write_test_footer(tc_name
)
1771 def test_BGP_active_standby_preemption_and_ecmp_p1(request
):
1773 Verify that BGP Active/Standby/Pre-emption/ECMP.
1776 tc_name
= request
.node
.name
1777 write_test_header(tc_name
)
1778 tgen
= get_topogen()
1780 # Don"t run this test if we have any failure.
1781 if tgen
.routers_have_failure():
1782 pytest
.skip(tgen
.errors
)
1784 step("Initial config :Configure BGP neighborship between R1 and R3.")
1785 reset_config_on_routers(tgen
)
1787 step("Change the AS number on R2 as 200")
1788 input_dict
= {"r2": {"bgp": {"local_as": 200}}}
1789 result
= modify_as_number(tgen
, topo
, input_dict
)
1790 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1792 step("Verify BGP converge after changing the AS number on R2")
1793 result
= verify_bgp_convergence_from_running_config(tgen
)
1794 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1796 step("Advertise a set of prefixes from R1 to both peers R2 & R3")
1797 for addr_type
in ADDR_TYPES
:
1800 "static_routes": [{"network": NETWORK
[addr_type
], "next_hop": "null0"}]
1803 result
= create_static_routes(tgen
, input_dict_1
)
1804 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1812 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1813 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1819 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
1820 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1822 step("Verify that R4 receives BGP prefixes via both peer routers R2 & R3")
1823 for addr_type
in ADDR_TYPES
:
1824 input_dict_3
= {"r4": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
1825 result
= verify_bgp_rib(
1831 topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
1832 topo
["routers"]["r3"]["links"]["r4"][addr_type
].split("/")[0],
1835 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
1840 "Configure a route-map to set as-path attribute and"
1841 "apply on R3 in an inbound direction:"
1850 "set": {"path": {"as_num": 123, "as_action": "prepend"}},
1856 result
= create_route_maps(tgen
, input_dict_4
)
1857 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1871 "name": "Path_Attribue",
1889 "name": "Path_Attribue",
1903 result
= create_router_bgp(tgen
, topo
, input_dict_5
)
1904 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1906 step("Verify on R4, BGP routes with shorter as-path are installed in FIB")
1907 for addr_type
in ADDR_TYPES
:
1910 input_dict_6
= {"r4": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
1911 result
= verify_rib(
1916 next_hop
=topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
1919 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1923 step("Shutdown BGP neighorship between R1-R2")
1925 intf_r4_r2
= topo
["routers"]["r4"]["links"]["r2"]["interface"]
1926 shutdown_bringup_interface(tgen
, dut
, intf_r4_r2
)
1929 "Verify that prefixes from next-hop via R2 are withdrawn"
1930 "and installed via next-hop as R3"
1932 result
= verify_rib(
1937 next_hop
=topo
["routers"]["r3"]["links"]["r4"][addr_type
].split("/")[0],
1940 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1942 step("Do a no shut for BGP neighorship between R2-R4")
1943 shutdown_bringup_interface(tgen
, dut
, intf_r4_r2
, ifaceaction
=True)
1946 "Verify that prefixes from next-hop via R3 are withdrawn"
1947 "from R4 and installed via next-hop as R2 (preemption)"
1949 result
= verify_rib(
1954 next_hop
=topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
1957 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1959 step("Remove the route-map from R3's neighbor statement")
1972 "name": "Path_Attribue",
1991 "name": "Path_Attribue",
2006 result
= create_router_bgp(tgen
, topo
, input_dict_5
)
2007 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2009 step("Configure multipath-relax and maximum-paths 2 on R4 for ECMP")
2014 "ipv4": {"unicast": {"maximum_paths": {"ebgp": 2}}},
2015 "ipv6": {"unicast": {"maximum_paths": {"ebgp": 2}}},
2020 result
= create_router_bgp(tgen
, topo
, input_dict_8
)
2021 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2024 "r4": {"bgp": {"local_as": "400", "bestpath": {"aspath": "multipath-relax"}}}
2027 result
= create_router_bgp(tgen
, topo
, maxpath_relax
)
2028 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2030 step("Verify FIB of R4, BGP prefixes with ECMP next-hop via R2 and R3")
2031 for addr_type
in ADDR_TYPES
:
2032 input_dict
= {"r4": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
2033 result
= verify_rib(
2039 topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
2040 topo
["routers"]["r3"]["links"]["r4"][addr_type
].split("/")[0],
2043 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
2047 step("Remove multipath-relax command from R4")
2049 del_maxpath_relax
= {
2053 "bestpath": {"aspath": "multipath-relax", "delete": True},
2058 result
= create_router_bgp(tgen
, topo
, del_maxpath_relax
)
2059 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2061 step("Verify that ECMP is no longer happening on R4.")
2062 for addr_type
in ADDR_TYPES
:
2063 input_dict
= {"r4": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
2064 result
= verify_rib(
2070 topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
2071 topo
["routers"]["r3"]["links"]["r4"][addr_type
].split("/")[0],
2077 ), "Testcase {} : Failed \n " "Routes are still present \n Error: {}".format(
2081 step("Reconfigure multipath-relax command on R4")
2082 result
= create_router_bgp(tgen
, topo
, maxpath_relax
)
2083 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2085 step("Verify FIB of R4, BGP prefixes with ECMP next-hop via R2 and R3")
2086 result
= verify_rib(
2092 topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
2093 topo
["routers"]["r3"]["links"]["r4"][addr_type
].split("/")[0],
2096 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2098 step("Remove maximum-path 2 command from R4")
2121 result
= create_router_bgp(tgen
, topo
, input_dict_8
)
2122 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2124 step("Verify that ECMP is no longer happening on R4")
2125 result
= verify_rib(
2131 topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
2132 topo
["routers"]["r3"]["links"]["r4"][addr_type
].split("/")[0],
2138 ), "Testcase {} : Failed \n " "Routes are still present \n Error: {}".format(
2142 step("Re-configure maximum-path 2 command on R4")
2165 result
= create_router_bgp(tgen
, topo
, input_dict_8
)
2166 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2168 step("Verify FIB of R4, BGP prefixes with ECMP next-hop via R2 and R3")
2169 result
= verify_rib(
2175 topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
2176 topo
["routers"]["r3"]["links"]["r4"][addr_type
].split("/")[0],
2179 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2181 write_test_footer(tc_name
)
2184 def test_password_authentication_for_eBGP_and_iBGP_peers_p1(request
):
2186 Verify password authentication for eBGP and iBGP peers.
2189 tc_name
= request
.node
.name
2190 write_test_header(tc_name
)
2191 tgen
= get_topogen()
2193 # Don"t run this test if we have any failure.
2194 if tgen
.routers_have_failure():
2195 pytest
.skip(tgen
.errors
)
2197 step("Initial config :Configure BGP neighborship between R1 and R3.")
2198 reset_config_on_routers(tgen
)
2201 "Add a static route on R1 for loopbacks IP's reachability of R2, R3"
2202 "and on R2 and R3 for loopback IP of R1"
2204 for addr_type
in ADDR_TYPES
:
2205 nh1
= topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
2206 nh2
= topo
["routers"]["r1"]["links"]["r2"][addr_type
].split("/")[0]
2207 nh3
= topo
["routers"]["r1"]["links"]["r3"][addr_type
].split("/")[0]
2208 nh4
= topo
["routers"]["r2"]["links"]["r1"][addr_type
].split("/")[0]
2213 "network": topo
["routers"]["r3"]["links"]["lo"][addr_type
],
2223 "network": topo
["routers"]["r1"]["links"]["lo"][addr_type
],
2233 "network": topo
["routers"]["r1"]["links"]["lo"][addr_type
],
2243 "network": topo
["routers"]["r2"]["links"]["lo"][addr_type
],
2249 dut_list
= ["r1", "r2", "r3", "r1"]
2250 nexthop_list
= [nh1
, nh2
, nh3
, nh4
]
2251 input_dict_list
= [input_dict_1
, input_dict_2
, input_dict_3
, input_dict_4
]
2252 for dut
, next_hop
, input_dict
in zip(dut_list
, nexthop_list
, input_dict_list
):
2253 result
= create_static_routes(tgen
, input_dict
)
2254 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
2258 step("Verify that static routes are installed in FIB of routers")
2259 result
= verify_rib(
2260 tgen
, addr_type
, dut
, input_dict
, next_hop
=next_hop
, protocol
="static"
2262 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
2266 step("Configure BGP sessions between R1-R2 and R1-R3 over loopback IPs")
2267 for routerN
in ["r1", "r3"]:
2268 for addr_type
in ADDR_TYPES
:
2271 elif routerN
== "r3":
2273 topo
["routers"][routerN
]["bgp"]["address_family"][addr_type
]["unicast"][
2275 ][bgp_neighbor
]["dest_link"] = {
2276 "lo": {"ebgp_multihop": 2, "source_link": "lo"}
2278 build_config_from_json(tgen
, topo
, save_bkup
=False)
2280 for routerN
in ["r1", "r2"]:
2281 for addr_type
in ADDR_TYPES
:
2284 elif routerN
== "r2":
2286 topo
["routers"][routerN
]["bgp"]["address_family"][addr_type
]["unicast"][
2288 ][bgp_neighbor
]["dest_link"] = {"lo": {"source_link": "lo"}}
2289 build_config_from_json(tgen
, topo
, save_bkup
=False)
2291 for routerN
in ["r1", "r2", "r3"]:
2292 for addr_type
in ADDR_TYPES
:
2293 for bgp_neighbor
in topo
["routers"][routerN
]["bgp"]["address_family"][
2295 ]["unicast"]["neighbor"].keys():
2296 if routerN
in ["r1", "r2", "r3"] and bgp_neighbor
== "r4":
2298 if addr_type
== "ipv4":
2299 topo
["routers"][routerN
]["bgp"]["address_family"][addr_type
][
2301 ]["neighbor"][bgp_neighbor
]["dest_link"] = {
2302 "lo": {"deactivate": "ipv6"}
2304 elif addr_type
== "ipv6":
2305 topo
["routers"][routerN
]["bgp"]["address_family"][addr_type
][
2307 ]["neighbor"][bgp_neighbor
]["dest_link"] = {
2308 "lo": {"deactivate": "ipv4"}
2310 build_config_from_json(tgen
, topo
, save_bkup
=False)
2312 result
= verify_bgp_convergence(tgen
, topo
)
2313 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2315 step("Configure authentication password on R1 for neighbor statements")
2316 for bgp_neighbor
in ["r2", "r3"]:
2317 for addr_type
in ADDR_TYPES
:
2318 topo
["routers"]["r1"]["bgp"]["address_family"][addr_type
]["unicast"][
2320 ][bgp_neighbor
]["dest_link"] = {"lo": {"password": "vmware"}}
2321 build_config_from_json(tgen
, topo
, save_bkup
=False)
2324 "Verify that both sessions go down as only R1 has password"
2325 "configured but not peer routers"
2327 result
= verify_bgp_convergence(tgen
, topo
, expected
=False)
2330 ), "Testcase {} : Failed \n " "BGP is converged \n Error: {}".format(
2334 step("configure same password on R2 and R3")
2335 for routerN
in ["r2", "r3"]:
2336 for addr_type
in ADDR_TYPES
:
2337 topo
["routers"][routerN
]["bgp"]["address_family"][addr_type
]["unicast"][
2339 ]["r1"]["dest_link"] = {"lo": {"password": "vmware"}}
2340 build_config_from_json(tgen
, topo
, save_bkup
=False)
2342 step("Verify that all BGP sessions come up due to identical passwords")
2343 result
= verify_bgp_convergence(tgen
, topo
)
2344 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2346 step("Configure same password on R2 and R3, but in CAPs.")
2347 for routerN
in ["r2", "r3"]:
2348 for addr_type
in ADDR_TYPES
:
2349 topo
["routers"][routerN
]["bgp"]["address_family"][addr_type
]["unicast"][
2351 ]["r1"]["dest_link"] = {"lo": {"password": "VMWARE"}}
2352 build_config_from_json(tgen
, topo
, save_bkup
=False)
2355 "Verify that BGP sessions do not come up as password"
2356 "strings are in CAPs on R2 and R3"
2358 result
= verify_bgp_convergence(tgen
, topo
, expected
=False)
2361 ), "Testcase {} : Failed \n " "BGP is converged \n Error: {}".format(
2365 step("Configure same password on R2 and R3 without CAPs")
2366 for routerN
in ["r2", "r3"]:
2367 for addr_type
in ADDR_TYPES
:
2368 topo
["routers"][routerN
]["bgp"]["address_family"][addr_type
]["unicast"][
2370 ]["r1"]["dest_link"] = {"lo": {"password": "vmware"}}
2371 build_config_from_json(tgen
, topo
, save_bkup
=False)
2373 step("Verify all BGP sessions come up again due to identical passwords")
2374 result
= verify_bgp_convergence(tgen
, topo
)
2375 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2377 step("Remove password from R1")
2378 for bgp_neighbor
in ["r2", "r3"]:
2379 for addr_type
in ADDR_TYPES
:
2380 topo
["routers"]["r1"]["bgp"]["address_family"][addr_type
]["unicast"][
2382 ][bgp_neighbor
]["dest_link"] = {"lo": {"no_password": "vmware"}}
2383 build_config_from_json(tgen
, topo
, save_bkup
=False)
2385 step("Verify if password is removed from R1, both sessions go down again")
2386 result
= verify_bgp_convergence(tgen
, topo
, expected
=False)
2389 ), "Testcase {} : Failed \n " "BGP is converged \n Error: {}".format(
2393 step("Configure alphanumeric password on R1 and peer routers R2,R3")
2394 for bgp_neighbor
in ["r2", "r3"]:
2395 for addr_type
in ADDR_TYPES
:
2396 topo
["routers"]["r1"]["bgp"]["address_family"][addr_type
]["unicast"][
2398 ][bgp_neighbor
]["dest_link"] = {"lo": {"password": "Vmware@123"}}
2399 build_config_from_json(tgen
, topo
, save_bkup
=False)
2401 for routerN
in ["r2", "r3"]:
2402 for addr_type
in ADDR_TYPES
:
2403 topo
["routers"][routerN
]["bgp"]["address_family"][addr_type
]["unicast"][
2405 ]["r1"]["dest_link"] = {"lo": {"password": "Vmware@123"}}
2406 build_config_from_json(tgen
, topo
, save_bkup
=False)
2409 "Verify that sessions Come up irrespective of characters"
2410 "used in password string"
2412 result
= verify_bgp_convergence(tgen
, topo
)
2413 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2415 write_test_footer(tc_name
)
2418 if __name__
== "__main__":
2419 args
= ["-s"] + sys
.argv
[1:]
2420 sys
.exit(pytest
.main(args
))