Exemplo n.º 1
0
class RunIperf(DeviceTestStepBase):
    def __init__(self, tc_conf, global_conf, ts_conf, factory):
        DeviceTestStepBase.__init__(self, tc_conf, global_conf, ts_conf, factory)
        self.server_object = None
        self.networking_api = self._device.get_uecmd("Networking")
        self.svr_networking_api = None
        self.equip_mgr = EquipmentManager()
        self.device_mgr = DeviceManager()
        self._iperf_settings = None

    def run(self, context):
        """
        Runs the test step

        @type context: TestStepContext
        @param context: test case context
        """
        DeviceTestStepBase.run(self, context)

        runtime_seconds = self._pars.duration * 60
        server_address = "none"
        if self._pars.iperf_protocol == "tcp":
            port_num = 5001
        else:
            port_num = 5009

        # prepare setup the IPERF test.
        self._iperf_settings = {"duration": runtime_seconds,
                                "protocol": self._pars.iperf_protocol,
                                "port_number": port_num,
                                "direction": self._pars.direction,
                                "parallel_thread": self._pars.nr_of_threads}

        bench_config = self._global_conf.benchConfig.get_dict()
        if self._pars.server_name not in bench_config.keys():
            # the indicated equipment or phone is NOT declared in the current bench config
            raise Exception("")

        # check in the bench config what is the kind of given server
        eqt_param = self._global_conf.benchConfig.get_parameters(self._pars.server_name)
        eqt_param_dict = eqt_param.get_dict()
        if "Model" in eqt_param_dict.keys():
            # server is an equipment
            eqt_param_dict = eqt_param.get_param_value("Model")
            if "REMOTE_COMPUTER" in eqt_param_dict:
                # remote computer, get the IP parameter
                server_address = eqt_param.get_param_value("IP")
                self._iperf_settings["computer"] = self.equip_mgr.get_computer(self._pars.server_name)
            elif "COMPUTER" in eqt_param_dict:
                # local computer, nothing to do
                pass
            elif "RS_CMW500" in eqt_param_dict:
                # equipment with Iperf embedded, get the IP_Lan1 parameter
                server_address = eqt_param.get_param_value("IP_Lan1")
                self._iperf_settings["equipment_api"] = \
                    self.equip_mgr.get_cellular_network_simulator().get_cell_4g().get_data()
        else:
            # server is a phone
            phone = self.device_mgr.get_device(self._pars.server_name)
            networking_api2 = phone.get_uecmd("Networking")
            self._iperf_settings["networking_api2"] = networking_api2
            if self._pars.server_net_interface is not None:
                server_address = networking_api2.get_interface_ipv4_address(self._pars.server_net_interface)
            else:
                self._logger.warning("No Server net interface provided. Use the DUT net interface")
                server_address = networking_api2.get_interface_ipv4_address(self._pars.net_interface)

        time.sleep(5)
        dut_ip_address = get_dut_ipv4_address(self.networking_api, self._pars.net_interface)
        if self._pars.direction in ("down", "both"):
            self._iperf_settings["server_ip_address"] = dut_ip_address
            self._iperf_settings["bind_host"] = server_address
        else:
            self._iperf_settings["server_ip_address"] = server_address
            self._iperf_settings["bind_host"] = dut_ip_address

        self._logger.info("RunIperf: starting")

        self._logger.info("IPERF parameters:")
        self._logger.info("  server addr: " + server_address)
        self._logger.info("  duration: %d sec" % runtime_seconds)
        self._logger.info("  direction: " + self._pars.direction)
        self._logger.info("  port: %d" % port_num)

        if self._pars.window_size.lower() != "compute":
            self._iperf_settings["server_window_size"] = self._pars.window_size
            self._iperf_settings["client_window_size"] = self._pars.window_size
        if self._pars.no_delay:
            self._iperf_settings["no_delay"] = ''
        if self._pars.iperf_options.lower() != "none":
            self._iperf_settings["extra_options"] = self._pars.iperf_options

        # Run Iperf command
        IperfHandler = IperfExecutionHandler(self._iperf_settings, self._device.get_uecmd("Networking"))
        throughput = IperfHandler.iperf()

        context.set_nested_info([self._pars.measured_throughput, "UL_VALUE"], throughput.ul_throughput.value)
        context.set_nested_info([self._pars.measured_throughput, "DL_VALUE"], throughput.dl_throughput.value)
        context.set_nested_info([self._pars.measured_throughput, "UL_UNITS"], throughput.ul_throughput.unit)
        context.set_nested_info([self._pars.measured_throughput, "DL_UNITS"], throughput.dl_throughput.unit)

        self._logger.info("Start iperf client: finished")
