示例#1
0
def set_status(dut, portlist, status):
    """

    :param dut:
    :type dut:
    :param portlist:
    :type portlist:
    :param status: "shutdown" or "startup"
    :type status: string
    :return:
    :rtype:
    """

    if '-' in portlist:
        st.config(dut, "config interface {} {}".format(status, portlist))
        return

    if not st.is_community_build():
        try:
            port = ",".join(portlist)
            return st.config(dut,
                             "config interface {} {}".format(status, port))
        except Exception as exp:
            st.warn("Failed to execute {} command - try alternative".format(
                status))

    for port in portlist:
        try:
            st.config(dut, "config interface {} {}".format(status, port))
        except ValueError as ex:
            st.warn("Failed to execute {} command - try alternative".format(
                status))
            st.config(dut, "config interface {} {}".format(port, status))
    return ""
示例#2
0
def get_status(dut, port=None):
    """

    :param dut:
    :type dut:
    :param port:
    :type port:
    :return:
    :rtype:
    """

    if not port:
        return st.show(dut, "show interfaces status")

    # no range support in community build
    if st.is_community_build():
        if "," in port or "-" in port:
            return st.show(dut, "show interfaces status")

    # port could be range switch to all when failed
    try:
        return st.show(dut, "show interfaces status {}".format(port))
    except ValueError as ex:
        st.warn("Failed to use interface command - try global")

    return st.show(dut, "show interfaces status")
示例#3
0
def get_status(dut, port=None, cli_type=''):
    """
    :param dut:
    :type dut:
    :param port:
    :type port:
    :return:
    :rtype:
    """
    cli_type = st.get_ui_type(dut, cli_type=cli_type)
    if cli_type == "click":
        if not port:
            return st.show(dut, "show interfaces status")

        # get all interfaces status if there is no interface range support
        if not _has_intf_range(dut):
            if "," in port or "-" in port:
                return st.show(dut, "show interfaces status")

        # port could be range switch to all when failed
        try:
            return st.show(dut, "show interfaces status {}".format(port))
        except ValueError:
            st.warn("Failed to use interface command - try global")

        return st.show(dut, "show interfaces status")
    elif cli_type == "klish":
        command = "show interface status"
        if port:
            interface = port.split(",")
            command += " | grep \"{}\"".format("|".join(interface))
        return st.show(dut, command, type=cli_type)
    elif cli_type in ["rest-patch", "rest-put"]:
        rest_urls = st.get_datastore(dut, "rest_urls")
        result = []
        if port:
            ports = port.split(",")
            for port2 in ports:
                url = rest_urls['per_interface_details'].format(port2)
                output = get_rest(dut, rest_url=url, timeout=60)
                processed_output = process_intf_status_rest_output(output)
                if processed_output:
                    result.extend(processed_output)
                st.log("REST output is: {}".format(output))
        else:
            url = rest_urls['all_interfaces_details']
            output = get_rest(dut, rest_url=url, timeout=60)
            processed_output = process_intf_status_rest_output(
                output, single_port=False)
            if processed_output:
                result.extend(processed_output)
        return result
    else:
        st.log("Unsupported CLI TYPE {}".format(cli_type))
        return False
示例#4
0
def test_ft_ip_static_route_traffic_forward():
    # Objective - Verify the Ipv4 traffic forwarding over IPv4 static route.
    tg_handler = tgapi.get_handles_byname("T1D1P1", "T1D2P1")
    tg = tg_handler["tg"]
    tg.tg_traffic_control(action="reset", port_handle=tg_handler["tg_ph_list"])
    tg.tg_traffic_control(action="clear_stats",
                          port_handle=tg_handler["tg_ph_list"])

    dut_rt_int_mac1 = basic_obj.get_ifconfig_ether(vars.D1, vars.D1T1P1)
    h1 = tg.tg_interface_config(port_handle=tg_handler["tg_ph_1"], mode='config', intf_ip_addr=data.ip4_addr[0], \
                                gateway=data.ip4_addr[1], src_mac_addr=data.tg_mac1, arp_send_req='1')
    st.log("INTFCONF: " + str(h1))
    h2 = tg.tg_interface_config(port_handle=tg_handler["tg_ph_2"], mode='config', intf_ip_addr=data.ip4_addr[9], \
                                gateway=data.ip4_addr[8], src_mac_addr=data.tg_mac2, arp_send_req='1')
    st.log("INTFCONF: " + str(h2))
    # Ping from tgen to DUT.
    res = tgapi.verify_ping(src_obj=tg, port_handle=tg_handler["tg_ph_1"], dev_handle=h1['handle'], dst_ip=data.ip4_addr[1], \
                      ping_count='1', exp_count='1')
    if res:
        st.log("Ping succeeded.")
    else:
        st.warn("Ping failed.")
    tr1 = tg.tg_traffic_config(port_handle=tg_handler["tg_ph_1"], mode='create', transmit_mode='single_burst',
                               pkts_per_burst=2000, \
                               length_mode='fixed', rate_pps=2000, l3_protocol='ipv4', mac_src=data.tg_mac1, \
                               mac_dst=dut_rt_int_mac1, ip_src_addr=data.ip4_addr[0],
                               ip_dst_addr=data.ip4_addr[9])
    st.log("TRAFCONF: " + str(tr1))
    res = tg.tg_traffic_control(action='run', stream_handle=tr1['stream_id'])
    st.log("TR_CTRL: " + str(res))
    tg.tg_traffic_control(action='stop', stream_handle=tr1['stream_id'])
    st.log("Checking the stats and verifying the traffic flow")
    traffic_details = {
        '1': {
            'tx_ports': [vars.T1D1P1],
            'tx_obj': [tg_handler["tg"]],
            'exp_ratio': [1],
            'rx_ports': [vars.T1D2P1],
            'rx_obj': [tg_handler["tg"]],
        }
    }
    #verify statistics
    aggrResult = tgapi.validate_tgen_traffic(traffic_details=traffic_details,
                                             mode='aggregate',
                                             comp_type='packet_count')
    if not aggrResult:
        st.report_fail("traffic_verification_failed")
    st.report_pass("test_case_passed")
