blob: c1e0b2327f58a4192d5124f1ffca3faf4c6ebeb3 [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
17import time
18import socket
19
20from acts import asserts
21from acts import base_test
22from acts import test_runner
23from acts.controllers import adb
24from acts.test_utils.tel import tel_data_utils
25from acts.test_utils.tel import tel_test_utils
26from acts.test_utils.tel import tel_defines
27from acts.test_utils.wifi import wifi_test_utils
28
29
30class WifiTetheringTest(base_test.BaseTestClass):
31 """ Tests for Wifi Tethering """
32
33 def setup_class(self):
34 """ Setup devices for tethering and unpack params """
35 self.hotspot_device, self.tethered_device = self.android_devices[:2]
36 req_params = ("ssid", "password", "url")
37 self.unpack_userparams(req_params)
38 asserts.assert_true(
39 tel_data_utils.toggle_airplane_mode(self.log, self.hotspot_device, False),
40 "Could not disable airplane mode")
41 wifi_test_utils.wifi_toggle_state(self.hotspot_device, False)
42 self.hotspot_device.droid.telephonyToggleDataConnection(True)
43 tel_data_utils.wait_for_cell_data_connection(self.log, self.hotspot_device, True)
44 asserts.assert_true(
45 tel_data_utils.verify_http_connection(self.log, self.hotspot_device),
46 "HTTP verification failed on cell data connection")
47 asserts.assert_true(
48 self.hotspot_device.droid.connectivityIsTetheringSupported(),
49 "Tethering is not supported for the provider")
50 wifi_test_utils.wifi_test_device_init(self.tethered_device)
51 self.tethered_device.droid.telephonyToggleDataConnection(False)
52
53 def teardown_class(self):
54 """ Reset devices """
55 wifi_test_utils.wifi_toggle_state(self.hotspot_device, True)
56 self.hotspot_device.droid.telephonyToggleDataConnection(True)
57 self.tethered_device.droid.telephonyToggleDataConnection(True)
58
59 """ Helper functions """
60
61 def _is_ipaddress_ipv6(self,ip_address):
62 """ Verify if the given string is a valid IPv6 address
63
64 Args:
65 1. string which contains the IP address
66
67 Returns:
68 True: if valid ipv6 address
69 False: if not
70 """
71 try:
72 socket.inet_pton(socket.AF_INET6, ip_address)
73 return True
74 except socket.error:
75 return False
76
77 def _supports_ipv6_tethering(self, dut):
78 """ Check if provider supports IPv6 tethering.
79 Currently, only Verizon supports IPv6 tethering
80
81 Returns:
82 True: if provider supports IPv6 tethering
83 False: if not
84 """
85 # Currently only Verizon support IPv6 tethering
86 carrier_supports_tethering = ["vzw"]
87 operator = tel_test_utils.get_operator_name(self.log, dut)
88 return operator in carrier_supports_tethering
89
90 def _find_ipv6_default_route(self, dut):
91 """ Checks if IPv6 default route exists in the link properites
92
93 Returns:
94 True: if default route found
95 False: if not
96 """
97 default_route_substr = "::/0 -> "
98 link_properties = dut.droid.connectivityGetActiveLinkProperties()
99 return link_properties and default_route_substr in link_properties
100
101 def _verify_ipv6_tethering(self,dut):
102 """ Verify IPv6 tethering """
103 http_response = dut.droid.httpRequestString(self.url)
104 link_properties = dut.droid.connectivityGetActiveLinkProperties()
105 self.log.info("IP address %s " % http_response)
106 if dut==self.hotspot_device or self._supports_ipv6_tethering(self.hotspot_device):
107 asserts.assert_true(self._is_ipaddress_ipv6(http_response),
108 "The http response did not return IPv6 address")
109 asserts.assert_true(link_properties and http_response in link_properties,
110 "Could not find IPv6 address in link properties")
111 asserts.assert_true(self._find_ipv6_default_route(dut),
112 "Could not find IPv6 default route in link properties")
113 else:
114 asserts.assert_true(not self._find_ipv6_default_route(dut),
115 "Found IPv6 default route in link properties")
116
117
118 """ Test Cases """
119
120 def test_ipv6_tethering(self):
121 """ IPv6 tethering test
122
123 Steps:
124 1. Start wifi tethering on provider
125 2. Client connects to wifi tethering SSID
126 3. Verify IPv6 address on the client's link properties
127 4. Verify ping on client using ping6 which should pass
128 5. Disable mobile data on provider and verify that link properties
129 does not have IPv6 address and default route
130 """
131 # Start wifi tethering on the hotspot device
132 self.log.info("Start tethering on provider: {}"
133 .format(self.hotspot_device.serial))
134 wifi_test_utils.start_wifi_tethering(self.hotspot_device,
135 self.ssid,
136 self.password)
137 time.sleep(tel_defines.WAIT_TIME_ANDROID_STATE_SETTLING)
138 asserts.assert_true(
139 tel_data_utils.verify_http_connection(self.log,self.hotspot_device),
140 "Could not verify http connection on the provider")
141
142 # Verify link properties on hotspot device
143 self.log.info("Check IPv6 properties on the hotspot device")
144 self._verify_ipv6_tethering(self.hotspot_device)
145
146 # Connect the client to the SSID
147 asserts.assert_true(
148 tel_test_utils.WifiUtils.wifi_connect(self.log,
149 self.tethered_device,
150 self.ssid,
151 self.password),
152 "Unable to connect to the hotspot SSID")
153
154 # Need to wait atleast 2 seconds for IPv6 address to
155 # show up in the link properties
156 time.sleep(2)
157
158 # Verify link properties on tethered device
159 self.log.info("Check IPv6 properties on the tethered device")
160 self._verify_ipv6_tethering(self.tethered_device)
161
162 # Verify ping6 on tethered device
163 ping_result = self.tethered_device.droid.pingHost("www.google.com",
164 5,
165 "ping6")
166 if self._supports_ipv6_tethering(self.hotspot_device):
167 asserts.assert_true(ping_result, "Ping6 failed on the client")
168 else:
169 asserts.assert_true(not ping_result, "Ping6 failed as expected")
170
171 # Disable mobile data on hotspot device
172 # and verify the link properties on tethered device
173 self.log.info("Disabling mobile data on hotspot device")
174 self.hotspot_device.droid.telephonyToggleDataConnection(False)
175 asserts.assert_equal(self.hotspot_device.droid.telephonyGetDataConnectionState(),
176 tel_defines.DATA_STATE_CONNECTED,
177 "Could not disable cell data")
178 time.sleep(2) # wait until the IPv6 is removed from link properties
179 asserts.assert_true(not self._find_ipv6_default_route(self.tethered_device),
180 "Found IPv6 default route in link properties - Data off")