def _bring_up_callbox(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)
            if rat == RAT_LTE:
                set_post_sim_params(self.anritsu, self.user_params,
                                    self.ad.sim_card)
            self.anritsu.start_simulation()

            if rat == RAT_LTE:
                preferred_network_setting = NETWORK_MODE_LTE_GSM_WCDMA
                rat_family = RAT_FAMILY_LTE
            else:
                self.log.error("No valid RAT provided to bring up callbox.")
                return False

            if not ensure_preferred_network_type_for_subscription(
                    self.ad, preferred_network_setting):
                self.log.error(
                    "Failed to set rat family {}, preferred network:{}".format(
                        rat_family, preferred_network_setting))
                return False

            if self.ad.droid.connectivityCheckAirplaneMode():
                toggle_airplane_mode(self.log, self.ad, False)
        except AnritsuError as e:
            self.log.error("Error in connection with Anritsu Simulator: " +
                           str(e))
            return False
        return True
    def _send_receive_etws_message(self, set_simulation_func, rat, message_id,
                                   warning_message):
        try:
            [self.bts1] = set_simulation_func(self.anritsu, self.user_params,
                                              self.ad.sim_card)
            set_usim_parameters(self.anritsu, self.ad.sim_card)
            if rat == RAT_LTE:
                set_post_sim_params(self.anritsu, self.user_params,
                                    self.ad.sim_card)
            self.anritsu.start_simulation()

            if rat == RAT_LTE:
                preferred_network_setting = NETWORK_MODE_LTE_GSM_WCDMA
                rat_family = RAT_FAMILY_LTE
            elif rat == RAT_WCDMA:
                self.bts1.wcdma_ctch = CTCHSetup.CTCH_ENABLE
                self.ad.droid.telephonyToggleDataConnection(False)
                preferred_network_setting = NETWORK_MODE_GSM_UMTS
                rat_family = RAT_FAMILY_UMTS
            elif rat == RAT_GSM:
                self.bts1.gsm_cbch = CBCHSetup.CBCH_ENABLE
                self.ad.droid.telephonyToggleDataConnection(False)
                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 ETWS 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()
            if not etws_receive_verify_message_lte_wcdma(
                    self.log, self.ad, self.anritsu,
                    next(TelLabEtwsTest.SERIAL_NO), message_id,
                    warning_message):
                self.log.error(
                    "Phone {} Failed to receive ETWS message".format(
                        self.ad.serial))
                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 ETWS send/receive: " + str(e))
            return False
        return True
コード例 #3
0
    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
