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