Home | History | Annotate | Download | only in network_WiFi_LinkMonitorFailure
      1 # Copyright 2015 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 import time
      7 
      8 from autotest_lib.client.common_lib import error
      9 from autotest_lib.client.common_lib.cros.network import xmlrpc_datatypes
     10 from autotest_lib.server.cros.network import hostap_config
     11 from autotest_lib.server.cros.network import wifi_cell_test_base
     12 
     13 
     14 class network_WiFi_LinkMonitorFailure(wifi_cell_test_base.WiFiCellTestBase):
     15     """Test how a DUT behaves when the network link disappears.
     16 
     17     Connects a DUT to an AP, then silently change the gateway IP on the AP
     18     to simulate network link disappearance. Determine the time the DUT take
     19     to detect link failure and the time for the subsequent reassociation
     20     request.
     21 
     22     """
     23 
     24     version = 1
     25 
     26     # Passive link monitor takes 25 seconds to fail, active link monitor
     27     # takes upto 50 seconds to fail (unicast ARP failures doesn't count since
     28     # unicast ARP gateway support is not established).
     29     LINK_FAILURE_MAX_SECONDS = 80
     30     REASSOCIATE_TIMEOUT_SECONDS = 10
     31 
     32     def run_once(self):
     33         """Body of the test."""
     34         # Establish a connection with an AP.
     35         ap_config = hostap_config.HostapConfig(channel=1)
     36         self.context.configure(ap_config)
     37         ssid = self.context.router.get_ssid()
     38         client_config = xmlrpc_datatypes.AssociationParameters(ssid=ssid)
     39         self.context.assert_connect_wifi(client_config)
     40         self.context.assert_ping_from_dut()
     41 
     42         # Restart local server with a different address index. This will
     43         # simulate the disappearance of the network link from the client's
     44         # point of view.
     45         logging.info("Restart local server with different address")
     46         self.context.router.change_server_address_index()
     47         with self.context.client.iw_runner.get_event_logger() as logger:
     48             logger.start()
     49             # wait for the timeout seconds for link failure and reassociation
     50             # to complete.
     51             time.sleep(self.LINK_FAILURE_MAX_SECONDS +
     52                        self.REASSOCIATE_TIMEOUT_SECONDS)
     53             logger.stop()
     54 
     55             # Link failure detection time.
     56             link_failure_time = logger.get_time_to_disconnected()
     57             if (link_failure_time is None or
     58                 link_failure_time > self.LINK_FAILURE_MAX_SECONDS):
     59                 raise error.TestFail(
     60                         'Failed to detect link failure within given timeout')
     61             logging.info('Link failure detection time: %.2f seconds',
     62                          link_failure_time)
     63 
     64             # Reassociation time.
     65             reassociate_time = logger.get_reassociation_time()
     66             if (reassociate_time is None or
     67                 reassociate_time > self.REASSOCIATE_TIMEOUT_SECONDS):
     68                 raise error.TestFail(
     69                         'Failed to reassociate within given timeout')
     70             logging.info('Reassociate time: %.2f seconds', reassociate_time)
     71