コード例 #4
0
    def _setup_emergency_call(self,
                              set_simulation_func,
                              phone_setup_func,
                              phone_idle_func_after_registration=None,
                              is_ims_call=False,
                              is_wait_for_registration=True,
                              csfb_type=None,
                              srlte_csfb=None,
                              srvcc=None,
                              emergency_number=DEFAULT_EMERGENCY_CALL_NUMBER,
                              teardown_side=CALL_TEARDOWN_PHONE,
                              wait_time_in_call=WAIT_TIME_IN_CALL):
        try:
            set_simulation_func(self.anritsu, self.user_params,
                                self.ad.sim_card)
            set_usim_parameters(self.anritsu, self.ad.sim_card)
            if is_ims_call or srvcc or csfb_type:
                set_post_sim_params(self.anritsu, self.user_params,
                                    self.ad.sim_card)
            self.virtualPhoneHandle.auto_answer = (VirtualPhoneAutoAnswer.ON,
                                                   2)
            if csfb_type:
                self.anritsu.csfb_type = csfb_type
            if srlte_csfb == "lte_call_failure":
                self.anritsu.send_command("IMSPSAPAUTOANSWER 1,DISABLE")
                self.anritsu.start_simulation()
                self.anritsu.send_command("IMSSTARTVN 1")
                check_ims_reg = True
                check_ims_calling = True
            elif srlte_csfb == "ims_unregistered":
                self.anritsu.start_simulation()
                self.anritsu.send_command("IMSSTARTVN 1")
                self.anritsu.send_command(
                    "IMSCSCFBEHAVIOR 1,SENDERRORRESPONSE603")
                check_ims_reg = False
                check_ims_calling = False
            elif srlte_csfb == "ps911_unsupported":
                self.anritsu.send_command("EMCBS NOTSUPPORT,BTS1")
                self.anritsu.start_simulation()
                self.anritsu.send_command("IMSSTARTVN 1")
                check_ims_reg = True
                check_ims_calling = False
            elif srlte_csfb == "emc_barred":
                self.anritsu.send_command("ACBARRED USERSPECIFIC,BTS1")
                self.anritsu.send_command("LTEEMERGENCYACBARRED BARRED,BTS1")
                self.anritsu.start_simulation()
                self.anritsu.send_command("IMSSTARTVN 1")
                check_ims_reg = True
                check_ims_calling = False
            elif srvcc == "InCall":
                self.anritsu.start_simulation()
                self.anritsu.send_command("IMSSTARTVN 1")
                self.anritsu.send_command("IMSSTARTVN 2")
                self.anritsu.send_command("IMSSTARTVN 3")
                check_ims_reg = True
                check_ims_calling = True
            else:
                self.anritsu.start_simulation()
            if is_ims_call or csfb_type:
                self.anritsu.send_command("IMSSTARTVN 1")
                self.anritsu.send_command("IMSSTARTVN 2")
                self.anritsu.send_command("IMSSTARTVN 3")

            iterations = 1
            if self.stress_test_number > 0:
                iterations = self.stress_test_number
            successes = 0
            for i in range(1, iterations + 1):
                if self.stress_test_number:
                    self.log.info(
                        "Running iteration {} of {}".format(i, iterations))
                # FIXME: There's no good reason why this must be true;
                # I can only assume this was done to work around a problem
                self.ad.droid.telephonyToggleDataConnection(False)

                # turn off all other BTS to ensure UE registers on BTS1
                sim_model = (self.anritsu.get_simulation_model()).split(",")
                no_of_bts = len(sim_model)
                for i in range(2, no_of_bts + 1):
                    self.anritsu.send_command(
                        "OUTOFSERVICE OUT,BTS{}".format(i))

                if phone_setup_func is not None:
                    if not phone_setup_func(self.ad):
                        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 phone_setup_func(self.ad):
                            self.log.error("phone_setup_func failed.")
                            continue

                if is_wait_for_registration:
                    self.anritsu.wait_for_registration_state()

                if phone_idle_func_after_registration:
                    if not phone_idle_func_after_registration(self.log,
                                                              self.ad):
                        continue

                for i in range(2, no_of_bts + 1):
                    self.anritsu.send_command(
                        "OUTOFSERVICE IN,BTS{}".format(i))

                time.sleep(WAIT_TIME_ANRITSU_REG_AND_CALL)
                if srlte_csfb or srvcc:
                    if not ims_call_cs_teardown(
                            self.log, self.ad, self.anritsu, emergency_number,
                            CALL_TEARDOWN_PHONE, True, check_ims_reg,
                            check_ims_calling, srvcc,
                            WAIT_TIME_IN_CALL_FOR_IMS, WAIT_TIME_IN_CALL):
                        self.log.error(
                            "Phone {} Failed to make emergency call to {}"
                            .format(self.ad.serial, emergency_number))
                        continue
                else:
                    if not call_mo_setup_teardown(
                            self.log, self.ad, self.anritsu, emergency_number,
                            CALL_TEARDOWN_PHONE, True, WAIT_TIME_IN_CALL,
                            is_ims_call):
                        self.log.error(
                            "Phone {} Failed to make emergency call to {}"
                            .format(self.ad.serial, emergency_number))
                        continue
                successes += 1
                if self.stress_test_number:
                    self.log.info("Passed iteration {}".format(i))
            if self.stress_test_number:
                self.log.info("Total of {} successes out of {} attempts".
                              format(successes, iterations))
            return True if successes == iterations else 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 emergency call procedure: " + str(
                e))
            return False
        return True