Exemplo n.º 2
0
class GenericSniffer(EquipmentBase, ISniffer):
    def __init__(self, name, model, eqt_params, bench_params):
        """
        Constructor
        """
        # Initialize class parent
        ISniffer.__init__(self)
        EquipmentBase.__init__(self, name, model, eqt_params)

        computer = str(bench_params.get_param_value("Computer"))
        # NOTE: import here to avoid circular dependency on
        # EquipmentManager if imported at top level
        from acs_test_scripts.Equipment.EquipmentManager import EquipmentManager
        self._em = EquipmentManager()
        self._computer = self._em.get_computer(computer)

        self._ssh_process = None
        self._ssh_queue = None
        self._local_out = ""
        self._sniff_ongoing = False
        self._wifi_interface = bench_params.get_param_value("Interface", "")
        if self._wifi_interface == "":
            self._wifi_interface = self._computer.get_wifi_interface()

        self._sniffer_tool_checked = False
        self._sniffer_cmd = "NOT_YET_DEFINED"

    def init(self):
        """
        Initializes the equipment and establishes the connection.
        """
        self.get_logger().info("init")

        # Open connection to sniffer
        self._computer.init(True)

        # Check Sniffer binary tool existence
        self._check_sniffer_tool(self._sniffer_cmd)

        # End all potential ongoing sniffer traces
        self._computer.run_cmd("killall %s" % self._sniffer_cmd)
        self._sniff_ongoing = False

    def release(self):
        """
        Releases equipment resources and close connection.
        """
        self.get_logger().info("release")
        self._computer.release()

    def get_capture_file(self, log_file_name):
        """
        get the capture file and save it
        in the current _Report directory without stopping the capture
        :type log_filename: str
        :param log_filename: pathname of the output capture file
        """
        self._computer.copy_file_in_local_path(self._remote_out, log_file_name)

    def _check_sniffer_tool(self, binary_to_check):
        """
        Check that binary_to_check command is installed on the host computer

        :type binary_to_check: str
        :param binary_to_check: Binary cmd to check if available on the Computer
        """
        if not self._sniffer_tool_checked:

            if self._computer.get_model() == "LOCAL_COMPUTER" \
                    and self._computer.get_os() == self._computer.WINDOWS:
                msg = "Sniffer must be installed on a LOCAL or REMOTE Linux computer"
                self._logger.error(msg)
                raise TestEquipmentException(
                    TestEquipmentException.FEATURE_NOT_IMPLEMENTED, msg)

            out = self._computer.run_cmd("which %s" % binary_to_check)
            if ("/%s" % binary_to_check) not in out["std"]:
                msg = "%s is not available on %s" % (binary_to_check,
                                                     self._computer.get_name())
                self._logger.error(msg)
                raise TestEquipmentException(
                    TestEquipmentException.FEATURE_NOT_IMPLEMENTED, msg)

            self._sniffer_tool_checked = True

    def _build_sniffer_cmd(self,
                           save_sniff_in_ascii=False,
                           dut_mac_addr="",
                           ssid="",
                           filter_option="-R"):
        """
        Build the sniff command

        :type save_sniff_in_ascii: boolean
        :param save_sniff_in_ascii: enable ascii format for sniff logs

        :type dut_mac_addr: str
        :param dut_mac_addr: mac address to filter on

        :type ssid: str
        :param ssid: ssid address to filter on

        :type filter: str
        :param filter: special option for filter (-R or -Y)
        """
        sniff = "%s -i%s -s0 " % (self._sniffer_cmd, self._wifi_interface)

        # Build the sniff_filter
        if dut_mac_addr or ssid:
            sniff_filter = ""
            if dut_mac_addr:
                sniff_filter += 'wlan.addr==%s' % dut_mac_addr
            if dut_mac_addr and ssid:
                sniff_filter += " || "
            if ssid:
                sniff_filter += '(wlan.fc.type_subtype==0x08 && wlan_mgt.ssid=="%s")' % ssid
            sniff += '%s "%s" ' % (filter_option, sniff_filter)

        if save_sniff_in_ascii:
            sniff += '-V > %s' % self._remote_out
        else:
            sniff += "-w%s" % self._remote_out

        return sniff
