4 # Copyright (c) 2022 by VMware, Inc. ("VMware")
5 # Used Copyright (c) 2018 by Network Device Education Foundation,
6 # Inc. ("NetDEF") in this file.
8 # Permission to use, copy, modify, and/or distribute this software
9 # for any purpose with or without fee is hereby granted, provided
10 # that the above copyright notice and this permission notice appear
13 # THE SOFTWARE IS PROVIDED "AS IS" AND VMWARE DISCLAIMS ALL WARRANTIES
14 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL VMWARE BE LIABLE FOR
16 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
17 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
18 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
19 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
29 """Following tests are covered to test bgp admin distance functionality.
31 Verify bgp admin distance functionality when static route is configured
32 same as bgp learnt route in user vrf.
34 TC_6: Verify bgp admin distance functionality with ECMP in user vrf.
37 Verify bgp admin distance functionality when routes are
38 imported between VRFs.
41 #################################
43 #################################
54 | iBGP +-------+ eBGP +-------+
55 +---------- | R3 |----------| R4 |
67 # Save the Current Working Directory to find configuration files.
68 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
69 sys
.path
.append(os
.path
.join(CWD
, "../"))
70 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
72 # pylint: disable=C0413
73 # Import topogen and topotest helpers
74 from lib
.topogen
import Topogen
, get_topogen
76 # Required to instantiate the topology builder class.
77 from lib
.common_config
import (
85 reset_config_on_routers
,
88 from lib
.topolog
import logger
90 verify_bgp_convergence
,
92 verify_best_path_as_per_admin_distance
,
95 # pylint: disable=C0413
96 # Import topogen and topotest helpers
97 from lib
.topogen
import Topogen
, get_topogen
98 from lib
.topojson
import build_config_from_json
99 from lib
.topolog
import logger
103 bgp_convergence
= False
104 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.staticd
]
124 ADDR_TYPES
= check_address_types()
127 def setup_module(mod
):
129 Sets up the pytest environment
136 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
137 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
138 logger
.info("=" * 40)
140 logger
.info("Running setup_module to create topology")
142 # This function initiates the topology build with Topogen...
143 json_file
= "{}/bgp_admin_dist_vrf.json".format(CWD
)
144 tgen
= Topogen(json_file
, mod
.__name
__)
146 topo
= tgen
.json_topo
148 # Starting topology, create tmp files which are loaded to routers
149 # to start deamons and then start routers
152 # Creating configuration from JSON
153 build_config_from_json(tgen
, topo
)
155 # Checking BGP convergence
156 global bgp_convergence
159 # Don't run this test if we have any failure.
160 if tgen
.routers_have_failure():
161 pytest
.skip(tgen
.errors
)
163 # Api call verify whether BGP is converged
164 bgp_convergence
= verify_bgp_convergence(tgen
, topo
)
165 assert bgp_convergence
is True, "setup_module :Failed \n Error:" " {}".format(
168 logger
.info("Running setup_module() done")
171 def teardown_module(mod
):
174 Teardown the pytest environment.
177 logger
.info("Running teardown_module to delete topology")
180 # Stop toplogy and Remove tmp files
184 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
186 logger
.info("=" * 40)
189 #####################################################
191 #####################################################
194 def test_bgp_admin_distance_ebgp_vrf_p0():
197 Verify bgp admin distance functionality when static route is
198 configured same as ebgp learnt route
201 global bgp_convergence
203 if bgp_convergence
is not True:
204 pytest
.skip("skipping test case because of BGP Convergence failure at setup")
207 tc_name
= inspect
.stack()[0][3]
208 write_test_header(tc_name
)
209 if tgen
.routers_have_failure():
210 check_router_status(tgen
)
212 step("Configure base config as per the topology")
213 reset_config_on_routers(tgen
)
215 step("Configure bgp admin distance 200 with CLI in dut.")
226 "distance": {"ebgp": 200, "ibgp": 200, "local": 200}
231 "distance": {"ebgp": 200, "ibgp": 200, "local": 200}
240 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
241 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
243 step("Verify bgp routes have admin distance of 200 in dut.")
244 # Verifying best path
246 attribute
= "admin_distance"
253 "network": NETWORK
["ipv4"][0],
254 "admin_distance": 200,
258 "network": NETWORK
["ipv4"][1],
259 "admin_distance": 200,
269 "network": NETWORK
["ipv6"][0],
270 "admin_distance": 200,
274 "network": NETWORK
["ipv6"][1],
275 "admin_distance": 200,
283 for addr_type
in ADDR_TYPES
:
284 result
= verify_best_path_as_per_admin_distance(
285 tgen
, addr_type
, dut
, input_dict
[addr_type
], attribute
, vrf
="RED"
287 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
291 step("Modify the admin distance value to 150.")
301 "distance": {"ebgp": 150, "ibgp": 150, "local": 150}
306 "distance": {"ebgp": 150, "ibgp": 150, "local": 150}
315 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
316 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
318 step("Verify bgp routes have admin distance of 150 in dut.")
319 # Verifying best path
321 attribute
= "admin_distance"
328 "network": NETWORK
["ipv4"][0],
329 "admin_distance": 150,
333 "network": NETWORK
["ipv4"][1],
334 "admin_distance": 150,
344 "network": NETWORK
["ipv6"][0],
345 "admin_distance": 150,
349 "network": NETWORK
["ipv6"][1],
350 "admin_distance": 150,
358 for addr_type
in ADDR_TYPES
:
359 result
= verify_best_path_as_per_admin_distance(
360 tgen
, addr_type
, dut
, input_dict
[addr_type
], attribute
, vrf
="RED"
362 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
366 step("Un configure the admin distance value on DUT")
400 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
401 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
403 step("Verify bgp routes have default admin distance in dut.")
404 # Verifying best path
406 attribute
= "admin_distance"
412 {"network": NETWORK
["ipv4"][0], "admin_distance": 20, "vrf": "RED"},
413 {"network": NETWORK
["ipv4"][1], "admin_distance": 20, "vrf": "RED"},
420 {"network": NETWORK
["ipv6"][0], "admin_distance": 20, "vrf": "RED"},
421 {"network": NETWORK
["ipv6"][1], "admin_distance": 20, "vrf": "RED"},
427 for addr_type
in ADDR_TYPES
:
428 result
= verify_best_path_as_per_admin_distance(
429 tgen
, addr_type
, dut
, input_dict
[addr_type
], attribute
, vrf
="RED"
431 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
435 step("Configure static route Without any admin distance")
437 for addr_type
in ADDR_TYPES
:
438 # Create Static routes
442 {"network": NETWORK
[addr_type
], "next_hop": "Null0", "vrf": "RED"}
447 result
= create_static_routes(tgen
, input_dict
)
448 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
452 step("Verify that zebra selects static route.")
455 for addr_type
in ADDR_TYPES
:
459 {"network": NETWORK
[addr_type
], "next_hop": "Null0", "vrf": "RED"}
463 result4
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
464 assert result4
is True, "Testcase {} : Failed \n Error: {}".format(
468 step("Configure static route with admin distance of 253")
469 for addr_type
in ADDR_TYPES
:
470 # Create Static routes
475 "network": NETWORK
[addr_type
],
477 "admin_distance": 253,
484 result
= create_static_routes(tgen
, input_dict
)
485 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
489 step("Verify that zebra selects bgp route.")
492 for addr_type
in ADDR_TYPES
:
497 "network": NETWORK
[addr_type
],
499 "admin_distance": 253,
505 result4
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
506 assert result4
is True, "Testcase {} : Failed \n Error: {}".format(
510 step("Configure admin distance of 254 in bgp for route .")
520 "distance": {"ebgp": 254, "ibgp": 254, "local": 254}
525 "distance": {"ebgp": 254, "ibgp": 254, "local": 254}
534 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
535 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
537 step("Verify that zebra selects static route.")
540 for addr_type
in ADDR_TYPES
:
545 "network": NETWORK
[addr_type
],
547 "admin_distance": 253,
554 result4
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
555 assert result4
is True, "Testcase {} : Failed \n Error: {}".format(
559 step("Configure admin distance of 255 in bgp for route in vrf red")
569 "distance": {"ebgp": 255, "ibgp": 255, "local": 255}
574 "distance": {"ebgp": 255, "ibgp": 255, "local": 255}
583 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
584 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
586 step("Verify that zebra selects static route.")
589 for addr_type
in ADDR_TYPES
:
594 "network": NETWORK
[addr_type
],
596 "admin_distance": 253,
603 result4
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
604 assert result4
is True, "Testcase {} : Failed \n Error: {}".format(
608 step("Delete the static route.")
609 for addr_type
in ADDR_TYPES
:
610 # Create Static routes
615 "network": NETWORK
[addr_type
],
617 "admin_distance": 253,
625 result
= create_static_routes(tgen
, input_dict
)
626 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
630 step("Verify that zebra selects bgp route.")
633 for addr_type
in ADDR_TYPES
:
634 result4
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
635 assert result4
is True, "Testcase {} : Failed \n Error: {}".format(
639 write_test_footer(tc_name
)
642 def test_bgp_admin_distance_ebgp_with_imported_rtes_vrf_p0():
645 Verify bgp admin distance functionality when static route is configured
646 same as bgp learnt route in user vrf.
649 global bgp_convergence
651 if bgp_convergence
is not True:
652 pytest
.skip("skipping test case because of BGP Convergence failure at setup")
655 tc_name
= inspect
.stack()[0][3]
656 write_test_header(tc_name
)
657 if tgen
.routers_have_failure():
658 check_router_status(tgen
)
660 step("Configure base config as per the topology")
661 reset_config_on_routers(tgen
)
662 step("Configure bgp admin distance 200 with CLI in dut.")
663 step(" Import route from vrf to default vrf")
673 "distance": {"ebgp": 200, "ibgp": 200, "local": 200}
678 "distance": {"ebgp": 200, "ibgp": 200, "local": 200}
688 "distance": {"ebgp": 200, "ibgp": 200, "local": 200},
689 "import": {"vrf": "RED"},
694 "distance": {"ebgp": 200, "ibgp": 200, "local": 200},
706 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
707 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
709 step("Verify bgp routes have admin distance of 200 in dut.")
710 # Verifying best path
712 attribute
= "admin_distance"
719 "network": NETWORK
["ipv4"][0],
720 "admin_distance": 200,
724 "network": NETWORK
["ipv4"][1],
725 "admin_distance": 200,
735 "network": NETWORK
["ipv6"][0],
736 "admin_distance": 200,
740 "network": NETWORK
["ipv6"][1],
741 "admin_distance": 200,
749 for addr_type
in ADDR_TYPES
:
750 result
= verify_best_path_as_per_admin_distance(
751 tgen
, addr_type
, dut
, input_dict
[addr_type
], attribute
, vrf
="RED"
753 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
758 "Verify that routes are getting imported without any issues and "
759 "routes are calculated and installed in rib."
767 "network": NETWORK
["ipv4"][0],
768 "admin_distance": 200,
771 "network": NETWORK
["ipv4"][1],
772 "admin_distance": 200,
781 "network": NETWORK
["ipv6"][0],
782 "admin_distance": 200,
785 "network": NETWORK
["ipv6"][1],
786 "admin_distance": 200,
793 step("Verify that zebra selects bgp route.")
796 for addr_type
in ADDR_TYPES
:
797 result4
= verify_rib(tgen
, addr_type
, dut
, input_dict
, protocol
=protocol
)
798 assert result4
is True, "Testcase {} : Failed \n Error: {}".format(
802 step(" Un configure import route vrf red inside default vrf.")
812 "distance": {"ebgp": 200, "ibgp": 200, "local": 200}
817 "distance": {"ebgp": 200, "ibgp": 200, "local": 200}
827 "distance": {"ebgp": 200, "ibgp": 200, "local": 200},
828 "import": {"vrf": "RED", "delete": True},
833 "distance": {"ebgp": 200, "ibgp": 200, "local": 200},
834 "import": {"vrf": "RED", "delete": True},
843 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
844 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
851 "network": NETWORK
["ipv4"][0],
852 "admin_distance": 200,
855 "network": NETWORK
["ipv4"][1],
856 "admin_distance": 200,
865 "network": NETWORK
["ipv6"][0],
866 "admin_distance": 200,
869 "network": NETWORK
["ipv6"][1],
870 "admin_distance": 200,
877 step("Verify that route withdrawal happens properly.")
880 for addr_type
in ADDR_TYPES
:
881 result4
= verify_rib(
885 input_dict
[addr_type
],
891 ), "Testcase {} : Failed \n Route is not withdrawn. Error: {}".format(
895 write_test_footer(tc_name
)
898 if __name__
== "__main__":
899 args
= ["-s"] + sys
.argv
[1:]
900 sys
.exit(pytest
.main(args
))