コード例 #5
0
    def _setup_sms(self,
                   set_simulation_func,
                   phone_setup_func,
                   rat,
                   phone_number,
                   message,
                   mo_mt=DIRECTION_MOBILE_ORIGINATED):
        try:
            [self.bts1] = set_simulation_func(self.anritsu, self.user_params,
                                              self.ad.sim_card)
            set_usim_parameters(self.anritsu, self.ad.sim_card)
            if rat == RAT_LTE:
                set_post_sim_params(self.anritsu, self.user_params,
                                    self.ad.sim_card)
            self.anritsu.start_simulation()
            self.anritsu.send_command("IMSSTARTVN 1")
            self.anritsu.send_command("IMSSTARTVN 2")
            self.anritsu.send_command("IMSSTARTVN 3")

            if rat == RAT_LTE:
                preferred_network_setting = NETWORK_MODE_LTE_GSM_WCDMA
                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 phone_setup_func is not None:
                if not phone_setup_func(self.ad):
                    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 phone_setup_func(self.ad):
                        self.log.error("phone_setup_func failed.")
                        return False

            self.anritsu.wait_for_registration_state()
            time.sleep(self.SETTLING_TIME)
            if mo_mt == DIRECTION_MOBILE_ORIGINATED:
                if not sms_mo_send(self.log, self.ad, self.virtualPhoneHandle,
                                   phone_number, message, rat):
                    self.log.error("Phone {} Failed to send SMS".format(
                        self.ad.serial))
                    return False
            else:
                if not sms_mt_receive_verify(self.log, self.ad,
                                             self.virtualPhoneHandle,
                                             phone_number, message, rat):
                    self.log.error("Phone {} Failed to receive MT SMS".format(
                        self.ad.serial))
                    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 emergency call procedure: " +
                           str(e))
            return False
        return True
