blob: d471290f4f702e6c98265665470c7576c97140e7 [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:
Girish Moturu9bd1e9a2017-12-14 10:10:25 -080065 ad.droid.telephonyToggleDataConnection(False)
Girish Moturu2c21eb32017-05-25 14:37:55 +053066 wutils.wifi_test_device_init(ad)
Girish Moturuf72690e2017-02-14 15:19:53 -080067
Girish Moturu7f287522017-09-25 13:33:06 -070068 # Set chrome browser start with no-first-run verification
69 # Give permission to read from and write to storage
70 commands = ["pm grant com.android.chrome "
71 "android.permission.READ_EXTERNAL_STORAGE",
72 "pm grant com.android.chrome "
73 "android.permission.WRITE_EXTERNAL_STORAGE",
74 "rm /data/local/chrome-command-line",
75 "am set-debug-app --persistent com.android.chrome",
76 'echo "chrome --no-default-browser-check --no-first-run '
77 '--disable-fre" > /data/local/tmp/chrome-command-line']
78 for cmd in commands:
79 for dut in self.tethered_devices:
80 try:
81 dut.adb.shell(cmd)
82 except adb.AdbError:
83 self.log.warn("adb command %s failed on %s"
84 % (cmd, dut.serial))
85
Girish Moturuf72690e2017-02-14 15:19:53 -080086 def teardown_class(self):
87 """ Reset devices """
Girish Moturu2c21eb32017-05-25 14:37:55 +053088 wutils.wifi_toggle_state(self.hotspot_device, True)
Girish Moturu9bd1e9a2017-12-14 10:10:25 -080089 for ad in self.tethered_devices:
90 ad.droid.telephonyToggleDataConnection(True)
Girish Moturu2c21eb32017-05-25 14:37:55 +053091
92 def on_fail(self, test_name, begin_time):
93 """ Collect bug report on failure """
94 self.hotspot_device.take_bug_report(test_name, begin_time)
Girish Moturu7df90e32017-10-16 12:49:56 -070095 for ad in self.tethered_devices:
96 ad.take_bug_report(test_name, begin_time)
Girish Moturuf72690e2017-02-14 15:19:53 -080097
98 """ Helper functions """
99
Girish Moturu2c21eb32017-05-25 14:37:55 +0530100 def _is_ipaddress_ipv6(self, ip_address):
Girish Moturuf72690e2017-02-14 15:19:53 -0800101 """ Verify if the given string is a valid IPv6 address
102
103 Args:
104 1. string which contains the IP address
105
106 Returns:
107 True: if valid ipv6 address
108 False: if not
109 """
110 try:
111 socket.inet_pton(socket.AF_INET6, ip_address)
112 return True
113 except socket.error:
114 return False
115
116 def _supports_ipv6_tethering(self, dut):
117 """ Check if provider supports IPv6 tethering.
118 Currently, only Verizon supports IPv6 tethering
119
120 Returns:
121 True: if provider supports IPv6 tethering
122 False: if not
123 """
124 # Currently only Verizon support IPv6 tethering
125 carrier_supports_tethering = ["vzw"]
Girish Moturu2c21eb32017-05-25 14:37:55 +0530126 operator = get_operator_name(self.log, dut)
Girish Moturuf72690e2017-02-14 15:19:53 -0800127 return operator in carrier_supports_tethering
128
Girish Moturu2c21eb32017-05-25 14:37:55 +0530129 def _carrier_supports_ipv6(self,dut):
130 """ Verify if carrier supports ipv6
131 Currently, only verizon and t-mobile supports IPv6
132
133 Returns:
134 True: if carrier supports ipv6
135 False: if not
136 """
137 carrier_supports_ipv6 = ["vzw", "tmo"]
138 operator = get_operator_name(self.log, dut)
Girish Moturu7f287522017-09-25 13:33:06 -0700139 self.log.info("Carrier is %s" % operator)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530140 return operator in carrier_supports_ipv6
141
Girish Moturu2c21eb32017-05-25 14:37:55 +0530142 def _verify_ipv6_tethering(self, dut):
Girish Moturuf72690e2017-02-14 15:19:53 -0800143 """ Verify IPv6 tethering """
144 http_response = dut.droid.httpRequestString(self.url)
Girish Moturuf72690e2017-02-14 15:19:53 -0800145 self.log.info("IP address %s " % http_response)
Girish Moturu0fd0b942017-12-12 12:04:56 -0800146 active_link_addrs = dut.droid.connectivityGetAllAddressesOfActiveLink()
Girish Moturu2c21eb32017-05-25 14:37:55 +0530147 if dut==self.hotspot_device and self._carrier_supports_ipv6(dut)\
148 or self._supports_ipv6_tethering(self.hotspot_device):
Girish Moturuf72690e2017-02-14 15:19:53 -0800149 asserts.assert_true(self._is_ipaddress_ipv6(http_response),
150 "The http response did not return IPv6 address")
Girish Moturu0fd0b942017-12-12 12:04:56 -0800151 asserts.assert_true(
152 active_link_addrs and http_response in str(active_link_addrs),
153 "Could not find IPv6 address in link properties")
154 asserts.assert_true(
155 dut.droid.connectivityHasIPv6DefaultRoute(),
156 "Could not find IPv6 default route in link properties")
Girish Moturuf72690e2017-02-14 15:19:53 -0800157 else:
Girish Moturu0fd0b942017-12-12 12:04:56 -0800158 asserts.assert_true(
159 not dut.droid.connectivityHasIPv6DefaultRoute(),
160 "Found IPv6 default route in link properties")
Girish Moturuf72690e2017-02-14 15:19:53 -0800161
Girish Moturu2c21eb32017-05-25 14:37:55 +0530162 def _start_wifi_tethering(self, wifi_band=WIFI_CONFIG_APBAND_2G):
163 """ Start wifi tethering on hotspot device
164
165 Args:
166 1. wifi_band: specifies the wifi band to start the hotspot
167 on. The current options are 2G and 5G
168 """
169 wutils.start_wifi_tethering(self.hotspot_device,
170 self.network[wutils.WifiEnums.SSID_KEY],
171 self.network[wutils.WifiEnums.PWD_KEY],
172 wifi_band)
173
174 def _connect_disconnect_devices(self):
175 """ Randomly connect and disconnect devices from the
176 self.tethered_devices list to hotspot device
177 """
178 device_connected = [ False ] * len(self.tethered_devices)
179 for _ in range(50):
180 dut_id = random.randint(0, len(self.tethered_devices)-1)
181 dut = self.tethered_devices[dut_id]
Girish Moturu7df90e32017-10-16 12:49:56 -0700182 # wait for 1 sec between connect & disconnect stress test
183 time.sleep(1)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530184 if device_connected[dut_id]:
185 wutils.wifi_forget_network(dut, self.network["SSID"])
186 else:
187 wutils.wifi_connect(dut, self.network)
188 device_connected[dut_id] = not device_connected[dut_id]
189
Girish Moturu7f287522017-09-25 13:33:06 -0700190 def _verify_ping(self, dut, ip, isIPv6=False):
Girish Moturu2c21eb32017-05-25 14:37:55 +0530191 """ Verify ping works from the dut to IP/hostname
192
193 Args:
194 1. dut - ad object to check ping from
195 2. ip - ip/hostname to ping (IPv4 and IPv6)
196
197 Returns:
198 True - if ping is successful
199 False - if not
200 """
201 self.log.info("Pinging %s from dut %s" % (ip, dut.serial))
Girish Moturu7f287522017-09-25 13:33:06 -0700202 if isIPv6 or self._is_ipaddress_ipv6(ip):
Girish Moturu2c21eb32017-05-25 14:37:55 +0530203 return dut.droid.pingHost(ip, 5, "ping6")
204 return dut.droid.pingHost(ip)
205
206 def _return_ip_for_interface(self, dut, iface_name):
207 """ Return list of IP addresses for an interface
208
209 Args:
210 1. dut - ad object
211 2. iface_name - interface name
212
213 Returns:
214 List of IPv4 and IPv6 addresses
215 """
216 return dut.droid.connectivityGetIPv4Addresses(iface_name) + \
217 dut.droid.connectivityGetIPv6Addresses(iface_name)
218
219 def _test_traffic_between_two_tethered_devices(self, dut1, dut2):
220 """ Verify pinging interfaces of one DUT from another
221
222 Args:
223 1. dut1 - tethered device 1
224 2. dut2 - tethered device 2
225 """
226 wutils.wifi_connect(dut1, self.network)
227 wutils.wifi_connect(dut2, self.network)
228
229 dut1_ipaddrs = dut1.droid.connectivityGetIPv4Addresses("wlan0") + \
230 dut1.droid.connectivityGetIPv6Addresses("wlan0")
231 dut2_ipaddrs = dut2.droid.connectivityGetIPv4Addresses("wlan0") + \
232 dut2.droid.connectivityGetIPv6Addresses("wlan0")
233
234 for ip in dut1_ipaddrs:
235 asserts.assert_true(self._verify_ping(dut2, ip), "%s " % ip)
236 for ip in dut2_ipaddrs:
237 asserts.assert_true(self._verify_ping(dut1, ip), "%s " % ip)
238
239 def _ping_hotspot_interfaces_from_tethered_device(self, dut):
240 """ Ping hotspot interfaces from tethered device
241
242 Args:
243 1. dut - tethered device
244
245 Returns:
246 True - if all IP addresses are pingable
247 False - if not
248 """
249 ifaces = self.hotspot_device.droid.connectivityGetNetworkInterfaces()
250 return_result = True
251 for interface in ifaces:
252 iface_name = interface.split()[0].split(':')[1]
253 if iface_name == "lo":
254 continue
255 ip_list = self._return_ip_for_interface(
256 self.hotspot_device, iface_name)
257 for ip in ip_list:
258 ping_result = self._verify_ping(dut, ip)
259 self.log.info("Ping result: %s %s %s" %
260 (iface_name, ip, ping_result))
261 return_result = return_result and ping_result
262
263 return return_result
Girish Moturuf72690e2017-02-14 15:19:53 -0800264
265 """ Test Cases """
266
Girish Moturu2c21eb32017-05-25 14:37:55 +0530267 @test_tracker_info(uuid="36d03295-bea3-446e-8342-b9f8f1962a32")
Girish Moturuf72690e2017-02-14 15:19:53 -0800268 def test_ipv6_tethering(self):
269 """ IPv6 tethering test
270
271 Steps:
Girish Moturu2c21eb32017-05-25 14:37:55 +0530272 1. Start wifi tethering on hotspot device
Girish Moturu7df90e32017-10-16 12:49:56 -0700273 2. Verify IPv6 address on hotspot device (VZW & TMO only)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530274 3. Connect tethered device to hotspot device
Girish Moturu7df90e32017-10-16 12:49:56 -0700275 4. Verify IPv6 address on the client's link properties (VZW only)
276 5. Verify ping on client using ping6 which should pass (VZW only)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530277 6. Disable mobile data on provider and verify that link properties
Girish Moturu7df90e32017-10-16 12:49:56 -0700278 does not have IPv6 address and default route (VZW only)
Girish Moturuf72690e2017-02-14 15:19:53 -0800279 """
280 # Start wifi tethering on the hotspot device
Girish Moturu2c21eb32017-05-25 14:37:55 +0530281 wutils.toggle_wifi_off_and_on(self.hotspot_device)
282 self._start_wifi_tethering()
Girish Moturuf72690e2017-02-14 15:19:53 -0800283
284 # Verify link properties on hotspot device
Girish Moturu7f287522017-09-25 13:33:06 -0700285 self.log.info("Check IPv6 properties on the hotspot device. "
286 "Verizon & T-mobile should have IPv6 in link properties")
Girish Moturuf72690e2017-02-14 15:19:53 -0800287 self._verify_ipv6_tethering(self.hotspot_device)
288
289 # Connect the client to the SSID
Girish Moturu2c21eb32017-05-25 14:37:55 +0530290 wutils.wifi_connect(self.tethered_devices[0], self.network)
Girish Moturuf72690e2017-02-14 15:19:53 -0800291
292 # Need to wait atleast 2 seconds for IPv6 address to
293 # show up in the link properties
Girish Moturu7f287522017-09-25 13:33:06 -0700294 time.sleep(WAIT_TIME)
Girish Moturuf72690e2017-02-14 15:19:53 -0800295
296 # Verify link properties on tethered device
Girish Moturu7f287522017-09-25 13:33:06 -0700297 self.log.info("Check IPv6 properties on the tethered device. "
298 "Device should have IPv6 if carrier is Verizon")
Girish Moturu2c21eb32017-05-25 14:37:55 +0530299 self._verify_ipv6_tethering(self.tethered_devices[0])
Girish Moturuf72690e2017-02-14 15:19:53 -0800300
301 # Verify ping6 on tethered device
Girish Moturu2c21eb32017-05-25 14:37:55 +0530302 ping_result = self._verify_ping(self.tethered_devices[0],
Girish Moturu7f287522017-09-25 13:33:06 -0700303 wutils.DEFAULT_PING_ADDR, True)
Girish Moturuf72690e2017-02-14 15:19:53 -0800304 if self._supports_ipv6_tethering(self.hotspot_device):
305 asserts.assert_true(ping_result, "Ping6 failed on the client")
306 else:
307 asserts.assert_true(not ping_result, "Ping6 failed as expected")
308
309 # Disable mobile data on hotspot device
310 # and verify the link properties on tethered device
Girish Moturu2c21eb32017-05-25 14:37:55 +0530311 self.log.info("Disabling mobile data to verify ipv6 default route")
Girish Moturuf72690e2017-02-14 15:19:53 -0800312 self.hotspot_device.droid.telephonyToggleDataConnection(False)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530313 asserts.assert_equal(
314 self.hotspot_device.droid.telephonyGetDataConnectionState(),
315 tel_defines.DATA_STATE_CONNECTED,
316 "Could not disable cell data")
317
Girish Moturu7f287522017-09-25 13:33:06 -0700318 time.sleep(WAIT_TIME) # wait until the IPv6 is removed from link properties
Girish Moturu2c21eb32017-05-25 14:37:55 +0530319
Girish Moturu0fd0b942017-12-12 12:04:56 -0800320 result = self.tethered_devices[0].droid.connectivityHasIPv6DefaultRoute()
Girish Moturu2c21eb32017-05-25 14:37:55 +0530321 self.hotspot_device.droid.telephonyToggleDataConnection(True)
Girish Moturu7df90e32017-10-16 12:49:56 -0700322 if result:
Girish Moturu2c21eb32017-05-25 14:37:55 +0530323 asserts.fail("Found IPv6 default route in link properties:Data off")
Girish Moturu7df90e32017-10-16 12:49:56 -0700324 self.log.info("Did not find IPv6 address in link properties")
Girish Moturu2c21eb32017-05-25 14:37:55 +0530325
326 # Disable wifi tethering
327 wutils.stop_wifi_tethering(self.hotspot_device)
328
329 @test_tracker_info(uuid="110b61d1-8af2-4589-8413-11beac7a3025")
Girish Moturu7df90e32017-10-16 12:49:56 -0700330 def wifi_tethering_2ghz_traffic_between_2tethered_devices(self):
Girish Moturu2c21eb32017-05-25 14:37:55 +0530331 """ Steps:
332
333 1. Start wifi hotspot with 2G band
334 2. Connect 2 tethered devices to the hotspot device
335 3. Ping interfaces between the tethered devices
336 """
337 wutils.toggle_wifi_off_and_on(self.hotspot_device)
338 self._start_wifi_tethering(WIFI_CONFIG_APBAND_2G)
339 self._test_traffic_between_two_tethered_devices(self.tethered_devices[0],
340 self.tethered_devices[1])
341 wutils.stop_wifi_tethering(self.hotspot_device)
342
343 @test_tracker_info(uuid="953f6e2e-27bd-4b73-85a6-d2eaa4e755d5")
Girish Moturu7df90e32017-10-16 12:49:56 -0700344 def wifi_tethering_5ghz_traffic_between_2tethered_devices(self):
Girish Moturu2c21eb32017-05-25 14:37:55 +0530345 """ Steps:
346
347 1. Start wifi hotspot with 5ghz band
348 2. Connect 2 tethered devices to the hotspot device
349 3. Send traffic between the tethered devices
350 """
351 wutils.toggle_wifi_off_and_on(self.hotspot_device)
352 self._start_wifi_tethering(WIFI_CONFIG_APBAND_5G)
353 self._test_traffic_between_two_tethered_devices(self.tethered_devices[0],
354 self.tethered_devices[1])
355 wutils.stop_wifi_tethering(self.hotspot_device)
356
357 @test_tracker_info(uuid="d7d5aa51-682d-4882-a334-61966d93b68c")
358 def test_wifi_tethering_2ghz_connect_disconnect_devices(self):
359 """ Steps:
360
361 1. Start wifi hotspot with 2ghz band
362 2. Connect and disconnect multiple devices randomly
363 3. Verify the correct functionality
364 """
365 wutils.toggle_wifi_off_and_on(self.hotspot_device)
366 self._start_wifi_tethering(WIFI_CONFIG_APBAND_2G)
367 self._connect_disconnect_devices()
368 wutils.stop_wifi_tethering(self.hotspot_device)
369
370 @test_tracker_info(uuid="34abd6c9-c7f1-4d89-aa2b-a66aeabed9aa")
371 def test_wifi_tethering_5ghz_connect_disconnect_devices(self):
372 """ Steps:
373
374 1. Start wifi hotspot with 5ghz band
375 2. Connect and disconnect multiple devices randomly
376 3. Verify the correct functionality
377 """
378 wutils.toggle_wifi_off_and_on(self.hotspot_device)
379 self._start_wifi_tethering(WIFI_CONFIG_APBAND_5G)
380 self._connect_disconnect_devices()
381 wutils.stop_wifi_tethering(self.hotspot_device)
382
383 @test_tracker_info(uuid="7edfb220-37f8-42ea-8d7c-39712fbe9be5")
384 def test_wifi_tethering_2ghz_ping_hotspot_interfaces(self):
385 """ Steps:
386
387 1. Start wifi hotspot with 2ghz band
388 2. Connect tethered device to hotspot device
389 3. Ping 'wlan0' and 'rmnet_data' interface's IPv4
390 and IPv6 interfaces on hotspot device from tethered device
391 """
392 wutils.toggle_wifi_off_and_on(self.hotspot_device)
393 self._start_wifi_tethering(WIFI_CONFIG_APBAND_2G)
394 wutils.wifi_connect(self.tethered_devices[0], self.network)
395 result = self._ping_hotspot_interfaces_from_tethered_device(
396 self.tethered_devices[0])
397 wutils.stop_wifi_tethering(self.hotspot_device)
398 return result
399
400 @test_tracker_info(uuid="17e450f4-795f-4e67-adab-984940dffedc")
401 def test_wifi_tethering_5ghz_ping_hotspot_interfaces(self):
402 """ Steps:
403
404 1. Start wifi hotspot with 5ghz band
405 2. Connect tethered device to hotspot device
406 3. Ping 'wlan0' and 'rmnet_data' interface's IPv4
407 and IPv6 interfaces on hotspot device from tethered device
408 """
409 wutils.toggle_wifi_off_and_on(self.hotspot_device)
410 self._start_wifi_tethering(WIFI_CONFIG_APBAND_5G)
411 wutils.wifi_connect(self.tethered_devices[0], self.network)
412 result = self._ping_hotspot_interfaces_from_tethered_device(
413 self.tethered_devices[0])
414 wutils.stop_wifi_tethering(self.hotspot_device)
415 return result
416
417 @test_tracker_info(uuid="d4e18031-0af0-4b29-a574-8707cd4029b7")
418 def test_wifi_tethering_verify_received_bytes(self):
419 """ Steps:
420
421 1. Start wifi hotspot and connect tethered device to it
422 2. Get the data usage on hotspot device
423 3. Download data on tethered device
424 4. Get the new data usage on hotspot device
425 5. Verify that hotspot device's data usage
426 increased by downloaded file size
427 """
428 wutils.toggle_wifi_off_and_on(self.hotspot_device)
429 dut = self.hotspot_device
430 self._start_wifi_tethering()
431 wutils.wifi_connect(self.tethered_devices[0], self.network)
432 subscriber_id = dut.droid.telephonyGetSubscriberId()
433
434 # get data usage limit
435 end_time = int(time.time() * 1000)
436 bytes_before_download = dut.droid.connectivityGetRxBytesForDevice(
437 subscriber_id, 0, end_time)
Girish Moturu7df90e32017-10-16 12:49:56 -0700438 self.log.info("Data usage before download: %s MB" %
439 (bytes_before_download/self.convert_byte_to_mb))
Girish Moturu2c21eb32017-05-25 14:37:55 +0530440
441 # download file
Girish Moturu7f287522017-09-25 13:33:06 -0700442 self.log.info("Download file of size %sMB" % self.file_size)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530443 http_file_download_by_chrome(self.tethered_devices[0],
Girish Moturu0fd0b942017-12-12 12:04:56 -0800444 self.download_file,
445 self.file_size)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530446
447 # get data usage limit after download
448 end_time = int(time.time() * 1000)
449 bytes_after_download = dut.droid.connectivityGetRxBytesForDevice(
450 subscriber_id, 0, end_time)
Girish Moturu7df90e32017-10-16 12:49:56 -0700451 self.log.info("Data usage after download: %s MB" %
452 (bytes_after_download/self.convert_byte_to_mb))
Girish Moturu2c21eb32017-05-25 14:37:55 +0530453
454 bytes_diff = bytes_after_download - bytes_before_download
455 wutils.stop_wifi_tethering(self.hotspot_device)
456
457 # verify data usage update is correct
458 bytes_used = bytes_diff/self.convert_byte_to_mb
Girish Moturu7f287522017-09-25 13:33:06 -0700459 self.log.info("Data usage on the device increased by %s" % bytes_used)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530460 return bytes_used > self.file_size \
461 and bytes_used < self.file_size + self.data_usage_error
462
463 @test_tracker_info(uuid="07a00c96-4770-44a1-a9db-b3d02d6a12b6")
464 def test_wifi_tethering_data_usage_limit(self):
465 """ Steps:
466
Girish Moturu7df90e32017-10-16 12:49:56 -0700467 1. Set the data usage limit to current data usage + 10MB
Girish Moturu2c21eb32017-05-25 14:37:55 +0530468 2. Start wifi tethering and connect a dut to the SSID
Girish Moturu7df90e32017-10-16 12:49:56 -0700469 3. Download 20MB data on tethered device
Girish Moturu2c21eb32017-05-25 14:37:55 +0530470 a. file download should stop
471 b. tethered device will lose internet connectivity
472 c. data usage limit reached message should be displayed
473 on the hotspot device
474 4. Verify data usage limit
475 """
476 wutils.toggle_wifi_off_and_on(self.hotspot_device)
477 dut = self.hotspot_device
Girish Moturu7df90e32017-10-16 12:49:56 -0700478 data_usage_inc = 10 * self.convert_byte_to_mb
Girish Moturu2c21eb32017-05-25 14:37:55 +0530479 subscriber_id = dut.droid.telephonyGetSubscriberId()
480
481 self._start_wifi_tethering()
482 wutils.wifi_connect(self.tethered_devices[0], self.network)
483
484 # get current data usage
485 end_time = int(time.time() * 1000)
486 old_data_usage = dut.droid.connectivityQuerySummaryForDevice(
487 subscriber_id, 0, end_time)
488
Girish Moturu7df90e32017-10-16 12:49:56 -0700489 # set data usage limit to current usage limit + 10MB
Girish Moturu2c21eb32017-05-25 14:37:55 +0530490 dut.droid.connectivitySetDataUsageLimit(
Girish Moturu7df90e32017-10-16 12:49:56 -0700491 subscriber_id, str(int(old_data_usage + data_usage_inc)))
Girish Moturu2c21eb32017-05-25 14:37:55 +0530492
Girish Moturu7df90e32017-10-16 12:49:56 -0700493 # download file - size 20MB
Girish Moturu2c21eb32017-05-25 14:37:55 +0530494 http_file_download_by_chrome(self.tethered_devices[0],
495 self.download_file,
Girish Moturu0fd0b942017-12-12 12:04:56 -0800496 self.file_size,
Girish Moturu2c21eb32017-05-25 14:37:55 +0530497 timeout=120)
498 end_time = int(time.time() * 1000)
499 new_data_usage = dut.droid.connectivityQuerySummaryForDevice(
500 subscriber_id, 0, end_time)
501
502 # test network connectivity on tethered device
503 asserts.assert_true(
504 not wutils.validate_connection(self.tethered_devices[0]),
505 "Tethered device has internet connectivity after data usage"
506 "limit is reached on hotspot device")
507 dut.droid.connectivityFactoryResetNetworkPolicies(subscriber_id)
508 wutils.stop_wifi_tethering(self.hotspot_device)
509
Girish Moturu7df90e32017-10-16 12:49:56 -0700510 old_data_usage = (old_data_usage+data_usage_inc)/self.convert_byte_to_mb
Girish Moturu2c21eb32017-05-25 14:37:55 +0530511 new_data_usage = new_data_usage/self.convert_byte_to_mb
Girish Moturu7df90e32017-10-16 12:49:56 -0700512 self.log.info("Expected data usage: %s MB" % old_data_usage)
513 self.log.info("Actual data usage: %s MB" % new_data_usage)
Girish Moturu2c21eb32017-05-25 14:37:55 +0530514
515 return (new_data_usage-old_data_usage) < self.data_usage_error
516
517 @test_tracker_info(uuid="2bc344cb-0277-4f06-b6cc-65b3972086ed")
518 def test_change_wifi_hotspot_ssid_when_hotspot_enabled(self):
519 """ Steps:
520
521 1. Start wifi tethering
522 2. Verify wifi Ap configuration
523 3. Change the SSID of the wifi hotspot while hotspot is on
524 4. Verify the new SSID in wifi ap configuration
525 5. Restart tethering and verify that the tethered device is able
526 to connect to the new SSID
527 """
528 wutils.toggle_wifi_off_and_on(self.hotspot_device)
529 dut = self.hotspot_device
530
531 # start tethering and verify the wifi ap configuration settings
532 self._start_wifi_tethering()
533 wifi_ap = dut.droid.wifiGetApConfiguration()
534 asserts.assert_true(
535 wifi_ap[wutils.WifiEnums.SSID_KEY] == \
536 self.network[wutils.WifiEnums.SSID_KEY],
537 "Configured wifi hotspot SSID did not match with the expected SSID")
538 wutils.wifi_connect(self.tethered_devices[0], self.network)
539
540 # update the wifi ap configuration with new ssid
541 config = {wutils.WifiEnums.SSID_KEY: self.new_ssid}
542 config[wutils.WifiEnums.PWD_KEY] = self.network[wutils.WifiEnums.PWD_KEY]
543 config[wutils.WifiEnums.APBAND_KEY] = WIFI_CONFIG_APBAND_2G
544 asserts.assert_true(
545 dut.droid.wifiSetWifiApConfiguration(config),
546 "Failed to update WifiAp Configuration")
547 wifi_ap = dut.droid.wifiGetApConfiguration()
548 asserts.assert_true(
549 wifi_ap[wutils.WifiEnums.SSID_KEY] == self.new_ssid,
550 "Configured wifi hotspot SSID does not match with the expected SSID")
551
552 # start wifi tethering with new wifi ap configuration
553 wutils.stop_wifi_tethering(dut)
554 dut.droid.wifiStartTrackingTetherStateChange()
555 dut.droid.connectivityStartTethering(tel_defines.TETHERING_WIFI, False)
556 try:
557 dut.ed.pop_event("ConnectivityManagerOnTetheringStarted")
558 dut.ed.wait_for_event("TetherStateChanged",
559 lambda x: x["data"]["ACTIVE_TETHER"], 30)
560 except:
561 asserts.fail("Didn't receive wifi tethering starting confirmation")
562 dut.droid.wifiStopTrackingTetherStateChange()
563
564 # verify dut can connect to new wifi ap configuration
565 new_network = {wutils.WifiEnums.SSID_KEY: self.new_ssid,
566 wutils.WifiEnums.PWD_KEY: \
567 self.network[wutils.WifiEnums.PWD_KEY]}
568 wutils.wifi_connect(self.tethered_devices[0], new_network)
569 wutils.stop_wifi_tethering(self.hotspot_device)