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
,
75 from lib
.topolog
import logger
77 verify_bgp_convergence
,
81 verify_bgp_convergence_from_running_config
,
83 verify_bgp_attributes
,
86 from lib
.topojson
import build_topo_from_json
, build_config_from_json
89 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.staticd
]
92 # Reading the data from JSON File for topology and configuration creation
93 jsonFile
= "{}/bgp_recursive_route_ebgp_multi_hop.json".format(CWD
)
95 with
open(jsonFile
, "r") as topoJson
:
96 topo
= json
.load(topoJson
)
98 logger
.info("Could not read file:", jsonFile
)
101 BGP_CONVERGENCE
= False
104 ADDR_TYPES
= check_address_types()
106 "ipv4": ["100.1.1.1/32", "100.1.1.2/32"],
107 "ipv6": ["100::1/128", "100::2/128"],
111 "N1": {"ipv4": "20.20.20.20/24", "ipv6": "20:20::20:20/120"},
112 "N2": {"ipv4": "30.30.30.30/24", "ipv6": "30:30::30:30/120"},
113 "N3": {"ipv4": "40.40.40.40/24", "ipv6": "40:40::40:40/120"},
117 "4thOctate": {"ipv4": "10.0.1.250/24", "ipv6": "fd00:0:0:1::100/64"},
118 "3rdOctate": {"ipv4": "10.0.10.2/24", "ipv6": "fd00:0:0:10::2/64"},
122 "Lo_R1": {"ipv4": "1.1.1.1/32", "ipv6": "1:1::1:1/128"},
123 "Lo_R4": {"ipv4": "4.4.4.4/32", "ipv6": "4:4::4:4/128"},
127 class CreateTopo(Topo
):
129 Test BasicTopo - topology 1
131 * `Topo`: Topology object
134 def build(self
, *_args
, **_opts
):
136 tgen
= get_topogen(self
)
138 # Building topology from json file
139 build_topo_from_json(tgen
, topo
)
142 def setup_module(mod
):
144 Sets up the pytest environment
149 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
150 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
151 logger
.info("=" * 40)
153 logger
.info("Running setup_module to create topology")
155 # This function initiates the topology build with Topogen...
156 tgen
= Topogen(CreateTopo
, mod
.__name
__)
157 # ... and here it calls Mininet initialization functions.
159 # Starting topology, create tmp files which are loaded to routers
160 # to start deamons and then start routers
163 # Creating configuration from JSON
164 build_config_from_json(tgen
, topo
)
166 global BGP_CONVERGENCE
167 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
168 assert BGP_CONVERGENCE
is True, "setup_module : Failed \n Error : {}".format(
172 logger
.info("Running setup_module() done")
175 def teardown_module():
176 """Teardown the pytest environment"""
178 logger
.info("Running teardown_module to delete topology")
182 # Stop toplogy and Remove tmp files
186 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
188 logger
.info("=" * 40)
191 #####################################################
195 #####################################################
198 def test_recursive_routes_iBGP_peer_p1(request
):
200 Verify that BGP routes are installed in iBGP peer, only
201 when there is a recursive route for next-hop reachability.
204 tc_name
= request
.node
.name
205 write_test_header(tc_name
)
208 # Don"t run this test if we have any failure.
209 if tgen
.routers_have_failure():
210 pytest
.skip(tgen
.errors
)
212 step("Initial config :Configure BGP neighborship between R1 and R3.")
213 reset_config_on_routers(tgen
)
219 "Configure static routes on R1 pointing next-hop as connected"
220 "link between R1 & R3's IP"
222 for addr_type
in ADDR_TYPES
:
227 "network": NETWORK
[addr_type
],
228 "next_hop": topo
["routers"]["r3"]["links"]["r1"][
235 result
= create_static_routes(tgen
, input_dict_4
)
238 "Verify on router R1 that these static routes are "
239 "installed in RIB+FIB of R1"
246 next_hop
=topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0],
249 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
253 step("Redistribute these static routes in BGP on router R1")
258 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
259 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
264 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
267 "Verify on router R1 that these static routes are installed"
268 "in RIB table as well"
270 for addr_type
in ADDR_TYPES
:
275 "network": NETWORK
[addr_type
],
276 "next_hop": topo
["routers"]["r3"]["links"]["r1"][
283 result
= verify_bgp_rib(
288 next_hop
=topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0],
290 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
295 "Configure a static routes for next hop IP on R2 via multiple"
296 "recursive static routes"
299 create_interface_in_kernel(
300 tgen
, dut
, "lo", "40.40.40.50", netmask
="255.255.255.0", create
=True
302 create_interface_in_kernel(
303 tgen
, dut
, "lo", "40:40::40:50", netmask
="120", create
=True
305 for addr_type
in ADDR_TYPES
:
310 "network": topo
["routers"]["r3"]["links"]["r1"][addr_type
],
311 "next_hop": RECUR_NEXT_HOP
["N1"][addr_type
].split("/")[0],
314 "network": RECUR_NEXT_HOP
["N1"][addr_type
],
315 "next_hop": RECUR_NEXT_HOP
["N2"][addr_type
].split("/")[0],
318 "network": RECUR_NEXT_HOP
["N2"][addr_type
],
319 "next_hop": RECUR_NEXT_HOP
["N3"][addr_type
].split("/")[0],
324 result
= create_static_routes(tgen
, input_dict_3
)
325 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
329 step("verify if redistributed routes are now installed in FIB of R2")
335 next_hop
=topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0],
338 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
342 step("Delete 1 route from static recursive for the next-hop IP")
344 for addr_type
in ADDR_TYPES
:
349 "network": RECUR_NEXT_HOP
["N1"][addr_type
],
350 "next_hop": RECUR_NEXT_HOP
["N2"][addr_type
].split("/")[0],
356 result
= create_static_routes(tgen
, input_dict_3
)
357 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
361 step("Verify that redistributed routes are withdrawn from FIB of R2")
367 next_hop
=topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0],
373 ), "Testcase {} : Failed \n " "Routes are still present \n Error: {}".format(
377 step("Reconfigure the same static route on R2 again")
379 for addr_type
in ADDR_TYPES
:
384 "network": RECUR_NEXT_HOP
["N1"][addr_type
],
385 "next_hop": RECUR_NEXT_HOP
["N2"][addr_type
].split("/")[0],
390 result
= create_static_routes(tgen
, input_dict_3
)
391 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
395 step("Verify that redistributed routes are again installed" "in FIB of R2")
401 next_hop
=topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0],
404 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
408 step("Configure static route with changed next-hop from same subnet")
409 for addr_type
in ADDR_TYPES
:
414 "network": NETWORK
[addr_type
],
415 "next_hop": topo
["routers"]["r3"]["links"]["r1"][
421 "network": NETWORK
[addr_type
],
422 "next_hop": CHANGED_NEXT_HOP
["4thOctate"][addr_type
].split("/")[
429 result
= create_static_routes(tgen
, input_dict_4
)
430 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
434 result
= verify_rib(tgen
, addr_type
, "r1", input_dict_4
, protocol
="static")
435 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
440 "Verify that redistributed routes are not withdrawn as changed"
441 "next-hop IP, belongs to the same subnet"
443 result
= verify_rib(tgen
, addr_type
, "r2", input_dict_4
, protocol
="bgp")
444 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
448 step("Configure static route with changed next-hop from different subnet")
450 create_interface_in_kernel(
451 tgen
, dut
, "lo10", "10.0.10.10", netmask
="255.255.255.0", create
=True
453 create_interface_in_kernel(
454 tgen
, dut
, "lo10", "fd00:0:0:10::104", netmask
="64", create
=True
456 for addr_type
in ADDR_TYPES
:
461 "network": NETWORK
[addr_type
],
462 "next_hop": CHANGED_NEXT_HOP
["4thOctate"][addr_type
].split("/")[
468 "network": NETWORK
[addr_type
],
469 "next_hop": CHANGED_NEXT_HOP
["3rdOctate"][addr_type
].split("/")[
476 result
= create_static_routes(tgen
, input_dict_4
)
477 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
481 result
= verify_rib(tgen
, addr_type
, "r1", input_dict_4
, protocol
="static")
482 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
487 "Verify that redistributed routes are withdrawn as changed "
488 "next-hop IP, belongs to different subnet"
491 tgen
, addr_type
, "r2", input_dict_4
, protocol
="bgp", expected
=False
495 ), "Testcase {} : Failed \n " "Routes are still present \n Error: {}".format(
499 write_test_footer(tc_name
)
502 def test_next_hop_as_self_ip_p1(request
):
504 Verify that any BGP prefix received with next hop as
505 self-ip is not installed in BGP RIB or FIB table.
508 tc_name
= request
.node
.name
509 write_test_header(tc_name
)
512 # Don"t run this test if we have any failure.
513 if tgen
.routers_have_failure():
514 pytest
.skip(tgen
.errors
)
516 step("Initial config :Configure BGP neighborship between R1 and R3.")
517 reset_config_on_routers(tgen
)
520 "Configure static routes on R1 with a next-hop IP belonging"
521 "to the same subnet of R2's link IP."
524 create_interface_in_kernel(
528 topo
["routers"]["r4"]["links"]["r2"]["ipv4"].split("/")[0],
529 netmask
="255.255.255.0",
532 create_interface_in_kernel(
536 topo
["routers"]["r4"]["links"]["r2"]["ipv6"].split("/")[0],
540 for addr_type
in ADDR_TYPES
:
545 "network": NETWORK
[addr_type
],
546 "next_hop": topo
["routers"]["r2"]["links"]["r4"][
553 result
= create_static_routes(tgen
, input_dict_4
)
555 step("Verify that static routes are installed in RIB and FIB of R1")
561 next_hop
=topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
564 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
568 step("Redistribute static routes into BGP on R1")
573 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
574 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
579 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
582 "Verify that R2 denies the prefixes received in update message,"
583 "as next-hop IP belongs to connected interface"
585 for addr_type
in ADDR_TYPES
:
590 "network": NETWORK
[addr_type
],
591 "next_hop": topo
["routers"]["r2"]["links"]["r4"][
598 result
= verify_bgp_rib(
603 next_hop
=topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
608 ), "Testcase {} : Failed \n " "Routes are still present \n Error: {}".format(
612 step("Shut interface on R2 that has IP from the subnet as BGP next-hop")
613 intf_r2_r4
= topo
["routers"]["r2"]["links"]["r4"]["interface"]
614 shutdown_bringup_interface(tgen
, "r2", intf_r2_r4
)
616 for addr_type
in ADDR_TYPES
:
617 clear_bgp(tgen
, addr_type
, "r2")
619 "Verify that redistributed routes now appear only in BGP table,"
620 "as next-hop IP is no more active on R2"
622 for addr_type
in ADDR_TYPES
:
627 "network": NETWORK
[addr_type
],
628 "next_hop": topo
["routers"]["r2"]["links"]["r4"][
635 result
= verify_bgp_rib(
640 next_hop
=topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
642 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
646 step("No shutdown interface on R2 which was shut in previous step")
647 intf_r2_r4
= topo
["routers"]["r2"]["links"]["r4"]["interface"]
648 shutdown_bringup_interface(tgen
, "r2", intf_r2_r4
, ifaceaction
=True)
651 "Verify that R2 dosn't install prefixes RIB to FIB as next-hop"
652 "interface is up now"
654 for addr_type
in ADDR_TYPES
:
659 "network": NETWORK
[addr_type
],
660 "next_hop": topo
["routers"]["r2"]["links"]["r4"][
667 result
= verify_bgp_rib(
672 next_hop
=topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
674 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
682 next_hop
=topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
687 ), "Testcase {} : Failed \n " "Routes are still present \n Error: {}".format(
691 write_test_footer(tc_name
)
694 def test_next_hop_with_recursive_lookup_p1(request
):
696 Verify that for a BGP prefix next-hop information doesn't change
697 when same prefix is received from another peer via recursive lookup.
700 tc_name
= request
.node
.name
701 write_test_header(tc_name
)
704 # Don"t run this test if we have any failure.
705 if tgen
.routers_have_failure():
706 pytest
.skip(tgen
.errors
)
708 step("Initial config :Configure BGP neighborship between R1 and R3.")
709 reset_config_on_routers(tgen
)
711 step("Verify that BGP peering comes up.")
713 result
= verify_bgp_convergence_from_running_config(tgen
)
714 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
716 step("Do redistribute connected on router R3.")
722 "unicast": {"redistribute": [{"redist_type": "connected"}]}
725 "unicast": {"redistribute": [{"redist_type": "connected"}]}
732 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
733 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
735 step("Verify that R1 receives all connected")
736 for addr_type
in ADDR_TYPES
:
738 "ipv4": ["1.0.3.17/32", "10.0.1.0/24", "10.0.3.0/24"],
739 "ipv6": ["2001:db8:f::3:17/128", "fd00:0:0:1::/64", "fd00:0:0:3::/64"],
741 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
742 result
= verify_rib(tgen
, addr_type
, "r1", input_dict
, protocol
="bgp")
743 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
748 "Configure a BGP neighborship between R1 and R4, directly via "
751 r1_local_as
= topo
["routers"]["r1"]["bgp"]["local_as"]
752 r1_r3_addr
= topo
["routers"]["r1"]["links"]["r3"]
753 r4_local_as
= topo
["routers"]["r4"]["bgp"]["local_as"]
754 r4_r3_addr
= topo
["routers"]["r4"]["links"]["r3"]
757 for addr_type
in ADDR_TYPES
:
761 "router bgp {}".format(r1_local_as
),
762 "neighbor {} remote-as {}".format(
763 r4_r3_addr
[addr_type
].split("/")[0], r4_local_as
765 "neighbor {} timers {} {}".format(
766 r4_r3_addr
[addr_type
].split("/")[0],
770 "neighbor {} ebgp-multihop {}".format(
771 r4_r3_addr
[addr_type
].split("/")[0], ebgp_multi_hop
777 "router bgp {}".format(r4_local_as
),
778 "neighbor {} remote-as {}".format(
779 r1_r3_addr
[addr_type
].split("/")[0], r1_local_as
781 "neighbor {} timers {} {}".format(
782 r1_r3_addr
[addr_type
].split("/")[0],
786 "neighbor {} ebgp-multihop {}".format(
787 r1_r3_addr
[addr_type
].split("/")[0], ebgp_multi_hop
792 result
= apply_raw_config(tgen
, raw_config
)
793 assert result
is True, "Testcase {} : Failed Error : {}".format(tc_name
, result
)
795 for addr_type
in ADDR_TYPES
:
796 if addr_type
== "ipv4":
800 "router bgp {}".format(r1_local_as
),
801 "address-family {} unicast".format(addr_type
),
802 "no neighbor {} activate".format(
803 r4_r3_addr
["ipv6"].split("/")[0]
809 "router bgp {}".format(r4_local_as
),
810 "address-family {} unicast".format(addr_type
),
811 "no neighbor {} activate".format(
812 r1_r3_addr
["ipv6"].split("/")[0]
821 "router bgp {}".format(r1_local_as
),
822 "address-family {} unicast".format(addr_type
),
823 "neighbor {} activate".format(
824 r4_r3_addr
[addr_type
].split("/")[0]
830 "router bgp {}".format(r4_local_as
),
831 "address-family {} unicast".format(addr_type
),
832 "neighbor {} activate".format(
833 r1_r3_addr
[addr_type
].split("/")[0]
838 result
= apply_raw_config(tgen
, raw_config
)
839 assert result
is True, "Testcase {} : Failed Error : {}".format(tc_name
, result
)
841 step("Verify that BGP session between R1 and R4 comes up" "(recursively via R3).")
842 result
= verify_bgp_convergence_from_running_config(tgen
)
843 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
845 step("Do redistribute connected on router R4.")
851 "unicast": {"redistribute": [{"redist_type": "connected"}]}
854 "unicast": {"redistribute": [{"redist_type": "connected"}]}
861 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
862 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
865 "Verify that R1 now receives BGP prefix of link r3-r4 via 2 "
866 "next-hops R3 and R4. however do not install with NHT R4 in FIB."
868 for addr_type
in ADDR_TYPES
:
869 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
871 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
872 next_hop
= topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
875 tgen
, addr_type
, "r1", input_dict
, protocol
="bgp", next_hop
=next_hop
877 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
881 step("Clear bgp sessions from R1 using 'clear ip bgp *'")
882 for addr_type
in ADDR_TYPES
:
883 clear_bgp(tgen
, addr_type
, "r1")
886 "Verify that prefix of link r3-r4 is again learned via 2 "
887 "next-hops (from R3 and R4 directly)"
889 for addr_type
in ADDR_TYPES
:
890 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
892 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
893 next_hop
= topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
896 tgen
, addr_type
, "r1", input_dict
, protocol
="bgp", next_hop
=next_hop
898 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
902 step("Remove redistribution from router R3.")
911 {"redist_type": "connected", "delete": True}
918 {"redist_type": "connected", "delete": True}
927 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
928 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
931 "Verify that peering between R1-R4 goes down and prefix "
932 "of link r3-r4, with NHT R4 is withdrawn."
935 logger
.info("Sleeping for holddowntimer: {}".format(HOLD_DOWN_TIMER
))
936 sleep(HOLD_DOWN_TIMER
+ 1)
938 result
= verify_bgp_convergence_from_running_config(tgen
, expected
=False)
941 ), "Testcase {} : Failed \n" "BGP is converged \n Error : {}".format(
944 logger
.info("Expected behaviour: {}".format(result
))
946 for addr_type
in ADDR_TYPES
:
947 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
949 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
950 next_hop
= topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
953 tgen
, addr_type
, "r1", input_dict
, protocol
="bgp", next_hop
=next_hop
955 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
959 step("Re-apply redistribution on R3.")
967 "unicast": {"redistribute": [{"redist_type": "connected"}]}
970 "unicast": {"redistribute": [{"redist_type": "connected"}]}
977 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
978 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
981 "Verify that peering between R1-R4 goes down and prefix "
982 "of link r3-r4 with NHT R4 is withdrawn."
985 result
= verify_bgp_convergence_from_running_config(tgen
)
986 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
988 for addr_type
in ADDR_TYPES
:
989 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
991 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
992 next_hop
= topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
995 tgen
, addr_type
, "r1", input_dict
, protocol
="bgp", next_hop
=next_hop
997 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1001 step("Remove redistribution from router R4.")
1011 {"redist_type": "connected", "delete": True}
1018 {"redist_type": "connected", "delete": True}
1027 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
1028 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1031 "Verify that peering between R1-R4 doesn't go down but prefix "
1032 "of link r3-r4 with NHT R4 is withdrawn."
1035 logger
.info("Sleeping for holddowntimer: {}".format(HOLD_DOWN_TIMER
))
1036 sleep(HOLD_DOWN_TIMER
+ 1)
1038 result
= verify_bgp_convergence_from_running_config(tgen
)
1039 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1041 for addr_type
in ADDR_TYPES
:
1042 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
1044 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
1045 next_hop
= topo
["routers"]["r4"]["links"]["r3"][addr_type
].split("/")[0]
1047 result
= verify_rib(
1058 ), "Testcase {} : Failed \n " "Route is still present \n Error : {}".format(
1062 step("Re-apply redistribution on R4.")
1072 {"redist_type": "connected", "delete": True}
1079 {"redist_type": "connected", "delete": True}
1088 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
1089 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1091 step("Verify that prefix of link r3-r4 is re-learned via NHT R4.")
1093 for addr_type
in ADDR_TYPES
:
1094 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
1096 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
1097 next_hop
= topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
1099 result
= verify_rib(
1100 tgen
, addr_type
, "r1", input_dict
, protocol
="bgp", next_hop
=next_hop
1102 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1106 step("Toggle the interface on R3(ifconfig 192.34).")
1108 intf_r3_r4
= topo
["routers"]["r3"]["links"]["r4"]["interface"]
1109 shutdown_bringup_interface(tgen
, "r3", intf_r3_r4
)
1112 "Verify that peering between R1-R4 goes down and comes up when "
1113 "interface is toggled. Also prefix of link r3-r4(via both NHTs) is"
1114 " withdrawn and re-learned accordingly."
1117 result
= verify_bgp_convergence_from_running_config(tgen
, expected
=False)
1120 ), "Testcase {} : Failed \n" "BGP is converged \n Error : {}".format(
1123 logger
.info("Expected behaviour: {}".format(result
))
1125 for addr_type
in ADDR_TYPES
:
1126 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
1128 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
1129 next_hop
= topo
["routers"]["r4"]["links"]["r3"][addr_type
].split("/")[0]
1131 result
= verify_rib(
1142 ), "Testcase {} : Failed \n " "Route is still present \n Error : {}".format(
1146 shutdown_bringup_interface(tgen
, "r3", intf_r3_r4
, True)
1148 result
= verify_bgp_convergence_from_running_config(tgen
)
1149 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1151 for addr_type
in ADDR_TYPES
:
1152 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
1154 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
1155 next_hop
= topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
1157 result
= verify_rib(
1158 tgen
, addr_type
, "r1", input_dict
, protocol
="bgp", next_hop
=next_hop
1160 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1164 step("Toggle the interface on R4(ifconfig 192.34).")
1166 intf_r4_r3
= topo
["routers"]["r4"]["links"]["r3"]["interface"]
1167 shutdown_bringup_interface(tgen
, "r4", intf_r4_r3
)
1170 "Verify that peering between R1-R4 goes down and comes up when"
1171 "interface is toggled. Also prefix of link r3-r4(via R4)"
1172 " is withdrawn and re-learned accordingly."
1175 result
= verify_bgp_convergence_from_running_config(tgen
, expected
=False)
1178 ), "Testcase {} : Failed \n" "BGP is converged \n Error : {}".format(
1181 logger
.info("Expected behaviour: {}".format(result
))
1183 for addr_type
in ADDR_TYPES
:
1184 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
1186 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
1187 next_hop
= topo
["routers"]["r4"]["links"]["r3"][addr_type
].split("/")[0]
1189 result
= verify_rib(
1200 ), "Testcase {} : Failed \n " "Route is still present \n Error : {}".format(
1204 shutdown_bringup_interface(tgen
, "r4", intf_r4_r3
, True)
1206 result
= verify_bgp_convergence_from_running_config(tgen
)
1207 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1209 for addr_type
in ADDR_TYPES
:
1210 routes
= {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
1212 input_dict
= {"r1": {"static_routes": [{"network": routes
[addr_type
]}]}}
1213 next_hop
= topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
1215 result
= verify_rib(
1216 tgen
, addr_type
, "r1", input_dict
, protocol
="bgp", next_hop
=next_hop
1218 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1222 write_test_footer(tc_name
)
1225 def test_BGP_path_attributes_default_values_p1(request
):
1227 Verify that BGP path attributes are present in CLI
1228 outputs and JSON format, even if set to default.
1231 tc_name
= request
.node
.name
1232 write_test_header(tc_name
)
1233 tgen
= get_topogen()
1235 # Don"t run this test if we have any failure.
1236 if tgen
.routers_have_failure():
1237 pytest
.skip(tgen
.errors
)
1239 step("Initial config: Configure BGP neighborship, between R1-R2 & R1-R3")
1240 reset_config_on_routers(tgen
)
1242 step("Advertise a set of prefixes from R1 to both peers R2 and R3")
1243 for addr_type
in ADDR_TYPES
:
1246 "static_routes": [{"network": NETWORK
[addr_type
], "next_hop": "null0"}]
1249 result
= create_static_routes(tgen
, input_dict_1
)
1255 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1256 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1261 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
1264 "Verify that advertised prefixes are received on R4 and well"
1265 "known attributes are present in the CLI and JSON outputs with"
1266 "default values without any route-map config."
1268 for addr_type
in ADDR_TYPES
:
1269 input_dict_3
= {"r4": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
1270 result
= verify_bgp_rib(
1276 topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
1277 topo
["routers"]["r3"]["links"]["r4"][addr_type
].split("/")[0],
1280 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
1284 for addr_type
in ADDR_TYPES
:
1288 "rmap_pf": [{"set": {"origin": "incomplete", "aspath": "300 100"}}]
1293 result
= verify_bgp_attributes(
1298 rmap_name
="rmap_pf",
1299 input_dict
=input_dict_4
,
1301 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
1306 "Configure a route-map to set below attribute value as 500"
1307 "and apply on R4 in an inbound direction"
1309 for addr_type
in ADDR_TYPES
:
1317 "path": {"as_num": 500, "as_action": "prepend"},
1326 result
= create_route_maps(tgen
, input_dict_4
)
1327 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1341 "name": "Path_Attribue",
1359 "name": "Path_Attribue",
1374 result
= create_router_bgp(tgen
, topo
, input_dict_5
)
1375 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1378 "Verify that once the route-map is applied all the attributes"
1379 "part of route-map, changes value to 500"
1381 for addr_type
in ADDR_TYPES
:
1389 "aspath": "500 300 100",
1397 result
= verify_bgp_attributes(
1402 rmap_name
="rmap_pf",
1403 input_dict
=input_dict_4
,
1405 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
1409 step("Remove the route-map from R4")
1422 "name": "Path_Attribue",
1441 "name": "Path_Attribue",
1457 result
= create_router_bgp(tgen
, topo
, input_dict_5
)
1458 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1461 "Verify on R4 that well known attributes are present in the CLI &"
1462 "JSON outputs again with default values without route-map config"
1464 for addr_type
in ADDR_TYPES
:
1468 "rmap_pf": [{"set": {"aspath": "300 100", "origin": "incomplete"}}]
1472 result
= verify_bgp_attributes(
1477 rmap_name
="rmap_pf",
1478 input_dict
=input_dict_4
,
1481 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
1485 write_test_footer(tc_name
)
1488 def test_BGP_peering_bw_loopback_and_physical_p1(request
):
1490 Verifying the BGP peering between loopback and
1491 physical link's IP of 2 peer routers.
1494 tc_name
= request
.node
.name
1495 write_test_header(tc_name
)
1496 tgen
= get_topogen()
1498 # Don"t run this test if we have any failure.
1499 if tgen
.routers_have_failure():
1500 pytest
.skip(tgen
.errors
)
1502 step("Initial config :Configure BGP neighborship between R1 and R3.")
1503 reset_config_on_routers(tgen
)
1505 step("Configure a loopback interface on R1")
1507 create_interface_in_kernel(
1508 tgen
, dut
, "lo10", "1.1.1.1", netmask
="255.255.255.255", create
=True
1510 create_interface_in_kernel(
1511 tgen
, dut
, "lo10", "1:1::1:1", netmask
="128", create
=True
1514 step("Configure BGP session between R1's loopbak & R3")
1515 for addr_type
in ADDR_TYPES
:
1520 "network": Loopabck_IP
["Lo_R1"][addr_type
],
1521 "next_hop": topo
["routers"]["r1"]["links"]["r3"][
1528 result
= create_static_routes(tgen
, input_dict_1
)
1529 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1532 result
= verify_rib(
1538 next_hop
=topo
["routers"]["r1"]["links"]["r3"][addr_type
].split("/")[0],
1540 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1544 for addr_type
in ADDR_TYPES
:
1548 "router bgp {}".format(topo
["routers"]["r1"]["bgp"]["local_as"]),
1549 "address-family {} unicast".format(addr_type
),
1550 "neighbor {} update-source lo10".format(
1551 topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
1553 "neighbor {} timers 1 3".format(
1554 topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
1560 "router bgp {}".format(topo
["routers"]["r3"]["bgp"]["local_as"]),
1561 "address-family {} unicast".format(addr_type
),
1562 "no neighbor {} remote-as {}".format(
1563 topo
["routers"]["r1"]["links"]["r3"][addr_type
].split("/")[0],
1564 topo
["routers"]["r1"]["bgp"]["local_as"],
1566 "neighbor {} remote-as {}".format(
1567 Loopabck_IP
["Lo_R1"][addr_type
].split("/")[0],
1568 topo
["routers"]["r1"]["bgp"]["local_as"],
1570 "neighbor {} ebgp-multihop 3".format(
1571 Loopabck_IP
["Lo_R1"][addr_type
].split("/")[0]
1576 result
= apply_raw_config(tgen
, raw_config
)
1577 assert result
is True, "Testcase {} : Failed Error : {}".format(tc_name
, result
)
1579 for addr_type
in ADDR_TYPES
:
1580 if addr_type
== "ipv6":
1584 "router bgp {}".format(
1585 topo
["routers"]["r3"]["bgp"]["local_as"]
1587 "address-family {} unicast".format(addr_type
),
1588 "neighbor {} activate".format(
1589 Loopabck_IP
["Lo_R1"][addr_type
].split("/")[0]
1598 "router bgp {}".format(
1599 topo
["routers"]["r3"]["bgp"]["local_as"]
1601 "address-family {} unicast".format(addr_type
),
1602 "no neighbor {} activate".format(
1603 Loopabck_IP
["Lo_R1"]["ipv6"].split("/")[0]
1608 result
= apply_raw_config(tgen
, raw_config
)
1609 assert result
is True, "Testcase {} : Failed Error : {}".format(tc_name
, result
)
1611 step("Verify that BGP neighborship between R1 and R3 comes up")
1612 result
= verify_bgp_convergence_from_running_config(tgen
)
1613 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1615 step("Remove ebgp-multihop command from R3")
1616 for addr_type
in ADDR_TYPES
:
1620 "router bgp {}".format(topo
["routers"]["r3"]["bgp"]["local_as"]),
1621 "no neighbor {} ebgp-multihop 3".format(
1622 Loopabck_IP
["Lo_R1"][addr_type
].split("/")[0]
1627 result
= apply_raw_config(tgen
, raw_config
)
1628 assert result
is True, "Testcase {} : Failed Error : {}".format(tc_name
, result
)
1630 step("Verify that once eBGP multi-hop is removed, BGP session goes down")
1631 result
= verify_bgp_convergence_from_running_config(tgen
, expected
=False)
1634 ), "Testcase {} : Failed \n " "BGP is converged \n Error: {}".format(
1638 step("Add ebgp-multihop command on R3 again")
1639 for addr_type
in ADDR_TYPES
:
1643 "router bgp {}".format(topo
["routers"]["r3"]["bgp"]["local_as"]),
1644 "neighbor {} ebgp-multihop 3".format(
1645 Loopabck_IP
["Lo_R1"][addr_type
].split("/")[0]
1650 result
= apply_raw_config(tgen
, raw_config
)
1651 assert result
is True, "Testcase {} : Failed Error : {}".format(tc_name
, result
)
1653 step("Verify that BGP neighborship between R1 and R3 comes up")
1654 result
= verify_bgp_convergence_from_running_config(tgen
)
1655 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1657 step("Remove update-source command from R1")
1658 for addr_type
in ADDR_TYPES
:
1662 "router bgp {}".format(topo
["routers"]["r1"]["bgp"]["local_as"]),
1663 "no neighbor {} update-source lo10".format(
1664 topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
1669 result
= apply_raw_config(tgen
, raw_config
)
1670 assert result
is True, "Testcase {} : Failed Error : {}".format(tc_name
, result
)
1672 step("Verify that BGP session goes down, when update-source is removed")
1673 result
= verify_bgp_convergence_from_running_config(tgen
, expected
=False)
1676 ), "Testcase {} : Failed \n " "BGP is converged \n Error: {}".format(
1680 step("Add update-source command on R1 again")
1681 for addr_type
in ADDR_TYPES
:
1685 "router bgp {}".format(topo
["routers"]["r1"]["bgp"]["local_as"]),
1686 "neighbor {} update-source lo10".format(
1687 topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
1692 result
= apply_raw_config(tgen
, raw_config
)
1693 assert result
is True, "Testcase {} : Failed Error : {}".format(tc_name
, result
)
1695 step("Verify that BGP neighborship between R1 and R3 comes up")
1696 result
= verify_bgp_convergence_from_running_config(tgen
)
1697 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1699 step("Remove static route from R3")
1700 for addr_type
in ADDR_TYPES
:
1705 "network": Loopabck_IP
["Lo_R1"][addr_type
],
1706 "next_hop": topo
["routers"]["r1"]["links"]["r3"][
1714 result
= create_static_routes(tgen
, input_dict_1
)
1715 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1718 result
= verify_rib(
1724 next_hop
=topo
["routers"]["r1"]["links"]["r3"][addr_type
].split("/")[0],
1729 ), "Testcase {} : Failed \n " "Routes are still present \n Error: {}".format(
1734 step("Verify that BGP session goes down, when static route is removed")
1735 result
= verify_bgp_convergence_from_running_config(tgen
, expected
=False)
1738 ), "Testcase {} : Failed \n " "BGP is converged \n Error: {}".format(
1742 step("Add static route on R3 again")
1743 for addr_type
in ADDR_TYPES
:
1748 "network": Loopabck_IP
["Lo_R1"][addr_type
],
1749 "next_hop": topo
["routers"]["r1"]["links"]["r3"][
1756 result
= create_static_routes(tgen
, input_dict_1
)
1757 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1760 result
= verify_rib(
1766 next_hop
=topo
["routers"]["r1"]["links"]["r3"][addr_type
].split("/")[0],
1768 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1772 step("Verify that BGP neighborship between R1 and R3 comes up")
1773 result
= verify_bgp_convergence_from_running_config(tgen
)
1774 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1776 step("Toggle physical interface on R1")
1777 intf_r1_r3
= topo
["routers"]["r1"]["links"]["r3"]["interface"]
1778 shutdown_bringup_interface(tgen
, "r1", intf_r1_r3
)
1780 step("Verify that BGP neighborship between R1 and R3 goes down")
1781 result
= verify_bgp_convergence_from_running_config(tgen
, expected
=False)
1784 ), "Testcase {} : Failed \n " "BGP is converged \n Error: {}".format(
1788 intf_r1_r3
= topo
["routers"]["r1"]["links"]["r3"]["interface"]
1789 shutdown_bringup_interface(tgen
, "r1", intf_r1_r3
, True)
1791 step("Verify that BGP neighborship between R1 and R3 comes up")
1792 result
= verify_bgp_convergence_from_running_config(tgen
)
1793 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1795 write_test_footer(tc_name
)
1798 def test_BGP_active_standby_preemption_and_ecmp_p1(request
):
1800 Verify that BGP Active/Standby/Pre-emption/ECMP.
1803 tc_name
= request
.node
.name
1804 write_test_header(tc_name
)
1805 tgen
= get_topogen()
1807 # Don"t run this test if we have any failure.
1808 if tgen
.routers_have_failure():
1809 pytest
.skip(tgen
.errors
)
1811 step("Initial config :Configure BGP neighborship between R1 and R3.")
1812 reset_config_on_routers(tgen
)
1814 step("Change the AS number on R2 as 200")
1815 input_dict
= {"r2": {"bgp": {"local_as": 200}}}
1816 result
= modify_as_number(tgen
, topo
, input_dict
)
1817 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1819 step("Verify BGP converge after changing the AS number on R2")
1820 result
= verify_bgp_convergence_from_running_config(tgen
)
1821 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1823 step("Advertise a set of prefixes from R1 to both peers R2 & R3")
1824 for addr_type
in ADDR_TYPES
:
1827 "static_routes": [{"network": NETWORK
[addr_type
], "next_hop": "null0"}]
1830 result
= create_static_routes(tgen
, input_dict_1
)
1831 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1839 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1840 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1846 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
1847 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1849 step("Verify that R4 receives BGP prefixes via both peer routers R2 & R3")
1850 for addr_type
in ADDR_TYPES
:
1851 input_dict_3
= {"r4": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
1852 result
= verify_bgp_rib(
1858 topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
1859 topo
["routers"]["r3"]["links"]["r4"][addr_type
].split("/")[0],
1862 assert result
is True, "Testcase {}: Failed \n Error : {}".format(
1867 "Configure a route-map to set as-path attribute and"
1868 "apply on R3 in an inbound direction:"
1877 "set": {"path": {"as_num": 123, "as_action": "prepend"}},
1883 result
= create_route_maps(tgen
, input_dict_4
)
1884 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1898 "name": "Path_Attribue",
1916 "name": "Path_Attribue",
1930 result
= create_router_bgp(tgen
, topo
, input_dict_5
)
1931 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1933 step("Verify on R4, BGP routes with shorter as-path are installed in FIB")
1934 for addr_type
in ADDR_TYPES
:
1937 input_dict_6
= {"r4": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
1938 result
= verify_rib(
1943 next_hop
=topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
1946 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
1950 step("Shutdown BGP neighorship between R1-R2")
1952 intf_r4_r2
= topo
["routers"]["r4"]["links"]["r2"]["interface"]
1953 shutdown_bringup_interface(tgen
, dut
, intf_r4_r2
)
1956 "Verify that prefixes from next-hop via R2 are withdrawn"
1957 "and installed via next-hop as R3"
1959 result
= verify_rib(
1964 next_hop
=topo
["routers"]["r3"]["links"]["r4"][addr_type
].split("/")[0],
1967 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1969 step("Do a no shut for BGP neighorship between R2-R4")
1970 shutdown_bringup_interface(tgen
, dut
, intf_r4_r2
, ifaceaction
=True)
1973 "Verify that prefixes from next-hop via R3 are withdrawn"
1974 "from R4 and installed via next-hop as R2 (preemption)"
1976 result
= verify_rib(
1981 next_hop
=topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
1984 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
1986 step("Remove the route-map from R3's neighbor statement")
1999 "name": "Path_Attribue",
2018 "name": "Path_Attribue",
2033 result
= create_router_bgp(tgen
, topo
, input_dict_5
)
2034 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2036 step("Configure multipath-relax and maximum-paths 2 on R4 for ECMP")
2041 "ipv4": {"unicast": {"maximum_paths": {"ebgp": 2}}},
2042 "ipv6": {"unicast": {"maximum_paths": {"ebgp": 2}}},
2047 result
= create_router_bgp(tgen
, topo
, input_dict_8
)
2048 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2051 "r4": {"bgp": {"local_as": "400", "bestpath": {"aspath": "multipath-relax"}}}
2054 result
= create_router_bgp(tgen
, topo
, maxpath_relax
)
2055 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2057 step("Verify FIB of R4, BGP prefixes with ECMP next-hop via R2 and R3")
2058 for addr_type
in ADDR_TYPES
:
2059 input_dict
= {"r4": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
2060 result
= verify_rib(
2066 topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
2067 topo
["routers"]["r3"]["links"]["r4"][addr_type
].split("/")[0],
2070 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
2074 step("Remove multipath-relax command from R4")
2076 del_maxpath_relax
= {
2080 "bestpath": {"aspath": "multipath-relax", "delete": True},
2085 result
= create_router_bgp(tgen
, topo
, del_maxpath_relax
)
2086 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2088 step("Verify that ECMP is no longer happening on R4.")
2089 for addr_type
in ADDR_TYPES
:
2090 input_dict
= {"r4": {"static_routes": [{"network": NETWORK
[addr_type
]}]}}
2091 result
= verify_rib(
2097 topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
2098 topo
["routers"]["r3"]["links"]["r4"][addr_type
].split("/")[0],
2104 ), "Testcase {} : Failed \n " "Routes are still present \n Error: {}".format(
2108 step("Reconfigure multipath-relax command on R4")
2109 result
= create_router_bgp(tgen
, topo
, maxpath_relax
)
2110 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2112 step("Verify FIB of R4, BGP prefixes with ECMP next-hop via R2 and R3")
2113 result
= verify_rib(
2119 topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
2120 topo
["routers"]["r3"]["links"]["r4"][addr_type
].split("/")[0],
2123 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2125 step("Remove maximum-path 2 command from R4")
2148 result
= create_router_bgp(tgen
, topo
, input_dict_8
)
2149 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2151 step("Verify that ECMP is no longer happening on R4")
2152 result
= verify_rib(
2158 topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
2159 topo
["routers"]["r3"]["links"]["r4"][addr_type
].split("/")[0],
2165 ), "Testcase {} : Failed \n " "Routes are still present \n Error: {}".format(
2169 step("Re-configure maximum-path 2 command on R4")
2192 result
= create_router_bgp(tgen
, topo
, input_dict_8
)
2193 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2195 step("Verify FIB of R4, BGP prefixes with ECMP next-hop via R2 and R3")
2196 result
= verify_rib(
2202 topo
["routers"]["r2"]["links"]["r4"][addr_type
].split("/")[0],
2203 topo
["routers"]["r3"]["links"]["r4"][addr_type
].split("/")[0],
2206 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2208 write_test_footer(tc_name
)
2211 def test_password_authentication_for_eBGP_and_iBGP_peers_p1(request
):
2213 Verify password authentication for eBGP and iBGP peers.
2216 tc_name
= request
.node
.name
2217 write_test_header(tc_name
)
2218 tgen
= get_topogen()
2220 # Don"t run this test if we have any failure.
2221 if tgen
.routers_have_failure():
2222 pytest
.skip(tgen
.errors
)
2224 step("Initial config :Configure BGP neighborship between R1 and R3.")
2225 reset_config_on_routers(tgen
)
2228 "Add a static route on R1 for loopbacks IP's reachability of R2, R3"
2229 "and on R2 and R3 for loopback IP of R1"
2231 for addr_type
in ADDR_TYPES
:
2232 nh1
= topo
["routers"]["r3"]["links"]["r1"][addr_type
].split("/")[0]
2233 nh2
= topo
["routers"]["r1"]["links"]["r2"][addr_type
].split("/")[0]
2234 nh3
= topo
["routers"]["r1"]["links"]["r3"][addr_type
].split("/")[0]
2235 nh4
= topo
["routers"]["r2"]["links"]["r1"][addr_type
].split("/")[0]
2240 "network": topo
["routers"]["r3"]["links"]["lo"][addr_type
],
2250 "network": topo
["routers"]["r1"]["links"]["lo"][addr_type
],
2260 "network": topo
["routers"]["r1"]["links"]["lo"][addr_type
],
2270 "network": topo
["routers"]["r2"]["links"]["lo"][addr_type
],
2276 dut_list
= ["r1", "r2", "r3", "r1"]
2277 nexthop_list
= [nh1
, nh2
, nh3
, nh4
]
2278 input_dict_list
= [input_dict_1
, input_dict_2
, input_dict_3
, input_dict_4
]
2279 for dut
, next_hop
, input_dict
in zip(dut_list
, nexthop_list
, input_dict_list
):
2280 result
= create_static_routes(tgen
, input_dict
)
2281 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
2285 step("Verify that static routes are installed in FIB of routers")
2286 result
= verify_rib(
2287 tgen
, addr_type
, dut
, input_dict
, next_hop
=next_hop
, protocol
="static"
2289 assert result
is True, "Testcase {} : Failed \n Error : {}".format(
2293 step("Configure BGP sessions between R1-R2 and R1-R3 over loopback IPs")
2294 for routerN
in ["r1", "r3"]:
2295 for addr_type
in ADDR_TYPES
:
2298 elif routerN
== "r3":
2300 topo
["routers"][routerN
]["bgp"]["address_family"][addr_type
]["unicast"][
2302 ][bgp_neighbor
]["dest_link"] = {
2303 "lo": {"ebgp_multihop": 2, "source_link": "lo"}
2305 build_config_from_json(tgen
, topo
, save_bkup
=False)
2307 for routerN
in ["r1", "r2"]:
2308 for addr_type
in ADDR_TYPES
:
2311 elif routerN
== "r2":
2313 topo
["routers"][routerN
]["bgp"]["address_family"][addr_type
]["unicast"][
2315 ][bgp_neighbor
]["dest_link"] = {"lo": {"source_link": "lo"}}
2316 build_config_from_json(tgen
, topo
, save_bkup
=False)
2318 for routerN
in ["r1", "r2", "r3"]:
2319 for addr_type
in ADDR_TYPES
:
2320 for bgp_neighbor
in topo
["routers"][routerN
]["bgp"]["address_family"][
2322 ]["unicast"]["neighbor"].keys():
2323 if routerN
in ["r1", "r2", "r3"] and bgp_neighbor
== "r4":
2325 if addr_type
== "ipv4":
2326 topo
["routers"][routerN
]["bgp"]["address_family"][addr_type
][
2328 ]["neighbor"][bgp_neighbor
]["dest_link"] = {
2329 "lo": {"deactivate": "ipv6"}
2331 elif addr_type
== "ipv6":
2332 topo
["routers"][routerN
]["bgp"]["address_family"][addr_type
][
2334 ]["neighbor"][bgp_neighbor
]["dest_link"] = {
2335 "lo": {"deactivate": "ipv4"}
2337 build_config_from_json(tgen
, topo
, save_bkup
=False)
2339 result
= verify_bgp_convergence(tgen
, topo
)
2340 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2342 step("Configure authentication password on R1 for neighbor statements")
2343 for bgp_neighbor
in ["r2", "r3"]:
2344 for addr_type
in ADDR_TYPES
:
2345 topo
["routers"]["r1"]["bgp"]["address_family"][addr_type
]["unicast"][
2347 ][bgp_neighbor
]["dest_link"] = {"lo": {"password": "vmware"}}
2348 build_config_from_json(tgen
, topo
, save_bkup
=False)
2351 "Verify that both sessions go down as only R1 has password"
2352 "configured but not peer routers"
2354 result
= verify_bgp_convergence(tgen
, topo
, expected
=False)
2357 ), "Testcase {} : Failed \n " "BGP is converged \n Error: {}".format(
2361 step("configure same password on R2 and R3")
2362 for routerN
in ["r2", "r3"]:
2363 for addr_type
in ADDR_TYPES
:
2364 topo
["routers"][routerN
]["bgp"]["address_family"][addr_type
]["unicast"][
2366 ]["r1"]["dest_link"] = {"lo": {"password": "vmware"}}
2367 build_config_from_json(tgen
, topo
, save_bkup
=False)
2369 step("Verify that all BGP sessions come up due to identical passwords")
2370 result
= verify_bgp_convergence(tgen
, topo
)
2371 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2373 step("Configure same password on R2 and R3, but in CAPs.")
2374 for routerN
in ["r2", "r3"]:
2375 for addr_type
in ADDR_TYPES
:
2376 topo
["routers"][routerN
]["bgp"]["address_family"][addr_type
]["unicast"][
2378 ]["r1"]["dest_link"] = {"lo": {"password": "VMWARE"}}
2379 build_config_from_json(tgen
, topo
, save_bkup
=False)
2382 "Verify that BGP sessions do not come up as password"
2383 "strings are in CAPs on R2 and R3"
2385 result
= verify_bgp_convergence(tgen
, topo
, expected
=False)
2388 ), "Testcase {} : Failed \n " "BGP is converged \n Error: {}".format(
2392 step("Configure same password on R2 and R3 without CAPs")
2393 for routerN
in ["r2", "r3"]:
2394 for addr_type
in ADDR_TYPES
:
2395 topo
["routers"][routerN
]["bgp"]["address_family"][addr_type
]["unicast"][
2397 ]["r1"]["dest_link"] = {"lo": {"password": "vmware"}}
2398 build_config_from_json(tgen
, topo
, save_bkup
=False)
2400 step("Verify all BGP sessions come up again due to identical passwords")
2401 result
= verify_bgp_convergence(tgen
, topo
)
2402 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2404 step("Remove password from R1")
2405 for bgp_neighbor
in ["r2", "r3"]:
2406 for addr_type
in ADDR_TYPES
:
2407 topo
["routers"]["r1"]["bgp"]["address_family"][addr_type
]["unicast"][
2409 ][bgp_neighbor
]["dest_link"] = {"lo": {"no_password": "vmware"}}
2410 build_config_from_json(tgen
, topo
, save_bkup
=False)
2412 step("Verify if password is removed from R1, both sessions go down again")
2413 result
= verify_bgp_convergence(tgen
, topo
, expected
=False)
2416 ), "Testcase {} : Failed \n " "BGP is converged \n Error: {}".format(
2420 step("Configure alphanumeric password on R1 and peer routers R2,R3")
2421 for bgp_neighbor
in ["r2", "r3"]:
2422 for addr_type
in ADDR_TYPES
:
2423 topo
["routers"]["r1"]["bgp"]["address_family"][addr_type
]["unicast"][
2425 ][bgp_neighbor
]["dest_link"] = {"lo": {"password": "Vmware@123"}}
2426 build_config_from_json(tgen
, topo
, save_bkup
=False)
2428 for routerN
in ["r2", "r3"]:
2429 for addr_type
in ADDR_TYPES
:
2430 topo
["routers"][routerN
]["bgp"]["address_family"][addr_type
]["unicast"][
2432 ]["r1"]["dest_link"] = {"lo": {"password": "Vmware@123"}}
2433 build_config_from_json(tgen
, topo
, save_bkup
=False)
2436 "Verify that sessions Come up irrespective of characters"
2437 "used in password string"
2439 result
= verify_bgp_convergence(tgen
, topo
)
2440 assert result
is True, "Testcase {} : Failed \n Error : {}".format(tc_name
, result
)
2442 write_test_footer(tc_name
)
2445 if __name__
== "__main__":
2446 args
= ["-s"] + sys
.argv
[1:]
2447 sys
.exit(pytest
.main(args
))