Home | History | Annotate | Download | only in network
      1 # Copyright (c) 2017 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 """RF Switch is a device used to route WiFi signals through RF cables
      6 between 4 isolation boxes with APs and 4 isolation boxes with DUTs.
      7 
      8 RFSwitchController Class provides methods to control RF Switch.
      9 
     10 This class can be used to:
     11 1) retrieve all APBoxes and ClientBoxes connected to the RF Switch.
     12 2) connect Client and AP Boxes for testing.
     13 3) retrieve information about current connections.
     14 4) reset all connections.
     15 """
     16 
     17 import common
     18 import logging
     19 
     20 from autotest_lib.server import frontend
     21 from autotest_lib.server import site_utils
     22 from autotest_lib.server.cros.network import rf_switch_ap_box
     23 from autotest_lib.server.cros.network import rf_switch_client_box
     24 
     25 
     26 RF_SWITCH_STR = 'rf_switch_'
     27 RF_SWITCH_CLIENT = 'rf_switch_client'
     28 RF_SWITCH_APS = 'rf_switch_aps'
     29 
     30 
     31 class RFSwitchController(object):
     32     """Controller class to manage the RFSwitch."""
     33 
     34 
     35     def __init__(self, rf_switch_host):
     36         """Constructor for RF Switch Controller.
     37 
     38         @param rf_switch_host: An AFE Host object of RF Switch.
     39         """
     40         self.rf_switch_host = rf_switch_host
     41         self.rf_switch_labels = rf_switch_host.labels
     42         # RF Switches are named as rf_switch_1, rf_switch_2 using labels.
     43         # To find the rf_switch, find label starting with 'rf_switch_'
     44         labels = [
     45                 s for s in self.rf_switch_labels if s.startswith(RF_SWITCH_STR)]
     46         afe = frontend.AFE(
     47                 debug=True, server=site_utils.get_global_afe_hostname())
     48         self.hosts = afe.get_hosts(label=labels[0])
     49         self.ap_boxes = []
     50         self.client_boxes = []
     51         for host in self.hosts:
     52             if RF_SWITCH_APS in host.labels:
     53                 self.ap_boxes.append(rf_switch_ap_box.APBox(host))
     54             elif RF_SWITCH_CLIENT in host.labels:
     55                 self.client_boxes.append(rf_switch_client_box.ClientBox(host))
     56         if not self.ap_boxes:
     57             logging.error('No AP boxes available for the RF Switch.')
     58         if not self.client_boxes:
     59             logging.error('No Client boxes available for the RF Switch.')
     60 
     61 
     62     def get_ap_boxes(self):
     63         """Returns all AP Boxes connected to the RF Switch.
     64 
     65         @returns a list of
     66         autotest_lib.server.cros.network.rf_switch_ap_box.APBox objects.
     67         """
     68         return self.ap_boxes
     69 
     70 
     71     def get_client_boxes(self):
     72         """Returns all Client Boxes connected to the RF Switch.
     73 
     74         @returns a list of
     75         autotest_lib.server.cros.network.rf_switch_client_box.ClientBox objects.
     76         """
     77         return self.client_boxes
     78