blob: c6728628bc302324fe8768c7cd68423753f85f77 [file] [log] [blame]
Etan Cohenfc5f3732017-06-02 17:31:52 -07001#!/usr/bin/python3.4
2#
3# Copyright 2017 - The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17import time
18
19from acts.test_utils.net import connectivity_const as cconsts
20from acts.test_utils.wifi.aware import aware_const as aconsts
21from acts.test_utils.wifi.aware import aware_test_utils as autils
22from acts.test_utils.wifi.aware.AwareBaseTest import AwareBaseTest
23
24
25class DataPathTest(AwareBaseTest):
26 """Set of tests for Wi-Fi Aware discovery."""
27
28 # configuration parameters used by tests
29 ENCR_TYPE_OPEN = 0
30 ENCR_TYPE_PASSPHRASE = 1
31
32 PASSPHRASE = "This is some random passphrase - very very secure!!"
33
34 PING_MSG = "ping"
35
36 # message re-transmit counter (increases reliability in open-environment)
37 # Note: reliability of message transmission is tested elsewhere
38 MSG_RETX_COUNT = 5 # hard-coded max value, internal API
39
Etan Cohenba8a53f2017-06-05 12:55:02 -070040 # number of second to 'reasonably' wait to make sure that devices synchronize
41 # with each other - useful for OOB test cases, where the OOB discovery would
42 # take some time
43 WAIT_FOR_CLUSTER = 5
44
Etan Cohenfc5f3732017-06-02 17:31:52 -070045 def __init__(self, controllers):
46 AwareBaseTest.__init__(self, controllers)
47
48 def create_config(self, dtype):
49 """Create a base configuration based on input parameters.
50
51 Args:
52 dtype: Publish or Subscribe discovery type
53
54 Returns:
55 Discovery configuration object.
56 """
57 config = {}
58 config[aconsts.DISCOVERY_KEY_DISCOVERY_TYPE] = dtype
59 config[aconsts.DISCOVERY_KEY_SERVICE_NAME] = "GoogleTestServiceDataPath"
60 return config
61
62 def request_network(self, dut, ns):
63 """Request a Wi-Fi Aware network.
64
65 Args:
66 dut: Device
67 ns: Network specifier
68 Returns: the request key
69 """
70 network_req = {"TransportType": 5, "NetworkSpecifier": ns}
71 return dut.droid.connectivityRequestWifiAwareNetwork(network_req)
72
73 def run_ib_data_path_test(self, ptype, stype, encr_type, use_peer_id):
74 """Runs the in-band data-path tests.
75
76 Args:
77 ptype: Publish discovery type
78 stype: Subscribe discovery type
79 encr_type: Encryption type, one of ENCR_TYPE_*
80 use_peer_id: On Responder (publisher): True to use peer ID, False to
81 accept any request
82 """
83 p_dut = self.android_devices[0]
84 p_dut.pretty_name = "Publisher"
85 s_dut = self.android_devices[1]
86 s_dut.pretty_name = "Subscriber"
87
88 # Publisher+Subscriber: attach and wait for confirmation
89 p_id = p_dut.droid.wifiAwareAttach()
90 autils.wait_for_event(p_dut, aconsts.EVENT_CB_ON_ATTACHED)
91 s_id = s_dut.droid.wifiAwareAttach()
92 autils.wait_for_event(s_dut, aconsts.EVENT_CB_ON_ATTACHED)
93
94 # Publisher: start publish and wait for confirmation
95 p_disc_id = p_dut.droid.wifiAwarePublish(p_id, self.create_config(ptype))
96 autils.wait_for_event(p_dut, aconsts.SESSION_CB_ON_PUBLISH_STARTED)
97
98 # Subscriber: start subscribe and wait for confirmation
99 s_disc_id = s_dut.droid.wifiAwareSubscribe(s_id, self.create_config(stype))
100 autils.wait_for_event(s_dut, aconsts.SESSION_CB_ON_SUBSCRIBE_STARTED)
101
102 # Subscriber: wait for service discovery
103 discovery_event = autils.wait_for_event(
104 s_dut, aconsts.SESSION_CB_ON_SERVICE_DISCOVERED)
105 peer_id_on_sub = discovery_event["data"][aconsts.SESSION_CB_KEY_PEER_ID]
106
107 if use_peer_id: # only need message to receive peer ID
108 # Subscriber: send message to peer (Publisher - so it knows our address)
109 s_dut.droid.wifiAwareSendMessage(s_disc_id, peer_id_on_sub,
110 self.get_next_msg_id(), self.PING_MSG,
111 self.MSG_RETX_COUNT)
112 autils.wait_for_event(s_dut, aconsts.SESSION_CB_ON_MESSAGE_SENT)
113
114 # Publisher: wait for received message
115 pub_rx_msg_event = autils.wait_for_event(
116 p_dut, aconsts.SESSION_CB_ON_MESSAGE_RECEIVED)
117 peer_id_on_pub = pub_rx_msg_event["data"][aconsts.SESSION_CB_KEY_PEER_ID]
118
119 # Publisher: request network
120 p_req_key = self.request_network(
121 p_dut,
122 p_dut.droid.wifiAwareCreateNetworkSpecifier(
123 p_disc_id, peer_id_on_pub if use_peer_id else None, self.PASSPHRASE
124 if encr_type == self.ENCR_TYPE_PASSPHRASE else None))
125
126 # Subscriber: request network
127 s_req_key = self.request_network(
128 s_dut,
129 s_dut.droid.wifiAwareCreateNetworkSpecifier(
130 s_disc_id, peer_id_on_sub, self.PASSPHRASE
131 if encr_type == self.ENCR_TYPE_PASSPHRASE else None))
132
133 # Publisher & Subscriber: wait for network formation
134 p_net_event = autils.wait_for_event_with_keys(
135 p_dut, cconsts.EVENT_NETWORK_CALLBACK,
136 autils.EVENT_TIMEOUT,
137 (cconsts.NETWORK_CB_KEY_EVENT,
138 cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED),
139 (cconsts.NETWORK_CB_KEY_ID, p_req_key))
140 s_net_event = autils.wait_for_event_with_keys(
141 s_dut, cconsts.EVENT_NETWORK_CALLBACK,
142 autils.EVENT_TIMEOUT,
143 (cconsts.NETWORK_CB_KEY_EVENT,
144 cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED),
145 (cconsts.NETWORK_CB_KEY_ID, s_req_key))
146
147 p_aware_if = p_net_event["data"][cconsts.NETWORK_CB_KEY_INTERFACE_NAME]
148 s_aware_if = s_net_event["data"][cconsts.NETWORK_CB_KEY_INTERFACE_NAME]
149 self.log.info("Interface names: p=%s, s=%s", p_aware_if, s_aware_if)
150
151 p_ipv6 = p_dut.droid.connectivityGetLinkLocalIpv6Address(p_aware_if).split(
152 "%")[0]
153 s_ipv6 = s_dut.droid.connectivityGetLinkLocalIpv6Address(s_aware_if).split(
154 "%")[0]
155 self.log.info("Interface addresses (IPv6): p=%s, s=%s", p_ipv6, s_ipv6)
156
157 # TODO: possibly send messages back and forth, prefer to use netcat/nc
158
159 # clean-up
160 p_dut.droid.connectivityUnregisterNetworkCallback(p_req_key)
161 s_dut.droid.connectivityUnregisterNetworkCallback(s_req_key)
162
Etan Cohenba8a53f2017-06-05 12:55:02 -0700163 def run_oob_data_path_test(self, encr_type, use_peer_id):
164 """Runs the out-of-band data-path tests.
165
166 Args:
167 encr_type: Encryption type, one of ENCR_TYPE_*
168 use_peer_id: On Responder: True to use peer ID, False to accept any
169 request
170 """
171 init_dut = self.android_devices[0]
172 init_dut.pretty_name = "Initiator"
173 resp_dut = self.android_devices[1]
174 resp_dut.pretty_name = "Responder"
175
176 # Publisher+Subscriber: attach and wait for confirmation & identity
177 init_id = init_dut.droid.wifiAwareAttach(True)
178 autils.wait_for_event(init_dut, aconsts.EVENT_CB_ON_ATTACHED)
179 init_ident_event = autils.wait_for_event(
180 init_dut, aconsts.EVENT_CB_ON_IDENTITY_CHANGED)
181 init_mac = init_ident_event["data"]["mac"]
182 resp_id = resp_dut.droid.wifiAwareAttach(True)
183 autils.wait_for_event(resp_dut, aconsts.EVENT_CB_ON_ATTACHED)
184 resp_ident_event = autils.wait_for_event(
185 resp_dut, aconsts.EVENT_CB_ON_IDENTITY_CHANGED)
186 resp_mac = resp_ident_event["data"]["mac"]
187
188 # wait for for devices to synchronize with each other - there are no other
189 # mechanisms to make sure this happens for OOB discovery (except retrying
190 # to execute the data-path request)
191 time.sleep(self.WAIT_FOR_CLUSTER)
192
193 # Responder: request network
194 resp_req_key = self.request_network(
195 resp_dut,
196 resp_dut.droid.wifiAwareCreateNetworkSpecifierOob(
197 resp_id, aconsts.DATA_PATH_RESPONDER, init_mac
198 if use_peer_id else None, self.PASSPHRASE
199 if encr_type == self.ENCR_TYPE_PASSPHRASE else None))
200
201 # Initiator: request network
202 init_req_key = self.request_network(
203 init_dut,
204 init_dut.droid.wifiAwareCreateNetworkSpecifierOob(
205 init_id, aconsts.DATA_PATH_INITIATOR, resp_mac, self.PASSPHRASE
206 if encr_type == self.ENCR_TYPE_PASSPHRASE else None))
207
208 # Initiator & Responder: wait for network formation
209 init_net_event = autils.wait_for_event_with_keys(
210 init_dut, cconsts.EVENT_NETWORK_CALLBACK,
211 autils.EVENT_TIMEOUT,
212 (cconsts.NETWORK_CB_KEY_EVENT,
213 cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED),
214 (cconsts.NETWORK_CB_KEY_ID, init_req_key))
215 resp_net_event = autils.wait_for_event_with_keys(
216 resp_dut, cconsts.EVENT_NETWORK_CALLBACK,
217 autils.EVENT_TIMEOUT,
218 (cconsts.NETWORK_CB_KEY_EVENT,
219 cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED),
220 (cconsts.NETWORK_CB_KEY_ID, resp_req_key))
221
222 init_aware_if = init_net_event["data"][
223 cconsts.NETWORK_CB_KEY_INTERFACE_NAME]
224 resp_aware_if = resp_net_event["data"][
225 cconsts.NETWORK_CB_KEY_INTERFACE_NAME]
226 self.log.info("Interface names: I=%s, R=%s", init_aware_if, resp_aware_if)
227
228 init_ipv6 = init_dut.droid.connectivityGetLinkLocalIpv6Address(
229 init_aware_if).split("%")[0]
230 resp_ipv6 = resp_dut.droid.connectivityGetLinkLocalIpv6Address(
231 resp_aware_if).split("%")[0]
232 self.log.info("Interface addresses (IPv6): I=%s, R=%s", init_ipv6,
233 resp_ipv6)
234
235 # TODO: possibly send messages back and forth, prefer to use netcat/nc
236
237 # clean-up
238 resp_dut.droid.connectivityUnregisterNetworkCallback(resp_req_key)
239 init_dut.droid.connectivityUnregisterNetworkCallback(init_req_key)
240
241
Etan Cohenfc5f3732017-06-02 17:31:52 -0700242 #######################################
243 # Positive In-Band (IB) tests key:
244 #
245 # names is: test_ib_<pub_type>_<sub_type>_<encr_type>_<peer_spec>
246 # where:
247 #
248 # pub_type: Type of publish discovery session: unsolicited or solicited.
249 # sub_type: Type of subscribe discovery session: passive or active.
250 # encr_type: Encription type: open, passphrase
251 # peer_spec: Peer specification method: any or specific
252 #
253 # Note: In-Band means using Wi-Fi Aware for discovery and referring to the
254 # peer using the Aware-provided peer handle (as opposed to a MAC address).
255 #######################################
256
257 def test_ib_unsolicited_passive_open_specific(self):
258 """Data-path: in-band, unsolicited/passive, open encryption, specific peer
259
260 Verifies end-to-end discovery + data-path creation.
261 """
262 self.run_ib_data_path_test(
263 ptype=aconsts.PUBLISH_TYPE_UNSOLICITED,
264 stype=aconsts.SUBSCRIBE_TYPE_PASSIVE,
265 encr_type=self.ENCR_TYPE_OPEN,
266 use_peer_id=True)
267
268 def test_ib_unsolicited_passive_open_any(self):
269 """Data-path: in-band, unsolicited/passive, open encryption, any peer
270
271 Verifies end-to-end discovery + data-path creation.
272 """
273 self.run_ib_data_path_test(
274 ptype=aconsts.PUBLISH_TYPE_UNSOLICITED,
275 stype=aconsts.SUBSCRIBE_TYPE_PASSIVE,
276 encr_type=self.ENCR_TYPE_OPEN,
277 use_peer_id=False)
278
279 def test_ib_unsolicited_passive_passphrase_specific(self):
280 """Data-path: in-band, unsolicited/passive, passphrase, specific peer
281
282 Verifies end-to-end discovery + data-path creation.
283 """
284 self.run_ib_data_path_test(
285 ptype=aconsts.PUBLISH_TYPE_UNSOLICITED,
286 stype=aconsts.SUBSCRIBE_TYPE_PASSIVE,
287 encr_type=self.ENCR_TYPE_PASSPHRASE,
288 use_peer_id=True)
289
290 def test_ib_unsolicited_passive_passphrase_any(self):
291 """Data-path: in-band, unsolicited/passive, passphrase, any peer
292
293 Verifies end-to-end discovery + data-path creation.
294 """
295 self.run_ib_data_path_test(
296 ptype=aconsts.PUBLISH_TYPE_UNSOLICITED,
297 stype=aconsts.SUBSCRIBE_TYPE_PASSIVE,
298 encr_type=self.ENCR_TYPE_PASSPHRASE,
299 use_peer_id=False)
300
301 def test_ib_solicited_active_open_specific(self):
Etan Cohenba8a53f2017-06-05 12:55:02 -0700302 """Data-path: in-band, solicited/active, open encryption, specific peer
Etan Cohenfc5f3732017-06-02 17:31:52 -0700303
Etan Cohenba8a53f2017-06-05 12:55:02 -0700304 Verifies end-to-end discovery + data-path creation.
305 """
306 self.run_ib_data_path_test(
307 ptype=aconsts.PUBLISH_TYPE_SOLICITED,
308 stype=aconsts.SUBSCRIBE_TYPE_ACTIVE,
309 encr_type=self.ENCR_TYPE_OPEN,
310 use_peer_id=True)
Etan Cohenfc5f3732017-06-02 17:31:52 -0700311
312 def test_ib_solicited_active_open_any(self):
Etan Cohenba8a53f2017-06-05 12:55:02 -0700313 """Data-path: in-band, solicited/active, open encryption, any peer
Etan Cohenfc5f3732017-06-02 17:31:52 -0700314
Etan Cohenba8a53f2017-06-05 12:55:02 -0700315 Verifies end-to-end discovery + data-path creation.
316 """
317 self.run_ib_data_path_test(
318 ptype=aconsts.PUBLISH_TYPE_SOLICITED,
319 stype=aconsts.SUBSCRIBE_TYPE_ACTIVE,
320 encr_type=self.ENCR_TYPE_OPEN,
321 use_peer_id=False)
Etan Cohenfc5f3732017-06-02 17:31:52 -0700322
323 def test_ib_solicited_active_passphrase_specific(self):
Etan Cohenba8a53f2017-06-05 12:55:02 -0700324 """Data-path: in-band, solicited/active, passphrase, specific peer
Etan Cohenfc5f3732017-06-02 17:31:52 -0700325
Etan Cohenba8a53f2017-06-05 12:55:02 -0700326 Verifies end-to-end discovery + data-path creation.
327 """
328 self.run_ib_data_path_test(
329 ptype=aconsts.PUBLISH_TYPE_SOLICITED,
330 stype=aconsts.SUBSCRIBE_TYPE_ACTIVE,
331 encr_type=self.ENCR_TYPE_PASSPHRASE,
332 use_peer_id=True)
Etan Cohenfc5f3732017-06-02 17:31:52 -0700333
334 def test_ib_solicited_active_passphrase_any(self):
Etan Cohenba8a53f2017-06-05 12:55:02 -0700335 """Data-path: in-band, solicited/active, passphrase, any peer
Etan Cohenfc5f3732017-06-02 17:31:52 -0700336
Etan Cohenba8a53f2017-06-05 12:55:02 -0700337 Verifies end-to-end discovery + data-path creation.
338 """
339 self.run_ib_data_path_test(
340 ptype=aconsts.PUBLISH_TYPE_SOLICITED,
341 stype=aconsts.SUBSCRIBE_TYPE_ACTIVE,
342 encr_type=self.ENCR_TYPE_PASSPHRASE,
343 use_peer_id=False)
Etan Cohenfc5f3732017-06-02 17:31:52 -0700344
Etan Cohenba8a53f2017-06-05 12:55:02 -0700345 #######################################
346 # Positive Out-of-Band (OOB) tests key:
347 #
348 # names is: test_oob_<encr_type>_<peer_spec>
349 # where:
350 #
351 # encr_type: Encription type: open, passphrase
352 # peer_spec: Peer specification method: any or specific
353 #
354 # Note: Out-of-Band means using a non-Wi-Fi Aware mechanism for discovery and
355 # exchange of MAC addresses and then Wi-Fi Aware for data-path.
356 #######################################
357
358 def test_oob_open_specific(self):
359 """Data-path: out-of-band, open encryption, specific peer
360
361 Verifies end-to-end discovery + data-path creation.
362 """
363 self.run_oob_data_path_test(
364 encr_type=self.ENCR_TYPE_OPEN,
365 use_peer_id=True)
366
367 def test_oob_open_any(self):
368 """Data-path: out-of-band, open encryption, any peer
369
370 Verifies end-to-end discovery + data-path creation.
371 """
372 self.run_oob_data_path_test(
373 encr_type=self.ENCR_TYPE_OPEN,
374 use_peer_id=False)
375
376 def test_oob_passphrase_specific(self):
377 """Data-path: out-of-band, passphrase, specific peer
378
379 Verifies end-to-end discovery + data-path creation.
380 """
381 self.run_oob_data_path_test(
382 encr_type=self.ENCR_TYPE_PASSPHRASE,
383 use_peer_id=True)
384
385 def test_oob_passphrase_any(self):
386 """Data-path: out-of-band, passphrase, any peer
387
388 Verifies end-to-end discovery + data-path creation.
389 """
390 self.run_oob_data_path_test(
391 encr_type=self.ENCR_TYPE_PASSPHRASE,
392 use_peer_id=False)