コード例 #1
0
def test_pbr_flap():
    "Test PBR interface flapping"

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

    # Verify PBR Status
    logger.info("Flapping PBR Interfaces")

    router_list = tgen.routers().values()
    for router in router_list:
        # Flap interface to see if route-map properties are intact
        # Shutdown interface

        for i in range(5):
            intf = "r1-eth{}".format(i)

            # Down and back again
            shutdown_bringup_interface(tgen, router.name, intf, False)
            shutdown_bringup_interface(tgen, router.name, intf, True)

        intf_file = "{}/{}/pbr-interface.json".format(CWD, router.name)
        logger.info(intf_file)

        # Read expected result from file
        expected = json.loads(open(intf_file).read())

        # Actual output from router
        actual = router.vtysh_cmd("show pbr interface json", isjson=True)
        assertmsg = '"show pbr interface" mismatches on {}'.format(router.name)

        assert topotest.json_cmp(actual, expected) is None, assertmsg
コード例 #2
0
ファイル: test_pbr_topo1.py プロジェクト: zpericic/frr
def test_pbr_flap():
    "Test PBR interface flapping"

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

    # Verify PBR Status
    logger.info("Flapping PBR Interfaces")

    router_list = tgen.routers().values()
    for router in router_list:
        # Flap interface to see if route-map properties are intact
        # Shutdown interface

        for i in range(5):
            intf = "r1-eth{}".format(i)

            # Down and back again
            shutdown_bringup_interface(tgen, router.name, intf, False)
            shutdown_bringup_interface(tgen, router.name, intf, True)

        intf_file = "{}/{}/pbr-interface.json".format(CWD, router.name)
        logger.info(intf_file)

        # Read expected result from file
        expected = json.loads(open(intf_file).read())

        # Actual output from router
        test_func = partial(
            topotest.router_json_cmp, router, "show pbr interface json", expected
        )
        _, result = topotest.run_and_expect(test_func, None, count=30, wait=1)
        assertmsg = '"show pbr interface" mismatches on {}'.format(router.name)
        if result is not None:
            gather_pbr_data_on_error(router)
            assert result is None, assertmsg
