def test_admin_distance_for_existing_static_routes(request):
    """Test to modify and verify admin distance for existing static routes."""

    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)

    input_dict = {
        "r1": {
            "static_routes": [
                {
                    "network": "10.0.20.1/32",
                    "admin_distance": 10,
                    "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)

    # Verifying admin distance  once modified
    result = verify_admin_distance_for_static_routes(tgen, input_dict)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    write_test_footer(tc_name)
Esempio n. 2
0
def test_route_summarisation_with_summary_only_p1(request):
    """
    Verify route summarisation with summary-only for redistributed as well as
    locally generated 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],
                    ],
                    "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],
                    ]
                }]
            }
        }

        result = verify_rib(tgen, addr_type, "r3", input_static)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    step("Advertise some prefixes using network command")
    step("Additionally advertise 10.1.4.0/24 & 10.1.5.0/24 and "
         "10:1::4:0/120 & 10:1::5:0/120 from R4 to R1.")

    for addr_type in ADDR_TYPES:
        input_advertise = {
            "r1": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "advertise_networks": [{
                                    "network": [
                                        NETWORK_2_1[addr_type],
                                        NETWORK_2_2[addr_type],
                                        NETWORK_2_3[addr_type],
                                        NETWORK_2_4[addr_type],
                                    ]
                                }]
                            }
                        }
                    }
                }
            },
            "r4": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "advertise_networks": [{
                                    "network": [
                                        NETWORK_1_4[addr_type],
                                        NETWORK_1_5[addr_type],
                                    ]
                                }]
                            }
                        }
                    }
                }
            },
        }

        result = create_router_bgp(tgen, topo, input_advertise)
        assert result is True, "Testcase {} :Failed \n Error: {}".format(
            tc_name, result)

    step("Verify that advertised prefixes using network command are being "
         "advertised in BGP process")

    for addr_type in ADDR_TYPES:
        input_advertise = {
            "r1": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "advertise_networks": [{
                                    "network": [
                                        NETWORK_2_1[addr_type],
                                        NETWORK_2_2[addr_type],
                                        NETWORK_2_3[addr_type],
                                        NETWORK_2_4[addr_type],
                                    ]
                                }]
                            }
                        }
                    }
                }
            }
        }

        result = verify_rib(tgen, addr_type, "r3", input_advertise)
        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],
                                    "summary":
                                    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 1 summarised route and remaining suppressed "
         "routes on advertising router R1 and only 1 summarised route on "
         "receiving router R3 for both AFIs.")

    for addr_type in ADDR_TYPES:
        input_static_agg = {
            "r1": {
                "static_routes": [{
                    "network": AGGREGATE_NW[addr_type]
                }]
            }
        }

        input_static = {
            "r1": {
                "static_routes": [{
                    "network": [
                        NETWORK_1_1[addr_type],
                        NETWORK_1_2[addr_type],
                        NETWORK_1_3[addr_type],
                    ]
                }]
            }
        }

        result = verify_rib(tgen,
                            addr_type,
                            "r3",
                            input_static_agg,
                            protocol="bgp")
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        result = verify_rib(tgen,
                            addr_type,
                            "r3",
                            input_static,
                            protocol="bgp",
                            expected=False)
        assert (
            result is not True
        ), "Testcase {} : Failed \n " "Routes are still present \n Error: {}".format(
            tc_name, result)

        result = verify_rib(tgen,
                            addr_type,
                            "r1",
                            input_static_agg,
                            protocol="bgp")
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        result = verify_rib(tgen, addr_type, "r1", input_static)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    for action, value in zip(["removed", "add"], [True, False]):

        step("{} static routes as below: "
             "(no) ip route 10.1.1.0/24 and (no) ip route 10.1.2.0/24"
             "(no) ipv6 route 10:1::1:0/120 and (no) ip route 10:1::2:0/120".
             format(action))

        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":
                        value,
                    }]
                }
            }

            result = create_static_routes(tgen, input_static)
            assert result is True, "Testcase {} : Failed \n Error: {}".format(
                tc_name, result)

        step(
            "Verify that there is no impact on R3, as summarised route remains "
            "intact. However suppressed routes on R1 disappear and re-appear "
            "based on {} static routes.".format(action))

        for addr_type in ADDR_TYPES:
            input_static_1 = {
                "r1": {
                    "static_routes": [{
                        "network":
                        [NETWORK_1_1[addr_type], NETWORK_1_2[addr_type]]
                    }]
                }
            }

            input_static_2 = {
                "r1": {
                    "static_routes": [{
                        "network": AGGREGATE_NW[addr_type]
                    }]
                }
            }

            if value:
                result = verify_rib(tgen,
                                    addr_type,
                                    "r1",
                                    input_static_1,
                                    expected=False)
                assert (
                    result is not True
                ), "Testcase {} : Failed \n Routes are still present \n Error: {}".format(
                    tc_name, result)
            else:
                result = verify_rib(tgen, addr_type, "r1", input_static_1)
                assert result is True, "Testcase {} : Failed \n Error: {}".format(
                    tc_name, result)

            result = verify_rib(tgen,
                                addr_type,
                                "r3",
                                input_static_2,
                                protocol="bgp")
            assert result is True, "Testcase {} : Failed \n Error: {}".format(
                tc_name, result)

        step(
            "{} prefixes using network command as below:"
            "(no) network 10.1.6.1/24 and (no) network 10.1.7.1/24"
            "(no) network 10:1::6:0/120 and (no) network 10:1::7:0/120".format(
                action))

        for addr_type in ADDR_TYPES:
            input_advertise = {
                "r1": {
                    "bgp": {
                        "address_family": {
                            addr_type: {
                                "unicast": {
                                    "advertise_networks": [{
                                        "network": [
                                            NETWORK_2_3[addr_type],
                                            NETWORK_2_4[addr_type],
                                        ],
                                        "delete":
                                        value,
                                    }]
                                }
                            }
                        }
                    }
                }
            }

            result = create_router_bgp(tgen, topo, input_advertise)
            assert result is True, "Testcase {} :Failed \n Error: {}".format(
                tc_name, result)

        step(
            "Verify that there is no impact on R3, as summarised route remains "
            "intact. However suppressed routes on R1 disappear and re-appear "
            "based on {} of network command.".format(action))

        for addr_type in ADDR_TYPES:
            input_advertise_1 = {
                "r1": {
                    "bgp": {
                        "address_family": {
                            addr_type: {
                                "unicast": {
                                    "advertise_networks": [{
                                        "network": [
                                            NETWORK_2_3[addr_type],
                                            NETWORK_2_4[addr_type],
                                        ]
                                    }]
                                }
                            }
                        }
                    }
                }
            }

            input_advertise_2 = {
                "r1": {
                    "bgp": {
                        "address_family": {
                            addr_type: {
                                "unicast": {
                                    "advertise_networks": [{
                                        "network":
                                        AGGREGATE_NW[addr_type]
                                    }]
                                }
                            }
                        }
                    }
                }
            }

            if value:
                result = verify_bgp_rib(tgen,
                                        addr_type,
                                        "r1",
                                        input_advertise_1,
                                        expected=False)
                assert result is not True, (
                    "Testcase {} : Failed \n "
                    "Routes are still present \n Error: {}".format(
                        tc_name, result))
            else:
                result = verify_bgp_rib(tgen, addr_type, "r1",
                                        input_advertise_1)
                assert result is True, "Testcase {} : Failed \n Error: {}".format(
                    tc_name, result)

            result = verify_rib(tgen, addr_type, "r3", input_advertise_2)
            assert result is True, "Testcase {} : Failed \n Error: {}".format(
                tc_name, result)

    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],
                    "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:
        input_advertise = {
            "r1": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "advertise_networks": [{
                                    "network":
                                    NETWORK_4_1[addr_type],
                                }]
                            }
                        }
                    }
                }
            }
        }

        result = create_router_bgp(tgen, topo, input_advertise)
        assert result is True, "Testcase {} :Failed \n Error: {}".format(
            tc_name, result)

    step("Verify that when a network within aggregation range is added, "
         "there is no impact on receiving router. However if a network "
         "outside aggregation range is added/removed, R3 receives and "
         "withdraws it accordingly.")

    for addr_type in ADDR_TYPES:
        input_static = {
            "r1": {
                "static_routes": [{
                    "network": AGGREGATE_NW[addr_type]
                }]
            }
        }

        result = verify_rib(tgen,
                            addr_type,
                            "r3",
                            input_static,
                            protocol="bgp")
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        input_advertise_2 = {
            "r1": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "advertise_networks": [{
                                    "network": [
                                        NETWORK_4_1[addr_type],
                                        AGGREGATE_NW[addr_type],
                                    ]
                                }]
                            }
                        }
                    }
                }
            }
        }

        result = verify_rib(tgen,
                            addr_type,
                            "r3",
                            input_advertise_2,
                            protocol="bgp")
        assert result is True, "Testcase {} : 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],
                                        "summary":
                                        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 on both routers that summarised route is withdrawn from R1 "
            "and R3 when aggregate-address command is removed and appears again "
            "when aggregate-address command is re-added. Check for both AFIs.")

        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)

    write_test_footer(tc_name)
Esempio n. 3
0
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)
Esempio n. 4
0
def test_ospf_learning_tc15_p0(request):
    """Verify OSPF can learn different types of LSA and processes them.

    OSPF Learning : Edge learning different types of LSAs.
    """
    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)

    global topo
    step("Bring up the base config as per the topology")
    step("Configure area 1 as NSSA Area")

    reset_config_on_routers(tgen)

    step("Verify that Type 3 summary LSA is originated for the same Area 0")
    ip = topo["routers"]["r1"]["links"]["r3-link0"]["ipv4"]
    ip_net = str(ipaddress.ip_interface(u"{}".format(ip)).network)

    dut = "r0"
    input_dict = {
        "r1": {
            "static_routes": [{
                "network": ip_net,
                "no_of_ip": 1,
                "routeType": "N IA"
            }]
        }
    }

    dut = "r0"
    result = verify_ospf_rib(tgen, dut, input_dict)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    protocol = "ospf"
    result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    input_dict = {
        "r2": {
            "static_routes": [{
                "network": NETWORK["ipv4"][0],
                "no_of_ip": 5,
                "next_hop": "Null0"
            }]
        }
    }
    result = create_static_routes(tgen, input_dict)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Redistribute static route in R2 ospf.")
    dut = "r2"
    redistribute_ospf(tgen, topo, dut, "static")

    step("Verify that Type 5 LSA is originated by R2.")
    dut = "r0"
    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("Verify that R0 receives Type 4 summary LSA.")
    dut = "r0"
    input_dict = {
        "r1": {
            "static_routes": [{
                "network": NETWORK["ipv4"][0],
                "no_of_ip": 1,
                "routeType": "N E2"
            }]
        }
    }

    dut = "r1"
    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)

    ospf_covergence = verify_ospf_neighbor(tgen, topo)
    assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
        ospf_covergence)

    step("Change area 1 as non nssa area (on the fly changing area"
         " type on DUT).")

    for rtr in ["r1", "r2", "r3"]:
        input_dict = {
            rtr: {
                "ospf": {
                    "area": [{
                        "id": "0.0.0.2",
                        "type": "nssa",
                        "delete": True
                    }]
                }
            }
        }
        result = create_router_ospf(tgen, topo, input_dict)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    step("Verify that OSPF neighbours are reset after changing area type.")
    step("Verify that ABR R2 originates type 5 LSA in area 1.")
    step("Verify that route is calculated and installed in R1.")

    input_dict = {
        "r1": {
            "static_routes": [{
                "network": NETWORK["ipv4"][0],
                "no_of_ip": 1,
                "routeType": "N E2"
            }]
        }
    }

    dut = "r1"
    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)
Esempio n. 5
0
def test_bgp_local_nexthop_p1_tc14_ebgp(request):
    """
    Verify BGP did not install the static route when it receive route
    with local next hop

    """
    tc_name = request.node.name
    write_test_header(tc_name)
    tgen = get_topogen()

    step("Configure BGP IPv4 session between R2 and R3")
    step("Configure IPv4 static route on R2")
    reset_config_on_routers(tgen)

    for addr_type in ADDR_TYPES:
        # Enable static routes
        input_dict_4 = {
            "r2": {
                "static_routes": [{
                    "network":
                    NETWORK[addr_type],
                    "next_hop":
                    topo["routers"]["r3"]["links"]["r2-link0"]
                    [addr_type].split("/")[0],
                }]
            }
        }

        logger.info("Configure static routes")
        result = create_static_routes(tgen, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        step("Configure redistribute static in the BGP")

        input_dict_2 = {
            "r2": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "redistribute": [{
                                    "redist_type": "static"
                                }]
                            }
                        }
                    }
                }
            }
        }
        result = create_router_bgp(tgen, topo, input_dict_2)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        step("Verify R2 BGP table has IPv4 route")
        dut = "r2"
        result = verify_rib(tgen, addr_type, dut, input_dict_4)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes is" " missing in RIB of R2".format(
            tc_name)

        step(" Verify route did not install in the R3 BGP table, RIB/FIB")
        dut = "r3"
        result = verify_bgp_rib(tgen,
                                addr_type,
                                dut,
                                input_dict_4,
                                expected=False)
        assert result is not True, (
            "Testcase {} : Failed \nError: Routes is"
            " still present in BGP RIB of R2".format(tc_name))

        result = verify_rib(tgen, addr_type, dut, input_dict_4, expected=False)
        assert result is not True, (
            "Testcase {} : Failed \nError: Routes is"
            " still present in RIB of R2".format(tc_name))

    write_test_footer(tc_name)
Esempio n. 6
0
def test_staticroute_with_ecmp_p0_tc3_ebgp(request):
    """
    Verify static route ECMP functionality with 8 next hop'

    """
    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)
    NEXT_HOP_IP = populate_nh()

    step("Configure 8 interfaces / links between R1 and R2,")
    step("Configure IPv4 static route in R2 with 8 next hop"
         "N1(21.1.1.2), N2(22.1.1.2), N3(23.1.1.2), N4(24.1.1.2),"
         "N5(25.1.1.2), N6(26.1.1.2), N7(27.1.1.2),N8(28.1.1.2), Static"
         "route next-hop present on R1")

    step("Configure IBGP IPv4 peering between R2 and R3 router.")

    for addr_type in ADDR_TYPES:
        # Enable static routes
        for nhp in range(1, 9):
            input_dict_4 = {
                "r2": {
                    "static_routes": [{
                        "network":
                        PREFIX1[addr_type],
                        "next_hop":
                        NEXT_HOP_IP["nh" + str(nhp)][addr_type],
                    }]
                }
            }
            logger.info("Configure static routes")
            result = create_static_routes(tgen, input_dict_4)
            assert result is True, "Testcase {} : Failed \n Error: {}".format(
                tc_name, result)
        logger.info("Verifying %s routes on r2", addr_type)
        nh = [
            NEXT_HOP_IP["nh1"][addr_type],
            NEXT_HOP_IP["nh2"][addr_type],
            NEXT_HOP_IP["nh3"][addr_type],
            NEXT_HOP_IP["nh4"][addr_type],
            NEXT_HOP_IP["nh5"][addr_type],
            NEXT_HOP_IP["nh6"][addr_type],
            NEXT_HOP_IP["nh7"][addr_type],
            NEXT_HOP_IP["nh8"][addr_type],
        ]

        dut = "r2"
        protocol = "static"
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_4,
                            next_hop=nh,
                            protocol=protocol)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(
            tc_name)
    step("Configure redistribute static in BGP on R2 router")
    for addr_type in ADDR_TYPES:
        input_dict_2 = {
            "r2": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "redistribute": [{
                                    "redist_type": "static"
                                }]
                            }
                        }
                    }
                }
            }
        }
        result = create_router_bgp(tgen, topo, input_dict_2)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    step("Remove the static route configured with nexthop N1 to N8, one"
         "by one from running config")
    for addr_type in ADDR_TYPES:
        # delete static routes
        for nhp in range(1, 9):
            input_dict_4 = {
                "r2": {
                    "static_routes": [{
                        "network":
                        PREFIX1[addr_type],
                        "next_hop":
                        NEXT_HOP_IP["nh" + str(nhp)][addr_type],
                        "delete":
                        True,
                    }]
                }
            }

        logger.info("Configure static routes")
        result = create_static_routes(tgen, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        result = verify_rib(
            tgen,
            addr_type,
            dut,
            input_dict_4,
            next_hop=nh,
            protocol=protocol,
            expected=False,
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
            tc_name)

    step("Configure the static route with nexthop N1 to N8, one by" "one")

    for addr_type in ADDR_TYPES:
        # add static routes
        for nhp in range(1, 9):
            input_dict_4 = {
                "r2": {
                    "static_routes": [{
                        "network":
                        PREFIX1[addr_type],
                        "next_hop":
                        NEXT_HOP_IP["nh" + str(nhp)][addr_type],
                    }]
                }
            }

        logger.info("Configure static routes")
        result = create_static_routes(tgen, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    result = verify_rib(tgen,
                        addr_type,
                        dut,
                        input_dict_4,
                        next_hop=nh,
                        protocol=protocol)
    assert (
        result is True
    ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(
        tc_name)

    step("Random shut of the nexthop interfaces")
    randnum = random.randint(0, 7)
    for addr_type in ADDR_TYPES:
        intf = topo["routers"]["r2"]["links"]["r1-link" +
                                              str(randnum)]["interface"]
        shutdown_bringup_interface(tgen, dut, intf, False)
        nhip = NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type]
        input_dict_5 = {
            "r2": {
                "static_routes": [{
                    "network":
                    PREFIX1[addr_type],
                    "next_hop":
                    NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type],
                }]
            }
        }
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            input_dict_5,
            next_hop=nhip,
            protocol=protocol,
            expected=False,
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
            tc_name)

    step("Random no shut of the nexthop interfaces")
    for addr_type in ADDR_TYPES:
        intf = topo["routers"]["r2"]["links"]["r1-link" +
                                              str(randnum)]["interface"]
        shutdown_bringup_interface(tgen, dut, intf, True)
        nhip = NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type]
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_5,
                            next_hop=nhip,
                            protocol=protocol)
        assert (
            result is True
        ), "Testcase {} : Failed \n" "Error: Routes are missing in RIB".format(
            tc_name)

    step("Reload the FRR router")
    # stop/start -> restart FRR router and verify
    stop_router(tgen, "r2")
    start_router(tgen, "r2")

    result = verify_rib(tgen,
                        addr_type,
                        dut,
                        input_dict_4,
                        next_hop=nh,
                        protocol=protocol)
    assert (
        result is True
    ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(
        tc_name)

    write_test_footer(tc_name)
Esempio n. 7
0
def test_ospf_chaos_tc34_p1(request):
    """
    verify ospf functionality when staticd is restarted.

    Verify ospf functionalitywhen staticroutes are
    redistributed & Staticd is restarted.
    """
    tc_name = request.node.name
    write_test_header(tc_name)
    tgen = get_topogen()
    global topo
    step("Bring up the base config as per the topology")
    reset_config_on_routers(tgen)

    step("Create static routes(10.0.20.1/32) in R1 and redistribute "
         "to OSPF using route map.")

    # Create Static routes
    input_dict = {
        "r0": {
            "static_routes": [{
                "network": NETWORK["ipv4"][0],
                "no_of_ip": 5,
                "next_hop": "Null0",
            }]
        }
    }
    result = create_static_routes(tgen, input_dict)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    ospf_red_r0 = {
        "r0": {
            "ospf": {
                "redistribute": [{
                    "redist_type": "static"
                }]
            }
        }
    }
    result = create_router_ospf(tgen, topo, ospf_red_r0)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Verify OSPF neighbors after base config is done.")
    # Api call verify whether OSPF is converged
    ospf_covergence = verify_ospf_neighbor(tgen, topo)
    assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
        ospf_covergence)

    step("Verify that route is advertised to R1.")
    dut = "r1"
    protocol = "ospf"
    nh = topo["routers"]["r0"]["links"]["r1"]["ipv4"].split("/")[0]
    result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    result = verify_rib(tgen,
                        "ipv4",
                        dut,
                        input_dict,
                        protocol=protocol,
                        next_hop=nh)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Kill staticd daemon on R0.")
    kill_router_daemons(tgen, "r0", ["staticd"])

    step("Verify that route advertised to R1 are deleted from RIB and FIB.")
    dut = "r1"
    protocol = "ospf"
    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)

    step("Bring up staticd daemon on R0.")
    start_router_daemons(tgen, "r0", ["staticd"])

    step("Verify OSPF neighbors are up after bringing back ospfd in R0")
    # Api call verify whether OSPF is converged
    ospf_covergence = verify_ospf_neighbor(tgen, topo)
    assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
        ospf_covergence)

    step("All the neighbours are up and routes are installed before the"
         " restart. Verify OSPF route table and ip route table.")
    dut = "r1"
    protocol = "ospf"
    result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    result = verify_rib(tgen,
                        "ipv4",
                        dut,
                        input_dict,
                        protocol=protocol,
                        next_hop=nh)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Kill staticd daemon on R1.")
    kill_router_daemons(tgen, "r1", ["staticd"])

    step("Bring up staticd daemon on R1.")
    start_router_daemons(tgen, "r1", ["staticd"])

    step("Verify OSPF neighbors are up after bringing back ospfd in R1")
    # Api call verify whether OSPF is converged
    ospf_covergence = verify_ospf_neighbor(tgen, topo)
    assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
        ospf_covergence)

    step("All the neighbours are up and routes are installed before the"
         " restart. Verify OSPF route table and ip route table.")

    dut = "r1"
    protocol = "ospf"
    result = verify_ospf_rib(tgen, dut, input_dict, next_hop=nh)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    result = verify_rib(tgen,
                        "ipv4",
                        dut,
                        input_dict,
                        protocol=protocol,
                        next_hop=nh)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    write_test_footer(tc_name)
Esempio n. 8
0
def test_restart_frr_p2(request):
    """

    Test extended capability nexthop , restart frr.

    Verify IPv4 routes are intact after stop and start the FRR services
    """
    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 Unnumbered session between R1 and R2")
    step("Enable capability extended-nexthop on both the IPv6 BGP peers")
    step("Activate same IPv6 nbr from IPv4 unicast family")
    step("Enable cap ext nh on r1 and r2 and activate in ipv4 addr family")
    step("Verify bgp convergence as ipv6 nbr is enabled on ipv4 addr family.")
    bgp_convergence = verify_bgp_convergence(tgen, topo)
    assert bgp_convergence is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, bgp_convergence
    )

    step(" Configure 5 IPv4 static" " routes on R1, Nexthop as different links of R0")
    for rte in range(0, NO_OF_RTES):
        # Create Static routes
        input_dict = {
            "r1": {
                "static_routes": [
                    {
                        "network": NETWORK["ipv4"][rte],
                        "no_of_ip": 1,
                        "next_hop": NEXT_HOP["ipv4"][rte],
                    }
                ]
            }
        }
        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 and IPv6 "
        "unicast family respectively from R1 using red static cmd "
        "Advertise loopback from IPv4 unicast family using network command "
        "from R1"
    )

    configure_bgp_on_r1 = {
        "r1": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "redistribute": [{"redist_type": "static"}],
                            "advertise_networks": [
                                {"network": NETWORK_CMD_IP, "no_of_network": 1}
                            ],
                        }
                    },
                    "ipv6": {"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)
    step(
        "IPv4 routes advertised using static and network command are "
        " received on R2 BGP and routing table , "
        "verify using show ip bgp, show ip route for IPv4 routes ."
    )

    llip = get_llip("r1", "r2-link0")
    assert llip is not None, "Testcase {} : Failed \n Error: {}".format(tc_name, result)

    dut = "r2"
    protocol = "bgp"
    verify_nh_for_static_rtes = {
        "r1": {
            "static_routes": [
                {
                    "network": NETWORK["ipv4"][0],
                    "no_of_ip": NO_OF_RTES,
                    "next_hop": llip,
                }
            ]
        }
    }
    bgp_rib = verify_rib(tgen, "ipv4", dut, verify_nh_for_static_rtes, next_hop=llip)
    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=llip, protocol=protocol
    )
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)

    verify_nh_for_nw_rtes = {
        "r1": {
            "static_routes": [
                {"network": NETWORK_CMD_IP, "no_of_ip": 1, "next_hop": llip}
            ]
        }
    }

    bgp_rib = verify_rib(tgen, "ipv4", dut, verify_nh_for_nw_rtes, next_hop=llip)
    assert bgp_rib is True, "Testcase {} : Failed \n Error: {}".format(tc_name, bgp_rib)
    result = verify_rib(
        tgen, "ipv4", dut, verify_nh_for_nw_rtes, next_hop=llip, protocol=protocol
    )
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)

    # stop/start -> restart FRR router and verify
    stop_router(tgen, "r1")
    stop_router(tgen, "r2")
    start_router(tgen, "r1")
    start_router(tgen, "r2")

    step(
        "After stop/start of FRR services , verify session up and routes "
        "came up fine ,nh is proper using show bgp & show ipv6 route on R2 "
    )
    bgp_convergence = verify_bgp_convergence(tgen, topo)
    assert bgp_convergence is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, bgp_convergence
    )

    llip = get_llip("r1", "r2-link0")
    assert llip is not None, "Testcase {} : Failed \n Error: {}".format(tc_name, result)

    # verify the routes with nh as ext_nh
    verify_nh_for_static_rtes = {
        "r1": {
            "static_routes": [
                {"network": NETWORK["ipv4"][0], "no_of_ip": 1, "next_hop": llip}
            ]
        }
    }
    bgp_rib = verify_rib(tgen, "ipv4", dut, verify_nh_for_static_rtes, next_hop=llip)
    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=llip, protocol=protocol
    )
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)

    # verify the routes with nh as ext_nh
    verify_nh_for_nw_rtes = {
        "r1": {
            "static_routes": [
                {"network": NETWORK_CMD_IP, "no_of_ip": 1, "next_hop": llip}
            ]
        }
    }
    bgp_rib = verify_rib(tgen, "ipv4", dut, verify_nh_for_nw_rtes, next_hop=llip)
    assert bgp_rib is True, "Testcase {} : Failed \n Error: {}".format(tc_name, bgp_rib)
    result = verify_rib(
        tgen, "ipv4", dut, verify_nh_for_nw_rtes, next_hop=llip, protocol=protocol
    )
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
    write_test_footer(tc_name)
Esempio n. 9
0
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")
Esempio n. 10
0
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
            )
Esempio n. 11
0
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)
Esempio n. 12
0
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
        )
Esempio n. 13
0
def test_ecmp_remove_static_route(request):
    """
    Delete static routes and verify routers are cleared from BGP table,
    and RIB of DUT.
    """

    tc_name = request.node.name
    write_test_header(tc_name)
    tgen = get_topogen()

    # Verifying RIB routes
    dut = "r3"
    protocol = "bgp"

    reset_config_on_routers(tgen)

    static_or_nw(tgen, topo, tc_name, "redist_static", "r2")
    for addr_type in ADDR_TYPES:
        input_dict_1 = {
            "r3": {
                "static_routes": [{
                    "network": NETWORK[addr_type]
                }]
            }
        }

        logger.info("Verifying %s routes on r3", addr_type)
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            input_dict_1,
            next_hop=NEXT_HOPS[addr_type],
            protocol=protocol,
        )
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    for addr_type in ADDR_TYPES:
        input_dict_2 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK[addr_type],
                    "next_hop": NEXT_HOP_IP[addr_type],
                    "delete": True,
                }]
            }
        }

        logger.info("Remove static routes")
        result = create_static_routes(tgen, input_dict_2)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        logger.info("Verifying %s routes on r3 are removed", addr_type)
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            input_dict_2,
            next_hop=[],
            protocol=protocol,
            expected=False,
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \n Routes still" " present in RIB".format(
            tc_name)

    for addr_type in ADDR_TYPES:
        # Enable static routes
        input_dict_4 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK[addr_type],
                    "next_hop": NEXT_HOP_IP[addr_type]
                }]
            }
        }

        logger.info("Enable static route")
        result = create_static_routes(tgen, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        logger.info("Verifying %s routes on r3", addr_type)
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            input_dict_4,
            next_hop=NEXT_HOPS[addr_type],
            protocol=protocol,
        )
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    write_test_footer(tc_name)
Esempio n. 14
0
def static_or_nw(tgen, topo, tc_name, test_type, dut):

    if test_type == "redist_static":
        input_dict_static = {
            dut: {
                "static_routes": [
                    {
                        "network": NETWORK["ipv4"],
                        "next_hop": NEXT_HOP_IP["ipv4"]
                    },
                    {
                        "network": NETWORK["ipv6"],
                        "next_hop": NEXT_HOP_IP["ipv6"]
                    },
                ]
            }
        }
        logger.info("Configuring static route on router %s", dut)
        result = create_static_routes(tgen, input_dict_static)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        input_dict_2 = {
            dut: {
                "bgp": {
                    "address_family": {
                        "ipv4": {
                            "unicast": {
                                "redistribute": [{
                                    "redist_type": "static"
                                }]
                            }
                        },
                        "ipv6": {
                            "unicast": {
                                "redistribute": [{
                                    "redist_type": "static"
                                }]
                            }
                        },
                    }
                }
            }
        }

        logger.info("Configuring redistribute static route on router %s", dut)
        result = create_router_bgp(tgen, topo, input_dict_2)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    elif test_type == "advertise_nw":
        input_dict_nw = {
            dut: {
                "bgp": {
                    "address_family": {
                        "ipv4": {
                            "unicast": {
                                "advertise_networks": [{
                                    "network":
                                    NETWORK["ipv4"]
                                }]
                            }
                        },
                        "ipv6": {
                            "unicast": {
                                "advertise_networks": [{
                                    "network":
                                    NETWORK["ipv6"]
                                }]
                            }
                        },
                    }
                }
            }
        }

        logger.info(
            "Advertising networks %s %s from router %s",
            NETWORK["ipv4"],
            NETWORK["ipv6"],
            dut,
        )
        result = create_router_bgp(tgen, topo, input_dict_nw)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)
Esempio n. 15
0
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)
Esempio n. 16
0
def test_verify_overlay_index_p1(request):
    """
    In absence of an overlay index all IP-Prefixes(RT-5)
    are advertised with default values for below parameters:
        --> Ethernet Tag ID = GW IP address = ESI=0
    """

    tgen = get_topogen()
    tc_name = request.node.name
    write_test_header(tc_name)
    check_router_status(tgen)
    reset_config_on_routers(tgen)
    add_default_routes(tgen)

    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)

    step("Following steps are taken care in base config:")
    step(
        "Configure BGP neighborship for both address families"
        "(IPv4 & IPv6) between Edge-1 and VFN routers(R1 and R2)"
    )
    step(
        "Advertise prefixes from VNF routers R1 and R2 in associated "
        "VRFs for both address-family."
    )
    step("Advertise VRF routes as in EVPN address family from Edge-1 " "router.")

    for addr_type in ADDR_TYPES:
        input_dict_1 = {
            "r1": {
                "static_routes": [
                    {
                        "network": NETWORK1_1[addr_type],
                        "next_hop": NEXT_HOP_IP[addr_type],
                        "vrf": "RED",
                    }
                ]
            },
            "r2": {
                "static_routes": [
                    {
                        "network": NETWORK2_1[addr_type],
                        "next_hop": NEXT_HOP_IP[addr_type],
                        "vrf": "BLUE",
                    },
                    {
                        "network": NETWORK3_1[addr_type],
                        "next_hop": NEXT_HOP_IP[addr_type],
                        "vrf": "GREEN",
                    },
                ]
            },
        }

        result = create_static_routes(tgen, input_dict_1)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

    step("Verify: Prefixes are received in all VRFs on Edge-1 router.")

    for addr_type in ADDR_TYPES:
        input_routes = {key: topo["routers"][key] for key in ["r1"]}
        result = verify_rib(tgen, addr_type, "e1", input_routes)
        assert result is True, "Testcase {} :Failed \n Error: {}".format(
            tc_name, result
        )

    for addr_type in ADDR_TYPES:
        input_routes = {key: topo["routers"][key] for key in ["r2"]}
        result = verify_rib(tgen, addr_type, "e1", input_routes)
        assert result is True, "Testcase {} :Failed \n Error: {}".format(
            tc_name, result
        )

    step(
        "Verify that EVPN routes, received on DCG-1 and DCG-2 do not "
        "carry any overlay index and these indexes are set to default "
        "value=0. "
    )

    for addr_type in ADDR_TYPES:
        input_routes = {key: topo["routers"][key] for key in ["r1"]}

        result = verify_attributes_for_evpn_routes(
            tgen, topo, "d1", input_routes, ethTag=0
        )
        assert result is True, "Testcase {} :Failed \n Error: {}".format(
            tc_name, result
        )

        result = verify_attributes_for_evpn_routes(
            tgen, topo, "d2", input_routes, ethTag=0
        )
        assert result is True, "Testcase {} :Failed \n Error: {}".format(
            tc_name, result
        )

    write_test_footer(tc_name)
Esempio n. 17
0
def test_RT_verification_auto_p0(request):
    """
    RT verification(auto)
    """

    tgen = get_topogen()
    tc_name = request.node.name
    write_test_header(tc_name)
    check_router_status(tgen)
    reset_config_on_routers(tgen)
    add_default_routes(tgen)

    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)

    step(
        "Advertise overlapping prefixes from VNFs R1 and R2 in all VRFs "
        "RED, GREEN and BLUE 100.1.1.1/32 and 100::100/128"
    )

    for addr_type in ADDR_TYPES:
        input_dict_1 = {
            "r1": {
                "static_routes": [
                    {
                        "network": NETWORK4_1[addr_type],
                        "next_hop": NEXT_HOP_IP[addr_type],
                        "vrf": "RED",
                    }
                ]
            },
            "r2": {
                "static_routes": [
                    {
                        "network": NETWORK4_1[addr_type],
                        "next_hop": NEXT_HOP_IP[addr_type],
                        "vrf": "BLUE",
                    },
                    {
                        "network": NETWORK4_1[addr_type],
                        "next_hop": NEXT_HOP_IP[addr_type],
                        "vrf": "GREEN",
                    },
                ]
            },
        }

        result = create_static_routes(tgen, input_dict_1)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

    step(
        "Verify that Edge-1 receives same prefixes in all 3 VRFs via "
        "corresponding next-hop in associated VRF sh bgp vrf all"
    )

    for addr_type in ADDR_TYPES:
        input_routes = {
            "r1": {
                "static_routes": [
                    {
                        "network": NETWORK4_1[addr_type],
                        "next_hop": NEXT_HOP_IP[addr_type],
                        "vrf": "RED",
                    }
                ]
            },
            "r2": {
                "static_routes": [
                    {
                        "network": NETWORK4_1[addr_type],
                        "next_hop": NEXT_HOP_IP[addr_type],
                        "vrf": "BLUE",
                    },
                    {
                        "network": NETWORK4_1[addr_type],
                        "next_hop": NEXT_HOP_IP[addr_type],
                        "vrf": "GREEN",
                    },
                ]
            },
        }

        result = verify_rib(tgen, addr_type, "e1", input_routes)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

    step(
        "Configure 4-byte local AS number on Edge-1 and establish EVPN "
        "neighborship with DCG-1 & DCG-2."
    )

    topo_local = deepcopy(topo)

    step("Delete BGP config for vrf RED.")

    input_dict_vni = {
        "e1": {
            "vrfs": [
                {"name": "RED", "no_vni": VNI_1},
                {"name": "BLUE", "no_vni": VNI_2},
                {"name": "GREEN", "no_vni": VNI_3},
            ]
        }
    }
    result = create_vrf_cfg(tgen, topo, input_dict=input_dict_vni)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    input_dict_2 = {}
    for dut in ["e1"]:
        temp = {dut: {"bgp": []}}
        input_dict_2.update(temp)

        INDEX = [0, 1, 2, 3]
        VRFS = ["RED", "BLUE", "GREEN", None]
        AS_NUM = [100, 100, 100, 100]

        for index, vrf, as_num in zip(INDEX, VRFS, AS_NUM):
            topo_local["routers"][dut]["bgp"][index]["local_as"] = 4294967293
            if vrf:
                temp[dut]["bgp"].append(
                    {"local_as": as_num, "vrf": vrf, "delete": True}
                )
            else:
                temp[dut]["bgp"].append({"local_as": as_num, "delete": True})

    result = create_router_bgp(tgen, topo, input_dict_2)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    result = create_router_bgp(tgen, topo_local["routers"])
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    input_dict_vni = {
        "e1": {
            "vrfs": [
                {"name": "RED", "vni": VNI_1},
                {"name": "BLUE", "vni": VNI_2},
                {"name": "GREEN", "vni": VNI_3},
            ]
        }
    }
    result = create_vrf_cfg(tgen, topo, input_dict=input_dict_vni)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    step(
        "Verify that all overlapping prefixes across different VRFs are "
        "advertised in EVPN with unique RD value(auto derived)."
    )
    step(
        "Verify that FRR uses only the lower 2 bytes of ASN+VNI for auto "
        "derived RT value."
    )

    for addr_type in ADDR_TYPES:
        input_routes_1 = {
            "r1": {"static_routes": [{"network": NETWORK4_1[addr_type], "vrf": "RED"}]}
        }
        input_routes_2 = {
            "r2": {"static_routes": [{"network": NETWORK4_1[addr_type], "vrf": "BLUE"}]}
        }
        input_routes_3 = {
            "r2": {
                "static_routes": [{"network": NETWORK4_1[addr_type], "vrf": "GREEN"}]
            }
        }

        result = verify_attributes_for_evpn_routes(
            tgen, topo, "e1", input_routes_1, rd="auto", rd_peer="e1"
        )
        assert result is True, "Testcase {} :Failed \n Error: {}".format(
            tc_name, result
        )

        result = verify_attributes_for_evpn_routes(
            tgen, topo, "e1", input_routes_1, rt="auto", rt_peer="e1"
        )
        assert result is True, "Testcase {} :Failed \n Error: {}".format(
            tc_name, result
        )

        result = verify_attributes_for_evpn_routes(
            tgen, topo, "e1", input_routes_2, rd="auto", rd_peer="e1"
        )
        assert result is True, "Testcase {} :Failed \n Error: {}".format(
            tc_name, result
        )

        result = verify_attributes_for_evpn_routes(
            tgen, topo, "e1", input_routes_2, rt="auto", rt_peer="e1"
        )
        assert result is True, "Testcase {} :Failed \n Error: {}".format(
            tc_name, result
        )

        result = verify_attributes_for_evpn_routes(
            tgen, topo, "e1", input_routes_3, rd="auto", rd_peer="e1"
        )
        assert result is True, "Testcase {} :Failed \n Error: {}".format(
            tc_name, result
        )

        result = verify_attributes_for_evpn_routes(
            tgen, topo, "e1", input_routes_3, rt="auto", rt_peer="e1"
        )
        assert result is True, "Testcase {} :Failed \n Error: {}".format(
            tc_name, result
        )

    step(
        "Verify that DCG-1(iBGP peer) automatically imports the prefixes"
        " from EVPN address-family to respective VRFs."
    )
    step(
        "Verify if DCG-2(eBGP peer) automatically imports the prefixes "
        "from EVPN address-family to respective VRFs or not."
    )

    for addr_type in ADDR_TYPES:
        input_routes = {
            "r1": {
                "static_routes": [
                    {
                        "network": NETWORK4_1[addr_type],
                        "next_hop": NEXT_HOP_IP[addr_type],
                        "vrf": "RED",
                    }
                ]
            },
            "r2": {
                "static_routes": [
                    {
                        "network": NETWORK4_1[addr_type],
                        "next_hop": NEXT_HOP_IP[addr_type],
                        "vrf": "BLUE",
                    },
                    {
                        "network": NETWORK4_1[addr_type],
                        "next_hop": NEXT_HOP_IP[addr_type],
                        "vrf": "GREEN",
                    },
                ]
            },
        }

        result = verify_rib(tgen, addr_type, "d1", input_routes)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        result = verify_rib(tgen, addr_type, "d2", input_routes)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

    step(
        "Change the VNI number for all 3 VRFs on Edge-1 as:"
        "RED : 75400, GREEN: 75500, BLUE: 75600"
    )

    input_dict_vni = {
        "e1": {
            "vrfs": [
                {"name": "RED", "no_vni": VNI_1},
                {"name": "BLUE", "no_vni": VNI_2},
                {"name": "GREEN", "no_vni": VNI_3},
            ]
        }
    }
    result = create_vrf_cfg(tgen, topo, input_dict=input_dict_vni)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    input_dict_vni = {
        "e1": {
            "vrfs": [
                {"name": "RED", "vni": 75400},
                {"name": "BLUE", "vni": 75500},
                {"name": "GREEN", "vni": 75600},
            ]
        }
    }
    result = create_vrf_cfg(tgen, topo, input_dict=input_dict_vni)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    step("Delete configured vxlan")
    dut = "e1"
    vxlan_input = {
        dut: {
            "vxlan": [
                {
                    "vxlan_name": VXLAN["vxlan_name"],
                    "vxlan_id": VXLAN["vxlan_id"],
                    "dstport": VXLAN["dstport"],
                    "local_addr": VXLAN["local_addr"][dut],
                    "learning": VXLAN["learning"],
                    "delete": True,
                }
            ]
        }
    }

    result = configure_vxlan(tgen, vxlan_input)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    step("Configured vxlan")
    VXLAN["vxlan_id"] = [75400, 75500, 75600]
    vxlan_input = {
        dut: {
            "vxlan": [
                {
                    "vxlan_name": VXLAN["vxlan_name"],
                    "vxlan_id": VXLAN["vxlan_id"],
                    "dstport": VXLAN["dstport"],
                    "local_addr": VXLAN["local_addr"][dut],
                    "learning": VXLAN["learning"],
                }
            ]
        }
    }

    result = configure_vxlan(tgen, vxlan_input)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    step("Configure bridge interface")
    brctl_input = {
        dut: {
            "brctl": [
                {
                    "brctl_name": BRCTL["brctl_name"],
                    "addvxlan": BRCTL["addvxlan"],
                    "vrf": BRCTL["vrf"],
                    "stp": BRCTL["stp"],
                }
            ]
        }
    }
    result = configure_brctl(tgen, topo, brctl_input)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    step(
        "Verify on Edge-1 that auto derived RT value has changed for "
        "each VRF based on VNI number.."
    )

    input_dict = {
        "e1": {
            "vrfs": [
                {"RED": {"vni": 75400}},
                {"BLUE": {"vni": 75500}},
                {"GREEN": {"vni": 75600}},
            ]
        }
    }

    result = verify_vrf_vni(tgen, input_dict)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    step(
        "Verify on Edge-1 that auto derived RT value has changed for "
        "each VRF based on VNI number."
    )

    for addr_type in ADDR_TYPES:
        input_routes = {
            "r1": {"static_routes": [{"network": NETWORK4_1[addr_type], "vrf": "RED"}]}
        }

        result = verify_attributes_for_evpn_routes(
            tgen, topo, "e1", input_routes, rt="auto", rt_peer="e1"
        )
        assert result is True, "Testcase {} :Failed \n Error: {}".format(
            tc_name, result
        )

    step(
        "Verify on DCG-2 that prefixes are not imported from EVPN "
        "address-family to VRFs as RT values are different on sending("
        "edge-1) and receiving(DCG-2) end."
    )

    for addr_type in ADDR_TYPES:
        input_routes = {
            "r1": {"static_routes": [{"network": NETWORK4_1[addr_type], "vrf": "RED"}]}
        }

        result = verify_rib(tgen, addr_type, "d2", input_routes, expected=False)
        assert result is not True, "Testcase {} :Failed \n "
        "Routes are still present: {}".format(tc_name, result)
        logger.info("Expected Behavior: {}".format(result))

    step(
        "Revert back to original VNI number for all 3 VRFs on Edge-1 "
        "as: RED : 75100, GREEN: 75200, BLUE: 75300"
    )

    input_dict_vni = {
        "e1": {
            "vrfs": [
                {"name": "RED", "no_vni": 75400},
                {"name": "BLUE", "no_vni": 75500},
                {"name": "GREEN", "no_vni": 75600},
            ]
        }
    }
    result = create_vrf_cfg(tgen, topo, input_dict=input_dict_vni)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    input_dict_vni = {
        "e1": {
            "vrfs": [
                {"name": "RED", "vni": VNI_1},
                {"name": "BLUE", "vni": VNI_2},
                {"name": "GREEN", "vni": VNI_3},
            ]
        }
    }
    result = create_vrf_cfg(tgen, topo, input_dict=input_dict_vni)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    step("Delete configured vxlan")
    dut = "e1"
    vxlan_input = {
        dut: {
            "vxlan": [
                {
                    "vxlan_name": VXLAN["vxlan_name"],
                    "vxlan_id": VXLAN["vxlan_id"],
                    "dstport": VXLAN["dstport"],
                    "local_addr": VXLAN["local_addr"][dut],
                    "learning": VXLAN["learning"],
                    "delete": True,
                }
            ]
        }
    }
    result = configure_vxlan(tgen, vxlan_input)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    step("Configured vxlan")
    VXLAN["vxlan_id"] = [75100, 75200, 75300]
    vxlan_input = {
        dut: {
            "vxlan": [
                {
                    "vxlan_name": VXLAN["vxlan_name"],
                    "vxlan_id": VXLAN["vxlan_id"],
                    "dstport": VXLAN["dstport"],
                    "local_addr": VXLAN["local_addr"][dut],
                    "learning": VXLAN["learning"],
                }
            ]
        }
    }
    result = configure_vxlan(tgen, vxlan_input)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    step("Configure bridge interface")
    brctl_input = {
        dut: {
            "brctl": [
                {
                    "brctl_name": BRCTL["brctl_name"],
                    "addvxlan": BRCTL["addvxlan"],
                    "vrf": BRCTL["vrf"],
                    "stp": BRCTL["stp"],
                }
            ]
        }
    }
    result = configure_brctl(tgen, topo, brctl_input)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    step(
        "Verify on Edge-1 that auto derived RT value has changed for "
        "each VRF based on VNI number."
    )
    step(
        "Verify that DCG-1(iBGP peer) automatically imports the prefixes"
        " from EVPN address-family to respective VRFs."
    )

    for addr_type in ADDR_TYPES:
        input_routes = {
            "r1": {"static_routes": [{"network": NETWORK4_1[addr_type], "vrf": "RED"}]}
        }

        result = verify_attributes_for_evpn_routes(
            tgen, topo, "e1", input_routes, rt="auto", rt_peer="e1"
        )
        assert result is True, "Testcase {} :Failed \n Error: {}".format(
            tc_name, result
        )

        result = verify_rib(tgen, addr_type, "d1", input_routes)
        assert result is True, "Testcase {} :Failed \n Error: {}".format(
            tc_name, result
        )

    step("Test with smaller VNI numbers (1-75000)")

    input_dict_vni = {"e1": {"vrfs": [{"name": "RED", "no_vni": VNI_1}]}}
    result = create_vrf_cfg(tgen, topo, input_dict=input_dict_vni)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    input_dict_vni = {"e1": {"vrfs": [{"name": "RED", "vni": 111}]}}
    result = create_vrf_cfg(tgen, topo, input_dict=input_dict_vni)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    step(
        "Verify that DCG-2 receives EVPN prefixes along with auto "
        "derived RT values(based on smaller VNI numbers)"
    )

    for addr_type in ADDR_TYPES:
        input_routes_1 = {
            "r1": {"static_routes": [{"network": NETWORK4_1[addr_type], "vrf": "RED"}]}
        }

        result = verify_attributes_for_evpn_routes(
            tgen, topo, "d2", input_routes_1, rt="auto", rt_peer="e1", expected=False
        )
        assert result is not True, "Testcase {} :Failed \n "
        "Malfaromed Auto-RT value accepted: {}".format(tc_name, result)
        logger.info("Expected Behavior: {}".format(result))

    step("Configure VNI number more than boundary limit (16777215)")

    input_dict_vni = {"e1": {"vrfs": [{"name": "RED", "no_vni": 111}]}}
    result = create_vrf_cfg(tgen, topo, input_dict=input_dict_vni)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    input_dict_vni = {"e1": {"vrfs": [{"name": "RED", "vni": 16777215}]}}
    result = create_vrf_cfg(tgen, topo, input_dict=input_dict_vni)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    step("CLI error for malformed VNI.")
    input_dict = {
        "e1": {
            "vrfs": [{"RED": {"vni": 16777215, "routerMac": "None", "state": "Down"}}]
        }
    }

    result = verify_vrf_vni(tgen, input_dict)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    for addr_type in ADDR_TYPES:
        input_routes_1 = {
            "r1": {"static_routes": [{"network": NETWORK4_1[addr_type], "vrf": "RED"}]}
        }

        result = verify_attributes_for_evpn_routes(
            tgen, topo, "d2", input_routes_1, rt="auto", rt_peer="e1", expected=False
        )
        assert result is not True, "Testcase {} :Failed \n "
        "Malfaromed Auto-RT value accepted: {}".format(tc_name, result)
        logger.info("Expected Behavior: {}".format(result))

    step("Un-configure VNI number more than boundary limit (16777215)")

    input_dict_vni = {"e1": {"vrfs": [{"name": "RED", "no_vni": 16777215}]}}
    result = create_vrf_cfg(tgen, topo, input_dict=input_dict_vni)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    write_test_footer(tc_name)
Esempio n. 18
0
def test_route_map_set_only_no_match_p0(request):
    """
    TC_37:
    Test add/remove route-maps with multiple set
    clauses and without any match statement.(Set only)
    """

    tgen = get_topogen()
    # test case name
    tc_name = request.node.name
    write_test_header(tc_name)

    # Creating configuration from JSON
    reset_config_on_routers(tgen)

    for adt in ADDR_TYPES:
        # Create Static routes
        input_dict = {
            "r1": {
                "static_routes": [
                    {
                        "network": NETWORK[adt][0],
                        "no_of_ip": 1,
                        "next_hop": NEXT_HOP[adt],
                    }
                ]
            }
        }
        result = create_static_routes(tgen, input_dict)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        # Api call to redistribute static routes
        input_dict_1 = {
            "r1": {
                "bgp": {
                    "address_family": {
                        "ipv4": {
                            "unicast": {
                                "redistribute": [
                                    {"redist_type": "static"},
                                    {"redist_type": "connected"},
                                ]
                            }
                        },
                        "ipv6": {
                            "unicast": {
                                "redistribute": [
                                    {"redist_type": "static"},
                                    {"redist_type": "connected"},
                                ]
                            }
                        },
                    }
                }
            }
        }
        result = create_router_bgp(tgen, topo, input_dict_1)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        # Create route map
        input_dict_3 = {
            "r3": {
                "route_maps": {
                    "rmap_match_pf_1": [
                        {
                            "action": "permit",
                            "set": {"metric": 50, "locPrf": 150, "weight": 4000},
                        }
                    ]
                }
            }
        }
        result = create_route_maps(tgen, input_dict_3)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

        # Configure neighbor for route map
        input_dict_4 = {
            "r3": {
                "bgp": {
                    "address_family": {
                        "ipv4": {
                            "unicast": {
                                "neighbor": {
                                    "r1": {
                                        "dest_link": {
                                            "r3": {
                                                "route_maps": [
                                                    {
                                                        "name": "rmap_match_pf_1",
                                                        "direction": "in",
                                                    }
                                                ]
                                            }
                                        }
                                    },
                                    "r4": {
                                        "dest_link": {
                                            "r3": {
                                                "route_maps": [
                                                    {
                                                        "name": "rmap_match_pf_1",
                                                        "direction": "out",
                                                    }
                                                ]
                                            }
                                        }
                                    },
                                }
                            }
                        },
                        "ipv6": {
                            "unicast": {
                                "neighbor": {
                                    "r1": {
                                        "dest_link": {
                                            "r3": {
                                                "route_maps": [
                                                    {
                                                        "name": "rmap_match_pf_1",
                                                        "direction": "in",
                                                    }
                                                ]
                                            }
                                        }
                                    },
                                    "r4": {
                                        "dest_link": {
                                            "r3": {
                                                "route_maps": [
                                                    {
                                                        "name": "rmap_match_pf_1",
                                                        "direction": "out",
                                                    }
                                                ]
                                            }
                                        }
                                    },
                                }
                            }
                        },
                    }
                }
            }
        }
        result = create_router_bgp(tgen, topo, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result
        )

    time.sleep(2)
    for adt in ADDR_TYPES:
        input_dict_4 = {
            "r3": {
                "route_maps": {
                    "rmap_match_pf_1": [
                        {
                            "action": "permit",
                            "set": {
                                "metric": 50,
                            },
                        }
                    ]
                }
            }
        }
        # Verifying RIB routes
        static_routes = [NETWORK[adt][0]]
        result = verify_bgp_attributes(
            tgen, adt, "r3", static_routes, "rmap_match_pf_1", input_dict_3
        )
        assert result is True, "Test case {} : Failed \n Error: {}".format(
            tc_name, result
        )

        result = verify_bgp_attributes(
            tgen, adt, "r4", static_routes, "rmap_match_pf_1", input_dict_4
        )
        assert result is True, "Test case {} : Failed \n Error: {}".format(
            tc_name, result
        )

        logger.info("Testcase " + tc_name + " :Passed \n")
Esempio n. 19
0
def pre_config_to_bsm(tgen, topo, tc_name, bsr, sender, receiver, fhr, rp, lhr,
                      packet):
    """
    API to do required configuration to send and receive BSR packet
    """

    # Re-configure interfaces as per BSR packet
    result = reconfig_interfaces(tgen, topo, bsr, fhr, packet)
    assert result is True, "Testcase {} :Failed \n Error {}".format(
        tc_name, result)

    # Create static routes
    if "bsr" in topo["routers"][bsr]["bsm"]["bsr_packets"][packet]:
        bsr_route = topo["routers"][bsr]["bsm"]["bsr_packets"][packet]["bsr"]
        next_hop = topo["routers"][bsr]["bsm"]["bsr_packets"][packet][
            "src_ip"].split("/")[0]
        next_hop_rp = topo["routers"][fhr]["links"][rp]["ipv4"].split("/")[0]
        next_hop_lhr = topo["routers"][rp]["links"][lhr]["ipv4"].split("/")[0]

        # Add static routes
        input_dict = {
            fhr: {
                "static_routes": [{
                    "network": bsr_route,
                    "next_hop": next_hop
                }]
            },
            rp: {
                "static_routes": [{
                    "network": bsr_route,
                    "next_hop": next_hop_rp
                }]
            },
            lhr: {
                "static_routes": [{
                    "network": bsr_route,
                    "next_hop": next_hop_lhr
                }]
            },
        }

        result = create_static_routes(tgen, input_dict)
        assert result is True, "Testcase {} :Failed \n Error {}".format(
            tc_name, result)

    # Add kernal route for source
    group = topo["routers"][bsr]["bsm"]["bsr_packets"][packet]["pkt_dst"]
    bsr_interface = topo["routers"][bsr]["links"][fhr]["interface"]
    result = addKernelRoute(tgen, bsr, bsr_interface, group)
    assert result is True, "Testcase {} :Failed \n Error {}".format(
        tc_name, result)

    # RP Mapping
    rp_mapping = topo["routers"][bsr]["bsm"]["bsr_packets"][packet][
        "rp_mapping"]

    # Add interfaces in RP for all the RPs
    result = add_rp_interfaces_and_pim_config(tgen, topo, "lo", rp, rp_mapping)
    assert result is True, "Testcase {} :Failed \n Error {}".format(
        tc_name, result)

    # Add kernal routes to sender and receiver
    for group, rp_list in rp_mapping.items():
        mask = group.split("/")[1]
        if int(mask) == 32:
            group = group.split("/")[0]

        # Add kernal routes for sender
        s_interface = topo["routers"][sender]["links"][fhr]["interface"]
        result = addKernelRoute(tgen, sender, s_interface, group)
        assert result is True, "Testcase {} :Failed \n Error {}".format(
            tc_name, result)

        # Add kernal routes for receiver
        r_interface = topo["routers"][receiver]["links"][lhr]["interface"]
        result = addKernelRoute(tgen, receiver, r_interface, group)
        assert result is True, "Testcase {} :Failed \n Error {}".format(
            tc_name, result)

        # Add static routes for RPs in FHR and LHR
        next_hop_fhr = topo["routers"][rp]["links"][fhr]["ipv4"].split("/")[0]
        next_hop_lhr = topo["routers"][rp]["links"][lhr]["ipv4"].split("/")[0]
        input_dict = {
            fhr: {
                "static_routes": [{
                    "network": rp_list,
                    "next_hop": next_hop_fhr
                }]
            },
        }
        result = create_static_routes(tgen, input_dict)
        assert result is True, "Testcase {} :Failed \n Error {}".format(
            tc_name, result)

        input_dict = {
            lhr: {
                "static_routes": [{
                    "network": rp_list,
                    "next_hop": next_hop_lhr
                }]
            },
        }
        result = create_static_routes(tgen, input_dict)
        assert result is True, "Testcase {} :Failed \n Error {}".format(
            tc_name, result)
    return True
Esempio n. 20
0
def test_static_routes(request):
    """Test to create and verify static routes."""

    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)

    # Api call to create static routes
    input_dict = {
        "r1": {
            "static_routes": [
                {
                    "network": "10.0.20.1/32",
                    "no_of_ip": 9,
                    "admin_distance": 100,
                    "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
    input_dict_1 = {
        "r1": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "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)

    # Verifying RIB routes
    dut = "r3"
    protocol = "bgp"
    next_hop = ["10.0.0.2", "10.0.0.5"]
    result = verify_rib(
        tgen, "ipv4", dut, input_dict, next_hop=next_hop, protocol=protocol
    )
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    write_test_footer(tc_name)
Esempio n. 21
0
def test_static_route_with_tag_p0_tc_13_ebgp(request):
    """
    Verify static route with tag option

    """
    tc_name = request.node.name
    write_test_header(tc_name)
    tgen = get_topogen()

    # Don't run this test if we have any failure.
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)

    step("Configure 8 links between R1 and R2")
    step("Configure 1 links between R2 and R3")
    NEXT_HOP_IP = populate_nh()

    step("Configure 2 IPv4 static route (S1 and S2) in R2 with same"
         "next hop N1 28.1.1.2")
    step("Configure static route S1 with tag 1 and static route S2 with"
         "tag2")
    step("S1= ip route 10.1.1.1/24 28.1.1.2 tag 1")
    step("S2= ip route 20.1.1.1/24 28.1.1.2 tag 2")
    step("Enable redistribute static in BGP with route-map")
    reset_config_on_routers(tgen)

    for addr_type in ADDR_TYPES:
        # Enable static routes
        input_dict_4 = {
            "r2": {
                "static_routes": [
                    {
                        "network": NETWORK[addr_type],
                        "next_hop": NEXT_HOP_IP["nh1"][addr_type],
                        "tag": 4001,
                    },
                    {
                        "network": NETWORK2[addr_type],
                        "next_hop": NEXT_HOP_IP["nh1"][addr_type],
                        "tag": 4002,
                    },
                ]
            }
        }

        logger.info("Configure static routes")
        result = create_static_routes(tgen, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)
        step("verify routes are present in RIB")
        dut = "r2"
        protocol = "static"
        nh = NEXT_HOP_IP["nh1"][addr_type]
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_4,
                            next_hop=nh,
                            protocol=protocol)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(
            tc_name)

        step("Configure route-map on R2 with allow tag1 and deny tag2")

        # Create route map
        input_dict_3 = {
            "r2": {
                "route_maps": {
                    "rmap_match_tag_1_{}".format(addr_type): [
                        {
                            "action": "permit",
                            "seq_id": 10,
                            "match": {
                                addr_type: {
                                    "tag": "4001"
                                }
                            },
                        },
                        {
                            "action": "deny",
                            "seq_id": 20,
                            "match": {
                                addr_type: {
                                    "tag": "4002"
                                }
                            },
                        },
                    ]
                }
            }
        }
        result = create_route_maps(tgen, input_dict_3)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        # Configure neighbor for route map
        input_dict_4 = {
            "r2": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "neighbor": {
                                    "r3": {
                                        "dest_link": {
                                            "r2-link0": {
                                                "route_maps": [{
                                                    "name":
                                                    "rmap_match_tag_1_ipv4",
                                                    "direction":
                                                    "out",
                                                }]
                                            }
                                        }
                                    }
                                },
                                "redistribute": [{
                                    "redist_type": "static"
                                }],
                            }
                        }
                    }
                }
            }
        }
        result = create_router_bgp(tgen, topo, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        step("Verify static route S1 advetised in BGP table when tag1 permit"
             "in route-map else it is denied")
        dut = "r3"
        input_dict_0 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK2[addr_type],
                    "next_hop": NEXT_HOP_IP["nh1"][addr_type],
                    "tag": 4002,
                }]
            }
        }

        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_0,
                            protocol=protocol,
                            expected=False)
        assert result is not True, (
            "Testcase {} : Failed \nError: Route with "
            "tag 4002 is still present in RIB".format(tc_name))

        dut = "r2"
        input_dict_1 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK[addr_type],
                    "tag": 4001
                }]
            }
        }

        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_0,
                            protocol=protocol)
        assert result is True, ("Testcase {} : Failed \nError: Route with "
                                "tag 4001 is missing in RIB".format(tc_name))

        step("Modify the route-map to allow tag2 and deny tag1")
        # Create route map
        input_dict_3 = {
            "r2": {
                "route_maps": {
                    "rmap_match_tag_1_{}".format(addr_type): [
                        {
                            "action": "deny",
                            "seq_id": 10,
                            "match": {
                                addr_type: {
                                    "tag": "4001"
                                }
                            },
                        },
                        {
                            "action": "permit",
                            "seq_id": 20,
                            "match": {
                                addr_type: {
                                    "tag": "4002"
                                }
                            },
                        },
                    ]
                }
            }
        }
        result = create_route_maps(tgen, input_dict_3)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        dut = "r3"
        step("Verify static route S2 advertised in BGP table when tag2"
             "permit in route-map else it is denied")
        protocol = "bgp"
        input_dict_0 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK2[addr_type],
                    "tag": 4002
                }]
            }
        }

        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_0,
                            protocol=protocol)
        assert result is True, ("Testcase {} : Failed \nError: Route with "
                                "tag 4002 is missing in RIB".format(tc_name))

        input_dict_1 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK[addr_type],
                    "tag": 4001
                }]
            }
        }
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_1,
                            protocol=protocol,
                            expected=False)
        assert result is not True, (
            "Testcase {} : Failed \nError: Route with "
            "tag 4001 is still present in RIB".format(tc_name))

    step("Configure one static route with 2 ECMP nexthop N1 and N2")
    step("For N1 configure tag 1 and for N2 configure tag 2")
    step("S1= ip route 10.1.1.1/24 28.1.1.2 tag 1")
    step("S1= ip route 10.1.1.1/24 29.1.1.2 tag 2")
    step("configure the route-map to allow tag1 and deny tag 2")
    step("Modify the route-map to allow tag2 and deny tag1")

    for addr_type in ADDR_TYPES:
        # Enable static routes
        input_dict_4 = {
            "r2": {
                "static_routes": [
                    {
                        "network": NETWORK2[addr_type],
                        "next_hop": NEXT_HOP_IP["nh1"][addr_type],
                        "tag": 4001,
                    },
                    {
                        "network": NETWORK2[addr_type],
                        "next_hop": NEXT_HOP_IP["nh2"][addr_type],
                        "tag": 4002,
                    },
                ]
            }
        }

        logger.info("Configure static routes")
        result = create_static_routes(tgen, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        dut = "r2"
        protocol = "static"
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_4,
                            protocol=protocol,
                            fib=True)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(
            tc_name)

    step("shut/no shut of tag1 and tag2 nexthop")

    intf = topo["routers"]["r2"]["links"]["r1-link0"]["interface"]
    shutdown_bringup_interface(tgen, dut, intf, False)

    shutdown_bringup_interface(tgen, dut, intf, True)

    step("configure one static route with 3 next-hop")
    step("N1-tag1, N2-tag2, N3-tag3")
    step("S1= ip route 10.1.1.1/24 28.1.1.2 tag 1")
    step("S1= ip route 10.1.1.1/24 29.1.1.2 tag 2")
    step("S1= ip route 10.1.1.1/24 28.1.1.2 tag 3")

    for addr_type in ADDR_TYPES:
        # Enable static routes
        input_dict_4 = {
            "r2": {
                "static_routes": [
                    {
                        "network": NETWORK2[addr_type],
                        "next_hop": NEXT_HOP_IP["nh1"][addr_type],
                        "tag": 4001,
                    },
                    {
                        "network": NETWORK2[addr_type],
                        "next_hop": NEXT_HOP_IP["nh2"][addr_type],
                        "tag": 4002,
                    },
                    {
                        "network": NETWORK2[addr_type],
                        "next_hop": NEXT_HOP_IP["nh3"][addr_type],
                        "tag": 4003,
                    },
                ]
            }
        }

        logger.info("Configure static routes")
        result = create_static_routes(tgen, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        dut = "r2"
        protocol = "static"
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_4,
                            protocol=protocol)

        step("configure the route-map to allow tag2 & tag3 and deny tag1")
        # Create route map
        input_dict_3 = {
            "r2": {
                "route_maps": {
                    "rmap_match_tag_1_{}".format(addr_type): [
                        {
                            "action": "deny",
                            "seq_id": 10,
                            "match": {
                                addr_type: {
                                    "tag": "4001"
                                }
                            },
                        },
                        {
                            "action": "permit",
                            "seq_id": 20,
                            "match": {
                                addr_type: {
                                    "tag": "4002"
                                }
                            },
                        },
                        {
                            "action": "permit",
                            "seq_id": 30,
                            "match": {
                                addr_type: {
                                    "tag": "4003"
                                }
                            },
                        },
                    ]
                }
            }
        }
        result = create_route_maps(tgen, input_dict_3)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        step("Verify static route advertised in BGP table with tag3"
             " nexthop if tag2 is down")
        dut = "r3"
        protocol = "bgp"
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        step("shut / no shut of tag2 and tag3 next-hop")

        intf = topo["routers"]["r2"]["links"]["r1-link1"]["interface"]
        shutdown_bringup_interface(tgen, dut, intf, False)

        intf = topo["routers"]["r2"]["links"]["r1-link2"]["interface"]
        shutdown_bringup_interface(tgen, dut, intf, False)

        step("shut/no shut of tag2 and tag3 nexthop")
        intf = topo["routers"]["r2"]["links"]["r1-link1"]["interface"]
        shutdown_bringup_interface(tgen, dut, intf, True)

        intf = topo["routers"]["r2"]["links"]["r1-link2"]["interface"]
        shutdown_bringup_interface(tgen, dut, intf, True)

        step("Verify after shut/noshut of nexthop BGP table updated correctly")
        dut = "r3"
        protocol = "bgp"
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    write_test_footer(tc_name)
Esempio n. 22
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)
Esempio n. 23
0
def test_staticroute_with_ecmp_with_diff_AD_p0_tc4_ebgp(request):
    """
    Verify static route ECMP functionality with 8 next hop

    """
    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)
    NEXT_HOP_IP = populate_nh()

    step("Configure 8 interfaces / links between R1 and R2,")
    step("Configure IBGP IPv4 peering between R2 and R3 router.")
    reset_config_on_routers(tgen)
    NEXT_HOP_IP = populate_nh()
    nh_all = {}
    for addr_type in ADDR_TYPES:
        nh_all[addr_type] = []
        for nhp in range(1, 9):
            nh_all[addr_type].append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
    step("Configure IPv4 static route in R2 with 8 next hop"
         "N1(21.1.1.2) AD 10, N2(22.1.1.2) AD 20, N3(23.1.1.2) AD 30,"
         "N4(24.1.1.2) AD 40, N5(25.1.1.2) AD 50, N6(26.1.1.2) AD 60,"
         "N7(27.1.1.2) AD 70, N8(28.1.1.2) AD 80, Static route next-hop"
         "present on R1")
    for addr_type in ADDR_TYPES:
        for nhp in range(1, 9):
            input_dict_4 = {
                "r2": {
                    "static_routes": [{
                        "network":
                        PREFIX1[addr_type],
                        "next_hop":
                        NEXT_HOP_IP["nh" + str(nhp)][addr_type],
                        "admin_distance":
                        10 * nhp,
                    }]
                }
            }
            logger.info("Configure static routes")
            result = create_static_routes(tgen, input_dict_4)
            assert result is True, "Testcase {} : Failed \n Error: {}".format(
                tc_name, result)
        logger.info("Verifying %s routes on r2", addr_type)

        step("On R2, static route installed in RIB using "
             "show ip route with 8 next hop, lowest AD nexthop is active")
        step("On R2, static route with lowest AD nexthop installed in FIB")
        input_dict_4 = {
            "r2": {
                "static_routes": [{
                    "network": PREFIX1[addr_type],
                    "next_hop": NEXT_HOP_IP["nh1"][addr_type],
                    "admin_distance": 10,
                }]
            }
        }
        dut = "r2"
        protocol = "static"
        nh = NEXT_HOP_IP["nh1"][addr_type]
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_4,
                            next_hop=nh,
                            protocol=protocol,
                            fib=True)
        assert result is True, ("Testcase {} : Failed \nError: Route with "
                                " lowest AD is missing in RIB".format(tc_name))

        nh = []
        for nhp in range(2, 9):
            nh.append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            input_dict_4,
            next_hop=nh,
            protocol=protocol,
            fib=True,
            expected=False,
        )
        assert result is not True, (
            "Testcase {} : Failed \nError: Routes "
            " with high AD are active in RIB".format(tc_name))

    step("Configure redistribute static in BGP on R2 router")
    for addr_type in ADDR_TYPES:
        input_dict_2 = {
            "r2": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "redistribute": [{
                                    "redist_type": "static"
                                }]
                            }
                        }
                    }
                }
            }
        }

        logger.info("Configuring redistribute static")
        result = create_router_bgp(tgen, topo, input_dict_2)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        step("After configuring them, route is always active with lowest AD"
             "value and all the nexthop populated in RIB and FIB again ")
        input_dict_4 = {
            "r2": {
                "static_routes": [{
                    "network": PREFIX1[addr_type],
                    "next_hop": NEXT_HOP_IP["nh1"][addr_type],
                    "admin_distance": 10,
                }]
            }
        }
        dut = "r2"
        protocol = "static"
        nh = NEXT_HOP_IP["nh1"][addr_type]
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_4,
                            next_hop=nh,
                            protocol=protocol,
                            fib=True)
        assert result is True, ("Testcase {} : Failed \nError: Route with "
                                " lowest AD is missing in RIB".format(tc_name))

    step("Remove the static route configured with nexthop N1 to N8, one"
         "by one from running config")

    for addr_type in ADDR_TYPES:
        # delete static routes
        for nhp in range(1, 9):
            input_dict_4 = {
                "r2": {
                    "static_routes": [{
                        "network":
                        PREFIX1[addr_type],
                        "next_hop":
                        NEXT_HOP_IP["nh" + str(nhp)][addr_type],
                        "admin_distance":
                        10 * nhp,
                        "delete":
                        True,
                    }]
                }
            }

        logger.info("Configure static routes")
        result = create_static_routes(tgen, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    step("After removing the static route with N1 to N8 one by one, "
         "route become active with next preferred nexthop and nexthop which "
         "got removed is not shown in RIB and FIB")
    result = verify_rib(
        tgen,
        addr_type,
        dut,
        input_dict_4,
        next_hop=nh_all[addr_type],
        protocol=protocol,
        expected=False,
    )
    assert (
        result is not True
    ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
        tc_name)

    step("Configure the static route with nexthop N1 to N8, one by" "one")
    for addr_type in ADDR_TYPES:
        # add static routes
        for nhp in range(1, 9):
            input_dict_4 = {
                "r2": {
                    "static_routes": [{
                        "network":
                        PREFIX1[addr_type],
                        "next_hop":
                        NEXT_HOP_IP["nh" + str(nhp)][addr_type],
                        "admin_distance":
                        10 * nhp,
                    }]
                }
            }
        logger.info("Configure static routes")
        result = create_static_routes(tgen, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        step("On R2, static route with lowest AD nexthop installed in FIB")
        input_dict_4 = {
            "r2": {
                "static_routes": [{
                    "network": PREFIX1[addr_type],
                    "next_hop": NEXT_HOP_IP["nh1"][addr_type],
                    "admin_distance": 10,
                }]
            }
        }
        dut = "r2"
        protocol = "static"
        nh = NEXT_HOP_IP["nh1"][addr_type]
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_4,
                            next_hop=nh,
                            protocol=protocol,
                            fib=True)
        assert result is True, ("Testcase {} : Failed \nError: Route with "
                                " lowest AD is missing in RIB".format(tc_name))

        nh = []
        for nhp in range(2, 9):
            nh.append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            input_dict_4,
            next_hop=nh,
            protocol=protocol,
            fib=True,
            expected=False,
        )
        assert result is not True, (
            "Testcase {} : Failed \nError: Routes "
            " with high AD are active in RIB".format(tc_name))

    step("Random shut of the nexthop interfaces")
    randnum = random.randint(0, 7)
    for addr_type in ADDR_TYPES:
        intf = topo["routers"]["r2"]["links"]["r1-link" +
                                              str(randnum)]["interface"]
        shutdown_bringup_interface(tgen, dut, intf, False)
        nhip = NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type]
        input_dict_5 = {
            "r2": {
                "static_routes": [{
                    "network":
                    PREFIX1[addr_type],
                    "next_hop":
                    NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type],
                }]
            }
        }
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            input_dict_5,
            next_hop=nhip,
            protocol=protocol,
            expected=False,
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
            tc_name)

    step("Random no shut of the nexthop interfaces")
    for addr_type in ADDR_TYPES:
        intf = topo["routers"]["r2"]["links"]["r1-link" +
                                              str(randnum)]["interface"]
        shutdown_bringup_interface(tgen, dut, intf, True)
        nhip = NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type]
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_5,
                            next_hop=nhip,
                            protocol=protocol)
        assert (
            result is True
        ), "Testcase {} : Failed \n" "Error: Routes are missing in RIB".format(
            tc_name)

    step("Reload the FRR router")
    # stop/start -> restart FRR router and verify
    stop_router(tgen, "r2")
    start_router(tgen, "r2")

    step("After reload of FRR router, static route installed "
         "in RIB and FIB properly .")
    for addr_type in ADDR_TYPES:
        input_dict_4 = {
            "r2": {
                "static_routes": [{
                    "network": PREFIX1[addr_type],
                    "next_hop": NEXT_HOP_IP["nh1"][addr_type],
                    "admin_distance": 10,
                }]
            }
        }
        dut = "r2"
        protocol = "static"
        nh = NEXT_HOP_IP["nh1"][addr_type]
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_4,
                            next_hop=nh,
                            protocol=protocol,
                            fib=True)
        assert result is True, ("Testcase {} : Failed \nError: Route with "
                                " lowest AD is missing in RIB".format(tc_name))

        nh = []
        for nhp in range(2, 9):
            nh.append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            input_dict_4,
            next_hop=nh,
            protocol=protocol,
            fib=True,
            expected=False,
        )
        assert result is not True, (
            "Testcase {} : Failed \nError: Routes "
            " with high AD are active in RIB".format(tc_name))

    write_test_footer(tc_name)
Esempio n. 24
0
def test_bgp_with_loopback_interface(request):
    """
    Test BGP with loopback interface

    Adding keys:value pair  "dest_link": "lo" and "source_link": "lo"
    peer dict of input json file for all router's creating config using
    loopback interface. Once BGP neighboship is up then verifying BGP
    convergence
    """

    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)

    for routerN in sorted(topo["routers"].keys()):
        for bgp_neighbor in topo["routers"][routerN]["bgp"]["address_family"]["ipv4"][
            "unicast"
        ]["neighbor"].keys():

            # Adding ['source_link'] = 'lo' key:value pair
            topo["routers"][routerN]["bgp"]["address_family"]["ipv4"]["unicast"][
                "neighbor"
            ][bgp_neighbor]["dest_link"] = {
                "lo": {
                    "source_link": "lo",
                }
            }

    # Creating configuration from JSON
    build_config_from_json(tgen, topo)

    input_dict = {
        "r1": {
            "static_routes": [
                {"network": "1.0.2.17/32", "next_hop": "10.0.0.2"},
                {"network": "1.0.3.17/32", "next_hop": "10.0.0.6"},
            ]
        },
        "r2": {
            "static_routes": [
                {"network": "1.0.1.17/32", "next_hop": "10.0.0.1"},
                {"network": "1.0.3.17/32", "next_hop": "10.0.0.10"},
            ]
        },
        "r3": {
            "static_routes": [
                {"network": "1.0.1.17/32", "next_hop": "10.0.0.5"},
                {"network": "1.0.2.17/32", "next_hop": "10.0.0.9"},
                {"network": "1.0.4.17/32", "next_hop": "10.0.0.14"},
            ]
        },
        "r4": {"static_routes": [{"network": "1.0.3.17/32", "next_hop": "10.0.0.13"}]},
    }
    result = create_static_routes(tgen, input_dict)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    # Api call verify whether BGP is converged
    result = verify_bgp_convergence(tgen, topo)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    write_test_footer(tc_name)
Esempio n. 25
0
def test_frr_intf_name_as_gw_gap_tc4_ebgp_p0(request):
    """
    Verify static route configure with interface name as gateway'
        'address'
    """
    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)

    dut = "r1"
    intf = topo["routers"]["r1"]["links"]["r2-link0"]["interface"]
    nh = topo["routers"]["r1"]["links"]["r2-link0"]
    ip_list = {
        "ipv4": [(dut, intf, ["1.1.1.1/32"], nh["ipv4"].split("/")[0])],
        "ipv6": [(dut, intf, ["4001::32/128"], nh["ipv6"].split("/")[0])],
    }

    step("Configure IPv4 and IPv6 static route in FRR with different next"
         "hop (ens224 as nexthop))")
    step("ip route 2.2.2.0/24 20.1.1.1 ens224 ----from FRR cli")
    step("ipv6 route 2000::1/120 5000::1 ens224 ----from FRR cli")

    for addr_type in ADDR_TYPES:
        # Enable static routes
        nh = topo["routers"]["r2"]["links"]["r1-link0"][addr_type].split(
            "/")[0]
        input_dict_4 = {
            "r1": {
                "static_routes": [{
                    "network": ip_list[addr_type][0][2][0],
                    "next_hop": nh
                }]
            }
        }

        logger.info("Configure static routes")
        result = create_static_routes(tgen, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        step("IPv4 and IPv6 Static route added in FRR verify using "
             "show ip route , nexthop is resolved using show nht")
        protocol = "static"
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_4,
                            protocol=protocol,
                            next_hop=nh)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(
            tc_name)

        input_dict_nh = {
            "r1": {
                nh: {
                    "Address": nh,
                    "resolvedVia": "connected",
                    "nexthops": {
                        "nexthop1": {
                            "Interfcae": intf
                        }
                    },
                }
            }
        }
        result = verify_ip_nht(tgen, input_dict_nh)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Nexthop is" " missing in RIB".format(
            tc_name)

        step("Shut / no shut IPv4 and IPv6 static next hop interface from"
             "kernel and FRR CLI")

        shutdown_bringup_interface(tgen, dut, intf, False)

        step(
            "After shut of nexthop interface, IPv4 and IPv6 route got removed "
            "from RIB verify using show ip route show nht")
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            input_dict_4,
            protocol=protocol,
            next_hop=nh,
            expected=False,
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(
            tc_name)

        shutdown_bringup_interface(tgen, dut, intf, True)

        step("After no shut route got added again in RIB /FIB using "
             "show ip route nexthop is resolved using show nht")
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_4,
                            protocol=protocol)
        assert result is True, "Testcase {} : Failed".format(tc_name)

    for addr_type in ADDR_TYPES:
        nh = topo["routers"]["r2"]["links"]["r1-link0"][addr_type].split(
            "/")[0]
        input_dict_4 = {
            "r1": {
                "static_routes": [{
                    "network": ip_list[addr_type][0][2][0],
                    "next_hop": nh,
                    "delete": True,
                }]
            }
        }

        logger.info("Configure static routes")
        result = create_static_routes(tgen, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        step("Removing FRR configured static route verify FRR route also "
             "removed from FRR")
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            input_dict_4,
            protocol=protocol,
            next_hop=nh,
            expected=False,
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \nError: Routes" " still present in RIB".format(
            tc_name)

    write_test_footer(tc_name)
Esempio n. 26
0
def test_bgp_with_loopback_with_same_subnet_p1(request):
    """
    Verify routes not installed in zebra when /32 routes received
    with loopback BGP session subnet
    """

    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)
    step("Delete BGP seesion created initially")
    input_dict_r1 = {
        "r1": {"bgp": {"delete": True}},
        "r2": {"bgp": {"delete": True}},
        "r3": {"bgp": {"delete": True}},
        "r4": {"bgp": {"delete": True}},
    }
    result = create_router_bgp(tgen, topo, input_dict_r1)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)

    step("Create BGP session over loop address")
    topo_modify = deepcopy(topo)

    for routerN in sorted(topo["routers"].keys()):
        for addr_type in ADDR_TYPES:
            for bgp_neighbor in topo_modify["routers"][routerN]["bgp"][
                "address_family"
            ][addr_type]["unicast"]["neighbor"].keys():

                # Adding ['source_link'] = 'lo' key:value pair
                topo_modify["routers"][routerN]["bgp"]["address_family"][addr_type][
                    "unicast"
                ]["neighbor"][bgp_neighbor]["dest_link"] = {
                    "lo": {"source_link": "lo", "ebgp_multihop": 2}
                }

    result = create_router_bgp(tgen, topo_modify["routers"])
    assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)

    step("Disable IPv6 BGP nbr from ipv4 address family")
    raw_config = {
        "r1": {
            "raw_config": [
                "router bgp {}".format(topo["routers"]["r1"]["bgp"]["local_as"]),
                "address-family ipv4 unicast",
                "no neighbor {} activate".format(
                    topo["routers"]["r2"]["links"]["lo"]["ipv6"].split("/")[0]
                ),
                "no neighbor {} activate".format(
                    topo["routers"]["r3"]["links"]["lo"]["ipv6"].split("/")[0]
                ),
            ]
        },
        "r2": {
            "raw_config": [
                "router bgp {}".format(topo["routers"]["r2"]["bgp"]["local_as"]),
                "address-family ipv4 unicast",
                "no neighbor {} activate".format(
                    topo["routers"]["r1"]["links"]["lo"]["ipv6"].split("/")[0]
                ),
                "no neighbor {} activate".format(
                    topo["routers"]["r3"]["links"]["lo"]["ipv6"].split("/")[0]
                ),
            ]
        },
        "r3": {
            "raw_config": [
                "router bgp {}".format(topo["routers"]["r3"]["bgp"]["local_as"]),
                "address-family ipv4 unicast",
                "no neighbor {} activate".format(
                    topo["routers"]["r1"]["links"]["lo"]["ipv6"].split("/")[0]
                ),
                "no neighbor {} activate".format(
                    topo["routers"]["r2"]["links"]["lo"]["ipv6"].split("/")[0]
                ),
                "no neighbor {} activate".format(
                    topo["routers"]["r4"]["links"]["lo"]["ipv6"].split("/")[0]
                ),
            ]
        },
        "r4": {
            "raw_config": [
                "router bgp {}".format(topo["routers"]["r4"]["bgp"]["local_as"]),
                "address-family ipv4 unicast",
                "no neighbor {} activate".format(
                    topo["routers"]["r3"]["links"]["lo"]["ipv6"].split("/")[0]
                ),
            ]
        },
    }

    step("Configure kernel routes")
    result = apply_raw_config(tgen, raw_config)
    assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)

    r1_ipv4_lo = topo["routers"]["r1"]["links"]["lo"]["ipv4"]
    r1_ipv6_lo = topo["routers"]["r1"]["links"]["lo"]["ipv6"]
    r2_ipv4_lo = topo["routers"]["r2"]["links"]["lo"]["ipv4"]
    r2_ipv6_lo = topo["routers"]["r2"]["links"]["lo"]["ipv6"]
    r3_ipv4_lo = topo["routers"]["r3"]["links"]["lo"]["ipv4"]
    r3_ipv6_lo = topo["routers"]["r3"]["links"]["lo"]["ipv6"]
    r4_ipv4_lo = topo["routers"]["r4"]["links"]["lo"]["ipv4"]
    r4_ipv6_lo = topo["routers"]["r4"]["links"]["lo"]["ipv6"]

    r1_r2 = topo["routers"]["r1"]["links"]["r2"]["ipv6"].split("/")[0]
    r2_r1 = topo["routers"]["r2"]["links"]["r1"]["ipv6"].split("/")[0]
    r1_r3 = topo["routers"]["r1"]["links"]["r3"]["ipv6"].split("/")[0]
    r3_r1 = topo["routers"]["r3"]["links"]["r1"]["ipv6"].split("/")[0]
    r2_r3 = topo["routers"]["r2"]["links"]["r3"]["ipv6"].split("/")[0]
    r3_r2 = topo["routers"]["r3"]["links"]["r2"]["ipv6"].split("/")[0]
    r3_r4 = topo["routers"]["r3"]["links"]["r4"]["ipv6"].split("/")[0]
    r4_r3 = topo["routers"]["r4"]["links"]["r3"]["ipv6"].split("/")[0]

    r1_r2_ipv4 = topo["routers"]["r1"]["links"]["r2"]["ipv4"].split("/")[0]
    r2_r1_ipv4 = topo["routers"]["r2"]["links"]["r1"]["ipv4"].split("/")[0]
    r1_r3_ipv4 = topo["routers"]["r1"]["links"]["r3"]["ipv4"].split("/")[0]
    r3_r1_ipv4 = topo["routers"]["r3"]["links"]["r1"]["ipv4"].split("/")[0]
    r2_r3_ipv4 = topo["routers"]["r2"]["links"]["r3"]["ipv4"].split("/")[0]
    r3_r2_ipv4 = topo["routers"]["r3"]["links"]["r2"]["ipv4"].split("/")[0]
    r3_r4_ipv4 = topo["routers"]["r3"]["links"]["r4"]["ipv4"].split("/")[0]
    r4_r3_ipv4 = topo["routers"]["r4"]["links"]["r3"]["ipv4"].split("/")[0]

    r1_r2_intf = topo["routers"]["r1"]["links"]["r2"]["interface"]
    r2_r1_intf = topo["routers"]["r2"]["links"]["r1"]["interface"]
    r1_r3_intf = topo["routers"]["r1"]["links"]["r3"]["interface"]
    r3_r1_intf = topo["routers"]["r3"]["links"]["r1"]["interface"]
    r2_r3_intf = topo["routers"]["r2"]["links"]["r3"]["interface"]
    r3_r2_intf = topo["routers"]["r3"]["links"]["r2"]["interface"]
    r3_r4_intf = topo["routers"]["r3"]["links"]["r4"]["interface"]
    r4_r3_intf = topo["routers"]["r4"]["links"]["r3"]["interface"]

    ipv4_list = [
        ("r1", r1_r2_intf, r2_ipv4_loopback),
        ("r1", r1_r3_intf, r3_ipv4_loopback),
        ("r2", r2_r1_intf, r1_ipv4_loopback),
        ("r2", r2_r3_intf, r3_ipv4_loopback),
        ("r3", r3_r1_intf, r1_ipv4_loopback),
        ("r3", r3_r2_intf, r2_ipv4_loopback),
        ("r3", r3_r4_intf, r4_ipv4_loopback),
        ("r4", r4_r3_intf, r3_ipv4_loopback),
    ]

    ipv6_list = [
        ("r1", r1_r2_intf, r2_ipv6_loopback, r2_r1),
        ("r1", r1_r3_intf, r3_ipv6_loopback, r3_r1),
        ("r2", r2_r1_intf, r1_ipv6_loopback, r1_r2),
        ("r2", r2_r3_intf, r3_ipv6_loopback, r3_r2),
        ("r3", r3_r1_intf, r1_ipv6_loopback, r1_r3),
        ("r3", r3_r2_intf, r2_ipv6_loopback, r2_r3),
        ("r3", r3_r4_intf, r4_ipv6_loopback, r4_r3),
        ("r4", r4_r3_intf, r3_ipv6_loopback, r3_r4),
    ]

    for dut, intf, loop_addr in ipv4_list:
        result = addKernelRoute(tgen, dut, intf, loop_addr)
        assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)

    for dut, intf, loop_addr, next_hop in ipv6_list:
        result = addKernelRoute(tgen, dut, intf, loop_addr, next_hop)
        assert result is True, "Testcase {}:Failed \n Error: {}".format(tc_name, result)

    step("Configure static routes")

    input_dict = {
        "r1": {
            "static_routes": [
                {"network": r2_ipv4_loopback, "next_hop": r2_r1_ipv4},
                {"network": r3_ipv4_loopback, "next_hop": r3_r1_ipv4},
                {"network": r2_ipv6_loopback, "next_hop": r2_r1},
                {"network": r3_ipv6_loopback, "next_hop": r3_r1},
            ]
        },
        "r2": {
            "static_routes": [
                {"network": r1_ipv4_loopback, "next_hop": r1_r2_ipv4},
                {"network": r3_ipv4_loopback, "next_hop": r3_r2_ipv4},
                {"network": r1_ipv6_loopback, "next_hop": r1_r2},
                {"network": r3_ipv6_loopback, "next_hop": r3_r2},
            ]
        },
        "r3": {
            "static_routes": [
                {"network": r1_ipv4_loopback, "next_hop": r1_r3_ipv4},
                {"network": r2_ipv4_loopback, "next_hop": r2_r3_ipv4},
                {"network": r4_ipv4_loopback, "next_hop": r4_r3_ipv4},
                {"network": r1_ipv6_loopback, "next_hop": r1_r3},
                {"network": r2_ipv6_loopback, "next_hop": r2_r3},
                {"network": r4_ipv6_loopback, "next_hop": r4_r3},
            ]
        },
        "r4": {
            "static_routes": [
                {"network": r3_ipv4_loopback, "next_hop": r3_r4_ipv4},
                {"network": r3_ipv6_loopback, "next_hop": r3_r4},
            ]
        },
    }
    result = create_static_routes(tgen, input_dict)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    step("Verify BGP session convergence")

    result = verify_bgp_convergence(tgen, topo_modify)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    step("Configure redistribute connected on R2 and R4")
    input_dict_1 = {
        "r2": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {"redistribute": [{"redist_type": "connected"}]}
                    },
                    "ipv6": {
                        "unicast": {"redistribute": [{"redist_type": "connected"}]}
                    },
                }
            }
        },
        "r4": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {"redistribute": [{"redist_type": "connected"}]}
                    },
                    "ipv6": {
                        "unicast": {"redistribute": [{"redist_type": "connected"}]}
                    },
                }
            }
        },
    }

    result = create_router_bgp(tgen, topo, input_dict_1)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    step("Verify Ipv4 and Ipv6 network installed in R1 RIB but not in FIB")
    input_dict_r1 = {
        "r1": {
            "static_routes": [
                {"network": "1.0.2.17/32"},
                {"network": "2001:db8:f::2:17/128"},
            ]
        }
    }

    dut = "r1"
    protocol = "bgp"
    for addr_type in ADDR_TYPES:
        result = verify_fib_routes(
            tgen, addr_type, dut, input_dict_r1, expected=False
        )  # pylint: disable=E1123
        assert result is not True, (
            "Testcase {} : Failed \n".format(tc_name)
            + "Expected behavior: routes should not present in fib \n"
            + "Error: {}".format(result)
        )

    step("Verify Ipv4 and Ipv6 network installed in r3 RIB but not in FIB")
    input_dict_r3 = {
        "r3": {
            "static_routes": [
                {"network": "1.0.4.17/32"},
                {"network": "2001:db8:f::4:17/128"},
            ]
        }
    }
    dut = "r3"
    protocol = "bgp"
    for addr_type in ADDR_TYPES:
        result = verify_fib_routes(
            tgen, addr_type, dut, input_dict_r1, expected=False
        )  # pylint: disable=E1123
        assert result is not True, (
            "Testcase {} : Failed \n".format(tc_name)
            + "Expected behavior: routes should not present in fib \n"
            + "Error: {}".format(result)
        )

    write_test_footer(tc_name)
Esempio n. 27
0
def test_ospf_routemaps_functionality_tc20_p0(request):
    """
    OSPF route map support functionality.

    Verify OSPF route map support functionality when route map is not
    configured at system level but configured in OSPF

    """
    tc_name = request.node.name
    write_test_header(tc_name)
    tgen = get_topogen()
    global topo
    step("Bring up the base config as per the topology")
    reset_config_on_routers(tgen)

    step("Create static routes(10.0.20.1/32 and 10.0.20.2/32) in R0")
    # Create Static routes
    input_dict = {
        "r0": {
            "static_routes": [{
                "network": NETWORK["ipv4"][0],
                "no_of_ip": 5,
                "next_hop": "Null0",
            }]
        }
    }
    result = create_static_routes(tgen, input_dict)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Redistribute to ospf using route map ( non existent route map)")
    ospf_red_r1 = {
        "r0": {
            "ospf": {
                "redistribute": [{
                    "redist_type": "static",
                    "route_map": "rmap_ipv4"
                }]
            }
        }
    }
    result = create_router_ospf(tgen, topo, ospf_red_r1)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Verify that routes are not allowed in OSPF even tough no "
         "matching routing map is configured.")

    dut = "r1"
    protocol = "ospf"
    result = verify_ospf_rib(tgen, dut, input_dict, attempts=2, expected=False)
    assert result is not True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    result = verify_rib(tgen,
                        "ipv4",
                        dut,
                        input_dict,
                        protocol=protocol,
                        attempts=2,
                        expected=False)
    assert result is not True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("configure the route map with the same name that is used "
         "in the ospf with deny rule.")

    # Create route map
    routemaps = {"r0": {"route_maps": {"rmap_ipv4": [{"action": "deny"}]}}}
    result = create_route_maps(tgen, routemaps)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("verify that now route map is activated & routes are denied in OSPF.")
    dut = "r1"
    protocol = "ospf"
    result = verify_ospf_rib(tgen, dut, input_dict, expected=False)
    assert result is not True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    result = verify_rib(tgen,
                        "ipv4",
                        dut,
                        input_dict,
                        protocol=protocol,
                        expected=False)
    assert result is not True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    # Create route map
    routemaps = {"r0": {"route_maps": {"rmap_ipv4": [{"action": "deny"}]}}}
    result = create_route_maps(tgen, routemaps)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("verify that now route map is activated & routes are denied in OSPF.")
    dut = "r1"
    protocol = "ospf"
    result = verify_ospf_rib(tgen, dut, input_dict, expected=False)
    assert result is not True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    result = verify_rib(tgen,
                        "ipv4",
                        dut,
                        input_dict,
                        protocol=protocol,
                        expected=False)
    assert result is not True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Delete the route map.")
    # Create route map
    routemaps = {
        "r0": {
            "route_maps": {
                "rmap_ipv4": [{
                    "action": "deny",
                    "delete": True
                }]
            }
        }
    }
    result = create_route_maps(tgen, routemaps)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Verify that routes are allowed in OSPF even tough "
         "no matching routing map is configured.")
    dut = "r1"
    protocol = "ospf"
    result = verify_ospf_rib(tgen, dut, input_dict, expected=False)
    assert result is not True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    result = verify_rib(tgen,
                        "ipv4",
                        dut,
                        input_dict,
                        protocol=protocol,
                        expected=False)
    assert result is not True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    write_test_footer(tc_name)
Esempio n. 28
0
def add_default_routes(tgen):
    """
    API to do prerequisite config for testsuite

    parameters:
    -----------
    * `tgen`: topogen object
    """

    step("Add default routes..")

    default_routes = {
        "e1": {
            "static_routes": [
                {
                    "network": "{}/32".format(VXLAN["local_addr"]["d1"]),
                    "next_hop": topo["routers"]["d1"]["links"]["e1-link1"][
                        "ipv4"
                    ].split("/")[0],
                },
                {
                    "network": "{}/32".format(VXLAN["local_addr"]["d2"]),
                    "next_hop": topo["routers"]["d2"]["links"]["e1-link1"][
                        "ipv4"
                    ].split("/")[0],
                },
            ]
        },
        "d1": {
            "static_routes": [
                {
                    "network": "{}/32".format(VXLAN["local_addr"]["e1"]),
                    "next_hop": topo["routers"]["e1"]["links"]["d1-link1"][
                        "ipv4"
                    ].split("/")[0],
                },
                {
                    "network": "{}/32".format(VXLAN["local_addr"]["d2"]),
                    "next_hop": topo["routers"]["e1"]["links"]["d1-link1"][
                        "ipv4"
                    ].split("/")[0],
                },
            ]
        },
        "d2": {
            "static_routes": [
                {
                    "network": "{}/32".format(VXLAN["local_addr"]["d1"]),
                    "next_hop": topo["routers"]["e1"]["links"]["d2-link1"][
                        "ipv4"
                    ].split("/")[0],
                },
                {
                    "network": "{}/32".format(VXLAN["local_addr"]["e1"]),
                    "next_hop": topo["routers"]["e1"]["links"]["d2-link1"][
                        "ipv4"
                    ].split("/")[0],
                },
            ]
        },
    }

    result = create_static_routes(tgen, default_routes)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
Esempio n. 29
0
def test_ospf_redistribution_tc8_p1(request):
    """
    Test OSPF redistribution of connected routes.

    Verify OSPF redistribution of connected routes when bgp multi hop
    neighbor is configured using ospf routes

    """
    tc_name = request.node.name
    write_test_header(tc_name)
    tgen = get_topogen()
    global topo
    step("Bring up the base config.")
    step("Configure loopback interface on all routers, and redistribut"
         "e connected routes into ospf")
    reset_config_on_routers(tgen)

    step("verify that connected routes -loopback is found in all routers"
         "advertised/exchaged via ospf")
    for rtr in topo["routers"]:
        redistribute_ospf(tgen, topo, rtr, "static")
        redistribute_ospf(tgen, topo, rtr, "connected")
    for node in topo["routers"]:
        input_dict = {
            "r0": {
                "static_routes": [{
                    "network":
                    topo["routers"][node]["links"]["lo"]["ipv4"],
                    "no_of_ip":
                    1,
                }]
            }
        }
        for rtr in topo["routers"]:
            result = verify_rib(tgen, "ipv4", rtr, input_dict)
            assert result is True, "Testcase {} : Failed \n Error: {}".format(
                tc_name, result)

    step("Configure E BGP multi hop using the loopback addresses.")
    as_num = 100
    for node in topo["routers"]:
        as_num += 1
        topo["routers"][node].update({
            "bgp": {
                "local_as": as_num,
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "neighbor": {}
                        }
                    }
                },
            }
        })
    for node in topo["routers"]:
        for rtr in topo["routers"]:
            if node is not rtr:
                topo["routers"][node]["bgp"]["address_family"]["ipv4"][
                    "unicast"]["neighbor"].update({
                        rtr: {
                            "dest_link": {
                                "lo": {
                                    "source_link": "lo",
                                    "ebgp_multihop": 2
                                }
                            }
                        }
                    })

    result = create_router_bgp(tgen, topo, topo["routers"])
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Verify that BGP neighbor is ESTABLISHED")
    result = verify_bgp_convergence(tgen, topo)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, result)
    step("Configure couple of static routes in R0 and "
         "Redistribute static routes in R1 bgp.")

    for rtr in topo["routers"]:
        redistribute_ospf(tgen, topo, rtr, "static", delete=True)

    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)

    configure_bgp_on_r0 = {
        "r0": {
            "bgp": {
                "address_family": {
                    "ipv4": {
                        "unicast": {
                            "redistribute": [{
                                "redist_type": "static"
                            }]
                        }
                    }
                }
            }
        }
    }
    result = create_router_bgp(tgen, topo, configure_bgp_on_r0)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)
    protocol = "bgp"
    for rtr in ["r1", "r2", "r3"]:
        result = verify_rib(tgen, "ipv4", rtr, input_dict, protocol=protocol)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    step("Clear ospf neighbours in R0")
    for rtr in topo["routers"]:
        clear_ospf(tgen, rtr)

    step("Verify that OSPF neighbours are reset and forms new adjacencies.")
    # Api call verify whether OSPF is converged
    ospf_covergence = verify_ospf_neighbor(tgen, topo)
    assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
        ospf_covergence)

    step("Verify that BGP neighbours are reset and forms new adjacencies.")
    result = verify_bgp_convergence(tgen, topo)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, result)

    protocol = "bgp"
    for rtr in ["r1", "r2", "r3"]:
        result = verify_rib(tgen, "ipv4", rtr, input_dict, protocol=protocol)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    write_test_footer(tc_name)
def test_static_route_2nh_admin_dist_p0_tc_2_ebgp(request):
    """
    Verify static route functionality with 2 next hop & different AD value.

    """
    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 IPv4 static route (10.1.1.1) in R2 with next hop N1"
         "(28.1.1.2 ) AD 10 and N2 (29.1.1.2) AD 20 , Static route next-hop"
         "present on R1 \n ex :- ip route 10.1.1.1/24 28.1.1.2 10 & "
         "ip route 10.1.1.1/24 29.1.1.2 20")

    reset_config_on_routers(tgen)
    next_hop_ip = populate_nh()
    for addr_type in ADDR_TYPES:
        input_dict_4 = {
            "r2": {
                "static_routes": [
                    {
                        "network": NETWORK2[addr_type],
                        "next_hop": next_hop_ip["nh1"][addr_type],
                        "admin_distance": 10,
                    },
                    {
                        "network": NETWORK2[addr_type],
                        "next_hop": next_hop_ip["nh2"][addr_type],
                        "admin_distance": 20,
                    },
                ]
            }
        }
        logger.info("Configure static routes")
        result = create_static_routes(tgen, input_dict_4)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        step("On R2, static route installed in RIB using "
             "show ip route with 2 next hop , lowest AD nexthop is active ")
        rte1_nh1 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK2[addr_type],
                    "next_hop": next_hop_ip["nh1"][addr_type],
                    "admin_distance": 10,
                }]
            }
        }
        nh = [next_hop_ip["nh1"][addr_type]]
        dut = "r2"
        protocol = "static"
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            rte1_nh1,
                            next_hop=nh,
                            protocol=protocol,
                            fib=True)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes is" "missing in RIB".format(
            tc_name)

        rte2_nh2 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK2[addr_type],
                    "next_hop": next_hop_ip["nh2"][addr_type],
                    "admin_distance": 20,
                }]
            }
        }
        nh = [next_hop_ip["nh2"][addr_type]]
        dut = "r2"
        protocol = "static"
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            rte2_nh2,
            next_hop=nh,
            protocol=protocol,
            fib=True,
            expected=False,
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(
            tc_name)

        step("Configure IBGP IPv4 peering between R2 and R3 router.")
        step("Explicit route is added in R3 for R2 nexthop rechability")
        rt3_rtes = {
            "r3": {
                "static_routes": [
                    {
                        "network":
                        next_hop_ip["nh1"][addr_type] + "/32",
                        "next_hop":
                        topo["routers"]["r2"]["links"]["r3"][addr_type],
                    },
                    {
                        "network":
                        next_hop_ip["nh2"][addr_type] + "/32",
                        "next_hop":
                        topo["routers"]["r2"]["links"]["r3"][addr_type],
                    },
                ]
            }
        }
        logger.info("Configure static routes")
        result = create_static_routes(tgen, rt3_rtes)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)
        step("Configure redistribute static in BGP on R2 router")

        input_dict_2 = {
            "r2": {
                "bgp": {
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "redistribute": [{
                                    "redist_type": "static"
                                }]
                            }
                        }
                    }
                }
            }
        }
        result = create_router_bgp(tgen, topo, input_dict_2)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        step("Remove the static route configured with nexthop N1 from"
             "running config")
        rt1_nh1 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK[addr_type],
                    "next_hop": next_hop_ip["nh1"][addr_type],
                    "admin_distance": 10,
                    "delete": True,
                }]
            }
        }

        logger.info("Configure static routes")
        result = create_static_routes(tgen, rt1_nh1)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        step("On R2, after removing the static route with N1 , "
             "route become active with nexthop N2 and vice versa.")
        rte1_nh1 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK2[addr_type],
                    "next_hop": next_hop_ip["nh1"][addr_type],
                    "admin_distance": 10,
                }]
            }
        }
        nh = [next_hop_ip["nh1"][addr_type]]
        dut = "r2"
        protocol = "static"
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            rte1_nh1,
            next_hop=nh,
            protocol=protocol,
            fib=True,
            expected=False,
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \nError: Routes is" "missing in RIB".format(
            tc_name)

        rte2_nh2 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK2[addr_type],
                    "next_hop": next_hop_ip["nh2"][addr_type],
                    "admin_distance": 20,
                }]
            }
        }
        nh = [next_hop_ip["nh2"][addr_type]]
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            rte2_nh2,
                            next_hop=nh,
                            protocol=protocol,
                            fib=True)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(
            tc_name)

        step("Configure the static route with nexthop N1")
        rte1_nh1 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK[addr_type],
                    "next_hop": next_hop_ip["nh1"][addr_type],
                    "admin_distance": 10,
                }]
            }
        }
        logger.info("Configure static routes")
        result = create_static_routes(tgen, rte1_nh1)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        step("Remove the static route configured with nexthop N2 from"
             "running config")
        rte2_nh2 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK[addr_type],
                    "next_hop": next_hop_ip["nh2"][addr_type],
                    "admin_distance": 20,
                    "delete": True,
                }]
            }
        }
        logger.info("Configure static routes")
        result = create_static_routes(tgen, rte2_nh2)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        step("On R2, after removing the static route with N2 , "
             "route become active with nexthop N1 and vice versa.")
        nh = next_hop_ip["nh2"][addr_type]
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            rte2_nh2,
            next_hop=nh,
            protocol=protocol,
            expected=False,
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \nError: Routes is" " still present in RIB".format(
            tc_name)

        nh = [next_hop_ip["nh1"][addr_type]]
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            rte1_nh1,
                            next_hop=nh,
                            protocol=protocol)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(
            tc_name)

        step("Configure the static route with nexthop N2")
        rte2_nh2 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK[addr_type],
                    "next_hop": next_hop_ip["nh2"][addr_type],
                    "admin_distance": 20,
                }]
            }
        }

        logger.info("Configure static routes")
        result = create_static_routes(tgen, rte2_nh2)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

        step("Shut nexthop interface N1")
        intf = topo["routers"]["r2"]["links"]["r1-link0"]["interface"]

        shutdown_bringup_interface(tgen, dut, intf, False)

        step("after shut of nexthop N1 , route become active with nexthop N2")

        nh = next_hop_ip["nh1"][addr_type]
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            rte1_nh1,
            next_hop=nh,
            protocol=protocol,
            expected=False,
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \nError: Routes is" " still present in RIB".format(
            tc_name)

        nh = [next_hop_ip["nh2"][addr_type]]
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            rte2_nh2,
                            next_hop=nh,
                            protocol=protocol,
                            fib=True)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(
            tc_name)

        step("No shut the nexthop interface N1")
        shutdown_bringup_interface(tgen, dut, intf, True)

        step("after shut of nexthop N1 , route become active "
             "with nexthop N2 and vice versa.")
        nh = [next_hop_ip["nh1"][addr_type]]

        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            rte1_nh1,
                            next_hop=nh,
                            protocol=protocol,
                            fib=True)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(
            tc_name)

        step("Shut nexthop interface N2")
        intf = topo["routers"]["r2"]["links"]["r1-link1"]["interface"]

        shutdown_bringup_interface(tgen, dut, intf, False)

        step(" after shut of nexthop N1 , route become active with "
             "nexthop N2 and vice versa.")
        nh = next_hop_ip["nh2"][addr_type]

        result = verify_rib(
            tgen,
            addr_type,
            dut,
            rte2_nh2,
            next_hop=nh,
            protocol=protocol,
            expected=False,
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \nError: Routes is" " still present in RIB".format(
            tc_name)

        nh = [next_hop_ip["nh1"][addr_type]]
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            rte1_nh1,
                            next_hop=nh,
                            protocol=protocol)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(
            tc_name)

        step("No shut nexthop interface N2")
        shutdown_bringup_interface(tgen, dut, intf, True)

        step("after shut of nexthop N1 , route become active "
             "with nexthop N2 and vice versa.")
        rte1_nh1 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK2[addr_type],
                    "next_hop": next_hop_ip["nh1"][addr_type],
                    "admin_distance": 10,
                }]
            }
        }
        nh = [next_hop_ip["nh1"][addr_type]]
        dut = "r2"
        protocol = "static"
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            rte1_nh1,
                            next_hop=nh,
                            protocol=protocol,
                            fib=True)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes is" "missing in RIB".format(
            tc_name)

        rte2_nh2 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK2[addr_type],
                    "next_hop": next_hop_ip["nh2"][addr_type],
                    "admin_distance": 20,
                }]
            }
        }
        nh = [next_hop_ip["nh2"][addr_type]]
        dut = "r2"
        protocol = "static"
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            rte2_nh2,
            next_hop=nh,
            protocol=protocol,
            fib=True,
            expected=False,
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(
            tc_name)

        dut = "r3"
        protocol = "bgp"

        result = verify_rib(
            tgen,
            addr_type,
            dut,
            rte2_nh2,
            next_hop=nh,
            protocol=protocol,
            fib=True,
            expected=False,
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(
            tc_name)

        dut = "r2"
        step("Reload the FRR router")
        # stop/start -> restart FRR router and verify
        stop_router(tgen, "r2")

        start_router(tgen, "r2")

        step("After reload of FRR router , static route installed"
             " in RIB and FIB properly .")
        rte1_nh1 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK2[addr_type],
                    "next_hop": next_hop_ip["nh1"][addr_type],
                    "admin_distance": 10,
                }]
            }
        }
        nh = [next_hop_ip["nh1"][addr_type]]
        dut = "r2"
        protocol = "static"
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            rte1_nh1,
                            next_hop=nh,
                            protocol=protocol,
                            fib=True)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes is" "missing in RIB".format(
            tc_name)

        dut = "r3"
        protocol = "bgp"
        result = verify_bgp_rib(tgen, addr_type, dut, rte1_nh1, next_hop=nh)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes is" "missing in RIB".format(
            tc_name)

        rte2_nh2 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK2[addr_type],
                    "next_hop": next_hop_ip["nh2"][addr_type],
                    "admin_distance": 20,
                }]
            }
        }
        nh = [next_hop_ip["nh2"][addr_type]]
        dut = "r2"
        protocol = "static"
        result = verify_rib(
            tgen,
            addr_type,
            dut,
            rte2_nh2,
            next_hop=nh,
            protocol=protocol,
            fib=True,
            expected=False,
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(
            tc_name)

        dut = "r3"
        protocol = "bgp"
        result = verify_bgp_rib(tgen, addr_type, dut, rte2_nh2, next_hop=nh)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(
            tc_name)

        result = verify_rib(
            tgen,
            addr_type,
            dut,
            rte2_nh2,
            next_hop=nh,
            protocol=protocol,
            fib=True,
            expected=False,
        )
        assert (
            result is not True
        ), "Testcase {} : Failed \nError: Routes is" "not active in RIB".format(
            tc_name)

    write_test_footer(tc_name)