Exemple #1
0
def run_monitor(devices, setup_params, refs, duts, monitors, seconds=None):
    try:
        air_monitor = []
        output = "\n\tPCAP files:\n"
        # setup log dir
        local_log_dir = setup_params['local_log_dir']

        # add/run monitors if requested
        air_monitors = monitor.create(devices, setup_params, refs, duts,
                                      monitors)
        for air_monitor in air_monitors:
            monitor.setup(air_monitor)
            monitor.run(air_monitor, setup_params)
            logger.warning(air_monitor.name + " - monitor started ...")

        if seconds != None:
            time.sleep(int(seconds))
        else:
            input("\tPress Enter to end capturing...")

        # destroy monitor / get pcap
        monitor.destroy(devices, air_monitors)
        for air_monitor in air_monitors:
            for log in air_monitor.logs:
                head, tail = os.path.split(log)
                output = output + "\t" + local_log_dir + "/" + tail + "\n"
            air_monitor.get_logs(local_log_dir)
        return output
    except:
        for air_monitor in air_monitors:
            monitor.destroy(devices, air_monitors)
            air_monitor.get_logs(local_log_dir)
        raise
Exemple #2
0
def test_example(devices, setup_params, refs, duts, monitors):
    """TC example - simple connect and ping test"""
    try:
        sta = None
        ap = None
        hapd = None
        wpas = None
        mon = None

        # get hosts based on name
        sta = rutils.get_host(devices, duts[0])
        ap = rutils.get_host(devices, refs[0])

        # setup log dir
        local_log_dir = setup_params['local_log_dir']

        # setup hw before test
        rutils.setup_hw([sta, ap], setup_params)

        # run traces if requested
        rutils.trace_start([sta], setup_params)

        # run perf if requested
        rutils.perf_start([sta], setup_params)

        # run hostapd/wpa_supplicant
        rutils.run_wpasupplicant(sta, setup_params)
        rutils.run_hostapd(ap, setup_params)

        # get ap_params
        ap_params = rutils.get_ap_params(channel="1",
                                         bw="HT20",
                                         country="US",
                                         security="open")

        # Add monitors if requested
        monitor_hosts = monitor.create(devices, setup_params, refs, duts,
                                       monitors)
        if len(monitor_hosts) > 0:
            mon = monitor_hosts[0]
        monitor.add(sta, monitors)
        monitor.add(ap, monitors)

        # connect to hostapd/wpa_supplicant UDP CTRL iface
        hapd = hostapd.add_ap(ap.dev, ap_params)
        freq = hapd.get_status_field("freq")
        wpas = WpaSupplicant(hostname=sta.host,
                             global_iface="udp",
                             global_port=sta.port)
        wpas.interface_add(sta.ifname)

        # setup standalone monitor based on hapd; could be multi interface
        # monitor
        monitor_param = monitor.get_monitor_params(hapd)
        monitor.setup(mon, [monitor_param])

        # run monitors
        monitor.run(sta, setup_params)
        monitor.run(ap, setup_params)
        monitor.run(mon, setup_params)

        # connect wpa_supplicant to hostapd
        wpas.connect(ap_params['ssid'], key_mgmt="NONE", scan_freq=freq)

        # run ping test
        ap_sta, sta_ap = rutils.check_connectivity(ap, sta, "ipv6")

        # remove/destroy monitors
        monitor.remove(sta)
        monitor.remove(ap)
        monitor.destroy(devices, monitor_hosts)

        # hostapd/wpa_supplicant cleanup
        wpas.interface_remove(sta.ifname)
        wpas.terminate()

        hapd.close_ctrl()
        hostapd.remove_bss(ap.dev)
        hostapd.terminate(ap.dev)

        # stop perf
        rutils.perf_stop([sta], setup_params)

        # stop traces
        rutils.trace_stop([sta], setup_params)

        # get wpa_supplicant/hostapd/tshark logs
        sta.get_logs(local_log_dir)
        ap.get_logs(local_log_dir)
        if mon:
            mon.get_logs(local_log_dir)

        return "packet_loss: " + ap_sta + ", " + sta_ap
    except:
        rutils.perf_stop([sta], setup_params)
        rutils.trace_stop([sta], setup_params)
        if wpas:
            try:
                wpas.interface_remove(sta.ifname)
                wpas.terminate()
            except:
                pass
        if hapd:
            try:
                hapd.close_ctrl()
                hostapd.remove_bss(ap.dev)
                hostapd.terminate(ap.dev)
            except:
                pass
        if mon:
            monitor.destroy(devices, monitor_hosts)
            mon.get_logs(local_log_dir)

        if sta:
            monitor.remove(sta)
            dmesg = setup_params['log_dir'] + setup_params[
                'tc_name'] + "_" + sta.name + "_" + sta.ifname + ".dmesg"
            sta.execute(["dmesg", "-c", ">", dmesg])
            sta.add_log(dmesg)
            sta.get_logs(local_log_dir)
            sta.execute(["ifconfig", sta.ifname, "down"])
        if ap:
            monitor.remove(ap)
            dmesg = setup_params['log_dir'] + setup_params[
                'tc_name'] + "_" + ap.name + "_" + ap.ifname + ".dmesg"
            ap.execute(["dmesg", "-c", ">", dmesg])
            ap.add_log(dmesg)
            ap.get_logs(local_log_dir)
            ap.execute(["ifconfig", ap.ifname, " down"])
        raise