Exemplo n.º 3
0
class P2pSupplicant(EquipmentBase, IP2pSupplicant):
    """
    Implementation of P2P Client interface
    """
    def __init__(self, name, model, eqt_params, bench_params):
        """
        Constructor
        """
        IP2pSupplicant.__init__(self)
        EquipmentBase.__init__(self, name, model, eqt_params)
        computer = str(bench_params.get_param_value("Computer"))
        # NOTE: import here to avoid circular dependency on
        # EquipmentManager if imported at top level
        from acs_test_scripts.Equipment.EquipmentManager import EquipmentManager
        self._em = EquipmentManager()
        self._computer = self._em.get_computer(computer)
        self._p2psupplicant_ongoing = False

        # Get binary and cofiguration file path
        self._wpa_supplicant_bin = posixpath.realpath(
            eqt_params[model]["Binary"])
        self._wpa_p2p_conf = posixpath.realpath(
            eqt_params[model]["Configuration"])

    def start(self, lan_interface):
        """
        Start the P2P Supplicant
        :type lan_interface: str
        :param lan_interface: Lan interface to use
        """
        if self._p2psupplicant_ongoing:
            msg = "Cannot start 2 P2P Supplicant in the same time"
            self.get_logger().error(msg)
            raise TestEquipmentException(
                TestEquipmentException.OPERATION_FAILED, msg)

        self._logger.debug("start_P2P supplicant")

        self._computer.init()
        self._computer.run_cmd("killall wpa_supplicant", 1)

        # Check WPA_Cli existence
        self._computer.check_command("wpa_supplicant")

        # remove the old temporary files
        self._computer.run_cmd("rm -rf /var/run/wpa_supplicant/wlan2")

        self._logger.debug("start wpa_supplicant")

        wpaoutput = self._computer.run_cmd("%s -Dnl80211 -c%s -i %s -dt &> /dev/null &" \
                                           % (self._wpa_supplicant_bin, self._wpa_p2p_conf, lan_interface), 2)
        wpaoutput = wpaoutput["std"]

        if "Failed to initialize wpa_supplicant" in wpaoutput:
            msg = "Failed to initialize "
            self._logger.error(msg)
            raise TestEquipmentException(
                TestEquipmentException.OPERATION_FAILED, msg)

        self._p2psupplicant_ongoing = True

    def stop(self):
        """
        Stop the P2P Supplicant
        """
        if not self._p2psupplicant_ongoing:
            self._logger.warning("P2P Supplicant not started")
            return

        self._logger.debug("Stop P2P Supplicant")

        # clean the supplicant environment
        self._computer.run_cmd("killall wpa_supplicant")
        self._computer.run_cmd("rm -rf /var/run/wpa_supplicant/wlan2")

        self._logger.info("P2P release")
        self._computer.release()

        self._p2psupplicant_ongoing = False
