def test_android_get_interface_ip_addresses_empty(self, adb_mock): adb_mock().shell.side_effect = [ MOCK_IP_ADDRESSES, MOCK_IFCONFIG_OUTPUT ] self.assertEqual( utils.get_interface_ip_addresses(AndroidDevice(), 'wlan1'), CORRECT_EMPTY_IP_LIST)
def test_android_get_interface_ip_addresses_full(self, is_bootloader, adb_mock): adb_mock().shell.side_effect = [ MOCK_IP_ADDRESSES, MOCK_IFCONFIG_OUTPUT ] self.assertEqual( utils.get_interface_ip_addresses(AndroidDevice(), 'eno1'), CORRECT_FULL_IP_LIST)
def test_local_get_interface_ip_addresses_empty(self, job_mock): job_mock.side_effect = [ job.Result(stdout=bytes(MOCK_IP_ADDRESSES, 'utf-8'), encoding='utf-8'), job.Result(stdout=bytes(MOCK_IFCONFIG_OUTPUT, 'utf-8'), encoding='utf-8') ] self.assertEqual(utils.get_interface_ip_addresses(job, 'wlan1'), CORRECT_EMPTY_IP_LIST)
def test_fuchsia_get_interface_ip_addresses_empty(self, init_mock, list_interfaces_mock, fuchsia_device_mock): init_mock.return_value = None list_interfaces_mock.return_value = FUCHSIA_INTERFACES fuchsia_device_mock.return_value = None self.assertEqual( utils.get_interface_ip_addresses( FuchsiaDevice({'ip': '192.168.1.1'}), 'wlan1'), CORRECT_EMPTY_IP_LIST)
def test_ssh_get_interface_ip_addresses_empty(self, ssh_mock): ssh_mock.side_effect = [ job.Result(stdout=bytes(MOCK_IP_ADDRESSES, 'utf-8'), encoding='utf-8'), job.Result(stdout=bytes(MOCK_IFCONFIG_OUTPUT, 'utf-8'), encoding='utf-8') ] self.assertEqual( utils.get_interface_ip_addresses(SshConnection('mock_settings'), 'wlan1'), CORRECT_EMPTY_IP_LIST)
def get_interface_ip_addresses(self, interface): """Gets all of the ip addresses, ipv4 and ipv6, associated with a particular interface name. Args: interface: The interface name on the device, ie eth0 Returns: A list of dictionaries of the the various IP addresses: ipv4_private_local_addresses: Any 192.168, 172.16, or 10 addresses ipv4_public_addresses: Any IPv4 public addresses ipv6_link_local_addresses: Any fe80:: addresses ipv6_private_local_addresses: Any fd00:: addresses ipv6_public_addresses: Any publicly routable addresses """ return utils.get_interface_ip_addresses(job, interface)
def _reserve_server(self, subnet): """Reserves an available IPerfServer for use in a stream from another WmmTransceiver. If none are available, a new one is created. Args: subnet: string, subnet of test network, to retrieve the appropriate server address Returns: (string, int) representing the IPerfServer address and port """ reserved_server = None for server in self._iperf_servers: if self._iperf_servers[server] == AVAILABLE: reserved_server = server break else: iperf_server_config = self._iperf_config iperf_server_config.update({'port': self._next_server_port}) self._next_server_port += 1 reserved_server = iperf_server.create([iperf_server_config])[0] self._iperf_server_ports[reserved_server.port] = reserved_server self._iperf_servers[reserved_server] = UNAVAILABLE reserved_server.start() end_time = time.time() + DEFAULT_IP_ADDR_TIMEOUT while time.time() < end_time: if self.wlan_device: addresses = utils.get_interface_ip_addresses( self.wlan_device.device, self._test_interface) else: addresses = reserved_server.get_interface_ip_addresses( self._test_interface) for addr in addresses['ipv4_private']: if utils.ip_in_subnet(addr, subnet): return (addr, reserved_server.port) raise AttributeError( 'Reserved server has no ipv4 address in the %s subnet' % subnet)
def test_soft_ap_and_client(self): """ Tests FuchsiaDevice DUT can act as a client and a SoftAP simultaneously. Raises: ConnectionError: if DUT fails to connect as client RuntimeError: if parallel processes fail to join TestFailure: if DUT fails to pass traffic as either a client or an AP """ asserts.skip_if(not self.access_point, 'No access point provided.') self.log.info('Setting up AP using hostapd.') # Configure AP ap_params = self.user_params.get('soft_ap_test_params', {}).get('ap_params', {}) channel = ap_params.get('channel', 11) ssid = ap_params.get('ssid', 'apnet') security_mode = ap_params.get('security_mode', None) password = ap_params.get('password', None) if security_mode: security = hostapd_security.Security(security_mode, password) else: security = None # Setup AP and associate DUT if not setup_ap_and_associate(access_point=self.access_point, client=self.dut, profile_name='whirlwind', channel=channel, security=security, password=password, ssid=ssid): raise ConnectionError( 'FuchsiaDevice DUT failed to connect as client to AP.') self.log.info('DUT successfully associated to AP network.') # Verify FuchsiaDevice's client interface has an ip address from AP dut_client_interface = self.get_dut_interface_by_role( INTERFACE_ROLE_CLIENT) # Verify FuchsiaDevice can ping AP lowest_5ghz_channel = 36 if channel < lowest_5ghz_channel: ap_interface = self.access_point.wlan_2g else: ap_interface = self.access_point.wlan_5g ap_ipv4 = utils.get_interface_ip_addresses( self.access_point.ssh, ap_interface)['ipv4_private'][0] self.verify_ping(self.dut, ap_ipv4) # Setup SoftAP soft_ap_settings = { 'ssid': utils.rand_ascii_str(hostapd_constants.AP_SSID_LENGTH_2G), 'security_type': SECURITY_OPEN, 'connectivity_mode': CONNECTIVITY_MODE_LOCAL, 'operating_band': OPERATING_BAND_2G } self.start_soft_ap(soft_ap_settings) # Get FuchsiaDevice's AP interface info dut_ap_interface = self.get_dut_interface_by_role(INTERFACE_ROLE_AP) # Associate primary client with SoftAP self.associate_with_soft_ap(self.primary_client.w_device, soft_ap_settings) # Verify primary client has an ip address from SoftAP client_ipv4 = self.wait_for_ipv4_address(self.primary_client.w_device, ANDROID_DEFAULT_WLAN_PORT) # Verify primary client can ping SoftAP, and reverse self.verify_ping(self.primary_client.w_device, dut_ap_interface.ipv4) self.verify_ping(self.dut, client_ipv4) # Set up secondary iperf server of FuchsiaDevice self.log.info('Setting up second iperf server on FuchsiaDevice DUT.') secondary_iperf_server = iperf_server.IPerfServerOverSsh( self.iperf_server_config, DEFAULT_IPERF_PORT + 1, use_killall=True) secondary_iperf_server.start() # Set up iperf client on AP self.log.info('Setting up iperf client on AP.') ap_iperf_client = iperf_client.IPerfClientOverSsh( self.user_params['AccessPoint'][0]['ssh_config']) # Setup iperf processes: # Primary client <-> SoftAP interface on FuchsiaDevice # AP <-> Client interface on FuchsiaDevice process_errors = mp.Queue() iperf_soft_ap = mp.Process( target=self.run_iperf_traffic_parallel_process, args=[ self.primary_client.ip_client, dut_ap_interface.ipv4, process_errors ]) iperf_fuchsia_client = mp.Process( target=self.run_iperf_traffic_parallel_process, args=[ap_iperf_client, dut_client_interface.ipv4, process_errors], kwargs={'server_port': 5202}) # Run iperf processes simultaneously self.log.info('Running simultaneous iperf traffic: between AP and DUT ' 'client interface, and DUT AP interface and client.') iperf_soft_ap.start() iperf_fuchsia_client.start() # Block until processes can join or timeout for proc in [iperf_soft_ap, iperf_fuchsia_client]: proc.join(timeout=30) if proc.is_alive(): raise RuntimeError('Failed to join process %s' % proc) # Stop iperf server (also stopped in teardown class as failsafe) secondary_iperf_server.stop() # Check errors from parallel processes if process_errors.empty(): asserts.explicit_pass( 'FuchsiaDevice was successfully able to pass traffic as a ' 'client and an AP simultaneously.') else: while not process_errors.empty(): self.log.error('Error in iperf process: %s' % process_errors.get()) asserts.fail( 'FuchsiaDevice failed to pass traffic as a client and an AP ' 'simultaneously.')
def get_interface_ip_addresses(self, interface): return get_interface_ip_addresses(self.device, interface)