Girish Moturu | f72690e | 2017-02-14 15:19:53 -0800 | [diff] [blame] | 1 | # |
| 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 | |
| 16 | import logging |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 17 | import random |
Girish Moturu | f72690e | 2017-02-14 15:19:53 -0800 | [diff] [blame] | 18 | import socket |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 19 | import time |
Girish Moturu | f72690e | 2017-02-14 15:19:53 -0800 | [diff] [blame] | 20 | |
| 21 | from acts import asserts |
| 22 | from acts import base_test |
| 23 | from acts import test_runner |
| 24 | from acts.controllers import adb |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 25 | from acts.test_decorators import test_tracker_info |
Girish Moturu | f72690e | 2017-02-14 15:19:53 -0800 | [diff] [blame] | 26 | from acts.test_utils.tel import tel_data_utils |
Girish Moturu | f72690e | 2017-02-14 15:19:53 -0800 | [diff] [blame] | 27 | from acts.test_utils.tel import tel_defines |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 28 | from acts.test_utils.tel.tel_data_utils import toggle_airplane_mode |
| 29 | from acts.test_utils.tel.tel_data_utils import wait_for_cell_data_connection |
| 30 | from acts.test_utils.tel.tel_test_utils import get_operator_name |
| 31 | from acts.test_utils.tel.tel_test_utils import http_file_download_by_chrome |
| 32 | from acts.test_utils.tel.tel_test_utils import verify_http_connection |
| 33 | from acts.test_utils.tel.tel_test_utils import WIFI_CONFIG_APBAND_2G |
| 34 | from acts.test_utils.tel.tel_test_utils import WIFI_CONFIG_APBAND_5G |
| 35 | from acts.test_utils.wifi import wifi_test_utils as wutils |
Girish Moturu | f72690e | 2017-02-14 15:19:53 -0800 | [diff] [blame] | 36 | |
Girish Moturu | 7f28752 | 2017-09-25 13:33:06 -0700 | [diff] [blame] | 37 | WAIT_TIME = 2 |
Girish Moturu | f72690e | 2017-02-14 15:19:53 -0800 | [diff] [blame] | 38 | |
| 39 | class WifiTetheringTest(base_test.BaseTestClass): |
| 40 | """ Tests for Wifi Tethering """ |
| 41 | |
| 42 | def setup_class(self): |
| 43 | """ Setup devices for tethering and unpack params """ |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 44 | |
| 45 | self.convert_byte_to_mb = 1024.0 * 1024.0 |
| 46 | self.new_ssid = "wifi_tethering_test2" |
Girish Moturu | 7df90e3 | 2017-10-16 12:49:56 -0700 | [diff] [blame] | 47 | self.data_usage_error = 1 |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 48 | |
| 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 Moturu | f72690e | 2017-02-14 15:19:53 -0800 | [diff] [blame] | 52 | self.unpack_userparams(req_params) |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 53 | self.file_size = int(self.file_size) |
| 54 | |
| 55 | wutils.wifi_toggle_state(self.hotspot_device, False) |
Girish Moturu | f72690e | 2017-02-14 15:19:53 -0800 | [diff] [blame] | 56 | self.hotspot_device.droid.telephonyToggleDataConnection(True) |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 57 | wait_for_cell_data_connection(self.log, self.hotspot_device, True) |
Girish Moturu | f72690e | 2017-02-14 15:19:53 -0800 | [diff] [blame] | 58 | asserts.assert_true( |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 59 | verify_http_connection(self.log, self.hotspot_device), |
Girish Moturu | f72690e | 2017-02-14 15:19:53 -0800 | [diff] [blame] | 60 | "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 Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 64 | for ad in self.tethered_devices: |
Girish Moturu | 9bd1e9a | 2017-12-14 10:10:25 -0800 | [diff] [blame^] | 65 | ad.droid.telephonyToggleDataConnection(False) |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 66 | wutils.wifi_test_device_init(ad) |
Girish Moturu | f72690e | 2017-02-14 15:19:53 -0800 | [diff] [blame] | 67 | |
Girish Moturu | 7f28752 | 2017-09-25 13:33:06 -0700 | [diff] [blame] | 68 | # 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 Moturu | f72690e | 2017-02-14 15:19:53 -0800 | [diff] [blame] | 86 | def teardown_class(self): |
| 87 | """ Reset devices """ |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 88 | wutils.wifi_toggle_state(self.hotspot_device, True) |
Girish Moturu | 9bd1e9a | 2017-12-14 10:10:25 -0800 | [diff] [blame^] | 89 | for ad in self.tethered_devices: |
| 90 | ad.droid.telephonyToggleDataConnection(True) |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 91 | |
| 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 Moturu | 7df90e3 | 2017-10-16 12:49:56 -0700 | [diff] [blame] | 95 | for ad in self.tethered_devices: |
| 96 | ad.take_bug_report(test_name, begin_time) |
Girish Moturu | f72690e | 2017-02-14 15:19:53 -0800 | [diff] [blame] | 97 | |
| 98 | """ Helper functions """ |
| 99 | |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 100 | def _is_ipaddress_ipv6(self, ip_address): |
Girish Moturu | f72690e | 2017-02-14 15:19:53 -0800 | [diff] [blame] | 101 | """ 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 Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 126 | operator = get_operator_name(self.log, dut) |
Girish Moturu | f72690e | 2017-02-14 15:19:53 -0800 | [diff] [blame] | 127 | return operator in carrier_supports_tethering |
| 128 | |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 129 | 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 Moturu | 7f28752 | 2017-09-25 13:33:06 -0700 | [diff] [blame] | 139 | self.log.info("Carrier is %s" % operator) |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 140 | return operator in carrier_supports_ipv6 |
| 141 | |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 142 | def _verify_ipv6_tethering(self, dut): |
Girish Moturu | f72690e | 2017-02-14 15:19:53 -0800 | [diff] [blame] | 143 | """ Verify IPv6 tethering """ |
| 144 | http_response = dut.droid.httpRequestString(self.url) |
Girish Moturu | f72690e | 2017-02-14 15:19:53 -0800 | [diff] [blame] | 145 | self.log.info("IP address %s " % http_response) |
Girish Moturu | 0fd0b94 | 2017-12-12 12:04:56 -0800 | [diff] [blame] | 146 | active_link_addrs = dut.droid.connectivityGetAllAddressesOfActiveLink() |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 147 | if dut==self.hotspot_device and self._carrier_supports_ipv6(dut)\ |
| 148 | or self._supports_ipv6_tethering(self.hotspot_device): |
Girish Moturu | f72690e | 2017-02-14 15:19:53 -0800 | [diff] [blame] | 149 | asserts.assert_true(self._is_ipaddress_ipv6(http_response), |
| 150 | "The http response did not return IPv6 address") |
Girish Moturu | 0fd0b94 | 2017-12-12 12:04:56 -0800 | [diff] [blame] | 151 | 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 Moturu | f72690e | 2017-02-14 15:19:53 -0800 | [diff] [blame] | 157 | else: |
Girish Moturu | 0fd0b94 | 2017-12-12 12:04:56 -0800 | [diff] [blame] | 158 | asserts.assert_true( |
| 159 | not dut.droid.connectivityHasIPv6DefaultRoute(), |
| 160 | "Found IPv6 default route in link properties") |
Girish Moturu | f72690e | 2017-02-14 15:19:53 -0800 | [diff] [blame] | 161 | |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 162 | 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 Moturu | 7df90e3 | 2017-10-16 12:49:56 -0700 | [diff] [blame] | 182 | # wait for 1 sec between connect & disconnect stress test |
| 183 | time.sleep(1) |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 184 | 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 Moturu | 7f28752 | 2017-09-25 13:33:06 -0700 | [diff] [blame] | 190 | def _verify_ping(self, dut, ip, isIPv6=False): |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 191 | """ 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 Moturu | 7f28752 | 2017-09-25 13:33:06 -0700 | [diff] [blame] | 202 | if isIPv6 or self._is_ipaddress_ipv6(ip): |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 203 | 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 Moturu | f72690e | 2017-02-14 15:19:53 -0800 | [diff] [blame] | 264 | |
| 265 | """ Test Cases """ |
| 266 | |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 267 | @test_tracker_info(uuid="36d03295-bea3-446e-8342-b9f8f1962a32") |
Girish Moturu | f72690e | 2017-02-14 15:19:53 -0800 | [diff] [blame] | 268 | def test_ipv6_tethering(self): |
| 269 | """ IPv6 tethering test |
| 270 | |
| 271 | Steps: |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 272 | 1. Start wifi tethering on hotspot device |
Girish Moturu | 7df90e3 | 2017-10-16 12:49:56 -0700 | [diff] [blame] | 273 | 2. Verify IPv6 address on hotspot device (VZW & TMO only) |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 274 | 3. Connect tethered device to hotspot device |
Girish Moturu | 7df90e3 | 2017-10-16 12:49:56 -0700 | [diff] [blame] | 275 | 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 Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 277 | 6. Disable mobile data on provider and verify that link properties |
Girish Moturu | 7df90e3 | 2017-10-16 12:49:56 -0700 | [diff] [blame] | 278 | does not have IPv6 address and default route (VZW only) |
Girish Moturu | f72690e | 2017-02-14 15:19:53 -0800 | [diff] [blame] | 279 | """ |
| 280 | # Start wifi tethering on the hotspot device |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 281 | wutils.toggle_wifi_off_and_on(self.hotspot_device) |
| 282 | self._start_wifi_tethering() |
Girish Moturu | f72690e | 2017-02-14 15:19:53 -0800 | [diff] [blame] | 283 | |
| 284 | # Verify link properties on hotspot device |
Girish Moturu | 7f28752 | 2017-09-25 13:33:06 -0700 | [diff] [blame] | 285 | self.log.info("Check IPv6 properties on the hotspot device. " |
| 286 | "Verizon & T-mobile should have IPv6 in link properties") |
Girish Moturu | f72690e | 2017-02-14 15:19:53 -0800 | [diff] [blame] | 287 | self._verify_ipv6_tethering(self.hotspot_device) |
| 288 | |
| 289 | # Connect the client to the SSID |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 290 | wutils.wifi_connect(self.tethered_devices[0], self.network) |
Girish Moturu | f72690e | 2017-02-14 15:19:53 -0800 | [diff] [blame] | 291 | |
| 292 | # Need to wait atleast 2 seconds for IPv6 address to |
| 293 | # show up in the link properties |
Girish Moturu | 7f28752 | 2017-09-25 13:33:06 -0700 | [diff] [blame] | 294 | time.sleep(WAIT_TIME) |
Girish Moturu | f72690e | 2017-02-14 15:19:53 -0800 | [diff] [blame] | 295 | |
| 296 | # Verify link properties on tethered device |
Girish Moturu | 7f28752 | 2017-09-25 13:33:06 -0700 | [diff] [blame] | 297 | self.log.info("Check IPv6 properties on the tethered device. " |
| 298 | "Device should have IPv6 if carrier is Verizon") |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 299 | self._verify_ipv6_tethering(self.tethered_devices[0]) |
Girish Moturu | f72690e | 2017-02-14 15:19:53 -0800 | [diff] [blame] | 300 | |
| 301 | # Verify ping6 on tethered device |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 302 | ping_result = self._verify_ping(self.tethered_devices[0], |
Girish Moturu | 7f28752 | 2017-09-25 13:33:06 -0700 | [diff] [blame] | 303 | wutils.DEFAULT_PING_ADDR, True) |
Girish Moturu | f72690e | 2017-02-14 15:19:53 -0800 | [diff] [blame] | 304 | 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 Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 311 | self.log.info("Disabling mobile data to verify ipv6 default route") |
Girish Moturu | f72690e | 2017-02-14 15:19:53 -0800 | [diff] [blame] | 312 | self.hotspot_device.droid.telephonyToggleDataConnection(False) |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 313 | asserts.assert_equal( |
| 314 | self.hotspot_device.droid.telephonyGetDataConnectionState(), |
| 315 | tel_defines.DATA_STATE_CONNECTED, |
| 316 | "Could not disable cell data") |
| 317 | |
Girish Moturu | 7f28752 | 2017-09-25 13:33:06 -0700 | [diff] [blame] | 318 | time.sleep(WAIT_TIME) # wait until the IPv6 is removed from link properties |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 319 | |
Girish Moturu | 0fd0b94 | 2017-12-12 12:04:56 -0800 | [diff] [blame] | 320 | result = self.tethered_devices[0].droid.connectivityHasIPv6DefaultRoute() |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 321 | self.hotspot_device.droid.telephonyToggleDataConnection(True) |
Girish Moturu | 7df90e3 | 2017-10-16 12:49:56 -0700 | [diff] [blame] | 322 | if result: |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 323 | asserts.fail("Found IPv6 default route in link properties:Data off") |
Girish Moturu | 7df90e3 | 2017-10-16 12:49:56 -0700 | [diff] [blame] | 324 | self.log.info("Did not find IPv6 address in link properties") |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 325 | |
| 326 | # Disable wifi tethering |
| 327 | wutils.stop_wifi_tethering(self.hotspot_device) |
| 328 | |
| 329 | @test_tracker_info(uuid="110b61d1-8af2-4589-8413-11beac7a3025") |
Girish Moturu | 7df90e3 | 2017-10-16 12:49:56 -0700 | [diff] [blame] | 330 | def wifi_tethering_2ghz_traffic_between_2tethered_devices(self): |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 331 | """ 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 Moturu | 7df90e3 | 2017-10-16 12:49:56 -0700 | [diff] [blame] | 344 | def wifi_tethering_5ghz_traffic_between_2tethered_devices(self): |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 345 | """ 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 Moturu | 7df90e3 | 2017-10-16 12:49:56 -0700 | [diff] [blame] | 438 | self.log.info("Data usage before download: %s MB" % |
| 439 | (bytes_before_download/self.convert_byte_to_mb)) |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 440 | |
| 441 | # download file |
Girish Moturu | 7f28752 | 2017-09-25 13:33:06 -0700 | [diff] [blame] | 442 | self.log.info("Download file of size %sMB" % self.file_size) |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 443 | http_file_download_by_chrome(self.tethered_devices[0], |
Girish Moturu | 0fd0b94 | 2017-12-12 12:04:56 -0800 | [diff] [blame] | 444 | self.download_file, |
| 445 | self.file_size) |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 446 | |
| 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 Moturu | 7df90e3 | 2017-10-16 12:49:56 -0700 | [diff] [blame] | 451 | self.log.info("Data usage after download: %s MB" % |
| 452 | (bytes_after_download/self.convert_byte_to_mb)) |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 453 | |
| 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 Moturu | 7f28752 | 2017-09-25 13:33:06 -0700 | [diff] [blame] | 459 | self.log.info("Data usage on the device increased by %s" % bytes_used) |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 460 | 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 Moturu | 7df90e3 | 2017-10-16 12:49:56 -0700 | [diff] [blame] | 467 | 1. Set the data usage limit to current data usage + 10MB |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 468 | 2. Start wifi tethering and connect a dut to the SSID |
Girish Moturu | 7df90e3 | 2017-10-16 12:49:56 -0700 | [diff] [blame] | 469 | 3. Download 20MB data on tethered device |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 470 | 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 Moturu | 7df90e3 | 2017-10-16 12:49:56 -0700 | [diff] [blame] | 478 | data_usage_inc = 10 * self.convert_byte_to_mb |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 479 | 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 Moturu | 7df90e3 | 2017-10-16 12:49:56 -0700 | [diff] [blame] | 489 | # set data usage limit to current usage limit + 10MB |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 490 | dut.droid.connectivitySetDataUsageLimit( |
Girish Moturu | 7df90e3 | 2017-10-16 12:49:56 -0700 | [diff] [blame] | 491 | subscriber_id, str(int(old_data_usage + data_usage_inc))) |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 492 | |
Girish Moturu | 7df90e3 | 2017-10-16 12:49:56 -0700 | [diff] [blame] | 493 | # download file - size 20MB |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 494 | http_file_download_by_chrome(self.tethered_devices[0], |
| 495 | self.download_file, |
Girish Moturu | 0fd0b94 | 2017-12-12 12:04:56 -0800 | [diff] [blame] | 496 | self.file_size, |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 497 | 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 Moturu | 7df90e3 | 2017-10-16 12:49:56 -0700 | [diff] [blame] | 510 | old_data_usage = (old_data_usage+data_usage_inc)/self.convert_byte_to_mb |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 511 | new_data_usage = new_data_usage/self.convert_byte_to_mb |
Girish Moturu | 7df90e3 | 2017-10-16 12:49:56 -0700 | [diff] [blame] | 512 | self.log.info("Expected data usage: %s MB" % old_data_usage) |
| 513 | self.log.info("Actual data usage: %s MB" % new_data_usage) |
Girish Moturu | 2c21eb3 | 2017-05-25 14:37:55 +0530 | [diff] [blame] | 514 | |
| 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) |