1#!/usr/bin/env python3
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"""
17Controller interface for Anritsu Signalling Tester MD8475A.
18"""
19
20import logging
21import time
22import socket
23from enum import Enum
24from enum import IntEnum
25
26from acts.controllers.anritsu_lib._anritsu_utils import AnritsuError
27from acts.controllers.anritsu_lib._anritsu_utils import AnritsuUtils
28from acts.controllers.anritsu_lib._anritsu_utils import NO_ERROR
29from acts.controllers.anritsu_lib._anritsu_utils import OPERATION_COMPLETE
30
31from acts import tracelogger
32
33TERMINATOR = "\0"
34
35# The following wait times (except COMMUNICATION_STATE_WAIT_TIME) are actually
36# the times for socket to time out. Increasing them is to make sure there is
37# enough time for MD8475A operation to be completed in some cases.
38# It won't increase test execution time.
39SMARTSTUDIO_LAUNCH_WAIT_TIME = 300  # was 90
40SMARTSTUDIO_SIMULATION_START_WAIT_TIME = 300  # was 120
41REGISTRATION_STATE_WAIT_TIME = 240
42LOAD_SIMULATION_PARAM_FILE_WAIT_TIME = 30
43COMMUNICATION_STATE_WAIT_TIME = 240
44ANRITSU_SOCKET_BUFFER_SIZE = 8192
45COMMAND_COMPLETE_WAIT_TIME = 180  # was 90
46SETTLING_TIME = 1
47WAIT_TIME_IDENTITY_RESPONSE = 5
48IDLE_STATE_WAIT_TIME = 240
49
50IMSI_READ_USERDATA_WCDMA = "081501"
51IMEI_READ_USERDATA_WCDMA = "081502"
52IMEISV_READ_USERDATA_WCDMA = "081503"
53IMSI_READ_USERDATA_LTE = "075501"
54IMEI_READ_USERDATA_LTE = "075502"
55IMEISV_READ_USERDATA_LTE = "075503"
56IMSI_READ_USERDATA_GSM = "081501"
57IMEI_READ_USERDATA_GSM = "081502"
58IMEISV_READ_USERDATA_GSM = "081503"
59IDENTITY_REQ_DATA_LEN = 24
60SEQ_LOG_MESSAGE_START_INDEX = 60
61
62WCDMA_BANDS = {
63    "I": "1",
64    "II": "2",
65    "III": "3",
66    "IV": "4",
67    "V": "5",
68    "VI": "6",
69    "VII": "7",
70    "VIII": "8",
71    "IX": "9",
72    "X": "10",
73    "XI": "11",
74    "XII": "12",
75    "XIII": "13",
76    "XIV": "14"
77}
78
79
80def create(configs):
81    objs = []
82    for c in configs:
83        ip_address = c["ip_address"]
84        objs.append(MD8475A(ip_address))
85    return objs
86
87
88def destroy(objs):
89    return
90
91
92class ProcessingStatus(Enum):
93    ''' MD8475A processing status for UE,Packet,Voice,Video,SMS,
94        PPP, PWS '''
95    PROCESS_STATUS_NONE = "NONE"
96    PROCESS_STATUS_NOTRUN = "NOTRUN"
97    PROCESS_STATUS_POWEROFF = "POWEROFF"
98    PROCESS_STATUS_REGISTRATION = "REGISTRATION"
99    PROCESS_STATUS_DETACH = "DETACH"
100    PROCESS_STATUS_IDLE = "IDLE"
101    PROCESS_STATUS_ORIGINATION = "ORIGINATION"
102    PROCESS_STATUS_HANDOVER = "HANDOVER"
103    PROCESS_STATUS_UPDATING = "UPDATING"
104    PROCESS_STATUS_TERMINATION = "TERMINATION"
105    PROCESS_STATUS_COMMUNICATION = "COMMUNICATION"
106    PROCESS_STATUS_UERELEASE = "UERELEASE"
107    PROCESS_STATUS_NWRELEASE = "NWRELEASE"
108
109
110class BtsNumber(Enum):
111    '''ID number for MD8475A supported BTS '''
112    BTS1 = "BTS1"
113    BTS2 = "BTS2"
114    BTS3 = "BTS3"
115    BTS4 = "BTS4"
116    BTS5 = "BTS5"
117
118
119class BtsTechnology(Enum):
120    ''' BTS system technology'''
121    LTE = "LTE"
122    WCDMA = "WCDMA"
123    TDSCDMA = "TDSCDMA"
124    GSM = "GSM"
125    CDMA1X = "CDMA1X"
126    EVDO = "EVDO"
127
128
129class BtsBandwidth(Enum):
130    ''' Values for Cell Bandwidth '''
131    LTE_BANDWIDTH_1dot4MHz = "1.4MHz"
132    LTE_BANDWIDTH_3MHz = "3MHz"
133    LTE_BANDWIDTH_5MHz = "5MHz"
134    LTE_BANDWIDTH_10MHz = "10MHz"
135    LTE_BANDWIDTH_15MHz = "15MHz"
136    LTE_BANDWIDTH_20MHz = "20MHz"
137
138    def get_float_value(bts_bandwidth):
139        """ Returns a float representing the bandwidth in MHz.
140
141        Args:
142            bts_bandwidth: a BtsBandwidth enum or a string matching one of the
143            values in the BtsBandwidth enum.
144        """
145
146        if isinstance(bts_bandwidth, BtsBandwidth):
147            bandwidth_str = bts_bandwidth.value
148        elif isinstance(bts_bandwidth, str):
149            bandwidth_str = bts_bandwidth
150        else:
151            raise TypeError('bts_bandwidth should be an instance of string or '
152                            'BtsBandwidth. ')
153
154        if bandwidth_str == BtsBandwidth.LTE_BANDWIDTH_20MHz.value:
155            return 20
156        elif bandwidth_str == BtsBandwidth.LTE_BANDWIDTH_15MHz.value:
157            return 15
158        elif bandwidth_str == BtsBandwidth.LTE_BANDWIDTH_10MHz.value:
159            return 10
160        elif bandwidth_str == BtsBandwidth.LTE_BANDWIDTH_5MHz.value:
161            return 5
162        elif bandwidth_str == BtsBandwidth.LTE_BANDWIDTH_3MHz.value:
163            return 3
164        elif bandwidth_str == BtsBandwidth.LTE_BANDWIDTH_1dot4MHz.value:
165            return 1.4
166        else:
167            raise ValueError(
168                'Could not map {} to a bandwidth value.'.format(bandwidth_str))
169
170
171MAX_NRB_FOR_BANDWIDTH = {
172    BtsBandwidth.LTE_BANDWIDTH_1dot4MHz.value: 6,
173    BtsBandwidth.LTE_BANDWIDTH_3MHz.value: 15,
174    BtsBandwidth.LTE_BANDWIDTH_5MHz.value: 25,
175    BtsBandwidth.LTE_BANDWIDTH_10MHz.value: 50,
176    BtsBandwidth.LTE_BANDWIDTH_15MHz.value: 75,
177    BtsBandwidth.LTE_BANDWIDTH_20MHz.value: 100
178}
179
180
181class LteMimoMode(Enum):
182    """ Values for LTE MIMO modes. """
183    NONE = "MIMONOT"
184    MIMO_2X2 = "MIMO2X2"
185    MIMO_4X4 = "MIMO4X4"
186
187
188class BtsGprsMode(Enum):
189    ''' Values for Gprs Modes '''
190    NO_GPRS = "NO_GPRS"
191    GPRS = "GPRS"
192    EGPRS = "EGPRS"
193
194
195class BtsPacketRate(Enum):
196    ''' Values for Cell Packet rate '''
197    LTE_MANUAL = "MANUAL"
198    LTE_BESTEFFORT = "BESTEFFORT"
199    WCDMA_DL384K_UL64K = "DL384K_UL64K"
200    WCDMA_DLHSAUTO_REL7_UL384K = "DLHSAUTO_REL7_UL384K"
201    WCDMA_DL18_0M_UL384K = "DL18_0M_UL384K"
202    WCDMA_DL21_6M_UL384K = "DL21_6M_UL384K"
203    WCDMA_DLHSAUTO_REL7_ULHSAUTO = "DLHSAUTO_REL7_ULHSAUTO"
204    WCDMA_DL18_0M_UL1_46M = "DL18_0M_UL1_46M"
205    WCDMA_DL18_0M_UL2_0M = "DL18_0M_UL2_0M"
206    WCDMA_DL18_0M_UL5_76M = "DL18_0M_UL5_76M"
207    WCDMA_DL21_6M_UL1_46M = "DL21_6M_UL1_46M"
208    WCDMA_DL21_6M_UL2_0M = "DL21_6M_UL2_0M"
209    WCDMA_DL21_6M_UL5_76M = "DL21_6M_UL5_76M"
210    WCDMA_DLHSAUTO_REL8_UL384K = "DLHSAUTO_REL8_UL384K"
211    WCDMA_DL23_4M_UL384K = "DL23_4M_UL384K"
212    WCDMA_DL28_0M_UL384K = "DL28_0M_UL384K"
213    WCDMA_DL36_0M_UL384K = "DL36_0M_UL384K"
214    WCDMA_DL43_2M_UL384K = "DL43_2M_UL384K"
215    WCDMA_DLHSAUTO_REL8_ULHSAUTO = "DLHSAUTO_REL8_ULHSAUTO"
216    WCDMA_DL23_4M_UL1_46M = "DL23_4M_UL1_46M"
217    WCDMA_DL23_4M_UL2_0M = "DL23_4M_UL2_0M"
218    WCDMA_DL23_4M_UL5_76M = "DL23_4M_UL5_76M"
219    WCDMA_DL28_0M_UL1_46M = "DL28_0M_UL1_46M"
220    WCDMA_DL28_0M_UL2_0M = "DL28_0M_UL2_0M"
221    WCDMA_DL28_0M_UL5_76M = "L28_0M_UL5_76M"
222    WCDMA_DL36_0M_UL1_46M = "DL36_0M_UL1_46M"
223    WCDMA_DL36_0M_UL2_0M = "DL36_0M_UL2_0M"
224    WCDMA_DL36_0M_UL5_76M = "DL36_0M_UL5_76M"
225    WCDMA_DL43_2M_UL1_46M = "DL43_2M_UL1_46M"
226    WCDMA_DL43_2M_UL2_0M = "DL43_2M_UL2_0M"
227    WCDMA_DL43_2M_UL5_76M = "DL43_2M_UL5_76M"
228
229
230class BtsPacketWindowSize(Enum):
231    ''' Values for Cell Packet window size '''
232    WINDOW_SIZE_1 = 1
233    WINDOW_SIZE_8 = 8
234    WINDOW_SIZE_16 = 16
235    WINDOW_SIZE_32 = 32
236    WINDOW_SIZE_64 = 64
237    WINDOW_SIZE_128 = 128
238    WINDOW_SIZE_256 = 256
239    WINDOW_SIZE_512 = 512
240    WINDOW_SIZE_768 = 768
241    WINDOW_SIZE_1024 = 1024
242    WINDOW_SIZE_1536 = 1536
243    WINDOW_SIZE_2047 = 2047
244
245
246class BtsServiceState(Enum):
247    ''' Values for BTS service state '''
248    SERVICE_STATE_IN = "IN"
249    SERVICE_STATE_OUT = "OUT"
250
251
252class BtsCellBarred(Enum):
253    ''' Values for Cell barred parameter '''
254    NOTBARRED = "NOTBARRED"
255    BARRED = "BARRED"
256
257
258class BtsAccessClassBarred(Enum):
259    ''' Values for Access class barred parameter '''
260    NOTBARRED = "NOTBARRED"
261    EMERGENCY = "EMERGENCY"
262    BARRED = "BARRED"
263    USERSPECIFIC = "USERSPECIFIC"
264
265
266class BtsLteEmergencyAccessClassBarred(Enum):
267    ''' Values for Lte emergency access class barred parameter '''
268    NOTBARRED = "NOTBARRED"
269    BARRED = "BARRED"
270
271
272class BtsNwNameEnable(Enum):
273    ''' Values for BT network name enable parameter '''
274    NAME_ENABLE = "ON"
275    NAME_DISABLE = "OFF"
276
277
278class IPAddressType(Enum):
279    ''' Values for IP address type '''
280    IPV4 = "IPV4"
281    IPV6 = "IPV6"
282    IPV4V6 = "IPV4V6"
283
284
285class TriggerMessageIDs(Enum):
286    ''' ID for Trigger messages  '''
287    RRC_CONNECTION_REQ = 111101
288    RRC_CONN_REESTABLISH_REQ = 111100
289    ATTACH_REQ = 141141
290    DETACH_REQ = 141145
291    MM_LOC_UPDATE_REQ = 221108
292    GMM_ATTACH_REQ = 241101
293    GMM_RA_UPDATE_REQ = 241108
294    IDENTITY_REQUEST_LTE = 141155
295    IDENTITY_REQUEST_WCDMA = 241115
296    IDENTITY_REQUEST_GSM = 641115
297    UE_CAPABILITY_ENQUIRY = 111167
298
299
300class TriggerMessageReply(Enum):
301    ''' Values for Trigger message reply parameter '''
302    ACCEPT = "ACCEPT"
303    REJECT = "REJECT"
304    IGNORE = "IGNORE"
305    NONE = "NONE"
306    ILLEGAL = "ILLEGAL"
307
308
309class TestProcedure(Enum):
310    ''' Values for different Test procedures in MD8475A '''
311    PROCEDURE_BL = "BL"
312    PROCEDURE_SELECTION = "SELECTION"
313    PROCEDURE_RESELECTION = "RESELECTION"
314    PROCEDURE_REDIRECTION = "REDIRECTION"
315    PROCEDURE_HO = "HO"
316    PROCEDURE_HHO = "HHO"
317    PROCEDURE_SHO = "SHO"
318    PROCEDURE_MEASUREMENT = "MEASUREMENT"
319    PROCEDURE_CELLCHANGE = "CELLCHANGE"
320    PROCEDURE_MULTICELL = "MULTICELL"
321
322
323class TestPowerControl(Enum):
324    ''' Values for power control in test procedure '''
325    POWER_CONTROL_ENABLE = "ENABLE"
326    POWER_CONTROL_DISABLE = "DISABLE"
327
328
329class TestMeasurement(Enum):
330    ''' Values for mesaurement in test procedure '''
331    MEASUREMENT_ENABLE = "ENABLE"
332    MEASUREMENT_DISABLE = "DISABLE"
333
334
335'''MD8475A processing states'''
336_PROCESS_STATES = {
337    "NONE": ProcessingStatus.PROCESS_STATUS_NONE,
338    "NOTRUN": ProcessingStatus.PROCESS_STATUS_NOTRUN,
339    "POWEROFF": ProcessingStatus.PROCESS_STATUS_POWEROFF,
340    "REGISTRATION": ProcessingStatus.PROCESS_STATUS_REGISTRATION,
341    "DETACH": ProcessingStatus.PROCESS_STATUS_DETACH,
342    "IDLE": ProcessingStatus.PROCESS_STATUS_IDLE,
343    "ORIGINATION": ProcessingStatus.PROCESS_STATUS_ORIGINATION,
344    "HANDOVER": ProcessingStatus.PROCESS_STATUS_HANDOVER,
345    "UPDATING": ProcessingStatus.PROCESS_STATUS_UPDATING,
346    "TERMINATION": ProcessingStatus.PROCESS_STATUS_TERMINATION,
347    "COMMUNICATION": ProcessingStatus.PROCESS_STATUS_COMMUNICATION,
348    "UERELEASE": ProcessingStatus.PROCESS_STATUS_UERELEASE,
349    "NWRELEASE": ProcessingStatus.PROCESS_STATUS_NWRELEASE,
350}
351
352
353class ImsCscfStatus(Enum):
354    """ MD8475A ims cscf status for UE
355    """
356    OFF = "OFF"
357    SIPIDLE = "SIPIDLE"
358    CONNECTED = "CONNECTED"
359    CALLING = "CALLING"
360    RINGING = "RINGING"
361    UNKNOWN = "UNKNOWN"
362
363
364class ImsCscfCall(Enum):
365    """ MD8475A ims cscf call action
366    """
367    MAKE = "MAKE"
368    END = "END"
369    MAKEVIDEO = "MAKEVIDEO"
370    MAKE2ND = "MAKE2ND"
371    END2ND = "END2ND"
372    ANSWER = "ANSWER"
373    HOLD = "HOLD"
374    RESUME = "RESUME"
375
376
377class VirtualPhoneStatus(IntEnum):
378    ''' MD8475A virtual phone status for UE voice and UE video
379        PPP, PWS '''
380    STATUS_IDLE = 0
381    STATUS_VOICECALL_ORIGINATION = 1
382    STATUS_VOICECALL_INCOMING = 2
383    STATUS_VOICECALL_INPROGRESS = 3
384    STATUS_VOICECALL_DISCONNECTING = 4
385    STATUS_VOICECALL_DISCONNECTED = 5
386    STATUS_VIDEOCALL_ORIGINATION = 6
387    STATUS_VIDEOCALL_INCOMING = 7
388    STATUS_VIDEOCALL_INPROGRESS = 8
389    STATUS_VIDEOCALL_DISCONNECTING = 9
390    STATUS_VIDEOCALL_DISCONNECTED = 10
391
392
393'''Virtual Phone Status '''
394_VP_STATUS = {
395    "0": VirtualPhoneStatus.STATUS_IDLE,
396    "1": VirtualPhoneStatus.STATUS_VOICECALL_ORIGINATION,
397    "2": VirtualPhoneStatus.STATUS_VOICECALL_INCOMING,
398    "3": VirtualPhoneStatus.STATUS_VOICECALL_INPROGRESS,
399    "4": VirtualPhoneStatus.STATUS_VOICECALL_DISCONNECTING,
400    "5": VirtualPhoneStatus.STATUS_VOICECALL_DISCONNECTED,
401    "6": VirtualPhoneStatus.STATUS_VIDEOCALL_ORIGINATION,
402    "7": VirtualPhoneStatus.STATUS_VIDEOCALL_INCOMING,
403    "8": VirtualPhoneStatus.STATUS_VIDEOCALL_INPROGRESS,
404    "9": VirtualPhoneStatus.STATUS_VIDEOCALL_DISCONNECTING,
405    "10": VirtualPhoneStatus.STATUS_VIDEOCALL_DISCONNECTED,
406}
407
408
409class VirtualPhoneAutoAnswer(Enum):
410    ''' Virtual phone auto answer enable values'''
411    ON = "ON"
412    OFF = "OFF"
413
414
415class CsfbType(Enum):
416    ''' CSFB Type values'''
417    CSFB_TYPE_REDIRECTION = "REDIRECTION"
418    CSFB_TYPE_HANDOVER = "HO"
419
420
421class ReturnToEUTRAN(Enum):
422    '''Return to EUTRAN setting values '''
423    RETEUTRAN_ENABLE = "ENABLE"
424    RETEUTRAN_DISABLE = "DISABLE"
425
426
427class CTCHSetup(Enum):
428    '''CTCH setting values '''
429    CTCH_ENABLE = "ENABLE"
430    CTCH_DISABLE = "DISABLE"
431
432
433class UEIdentityType(Enum):
434    '''UE Identity type values '''
435    IMSI = "IMSI"
436    IMEI = "IMEI"
437    IMEISV = "IMEISV"
438
439
440class CBCHSetup(Enum):
441    '''CBCH setting values '''
442    CBCH_ENABLE = "ENABLE"
443    CBCH_DISABLE = "DISABLE"
444
445
446class Switch(Enum):
447    ''' Values for ENABLE or DISABLE '''
448    ENABLE = "ENABLE"
449    DISABLE = "DISABLE"
450
451
452class MD8475A(object):
453    """Class to communicate with Anritsu MD8475A Signalling Tester.
454       This uses GPIB command to interface with Anritsu MD8475A """
455    def __init__(self, ip_address, wlan=False, md8475_version="A"):
456        self._error_reporting = True
457        self._ipaddr = ip_address
458        self.log = tracelogger.TraceLogger(logging.getLogger())
459        self._wlan = wlan
460        port_number = 28002
461        self._md8475_version = md8475_version
462        if md8475_version == "B":
463            global TERMINATOR
464            TERMINATOR = "\n"
465            port_number = 5025
466
467        # Open socket connection to Signaling Tester
468        self.log.info("Opening Socket Connection with "
469                      "Signaling Tester ({}) ".format(self._ipaddr))
470        try:
471            self._sock = socket.create_connection((self._ipaddr, port_number),
472                                                  timeout=120)
473            self.send_query("*IDN?", 60)
474            self.log.info("Communication with Signaling Tester OK.")
475            self.log.info("Opened Socket connection to ({})"
476                          "with handle ({})".format(self._ipaddr, self._sock))
477            # launching Smart Studio Application needed for the simulation
478            ret = self.launch_smartstudio()
479        except socket.timeout:
480            raise AnritsuError("Timeout happened while conencting to"
481                               " Anritsu MD8475A")
482        except socket.error:
483            raise AnritsuError("Socket creation error")
484
485    def get_BTS(self, btsnumber):
486        """ Returns the BTS object based on the BTS number provided
487
488        Args:
489            btsnumber: BTS number (BTS1, BTS2)
490
491        Returns:
492            BTS object
493        """
494        return _BaseTransceiverStation(self, btsnumber)
495
496    def get_AnritsuTestCases(self):
497        """ Returns the Anritsu Test Case Module Object
498
499        Args:
500            None
501
502        Returns:
503            Anritsu Test Case Module Object
504        """
505        return _AnritsuTestCases(self)
506
507    def get_VirtualPhone(self):
508        """ Returns the Anritsu Virtual Phone Module Object
509
510        Args:
511            None
512
513        Returns:
514            Anritsu Virtual Phone Module Object
515        """
516        return _VirtualPhone(self)
517
518    def get_PDN(self, pdn_number):
519        """ Returns the PDN Module Object
520
521        Args:
522            None
523
524        Returns:
525            Anritsu PDN Module Object
526        """
527        return _PacketDataNetwork(self, pdn_number)
528
529    def get_TriggerMessage(self):
530        """ Returns the Anritsu Trigger Message Module Object
531
532        Args:
533            None
534
535        Returns:
536            Anritsu Trigger Message Module Object
537        """
538        return _TriggerMessage(self)
539
540    def get_IMS(self, vnid):
541        """ Returns the IMS Module Object with VNID
542
543        Args:
544            vnid: Virtual Network ID
545
546        Returns:
547            Anritsu IMS VNID Module Object
548        """
549        return _IMS_Services(self, vnid)
550
551    def get_ims_cscf_status(self, virtual_network_id):
552        """ Get the IMS CSCF Status of virtual network
553
554        Args:
555            virtual_network_id: virtual network id
556
557        Returns:
558            IMS CSCF status
559        """
560        cmd = "IMSCSCFSTAT? {}".format(virtual_network_id)
561        return self.send_query(cmd)
562
563    def ims_cscf_call_action(self, virtual_network_id, action):
564        """ IMS CSCF Call action
565
566        Args:
567            virtual_network_id: virtual network id
568            action: action to make
569
570        Returns:
571            None
572        """
573        cmd = "IMSCSCFCALL {},{}".format(virtual_network_id, action)
574        self.send_command(cmd)
575
576    def send_query(self, query, sock_timeout=120):
577        """ Sends a Query message to Anritsu and return response
578
579        Args:
580            query - Query string
581
582        Returns:
583            query response
584        """
585        self.log.info("--> {}".format(query))
586        querytoSend = (query + TERMINATOR).encode('utf-8')
587        self._sock.settimeout(sock_timeout)
588        try:
589            self._sock.send(querytoSend)
590            result = self._sock.recv(ANRITSU_SOCKET_BUFFER_SIZE).rstrip(
591                TERMINATOR.encode('utf-8'))
592            response = result.decode('utf-8')
593            self.log.info('<-- {}'.format(response))
594            return response
595        except socket.timeout:
596            raise AnritsuError("Timeout: Response from Anritsu")
597        except socket.error:
598            raise AnritsuError("Socket Error")
599
600    def send_command(self, command, sock_timeout=120):
601        """ Sends a Command message to Anritsu
602
603        Args:
604            command - command string
605
606        Returns:
607            None
608        """
609        self.log.info("--> {}".format(command))
610        if self._error_reporting:
611            cmdToSend = (command + ";ERROR?" + TERMINATOR).encode('utf-8')
612            self._sock.settimeout(sock_timeout)
613            try:
614                self._sock.send(cmdToSend)
615                err = self._sock.recv(ANRITSU_SOCKET_BUFFER_SIZE).rstrip(
616                    TERMINATOR.encode('utf-8'))
617                error = int(err.decode('utf-8'))
618                if error != NO_ERROR:
619                    raise AnritsuError(error, command)
620            except socket.timeout:
621                raise AnritsuError("Timeout for Command Response from Anritsu")
622            except socket.error:
623                raise AnritsuError("Socket Error for Anritsu command")
624            except Exception as e:
625                raise AnritsuError(e, command)
626        else:
627            cmdToSend = (command + TERMINATOR).encode('utf-8')
628            try:
629                self._sock.send(cmdToSend)
630            except socket.error:
631                raise AnritsuError("Socket Error", command)
632            return
633
634    def launch_smartstudio(self):
635        """ launch the Smart studio application
636            This should be done before stating simulation
637
638        Args:
639            None
640
641        Returns:
642            None
643        """
644        # check the Smart Studio status . If Smart Studio doesn't exist ,
645        # start it.if it is running, stop it. Smart Studio should be in
646        # NOTRUN (Simulation Stopped) state to start new simulation
647        stat = self.send_query("STAT?", 30)
648        if stat == "NOTEXIST":
649            self.log.info("Launching Smart Studio Application,"
650                          "it takes about a minute.")
651            time_to_wait = SMARTSTUDIO_LAUNCH_WAIT_TIME
652            sleep_interval = 15
653            waiting_time = 0
654
655            err = self.send_command("RUN", SMARTSTUDIO_LAUNCH_WAIT_TIME)
656            stat = self.send_query("STAT?")
657            while stat != "NOTRUN":
658                time.sleep(sleep_interval)
659                waiting_time = waiting_time + sleep_interval
660                if waiting_time <= time_to_wait:
661                    stat = self.send_query("STAT?")
662                else:
663                    raise AnritsuError("Timeout: Smart Studio launch")
664        elif stat == "RUNNING":
665            # Stop simulation if necessary
666            self.send_command("STOP", 60)
667            stat = self.send_query("STAT?")
668
669        # The state of the Smart Studio should be NOTRUN at this point
670        # after the one of the steps from above
671        if stat != "NOTRUN":
672            self.log.info(
673                "Can not launch Smart Studio, "
674                "please shut down all the Smart Studio SW components")
675            raise AnritsuError("Could not run SmartStudio")
676
677    def close_smartstudio(self):
678        """ Closes the Smart studio application
679
680        Args:
681            None
682
683        Returns:
684            None
685        """
686        self.stop_simulation()
687        self.send_command("EXIT", 60)
688
689    def get_smartstudio_status(self):
690        """ Gets the Smart studio status
691
692        Args:
693            None
694
695        Returns:
696            Smart studio status
697        """
698        return self.send_query("STAT?")
699
700    def start_simulation(self):
701        """ Starting the simulation of the network model.
702            simulation model or simulation parameter file
703            should be set before starting the simulation
704
705        Args:
706          None
707
708        Returns:
709            None
710        """
711        time_to_wait = SMARTSTUDIO_SIMULATION_START_WAIT_TIME
712        sleep_interval = 2
713        waiting_time = 0
714
715        self.send_command("START", SMARTSTUDIO_SIMULATION_START_WAIT_TIME)
716
717        self.log.info("Waiting for CALLSTAT=POWEROFF")
718        callstat = self.send_query("CALLSTAT? BTS1").split(",")
719        while callstat[0] != "POWEROFF":
720            time.sleep(sleep_interval)
721            waiting_time += sleep_interval
722            if waiting_time <= time_to_wait:
723                callstat = self.send_query("CALLSTAT? BTS1").split(",")
724            else:
725                raise AnritsuError("Timeout: Starting simulation")
726
727    def stop_simulation(self):
728        """ Stop simulation operation
729
730        Args:
731          None
732
733        Returns:
734            None
735        """
736        # Stop virtual network (IMS) #1 if still running
737        # this is needed before Sync command is supported in 6.40a
738        if self.send_query("IMSVNSTAT? 1") == "RUNNING":
739            self.send_command("IMSSTOPVN 1")
740        if self.send_query("IMSVNSTAT? 2") == "RUNNING":
741            self.send_command("IMSSTOPVN 2")
742        stat = self.send_query("STAT?")
743        # Stop simulation if its is RUNNING
744        if stat == "RUNNING":
745            self.send_command("STOP", 60)
746            stat = self.send_query("STAT?")
747            if stat != "NOTRUN":
748                self.log.info("Failed to stop simulation")
749                raise AnritsuError("Failed to stop simulation")
750
751    def reset(self):
752        """ reset simulation parameters
753
754        Args:
755          None
756
757        Returns:
758            None
759        """
760        self.send_command("*RST", COMMAND_COMPLETE_WAIT_TIME)
761
762    def load_simulation_paramfile(self, filepath):
763        """ loads simulation model parameter file
764        Args:
765          filepath : simulation model parameter file path
766
767        Returns:
768            None
769        """
770        self.stop_simulation()
771        cmd = "LOADSIMPARAM \"" + filepath + '\";ERROR?'
772        self.send_query(cmd, LOAD_SIMULATION_PARAM_FILE_WAIT_TIME)
773
774    def load_cell_paramfile(self, filepath):
775        """ loads cell model parameter file
776
777        Args:
778          filepath : cell model parameter file path
779
780        Returns:
781            None
782        """
783        self.stop_simulation()
784        cmd = "LOADCELLPARAM \"" + filepath + '\";ERROR?'
785        status = int(self.send_query(cmd))
786        if status != NO_ERROR:
787            raise AnritsuError(status, cmd)
788
789    def _set_simulation_model(self, sim_model, reset=True):
790        """ Set simulation model and valid the configuration
791
792        Args:
793            sim_model: simulation model
794            reset: if True, reset the simulation after setting the new
795            simulation model
796        Returns:
797            True/False
798        """
799        error = int(
800            self.send_query("SIMMODEL %s;ERROR?" % sim_model,
801                            COMMAND_COMPLETE_WAIT_TIME))
802        if error:  # Try again if first set SIMMODEL fails
803            time.sleep(3)
804            if "WLAN" in sim_model:
805                new_sim_model = sim_model[:-5]
806                error = int(
807                    self.send_query("SIMMODEL %s;ERROR?" % new_sim_model,
808                                    COMMAND_COMPLETE_WAIT_TIME))
809                time.sleep(3)
810            error = int(
811                self.send_query("SIMMODEL %s;ERROR?" % sim_model,
812                                COMMAND_COMPLETE_WAIT_TIME))
813            if error:
814                return False
815        if reset:
816            # Reset might be necessary because SIMMODEL will load
817            # some of the contents from previous parameter files.
818            self.reset()
819        return True
820
821    def set_simulation_model(self, *bts_rats, reset=True):
822        """ Stops the simulation and then sets the simulation model.
823
824        Args:
825            *bts_rats: base station rats for BTS 1 to 5.
826            reset: if True, reset the simulation after setting the new
827            simulation model
828        Returns:
829            True or False
830        """
831        self.stop_simulation()
832        if len(bts_rats) not in range(1, 6):
833            raise ValueError(
834                "set_simulation_model requires 1 to 5 BTS values.")
835        simmodel = ",".join(bts_rat.value for bts_rat in bts_rats)
836        if self._wlan:
837            simmodel = simmodel + "," + "WLAN"
838        return self._set_simulation_model(simmodel, reset)
839
840    def get_simulation_model(self):
841        """ Gets the simulation model
842
843        Args:
844            None
845
846        Returns:
847            Current simulation model
848        """
849        cmd = "SIMMODEL?"
850        return self.send_query(cmd)
851
852    def get_lte_rrc_status_change(self):
853        """ Gets the LTE RRC status change function state
854
855        Returns:
856            Boolean: True is Enabled / False is Disabled
857        """
858        cmd = "L_RRCSTAT?"
859        return self.send_query(cmd) == "ENABLE"
860
861    def set_lte_rrc_status_change(self, status_change):
862        """ Enables or Disables the LTE RRC status change function
863
864        Returns:
865            None
866        """
867        cmd = "L_RRCSTAT "
868        if status_change:
869            cmd += "ENABLE"
870        else:
871            cmd += "DISABLE"
872        self.send_command(cmd)
873
874    def get_lte_rrc_status_change_timer(self):
875        """ Gets the LTE RRC Status Change Timer
876
877        Returns:
878            returns a status change timer integer value
879        """
880        cmd = "L_STATTMR?"
881        return self.send_query(cmd)
882
883    def set_lte_rrc_status_change_timer(self, time):
884        """ Sets the LTE RRC Status Change Timer parameter
885
886        Returns:
887            None
888        """
889        cmd = "L_STATTMR %s" % time
890        self.send_command(cmd)
891
892    def set_umts_rrc_status_change(self, status_change):
893        """ Enables or Disables the UMTS RRC status change function
894
895        Returns:
896            None
897        """
898        cmd = "W_RRCSTAT "
899        if status_change:
900            cmd += "ENABLE"
901        else:
902            cmd += "DISABLE"
903        self.send_command(cmd)
904
905    def get_umts_rrc_status_change(self):
906        """ Gets the UMTS RRC Status Change
907
908        Returns:
909            Boolean: True is Enabled / False is Disabled
910        """
911        cmd = "W_RRCSTAT?"
912        return self.send_query(cmd)
913
914    def set_umts_dch_stat_timer(self, timer_seconds):
915        """ Sets the UMTS RRC DCH timer
916
917        Returns:
918            None
919        """
920        cmd = "W_STATTMRDCH %s" % timer_seconds
921        self.send_command(cmd)
922
923    def set_simulation_state_to_poweroff(self):
924        """ Sets the simulation state to POWER OFF
925
926        Args:
927          None
928
929        Returns:
930            None
931        """
932        self.send_command("RESETSIMULATION POWEROFF")
933        time_to_wait = 30
934        sleep_interval = 2
935        waiting_time = 0
936
937        self.log.info("Waiting for CALLSTAT=POWEROFF")
938        callstat = self.send_query("CALLSTAT?").split(",")
939        while callstat[0] != "POWEROFF":
940            time.sleep(sleep_interval)
941            waiting_time = waiting_time + sleep_interval
942            if waiting_time <= time_to_wait:
943                callstat = self.send_query("CALLSTAT?").split(",")
944            else:
945                break
946
947    def set_simulation_state_to_idle(self, btsnumber):
948        """ Sets the simulation state to IDLE
949
950        Args:
951          None
952
953        Returns:
954            None
955        """
956        if not isinstance(btsnumber, BtsNumber):
957            raise ValueError(' The parameter should be of type "BtsNumber" ')
958        cmd = "RESETSIMULATION IDLE," + btsnumber.value
959        self.send_command(cmd)
960        time_to_wait = 30
961        sleep_interval = 2
962        waiting_time = 0
963
964        self.log.info("Waiting for CALLSTAT=IDLE")
965        callstat = self.send_query("CALLSTAT?").split(",")
966        while callstat[0] != "IDLE":
967            time.sleep(sleep_interval)
968            waiting_time = waiting_time + sleep_interval
969            if waiting_time <= time_to_wait:
970                callstat = self.send_query("CALLSTAT?").split(",")
971            else:
972                break
973
974    def set_trigger_message_mode(self, msg_id):
975        """ Sets the Message Mode of the trigger
976
977        Args:
978            msg_id: The hex value of the identity of an RRC/NAS message.
979
980        Returns:
981            None
982        """
983
984        if isinstance(msg_id, TriggerMessageIDs):
985            msg_id = msg_id.value
986
987        cmd = "TMMESSAGEMODE {},USERDATA".format(msg_id)
988        self.send_command(cmd)
989
990    def set_data_of_trigger_message(self, msg_id, user_data):
991        """ Sets the User Data of the trigger message
992
993        Args:
994            msg_id: The hex value of the identity of an RRC/NAS message.
995            user_data: Hex data
996
997        Returns:
998            None
999        """
1000
1001        if isinstance(msg_id, TriggerMessageIDs):
1002            msg_id = msg_id.value
1003
1004        data_len = len(user_data) * 4
1005
1006        cmd = "TMUSERDATA {}, {}, {}".format(msg_id, user_data, data_len)
1007        self.send_command(cmd)
1008
1009    def send_trigger_message(self, msg_id):
1010        """ Sends the User Data of the trigger information
1011
1012        Args:
1013            msg_id: The hex value of the identity of an RRC/NAS message.
1014
1015        Returns:
1016            None
1017        """
1018
1019        if isinstance(msg_id, TriggerMessageIDs):
1020            msg_id = msg_id.value
1021
1022        cmd = "TMSENDUSERMSG {}".format(msg_id)
1023        self.send_command(cmd)
1024
1025    def wait_for_registration_state(self,
1026                                    bts=1,
1027                                    time_to_wait=REGISTRATION_STATE_WAIT_TIME):
1028        """ Waits for UE registration state on Anritsu
1029
1030        Args:
1031          bts: index of MD8475A BTS, eg 1, 2
1032          time_to_wait: time to wait for the phone to get to registration state
1033
1034        Returns:
1035            None
1036        """
1037        self.log.info("wait for IDLE/COMMUNICATION state on anritsu.")
1038
1039        sleep_interval = 1
1040        sim_model = (self.get_simulation_model()).split(",")
1041        # wait 1 more round for GSM because of PS attach
1042        registration_check_iterations = 2 if sim_model[bts - 1] == "GSM" else 1
1043        for _ in range(registration_check_iterations):
1044            waiting_time = 0
1045            while waiting_time <= time_to_wait:
1046                callstat = self.send_query(
1047                    "CALLSTAT? BTS{}".format(bts)).split(",")
1048                if callstat[0] == "IDLE" or callstat[1] == "COMMUNICATION":
1049                    break
1050                time.sleep(sleep_interval)
1051                waiting_time += sleep_interval
1052            else:
1053                raise AnritsuError(
1054                    "UE failed to register in {} seconds".format(time_to_wait))
1055            time.sleep(sleep_interval)
1056
1057    def wait_for_communication_state(
1058            self, time_to_wait=COMMUNICATION_STATE_WAIT_TIME):
1059        """ Waits for UE communication state on Anritsu
1060
1061        Args:
1062          time_to_wait: time to wait for the phone to get to communication state
1063
1064        Returns:
1065            None
1066        """
1067        self.log.info("wait for COMMUNICATION state on anritsu")
1068        sleep_interval = 1
1069        waiting_time = 0
1070
1071        self.log.info("Waiting for CALLSTAT=COMMUNICATION")
1072        callstat = self.send_query("CALLSTAT? BTS1").split(",")
1073        while callstat[1] != "COMMUNICATION":
1074            time.sleep(sleep_interval)
1075            waiting_time += sleep_interval
1076            if waiting_time <= time_to_wait:
1077                callstat = self.send_query("CALLSTAT? BTS1").split(",")
1078            else:
1079                raise AnritsuError("UE failed to register on network")
1080
1081    def wait_for_idle_state(self, time_to_wait=IDLE_STATE_WAIT_TIME):
1082        """ Waits for UE idle state on Anritsu
1083
1084        Args:
1085          time_to_wait: time to wait for the phone to get to idle state
1086
1087        Returns:
1088            None
1089        """
1090        self.log.info("wait for IDLE state on anritsu.")
1091
1092        sleep_interval = 1
1093        waiting_time = 0
1094
1095        callstat = self.send_query("CALLSTAT? BTS1").split(",")
1096        while callstat[0] != "IDLE":
1097            time.sleep(sleep_interval)
1098            waiting_time += sleep_interval
1099            if waiting_time <= time_to_wait:
1100                callstat = self.send_query("CALLSTAT? BTS1").split(",")
1101            else:
1102                raise AnritsuError("UE failed to go on idle state")
1103
1104    def get_camping_cell(self):
1105        """ Gets the current camping cell information
1106
1107        Args:
1108          None
1109
1110        Returns:
1111            returns a tuple (BTS number, RAT Technology) '
1112        """
1113        bts_number, rat_info = self.send_query("CAMPINGCELL?").split(",")
1114        return bts_number, rat_info
1115
1116    def get_supported_bands(self, rat):
1117        """ Gets the supported bands from UE capability information
1118
1119        Args:
1120          rat: LTE or WCDMA
1121
1122        Returns:
1123            returns a list of bnads
1124        """
1125        cmd = "UEINFO? "
1126        if rat == "LTE":
1127            cmd += "L"
1128        elif rat == "WCDMA":
1129            cmd += "W"
1130        else:
1131            raise ValueError('The rat argument needs to be "LTE" or "WCDMA"')
1132        cmd += "_SupportedBand"
1133        result = self.send_query(cmd).split(",")
1134        if result == "NONE":
1135            return None
1136        if rat == "WCDMA":
1137            bands = []
1138            for band in result:
1139                bands.append(WCDMA_BANDS[band])
1140            return bands
1141        else:
1142            return result
1143
1144    def start_testcase(self):
1145        """ Starts a test case on Anritsu
1146
1147        Args:
1148          None
1149
1150        Returns:
1151            None
1152        """
1153        self.send_command("STARTTEST")
1154
1155    def get_testcase_status(self):
1156        """ Gets the current test case status on Anritsu
1157
1158        Args:
1159          None
1160
1161        Returns:
1162            current test case status
1163        """
1164        return self.send_query("TESTSTAT?")
1165
1166    def start_ip_traffic(self, pdn='1'):
1167        """ Starts IP data traffic with the selected PDN.
1168
1169        Args:
1170            pdn: the pdn to be used for data traffic. Defaults to '1'.
1171        """
1172        self.send_command('OPERATEIPTRAFFIC START,' + pdn)
1173
1174    def stop_ip_traffic(self, pdn='1'):
1175        """ Stops IP data traffic with the selected PDN.
1176
1177         Args:
1178            pdn: pdn for which data traffic has to be stopped. Defaults to '1'.
1179        """
1180        self.send_command('OPERATEIPTRAFFIC STOP,' + pdn)
1181
1182    def set_carrier_aggregation_enabled(self, enabled=True):
1183        """ Enables or disables de carrier aggregation option.
1184
1185        Args:
1186            enabled: enables CA if True and disables CA if False.
1187        """
1188        cmd = 'CA ' + 'ENABLE' if enabled else 'DISABLE'
1189        self.send_command(cmd)
1190
1191    # Common Default Gateway:
1192    @property
1193    def gateway_ipv4addr(self):
1194        """ Gets the IPv4 address of the default gateway
1195
1196        Args:
1197          None
1198
1199        Returns:
1200            current UE status
1201        """
1202        return self.send_query("DGIPV4?")
1203
1204    @gateway_ipv4addr.setter
1205    def gateway_ipv4addr(self, ipv4_addr):
1206        """ sets the IPv4 address of the default gateway
1207        Args:
1208            ipv4_addr: IPv4 address of the default gateway
1209
1210        Returns:
1211            None
1212        """
1213        cmd = "DGIPV4 " + ipv4_addr
1214        self.send_command(cmd)
1215
1216    @property
1217    def gateway_ipv6addr(self):
1218        """ Gets the IPv6 address of the default gateway
1219
1220        Args:
1221          None
1222
1223        Returns:
1224            current UE status
1225        """
1226        return self.send_query("DGIPV6?")
1227
1228    @gateway_ipv6addr.setter
1229    def gateway_ipv6addr(self, ipv6_addr):
1230        """ sets the IPv6 address of the default gateway
1231        Args:
1232            ipv6_addr: IPv6 address of the default gateway
1233
1234        Returns:
1235            None
1236        """
1237        cmd = "DGIPV6 " + ipv6_addr
1238        self.send_command(cmd)
1239
1240    @property
1241    def usim_key(self):
1242        """ Gets the USIM Security Key
1243
1244        Args:
1245          None
1246
1247        Returns:
1248            USIM Security Key
1249        """
1250        return self.send_query("USIMK?")
1251
1252    @usim_key.setter
1253    def usim_key(self, usimk):
1254        """ sets the USIM Security Key
1255        Args:
1256            usimk: USIM Security Key, eg "000102030405060708090A0B0C0D0E0F"
1257
1258        Returns:
1259            None
1260        """
1261        cmd = "USIMK " + usimk
1262        self.send_command(cmd)
1263
1264    def get_ue_status(self):
1265        """ Gets the current UE status on Anritsu
1266
1267        Args:
1268          None
1269
1270        Returns:
1271            current UE status
1272        """
1273        UE_STATUS_INDEX = 0
1274        ue_status = self.send_query("CALLSTAT?").split(",")[UE_STATUS_INDEX]
1275        return _PROCESS_STATES[ue_status]
1276
1277    def get_packet_status(self):
1278        """ Gets the current Packet status on Anritsu
1279
1280        Args:
1281          None
1282
1283        Returns:
1284            current Packet status
1285        """
1286        PACKET_STATUS_INDEX = 1
1287        packet_status = self.send_query("CALLSTAT?").split(
1288            ",")[PACKET_STATUS_INDEX]
1289        return _PROCESS_STATES[packet_status]
1290
1291    def disconnect(self):
1292        """ Disconnect the Anritsu box from test PC
1293
1294        Args:
1295          None
1296
1297        Returns:
1298            None
1299        """
1300        # no need to # exit smart studio application
1301        # self.close_smartstudio()
1302        self._sock.close()
1303
1304    def machine_reboot(self):
1305        """ Reboots the Anritsu Machine
1306
1307        Args:
1308          None
1309
1310        Returns:
1311            None
1312        """
1313        self.send_command("REBOOT")
1314
1315    def save_sequence_log(self, fileName):
1316        """ Saves the Anritsu Sequence logs to file
1317
1318        Args:
1319          fileName: log file name
1320
1321        Returns:
1322            None
1323        """
1324        cmd = 'SAVESEQLOG "{}"'.format(fileName)
1325        self.send_command(cmd)
1326
1327    def clear_sequence_log(self):
1328        """ Clears the Anritsu Sequence logs
1329
1330        Args:
1331          None
1332
1333        Returns:
1334            None
1335        """
1336        self.send_command("CLEARSEQLOG")
1337
1338    def save_message_log(self, fileName):
1339        """ Saves the Anritsu Message logs to file
1340
1341        Args:
1342          fileName: log file name
1343
1344        Returns:
1345            None
1346        """
1347        cmd = 'SAVEMSGLOG "{}"'.format(fileName)
1348        self.send_command(cmd)
1349
1350    def clear_message_log(self):
1351        """ Clears the Anritsu Message logs
1352
1353        Args:
1354          None
1355
1356        Returns:
1357            None
1358        """
1359        self.send_command("CLEARMSGLOG")
1360
1361    def save_trace_log(self, fileName, fileType, overwrite, start, end):
1362        """ Saves the Anritsu Trace logs
1363
1364        Args:
1365          fileName: log file name
1366          fileType: file type (BINARY, TEXT, H245,PACKET, CPLABE)
1367          overwrite: whether to over write
1368          start: starting trace number
1369          end: ending trace number
1370
1371        Returns:
1372            None
1373        """
1374        cmd = 'SAVETRACELOG "{}",{},{},{},{}'.format(fileName, fileType,
1375                                                     overwrite, start, end)
1376        self.send_command(cmd)
1377
1378    def send_cmas_lte_wcdma(self, serialNo, messageID, warningMessage):
1379        """ Sends a CMAS message
1380
1381        Args:
1382          serialNo: serial number of CMAS message
1383          messageID: CMAS message ID
1384          warningMessage:  CMAS Warning message
1385
1386        Returns:
1387            None
1388        """
1389        cmd = ('PWSSENDWM 3GPP,"BtsNo=1&WarningSystem=CMAS&SerialNo={}'
1390               '&MessageID={}&wm={}"').format(serialNo, messageID,
1391                                              warningMessage)
1392        self.send_command(cmd)
1393
1394    def send_etws_lte_wcdma(self, serialNo, messageID, warningType,
1395                            warningMessage, userAlertenable, popUpEnable):
1396        """ Sends a ETWS message
1397
1398        Args:
1399          serialNo: serial number of CMAS message
1400          messageID: CMAS message ID
1401          warningMessage:  CMAS Warning message
1402
1403        Returns:
1404            None
1405        """
1406        cmd = (
1407            'PWSSENDWM 3GPP,"BtsNo=1&WarningSystem=ETWS&SerialNo={}&'
1408            'Primary=ON&PrimaryMessageID={}&Secondary=ON&SecondaryMessageID={}'
1409            '&WarningType={}&wm={}&UserAlert={}&Popup={}&dcs=0x10&LanguageCode=en"'
1410        ).format(serialNo, messageID, messageID, warningType, warningMessage,
1411                 userAlertenable, popUpEnable)
1412        self.send_command(cmd)
1413
1414    def send_cmas_etws_cdma1x(self, message_id, service_category, alert_ext,
1415                              response_type, severity, urgency, certainty):
1416        """ Sends a CMAS/ETWS message on CDMA 1X
1417
1418        Args:
1419          serviceCategory: service category of alert
1420          messageID: message ID
1421          alertText: Warning message
1422
1423        Returns:
1424            None
1425        """
1426        cmd = (
1427            'PWSSENDWM 3GPP2,"BtsNo=1&ServiceCategory={}&MessageID={}&AlertText={}&'
1428            'CharSet=ASCII&ResponseType={}&Severity={}&Urgency={}&Certainty={}"'
1429        ).format(service_category, message_id, alert_ext, response_type,
1430                 severity, urgency, certainty)
1431        self.send_command(cmd)
1432
1433    @property
1434    def csfb_type(self):
1435        """ Gets the current CSFB type
1436
1437        Args:
1438            None
1439
1440        Returns:
1441            current CSFB type
1442        """
1443        return self.send_query("SIMMODELEX? CSFB")
1444
1445    @csfb_type.setter
1446    def csfb_type(self, csfb_type):
1447        """ sets the CSFB type
1448        Args:
1449            csfb_type: CSFB type
1450
1451        Returns:
1452            None
1453        """
1454        if not isinstance(csfb_type, CsfbType):
1455            raise ValueError('The parameter should be of type "CsfbType" ')
1456        cmd = "SIMMODELEX CSFB," + csfb_type.value
1457        self.send_command(cmd)
1458
1459    @property
1460    def csfb_return_to_eutran(self):
1461        """ Gets the current return to EUTRAN status
1462
1463        Args:
1464            None
1465
1466        Returns:
1467            current return to EUTRAN status
1468        """
1469        return self.send_query("SIMMODELEX? RETEUTRAN")
1470
1471    @csfb_return_to_eutran.setter
1472    def csfb_return_to_eutran(self, enable):
1473        """ sets the return to EUTRAN feature
1474        Args:
1475            enable: enable/disable return to EUTRAN feature
1476
1477        Returns:
1478            None
1479        """
1480        if not isinstance(enable, ReturnToEUTRAN):
1481            raise ValueError(
1482                'The parameter should be of type "ReturnToEUTRAN"')
1483        cmd = "SIMMODELEX RETEUTRAN," + enable.value
1484        self.send_command(cmd)
1485
1486    def set_packet_preservation(self):
1487        """ Set packet state to Preservation
1488
1489        Args:
1490            None
1491
1492        Returns:
1493            None
1494        """
1495        cmd = "OPERATEPACKET PRESERVATION"
1496        self.send_command(cmd)
1497
1498    def set_packet_dormant(self):
1499        """ Set packet state to Dormant
1500
1501        Args:
1502            None
1503
1504        Returns:
1505            None
1506        """
1507        cmd = "OPERATEPACKET DORMANT"
1508        self.send_command(cmd)
1509
1510    def get_ue_identity(self, identity_type):
1511        """ Get the UE identity IMSI, IMEI, IMEISV
1512
1513        Args:
1514            identity_type : IMSI/IMEI/IMEISV
1515
1516        Returns:
1517            IMSI/IMEI/IMEISV value
1518        """
1519        bts, rat = self.get_camping_cell()
1520        if rat == BtsTechnology.LTE.value:
1521            identity_request = TriggerMessageIDs.IDENTITY_REQUEST_LTE.value
1522            if identity_type == UEIdentityType.IMSI:
1523                userdata = IMSI_READ_USERDATA_LTE
1524            elif identity_type == UEIdentityType.IMEI:
1525                userdata = IMEI_READ_USERDATA_LTE
1526            elif identity_type == UEIdentityType.IMEISV:
1527                userdata = IMEISV_READ_USERDATA_LTE
1528            else:
1529                return None
1530        elif rat == BtsTechnology.WCDMA.value:
1531            identity_request = TriggerMessageIDs.IDENTITY_REQUEST_WCDMA.value
1532            if identity_type == UEIdentityType.IMSI:
1533                userdata = IMSI_READ_USERDATA_WCDMA
1534            elif identity_type == UEIdentityType.IMEI:
1535                userdata = IMEI_READ_USERDATA_WCDMA
1536            elif identity_type == UEIdentityType.IMEISV:
1537                userdata = IMEISV_READ_USERDATA_WCDMA
1538            else:
1539                return None
1540        elif rat == BtsTechnology.GSM.value:
1541            identity_request = TriggerMessageIDs.IDENTITY_REQUEST_GSM.value
1542            if identity_type == UEIdentityType.IMSI:
1543                userdata = IMSI_READ_USERDATA_GSM
1544            elif identity_type == UEIdentityType.IMEI:
1545                userdata = IMEI_READ_USERDATA_GSM
1546            elif identity_type == UEIdentityType.IMEISV:
1547                userdata = IMEISV_READ_USERDATA_GSM
1548            else:
1549                return None
1550        else:
1551            return None
1552
1553        self.send_command("TMMESSAGEMODE {},USERDATA".format(identity_request))
1554        time.sleep(SETTLING_TIME)
1555        self.send_command("TMUSERDATA {}, {}, {}".format(
1556            identity_request, userdata, IDENTITY_REQ_DATA_LEN))
1557        time.sleep(SETTLING_TIME)
1558        self.send_command("TMSENDUSERMSG {}".format(identity_request))
1559        time.sleep(WAIT_TIME_IDENTITY_RESPONSE)
1560        # Go through sequence log and find the identity response message
1561        target = '"{}"'.format(identity_type.value)
1562        seqlog = self.send_query("SEQLOG?").split(",")
1563        while (target not in seqlog):
1564            index = int(seqlog[0]) - 1
1565            if index < SEQ_LOG_MESSAGE_START_INDEX:
1566                self.log.error("Can not find " + target)
1567                return None
1568            seqlog = self.send_query("SEQLOG? %d" % index).split(",")
1569        return (seqlog[-1])
1570
1571    def trigger_ue_capability_enquiry(self, requested_bands):
1572        """ Triggers LTE RRC UE capability enquiry from callbox.
1573
1574        Args:
1575            requested_bands: User data in hex format
1576        """
1577        self.set_trigger_message_mode(TriggerMessageIDs.UE_CAPABILITY_ENQUIRY)
1578        time.sleep(SETTLING_TIME)
1579        self.set_data_of_trigger_message(
1580            TriggerMessageIDs.UE_CAPABILITY_ENQUIRY, requested_bands)
1581        time.sleep(SETTLING_TIME)
1582        self.send_trigger_message(TriggerMessageIDs.UE_CAPABILITY_ENQUIRY)
1583        time.sleep(SETTLING_TIME)
1584
1585    def get_measured_pusch_power(self):
1586        """ Queries the PUSCH power.
1587
1588        Returns:
1589            A string indicating PUSCH power in each input port.
1590        """
1591        return self.send_query("MONITOR? UL_PUSCH")
1592
1593    def select_usim(self, usim):
1594        """ Select pre-defined Anritsu USIM models
1595
1596        Args:
1597            usim: any of P0035Bx, P0135Ax, P0250Ax, P0260Ax
1598
1599        Returns:
1600            None
1601        """
1602        cmd = "SELECTUSIM {}".format(usim)
1603        self.send_command(cmd)
1604
1605
1606class _AnritsuTestCases(object):
1607    '''Class to interact with the MD8475 supported test procedures '''
1608    def __init__(self, anritsu):
1609        self._anritsu = anritsu
1610        self.log = anritsu.log
1611
1612    @property
1613    def procedure(self):
1614        """ Gets the current Test Procedure type
1615
1616        Args:
1617            None
1618
1619        Returns:
1620            One of TestProcedure type values
1621        """
1622        return self._anritsu.send_query("TESTPROCEDURE?")
1623
1624    @procedure.setter
1625    def procedure(self, procedure):
1626        """ sets the Test Procedure type
1627        Args:
1628            procedure: One of TestProcedure type values
1629
1630        Returns:
1631            None
1632        """
1633        if not isinstance(procedure, TestProcedure):
1634            raise ValueError(
1635                'The parameter should be of type "TestProcedure" ')
1636        cmd = "TESTPROCEDURE " + procedure.value
1637        self._anritsu.send_command(cmd)
1638
1639    @property
1640    def bts_direction(self):
1641        """ Gets the current Test direction
1642
1643         Args:
1644            None
1645
1646        Returns:
1647            Current Test direction eg:BTS2,BTS1
1648        """
1649        return self._anritsu.send_query("TESTBTSDIRECTION?")
1650
1651    @bts_direction.setter
1652    def bts_direction(self, direction):
1653        """ sets the Test direction  eg: BTS1 to BTS2 '''
1654
1655        Args:
1656            direction: tuple (from-bts,to_bts) of type BtsNumber
1657
1658        Returns:
1659            None
1660        """
1661        if not isinstance(direction, tuple) or len(direction) != 2:
1662            raise ValueError("Pass a tuple with two items")
1663        from_bts, to_bts = direction
1664        if (isinstance(from_bts, BtsNumber) and isinstance(to_bts, BtsNumber)):
1665            cmd = "TESTBTSDIRECTION {},{}".format(from_bts.value, to_bts.value)
1666            self._anritsu.send_command(cmd)
1667        else:
1668            raise ValueError(' The parameters should be of type "BtsNumber" ')
1669
1670    @property
1671    def registration_timeout(self):
1672        """ Gets the current Test registration timeout
1673
1674        Args:
1675            None
1676
1677        Returns:
1678            Current test registration timeout value
1679        """
1680        return self._anritsu.send_query("TESTREGISTRATIONTIMEOUT?")
1681
1682    @registration_timeout.setter
1683    def registration_timeout(self, timeout_value):
1684        """ sets the Test registration timeout value
1685        Args:
1686            timeout_value: test registration timeout value
1687
1688        Returns:
1689            None
1690        """
1691        cmd = "TESTREGISTRATIONTIMEOUT " + str(timeout_value)
1692        self._anritsu.send_command(cmd)
1693
1694    @property
1695    def power_control(self):
1696        """ Gets the power control enabled/disabled status for test case
1697
1698        Args:
1699            None
1700
1701        Returns:
1702            current power control enabled/disabled status
1703        """
1704        return self._anritsu.send_query("TESTPOWERCONTROL?")
1705
1706    @power_control.setter
1707    def power_control(self, enable):
1708        """ Sets the power control enabled/disabled status for test case
1709
1710        Args:
1711            enable:  enabled/disabled
1712
1713        Returns:
1714            None
1715        """
1716        if not isinstance(enable, TestPowerControl):
1717            raise ValueError(' The parameter should be of type'
1718                             ' "TestPowerControl" ')
1719        cmd = "TESTPOWERCONTROL " + enable.value
1720        self._anritsu.send_command(cmd)
1721
1722    @property
1723    def measurement_LTE(self):
1724        """ Checks measurement status for LTE test case
1725
1726        Args:
1727            None
1728
1729        Returns:
1730            Enabled/Disabled
1731        """
1732        return self._anritsu.send_query("TESTMEASUREMENT? LTE")
1733
1734    @measurement_LTE.setter
1735    def measurement_LTE(self, enable):
1736        """ Sets the measurement enabled/disabled status for LTE test case
1737
1738        Args:
1739            enable:  enabled/disabled
1740
1741        Returns:
1742            None
1743        """
1744        if not isinstance(enable, TestMeasurement):
1745            raise ValueError(' The parameter should be of type'
1746                             ' "TestMeasurement" ')
1747        cmd = "TESTMEASUREMENT LTE," + enable.value
1748        self._anritsu.send_command(cmd)
1749
1750    @property
1751    def measurement_WCDMA(self):
1752        """ Checks measurement status for WCDMA test case
1753
1754        Args:
1755            None
1756
1757        Returns:
1758            Enabled/Disabled
1759        """
1760        return self._anritsu.send_query("TESTMEASUREMENT? WCDMA")
1761
1762    @measurement_WCDMA.setter
1763    def measurement_WCDMA(self, enable):
1764        """ Sets the measurement enabled/disabled status for WCDMA test case
1765
1766        Args:
1767            enable:  enabled/disabled
1768
1769        Returns:
1770            None
1771        """
1772        if not isinstance(enable, TestMeasurement):
1773            raise ValueError(' The parameter should be of type'
1774                             ' "TestMeasurement" ')
1775        cmd = "TESTMEASUREMENT WCDMA," + enable.value
1776        self._anritsu.send_command(cmd)
1777
1778    @property
1779    def measurement_TDSCDMA(self):
1780        """ Checks measurement status for TDSCDMA test case
1781
1782        Args:
1783            None
1784
1785        Returns:
1786            Enabled/Disabled
1787        """
1788        return self._anritsu.send_query("TESTMEASUREMENT? TDSCDMA")
1789
1790    @measurement_TDSCDMA.setter
1791    def measurement_WCDMA(self, enable):
1792        """ Sets the measurement enabled/disabled status for TDSCDMA test case
1793
1794        Args:
1795            enable:  enabled/disabled
1796
1797        Returns:
1798            None
1799        """
1800        if not isinstance(enable, TestMeasurement):
1801            raise ValueError(' The parameter should be of type'
1802                             ' "TestMeasurement" ')
1803        cmd = "TESTMEASUREMENT TDSCDMA," + enable.value
1804        self._anritsu.send_command(cmd)
1805
1806    def set_pdn_targeteps(self, pdn_order, pdn_number=1):
1807        """ Sets PDN to connect as a target when performing the
1808           test case for packet handover
1809
1810        Args:
1811            pdn_order:  PRIORITY/USER
1812            pdn_number: Target PDN number
1813
1814        Returns:
1815            None
1816        """
1817        cmd = "TESTPDNTARGETEPS " + pdn_order
1818        if pdn_order == "USER":
1819            cmd = cmd + "," + str(pdn_number)
1820        self._anritsu.send_command(cmd)
1821
1822
1823class _BaseTransceiverStation(object):
1824    '''Class to interact different BTS supported by MD8475 '''
1825    def __init__(self, anritsu, btsnumber):
1826        if not isinstance(btsnumber, BtsNumber):
1827            raise ValueError(' The parameter should be of type "BtsNumber" ')
1828        self._bts_number = btsnumber.value
1829        self._anritsu = anritsu
1830        self.log = anritsu.log
1831
1832    @property
1833    def output_level(self):
1834        """ Gets the Downlink power of the cell
1835
1836        Args:
1837            None
1838
1839        Returns:
1840            DL Power level
1841        """
1842        cmd = "OLVL? " + self._bts_number
1843        return self._anritsu.send_query(cmd)
1844
1845    @output_level.setter
1846    def output_level(self, level):
1847        """ Sets the Downlink power of the cell
1848
1849        Args:
1850            level: Power level
1851
1852        Returns:
1853            None
1854        """
1855        counter = 1
1856        while float(level) != float(self.output_level):
1857            if counter > 3:
1858                raise AnritsuError("Fail to set output level in 3 tries!")
1859            cmd = "OLVL {},{}".format(level, self._bts_number)
1860            self._anritsu.send_command(cmd)
1861            counter += 1
1862            time.sleep(1)
1863
1864    @property
1865    def input_level(self):
1866        """ Gets the reference power of the cell
1867
1868        Args:
1869            None
1870
1871        Returns:
1872            Reference Power level
1873        """
1874        cmd = "RFLVL? " + self._bts_number
1875        return self._anritsu.send_query(cmd)
1876
1877    @input_level.setter
1878    def input_level(self, level):
1879        """ Sets the reference power of the cell
1880
1881        Args:
1882            level: Power level
1883
1884        Returns:
1885            None
1886        """
1887        counter = 1
1888        while float(level) != float(self.input_level):
1889            if counter > 3:
1890                raise AnritsuError("Fail to set intput level in 3 tries!")
1891            cmd = "RFLVL {},{}".format(level, self._bts_number)
1892            self._anritsu.send_command(cmd)
1893            counter += 1
1894            time.sleep(1)
1895
1896    @property
1897    def band(self):
1898        """ Gets the Band of the cell
1899
1900        Args:
1901            None
1902
1903        Returns:
1904            Cell band
1905        """
1906        cmd = "BAND? " + self._bts_number
1907        return self._anritsu.send_query(cmd)
1908
1909    @band.setter
1910    def band(self, band):
1911        """ Sets the Band of the cell
1912
1913        Args:
1914            band: Band of the cell
1915
1916        Returns:
1917            None
1918        """
1919        cmd = "BAND {},{}".format(band, self._bts_number)
1920        self._anritsu.send_command(cmd)
1921
1922    @property
1923    def transmode(self):
1924        """ Gets the Transmission Mode of the cell
1925
1926        Args:
1927            None
1928
1929        Returns:
1930            Transmission mode
1931        """
1932        cmd = "TRANSMODE? " + self._bts_number
1933        return self._anritsu.send_query(cmd)
1934
1935    @transmode.setter
1936    def transmode(self, tm_mode):
1937        """ Sets the TM of the cell
1938
1939        Args:
1940            TM: TM of the cell
1941
1942        Returns:
1943            None
1944        """
1945        cmd = "TRANSMODE {},{}".format(tm_mode, self._bts_number)
1946        self._anritsu.send_command(cmd)
1947
1948    @property
1949    def duplex_mode(self):
1950        """ Gets the Duplex Mode of the cell
1951
1952        Args:
1953            None
1954
1955        Returns:
1956            Duplex mode
1957        """
1958        cmd = "DUPLEXMODE? " + self._bts_number
1959        return self._anritsu.send_query(cmd)
1960
1961    @duplex_mode.setter
1962    def duplex_mode(self, mode):
1963        """ Sets the duplex mode for the cell
1964
1965        Args:
1966            mode: string indicating FDD or TDD
1967
1968        Returns:
1969            None
1970        """
1971        cmd = "DUPLEXMODE {},{}".format(mode, self._bts_number)
1972        self._anritsu.send_command(cmd)
1973
1974    @property
1975    def uldl_configuration(self):
1976        """ Gets the UL/DL pattern configuration for TDD bands
1977
1978        Args:
1979            None
1980
1981        Returns:
1982            Configuration number
1983        """
1984        cmd = "ULDLCONFIGURATION? " + self._bts_number
1985        return self._anritsu.send_query(cmd)
1986
1987    @uldl_configuration.setter
1988    def uldl_configuration(self, configuration):
1989        """ Sets the UL/DL pattern configuration for TDD bands
1990
1991        Args:
1992            configuration: configuration number, [ 0, 6 ] inclusive
1993
1994        Returns:
1995            None
1996
1997        Raises:
1998            ValueError: Frame structure has to be [ 0, 6 ] inclusive
1999        """
2000        if configuration not in range(0, 7):
2001            raise ValueError("The frame structure configuration has to be a "
2002                             "number between 0 and 6 inclusive")
2003
2004        cmd = "ULDLCONFIGURATION {},{}".format(configuration, self._bts_number)
2005        self._anritsu.send_command(cmd)
2006
2007    @property
2008    def cfi(self):
2009        """ Gets the Control Format Indicator for this base station.
2010
2011        Args:
2012            None
2013
2014        Returns:
2015            The CFI number.
2016        """
2017        cmd = "CFI? " + self._bts_number
2018        return self._anritsu.send_query(cmd)
2019
2020    @cfi.setter
2021    def cfi(self, cfi):
2022        """ Sets the Control Format Indicator for this base station.
2023
2024        Args:
2025            cfi: one of BESTEFFORT, AUTO, 1, 2 or 3.
2026
2027        Returns:
2028            None
2029
2030        Raises:
2031            ValueError: if cfi's value is invalid
2032        """
2033
2034        cfi = str(cfi)
2035
2036        valid_values = {'BESTEFFORT', 'AUTO', '1', '2', '3'}
2037        if cfi not in valid_values:
2038            raise ValueError('Valid values for CFI are %r' % valid_values)
2039
2040        cmd = "CFI {},{}".format(cfi, self._bts_number)
2041        self._anritsu.send_command(cmd)
2042
2043    @property
2044    def paging_duration(self):
2045        """ Gets the paging cycle duration for this base station.
2046
2047        Args:
2048            None
2049
2050        Returns:
2051            The paging cycle duration in milliseconds.
2052        """
2053        cmd = "PCYCLE? " + self._bts_number
2054        return self._anritsu.send_query(cmd)
2055
2056    @paging_duration.setter
2057    def paging_duration(self, duration):
2058        """ Sets the paging cycle duration for this base station.
2059
2060        Args:
2061            duration: the paging cycle duration in milliseconds.
2062
2063        Returns:
2064            None
2065
2066        Raises:
2067            ValueError: if duration's value is invalid
2068        """
2069
2070        duration = int(duration)
2071
2072        valid_values = {320, 640, 1280, 2560}
2073        if duration not in valid_values:
2074            raise ValueError('Valid values for the paging cycle duration are '
2075                             '%r.' % valid_values)
2076
2077        cmd = "PCYCLE {},{}".format(duration, self._bts_number)
2078        self._anritsu.send_command(cmd)
2079
2080    @property
2081    def phich_resource(self):
2082        """ Gets the PHICH Resource setting for this base station.
2083
2084        Args:
2085            None
2086
2087        Returns:
2088            The PHICH Resource setting.
2089        """
2090        cmd = "PHICHRESOURCE? " + self._bts_number
2091        return self._anritsu.send_query(cmd)
2092
2093    @phich_resource.setter
2094    def phich_resource(self, phich):
2095        """ Sets the PHICH Resource setting for this base station.
2096
2097        Args:
2098            phich: one of 1/6, 1/2, 1, 2.
2099
2100        Returns:
2101            None
2102
2103        Raises:
2104            ValueError: if phich's value is invalid
2105        """
2106
2107        phich = str(phich)
2108
2109        valid_values = ['1/6', '1/2', '1', '2']
2110        if phich not in valid_values:
2111            raise ValueError('Valid values for PHICH Resource are %r' %
2112                             valid_values)
2113
2114        cmd = "PHICHRESOURCE {},{}".format(phich, self._bts_number)
2115        self._anritsu.send_command(cmd)
2116
2117    @property
2118    def tdd_special_subframe(self):
2119        """ Gets SPECIALSUBFRAME of cell.
2120
2121        Args:
2122            None
2123
2124        Returns:
2125            tdd_special_subframe: integer between 0,9 inclusive
2126        """
2127        cmd = "SPECIALSUBFRAME? " + self._bts_number
2128        tdd_special_subframe = int(self._anritsu.send_query(cmd))
2129        return tdd_special_subframe
2130
2131    @tdd_special_subframe.setter
2132    def tdd_special_subframe(self, tdd_special_subframe):
2133        """ Sets SPECIALSUBFRAME of cell.
2134
2135        Args:
2136            tdd_special_subframe: int between 0,9 inclusive
2137
2138        Returns:
2139            None
2140
2141        Raises:
2142            ValueError: tdd_special_subframe has to be between 0,9 inclusive
2143        """
2144        if tdd_special_subframe not in range(0, 10):
2145            raise ValueError("The special subframe config is not [0,9]")
2146        cmd = "SPECIALSUBFRAME {},{}".format(tdd_special_subframe,
2147                                             self._bts_number)
2148        self._anritsu.send_command(cmd)
2149
2150    @property
2151    def dl_antenna(self):
2152        """ Gets the DL ANTENNA count of the cell
2153
2154        Args:
2155            None
2156
2157        Returns:
2158            No of DL Antenna
2159        """
2160        cmd = "ANTENNAS? " + self._bts_number
2161        return self._anritsu.send_query(cmd)
2162
2163    @dl_antenna.setter
2164    def dl_antenna(self, num_antenna):
2165        """ Sets the DL ANTENNA of the cell
2166
2167        Args:
2168            c: DL ANTENNA of the cell
2169
2170        Returns:
2171            None
2172        """
2173        cmd = "ANTENNAS {},{}".format(num_antenna, self._bts_number)
2174        self._anritsu.send_command(cmd)
2175
2176    @property
2177    def bandwidth(self):
2178        """ Gets the channel bandwidth of the cell
2179
2180        Args:
2181            None
2182
2183        Returns:
2184            channel bandwidth
2185        """
2186        cmd = "BANDWIDTH? " + self._bts_number
2187        return self._anritsu.send_query(cmd)
2188
2189    @bandwidth.setter
2190    def bandwidth(self, bandwidth):
2191        """ Sets the channel bandwidth of the cell
2192
2193        Args:
2194            bandwidth: channel bandwidth  of the cell
2195
2196        Returns:
2197            None
2198        """
2199        if not isinstance(bandwidth, BtsBandwidth):
2200            raise ValueError(' The parameter should be of type "BtsBandwidth"')
2201        cmd = "BANDWIDTH {},{}".format(bandwidth.value, self._bts_number)
2202        self._anritsu.send_command(cmd)
2203
2204    @property
2205    def dl_bandwidth(self):
2206        """ Gets the downlink bandwidth of the cell
2207
2208        Args:
2209            None
2210
2211        Returns:
2212            downlink bandwidth
2213        """
2214        cmd = "DLBANDWIDTH? " + self._bts_number
2215        return self._anritsu.send_query(cmd)
2216
2217    @dl_bandwidth.setter
2218    def dl_bandwidth(self, bandwidth):
2219        """ Sets the downlink bandwidth of the cell
2220
2221        Args:
2222            bandwidth: downlink bandwidth of the cell
2223
2224        Returns:
2225            None
2226        """
2227        if not isinstance(bandwidth, BtsBandwidth):
2228            raise ValueError(' The parameter should be of type "BtsBandwidth"')
2229        cmd = "DLBANDWIDTH {},{}".format(bandwidth.value, self._bts_number)
2230        self._anritsu.send_command(cmd)
2231
2232    @property
2233    def ul_bandwidth(self):
2234        """ Gets the uplink bandwidth of the cell
2235
2236        Args:
2237            None
2238
2239        Returns:
2240            uplink bandwidth
2241        """
2242        cmd = "ULBANDWIDTH? " + self._bts_number
2243        return self._anritsu.send_query(cmd)
2244
2245    @ul_bandwidth.setter
2246    def ul_bandwidth(self, bandwidth):
2247        """ Sets the uplink bandwidth of the cell
2248
2249        Args:
2250            bandwidth: uplink bandwidth of the cell
2251
2252        Returns:
2253            None
2254        """
2255        if not isinstance(bandwidth, BtsBandwidth):
2256            raise ValueError(
2257                ' The parameter should be of type "BtsBandwidth" ')
2258        cmd = "ULBANDWIDTH {},{}".format(bandwidth.value, self._bts_number)
2259        self._anritsu.send_command(cmd)
2260
2261    @property
2262    def packet_rate(self):
2263        """ Gets the packet rate of the cell
2264
2265        Args:
2266            None
2267
2268        Returns:
2269            packet rate
2270        """
2271        cmd = "PACKETRATE? " + self._bts_number
2272        return self._anritsu.send_query(cmd)
2273
2274    @packet_rate.setter
2275    def packet_rate(self, packetrate):
2276        """ Sets the packet rate of the cell
2277
2278        Args:
2279            packetrate: packet rate of the cell
2280
2281        Returns:
2282            None
2283        """
2284        if not isinstance(packetrate, BtsPacketRate):
2285            raise ValueError(' The parameter should be of type'
2286                             ' "BtsPacketRate" ')
2287        cmd = "PACKETRATE {},{}".format(packetrate.value, self._bts_number)
2288        self._anritsu.send_command(cmd)
2289
2290    @property
2291    def ul_windowsize(self):
2292        """ Gets the uplink window size of the cell
2293
2294        Args:
2295            None
2296
2297        Returns:
2298            uplink window size
2299        """
2300        cmd = "ULWINSIZE? " + self._bts_number
2301        return self._anritsu.send_query(cmd)
2302
2303    @ul_windowsize.setter
2304    def ul_windowsize(self, windowsize):
2305        """ Sets the uplink window size of the cell
2306
2307        Args:
2308            windowsize: uplink window size of the cell
2309
2310        Returns:
2311            None
2312        """
2313        if not isinstance(windowsize, BtsPacketWindowSize):
2314            raise ValueError(' The parameter should be of type'
2315                             ' "BtsPacketWindowSize" ')
2316        cmd = "ULWINSIZE {},{}".format(windowsize.value, self._bts_number)
2317        self._anritsu.send_command(cmd)
2318
2319    @property
2320    def dl_windowsize(self):
2321        """ Gets the downlink window size of the cell
2322
2323        Args:
2324            None
2325
2326        Returns:
2327            downlink window size
2328        """
2329        cmd = "DLWINSIZE? " + self._bts_number
2330        return self._anritsu.send_query(cmd)
2331
2332    @dl_windowsize.setter
2333    def dl_windowsize(self, windowsize):
2334        """ Sets the downlink window size of the cell
2335
2336        Args:
2337            windowsize: downlink window size of the cell
2338
2339        Returns:
2340            None
2341        """
2342        if not isinstance(windowsize, BtsPacketWindowSize):
2343            raise ValueError(' The parameter should be of type'
2344                             ' "BtsPacketWindowSize" ')
2345        cmd = "DLWINSIZE {},{}".format(windowsize.value, self._bts_number)
2346        self._anritsu.send_command(cmd)
2347
2348    @property
2349    def service_state(self):
2350        """ Gets the service state of BTS
2351
2352        Args:
2353            None
2354
2355        Returns:
2356            service state IN/OUT
2357        """
2358        cmd = "OUTOFSERVICE? " + self._bts_number
2359        return self._anritsu.send_query(cmd)
2360
2361    @service_state.setter
2362    def service_state(self, service_state):
2363        """ Sets the service state of BTS
2364
2365        Args:
2366            service_state: service state of BTS , IN/OUT
2367
2368        Returns:
2369            None
2370        """
2371        if not isinstance(service_state, BtsServiceState):
2372            raise ValueError(' The parameter should be of type'
2373                             ' "BtsServiceState" ')
2374        cmd = "OUTOFSERVICE {},{}".format(service_state.value,
2375                                          self._bts_number)
2376        self._anritsu.send_command(cmd)
2377
2378    @property
2379    def cell_barred(self):
2380        """ Gets the Cell Barred state of the cell
2381
2382        Args:
2383            None
2384
2385        Returns:
2386            one of BtsCellBarred value
2387        """
2388        cmd = "CELLBARRED?" + self._bts_number
2389        return self._anritsu.send_query(cmd)
2390
2391    @cell_barred.setter
2392    def cell_barred(self, barred_option):
2393        """ Sets the Cell Barred state of the cell
2394
2395        Args:
2396            barred_option: Cell Barred state of the cell
2397
2398        Returns:
2399            None
2400        """
2401        if not isinstance(barred_option, BtsCellBarred):
2402            raise ValueError(' The parameter should be of type'
2403                             ' "BtsCellBarred" ')
2404        cmd = "CELLBARRED {},{}".format(barred_option.value, self._bts_number)
2405        self._anritsu.send_command(cmd)
2406
2407    @property
2408    def accessclass_barred(self):
2409        """ Gets the Access Class Barred state of the cell
2410
2411        Args:
2412            None
2413
2414        Returns:
2415            one of BtsAccessClassBarred value
2416        """
2417        cmd = "ACBARRED? " + self._bts_number
2418        return self._anritsu.send_query(cmd)
2419
2420    @accessclass_barred.setter
2421    def accessclass_barred(self, barred_option):
2422        """ Sets the Access Class Barred state of the cell
2423
2424        Args:
2425            barred_option: Access Class Barred state of the cell
2426
2427        Returns:
2428            None
2429        """
2430        if not isinstance(barred_option, BtsAccessClassBarred):
2431            raise ValueError(' The parameter should be of type'
2432                             ' "BtsAccessClassBarred" ')
2433        cmd = "ACBARRED {},{}".format(barred_option.value, self._bts_number)
2434        self._anritsu.send_command(cmd)
2435
2436    @property
2437    def lteemergency_ac_barred(self):
2438        """ Gets the LTE emergency Access Class Barred state of the cell
2439
2440        Args:
2441            None
2442
2443        Returns:
2444            one of BtsLteEmergencyAccessClassBarred value
2445        """
2446        cmd = "LTEEMERGENCYACBARRED? " + self._bts_number
2447        return self._anritsu.send_query(cmd)
2448
2449    @lteemergency_ac_barred.setter
2450    def lteemergency_ac_barred(self, barred_option):
2451        """ Sets the LTE emergency Access Class Barred state of the cell
2452
2453        Args:
2454            barred_option: Access Class Barred state of the cell
2455
2456        Returns:
2457            None
2458        """
2459        if not isinstance(barred_option, BtsLteEmergencyAccessClassBarred):
2460            raise ValueError(' The parameter should be of type'
2461                             ' "BtsLteEmergencyAccessClassBarred" ')
2462        cmd = "LTEEMERGENCYACBARRED {},{}".format(barred_option.value,
2463                                                  self._bts_number)
2464        self._anritsu.send_command(cmd)
2465
2466    @property
2467    def mcc(self):
2468        """ Gets the MCC of the cell
2469
2470        Args:
2471            None
2472
2473        Returns:
2474            MCC of the cell
2475        """
2476        cmd = "MCC? " + self._bts_number
2477        return self._anritsu.send_query(cmd)
2478
2479    @mcc.setter
2480    def mcc(self, mcc_code):
2481        """ Sets the MCC of the cell
2482
2483        Args:
2484            mcc_code: MCC of the cell
2485
2486        Returns:
2487            None
2488        """
2489        cmd = "MCC {},{}".format(mcc_code, self._bts_number)
2490        self._anritsu.send_command(cmd)
2491
2492    @property
2493    def mnc(self):
2494        """ Gets the MNC of the cell
2495
2496        Args:
2497            None
2498
2499        Returns:
2500            MNC of the cell
2501        """
2502        cmd = "MNC? " + self._bts_number
2503        return self._anritsu.send_query(cmd)
2504
2505    @mnc.setter
2506    def mnc(self, mnc_code):
2507        """ Sets the MNC of the cell
2508
2509        Args:
2510            mnc_code: MNC of the cell
2511
2512        Returns:
2513            None
2514        """
2515        cmd = "MNC {},{}".format(mnc_code, self._bts_number)
2516        self._anritsu.send_command(cmd)
2517
2518    @property
2519    def nw_fullname_enable(self):
2520        """ Gets the network full name enable status
2521
2522        Args:
2523            None
2524
2525        Returns:
2526            one of BtsNwNameEnable value
2527        """
2528        cmd = "NWFNAMEON? " + self._bts_number
2529        return self._anritsu.send_query(cmd)
2530
2531    @nw_fullname_enable.setter
2532    def nw_fullname_enable(self, enable):
2533        """ Sets the network full name enable status
2534
2535        Args:
2536            enable: network full name enable status
2537
2538        Returns:
2539            None
2540        """
2541        if not isinstance(enable, BtsNwNameEnable):
2542            raise ValueError(' The parameter should be of type'
2543                             ' "BtsNwNameEnable" ')
2544        cmd = "NWFNAMEON {},{}".format(enable.value, self._bts_number)
2545        self._anritsu.send_command(cmd)
2546
2547    @property
2548    def nw_fullname(self):
2549        """ Gets the network full name
2550
2551        Args:
2552            None
2553
2554        Returns:
2555            Network fulll name
2556        """
2557        cmd = "NWFNAME? " + self._bts_number
2558        return self._anritsu.send_query(cmd)
2559
2560    @nw_fullname.setter
2561    def nw_fullname(self, fullname):
2562        """ Sets the network full name
2563
2564        Args:
2565            fullname: network full name
2566
2567        Returns:
2568            None
2569        """
2570        cmd = "NWFNAME {},{}".format(fullname, self._bts_number)
2571        self._anritsu.send_command(cmd)
2572
2573    @property
2574    def nw_shortname_enable(self):
2575        """ Gets the network short name enable status
2576
2577        Args:
2578            None
2579
2580        Returns:
2581            one of BtsNwNameEnable value
2582        """
2583        cmd = "NWSNAMEON? " + self._bts_number
2584        return self._anritsu.send_query(cmd)
2585
2586    @nw_shortname_enable.setter
2587    def nw_shortname_enable(self, enable):
2588        """ Sets the network short name enable status
2589
2590        Args:
2591            enable: network short name enable status
2592
2593        Returns:
2594            None
2595        """
2596        if not isinstance(enable, BtsNwNameEnable):
2597            raise ValueError(' The parameter should be of type'
2598                             ' "BtsNwNameEnable" ')
2599        cmd = "NWSNAMEON {},{}".format(enable.value, self._bts_number)
2600        self._anritsu.send_command(cmd)
2601
2602    @property
2603    def nw_shortname(self):
2604        """ Gets the network short name
2605
2606        Args:
2607            None
2608
2609        Returns:
2610            Network short name
2611        """
2612        cmd = "NWSNAME? " + self._bts_number
2613        return self._anritsu.send_query(cmd)
2614
2615    @nw_shortname.setter
2616    def nw_shortname(self, shortname):
2617        """ Sets the network short name
2618
2619        Args:
2620            shortname: network short name
2621
2622        Returns:
2623            None
2624        """
2625        cmd = "NWSNAME {},{}".format(shortname, self._bts_number)
2626        self._anritsu.send_command(cmd)
2627
2628    def apply_parameter_changes(self):
2629        """ apply the parameter changes at run time
2630
2631        Args:
2632            None
2633
2634        Returns:
2635            None
2636        """
2637        cmd = "APPLYPARAM"
2638        self._anritsu.send_command(cmd)
2639
2640    @property
2641    def wcdma_ctch(self):
2642        """ Gets the WCDMA CTCH enable/disable status
2643
2644        Args:
2645            None
2646
2647        Returns:
2648            one of CTCHSetup values
2649        """
2650        cmd = "CTCHPARAMSETUP? " + self._bts_number
2651        return self._anritsu.send_query(cmd)
2652
2653    @wcdma_ctch.setter
2654    def wcdma_ctch(self, enable):
2655        """ Sets the WCDMA CTCH enable/disable status
2656
2657        Args:
2658            enable: WCDMA CTCH enable/disable status
2659
2660        Returns:
2661            None
2662        """
2663        cmd = "CTCHPARAMSETUP {},{}".format(enable.value, self._bts_number)
2664        self._anritsu.send_command(cmd)
2665
2666    @property
2667    def lac(self):
2668        """ Gets the Location Area Code of the cell
2669
2670        Args:
2671            None
2672
2673        Returns:
2674            LAC value
2675        """
2676        cmd = "LAC? " + self._bts_number
2677        return self._anritsu.send_query(cmd)
2678
2679    @lac.setter
2680    def lac(self, lac):
2681        """ Sets the Location Area Code of the cell
2682
2683        Args:
2684            lac: Location Area Code of the cell
2685
2686        Returns:
2687            None
2688        """
2689        cmd = "LAC {},{}".format(lac, self._bts_number)
2690        self._anritsu.send_command(cmd)
2691
2692    @property
2693    def rac(self):
2694        """ Gets the Routing Area Code of the cell
2695
2696        Args:
2697            None
2698
2699        Returns:
2700            RAC value
2701        """
2702        cmd = "RAC? " + self._bts_number
2703        return self._anritsu.send_query(cmd)
2704
2705    @rac.setter
2706    def rac(self, rac):
2707        """ Sets the Routing Area Code of the cell
2708
2709        Args:
2710            rac: Routing Area Code of the cell
2711
2712        Returns:
2713            None
2714        """
2715        cmd = "RAC {},{}".format(rac, self._bts_number)
2716        self._anritsu.send_command(cmd)
2717
2718    @property
2719    def dl_channel(self):
2720        """ Gets the downlink channel number of the cell
2721
2722        Args:
2723            None
2724
2725        Returns:
2726            RAC value
2727        """
2728        cmd = "DLCHAN? " + self._bts_number
2729        return self._anritsu.send_query(cmd)
2730
2731    @dl_channel.setter
2732    def dl_channel(self, channel):
2733        """ Sets the downlink channel number of the cell
2734
2735        Args:
2736            channel: downlink channel number of the cell
2737
2738        Returns:
2739            None
2740        """
2741        cmd = "DLCHAN {},{}".format(channel, self._bts_number)
2742        self._anritsu.send_command(cmd)
2743
2744    @property
2745    def dl_cc_enabled(self):
2746        """ Checks if component carrier is enabled or disabled
2747
2748        Args:
2749            None
2750
2751        Returns:
2752            True if enabled, False if disabled
2753        """
2754        return (self._anritsu.send_query("TESTDLCC?" +
2755                                         self._bts_number) == "ENABLE")
2756
2757    @dl_cc_enabled.setter
2758    def dl_cc_enabled(self, enabled):
2759        """ Enables or disables the component carrier
2760
2761        Args:
2762            enabled: True if it should be enabled, False if disabled
2763
2764        Returns:
2765            None
2766        """
2767        cmd = "TESTDLCC {},{}".format("ENABLE" if enabled else "DISABLE",
2768                                      self._bts_number)
2769        self._anritsu.send_command(cmd)
2770
2771    @property
2772    def sector1_mcc(self):
2773        """ Gets the sector 1 MCC of the CDMA cell
2774
2775        Args:
2776            None
2777
2778        Returns:
2779            sector 1 mcc
2780        """
2781        cmd = "S1MCC? " + self._bts_number
2782        return self._anritsu.send_query(cmd)
2783
2784    @sector1_mcc.setter
2785    def sector1_mcc(self, mcc):
2786        """ Sets the sector 1 MCC of the CDMA cell
2787
2788        Args:
2789            mcc: sector 1 MCC of the CDMA cell
2790
2791        Returns:
2792            None
2793        """
2794        cmd = "S1MCC {},{}".format(mcc, self._bts_number)
2795        self._anritsu.send_command(cmd)
2796
2797    @property
2798    def sector1_sid(self):
2799        """ Gets the sector 1 system ID of the CDMA cell
2800
2801        Args:
2802            None
2803
2804        Returns:
2805            sector 1 system Id
2806        """
2807        cmd = "S1SID? " + self._bts_number
2808        return self._anritsu.send_query(cmd)
2809
2810    @sector1_sid.setter
2811    def sector1_sid(self, sid):
2812        """ Sets the sector 1 system ID of the CDMA cell
2813
2814        Args:
2815            sid: sector 1 system ID of the CDMA cell
2816
2817        Returns:
2818            None
2819        """
2820        cmd = "S1SID {},{}".format(sid, self._bts_number)
2821        self._anritsu.send_command(cmd)
2822
2823    @property
2824    def sector1_nid(self):
2825        """ Gets the sector 1 network ID of the CDMA cell
2826
2827        Args:
2828            None
2829
2830        Returns:
2831            sector 1 network Id
2832        """
2833        cmd = "S1NID? " + self._bts_number
2834        return self._anritsu.send_query(cmd)
2835
2836    @sector1_nid.setter
2837    def sector1_nid(self, nid):
2838        """ Sets the sector 1 network ID of the CDMA cell
2839
2840        Args:
2841            nid: sector 1 network ID of the CDMA cell
2842
2843        Returns:
2844            None
2845        """
2846        cmd = "S1NID {},{}".format(nid, self._bts_number)
2847        self._anritsu.send_command(cmd)
2848
2849    @property
2850    def sector1_baseid(self):
2851        """ Gets the sector 1 Base ID of the CDMA cell
2852
2853        Args:
2854            None
2855
2856        Returns:
2857            sector 1 Base Id
2858        """
2859        cmd = "S1BASEID? " + self._bts_number
2860        return self._anritsu.send_query(cmd)
2861
2862    @sector1_baseid.setter
2863    def sector1_baseid(self, baseid):
2864        """ Sets the sector 1 Base ID of the CDMA cell
2865
2866        Args:
2867            baseid: sector 1 Base ID of the CDMA cell
2868
2869        Returns:
2870            None
2871        """
2872        cmd = "S1BASEID {},{}".format(baseid, self._bts_number)
2873        self._anritsu.send_command(cmd)
2874
2875    @property
2876    def sector1_latitude(self):
2877        """ Gets the sector 1 latitude of the CDMA cell
2878
2879        Args:
2880            None
2881
2882        Returns:
2883            sector 1 latitude
2884        """
2885        cmd = "S1LATITUDE? " + self._bts_number
2886        return self._anritsu.send_query(cmd)
2887
2888    @sector1_latitude.setter
2889    def sector1_latitude(self, latitude):
2890        """ Sets the sector 1 latitude of the CDMA cell
2891
2892        Args:
2893            latitude: sector 1 latitude of the CDMA cell
2894
2895        Returns:
2896            None
2897        """
2898        cmd = "S1LATITUDE {},{}".format(latitude, self._bts_number)
2899        self._anritsu.send_command(cmd)
2900
2901    @property
2902    def sector1_longitude(self):
2903        """ Gets the sector 1 longitude of the CDMA cell
2904
2905        Args:
2906            None
2907
2908        Returns:
2909            sector 1 longitude
2910        """
2911        cmd = "S1LONGITUDE? " + self._bts_number
2912        return self._anritsu.send_query(cmd)
2913
2914    @sector1_longitude.setter
2915    def sector1_longitude(self, longitude):
2916        """ Sets the sector 1 longitude of the CDMA cell
2917
2918        Args:
2919            longitude: sector 1 longitude of the CDMA cell
2920
2921        Returns:
2922            None
2923        """
2924        cmd = "S1LONGITUDE {},{}".format(longitude, self._bts_number)
2925        self._anritsu.send_command(cmd)
2926
2927    @property
2928    def evdo_sid(self):
2929        """ Gets the Sector ID of the EVDO cell
2930
2931        Args:
2932            None
2933
2934        Returns:
2935            Sector Id
2936        """
2937        cmd = "S1SECTORID? " + self._bts_number
2938        return self._anritsu.send_query(cmd)
2939
2940    @evdo_sid.setter
2941    def evdo_sid(self, sid):
2942        """ Sets the Sector ID of the EVDO cell
2943
2944        Args:
2945            sid: Sector ID of the EVDO cell
2946
2947        Returns:
2948            None
2949        """
2950        cmd = "S1SECTORID {},{}".format(sid, self._bts_number)
2951        self._anritsu.send_command(cmd)
2952
2953    @property
2954    def cell_id(self):
2955        """ Gets the cell identity of the cell
2956
2957        Args:
2958            None
2959
2960        Returns:
2961            cell identity
2962        """
2963        cmd = "CELLID? " + self._bts_number
2964        return self._anritsu.send_query(cmd)
2965
2966    @cell_id.setter
2967    def cell_id(self, cell_id):
2968        """ Sets the cell identity of the cell
2969
2970        Args:
2971            cell_id: cell identity of the cell
2972
2973        Returns:
2974            None
2975        """
2976        cmd = "CELLID {},{}".format(cell_id, self._bts_number)
2977        self._anritsu.send_command(cmd)
2978
2979    @property
2980    def physical_cellid(self):
2981        """ Gets the physical cell id of the cell
2982
2983        Args:
2984            None
2985
2986        Returns:
2987            physical cell id
2988        """
2989        cmd = "PHYCELLID? " + self._bts_number
2990        return self._anritsu.send_query(cmd)
2991
2992    @physical_cellid.setter
2993    def physical_cellid(self, physical_cellid):
2994        """ Sets the physical cell id of the cell
2995
2996        Args:
2997            physical_cellid: physical cell id of the cell
2998
2999        Returns:
3000            None
3001        """
3002        cmd = "PHYCELLID {},{}".format(physical_cellid, self._bts_number)
3003        self._anritsu.send_command(cmd)
3004
3005    @property
3006    def gsm_mcs_dl(self):
3007        """ Gets the Modulation and Coding scheme (DL) of the GSM cell
3008
3009        Args:
3010            None
3011
3012        Returns:
3013            DL MCS
3014        """
3015        cmd = "DLMCS? " + self._bts_number
3016        return self._anritsu.send_query(cmd)
3017
3018    @gsm_mcs_dl.setter
3019    def gsm_mcs_dl(self, mcs_dl):
3020        """ Sets the Modulation and Coding scheme (DL) of the GSM cell
3021
3022        Args:
3023            mcs_dl: Modulation and Coding scheme (DL) of the GSM cell
3024
3025        Returns:
3026            None
3027        """
3028        cmd = "DLMCS {},{}".format(mcs_dl, self._bts_number)
3029        self._anritsu.send_command(cmd)
3030
3031    @property
3032    def gsm_mcs_ul(self):
3033        """ Gets the Modulation and Coding scheme (UL) of the GSM cell
3034
3035        Args:
3036            None
3037
3038        Returns:
3039            UL MCS
3040        """
3041        cmd = "ULMCS? " + self._bts_number
3042        return self._anritsu.send_query(cmd)
3043
3044    @gsm_mcs_ul.setter
3045    def gsm_mcs_ul(self, mcs_ul):
3046        """ Sets the Modulation and Coding scheme (UL) of the GSM cell
3047
3048        Args:
3049            mcs_ul:Modulation and Coding scheme (UL) of the GSM cell
3050
3051        Returns:
3052            None
3053        """
3054        cmd = "ULMCS {},{}".format(mcs_ul, self._bts_number)
3055        self._anritsu.send_command(cmd)
3056
3057    @property
3058    def lte_scheduling_mode(self):
3059        """ Gets the Scheduling mode of the LTE cell
3060
3061        Args:
3062            None
3063
3064        Returns:
3065            Scheduling mode
3066        """
3067        cmd = "SCHEDULEMODE? " + self._bts_number
3068        return self._anritsu.send_query(cmd)
3069
3070    @lte_scheduling_mode.setter
3071    def lte_scheduling_mode(self, mode):
3072        """ Sets the Scheduling mode of the LTE cell
3073
3074        Args:
3075            mode: STATIC (default) or DYNAMIC
3076
3077        Returns:
3078            None
3079        """
3080        counter = 1
3081        while mode != self.lte_scheduling_mode:
3082            if counter > 3:
3083                raise AnritsuError("Fail to set scheduling mode in 3 tries!")
3084            cmd = "SCHEDULEMODE {},{}".format(mode, self._bts_number)
3085            self._anritsu.send_command(cmd)
3086            counter += 1
3087            time.sleep(1)
3088
3089    @property
3090    def tbs_pattern(self):
3091        """ Gets the TBS Pattern setting for the LTE cell
3092
3093        Args:
3094            None
3095
3096        Returns:
3097            TBS Pattern setting
3098        """
3099        cmd = "TBSPATTERN? " + self._bts_number
3100        return self._anritsu.send_query(cmd)
3101
3102    @tbs_pattern.setter
3103    def tbs_pattern(self, pattern):
3104        """ Sets the TBS Pattern setting for the LTE cell
3105
3106        Args:
3107            mode: "FULLALLOCATION" or "OFF"
3108
3109        Returns:
3110            None
3111        """
3112        cmd = "TBSPATTERN {}, {}".format(pattern, self._bts_number)
3113        self._anritsu.send_command(cmd)
3114
3115    @property
3116    def drx_connected_mode(self):
3117        """ Gets the Connected DRX LTE cell parameter
3118
3119        Args:
3120            None
3121
3122        Returns:
3123            DRX connected mode (OFF, AUTO, MANUAL)
3124        """
3125        cmd = "DRXCONN? " + self._bts_number
3126        return self._anritsu.send_query(cmd)
3127
3128    @drx_connected_mode.setter
3129    def drx_connected_mode(self, mode):
3130        """  Sets the Connected DRX LTE cell parameter
3131
3132        Args:
3133            mode: OFF, AUTO, MANUAL
3134
3135        Returns:
3136            None
3137        """
3138        cmd = "DRXCONN {}, {}".format(mode, self._bts_number)
3139        self._anritsu.send_command(cmd)
3140
3141    @property
3142    def drx_on_duration_timer(self):
3143        """ Gets the amount of PDCCH subframes to wait for data after
3144            waking up from a DRX cycle
3145
3146        Args:
3147            None
3148
3149        Returns:
3150            DRX mode duration timer
3151        """
3152        cmd = "DRXDURATIONTIME? " + self._bts_number
3153        return self._anritsu.send_query(cmd)
3154
3155    @drx_on_duration_timer.setter
3156    def drx_on_duration_timer(self, time):
3157        """ Sets the amount of PDCCH subframes to wait for data after
3158            waking up from a DRX cycle
3159
3160        Args:
3161            timer: Amount of PDCCH subframes to wait for user data
3162                to be transmitted
3163
3164        Returns:
3165            None
3166        """
3167        cmd = "DRXDURATIONTIME PSF{}, {}".format(time, self._bts_number)
3168        self._anritsu.send_command(cmd)
3169
3170    @property
3171    def drx_inactivity_timer(self):
3172        """ Gets the number of PDCCH subframes to wait before entering DRX mode
3173
3174        Args:
3175            None
3176
3177        Returns:
3178            DRX mode inactivity timer
3179        """
3180        cmd = "DRXINACTIVITYTIME? " + self._bts_number
3181        return self._anritsu.send_query(cmd)
3182
3183    @drx_inactivity_timer.setter
3184    def drx_inactivity_timer(self, time):
3185        """ Sets the number of PDCCH subframes to wait before entering DRX mode
3186
3187        Args:
3188            timer: Length of the interval to wait
3189
3190        Returns:
3191            None
3192        """
3193        cmd = "DRXINACTIVITYTIME PSF{}, {}".format(time, self._bts_number)
3194        self._anritsu.send_command(cmd)
3195
3196    @property
3197    def drx_retransmission_timer(self):
3198        """ Gets the number of consecutive PDCCH subframes to wait
3199        for retransmission
3200
3201        Args:
3202            None
3203
3204        Returns:
3205            Number of PDCCH subframes to wait for retransmission
3206        """
3207        cmd = "DRXRETRANSTIME? " + self._bts_number
3208        return self._anritsu.send_query(cmd)
3209
3210    @drx_retransmission_timer.setter
3211    def drx_retransmission_timer(self, time):
3212        """ Sets the number of consecutive PDCCH subframes to wait
3213        for retransmission
3214
3215        Args:
3216            time: Number of PDCCH subframes to wait
3217            for retransmission
3218
3219        Returns:
3220            None
3221        """
3222        cmd = "DRXRETRANSTIME PSF{}, {}".format(time, self._bts_number)
3223        self._anritsu.send_command(cmd)
3224
3225    @property
3226    def drx_long_cycle(self):
3227        """ Gets the amount of subframes representing a DRX long cycle
3228
3229        Args:
3230            None
3231
3232        Returns:
3233            The amount of subframes representing one long DRX cycle.
3234            One cycle consists of DRX sleep + DRX on duration
3235        """
3236        cmd = "DRXLONGCYCLE? " + self._bts_number
3237        return self._anritsu.send_query(cmd)
3238
3239    @drx_long_cycle.setter
3240    def drx_long_cycle(self, time):
3241        """ Sets the amount of subframes representing a DRX long cycle
3242
3243        Args:
3244            long_cycle: The amount of subframes representing one long DRX cycle.
3245                One cycle consists of DRX sleep + DRX on duration
3246
3247        Returns:
3248            None
3249        """
3250        cmd = "DRXLONGCYCLE SF{}, {}".format(time, self._bts_number)
3251        self._anritsu.send_command(cmd)
3252
3253    @property
3254    def drx_long_cycle_offset(self):
3255        """ Gets the offset used to determine long cycle starting
3256        subframe
3257
3258        Args:
3259            None
3260
3261        Returns:
3262            Long cycle offset
3263        """
3264        cmd = "DRXLONGCYCLESTARTOFFSET? " + self._bts_number
3265        return self._anritsu.send_query(cmd)
3266
3267    @drx_long_cycle_offset.setter
3268    def drx_long_cycle_offset(self, offset):
3269        """ Sets the offset used to determine long cycle starting
3270        subframe
3271
3272        Args:
3273            offset: Number in range 0...(long cycle - 1)
3274        """
3275        cmd = "DRXLONGCYCLESTARTOFFSET {}, {}".format(offset, self._bts_number)
3276        self._anritsu.send_command(cmd)
3277
3278    @property
3279    def lte_mcs_dl(self):
3280        """ Gets the Modulation and Coding scheme (DL) of the LTE cell
3281
3282        Args:
3283            None
3284
3285        Returns:
3286            DL MCS
3287        """
3288        cmd = "DLIMCS? " + self._bts_number
3289        return self._anritsu.send_query(cmd)
3290
3291    @lte_mcs_dl.setter
3292    def lte_mcs_dl(self, mcs_dl):
3293        """ Sets the Modulation and Coding scheme (DL) of the LTE cell
3294
3295        Args:
3296            mcs_dl: Modulation and Coding scheme (DL) of the LTE cell
3297
3298        Returns:
3299            None
3300        """
3301        cmd = "DLIMCS {},{}".format(mcs_dl, self._bts_number)
3302        self._anritsu.send_command(cmd)
3303
3304    @property
3305    def lte_mcs_ul(self):
3306        """ Gets the Modulation and Coding scheme (UL) of the LTE cell
3307
3308        Args:
3309            None
3310
3311        Returns:
3312            UL MCS
3313        """
3314        cmd = "ULIMCS? " + self._bts_number
3315        return self._anritsu.send_query(cmd)
3316
3317    @lte_mcs_ul.setter
3318    def lte_mcs_ul(self, mcs_ul):
3319        """ Sets the Modulation and Coding scheme (UL) of the LTE cell
3320
3321        Args:
3322            mcs_ul: Modulation and Coding scheme (UL) of the LTE cell
3323
3324        Returns:
3325            None
3326        """
3327        cmd = "ULIMCS {},{}".format(mcs_ul, self._bts_number)
3328        self._anritsu.send_command(cmd)
3329
3330    @property
3331    def lte_dl_modulation_order(self):
3332        """ Gets the DL modulation order of the LTE cell
3333
3334        Args:
3335            None
3336
3337        Returns:
3338            The DL modulation order
3339        """
3340        cmd = "DLRMC_MOD? " + self._bts_number
3341        return self._anritsu.send_query(cmd)
3342
3343    @lte_dl_modulation_order.setter
3344    def lte_dl_modulation_order(self, order):
3345        """ Sets the DL modulation order of the LTE cell
3346
3347        Args:
3348            order: the DL modulation order of the LTE cell
3349
3350        Returns:
3351            None
3352        """
3353        cmd = "DLRMC_MOD {},{}".format(order, self._bts_number)
3354        self._anritsu.send_command(cmd)
3355
3356    @property
3357    def lte_ul_modulation_order(self):
3358        """ Gets the UL modulation order of the LTE cell
3359
3360        Args:
3361            None
3362
3363        Returns:
3364            The UL modulation order
3365        """
3366        cmd = "ULRMC_MOD? " + self._bts_number
3367        return self._anritsu.send_query(cmd)
3368
3369    @lte_ul_modulation_order.setter
3370    def lte_ul_modulation_order(self, order):
3371        """ Sets the UL modulation order of the LTE cell
3372
3373        Args:
3374            order: the UL modulation order of the LTE cell
3375
3376        Returns:
3377            None
3378        """
3379        cmd = "ULRMC_MOD {},{}".format(order, self._bts_number)
3380        self._anritsu.send_command(cmd)
3381
3382    @property
3383    def nrb_dl(self):
3384        """ Gets the Downlink N Resource Block of the cell
3385
3386        Args:
3387            None
3388
3389        Returns:
3390            Downlink NRB
3391        """
3392        cmd = "DLNRB? " + self._bts_number
3393        return self._anritsu.send_query(cmd)
3394
3395    @nrb_dl.setter
3396    def nrb_dl(self, blocks):
3397        """ Sets the Downlink N Resource Block of the cell
3398
3399        Args:
3400            blocks: Downlink N Resource Block of the cell
3401
3402        Returns:
3403            None
3404        """
3405        cmd = "DLNRB {},{}".format(blocks, self._bts_number)
3406        self._anritsu.send_command(cmd)
3407
3408    @property
3409    def nrb_ul(self):
3410        """ Gets the uplink N Resource Block of the cell
3411
3412        Args:
3413            None
3414
3415        Returns:
3416            uplink NRB
3417        """
3418        cmd = "ULNRB? " + self._bts_number
3419        return self._anritsu.send_query(cmd)
3420
3421    @nrb_ul.setter
3422    def nrb_ul(self, blocks):
3423        """ Sets the uplink N Resource Block of the cell
3424
3425        Args:
3426            blocks: uplink N Resource Block of the cell
3427
3428        Returns:
3429            None
3430        """
3431        cmd = "ULNRB {},{}".format(blocks, self._bts_number)
3432        self._anritsu.send_command(cmd)
3433
3434    @property
3435    def max_nrb_ul(self):
3436        ul_bandwidth = self.ul_bandwidth
3437        if ul_bandwidth == 'SAMEASDL':
3438            ul_bandwidth = self.dl_bandwidth
3439        max_nrb = MAX_NRB_FOR_BANDWIDTH.get(ul_bandwidth, None)
3440        if not max_nrb:
3441            raise ValueError('Could not get maximum RB allocation'
3442                             'for bandwidth: {}'.format(ul_bandwidth))
3443        return max_nrb
3444
3445    @property
3446    def mimo_support(self):
3447        """ Gets the maximum supported MIMO mode for the LTE bases tation.
3448
3449        Returns:
3450            the MIMO mode as a string
3451        """
3452        cmd = "LTEMIMO? " + self._bts_number
3453        return self._anritsu.send_query(cmd)
3454
3455    @mimo_support.setter
3456    def mimo_support(self, mode):
3457        """ Sets the maximum supported MIMO mode for the LTE base station.
3458
3459        Args:
3460            mode: a string or an object of the LteMimoMode class.
3461        """
3462
3463        if isinstance(mode, LteMimoMode):
3464            mode = mode.value
3465
3466        cmd = "LTEMIMO {},{}".format(self._bts_number, mode)
3467        self._anritsu.send_command(cmd)
3468
3469    @property
3470    def neighbor_cell_mode(self):
3471        """ Gets the neighbor cell mode
3472
3473        Args:
3474            None
3475
3476        Returns:
3477            current neighbor cell mode
3478        """
3479        cmd = "NCLIST? " + self._bts_number
3480        return self._anritsu.send_query(cmd)
3481
3482    @neighbor_cell_mode.setter
3483    def neighbor_cell_mode(self, mode):
3484        """ Sets the neighbor cell mode
3485
3486        Args:
3487            mode: neighbor cell mode , DEFAULT/ USERDATA
3488
3489        Returns:
3490            None
3491        """
3492        cmd = "NCLIST {},{}".format(mode, self._bts_number)
3493        self._anritsu.send_command(cmd)
3494
3495    def get_neighbor_cell_type(self, system, index):
3496        """ Gets the neighbor cell type
3497
3498        Args:
3499            system: simulation model of neighbor cell
3500                    LTE, WCDMA, TDSCDMA, GSM, CDMA1X,EVDO
3501            index: Index of neighbor cell
3502
3503        Returns:
3504            neighbor cell type
3505        """
3506        cmd = "NCTYPE? {},{},{}".format(system, index, self._bts_number)
3507        return self._anritsu.send_query(cmd)
3508
3509    def set_neighbor_cell_type(self, system, index, cell_type):
3510        """ Sets the neighbor cell type
3511
3512        Args:
3513            system: simulation model of neighbor cell
3514                   LTE, WCDMA, TDSCDMA, GSM, CDMA1X,EVDO
3515            index: Index of neighbor cell
3516            cell_type: cell type
3517                BTS1, BTS2, BTS3, BTS4,CELLNAME, DISABLE
3518
3519        Returns:
3520            None
3521        """
3522        cmd = "NCTYPE {},{},{},{}".format(system, index, cell_type,
3523                                          self._bts_number)
3524        self._anritsu.send_command(cmd)
3525
3526    def get_neighbor_cell_name(self, system, index):
3527        """ Gets the neighbor cell name
3528
3529        Args:
3530            system: simulation model of neighbor cell
3531                    LTE, WCDMA, TDSCDMA, GSM, CDMA1X,EVDO
3532            index: Index of neighbor cell
3533
3534        Returns:
3535            neighbor cell name
3536        """
3537        cmd = "NCCELLNAME? {},{},{}".format(system, index, self._bts_number)
3538        return self._anritsu.send_query(cmd)
3539
3540    def set_neighbor_cell_name(self, system, index, name):
3541        """ Sets the neighbor cell name
3542
3543        Args:
3544            system: simulation model of neighbor cell
3545                   LTE, WCDMA, TDSCDMA, GSM, CDMA1X,EVDO
3546            index: Index of neighbor cell
3547            name: cell name
3548
3549        Returns:
3550            None
3551        """
3552        cmd = "NCCELLNAME {},{},{},{}".format(system, index, name,
3553                                              self._bts_number)
3554        self._anritsu.send_command(cmd)
3555
3556    def get_neighbor_cell_mcc(self, system, index):
3557        """ Gets the neighbor cell mcc
3558
3559        Args:
3560            system: simulation model of neighbor cell
3561                    LTE, WCDMA, TDSCDMA, GSM, CDMA1X,EVDO
3562            index: Index of neighbor cell
3563
3564        Returns:
3565            neighbor cell mcc
3566        """
3567        cmd = "NCMCC? {},{},{}".format(system, index, self._bts_number)
3568        return self._anritsu.send_query(cmd)
3569
3570    def get_neighbor_cell_mnc(self, system, index):
3571        """ Gets the neighbor cell mnc
3572
3573        Args:
3574            system: simulation model of neighbor cell
3575                    LTE, WCDMA, TDSCDMA, GSM, CDMA1X,EVDO
3576            index: Index of neighbor cell
3577
3578        Returns:
3579            neighbor cell mnc
3580        """
3581        cmd = "NCMNC? {},{},{}".format(system, index, self._bts_number)
3582        return self._anritsu.send_query(cmd)
3583
3584    def get_neighbor_cell_id(self, system, index):
3585        """ Gets the neighbor cell id
3586
3587        Args:
3588            system: simulation model of neighbor cell
3589                    LTE, WCDMA, TDSCDMA, GSM, CDMA1X,EVDO
3590            index: Index of neighbor cell
3591
3592        Returns:
3593            neighbor cell id
3594        """
3595        cmd = "NCCELLID? {},{},{}".format(system, index, self._bts_number)
3596        return self._anritsu.send_query(cmd)
3597
3598    def get_neighbor_cell_tac(self, system, index):
3599        """ Gets the neighbor cell tracking area code
3600
3601        Args:
3602            system: simulation model of neighbor cell
3603                    LTE, WCDMA, TDSCDMA, GSM, CDMA1X,EVDO
3604            index: Index of neighbor cell
3605
3606        Returns:
3607            neighbor cell tracking area code
3608        """
3609        cmd = "NCTAC? {},{},{}".format(system, index, self._bts_number)
3610        return self._anritsu.send_query(cmd)
3611
3612    def get_neighbor_cell_dl_channel(self, system, index):
3613        """ Gets the neighbor cell downlink channel
3614
3615        Args:
3616            system: simulation model of neighbor cell
3617                    LTE, WCDMA, TDSCDMA, GSM, CDMA1X,EVDO
3618            index: Index of neighbor cell
3619
3620        Returns:
3621            neighbor cell tracking downlink channel
3622        """
3623        cmd = "NCDLCHAN? {},{},{}".format(system, index, self._bts_number)
3624        return self._anritsu.send_query(cmd)
3625
3626    def get_neighbor_cell_dl_bandwidth(self, system, index):
3627        """ Gets the neighbor cell downlink bandwidth
3628
3629        Args:
3630            system: simulation model of neighbor cell
3631                    LTE, WCDMA, TDSCDMA, GSM, CDMA1X,EVDO
3632            index: Index of neighbor cell
3633
3634        Returns:
3635            neighbor cell tracking downlink bandwidth
3636        """
3637        cmd = "NCDLBANDWIDTH {},{},{}".format(system, index, self._bts_number)
3638        return self._anritsu.send_query(cmd)
3639
3640    def get_neighbor_cell_pcid(self, system, index):
3641        """ Gets the neighbor cell physical cell id
3642
3643        Args:
3644            system: simulation model of neighbor cell
3645                    LTE, WCDMA, TDSCDMA, GSM, CDMA1X,EVDO
3646            index: Index of neighbor cell
3647
3648        Returns:
3649            neighbor cell physical cell id
3650        """
3651        cmd = "NCPHYCELLID {},{},{}".format(system, index, self._bts_number)
3652        return self._anritsu.send_query(cmd)
3653
3654    def get_neighbor_cell_lac(self, system, index):
3655        """ Gets the neighbor cell location area code
3656
3657        Args:
3658            system: simulation model of neighbor cell
3659                    LTE, WCDMA, TDSCDMA, GSM, CDMA1X,EVDO
3660            index: Index of neighbor cell
3661
3662        Returns:
3663            neighbor cell location area code
3664        """
3665        cmd = "NCLAC {},{},{}".format(system, index, self._bts_number)
3666        return self._anritsu.send_query(cmd)
3667
3668    def get_neighbor_cell_rac(self, system, index):
3669        """ Gets the neighbor cell routing area code
3670
3671        Args:
3672            system: simulation model of neighbor cell
3673                    LTE, WCDMA, TDSCDMA, GSM, CDMA1X,EVDO
3674            index: Index of neighbor cell
3675
3676        Returns:
3677            neighbor cell routing area code
3678        """
3679        cmd = "NCRAC {},{},{}".format(system, index, self._bts_number)
3680        return self._anritsu.send_query(cmd)
3681
3682    @property
3683    def primary_scrambling_code(self):
3684        """ Gets the primary scrambling code for WCDMA cell
3685
3686        Args:
3687            None
3688
3689        Returns:
3690            primary scrambling code
3691        """
3692        cmd = "PRISCRCODE? " + self._bts_number
3693        return self._anritsu.send_query(cmd)
3694
3695    @primary_scrambling_code.setter
3696    def primary_scrambling_code(self, psc):
3697        """ Sets the primary scrambling code for WCDMA cell
3698
3699        Args:
3700            psc: primary scrambling code
3701
3702        Returns:
3703            None
3704        """
3705        cmd = "PRISCRCODE {},{}".format(psc, self._bts_number)
3706        self._anritsu.send_command(cmd)
3707
3708    @property
3709    def tac(self):
3710        """ Gets the Tracking Area Code of the LTE cell
3711
3712        Args:
3713            None
3714
3715        Returns:
3716            Tracking Area Code of the LTE cell
3717        """
3718        cmd = "TAC? " + self._bts_number
3719        return self._anritsu.send_query(cmd)
3720
3721    @tac.setter
3722    def tac(self, tac):
3723        """ Sets the Tracking Area Code of the LTE cell
3724
3725        Args:
3726            tac: Tracking Area Code of the LTE cell
3727
3728        Returns:
3729            None
3730        """
3731        cmd = "TAC {},{}".format(tac, self._bts_number)
3732        self._anritsu.send_command(cmd)
3733
3734    @property
3735    def cell(self):
3736        """ Gets the current cell for BTS
3737
3738        Args:
3739            None
3740
3741        Returns:
3742            current cell for BTS
3743        """
3744        cmd = "CELLSEL? {}".format(self._bts_number)
3745        return self._anritsu.send_query(cmd)
3746
3747    @cell.setter
3748    def cell(self, cell_name):
3749        """ sets the  cell for BTS
3750        Args:
3751            cell_name: cell name
3752
3753        Returns:
3754            None
3755        """
3756        cmd = "CELLSEL {},{}".format(self._bts_number, cell_name)
3757        return self._anritsu.send_command(cmd)
3758
3759    @property
3760    def gsm_cbch(self):
3761        """ Gets the GSM CBCH enable/disable status
3762
3763        Args:
3764            None
3765
3766        Returns:
3767            one of CBCHSetup values
3768        """
3769        cmd = "CBCHPARAMSETUP? " + self._bts_number
3770        return self._anritsu.send_query(cmd)
3771
3772    @gsm_cbch.setter
3773    def gsm_cbch(self, enable):
3774        """ Sets the GSM CBCH enable/disable status
3775
3776        Args:
3777            enable: GSM CBCH enable/disable status
3778
3779        Returns:
3780            None
3781        """
3782        cmd = "CBCHPARAMSETUP {},{}".format(enable.value, self._bts_number)
3783        self._anritsu.send_command(cmd)
3784
3785    @property
3786    def gsm_gprs_mode(self):
3787        """ Gets the GSM connection mode
3788
3789        Args:
3790            None
3791
3792        Returns:
3793            A string indicating if connection is EGPRS, GPRS or non-GPRS
3794        """
3795        cmd = "GPRS? " + self._bts_number
3796        return self._anritsu.send_query(cmd)
3797
3798    @gsm_gprs_mode.setter
3799    def gsm_gprs_mode(self, mode):
3800        """ Sets the GPRS connection mode
3801
3802        Args:
3803            mode: GPRS connection mode
3804
3805        Returns:
3806            None
3807        """
3808
3809        if not isinstance(mode, BtsGprsMode):
3810            raise ValueError(' The parameter should be of type "BtsGprsMode"')
3811        cmd = "GPRS {},{}".format(mode.value, self._bts_number)
3812
3813        self._anritsu.send_command(cmd)
3814
3815    @property
3816    def gsm_slots(self):
3817        """ Gets the GSM slot assignment
3818
3819        Args:
3820            None
3821
3822        Returns:
3823            A tuple indicating DL and UL slots.
3824        """
3825
3826        cmd = "MLTSLTCFG? " + self._bts_number
3827
3828        response = self._anritsu.send_query(cmd)
3829        split_response = response.split(',')
3830
3831        if not len(split_response) == 2:
3832            raise ValueError(response)
3833
3834        return response[0], response[1]
3835
3836    @gsm_slots.setter
3837    def gsm_slots(self, slots):
3838        """ Sets the number of downlink / uplink slots for GSM
3839
3840        Args:
3841            slots: a tuple containing two ints indicating (DL,UL)
3842
3843        Returns:
3844            None
3845        """
3846
3847        try:
3848            dl, ul = slots
3849            dl = int(dl)
3850            ul = int(ul)
3851        except:
3852            raise ValueError(
3853                'The parameter slot has to be a tuple containing two ints '
3854                'indicating (dl,ul) slots.')
3855
3856        # Validate
3857        if dl < 1 or ul < 1 or dl + ul > 5:
3858            raise ValueError(
3859                'DL and UL slots have to be >= 1 and the sum <= 5.')
3860
3861        cmd = "MLTSLTCFG {},{},{}".format(dl, ul, self._bts_number)
3862
3863        self._anritsu.send_command(cmd)
3864
3865
3866class _VirtualPhone(object):
3867    '''Class to interact with virtual phone supported by MD8475 '''
3868    def __init__(self, anritsu):
3869        self._anritsu = anritsu
3870        self.log = anritsu.log
3871
3872    @property
3873    def id(self):
3874        """ Gets the virtual phone ID
3875
3876        Args:
3877            None
3878
3879        Returns:
3880            virtual phone ID
3881        """
3882        cmd = "VPID? "
3883        return self._anritsu.send_query(cmd)
3884
3885    @id.setter
3886    def id(self, phonenumber):
3887        """ Sets the virtual phone ID
3888
3889        Args:
3890            phonenumber: virtual phone ID
3891
3892        Returns:
3893            None
3894        """
3895        cmd = "VPID {}".format(phonenumber)
3896        self._anritsu.send_command(cmd)
3897
3898    @property
3899    def id_c2k(self):
3900        """ Gets the virtual phone ID for CDMA 1x
3901
3902        Args:
3903            None
3904
3905        Returns:
3906            virtual phone ID
3907        """
3908        cmd = "VPIDC2K? "
3909        return self._anritsu.send_query(cmd)
3910
3911    @id_c2k.setter
3912    def id_c2k(self, phonenumber):
3913        """ Sets the virtual phone ID for CDMA 1x
3914
3915        Args:
3916            phonenumber: virtual phone ID
3917
3918        Returns:
3919            None
3920        """
3921        cmd = "VPIDC2K {}".format(phonenumber)
3922        self._anritsu.send_command(cmd)
3923
3924    @property
3925    def auto_answer(self):
3926        """ Gets the auto answer status of virtual phone
3927
3928        Args:
3929            None
3930
3931        Returns:
3932            auto answer status, ON/OFF
3933        """
3934        cmd = "VPAUTOANSWER? "
3935        return self._anritsu.send_query(cmd)
3936
3937    @auto_answer.setter
3938    def auto_answer(self, option):
3939        """ Sets the auto answer feature
3940
3941        Args:
3942            option: tuple with two items for turning on Auto Answer
3943                    (OFF or (ON, timetowait))
3944
3945        Returns:
3946            None
3947        """
3948        enable = "OFF"
3949        time = 5
3950
3951        try:
3952            enable, time = option
3953        except ValueError:
3954            if enable != "OFF":
3955                raise ValueError("Pass a tuple with two items for"
3956                                 " Turning on Auto Answer")
3957        cmd = "VPAUTOANSWER {},{}".format(enable.value, time)
3958        self._anritsu.send_command(cmd)
3959
3960    @property
3961    def calling_mode(self):
3962        """ Gets the calling mode of virtual phone
3963
3964        Args:
3965            None
3966
3967        Returns:
3968            calling mode of virtual phone
3969        """
3970        cmd = "VPCALLINGMODE? "
3971        return self._anritsu.send_query(cmd)
3972
3973    @calling_mode.setter
3974    def calling_mode(self, calling_mode):
3975        """ Sets the calling mode of virtual phone
3976
3977        Args:
3978            calling_mode: calling mode of virtual phone
3979
3980        Returns:
3981            None
3982        """
3983        cmd = "VPCALLINGMODE {}".format(calling_mode)
3984        self._anritsu.send_command(cmd)
3985
3986    def set_voice_off_hook(self):
3987        """ Set the virtual phone operating mode to Voice Off Hook
3988
3989        Args:
3990            None
3991
3992        Returns:
3993            None
3994        """
3995        cmd = "OPERATEVPHONE 0"
3996        return self._anritsu.send_command(cmd)
3997
3998    def set_voice_on_hook(self):
3999        """ Set the virtual phone operating mode to Voice On Hook
4000
4001        Args:
4002            None
4003
4004        Returns:
4005            None
4006        """
4007        cmd = "OPERATEVPHONE 1"
4008        return self._anritsu.send_command(cmd)
4009
4010    def set_video_off_hook(self):
4011        """ Set the virtual phone operating mode to Video Off Hook
4012
4013        Args:
4014            None
4015
4016        Returns:
4017            None
4018        """
4019        cmd = "OPERATEVPHONE 2"
4020        return self._anritsu.send_command(cmd)
4021
4022    def set_video_on_hook(self):
4023        """ Set the virtual phone operating mode to Video On Hook
4024
4025        Args:
4026            None
4027
4028        Returns:
4029            None
4030        """
4031        cmd = "OPERATEVPHONE 3"
4032        return self._anritsu.send_command(cmd)
4033
4034    def set_call_waiting(self):
4035        """ Set the virtual phone operating mode to Call waiting
4036
4037        Args:
4038            None
4039
4040        Returns:
4041            None
4042        """
4043        cmd = "OPERATEVPHONE 4"
4044        return self._anritsu.send_command(cmd)
4045
4046    @property
4047    def status(self):
4048        """ Gets the virtual phone status
4049
4050        Args:
4051            None
4052
4053        Returns:
4054            virtual phone status
4055        """
4056        cmd = "VPSTAT?"
4057        status = self._anritsu.send_query(cmd)
4058        return _VP_STATUS[status]
4059
4060    def sendSms(self, phoneNumber, message):
4061        """ Sends the SMS data from Anritsu to UE
4062
4063        Args:
4064            phoneNumber: sender of SMS
4065            message: message text
4066
4067        Returns:
4068            None
4069        """
4070        cmd = ("SENDSMS /?PhoneNumber=001122334455&Sender={}&Text={}"
4071               "&DCS=00").format(phoneNumber, AnritsuUtils.gsm_encode(message))
4072        return self._anritsu.send_command(cmd)
4073
4074    def sendSms_c2k(self, phoneNumber, message):
4075        """ Sends the SMS data from Anritsu to UE (in CDMA)
4076
4077        Args:
4078            phoneNumber: sender of SMS
4079            message: message text
4080
4081        Returns:
4082            None
4083        """
4084        cmd = ("C2KSENDSMS System=CDMA\&Originating_Address={}\&UserData={}"
4085               ).format(phoneNumber, AnritsuUtils.cdma_encode(message))
4086        return self._anritsu.send_command(cmd)
4087
4088    def receiveSms(self):
4089        """ Receives SMS messages sent by the UE in an external application
4090
4091        Args:
4092            None
4093
4094        Returns:
4095            None
4096        """
4097        return self._anritsu.send_query("RECEIVESMS?")
4098
4099    def receiveSms_c2k(self):
4100        """ Receives SMS messages sent by the UE(in CDMA) in an external application
4101
4102        Args:
4103            None
4104
4105        Returns:
4106            None
4107        """
4108        return self._anritsu.send_query("C2KRECEIVESMS?")
4109
4110    def setSmsStatusReport(self, status):
4111        """ Set the Status Report value of the SMS
4112
4113        Args:
4114            status: status code
4115
4116        Returns:
4117            None
4118        """
4119        cmd = "SMSSTATUSREPORT {}".format(status)
4120        return self._anritsu.send_command(cmd)
4121
4122
4123class _PacketDataNetwork(object):
4124    '''Class to configure PDN parameters'''
4125    def __init__(self, anritsu, pdnnumber):
4126        self._pdn_number = pdnnumber
4127        self._anritsu = anritsu
4128        self.log = anritsu.log
4129
4130    # Default Gateway Selection
4131    @property
4132    def pdn_DG_selection(self):
4133        """ Gets the default gateway for the PDN
4134
4135        Args:
4136          None
4137
4138        Returns:
4139          Current UE status
4140        """
4141        cmd = "PDNDEFAULTGATEWAY? " + self._pdn_number
4142        return self._anritsu.send_query(cmd)
4143
4144    @pdn_DG_selection.setter
4145    def pdn_DG_selection(self, selection):
4146        """ Sets the default gateway selection for the PDN
4147
4148        Args:
4149          Selection: COMMON or USER
4150
4151        Returns:
4152          None
4153        """
4154        cmd = "PDNDEFAULTGATEWAY {},{}".format(self._pdn_number, selection)
4155        self._anritsu.send_command(cmd)
4156
4157    # PDN specific Default Gateway:
4158    @property
4159    def pdn_gateway_ipv4addr(self):
4160        """ Gets the IPv4 address of the default gateway
4161
4162        Args:
4163          None
4164
4165        Returns:
4166            current UE status
4167        """
4168        cmd = "PDNDGIPV4? " + self._pdn_number
4169        return self._anritsu.send_query(cmd)
4170
4171    @pdn_gateway_ipv4addr.setter
4172    def pdn_gateway_ipv4addr(self, ipv4_addr):
4173        """ sets the IPv4 address of the default gateway
4174
4175        Args:
4176            ipv4_addr: IPv4 address of the default gateway
4177
4178        Returns:
4179            None
4180        """
4181        cmd = "PDNDGIPV4 {},{}".format(self._pdn_number, ipv4_addr)
4182        self._anritsu.send_command(cmd)
4183
4184    @property
4185    def pdn_gateway_ipv6addr(self):
4186        """ Gets the IPv6 address of the default gateway
4187
4188        Args:
4189          None
4190
4191        Returns:
4192            current UE status
4193        """
4194        cmd = "PDNDGIPV6? " + self._pdn_number
4195        return self._anritsu.send_query(cmd)
4196
4197    @pdn_gateway_ipv6addr.setter
4198    def pdn_gateway_ipv6addr(self, ipv6_addr):
4199        """ sets the IPv6 address of the default gateway
4200
4201        Args:
4202            ipv6_addr: IPv6 address of the default gateway
4203
4204        Returns:
4205            None
4206        """
4207        cmd = "PDNDGIPV6 {},{}".format(self._pdn_number, ipv6_addr)
4208        self._anritsu.send_command(cmd)
4209
4210    @property
4211    def ue_address_iptype(self):
4212        """ Gets IP type of UE for particular PDN
4213
4214        Args:
4215            None
4216
4217        Returns:
4218            IP type of UE for particular PDN
4219        """
4220        cmd = "PDNIPTYPE? " + self._pdn_number
4221        return self._anritsu.send_query(cmd)
4222
4223    @ue_address_iptype.setter
4224    def ue_address_iptype(self, ip_type):
4225        """ Set IP type of UE for particular PDN
4226
4227        Args:
4228            ip_type: IP type of UE
4229
4230        Returns:
4231            None
4232        """
4233        if not isinstance(ip_type, IPAddressType):
4234            raise ValueError(
4235                ' The parameter should be of type "IPAddressType"')
4236        cmd = "PDNIPTYPE {},{}".format(self._pdn_number, ip_type.value)
4237        self._anritsu.send_command(cmd)
4238
4239    @property
4240    def ue_address_ipv4(self):
4241        """ Gets UE IPv4 address
4242
4243        Args:
4244            None
4245
4246        Returns:
4247            UE IPv4 address
4248        """
4249        cmd = "PDNIPV4? " + self._pdn_number
4250        return self._anritsu.send_query(cmd)
4251
4252    @ue_address_ipv4.setter
4253    def ue_address_ipv4(self, ip_address):
4254        """ Set UE IPv4 address
4255
4256        Args:
4257            ip_address: UE IPv4 address
4258
4259        Returns:
4260            None
4261        """
4262        cmd = "PDNIPV4 {},{}".format(self._pdn_number, ip_address)
4263        self._anritsu.send_command(cmd)
4264
4265    @property
4266    def ue_address_ipv6(self):
4267        """ Gets UE IPv6 address
4268
4269        Args:
4270            None
4271
4272        Returns:
4273            UE IPv6 address
4274        """
4275        cmd = "PDNIPV6? " + self._pdn_number
4276        return self._anritsu.send_query(cmd)
4277
4278    @ue_address_ipv6.setter
4279    def ue_address_ipv6(self, ip_address):
4280        """ Set UE IPv6 address
4281
4282        Args:
4283            ip_address: UE IPv6 address
4284
4285        Returns:
4286            None
4287        """
4288        cmd = "PDNIPV6 {},{}".format(self._pdn_number, ip_address)
4289        self._anritsu.send_command(cmd)
4290
4291    @property
4292    def primary_dns_address_ipv4(self):
4293        """ Gets Primary DNS server IPv4 address
4294
4295        Args:
4296            None
4297
4298        Returns:
4299            Primary DNS server IPv4 address
4300        """
4301        cmd = "PDNDNSIPV4PRI? " + self._pdn_number
4302        return self._anritsu.send_query(cmd)
4303
4304    @primary_dns_address_ipv4.setter
4305    def primary_dns_address_ipv4(self, ip_address):
4306        """ Set Primary DNS server IPv4 address
4307
4308        Args:
4309            ip_address: Primary DNS server IPv4 address
4310
4311        Returns:
4312            None
4313        """
4314        cmd = "PDNDNSIPV4PRI {},{}".format(self._pdn_number, ip_address)
4315        self._anritsu.send_command(cmd)
4316
4317    @property
4318    def secondary_dns_address_ipv4(self):
4319        """ Gets secondary DNS server IPv4 address
4320
4321        Args:
4322            None
4323
4324        Returns:
4325            secondary DNS server IPv4 address
4326        """
4327        cmd = "PDNDNSIPV4SEC? " + self._pdn_number
4328        return self._anritsu.send_query(cmd)
4329
4330    @secondary_dns_address_ipv4.setter
4331    def secondary_dns_address_ipv4(self, ip_address):
4332        """ Set secondary DNS server IPv4 address
4333
4334        Args:
4335            ip_address: secondary DNS server IPv4 address
4336
4337        Returns:
4338            None
4339        """
4340        cmd = "PDNDNSIPV4SEC {},{}".format(self._pdn_number, ip_address)
4341        self._anritsu.send_command(cmd)
4342
4343    @property
4344    def dns_address_ipv6(self):
4345        """ Gets DNS server IPv6 address
4346
4347        Args:
4348            None
4349
4350        Returns:
4351            DNS server IPv6 address
4352        """
4353        cmd = "PDNDNSIPV6? " + self._pdn_number
4354        return self._anritsu.send_query(cmd)
4355
4356    @dns_address_ipv6.setter
4357    def dns_address_ipv6(self, ip_address):
4358        """ Set DNS server IPv6 address
4359
4360        Args:
4361            ip_address: DNS server IPv6 address
4362
4363        Returns:
4364            None
4365        """
4366        cmd = "PDNDNSIPV6 {},{}".format(self._pdn_number, ip_address)
4367        self._anritsu.send_command(cmd)
4368
4369    @property
4370    def cscf_address_ipv4(self):
4371        """ Gets Secondary P-CSCF IPv4 address
4372
4373        Args:
4374            None
4375
4376        Returns:
4377            Secondary P-CSCF IPv4 address
4378        """
4379        cmd = "PDNPCSCFIPV4? " + self._pdn_number
4380        return self._anritsu.send_query(cmd)
4381
4382    @cscf_address_ipv4.setter
4383    def cscf_address_ipv4(self, ip_address):
4384        """ Set Secondary P-CSCF IPv4 address
4385
4386        Args:
4387            ip_address: Secondary P-CSCF IPv4 address
4388
4389        Returns:
4390            None
4391        """
4392        cmd = "PDNPCSCFIPV4 {},{}".format(self._pdn_number, ip_address)
4393        self._anritsu.send_command(cmd)
4394
4395    @property
4396    def cscf_address_ipv6(self):
4397        """ Gets P-CSCF IPv6 address
4398
4399        Args:
4400            None
4401
4402        Returns:
4403            P-CSCF IPv6 address
4404        """
4405        cmd = "PDNPCSCFIPV6? " + self._pdn_number
4406        return self._anritsu.send_query(cmd)
4407
4408    @cscf_address_ipv6.setter
4409    def cscf_address_ipv6(self, ip_address):
4410        """ Set P-CSCF IPv6 address
4411
4412        Args:
4413            ip_address: P-CSCF IPv6 address
4414
4415        Returns:
4416            None
4417        """
4418        cmd = "PDNPCSCFIPV6 {},{}".format(self._pdn_number, ip_address)
4419        self._anritsu.send_command(cmd)
4420
4421    @property
4422    def pdn_ims(self):
4423        """ Get PDN IMS VNID binding status
4424
4425        Args:
4426            None
4427
4428        Returns:
4429            PDN IMS VNID binding status
4430        """
4431        cmd = "PDNIMS? " + self._pdn_number
4432        return self._anritsu.send_query(cmd)
4433
4434    @pdn_ims.setter
4435    def pdn_ims(self, switch):
4436        """ Set PDN IMS VNID binding Enable/Disable
4437
4438        Args:
4439            switch: "ENABLE/DISABLE"
4440
4441        Returns:
4442            None
4443        """
4444        if not isinstance(switch, Switch):
4445            raise ValueError(' The parameter should be of type'
4446                             ' "Switch", ie, ENABLE or DISABLE ')
4447        cmd = "PDNIMS {},{}".format(self._pdn_number, switch.value)
4448        self._anritsu.send_command(cmd)
4449
4450    @property
4451    def pdn_vnid(self):
4452        """ Get PDN IMS VNID
4453
4454        Args:
4455            None
4456
4457        Returns:
4458            PDN IMS VNID
4459        """
4460        cmd = "PDNVNID? " + self._pdn_number
4461        return self._anritsu.send_query(cmd)
4462
4463    @pdn_vnid.setter
4464    def pdn_vnid(self, vnid):
4465        """ Set PDN IMS VNID
4466
4467        Args:
4468            vnid: 1~99
4469
4470        Returns:
4471            None
4472        """
4473        cmd = "PDNVNID {},{}".format(self._pdn_number, vnid)
4474        self._anritsu.send_command(cmd)
4475
4476    @property
4477    def pdn_apn_name(self):
4478        """ Get PDN APN NAME
4479
4480        Args:
4481            None
4482
4483        Returns:
4484            PDN APN NAME
4485        """
4486        cmd = "PDNCHECKAPN? " + self._pdn_number
4487        return self._anritsu.send_query(cmd)
4488
4489    @pdn_apn_name.setter
4490    def pdn_apn_name(self, name):
4491        """ Set PDN APN NAME
4492
4493        Args:
4494            name: fast.t-mobile.com, ims
4495
4496        Returns:
4497            None
4498        """
4499        cmd = "PDNCHECKAPN {},{}".format(self._pdn_number, name)
4500        self._anritsu.send_command(cmd)
4501
4502    @property
4503    def pdn_qci(self):
4504        """ Get PDN QCI Value
4505
4506        Args:
4507            None
4508
4509        Returns:
4510            PDN QCI Value
4511        """
4512        cmd = "PDNQCIDEFAULT? " + self._pdn_number
4513        return self._anritsu.send_query(cmd)
4514
4515    @pdn_qci.setter
4516    def pdn_qci(self, qci_value):
4517        """ Set PDN QCI Value
4518
4519        Args:
4520            qci_value: 5, 9
4521
4522        Returns:
4523            None
4524        """
4525        cmd = "PDNQCIDEFAULT {},{}".format(self._pdn_number, qci_value)
4526        self._anritsu.send_command(cmd)
4527
4528
4529class _TriggerMessage(object):
4530    '''Class to interact with trigger message handling supported by MD8475 '''
4531    def __init__(self, anritsu):
4532        self._anritsu = anritsu
4533        self.log = anritsu.log
4534
4535    def set_reply_type(self, message_id, reply_type):
4536        """ Sets the reply type of the trigger information
4537
4538        Args:
4539            message_id: trigger information message Id
4540            reply_type: reply type of the trigger information
4541
4542        Returns:
4543            None
4544        """
4545        if not isinstance(message_id, TriggerMessageIDs):
4546            raise ValueError(' The parameter should be of type'
4547                             ' "TriggerMessageIDs"')
4548        if not isinstance(reply_type, TriggerMessageReply):
4549            raise ValueError(' The parameter should be of type'
4550                             ' "TriggerMessageReply"')
4551
4552        cmd = "REJECTTYPE {},{}".format(message_id.value, reply_type.value)
4553        self._anritsu.send_command(cmd)
4554
4555    def set_reject_cause(self, message_id, cause):
4556        """ Sets the reject cause of the trigger information
4557
4558        Args:
4559            message_id: trigger information message Id
4560            cause: cause for reject
4561
4562        Returns:
4563            None
4564        """
4565        if not isinstance(message_id, TriggerMessageIDs):
4566            raise ValueError(' The parameter should be of type'
4567                             ' "TriggerMessageIDs"')
4568
4569        cmd = "REJECTCAUSE {},{}".format(message_id.value, cause)
4570        self._anritsu.send_command(cmd)
4571
4572
4573class _IMS_Services(object):
4574    '''Class to configure and operate IMS Services'''
4575    def __init__(self, anritsu, vnid):
4576        self._vnid = vnid
4577        self._anritsu = anritsu
4578        self.log = anritsu.log
4579
4580    @property
4581    def sync(self):
4582        """ Gets Sync Enable status
4583
4584        Args:
4585            None
4586
4587        Returns:
4588            VNID Sync Enable status
4589        """
4590        cmd = "IMSSYNCENABLE? " + self._vnid
4591        return self._anritsu.send_query(cmd)
4592
4593    @sync.setter
4594    def sync(self, switch):
4595        """ Set Sync Enable or Disable
4596
4597        Args:
4598            sync: ENABLE/DISABLE
4599
4600        Returns:
4601            None
4602        """
4603        if not isinstance(switch, Switch):
4604            raise ValueError(' The parameter should be of type "Switch"')
4605        cmd = "IMSSYNCENABLE {},{}".format(self._vnid, switch.value)
4606        self._anritsu.send_command(cmd)
4607
4608    @property
4609    def cscf_address_ipv4(self):
4610        """ Gets CSCF IPv4 address
4611
4612        Args:
4613            None
4614
4615        Returns:
4616            CSCF IPv4 address
4617        """
4618        cmd = "IMSCSCFIPV4? " + self._vnid
4619        return self._anritsu.send_query(cmd)
4620
4621    @cscf_address_ipv4.setter
4622    def cscf_address_ipv4(self, ip_address):
4623        """ Set CSCF IPv4 address
4624
4625        Args:
4626            ip_address: CSCF IPv4 address
4627
4628        Returns:
4629            None
4630        """
4631        cmd = "IMSCSCFIPV4 {},{}".format(self._vnid, ip_address)
4632        self._anritsu.send_command(cmd)
4633
4634    @property
4635    def cscf_address_ipv6(self):
4636        """ Gets CSCF IPv6 address
4637
4638        Args:
4639            None
4640
4641        Returns:
4642            CSCF IPv6 address
4643        """
4644        cmd = "IMSCSCFIPV6? " + self._vnid
4645        return self._anritsu.send_query(cmd)
4646
4647    @cscf_address_ipv6.setter
4648    def cscf_address_ipv6(self, ip_address):
4649        """ Set CSCF IPv6 address
4650
4651        Args:
4652            ip_address: CSCF IPv6 address
4653
4654        Returns:
4655            None
4656        """
4657        cmd = "IMSCSCFIPV6 {},{}".format(self._vnid, ip_address)
4658        self._anritsu.send_command(cmd)
4659
4660    @property
4661    def imscscf_iptype(self):
4662        """ Gets CSCF IP Type
4663
4664        Args:
4665            None
4666
4667        Returns:
4668            CSCF IP Type
4669        """
4670        cmd = "IMSCSCFIPTYPE? " + self._vnid
4671        return self._anritsu.send_query(cmd)
4672
4673    @imscscf_iptype.setter
4674    def imscscf_iptype(self, iptype):
4675        """ Set CSCF IP Type
4676
4677        Args:
4678            iptype: IPV4, IPV6, IPV4V6
4679
4680        Returns:
4681            None
4682        """
4683        cmd = "IMSCSCFIPTYPE {},{}".format(self._vnid, iptype)
4684        self._anritsu.send_command(cmd)
4685
4686    @property
4687    def cscf_monitoring_ua(self):
4688        """ Get CSCF Monitoring UA URI
4689
4690        Args:
4691            None
4692
4693        Returns:
4694            CSCF Monitoring UA URI
4695        """
4696        cmd = "IMSCSCFUAURI? " + self._vnid
4697        return self._anritsu.send_query(cmd)
4698
4699    @cscf_monitoring_ua.setter
4700    def cscf_monitoring_ua(self, ua_uri):
4701        """ Set CSCF Monitoring UA URI
4702
4703        Args:
4704            ua_uri: CSCF Monitoring UA URI
4705
4706        Returns:
4707            None
4708        """
4709        cmd = "IMSCSCFUAURI {},{}".format(self._vnid, ua_uri)
4710        self._anritsu.send_command(cmd)
4711
4712    @property
4713    def cscf_host_name(self):
4714        """ Get CSCF Host Name
4715
4716        Args:
4717            None
4718
4719        Returns:
4720            CSCF Host Name
4721        """
4722        cmd = "IMSCSCFNAME? " + self._vnid
4723        return self._anritsu.send_query(cmd)
4724
4725    @cscf_host_name.setter
4726    def cscf_host_name(self, host_name):
4727        """ Set CSCF Host Name
4728
4729        Args:
4730            host_name: CSCF Host Name
4731
4732        Returns:
4733            None
4734        """
4735        cmd = "IMSCSCFNAME {},{}".format(self._vnid, host_name)
4736        self._anritsu.send_command(cmd)
4737
4738    @property
4739    def cscf_ims_authentication(self):
4740        """ Get CSCF IMS Auth Value
4741
4742        Args:
4743            None
4744
4745        Returns:
4746            CSCF IMS Auth
4747        """
4748        cmd = "IMSCSCFAUTH? " + self._vnid
4749        return self._anritsu.send_query(cmd)
4750
4751    @cscf_ims_authentication.setter
4752    def cscf_ims_authentication(self, on_off):
4753        """ Set CSCF IMS Auth Value
4754
4755        Args:
4756            on_off: CSCF IMS Auth ENABLE/DISABLE
4757
4758        Returns:
4759            None
4760        """
4761        cmd = "IMSCSCFAUTH {},{}".format(self._vnid, on_off)
4762        self._anritsu.send_command(cmd)
4763
4764    @property
4765    def cscf_precondition(self):
4766        """ Get CSCF IMS Precondition
4767
4768        Args:
4769            None
4770
4771        Returns:
4772            CSCF IMS Precondition
4773        """
4774        cmd = "IMSCSCFPRECONDITION? " + self._vnid
4775        return self._anritsu.send_query(cmd)
4776
4777    @cscf_precondition.setter
4778    def cscf_precondition(self, on_off):
4779        """ Set CSCF IMS Precondition
4780
4781        Args:
4782            on_off: CSCF IMS Precondition ENABLE/DISABLE
4783
4784        Returns:
4785            None
4786        """
4787        cmd = "IMSCSCFPRECONDITION {},{}".format(self._vnid, on_off)
4788        self._anritsu.send_command(cmd)
4789
4790    @property
4791    def cscf_virtual_ua(self):
4792        """ Get CSCF Virtual UA URI
4793
4794        Args:
4795            None
4796
4797        Returns:
4798            CSCF Virtual UA URI
4799        """
4800        cmd = "IMSCSCFVUAURI? " + self._vnid
4801        return self._anritsu.send_query(cmd)
4802
4803    @cscf_virtual_ua.setter
4804    def cscf_virtual_ua(self, ua_uri):
4805        """ Set CSCF Virtual UA URI
4806
4807        Args:
4808            ua_uri: CSCF Virtual UA URI
4809
4810        Returns:
4811            None
4812        """
4813        cmd = "IMSCSCFVUAURI {},{}".format(self._vnid, ua_uri)
4814        self._anritsu.send_command(cmd)
4815
4816    @property
4817    def tmo_cscf_userslist_add(self):
4818        """ Get CSCF USERLIST
4819
4820        Args:
4821            None
4822
4823        Returns:
4824            CSCF USERLIST
4825        """
4826        cmd = "IMSCSCFUSERSLIST? " + self._vnid
4827        return self._anritsu.send_query(cmd)
4828
4829    @tmo_cscf_userslist_add.setter
4830    def tmo_cscf_userslist_add(self, username):
4831        """ Set CSCF USER to USERLIST
4832            This is needed if IMS AUTH is enabled
4833
4834        Args:
4835            username: CSCF Username
4836
4837        Returns:
4838            None
4839        """
4840        cmd = "IMSCSCFUSERSLISTADD {},{},00112233445566778899AABBCCDDEEFF,TS34108,AKAV1_MD5,\
4841        OPC,00000000000000000000000000000000,8000,TRUE,FALSE,0123456789ABCDEF0123456789ABCDEF,\
4842        54CDFEAB9889000001326754CDFEAB98,6754CDFEAB9889BAEFDC457623100132,\
4843        326754CDFEAB9889BAEFDC4576231001,TRUE,TRUE,TRUE".format(
4844            self._vnid, username)
4845        self._anritsu.send_command(cmd)
4846
4847    @property
4848    def fi_cscf_userslist_add(self):
4849        """ Get CSCF USERLIST
4850
4851        Args:
4852            None
4853
4854        Returns:
4855            CSCF USERLIST
4856        """
4857        cmd = "IMSCSCFUSERSLIST? " + self._vnid
4858        return self._anritsu.send_query(cmd)
4859
4860    @fi_cscf_userslist_add.setter
4861    def fi_cscf_userslist_add(self, username):
4862        """ Set CSCF USER to USERLIST
4863            This is needed if IMS AUTH is enabled
4864
4865        Args:
4866            username: CSCF Username
4867
4868        Returns:
4869            None
4870        """
4871        cmd = "IMSCSCFUSERSLISTADD {},{},00112233445566778899AABBCCDDEEFF,TS34108,AKAV1_MD5,\
4872        OPC,00000000000000000000000000000000,8000,TRUE,FALSE,0123456789ABCDEF0123456789ABCDEF,\
4873        54CDFEAB9889000001326754CDFEAB98,6754CDFEAB9889BAEFDC457623100132,\
4874        326754CDFEAB9889BAEFDC4576231001,TRUE,TRUE,TRUE".format(
4875            self._vnid, username)
4876        self._anritsu.send_command(cmd)
4877
4878    @property
4879    def vzw_cscf_userslist_add(self):
4880        """ Get CSCF USERLIST
4881
4882        Args:
4883            None
4884
4885        Returns:
4886            CSCF USERLIST
4887        """
4888        cmd = "IMSCSCFUSERSLIST? " + self._vnid
4889        return self._anritsu.send_query(cmd)
4890
4891    @vzw_cscf_userslist_add.setter
4892    def vzw_cscf_userslist_add(self, username):
4893        """ Set CSCF USER to USERLIST
4894            This is needed if IMS AUTH is enabled
4895
4896        Args:
4897            username: CSCF Username
4898
4899        Returns:
4900            None
4901        """
4902        cmd = "IMSCSCFUSERSLISTADD {},{},465B5CE8B199B49FAA5F0A2EE238A6BC,MILENAGE,AKAV1_MD5,\
4903        OP,5F1D289C5D354D0A140C2548F5F3E3BA,8000,TRUE,FALSE,0123456789ABCDEF0123456789ABCDEF,\
4904        54CDFEAB9889000001326754CDFEAB98,6754CDFEAB9889BAEFDC457623100132,\
4905        326754CDFEAB9889BAEFDC4576231001,TRUE,TRUE,TRUE".format(
4906            self._vnid, username)
4907        self._anritsu.send_command(cmd)
4908
4909    @property
4910    def dns(self):
4911        """ Gets DNS Enable status
4912
4913        Args:
4914            None
4915
4916        Returns:
4917            VNID DNS Enable status
4918        """
4919        cmd = "IMSDNS? " + self._vnid
4920        return self._anritsu.send_query(cmd)
4921
4922    @dns.setter
4923    def dns(self, switch):
4924        """ Set DNS Enable or Disable
4925
4926        Args:
4927            sync: ENABLE/DISABLE
4928
4929        Returns:
4930            None
4931        """
4932        if not isinstance(switch, Switch):
4933            raise ValueError(' The parameter should be of type "Switch"')
4934        cmd = "IMSDNS {},{}".format(self._vnid, switch.value)
4935        self._anritsu.send_command(cmd)
4936
4937    @property
4938    def ndp_nic(self):
4939        """ Gets NDP Network Interface name
4940
4941        Args:
4942            None
4943
4944        Returns:
4945            NDP NIC name
4946        """
4947        cmd = "IMSNDPNIC? " + self._vnid
4948        return self._anritsu.send_query(cmd)
4949
4950    @ndp_nic.setter
4951    def ndp_nic(self, nic_name):
4952        """ Set NDP Network Interface name
4953
4954        Args:
4955            nic_name: NDP Network Interface name
4956
4957        Returns:
4958            None
4959        """
4960        cmd = "IMSNDPNIC {},{}".format(self._vnid, nic_name)
4961        self._anritsu.send_command(cmd)
4962
4963    @property
4964    def ndp_prefix(self):
4965        """ Gets NDP IPv6 Prefix
4966
4967        Args:
4968            None
4969
4970        Returns:
4971            NDP IPv6 Prefix
4972        """
4973        cmd = "IMSNDPPREFIX? " + self._vnid
4974        return self._anritsu.send_query(cmd)
4975
4976    @ndp_prefix.setter
4977    def ndp_prefix(self, prefix_addr):
4978        """ Set NDP IPv6 Prefix
4979
4980        Args:
4981            prefix_addr: NDP IPV6 Prefix Addr
4982
4983        Returns:
4984            None
4985        """
4986        cmd = "IMSNDPPREFIX {},{},64".format(self._vnid, prefix_addr)
4987        self._anritsu.send_command(cmd)
4988
4989    @property
4990    def psap(self):
4991        """ Gets PSAP Enable status
4992
4993        Args:
4994            None
4995
4996        Returns:
4997            VNID PSAP Enable status
4998        """
4999        cmd = "IMSPSAP? " + self._vnid
5000        return self._anritsu.send_query(cmd)
5001
5002    @psap.setter
5003    def psap(self, switch):
5004        """ Set PSAP Enable or Disable
5005
5006        Args:
5007            switch: ENABLE/DISABLE
5008
5009        Returns:
5010            None
5011        """
5012        if not isinstance(switch, Switch):
5013            raise ValueError(' The parameter should be of type "Switch"')
5014        cmd = "IMSPSAP {},{}".format(self._vnid, switch.value)
5015        self._anritsu.send_command(cmd)
5016
5017    @property
5018    def psap_auto_answer(self):
5019        """ Gets PSAP Auto Answer status
5020
5021        Args:
5022            None
5023
5024        Returns:
5025            VNID PSAP Auto Answer status
5026        """
5027        cmd = "IMSPSAPAUTOANSWER? " + self._vnid
5028        return self._anritsu.send_query(cmd)
5029
5030    @psap_auto_answer.setter
5031    def psap_auto_answer(self, switch):
5032        """ Set PSAP Auto Answer Enable or Disable
5033
5034        Args:
5035            switch: ENABLE/DISABLE
5036
5037        Returns:
5038            None
5039        """
5040        if not isinstance(switch, Switch):
5041            raise ValueError(' The parameter should be of type "Switch"')
5042        cmd = "IMSPSAPAUTOANSWER {},{}".format(self._vnid, switch.value)
5043        self._anritsu.send_command(cmd)
5044
5045    def start_virtual_network(self):
5046        """ Start the specified Virtual Network (IMS service)
5047
5048        Args:
5049            None
5050
5051        Returns:
5052            None
5053        """
5054        cmd = "IMSSTARTVN " + self._vnid
5055        return self._anritsu.send_command(cmd)
5056