コード例 #6
0
    def active_handover(self,
                        set_simulation_func,
                        phone_setup_func,
                        phone_idle_func_after_registration=None,
                        volte=True,
                        iperf=True,
                        all_bands=False,
                        is_wait_for_registration=True,
                        voice_number=DEFAULT_CALL_NUMBER,
                        teardown_side=CALL_TEARDOWN_PHONE,
                        wait_time_in_call=WAIT_TIME_IN_CALL):
        try:
            bts = 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)
            self.anritsu.start_simulation()
            self.anritsu.send_command("IMSSTARTVN 1")
            self.anritsu.send_command("IMSSTARTVN 2")
            self.anritsu.send_command("IMSSTARTVN 3")
            # turn off all other BTS to ensure UE registers on BTS1
            simmodel = self.anritsu.get_simulation_model().split(',')
            no_of_bts = len(simmodel)
            for i in range(2, no_of_bts + 1):
                self.anritsu.send_command("OUTOFSERVICE OUT,BTS{}".format(i))
            if phone_setup_func is not None:
                if not phone_setup_func(self.ad):
                    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 phone_setup_func(self.ad):
                        self.log.error("phone_setup_func failed.")
            if is_wait_for_registration:
                self.anritsu.wait_for_registration_state()
            if phone_idle_func_after_registration:
                if not phone_idle_func_after_registration(self.log, self.ad):
                    self.log.error("phone_idle_func failed.")
            for i in range(2, no_of_bts + 1):
                self.anritsu.send_command("OUTOFSERVICE IN,BTS{}".format(i))
            time.sleep(WAIT_TIME_ANRITSU_REG_AND_CALL)
            if iperf:  # setup iPerf server
                server_ip = self.iperf_setup()
                if not server_ip:
                    self.log.error("iperf server can not be reached by ping")
                    return False
            if volte:  # make a VoLTE MO call
                if not make_ims_call(self.log, self.ad, self.anritsu,
                                     voice_number):
                    self.log.error(
                        "Phone {} Failed to make volte call to {}".format(
                            self.ad.serial, voice_number))
                    return False
            if all_bands and (simmodel[1] == "WCDMA"):
                band = []
                for rat in simmodel[:2]:
                    band.append(self.anritsu.get_supported_bands(rat))
                self.log.info("UE reported LTE bands are {}".format(band[0]))
                self.log.info("UE reported WCDMA bands are {}".format(band[1]))
                current_lte_band = bts[0].band
                # move current LTE band to the last in the list
                band[0].remove(current_lte_band)
                band[0].append(current_lte_band)
                n = max(len(band[0]), len(band[1]))
            else:
                n = 1  # n is the number of LTE->WCDMA->LTE handovers

            for i in range(n):
                if all_bands:
                    bts[1].band = band[1][i % len(band[1])]
                if not iperf:  # VoLTE only
                    result = handover_tc(self.log, self.anritsu,
                                         WAITTIME_BEFORE_HANDOVER,
                                         BtsNumber.BTS1, BtsNumber.BTS2)
                    time.sleep(WAITTIME_AFTER_HANDOVER)
                else:  # with iPerf
                    iperf_task = (self._iperf_task,
                                  (server_ip, WAITTIME_BEFORE_HANDOVER +
                                   WAITTIME_AFTER_HANDOVER - 10))
                    ho_task = (handover_tc, (self.log, self.anritsu,
                                             WAITTIME_BEFORE_HANDOVER,
                                             BtsNumber.BTS1, BtsNumber.BTS2))
                    result = run_multithread_func(self.log,
                                                  [ho_task, iperf_task])
                    if not result[1]:
                        self.log.error("iPerf failed.")
                        return False

                self.log.info("handover test case result code {}.".format(
                    result[0]))
                if volte:
                    # check if the phone stay in call
                    if not self.ad.droid.telecomIsInCall():
                        self.log.error("Call is already ended in the phone.")
                        return False

                    if not tear_down_call(self.log, self.ad, self.anritsu):
                        self.log.error("Phone {} Failed to tear down".format(
                            self.ad.serial, voice_number))
                        return False
                if simmodel[1] == "WCDMA" and iperf:
                    if all_bands:
                        bts[0].band = band[0][i % len(band[0])]
                    iperf_task = (self._iperf_task,
                                  (server_ip, WAITTIME_BEFORE_HANDOVER +
                                   WAITTIME_AFTER_HANDOVER - 10))
                    ho_task = (handover_tc, (self.log, self.anritsu,
                                             WAITTIME_BEFORE_HANDOVER,
                                             BtsNumber.BTS2, BtsNumber.BTS1))
                    result = run_multithread_func(self.log,
                                                  [ho_task, iperf_task])
                    if not result[1]:
                        self.log.error("iPerf failed.")
                        return False
                    self.log.info("handover test case result code {}.".format(
                        result[0]))

        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 voice call procedure: " + str(e))
            return False
        return True
    def _send_receive_cmas_message(
            self,
            set_simulation_func,
            rat,
            message_id,
            warning_message,
            c2k_response_type=CMAS_C2K_RESPONSETYPE_SHELTER,
            c2k_severity=CMAS_C2K_SEVERITY_EXTREME,
            c2k_urgency=CMAS_C2K_URGENCY_IMMEDIATE,
            c2k_certainty=CMAS_C2K_CERTIANTY_OBSERVED):
        try:
            [self.bts1] = set_simulation_func(self.anritsu, self.user_params,
                                              self.ad.sim_card)
            set_usim_parameters(self.anritsu, self.ad.sim_card)
            if rat == RAT_LTE:
                set_post_sim_params(self.anritsu, self.user_params,
                                    self.ad.sim_card)
            self.anritsu.start_simulation()

            if rat == RAT_LTE:
                preferred_network_setting = NETWORK_MODE_LTE_GSM_WCDMA
                rat_family = RAT_FAMILY_LTE
            elif rat == RAT_WCDMA:
                self.bts1.wcdma_ctch = CTCHSetup.CTCH_ENABLE
                self.ad.droid.telephonyToggleDataConnection(False)
                preferred_network_setting = NETWORK_MODE_GSM_UMTS
                rat_family = RAT_FAMILY_UMTS
            elif rat == RAT_GSM:
                self.bts1.gsm_cbch = CBCHSetup.CBCH_ENABLE
                self.ad.droid.telephonyToggleDataConnection(False)
                preferred_network_setting = NETWORK_MODE_GSM_ONLY
                rat_family = RAT_FAMILY_GSM
            elif rat == RAT_1XRTT:
                self.ad.droid.telephonyToggleDataConnection(False)
                preferred_network_setting = NETWORK_MODE_CDMA
                rat_family = RAT_FAMILY_CDMA2000
            else:
                self.log.error("No valid RAT provided for CMAS 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()
            if rat != RAT_1XRTT:
                if not cmas_receive_verify_message_lte_wcdma(
                        self.log, self.ad, self.anritsu,
                        next(TelLabCmasTest.SERIAL_NO), message_id,
                        warning_message):
                    self.log.warning(
                        "Phone {} Failed to receive CMAS message".format(
                            self.ad.serial))
                    # Another check of logcat before confirming failure
                    if self.ad.search_logcat(warning_message):
                        self.ad.log.info(
                            "Confirmed from Logcat - User received %s",
                            warning_message)
                        return True
                    return False
            else:
                if not cmas_receive_verify_message_cdma1x(
                        self.log, self.ad, self.anritsu,
                        next(TelLabCmasTest.SERIAL_NO), message_id,
                        warning_message, c2k_response_type, c2k_severity,
                        c2k_urgency, c2k_certainty):
                    self.log.warning(
                        "Phone {} Failed to receive CMAS message".format(
                            self.ad.serial))
                    if self.ad.search_logcat(warning_message):
                        self.ad.log.info(
                            "Confirmed from Logcat - User received %s",
                            warning_message)
                        return True
                    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 CMAS send/receive: " + 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 _data_stall_detection_recovery(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)

            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 Data Stall 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)

            self.bts1.output_level = self.start_power_level

            cmd = ('ss -l -p -n | grep "tcp.*droid_script" | tr -s " " '
                   '| cut -d " " -f 5 | sed s/.*://g')
            sl4a_port = self.ad.adb.shell(cmd)

            if not test_data_browsing_success_using_sl4a(self.log, self.ad):
                self.ad.log.error("Browsing failed before the test, aborting!")
                return False

            begin_time = get_device_epoch_time(self.ad)
            break_internet_except_sl4a_port(self.ad, sl4a_port)

            if not test_data_browsing_failure_using_sl4a(self.log, self.ad):
                self.ad.log.error("Browsing success even after breaking " \
                                  "the internet, aborting!")
                return False

            if not check_data_stall_detection(self.ad):
                self.ad.log.error("NetworkMonitor unable to detect Data Stall")

            if not check_network_validation_fail(self.ad, begin_time):
                self.ad.log.error("Unable to detect NW validation fail")
                return False

            if not check_data_stall_recovery(self.ad, begin_time):
                self.ad.log.error("Recovery was not triggerred")
                return False

            resume_internet_with_sl4a_port(self.ad, sl4a_port)

            if not test_data_browsing_success_using_sl4a(self.log, self.ad):
                self.ad.log.error("Browsing failed after resuming internet")
                return False

            self.ad.log.info("Triggering Out of Service Sceanrio")
            self.bts1.output_level = POWER_LEVEL_OUT_OF_SERVICE
            time.sleep(30)
            begin_time = get_device_epoch_time(self.ad)

            if not test_data_browsing_failure_using_sl4a(self.log, self.ad):
                self.ad.log.error("Browsing success even in OOS, aborting!")
                return False

            if not check_network_validation_fail(self.ad, begin_time):
                self.ad.log.error("Unable to detect NW validation fail")
                return False

            if check_data_stall_recovery(self.ad, begin_time):
                self.ad.log.error("FAILURE - Data Recovery was performed")
                return False
            self.ad.log.info("SUCCESS - Data Recovery was not performed")

            self.ad.log.info("Bringing up Strong Cellular Signal")
            self.bts1.output_level = POWER_LEVEL_FULL_SERVICE
            time.sleep(30)

            if not test_data_browsing_success_using_sl4a(self.log, self.ad):
                self.ad.log.error("Browsing failed after full service")
                return False
            return True

        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
        finally:
            resume_internet_with_sl4a_port(self.ad, sl4a_port)