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)))
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 run_oob_data_path_test(self, encr_type, use_peer_id): """Runs the out-of-band data-path tests. Args: encr_type: Encryption type, one of ENCR_TYPE_* use_peer_id: On Responder: True to use peer ID, False to accept any request """ init_dut = self.android_devices[0] init_dut.pretty_name = "Initiator" resp_dut = self.android_devices[1] resp_dut.pretty_name = "Responder" # 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(self.WAIT_FOR_CLUSTER) passphrase = None pmk = None if encr_type == self.ENCR_TYPE_PASSPHRASE: passphrase = self.PASSPHRASE elif encr_type == self.ENCR_TYPE_PMK: pmk = self.PMK # Responder: request network resp_req_key = self.request_network( resp_dut, resp_dut.droid.wifiAwareCreateNetworkSpecifierOob( resp_id, aconsts.DATA_PATH_RESPONDER, init_mac if use_peer_id else None, passphrase, pmk)) # Initiator: request network init_req_key = self.request_network( init_dut, init_dut.droid.wifiAwareCreateNetworkSpecifierOob( init_id, aconsts.DATA_PATH_INITIATOR, resp_mac, passphrase, pmk)) # Initiator & Responder: wait for network formation init_net_event = 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 = 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)) init_aware_if = init_net_event["data"][ cconsts.NETWORK_CB_KEY_INTERFACE_NAME] resp_aware_if = resp_net_event["data"][ cconsts.NETWORK_CB_KEY_INTERFACE_NAME] self.log.info("Interface names: I=%s, R=%s", init_aware_if, resp_aware_if) init_ipv6 = init_dut.droid.connectivityGetLinkLocalIpv6Address( init_aware_if).split("%")[0] resp_ipv6 = resp_dut.droid.connectivityGetLinkLocalIpv6Address( resp_aware_if).split("%")[0] self.log.info("Interface addresses (IPv6): I=%s, R=%s", init_ipv6, resp_ipv6) # TODO: possibly send messages back and forth, prefer to use netcat/nc # terminate sessions and wait for ON_LOST callbacks init_dut.droid.wifiAwareDestroy(init_id) resp_dut.droid.wifiAwareDestroy(resp_id) autils.wait_for_event_with_keys( init_dut, cconsts.EVENT_NETWORK_CALLBACK, autils.EVENT_NDP_TIMEOUT, (cconsts.NETWORK_CB_KEY_EVENT, cconsts.NETWORK_CB_LOST), (cconsts.NETWORK_CB_KEY_ID, init_req_key)) autils.wait_for_event_with_keys( resp_dut, cconsts.EVENT_NETWORK_CALLBACK, autils.EVENT_NDP_TIMEOUT, (cconsts.NETWORK_CB_KEY_EVENT, cconsts.NETWORK_CB_LOST), (cconsts.NETWORK_CB_KEY_ID, resp_req_key)) # clean-up resp_dut.droid.connectivityUnregisterNetworkCallback(resp_req_key) init_dut.droid.connectivityUnregisterNetworkCallback(init_req_key)
def run_ib_data_path_test(self, ptype, stype, encr_type, use_peer_id, passphrase_to_use=None): """Runs the in-band data-path tests. Args: ptype: Publish discovery type stype: Subscribe discovery type encr_type: Encryption type, one of ENCR_TYPE_* use_peer_id: On Responder (publisher): True to use peer ID, False to accept any request passphrase_to_use: The passphrase to use if encr_type=ENCR_TYPE_PASSPHRASE If None then use self.PASSPHRASE """ (p_dut, s_dut, p_id, s_id, p_disc_id, s_disc_id, peer_id_on_sub, peer_id_on_pub) = self.set_up_discovery(ptype, stype, use_peer_id) passphrase = None pmk = None if encr_type == self.ENCR_TYPE_PASSPHRASE: passphrase = self.PASSPHRASE if passphrase_to_use == None else passphrase_to_use elif encr_type == self.ENCR_TYPE_PMK: pmk = self.PMK # Publisher: request network p_req_key = self.request_network( p_dut, p_dut.droid.wifiAwareCreateNetworkSpecifier( p_disc_id, peer_id_on_pub if use_peer_id else None, passphrase, pmk)) # Subscriber: request network s_req_key = self.request_network( s_dut, s_dut.droid.wifiAwareCreateNetworkSpecifier( s_disc_id, peer_id_on_sub, passphrase, pmk)) # Publisher & Subscriber: wait for network formation p_net_event = 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 = 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["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 = p_dut.droid.connectivityGetLinkLocalIpv6Address( p_aware_if).split("%")[0] s_ipv6 = s_dut.droid.connectivityGetLinkLocalIpv6Address( s_aware_if).split("%")[0] self.log.info("Interface addresses (IPv6): p=%s, s=%s", p_ipv6, s_ipv6) # TODO: possibly send messages back and forth, prefer to use netcat/nc # terminate sessions and wait for ON_LOST callbacks p_dut.droid.wifiAwareDestroy(p_id) s_dut.droid.wifiAwareDestroy(s_id) autils.wait_for_event_with_keys( p_dut, cconsts.EVENT_NETWORK_CALLBACK, autils.EVENT_NDP_TIMEOUT, (cconsts.NETWORK_CB_KEY_EVENT, cconsts.NETWORK_CB_LOST), (cconsts.NETWORK_CB_KEY_ID, p_req_key)) autils.wait_for_event_with_keys( s_dut, cconsts.EVENT_NETWORK_CALLBACK, autils.EVENT_NDP_TIMEOUT, (cconsts.NETWORK_CB_KEY_EVENT, cconsts.NETWORK_CB_LOST), (cconsts.NETWORK_CB_KEY_ID, s_req_key)) # clean-up p_dut.droid.connectivityUnregisterNetworkCallback(p_req_key) s_dut.droid.connectivityUnregisterNetworkCallback(s_req_key)
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
def test_nsd_oob(self): """Validate that NSD (mDNS) works correctly on an NDP created using OOB (out-of band) discovery""" init_dut = self.android_devices[0] resp_dut = self.android_devices[1] # create NDP (init_req_key, resp_req_key, init_aware_if, resp_aware_if, init_ipv6, resp_ipv6) = autils.create_oob_ndp(init_dut, resp_dut) self.log.info("Interface names: I=%s, R=%s", init_aware_if, resp_aware_if) self.log.info("Interface addresses (IPv6): I=%s, R=%s", init_ipv6, resp_ipv6) # run NSD nsd_service_info = { "serviceInfoServiceName": "sl4aTestAwareNsd", "serviceInfoServiceType": "_simple-tx-rx._tcp.", "serviceInfoPort": 2257 } nsd_reg = None nsd_discovery = None try: # Initiator registers an NSD service nsd_reg = init_dut.droid.nsdRegisterService(nsd_service_info) event_nsd = autils.wait_for_event_with_keys( init_dut, nconsts.REG_LISTENER_EVENT, autils.EVENT_TIMEOUT, (nconsts.REG_LISTENER_CALLBACK, nconsts.REG_LISTENER_EVENT_ON_SERVICE_REGISTERED)) self.log.info("Initiator %s: %s", nconsts.REG_LISTENER_EVENT_ON_SERVICE_REGISTERED, event_nsd["data"]) # Responder starts an NSD discovery nsd_discovery = resp_dut.droid.nsdDiscoverServices( nsd_service_info[nconsts.NSD_SERVICE_INFO_SERVICE_TYPE]) event_nsd = autils.wait_for_event_with_keys( resp_dut, nconsts.DISCOVERY_LISTENER_EVENT, autils.EVENT_TIMEOUT, (nconsts.DISCOVERY_LISTENER_DATA_CALLBACK, nconsts.DISCOVERY_LISTENER_EVENT_ON_SERVICE_FOUND)) self.log.info("Responder %s: %s", nconsts.DISCOVERY_LISTENER_EVENT_ON_SERVICE_FOUND, event_nsd["data"]) # Responder resolves IP address of Initiator from NSD service discovery resp_dut.droid.nsdResolveService(event_nsd["data"]) event_nsd = autils.wait_for_event_with_keys( resp_dut, nconsts.RESOLVE_LISTENER_EVENT, autils.EVENT_TIMEOUT, (nconsts.RESOLVE_LISTENER_DATA_CALLBACK, nconsts.RESOLVE_LISTENER_EVENT_ON_SERVICE_RESOLVED)) self.log.info("Responder %s: %s", nconsts.RESOLVE_LISTENER_EVENT_ON_SERVICE_RESOLVED, event_nsd["data"]) # mDNS returns first character as '/' - strip # out to get clean IPv6 init_ipv6_nsd = event_nsd["data"][ nconsts.NSD_SERVICE_INFO_HOST][1:] asserts.assert_equal( init_ipv6, init_ipv6_nsd, "Initiator's IPv6 address obtained through NSD doesn't match!?" ) finally: # Stop NSD if nsd_reg is not None: init_dut.droid.nsdUnregisterService(nsd_reg) if nsd_discovery is not None: resp_dut.droid.nsdStopServiceDiscovery(nsd_discovery) # clean-up resp_dut.droid.connectivityUnregisterNetworkCallback(resp_req_key) init_dut.droid.connectivityUnregisterNetworkCallback(init_req_key)
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"])