Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 1 | module SIP_Tests { |
| 2 | |
Harald Welte | 34b5a95 | 2019-05-27 11:54:11 +0200 | [diff] [blame] | 3 | /* osmo-sip-connector test suite in TTCN-3 |
| 4 | * (C) 2018-2019 Harald Welte <laforge@gnumonks.org> |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Released under the terms of GNU General Public License, Version 2 or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 11 | */ |
| 12 | |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 13 | import from General_Types all; |
| 14 | import from Osmocom_Types all; |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 15 | import from Native_Functions all; |
| 16 | import from Misc_Helpers all; |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 17 | |
| 18 | import from Osmocom_CTRL_Functions all; |
| 19 | import from Osmocom_CTRL_Types all; |
| 20 | import from Osmocom_CTRL_Adapter all; |
| 21 | |
| 22 | import from TELNETasp_PortType all; |
| 23 | import from Osmocom_VTY_Functions all; |
| 24 | |
| 25 | import from MNCC_Emulation all; |
| 26 | import from MNCC_Types all; |
| 27 | |
| 28 | import from SDP_Types all; |
| 29 | |
| 30 | import from SIP_Emulation all; |
| 31 | import from SIPmsg_Types all; |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 32 | import from SIP_Templates all; |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 33 | |
| 34 | modulepar { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 35 | charstring mp_local_host := "127.0.0.2"; |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 36 | charstring mp_osmosip_host := "127.0.0.1"; |
| 37 | integer mp_osmosip_port_ctrl := -1; /* RFU */ |
| 38 | charstring mp_mncc := "/tmp/mncc"; |
| 39 | } |
| 40 | |
| 41 | type component test_CT extends CTRL_Adapter_CT { |
| 42 | var MNCC_Emulation_CT vc_MNCC; |
| 43 | var SIP_Emulation_CT vc_SIP; |
| 44 | |
| 45 | port TELNETasp_PT SIPVTY; |
| 46 | } |
| 47 | |
| 48 | type component ConnHdlr extends SIP_ConnHdlr, MNCC_ConnHdlr { |
| 49 | var ConnHdlrPars g_pars; |
| 50 | timer g_Tguard; |
| 51 | } |
| 52 | |
| 53 | type record ConnHdlrPars { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 54 | float t_guard, |
| 55 | CallPars g_cp optional |
| 56 | } |
| 57 | |
| 58 | type record CallPars { |
| 59 | boolean is_mo, |
| 60 | charstring calling, |
| 61 | charstring called, |
| 62 | |
| 63 | uint32_t mncc_call_id optional, |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 64 | CallParsComputed comp optional, |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 65 | |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 66 | charstring sip_rtp_addr, |
| 67 | uint16_t sip_rtp_port, |
| 68 | charstring cn_rtp_addr, |
| 69 | uint16_t cn_rtp_port |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | type record CallParsComputed { |
| 73 | CallidString sip_call_id, |
| 74 | SipAddr sip_url_ext, |
| 75 | SipAddr sip_url_gsm, |
| 76 | charstring sip_body, |
| 77 | integer sip_seq_nr |
| 78 | } |
| 79 | |
| 80 | private template (value) CallPars t_CallPars(boolean is_mo) := { |
| 81 | is_mo := is_mo, |
| 82 | calling := "12345", |
| 83 | called := "98766", |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 84 | |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 85 | mncc_call_id := omit, |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 86 | comp := omit, |
| 87 | sip_rtp_addr := "1.2.3.4", |
| 88 | sip_rtp_port := 1234, |
| 89 | cn_rtp_addr := "5.6.7.8", |
| 90 | cn_rtp_port := 5678 |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | private function f_CallPars_compute(inout CallPars cp) { |
| 94 | if (cp.is_mo) { |
| 95 | cp.comp.sip_url_ext := valueof(ts_SipAddr(cp.called, mp_local_host, 5060)); |
| 96 | cp.comp.sip_url_gsm := valueof(ts_SipAddr(cp.calling, mp_osmosip_host, 5060)); |
| 97 | cp.mncc_call_id := f_rnd_int(429496725); |
| 98 | } else { |
| 99 | cp.comp.sip_url_ext := valueof(ts_SipAddr(cp.calling, mp_local_host, 5060)); |
| 100 | cp.comp.sip_url_gsm := valueof(ts_SipAddr(cp.called, mp_osmosip_host, 5060)); |
| 101 | cp.comp.sip_call_id := hex2str(f_rnd_hexstring(15)); |
| 102 | } |
| 103 | cp.comp.sip_seq_nr := f_rnd_int(4294967295); |
| 104 | cp.comp.sip_body := ""; |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 105 | } |
| 106 | |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 107 | private function f_mgcp_addr2addrtype(charstring addr) return charstring { |
| 108 | for (var integer i := 0; i < lengthof(addr); i := i + 1) { |
| 109 | if (addr[i] == ":") { |
| 110 | return "IP6"; |
| 111 | } |
| 112 | } |
| 113 | return "IP4"; |
| 114 | } |
| 115 | |
| 116 | private function f_addrstr2addr(charstring addr) return octetstring { |
| 117 | if (f_addr_is_ipv6(addr)) { |
| 118 | return f_inet6_addr(addr); |
| 119 | } else { |
| 120 | return f_inet_addr(addr); |
| 121 | } |
| 122 | } |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 123 | |
| 124 | function f_init_mncc(charstring id) runs on test_CT { |
| 125 | id := id & "-MNCC"; |
| 126 | var MnccOps ops := { |
| 127 | create_cb := refers(MNCC_Emulation.ExpectedCreateCallback), |
| 128 | unitdata_cb := refers(MNCC_Emulation.DummyUnitdataCallback) |
| 129 | }; |
| 130 | |
| 131 | vc_MNCC := MNCC_Emulation_CT.create(id); |
| 132 | map(vc_MNCC:MNCC, system:MNCC_CODEC_PT); |
| 133 | vc_MNCC.start(MNCC_Emulation.main(ops, id, mp_mncc, true)); |
| 134 | } |
| 135 | |
| 136 | function f_init() runs on test_CT { |
Pau Espin Pedrol | 9a5b8ff | 2021-01-04 19:01:31 +0100 | [diff] [blame] | 137 | //f_ipa_ctrl_start_client(mp_osmosip_host, mp_osmosip_port_ctrl); |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 138 | f_init_mncc("SIP_Test"); |
| 139 | log("end of f_init_mncc"); |
| 140 | f_init_sip(vc_SIP, "SIP_Test"); |
| 141 | log("end of f_init_sip"); |
| 142 | |
| 143 | map(self:SIPVTY, system:SIPVTY); |
| 144 | f_vty_set_prompts(SIPVTY); |
| 145 | f_vty_transceive(SIPVTY, "enable"); |
| 146 | log("end of f_init"); |
| 147 | } |
| 148 | |
| 149 | type function void_fn(charstring id) runs on ConnHdlr; |
| 150 | |
| 151 | function f_start_handler(void_fn fn, ConnHdlrPars pars) |
| 152 | runs on test_CT return ConnHdlr { |
| 153 | var ConnHdlr vc_conn; |
| 154 | var charstring id := testcasename(); |
| 155 | |
| 156 | vc_conn := ConnHdlr.create(id); |
| 157 | |
| 158 | connect(vc_conn:SIP, vc_SIP:CLIENT); |
| 159 | connect(vc_conn:SIP_PROC, vc_SIP:CLIENT_PROC); |
| 160 | |
| 161 | connect(vc_conn:MNCC, vc_MNCC:MNCC_CLIENT); |
| 162 | connect(vc_conn:MNCC_PROC, vc_MNCC:MNCC_PROC); |
| 163 | |
| 164 | vc_conn.start(f_handler_init(fn, id, pars)); |
| 165 | return vc_conn; |
| 166 | } |
| 167 | |
| 168 | private altstep as_Tguard() runs on ConnHdlr { |
| 169 | [] g_Tguard.timeout { |
| 170 | setverdict(fail, "Tguard timeout"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 171 | mtc.stop; |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 172 | } |
| 173 | } |
| 174 | |
| 175 | private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars) |
| 176 | runs on ConnHdlr { |
| 177 | g_pars := pars; |
| 178 | g_Tguard.start(pars.t_guard); |
| 179 | activate(as_Tguard()); |
| 180 | |
| 181 | /* call the user-supied test case function */ |
| 182 | fn.apply(id); |
| 183 | } |
| 184 | |
| 185 | |
| 186 | template (value) ConnHdlrPars t_Pars := { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 187 | t_guard := 30.0, |
| 188 | g_cp := omit |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 189 | } |
| 190 | |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 191 | /* Establish a mobile terminated call described in 'cp' */ |
| 192 | function f_establish_mt(inout CallPars cp) runs on ConnHdlr { |
| 193 | var template SipAddr sip_addr_gsm := tr_SipAddr_from_val(cp.comp.sip_url_gsm); |
| 194 | var template SipAddr sip_addr_ext := tr_SipAddr_from_val(cp.comp.sip_url_ext); |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 195 | var PDU_SIP_Request sip_req; |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 196 | var PDU_SIP_Response sip_resp; |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 197 | var MNCC_PDU mncc; |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 198 | |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 199 | /* Ask MNCC_Emulation to "expect" a call to the given called number */ |
| 200 | f_create_mncc_expect(cp.called); |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 201 | |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 202 | /* OSC <- SIP: A party sends SIP invite for a MT-call into OSC */ |
| 203 | SIP.send(ts_SIP_INVITE(cp.comp.sip_call_id, cp.comp.sip_url_ext, cp.comp.sip_url_gsm, |
| 204 | cp.comp.sip_seq_nr, cp.comp.sip_body)); |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 205 | /* OSC -> SIP */ |
| 206 | SIP.receive(tr_SIP_Response(cp.comp.sip_call_id, sip_addr_ext, sip_addr_gsm, *, |
| 207 | "INVITE", 100, ?, "Trying", *)); |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 208 | |
Pau Espin Pedrol | 37cf408 | 2020-09-23 16:59:16 +0200 | [diff] [blame] | 209 | alt { |
| 210 | /* MSC <- OSC: OSC generates MNCC_SETUP_REQ from INVITE */ |
| 211 | [] MNCC.receive(tr_MNCC_SETUP_req) -> value mncc { |
| 212 | cp.mncc_call_id := mncc.u.signal.callref; |
| 213 | } |
| 214 | [] SIP.receive { |
Neels Hofmeyr | baf0272 | 2023-09-12 02:10:11 +0200 | [diff] [blame^] | 215 | setverdict(fail, "Received unexpected SIP response"); |
Pau Espin Pedrol | 37cf408 | 2020-09-23 16:59:16 +0200 | [diff] [blame] | 216 | SIP.send(ts_SIP_ACK(cp.comp.sip_call_id, cp.comp.sip_url_ext, cp.comp.sip_url_gsm, |
| 217 | cp.comp.sip_seq_nr, omit)); |
| 218 | mtc.stop; |
| 219 | } |
| 220 | } |
| 221 | |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 222 | /* MSC -> OSC: After MS sends CALL CONF in response to SETUP */ |
| 223 | MNCC.send(ts_MNCC_CALL_CONF_ind(cp.mncc_call_id)); |
| 224 | /* MSC <- OSC: OSC asks MSC to create RTP socket */ |
| 225 | MNCC.receive(tr_MNCC_RTP_CREATE(cp.mncc_call_id)); |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 226 | mncc := valueof(ts_MNCC_RTP_CREATE(cp.mncc_call_id)); |
| 227 | mncc.u.rtp.is_ipv6 := f_addr_is_ipv6(cp.cn_rtp_addr); |
| 228 | mncc.u.rtp.ip := f_addrstr2addr(cp.cn_rtp_addr); |
| 229 | mncc.u.rtp.rtp_port := cp.cn_rtp_port; |
| 230 | MNCC.send(mncc); |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 231 | |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 232 | /* MSC -> OSC: After MS is ringing and sent CC ALERTING */ |
| 233 | MNCC.send(ts_MNCC_ALERT_ind(cp.mncc_call_id)); |
| 234 | SIP.clear; |
Pau Espin Pedrol | 37cf408 | 2020-09-23 16:59:16 +0200 | [diff] [blame] | 235 | alt { |
| 236 | [] SIP.receive(tr_SIP_Response(cp.comp.sip_call_id, sip_addr_ext, sip_addr_gsm, *, |
| 237 | "INVITE", 180, ?, "Ringing", *)); |
| 238 | [] SIP.receive { |
| 239 | setverdict(fail, "Received unexpected respose"); |
| 240 | SIP.send(ts_SIP_ACK(cp.comp.sip_call_id, cp.comp.sip_url_ext, cp.comp.sip_url_gsm, |
| 241 | cp.comp.sip_seq_nr, omit)); |
| 242 | mtc.stop; |
| 243 | } |
| 244 | } |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 245 | |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 246 | /* MSC -> OSC: After MT user has picked up and sent CC CONNECT */ |
| 247 | MNCC.send(ts_MNCC_SETUP_CNF(cp.mncc_call_id)); |
| 248 | |
| 249 | SIP.clear; |
| 250 | interleave { |
| 251 | /* MSC <- OSC: OSC asks MSC to connect its RTP stream to remote end */ |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 252 | [] MNCC.receive(tr_MNCC_RTP_CONNECT(cp.mncc_call_id, f_addrstr2addr(cp.sip_rtp_addr), cp.sip_rtp_port)) {} |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 253 | /* OSC -> SIP: OSC confirms call establishment to SIP side */ |
| 254 | [] SIP.receive(tr_SIP_Response(cp.comp.sip_call_id, sip_addr_ext, sip_addr_gsm, ?, |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 255 | "INVITE", 200, ?, "OK", ?)) -> value sip_resp { |
| 256 | if (not match(sip_resp.messageBody, pattern "*" & cp.cn_rtp_addr & "*")) { |
| 257 | setverdict(fail, "wrong ip addr sent in SIP SDP, not containing ", cp.cn_rtp_addr); |
| 258 | mtc.stop; |
| 259 | } |
| 260 | } |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 261 | } |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 262 | /* OSC <- SIP: SIP world acknowledges "200 OK" */ |
| 263 | SIP.send(ts_SIP_ACK(cp.comp.sip_call_id, cp.comp.sip_url_ext, cp.comp.sip_url_gsm, |
| 264 | cp.comp.sip_seq_nr, omit)); |
| 265 | /* MSC <- OSC: OSC sends SETUP COMPL to MNCC (which triggers CC CONNECT ACK */ |
| 266 | MNCC.receive(tr_MNCC_SETUP_COMPL_req(cp.mncc_call_id)); |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 267 | } |
| 268 | |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 269 | /* Establish a mobile originated call described in 'cp' */ |
| 270 | function f_establish_mo(inout CallPars cp) runs on ConnHdlr { |
| 271 | var MNCC_number dst := valueof(ts_MNCC_number(cp.called, GSM48_TON_UNKNOWN)); |
| 272 | var MNCC_number src := valueof(ts_MNCC_number(cp.calling, GSM48_TON_UNKNOWN)); |
| 273 | var template SipAddr sip_addr_gsm := tr_SipAddr_from_val(cp.comp.sip_url_gsm); |
| 274 | var template SipAddr sip_addr_ext := tr_SipAddr_from_val(cp.comp.sip_url_ext); |
| 275 | var PDU_SIP_Request sip_req; |
| 276 | var integer seq_nr; |
| 277 | |
| 278 | f_create_sip_expect(cp.comp.sip_url_ext.addr.nameAddr.addrSpec); |
| 279 | |
| 280 | /* MSC -> OSC: MSC sends SETUP.ind after CC SETUP was received from MS */ |
| 281 | MNCC.send(ts_MNCC_SETUP_ind(cp.mncc_call_id, dst, src, "262420123456789")); |
| 282 | /* MSC <- OSC: Create GSM side RTP socket */ |
| 283 | MNCC.receive(tr_MNCC_RTP_CREATE(cp.mncc_call_id)) { |
| 284 | var MNCC_PDU mncc := valueof(ts_MNCC_RTP_CREATE(cp.mncc_call_id)); |
| 285 | mncc.u.rtp.payload_msg_type := oct2int('0300'O); |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 286 | mncc.u.rtp.is_ipv6 := f_addr_is_ipv6(cp.cn_rtp_addr); |
| 287 | mncc.u.rtp.ip := f_addrstr2addr(cp.cn_rtp_addr); |
| 288 | mncc.u.rtp.rtp_port := cp.cn_rtp_port; |
| 289 | MNCC.send(mncc); |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 290 | } |
| 291 | /* OSC -> SIP: Send INVITE with GSM side IP/Port in SDP */ |
| 292 | SIP.receive(tr_SIP_INVITE(?, sip_addr_gsm, sip_addr_ext, ?, ?)) -> value sip_req { |
| 293 | cp.comp.sip_url_gsm.params := sip_req.msgHeader.fromField.fromParams; |
| 294 | cp.comp.sip_call_id := sip_req.msgHeader.callId.callid; |
| 295 | seq_nr := sip_req.msgHeader.cSeq.seqNumber; |
| 296 | } |
| 297 | /* OSC <- SIP: Notify call is proceeding */ |
| 298 | SIP.send(ts_SIP_Response(cp.comp.sip_call_id, cp.comp.sip_url_gsm, cp.comp.sip_url_ext, |
| 299 | "INVITE", 100, seq_nr, "Trying", sip_req.msgHeader.via)); |
| 300 | /* MSC <- OSC: "100 Trying" translated to MNCC_CALL_PROC_REQ */ |
| 301 | MNCC.receive(tr_MNCC_CALL_PROC_req(cp.mncc_call_id)); |
| 302 | |
| 303 | /* OSC <- SIP: SIP-terminated user is ringing now */ |
| 304 | SIP.send(ts_SIP_Response(cp.comp.sip_call_id, cp.comp.sip_url_gsm, cp.comp.sip_url_ext, |
| 305 | "INVITE", 180, seq_nr, "Ringing", sip_req.msgHeader.via)); |
| 306 | |
| 307 | /* MSC <- OSC: "180 Ringing" translated to MNCC_ALERT_REQ */ |
| 308 | MNCC.receive(tr_MNCC_ALERT_req(cp.mncc_call_id)) {} |
| 309 | |
| 310 | /* OSC <- SIP: SIP-terminated user has accepted the call */ |
| 311 | SIP.send(ts_SIP_Response(cp.comp.sip_call_id, cp.comp.sip_url_gsm, cp.comp.sip_url_ext, |
| 312 | "INVITE", 200, seq_nr, "OK", sip_req.msgHeader.via, |
| 313 | cp.comp.sip_body)); |
| 314 | MNCC.receive(tr_MNCC_RTP_CONNECT(cp.mncc_call_id)); |
| 315 | /* MSC <- OSC: "200 OK" translated to MNCC_SETUP_RSP */ |
| 316 | MNCC.receive(tr_MNCC_SETUP_rsp(cp.mncc_call_id)); |
| 317 | |
| 318 | /* MSC -> OSC: CC CONNECT ACK was received from MS */ |
| 319 | MNCC.send(ts_MNCC_SETUP_COMPL_ind(cp.mncc_call_id)); |
| 320 | /* OSC -> SIP: Acknowledge the call */ |
| 321 | SIP.receive(tr_SIP_ACK(cp.comp.sip_call_id, sip_addr_gsm, sip_addr_ext, ?, omit)); |
| 322 | } |
| 323 | |
| 324 | /* Release call from the mobile side */ |
| 325 | function f_release_mobile(inout CallPars cp) runs on ConnHdlr { |
| 326 | var template SipAddr sip_addr_gsm := tr_SipAddr_from_val(cp.comp.sip_url_gsm); |
| 327 | var template SipAddr sip_addr_ext := tr_SipAddr_from_val(cp.comp.sip_url_ext); |
| 328 | var PDU_SIP_Request sip_req; |
| 329 | SIP.clear; |
| 330 | /* MSC -> OSC: Simulate a CC DISCONNET from the MT user */ |
| 331 | MNCC.send(ts_MNCC_DISC_ind(cp.mncc_call_id, ts_MNCC_cause(0))); |
| 332 | /* OSC -> SIP: Expect BYE from OSC to SIP side */ |
| 333 | SIP.receive(tr_SIP_BYE(cp.comp.sip_call_id, sip_addr_gsm, sip_addr_ext, ?, *)) -> value sip_req { |
| 334 | cp.comp.sip_url_gsm.params := sip_req.msgHeader.fromField.fromParams; |
| 335 | } |
| 336 | /* OSC <- SIP: Acknowledge the BYE */ |
| 337 | SIP.send(ts_SIP_Response(cp.comp.sip_call_id, cp.comp.sip_url_gsm, cp.comp.sip_url_ext, |
| 338 | "BYE", 200, sip_req.msgHeader.cSeq.seqNumber, "OK", |
| 339 | sip_req.msgHeader.via)); |
| 340 | /* MSC <- OSC: Send REL_REQ to MSC, triggers CC RELEASE REQ to MS */ |
| 341 | MNCC.receive(tr_MNCC_REL_req(cp.mncc_call_id)); // CAUSE? |
| 342 | /* MSC -> OSC: MS has responded with CC CLEAR COMPL, triggers MNCC_REL_CNF */ |
| 343 | MNCC.send(ts_MNCC_REL_cnf(cp.mncc_call_id, ts_MNCC_cause(0))); |
| 344 | } |
| 345 | |
| 346 | /* Release call from the SIP side */ |
| 347 | function f_release_sip(inout CallPars cp) runs on ConnHdlr { |
| 348 | var template SipAddr sip_addr_gsm := tr_SipAddr_from_val(cp.comp.sip_url_gsm); |
| 349 | var template SipAddr sip_addr_ext := tr_SipAddr_from_val(cp.comp.sip_url_ext); |
| 350 | /* OSC <- SIP: SIP-side sends a BYE to OSC */ |
| 351 | SIP.send(ts_SIP_BYE(cp.comp.sip_call_id, cp.comp.sip_url_ext, cp.comp.sip_url_gsm, |
| 352 | cp.comp.sip_seq_nr, omit)); |
| 353 | /* MSC <- OSC: Expect OSC to cause MNCC Disconnect Request */ |
| 354 | MNCC.receive(tr_MNCC_DISC_req(cp.mncc_call_id)); |
| 355 | /* MSC -> OSC: Indicate GSM side release */ |
| 356 | MNCC.send(ts_MNCC_REL_ind(cp.mncc_call_id, ts_MNCC_cause(0))); |
| 357 | /* OSC -> SIP: Confirmation to SIP side */ |
| 358 | SIP.receive(tr_SIP_Response(cp.comp.sip_call_id, sip_addr_ext, sip_addr_gsm, *, |
| 359 | "BYE", 200, cp.comp.sip_seq_nr, "OK", omit)); |
| 360 | } |
| 361 | |
| 362 | /* Successful MT Call, which is subsequently released by GSM side */ |
| 363 | private function f_TC_mt_success_rel_gsm(charstring id) runs on ConnHdlr { |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 364 | var CallPars cp := g_pars.g_cp; |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 365 | f_CallPars_compute(cp); |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 366 | cp.comp.sip_body := "v=0\r\no=Osmocom 0 0 IN IP4 1.1.1.1\r\ns=GSM Call\r\nc=IN " & |
| 367 | f_mgcp_addr2addrtype(cp.sip_rtp_addr) & " " & cp.sip_rtp_addr & |
| 368 | "\r\nt=0 0\r\nm=audio " & int2str(cp.sip_rtp_port) & |
| 369 | " RTP/AVP 0\r\na=rtpmap:0 GSM/8000\r\n"; |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 370 | f_sleep(3.0) |
| 371 | |
| 372 | f_establish_mt(cp); |
| 373 | /* now call is fully established */ |
| 374 | f_sleep(2.0); |
| 375 | f_release_mobile(cp); |
| 376 | setverdict(pass); |
| 377 | } |
| 378 | testcase TC_mt_success_rel_gsm() runs on test_CT { |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 379 | var ConnHdlrPars pars; |
| 380 | var ConnHdlr vc_conn; |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 381 | f_init(); |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 382 | pars := valueof(t_Pars); |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 383 | pars.g_cp := valueof(t_CallPars(false)); |
| 384 | vc_conn := f_start_handler(refers(f_TC_mt_success_rel_gsm), pars); |
| 385 | vc_conn.done; |
| 386 | } |
| 387 | testcase TC_mt_success_rel_gsm_ipv6() runs on test_CT { |
| 388 | var ConnHdlrPars pars; |
| 389 | var ConnHdlr vc_conn; |
| 390 | f_init(); |
| 391 | pars := valueof(t_Pars); |
| 392 | pars.g_cp := valueof(t_CallPars(false)); |
| 393 | pars.g_cp.sip_rtp_addr := "::1"; |
| 394 | pars.g_cp.cn_rtp_addr := "::2"; |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 395 | vc_conn := f_start_handler(refers(f_TC_mt_success_rel_gsm), pars); |
| 396 | vc_conn.done; |
| 397 | } |
| 398 | |
| 399 | /* Successful MT Call, which is subsequently released by SIP side */ |
| 400 | private function f_TC_mt_success_rel_sip(charstring id) runs on ConnHdlr { |
| 401 | var CallPars cp := valueof(t_CallPars(false)); |
| 402 | f_CallPars_compute(cp); |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 403 | cp.comp.sip_body := "v=0\r\no=Osmocom 0 0 IN IP4 1.1.1.1\r\ns=GSM Call\r\nc=IN " & |
| 404 | f_mgcp_addr2addrtype(cp.sip_rtp_addr) & " " & cp.sip_rtp_addr & |
| 405 | "\r\nt=0 0\r\nm=audio " & int2str(cp.sip_rtp_port) & |
| 406 | " RTP/AVP 0\r\na=rtpmap:0 GSM/8000\r\n"; |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 407 | f_sleep(3.0) |
| 408 | |
| 409 | f_establish_mt(cp); |
| 410 | /* now call is fully established */ |
| 411 | f_sleep(2.0); |
| 412 | f_release_sip(cp); |
| 413 | setverdict(pass); |
| 414 | } |
| 415 | testcase TC_mt_success_rel_sip() runs on test_CT { |
| 416 | var ConnHdlrPars pars; |
| 417 | var ConnHdlr vc_conn; |
| 418 | f_init(); |
| 419 | pars := valueof(t_Pars); |
| 420 | vc_conn := f_start_handler(refers(f_TC_mt_success_rel_sip), pars); |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 421 | vc_conn.done; |
| 422 | } |
| 423 | |
| 424 | |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 425 | /* Successful MO Call, which is subsequently released by GSM side */ |
| 426 | private function f_TC_mo_success_rel_gsm(charstring id) runs on ConnHdlr { |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 427 | var CallPars cp := g_pars.g_cp; |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 428 | f_CallPars_compute(cp); |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 429 | cp.comp.sip_body := "v=0\r\no=Osmocom 0 0 IN IP4 1.1.1.1\r\ns=GSM Call\r\nc=IN " & |
| 430 | f_mgcp_addr2addrtype(cp.sip_rtp_addr) & " " & cp.sip_rtp_addr & |
| 431 | "\r\nt=0 0\r\nm=audio " & int2str(cp.sip_rtp_port) & |
| 432 | " RTP/AVP 0\r\na=rtpmap:0 GSM/8000\r\n"; |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 433 | f_sleep(3.0) |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 434 | |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 435 | f_establish_mo(cp); |
| 436 | /* now call is fully established */ |
| 437 | f_sleep(2.0); |
| 438 | f_release_mobile(cp); |
| 439 | setverdict(pass); |
| 440 | } |
| 441 | testcase TC_mo_success_rel_gsm() runs on test_CT { |
| 442 | var ConnHdlrPars pars; |
| 443 | var ConnHdlr vc_conn; |
| 444 | f_init(); |
| 445 | pars := valueof(t_Pars); |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 446 | pars.g_cp := valueof(t_CallPars(true)); |
| 447 | vc_conn := f_start_handler(refers(f_TC_mo_success_rel_gsm), pars); |
| 448 | vc_conn.done; |
| 449 | } |
| 450 | testcase TC_mo_success_rel_gsm_ipv6() runs on test_CT { |
| 451 | var ConnHdlrPars pars; |
| 452 | var ConnHdlr vc_conn; |
| 453 | f_init(); |
| 454 | pars := valueof(t_Pars); |
| 455 | pars.g_cp := valueof(t_CallPars(true)); |
| 456 | pars.g_cp.sip_rtp_addr := "::1"; |
| 457 | pars.g_cp.cn_rtp_addr := "::2"; |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 458 | vc_conn := f_start_handler(refers(f_TC_mo_success_rel_gsm), pars); |
| 459 | vc_conn.done; |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 460 | } |
| 461 | |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 462 | /* Successful MO Call, which is subsequently released by SIP side */ |
| 463 | private function f_TC_mo_success_rel_sip(charstring id) runs on ConnHdlr { |
| 464 | var CallPars cp := valueof(t_CallPars(true)); |
| 465 | f_CallPars_compute(cp); |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 466 | cp.comp.sip_body := "v=0\r\no=Osmocom 0 0 IN IP4 1.1.1.1\r\ns=GSM Call\r\nc=IN " & |
| 467 | f_mgcp_addr2addrtype(cp.sip_rtp_addr) & " " & cp.sip_rtp_addr & |
| 468 | "\r\nt=0 0\r\nm=audio " & int2str(cp.sip_rtp_port) & |
| 469 | " RTP/AVP 0\r\na=rtpmap:0 GSM/8000\r\n"; |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 470 | f_sleep(3.0) |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 471 | |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 472 | f_establish_mo(cp); |
| 473 | /* now call is fully established */ |
| 474 | f_sleep(2.0); |
| 475 | f_release_sip(cp); |
| 476 | setverdict(pass); |
| 477 | } |
| 478 | testcase TC_mo_success_rel_sip() runs on test_CT { |
| 479 | var ConnHdlrPars pars; |
| 480 | var ConnHdlr vc_conn; |
| 481 | f_init(); |
| 482 | pars := valueof(t_Pars); |
| 483 | vc_conn := f_start_handler(refers(f_TC_mo_success_rel_sip), pars); |
| 484 | vc_conn.done; |
| 485 | } |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 486 | |
Harald Welte | ddf011e | 2019-04-19 09:39:35 +0200 | [diff] [blame] | 487 | /* SETUP followed by DISC results in lingering B-leg (OS#3518)*/ |
| 488 | private function f_TC_mo_setup_disc_late_rtp(charstring id) runs on ConnHdlr { |
| 489 | var CallPars cp := valueof(t_CallPars(true)); |
| 490 | f_CallPars_compute(cp); |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 491 | cp.comp.sip_body := "v=0\r\no=Osmocom 0 0 IN IP4 1.1.1.1\r\ns=GSM Call\r\nc=IN " & |
| 492 | f_mgcp_addr2addrtype(cp.sip_rtp_addr) & " " & cp.sip_rtp_addr & |
| 493 | "\r\nt=0 0\r\nm=audio " & int2str(cp.sip_rtp_port) & |
| 494 | " RTP/AVP 0\r\na=rtpmap:0 GSM/8000\r\n"; |
Harald Welte | ddf011e | 2019-04-19 09:39:35 +0200 | [diff] [blame] | 495 | f_sleep(3.0); |
| 496 | |
| 497 | var MNCC_number dst := valueof(ts_MNCC_number(cp.called, GSM48_TON_UNKNOWN)); |
| 498 | var MNCC_number src := valueof(ts_MNCC_number(cp.calling, GSM48_TON_UNKNOWN)); |
| 499 | var template SipAddr sip_addr_gsm := tr_SipAddr_from_val(cp.comp.sip_url_gsm); |
| 500 | var template SipAddr sip_addr_ext := tr_SipAddr_from_val(cp.comp.sip_url_ext); |
| 501 | |
| 502 | f_create_sip_expect(cp.comp.sip_url_ext.addr.nameAddr.addrSpec); |
| 503 | |
| 504 | /* MSC -> OSC: MSC sends SETUP.ind after CC SETUP was received from MS */ |
| 505 | MNCC.send(ts_MNCC_SETUP_ind(cp.mncc_call_id, dst, src, "262420123456789")); |
| 506 | |
| 507 | /* MSC -> OSC: Simulate a CC DISCONNET from the MT user *before* responding to the RTP_CREATE */ |
| 508 | MNCC.send(ts_MNCC_DISC_ind(cp.mncc_call_id, ts_MNCC_cause(0))); |
| 509 | |
| 510 | /* MSC <- OSC: Create GSM side RTP socket (too late) */ |
| 511 | MNCC.receive(tr_MNCC_RTP_CREATE(cp.mncc_call_id)) { |
| 512 | var MNCC_PDU mncc := valueof(ts_MNCC_RTP_CREATE(cp.mncc_call_id)); |
| 513 | mncc.u.rtp.payload_msg_type := oct2int('0300'O); |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 514 | mncc.u.rtp.is_ipv6 := f_addr_is_ipv6(cp.cn_rtp_addr); |
| 515 | mncc.u.rtp.ip := f_addrstr2addr(cp.cn_rtp_addr); |
| 516 | mncc.u.rtp.rtp_port := cp.cn_rtp_port; |
| 517 | MNCC.send(mncc); |
Harald Welte | ddf011e | 2019-04-19 09:39:35 +0200 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | /* OSC -> SIP: We should never receive INVITE */ |
| 521 | timer T := 10.0; |
| 522 | T.start; |
| 523 | alt { |
| 524 | [] SIP.receive(tr_SIP_INVITE(?, sip_addr_gsm, sip_addr_ext, ?, ?)) { |
| 525 | setverdict(fail, "Received unexpected INVITE"); |
| 526 | } |
| 527 | [] T.timeout { |
| 528 | setverdict(pass); |
| 529 | } |
| 530 | } |
| 531 | } |
| 532 | testcase TC_mo_setup_disc_late_rtp() runs on test_CT { |
| 533 | var ConnHdlrPars pars; |
| 534 | var ConnHdlr vc_conn; |
| 535 | f_init(); |
| 536 | pars := valueof(t_Pars); |
| 537 | vc_conn := f_start_handler(refers(f_TC_mo_setup_disc_late_rtp), pars); |
| 538 | vc_conn.done; |
| 539 | } |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 540 | |
| 541 | control { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 542 | execute( TC_mt_success_rel_gsm() ); |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 543 | execute( TC_mt_success_rel_gsm_ipv6() ); |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 544 | execute( TC_mt_success_rel_sip() ); |
| 545 | execute( TC_mo_success_rel_gsm() ); |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 546 | execute( TC_mo_success_rel_gsm_ipv6() ); |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 547 | execute( TC_mo_success_rel_sip() ); |
Harald Welte | ddf011e | 2019-04-19 09:39:35 +0200 | [diff] [blame] | 548 | execute( TC_mo_setup_disc_late_rtp() ); |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | |
| 552 | |
| 553 | } |