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 | |
Neels Hofmeyr | c35b657 | 2023-09-12 02:16:43 +0200 | [diff] [blame^] | 191 | altstep as_SIP_expect_resp(template PDU_SIP_Response sip_expect) runs on ConnHdlr |
| 192 | { |
| 193 | [] SIP.receive(sip_expect); |
| 194 | [] SIP.receive { |
| 195 | log("FAIL: expected SIP message ", sip_expect); |
| 196 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected SIP message"); |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | function f_SIP_expect_req(template PDU_SIP_Request sip_expect) runs on ConnHdlr return PDU_SIP_Request |
| 201 | { |
| 202 | var PDU_SIP_Request rx; |
| 203 | alt { |
| 204 | [] SIP.receive(sip_expect) -> value rx; |
| 205 | [] SIP.receive { |
| 206 | log("FAIL: expected SIP message ", sip_expect); |
| 207 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected SIP message"); |
| 208 | } |
| 209 | } |
| 210 | return rx; |
| 211 | } |
| 212 | |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 213 | /* Establish a mobile terminated call described in 'cp' */ |
| 214 | function f_establish_mt(inout CallPars cp) runs on ConnHdlr { |
| 215 | var template SipAddr sip_addr_gsm := tr_SipAddr_from_val(cp.comp.sip_url_gsm); |
| 216 | var template SipAddr sip_addr_ext := tr_SipAddr_from_val(cp.comp.sip_url_ext); |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 217 | var MNCC_PDU mncc; |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 218 | |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 219 | /* Ask MNCC_Emulation to "expect" a call to the given called number */ |
| 220 | f_create_mncc_expect(cp.called); |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 221 | |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 222 | /* OSC <- SIP: A party sends SIP invite for a MT-call into OSC */ |
| 223 | SIP.send(ts_SIP_INVITE(cp.comp.sip_call_id, cp.comp.sip_url_ext, cp.comp.sip_url_gsm, |
| 224 | cp.comp.sip_seq_nr, cp.comp.sip_body)); |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 225 | /* OSC -> SIP */ |
Neels Hofmeyr | c35b657 | 2023-09-12 02:16:43 +0200 | [diff] [blame^] | 226 | as_SIP_expect_resp(tr_SIP_Response(cp.comp.sip_call_id, sip_addr_ext, sip_addr_gsm, *, |
| 227 | "INVITE", 100, ?, "Trying", *)); |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 228 | |
Pau Espin Pedrol | 37cf408 | 2020-09-23 16:59:16 +0200 | [diff] [blame] | 229 | alt { |
| 230 | /* MSC <- OSC: OSC generates MNCC_SETUP_REQ from INVITE */ |
| 231 | [] MNCC.receive(tr_MNCC_SETUP_req) -> value mncc { |
| 232 | cp.mncc_call_id := mncc.u.signal.callref; |
| 233 | } |
| 234 | [] SIP.receive { |
Neels Hofmeyr | baf0272 | 2023-09-12 02:10:11 +0200 | [diff] [blame] | 235 | setverdict(fail, "Received unexpected SIP response"); |
Pau Espin Pedrol | 37cf408 | 2020-09-23 16:59:16 +0200 | [diff] [blame] | 236 | SIP.send(ts_SIP_ACK(cp.comp.sip_call_id, cp.comp.sip_url_ext, cp.comp.sip_url_gsm, |
| 237 | cp.comp.sip_seq_nr, omit)); |
| 238 | mtc.stop; |
| 239 | } |
| 240 | } |
| 241 | |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 242 | /* MSC -> OSC: After MS sends CALL CONF in response to SETUP */ |
| 243 | MNCC.send(ts_MNCC_CALL_CONF_ind(cp.mncc_call_id)); |
| 244 | /* MSC <- OSC: OSC asks MSC to create RTP socket */ |
| 245 | MNCC.receive(tr_MNCC_RTP_CREATE(cp.mncc_call_id)); |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 246 | mncc := valueof(ts_MNCC_RTP_CREATE(cp.mncc_call_id)); |
| 247 | mncc.u.rtp.is_ipv6 := f_addr_is_ipv6(cp.cn_rtp_addr); |
| 248 | mncc.u.rtp.ip := f_addrstr2addr(cp.cn_rtp_addr); |
| 249 | mncc.u.rtp.rtp_port := cp.cn_rtp_port; |
| 250 | MNCC.send(mncc); |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 251 | |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 252 | /* MSC -> OSC: After MS is ringing and sent CC ALERTING */ |
| 253 | MNCC.send(ts_MNCC_ALERT_ind(cp.mncc_call_id)); |
| 254 | SIP.clear; |
Neels Hofmeyr | c35b657 | 2023-09-12 02:16:43 +0200 | [diff] [blame^] | 255 | |
| 256 | as_SIP_expect_resp(tr_SIP_Response(cp.comp.sip_call_id, sip_addr_ext, sip_addr_gsm, *, |
| 257 | "INVITE", 180, ?, "Ringing", *)); |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 258 | |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 259 | /* MSC -> OSC: After MT user has picked up and sent CC CONNECT */ |
| 260 | MNCC.send(ts_MNCC_SETUP_CNF(cp.mncc_call_id)); |
| 261 | |
| 262 | SIP.clear; |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 263 | /* MSC <- OSC: OSC asks MSC to connect its RTP stream to remote end */ |
Neels Hofmeyr | c35b657 | 2023-09-12 02:16:43 +0200 | [diff] [blame^] | 264 | MNCC.receive(tr_MNCC_RTP_CONNECT(cp.mncc_call_id, f_addrstr2addr(cp.sip_rtp_addr), cp.sip_rtp_port)); |
| 265 | |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 266 | /* OSC -> SIP: OSC confirms call establishment to SIP side */ |
Neels Hofmeyr | c35b657 | 2023-09-12 02:16:43 +0200 | [diff] [blame^] | 267 | as_SIP_expect_resp(tr_SIP_Response(cp.comp.sip_call_id, sip_addr_ext, sip_addr_gsm, contact_addr := ?, |
| 268 | method := "INVITE", status_code := 200, |
| 269 | seq_nr := ?, reason := "OK", |
| 270 | body := pattern "*" & cp.cn_rtp_addr & "*")); |
| 271 | |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 272 | /* OSC <- SIP: SIP world acknowledges "200 OK" */ |
| 273 | SIP.send(ts_SIP_ACK(cp.comp.sip_call_id, cp.comp.sip_url_ext, cp.comp.sip_url_gsm, |
| 274 | cp.comp.sip_seq_nr, omit)); |
| 275 | /* MSC <- OSC: OSC sends SETUP COMPL to MNCC (which triggers CC CONNECT ACK */ |
| 276 | MNCC.receive(tr_MNCC_SETUP_COMPL_req(cp.mncc_call_id)); |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 277 | } |
| 278 | |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 279 | /* Establish a mobile originated call described in 'cp' */ |
| 280 | function f_establish_mo(inout CallPars cp) runs on ConnHdlr { |
| 281 | var MNCC_number dst := valueof(ts_MNCC_number(cp.called, GSM48_TON_UNKNOWN)); |
| 282 | var MNCC_number src := valueof(ts_MNCC_number(cp.calling, GSM48_TON_UNKNOWN)); |
| 283 | var template SipAddr sip_addr_gsm := tr_SipAddr_from_val(cp.comp.sip_url_gsm); |
| 284 | var template SipAddr sip_addr_ext := tr_SipAddr_from_val(cp.comp.sip_url_ext); |
| 285 | var PDU_SIP_Request sip_req; |
| 286 | var integer seq_nr; |
| 287 | |
| 288 | f_create_sip_expect(cp.comp.sip_url_ext.addr.nameAddr.addrSpec); |
| 289 | |
| 290 | /* MSC -> OSC: MSC sends SETUP.ind after CC SETUP was received from MS */ |
| 291 | MNCC.send(ts_MNCC_SETUP_ind(cp.mncc_call_id, dst, src, "262420123456789")); |
| 292 | /* MSC <- OSC: Create GSM side RTP socket */ |
| 293 | MNCC.receive(tr_MNCC_RTP_CREATE(cp.mncc_call_id)) { |
| 294 | var MNCC_PDU mncc := valueof(ts_MNCC_RTP_CREATE(cp.mncc_call_id)); |
| 295 | mncc.u.rtp.payload_msg_type := oct2int('0300'O); |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 296 | mncc.u.rtp.is_ipv6 := f_addr_is_ipv6(cp.cn_rtp_addr); |
| 297 | mncc.u.rtp.ip := f_addrstr2addr(cp.cn_rtp_addr); |
| 298 | mncc.u.rtp.rtp_port := cp.cn_rtp_port; |
| 299 | MNCC.send(mncc); |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 300 | } |
Neels Hofmeyr | c35b657 | 2023-09-12 02:16:43 +0200 | [diff] [blame^] | 301 | |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 302 | /* OSC -> SIP: Send INVITE with GSM side IP/Port in SDP */ |
Neels Hofmeyr | c35b657 | 2023-09-12 02:16:43 +0200 | [diff] [blame^] | 303 | sip_req := f_SIP_expect_req(tr_SIP_INVITE(?, sip_addr_gsm, sip_addr_ext, ?, ?)); |
| 304 | cp.comp.sip_url_gsm.params := sip_req.msgHeader.fromField.fromParams; |
| 305 | cp.comp.sip_call_id := sip_req.msgHeader.callId.callid; |
| 306 | seq_nr := sip_req.msgHeader.cSeq.seqNumber; |
| 307 | |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 308 | /* OSC <- SIP: Notify call is proceeding */ |
| 309 | SIP.send(ts_SIP_Response(cp.comp.sip_call_id, cp.comp.sip_url_gsm, cp.comp.sip_url_ext, |
| 310 | "INVITE", 100, seq_nr, "Trying", sip_req.msgHeader.via)); |
| 311 | /* MSC <- OSC: "100 Trying" translated to MNCC_CALL_PROC_REQ */ |
| 312 | MNCC.receive(tr_MNCC_CALL_PROC_req(cp.mncc_call_id)); |
| 313 | |
| 314 | /* OSC <- SIP: SIP-terminated user is ringing now */ |
| 315 | SIP.send(ts_SIP_Response(cp.comp.sip_call_id, cp.comp.sip_url_gsm, cp.comp.sip_url_ext, |
| 316 | "INVITE", 180, seq_nr, "Ringing", sip_req.msgHeader.via)); |
| 317 | |
| 318 | /* MSC <- OSC: "180 Ringing" translated to MNCC_ALERT_REQ */ |
| 319 | MNCC.receive(tr_MNCC_ALERT_req(cp.mncc_call_id)) {} |
| 320 | |
| 321 | /* OSC <- SIP: SIP-terminated user has accepted the call */ |
| 322 | SIP.send(ts_SIP_Response(cp.comp.sip_call_id, cp.comp.sip_url_gsm, cp.comp.sip_url_ext, |
| 323 | "INVITE", 200, seq_nr, "OK", sip_req.msgHeader.via, |
| 324 | cp.comp.sip_body)); |
| 325 | MNCC.receive(tr_MNCC_RTP_CONNECT(cp.mncc_call_id)); |
| 326 | /* MSC <- OSC: "200 OK" translated to MNCC_SETUP_RSP */ |
| 327 | MNCC.receive(tr_MNCC_SETUP_rsp(cp.mncc_call_id)); |
| 328 | |
| 329 | /* MSC -> OSC: CC CONNECT ACK was received from MS */ |
| 330 | MNCC.send(ts_MNCC_SETUP_COMPL_ind(cp.mncc_call_id)); |
| 331 | /* OSC -> SIP: Acknowledge the call */ |
| 332 | SIP.receive(tr_SIP_ACK(cp.comp.sip_call_id, sip_addr_gsm, sip_addr_ext, ?, omit)); |
| 333 | } |
| 334 | |
| 335 | /* Release call from the mobile side */ |
| 336 | function f_release_mobile(inout CallPars cp) runs on ConnHdlr { |
| 337 | var template SipAddr sip_addr_gsm := tr_SipAddr_from_val(cp.comp.sip_url_gsm); |
| 338 | var template SipAddr sip_addr_ext := tr_SipAddr_from_val(cp.comp.sip_url_ext); |
| 339 | var PDU_SIP_Request sip_req; |
| 340 | SIP.clear; |
| 341 | /* MSC -> OSC: Simulate a CC DISCONNET from the MT user */ |
| 342 | MNCC.send(ts_MNCC_DISC_ind(cp.mncc_call_id, ts_MNCC_cause(0))); |
Neels Hofmeyr | c35b657 | 2023-09-12 02:16:43 +0200 | [diff] [blame^] | 343 | |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 344 | /* OSC -> SIP: Expect BYE from OSC to SIP side */ |
Neels Hofmeyr | c35b657 | 2023-09-12 02:16:43 +0200 | [diff] [blame^] | 345 | sip_req := f_SIP_expect_req(tr_SIP_BYE(cp.comp.sip_call_id, sip_addr_gsm, sip_addr_ext, ?, *)); |
| 346 | cp.comp.sip_url_gsm.params := sip_req.msgHeader.fromField.fromParams; |
| 347 | |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 348 | /* OSC <- SIP: Acknowledge the BYE */ |
| 349 | SIP.send(ts_SIP_Response(cp.comp.sip_call_id, cp.comp.sip_url_gsm, cp.comp.sip_url_ext, |
| 350 | "BYE", 200, sip_req.msgHeader.cSeq.seqNumber, "OK", |
| 351 | sip_req.msgHeader.via)); |
| 352 | /* MSC <- OSC: Send REL_REQ to MSC, triggers CC RELEASE REQ to MS */ |
| 353 | MNCC.receive(tr_MNCC_REL_req(cp.mncc_call_id)); // CAUSE? |
| 354 | /* MSC -> OSC: MS has responded with CC CLEAR COMPL, triggers MNCC_REL_CNF */ |
| 355 | MNCC.send(ts_MNCC_REL_cnf(cp.mncc_call_id, ts_MNCC_cause(0))); |
| 356 | } |
| 357 | |
| 358 | /* Release call from the SIP side */ |
| 359 | function f_release_sip(inout CallPars cp) runs on ConnHdlr { |
| 360 | var template SipAddr sip_addr_gsm := tr_SipAddr_from_val(cp.comp.sip_url_gsm); |
| 361 | var template SipAddr sip_addr_ext := tr_SipAddr_from_val(cp.comp.sip_url_ext); |
| 362 | /* OSC <- SIP: SIP-side sends a BYE to OSC */ |
| 363 | SIP.send(ts_SIP_BYE(cp.comp.sip_call_id, cp.comp.sip_url_ext, cp.comp.sip_url_gsm, |
| 364 | cp.comp.sip_seq_nr, omit)); |
| 365 | /* MSC <- OSC: Expect OSC to cause MNCC Disconnect Request */ |
| 366 | MNCC.receive(tr_MNCC_DISC_req(cp.mncc_call_id)); |
| 367 | /* MSC -> OSC: Indicate GSM side release */ |
| 368 | MNCC.send(ts_MNCC_REL_ind(cp.mncc_call_id, ts_MNCC_cause(0))); |
| 369 | /* OSC -> SIP: Confirmation to SIP side */ |
Neels Hofmeyr | c35b657 | 2023-09-12 02:16:43 +0200 | [diff] [blame^] | 370 | as_SIP_expect_resp(tr_SIP_Response(cp.comp.sip_call_id, sip_addr_ext, sip_addr_gsm, *, |
| 371 | "BYE", 200, cp.comp.sip_seq_nr, "OK", omit)); |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | /* Successful MT Call, which is subsequently released by GSM side */ |
| 375 | 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] | 376 | var CallPars cp := g_pars.g_cp; |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 377 | f_CallPars_compute(cp); |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 378 | cp.comp.sip_body := "v=0\r\no=Osmocom 0 0 IN IP4 1.1.1.1\r\ns=GSM Call\r\nc=IN " & |
| 379 | f_mgcp_addr2addrtype(cp.sip_rtp_addr) & " " & cp.sip_rtp_addr & |
| 380 | "\r\nt=0 0\r\nm=audio " & int2str(cp.sip_rtp_port) & |
| 381 | " RTP/AVP 0\r\na=rtpmap:0 GSM/8000\r\n"; |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 382 | f_sleep(3.0) |
| 383 | |
| 384 | f_establish_mt(cp); |
| 385 | /* now call is fully established */ |
| 386 | f_sleep(2.0); |
| 387 | f_release_mobile(cp); |
| 388 | setverdict(pass); |
| 389 | } |
| 390 | testcase TC_mt_success_rel_gsm() runs on test_CT { |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 391 | var ConnHdlrPars pars; |
| 392 | var ConnHdlr vc_conn; |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 393 | f_init(); |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 394 | pars := valueof(t_Pars); |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 395 | pars.g_cp := valueof(t_CallPars(false)); |
| 396 | vc_conn := f_start_handler(refers(f_TC_mt_success_rel_gsm), pars); |
| 397 | vc_conn.done; |
| 398 | } |
| 399 | testcase TC_mt_success_rel_gsm_ipv6() runs on test_CT { |
| 400 | var ConnHdlrPars pars; |
| 401 | var ConnHdlr vc_conn; |
| 402 | f_init(); |
| 403 | pars := valueof(t_Pars); |
| 404 | pars.g_cp := valueof(t_CallPars(false)); |
| 405 | pars.g_cp.sip_rtp_addr := "::1"; |
| 406 | pars.g_cp.cn_rtp_addr := "::2"; |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 407 | vc_conn := f_start_handler(refers(f_TC_mt_success_rel_gsm), pars); |
| 408 | vc_conn.done; |
| 409 | } |
| 410 | |
| 411 | /* Successful MT Call, which is subsequently released by SIP side */ |
| 412 | private function f_TC_mt_success_rel_sip(charstring id) runs on ConnHdlr { |
| 413 | var CallPars cp := valueof(t_CallPars(false)); |
| 414 | f_CallPars_compute(cp); |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 415 | cp.comp.sip_body := "v=0\r\no=Osmocom 0 0 IN IP4 1.1.1.1\r\ns=GSM Call\r\nc=IN " & |
| 416 | f_mgcp_addr2addrtype(cp.sip_rtp_addr) & " " & cp.sip_rtp_addr & |
| 417 | "\r\nt=0 0\r\nm=audio " & int2str(cp.sip_rtp_port) & |
| 418 | " RTP/AVP 0\r\na=rtpmap:0 GSM/8000\r\n"; |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 419 | f_sleep(3.0) |
| 420 | |
| 421 | f_establish_mt(cp); |
| 422 | /* now call is fully established */ |
| 423 | f_sleep(2.0); |
| 424 | f_release_sip(cp); |
| 425 | setverdict(pass); |
| 426 | } |
| 427 | testcase TC_mt_success_rel_sip() runs on test_CT { |
| 428 | var ConnHdlrPars pars; |
| 429 | var ConnHdlr vc_conn; |
| 430 | f_init(); |
| 431 | pars := valueof(t_Pars); |
| 432 | 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] | 433 | vc_conn.done; |
| 434 | } |
| 435 | |
| 436 | |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 437 | /* Successful MO Call, which is subsequently released by GSM side */ |
| 438 | 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] | 439 | var CallPars cp := g_pars.g_cp; |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 440 | f_CallPars_compute(cp); |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 441 | cp.comp.sip_body := "v=0\r\no=Osmocom 0 0 IN IP4 1.1.1.1\r\ns=GSM Call\r\nc=IN " & |
| 442 | f_mgcp_addr2addrtype(cp.sip_rtp_addr) & " " & cp.sip_rtp_addr & |
| 443 | "\r\nt=0 0\r\nm=audio " & int2str(cp.sip_rtp_port) & |
| 444 | " RTP/AVP 0\r\na=rtpmap:0 GSM/8000\r\n"; |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 445 | f_sleep(3.0) |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 446 | |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 447 | f_establish_mo(cp); |
| 448 | /* now call is fully established */ |
| 449 | f_sleep(2.0); |
| 450 | f_release_mobile(cp); |
| 451 | setverdict(pass); |
| 452 | } |
| 453 | testcase TC_mo_success_rel_gsm() runs on test_CT { |
| 454 | var ConnHdlrPars pars; |
| 455 | var ConnHdlr vc_conn; |
| 456 | f_init(); |
| 457 | pars := valueof(t_Pars); |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 458 | pars.g_cp := valueof(t_CallPars(true)); |
| 459 | vc_conn := f_start_handler(refers(f_TC_mo_success_rel_gsm), pars); |
| 460 | vc_conn.done; |
| 461 | } |
| 462 | testcase TC_mo_success_rel_gsm_ipv6() runs on test_CT { |
| 463 | var ConnHdlrPars pars; |
| 464 | var ConnHdlr vc_conn; |
| 465 | f_init(); |
| 466 | pars := valueof(t_Pars); |
| 467 | pars.g_cp := valueof(t_CallPars(true)); |
| 468 | pars.g_cp.sip_rtp_addr := "::1"; |
| 469 | pars.g_cp.cn_rtp_addr := "::2"; |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 470 | vc_conn := f_start_handler(refers(f_TC_mo_success_rel_gsm), pars); |
| 471 | vc_conn.done; |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 472 | } |
| 473 | |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 474 | /* Successful MO Call, which is subsequently released by SIP side */ |
| 475 | private function f_TC_mo_success_rel_sip(charstring id) runs on ConnHdlr { |
| 476 | var CallPars cp := valueof(t_CallPars(true)); |
| 477 | f_CallPars_compute(cp); |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 478 | cp.comp.sip_body := "v=0\r\no=Osmocom 0 0 IN IP4 1.1.1.1\r\ns=GSM Call\r\nc=IN " & |
| 479 | f_mgcp_addr2addrtype(cp.sip_rtp_addr) & " " & cp.sip_rtp_addr & |
| 480 | "\r\nt=0 0\r\nm=audio " & int2str(cp.sip_rtp_port) & |
| 481 | " RTP/AVP 0\r\na=rtpmap:0 GSM/8000\r\n"; |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 482 | f_sleep(3.0) |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 483 | |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 484 | f_establish_mo(cp); |
| 485 | /* now call is fully established */ |
| 486 | f_sleep(2.0); |
| 487 | f_release_sip(cp); |
| 488 | setverdict(pass); |
| 489 | } |
| 490 | testcase TC_mo_success_rel_sip() runs on test_CT { |
| 491 | var ConnHdlrPars pars; |
| 492 | var ConnHdlr vc_conn; |
| 493 | f_init(); |
| 494 | pars := valueof(t_Pars); |
| 495 | vc_conn := f_start_handler(refers(f_TC_mo_success_rel_sip), pars); |
| 496 | vc_conn.done; |
| 497 | } |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 498 | |
Harald Welte | ddf011e | 2019-04-19 09:39:35 +0200 | [diff] [blame] | 499 | /* SETUP followed by DISC results in lingering B-leg (OS#3518)*/ |
| 500 | private function f_TC_mo_setup_disc_late_rtp(charstring id) runs on ConnHdlr { |
| 501 | var CallPars cp := valueof(t_CallPars(true)); |
| 502 | f_CallPars_compute(cp); |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 503 | cp.comp.sip_body := "v=0\r\no=Osmocom 0 0 IN IP4 1.1.1.1\r\ns=GSM Call\r\nc=IN " & |
| 504 | f_mgcp_addr2addrtype(cp.sip_rtp_addr) & " " & cp.sip_rtp_addr & |
| 505 | "\r\nt=0 0\r\nm=audio " & int2str(cp.sip_rtp_port) & |
| 506 | " RTP/AVP 0\r\na=rtpmap:0 GSM/8000\r\n"; |
Harald Welte | ddf011e | 2019-04-19 09:39:35 +0200 | [diff] [blame] | 507 | f_sleep(3.0); |
| 508 | |
| 509 | var MNCC_number dst := valueof(ts_MNCC_number(cp.called, GSM48_TON_UNKNOWN)); |
| 510 | var MNCC_number src := valueof(ts_MNCC_number(cp.calling, GSM48_TON_UNKNOWN)); |
| 511 | var template SipAddr sip_addr_gsm := tr_SipAddr_from_val(cp.comp.sip_url_gsm); |
| 512 | var template SipAddr sip_addr_ext := tr_SipAddr_from_val(cp.comp.sip_url_ext); |
| 513 | |
| 514 | f_create_sip_expect(cp.comp.sip_url_ext.addr.nameAddr.addrSpec); |
| 515 | |
| 516 | /* MSC -> OSC: MSC sends SETUP.ind after CC SETUP was received from MS */ |
| 517 | MNCC.send(ts_MNCC_SETUP_ind(cp.mncc_call_id, dst, src, "262420123456789")); |
| 518 | |
| 519 | /* MSC -> OSC: Simulate a CC DISCONNET from the MT user *before* responding to the RTP_CREATE */ |
| 520 | MNCC.send(ts_MNCC_DISC_ind(cp.mncc_call_id, ts_MNCC_cause(0))); |
| 521 | |
| 522 | /* MSC <- OSC: Create GSM side RTP socket (too late) */ |
| 523 | MNCC.receive(tr_MNCC_RTP_CREATE(cp.mncc_call_id)) { |
| 524 | var MNCC_PDU mncc := valueof(ts_MNCC_RTP_CREATE(cp.mncc_call_id)); |
| 525 | mncc.u.rtp.payload_msg_type := oct2int('0300'O); |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 526 | mncc.u.rtp.is_ipv6 := f_addr_is_ipv6(cp.cn_rtp_addr); |
| 527 | mncc.u.rtp.ip := f_addrstr2addr(cp.cn_rtp_addr); |
| 528 | mncc.u.rtp.rtp_port := cp.cn_rtp_port; |
| 529 | MNCC.send(mncc); |
Harald Welte | ddf011e | 2019-04-19 09:39:35 +0200 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | /* OSC -> SIP: We should never receive INVITE */ |
| 533 | timer T := 10.0; |
| 534 | T.start; |
| 535 | alt { |
| 536 | [] SIP.receive(tr_SIP_INVITE(?, sip_addr_gsm, sip_addr_ext, ?, ?)) { |
| 537 | setverdict(fail, "Received unexpected INVITE"); |
| 538 | } |
| 539 | [] T.timeout { |
| 540 | setverdict(pass); |
| 541 | } |
| 542 | } |
| 543 | } |
| 544 | testcase TC_mo_setup_disc_late_rtp() runs on test_CT { |
| 545 | var ConnHdlrPars pars; |
| 546 | var ConnHdlr vc_conn; |
| 547 | f_init(); |
| 548 | pars := valueof(t_Pars); |
| 549 | vc_conn := f_start_handler(refers(f_TC_mo_setup_disc_late_rtp), pars); |
| 550 | vc_conn.done; |
| 551 | } |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 552 | |
| 553 | control { |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 554 | execute( TC_mt_success_rel_gsm() ); |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 555 | execute( TC_mt_success_rel_gsm_ipv6() ); |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 556 | execute( TC_mt_success_rel_sip() ); |
| 557 | execute( TC_mo_success_rel_gsm() ); |
Pau Espin Pedrol | bdd874a | 2020-09-10 19:09:47 +0200 | [diff] [blame] | 558 | execute( TC_mo_success_rel_gsm_ipv6() ); |
Harald Welte | b0d9360 | 2018-03-20 18:09:34 +0100 | [diff] [blame] | 559 | execute( TC_mo_success_rel_sip() ); |
Harald Welte | ddf011e | 2019-04-19 09:39:35 +0200 | [diff] [blame] | 560 | execute( TC_mo_setup_disc_late_rtp() ); |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | |
| 564 | |
| 565 | } |