示例#5
0
def apis_instrument(scope, data):
    if st.getenv("SPYTEST_API_INSTRUMENT_SUPPORT", "0") == "0":
        return
    if scope in ["session-init-start", "session-init-end"]:
        _session_init(scope)
    elif scope in ["session-clean-start", "session-clean-end"]:
        pass
    elif scope in ["init-config-start", "init-config-end"]:
        _show_runcfg(scope, data)
    elif scope in ["apply-base-config-dut", "apply-base-config-dut-start", "apply-base-config-dut-end"]:
        _show_runcfg(scope, data)
    elif scope in ["module-init-start", "module-init-end"]:
        pass
    elif scope in ["module-clean-start", "module-clean-end"]:
        pass
    elif scope in ["function-init-start", "function-init-end"]:
        pass
    elif scope in ["function-clean-start", "function-clean-end"]:
        pass
    elif scope in ["post-module-prolog", "post-class-prolog"]:
        _show_runcfg(scope, data)
    else:
        st.warn("Unknown scope {}".format(scope))
示例#6
0
def create_v6_route(route_count):
    vars = st.get_testbed_vars()
    dut = vars.D1

    ipfeature.show_ip_route(dut, family='ipv6')
    ipfeature.get_interface_ip_address(dut, family='ipv6')

    bgpfeature.create_bgp_router(dut, data.as_num, '')
    bgpfeature.create_bgp_neighbor(dut,
                                   data.as_num,
                                   data.ip6_addr[0],
                                   data.remote_as_num,
                                   family="ipv6")
    create_bgp_neighbor_route_map_config(dut, data.as_num, data.ip6_addr[0],
                                         data.routemap)

    tg_handler = tgapi.get_handles_byname("T1D1P2", "T1D2P2")
    tg = tg_handler["tg"]
    tg.tg_traffic_control(action="reset", port_handle=tg_handler["tg_ph_list"])
    tg.tg_traffic_control(action="clear_stats",
                          port_handle=tg_handler["tg_ph_list"])

    dut_rt_int_mac1 = basic_obj.get_ifconfig_ether(vars.D1, vars.D1T1P1)
    h1 = tg.tg_interface_config(port_handle=tg_handler["tg_ph_1"], mode='config', ipv6_intf_addr=data.ip6_addr[0], \
                                ipv6_prefix_length='64', ipv6_gateway=data.ip6_addr[1],
                                src_mac_addr=data.tg_mac1, arp_send_req='1')
    st.log("INTFCONF: " + str(h1))
    h2 = tg.tg_interface_config(port_handle=tg_handler["tg_ph_2"], mode='config', ipv6_intf_addr=data.ip6_addr[9], \
                                ipv6_prefix_length='64', ipv6_gateway=data.ip6_addr[8],
                                src_mac_addr=data.tg_mac2, arp_send_req='1')
    st.log("INTFCONF: " + str(h2))

    # Ping from tgen to DUT.
    res = tgapi.verify_ping(src_obj=tg, port_handle=tg_handler["tg_ph_1"], dev_handle=h1['handle'], dst_ip=data.ip6_addr[1], \
                      ping_count='1', exp_count='1')
    if res:
        st.log("Ping succeeded.")
    else:
        st.warn("Ping failed.")

    bgp_conf = tg.tg_emulation_bgp_config(handle=h1['handle'],
                                          mode='enable',
                                          ip_version='6',
                                          active_connect_enable='1',
                                          local_as=data.as_num,
                                          remote_as=data.remote_as_num,
                                          remote_ipv6_addr=data.ip6_addr[1])

    tg.tg_emulation_bgp_route_config(handle=bgp_conf['handle'],
                                     mode='add',
                                     ip_version='6',
                                     num_routes=route_count,
                                     prefix='3300:1::',
                                     as_path='as_seq:1')
    tg.tg_emulation_bgp_control(handle=bgp_conf['handle'], mode='start')

    # Configuring the BGP router.
    st.log("BGP neighborship established.")
    tr1 = tg.tg_traffic_config(port_handle=tg_handler["tg_ph_1"], mode='create', transmit_mode='single_burst',
                               pkts_per_burst=2000, \
                               length_mode='fixed', rate_pps=2000, l3_protocol='ipv6', mac_src=data.tg_mac1, \
                               mac_dst=dut_rt_int_mac1, ipv6_src_addr=data.ip6_addr[0],
                               ipv6_dst_addr=data.ip6_addr[9])
    st.log("TRAFCONF: " + str(tr1))

    res = tg.tg_traffic_control(action='run', stream_handle=tr1['stream_id'])
    st.log("TR_CTRL: " + str(res))
    tg.tg_traffic_control(action='stop', stream_handle=tr1['stream_id'])
    st.log("Checking the stats and verifying the traffic flow")
    traffic_details = {
        '1': {
            'tx_ports': [vars.T1D1P2],
            'tx_obj': [tg_handler["tg"]],
            'exp_ratio': [1],
            'rx_ports': [vars.T1D2P2],
            'rx_obj': [tg_handler["tg"]],
        }
    }
    # verify statistics
    aggrResult = tgapi.validate_tgen_traffic(traffic_details=traffic_details,
                                             mode='aggregate',
                                             comp_type='packet_count')
    if not aggrResult:
        return False
    else:
        return True
