def test_large_community_advertise(request):
    """
    Verify that the community attribute value, which we have advertised are
    received in correct format and values, at the receiving end.
    """
    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)

    input_dict = {
        "largeCommunity": LARGE_COMM["r1"],
        "community": STANDARD_COMM["r1"],
    }

    for adt in ADDR_TYPES:
        result = verify_bgp_community(tgen, adt, "r2", [NETWORK[adt][0]], input_dict)
        assert result is True, "Test case {} : Failed \n Error: {}".format(
            tc_name, result
        )

        result = verify_bgp_community(tgen, adt, "r3", [NETWORK[adt][0]], input_dict)
        assert result is True, "Test case {} : Failed \n Error: {}".format(
            tc_name, result
        )

    write_test_footer(tc_name)
def test_large_community_after_clear_bgp(request):
    """
    Clear BGP neighbor-ship and check if large community and community
    attributes are getting re-populated.
    """
    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)

    input_dict = {"largeCommunity": LARGE_COMM["r1"], "community": STANDARD_COMM["r1"]}

    for adt in ADDR_TYPES:
        result = verify_bgp_community(tgen, adt, "r2", [NETWORK[adt][0]], input_dict)
        assert result is True, "Test case {} : Failed \n Error: {}".format(
            tc_name, result
        )

    step("Clearing BGP on r1")
    clear_bgp_and_verify(tgen, topo, "r1")

    for adt in ADDR_TYPES:
        result = verify_bgp_community(tgen, adt, "r2", [NETWORK[adt][0]], input_dict)
        assert result is True, "Test case {} : Failed \n Error: {}".format(
            tc_name, result
        )

    write_test_footer(tc_name)
def test_large_community_additive(request):
    """
    Verify that large community values" aggregation works fine.
    """
    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 = {
        "largeCommunity": "%s %s" % (LARGE_COMM["r1"], LARGE_COMM["r2"]),
        "community": "%s %s" % (STANDARD_COMM["r1"], STANDARD_COMM["r2"]),
    }

    for adt in ADDR_TYPES:
        result = verify_bgp_community(tgen, adt, "r4", [NETWORK[adt][0]], input_dict_1)
        assert result is True, "Test case {} : Failed \n Error: {}".format(
            tc_name, result
        )

    write_test_footer(tc_name)
def test_large_community_transitive(request):
    """
    Verify BGP Large Community attribute"s transitive property attribute.
    """
    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)

    input_dict_1 = {
        "largeCommunity": LARGE_COMM["r1"],
        "community": STANDARD_COMM["r1"],
    }

    for adt in ADDR_TYPES:
        result = verify_bgp_community(tgen, adt, "r4", [NETWORK[adt][0]], input_dict_1)
        assert result is True, "Test case {} : Failed \n Error: {}".format(
            tc_name, result
        )

    write_test_footer(tc_name)
def test_large_community_match_as_path(request):
    """
    Matching prefixes based on attributes other than prefix list and make use
    of set clause.
    """

    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_for_as_path(tgen, topo, tc_name)

    input_dict = {
        "largeCommunity": "%s %s" % (LARGE_COMM["pf_list_1"], LARGE_COMM["r2"]),
        "community": "%s %s" % (STANDARD_COMM["pf_list_1"], STANDARD_COMM["r2"]),
    }

    input_dict_1 = {
        "largeCommunity": "%s %s" % (LARGE_COMM["pf_list_2"], LARGE_COMM["r2"]),
        "community": "%s %s" % (STANDARD_COMM["pf_list_2"], STANDARD_COMM["r2"]),
    }

    for adt in ADDR_TYPES:
        result = verify_bgp_community(tgen, adt, "r5", [NETWORK[adt][0]], input_dict)
        assert result is True, "Test case {} : Failed \n Error: {}".format(
            tc_name, result
        )

        result = verify_bgp_community(
            tgen, adt, "r5", [NETWORK[adt][1]], input_dict_1, expected=False
        )

        assert result is not True, "Test case {} : Should fail \n Error: {}".format(
            tc_name, result
        )

    write_test_footer(tc_name)
Пример #6
0
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_large_community_aggregate_network(request):
    """
    Restart router and check if large community and community
    attributes are getting re-populated.
    """

    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_for_as_path(tgen, topo, tc_name)

    input_dict = {
        "community": STANDARD_COMM["agg_1"],
        "largeCommunity": LARGE_COMM["agg_1"],
    }

    input_dict_1 = {
        "r2": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "aggregate_address": [
                                {
                                    "network": "%s/%s"
                                    % (NETWORK["ipv4"][2], NET_MASK["ipv4"]),
                                    "as_set": True,
                                }
                            ]
                        }
                    },
                    "ipv6": {
                        "unicast": {
                            "aggregate_address": [
                                {
                                    "network": "%s/%s"
                                    % (NETWORK["ipv6"][2], NET_MASK["ipv6"]),
                                    "as_set": True,
                                }
                            ]
                        }
                    },
                }
            }
        }
    }

    step("Configuring aggregate address as-set on r2")
    result = create_router_bgp(tgen, topo, input_dict_1)
    assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result)

    for adt in ADDR_TYPES:
        result = verify_bgp_community(
            tgen, adt, "r4", ["%s/%s" % (NETWORK[adt][2], NET_MASK[adt])], input_dict
        )
        assert result is True, "Test case {} : Failed \n Error: {}".format(
            tc_name, result
        )

    input_dict_2 = {
        "r1": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "advertise_networks": [
                                {
                                    "network": "%s/%s"
                                    % (NETWORK["ipv4"][0], MASK["ipv4"]),
                                    "no_of_network": 1,
                                    "delete": True,
                                }
                            ]
                        }
                    },
                    "ipv6": {
                        "unicast": {
                            "advertise_networks": [
                                {
                                    "network": "%s/%s"
                                    % (NETWORK["ipv6"][0], MASK["ipv6"]),
                                    "no_of_network": 1,
                                    "delete": True,
                                }
                            ]
                        }
                    },
                }
            }
        }
    }

    step("Stop advertising one of the networks")
    result = create_router_bgp(tgen, topo, input_dict_2)
    assert result is True, "Test case {} : Failed \n Error: {}".format(tc_name, result)

    input_dict_3 = {
        "community": STANDARD_COMM["agg_2"],
        "largeCommunity": LARGE_COMM["agg_2"],
    }

    for adt in ADDR_TYPES:
        step("Verifying bgp community values on r5 is also modified")
        result = verify_bgp_community(
            tgen, adt, "r4", ["%s/%s" % (NETWORK[adt][2], NET_MASK[adt])], input_dict_3
        )
        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)