blob: af1bd088876ec936113601a158617ac0f9276adb [file] [log] [blame]
Girish Moturuf72690e2017-02-14 15:19:53 -08001#
2# Copyright 2017 - 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
16import logging
Girish Moturu2c21eb32017-05-25 14:37:55 +053017import random
Girish Moturuf72690e2017-02-14 15:19:53 -080018import socket
Girish Moturu2c21eb32017-05-25 14:37:55 +053019import time
Girish Moturuf72690e2017-02-14 15:19:53 -080020
21from acts import asserts
22from acts import base_test
23from acts import test_runner
24from acts.controllers import adb
Girish Moturu2c21eb32017-05-25 14:37:55 +053025from acts.test_decorators import test_tracker_info
Girish Moturuf72690e2017-02-14 15:19:53 -080026from acts.test_utils.tel import tel_data_utils
Girish Moturuf72690e2017-02-14 15:19:53 -080027from acts.test_utils.tel import tel_defines
Girish Moturu2c21eb32017-05-25 14:37:55 +053028from acts.test_utils.tel.tel_data_utils import toggle_airplane_mode
29from acts.test_utils.tel.tel_data_utils import wait_for_cell_data_connection
30from acts.test_utils.tel.tel_test_utils import get_operator_name
31from acts.test_utils.tel.tel_test_utils import http_file_download_by_chrome
32from acts.test_utils.tel.tel_test_utils import verify_http_connection
33from acts.test_utils.tel.tel_test_utils import WIFI_CONFIG_APBAND_2G
34from acts.test_utils.tel.tel_test_utils import WIFI_CONFIG_APBAND_5G
35from acts.test_utils.wifi import wifi_test_utils as wutils
Girish Moturuf72690e2017-02-14 15:19:53 -080036
Girish Moturu7f287522017-09-25 13:33:06 -070037WAIT_TIME = 2
Girish Moturuf72690e2017-02-14 15:19:53 -080038
39class WifiTetheringTest(base_test.BaseTestClass):
40 """ Tests for Wifi Tethering """
41
42 def setup_class(self):
43 """ Setup devices for tethering and unpack params """
Girish Moturu2c21eb32017-05-25 14:37:55 +053044
45 self.convert_byte_to_mb = 1024.0 * 1024.0
46 self.new_ssid = "wifi_tethering_test2"
Girish Moturu7df90e32017-10-16 12:49:56 -070047 self.data_usage_error = 1
Girish Moturu2c21eb32017-05-25 14:37:55 +053048
49 self.hotspot_device = self.android_devices[0]
50 self.tethered_devices = self.android_devices[1:]
51 req_params = ("network", "url", "download_file", "file_size")
Girish Moturuf72690e2017-02-14 15:19:53 -080052 self.unpack_userparams(req_params)
Girish Moturu2c21eb32017-05-25 14:37:55 +053053 self.file_size = int(self.file_size)
54
55 wutils.wifi_toggle_state(self.hotspot_device, False)
Girish Moturuf72690e2017-02-14 15:19:53 -080056 self.hotspot_device.droid.telephonyToggleDataConnection(True)
Girish Moturu2c21eb32017-05-25 14:37:55 +053057 wait_for_cell_data_connection(self.log, self.hotspot_device, True)
Girish Moturuf72690e2017-02-14 15:19:53 -080058 asserts.assert_true(
Girish Moturu2c21eb32017-05-25 14:37:55 +053059 verify_http_connection(self.log, self.hotspot_device),
Girish Moturuf72690e2017-02-14 15:19:53 -080060 "HTTP verification failed on cell data connection")
61 asserts.assert_true(
62 self.hotspot_device.droid.connectivityIsTetheringSupported(),
63 "Tethering is not supported for the provider")
Girish Moturu2c21eb32017-05-25 14:37:55 +053064 for ad in self.tethered_devices:
65 wutils.wifi_test_device_init(ad)
Girish Moturuf72690e2017-02-14 15:19:53 -080066
Girish Moturu7f287522017-09-25 13:33:06 -070067 # Set chrome browser start with no-first-run verification
68 # Give permission to read from and write to storage
69 commands = ["pm grant com.android.chrome "
70 "android.permission.READ_EXTERNAL_STORAGE",
71 "pm grant com.android.chrome "
72 "android.permission.WRITE_EXTERNAL_STORAGE",
73 "rm /data/local/chrome-command-line",
74 "am set-debug-app --persistent com.android.chrome",
75 'echo "chrome --no-default-browser-check --no-first-run '
76 '--disable-fre" > /data/local/tmp/chrome-command-line']
77 for cmd in commands:
78 for dut in self.tethered_devices:
79 try:
80 dut.adb.shell(cmd)
81 except adb.AdbError:
82 self.log.warn("adb command %s failed on %s"
83 % (cmd, dut.serial))
84
Girish Moturuf72690e2017-02-14 15:19:53 -080085 def teardown_class(self):
86 """ Reset devices """
Girish Moturu2c21eb32017-05-25 14:37:55 +053087 wutils.wifi_toggle_state(self.hotspot_device, True)
88
89 def on_fail(self, test_name, begin_time):
90 """ Collect bug report on failure """
91 self.hotspot_device.take_bug_report(test_name, begin_time)
Girish Moturu7df90e32017-10-16 12:49:56 -070092 for ad in self.tethered_devices:
93 ad.take_bug_report(test_name, begin_time)
Girish Moturuf72690e2017-02-14 15:19:53 -080094
95 """ Helper functions """
96
Girish Moturu2c21eb32017-05-25 14:37:55 +053097 def _is_ipaddress_ipv6(self, ip_address):
Girish Moturuf72690e2017-02-14 15:19:53 -080098 """ Verify if the given string is a valid IPv6 address
99
100 Args:
101 1. string which contains the IP address
102
103 Returns:
104 True: if valid ipv6 address
105 False: if not
106 """
107 try:
108 socket.inet_pton(socket.AF_INET6, ip_address)
109 return True
110 except socket.error:
111 return False
112
113 def _supports_ipv6_tethering(self, dut):
114 """ Check if provider supports IPv6 tethering.
115 Currently, only Verizon supports IPv6 tethering
116
117 Returns:
118 True: if provider supports IPv6 tethering
119 False: if not
120 """
121 # Currently only Verizon support IPv6 tethering
122 carrier_supports_tethering = ["vzw"]
Girish Moturu2c21eb32017-05-25 14:37:55 +0530123 operator = get_operator_name(self.log, dut)
Girish Moturuf72690e2017-02-14 15:19:53 -0800124 return operator in carrier_supports_tethering
125
Girish Moturu2c21eb32017-05-25 14:37:55 +0530126 def _carrier_supports_ipv6(self,dut):
127 """ Verify if carrier supports ipv6
128 Currently, only verizon and t-mobile supports IPv6
129
130 Returns:
131 True: if carrier supports ipv6
132 False: if not
133 """
134 carrier_supports_ipv6 = ["vzw", "tmo"]
135 operator = get_operator_name(self.log, dut)
Girish Moturu7f287522017-09-25 13:33:06 -0700136 self.log.info("Carrier is %s" % operator)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530137 return operator in carrier_supports_ipv6
138
Girish Moturu2c21eb32017-05-25 14:37:55 +0530139 def _verify_ipv6_tethering(self, dut):
Girish Moturuf72690e2017-02-14 15:19:53 -0800140 """ Verify IPv6 tethering """
141 http_response = dut.droid.httpRequestString(self.url)
Girish Moturuf72690e2017-02-14 15:19:53 -0800142 self.log.info("IP address %s " % http_response)
Girish Moturu0fd0b942017-12-12 12:04:56 -0800143 active_link_addrs = dut.droid.connectivityGetAllAddressesOfActiveLink()
Girish Moturu2c21eb32017-05-25 14:37:55 +0530144 if dut==self.hotspot_device and self._carrier_supports_ipv6(dut)\
145 or self._supports_ipv6_tethering(self.hotspot_device):
Girish Moturuf72690e2017-02-14 15:19:53 -0800146 asserts.assert_true(self._is_ipaddress_ipv6(http_response),
147 "The http response did not return IPv6 address")
Girish Moturu0fd0b942017-12-12 12:04:56 -0800148 asserts.assert_true(
149 active_link_addrs and http_response in str(active_link_addrs),
150 "Could not find IPv6 address in link properties")
151 asserts.assert_true(
152 dut.droid.connectivityHasIPv6DefaultRoute(),
153 "Could not find IPv6 default route in link properties")
Girish Moturuf72690e2017-02-14 15:19:53 -0800154 else:
Girish Moturu0fd0b942017-12-12 12:04:56 -0800155 asserts.assert_true(
156 not dut.droid.connectivityHasIPv6DefaultRoute(),
157 "Found IPv6 default route in link properties")
Girish Moturuf72690e2017-02-14 15:19:53 -0800158
Girish Moturu2c21eb32017-05-25 14:37:55 +0530159 def _start_wifi_tethering(self, wifi_band=WIFI_CONFIG_APBAND_2G):
160 """ Start wifi tethering on hotspot device
161
162 Args:
163 1. wifi_band: specifies the wifi band to start the hotspot
164 on. The current options are 2G and 5G
165 """
166 wutils.start_wifi_tethering(self.hotspot_device,
167 self.network[wutils.WifiEnums.SSID_KEY],
168 self.network[wutils.WifiEnums.PWD_KEY],
169 wifi_band)
170
171 def _connect_disconnect_devices(self):
172 """ Randomly connect and disconnect devices from the
173 self.tethered_devices list to hotspot device
174 """
175 device_connected = [ False ] * len(self.tethered_devices)
176 for _ in range(50):
177 dut_id = random.randint(0, len(self.tethered_devices)-1)
178 dut = self.tethered_devices[dut_id]
Girish Moturu7df90e32017-10-16 12:49:56 -0700179 # wait for 1 sec between connect & disconnect stress test
180 time.sleep(1)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530181 if device_connected[dut_id]:
182 wutils.wifi_forget_network(dut, self.network["SSID"])
183 else:
184 wutils.wifi_connect(dut, self.network)
185 device_connected[dut_id] = not device_connected[dut_id]
186
Girish Moturu7f287522017-09-25 13:33:06 -0700187 def _verify_ping(self, dut, ip, isIPv6=False):
Girish Moturu2c21eb32017-05-25 14:37:55 +0530188 """ Verify ping works from the dut to IP/hostname
189
190 Args:
191 1. dut - ad object to check ping from
192 2. ip - ip/hostname to ping (IPv4 and IPv6)
193
194 Returns:
195 True - if ping is successful
196 False - if not
197 """
198 self.log.info("Pinging %s from dut %s" % (ip, dut.serial))
Girish Moturu7f287522017-09-25 13:33:06 -0700199 if isIPv6 or self._is_ipaddress_ipv6(ip):
Girish Moturu2c21eb32017-05-25 14:37:55 +0530200 return dut.droid.pingHost(ip, 5, "ping6")
201 return dut.droid.pingHost(ip)
202
203 def _return_ip_for_interface(self, dut, iface_name):
204 """ Return list of IP addresses for an interface
205
206 Args:
207 1. dut - ad object
208 2. iface_name - interface name
209
210 Returns:
211 List of IPv4 and IPv6 addresses
212 """
213 return dut.droid.connectivityGetIPv4Addresses(iface_name) + \
214 dut.droid.connectivityGetIPv6Addresses(iface_name)
215
216 def _test_traffic_between_two_tethered_devices(self, dut1, dut2):
217 """ Verify pinging interfaces of one DUT from another
218
219 Args:
220 1. dut1 - tethered device 1
221 2. dut2 - tethered device 2
222 """
223 wutils.wifi_connect(dut1, self.network)
224 wutils.wifi_connect(dut2, self.network)
225
226 dut1_ipaddrs = dut1.droid.connectivityGetIPv4Addresses("wlan0") + \
227 dut1.droid.connectivityGetIPv6Addresses("wlan0")
228 dut2_ipaddrs = dut2.droid.connectivityGetIPv4Addresses("wlan0") + \
229 dut2.droid.connectivityGetIPv6Addresses("wlan0")
230
231 for ip in dut1_ipaddrs:
232 asserts.assert_true(self._verify_ping(dut2, ip), "%s " % ip)
233 for ip in dut2_ipaddrs:
234 asserts.assert_true(self._verify_ping(dut1, ip), "%s " % ip)
235
236 def _ping_hotspot_interfaces_from_tethered_device(self, dut):
237 """ Ping hotspot interfaces from tethered device
238
239 Args:
240 1. dut - tethered device
241
242 Returns:
243 True - if all IP addresses are pingable
244 False - if not
245 """
246 ifaces = self.hotspot_device.droid.connectivityGetNetworkInterfaces()
247 return_result = True
248 for interface in ifaces:
249 iface_name = interface.split()[0].split(':')[1]
250 if iface_name == "lo":
251 continue
252 ip_list = self._return_ip_for_interface(
253 self.hotspot_device, iface_name)
254 for ip in ip_list:
255 ping_result = self._verify_ping(dut, ip)
256 self.log.info("Ping result: %s %s %s" %
257 (iface_name, ip, ping_result))
258 return_result = return_result and ping_result
259
260 return return_result
Girish Moturuf72690e2017-02-14 15:19:53 -0800261
262 """ Test Cases """
263
Girish Moturu2c21eb32017-05-25 14:37:55 +0530264 @test_tracker_info(uuid="36d03295-bea3-446e-8342-b9f8f1962a32")
Girish Moturuf72690e2017-02-14 15:19:53 -0800265 def test_ipv6_tethering(self):
266 """ IPv6 tethering test
267
268 Steps:
Girish Moturu2c21eb32017-05-25 14:37:55 +0530269 1. Start wifi tethering on hotspot device
Girish Moturu7df90e32017-10-16 12:49:56 -0700270 2. Verify IPv6 address on hotspot device (VZW & TMO only)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530271 3. Connect tethered device to hotspot device
Girish Moturu7df90e32017-10-16 12:49:56 -0700272 4. Verify IPv6 address on the client's link properties (VZW only)
273 5. Verify ping on client using ping6 which should pass (VZW only)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530274 6. Disable mobile data on provider and verify that link properties
Girish Moturu7df90e32017-10-16 12:49:56 -0700275 does not have IPv6 address and default route (VZW only)
Girish Moturuf72690e2017-02-14 15:19:53 -0800276 """
277 # Start wifi tethering on the hotspot device
Girish Moturu2c21eb32017-05-25 14:37:55 +0530278 wutils.toggle_wifi_off_and_on(self.hotspot_device)
279 self._start_wifi_tethering()
Girish Moturuf72690e2017-02-14 15:19:53 -0800280
281 # Verify link properties on hotspot device
Girish Moturu7f287522017-09-25 13:33:06 -0700282 self.log.info("Check IPv6 properties on the hotspot device. "
283 "Verizon & T-mobile should have IPv6 in link properties")
Girish Moturuf72690e2017-02-14 15:19:53 -0800284 self._verify_ipv6_tethering(self.hotspot_device)
285
286 # Connect the client to the SSID
Girish Moturu2c21eb32017-05-25 14:37:55 +0530287 wutils.wifi_connect(self.tethered_devices[0], self.network)
Girish Moturuf72690e2017-02-14 15:19:53 -0800288
289 # Need to wait atleast 2 seconds for IPv6 address to
290 # show up in the link properties
Girish Moturu7f287522017-09-25 13:33:06 -0700291 time.sleep(WAIT_TIME)
Girish Moturuf72690e2017-02-14 15:19:53 -0800292
293 # Verify link properties on tethered device
Girish Moturu7f287522017-09-25 13:33:06 -0700294 self.log.info("Check IPv6 properties on the tethered device. "
295 "Device should have IPv6 if carrier is Verizon")
Girish Moturu2c21eb32017-05-25 14:37:55 +0530296 self._verify_ipv6_tethering(self.tethered_devices[0])
Girish Moturuf72690e2017-02-14 15:19:53 -0800297
298 # Verify ping6 on tethered device
Girish Moturu2c21eb32017-05-25 14:37:55 +0530299 ping_result = self._verify_ping(self.tethered_devices[0],
Girish Moturu7f287522017-09-25 13:33:06 -0700300 wutils.DEFAULT_PING_ADDR, True)
Girish Moturuf72690e2017-02-14 15:19:53 -0800301 if self._supports_ipv6_tethering(self.hotspot_device):
302 asserts.assert_true(ping_result, "Ping6 failed on the client")
303 else:
304 asserts.assert_true(not ping_result, "Ping6 failed as expected")
305
306 # Disable mobile data on hotspot device
307 # and verify the link properties on tethered device
Girish Moturu2c21eb32017-05-25 14:37:55 +0530308 self.log.info("Disabling mobile data to verify ipv6 default route")
Girish Moturuf72690e2017-02-14 15:19:53 -0800309 self.hotspot_device.droid.telephonyToggleDataConnection(False)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530310 asserts.assert_equal(
311 self.hotspot_device.droid.telephonyGetDataConnectionState(),
312 tel_defines.DATA_STATE_CONNECTED,
313 "Could not disable cell data")
314
Girish Moturu7f287522017-09-25 13:33:06 -0700315 time.sleep(WAIT_TIME) # wait until the IPv6 is removed from link properties
Girish Moturu2c21eb32017-05-25 14:37:55 +0530316
Girish Moturu0fd0b942017-12-12 12:04:56 -0800317 result = self.tethered_devices[0].droid.connectivityHasIPv6DefaultRoute()
Girish Moturu2c21eb32017-05-25 14:37:55 +0530318 self.hotspot_device.droid.telephonyToggleDataConnection(True)
Girish Moturu7df90e32017-10-16 12:49:56 -0700319 if result:
Girish Moturu2c21eb32017-05-25 14:37:55 +0530320 asserts.fail("Found IPv6 default route in link properties:Data off")
Girish Moturu7df90e32017-10-16 12:49:56 -0700321 self.log.info("Did not find IPv6 address in link properties")
Girish Moturu2c21eb32017-05-25 14:37:55 +0530322
323 # Disable wifi tethering
324 wutils.stop_wifi_tethering(self.hotspot_device)
325
326 @test_tracker_info(uuid="110b61d1-8af2-4589-8413-11beac7a3025")
Girish Moturu7df90e32017-10-16 12:49:56 -0700327 def wifi_tethering_2ghz_traffic_between_2tethered_devices(self):
Girish Moturu2c21eb32017-05-25 14:37:55 +0530328 """ Steps:
329
330 1. Start wifi hotspot with 2G band
331 2. Connect 2 tethered devices to the hotspot device
332 3. Ping interfaces between the tethered devices
333 """
334 wutils.toggle_wifi_off_and_on(self.hotspot_device)
335 self._start_wifi_tethering(WIFI_CONFIG_APBAND_2G)
336 self._test_traffic_between_two_tethered_devices(self.tethered_devices[0],
337 self.tethered_devices[1])
338 wutils.stop_wifi_tethering(self.hotspot_device)
339
340 @test_tracker_info(uuid="953f6e2e-27bd-4b73-85a6-d2eaa4e755d5")
Girish Moturu7df90e32017-10-16 12:49:56 -0700341 def wifi_tethering_5ghz_traffic_between_2tethered_devices(self):
Girish Moturu2c21eb32017-05-25 14:37:55 +0530342 """ Steps:
343
344 1. Start wifi hotspot with 5ghz band
345 2. Connect 2 tethered devices to the hotspot device
346 3. Send traffic between the tethered devices
347 """
348 wutils.toggle_wifi_off_and_on(self.hotspot_device)
349 self._start_wifi_tethering(WIFI_CONFIG_APBAND_5G)
350 self._test_traffic_between_two_tethered_devices(self.tethered_devices[0],
351 self.tethered_devices[1])
352 wutils.stop_wifi_tethering(self.hotspot_device)
353
354 @test_tracker_info(uuid="d7d5aa51-682d-4882-a334-61966d93b68c")
355 def test_wifi_tethering_2ghz_connect_disconnect_devices(self):
356 """ Steps:
357
358 1. Start wifi hotspot with 2ghz band
359 2. Connect and disconnect multiple devices randomly
360 3. Verify the correct functionality
361 """
362 wutils.toggle_wifi_off_and_on(self.hotspot_device)
363 self._start_wifi_tethering(WIFI_CONFIG_APBAND_2G)
364 self._connect_disconnect_devices()
365 wutils.stop_wifi_tethering(self.hotspot_device)
366
367 @test_tracker_info(uuid="34abd6c9-c7f1-4d89-aa2b-a66aeabed9aa")
368 def test_wifi_tethering_5ghz_connect_disconnect_devices(self):
369 """ Steps:
370
371 1. Start wifi hotspot with 5ghz band
372 2. Connect and disconnect multiple devices randomly
373 3. Verify the correct functionality
374 """
375 wutils.toggle_wifi_off_and_on(self.hotspot_device)
376 self._start_wifi_tethering(WIFI_CONFIG_APBAND_5G)
377 self._connect_disconnect_devices()
378 wutils.stop_wifi_tethering(self.hotspot_device)
379
380 @test_tracker_info(uuid="7edfb220-37f8-42ea-8d7c-39712fbe9be5")
381 def test_wifi_tethering_2ghz_ping_hotspot_interfaces(self):
382 """ Steps:
383
384 1. Start wifi hotspot with 2ghz band
385 2. Connect tethered device to hotspot device
386 3. Ping 'wlan0' and 'rmnet_data' interface's IPv4
387 and IPv6 interfaces on hotspot device from tethered device
388 """
389 wutils.toggle_wifi_off_and_on(self.hotspot_device)
390 self._start_wifi_tethering(WIFI_CONFIG_APBAND_2G)
391 wutils.wifi_connect(self.tethered_devices[0], self.network)
392 result = self._ping_hotspot_interfaces_from_tethered_device(
393 self.tethered_devices[0])
394 wutils.stop_wifi_tethering(self.hotspot_device)
395 return result
396
397 @test_tracker_info(uuid="17e450f4-795f-4e67-adab-984940dffedc")
398 def test_wifi_tethering_5ghz_ping_hotspot_interfaces(self):
399 """ Steps:
400
401 1. Start wifi hotspot with 5ghz band
402 2. Connect tethered device to hotspot device
403 3. Ping 'wlan0' and 'rmnet_data' interface's IPv4
404 and IPv6 interfaces on hotspot device from tethered device
405 """
406 wutils.toggle_wifi_off_and_on(self.hotspot_device)
407 self._start_wifi_tethering(WIFI_CONFIG_APBAND_5G)
408 wutils.wifi_connect(self.tethered_devices[0], self.network)
409 result = self._ping_hotspot_interfaces_from_tethered_device(
410 self.tethered_devices[0])
411 wutils.stop_wifi_tethering(self.hotspot_device)
412 return result
413
414 @test_tracker_info(uuid="d4e18031-0af0-4b29-a574-8707cd4029b7")
415 def test_wifi_tethering_verify_received_bytes(self):
416 """ Steps:
417
418 1. Start wifi hotspot and connect tethered device to it
419 2. Get the data usage on hotspot device
420 3. Download data on tethered device
421 4. Get the new data usage on hotspot device
422 5. Verify that hotspot device's data usage
423 increased by downloaded file size
424 """
425 wutils.toggle_wifi_off_and_on(self.hotspot_device)
426 dut = self.hotspot_device
427 self._start_wifi_tethering()
428 wutils.wifi_connect(self.tethered_devices[0], self.network)
429 subscriber_id = dut.droid.telephonyGetSubscriberId()
430
431 # get data usage limit
432 end_time = int(time.time() * 1000)
433 bytes_before_download = dut.droid.connectivityGetRxBytesForDevice(
434 subscriber_id, 0, end_time)
Girish Moturu7df90e32017-10-16 12:49:56 -0700435 self.log.info("Data usage before download: %s MB" %
436 (bytes_before_download/self.convert_byte_to_mb))
Girish Moturu2c21eb32017-05-25 14:37:55 +0530437
438 # download file
Girish Moturu7f287522017-09-25 13:33:06 -0700439 self.log.info("Download file of size %sMB" % self.file_size)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530440 http_file_download_by_chrome(self.tethered_devices[0],
Girish Moturu0fd0b942017-12-12 12:04:56 -0800441 self.download_file,
442 self.file_size)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530443
444 # get data usage limit after download
445 end_time = int(time.time() * 1000)
446 bytes_after_download = dut.droid.connectivityGetRxBytesForDevice(
447 subscriber_id, 0, end_time)
Girish Moturu7df90e32017-10-16 12:49:56 -0700448 self.log.info("Data usage after download: %s MB" %
449 (bytes_after_download/self.convert_byte_to_mb))
Girish Moturu2c21eb32017-05-25 14:37:55 +0530450
451 bytes_diff = bytes_after_download - bytes_before_download
452 wutils.stop_wifi_tethering(self.hotspot_device)
453
454 # verify data usage update is correct
455 bytes_used = bytes_diff/self.convert_byte_to_mb
Girish Moturu7f287522017-09-25 13:33:06 -0700456 self.log.info("Data usage on the device increased by %s" % bytes_used)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530457 return bytes_used > self.file_size \
458 and bytes_used < self.file_size + self.data_usage_error
459
460 @test_tracker_info(uuid="07a00c96-4770-44a1-a9db-b3d02d6a12b6")
461 def test_wifi_tethering_data_usage_limit(self):
462 """ Steps:
463
Girish Moturu7df90e32017-10-16 12:49:56 -0700464 1. Set the data usage limit to current data usage + 10MB
Girish Moturu2c21eb32017-05-25 14:37:55 +0530465 2. Start wifi tethering and connect a dut to the SSID
Girish Moturu7df90e32017-10-16 12:49:56 -0700466 3. Download 20MB data on tethered device
Girish Moturu2c21eb32017-05-25 14:37:55 +0530467 a. file download should stop
468 b. tethered device will lose internet connectivity
469 c. data usage limit reached message should be displayed
470 on the hotspot device
471 4. Verify data usage limit
472 """
473 wutils.toggle_wifi_off_and_on(self.hotspot_device)
474 dut = self.hotspot_device
Girish Moturu7df90e32017-10-16 12:49:56 -0700475 data_usage_inc = 10 * self.convert_byte_to_mb
Girish Moturu2c21eb32017-05-25 14:37:55 +0530476 subscriber_id = dut.droid.telephonyGetSubscriberId()
477
478 self._start_wifi_tethering()
479 wutils.wifi_connect(self.tethered_devices[0], self.network)
480
481 # get current data usage
482 end_time = int(time.time() * 1000)
483 old_data_usage = dut.droid.connectivityQuerySummaryForDevice(
484 subscriber_id, 0, end_time)
485
Girish Moturu7df90e32017-10-16 12:49:56 -0700486 # set data usage limit to current usage limit + 10MB
Girish Moturu2c21eb32017-05-25 14:37:55 +0530487 dut.droid.connectivitySetDataUsageLimit(
Girish Moturu7df90e32017-10-16 12:49:56 -0700488 subscriber_id, str(int(old_data_usage + data_usage_inc)))
Girish Moturu2c21eb32017-05-25 14:37:55 +0530489
Girish Moturu7df90e32017-10-16 12:49:56 -0700490 # download file - size 20MB
Girish Moturu2c21eb32017-05-25 14:37:55 +0530491 http_file_download_by_chrome(self.tethered_devices[0],
492 self.download_file,
Girish Moturu0fd0b942017-12-12 12:04:56 -0800493 self.file_size,
Girish Moturu2c21eb32017-05-25 14:37:55 +0530494 timeout=120)
495 end_time = int(time.time() * 1000)
496 new_data_usage = dut.droid.connectivityQuerySummaryForDevice(
497 subscriber_id, 0, end_time)
498
499 # test network connectivity on tethered device
500 asserts.assert_true(
501 not wutils.validate_connection(self.tethered_devices[0]),
502 "Tethered device has internet connectivity after data usage"
503 "limit is reached on hotspot device")
504 dut.droid.connectivityFactoryResetNetworkPolicies(subscriber_id)
505 wutils.stop_wifi_tethering(self.hotspot_device)
506
Girish Moturu7df90e32017-10-16 12:49:56 -0700507 old_data_usage = (old_data_usage+data_usage_inc)/self.convert_byte_to_mb
Girish Moturu2c21eb32017-05-25 14:37:55 +0530508 new_data_usage = new_data_usage/self.convert_byte_to_mb
Girish Moturu7df90e32017-10-16 12:49:56 -0700509 self.log.info("Expected data usage: %s MB" % old_data_usage)
510 self.log.info("Actual data usage: %s MB" % new_data_usage)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530511
512 return (new_data_usage-old_data_usage) < self.data_usage_error
513
514 @test_tracker_info(uuid="2bc344cb-0277-4f06-b6cc-65b3972086ed")
515 def test_change_wifi_hotspot_ssid_when_hotspot_enabled(self):
516 """ Steps:
517
518 1. Start wifi tethering
519 2. Verify wifi Ap configuration
520 3. Change the SSID of the wifi hotspot while hotspot is on
521 4. Verify the new SSID in wifi ap configuration
522 5. Restart tethering and verify that the tethered device is able
523 to connect to the new SSID
524 """
525 wutils.toggle_wifi_off_and_on(self.hotspot_device)
526 dut = self.hotspot_device
527
528 # start tethering and verify the wifi ap configuration settings
529 self._start_wifi_tethering()
530 wifi_ap = dut.droid.wifiGetApConfiguration()
531 asserts.assert_true(
532 wifi_ap[wutils.WifiEnums.SSID_KEY] == \
533 self.network[wutils.WifiEnums.SSID_KEY],
534 "Configured wifi hotspot SSID did not match with the expected SSID")
535 wutils.wifi_connect(self.tethered_devices[0], self.network)
536
537 # update the wifi ap configuration with new ssid
538 config = {wutils.WifiEnums.SSID_KEY: self.new_ssid}
539 config[wutils.WifiEnums.PWD_KEY] = self.network[wutils.WifiEnums.PWD_KEY]
540 config[wutils.WifiEnums.APBAND_KEY] = WIFI_CONFIG_APBAND_2G
541 asserts.assert_true(
542 dut.droid.wifiSetWifiApConfiguration(config),
543 "Failed to update WifiAp Configuration")
544 wifi_ap = dut.droid.wifiGetApConfiguration()
545 asserts.assert_true(
546 wifi_ap[wutils.WifiEnums.SSID_KEY] == self.new_ssid,
547 "Configured wifi hotspot SSID does not match with the expected SSID")
548
549 # start wifi tethering with new wifi ap configuration
550 wutils.stop_wifi_tethering(dut)
551 dut.droid.wifiStartTrackingTetherStateChange()
552 dut.droid.connectivityStartTethering(tel_defines.TETHERING_WIFI, False)
553 try:
554 dut.ed.pop_event("ConnectivityManagerOnTetheringStarted")
555 dut.ed.wait_for_event("TetherStateChanged",
556 lambda x: x["data"]["ACTIVE_TETHER"], 30)
557 except:
558 asserts.fail("Didn't receive wifi tethering starting confirmation")
559 dut.droid.wifiStopTrackingTetherStateChange()
560
561 # verify dut can connect to new wifi ap configuration
562 new_network = {wutils.WifiEnums.SSID_KEY: self.new_ssid,
563 wutils.WifiEnums.PWD_KEY: \
564 self.network[wutils.WifiEnums.PWD_KEY]}
565 wutils.wifi_connect(self.tethered_devices[0], new_network)
566 wutils.stop_wifi_tethering(self.hotspot_device)