Christopher Wiley | b7183e6 | 2013-06-19 13:36:23 -0700 | [diff] [blame] | 1 | # 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 | |
| 5 | import logging |
| 6 | |
Debayan | 4f59e4a | 2017-03-09 15:49:23 -0800 | [diff] [blame] | 7 | from autotest_lib.client.common_lib import error |
Christopher Wiley | 6aafddd | 2013-07-19 14:04:26 -0700 | [diff] [blame] | 8 | from autotest_lib.client.common_lib.cros.network import ping_runner |
Christopher Wiley | b7183e6 | 2013-06-19 13:36:23 -0700 | [diff] [blame] | 9 | from autotest_lib.client.common_lib.cros.network import xmlrpc_datatypes |
| 10 | from autotest_lib.client.common_lib.cros.network import xmlrpc_security_types |
Christopher Wiley | 99d42c9 | 2013-07-09 16:40:16 -0700 | [diff] [blame] | 11 | from autotest_lib.server.cros.network import hostap_config |
Christopher Wiley | 4961e84 | 2013-07-09 16:03:56 -0700 | [diff] [blame] | 12 | from autotest_lib.server.cros.network import wifi_cell_test_base |
Christopher Wiley | b7183e6 | 2013-06-19 13:36:23 -0700 | [diff] [blame] | 13 | |
| 14 | |
| 15 | class network_WiFi_PTK(wifi_cell_test_base.WiFiCellTestBase): |
Christopher Wiley | 6aafddd | 2013-07-19 14:04:26 -0700 | [diff] [blame] | 16 | """Test that pairwise temporal key rotations work as expected.""" |
Christopher Wiley | b7183e6 | 2013-06-19 13:36:23 -0700 | [diff] [blame] | 17 | version = 1 |
| 18 | |
Debayan | 4f59e4a | 2017-03-09 15:49:23 -0800 | [diff] [blame] | 19 | # These settings combine to give us around 75 seconds of ping time, |
| 20 | # which should be around 15 rekeys. |
Christopher Wiley | b7183e6 | 2013-06-19 13:36:23 -0700 | [diff] [blame] | 21 | PING_COUNT = 150 |
Debayan | 4f59e4a | 2017-03-09 15:49:23 -0800 | [diff] [blame] | 22 | PING_INTERVAL = 0.5 |
Christopher Wiley | b7183e6 | 2013-06-19 13:36:23 -0700 | [diff] [blame] | 23 | REKEY_PERIOD = 5 |
Debayan | 4f59e4a | 2017-03-09 15:49:23 -0800 | [diff] [blame] | 24 | PING_LOSS_THRESHOLD=20 |
Christopher Wiley | b7183e6 | 2013-06-19 13:36:23 -0700 | [diff] [blame] | 25 | |
| 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 Wiley | e8fb86b | 2014-07-02 11:36:39 -0700 | [diff] [blame] | 39 | # TODO(wiley) This is just until we find the source of these |
| 40 | # test failures. |
Kirtika Ruchandani | 103c4fd | 2017-03-24 17:30:58 -0700 | [diff] [blame] | 41 | self.context.capture_host.start_capture(ap_config.frequency) |
Christopher Wiley | b7183e6 | 2013-06-19 13:36:23 -0700 | [diff] [blame] | 42 | self.context.configure(ap_config) |
Christopher Wiley | 6aafddd | 2013-07-19 14:04:26 -0700 | [diff] [blame] | 43 | assoc_params = xmlrpc_datatypes.AssociationParameters( |
| 44 | ssid=self.context.router.get_ssid(), |
| 45 | security_config=wpa_config) |
Christopher Wiley | b7183e6 | 2013-06-19 13:36:23 -0700 | [diff] [blame] | 46 | self.context.assert_connect_wifi(assoc_params) |
Christopher Wiley | 6aafddd | 2013-07-19 14:04:26 -0700 | [diff] [blame] | 47 | ping_config = ping_runner.PingConfig(self.context.get_wifi_addr(), |
| 48 | count=self.PING_COUNT, |
Debayan | 4f59e4a | 2017-03-09 15:49:23 -0800 | [diff] [blame] | 49 | interval=self.PING_INTERVAL, |
| 50 | ignore_result=True) |
Christopher Wiley | b7183e6 | 2013-06-19 13:36:23 -0700 | [diff] [blame] | 51 | logging.info('Pinging DUT for %d seconds and rekeying ' |
Christopher Wiley | 6aafddd | 2013-07-19 14:04:26 -0700 | [diff] [blame] | 52 | 'every %d seconds.', |
| 53 | self.PING_COUNT * self.PING_INTERVAL, |
| 54 | self.REKEY_PERIOD) |
Debayan | 4f59e4a | 2017-03-09 15:49:23 -0800 | [diff] [blame] | 55 | ping_result = self.context.client.ping(ping_config=ping_config) |
| 56 | logging.info('Ping loss percentage: %d.', ping_result.loss) |
| 57 | 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 Wiley | b7183e6 | 2013-06-19 13:36:23 -0700 | [diff] [blame] | 62 | self.context.client.shill.disconnect(assoc_params.ssid) |
| 63 | self.context.router.deconfig() |
Kirtika Ruchandani | 103c4fd | 2017-03-24 17:30:58 -0700 | [diff] [blame] | 64 | self.context.capture_host.stop_capture() |