예제 #1
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)
예제 #2
0
def test_verify_zebra_nh_resolution(request):
    tgen = get_topogen()
    tc_name = request.node.name
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)
    logger.info("Starting Zebra NH resolution testcase")
    r1 = tgen.gears["r1"]

    step("Configure static route")
    input_dict_1 = {
        "r1": {
            "static_routes": [{
                "network": "2.2.2.0/24",
                "next_hop": "r1-eth0"
            }]
        }
    }

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

    step("Verify static routes in RIB of R1")
    input_dict_2 = {"r1": {"static_routes": [{"network": "2.2.2.0/24"}]}}

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

    step("Set the connected flag on the NH tracking entry")
    r1.vtysh_cmd("sharp watch nexthop 2.2.2.32 connected")

    step("Verify that NH 2.2.2.32 gets resolved over static route")
    input_dict_nh = {
        "r1": {
            NH1: {
                "Address": "2.2.2.0/24",
                "resolvedVia": "static",
                "nexthops": {
                    "nexthop1": {
                        "Interfcae": "r1-eth0"
                    }
                },
            }
        }
    }
    result = verify_ip_nht(tgen, input_dict_nh)
    assert result is True, "Testcase {} : Failed \n"
    "Error: Nexthop is missing in RIB".format(tc_name, result)

    step("Add a .32/32 route with the NH as itself")
    r1.vtysh_cmd("sharp install routes 2.2.2.32 nexthop 2.2.2.32 1")

    step("Verify that the installation of .32/32 has no effect on the NHT")
    input_dict_nh = {
        "r1": {
            NH1: {
                "Address": "2.2.2.0/24",
                "resolvedVia": "static",
                "nexthops": {
                    "nexthop1": {
                        "Interface": "r1-eth0"
                    }
                },
            }
        }
    }
    result = verify_ip_nht(tgen, input_dict_nh)
    assert result is True, "Testcase {} : Failed \n"
    "Error: Nexthop became unresolved".format(tc_name, result)

    step("Add a .31/32 route with the NH as 2.2.2.32"
         "to verify the NH Resolution behaviour")
    r1.vtysh_cmd("sharp install routes 2.2.2.31 nexthop 2.2.2.32 1")

    step("Verify that NH 2.2.2.2/32 doesn't become unresolved")
    input_dict_nh = {
        "r1": {
            NH1: {
                "Address": "2.2.2.0/24",
                "resolvedVia": "static",
                "nexthops": {
                    "nexthop1": {
                        "Interface": "r1-eth0"
                    }
                },
            }
        }
    }
    result = verify_ip_nht(tgen, input_dict_nh)
    assert result is True, "Testcase {} : Failed \n"
    "Error: Nexthop became unresolved".format(tc_name, result)