示例#7
0
def create_v4_route(route_count):
    vars = st.get_testbed_vars()
    dut = vars.D1

    ipfeature.show_ip_route(dut)
    ipfeature.get_interface_ip_address(dut)
    intf_obj.interface_status_show(dut)

    bgpfeature.create_bgp_router(dut, data.as_num, '')
    bgpfeature.create_bgp_neighbor(dut, data.as_num, data.ip4_addr[0],
                                   data.remote_as_num)

    tg_handler = tgapi.get_handles_byname("T1D1P1", "T1D2P1")
    tg = tg_handler["tg"]
    tg.tg_traffic_control(action="reset", port_handle=tg_handler["tg_ph_list"])
    tg.tg_traffic_control(action="clear_stats",
                          port_handle=tg_handler["tg_ph_list"])

    dut_rt_int_mac1 = basic_obj.get_ifconfig_ether(vars.D1, vars.D1T1P1)
    h1 = tg.tg_interface_config(port_handle=tg_handler["tg_ph_1"], mode='config', intf_ip_addr=data.ip4_addr[0], \
                                gateway=data.ip4_addr[1], src_mac_addr=data.tg_mac1, arp_send_req='1')
    st.log("INTFCONF: " + str(h1))
    h2 = tg.tg_interface_config(port_handle=tg_handler["tg_ph_2"], mode='config', intf_ip_addr=data.ip4_addr[9], \
                                gateway=data.ip4_addr[8], src_mac_addr=data.tg_mac2, arp_send_req='1')
    st.log("INTFCONF: " + str(h2))
    # Ping from tgen to DUT.
    res = tgapi.verify_ping(src_obj=tg, port_handle=tg_handler["tg_ph_1"], dev_handle=h1['handle'], dst_ip=data.ip4_addr[1], \
                      ping_count='1', exp_count='1')
    if res:
        st.log("Ping succeeded.")
    else:
        st.warn("Ping failed.")

    conf_var = {
        'mode': 'enable',
        'active_connect_enable': '1',
        'local_as': '200',
        'remote_as': '100',
        'remote_ip_addr': data.ip4_addr[1]
    }
    route_var = {
        'mode': 'add',
        'num_routes': route_count,
        'prefix': '121.1.1.0',
        'as_path': 'as_seq:1'
    }
    ctrl_start = {'mode': 'start'}

    # Configuring the BGP router.
    bgp_rtr1 = tgapi.tg_bgp_config(tg=tg,
                                   handle=h1['handle'],
                                   conf_var=conf_var,
                                   route_var=route_var,
                                   ctrl_var=ctrl_start)

    st.log("BGP_HANDLE: " + str(bgp_rtr1))
    st.log(
        "waiting for 10 sec to get the BGP neighbor started before going for another TG operation"
    )
    st.wait(10)
    # Verified at neighbor.
    tr1 = tg.tg_traffic_config(port_handle=tg_handler["tg_ph_1"], mode='create', transmit_mode='single_burst',
                               pkts_per_burst=2000, \
                               length_mode='fixed', rate_pps=2000, l3_protocol='ipv4', mac_src=data.tg_mac1, \
                               mac_dst=dut_rt_int_mac1, ip_src_addr=data.ip4_addr[0],
                               ip_dst_addr=data.ip4_addr[9])
    st.log("TRAFCONF: " + str(tr1))
    res = tg.tg_traffic_control(action='run', stream_handle=tr1['stream_id'])
    st.log("TR_CTRL: " + str(res))
    tg.tg_traffic_control(action='stop', stream_handle=tr1['stream_id'])
    st.log("Checking the stats and verifying the traffic flow")
    traffic_details = {
        '1': {
            'tx_ports': [vars.T1D1P1],
            'tx_obj': [tg_handler["tg"]],
            'exp_ratio': [1],
            'rx_ports': [vars.T1D2P1],
            'rx_obj': [tg_handler["tg"]],
        }
    }
    #verify statistics
    aggrResult = tgapi.validate_tgen_traffic(traffic_details=traffic_details,
                                             mode='aggregate',
                                             comp_type='packet_count')
    if not aggrResult:
        return False

    return True
