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 logging
     18 
     19 from autotest_lib.server import frontend
     20 from autotest_lib.server import site_utils
     21 from autotest_lib.server.cros.network import rf_switch_ap_box
     22 from autotest_lib.server.cros.network import rf_switch_client_box
     23 
     24 
     25 RF_SWITCH_STR = 'rf_switch_'
     26 RF_SWITCH_CLIENT = 'rf_switch_client'
     27 RF_SWITCH_APS = 'rf_switch_aps'
     28 
     29 
     30 class RFSwitchController(object):
     31     """Controller class to manage the RFSwitch."""
     32 
     33 
     34     def __init__(self, rf_switch_host):
     35         """Constructor for RF Switch Controller.
     36 
     37         @param rf_switch_host: An AFE Host object of RF Switch.
     38         """
     39         self.rf_switch_host = rf_switch_host
     40         self.rf_switch_labels = rf_switch_host.labels
     41         # RF Switches are named as rf_switch_1, rf_switch_2 using labels.
     42         # To find the rf_switch, find label starting with 'rf_switch_'
     43         labels = [
     44                 s for s in self.rf_switch_labels if s.startswith(RF_SWITCH_STR)]
     45         afe = frontend.AFE(
     46                 debug=True, server=site_utils.get_global_afe_hostname())
     47         self.hosts = afe.get_hosts(label=labels)
     48         self.ap_boxes = []
     49         self.client_boxes = []
     50         for host in self.hosts:
     51             if RF_SWITCH_APS in host.labels:
     52                 self.ap_boxes.append(rf_switch_ap_box.APBox(host))
     53             elif RF_SWITCH_CLIENT in host.labels:
     54                 self.client_boxes.append(rf_switch_client_box.ClientBox(host))
     55         if not self.ap_boxes:
     56             logging.error('No AP boxes available for the RF Switch.')
     57         if not self.client_boxes:
     58             logging.error('No Client boxes available for the RF Switch.')
     59 
     60 
     61     def get_ap_boxes(self):
     62         """Returns all AP Boxes connected to the RF Switch.
     63 
     64         @returns a list of
     65         autotest_lib.server.cros.network.rf_switch_ap_box.APBox objects.
     66         """
     67         return self.ap_boxes
     68 
     69 
     70     def get_client_boxes(self):
     71         """Returns all Client Boxes connected to the RF Switch.
     72 
     73         @returns a list of
     74         autotest_lib.server.cros.network.rf_switch_client_box.ClientBox objects.
     75         """
     76         return self.client_boxes
     77