def test_large_community_invalid_chars(request): """ BGP canonical lcommunities must only be digits """ 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) input_dict = { "r4": { "bgp_community_lists": [ { "community_type": "standard", "action": "permit", "name": "ANY", "value": "1:a:2", "large": True, } ] } } step("Checking boundary value for community 1:a:2") result = create_bgp_community_lists(tgen, input_dict) assert result is not True, "Test case {} : Failed \n Error: {}".format( tc_name, result )
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_verify_deleting_re_adding_route_map_with_iBGP_peers_p0(request): """ Verify graceful-shutdown functionality after deleting/re-adding route-map with iBGP peers """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() reset_config_on_routers(tgen) step("Done in base config: Configure base config as per the topology") step("Base config should be up, verify using BGP convergence") result = verify_bgp_convergence(tgen, topo) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) step("Done in base config: Advertise prefixes from R1") step("Verify BGP routes are received at R4 with best path from R3 to R1") for addr_type in ADDR_TYPES: dut = "r4" next_hop1 = next_hop_per_address_family(tgen, "r4", "r2", addr_type, NEXT_HOP_IP_1) next_hop2 = next_hop_per_address_family(tgen, "r4", "r3", addr_type, NEXT_HOP_IP_2) input_topo = {key: topo["routers"][key] for key in ["r1"]} result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop=[next_hop1, next_hop2]) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, addr_type, dut, input_topo, next_hop=[next_hop1, next_hop2]) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) step("On R1 configure:") step("Create standard bgp community-list to permit graceful-shutdown:") input_dict_1 = { "r1": { "bgp_community_lists": [{ "community_type": "standard", "action": "permit", "name": "GSHUT", "value": "graceful-shutdown", }] } } result = create_bgp_community_lists(tgen, input_dict_1) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) step("Create route-map to set community GSHUT in OUT direction") input_dict_2 = { "r1": { "route_maps": { "GSHUT-OUT": [{ "action": "permit", "seq_id": "10", "set": { "community": { "num": "graceful-shutdown" } }, }] } } } result = create_route_maps(tgen, input_dict_2) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) input_dict_3 = { "r1": { "bgp": { "address_family": { "ipv4": { "unicast": { "neighbor": { "r3": { "dest_link": { "r1": { "route_maps": [{ "name": "GSHUT-OUT", "direction": "out", }] } } } } } }, "ipv6": { "unicast": { "neighbor": { "r3": { "dest_link": { "r1": { "route_maps": [{ "name": "GSHUT-OUT", "direction": "out", }] } } } } } }, } } } } result = create_router_bgp(tgen, topo, input_dict_3) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) step( "FRR is setting local-pref to 0 by-default on receiver GSHUT community, " "below step is not needed, but keeping for reference") step("On R3, apply route-map IN direction to match GSHUT community " "and set local-preference to 0.") step("Verify BGP convergence on R4 and ensure all the neighbours state " "is established") result = verify_bgp_convergence(tgen, topo) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) step("Verify BGP routes on R4:") step("local pref for routes coming from R1 is set to 0.") for addr_type in ADDR_TYPES: rmap_dict = { "r1": { "route_maps": { "GSHUT-OUT": [{ "set": { "locPrf": 0 } }], } } } static_routes = [NETWORK[addr_type]] result = verify_bgp_attributes(tgen, addr_type, dut, static_routes, "GSHUT-OUT", rmap_dict) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) step("Ensure that best path is selected from R4 to R3.") for addr_type in ADDR_TYPES: dut = "r4" next_hop1 = next_hop_per_address_family(tgen, "r4", "r2", addr_type, NEXT_HOP_IP_1) next_hop2 = next_hop_per_address_family(tgen, "r4", "r3", addr_type, NEXT_HOP_IP_2) input_topo = {key: topo["routers"][key] for key in ["r1"]} result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop=[next_hop1, next_hop2]) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, addr_type, dut, input_topo, next_hop=next_hop1) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) step("Delete route-map from R1") del_rmap_dict = { "r1": { "route_maps": { "GSHUT-OUT": [{ "action": "permit", "seq_id": "10", "set": { "community": { "num": "graceful-shutdown", "delete": True } }, }] } } } result = create_route_maps(tgen, del_rmap_dict) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) step("Verify BGP convergence on R3 and ensure that all neighbor state " "is established") result = verify_bgp_convergence(tgen, topo) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) step("Verify BGP routes on R4:") step("Ensure that best path is selected from R1->R3") for addr_type in ADDR_TYPES: dut = "r4" next_hop1 = next_hop_per_address_family(tgen, "r4", "r2", addr_type, NEXT_HOP_IP_1) next_hop2 = next_hop_per_address_family(tgen, "r4", "r3", addr_type, NEXT_HOP_IP_2) input_topo = {key: topo["routers"][key] for key in ["r1"]} result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop=[next_hop1]) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, addr_type, dut, input_topo, next_hop=[next_hop1]) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) step("Re-add route-map in R1") result = create_route_maps(tgen, input_dict_2) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) step("Verify BGP convergence on R3 and ensure all the neighbours state " "is established") result = verify_bgp_convergence(tgen, topo) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) step("Verify BGP routes on R4:") step("local pref for routes coming from R1 is set to 0.") for addr_type in ADDR_TYPES: rmap_dict = { "r1": { "route_maps": { "GSHUT-OUT": [{ "set": { "locPrf": 0 } }] } } } static_routes = [NETWORK[addr_type]] result = verify_bgp_attributes(tgen, addr_type, dut, static_routes, "GSHUT-OUT", rmap_dict) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) step("Ensure that best path is selected from R4 to R3.") for addr_type in ADDR_TYPES: dut = "r4" next_hop1 = next_hop_per_address_family(tgen, "r4", "r2", addr_type, NEXT_HOP_IP_1) next_hop2 = next_hop_per_address_family(tgen, "r4", "r3", addr_type, NEXT_HOP_IP_2) input_topo = {key: topo["routers"][key] for key in ["r1"]} result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop=[next_hop1, next_hop2]) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) result = verify_rib(tgen, addr_type, dut, input_topo, next_hop=next_hop1) assert result is True, "Test case {} : Failed \n Error: {}".format( tc_name, result) write_test_footer(tc_name)
def test_large_community_match_all(request): """ Verify community and large-community list operations in route-map with all clause (exact, all, any, regex) works. """ tc_name = request.node.name write_test_header(tc_name) tgen = get_topogen() # Don"t run this test if we have any failure. if tgen.routers_have_failure(): pytest.skip(tgen.errors) reset_config_on_routers(tgen) config_router_r1(tgen, topo, tc_name) config_router_r2(tgen, topo, tc_name) config_router_additive(tgen, topo, tc_name) input_dict_1 = { "r4": { "bgp_community_lists": [ { "community_type": "standard", "action": "permit", "name": "ANY", "value": "1:1:1", "large": True, }, { "community_type": "standard", "action": "permit", "name": "ALL", "value": "1:1:1 1:2:1 1:3:1 1:4:1 1:5:1 2:1:1 2:2:1", "large": True, }, { "community_type": "expanded", "action": "permit", "name": "EXP_ALL", "value": "1:1:1 1:2:1 1:3:1 1:4:1 1:5:1 2:[1-5]:1", "large": True, }, ] } } step("Create bgp community lists for ANY, EXACT and EXP_ALL match") result = create_bgp_community_lists(tgen, input_dict_1) assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) input_dict_2 = { "r4": { "route_maps": { "LC4": [ { "action": "permit", "seq_id": "10", "match": {"large-community-list": {"id": "ANY"}}, }, { "action": "permit", "seq_id": "20", "match": {"large-community-list": {"id": "EXACT"}}, }, { "action": "permit", "seq_id": "30", "match": {"large-community-list": {"id": "EXP_ALL"}}, }, ] } } } step("Applying bgp community lits on LC4 route-map") result = create_route_maps(tgen, input_dict_2) assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) input_dict_3 = { "r4": { "bgp": { "address_family": { "ipv4": { "unicast": { "neighbor": { "r5": { "dest_link": { "r4-link1": { "route_maps": [ {"name": "LC4", "direction": "in"} ] } } } } } }, "ipv6": { "unicast": { "neighbor": { "r5": { "dest_link": { "r4-link1": { "route_maps": [ {"name": "LC4", "direction": "in"} ] } } } } } }, } } } } step("Apply route-mpa LC4 on r4 for r2 neighbor, direction 'in'") result = create_router_bgp(tgen, topo, input_dict_3) assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result) input_dict_4 = { "largeCommunity": "1:1:1 1:2:1 1:3:1 1:4:1 1:5:1 2:1:1 2:2:1 2:3:1 " "2:4:1 2:5:1" } for adt in ADDR_TYPES: result = verify_bgp_community(tgen, adt, "r4", [NETWORK[adt][0]], input_dict_4) assert result is True, "Test case {} : Should fail \n Error: {}".format( tc_name, result ) write_test_footer(tc_name)
def 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_large_community_boundary_values(request): """ Verify that any value in BGP Large communities for boundary values. """ 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) input_dict = { "r4": { "bgp_community_lists": [ { "community_type": "standard", "action": "permit", "name": "ANY", "value": "0:-1", } ] } } step("Checking boundary value for community 0:-1") result = create_bgp_community_lists(tgen, input_dict) assert result is not True, "Test case {} : Failed \n Error: {}".format( tc_name, result ) step("Checking community attribute 0:65536") input_dict_2 = { "r4": { "bgp_community_lists": [ { "community_type": "standard", "action": "permit", "name": "ANY", "value": "0:65536", } ] } } step("Checking boundary value for community 0:65536") result = create_bgp_community_lists(tgen, input_dict_2) assert result is not True, "Test case {} : Failed \n Error: {}".format( tc_name, result ) step("Checking boundary value for community 0:4294967296") input_dict_3 = { "r4": { "bgp_community_lists": [ { "community_type": "standard", "action": "permit", "name": "ANY", "value": "0:4294967296", "large": True, } ] } } result = create_bgp_community_lists(tgen, input_dict_3) assert result is not True, "Test case {} : Failed \n Error: {}".format( tc_name, result ) step("Checking boundary value for community 0:-1:1") input_dict_4 = { "r4": { "bgp_community_lists": [ { "community_type": "standard", "action": "permit", "name": "ANY", "value": "0:-1:1", "large": True, } ] } } result = create_bgp_community_lists(tgen, input_dict_4) assert result is not True, "Test case {} : Failed \n Error: {}".format( tc_name, result )