示例#8
0
def set_status(dut, portlist, status, cli_type=''):
    """
    :param dut:
    :type dut:
    :param portlist:
    :type portlist:
    :param status: "shutdown" or "startup"
    :type status: string
    :return:
    :rtype:
    """
    cli_type = st.get_ui_type(dut, cli_type=cli_type)
    if cli_type == "click":
        if '-' in portlist:
            st.config(dut, "config interface {} {}".format(status, portlist))
            return

        # check if there is interface range support
        if _has_intf_range(dut):
            try:
                port = ",".join(portlist)
                return st.config(dut, "config interface {} {}".format(status, port))
            except Exception:
                st.warn("Failed to execute {} command - try alternative".format(status))

        for port in portlist:
            try:
                st.config(dut, "config interface {} {}".format(status, port))
            except ValueError:
                st.warn("Failed to execute {} command - try alternative".format(status))
                st.config(dut, "config interface {} {}".format(port, status))
    elif cli_type == "klish":
        commands = list()
        if portlist:
            for intf in make_list(portlist):
                intf_details = get_interface_number_from_name(intf)
                if not intf_details:
                    st.error("Interface data not found for {} ".format(intf))
                else:
                    commands.append("interface {} {}".format(intf_details["type"], intf_details["number"]))
                    command = "shutdown" if status == "shutdown" else "no shutdown"
                    commands.append(command)
                    commands.append("exit")
        if commands:
            st.config(dut, commands, type=cli_type)
            return True
        return False
    elif cli_type in ["rest-patch", "rest-put"]:
        rest_urls = st.get_datastore(dut, "rest_urls")
        oper = False if status == 'shutdown' else True
        portlist = make_list(portlist)
        for port in portlist:
            url = rest_urls['per_interface_config'].format(port)
            intf_operation = {"openconfig-interfaces:config": {"enabled": oper}}
            if not config_rest(dut, http_method=cli_type, rest_url=url, json_data=intf_operation):
                return False
        return True
    else:
        st.log("Unsupported CLI TYPE {}".format(cli_type))
        return False
    return ""
