4 # Copyright (c) 2019 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
24 Following tests are covered to test BGP basic functionality:
27 - Create topology (setup module)
28 Creating 4 routers topology, r1, r2, r3 are in IBGP and
31 - Verify for bgp to converge
32 - Modify/Delete and verify router-id
33 - Modify and verify bgp timers
34 - Create and verify static routes
35 - Modify and verify admin distance for existing static routes
36 - Test advertise network using network command
38 - Test bgp convergence with loopback interface
39 - Test advertise network using network command
40 - Verify routes not installed in zebra when /32 routes received
41 with loopback BGP session subnet
43 # XXX clean up in later commit to avoid conflict on rebase
44 # pylint: disable=C0413
50 from copy
import deepcopy
52 # Save the Current Working Directory to find configuration files.
53 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
54 sys
.path
.append(os
.path
.join(CWD
, "../"))
55 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
57 # Required to instantiate the topology builder class.
64 verify_bgp_convergence
,
66 verify_bgp_timers_and_functionality
,
69 from lib
.common_config
import (
76 required_linux_kernel_version
,
77 reset_config_on_routers
,
80 verify_admin_distance_for_static_routes
,
88 # pylint: disable=C0413
89 # Import topogen and topotest helpers
90 from lib
.topogen
import Topogen
, get_topogen
91 from lib
.topojson
import build_config_from_json
92 from lib
.topolog
import logger
94 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.staticd
]
100 r1_ipv4_loopback
= "1.0.1.0/24"
101 r2_ipv4_loopback
= "1.0.2.0/24"
102 r3_ipv4_loopback
= "1.0.3.0/24"
103 r4_ipv4_loopback
= "1.0.4.0/24"
104 r1_ipv6_loopback
= "2001:db8:f::1:0/120"
105 r2_ipv6_loopback
= "2001:db8:f::2:0/120"
106 r3_ipv6_loopback
= "2001:db8:f::3:0/120"
107 r4_ipv6_loopback
= "2001:db8:f::4:0/120"
109 "ipv4": ["100.1.1.1/32", "100.1.1.2/32"],
110 "ipv6": ["100::1/128", "100::2/128"],
114 def setup_module(mod
):
116 Sets up the pytest environment
121 # Required linux kernel version for this suite to run.
122 result
= required_linux_kernel_version("4.15")
123 if result
is not True:
124 pytest
.skip("Kernel requirements are not met, kernel version should be >=4.15")
126 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
127 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
128 logger
.info("=" * 40)
130 logger
.info("Running setup_module to create topology")
132 # This function initiates the topology build with Topogen...
133 json_file
= "{}/bgp_basic_functionality.json".format(CWD
)
134 tgen
= Topogen(json_file
, mod
.__name
__)
136 topo
= tgen
.json_topo
137 # ... and here it calls Mininet initialization functions.
139 # Starting topology, create tmp files which are loaded to routers
140 # to start daemons and then start routers
143 # Creating configuration from JSON
144 build_config_from_json(tgen
, topo
)
147 global BGP_CONVERGENCE
148 ADDR_TYPES
= check_address_types()
149 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
150 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
154 logger
.info("Running setup_module() done")
157 def teardown_module():
158 """Teardown the pytest environment"""
160 logger
.info("Running teardown_module to delete topology")
164 # Stop toplogy and Remove tmp files
168 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
170 logger
.info("=" * 40)
173 #####################################################
177 #####################################################
180 def test_modify_and_delete_router_id(request
):
181 """Test to modify, delete and verify router-id."""
184 if BGP_CONVERGENCE
is not True:
185 pytest
.skip("skipped because of BGP Convergence failure")
188 tc_name
= request
.node
.name
189 write_test_header(tc_name
)
191 # Creating configuration from JSON
192 reset_config_on_routers(tgen
)
196 "r1": {"bgp": {"router_id": "12.12.12.12"}},
197 "r2": {"bgp": {"router_id": "22.22.22.22"}},
198 "r3": {"bgp": {"router_id": "33.33.33.33"}},
200 result
= create_router_bgp(tgen
, topo
, input_dict
)
201 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
203 # Verifying router id once modified
204 result
= verify_router_id(tgen
, topo
, input_dict
)
205 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
209 "r1": {"bgp": {"del_router_id": True}},
210 "r2": {"bgp": {"del_router_id": True}},
211 "r3": {"bgp": {"del_router_id": True}},
213 result
= create_router_bgp(tgen
, topo
, input_dict
)
214 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
216 # Verifying router id once deleted
217 # Once router-id is deleted, highest interface ip should become
219 result
= verify_router_id(tgen
, topo
, input_dict
)
220 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
222 write_test_footer(tc_name
)
225 def test_bgp_config_with_4byte_as_number(request
):
227 Configure BGP with 4 byte ASN and verify it works fine
231 if BGP_CONVERGENCE
is not True:
232 pytest
.skip("skipped because of BGP Convergence failure")
235 tc_name
= request
.node
.name
236 write_test_header(tc_name
)
238 # Creating configuration from JSON
239 reset_config_on_routers(tgen
)
242 "r1": {"bgp": {"local_as": 131079}},
243 "r2": {"bgp": {"local_as": 131079}},
244 "r3": {"bgp": {"local_as": 131079}},
245 "r4": {"bgp": {"local_as": 131080}},
247 result
= modify_as_number(tgen
, topo
, input_dict
)
248 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
250 result
= verify_as_numbers(tgen
, topo
, input_dict
)
251 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
253 write_test_footer(tc_name
)
256 def test_BGP_config_with_invalid_ASN_p2(request
):
258 Configure BGP with invalid ASN(ex - 0, reserved ASN) and verify test case
263 global BGP_CONVERGENCE
265 if BGP_CONVERGENCE
!= True:
266 pytest
.skip("skipped because of BGP Convergence failure")
269 tc_name
= request
.node
.name
270 write_test_header(tc_name
)
272 # Creating configuration from JSON
273 reset_config_on_routers(tgen
)
275 # Api call to modify AS number
298 result
= modify_as_number(tgen
, topo
, input_dict
)
301 ), "Expected BGP config is not created because of invalid ASNs: {}".format(result
)
303 # Creating configuration from JSON
304 reset_config_on_routers(tgen
)
306 result
= verify_bgp_convergence(tgen
, topo
)
308 assert False, "Testcase " + tc_name
+ " :Failed \n Error: {}".format(result
)
310 write_test_footer(tc_name
)
313 def test_BGP_config_with_2byteAS_and_4byteAS_number_p1(request
):
315 Configure BGP with 4 byte and 2 byte ASN and verify BGP is converged
319 global BGP_CONVERGENCE
321 if BGP_CONVERGENCE
!= True:
322 pytest
.skip("skipped because of BGP Convergence failure")
325 tc_name
= request
.node
.name
326 write_test_header(tc_name
)
328 # Creating configuration from JSON
329 reset_config_on_routers(tgen
)
331 result
= verify_bgp_convergence(tgen
, topo
)
333 assert False, "Testcase " + tc_name
+ " :Failed \n Error: {}".format(result
)
335 # Api call to modify AS number
337 "r1": {"bgp": {"local_as": 131079}},
338 "r2": {"bgp": {"local_as": 131079}},
339 "r3": {"bgp": {"local_as": 131079}},
340 "r4": {"bgp": {"local_as": 111}},
342 result
= modify_as_number(tgen
, topo
, input_dict
)
344 assert False, "Testcase " + tc_name
+ " :Failed \n Error: {}".format(result
)
346 result
= verify_as_numbers(tgen
, topo
, input_dict
)
348 assert False, "Testcase " + tc_name
+ " :Failed \n Error: {}".format(result
)
350 # Api call verify whether BGP is converged
351 result
= verify_bgp_convergence(tgen
, topo
)
353 assert False, "Testcase " + tc_name
+ " :Failed \n Error: {}".format(result
)
355 write_test_footer(tc_name
)
358 def test_bgp_timers_functionality(request
):
360 Test to modify bgp timers and verify timers functionality.
364 if BGP_CONVERGENCE
is not True:
365 pytest
.skip("skipped because of BGP Convergence failure")
368 tc_name
= request
.node
.name
369 write_test_header(tc_name
)
371 # Creating configuration from JSON
372 reset_config_on_routers(tgen
)
374 # Api call to modify BGP timerse
385 "keepalivetimer": KEEPALIVETIMER
,
386 "holddowntimer": HOLDDOWNTIMER
,
397 result
= create_router_bgp(tgen
, topo
, deepcopy(input_dict
))
398 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
400 # Api call to clear bgp, so timer modification would take place
401 clear_bgp_and_verify(tgen
, topo
, "r1")
403 # Verifying bgp timers functionality
404 result
= verify_bgp_timers_and_functionality(tgen
, topo
, input_dict
)
405 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
407 write_test_footer(tc_name
)
410 def test_static_routes(request
):
411 """Test to create and verify static routes."""
414 if BGP_CONVERGENCE
is not True:
415 pytest
.skip("skipped because of BGP Convergence failure")
418 tc_name
= request
.node
.name
419 write_test_header(tc_name
)
421 # Creating configuration from JSON
422 reset_config_on_routers(tgen
)
424 # Api call to create static routes
429 "network": "10.0.20.1/32",
431 "admin_distance": 100,
432 "next_hop": "10.0.0.2",
437 result
= create_static_routes(tgen
, input_dict
)
438 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
440 # Api call to redistribute static routes
448 {"redist_type": "static"},
449 {"redist_type": "connected"},
458 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
459 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
461 # Verifying RIB routes
464 next_hop
= ["10.0.0.2", "10.0.0.5"]
466 tgen
, "ipv4", dut
, input_dict
, next_hop
=next_hop
, protocol
=protocol
468 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
470 write_test_footer(tc_name
)
473 def test_admin_distance_for_existing_static_routes(request
):
474 """Test to modify and verify admin distance for existing static routes."""
477 if BGP_CONVERGENCE
is not True:
478 pytest
.skip("skipped because of BGP Convergence failure")
481 tc_name
= request
.node
.name
482 write_test_header(tc_name
)
484 # Creating configuration from JSON
485 reset_config_on_routers(tgen
)
491 "network": "10.0.20.1/32",
492 "admin_distance": 10,
493 "next_hop": "10.0.0.2",
498 result
= create_static_routes(tgen
, input_dict
)
499 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
501 # Verifying admin distance once modified
502 result
= verify_admin_distance_for_static_routes(tgen
, input_dict
)
503 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
505 write_test_footer(tc_name
)
508 def test_advertise_network_using_network_command(request
):
509 """Test advertise networks using network command."""
512 if BGP_CONVERGENCE
is not True:
513 pytest
.skip("skipped because of BGP Convergence failure")
516 tc_name
= request
.node
.name
517 write_test_header(tc_name
)
519 # Creating configuration from JSON
520 reset_config_on_routers(tgen
)
522 # Api call to advertise networks
529 "advertise_networks": [
530 {"network": "20.0.0.0/32", "no_of_network": 10},
531 {"network": "30.0.0.0/32", "no_of_network": 10},
540 result
= create_router_bgp(tgen
, topo
, input_dict
)
541 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
543 # Verifying RIB routes
546 result
= verify_rib(tgen
, "ipv4", dut
, input_dict
, protocol
=protocol
)
547 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
549 write_test_footer(tc_name
)
552 def test_clear_bgp_and_verify(request
):
554 Created few static routes and verified all routes are learned via BGP
555 cleared BGP and verified all routes are intact
559 if BGP_CONVERGENCE
is not True:
560 pytest
.skip("skipped because of BGP Convergence failure")
563 tc_name
= request
.node
.name
564 write_test_header(tc_name
)
566 # Creating configuration from JSON
567 reset_config_on_routers(tgen
)
570 result
= clear_bgp_and_verify(tgen
, topo
, "r1")
571 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
573 write_test_footer(tc_name
)
576 def test_BGP_attributes_with_vrf_default_keyword_p0(request
):
579 Verify BGP functionality for default vrf with
580 "vrf default" keyword.
583 tc_name
= request
.node
.name
584 write_test_header(tc_name
)
587 if tgen
.routers_have_failure():
588 pytest
.skip(tgen
.errors
)
590 # Creating configuration from JSON
591 reset_config_on_routers(tgen
)
593 step("Configure static routes and redistribute in BGP on R3")
594 for addr_type
in ADDR_TYPES
:
599 "network": NETWORK
[addr_type
][0],
607 result
= create_static_routes(tgen
, input_dict
)
608 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
616 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
617 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
622 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
623 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
626 "Create a route-map to match a specific prefix and modify"
627 "BGP attributes for matched prefix"
637 "network": NETWORK
["ipv4"][0],
646 "network": NETWORK
["ipv6"][0],
653 result
= create_prefix_lists(tgen
, input_dict_2
)
654 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
656 for addr_type
in ADDR_TYPES
:
657 if addr_type
== "ipv4":
665 "BGP_ATTR_{}".format(addr_type
): [
669 "match": {addr_type
: {"prefix_lists": pf_list
}},
671 "aspath": {"as_num": 500, "as_action": "prepend"},
674 "community": {"num": "500:500", "action": "additive"},
676 "num": "500:500:500",
677 "action": "additive",
681 {"action": "permit", "seq_id": 20},
684 "BGP_ATTR_{}".format(addr_type
): [
688 "match": {addr_type
: {"prefix_lists": pf_list
}},
690 "aspath": {"as_num": 500, "as_action": "prepend"},
693 "community": {"num": "500:500", "action": "additive"},
695 "num": "500:500:500",
696 "action": "additive",
700 {"action": "permit", "seq_id": 200},
705 result
= create_route_maps(tgen
, input_dict_6
)
706 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
710 step("Apply the route-map on R3 in outbound direction for peer R4")
724 "name": "BGP_ATTR_ipv4",
742 "name": "BGP_ATTR_ipv6",
757 result
= create_router_bgp(tgen
, topo
, input_dict_7
)
758 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
761 "verify modified attributes for specific prefix with 'vrf default'"
764 for addr_type
in ADDR_TYPES
:
770 "network": NETWORK
[addr_type
][0],
772 "largeCommunity": "500:500:500",
778 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict
)
779 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
782 result
= verify_rib(tgen
, addr_type
, dut
, input_dict
)
783 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
787 for addr_type
in ADDR_TYPES
:
793 "network": NETWORK
[addr_type
][0],
795 "community": "500:500",
801 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict
)
802 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
805 result
= verify_rib(tgen
, addr_type
, dut
, input_dict
)
806 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
810 input_dict_4
= {"largeCommunity": "500:500:500", "community": "500:500"}
812 result
= verify_bgp_community(
813 tgen
, addr_type
, dut
, [NETWORK
[addr_type
][0]], input_dict_4
815 assert result
is True, "Test case {} : Should fail \n Error: {}".format(
819 write_test_footer(tc_name
)
822 def test_bgp_with_loopback_interface(request
):
824 Test BGP with loopback interface
826 Adding keys:value pair "dest_link": "lo" and "source_link": "lo"
827 peer dict of input json file for all router's creating config using
828 loopback interface. Once BGP neighboship is up then verifying BGP
833 if BGP_CONVERGENCE
is not True:
834 pytest
.skip("skipped because of BGP Convergence failure")
837 tc_name
= request
.node
.name
838 write_test_header(tc_name
)
840 # Creating configuration from JSON
841 reset_config_on_routers(tgen
)
843 for routerN
in sorted(topo
["routers"].keys()):
844 for bgp_neighbor
in topo
["routers"][routerN
]["bgp"]["address_family"]["ipv4"][
846 ]["neighbor"].keys():
848 # Adding ['source_link'] = 'lo' key:value pair
849 topo
["routers"][routerN
]["bgp"]["address_family"]["ipv4"]["unicast"][
851 ][bgp_neighbor
]["dest_link"] = {
857 # Creating configuration from JSON
858 build_config_from_json(tgen
, topo
)
863 {"network": "1.0.2.17/32", "next_hop": "10.0.0.2"},
864 {"network": "1.0.3.17/32", "next_hop": "10.0.0.6"},
869 {"network": "1.0.1.17/32", "next_hop": "10.0.0.1"},
870 {"network": "1.0.3.17/32", "next_hop": "10.0.0.10"},
875 {"network": "1.0.1.17/32", "next_hop": "10.0.0.5"},
876 {"network": "1.0.2.17/32", "next_hop": "10.0.0.9"},
877 {"network": "1.0.4.17/32", "next_hop": "10.0.0.14"},
880 "r4": {"static_routes": [{"network": "1.0.3.17/32", "next_hop": "10.0.0.13"}]},
882 result
= create_static_routes(tgen
, input_dict
)
883 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
885 # Api call verify whether BGP is converged
886 result
= verify_bgp_convergence(tgen
, topo
)
887 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
889 write_test_footer(tc_name
)
892 def test_bgp_with_loopback_with_same_subnet_p1(request
):
894 Verify routes not installed in zebra when /32 routes received
895 with loopback BGP session subnet
899 if BGP_CONVERGENCE
is not True:
900 pytest
.skip("skipped because of BGP Convergence failure")
903 tc_name
= request
.node
.name
904 write_test_header(tc_name
)
906 # Creating configuration from JSON
907 reset_config_on_routers(tgen
)
908 step("Delete BGP seesion created initially")
910 "r1": {"bgp": {"delete": True}},
911 "r2": {"bgp": {"delete": True}},
912 "r3": {"bgp": {"delete": True}},
913 "r4": {"bgp": {"delete": True}},
915 result
= create_router_bgp(tgen
, topo
, input_dict_r1
)
916 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
918 step("Create BGP session over loop address")
919 topo_modify
= deepcopy(topo
)
921 for routerN
in sorted(topo
["routers"].keys()):
922 for addr_type
in ADDR_TYPES
:
923 for bgp_neighbor
in topo_modify
["routers"][routerN
]["bgp"][
925 ][addr_type
]["unicast"]["neighbor"].keys():
927 # Adding ['source_link'] = 'lo' key:value pair
928 topo_modify
["routers"][routerN
]["bgp"]["address_family"][addr_type
][
930 ]["neighbor"][bgp_neighbor
]["dest_link"] = {
931 "lo": {"source_link": "lo", "ebgp_multihop": 2}
934 result
= create_router_bgp(tgen
, topo_modify
["routers"])
935 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
937 step("Disable IPv6 BGP nbr from ipv4 address family")
941 "router bgp {}".format(topo
["routers"]["r1"]["bgp"]["local_as"]),
942 "address-family ipv4 unicast",
943 "no neighbor {} activate".format(
944 topo
["routers"]["r2"]["links"]["lo"]["ipv6"].split("/")[0]
946 "no neighbor {} activate".format(
947 topo
["routers"]["r3"]["links"]["lo"]["ipv6"].split("/")[0]
953 "router bgp {}".format(topo
["routers"]["r2"]["bgp"]["local_as"]),
954 "address-family ipv4 unicast",
955 "no neighbor {} activate".format(
956 topo
["routers"]["r1"]["links"]["lo"]["ipv6"].split("/")[0]
958 "no neighbor {} activate".format(
959 topo
["routers"]["r3"]["links"]["lo"]["ipv6"].split("/")[0]
965 "router bgp {}".format(topo
["routers"]["r3"]["bgp"]["local_as"]),
966 "address-family ipv4 unicast",
967 "no neighbor {} activate".format(
968 topo
["routers"]["r1"]["links"]["lo"]["ipv6"].split("/")[0]
970 "no neighbor {} activate".format(
971 topo
["routers"]["r2"]["links"]["lo"]["ipv6"].split("/")[0]
973 "no neighbor {} activate".format(
974 topo
["routers"]["r4"]["links"]["lo"]["ipv6"].split("/")[0]
980 "router bgp {}".format(topo
["routers"]["r4"]["bgp"]["local_as"]),
981 "address-family ipv4 unicast",
982 "no neighbor {} activate".format(
983 topo
["routers"]["r3"]["links"]["lo"]["ipv6"].split("/")[0]
989 step("Configure kernel routes")
990 result
= apply_raw_config(tgen
, raw_config
)
991 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
993 r1_ipv4_lo
= topo
["routers"]["r1"]["links"]["lo"]["ipv4"]
994 r1_ipv6_lo
= topo
["routers"]["r1"]["links"]["lo"]["ipv6"]
995 r2_ipv4_lo
= topo
["routers"]["r2"]["links"]["lo"]["ipv4"]
996 r2_ipv6_lo
= topo
["routers"]["r2"]["links"]["lo"]["ipv6"]
997 r3_ipv4_lo
= topo
["routers"]["r3"]["links"]["lo"]["ipv4"]
998 r3_ipv6_lo
= topo
["routers"]["r3"]["links"]["lo"]["ipv6"]
999 r4_ipv4_lo
= topo
["routers"]["r4"]["links"]["lo"]["ipv4"]
1000 r4_ipv6_lo
= topo
["routers"]["r4"]["links"]["lo"]["ipv6"]
1002 r1_r2
= topo
["routers"]["r1"]["links"]["r2"]["ipv6"].split("/")[0]
1003 r2_r1
= topo
["routers"]["r2"]["links"]["r1"]["ipv6"].split("/")[0]
1004 r1_r3
= topo
["routers"]["r1"]["links"]["r3"]["ipv6"].split("/")[0]
1005 r3_r1
= topo
["routers"]["r3"]["links"]["r1"]["ipv6"].split("/")[0]
1006 r2_r3
= topo
["routers"]["r2"]["links"]["r3"]["ipv6"].split("/")[0]
1007 r3_r2
= topo
["routers"]["r3"]["links"]["r2"]["ipv6"].split("/")[0]
1008 r3_r4
= topo
["routers"]["r3"]["links"]["r4"]["ipv6"].split("/")[0]
1009 r4_r3
= topo
["routers"]["r4"]["links"]["r3"]["ipv6"].split("/")[0]
1011 r1_r2_ipv4
= topo
["routers"]["r1"]["links"]["r2"]["ipv4"].split("/")[0]
1012 r2_r1_ipv4
= topo
["routers"]["r2"]["links"]["r1"]["ipv4"].split("/")[0]
1013 r1_r3_ipv4
= topo
["routers"]["r1"]["links"]["r3"]["ipv4"].split("/")[0]
1014 r3_r1_ipv4
= topo
["routers"]["r3"]["links"]["r1"]["ipv4"].split("/")[0]
1015 r2_r3_ipv4
= topo
["routers"]["r2"]["links"]["r3"]["ipv4"].split("/")[0]
1016 r3_r2_ipv4
= topo
["routers"]["r3"]["links"]["r2"]["ipv4"].split("/")[0]
1017 r3_r4_ipv4
= topo
["routers"]["r3"]["links"]["r4"]["ipv4"].split("/")[0]
1018 r4_r3_ipv4
= topo
["routers"]["r4"]["links"]["r3"]["ipv4"].split("/")[0]
1020 r1_r2_intf
= topo
["routers"]["r1"]["links"]["r2"]["interface"]
1021 r2_r1_intf
= topo
["routers"]["r2"]["links"]["r1"]["interface"]
1022 r1_r3_intf
= topo
["routers"]["r1"]["links"]["r3"]["interface"]
1023 r3_r1_intf
= topo
["routers"]["r3"]["links"]["r1"]["interface"]
1024 r2_r3_intf
= topo
["routers"]["r2"]["links"]["r3"]["interface"]
1025 r3_r2_intf
= topo
["routers"]["r3"]["links"]["r2"]["interface"]
1026 r3_r4_intf
= topo
["routers"]["r3"]["links"]["r4"]["interface"]
1027 r4_r3_intf
= topo
["routers"]["r4"]["links"]["r3"]["interface"]
1030 ("r1", r1_r2_intf
, r2_ipv4_loopback
),
1031 ("r1", r1_r3_intf
, r3_ipv4_loopback
),
1032 ("r2", r2_r1_intf
, r1_ipv4_loopback
),
1033 ("r2", r2_r3_intf
, r3_ipv4_loopback
),
1034 ("r3", r3_r1_intf
, r1_ipv4_loopback
),
1035 ("r3", r3_r2_intf
, r2_ipv4_loopback
),
1036 ("r3", r3_r4_intf
, r4_ipv4_loopback
),
1037 ("r4", r4_r3_intf
, r3_ipv4_loopback
),
1041 ("r1", r1_r2_intf
, r2_ipv6_loopback
, r2_r1
),
1042 ("r1", r1_r3_intf
, r3_ipv6_loopback
, r3_r1
),
1043 ("r2", r2_r1_intf
, r1_ipv6_loopback
, r1_r2
),
1044 ("r2", r2_r3_intf
, r3_ipv6_loopback
, r3_r2
),
1045 ("r3", r3_r1_intf
, r1_ipv6_loopback
, r1_r3
),
1046 ("r3", r3_r2_intf
, r2_ipv6_loopback
, r2_r3
),
1047 ("r3", r3_r4_intf
, r4_ipv6_loopback
, r4_r3
),
1048 ("r4", r4_r3_intf
, r3_ipv6_loopback
, r3_r4
),
1051 for dut
, intf
, loop_addr
in ipv4_list
:
1052 result
= addKernelRoute(tgen
, dut
, intf
, loop_addr
)
1053 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
1055 for dut
, intf
, loop_addr
, next_hop
in ipv6_list
:
1056 result
= addKernelRoute(tgen
, dut
, intf
, loop_addr
, next_hop
)
1057 assert result
is True, "Testcase {}:Failed \n Error: {}".format(tc_name
, result
)
1059 step("Configure static routes")
1064 {"network": r2_ipv4_loopback
, "next_hop": r2_r1_ipv4
},
1065 {"network": r3_ipv4_loopback
, "next_hop": r3_r1_ipv4
},
1066 {"network": r2_ipv6_loopback
, "next_hop": r2_r1
},
1067 {"network": r3_ipv6_loopback
, "next_hop": r3_r1
},
1072 {"network": r1_ipv4_loopback
, "next_hop": r1_r2_ipv4
},
1073 {"network": r3_ipv4_loopback
, "next_hop": r3_r2_ipv4
},
1074 {"network": r1_ipv6_loopback
, "next_hop": r1_r2
},
1075 {"network": r3_ipv6_loopback
, "next_hop": r3_r2
},
1080 {"network": r1_ipv4_loopback
, "next_hop": r1_r3_ipv4
},
1081 {"network": r2_ipv4_loopback
, "next_hop": r2_r3_ipv4
},
1082 {"network": r4_ipv4_loopback
, "next_hop": r4_r3_ipv4
},
1083 {"network": r1_ipv6_loopback
, "next_hop": r1_r3
},
1084 {"network": r2_ipv6_loopback
, "next_hop": r2_r3
},
1085 {"network": r4_ipv6_loopback
, "next_hop": r4_r3
},
1090 {"network": r3_ipv4_loopback
, "next_hop": r3_r4_ipv4
},
1091 {"network": r3_ipv6_loopback
, "next_hop": r3_r4
},
1095 result
= create_static_routes(tgen
, input_dict
)
1096 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
1098 step("Verify BGP session convergence")
1100 result
= verify_bgp_convergence(tgen
, topo_modify
)
1101 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
1103 step("Configure redistribute connected on R2 and R4")
1109 "unicast": {"redistribute": [{"redist_type": "connected"}]}
1112 "unicast": {"redistribute": [{"redist_type": "connected"}]}
1121 "unicast": {"redistribute": [{"redist_type": "connected"}]}
1124 "unicast": {"redistribute": [{"redist_type": "connected"}]}
1131 result
= create_router_bgp(tgen
, topo
, input_dict_1
)
1132 assert result
is True, "Testcase {} :Failed \n Error: {}".format(tc_name
, result
)
1134 step("Verify Ipv4 and Ipv6 network installed in R1 RIB but not in FIB")
1138 {"network": "1.0.2.17/32"},
1139 {"network": "2001:db8:f::2:17/128"},
1146 for addr_type
in ADDR_TYPES
:
1147 result
= verify_fib_routes(
1148 tgen
, addr_type
, dut
, input_dict_r1
, expected
=False
1149 ) # pylint: disable=E1123
1150 assert result
is not True, (
1151 "Testcase {} : Failed \n "
1152 "Expected: Routes should not be present in {} FIB \n "
1153 "Found: {}".format(tc_name
, dut
, result
)
1156 step("Verify Ipv4 and Ipv6 network installed in r3 RIB but not in FIB")
1160 {"network": "1.0.4.17/32"},
1161 {"network": "2001:db8:f::4:17/128"},
1167 for addr_type
in ADDR_TYPES
:
1168 result
= verify_fib_routes(
1169 tgen
, addr_type
, dut
, input_dict_r1
, expected
=False
1170 ) # pylint: disable=E1123
1171 assert result
is not True, (
1172 "Testcase {} : Failed \n "
1173 "Expected: Routes should not be present in {} FIB \n "
1174 "Found: {}".format(tc_name
, dut
, result
)
1177 write_test_footer(tc_name
)
1180 if __name__
== "__main__":
1181 args
= ["-s"] + sys
.argv
[1:]
1182 sys
.exit(pytest
.main(args
))