1#/usr/bin/env python3.4
2#
3#   Copyright 2016 - The Android Open Source Project
4#
5#   Licensed under the Apache License, Version 2.0 (the "License");
6#   you may not use this file except in compliance with the License.
7#   You may obtain a copy of the License at
8#
9#       http://www.apache.org/licenses/LICENSE-2.0
10#
11#   Unless required by applicable law or agreed to in writing, software
12#   distributed under the License is distributed on an "AS IS" BASIS,
13#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14#   See the License for the specific language governing permissions and
15#   limitations under the License.
16"""
17    Test Script for Telephony Pre Check In Sanity
18"""
19
20import math
21import time
22from acts.test_decorators import test_tracker_info
23from acts.controllers.anritsu_lib._anritsu_utils import AnritsuError
24from acts.controllers.anritsu_lib.md8475a import CTCHSetup
25from acts.controllers.anritsu_lib.md8475a import BtsBandwidth
26from acts.controllers.anritsu_lib.md8475a import BtsPacketRate
27from acts.controllers.anritsu_lib.md8475a import BtsServiceState
28from acts.controllers.anritsu_lib.md8475a import MD8475A
29from acts.controllers.anritsu_lib.mg3710a import MG3710A
30from acts.test_utils.tel.anritsu_utils import LTE_BAND_2
31from acts.test_utils.tel.anritsu_utils import set_system_model_gsm
32from acts.test_utils.tel.anritsu_utils import set_system_model_lte
33from acts.test_utils.tel.anritsu_utils import set_system_model_lte_lte
34from acts.test_utils.tel.anritsu_utils import set_system_model_lte_wcdma
35from acts.test_utils.tel.anritsu_utils import set_system_model_wcdma
36from acts.test_utils.tel.anritsu_utils import set_system_model_wcdma_gsm
37from acts.test_utils.tel.anritsu_utils import set_system_model_wcdma_wcdma
38from acts.test_utils.tel.anritsu_utils import set_usim_parameters
39from acts.test_utils.tel.tel_defines import NETWORK_MODE_CDMA
40from acts.test_utils.tel.tel_defines import NETWORK_MODE_GSM_ONLY
41from acts.test_utils.tel.tel_defines import NETWORK_MODE_GSM_UMTS
42from acts.test_utils.tel.tel_defines import NETWORK_MODE_LTE_GSM_WCDMA
43from acts.test_utils.tel.tel_defines import RAT_FAMILY_CDMA2000
44from acts.test_utils.tel.tel_defines import RAT_FAMILY_GSM
45from acts.test_utils.tel.tel_defines import RAT_FAMILY_LTE
46from acts.test_utils.tel.tel_defines import RAT_FAMILY_UMTS
47from acts.test_utils.tel.tel_test_utils import ensure_network_rat
48from acts.test_utils.tel.tel_test_utils import ensure_phones_idle
49from acts.test_utils.tel.tel_test_utils import toggle_airplane_mode
50from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
51from acts.controllers.anritsu_lib.cell_configurations import \
52    gsm_band850_ch128_fr869_cid58_cell
53from acts.controllers.anritsu_lib.cell_configurations import \
54    gsm_band850_ch251_fr893_cid59_cell
55from acts.controllers.anritsu_lib.cell_configurations import \
56    gsm_band1900_ch512_fr1930_cid51_cell
57from acts.controllers.anritsu_lib.cell_configurations import \
58    gsm_band1900_ch512_fr1930_cid52_cell
59from acts.controllers.anritsu_lib.cell_configurations import \
60    gsm_band1900_ch512_fr1930_cid53_cell
61from acts.controllers.anritsu_lib.cell_configurations import \
62    gsm_band1900_ch512_fr1930_cid54_cell
63from acts.controllers.anritsu_lib.cell_configurations import \
64    gsm_band1900_ch640_fr1955_cid56_cell
65from acts.controllers.anritsu_lib.cell_configurations import \
66    gsm_band1900_ch750_fr1977_cid57_cell
67from acts.controllers.anritsu_lib.cell_configurations import \
68    lte_band2_ch900_fr1960_pcid9_cell
69from acts.controllers.anritsu_lib.cell_configurations import \
70    lte_band4_ch2000_fr2115_pcid1_cell
71from acts.controllers.anritsu_lib.cell_configurations import \
72    lte_band4_ch2000_fr2115_pcid2_cell
73from acts.controllers.anritsu_lib.cell_configurations import \
74    lte_band4_ch2000_fr2115_pcid3_cell
75from acts.controllers.anritsu_lib.cell_configurations import \
76    lte_band4_ch2000_fr2115_pcid4_cell
77from acts.controllers.anritsu_lib.cell_configurations import \
78    lte_band4_ch2050_fr2120_pcid7_cell
79from acts.controllers.anritsu_lib.cell_configurations import \
80    lte_band4_ch2050_fr2120_pcid7_cell
81from acts.controllers.anritsu_lib.cell_configurations import \
82    lte_band4_ch2250_fr2140_pcid8_cell
83from acts.controllers.anritsu_lib.cell_configurations import \
84    lte_band12_ch5095_fr737_pcid10_cell
85from acts.controllers.anritsu_lib.cell_configurations import \
86    wcdma_band1_ch10700_fr2140_cid31_cell
87from acts.controllers.anritsu_lib.cell_configurations import \
88    wcdma_band1_ch10700_fr2140_cid32_cell
89from acts.controllers.anritsu_lib.cell_configurations import \
90    wcdma_band1_ch10700_fr2140_cid33_cell
91from acts.controllers.anritsu_lib.cell_configurations import \
92    wcdma_band1_ch10700_fr2140_cid34_cell
93from acts.controllers.anritsu_lib.cell_configurations import \
94    wcdma_band1_ch10575_fr2115_cid36_cell
95from acts.controllers.anritsu_lib.cell_configurations import \
96    wcdma_band1_ch10800_fr2160_cid37_cell
97from acts.controllers.anritsu_lib.cell_configurations import \
98    wcdma_band2_ch9800_fr1960_cid38_cell
99from acts.controllers.anritsu_lib.cell_configurations import \
100    wcdma_band2_ch9900_fr1980_cid39_cell
101
102
103class TelLabNeighborCellTest(TelephonyBaseTest):
104
105    # This is the default offset between CallBox Power Level and Phone measure
106    # Power Level.
107    # TODO: Probably need to further tune those values.
108    _LTE_RSSI_OFFSET = -39
109    _WCDMA_RSSI_OFFSET = -31
110    _GSM_RSSI_OFFSET = -30
111
112    _ANRITSU_SETTLING_TIME = 15
113    _SETTLING_TIME = 75
114    _LTE_MCS_DL = 5
115    _LTE_MCS_UL = 5
116    _NRB_DL = 50
117    _NRB_UL = 50
118    _CELL_PARAM_FILE = 'C:\\MX847570\\CellParam\\NEIGHBOR_CELL_TEST_TMO.wnscp'
119
120    # Below are keys should be included in expected cell info.
121    # TARGET_RSSI: This is expected RSSI.
122    TARGET_RSSI = 'target_rssi'
123    # MAX_ERROR_RSSI: This is max error between 'each sample of reported RSSI'
124    # and 'expected RSSI'
125    MAX_ERROR_RSSI = 'max_error_rssi'
126    # MAX_ERROR_AVERAGE_RSSI: This is max error between
127    # 'average value of reported RSSI' and 'expected RSSI'
128    MAX_ERROR_AVERAGE_RSSI = 'max_error_average_rssi'
129    # REPORT_RATE: expected report rate for neighbor cell.
130    REPORT_RATE = 'report_rate'
131    # RAT: expected network rat.
132    RAT = 'rat'
133    # IS_REGISTERED: is the cell registered.
134    # For serving cell, this value should be True; for neighbor cell, should be
135    # False
136    IS_REGISTERED = 'registered'
137    # CID: cell CID info.
138    CID = 'cid'
139    # PCID: cell PCID info.
140    PCID = 'pcid'
141    # PSC: cell PSC info.
142    PSC = 'psc'
143
144    # Keys for calculate average RSSI. Only used in _verify_cell_info
145    RSSI = 'rssi'
146    COUNT = 'count'
147
148    # Pre-defined invalid value. If this value is reported in cell info, just
149    # discard this value. E.g. if in reported cell info, cid is reported as
150    # 0x7fffffff, need to discard this value when calculating unique_id
151    INVALID_VALUE = 0x7fffffff
152
153    def __init__(self, controllers):
154        TelephonyBaseTest.__init__(self, controllers)
155        self.ad = self.android_devices[0]
156        self.ad.sim_card = getattr(self.ad, "sim_card", None)
157        self.md8475a_ip_address = self.user_params[
158            "anritsu_md8475a_ip_address"]
159        self.mg3710a_ip_address = self.user_params[
160            "anritsu_mg3710a_ip_address"]
161        self.wlan_option = self.user_params.get("anritsu_wlan_option", False)
162
163        if "lte_rssi_offset" in self.user_params:
164            self._LTE_RSSI_OFFSET = int(self.user_params["lte_rssi_offset"])
165        if "wcdma_rssi_offset" in self.user_params:
166            self._WCDMA_RSSI_OFFSET = int(self.user_params[
167                "wcdma_rssi_offset"])
168        if "gsm_rssi_offset" in self.user_params:
169            self._GSM_RSSI_OFFSET = int(self.user_params["gsm_rssi_offset"])
170
171    def setup_class(self):
172        self.md8475a = None
173        self.mg3710a = None
174        try:
175            self.md8475a = MD8475A(self.md8475a_ip_address, self.log)
176        except AnritsuError as e:
177            self.log.error("Error in connecting to Anritsu MD8475A:{}".format(
178                e))
179            return False
180
181        try:
182            self.mg3710a = MG3710A(self.mg3710a_ip_address, self.log)
183        except AnritsuError as e:
184            self.log.error("Error in connecting to Anritsu MG3710A :{}".format(
185                e))
186            return False
187        return True
188
189    def setup_test(self):
190        self.turn_off_3710a_sg(1)
191        self.turn_off_3710a_sg(2)
192        self.mg3710a.set_arb_pattern_aorb_state("A", "OFF", 1)
193        self.mg3710a.set_arb_pattern_aorb_state("B", "OFF", 1)
194        self.mg3710a.set_arb_pattern_aorb_state("A", "OFF", 2)
195        self.mg3710a.set_arb_pattern_aorb_state("B", "OFF", 2)
196        self.mg3710a.set_freq_relative_display_status("OFF", 1)
197        self.mg3710a.set_freq_relative_display_status("OFF", 2)
198        self.ad.droid.telephonySetPreferredNetworkTypes(
199            NETWORK_MODE_LTE_GSM_WCDMA)
200        ensure_phones_idle(self.log, self.android_devices)
201        toggle_airplane_mode(self.log, self.ad, True)
202        self.ad.droid.telephonyToggleDataConnection(True)
203        self.ad.adb.shell("setprop net.lte.ims.volte.provisioned 1",
204                          ignore_status=True)
205        return True
206
207    def teardown_test(self):
208        toggle_airplane_mode(self.log, self.ad, True)
209        self.turn_off_3710a_sg(1)
210        self.turn_off_3710a_sg(2)
211        self.log.info("Stopping Simulation")
212        self.md8475a.stop_simulation()
213        return True
214
215    def teardown_class(self):
216        if self.md8475a is not None:
217            self.md8475a.disconnect()
218        if self.mg3710a is not None:
219            self.mg3710a.disconnect()
220        return True
221
222    def _setup_lte_serving_cell(self, bts, dl_power, cell_id, physical_cellid):
223        bts.output_level = dl_power
224        bts.bandwidth = BtsBandwidth.LTE_BANDWIDTH_10MHz
225        bts.packet_rate = BtsPacketRate.LTE_MANUAL
226        bts.lte_mcs_dl = self._LTE_MCS_DL
227        bts.lte_mcs_ul = self._LTE_MCS_UL
228        bts.nrb_dl = self._NRB_DL
229        bts.nrb_ul = self._NRB_UL
230        bts.cell_id = cell_id
231        bts.physical_cellid = physical_cellid
232        bts.neighbor_cell_mode = "DEFAULT"
233
234    def _setup_lte_neighbhor_cell_md8475a(self, bts, band, dl_power, cell_id,
235                                          physical_cellid):
236        bts.output_level = dl_power
237        bts.band = band
238        bts.bandwidth = BtsBandwidth.LTE_BANDWIDTH_10MHz
239        bts.cell_id = cell_id
240        bts.physical_cellid = physical_cellid
241        bts.neighbor_cell_mode = "DEFAULT"
242        bts.packet_rate = BtsPacketRate.LTE_MANUAL
243        bts.lte_mcs_dl = self._LTE_MCS_DL
244        bts.lte_mcs_ul = self._LTE_MCS_UL
245        bts.nrb_dl = self._NRB_DL
246        bts.nrb_ul = self._NRB_UL
247
248    def _setup_wcdma_serving_cell(self, bts, dl_power, cell_id):
249        bts.output_level = dl_power
250        bts.cell_id = cell_id
251        bts.neighbor_cell_mode = "DEFAULT"
252
253    def _setup_wcdma_neighbhor_cell_md8475a(self, bts, band, dl_power,
254                                            cell_id):
255        bts.output_level = dl_power
256        bts.band = band
257        bts.cell_id = cell_id
258        bts.neighbor_cell_mode = "DEFAULT"
259
260    def _setup_lte_cell_md8475a(self, bts, params, dl_power):
261        bts.output_level = dl_power
262        bts.band = params['band']
263        bts.bandwidth = params['bandwidth']
264        bts.cell_id = params['cid']
265        bts.physical_cellid = params['pcid']
266        bts.mcc = params['mcc']
267        bts.mnc = params['mnc']
268        bts.tac = params['tac']
269        bts.neighbor_cell_mode = "DEFAULT"
270        bts.dl_channel = params['channel']
271        bts.packet_rate = BtsPacketRate.LTE_MANUAL
272        bts.lte_mcs_dl = self._LTE_MCS_DL
273        bts.lte_mcs_ul = self._LTE_MCS_UL
274        bts.nrb_dl = self._NRB_DL
275        bts.nrb_ul = self._NRB_UL
276
277    def _setup_wcdma_cell_md8475a(self, bts, params, dl_power):
278        bts.output_level = dl_power
279        bts.band = params['band']
280        bts.cell_id = params['cid']
281        bts.mcc = params['mcc']
282        bts.mnc = params['mnc']
283        bts.lac = params['lac']
284        bts.rac = params['rac']
285        bts.neighbor_cell_mode = "DEFAULT"
286        bts.primary_scrambling_code = params['psc']
287        bts.dl_channel = params['channel']
288
289    def _setup_gsm_cell_md8475a(self, bts, params, dl_power):
290        bts.output_level = params['power']
291        bts.band = params['band']
292        bts.cell_id = params['cid']
293        bts.mcc = params['mcc']
294        bts.mnc = params['mnc']
295        bts.lac = params['lac']
296        bts.rac = params['rac']
297        bts.neighbor_cell_mode = "DEFAULT"
298
299    def setup_3710a_waveform(self, sg_number, memory, frequency, power_level,
300                             wave_package_name, wave_pattern_name):
301        self.mg3710a.set_frequency(frequency, sg_number)
302        self.mg3710a.set_arb_state("ON", sg_number)
303        self.mg3710a.set_arb_combination_mode("EDIT", sg_number)
304        self.mg3710a.select_waveform(wave_package_name, wave_pattern_name,
305                                     memory, sg_number)
306        self.mg3710a.set_arb_pattern_aorb_state(memory, "ON", sg_number)
307        self.mg3710a.set_arb_level_aorb(memory, power_level, sg_number)
308
309    def turn_on_3710a_sg(self, sg_number):
310        self.mg3710a.set_modulation_state("ON", sg_number)
311        self.mg3710a.set_rf_output_state("ON", sg_number)
312
313    def turn_off_3710a_sg(self, sg_number):
314        self.mg3710a.set_modulation_state("OFF", sg_number)
315        self.mg3710a.set_rf_output_state("OFF", sg_number)
316
317    def _is_matching_cell(self, expected_cell_info, input_cell_info):
318        """Return if 'input_cell_info' matches 'expected_cell_info'.
319
320        Args:
321            expected_cell_info: expected cell info. (dictionary)
322            input_cell_info: input cell info to test. (dictionary)
323
324        Returns:
325            True if:
326                for each key in key_list, if key exist in expected_cell_info,
327                it should also exist in input_cell_info, and the values should
328                equal in expected_cell_info and input_cell_info
329            False otherwise.
330        """
331        for key in [
332                self.CID, self.PCID, self.RAT, self.PSC, self.IS_REGISTERED
333        ]:
334            if key in expected_cell_info:
335                if key not in input_cell_info:
336                    return False
337                if input_cell_info[key] != expected_cell_info[key]:
338                    return False
339        return True
340
341    def _unique_cell_id(self, input_cell_info):
342        """Get the unique id for cell_info, based on cid, pcid, rat, psc and
343        is_registered.
344
345        Args:
346            input_cell_info: cell info to get unique id.
347
348        Returns:
349            unique id (string)
350        """
351        unique_id = ""
352        for key in [
353                self.CID, self.PCID, self.RAT, self.PSC, self.IS_REGISTERED
354        ]:
355            if key in input_cell_info:
356                if input_cell_info[key] != self.INVALID_VALUE:
357                    unique_id += key + ":" + str(input_cell_info[key]) + ":"
358        return unique_id
359
360    def _get_rssi_from_cell_info(self, cell_info):
361        """Return the RSSI value reported in cell_info.
362
363        Args:
364            cell_info: cell info to get RSSI.
365
366        Returns:
367            RSSI reported in this cell info.
368        """
369        rat_to_rssi_tbl = {
370            'lte': 'rsrp',
371            'wcdma': 'signal_strength',
372            'gsm': 'signal_strength'
373        }
374        try:
375            return cell_info[rat_to_rssi_tbl[cell_info[self.RAT]]]
376        except KeyError:
377            return None
378
379    def _is_rssi_in_expected_range(self, actual_rssi, expected_rssi,
380                                   max_error):
381        """Return if actual_rssi is within expected range.
382
383        Args:
384            actual_rssi: the rssi value to test.
385            expected_rssi: expected rssi value.
386            max_error: max error.
387
388        Returns:
389            if the difference between actual_rssi and expected_rssi is within
390            max_error, return True. Otherwise False.
391        """
392        if abs(actual_rssi - expected_rssi) > max_error:
393            self.log.error(
394                "Expected RSSI: {}, max error: {}, reported RSSI: {}".format(
395                    expected_rssi, max_error, actual_rssi))
396            return False
397        else:
398            return True
399
400    def _verify_cell_info(self,
401                          ad,
402                          expected_cell_info_stats,
403                          number_of_sample=10,
404                          delay_each_sample=5):
405        """Return if reported cell info from ad matches expected_cell_info_stats
406        or not.
407
408        Args:
409            ad: android device object.
410            expected_cell_info_stats: expected cell info list.
411            number_of_sample: number of sample to take from DUT.
412            delay_each_sample: time delay between each sample.
413
414        Returns:
415            True if reported cell info matches with expected_cell_info_stats.
416            False otherwise.
417
418        """
419
420        cell_info_stats = {}
421
422        for index in range(number_of_sample):
423            info_list = ad.droid.telephonyGetAllCellInfo()
424
425            self.log.info("Received Cell Info List: {}".format(info_list))
426
427            for sample in info_list:
428                rssi = self._get_rssi_from_cell_info(sample)
429                unique_id = self._unique_cell_id(sample)
430
431                # check cell logic
432                if not unique_id in expected_cell_info_stats:
433                    self.log.error("Found unexpected cell!")
434                    return False
435                elif not self._is_matching_cell(
436                        expected_cell_info_stats[unique_id], sample):
437                    self.log.error("Mismatched Cell Info")
438                    return False
439
440                # Check RSSI within expected range
441                if not self._is_rssi_in_expected_range(
442                        self._get_rssi_from_cell_info(sample),
443                        expected_cell_info_stats[unique_id][self.TARGET_RSSI],
444                        expected_cell_info_stats[unique_id][
445                            self.MAX_ERROR_RSSI]):
446                    self.log.error("Cell Info: {}. Cell RSSI not" +
447                                   " in expected range".format(sample))
448                    return False
449                if unique_id not in cell_info_stats:
450                    cell_info_stats[unique_id] = {self.RSSI: 0, self.COUNT: 0}
451                cell_info_stats[unique_id][self.RSSI] += rssi
452                cell_info_stats[unique_id][self.COUNT] += 1
453
454            time.sleep(delay_each_sample)
455
456        try:
457            for unique_id in expected_cell_info_stats.keys():
458                expected_cell_info = expected_cell_info_stats[unique_id]
459
460                expected_number_of_sample_reported = math.floor(
461                    expected_cell_info[self.REPORT_RATE] * number_of_sample)
462
463                if cell_info_stats[unique_id][
464                        self.COUNT] < expected_number_of_sample_reported:
465                    self.log.error(
466                        "Insufficient reports {}/{} for {}, expected: {}",
467                        expected_cell_info[unique_id][self.COUNT],
468                        number_of_sample, expected_cell_info,
469                        expected_number_of_sample_reported)
470                    return False
471
472                average_rssi = cell_info_stats[unique_id][self.RSSI] / \
473                               cell_info_stats[unique_id][self.COUNT]
474
475                # Check Average RSSI within expected range
476                if not self._is_rssi_in_expected_range(
477                        average_rssi, expected_cell_info[self.TARGET_RSSI],
478                        expected_cell_info[self.MAX_ERROR_AVERAGE_RSSI]):
479                    self.log.error("Cell Average RSSI not in expected range.")
480                    return False
481        except KeyError as unique_id:
482            self.log.error("Failed to find key {}".format(unique_id))
483            self.log.error("Expected cell info not reported {}.".format(
484                expected_cell_info))
485            return False
486
487        return True
488
489    def lte_intra_freq_ncell(self,
490                             ad,
491                             pcid_list,
492                             init_pwr,
493                             power_seq,
494                             interval=3,
495                             err_margin=1):
496        """Return True if UE measured RSSI follows the powers in BTS simulator
497
498        Args:
499            ad: android device object.
500            pcid: list of PCID of LTE BTS
501            init_pwr: initial downlinl power in dBm for serving and neighbor cell
502            power_seq: power change sequence in dB.
503            interval: time delay in seocnd between each power change.
504            error_margin: error margin in dB to determine measurement pass or fail
505
506        Returns:
507            True if all measurments are within margin.
508            False otherwise.
509
510        """
511        bts = set_system_model_lte_lte(self.md8475a, self.user_params,
512                                       self.ad.sim_card)
513
514        self._setup_lte_serving_cell(bts[0], init_pwr, pcid_list[0],
515                                     pcid_list[0])
516        self._setup_lte_neighbhor_cell_md8475a(bts[1], LTE_BAND_2, init_pwr,
517                                               pcid_list[1], pcid_list[1])
518        set_usim_parameters(self.md8475a, self.ad.sim_card)
519        self.md8475a.send_command("IMSSTARTVN 1")
520        self.md8475a.start_simulation()
521        bts[1].service_state = BtsServiceState.SERVICE_STATE_OUT
522        self.ad.droid.telephonyToggleDataConnection(True)
523        if not ensure_network_rat(
524                self.log,
525                self.ad,
526                NETWORK_MODE_LTE_GSM_WCDMA,
527                RAT_FAMILY_LTE,
528                toggle_apm_after_setting=True):
529            self.log.error("Failed to set rat family {}, preferred network:{}".
530                           format(RAT_FAMILY_LTE, NETWORK_MODE_LTE_GSM_WCDMA))
531            return False
532        self.md8475a.wait_for_registration_state()
533        time.sleep(1)
534        bts[1].service_state = BtsServiceState.SERVICE_STATE_IN
535
536        n_bts = len(pcid_list)  # number of total BTS
537        if n_bts >= 3:
538            self.setup_3710a_waveform("1", "A", "1960MHZ", init_pwr, "LTE",
539                                      "10M_B1_CID2")
540            self.turn_on_3710a_sg(1)
541        if n_bts == 4:
542            self.setup_3710a_waveform("1", "B", "1960MHZ", init_pwr, "LTE",
543                                      "10M_B1_CID3")
544        self.log.info("Wait for {} seconds to settle".format(
545            self._ANRITSU_SETTLING_TIME))
546        time.sleep(self._ANRITSU_SETTLING_TIME)
547        cell_list = ad.droid.telephonyGetAllCellInfo()
548        self.log.info("Received Cell Info List: {}".format(cell_list))
549        init_rsrp_list = []
550        for pcid in pcid_list:
551            for cell in cell_list:
552                if cell['pcid'] == pcid:
553                    init_rsrp_list.append(cell['rsrp'])
554                    break
555        self.log.info("init_rsrp_list = {}".format(init_rsrp_list))
556        error_seq = []
557        for power in power_seq:
558            self.log.info("power = {}".format(power))
559            for i in range(2):
560                bts[i].output_level = init_pwr + power[i]
561            if n_bts >= 3:
562                self.mg3710a.set_arb_level_aorb("A", init_pwr + power[2], "1")
563            if n_bts == 4:
564                self.mg3710a.set_arb_level_aorb("B", init_pwr + power[2], "1")
565            time.sleep(interval)
566            cell_list = ad.droid.telephonyGetAllCellInfo()
567            delta = []
568            error = []
569            for pcid, init_rsrp, pwr in zip(pcid_list, init_rsrp_list, power):
570                found = False
571                for cell in cell_list:
572                    if cell['pcid'] == pcid:
573                        found = True
574                        self.log.info("pcid {}, rsrp = {}".format(pcid, cell[
575                            'rsrp']))
576                        delta.append(cell['rsrp'] - init_rsrp)
577                        error.append(cell['rsrp'] - init_rsrp - pwr)
578                if not found:
579                    self.log.info("pcid {} not found!".format(pcid))
580                    delta.append(-99)
581                    error.append(-99)
582            self.log.info("delta = {}".format(delta))
583            self.log.info("error = {}".format(error))
584            error_seq.append(error)
585        self.log.info("error_seq = {}".format(error_seq))
586        for error in error_seq:
587            for err in error:
588                if err != -99 and abs(err) > err_margin:
589                    self.log.error(
590                        "Test failed! Measured power error is greater than margin."
591                    )
592                    return False
593        return True
594
595    """ Tests Begin """
596
597    @test_tracker_info(uuid="17a42861-abb5-480b-9139-89219fa304b2")
598    @TelephonyBaseTest.tel_test_wrap
599    def test_2lte_intra_freq_ncell_away_close(self):
600        """ Test phone moving away from Neighbor Intra Freq cell then
601        close back while serving cell stays the same power
602
603        Setup a two LTE cell configuration on MD8475A
604        Make Sure Phone is in LTE mode
605        Verify the reported RSSI follows the DL power change in MD8475A
606
607        Returns:
608            True if pass; False if fail
609        """
610        pcid = [0, 1]
611        init_pwr = -30  # initial DL power for all cells
612        power_seq = [
613            [0, -1],  # power change sequence reference to init_pwr
614            [0, -2],
615            [0, -3],
616            [0, -4],
617            [0, -3],
618            [0, -2],
619            [0, -1],
620            [0, 0],
621            [0, 1],
622            [0, 3],
623            [0, 4],
624            [0, 5],
625            [0, 6],
626            [0, 7],
627            [0, 8],
628            [0, 9],
629            [0, 10],
630            [0, 9],
631            [0, 8],
632            [0, 7],
633            [0, 6],
634            [0, 5],
635            [0, 4],
636            [0, 3],
637            [0, 2],
638            [0, 1],
639            [0, 0]
640        ]
641
642        return self.lte_intra_freq_ncell(self.ad, pcid, init_pwr, power_seq)
643
644    @test_tracker_info(uuid="117f404b-fb78-474a-86ba-209e6a54c9a8")
645    @TelephonyBaseTest.tel_test_wrap
646    def test_2lte_intra_freq_scell_away_close(self):
647        """ Test phone moving away from serving cell then close back while
648        neighbor Intra Freq cell stays the same power
649
650        Setup a two LTE cell configuration on MD8475A
651        Make Sure Phone is in LTE mode
652        Verify the reported RSSI follows the DL power change in MD8475A
653
654        Returns:
655            True if pass; False if fail
656        """
657        pcid = [0, 1]
658        init_pwr = -30  # initial DL power for all cells
659        power_seq = [
660            [-1, 0],  # power change sequence reference to init_pwr
661            [-2, 0],
662            [-3, 0],
663            [-4, 0],
664            [-5, 0],
665            [-6, 0],
666            [-7, 0],
667            [-8, 0],
668            [-9, 0],
669            [-10, 0],
670            [-9, 0],
671            [-8, 0],
672            [-7, 0],
673            [-6, 0],
674            [-5, 0],
675            [-4, 0],
676            [-3, 0],
677            [-2, 0],
678            [-1, 0],
679            [0, 0],
680            [1, 0],
681            [2, 0],
682            [3, 0],
683            [4, 0],
684            [3, 0],
685            [2, 0],
686            [1, 0],
687            [0, 0]
688        ]
689
690        return self.lte_intra_freq_ncell(self.ad, pcid, init_pwr, power_seq)
691
692    @test_tracker_info(uuid="d1eec95f-40e9-4099-a669-9a88e56049ca")
693    @TelephonyBaseTest.tel_test_wrap
694    def test_2lte_intra_freq_ncell_away_close_2(self):
695        """ Test phone moving away from serving cell and close to neighbor
696        Intra Freq cell, then back and forth
697
698        Setup a two LTE cell configuration on MD8475A
699        Make Sure Phone is in LTE mode
700        Verify the reported RSSI follows the DL power change in MD8475A
701
702        Returns:
703            True if pass; False if fail
704        """
705        pcid = [0, 1]
706        init_pwr = -30  # initial DL power for all cells
707        power_seq = [
708            [-1, 1],  # power change sequence reference to init_pwr
709            [-2, 2],
710            [-3, 3],
711            [-4, 4],
712            [-5, 5],
713            [-4, 4],
714            [-3, 3],
715            [-2, 2],
716            [-1, 1],
717            [-0, 0],
718            [1, -1],
719            [2, -2],
720            [1, -1],
721            [0, 0]
722        ]
723
724        return self.lte_intra_freq_ncell(self.ad, pcid, init_pwr, power_seq)
725
726    @test_tracker_info(uuid="c642a85b-4970-429c-81c4-f635392879be")
727    @TelephonyBaseTest.tel_test_wrap
728    def test_2lte_intra_freq_2cell_synced(self):
729        """ Test phone moving away and back to both serving cell and neighbor
730        Intra Freq cell
731
732        Setup a two LTE cell configuration on MD8475A
733        Make Sure Phone is in LTE mode
734        Verify the reported RSSI follows the DL power change in MD8475A and MG3710A
735
736        Returns:
737            True if pass; False if fail
738        """
739        pcid = [0, 1]
740        init_pwr = -30  # initial DL power for all cells
741        power_seq = [
742            [-1, -1],  # power change sequence reference to init_pwr
743            [-3, -3],
744            [-5, -5],
745            [-7, -7],
746            [-5, -5],
747            [-3, -3],
748            [-1, -1],
749            [1, 1],
750            [3, 3],
751            [5, 5],
752            [7, 7],
753            [3, 3],
754            [0, 0]
755        ]
756
757        return self.lte_intra_freq_ncell(self.ad, pcid, init_pwr, power_seq)
758
759    @test_tracker_info(uuid="9144fab6-c7e1-4de2-a01d-7a15c117ec70")
760    @TelephonyBaseTest.tel_test_wrap
761    def test_3lte_intra_freq_scell_reversed(self):
762        """ Test phone moving away and back between 2 neighbor cells while maintain
763        same rssi with serving cell
764
765        Setup a two LTE cell configuration on MD8475A
766        Make Sure Phone is in LTE mode
767        Verify the reported RSSI follows the DL power change in MD8475A and MG3710A
768
769        Returns:
770            True if pass; False if fail
771        """
772        pcid = [0, 1, 2]
773        init_pwr = -30  # initial DL power for all cells
774        power_seq = [
775            [0, 1, -1],  # power change sequence reference to init_pwr
776            [0, 2, -2],
777            [0, 3, -3],
778            [0, 4, -4],
779            [0, 3, -3],
780            [0, 2, -2],
781            [0, 1, -1],
782            [0, 0, 0],
783            [0, -1, 1],
784            [0, -2, 2],
785            [0, -3, 3],
786            [0, -4, 4],
787            [0, -3, 3],
788            [0, -2, 2],
789            [0, -1, 1],
790            [0, 0, 0]
791        ]
792
793        return self.lte_intra_freq_ncell(self.ad, pcid, init_pwr, power_seq)
794
795    @test_tracker_info(uuid="7bfbea72-e6fa-45ae-bf7e-b9b42063abe7")
796    @TelephonyBaseTest.tel_test_wrap
797    def test_3lte_intra_freq_3cell_synced(self):
798        """ Test phone moving away and back to both serving cell and neighbor
799        Intra Freq cell
800
801        Setup a two LTE cell configuration on MD8475A
802        Make Sure Phone is in LTE mode
803        Verify the reported RSSI follows the DL power change in MD8475A
804
805        Returns:
806            True if pass; False if fail
807        """
808        pcid = [0, 1, 2]
809        init_pwr = -30  # initial DL power for all cells
810        power_seq = [
811            [-1, -1, -1],  # power change sequence reference to init_pwr
812            [-3, -3, -3],
813            [-5, -5, -5],
814            [-7, -7, -7],
815            [-5, -5, -5],
816            [-3, -3, -3],
817            [-1, -1, -1],
818            [1, 1, 1],
819            [3, 3, 3],
820            [5, 5, 5],
821            [7, 7, 7],
822            [3, 3, 3],
823            [0, 0, 0]
824        ]
825
826        return self.lte_intra_freq_ncell(self.ad, pcid, init_pwr, power_seq)
827
828    @test_tracker_info(uuid="b4577ae1-6435-4a15-9449-e02013dfb032")
829    @TelephonyBaseTest.tel_test_wrap
830    def test_ncells_intra_lte_0_cells(self):
831        """ Test Number of neighbor cells reported by Phone when no neighbor
832        cells are present (Phone camped on LTE)
833
834        Setup a single LTE cell configuration on MD8475A
835        Make Sure Phone is in LTE mode
836        Verify the number of neighbor cells reported by Phone
837
838        Returns:
839            True if pass; False if fail
840        """
841        serving_cell_cid = 11
842        serving_cell_pcid = 11
843        serving_cell_dlpower = -20
844        expected_cell_info_list = [
845            # Serving Cell
846            {
847                self.CID: serving_cell_cid,
848                self.PCID: serving_cell_pcid,
849                self.REPORT_RATE: 1,
850                self.IS_REGISTERED: True,
851                self.RAT: 'lte',
852                self.TARGET_RSSI: self._LTE_RSSI_OFFSET + serving_cell_dlpower,
853                self.MAX_ERROR_RSSI: 3,
854                self.MAX_ERROR_AVERAGE_RSSI: 3
855            }
856        ]
857        expected_cell_info_stats = {}
858        for sample in expected_cell_info_list:
859            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
860
861        [bts1] = set_system_model_lte(self.md8475a, self.user_params,
862                                      self.ad.sim_card)
863        self._setup_lte_serving_cell(bts1, serving_cell_dlpower,
864                                     serving_cell_cid, serving_cell_pcid)
865        set_usim_parameters(self.md8475a, self.ad.sim_card)
866        self.md8475a.start_simulation()
867
868        if not ensure_network_rat(
869                self.log,
870                self.ad,
871                NETWORK_MODE_LTE_GSM_WCDMA,
872                RAT_FAMILY_LTE,
873                toggle_apm_after_setting=True):
874            self.log.error("Failed to set rat family {}, preferred network:{}".
875                           format(RAT_FAMILY_LTE, NETWORK_MODE_LTE_GSM_WCDMA))
876            return False
877        self.md8475a.wait_for_registration_state()
878        time.sleep(self._SETTLING_TIME)
879        return self._verify_cell_info(self.ad, expected_cell_info_stats)
880
881    @test_tracker_info(uuid="fe2cc07b-9676-41ab-b7ff-112d3ef84980")
882    @TelephonyBaseTest.tel_test_wrap
883    def test_ncells_intra_lte_1_cells(self):
884        """ Test Number of neighbor cells reported by Phone when one neighbor
885        cell is present (Phone camped on LTE)
886
887        Setup a two LTE cell configuration on MD8475A
888        Make Sure Phone is in LTE mode
889        Verify the number of neighbor cells reported by Phone
890
891        Returns:
892            True if pass; False if fail
893        """
894        serving_cell_cid = 11
895        serving_cell_pcid = 11
896        neigh_cell_cid = 22
897        neigh_cell_pcid = 22
898        serving_cell_dlpower = -20
899        neigh_cell_dlpower = -24
900
901        expected_cell_info_list = [
902            # Serving Cell
903            {
904                self.CID: serving_cell_cid,
905                self.PCID: serving_cell_pcid,
906                self.REPORT_RATE: 1,
907                self.IS_REGISTERED: True,
908                self.RAT: 'lte',
909                self.TARGET_RSSI: self._LTE_RSSI_OFFSET + serving_cell_dlpower,
910                self.MAX_ERROR_RSSI: 3,
911                self.MAX_ERROR_AVERAGE_RSSI: 3
912            },
913            # Neighbor Cells
914            {
915                self.PCID: neigh_cell_pcid,
916                self.REPORT_RATE: 0.1,
917                self.IS_REGISTERED: False,
918                self.RAT: 'lte',
919                self.TARGET_RSSI: self._LTE_RSSI_OFFSET + neigh_cell_dlpower,
920                self.MAX_ERROR_RSSI: 4,
921                self.MAX_ERROR_AVERAGE_RSSI: 3
922            }
923        ]
924        expected_cell_info_stats = {}
925        for sample in expected_cell_info_list:
926            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
927
928        [bts1, bts2] = set_system_model_lte_lte(self.md8475a, self.user_params,
929                                                self.ad.sim_card)
930
931        self._setup_lte_serving_cell(bts1, serving_cell_dlpower,
932                                     serving_cell_cid, serving_cell_pcid)
933        self._setup_lte_neighbhor_cell_md8475a(bts2, LTE_BAND_2,
934                                               neigh_cell_dlpower,
935                                               neigh_cell_cid, neigh_cell_pcid)
936        set_usim_parameters(self.md8475a, self.ad.sim_card)
937        self.md8475a.send_command("IMSSTARTVN 1")
938        self.md8475a.start_simulation()
939        bts2.service_state = BtsServiceState.SERVICE_STATE_OUT
940
941        if not ensure_network_rat(
942                self.log,
943                self.ad,
944                NETWORK_MODE_LTE_GSM_WCDMA,
945                RAT_FAMILY_LTE,
946                toggle_apm_after_setting=True):
947            self.log.error("Failed to set rat family {}, preferred network:{}".
948                           format(RAT_FAMILY_LTE, NETWORK_MODE_LTE_GSM_WCDMA))
949            return False
950        self.md8475a.wait_for_registration_state()
951        bts2.service_state = BtsServiceState.SERVICE_STATE_IN
952        self.log.info("Wait for {} seconds to settle".format(
953            self._SETTLING_TIME))
954        time.sleep(self._SETTLING_TIME)
955        return self._verify_cell_info(self.ad, expected_cell_info_stats)
956
957    @test_tracker_info(uuid="8abc7903-4ea7-407a-946b-455d7f767c3e")
958    @TelephonyBaseTest.tel_test_wrap
959    def test_ncells_intra_lte_2_cells(self):
960        """ Test Number of neighbor cells reported by Phone when two neighbor
961        cells are present (Phone camped on LTE)
962
963        Setup a two LTE cell configuration on MD8475A
964        Setup one waveform on MG3710A
965        Make Sure Phone is in LTE mode
966        Verify the number of neighbor cells reported by Phone
967
968        Returns:
969            True if pass; False if fail
970        """
971        serving_cell_cid = 11
972        serving_cell_pcid = 11
973        neigh_cell_1_cid = 22
974        neigh_cell_1_pcid = 22
975        neigh_cell_2_cid = 1
976        neigh_cell_2_pcid = 1
977        serving_cell_dlpower = -20
978        neigh_cell_1_dlpower = -24
979        neigh_cell_2_dlpower = -23
980
981        expected_cell_info_list = [
982            # Serving Cell
983            {
984                self.CID: serving_cell_cid,
985                self.PCID: serving_cell_pcid,
986                self.REPORT_RATE: 1,
987                self.IS_REGISTERED: True,
988                self.RAT: 'lte',
989                self.TARGET_RSSI: self._LTE_RSSI_OFFSET + serving_cell_dlpower,
990                self.MAX_ERROR_RSSI: 3,
991                self.MAX_ERROR_AVERAGE_RSSI: 3
992            },
993            # Neighbor Cells
994            {
995                self.PCID: neigh_cell_1_pcid,
996                self.REPORT_RATE: 0.1,
997                self.IS_REGISTERED: False,
998                self.RAT: 'lte',
999                self.TARGET_RSSI: self._LTE_RSSI_OFFSET + neigh_cell_1_dlpower,
1000                self.MAX_ERROR_RSSI: 4,
1001                self.MAX_ERROR_AVERAGE_RSSI: 3
1002            },
1003            {
1004                self.PCID: neigh_cell_2_pcid,
1005                self.REPORT_RATE: 0.1,
1006                self.IS_REGISTERED: False,
1007                self.RAT: 'lte',
1008                self.TARGET_RSSI: self._LTE_RSSI_OFFSET + neigh_cell_2_dlpower,
1009                self.MAX_ERROR_RSSI: 4,
1010                self.MAX_ERROR_AVERAGE_RSSI: 3
1011            }
1012        ]
1013        expected_cell_info_stats = {}
1014        for sample in expected_cell_info_list:
1015            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
1016
1017        [bts1, bts2] = set_system_model_lte_lte(self.md8475a, self.user_params,
1018                                                self.ad.sim_card)
1019
1020        self._setup_lte_serving_cell(bts1, serving_cell_dlpower,
1021                                     serving_cell_cid, serving_cell_pcid)
1022        self._setup_lte_neighbhor_cell_md8475a(
1023            bts2, LTE_BAND_2, neigh_cell_1_dlpower, neigh_cell_1_cid,
1024            neigh_cell_1_pcid)
1025        set_usim_parameters(self.md8475a, self.ad.sim_card)
1026        self.md8475a.start_simulation()
1027        if not ensure_network_rat(
1028                self.log,
1029                self.ad,
1030                NETWORK_MODE_LTE_GSM_WCDMA,
1031                RAT_FAMILY_LTE,
1032                toggle_apm_after_setting=True):
1033            self.log.error("Failed to set rat family {}, preferred network:{}".
1034                           format(RAT_FAMILY_LTE, NETWORK_MODE_LTE_GSM_WCDMA))
1035            return False
1036        self.md8475a.wait_for_registration_state()
1037
1038        self.setup_3710a_waveform("1", "A", "1960MHZ", neigh_cell_2_dlpower,
1039                                  "LTE", "10M_B1_CID1")
1040        self.turn_on_3710a_sg(1)
1041        time.sleep(self._SETTLING_TIME)
1042        return self._verify_cell_info(self.ad, expected_cell_info_stats)
1043
1044    @test_tracker_info(uuid="623b3d16-bc48-4353-abc3-054ca6351a97")
1045    @TelephonyBaseTest.tel_test_wrap
1046    def test_ncells_intra_lte_3_cells(self):
1047        """ Test Number of neighbor cells reported by Phone when three neighbor
1048        cells are present (Phone camped on LTE)
1049
1050        Setup two LTE cell configuration on MD8475A
1051        Setup two waveform on MG3710A
1052        Make Sure Phone is in LTE mode
1053        Verify the number of neighbor cells reported by Phone
1054
1055        Returns:
1056            True if pass; False if fail
1057        """
1058        serving_cell_cid = 11
1059        serving_cell_pcid = 11
1060        neigh_cell_1_cid = 1
1061        neigh_cell_1_pcid = 1
1062        neigh_cell_2_cid = 2
1063        neigh_cell_2_pcid = 2
1064        neigh_cell_3_cid = 3
1065        neigh_cell_3_pcid = 3
1066        serving_cell_dlpower = -20
1067        neigh_cell_1_dlpower = -24
1068        neigh_cell_2_dlpower = -22
1069        neigh_cell_3_dlpower = -23
1070
1071        expected_cell_info_list = [
1072            # Serving Cell
1073            {
1074                self.CID: serving_cell_cid,
1075                self.PCID: serving_cell_pcid,
1076                self.REPORT_RATE: 1,
1077                self.IS_REGISTERED: True,
1078                self.RAT: 'lte',
1079                self.TARGET_RSSI: self._LTE_RSSI_OFFSET + serving_cell_dlpower,
1080                self.MAX_ERROR_RSSI: 3,
1081                self.MAX_ERROR_AVERAGE_RSSI: 3
1082            },
1083            # Neighbor Cells
1084            {
1085                self.PCID: neigh_cell_1_pcid,
1086                self.REPORT_RATE: 0.1,
1087                self.IS_REGISTERED: False,
1088                self.RAT: 'lte',
1089                self.TARGET_RSSI: self._LTE_RSSI_OFFSET + neigh_cell_1_dlpower,
1090                self.MAX_ERROR_RSSI: 4,
1091                self.MAX_ERROR_AVERAGE_RSSI: 3
1092            },
1093            {
1094                self.PCID: neigh_cell_2_pcid,
1095                self.REPORT_RATE: 0.1,
1096                self.IS_REGISTERED: False,
1097                self.RAT: 'lte',
1098                self.TARGET_RSSI: self._LTE_RSSI_OFFSET + neigh_cell_2_dlpower,
1099                self.MAX_ERROR_RSSI: 4,
1100                self.MAX_ERROR_AVERAGE_RSSI: 3
1101            },
1102            {
1103                self.PCID: neigh_cell_3_pcid,
1104                self.REPORT_RATE: 0.1,
1105                self.IS_REGISTERED: False,
1106                self.RAT: 'lte',
1107                self.TARGET_RSSI: self._LTE_RSSI_OFFSET + neigh_cell_3_dlpower,
1108                self.MAX_ERROR_RSSI: 4,
1109                self.MAX_ERROR_AVERAGE_RSSI: 3
1110            }
1111        ]
1112        expected_cell_info_stats = {}
1113        for sample in expected_cell_info_list:
1114            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
1115        [bts1, bts2] = set_system_model_lte_lte(self.md8475a, self.user_params,
1116                                                self.ad.sim_card)
1117        self._setup_lte_serving_cell(bts1, serving_cell_dlpower,
1118                                     serving_cell_cid, serving_cell_pcid)
1119
1120        self._setup_lte_neighbhor_cell_md8475a(
1121            bts2, LTE_BAND_2, neigh_cell_1_dlpower, neigh_cell_1_cid,
1122            neigh_cell_1_pcid)
1123        set_usim_parameters(self.md8475a, self.ad.sim_card)
1124        self.md8475a.start_simulation()
1125        if not ensure_network_rat(
1126                self.log,
1127                self.ad,
1128                NETWORK_MODE_LTE_GSM_WCDMA,
1129                RAT_FAMILY_LTE,
1130                toggle_apm_after_setting=True):
1131            self.log.error("Failed to set rat family {}, preferred network:{}".
1132                           format(RAT_FAMILY_LTE, NETWORK_MODE_LTE_GSM_WCDMA))
1133            return False
1134        self.md8475a.wait_for_registration_state()
1135
1136        self.setup_3710a_waveform("1", "A", "1960MHZ", neigh_cell_2_dlpower,
1137                                  "LTE", "10M_B1_CID2")
1138
1139        self.setup_3710a_waveform("1", "B", "1960MHZ", neigh_cell_3_dlpower,
1140                                  "LTE", "10M_B1_CID3")
1141        self.turn_on_3710a_sg(1)
1142        time.sleep(self._SETTLING_TIME)
1143        return self._verify_cell_info(self.ad, expected_cell_info_stats)
1144
1145    @test_tracker_info(uuid="3e094e3d-e7b7-447a-9a7a-8060c5b17e88")
1146    @TelephonyBaseTest.tel_test_wrap
1147    def test_ncells_intra_lte_4_cells(self):
1148        """ Test Number of neighbor cells reported by Phone when four neighbor
1149        cells are present (Phone camped on LTE)
1150
1151        Setup two LTE cell configuration on MD8475A
1152        Setup three waveform on MG3710A
1153        Make Sure Phone is in LTE mode
1154        Verify the number of neighbor cells reported by Phone
1155
1156        Returns:
1157            True if pass; False if fail
1158        """
1159        serving_cell_cid = 11
1160        serving_cell_pcid = 11
1161        neigh_cell_1_cid = 1
1162        neigh_cell_1_pcid = 1
1163        neigh_cell_2_cid = 2
1164        neigh_cell_2_pcid = 2
1165        neigh_cell_3_cid = 3
1166        neigh_cell_3_pcid = 3
1167        neigh_cell_4_cid = 5
1168        neigh_cell_4_pcid = 5
1169        serving_cell_dlpower = -20
1170        neigh_cell_1_dlpower = -24
1171        neigh_cell_2_dlpower = -22
1172        neigh_cell_3_dlpower = -24
1173        neigh_cell_4_dlpower = -22
1174
1175        expected_cell_info_list = [
1176            # Serving Cell
1177            {
1178                self.CID: serving_cell_cid,
1179                self.PCID: serving_cell_pcid,
1180                self.REPORT_RATE: 1,
1181                self.IS_REGISTERED: True,
1182                self.RAT: 'lte',
1183                self.TARGET_RSSI: self._LTE_RSSI_OFFSET + serving_cell_dlpower,
1184                self.MAX_ERROR_RSSI: 3,
1185                self.MAX_ERROR_AVERAGE_RSSI: 3
1186            },
1187            # Neighbor Cells
1188            {
1189                self.PCID: neigh_cell_1_pcid,
1190                self.REPORT_RATE: 0.1,
1191                self.IS_REGISTERED: False,
1192                self.RAT: 'lte',
1193                self.TARGET_RSSI: self._LTE_RSSI_OFFSET + neigh_cell_1_dlpower,
1194                self.MAX_ERROR_RSSI: 4,
1195                self.MAX_ERROR_AVERAGE_RSSI: 3
1196            },
1197            {
1198                self.PCID: neigh_cell_2_pcid,
1199                self.REPORT_RATE: 0.1,
1200                self.IS_REGISTERED: False,
1201                self.RAT: 'lte',
1202                self.TARGET_RSSI: self._LTE_RSSI_OFFSET + neigh_cell_2_dlpower,
1203                self.MAX_ERROR_RSSI: 4,
1204                self.MAX_ERROR_AVERAGE_RSSI: 3
1205            },
1206            {
1207                self.PCID: neigh_cell_3_pcid,
1208                self.REPORT_RATE: 0.1,
1209                self.IS_REGISTERED: False,
1210                self.RAT: 'lte',
1211                self.TARGET_RSSI: self._LTE_RSSI_OFFSET + neigh_cell_3_dlpower,
1212                self.MAX_ERROR_RSSI: 4,
1213                self.MAX_ERROR_AVERAGE_RSSI: 3
1214            },
1215            {
1216                self.PCID: neigh_cell_4_pcid,
1217                self.REPORT_RATE: 0.1,
1218                self.IS_REGISTERED: False,
1219                self.RAT: 'lte',
1220                self.TARGET_RSSI: self._LTE_RSSI_OFFSET + neigh_cell_4_dlpower,
1221                self.MAX_ERROR_RSSI: 4,
1222                self.MAX_ERROR_AVERAGE_RSSI: 3
1223            }
1224        ]
1225        expected_cell_info_stats = {}
1226        for sample in expected_cell_info_list:
1227            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
1228
1229        [bts1, bts2] = set_system_model_lte_lte(self.md8475a, self.user_params,
1230                                                self.ad.sim_card)
1231        self._setup_lte_serving_cell(bts1, serving_cell_dlpower,
1232                                     serving_cell_cid, serving_cell_pcid)
1233
1234        self._setup_lte_neighbhor_cell_md8475a(
1235            bts2, LTE_BAND_2, neigh_cell_1_dlpower, neigh_cell_1_cid,
1236            neigh_cell_1_pcid)
1237        set_usim_parameters(self.md8475a, self.ad.sim_card)
1238        self.md8475a.start_simulation()
1239
1240        if not ensure_network_rat(
1241                self.log,
1242                self.ad,
1243                NETWORK_MODE_LTE_GSM_WCDMA,
1244                RAT_FAMILY_LTE,
1245                toggle_apm_after_setting=True):
1246            self.log.error("Failed to set rat family {}, preferred network:{}".
1247                           format(RAT_FAMILY_LTE, NETWORK_MODE_LTE_GSM_WCDMA))
1248            return False
1249        self.md8475a.wait_for_registration_state()
1250
1251        self.setup_3710a_waveform("1", "A", "1960MHZ", neigh_cell_2_dlpower,
1252                                  "LTE", "10M_B1_CID2")
1253
1254        self.setup_3710a_waveform("1", "B", "1960MHZ", neigh_cell_3_dlpower,
1255                                  "LTE", "10M_B1_CID3")
1256
1257        self.setup_3710a_waveform("2", "A", "1960MHZ", neigh_cell_4_dlpower,
1258                                  "LTE", "10M_B1_CID5")
1259        self.turn_on_3710a_sg(1)
1260        self.turn_on_3710a_sg(2)
1261        time.sleep(self._SETTLING_TIME)
1262
1263        return self._verify_cell_info(self.ad, expected_cell_info_stats)
1264
1265    @test_tracker_info(uuid="7e9a9c30-9284-4440-b85e-f94b83e0373f")
1266    @TelephonyBaseTest.tel_test_wrap
1267    def test_neighbor_cell_reporting_lte_intrafreq_0_tmo(self):
1268        """ Test Number of neighbor cells reported by Phone when no neighbor
1269        cells are present (Phone camped on LTE)
1270
1271        Setup a single LTE cell configuration on MD8475A
1272        Make Sure Phone is in LTE mode
1273        Verify the number of neighbor cells reported by Phone
1274
1275        Returns:
1276            True if pass; False if fail
1277        """
1278        serving_cell = lte_band4_ch2000_fr2115_pcid1_cell
1279        serving_cell['power'] = -20
1280
1281        expected_cell_info_list = [
1282            # Serving Cell
1283            {
1284                self.CID: serving_cell[self.CID],
1285                self.PCID: serving_cell[self.PCID],
1286                self.REPORT_RATE: 1,
1287                self.IS_REGISTERED: True,
1288                self.RAT: 'lte',
1289                self.TARGET_RSSI:
1290                self._LTE_RSSI_OFFSET + serving_cell['power'],
1291                self.MAX_ERROR_RSSI: 3,
1292                self.MAX_ERROR_AVERAGE_RSSI: 3
1293            }
1294        ]
1295
1296        expected_cell_info_stats = {}
1297        for sample in expected_cell_info_list:
1298            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
1299
1300        [bts1] = set_system_model_lte(self.md8475a, self.user_params,
1301                                      self.ad.sim_card)
1302        self._setup_lte_cell_md8475a(bts1, serving_cell, serving_cell['power'])
1303        set_usim_parameters(self.md8475a, self.ad.sim_card)
1304        self.md8475a.start_simulation()
1305
1306        if not ensure_network_rat(
1307                self.log,
1308                self.ad,
1309                NETWORK_MODE_LTE_GSM_WCDMA,
1310                RAT_FAMILY_LTE,
1311                toggle_apm_after_setting=True):
1312            self.log.error("Failed to set rat family {}, preferred network:{}".
1313                           format(RAT_FAMILY_LTE, NETWORK_MODE_LTE_GSM_WCDMA))
1314            return False
1315        self.md8475a.wait_for_registration_state()
1316        time.sleep(self._SETTLING_TIME)
1317        return self._verify_cell_info(self.ad, expected_cell_info_stats)
1318
1319    @test_tracker_info(uuid="13bd7000-5a45-43f5-9e54-001e0aa09262")
1320    @TelephonyBaseTest.tel_test_wrap
1321    def test_neighbor_cell_reporting_lte_intrafreq_1_tmo(self):
1322        """ Test Number of neighbor cells reported by Phone when one neighbor
1323        cell is present (Phone camped on LTE)
1324
1325        Setup a two LTE cell configuration on MD8475A
1326        Make Sure Phone is in LTE mode
1327        Verify the number of neighbor cells reported by Phone
1328
1329        Returns:
1330            True if pass; False if fail
1331        """
1332        serving_cell = lte_band4_ch2000_fr2115_pcid1_cell
1333        neighbor_cell = lte_band4_ch2000_fr2115_pcid2_cell
1334        serving_cell['power'] = -20
1335        neighbor_cell['power'] = -24
1336        expected_cell_info_list = [
1337            # Serving Cell
1338            {
1339                self.CID: serving_cell[self.CID],
1340                self.PCID: serving_cell[self.PCID],
1341                self.REPORT_RATE: 1,
1342                self.IS_REGISTERED: True,
1343                self.RAT: 'lte',
1344                self.TARGET_RSSI:
1345                self._LTE_RSSI_OFFSET + serving_cell['power'],
1346                self.MAX_ERROR_RSSI: 3,
1347                self.MAX_ERROR_AVERAGE_RSSI: 3
1348            },
1349            # Neighbor Cells
1350            {
1351                self.PCID: neighbor_cell[self.PCID],
1352                self.REPORT_RATE: 0.1,
1353                self.IS_REGISTERED: False,
1354                self.RAT: 'lte',
1355                self.TARGET_RSSI:
1356                self._LTE_RSSI_OFFSET + neighbor_cell['power'],
1357                self.MAX_ERROR_RSSI: 4,
1358                self.MAX_ERROR_AVERAGE_RSSI: 3
1359            }
1360        ]
1361        expected_cell_info_stats = {}
1362        for sample in expected_cell_info_list:
1363            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
1364
1365        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
1366        [bts1, bts2] = set_system_model_lte_lte(self.md8475a, self.user_params,
1367                                                self.ad.sim_card)
1368        self._setup_lte_cell_md8475a(bts1, serving_cell, serving_cell['power'])
1369        self._setup_lte_cell_md8475a(bts2, neighbor_cell,
1370                                     neighbor_cell['power'])
1371        bts1.neighbor_cell_mode = "USERDATA"
1372        bts1.set_neighbor_cell_type("LTE", 1, "CELLNAME")
1373        bts1.set_neighbor_cell_name("LTE", 1, "LTE_4_C2000_F2115_PCID2")
1374        set_usim_parameters(self.md8475a, self.ad.sim_card)
1375        self.md8475a.start_simulation()
1376        # To make sure phone camps on BTS1
1377        bts2.service_state = BtsServiceState.SERVICE_STATE_OUT
1378
1379        if not ensure_network_rat(
1380                self.log,
1381                self.ad,
1382                NETWORK_MODE_LTE_GSM_WCDMA,
1383                RAT_FAMILY_LTE,
1384                toggle_apm_after_setting=True):
1385            self.log.error("Failed to set rat family {}, preferred network:{}".
1386                           format(RAT_FAMILY_LTE, NETWORK_MODE_LTE_GSM_WCDMA))
1387            return False
1388        self.md8475a.wait_for_registration_state()
1389        time.sleep(self._ANRITSU_SETTLING_TIME)
1390        bts2.service_state = BtsServiceState.SERVICE_STATE_IN
1391        time.sleep(self._SETTLING_TIME)
1392        return self._verify_cell_info(self.ad, expected_cell_info_stats)
1393
1394    @test_tracker_info(uuid="5dca3a16-73a0-448a-a35d-22ebd253a570")
1395    @TelephonyBaseTest.tel_test_wrap
1396    def test_neighbor_cell_reporting_lte_intrafreq_2_tmo(self):
1397        """ Test Number of neighbor cells reported by Phone when two neighbor
1398        cells are present (Phone camped on LTE)
1399
1400        Setup one LTE cell configuration on MD8475A
1401        Setup two waveform on MG3710A
1402        Make Sure Phone is in LTE mode
1403        Verify the number of neighbor cells reported by Phone
1404
1405        Returns:
1406            True if pass; False if fail
1407        """
1408        serving_cell = lte_band4_ch2000_fr2115_pcid1_cell
1409        neighbor_cell_1 = lte_band4_ch2000_fr2115_pcid2_cell
1410        neighbor_cell_2 = lte_band4_ch2000_fr2115_pcid3_cell
1411        serving_cell['power'] = -20
1412        neighbor_cell_1['power'] = -24
1413        neighbor_cell_2['power'] = -23
1414
1415        expected_cell_info_list = [
1416            # Serving Cell
1417            {
1418                self.CID: serving_cell[self.CID],
1419                self.PCID: serving_cell[self.PCID],
1420                self.REPORT_RATE: 1,
1421                self.IS_REGISTERED: True,
1422                self.RAT: 'lte',
1423                self.TARGET_RSSI:
1424                self._LTE_RSSI_OFFSET + serving_cell['power'],
1425                self.MAX_ERROR_RSSI: 3,
1426                self.MAX_ERROR_AVERAGE_RSSI: 3
1427            },
1428            # Neighbor Cells
1429            {
1430                self.PCID: neighbor_cell_1[self.PCID],
1431                self.REPORT_RATE: 0.1,
1432                self.IS_REGISTERED: False,
1433                self.RAT: 'lte',
1434                self.TARGET_RSSI:
1435                self._LTE_RSSI_OFFSET + neighbor_cell_1['power'],
1436                self.MAX_ERROR_RSSI: 4,
1437                self.MAX_ERROR_AVERAGE_RSSI: 3
1438            },
1439            {
1440                self.PCID: neighbor_cell_2[self.PCID],
1441                self.REPORT_RATE: 0.1,
1442                self.IS_REGISTERED: False,
1443                self.RAT: 'lte',
1444                self.TARGET_RSSI:
1445                self._LTE_RSSI_OFFSET + neighbor_cell_2['power'],
1446                self.MAX_ERROR_RSSI: 4,
1447                self.MAX_ERROR_AVERAGE_RSSI: 3
1448            }
1449        ]
1450        expected_cell_info_stats = {}
1451        for sample in expected_cell_info_list:
1452            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
1453
1454        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
1455        [bts1, bts2] = set_system_model_lte_lte(self.md8475a, self.user_params,
1456                                                self.ad.sim_card)
1457        self._setup_lte_cell_md8475a(bts1, serving_cell, serving_cell['power'])
1458        self._setup_lte_cell_md8475a(bts2, neighbor_cell_1,
1459                                     neighbor_cell_1['power'])
1460        bts1.neighbor_cell_mode = "USERDATA"
1461        bts1.set_neighbor_cell_type("LTE", 1, "CELLNAME")
1462        bts1.set_neighbor_cell_name("LTE", 1, "LTE_4_C2000_F2115_PCID2")
1463        bts1.set_neighbor_cell_type("LTE", 2, "CELLNAME")
1464        bts1.set_neighbor_cell_name("LTE", 2, "LTE_4_C2000_F2115_PCID3")
1465        set_usim_parameters(self.md8475a, self.ad.sim_card)
1466        self.md8475a.start_simulation()
1467        # To make sure phone camps on BTS1
1468        bts2.service_state = BtsServiceState.SERVICE_STATE_OUT
1469
1470        if not ensure_network_rat(
1471                self.log,
1472                self.ad,
1473                NETWORK_MODE_LTE_GSM_WCDMA,
1474                RAT_FAMILY_LTE,
1475                toggle_apm_after_setting=True):
1476            self.log.error("Failed to set rat family {}, preferred network:{}".
1477                           format(RAT_FAMILY_LTE, NETWORK_MODE_LTE_GSM_WCDMA))
1478            return False
1479        self.md8475a.wait_for_registration_state()
1480        time.sleep(self._ANRITSU_SETTLING_TIME)
1481        bts2.service_state = BtsServiceState.SERVICE_STATE_IN
1482        self.setup_3710a_waveform("1", "A", "2115MHz",
1483                                  neighbor_cell_2['power'], "LTE",
1484                                  "lte_4_ch2000_pcid3")
1485        self.turn_on_3710a_sg(1)
1486        time.sleep(self._SETTLING_TIME)
1487        return self._verify_cell_info(self.ad, expected_cell_info_stats)
1488
1489    @test_tracker_info(uuid="860152de-8aa0-422e-b5b0-28bf244076f4")
1490    @TelephonyBaseTest.tel_test_wrap
1491    def test_neighbor_cell_reporting_lte_intrafreq_3_tmo(self):
1492        """ Test Number of neighbor cells reported by Phone when three neighbor
1493        cells are present (Phone camped on LTE)
1494
1495        Setup a one LTE cell configuration on MD8475A
1496        Setup three waveforms on MG3710A
1497        Make Sure Phone is in LTE mode
1498        Verify the number of neighbor cells reported by Phone
1499
1500        Returns:
1501            True if pass; False if fail
1502        """
1503        serving_cell = lte_band4_ch2000_fr2115_pcid1_cell
1504        neighbor_cell_1 = lte_band4_ch2000_fr2115_pcid2_cell
1505        neighbor_cell_2 = lte_band4_ch2000_fr2115_pcid3_cell
1506        neighbor_cell_3 = lte_band4_ch2000_fr2115_pcid4_cell
1507        serving_cell['power'] = -20
1508        neighbor_cell_1['power'] = -24
1509        neighbor_cell_2['power'] = -23
1510        neighbor_cell_3['power'] = -22
1511
1512        expected_cell_info_list = [
1513            # Serving Cell
1514            {
1515                self.CID: serving_cell[self.CID],
1516                self.PCID: serving_cell[self.PCID],
1517                self.REPORT_RATE: 1,
1518                self.IS_REGISTERED: True,
1519                self.RAT: 'lte',
1520                self.TARGET_RSSI:
1521                self._LTE_RSSI_OFFSET + serving_cell['power'],
1522                self.MAX_ERROR_RSSI: 3,
1523                self.MAX_ERROR_AVERAGE_RSSI: 3
1524            },
1525            # Neighbor Cells
1526            {
1527                self.PCID: neighbor_cell_1[self.PCID],
1528                self.REPORT_RATE: 0.1,
1529                self.IS_REGISTERED: False,
1530                self.RAT: 'lte',
1531                self.TARGET_RSSI:
1532                self._LTE_RSSI_OFFSET + neighbor_cell_1['power'],
1533                self.MAX_ERROR_RSSI: 4,
1534                self.MAX_ERROR_AVERAGE_RSSI: 3
1535            },
1536            {
1537                self.PCID: neighbor_cell_2[self.PCID],
1538                self.REPORT_RATE: 0.1,
1539                self.IS_REGISTERED: False,
1540                self.RAT: 'lte',
1541                self.TARGET_RSSI:
1542                self._LTE_RSSI_OFFSET + neighbor_cell_2['power'],
1543                self.MAX_ERROR_RSSI: 4,
1544                self.MAX_ERROR_AVERAGE_RSSI: 3
1545            },
1546            {
1547                self.PCID: neighbor_cell_3[self.PCID],
1548                self.REPORT_RATE: 0.1,
1549                self.IS_REGISTERED: False,
1550                self.RAT: 'lte',
1551                self.TARGET_RSSI:
1552                self._LTE_RSSI_OFFSET + neighbor_cell_3['power'],
1553                self.MAX_ERROR_RSSI: 4,
1554                self.MAX_ERROR_AVERAGE_RSSI: 3
1555            }
1556        ]
1557        expected_cell_info_stats = {}
1558        for sample in expected_cell_info_list:
1559            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
1560
1561        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
1562        [bts1, bts2] = set_system_model_lte_lte(self.md8475a, self.user_params,
1563                                                self.ad.sim_card)
1564        self._setup_lte_cell_md8475a(bts1, serving_cell, serving_cell['power'])
1565        self._setup_lte_cell_md8475a(bts2, neighbor_cell_1,
1566                                     neighbor_cell_1['power'])
1567        bts1.neighbor_cell_mode = "USERDATA"
1568        bts1.set_neighbor_cell_type("LTE", 1, "CELLNAME")
1569        bts1.set_neighbor_cell_name("LTE", 1, "LTE_4_C2000_F2115_PCID2")
1570        bts1.set_neighbor_cell_type("LTE", 2, "CELLNAME")
1571        bts1.set_neighbor_cell_name("LTE", 2, "LTE_4_C2000_F2115_PCID3")
1572        bts1.set_neighbor_cell_type("LTE", 3, "CELLNAME")
1573        bts1.set_neighbor_cell_name("LTE", 3, "LTE_4_C2000_F2115_PCID4")
1574        set_usim_parameters(self.md8475a, self.ad.sim_card)
1575        self.md8475a.start_simulation()
1576        # To make sure phone camps on BTS1
1577        bts2.service_state = BtsServiceState.SERVICE_STATE_OUT
1578
1579        if not ensure_network_rat(
1580                self.log,
1581                self.ad,
1582                NETWORK_MODE_LTE_GSM_WCDMA,
1583                RAT_FAMILY_LTE,
1584                toggle_apm_after_setting=True):
1585            self.log.error("Failed to set rat family {}, preferred network:{}".
1586                           format(RAT_FAMILY_LTE, NETWORK_MODE_LTE_GSM_WCDMA))
1587            return False
1588        self.md8475a.wait_for_registration_state()
1589        time.sleep(self._ANRITSU_SETTLING_TIME)
1590        bts2.service_state = BtsServiceState.SERVICE_STATE_IN
1591        self.setup_3710a_waveform("1", "A", "2115MHz",
1592                                  neighbor_cell_2['power'], "LTE",
1593                                  "lte_4_ch2000_pcid3")
1594
1595        self.setup_3710a_waveform("1", "B", "2115MHz",
1596                                  neighbor_cell_3['power'], "LTE",
1597                                  "lte_4_ch2000_pcid4")
1598        self.turn_on_3710a_sg(1)
1599        time.sleep(self._SETTLING_TIME)
1600        return self._verify_cell_info(self.ad, expected_cell_info_stats)
1601
1602    @test_tracker_info(uuid="8c5b63ba-1322-47b6-adce-5224cbc0995a")
1603    @TelephonyBaseTest.tel_test_wrap
1604    def test_neighbor_cell_reporting_lte_interfreq_1_tmo(self):
1605        """ Test Number of neighbor cells reported by Phone when two neighbor
1606        cells(inter frequency) are present (Phone camped on LTE)
1607
1608        Setup a a LTE cell configuration on MD8475A
1609        Setup two LTE waveforms(inter frequency) on MG3710A
1610        Make Sure Phone is in LTE mode
1611        Verify the number of neighbor cells reported by Phone
1612
1613        Returns:
1614            True if pass; False if fail
1615        """
1616        serving_cell = lte_band4_ch2000_fr2115_pcid1_cell
1617        neighbor_cell_1 = lte_band4_ch2050_fr2120_pcid7_cell
1618        serving_cell['power'] = -20
1619        neighbor_cell_1['power'] = -23
1620        expected_cell_info_list = [
1621            # Serving Cell
1622            {
1623                self.CID: serving_cell[self.CID],
1624                self.PCID: serving_cell[self.PCID],
1625                self.REPORT_RATE: 1,
1626                self.IS_REGISTERED: True,
1627                self.RAT: 'lte',
1628                self.TARGET_RSSI:
1629                self._LTE_RSSI_OFFSET + serving_cell['power'],
1630                self.MAX_ERROR_RSSI: 3,
1631                self.MAX_ERROR_AVERAGE_RSSI: 3
1632            },
1633            # Neighbor Cells
1634            {
1635                self.PCID: neighbor_cell_1[self.PCID],
1636                self.REPORT_RATE: 0.1,
1637                self.IS_REGISTERED: False,
1638                self.RAT: 'lte',
1639                self.TARGET_RSSI:
1640                self._LTE_RSSI_OFFSET + neighbor_cell_1['power'],
1641                self.MAX_ERROR_RSSI: 4,
1642                self.MAX_ERROR_AVERAGE_RSSI: 3
1643            }
1644        ]
1645        expected_cell_info_stats = {}
1646        for sample in expected_cell_info_list:
1647            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
1648
1649        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
1650        [bts1, bts2] = set_system_model_lte_lte(self.md8475a, self.user_params,
1651                                                self.ad.sim_card)
1652        self._setup_lte_cell_md8475a(bts1, serving_cell, serving_cell['power'])
1653        self._setup_lte_cell_md8475a(bts2, neighbor_cell_1,
1654                                     neighbor_cell_1['power'])
1655        bts1.neighbor_cell_mode = "USERDATA"
1656        bts1.set_neighbor_cell_type("LTE", 1, "CELLNAME")
1657        bts1.set_neighbor_cell_name("LTE", 1, "LTE_4_C2050_F2120_PCID7")
1658        set_usim_parameters(self.md8475a, self.ad.sim_card)
1659        self.md8475a.start_simulation()
1660        # To make sure phone camps on BTS1
1661        bts2.service_state = BtsServiceState.SERVICE_STATE_OUT
1662
1663        self.ad.droid.telephonyToggleDataConnection(False)
1664        if not ensure_network_rat(
1665                self.log,
1666                self.ad,
1667                NETWORK_MODE_LTE_GSM_WCDMA,
1668                RAT_FAMILY_LTE,
1669                toggle_apm_after_setting=True):
1670            self.log.error("Failed to set rat family {}, preferred network:{}".
1671                           format(RAT_FAMILY_LTE, NETWORK_MODE_LTE_GSM_WCDMA))
1672            return False
1673        self.md8475a.wait_for_registration_state()
1674        time.sleep(self._ANRITSU_SETTLING_TIME)
1675        bts2.service_state = BtsServiceState.SERVICE_STATE_IN
1676        time.sleep(self._ANRITSU_SETTLING_TIME)
1677        self.md8475a.set_packet_preservation()
1678        time.sleep(self._SETTLING_TIME)
1679        return self._verify_cell_info(self.ad, expected_cell_info_stats)
1680
1681    @test_tracker_info(uuid="97853501-a328-4706-bb3f-c5e708b1ccb8")
1682    @TelephonyBaseTest.tel_test_wrap
1683    def test_neighbor_cell_reporting_lte_interfreq_2_tmo(self):
1684        """ Test Number of neighbor cells reported by Phone when two neighbor
1685        cells(inter frequency) are present (Phone camped on LTE)
1686
1687        Setup a a LTE cell configuration on MD8475A
1688        Setup two LTE waveforms(inter frequency) on MG3710A
1689        Make Sure Phone is in LTE mode
1690        Verify the number of neighbor cells reported by Phone
1691
1692        Returns:
1693            True if pass; False if fail
1694        """
1695        serving_cell = lte_band4_ch2000_fr2115_pcid1_cell
1696        neighbor_cell_1 = lte_band4_ch2050_fr2120_pcid7_cell
1697        neighbor_cell_2 = lte_band4_ch2250_fr2140_pcid8_cell
1698        serving_cell['power'] = -20
1699        neighbor_cell_1['power'] = -23
1700        neighbor_cell_2['power'] = -22
1701
1702        expected_cell_info_list = [
1703            # Serving Cell
1704            {
1705                self.CID: serving_cell[self.CID],
1706                self.PCID: serving_cell[self.PCID],
1707                self.REPORT_RATE: 1,
1708                self.IS_REGISTERED: True,
1709                self.RAT: 'lte',
1710                self.TARGET_RSSI:
1711                self._LTE_RSSI_OFFSET + serving_cell['power'],
1712                self.MAX_ERROR_RSSI: 3,
1713                self.MAX_ERROR_AVERAGE_RSSI: 3
1714            },
1715            # Neighbor Cells
1716            {
1717                self.PCID: neighbor_cell_1[self.PCID],
1718                self.REPORT_RATE: 0.1,
1719                self.IS_REGISTERED: False,
1720                self.RAT: 'lte',
1721                self.TARGET_RSSI:
1722                self._LTE_RSSI_OFFSET + neighbor_cell_1['power'],
1723                self.MAX_ERROR_RSSI: 4,
1724                self.MAX_ERROR_AVERAGE_RSSI: 3
1725            },
1726            {
1727                self.PCID: neighbor_cell_2[self.PCID],
1728                self.REPORT_RATE: 0.1,
1729                self.IS_REGISTERED: False,
1730                self.RAT: 'lte',
1731                self.TARGET_RSSI:
1732                self._LTE_RSSI_OFFSET + neighbor_cell_2['power'],
1733                self.MAX_ERROR_RSSI: 4,
1734                self.MAX_ERROR_AVERAGE_RSSI: 3
1735            }
1736        ]
1737        expected_cell_info_stats = {}
1738        for sample in expected_cell_info_list:
1739            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
1740
1741        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
1742        [bts1, bts2] = set_system_model_lte_lte(self.md8475a, self.user_params,
1743                                                self.ad.sim_card)
1744        self._setup_lte_cell_md8475a(bts1, serving_cell, serving_cell['power'])
1745        self._setup_lte_cell_md8475a(bts2, neighbor_cell_1,
1746                                     neighbor_cell_1['power'])
1747        bts1.neighbor_cell_mode = "USERDATA"
1748        bts1.set_neighbor_cell_type("LTE", 1, "CELLNAME")
1749        bts1.set_neighbor_cell_name("LTE", 1, "LTE_4_C2050_F2120_PCID7")
1750        bts1.set_neighbor_cell_type("LTE", 2, "CELLNAME")
1751        bts1.set_neighbor_cell_name("LTE", 2, "LTE_4_C2250_F2140_PCID8")
1752        set_usim_parameters(self.md8475a, self.ad.sim_card)
1753        self.md8475a.start_simulation()
1754        # To make sure phone camps on BTS1
1755        bts2.service_state = BtsServiceState.SERVICE_STATE_OUT
1756
1757        self.ad.droid.telephonyToggleDataConnection(False)
1758        if not ensure_network_rat(
1759                self.log,
1760                self.ad,
1761                NETWORK_MODE_LTE_GSM_WCDMA,
1762                RAT_FAMILY_LTE,
1763                toggle_apm_after_setting=True):
1764            self.log.error("Failed to set rat family {}, preferred network:{}".
1765                           format(RAT_FAMILY_LTE, NETWORK_MODE_LTE_GSM_WCDMA))
1766            return False
1767        self.md8475a.wait_for_registration_state()
1768        time.sleep(self._ANRITSU_SETTLING_TIME)
1769        bts2.service_state = BtsServiceState.SERVICE_STATE_IN
1770        time.sleep(self._ANRITSU_SETTLING_TIME)
1771        self.setup_3710a_waveform("1", "A", "2140MHz",
1772                                  neighbor_cell_2['power'], "LTE",
1773                                  "lte_4_ch2250_pcid8")
1774
1775        self.turn_on_3710a_sg(1)
1776        self.md8475a.set_packet_preservation()
1777        time.sleep(self._SETTLING_TIME)
1778        return self._verify_cell_info(self.ad, expected_cell_info_stats)
1779
1780    @test_tracker_info(uuid="74bd528c-e1c5-476d-9ee0-ebfc7bbc5de1")
1781    @TelephonyBaseTest.tel_test_wrap
1782    def test_neighbor_cell_reporting_lte_interband_2_tmo(self):
1783        """ Test Number of neighbor cells reported by Phone when two neighbor
1784        cells(inter band) are present (Phone camped on LTE)
1785
1786        Setup one LTE cell configuration on MD8475A
1787        Setup two LTE waveforms((inter band)) on MG3710A
1788        Make Sure Phone is in LTE mode
1789        Verify the number of neighbor cells reported by Phone
1790
1791        Returns:
1792            True if pass; False if fail
1793        """
1794        serving_cell = lte_band4_ch2000_fr2115_pcid1_cell
1795        neighbor_cell_1 = lte_band2_ch900_fr1960_pcid9_cell
1796        neighbor_cell_2 = lte_band12_ch5095_fr737_pcid10_cell
1797        serving_cell['power'] = -20
1798        neighbor_cell_1['power'] = -24
1799        neighbor_cell_2['power'] = -22
1800
1801        expected_cell_info_list = [
1802            # Serving Cell
1803            {
1804                self.CID: serving_cell[self.CID],
1805                self.PCID: serving_cell[self.PCID],
1806                self.REPORT_RATE: 1,
1807                self.IS_REGISTERED: True,
1808                self.RAT: 'lte',
1809                self.TARGET_RSSI:
1810                self._LTE_RSSI_OFFSET + serving_cell['power'],
1811                self.MAX_ERROR_RSSI: 3,
1812                self.MAX_ERROR_AVERAGE_RSSI: 3
1813            },
1814            # Neighbor Cells
1815            {
1816                self.PCID: neighbor_cell_1[self.PCID],
1817                self.REPORT_RATE: 0.1,
1818                self.IS_REGISTERED: False,
1819                self.RAT: 'lte',
1820                self.TARGET_RSSI:
1821                self._LTE_RSSI_OFFSET + neighbor_cell_1['power'],
1822                self.MAX_ERROR_RSSI: 4,
1823                self.MAX_ERROR_AVERAGE_RSSI: 3
1824            },
1825            {
1826                self.PCID: neighbor_cell_2[self.PCID],
1827                self.REPORT_RATE: 0.1,
1828                self.IS_REGISTERED: False,
1829                self.RAT: 'lte',
1830                self.TARGET_RSSI:
1831                self._LTE_RSSI_OFFSET + neighbor_cell_2['power'],
1832                self.MAX_ERROR_RSSI: 4,
1833                self.MAX_ERROR_AVERAGE_RSSI: 3
1834            }
1835        ]
1836        expected_cell_info_stats = {}
1837        for sample in expected_cell_info_list:
1838            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
1839
1840        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
1841        [bts1, bts2] = set_system_model_lte_lte(self.md8475a, self.user_params,
1842                                                self.ad.sim_card)
1843        self._setup_lte_cell_md8475a(bts1, serving_cell, serving_cell['power'])
1844        self._setup_lte_cell_md8475a(bts2, neighbor_cell_1,
1845                                     neighbor_cell_1['power'])
1846        bts1.neighbor_cell_mode = "USERDATA"
1847        bts1.set_neighbor_cell_type("LTE", 1, "CELLNAME")
1848        bts1.set_neighbor_cell_name("LTE", 1, "LTE_2_C900_F1960_PCID9")
1849        bts1.set_neighbor_cell_type("LTE", 2, "CELLNAME")
1850        bts1.set_neighbor_cell_name("LTE", 2, "LTE_12_C5095_F737_PCID10")
1851        set_usim_parameters(self.md8475a, self.ad.sim_card)
1852        self.md8475a.start_simulation()
1853        # To make sure phone camps on BTS1
1854        bts2.service_state = BtsServiceState.SERVICE_STATE_OUT
1855
1856        self.ad.droid.telephonyToggleDataConnection(False)
1857        if not ensure_network_rat(
1858                self.log,
1859                self.ad,
1860                NETWORK_MODE_LTE_GSM_WCDMA,
1861                RAT_FAMILY_LTE,
1862                toggle_apm_after_setting=True):
1863            self.log.error("Failed to set rat family {}, preferred network:{}".
1864                           format(RAT_FAMILY_LTE, NETWORK_MODE_LTE_GSM_WCDMA))
1865            return False
1866        self.md8475a.wait_for_registration_state()
1867        time.sleep(self._ANRITSU_SETTLING_TIME)
1868        bts2.service_state = BtsServiceState.SERVICE_STATE_IN
1869        self.setup_3710a_waveform("1", "A", "737.5MHz",
1870                                  neighbor_cell_2['power'], "LTE",
1871                                  "lte_12_ch5095_pcid10")
1872        self.turn_on_3710a_sg(1)
1873        time.sleep(self._ANRITSU_SETTLING_TIME)
1874        self.md8475a.set_packet_preservation()
1875        time.sleep(self._SETTLING_TIME)
1876        return self._verify_cell_info(self.ad, expected_cell_info_stats)
1877
1878    @test_tracker_info(uuid="6289e3e4-9316-4b82-bd0b-dde53f26da0d")
1879    @TelephonyBaseTest.tel_test_wrap
1880    def test_neighbor_cell_reporting_lte_interrat_1_tmo(self):
1881        """ Test Number of neighbor cells reported by Phone when two neighbor
1882        cells(inter RAT) are present (Phone camped on LTE)
1883
1884        Setup one LTE and one WCDMA cell configuration on MD8475A
1885        Setup one GSM waveform on MG3710A
1886        Make Sure Phone is in LTE mode
1887        Verify the number of neighbor cells reported by Phone
1888
1889        Returns:
1890            True if pass; False if fail
1891        """
1892        serving_cell = lte_band4_ch2000_fr2115_pcid1_cell
1893        neighbor_cell_1 = wcdma_band1_ch10700_fr2140_cid31_cell
1894        serving_cell['power'] = -20
1895        neighbor_cell_1['power'] = -24
1896
1897        expected_cell_info_list = [
1898            # Serving Cell
1899            {
1900                self.CID: serving_cell[self.CID],
1901                self.PCID: serving_cell[self.PCID],
1902                self.REPORT_RATE: 1,
1903                self.IS_REGISTERED: True,
1904                self.RAT: 'lte',
1905                self.TARGET_RSSI:
1906                self._LTE_RSSI_OFFSET + serving_cell['power'],
1907                self.MAX_ERROR_RSSI: 3,
1908                self.MAX_ERROR_AVERAGE_RSSI: 3
1909            },
1910            # Neighbor Cells
1911            {
1912                self.PSC: neighbor_cell_1[self.PSC],
1913                self.REPORT_RATE: 0.1,
1914                self.IS_REGISTERED: False,
1915                self.RAT: 'wcdma',
1916                self.TARGET_RSSI:
1917                self._WCDMA_RSSI_OFFSET + neighbor_cell_1['power'],
1918                self.MAX_ERROR_RSSI: 4,
1919                self.MAX_ERROR_AVERAGE_RSSI: 3
1920            }
1921        ]
1922        expected_cell_info_stats = {}
1923        for sample in expected_cell_info_list:
1924            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
1925
1926        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
1927        [bts1, bts2] = set_system_model_lte_wcdma(
1928            self.md8475a, self.user_params, self.ad.sim_card)
1929        self._setup_lte_cell_md8475a(bts1, serving_cell, serving_cell['power'])
1930        self._setup_wcdma_cell_md8475a(bts2, neighbor_cell_1,
1931                                       neighbor_cell_1['power'])
1932        bts1.neighbor_cell_mode = "USERDATA"
1933        bts1.set_neighbor_cell_type("WCDMA", 1, "CELLNAME")
1934        bts1.set_neighbor_cell_name("WCDMA", 1, "WCDM_1_C10700_F2140_CID31")
1935        set_usim_parameters(self.md8475a, self.ad.sim_card)
1936        self.md8475a.start_simulation()
1937        # To make sure phone camps on BTS1
1938        bts2.service_state = BtsServiceState.SERVICE_STATE_OUT
1939
1940        self.ad.droid.telephonyToggleDataConnection(False)
1941        if not ensure_network_rat(
1942                self.log,
1943                self.ad,
1944                NETWORK_MODE_LTE_GSM_WCDMA,
1945                RAT_FAMILY_LTE,
1946                toggle_apm_after_setting=True):
1947            self.log.error("Failed to set rat family {}, preferred network:{}".
1948                           format(RAT_FAMILY_LTE, NETWORK_MODE_LTE_GSM_WCDMA))
1949            return False
1950        self.md8475a.wait_for_registration_state()
1951        time.sleep(self._ANRITSU_SETTLING_TIME)
1952        self.md8475a.set_packet_preservation()
1953        time.sleep(self._SETTLING_TIME)
1954        return self._verify_cell_info(self.ad, expected_cell_info_stats)
1955
1956    @test_tracker_info(uuid="9be4e4a8-f79a-4283-9a85-371a9bddfa5d")
1957    @TelephonyBaseTest.tel_test_wrap
1958    def test_neighbor_cell_reporting_lte_interrat_2_tmo(self):
1959        """ Test Number of neighbor cells reported by Phone when two neighbor
1960        cells(inter RAT) are present (Phone camped on LTE)
1961
1962        Setup one LTE and one WCDMA cell configuration on MD8475A
1963        Setup one GSM waveform on MG3710A
1964        Make Sure Phone is in LTE mode
1965        Verify the number of neighbor cells reported by Phone
1966
1967        Returns:
1968            True if pass; False if fail
1969        """
1970        serving_cell = lte_band4_ch2000_fr2115_pcid1_cell
1971        neighbor_cell_1 = wcdma_band1_ch10700_fr2140_cid31_cell
1972        neighbor_cell_2 = gsm_band1900_ch512_fr1930_cid51_cell
1973        serving_cell['power'] = -20
1974        neighbor_cell_1['power'] = -24
1975        neighbor_cell_2['power'] = -22
1976        expected_cell_info_list = [
1977            # Serving Cell
1978            {
1979                self.CID: serving_cell[self.CID],
1980                self.PCID: serving_cell[self.PCID],
1981                self.REPORT_RATE: 1,
1982                self.IS_REGISTERED: True,
1983                self.RAT: 'lte',
1984                self.TARGET_RSSI:
1985                self._LTE_RSSI_OFFSET + serving_cell['power'],
1986                self.MAX_ERROR_RSSI: 3,
1987                self.MAX_ERROR_AVERAGE_RSSI: 3
1988            },
1989            # Neighbor Cells
1990            {
1991                self.PSC: neighbor_cell_1[self.PSC],
1992                self.REPORT_RATE: 0.1,
1993                self.IS_REGISTERED: False,
1994                self.RAT: 'wcdma',
1995                self.TARGET_RSSI:
1996                self._WCDMA_RSSI_OFFSET + neighbor_cell_1['power'],
1997                self.MAX_ERROR_RSSI: 4,
1998                self.MAX_ERROR_AVERAGE_RSSI: 3
1999            },
2000            {
2001                self.CID: neighbor_cell_2[self.CID],
2002                self.REPORT_RATE: 0.1,
2003                self.IS_REGISTERED: False,
2004                self.RAT: 'gsm',
2005                self.TARGET_RSSI:
2006                self._GSM_RSSI_OFFSET + neighbor_cell_2['power'],
2007                self.MAX_ERROR_RSSI: 4,
2008                self.MAX_ERROR_AVERAGE_RSSI: 3
2009            }
2010        ]
2011        expected_cell_info_stats = {}
2012        for sample in expected_cell_info_list:
2013            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
2014
2015        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
2016        [bts1, bts2] = set_system_model_lte_wcdma(
2017            self.md8475a, self.user_params, self.ad.sim_card)
2018        self._setup_lte_cell_md8475a(bts1, serving_cell, serving_cell['power'])
2019        self._setup_wcdma_cell_md8475a(bts2, neighbor_cell_1,
2020                                       neighbor_cell_1['power'])
2021        bts1.neighbor_cell_mode = "USERDATA"
2022        bts1.set_neighbor_cell_type("WCDMA", 1, "CELLNAME")
2023        bts1.set_neighbor_cell_name("WCDMA", 1, "WCDM_1_C10700_F2140_CID31")
2024        bts1.set_neighbor_cell_type("GSM", 1, "CELLNAME")
2025        bts1.set_neighbor_cell_name("GSM", 1, "GSM_1900_C512_F1930_CID51")
2026        set_usim_parameters(self.md8475a, self.ad.sim_card)
2027        self.md8475a.start_simulation()
2028        # To make sure phone camps on BTS1
2029        bts2.service_state = BtsServiceState.SERVICE_STATE_OUT
2030
2031        self.ad.droid.telephonyToggleDataConnection(False)
2032        if not ensure_network_rat(
2033                self.log,
2034                self.ad,
2035                NETWORK_MODE_LTE_GSM_WCDMA,
2036                RAT_FAMILY_LTE,
2037                toggle_apm_after_setting=True):
2038            self.log.error("Failed to set rat family {}, preferred network:{}".
2039                           format(RAT_FAMILY_LTE, NETWORK_MODE_LTE_GSM_WCDMA))
2040            return False
2041        self.md8475a.wait_for_registration_state()
2042        time.sleep(self._ANRITSU_SETTLING_TIME)
2043        bts2.service_state = BtsServiceState.SERVICE_STATE_IN
2044        self.setup_3710a_waveform("1", "A", "1930.2MHz",
2045                                  neighbor_cell_2['power'], "GSM",
2046                                  "gsm_lac51_cid51")
2047        self.turn_on_3710a_sg(1)
2048        time.sleep(self._ANRITSU_SETTLING_TIME)
2049        self.md8475a.set_packet_preservation()
2050        time.sleep(self._SETTLING_TIME)
2051        return self._verify_cell_info(self.ad, expected_cell_info_stats)
2052
2053    @test_tracker_info(uuid="14db7a3d-b18b-4b87-9d84-fb0c00d3971e")
2054    @TelephonyBaseTest.tel_test_wrap
2055    def test_neighbor_cell_reporting_wcdma_intrafreq_0_tmo(self):
2056        """ Test Number of neighbor cells reported by Phone when no neighbor
2057        cells are present (Phone camped on WCDMA)
2058
2059        Setup a single WCDMA cell configuration on MD8475A
2060        Make Sure Phone camped on WCDMA
2061        Verify the number of neighbor cells reported by Phone
2062
2063        Returns:
2064            True if pass; False if fail
2065        """
2066        serving_cell = wcdma_band1_ch10700_fr2140_cid31_cell
2067        serving_cell['power'] = -20
2068        expected_cell_info_list = [
2069            # Serving Cell
2070            {
2071                self.CID: serving_cell[self.CID],
2072                self.PSC: serving_cell[self.PSC],
2073                self.REPORT_RATE: 1,
2074                self.IS_REGISTERED: True,
2075                self.RAT: 'wcdma',
2076                self.TARGET_RSSI:
2077                self._WCDMA_RSSI_OFFSET + serving_cell['power'],
2078                self.MAX_ERROR_RSSI: 3,
2079                self.MAX_ERROR_AVERAGE_RSSI: 3
2080            }
2081        ]
2082        expected_cell_info_stats = {}
2083        for sample in expected_cell_info_list:
2084            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
2085
2086        [bts1] = set_system_model_wcdma(self.md8475a, self.user_params,
2087                                        self.ad.sim_card)
2088        self._setup_wcdma_cell_md8475a(bts1, serving_cell,
2089                                       serving_cell['power'])
2090        set_usim_parameters(self.md8475a, self.ad.sim_card)
2091        self.md8475a.start_simulation()
2092
2093        if not ensure_network_rat(
2094                self.log,
2095                self.ad,
2096                NETWORK_MODE_GSM_UMTS,
2097                RAT_FAMILY_UMTS,
2098                toggle_apm_after_setting=True):
2099            self.log.error("Failed to set rat family {}, preferred network:{}".
2100                           format(RAT_FAMILY_UMTS, NETWORK_MODE_GSM_UMTS))
2101            return False
2102        self.md8475a.wait_for_registration_state()
2103        time.sleep(self._SETTLING_TIME)
2104        return self._verify_cell_info(self.ad, expected_cell_info_stats)
2105
2106    @test_tracker_info(uuid="1a227d1e-9991-4646-b51a-8156f24485da")
2107    @TelephonyBaseTest.tel_test_wrap
2108    def test_neighbor_cell_reporting_wcdma_intrafreq_1_tmo(self):
2109        """ Test Number of neighbor cells reported by Phone when one neighbor
2110        cells is present (Phone camped on WCDMA)
2111
2112        Setup two WCDMA cell configuration on MD8475A
2113        Make Sure Phone camped on WCDMA
2114        Verify the number of neighbor cells reported by Phone
2115
2116        Returns:
2117            True if pass; False if fail
2118        """
2119        serving_cell = wcdma_band1_ch10700_fr2140_cid31_cell
2120        neighbor_cell = wcdma_band1_ch10700_fr2140_cid34_cell
2121        serving_cell['power'] = -20
2122        neighbor_cell['power'] = -24
2123        expected_cell_info_list = [
2124            # Serving Cell
2125            {
2126                self.CID: serving_cell[self.CID],
2127                self.PSC: serving_cell[self.PSC],
2128                self.REPORT_RATE: 1,
2129                self.IS_REGISTERED: True,
2130                self.RAT: 'wcdma',
2131                self.TARGET_RSSI:
2132                self._WCDMA_RSSI_OFFSET + serving_cell['power'],
2133                self.MAX_ERROR_RSSI: 3,
2134                self.MAX_ERROR_AVERAGE_RSSI: 3
2135            },
2136            # Neighbor Cells
2137            {
2138                self.PSC: neighbor_cell[self.PSC],
2139                self.REPORT_RATE: 0.1,
2140                self.IS_REGISTERED: False,
2141                self.RAT: 'wcdma',
2142                self.TARGET_RSSI:
2143                self._WCDMA_RSSI_OFFSET + neighbor_cell['power'],
2144                self.MAX_ERROR_RSSI: 4,
2145                self.MAX_ERROR_AVERAGE_RSSI: 3
2146            }
2147        ]
2148        expected_cell_info_stats = {}
2149        for sample in expected_cell_info_list:
2150            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
2151
2152        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
2153        [bts1, bts2] = set_system_model_wcdma_wcdma(
2154            self.md8475a, self.user_params, self.ad.sim_card)
2155        self._setup_wcdma_cell_md8475a(bts1, serving_cell,
2156                                       serving_cell['power'])
2157        self._setup_wcdma_cell_md8475a(bts2, neighbor_cell,
2158                                       neighbor_cell['power'])
2159        bts1.neighbor_cell_mode = "USERDATA"
2160        bts1.set_neighbor_cell_type("WCDMA", 1, "CELLNAME")
2161        bts1.set_neighbor_cell_name("WCDMA", 1, "WCDM_1_C10700_F2140_CID34")
2162        set_usim_parameters(self.md8475a, self.ad.sim_card)
2163        self.md8475a.start_simulation()
2164        # To make sure phone camps on BTS1
2165        bts2.service_state = BtsServiceState.SERVICE_STATE_OUT
2166
2167        if not ensure_network_rat(
2168                self.log,
2169                self.ad,
2170                NETWORK_MODE_GSM_UMTS,
2171                RAT_FAMILY_UMTS,
2172                toggle_apm_after_setting=True):
2173            self.log.error("Failed to set rat family {}, preferred network:{}".
2174                           format(RAT_FAMILY_UMTS, NETWORK_MODE_GSM_UMTS))
2175            return False
2176        self.md8475a.wait_for_registration_state()
2177        time.sleep(self._ANRITSU_SETTLING_TIME)
2178        bts2.service_state = BtsServiceState.SERVICE_STATE_IN
2179        time.sleep(self._SETTLING_TIME)
2180        return self._verify_cell_info(self.ad, expected_cell_info_stats)
2181
2182    @test_tracker_info(uuid="170689a0-0db1-4a14-8b87-5a1b6c9b8581")
2183    @TelephonyBaseTest.tel_test_wrap
2184    def test_neighbor_cell_reporting_wcdma_intrafreq_2_tmo(self):
2185        """ Test Number of neighbor cells reported by Phone when two neighbor
2186        cells are present (Phone camped on WCDMA)
2187
2188        Setup two WCDMA cell configuration on MD8475A
2189        Setup one WCDMA waveform on MG3710A
2190        Make Sure Phone camped on WCDMA
2191        Verify the number of neighbor cells reported by Phone
2192
2193        Returns:
2194            True if pass; False if fail
2195        """
2196        serving_cell = wcdma_band1_ch10700_fr2140_cid31_cell
2197        neighbor_cell_1 = wcdma_band1_ch10700_fr2140_cid32_cell
2198        neighbor_cell_2 = wcdma_band1_ch10700_fr2140_cid33_cell
2199        serving_cell['power'] = -20
2200        neighbor_cell_1['power'] = -24
2201        neighbor_cell_2['power'] = -22
2202        expected_cell_info_list = [
2203            # Serving Cell
2204            {
2205                self.CID: serving_cell[self.CID],
2206                self.PSC: serving_cell[self.PSC],
2207                self.REPORT_RATE: 1,
2208                self.IS_REGISTERED: True,
2209                self.RAT: 'wcdma',
2210                self.TARGET_RSSI:
2211                self._WCDMA_RSSI_OFFSET + serving_cell['power'],
2212                self.MAX_ERROR_RSSI: 3,
2213                self.MAX_ERROR_AVERAGE_RSSI: 3
2214            },
2215            # Neighbor Cells
2216            {
2217                self.PSC: neighbor_cell_1[self.PSC],
2218                self.REPORT_RATE: 0.1,
2219                self.IS_REGISTERED: False,
2220                self.RAT: 'wcdma',
2221                self.TARGET_RSSI:
2222                self._WCDMA_RSSI_OFFSET + neighbor_cell_1['power'],
2223                self.MAX_ERROR_RSSI: 4,
2224                self.MAX_ERROR_AVERAGE_RSSI: 3
2225            },
2226            {
2227                self.PSC: neighbor_cell_2[self.PSC],
2228                self.REPORT_RATE: 0.1,
2229                self.IS_REGISTERED: False,
2230                self.RAT: 'wcdma',
2231                self.TARGET_RSSI:
2232                self._WCDMA_RSSI_OFFSET + neighbor_cell_2['power'],
2233                self.MAX_ERROR_RSSI: 4,
2234                self.MAX_ERROR_AVERAGE_RSSI: 3
2235            }
2236        ]
2237        expected_cell_info_stats = {}
2238        for sample in expected_cell_info_list:
2239            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
2240
2241        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
2242        [bts1, bts2] = set_system_model_wcdma_wcdma(
2243            self.md8475a, self.user_params, self.ad.sim_card)
2244        self._setup_wcdma_cell_md8475a(bts1, serving_cell,
2245                                       serving_cell['power'])
2246        self._setup_wcdma_cell_md8475a(bts2, neighbor_cell_1,
2247                                       neighbor_cell_1['power'])
2248        bts1.neighbor_cell_mode = "USERDATA"
2249        bts1.set_neighbor_cell_type("WCDMA", 1, "CELLNAME")
2250        bts1.set_neighbor_cell_name("WCDMA", 1, "WCDM_1_C10700_F2140_CID32")
2251        bts1.set_neighbor_cell_type("WCDMA", 2, "CELLNAME")
2252        bts1.set_neighbor_cell_name("WCDMA", 2, "WCDM_1_C10700_F2140_CID33")
2253        set_usim_parameters(self.md8475a, self.ad.sim_card)
2254        self.md8475a.start_simulation()
2255        # To make sure phone camps on BTS1
2256        bts2.service_state = BtsServiceState.SERVICE_STATE_OUT
2257
2258        if not ensure_network_rat(
2259                self.log,
2260                self.ad,
2261                NETWORK_MODE_GSM_UMTS,
2262                RAT_FAMILY_UMTS,
2263                toggle_apm_after_setting=True):
2264            self.log.error("Failed to set rat family {}, preferred network:{}".
2265                           format(RAT_FAMILY_UMTS, NETWORK_MODE_GSM_UMTS))
2266            return False
2267        self.md8475a.wait_for_registration_state()
2268        time.sleep(self._ANRITSU_SETTLING_TIME)
2269        bts2.service_state = BtsServiceState.SERVICE_STATE_IN
2270        self.setup_3710a_waveform("1", "A", "2140MHz",
2271                                  neighbor_cell_2['power'], "WCDMA",
2272                                  "wcdma_1_psc33_cid33")
2273        self.turn_on_3710a_sg(1)
2274        time.sleep(self._SETTLING_TIME)
2275        return self._verify_cell_info(self.ad, expected_cell_info_stats)
2276
2277    @test_tracker_info(uuid="3ec77512-4d5b-40c9-b733-cf358f999e15")
2278    @TelephonyBaseTest.tel_test_wrap
2279    def test_neighbor_cell_reporting_wcdma_intrafreq_3_tmo(self):
2280        """ Test Number of neighbor cells reported by Phone when three neighbor
2281        cells are present (Phone camped on WCDMA)
2282
2283        Setup two WCDMA cell configuration on MD8475A
2284        Setup two WCDMA waveform on MG3710A
2285        Make Sure Phone camped on WCDMA
2286        Verify the number of neighbor cells reported by Phone
2287
2288        Returns:
2289            True if pass; False if fail
2290        """
2291        serving_cell = wcdma_band1_ch10700_fr2140_cid31_cell
2292        neighbor_cell_1 = wcdma_band1_ch10700_fr2140_cid32_cell
2293        neighbor_cell_2 = wcdma_band1_ch10700_fr2140_cid33_cell
2294        neighbor_cell_3 = wcdma_band1_ch10700_fr2140_cid34_cell
2295        serving_cell['power'] = -20
2296        neighbor_cell_1['power'] = -24
2297        neighbor_cell_2['power'] = -23
2298        neighbor_cell_3['power'] = -22
2299
2300        expected_cell_info_list = [
2301            # Serving Cell
2302            {
2303                self.CID: serving_cell[self.CID],
2304                self.PSC: serving_cell[self.PSC],
2305                self.REPORT_RATE: 1,
2306                self.IS_REGISTERED: True,
2307                self.RAT: 'wcdma',
2308                self.TARGET_RSSI:
2309                self._WCDMA_RSSI_OFFSET + serving_cell['power'],
2310                self.MAX_ERROR_RSSI: 3,
2311                self.MAX_ERROR_AVERAGE_RSSI: 3
2312            },
2313            # Neighbor Cells
2314            {
2315                self.PSC: neighbor_cell_1[self.PSC],
2316                self.REPORT_RATE: 0.1,
2317                self.IS_REGISTERED: False,
2318                self.RAT: 'wcdma',
2319                self.TARGET_RSSI:
2320                self._WCDMA_RSSI_OFFSET + neighbor_cell_1['power'],
2321                self.MAX_ERROR_RSSI: 4,
2322                self.MAX_ERROR_AVERAGE_RSSI: 3
2323            },
2324            {
2325                self.PSC: neighbor_cell_2[self.PSC],
2326                self.REPORT_RATE: 0.1,
2327                self.IS_REGISTERED: False,
2328                self.RAT: 'wcdma',
2329                self.TARGET_RSSI:
2330                self._WCDMA_RSSI_OFFSET + neighbor_cell_2['power'],
2331                self.MAX_ERROR_RSSI: 4,
2332                self.MAX_ERROR_AVERAGE_RSSI: 3
2333            },
2334            {
2335                self.PSC: neighbor_cell_3[self.PSC],
2336                self.REPORT_RATE: 0.1,
2337                self.IS_REGISTERED: False,
2338                self.RAT: 'wcdma',
2339                self.TARGET_RSSI:
2340                self._WCDMA_RSSI_OFFSET + neighbor_cell_3['power'],
2341                self.MAX_ERROR_RSSI: 4,
2342                self.MAX_ERROR_AVERAGE_RSSI: 3
2343            }
2344        ]
2345        expected_cell_info_stats = {}
2346        for sample in expected_cell_info_list:
2347            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
2348
2349        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
2350        [bts1, bts2] = set_system_model_wcdma_wcdma(
2351            self.md8475a, self.user_params, self.ad.sim_card)
2352        self._setup_wcdma_cell_md8475a(bts1, serving_cell,
2353                                       serving_cell['power'])
2354        self._setup_wcdma_cell_md8475a(bts2, neighbor_cell_1,
2355                                       neighbor_cell_1['power'])
2356        bts1.neighbor_cell_mode = "USERDATA"
2357        bts1.set_neighbor_cell_type("WCDMA", 1, "CELLNAME")
2358        bts1.set_neighbor_cell_name("WCDMA", 1, "WCDM_1_C10700_F2140_CID32")
2359        bts1.set_neighbor_cell_type("WCDMA", 2, "CELLNAME")
2360        bts1.set_neighbor_cell_name("WCDMA", 2, "WCDM_1_C10700_F2140_CID33")
2361        bts1.set_neighbor_cell_type("WCDMA", 3, "CELLNAME")
2362        bts1.set_neighbor_cell_name("WCDMA", 3, "WCDM_1_C10700_F2140_CID34")
2363        set_usim_parameters(self.md8475a, self.ad.sim_card)
2364        self.md8475a.start_simulation()
2365        # To make sure phone camps on BTS1
2366        bts2.service_state = BtsServiceState.SERVICE_STATE_OUT
2367
2368        if not ensure_network_rat(
2369                self.log,
2370                self.ad,
2371                NETWORK_MODE_GSM_UMTS,
2372                RAT_FAMILY_UMTS,
2373                toggle_apm_after_setting=True):
2374            self.log.error("Failed to set rat family {}, preferred network:{}".
2375                           format(RAT_FAMILY_UMTS, NETWORK_MODE_GSM_UMTS))
2376            return False
2377        self.md8475a.wait_for_registration_state()
2378        time.sleep(self._ANRITSU_SETTLING_TIME)
2379        bts2.service_state = BtsServiceState.SERVICE_STATE_IN
2380        self.setup_3710a_waveform("1", "A", "2140MHz",
2381                                  neighbor_cell_2['power'], "WCDMA",
2382                                  "wcdma_1_psc33_cid33")
2383
2384        self.setup_3710a_waveform("2", "A", "2140MHz",
2385                                  neighbor_cell_3['power'], "WCDMA",
2386                                  "wcdma_1_psc34_cid34")
2387        self.turn_on_3710a_sg(1)
2388        self.turn_on_3710a_sg(2)
2389        time.sleep(self._SETTLING_TIME)
2390        return self._verify_cell_info(self.ad, expected_cell_info_stats)
2391
2392    @test_tracker_info(uuid="6f39e4a5-81da-4f47-8022-f22d82ff6f31")
2393    @TelephonyBaseTest.tel_test_wrap
2394    def test_neighbor_cell_reporting_wcdma_interfreq_1_tmo(self):
2395        """ Test Number of neighbor cells reported by Phone when two neighbor
2396        cells(inter frequency) are present (Phone camped on WCDMA)
2397
2398        Setup a two WCDMA cell configuration on MD8475A
2399        Setup one WCDMA waveform on MG3710A
2400        Make Sure Phone camped on WCDMA
2401        Verify the number of neighbor cells reported by Phonene
2402
2403        Returns:
2404            True if pass; False if fail
2405        """
2406        serving_cell = wcdma_band1_ch10700_fr2140_cid31_cell
2407        neighbor_cell_1 = wcdma_band1_ch10800_fr2160_cid37_cell
2408        serving_cell['power'] = -20
2409        neighbor_cell_1['power'] = -24
2410
2411        expected_cell_info_list = [
2412            # Serving Cell
2413            {
2414                self.CID: serving_cell[self.CID],
2415                self.PSC: serving_cell[self.PSC],
2416                self.REPORT_RATE: 1,
2417                self.IS_REGISTERED: True,
2418                self.RAT: 'wcdma',
2419                self.TARGET_RSSI:
2420                self._WCDMA_RSSI_OFFSET + serving_cell['power'],
2421                self.MAX_ERROR_RSSI: 3,
2422                self.MAX_ERROR_AVERAGE_RSSI: 3
2423            },
2424            # Neighbor Cells
2425            {
2426                self.PSC: neighbor_cell_1[self.PSC],
2427                self.REPORT_RATE: 0.1,
2428                self.IS_REGISTERED: False,
2429                self.RAT: 'wcdma',
2430                self.TARGET_RSSI:
2431                self._WCDMA_RSSI_OFFSET + neighbor_cell_1['power'],
2432                self.MAX_ERROR_RSSI: 4,
2433                self.MAX_ERROR_AVERAGE_RSSI: 3
2434            }
2435        ]
2436        expected_cell_info_stats = {}
2437        for sample in expected_cell_info_list:
2438            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
2439
2440        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
2441        [bts1, bts2] = set_system_model_wcdma_wcdma(
2442            self.md8475a, self.user_params, self.ad.sim_card)
2443        self._setup_wcdma_cell_md8475a(bts1, serving_cell,
2444                                       serving_cell['power'])
2445        self._setup_wcdma_cell_md8475a(bts2, neighbor_cell_1,
2446                                       neighbor_cell_1['power'])
2447        bts1.neighbor_cell_mode = "USERDATA"
2448        bts1.set_neighbor_cell_type("WCDMA", 1, "CELLNAME")
2449        bts1.set_neighbor_cell_name("WCDMA", 1, "WCDM_1_C10800_F2160_CID37")
2450        set_usim_parameters(self.md8475a, self.ad.sim_card)
2451        self.md8475a.start_simulation()
2452        #To make sure phone camps on BTS1
2453        bts2.service_state = BtsServiceState.SERVICE_STATE_OUT
2454
2455        self.ad.droid.telephonyToggleDataConnection(False)
2456        if not ensure_network_rat(
2457                self.log,
2458                self.ad,
2459                NETWORK_MODE_GSM_UMTS,
2460                RAT_FAMILY_UMTS,
2461                toggle_apm_after_setting=True):
2462            self.log.error("Failed to set rat family {}, preferred network:{}".
2463                           format(RAT_FAMILY_UMTS, NETWORK_MODE_GSM_UMTS))
2464            return False
2465        self.md8475a.wait_for_registration_state()
2466        time.sleep(self._ANRITSU_SETTLING_TIME)
2467        bts2.service_state = BtsServiceState.SERVICE_STATE_IN
2468        time.sleep(self._SETTLING_TIME)
2469        return self._verify_cell_info(self.ad, expected_cell_info_stats)
2470
2471    @test_tracker_info(uuid="992d9ffb-2538-447b-b7e8-f40061063686")
2472    @TelephonyBaseTest.tel_test_wrap
2473    def test_neighbor_cell_reporting_wcdma_interfreq_2_tmo(self):
2474        """ Test Number of neighbor cells reported by Phone when two neighbor
2475        cells(inter frequency) are present (Phone camped on WCDMA)
2476
2477        Setup a two WCDMA cell configuration on MD8475A
2478        Setup one WCDMA waveform on MG3710A
2479        Make Sure Phone camped on WCDMA
2480        Verify the number of neighbor cells reported by Phonene
2481
2482        Returns:
2483            True if pass; False if fail
2484        """
2485        serving_cell = wcdma_band1_ch10700_fr2140_cid31_cell
2486        neighbor_cell_1 = wcdma_band1_ch10575_fr2115_cid36_cell
2487        neighbor_cell_2 = wcdma_band1_ch10800_fr2160_cid37_cell
2488        serving_cell['power'] = -20
2489        neighbor_cell_1['power'] = -24
2490        neighbor_cell_2['power'] = -23
2491        expected_cell_info_list = [
2492            # Serving Cell
2493            {
2494                self.CID: serving_cell[self.CID],
2495                self.PSC: serving_cell[self.PSC],
2496                self.REPORT_RATE: 1,
2497                self.IS_REGISTERED: True,
2498                self.RAT: 'wcdma',
2499                self.TARGET_RSSI:
2500                self._WCDMA_RSSI_OFFSET + serving_cell['power'],
2501                self.MAX_ERROR_RSSI: 3,
2502                self.MAX_ERROR_AVERAGE_RSSI: 3
2503            },
2504            # Neighbor Cells
2505            {
2506                self.PSC: neighbor_cell_1[self.PSC],
2507                self.REPORT_RATE: 0.1,
2508                self.IS_REGISTERED: False,
2509                self.RAT: 'wcdma',
2510                self.TARGET_RSSI:
2511                self._WCDMA_RSSI_OFFSET + neighbor_cell_1['power'],
2512                self.MAX_ERROR_RSSI: 4,
2513                self.MAX_ERROR_AVERAGE_RSSI: 3
2514            },
2515            {
2516                self.PSC: neighbor_cell_2[self.PSC],
2517                self.REPORT_RATE: 0.1,
2518                self.IS_REGISTERED: False,
2519                self.RAT: 'wcdma',
2520                self.TARGET_RSSI:
2521                self._WCDMA_RSSI_OFFSET + neighbor_cell_2['power'],
2522                self.MAX_ERROR_RSSI: 4,
2523                self.MAX_ERROR_AVERAGE_RSSI: 3
2524            }
2525        ]
2526        expected_cell_info_stats = {}
2527        for sample in expected_cell_info_list:
2528            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
2529
2530        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
2531        [bts1, bts2] = set_system_model_wcdma_wcdma(
2532            self.md8475a, self.user_params, self.ad.sim_card)
2533        self._setup_wcdma_cell_md8475a(bts1, serving_cell,
2534                                       serving_cell['power'])
2535        self._setup_wcdma_cell_md8475a(bts2, neighbor_cell_1,
2536                                       neighbor_cell_1['power'])
2537        bts1.neighbor_cell_mode = "USERDATA"
2538        bts1.set_neighbor_cell_type("WCDMA", 1, "CELLNAME")
2539        bts1.set_neighbor_cell_name("WCDMA", 1, "WCDM_1_C10575_F2115_CID36")
2540        bts1.set_neighbor_cell_type("WCDMA", 2, "CELLNAME")
2541        bts1.set_neighbor_cell_name("WCDMA", 2, "WCDM_1_C10800_F2160_CID37")
2542        set_usim_parameters(self.md8475a, self.ad.sim_card)
2543        self.md8475a.start_simulation()
2544        # To make sure phone camps on BTS1
2545        bts2.service_state = BtsServiceState.SERVICE_STATE_OUT
2546
2547        self.ad.droid.telephonyToggleDataConnection(False)
2548        if not ensure_network_rat(
2549                self.log,
2550                self.ad,
2551                NETWORK_MODE_GSM_UMTS,
2552                RAT_FAMILY_UMTS,
2553                toggle_apm_after_setting=True):
2554            self.log.error("Failed to set rat family {}, preferred network:{}".
2555                           format(RAT_FAMILY_UMTS, NETWORK_MODE_GSM_UMTS))
2556            return False
2557        self.md8475a.wait_for_registration_state()
2558        time.sleep(self._ANRITSU_SETTLING_TIME)
2559        bts2.service_state = BtsServiceState.SERVICE_STATE_IN
2560        self.setup_3710a_waveform("1", "A", "2160MHz",
2561                                  neighbor_cell_2['power'], "WCDMA",
2562                                  "wcdma_1_psc37_cid37")
2563        self.turn_on_3710a_sg(1)
2564        time.sleep(self._SETTLING_TIME)
2565        return self._verify_cell_info(self.ad, expected_cell_info_stats)
2566
2567    @test_tracker_info(uuid="60cb8c15-3cb3-4ead-9e59-a8aee819e9ef")
2568    @TelephonyBaseTest.tel_test_wrap
2569    def test_neighbor_cell_reporting_wcdma_interband_2_tmo(self):
2570        """ Test Number of neighbor cells reported by Phone when two neighbor
2571        cells(inter band) are present (Phone camped on WCDMA)
2572
2573        Setup a two WCDMA cell configuration on MD8475A
2574        Setup one WCDMA waveform on MG3710A
2575        Make Sure Phone camped on WCDMA
2576        Verify the number of neighbor cells reported by Phone
2577
2578        Returns:
2579            True if pass; False if fail
2580        """
2581        serving_cell = wcdma_band1_ch10700_fr2140_cid31_cell
2582        neighbor_cell_1 = wcdma_band2_ch9800_fr1960_cid38_cell
2583        neighbor_cell_2 = wcdma_band2_ch9900_fr1980_cid39_cell
2584        serving_cell['power'] = -20
2585        neighbor_cell_1['power'] = -23
2586        neighbor_cell_2['power'] = -22
2587
2588        expected_cell_info_list = [
2589            # Serving Cell
2590            {
2591                self.CID: serving_cell[self.CID],
2592                self.PSC: serving_cell[self.PSC],
2593                self.REPORT_RATE: 1,
2594                self.IS_REGISTERED: True,
2595                self.RAT: 'wcdma',
2596                self.TARGET_RSSI:
2597                self._WCDMA_RSSI_OFFSET + serving_cell['power'],
2598                self.MAX_ERROR_RSSI: 3,
2599                self.MAX_ERROR_AVERAGE_RSSI: 3
2600            },
2601            # Neighbor Cells
2602            {
2603                self.PSC: neighbor_cell_1[self.PSC],
2604                self.REPORT_RATE: 0.1,
2605                self.IS_REGISTERED: False,
2606                self.RAT: 'wcdma',
2607                self.TARGET_RSSI:
2608                self._WCDMA_RSSI_OFFSET + neighbor_cell_1['power'],
2609                self.MAX_ERROR_RSSI: 4,
2610                self.MAX_ERROR_AVERAGE_RSSI: 3
2611            },
2612            {
2613                self.PSC: neighbor_cell_2[self.PSC],
2614                self.REPORT_RATE: 0.1,
2615                self.IS_REGISTERED: False,
2616                self.RAT: 'wcdma',
2617                self.TARGET_RSSI:
2618                self._WCDMA_RSSI_OFFSET + neighbor_cell_2['power'],
2619                self.MAX_ERROR_RSSI: 4,
2620                self.MAX_ERROR_AVERAGE_RSSI: 3
2621            }
2622        ]
2623        expected_cell_info_stats = {}
2624        for sample in expected_cell_info_list:
2625            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
2626
2627        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
2628        [bts1, bts2] = set_system_model_wcdma_wcdma(
2629            self.md8475a, self.user_params, self.ad.sim_card)
2630        self._setup_wcdma_cell_md8475a(bts1, serving_cell,
2631                                       serving_cell['power'])
2632        self._setup_wcdma_cell_md8475a(bts2, neighbor_cell_1,
2633                                       neighbor_cell_1['power'])
2634        bts1.neighbor_cell_mode = "USERDATA"
2635        bts1.set_neighbor_cell_type("WCDMA", 1, "CELLNAME")
2636        bts1.set_neighbor_cell_name("WCDMA", 1, "WCDM_2_C9800_F1960_CID38")
2637        bts1.set_neighbor_cell_type("WCDMA", 2, "CELLNAME")
2638        bts1.set_neighbor_cell_name("WCDMA", 2, "WCDM_2_C9900_F1980_CID39")
2639        set_usim_parameters(self.md8475a, self.ad.sim_card)
2640        self.md8475a.start_simulation()
2641        # To make sure phone camps on BTS1
2642        bts2.service_state = BtsServiceState.SERVICE_STATE_OUT
2643
2644        self.ad.droid.telephonyToggleDataConnection(False)
2645        if not ensure_network_rat(
2646                self.log,
2647                self.ad,
2648                NETWORK_MODE_GSM_UMTS,
2649                RAT_FAMILY_UMTS,
2650                toggle_apm_after_setting=True):
2651            self.log.error("Failed to set rat family {}, preferred network:{}".
2652                           format(RAT_FAMILY_UMTS, NETWORK_MODE_GSM_UMTS))
2653            return False
2654        self.md8475a.wait_for_registration_state()
2655        time.sleep(self._ANRITSU_SETTLING_TIME)
2656        bts2.service_state = BtsServiceState.SERVICE_STATE_IN
2657        self.setup_3710a_waveform("1", "A", "1980MHz",
2658                                  neighbor_cell_2['power'], "WCDMA",
2659                                  "wcdma_2_psc39_cid39")
2660        self.turn_on_3710a_sg(1)
2661        time.sleep(self._SETTLING_TIME)
2662        return self._verify_cell_info(self.ad, expected_cell_info_stats)
2663
2664    @test_tracker_info(uuid="daa29f27-f67b-47ee-9a30-1c9572eedf2f")
2665    @TelephonyBaseTest.tel_test_wrap
2666    def test_neighbor_cell_reporting_wcdma_interrat_1_tmo(self):
2667        """ Test Number of neighbor cells reported by Phone when two neighbor
2668        cells are present (Phone camped on WCDMA)
2669
2670        Setup a two WCDMA cell configuration on MD8475A
2671        Setup one WCDMA waveform on MG3710A
2672        Make Sure Phone camped on WCDMA
2673        Verify the number of neighbor cells reported by Phone
2674
2675        Returns:
2676            True if pass; False if fail
2677        """
2678        serving_cell = wcdma_band1_ch10700_fr2140_cid31_cell
2679        neighbor_cell_1 = gsm_band1900_ch512_fr1930_cid51_cell
2680        neighbor_cell_2 = lte_band4_ch2000_fr2115_pcid1_cell
2681        serving_cell['power'] = -20
2682        neighbor_cell_1['power'] = -23
2683        neighbor_cell_2['power'] = -22
2684
2685        expected_cell_info_list = [
2686            # Serving Cell
2687            {
2688                self.CID: serving_cell[self.CID],
2689                self.PSC: serving_cell[self.PSC],
2690                self.REPORT_RATE: 1,
2691                self.IS_REGISTERED: True,
2692                self.RAT: 'wcdma',
2693                self.TARGET_RSSI:
2694                self._WCDMA_RSSI_OFFSET + serving_cell['power'],
2695                self.MAX_ERROR_RSSI: 3,
2696                self.MAX_ERROR_AVERAGE_RSSI: 3
2697            },
2698            # Neighbor Cells
2699            {
2700                self.CID: neighbor_cell_1[self.CID],
2701                self.REPORT_RATE: 0.1,
2702                self.IS_REGISTERED: False,
2703                self.RAT: 'gsm',
2704                self.TARGET_RSSI:
2705                self._GSM_RSSI_OFFSET + neighbor_cell_1['power'],
2706                self.MAX_ERROR_RSSI: 4,
2707                self.MAX_ERROR_AVERAGE_RSSI: 3
2708            },
2709            {
2710                self.PCID: neighbor_cell_2[self.PCID],
2711                self.REPORT_RATE: 0.1,
2712                self.IS_REGISTERED: False,
2713                self.RAT: 'lte',
2714                self.TARGET_RSSI:
2715                self._LTE_RSSI_OFFSET + neighbor_cell_2['power'],
2716                self.MAX_ERROR_RSSI: 4,
2717                self.MAX_ERROR_AVERAGE_RSSI: 3
2718            }
2719        ]
2720        expected_cell_info_stats = {}
2721        for sample in expected_cell_info_list:
2722            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
2723
2724        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
2725        [bts1, bts2] = set_system_model_lte_wcdma(
2726            self.md8475a, self.user_params, self.ad.sim_card)
2727        self._setup_wcdma_cell_md8475a(bts2, serving_cell,
2728                                       serving_cell['power'])
2729        self._setup_lte_cell_md8475a(bts1, neighbor_cell_2,
2730                                     neighbor_cell_2['power'])
2731        bts2.neighbor_cell_mode = "USERDATA"
2732        bts2.set_neighbor_cell_type("LTE", 1, "CELLNAME")
2733        bts2.set_neighbor_cell_name("LTE", 1, "LTE_4_C2000_F2115_PCID1")
2734        set_usim_parameters(self.md8475a, self.ad.sim_card)
2735        self.md8475a.start_simulation()
2736        # To make sure phone camps on BTS1
2737        bts1.service_state = BtsServiceState.SERVICE_STATE_OUT
2738
2739        self.ad.droid.telephonyToggleDataConnection(False)
2740        if not ensure_network_rat(
2741                self.log,
2742                self.ad,
2743                NETWORK_MODE_GSM_UMTS,
2744                RAT_FAMILY_UMTS,
2745                toggle_apm_after_setting=True):
2746            self.log.error("Failed to set rat family {}, preferred network:{}".
2747                           format(RAT_FAMILY_UMTS, NETWORK_MODE_GSM_UMTS))
2748            return False
2749        self.md8475a.wait_for_registration_state()
2750        time.sleep(self._ANRITSU_SETTLING_TIME)
2751        bts1.service_state = BtsServiceState.SERVICE_STATE_IN
2752        time.sleep(self._SETTLING_TIME)
2753        return self._verify_cell_info(self.ad, expected_cell_info_stats)
2754
2755    @test_tracker_info(uuid="08e5d666-fae6-48a3-b03b-de7b7b3f5982")
2756    @TelephonyBaseTest.tel_test_wrap
2757    def test_neighbor_cell_reporting_wcdma_interrat_2_tmo(self):
2758        """ Test Number of neighbor cells reported by Phone when two neighbor
2759        cells are present (Phone camped on WCDMA)
2760
2761        Setup a two WCDMA cell configuration on MD8475A
2762        Setup one WCDMA waveform on MG3710A
2763        Make Sure Phone camped on WCDMA
2764        Verify the number of neighbor cells reported by Phone
2765
2766        Returns:
2767            True if pass; False if fail
2768        """
2769        serving_cell = wcdma_band1_ch10700_fr2140_cid31_cell
2770        neighbor_cell_1 = gsm_band1900_ch512_fr1930_cid51_cell
2771        neighbor_cell_2 = lte_band4_ch2000_fr2115_pcid1_cell
2772        serving_cell['power'] = -20
2773        neighbor_cell_1['power'] = -23
2774        neighbor_cell_2['power'] = -22
2775
2776        expected_cell_info_list = [
2777            # Serving Cell
2778            {
2779                self.CID: serving_cell[self.CID],
2780                self.PSC: serving_cell[self.PSC],
2781                self.REPORT_RATE: 1,
2782                self.IS_REGISTERED: True,
2783                self.RAT: 'wcdma',
2784                self.TARGET_RSSI:
2785                self._WCDMA_RSSI_OFFSET + serving_cell['power'],
2786                self.MAX_ERROR_RSSI: 3,
2787                self.MAX_ERROR_AVERAGE_RSSI: 3
2788            },
2789            # Neighbor Cells
2790            {
2791                self.CID: neighbor_cell_1[self.CID],
2792                self.REPORT_RATE: 0.1,
2793                self.IS_REGISTERED: False,
2794                self.RAT: 'gsm',
2795                self.TARGET_RSSI:
2796                self._GSM_RSSI_OFFSET + neighbor_cell_1['power'],
2797                self.MAX_ERROR_RSSI: 4,
2798                self.MAX_ERROR_AVERAGE_RSSI: 3
2799            },
2800            {
2801                self.PCID: neighbor_cell_2[self.PCID],
2802                self.REPORT_RATE: 0.1,
2803                self.IS_REGISTERED: False,
2804                self.RAT: 'lte',
2805                self.TARGET_RSSI:
2806                self._LTE_RSSI_OFFSET + neighbor_cell_2['power'],
2807                self.MAX_ERROR_RSSI: 4,
2808                self.MAX_ERROR_AVERAGE_RSSI: 3
2809            }
2810        ]
2811        expected_cell_info_stats = {}
2812        for sample in expected_cell_info_list:
2813            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
2814
2815        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
2816        [bts1, bts2] = set_system_model_wcdma_gsm(
2817            self.md8475a, self.user_params, self.ad.sim_card)
2818        self._setup_wcdma_cell_md8475a(bts1, serving_cell,
2819                                       serving_cell['power'])
2820        self._setup_gsm_cell_md8475a(bts2, neighbor_cell_1,
2821                                     neighbor_cell_1['power'])
2822        bts1.neighbor_cell_mode = "USERDATA"
2823        bts1.set_neighbor_cell_type("GSM", 1, "CELLNAME")
2824        bts1.set_neighbor_cell_name("GSM", 1, "GSM_1900_C512_F1930_CID51")
2825        bts1.set_neighbor_cell_type("LTE", 1, "CELLNAME")
2826        bts1.set_neighbor_cell_name("LTE", 1, "LTE_4_C2000_F2115_PCID1")
2827        set_usim_parameters(self.md8475a, self.ad.sim_card)
2828        self.md8475a.start_simulation()
2829        # To make sure phone camps on BTS1
2830        bts2.service_state = BtsServiceState.SERVICE_STATE_OUT
2831
2832        self.ad.droid.telephonyToggleDataConnection(False)
2833        if not ensure_network_rat(
2834                self.log,
2835                self.ad,
2836                NETWORK_MODE_GSM_UMTS,
2837                RAT_FAMILY_UMTS,
2838                toggle_apm_after_setting=True):
2839            self.log.error("Failed to set rat family {}, preferred network:{}".
2840                           format(RAT_FAMILY_UMTS, NETWORK_MODE_GSM_UMTS))
2841            return False
2842        self.md8475a.wait_for_registration_state()
2843        time.sleep(self._ANRITSU_SETTLING_TIME)
2844        bts2.service_state = BtsServiceState.SERVICE_STATE_IN
2845        self.setup_3710a_waveform("1", "A", "2115MHz",
2846                                  neighbor_cell_2['power'], "LTE",
2847                                  "lte_4_ch2000_pcid1")
2848        self.turn_on_3710a_sg(1)
2849        time.sleep(self._SETTLING_TIME)
2850        return self._verify_cell_info(self.ad, expected_cell_info_stats)
2851
2852    @test_tracker_info(uuid="bebbe764-4c8c-4aaf-81b9-c61509a9695e")
2853    @TelephonyBaseTest.tel_test_wrap
2854    def test_neighbor_cell_reporting_gsm_intrafreq_0_tmo(self):
2855        """ Test Number of neighbor cells reported by Phone when no neighbor
2856        cells are present (Phone camped on GSM)
2857
2858        Setup one GSM cell configuration on MD8475A
2859        Make Sure Phone camped on GSM
2860        Verify the number of neighbor cells reported by Phone
2861
2862        Returns:
2863            True if pass; False if fail
2864        """
2865        serving_cell = gsm_band1900_ch512_fr1930_cid51_cell
2866        serving_cell['power'] = -30
2867
2868        expected_cell_info_list = [
2869            # Serving Cell
2870            {
2871                self.CID: serving_cell[self.CID],
2872                self.REPORT_RATE: 1,
2873                self.IS_REGISTERED: True,
2874                self.RAT: 'gsm',
2875                self.TARGET_RSSI:
2876                self._GSM_RSSI_OFFSET + serving_cell['power'],
2877                self.MAX_ERROR_RSSI: 3,
2878                self.MAX_ERROR_AVERAGE_RSSI: 3
2879            }
2880        ]
2881        expected_cell_info_stats = {}
2882        for sample in expected_cell_info_list:
2883            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
2884
2885        [bts1] = set_system_model_gsm(self.md8475a, self.user_params,
2886                                      self.ad.sim_card)
2887        self._setup_gsm_cell_md8475a(bts1, serving_cell, serving_cell['power'])
2888        set_usim_parameters(self.md8475a, self.ad.sim_card)
2889        self.md8475a.start_simulation()
2890        if not ensure_network_rat(
2891                self.log,
2892                self.ad,
2893                NETWORK_MODE_GSM_ONLY,
2894                RAT_FAMILY_GSM,
2895                toggle_apm_after_setting=True):
2896            self.log.error("Failed to set rat family {}, preferred network:{}".
2897                           format(RAT_FAMILY_GSM, NETWORK_MODE_GSM_ONLY))
2898            return False
2899        self.md8475a.wait_for_registration_state()
2900        time.sleep(self._SETTLING_TIME)
2901        return self._verify_cell_info(self.ad, expected_cell_info_stats)
2902
2903    @test_tracker_info(uuid="861dd399-d6f6-4e9f-9e8d-0718966ea45a")
2904    @TelephonyBaseTest.tel_test_wrap
2905    def test_neighbor_cell_reporting_gsm_intrafreq_1_tmo(self):
2906        """ Test Number of neighbor cells reported by Phone when one neighbor
2907        cell is present (Phone camped on GSM)
2908
2909        Setup one GSM cell configuration on MD8475A
2910        Make Sure Phone camped on GSM
2911        Verify the number of neighbor cells reported by Phone
2912
2913        Returns:
2914            True if pass; False if fail
2915        """
2916        serving_cell = gsm_band1900_ch512_fr1930_cid51_cell
2917        neighbor_cell = gsm_band1900_ch512_fr1930_cid52_cell
2918        serving_cell['power'] = -20
2919        neighbor_cell['power'] = -22
2920
2921        expected_cell_info_list = [
2922            # Serving Cell
2923            {
2924                self.CID: serving_cell[self.CID],
2925                self.REPORT_RATE: 1,
2926                self.IS_REGISTERED: True,
2927                self.RAT: 'gsm',
2928                self.TARGET_RSSI:
2929                self._GSM_RSSI_OFFSET + serving_cell['power'],
2930                self.MAX_ERROR_RSSI: 3,
2931                self.MAX_ERROR_AVERAGE_RSSI: 3
2932            },
2933            # Neighbor Cells
2934            {
2935                self.CID: neighbor_cell_1[self.CID],
2936                self.REPORT_RATE: 0.1,
2937                self.IS_REGISTERED: False,
2938                self.RAT: 'gsm',
2939                self.TARGET_RSSI:
2940                self._GSM_RSSI_OFFSET + neighbor_cell_1['power'],
2941                self.MAX_ERROR_RSSI: 4,
2942                self.MAX_ERROR_AVERAGE_RSSI: 3
2943            }
2944        ]
2945        expected_cell_info_stats = {}
2946        for sample in expected_cell_info_list:
2947            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
2948
2949        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
2950        [bts1] = set_system_model_gsm(self.md8475a, self.user_params,
2951                                      self.ad.sim_card)
2952        self._setup_gsm_cell_md8475a(bts1, serving_cell, serving_cell['power'])
2953        bts1.neighbor_cell_mode = "USERDATA"
2954        bts1.set_neighbor_cell_type("GSM", 1, "CELLNAME")
2955        bts1.set_neighbor_cell_name("GSM", 1, "GSM_1900_C512_F1930_CID52")
2956        set_usim_parameters(self.md8475a, self.ad.sim_card)
2957        self.md8475a.start_simulation()
2958
2959        if not ensure_network_rat(
2960                self.log,
2961                self.ad,
2962                NETWORK_MODE_GSM_ONLY,
2963                RAT_FAMILY_GSM,
2964                toggle_apm_after_setting=True):
2965            self.log.error("Failed to set rat family {}, preferred network:{}".
2966                           format(RAT_FAMILY_GSM, NETWORK_MODE_GSM_ONLY))
2967            return False
2968        self.md8475a.wait_for_registration_state()
2969        time.sleep(self._ANRITSU_SETTLING_TIME)
2970        self.setup_3710a_waveform("1", "A", "1930.2MHz",
2971                                  neighbor_cell['power'], "GSM",
2972                                  "gsm_lac52_cid52")
2973
2974        self.turn_on_3710a_sg(1)
2975        time.sleep(self._SETTLING_TIME)
2976        return self._verify_cell_info(self.ad, expected_cell_info_stats)
2977
2978    @test_tracker_info(uuid="58627a33-45bd-436d-85b2-1ca711f56794")
2979    @TelephonyBaseTest.tel_test_wrap
2980    def test_neighbor_cell_reporting_gsm_intrafreq_2_tmo(self):
2981        """ Test Number of neighbor cells reported by Phone when two neighbor
2982        cells are present (Phone camped on GSM)
2983
2984        Setup one GSM cell configuration on MD8475A
2985        Setup two GSM waveforms on MG3710A
2986        Make Sure Phone camped on GSM
2987        Verify the number of neighbor cells reported by Phone
2988
2989        Returns:
2990            True if pass; False if fail
2991        """
2992        serving_cell = gsm_band1900_ch512_fr1930_cid51_cell
2993        neighbor_cell_1 = gsm_band1900_ch512_fr1930_cid52_cell
2994        neighbor_cell_2 = gsm_band1900_ch512_fr1930_cid53_cell
2995        serving_cell['power'] = -20
2996        neighbor_cell_1['power'] = -24
2997        neighbor_cell_2['power'] = -22
2998
2999        expected_cell_info_list = [
3000            # Serving Cell
3001            {
3002                self.CID: serving_cell[self.CID],
3003                self.REPORT_RATE: 1,
3004                self.IS_REGISTERED: True,
3005                self.RAT: 'gsm',
3006                self.TARGET_RSSI:
3007                self._GSM_RSSI_OFFSET + serving_cell['power'],
3008                self.MAX_ERROR_RSSI: 3,
3009                self.MAX_ERROR_AVERAGE_RSSI: 3
3010            },
3011            # Neighbor Cells
3012            {
3013                self.CID: neighbor_cell_1[self.CID],
3014                self.REPORT_RATE: 0.1,
3015                self.IS_REGISTERED: False,
3016                self.RAT: 'gsm',
3017                self.TARGET_RSSI:
3018                self._GSM_RSSI_OFFSET + neighbor_cell_1['power'],
3019                self.MAX_ERROR_RSSI: 4,
3020                self.MAX_ERROR_AVERAGE_RSSI: 3
3021            },
3022            {
3023                self.CID: neighbor_cell_2[self.CID],
3024                self.REPORT_RATE: 0.1,
3025                self.IS_REGISTERED: False,
3026                self.RAT: 'gsm',
3027                self.TARGET_RSSI:
3028                self._GSM_RSSI_OFFSET + neighbor_cell_2['power'],
3029                self.MAX_ERROR_RSSI: 4,
3030                self.MAX_ERROR_AVERAGE_RSSI: 3
3031            }
3032        ]
3033        expected_cell_info_stats = {}
3034        for sample in expected_cell_info_list:
3035            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
3036
3037        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
3038        [bts1] = set_system_model_gsm(self.md8475a, self.user_params,
3039                                      self.ad.sim_card)
3040        self._setup_gsm_cell_md8475a(bts1, serving_cell, serving_cell['power'])
3041        bts1.neighbor_cell_mode = "USERDATA"
3042        bts1.set_neighbor_cell_type("GSM", 1, "CELLNAME")
3043        bts1.set_neighbor_cell_name("GSM", 1, "GSM_1900_C512_F1930_CID52")
3044        bts1.set_neighbor_cell_type("GSM", 2, "CELLNAME")
3045        bts1.set_neighbor_cell_name("GSM", 2, "GSM_1900_C512_F1930_CID53")
3046        set_usim_parameters(self.md8475a, self.ad.sim_card)
3047        self.md8475a.start_simulation()
3048
3049        if not ensure_network_rat(
3050                self.log,
3051                self.ad,
3052                NETWORK_MODE_GSM_ONLY,
3053                RAT_FAMILY_GSM,
3054                toggle_apm_after_setting=True):
3055            self.log.error("Failed to set rat family {}, preferred network:{}".
3056                           format(RAT_FAMILY_GSM, NETWORK_MODE_GSM_ONLY))
3057            return False
3058        self.md8475a.wait_for_registration_state()
3059        self.setup_3710a_waveform("1", "A", "1930.2MHz",
3060                                  neighbor_cell_1['power'], "GSM",
3061                                  "gsm_lac52_cid52")
3062
3063        self.setup_3710a_waveform("2", "A", "1930.2MHz",
3064                                  neighbor_cell_2['power'], "GSM",
3065                                  "gsm_lac53_cid53")
3066        self.turn_on_3710a_sg(1)
3067        self.turn_on_3710a_sg(2)
3068        time.sleep(self._SETTLING_TIME)
3069        return self._verify_cell_info(self.ad, expected_cell_info_stats)
3070
3071    @test_tracker_info(uuid="3ff3439a-2e45-470a-a2d6-c63e37379f19")
3072    @TelephonyBaseTest.tel_test_wrap
3073    def test_neighbor_cell_reporting_gsm_intrafreq_3_tmo(self):
3074        """ Test Number of neighbor cells reported by Phone when three neighbor
3075        cells are present (Phone camped on GSM)
3076
3077        Setup one GSM cell configuration on MD8475A
3078        Setup three GSM waveforms on MG3710A
3079        Make Sure Phone camped on GSM
3080        Verify the number of neighbor cells reported by Phone
3081
3082        Returns:
3083            True if pass; False if fail
3084        """
3085        serving_cell = gsm_band1900_ch512_fr1930_cid51_cell
3086        neighbor_cell_1 = gsm_band1900_ch512_fr1930_cid52_cell
3087        neighbor_cell_2 = gsm_band1900_ch512_fr1930_cid53_cell
3088        neighbor_cell_3 = gsm_band1900_ch512_fr1930_cid54_cell
3089        serving_cell['power'] = -20
3090        neighbor_cell_1['power'] = -24
3091        neighbor_cell_2['power'] = -22
3092        neighbor_cell_3['power'] = -24
3093
3094        expected_cell_info_list = [
3095            # Serving Cell
3096            {
3097                self.CID: serving_cell[self.CID],
3098                self.REPORT_RATE: 1,
3099                self.IS_REGISTERED: True,
3100                self.RAT: 'gsm',
3101                self.TARGET_RSSI:
3102                self._GSM_RSSI_OFFSET + serving_cell['power'],
3103                self.MAX_ERROR_RSSI: 3,
3104                self.MAX_ERROR_AVERAGE_RSSI: 3
3105            },
3106            # Neighbor Cells
3107            {
3108                self.CID: neighbor_cell_1[self.CID],
3109                self.REPORT_RATE: 0.1,
3110                self.IS_REGISTERED: False,
3111                self.RAT: 'gsm',
3112                self.TARGET_RSSI:
3113                self._GSM_RSSI_OFFSET + neighbor_cell_1['power'],
3114                self.MAX_ERROR_RSSI: 4,
3115                self.MAX_ERROR_AVERAGE_RSSI: 3
3116            },
3117            {
3118                self.CID: neighbor_cell_2[self.CID],
3119                self.REPORT_RATE: 0.1,
3120                self.IS_REGISTERED: False,
3121                self.RAT: 'gsm',
3122                self.TARGET_RSSI:
3123                self._GSM_RSSI_OFFSET + neighbor_cell_2['power'],
3124                self.MAX_ERROR_RSSI: 4,
3125                self.MAX_ERROR_AVERAGE_RSSI: 3
3126            },
3127            {
3128                self.CID: neighbor_cell_3[self.CID],
3129                self.REPORT_RATE: 0.1,
3130                self.IS_REGISTERED: False,
3131                self.RAT: 'gsm',
3132                self.TARGET_RSSI:
3133                self._GSM_RSSI_OFFSET + neighbor_cell_3['power'],
3134                self.MAX_ERROR_RSSI: 4,
3135                self.MAX_ERROR_AVERAGE_RSSI: 3
3136            }
3137        ]
3138        expected_cell_info_stats = {}
3139        for sample in expected_cell_info_list:
3140            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
3141
3142        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
3143        [bts1] = set_system_model_gsm(self.md8475a, self.user_params,
3144                                      self.ad.sim_card)
3145        self._setup_gsm_cell_md8475a(bts1, serving_cell, serving_cell['power'])
3146        bts1.neighbor_cell_mode = "USERDATA"
3147        bts1.set_neighbor_cell_type("GSM", 1, "CELLNAME")
3148        bts1.set_neighbor_cell_name("GSM", 1, "GSM_1900_C512_F1930_CID52")
3149        bts1.set_neighbor_cell_type("GSM", 2, "CELLNAME")
3150        bts1.set_neighbor_cell_name("GSM", 2, "GSM_1900_C512_F1930_CID53")
3151        bts1.set_neighbor_cell_type("GSM", 3, "CELLNAME")
3152        bts1.set_neighbor_cell_name("GSM", 3, "GSM_1900_C512_F1930_CID53")
3153        set_usim_parameters(self.md8475a, self.ad.sim_card)
3154        self.md8475a.start_simulation()
3155
3156        if not ensure_network_rat(
3157                self.log,
3158                self.ad,
3159                NETWORK_MODE_GSM_ONLY,
3160                RAT_FAMILY_GSM,
3161                toggle_apm_after_setting=True):
3162            self.log.error("Failed to set rat family {}, preferred network:{}".
3163                           format(RAT_FAMILY_GSM, NETWORK_MODE_GSM_ONLY))
3164            return False
3165        self.md8475a.wait_for_registration_state()
3166        self.setup_3710a_waveform("1", "A", "1930.2MHz",
3167                                  neighbor_cell_1['power'], "GSM",
3168                                  "gsm_lac52_cid52")
3169
3170        self.setup_3710a_waveform("2", "A", "1930.2MHz",
3171                                  neighbor_cell_2['power'], "GSM",
3172                                  "gsm_lac53_cid53")
3173
3174        self.setup_3710a_waveform("2", "B", "1930.2MHz",
3175                                  neighbor_cell_3['power'], "GSM",
3176                                  "gsm_lac54_cid54")
3177        self.turn_on_3710a_sg(1)
3178        self.turn_on_3710a_sg(2)
3179        time.sleep(self._SETTLING_TIME)
3180        return self._verify_cell_info(self.ad, expected_cell_info_stats)
3181
3182    @test_tracker_info(uuid="0cac1370-144e-40a4-b6bc-66691926f898")
3183    @TelephonyBaseTest.tel_test_wrap
3184    def test_neighbor_cell_reporting_gsm_interfreq_1_tmo(self):
3185        """ Test Number of neighbor cells reported by Phone when one neighbor
3186        cells(inter frequency) is present (Phone camped on GSM)
3187
3188        Setup one GSM cell configuration on MD8475A
3189        Setup two GSM waveforms on MG3710A
3190        Make Sure Phone camped on GSM
3191        Verify the number of neighbor cells reported by Phone
3192
3193        Returns:
3194            True if pass; False if fail
3195        """
3196        serving_cell = gsm_band1900_ch512_fr1930_cid51_cell
3197        neighbor_cell_1 = gsm_band1900_ch640_fr1955_cid56_cell
3198        serving_cell['power'] = -20
3199        neighbor_cell_1['power'] = -24
3200
3201        expected_cell_info_list = [
3202            # Serving Cell
3203            {
3204                self.CID: serving_cell[self.CID],
3205                self.REPORT_RATE: 1,
3206                self.IS_REGISTERED: True,
3207                self.RAT: 'gsm',
3208                self.TARGET_RSSI:
3209                self._GSM_RSSI_OFFSET + serving_cell['power'],
3210                self.MAX_ERROR_RSSI: 3,
3211                self.MAX_ERROR_AVERAGE_RSSI: 3
3212            },
3213            # Neighbor Cells
3214            {
3215                self.CID: neighbor_cell_1[self.CID],
3216                self.REPORT_RATE: 0.1,
3217                self.IS_REGISTERED: False,
3218                self.RAT: 'gsm',
3219                self.TARGET_RSSI:
3220                self._GSM_RSSI_OFFSET + neighbor_cell_1['power'],
3221                self.MAX_ERROR_RSSI: 4,
3222                self.MAX_ERROR_AVERAGE_RSSI: 3
3223            }
3224        ]
3225        expected_cell_info_stats = {}
3226        for sample in expected_cell_info_list:
3227            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
3228
3229        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
3230        [bts1] = set_system_model_gsm(self.md8475a, self.user_params,
3231                                      self.ad.sim_card)
3232        self._setup_gsm_cell_md8475a(bts1, serving_cell, serving_cell['power'])
3233        bts1.neighbor_cell_mode = "USERDATA"
3234        bts1.set_neighbor_cell_type("GSM", 1, "CELLNAME")
3235        bts1.set_neighbor_cell_name("GSM", 1, "GSM_1900_C640_F1955_CID56")
3236        set_usim_parameters(self.md8475a, self.ad.sim_card)
3237        self.md8475a.start_simulation()
3238
3239        self.ad.droid.telephonyToggleDataConnection(False)
3240        if not ensure_network_rat(
3241                self.log,
3242                self.ad,
3243                NETWORK_MODE_GSM_ONLY,
3244                RAT_FAMILY_GSM,
3245                toggle_apm_after_setting=True):
3246            self.log.error("Failed to set rat family {}, preferred network:{}".
3247                           format(RAT_FAMILY_GSM, NETWORK_MODE_GSM_ONLY))
3248            return False
3249        self.md8475a.wait_for_registration_state()
3250        self.setup_3710a_waveform("1", "A", "1955.8MHz",
3251                                  neighbor_cell_1['power'], "GSM",
3252                                  "gsm_lac56_cid56")
3253
3254        self.turn_on_3710a_sg(1)
3255        time.sleep(self._SETTLING_TIME)
3256        return self._verify_cell_info(self.ad, expected_cell_info_stats)
3257
3258    @test_tracker_info(uuid="5f0367dd-08b5-4871-a784-51a0f76e229b")
3259    @TelephonyBaseTest.tel_test_wrap
3260    def test_neighbor_cell_reporting_gsm_interfreq_2_tmo(self):
3261        """ Test Number of neighbor cells reported by Phone when two neighbor
3262        cells(inter frequency) are present (Phone camped on GSM)
3263
3264        Setup one GSM cell configuration on MD8475A
3265        Setup two GSM waveforms on MG3710A
3266        Make Sure Phone camped on GSM
3267        Verify the number of neighbor cells reported by Phone
3268
3269        Returns:
3270            True if pass; False if fail
3271        """
3272        serving_cell = gsm_band1900_ch512_fr1930_cid51_cell
3273        neighbor_cell_1 = gsm_band1900_ch640_fr1955_cid56_cell
3274        neighbor_cell_2 = gsm_band1900_ch750_fr1977_cid57_cell
3275        serving_cell['power'] = -20
3276        neighbor_cell_1['power'] = -24
3277        neighbor_cell_2['power'] = -22
3278
3279        expected_cell_info_list = [
3280            # Serving Cell
3281            {
3282                self.CID: serving_cell[self.CID],
3283                self.REPORT_RATE: 1,
3284                self.IS_REGISTERED: True,
3285                self.RAT: 'gsm',
3286                self.TARGET_RSSI:
3287                self._GSM_RSSI_OFFSET + serving_cell['power'],
3288                self.MAX_ERROR_RSSI: 3,
3289                self.MAX_ERROR_AVERAGE_RSSI: 3
3290            },
3291            # Neighbor Cells
3292            {
3293                self.CID: neighbor_cell_1[self.CID],
3294                self.REPORT_RATE: 0.1,
3295                self.IS_REGISTERED: False,
3296                self.RAT: 'gsm',
3297                self.TARGET_RSSI:
3298                self._GSM_RSSI_OFFSET + neighbor_cell_1['power'],
3299                self.MAX_ERROR_RSSI: 4,
3300                self.MAX_ERROR_AVERAGE_RSSI: 3
3301            },
3302            {
3303                self.CID: neighbor_cell_2[self.CID],
3304                self.REPORT_RATE: 0.1,
3305                self.IS_REGISTERED: False,
3306                self.RAT: 'gsm',
3307                self.TARGET_RSSI:
3308                self._GSM_RSSI_OFFSET + neighbor_cell_2['power'],
3309                self.MAX_ERROR_RSSI: 4,
3310                self.MAX_ERROR_AVERAGE_RSSI: 3
3311            }
3312        ]
3313        expected_cell_info_stats = {}
3314        for sample in expected_cell_info_list:
3315            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
3316
3317        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
3318        [bts1] = set_system_model_gsm(self.md8475a, self.user_params,
3319                                      self.ad.sim_card)
3320        self._setup_gsm_cell_md8475a(bts1, serving_cell, serving_cell['power'])
3321        bts1.neighbor_cell_mode = "USERDATA"
3322        bts1.set_neighbor_cell_type("GSM", 1, "CELLNAME")
3323        bts1.set_neighbor_cell_name("GSM", 1, "GSM_1900_C640_F1955_CID56")
3324        bts1.set_neighbor_cell_type("GSM", 2, "CELLNAME")
3325        bts1.set_neighbor_cell_name("GSM", 2, "GSM_1900_C750_F1977_CID57")
3326        set_usim_parameters(self.md8475a, self.ad.sim_card)
3327        self.md8475a.start_simulation()
3328
3329        self.ad.droid.telephonyToggleDataConnection(False)
3330        if not ensure_network_rat(
3331                self.log,
3332                self.ad,
3333                NETWORK_MODE_GSM_ONLY,
3334                RAT_FAMILY_GSM,
3335                toggle_apm_after_setting=True):
3336            self.log.error("Failed to set rat family {}, preferred network:{}".
3337                           format(RAT_FAMILY_GSM, NETWORK_MODE_GSM_ONLY))
3338            return False
3339        self.md8475a.wait_for_registration_state()
3340        self.setup_3710a_waveform("1", "A", "1955.8MHz",
3341                                  neighbor_cell_1['power'], "GSM",
3342                                  "gsm_lac56_cid56")
3343
3344        self.setup_3710a_waveform("2", "A", "1977.8MHz",
3345                                  neighbor_cell_2['power'], "GSM",
3346                                  "gsm_lac57_cid57")
3347        self.turn_on_3710a_sg(1)
3348        self.turn_on_3710a_sg(2)
3349        time.sleep(self._SETTLING_TIME)
3350        return self._verify_cell_info(self.ad, expected_cell_info_stats)
3351
3352    @test_tracker_info(uuid="b195153f-f6a0-4ec4-bb53-29c30ec0a034")
3353    @TelephonyBaseTest.tel_test_wrap
3354    def test_neighbor_cell_reporting_gsm_interband_2_tmo(self):
3355        """ Test Number of neighbor cells reported by Phone when two neighbor
3356        cells(inter band) are present (Phone camped on GSM)
3357
3358        Setup one GSM cell configuration on MD8475A
3359        Setup two GSM waveforms on MG3710A
3360        Make Sure Phone camped on GSM
3361        Verify the number of neighbor cells reported by Phone
3362
3363        Returns:
3364            True if pass; False if fail
3365        """
3366        serving_cell = gsm_band1900_ch512_fr1930_cid51_cell
3367        neighbor_cell_1 = gsm_band850_ch128_fr869_cid58_cell
3368        neighbor_cell_2 = gsm_band850_ch251_fr893_cid59_cell
3369        serving_cell['power'] = -20
3370        neighbor_cell_1['power'] = -24
3371        neighbor_cell_2['power'] = -22
3372
3373        expected_cell_info_list = [
3374            # Serving Cell
3375            {
3376                self.CID: serving_cell[self.CID],
3377                self.REPORT_RATE: 1,
3378                self.IS_REGISTERED: True,
3379                self.RAT: 'gsm',
3380                self.TARGET_RSSI:
3381                self._GSM_RSSI_OFFSET + serving_cell['power'],
3382                self.MAX_ERROR_RSSI: 3,
3383                self.MAX_ERROR_AVERAGE_RSSI: 3
3384            },
3385            # Neighbor Cells
3386            {
3387                self.CID: neighbor_cell_1[self.CID],
3388                self.REPORT_RATE: 0.1,
3389                self.IS_REGISTERED: False,
3390                self.RAT: 'gsm',
3391                self.TARGET_RSSI:
3392                self._GSM_RSSI_OFFSET + neighbor_cell_1['power'],
3393                self.MAX_ERROR_RSSI: 4,
3394                self.MAX_ERROR_AVERAGE_RSSI: 3
3395            },
3396            {
3397                self.CID: neighbor_cell_2[self.CID],
3398                self.REPORT_RATE: 0.1,
3399                self.IS_REGISTERED: False,
3400                self.RAT: 'gsm',
3401                self.TARGET_RSSI:
3402                self._GSM_RSSI_OFFSET + neighbor_cell_2['power'],
3403                self.MAX_ERROR_RSSI: 4,
3404                self.MAX_ERROR_AVERAGE_RSSI: 3
3405            }
3406        ]
3407        expected_cell_info_stats = {}
3408        for sample in expected_cell_info_list:
3409            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
3410
3411        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
3412        [bts1] = set_system_model_gsm(self.md8475a, self.user_params,
3413                                      self.ad.sim_card)
3414        self._setup_gsm_cell_md8475a(bts1, serving_cell, serving_cell['power'])
3415        bts1.neighbor_cell_mode = "USERDATA"
3416        bts1.set_neighbor_cell_type("GSM", 1, "CELLNAME")
3417        bts1.set_neighbor_cell_name("GSM", 1, "GSM_850_C128_F869_CID58")
3418        bts1.set_neighbor_cell_type("GSM", 2, "CELLNAME")
3419        bts1.set_neighbor_cell_name("GSM", 2, "GSM_850_C251_F893_CID59")
3420        set_usim_parameters(self.md8475a, self.ad.sim_card)
3421        self.md8475a.start_simulation()
3422
3423        self.ad.droid.telephonyToggleDataConnection(False)
3424        if not ensure_network_rat(
3425                self.log,
3426                self.ad,
3427                NETWORK_MODE_GSM_ONLY,
3428                RAT_FAMILY_GSM,
3429                toggle_apm_after_setting=True):
3430            self.log.error("Failed to set rat family {}, preferred network:{}".
3431                           format(RAT_FAMILY_GSM, NETWORK_MODE_GSM_ONLY))
3432            return False
3433        self.md8475a.wait_for_registration_state()
3434        self.setup_3710a_waveform("1", "A", "869MHz", neighbor_cell_1['power'],
3435                                  "GSM", "gsm_lac58_cid58")
3436
3437        self.setup_3710a_waveform("2", "A", "893MHz", neighbor_cell_2['power'],
3438                                  "GSM", "gsm_lac59_cid59")
3439        self.turn_on_3710a_sg(1)
3440        self.turn_on_3710a_sg(2)
3441        time.sleep(self._SETTLING_TIME)
3442        return self._verify_cell_info(self.ad, expected_cell_info_stats)
3443
3444    @test_tracker_info(uuid="209f62c1-7950-447c-9101-abe930da20ba")
3445    @TelephonyBaseTest.tel_test_wrap
3446    def test_neighbor_cell_reporting_gsm_interrat_2_tmo(self):
3447        """ Test Number of neighbor cells reported by Phone when no neighbor
3448        cells(inter RAT) are present (Phone camped on GSM)
3449
3450        Setup one GSM cell configuration on MD8475A
3451        Setup one LTE and one GSM waveforms on MG3710A
3452        Make Sure Phone camped on GSM
3453        Verify the number of neighbor cells reported by Phone
3454
3455        Returns:
3456            True if pass; False if fail
3457        """
3458        serving_cell = gsm_band1900_ch512_fr1930_cid51_cell
3459        neighbor_cell_1 = lte_band4_ch2000_fr2115_pcid1_cell
3460        neighbor_cell_2 = wcdma_band1_ch10700_fr2140_cid31_cell
3461        serving_cell['power'] = -20
3462        neighbor_cell_1['power'] = -24
3463        neighbor_cell_2['power'] = -22
3464
3465        expected_cell_info_list = [
3466            # Serving Cell
3467            {
3468                self.CID: serving_cell[self.CID],
3469                self.REPORT_RATE: 1,
3470                self.IS_REGISTERED: True,
3471                self.RAT: 'gsm',
3472                self.TARGET_RSSI:
3473                self._GSM_RSSI_OFFSET + serving_cell['power'],
3474                self.MAX_ERROR_RSSI: 3,
3475                self.MAX_ERROR_AVERAGE_RSSI: 3
3476            },
3477            # Neighbor Cells
3478            {
3479                self.PCID: neighbor_cell_1[self.PCID],
3480                self.REPORT_RATE: 0.1,
3481                self.IS_REGISTERED: False,
3482                self.RAT: 'lte',
3483                self.TARGET_RSSI:
3484                self._LTE_RSSI_OFFSET + neighbor_cell_1['power'],
3485                self.MAX_ERROR_RSSI: 4,
3486                self.MAX_ERROR_AVERAGE_RSSI: 3
3487            },
3488            {
3489                self.PSC: neighbor_cell_2[self.PSC],
3490                self.REPORT_RATE: 0.1,
3491                self.IS_REGISTERED: False,
3492                self.RAT: 'wcdma',
3493                self.TARGET_RSSI:
3494                self._WCDMA_RSSI_OFFSET + neighbor_cell_2['power'],
3495                self.MAX_ERROR_RSSI: 4,
3496                self.MAX_ERROR_AVERAGE_RSSI: 3
3497            }
3498        ]
3499        expected_cell_info_stats = {}
3500        for sample in expected_cell_info_list:
3501            expected_cell_info_stats[self._unique_cell_id(sample)] = sample
3502
3503        self.md8475a.load_cell_paramfile(self._CELL_PARAM_FILE)
3504        [bts1] = set_system_model_gsm(self.md8475a, self.user_params,
3505                                      self.ad.sim_card)
3506        self._setup_gsm_cell_md8475a(bts1, serving_cell, serving_cell['power'])
3507        bts1.neighbor_cell_mode = "USERDATA"
3508        bts1.set_neighbor_cell_type("LTE", 1, "CELLNAME")
3509        bts1.set_neighbor_cell_name("LTE", 1, "LTE_4_C2000_F2115_PCID1")
3510        bts1.set_neighbor_cell_type("WCDMA", 2, "CELLNAME")
3511        bts1.set_neighbor_cell_name("WCDMA", 2, "WCDM_1_C10700_F2140_CID31")
3512        set_usim_parameters(self.md8475a, self.ad.sim_card)
3513        self.md8475a.start_simulation()
3514        self.ad.droid.telephonyToggleDataConnection(False)
3515        if not ensure_network_rat(
3516                self.log,
3517                self.ad,
3518                NETWORK_MODE_GSM_ONLY,
3519                RAT_FAMILY_GSM,
3520                toggle_apm_after_setting=True):
3521            self.log.error("Failed to set rat family {}, preferred network:{}".
3522                           format(RAT_FAMILY_GSM, NETWORK_MODE_GSM_ONLY))
3523            return False
3524        self.md8475a.wait_for_registration_state()
3525        self.setup_3710a_waveform("1", "A", "2115MHz",
3526                                  neighbor_cell_1['power'], "LTE",
3527                                  "lte_1_ch2000_pcid1")
3528
3529        self.setup_3710a_waveform("2", "A", "2140MHz",
3530                                  neighbor_cell_2['power'], "WCDMA",
3531                                  "wcdma_1_psc31_cid31")
3532        self.turn_on_3710a_sg(1)
3533        self.turn_on_3710a_sg(2)
3534        time.sleep(self._SETTLING_TIME)
3535        return self._verify_cell_info(self.ad, expected_cell_info_stats)
3536
3537    """ Tests End """
3538