def run_once(self):
        """Sets up a router, connects to it, pings it, and repeats."""
        configuration = hostap_config.HostapConfig(
            channel=self.PROBE_RESPONSE_TEST_CHANNEL,
            mode=hostap_config.HostapConfig.MODE_11B)
        self.context.router.require_capabilities(
            [site_linux_system.LinuxSystem.CAPABILITY_SEND_MANAGEMENT_FRAME])

        self.context.configure(configuration)
        # Configure 2nd AP to inject the malformed probe responses.
        self.context.configure(configuration, multi_interface=True)
        client_mac = self.context.client.wifi_mac

        pretest_reset_count = self.context.client.get_num_card_resets()
        logging.debug('pretest_reset_count=%d', pretest_reset_count)
        self.context.capture_host.start_capture(
            configuration.frequency,
            ht_type=configuration.ht_packet_capture_mode)
        assoc_params = xmlrpc_datatypes.AssociationParameters()
        assoc_params.ssid = self.context.router.get_ssid(instance=0)
        self.context.assert_connect_wifi(assoc_params)
        start_time = time.time()
        rx_probe_resp_count = 0
        with self.context.client.assert_no_disconnects():
            with frame_sender.FrameSender(
                    self.context.router,
                    'probe_response',
                    self.PROBE_RESPONSE_TEST_CHANNEL,
                    ssid_prefix='TestingProbes',
                    num_bss=1,
                    frame_count=0,
                    delay=self.PROBE_RESPONSE_DELAY_MSEC,
                    dest_addr=client_mac,
                    probe_resp_footer='\xdd\xb7\x00\x1a\x11\x01\x01\x02\x03',
                    instance=1):
                while time.time() - start_time < self.SCAN_LOOP_SEC:
                    bss_list = self.context.client.iw_runner.scan(
                        self.context.client.wifi_if, [2412]) or []
                    for bss in bss_list:
                        logging.debug('found bss: %s', bss.ssid)
                        if bss.ssid == 'TestingProbes00000000':
                            rx_probe_resp_count += 1
                    time.sleep(self.SCAN_LOOP_SLEEP_SEC)
                else:
                    logging.debug('done scanning for networks')

        logging.debug('received %s probe_responses', rx_probe_resp_count)
        if rx_probe_resp_count == 0:
            raise error.TestFail('Client failed to receive probe responses')

        reset_count = self.context.client.get_num_card_resets()
        logging.debug('reset count = %s', reset_count)
        test_resets = reset_count - pretest_reset_count
        if test_resets < 0:
            logging.debug('logs rotated during test')
            if reset_count > 0:
                test_resets = reset_count

        if test_resets > 0:
            raise error.TestFail('Client reset card')
        self.context.client.shill.disconnect(assoc_params.ssid)
        self.context.router.deconfig()
        self.context.capture_host.stop_capture()
    def _channel_dwell_time_test(self, single_channel):
        """Perform test to determine channel dwell time.

        This function invoke FrameSender to continuously send beacon frames
        for specific number of BSSs with specific delay, the SSIDs of the
        BSS are in hex numerical order. And at the same time, perform wifi scan
        on the DUT. The index in the SSIDs of the scan result will be used to
        interpret the relative start time and end time of the channel scan.

        @param single_channel: bool perform single channel scan if true.

        @return int dwell time in ms.

        """
        dwell_time = 0
        channel = hostap_config.HostapConfig.get_channel_for_frequency(
            self.FREQUENCY_MHZ)
        self.context.router.start_capture(self.FREQUENCY_MHZ)
        ssid_prefix = self._build_ssid_prefix()

        with frame_sender.FrameSender(self.context.router,
                                      'beacon',
                                      channel,
                                      ssid_prefix=ssid_prefix,
                                      num_bss=self.NUM_BSS,
                                      frame_count=0,
                                      delay=self.DELAY_INTERVAL_MILLISECONDS):
            if single_channel:
                frequencies = [self.FREQUENCY_MHZ]
            else:
                frequencies = []
            # Perform scan
            start_time = time.time()
            while time.time() - start_time < self.SCAN_RETRY_TIMEOUT_SECONDS:
                bss_list = self.context.client.iw_runner.scan(
                    self.context.client.wifi_if, frequencies=frequencies)

                if bss_list is not None:
                    break

                time.sleep(0.5)
            else:
                raise error.TestFail('Unable to trigger scan on client.')
            if not bss_list:
                raise error.TestFail('Failed to find any BSS')

            # Remaining work is done outside the FrameSender
            # context. This is to ensure that no additional frames are
            # transmitted while we're waiting for the packet capture
            # to complete.

        pcap_path = self.context.router.stop_capture()[0].local_pcap_path

        # Filter scan result based on ssid prefix to remove any cached
        # BSSs from previous run.
        result_list = [
            bss.ssid for bss in bss_list if bss.ssid.startswith(ssid_prefix)
        ]
        if result_list is None:
            raise error.TestFail('Failed to find any BSS for this test')

        beacon_frames = tcpdump_analyzer.get_frames(
            pcap_path,
            tcpdump_analyzer.WLAN_BEACON_ACCEPTOR,
            bad_fcs='include')
        # Filter beacon frames based on ssid prefix.
        result_beacon_frames = [
            beacon_frame for beacon_frame in beacon_frames
            if beacon_frame.ssid.startswith(ssid_prefix)
        ]
        if result_beacon_frames is None:
            raise error.TestFail('Failed to find any beacons for this test')
        return self._get_dwell_time(result_list, result_beacon_frames)