def run_hwsim_test(devices, setup_params, refs, duts, monitors, hwsim_test):
    try:
        ref_hosts = []
        dut_hosts = []
        dev = []
        apdev = []

        # get hosts
        for ref in refs:
            ref_host = rutils.get_host(devices, ref)
            ref_hosts.append(ref_host)
        for dut in duts:
            dut_host = rutils.get_host(devices, dut)
            dut_hosts.append(dut_host)

        # setup log dir
        local_log_dir = setup_params['local_log_dir']

        # setup hw before test
        rutils.setup_hw(ref_hosts, setup_params)
        rutils.setup_hw(dut_hosts, setup_params)

        # run monitors if requested/possible
        for ref_host in ref_hosts:
            monitor.add(ref_host, monitors)
            monitor.run(ref_host, setup_params)
        for dut_host in dut_hosts:
            monitor.add(dut_host, monitors)
            monitor.run(dut_host, setup_params)

        monitor_hosts = monitor.create(devices, setup_params, refs, duts,
                                       monitors)
        mon = None
        if len(monitor_hosts) > 0:
            mon = monitor_hosts[0]
            wlantest.Wlantest.reset_remote_wlantest()
            wlantest.Wlantest.register_remote_wlantest(mon, setup_params,
                                                       monitor)

        # run hostapd/wpa_supplicant
        for ref_host in ref_hosts:
            rutils.run_wpasupplicant(ref_host, setup_params)
            wpas = WpaSupplicant(hostname=ref_host.host, global_iface="udp",
                                 global_port=ref_host.port)
            wpas.interface_add(ref_host.ifname)
            dev.append(wpas)
        for dut_host in dut_hosts:
            rutils.run_hostapd(dut_host, setup_params)
            dut_host.dev['bssid'] = rutils.get_mac_addr(dut_host)
            apdev.append(dut_host.dev)

        # run hwsim test/currently only 2 params tests
        if hwsim_test.func_code.co_argcount == 1:
            hwsim_test(dev)
        elif hwsim_test.func_code.co_argcount == 2:
            hwsim_test(dev, apdev)
        else:
            raise Exception("more than 2 arguments required")

       # hostapd/wpa_supplicant cleanup
        for wpas in dev:
            wpas.interface_remove(wpas.host.ifname)
            wpas.terminate()
        dev = []

        # remove monitors
        for ref_host in ref_hosts:
            monitor.remove(ref_host)
        for dut_host in dut_hosts:
            monitor.remove(dut_host)

        for ref_host in ref_hosts:
            ref_host.execute(["killall", "wpa_supplicant"])
            ref_host.get_logs(local_log_dir)
        for dut_host in dut_hosts:
            dut_host.execute(["killall", "hostapd"])
            dut_host.get_logs(local_log_dir)
        if mon is not None:
            wlantest.Wlantest.reset_remote_wlantest()
            mon.get_logs(local_log_dir)

        return ""
    except:
        logger.info(traceback.format_exc())
        for wpas in dev:
            try:
                wpas.interface_remove(wpas.host.ifname)
                wpas.terminate()
            except:
                pass

        for ref_host in ref_hosts:
            monitor.remove(ref_host)
        for dut_host in dut_hosts:
            monitor.remove(dut_host)

        for ref_host in ref_hosts:
            ref_host.execute(["killall", "wpa_supplicant"])
            ref_host.get_logs(local_log_dir)
        for dut_host in dut_hosts:
            dut_host.execute(["killall", "hostapd"])
            dut_host.get_logs(local_log_dir)
        if mon is not None:
            wlantest.Wlantest.reset_remote_wlantest()
            mon.get_logs(local_log_dir)
        raise
