• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
6between 4 isolation boxes with APs and 4 isolation boxes with DUTs.
7
8RFSwitchController Class provides methods to control RF Switch.
9
10This class can be used to:
111) retrieve all APBoxes and ClientBoxes connected to the RF Switch.
122) connect Client and AP Boxes for testing.
133) retrieve information about current connections.
144) reset all connections.
15"""
16
17import logging
18
19from autotest_lib.server import frontend
20from autotest_lib.server import site_utils
21from autotest_lib.server.cros.network import rf_switch_ap_box
22from autotest_lib.server.cros.network import rf_switch_client_box
23
24
25RF_SWITCH_STR = 'rf_switch_'
26RF_SWITCH_CLIENT = 'rf_switch_client'
27RF_SWITCH_APS = 'rf_switch_aps'
28
29
30class 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