Home | History | Annotate | Download | only in network_WiFi_Regulatory
      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 from autotest_lib.client.common_lib import error
      6 from autotest_lib.client.common_lib.cros.network import ping_runner
      7 from autotest_lib.client.common_lib.cros.network import xmlrpc_datatypes
      8 from autotest_lib.server import site_linux_system
      9 from autotest_lib.server.cros.network import wifi_cell_test_base
     10 
     11 
     12 class network_WiFi_Regulatory(wifi_cell_test_base.WiFiCellTestBase):
     13     """Test that the client vacates the channel after notification
     14     from the AP that it should switch channels."""
     15     version = 1
     16 
     17 
     18     def parse_additional_arguments(self, commandline_args, additional_params):
     19         """Hook into super class to take control files parameters.
     20 
     21         @param commandline_args dict of parsed parameters from the autotest.
     22         @param additional_params list of dicts describing router configs.
     23 
     24         """
     25         self._configurations = additional_params
     26 
     27 
     28     def run_once(self):
     29         """Sets up a router, connects to it, then tests a channel switch."""
     30         for router_conf, alternate_channel in self._configurations:
     31             self.context.router.require_capabilities(
     32                   [site_linux_system.LinuxSystem.
     33                           CAPABILITY_SEND_MANAGEMENT_FRAME])
     34             self.context.configure(router_conf)
     35             self.context.capture_host.start_capture(
     36                     router_conf.frequency,
     37                     filename='chan%d.pcap' % router_conf.channel)
     38             assoc_params = xmlrpc_datatypes.AssociationParameters()
     39             assoc_params.ssid = self.context.router.get_ssid()
     40             self.context.assert_connect_wifi(assoc_params)
     41             ping_config = ping_runner.PingConfig(
     42                     self.context.get_wifi_addr(ap_num=0))
     43             client_mac = self.context.client.wifi_mac
     44             for attempt in range(10):
     45                 # Since the client might be in power-save, we are not
     46                 # guaranteed it will hear this message the first time around.
     47                 self.context.router.send_management_frame_on_ap(
     48                         'channel_switch', alternate_channel)
     49 
     50                 # Test to see if the router received a deauth message from
     51                 # the client.
     52                 if self.context.router.detect_client_deauth(client_mac):
     53                     break
     54 
     55                 # Otherwise detect the client leaving indirectly by measuring
     56                 # client pings.  This should fail at some point.
     57                 ping_config = ping_runner.PingConfig(
     58                         self.context.get_wifi_addr(ap_num=0),
     59                         count=3, ignore_status=True,
     60                         ignore_result=True)
     61                 result = self.context.client.ping(ping_config)
     62                 if result.loss > 60:
     63                     break
     64             else:
     65                 raise error.TestFail('Client never lost connectivity')
     66             self.context.client.shill.disconnect(assoc_params.ssid)
     67             self.context.router.deconfig()
     68             self.context.capture_host.stop_capture()
     69