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.
45 from time
import sleep
46 from copy
import deepcopy
48 # Save the Current Working Directory to find configuration files.
49 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
50 sys
.path
.append(os
.path
.join(CWD
, "../"))
52 # pylint: disable=C0413
53 # Import topogen and topotest helpers
54 from lib
import topotest
55 from mininet
.topo
import Topo
56 from lib
.topogen
import Topogen
, get_topogen
58 # Import topoJson from lib, to create topology and initial configuration
59 from lib
.common_config
import (
64 reset_config_on_routers
,
70 create_interface_in_kernel
,
71 shutdown_bringup_interface
,
74 kill_mininet_routers_process
,
76 from lib
.topolog
import logger
78 verify_bgp_convergence
,
82 verify_bgp_convergence_from_running_config
,
84 verify_bgp_attributes
,
87 from lib
.topojson
import build_topo_from_json
, build_config_from_json
89 # Reading the data from JSON File for topology and configuration creation
90 jsonFile
= "{}/bgp_recursive_route_ebgp_multi_hop.json".format(CWD
)
92 with
open(jsonFile
, "r") as topoJson
:
93 topo
= json
.load(topoJson
)
95 logger
.info("Could not read file:", jsonFile
)
98 BGP_CONVERGENCE
= False
101 ADDR_TYPES
= check_address_types()
103 "ipv4": ["100.1.1.1/32", "100.1.1.2/32"],
104 "ipv6": ["100::1/128", "100::2/128"],
108 "N1": {"ipv4": "20.20.20.20/24", "ipv6": "20:20::20:20/120"},
109 "N2": {"ipv4": "30.30.30.30/24", "ipv6": "30:30::30:30/120"},
110 "N3": {"ipv4": "40.40.40.40/24", "ipv6": "40:40::40:40/120"},
114 "4thOctate": {"ipv4": "10.0.1.250/24", "ipv6": "fd00:0:0:1::100/64"},
115 "3rdOctate": {"ipv4": "10.0.10.2/24", "ipv6": "fd00:0:0:10::2/64"},
119 "Lo_R1": {"ipv4": "1.1.1.1/32", "ipv6": "1:1::1:1/128"},
120 "Lo_R4": {"ipv4": "4.4.4.4/32", "ipv6": "4:4::4:4/128"},
124 class CreateTopo(Topo
):
126 Test BasicTopo - topology 1
128 * `Topo`: Topology object
131 def build(self
, *_args
, **_opts
):
133 tgen
= get_topogen(self
)
135 # Building topology from json file
136 build_topo_from_json(tgen
, topo
)
139 def setup_module(mod
):
141 Sets up the pytest environment
146 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
147 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
148 logger
.info("=" * 40)
150 logger
.info("Running setup_module to create topology")
152 # This function initiates the topology build with Topogen...
153 tgen
= Topogen(CreateTopo
, mod
.__name
__)
154 # ... and here it calls Mininet initialization functions.
156 # Starting topology, create tmp files which are loaded to routers
157 # to start deamons and then start routers
160 # Creating configuration from JSON
161 build_config_from_json(tgen
, topo
)
163 global BGP_CONVERGENCE
164 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
165 assert BGP_CONVERGENCE
is True, "setup_module : Failed \n Error : {}".format(
169 logger
.info("Running setup_module() done")
172 def teardown_module():
173 """Teardown the pytest environment"""
175 logger
.info("Running teardown_module to delete topology")
179 # Stop toplogy and Remove tmp files
183 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
185 logger
.info("=" * 40)
188 #####################################################
192 #####################################################
195 def test_recursive_routes_iBGP_peer_p1(request
):
197 Verify that BGP routes are installed in iBGP peer, only
198 when there is a recursive route for next-hop reachability.
201 tc_name
= request
.node
.name
202 write_test_header(tc_name
)
205 # Don"t run this test if we have any failure.
206 if tgen
.routers_have_failure():
207 pytest
.skip(tgen
.errors
)
209 step("Initial config :Configure BGP neighborship between R1 and R3.")
210 reset_config_on_routers(tgen
)
216 "Configure static routes on R1 pointing next-hop as connected"
217 "link between R1 & R3's IP"
219 for addr_type
in ADDR_TYPES
:
224 "network": NETWORK
[addr_type
],
225 "next_hop": topo
["routers"]["r3"]["links"]["r1"][
232 result
= create_static_routes(tgen
, input_dict_4
)
235 "Verify on router R1 that these static routes are "
236 "installed in RIB+FIB of R1"
243 next_hop
=topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0],
246 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
250 step("Redistribute these static routes in BGP on router R1")
255 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
256 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
261 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
264 "Verify on router R1 that these static routes are installed"
265 "in RIB table as well"
267 for addr_type
in ADDR_TYPES
:
272 "network": NETWORK
[addr_type
],
273 "next_hop": topo
["routers"]["r3"]["links"]["r1"][
280 result
= verify_bgp_rib(
285 next_hop
=topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0],
287 assert result
is True, "Testcase : Failed \n Error : {}".format(
292 "Configure a static routes for next hop IP on R2 via multiple"
293 "recursive static routes"
296 create_interface_in_kernel(
297 tgen
, dut
, "lo", "40.40.40.50", netmask
="255.255.255.0", create
=True
299 create_interface_in_kernel(
300 tgen
, dut
, "lo", "40:40::40:50", netmask
="120", create
=True
302 for addr_type
in ADDR_TYPES
:
307 "network": topo
["routers"]["r3"]["links"]["r1"][addr_type
],
308 "next_hop": RECUR_NEXT_HOP
["N1"][addr_type
].split("/")[0],
311 "network": RECUR_NEXT_HOP
["N1"][addr_type
],
312 "next_hop": RECUR_NEXT_HOP
["N2"][addr_type
].split("/")[0],
315 "network": RECUR_NEXT_HOP
["N2"][addr_type
],
316 "next_hop": RECUR_NEXT_HOP
["N3"][addr_type
].split("/")[0],
321 result
= create_static_routes(tgen
, input_dict_3
)
322 assert result
is True, "Testcase : Failed \n Error : {}".format(
326 step("verify if redistributed routes are now installed in FIB of R2")
332 next_hop
=topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0],
335 assert result
is True, "Testcase : Failed \n Error : {}".format(
339 step("Delete 1 route from static recursive for the next-hop IP")
341 for addr_type
in ADDR_TYPES
:
346 "network": RECUR_NEXT_HOP
["N1"][addr_type
],
347 "next_hop": RECUR_NEXT_HOP
["N2"][addr_type
].split("/")[0],
353 result
= create_static_routes(tgen
, input_dict_3
)
354 assert result
is True, "Testcase : Failed \n Error : {}".format(
358 step("Verify that redistributed routes are withdrawn from FIB of R2")
364 next_hop
=topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0],
368 assert result
is not True, "Testcase : Failed \n Error : {}".format(
372 step("Reconfigure the same static route on R2 again")
374 for addr_type
in ADDR_TYPES
:
379 "network": RECUR_NEXT_HOP
["N1"][addr_type
],
380 "next_hop": RECUR_NEXT_HOP
["N2"][addr_type
].split("/")[0],
385 result
= create_static_routes(tgen
, input_dict_3
)
386 assert result
is True, "Testcase : Failed \n Error : {}".format(
390 step("Verify that redistributed routes are again installed" "in FIB of R2")
396 next_hop
=topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0],
399 assert result
is True, "Testcase : Failed \n Error : {}".format(
403 step("Configure static route with changed next-hop from same subnet")
404 for addr_type
in ADDR_TYPES
:
409 "network": NETWORK
[addr_type
],
410 "next_hop": topo
["routers"]["r3"]["links"]["r1"][
416 "network": NETWORK
[addr_type
],
417 "next_hop": CHANGED_NEXT_HOP
["4thOctate"][addr_type
].split("/")[
424 result
= create_static_routes(tgen
, input_dict_4
)
425 assert result
is True, "Testcase : Failed \n Error : {}".format(
429 result
= verify_rib(tgen
, addr_type
, "r1", input_dict_4
, protocol
="static")
430 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
435 "Verify that redistributed routes are not withdrawn as changed"
436 "next-hop IP, belongs to the same subnet"
438 result
= verify_rib(tgen
, addr_type
, "r2", input_dict_4
, protocol
="bgp")
439 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
443 step("Configure static route with changed next-hop from different subnet")
445 create_interface_in_kernel(
446 tgen
, dut
, "lo10", "10.0.10.10", netmask
="255.255.255.0", create
=True
448 create_interface_in_kernel(
449 tgen
, dut
, "lo10", "fd00:0:0:10::104", netmask
="64", create
=True
451 for addr_type
in ADDR_TYPES
:
456 "network": NETWORK
[addr_type
],
457 "next_hop": CHANGED_NEXT_HOP
["4thOctate"][addr_type
].split("/")[
463 "network": NETWORK
[addr_type
],
464 "next_hop": CHANGED_NEXT_HOP
["3rdOctate"][addr_type
].split("/")[
471 result
= create_static_routes(tgen
, input_dict_4
)
472 assert result
is True, "Testcase : Failed \n Error : {}".format(
476 result
= verify_rib(tgen
, addr_type
, "r1", input_dict_4
, protocol
="static")
477 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
482 "Verify that redistributed routes are withdrawn as changed "
483 "next-hop IP, belongs to different subnet"
486 tgen
, addr_type
, "r2", input_dict_4
, protocol
="bgp", expected
=False
488 assert result
is not True, "Testcase {} : Failed \n Error : {}".format(
492 write_test_footer(tc_name
)
495 def test_next_hop_as_self_ip_p1(request
):
497 Verify that any BGP prefix received with next hop as
498 self-ip is not installed in BGP RIB or FIB table.
501 tc_name
= request
.node
.name
502 write_test_header(tc_name
)
505 # Don"t run this test if we have any failure.
506 if tgen
.routers_have_failure():
507 pytest
.skip(tgen
.errors
)
509 step("Initial config :Configure BGP neighborship between R1 and R3.")
510 reset_config_on_routers(tgen
)
513 "Configure static routes on R1 with a next-hop IP belonging"
514 "to the same subnet of R2's link IP."
517 create_interface_in_kernel(
521 topo
["routers"]["r4"]["links"]["r2"]["ipv4"].split("/")[0],
522 netmask
="255.255.255.0",
525 create_interface_in_kernel(
529 topo
["routers"]["r4"]["links"]["r2"]["ipv6"].split("/")[0],
533 for addr_type
in ADDR_TYPES
:
538 "network": NETWORK
[addr_type
],
539 "next_hop": topo
["routers"]["r2"]["links"]["r4"][
546 result
= create_static_routes(tgen
, input_dict_4
)
548 step("Verify that static routes are installed in RIB and FIB of R1")
554 next_hop
=topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
557 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
561 step("Redistribute static routes into BGP on R1")
566 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
567 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
572 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
575 "Verify that R2 denies the prefixes received in update message,"
576 "as next-hop IP belongs to connected interface"
578 for addr_type
in ADDR_TYPES
:
583 "network": NETWORK
[addr_type
],
584 "next_hop": topo
["routers"]["r2"]["links"]["r4"][
591 result
= verify_bgp_rib(
596 next_hop
=topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
599 assert result
is not True, "Testcase : Failed \n Error : {}".format(
603 step("Shut interface on R2 that has IP from the subnet as BGP next-hop")
604 intf_r2_r4
= topo
["routers"]["r2"]["links"]["r4"]["interface"]
605 shutdown_bringup_interface(tgen
, "r2", intf_r2_r4
)
607 for addr_type
in ADDR_TYPES
:
608 clear_bgp(tgen
, addr_type
, "r2")
610 "Verify that redistributed routes now appear only in BGP table,"
611 "as next-hop IP is no more active on R2"
613 for addr_type
in ADDR_TYPES
:
618 "network": NETWORK
[addr_type
],
619 "next_hop": topo
["routers"]["r2"]["links"]["r4"][
626 result
= verify_bgp_rib(
631 next_hop
=topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
633 assert result
is True, "Testcase : Failed \n Error : {}".format(
637 step("No shutdown interface on R2 which was shut in previous step")
638 intf_r2_r4
= topo
["routers"]["r2"]["links"]["r4"]["interface"]
639 shutdown_bringup_interface(tgen
, "r2", intf_r2_r4
, ifaceaction
=True)
642 "Verify that R2 dosn't install prefixes RIB to FIB as next-hop"
643 "interface is up now"
645 for addr_type
in ADDR_TYPES
:
650 "network": NETWORK
[addr_type
],
651 "next_hop": topo
["routers"]["r2"]["links"]["r4"][
658 result
= verify_bgp_rib(
663 next_hop
=topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
665 assert result
is True, "Testcase : Failed \n Error : {}".format(
673 next_hop
=topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
676 assert result
is not True, "Testcase : Failed \n Error : {}".format(
680 write_test_footer(tc_name
)
683 def test_next_hop_with_recursive_lookup_p1(request
):
685 Verify that for a BGP prefix next-hop information doesn't change
686 when same prefix is received from another peer via recursive lookup.
689 tc_name
= request
.node
.name
690 write_test_header(tc_name
)
693 # Don"t run this test if we have any failure.
694 if tgen
.routers_have_failure():
695 pytest
.skip(tgen
.errors
)
697 step("Initial config :Configure BGP neighborship between R1 and R3.")
698 reset_config_on_routers(tgen
)
700 step("Verify that BGP peering comes up.")
702 result
= verify_bgp_convergence_from_running_config(tgen
)
703 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
705 step("Do redistribute connected on router R3.")
711 "unicast": {"redistribute": [{"redist_type": "connected"}]}
714 "unicast": {"redistribute": [{"redist_type": "connected"}]}
721 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
722 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
724 step("Verify that R1 receives all connected")
725 for addr_type
in ADDR_TYPES
:
727 "ipv4": ["1.0.3.17/32", "10.0.1.0/24", "10.0.3.0/24"],
728 "ipv6": ["2001:db8:f::3:17/128", "fd00:0:0:1::/64", "fd00:0:0:3::/64"],
730 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
731 result
= verify_rib(tgen
, addr_type
, "r1", input_dict
, protocol
="bgp")
732 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
737 "Configure a BGP neighborship between R1 and R4, directly via "
740 r1_local_as
= topo
["routers"]["r1"]["bgp"]["local_as"]
741 r1_r3_addr
= topo
["routers"]["r1"]["links"]["r3"]
742 r4_local_as
= topo
["routers"]["r4"]["bgp"]["local_as"]
743 r4_r3_addr
= topo
["routers"]["r4"]["links"]["r3"]
746 for addr_type
in ADDR_TYPES
:
750 "router bgp {}".format(r1_local_as
),
751 "neighbor {} remote-as {}".format(
752 r4_r3_addr
[addr_type
].split("/")[0], r4_local_as
754 "neighbor {} timers {} {}".format(
755 r4_r3_addr
[addr_type
].split("/")[0],
759 "neighbor {} ebgp-multihop {}".format(
760 r4_r3_addr
[addr_type
].split("/")[0], ebgp_multi_hop
766 "router bgp {}".format(r4_local_as
),
767 "neighbor {} remote-as {}".format(
768 r1_r3_addr
[addr_type
].split("/")[0], r1_local_as
770 "neighbor {} timers {} {}".format(
771 r1_r3_addr
[addr_type
].split("/")[0],
775 "neighbor {} ebgp-multihop {}".format(
776 r1_r3_addr
[addr_type
].split("/")[0], ebgp_multi_hop
781 result
= apply_raw_config(tgen
, raw_config
)
782 assert result
is True, "Testcase {} : Failed Error : {}".format(tc_name
, result
)
784 for addr_type
in ADDR_TYPES
:
785 if addr_type
== "ipv4":
789 "router bgp {}".format(r1_local_as
),
790 "address-family {} unicast".format(addr_type
),
791 "no neighbor {} activate".format(
792 r4_r3_addr
["ipv6"].split("/")[0]
798 "router bgp {}".format(r4_local_as
),
799 "address-family {} unicast".format(addr_type
),
800 "no neighbor {} activate".format(
801 r1_r3_addr
["ipv6"].split("/")[0]
810 "router bgp {}".format(r1_local_as
),
811 "address-family {} unicast".format(addr_type
),
812 "neighbor {} activate".format(
813 r4_r3_addr
[addr_type
].split("/")[0]
819 "router bgp {}".format(r4_local_as
),
820 "address-family {} unicast".format(addr_type
),
821 "neighbor {} activate".format(
822 r1_r3_addr
[addr_type
].split("/")[0]
827 result
= apply_raw_config(tgen
, raw_config
)
828 assert result
is True, "Testcase {} : Failed Error : {}".format(tc_name
, result
)
830 step("Verify that BGP session between R1 and R4 comes up" "(recursively via R3).")
831 result
= verify_bgp_convergence_from_running_config(tgen
)
832 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
834 step("Do redistribute connected on router R4.")
840 "unicast": {"redistribute": [{"redist_type": "connected"}]}
843 "unicast": {"redistribute": [{"redist_type": "connected"}]}
850 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
851 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
854 "Verify that R1 now receives BGP prefix of link r3-r4 via 2 "
855 "next-hops R3 and R4. however do not install with NHT R4 in FIB."
857 for addr_type
in ADDR_TYPES
:
858 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
860 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
861 next_hop
= topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
864 tgen
, addr_type
, "r1", input_dict
, protocol
="bgp", next_hop
=next_hop
866 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
870 step("Clear bgp sessions from R1 using 'clear ip bgp *'")
871 for addr_type
in ADDR_TYPES
:
872 clear_bgp(tgen
, addr_type
, "r1")
875 "Verify that prefix of link r3-r4 is again learned via 2 "
876 "next-hops (from R3 and R4 directly)"
878 for addr_type
in ADDR_TYPES
:
879 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
881 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
882 next_hop
= topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
885 tgen
, addr_type
, "r1", input_dict
, protocol
="bgp", next_hop
=next_hop
887 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
891 step("Remove redistribution from router R3.")
900 {"redist_type": "connected", "delete": True}
907 {"redist_type": "connected", "delete": True}
916 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
917 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
920 "Verify that peering between R1-R4 goes down and prefix "
921 "of link r3-r4, with NHT R4 is withdrawn."
924 logger
.info("Sleeping for holddowntimer: {}".format(HOLD_DOWN_TIMER
))
925 sleep(HOLD_DOWN_TIMER
+ 1)
927 result
= verify_bgp_convergence_from_running_config(tgen
, expected
=False)
930 ), "Testcase {} : Failed \n" "BGP is converged \n Error : {}".format(
933 logger
.info("Expected behaviour: {}".format(result
))
935 for addr_type
in ADDR_TYPES
:
936 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
938 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
939 next_hop
= topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
942 tgen
, addr_type
, "r1", input_dict
, protocol
="bgp", next_hop
=next_hop
944 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
948 step("Re-apply redistribution on R3.")
956 "unicast": {"redistribute": [{"redist_type": "connected"}]}
959 "unicast": {"redistribute": [{"redist_type": "connected"}]}
966 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
967 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
970 "Verify that peering between R1-R4 goes down and prefix "
971 "of link r3-r4 with NHT R4 is withdrawn."
974 result
= verify_bgp_convergence_from_running_config(tgen
)
975 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
977 for addr_type
in ADDR_TYPES
:
978 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
980 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
981 next_hop
= topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
984 tgen
, addr_type
, "r1", input_dict
, protocol
="bgp", next_hop
=next_hop
986 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
990 step("Remove redistribution from router R4.")
1000 {"redist_type": "connected", "delete": True}
1007 {"redist_type": "connected", "delete": True}
1016 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
1017 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1020 "Verify that peering between R1-R4 doesn't go down but prefix "
1021 "of link r3-r4 with NHT R4 is withdrawn."
1024 logger
.info("Sleeping for holddowntimer: {}".format(HOLD_DOWN_TIMER
))
1025 sleep(HOLD_DOWN_TIMER
+ 1)
1027 result
= verify_bgp_convergence_from_running_config(tgen
)
1028 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1030 for addr_type
in ADDR_TYPES
:
1031 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
1033 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
1034 next_hop
= topo
["routers"]["r4"]["links"]["r3"][addr_type
].split("/")[0]
1036 result
= verify_rib(
1047 ), "Testcase {} : Failed \n " "Route is still present \n Error : {}".format(
1051 step("Re-apply redistribution on R4.")
1061 {"redist_type": "connected", "delete": True}
1068 {"redist_type": "connected", "delete": True}
1077 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
1078 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1080 step("Verify that prefix of link r3-r4 is re-learned via NHT R4.")
1082 for addr_type
in ADDR_TYPES
:
1083 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
1085 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
1086 next_hop
= topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
1088 result
= verify_rib(
1089 tgen
, addr_type
, "r1", input_dict
, protocol
="bgp", next_hop
=next_hop
1091 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1095 step("Toggle the interface on R3(ifconfig 192.34).")
1097 intf_r3_r4
= topo
["routers"]["r3"]["links"]["r4"]["interface"]
1098 shutdown_bringup_interface(tgen
, "r3", intf_r3_r4
)
1101 "Verify that peering between R1-R4 goes down and comes up when "
1102 "interface is toggled. Also prefix of link r3-r4(via both NHTs) is"
1103 " withdrawn and re-learned accordingly."
1106 result
= verify_bgp_convergence_from_running_config(tgen
, expected
=False)
1109 ), "Testcase {} : Failed \n" "BGP is converged \n Error : {}".format(
1112 logger
.info("Expected behaviour: {}".format(result
))
1114 for addr_type
in ADDR_TYPES
:
1115 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
1117 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
1118 next_hop
= topo
["routers"]["r4"]["links"]["r3"][addr_type
].split("/")[0]
1120 result
= verify_rib(
1131 ), "Testcase {} : Failed \n " "Route is still present \n Error : {}".format(
1135 shutdown_bringup_interface(tgen
, "r3", intf_r3_r4
, True)
1137 result
= verify_bgp_convergence_from_running_config(tgen
)
1138 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1140 for addr_type
in ADDR_TYPES
:
1141 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
1143 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
1144 next_hop
= topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
1146 result
= verify_rib(
1147 tgen
, addr_type
, "r1", input_dict
, protocol
="bgp", next_hop
=next_hop
1149 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1153 step("Toggle the interface on R4(ifconfig 192.34).")
1155 intf_r4_r3
= topo
["routers"]["r4"]["links"]["r3"]["interface"]
1156 shutdown_bringup_interface(tgen
, "r4", intf_r4_r3
)
1159 "Verify that peering between R1-R4 goes down and comes up when"
1160 "interface is toggled. Also prefix of link r3-r4(via R4)"
1161 " is withdrawn and re-learned accordingly."
1164 result
= verify_bgp_convergence_from_running_config(tgen
, expected
=False)
1167 ), "Testcase {} : Failed \n" "BGP is converged \n Error : {}".format(
1170 logger
.info("Expected behaviour: {}".format(result
))
1172 for addr_type
in ADDR_TYPES
:
1173 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
1175 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
1176 next_hop
= topo
["routers"]["r4"]["links"]["r3"][addr_type
].split("/")[0]
1178 result
= verify_rib(
1189 ), "Testcase {} : Failed \n " "Route is still present \n Error : {}".format(
1193 shutdown_bringup_interface(tgen
, "r4", intf_r4_r3
, True)
1195 result
= verify_bgp_convergence_from_running_config(tgen
)
1196 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1198 for addr_type
in ADDR_TYPES
:
1199 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
1201 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
1202 next_hop
= topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
1204 result
= verify_rib(
1205 tgen
, addr_type
, "r1", input_dict
, protocol
="bgp", next_hop
=next_hop
1207 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1211 write_test_footer(tc_name
)
1214 def test_BGP_path_attributes_default_values_p1(request
):
1216 Verify that BGP path attributes are present in CLI
1217 outputs and JSON format, even if set to default.
1220 tc_name
= request
.node
.name
1221 write_test_header(tc_name
)
1222 tgen
= get_topogen()
1224 # Don"t run this test if we have any failure.
1225 if tgen
.routers_have_failure():
1226 pytest
.skip(tgen
.errors
)
1228 step("Initial config: Configure BGP neighborship, between R1-R2 & R1-R3")
1229 reset_config_on_routers(tgen
)
1231 step("Advertise a set of prefixes from R1 to both peers R2 and R3")
1232 for addr_type
in ADDR_TYPES
:
1235 "static_routes": [{"network": NETWORK
[addr_type
], "next_hop": "null0"}]
1238 result
= create_static_routes(tgen
, input_dict_1
)
1244 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1245 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1250 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
1253 "Verify that advertised prefixes are received on R4 and well"
1254 "known attributes are present in the CLI and JSON outputs with"
1255 "default values without any route-map config."
1257 for addr_type
in ADDR_TYPES
:
1258 input_dict_3
= {"r4": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
1259 result
= verify_bgp_rib(
1265 topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
1266 topo
["routers"]["r3"]["links"]["r4"][addr_type
].split("/")[0],
1269 assert result
is True, "Testcase : Failed \n Error : {}".format(
1273 for addr_type
in ADDR_TYPES
:
1277 "rmap_pf": [{"set": {"origin": "incomplete", "aspath": "300 100"}}]
1282 result
= verify_bgp_attributes(
1287 rmap_name
="rmap_pf",
1288 input_dict
=input_dict_4
,
1290 assert result
is True, "Testcase : Failed \n Error : {}".format(
1295 "Configure a route-map to set below attribute value as 500"
1296 "and apply on R4 in an inbound direction"
1298 for addr_type
in ADDR_TYPES
:
1306 "path": {"as_num": 500, "as_action": "prepend"},
1315 result
= create_route_maps(tgen
, input_dict_4
)
1316 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1330 "name": "Path_Attribue",
1348 "name": "Path_Attribue",
1363 result
= create_router_bgp(tgen
, topo
, input_dict_5
)
1364 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1367 "Verify that once the route-map is applied all the attributes"
1368 "part of route-map, changes value to 500"
1370 for addr_type
in ADDR_TYPES
:
1378 "aspath": "500 300 100",
1386 result
= verify_bgp_attributes(
1391 rmap_name
="rmap_pf",
1392 input_dict
=input_dict_4
,
1394 assert result
is True, "Testcase : Failed \n Error : {}".format(
1398 step("Remove the route-map from R4")
1411 "name": "Path_Attribue",
1430 "name": "Path_Attribue",
1446 result
= create_router_bgp(tgen
, topo
, input_dict_5
)
1447 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1450 "Verify on R4 that well known attributes are present in the CLI &"
1451 "JSON outputs again with default values without route-map config"
1453 for addr_type
in ADDR_TYPES
:
1457 "rmap_pf": [{"set": {"aspath": "300 100", "origin": "incomplete"}}]
1461 result
= verify_bgp_attributes(
1466 rmap_name
="rmap_pf",
1467 input_dict
=input_dict_4
,
1470 assert result
is True, "Testcase : Failed \n Error : {}".format(
1474 write_test_footer(tc_name
)
1477 def test_BGP_peering_bw_loopback_and_physical_p1(request
):
1479 Verifying the BGP peering between loopback and
1480 physical link's IP of 2 peer routers.
1483 tc_name
= request
.node
.name
1484 write_test_header(tc_name
)
1485 tgen
= get_topogen()
1487 # Don"t run this test if we have any failure.
1488 if tgen
.routers_have_failure():
1489 pytest
.skip(tgen
.errors
)
1491 step("Initial config :Configure BGP neighborship between R1 and R3.")
1492 reset_config_on_routers(tgen
)
1494 step("Configure a loopback interface on R1")
1496 create_interface_in_kernel(
1497 tgen
, dut
, "lo10", "1.1.1.1", netmask
="255.255.255.255", create
=True
1499 create_interface_in_kernel(
1500 tgen
, dut
, "lo10", "1:1::1:1", netmask
="128", create
=True
1503 step("Configure BGP session between R1's loopbak & R3")
1504 for addr_type
in ADDR_TYPES
:
1509 "network": Loopabck_IP
["Lo_R1"][addr_type
],
1510 "next_hop": topo
["routers"]["r1"]["links"]["r3"][
1517 result
= create_static_routes(tgen
, input_dict_1
)
1518 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1521 result
= verify_rib(
1527 next_hop
=topo
["routers"]["r1"]["links"]["r3"][addr_type
].split("/")[0],
1529 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1533 for addr_type
in ADDR_TYPES
:
1537 "router bgp {}".format(topo
["routers"]["r1"]["bgp"]["local_as"]),
1538 "address-family {} unicast".format(addr_type
),
1539 "neighbor {} update-source lo10".format(
1540 topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
1542 "neighbor {} timers 1 3".format(
1543 topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
1549 "router bgp {}".format(topo
["routers"]["r3"]["bgp"]["local_as"]),
1550 "address-family {} unicast".format(addr_type
),
1551 "no neighbor {} remote-as {}".format(
1552 topo
["routers"]["r1"]["links"]["r3"][addr_type
].split("/")[0],
1553 topo
["routers"]["r1"]["bgp"]["local_as"],
1555 "neighbor {} remote-as {}".format(
1556 Loopabck_IP
["Lo_R1"][addr_type
].split("/")[0],
1557 topo
["routers"]["r1"]["bgp"]["local_as"],
1559 "neighbor {} ebgp-multihop 3".format(
1560 Loopabck_IP
["Lo_R1"][addr_type
].split("/")[0]
1565 result
= apply_raw_config(tgen
, raw_config
)
1566 assert result
is True, "Testcase {} : Failed Error : {}".format(tc_name
, result
)
1568 for addr_type
in ADDR_TYPES
:
1569 if addr_type
== "ipv6":
1573 "router bgp {}".format(
1574 topo
["routers"]["r3"]["bgp"]["local_as"]
1576 "address-family {} unicast".format(addr_type
),
1577 "neighbor {} activate".format(
1578 Loopabck_IP
["Lo_R1"][addr_type
].split("/")[0]
1587 "router bgp {}".format(
1588 topo
["routers"]["r3"]["bgp"]["local_as"]
1590 "address-family {} unicast".format(addr_type
),
1591 "no neighbor {} activate".format(
1592 Loopabck_IP
["Lo_R1"]["ipv6"].split("/")[0]
1597 result
= apply_raw_config(tgen
, raw_config
)
1598 assert result
is True, "Testcase {} : Failed Error : {}".format(tc_name
, result
)
1600 step("Verify that BGP neighborship between R1 and R3 comes up")
1601 result
= verify_bgp_convergence_from_running_config(tgen
)
1602 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1604 step("Remove ebgp-multihop command from R3")
1605 for addr_type
in ADDR_TYPES
:
1609 "router bgp {}".format(topo
["routers"]["r3"]["bgp"]["local_as"]),
1610 "no neighbor {} ebgp-multihop 3".format(
1611 Loopabck_IP
["Lo_R1"][addr_type
].split("/")[0]
1616 result
= apply_raw_config(tgen
, raw_config
)
1617 assert result
is True, "Testcase {} : Failed Error : {}".format(tc_name
, result
)
1619 step("Verify that once eBGP multi-hop is removed, BGP session goes down")
1620 result
= verify_bgp_convergence_from_running_config(tgen
, expected
=False)
1621 assert result
is not True, "Testcase {} : Failed \n Error : {}".format(
1625 step("Add ebgp-multihop command on R3 again")
1626 for addr_type
in ADDR_TYPES
:
1630 "router bgp {}".format(topo
["routers"]["r3"]["bgp"]["local_as"]),
1631 "neighbor {} ebgp-multihop 3".format(
1632 Loopabck_IP
["Lo_R1"][addr_type
].split("/")[0]
1637 result
= apply_raw_config(tgen
, raw_config
)
1638 assert result
is True, "Testcase {} : Failed Error : {}".format(tc_name
, result
)
1640 step("Verify that BGP neighborship between R1 and R3 comes up")
1641 result
= verify_bgp_convergence_from_running_config(tgen
)
1642 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1644 step("Remove update-source command from R1")
1645 for addr_type
in ADDR_TYPES
:
1649 "router bgp {}".format(topo
["routers"]["r1"]["bgp"]["local_as"]),
1650 "no neighbor {} update-source lo10".format(
1651 topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
1656 result
= apply_raw_config(tgen
, raw_config
)
1657 assert result
is True, "Testcase {} : Failed Error : {}".format(tc_name
, result
)
1659 step("Verify that BGP session goes down, when update-source is removed")
1660 result
= verify_bgp_convergence_from_running_config(tgen
, expected
=False)
1661 assert result
is not True, "Testcase {} : Failed \n Error : {}".format(
1665 step("Add update-source command on R1 again")
1666 for addr_type
in ADDR_TYPES
:
1670 "router bgp {}".format(topo
["routers"]["r1"]["bgp"]["local_as"]),
1671 "neighbor {} update-source lo10".format(
1672 topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
1677 result
= apply_raw_config(tgen
, raw_config
)
1678 assert result
is True, "Testcase {} : Failed Error : {}".format(tc_name
, result
)
1680 step("Verify that BGP neighborship between R1 and R3 comes up")
1681 result
= verify_bgp_convergence_from_running_config(tgen
)
1682 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1684 step("Remove static route from R3")
1685 for addr_type
in ADDR_TYPES
:
1690 "network": Loopabck_IP
["Lo_R1"][addr_type
],
1691 "next_hop": topo
["routers"]["r1"]["links"]["r3"][
1699 result
= create_static_routes(tgen
, input_dict_1
)
1700 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1703 result
= verify_rib(
1709 next_hop
=topo
["routers"]["r1"]["links"]["r3"][addr_type
].split("/")[0],
1712 assert result
is not True, "Testcase {} : Failed \n Error : {}".format(
1717 step("Verify that BGP session goes down, when static route is removed")
1718 result
= verify_bgp_convergence_from_running_config(tgen
, expected
=False)
1719 assert result
is not True, "Testcase {} : Failed \n Error : {}".format(
1723 step("Add static route on R3 again")
1724 for addr_type
in ADDR_TYPES
:
1729 "network": Loopabck_IP
["Lo_R1"][addr_type
],
1730 "next_hop": topo
["routers"]["r1"]["links"]["r3"][
1737 result
= create_static_routes(tgen
, input_dict_1
)
1738 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1741 result
= verify_rib(
1747 next_hop
=topo
["routers"]["r1"]["links"]["r3"][addr_type
].split("/")[0],
1749 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1753 step("Verify that BGP neighborship between R1 and R3 comes up")
1754 result
= verify_bgp_convergence_from_running_config(tgen
)
1755 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1757 step("Toggle physical interface on R1")
1758 intf_r1_r3
= topo
["routers"]["r1"]["links"]["r3"]["interface"]
1759 shutdown_bringup_interface(tgen
, "r1", intf_r1_r3
)
1761 step("Verify that BGP neighborship between R1 and R3 goes down")
1762 result
= verify_bgp_convergence_from_running_config(tgen
, expected
=False)
1763 assert result
is not True, "Testcase {} : Failed \n Error : {}".format(
1767 intf_r1_r3
= topo
["routers"]["r1"]["links"]["r3"]["interface"]
1768 shutdown_bringup_interface(tgen
, "r1", intf_r1_r3
, True)
1770 step("Verify that BGP neighborship between R1 and R3 comes up")
1771 result
= verify_bgp_convergence_from_running_config(tgen
)
1772 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1774 write_test_footer(tc_name
)
1777 def test_BGP_active_standby_preemption_and_ecmp_p1(request
):
1779 Verify that BGP Active/Standby/Pre-emption/ECMP.
1782 tc_name
= request
.node
.name
1783 write_test_header(tc_name
)
1784 tgen
= get_topogen()
1786 # Don"t run this test if we have any failure.
1787 if tgen
.routers_have_failure():
1788 pytest
.skip(tgen
.errors
)
1790 step("Initial config :Configure BGP neighborship between R1 and R3.")
1791 reset_config_on_routers(tgen
)
1793 step("Change the AS number on R2 as 200")
1794 input_dict
= {"r2": {"bgp": {"local_as": 200}}}
1795 result
= modify_as_number(tgen
, topo
, input_dict
)
1796 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1798 step("Verify BGP converge after changing the AS number on R2")
1799 result
= verify_bgp_convergence_from_running_config(tgen
)
1800 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1802 step("Advertise a set of prefixes from R1 to both peers R2 & R3")
1803 for addr_type
in ADDR_TYPES
:
1806 "static_routes": [{"network": NETWORK
[addr_type
], "next_hop": "null0"}]
1809 result
= create_static_routes(tgen
, input_dict_1
)
1810 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1818 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1819 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1825 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
1826 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1828 step("Verify that R4 receives BGP prefixes via both peer routers R2 & R3")
1829 for addr_type
in ADDR_TYPES
:
1830 input_dict_3
= {"r4": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
1831 result
= verify_bgp_rib(
1837 topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
1838 topo
["routers"]["r3"]["links"]["r4"][addr_type
].split("/")[0],
1841 assert result
is True, "Testcase : Failed \n Error : {}".format(
1846 "Configure a route-map to set as-path attribute and"
1847 "apply on R3 in an inbound direction:"
1856 "set": {"path": {"as_num": 123, "as_action": "prepend"}},
1862 result
= create_route_maps(tgen
, input_dict_4
)
1863 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1877 "name": "Path_Attribue",
1895 "name": "Path_Attribue",
1909 result
= create_router_bgp(tgen
, topo
, input_dict_5
)
1910 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1912 step("Verify on R4, BGP routes with shorter as-path are installed in FIB")
1913 for addr_type
in ADDR_TYPES
:
1916 input_dict_6
= {"r4": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
1917 result
= verify_rib(
1922 next_hop
=topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
1925 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1929 step("Shutdown BGP neighorship between R1-R2")
1931 intf_r4_r2
= topo
["routers"]["r4"]["links"]["r2"]["interface"]
1932 shutdown_bringup_interface(tgen
, dut
, intf_r4_r2
)
1935 "Verify that prefixes from next-hop via R2 are withdrawn"
1936 "and installed via next-hop as R3"
1938 result
= verify_rib(
1943 next_hop
=topo
["routers"]["r3"]["links"]["r4"][addr_type
].split("/")[0],
1946 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1948 step("Do a no shut for BGP neighorship between R2-R4")
1949 shutdown_bringup_interface(tgen
, dut
, intf_r4_r2
, ifaceaction
=True)
1952 "Verify that prefixes from next-hop via R3 are withdrawn"
1953 "from R4 and installed via next-hop as R2 (preemption)"
1955 result
= verify_rib(
1960 next_hop
=topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
1963 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1965 step("Remove the route-map from R3's neighbor statement")
1978 "name": "Path_Attribue",
1997 "name": "Path_Attribue",
2012 result
= create_router_bgp(tgen
, topo
, input_dict_5
)
2013 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2015 step("Configure multipath-relax and maximum-paths 2 on R4 for ECMP")
2020 "ipv4": {"unicast": {"maximum_paths": {"ebgp": 2}}},
2021 "ipv6": {"unicast": {"maximum_paths": {"ebgp": 2}}},
2026 result
= create_router_bgp(tgen
, topo
, input_dict_8
)
2027 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2030 "r4": {"bgp": {"local_as": "400", "bestpath": {"aspath": "multipath-relax"}}}
2033 result
= create_router_bgp(tgen
, topo
, maxpath_relax
)
2034 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2036 step("Verify FIB of R4, BGP prefixes with ECMP next-hop via R2 and R3")
2037 for addr_type
in ADDR_TYPES
:
2038 input_dict
= {"r4": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
2039 result
= verify_rib(
2045 topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
2046 topo
["routers"]["r3"]["links"]["r4"][addr_type
].split("/")[0],
2049 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
2053 step("Remove multipath-relax command from R4")
2055 del_maxpath_relax
= {
2059 "bestpath": {"aspath": "multipath-relax", "delete": True},
2064 result
= create_router_bgp(tgen
, topo
, del_maxpath_relax
)
2065 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2067 step("Verify that ECMP is no longer happening on R4.")
2068 for addr_type
in ADDR_TYPES
:
2069 input_dict
= {"r4": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
2070 result
= verify_rib(
2076 topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
2077 topo
["routers"]["r3"]["links"]["r4"][addr_type
].split("/")[0],
2081 assert result
is not True, "Testcase {} : Failed \n Error : {}".format(
2085 step("Reconfigure multipath-relax command on R4")
2086 result
= create_router_bgp(tgen
, topo
, maxpath_relax
)
2087 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2089 step("Verify FIB of R4, BGP prefixes with ECMP next-hop via R2 and R3")
2090 result
= verify_rib(
2096 topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
2097 topo
["routers"]["r3"]["links"]["r4"][addr_type
].split("/")[0],
2100 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2102 step("Remove maximum-path 2 command from R4")
2125 result
= create_router_bgp(tgen
, topo
, input_dict_8
)
2126 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2128 step("Verify that ECMP is no longer happening on R4")
2129 result
= verify_rib(
2135 topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
2136 topo
["routers"]["r3"]["links"]["r4"][addr_type
].split("/")[0],
2140 assert result
is not True, "Testcase {} : Failed \n Error : {}".format(
2144 step("Re-configure maximum-path 2 command on R4")
2167 result
= create_router_bgp(tgen
, topo
, input_dict_8
)
2168 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2170 step("Verify FIB of R4, BGP prefixes with ECMP next-hop via R2 and R3")
2171 result
= verify_rib(
2177 topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
2178 topo
["routers"]["r3"]["links"]["r4"][addr_type
].split("/")[0],
2181 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2183 write_test_footer(tc_name
)
2186 def test_password_authentication_for_eBGP_and_iBGP_peers_p1(request
):
2188 Verify password authentication for eBGP and iBGP peers.
2191 tc_name
= request
.node
.name
2192 write_test_header(tc_name
)
2193 tgen
= get_topogen()
2195 # Don"t run this test if we have any failure.
2196 if tgen
.routers_have_failure():
2197 pytest
.skip(tgen
.errors
)
2199 step("Initial config :Configure BGP neighborship between R1 and R3.")
2200 reset_config_on_routers(tgen
)
2203 "Add a static route on R1 for loopbacks IP's reachability of R2, R3"
2204 "and on R2 and R3 for loopback IP of R1"
2206 for addr_type
in ADDR_TYPES
:
2207 nh1
= topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
2208 nh2
= topo
["routers"]["r1"]["links"]["r2"][addr_type
].split("/")[0]
2209 nh3
= topo
["routers"]["r1"]["links"]["r3"][addr_type
].split("/")[0]
2210 nh4
= topo
["routers"]["r2"]["links"]["r1"][addr_type
].split("/")[0]
2215 "network": topo
["routers"]["r3"]["links"]["lo"][addr_type
],
2225 "network": topo
["routers"]["r1"]["links"]["lo"][addr_type
],
2235 "network": topo
["routers"]["r1"]["links"]["lo"][addr_type
],
2245 "network": topo
["routers"]["r2"]["links"]["lo"][addr_type
],
2251 dut_list
= ["r1", "r2", "r3", "r1"]
2252 nexthop_list
= [nh1
, nh2
, nh3
, nh4
]
2253 input_dict_list
= [input_dict_1
, input_dict_2
, input_dict_3
, input_dict_4
]
2254 for dut
, next_hop
, input_dict
in zip(dut_list
, nexthop_list
, input_dict_list
):
2255 result
= create_static_routes(tgen
, input_dict
)
2256 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
2260 step("Verify that static routes are installed in FIB of routers")
2261 result
= verify_rib(
2262 tgen
, addr_type
, dut
, input_dict
, next_hop
=next_hop
, protocol
="static"
2264 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
2268 step("Configure BGP sessions between R1-R2 and R1-R3 over loopback IPs")
2269 for routerN
in ["r1", "r3"]:
2270 for addr_type
in ADDR_TYPES
:
2273 elif routerN
== "r3":
2275 topo
["routers"][routerN
]["bgp"]["address_family"][addr_type
]["unicast"][
2277 ][bgp_neighbor
]["dest_link"] = {
2278 "lo": {"ebgp_multihop": 2, "source_link": "lo"}
2280 build_config_from_json(tgen
, topo
, save_bkup
=False)
2282 for routerN
in ["r1", "r2"]:
2283 for addr_type
in ADDR_TYPES
:
2286 elif routerN
== "r2":
2288 topo
["routers"][routerN
]["bgp"]["address_family"][addr_type
]["unicast"][
2290 ][bgp_neighbor
]["dest_link"] = {"lo": {"source_link": "lo"}}
2291 build_config_from_json(tgen
, topo
, save_bkup
=False)
2293 for routerN
in ["r1", "r2", "r3"]:
2294 for addr_type
in ADDR_TYPES
:
2295 for bgp_neighbor
in topo
["routers"][routerN
]["bgp"]["address_family"][
2297 ]["unicast"]["neighbor"].keys():
2298 if routerN
in ["r1", "r2", "r3"] and bgp_neighbor
== "r4":
2300 if addr_type
== "ipv4":
2301 topo
["routers"][routerN
]["bgp"]["address_family"][addr_type
][
2303 ]["neighbor"][bgp_neighbor
]["dest_link"] = {
2304 "lo": {"deactivate": "ipv6"}
2306 elif addr_type
== "ipv6":
2307 topo
["routers"][routerN
]["bgp"]["address_family"][addr_type
][
2309 ]["neighbor"][bgp_neighbor
]["dest_link"] = {
2310 "lo": {"deactivate": "ipv4"}
2312 build_config_from_json(tgen
, topo
, save_bkup
=False)
2314 result
= verify_bgp_convergence(tgen
, topo
)
2315 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2317 step("Configure authentication password on R1 for neighbor statements")
2318 for bgp_neighbor
in ["r2", "r3"]:
2319 for addr_type
in ADDR_TYPES
:
2320 topo
["routers"]["r1"]["bgp"]["address_family"][addr_type
]["unicast"][
2322 ][bgp_neighbor
]["dest_link"] = {"lo": {"password": "vmware"}}
2323 build_config_from_json(tgen
, topo
, save_bkup
=False)
2326 "Verify that both sessions go down as only R1 has password"
2327 "configured but not peer routers"
2329 result
= verify_bgp_convergence(tgen
, topo
, expected
=False)
2330 assert result
is not True, "Testcase {} : Failed \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)
2359 assert result
is not True, "Testcase {} : Failed \n Error : {}".format(
2363 step("Configure same password on R2 and R3 without CAPs")
2364 for routerN
in ["r2", "r3"]:
2365 for addr_type
in ADDR_TYPES
:
2366 topo
["routers"][routerN
]["bgp"]["address_family"][addr_type
]["unicast"][
2368 ]["r1"]["dest_link"] = {"lo": {"password": "vmware"}}
2369 build_config_from_json(tgen
, topo
, save_bkup
=False)
2371 step("Verify all BGP sessions come up again due to identical passwords")
2372 result
= verify_bgp_convergence(tgen
, topo
)
2373 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2375 step("Remove password from R1")
2376 for bgp_neighbor
in ["r2", "r3"]:
2377 for addr_type
in ADDR_TYPES
:
2378 topo
["routers"]["r1"]["bgp"]["address_family"][addr_type
]["unicast"][
2380 ][bgp_neighbor
]["dest_link"] = {"lo": {"no_password": "vmware"}}
2381 build_config_from_json(tgen
, topo
, save_bkup
=False)
2383 step("Verify if password is removed from R1, both sessions go down again")
2384 result
= verify_bgp_convergence(tgen
, topo
, expected
=False)
2385 assert result
is not True, "Testcase {} : Failed \n Error : {}".format(
2389 step("Configure alphanumeric password on R1 and peer routers R2,R3")
2390 for bgp_neighbor
in ["r2", "r3"]:
2391 for addr_type
in ADDR_TYPES
:
2392 topo
["routers"]["r1"]["bgp"]["address_family"][addr_type
]["unicast"][
2394 ][bgp_neighbor
]["dest_link"] = {"lo": {"password": "Vmware@123"}}
2395 build_config_from_json(tgen
, topo
, save_bkup
=False)
2397 for routerN
in ["r2", "r3"]:
2398 for addr_type
in ADDR_TYPES
:
2399 topo
["routers"][routerN
]["bgp"]["address_family"][addr_type
]["unicast"][
2401 ]["r1"]["dest_link"] = {"lo": {"password": "Vmware@123"}}
2402 build_config_from_json(tgen
, topo
, save_bkup
=False)
2405 "Verify that sessions Come up irrespective of characters"
2406 "used in password string"
2408 result
= verify_bgp_convergence(tgen
, topo
)
2409 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2411 write_test_footer(tc_name
)
2414 if __name__
== "__main__":
2415 args
= ["-s"] + sys
.argv
[1:]
2416 sys
.exit(pytest
.main(args
))