Exemplo n.º 4
0
class P2pClient(EquipmentBase, IP2pClient):
    """
    Implementation of P2P Client interface
    """
    def __init__(self, name, model, eqt_params, bench_params):
        """
        Constructor
        """
        IP2pClient.__init__(self)
        EquipmentBase.__init__(self, name, model, eqt_params)
        computer = str(bench_params.get_param_value("Computer"))
        # NOTE: import here to avoid circular dependency on
        # EquipmentManager if imported at top level
        from acs_test_scripts.Equipment.EquipmentManager import EquipmentManager
        self._em = EquipmentManager()
        self._computer = self._em.get_computer(computer)
        self._lan_interface = ""
        self._p2pclient_ongoing = False

        # Get binary file path
        self._wpa_cli_bin = posixpath.realpath(eqt_params[model]["Binary"])

        self._logger = self.get_logger()

    def init(self):
        """
        Initializes the equipment and establishes the connection.
        """
        self._logger.info("init")

        self._computer.init()

        # Open ssh connection
        self._computer.run_cmd("killall wpa_cli")

        # Check WPA_Cli existence
        self._computer.check_command("wpa_cli")

    def release(self):
        """
        Releases equipment resources and close connection.
        """
        self._logger.info("P2P release")

        self._computer.release()

    def set_lan_interface_ip_address(self, ip_address, timeout):
        """
        Set the interface ip address.
        If the WPA Cli is not run, the SSH connection is use,
        else, a new SSH connection is opened and close just after
        :type ip_address: str
        :param ip_address: the ip address to set on interface
        :type timeout: int
        :param timeout: UNUSED here
        """
        self.stop()
        self._computer.run_cmd(
            "ifconfig " + self._lan_interface + " " + ip_address, 1)

    def start(self, lan_interface):
        """
        Start the P2P Client
        :type lan_interface: str
        :param lan_interface: the interface to connect on (not use)
        :rtype: str
        :return: the P2P Client Mac address
        """
        if self._p2pclient_ongoing:
            msg = "Cannot start 2 P2P Client in the same time"
            self._logger.error(msg)
            raise TestEquipmentException(
                TestEquipmentException.OPERATION_FAILED, msg)

        self._logger.debug("start_P2P client")

        self._lan_interface = ""

        cli2output = self._computer.run_cmd(self._wpa_cli_bin, 2)
        cli2output = cli2output['std']

        if cli2output:
            self._logger.debug("P2P Client start output " + cli2output)

        # Retrieve the LAN interface
        result = re.search(r"Selected interface '(.+)'", cli2output)
        if result is not None:
            self._lan_interface = result.groups()[0]
        self._logger.debug("cli2lan: " + self._lan_interface)
        msg = "Could not connect to wpa_supplicant"
        if msg in cli2output:
            self._logger.error(msg)
            raise TestEquipmentException(
                TestEquipmentException.OPERATION_FAILED, msg)

        # Retrieve the used WPA P2P Client Mac address
        cli2output = self._computer.run_cmd("status", 2)
        cli2output = cli2output['std']
        if cli2output:
            self._logger.debug("wpa_cli2 status output: " + cli2output)

        result = re.search(
            r"p2p_device_address=(([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2})",
            cli2output, re.MULTILINE)
        if result is None:
            msg = "Could not get P2P Client device address"
            self._logger.error(msg)
            raise TestEquipmentException(
                TestEquipmentException.OPERATION_FAILED, msg)
        client_address = result.groups()[0]
        self._logger.debug("cli2address: " + client_address)

        self._p2pclient_ongoing = True
        return client_address

    def stop(self):
        """
        Stop the P2P Client
        """
        if not self._p2pclient_ongoing:
            self._logger.warning("P2P not started")
            return

        self._logger.debug("Stop P2P client")

        # Stop the WPA Client
        self._computer.run_cmd("quit")

        # Kill wpa_cli
        self._computer.run_cmd("killall wpa_cli")

        self._p2pclient_ongoing = False

    def remove_all_network(self):
        """
        remove the remaining p2p groups networks
        """
        if not self._p2pclient_ongoing:
            self._logger.warning("P2P not started")
            return

        self._logger.debug("p2p remove all network...")

        self._computer.run_cmd("remove_network all")
        self._computer.run_cmd("save")

    def find_network(self):
        """
        Find available p2p network
        """
        if not self._p2pclient_ongoing:
            self._logger.warning("P2P not started")
            return

        self._logger.debug("p2p find...")
        self._computer.run_cmd("p2p_find")

    def find_dut(self, dut_mac, timeout):
        """
        Find and listen a DUT in the network list

        :type dut_mac: str
        :param dut_mac: DUT Mac adress to found
        :type timeout: int
        :param timeout: maximum delay (in seconds) to search
        :rtype: str
        :return: None if not found. The Dut name if found
        """
        if not self._p2pclient_ongoing:
            self._logger.warning("P2P not started")
            return

        # search device address and name in p2pfind replies
        self._logger.debug(
            "search device address and name in p2pfind replies...")

        regex_string = "P2P-DEVICE-FOUND.* name='([^']+)' "
        regex = re.compile(regex_string)
        p2p_dest = None

        start = time.time()
        while start + timeout > time.time():
            cli1output = self._computer.read(1)
            if cli1output:
                lines = cli1output.split('\n')
                for line in lines:
                    if dut_mac in line:
                        p2p_dest = regex.search(line)
                        if p2p_dest is not None:
                            p2p_dest = p2p_dest.groups()[0]
                            break
            if p2p_dest is not None:
                break

        if p2p_dest is None:
            self._computer.run_cmd("p2p_stop_find")
            msg = "Could not find device address in p2p_find"
            self._logger.error(msg)
            raise TestEquipmentException(
                TestEquipmentException.OPERATION_FAILED, msg)

        self._logger.debug("p2p destination: " + p2p_dest)

        return p2p_dest

    def stop_find(self):
        """
        Stop the P2P find
        """
        if not self._p2pclient_ongoing:
            self._logger.warning("P2P not started")
            return

        self._logger.debug("p2p stop find...")

        self._computer.run_cmd("p2p_stop_find")

    def listen(self):
        """
        Enable the P2p listen mode
        """
        if not self._p2pclient_ongoing:
            self._logger.warning("P2P not started")
            return

        self._logger.debug("p2p listen...")

        self._computer.run_cmd("p2p_listen")

    def set_listen_channel(self, channel):
        """
        Set the P2p listen channel
        :type channel: int
        :param channel: channel to set
        """
        if not self._p2pclient_ongoing:
            self._logger.warning("P2P not started")
            return

        self._logger.debug("set p2p listen channel: " + str(channel))

        self._computer.run_cmd("set p2p_listen_channel " + str(channel))

    def set_device_name(self, name):
        """
        Set the P2p device name
        :type name: str
        :param name: the device name
        """
        if not self._p2pclient_ongoing:
            self._logger.warning("P2P not started")
            return

        self._logger.debug("set p2p device name: " + name)

        self._computer.run_cmd("set device_name " + name)

    def connect_pbc(self,
                    dut_mac,
                    go_intent,
                    persistent=False,
                    frequency=2412):
        """
        Launch a connection to the DUT or accept a connection from the DUT on PBC mode.

        :type dut_mac: str
        :param dut_mac: DUT Mac adress to found
        :type go_intent: integer
        :param go_intent: the local WPA Cli Go value (0 to 15)
        :type persistent: boolean
        :param persistent: persistent connection
        :type frequency: integer
        :param frequency: connection frequency
        """
        if not self._p2pclient_ongoing:
            self._logger.warning("P2P not started")
            return

        self._logger.debug("p2p connect_pbc...")

        persistence = ""
        if persistent:
            persistence = "persistent "

        self._computer.run_cmd("p2p_connect " + dut_mac + " pbc " + persistence + \
                               " go_intent=" + str(go_intent) + " freq=" + str(frequency))

    def connect_pin_display(self,
                            dut_mac,
                            go_intent,
                            persistent=False,
                            frequency=2412):
        """
        Launch a connection to the DUT with PIN request mode.

        :type dut_mac: str
        :param dut_mac: DUT Mac adress to found
        :type go_intent: integer
        :param go_intent: the local WPA Cli Go value (0 to 15)
        :type persistent: boolean
        :param persistent: persistent connection
        :type frequency: integer
        :param frequency: connection frequency
        :rtype: str
        :return: The Pin code
        """
        if not self._p2pclient_ongoing:
            self._logger.warning("P2P not started")
            return

        self._logger.debug("p2p connect_pin_display...")

        persistence = ""
        if persistent:
            persistence = "persistent "

        cli1output = self._computer.run_cmd("p2p_connect " + dut_mac + " pin display " + persistence + \
                                            "go_intent=" + str(go_intent) + " freq=" + str(frequency), 3)
        cli1output = cli1output['std']

        pincode = cli1output.split('\n')
        if len(pincode) < 2:
            msg = "could not get pin code from device"
            self._logger.error(msg)
            raise TestEquipmentException(
                TestEquipmentException.OPERATION_FAILED, msg)

        self._logger.debug("client pin code: " + pincode)
        pincode = pincode[1].strip()

        return pincode

    def connect_pin_enter(self,
                          dut_mac,
                          pin_code,
                          go_intent,
                          persistent=False,
                          frequency=2412):
        """
        Accept a connection from the DUT on PIN request mode.

        :type dut_mac: str
        :param dut_mac: DUT Mac adress to found
        :type pin_code: str
        :param pin_code: The pin code to connect
        :type go_intent: integer
        :param go_intent: the local WPA Cli Go value (0 to 15)
        :type persistent: boolean
        :param persistent: persistent connection
        :type frequency: integer
        :param frequency: connection frequency
        """
        if not self._p2pclient_ongoing:
            self._logger.warning("P2P not started")
            return

        self._logger.debug("p2p connect_pin_enter...")

        persistence = ""
        if persistent:
            persistence = "persistent "

        self._computer.run_cmd("p2p_connect " + dut_mac + " " + pin_code + " keypad " + persistence + \
                               "go_intent=" + str(go_intent) + " freq=" + str(frequency))

    def disconnect(self):
        """
        disconnect the other DUT
        """
        if not self._p2pclient_ongoing:
            self._logger.warning("P2P not started")
            return

        if self._lan_interface is not None:
            self._logger.debug("p2p p2p_group_remove " + self._lan_interface)
            self._computer.run_cmd("p2p_group_remove " + self._lan_interface)