示例#9
0
def test_ft_arp_entry_link_failure():
    ################# Author Details ################
    # Name: Rakesh Kumar Vooturi
    # Email:  [email protected]
    #################################################
    #
    # Objective - Verify an ARP table entry learned on port based routing interface is
    #               removed from ARP table after link failure on which that entry is learned.
    # Objective - Verify an ARP table entry learned on vlan based routing interface is
    #               removed from ARP table after link failure on which that entry is learned
    #
    ############### Test bed details ################
    #  DUT-----TG
    #################################################
    # Ping from tgen to DUT.
    res = tgapi.verify_ping(src_obj=tg,
                            port_handle=tg_handler["tg_ph_1"],
                            dev_handle=h1['handle'],
                            dst_ip=data.d1t1_ip_addr,
                            ping_count='1',
                            exp_count='1')
    if res:
        st.log("Ping succeeded.")
    else:
        st.warn("Ping failed.")

    res = tgapi.verify_ping(src_obj=tg,
                            port_handle=tg_handler["tg_ph_2"],
                            dev_handle=h2['handle'],
                            dst_ip=data.d1t2_ip_addr,
                            ping_count='1',
                            exp_count='1')
    st.log("PING_RES: " + str(res))
    if res:
        st.log("Ping succeeded.")
    else:
        st.warn("Ping failed.")

    # Verify dynamic arp entries
    st.log("Verifying the arp entries on the DUT.")
    if not arp_obj.verify_arp(dut1, data.t1d1_ip_addr, data.t1d1_mac_addr,
                              vars.D1T1P1):
        st.report_fail("ARP_entry_dynamic_entry_fail", data.t1d1_ip_addr, dut1)
    st.log("Verifying the arp entries on the DUT")
    if not arp_obj.verify_arp(dut1, data.t2d1_ip_addr, data.t2d1_mac_addr,
                              vars.D1T1P2, data.vlan_1):
        st.report_fail("ARP_entry_dynamic_entry_fail", data.t2d1_ip_addr, dut1)

    # Shutdown the routing interface link.
    st.log("Shutdown the routing interface links.")
    if not interface_obj.interface_operation(dut1, [vars.D1T1P1, vars.D1T1P2],
                                             "shutdown"):
        st.report_fail('interface_admin_shut_down_fail',
                       [vars.D1T1P1, vars.D1T1P2])

    # Verify dynamic arp entries
    st.log("Verifying the arp entries on the DUT.")
    if arp_obj.verify_arp(dut1, data.t1d1_ip_addr, data.t1d1_mac_addr,
                          vars.D1T1P1):
        st.report_fail("ARP_dynamic_entry_removal_fail", data.t1d1_ip_addr,
                       vars.D1T1P1)
    st.log("Verifying the arp entries on the DUT")
    if arp_obj.verify_arp(dut1, data.t2d1_ip_addr):
        st.report_fail("ARP_dynamic_entry_removal_fail", data.t2d1_ip_addr,
                       vars.D1T1P2)

    # Startup the routing interface link.
    st.log("Startup the routing interface link.")
    if not interface_obj.interface_operation(dut1, [vars.D1T1P1, vars.D1T1P2],
                                             "startup"):
        st.report_fail('interface_admin_startup_fail',
                       [vars.D1T1P1, vars.D1T1P2])

    st.wait(5)

    # Verify dynamic arp entries
    st.log("Verifying the arp entries on the DUT.")
    if not arp_obj.verify_arp(dut1, data.t1d1_ip_addr, data.t1d1_mac_addr,
                              vars.D1T1P1):
        st.report_fail("ARP_entry_dynamic_entry_fail", data.t1d1_ip_addr, dut1)
    st.log("Verifying the arp entries on the DUT")
    if not arp_obj.verify_arp(dut1, data.t2d1_ip_addr, data.t2d1_mac_addr,
                              vars.D1T1P2, data.vlan_1):
        st.report_fail("ARP_entry_dynamic_entry_fail", data.t2d1_ip_addr, dut1)

    st.report_pass("test_case_passed")
