Home | History | Annotate | Download | only in wifi
      1 #
      2 #   Copyright 2016 - The Android Open Source Project
      3 #
      4 #   Licensed under the Apache License, Version 2.0 (the "License");
      5 #   you may not use this file except in compliance with the License.
      6 #   You may obtain a copy of the License at
      7 #
      8 #       http://www.apache.org/licenses/LICENSE-2.0
      9 #
     10 #   Unless required by applicable law or agreed to in writing, software
     11 #   distributed under the License is distributed on an "AS IS" BASIS,
     12 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 #   See the License for the specific language governing permissions and
     14 #   limitations under the License.
     15 
     16 import pprint
     17 import random
     18 import time
     19 
     20 from acts import asserts
     21 from acts import base_test
     22 from acts import signals
     23 from acts.test_decorators import test_tracker_info
     24 from acts.test_utils.wifi import wifi_test_utils as wutils
     25 
     26 WifiEnums = wutils.WifiEnums
     27 
     28 # EAP Macros
     29 EAP = WifiEnums.Eap
     30 EapPhase2 = WifiEnums.EapPhase2
     31 
     32 # Enterprise Config Macros
     33 Ent = WifiEnums.Enterprise
     34 
     35 
     36 class WifiEnterpriseRoamingTest(base_test.BaseTestClass):
     37     def setup_class(self):
     38         self.dut = self.android_devices[0]
     39         wutils.wifi_test_device_init(self.dut)
     40         req_params = (
     41             "ent_roaming_ssid",
     42             "bssid_a",
     43             "bssid_b",
     44             "attn_vals",
     45             # Expected time within which roaming should finish, in seconds.
     46             "roam_interval",
     47             "ca_cert",
     48             "client_cert",
     49             "client_key",
     50             "eap_identity",
     51             "eap_password",
     52             "device_password")
     53         self.unpack_userparams(req_params)
     54         self.config_peap = {
     55             Ent.EAP: int(EAP.PEAP),
     56             Ent.CA_CERT: self.ca_cert,
     57             Ent.IDENTITY: self.eap_identity,
     58             Ent.PASSWORD: self.eap_password,
     59             Ent.PHASE2: int(EapPhase2.MSCHAPV2),
     60             WifiEnums.SSID_KEY: self.ent_roaming_ssid
     61         }
     62         self.config_tls = {
     63             Ent.EAP: int(EAP.TLS),
     64             Ent.CA_CERT: self.ca_cert,
     65             WifiEnums.SSID_KEY: self.ent_roaming_ssid,
     66             Ent.CLIENT_CERT: self.client_cert,
     67             Ent.PRIVATE_KEY_ID: self.client_key,
     68             Ent.IDENTITY: self.eap_identity,
     69         }
     70         self.config_ttls = {
     71             Ent.EAP: int(EAP.TTLS),
     72             Ent.CA_CERT: self.ca_cert,
     73             Ent.IDENTITY: self.eap_identity,
     74             Ent.PASSWORD: self.eap_password,
     75             Ent.PHASE2: int(EapPhase2.MSCHAPV2),
     76             WifiEnums.SSID_KEY: self.ent_roaming_ssid
     77         }
     78         self.config_sim = {
     79             Ent.EAP: int(EAP.SIM),
     80             WifiEnums.SSID_KEY: self.ent_roaming_ssid,
     81         }
     82         self.attenuators = wutils.group_attenuators(self.attenuators)
     83         self.attn_a = self.attenuators[0]
     84         self.attn_b = self.attenuators[1]
     85         # Set screen lock password so ConfigStore is unlocked.
     86         self.dut.droid.setDevicePassword(self.device_password)
     87         self.set_attns("default")
     88 
     89     def teardown_class(self):
     90         wutils.reset_wifi(self.dut)
     91         self.dut.droid.disableDevicePassword()
     92         self.dut.ed.clear_all_events()
     93         self.set_attns("default")
     94 
     95     def setup_test(self):
     96         self.dut.droid.wifiStartTrackingStateChange()
     97         self.dut.droid.wakeLockAcquireBright()
     98         self.dut.droid.wakeUpNow()
     99         wutils.reset_wifi(self.dut)
    100         self.dut.ed.clear_all_events()
    101 
    102     def teardown_test(self):
    103         self.dut.droid.wakeLockRelease()
    104         self.dut.droid.goToSleepNow()
    105         self.dut.droid.wifiStopTrackingStateChange()
    106         self.set_attns("default")
    107 
    108     def on_fail(self, test_name, begin_time):
    109         self.dut.cat_adb_log(test_name, begin_time)
    110 
    111     def set_attns(self, attn_val_name):
    112         """Sets attenuation values on attenuators used in this test.
    113 
    114         Args:
    115             attn_val_name: Name of the attenuation value pair to use.
    116         """
    117         self.log.info("Set attenuation values to %s",
    118                       self.attn_vals[attn_val_name])
    119         try:
    120             self.attn_a.set_atten(self.attn_vals[attn_val_name][0])
    121             self.attn_b.set_atten(self.attn_vals[attn_val_name][1])
    122         except:
    123             self.log.exception("Failed to set attenuation values %s.",
    124                            attn_val_name)
    125             raise
    126 
    127     def gen_eap_configs(self):
    128         """Generates configurations for different EAP authentication types.
    129 
    130         Returns:
    131             A list of dicts each representing an EAP configuration.
    132         """
    133         configs = [self.config_tls]
    134         # self.config_sim
    135         configs += wutils.expand_enterprise_config_by_phase2(self.config_ttls)
    136         configs += wutils.expand_enterprise_config_by_phase2(self.config_peap)
    137         return configs
    138 
    139     def trigger_roaming_and_validate(self, attn_val_name, expected_con):
    140         """Sets attenuators to trigger roaming and validate the DUT connected
    141         to the BSSID expected.
    142 
    143         Args:
    144             attn_val_name: Name of the attenuation value pair to use.
    145             expected_con: The expected info of the network to we expect the DUT
    146                 to roam to.
    147         """
    148         self.set_attns(attn_val_name)
    149         self.log.info("Wait %ss for roaming to finish.", self.roam_interval)
    150         time.sleep(self.roam_interval)
    151         try:
    152             self.dut.droid.wakeLockAcquireBright()
    153             self.dut.droid.wakeUpNow()
    154             wutils.verify_wifi_connection_info(self.dut, expected_con)
    155             expected_bssid = expected_con[WifiEnums.BSSID_KEY]
    156             self.log.info("Roamed to %s successfully", expected_bssid)
    157         finally:
    158             self.dut.droid.wifiLockRelease()
    159             self.dut.droid.goToSleepNow()
    160 
    161     def roaming_between_a_and_b_logic(self, config):
    162         """Test roaming between two enterprise APs.
    163 
    164         Steps:
    165         1. Make bssid_a visible, bssid_b not visible.
    166         2. Connect to ent_roaming_ssid. Expect DUT to connect to bssid_a.
    167         3. Make bssid_a not visible, bssid_b visible.
    168         4. Expect DUT to roam to bssid_b.
    169         5. Make bssid_a visible, bssid_b not visible.
    170         6. Expect DUT to roam back to bssid_a.
    171         """
    172         expected_con_to_a = {
    173             WifiEnums.SSID_KEY: self.ent_roaming_ssid,
    174             WifiEnums.BSSID_KEY: self.bssid_a,
    175         }
    176         expected_con_to_b = {
    177             WifiEnums.SSID_KEY: self.ent_roaming_ssid,
    178             WifiEnums.BSSID_KEY: self.bssid_b,
    179         }
    180         self.set_attns("a_on_b_off")
    181         wutils.wifi_connect(self.dut, config)
    182         wutils.verify_wifi_connection_info(self.dut, expected_con_to_a)
    183         self.log.info("Roaming from %s to %s", self.bssid_a, self.bssid_b)
    184         self.trigger_roaming_and_validate("b_on_a_off", expected_con_to_b)
    185         self.log.info("Roaming from %s to %s", self.bssid_b, self.bssid_a)
    186         self.trigger_roaming_and_validate("a_on_b_off", expected_con_to_a)
    187 
    188     """ Tests Begin """
    189 
    190     # TODO: gmoturu Move run_generated_testcases to individual tests
    191     @test_tracker_info(uuid="dd8899d7-e1c8-4066-b5c0-fd80b88e20ee")
    192     @signals.generated_test
    193     def test_roaming_with_different_auth_method(self):
    194         eap_configs = self.gen_eap_configs()
    195         self.log.info("Testing %d different configs.", len(eap_configs))
    196         random.shuffle(eap_configs)
    197         failed = self.run_generated_testcases(
    198             self.roaming_between_a_and_b_logic,
    199             eap_configs,
    200             name_func=wutils.generate_eap_test_name)
    201         asserts.assert_equal(
    202             len(failed), 0,
    203             "The following configs failed enterprise roaming test: %s" %
    204             pprint.pformat(failed))
    205 
    206     """ Tests End """
    207