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 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.staticd
]
79 # Required to instantiate the topology builder class.
81 # pylint: disable=C0413
82 # Import topogen and topotest helpers
86 NETWORK1_1
= {"ipv4": "198.51.1.1/32", "ipv6": "2001:DB8::1:1/128"}
87 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
88 NEXT_HOP_IP
= {"ipv4": "Null0", "ipv6": "Null0"}
90 def setup_module(mod
):
92 Sets up the pytest environment
97 # Required linux kernel version for this suite to run.
98 result
= required_linux_kernel_version("4.15")
99 if result
is not True:
100 pytest
.skip("Kernel requirements are not met")
102 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
103 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
104 logger
.info("=" * 40)
106 logger
.info("Running setup_module to create topology")
108 # This function initiates the topology build with Topogen...
109 json_file
= "{}/bgp_default_originate_topo1.json".format(CWD
)
110 tgen
= Topogen(json_file
, mod
.__name
__)
112 topo
= tgen
.json_topo
113 # ... and here it calls Mininet initialization functions.
115 # Starting topology, create tmp files which are loaded to routers
116 # to start daemons and then start routers
119 # Creating configuration from JSON
120 build_config_from_json(tgen
, topo
)
123 global BGP_CONVERGENCE
124 global DEFAULT_ROUTES
125 global DEFAULT_ROUTE_NXT_HOP_R1
, DEFAULT_ROUTE_NXT_HOP_R3
126 ADDR_TYPES
= check_address_types()
127 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
128 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
132 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
134 interface
= topo
["routers"]["r1"]["links"]["r2"]["interface"]
135 ipv6_link_local
= get_frr_ipv6_linklocal(tgen
, "r1", intf
=interface
)
136 ipv4_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"]["ipv4"].split("/")[0]
137 ipv6_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"]["ipv6"].split("/")[0]
138 DEFAULT_ROUTE_NXT_HOP_R1
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local
}
140 interface
= topo
["routers"]["r3"]["links"]["r2"]["interface"]
141 ipv6_link_local
= get_frr_ipv6_linklocal(tgen
, "r3", intf
=interface
)
142 ipv4_nxt_hop
= topo
["routers"]["r3"]["links"]["r2"]["ipv4"].split("/")[0]
143 ipv6_nxt_hop
= topo
["routers"]["r3"]["links"]["r2"]["ipv6"].split("/")[0]
144 DEFAULT_ROUTE_NXT_HOP_R3
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local
}
146 logger
.info("Running setup_module() done")
149 def teardown_module():
150 """Teardown the pytest environment"""
152 logger
.info("Running teardown_module to delete topology")
156 # Stop toplogy and Remove tmp files
160 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
162 logger
.info("=" * 40)
165 #####################################################
169 #####################################################
172 def test_default_originate_delete_conditional_routemap(request
):
175 1. When there is change in route-map policy associated with default-originate, changes does not reflect.
176 2. When route-map associated with default-originate is deleted, default route doesn't get withdrawn
177 3. Update message is not being sent when only route-map is removed from the default-originate config.
178 4. SNT counter gets incremented on change of every policy associated with default-originate
179 5. Route-map with multiple match clauses causes inconsistencies with default-originate.
182 global BGP_CONVERGENCE
184 tc_name
= request
.node
.name
185 write_test_header(tc_name
)
187 if tgen
.routers_have_failure():
188 check_router_status(tgen
)
189 reset_config_on_routers(tgen
)
191 if BGP_CONVERGENCE
!= True:
192 pytest
.skip("skipped because of BGP Convergence failure")
194 step("Configure IPv4 and IPv6 , IBGP neighbor between R1 and R2")
195 step("Configure IPv4 and IPv6 , EBGP neighbor between R1 and R0")
223 result
= modify_as_number(tgen
, topo
, input_dict
)
225 assert result
is True
226 except AssertionError:
227 logger
.info("Expected behaviour: {}".format(result
))
228 logger
.info("BGP config is not created because of invalid ASNs")
230 step("After changing the BGP remote as , Verify the BGP Convergence")
231 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
233 BGP_CONVERGENCE
is True
234 ), "Complete convergence is expected after changing ASN ....! ERROR :Failed \n Error: {}".format(
238 step("Configure 1 IPv4 and 1 IPv6 Static route on R0 with next-hop as Null0")
239 for addr_type
in ADDR_TYPES
:
240 static_routes_input
= {
244 "network": [NETWORK1_1
[addr_type
]],
245 "next_hop": NEXT_HOP_IP
[addr_type
],
250 result
= create_static_routes(tgen
, static_routes_input
)
253 ), "Testcase {} : Failed to configure the static route \n Error: {}".format(
257 step("verify IPv4 and IPv6 static route are configured and up on R0")
258 for addr_type
in ADDR_TYPES
:
259 static_routes_input
= {
263 "network": [NETWORK1_1
[addr_type
]],
264 "next_hop": NEXT_HOP_IP
[addr_type
],
269 result
= verify_fib_routes(tgen
, addr_type
, "r0", static_routes_input
)
272 ), "Testcase {} : routes {} not found in R0 FIB \n Error: {}".format(
273 tc_name
, static_routes_input
, result
277 "Configure redistribute static on IPv4 and IPv6 address family on R0 for R0 to R1 neighbor "
279 redistribute_static
= {
283 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
284 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
289 result
= create_router_bgp(tgen
, topo
, redistribute_static
)
292 ), "Testcase {} : Failed to configure redistribute configuration....! \n Error: {}".format(
296 step("verify IPv4 and IPv6 static route are received on R1")
297 for addr_type
in ADDR_TYPES
:
298 static_routes_input
= {
302 "network": [NETWORK1_1
[addr_type
]],
303 "next_hop": NEXT_HOP_IP
[addr_type
],
308 result
= verify_fib_routes(tgen
, addr_type
, "r1", static_routes_input
)
311 ), "Testcase {} : Failed... Routes {} expected in r1 FIB after configuring the redistribute config on R0 \n Error: {}".format(
312 tc_name
, static_routes_input
, result
315 result
= verify_bgp_rib(tgen
, addr_type
, "r1", static_routes_input
)
318 ), "Testcase {} : Failed... Routes {} expected in r1 RIB after configuring the redistribute config on R0\n Error: {}".format(
319 tc_name
, static_routes_input
, result
323 "Configure IPv4 prefix-list 'Pv4' and and IPv6 prefix-list 'Pv6' on R1 to match BGP route Sv41, IPv6 route Sv61 permit "
332 "network": NETWORK1_1
["ipv4"],
341 "network": NETWORK1_1
["ipv6"],
349 result
= create_prefix_lists(tgen
, input_dict_3
)
352 ), "Testcase {} : Failed to configure the prefix list \n Error: {}".format(
357 "Configure IPV4 and IPv6 route-map (RMv4 and RMv6) matching prefix-list (Pv4 and Pv6) respectively on R1"
366 "match": {"ipv4": {"prefix_lists": "Pv4"}},
370 "as_action": "prepend",
379 "match": {"ipv6": {"prefix_lists": "Pv6"}},
383 "as_action": "prepend",
391 result
= create_route_maps(tgen
, input_dict_3
)
394 ), "Testcase {} : Failed to configure the route map \n Error: {}".format(
399 "Configure default-originate with route-map (RMv4 and RMv6) on R1, on BGP IPv4 and IPv6 address family "
401 local_as
= get_dut_as_number(tgen
, dut
="r1")
402 default_originate_config
= {
405 "local_as": local_as
,
408 "unicast": {"default_originate": {"r2": {"route_map": "RMv4"}}}
411 "unicast": {"default_originate": {"r2": {"route_map": "RMv6"}}}
417 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
420 ), "Testcase {} : Failed to configure the default originate \n Error: {}".format(
425 "After configuring default-originate command , verify default routes are advertised on R2 "
427 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
428 result
= verify_rib_default_route(
432 routes
=DEFAULT_ROUTES
,
433 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
435 expected_aspath
="5555",
439 ), "Testcase {} : Failed to configure the default originate \n Error: {}".format(
443 result
= verify_fib_default_route(
447 routes
=DEFAULT_ROUTES
,
448 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
453 ), "Testcase {} : Failed to configure the default originate \n Error: {}".format(
457 step("Changing the as-path policy of the existing route-map")
465 "match": {"ipv4": {"prefix_lists": "Pv4"}},
469 "as_action": "prepend",
478 "match": {"ipv6": {"prefix_lists": "Pv6"}},
482 "as_action": "prepend",
490 result
= create_route_maps(tgen
, input_dict_3
)
493 ), "Testcase {} : Failed to configure the route map \n Error: {}".format(
498 "Verify prefix sent count on R1 towards R2 \n Send count shoud not be incremented on change of existing (AS-path) policy "
500 snapshot
= get_prefix_count_route(
501 tgen
, topo
, dut
="r1", peer
="r2", link
="r1", sent
=True, received
=False
504 ipv4_prefix_count
= False
505 ipv6_prefix_count
= False
506 if snapshot
["ipv4_count"] == 2:
507 ipv4_prefix_count
= True
508 if snapshot
["ipv6_count"] == 2:
509 ipv6_prefix_count
= True
512 ipv4_prefix_count
is True
513 ), "Testcase {} : Failed Error: Expected sent Prefix is 2 but obtained {} ".format(
514 tc_name
, ipv4_prefix_count
517 ipv6_prefix_count
is True
518 ), "Testcase {} : Failed Error: Expected sent Prefix is 2 but obtained {} ".format(
519 tc_name
, ipv6_prefix_count
523 "After changing the as-path policy verify the new policy is advertised to router R2"
525 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
526 result
= verify_rib_default_route(
530 routes
=DEFAULT_ROUTES
,
531 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
533 expected_aspath
="6666",
537 ), "Testcase {} : Default route with expected attributes is not found in BGP RIB \n Error: {}".format(
541 result
= verify_fib_default_route(
545 routes
=DEFAULT_ROUTES
,
546 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
551 ), "Testcase {} : Default route with expected attributes is not found in BGP FIB \n Error: {}".format(
555 step("Remove the as-path policy from the route-map")
563 "match": {"ipv4": {"prefix_lists": "Pv4"}},
567 "as_action": "prepend",
577 "match": {"ipv6": {"prefix_lists": "Pv6"}},
581 "as_action": "prepend",
590 result
= create_route_maps(tgen
, input_dict_3
)
593 ), "Testcase {} : Failed to configure the route map \n Error: {}".format(
598 "After removing the route policy (AS-Path) verify that as-path is removed in r2 "
600 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
602 result
= verify_rib_default_route(
606 routes
=DEFAULT_ROUTES
,
607 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
609 assert result
is True, "Testcase {} : Failed ... ! \n Error: {}".format(
613 result
= verify_fib_default_route(
617 routes
=DEFAULT_ROUTES
,
618 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
621 assert result
is True, "Testcase {} : Failed .... !\n Error: {}".format(
625 step("Delete the route-map ")
627 delete_routemap
= {"r1": {"route_maps": ["RMv4", "RMv6"]}}
628 result
= delete_route_maps(tgen
, delete_routemap
)
631 ), "Testcase {} : Failed to delete the route-map\n Error: {}".format(
636 "After deleting route-map , verify the default route in FIB and RIB are removed "
638 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
639 result
= verify_rib_default_route(
643 routes
=DEFAULT_ROUTES
,
644 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
650 ), "Testcase {} : After removing the route-map the default-route is not removed from R2 RIB\n Error: {}".format(
654 result
= verify_fib_default_route(
658 routes
=DEFAULT_ROUTES
,
659 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
664 ), "Testcase {} : After removing the route-map the default-route is not removed from R2 FIB \n Error: {}".format(
668 step("Create route-map with with sequnce number 10 ")
676 "match": {"ipv4": {"prefix_lists": "Pv4"}},
680 "as_action": "prepend",
689 "match": {"ipv6": {"prefix_lists": "Pv6"}},
693 "as_action": "prepend",
701 result
= create_route_maps(tgen
, input_dict_3
)
704 ), "Testcase {} : Failed to configure the route map \n Error: {}".format(
709 "After Configuring the route-map the dut is expected to receive the route policy (as-path) as 99999"
711 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
712 result
= verify_rib_default_route(
716 routes
=DEFAULT_ROUTES
,
717 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
719 expected_aspath
="9999",
721 assert result
is True, "Testcase {} : Failed...! \n Error: {}".format(
725 result
= verify_fib_default_route(
729 routes
=DEFAULT_ROUTES
,
730 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
733 assert result
is True, "Testcase {} : Failed ...!\n Error: {}".format(
737 step("Create another route-map with seq number less than the previous i. <10 ")
745 "match": {"ipv4": {"prefix_lists": "Pv4"}},
749 "as_action": "prepend",
758 "match": {"ipv6": {"prefix_lists": "Pv6"}},
762 "as_action": "prepend",
770 result
= create_route_maps(tgen
, input_dict_3
)
773 ), "Testcase {} : Failed to configure the route map \n Error: {}".format(
778 "On creating new route-map the route-map with lower seq id should be considered "
780 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
781 result
= verify_rib_default_route(
785 routes
=DEFAULT_ROUTES
,
786 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
788 expected_aspath
="7777",
792 ), "Testcase {} : Route-map with lowest prefix is not considered \n Error: {}".format(
796 result
= verify_fib_default_route(
800 routes
=DEFAULT_ROUTES
,
801 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
806 ), "Testcase {} : Route-map with lowest prefix is not considered \n Error: {}".format(
810 write_test_footer(tc_name
)
813 def test_verify_default_originate_after_BGP_attributes_p1(request
):
815 "Verify different BGP attributes with default-originate route "
818 global BGP_CONVERGENCE
821 tc_name
= request
.node
.name
822 write_test_header(tc_name
)
823 # Don't run this test if we have any failure.
824 if tgen
.routers_have_failure():
825 check_router_status(tgen
)
826 reset_config_on_routers(tgen
)
828 if BGP_CONVERGENCE
!= True:
829 pytest
.skip("skipped because of BGP Convergence failure")
831 step("Configure IPv4 and IPv6 , EBGP neighbor between R3 and R2")
832 step("Configure IPv4 and IPv6 IBGP neighbor between R3 and R4")
833 r0_local_as
= topo
['routers']['r0']['bgp']['local_as']
834 r1_local_as
= topo
['routers']['r1']['bgp']['local_as']
835 r2_local_as
= topo
['routers']['r2']['bgp']['local_as']
836 r3_local_as
= topo
['routers']['r3']['bgp']['local_as']
837 r4_local_as
= topo
['routers']['r4']['bgp']['local_as']
841 "local_as": r0_local_as
,
846 "local_as": r1_local_as
,
851 "local_as": r2_local_as
,
865 result
= modify_as_number(tgen
, topo
, input_dict
)
868 assert result
is True
869 except AssertionError:
870 logger
.info("Expected behaviour: {}".format(result
))
871 logger
.info("BGP config is not created because of invalid ASNs")
872 step("After changing the BGP AS Path Verify the BGP Convergence")
874 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
875 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
880 "Configure one IPv4 and one IPv6, Static route on R4 with next-hop as Null0 IPv4 route Sv41, IPv6 route Sv61 "
882 for addr_type
in ADDR_TYPES
:
883 static_routes_input
= {
887 "network": [NETWORK1_1
[addr_type
]],
888 "next_hop": NEXT_HOP_IP
[addr_type
],
893 result
= create_static_routes(tgen
, static_routes_input
)
894 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
897 step("Verify IPv4 and IPv6 static routes configured on R4 in FIB")
898 for addr_type
in ADDR_TYPES
:
899 static_routes_input
= {
903 "network": [NETWORK1_1
[addr_type
]],
904 "next_hop": NEXT_HOP_IP
[addr_type
],
909 result
= verify_fib_routes(tgen
, addr_type
, "r4", static_routes_input
)
910 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
915 "Configure redistribute static knob on R4 , for R4 to R3 neighbor for IPv4 and IPv6 address family "
917 redistribute_static
= {
921 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
922 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
927 result
= create_router_bgp(tgen
, topo
, redistribute_static
)
928 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
931 "Verify After configuring redistribute static , verify route received in BGP table of R3"
933 for addr_type
in ADDR_TYPES
:
934 static_routes_input
= {
938 "network": [NETWORK1_1
[addr_type
]],
939 "next_hop": NEXT_HOP_IP
[addr_type
],
944 result
= verify_fib_routes(tgen
, addr_type
, "r3", static_routes_input
)
945 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
949 result
= verify_bgp_rib(tgen
, addr_type
, "r3", static_routes_input
)
950 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
954 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"""
963 "network": NETWORK1_1
["ipv4"],
968 {"seqid": "1", "network": "200.1.1.1/24", "action": "permit"}
975 "network": NETWORK1_1
["ipv6"],
980 {"seqid": " 1", "network": "200::1/64", "action": "permit"}
986 result
= create_prefix_lists(tgen
, input_dict_3
)
987 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
989 step("verify IPv4 and IPv6 Prefix list got configured on R3")
990 input_dict
= {"r3": {"prefix_lists": ["Pv41", "Pv61", "Pv42", "Pv62"]}}
991 result
= verify_prefix_lists(tgen
, input_dict
)
992 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
995 "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"
1004 "match": {"ipv4": {"prefix_lists": "Pv41"}},
1009 "match": {"ipv4": {"prefix_lists": "Pv42"}},
1016 "match": {"ipv6": {"prefix_lists": "Pv61"}},
1021 "match": {"ipv6": {"prefix_lists": "Pv62"}},
1027 result
= create_route_maps(tgen
, input_dict_3
)
1028 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1031 "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 "
1043 "as_action": "prepend",
1054 "as_action": "prepend",
1066 "as_action": "prepend",
1076 "as_action": "prepend",
1085 result
= create_route_maps(tgen
, route_map
)
1086 assert result
is True, "Test case {} : Failed \n Error: {}".format(tc_name
, result
)
1089 " Configure default-originate with IPv4 and IPv6 route-map on R3 for R3-R2 IPv4 and IPv6 BGP neighbor"
1092 local_as
= get_dut_as_number(tgen
, dut
="r3")
1093 default_originate_config
= {
1096 "local_as": local_as
,
1099 "unicast": {"default_originate": {"r2": {"route_map": "RMv4"}}}
1102 "unicast": {"default_originate": {"r2": {"route_map": "RMv6"}}}
1108 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
1109 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1112 "Verify IPv4 and IPv6 default route received on R2 with both the AS path on R2"
1114 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1116 result
= verify_rib_default_route(
1120 routes
=DEFAULT_ROUTES
,
1121 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1123 expected_aspath
="4000 200",
1127 "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"
1139 "as_action": "prepend",
1150 "as_action": "prepend",
1162 "as_action": "prepend",
1172 "as_action": "prepend",
1181 result
= create_route_maps(tgen
, route_map
)
1182 assert result
is True, "Test case {} : Failed \n Error: {}".format(tc_name
, result
)
1183 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1186 step("As path 500 added to IPv4 and IPv6 default -originate route received on R2")
1187 result
= verify_rib_default_route(
1191 routes
=DEFAULT_ROUTES
,
1192 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1194 expected_aspath
="4000 500",
1196 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1199 "Apply on route-map seq1 set metric value to 70 and route-map seq2 set metric 80 IPv4 and IPv6 route-map"
1240 result
= create_route_maps(tgen
, route_map
)
1241 assert result
is True, "Test case {} : Failed \n Error: {}".format(tc_name
, result
)
1244 "Verify Configured metric value received on R2 along with as-path for IPv4 and IPv6 default routes "
1248 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "::/0"}
1249 result
= verify_rib_default_route(
1253 routes
=DEFAULT_ROUTES
,
1254 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1256 expected_aspath
="4000 500",
1261 "Modify route-map seq1 configure metric 50 and route-map seq2 configure metric 100 IPv4 and IPv6 route-map "
1302 result
= create_route_maps(tgen
, route_map
)
1303 assert result
is True, "Test case {} : Failed \n Error: {}".format(tc_name
, result
)
1306 "Verify Configured metric value received on R2 along with as-path for IPv4 and IPv6 default routes "
1310 result
= verify_rib_default_route(
1314 routes
=DEFAULT_ROUTES
,
1315 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1317 expected_aspath
="4000 500",
1319 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1321 step("Delete AS-prepend from IP4 and IPv6 route-map configured on R3 ")
1333 "as_action": "prepend",
1345 "as_action": "prepend",
1359 "as_action": "prepend",
1371 "as_action": "prepend",
1382 result
= create_route_maps(tgen
, route_map
)
1383 assert result
is True, "Test case {} : Failed \n Error: {}".format(tc_name
, result
)
1386 "Verify AS-prepend is deleted from default originate route and metric value only present on R2 for IPv4 and IPv6 default routes "
1392 result
= verify_rib_default_route(
1396 routes
=DEFAULT_ROUTES
,
1397 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1399 expected_aspath
="4000",
1401 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1404 step("Delete metric value from IP4 and IPv6 route-map configured on R3 ")
1412 "set": {"metric": 50, "delete": True},
1417 "set": {"metric": 100, "delete": True},
1424 "set": {"metric": 50, "delete": True},
1429 "set": {"metric": 100, "delete": True},
1436 result
= create_route_maps(tgen
, route_map
)
1437 assert result
is True, "Test case {} : Failed \n Error: {}".format(tc_name
, result
)
1440 "Verify Metric value deleted from IPv4 and IPv6 default route on R2 ,verify default routes "
1445 result
= verify_rib_default_route(
1449 routes
=DEFAULT_ROUTES
,
1450 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1452 expected_aspath
="4000",
1455 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1456 step("Change IPv4 and IPv6 , EBGP to IBGP neighbor between R3 and R2")
1457 step("Change IPv4 and IPv6 IBGP to EBGP neighbor between R3 and R4")
1458 r0_local_as
= topo
['routers']['r0']['bgp']['local_as']
1459 r1_local_as
= topo
['routers']['r1']['bgp']['local_as']
1460 r2_local_as
= topo
['routers']['r2']['bgp']['local_as']
1461 r3_local_as
= topo
['routers']['r3']['bgp']['local_as']
1462 r4_local_as
= topo
['routers']['r4']['bgp']['local_as']
1466 "local_as": r0_local_as
,
1471 "local_as": r1_local_as
,
1491 result
= modify_as_number(tgen
, topo
, input_dict
)
1493 assert result
is True
1494 except AssertionError:
1495 logger
.info("Expected behaviour: {}".format(result
))
1496 logger
.info("BGP config is not created because of invalid ASNs")
1497 step("After changing the BGP AS Path Verify the BGP Convergence")
1498 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
1499 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
1503 "Configure one IPv4 and one IPv6, Static route on R4 with next-hop as Null0 IPv4 route Sv41, IPv6 route Sv61 "
1505 for addr_type
in ADDR_TYPES
:
1506 static_routes_input
= {
1510 "network": [NETWORK1_1
[addr_type
]],
1511 "next_hop": NEXT_HOP_IP
[addr_type
],
1516 result
= create_static_routes(tgen
, static_routes_input
)
1517 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1520 step("Verify IPv4 and IPv6 static routes configured on R4 in FIB")
1521 for addr_type
in ADDR_TYPES
:
1522 static_routes_input
= {
1526 "network": [NETWORK1_1
[addr_type
]],
1527 "next_hop": NEXT_HOP_IP
[addr_type
],
1532 result
= verify_fib_routes(tgen
, addr_type
, "r4", static_routes_input
)
1533 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1538 "Configure redistribute static knob on R4 , for R4 to R3 neighbor for IPv4 and IPv6 address family "
1540 redistribute_static
= {
1544 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1545 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1550 result
= create_router_bgp(tgen
, topo
, redistribute_static
)
1551 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1554 "Verify After configuring redistribute static , verify route received in BGP table of R3"
1556 for addr_type
in ADDR_TYPES
:
1557 static_routes_input
= {
1561 "network": [NETWORK1_1
[addr_type
]],
1562 "next_hop": NEXT_HOP_IP
[addr_type
],
1567 result
= verify_fib_routes(tgen
, addr_type
, "r3", static_routes_input
)
1568 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1572 result
= verify_bgp_rib(tgen
, addr_type
, "r3", static_routes_input
)
1573 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1577 " Configure default-originate with IPv4 and IPv6 route-map on R3 for R3-R2 IPv4 and IPv6 BGP neighbor"
1579 local_as
= get_dut_as_number(tgen
, dut
="r3")
1580 default_originate_config
= {
1583 "local_as": local_as
,
1586 "unicast": {"default_originate": {"r2": {"route_map": "RMv4"}}}
1589 "unicast": {"default_originate": {"r2": {"route_map": "RMv6"}}}
1595 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
1596 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1599 "Verify IPv4 and IPv6 default route received on R2 with both the AS path on R2"
1601 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1602 result
= verify_rib_default_route(
1606 routes
=DEFAULT_ROUTES
,
1607 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1609 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1612 "Configure local -preference to 50 on IPv4 and IPv6 route map seq1 and 60 on seq2"
1653 result
= create_route_maps(tgen
, route_map
)
1654 assert result
is True, "Test case {} : Failed \n Error: {}".format(tc_name
, result
)
1657 "Verify Configured metric value received on R2 along with as-path for IPv4 and IPv6 default routes "
1662 result
= verify_rib_default_route(
1666 routes
=DEFAULT_ROUTES
,
1667 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1672 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1675 "Modify local preference value to 150 on IPv4 and IPv6 route map seq1 and 160 on seq2"
1716 result
= create_route_maps(tgen
, route_map
)
1717 assert result
is True, "Test case {} : Failed \n Error: {}".format(tc_name
, result
)
1720 "Verify Modified local-preference value received on R2 for IPv4 and IPv6 default routes "
1726 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "::/0"}
1727 result
= verify_rib_default_route(
1731 routes
=DEFAULT_ROUTES
,
1732 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1736 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1737 # updating the topology with the updated AS-Number to avoid conflict in con configuring the AS
1739 updated_topo
['routers']['r0']['bgp']['local_as']=get_dut_as_number(tgen
,"r0")
1740 updated_topo
['routers']['r1']['bgp']['local_as']=get_dut_as_number(tgen
,"r1")
1741 updated_topo
['routers']['r2']['bgp']['local_as']=get_dut_as_number(tgen
,"r2")
1742 updated_topo
['routers']['r3']['bgp']['local_as']=get_dut_as_number(tgen
,"r3")
1743 updated_topo
['routers']['r4']['bgp']['local_as']=get_dut_as_number(tgen
,"r4")
1745 step("Shut IPv4/IPv6 BGP neighbor from R4 ( R4-R3) using 'neighbor x.x.x.x shut' command ")
1746 local_as
= get_dut_as_number(tgen
, dut
="r4")
1750 "local_as": local_as
,
1757 "r4": {"shutdown":True}
1768 "r4": {"shutdown":True}
1778 result
= create_router_bgp(tgen
, updated_topo
, shut_neighbor
)
1779 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1781 interface
= topo
['routers']['r3']['links']['r4']['interface']
1784 "interface_list": [interface
],
1789 result
= interface_status(tgen
, topo
, input_dict
)
1790 assert result
is True, "Testcase {} : Shut down the interface failed ! \n Error: {}".format(tc_name
, result
)
1792 step("After shutting the interface verify the BGP convergence")
1793 result
= verify_bgp_convergence(tgen
,topo
,expected
=False)
1794 assert result
is not True, "Testcase {} : Failed \n After shutting Down BGP convergence should Fail and return False \n Error: {}".format(tc_name
, result
)
1796 step("verify default route deleted from R2 ")
1797 result
= verify_rib_default_route(
1801 routes
=DEFAULT_ROUTES
,
1802 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1804 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
)
1806 result
= verify_fib_default_route(
1810 routes
=DEFAULT_ROUTES
,
1811 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1813 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
)
1816 step("no Shut IPv4/IPv6 BGP neighbor from R4 ( R4-R3) using 'neighbor x.x.x.x shut' command ")
1817 local_as
= get_dut_as_number(tgen
, dut
="r4")
1821 "local_as": local_as
,
1828 "r4": {"shutdown":False}
1839 "r4": {"shutdown":False}
1849 result
= create_router_bgp(tgen
, updated_topo
, shut_neighbor
)
1850 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1852 interface
= topo
['routers']['r3']['links']['r4']['interface']
1855 "interface_list": [interface
],
1860 result
= interface_status(tgen
, topo
, input_dict
)
1861 assert result
is True, "Testcase {} : Bring up interface failed ! \n Error: {}".format(tc_name
, result
)
1863 step("After no shutting the interface verify the BGP convergence")
1864 result
= verify_bgp_convergence(tgen
,topo
,expected
=True)
1865 assert result
is True, "Testcase {} : Failed \n After shutting Down BGP convergence should Fail and return False \n Error: {}".format(tc_name
, result
)
1867 step("After no shut neighbor , verify default route relearn on R2")
1868 result
= verify_rib_default_route(
1872 routes
=DEFAULT_ROUTES
,
1873 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1875 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
)
1877 result
= verify_fib_default_route(
1881 routes
=DEFAULT_ROUTES
,
1882 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1884 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
)
1888 step("Remove IPv4/IPv6 static route configure on R4")
1889 for addr_type
in ADDR_TYPES
:
1890 static_routes_input
= {
1894 "network": [NETWORK1_1
[addr_type
]],
1895 "next_hop": NEXT_HOP_IP
[addr_type
],
1901 result
= create_static_routes(tgen
, static_routes_input
)
1902 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1905 step("Verify IPv4 and IPv6 static routes removed on R4 in FIB")
1906 for addr_type
in ADDR_TYPES
:
1907 static_routes_input
= {
1911 "network": [NETWORK1_1
[addr_type
]],
1912 "next_hop": NEXT_HOP_IP
[addr_type
],
1917 result
= verify_fib_routes(tgen
, addr_type
, "r4", static_routes_input
, expected
=False)
1918 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
1921 result
= verify_bgp_rib(tgen
, addr_type
, "r4", static_routes_input
, expected
=False)
1922 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
1926 step("After removing static route , verify default route removed on R2")
1927 result
= verify_rib_default_route(
1931 routes
=DEFAULT_ROUTES
,
1932 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1934 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
)
1936 result
= verify_fib_default_route(
1940 routes
=DEFAULT_ROUTES
,
1941 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1943 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
)
1946 step("Configuring the static route back in r4")
1947 for addr_type
in ADDR_TYPES
:
1948 static_routes_input
= {
1952 "network": [NETWORK1_1
[addr_type
]],
1953 "next_hop": NEXT_HOP_IP
[addr_type
],
1958 result
= create_static_routes(tgen
, static_routes_input
)
1959 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1962 step("Verify IPv4 and IPv6 static routes configured on R4 in FIB")
1963 for addr_type
in ADDR_TYPES
:
1964 static_routes_input
= {
1968 "network": [NETWORK1_1
[addr_type
]],
1969 "next_hop": NEXT_HOP_IP
[addr_type
],
1974 result
= verify_fib_routes(tgen
, addr_type
, "r4", static_routes_input
, expected
=True)
1975 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1978 result
= verify_bgp_rib(tgen
, addr_type
, "r4", static_routes_input
, expected
=True)
1979 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1983 step("After adding static route back , verify default route learned on R2")
1984 result
= verify_rib_default_route(
1988 routes
=DEFAULT_ROUTES
,
1989 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1991 assert result
is True, "Testcase {} : Failed \n Error: After removing static the default route is expected but found in RIB -> {}".format( tc_name
, result
)
1993 result
= verify_fib_default_route(
1997 routes
=DEFAULT_ROUTES
,
1998 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
2000 assert result
is True, "Testcase {} : Failed \n Error: After removing static the default route is expected but found in FIB -> {}".format( tc_name
, result
)
2002 step("Deactivate IPv4 and IPv6 neighbor configured from R4 ( R4-R3)")
2004 configure_bgp_on_r1
= {
2011 "r3": {"dest_link": {"r4": {"deactivate": "ipv4"}}}
2018 "r3": {"dest_link": {"r4": {"deactivate": "ipv6"}}}
2027 result
= create_router_bgp(tgen
, updated_topo
, configure_bgp_on_r1
)
2028 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2030 step("After deactivating the BGP neighbor , verify default route removed on R2")
2031 result
= verify_rib_default_route(
2035 routes
=DEFAULT_ROUTES
,
2036 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
2038 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
)
2040 result
= verify_fib_default_route(
2044 routes
=DEFAULT_ROUTES
,
2045 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
2047 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
)
2049 step("Activate IPv4 and IPv6 neighbor configured from R4 ( R4-R3)")
2051 configure_bgp_on_r1
= {
2058 "r3": {"dest_link": {"r4": {"activate": "ipv4"}}}
2065 "r3": {"dest_link": {"r4": {"activate": "ipv6"}}}
2074 result
= create_router_bgp(tgen
, updated_topo
, configure_bgp_on_r1
)
2075 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2077 step("Verify bgp convergence.")
2078 bgp_convergence
= verify_bgp_convergence(tgen
, updated_topo
)
2079 assert bgp_convergence
is True, "Testcase {} : Failed \n Error: {}".format(
2080 tc_name
, bgp_convergence
2082 step("After Activating the BGP neighbor , verify default route learned on R2")
2083 result
= verify_rib_default_route(
2087 routes
=DEFAULT_ROUTES
,
2088 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
2090 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
)
2092 result
= verify_fib_default_route(
2096 routes
=DEFAULT_ROUTES
,
2097 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
2099 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
)
2100 write_test_footer(tc_name
)
2102 if __name__
== "__main__":
2103 args
= ["-s"] + sys
.argv
[1:]
2104 sys
.exit(pytest
.main(args
))