2 # SPDX-License-Identifier: ISC
4 # Copyright (c) 2022 by VMware, Inc. ("VMware")
5 # Shreenidhi A R <rshreenidhi@vmware.com>
6 # Used Copyright (c) 2018 by Network Device Education Foundation, Inc. ("NetDEF")
10 Following scenerios are covered.
11 1. When there is change in route-map policy associated with default-originate, changes does not reflect.
12 2. When route-map associated with default-originate is deleted, default route doesn't get withdrawn
13 3. Update message is not being sent when only route-map is removed from the default-originate config.
14 4. SNT counter gets incremented on change of every policy associated with default-originate
15 5. Route-map with multiple match clauses causes inconsistencies with default-originate.
16 6. BGP-Default originate behaviour with BGP attributes
22 from copy
import deepcopy
23 from lib
.topolog
import logger
25 # pylint: disable=C0413
26 # Import topogen and topotest helpers
27 from lib
.topogen
import Topogen
, get_topogen
28 from lib
.topojson
import build_config_from_json
29 from lib
.topolog
import logger
32 verify_bgp_convergence
,
34 get_prefix_count_route
,
38 verify_rib_default_route
,
39 verify_fib_default_route
,
41 from lib
.common_config
import (
44 required_linux_kernel_version
,
48 get_frr_ipv6_linklocal
,
54 reset_config_on_routers
,
60 # Save the Current Working Directory to find configuration files.
61 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
62 sys
.path
.append(os
.path
.join(CWD
, "../"))
63 sys
.path
.append(os
.path
.join(CWD
, "../lib/"))
65 pytestmark
= [pytest
.mark
.bgpd
, pytest
.mark
.staticd
]
67 # Required to instantiate the topology builder class.
69 # pylint: disable=C0413
70 # Import topogen and topotest helpers
74 NETWORK1_1
= {"ipv4": "198.51.1.1/32", "ipv6": "2001:DB8::1:1/128"}
75 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
76 NEXT_HOP_IP
= {"ipv4": "Null0", "ipv6": "Null0"}
78 def setup_module(mod
):
80 Sets up the pytest environment
85 # Required linux kernel version for this suite to run.
86 result
= required_linux_kernel_version("4.15")
87 if result
is not True:
88 pytest
.skip("Kernel requirements are not met")
90 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
91 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
94 logger
.info("Running setup_module to create topology")
96 # This function initiates the topology build with Topogen...
97 json_file
= "{}/bgp_default_originate_topo1.json".format(CWD
)
98 tgen
= Topogen(json_file
, mod
.__name
__)
100 topo
= tgen
.json_topo
101 # ... and here it calls Mininet initialization functions.
103 # Starting topology, create tmp files which are loaded to routers
104 # to start daemons and then start routers
107 # Creating configuration from JSON
108 build_config_from_json(tgen
, topo
)
111 global BGP_CONVERGENCE
112 global DEFAULT_ROUTES
113 global DEFAULT_ROUTE_NXT_HOP_R1
, DEFAULT_ROUTE_NXT_HOP_R3
114 ADDR_TYPES
= check_address_types()
115 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
116 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
120 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
122 interface
= topo
["routers"]["r1"]["links"]["r2"]["interface"]
123 ipv6_link_local
= get_frr_ipv6_linklocal(tgen
, "r1", intf
=interface
)
124 ipv4_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"]["ipv4"].split("/")[0]
125 ipv6_nxt_hop
= topo
["routers"]["r1"]["links"]["r2"]["ipv6"].split("/")[0]
126 DEFAULT_ROUTE_NXT_HOP_R1
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local
}
128 interface
= topo
["routers"]["r3"]["links"]["r2"]["interface"]
129 ipv6_link_local
= get_frr_ipv6_linklocal(tgen
, "r3", intf
=interface
)
130 ipv4_nxt_hop
= topo
["routers"]["r3"]["links"]["r2"]["ipv4"].split("/")[0]
131 ipv6_nxt_hop
= topo
["routers"]["r3"]["links"]["r2"]["ipv6"].split("/")[0]
132 DEFAULT_ROUTE_NXT_HOP_R3
= {"ipv4": ipv4_nxt_hop
, "ipv6": ipv6_link_local
}
134 logger
.info("Running setup_module() done")
137 def teardown_module():
138 """Teardown the pytest environment"""
140 logger
.info("Running teardown_module to delete topology")
144 # Stop toplogy and Remove tmp files
148 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
150 logger
.info("=" * 40)
153 #####################################################
157 #####################################################
160 def test_default_originate_delete_conditional_routemap(request
):
163 1. When there is change in route-map policy associated with default-originate, changes does not reflect.
164 2. When route-map associated with default-originate is deleted, default route doesn't get withdrawn
165 3. Update message is not being sent when only route-map is removed from the default-originate config.
166 4. SNT counter gets incremented on change of every policy associated with default-originate
167 5. Route-map with multiple match clauses causes inconsistencies with default-originate.
170 global BGP_CONVERGENCE
172 tc_name
= request
.node
.name
173 write_test_header(tc_name
)
175 if tgen
.routers_have_failure():
176 check_router_status(tgen
)
177 reset_config_on_routers(tgen
)
179 if BGP_CONVERGENCE
!= True:
180 pytest
.skip("skipped because of BGP Convergence failure")
182 step("Configure IPv4 and IPv6 , IBGP neighbor between R1 and R2")
183 step("Configure IPv4 and IPv6 , EBGP neighbor between R1 and R0")
211 result
= modify_as_number(tgen
, topo
, input_dict
)
213 assert result
is True
214 except AssertionError:
215 logger
.info("Expected behaviour: {}".format(result
))
216 logger
.info("BGP config is not created because of invalid ASNs")
218 step("After changing the BGP remote as , Verify the BGP Convergence")
219 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
221 BGP_CONVERGENCE
is True
222 ), "Complete convergence is expected after changing ASN ....! ERROR :Failed \n Error: {}".format(
226 step("Configure 1 IPv4 and 1 IPv6 Static route on R0 with next-hop as Null0")
227 for addr_type
in ADDR_TYPES
:
228 static_routes_input
= {
232 "network": [NETWORK1_1
[addr_type
]],
233 "next_hop": NEXT_HOP_IP
[addr_type
],
238 result
= create_static_routes(tgen
, static_routes_input
)
241 ), "Testcase {} : Failed to configure the static route \n Error: {}".format(
245 step("verify IPv4 and IPv6 static route are configured and up on R0")
246 for addr_type
in ADDR_TYPES
:
247 static_routes_input
= {
251 "network": [NETWORK1_1
[addr_type
]],
252 "next_hop": NEXT_HOP_IP
[addr_type
],
257 result
= verify_fib_routes(tgen
, addr_type
, "r0", static_routes_input
)
260 ), "Testcase {} : routes {} not found in R0 FIB \n Error: {}".format(
261 tc_name
, static_routes_input
, result
265 "Configure redistribute static on IPv4 and IPv6 address family on R0 for R0 to R1 neighbor "
267 redistribute_static
= {
271 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
272 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
277 result
= create_router_bgp(tgen
, topo
, redistribute_static
)
280 ), "Testcase {} : Failed to configure redistribute configuration....! \n Error: {}".format(
284 step("verify IPv4 and IPv6 static route are received on R1")
285 for addr_type
in ADDR_TYPES
:
286 static_routes_input
= {
290 "network": [NETWORK1_1
[addr_type
]],
291 "next_hop": NEXT_HOP_IP
[addr_type
],
296 result
= verify_fib_routes(tgen
, addr_type
, "r1", static_routes_input
)
299 ), "Testcase {} : Failed... Routes {} expected in r1 FIB after configuring the redistribute config on R0 \n Error: {}".format(
300 tc_name
, static_routes_input
, result
303 result
= verify_bgp_rib(tgen
, addr_type
, "r1", static_routes_input
)
306 ), "Testcase {} : Failed... Routes {} expected in r1 RIB after configuring the redistribute config on R0\n Error: {}".format(
307 tc_name
, static_routes_input
, result
311 "Configure IPv4 prefix-list 'Pv4' and and IPv6 prefix-list 'Pv6' on R1 to match BGP route Sv41, IPv6 route Sv61 permit "
320 "network": NETWORK1_1
["ipv4"],
329 "network": NETWORK1_1
["ipv6"],
337 result
= create_prefix_lists(tgen
, input_dict_3
)
340 ), "Testcase {} : Failed to configure the prefix list \n Error: {}".format(
345 "Configure IPV4 and IPv6 route-map (RMv4 and RMv6) matching prefix-list (Pv4 and Pv6) respectively on R1"
354 "match": {"ipv4": {"prefix_lists": "Pv4"}},
358 "as_action": "prepend",
367 "match": {"ipv6": {"prefix_lists": "Pv6"}},
371 "as_action": "prepend",
379 result
= create_route_maps(tgen
, input_dict_3
)
382 ), "Testcase {} : Failed to configure the route map \n Error: {}".format(
387 "Configure default-originate with route-map (RMv4 and RMv6) on R1, on BGP IPv4 and IPv6 address family "
389 local_as
= get_dut_as_number(tgen
, dut
="r1")
390 default_originate_config
= {
393 "local_as": local_as
,
396 "unicast": {"default_originate": {"r2": {"route_map": "RMv4"}}}
399 "unicast": {"default_originate": {"r2": {"route_map": "RMv6"}}}
405 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
408 ), "Testcase {} : Failed to configure the default originate \n Error: {}".format(
413 "After configuring default-originate command , verify default routes are advertised on R2 "
415 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
416 result
= verify_rib_default_route(
420 routes
=DEFAULT_ROUTES
,
421 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
423 expected_aspath
="5555",
427 ), "Testcase {} : Failed to configure the default originate \n Error: {}".format(
431 result
= verify_fib_default_route(
435 routes
=DEFAULT_ROUTES
,
436 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
441 ), "Testcase {} : Failed to configure the default originate \n Error: {}".format(
445 step("Changing the as-path policy of the existing route-map")
453 "match": {"ipv4": {"prefix_lists": "Pv4"}},
457 "as_action": "prepend",
466 "match": {"ipv6": {"prefix_lists": "Pv6"}},
470 "as_action": "prepend",
478 result
= create_route_maps(tgen
, input_dict_3
)
481 ), "Testcase {} : Failed to configure the route map \n Error: {}".format(
486 "Verify prefix sent count on R1 towards R2 \n Send count shoud not be incremented on change of existing (AS-path) policy "
488 snapshot
= get_prefix_count_route(
489 tgen
, topo
, dut
="r1", peer
="r2", link
="r1", sent
=True, received
=False
492 ipv4_prefix_count
= False
493 ipv6_prefix_count
= False
494 if snapshot
["ipv4_count"] == 2:
495 ipv4_prefix_count
= True
496 if snapshot
["ipv6_count"] == 2:
497 ipv6_prefix_count
= True
500 ipv4_prefix_count
is True
501 ), "Testcase {} : Failed Error: Expected sent Prefix is 2 but obtained {} ".format(
502 tc_name
, ipv4_prefix_count
505 ipv6_prefix_count
is True
506 ), "Testcase {} : Failed Error: Expected sent Prefix is 2 but obtained {} ".format(
507 tc_name
, ipv6_prefix_count
511 "After changing the as-path policy verify the new policy is advertised to router R2"
513 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
514 result
= verify_rib_default_route(
518 routes
=DEFAULT_ROUTES
,
519 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
521 expected_aspath
="6666",
525 ), "Testcase {} : Default route with expected attributes is not found in BGP RIB \n Error: {}".format(
529 result
= verify_fib_default_route(
533 routes
=DEFAULT_ROUTES
,
534 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
539 ), "Testcase {} : Default route with expected attributes is not found in BGP FIB \n Error: {}".format(
543 step("Remove the as-path policy from the route-map")
551 "match": {"ipv4": {"prefix_lists": "Pv4"}},
555 "as_action": "prepend",
565 "match": {"ipv6": {"prefix_lists": "Pv6"}},
569 "as_action": "prepend",
578 result
= create_route_maps(tgen
, input_dict_3
)
581 ), "Testcase {} : Failed to configure the route map \n Error: {}".format(
586 "After removing the route policy (AS-Path) verify that as-path is removed in r2 "
588 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
590 result
= verify_rib_default_route(
594 routes
=DEFAULT_ROUTES
,
595 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
597 assert result
is True, "Testcase {} : Failed ... ! \n Error: {}".format(
601 result
= verify_fib_default_route(
605 routes
=DEFAULT_ROUTES
,
606 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
609 assert result
is True, "Testcase {} : Failed .... !\n Error: {}".format(
613 step("Delete the route-map ")
615 delete_routemap
= {"r1": {"route_maps": ["RMv4", "RMv6"]}}
616 result
= delete_route_maps(tgen
, delete_routemap
)
619 ), "Testcase {} : Failed to delete the route-map\n Error: {}".format(
624 "After deleting route-map , verify the default route in FIB and RIB are removed "
626 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
627 result
= verify_rib_default_route(
631 routes
=DEFAULT_ROUTES
,
632 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
638 ), "Testcase {} : After removing the route-map the default-route is not removed from R2 RIB\n Error: {}".format(
642 result
= verify_fib_default_route(
646 routes
=DEFAULT_ROUTES
,
647 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
652 ), "Testcase {} : After removing the route-map the default-route is not removed from R2 FIB \n Error: {}".format(
656 step("Create route-map with with sequnce number 10 ")
664 "match": {"ipv4": {"prefix_lists": "Pv4"}},
668 "as_action": "prepend",
677 "match": {"ipv6": {"prefix_lists": "Pv6"}},
681 "as_action": "prepend",
689 result
= create_route_maps(tgen
, input_dict_3
)
692 ), "Testcase {} : Failed to configure the route map \n Error: {}".format(
697 "After Configuring the route-map the dut is expected to receive the route policy (as-path) as 99999"
699 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
700 result
= verify_rib_default_route(
704 routes
=DEFAULT_ROUTES
,
705 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
707 expected_aspath
="9999",
709 assert result
is True, "Testcase {} : Failed...! \n Error: {}".format(
713 result
= verify_fib_default_route(
717 routes
=DEFAULT_ROUTES
,
718 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
721 assert result
is True, "Testcase {} : Failed ...!\n Error: {}".format(
725 step("Create another route-map with seq number less than the previous i. <10 ")
733 "match": {"ipv4": {"prefix_lists": "Pv4"}},
737 "as_action": "prepend",
746 "match": {"ipv6": {"prefix_lists": "Pv6"}},
750 "as_action": "prepend",
758 result
= create_route_maps(tgen
, input_dict_3
)
761 ), "Testcase {} : Failed to configure the route map \n Error: {}".format(
766 "On creating new route-map the route-map with lower seq id should be considered "
768 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
769 result
= verify_rib_default_route(
773 routes
=DEFAULT_ROUTES
,
774 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
776 expected_aspath
="7777",
780 ), "Testcase {} : Route-map with lowest prefix is not considered \n Error: {}".format(
784 result
= verify_fib_default_route(
788 routes
=DEFAULT_ROUTES
,
789 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R1
,
794 ), "Testcase {} : Route-map with lowest prefix is not considered \n Error: {}".format(
798 write_test_footer(tc_name
)
801 def test_verify_default_originate_after_BGP_attributes_p1(request
):
803 "Verify different BGP attributes with default-originate route "
806 global BGP_CONVERGENCE
809 tc_name
= request
.node
.name
810 write_test_header(tc_name
)
811 # Don't run this test if we have any failure.
812 if tgen
.routers_have_failure():
813 check_router_status(tgen
)
814 reset_config_on_routers(tgen
)
816 if BGP_CONVERGENCE
!= True:
817 pytest
.skip("skipped because of BGP Convergence failure")
819 step("Configure IPv4 and IPv6 , EBGP neighbor between R3 and R2")
820 step("Configure IPv4 and IPv6 IBGP neighbor between R3 and R4")
821 r0_local_as
= topo
['routers']['r0']['bgp']['local_as']
822 r1_local_as
= topo
['routers']['r1']['bgp']['local_as']
823 r2_local_as
= topo
['routers']['r2']['bgp']['local_as']
824 r3_local_as
= topo
['routers']['r3']['bgp']['local_as']
825 r4_local_as
= topo
['routers']['r4']['bgp']['local_as']
829 "local_as": r0_local_as
,
834 "local_as": r1_local_as
,
839 "local_as": r2_local_as
,
853 result
= modify_as_number(tgen
, topo
, input_dict
)
856 assert result
is True
857 except AssertionError:
858 logger
.info("Expected behaviour: {}".format(result
))
859 logger
.info("BGP config is not created because of invalid ASNs")
860 step("After changing the BGP AS Path Verify the BGP Convergence")
862 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
863 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
868 "Configure one IPv4 and one IPv6, Static route on R4 with next-hop as Null0 IPv4 route Sv41, IPv6 route Sv61 "
870 for addr_type
in ADDR_TYPES
:
871 static_routes_input
= {
875 "network": [NETWORK1_1
[addr_type
]],
876 "next_hop": NEXT_HOP_IP
[addr_type
],
881 result
= create_static_routes(tgen
, static_routes_input
)
882 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
885 step("Verify IPv4 and IPv6 static routes configured on R4 in FIB")
886 for addr_type
in ADDR_TYPES
:
887 static_routes_input
= {
891 "network": [NETWORK1_1
[addr_type
]],
892 "next_hop": NEXT_HOP_IP
[addr_type
],
897 result
= verify_fib_routes(tgen
, addr_type
, "r4", static_routes_input
)
898 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
903 "Configure redistribute static knob on R4 , for R4 to R3 neighbor for IPv4 and IPv6 address family "
905 redistribute_static
= {
909 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
910 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
915 result
= create_router_bgp(tgen
, topo
, redistribute_static
)
916 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
919 "Verify After configuring redistribute static , verify route received in BGP table of R3"
921 for addr_type
in ADDR_TYPES
:
922 static_routes_input
= {
926 "network": [NETWORK1_1
[addr_type
]],
927 "next_hop": NEXT_HOP_IP
[addr_type
],
932 result
= verify_fib_routes(tgen
, addr_type
, "r3", static_routes_input
)
933 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
937 result
= verify_bgp_rib(tgen
, addr_type
, "r3", static_routes_input
)
938 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
942 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"""
951 "network": NETWORK1_1
["ipv4"],
956 {"seqid": "1", "network": "200.1.1.1/24", "action": "permit"}
963 "network": NETWORK1_1
["ipv6"],
968 {"seqid": " 1", "network": "200::1/64", "action": "permit"}
974 result
= create_prefix_lists(tgen
, input_dict_3
)
975 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
977 step("verify IPv4 and IPv6 Prefix list got configured on R3")
978 input_dict
= {"r3": {"prefix_lists": ["Pv41", "Pv61", "Pv42", "Pv62"]}}
979 result
= verify_prefix_lists(tgen
, input_dict
)
980 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
983 "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"
992 "match": {"ipv4": {"prefix_lists": "Pv41"}},
997 "match": {"ipv4": {"prefix_lists": "Pv42"}},
1004 "match": {"ipv6": {"prefix_lists": "Pv61"}},
1009 "match": {"ipv6": {"prefix_lists": "Pv62"}},
1015 result
= create_route_maps(tgen
, input_dict_3
)
1016 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1019 "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 "
1031 "as_action": "prepend",
1042 "as_action": "prepend",
1054 "as_action": "prepend",
1064 "as_action": "prepend",
1073 result
= create_route_maps(tgen
, route_map
)
1074 assert result
is True, "Test case {} : Failed \n Error: {}".format(tc_name
, result
)
1077 " Configure default-originate with IPv4 and IPv6 route-map on R3 for R3-R2 IPv4 and IPv6 BGP neighbor"
1080 local_as
= get_dut_as_number(tgen
, dut
="r3")
1081 default_originate_config
= {
1084 "local_as": local_as
,
1087 "unicast": {"default_originate": {"r2": {"route_map": "RMv4"}}}
1090 "unicast": {"default_originate": {"r2": {"route_map": "RMv6"}}}
1096 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
1097 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1100 "Verify IPv4 and IPv6 default route received on R2 with both the AS path on R2"
1102 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1104 result
= verify_rib_default_route(
1108 routes
=DEFAULT_ROUTES
,
1109 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1111 expected_aspath
="4000 200",
1115 "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"
1127 "as_action": "prepend",
1138 "as_action": "prepend",
1150 "as_action": "prepend",
1160 "as_action": "prepend",
1169 result
= create_route_maps(tgen
, route_map
)
1170 assert result
is True, "Test case {} : Failed \n Error: {}".format(tc_name
, result
)
1171 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1174 step("As path 500 added to IPv4 and IPv6 default -originate route received on R2")
1175 result
= verify_rib_default_route(
1179 routes
=DEFAULT_ROUTES
,
1180 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1182 expected_aspath
="4000 500",
1184 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1187 "Apply on route-map seq1 set metric value to 70 and route-map seq2 set metric 80 IPv4 and IPv6 route-map"
1228 result
= create_route_maps(tgen
, route_map
)
1229 assert result
is True, "Test case {} : Failed \n Error: {}".format(tc_name
, result
)
1232 "Verify Configured metric value received on R2 along with as-path for IPv4 and IPv6 default routes "
1236 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "::/0"}
1237 result
= verify_rib_default_route(
1241 routes
=DEFAULT_ROUTES
,
1242 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1244 expected_aspath
="4000 500",
1249 "Modify route-map seq1 configure metric 50 and route-map seq2 configure metric 100 IPv4 and IPv6 route-map "
1290 result
= create_route_maps(tgen
, route_map
)
1291 assert result
is True, "Test case {} : Failed \n Error: {}".format(tc_name
, result
)
1294 "Verify Configured metric value received on R2 along with as-path for IPv4 and IPv6 default routes "
1298 result
= verify_rib_default_route(
1302 routes
=DEFAULT_ROUTES
,
1303 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1305 expected_aspath
="4000 500",
1307 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1309 step("Delete AS-prepend from IP4 and IPv6 route-map configured on R3 ")
1321 "as_action": "prepend",
1333 "as_action": "prepend",
1347 "as_action": "prepend",
1359 "as_action": "prepend",
1370 result
= create_route_maps(tgen
, route_map
)
1371 assert result
is True, "Test case {} : Failed \n Error: {}".format(tc_name
, result
)
1374 "Verify AS-prepend is deleted from default originate route and metric value only present on R2 for IPv4 and IPv6 default routes "
1380 result
= verify_rib_default_route(
1384 routes
=DEFAULT_ROUTES
,
1385 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1387 expected_aspath
="4000",
1389 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1392 step("Delete metric value from IP4 and IPv6 route-map configured on R3 ")
1400 "set": {"metric": 50, "delete": True},
1405 "set": {"metric": 100, "delete": True},
1412 "set": {"metric": 50, "delete": True},
1417 "set": {"metric": 100, "delete": True},
1424 result
= create_route_maps(tgen
, route_map
)
1425 assert result
is True, "Test case {} : Failed \n Error: {}".format(tc_name
, result
)
1428 "Verify Metric value deleted from IPv4 and IPv6 default route on R2 ,verify default routes "
1433 result
= verify_rib_default_route(
1437 routes
=DEFAULT_ROUTES
,
1438 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1440 expected_aspath
="4000",
1443 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1444 step("Change IPv4 and IPv6 , EBGP to IBGP neighbor between R3 and R2")
1445 step("Change IPv4 and IPv6 IBGP to EBGP neighbor between R3 and R4")
1446 r0_local_as
= topo
['routers']['r0']['bgp']['local_as']
1447 r1_local_as
= topo
['routers']['r1']['bgp']['local_as']
1448 r2_local_as
= topo
['routers']['r2']['bgp']['local_as']
1449 r3_local_as
= topo
['routers']['r3']['bgp']['local_as']
1450 r4_local_as
= topo
['routers']['r4']['bgp']['local_as']
1454 "local_as": r0_local_as
,
1459 "local_as": r1_local_as
,
1479 result
= modify_as_number(tgen
, topo
, input_dict
)
1481 assert result
is True
1482 except AssertionError:
1483 logger
.info("Expected behaviour: {}".format(result
))
1484 logger
.info("BGP config is not created because of invalid ASNs")
1485 step("After changing the BGP AS Path Verify the BGP Convergence")
1486 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
1487 assert BGP_CONVERGENCE
is True, "setup_module :Failed \n Error: {}".format(
1491 "Configure one IPv4 and one IPv6, Static route on R4 with next-hop as Null0 IPv4 route Sv41, IPv6 route Sv61 "
1493 for addr_type
in ADDR_TYPES
:
1494 static_routes_input
= {
1498 "network": [NETWORK1_1
[addr_type
]],
1499 "next_hop": NEXT_HOP_IP
[addr_type
],
1504 result
= create_static_routes(tgen
, static_routes_input
)
1505 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1508 step("Verify IPv4 and IPv6 static routes configured on R4 in FIB")
1509 for addr_type
in ADDR_TYPES
:
1510 static_routes_input
= {
1514 "network": [NETWORK1_1
[addr_type
]],
1515 "next_hop": NEXT_HOP_IP
[addr_type
],
1520 result
= verify_fib_routes(tgen
, addr_type
, "r4", static_routes_input
)
1521 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1526 "Configure redistribute static knob on R4 , for R4 to R3 neighbor for IPv4 and IPv6 address family "
1528 redistribute_static
= {
1532 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1533 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1538 result
= create_router_bgp(tgen
, topo
, redistribute_static
)
1539 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1542 "Verify After configuring redistribute static , verify route received in BGP table of R3"
1544 for addr_type
in ADDR_TYPES
:
1545 static_routes_input
= {
1549 "network": [NETWORK1_1
[addr_type
]],
1550 "next_hop": NEXT_HOP_IP
[addr_type
],
1555 result
= verify_fib_routes(tgen
, addr_type
, "r3", static_routes_input
)
1556 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1560 result
= verify_bgp_rib(tgen
, addr_type
, "r3", static_routes_input
)
1561 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1565 " Configure default-originate with IPv4 and IPv6 route-map on R3 for R3-R2 IPv4 and IPv6 BGP neighbor"
1567 local_as
= get_dut_as_number(tgen
, dut
="r3")
1568 default_originate_config
= {
1571 "local_as": local_as
,
1574 "unicast": {"default_originate": {"r2": {"route_map": "RMv4"}}}
1577 "unicast": {"default_originate": {"r2": {"route_map": "RMv6"}}}
1583 result
= create_router_bgp(tgen
, topo
, default_originate_config
)
1584 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1587 "Verify IPv4 and IPv6 default route received on R2 with both the AS path on R2"
1589 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1590 result
= verify_rib_default_route(
1594 routes
=DEFAULT_ROUTES
,
1595 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1597 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1600 "Configure local -preference to 50 on IPv4 and IPv6 route map seq1 and 60 on seq2"
1641 result
= create_route_maps(tgen
, route_map
)
1642 assert result
is True, "Test case {} : Failed \n Error: {}".format(tc_name
, result
)
1645 "Verify Configured metric value received on R2 along with as-path for IPv4 and IPv6 default routes "
1650 result
= verify_rib_default_route(
1654 routes
=DEFAULT_ROUTES
,
1655 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1660 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1663 "Modify local preference value to 150 on IPv4 and IPv6 route map seq1 and 160 on seq2"
1704 result
= create_route_maps(tgen
, route_map
)
1705 assert result
is True, "Test case {} : Failed \n Error: {}".format(tc_name
, result
)
1708 "Verify Modified local-preference value received on R2 for IPv4 and IPv6 default routes "
1714 DEFAULT_ROUTES
= {"ipv4": "0.0.0.0/0", "ipv6": "::/0"}
1715 result
= verify_rib_default_route(
1719 routes
=DEFAULT_ROUTES
,
1720 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1724 assert result
is True, "Testcase {} : Failed Error: {}".format(tc_name
, result
)
1725 # updating the topology with the updated AS-Number to avoid conflict in con configuring the AS
1727 updated_topo
['routers']['r0']['bgp']['local_as']=get_dut_as_number(tgen
,"r0")
1728 updated_topo
['routers']['r1']['bgp']['local_as']=get_dut_as_number(tgen
,"r1")
1729 updated_topo
['routers']['r2']['bgp']['local_as']=get_dut_as_number(tgen
,"r2")
1730 updated_topo
['routers']['r3']['bgp']['local_as']=get_dut_as_number(tgen
,"r3")
1731 updated_topo
['routers']['r4']['bgp']['local_as']=get_dut_as_number(tgen
,"r4")
1733 step("Shut IPv4/IPv6 BGP neighbor from R4 ( R4-R3) using 'neighbor x.x.x.x shut' command ")
1734 local_as
= get_dut_as_number(tgen
, dut
="r4")
1738 "local_as": local_as
,
1745 "r4": {"shutdown":True}
1756 "r4": {"shutdown":True}
1766 result
= create_router_bgp(tgen
, updated_topo
, shut_neighbor
)
1767 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1769 interface
= topo
['routers']['r3']['links']['r4']['interface']
1772 "interface_list": [interface
],
1777 result
= interface_status(tgen
, topo
, input_dict
)
1778 assert result
is True, "Testcase {} : Shut down the interface failed ! \n Error: {}".format(tc_name
, result
)
1780 step("After shutting the interface verify the BGP convergence")
1781 result
= verify_bgp_convergence(tgen
,topo
,expected
=False)
1782 assert result
is not True, "Testcase {} : Failed \n After shutting Down BGP convergence should Fail and return False \n Error: {}".format(tc_name
, result
)
1784 step("verify default route deleted from R2 ")
1785 result
= verify_rib_default_route(
1789 routes
=DEFAULT_ROUTES
,
1790 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1792 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
)
1794 result
= verify_fib_default_route(
1798 routes
=DEFAULT_ROUTES
,
1799 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1801 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
)
1804 step("no Shut IPv4/IPv6 BGP neighbor from R4 ( R4-R3) using 'neighbor x.x.x.x shut' command ")
1805 local_as
= get_dut_as_number(tgen
, dut
="r4")
1809 "local_as": local_as
,
1816 "r4": {"shutdown":False}
1827 "r4": {"shutdown":False}
1837 result
= create_router_bgp(tgen
, updated_topo
, shut_neighbor
)
1838 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1840 interface
= topo
['routers']['r3']['links']['r4']['interface']
1843 "interface_list": [interface
],
1848 result
= interface_status(tgen
, topo
, input_dict
)
1849 assert result
is True, "Testcase {} : Bring up interface failed ! \n Error: {}".format(tc_name
, result
)
1851 step("After no shutting the interface verify the BGP convergence")
1852 result
= verify_bgp_convergence(tgen
,topo
,expected
=True)
1853 assert result
is True, "Testcase {} : Failed \n After shutting Down BGP convergence should Fail and return False \n Error: {}".format(tc_name
, result
)
1855 step("After no shut neighbor , verify default route relearn on R2")
1856 result
= verify_rib_default_route(
1860 routes
=DEFAULT_ROUTES
,
1861 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1863 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
)
1865 result
= verify_fib_default_route(
1869 routes
=DEFAULT_ROUTES
,
1870 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1872 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
)
1876 step("Remove IPv4/IPv6 static route configure on R4")
1877 for addr_type
in ADDR_TYPES
:
1878 static_routes_input
= {
1882 "network": [NETWORK1_1
[addr_type
]],
1883 "next_hop": NEXT_HOP_IP
[addr_type
],
1889 result
= create_static_routes(tgen
, static_routes_input
)
1890 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1893 step("Verify IPv4 and IPv6 static routes removed on R4 in FIB")
1894 for addr_type
in ADDR_TYPES
:
1895 static_routes_input
= {
1899 "network": [NETWORK1_1
[addr_type
]],
1900 "next_hop": NEXT_HOP_IP
[addr_type
],
1905 result
= verify_fib_routes(tgen
, addr_type
, "r4", static_routes_input
, expected
=False)
1906 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
1909 result
= verify_bgp_rib(tgen
, addr_type
, "r4", static_routes_input
, expected
=False)
1910 assert result
is not True, "Testcase {} : Failed \n Error: {}".format(
1914 step("After removing static route , verify default route removed on R2")
1915 result
= verify_rib_default_route(
1919 routes
=DEFAULT_ROUTES
,
1920 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1922 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
)
1924 result
= verify_fib_default_route(
1928 routes
=DEFAULT_ROUTES
,
1929 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1931 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
)
1934 step("Configuring the static route back in r4")
1935 for addr_type
in ADDR_TYPES
:
1936 static_routes_input
= {
1940 "network": [NETWORK1_1
[addr_type
]],
1941 "next_hop": NEXT_HOP_IP
[addr_type
],
1946 result
= create_static_routes(tgen
, static_routes_input
)
1947 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1950 step("Verify IPv4 and IPv6 static routes configured on R4 in FIB")
1951 for addr_type
in ADDR_TYPES
:
1952 static_routes_input
= {
1956 "network": [NETWORK1_1
[addr_type
]],
1957 "next_hop": NEXT_HOP_IP
[addr_type
],
1962 result
= verify_fib_routes(tgen
, addr_type
, "r4", static_routes_input
, expected
=True)
1963 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1966 result
= verify_bgp_rib(tgen
, addr_type
, "r4", static_routes_input
, expected
=True)
1967 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
1971 step("After adding static route back , verify default route learned on R2")
1972 result
= verify_rib_default_route(
1976 routes
=DEFAULT_ROUTES
,
1977 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1979 assert result
is True, "Testcase {} : Failed \n Error: After removing static the default route is expected but found in RIB -> {}".format( tc_name
, result
)
1981 result
= verify_fib_default_route(
1985 routes
=DEFAULT_ROUTES
,
1986 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
1988 assert result
is True, "Testcase {} : Failed \n Error: After removing static the default route is expected but found in FIB -> {}".format( tc_name
, result
)
1990 step("Deactivate IPv4 and IPv6 neighbor configured from R4 ( R4-R3)")
1992 configure_bgp_on_r1
= {
1999 "r3": {"dest_link": {"r4": {"deactivate": "ipv4"}}}
2006 "r3": {"dest_link": {"r4": {"deactivate": "ipv6"}}}
2015 result
= create_router_bgp(tgen
, updated_topo
, configure_bgp_on_r1
)
2016 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2018 step("After deactivating the BGP neighbor , verify default route removed on R2")
2019 result
= verify_rib_default_route(
2023 routes
=DEFAULT_ROUTES
,
2024 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
2026 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
)
2028 result
= verify_fib_default_route(
2032 routes
=DEFAULT_ROUTES
,
2033 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
2035 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
)
2037 step("Activate IPv4 and IPv6 neighbor configured from R4 ( R4-R3)")
2039 configure_bgp_on_r1
= {
2046 "r3": {"dest_link": {"r4": {"activate": "ipv4"}}}
2053 "r3": {"dest_link": {"r4": {"activate": "ipv6"}}}
2062 result
= create_router_bgp(tgen
, updated_topo
, configure_bgp_on_r1
)
2063 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
2065 step("Verify bgp convergence.")
2066 bgp_convergence
= verify_bgp_convergence(tgen
, updated_topo
)
2067 assert bgp_convergence
is True, "Testcase {} : Failed \n Error: {}".format(
2068 tc_name
, bgp_convergence
2070 step("After Activating the BGP neighbor , verify default route learned on R2")
2071 result
= verify_rib_default_route(
2075 routes
=DEFAULT_ROUTES
,
2076 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
2078 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
)
2080 result
= verify_fib_default_route(
2084 routes
=DEFAULT_ROUTES
,
2085 expected_nexthop
=DEFAULT_ROUTE_NXT_HOP_R3
,
2087 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
)
2088 write_test_footer(tc_name
)
2090 if __name__
== "__main__":
2091 args
= ["-s"] + sys
.argv
[1:]
2092 sys
.exit(pytest
.main(args
))