1# Copyright (c) 2021 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 5from autotest_lib.client.common_lib import error 6from autotest_lib.client.common_lib.cros.network import ping_runner 7from autotest_lib.server.cros.network import ip_config_context_manager 8from autotest_lib.server.cros.network import wifi_cell_test_base 9 10 11class WiFiCellPerfTestBase(wifi_cell_test_base.WiFiCellTestBase): 12 """An abstract base class for autotests in WiFi performance cells. 13 14 Similar to WiFiCellTestBase with one major exception: 15 16 The pcap device is also used as an endpoint in performance tests, so the 17 router and pcap device must have a direct Ethernet connection over their LAN 18 ports in a WiFiCellPerfTestBase. 19 """ 20 21 def configure_and_connect_to_ap(self, ap_config): 22 """Configure the router as an AP with the given config and connect 23 the DUT to it. 24 25 @param ap_config HostapConfig object. 26 27 @return name of the configured AP 28 """ 29 # self.context.configure has a similar check - but that one only 30 # errors out if the AP *requires* VHT i.e. AP is requesting 31 # MODE_11AC_PURE and the client does not support it. 32 # For performance tests we don't want to run MODE_11AC_MIXED on the AP if 33 # the client does not support VHT, as we are guaranteed to get the 34 # same results at 802.11n/HT40 in that case. 35 if ap_config.is_11ac and not self.context.client.is_vht_supported(): 36 raise error.TestNAError('Client does not have AC support') 37 return super(WiFiCellPerfTestBase, 38 self).configure_and_connect_to_ap(ap_config) 39 40 def _verify_additional_setup_requirements(self): 41 """Ensure that the router and pcap device in the cell have a direct 42 connection available over their respective LAN ports. Raises a test NA 43 error if this connection cannot be verified. 44 """ 45 router_lan_ip_addr = "192.168.1.50" 46 pcap_lan_ip_addr = "192.168.1.51" 47 router_lan_iface_name = "eth1" 48 pcap_lan_iface_name = "eth1" 49 50 with ip_config_context_manager.IpConfigContextManager() as ip_context: 51 try: 52 ip_context.bring_interface_up(self.context.router.host, 53 router_lan_iface_name) 54 ip_context.bring_interface_up(self.context.pcap_host.host, 55 pcap_lan_iface_name) 56 ip_context.assign_ip_addr_to_iface(self.context.router.host, 57 router_lan_ip_addr, 58 router_lan_iface_name) 59 ip_context.assign_ip_addr_to_iface(self.context.pcap_host.host, 60 pcap_lan_ip_addr, 61 pcap_lan_iface_name) 62 ping_config = ping_runner.PingConfig( 63 pcap_lan_ip_addr, 64 count=5, 65 source_iface=router_lan_iface_name, 66 ignore_result=True) 67 ping_result = self.context.router.ping(ping_config) 68 if ping_result.received == 0: 69 raise Exception("Ping failed (%s)" % (ping_result)) 70 except Exception as e: 71 raise error.TestNAError( 72 'Could not verify connection between router and pcap ' 73 'devices. Router and pcap device must have a direct ' 74 'Ethernet connection over their LAN ports to run ' 75 'performance tests: %s' % (e)) 76