blob: f0638435c4458b26a676cecc30cfed1d29b63525 [file] [log] [blame]
Christopher Wileyb7183e62013-06-19 13:36:23 -07001# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import logging
6
Debayan4f59e4a2017-03-09 15:49:23 -08007from autotest_lib.client.common_lib import error
Christopher Wiley6aafddd2013-07-19 14:04:26 -07008from autotest_lib.client.common_lib.cros.network import ping_runner
Christopher Wileyb7183e62013-06-19 13:36:23 -07009from autotest_lib.client.common_lib.cros.network import xmlrpc_datatypes
10from autotest_lib.client.common_lib.cros.network import xmlrpc_security_types
Christopher Wiley99d42c92013-07-09 16:40:16 -070011from autotest_lib.server.cros.network import hostap_config
Christopher Wiley4961e842013-07-09 16:03:56 -070012from autotest_lib.server.cros.network import wifi_cell_test_base
Christopher Wileyb7183e62013-06-19 13:36:23 -070013
14
15class network_WiFi_PTK(wifi_cell_test_base.WiFiCellTestBase):
Christopher Wiley6aafddd2013-07-19 14:04:26 -070016 """Test that pairwise temporal key rotations work as expected."""
Christopher Wileyb7183e62013-06-19 13:36:23 -070017 version = 1
18
Debayan4f59e4a2017-03-09 15:49:23 -080019 # These settings combine to give us around 75 seconds of ping time,
20 # which should be around 15 rekeys.
Christopher Wileyb7183e62013-06-19 13:36:23 -070021 PING_COUNT = 150
Debayan4f59e4a2017-03-09 15:49:23 -080022 PING_INTERVAL = 0.5
Christopher Wileyb7183e62013-06-19 13:36:23 -070023 REKEY_PERIOD = 5
Debayan4f59e4a2017-03-09 15:49:23 -080024 PING_LOSS_THRESHOLD=20
Christopher Wileyb7183e62013-06-19 13:36:23 -070025
26 def run_once(self):
27 """Test body."""
28 wpa_config = xmlrpc_security_types.WPAConfig(
29 psk='chromeos',
30 wpa_mode=xmlrpc_security_types.WPAConfig.MODE_MIXED_WPA,
31 wpa_ciphers=[xmlrpc_security_types.WPAConfig.CIPHER_TKIP,
32 xmlrpc_security_types.WPAConfig.CIPHER_CCMP],
33 wpa2_ciphers=[xmlrpc_security_types.WPAConfig.CIPHER_CCMP],
34 wpa_ptk_rekey_period=self.REKEY_PERIOD)
35 ap_config = hostap_config.HostapConfig(
36 frequency=2412,
37 mode=hostap_config.HostapConfig.MODE_11N_PURE,
38 security_config=wpa_config)
Christopher Wileye8fb86b2014-07-02 11:36:39 -070039 # TODO(wiley) This is just until we find the source of these
40 # test failures.
Kirtika Ruchandani103c4fd2017-03-24 17:30:58 -070041 self.context.capture_host.start_capture(ap_config.frequency)
Christopher Wileyb7183e62013-06-19 13:36:23 -070042 self.context.configure(ap_config)
Christopher Wiley6aafddd2013-07-19 14:04:26 -070043 assoc_params = xmlrpc_datatypes.AssociationParameters(
44 ssid=self.context.router.get_ssid(),
45 security_config=wpa_config)
Christopher Wileyb7183e62013-06-19 13:36:23 -070046 self.context.assert_connect_wifi(assoc_params)
Christopher Wiley6aafddd2013-07-19 14:04:26 -070047 ping_config = ping_runner.PingConfig(self.context.get_wifi_addr(),
48 count=self.PING_COUNT,
Debayan4f59e4a2017-03-09 15:49:23 -080049 interval=self.PING_INTERVAL,
50 ignore_result=True)
Christopher Wileyb7183e62013-06-19 13:36:23 -070051 logging.info('Pinging DUT for %d seconds and rekeying '
Christopher Wiley6aafddd2013-07-19 14:04:26 -070052 'every %d seconds.',
53 self.PING_COUNT * self.PING_INTERVAL,
54 self.REKEY_PERIOD)
Debayan4f59e4a2017-03-09 15:49:23 -080055 ping_result = self.context.client.ping(ping_config=ping_config)
Brian Norriseaf36fe2018-10-25 19:03:07 -070056 logging.info('Ping loss percentage: %r.', ping_result.loss)
Debayan4f59e4a2017-03-09 15:49:23 -080057 self.output_perf_value(description='Network_wifi_PTK_PingLoss',
58 value=ping_result.loss, units='percent', higher_is_better=False)
59 if ping_result.loss > self.PING_LOSS_THRESHOLD:
60 raise error.TestNAError('Lost ping packets %r percentage.' %
61 ping_result.loss)
Christopher Wileyb7183e62013-06-19 13:36:23 -070062 self.context.client.shill.disconnect(assoc_params.ssid)
63 self.context.router.deconfig()
Kirtika Ruchandani103c4fd2017-03-24 17:30:58 -070064 self.context.capture_host.stop_capture()