Etan Cohen | bfb149f | 2017-06-06 10:13:17 -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 | |
Etan Cohen | bfb149f | 2017-06-06 10:13:17 -0700 | [diff] [blame] | 17 | import time |
| 18 | |
| 19 | from acts import asserts |
Etan Cohen | f02703c | 2017-08-24 11:11:44 -0700 | [diff] [blame] | 20 | from acts.test_decorators import test_tracker_info |
Etan Cohen | bfb149f | 2017-06-06 10:13:17 -0700 | [diff] [blame] | 21 | from acts.test_utils.net import connectivity_const as cconsts |
| 22 | from acts.test_utils.wifi.aware import aware_const as aconsts |
| 23 | from acts.test_utils.wifi.aware import aware_test_utils as autils |
| 24 | from acts.test_utils.wifi.aware.AwareBaseTest import AwareBaseTest |
| 25 | |
| 26 | |
| 27 | class MacRandomTest(AwareBaseTest): |
| 28 | """Set of tests for Wi-Fi Aware MAC address randomization of NMI (NAN |
| 29 | management interface) and NDI (NAN data interface).""" |
| 30 | |
| 31 | NUM_ITERATIONS = 10 |
| 32 | |
| 33 | # number of second to 'reasonably' wait to make sure that devices synchronize |
| 34 | # with each other - useful for OOB test cases, where the OOB discovery would |
| 35 | # take some time |
| 36 | WAIT_FOR_CLUSTER = 5 |
| 37 | |
| 38 | def __init__(self, controllers): |
| 39 | AwareBaseTest.__init__(self, controllers) |
| 40 | |
Etan Cohen | 62a3c17 | 2017-06-07 11:08:35 -0700 | [diff] [blame] | 41 | def request_network(self, dut, ns): |
| 42 | """Request a Wi-Fi Aware network. |
| 43 | |
| 44 | Args: |
| 45 | dut: Device |
| 46 | ns: Network specifier |
| 47 | Returns: the request key |
| 48 | """ |
| 49 | network_req = {"TransportType": 5, "NetworkSpecifier": ns} |
| 50 | return dut.droid.connectivityRequestWifiAwareNetwork(network_req) |
| 51 | |
Etan Cohen | bfb149f | 2017-06-06 10:13:17 -0700 | [diff] [blame] | 52 | ########################################################################## |
| 53 | |
Etan Cohen | 185b3cf | 2017-08-22 14:10:10 -0700 | [diff] [blame] | 54 | @test_tracker_info(uuid="09964368-146a-48e4-9f33-6a319f9eeadc") |
Etan Cohen | d4a30d8 | 2017-06-22 10:28:05 -0700 | [diff] [blame] | 55 | def test_nmi_ndi_randomization_on_enable(self): |
| 56 | """Validate randomization of the NMI (NAN management interface) and all NDIs |
| 57 | (NAN data-interface) on each enable/disable cycle""" |
Etan Cohen | bfb149f | 2017-06-06 10:13:17 -0700 | [diff] [blame] | 58 | dut = self.android_devices[0] |
| 59 | |
| 60 | # DUT: attach and wait for confirmation & identity 10 times |
| 61 | mac_addresses = {} |
| 62 | for i in range(self.NUM_ITERATIONS): |
| 63 | id = dut.droid.wifiAwareAttach(True) |
| 64 | autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED) |
| 65 | ident_event = autils.wait_for_event(dut, |
| 66 | aconsts.EVENT_CB_ON_IDENTITY_CHANGED) |
Etan Cohen | d4a30d8 | 2017-06-22 10:28:05 -0700 | [diff] [blame] | 67 | |
| 68 | # process NMI |
Etan Cohen | bfb149f | 2017-06-06 10:13:17 -0700 | [diff] [blame] | 69 | mac = ident_event["data"]["mac"] |
Etan Cohen | d4a30d8 | 2017-06-22 10:28:05 -0700 | [diff] [blame] | 70 | dut.log.info("NMI=%s", mac) |
Etan Cohen | bfb149f | 2017-06-06 10:13:17 -0700 | [diff] [blame] | 71 | if mac in mac_addresses: |
| 72 | mac_addresses[mac] = mac_addresses[mac] + 1 |
| 73 | else: |
| 74 | mac_addresses[mac] = 1 |
Etan Cohen | d4a30d8 | 2017-06-22 10:28:05 -0700 | [diff] [blame] | 75 | |
| 76 | # process NDIs |
| 77 | time.sleep(5) # wait for NDI creation to complete |
| 78 | for j in range(dut.aware_capabilities[aconsts.CAP_MAX_NDI_INTERFACES]): |
| 79 | ndi_interface = "%s%d" % (aconsts.AWARE_NDI_PREFIX, j) |
| 80 | ndi_mac = autils.get_mac_addr(dut, ndi_interface) |
| 81 | dut.log.info("NDI %s=%s", ndi_interface, ndi_mac) |
| 82 | if ndi_mac in mac_addresses: |
| 83 | mac_addresses[ndi_mac] = mac_addresses[ndi_mac] + 1 |
| 84 | else: |
| 85 | mac_addresses[ndi_mac] = 1 |
| 86 | |
Etan Cohen | bfb149f | 2017-06-06 10:13:17 -0700 | [diff] [blame] | 87 | dut.droid.wifiAwareDestroy(id) |
| 88 | |
| 89 | # Test for uniqueness |
| 90 | for mac in mac_addresses.keys(): |
| 91 | if mac_addresses[mac] != 1: |
Etan Cohen | 4180155 | 2017-06-07 14:57:49 -0700 | [diff] [blame] | 92 | asserts.fail("MAC address %s repeated %d times (all=%s)" % (mac, |
Etan Cohen | bfb149f | 2017-06-06 10:13:17 -0700 | [diff] [blame] | 93 | mac_addresses[mac], mac_addresses)) |
Etan Cohen | 62a3c17 | 2017-06-07 11:08:35 -0700 | [diff] [blame] | 94 | |
Etan Cohen | 4180155 | 2017-06-07 14:57:49 -0700 | [diff] [blame] | 95 | # Verify that infra interface (e.g. wlan0) MAC address is not used for NMI |
| 96 | infra_mac = autils.get_wifi_mac_address(dut) |
| 97 | asserts.assert_false( |
| 98 | infra_mac in mac_addresses, |
| 99 | "Infrastructure MAC address (%s) is used for Aware NMI (all=%s)" % |
| 100 | (infra_mac, mac_addresses)) |
| 101 | |
Etan Cohen | 185b3cf | 2017-08-22 14:10:10 -0700 | [diff] [blame] | 102 | @test_tracker_info(uuid="0fb0b5d8-d9cb-4e37-b9af-51811be5670d") |
Etan Cohen | 641d822 | 2017-06-07 13:57:49 -0700 | [diff] [blame] | 103 | def test_nmi_randomization_on_interval(self): |
| 104 | """Validate randomization of the NMI (NAN management interface) on a set |
| 105 | interval. Default value is 30 minutes - change to a small value to allow |
| 106 | testing in real-time""" |
| 107 | RANDOM_INTERVAL = 120 # minimal value in current implementation |
| 108 | |
| 109 | dut = self.android_devices[0] |
| 110 | |
| 111 | # set randomization interval to 5 seconds |
| 112 | dut.adb.shell("cmd wifiaware native_api set mac_random_interval_sec %d" % |
| 113 | RANDOM_INTERVAL) |
| 114 | |
| 115 | # attach and wait for first identity |
| 116 | id = dut.droid.wifiAwareAttach(True) |
| 117 | autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED) |
| 118 | ident_event = autils.wait_for_event(dut, |
| 119 | aconsts.EVENT_CB_ON_IDENTITY_CHANGED) |
| 120 | mac1 = ident_event["data"]["mac"] |
| 121 | |
| 122 | # wait for second identity callback |
| 123 | # Note: exact randomization interval is not critical, just approximate, |
| 124 | # hence giving a few more seconds. |
| 125 | ident_event = autils.wait_for_event(dut, |
| 126 | aconsts.EVENT_CB_ON_IDENTITY_CHANGED, |
| 127 | timeout=RANDOM_INTERVAL + 5) |
| 128 | mac2 = ident_event["data"]["mac"] |
| 129 | |
| 130 | # validate MAC address is randomized |
| 131 | asserts.assert_false( |
| 132 | mac1 == mac2, |
| 133 | "Randomized MAC addresses (%s, %s) should be different" % (mac1, mac2)) |
| 134 | |
| 135 | # clean-up |
| 136 | dut.droid.wifiAwareDestroy(id) |