blob: 0cebd42e28e81680fc0b242b53c68d5a75a96203 [file] [log] [blame]
Ang Li73697b32015-12-03 00:41:53 +00001#
tturney1bdf77d2015-12-28 17:46:13 -08002# Copyright 2016 - The Android Open Source Project
Ang Li73697b32015-12-03 00:41:53 +00003#
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
16import pprint
Ang Li8e767182015-12-09 17:29:24 -080017import random
Ang Li73697b32015-12-03 00:41:53 +000018import time
19
Ang Lic2d45212016-03-10 18:38:53 -080020from acts import asserts
Ang Li81549052016-06-09 18:51:14 -070021from acts import signals
Girish Moturu43faec82017-06-12 10:46:51 +053022from acts.test_decorators import test_tracker_info
Ang Li81549052016-06-09 18:51:14 -070023from acts.test_utils.wifi import wifi_test_utils as wutils
Girish Moturuf1ce4202018-10-20 21:33:00 -070024from acts.test_utils.wifi.WifiBaseTest import WifiBaseTest
Ang Lic2d45212016-03-10 18:38:53 -080025
Ang Lie8ed2b32015-12-11 12:30:20 -080026WifiEnums = wutils.WifiEnums
Ang Li73697b32015-12-03 00:41:53 +000027
28# EAP Macros
29EAP = WifiEnums.Eap
30EapPhase2 = WifiEnums.EapPhase2
31
32# Enterprise Config Macros
33Ent = WifiEnums.Enterprise
34
Ang Li73697b32015-12-03 00:41:53 +000035
Girish Moturuf1ce4202018-10-20 21:33:00 -070036class WifiEnterpriseRoamingTest(WifiBaseTest):
Ang Li73697b32015-12-03 00:41:53 +000037 def setup_class(self):
Xianyuan Jia168103b2019-09-06 12:22:52 -070038 super().setup_class()
39
Ang Li73697b32015-12-03 00:41:53 +000040 self.dut = self.android_devices[0]
Ang Li8e767182015-12-09 17:29:24 -080041 wutils.wifi_test_device_init(self.dut)
Ang Li73697b32015-12-03 00:41:53 +000042 req_params = (
Ang Li73697b32015-12-03 00:41:53 +000043 "attn_vals",
44 # Expected time within which roaming should finish, in seconds.
45 "roam_interval",
46 "ca_cert",
47 "client_cert",
48 "client_key",
49 "eap_identity",
50 "eap_password",
Girish Moturuf1ce4202018-10-20 21:33:00 -070051 "device_password",
52 "radius_conf_2g",
53 "radius_conf_5g")
Ang Li5cd6d3c2016-02-01 11:29:14 -080054 self.unpack_userparams(req_params)
Girish Moturuf1ce4202018-10-20 21:33:00 -070055 if "AccessPoint" in self.user_params:
56 self.legacy_configure_ap_and_start(
57 mirror_ap=True,
58 ent_network=True,
59 ap_count=2,
60 radius_conf_2g=self.radius_conf_2g,
61 radius_conf_5g=self.radius_conf_5g,)
62 self.ent_network_2g_a = self.ent_networks[0]["2g"]
63 self.ent_network_2g_b = self.ent_networks[1]["2g"]
64 self.bssid_2g_a = self.ent_network_2g_a[WifiEnums.BSSID_KEY.lower()]
65 self.bssid_2g_b = self.ent_network_2g_b[WifiEnums.BSSID_KEY.lower()]
66 self.ent_roaming_ssid = self.ent_network_2g_a[WifiEnums.SSID_KEY]
67 self.bssid_a = self.bssid_2g_a
68 self.bssid_b = self.bssid_2g_b
69
Ang Li73697b32015-12-03 00:41:53 +000070 self.config_peap = {
Girish Moturu150d32f2017-02-14 12:27:07 -080071 Ent.EAP: int(EAP.PEAP),
Ang Li73697b32015-12-03 00:41:53 +000072 Ent.CA_CERT: self.ca_cert,
73 Ent.IDENTITY: self.eap_identity,
74 Ent.PASSWORD: self.eap_password,
Girish Moturu150d32f2017-02-14 12:27:07 -080075 Ent.PHASE2: int(EapPhase2.MSCHAPV2),
Ang Li73697b32015-12-03 00:41:53 +000076 WifiEnums.SSID_KEY: self.ent_roaming_ssid
77 }
78 self.config_tls = {
Girish Moturu150d32f2017-02-14 12:27:07 -080079 Ent.EAP: int(EAP.TLS),
Ang Li73697b32015-12-03 00:41:53 +000080 Ent.CA_CERT: self.ca_cert,
81 WifiEnums.SSID_KEY: self.ent_roaming_ssid,
82 Ent.CLIENT_CERT: self.client_cert,
83 Ent.PRIVATE_KEY_ID: self.client_key,
84 Ent.IDENTITY: self.eap_identity,
85 }
86 self.config_ttls = {
Girish Moturu150d32f2017-02-14 12:27:07 -080087 Ent.EAP: int(EAP.TTLS),
Ang Li73697b32015-12-03 00:41:53 +000088 Ent.CA_CERT: self.ca_cert,
89 Ent.IDENTITY: self.eap_identity,
90 Ent.PASSWORD: self.eap_password,
Girish Moturu150d32f2017-02-14 12:27:07 -080091 Ent.PHASE2: int(EapPhase2.MSCHAPV2),
Ang Li73697b32015-12-03 00:41:53 +000092 WifiEnums.SSID_KEY: self.ent_roaming_ssid
93 }
94 self.config_sim = {
Girish Moturu150d32f2017-02-14 12:27:07 -080095 Ent.EAP: int(EAP.SIM),
Ang Li73697b32015-12-03 00:41:53 +000096 WifiEnums.SSID_KEY: self.ent_roaming_ssid,
97 }
98 self.attn_a = self.attenuators[0]
Girish Moturuf1ce4202018-10-20 21:33:00 -070099 self.attn_b = self.attenuators[2]
Ang Li73697b32015-12-03 00:41:53 +0000100 # Set screen lock password so ConfigStore is unlocked.
Ang Lia9d188f2016-02-17 18:03:01 -0800101 self.dut.droid.setDevicePassword(self.device_password)
Ang Li73697b32015-12-03 00:41:53 +0000102 self.set_attns("default")
Ang Li73697b32015-12-03 00:41:53 +0000103
104 def teardown_class(self):
Ang Li8e767182015-12-09 17:29:24 -0800105 wutils.reset_wifi(self.dut)
Hsiu-Chang Chen3492edd2019-03-27 10:28:58 +0800106 self.dut.droid.disableDevicePassword(self.device_password)
Ang Lia9d188f2016-02-17 18:03:01 -0800107 self.dut.ed.clear_all_events()
Ang Li73697b32015-12-03 00:41:53 +0000108 self.set_attns("default")
109
110 def setup_test(self):
Ang Lia9d188f2016-02-17 18:03:01 -0800111 self.dut.droid.wifiStartTrackingStateChange()
112 self.dut.droid.wakeLockAcquireBright()
113 self.dut.droid.wakeUpNow()
Ang Li8e767182015-12-09 17:29:24 -0800114 wutils.reset_wifi(self.dut)
Ang Lia9d188f2016-02-17 18:03:01 -0800115 self.dut.ed.clear_all_events()
Ang Li73697b32015-12-03 00:41:53 +0000116
117 def teardown_test(self):
Ang Lia9d188f2016-02-17 18:03:01 -0800118 self.dut.droid.wakeLockRelease()
119 self.dut.droid.goToSleepNow()
120 self.dut.droid.wifiStopTrackingStateChange()
Ang Li73697b32015-12-03 00:41:53 +0000121 self.set_attns("default")
122
Ang Li20377aa2016-02-26 13:19:51 -0800123 def on_fail(self, test_name, begin_time):
Hsiu-Chang Chen0f7d7ae2019-06-04 14:26:04 +0800124 self.dut.take_bug_report(test_name, begin_time)
Ang Li20377aa2016-02-26 13:19:51 -0800125 self.dut.cat_adb_log(test_name, begin_time)
126
Ang Li73697b32015-12-03 00:41:53 +0000127 def set_attns(self, attn_val_name):
128 """Sets attenuation values on attenuators used in this test.
129
130 Args:
131 attn_val_name: Name of the attenuation value pair to use.
132 """
Ang Li81549052016-06-09 18:51:14 -0700133 self.log.info("Set attenuation values to %s",
134 self.attn_vals[attn_val_name])
Ang Li73697b32015-12-03 00:41:53 +0000135 try:
136 self.attn_a.set_atten(self.attn_vals[attn_val_name][0])
137 self.attn_b.set_atten(self.attn_vals[attn_val_name][1])
138 except:
Ang Li81549052016-06-09 18:51:14 -0700139 self.log.exception("Failed to set attenuation values %s.",
140 attn_val_name)
Ang Li73697b32015-12-03 00:41:53 +0000141 raise
142
Ang Li73697b32015-12-03 00:41:53 +0000143 def trigger_roaming_and_validate(self, attn_val_name, expected_con):
144 """Sets attenuators to trigger roaming and validate the DUT connected
145 to the BSSID expected.
146
147 Args:
148 attn_val_name: Name of the attenuation value pair to use.
149 expected_con: The expected info of the network to we expect the DUT
150 to roam to.
151 """
152 self.set_attns(attn_val_name)
Ang Li81549052016-06-09 18:51:14 -0700153 self.log.info("Wait %ss for roaming to finish.", self.roam_interval)
Ang Li73697b32015-12-03 00:41:53 +0000154 time.sleep(self.roam_interval)
155 try:
Ang Lia9d188f2016-02-17 18:03:01 -0800156 self.dut.droid.wakeLockAcquireBright()
157 self.dut.droid.wakeUpNow()
Ang Li8e767182015-12-09 17:29:24 -0800158 wutils.verify_wifi_connection_info(self.dut, expected_con)
Ang Li73697b32015-12-03 00:41:53 +0000159 expected_bssid = expected_con[WifiEnums.BSSID_KEY]
Ang Li81549052016-06-09 18:51:14 -0700160 self.log.info("Roamed to %s successfully", expected_bssid)
Ang Li73697b32015-12-03 00:41:53 +0000161 finally:
Ang Lia9d188f2016-02-17 18:03:01 -0800162 self.dut.droid.wifiLockRelease()
163 self.dut.droid.goToSleepNow()
Ang Li73697b32015-12-03 00:41:53 +0000164
165 def roaming_between_a_and_b_logic(self, config):
166 """Test roaming between two enterprise APs.
167
168 Steps:
169 1. Make bssid_a visible, bssid_b not visible.
170 2. Connect to ent_roaming_ssid. Expect DUT to connect to bssid_a.
171 3. Make bssid_a not visible, bssid_b visible.
172 4. Expect DUT to roam to bssid_b.
173 5. Make bssid_a visible, bssid_b not visible.
174 6. Expect DUT to roam back to bssid_a.
175 """
176 expected_con_to_a = {
177 WifiEnums.SSID_KEY: self.ent_roaming_ssid,
178 WifiEnums.BSSID_KEY: self.bssid_a,
179 }
180 expected_con_to_b = {
181 WifiEnums.SSID_KEY: self.ent_roaming_ssid,
182 WifiEnums.BSSID_KEY: self.bssid_b,
183 }
184 self.set_attns("a_on_b_off")
Bindu Mahadev66179ef2017-01-25 14:39:07 -0800185 wutils.wifi_connect(self.dut, config)
Ang Li8e767182015-12-09 17:29:24 -0800186 wutils.verify_wifi_connection_info(self.dut, expected_con_to_a)
Ang Li81549052016-06-09 18:51:14 -0700187 self.log.info("Roaming from %s to %s", self.bssid_a, self.bssid_b)
Ang Li73697b32015-12-03 00:41:53 +0000188 self.trigger_roaming_and_validate("b_on_a_off", expected_con_to_b)
Ang Li81549052016-06-09 18:51:14 -0700189 self.log.info("Roaming from %s to %s", self.bssid_b, self.bssid_a)
Ang Li73697b32015-12-03 00:41:53 +0000190 self.trigger_roaming_and_validate("a_on_b_off", expected_con_to_a)
Ang Li73697b32015-12-03 00:41:53 +0000191
192 """ Tests Begin """
Ang Li81549052016-06-09 18:51:14 -0700193
Girish Moturuf14d45c2017-06-27 13:00:08 +0530194 @test_tracker_info(uuid="b15e4b3f-841d-428d-87ac-272f29f06e14")
195 def test_roaming_with_config_tls(self):
196 self.roaming_between_a_and_b_logic(self.config_tls)
197
198 @test_tracker_info(uuid="d349cfec-b4af-48b2-88b7-744f5de25d43")
199 def test_roaming_with_config_ttls_none(self):
200 config = dict(self.config_ttls)
201 config[WifiEnums.Enterprise.PHASE2] = WifiEnums.EapPhase2.NONE.value
202 self.roaming_between_a_and_b_logic(config)
203
204 @test_tracker_info(uuid="89b8161c-754e-4138-831d-5fe40f521ce4")
205 def test_roaming_with_config_ttls_pap(self):
206 config = dict(self.config_ttls)
207 config[WifiEnums.Enterprise.PHASE2] = WifiEnums.EapPhase2.PAP.value
208 self.roaming_between_a_and_b_logic(config)
209
210 @test_tracker_info(uuid="d4925470-924b-4d03-8437-83e26b5f2df3")
211 def test_roaming_with_config_ttls_mschap(self):
212 config = dict(self.config_ttls)
213 config[WifiEnums.Enterprise.PHASE2] = WifiEnums.EapPhase2.MSCHAP.value
214 self.roaming_between_a_and_b_logic(config)
215
216 @test_tracker_info(uuid="206b1327-dd9c-4742-8717-e7bf2a04eed6")
217 def test_roaming_with_config_ttls_mschapv2(self):
218 config = dict(self.config_ttls)
219 config[WifiEnums.Enterprise.PHASE2] = WifiEnums.EapPhase2.MSCHAPV2.value
220 self.roaming_between_a_and_b_logic(config)
221
222 @test_tracker_info(uuid="c2c0168b-2933-4954-af62-fb41f42dc45a")
223 def test_roaming_with_config_ttls_gtc(self):
224 config = dict(self.config_ttls)
225 config[WifiEnums.Enterprise.PHASE2] = WifiEnums.EapPhase2.GTC.value
226 self.roaming_between_a_and_b_logic(config)
227
228 @test_tracker_info(uuid="481c4102-8f5b-4fcd-95cc-5e3285f47985")
229 def test_roaming_with_config_peap_mschapv2(self):
230 config = dict(self.config_peap)
231 config[WifiEnums.Enterprise.PHASE2] = WifiEnums.EapPhase2.MSCHAPV2.value
232 self.roaming_between_a_and_b_logic(config)
233
234 @test_tracker_info(uuid="404155d4-33a7-42b3-b369-5f2d63d19f16")
235 def test_roaming_with_config_peap_gtc(self):
236 config = dict(self.config_peap)
237 config[WifiEnums.Enterprise.PHASE2] = WifiEnums.EapPhase2.GTC.value
238 self.roaming_between_a_and_b_logic(config)
Ang Li81549052016-06-09 18:51:14 -0700239
Ang Li73697b32015-12-03 00:41:53 +0000240 """ Tests End """