def test_delete_prefix_lists(request): """ Delete ip prefix list """ tgen = get_topogen() if BGP_CONVERGENCE is not True: pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = request.node.name write_test_header(tc_name) # Creating configuration from JSON reset_config_on_routers(tgen) # Create ip prefix list input_dict_2 = { "r1": { "prefix_lists": { "ipv4": { "pf_list_1": [ {"seqid": "10", "network": "10.0.20.1/32", "action": "deny"} ] } } } } result = create_prefix_lists(tgen, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) result = verify_prefix_lists(tgen, input_dict_2) assert result is not True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) # Delete prefix list input_dict_2 = { "r1": { "prefix_lists": { "ipv4": { "pf_list_1": [ { "seqid": "10", "network": "10.0.20.1/32", "action": "deny", "delete": True, } ] } } } } result = create_prefix_lists(tgen, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) result = verify_prefix_lists(tgen, input_dict_2) assert result is True, "Testcase {} : 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 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 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_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_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_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_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_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_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)
def test_ext_nh_cap_admin_dist_tag_ibgp_peer_p1(request): """ Test extended capability nexthop with admin distance and route tag. Verify IPv4 routes are advertised to peer when static routes are configured with ADMIN distance and 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) reset_config_on_routers(tgen) step( "Configure IPv6 EBGP session between R1 and R2 with global IPv6" " address Enable capability extended-nexthop on the nbr from both" " the routers" ) step( "Change ebgp to ibgp nbrs between r1 and r2 , Activate same IPv6" " nbr from IPv4 unicast family " ) step( " Configure 5 IPv4 static routes" " on R1 nexthop for static route exists on different link of R0" ) count = 0 for rte in range(0, NO_OF_RTES): count += 1 # Create Static routes input_dict = { "r1": { "static_routes": [ { "network": NETWORK["ipv4"][rte], "no_of_ip": 1, "next_hop": NEXT_HOP["ipv4"][rte], "admin_distance": 100 + count, "tag": 4001 + count, } ] } } result = create_static_routes(tgen, input_dict) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) step( "Advertise static routes from IPv4 unicast family & IPv6 unicast" " family respectively from R1.Configure loopback on R1 with IPv4 " "address & Advertise loopback from IPv4 unicast family " "using network cmd from R1" ) configure_bgp_on_r1 = { "r1": { "bgp": { "address_family": { "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}} } } } } result = create_router_bgp(tgen, topo, configure_bgp_on_r1) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) glip = get_llip("r1", "r2-link0") assert glip is not None, "Testcase {} : Failed \n Error: {}".format(tc_name, result) step( "IPv4 and IPv6 routes advertised using static & network cmd are" "received on R2 BGP and routing table , verify using show ip bgp" "show ip route for IPv4 routes and show bgp, show ipv6 routes" "for IPv6 routes ." ) dut = "r2" protocol = "bgp" count = 0 # verify the routes with nh as ext_nh verify_nh_for_static_rtes = { "r1": { "static_routes": [ { "network": NETWORK["ipv4"][0], "no_of_ip": NO_OF_RTES, "next_hop": glip, "admin_distance": 100 + count, "tag": 4001 + count, } ] } } bgp_rib = verify_bgp_rib( tgen, "ipv4", dut, verify_nh_for_static_rtes, next_hop=glip ) assert bgp_rib is True, "Testcase {} : Failed \n Error: {}".format(tc_name, bgp_rib) result = verify_rib( tgen, "ipv4", dut, verify_nh_for_static_rtes, next_hop=glip, protocol=protocol ) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) count = 0 for rte in range(0, NO_OF_RTES): count += 10 input_dict_2 = { "r3": { "prefix_lists": { "ipv4": { "pf_list_1_ipv4": [ { "seqid": 0 + count, "action": "permit", "network": NETWORK["ipv4"][rte], } ] } } } } 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_6 = { "r3": { "route_maps": { "rmap_match_tag_1_{}".format("ipv4"): [ { "action": "deny", "match": { "ipv4": {"prefix_lists": "pf_list_1_{}".format("ipv4")} }, } ] } } } 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 = { "r1": { "bgp": { "address_family": { "ipv6": { "unicast": { "neighbor": { "r2": { "dest_link": { "r1-link0": { "route_maps": [ { "name": "rmap_match_tag_1_ipv4", "direction": "out", } ] } } } } } } } } } } result = create_router_bgp(tgen, topo, input_dict_7) assert result is True, "Testcase {} : Failed \n Error: {}".format( tc_name, result ) write_test_footer(tc_name)
def test_modify_prefix_lists_out_permit_to_deny(request): """ Modify ip prefix list and test permit to deny prefixes OUT direction """ tgen = get_topogen() if BGP_CONVERGENCE is not True: pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = request.node.name write_test_header(tc_name) # Creating configuration from JSON reset_config_on_routers(tgen) # Create Static Routes input_dict = { "r1": { "static_routes": [ {"network": "10.0.20.1/32", "no_of_ip": 9, "next_hop": "10.0.0.2"} ] } } 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 # Create ip prefix list input_dict_1 = { "r3": { "prefix_lists": { "ipv4": { "pf_list_1": [ { "seqid": "10", "network": "10.0.0.0/8", "le": "32", "action": "permit", } ] } } } } result = create_prefix_lists(tgen, input_dict_1) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Configure prefix list to bgp neighbor input_dict_2 = { "r1": { "bgp": { "address_family": { "ipv4": { "unicast": { "redistribute": [ {"redist_type": "static"}, {"redist_type": "connected"}, ] } } } } }, "r3": { "bgp": { "address_family": { "ipv4": { "unicast": { "neighbor": { "r4": { "dest_link": { "r3": { "prefix_lists": [ { "name": "pf_list_1", "direction": "out", } ] } } } } } } } } }, } result = create_router_bgp(tgen, topo, input_dict_2) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r4" protocol = "bgp" result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Modify ip prefix list input_dict_1 = { "r3": { "prefix_lists": { "ipv4": { "pf_list_1": [ { "seqid": "10", "network": "10.0.0.0/8", "le": "32", "action": "deny", }, {"seqid": "11", "network": "any", "action": "permit"}, ] } } } } result = create_prefix_lists(tgen, input_dict_1) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Api call to clear bgp, so config changes would be reflected dut = "r3" result = clear_bgp_and_verify(tgen, topo, dut) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r4" protocol = "bgp" result = verify_rib( tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False ) assert ( result is not True ), "Testcase {} : Failed \n Error: Routes still" " present in RIB".format(tc_name) write_test_footer(tc_name)
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_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_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 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_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_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_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_ip_prefix_lists_in_permit(request): """ Create ip prefix list and test permit prefixes IN direction """ tgen = get_topogen() if BGP_CONVERGENCE is not True: pytest.skip("skipped because of BGP Convergence failure") # test case name tc_name = request.node.name write_test_header(tc_name) # Create Static routes input_dict = { "r1": { "static_routes": [ {"network": "20.0.20.1/32", "no_of_ip": 1, "next_hop": "10.0.0.2"} ] } } result = create_static_routes(tgen, input_dict) 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": [{"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) # Configure bgp neighbor with prefix list input_dict_3 = { "r1": { "bgp": { "address_family": { "ipv4": { "unicast": { "redistribute": [ {"redist_type": "static"}, {"redist_type": "connected"}, ] } } } } }, "r3": { "bgp": { "address_family": { "ipv4": { "unicast": { "neighbor": { "r1": { "dest_link": { "r3": { "prefix_lists": [ {"name": "pf_list_1", "direction": "in"} ] } } } } } } } } }, } result = create_router_bgp(tgen, topo, input_dict_3) assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) # Verifying RIB routes dut = "r3" protocol = "bgp" 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)