コード例 #3
0
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)
コード例 #4
0
def test_same_rte_from_bgp_static_p0_tc5_ebgp(request):
    """
    Verify RIB status when same route advertise via BGP and static
    route

    """
    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 EBGP IPv4 peering between R2 and R3 router.")

    step("Configure IPv4 static route (10.1.1.1/24) in R2 with next hop"
         "N1 (28.1.1.2 ) and N2 (29.1.1.2) , Static route next-hop present"
         "on R1")

    for addr_type in ADDR_TYPES:
        input_dict_4 = {
            "r2": {
                "static_routes": [
                    {
                        "network": NETWORK[addr_type],
                        "next_hop": NEXT_HOP_IP["nh1"][addr_type],
                    },
                    {
                        "network": NETWORK[addr_type],
                        "next_hop": NEXT_HOP_IP["nh2"][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)

    step("Configure redistribute static in BGP.")
    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("Verify on R3 , route receive on R3 BGP table ")
        dut = "r3"
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
            tc_name)

        step("Verify route installed in the RIB and FIB of R3")
        protocol = "bgp"
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_4,
                            protocol=protocol)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
            tc_name)

    step("Configure 2 links/interfaces between R1 and R3 , keep one"
         "interface in shut (active) state and other interface in no shut"
         "(inactive) state")
    dut = "r3"
    intf = topo["routers"]["r3"]["links"]["r1-link0"]["interface"]
    shutdown_bringup_interface(tgen, dut, intf, False)

    step("Configure same static route (10.1.1.1/24) in R3 with inactive"
         "nexthop interface")

    step("Configure same static route 10.1.1.1/24) again in R3 with"
         "active nexthop interface")
    for addr_type in ADDR_TYPES:
        input_dict_4 = {
            "r3": {
                "static_routes": [
                    {
                        "network":
                        NETWORK[addr_type],
                        "next_hop":
                        topo["routers"]["r1"]["links"]["r3-link0"][addr_type],
                    },
                    {
                        "network":
                        NETWORK[addr_type],
                        "next_hop":
                        topo["routers"]["r1"]["links"]["r3-link1"][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)

        step("Verify when static route configure with inactive nexthop , "
             "verify BGP received route is active in the RIB and FIB")
        dut = "r3"
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Route is" " missing in BGP RIB".format(
            tc_name)

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

    step("Remove the static route on R3 configured with active" "interface")
    for addr_type in ADDR_TYPES:
        input_dict_4 = {
            "r3": {
                "static_routes": [
                    {
                        "network":
                        NETWORK[addr_type],
                        "next_hop":
                        topo["routers"]["r1"]["links"]["r3-link0"][addr_type],
                        "delete":
                        True,
                    },
                    {
                        "network":
                        NETWORK[addr_type],
                        "next_hop":
                        topo["routers"]["r1"]["links"]["r3-link1"][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)
        step("After removing the static route with active nexthop verify "
             "BGP received route is became active in RIB and FIB")
        dut = "r3"
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Route is" " missing in BGP RIB".format(
            tc_name)

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

    write_test_footer(tc_name)
コード例 #5
0
ファイル: test_ospf_lan.py プロジェクト: tih/frr
def test_ospf_lan_tc1_p0(request):
    """
    OSPF Hello protocol - Verify DR BDR Elections

    """
    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")
    reset_config_on_routers(tgen)
    step("Verify that DR BDR DRother are elected in the LAN.")
    input_dict = {
        "r0": {
            "ospf": {
                "neighbors": {
                    "r1": {
                        "state": "Full",
                        "role": "DR"
                    },
                    "r2": {
                        "state": "Full",
                        "role": "DROther"
                    },
                    "r3": {
                        "state": "Full",
                        "role": "DROther"
                    },
                }
            }
        }
    }
    dut = "r0"
    result = verify_ospf_neighbor(tgen, topo, dut, input_dict, lan=True)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Verify that all the routers are in FULL state with DR and BDR "
         "in the topology")

    input_dict = {
        "r1": {
            "ospf": {
                "neighbors": {
                    "r0": {
                        "state": "Full",
                        "role": "Backup"
                    },
                    "r2": {
                        "state": "Full",
                        "role": "DROther"
                    },
                    "r3": {
                        "state": "Full",
                        "role": "DROther"
                    },
                }
            }
        }
    }
    dut = "r1"
    result = verify_ospf_neighbor(tgen, topo, dut, input_dict, lan=True)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Configure DR pririty 100 on R0 and clear ospf neighbors "
         "on all the routers.")

    input_dict = {
        "r0": {
            "links": {
                "s1": {
                    "interface":
                    topo["routers"]["r0"]["links"]["s1"]["interface"],
                    "ospf": {
                        "priority": 100
                    },
                }
            }
        }
    }

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

    step("Clear ospf neighbours in all routers")
    for rtr in ["r0", "r1", "r2", "r3"]:
        clear_ospf(tgen, rtr)

    step("Verify that DR election is triggered and R0 is elected as DR")
    input_dict = {
        "r0": {
            "ospf": {
                "neighbors": {
                    "r1": {
                        "state": "Full",
                        "role": "Backup"
                    },
                    "r2": {
                        "state": "Full",
                        "role": "DROther"
                    },
                    "r3": {
                        "state": "Full",
                        "role": "DROther"
                    },
                }
            }
        }
    }
    dut = "r0"
    result = verify_ospf_neighbor(tgen, topo, dut, input_dict, lan=True)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Configure DR pririty 150 on R0 and clear ospf neighbors "
         "on all the routers.")

    input_dict = {
        "r0": {
            "links": {
                "s1": {
                    "interface":
                    topo["routers"]["r0"]["links"]["s1"]["interface"],
                    "ospf": {
                        "priority": 150
                    },
                }
            }
        }
    }

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

    step("Clear ospf neighbours in all routers")
    for rtr in ["r0", "r1"]:
        clear_ospf(tgen, rtr)

    step("Verify that DR election is triggered and R0 is elected as DR")
    input_dict = {
        "r0": {
            "ospf": {
                "neighbors": {
                    "r1": {
                        "state": "Full",
                        "role": "Backup"
                    },
                    "r2": {
                        "state": "Full",
                        "role": "DROther"
                    },
                    "r3": {
                        "state": "Full",
                        "role": "DROther"
                    },
                }
            }
        }
    }
    dut = "r0"
    result = verify_ospf_neighbor(tgen, topo, dut, input_dict, lan=True)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Configure DR priority 0 on R0 & Clear ospf nbrs on all the routers")

    input_dict = {
        "r0": {
            "links": {
                "s1": {
                    "interface":
                    topo["routers"]["r0"]["links"]["s1"]["interface"],
                    "ospf": {
                        "priority": 0
                    },
                }
            }
        }
    }

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

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

    step("Verify that DR election is triggered and R0 is elected as DRother")
    input_dict = {
        "r0": {
            "ospf": {
                "neighbors": {
                    "r1": {
                        "state": "Full",
                        "role": "DR"
                    },
                    "r2": {
                        "state": "2-Way",
                        "role": "DROther"
                    },
                    "r3": {
                        "state": "2-Way",
                        "role": "DROther"
                    },
                }
            }
        }
    }
    dut = "r0"
    result = verify_ospf_neighbor(tgen, topo, dut, input_dict, lan=True)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Configure DR priority to default on R0 and Clear ospf neighbors"
         " on all the routers")

    input_dict = {
        "r0": {
            "links": {
                "s1": {
                    "interface":
                    topo["routers"]["r0"]["links"]["s1"]["interface"],
                    "ospf": {
                        "priority": 100
                    },
                }
            }
        }
    }

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

    step("Clear ospf neighbours in all routers")
    for rtr in ["r0", "r1"]:
        clear_ospf(tgen, rtr)

    step("Verify that DR election is triggered and R0 is elected as DR")
    input_dict = {
        "r0": {
            "ospf": {
                "neighbors": {
                    "r1": {
                        "state": "Full",
                        "role": "Backup"
                    },
                    "r2": {
                        "state": "Full",
                        "role": "DROther"
                    },
                    "r3": {
                        "state": "Full",
                        "role": "DROther"
                    },
                }
            }
        }
    }
    dut = "r0"
    result = verify_ospf_neighbor(tgen, topo, dut, input_dict, lan=True)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Shut interface on R0")
    dut = "r0"
    intf = topo["routers"]["r0"]["links"]["s1"]["interface"]
    shutdown_bringup_interface(tgen, dut, intf, False)

    result = verify_ospf_neighbor(tgen, topo, dut, lan=True, expected=False)
    assert (
        result is not True
    ), "Testcase {} : Failed \n " "r0: OSPF neighbors-hip is up \n Error: {}".format(
        tc_name, result)

    step("No Shut interface on R0")
    dut = "r0"
    intf = topo["routers"]["r0"]["links"]["s1"]["interface"]
    shutdown_bringup_interface(tgen, dut, intf, True)

    input_dict = {
        "r0": {
            "ospf": {
                "neighbors": {
                    "r1": {
                        "state": "Full",
                        "role": "DR"
                    },
                    "r2": {
                        "state": "Full",
                        "role": "DROther"
                    },
                    "r3": {
                        "state": "Full",
                        "role": "DROther"
                    },
                }
            }
        }
    }
    step("Verify that after no shut ospf neighbours are full on R0.")
    result = verify_ospf_neighbor(tgen, topo, dut, input_dict, lan=True)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Clear ospf on DR router in the topology.")
    clear_ospf(tgen, "r0")

    step("Verify that BDR is getting promoted to DR after clear.")
    step("Verify that all the nbrs are in FULL state with the elected DR.")
    result = verify_ospf_neighbor(tgen, topo, dut, input_dict, lan=True)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Change the ip on LAN intf on R0 to other ip from the same subnet.")
    topo_modify_change_ip = deepcopy(topo)
    intf_ip = topo_modify_change_ip["routers"]["r0"]["links"]["s1"]["ipv4"]
    topo_modify_change_ip["routers"]["r0"]["links"]["s1"]["ipv4"] = str(
        IPv4Address(frr_unicode(intf_ip.split("/")[0])) + 3) + "/{}".format(
            intf_ip.split("/")[1])

    build_config_from_json(tgen, topo_modify_change_ip, save_bkup=False)

    step("Verify that OSPF is in FULL state with other routers with "
         "newly configured IP.")
    result = verify_ospf_neighbor(tgen, topo, dut, input_dict, lan=True)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Change the ospf router id on the R0 and clear ip ospf interface.")
    change_rid = {"r0": {"ospf": {"router_id": "100.1.1.100"}}}

    result = create_router_ospf(tgen, topo, change_rid)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)
    topo["routers"]["r0"]["ospf"]["router_id"] = "100.1.1.100"
    step("Reload the FRR router")

    stop_router(tgen, "r0")
    start_router(tgen, "r0")

    step("Verify that OSPF is in FULL state with other routers with"
         " newly configured router id.")
    input_dict = {
        "r1": {
            "ospf": {
                "neighbors": {
                    "r0": {
                        "state": "Full",
                        "role": "Backup"
                    },
                    "r2": {
                        "state": "Full",
                        "role": "DROther"
                    },
                    "r3": {
                        "state": "Full",
                        "role": "DROther"
                    },
                }
            }
        }
    }
    dut = "r1"
    result = verify_ospf_neighbor(tgen, topo, dut, input_dict, lan=True)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    step("Reconfigure the original router id and clear ip ospf interface.")
    change_rid = {"r0": {"ospf": {"router_id": "100.1.1.0"}}}
    result = create_router_ospf(tgen, topo, change_rid)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)
    topo["routers"]["r0"]["ospf"]["router_id"] = "100.1.1.0"
    step("Reload the FRR router")
    # stop/start -> restart FRR router and verify
    stop_router(tgen, "r0")
    start_router(tgen, "r0")

    step("Verify that OSPF is enabled with router id previously configured.")
    input_dict = {
        "r1": {
            "ospf": {
                "neighbors": {
                    "r0": {
                        "state": "Full",
                        "role": "Backup"
                    },
                    "r2": {
                        "state": "Full",
                        "role": "DROther"
                    },
                    "r3": {
                        "state": "Full",
                        "role": "DROther"
                    },
                }
            }
        }
    }
    dut = "r1"
    result = verify_ospf_neighbor(tgen, topo, dut, input_dict, lan=True)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    write_test_footer(tc_name)
コード例 #6
0
def test_static_route_2nh_p0_tc_1_ibgp(request):
    """
    Verify static route ECMP functionality with 2 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 IPv4 static route (10.1.1.1) in R2 with next hop N1"
         "(28.1.1.2 ) and N2 (29.1.1.2) , Static route next-hop present on"
         "R1")
    step("ex :- ip route 10.1.1.1/24 28.1.1.2 & ip route 10.1.1.1/24 29.1.1.1")
    for addr_type in ADDR_TYPES:
        input_dict_4 = {
            "r2": {
                "static_routes": [
                    {
                        "network": NETWORK[addr_type],
                        "next_hop": NEXT_HOP_IP["nh1"][addr_type],
                    },
                    {
                        "network": NETWORK[addr_type],
                        "next_hop": NEXT_HOP_IP["nh2"][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)

        step("On R2, static route installed in RIB using show ip route"
             " with 2 ECMP next hop ")
        nh = [NEXT_HOP_IP["nh1"][addr_type], NEXT_HOP_IP["nh2"][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 is" " missing in RIB".format(
            tc_name)

        step("Configure IBGP IPv4 peering between R2 and R3 router.")
        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"
        )
        input_dict_4 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK[addr_type],
                    "next_hop": NEXT_HOP_IP["nh1"][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)

        step("On R2, after removing the static route with N1 , "
             "route become active with nexthop N2 and vice versa.")
        nh = NEXT_HOP_IP["nh1"][addr_type]
        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 is" " still present in RIB".format(
            tc_name)

        nh = [NEXT_HOP_IP["nh2"][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 is" " missing in RIB".format(
            tc_name)

        step("Configure the static route with nexthop N1")

        input_dict_4 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK[addr_type],
                    "next_hop": NEXT_HOP_IP["nh1"][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)

        step(
            "Remove the static route configured with nexthop N2 from running config"
        )

        input_dict_4 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK[addr_type],
                    "next_hop": NEXT_HOP_IP["nh2"][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)

        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,
            input_dict_4,
            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,
                            input_dict_4,
                            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")
        input_dict_4 = {
            "r2": {
                "static_routes": [{
                    "network": NETWORK[addr_type],
                    "next_hop": NEXT_HOP_IP["nh2"][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)

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

        shutdown_bringup_interface(tgen, dut, intf, False)

        step("Only one the nexthops should be active in RIB.")

        nh = NEXT_HOP_IP["nh2"][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 is" " missing in RIB".format(
            tc_name)

        nh = NEXT_HOP_IP["nh1"][addr_type]
        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 is" " still present in RIB".format(
            tc_name)

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

        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: Route is" " still present in RIB".format(
            tc_name)

        dut = "r2"
        nh = [NEXT_HOP_IP["nh2"][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 is" " missing in RIB".format(
            tc_name)

        dut = "r3"
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Route is" " missing in RIB".format(
            tc_name)

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

        dut = "r2"
        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], NEXT_HOP_IP["nh2"][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 is" " missing in RIB".format(
            tc_name)

        step("Shut nexthop interface N2")
        intf = topo["routers"]["r2"]["links"]["r1-link1"]["interface"]
        dut = "r2"
        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,
            input_dict_4,
            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]]
        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 is" " missing in RIB".format(
            tc_name)

        dut = "r3"
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Route is" " missing in RIB".format(
            tc_name)

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

        step("No shut nexthop interface N2")
        dut = "r2"
        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], NEXT_HOP_IP["nh2"][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 is" " missing in RIB".format(
            tc_name)

        dut = "r3"
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Route is" " missing in RIB".format(
            tc_name)

        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_4,
                            protocol=protocol,
                            expected=False)
        assert (
            result is not True
        ), "Testcase {} : Failed \nError: Route is" " still present 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")

        dut = "r2"
        step("After reload of FRR router , static route installed"
             " in RIB and FIB properly .")
        result = verify_rib(tgen,
                            addr_type,
                            dut,
                            input_dict_4,
                            next_hop=nh,
                            protocol=protocol)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Routes is" " missing in RIB".format(
            tc_name)

        dut = "r3"
        result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
        assert (
            result is True
        ), "Testcase {} : Failed \nError: Route is" " still present in RIB".format(
            tc_name)

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

    write_test_footer(tc_name)
コード例 #7
0
def test_ospfv3_redistribution_tc6_p0(request):
    """Test OSPF inter area route calculations."""
    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():
        check_router_status(tgen)

    global topo
    step("Bring up the base config.")
    reset_config_on_routers(tgen)

    step("Verify that OSPF neighbors are FULL.")
    ospf_covergence = verify_ospf6_neighbor(tgen, topo)
    assert ospf_covergence is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, ospf_covergence)

    step("verify intra area route is calculated for r0-r3 interface ip in R1")
    ip = topo["routers"]["r0"]["links"]["r3"]["ipv6"]
    ip_net = str(ipaddress.ip_interface(u"{}".format(ip)).network)
    llip = get_llip("r0", "r1")
    assert llip is not None, "Testcase {} : Failed \n Error: {}".format(
        tc_name, llip)
    nh = llip
    input_dict = {
        "r1": {
            "static_routes": [{
                "network": ip_net,
                "no_of_ip": 1,
                "routeType": "Network"
            }]
        }
    }

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

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

    step("Delete the ip address on newly configured loopback of R0")
    topo1 = {
        "r0": {
            "links": {
                "r3": {
                    "ipv6": topo["routers"]["r0"]["links"]["r3"]["ipv6"],
                    "interface":
                    topo["routers"]["r0"]["links"]["r3"]["interface"],
                    "delete": True,
                }
            }
        }
    }

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

    dut = "r1"
    result = verify_ospf6_rib(tgen,
                              dut,
                              input_dict,
                              next_hop=nh,
                              expected=False)
    assert (
        result is not True
    ), "Testcase {} : Failed \n Route present in RIB. Error: {}".format(
        tc_name, result)

    protocol = "ospf"
    result = verify_rib(tgen,
                        "ipv6",
                        dut,
                        input_dict,
                        protocol=protocol,
                        next_hop=nh,
                        expected=False)
    assert (
        result is not True
    ), "Testcase {} : Failed \n Route present in RIB. Error: {}".format(
        tc_name, result)

    step("Add back the deleted ip address on newly configured interface of R0")
    topo1 = {
        "r0": {
            "links": {
                "r3": {
                    "ipv6": topo["routers"]["r0"]["links"]["r3"]["ipv6"],
                    "interface":
                    topo["routers"]["r0"]["links"]["r3"]["interface"],
                }
            }
        }
    }

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

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

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

    step("Shut no shut interface on R0")
    dut = "r0"
    intf = topo["routers"]["r0"]["links"]["r3"]["interface"]
    shutdown_bringup_interface(tgen, dut, intf, False)

    step("un shut the OSPF interface on R0")
    dut = "r0"
    shutdown_bringup_interface(tgen, dut, intf, True)

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

    protocol = "ospf"
    result = verify_rib(tgen,
                        "ipv6",
                        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)
コード例 #8
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)
コード例 #9
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)
コード例 #10
0
def test_ospf_authentication_md5_tc29_p1(request):
    """
    OSPF Authentication - Verify ospf authentication with MD5 authentication.

    """
    tc_name = request.node.name
    write_test_header(tc_name)
    tgen = get_topogen()
    global topo
    step("Bring up the base config.")
    reset_config_on_routers(tgen)
    step("Configure ospf with on R1 and R2, enable ospf on R1 interface "
         "connected to R2 with message-digest authentication using  ip "
         "ospf authentication  message-digest cmd.")

    r1_ospf_auth = {
        "r1": {
            "links": {
                "r2": {
                    "ospf": {
                        "authentication": "message-digest",
                        "authentication-key": "ospf",
                        "message-digest-key": "10",
                    }
                }
            }
        }
    }
    result = config_ospf_interface(tgen, topo, r1_ospf_auth)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, result)

    step("Verify that the neighbour is not FULL between R1 and R2.")
    # wait for dead time expiry.
    sleep(6)
    dut = "r1"
    ospf_covergence = verify_ospf_neighbor(tgen,
                                           topo,
                                           dut=dut,
                                           expected=False,
                                           attempts=3)
    assert ospf_covergence is not True, "setup_module :Failed \n Error:" " {}".format(
        ospf_covergence)

    step("On R2 enable ospf on interface with message-digest authentication"
         "  using  ip ospf authentication  message-digest password cmd.")

    r2_ospf_auth = {
        "r2": {
            "links": {
                "r1": {
                    "ospf": {
                        "authentication": "message-digest",
                        "authentication-key": "ospf",
                        "message-digest-key": "10",
                    }
                }
            }
        }
    }
    result = config_ospf_interface(tgen, topo, r2_ospf_auth)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, result)

    step("Verify that the neighbour is FULL between R1 and R2  "
         "using show ip ospf neighbor cmd.")

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

    step("Disable message-digest authentication on R2  using no ip ospf "
         "authentication  message-digest password cmd.")

    r2_ospf_auth = {
        "r2": {
            "links": {
                "r1": {
                    "ospf": {
                        "authentication": "message-digest",
                        "authentication-key": "ospf",
                        "message-digest-key": "10",
                        "del_action": True,
                    }
                }
            }
        }
    }
    result = config_ospf_interface(tgen, topo, r2_ospf_auth)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, result)

    step("Verify on R1 ,nbr is deleted for R2 after dead interval expiry")
    #  wait till the dead timer expiry
    sleep(6)
    dut = "r2"
    ospf_covergence = verify_ospf_neighbor(tgen,
                                           topo,
                                           dut=dut,
                                           expected=False,
                                           attempts=5)
    assert ospf_covergence is not True, "setup_module :Failed \n Error:" " {}".format(
        ospf_covergence)

    step("Again On R2 enable ospf on interface with  message-digest auth")
    r2_ospf_auth = {
        "r2": {
            "links": {
                "r1": {
                    "ospf": {
                        "authentication": "message-digest",
                        "authentication-key": "ospf",
                        "message-digest-key": "10",
                    }
                }
            }
        }
    }
    result = config_ospf_interface(tgen, topo, r2_ospf_auth)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, result)

    step("Verify that the neighbour is FULL between R1 and R2 using"
         " show ip ospf neighbor cmd.")

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

    step("Shut no shut interface on R1")
    dut = "r1"
    intf = topo["routers"]["r1"]["links"]["r2"]["interface"]
    shutdown_bringup_interface(tgen, dut, intf, False)

    dut = "r2"
    step("Verify that the neighbour is not FULL between R1 and R2 using "
         "show ip ospf neighbor cmd.")
    ospf_covergence = verify_ospf_neighbor(tgen, topo, dut=dut, expected=False)
    assert ospf_covergence is not True, "setup_module :Failed \n Error:" " {}".format(
        ospf_covergence)

    dut = "r1"
    shutdown_bringup_interface(tgen, dut, intf, True)

    step("Verify that the neighbour is FULL between R1 and R2 using "
         "show ip ospf neighbor cmd.")

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

    step("Change Ip address on R1 and R2")

    topo_modify_change_ip = deepcopy(topo)

    intf_ip = topo_modify_change_ip["routers"]["r1"]["links"]["r2"]["ipv4"]

    topo_modify_change_ip["routers"]["r1"]["links"]["r2"]["ipv4"] = str(
        IPv4Address(unicode(intf_ip.split("/")[0])) + 3) + "/{}".format(
            intf_ip.split("/")[1])

    build_config_from_json(tgen, topo_modify_change_ip, save_bkup=False)

    reset_config_on_routers(tgen, routerName="r1")
    dut = "r1"
    intf = topo["routers"]["r1"]["links"]["r2"]["interface"]
    shutdown_bringup_interface(tgen, dut, intf, False)
    shutdown_bringup_interface(tgen, dut, intf, True)
    clear_ospf(tgen, "r1")
    r1_ospf_auth = {
        "r1": {
            "links": {
                "r2": {
                    "ospf": {
                        "authentication": "message-digest",
                        "authentication-key": "ospf",
                        "message-digest-key": "10",
                    }
                }
            }
        }
    }
    result = config_ospf_interface(tgen, topo, r1_ospf_auth)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, result)

    step("Verify that the neighbour is FULL between R1 and R2 with new "
         "ip address using show ip ospf ")

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

    write_test_footer(tc_name)
コード例 #11
0
def test_pimv6_add_delete_static_RP_p0(request):
    """
    TC_1: Verify upstream interfaces(IIF) and join state are updated
        properly after adding and deleting the static RP
    TC_2: Verify IIF and OIL in "show ip pim state" updated properly
        after adding and deleting the static RP
    TC_3: (*, G) Mroute entry are cleared when static RP gets deleted
    TC_4: Verify (*,G) prune is send towards the RP after deleting the
        static RP

    TOPOlogy used:
         r0------r1-----r2
       iperf    DUT     RP
    """

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

    # Don"t run this test if we have any failure.
    if tgen.routers_have_failure():
        check_router_status(tgen)

    step("Shut link b/w R1 and R3 and R1 and R4 as per tescase topology")
    intf_r1_r3 = TOPO["routers"]["r1"]["links"]["r3"]["interface"]
    intf_r1_r4 = TOPO["routers"]["r1"]["links"]["r4"]["interface"]
    for intf in [intf_r1_r3, intf_r1_r4]:
        shutdown_bringup_interface(tgen, "r1", intf, ifaceaction=False)

    step("Enable PIM between r1 and r2")
    step("Enable MLD on r1 interface and send IGMP " "join (FF08::1) to r1")
    step("Configure r2 loopback interface as RP")
    input_dict = {
        "r2": {
            "pim6": {
                "rp": [{
                    "rp_addr":
                    TOPO["routers"]["r2"]["links"]["lo"]["ipv6"].split("/")[0],
                    "group_addr_range":
                    GROUP_RANGE_V6,
                }]
            }
        }
    }

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

    step("Verify show ip pim interface traffic without any mld join")
    state_dict = {
        "r1": {
            TOPO["routers"]["r1"]["links"]["r2"]["interface"]: ["pruneTx"]
        }
    }

    state_before = verify_pim_interface_traffic(tgen,
                                                state_dict,
                                                addr_type="ipv6")
    assert isinstance(
        state_before, dict
    ), "Testcase{} : Failed \n state_before is not dictionary \n " "Error: {}".format(
        tc_name, result)

    step("send mld join (FF08::1) to R1")
    intf = TOPO["routers"]["r0"]["links"]["r1"]["interface"]
    intf_ip = TOPO["routers"]["r0"]["links"]["r1"]["ipv6"].split("/")[0]
    result = socat_send_igmp_join_traffic(tgen,
                                          "r0",
                                          "UDP6-RECV",
                                          IGMP_JOIN_V6,
                                          intf,
                                          intf_ip,
                                          join=True)
    assert result is True, "Testcase {}: Failed Error: {}".format(
        tc_name, result)

    step("r1: Verify RP info")
    dut = "r1"
    oif = TOPO["routers"]["r1"]["links"]["r2"]["interface"]
    iif = TOPO["routers"]["r1"]["links"]["r0"]["interface"]
    rp_address = TOPO["routers"]["r2"]["links"]["lo"]["ipv6"].split("/")[0]
    result = verify_pim_rp_info(tgen, TOPO, dut, GROUP_RANGE_V6, oif,
                                rp_address, SOURCE)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, result)

    step("r1: Verify upstream IIF interface")
    result = verify_upstream_iif(tgen, dut, oif, STAR, IGMP_JOIN_V6)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, result)

    step("r1: Verify upstream join state and join timer")
    result = verify_join_state_and_timer(tgen, dut, oif, STAR, IGMP_JOIN_V6)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, result)

    step("r1: Verify PIM state")
    result = verify_pim_state(tgen, dut, oif, iif, IGMP_JOIN_V6)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, result)

    step("r1: Verify ip mroutes")
    result = verify_mroutes(tgen, dut, STAR, IGMP_JOIN_V6, oif, iif)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, result)

    step("r1: Delete RP configuration")
    input_dict = {
        "r2": {
            "pim6": {
                "rp": [{
                    "rp_addr":
                    TOPO["routers"]["r2"]["links"]["lo"]["ipv6"].split("/")[0],
                    "group_addr_range":
                    GROUP_RANGE_V6,
                    "delete":
                    True,
                }]
            }
        }
    }

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

    step("r1: Verify RP info")
    result = verify_pim_rp_info(tgen,
                                TOPO,
                                dut,
                                GROUP_RANGE_V6,
                                oif,
                                rp_address,
                                SOURCE,
                                expected=False)
    assert (
        result is not True
    ), "Testcase {} :Failed \n " "RP: {} info is still present \n Error: {}".format(
        tc_name, rp_address, result)

    step("r1: Verify upstream IIF interface")
    result = verify_upstream_iif(tgen,
                                 dut,
                                 oif,
                                 STAR,
                                 IGMP_JOIN_V6,
                                 expected=False)
    assert result is not True, (
        "Testcase {} :Failed \n "
        "Upstream ({}, {}) is still in join state \n Error: {}".format(
            tc_name, STAR, IGMP_JOIN_V6, result))

    step("r1: Verify upstream join state and join timer")
    result = verify_join_state_and_timer(tgen,
                                         dut,
                                         oif,
                                         STAR,
                                         IGMP_JOIN_V6,
                                         expected=False)
    assert result is not True, (
        "Testcase {} :Failed \n "
        "Upstream ({}, {}) timer is still running \n Error: {}".format(
            tc_name, STAR, IGMP_JOIN_V6, result))

    step("r1: Verify PIM state")
    result = verify_pim_state(tgen,
                              dut,
                              oif,
                              iif,
                              IGMP_JOIN_V6,
                              expected=False)
    assert result is not True, (
        "Testcase {} :Failed \n "
        "PIM state for group: {} is still Active \n Error: {}".format(
            tc_name, IGMP_JOIN_V6, result))

    step("r1: Verify ip mroutes")
    result = verify_mroutes(tgen,
                            dut,
                            STAR,
                            IGMP_JOIN_V6,
                            oif,
                            iif,
                            expected=False)
    assert result is not True, (
        "Testcase {} :Failed \n "
        "mroute ({}, {}) is still present \n Error: {}".format(
            tc_name, STAR, IGMP_JOIN_V6, result))

    step("r1: Verify show ip pim interface traffic without any IGMP join")
    state_after = verify_pim_interface_traffic(tgen,
                                               state_dict,
                                               addr_type="ipv6")
    assert isinstance(
        state_after, dict
    ), "Testcase{} : Failed \n state_before is not dictionary \n " "Error: {}".format(
        tc_name, result)

    result = verify_state_incremented(state_before, state_after)
    assert result is True, "Testcase{} : Failed Error: {}".format(
        tc_name, result)

    write_test_footer(tc_name)
コード例 #12
0
def test_RP_configured_as_LHR_1_p1(request):
    """
    TC_21_1_P1: Verify OIF and RPF for (*,G) and (S,G) when static RP configure
             in LHR router

    Topology used:
                ________r2_____
                |             |
      iperf     |             |     iperf
        r0-----r1-------------r3-----r5

    r1 : LHR/RP
    r3 : FHR
    """

    tgen = get_topogen()
    tc_name = request.node.name
    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("Creating configuration from JSON")
    reset_config_on_routers(tgen)
    app_helper.stop_all_hosts()
    clear_mroute(tgen)
    clear_pim_interface_traffic(tgen, TOPO)

    step("Enable IGMP on r1 interface")
    step("Configure RP on r1 (loopback interface) for the group range"
         " 224.0.0.0/4")
    step("Enable the PIM on all the interfaces of r1, r2, r3 and r4 routers")
    step("Send the IGMP join from r0")
    step("Send multicast traffic from r5")

    step("r1 , r2, r3, r4: Delete existing RP configuration"
         "configure r1(LHR) as RP")
    input_dict = {
        "r1": {
            "pim": {
                "rp": [{
                    "rp_addr": "1.0.2.17",
                    "group_addr_range": GROUP_RANGE_ALL,
                    "delete": True,
                }]
            }
        },
        "r2": {
            "pim": {
                "rp": [{
                    "rp_addr": "1.0.2.17",
                    "group_addr_range": GROUP_RANGE_ALL,
                    "delete": True,
                }]
            }
        },
        "r3": {
            "pim": {
                "rp": [{
                    "rp_addr": "1.0.2.17",
                    "group_addr_range": GROUP_RANGE_ALL,
                    "delete": True,
                }]
            }
        },
        "r4": {
            "pim": {
                "rp": [{
                    "rp_addr": "1.0.2.17",
                    "group_addr_range": GROUP_RANGE_ALL,
                    "delete": True,
                }]
            }
        },
    }

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

    step("r1: Configure r1(LHR) as RP")
    input_dict = {
        "r1": {
            "pim": {
                "rp": [{
                    "rp_addr": "1.0.1.17",
                    "group_addr_range": GROUP_RANGE_ALL,
                }]
            }
        },
        "r2": {
            "pim": {
                "rp": [{
                    "rp_addr": "1.0.1.17",
                    "group_addr_range": GROUP_RANGE_ALL,
                }]
            }
        },
        "r3": {
            "pim": {
                "rp": [{
                    "rp_addr": "1.0.1.17",
                    "group_addr_range": GROUP_RANGE_ALL,
                }]
            }
        },
        "r4": {
            "pim": {
                "rp": [{
                    "rp_addr": "1.0.1.17",
                    "group_addr_range": GROUP_RANGE_ALL,
                }]
            }
        },
    }

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

    shutdown_bringup_interface(tgen, "r1", "lo", False)
    sleep(5)
    shutdown_bringup_interface(tgen, "r1", "lo", True)
    sleep(5)

    step("r1: Verify RP info")
    dut = "r1"
    rp_address = "1.0.1.17"
    iif = "lo"
    result = verify_pim_rp_info(tgen, TOPO, dut, GROUP_RANGE_ALL, iif,
                                rp_address, SOURCE)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, result)

    step("r0: Send IGMP join")
    result = app_helper.run_join("r0", GROUP_ADDRESS, "r1")
    assert result is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, result)

    step("r1: Verify IGMP groups")
    oif = "r1-r0-eth0"
    result = verify_igmp_groups(tgen, dut, oif, GROUP_ADDRESS)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, result)

    step("r5: Send multicast traffic for group 225.1.1.1")
    result = app_helper.run_traffic("r5", GROUP_ADDRESS, "r3")
    assert result is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, result)

    step("r1: Verify (*, G) upstream IIF interface")
    result = verify_upstream_iif(tgen, dut, iif, STAR, GROUP_ADDRESS)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, result)

    step("r1: Verify (*, G) upstream join state and join timer")
    result = verify_join_state_and_timer(tgen, dut, iif, STAR, GROUP_ADDRESS)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, result)

    step("r1: Verify (*, G) ip mroutes")
    result = verify_mroutes(tgen, dut, STAR, GROUP_ADDRESS, iif, oif)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, result)

    step("r1: Verify (S, G) upstream IIF interface")
    iif = "r1-r3-eth2"
    result = verify_upstream_iif(tgen, dut, iif, SOURCE_ADDRESS, GROUP_ADDRESS)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, result)

    step("r1: Verify (S, G) upstream join state and join timer")
    result = verify_join_state_and_timer(tgen, dut, iif, SOURCE_ADDRESS,
                                         GROUP_ADDRESS)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, result)

    step("r1: Verify (S, G) ip mroutes")
    result = verify_mroutes(tgen, dut, SOURCE_ADDRESS, GROUP_ADDRESS, iif, oif)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, result)

    step("r3: Verify (S, G) upstream IIF interface")
    dut = "r3"
    iif = "r3-r5-eth3"
    result = verify_upstream_iif(tgen, dut, iif, SOURCE_ADDRESS, GROUP_ADDRESS)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, result)

    step("r3: Verify (S, G) upstream join state and join timer")
    result = verify_join_state_and_timer(tgen,
                                         dut,
                                         iif,
                                         SOURCE_ADDRESS,
                                         GROUP_ADDRESS,
                                         expected=False)
    assert result is not True, (
        "Testcase {} : Failed \n "
        "r3: (S, G) upstream join state is joined and join"
        " timer is running \n Error: {}".format(tc_name, result))

    step("r3: Verify (S, G) ip mroutes")
    oif = "r3-r1-eth0"
    result = verify_mroutes(tgen, dut, SOURCE_ADDRESS, GROUP_ADDRESS, iif, oif)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, result)

    # Uncomment next line for debugging
    # tgen.mininet_cli()

    write_test_footer(tc_name)
コード例 #13
0
def test_ospf6_auth_trailer_tc4_keychain_sha256(request):
    """
    OSPFv3 Authentication Trailer - Verify ospfv3 authentication trailer
    using HMAC-SHA-256 keychain configuration.

    """
    tc_name = request.node.name
    write_test_header(tc_name)
    tgen = get_topogen()
    global topo
    step("Bring up the base config.")
    reset_config_on_routers(tgen)
    step(
        "Configure ospf6 between R1 and R2, enable ospf6 auth on R1 interface "
        "connected to R2 with auth trailer")

    router1 = tgen.gears["r1"]
    router2 = tgen.gears["r2"]

    router1.vtysh_cmd("""configure terminal
           key chain auth
             key 10
               key-string ospf6
               cryptographic-algorithm hmac-sha-256""")

    router2.vtysh_cmd("""configure terminal
           key chain auth
             key 10
               key-string ospf6
               cryptographic-algorithm hmac-sha-256""")

    r1_ospf6_auth = {
        "r1": {
            "links": {
                "r2": {
                    "ospf6": {
                        "keychain": "auth",
                    }
                }
            }
        }
    }
    result = config_ospf6_interface(tgen, topo, r1_ospf6_auth)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, result)

    step("Verify that the neighbour is not FULL between R1 and R2.")
    # wait for dead time expiry.
    sleep(6)
    dut = "r1"
    ospf6_covergence = verify_ospf6_neighbor(tgen,
                                             topo,
                                             dut=dut,
                                             expected=False,
                                             retry_timeout=3)
    assert ospf6_covergence is not True, "Testcase {} :Failed \n Error:" " {}".format(
        tc_name, ospf6_covergence)

    step("Configure ospf6 between R1 and R2, enable ospf6 on R2 interface "
         "connected to R1 with auth trailer")

    r2_ospf6_auth = {
        "r2": {
            "links": {
                "r1": {
                    "ospf6": {
                        "keychain": "auth",
                    }
                }
            }
        }
    }
    result = config_ospf6_interface(tgen, topo, r2_ospf6_auth)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, result)

    step("Verify that the neighbour is FULL between R1 and R2  "
         "using show ipv6 ospf6 neighbor cmd.")

    dut = "r2"
    ospf6_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut)
    assert ospf6_covergence is True, "Testcase {} :Failed \n Error:" " {}".format(
        tc_name, ospf6_covergence)

    step("Disable authentication on R2 ")

    r2_ospf6_auth = {
        "r2": {
            "links": {
                "r1": {
                    "ospf6": {
                        "keychain": "auth",
                        "del_action": True
                    }
                }
            }
        }
    }
    result = config_ospf6_interface(tgen, topo, r2_ospf6_auth)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, result)

    step("Verify on R1 ,nbr is deleted for R2 after dead interval expiry")
    #  wait till the dead timer expiry
    sleep(6)
    dut = "r2"
    ospf6_covergence = verify_ospf6_neighbor(tgen,
                                             topo,
                                             dut=dut,
                                             expected=False,
                                             retry_timeout=5)
    assert ospf6_covergence is not True, "Testcase {} :Failed \n Error:" " {}".format(
        tc_name, ospf6_covergence)

    step("Again On R2 enable ospf6 on interface with  message-digest auth")
    r2_ospf6_auth = {
        "r2": {
            "links": {
                "r1": {
                    "ospf6": {
                        "keychain": "auth",
                    }
                }
            }
        }
    }
    result = config_ospf6_interface(tgen, topo, r2_ospf6_auth)
    assert result is True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, result)

    step("Verify that the neighbour is FULL between R1 and R2 using"
         " show ip ospf6 neighbor cmd.")

    dut = "r2"
    ospf6_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut)
    assert ospf6_covergence is True, "Testcase {} :Failed \n Error:" " {}".format(
        tc_name, ospf6_covergence)

    step("Shut no shut interface on R1")
    dut = "r1"
    intf = topo["routers"]["r1"]["links"]["r2"]["interface"]
    shutdown_bringup_interface(tgen, dut, intf, False)

    dut = "r2"
    step("Verify that the neighbour is not FULL between R1 and R2 using "
         "show ip ospf6 neighbor cmd.")
    ospf6_covergence = verify_ospf6_neighbor(tgen,
                                             topo,
                                             dut=dut,
                                             expected=False)
    assert ospf6_covergence is not True, "Testcase {} :Failed \n Error:" " {}".format(
        tc_name, ospf6_covergence)

    dut = "r1"
    shutdown_bringup_interface(tgen, dut, intf, True)

    step("Verify that the neighbour is FULL between R1 and R2 using "
         "show ip ospf6 neighbor cmd.")

    dut = "r2"
    ospf6_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut)
    assert ospf6_covergence is True, "Testcase {} :Failed \n Error:" " {}".format(
        tc_name, ospf6_covergence)

    write_test_footer(tc_name)
コード例 #14
0
def test_ecmp_fast_convergence(request, test_type, tgen, topo):
    """This test is to verify bgp fast-convergence cli functionality"""

    tc_name = request.node.name
    write_test_header(tc_name)

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

    reset_config_on_routers(tgen)
    static_or_nw(tgen, topo, tc_name, test_type, "r2")

    for addr_type in ADDR_TYPES:
        input_dict = {
            "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,
            protocol=protocol,
        )
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    intf1 = topo["routers"]["r2"]["links"]["r3-link1"]["interface"]
    intf2 = topo["routers"]["r2"]["links"]["r3-link2"]["interface"]

    logger.info("Shutdown one of the link b/w r2 and r3")
    shutdown_bringup_interface(tgen, "r2", intf1, False)

    logger.info("Verify bgp neighbors are still up")
    result = verify_bgp_convergence(tgen, topo)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    logger.info("Shutdown another link b/w r2 and r3")
    shutdown_bringup_interface(tgen, "r2", intf2, False)

    logger.info("Wait for 10 sec and make sure bgp neighbors are still up")
    sleep(10)
    result = verify_bgp_convergence(tgen, topo)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    logger.info("No shut links b/w r2 and r3")
    shutdown_bringup_interface(tgen, "r2", intf1, True)
    shutdown_bringup_interface(tgen, "r2", intf2, True)

    logger.info("Ensure that the links are still up")
    result = verify_bgp_convergence(tgen, topo)

    logger.info("Enable bgp fast-convergence cli")
    raw_config = {
        "r2": {
            "raw_config": [
                "router bgp {}".format(
                    topo["routers"]["r2"]["bgp"]["local_as"]),
                "bgp fast-convergence",
            ]
        }
    }
    result = apply_raw_config(tgen, raw_config)
    assert result is True, "Testcase {} : Failed Error: {}".format(
        tc_name, result)

    logger.info("Ensure BGP has processed the cli")
    r2 = tgen.gears["r2"]
    output = r2.vtysh_cmd("show run")
    verify = re.search(r"fast-convergence", output)
    assert verify is not None, (
        "r2 does not have the fast convergence command yet")

    logger.info("Shutdown one link b/w r2 and r3")
    shutdown_bringup_interface(tgen, "r2", intf1, False)

    logger.info("Verify bgp neighbors goes down immediately")
    result = verify_bgp_convergence(tgen, topo, dut="r2", expected=False)
    assert result is not True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    logger.info("Shutdown second link b/w r2 and r3")
    shutdown_bringup_interface(tgen, "r2", intf2, False)

    logger.info("Verify bgp neighbors goes down immediately")
    result = verify_bgp_convergence(tgen, topo, dut="r2", expected=False)
    assert result is not True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    write_test_footer(tc_name)
コード例 #15
0
def test_bgp_best_path_with_dynamic_import_p0(request):
    """
    TC6_FUNC_6:
    1.5.6. Verify BGP best path selection algorithm works fine when
    routes are imported from ISR to default vrf and vice versa.
    """

    tgen = get_topogen()
    tc_name = request.node.name
    write_test_header(tc_name)
    build_config_from_json(tgen, topo)

    if tgen.routers_have_failure():
        check_router_status(tgen)

    for addr_type in ADDR_TYPES:

        step("Redistribute configured static routes into BGP process"
             " on R1/R2 and R3")

        input_dict_1 = {}
        DUT = ["r1", "r2", "r3", "r4"]
        VRFS = ["ISR", "ISR", "default", "default"]
        AS_NUM = [100, 100, 300, 400]

        for dut, vrf, as_num in zip(DUT, VRFS, AS_NUM):
            temp = {dut: {"bgp": []}}
            input_dict_1.update(temp)

            temp[dut]["bgp"].append({
                "local_as": as_num,
                "vrf": vrf,
                "address_family": {
                    addr_type: {
                        "unicast": {
                            "redistribute": [{
                                "redist_type": "static"
                            }]
                        }
                    }
                },
            })

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

    for addr_type in ADDR_TYPES:

        step("Import from default vrf into vrf ISR on R1 and R2 as below")

        input_dict_vrf = {}
        DUT = ["r1", "r2"]
        VRFS = ["ISR", "ISR"]
        AS_NUM = [100, 100]

        for dut, vrf, as_num in zip(DUT, VRFS, AS_NUM):
            temp = {dut: {"bgp": []}}
            input_dict_vrf.update(temp)

            temp[dut]["bgp"].append({
                "local_as": as_num,
                "vrf": vrf,
                "address_family": {
                    addr_type: {
                        "unicast": {
                            "import": {
                                "vrf": "default"
                            }
                        }
                    }
                },
            })

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

        input_dict_default = {}
        DUT = ["r1", "r2"]
        VRFS = ["default", "default"]
        AS_NUM = [100, 100]

        for dut, vrf, as_num in zip(DUT, VRFS, AS_NUM):
            temp = {dut: {"bgp": []}}
            input_dict_default.update(temp)

            temp[dut]["bgp"].append({
                "local_as": as_num,
                "vrf": vrf,
                "address_family": {
                    addr_type: {
                        "unicast": {
                            "import": {
                                "vrf": "ISR"
                            }
                        }
                    }
                },
            })

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

    step("Verify ECMP/Next-hop/Imported routes Vs Locally originated "
         "routes/eBGP routes vs iBGP routes --already covered in almost"
         " all tests")

    for addr_type in ADDR_TYPES:

        step("Verify Pre-emption")

        input_routes_r3 = {
            "r3": {
                "static_routes": [{
                    "network": [NETWORK3_3[addr_type]]
                }]
            }
        }

        intf_r3_r1 = topo["routers"]["r3"]["links"]["r1-link1"]["interface"]
        intf_r4_r1 = topo["routers"]["r4"]["links"]["r1-link1"]["interface"]

        if addr_type == "ipv6" and "link_local" in PREFERRED_NEXT_HOP:
            nh_r3_r1 = get_frr_ipv6_linklocal(tgen, "r3", intf=intf_r3_r1)
            nh_r4_r1 = get_frr_ipv6_linklocal(tgen, "r4", intf=intf_r4_r1)
        else:
            nh_r3_r1 = topo["routers"]["r3"]["links"]["r1-link1"][
                addr_type].split("/")[0]
            nh_r4_r1 = topo["routers"]["r4"]["links"]["r1-link1"][
                addr_type].split("/")[0]

        result = verify_bgp_rib(tgen,
                                addr_type,
                                "r1",
                                input_routes_r3,
                                next_hop=[nh_r4_r1])
        assert result is True, "Testcase {} : Failed \n Error {}".format(
            tc_name, result)

    step("Shutdown interface connected to r1 from r4:")
    shutdown_bringup_interface(tgen, "r4", intf_r4_r1, False)

    for addr_type in ADDR_TYPES:

        input_routes_r3 = {
            "r3": {
                "static_routes": [{
                    "network": [NETWORK3_3[addr_type]]
                }]
            }
        }

        intf_r3_r1 = topo["routers"]["r3"]["links"]["r1-link1"]["interface"]
        intf_r4_r1 = topo["routers"]["r4"]["links"]["r1-link1"]["interface"]

        if addr_type == "ipv6" and "link_local" in PREFERRED_NEXT_HOP:
            nh_r3_r1 = get_frr_ipv6_linklocal(tgen, "r3", intf=intf_r3_r1)
            nh_r4_r1 = get_frr_ipv6_linklocal(tgen, "r4", intf=intf_r4_r1)
        else:
            nh_r3_r1 = topo["routers"]["r3"]["links"]["r1-link1"][
                addr_type].split("/")[0]
            nh_r4_r1 = topo["routers"]["r4"]["links"]["r1-link1"][
                addr_type].split("/")[0]

        step("Verify next-hop is changed")
        result = verify_bgp_rib(tgen,
                                addr_type,
                                "r1",
                                input_routes_r3,
                                next_hop=[nh_r3_r1])
        assert result is True, "Testcase {} : Failed \n Error {}".format(
            tc_name, result)

    step("Bringup interface connected to r1 from r4:")
    shutdown_bringup_interface(tgen, "r4", intf_r4_r1, True)

    for addr_type in ADDR_TYPES:

        input_routes_r3 = {
            "r3": {
                "static_routes": [{
                    "network": [NETWORK3_3[addr_type]]
                }]
            }
        }

        intf_r3_r1 = topo["routers"]["r3"]["links"]["r1-link1"]["interface"]
        intf_r4_r1 = topo["routers"]["r4"]["links"]["r1-link1"]["interface"]

        if addr_type == "ipv6" and "link_local" in PREFERRED_NEXT_HOP:
            nh_r3_r1 = get_frr_ipv6_linklocal(tgen, "r3", intf=intf_r3_r1)
            nh_r4_r1 = get_frr_ipv6_linklocal(tgen, "r4", intf=intf_r4_r1)
        else:
            nh_r3_r1 = topo["routers"]["r3"]["links"]["r1-link1"][
                addr_type].split("/")[0]
            nh_r4_r1 = topo["routers"]["r4"]["links"]["r1-link1"][
                addr_type].split("/")[0]

        step("Verify next-hop is not chnaged aftr shutdown:")
        result = verify_bgp_rib(tgen,
                                addr_type,
                                "r1",
                                input_routes_r3,
                                next_hop=[nh_r3_r1])
        assert result is True, "Testcase {} : Failed \n Error {}".format(
            tc_name, result)

    step("Active-Standby scenario(as-path prepend and Local pref)")

    for addr_type in ADDR_TYPES:

        step("Create prefix-list")

        input_dict_pf = {
            "r1": {
                "prefix_lists": {
                    addr_type: {
                        "pf_ls_{}".format(addr_type): [{
                            "seqid":
                            10,
                            "network":
                            NETWORK3_4[addr_type],
                            "action":
                            "permit",
                        }]
                    }
                }
            }
        }
        result = create_prefix_lists(tgen, input_dict_pf)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    for addr_type in ADDR_TYPES:

        step("Create route-map to match prefix-list and set localpref 500")

        input_dict_rm = {
            "r1": {
                "route_maps": {
                    "rmap_PATH1_{}".format(addr_type): [{
                        "action": "permit",
                        "seq_id": 10,
                        "match": {
                            addr_type: {
                                "prefix_lists": "pf_ls_{}".format(addr_type)
                            }
                        },
                        "set": {
                            "locPrf": 500
                        },
                    }]
                }
            }
        }

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

        step("Create route-map to match prefix-list and set localpref 600")

        input_dict_rm = {
            "r1": {
                "route_maps": {
                    "rmap_PATH2_{}".format(addr_type): [{
                        "action": "permit",
                        "seq_id": 20,
                        "match": {
                            addr_type: {
                                "prefix_lists": "pf_ls_{}".format(addr_type)
                            }
                        },
                        "set": {
                            "locPrf": 600
                        },
                    }]
                }
            }
        }

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

        input_dict_rma = {
            "r1": {
                "bgp": [{
                    "local_as": "100",
                    "address_family": {
                        addr_type: {
                            "unicast": {
                                "neighbor": {
                                    "r3": {
                                        "dest_link": {
                                            "r1-link1": {
                                                "route_maps": [{
                                                    "name":
                                                    "rmap_PATH1_{}".format(
                                                        addr_type),
                                                    "direction":
                                                    "in",
                                                }]
                                            }
                                        }
                                    },
                                    "r4": {
                                        "dest_link": {
                                            "r1-link1": {
                                                "route_maps": [{
                                                    "name":
                                                    "rmap_PATH2_{}".format(
                                                        addr_type),
                                                    "direction":
                                                    "in",
                                                }]
                                            }
                                        }
                                    },
                                }
                            }
                        }
                    },
                }]
            }
        }

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

    dut = "r1"
    attribute = "locPrf"

    for addr_type in ADDR_TYPES:

        step("Verify bestpath is installed as per highest localpref")

        input_routes_r3 = {
            "r3": {
                "static_routes": [{
                    "network": [NETWORK3_3[addr_type], NETWORK3_4[addr_type]]
                }]
            }
        }

        result = verify_best_path_as_per_bgp_attribute(tgen, addr_type, dut,
                                                       input_routes_r3,
                                                       attribute)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    for addr_type in ADDR_TYPES:

        step("Create route-map to match prefix-list and set localpref 700")

        input_dict_rm = {
            "r1": {
                "route_maps": {
                    "rmap_PATH1_{}".format(addr_type): [{
                        "action": "permit",
                        "seq_id": 10,
                        "match": {
                            addr_type: {
                                "prefix_lists": "pf_ls_{}".format(addr_type)
                            }
                        },
                        "set": {
                            "locPrf": 700
                        },
                    }]
                }
            }
        }

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

    for addr_type in ADDR_TYPES:

        step("Verify bestpath is changed as per highest localpref")

        input_routes_r3 = {
            "r3": {
                "static_routes": [{
                    "network": [NETWORK3_3[addr_type], NETWORK3_4[addr_type]]
                }]
            }
        }

        result = verify_best_path_as_per_bgp_attribute(tgen, addr_type, dut,
                                                       input_routes_r3,
                                                       attribute)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    for addr_type in ADDR_TYPES:

        step("Create route-map to match prefix-list and set as-path prepend")

        input_dict_rm = {
            "r1": {
                "route_maps": {
                    "rmap_PATH2_{}".format(addr_type): [{
                        "action": "permit",
                        "seq_id": 20,
                        "match": {
                            addr_type: {
                                "prefix_lists": "pf_ls_{}".format(addr_type)
                            }
                        },
                        "set": {
                            "localpref": 700,
                            "path": {
                                "as_num": "111",
                                "as_action": "prepend"
                            },
                        },
                    }]
                }
            }
        }

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

    attribute = "path"

    for addr_type in ADDR_TYPES:

        step("Verify bestpath is changed as per shortest as-path")

        input_routes_r3 = {
            "r3": {
                "static_routes": [{
                    "network": [NETWORK3_3[addr_type], NETWORK3_4[addr_type]]
                }]
            }
        }

        result = verify_best_path_as_per_bgp_attribute(tgen, addr_type, dut,
                                                       input_routes_r3,
                                                       attribute)
        assert result is True, "Testcase {} : Failed \n Error: {}".format(
            tc_name, result)

    write_test_footer(tc_name)
コード例 #16
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)
コード例 #17
0
def test_mroute_with_RP_default_route_all_nodes_p2(request):
    """
    TC_50 Verify mroute when LHR,FHR,RP and transit routers reachable
    using default routes
    """

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

    # Creating configuration from JSON
    kill_iperf(tgen)
    clear_ip_mroute(tgen)
    reset_config_on_routers(tgen)
    clear_ip_pim_interface_traffic(tgen, topo)

    # Don"t run this test if we have any failure.
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)
    step(
        "Remove c1-c2 connected link to simulate topo "
        "c1(LHR)---l1(RP)----r2---f1-----c2(FHR)"
    )

    intf_c1_c2 = topo["routers"]["c1"]["links"]["c2"]["interface"]
    intf_c2_c1 = topo["routers"]["c2"]["links"]["c1"]["interface"]
    shutdown_bringup_interface(tgen, "c1", intf_c1_c2, False)
    shutdown_bringup_interface(tgen, "c2", intf_c2_c1, False)

    step("Enable the PIM on all the interfaces of FRR1, FRR2, FRR3")
    step(
        "Enable IGMP of FRR1 interface and send IGMP joins "
        " from FRR1 node for group range (225.1.1.1-5)"
    )

    intf_c1_i4 = topo["routers"]["c1"]["links"]["i4"]["interface"]
    input_dict = {
        "c1": {"igmp": {"interfaces": {intf_c1_i4: {"igmp": {"version": "2"}}}}}
    }
    result = create_igmp_config(tgen, topo, input_dict)
    assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)

    input_join = {"i4": topo["routers"]["i4"]["links"]["c1"]["interface"]}

    for recvr, recvr_intf in input_join.items():
        result = config_to_send_igmp_join_and_traffic(
            tgen, topo, tc_name, recvr, recvr_intf, GROUP_RANGE_1, join=True
        )
        assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)

        result = iperfSendIGMPJoin(tgen, recvr, IGMP_JOIN_RANGE_1, join_interval=1)
        assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)

    step("Configure static RP for (225.1.1.1-5) as R2")

    input_dict = {
        "l1": {
            "pim": {
                "rp": [
                    {
                        "rp_addr": topo["routers"]["l1"]["links"]["lo"]["ipv4"].split(
                            "/"
                        )[0],
                        "group_addr_range": GROUP_RANGE,
                    }
                ]
            }
        }
    }

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

    step("Send traffic from C2 to all the groups ( 225.1.1.1 to 225.1.1.5)")

    input_src = {"i5": topo["routers"]["i5"]["links"]["c2"]["interface"]}

    for src, src_intf in input_src.items():
        result = config_to_send_igmp_join_and_traffic(
            tgen, topo, tc_name, src, src_intf, GROUP_RANGE_1, traffic=True
        )
        assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)

        result = iperfSendTraffic(tgen, src, IGMP_JOIN_RANGE_1, 32, 2500)
        assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)

    source_i5 = topo["routers"]["i5"]["links"]["c2"]["ipv4"].split("/")[0]

    input_dict_starg = [
        {
            "dut": "c1",
            "src_address": "*",
            "iif": topo["routers"]["c1"]["links"]["l1"]["interface"],
            "oil": topo["routers"]["c1"]["links"]["i4"]["interface"],
        }
    ]

    input_dict_sg = [
        {
            "dut": "c1",
            "src_address": source_i5,
            "iif": topo["routers"]["c1"]["links"]["l1"]["interface"],
            "oil": topo["routers"]["c1"]["links"]["i4"]["interface"],
        }
    ]

    step("Verify mroutes and iff upstream")

    for data in input_dict_sg:
        result = verify_ip_mroutes(
            tgen,
            data["dut"],
            data["src_address"],
            IGMP_JOIN_RANGE_1,
            data["iif"],
            data["oil"],
        )
        assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)

        result = verify_upstream_iif(
            tgen, data["dut"], data["iif"], data["src_address"], IGMP_JOIN_RANGE_1
        )
        assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)

    for data in input_dict_starg:
        result = verify_ip_mroutes(
            tgen,
            data["dut"],
            data["src_address"],
            IGMP_JOIN_RANGE_1,
            data["iif"],
            data["oil"],
        )
        assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)

        result = verify_upstream_iif(
            tgen, data["dut"], data["iif"], data["src_address"], IGMP_JOIN_RANGE_1
        )
        assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)

    step("Delete static routes RP on all the nodes")
    input_dict = {
        "c2": {
            "static_routes": [
                {"network": ["1.0.4.11/32"], "next_hop": "10.0.3.2", "delete": True}
            ]
        },
        "c1": {
            "static_routes": [
                {"network": ["1.0.4.11/32"], "next_hop": "10.0.2.2", "delete": True}
            ]
        },
        "r2": {
            "static_routes": [
                {"network": ["1.0.4.11/32"], "next_hop": "10.0.12.1", "delete": True}
            ]
        },
        "f1": {
            "static_routes": [
                {"network": ["1.0.4.11/32"], "next_hop": "10.0.7.2", "delete": True}
            ]
        },
    }

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

    step("Verify RP info unknown after removing static route from c2 ")
    dut = "c2"
    rp_address = topo["routers"]["l1"]["links"]["lo"]["ipv4"].split("/")[0]
    SOURCE = "Static"
    result = verify_pim_rp_info(
        tgen, topo, dut, GROUP_RANGE_1, "Unknown", rp_address, SOURCE
    )
    assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)

    for data in input_dict_starg:
        result = verify_ip_mroutes(
            tgen,
            data["dut"],
            data["src_address"],
            IGMP_JOIN_RANGE_1,
            data["iif"],
            data["oil"],
            expected=False,
        )
        assert result is not True, "Testcase {} : Failed Error: {}".format(
            tc_name, result
        )

        result = verify_upstream_iif(
            tgen,
            data["dut"],
            data["iif"],
            data["src_address"],
            IGMP_JOIN_RANGE_1,
            expected=False,
        )
        assert result is not True, "Testcase {} : Failed Error: {}".format(
            tc_name, result
        )

    step("Configure default routes on all the nodes")

    intf_f1_c2 = topo["routers"]["f1"]["links"]["c2"]["ipv4"].split("/")[0]
    intf_l1_c1 = topo["routers"]["l1"]["links"]["c1"]["ipv4"].split("/")[0]
    intf_l1_r2 = topo["routers"]["l1"]["links"]["r2"]["ipv4"].split("/")[0]
    intf_r2_f1 = topo["routers"]["r2"]["links"]["f1"]["ipv4"].split("/")[0]

    input_dict = {
        "c1": {"static_routes": [{"network": "0.0.0.0/0", "next_hop": intf_l1_c1}]},
        "c2": {"static_routes": [{"network": "0.0.0.0/0", "next_hop": intf_f1_c2}]},
        "r2": {"static_routes": [{"network": "0.0.0.0/0", "next_hop": intf_l1_r2}]},
        "f1": {"static_routes": [{"network": "0.0.0.0/0", "next_hop": intf_r2_f1}]},
    }
    result = create_static_routes(tgen, input_dict)
    assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)

    step("applying ip nht config  on c2")

    raw_config = {
        "c1": {"raw_config": ["ip nht resolve-via-default"]},
        "c2": {"raw_config": ["ip nht resolve-via-default"]},
        "r2": {"raw_config": ["ip nht resolve-via-default"]},
        "f1": {"raw_config": ["ip nht resolve-via-default"]},
        "l1": {"raw_config": ["ip nht resolve-via-default"]},
    }

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

    step("Verify RP info Not unknown after removing static route from c2 ")
    dut = "c2"
    step("Verify RP info is NOT unknown after removing static route from c2 ")
    result = verify_pim_rp_info(
        tgen, topo, dut, GROUP_RANGE_1, "Unknown", rp_address, SOURCE, expected=False
    )
    assert result is not True, "Testcase {} :Failed \n Error: {}".format(
        tc_name, result
    )

    step("Verify (s,g) populated after adding default route ")

    for data in input_dict_sg:
        result = verify_ip_mroutes(
            tgen,
            data["dut"],
            data["src_address"],
            IGMP_JOIN_RANGE_1,
            data["iif"],
            data["oil"],
        )
        assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)

        result = verify_upstream_iif(
            tgen, data["dut"], data["iif"], data["src_address"], IGMP_JOIN_RANGE_1
        )
        assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)

    step("Verify (*,g) populated after adding default route ")

    for data in input_dict_starg:
        result = verify_ip_mroutes(
            tgen,
            data["dut"],
            data["src_address"],
            IGMP_JOIN_RANGE_1,
            data["iif"],
            data["oil"],
        )
        assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)

        result = verify_upstream_iif(
            tgen, data["dut"], data["iif"], data["src_address"], IGMP_JOIN_RANGE_1
        )
        assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)

    write_test_footer(tc_name)
コード例 #18
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)
コード例 #19
0
def test_PIM_hello_tx_rx_p1(request):
    """
    TC_54 Verify received and transmit hello stats
        are getting cleared after PIM nbr reset
    """

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

    # Creating configuration from JSON
    kill_iperf(tgen)
    clear_ip_mroute(tgen)
    reset_config_on_routers(tgen)
    clear_ip_pim_interface_traffic(tgen, topo)

    # Don"t run this test if we have any failure.
    if tgen.routers_have_failure():
        pytest.skip(tgen.errors)
    step(
        "Remove c1-c2 connected link to simulate topo "
        "c1(LHR)---l1(RP)----r2---f1-----c2(FHR)"
    )

    intf_c1_c2 = topo["routers"]["c1"]["links"]["c2"]["interface"]
    intf_c2_c1 = topo["routers"]["c2"]["links"]["c1"]["interface"]
    shutdown_bringup_interface(tgen, "c1", intf_c1_c2, False)
    shutdown_bringup_interface(tgen, "c2", intf_c2_c1, False)

    step("Enable the PIM on all the interfaces of FRR1, FRR2, FRR3")
    step(
        "Enable IGMP of FRR1 interface and send IGMP joins "
        " from FRR1 node for group range (225.1.1.1-5)"
    )

    intf_c1_i4 = topo["routers"]["c1"]["links"]["i4"]["interface"]
    input_dict = {
        "c1": {"igmp": {"interfaces": {intf_c1_i4: {"igmp": {"version": "2"}}}}}
    }
    result = create_igmp_config(tgen, topo, input_dict)
    assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)

    input_join = {"i4": topo["routers"]["i4"]["links"]["c1"]["interface"]}

    for recvr, recvr_intf in input_join.items():
        result = config_to_send_igmp_join_and_traffic(
            tgen, topo, tc_name, recvr, recvr_intf, GROUP_RANGE_1, join=True
        )
        assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)

        result = iperfSendIGMPJoin(tgen, recvr, IGMP_JOIN_RANGE_1, join_interval=1)
        assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)

    step("Configure static RP for (225.1.1.1-5) as R2")

    input_dict = {
        "l1": {
            "pim": {
                "rp": [
                    {
                        "rp_addr": topo["routers"]["l1"]["links"]["lo"]["ipv4"].split(
                            "/"
                        )[0],
                        "group_addr_range": GROUP_RANGE,
                    }
                ]
            }
        }
    }

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

    step("Send Mcast traffic from C2 to all the groups ( 225.1.1.1 to 225.1.1.5)")

    input_src = {"i5": topo["routers"]["i5"]["links"]["c2"]["interface"]}

    for src, src_intf in input_src.items():
        result = config_to_send_igmp_join_and_traffic(
            tgen, topo, tc_name, src, src_intf, GROUP_RANGE_1, traffic=True
        )
        assert result is True, "Testcase {}: Failed Error: {}".format(tc_name, result)

        result = iperfSendTraffic(tgen, src, IGMP_JOIN_RANGE_1, 32, 2500)
        assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)

    source_i5 = topo["routers"]["i5"]["links"]["c2"]["ipv4"].split("/")[0]

    input_dict_starg = [
        {
            "dut": "c1",
            "src_address": "*",
            "iif": topo["routers"]["c1"]["links"]["l1"]["interface"],
            "oil": topo["routers"]["c1"]["links"]["i4"]["interface"],
        }
    ]

    input_dict_sg = [
        {
            "dut": "c1",
            "src_address": source_i5,
            "iif": topo["routers"]["c1"]["links"]["l1"]["interface"],
            "oil": topo["routers"]["c1"]["links"]["i4"]["interface"],
        }
    ]

    step("(*,G) and (S,G) created on f1 and node verify using 'show ip mroute'")
    for data in input_dict_sg:
        result = verify_ip_mroutes(
            tgen,
            data["dut"],
            data["src_address"],
            IGMP_JOIN_RANGE_1,
            data["iif"],
            data["oil"],
        )
        assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)

    for data in input_dict_starg:
        result = verify_ip_mroutes(
            tgen,
            data["dut"],
            data["src_address"],
            IGMP_JOIN_RANGE_1,
            data["iif"],
            data["oil"],
        )
        assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)

    intf_l1_c1 = topo["routers"]["l1"]["links"]["c1"]["interface"]
    intf_c1_l1 = topo["routers"]["c1"]["links"]["l1"]["interface"]

    step("verify before stats on C1")
    state_dict = {"c1": {intf_c1_l1: ["helloTx", "helloRx"],}}

    c1_state_before = verify_pim_interface_traffic(tgen, state_dict)
    assert isinstance(
        c1_state_before, dict
    ), "Testcase{} : Failed \n state_before is not dictionary \n "
    "Error: {}".format(tc_name, result)

    step("Flap PIM nbr while doing interface c1-l1 interface shut from f1 side")
    shutdown_bringup_interface(tgen, "c1", intf_c1_l1, False)

    step(
        "After shut of local interface from c1 , verify rx/tx hello counters are cleared on c1 side"
        "verify using 'show ip pim interface traffic'"
    )
    shutdown_bringup_interface(tgen, "c1", intf_c1_l1, True)

    step("verify stats after on c1")
    c1_state_after = verify_pim_interface_traffic(tgen, state_dict)
    assert isinstance(
        c1_state_after, dict
    ), "Testcase{} : Failed \n state_before is not dictionary \n "
    "Error: {}".format(tc_name, result)

    step("verify stats not increamented on c1")
    result = verify_state_incremented(c1_state_before, c1_state_after)
    assert (
        result is not True
    ), "Testcase{} : Failed Error: {}" "stats incremented".format(tc_name, result)

    step("verify before stats on l1")
    l1_state_dict = {"l1": {intf_l1_c1: ["helloTx", "helloRx"],}}

    l1_state_before = verify_pim_interface_traffic(tgen, l1_state_dict)
    assert isinstance(
        l1_state_before, dict
    ), "Testcase{} : Failed \n state_before is not dictionary \n "
    "Error: {}".format(tc_name, result)

    step("Flap PIM nbr while doing interface r2-c1 shut from r2 side")
    shutdown_bringup_interface(tgen, "l1", intf_l1_c1, False)

    step(
        "After shut the interface from r2 side , verify r2 side rx and tx of hello"
        "counters are resetted show ip pim interface traffic"
    )
    shutdown_bringup_interface(tgen, "l1", intf_l1_c1, True)

    step("verify stats after on l1")
    l1_state_after = verify_pim_interface_traffic(tgen, l1_state_dict)
    assert isinstance(
        l1_state_after, dict
    ), "Testcase{} : Failed \n state_before is not dictionary \n "
    "Error: {}".format(tc_name, result)

    step("verify stats not increamented on l1")
    result = verify_state_incremented(l1_state_before, l1_state_after)
    assert (
        result is not True
    ), "Testcase{} : Failed Error: {}" "stats incremented".format(tc_name, result)

    step("Reinit the dict")
    c1_state_before = {}
    l1_state_before = {}
    c1_state_after = {}
    l1_state_after = {}

    step("verify before stats on C1")
    state_dict = {"c1": {intf_c1_l1: ["helloTx", "helloRx"],}}

    c1_state_before = verify_pim_interface_traffic(tgen, state_dict)
    assert isinstance(
        c1_state_before, dict
    ), "Testcase{} : Failed \n state_before is not dictionary \n "
    "Error: {}".format(tc_name, result)

    step("Flap c1-r2 pim nbr while changing ip address from c1 side")
    c1_l1_ip_subnet = topo["routers"]["c1"]["links"]["l1"]["ipv4"]

    raw_config = {
        "c1": {
            "raw_config": [
                "interface {}".format(intf_c1_l1),
                "no ip address {}".format(c1_l1_ip_subnet),
                "ip address {}".format(NEW_ADDRESS_2_SUBNET),
            ]
        }
    }

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

    step("verify stats after on c1")
    c1_state_after = verify_pim_interface_traffic(tgen, state_dict)
    assert isinstance(
        c1_state_after, dict
    ), "Testcase{} : Failed \n state_before is not dictionary \n "
    "Error: {}".format(tc_name, result)

    step("verify stats not increamented on c1")
    result = verify_state_incremented(c1_state_before, c1_state_after)
    assert (
        result is not True
    ), "Testcase{} : Failed Error: {}" "stats incremented".format(tc_name, result)

    write_test_footer(tc_name)
コード例 #20
0
def test_ospf_redistribution_tc6_p0(request):
    """Test OSPF inter area route calculations."""
    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.")
    reset_config_on_routers(tgen)

    step("Verify that OSPF neighbors are FULL.")
    ospf_covergence = verify_ospf_neighbor(tgen, topo)
    assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
        ospf_covergence)

    step("verify intra area route is calculated for r0-r3 interface ip in R1")
    ip = topo["routers"]["r0"]["links"]["r3"]["ipv4"]
    ip_net = str(ipaddress.ip_interface(u"{}".format(ip)).network)
    nh = topo["routers"]["r0"]["links"]["r1"]["ipv4"].split("/")[0]
    input_dict = {
        "r1": {
            "static_routes": [{
                "network": ip_net,
                "no_of_ip": 1,
                "routeType": "N"
            }]
        }
    }

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

    protocol = "ospf"
    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("Delete the ip address on newly configured loopback of R0")
    topo1 = {
        "r0": {
            "links": {
                "r3": {
                    "ipv4": topo["routers"]["r0"]["links"]["r3"]["ipv4"],
                    "interface":
                    topo["routers"]["r0"]["links"]["r3"]["interface"],
                    "delete": True,
                }
            }
        }
    }

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

    dut = "r1"
    for num in range(0, nretry):
        result = verify_ospf_rib(tgen,
                                 dut,
                                 input_dict,
                                 next_hop=nh,
                                 expected=False)
        if result is not True:
            break
    assert result is not True, (
        "Testcase {} : Failed \n "
        "r1: OSPF routes are present after deleting ip address of newly "
        "configured loopback of R0 \n Error: {}".format(tc_name, result))

    protocol = "ospf"
    result = verify_rib(
        tgen,
        "ipv4",
        dut,
        input_dict,
        protocol=protocol,
        next_hop=nh,
        expected=False,
    )
    assert result is not True, (
        "Testcase {} : Failed \n "
        "r1: OSPF routes are present in fib after deleting ip address of newly "
        "configured loopback of R0 \n Error: {}".format(tc_name, result))

    step("Add back the deleted ip address on newly configured interface of R0")
    topo1 = {
        "r0": {
            "links": {
                "r3": {
                    "ipv4": topo["routers"]["r0"]["links"]["r3"]["ipv4"],
                    "interface":
                    topo["routers"]["r0"]["links"]["r3"]["interface"],
                }
            }
        }
    }

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

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

    protocol = "ospf"
    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("Shut no shut interface on R0")
    dut = "r0"
    intf = topo["routers"]["r0"]["links"]["r3"]["interface"]
    shutdown_bringup_interface(tgen, dut, intf, False)

    step("un shut the OSPF interface on R0")
    dut = "r0"
    shutdown_bringup_interface(tgen, dut, intf, True)

    dut = "r1"
    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,
                        next_hop=nh)
    assert result is True, "Testcase {} : Failed \n Error: {}".format(
        tc_name, result)

    write_test_footer(tc_name)
コード例 #21
0
def test_ospfv3_ecmp_tc16_p0(request):
    """
    Verify OSPF ECMP.

    Verify OSPF ECMP with max path configured as 8 (ECMP
    configured at FRR level)
    """
    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 8 interfaces between R1 and R2 and enable ospf in area 0.")

    reset_config_on_routers(tgen)

    step("Verify that OSPF is up with 8 neighborship sessions.")
    dut = "r1"
    ospf_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut)
    assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
        ospf_covergence)

    step("Configure a static route in R0 and redistribute in OSPF.")

    input_dict = {
        "r0": {
            "static_routes": [{
                "network": NETWORK["ipv6"][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)

    dut = "r0"
    red_static(dut)

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

    step("Verify that route in R2 in stalled with 8 next hops.")
    nh = []
    for item in range(1, 7):
        nh.append(llip)

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

    nh2 = llip

    nh.append(nh2)

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

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

    step("shut no shut all the interfaces on the remote router - R2")
    dut = "r1"
    for intfr in range(1, 7):
        intf = topo["routers"]["r1"]["links"]["r0-link{}".format(
            intfr)]["interface"]
        shutdown_bringup_interface(tgen, dut, intf, False)

    result = verify_ospf6_rib(tgen,
                              dut,
                              input_dict,
                              next_hop=nh,
                              expected=False)
    assert (
        result is not True
    ), "Testcase {} : Failed \n Route present in OSPF RIB.  Error: {}".format(
        tc_name, result)

    protocol = "ospf"
    result = verify_rib(tgen,
                        "ipv6",
                        dut,
                        input_dict,
                        protocol=protocol,
                        next_hop=nh,
                        expected=False)
    assert (
        result is not True
    ), "Testcase {} : Failed \n Route present in RIB. Error: {}".format(
        tc_name, result)

    for intfr in range(1, 7):
        intf = topo["routers"]["r1"]["links"]["r0-link{}".format(
            intfr)]["interface"]
        shutdown_bringup_interface(tgen, dut, intf, True)

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

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

    step("shut no shut on all the interfaces on DUT (r1)")
    for intfr in range(1, 7):
        intf = topo["routers"]["r1"]["links"]["r0-link{}".format(
            intfr)]["interface"]
        shutdown_bringup_interface(tgen, dut, intf, False)

    for intfr in range(1, 7):
        intf = topo["routers"]["r1"]["links"]["r0-link{}".format(
            intfr)]["interface"]
        shutdown_bringup_interface(tgen, dut, intf, True)

    step("Verify that all the neighbours are up and routes are installed"
         " with 8 next hop in ospf and ip route tables on R1.")

    step("Verify that OSPF is up with 8 neighborship sessions.")
    dut = "r1"
    ospf_covergence = verify_ospf6_neighbor(tgen, topo, dut=dut)
    assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format(
        ospf_covergence)

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

    protocol = "ospf"
    result = verify_rib(tgen,
                        "ipv6",
                        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)