• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2#
3#   Copyright 2022 - Google
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
17import json
18import logging
19from typing import Any, Mapping, Optional, Union
20
21from acts.controllers.amarisoft_lib import amarisoft_client
22from acts.controllers.amarisoft_lib import amarisoft_constants as const
23
24
25class ImsFunctions():
26  """Utilities for Amarisoft's IMS Remote API.
27
28  Attributes:
29    remote: An amarisoft client.
30  """
31
32  def __init__(self, remote: amarisoft_client.AmariSoftClient):
33    self.remote = remote
34
35  def make_call(self,
36              impi: str,
37              impu: str,
38              contact: str,
39              sip_file: str = 'mt_call_qos.sdp',
40              caller: str = 'Amarisoft',
41              duration: int = 30) -> None:
42    """Performs MT call from callbox to test device.
43
44    Args:
45      impi: IMPI (IP Multimedia Private identity) of user to call.
46      impu: IMPU (IP Multimedia Public identity) of user to call.
47      contact: Contact SIP uri of user to call.
48      sip_file: Define file to use as sdp.
49      caller: The number/ID is displayed as the caller.
50      duration: If set, call duration in seconds (The server will close the
51        dialog).
52    """
53    msg = {}
54    msg['message'] = 'mt_call'
55    msg['impi'] = impi
56    msg['impu'] = impu
57    msg['contact'] = contact
58    msg['sip_file'] = sip_file
59    msg['caller'] = caller
60    msg['duration'] = duration
61    dump_msg = json.dumps(msg)
62    logging.debug('mt_call dump msg = %s', dump_msg)
63    head, body = self.remote.send_message(const.PortNumber.URI_IMS, dump_msg)
64    self.remote.verify_response('mt_call', head, body)
65
66  def send_sms(self,
67               text: str,
68               impi: str,
69               sender: Optional[str] = 'Amarisoft') -> None:
70    """Sends SMS to assigned device which connect to Amarisoft.
71
72    Args:
73      text: SMS text to send.
74      impi: IMPI (IP Multimedia Private identity) of user.
75      sender: Sets SMS sender.
76    """
77    msg = {}
78    msg['message'] = 'sms'
79    msg['text'] = text
80    msg['impi'] = impi
81    msg['sender'] = sender
82    dump_msg = json.dumps(msg)
83    logging.debug('send_sms dump msg = %s', dump_msg)
84    head, body = self.remote.send_message(const.PortNumber.URI_IMS, dump_msg)
85    self.remote.verify_response('sms', head, body)
86
87  def send_mms(self, filename: str, sender: str, receiver: str) -> None:
88    """Sends MMS to assigned device which connect to Amarisoft.
89
90    Args:
91      filename: File name with absolute path to send. Extensions jpg, jpeg, png,
92        gif and txt are supported.
93      sender: IMPI (IP Multimedia Private identity) of user.
94      receiver: IMPU (IP Multimedia Public identity) of user.
95    """
96    msg = {}
97    msg['message'] = 'mms'
98    msg['filename'] = filename
99    msg['sender'] = sender
100    msg['receiver'] = receiver
101    dump_msg = json.dumps(msg)
102    logging.debug('send_mms dump msg = %s', dump_msg)
103    head, body = self.remote.send_message(const.PortNumber.URI_IMS, dump_msg)
104    self.remote.verify_response('mms', head, body)
105
106  def users_get(self, registered_only: bool = True) -> Mapping[str, Any]:
107    """Gets users state.
108
109    Args:
110      registered_only: If set, only registered user will be dumped.
111
112    Returns:
113      The user information.
114    """
115    msg = {}
116    msg['message'] = 'users_get'
117    msg['registered_only'] = registered_only
118    dump_msg = json.dumps(msg)
119    logging.debug('users_get dump msg = %s', dump_msg)
120    head, body = self.remote.send_message(const.PortNumber.URI_IMS, dump_msg)
121    _, loaded_body = self.remote.verify_response('users_get', head, body)
122    return loaded_body
123
124  def get_impu(self, impi) -> Union[str, None]:
125    """Obtains the IMPU of the target user according to IMPI.
126
127    Args:
128      impi: IMPI (IP Multimedia Private identity) of user to call. ex:
129        "310260123456785@ims.mnc260.mcc310.3gppnetwork.org"
130
131    Returns:
132      The IMPU of target user.
133    """
134    body = self.users_get(True)
135    for index in range(len(body['users'])):
136      if impi in body['users'][index]['impi']:
137        impu = body['users'][index]['bindings'][0]['impu'][1]
138        return impu
139    return None
140
141  def get_uri(self, impi) -> Union[str, None]:
142    """Obtains the URI of the target user according to IMPI.
143
144    Args:
145      impi: IMPI (IP Multimedia Private identity) of user to call. ex:
146        "310260123456785@ims.mnc260.mcc310.3gppnetwork.org"
147
148    Returns:
149      The URI of target user.
150    """
151    body = self.users_get(True)
152    for index in range(len(body['users'])):
153      if impi in body['users'][index]['impi']:
154        uri = body['users'][index]['bindings'][0]['uri']
155        return uri
156    return None
157