def validate_ping_between_two_clients(self, config): """Test ping between softap's clients. Connect two android device to the wifi hotspot. Verify the clients can ping each other. Args: config: wifi network config with SSID, password """ # Connect DUT to Network ad1 = self.dut_client ad2 = self.android_devices[2] wutils.wifi_connect(ad1, config, check_connectivity=False) wutils.wifi_connect(ad2, config, check_connectivity=False) ad1_ip = ad1.droid.connectivityGetIPv4Addresses('wlan0')[0] ad2_ip = ad2.droid.connectivityGetIPv4Addresses('wlan0')[0] # Ping each other ad1.log.info("Try to ping %s" % ad2_ip) asserts.assert_true( utils.adb_shell_ping(ad1, count=10, dest_ip=ad2_ip, timeout=20), "%s ping %s failed" % (ad1.serial, ad2_ip)) ad2.log.info("Try to ping %s" % ad1_ip) asserts.assert_true( utils.adb_shell_ping(ad2, count=10, dest_ip=ad1_ip, timeout=20), "%s ping %s failed" % (ad2.serial, ad1_ip))
def validate_ping_between_softap_and_client(self, config): """Test ping between softap and its client. Connect one android device to the wifi hotspot. Verify they can ping each other. Args: config: wifi network config with SSID, password """ wutils.wifi_connect(self.dut_client, config, check_connectivity=False) dut_ip = self.dut.droid.connectivityGetIPv4Addresses(self.AP_IFACE)[0] dut_client_ip = self.dut_client.droid.connectivityGetIPv4Addresses( 'wlan0')[0] self.dut.log.info("Try to ping %s" % dut_client_ip) asserts.assert_true( utils.adb_shell_ping(self.dut, count=10, dest_ip=dut_client_ip, timeout=20), "%s ping %s failed" % (self.dut.serial, dut_client_ip)) self.dut_client.log.info("Try to ping %s" % dut_ip) asserts.assert_true( utils.adb_shell_ping(self.dut_client, count=10, dest_ip=dut_ip, timeout=20), "%s ping %s failed" % (self.dut_client.serial, dut_ip)) wutils.stop_wifi_tethering(self.dut)
def test_firmware_crash_softap_reconnect_stress(self): """Firmware crash stress test for softap mode 1. Turn off dut's Wi-Fi 2. Turn on dut's hotspot and connected by dut client 3. Trigger firmware crash 4. Check ssr happened 5. Check the connectivity of hotspot's client 6. Repeat step 3~5 """ wutils.wifi_toggle_state(self.dut, False) # Setup Soft AP sap_config = wutils.create_softap_config() wutils.start_wifi_tethering(self.dut, sap_config[wutils.WifiEnums.SSID_KEY], sap_config[wutils.WifiEnums.PWD_KEY], wutils.WifiEnums.WIFI_CONFIG_APBAND_2G) config = { "SSID": sap_config[wutils.WifiEnums.SSID_KEY], "password": sap_config[wutils.WifiEnums.PWD_KEY] } # DUT client connects to softap wutils.wifi_toggle_state(self.dut_client, True) wutils.connect_to_wifi_network(self.dut_client, config, check_connectivity=False) # Ping the DUT dut_addr = self.dut.droid.connectivityGetIPv4Addresses( self.ap_iface)[0] asserts.assert_true( utils.adb_shell_ping(self.dut_client, count=10, dest_ip=dut_addr, timeout=20), "%s ping %s failed" % (self.dut_client.serial, dut_addr)) for count in range(self.stress_count): self.log.info( "%s: %d/%d" % (self.current_test_name, count + 1, self.stress_count)) wutils.reset_wifi(self.dut_client) # Trigger firmware crash self.trigger_wifi_firmware_crash(self.dut) # Connect DUT to Network wutils.connect_to_wifi_network(self.dut_client, config, check_connectivity=False) # Ping the DUT server_addr = self.dut.droid.connectivityGetIPv4Addresses( self.ap_iface)[0] asserts.assert_true( utils.adb_shell_ping(self.dut_client, count=10, dest_ip=server_addr, timeout=20), "%s ping %s failed" % (self.dut_client.serial, server_addr)) wutils.stop_wifi_tethering(self.dut)
def iperf_setup(self): # Fetch IP address of the host machine destination_ip = get_host_ip_address(self) if not adb_shell_ping(self.ad, DEFAULT_PING_DURATION, destination_ip): self.log.error("Pings failed to Destination.") return False return destination_ip
def can_ping(self, dest_ip, count=3, interval=1000, timeout=1000, size=25, additional_ping_params=None): return adb_shell_ping(self.device, dest_ip=dest_ip, count=count, timeout=timeout)
def verify_traffic_between_dut_clients(self, ad1, ad2, num_of_tries=2): """Test the clients that connect to DUT's softap can ping each other. Args: ad1: DUT 1 ad2: DUT 2 num_of_tries: the retry times of ping test. """ ad1_ip = ad1.droid.connectivityGetIPv4Addresses(WLAN)[0] ad2_ip = ad2.droid.connectivityGetIPv4Addresses(WLAN)[0] # Ping each other for _ in range(num_of_tries): if utils.adb_shell_ping(ad1, count=10, dest_ip=ad2_ip, timeout=20): break else: asserts.fail("%s ping %s failed" % (ad1.serial, ad2_ip)) for _ in range(num_of_tries): if utils.adb_shell_ping(ad2, count=10, dest_ip=ad1_ip, timeout=20): break else: asserts.fail("%s ping %s failed" % (ad2.serial, ad1_ip))
def iperf_setup(self): # Fetch IP address of the host machine cmd = "|".join(("ifconfig", "grep eth0 -A1", "grep inet", "cut -d ':' -f2", "cut -d ' ' -f 1")) destination_ip = exe_cmd(cmd) destination_ip = (destination_ip.decode("utf-8")).split("\n")[0] self.log.info("Dest IP is %s", destination_ip) if not adb_shell_ping(self.ad, DEFAULT_PING_DURATION, destination_ip): self.log.error("Pings failed to Destination.") return False return destination_ip
def _setup_data(self, set_simulation_func, rat): try: [self.bts1] = set_simulation_func(self.anritsu, self.user_params, self.ad.sim_card) set_usim_parameters(self.anritsu, self.ad.sim_card) set_post_sim_params(self.anritsu, self.user_params, self.ad.sim_card) if self.lte_bandwidth == 20: self.bts1.bandwidth = BtsBandwidth.LTE_BANDWIDTH_20MHz elif self.lte_bandwidth == 15: self.bts1.bandwidth = BtsBandwidth.LTE_BANDWIDTH_15MHz elif self.lte_bandwidth == 10: self.bts1.bandwidth = BtsBandwidth.LTE_BANDWIDTH_10MHz else: self.bts1.bandwidth = BtsBandwidth.LTE_BANDWIDTH_5MHz self.anritsu.start_simulation() if rat == RAT_LTE: preferred_network_setting = NETWORK_MODE_LTE_CDMA_EVDO rat_family = RAT_FAMILY_LTE elif rat == RAT_WCDMA: preferred_network_setting = NETWORK_MODE_GSM_UMTS rat_family = RAT_FAMILY_UMTS elif rat == RAT_GSM: preferred_network_setting = NETWORK_MODE_GSM_ONLY rat_family = RAT_FAMILY_GSM elif rat == RAT_1XRTT: preferred_network_setting = NETWORK_MODE_CDMA rat_family = RAT_FAMILY_CDMA2000 else: self.log.error("No valid RAT provided for SMS test.") return False if not ensure_network_rat( self.log, self.ad, preferred_network_setting, rat_family, toggle_apm_after_setting=True): self.log.error( "Failed to set rat family {}, preferred network:{}".format( rat_family, preferred_network_setting)) return False self.anritsu.wait_for_registration_state() time.sleep(self.SETTLING_TIME) # Fetch IP address of the host machine cmd = "|".join(("ifconfig", "grep eth0 -A1", "grep inet", "cut -d ':' -f2", "cut -d ' ' -f 1")) destination_ip = exe_cmd(cmd) destination_ip = (destination_ip.decode("utf-8")).split("\n")[0] self.log.info("Dest IP is %s", destination_ip) if not adb_shell_ping(self.ad, DEFAULT_PING_DURATION, destination_ip): self.log.error("Pings failed to Destination.") return False self.bts1.output_level = self.start_power_level # Power, iperf, file output, power change for iteration in range(1, self.MAX_ITERATIONS + 1): self.log.info("------- Current Iteration: %d / %d -------", iteration, self.MAX_ITERATIONS) current_power = self.bts1.output_level self.log.info("Current Power Level is %s", current_power) self.ip_server.start() tput_dict = {"Uplink": 0, "Downlink": 0} if iperf_test_by_adb( self.log, self.ad, destination_ip, self.port_num, True, 10, rate_dict=tput_dict): uplink = tput_dict["Uplink"] downlink = tput_dict["Downlink"] else: self.log.error("iperf failed to Destination.") self.log.info("Iteration %d Failed", iteration) if float(current_power) < -55.0: return True else: return False self.ip_server.stop() self.log.info("Iteration %d Passed", iteration) self.logpath = os.path.join(logging.log_path, "power_tput.txt") line = "Power " + current_power + " DL TPUT " + str(downlink) with open(self.logpath, "a") as tput_file: tput_file.write(line) tput_file.write("\n") current_power = float(current_power) new_power = current_power - self.step_size self.log.info("Setting Power Level to %f", new_power) self.bts1.output_level = new_power except AnritsuError as e: self.log.error("Error in connection with Anritsu Simulator: " + str(e)) return False except Exception as e: self.log.error("Exception during Data procedure: " + str(e)) return False return True
def LTE_WCDMA_data_roaming(self, mcc, mnc): try: [self.bts1, self.bts2] = set_system_model_lte_wcdma(self.anritsu, self.user_params, self.ad.sim_card) set_usim_parameters(self.anritsu, self.ad.sim_card) self.bts1.mcc = mcc self.bts1.mnc = mnc self.bts2.mcc = mcc self.bts2.mnc = mnc self.bts2.packet_rate = BtsPacketRate.WCDMA_DLHSAUTO_REL7_ULHSAUTO self.anritsu.start_simulation() self.bts2.service_state = BtsServiceState.SERVICE_STATE_OUT self.log.info("Toggle Mobile Data On") self.ad.droid.telephonyToggleDataConnection(True) if not ensure_network_rat(self.log, self.ad, NETWORK_MODE_LTE_GSM_WCDMA, RAT_FAMILY_LTE, toggle_apm_after_setting=True): self.log.error( "Failed to set rat family {}, preferred network:{}".format( RAT_FAMILY_LTE, NETWORK_MODE_LTE_GSM_WCDMA)) return False toggle_cell_data_roaming(self.ad, True) self.anritsu.wait_for_registration_state(1) # for BTS1 LTE time.sleep(TIME_TO_WAIT_BEFORE_PING) if not adb_shell_ping(self.ad, PING_DURATION, PING_TARGET): self.log.error( "Test Fail: Phone {} can not ping {} with Data Roaming On". format(self.ad.serial, PING_TARGET)) return False toggle_cell_data_roaming(self.ad, False) time.sleep(TIME_TO_WAIT_BEFORE_PING) if adb_shell_ping(self.ad, PING_DURATION, PING_TARGET): self.log.error( "Test Fail: Phone {} can ping {} with Data Roaming Off". format(self.ad.serial, PING_TARGET)) return False toggle_airplane_mode(self.log, self.ad, True) time.sleep(2) self.bts2.service_state = BtsServiceState.SERVICE_STATE_IN self.bts1.service_state = BtsServiceState.SERVICE_STATE_OUT toggle_airplane_mode(self.log, self.ad, False) toggle_cell_data_roaming(self.ad, True) self.anritsu.wait_for_registration_state(2) # for BTS2 WCDMA time.sleep(TIME_TO_WAIT_BEFORE_PING) if not adb_shell_ping(self.ad, PING_DURATION, PING_TARGET): self.log.error( "Test Fail: Phone {} can not ping {} with Data Roaming On". format(self.ad.serial, PING_TARGET)) return False toggle_cell_data_roaming(self.ad, False) time.sleep(TIME_TO_WAIT_BEFORE_PING) if adb_shell_ping(self.ad, PING_DURATION, PING_TARGET): self.log.error( "Test Fail: Phone {} can ping {} with Data Roaming Off". format(self.ad.serial, PING_TARGET)) return False except AnritsuError as e: self.log.error("Error in connection with Anritsu Simulator: " + str(e)) return False except Exception as e: self.log.error("Exception during data roaming: " + str(e)) return False return True
def LTE_WCDMA_data_roaming(self, mcc, mnc, lte_band, wcdma_band): try: [self.bts1, self.bts2] = set_system_model_lte_wcdma(self.anritsu, self.user_params, self.ad.sim_card) set_usim_parameters(self.anritsu, self.ad.sim_card) set_post_sim_params(self.anritsu, self.user_params, self.ad.sim_card) self.bts1.mcc = mcc self.bts1.mnc = mnc self.bts2.mcc = mcc self.bts2.mnc = mnc self.bts1.band = lte_band self.bts2.band = wcdma_band self.bts2.packet_rate = BtsPacketRate.WCDMA_DLHSAUTO_REL8_ULHSAUTO self.anritsu.start_simulation() self.bts2.service_state = BtsServiceState.SERVICE_STATE_OUT self.log.info("Toggle Mobile Data On") self.ad.droid.telephonyToggleDataConnection(True) if not self.phone_setup_data_roaming(): self.log.warning("phone_setup_func failed. Rebooting UE") self.ad.reboot() time.sleep(30) if self.ad.sim_card == "VzW12349": set_preferred_apn_by_adb(self.ad, "VZWINTERNET") if not self.phone_setup_data_roaming(): self.log.error( "Failed to set rat family {}, preferred network:{}". format(RAT_FAMILY_LTE, NETWORK_MODE_LTE_GSM_WCDMA)) return False toggle_cell_data_roaming(self.ad, True) self.anritsu.wait_for_registration_state(1) # for BTS1 LTE time.sleep(TIME_TO_WAIT_BEFORE_PING) for i in range(3): self.ad.log.info("Verify internet connection - attempt %d", i + 1) result = adb_shell_ping(self.ad, PING_DURATION, PING_TARGET) if result: self.ad.log.info("PING SUCCESS") break elif i == 2: self.log.error( "Test Fail: Phone {} can not ping {} with Data Roaming On" .format(self.ad.serial, PING_TARGET)) return False toggle_cell_data_roaming(self.ad, False) time.sleep(TIME_TO_WAIT_BEFORE_PING) if adb_shell_ping(self.ad, PING_DURATION, PING_TARGET): self.log.error( "Test Fail: Phone {} can ping {} with Data Roaming Off". format(self.ad.serial, PING_TARGET)) return False toggle_airplane_mode(self.log, self.ad, True) time.sleep(2) self.bts2.service_state = BtsServiceState.SERVICE_STATE_IN self.bts1.service_state = BtsServiceState.SERVICE_STATE_OUT toggle_airplane_mode(self.log, self.ad, False) toggle_cell_data_roaming(self.ad, True) self.anritsu.wait_for_registration_state(2) # for BTS2 WCDMA time.sleep(TIME_TO_WAIT_BEFORE_PING) for i in range(3): self.ad.log.info("Verify internet connection - attempt %d", i + 1) result = adb_shell_ping(self.ad, PING_DURATION, PING_TARGET) if result: self.ad.log.info("PING SUCCESS") break elif i == 2: self.log.error( "Test Fail: Phone {} can not ping {} with Data Roaming On" .format(self.ad.serial, PING_TARGET)) return False toggle_cell_data_roaming(self.ad, False) time.sleep(TIME_TO_WAIT_BEFORE_PING) if adb_shell_ping(self.ad, PING_DURATION, PING_TARGET): self.log.error( "Test Fail: Phone {} can ping {} with Data Roaming Off". format(self.ad.serial, PING_TARGET)) return False except AnritsuError as e: self.log.error("Error in connection with Anritsu Simulator: " + str(e)) return False except Exception as e: self.log.error("Exception during data roaming: " + str(e)) return False return True
def start_tel_traffic(self, client_host): """ Starts iPerf in the indicated device and initiates traffic. Starts the required iperf clients and servers according to the traffic pattern config in the current test. Args: client_host: device handler in which to start the iperf client. Returns: A list of iperf helpers. """ # The iPerf server is hosted in this computer self.iperf_server_address = scapy.get_if_addr( self.packet_senders[0].interface) self.log.info('Testing IP connectivity with ping.') if not utils.adb_shell_ping( client_host, count=10, dest_ip=self.iperf_server_address): raise RuntimeError('Ping between DUT and host failed.') # Start iPerf traffic iperf_helpers = [] # If the tcp_window_fraction parameter was set, calculate the TCP # window size as a fraction of the peak throughput. ul_tcp_window = None dl_tcp_window = None if self.tcp_window_fraction == 0: self.log.info("tcp_window_fraction was not indicated. " "Disabling fixed TCP window.") else: try: max_dl_tput = self.simulation.maximum_downlink_throughput() max_ul_tput = self.simulation.maximum_uplink_throughput() dl_tcp_window = max_dl_tput / self.tcp_window_fraction ul_tcp_window = max_ul_tput / self.tcp_window_fraction except NotImplementedError: self.log.error("Maximum downlink/uplink throughput method not " "implemented for %s." % type(self.simulation).__name__) if self.traffic_direction in [ self.PARAM_DIRECTION_DL, self.PARAM_DIRECTION_DL_UL ]: # Downlink traffic iperf_helpers.append( self.start_iperf_traffic(client_host, server_idx=len(iperf_helpers), traffic_direction='DL', window=dl_tcp_window, bandwidth=self.bandwidth_limit_dl)) if self.traffic_direction in [ self.PARAM_DIRECTION_UL, self.PARAM_DIRECTION_DL_UL ]: # Uplink traffic iperf_helpers.append( self.start_iperf_traffic(client_host, server_idx=len(iperf_helpers), traffic_direction='UL', window=ul_tcp_window, bandwidth=self.bandwidth_limit_ul)) # Enable TCP logger. if self.tcp_dumps: self.log.info('Enabling TCP logger.') telutils.start_adb_tcpdump(self.dut) return iperf_helpers
def ping(self, dest_ip, count=3, interval=1000, timeout=1000, size=25): return adb_shell_ping(self.device, dest_ip=dest_ip, count=count, timeout=timeout)