Pau Espin Pedrol | 37ee0ed | 2024-03-28 21:17:12 +0100 | [diff] [blame] | 1 | module Asterisk_Tests { |
| 2 | |
| 3 | /* Asterisk test suite in TTCN-3 |
| 4 | * (C) 2024 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de> |
| 5 | * All rights reserved. |
| 6 | * Author: Pau Espin Pedrol <pespin@sysmocom.de> |
| 7 | * |
| 8 | * Released under the terms of GNU General Public License, Version 2 or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 12 | */ |
| 13 | |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 14 | import from TCCOpenSecurity_Functions all; |
Pau Espin Pedrol | 37ee0ed | 2024-03-28 21:17:12 +0100 | [diff] [blame] | 15 | import from General_Types all; |
| 16 | import from Osmocom_Types all; |
| 17 | import from Native_Functions all; |
| 18 | import from Misc_Helpers all; |
Pau Espin Pedrol | 54b614a | 2024-04-17 18:58:36 +0200 | [diff] [blame] | 19 | import from TELNETasp_PortType all; |
| 20 | import from AMI_Functions all; |
Pau Espin Pedrol | 37ee0ed | 2024-03-28 21:17:12 +0100 | [diff] [blame] | 21 | |
| 22 | import from SDP_Types all; |
| 23 | import from SDP_Templates all; |
| 24 | |
| 25 | import from SIP_Emulation all; |
| 26 | import from SIPmsg_Types all; |
| 27 | import from SIP_Templates all; |
| 28 | |
Pau Espin Pedrol | caf028d | 2024-04-18 13:47:07 +0200 | [diff] [blame] | 29 | import from SIP_ConnectionHandler all; |
Pau Espin Pedrol | ac8a054 | 2024-04-19 17:30:57 +0200 | [diff] [blame] | 30 | import from IMS_ConnectionHandler all; |
Pau Espin Pedrol | caf028d | 2024-04-18 13:47:07 +0200 | [diff] [blame] | 31 | |
Pau Espin Pedrol | 37ee0ed | 2024-03-28 21:17:12 +0100 | [diff] [blame] | 32 | modulepar { |
| 33 | charstring mp_local_sip_host := "127.0.0.2"; |
| 34 | integer mp_local_sip_port := 5060; |
| 35 | charstring mp_remote_sip_host := "127.0.0.1"; |
| 36 | integer mp_remote_sip_port := 5060; |
Pau Espin Pedrol | 54b614a | 2024-04-17 18:58:36 +0200 | [diff] [blame] | 37 | |
Pau Espin Pedrol | ac8a054 | 2024-04-19 17:30:57 +0200 | [diff] [blame] | 38 | charstring mp_local_ims_host := "127.0.0.3"; |
| 39 | integer mp_local_ims_port := 5060; |
Pau Espin Pedrol | a2812ec | 2024-05-10 20:30:44 +0200 | [diff] [blame] | 40 | charstring mp_ims_imsi := "238010000090828"; |
Pau Espin Pedrol | ac8a054 | 2024-04-19 17:30:57 +0200 | [diff] [blame] | 41 | |
Pau Espin Pedrol | 54b614a | 2024-04-17 18:58:36 +0200 | [diff] [blame] | 42 | /* Asterisk AMI: */ |
Pau Espin Pedrol | 01f1df8 | 2024-05-08 16:55:55 +0200 | [diff] [blame] | 43 | charstring mp_ami_remote_host := "127.0.0.1"; |
| 44 | integer mp_ami_remote_port := 5038; |
| 45 | charstring mp_ami_local_host := "0.0.0.0"; |
| 46 | integer mp_ami_local_port := 0; |
Pau Espin Pedrol | 54b614a | 2024-04-17 18:58:36 +0200 | [diff] [blame] | 47 | charstring mp_ami_user := "test_user"; |
| 48 | charstring mp_ami_secret := "1234"; |
Pau Espin Pedrol | a2812ec | 2024-05-10 20:30:44 +0200 | [diff] [blame] | 49 | charstring mp_volte_ims_outbound_registration := "volte_ims"; |
Pau Espin Pedrol | 37ee0ed | 2024-03-28 21:17:12 +0100 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | type component test_CT { |
Pau Espin Pedrol | ac8a054 | 2024-04-19 17:30:57 +0200 | [diff] [blame] | 53 | /* Manages all local VoIP users Asterisk is serving: */ |
Pau Espin Pedrol | 37ee0ed | 2024-03-28 21:17:12 +0100 | [diff] [blame] | 54 | var SIP_Emulation_CT vc_SIP; |
Pau Espin Pedrol | ac8a054 | 2024-04-19 17:30:57 +0200 | [diff] [blame] | 55 | /* Manages the IMS server Asterisk connects to: */ |
| 56 | var SIP_Emulation_CT vc_IMS; |
| 57 | |
Pau Espin Pedrol | bcb4e82 | 2024-04-26 20:16:47 +0200 | [diff] [blame] | 58 | /* Connection towards Asterisk AMI iface: */ |
| 59 | var AMI_Adapter_CT vc_AMI; |
| 60 | port AMI_Msg_PT AMI_CLIENT; |
Pau Espin Pedrol | ac8a054 | 2024-04-19 17:30:57 +0200 | [diff] [blame] | 61 | |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 62 | port Coord_PT COORD; |
Pau Espin Pedrol | ac8a054 | 2024-04-19 17:30:57 +0200 | [diff] [blame] | 63 | port IMSCoord_PT IMS_COORD; |
Pau Espin Pedrol | 37ee0ed | 2024-03-28 21:17:12 +0100 | [diff] [blame] | 64 | } |
| 65 | |
Pau Espin Pedrol | 32167d8 | 2024-04-10 13:14:51 +0200 | [diff] [blame] | 66 | const charstring broadcast_sip_extension := "0500"; |
Pau Espin Pedrol | 37ee0ed | 2024-03-28 21:17:12 +0100 | [diff] [blame] | 67 | |
Pau Espin Pedrol | 901cede | 2024-05-30 13:03:42 +0200 | [diff] [blame] | 68 | /* TODO: need to find correct RES, CK, IK, values for: |
| 69 | * Response: "a19de225d030e6e0ec20f6de5f9dd80d" |
| 70 | * CNonce Value: "9a6460bcc3c84a3eac69455a93b67a77" |
| 71 | */ |
| 72 | const charstring c_auth_res := "a19de225d030e6e0"; |
| 73 | const charstring c_auth_ck := "9a6460bcc3c84a3eac69455a93b67a77"; |
| 74 | const charstring c_auth_ik := "5238297dfcca759bd05d48ff49bc63fa"; |
| 75 | |
Pau Espin Pedrol | caf028d | 2024-04-18 13:47:07 +0200 | [diff] [blame] | 76 | function f_init_ConnHdlrPars(integer idx := 1) runs on test_CT return SIPConnHdlrPars { |
| 77 | var template (value) CallPars cp := t_CallPars(mp_local_sip_host, 1234 + 2*idx); |
| 78 | var template (value) SIPConnHdlrPars pars := t_Pars(mp_local_sip_host, |
| 79 | mp_local_sip_port, |
| 80 | mp_remote_sip_host, |
| 81 | mp_remote_sip_port, |
| 82 | "0" & int2str(str2int(broadcast_sip_extension) + idx), |
| 83 | cp := cp); |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 84 | return valueof(pars); |
Pau Espin Pedrol | 37ee0ed | 2024-03-28 21:17:12 +0100 | [diff] [blame] | 85 | } |
| 86 | |
Pau Espin Pedrol | a2812ec | 2024-05-10 20:30:44 +0200 | [diff] [blame] | 87 | function f_init_IMS_ConnHdlrPars(integer idx := 1) runs on test_CT return IMS_ConnHdlrPars { |
| 88 | var template (value) IMS_CallPars cp := t_IMS_CallPars(mp_local_sip_host, 1234 + 2*idx); |
| 89 | var template (value) IMS_ConnHdlrPars pars := t_IMS_Pars(mp_local_ims_host, |
| 90 | mp_local_ims_port, |
| 91 | mp_ims_imsi, |
| 92 | cp := cp); |
| 93 | return valueof(pars); |
| 94 | } |
| 95 | |
Pau Espin Pedrol | 54b614a | 2024-04-17 18:58:36 +0200 | [diff] [blame] | 96 | /* Initialize connection towards Asterisk AMI */ |
| 97 | private function f_init_ami() runs on test_CT { |
Pau Espin Pedrol | bcb4e82 | 2024-04-26 20:16:47 +0200 | [diff] [blame] | 98 | var charstring id := "Asterisk_Tests_AMI_EMU"; |
Pau Espin Pedrol | 01f1df8 | 2024-05-08 16:55:55 +0200 | [diff] [blame] | 99 | vc_AMI := AMI_Adapter_CT.create(id) alive; |
Pau Espin Pedrol | bcb4e82 | 2024-04-26 20:16:47 +0200 | [diff] [blame] | 100 | connect(self:AMI_CLIENT, vc_AMI:CLIENT); |
Pau Espin Pedrol | 01f1df8 | 2024-05-08 16:55:55 +0200 | [diff] [blame] | 101 | |
| 102 | var AMI_Adapter_Parameters ami_pars := { |
| 103 | remote_host := mp_ami_remote_host, |
| 104 | remote_port := mp_ami_remote_port, |
| 105 | local_host := mp_ami_local_host, |
| 106 | local_port := mp_ami_local_port, |
| 107 | welcome_str := c_default_AMI_Adapter_pars.welcome_str |
| 108 | }; |
| 109 | vc_AMI.start(f_AMI_Adapter_main(ami_pars)); |
Pau Espin Pedrol | bcb4e82 | 2024-04-26 20:16:47 +0200 | [diff] [blame] | 110 | |
Pau Espin Pedrol | bcb4e82 | 2024-04-26 20:16:47 +0200 | [diff] [blame] | 111 | f_ami_action_login(AMI_CLIENT, mp_ami_user, mp_ami_secret); |
Pau Espin Pedrol | e98f441 | 2024-05-17 19:33:46 +0200 | [diff] [blame] | 112 | |
| 113 | timer tReady; |
| 114 | tReady.start(10.0); |
| 115 | alt { |
| 116 | [] AMI_CLIENT.receive(tr_AMI_Event_FullyBooted); |
| 117 | [] as_ami_rx_ignore(AMI_CLIENT); |
| 118 | [] tReady.timeout { |
| 119 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 120 | log2str("AMI FullyBooted timeout: ")); |
| 121 | } |
| 122 | } |
Pau Espin Pedrol | 54b614a | 2024-04-17 18:58:36 +0200 | [diff] [blame] | 123 | } |
| 124 | |
Pau Espin Pedrol | ac8a054 | 2024-04-19 17:30:57 +0200 | [diff] [blame] | 125 | /* Local SIP UAs */ |
| 126 | private function f_init_sip_local() runs on test_CT { |
| 127 | var charstring id := "Asterisk_Tests_LOCAL_SIP_EMU"; |
| 128 | f_init_sip(vc_SIP, id); |
| 129 | } |
| 130 | |
| 131 | /* IMS Server connection */ |
| 132 | private function f_init_sip_ims() runs on test_CT { |
| 133 | var charstring id := "Asterisk_Tests_IMS_SIP_EMU"; |
| 134 | f_init_sip(vc_IMS, id); |
| 135 | } |
| 136 | |
Pau Espin Pedrol | 37ee0ed | 2024-03-28 21:17:12 +0100 | [diff] [blame] | 137 | function f_init() runs on test_CT { |
Pau Espin Pedrol | ac8a054 | 2024-04-19 17:30:57 +0200 | [diff] [blame] | 138 | var charstring id; |
| 139 | |
Pau Espin Pedrol | 54b614a | 2024-04-17 18:58:36 +0200 | [diff] [blame] | 140 | f_init_ami(); |
Pau Espin Pedrol | ac8a054 | 2024-04-19 17:30:57 +0200 | [diff] [blame] | 141 | f_init_sip_local(); |
| 142 | f_init_sip_ims(); |
Pau Espin Pedrol | 37ee0ed | 2024-03-28 21:17:12 +0100 | [diff] [blame] | 143 | log("end of f_init"); |
| 144 | } |
| 145 | |
Pau Espin Pedrol | 01f1df8 | 2024-05-08 16:55:55 +0200 | [diff] [blame] | 146 | function f_shutdown() runs on test_CT { |
| 147 | /* Tear down AMI Adapter to avoid it keep receiving data from Asterisk |
| 148 | * and sending it to us after we stopped, causing error (Broken Pipe): */ |
| 149 | vc_AMI.stop; |
| 150 | vc_AMI.done; |
| 151 | log("end of ", testcasename()); |
| 152 | setverdict(pass); |
| 153 | } |
| 154 | |
Pau Espin Pedrol | caf028d | 2024-04-18 13:47:07 +0200 | [diff] [blame] | 155 | function f_start_handler(void_fn fn, SIPConnHdlrPars pars) |
| 156 | runs on test_CT return SIPConnHdlr { |
| 157 | var SIPConnHdlr vc_conn; |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 158 | var charstring id := testcasename() & "-ConnHdlr-" & pars.user; |
Pau Espin Pedrol | 37ee0ed | 2024-03-28 21:17:12 +0100 | [diff] [blame] | 159 | |
Pau Espin Pedrol | caf028d | 2024-04-18 13:47:07 +0200 | [diff] [blame] | 160 | vc_conn := SIPConnHdlr.create(id) alive; |
Pau Espin Pedrol | 37ee0ed | 2024-03-28 21:17:12 +0100 | [diff] [blame] | 161 | |
| 162 | connect(vc_conn:SIP, vc_SIP:CLIENT); |
| 163 | connect(vc_conn:SIP_PROC, vc_SIP:CLIENT_PROC); |
| 164 | |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 165 | connect(vc_conn:COORD, self:COORD); |
| 166 | |
Pau Espin Pedrol | 37ee0ed | 2024-03-28 21:17:12 +0100 | [diff] [blame] | 167 | vc_conn.start(f_handler_init(fn, id, pars)); |
| 168 | return vc_conn; |
| 169 | } |
| 170 | |
Pau Espin Pedrol | a2812ec | 2024-05-10 20:30:44 +0200 | [diff] [blame] | 171 | function f_start_handler_IMS(ims_void_fn fn, IMS_ConnHdlrPars pars) |
| 172 | runs on test_CT return IMS_ConnHdlr { |
| 173 | var IMS_ConnHdlr vc_conn; |
Pau Espin Pedrol | 901cede | 2024-05-30 13:03:42 +0200 | [diff] [blame] | 174 | var charstring id := testcasename() & "-IMS_ConnHdlr-" & pars.subscr.imsi; |
Pau Espin Pedrol | a2812ec | 2024-05-10 20:30:44 +0200 | [diff] [blame] | 175 | |
| 176 | vc_conn := IMS_ConnHdlr.create(id) alive; |
| 177 | |
| 178 | connect(vc_conn:SIP, vc_IMS:CLIENT); |
| 179 | connect(vc_conn:SIP_PROC, vc_IMS:CLIENT_PROC); |
| 180 | |
| 181 | connect(vc_conn:COORD, self:IMS_COORD); |
| 182 | |
| 183 | vc_conn.start(f_ims_handler_init(fn, id, pars)); |
| 184 | return vc_conn; |
| 185 | } |
| 186 | |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 187 | /* Test SIP registration of local clients */ |
Pau Espin Pedrol | caf028d | 2024-04-18 13:47:07 +0200 | [diff] [blame] | 188 | private function f_TC_internal_registration(charstring id) runs on SIPConnHdlr { |
Pau Espin Pedrol | 37ee0ed | 2024-03-28 21:17:12 +0100 | [diff] [blame] | 189 | |
| 190 | f_SIP_register(); |
Pau Espin Pedrol | 37ee0ed | 2024-03-28 21:17:12 +0100 | [diff] [blame] | 191 | // f_SIP_deregister(); |
| 192 | setverdict(pass); |
| 193 | } |
Pau Espin Pedrol | 37ee0ed | 2024-03-28 21:17:12 +0100 | [diff] [blame] | 194 | testcase TC_internal_registration() runs on test_CT { |
Pau Espin Pedrol | caf028d | 2024-04-18 13:47:07 +0200 | [diff] [blame] | 195 | var SIPConnHdlrPars pars; |
| 196 | var SIPConnHdlr vc_conn; |
Pau Espin Pedrol | 37ee0ed | 2024-03-28 21:17:12 +0100 | [diff] [blame] | 197 | f_init(); |
| 198 | pars := f_init_ConnHdlrPars(); |
| 199 | vc_conn := f_start_handler(refers(f_TC_internal_registration), pars); |
| 200 | vc_conn.done; |
Pau Espin Pedrol | 01f1df8 | 2024-05-08 16:55:55 +0200 | [diff] [blame] | 201 | f_shutdown(); |
Pau Espin Pedrol | 37ee0ed | 2024-03-28 21:17:12 +0100 | [diff] [blame] | 202 | } |
| 203 | |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 204 | /* Successful SIP MO-MT Call between local clients: */ |
Pau Espin Pedrol | caf028d | 2024-04-18 13:47:07 +0200 | [diff] [blame] | 205 | private function f_TC_internal_call_mo(charstring id) runs on SIPConnHdlr { |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 206 | |
| 207 | f_SIP_register(); |
| 208 | COORD.send(COORD_CMD_REGISTERED); |
| 209 | |
| 210 | COORD.receive(COORD_CMD_START); |
| 211 | f_SIP_mo_call_setup(); |
| 212 | COORD.send(COORD_CMD_CALL_ESTABLISHED); |
| 213 | |
| 214 | COORD.receive(COORD_CMD_HANGUP); |
| 215 | f_SIP_do_call_hangup(); |
| 216 | |
| 217 | setverdict(pass); |
| 218 | } |
Pau Espin Pedrol | caf028d | 2024-04-18 13:47:07 +0200 | [diff] [blame] | 219 | private function f_TC_internal_call_mt(charstring id) runs on SIPConnHdlr { |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 220 | |
| 221 | f_create_sip_expect(valueof(ts_SipUrl_from_Addr_Union(g_pars.cp.called.addr))); |
| 222 | |
| 223 | f_SIP_register(); |
| 224 | COORD.send(COORD_CMD_REGISTERED); |
| 225 | |
Pau Espin Pedrol | 32167d8 | 2024-04-10 13:14:51 +0200 | [diff] [blame] | 226 | if (g_pars.cp.mt.exp_cancel) { |
| 227 | as_SIP_mt_call_cancelled(); |
| 228 | COORD.send(COORD_CMD_CALL_CANCELLED); |
| 229 | setverdict(pass); |
| 230 | return; |
| 231 | } |
| 232 | |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 233 | as_SIP_mt_call_accept(); |
| 234 | COORD.send(COORD_CMD_CALL_ESTABLISHED); |
| 235 | |
| 236 | /* Once MO hangs up, Asterisk updates us to point RTP to it: */ |
| 237 | as_SIP_exp_call_update(g_pars.cp.sip_seq_nr + 1); |
| 238 | as_SIP_exp_call_hangup(g_pars.cp.sip_seq_nr + 1); |
| 239 | |
| 240 | setverdict(pass); |
| 241 | } |
| 242 | testcase TC_internal_call_momt() runs on test_CT { |
Pau Espin Pedrol | caf028d | 2024-04-18 13:47:07 +0200 | [diff] [blame] | 243 | var SIPConnHdlrPars pars[2]; |
| 244 | var SIPConnHdlr vc_conn[2]; |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 245 | |
| 246 | f_init(); |
| 247 | |
| 248 | pars[0] := f_init_ConnHdlrPars(idx := 1); |
| 249 | pars[1] := f_init_ConnHdlrPars(idx := 2); |
| 250 | |
| 251 | pars[0].cp.calling := pars[0].registrar_sip_record; |
| 252 | pars[0].cp.called := pars[1].registrar_sip_record; |
| 253 | |
| 254 | pars[1].cp.calling := pars[0].registrar_sip_record; |
| 255 | pars[1].cp.called := pars[1].local_sip_record; |
| 256 | |
| 257 | vc_conn[0] := f_start_handler(refers(f_TC_internal_call_mo), pars[0]); |
| 258 | vc_conn[1] := f_start_handler(refers(f_TC_internal_call_mt), pars[1]); |
| 259 | |
| 260 | interleave { |
| 261 | [] COORD.receive(COORD_CMD_REGISTERED) from vc_conn[0]; |
| 262 | [] COORD.receive(COORD_CMD_REGISTERED) from vc_conn[1]; |
| 263 | } |
| 264 | |
| 265 | COORD.send(COORD_CMD_START) to vc_conn[0]; |
| 266 | |
| 267 | interleave { |
| 268 | [] COORD.receive(COORD_CMD_CALL_ESTABLISHED) from vc_conn[0]; |
| 269 | [] COORD.receive(COORD_CMD_CALL_ESTABLISHED) from vc_conn[1]; |
| 270 | } |
| 271 | |
Pau Espin Pedrol | 32167d8 | 2024-04-10 13:14:51 +0200 | [diff] [blame] | 272 | /* Call on-going */ |
| 273 | f_sleep(1.0); |
| 274 | |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 275 | COORD.send(COORD_CMD_HANGUP) to vc_conn[0]; |
| 276 | |
| 277 | |
| 278 | vc_conn[0].done; |
| 279 | vc_conn[1].done; |
Pau Espin Pedrol | 01f1df8 | 2024-05-08 16:55:55 +0200 | [diff] [blame] | 280 | f_shutdown(); |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 281 | } |
| 282 | |
Pau Espin Pedrol | 32167d8 | 2024-04-10 13:14:51 +0200 | [diff] [blame] | 283 | /* One of the users calls (INVITE) shared extension, which makes all other user |
| 284 | * equipments ring (INVITE). The first one to pick up the call (OK 200) gets the |
| 285 | * call established (ACK), others get a CANCEL event. */ |
| 286 | private function TC_internal_call_all_Nregistered(integer num_conns := 2) runs on test_CT { |
Pau Espin Pedrol | caf028d | 2024-04-18 13:47:07 +0200 | [diff] [blame] | 287 | var SIPConnHdlrList vc_conn_list := {}; |
Pau Espin Pedrol | 32167d8 | 2024-04-10 13:14:51 +0200 | [diff] [blame] | 288 | const integer vc_conn_mo_idx := 0; /* Index of MO leg in vc_conn_list */ |
| 289 | const integer vc_conn_mt_idx := 1; /* Index of MT leg in vc_conn_list, peer picking up first the call */ |
| 290 | var SipAddr broadcast_sip_record; |
Pau Espin Pedrol | caf028d | 2024-04-18 13:47:07 +0200 | [diff] [blame] | 291 | var SIPConnHdlrPars pars_mo; |
Pau Espin Pedrol | 32167d8 | 2024-04-10 13:14:51 +0200 | [diff] [blame] | 292 | |
| 293 | f_init(); |
| 294 | |
| 295 | broadcast_sip_record := valueof(ts_SipAddr(ts_HostPort(mp_local_sip_host), |
| 296 | ts_UserInfo(broadcast_sip_extension))); |
| 297 | |
| 298 | for (var integer i := 0; i < num_conns; i := i + 1) { |
Pau Espin Pedrol | caf028d | 2024-04-18 13:47:07 +0200 | [diff] [blame] | 299 | var SIPConnHdlrPars pars; |
| 300 | var SIPConnHdlr vc_conn; |
Pau Espin Pedrol | 32167d8 | 2024-04-10 13:14:51 +0200 | [diff] [blame] | 301 | pars := f_init_ConnHdlrPars(idx := i + 1); |
| 302 | if (i == vc_conn_mo_idx) { /* MO */ |
| 303 | pars.cp.calling := pars.registrar_sip_record; |
| 304 | pars.cp.called := broadcast_sip_record; |
| 305 | vc_conn := f_start_handler(refers(f_TC_internal_call_mo), pars); |
| 306 | pars_mo := pars; |
| 307 | } else { /* MT */ |
| 308 | pars.cp.calling := pars_mo.registrar_sip_record; |
| 309 | pars.cp.called := pars.local_sip_record; |
| 310 | pars.cp.mt.wait_coord_cmd_pickup := true; |
| 311 | if (i != vc_conn_mt_idx) { |
| 312 | /* Only first MT picking up (OK 200 INVITE) will be ACKed, others CANCELed: */ |
| 313 | pars.cp.mt.exp_cancel := true; |
| 314 | } |
| 315 | vc_conn := f_start_handler(refers(f_TC_internal_call_mt), pars); |
| 316 | } |
| 317 | vc_conn_list := vc_conn_list & { vc_conn }; |
| 318 | } |
| 319 | |
| 320 | /* Wait all users are registered: */ |
| 321 | for (var integer i := 0; i < num_conns; i := i + 1) { |
| 322 | /* Note: "from vc_conn_list[i]" can't be used since they may arrive from components in any order: */ |
| 323 | COORD.receive(COORD_CMD_REGISTERED); |
| 324 | } |
| 325 | |
| 326 | /* Ask MO user to start the call: */ |
| 327 | COORD.send(COORD_CMD_START) to vc_conn_list[vc_conn_mo_idx]; |
| 328 | |
| 329 | /* Make sure the desired MT is the one picking up first the call: */ |
| 330 | COORD.send(COORD_CMD_PICKUP) to vc_conn_list[vc_conn_mt_idx]; |
| 331 | interleave { |
| 332 | [] COORD.receive(COORD_CMD_CALL_ESTABLISHED) from vc_conn_list[vc_conn_mo_idx]; |
| 333 | [] COORD.receive(COORD_CMD_CALL_ESTABLISHED) from vc_conn_list[vc_conn_mt_idx]; |
| 334 | } |
| 335 | |
| 336 | /* Pick up from other phone calls and expect CANCEL: */ |
| 337 | for (var integer i := 0; i < num_conns; i := i + 1) { |
| 338 | if (i != vc_conn_mo_idx and i != vc_conn_mt_idx) { |
| 339 | COORD.send(COORD_CMD_PICKUP) to vc_conn_list[i]; |
| 340 | COORD.receive(COORD_CMD_CALL_CANCELLED) from vc_conn_list[i]; |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | /* Call on-going */ |
| 345 | f_sleep(1.0); |
| 346 | |
| 347 | COORD.send(COORD_CMD_HANGUP) to vc_conn_list[vc_conn_mo_idx]; |
| 348 | |
| 349 | for (var integer i := 0; i < num_conns; i := i + 1) { |
| 350 | vc_conn_list[i].done; |
| 351 | } |
Pau Espin Pedrol | 01f1df8 | 2024-05-08 16:55:55 +0200 | [diff] [blame] | 352 | f_shutdown(); |
Pau Espin Pedrol | 32167d8 | 2024-04-10 13:14:51 +0200 | [diff] [blame] | 353 | } |
| 354 | testcase TC_internal_call_all_2registered() runs on test_CT { |
| 355 | TC_internal_call_all_Nregistered(2); |
| 356 | } |
| 357 | testcase TC_internal_call_all_3registered() runs on test_CT { |
| 358 | TC_internal_call_all_Nregistered(3); |
| 359 | } |
| 360 | testcase TC_internal_call_all_4registered() runs on test_CT { |
| 361 | TC_internal_call_all_Nregistered(4); |
| 362 | } |
| 363 | |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 364 | testcase TC_selftest() runs on test_CT { |
Pau Espin Pedrol | 01f1df8 | 2024-05-08 16:55:55 +0200 | [diff] [blame] | 365 | f_ami_selftest(); |
Pau Espin Pedrol | 05eaa1a | 2024-04-02 12:56:26 +0200 | [diff] [blame] | 366 | f_sip_digest_selftest(); |
| 367 | setverdict(pass); |
| 368 | } |
| 369 | |
Pau Espin Pedrol | 901cede | 2024-05-30 13:03:42 +0200 | [diff] [blame] | 370 | private function f_AMI_IMS_register(IMS_ConnHdlrPars pars) runs on test_CT |
| 371 | { |
| 372 | /* Give some time for IMS_ConnHdlr to register SIP expect. This could be done through IMS_COORD. */ |
| 373 | f_sleep(1.0); |
| 374 | /* Clear events: */ |
| 375 | AMI_CLIENT.clear; |
| 376 | |
| 377 | /* Announce network information, this should usually happen when UE |
| 378 | * becomes attached to network and before IMS APN is set up: */ |
| 379 | f_ami_action_PJSIPAccessNetworkInfo(AMI_CLIENT, mp_volte_ims_outbound_registration, |
| 380 | f_ami_gen_PJSIPAccessNetworkInfo_Info_EUTRAN(pars.subscr.uli_str)); |
| 381 | |
| 382 | /* Trigger registration: */ |
| 383 | f_ami_action_PJSIPRegister(AMI_CLIENT, mp_volte_ims_outbound_registration); |
| 384 | |
| 385 | var charstring rand_str := oct2str(pars.subscr.rand); |
| 386 | var charstring autn_str := oct2str(pars.subscr.autn); |
| 387 | AMI_CLIENT.receive(tr_AMI_Event_AuthRequest(mp_volte_ims_outbound_registration, |
| 388 | rand := pattern @nocase rand_str, |
| 389 | autn := pattern @nocase autn_str)); |
| 390 | |
| 391 | f_ami_action_AuthResponse_RES(AMI_CLIENT, |
| 392 | mp_volte_ims_outbound_registration, |
| 393 | c_auth_res, c_auth_ck, c_auth_ik); |
| 394 | |
| 395 | AMI_CLIENT.receive(tr_AMI_Event_Registry(f_sip_SipAddr_to_str(pars.subscr.local_sip_record), |
| 396 | "sip:" & mp_local_ims_host, |
| 397 | "Registered")); |
| 398 | |
| 399 | /* TODO: test "Action: PJSIPUnregister" */ |
| 400 | |
| 401 | /* TODO: in another test emulating a call, test "Action: DedicatedBearerStatus" */ |
| 402 | } |
| 403 | |
Pau Espin Pedrol | a2812ec | 2024-05-10 20:30:44 +0200 | [diff] [blame] | 404 | /* Test SIP registration of local clients */ |
| 405 | private function f_TC_ims_registration(charstring id) runs on IMS_ConnHdlr { |
Pau Espin Pedrol | 901cede | 2024-05-30 13:03:42 +0200 | [diff] [blame] | 406 | f_create_sip_expect(valueof(ts_SipUrl_from_Addr_Union(g_pars.subscr.registrar_sip_record.addr))); |
Pau Espin Pedrol | a2812ec | 2024-05-10 20:30:44 +0200 | [diff] [blame] | 407 | as_IMS_register(); |
| 408 | setverdict(pass); |
| 409 | } |
| 410 | testcase TC_ims_registration() runs on test_CT { |
| 411 | var IMS_ConnHdlrPars pars; |
| 412 | var IMS_ConnHdlr vc_conn; |
| 413 | f_init(); |
| 414 | pars := f_init_IMS_ConnHdlrPars(); |
| 415 | vc_conn := f_start_handler_IMS(refers(f_TC_ims_registration), pars); |
| 416 | |
Pau Espin Pedrol | 901cede | 2024-05-30 13:03:42 +0200 | [diff] [blame] | 417 | f_AMI_IMS_register(pars); |
Pau Espin Pedrol | a2812ec | 2024-05-10 20:30:44 +0200 | [diff] [blame] | 418 | |
| 419 | vc_conn.done; |
| 420 | f_shutdown(); |
| 421 | } |
| 422 | |
Pau Espin Pedrol | 901cede | 2024-05-30 13:03:42 +0200 | [diff] [blame] | 423 | /* Test SIP registration of local clients */ |
| 424 | private function f_TC_ims_call_mo(charstring id) runs on IMS_ConnHdlr { |
| 425 | f_create_sip_expect(valueof(ts_SipUrl_from_Addr_Union(g_pars.subscr.registrar_sip_record.addr))); |
| 426 | if (ispresent(g_pars.subscr.cp.called)) { |
| 427 | f_create_sip_expect(valueof(ts_SipUrl_from_Addr_Union(g_pars.subscr.cp.called.addr))); |
| 428 | } |
| 429 | as_IMS_register(); |
| 430 | setverdict(pass); |
| 431 | as_IMS_mo_call_accept(); |
| 432 | setverdict(pass); |
| 433 | COORD.send(COORD_CMD_CALL_ESTABLISHED); |
| 434 | as_IMS_exp_call_hangup(g_pars.subscr.cp.sip_seq_nr + 1); |
| 435 | setverdict(pass); |
| 436 | } |
| 437 | testcase TC_ims_call_mo() runs on test_CT { |
| 438 | var SIPConnHdlrPars sip_pars; |
| 439 | var IMS_ConnHdlrPars ims_pars; |
| 440 | var SIPConnHdlr vc_conn_sip; |
| 441 | var IMS_ConnHdlr vc_conn_ims; |
| 442 | const charstring c_ext_msisdn := "90829"; |
| 443 | |
| 444 | f_init(); |
| 445 | |
| 446 | sip_pars := f_init_ConnHdlrPars(idx := 1); |
| 447 | ims_pars := f_init_IMS_ConnHdlrPars(); |
| 448 | |
| 449 | sip_pars.cp.calling := sip_pars.registrar_sip_record; |
| 450 | sip_pars.cp.called := valueof(ts_SipAddr(ts_HostPort(sip_pars.remote_sip_host), |
| 451 | ts_UserInfo(c_ext_msisdn))); |
| 452 | ims_pars.subscr.cp.calling := valueof(ts_SipAddr(ts_HostPort(ims_pars.local_sip_host), |
| 453 | ts_UserInfo(ims_pars.subscr.msisdn))); |
| 454 | ims_pars.subscr.cp.called := valueof(ts_SipAddr(ts_HostPort(ims_pars.local_sip_host), |
| 455 | ts_UserInfo(c_ext_msisdn))); |
| 456 | |
| 457 | vc_conn_ims := f_start_handler_IMS(refers(f_TC_ims_call_mo), ims_pars); |
| 458 | vc_conn_sip := f_start_handler(refers(f_TC_internal_call_mo), sip_pars); |
| 459 | |
| 460 | COORD.receive(COORD_CMD_REGISTERED) from vc_conn_sip; |
| 461 | |
| 462 | f_AMI_IMS_register(ims_pars); |
| 463 | |
| 464 | COORD.send(COORD_CMD_START) to vc_conn_sip; |
| 465 | COORD.receive(COORD_CMD_CALL_ESTABLISHED) from vc_conn_sip; |
| 466 | IMS_COORD.receive(COORD_CMD_CALL_ESTABLISHED) from vc_conn_ims; |
| 467 | |
| 468 | /* Call on-going */ |
| 469 | f_sleep(1.0); |
| 470 | |
| 471 | COORD.send(COORD_CMD_HANGUP) to vc_conn_sip; |
| 472 | |
| 473 | vc_conn_sip.done; |
| 474 | vc_conn_ims.done; |
| 475 | f_shutdown(); |
| 476 | } |
| 477 | |
Pau Espin Pedrol | 37ee0ed | 2024-03-28 21:17:12 +0100 | [diff] [blame] | 478 | control { |
| 479 | execute( TC_internal_registration() ); |
Pau Espin Pedrol | 7011bf4 | 2024-04-08 17:56:58 +0200 | [diff] [blame] | 480 | execute( TC_internal_call_momt() ); |
Pau Espin Pedrol | 32167d8 | 2024-04-10 13:14:51 +0200 | [diff] [blame] | 481 | execute( TC_internal_call_all_2registered() ); |
| 482 | execute( TC_internal_call_all_3registered() ); |
| 483 | execute( TC_internal_call_all_4registered() ); |
Pau Espin Pedrol | a2812ec | 2024-05-10 20:30:44 +0200 | [diff] [blame] | 484 | execute( TC_ims_registration() ); |
Pau Espin Pedrol | 901cede | 2024-05-30 13:03:42 +0200 | [diff] [blame] | 485 | execute( TC_ims_call_mo() ); |
Pau Espin Pedrol | 37ee0ed | 2024-03-28 21:17:12 +0100 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | } |