def create_date_path(self, p_dut, pub_session, s_dut, sub_session, sec_type):
        """Create NDP based on the security type(open, PMK, PASSPHRASE), run socket connect

    Args:
        p_dut: Publish device
        p_disc_id: Publisher discovery id
        peer_id_on_pub: peer id on publisher
        s_dut: Subscribe device
        s_disc_id: Subscriber discovery id
        peer_id_on_sub: peer id on subscriber
        sec_type: NDP security type(open, PMK or PASSPHRASE)
        @:return: dict with NDP info
    """

        passphrase = None
        pmk = None

        if sec_type == self.ENCR_TYPE_PASSPHRASE:
            passphrase = self.PASSPHRASE
        if sec_type == self.ENCR_TYPE_PMK:
            pmk = self.PMK

        p_req_key = autils.request_network(
            p_dut,
            p_dut.droid.wifiAwareCreateNetworkSpecifier(pub_session["discId"],
                                                        None,
                                                        passphrase, pmk))
        s_req_key = autils.request_network(
            s_dut,
            s_dut.droid.wifiAwareCreateNetworkSpecifier(sub_session["discId"],
                                                        sub_session["peerId"],
                                                        passphrase, pmk))

        p_net_event_nc = autils.wait_for_event_with_keys(
            p_dut, cconsts.EVENT_NETWORK_CALLBACK, autils.EVENT_NDP_TIMEOUT,
            (cconsts.NETWORK_CB_KEY_EVENT,
             cconsts.NETWORK_CB_CAPABILITIES_CHANGED),
            (cconsts.NETWORK_CB_KEY_ID, p_req_key))
        s_net_event_nc = autils.wait_for_event_with_keys(
            s_dut, cconsts.EVENT_NETWORK_CALLBACK, autils.EVENT_NDP_TIMEOUT,
            (cconsts.NETWORK_CB_KEY_EVENT,
             cconsts.NETWORK_CB_CAPABILITIES_CHANGED),
            (cconsts.NETWORK_CB_KEY_ID, s_req_key))
        p_net_event_lp = autils.wait_for_event_with_keys(
            p_dut, cconsts.EVENT_NETWORK_CALLBACK, autils.EVENT_NDP_TIMEOUT,
            (cconsts.NETWORK_CB_KEY_EVENT,
             cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED),
            (cconsts.NETWORK_CB_KEY_ID, p_req_key))
        s_net_event_lp = autils.wait_for_event_with_keys(
            s_dut, cconsts.EVENT_NETWORK_CALLBACK, autils.EVENT_NDP_TIMEOUT,
            (cconsts.NETWORK_CB_KEY_EVENT,
             cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED),
            (cconsts.NETWORK_CB_KEY_ID, s_req_key))

        p_aware_if = p_net_event_lp["data"][cconsts.NETWORK_CB_KEY_INTERFACE_NAME]
        s_aware_if = s_net_event_lp["data"][cconsts.NETWORK_CB_KEY_INTERFACE_NAME]
        p_if_mac = self.transfer_mac_format(autils.get_mac_addr(p_dut, p_aware_if))
        p_dut.log.info("NDI %s=%s", p_aware_if, p_if_mac)
        s_if_mac = self.transfer_mac_format(autils.get_mac_addr(s_dut, s_aware_if))
        s_dut.log.info("NDI %s=%s", s_aware_if, s_if_mac)

        s_ipv6 = p_net_event_nc["data"][aconsts.NET_CAP_IPV6]
        p_ipv6 = s_net_event_nc["data"][aconsts.NET_CAP_IPV6]
        asserts.assert_true(
            autils.verify_socket_connect(p_dut, s_dut, p_ipv6, s_ipv6, 0),
            "Failed socket link with Pub as Server")
        asserts.assert_true(
            autils.verify_socket_connect(s_dut, p_dut, s_ipv6, p_ipv6, 0),
            "Failed socket link with Sub as Server")

        ndp_info = {"pubReqKey": p_req_key, "pubIfMac": p_if_mac,
                    "subReqKey": s_req_key, "subIfMac": s_if_mac}
        return ndp_info
    def test_oob_ndp_stress(self):
        """Run NDP (NAN data-path) stress test creating and destroying Aware
    attach sessions, discovery sessions, and NDPs."""
        init_dut = self.android_devices[0]
        init_dut.pretty_name = 'Initiator'
        resp_dut = self.android_devices[1]
        resp_dut.pretty_name = 'Responder'

        ndp_init_setup_success = 0
        ndp_init_setup_failures = 0
        ndp_resp_setup_success = 0
        ndp_resp_setup_failures = 0

        for attach_iter in range(self.ATTACH_ITERATIONS):
            init_id = init_dut.droid.wifiAwareAttach(True)
            autils.wait_for_event(init_dut, aconsts.EVENT_CB_ON_ATTACHED)
            init_ident_event = autils.wait_for_event(
                init_dut, aconsts.EVENT_CB_ON_IDENTITY_CHANGED)
            init_mac = init_ident_event['data']['mac']
            time.sleep(self.device_startup_offset)
            resp_id = resp_dut.droid.wifiAwareAttach(True)
            autils.wait_for_event(resp_dut, aconsts.EVENT_CB_ON_ATTACHED)
            resp_ident_event = autils.wait_for_event(
                resp_dut, aconsts.EVENT_CB_ON_IDENTITY_CHANGED)
            resp_mac = resp_ident_event['data']['mac']

            # wait for for devices to synchronize with each other - there are no other
            # mechanisms to make sure this happens for OOB discovery (except retrying
            # to execute the data-path request)
            time.sleep(autils.WAIT_FOR_CLUSTER)

            for ndp_iteration in range(self.NDP_ITERATIONS):
                # Responder: request network
                resp_req_key = autils.request_network(
                    resp_dut,
                    resp_dut.droid.wifiAwareCreateNetworkSpecifierOob(
                        resp_id, aconsts.DATA_PATH_RESPONDER, init_mac, None))

                # Initiator: request network
                init_req_key = autils.request_network(
                    init_dut,
                    init_dut.droid.wifiAwareCreateNetworkSpecifierOob(
                        init_id, aconsts.DATA_PATH_INITIATOR, resp_mac, None))

                # Initiator: wait for network formation
                got_on_available = False
                got_on_link_props = False
                while not got_on_available or not got_on_link_props:
                    try:
                        nc_event = init_dut.ed.pop_event(
                            cconsts.EVENT_NETWORK_CALLBACK,
                            autils.EVENT_NDP_TIMEOUT)
                        if nc_event['data'][
                                cconsts.
                                NETWORK_CB_KEY_EVENT] == cconsts.NETWORK_CB_AVAILABLE:
                            got_on_available = True
                        elif (nc_event['data'][cconsts.NETWORK_CB_KEY_EVENT] ==
                              cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED):
                            got_on_link_props = True
                    except queue.Empty:
                        ndp_init_setup_failures = ndp_init_setup_failures + 1
                        init_dut.log.info(
                            '[Initiator] Timed out while waiting for '
                            'EVENT_NETWORK_CALLBACK')
                        break

                if got_on_available and got_on_link_props:
                    ndp_init_setup_success = ndp_init_setup_success + 1

                # Responder: wait for network formation
                got_on_available = False
                got_on_link_props = False
                while not got_on_available or not got_on_link_props:
                    try:
                        nc_event = resp_dut.ed.pop_event(
                            cconsts.EVENT_NETWORK_CALLBACK,
                            autils.EVENT_NDP_TIMEOUT)
                        if nc_event['data'][
                                cconsts.
                                NETWORK_CB_KEY_EVENT] == cconsts.NETWORK_CB_AVAILABLE:
                            got_on_available = True
                        elif (nc_event['data'][cconsts.NETWORK_CB_KEY_EVENT] ==
                              cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED):
                            got_on_link_props = True
                    except queue.Empty:
                        ndp_resp_setup_failures = ndp_resp_setup_failures + 1
                        init_dut.log.info(
                            '[Responder] Timed out while waiting for '
                            'EVENT_NETWORK_CALLBACK')
                        break

                if got_on_available and got_on_link_props:
                    ndp_resp_setup_success = ndp_resp_setup_success + 1

                # clean-up
                init_dut.droid.connectivityUnregisterNetworkCallback(
                    init_req_key)
                resp_dut.droid.connectivityUnregisterNetworkCallback(
                    resp_req_key)

                # wait before trying another iteration (need to let CM clean-up)
                time.sleep(10)

            # clean-up at end of iteration
            init_dut.droid.wifiAwareDestroy(init_id)
            resp_dut.droid.wifiAwareDestroy(resp_id)

        results = {}
        results['ndp_init_setup_success'] = ndp_init_setup_success
        results['ndp_init_setup_failures'] = ndp_init_setup_failures
        results['ndp_resp_setup_success'] = ndp_resp_setup_success
        results['ndp_resp_setup_failures'] = ndp_resp_setup_failures
        asserts.assert_equal(ndp_init_setup_failures + ndp_resp_setup_failures,
                             0,
                             'test_oob_ndp_stress finished',
                             extras=results)
        asserts.explicit_pass("test_oob_ndp_stress done", extras=results)
Пример #3
0
    def test_max_ndp(self):
        """Validate that the device can create as many NDPs as are specified
    by its capabilities.

    Mechanics:
    - Publisher on DUT (first device)
    - Subscribers on all other devices
    - On discovery set up NDP

    Note: the test requires MAX_NDP + 2 devices to be validated. If these are
    not available the test will fail.
    """
        dut = self.android_devices[0]

        # get max NDP: using first available device (assumes all devices are the
        # same)
        max_ndp = dut.aware_capabilities[aconsts.CAP_MAX_NDP_SESSIONS]

        # get number of attached devices: needs to be max_ndp+2 to allow for max_ndp
        # NDPs + an additional one expected to fail.
        # However, will run the test with max_ndp+1 devices to verify that at least
        # that many NDPs can be created. Will still fail at the end to indicate that
        # full test was not run.
        num_peer_devices = min(len(self.android_devices) - 1, max_ndp + 1)
        asserts.assert_true(
            num_peer_devices >= max_ndp,
            'A minimum of %d devices is needed to run the test, have %d' %
            (max_ndp + 1, len(self.android_devices)))

        # attach
        session_id = dut.droid.wifiAwareAttach()
        autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED)

        # start publisher
        p_disc_id = self.start_discovery_session(
            dut,
            session_id,
            is_publish=True,
            dtype=aconsts.PUBLISH_TYPE_UNSOLICITED,
            service_name=self.SERVICE_NAME,
            expect_success=True)

        # loop over other DUTs
        for i in range(num_peer_devices):
            other_dut = self.android_devices[i + 1]

            # attach
            other_session_id = other_dut.droid.wifiAwareAttach()
            autils.wait_for_event(other_dut, aconsts.EVENT_CB_ON_ATTACHED)

            # start subscriber
            s_disc_id = self.start_discovery_session(
                other_dut,
                other_session_id,
                is_publish=False,
                dtype=aconsts.SUBSCRIBE_TYPE_PASSIVE,
                service_name=self.SERVICE_NAME,
                expect_success=True)

            discovery_event = autils.wait_for_event(
                other_dut, aconsts.SESSION_CB_ON_SERVICE_DISCOVERED)
            peer_id_on_sub = discovery_event['data'][
                aconsts.SESSION_CB_KEY_PEER_ID]

            # Subscriber: send message to peer (Publisher - so it knows our address)
            other_dut.droid.wifiAwareSendMessage(s_disc_id, peer_id_on_sub,
                                                 self.get_next_msg_id(),
                                                 "ping",
                                                 aconsts.MAX_TX_RETRIES)
            autils.wait_for_event(other_dut,
                                  aconsts.SESSION_CB_ON_MESSAGE_SENT)

            # Publisher: wait for received message
            pub_rx_msg_event = autils.wait_for_event(
                dut, aconsts.SESSION_CB_ON_MESSAGE_RECEIVED)
            peer_id_on_pub = pub_rx_msg_event['data'][
                aconsts.SESSION_CB_KEY_PEER_ID]

            # publisher (responder): request network
            p_req_key = autils.request_network(
                dut,
                dut.droid.wifiAwareCreateNetworkSpecifier(
                    p_disc_id, peer_id_on_pub))

            # subscriber (initiator): request network
            s_req_key = autils.request_network(
                other_dut,
                other_dut.droid.wifiAwareCreateNetworkSpecifier(
                    s_disc_id, peer_id_on_sub))

            # wait for network (or not - on the last iteration)
            if i != max_ndp:
                p_net_event = autils.wait_for_event_with_keys(
                    dut, cconsts.EVENT_NETWORK_CALLBACK,
                    autils.EVENT_NDP_TIMEOUT,
                    (cconsts.NETWORK_CB_KEY_EVENT,
                     cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED),
                    (cconsts.NETWORK_CB_KEY_ID, p_req_key))
                s_net_event = autils.wait_for_event_with_keys(
                    other_dut, cconsts.EVENT_NETWORK_CALLBACK,
                    autils.EVENT_NDP_TIMEOUT,
                    (cconsts.NETWORK_CB_KEY_EVENT,
                     cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED),
                    (cconsts.NETWORK_CB_KEY_ID, s_req_key))

                p_aware_if = p_net_event['data'][
                    cconsts.NETWORK_CB_KEY_INTERFACE_NAME]
                s_aware_if = s_net_event['data'][
                    cconsts.NETWORK_CB_KEY_INTERFACE_NAME]
                self.log.info('Interface names: p=%s, s=%s', p_aware_if,
                              s_aware_if)

                p_ipv6 = dut.droid.connectivityGetLinkLocalIpv6Address(
                    p_aware_if).split('%')[0]
                s_ipv6 = other_dut.droid.connectivityGetLinkLocalIpv6Address(
                    s_aware_if).split('%')[0]
                self.log.info('Interface addresses (IPv6): p=%s, s=%s', p_ipv6,
                              s_ipv6)
            else:
                autils.fail_on_event_with_keys(
                    dut, cconsts.EVENT_NETWORK_CALLBACK,
                    autils.EVENT_NDP_TIMEOUT,
                    (cconsts.NETWORK_CB_KEY_EVENT,
                     cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED),
                    (cconsts.NETWORK_CB_KEY_ID, p_req_key))
                autils.fail_on_event_with_keys(
                    other_dut, cconsts.EVENT_NETWORK_CALLBACK,
                    autils.EVENT_NDP_TIMEOUT,
                    (cconsts.NETWORK_CB_KEY_EVENT,
                     cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED),
                    (cconsts.NETWORK_CB_KEY_ID, s_req_key))

        asserts.assert_true(
            num_peer_devices > max_ndp,
            'Needed %d devices to run the test, have %d' %
            (max_ndp + 2, len(self.android_devices)))
Пример #4
0
    def run_end_to_end_latency(self, results, dw_24ghz, dw_5ghz,
                               num_iterations, startup_offset, include_setup):
        """Measure the latency for end-to-end communication link setup:
    - Start Aware
    - Discovery
    - Message from Sub -> Pub
    - Message from Pub -> Sub
    - NDP setup

    Args:
      results: Result array to be populated - will add results (not erase it)
      dw_24ghz: DW interval in the 2.4GHz band.
      dw_5ghz: DW interval in the 5GHz band.
      startup_offset: The start-up gap (in seconds) between the two devices
      include_setup: True to include the cluster setup in the latency
                    measurements.
    """
        key = "dw24_%d_dw5_%d" % (dw_24ghz, dw_5ghz)
        results[key] = {}
        results[key]["num_iterations"] = num_iterations

        p_dut = self.android_devices[0]
        p_dut.pretty_name = "Publisher"
        s_dut = self.android_devices[1]
        s_dut.pretty_name = "Subscriber"

        # override the default DW configuration
        autils.config_power_settings(p_dut, dw_24ghz, dw_5ghz)
        autils.config_power_settings(s_dut, dw_24ghz, dw_5ghz)

        latencies = []

        # allow for failures here since running lots of samples and would like to
        # get the partial data even in the presence of errors
        failures = 0

        if not include_setup:
            # Publisher+Subscriber: attach and wait for confirmation
            p_id = p_dut.droid.wifiAwareAttach(False)
            autils.wait_for_event(p_dut, aconsts.EVENT_CB_ON_ATTACHED)
            time.sleep(startup_offset)
            s_id = s_dut.droid.wifiAwareAttach(False)
            autils.wait_for_event(s_dut, aconsts.EVENT_CB_ON_ATTACHED)

        for i in range(num_iterations):
            while (True):  # for pseudo-goto/finalize
                timestamp_start = time.perf_counter()

                if include_setup:
                    # Publisher+Subscriber: attach and wait for confirmation
                    p_id = p_dut.droid.wifiAwareAttach(False)
                    autils.wait_for_event(p_dut, aconsts.EVENT_CB_ON_ATTACHED)
                    time.sleep(startup_offset)
                    s_id = s_dut.droid.wifiAwareAttach(False)
                    autils.wait_for_event(s_dut, aconsts.EVENT_CB_ON_ATTACHED)

                # start publish
                p_disc_id, p_disc_event = self.start_discovery_session(
                    p_dut, p_id, True, aconsts.PUBLISH_TYPE_UNSOLICITED)

                # start subscribe
                s_disc_id, s_session_event = self.start_discovery_session(
                    s_dut, s_id, False, aconsts.SUBSCRIBE_TYPE_PASSIVE)

                # wait for discovery (allow for failures here since running lots of
                # samples and would like to get the partial data even in the presence of
                # errors)
                try:
                    event = s_dut.ed.pop_event(
                        aconsts.SESSION_CB_ON_SERVICE_DISCOVERED,
                        autils.EVENT_TIMEOUT)
                    s_dut.log.info(
                        "[Subscriber] SESSION_CB_ON_SERVICE_DISCOVERED: %s",
                        event["data"])
                    peer_id_on_sub = event['data'][
                        aconsts.SESSION_CB_KEY_PEER_ID]
                except queue.Empty:
                    s_dut.log.info("[Subscriber] Timed out while waiting for "
                                   "SESSION_CB_ON_SERVICE_DISCOVERED")
                    failures = failures + 1
                    break

                # message from Sub -> Pub
                msg_s2p = "Message Subscriber -> Publisher #%d" % i
                next_msg_id = self.get_next_msg_id()
                s_dut.droid.wifiAwareSendMessage(s_disc_id, peer_id_on_sub,
                                                 next_msg_id, msg_s2p, 0)

                # wait for Tx confirmation
                try:
                    s_dut.ed.pop_event(aconsts.SESSION_CB_ON_MESSAGE_SENT,
                                       autils.EVENT_TIMEOUT)
                except queue.Empty:
                    s_dut.log.info("[Subscriber] Timed out while waiting for "
                                   "SESSION_CB_ON_MESSAGE_SENT")
                    failures = failures + 1
                    break

                # wait for Rx confirmation (and validate contents)
                try:
                    event = p_dut.ed.pop_event(
                        aconsts.SESSION_CB_ON_MESSAGE_RECEIVED,
                        autils.EVENT_TIMEOUT)
                    peer_id_on_pub = event['data'][
                        aconsts.SESSION_CB_KEY_PEER_ID]
                    if (event["data"][aconsts.SESSION_CB_KEY_MESSAGE_AS_STRING]
                            != msg_s2p):
                        p_dut.log.info(
                            "[Publisher] Corrupted input message - %s", event)
                        failures = failures + 1
                        break
                except queue.Empty:
                    p_dut.log.info("[Publisher] Timed out while waiting for "
                                   "SESSION_CB_ON_MESSAGE_RECEIVED")
                    failures = failures + 1
                    break

                # message from Pub -> Sub
                msg_p2s = "Message Publisher -> Subscriber #%d" % i
                next_msg_id = self.get_next_msg_id()
                p_dut.droid.wifiAwareSendMessage(p_disc_id, peer_id_on_pub,
                                                 next_msg_id, msg_p2s, 0)

                # wait for Tx confirmation
                try:
                    p_dut.ed.pop_event(aconsts.SESSION_CB_ON_MESSAGE_SENT,
                                       autils.EVENT_TIMEOUT)
                except queue.Empty:
                    p_dut.log.info("[Publisher] Timed out while waiting for "
                                   "SESSION_CB_ON_MESSAGE_SENT")
                    failures = failures + 1
                    break

                # wait for Rx confirmation (and validate contents)
                try:
                    event = s_dut.ed.pop_event(
                        aconsts.SESSION_CB_ON_MESSAGE_RECEIVED,
                        autils.EVENT_TIMEOUT)
                    if (event["data"][aconsts.SESSION_CB_KEY_MESSAGE_AS_STRING]
                            != msg_p2s):
                        s_dut.log.info(
                            "[Subscriber] Corrupted input message - %s", event)
                        failures = failures + 1
                        break
                except queue.Empty:
                    s_dut.log.info("[Subscriber] Timed out while waiting for "
                                   "SESSION_CB_ON_MESSAGE_RECEIVED")
                    failures = failures + 1
                    break

                # create NDP

                # Publisher: request network
                p_req_key = autils.request_network(
                    p_dut,
                    p_dut.droid.wifiAwareCreateNetworkSpecifier(
                        p_disc_id, peer_id_on_pub, None))

                # Subscriber: request network
                s_req_key = autils.request_network(
                    s_dut,
                    s_dut.droid.wifiAwareCreateNetworkSpecifier(
                        s_disc_id, peer_id_on_sub, None))

                # Publisher & Subscriber: wait for network formation
                try:
                    p_net_event = autils.wait_for_event_with_keys(
                        p_dut, cconsts.EVENT_NETWORK_CALLBACK,
                        autils.EVENT_TIMEOUT,
                        (cconsts.NETWORK_CB_KEY_EVENT,
                         cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED),
                        (cconsts.NETWORK_CB_KEY_ID, p_req_key))
                    s_net_event = autils.wait_for_event_with_keys(
                        s_dut, cconsts.EVENT_NETWORK_CALLBACK,
                        autils.EVENT_TIMEOUT,
                        (cconsts.NETWORK_CB_KEY_EVENT,
                         cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED),
                        (cconsts.NETWORK_CB_KEY_ID, s_req_key))
                except:
                    failures = failures + 1
                    break

                p_aware_if = p_net_event["data"][
                    cconsts.NETWORK_CB_KEY_INTERFACE_NAME]
                s_aware_if = s_net_event["data"][
                    cconsts.NETWORK_CB_KEY_INTERFACE_NAME]

                p_ipv6 = \
                p_dut.droid.connectivityGetLinkLocalIpv6Address(p_aware_if).split("%")[
                  0]
                s_ipv6 = \
                s_dut.droid.connectivityGetLinkLocalIpv6Address(s_aware_if).split("%")[
                  0]

                p_dut.log.info("[Publisher] IF=%s, IPv6=%s", p_aware_if,
                               p_ipv6)
                s_dut.log.info("[Subscriber] IF=%s, IPv6=%s", s_aware_if,
                               s_ipv6)

                latencies.append(time.perf_counter() - timestamp_start)
                break

            # destroy sessions
            p_dut.droid.wifiAwareDestroyDiscoverySession(p_disc_id)
            s_dut.droid.wifiAwareDestroyDiscoverySession(s_disc_id)
            if include_setup:
                p_dut.droid.wifiAwareDestroy(p_id)
                s_dut.droid.wifiAwareDestroy(s_id)

        autils.extract_stats(p_dut,
                             data=latencies,
                             results=results[key],
                             key_prefix="",
                             log_prefix="End-to-End(dw24=%d, dw5=%d)" %
                             (dw_24ghz, dw_5ghz))
        results[key]["failures"] = failures
Пример #5
0
    def run_ndp_oob_latency(self, results, dw_24ghz, dw_5ghz, num_iterations):
        """Runs the NDP setup with OOB (out-of-band) discovery latency test.

    Args:
      results: Result array to be populated - will add results (not erase it)
      dw_24ghz: DW interval in the 2.4GHz band.
      dw_5ghz: DW interval in the 5GHz band.
    """
        key_avail = "on_avail_dw24_%d_dw5_%d" % (dw_24ghz, dw_5ghz)
        key_link_props = "link_props_dw24_%d_dw5_%d" % (dw_24ghz, dw_5ghz)
        results[key_avail] = {}
        results[key_link_props] = {}
        results[key_avail]["num_iterations"] = num_iterations

        init_dut = self.android_devices[0]
        init_dut.pretty_name = 'Initiator'
        resp_dut = self.android_devices[1]
        resp_dut.pretty_name = 'Responder'

        # override the default DW configuration
        autils.config_power_settings(init_dut, dw_24ghz, dw_5ghz)
        autils.config_power_settings(resp_dut, dw_24ghz, dw_5ghz)

        # Initiator+Responder: attach and wait for confirmation & identity
        init_id = init_dut.droid.wifiAwareAttach(True)
        autils.wait_for_event(init_dut, aconsts.EVENT_CB_ON_ATTACHED)
        init_ident_event = autils.wait_for_event(
            init_dut, aconsts.EVENT_CB_ON_IDENTITY_CHANGED)
        init_mac = init_ident_event['data']['mac']
        time.sleep(self.device_startup_offset)
        resp_id = resp_dut.droid.wifiAwareAttach(True)
        autils.wait_for_event(resp_dut, aconsts.EVENT_CB_ON_ATTACHED)
        resp_ident_event = autils.wait_for_event(
            resp_dut, aconsts.EVENT_CB_ON_IDENTITY_CHANGED)
        resp_mac = resp_ident_event['data']['mac']

        # wait for for devices to synchronize with each other - there are no other
        # mechanisms to make sure this happens for OOB discovery (except retrying
        # to execute the data-path request)
        time.sleep(autils.WAIT_FOR_CLUSTER)

        on_available_latencies = []
        link_props_latencies = []
        ndp_setup_failures = 0
        for i in range(num_iterations):
            # Responder: request network
            resp_req_key = autils.request_network(
                resp_dut,
                resp_dut.droid.wifiAwareCreateNetworkSpecifierOob(
                    resp_id, aconsts.DATA_PATH_RESPONDER, init_mac, None))

            # Initiator: request network
            init_req_key = autils.request_network(
                init_dut,
                init_dut.droid.wifiAwareCreateNetworkSpecifierOob(
                    init_id, aconsts.DATA_PATH_INITIATOR, resp_mac, None))

            # Initiator & Responder: wait for network formation
            got_on_available = False
            got_on_link_props = False
            while not got_on_available or not got_on_link_props:
                try:
                    nc_event = init_dut.ed.pop_event(
                        cconsts.EVENT_NETWORK_CALLBACK,
                        autils.EVENT_NDP_TIMEOUT)
                    if nc_event["data"][
                            cconsts.
                            NETWORK_CB_KEY_EVENT] == cconsts.NETWORK_CB_AVAILABLE:
                        got_on_available = True
                        on_available_latencies.append(
                            nc_event["data"][
                                cconsts.NETWORK_CB_KEY_CURRENT_TS] -
                            nc_event["data"][cconsts.NETWORK_CB_KEY_CREATE_TS])
                    elif (nc_event["data"][cconsts.NETWORK_CB_KEY_EVENT] ==
                          cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED):
                        got_on_link_props = True
                        link_props_latencies.append(
                            nc_event["data"][
                                cconsts.NETWORK_CB_KEY_CURRENT_TS] -
                            nc_event["data"][cconsts.NETWORK_CB_KEY_CREATE_TS])
                except queue.Empty:
                    ndp_setup_failures = ndp_setup_failures + 1
                    init_dut.log.info(
                        "[Initiator] Timed out while waiting for "
                        "EVENT_NETWORK_CALLBACK")
                    break

            # clean-up
            init_dut.droid.connectivityUnregisterNetworkCallback(init_req_key)
            resp_dut.droid.connectivityUnregisterNetworkCallback(resp_req_key)

            # wait to make sure previous NDP terminated, otherwise its termination
            # time will be counted in the setup latency!
            time.sleep(2)

        autils.extract_stats(
            init_dut,
            data=on_available_latencies,
            results=results[key_avail],
            key_prefix="",
            log_prefix="NDP setup OnAvailable(dw24=%d, dw5=%d)" %
            (dw_24ghz, dw_5ghz))
        autils.extract_stats(
            init_dut,
            data=link_props_latencies,
            results=results[key_link_props],
            key_prefix="",
            log_prefix="NDP setup OnLinkProperties (dw24=%d, dw5=%d)" %
            (dw_24ghz, dw_5ghz))
        results[key_avail]["ndp_setup_failures"] = ndp_setup_failures
    def run_iperf_max_ndi_aware_only(self, sec_configs, results):
        """Measure iperf performance on multiple NDPs between 2 devices using
    different security configurations (and hence different NDIs). Test with
    Aware enabled and no infrastructure connection - i.e. device is not
    associated to an AP.

    The security configuration can be:
    - None: open
    - String: passphrase
    - otherwise: PMK (byte array)

    Args:
      sec_configs: list of security configurations
      results: Dictionary into which to place test results.
    """
        init_dut = self.android_devices[0]
        init_dut.pretty_name = "Initiator"
        resp_dut = self.android_devices[1]
        resp_dut.pretty_name = "Responder"

        asserts.skip_if(
            init_dut.aware_capabilities[aconsts.CAP_MAX_NDI_INTERFACES] <
            len(sec_configs)
            or resp_dut.aware_capabilities[aconsts.CAP_MAX_NDI_INTERFACES] <
            len(sec_configs),
            "Initiator or Responder do not support multiple NDIs")

        init_id, init_mac = autils.attach_with_identity(init_dut)
        resp_id, resp_mac = autils.attach_with_identity(resp_dut)

        # wait for for devices to synchronize with each other - there are no other
        # mechanisms to make sure this happens for OOB discovery (except retrying
        # to execute the data-path request)
        time.sleep(autils.WAIT_FOR_CLUSTER)

        resp_req_keys = []
        init_req_keys = []
        resp_aware_ifs = []
        init_aware_ifs = []
        resp_aware_ipv6s = []
        init_aware_ipv6s = []

        for sec in sec_configs:
            # Responder: request network
            resp_req_key = autils.request_network(
                resp_dut,
                autils.get_network_specifier(resp_dut, resp_id,
                                             aconsts.DATA_PATH_RESPONDER,
                                             init_mac, sec))
            resp_req_keys.append(resp_req_key)

            # Initiator: request network
            init_req_key = autils.request_network(
                init_dut,
                autils.get_network_specifier(init_dut, init_id,
                                             aconsts.DATA_PATH_INITIATOR,
                                             resp_mac, sec))
            init_req_keys.append(init_req_key)

            # Wait for network
            init_net_event_nc = autils.wait_for_event_with_keys(
                init_dut, cconsts.EVENT_NETWORK_CALLBACK,
                autils.EVENT_NDP_TIMEOUT,
                (cconsts.NETWORK_CB_KEY_EVENT,
                 cconsts.NETWORK_CB_CAPABILITIES_CHANGED),
                (cconsts.NETWORK_CB_KEY_ID, init_req_key))
            resp_net_event_nc = autils.wait_for_event_with_keys(
                resp_dut, cconsts.EVENT_NETWORK_CALLBACK,
                autils.EVENT_NDP_TIMEOUT,
                (cconsts.NETWORK_CB_KEY_EVENT,
                 cconsts.NETWORK_CB_CAPABILITIES_CHANGED),
                (cconsts.NETWORK_CB_KEY_ID, resp_req_key))

            # validate no leak of information
            asserts.assert_false(
                cconsts.NETWORK_CB_KEY_NETWORK_SPECIFIER
                in init_net_event_nc["data"], "Network specifier leak!")
            asserts.assert_false(
                cconsts.NETWORK_CB_KEY_NETWORK_SPECIFIER
                in resp_net_event_nc["data"], "Network specifier leak!")

            # note that Init <-> Resp since IPv6 are of peer's!
            resp_ipv6 = init_net_event_nc["data"][aconsts.NET_CAP_IPV6]
            init_ipv6 = resp_net_event_nc["data"][aconsts.NET_CAP_IPV6]

            init_net_event_lp = autils.wait_for_event_with_keys(
                init_dut, cconsts.EVENT_NETWORK_CALLBACK,
                autils.EVENT_NDP_TIMEOUT,
                (cconsts.NETWORK_CB_KEY_EVENT,
                 cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED),
                (cconsts.NETWORK_CB_KEY_ID, init_req_key))
            resp_net_event_lp = autils.wait_for_event_with_keys(
                resp_dut, cconsts.EVENT_NETWORK_CALLBACK,
                autils.EVENT_NDP_TIMEOUT,
                (cconsts.NETWORK_CB_KEY_EVENT,
                 cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED),
                (cconsts.NETWORK_CB_KEY_ID, resp_req_key))

            resp_aware_ifs.append(resp_net_event_lp["data"][
                cconsts.NETWORK_CB_KEY_INTERFACE_NAME])
            init_aware_ifs.append(init_net_event_lp["data"][
                cconsts.NETWORK_CB_KEY_INTERFACE_NAME])

            resp_aware_ipv6s.append(resp_ipv6)
            init_aware_ipv6s.append(init_ipv6)

        self.log.info("Initiator interfaces/ipv6: %s / %s", init_aware_ifs,
                      init_aware_ipv6s)
        self.log.info("Responder interfaces/ipv6: %s / %s", resp_aware_ifs,
                      resp_aware_ipv6s)

        # create threads, start them, and wait for all to finish
        base_port = 5000
        q = queue.Queue()
        threads = []
        for i in range(len(sec_configs)):
            threads.append(
                threading.Thread(target=self.run_iperf,
                                 args=(q, init_dut, resp_dut,
                                       resp_aware_ifs[i], init_aware_ipv6s[i],
                                       base_port + i)))

        for thread in threads:
            thread.start()

        for thread in threads:
            thread.join()

        # release requests
        for resp_req_key in resp_req_keys:
            resp_dut.droid.connectivityUnregisterNetworkCallback(resp_req_key)
        for init_req_key in init_req_keys:
            init_dut.droid.connectivityUnregisterNetworkCallback(init_req_key)

        # collect data
        for i in range(len(sec_configs)):
            results[i] = {}
            result, data = q.get()
            asserts.assert_true(
                result, "Failure starting/running iperf3 in client mode")
            self.log.debug(pprint.pformat(data))
            data_json = json.loads("".join(data))
            if "error" in data_json:
                asserts.fail("iperf run failed: %s" % data_json["error"],
                             extras=data_json)
            results[i]["tx_rate"] = data_json["end"]["sum_sent"][
                "bits_per_second"]
            results[i]["rx_rate"] = data_json["end"]["sum_received"][
                "bits_per_second"]
            self.log.info("iPerf3: Sent = %d bps Received = %d bps",
                          results[i]["tx_rate"], results[i]["rx_rate"])
