Etan Cohen | 48adcd2 | 2017-06-08 16:59:23 -0700 | [diff] [blame^] | 1 | #!/usr/bin/python3.4 |
| 2 | # |
| 3 | # Copyright 2017 - The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | import json |
| 18 | import pprint |
| 19 | import time |
| 20 | |
| 21 | from acts import asserts |
| 22 | from acts.test_utils.net import connectivity_const as cconsts |
| 23 | from acts.test_utils.wifi.aware import aware_const as aconsts |
| 24 | from acts.test_utils.wifi.aware import aware_test_utils as autils |
| 25 | from acts.test_utils.wifi.aware.AwareBaseTest import AwareBaseTest |
| 26 | |
| 27 | |
| 28 | class ThroughputTest(AwareBaseTest): |
| 29 | """Set of tests for Wi-Fi Aware to measure latency of Aware operations.""" |
| 30 | |
| 31 | # number of second to 'reasonably' wait to make sure that devices synchronize |
| 32 | # with each other - useful for OOB test cases, where the OOB discovery would |
| 33 | # take some time |
| 34 | WAIT_FOR_CLUSTER = 5 |
| 35 | |
| 36 | def __init__(self, controllers): |
| 37 | AwareBaseTest.__init__(self, controllers) |
| 38 | |
| 39 | def request_network(self, dut, ns): |
| 40 | """Request a Wi-Fi Aware network. |
| 41 | |
| 42 | Args: |
| 43 | dut: Device |
| 44 | ns: Network specifier |
| 45 | Returns: the request key |
| 46 | """ |
| 47 | network_req = {"TransportType": 5, "NetworkSpecifier": ns} |
| 48 | return dut.droid.connectivityRequestWifiAwareNetwork(network_req) |
| 49 | |
| 50 | ######################################################################## |
| 51 | |
| 52 | def test_iperf_single_ndp_aware_only(self): |
| 53 | """Measure iperf performance on a single NDP, with Aware enabled and no |
| 54 | infrastructure connection - i.e. device is not associated to an AP""" |
| 55 | init_dut = self.android_devices[0] |
| 56 | init_dut.pretty_name = "Initiator" |
| 57 | resp_dut = self.android_devices[1] |
| 58 | resp_dut.pretty_name = "Responder" |
| 59 | |
| 60 | # Initiator+Responder: attach and wait for confirmation & identity |
| 61 | init_id = init_dut.droid.wifiAwareAttach(True) |
| 62 | autils.wait_for_event(init_dut, aconsts.EVENT_CB_ON_ATTACHED) |
| 63 | init_ident_event = autils.wait_for_event( |
| 64 | init_dut, aconsts.EVENT_CB_ON_IDENTITY_CHANGED) |
| 65 | init_mac = init_ident_event["data"]["mac"] |
| 66 | resp_id = resp_dut.droid.wifiAwareAttach(True) |
| 67 | autils.wait_for_event(resp_dut, aconsts.EVENT_CB_ON_ATTACHED) |
| 68 | resp_ident_event = autils.wait_for_event( |
| 69 | resp_dut, aconsts.EVENT_CB_ON_IDENTITY_CHANGED) |
| 70 | resp_mac = resp_ident_event["data"]["mac"] |
| 71 | |
| 72 | # wait for for devices to synchronize with each other - there are no other |
| 73 | # mechanisms to make sure this happens for OOB discovery (except retrying |
| 74 | # to execute the data-path request) |
| 75 | time.sleep(self.WAIT_FOR_CLUSTER) |
| 76 | |
| 77 | # Responder: request network |
| 78 | resp_req_key = self.request_network( |
| 79 | resp_dut, |
| 80 | resp_dut.droid.wifiAwareCreateNetworkSpecifierOob( |
| 81 | resp_id, aconsts.DATA_PATH_RESPONDER, init_mac, None)) |
| 82 | |
| 83 | # Initiator: request network |
| 84 | init_req_key = self.request_network( |
| 85 | init_dut, |
| 86 | init_dut.droid.wifiAwareCreateNetworkSpecifierOob( |
| 87 | init_id, aconsts.DATA_PATH_INITIATOR, resp_mac, None)) |
| 88 | |
| 89 | # Initiator & Responder: wait for network formation |
| 90 | init_net_event = autils.wait_for_event_with_keys( |
| 91 | init_dut, cconsts.EVENT_NETWORK_CALLBACK, autils.EVENT_TIMEOUT, |
| 92 | (cconsts.NETWORK_CB_KEY_EVENT, |
| 93 | cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED), |
| 94 | (cconsts.NETWORK_CB_KEY_ID, init_req_key)) |
| 95 | resp_net_event = autils.wait_for_event_with_keys( |
| 96 | resp_dut, cconsts.EVENT_NETWORK_CALLBACK, autils.EVENT_TIMEOUT, |
| 97 | (cconsts.NETWORK_CB_KEY_EVENT, |
| 98 | cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED), |
| 99 | (cconsts.NETWORK_CB_KEY_ID, resp_req_key)) |
| 100 | |
| 101 | init_aware_if = init_net_event["data"][ |
| 102 | cconsts.NETWORK_CB_KEY_INTERFACE_NAME] |
| 103 | resp_aware_if = resp_net_event["data"][ |
| 104 | cconsts.NETWORK_CB_KEY_INTERFACE_NAME] |
| 105 | self.log.info("Interface names: I=%s, R=%s", init_aware_if, resp_aware_if) |
| 106 | |
| 107 | init_ipv6 = init_dut.droid.connectivityGetLinkLocalIpv6Address( |
| 108 | init_aware_if).split("%")[0] |
| 109 | resp_ipv6 = resp_dut.droid.connectivityGetLinkLocalIpv6Address( |
| 110 | resp_aware_if).split("%")[0] |
| 111 | self.log.info("Interface addresses (IPv6): I=%s, R=%s", init_ipv6, |
| 112 | resp_ipv6) |
| 113 | |
| 114 | # Run iperf3 |
| 115 | result, data = init_dut.run_iperf_server("-D") |
| 116 | asserts.assert_true(result, "Can't start iperf3 server") |
| 117 | |
| 118 | result, data = resp_dut.run_iperf_client( |
| 119 | "%s%%%s" % (init_ipv6, resp_aware_if), "-6 -J") |
| 120 | self.log.debug(data) |
| 121 | asserts.assert_true(result, |
| 122 | "Failure starting/running iperf3 in client mode") |
| 123 | self.log.debug(pprint.pformat(data)) |
| 124 | |
| 125 | # clean-up |
| 126 | resp_dut.droid.connectivityUnregisterNetworkCallback(resp_req_key) |
| 127 | init_dut.droid.connectivityUnregisterNetworkCallback(init_req_key) |
| 128 | |
| 129 | # Collect results |
| 130 | results = {} |
| 131 | data_json = json.loads("".join(data)) |
| 132 | results["tx_rate"] = data_json["end"]["sum_sent"]["bits_per_second"] |
| 133 | results["rx_rate"] = data_json["end"]["sum_received"]["bits_per_second"] |
| 134 | self.log.info("iPerf3: Sent = %d bps Received = %d bps", results["tx_rate"], |
| 135 | results["rx_rate"]) |
| 136 | asserts.explicit_pass("Aware data-path test passes", extras=results) |