3 # Copyright (c) 2022 by VMware, Inc. ("VMware")
4 # Used Copyright (c) 2018 by Network Device Education Foundation, Inc. ("NetDEF")
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
11 # Shreenidhi A R <rshreenidhi@vmware.com>
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
22 Following scenerios are covered.
23 1. When there is change in route-map policy associated with default-originate, changes does not reflect.
24 2. When route-map associated with default-originate is deleted, default route doesn't get withdrawn
25 3. Update message is not being sent when only route-map is removed from the default-originate config.
26 4. SNT counter gets incremented on change of every policy associated with default-originate
27 5. Route-map with multiple match clauses causes inconsistencies with default-originate.
28 6. BGP-Default originate behaviour with BGP attributes
34 from copy
import deepcopy
35 from lib
.topolog
import logger
37 # pylint: disable=C0413
38 # Import topogen and topotest helpers
39 from lib
.topogen
import Topogen
, get_topogen
40 from lib
.topojson
import build_config_from_json
41 from lib
.topolog
import logger
44 verify_bgp_convergence
,
46 get_prefix_count_route
,
50 verify_rib_default_route
,
51 verify_fib_default_route
,
53 from lib
.common_config
import (
56 required_linux_kernel_version
,
60 get_frr_ipv6_linklocal
,
66 reset_config_on_routers
,
72 # Save the Current Working Directory to find configuration files.
73 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
74 sys
.path
.append(os
.path
.join(CWD
, "../"))
75 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
77 # Required to instantiate the topology builder class.
79 # pylint: disable=C0413
80 # Import topogen and topotest helpers
84 NETWORK1_1
= {"ipv4": "198.51.1.1/32", "ipv6": "2001:DB8::1:1/128"}
85 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
86 NEXT_HOP_IP
= {"ipv4": "Null0", "ipv6": "Null0"}
88 def setup_module(mod
):
90 Sets up the pytest environment
95 # Required linux kernel version for this suite to run.
96 result
= required_linux_kernel_version("4.15")
97 if result
is not True:
98 pytest
.skip("Kernel requirements are not met")
100 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
101 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
102 logger
.info("=" * 40)
104 logger
.info("Running setup_module to create topology")
106 # This function initiates the topology build with Topogen...
107 json_file
= "{}/bgp_default_originate_topo1.json".format(CWD
)
108 tgen
= Topogen(json_file
, mod
.__name
__)
110 topo
= tgen
.json_topo
111 # ... and here it calls Mininet initialization functions.
113 # Starting topology, create tmp files which are loaded to routers
114 # to start daemons and then start routers
117 # Creating configuration from JSON
118 build_config_from_json(tgen
, topo
)
121 global BGP_CONVERGENCE
122 global DEFAULT_ROUTES
123 global DEFAULT_ROUTE_NXT_HOP_R1
, DEFAULT_ROUTE_NXT_HOP_R3
124 ADDR_TYPES
= check_address_types()
125 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
126 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
130 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
132 interface
= topo
["routers"]["r1"]["links"]["r2"]["interface"]
133 ipv6_link_local
= get_frr_ipv6_linklocal(tgen
, "r1", intf
=interface
)
134 ipv4_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"]["ipv4"].split("/")[0]
135 ipv6_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"]["ipv6"].split("/")[0]
136 DEFAULT_ROUTE_NXT_HOP_R1
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local
}
138 interface
= topo
["routers"]["r3"]["links"]["r2"]["interface"]
139 ipv6_link_local
= get_frr_ipv6_linklocal(tgen
, "r3", intf
=interface
)
140 ipv4_nxt_hop
= topo
["routers"]["r3"]["links"]["r2"]["ipv4"].split("/")[0]
141 ipv6_nxt_hop
= topo
["routers"]["r3"]["links"]["r2"]["ipv6"].split("/")[0]
142 DEFAULT_ROUTE_NXT_HOP_R3
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local
}
144 logger
.info("Running setup_module() done")
147 def teardown_module():
148 """Teardown the pytest environment"""
150 logger
.info("Running teardown_module to delete topology")
154 # Stop toplogy and Remove tmp files
158 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
160 logger
.info("=" * 40)
163 #####################################################
167 #####################################################
170 def test_default_originate_delete_conditional_routemap(request
):
173 1. When there is change in route-map policy associated with default-originate, changes does not reflect.
174 2. When route-map associated with default-originate is deleted, default route doesn't get withdrawn
175 3. Update message is not being sent when only route-map is removed from the default-originate config.
176 4. SNT counter gets incremented on change of every policy associated with default-originate
177 5. Route-map with multiple match clauses causes inconsistencies with default-originate.
180 global BGP_CONVERGENCE
182 tc_name
= request
.node
.name
183 write_test_header(tc_name
)
185 if tgen
.routers_have_failure():
186 check_router_status(tgen
)
187 reset_config_on_routers(tgen
)
189 if BGP_CONVERGENCE
!= True:
190 pytest
.skip("skipped because of BGP Convergence failure")
192 step("Configure IPv4 and IPv6 , IBGP neighbor between R1 and R2")
193 step("Configure IPv4 and IPv6 , EBGP neighbor between R1 and R0")
221 result
= modify_as_number(tgen
, topo
, input_dict
)
223 assert result
is True
224 except AssertionError:
225 logger
.info("Expected behaviour: {}".format(result
))
226 logger
.info("BGP config is not created because of invalid ASNs")
228 step("After changing the BGP remote as , Verify the BGP Convergence")
229 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
231 BGP_CONVERGENCE
is True
232 ), "Complete convergence is expected after changing ASN ....! ERROR :Failed \n Error: {}".format(
236 step("Configure 1 IPv4 and 1 IPv6 Static route on R0 with next-hop as Null0")
237 for addr_type
in ADDR_TYPES
:
238 static_routes_input
= {
242 "network": [NETWORK1_1
[addr_type
]],
243 "next_hop": NEXT_HOP_IP
[addr_type
],
248 result
= create_static_routes(tgen
, static_routes_input
)
251 ), "Testcase {} : Failed to configure the static route \n Error: {}".format(
255 step("verify IPv4 and IPv6 static route are configured and up on R0")
256 for addr_type
in ADDR_TYPES
:
257 static_routes_input
= {
261 "network": [NETWORK1_1
[addr_type
]],
262 "next_hop": NEXT_HOP_IP
[addr_type
],
267 result
= verify_fib_routes(tgen
, addr_type
, "r0", static_routes_input
)
270 ), "Testcase {} : routes {} not found in R0 FIB \n Error: {}".format(
271 tc_name
, static_routes_input
, result
275 "Configure redistribute static on IPv4 and IPv6 address family on R0 for R0 to R1 neighbor "
277 redistribute_static
= {
281 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
282 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
287 result
= create_router_bgp(tgen
, topo
, redistribute_static
)
290 ), "Testcase {} : Failed to configure redistribute configuration....! \n Error: {}".format(
294 step("verify IPv4 and IPv6 static route are received on R1")
295 for addr_type
in ADDR_TYPES
:
296 static_routes_input
= {
300 "network": [NETWORK1_1
[addr_type
]],
301 "next_hop": NEXT_HOP_IP
[addr_type
],
306 result
= verify_fib_routes(tgen
, addr_type
, "r1", static_routes_input
)
309 ), "Testcase {} : Failed... Routes {} expected in r1 FIB after configuring the redistribute config on R0 \n Error: {}".format(
310 tc_name
, static_routes_input
, result
313 result
= verify_bgp_rib(tgen
, addr_type
, "r1", static_routes_input
)
316 ), "Testcase {} : Failed... Routes {} expected in r1 RIB after configuring the redistribute config on R0\n Error: {}".format(
317 tc_name
, static_routes_input
, result
321 "Configure IPv4 prefix-list 'Pv4' and and IPv6 prefix-list 'Pv6' on R1 to match BGP route Sv41, IPv6 route Sv61 permit "
330 "network": NETWORK1_1
["ipv4"],
339 "network": NETWORK1_1
["ipv6"],
347 result
= create_prefix_lists(tgen
, input_dict_3
)
350 ), "Testcase {} : Failed to configure the prefix list \n Error: {}".format(
355 "Configure IPV4 and IPv6 route-map (RMv4 and RMv6) matching prefix-list (Pv4 and Pv6) respectively on R1"
364 "match": {"ipv4": {"prefix_lists": "Pv4"}},
368 "as_action": "prepend",
377 "match": {"ipv6": {"prefix_lists": "Pv6"}},
381 "as_action": "prepend",
389 result
= create_route_maps(tgen
, input_dict_3
)
392 ), "Testcase {} : Failed to configure the route map \n Error: {}".format(
397 "Configure default-originate with route-map (RMv4 and RMv6) on R1, on BGP IPv4 and IPv6 address family "
399 local_as
= get_dut_as_number(tgen
, dut
="r1")
400 default_originate_config
= {
403 "local_as": local_as
,
406 "unicast": {"default_originate": {"r2": {"route_map": "RMv4"}}}
409 "unicast": {"default_originate": {"r2": {"route_map": "RMv6"}}}
415 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
418 ), "Testcase {} : Failed to configure the default originate \n Error: {}".format(
423 "After configuring default-originate command , verify default routes are advertised on R2 "
425 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
426 result
= verify_rib_default_route(
430 routes
=DEFAULT_ROUTES
,
431 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
433 expected_aspath
="5555",
437 ), "Testcase {} : Failed to configure the default originate \n Error: {}".format(
441 result
= verify_fib_default_route(
445 routes
=DEFAULT_ROUTES
,
446 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
451 ), "Testcase {} : Failed to configure the default originate \n Error: {}".format(
455 step("Changing the as-path policy of the existing route-map")
463 "match": {"ipv4": {"prefix_lists": "Pv4"}},
467 "as_action": "prepend",
476 "match": {"ipv6": {"prefix_lists": "Pv6"}},
480 "as_action": "prepend",
488 result
= create_route_maps(tgen
, input_dict_3
)
491 ), "Testcase {} : Failed to configure the route map \n Error: {}".format(
496 "Verify prefix sent count on R1 towards R2 \n Send count shoud not be incremented on change of existing (AS-path) policy "
498 snapshot
= get_prefix_count_route(
499 tgen
, topo
, dut
="r1", peer
="r2", link
="r1", sent
=True, received
=False
502 ipv4_prefix_count
= False
503 ipv6_prefix_count
= False
504 if snapshot
["ipv4_count"] == 2:
505 ipv4_prefix_count
= True
506 if snapshot
["ipv6_count"] == 2:
507 ipv6_prefix_count
= True
510 ipv4_prefix_count
is True
511 ), "Testcase {} : Failed Error: Expected sent Prefix is 2 but obtained {} ".format(
512 tc_name
, ipv4_prefix_count
515 ipv6_prefix_count
is True
516 ), "Testcase {} : Failed Error: Expected sent Prefix is 2 but obtained {} ".format(
517 tc_name
, ipv6_prefix_count
521 "After changing the as-path policy verify the new policy is advertised to router R2"
523 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
524 result
= verify_rib_default_route(
528 routes
=DEFAULT_ROUTES
,
529 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
531 expected_aspath
="6666",
535 ), "Testcase {} : Default route with expected attributes is not found in BGP RIB \n Error: {}".format(
539 result
= verify_fib_default_route(
543 routes
=DEFAULT_ROUTES
,
544 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
549 ), "Testcase {} : Default route with expected attributes is not found in BGP FIB \n Error: {}".format(
553 step("Remove the as-path policy from the route-map")
561 "match": {"ipv4": {"prefix_lists": "Pv4"}},
565 "as_action": "prepend",
575 "match": {"ipv6": {"prefix_lists": "Pv6"}},
579 "as_action": "prepend",
588 result
= create_route_maps(tgen
, input_dict_3
)
591 ), "Testcase {} : Failed to configure the route map \n Error: {}".format(
596 "After removing the route policy (AS-Path) verify that as-path is removed in r2 "
598 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
600 result
= verify_rib_default_route(
604 routes
=DEFAULT_ROUTES
,
605 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
607 assert result
is True, "Testcase {} : Failed ... ! \n Error: {}".format(
611 result
= verify_fib_default_route(
615 routes
=DEFAULT_ROUTES
,
616 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
619 assert result
is True, "Testcase {} : Failed .... !\n Error: {}".format(
623 step("Delete the route-map ")
625 delete_routemap
= {"r1": {"route_maps": ["RMv4", "RMv6"]}}
626 result
= delete_route_maps(tgen
, delete_routemap
)
629 ), "Testcase {} : Failed to delete the route-map\n Error: {}".format(
634 "After deleting route-map , verify the default route in FIB and RIB are removed "
636 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
637 result
= verify_rib_default_route(
641 routes
=DEFAULT_ROUTES
,
642 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
648 ), "Testcase {} : After removing the route-map the default-route is not removed from R2 RIB\n Error: {}".format(
652 result
= verify_fib_default_route(
656 routes
=DEFAULT_ROUTES
,
657 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
662 ), "Testcase {} : After removing the route-map the default-route is not removed from R2 FIB \n Error: {}".format(
666 step("Create route-map with with sequnce number 10 ")
674 "match": {"ipv4": {"prefix_lists": "Pv4"}},
678 "as_action": "prepend",
687 "match": {"ipv6": {"prefix_lists": "Pv6"}},
691 "as_action": "prepend",
699 result
= create_route_maps(tgen
, input_dict_3
)
702 ), "Testcase {} : Failed to configure the route map \n Error: {}".format(
707 "After Configuring the route-map the dut is expected to receive the route policy (as-path) as 99999"
709 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
710 result
= verify_rib_default_route(
714 routes
=DEFAULT_ROUTES
,
715 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
717 expected_aspath
="9999",
719 assert result
is True, "Testcase {} : Failed...! \n Error: {}".format(
723 result
= verify_fib_default_route(
727 routes
=DEFAULT_ROUTES
,
728 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
731 assert result
is True, "Testcase {} : Failed ...!\n Error: {}".format(
735 step("Create another route-map with seq number less than the previous i. <10 ")
743 "match": {"ipv4": {"prefix_lists": "Pv4"}},
747 "as_action": "prepend",
756 "match": {"ipv6": {"prefix_lists": "Pv6"}},
760 "as_action": "prepend",
768 result
= create_route_maps(tgen
, input_dict_3
)
771 ), "Testcase {} : Failed to configure the route map \n Error: {}".format(
776 "On creating new route-map the route-map with lower seq id should be considered "
778 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
779 result
= verify_rib_default_route(
783 routes
=DEFAULT_ROUTES
,
784 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
786 expected_aspath
="7777",
790 ), "Testcase {} : Route-map with lowest prefix is not considered \n Error: {}".format(
794 result
= verify_fib_default_route(
798 routes
=DEFAULT_ROUTES
,
799 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
804 ), "Testcase {} : Route-map with lowest prefix is not considered \n Error: {}".format(
808 write_test_footer(tc_name
)
811 def test_verify_default_originate_after_BGP_attributes_p1(request
):
813 "Verify different BGP attributes with default-originate route "
816 global BGP_CONVERGENCE
819 tc_name
= request
.node
.name
820 write_test_header(tc_name
)
821 # Don't run this test if we have any failure.
822 if tgen
.routers_have_failure():
823 check_router_status(tgen
)
824 reset_config_on_routers(tgen
)
826 if BGP_CONVERGENCE
!= True:
827 pytest
.skip("skipped because of BGP Convergence failure")
829 step("Configure IPv4 and IPv6 , EBGP neighbor between R3 and R2")
830 step("Configure IPv4 and IPv6 IBGP neighbor between R3 and R4")
831 r0_local_as
= topo
['routers']['r0']['bgp']['local_as']
832 r1_local_as
= topo
['routers']['r1']['bgp']['local_as']
833 r2_local_as
= topo
['routers']['r2']['bgp']['local_as']
834 r3_local_as
= topo
['routers']['r3']['bgp']['local_as']
835 r4_local_as
= topo
['routers']['r4']['bgp']['local_as']
839 "local_as": r0_local_as
,
844 "local_as": r1_local_as
,
849 "local_as": r2_local_as
,
863 result
= modify_as_number(tgen
, topo
, input_dict
)
866 assert result
is True
867 except AssertionError:
868 logger
.info("Expected behaviour: {}".format(result
))
869 logger
.info("BGP config is not created because of invalid ASNs")
870 step("After changing the BGP AS Path Verify the BGP Convergence")
872 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
873 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
878 "Configure one IPv4 and one IPv6, Static route on R4 with next-hop as Null0 IPv4 route Sv41, IPv6 route Sv61 "
880 for addr_type
in ADDR_TYPES
:
881 static_routes_input
= {
885 "network": [NETWORK1_1
[addr_type
]],
886 "next_hop": NEXT_HOP_IP
[addr_type
],
891 result
= create_static_routes(tgen
, static_routes_input
)
892 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
895 step("Verify IPv4 and IPv6 static routes configured on R4 in FIB")
896 for addr_type
in ADDR_TYPES
:
897 static_routes_input
= {
901 "network": [NETWORK1_1
[addr_type
]],
902 "next_hop": NEXT_HOP_IP
[addr_type
],
907 result
= verify_fib_routes(tgen
, addr_type
, "r4", static_routes_input
)
908 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
913 "Configure redistribute static knob on R4 , for R4 to R3 neighbor for IPv4 and IPv6 address family "
915 redistribute_static
= {
919 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
920 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
925 result
= create_router_bgp(tgen
, topo
, redistribute_static
)
926 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
929 "Verify After configuring redistribute static , verify route received in BGP table of R3"
931 for addr_type
in ADDR_TYPES
:
932 static_routes_input
= {
936 "network": [NETWORK1_1
[addr_type
]],
937 "next_hop": NEXT_HOP_IP
[addr_type
],
942 result
= verify_fib_routes(tgen
, addr_type
, "r3", static_routes_input
)
943 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
947 result
= verify_bgp_rib(tgen
, addr_type
, "r3", static_routes_input
)
948 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
952 NOTE
= """Configure 2 IPv4 prefix-list Pv41 Pv42 and and 2 IPv6 prefix-list Pv61 Pv62 on R3 to match BGP IPv4 route Sv41, 200.1.1.1/24 , IPv6 route Sv61 and 200::1/64"""
961 "network": NETWORK1_1
["ipv4"],
966 {"seqid": "1", "network": "200.1.1.1/24", "action": "permit"}
973 "network": NETWORK1_1
["ipv6"],
978 {"seqid": " 1", "network": "200::1/64", "action": "permit"}
984 result
= create_prefix_lists(tgen
, input_dict_3
)
985 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
987 step("verify IPv4 and IPv6 Prefix list got configured on R3")
988 input_dict
= {"r3": {"prefix_lists": ["Pv41", "Pv61", "Pv42", "Pv62"]}}
989 result
= verify_prefix_lists(tgen
, input_dict
)
990 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
993 "Configure 2 sequence of route-map for IPv4 seq1 permit Pv41 and seq2 permit Pv42 and for IPv6 seq1 permit Pv61 , seq2 permit Pv62 on R3"
1002 "match": {"ipv4": {"prefix_lists": "Pv41"}},
1007 "match": {"ipv4": {"prefix_lists": "Pv42"}},
1014 "match": {"ipv6": {"prefix_lists": "Pv61"}},
1019 "match": {"ipv6": {"prefix_lists": "Pv62"}},
1025 result
= create_route_maps(tgen
, input_dict_3
)
1026 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1029 "Apply on route-map seq1 set as-path prepend to 200 and route-map seq2 set as-path prepend to 300 for IPv4 and IPv6 route-map "
1041 "as_action": "prepend",
1052 "as_action": "prepend",
1064 "as_action": "prepend",
1074 "as_action": "prepend",
1083 result
= create_route_maps(tgen
, route_map
)
1084 assert result
is True, "Test case {} : Failed \n Error: {}".format(tc_name
, result
)
1087 " Configure default-originate with IPv4 and IPv6 route-map on R3 for R3-R2 IPv4 and IPv6 BGP neighbor"
1090 local_as
= get_dut_as_number(tgen
, dut
="r3")
1091 default_originate_config
= {
1094 "local_as": local_as
,
1097 "unicast": {"default_originate": {"r2": {"route_map": "RMv4"}}}
1100 "unicast": {"default_originate": {"r2": {"route_map": "RMv6"}}}
1106 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
1107 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1110 "Verify IPv4 and IPv6 default route received on R2 with both the AS path on R2"
1112 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1114 result
= verify_rib_default_route(
1118 routes
=DEFAULT_ROUTES
,
1119 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1121 expected_aspath
="4000 200",
1125 "Modify AS prepend path adding one more value 500 in route-map sequence 1 and 600 for route-map sequence 2 for IPv4 and IPv6 route-map"
1137 "as_action": "prepend",
1148 "as_action": "prepend",
1160 "as_action": "prepend",
1170 "as_action": "prepend",
1179 result
= create_route_maps(tgen
, route_map
)
1180 assert result
is True, "Test case {} : Failed \n Error: {}".format(tc_name
, result
)
1181 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1184 step("As path 500 added to IPv4 and IPv6 default -originate route received on R2")
1185 result
= verify_rib_default_route(
1189 routes
=DEFAULT_ROUTES
,
1190 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1192 expected_aspath
="4000 500",
1194 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1197 "Apply on route-map seq1 set metric value to 70 and route-map seq2 set metric 80 IPv4 and IPv6 route-map"
1238 result
= create_route_maps(tgen
, route_map
)
1239 assert result
is True, "Test case {} : Failed \n Error: {}".format(tc_name
, result
)
1242 "Verify Configured metric value received on R2 along with as-path for IPv4 and IPv6 default routes "
1246 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "::/0"}
1247 result
= verify_rib_default_route(
1251 routes
=DEFAULT_ROUTES
,
1252 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1254 expected_aspath
="4000 500",
1259 "Modify route-map seq1 configure metric 50 and route-map seq2 configure metric 100 IPv4 and IPv6 route-map "
1300 result
= create_route_maps(tgen
, route_map
)
1301 assert result
is True, "Test case {} : Failed \n Error: {}".format(tc_name
, result
)
1304 "Verify Configured metric value received on R2 along with as-path for IPv4 and IPv6 default routes "
1308 result
= verify_rib_default_route(
1312 routes
=DEFAULT_ROUTES
,
1313 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1315 expected_aspath
="4000 500",
1317 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1319 step("Delete AS-prepend from IP4 and IPv6 route-map configured on R3 ")
1331 "as_action": "prepend",
1343 "as_action": "prepend",
1357 "as_action": "prepend",
1369 "as_action": "prepend",
1380 result
= create_route_maps(tgen
, route_map
)
1381 assert result
is True, "Test case {} : Failed \n Error: {}".format(tc_name
, result
)
1384 "Verify AS-prepend is deleted from default originate route and metric value only present on R2 for IPv4 and IPv6 default routes "
1390 result
= verify_rib_default_route(
1394 routes
=DEFAULT_ROUTES
,
1395 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1397 expected_aspath
="4000",
1399 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1402 step("Delete metric value from IP4 and IPv6 route-map configured on R3 ")
1410 "set": {"metric": 50, "delete": True},
1415 "set": {"metric": 100, "delete": True},
1422 "set": {"metric": 50, "delete": True},
1427 "set": {"metric": 100, "delete": True},
1434 result
= create_route_maps(tgen
, route_map
)
1435 assert result
is True, "Test case {} : Failed \n Error: {}".format(tc_name
, result
)
1438 "Verify Metric value deleted from IPv4 and IPv6 default route on R2 ,verify default routes "
1443 result
= verify_rib_default_route(
1447 routes
=DEFAULT_ROUTES
,
1448 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1450 expected_aspath
="4000",
1453 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1454 step("Change IPv4 and IPv6 , EBGP to IBGP neighbor between R3 and R2")
1455 step("Change IPv4 and IPv6 IBGP to EBGP neighbor between R3 and R4")
1456 r0_local_as
= topo
['routers']['r0']['bgp']['local_as']
1457 r1_local_as
= topo
['routers']['r1']['bgp']['local_as']
1458 r2_local_as
= topo
['routers']['r2']['bgp']['local_as']
1459 r3_local_as
= topo
['routers']['r3']['bgp']['local_as']
1460 r4_local_as
= topo
['routers']['r4']['bgp']['local_as']
1464 "local_as": r0_local_as
,
1469 "local_as": r1_local_as
,
1489 result
= modify_as_number(tgen
, topo
, input_dict
)
1491 assert result
is True
1492 except AssertionError:
1493 logger
.info("Expected behaviour: {}".format(result
))
1494 logger
.info("BGP config is not created because of invalid ASNs")
1495 step("After changing the BGP AS Path Verify the BGP Convergence")
1496 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
1497 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
1501 "Configure one IPv4 and one IPv6, Static route on R4 with next-hop as Null0 IPv4 route Sv41, IPv6 route Sv61 "
1503 for addr_type
in ADDR_TYPES
:
1504 static_routes_input
= {
1508 "network": [NETWORK1_1
[addr_type
]],
1509 "next_hop": NEXT_HOP_IP
[addr_type
],
1514 result
= create_static_routes(tgen
, static_routes_input
)
1515 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1518 step("Verify IPv4 and IPv6 static routes configured on R4 in FIB")
1519 for addr_type
in ADDR_TYPES
:
1520 static_routes_input
= {
1524 "network": [NETWORK1_1
[addr_type
]],
1525 "next_hop": NEXT_HOP_IP
[addr_type
],
1530 result
= verify_fib_routes(tgen
, addr_type
, "r4", static_routes_input
)
1531 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1536 "Configure redistribute static knob on R4 , for R4 to R3 neighbor for IPv4 and IPv6 address family "
1538 redistribute_static
= {
1542 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1543 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1548 result
= create_router_bgp(tgen
, topo
, redistribute_static
)
1549 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1552 "Verify After configuring redistribute static , verify route received in BGP table of R3"
1554 for addr_type
in ADDR_TYPES
:
1555 static_routes_input
= {
1559 "network": [NETWORK1_1
[addr_type
]],
1560 "next_hop": NEXT_HOP_IP
[addr_type
],
1565 result
= verify_fib_routes(tgen
, addr_type
, "r3", static_routes_input
)
1566 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1570 result
= verify_bgp_rib(tgen
, addr_type
, "r3", static_routes_input
)
1571 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1575 " Configure default-originate with IPv4 and IPv6 route-map on R3 for R3-R2 IPv4 and IPv6 BGP neighbor"
1577 local_as
= get_dut_as_number(tgen
, dut
="r3")
1578 default_originate_config
= {
1581 "local_as": local_as
,
1584 "unicast": {"default_originate": {"r2": {"route_map": "RMv4"}}}
1587 "unicast": {"default_originate": {"r2": {"route_map": "RMv6"}}}
1593 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
1594 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1597 "Verify IPv4 and IPv6 default route received on R2 with both the AS path on R2"
1599 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1600 result
= verify_rib_default_route(
1604 routes
=DEFAULT_ROUTES
,
1605 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1607 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1610 "Configure local -preference to 50 on IPv4 and IPv6 route map seq1 and 60 on seq2"
1651 result
= create_route_maps(tgen
, route_map
)
1652 assert result
is True, "Test case {} : Failed \n Error: {}".format(tc_name
, result
)
1655 "Verify Configured metric value received on R2 along with as-path for IPv4 and IPv6 default routes "
1660 result
= verify_rib_default_route(
1664 routes
=DEFAULT_ROUTES
,
1665 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1670 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1673 "Modify local preference value to 150 on IPv4 and IPv6 route map seq1 and 160 on seq2"
1714 result
= create_route_maps(tgen
, route_map
)
1715 assert result
is True, "Test case {} : Failed \n Error: {}".format(tc_name
, result
)
1718 "Verify Modified local-preference value received on R2 for IPv4 and IPv6 default routes "
1724 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "::/0"}
1725 result
= verify_rib_default_route(
1729 routes
=DEFAULT_ROUTES
,
1730 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1734 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1735 # updating the topology with the updated AS-Number to avoid conflict in con configuring the AS
1737 updated_topo
['routers']['r0']['bgp']['local_as']=get_dut_as_number(tgen
,"r0")
1738 updated_topo
['routers']['r1']['bgp']['local_as']=get_dut_as_number(tgen
,"r1")
1739 updated_topo
['routers']['r2']['bgp']['local_as']=get_dut_as_number(tgen
,"r2")
1740 updated_topo
['routers']['r3']['bgp']['local_as']=get_dut_as_number(tgen
,"r3")
1741 updated_topo
['routers']['r4']['bgp']['local_as']=get_dut_as_number(tgen
,"r4")
1743 step("Shut IPv4/IPv6 BGP neighbor from R4 ( R4-R3) using 'neighbor x.x.x.x shut' command ")
1744 local_as
= get_dut_as_number(tgen
, dut
="r4")
1748 "local_as": local_as
,
1755 "r4": {"shutdown":True}
1766 "r4": {"shutdown":True}
1776 result
= create_router_bgp(tgen
, updated_topo
, shut_neighbor
)
1777 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1779 interface
= topo
['routers']['r3']['links']['r4']['interface']
1782 "interface_list": [interface
],
1787 result
= interface_status(tgen
, topo
, input_dict
)
1788 assert result
is True, "Testcase {} : Shut down the interface failed ! \n Error: {}".format(tc_name
, result
)
1790 step("After shutting the interface verify the BGP convergence")
1791 result
= verify_bgp_convergence(tgen
,topo
,expected
=False)
1792 assert result
is not True, "Testcase {} : Failed \n After shutting Down BGP convergence should Fail and return False \n Error: {}".format(tc_name
, result
)
1794 step("verify default route deleted from R2 ")
1795 result
= verify_rib_default_route(
1799 routes
=DEFAULT_ROUTES
,
1800 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1802 assert result
is not True, "Testcase {} : Failed \n Error: After Shut down interface the default route is NOT expected but found in RIB -> {}".format( tc_name
, result
)
1804 result
= verify_fib_default_route(
1808 routes
=DEFAULT_ROUTES
,
1809 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1811 assert result
is not True, "Testcase {} : Failed \n Error: After Shut down interface the default route is NOT expected but found in FIB -> {}".format( tc_name
, result
)
1814 step("no Shut IPv4/IPv6 BGP neighbor from R4 ( R4-R3) using 'neighbor x.x.x.x shut' command ")
1815 local_as
= get_dut_as_number(tgen
, dut
="r4")
1819 "local_as": local_as
,
1826 "r4": {"shutdown":False}
1837 "r4": {"shutdown":False}
1847 result
= create_router_bgp(tgen
, updated_topo
, shut_neighbor
)
1848 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1850 interface
= topo
['routers']['r3']['links']['r4']['interface']
1853 "interface_list": [interface
],
1858 result
= interface_status(tgen
, topo
, input_dict
)
1859 assert result
is True, "Testcase {} : Bring up interface failed ! \n Error: {}".format(tc_name
, result
)
1861 step("After no shutting the interface verify the BGP convergence")
1862 result
= verify_bgp_convergence(tgen
,topo
,expected
=True)
1863 assert result
is True, "Testcase {} : Failed \n After shutting Down BGP convergence should Fail and return False \n Error: {}".format(tc_name
, result
)
1865 step("After no shut neighbor , verify default route relearn on R2")
1866 result
= verify_rib_default_route(
1870 routes
=DEFAULT_ROUTES
,
1871 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1873 assert result
is True, "Testcase {} : Failed \n Error: After no Shut down interface the default route is expected but found in RIB -> {}".format( tc_name
, result
)
1875 result
= verify_fib_default_route(
1879 routes
=DEFAULT_ROUTES
,
1880 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1882 assert result
is True, "Testcase {} : Failed \n Error: After Shut down interface the default route is expected but found in FIB -> {}".format( tc_name
, result
)
1886 step("Remove IPv4/IPv6 static route configure on R4")
1887 for addr_type
in ADDR_TYPES
:
1888 static_routes_input
= {
1892 "network": [NETWORK1_1
[addr_type
]],
1893 "next_hop": NEXT_HOP_IP
[addr_type
],
1899 result
= create_static_routes(tgen
, static_routes_input
)
1900 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1903 step("Verify IPv4 and IPv6 static routes removed on R4 in FIB")
1904 for addr_type
in ADDR_TYPES
:
1905 static_routes_input
= {
1909 "network": [NETWORK1_1
[addr_type
]],
1910 "next_hop": NEXT_HOP_IP
[addr_type
],
1915 result
= verify_fib_routes(tgen
, addr_type
, "r4", static_routes_input
, expected
=False)
1916 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
1919 result
= verify_bgp_rib(tgen
, addr_type
, "r4", static_routes_input
, expected
=False)
1920 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
1924 step("After removing static route , verify default route removed on R2")
1925 result
= verify_rib_default_route(
1929 routes
=DEFAULT_ROUTES
,
1930 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1932 assert result
is not True, "Testcase {} : Failed \n Error: After removing static the default route is NOT expected but found in RIB -> {}".format( tc_name
, result
)
1934 result
= verify_fib_default_route(
1938 routes
=DEFAULT_ROUTES
,
1939 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1941 assert result
is not True, "Testcase {} : Failed \n Error: After removing static the default route is NOT expected but found in FIB -> {}".format( tc_name
, result
)
1944 step("Configuring the static route back in r4")
1945 for addr_type
in ADDR_TYPES
:
1946 static_routes_input
= {
1950 "network": [NETWORK1_1
[addr_type
]],
1951 "next_hop": NEXT_HOP_IP
[addr_type
],
1956 result
= create_static_routes(tgen
, static_routes_input
)
1957 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1960 step("Verify IPv4 and IPv6 static routes configured on R4 in FIB")
1961 for addr_type
in ADDR_TYPES
:
1962 static_routes_input
= {
1966 "network": [NETWORK1_1
[addr_type
]],
1967 "next_hop": NEXT_HOP_IP
[addr_type
],
1972 result
= verify_fib_routes(tgen
, addr_type
, "r4", static_routes_input
, expected
=True)
1973 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1976 result
= verify_bgp_rib(tgen
, addr_type
, "r4", static_routes_input
, expected
=True)
1977 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1981 step("After adding static route back , verify default route learned on R2")
1982 result
= verify_rib_default_route(
1986 routes
=DEFAULT_ROUTES
,
1987 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1989 assert result
is True, "Testcase {} : Failed \n Error: After removing static the default route is expected but found in RIB -> {}".format( tc_name
, result
)
1991 result
= verify_fib_default_route(
1995 routes
=DEFAULT_ROUTES
,
1996 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1998 assert result
is True, "Testcase {} : Failed \n Error: After removing static the default route is expected but found in FIB -> {}".format( tc_name
, result
)
2000 step("Deactivate IPv4 and IPv6 neighbor configured from R4 ( R4-R3)")
2002 configure_bgp_on_r1
= {
2009 "r3": {"dest_link": {"r4": {"deactivate": "ipv4"}}}
2016 "r3": {"dest_link": {"r4": {"deactivate": "ipv6"}}}
2025 result
= create_router_bgp(tgen
, updated_topo
, configure_bgp_on_r1
)
2026 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2028 step("After deactivating the BGP neighbor , verify default route removed on R2")
2029 result
= verify_rib_default_route(
2033 routes
=DEFAULT_ROUTES
,
2034 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
2036 assert result
is not True, "Testcase {} : Failed \n Error: After Deactivating the BGP neighbor the default route is NOT expected but found in RIB -> {}".format( tc_name
, result
)
2038 result
= verify_fib_default_route(
2042 routes
=DEFAULT_ROUTES
,
2043 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
2045 assert result
is not True, "Testcase {} : Failed \n Error: After Deactivating the BGP neighbor the default route is NOT expected but found in FIB -> {}".format( tc_name
, result
)
2047 step("Activate IPv4 and IPv6 neighbor configured from R4 ( R4-R3)")
2049 configure_bgp_on_r1
= {
2056 "r3": {"dest_link": {"r4": {"activate": "ipv4"}}}
2063 "r3": {"dest_link": {"r4": {"activate": "ipv6"}}}
2072 result
= create_router_bgp(tgen
, updated_topo
, configure_bgp_on_r1
)
2073 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2075 step("Verify bgp convergence.")
2076 bgp_convergence
= verify_bgp_convergence(tgen
, updated_topo
)
2077 assert bgp_convergence
is True, "Testcase {} : Failed \n Error: {}".format(
2078 tc_name
, bgp_convergence
2080 step("After Activating the BGP neighbor , verify default route learned on R2")
2081 result
= verify_rib_default_route(
2085 routes
=DEFAULT_ROUTES
,
2086 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
2088 assert result
is True, "Testcase {} : Failed \n Error: After Deactivating the BGP neighbor the default route is expected but found in RIB -> {}".format( tc_name
, result
)
2090 result
= verify_fib_default_route(
2094 routes
=DEFAULT_ROUTES
,
2095 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
2097 assert result
is True, "Testcase {} : Failed \n Error: After Deactivating the BGP neighbor the default route is expected but found in FIB -> {}".format( tc_name
, result
)
2098 write_test_footer(tc_name
)
2100 if __name__
== "__main__":
2101 args
= ["-s"] + sys
.argv
[1:]
2102 sys
.exit(pytest
.main(args
))