Exemple #4
0
def run_hwsim_test(devices, setup_params, refs, duts, monitors, hwsim_test):
    try:
        ref_hosts = []
        dut_hosts = []
        dev = []
        apdev = []

        # get hosts
        for ref in refs:
            ref_host = rutils.get_host(devices, ref)
            ref_hosts.append(ref_host)
        for dut in duts:
            dut_host = rutils.get_host(devices, dut)
            dut_hosts.append(dut_host)

        # setup log dir
        local_log_dir = setup_params['local_log_dir']

        # setup hw before test
        rutils.setup_hw(ref_hosts, setup_params)
        rutils.setup_hw(dut_hosts, setup_params)

        # run monitors if requested/possible
        for ref_host in ref_hosts:
            monitor.add(ref_host, monitors)
            monitor.run(ref_host, setup_params)
        for dut_host in dut_hosts:
            monitor.add(dut_host, monitors)
            monitor.run(dut_host, setup_params)

        monitor_hosts = monitor.create(devices, setup_params, refs, duts,
                                       monitors)
        mon = None
        if len(monitor_hosts) > 0:
            mon = monitor_hosts[0]
            wlantest.Wlantest.reset_remote_wlantest()
            wlantest.Wlantest.register_remote_wlantest(mon, setup_params,
                                                       monitor)

        # run hostapd/wpa_supplicant
        for ref_host in ref_hosts:
            rutils.run_wpasupplicant(ref_host, setup_params)
            wpas = WpaSupplicant(hostname=ref_host.host,
                                 global_iface="udp",
                                 global_port=ref_host.port)
            wpas.interface_add(ref_host.ifname)
            dev.append(wpas)
        for dut_host in dut_hosts:
            rutils.run_hostapd(dut_host, setup_params)
            dut_host.dev['bssid'] = rutils.get_mac_addr(dut_host)
            apdev.append(dut_host.dev)

        if hwsim_test.__code__.co_argcount == 1:
            hwsim_test(dev)
        elif hwsim_test.__code__.co_argcount == 2:
            hwsim_test(dev, apdev)
        else:
            params = {}
            params['long'] = 1
            params['logdir'] = local_log_dir
            hwsim_test(dev, apdev, params)

    # hostapd/wpa_supplicant cleanup
        for wpas in dev:
            wpas.interface_remove(wpas.host.ifname)
            wpas.terminate()
        dev = []

        # remove monitors
        for ref_host in ref_hosts:
            monitor.remove(ref_host)
        for dut_host in dut_hosts:
            monitor.remove(dut_host)

        for ref_host in ref_hosts:
            rutils.kill_wpasupplicant(ref_host, setup_params)
            ref_host.get_logs(local_log_dir)
        for dut_host in dut_hosts:
            rutils.kill_hostapd(dut_host, setup_params)
            dut_host.get_logs(local_log_dir)
        if mon is not None:
            wlantest.Wlantest.reset_remote_wlantest()
            mon.get_logs(local_log_dir)

        return ""
    except:
        logger.info(traceback.format_exc())
        for wpas in dev:
            try:
                wpas.interface_remove(wpas.host.ifname)
                wpas.terminate()
            except:
                pass

        for ref_host in ref_hosts:
            monitor.remove(ref_host)
        for dut_host in dut_hosts:
            monitor.remove(dut_host)

        for ref_host in ref_hosts:
            rutils.kill_wpasupplicant(ref_host, setup_params)
            ref_host.get_logs(local_log_dir)
        for dut_host in dut_hosts:
            rutils.kill_hostapd(dut_host, setup_params)
            dut_host.get_logs(local_log_dir)
        if mon is not None:
            wlantest.Wlantest.reset_remote_wlantest()
            mon.get_logs(local_log_dir)
        raise