示例#10
0
def test_ft_arp_clear_cache_static_and_dynamic_entries(
        fixture_ft_arp_clear_cache_static_and_dynamic_entries):
    ################## Author Details ###############
    # Name: Rakesh Kumar Vooturi
    # Email: [email protected]
    #################################################
    #
    # Objective - Verify that the clearing the ARP cache,
    #             all dynamic entries are removed and static entries are not cleared.
    #
    ############### Test bed details ################
    #  TG-----DUT-----TG
    #################################################
    # Adding static arp entries
    arp_obj.add_static_arp(dut1, data.static_arp_ip_1, data.static_arp_mac_1,
                           vars.D1T1P1)
    arp_obj.add_static_arp(dut1, data.static_arp_ip, data.static_arp_mac,
                           data.vlan_int_1)

    res = tgapi.verify_ping(src_obj=tg,
                            port_handle=tg_handler["tg_ph_1"],
                            dev_handle=h1['handle'],
                            dst_ip=data.d1t1_ip_addr,
                            ping_count='1',
                            exp_count='1')
    if res:
        st.log("Ping succeeded.")
    else:
        st.warn("Ping failed.")

    res = tgapi.verify_ping(src_obj=tg,
                            port_handle=tg_handler["tg_ph_2"],
                            dev_handle=h2['handle'],
                            dst_ip=data.d1t2_ip_addr,
                            ping_count='1',
                            exp_count='1')
    if res:
        st.log("Ping succeeded.")
    else:
        st.warn("Ping failed.")

    # Verify static and dynamic arp entries
    st.log("Verifying the arp entries on the DUT")
    if not arp_obj.verify_arp(dut1, data.t1d1_ip_addr, data.t1d1_mac_addr,
                              vars.D1T1P1):
        st.report_fail("ARP_entry_dynamic_entry_fail", data.t1d1_ip_addr, dut1)
    if not arp_obj.verify_arp(dut1, data.t2d1_ip_addr, data.t2d1_mac_addr,
                              vars.D1T1P2, data.vlan_1):
        st.report_fail("ARP_entry_dynamic_entry_fail", data.t2d1_ip_addr, dut1)
    if not arp_obj.verify_arp(dut1, data.static_arp_ip_1,
                              data.static_arp_mac_1, vars.D1T1P1):
        st.report_fail("static_arp_create_fail", dut1)
    if not arp_obj.verify_arp(dut1, data.static_arp_ip, data.static_arp_mac,
                              "", data.vlan_1):
        st.report_fail("static_arp_create_fail", dut1)

    st.banner(
        "Start - Verifying dynamic and static arp entries behavior on issuing sonic-clear arp command *WITH* traffic flowing"
    )

    # TG ports reset
    st.log("Resetting the TG ports")
    tg.tg_traffic_control(action="clear_stats",
                          port_handle=tg_handler["tg_ph_list"])

    #TG stream formation
    s1 = tg.tg_traffic_config(port_handle=tg_handler["tg_ph_2"],
                              mode='create',
                              rate_pps=10,
                              mac_src=data.t2d1_mac_addr,
                              transmit_mode="continuous",
                              mac_dst=d1_mac_addr,
                              l2_encap='ethernet_ii_vlan',
                              l3_protocol="ipv4",
                              ip_dst_addr=data.t1d1_ip_addr,
                              ip_src_addr=data.t2d1_ip_addr,
                              vlan_id=data.vlan_1,
                              vlan="enable")
    s2 = tg.tg_traffic_config(port_handle=tg_handler["tg_ph_1"],
                              mode='create',
                              rate_pps=10,
                              mac_src=data.t1d1_mac_addr,
                              transmit_mode="continuous",
                              mac_dst=d1_mac_addr,
                              l2_encap='ethernet_ii_vlan',
                              l3_protocol="ipv4",
                              ip_dst_addr=data.t2d1_ip_addr,
                              ip_src_addr=data.t1d1_ip_addr)

    tg.tg_traffic_control(action="run",
                          stream_handle=[s1['stream_id'], s2['stream_id']])

    # Adding wait for traffic to flow.
    st.wait(5)

    # Issuing sonic-clear arp command and veryfying the entries behavior.
    arp_obj.clear_arp_table(dut1)

    # Adding wait for traffic to flow.
    st.wait(5)

    # Verify static and dynamic arp entries after clear arp
    st.log(
        "Verifying the arp entries on the DUT after issuing sonic-clear arp command with traffic flowing."
    )
    if not arp_obj.verify_arp(dut1, data.t1d1_ip_addr, data.t1d1_mac_addr,
                              vars.D1T1P1):
        st.report_fail("ARP_entry_dynamic_entry_fail", data.t1d1_ip_addr, dut1)
    if not arp_obj.verify_arp(dut1, data.t2d1_ip_addr, data.t2d1_mac_addr,
                              vars.D1T1P2, data.vlan_1):
        st.report_fail("ARP_entry_dynamic_entry_fail", data.t2d1_ip_addr, dut1)
    if not arp_obj.verify_arp(dut1, data.static_arp_ip_1,
                              data.static_arp_mac_1, vars.D1T1P1):
        st.report_fail("static_arp_delete_fail", dut1)
    if not arp_obj.verify_arp(dut1, data.static_arp_ip, data.static_arp_mac,
                              "", data.vlan_1):
        st.report_fail("static_arp_delete_fail", dut1)

    # Stop the traffic
    tg.tg_traffic_control(action="stop",
                          stream_handle=[s1['stream_id'], s2['stream_id']])

    st.log("Verifying the TG stats")

    traffic_details = {
        '1': {
            'tx_ports': [vars.T1D1P2],
            'tx_obj': [tg],
            'exp_ratio': [1],
            'rx_ports': [vars.T1D1P1],
            'rx_obj': [tg],
        }
    }
    if not tgapi.validate_tgen_traffic(traffic_details=traffic_details,
                                       mode='aggregate',
                                       comp_type='packet_count'):
        st.report_fail("traffic_verification_failed")
    else:
        st.log("traffic verification passed")

    st.banner(
        "End - Verified dynamic and static arp entries behavior on issuing sonic-clear arp command *WITH* traffic flowing"
    )

    st.banner(
        "Start - Verifying dynamic and static arp entries behavior on issuing sonic-clear arp command *WITHOUT* traffic flowing"
    )
    # Issuing sonic-clear arp command and veryfying the entries behavior.
    arp_obj.clear_arp_table(dut1)

    # Verify static and dynamic arp entries after clear arp
    st.log(
        "Verifying the arp entries on the DUT after issuing sonic-clear arp command"
    )
    if arp_obj.verify_arp(dut1, data.t1d1_ip_addr, data.t1d1_mac_addr,
                          vars.D1T1P1):
        st.report_fail("ARP_dynamic_entry_clear_arp_fail", data.t1d1_ip_addr,
                       dut1)
    if arp_obj.verify_arp(dut1, data.t2d1_ip_addr, data.t2d1_mac_addr,
                          vars.D1T1P2, data.vlan_1):
        st.report_fail("ARP_dynamic_entry_clear_arp_fail", data.t2d1_ip_addr,
                       dut1)
    if not arp_obj.verify_arp(dut1, data.static_arp_ip_1,
                              data.static_arp_mac_1, vars.D1T1P1):
        st.report_fail("static_arp_delete_fail", dut1)
    if not arp_obj.verify_arp(dut1, data.static_arp_ip, data.static_arp_mac,
                              "", data.vlan_1):
        st.report_fail("static_arp_delete_fail", dut1)

    st.banner(
        "End - Verified dynamic and static arp entries behavior on issuing sonic-clear arp command *WITHOUT* traffic flowing"
    )

    st.report_pass("test_case_passed")
