Home | History | Annotate | Download | only in functional
      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 time
     18 
     19 from acts import asserts
     20 from acts.test_decorators import test_tracker_info
     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 
     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 
     52   ##########################################################################
     53 
     54   @test_tracker_info(uuid="09964368-146a-48e4-9f33-6a319f9eeadc")
     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"""
     58     dut = self.android_devices[0]
     59 
     60     # re-enable randomization interval (since if disabled it may also disable
     61     # the 'randomize on enable' feature).
     62     autils.configure_mac_random_interval(dut, 1800)
     63 
     64     # DUT: attach and wait for confirmation & identity 10 times
     65     mac_addresses = {}
     66     for i in range(self.NUM_ITERATIONS):
     67       id = dut.droid.wifiAwareAttach(True)
     68       autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED)
     69       ident_event = autils.wait_for_event(dut,
     70                                           aconsts.EVENT_CB_ON_IDENTITY_CHANGED)
     71 
     72       # process NMI
     73       mac = ident_event["data"]["mac"]
     74       dut.log.info("NMI=%s", mac)
     75       if mac in mac_addresses:
     76         mac_addresses[mac] = mac_addresses[mac] + 1
     77       else:
     78         mac_addresses[mac] = 1
     79 
     80       # process NDIs
     81       time.sleep(5) # wait for NDI creation to complete
     82       for j in range(dut.aware_capabilities[aconsts.CAP_MAX_NDI_INTERFACES]):
     83         ndi_interface = "%s%d" % (aconsts.AWARE_NDI_PREFIX, j)
     84         ndi_mac = autils.get_mac_addr(dut, ndi_interface)
     85         dut.log.info("NDI %s=%s", ndi_interface, ndi_mac)
     86         if ndi_mac in mac_addresses:
     87           mac_addresses[ndi_mac] = mac_addresses[ndi_mac] + 1
     88         else:
     89           mac_addresses[ndi_mac] = 1
     90 
     91       dut.droid.wifiAwareDestroy(id)
     92 
     93     # Test for uniqueness
     94     for mac in mac_addresses.keys():
     95       if mac_addresses[mac] != 1:
     96         asserts.fail("MAC address %s repeated %d times (all=%s)" % (mac,
     97                      mac_addresses[mac], mac_addresses))
     98 
     99     # Verify that infra interface (e.g. wlan0) MAC address is not used for NMI
    100     infra_mac = autils.get_wifi_mac_address(dut)
    101     asserts.assert_false(
    102         infra_mac in mac_addresses,
    103         "Infrastructure MAC address (%s) is used for Aware NMI (all=%s)" %
    104         (infra_mac, mac_addresses))
    105 
    106   @test_tracker_info(uuid="0fb0b5d8-d9cb-4e37-b9af-51811be5670d")
    107   def test_nmi_randomization_on_interval(self):
    108     """Validate randomization of the NMI (NAN management interface) on a set
    109     interval. Default value is 30 minutes - change to a small value to allow
    110     testing in real-time"""
    111     RANDOM_INTERVAL = 120 # minimal value in current implementation
    112 
    113     dut = self.android_devices[0]
    114 
    115     # set randomization interval to 120 seconds
    116     autils.configure_mac_random_interval(dut, RANDOM_INTERVAL)
    117 
    118     # attach and wait for first identity
    119     id = dut.droid.wifiAwareAttach(True)
    120     autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED)
    121     ident_event = autils.wait_for_event(dut,
    122                                         aconsts.EVENT_CB_ON_IDENTITY_CHANGED)
    123     mac1 = ident_event["data"]["mac"]
    124 
    125     # wait for second identity callback
    126     # Note: exact randomization interval is not critical, just approximate,
    127     # hence giving a few more seconds.
    128     ident_event = autils.wait_for_event(dut,
    129                                         aconsts.EVENT_CB_ON_IDENTITY_CHANGED,
    130                                         timeout=RANDOM_INTERVAL + 5)
    131     mac2 = ident_event["data"]["mac"]
    132 
    133     # validate MAC address is randomized
    134     asserts.assert_false(
    135         mac1 == mac2,
    136         "Randomized MAC addresses (%s, %s) should be different" % (mac1, mac2))
    137 
    138     # clean-up
    139     dut.droid.wifiAwareDestroy(id)
    140