def test_example(devices, setup_params, refs, duts, monitors):
    """TC example - simple connect and ping test"""
    try:
        sta = None
        ap = None
        hapd = None
        wpas = None
        mon = None

        # get hosts based on name
        sta = rutils.get_host(devices, duts[0])
        ap = rutils.get_host(devices, refs[0])

        # setup log dir
        local_log_dir = setup_params['local_log_dir']

        # setup hw before test
        rutils.setup_hw([sta, ap], setup_params)

        # run traces if requested
        rutils.trace_start([sta], setup_params)

        # run perf if requested
        rutils.perf_start([sta], setup_params)

        # run hostapd/wpa_supplicant
        rutils.run_wpasupplicant(sta, setup_params)
        rutils.run_hostapd(ap, setup_params)

        # get ap_params
        ap_params = rutils.get_ap_params(channel="1", bw="HT20", country="US",
                                         security="open")

        # Add monitors if requested
        monitor_hosts = monitor.create(devices, setup_params, refs, duts,
                                       monitors)
        if len(monitor_hosts) > 0:
            mon = monitor_hosts[0]
        monitor.add(sta, monitors)
        monitor.add(ap, monitors)

        # connect to hostapd/wpa_supplicant UDP CTRL iface
        hapd = hostapd.add_ap(ap.dev, ap_params)
        freq = hapd.get_status_field("freq")
        wpas = WpaSupplicant(hostname = sta.host, global_iface="udp",
                             global_port = sta.port)
        wpas.interface_add(sta.ifname)

        # setup standalone monitor based on hapd; could be multi interface
        # monitor
        monitor_param = monitor.get_monitor_params(hapd)
        monitor.setup(mon, [monitor_param])

        # run monitors
        monitor.run(sta, setup_params)
        monitor.run(ap, setup_params)
        monitor.run(mon, setup_params)

        # connect wpa_supplicant to hostapd
        wpas.connect(ap_params['ssid'], key_mgmt="NONE", scan_freq=freq)

        # run ping test
        ap_sta, sta_ap = rutils.check_connectivity(ap, sta, "ipv6")

        # remove/destroy monitors
        monitor.remove(sta)
        monitor.remove(ap)
        monitor.destroy(devices, monitor_hosts)

        # hostapd/wpa_supplicant cleanup
        wpas.interface_remove(sta.ifname)
        wpas.terminate()

        hapd.close_ctrl()
        hostapd.remove_bss(ap.dev)
        hostapd.terminate(ap.dev)

        # stop perf
        rutils.perf_stop([sta], setup_params)

        # stop traces
        rutils.trace_stop([sta], setup_params)

        # get wpa_supplicant/hostapd/tshark logs
        sta.get_logs(local_log_dir)
        ap.get_logs(local_log_dir)
        if mon:
            mon.get_logs(local_log_dir)

        return "packet_loss: " + ap_sta + ", " + sta_ap
    except:
        rutils.perf_stop([sta], setup_params)
        rutils.trace_stop([sta], setup_params)
        if wpas:
            try:
                wpas.interface_remove(sta.ifname)
                wpas.terminate()
            except:
                pass
        if hapd:
            try:
                hapd.close_ctrl()
                hostapd.remove_bss(ap.dev)
                hostapd.terminate(ap.dev)
            except:
                pass
        if mon:
            monitor.destroy(devices, monitor_hosts)
            mon.get_logs(local_log_dir)

        if sta:
            monitor.remove(sta)
            dmesg = setup_params['log_dir'] + setup_params['tc_name'] + "_" + sta.name + "_" + sta.ifname + ".dmesg"
            sta.execute(["dmesg", "-c", ">", dmesg])
            sta.add_log(dmesg)
            sta.get_logs(local_log_dir)
            sta.execute(["ifconfig", sta.ifname, "down"])
        if ap:
            monitor.remove(ap)
            dmesg = setup_params['log_dir'] + setup_params['tc_name'] + "_" + ap.name + "_" + ap.ifname + ".dmesg"
            ap.execute(["dmesg", "-c", ">", dmesg])
            ap.add_log(dmesg)
            ap.get_logs(local_log_dir)
            ap.execute(["ifconfig", ap.ifname, " down"])
        raise