示例#11
0
def test_ft_arp_dynamic_renew_traffic_test(
        fixture_ft_arp_dynamic_renew_traffic_test):
    ################## Author Details ################
    # Name: Rakesh Kumar Vooturi
    # Email: [email protected]
    ##################################################
    #
    # Objective - Verify a dynamic ARP table entry can be created.
    # Objective - Verify that there is no data traffic loss during ARP dynamic review.
    #
    ############### Test bed details ################
    #  TG-----DUT-----TG
    #################################################
    # Set DUT values
    st.log("Setting the DUT values")
    arp_obj.set_arp_ageout_time(dut1, 5)

    # Ping from tgen to DUT.
    res = tgapi.verify_ping(src_obj=tg,
                            port_handle=tg_handler["tg_ph_1"],
                            dev_handle=h1['handle'],
                            dst_ip=data.d1t1_ip_addr,
                            ping_count='1',
                            exp_count='1')
    if res:
        st.log("Ping succeeded.")
    else:
        st.warn("Ping failed.")

    res = tgapi.verify_ping(src_obj=tg,
                            port_handle=tg_handler["tg_ph_2"],
                            dev_handle=h2['handle'],
                            dst_ip=data.d1t2_ip_addr,
                            ping_count='1',
                            exp_count='1')
    if res:
        st.log("Ping succeeded.")
    else:
        st.warn("Ping failed.")

    # TG ports reset
    st.log("Resetting the TG ports")
    tg.tg_traffic_control(action="clear_stats",
                          port_handle=tg_handler["tg_ph_list"])

    #TG stream formation
    s1 = tg.tg_traffic_config(port_handle=tg_handler["tg_ph_2"],
                              mode='create',
                              rate_pps=10,
                              mac_src=data.t2d1_mac_addr,
                              transmit_mode="continuous",
                              mac_dst=d1_mac_addr,
                              l2_encap='ethernet_ii_vlan',
                              l3_protocol="ipv4",
                              ip_dst_addr=data.t1d1_ip_addr,
                              ip_src_addr=data.t2d1_ip_addr,
                              vlan_id=data.vlan_1,
                              vlan="enable")
    tg.tg_traffic_control(action="run", stream_handle=s1['stream_id'])

    # Waiting for more than arp ageout time
    st.wait(10)
    tg.tg_traffic_control(action="stop", stream_handle=s1['stream_id'])

    # Adding sleep
    st.wait(2)

    st.log("Checking the stats and verifying the traffic flow")
    traffic_details = {
        '1': {
            'tx_ports': [vars.T1D1P2],
            'tx_obj': [tg],
            'exp_ratio': [1],
            'rx_ports': [vars.T1D1P1],
            'rx_obj': [tg],
        }
    }
    if not tgapi.validate_tgen_traffic(traffic_details=traffic_details,
                                       mode='aggregate',
                                       comp_type='packet_count'):
        st.report_fail("traffic_verification_failed")
    else:
        st.log("traffic verification passed")
    st.report_pass("test_case_passed")
示例#12
0
def set_crm_thresholds_value(dut, family, mode, value, cli_type=""):
    """
    Configuring CRM Threshold values.
    Author : Prudvi Mangadu ([email protected])
    :param dut:
    :param family:
    :param mode:
    :param value:
    :param cli_type: click or klish designation:
    :return:
    """
    cli_type = st.get_ui_type(dut, cli_type=cli_type)
    family = family.lower()
    mode = mode.lower()
    if family == 'acl_table_stats':
        family = 'acl_table'
    family_list = crm_get_family_list(dut)
    if family not in family_list:
        log = "family: '{}' is  invalid , use any of valid family from - {}".format(
            family, ','.join(family_list))
        st.error(log)
        return False
    if mode not in mode_list:
        log = "mode:'{}' is invalid , use any of valid mode from - {}".format(
            mode, ','.join(mode_list))
        st.error(log)
        return False
    command = ""
    if cli_type == "click":
        command = 'crm config thresholds {} {} {}'.format(
            family.replace('_', ' '), mode, value)
        if family == 'all':
            st.warn("Command: '{}' is not a Click command".format(command))
    elif cli_type == "klish":
        command = 'crm thresholds {} {} {}'.format(family.replace('_', ' '),
                                                   mode, value)
    elif cli_type in ["rest-patch", "rest-put"]:
        rest_urls = st.get_datastore(dut, "rest_urls")
        url = rest_urls['crm_thresholds']
        config_json = {"openconfig-system-crm:threshold": {}}
        k = {"config": {}}
        k["config"][mode] = int(value)
        temp = dict()
        list1 = family.split("_")
        if len(list1) == 3:
            if "acl" in list1:
                temp = {list1[1]: {list1[2]: k}}
            else:
                temp["{}-{}".format(list1[1], list1[2])] = k
            config_json["openconfig-system-crm:threshold"][list1[0]] = temp
        elif len(list1) == 2:
            temp[list1[0]] = {list1[1]: k}
            config_json["openconfig-system-crm:threshold"] = temp
        else:
            temp[list1[0]] = k
            config_json["openconfig-system-crm:threshold"] = temp
        if not config_rest(
                dut, http_method=cli_type, rest_url=url,
                json_data=config_json):
            return False

    else:
        st.error("Unsupported cli type: {}".format(cli_type))
        return False
    if command:
        rv = st.config(dut, command, type=cli_type)
        if 'Error' in rv:
            st.error("{}".format(rv))
            return False
    return True