Пример #7
0
    def run_oob_ndp_stress(self,
                           attach_iterations,
                           ndp_iterations,
                           trigger_failure_on_index=None):
        """Run NDP (NAN data-path) stress test creating and destroying Aware
    attach sessions, discovery sessions, and NDPs.

    Args:
      attach_iterations: Number of attach sessions.
      ndp_iterations: Number of NDP to be attempted per attach session.
      trigger_failure_on_index: Trigger a failure on this NDP iteration (the
                                mechanism is to request NDP on Initiator
                                before issuing the requeest on the Responder).
                                If None then no artificial failure triggered.
    """
        init_dut = self.android_devices[0]
        init_dut.pretty_name = 'Initiator'
        resp_dut = self.android_devices[1]
        resp_dut.pretty_name = 'Responder'

        ndp_init_setup_success = 0
        ndp_init_setup_failures = 0
        ndp_resp_setup_success = 0
        ndp_resp_setup_failures = 0
        ndp_full_socket_success = 0

        for attach_iter in range(attach_iterations):
            init_id = init_dut.droid.wifiAwareAttach(True)
            autils.wait_for_event(init_dut, aconsts.EVENT_CB_ON_ATTACHED)
            init_ident_event = autils.wait_for_event(
                init_dut, aconsts.EVENT_CB_ON_IDENTITY_CHANGED)
            init_mac = init_ident_event['data']['mac']
            time.sleep(self.device_startup_offset)
            resp_id = resp_dut.droid.wifiAwareAttach(True)
            autils.wait_for_event(resp_dut, aconsts.EVENT_CB_ON_ATTACHED)
            resp_ident_event = autils.wait_for_event(
                resp_dut, aconsts.EVENT_CB_ON_IDENTITY_CHANGED)
            resp_mac = resp_ident_event['data']['mac']

            # wait for for devices to synchronize with each other - there are no other
            # mechanisms to make sure this happens for OOB discovery (except retrying
            # to execute the data-path request)
            time.sleep(autils.WAIT_FOR_CLUSTER)

            for ndp_iteration in range(ndp_iterations):
                if trigger_failure_on_index != ndp_iteration:
                    # Responder: request network
                    resp_req_key = autils.request_network(
                        resp_dut,
                        resp_dut.droid.wifiAwareCreateNetworkSpecifierOob(
                            resp_id, aconsts.DATA_PATH_RESPONDER, init_mac,
                            None))

                    # Wait a minimal amount of time to let the Responder configure itself
                    # and be ready for the request. While calling it first may be
                    # sufficient there are no guarantees that a glitch may slow the
                    # Responder slightly enough to invert the setup order.
                    time.sleep(1)

                    # Initiator: request network
                    init_req_key = autils.request_network(
                        init_dut,
                        init_dut.droid.wifiAwareCreateNetworkSpecifierOob(
                            init_id, aconsts.DATA_PATH_INITIATOR, resp_mac,
                            None))
                else:
                    # Initiator: request network
                    init_req_key = autils.request_network(
                        init_dut,
                        init_dut.droid.wifiAwareCreateNetworkSpecifierOob(
                            init_id, aconsts.DATA_PATH_INITIATOR, resp_mac,
                            None))

                    # Wait a minimal amount of time to let the Initiator configure itself
                    # to guarantee failure!
                    time.sleep(2)

                    # Responder: request network
                    resp_req_key = autils.request_network(
                        resp_dut,
                        resp_dut.droid.wifiAwareCreateNetworkSpecifierOob(
                            resp_id, aconsts.DATA_PATH_RESPONDER, init_mac,
                            None))

                init_ipv6 = None
                resp_ipv6 = None

                # Initiator: wait for network formation
                got_on_available = False
                got_on_link_props = False
                got_on_net_cap = False
                while not got_on_available or not got_on_link_props or not got_on_net_cap:
                    try:
                        nc_event = init_dut.ed.pop_event(
                            cconsts.EVENT_NETWORK_CALLBACK,
                            autils.EVENT_NDP_TIMEOUT)
                        if nc_event['data'][
                                cconsts.
                                NETWORK_CB_KEY_EVENT] == cconsts.NETWORK_CB_AVAILABLE:
                            got_on_available = True
                        elif (nc_event['data'][cconsts.NETWORK_CB_KEY_EVENT] ==
                              cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED):
                            got_on_link_props = True
                        elif (nc_event['data'][cconsts.NETWORK_CB_KEY_EVENT] ==
                              cconsts.NETWORK_CB_CAPABILITIES_CHANGED):
                            got_on_net_cap = True
                            if aconsts.NET_CAP_IPV6 in nc_event["data"]:
                                resp_ipv6 = nc_event["data"][
                                    aconsts.NET_CAP_IPV6]
                    except queue.Empty:
                        ndp_init_setup_failures = ndp_init_setup_failures + 1
                        init_dut.log.info(
                            '[Initiator] Timed out while waiting for '
                            'EVENT_NETWORK_CALLBACK')
                        break

                if got_on_available and got_on_link_props and got_on_net_cap:
                    ndp_init_setup_success = ndp_init_setup_success + 1

                # Responder: wait for network formation
                got_on_available = False
                got_on_link_props = False
                got_on_net_cap = False
                while not got_on_available or not got_on_link_props or not got_on_net_cap:
                    try:
                        nc_event = resp_dut.ed.pop_event(
                            cconsts.EVENT_NETWORK_CALLBACK,
                            autils.EVENT_NDP_TIMEOUT)
                        if nc_event['data'][
                                cconsts.
                                NETWORK_CB_KEY_EVENT] == cconsts.NETWORK_CB_AVAILABLE:
                            got_on_available = True
                        elif (nc_event['data'][cconsts.NETWORK_CB_KEY_EVENT] ==
                              cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED):
                            got_on_link_props = True
                        elif (nc_event['data'][cconsts.NETWORK_CB_KEY_EVENT] ==
                              cconsts.NETWORK_CB_CAPABILITIES_CHANGED):
                            got_on_net_cap = True
                            if aconsts.NET_CAP_IPV6 in nc_event["data"]:
                                init_ipv6 = nc_event["data"][
                                    aconsts.NET_CAP_IPV6]
                    except queue.Empty:
                        ndp_resp_setup_failures = ndp_resp_setup_failures + 1
                        init_dut.log.info(
                            '[Responder] Timed out while waiting for '
                            'EVENT_NETWORK_CALLBACK')
                        break

                if got_on_available and got_on_link_props and got_on_net_cap:
                    ndp_resp_setup_success = ndp_resp_setup_success + 1

                # open sockets to test connection
                if autils.verify_socket_connect(init_dut, resp_dut, init_ipv6,
                                                resp_ipv6, 0):
                    if autils.verify_socket_connect(resp_dut, init_dut,
                                                    resp_ipv6, init_ipv6, 0):
                        ndp_full_socket_success = ndp_full_socket_success + 1

                # clean-up
                init_dut.droid.connectivityUnregisterNetworkCallback(
                    init_req_key)
                resp_dut.droid.connectivityUnregisterNetworkCallback(
                    resp_req_key)

            # clean-up at end of iteration
            init_dut.droid.wifiAwareDestroy(init_id)
            resp_dut.droid.wifiAwareDestroy(resp_id)

        results = {}
        results['ndp_init_setup_success'] = ndp_init_setup_success
        results['ndp_init_setup_failures'] = ndp_init_setup_failures
        results['ndp_resp_setup_success'] = ndp_resp_setup_success
        results['ndp_resp_setup_failures'] = ndp_resp_setup_failures
        results['ndp_full_socket_success'] = ndp_full_socket_success
        max_failures = (self.MAX_FAILURE_PERCENTAGE * attach_iterations *
                        ndp_iterations / 100)
        if max_failures == 0:
            max_failures = 1
        if trigger_failure_on_index is not None:
            max_failures = max_failures + 1  # for the triggered failure
        asserts.assert_true(
            (ndp_init_setup_failures + ndp_resp_setup_failures) <
            (2 * max_failures),
            'NDP setup failure rate exceeds threshold',
            extras=results)
        asserts.explicit_pass("test_oob_ndp_stress* done", extras=results)