def config_router_additive(tgen, topo, tc_name): global CONFIG_ROUTER_ADDITIVE input_dict = { "r2": { "route_maps": { "LC2": [ { "action": "permit", "seq_id": "10", "set": { "large_community": { "num": LARGE_COMM["r2"], "action": "additive", }, "community": { "num": STANDARD_COMM["r2"], "action": "additive", }, }, } ] } } } step("Configuring LC2 with community attributes as additive") result = create_route_maps(tgen, input_dict) assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) # tgen.mininet_cli() CONFIG_ROUTER_ADDITIVE = True
def test_large_community_set(request): """ Verify if large community attribute can be configured only in correct canonical format. """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() # Don"t run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) # API call to modify router id # input_dict dictionary to be provided to configure route_map input_dict = { "r1": { "route_maps": { "LC1": [ { "action": "permit", "seq_id": "10", "set": { "large_community": {"num": LARGE_COMM["r1"]}, "community": {"num": STANDARD_COMM["r1"]}, }, } ] } } } step("Trying to set bgp communities") result = create_route_maps(tgen, input_dict) assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) write_test_footer(tc_name)
def test_verify_deleting_re_adding_route_map_with_iBGP_peers_p0(request): """ Verify graceful-shutdown functionality after deleting/re-adding route-map with iBGP peers """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() reset_config_on_routers(tgen) step("Done in base config: Configure base config as per the topology") step("Base config should be up, verify using BGP convergence") result = verify_bgp_convergence(tgen, topo) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) step("Done in base config: Advertise prefixes from R1") step("Verify BGP routes are received at R4 with best path from R3 to R1") for addr_type in ADDR_TYPES: dut = "r4" next_hop1 = next_hop_per_address_family(tgen, "r4", "r2", addr_type, NEXT_HOP_IP_1) next_hop2 = next_hop_per_address_family(tgen, "r4", "r3", addr_type, NEXT_HOP_IP_2) input_topo = {key: topo["routers"][key] for key in ["r1"]} result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop=[next_hop1, next_hop2]) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, addr_type, dut, input_topo, next_hop=[next_hop1, next_hop2]) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) step("On R1 configure:") step("Create standard bgp community-list to permit graceful-shutdown:") input_dict_1 = { "r1": { "bgp_community_lists": [{ "community_type": "standard", "action": "permit", "name": "GSHUT", "value": "graceful-shutdown", }] } } result = create_bgp_community_lists(tgen, input_dict_1) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) step("Create route-map to set community GSHUT in OUT direction") input_dict_2 = { "r1": { "route_maps": { "GSHUT-OUT": [{ "action": "permit", "seq_id": "10", "set": { "community": { "num": "graceful-shutdown" } }, }] } } } result = create_route_maps(tgen, input_dict_2) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) input_dict_3 = { "r1": { "bgp": { "address_family": { "ipv4": { "unicast": { "neighbor": { "r3": { "dest_link": { "r1": { "route_maps": [{ "name": "GSHUT-OUT", "direction": "out", }] } } } } } }, "ipv6": { "unicast": { "neighbor": { "r3": { "dest_link": { "r1": { "route_maps": [{ "name": "GSHUT-OUT", "direction": "out", }] } } } } } }, } } } } result = create_router_bgp(tgen, topo, input_dict_3) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) step( "FRR is setting local-pref to 0 by-default on receiver GSHUT community, " "below step is not needed, but keeping for reference") step("On R3, apply route-map IN direction to match GSHUT community " "and set local-preference to 0.") step("Verify BGP convergence on R4 and ensure all the neighbours state " "is established") result = verify_bgp_convergence(tgen, topo) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) step("Verify BGP routes on R4:") step("local pref for routes coming from R1 is set to 0.") for addr_type in ADDR_TYPES: rmap_dict = { "r1": { "route_maps": { "GSHUT-OUT": [{ "set": { "locPrf": 0 } }], } } } static_routes = [NETWORK[addr_type]] result = verify_bgp_attributes(tgen, addr_type, dut, static_routes, "GSHUT-OUT", rmap_dict) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) step("Ensure that best path is selected from R4 to R3.") for addr_type in ADDR_TYPES: dut = "r4" next_hop1 = next_hop_per_address_family(tgen, "r4", "r2", addr_type, NEXT_HOP_IP_1) next_hop2 = next_hop_per_address_family(tgen, "r4", "r3", addr_type, NEXT_HOP_IP_2) input_topo = {key: topo["routers"][key] for key in ["r1"]} result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop=[next_hop1, next_hop2]) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, addr_type, dut, input_topo, next_hop=next_hop1) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) step("Delete route-map from R1") del_rmap_dict = { "r1": { "route_maps": { "GSHUT-OUT": [{ "action": "permit", "seq_id": "10", "set": { "community": { "num": "graceful-shutdown", "delete": True } }, }] } } } result = create_route_maps(tgen, del_rmap_dict) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) step("Verify BGP convergence on R3 and ensure that all neighbor state " "is established") result = verify_bgp_convergence(tgen, topo) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) step("Verify BGP routes on R4:") step("Ensure that best path is selected from R1->R3") for addr_type in ADDR_TYPES: dut = "r4" next_hop1 = next_hop_per_address_family(tgen, "r4", "r2", addr_type, NEXT_HOP_IP_1) next_hop2 = next_hop_per_address_family(tgen, "r4", "r3", addr_type, NEXT_HOP_IP_2) input_topo = {key: topo["routers"][key] for key in ["r1"]} result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop=[next_hop1]) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, addr_type, dut, input_topo, next_hop=[next_hop1]) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) step("Re-add route-map in R1") result = create_route_maps(tgen, input_dict_2) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) step("Verify BGP convergence on R3 and ensure all the neighbours state " "is established") result = verify_bgp_convergence(tgen, topo) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) step("Verify BGP routes on R4:") step("local pref for routes coming from R1 is set to 0.") for addr_type in ADDR_TYPES: rmap_dict = { "r1": { "route_maps": { "GSHUT-OUT": [{ "set": { "locPrf": 0 } }] } } } static_routes = [NETWORK[addr_type]] result = verify_bgp_attributes(tgen, addr_type, dut, static_routes, "GSHUT-OUT", rmap_dict) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) step("Ensure that best path is selected from R4 to R3.") for addr_type in ADDR_TYPES: dut = "r4" next_hop1 = next_hop_per_address_family(tgen, "r4", "r2", addr_type, NEXT_HOP_IP_1) next_hop2 = next_hop_per_address_family(tgen, "r4", "r3", addr_type, NEXT_HOP_IP_2) input_topo = {key: topo["routers"][key] for key in ["r1"]} result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop=[next_hop1, next_hop2]) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, addr_type, dut, input_topo, next_hop=next_hop1) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name)
def test_bgp_no_export_local_as_and_internet_communities_p0(request): """ Verify that BGP well known communities work fine for eBGP and iBGP peers. Well known communities tested: no-export, local-AS, internet """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() # Don"t run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) step("Initial config: Configure BGP neighborship between R1 and R3.") reset_config_on_routers(tgen) step("Configure static routes on R1 with next-hop as null0") for addr_type in ADDR_TYPES: input_dict_4 = { "r1": { "static_routes": [{ "network": NETWORK[addr_type], "next_hop": "null0" }] } } result = create_static_routes(tgen, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) for comm_type in ["no-export", "local-AS", "internet"]: step("Create a route-map on R1 to set community as {}".format( comm_type)) seq_id = 10 input_rmap = { "r1": { "route_maps": { "rmap_wkc": [{ "action": "permit", "seq_id": seq_id, "set": { "community": { "num": "{}".format(comm_type) } }, }] } } } result = create_route_maps(tgen, input_rmap) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Apply route-map while redistributing static routes into BGP") input_dict_2 = { "r1": { "bgp": { "address_family": { "ipv4": { "unicast": { "redistribute": [{ "redist_type": "static", "attribute": { "route-map": "rmap_wkc" }, }] } }, "ipv6": { "unicast": { "redistribute": [{ "redist_type": "static", "attribute": { "route-map": "rmap_wkc" }, }] } }, } } } } result = create_router_bgp(tgen, topo, input_dict_2) step("Verify that BGP prefixes on R1 have community: {}".format( comm_type)) input_dict_4 = {"community": "{}".format(comm_type)} for addr_type in ADDR_TYPES: result = verify_bgp_community(tgen, addr_type, "r1", NETWORK[addr_type], input_dict_4) assert result is True, "Test case {} : Should fail \n Error: {}".format( tc_name, result) for addr_type in ADDR_TYPES: input_dict_4 = { "r1": { "static_routes": [{ "network": NETWORK[addr_type], "next_hop": topo["routers"]["r2"]["links"]["r1"][addr_type].split( "/")[0], }] } } result = verify_bgp_rib( tgen, addr_type, "r2", input_dict_4, next_hop=topo["routers"]["r1"]["links"]["r2"][addr_type].split( "/")[0], ) assert result is True, "Testcase : Failed \n Error: {}".format( tc_name, result) if comm_type == "internet": step("Verify that these prefixes, originated on R1, are" "received on both R2 and R3") result = verify_rib( tgen, addr_type, "r3", input_dict_4, next_hop=topo["routers"]["r1"]["links"]["r3"] [addr_type].split("/")[0], ) assert result is True, "Testcase : Failed \n Error: {}".format( tc_name, result) else: step("Verify that these prefixes, originated on R1, are not" "received on R3 but received on R2") result = verify_rib( tgen, addr_type, "r3", input_dict_4, next_hop=topo["routers"]["r1"]["links"]["r3"] [addr_type].split("/")[0], expected=False, ) assert result is not True, "Testcase : Failed \n Error: {}".format( tc_name, result) step("Remove route-map from redistribute static on R1") input_dict_2 = { "r1": { "bgp": { "address_family": { "ipv4": { "unicast": { "redistribute": [{ "redist_type": "static", "delete": True }] } }, "ipv6": { "unicast": { "redistribute": [{ "redist_type": "static", "delete": True }] } }, } } } } result = create_router_bgp(tgen, topo, input_dict_2) assert result is True, "Testcase : Failed \n Error: {}".format( tc_name, result) step("Configure redistribute static") input_dict_2 = { "r1": { "bgp": { "address_family": { "ipv4": { "unicast": { "redistribute": [{ "redist_type": "static" }] } }, "ipv6": { "unicast": { "redistribute": [{ "redist_type": "static" }] } }, } } } } result = create_router_bgp(tgen, topo, input_dict_2) assert result is True, "Testcase : Failed \n Error: {}".format( tc_name, result) step("Verify that these prefixes, originated on R1, are now" "received on both routers R2 and R3") for addr_type in ADDR_TYPES: input_dict_4 = { "r1": { "static_routes": [{ "network": NETWORK[addr_type], "next_hop": topo["routers"]["r2"]["links"]["r1"][addr_type].split( "/")[0], }] } } result = verify_bgp_rib( tgen, addr_type, "r2", input_dict_4, next_hop=topo["routers"]["r1"]["links"]["r2"][addr_type].split( "/")[0], ) assert result is True, "Testcase : Failed \n Error: {}".format( tc_name, result) result = verify_bgp_rib( tgen, addr_type, "r3", input_dict_4, next_hop=topo["routers"]["r1"]["links"]["r3"][addr_type].split( "/")[0], ) assert result is True, "Testcase : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name)
def test_weight_attribute(request): """ Test configure/modify weight attribute and verify best path is installed as per highest weight """ tgen = get_topogen() # Don't run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) # test case name tc_name = request.node.name write_test_header(tc_name) # Creating configuration from JSON reset_config_on_routers(tgen) # Api call to advertise networks input_dict = { "r7": { "bgp": { "address_family": { "ipv4": { "unicast": { "advertise_networks": [ {"network": "200.50.2.0/32"}, {"network": "200.60.2.0/32"}, ] } }, "ipv6": { "unicast": { "advertise_networks": [ {"network": "200:50:2::/128"}, {"network": "200:60:2::/128"}, ] } }, } } }, "r2": { "bgp": { "address_family": { "ipv4": { "unicast": { "neighbor": { "r1": {"dest_link": {"r2": {"next_hop_self": True}}} } } }, "ipv6": { "unicast": { "neighbor": { "r1": {"dest_link": {"r2": {"next_hop_self": True}}} } } }, } } }, "r3": { "bgp": { "address_family": { "ipv4": { "unicast": { "neighbor": { "r1": {"dest_link": {"r3": {"next_hop_self": True}}} } } }, "ipv6": { "unicast": { "neighbor": { "r1": {"dest_link": {"r3": {"next_hop_self": True}}} } } }, } } }, } result = create_router_bgp(tgen, topo, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Create Prefix list input_dict_2 = { "r1": { "prefix_lists": { "ipv4": { "pf_ls_1_ipv4": [ { "seqid": 10, "network": "200.0.0.0/8", "le": "32", "action": "permit", } ] }, "ipv6": { "pf_ls_1_ipv6": [ { "seqid": 10, "network": "200::/8", "le": "128", "action": "permit", } ] }, } } } result = create_prefix_lists(tgen, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Create route map input_dict_3 = { "r1": { "route_maps": { "RMAP_WEIGHT": [ { "action": "permit", "seq_id": "5", "match": {"ipv4": {"prefix_lists": "pf_ls_1_ipv4"}}, "set": {"weight": 500}, }, { "action": "permit", "seq_id": "10", "match": {"ipv6": {"prefix_lists": "pf_ls_1_ipv6"}}, "set": {"weight": 500}, }, ] } } } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Configure neighbor for route map input_dict_4 = { "r1": { "bgp": { "address_family": { "ipv4": { "unicast": { "neighbor": { "r2": { "dest_link": { "r1": { "route_maps": [ { "name": "RMAP_WEIGHT", "direction": "in", } ] } } } } } }, "ipv6": { "unicast": { "neighbor": { "r2": { "dest_link": { "r1": { "route_maps": [ { "name": "RMAP_WEIGHT", "direction": "in", } ] } } } } } }, } } } } result = create_router_bgp(tgen, topo, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying best path dut = "r1" attribute = "weight" for addr_type in ADDR_TYPES: result = verify_best_path_as_per_bgp_attribute( tgen, addr_type, dut, {"r7": input_dict["r7"]}, attribute ) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) # Modify route map input_dict_3 = { "r1": { "route_maps": { "RMAP_WEIGHT": [ { "action": "permit", "seq_id": "5", "match": {"ipv4": {"prefix_lists": "pf_ls_1_ipv4"}}, "set": {"weight": 1000}, }, { "action": "permit", "seq_id": "10", "match": {"ipv6": {"prefix_lists": "pf_ls_1_ipv6"}}, "set": {"weight": 1000}, }, ] } } } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying best path dut = "r1" attribute = "weight" for addr_type in ADDR_TYPES: result = verify_best_path_as_per_bgp_attribute( tgen, addr_type, dut, {"r7": input_dict["r7"]}, attribute ) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) write_test_footer(tc_name)
def test_BGP_attributes_with_vrf_default_keyword_p0(request): """ TC_9: Verify BGP functionality for default vrf with "vrf default" keyword. """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() if tgen.routers_have_failure(): pytest.skip(tgen.errors) # Creating configuration from JSON reset_config_on_routers(tgen) step("Configure static routes and redistribute in BGP on R3") for addr_type in ADDR_TYPES: input_dict = { "r3": { "static_routes": [ { "network": NETWORK[addr_type][0], "no_of_ip": 4, "next_hop": "Null0", } ] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) input_dict_2 = { "r3": { "bgp": { "address_family": { "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}}, "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}}, } } } } result = create_router_bgp(tgen, topo, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step( "Create a route-map to match a specific prefix and modify" "BGP attributes for matched prefix" ) input_dict_2 = { "r3": { "prefix_lists": { "ipv4": { "ABC": [ { "seqid": 10, "action": "permit", "network": NETWORK["ipv4"][0], } ] }, "ipv6": { "XYZ": [ { "seqid": 100, "action": "permit", "network": NETWORK["ipv6"][0], } ] }, } } } result = create_prefix_lists(tgen, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) for addr_type in ADDR_TYPES: if addr_type == "ipv4": pf_list = "ABC" else: pf_list = "XYZ" input_dict_6 = { "r3": { "route_maps": { "BGP_ATTR_{}".format(addr_type): [ { "action": "permit", "seq_id": 10, "match": {addr_type: {"prefix_lists": pf_list}}, "set": { "aspath": {"as_num": 500, "as_action": "prepend"}, "localpref": 500, "origin": "egp", "community": {"num": "500:500", "action": "additive"}, "large_community": { "num": "500:500:500", "action": "additive", }, }, }, {"action": "permit", "seq_id": 20}, ] }, "BGP_ATTR_{}".format(addr_type): [ { "action": "permit", "seq_id": 100, "match": {addr_type: {"prefix_lists": pf_list}}, "set": { "aspath": {"as_num": 500, "as_action": "prepend"}, "localpref": 500, "origin": "egp", "community": {"num": "500:500", "action": "additive"}, "large_community": { "num": "500:500:500", "action": "additive", }, }, }, {"action": "permit", "seq_id": 200}, ], } } result = create_route_maps(tgen, input_dict_6) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) step("Apply the route-map on R3 in outbound direction for peer R4") input_dict_7 = { "r3": { "bgp": { "address_family": { "ipv4": { "unicast": { "neighbor": { "r4": { "dest_link": { "r3": { "route_maps": [ { "name": "BGP_ATTR_ipv4", "direction": "out", } ] } } } } } }, "ipv6": { "unicast": { "neighbor": { "r4": { "dest_link": { "r3": { "route_maps": [ { "name": "BGP_ATTR_ipv6", "direction": "out", } ] } } } } } }, } } } } result = create_router_bgp(tgen, topo, input_dict_7) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step( "verify modified attributes for specific prefix with 'vrf default'" "keyword on R4" ) for addr_type in ADDR_TYPES: dut = "r4" input_dict = { "r3": { "static_routes": [ { "network": NETWORK[addr_type][0], "vrf": "default", "largeCommunity": "500:500:500", } ] } } result = verify_bgp_rib(tgen, addr_type, dut, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) result = verify_rib(tgen, addr_type, dut, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) for addr_type in ADDR_TYPES: dut = "r4" input_dict = { "r3": { "static_routes": [ { "network": NETWORK[addr_type][0], "vrf": "default", "community": "500:500", } ] } } result = verify_bgp_rib(tgen, addr_type, dut, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) result = verify_rib(tgen, addr_type, dut, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) input_dict_4 = {"largeCommunity": "500:500:500", "community": "500:500"} result = verify_bgp_community( tgen, addr_type, dut, [NETWORK[addr_type][0]], input_dict_4 ) assert result is True, "Test case {} : Should fail \n Error: {}".format( tc_name, result ) write_test_footer(tc_name)
def test_ospf_routemaps_functionality_tc20_p0(request): """ OSPF route map support functionality. Verify OSPF route map support functionality when route map is not configured at system level but configured in OSPF """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() global topo step("Bring up the base config as per the topology") reset_config_on_routers(tgen) step("Create static routes(10.0.20.1/32 and 10.0.20.2/32) in R0") # Create Static routes input_dict = { "r0": { "static_routes": [{ "network": NETWORK["ipv4"][0], "no_of_ip": 5, "next_hop": "Null0", }] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Redistribute to ospf using route map ( non existent route map)") ospf_red_r1 = { "r0": { "ospf": { "redistribute": [{ "redist_type": "static", "route_map": "rmap_ipv4" }] } } } result = create_router_ospf(tgen, topo, ospf_red_r1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Verify that routes are not allowed in OSPF even tough no " "matching routing map is configured.") dut = "r1" protocol = "ospf" result = verify_ospf_rib(tgen, dut, input_dict, attempts=2, expected=False) assert result is not True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, attempts=2, expected=False) assert result is not True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("configure the route map with the same name that is used " "in the ospf with deny rule.") # Create route map routemaps = {"r0": {"route_maps": {"rmap_ipv4": [{"action": "deny"}]}}} result = create_route_maps(tgen, routemaps) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("verify that now route map is activated & routes are denied in OSPF.") dut = "r1" protocol = "ospf" result = verify_ospf_rib(tgen, dut, input_dict, expected=False) assert result is not True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False) assert result is not True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create route map routemaps = {"r0": {"route_maps": {"rmap_ipv4": [{"action": "deny"}]}}} result = create_route_maps(tgen, routemaps) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("verify that now route map is activated & routes are denied in OSPF.") dut = "r1" protocol = "ospf" result = verify_ospf_rib(tgen, dut, input_dict, expected=False) assert result is not True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False) assert result is not True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Delete the route map.") # Create route map routemaps = { "r0": { "route_maps": { "rmap_ipv4": [{ "action": "deny", "delete": True }] } } } result = create_route_maps(tgen, routemaps) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Verify that routes are allowed in OSPF even tough " "no matching routing map is configured.") dut = "r1" protocol = "ospf" result = verify_ospf_rib(tgen, dut, input_dict, expected=False) assert result is not True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False) assert result is not True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name)
def test_route_map_inbound_outbound_same_neighbor_p0(request): """ TC_34: Verify if route-maps is applied in both inbound and outbound direction to same neighbor/interface. """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() # Don"t run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) # Creating configuration from JSON reset_config_on_routers(tgen) for adt in ADDR_TYPES: # Create Static routes input_dict = { "r1": { "static_routes": [ { "network": NETWORK[adt][0], "no_of_ip": 9, "next_hop": NEXT_HOP[adt], } ] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) # Api call to redistribute static routes input_dict_1 = { "r1": { "bgp": { "local_as": 100, "address_family": { "ipv4": { "unicast": { "redistribute": [ {"redist_type": "static"}, {"redist_type": "connected"}, ] } }, "ipv6": { "unicast": { "redistribute": [ {"redist_type": "static"}, {"redist_type": "connected"}, ] } }, }, } } } result = create_router_bgp(tgen, topo, input_dict_1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) input_dict_2 = { "r4": { "static_routes": [ { "network": NETWORK[adt][1], "no_of_ip": 9, "next_hop": NEXT_HOP[adt], } ] } } result = create_static_routes(tgen, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) # Api call to redistribute static routes input_dict_5 = { "r1": { "bgp": { "address_family": { "ipv4": { "unicast": { "redistribute": [ {"redist_type": "static"}, {"redist_type": "connected"}, ] } }, "ipv6": { "unicast": { "redistribute": [ {"redist_type": "static"}, {"redist_type": "connected"}, ] } }, } } } } result = create_router_bgp(tgen, topo, input_dict_5) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) input_dict_2 = { "r3": { "prefix_lists": { "ipv4": { "pf_list_1_ipv4": [ { "seqid": 10, "action": "permit", "network": NETWORK["ipv4"][0], } ], "pf_list_2_ipv4": [ { "seqid": 10, "action": "permit", "network": NETWORK["ipv4"][1], } ], }, "ipv6": { "pf_list_1_ipv6": [ { "seqid": 100, "action": "permit", "network": NETWORK["ipv6"][0], } ], "pf_list_2_ipv6": [ { "seqid": 100, "action": "permit", "network": NETWORK["ipv6"][1], } ], }, } } } result = create_prefix_lists(tgen, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) # Create route map for addr_type in ADDR_TYPES: input_dict_6 = { "r3": { "route_maps": { "rmap_match_tag_1_{}".format(addr_type): [ { "action": "deny", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) } }, } ], "rmap_match_tag_2_{}".format(addr_type): [ { "action": "permit", "match": { addr_type: { "prefix_lists": "pf_list_2_{}".format(addr_type) } }, } ], } } } result = create_route_maps(tgen, input_dict_6) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) # Configure neighbor for route map input_dict_7 = { "r3": { "bgp": { "address_family": { "ipv4": { "unicast": { "neighbor": { "r4": { "dest_link": { "r3": { "route_maps": [ { "name": "rmap_match_tag_1_ipv4", "direction": "in", }, { "name": "rmap_match_tag_1_ipv4", "direction": "out", }, ] } } } } } }, "ipv6": { "unicast": { "neighbor": { "r4": { "dest_link": { "r3": { "route_maps": [ { "name": "rmap_match_tag_1_ipv6", "direction": "in", }, { "name": "rmap_match_tag_1_ipv6", "direction": "out", }, ] } } } } } }, } } } } result = create_router_bgp(tgen, topo, input_dict_7) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) for adt in ADDR_TYPES: # Verifying RIB routes dut = "r3" protocol = "bgp" input_dict_2 = { "r4": { "static_routes": [ { "network": [NETWORK[adt][1]], "no_of_ip": 9, "next_hop": NEXT_HOP[adt], } ] } } result = verify_rib( tgen, adt, dut, input_dict_2, protocol=protocol, expected=False ) assert result is not True, ("Testcase {} : Failed \n" "routes are not present in rib \n Error: {}".format(tc_name, result)) logger.info("Expected behaviour: {}".format(result)) # Verifying RIB routes dut = "r4" input_dict = { "r1": { "static_routes": [ { "network": [NETWORK[adt][0]], "no_of_ip": 9, "next_hop": NEXT_HOP[adt], } ] } } result = verify_rib( tgen, adt, dut, input_dict, protocol=protocol, expected=False ) assert result is not True, ("Testcase {} : Failed \n " "routes are not present in rib \n Error: {}".format(tc_name, result)) logger.info("Expected behaviour: {}".format(result)) write_test_footer(tc_name)
def test_route_map_multiple_seq_different_match_set_clause_p0(request): """ TC_35: Test multiple sequence numbers in a single route-map for different match/set clauses. """ tgen = get_topogen() # test case name tc_name = request.node.name write_test_header(tc_name) # Creating configuration from JSON reset_config_on_routers(tgen) for adt in ADDR_TYPES: # Create Static routes input_dict = { "r1": { "static_routes": [ { "network": NETWORK[adt][0], "no_of_ip": 1, "next_hop": NEXT_HOP[adt], } ] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) # Api call to redistribute static routes input_dict_1 = { "r1": { "bgp": { "address_family": { "ipv4": { "unicast": { "redistribute": [ {"redist_type": "static"}, {"redist_type": "connected"}, ] } }, "ipv6": { "unicast": { "redistribute": [ {"redist_type": "static"}, {"redist_type": "connected"}, ] } }, } } } } result = create_router_bgp(tgen, topo, input_dict_1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) # Create ip prefix list input_dict_2 = { "r3": { "prefix_lists": { "ipv4": { "pf_list_1_ipv4": [ {"seqid": 10, "network": "any", "action": "permit"} ] }, "ipv6": { "pf_list_1_ipv6": [ {"seqid": 100, "network": "any", "action": "permit"} ] }, } } } result = create_prefix_lists(tgen, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) # Create route map for addr_type in ADDR_TYPES: input_dict_3 = { "r3": { "route_maps": { "rmap_match_pf_1_{}".format(addr_type): [ { "action": "permit", "match": { addr_type: { "prefix_lists": "pf_list_2_{}".format(addr_type) } }, "set": {"path": {"as_num": 500}}, }, { "action": "permit", "match": { addr_type: { "prefix_lists": "pf_list_2_{}".format(addr_type) } }, "set": { "locPrf": 150, }, }, { "action": "permit", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) } }, "set": {"metric": 50}, }, ] } } } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) # Configure neighbor for route map input_dict_4 = { "r3": { "bgp": { "address_family": { "ipv4": { "unicast": { "neighbor": { "r1": { "dest_link": { "r3": { "route_maps": [ { "name": "rmap_match_pf_1_ipv4", "direction": "in", } ] } } }, "r4": { "dest_link": { "r3": { "route_maps": [ { "name": "rmap_match_pf_1_ipv4", "direction": "out", } ] } } }, } } }, "ipv6": { "unicast": { "neighbor": { "r1": { "dest_link": { "r3": { "route_maps": [ { "name": "rmap_match_pf_1_ipv6", "direction": "in", } ] } } }, "r4": { "dest_link": { "r3": { "route_maps": [ { "name": "rmap_match_pf_1_ipv6", "direction": "out", } ] } } }, } } }, } } } } result = create_router_bgp(tgen, topo, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) for adt in ADDR_TYPES: # Verifying RIB routes dut = "r3" protocol = "bgp" input_dict = { "r3": { "route_maps": { "rmap_match_pf_list1": [ { "set": { "metric": 50, } } ], } } } static_routes = [NETWORK[adt][0]] time.sleep(2) result = verify_bgp_attributes( tgen, adt, dut, static_routes, "rmap_match_pf_list1", input_dict ) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result ) dut = "r4" result = verify_bgp_attributes( tgen, adt, dut, static_routes, "rmap_match_pf_list1", input_dict ) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result ) logger.info("Testcase " + tc_name + " :Passed \n")
def test_route_summarisation_with_as_set_p1(request): """ Verify route summarisation with as-set for redistributed routes. """ tgen = get_topogen() tc_name = request.node.name reset_config_on_routers(tgen) write_test_header(tc_name) # Don"t run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) step("Configure static routes on router R1 and redistribute in " "BGP process.") for addr_type in ADDR_TYPES: input_static = { "r1": { "static_routes": [{ "network": [ NETWORK_1_1[addr_type], NETWORK_1_2[addr_type], NETWORK_1_3[addr_type], NETWORK_1_4[addr_type], NETWORK_1_5[addr_type], ], "next_hop": NEXT_HOP[addr_type], }] } } input_redistribute = { "r1": { "bgp": { "address_family": { addr_type: { "unicast": { "redistribute": [{ "redist_type": "static" }] } } } } } } step("Configuring {} static routes on router R1 ".format(addr_type)) result = create_static_routes(tgen, input_static) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step( "Configuring redistribute static for {} address-family on router R1 " .format(addr_type)) result = create_router_bgp(tgen, topo, input_redistribute) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) step("Verify that Static routes are redistributed in BGP process") for addr_type in ADDR_TYPES: input_static = { "r1": { "static_routes": [{ "network": [ NETWORK_1_1[addr_type], NETWORK_1_2[addr_type], NETWORK_1_3[addr_type], NETWORK_1_4[addr_type], NETWORK_1_5[addr_type], ] }] } } result = verify_rib(tgen, addr_type, "r3", input_static) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Configure a route-map to attach a unique community attribute value " "to each of these prefixes, while re-distributing static.") for addr_type in ADDR_TYPES: for pfx, seq_id, network, in zip( [1, 2, 3, 4, 5], [10, 20, 30, 40, 50], [NETWORK_1_1, NETWORK_1_2, NETWORK_1_3, NETWORK_1_4, NETWORK_1_5], ): prefix_list = { "r1": { "prefix_lists": { addr_type: { "pf_list_{}_{}".format(addr_type, pfx): [{ "seqid": seq_id, "network": network[addr_type], "action": "permit", }] } } } } result = create_prefix_lists(tgen, prefix_list) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) step("Create route-map for applying prefix-list on r1") for addr_type in ADDR_TYPES: for pfx, comm_id in zip([1, 2, 3, 4, 5], [0, 1, 2, 3, 4]): route_map = { "r1": { "route_maps": { "rmap_{}".format(addr_type): [{ "action": "permit", "match": { addr_type: { "prefix_lists": "pf_list_{}_{}".format(addr_type, pfx) } }, "set": { "community": { "num": COMMUNITY[comm_id] } }, }] } } } result = create_route_maps(tgen, route_map) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) step("Re-configure redistribute static with route-map") for addr_type in ADDR_TYPES: input_redistribute = { "r1": { "bgp": { "address_family": { addr_type: { "unicast": { "redistribute": [{ "redist_type": "static", "attribute": { "route-map": "rmap_{}".format(addr_type) }, }] } } } } } } result = create_router_bgp(tgen, topo, input_redistribute) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) step("Configure aggregate-address to summarise all the advertised routes.") for addr_type in ADDR_TYPES: route_aggregate = { "r1": { "bgp": { "address_family": { addr_type: { "unicast": { "aggregate_address": [{ "network": AGGREGATE_NW[addr_type], "as_set": True }] } } } } } } result = create_router_bgp(tgen, topo, route_aggregate) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) step("Verify that we see summarised route on router R3 with all the " "community attribute values combined with that aggregate route.") for addr_type in ADDR_TYPES: input_dict = {"community": COMMUNITY[5]} result = verify_bgp_community(tgen, addr_type, "r3", [AGGREGATE_NW[addr_type]], input_dict) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) step("Remove static routes as below: " "(no) ip route 10.1.1.0/24 blackhole " "(no) ip route 10.1.2.0/24 blackhole " "(no) ipv6 route 10:1::1:0/120 blackhole " "(no) ipv6 route 10:1::2:0/120 blackhole ") for addr_type in ADDR_TYPES: input_static = { "r1": { "static_routes": [{ "network": [NETWORK_1_1[addr_type], NETWORK_1_2[addr_type]], "next_hop": NEXT_HOP[addr_type], "delete": True, }] } } result = create_static_routes(tgen, input_static) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Verify on R3 that whenever we remove the static routes, we still" " see aggregated route however the corresponding community attribute" "values are withdrawn.") for addr_type in ADDR_TYPES: input_dict = {"community": COMMUNITY[6]} result = verify_bgp_community(tgen, addr_type, "r3", [AGGREGATE_NW[addr_type]], input_dict) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) step("Add/remove a new network with community value, each one from out of " "aggregation range and other within aggregation range. ") step("Add a new network each one from out of aggregation range and " "other within aggregation range. ") for addr_type in ADDR_TYPES: input_static = { "r1": { "static_routes": [{ "network": [NETWORK_3_1[addr_type], NETWORK_4_1[addr_type]], "next_hop": NEXT_HOP[addr_type], }] } } result = create_static_routes(tgen, input_static) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) for addr_type in ADDR_TYPES: for ( pfx, seq_id, network, ) in zip([6, 7], [60, 70], [NETWORK_3_1, NETWORK_4_1]): prefix_list = { "r1": { "prefix_lists": { addr_type: { "pf_list_{}_{}".format(addr_type, pfx): [{ "seqid": seq_id, "network": network[addr_type], "action": "permit", }] } } } } result = create_prefix_lists(tgen, prefix_list) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) step("Create route-map for applying prefix-list on r1") for addr_type in ADDR_TYPES: for pfx, comm_id in zip([6, 7], [7, 8]): route_map = { "r1": { "route_maps": { "rmap_{}".format(addr_type): [{ "action": "permit", "match": { addr_type: { "prefix_lists": "pf_list_{}_{}".format(addr_type, pfx) } }, "set": { "community": { "num": COMMUNITY[comm_id] } }, }] } } } result = create_route_maps(tgen, route_map) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) step( "Verify on R3 when route is added within the summary range, aggregated" " route also has associated community value added. However if the route" " is beyond the summary range the aggregated route would have no impact" ) for addr_type in ADDR_TYPES: input_dict = {"community": COMMUNITY[9]} result = verify_bgp_community(tgen, addr_type, "r3", [AGGREGATE_NW[addr_type]], input_dict) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) for action, value in zip(["Delete", "Re-add"], [True, False]): step("{} aggregation command from R1.".format(action)) for addr_type in ADDR_TYPES: route_aggregate = { "r1": { "bgp": { "address_family": { addr_type: { "unicast": { "aggregate_address": [{ "network": AGGREGATE_NW[addr_type], "as_set": True, "delete": value, }] } } } } } } result = create_router_bgp(tgen, topo, route_aggregate) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) step( "Verify that when as-set command is removed, we do not see community " "attribute added to summarised route on R3. However when as-set option " "is re-added, all the community attribute values must appear with " "summarised route.") for addr_type in ADDR_TYPES: input_static_agg = { "r1": { "static_routes": [{ "network": AGGREGATE_NW[addr_type] }] } } if value: result = verify_rib(tgen, addr_type, "r1", input_static_agg, expected=False) assert ( result is not True ), "Testcase {} : Failed \n Aggregated route is still present \n Error: {}".format( tc_name, result) result = verify_rib(tgen, addr_type, "r3", input_static_agg, expected=False) assert ( result is not True ), "Testcase {} : Failed \n Aggregated route is still present \n Error: {}".format( tc_name, result) else: result = verify_rib(tgen, addr_type, "r1", input_static_agg) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, addr_type, "r3", input_static_agg) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) input_dict = {"community": COMMUNITY[9]} result = verify_bgp_community(tgen, addr_type, "r3", [AGGREGATE_NW[addr_type]], input_dict) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name)
def test_modify_route_map_match_set_clauses_p1(request): """ TC13_CHAOS_4: 1.5.13. Verify that Changing route-map configurations(match/set clauses) on the fly it takes immediate effect. """ tgen = get_topogen() tc_name = request.node.name write_test_header(tc_name) build_config_from_json(tgen, topo) if tgen.routers_have_failure(): check_router_status(tgen) for addr_type in ADDR_TYPES: step("Configure route-map to set community attribute for a specific" "prefix on R1 in vrf ISR") input_dict_pf = { "r1": { "prefix_lists": { addr_type: { "pflist_ABC_{}".format(addr_type): [{ "seqid": 10, "network": NETWORK1_1[addr_type], "action": "permit", }] } } } } result = create_prefix_lists(tgen, input_dict_pf) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) input_dict_cl = { "r1": { "bgp_community_lists": [{ "community_type": "expanded", "action": "permit", "name": "COMM", "value": "100:100", }] } } result = create_bgp_community_lists(tgen, input_dict_cl) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) for addr_type in ADDR_TYPES: input_dict_rm = { "r1": { "route_maps": { "rmap_XYZ_{}".format(addr_type): [{ "action": "permit", "match": { addr_type: { "prefix_lists": "pflist_ABC_{}".format(addr_type) } }, "set": { "community": { "num": "100:100" } }, }] } } } result = create_route_maps(tgen, input_dict_rm) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) for addr_type in ADDR_TYPES: step("Apply this route-map on R1 to vrf ISR while redistributing the" " prefixes into BGP") input_dict_1 = {} DUT = ["r1"] VRFS = ["ISR"] AS_NUM = [100] for dut, vrf, as_num in zip(DUT, VRFS, AS_NUM): temp = {dut: {"bgp": []}} input_dict_1.update(temp) temp[dut]["bgp"].append({ "local_as": as_num, "vrf": vrf, "address_family": { addr_type: { "unicast": { "redistribute": [{ "redist_type": "static", "attribute": { "route-map": "rmap_XYZ_{}".format(addr_type) }, }] } } }, }) result = create_router_bgp(tgen, topo, input_dict_1) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) for addr_type in ADDR_TYPES: step("Configure another route-map for filtering the prefixes based on" " community attribute while importing into default vrf") input_dict_rm = { "r1": { "route_maps": { "rmap_IMP_{}".format(addr_type): [{ "action": "permit", "seq_id": 10, "match": { "community_list": { "id": "COMM" } }, "set": { "community": { "num": "none" } }, }] } } } result = create_route_maps(tgen, input_dict_rm) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) for addr_type in ADDR_TYPES: step("Apply the route-map while Importing vrf ISR's prefixes into " "default vrf on router R1:") input_dict_isr = {} DUT = ["r1"] VRFS = ["default"] AS_NUM = [100] for dut, vrf, as_num in zip(DUT, VRFS, AS_NUM): temp = {dut: {"bgp": []}} input_dict_isr.update(temp) temp[dut]["bgp"].append({ "local_as": as_num, "vrf": vrf, "address_family": { addr_type: { "unicast": { "import": { "vrf": "ISR" } } } }, }) temp[dut]["bgp"].append({ "local_as": as_num, "vrf": vrf, "address_family": { addr_type: { "unicast": { "import": { "vrf": "route-map rmap_IMP_{}".format(addr_type) } } } }, }) result = create_router_bgp(tgen, topo, input_dict_isr) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) for addr_type in ADDR_TYPES: step("Verify on R1 that only prefixes with community value 100:100" "in vrf ISR are imported to vrf default. While importing, the" " community value has been stripped off:") input_routes_r1 = { "r1": { "static_routes": [{ "network": [NETWORK1_1[addr_type]], "vrf": "default" }] } } result = verify_bgp_rib(tgen, addr_type, "r1", input_routes_r1) assert result is True, "Testcase {} : Failed \n Error {}".format( tc_name, result) for addr_type in ADDR_TYPES: step("Add set clause in route-map IMP:") input_dict_rm = { "r1": { "route_maps": { "rmap_IMP_{}".format(addr_type): [{ "action": "permit", "seq_id": 10, "match": { "community_list": { "id": "COMM" } }, "set": { "large_community": { "num": "100:100:100" }, "locPrf": 500, "path": { "as_num": "100 100", "as_action": "prepend" }, }, }] } } } result = create_route_maps(tgen, input_dict_rm) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) for addr_type in ADDR_TYPES: step("Verify that as we continue adding different attributes " "step-by-step in route-map IMP those attributes gets " "attached to prefixes:") input_routes_r1 = { "r1": { "static_routes": [{ "network": [NETWORK1_1[addr_type]], "vrf": "default" }] } } input_dict_comm = {"largeCommunity": "100:100:100"} result = verify_bgp_community(tgen, addr_type, dut, [NETWORK1_1[addr_type]], input_dict_comm) assert result is True, "Testcase {} : Failed \n Error {}".format( tc_name, result) input_rmap = { "r1": { "route_maps": { "rmap_IMP_{}".format(addr_type): [{ "set": { "locPrf": 500 } }] } } } result = verify_bgp_attributes( tgen, addr_type, "r1", [NETWORK1_1[addr_type]], rmap_name="rmap_IMP_{}".format(addr_type), input_dict=input_rmap, ) assert result is True, "Testcase : Failed \n Error: {}".format( tc_name, result) step("Change community-list to match a different value then " "100:100.") input_dict_cl = { "r1": { "bgp_community_lists": [{ "community_type": "expanded", "action": "permit", "name": "COMM", "value": "100:100", "delete": True, }] } } result = create_bgp_community_lists(tgen, input_dict_cl) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) for addr_type in ADDR_TYPES: input_routes_r1 = { "r1": { "static_routes": [{ "network": [NETWORK1_1[addr_type]], "vrf": "default" }] } } result = verify_bgp_rib(tgen, addr_type, "r1", input_routes_r1, expected=False) assert ( result is not True ), "Testcase {} : Failed \n Error : Routes are still " "present {}".format( tc_name, result) write_test_footer(tc_name)
def config_router_r1(tgen, topo, tc_name): global CONFIG_ROUTER_R1 input_dict_1 = { "r1": { "route_maps": { "LC1": [ { "action": "permit", "seq_id": "10", "set": { "large_community": {"num": LARGE_COMM["r1"]}, "community": {"num": STANDARD_COMM["r1"]}, }, } ] } } } step("Configuring LC1 on r1") result = create_route_maps(tgen, input_dict_1) assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) # Configure neighbor for route map input_dict_2 = { "r1": { "bgp": { "address_family": { "ipv4": { "unicast": { "advertise_networks": [ { "network": "%s/%s" % (NETWORK["ipv4"][0], MASK["ipv4"]), "no_of_network": 4, } ], "neighbor": { "r2": { "dest_link": { "r1-link1": { "route_maps": [ {"name": "LC1", "direction": "out"} ] } } }, "r3": { "dest_link": { "r1-link1": { "route_maps": [ {"name": "LC1", "direction": "out"} ] } } }, }, } }, "ipv6": { "unicast": { "advertise_networks": [ { "network": "%s/%s" % (NETWORK["ipv6"][0], MASK["ipv6"]), "no_of_network": 4, } ], "neighbor": { "r2": { "dest_link": { "r1-link1": { "route_maps": [ {"name": "LC1", "direction": "out"} ] } } }, "r3": { "dest_link": { "r1-link1": { "route_maps": [ {"name": "LC1", "direction": "out"} ] } } }, }, } }, } } } } step("Applying LC1 on r1 neighbors and advertising networks") result = create_router_bgp(tgen, topo, input_dict_2) assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) CONFIG_ROUTER_R1 = True
def config_router_r2(tgen, topo, tc_name): global CONFIG_ROUTER_R2 input_dict = { "r2": { "route_maps": { "LC2": [ { "action": "permit", "seq_id": "10", "set": { "large_community": {"num": LARGE_COMM["r2"]}, "community": {"num": STANDARD_COMM["r2"]}, }, } ] } } } step("Configuring route-maps LC2 on r2") result = create_route_maps(tgen, input_dict) assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) input_dict_1 = { "r2": { "bgp": { "address_family": { "ipv4": { "unicast": { "neighbor": { "r4": { "dest_link": { "r2-link1": { "route_maps": [ {"name": "LC2", "direction": "out"} ] } } } } } }, "ipv6": { "unicast": { "neighbor": { "r4": { "dest_link": { "r2-link1": { "route_maps": [ {"name": "LC2", "direction": "out"} ] } } } } } }, } } } } step("Applying LC2 on r2 neighbors in out direction") result = create_router_bgp(tgen, topo, input_dict_1) assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) CONFIG_ROUTER_R2 = True
def test_ospf_routemaps_functionality_tc21_p0(request): """ OSPF route map support functionality. Verify OSPF route map support functionality with set/match clauses /call/continue/goto in a route-map to see if it takes immediate effect. """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() global topo step("Bring up the base config as per the topology") reset_config_on_routers(tgen) step("Create static routes(10.0.20.1/32) in R1 and redistribute " "to OSPF using route map.") # Create Static routes input_dict = { "r0": { "static_routes": [{ "network": NETWORK["ipv4"][0], "no_of_ip": 5, "next_hop": "Null0", }] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) redistribute_ospf(tgen, topo, "r0", "static", route_map="rmap_ipv4") # Create route map routemaps = { "r0": { "route_maps": { "rmap_ipv4": [{ "action": "permit", "seq_id": 10 }] } } } result = create_route_maps(tgen, routemaps) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Verify that route is advertised to R2.") dut = "r1" protocol = "ospf" result = verify_ospf_rib(tgen, dut, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create route map routemaps = { "r0": { "route_maps": { "rmap_ipv4": [{ "action": "permit", "delete": True, "seq_id": 10 }] } } } result = create_route_maps(tgen, routemaps) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step(" Configure route map with set clause (set metric)") # Create route map routemaps = { "r0": { "route_maps": { "rmap_ipv4": [{ "action": "permit", "set": { "med": 123 }, "seq_id": 10 }] } } } result = create_route_maps(tgen, routemaps) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Verify that configured metric is applied to ospf routes.") dut = "r1" protocol = "ospf" result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Configure route map with match clause (match metric) with " "some actions(change metric).") # Create route map routemaps = { "r0": { "route_maps": { "rmap_ipv4": [{ "action": "permit", "match": { "med": 123 }, "set": { "med": 150 }, "seq_id": 10, }] } } } result = create_route_maps(tgen, routemaps) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Configure route map with call clause") # Create ip prefix list input_dict_2 = { "r0": { "prefix_lists": { "ipv4": { "pf_list_1_ipv4": [{ "seqid": 10, "network": "any", "action": "permit" }] } } } } result = create_prefix_lists(tgen, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create route map input_dict_3 = { "r0": { "route_maps": { "rmap_ipv4": [{ "action": "permit", "match": { "ipv4": { "prefix_lists": "pf_list_1_ipv4" } }, "set": { "med": 150 }, "call": "rmap_match_pf_2_ipv4", "seq_id": 10, }], "rmap_match_pf_2_ipv4": [{ "action": "permit", "match": { "ipv4": { "prefix_lists": "pf_list_1_ipv4" } }, "set": { "med": 200 }, "seq_id": 10, }], } } } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_ospf_rib(tgen, dut, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create route map routemaps = {"r0": {"route_maps": {"rmap_ipv4": [{"delete": True}]}}} result = create_route_maps(tgen, routemaps) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Configure route map with continue clause") # Create route map input_dict_3 = { "r0": { "route_maps": { "rmap_ipv4": [ { "action": "permit", "seq_id": "10", "match": { "ipv4": { "prefix_lists": "pf_list_1_ipv4" } }, "set": { "med": 150 }, "continue": "30", "seq_id": 10, }, { "action": "permit", "match": { "ipv4": { "prefix_lists": "pf_list_1_ipv4" } }, "set": { "med": 100 }, "seq_id": 20, }, { "action": "permit", "match": { "ipv4": { "prefix_lists": "pf_list_1_ipv4" } }, "set": { "med": 50 }, "seq_id": 30, }, ] } } } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_ospf_rib(tgen, dut, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Configure route map with goto clause") # Create route map input_dict_3 = { "r0": { "route_maps": { "rmap_ipv4": [ { "action": "permit", "seq_id": "10", "match": { "ipv4": { "prefix_lists": "pf_list_1_ipv4" } }, "goto": "30", }, { "action": "permit", "seq_id": "20", "match": { "ipv4": { "prefix_lists": "pf_list_1_ipv4" } }, "set": { "med": 100 }, }, { "action": "permit", "seq_id": "30", "match": { "ipv4": { "prefix_lists": "pf_list_1_ipv4" } }, "set": { "med": 200 }, }, ] } } } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name)
def test_ospf_routemaps_functionality_tc19_p0(request): """ OSPF Route map - Verify OSPF route map support functionality. """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() global topo step("Bring up the base config as per the topology") reset_config_on_routers(tgen) step("Create static routes(10.0.20.1/32 and 10.0.20.2/32) in R0") # Create Static routes input_dict = { "r0": { "static_routes": [{ "network": NETWORK["ipv4"][0], "no_of_ip": 5, "next_hop": "Null0", }] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) redistribute_ospf(tgen, topo, "r0", "static") dut = "r1" lsid = NETWORK["ipv4"][0].split("/")[0] rid = routerids[0] protocol = "ospf" result = verify_ospf_rib(tgen, dut, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) redistribute_ospf(tgen, topo, "r0", "static", delete=True) step("Create prefix-list in R0 to permit 10.0.20.1/32 prefix &" " deny 10.0.20.2/32") # Create ip prefix list pfx_list = { "r0": { "prefix_lists": { "ipv4": { "pf_list_1_ipv4": [ { "seqid": 10, "network": NETWORK["ipv4"][0], "action": "permit", }, { "seqid": 11, "network": "any", "action": "deny" }, ] } } } } result = create_prefix_lists(tgen, pfx_list) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create route map routemaps = { "r0": { "route_maps": { "rmap_ipv4": [{ "action": "permit", "match": { "ipv4": { "prefix_lists": "pf_list_1_ipv4" } }, }] } } } result = create_route_maps(tgen, routemaps) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Configure route map rmap1 and redistribute static routes to" " ospf using route map rmap1") redistribute_ospf(tgen, topo, "r0", "static", route_map="rmap_ipv4") step("Change prefix rules to permit 10.0.20.2 and deny 10.0.20.1") # Create ip prefix list pfx_list = { "r0": { "prefix_lists": { "ipv4": { "pf_list_1_ipv4": [ { "seqid": 10, "network": NETWORK["ipv4"][1], "action": "permit", }, { "seqid": 11, "network": "any", "action": "deny" }, ] } } } } result = create_prefix_lists(tgen, pfx_list) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Verify that route 10.0.20.2 is allowed and 10.0.20.1 is denied.") dut = "r1" input_dict = { "r0": { "static_routes": [{ "network": NETWORK["ipv4"][1], "no_of_ip": 1, "next_hop": "Null0" }] } } result = verify_ospf_rib(tgen, dut, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) input_dict = { "r0": { "static_routes": [{ "network": NETWORK["ipv4"][0], "no_of_ip": 1, "next_hop": "Null0" }] } } result = verify_ospf_rib(tgen, dut, input_dict, expected=False) assert result is not True, ( "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(tc_name, result)) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False) assert result is not True, ( "Testcase {} : Failed \n " "r1: routes are present in fib \n Error: {}".format(tc_name, result)) step("Delete and reconfigure prefix list.") # Create ip prefix list pfx_list = { "r0": { "prefix_lists": { "ipv4": { "pf_list_1_ipv4": [ { "seqid": 10, "network": NETWORK["ipv4"][1], "action": "permit", "delete": True, }, { "seqid": 11, "network": "any", "action": "deny", "delete": True, }, ] } } } } result = create_prefix_lists(tgen, pfx_list) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_prefix_lists(tgen, pfx_list) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) input_dict = { "r0": { "static_routes": [{ "network": NETWORK["ipv4"][0], "no_of_ip": 5, "next_hop": "Null0" }] } } result = verify_ospf_rib(tgen, dut, input_dict, expected=False) assert result is not True, ( "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(tc_name, result)) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False) assert result is not True, ( "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(tc_name, result)) pfx_list = { "r0": { "prefix_lists": { "ipv4": { "pf_list_1_ipv4": [ { "seqid": 10, "network": NETWORK["ipv4"][1], "action": "permit", }, { "seqid": 11, "network": "any", "action": "deny" }, ] } } } } result = create_prefix_lists(tgen, pfx_list) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Verify that route 10.0.20.2 is allowed and 10.0.20.1 is denied.") dut = "r1" input_dict = { "r0": { "static_routes": [{ "network": NETWORK["ipv4"][1], "no_of_ip": 1, "next_hop": "Null0" }] } } result = verify_ospf_rib(tgen, dut, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) input_dict = { "r0": { "static_routes": [{ "network": NETWORK["ipv4"][0], "no_of_ip": 1, "next_hop": "Null0" }] } } result = verify_ospf_rib(tgen, dut, input_dict, expected=False) assert result is not True, ( "Testcase {} : Failed \n " "r1: OSPF routes are present \n Error: {}".format(tc_name, result)) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False) assert result is not True, ( "Testcase {} : Failed \n " "r1: routes are still present \n Error: {}".format(tc_name, result)) write_test_footer(tc_name)
def test_bgp_no_advertise_community_p0(request): """ Verify routes are not advertised when NO-ADVERTISE Community is applied """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() reset_config_on_routers(tgen) # Don't run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) NEXT_HOP_IP = { "ipv4": topo["routers"]["r0"]["links"]["r1"]["ipv4"].split("/")[0], "ipv6": topo["routers"]["r0"]["links"]["r1"]["ipv6"].split("/")[0], } # configure static routes dut = "r3" protocol = "bgp" for addr_type in ADDR_TYPES: # Enable static routes input_dict = { "r1": { "static_routes": [ {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]} ] } } logger.info("Configure static routes") result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) step("configure redistribute static and connected in Router BGP " "in R1") input_dict_2 = { "r1": { "bgp": { "address_family": { addr_type: { "unicast": { "redistribute": [ {"redist_type": "static"}, {"redist_type": "connected"}, ] } } } } } } result = create_router_bgp(tgen, topo, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) step( "BGP neighbors are up, static and connected route advertised from" " R1 are present on R2 BGP table and RIB using show ip bgp and " " show ip route" ) step( "Static and connected route advertised from R1 are present on R3" " BGP table and RIB using show ip bgp and show ip route" ) dut = "r3" protocol = "bgp" result = verify_bgp_rib(tgen, addr_type, dut, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) step("Configure prefix list P1 on R2 to permit route coming from R1") # Create ip prefix list input_dict_2 = { "r2": { "prefix_lists": { addr_type: { "pf_list_1_{}".format(addr_type): [ {"seqid": 10, "network": "any", "action": "permit"} ] } } } } result = create_prefix_lists(tgen, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) # Create route map input_dict_3 = { "r2": { "route_maps": { "rmap_match_pf_1_{}".format(addr_type): [ { "action": "permit", "seq_id": "5", "match": { addr_type: {"prefix_lists": "pf_list_1_" + addr_type} }, "set": {"community": {"num": "no-advertise"}}, } ] } } } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) step( "Apply route-map RM1 on R2, R2 to R3 BGP neighbor with no" " advertise community" ) # Configure neighbor for route map input_dict_4 = { "r2": { "bgp": { "address_family": { addr_type: { "unicast": { "neighbor": { "r1": { "dest_link": { "r2": { "route_maps": [ { "name": "rmap_match_pf_1_" + addr_type, "direction": "in", } ] } } } } } } } } } } result = create_router_bgp(tgen, topo, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) step( "After advertising no advertise community to BGP neighbor " "static and connected router got removed from R3 verify using " "show ip bgp & show ip route" ) result = verify_bgp_rib(tgen, addr_type, dut, input_dict, expected=False) assert result is not True, "Testcase {} : Failed \n " " Routes still present in R3 router. Error: {}".format(tc_name, result) result = verify_rib( tgen, addr_type, dut, input_dict, protocol=protocol, expected=False ) assert result is not True, "Testcase {} : Failed \n " " Routes still present in R3 router. Error: {}".format(tc_name, result) step("Remove and Add no advertise community") # Configure neighbor for route map input_dict_4 = { "r2": { "bgp": { "address_family": { addr_type: { "unicast": { "neighbor": { "r1": { "dest_link": { "r2": { "route_maps": [ { "name": "rmap_match_pf_1_" + addr_type, "direction": "in", "delete": True, } ] } } } } } } } } } } result = create_router_bgp(tgen, topo, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) step( "After removing no advertise community from BGP neighbor " "static and connected router got advertised to R3 and " "removing route-map, verify route using show ip bgp" " and show ip route" ) result = verify_bgp_rib(tgen, addr_type, dut, input_dict) assert result is True, "Testcase {} : Failed \n " " Routes still present in R3 router. Error: {}".format(tc_name, result) result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n " " Routes still present in R3 router. Error: {}".format(tc_name, result) step("Repeat above steps when IBGP nbr configured between R1, R2 & R2, R3") topo1 = deepcopy(topo) topo1["routers"]["r1"]["bgp"]["local_as"] = "100" topo1["routers"]["r2"]["bgp"]["local_as"] = "100" topo1["routers"]["r3"]["bgp"]["local_as"] = "100" for rtr in ["r1", "r2", "r3"]: if "bgp" in topo1["routers"][rtr].keys(): delete_bgp = {rtr: {"bgp": {"delete": True}}} result = create_router_bgp(tgen, topo1, delete_bgp) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) config_bgp = { rtr: {"bgp": {"local_as": topo1["routers"][rtr]["bgp"]["local_as"]}} } result = create_router_bgp(tgen, topo1, config_bgp) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) build_config_from_json(tgen, topo1, save_bkup=False) step("verify bgp convergence before starting test case") bgp_convergence = verify_bgp_convergence(tgen, topo1) assert bgp_convergence is True, "Testcase {} : Failed \n Error: {}".format( tc_name, bgp_convergence ) # configure static routes dut = "r3" protocol = "bgp" for addr_type in ADDR_TYPES: # Enable static routes input_dict = { "r1": { "static_routes": [ {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]} ] } } logger.info("Configure static routes") result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) step("configure redistribute static and connected in Router " "BGP in R1") input_dict_2 = { "r1": { "bgp": { "address_family": { addr_type: { "unicast": { "redistribute": [ {"redist_type": "static"}, {"redist_type": "connected"}, ] } } } } } } result = create_router_bgp(tgen, topo, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) step( "BGP neighbors are up, static and connected route advertised from" " R1 are present on R2 BGP table and RIB using show ip bgp and " " show ip route" ) step( "Static and connected route advertised from R1 are present on R3" " BGP table and RIB using show ip bgp and show ip route" ) dut = "r2" protocol = "bgp" result = verify_bgp_rib(tgen, addr_type, dut, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) step("Configure prefix list P1 on R2 to permit route coming from R1") # Create ip prefix list input_dict_2 = { "r2": { "prefix_lists": { addr_type: { "pf_list_1_{}".format(addr_type): [ {"seqid": 10, "network": "any", "action": "permit"} ] } } } } result = create_prefix_lists(tgen, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) # Create route map input_dict_3 = { "r2": { "route_maps": { "rmap_match_pf_1_{}".format(addr_type): [ { "action": "permit", "seq_id": "5", "match": { addr_type: {"prefix_lists": "pf_list_1_" + addr_type} }, "set": {"community": {"num": "no-advertise"}}, } ] } } } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) step( "Apply route-map RM1 on R2, R2 to R3 BGP neighbor with no" " advertise community" ) # Configure neighbor for route map input_dict_4 = { "r2": { "bgp": { "address_family": { addr_type: { "unicast": { "neighbor": { "r1": { "dest_link": { "r2": { "route_maps": [ { "name": "rmap_match_pf_1_" + addr_type, "direction": "in", } ] } } } } } } } } } } result = create_router_bgp(tgen, topo, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) step( "After advertising no advertise community to BGP neighbor " "static and connected router got removed from R3 verify using " "show ip bgp & show ip route" ) result = verify_bgp_rib(tgen, addr_type, dut, input_dict) assert result is True, "Testcase {} : Failed \n " " Routes still present in R3 router. Error: {}".format(tc_name, result) result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n " " Routes still present in R3 router. Error: {}".format(tc_name, result) step("Remove and Add no advertise community") # Configure neighbor for route map input_dict_4 = { "r2": { "bgp": { "address_family": { addr_type: { "unicast": { "neighbor": { "r1": { "dest_link": { "r2": { "route_maps": [ { "name": "rmap_match_pf_1_" + addr_type, "direction": "in", "delete": True, } ] } } } } } } } } } } result = create_router_bgp(tgen, topo, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) step( "After removing no advertise community from BGP neighbor " "static and connected router got advertised to R3 and " "removing route verify using show ip bgp and " " show ip route" ) result = verify_bgp_rib(tgen, addr_type, dut, input_dict) assert result is True, "Testcase {} : Failed \n " " Routes still present in R3 router. Error: {}".format(tc_name, result) result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n " " Routes still present in R3 router. Error: {}".format(tc_name, result) write_test_footer(tc_name)
def test_ospf_routemaps_functionality_tc22_p0(request): """ OSPF Route map - Multiple sequence numbers. Verify OSPF route map support functionality with multiple sequence numbers in a single route-map for different match/set clauses. """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() global topo step("Bring up the base config as per the topology") reset_config_on_routers(tgen) step("Configure route map with seq number 10 to with ip prefix" " permitting route 10.0.20.1/32 in R1") step("Configure route map with seq number 20 to with ip prefix" " permitting route 10.0.20.2/32 in R1") # Create route map input_dict_3 = { "r0": { "route_maps": { "rmap_ipv4": [ { "action": "permit", "seq_id": "10", "match": { "ipv4": { "prefix_lists": "pf_list_1_ipv4" } }, }, { "action": "permit", "seq_id": "20", "match": { "ipv4": { "prefix_lists": "pf_list_2_ipv4" } }, }, ] } } } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create ip prefix list input_dict_2 = { "r0": { "prefix_lists": { "ipv4": { "pf_list_1_ipv4": [{ "seqid": 10, "network": NETWORK["ipv4"][0], "action": "permit" }] } } } } result = create_prefix_lists(tgen, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create ip prefix list input_dict_2 = { "r0": { "prefix_lists": { "ipv4": { "pf_list_2_ipv4": [{ "seqid": 10, "network": NETWORK["ipv4"][1], "action": "permit" }] } } } } result = create_prefix_lists(tgen, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Configure static routes 10.0.20.1/32 and 10.0.20.2 in R1") # Create Static routes input_dict = { "r0": { "static_routes": [{ "network": NETWORK["ipv4"][0], "no_of_ip": 5, "next_hop": "Null0", }] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Configure redistribute static route with route map.") ospf_red_r0 = { "r0": { "ospf": { "redistribute": [{ "redist_type": "static", "route_map": "rmap_ipv4" }] } } } result = create_router_ospf(tgen, topo, ospf_red_r0) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) input_dict = { "r0": { "static_routes": [{ "network": NETWORK["ipv4"][0], "no_of_ip": 2, "next_hop": "Null0", }] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Verify that both routes are learned in R1 and R2") dut = "r1" protocol = "ospf" result = verify_ospf_rib(tgen, dut, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) dut = "r2" protocol = "ospf" result = verify_ospf_rib(tgen, dut, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Change route map with seq number 20 to deny.") # Create route map input_dict_3 = { "r0": { "route_maps": { "rmap_ipv4": [{ "action": "deny", "seq_id": "20", "match": { "ipv4": { "prefix_lists": "pf_list_2_ipv4" } }, }] } } } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Verify the route 10.0.20.2/32 is withdrawn and not present " "in the routing table of R0 and R1.") input_dict = { "r0": { "static_routes": [{ "network": NETWORK["ipv4"][1], "next_hop": "Null0" }] } } dut = "r1" protocol = "ospf" result = verify_ospf_rib(tgen, dut, input_dict, expected=False) assert result is not True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False) assert result is not True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) dut = "r2" protocol = "ospf" result = verify_ospf_rib(tgen, dut, input_dict, expected=False) assert result is not True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False) assert result is not True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name)
def test_ospf_routemaps_functionality_tc25_p0(request): """ OSPF route map support functionality. Verify OSPF route map support functionality when route map actions are toggled. """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() global topo step("Bring up the base config as per the topology") reset_config_on_routers(tgen) step("Create static routes(10.0.20.1/32) in R1 and redistribute " "to OSPF using route map.") # Create Static routes input_dict = { "r0": { "static_routes": [{ "network": NETWORK["ipv4"][0], "no_of_ip": 5, "next_hop": "Null0", }] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) ospf_red_r0 = { "r0": { "ospf": { "redistribute": [{ "redist_type": "static", "route_map": "rmap_ipv4" }] } } } result = create_router_ospf(tgen, topo, ospf_red_r0) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Configure route map with permit rule") # Create route map routemaps = {"r0": {"route_maps": {"rmap_ipv4": [{"action": "permit"}]}}} result = create_route_maps(tgen, routemaps) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Verify that route is advertised to R1.") dut = "r1" protocol = "ospf" result = verify_ospf_rib(tgen, dut, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Configure route map with deny rule") # Create route map routemaps = { "r0": { "route_maps": { "rmap_ipv4": [{ "seq_id": 10, "action": "deny" }] } } } result = create_route_maps(tgen, routemaps) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Api call verify whether OSPF is converged ospf_covergence = verify_ospf_neighbor(tgen, topo) assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( ospf_covergence) step("Verify that route is not advertised to R1.") dut = "r1" protocol = "ospf" result = verify_ospf_rib(tgen, dut, input_dict, expected=False) assert result is not True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False) assert result is not True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name)
def test_bgp_best_path_with_dynamic_import_p0(request): """ TC6_FUNC_6: 1.5.6. Verify BGP best path selection algorithm works fine when routes are imported from ISR to default vrf and vice versa. """ tgen = get_topogen() tc_name = request.node.name write_test_header(tc_name) build_config_from_json(tgen, topo) if tgen.routers_have_failure(): check_router_status(tgen) for addr_type in ADDR_TYPES: step("Redistribute configured static routes into BGP process" " on R1/R2 and R3") input_dict_1 = {} DUT = ["r1", "r2", "r3", "r4"] VRFS = ["ISR", "ISR", "default", "default"] AS_NUM = [100, 100, 300, 400] for dut, vrf, as_num in zip(DUT, VRFS, AS_NUM): temp = {dut: {"bgp": []}} input_dict_1.update(temp) temp[dut]["bgp"].append({ "local_as": as_num, "vrf": vrf, "address_family": { addr_type: { "unicast": { "redistribute": [{ "redist_type": "static" }] } } }, }) result = create_router_bgp(tgen, topo, input_dict_1) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result) for addr_type in ADDR_TYPES: step("Import from default vrf into vrf ISR on R1 and R2 as below") input_dict_vrf = {} DUT = ["r1", "r2"] VRFS = ["ISR", "ISR"] AS_NUM = [100, 100] for dut, vrf, as_num in zip(DUT, VRFS, AS_NUM): temp = {dut: {"bgp": []}} input_dict_vrf.update(temp) temp[dut]["bgp"].append({ "local_as": as_num, "vrf": vrf, "address_family": { addr_type: { "unicast": { "import": { "vrf": "default" } } } }, }) result = create_router_bgp(tgen, topo, input_dict_vrf) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) input_dict_default = {} DUT = ["r1", "r2"] VRFS = ["default", "default"] AS_NUM = [100, 100] for dut, vrf, as_num in zip(DUT, VRFS, AS_NUM): temp = {dut: {"bgp": []}} input_dict_default.update(temp) temp[dut]["bgp"].append({ "local_as": as_num, "vrf": vrf, "address_family": { addr_type: { "unicast": { "import": { "vrf": "ISR" } } } }, }) result = create_router_bgp(tgen, topo, input_dict_default) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Verify ECMP/Next-hop/Imported routes Vs Locally originated " "routes/eBGP routes vs iBGP routes --already covered in almost" " all tests") for addr_type in ADDR_TYPES: step("Verify Pre-emption") input_routes_r3 = { "r3": { "static_routes": [{ "network": [NETWORK3_3[addr_type]] }] } } intf_r3_r1 = topo["routers"]["r3"]["links"]["r1-link1"]["interface"] intf_r4_r1 = topo["routers"]["r4"]["links"]["r1-link1"]["interface"] if addr_type == "ipv6" and "link_local" in PREFERRED_NEXT_HOP: nh_r3_r1 = get_frr_ipv6_linklocal(tgen, "r3", intf=intf_r3_r1) nh_r4_r1 = get_frr_ipv6_linklocal(tgen, "r4", intf=intf_r4_r1) else: nh_r3_r1 = topo["routers"]["r3"]["links"]["r1-link1"][ addr_type].split("/")[0] nh_r4_r1 = topo["routers"]["r4"]["links"]["r1-link1"][ addr_type].split("/")[0] result = verify_bgp_rib(tgen, addr_type, "r1", input_routes_r3, next_hop=[nh_r4_r1]) assert result is True, "Testcase {} : Failed \n Error {}".format( tc_name, result) step("Shutdown interface connected to r1 from r4:") shutdown_bringup_interface(tgen, "r4", intf_r4_r1, False) for addr_type in ADDR_TYPES: input_routes_r3 = { "r3": { "static_routes": [{ "network": [NETWORK3_3[addr_type]] }] } } intf_r3_r1 = topo["routers"]["r3"]["links"]["r1-link1"]["interface"] intf_r4_r1 = topo["routers"]["r4"]["links"]["r1-link1"]["interface"] if addr_type == "ipv6" and "link_local" in PREFERRED_NEXT_HOP: nh_r3_r1 = get_frr_ipv6_linklocal(tgen, "r3", intf=intf_r3_r1) nh_r4_r1 = get_frr_ipv6_linklocal(tgen, "r4", intf=intf_r4_r1) else: nh_r3_r1 = topo["routers"]["r3"]["links"]["r1-link1"][ addr_type].split("/")[0] nh_r4_r1 = topo["routers"]["r4"]["links"]["r1-link1"][ addr_type].split("/")[0] step("Verify next-hop is changed") result = verify_bgp_rib(tgen, addr_type, "r1", input_routes_r3, next_hop=[nh_r3_r1]) assert result is True, "Testcase {} : Failed \n Error {}".format( tc_name, result) step("Bringup interface connected to r1 from r4:") shutdown_bringup_interface(tgen, "r4", intf_r4_r1, True) for addr_type in ADDR_TYPES: input_routes_r3 = { "r3": { "static_routes": [{ "network": [NETWORK3_3[addr_type]] }] } } intf_r3_r1 = topo["routers"]["r3"]["links"]["r1-link1"]["interface"] intf_r4_r1 = topo["routers"]["r4"]["links"]["r1-link1"]["interface"] if addr_type == "ipv6" and "link_local" in PREFERRED_NEXT_HOP: nh_r3_r1 = get_frr_ipv6_linklocal(tgen, "r3", intf=intf_r3_r1) nh_r4_r1 = get_frr_ipv6_linklocal(tgen, "r4", intf=intf_r4_r1) else: nh_r3_r1 = topo["routers"]["r3"]["links"]["r1-link1"][ addr_type].split("/")[0] nh_r4_r1 = topo["routers"]["r4"]["links"]["r1-link1"][ addr_type].split("/")[0] step("Verify next-hop is not chnaged aftr shutdown:") result = verify_bgp_rib(tgen, addr_type, "r1", input_routes_r3, next_hop=[nh_r3_r1]) assert result is True, "Testcase {} : Failed \n Error {}".format( tc_name, result) step("Active-Standby scenario(as-path prepend and Local pref)") for addr_type in ADDR_TYPES: step("Create prefix-list") input_dict_pf = { "r1": { "prefix_lists": { addr_type: { "pf_ls_{}".format(addr_type): [{ "seqid": 10, "network": NETWORK3_4[addr_type], "action": "permit", }] } } } } result = create_prefix_lists(tgen, input_dict_pf) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) for addr_type in ADDR_TYPES: step("Create route-map to match prefix-list and set localpref 500") input_dict_rm = { "r1": { "route_maps": { "rmap_PATH1_{}".format(addr_type): [{ "action": "permit", "seq_id": 10, "match": { addr_type: { "prefix_lists": "pf_ls_{}".format(addr_type) } }, "set": { "locPrf": 500 }, }] } } } result = create_route_maps(tgen, input_dict_rm) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Create route-map to match prefix-list and set localpref 600") input_dict_rm = { "r1": { "route_maps": { "rmap_PATH2_{}".format(addr_type): [{ "action": "permit", "seq_id": 20, "match": { addr_type: { "prefix_lists": "pf_ls_{}".format(addr_type) } }, "set": { "locPrf": 600 }, }] } } } result = create_route_maps(tgen, input_dict_rm) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) input_dict_rma = { "r1": { "bgp": [{ "local_as": "100", "address_family": { addr_type: { "unicast": { "neighbor": { "r3": { "dest_link": { "r1-link1": { "route_maps": [{ "name": "rmap_PATH1_{}".format( addr_type), "direction": "in", }] } } }, "r4": { "dest_link": { "r1-link1": { "route_maps": [{ "name": "rmap_PATH2_{}".format( addr_type), "direction": "in", }] } } }, } } } }, }] } } result = create_router_bgp(tgen, topo, input_dict_rma) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) dut = "r1" attribute = "locPrf" for addr_type in ADDR_TYPES: step("Verify bestpath is installed as per highest localpref") input_routes_r3 = { "r3": { "static_routes": [{ "network": [NETWORK3_3[addr_type], NETWORK3_4[addr_type]] }] } } result = verify_best_path_as_per_bgp_attribute(tgen, addr_type, dut, input_routes_r3, attribute) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) for addr_type in ADDR_TYPES: step("Create route-map to match prefix-list and set localpref 700") input_dict_rm = { "r1": { "route_maps": { "rmap_PATH1_{}".format(addr_type): [{ "action": "permit", "seq_id": 10, "match": { addr_type: { "prefix_lists": "pf_ls_{}".format(addr_type) } }, "set": { "locPrf": 700 }, }] } } } result = create_route_maps(tgen, input_dict_rm) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) for addr_type in ADDR_TYPES: step("Verify bestpath is changed as per highest localpref") input_routes_r3 = { "r3": { "static_routes": [{ "network": [NETWORK3_3[addr_type], NETWORK3_4[addr_type]] }] } } result = verify_best_path_as_per_bgp_attribute(tgen, addr_type, dut, input_routes_r3, attribute) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) for addr_type in ADDR_TYPES: step("Create route-map to match prefix-list and set as-path prepend") input_dict_rm = { "r1": { "route_maps": { "rmap_PATH2_{}".format(addr_type): [{ "action": "permit", "seq_id": 20, "match": { addr_type: { "prefix_lists": "pf_ls_{}".format(addr_type) } }, "set": { "localpref": 700, "path": { "as_num": "111", "as_action": "prepend" }, }, }] } } } result = create_route_maps(tgen, input_dict_rm) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) attribute = "path" for addr_type in ADDR_TYPES: step("Verify bestpath is changed as per shortest as-path") input_routes_r3 = { "r3": { "static_routes": [{ "network": [NETWORK3_3[addr_type], NETWORK3_4[addr_type]] }] } } result = verify_best_path_as_per_bgp_attribute(tgen, addr_type, dut, input_routes_r3, attribute) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name)
def config_for_as_path(tgen, topo, tc_name): config_router_r1(tgen, topo, tc_name) config_router_r2(tgen, topo, tc_name) # Create ipv6 prefix list input_dict_1 = { "r1": { "prefix_lists": { "ipv4": { "pf_list_1": [ { "seqid": "10", "network": "%s/%s" % (NETWORK["ipv4"][0], MASK["ipv4"]), "action": "permit", } ], "pf_list_2": [ { "seqid": "10", "network": "%s/%s" % (NETWORK["ipv4"][1], MASK["ipv4"]), "action": "permit", } ], }, "ipv6": { "pf_list_3": [ { "seqid": "10", "network": "%s/%s" % (NETWORK["ipv6"][0], MASK["ipv6"]), "action": "permit", } ], "pf_list_4": [ { "seqid": "10", "network": "%s/%s" % (NETWORK["ipv6"][1], MASK["ipv6"]), "action": "permit", } ], }, } } } step("Configuring prefix-lists on r1 to filter networks") result = create_prefix_lists(tgen, input_dict_1) assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) input_dict_2 = { "r1": { "route_maps": { "LC1": [ { "action": "permit", "seq_id": 10, "match": {"ipv4": {"prefix_lists": "pf_list_1"}}, "set": { "large_community": {"num": LARGE_COMM["pf_list_1"]}, "community": {"num": STANDARD_COMM["pf_list_1"]}, }, }, { "action": "permit", "seq_id": 20, "match": {"ipv6": {"prefix_lists": "pf_list_3"}}, "set": { "large_community": {"num": LARGE_COMM["pf_list_1"]}, "community": {"num": STANDARD_COMM["pf_list_1"]}, }, }, { "action": "permit", "seq_id": 30, "match": {"ipv4": {"prefix_lists": "pf_list_2"}}, "set": { "large_community": {"num": LARGE_COMM["pf_list_2"]}, "community": {"num": STANDARD_COMM["pf_list_2"]}, }, }, { "action": "permit", "seq_id": 40, "match": {"ipv6": {"prefix_lists": "pf_list_4"}}, "set": { "large_community": {"num": LARGE_COMM["pf_list_2"]}, "community": {"num": STANDARD_COMM["pf_list_2"]}, }, }, ] } } } step( "Applying prefix-lists match in route-map LC1 on r1. Setting" " community attritbute for filtered networks" ) result = create_route_maps(tgen, input_dict_2) assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) config_router_additive(tgen, topo, tc_name) input_dict_3 = { "r4": { "bgp_community_lists": [ { "community_type": "standard", "action": "permit", "name": "ANY", "value": LARGE_COMM["pf_list_1"], "large": True, }, { "community_type": "standard", "action": "permit", "name": "ANY", "value": STANDARD_COMM["pf_list_1"], }, ] } } step("Configuring bgp community lists on r4") result = create_bgp_community_lists(tgen, input_dict_3) assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) input_dict_4 = { "r4": { "route_maps": { "LC4": [ { "action": "permit", "seq_id": "10", "match": { "large_community_list": {"id": "ANY"}, "community_list": {"id": "ANY"}, }, "set": {"path": {"as_num": "4000000", "as_action": "prepend"}}, } ] } } } step("Applying community list on route-map on r4") result = create_route_maps(tgen, input_dict_4) assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) input_dict_5 = { "r4": { "bgp": { "address_family": { "ipv4": { "unicast": { "neighbor": { "r5": { "dest_link": { "r4-link1": { "route_maps": [ {"name": "LC4", "direction": "out"} ] } } } } } }, "ipv6": { "unicast": { "neighbor": { "r5": { "dest_link": { "r4-link1": { "route_maps": [ {"name": "LC4", "direction": "out"} ] } } } } } }, } } } } step("Applying route-map LC4 out from r4 to r5 ") result = create_router_bgp(tgen, topo, input_dict_5) assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result)
def test_route_map_match_only_no_set_p0(request): """ TC_38: Test add/remove route-maps with multiple match clauses and without any set statement.(Match only) """ tgen = get_topogen() # test case name tc_name = request.node.name write_test_header(tc_name) # Creating configuration from JSON reset_config_on_routers(tgen) for adt in ADDR_TYPES: # Create Static routes input_dict = { "r1": { "static_routes": [ { "network": NETWORK[adt][0], "no_of_ip": 1, "next_hop": NEXT_HOP[adt], } ] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) # Api call to redistribute static routes input_dict_1 = { "r1": { "bgp": { "address_family": { "ipv4": { "unicast": { "redistribute": [ {"redist_type": "static"}, {"redist_type": "connected"}, ] } }, "ipv6": { "unicast": { "redistribute": [ {"redist_type": "static"}, {"redist_type": "connected"}, ] } }, } } } } result = create_router_bgp(tgen, topo, input_dict_1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) # Create ip prefix list input_dict_2 = { "r1": { "prefix_lists": { "ipv4": { "pf_list_1_ipv4": [ {"seqid": 10, "network": "any", "action": "permit"} ] }, "ipv6": { "pf_list_1_ipv6": [ {"seqid": 100, "network": "any", "action": "permit"} ] }, } } } result = create_prefix_lists(tgen, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) # Create route map for addr_type in ADDR_TYPES: input_dict_3 = { "r1": { "route_maps": { "rmap_match_pf_1_{}".format(addr_type): [ { "action": "permit", "set": { "metric": 50, "locPrf": 150, }, } ] } } } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) # Configure neighbor for route map input_dict_4 = { "r1": { "bgp": { "address_family": { "ipv4": { "unicast": { "neighbor": { "r3": { "dest_link": { "r1": { "route_maps": [ { "name": "rmap_match_pf_1_ipv4", "direction": "out", } ] } } } } } }, "ipv6": { "unicast": { "neighbor": { "r3": { "dest_link": { "r1": { "route_maps": [ { "name": "rmap_match_pf_1_ipv6", "direction": "out", } ] } } } } } }, } } } } result = create_router_bgp(tgen, topo, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) # Create ip prefix list input_dict_5 = { "r3": { "prefix_lists": { "ipv4": { "pf_list_1_ipv4": [ {"seqid": 10, "network": "any", "action": "permit"} ] }, "ipv6": { "pf_list_1_ipv6": [ {"seqid": 100, "network": "any", "action": "permit"} ] }, } } } result = create_prefix_lists(tgen, input_dict_5) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) # Create route map for addr_type in ADDR_TYPES: input_dict_6 = { "r3": { "route_maps": { "rmap_match_pf_2_{}".format(addr_type): [ { "action": "permit", "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) } }, } ] } } } result = create_route_maps(tgen, input_dict_6) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) # Configure neighbor for route map input_dict_7 = { "r3": { "bgp": { "address_family": { "ipv4": { "unicast": { "neighbor": { "r1": { "dest_link": { "r3": { "route_maps": [ { "name": "rmap_match_pf_2_ipv4", "direction": "in", } ] } } }, "r4": { "dest_link": { "r3": { "route_maps": [ { "name": "rmap_match_pf_2_ipv4", "direction": "out", } ] } } }, } } }, "ipv6": { "unicast": { "neighbor": { "r1": { "dest_link": { "r3": { "route_maps": [ { "name": "rmap_match_pf_2_ipv6", "direction": "in", } ] } } }, "r4": { "dest_link": { "r3": { "route_maps": [ { "name": "rmap_match_pf_2_ipv6", "direction": "out", } ] } } }, } } }, } } } } result = create_router_bgp(tgen, topo, input_dict_7) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) for adt in ADDR_TYPES: # Verifying RIB routes static_routes = [NETWORK[adt][0]] result = verify_bgp_attributes( tgen, adt, "r3", static_routes, "rmap_match_pf_1", input_dict_3 ) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result )
def test_large_community_match_all(request): """ Verify community and large-community list operations in route-map with all clause (exact, all, any, regex) works. """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() # Don"t run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) reset_config_on_routers(tgen) config_router_r1(tgen, topo, tc_name) config_router_r2(tgen, topo, tc_name) config_router_additive(tgen, topo, tc_name) input_dict_1 = { "r4": { "bgp_community_lists": [ { "community_type": "standard", "action": "permit", "name": "ANY", "value": "1:1:1", "large": True, }, { "community_type": "standard", "action": "permit", "name": "ALL", "value": "1:1:1 1:2:1 1:3:1 1:4:1 1:5:1 2:1:1 2:2:1", "large": True, }, { "community_type": "expanded", "action": "permit", "name": "EXP_ALL", "value": "1:1:1 1:2:1 1:3:1 1:4:1 1:5:1 2:[1-5]:1", "large": True, }, ] } } step("Create bgp community lists for ANY, EXACT and EXP_ALL match") result = create_bgp_community_lists(tgen, input_dict_1) assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) input_dict_2 = { "r4": { "route_maps": { "LC4": [ { "action": "permit", "seq_id": "10", "match": {"large-community-list": {"id": "ANY"}}, }, { "action": "permit", "seq_id": "20", "match": {"large-community-list": {"id": "EXACT"}}, }, { "action": "permit", "seq_id": "30", "match": {"large-community-list": {"id": "EXP_ALL"}}, }, ] } } } step("Applying bgp community lits on LC4 route-map") result = create_route_maps(tgen, input_dict_2) assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) input_dict_3 = { "r4": { "bgp": { "address_family": { "ipv4": { "unicast": { "neighbor": { "r5": { "dest_link": { "r4-link1": { "route_maps": [ {"name": "LC4", "direction": "in"} ] } } } } } }, "ipv6": { "unicast": { "neighbor": { "r5": { "dest_link": { "r4-link1": { "route_maps": [ {"name": "LC4", "direction": "in"} ] } } } } } }, } } } } step("Apply route-mpa LC4 on r4 for r2 neighbor, direction 'in'") result = create_router_bgp(tgen, topo, input_dict_3) assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) input_dict_4 = { "largeCommunity": "1:1:1 1:2:1 1:3:1 1:4:1 1:5:1 2:1:1 2:2:1 2:3:1 " "2:4:1 2:5:1" } for adt in ADDR_TYPES: result = verify_bgp_community(tgen, adt, "r4", [NETWORK[adt][0]], input_dict_4) assert result is True, "Test case {} : Should fail \n Error: {}".format( tc_name, result ) write_test_footer(tc_name)
def test_route_map_with_action_values_combination_of_prefix_action_p0( request, prefix_action, rmap_action ): """ TC_36: Test permit/deny statements operation in route-maps with a permutation and combination of permit/deny in prefix-lists """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() # Don"t run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) # Creating configuration from JSON reset_config_on_routers(tgen) for adt in ADDR_TYPES: # Create Static routes input_dict = { "r1": { "static_routes": [ { "network": NETWORK[adt][0], "no_of_ip": 9, "next_hop": NEXT_HOP[adt], } ] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) # Api call to redistribute static routes input_dict_1 = { "r1": { "bgp": { "local_as": 100, "address_family": { "ipv4": { "unicast": { "redistribute": [ {"redist_type": "static"}, {"redist_type": "connected"}, ] } }, "ipv6": { "unicast": { "redistribute": [ {"redist_type": "static"}, {"redist_type": "connected"}, ] } }, }, } } } result = create_router_bgp(tgen, topo, input_dict_1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) # Permit in perfix list and route-map input_dict_2 = { "r3": { "prefix_lists": { "ipv4": { "pf_list_1_ipv4": [ {"seqid": 10, "network": "any", "action": prefix_action} ] }, "ipv6": { "pf_list_1_ipv6": [ {"seqid": 100, "network": "any", "action": prefix_action} ] }, } } } result = create_prefix_lists(tgen, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) # Create route map for addr_type in ADDR_TYPES: input_dict_3 = { "r3": { "route_maps": { "rmap_match_pf_1_{}".format(addr_type): [ { "action": rmap_action, "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) } }, } ] } } } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) # Configure neighbor for route map input_dict_7 = { "r3": { "bgp": { "address_family": { "ipv4": { "unicast": { "neighbor": { "r1": { "dest_link": { "r3": { "route_maps": [ { "name": "rmap_match_pf_1_ipv4", "direction": "in", } ] } } } } } }, "ipv6": { "unicast": { "neighbor": { "r1": { "dest_link": { "r3": { "route_maps": [ { "name": "rmap_match_pf_1_ipv6", "direction": "in", } ] } } } } } }, } } } } result = create_router_bgp(tgen, topo, input_dict_7) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) dut = "r3" protocol = "bgp" input_dict_2 = { "r1": { "static_routes": [ { "network": [NETWORK[adt][0]], "no_of_ip": 9, "next_hop": NEXT_HOP[adt], } ] } } # tgen.mininet_cli() if "deny" in [prefix_action, rmap_action]: result = verify_rib( tgen, adt, dut, input_dict_2, protocol=protocol, expected=False ) assert result is not True, ("Testcase {} : Failed \n " "Routes are still present \n Error: {}".format(tc_name, result)) logger.info("Expected behaviour: {}".format(result)) else: result = verify_rib( tgen, adt, dut, input_dict_2, protocol=protocol ) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result )
def test_static_routes_rmap_pfxlist_p0_tc7_ibgp(request): """ Verify static route are blocked from route-map & prefix-list applied in BGP nbrs """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() # Don't run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) reset_config_on_routers(tgen) step("Configure holddown timer = 1 keep alive = 3 in all the neighbors") step("verify bgp convergence before starting test case") bgp_convergence = verify_bgp_convergence(tgen, topo) assert bgp_convergence is True, "Testcase {} : Failed \n Error: {}".format( tc_name, bgp_convergence ) step( "Configure 4 IPv4 and 4 IPv6 nbrs with password with mismatch " " authentication between FRR routers " ) for addr_type in ADDR_TYPES: # Api call to modfiy BGP timerse input_dict = { "r2": { "bgp": { "local_as": "200", "address_family": { addr_type: { "unicast": { "neighbor": { "r1": { "dest_link": { "r2-link0": {"password": "******"}, "r2-link1": {"password": "******"}, "r2-link2": {"password": "******"}, "r2-link3": {"password": "******"}, } }, "r3": { "dest_link": { "r2-link0": {"password": "******"}, "r2-link1": {"password": "******"}, "r2-link2": {"password": "******"}, "r2-link3": {"password": "******"}, } }, } } } }, } } } result = create_router_bgp(tgen, topo, deepcopy(input_dict)) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result ) clear_bgp(tgen, addr_type, "r2") step(" All BGP nbrs are down as authentication is mismatch on both" " the sides") bgp_convergence = verify_bgp_convergence(tgen, topo, expected=False) assert bgp_convergence is not True, "Testcase {} : " "Failed \n BGP nbrs must be down. Error: {}".format(tc_name, bgp_convergence) step( "Configure 4 IPv4 and 4 IPv6 nbrs with macthing password " " authentication between FRR routers " ) for addr_type in ADDR_TYPES: input_dict = { "r2": { "bgp": { "local_as": "200", "address_family": { addr_type: { "unicast": { "neighbor": { "r1": { "dest_link": { "r2-link0": {"password": "******"}, "r2-link1": {"password": "******"}, "r2-link2": {"password": "******"}, "r2-link3": {"password": "******"}, } }, "r3": { "dest_link": { "r2-link0": {"password": "******"}, "r2-link1": {"password": "******"}, "r2-link2": {"password": "******"}, "r2-link3": {"password": "******"}, } }, } } } }, } } } result = create_router_bgp(tgen, topo, deepcopy(input_dict)) assert result is True, "Testcase {} :Failed \n Error: {}".format( tc_name, result ) step("All BGP nbrs are up as authentication is matched now") bgp_convergence = verify_bgp_convergence(tgen, topo) assert bgp_convergence is True, "Testcase {} : Failed \n " "Error: {}".format( tc_name, bgp_convergence ) step("Create prefix list P1 to permit VM3 & deny VM1 v4 & v6 routes") step("Create prefix list P2 to permit VM6 IPv4 and IPv6 routes") for addr_type in ADDR_TYPES: input_dict_2 = { "r2": { "prefix_lists": { addr_type: { "pf_list_1_{}".format(addr_type): [ { "seqid": 10, "network": topo["routers"]["r2"]["links"]["vm3"][ addr_type ], "action": "permit", }, { "seqid": 20, "network": topo["routers"]["r2"]["links"]["vm1"][ addr_type ], "action": "deny", }, ], "pf_list_2_{}".format(addr_type): [ { "seqid": 10, "network": topo["routers"]["r2"]["links"]["vm6"][ addr_type ], "action": "permit", } ], } } } } result = create_prefix_lists(tgen, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) step( "Prefix list created with matching networks deny or permit " "show ip prefix list" ) result = verify_prefix_lists(tgen, input_dict_2) assert result is not True, "Testcase {} : Failed \n" " Error: {}".format(tc_name, result) step("Redistribute all the routes (connected, static)") input_dict_2_r1 = { "r1": { "bgp": { "address_family": { addr_type: { "unicast": {"redistribute": [{"redist_type": "static"}]} } } } } } result = create_router_bgp(tgen, topo, input_dict_2_r1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) input_dict_2_r2 = { "r2": { "bgp": { "address_family": { addr_type: { "unicast": {"redistribute": [{"redist_type": "static"}]} } } } } } result = create_router_bgp(tgen, topo, input_dict_2_r2) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) input_dict_2_r3 = { "r3": { "bgp": { "address_family": { addr_type: { "unicast": {"redistribute": [{"redist_type": "static"}]} } } } } } result = create_router_bgp(tgen, topo, input_dict_2_r3) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) step("configure redistribute connected in Router BGP") input_dict_2_r1 = { "r1": { "bgp": { "address_family": { addr_type: { "unicast": {"redistribute": [{"redist_type": "connected"}]} } } } } } result = create_router_bgp(tgen, topo, input_dict_2_r1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) input_dict_2_r3 = { "r3": { "bgp": { "address_family": { addr_type: { "unicast": {"redistribute": [{"redist_type": "connected"}]} } } } } } result = create_router_bgp(tgen, topo, input_dict_2_r3) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) input_dict_2 = { "r2": { "bgp": { "address_family": { addr_type: { "unicast": {"redistribute": [{"redist_type": "connected"}]} } } } } } result = create_router_bgp(tgen, topo, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) step("Apply prefix list P1 on BGP neighbors 1 2 3 4 connected from " "frr r1") # Configure prefix list to bgp neighbor input_dict_4 = { "r2": { "bgp": { "address_family": { addr_type: { "unicast": { "neighbor": { "r1": { "dest_link": { "r2-link0": { "prefix_lists": [ { "name": "pf_list_1_{}".format( addr_type ), "direction": "out", } ] }, "r2-link1": { "prefix_lists": [ { "name": "pf_list_1_{}".format( addr_type ), "direction": "out", } ] }, "r2-link2": { "prefix_lists": [ { "name": "pf_list_1_{}".format( addr_type ), "direction": "out", } ] }, "r2-link3": { "prefix_lists": [ { "name": "pf_list_1_{}".format( addr_type ), "direction": "out", } ] }, } } } } } } } } } result = create_router_bgp(tgen, topo, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) step("Apply prefix list P2 on BGP nbrs 5 & 6 connected from FRR-2") # Configure prefix list to bgp neighbor input_dict_4 = { "r2": { "bgp": { "address_family": { addr_type: { "unicast": { "neighbor": { "r3": { "dest_link": { "r2-link0": { "prefix_lists": [ { "name": "pf_list_2_{}".format( addr_type ), "direction": "out", } ] }, "r2-link1": { "prefix_lists": [ { "name": "pf_list_2_{}".format( addr_type ), "direction": "out", } ] }, "r2-link2": { "prefix_lists": [ { "name": "pf_list_2_{}".format( addr_type ), "direction": "out", } ] }, "r2-link3": { "prefix_lists": [ { "name": "pf_list_2_{}".format( addr_type ), "direction": "out", } ] }, } } } } } } } } } result = create_router_bgp(tgen, topo, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) clear_bgp_and_verify(tgen, topo, "r2") step( "VM1 IPv4 and IPv6 Route which is denied using prefix list is " "not present on FRR1 side routing table , also not able to " "ping the routes show ip route" ) dut = "r1" protocol = "bgp" ntwk_r2_vm1 = str( ipaddress.ip_interface( u"{}".format(topo["routers"]["r2"]["links"]["vm1"][addr_type]) ).network ) input_dict = {"r1": {"static_routes": [{"network": ntwk_r2_vm1}]}} result4 = verify_rib( tgen, addr_type, dut, input_dict, protocol=protocol, expected=False ) assert result4 is not True, "Testcase {} : Failed , VM1 route is " "not filtered out via prefix list. \n Error: {}".format(tc_name, result4) step( "VM4 and VM6 IPV4 and IPv6 address are present in local and " "FRR2 routing table show ip bgp show ip route" ) dut = "r2" ntwk_r2_vm6 = str( ipaddress.ip_interface( u"{}".format(topo["routers"]["r2"]["links"]["vm6"][addr_type]) ).network ) input_dict = {"r3": {"static_routes": [{"network": ntwk_r2_vm6}]}} result4 = verify_rib(tgen, addr_type, dut, input_dict) assert result4 is True, "Testcase {} : Failed.\n Error: {}".format( tc_name, result4 ) step("Remove prefix list from all the neighbors") input_dict_4 = { "r2": { "bgp": { "address_family": { addr_type: { "unicast": { "neighbor": { "r1": { "dest_link": { "r2-link0": { "prefix_lists": [ { "name": "pf_list_1_{}".format( addr_type ), "direction": "out", "delete": True, } ] }, "r2-link1": { "prefix_lists": [ { "name": "pf_list_1_{}".format( addr_type ), "direction": "out", "delete": True, } ] }, "r2-link2": { "prefix_lists": [ { "name": "pf_list_1_{}".format( addr_type ), "direction": "out", "delete": True, } ] }, "r2-link3": { "prefix_lists": [ { "name": "pf_list_1_{}".format( addr_type ), "direction": "out", "delete": True, } ] }, } } } } } } } } } result = create_router_bgp(tgen, topo, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) input_dict_4 = { "r2": { "bgp": { "address_family": { addr_type: { "unicast": { "neighbor": { "r3": { "dest_link": { "r2-link0": { "prefix_lists": [ { "name": "pf_list_2_{}".format( addr_type ), "direction": "out", "delete": True, } ] }, "r2-link1": { "prefix_lists": [ { "name": "pf_list_2_{}".format( addr_type ), "direction": "out", "delete": True, } ] }, "r2-link2": { "prefix_lists": [ { "name": "pf_list_2_{}".format( addr_type ), "direction": "out", "delete": True, } ] }, "r2-link3": { "prefix_lists": [ { "name": "pf_list_2_{}".format( addr_type ), "direction": "out", "delete": True, } ] }, } } } } } } } } } result = create_router_bgp(tgen, topo, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) clear_bgp_and_verify(tgen, topo, "r2") step("Create RouteMap_1 with prefix list P1 and weight 50") # Create route map rmap_dict = { "r2": { "route_maps": { "rmap_pf_list_1_{}".format(addr_type): [ { "action": "permit", "set": {"weight": 50}, "match": { addr_type: { "prefix_lists": "pf_list_1_{}".format(addr_type) } }, } ] } } } result = create_route_maps(tgen, rmap_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) step("Create RouteMap_2 with prefix list P2 and weight 50") # Create route map rmap_dict = { "r2": { "route_maps": { "rmap_pf_list_2_{}".format(addr_type): [ { "action": "permit", "set": {"weight": 50}, "match": { addr_type: { "prefix_lists": "pf_list_2_{}".format(addr_type) } }, } ] } } } result = create_route_maps(tgen, rmap_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) step("Verify Route-map created verify using show route-map") # verify rmap_pf_list_1 and rmap_pf_list_2 are present in router r2 input_dict = { "r2": { "route_maps": [ "rmap_pf_list_1_{}".format(addr_type), "rmap_pf_list_2_{}".format(addr_type), ] } } result = verify_route_maps(tgen, input_dict, expected=False) assert result is not True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) step("Apply policy RouteMap_1 nbrs 1 2 3 4 to FRR 1") # Configure prefix list to bgp neighbor input_dict_4 = { "r2": { "bgp": { "address_family": { addr_type: { "unicast": { "neighbor": { "r1": { "dest_link": { "r2-link0": { "route_maps": [ { "name": "rmap_pf_list_1_" "{}".format(addr_type), "direction": "out", } ] }, "r2-link1": { "route_maps": [ { "name": "rmap_pf_list_1_" "{}".format(addr_type), "direction": "out", } ] }, "r2-link2": { "route_maps": [ { "name": "rmap_pf_list_1_" "{}".format(addr_type), "direction": "out", } ] }, "r2-link3": { "route_maps": [ { "name": "rmap_pf_list_1_" "{}".format(addr_type), "direction": "out", } ] }, } } } } } } } } } result = create_router_bgp(tgen, topo, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) step("Apply policy RouteMap_2 nbrs 5 and 6 to FRR2") # Configure prefix list to bgp neighbor input_dict_4 = { "r2": { "bgp": { "address_family": { addr_type: { "unicast": { "neighbor": { "r3": { "dest_link": { "r2-link0": { "route_maps": [ { "name": "rmap_pf_list_2_" "{}".format(addr_type), "direction": "out", } ] }, "r2-link1": { "route_maps": [ { "name": "rmap_pf_list_2_" "{}".format(addr_type), "direction": "out", } ] }, "r2-link2": { "route_maps": [ { "name": "rmap_pf_list_2_" "{}".format(addr_type), "direction": "out", } ] }, "r2-link3": { "route_maps": [ { "name": "rmap_pf_list_2_" "{}".format(addr_type), "direction": "out", } ] }, } } } } } } } } } result = create_router_bgp(tgen, topo, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) step( "After applying to BGP neighbors verify VM1 IPv4 and IPv6 Route" " which is denied using prefix list is not present on FRR side" " routing table , also not able to ping the routes show ip route" " and VM4 and VM6 IPV4 and IPv6 address are present in local and" " FRR routing table show ip bgp show ip route" ) dut = "r1" protocol = "bgp" ntwk_r2_vm1 = str( ipaddress.ip_interface( u"{}".format(topo["routers"]["r2"]["links"]["vm1"][addr_type]) ).network ) input_dict = {"r1": {"static_routes": [{"network": ntwk_r2_vm1}]}} result4 = verify_rib( tgen, addr_type, dut, input_dict, protocol=protocol, expected=False ) assert ( result4 is not True ), "Testcase {} : Failed \n" "routes are still present \n Error: {}".format( tc_name, result4 ) step("vm4 should be present in FRR1") dut = "r1" ntwk_r2_vm1 = str( ipaddress.ip_interface( u"{}".format(topo["routers"]["r1"]["links"]["vm4"][addr_type]) ).network ) input_dict = {"r1": {"static_routes": [{"network": ntwk_r2_vm1}]}} result4 = verify_rib(tgen, addr_type, dut, input_dict) assert result4 is True, "Testcase {} : Failed , VM1 route is " "not filtered out via prefix list. \n Error: {}".format(tc_name, result4) step("vm4 should be present in FRR2") dut = "r2" ntwk_r2_vm1 = str( ipaddress.ip_interface( u"{}".format(topo["routers"]["r1"]["links"]["vm4"][addr_type]) ).network ) input_dict = {"r1": {"static_routes": [{"network": ntwk_r2_vm1}]}} result4 = verify_rib(tgen, addr_type, dut, input_dict) assert result4 is True, "Testcase {} : Failed , VM1 route is " "not filtered out via prefix list. \n Error: {}".format(tc_name, result4) dut = "r3" protocol = "bgp" ntwk_r2_vm6 = str( ipaddress.ip_interface( u"{}".format(topo["routers"]["r2"]["links"]["vm6"][addr_type]) ).network ) input_dict = {"r3": {"static_routes": [{"network": ntwk_r2_vm6}]}} result4 = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol) assert result4 is True, "Testcase {} : Failed.\n Error: {}".format( tc_name, result4 ) write_test_footer(tc_name)
def test_route_map_set_only_no_match_p0(request): """ TC_37: Test add/remove route-maps with multiple set clauses and without any match statement.(Set only) """ tgen = get_topogen() # test case name tc_name = request.node.name write_test_header(tc_name) # Creating configuration from JSON reset_config_on_routers(tgen) for adt in ADDR_TYPES: # Create Static routes input_dict = { "r1": { "static_routes": [ { "network": NETWORK[adt][0], "no_of_ip": 1, "next_hop": NEXT_HOP[adt], } ] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) # Api call to redistribute static routes input_dict_1 = { "r1": { "bgp": { "address_family": { "ipv4": { "unicast": { "redistribute": [ {"redist_type": "static"}, {"redist_type": "connected"}, ] } }, "ipv6": { "unicast": { "redistribute": [ {"redist_type": "static"}, {"redist_type": "connected"}, ] } }, } } } } result = create_router_bgp(tgen, topo, input_dict_1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) # Create route map input_dict_3 = { "r3": { "route_maps": { "rmap_match_pf_1": [ { "action": "permit", "set": {"metric": 50, "locPrf": 150, "weight": 4000}, } ] } } } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) # Configure neighbor for route map input_dict_4 = { "r3": { "bgp": { "address_family": { "ipv4": { "unicast": { "neighbor": { "r1": { "dest_link": { "r3": { "route_maps": [ { "name": "rmap_match_pf_1", "direction": "in", } ] } } }, "r4": { "dest_link": { "r3": { "route_maps": [ { "name": "rmap_match_pf_1", "direction": "out", } ] } } }, } } }, "ipv6": { "unicast": { "neighbor": { "r1": { "dest_link": { "r3": { "route_maps": [ { "name": "rmap_match_pf_1", "direction": "in", } ] } } }, "r4": { "dest_link": { "r3": { "route_maps": [ { "name": "rmap_match_pf_1", "direction": "out", } ] } } }, } } }, } } } } result = create_router_bgp(tgen, topo, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) time.sleep(2) for adt in ADDR_TYPES: input_dict_4 = { "r3": { "route_maps": { "rmap_match_pf_1": [ { "action": "permit", "set": { "metric": 50, }, } ] } } } # Verifying RIB routes static_routes = [NETWORK[adt][0]] result = verify_bgp_attributes( tgen, adt, "r3", static_routes, "rmap_match_pf_1", input_dict_3 ) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result ) result = verify_bgp_attributes( tgen, adt, "r4", static_routes, "rmap_match_pf_1", input_dict_4 ) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result ) logger.info("Testcase " + tc_name + " :Passed \n")
def test_bgp_allowas_in_no_of_occurrences_p0(request): """ Verify that the if number of occurrences of AS number in path is more than the configured allowas-in value then we do not accept the route. """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() reset_config_on_routers(tgen) # Don't run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) dut = "r3" protocol = "bgp" for addr_type in ADDR_TYPES: # Enable static routes static_routes = { "r1": { "static_routes": [ {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]} ] } } logger.info("Configure static routes") result = create_static_routes(tgen, static_routes) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) step("configure redistribute static in Router BGP in R1") input_dict_2 = { "r1": { "bgp": { "address_family": { addr_type: { "unicast": {"redistribute": [{"redist_type": "static"}]} } } } } } result = create_router_bgp(tgen, topo, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) step("Configure a route-map on R1 to prepend AS 4 times.") for addr_type in ADDR_TYPES: input_dict_4 = { "r1": { "route_maps": { "ASP_{}".format(addr_type): [ { "action": "permit", "set": { "path": { "as_num": "200 200 200 200", "as_action": "prepend", } }, } ] } } } result = create_route_maps(tgen, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) step("configure route map in out direction on R1") # Configure neighbor for route map input_dict_7 = { "r1": { "bgp": { "address_family": { addr_type: { "unicast": { "neighbor": { "r2": { "dest_link": { "r1": { "route_maps": [ { "name": "ASP_{}".format( addr_type ), "direction": "out", } ] } } } } } } } } } } result = create_router_bgp(tgen, topo, input_dict_7) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) for addr_type in ADDR_TYPES: step('Configure "allowas-in 4" on R3 for R2.') # Api call to enable allowas-in in bgp process. input_dict_1 = { "r3": { "bgp": { "address_family": { addr_type: { "unicast": { "neighbor": { "r2": { "dest_link": { "r3": { "allowas-in": {"number_occurences": 4} } } } } } } } } } } result = create_router_bgp(tgen, topo, input_dict_1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) result = verify_rib( tgen, addr_type, dut, static_routes, protocol=protocol, expected=False ) assert result is not True, ( "Testcase {} : Failed \n ".format(tc_name) + "Expected behavior: routes are should not be present in rib\n" + "Error: {}".format(result) ) for addr_type in ADDR_TYPES: step('Configure "allowas-in 5" on R3 for R2.') input_dict_1 = { "r3": { "bgp": { "address_family": { addr_type: { "unicast": { "neighbor": { "r2": { "dest_link": { "r3": { "allowas-in": {"number_occurences": 5} } } } } } } } } } } result = create_router_bgp(tgen, topo, input_dict_1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) static_routes = { "r1": { "static_routes": [ {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]} ] } } result = verify_rib(tgen, addr_type, dut, static_routes, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) write_test_footer(tc_name)
def test_static_route_with_tag_p0_tc_13_ebgp(request): """ Verify static route with tag option """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() # Don't run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) step("Configure 8 links between R1 and R2") step("Configure 1 links between R2 and R3") NEXT_HOP_IP = populate_nh() step("Configure 2 IPv4 static route (S1 and S2) in R2 with same" "next hop N1 28.1.1.2") step("Configure static route S1 with tag 1 and static route S2 with" "tag2") step("S1= ip route 10.1.1.1/24 28.1.1.2 tag 1") step("S2= ip route 20.1.1.1/24 28.1.1.2 tag 2") step("Enable redistribute static in BGP with route-map") reset_config_on_routers(tgen) for addr_type in ADDR_TYPES: # Enable static routes input_dict_4 = { "r2": { "static_routes": [ { "network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP["nh1"][addr_type], "tag": 4001, }, { "network": NETWORK2[addr_type], "next_hop": NEXT_HOP_IP["nh1"][addr_type], "tag": 4002, }, ] } } logger.info("Configure static routes") result = create_static_routes(tgen, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("verify routes are present in RIB") dut = "r2" protocol = "static" nh = NEXT_HOP_IP["nh1"][addr_type] result = verify_rib(tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol) assert ( result is True ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format( tc_name) step("Configure route-map on R2 with allow tag1 and deny tag2") # Create route map input_dict_3 = { "r2": { "route_maps": { "rmap_match_tag_1_{}".format(addr_type): [ { "action": "permit", "seq_id": 10, "match": { addr_type: { "tag": "4001" } }, }, { "action": "deny", "seq_id": 20, "match": { addr_type: { "tag": "4002" } }, }, ] } } } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_4 = { "r2": { "bgp": { "address_family": { addr_type: { "unicast": { "neighbor": { "r3": { "dest_link": { "r2-link0": { "route_maps": [{ "name": "rmap_match_tag_1_ipv4", "direction": "out", }] } } } }, "redistribute": [{ "redist_type": "static" }], } } } } } } result = create_router_bgp(tgen, topo, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Verify static route S1 advetised in BGP table when tag1 permit" "in route-map else it is denied") dut = "r3" input_dict_0 = { "r2": { "static_routes": [{ "network": NETWORK2[addr_type], "next_hop": NEXT_HOP_IP["nh1"][addr_type], "tag": 4002, }] } } result = verify_rib(tgen, addr_type, dut, input_dict_0, protocol=protocol, expected=False) assert result is not True, ( "Testcase {} : Failed \nError: Route with " "tag 4002 is still present in RIB".format(tc_name)) dut = "r2" input_dict_1 = { "r2": { "static_routes": [{ "network": NETWORK[addr_type], "tag": 4001 }] } } result = verify_rib(tgen, addr_type, dut, input_dict_0, protocol=protocol) assert result is True, ("Testcase {} : Failed \nError: Route with " "tag 4001 is missing in RIB".format(tc_name)) step("Modify the route-map to allow tag2 and deny tag1") # Create route map input_dict_3 = { "r2": { "route_maps": { "rmap_match_tag_1_{}".format(addr_type): [ { "action": "deny", "seq_id": 10, "match": { addr_type: { "tag": "4001" } }, }, { "action": "permit", "seq_id": 20, "match": { addr_type: { "tag": "4002" } }, }, ] } } } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) dut = "r3" step("Verify static route S2 advertised in BGP table when tag2" "permit in route-map else it is denied") protocol = "bgp" input_dict_0 = { "r2": { "static_routes": [{ "network": NETWORK2[addr_type], "tag": 4002 }] } } result = verify_rib(tgen, addr_type, dut, input_dict_0, protocol=protocol) assert result is True, ("Testcase {} : Failed \nError: Route with " "tag 4002 is missing in RIB".format(tc_name)) input_dict_1 = { "r2": { "static_routes": [{ "network": NETWORK[addr_type], "tag": 4001 }] } } result = verify_rib(tgen, addr_type, dut, input_dict_1, protocol=protocol, expected=False) assert result is not True, ( "Testcase {} : Failed \nError: Route with " "tag 4001 is still present in RIB".format(tc_name)) step("Configure one static route with 2 ECMP nexthop N1 and N2") step("For N1 configure tag 1 and for N2 configure tag 2") step("S1= ip route 10.1.1.1/24 28.1.1.2 tag 1") step("S1= ip route 10.1.1.1/24 29.1.1.2 tag 2") step("configure the route-map to allow tag1 and deny tag 2") step("Modify the route-map to allow tag2 and deny tag1") for addr_type in ADDR_TYPES: # Enable static routes input_dict_4 = { "r2": { "static_routes": [ { "network": NETWORK2[addr_type], "next_hop": NEXT_HOP_IP["nh1"][addr_type], "tag": 4001, }, { "network": NETWORK2[addr_type], "next_hop": NEXT_HOP_IP["nh2"][addr_type], "tag": 4002, }, ] } } logger.info("Configure static routes") result = create_static_routes(tgen, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) dut = "r2" protocol = "static" result = verify_rib(tgen, addr_type, dut, input_dict_4, protocol=protocol, fib=True) assert ( result is True ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format( tc_name) step("shut/no shut of tag1 and tag2 nexthop") intf = topo["routers"]["r2"]["links"]["r1-link0"]["interface"] shutdown_bringup_interface(tgen, dut, intf, False) shutdown_bringup_interface(tgen, dut, intf, True) step("configure one static route with 3 next-hop") step("N1-tag1, N2-tag2, N3-tag3") step("S1= ip route 10.1.1.1/24 28.1.1.2 tag 1") step("S1= ip route 10.1.1.1/24 29.1.1.2 tag 2") step("S1= ip route 10.1.1.1/24 28.1.1.2 tag 3") for addr_type in ADDR_TYPES: # Enable static routes input_dict_4 = { "r2": { "static_routes": [ { "network": NETWORK2[addr_type], "next_hop": NEXT_HOP_IP["nh1"][addr_type], "tag": 4001, }, { "network": NETWORK2[addr_type], "next_hop": NEXT_HOP_IP["nh2"][addr_type], "tag": 4002, }, { "network": NETWORK2[addr_type], "next_hop": NEXT_HOP_IP["nh3"][addr_type], "tag": 4003, }, ] } } logger.info("Configure static routes") result = create_static_routes(tgen, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) dut = "r2" protocol = "static" result = verify_rib(tgen, addr_type, dut, input_dict_4, protocol=protocol) step("configure the route-map to allow tag2 & tag3 and deny tag1") # Create route map input_dict_3 = { "r2": { "route_maps": { "rmap_match_tag_1_{}".format(addr_type): [ { "action": "deny", "seq_id": 10, "match": { addr_type: { "tag": "4001" } }, }, { "action": "permit", "seq_id": 20, "match": { addr_type: { "tag": "4002" } }, }, { "action": "permit", "seq_id": 30, "match": { addr_type: { "tag": "4003" } }, }, ] } } } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Verify static route advertised in BGP table with tag3" " nexthop if tag2 is down") dut = "r3" protocol = "bgp" result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("shut / no shut of tag2 and tag3 next-hop") intf = topo["routers"]["r2"]["links"]["r1-link1"]["interface"] shutdown_bringup_interface(tgen, dut, intf, False) intf = topo["routers"]["r2"]["links"]["r1-link2"]["interface"] shutdown_bringup_interface(tgen, dut, intf, False) step("shut/no shut of tag2 and tag3 nexthop") intf = topo["routers"]["r2"]["links"]["r1-link1"]["interface"] shutdown_bringup_interface(tgen, dut, intf, True) intf = topo["routers"]["r2"]["links"]["r1-link2"]["interface"] shutdown_bringup_interface(tgen, dut, intf, True) step("Verify after shut/noshut of nexthop BGP table updated correctly") dut = "r3" protocol = "bgp" result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name)
def test_bgp_allowas_in_sameastoebgp_p1(request): """ Verify that when we advertise a network, learned from the same AS via allowas-in command, to an eBGP neighbor we see multiple occurrences of our own AS based on configured value+1. """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() reset_config_on_routers(tgen) # Don't run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) dut = "r3" protocol = "bgp" for addr_type in ADDR_TYPES: # Enable static routes static_routes = { "r1": { "static_routes": [ {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]} ] } } logger.info("Configure static routes") result = create_static_routes(tgen, static_routes) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) step("configure redistribute static in Router BGP in R1") input_dict_2 = { "r1": { "bgp": { "address_family": { addr_type: { "unicast": {"redistribute": [{"redist_type": "static"}]} } } } } } result = create_router_bgp(tgen, topo, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) step("Configure a route-map on R2 to prepend AS 2 times.") for addr_type in ADDR_TYPES: input_dict_4 = { "r2": { "route_maps": { "ASP_{}".format(addr_type): [ { "action": "permit", "set": { "path": {"as_num": "200 200", "as_action": "prepend"} }, } ] } } } result = create_route_maps(tgen, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) step("configure route map in out direction on R2") # Configure neighbor for route map input_dict_7 = { "r2": { "bgp": { "address_family": { addr_type: { "unicast": { "neighbor": { "r3": { "dest_link": { "r2": { "route_maps": [ { "name": "ASP_{}".format( addr_type ), "direction": "out", } ] } } } } } } } } } } result = create_router_bgp(tgen, topo, input_dict_7) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) for addr_type in ADDR_TYPES: step('Configure "allowas-in 3" on R3 for R1.') input_dict_1 = { "r3": { "bgp": { "address_family": { addr_type: { "unicast": { "neighbor": { "r2": { "dest_link": { "r3": { "allowas-in": {"number_occurences": 3} } } } } } } } } } } result = create_router_bgp(tgen, topo, input_dict_1) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) static_routes = { "r1": { "static_routes": [ {"network": NETWORK[addr_type], "next_hop": NEXT_HOP_IP[addr_type]} ] } } dut = "r5" path = "200 100 200 200 200" result = verify_bgp_rib(tgen, addr_type, dut, static_routes, aspath=path) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) write_test_footer(tc_name)
def test_ospf_routemaps_functionality_tc24_p0(request): """ OSPF Route map - Multiple set clauses. Verify OSPF route map support functionality when we add/remove route-maps with multiple match clauses and without any set statement.(Match only) """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() global topo step("Bring up the base config as per the topology") reset_config_on_routers(tgen) step("Create static routes(10.0.20.1/32) in R1 and redistribute to " "OSPF using route map.") # Create Static routes input_dict = { "r0": { "static_routes": [{ "network": NETWORK["ipv4"][0], "no_of_ip": 1, "next_hop": "Null0", }] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) ospf_red_r0 = { "r0": { "ospf": { "redistribute": [{ "redist_type": "static", "route_map": "rmap_ipv4" }] } } } result = create_router_ospf(tgen, topo, ospf_red_r0) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create ip prefix list pfx_list = { "r0": { "prefix_lists": { "ipv4": { "pf_list_1_ipv4": [{ "seqid": 10, "network": "any", "action": "permit" }] } } } } result = create_prefix_lists(tgen, pfx_list) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("verify that prefix-list is created in R0.") result = verify_prefix_lists(tgen, pfx_list) assert result is not True, ("Testcase {} : Failed \n Prefix list not " "present. Error: {}".format(tc_name, result)) # Create route map routemaps = { "r0": { "route_maps": { "rmap_ipv4": [{ "action": "permit", "match": { "ipv4": { "prefix_lists": "pf_list_1_ipv4" } }, }] } } } result = create_route_maps(tgen, routemaps) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Verify that metric falls back to original metric for ospf routes.") dut = "r1" protocol = "ospf" result = verify_ospf_rib(tgen, dut, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Create static routes(10.0.20.1/32) in R1 and redistribute to " "OSPF using route map.") # Create Static routes input_dict = { "r0": { "static_routes": [{ "network": NETWORK["ipv4"][1], "no_of_ip": 1, "next_hop": "Null0", "tag": 1000, }] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create ip prefix list pfx_list = { "r0": { "prefix_lists": { "ipv4": { "pf_list_1_ipv4": [{ "seqid": 10, "network": "any", "action": "permit" }] } } } } result = create_prefix_lists(tgen, pfx_list) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("verify that prefix-list is created in R0.") result = verify_prefix_lists(tgen, pfx_list) assert result is not True, ("Testcase {} : Failed \n Prefix list not " "present. Error: {}".format(tc_name, result)) # Create route map routemaps = { "r0": { "route_maps": { "rmap_ipv4": [{ "action": "permit", "match": { "ipv4": { "tag": "1000" } } }] } } } result = create_route_maps(tgen, routemaps) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Verify that metric falls back to original metric for ospf routes.") dut = "r1" protocol = "ospf" result = verify_ospf_rib(tgen, dut, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Delete the match clause with tag in route map") # Create route map routemaps = { "r0": { "route_maps": { "rmap_ipv4": [{ "action": "permit", "match": { "ipv4": { "tag": "1000", "delete": True } }, }] } } } result = create_route_maps(tgen, routemaps) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Verify that metric falls back to original metric for ospf routes.") dut = "r1" protocol = "ospf" result = verify_ospf_rib(tgen, dut, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) step("Delete the match clause with metric in route map.") # Create route map routemaps = { "r0": { "route_maps": { "rmap_ipv4": [{ "action": "permit", "match": { "ipv4": { "prefix_lists": "pf_list_1_ipv4" } }, }] } } } result = create_route_maps(tgen, routemaps) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_ospf_rib(tgen, dut, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name)
def test_med_attribute(request): " Verifying MED attribute functionality" tgen = get_topogen() # Don't run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) # test case name tc_name = request.node.name write_test_header(tc_name) # Creating configuration from JSON reset_config_on_routers(tgen) # Api call to advertise networks input_dict = { "r4": { "bgp":{ "address_family": { "ipv4": { "unicast": { "advertise_networks": [ { "network": "200.50.2.0/32" }, { "network": "200.60.2.0/32" } ] } } } } } } result = create_router_bgp(tgen, topo, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Api call to advertise networks # Configure next-hop-self to bgp neighbor # Create Prefix list input_dict_3 = { "r2": { "prefix_lists": { "ipv4": { "pf_ls_r2": [{ "seqid": 10, "network": "200.0.0.0/8", "le": "32", "action": "permit" }] } } }, "r3": { "prefix_lists": { "ipv4": { "pf_ls_r3": [{ "seqid": 10, "network": "200.0.0.0/8", "le": "32", "action": "permit" }] } } } } result = create_prefix_lists(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Create route map input_dict_3 = { "r2": { "route_maps": { "RMAP_MED_R2": [{ "action": "permit", "match": { "ipv4": { "prefix_lists": "pf_ls_r2" } }, "set": { "med": 100 } }] } }, "r3": { "route_maps": { "RMAP_MED_R3": [{ "action": "permit", "match": { "ipv4": { "prefix_lists": "pf_ls_r3" } }, "set": { "med": 10 } }] } } } result = create_route_maps(tgen, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Configure neighbor for route map input_dict_4 = { "r5": { "bgp": { "address_family": { "ipv4": { "unicast": { "advertise_networks": [ { "network": "200.50.2.0/32" }, { "network": "200.60.2.0/32" } ] } } } } }, "r2": { "bgp": { "address_family": { "ipv4": { "unicast": { "neighbor": { "r4": { "dest_link": { "r2-link1": { "route_maps": [ {"name": "RMAP_MED_R2", "direction": "in"} ] } } }, "r1": { "dest_link": { "r2": {"next_hop_self": True} } } } } } } } }, "r3": { "bgp": { "address_family": { "ipv4": { "unicast": { "neighbor": { "r1": { "dest_link": { "r3": {"next_hop_self": True} } }, "r5": { "dest_link": { "r3": { "route_maps": [ {"name": "RMAP_MED_R3", "direction": "in"} ] } } } } } } } } } } result = create_router_bgp(tgen, topo, input_dict_4) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) # Verifying best path dut = "r1" attribute = "med" result = verify_best_path_as_per_bgp_attribute(tgen, "ipv4", dut, input_dict, attribute) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result) logger.info("Testcase %s :Passed \n", tc_name)