示例#13
0
def warn(fmt, *args):
    st.warn(fmt % args)
示例#14
0
def test_ft_l3_fwding():
    """
    Testcase : verify the basic L3 traffic validation
    Author : Praveen Kumar Kota <*****@*****.**>
    """
    sub_intf = 0
    operation_tg1 = {
        "openconfig-if-ip:config": {
            "ip": "192.168.1.1",
            "prefix-length": 24
        }
    }
    operation_tg2 = {
        "openconfig-if-ip:config": {
            "ip": "192.168.2.1",
            "prefix-length": 24
        }
    }
    rest_urls = st.get_datastore(vars.D1, "rest_urls")
    url = rest_urls['ip_config'].format(vars.D1T1P1, sub_intf,
                                        data.ip4_addr_t1)
    url2 = rest_urls['ip_config'].format(vars.D1T1P2, sub_intf,
                                         data.ip4_addr_t2)

    config_rest(vars.D1,
                http_method="rest-patch",
                rest_url=url,
                json_data=operation_tg1)
    get_rest(vars.D1, rest_url=url)
    config_rest(vars.D1,
                http_method="rest-patch",
                rest_url=url2,
                json_data=operation_tg2)
    get_rest(vars.D1, rest_url=url2)

    h1 = tg.tg_interface_config(port_handle=tg_handler["tg_ph_1"],
                                mode='config',
                                intf_ip_addr=data.ip4_addr_t1_tg,
                                gateway=data.ip4_addr_t1,
                                src_mac_addr=data.tg_mac1,
                                arp_send_req='1')
    tg.tg_interface_config(port_handle=tg_handler["tg_ph_2"],
                           mode='config',
                           intf_ip_addr=data.ip4_addr_t2_tg,
                           gateway=data.ip4_addr_t2,
                           src_mac_addr=data.tg_mac2,
                           arp_send_req='1')
    res = tgapi.verify_ping(src_obj=tg,
                            port_handle=tg_handler["tg_ph_1"],
                            dev_handle=h1['handle'],
                            dst_ip=data.ip4_addr_t2_tg,
                            ping_count='1',
                            exp_count='1')
    if res:
        st.log("Ping succeeded.")
    else:
        st.warn("Ping failed.")
    dut_rt_int_mac1 = basic_obj.get_ifconfig_ether(vars.D1, vars.D1T1P1)
    tr1 = tg.tg_traffic_config(port_handle=tg_handler["tg_ph_1"], mode='create', transmit_mode='single_burst',
                               pkts_per_burst=1000, length_mode='fixed', rate_pps=1000, l3_protocol='ipv4', mac_src=data.tg_mac1, \
                               mac_dst=dut_rt_int_mac1, ip_src_addr=data.ip4_addr_t1_tg, ip_dst_addr=data.ip4_addr_t2_tg)
    ifapi.clear_interface_counters(vars.D1, interface_type="all")
    ifapi.show_interface_counters_all(vars.D1)
    tg.tg_traffic_control(action='run', stream_handle=tr1['stream_id'])
    st.wait(2)
    tg.tg_traffic_control(action='stop', stream_handle=tr1['stream_id'])
    st.wait(2)
    ifapi.show_interface_counters_all(vars.D1)
    tg_1_stats = tgapi.get_traffic_stats(tg,
                                         mode='aggregate',
                                         port_handle=tg_handler["tg_ph_1"])
    tg_2_stats = tgapi.get_traffic_stats(tg,
                                         mode='aggregate',
                                         port_handle=tg_handler["tg_ph_2"])
    counter1 = tg_2_stats.rx.total_packets
    counter2 = tg_1_stats.tx.total_packets
    if not counter1 >= counter2:
        ifapi.show_interface_counters_all(vars.D1)
        st.report_fail("test_case_failed")
    st.report_pass("test_case_passed")