Harald Welte | 34b5a95 | 2019-05-27 11:54:11 +0200 | [diff] [blame] | 1 | /* MGW (Media Gateway) test suite in TTCN-3 |
| 2 | * (C) 2017-2018 Harald Welte <laforge@gnumonks.org> |
| 3 | * (C) 2018-2019 sysmocom - s.f.m.c. GmbH |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * Released under the terms of GNU General Public License, Version 2 or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 10 | */ |
| 11 | |
Harald Welte | 00a067f | 2017-09-13 23:27:17 +0200 | [diff] [blame] | 12 | module MGCP_Test { |
Harald Welte | f07c286 | 2017-11-18 17:16:24 +0100 | [diff] [blame] | 13 | import from Osmocom_Types all; |
Harald Welte | 00a067f | 2017-09-13 23:27:17 +0200 | [diff] [blame] | 14 | import from MGCP_Types all; |
Harald Welte | 4029e8c | 2017-11-23 22:00:42 +0100 | [diff] [blame] | 15 | import from MGCP_Templates all; |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 16 | import from SDP_Types all; |
| 17 | import from MGCP_CodecPort all; |
| 18 | import from MGCP_CodecPort_CtrlFunct all; |
Harald Welte | f07c286 | 2017-11-18 17:16:24 +0100 | [diff] [blame] | 19 | import from RTP_CodecPort all; |
| 20 | import from RTP_CodecPort_CtrlFunct all; |
Harald Welte | bb7523b | 2018-03-29 08:52:01 +0200 | [diff] [blame] | 21 | import from RTP_Emulation all; |
Pau Espin Pedrol | b2c6b38 | 2019-05-14 13:40:49 +0200 | [diff] [blame] | 22 | import from OSMUX_Types all; |
| 23 | import from OSMUX_CodecPort all; |
| 24 | import from OSMUX_CodecPort_CtrlFunct all; |
| 25 | import from OSMUX_Emulation all; |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 26 | import from IPL4asp_Types all; |
Philipp Maier | 6137c32 | 2019-02-20 16:13:41 +0100 | [diff] [blame] | 27 | import from General_Types all; |
| 28 | import from Native_Functions all; |
| 29 | import from IPCP_Types all; |
| 30 | import from IP_Types all; |
| 31 | import from Osmocom_VTY_Functions all; |
| 32 | import from TELNETasp_PortType all; |
Harald Welte | 00a067f | 2017-09-13 23:27:17 +0200 | [diff] [blame] | 33 | |
Philipp Maier | bb7a01c | 2018-02-01 12:32:57 +0100 | [diff] [blame] | 34 | const charstring c_mgw_domain := "mgw"; |
| 35 | const charstring c_mgw_ep_rtpbridge := "rtpbridge/"; |
| 36 | |
Harald Welte | 21ba557 | 2017-09-19 17:55:05 +0800 | [diff] [blame] | 37 | /* any variables declared in the component will be available to |
| 38 | * all functions that 'run on' the named component, similar to |
| 39 | * class members in C++ */ |
Harald Welte | 00a067f | 2017-09-13 23:27:17 +0200 | [diff] [blame] | 40 | type component dummy_CT { |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 41 | port MGCP_CODEC_PT MGCP; |
| 42 | var boolean initialized := false; |
Harald Welte | 5501536 | 2017-11-18 16:02:42 +0100 | [diff] [blame] | 43 | var ConnectionId g_mgcp_conn_id := -1; |
Harald Welte | e1e18c5 | 2017-09-17 16:23:07 +0800 | [diff] [blame] | 44 | var integer g_trans_id; |
Harald Welte | f07c286 | 2017-11-18 17:16:24 +0100 | [diff] [blame] | 45 | |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 46 | var RTP_Emulation_CT vc_RTPEM[3]; |
| 47 | port RTPEM_CTRL_PT RTPEM[3]; |
Philipp Maier | 6137c32 | 2019-02-20 16:13:41 +0100 | [diff] [blame] | 48 | |
Pau Espin Pedrol | b2c6b38 | 2019-05-14 13:40:49 +0200 | [diff] [blame] | 49 | var OSMUX_Emulation_CT vc_OsmuxEM; |
| 50 | port OsmuxEM_CTRL_PT OsmuxEM; |
| 51 | |
Philipp Maier | 6137c32 | 2019-02-20 16:13:41 +0100 | [diff] [blame] | 52 | port TELNETasp_PT MGWVTY; |
Harald Welte | 00a067f | 2017-09-13 23:27:17 +0200 | [diff] [blame] | 53 | }; |
| 54 | |
Harald Welte | e1e18c5 | 2017-09-17 16:23:07 +0800 | [diff] [blame] | 55 | function get_next_trans_id() runs on dummy_CT return MgcpTransId { |
| 56 | var MgcpTransId tid := int2str(g_trans_id); |
| 57 | g_trans_id := g_trans_id + 1; |
| 58 | return tid; |
| 59 | } |
| 60 | |
Harald Welte | 21ba557 | 2017-09-19 17:55:05 +0800 | [diff] [blame] | 61 | /* all parameters declared here can be modified / overridden by |
| 62 | * the config file in the [MODULE_PARAMETERS] section. If no |
| 63 | * config file is used or the file doesn't specify them, the |
| 64 | * default values assigned below are used */ |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 65 | modulepar { |
| 66 | PortNumber mp_local_udp_port := 2727; |
| 67 | charstring mp_local_ip := "127.0.0.1"; |
| 68 | PortNumber mp_remote_udp_port := 2427; |
| 69 | charstring mp_remote_ip := "127.0.0.1"; |
Harald Welte | f07c286 | 2017-11-18 17:16:24 +0100 | [diff] [blame] | 70 | PortNumber mp_local_rtp_port_base := 10000; |
Pau Espin Pedrol | b2c6b38 | 2019-05-14 13:40:49 +0200 | [diff] [blame] | 71 | PortNumber mp_local_osmux_port := 1985; |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 72 | } |
| 73 | |
Pau Espin Pedrol | b2c6b38 | 2019-05-14 13:40:49 +0200 | [diff] [blame] | 74 | private function f_vty_enable_osmux(boolean osmux_on) runs on dummy_CT { |
| 75 | /* Turn on conversion mode */ |
| 76 | f_vty_enter_config(MGWVTY); |
| 77 | f_vty_transceive(MGWVTY, "mgcp"); |
| 78 | if (osmux_on) { |
| 79 | f_vty_transceive(MGWVTY, "osmux on"); |
| 80 | } else { |
| 81 | f_vty_transceive(MGWVTY, "osmux off"); |
| 82 | } |
| 83 | f_vty_transceive(MGWVTY, "exit"); |
| 84 | f_vty_transceive(MGWVTY, "exit"); |
| 85 | |
| 86 | } |
| 87 | |
| 88 | private function f_init_vty(boolean osmux_on) runs on dummy_CT { |
Philipp Maier | 6137c32 | 2019-02-20 16:13:41 +0100 | [diff] [blame] | 89 | map(self:MGWVTY, system:MGWVTY); |
| 90 | f_vty_set_prompts(MGWVTY); |
| 91 | f_vty_transceive(MGWVTY, "enable"); |
Pau Espin Pedrol | b2c6b38 | 2019-05-14 13:40:49 +0200 | [diff] [blame] | 92 | |
| 93 | f_vty_enable_osmux(osmux_on); |
Philipp Maier | 6137c32 | 2019-02-20 16:13:41 +0100 | [diff] [blame] | 94 | } |
| 95 | |
Harald Welte | bb7523b | 2018-03-29 08:52:01 +0200 | [diff] [blame] | 96 | private function f_rtpem_init(inout RTP_Emulation_CT comp_ref, integer i) |
| 97 | runs on dummy_CT { |
| 98 | comp_ref := RTP_Emulation_CT.create("RTPEM" & int2str(i)); |
| 99 | map(comp_ref:RTP, system:RTP); |
| 100 | map(comp_ref:RTCP, system:RTCP); |
| 101 | comp_ref.start(RTP_Emulation.f_main()); |
| 102 | } |
| 103 | |
Pau Espin Pedrol | b2c6b38 | 2019-05-14 13:40:49 +0200 | [diff] [blame] | 104 | private function f_osmuxem_init(inout OSMUX_Emulation_CT comp_ref) |
| 105 | runs on dummy_CT { |
| 106 | comp_ref := OSMUX_Emulation_CT.create("OsmuxEM"); |
| 107 | map(comp_ref:OSMUX, system:OSMUX); |
| 108 | comp_ref.start(OSMUX_Emulation.f_main()); |
| 109 | } |
| 110 | |
Harald Welte | 21ba557 | 2017-09-19 17:55:05 +0800 | [diff] [blame] | 111 | /* initialization function, called by each test case at the |
| 112 | * beginning, but 'initialized' variable ensures its body is |
| 113 | * only executed once */ |
Pau Espin Pedrol | b2c6b38 | 2019-05-14 13:40:49 +0200 | [diff] [blame] | 114 | private function f_init(template MgcpEndpoint ep := omit, boolean osmux_on := false) runs on dummy_CT { |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 115 | var Result res; |
Harald Welte | f07c286 | 2017-11-18 17:16:24 +0100 | [diff] [blame] | 116 | var uint32_t ssrc; |
Philipp Maier | 28bb829 | 2018-07-20 17:09:17 +0200 | [diff] [blame] | 117 | |
Harald Welte | edc45c1 | 2017-11-18 19:15:05 +0100 | [diff] [blame] | 118 | if (initialized == false) { |
| 119 | initialized := true; |
| 120 | |
| 121 | /* some random number for the initial transaction id */ |
| 122 | g_trans_id := float2int(rnd()*65535.0); |
| 123 | map(self:MGCP, system:MGCP_CODEC_PT); |
| 124 | /* connect the MGCP test port using the given |
| 125 | * source/destionation ip/port and store the connection id in g_mgcp_conn_id |
| 126 | * */ |
| 127 | res := MGCP_CodecPort_CtrlFunct.f_IPL4_connect(MGCP, mp_remote_ip, mp_remote_udp_port, mp_local_ip, mp_local_udp_port, 0, { udp := {} }); |
Harald Welte | 9220f63 | 2018-05-23 20:27:02 +0200 | [diff] [blame] | 128 | if (not ispresent(res.connId)) { |
| 129 | setverdict(fail, "Could not connect MGCP, check your configuration"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 130 | mtc.stop; |
Harald Welte | 9220f63 | 2018-05-23 20:27:02 +0200 | [diff] [blame] | 131 | } |
Harald Welte | edc45c1 | 2017-11-18 19:15:05 +0100 | [diff] [blame] | 132 | g_mgcp_conn_id := res.connId; |
| 133 | |
Harald Welte | bb7523b | 2018-03-29 08:52:01 +0200 | [diff] [blame] | 134 | for (var integer i := 0; i < sizeof(vc_RTPEM); i := i+1) { |
| 135 | f_rtpem_init(vc_RTPEM[i], i); |
| 136 | connect(vc_RTPEM[i]:CTRL, self:RTPEM[i]); |
| 137 | } |
Pau Espin Pedrol | b2c6b38 | 2019-05-14 13:40:49 +0200 | [diff] [blame] | 138 | if (osmux_on) { |
| 139 | f_osmuxem_init(vc_OsmuxEM); |
| 140 | connect(vc_OsmuxEM:CTRL, self:OsmuxEM); |
| 141 | } |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 142 | } |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 143 | |
Harald Welte | edc45c1 | 2017-11-18 19:15:05 +0100 | [diff] [blame] | 144 | if (isvalue(ep)) { |
| 145 | /* do a DLCX on all connections of the EP */ |
| 146 | f_dlcx_ignore(valueof(ep)); |
| 147 | } |
Philipp Maier | 6137c32 | 2019-02-20 16:13:41 +0100 | [diff] [blame] | 148 | |
Pau Espin Pedrol | b2c6b38 | 2019-05-14 13:40:49 +0200 | [diff] [blame] | 149 | f_init_vty(osmux_on); |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 150 | } |
| 151 | |
Harald Welte | 00a067f | 2017-09-13 23:27:17 +0200 | [diff] [blame] | 152 | testcase TC_selftest() runs on dummy_CT { |
| 153 | const charstring c_auep := "AUEP 158663169 ds/e1-1/2@172.16.6.66 MGCP 1.0\r\n"; |
Philipp Maier | bb7a01c | 2018-02-01 12:32:57 +0100 | [diff] [blame] | 154 | const charstring c_mdcx3 := "MDCX 18983215 " & c_mgw_ep_rtpbridge & "1@" & c_mgw_domain & " MGCP 1.0\r\n"; |
Harald Welte | 00a067f | 2017-09-13 23:27:17 +0200 | [diff] [blame] | 155 | const charstring c_mdcx3_ret := "200 18983215 OK\r\n" & |
| 156 | "I: 1\n" & |
| 157 | "\n" & |
| 158 | "v=0\r\n" & |
| 159 | "o=- 1 23 IN IP4 0.0.0.0\r\n" & |
| 160 | "s=-\r\n" & |
| 161 | "c=IN IP4 0.0.0.0\r\n" & |
| 162 | "t=0 0\r\n" & |
| 163 | "m=audio 0 RTP/AVP 126\r\n" & |
| 164 | "a=rtpmap:126 AMR/8000\r\n" & |
| 165 | "a=ptime:20\r\n"; |
Philipp Maier | bb7a01c | 2018-02-01 12:32:57 +0100 | [diff] [blame] | 166 | const charstring c_mdcx4 := "MDCX 18983216 " & c_mgw_ep_rtpbridge & "1@" & c_mgw_domain & " MGCP 1.0\r\n" & |
Harald Welte | 00a067f | 2017-09-13 23:27:17 +0200 | [diff] [blame] | 167 | "M: sendrecv\r" & |
| 168 | "C: 2\r\n" & |
| 169 | "I: 1\r\n" & |
| 170 | "L: p:20, a:AMR, nt:IN\r\n" & |
| 171 | "\n" & |
| 172 | "v=0\r\n" & |
| 173 | "o=- 1 23 IN IP4 0.0.0.0\r\n" & |
Harald Welte | 2871d0b | 2017-09-14 22:42:12 +0800 | [diff] [blame] | 174 | "s=-\r\n" & |
Harald Welte | 00a067f | 2017-09-13 23:27:17 +0200 | [diff] [blame] | 175 | "c=IN IP4 0.0.0.0\r\n" & |
| 176 | "t=0 0\r\n" & |
| 177 | "m=audio 4441 RTP/AVP 99\r\n" & |
| 178 | "a=rtpmap:99 AMR/8000\r\n" & |
| 179 | "a=ptime:40\r\n"; |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 180 | const charstring c_crcx510_ret := "510 23 FAIL\r\n" |
Harald Welte | 00a067f | 2017-09-13 23:27:17 +0200 | [diff] [blame] | 181 | |
| 182 | log(c_auep); |
| 183 | log(dec_MgcpCommand(c_auep)); |
| 184 | |
| 185 | log(c_mdcx3); |
| 186 | log(dec_MgcpCommand(c_mdcx3)); |
| 187 | |
| 188 | log(c_mdcx3_ret); |
| 189 | log(dec_MgcpResponse(c_mdcx3_ret)); |
| 190 | |
| 191 | log(c_mdcx4); |
| 192 | log(dec_MgcpCommand(c_mdcx4)); |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 193 | |
Philipp Maier | bb7a01c | 2018-02-01 12:32:57 +0100 | [diff] [blame] | 194 | log(ts_CRCX("23", c_mgw_ep_rtpbridge & "42@" & c_mgw_domain, "sendrecv", '1234'H)); |
| 195 | log(enc_MgcpCommand(valueof(ts_CRCX("23", c_mgw_ep_rtpbridge & "42@" & c_mgw_domain, "sendrecv", '1234'H)))); |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 196 | |
| 197 | log(c_crcx510_ret); |
| 198 | log(dec_MgcpResponse(c_crcx510_ret)); |
| 199 | log(dec_MgcpMessage(c_crcx510_ret)); |
Daniel Willmann | 94e4e80 | 2018-12-13 16:56:26 +0100 | [diff] [blame] | 200 | |
| 201 | /* We didn't encounter any DTE, so pass the test */ |
| 202 | setverdict(pass); |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 203 | } |
| 204 | |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 205 | /* CRCX test ideas: |
Harald Welte | e0b331f | 2017-11-18 20:34:33 +0100 | [diff] [blame] | 206 | * x without mandatory CallId |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 207 | * - with forbidden parameters (e.g. Capabilities, PackageList, ... |
| 208 | * - CRCX with remote session description and without |
| 209 | * |
| 210 | * general ideas: |
Harald Welte | e0b331f | 2017-11-18 20:34:33 +0100 | [diff] [blame] | 211 | * x packetization != 20ms |
| 212 | * x invalid mode |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 213 | * x unsupported mode (517) |
| 214 | * x bidirectional mode before RemoteConnDesc: 527 |
| 215 | * - invalid codec |
Harald Welte | e0b331f | 2017-11-18 20:34:33 +0100 | [diff] [blame] | 216 | * x retransmission of same transaction |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 217 | * - unsupported LocalConnectionOptions ("b", "a", "e", "gc", "s", "r", "k", ..) |
| 218 | */ |
| 219 | |
Harald Welte | 21ba557 | 2017-09-19 17:55:05 +0800 | [diff] [blame] | 220 | /* build a receive template for receiving a MGCP message. You |
| 221 | * pass the MGCP response template in, and it will generate an |
| 222 | * MGCP_RecvFrom template that can match the primitives arriving on the |
| 223 | * MGCP_CodecPort */ |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 224 | function tr_MGCP_RecvFrom_R(template MgcpResponse resp) runs on dummy_CT return template MGCP_RecvFrom { |
| 225 | var template MGCP_RecvFrom mrf := { |
Harald Welte | 5501536 | 2017-11-18 16:02:42 +0100 | [diff] [blame] | 226 | connId := g_mgcp_conn_id, |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 227 | remName := mp_remote_ip, |
| 228 | remPort := mp_remote_udp_port, |
| 229 | locName := mp_local_ip, |
| 230 | locPort := mp_local_udp_port, |
| 231 | msg := { response := resp } |
| 232 | } |
| 233 | return mrf; |
| 234 | } |
| 235 | |
| 236 | /* Send a MGCP request + receive a (matching!) response */ |
| 237 | function mgcp_transceive_mgw(template MgcpCommand cmd, template MgcpResponse resp := ?) runs on dummy_CT return MgcpResponse { |
| 238 | var MgcpMessage msg := { command := valueof(cmd) }; |
| 239 | resp.line.trans_id := cmd.line.trans_id; |
| 240 | var template MGCP_RecvFrom mrt := tr_MGCP_RecvFrom_R(resp); |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 241 | var MGCP_RecvFrom mrf; |
| 242 | timer T := 5.0; |
| 243 | |
Harald Welte | 5501536 | 2017-11-18 16:02:42 +0100 | [diff] [blame] | 244 | MGCP.send(t_MGCP_Send(g_mgcp_conn_id, msg)); |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 245 | T.start; |
| 246 | alt { |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 247 | [] MGCP.receive(mrt) -> value mrf { } |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 248 | [] MGCP.receive(tr_MGCP_RecvFrom_R(?)) { |
| 249 | setverdict(fail, "Response didn't match template"); |
| 250 | mtc.stop; |
| 251 | } |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 252 | [] MGCP.receive { repeat; } |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 253 | [] T.timeout { |
| 254 | setverdict(fail, "Timeout waiting for response to ", cmd); |
| 255 | mtc.stop; |
| 256 | } |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 257 | } |
| 258 | T.stop; |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 259 | |
| 260 | if (isbound(mrf) and isbound(mrf.msg) and ischosen(mrf.msg.response)) { |
| 261 | return mrf.msg.response; |
| 262 | } else { |
| 263 | var MgcpResponse r := { line := { code := "999", trans_id := valueof(cmd.line.trans_id) } }; |
| 264 | return r; |
| 265 | } |
Harald Welte | 00a067f | 2017-09-13 23:27:17 +0200 | [diff] [blame] | 266 | } |
| 267 | |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 268 | function extract_conn_id(MgcpResponse resp) return MgcpConnectionId { |
| 269 | var integer i; |
| 270 | for (i := 0; i < lengthof(resp.params); i := i + 1) { |
| 271 | var MgcpParameter par := resp.params[i]; |
| 272 | if (par.code == "I") { |
| 273 | return str2hex(par.val); |
| 274 | } |
| 275 | } |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 276 | setverdict(fail, "Could not find conn id for MgcpReponse"); |
| 277 | mtc.stop; |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 278 | return '00000000'H; |
| 279 | } |
| 280 | |
Harald Welte | 10889c1 | 2017-11-18 19:40:31 +0100 | [diff] [blame] | 281 | function f_dlcx(MgcpEndpoint ep, template MgcpResponseCode ret_code, template charstring ret_val, |
| 282 | template MgcpCallId call_id := omit, |
| 283 | template MgcpConnectionId conn_id := omit) runs on dummy_CT { |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 284 | var template MgcpCommand cmd; |
| 285 | var MgcpResponse resp; |
| 286 | var template MgcpResponse rtmpl := { |
| 287 | line := { |
Harald Welte | 10889c1 | 2017-11-18 19:40:31 +0100 | [diff] [blame] | 288 | code := ret_code, |
| 289 | string := ret_val |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 290 | }, |
| 291 | params := *, |
| 292 | sdp := * |
| 293 | }; |
Harald Welte | c40e0c3 | 2017-11-18 19:08:22 +0100 | [diff] [blame] | 294 | cmd := ts_DLCX(get_next_trans_id(), ep, call_id, conn_id); |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 295 | resp := mgcp_transceive_mgw(cmd, rtmpl); |
| 296 | } |
| 297 | |
Harald Welte | 10889c1 | 2017-11-18 19:40:31 +0100 | [diff] [blame] | 298 | /* Send DLCX and expect OK response */ |
| 299 | function f_dlcx_ok(MgcpEndpoint ep, template MgcpCallId call_id := omit, |
| 300 | template MgcpConnectionId conn_id := omit) runs on dummy_CT { |
Harald Welte | f91edf3 | 2017-12-28 14:16:21 +0100 | [diff] [blame] | 301 | f_dlcx(ep, ("200","250"), "OK", call_id, conn_id); |
Harald Welte | 10889c1 | 2017-11-18 19:40:31 +0100 | [diff] [blame] | 302 | } |
| 303 | |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 304 | /* Send DLCX and accept any response */ |
Harald Welte | c40e0c3 | 2017-11-18 19:08:22 +0100 | [diff] [blame] | 305 | function f_dlcx_ignore(MgcpEndpoint ep, template MgcpCallId call_id := omit, |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 306 | template MgcpConnectionId conn_id := omit) runs on dummy_CT { |
Harald Welte | 10889c1 | 2017-11-18 19:40:31 +0100 | [diff] [blame] | 307 | f_dlcx(ep, ?, *, call_id, conn_id); |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 308 | } |
| 309 | |
Harald Welte | bb7523b | 2018-03-29 08:52:01 +0200 | [diff] [blame] | 310 | type record HostPort { |
| 311 | charstring hostname, |
| 312 | integer portnr optional |
| 313 | } |
| 314 | type record RtpFlowData { |
| 315 | HostPort em, /* emulation side */ |
| 316 | HostPort mgw, /* mgw side */ |
| 317 | uint7_t pt, |
| 318 | charstring codec, |
Philipp Maier | 28bb829 | 2018-07-20 17:09:17 +0200 | [diff] [blame] | 319 | MgcpConnectionId mgcp_conn_id optional, |
Philipp Maier | c8c0b40 | 2019-03-07 10:48:45 +0100 | [diff] [blame] | 320 | RtpemConfig rtp_cfg optional, |
Pau Espin Pedrol | b2c6b38 | 2019-05-14 13:40:49 +0200 | [diff] [blame] | 321 | boolean osmux_cid_sent, /* whther non wildcarded CID was already sent to MGW */ |
| 322 | MgcpOsmuxCID osmux_cid optional, |
| 323 | MgcpOsmuxCID osmux_cid_response optional, |
| 324 | OsmuxemConfig osmux_cfg optional, |
Philipp Maier | c8c0b40 | 2019-03-07 10:48:45 +0100 | [diff] [blame] | 325 | charstring fmtp optional |
Harald Welte | bb7523b | 2018-03-29 08:52:01 +0200 | [diff] [blame] | 326 | } |
| 327 | |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 328 | /* Create an RTP flow (bidirectional, or receive-only) */ |
| 329 | function f_flow_create(RTPEM_CTRL_PT pt, MgcpEndpoint ep, MgcpCallId call_id, charstring mode, inout RtpFlowData flow, |
Harald Welte | bb7523b | 2018-03-29 08:52:01 +0200 | [diff] [blame] | 330 | boolean one_phase := true) |
| 331 | runs on dummy_CT { |
Harald Welte | bb7523b | 2018-03-29 08:52:01 +0200 | [diff] [blame] | 332 | var template MgcpCommand cmd; |
| 333 | var MgcpResponse resp; |
Philipp Maier | c8c0b40 | 2019-03-07 10:48:45 +0100 | [diff] [blame] | 334 | var SDP_attribute_list attributes; |
| 335 | |
| 336 | attributes := { valueof(ts_SDP_rtpmap(flow.pt, flow.codec)), valueof(ts_SDP_ptime(20)) }; |
| 337 | if (isvalue(flow.fmtp)) { |
| 338 | attributes := attributes & { valueof(ts_SDP_fmtp(flow.pt, flow.fmtp)) }; |
| 339 | } |
Harald Welte | bb7523b | 2018-03-29 08:52:01 +0200 | [diff] [blame] | 340 | |
| 341 | /* bind local RTP emulation socket */ |
| 342 | f_rtpem_bind(pt, flow.em.hostname, flow.em.portnr); |
| 343 | |
Philipp Maier | 28bb829 | 2018-07-20 17:09:17 +0200 | [diff] [blame] | 344 | /* configure rtp-emulation */ |
| 345 | if (ispresent(flow.rtp_cfg)) { |
| 346 | f_rtpem_configure(pt, flow.rtp_cfg); |
| 347 | } else { |
| 348 | var RtpemConfig rtp_cfg := c_RtpemDefaultCfg; |
| 349 | rtp_cfg.tx_payload_type := flow.pt |
| 350 | f_rtpem_configure(pt, rtp_cfg); |
| 351 | } |
| 352 | |
Harald Welte | bb7523b | 2018-03-29 08:52:01 +0200 | [diff] [blame] | 353 | if (one_phase) { |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 354 | /* Connect flow to MGW using a CRCX that also contains an SDP |
| 355 | * part that tells the MGW where we are listening for RTP streams |
| 356 | * that come from the MGW. We get a fully working connection in |
| 357 | * one go. */ |
| 358 | |
| 359 | cmd := ts_CRCX(get_next_trans_id(), ep, mode, call_id); |
Harald Welte | edc8874 | 2018-03-29 18:01:16 +0200 | [diff] [blame] | 360 | cmd.sdp := ts_SDP(flow.em.hostname, flow.em.hostname, "23", "42", |
Philipp Maier | c8c0b40 | 2019-03-07 10:48:45 +0100 | [diff] [blame] | 361 | flow.em.portnr, { int2str(flow.pt) }, attributes); |
| 362 | |
Harald Welte | bb7523b | 2018-03-29 08:52:01 +0200 | [diff] [blame] | 363 | resp := mgcp_transceive_mgw(cmd, tr_CRCX_ACK); |
| 364 | flow.mgcp_conn_id := extract_conn_id(resp); |
| 365 | /* extract port number from response */ |
| 366 | flow.mgw.portnr := |
| 367 | resp.sdp.media_list[0].media_field.ports.port_number; |
| 368 | } else { |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 369 | /* Create a half-open connection only. We do not tell the MGW |
| 370 | * where it can send RTP streams to us. This means this |
| 371 | * connection will only be able to receive but can not send |
| 372 | * data back to us. In order to turn the connection in a fully |
| 373 | * bi-directional one, a separate MDCX is needed. */ |
| 374 | |
| 375 | cmd := ts_CRCX(get_next_trans_id(), ep, mode, call_id); |
Harald Welte | bb7523b | 2018-03-29 08:52:01 +0200 | [diff] [blame] | 376 | resp := mgcp_transceive_mgw(cmd, tr_CRCX_ACK); |
| 377 | flow.mgcp_conn_id := extract_conn_id(resp); |
| 378 | /* extract MGW-side port number from response */ |
| 379 | flow.mgw.portnr := |
| 380 | resp.sdp.media_list[0].media_field.ports.port_number; |
Harald Welte | bb7523b | 2018-03-29 08:52:01 +0200 | [diff] [blame] | 381 | } |
| 382 | /* finally, connect the emulation-side RTP socket to the MGW */ |
| 383 | f_rtpem_connect(pt, flow.mgw.hostname, flow.mgw.portnr); |
| 384 | } |
| 385 | |
Pau Espin Pedrol | b2c6b38 | 2019-05-14 13:40:49 +0200 | [diff] [blame] | 386 | /* Create an Osmux flow (bidirectional, or receive-only) */ |
| 387 | function f_flow_create_osmux(OsmuxEM_CTRL_PT pt, MgcpEndpoint ep, MgcpCallId call_id, charstring mode, inout RtpFlowData flow, |
| 388 | boolean one_phase := true) |
| 389 | runs on dummy_CT { |
| 390 | var template MgcpCommand cmd; |
| 391 | var MgcpResponse resp; |
| 392 | var SDP_attribute_list attributes; |
| 393 | var OsmuxTxHandle tx_hdl; |
| 394 | var OsmuxRxHandle rx_hdl; |
| 395 | var charstring cid_response; |
| 396 | var OsmuxCID cid_resp_parsed |
| 397 | |
| 398 | attributes := { valueof(ts_SDP_rtpmap(flow.pt, flow.codec)), valueof(ts_SDP_ptime(20)) }; |
| 399 | if (isvalue(flow.fmtp)) { |
| 400 | attributes := attributes & { valueof(ts_SDP_fmtp(flow.pt, flow.fmtp)) }; |
| 401 | } |
| 402 | |
| 403 | /* bind local Osmux emulation socket */ |
| 404 | f_osmuxem_bind(pt, flow.em.hostname, flow.em.portnr); |
| 405 | |
| 406 | /* configure osmux-emulation */ |
| 407 | if (ispresent(flow.osmux_cfg)) { |
| 408 | f_osmuxem_configure(pt, flow.osmux_cfg); |
| 409 | } else { |
| 410 | var OsmuxemConfig osmux_cfg := c_OsmuxemDefaultCfg; |
| 411 | f_osmuxem_configure(pt, osmux_cfg); |
| 412 | flow.osmux_cfg := osmux_cfg |
| 413 | } |
| 414 | |
| 415 | if (one_phase) { |
| 416 | /* Connect flow to MGW using a CRCX that also contains an SDP |
| 417 | * part that tells the MGW where we are listening for Osmux streams |
| 418 | * that come from the MGW. We get a fully working connection in |
| 419 | * one go. */ |
| 420 | rx_hdl := c_OsmuxemDefaultRxHandle; |
| 421 | rx_hdl.cid := flow.osmux_cid; |
| 422 | f_osmuxem_register_rxhandle(pt, rx_hdl); |
| 423 | flow.osmux_cid_sent := true; |
| 424 | cmd := ts_CRCX_osmux(get_next_trans_id(), ep, mode, call_id, flow.osmux_cid); |
| 425 | cmd.sdp := ts_SDP(flow.em.hostname, flow.em.hostname, "23", "42", |
| 426 | flow.em.portnr, { int2str(flow.pt) }, attributes); |
| 427 | resp := mgcp_transceive_mgw(cmd, tr_CRCX_ACK_osmux); |
| 428 | flow.mgcp_conn_id := extract_conn_id(resp); |
| 429 | /* extract port number from response */ |
| 430 | flow.mgw.portnr := |
| 431 | resp.sdp.media_list[0].media_field.ports.port_number; |
| 432 | } else { |
| 433 | /* Create a half-open connection only. We do not tell the MGW |
| 434 | * where it can send Osmux streams to us. This means this |
| 435 | * connection will only be able to receive but can not send |
| 436 | * data back to us. In order to turn the connection in a fully |
| 437 | * bi-directional one, a separate MDCX is needed. */ |
| 438 | |
| 439 | cmd := ts_CRCX_osmux(get_next_trans_id(), ep, mode, call_id, flow.osmux_cid); |
| 440 | resp := mgcp_transceive_mgw(cmd, tr_CRCX_ACK_osmux); |
| 441 | |
| 442 | flow.mgcp_conn_id := extract_conn_id(resp); |
| 443 | /* extract MGW-side port number from response */ |
| 444 | flow.mgw.portnr := |
| 445 | resp.sdp.media_list[0].media_field.ports.port_number; |
| 446 | } |
| 447 | |
| 448 | /* extract Osmux CID we got assigned by the MGW */ |
| 449 | var MgcpMessage resp_msg := { |
| 450 | response := resp |
| 451 | } |
| 452 | |
| 453 | if (f_mgcp_find_param(resp_msg, "X-OSMUX", cid_response) == false) { |
| 454 | setverdict(fail, "No Osmux CID in MGCP response", resp); |
| 455 | mtc.stop; |
| 456 | } |
| 457 | |
| 458 | /* Make sure response is no wildcard */ |
| 459 | flow.osmux_cid_response := f_mgcp_osmux_cid_decode(cid_response); |
| 460 | if (flow.osmux_cid_response == -1) { |
| 461 | setverdict(fail, "Osmux CID in MGCP response contains unexpected wildcard"); |
| 462 | mtc.stop; |
| 463 | } |
| 464 | tx_hdl := valueof(t_TxHandleAMR590(flow.osmux_cid_response)); |
| 465 | f_osmuxem_register_txhandle(pt, tx_hdl); |
| 466 | |
| 467 | /* finally, connect the emulation-side RTP socket to the MGW */ |
| 468 | f_osmuxem_connect(pt, flow.mgw.hostname, flow.mgw.portnr); |
| 469 | } |
| 470 | |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 471 | /* Modify an existing RTP flow */ |
| 472 | function f_flow_modify(RTPEM_CTRL_PT pt, MgcpEndpoint ep, MgcpCallId call_id, charstring mode, inout RtpFlowData flow) |
| 473 | runs on dummy_CT { |
| 474 | var template MgcpCommand cmd; |
| 475 | var MgcpResponse resp; |
Philipp Maier | c8c0b40 | 2019-03-07 10:48:45 +0100 | [diff] [blame] | 476 | var SDP_attribute_list attributes; |
| 477 | |
| 478 | attributes := { valueof(ts_SDP_rtpmap(flow.pt, flow.codec)), valueof(ts_SDP_ptime(20)) }; |
| 479 | if (isvalue(flow.fmtp)) { |
| 480 | attributes := attributes & { valueof(ts_SDP_fmtp(flow.pt, flow.fmtp)) }; |
| 481 | } |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 482 | |
| 483 | /* rebind local RTP emulation socket to the new address */ |
| 484 | f_rtpem_bind(pt, flow.em.hostname, flow.em.portnr); |
| 485 | |
Philipp Maier | 28bb829 | 2018-07-20 17:09:17 +0200 | [diff] [blame] | 486 | /* reconfigure rtp-emulation */ |
| 487 | if (ispresent(flow.rtp_cfg)) { |
| 488 | f_rtpem_configure(pt, flow.rtp_cfg); |
| 489 | } else { |
| 490 | var RtpemConfig rtp_cfg := c_RtpemDefaultCfg; |
| 491 | rtp_cfg.tx_payload_type := flow.pt |
| 492 | f_rtpem_configure(pt, rtp_cfg); |
| 493 | } |
| 494 | |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 495 | /* connect MGW side RTP socket to the emulation-side RTP socket using SDP */ |
| 496 | cmd := ts_MDCX(get_next_trans_id(), ep, mode, call_id, flow.mgcp_conn_id); |
| 497 | cmd.sdp := ts_SDP(flow.em.hostname, flow.em.hostname, "23", "42", |
Philipp Maier | c8c0b40 | 2019-03-07 10:48:45 +0100 | [diff] [blame] | 498 | flow.em.portnr, { int2str(flow.pt) }, attributes); |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 499 | resp := mgcp_transceive_mgw(cmd, tr_MDCX_ACK); |
| 500 | |
| 501 | /* extract MGW-side port number from response. (usually this |
| 502 | * will not change, but thats is up to the MGW) */ |
| 503 | flow.mgw.portnr := |
| 504 | resp.sdp.media_list[0].media_field.ports.port_number; |
| 505 | |
| 506 | /* reconnect the emulation-side RTP socket to the MGW */ |
| 507 | f_rtpem_connect(pt, flow.mgw.hostname, flow.mgw.portnr); |
| 508 | } |
| 509 | |
Pau Espin Pedrol | b2c6b38 | 2019-05-14 13:40:49 +0200 | [diff] [blame] | 510 | /* Modify an existing Osmux flow */ |
| 511 | function f_flow_modify_osmux(OsmuxEM_CTRL_PT pt, MgcpEndpoint ep, MgcpCallId call_id, charstring mode, inout RtpFlowData flow) |
| 512 | runs on dummy_CT { |
| 513 | var template MgcpCommand cmd; |
| 514 | var MgcpResponse resp; |
| 515 | var SDP_attribute_list attributes; |
| 516 | var OsmuxRxHandle rx_hdl; |
| 517 | var charstring cid_response; |
| 518 | var OsmuxCID cid_resp_parsed |
| 519 | |
| 520 | attributes := { valueof(ts_SDP_rtpmap(flow.pt, flow.codec)), valueof(ts_SDP_ptime(20)) }; |
| 521 | if (isvalue(flow.fmtp)) { |
| 522 | attributes := attributes & { valueof(ts_SDP_fmtp(flow.pt, flow.fmtp)) }; |
| 523 | } |
| 524 | |
| 525 | /* rebind local Osmux emulation socket to the new address */ |
| 526 | f_osmuxem_bind(pt, flow.em.hostname, flow.em.portnr); |
| 527 | |
| 528 | /* configure osmux-emulation */ |
| 529 | if (ispresent(flow.osmux_cfg)) { |
| 530 | f_osmuxem_configure(pt, flow.osmux_cfg); |
| 531 | } else { |
| 532 | var OsmuxemConfig osmux_cfg := c_OsmuxemDefaultCfg; |
| 533 | f_osmuxem_configure(pt, osmux_cfg); |
| 534 | } |
| 535 | |
| 536 | /* We didn't send a non-wildcarded Osmux CID yet. If caller wants to submit it, register handler */ |
| 537 | if (flow.osmux_cid_sent == false and flow.osmux_cid != -1) { |
| 538 | rx_hdl := c_OsmuxemDefaultRxHandle; |
| 539 | rx_hdl.cid := flow.osmux_cid; |
| 540 | f_osmuxem_register_rxhandle(pt, rx_hdl); |
| 541 | flow.osmux_cid_sent := true; |
| 542 | } |
| 543 | |
| 544 | /* connect MGW side Osmux socket to the emulation-side Osmux socket using SDP */ |
| 545 | cmd := ts_MDCX_osmux(get_next_trans_id(), ep, mode, call_id, flow.mgcp_conn_id, flow.osmux_cid); |
| 546 | cmd.sdp := ts_SDP(flow.em.hostname, flow.em.hostname, "23", "42", |
| 547 | flow.em.portnr, { int2str(flow.pt) }, attributes); |
| 548 | resp := mgcp_transceive_mgw(cmd, tr_MDCX_ACK); |
| 549 | |
| 550 | /* extract MGW-side port number from response. (usually this |
| 551 | * will not change, but thats is up to the MGW) */ |
| 552 | flow.mgw.portnr := |
| 553 | resp.sdp.media_list[0].media_field.ports.port_number; |
| 554 | |
| 555 | /* extract Osmux CID we got assigned by the MGW */ |
| 556 | var MgcpMessage resp_msg := { |
| 557 | response := resp |
| 558 | } |
| 559 | |
| 560 | if (f_mgcp_find_param(resp_msg, "X-OSMUX", cid_response) == false) { |
| 561 | setverdict(fail, "No Osmux CID in MGCP response", resp); |
| 562 | mtc.stop; |
| 563 | } |
| 564 | |
| 565 | /* Make sure response is no wildcard */ |
| 566 | cid_resp_parsed := f_mgcp_osmux_cid_decode(cid_response); |
| 567 | if (cid_resp_parsed == -1) { |
| 568 | setverdict(fail, "Osmux CID in MGCP response contains unexpected wildcard"); |
| 569 | mtc.stop; |
| 570 | } |
| 571 | if (cid_resp_parsed != flow.osmux_cid_response) { |
| 572 | setverdict(fail, "Osmux CID in MGCP MDCX response changed from prev value"); |
| 573 | mtc.stop; |
| 574 | } |
| 575 | |
| 576 | /* reconnect the emulation-side Osmux socket to the MGW */ |
| 577 | f_osmuxem_connect(pt, flow.mgw.hostname, flow.mgw.portnr); |
| 578 | } |
| 579 | |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 580 | /* Delete an existing RTP flow */ |
| 581 | function f_flow_delete(RTPEM_CTRL_PT pt, template MgcpEndpoint ep := omit, template MgcpCallId call_id := omit) |
| 582 | runs on dummy_CT { |
| 583 | var template MgcpCommand cmd; |
| 584 | var MgcpResponse resp; |
| 585 | |
| 586 | /* Switch off RTP flow */ |
| 587 | f_rtpem_mode(pt, RTPEM_MODE_NONE); |
| 588 | |
| 589 | /* Delete connection on MGW (if needed) */ |
| 590 | if (isvalue(call_id) and isvalue(ep)) { |
| 591 | f_sleep(0.1); |
| 592 | f_dlcx_ok(valueof(ep), call_id); |
| 593 | } |
| 594 | } |
| 595 | |
Pau Espin Pedrol | b2c6b38 | 2019-05-14 13:40:49 +0200 | [diff] [blame] | 596 | /* Delete an existing Osmux flow */ |
| 597 | function f_flow_delete_osmux(OsmuxEM_CTRL_PT pt, template MgcpEndpoint ep := omit, template MgcpCallId call_id := omit) |
| 598 | runs on dummy_CT { |
| 599 | var template MgcpCommand cmd; |
| 600 | var MgcpResponse resp; |
| 601 | |
| 602 | /* Switch off Osmux flow */ |
| 603 | f_osmuxem_mode(pt, OSMUXEM_MODE_NONE); |
| 604 | |
| 605 | /* Delete connection on MGW (if needed) */ |
| 606 | if (isvalue(call_id) and isvalue(ep)) { |
| 607 | f_sleep(0.1); |
| 608 | f_dlcx_ok(valueof(ep), call_id); |
| 609 | } |
| 610 | } |
| 611 | |
Philipp Maier | bb7a01c | 2018-02-01 12:32:57 +0100 | [diff] [blame] | 612 | function f_crcx(charstring ep_prefix) runs on dummy_CT { |
| 613 | var MgcpEndpoint ep := ep_prefix & "2@" & c_mgw_domain; |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 614 | var template MgcpCommand cmd; |
| 615 | var MgcpResponse resp; |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 616 | var MgcpCallId call_id := '1234'H; |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 617 | |
Harald Welte | edc45c1 | 2017-11-18 19:15:05 +0100 | [diff] [blame] | 618 | f_init(ep); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 619 | |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 620 | /* create the connection on the MGW */ |
| 621 | cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id); |
Harald Welte | 9988d28 | 2017-11-18 19:22:00 +0100 | [diff] [blame] | 622 | resp := mgcp_transceive_mgw(cmd, tr_CRCX_ACK); |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 623 | extract_conn_id(resp); |
| 624 | |
| 625 | /* clean-up */ |
| 626 | f_dlcx_ok(ep, call_id); |
Philipp Maier | bb7a01c | 2018-02-01 12:32:57 +0100 | [diff] [blame] | 627 | } |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 628 | |
Philipp Maier | 45635f4 | 2018-06-05 17:28:02 +0200 | [diff] [blame] | 629 | function f_crcx_no_lco(charstring ep_prefix) runs on dummy_CT { |
| 630 | var MgcpEndpoint ep := ep_prefix & "2@" & c_mgw_domain; |
| 631 | var template MgcpCommand cmd; |
| 632 | var MgcpResponse resp; |
| 633 | var MgcpCallId call_id := '1234'H; |
| 634 | |
| 635 | f_init(ep); |
| 636 | |
| 637 | /* create the connection on the MGW */ |
| 638 | cmd := ts_CRCX_no_lco(get_next_trans_id(), ep, "recvonly", call_id); |
| 639 | resp := mgcp_transceive_mgw(cmd, tr_CRCX_ACK); |
| 640 | extract_conn_id(resp); |
| 641 | |
| 642 | /* clean-up */ |
| 643 | f_dlcx_ok(ep, call_id); |
| 644 | |
| 645 | /* See also OS#2658: Even when we omit the LCO information, we |
| 646 | expect the MGW to pick a sane payload type for us. This |
| 647 | payload type should be visible in the SDP of the response. */ |
Philipp Maier | 76a8d01 | 2018-06-21 10:03:13 +0200 | [diff] [blame] | 648 | if (resp.sdp.media_list[0].media_field.fmts[0] != "0") { |
Philipp Maier | 45635f4 | 2018-06-05 17:28:02 +0200 | [diff] [blame] | 649 | setverdict(fail, "SDP contains unexpected codec"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 650 | mtc.stop; |
Philipp Maier | 45635f4 | 2018-06-05 17:28:02 +0200 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | /* See also OS#2658: We also expect the MGW to assign a port |
| 654 | number to us. */ |
| 655 | if (isbound(resp.sdp.media_list[0].media_field.ports.port_number) == false) { |
| 656 | setverdict(fail, "SDP does not contain a port number"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 657 | mtc.stop; |
Philipp Maier | 45635f4 | 2018-06-05 17:28:02 +0200 | [diff] [blame] | 658 | } |
| 659 | } |
| 660 | |
Pau Espin Pedrol | b2c6b38 | 2019-05-14 13:40:49 +0200 | [diff] [blame] | 661 | function f_crcx_osmux(charstring ep_prefix, MgcpOsmuxCID osmux_cid, boolean run_init := true) runs on dummy_CT { |
| 662 | var MgcpEndpoint ep := ep_prefix & "2@" & c_mgw_domain; |
| 663 | var template MgcpCommand cmd; |
| 664 | var MgcpResponse resp; |
| 665 | var MgcpCallId call_id := '1234'H; |
| 666 | var charstring cid_response; |
| 667 | |
| 668 | if (run_init) { |
| 669 | f_init(ep, true); |
| 670 | } |
| 671 | |
| 672 | /* create the connection on the MGW */ |
| 673 | cmd := ts_CRCX_osmux(get_next_trans_id(), ep, "recvonly", call_id, osmux_cid); |
| 674 | resp := mgcp_transceive_mgw(cmd, tr_CRCX_ACK_osmux); |
| 675 | extract_conn_id(resp); |
| 676 | |
| 677 | /* extract Osmux CID we got assigned by the MGW */ |
| 678 | var MgcpMessage resp_msg := { |
| 679 | response := resp |
| 680 | } |
| 681 | |
| 682 | if (f_mgcp_find_param(resp_msg, "X-OSMUX", cid_response) == false) { |
| 683 | setverdict(fail, "No Osmux CID in MGCP response", resp); |
| 684 | mtc.stop; |
| 685 | } |
| 686 | |
| 687 | /* Make sure response is no wildcard */ |
| 688 | if (f_mgcp_osmux_cid_decode(cid_response) == -1) { |
| 689 | setverdict(fail, "Osmux CID in MGCP response contains unexpected wildcard"); |
| 690 | mtc.stop; |
| 691 | } |
| 692 | |
| 693 | /* clean-up */ |
| 694 | f_dlcx_ok(ep, call_id); |
| 695 | } |
| 696 | |
Philipp Maier | bb7a01c | 2018-02-01 12:32:57 +0100 | [diff] [blame] | 697 | /* test valid CRCX without SDP */ |
| 698 | testcase TC_crcx() runs on dummy_CT { |
| 699 | f_crcx(c_mgw_ep_rtpbridge); |
| 700 | setverdict(pass); |
| 701 | } |
| 702 | |
Philipp Maier | 45635f4 | 2018-06-05 17:28:02 +0200 | [diff] [blame] | 703 | /* test valid CRCX without SDP and LCO */ |
| 704 | testcase TC_crcx_no_lco() runs on dummy_CT { |
| 705 | f_crcx_no_lco(c_mgw_ep_rtpbridge); |
| 706 | setverdict(pass); |
| 707 | } |
| 708 | |
Philipp Maier | bb7a01c | 2018-02-01 12:32:57 +0100 | [diff] [blame] | 709 | /* test valid CRCX without SDP (older method without endpoint prefix) */ |
| 710 | testcase TC_crcx_noprefix() runs on dummy_CT { |
| 711 | f_crcx(""); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 712 | setverdict(pass); |
| 713 | } |
| 714 | |
| 715 | /* test CRCX with unsupported mode, expect 517 */ |
| 716 | testcase TC_crcx_unsupp_mode() runs on dummy_CT { |
| 717 | var template MgcpCommand cmd; |
| 718 | var MgcpResponse resp; |
Philipp Maier | bb7a01c | 2018-02-01 12:32:57 +0100 | [diff] [blame] | 719 | var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "2@" & c_mgw_domain; |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 720 | var MgcpCallId call_id := '1233'H; |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 721 | var template MgcpResponse rtmpl := tr_MgcpResp_Err("517"); |
| 722 | |
Harald Welte | edc45c1 | 2017-11-18 19:15:05 +0100 | [diff] [blame] | 723 | f_init(ep); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 724 | |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 725 | cmd := ts_CRCX(get_next_trans_id(), ep, "netwtest", call_id); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 726 | resp := mgcp_transceive_mgw(cmd, rtmpl); |
| 727 | setverdict(pass); |
| 728 | } |
| 729 | |
Harald Welte | 21ba557 | 2017-09-19 17:55:05 +0800 | [diff] [blame] | 730 | /* test CRCX with early bi-directional mode, expect 527 as |
| 731 | * bi-diretional media can only be established once both local and |
| 732 | * remote side are specified, see MGCP RFC */ |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 733 | testcase TC_crcx_early_bidir_mode() runs on dummy_CT { |
| 734 | var template MgcpCommand cmd; |
| 735 | var MgcpResponse resp; |
Philipp Maier | bb7a01c | 2018-02-01 12:32:57 +0100 | [diff] [blame] | 736 | var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "2@" & c_mgw_domain; |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 737 | var MgcpCallId call_id := '1232'H; |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 738 | var template MgcpResponse rtmpl := tr_MgcpResp_Err("527"); |
| 739 | |
Harald Welte | edc45c1 | 2017-11-18 19:15:05 +0100 | [diff] [blame] | 740 | f_init(ep); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 741 | |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 742 | cmd := ts_CRCX(get_next_trans_id(), ep, "sendrecv", call_id); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 743 | resp := mgcp_transceive_mgw(cmd, rtmpl); |
| 744 | setverdict(pass); |
| 745 | } |
| 746 | |
| 747 | /* test CRCX with unsupported Parameters */ |
| 748 | testcase TC_crcx_unsupp_param() runs on dummy_CT { |
| 749 | var template MgcpCommand cmd; |
| 750 | var MgcpResponse resp; |
Philipp Maier | bb7a01c | 2018-02-01 12:32:57 +0100 | [diff] [blame] | 751 | var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "2@" & c_mgw_domain; |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 752 | var MgcpCallId call_id := '1231'H; |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 753 | var template MgcpResponse rtmpl := tr_MgcpResp_Err("539"); |
| 754 | |
Harald Welte | edc45c1 | 2017-11-18 19:15:05 +0100 | [diff] [blame] | 755 | f_init(ep); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 756 | |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 757 | cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id); |
Harald Welte | a01e38d | 2017-11-18 18:40:01 +0100 | [diff] [blame] | 758 | /* osmo-bsc_mgcp/mgw doesn't implement notifications */ |
| 759 | f_mgcp_par_append(cmd.params, MgcpParameter:{ "N", "foobar" }); |
| 760 | |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 761 | resp := mgcp_transceive_mgw(cmd, rtmpl); |
| 762 | setverdict(pass); |
| 763 | } |
| 764 | |
| 765 | /* test CRCX with missing CallId */ |
| 766 | testcase TC_crcx_missing_callid() runs on dummy_CT { |
| 767 | var template MgcpCommand cmd; |
| 768 | var MgcpResponse resp; |
Philipp Maier | bb7a01c | 2018-02-01 12:32:57 +0100 | [diff] [blame] | 769 | var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "2@" & c_mgw_domain; |
Harald Welte | f91edf3 | 2017-12-28 14:16:21 +0100 | [diff] [blame] | 770 | var template MgcpResponse rtmpl := tr_MgcpResp_Err(("400","516")); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 771 | |
Harald Welte | edc45c1 | 2017-11-18 19:15:05 +0100 | [diff] [blame] | 772 | f_init(ep); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 773 | |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 774 | cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", '1230'H); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 775 | cmd.params := { |
| 776 | t_MgcpParConnMode("recvonly"), |
| 777 | t_MgcpParLocConnOpt("p:20") |
| 778 | } |
| 779 | resp := mgcp_transceive_mgw(cmd, rtmpl); |
| 780 | setverdict(pass); |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 781 | |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | /* test CRCX with missing Mode */ |
| 785 | testcase TC_crcx_missing_mode() runs on dummy_CT { |
| 786 | var template MgcpCommand cmd; |
| 787 | var MgcpResponse resp; |
Philipp Maier | bb7a01c | 2018-02-01 12:32:57 +0100 | [diff] [blame] | 788 | var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "2@" & c_mgw_domain; |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 789 | var MgcpCallId call_id := '1229'H; |
Harald Welte | f91edf3 | 2017-12-28 14:16:21 +0100 | [diff] [blame] | 790 | var template MgcpResponse rtmpl := tr_MgcpResp_Err(("400","517")); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 791 | |
Harald Welte | edc45c1 | 2017-11-18 19:15:05 +0100 | [diff] [blame] | 792 | f_init(ep); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 793 | |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 794 | cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 795 | cmd.params := { |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 796 | ts_MgcpParCallId(call_id), |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 797 | t_MgcpParLocConnOpt("p:20") |
| 798 | } |
| 799 | resp := mgcp_transceive_mgw(cmd, rtmpl); |
| 800 | setverdict(pass); |
| 801 | } |
| 802 | |
| 803 | /* test CRCX with unsupported packetization interval */ |
| 804 | testcase TC_crcx_unsupp_packet_intv() runs on dummy_CT { |
| 805 | var template MgcpCommand cmd; |
| 806 | var MgcpResponse resp; |
Philipp Maier | bb7a01c | 2018-02-01 12:32:57 +0100 | [diff] [blame] | 807 | var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "2@" & c_mgw_domain; |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 808 | var MgcpCallId call_id := '1228'H; |
Harald Welte | 0d19861 | 2017-11-18 19:58:31 +0100 | [diff] [blame] | 809 | var template MgcpResponse rtmpl := tr_MgcpResp_Err("535"); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 810 | |
Harald Welte | edc45c1 | 2017-11-18 19:15:05 +0100 | [diff] [blame] | 811 | f_init(ep); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 812 | |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 813 | cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id); |
Harald Welte | a01e38d | 2017-11-18 18:40:01 +0100 | [diff] [blame] | 814 | cmd.params[2] := t_MgcpParLocConnOpt("p:111"); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 815 | resp := mgcp_transceive_mgw(cmd, rtmpl); |
| 816 | setverdict(pass); |
| 817 | } |
| 818 | |
| 819 | /* test CRCX with illegal double presence of local connection option */ |
| 820 | testcase TC_crcx_illegal_double_lco() runs on dummy_CT { |
| 821 | var template MgcpCommand cmd; |
| 822 | var MgcpResponse resp; |
Philipp Maier | bb7a01c | 2018-02-01 12:32:57 +0100 | [diff] [blame] | 823 | var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "2@" & c_mgw_domain; |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 824 | var MgcpCallId call_id := '1227'H; |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 825 | var template MgcpResponse rtmpl := tr_MgcpResp_Err("524"); |
| 826 | |
Harald Welte | edc45c1 | 2017-11-18 19:15:05 +0100 | [diff] [blame] | 827 | f_init(ep); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 828 | |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 829 | cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id); |
Harald Welte | a01e38d | 2017-11-18 18:40:01 +0100 | [diff] [blame] | 830 | /* p:20 is permitted only once and not twice! */ |
| 831 | cmd.params[2] := t_MgcpParLocConnOpt("p:20, a:AMR, p:20"); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 832 | resp := mgcp_transceive_mgw(cmd, rtmpl); |
| 833 | setverdict(pass); |
| 834 | } |
| 835 | |
| 836 | /* test valid CRCX with valid SDP */ |
| 837 | testcase TC_crcx_sdp() runs on dummy_CT { |
| 838 | var template MgcpCommand cmd; |
| 839 | var MgcpResponse resp; |
Philipp Maier | bb7a01c | 2018-02-01 12:32:57 +0100 | [diff] [blame] | 840 | var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "2@" & c_mgw_domain; |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 841 | var MgcpCallId call_id := '1226'H; |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 842 | |
Harald Welte | edc45c1 | 2017-11-18 19:15:05 +0100 | [diff] [blame] | 843 | f_init(ep); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 844 | |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 845 | cmd := ts_CRCX(get_next_trans_id(), ep, "sendrecv", call_id); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 846 | cmd.sdp := ts_SDP("127.0.0.1", "127.0.0.2", "23", "42", 2344, { "98" }, |
| 847 | { valueof(ts_SDP_rtpmap(98, "AMR/8000")), |
| 848 | valueof(ts_SDP_ptime(20)) }); |
Harald Welte | 9988d28 | 2017-11-18 19:22:00 +0100 | [diff] [blame] | 849 | resp := mgcp_transceive_mgw(cmd, tr_CRCX_ACK); |
Philipp Maier | dffa6a4 | 2018-02-02 11:55:44 +0100 | [diff] [blame] | 850 | |
| 851 | /* clean-up */ |
| 852 | f_dlcx_ok(ep, call_id); |
| 853 | |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 854 | setverdict(pass); |
| 855 | } |
| 856 | |
Philipp Maier | 5e06cee | 2018-02-01 18:28:08 +0100 | [diff] [blame] | 857 | /* test valid wildcarded CRCX */ |
| 858 | testcase TC_crcx_wildcarded() runs on dummy_CT { |
| 859 | var template MgcpCommand cmd; |
| 860 | var MgcpResponse resp; |
| 861 | var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "*@" & c_mgw_domain; |
| 862 | var MgcpCallId call_id := '1234'H; |
| 863 | var MgcpEndpoint ep_assigned; |
| 864 | f_init(); |
| 865 | |
| 866 | /* create the connection on the MGW */ |
| 867 | cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id); |
| 868 | resp := mgcp_transceive_mgw(cmd, tr_CRCX_ACK); |
| 869 | extract_conn_id(resp); |
| 870 | |
| 871 | /* extract endpoint name we got assigned by the MGW */ |
| 872 | var MgcpMessage resp_msg := { |
| 873 | response := resp |
| 874 | } |
| 875 | if (f_mgcp_find_param(resp_msg, "Z", ep_assigned) == false) { |
| 876 | setverdict(fail, "No SpecificEndpointName in MGCP response", resp); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 877 | mtc.stop; |
Philipp Maier | 5e06cee | 2018-02-01 18:28:08 +0100 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | /* clean-up */ |
| 881 | f_dlcx_ok(ep_assigned, call_id); |
| 882 | |
| 883 | setverdict(pass); |
| 884 | } |
| 885 | |
| 886 | /* test valid wildcarded CRCX */ |
| 887 | testcase TC_crcx_wildcarded_exhaust() runs on dummy_CT { |
Philipp Maier | c60e847 | 2020-07-08 12:57:13 +0200 | [diff] [blame] | 888 | const integer n_endpoints := 31; |
Philipp Maier | 5e06cee | 2018-02-01 18:28:08 +0100 | [diff] [blame] | 889 | var integer i; |
| 890 | var template MgcpCommand cmd; |
| 891 | var MgcpResponse resp; |
| 892 | var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "*@" & c_mgw_domain; |
| 893 | var MgcpCallId call_id := '1234'H; |
| 894 | var MgcpEndpoint ep_assigned[n_endpoints]; |
| 895 | f_init(); |
| 896 | |
| 897 | /* Exhaust all endpoint resources on the virtual trunk */ |
| 898 | for (i := 0; i < n_endpoints; i := i+1) { |
| 899 | cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id); |
| 900 | resp := mgcp_transceive_mgw(cmd, tr_CRCX_ACK); |
| 901 | |
| 902 | /* Make sure we got a connection id */ |
| 903 | extract_conn_id(resp); |
| 904 | |
| 905 | var MgcpMessage resp_msg := { |
| 906 | response := resp |
| 907 | } |
| 908 | if (f_mgcp_find_param(resp_msg, "Z", ep_assigned[i]) == false) { |
| 909 | setverdict(fail, "No SpecificEndpointName in MGCP response", resp); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 910 | mtc.stop; |
Philipp Maier | 5e06cee | 2018-02-01 18:28:08 +0100 | [diff] [blame] | 911 | } |
| 912 | } |
| 913 | |
| 914 | /* Try to allocate one more endpoint, which should fail */ |
| 915 | cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id); |
| 916 | var template MgcpResponse rtmpl := tr_MgcpResp_Err("403"); |
| 917 | resp := mgcp_transceive_mgw(cmd, rtmpl); |
| 918 | setverdict(pass); |
| 919 | |
| 920 | /* clean-up */ |
| 921 | for (i := 0; i < n_endpoints; i := i+1) { |
| 922 | f_dlcx_ok(ep_assigned[i], call_id); |
| 923 | } |
| 924 | setverdict(pass); |
| 925 | } |
| 926 | |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 927 | /* TODO: various SDP related bits */ |
| 928 | |
| 929 | |
| 930 | /* TODO: CRCX with X-Osmux */ |
| 931 | /* TODO: double CRCX without force_realloc */ |
| 932 | |
| 933 | /* TODO: MDCX (various) */ |
| 934 | |
| 935 | /* TODO: MDCX without CRCX first */ |
| 936 | testcase TC_mdcx_without_crcx() runs on dummy_CT { |
| 937 | var template MgcpCommand cmd; |
| 938 | var MgcpResponse resp; |
Philipp Maier | bb7a01c | 2018-02-01 12:32:57 +0100 | [diff] [blame] | 939 | var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "3@" & c_mgw_domain; |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 940 | var MgcpCallId call_id := '1225'H; |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 941 | var template MgcpResponse rtmpl := { |
| 942 | line := { |
| 943 | /* TODO: accept/enforce better error? */ |
| 944 | code := "400", |
| 945 | string := ? |
| 946 | }, |
| 947 | params:= { }, |
| 948 | sdp := omit |
| 949 | }; |
| 950 | |
Harald Welte | edc45c1 | 2017-11-18 19:15:05 +0100 | [diff] [blame] | 951 | f_init(ep); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 952 | |
Harald Welte | 2bcfd3a | 2017-11-18 22:14:35 +0100 | [diff] [blame] | 953 | cmd := ts_MDCX(get_next_trans_id(), ep, "sendrecv", call_id, call_id); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 954 | cmd.sdp := ts_SDP("127.0.0.1", "127.0.0.2", "23", "42", 2344, { "98" }, |
| 955 | { valueof(ts_SDP_rtpmap(98, "AMR/8000")), |
| 956 | valueof(ts_SDP_ptime(20)) }); |
| 957 | resp := mgcp_transceive_mgw(cmd, rtmpl); |
| 958 | setverdict(pass); |
| 959 | } |
| 960 | |
| 961 | /* DLCX without CRCX first */ |
| 962 | testcase TC_dlcx_without_crcx() runs on dummy_CT { |
| 963 | var template MgcpCommand cmd; |
| 964 | var MgcpResponse resp; |
Philipp Maier | bb7a01c | 2018-02-01 12:32:57 +0100 | [diff] [blame] | 965 | var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "4@" & c_mgw_domain; |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 966 | var template MgcpResponse rtmpl := { |
| 967 | line := { |
Harald Welte | f91edf3 | 2017-12-28 14:16:21 +0100 | [diff] [blame] | 968 | code := ("400", "515"), |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 969 | string := ? |
| 970 | }, |
| 971 | params:= { }, |
| 972 | sdp := omit |
| 973 | }; |
| 974 | |
Harald Welte | edc45c1 | 2017-11-18 19:15:05 +0100 | [diff] [blame] | 975 | f_init(ep); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 976 | |
Harald Welte | edc45c1 | 2017-11-18 19:15:05 +0100 | [diff] [blame] | 977 | cmd := ts_DLCX(get_next_trans_id(), ep, '41234'H); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 978 | resp := mgcp_transceive_mgw(cmd, rtmpl); |
| 979 | setverdict(pass); |
| 980 | } |
| 981 | |
Philipp Maier | 8a3dc92 | 2018-02-02 14:55:12 +0100 | [diff] [blame] | 982 | /* test valid wildcarded MDCX */ |
| 983 | testcase TC_mdcx_wildcarded() runs on dummy_CT { |
| 984 | /* Note: A wildcarded MDCX is not allowed, so we expect the |
| 985 | * MGW to reject this request */ |
| 986 | var template MgcpCommand cmd; |
| 987 | var MgcpResponse resp; |
| 988 | var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "*@" & c_mgw_domain; |
| 989 | var MgcpCallId call_id := '1225'H; |
| 990 | var template MgcpResponse rtmpl := { |
| 991 | line := { |
| 992 | /* TODO: accept/enforce better error? */ |
| 993 | code := "507", |
| 994 | string := ? |
| 995 | }, |
| 996 | params:= { }, |
| 997 | sdp := omit |
| 998 | }; |
| 999 | |
| 1000 | f_init(ep); |
| 1001 | |
| 1002 | cmd := ts_MDCX(get_next_trans_id(), ep, "sendrecv", call_id, call_id); |
| 1003 | cmd.sdp := ts_SDP("127.0.0.1", "127.0.0.2", "23", "42", 2344, { "98" }, |
| 1004 | { valueof(ts_SDP_rtpmap(98, "AMR/8000")), |
| 1005 | valueof(ts_SDP_ptime(20)) }); |
| 1006 | resp := mgcp_transceive_mgw(cmd, rtmpl); |
| 1007 | setverdict(pass); |
| 1008 | } |
| 1009 | |
| 1010 | /* test valid wildcarded DLCX */ |
| 1011 | testcase TC_dlcx_wildcarded() runs on dummy_CT { |
| 1012 | /* Note: A wildcarded DLCX is specified, but our MGW does not |
| 1013 | * support this feature so we expect the MGW to reject the |
| 1014 | * request */ |
| 1015 | var template MgcpCommand cmd; |
| 1016 | var MgcpResponse resp; |
| 1017 | var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "*@" & c_mgw_domain; |
| 1018 | var template MgcpResponse rtmpl := { |
| 1019 | line := { |
| 1020 | code := "507", |
| 1021 | string := ? |
| 1022 | }, |
| 1023 | params:= { }, |
| 1024 | sdp := omit |
| 1025 | }; |
| 1026 | |
| 1027 | f_init(ep); |
| 1028 | |
| 1029 | cmd := ts_DLCX(get_next_trans_id(), ep, '41234'H); |
| 1030 | resp := mgcp_transceive_mgw(cmd, rtmpl); |
| 1031 | setverdict(pass); |
| 1032 | } |
| 1033 | |
Harald Welte | 79181ff | 2017-11-18 19:26:11 +0100 | [diff] [blame] | 1034 | /* Test (valid) CRCX followed by (valid) DLCX containig EP+CallId+ConnId */ |
| 1035 | testcase TC_crcx_and_dlcx_ep_callid_connid() runs on dummy_CT { |
| 1036 | var template MgcpCommand cmd; |
| 1037 | var MgcpResponse resp; |
Philipp Maier | bb7a01c | 2018-02-01 12:32:57 +0100 | [diff] [blame] | 1038 | var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "5@" & c_mgw_domain; |
Harald Welte | 79181ff | 2017-11-18 19:26:11 +0100 | [diff] [blame] | 1039 | var MgcpCallId call_id := '51234'H; |
| 1040 | |
| 1041 | f_init(ep); |
| 1042 | |
| 1043 | cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id); |
| 1044 | resp := mgcp_transceive_mgw(cmd, tr_CRCX_ACK); |
| 1045 | |
| 1046 | f_dlcx_ok(ep, call_id, extract_conn_id(resp)); |
| 1047 | |
| 1048 | setverdict(pass); |
| 1049 | } |
| 1050 | |
Pau Espin Pedrol | b2c6b38 | 2019-05-14 13:40:49 +0200 | [diff] [blame] | 1051 | /* test valid CRCX without SDP */ |
| 1052 | testcase TC_crcx_osmux_wildcard() runs on dummy_CT { |
| 1053 | f_crcx_osmux(c_mgw_ep_rtpbridge, -1); |
| 1054 | setverdict(pass); |
| 1055 | } |
| 1056 | |
| 1057 | /* test valid CRCX without SDP */ |
| 1058 | testcase TC_crcx_osmux_fixed() runs on dummy_CT { |
| 1059 | f_crcx_osmux(c_mgw_ep_rtpbridge, 2); |
| 1060 | setverdict(pass); |
| 1061 | } |
| 1062 | |
| 1063 | /* test valid CRCX without SDP, twice, to make sure CID is freed fine during first step. */ |
| 1064 | testcase TC_crcx_osmux_fixed_twice() runs on dummy_CT { |
| 1065 | f_crcx_osmux(c_mgw_ep_rtpbridge, 3, true); |
| 1066 | f_crcx_osmux(c_mgw_ep_rtpbridge, 3, false); |
| 1067 | setverdict(pass); |
| 1068 | } |
| 1069 | |
| 1070 | /* Create one half open connection in receive-only mode. The MGW must accept |
| 1071 | * the packets but must not send any. */ |
| 1072 | testcase TC_one_crcx_receive_only_osmux() runs on dummy_CT { |
| 1073 | var RtpFlowData flow; |
| 1074 | var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "1@" & c_mgw_domain; |
| 1075 | var MgcpCallId call_id := '1225'H; |
| 1076 | var OsmuxemStats stats; |
| 1077 | var OsmuxTxHandle tx_hdl; |
| 1078 | |
| 1079 | f_init(ep, true); |
| 1080 | flow := valueof(t_RtpFlow(mp_local_ip, mp_remote_ip, 112, "AMR/8000/1")); |
| 1081 | flow.em.portnr := mp_local_osmux_port; |
| 1082 | flow.osmux_cid := -1; |
| 1083 | f_flow_create_osmux(OsmuxEM, ep, call_id, "recvonly", flow, false); |
| 1084 | |
| 1085 | /* create a transmitter not yet known by MGW */ |
| 1086 | tx_hdl := valueof(t_TxHandleAMR590(2)); |
| 1087 | f_osmuxem_register_txhandle(OsmuxEM, tx_hdl); |
| 1088 | |
| 1089 | f_osmuxem_mode(OsmuxEM, OSMUXEM_MODE_TXONLY); |
| 1090 | f_sleep(1.0); |
| 1091 | f_flow_delete_osmux(OsmuxEM, ep, call_id); |
| 1092 | |
| 1093 | stats := f_osmuxem_stats_get(OsmuxEM); |
| 1094 | |
| 1095 | if (stats.num_pkts_tx < 40 / flow.osmux_cfg.batch_size) { |
| 1096 | setverdict(fail); |
| 1097 | } |
| 1098 | if (stats.bytes_payload_tx < stats.num_pkts_tx * f_amrft_payload_len(tx_hdl.amr_ft) * flow.osmux_cfg.batch_size) { |
| 1099 | setverdict(fail); |
| 1100 | } |
| 1101 | |
| 1102 | f_osmuxem_stats_err_check(stats); |
| 1103 | |
| 1104 | setverdict(pass); |
| 1105 | } |
| 1106 | |
| 1107 | /* Create one connection in loopback mode, test if the Osmux packets are |
| 1108 | * actually reflected */ |
| 1109 | testcase TC_one_crcx_loopback_osmux() runs on dummy_CT { |
| 1110 | var RtpFlowData flow; |
| 1111 | var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "1@" & c_mgw_domain; |
| 1112 | var MgcpCallId call_id := '1225'H; |
| 1113 | var OsmuxemStats stats; |
| 1114 | var OsmuxTxHandle tx_hdl; |
| 1115 | |
| 1116 | f_init(ep, true); |
| 1117 | flow := valueof(t_RtpFlow(mp_local_ip, mp_remote_ip, 111, "GSM-HR-08/8000/1")); |
| 1118 | flow.em.portnr := mp_local_osmux_port; |
| 1119 | flow.osmux_cid := 2; |
| 1120 | f_flow_create_osmux(OsmuxEM, ep, call_id, "loopback", flow); |
| 1121 | |
| 1122 | f_osmuxem_mode(OsmuxEM, OSMUXEM_MODE_BIDIR); |
| 1123 | f_sleep(1.0); |
| 1124 | |
| 1125 | /* Switch off both Tx, wait to receive delayed frames from MGW */ |
| 1126 | f_osmuxem_mode(OsmuxEM, OSMUXEM_MODE_RXONLY); |
| 1127 | f_sleep(0.1); |
| 1128 | f_flow_delete_osmux(OsmuxEM, ep, call_id); |
| 1129 | |
| 1130 | stats := f_osmuxem_stats_get(OsmuxEM); |
| 1131 | |
| 1132 | if (stats.num_pkts_tx != stats.num_pkts_rx) { |
| 1133 | setverdict(fail); |
| 1134 | } |
| 1135 | if (stats.bytes_payload_tx != stats.bytes_payload_rx) { |
| 1136 | setverdict(fail); |
| 1137 | } |
| 1138 | |
| 1139 | f_osmuxem_stats_err_check(stats); |
| 1140 | |
| 1141 | setverdict(pass); |
| 1142 | } |
| 1143 | |
| 1144 | /* Cross-compare two osmuxem-statistics. The transmission statistics on the a side |
| 1145 | * must match the reception statistics on the other side and vice versa. The |
| 1146 | * user may also supply a tolerance value (number of packets) when deviations |
| 1147 | * are acceptable */ |
| 1148 | function f_rtp_osmux_stats_compare(RtpemStats a, OsmuxemStats b, integer batch_size, integer tolerance := 0) return boolean { |
| 1149 | var integer plen; |
| 1150 | |
| 1151 | log("stats A: ", a); |
| 1152 | log("stats B: ", b); |
| 1153 | log("tolerance: ", tolerance, " packets"); |
| 1154 | log("batch_size: ", batch_size, " packets"); |
| 1155 | |
| 1156 | var integer tolerance_batch := tolerance + (batch_size - tolerance mod batch_size); |
| 1157 | |
| 1158 | if (f_osmuxem_stats_compare_value(a.num_pkts_tx, b.num_pkts_rx * batch_size, tolerance_batch) == false) { |
| 1159 | return false; |
| 1160 | } |
| 1161 | |
| 1162 | if (f_osmuxem_stats_compare_value(a.num_pkts_rx / batch_size, b.num_pkts_tx, tolerance_batch) == false) { |
| 1163 | return false; |
| 1164 | } |
| 1165 | |
| 1166 | if(a.num_pkts_tx > 0) { |
| 1167 | plen := a.bytes_payload_tx / a.num_pkts_tx; |
| 1168 | } else { |
| 1169 | plen := 0; |
| 1170 | } |
| 1171 | |
| 1172 | /* Each RTP pcket payload contains 2 extra bytes due to AMR ToC at start */ |
| 1173 | if (f_osmuxem_stats_compare_value(a.bytes_payload_tx, b.bytes_payload_rx + a.num_pkts_tx * 2, tolerance_batch * plen) == false) { |
| 1174 | log("incorrect payload A->B: " , a.bytes_payload_tx, " vs ", b.bytes_payload_rx + a.num_pkts_rx * 2); |
| 1175 | return false; |
| 1176 | } |
| 1177 | |
| 1178 | if (f_osmuxem_stats_compare_value(a.bytes_payload_rx, b.bytes_payload_tx + b.num_pkts_tx * 2 * batch_size, tolerance_batch * plen) == false) { |
| 1179 | log("incorrect payload B->A: " , b.bytes_payload_tx + b.num_pkts_tx * 2 * batch_size, " vs ", a.bytes_payload_rx); |
| 1180 | return false; |
| 1181 | } |
| 1182 | |
| 1183 | return true; |
| 1184 | } |
| 1185 | |
| 1186 | function f_TC_two_crcx_and_rtp_osmux(boolean bidir) runs on dummy_CT { |
| 1187 | var RtpFlowData flow[2]; |
| 1188 | var RtpemStats stats_rtp; |
| 1189 | var OsmuxemStats stats_osmux; |
| 1190 | var MgcpResponse resp; |
| 1191 | var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "2@" & c_mgw_domain; |
| 1192 | var MgcpCallId call_id := '1226'H; |
| 1193 | var integer tolerance := 0; |
| 1194 | |
| 1195 | f_init(ep, true); |
| 1196 | |
| 1197 | /* from us to MGW */ |
| 1198 | flow[0] := valueof(t_RtpFlow(mp_local_ip, mp_remote_ip, 112, "AMR/8000")); |
| 1199 | flow[0].rtp_cfg := c_RtpemDefaultCfg |
| 1200 | flow[0].rtp_cfg.tx_payload_type := flow[0].pt; |
| 1201 | /* 0014 is the ToC (CMR=AMR4.75) in front of AMR Payload in RTP Payload */ |
| 1202 | flow[0].rtp_cfg.rx_fixed_payload := '0014'O & f_osmux_gen_expected_rx_rtp_payload(2 /* AMR_FT_2, 5.90 */, c_OsmuxemDefaultCfg.tx_fixed_payload); |
| 1203 | flow[0].rtp_cfg.tx_fixed_payload := flow[0].rtp_cfg.rx_fixed_payload; |
| 1204 | /* bind local RTP emulation sockets */ |
| 1205 | flow[0].em.portnr := 10000; |
| 1206 | f_flow_create(RTPEM[0], ep, call_id, "sendrecv", flow[0]); |
| 1207 | |
| 1208 | /* from MGW back to us */ |
| 1209 | flow[1] := valueof(t_RtpFlow(mp_local_ip, mp_remote_ip, 110, "AMR/8000")); |
| 1210 | flow[1].em.portnr := mp_local_osmux_port; |
| 1211 | flow[1].osmux_cid := 2; |
| 1212 | flow[1].osmux_cfg := c_OsmuxemDefaultCfg; |
| 1213 | f_flow_create_osmux(OsmuxEM, ep, call_id, "sendrecv", flow[1]); |
| 1214 | |
| 1215 | if (bidir) { |
| 1216 | f_rtpem_mode(RTPEM[0], RTPEM_MODE_BIDIR); |
| 1217 | f_osmuxem_mode(OsmuxEM, OSMUXEM_MODE_BIDIR); |
| 1218 | |
| 1219 | /* Note: When we test bidirectional we may |
| 1220 | * loose packets during switch off because |
| 1221 | * both ends are transmitting and we only |
| 1222 | * can switch them off one by one. */ |
| 1223 | tolerance := 3; |
| 1224 | } else { |
| 1225 | f_rtpem_mode(RTPEM[0], RTPEM_MODE_RXONLY); |
| 1226 | f_osmuxem_mode(OsmuxEM, OSMUXEM_MODE_TXONLY); |
| 1227 | } |
| 1228 | |
| 1229 | f_sleep(1.0); |
| 1230 | |
| 1231 | /* Switch off both Tx, wait to receive delayed frames from MGW */ |
| 1232 | f_rtpem_mode(RTPEM[0], RTPEM_MODE_RXONLY); |
| 1233 | f_osmuxem_mode(OsmuxEM, OSMUXEM_MODE_RXONLY); |
| 1234 | f_sleep(0.1); |
| 1235 | |
| 1236 | f_flow_delete_osmux(OsmuxEM, ep, call_id); |
| 1237 | f_flow_delete(RTPEM[1]); |
| 1238 | |
| 1239 | stats_rtp := f_rtpem_stats_get(RTPEM[0]); |
| 1240 | stats_osmux := f_osmuxem_stats_get(OsmuxEM); |
| 1241 | if (not f_rtp_osmux_stats_compare(stats_rtp, stats_osmux, flow[1].osmux_cfg.batch_size, tolerance)) { |
| 1242 | setverdict(fail, "RTP and Osmux endpoint statistics don't match"); |
| 1243 | mtc.stop; |
| 1244 | } |
| 1245 | |
| 1246 | f_rtpem_stats_err_check(stats_rtp); |
| 1247 | f_osmuxem_stats_err_check(stats_osmux); |
| 1248 | |
| 1249 | setverdict(pass); |
| 1250 | } |
| 1251 | |
| 1252 | /* create one RTP and one OSmux emulations; create two connections on MGW EP, exchange some data */ |
| 1253 | testcase TC_two_crcx_and_rtp_osmux() runs on dummy_CT { |
| 1254 | f_TC_two_crcx_and_rtp_osmux(false); |
| 1255 | } |
| 1256 | |
| 1257 | /* create one RTP and one OSmux emulations; create two connections on MGW EP, |
| 1258 | * exchange some data in both directions */ |
| 1259 | testcase TC_two_crcx_and_rtp_osmux_bidir() runs on dummy_CT { |
| 1260 | f_TC_two_crcx_and_rtp_osmux(true); |
| 1261 | } |
| 1262 | |
| 1263 | |
| 1264 | function f_two_crcx_mdcx_and_rtp_osmux(boolean crcx_osmux_wildcard) runs on dummy_CT { |
| 1265 | var RtpFlowData flow[2]; |
| 1266 | var RtpemStats stats_rtp; |
| 1267 | var OsmuxemStats stats_osmux; |
| 1268 | var MgcpResponse resp; |
| 1269 | var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "2@" & c_mgw_domain; |
| 1270 | var MgcpCallId call_id := '1227'H; |
| 1271 | var integer num_pkts_tx[2]; |
| 1272 | var integer temp; |
| 1273 | |
| 1274 | f_init(ep, true); |
| 1275 | |
| 1276 | /* Create the first connection in receive only mode */ |
| 1277 | flow[0] := valueof(t_RtpFlow(mp_local_ip, mp_remote_ip, 112, "AMR/8000")); |
| 1278 | flow[0].rtp_cfg := c_RtpemDefaultCfg |
| 1279 | flow[0].rtp_cfg.tx_payload_type := flow[0].pt; |
| 1280 | /* 0014 is the ToC (CMR=AMR4.75) in front of AMR Payload in RTP Payload */ |
| 1281 | flow[0].rtp_cfg.rx_fixed_payload := '0014'O & f_osmux_gen_expected_rx_rtp_payload(2 /* AMR_FT_2, 5.90 */, c_OsmuxemDefaultCfg.tx_fixed_payload); |
| 1282 | flow[0].rtp_cfg.tx_fixed_payload := flow[0].rtp_cfg.rx_fixed_payload; |
| 1283 | /* bind local RTP emulation sockets */ |
| 1284 | flow[0].em.portnr := 10000; |
| 1285 | f_flow_create(RTPEM[0], ep, call_id, "recvonly", flow[0], false); |
| 1286 | |
| 1287 | |
| 1288 | /* Create the second connection. This connection will be also |
| 1289 | * in receive only mode */ |
| 1290 | flow[1] := valueof(t_RtpFlow(mp_local_ip, mp_remote_ip, 110, "AMR/8000")); |
| 1291 | flow[1].em.portnr := mp_local_osmux_port; |
| 1292 | if (crcx_osmux_wildcard) { |
| 1293 | flow[1].osmux_cid := -1; |
| 1294 | } else { |
| 1295 | flow[1].osmux_cid := 2; |
| 1296 | } |
| 1297 | flow[1].osmux_cfg := c_OsmuxemDefaultCfg; |
| 1298 | f_flow_create_osmux(OsmuxEM, ep, call_id, "recvonly", flow[1], false); |
| 1299 | |
| 1300 | |
| 1301 | /* The first leg starts transmitting */ |
| 1302 | f_rtpem_mode(RTPEM[0], RTPEM_MODE_TXONLY); |
| 1303 | f_sleep(0.5); |
| 1304 | stats_rtp := f_rtpem_stats_get(RTPEM[0]); |
| 1305 | if (stats_rtp.num_pkts_rx_err_disabled != 0) { |
| 1306 | setverdict(fail, "received packets from RTP MGW on recvonly connection"); |
| 1307 | mtc.stop; |
| 1308 | } |
| 1309 | stats_osmux := f_osmuxem_stats_get(OsmuxEM); |
| 1310 | if (stats_osmux.num_pkts_rx_err_disabled != 0) { |
| 1311 | setverdict(fail, "received packets from Osmux MGW on recvonly connection"); |
| 1312 | mtc.stop; |
| 1313 | } |
| 1314 | |
| 1315 | /* The second leg starts transmitting a little later */ |
| 1316 | f_osmuxem_mode(OsmuxEM, OSMUXEM_MODE_TXONLY); |
| 1317 | f_sleep(1.0); |
| 1318 | stats_rtp := f_rtpem_stats_get(RTPEM[0]); |
| 1319 | if (stats_rtp.num_pkts_rx_err_disabled != 0) { |
| 1320 | setverdict(fail, "received packets from RTP MGW on recvonly connection"); |
| 1321 | mtc.stop; |
| 1322 | } |
| 1323 | stats_osmux := f_osmuxem_stats_get(OsmuxEM); |
| 1324 | if (stats_osmux.num_pkts_rx_err_disabled != 0) { |
| 1325 | setverdict(fail, "received packets from Osmux MGW on recvonly connection"); |
| 1326 | mtc.stop; |
| 1327 | } |
| 1328 | |
| 1329 | /* The first leg will now be switched into bidirectional |
| 1330 | * mode, but we do not expect any data comming back yet. */ |
| 1331 | f_flow_modify(RTPEM[0], ep, call_id, "sendrecv", flow[0]); |
| 1332 | f_sleep(0.5); |
| 1333 | stats_rtp := f_rtpem_stats_get(RTPEM[0]); |
| 1334 | if (stats_rtp.num_pkts_rx_err_disabled != 0) { |
| 1335 | setverdict(fail, "received packets from RTP MGW on recvonly connection"); |
| 1336 | mtc.stop; |
| 1337 | } |
| 1338 | stats_osmux := f_osmuxem_stats_get(OsmuxEM); |
| 1339 | if (stats_osmux.num_pkts_rx_err_disabled != 0) { |
| 1340 | setverdict(fail, "received packets from Osmux MGW on recvonly connection"); |
| 1341 | mtc.stop; |
| 1342 | } |
| 1343 | |
| 1344 | /* When the second leg is switched into bidirectional mode |
| 1345 | * as well, then the MGW will connect the two together and |
| 1346 | * we should see RTP streams passing through from both ends. */ |
| 1347 | f_rtpem_mode(RTPEM[0], RTPEM_MODE_BIDIR); |
| 1348 | f_osmuxem_mode(OsmuxEM, OSMUXEM_MODE_BIDIR); |
| 1349 | stats_rtp := f_rtpem_stats_get(RTPEM[0]); |
| 1350 | num_pkts_tx[0] := stats_rtp.num_pkts_tx |
| 1351 | stats_osmux := f_osmuxem_stats_get(OsmuxEM); |
| 1352 | num_pkts_tx[1] := stats_osmux.num_pkts_tx |
| 1353 | |
| 1354 | if (crcx_osmux_wildcard) { |
| 1355 | /* For now we must set same CID as the MGW recvCID, |
| 1356 | * having sendCID!=recvCID is not yet supported. */ |
| 1357 | flow[1].osmux_cid := flow[1].osmux_cid_response; |
| 1358 | } |
| 1359 | f_flow_modify_osmux(OsmuxEM, ep, call_id, "sendrecv", flow[1]); |
| 1360 | f_sleep(2.0); |
| 1361 | |
| 1362 | stats_rtp := f_rtpem_stats_get(RTPEM[0]); |
| 1363 | stats_osmux := f_osmuxem_stats_get(OsmuxEM); |
| 1364 | |
| 1365 | temp := stats_rtp.num_pkts_tx - num_pkts_tx[0] - stats_osmux.num_pkts_rx * flow[1].osmux_cfg.batch_size; |
| 1366 | if (temp > 3 * flow[1].osmux_cfg.batch_size or temp < -3 * flow[1].osmux_cfg.batch_size) { |
| 1367 | log("stats_rtp: ", stats_rtp); |
| 1368 | log("stats_osmux: ", stats_osmux); |
| 1369 | log("old_rtp_tx: ", num_pkts_tx[0]); |
| 1370 | setverdict(fail, "number of packets not within normal parameters (" & int2str(temp) & ")"); |
| 1371 | mtc.stop; |
| 1372 | } |
| 1373 | |
| 1374 | temp := stats_osmux.num_pkts_tx - num_pkts_tx[1] - stats_rtp.num_pkts_rx / flow[1].osmux_cfg.batch_size; |
| 1375 | if (temp > 3 or temp < -3) { |
| 1376 | setverdict(fail, "number of packets not within normal parameters (" & int2str(temp) & ")"); |
| 1377 | mtc.stop; |
| 1378 | } |
| 1379 | |
| 1380 | f_rtpem_stats_err_check(stats_rtp); |
| 1381 | f_osmuxem_stats_err_check(stats_osmux); |
| 1382 | |
| 1383 | /* Tear down */ |
| 1384 | f_flow_delete(RTPEM[0]); |
| 1385 | f_flow_delete_osmux(OsmuxEM, ep, call_id); |
| 1386 | setverdict(pass); |
| 1387 | } |
| 1388 | |
| 1389 | /* create one RTP and one OSmux emulations and pass data in both |
| 1390 | directions. Create CRCX with wildcard Osmux CID and set it later |
| 1391 | during MDCX. This is similar to how MSC sets up the call in AoIP. */ |
| 1392 | testcase TC_two_crcx_mdcx_and_rtp_osmux_wildcard() runs on dummy_CT { |
| 1393 | f_two_crcx_mdcx_and_rtp_osmux(true); |
| 1394 | } |
| 1395 | |
| 1396 | /* create one RTP and one OSmux emulations and pass data in both |
| 1397 | directions. Create CRCX with fixed Osmux CID and keep it during |
| 1398 | MDCX. This is similar to how BSC sets up the call in AoIP. */ |
| 1399 | testcase TC_two_crcx_mdcx_and_rtp_osmux_fixed() runs on dummy_CT { |
| 1400 | f_two_crcx_mdcx_and_rtp_osmux(false); |
| 1401 | } |
| 1402 | |
Harald Welte | 646ecdb | 2017-12-28 03:21:57 +0100 | [diff] [blame] | 1403 | function f_crcx_and_dlcx_ep_callid_connid(MgcpEndpoint ep, MgcpCallId call_id) runs on dummy_CT { |
| 1404 | var template MgcpCommand cmd; |
| 1405 | var MgcpResponse resp; |
| 1406 | |
| 1407 | cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id); |
| 1408 | resp := mgcp_transceive_mgw(cmd, tr_CRCX_ACK); |
| 1409 | |
| 1410 | f_dlcx_ok(ep, call_id, extract_conn_id(resp)); |
| 1411 | |
| 1412 | setverdict(pass); |
| 1413 | } |
| 1414 | |
| 1415 | testcase TC_crcx_dlcx_30ep() runs on dummy_CT { |
| 1416 | var MgcpEndpoint ep; |
| 1417 | var MgcpCallId call_id; |
| 1418 | var integer ep_nr; |
| 1419 | |
| 1420 | f_init(); |
| 1421 | |
| 1422 | for (ep_nr := 1; ep_nr < 30; ep_nr := ep_nr+1) { |
Philipp Maier | 4c2a1ea | 2020-05-15 18:37:05 +0200 | [diff] [blame] | 1423 | if(ep_nr > 15) { |
| 1424 | ep := c_mgw_ep_rtpbridge & hex2str(int2hex(ep_nr, 2)) & "@" & c_mgw_domain; |
| 1425 | } else { |
| 1426 | ep := c_mgw_ep_rtpbridge & hex2str(int2hex(ep_nr, 1)) & "@" & c_mgw_domain; |
| 1427 | } |
Harald Welte | 646ecdb | 2017-12-28 03:21:57 +0100 | [diff] [blame] | 1428 | call_id := int2hex(ep_nr, 2) & '1234'H; |
| 1429 | f_crcx_and_dlcx_ep_callid_connid(ep, call_id); |
| 1430 | } |
| 1431 | } |
| 1432 | |
Harald Welte | 79181ff | 2017-11-18 19:26:11 +0100 | [diff] [blame] | 1433 | /* Test (valid) CRCX followed by (valid) DLCX containing EP+CallId */ |
| 1434 | testcase TC_crcx_and_dlcx_ep_callid() runs on dummy_CT { |
Harald Welte | 5b4c44e | 2017-09-17 16:35:27 +0800 | [diff] [blame] | 1435 | var template MgcpCommand cmd; |
| 1436 | var MgcpResponse resp; |
Philipp Maier | bb7a01c | 2018-02-01 12:32:57 +0100 | [diff] [blame] | 1437 | var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "5@" & c_mgw_domain; |
Harald Welte | 6d167f8 | 2017-11-18 19:41:35 +0100 | [diff] [blame] | 1438 | var MgcpCallId call_id := '51233'H; |
Harald Welte | 5b4c44e | 2017-09-17 16:35:27 +0800 | [diff] [blame] | 1439 | |
Harald Welte | edc45c1 | 2017-11-18 19:15:05 +0100 | [diff] [blame] | 1440 | f_init(ep); |
Harald Welte | 5b4c44e | 2017-09-17 16:35:27 +0800 | [diff] [blame] | 1441 | |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 1442 | cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id); |
Harald Welte | 9988d28 | 2017-11-18 19:22:00 +0100 | [diff] [blame] | 1443 | resp := mgcp_transceive_mgw(cmd, tr_CRCX_ACK); |
Harald Welte | 5b4c44e | 2017-09-17 16:35:27 +0800 | [diff] [blame] | 1444 | |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 1445 | f_dlcx_ok(ep, call_id); |
Harald Welte | 5b4c44e | 2017-09-17 16:35:27 +0800 | [diff] [blame] | 1446 | |
| 1447 | setverdict(pass); |
| 1448 | } |
| 1449 | |
Harald Welte | 79181ff | 2017-11-18 19:26:11 +0100 | [diff] [blame] | 1450 | /* Test (valid) CRCX followed by (valid) DLCX containing EP */ |
| 1451 | testcase TC_crcx_and_dlcx_ep() runs on dummy_CT { |
| 1452 | var template MgcpCommand cmd; |
| 1453 | var MgcpResponse resp; |
Philipp Maier | bb7a01c | 2018-02-01 12:32:57 +0100 | [diff] [blame] | 1454 | var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "5@" & c_mgw_domain; |
Harald Welte | 6d167f8 | 2017-11-18 19:41:35 +0100 | [diff] [blame] | 1455 | var MgcpCallId call_id := '51232'H; |
Harald Welte | 79181ff | 2017-11-18 19:26:11 +0100 | [diff] [blame] | 1456 | |
| 1457 | f_init(ep); |
| 1458 | |
| 1459 | cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id); |
| 1460 | resp := mgcp_transceive_mgw(cmd, tr_CRCX_ACK); |
| 1461 | |
| 1462 | f_dlcx_ok(ep); |
| 1463 | |
| 1464 | setverdict(pass); |
| 1465 | } |
| 1466 | |
| 1467 | |
Harald Welte | 6d167f8 | 2017-11-18 19:41:35 +0100 | [diff] [blame] | 1468 | /* CRCX + DLCX of valid endpoint but invalid call-id */ |
| 1469 | testcase TC_crcx_and_dlcx_ep_callid_inval() runs on dummy_CT { |
| 1470 | var template MgcpCommand cmd; |
| 1471 | var MgcpResponse resp; |
Philipp Maier | bb7a01c | 2018-02-01 12:32:57 +0100 | [diff] [blame] | 1472 | var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "5@" & c_mgw_domain; |
Harald Welte | 6d167f8 | 2017-11-18 19:41:35 +0100 | [diff] [blame] | 1473 | var MgcpCallId call_id := '51231'H; |
| 1474 | |
| 1475 | f_init(ep); |
| 1476 | |
| 1477 | cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id); |
| 1478 | resp := mgcp_transceive_mgw(cmd, tr_CRCX_ACK); |
| 1479 | |
| 1480 | f_dlcx(ep, "516", *, 'ffff'H); |
| 1481 | |
| 1482 | setverdict(pass); |
| 1483 | } |
| 1484 | |
| 1485 | |
| 1486 | /* CRCX + DLCX of valid endpoint and call-id but invalid conn-id */ |
| 1487 | testcase TC_crcx_and_dlcx_ep_callid_connid_inval() runs on dummy_CT { |
| 1488 | var template MgcpCommand cmd; |
| 1489 | var MgcpResponse resp; |
Philipp Maier | bb7a01c | 2018-02-01 12:32:57 +0100 | [diff] [blame] | 1490 | var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "5@" & c_mgw_domain; |
Harald Welte | 6d167f8 | 2017-11-18 19:41:35 +0100 | [diff] [blame] | 1491 | var MgcpCallId call_id := '51230'H; |
| 1492 | |
| 1493 | f_init(ep); |
| 1494 | |
| 1495 | cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id); |
| 1496 | resp := mgcp_transceive_mgw(cmd, tr_CRCX_ACK); |
| 1497 | |
| 1498 | f_dlcx(ep, "515", *, call_id, 'ffff'H); |
| 1499 | |
| 1500 | setverdict(pass); |
| 1501 | } |
| 1502 | |
| 1503 | |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 1504 | /* TODO: Double-DLCX (retransmission) */ |
Harald Welte | f53f164 | 2017-11-18 19:57:11 +0100 | [diff] [blame] | 1505 | testcase TC_crcx_and_dlcx_retrans() runs on dummy_CT { |
| 1506 | var template MgcpCommand cmd; |
| 1507 | var MgcpResponse resp; |
Philipp Maier | bb7a01c | 2018-02-01 12:32:57 +0100 | [diff] [blame] | 1508 | var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "5@" & c_mgw_domain; |
Harald Welte | f53f164 | 2017-11-18 19:57:11 +0100 | [diff] [blame] | 1509 | var MgcpCallId call_id := '51229'H; |
| 1510 | var template MgcpResponse rtmpl := { |
| 1511 | line := { |
| 1512 | code := "200", |
| 1513 | string := "OK" |
| 1514 | }, |
| 1515 | params:= { }, |
| 1516 | sdp := omit |
| 1517 | }; |
| 1518 | |
| 1519 | f_init(ep); |
| 1520 | |
| 1521 | cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id); |
| 1522 | resp := mgcp_transceive_mgw(cmd, tr_CRCX_ACK); |
| 1523 | |
| 1524 | cmd := ts_DLCX(get_next_trans_id(), ep, call_id); |
| 1525 | resp := mgcp_transceive_mgw(cmd, rtmpl); |
| 1526 | resp := mgcp_transceive_mgw(cmd, rtmpl); |
| 1527 | |
| 1528 | setverdict(pass); |
| 1529 | } |
| 1530 | |
Harald Welte | bb7523b | 2018-03-29 08:52:01 +0200 | [diff] [blame] | 1531 | template (value) RtpFlowData t_RtpFlow(charstring host_a, charstring host_b, uint7_t pt, |
| 1532 | charstring codec) := { |
| 1533 | em := { |
| 1534 | hostname := host_a, |
| 1535 | portnr := omit |
| 1536 | }, |
| 1537 | mgw := { |
| 1538 | hostname := host_b, |
| 1539 | portnr := omit |
| 1540 | }, |
| 1541 | pt := pt, |
Pau Espin Pedrol | b2c6b38 | 2019-05-14 13:40:49 +0200 | [diff] [blame] | 1542 | codec := codec, |
| 1543 | osmux_cid_sent := false |
Harald Welte | bb7523b | 2018-03-29 08:52:01 +0200 | [diff] [blame] | 1544 | } |
Harald Welte | f53f164 | 2017-11-18 19:57:11 +0100 | [diff] [blame] | 1545 | |
Harald Welte | bb7523b | 2018-03-29 08:52:01 +0200 | [diff] [blame] | 1546 | /* transmit RTP streams between two RTP Emulations back-to-back; expect no loss */ |
| 1547 | testcase TC_rtpem_selftest() runs on dummy_CT { |
| 1548 | var RtpemStats stats[2]; |
| 1549 | var integer local_port := 10000; |
| 1550 | var integer local_port2 := 20000; |
| 1551 | |
| 1552 | f_init(); |
| 1553 | |
| 1554 | f_rtpem_bind(RTPEM[0], "127.0.0.1", local_port); |
| 1555 | f_rtpem_bind(RTPEM[1], "127.0.0.2", local_port2); |
| 1556 | |
| 1557 | f_rtpem_connect(RTPEM[0], "127.0.0.2", local_port2); |
| 1558 | f_rtpem_connect(RTPEM[1], "127.0.0.1", local_port); |
| 1559 | |
| 1560 | log("=== starting"); |
| 1561 | f_rtpem_mode(RTPEM[0], RTPEM_MODE_BIDIR); |
| 1562 | f_rtpem_mode(RTPEM[1], RTPEM_MODE_BIDIR); |
| 1563 | |
| 1564 | f_sleep(5.0); |
| 1565 | |
| 1566 | log("=== stopping"); |
| 1567 | f_rtpem_mode(RTPEM[1], RTPEM_MODE_RXONLY); |
| 1568 | f_rtpem_mode(RTPEM[0], RTPEM_MODE_RXONLY); |
| 1569 | f_sleep(0.5); |
| 1570 | f_rtpem_mode(RTPEM[1], RTPEM_MODE_NONE); |
| 1571 | f_rtpem_mode(RTPEM[0], RTPEM_MODE_NONE); |
| 1572 | |
| 1573 | stats[0] := f_rtpem_stats_get(RTPEM[0]); |
| 1574 | stats[1] := f_rtpem_stats_get(RTPEM[1]); |
| 1575 | if (not f_rtpem_stats_compare(stats[0], stats[1])) { |
| 1576 | setverdict(fail, "RTP endpoint statistics don't match"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 1577 | mtc.stop; |
Harald Welte | bb7523b | 2018-03-29 08:52:01 +0200 | [diff] [blame] | 1578 | } |
| 1579 | setverdict(pass); |
| 1580 | } |
| 1581 | |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 1582 | /* Create one half open connection in receive-only mode. The MGW must accept |
| 1583 | * the packets but must not send any. */ |
| 1584 | testcase TC_one_crcx_receive_only_rtp() runs on dummy_CT { |
| 1585 | var RtpFlowData flow; |
| 1586 | var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "1@" & c_mgw_domain; |
| 1587 | var MgcpCallId call_id := '1225'H; |
| 1588 | var RtpemStats stats; |
| 1589 | |
| 1590 | f_init(ep); |
| 1591 | flow := valueof(t_RtpFlow(mp_local_ip, mp_remote_ip, 112, "AMR/8000/1")); |
| 1592 | flow.em.portnr := 10000; |
| 1593 | f_flow_create(RTPEM[0], ep, call_id, "recvonly", flow, false); |
| 1594 | |
| 1595 | f_rtpem_mode(RTPEM[0], RTPEM_MODE_TXONLY); |
| 1596 | f_sleep(1.0); |
| 1597 | f_flow_delete(RTPEM[0], ep, call_id); |
| 1598 | |
| 1599 | stats := f_rtpem_stats_get(RTPEM[0]); |
| 1600 | |
Philipp Maier | 42b17cc | 2019-10-01 13:53:17 +0200 | [diff] [blame] | 1601 | /* Make sure that at least some amount of RTP packets/bytes |
| 1602 | * have has been transmitted. The compare values for |
| 1603 | * stats.num_pkts_tx and stats.bytes_payload_tx are determined |
| 1604 | * using a testrun and the results were devided by 2, so even |
| 1605 | * in load situations we should reach the minimum amount of |
| 1606 | * required packets/bytes */ |
| 1607 | |
| 1608 | if (stats.num_pkts_tx < 24) { |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 1609 | setverdict(fail); |
| 1610 | } |
Philipp Maier | 42b17cc | 2019-10-01 13:53:17 +0200 | [diff] [blame] | 1611 | if (stats.bytes_payload_tx < 96) { |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 1612 | setverdict(fail); |
| 1613 | } |
Philipp Maier | 3629139 | 2018-07-25 09:40:44 +0200 | [diff] [blame] | 1614 | |
| 1615 | f_rtpem_stats_err_check(stats); |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 1616 | |
| 1617 | setverdict(pass); |
| 1618 | } |
| 1619 | |
| 1620 | /* Create one connection in loopback mode, test if the RTP packets are |
| 1621 | * actually reflected */ |
| 1622 | testcase TC_one_crcx_loopback_rtp() runs on dummy_CT { |
| 1623 | var RtpFlowData flow; |
| 1624 | var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "1@" & c_mgw_domain; |
| 1625 | var MgcpCallId call_id := '1225'H; |
| 1626 | var RtpemStats stats; |
| 1627 | |
| 1628 | f_init(ep); |
| 1629 | flow := valueof(t_RtpFlow(mp_local_ip, mp_remote_ip, 111, "GSM-HR-08/8000/1")); |
| 1630 | flow.em.portnr := 10000; |
| 1631 | f_flow_create(RTPEM[0], ep, call_id, "loopback", flow); |
| 1632 | |
| 1633 | f_rtpem_mode(RTPEM[0], RTPEM_MODE_BIDIR); |
| 1634 | f_sleep(1.0); |
| 1635 | f_flow_delete(RTPEM[0], ep, call_id); |
| 1636 | |
| 1637 | stats := f_rtpem_stats_get(RTPEM[0]); |
| 1638 | |
| 1639 | if (stats.num_pkts_tx != stats.num_pkts_rx) { |
| 1640 | setverdict(fail); |
| 1641 | } |
| 1642 | if (stats.bytes_payload_tx != stats.bytes_payload_rx) { |
| 1643 | setverdict(fail); |
| 1644 | } |
Philipp Maier | 3629139 | 2018-07-25 09:40:44 +0200 | [diff] [blame] | 1645 | |
| 1646 | f_rtpem_stats_err_check(stats); |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 1647 | |
| 1648 | setverdict(pass); |
| 1649 | } |
| 1650 | |
Philipp Maier | 7df85f6 | 2018-07-25 10:26:09 +0200 | [diff] [blame] | 1651 | function f_TC_two_crcx_and_rtp(boolean bidir, charstring codec_name_a, integer pt_a, |
| 1652 | charstring codec_name_b, integer pt_b) runs on dummy_CT { |
Harald Welte | bb7523b | 2018-03-29 08:52:01 +0200 | [diff] [blame] | 1653 | var RtpFlowData flow[2]; |
| 1654 | var RtpemStats stats[2]; |
Harald Welte | bb7523b | 2018-03-29 08:52:01 +0200 | [diff] [blame] | 1655 | var MgcpResponse resp; |
| 1656 | var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "2@" & c_mgw_domain; |
| 1657 | var MgcpCallId call_id := '1226'H; |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 1658 | var integer tolerance := 0; |
Harald Welte | bb7523b | 2018-03-29 08:52:01 +0200 | [diff] [blame] | 1659 | |
| 1660 | f_init(ep); |
| 1661 | |
| 1662 | /* from us to MGW */ |
Philipp Maier | 7df85f6 | 2018-07-25 10:26:09 +0200 | [diff] [blame] | 1663 | flow[0] := valueof(t_RtpFlow(mp_local_ip, mp_remote_ip, pt_a, codec_name_a)); |
Harald Welte | bb7523b | 2018-03-29 08:52:01 +0200 | [diff] [blame] | 1664 | /* bind local RTP emulation sockets */ |
| 1665 | flow[0].em.portnr := 10000; |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 1666 | f_flow_create(RTPEM[0], ep, call_id, "sendrecv", flow[0]); |
Harald Welte | bb7523b | 2018-03-29 08:52:01 +0200 | [diff] [blame] | 1667 | |
| 1668 | /* from MGW back to us */ |
Philipp Maier | 7df85f6 | 2018-07-25 10:26:09 +0200 | [diff] [blame] | 1669 | flow[1] := valueof(t_RtpFlow(mp_local_ip, mp_remote_ip, pt_b, codec_name_b)); |
Harald Welte | bb7523b | 2018-03-29 08:52:01 +0200 | [diff] [blame] | 1670 | flow[1].em.portnr := 20000; |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 1671 | f_flow_create(RTPEM[1], ep, call_id, "sendrecv", flow[1]); |
| 1672 | |
| 1673 | if (bidir) { |
| 1674 | f_rtpem_mode(RTPEM[0], RTPEM_MODE_BIDIR); |
| 1675 | f_rtpem_mode(RTPEM[1], RTPEM_MODE_BIDIR); |
| 1676 | |
| 1677 | /* Note: When we test bidirectional we may |
| 1678 | * loose packets during switch off because |
| 1679 | * both ends are transmitting and we only |
| 1680 | * can switch them off one by one. */ |
| 1681 | tolerance := 3; |
| 1682 | } else { |
| 1683 | f_rtpem_mode(RTPEM[0], RTPEM_MODE_RXONLY); |
| 1684 | f_rtpem_mode(RTPEM[1], RTPEM_MODE_TXONLY); |
| 1685 | } |
| 1686 | |
| 1687 | f_sleep(1.0); |
| 1688 | |
| 1689 | f_flow_delete(RTPEM[1]); |
| 1690 | f_flow_delete(RTPEM[0], ep, call_id); |
| 1691 | |
| 1692 | stats[0] := f_rtpem_stats_get(RTPEM[0]); |
| 1693 | stats[1] := f_rtpem_stats_get(RTPEM[1]); |
| 1694 | if (not f_rtpem_stats_compare(stats[0], stats[1], tolerance)) { |
| 1695 | setverdict(fail, "RTP endpoint statistics don't match"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 1696 | mtc.stop; |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 1697 | } |
| 1698 | |
Philipp Maier | 3629139 | 2018-07-25 09:40:44 +0200 | [diff] [blame] | 1699 | f_rtpem_stats_err_check(stats[0]); |
| 1700 | f_rtpem_stats_err_check(stats[1]); |
Philipp Maier | c290d72 | 2018-07-24 18:51:36 +0200 | [diff] [blame] | 1701 | |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 1702 | setverdict(pass); |
| 1703 | } |
| 1704 | |
| 1705 | /* create two local RTP emulations; create two connections on MGW EP, exchange some data */ |
| 1706 | testcase TC_two_crcx_and_rtp() runs on dummy_CT { |
Philipp Maier | 7df85f6 | 2018-07-25 10:26:09 +0200 | [diff] [blame] | 1707 | f_TC_two_crcx_and_rtp(false, "AMR/8000", 98, "AMR/8000", 98); |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 1708 | } |
| 1709 | |
| 1710 | /* create two local RTP emulations; create two connections on MGW EP, |
| 1711 | * exchange some data in both directions */ |
| 1712 | testcase TC_two_crcx_and_rtp_bidir() runs on dummy_CT { |
Philipp Maier | 7df85f6 | 2018-07-25 10:26:09 +0200 | [diff] [blame] | 1713 | f_TC_two_crcx_and_rtp(true, "AMR/8000", 98, "AMR/8000", 98); |
| 1714 | } |
| 1715 | |
| 1716 | /* same as TC_two_crcx_and_rtp, but with different PT number on both ends */ |
| 1717 | testcase TC_two_crcx_diff_pt_and_rtp() runs on dummy_CT { |
| 1718 | f_TC_two_crcx_and_rtp(false, "AMR/8000", 98, "AMR/8000", 112); |
| 1719 | } |
| 1720 | |
| 1721 | /* same as TC_two_crcx_and_rtp, but with different PT number on both ends */ |
| 1722 | testcase TC_two_crcx_diff_pt_and_rtp_bidir() runs on dummy_CT { |
| 1723 | f_TC_two_crcx_and_rtp(true, "AMR/8000", 98, "AMR/8000", 112); |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 1724 | } |
| 1725 | |
| 1726 | /* create two local RTP emulations and pass data in both directions */ |
| 1727 | testcase TC_two_crcx_mdcx_and_rtp() runs on dummy_CT { |
| 1728 | var RtpFlowData flow[2]; |
| 1729 | var RtpemStats stats[2]; |
| 1730 | var MgcpResponse resp; |
| 1731 | var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "2@" & c_mgw_domain; |
| 1732 | var MgcpCallId call_id := '1227'H; |
| 1733 | var integer num_pkts_tx[2]; |
| 1734 | var integer temp; |
| 1735 | |
| 1736 | f_init(ep); |
| 1737 | |
| 1738 | /* Create the first connection in receive only mode */ |
| 1739 | flow[0] := valueof(t_RtpFlow(mp_local_ip, mp_remote_ip, 3, "GSM/8000/1")); |
| 1740 | flow[0].em.portnr := 10000; |
| 1741 | f_flow_create(RTPEM[0], ep, call_id, "recvonly", flow[0], false); |
| 1742 | |
| 1743 | /* Create the second connection. This connection will be also |
| 1744 | * in receive only mode */ |
| 1745 | flow[1] := valueof(t_RtpFlow(mp_local_ip, mp_remote_ip, 3, "GSM/8000/1")); |
| 1746 | flow[1].em.portnr := 20000; |
| 1747 | f_flow_create(RTPEM[1], ep, call_id, "recvonly", flow[1], false); |
| 1748 | |
| 1749 | /* The first leg starts transmitting */ |
| 1750 | f_rtpem_mode(RTPEM[0], RTPEM_MODE_TXONLY); |
| 1751 | f_sleep(0.5); |
| 1752 | stats[0] := f_rtpem_stats_get(RTPEM[0]); |
| 1753 | if (stats[0].num_pkts_rx_err_disabled != 0) { |
| 1754 | setverdict(fail, "received packets from MGW on recvonly connection"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 1755 | mtc.stop; |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 1756 | } |
| 1757 | stats[1] := f_rtpem_stats_get(RTPEM[1]); |
| 1758 | if (stats[1].num_pkts_rx_err_disabled != 0) { |
| 1759 | setverdict(fail, "received packets from MGW on recvonly connection"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 1760 | mtc.stop; |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 1761 | } |
| 1762 | |
| 1763 | /* The second leg starts transmitting a little later */ |
| 1764 | f_rtpem_mode(RTPEM[1], RTPEM_MODE_TXONLY); |
| 1765 | f_sleep(1.0); |
| 1766 | stats[0] := f_rtpem_stats_get(RTPEM[0]); |
| 1767 | if (stats[0].num_pkts_rx_err_disabled != 0) { |
| 1768 | setverdict(fail, "received packets from MGW on recvonly connection"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 1769 | mtc.stop; |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 1770 | } |
| 1771 | stats[1] := f_rtpem_stats_get(RTPEM[1]); |
| 1772 | if (stats[1].num_pkts_rx_err_disabled != 0) { |
| 1773 | setverdict(fail, "received packets from MGW on recvonly connection"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 1774 | mtc.stop; |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 1775 | } |
| 1776 | |
| 1777 | /* The first leg will now be switched into bidirectional |
| 1778 | * mode, but we do not expect any data comming back yet. */ |
| 1779 | f_flow_modify(RTPEM[0], ep, call_id, "sendrecv", flow[0]); |
| 1780 | f_sleep(0.5); |
| 1781 | stats[0] := f_rtpem_stats_get(RTPEM[0]); |
| 1782 | if (stats[1].num_pkts_rx_err_disabled != 0) { |
| 1783 | setverdict(fail, "received packets from MGW on recvonly connection"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 1784 | mtc.stop; |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 1785 | } |
| 1786 | stats[1] := f_rtpem_stats_get(RTPEM[1]); |
| 1787 | if (stats[1].num_pkts_rx_err_disabled != 0) { |
| 1788 | setverdict(fail, "received packets from MGW on recvonly connection"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 1789 | mtc.stop; |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 1790 | } |
| 1791 | |
| 1792 | /* When the second leg is switched into bidirectional mode |
| 1793 | * as well, then the MGW will connect the two together and |
| 1794 | * we should see RTP streams passing through from both ends. */ |
| 1795 | f_rtpem_mode(RTPEM[0], RTPEM_MODE_BIDIR); |
| 1796 | f_rtpem_mode(RTPEM[1], RTPEM_MODE_BIDIR); |
| 1797 | stats[0] := f_rtpem_stats_get(RTPEM[0]); |
| 1798 | num_pkts_tx[0] := stats[0].num_pkts_tx |
| 1799 | stats[1] := f_rtpem_stats_get(RTPEM[1]); |
| 1800 | num_pkts_tx[1] := stats[1].num_pkts_tx |
| 1801 | |
| 1802 | f_flow_modify(RTPEM[1], ep, call_id, "sendrecv", flow[1]); |
| 1803 | f_sleep(2.0); |
| 1804 | |
| 1805 | stats[0] := f_rtpem_stats_get(RTPEM[0]); |
| 1806 | stats[1] := f_rtpem_stats_get(RTPEM[1]); |
| 1807 | |
| 1808 | temp := stats[0].num_pkts_tx - num_pkts_tx[0] - stats[1].num_pkts_rx; |
| 1809 | if (temp > 3 or temp < -3) { |
| 1810 | setverdict(fail, "number of packets not within normal parameters"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 1811 | mtc.stop; |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | temp := stats[1].num_pkts_tx - num_pkts_tx[1] - stats[0].num_pkts_rx; |
| 1815 | if (temp > 3 or temp < -3) { |
| 1816 | setverdict(fail, "number of packets not within normal parameters"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 1817 | mtc.stop; |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 1818 | } |
Philipp Maier | 3629139 | 2018-07-25 09:40:44 +0200 | [diff] [blame] | 1819 | |
| 1820 | f_rtpem_stats_err_check(stats[0]); |
| 1821 | f_rtpem_stats_err_check(stats[1]); |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 1822 | |
| 1823 | /* Tear down */ |
| 1824 | f_flow_delete(RTPEM[0]); |
| 1825 | f_flow_delete(RTPEM[1], ep, call_id); |
| 1826 | setverdict(pass); |
| 1827 | } |
| 1828 | |
| 1829 | /* Test what happens when two RTP streams from different sources target |
| 1830 | * a single connection. Is the unsolicited stream properly ignored? */ |
| 1831 | testcase TC_two_crcx_and_unsolicited_rtp() runs on dummy_CT { |
| 1832 | var RtpFlowData flow[2]; |
| 1833 | var RtpemStats stats[2]; |
| 1834 | var MgcpResponse resp; |
| 1835 | var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "2@" & c_mgw_domain; |
| 1836 | var MgcpCallId call_id := '1234321326'H; |
| 1837 | var integer unsolicited_port := 10002; |
| 1838 | |
| 1839 | f_init(ep); |
| 1840 | |
| 1841 | /* from us to MGW */ |
| 1842 | flow[0] := valueof(t_RtpFlow(mp_local_ip, mp_remote_ip, 98, "AMR/8000")); |
| 1843 | /* bind local RTP emulation sockets */ |
| 1844 | flow[0].em.portnr := 10000; |
| 1845 | f_flow_create(RTPEM[0], ep, call_id, "sendrecv", flow[0]); |
| 1846 | |
| 1847 | /* from MGW back to us */ |
| 1848 | flow[1] := valueof(t_RtpFlow(mp_local_ip, mp_remote_ip, 98, "AMR/8000")); |
| 1849 | flow[1].em.portnr := 20000; |
| 1850 | f_flow_create(RTPEM[1], ep, call_id, "sendrecv", flow[1]); |
Harald Welte | bb7523b | 2018-03-29 08:52:01 +0200 | [diff] [blame] | 1851 | |
| 1852 | f_rtpem_mode(RTPEM[1], RTPEM_MODE_RXONLY); |
| 1853 | f_rtpem_mode(RTPEM[0], RTPEM_MODE_TXONLY); |
| 1854 | |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 1855 | f_sleep(0.5); |
Harald Welte | bb7523b | 2018-03-29 08:52:01 +0200 | [diff] [blame] | 1856 | |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 1857 | /* Start inserting unsolicited RTP packets */ |
Philipp Maier | 4de3e37 | 2018-06-29 17:15:22 +0200 | [diff] [blame] | 1858 | f_rtpem_bind(RTPEM[2], mp_local_ip, unsolicited_port); |
| 1859 | f_rtpem_connect(RTPEM[2], mp_remote_ip, flow[0].mgw.portnr); |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 1860 | f_rtpem_mode(RTPEM[2], RTPEM_MODE_TXONLY); |
| 1861 | |
| 1862 | f_sleep(0.5); |
| 1863 | |
Daniel Willmann | a069d38 | 2018-12-13 13:53:33 +0100 | [diff] [blame] | 1864 | /* Stop transmitting packets and tear down the flows */ |
| 1865 | f_rtpem_mode(RTPEM[2], RTPEM_MODE_NONE); |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 1866 | f_flow_delete(RTPEM[0]); |
| 1867 | f_flow_delete(RTPEM[1], ep, call_id); |
Harald Welte | bb7523b | 2018-03-29 08:52:01 +0200 | [diff] [blame] | 1868 | |
| 1869 | stats[0] := f_rtpem_stats_get(RTPEM[0]); |
| 1870 | stats[1] := f_rtpem_stats_get(RTPEM[1]); |
| 1871 | if (not f_rtpem_stats_compare(stats[0], stats[1])) { |
| 1872 | setverdict(fail, "RTP endpoint statistics don't match"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 1873 | mtc.stop; |
Harald Welte | bb7523b | 2018-03-29 08:52:01 +0200 | [diff] [blame] | 1874 | } |
| 1875 | |
Philipp Maier | 3629139 | 2018-07-25 09:40:44 +0200 | [diff] [blame] | 1876 | f_rtpem_stats_err_check(stats[0]); |
| 1877 | f_rtpem_stats_err_check(stats[0]); |
Philipp Maier | c290d72 | 2018-07-24 18:51:36 +0200 | [diff] [blame] | 1878 | |
Harald Welte | bb7523b | 2018-03-29 08:52:01 +0200 | [diff] [blame] | 1879 | setverdict(pass); |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 1880 | } |
Harald Welte | bb7523b | 2018-03-29 08:52:01 +0200 | [diff] [blame] | 1881 | |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 1882 | /* Test a handover situation. We first create two connections transmit |
| 1883 | * some data bidirectionally. Then we will simulate a handover situation. */ |
| 1884 | testcase TC_two_crcx_and_one_mdcx_rtp_ho() runs on dummy_CT { |
| 1885 | var RtpFlowData flow[2]; |
| 1886 | var RtpemStats stats[3]; |
| 1887 | var MgcpResponse resp; |
| 1888 | var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "4@" & c_mgw_domain; |
| 1889 | var MgcpCallId call_id := '76338'H; |
| 1890 | var integer port_old; |
| 1891 | |
| 1892 | f_init(ep); |
| 1893 | |
| 1894 | /* First connection (BTS) */ |
| 1895 | flow[0] := valueof(t_RtpFlow(mp_local_ip, mp_remote_ip, 110, "GSM-EFR/8000")); |
| 1896 | /* bind local RTP emulation sockets */ |
| 1897 | flow[0].em.portnr := 10000; |
| 1898 | f_flow_create(RTPEM[0], ep, call_id, "sendrecv", flow[0]); |
| 1899 | |
| 1900 | /* Second connection (PBX) */ |
| 1901 | flow[1] := valueof(t_RtpFlow(mp_local_ip, mp_remote_ip, 110, "GSM-EFR/8000")); |
| 1902 | flow[1].em.portnr := 20000; |
| 1903 | f_flow_create(RTPEM[1], ep, call_id, "sendrecv", flow[1]); |
| 1904 | |
| 1905 | /* Normal rtp flow for one second */ |
| 1906 | f_rtpem_mode(RTPEM[0], RTPEM_MODE_BIDIR); |
| 1907 | f_rtpem_mode(RTPEM[1], RTPEM_MODE_BIDIR); |
| 1908 | f_sleep(1.0); |
| 1909 | |
| 1910 | /* Now switch the flow over to a new port (BTS) */ |
| 1911 | port_old := flow[0].em.portnr; |
| 1912 | flow[0].em.portnr := 10002; |
Daniel Willmann | 43a1a0b | 2018-08-01 11:19:39 +0200 | [diff] [blame] | 1913 | f_rtpem_mode(RTPEM[0], RTPEM_MODE_RXONLY); |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 1914 | f_flow_modify(RTPEM[0], ep, call_id, "sendrecv", flow[0]); |
Daniel Willmann | 43a1a0b | 2018-08-01 11:19:39 +0200 | [diff] [blame] | 1915 | f_rtpem_mode(RTPEM[0], RTPEM_MODE_BIDIR); |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 1916 | |
| 1917 | /* When handing over a call, the old source may still keep |
| 1918 | * transmitting for a while. We simulate this by injecting |
| 1919 | * some unsolicited packets on the behalf of the old source, |
| 1920 | * (old remote port) */ |
Philipp Maier | 4de3e37 | 2018-06-29 17:15:22 +0200 | [diff] [blame] | 1921 | f_rtpem_bind(RTPEM[2], mp_local_ip, port_old); |
| 1922 | f_rtpem_connect(RTPEM[2], mp_remote_ip, flow[0].mgw.portnr); |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 1923 | f_rtpem_mode(RTPEM[2], RTPEM_MODE_TXONLY); |
| 1924 | f_sleep(1.0); |
| 1925 | f_rtpem_mode(RTPEM[2], RTPEM_MODE_NONE); |
| 1926 | f_sleep(1.0); |
| 1927 | |
| 1928 | /* Terminate call */ |
| 1929 | f_flow_delete(RTPEM[0]); |
| 1930 | f_flow_delete(RTPEM[1], ep, call_id); |
| 1931 | |
| 1932 | stats[0] := f_rtpem_stats_get(RTPEM[0]); |
| 1933 | stats[1] := f_rtpem_stats_get(RTPEM[1]); |
| 1934 | if (not f_rtpem_stats_compare(stats[0], stats[1], 5)) { |
| 1935 | setverdict(fail, "RTP endpoint statistics don't match"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 1936 | mtc.stop; |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 1937 | } |
| 1938 | stats[2] := f_rtpem_stats_get(RTPEM[2]); |
| 1939 | if (stats[2].num_pkts_rx_err_disabled != 0) { |
| 1940 | setverdict(fail, "received packets on old leg after handover"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 1941 | mtc.stop; |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 1942 | } |
| 1943 | |
Philipp Maier | 3629139 | 2018-07-25 09:40:44 +0200 | [diff] [blame] | 1944 | f_rtpem_stats_err_check(stats[0]); |
| 1945 | f_rtpem_stats_err_check(stats[1]); |
| 1946 | f_rtpem_stats_err_check(stats[2]); |
Philipp Maier | c290d72 | 2018-07-24 18:51:36 +0200 | [diff] [blame] | 1947 | |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 1948 | setverdict(pass); |
Harald Welte | bb7523b | 2018-03-29 08:52:01 +0200 | [diff] [blame] | 1949 | } |
Harald Welte | f53f164 | 2017-11-18 19:57:11 +0100 | [diff] [blame] | 1950 | |
Philipp Maier | 6d4e094 | 2019-02-21 17:35:01 +0100 | [diff] [blame] | 1951 | |
| 1952 | /* create two local RTP emulations; create two connections on MGW EP, see if |
| 1953 | * exchanged data is converted bwtween ts101318 and rfc5993 */ |
| 1954 | testcase TC_ts101318_rfc5993_rtp_conversion() runs on dummy_CT { |
| 1955 | var RtpFlowData flow[2]; |
| 1956 | var RtpemStats stats[2]; |
| 1957 | var MgcpResponse resp; |
| 1958 | var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "2@" & c_mgw_domain; |
| 1959 | var MgcpCallId call_id := '1226'H; |
| 1960 | |
| 1961 | f_init(ep); |
| 1962 | |
| 1963 | /* Turn on conversion mode */ |
| 1964 | f_vty_enter_config(MGWVTY); |
| 1965 | f_vty_transceive(MGWVTY, "mgcp"); |
| 1966 | f_vty_transceive(MGWVTY, "rtp-patch rfc5993hr"); |
| 1967 | |
Philipp Maier | faa1d2f | 2019-10-01 14:07:35 +0200 | [diff] [blame] | 1968 | /* Connection #0 (Bidirectional) */ |
Philipp Maier | 6d4e094 | 2019-02-21 17:35:01 +0100 | [diff] [blame] | 1969 | flow[0] := valueof(t_RtpFlow(mp_local_ip, mp_remote_ip, 111, "GSM-HR-08/8000")); |
| 1970 | /* bind local RTP emulation sockets */ |
| 1971 | flow[0].em.portnr := 10000; |
| 1972 | flow[0].rtp_cfg := c_RtpemDefaultCfg; |
| 1973 | flow[0].rtp_cfg.tx_payload_type := flow[0].pt; |
| 1974 | flow[0].rtp_cfg.rx_fixed_payload := '0b11b3eede60be4e3ec68838c7b5'O; |
| 1975 | flow[0].rtp_cfg.tx_fixed_payload := '0b11b3eede60be4e3ec68838c7b5'O; |
| 1976 | f_flow_create(RTPEM[0], ep, call_id, "sendrecv", flow[0]); |
| 1977 | |
Philipp Maier | faa1d2f | 2019-10-01 14:07:35 +0200 | [diff] [blame] | 1978 | /* Connection #1 (Bidirectional) */ |
Philipp Maier | 6d4e094 | 2019-02-21 17:35:01 +0100 | [diff] [blame] | 1979 | flow[1] := valueof(t_RtpFlow(mp_local_ip, mp_remote_ip, 111, "GSM-HR-08/8000")); |
| 1980 | flow[1].em.portnr := 20000; |
| 1981 | flow[1].rtp_cfg := c_RtpemDefaultCfg; |
| 1982 | flow[1].rtp_cfg.tx_payload_type := flow[1].pt; |
| 1983 | flow[1].rtp_cfg.rx_fixed_payload := '000b11b3eede60be4e3ec68838c7b5'O; |
| 1984 | flow[1].rtp_cfg.tx_fixed_payload := '000b11b3eede60be4e3ec68838c7b5'O; |
| 1985 | f_flow_create(RTPEM[1], ep, call_id, "sendrecv", flow[1]); |
| 1986 | |
Philipp Maier | faa1d2f | 2019-10-01 14:07:35 +0200 | [diff] [blame] | 1987 | /* Send RTP packets to connection #0, receive on connection #1 */ |
| 1988 | f_rtpem_mode(RTPEM[1], RTPEM_MODE_RXONLY); |
| 1989 | f_sleep(0.5); |
| 1990 | f_rtpem_mode(RTPEM[0], RTPEM_MODE_TXONLY); |
Philipp Maier | 6d4e094 | 2019-02-21 17:35:01 +0100 | [diff] [blame] | 1991 | f_sleep(1.0); |
Philipp Maier | faa1d2f | 2019-10-01 14:07:35 +0200 | [diff] [blame] | 1992 | f_rtpem_mode(RTPEM[0], RTPEM_MODE_NONE); |
| 1993 | f_sleep(0.5); |
| 1994 | f_rtpem_mode(RTPEM[1], RTPEM_MODE_NONE); |
Philipp Maier | 6d4e094 | 2019-02-21 17:35:01 +0100 | [diff] [blame] | 1995 | |
Philipp Maier | faa1d2f | 2019-10-01 14:07:35 +0200 | [diff] [blame] | 1996 | /* Send RTP packets to connection #1, receive on connection #0 */ |
| 1997 | f_rtpem_mode(RTPEM[0], RTPEM_MODE_RXONLY); |
| 1998 | f_sleep(0.5); |
| 1999 | f_rtpem_mode(RTPEM[1], RTPEM_MODE_TXONLY); |
| 2000 | f_sleep(1.0); |
| 2001 | f_rtpem_mode(RTPEM[1], RTPEM_MODE_NONE); |
| 2002 | f_sleep(0.5); |
| 2003 | f_rtpem_mode(RTPEM[0], RTPEM_MODE_NONE); |
| 2004 | |
| 2005 | /* Remove RTP flows and check statistics */ |
Philipp Maier | 6d4e094 | 2019-02-21 17:35:01 +0100 | [diff] [blame] | 2006 | f_flow_delete(RTPEM[0]); |
| 2007 | f_flow_delete(RTPEM[1], ep, call_id); |
| 2008 | |
Philipp Maier | faa1d2f | 2019-10-01 14:07:35 +0200 | [diff] [blame] | 2009 | /* Check for errors */ |
Philipp Maier | 6d4e094 | 2019-02-21 17:35:01 +0100 | [diff] [blame] | 2010 | stats[0] := f_rtpem_stats_get(RTPEM[0]); |
| 2011 | stats[1] := f_rtpem_stats_get(RTPEM[1]); |
Philipp Maier | 6d4e094 | 2019-02-21 17:35:01 +0100 | [diff] [blame] | 2012 | f_rtpem_stats_err_check(stats[0]); |
| 2013 | f_rtpem_stats_err_check(stats[1]); |
| 2014 | |
| 2015 | /* Turn off conversion mode */ |
| 2016 | f_vty_transceive(MGWVTY, "no rtp-patch rfc5993hr"); |
| 2017 | |
| 2018 | setverdict(pass); |
| 2019 | } |
| 2020 | |
Philipp Maier | 4f764ce | 2019-03-07 10:54:10 +0100 | [diff] [blame] | 2021 | /* create two local RTP emulations; create two connections on MGW EP, see if |
| 2022 | * exchanged data is converted between AMR octet-aligned and bandwith |
| 2023 | * efficient-mode */ |
| 2024 | function f_TC_amr_x_x_rtp_conversion(octetstring pl0, octetstring pl1, charstring fmtp0, charstring fmtp1) runs on dummy_CT { |
| 2025 | var RtpFlowData flow[2]; |
| 2026 | var RtpemStats stats[2]; |
| 2027 | var MgcpResponse resp; |
| 2028 | var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "2@" & c_mgw_domain; |
| 2029 | var MgcpCallId call_id := '1226'H; |
| 2030 | |
| 2031 | f_init(ep); |
| 2032 | |
Philipp Maier | 9ff0f8a | 2019-10-01 13:21:28 +0200 | [diff] [blame] | 2033 | /* Connection #0 (Bidirectional) */ |
Philipp Maier | 4f764ce | 2019-03-07 10:54:10 +0100 | [diff] [blame] | 2034 | flow[0] := valueof(t_RtpFlow(mp_local_ip, mp_remote_ip, 112, "AMR/8000")); |
| 2035 | /* bind local RTP emulation sockets */ |
| 2036 | flow[0].em.portnr := 10000; |
| 2037 | flow[0].rtp_cfg := c_RtpemDefaultCfg; |
| 2038 | flow[0].rtp_cfg.tx_payload_type := flow[0].pt; |
| 2039 | flow[0].rtp_cfg.rx_fixed_payload := pl0; |
| 2040 | flow[0].rtp_cfg.tx_fixed_payload := pl0; |
| 2041 | flow[0].fmtp := fmtp0; |
| 2042 | f_flow_create(RTPEM[0], ep, call_id, "sendrecv", flow[0]); |
| 2043 | |
Philipp Maier | 9ff0f8a | 2019-10-01 13:21:28 +0200 | [diff] [blame] | 2044 | /* Connection #1 (Bidirectional) */ |
Philipp Maier | 4f764ce | 2019-03-07 10:54:10 +0100 | [diff] [blame] | 2045 | flow[1] := valueof(t_RtpFlow(mp_local_ip, mp_remote_ip, 112, "AMR/8000")); |
| 2046 | flow[1].em.portnr := 20000; |
| 2047 | flow[1].rtp_cfg := c_RtpemDefaultCfg; |
| 2048 | flow[1].rtp_cfg.tx_payload_type := flow[1].pt; |
| 2049 | flow[1].rtp_cfg.rx_fixed_payload := pl1; |
| 2050 | flow[1].rtp_cfg.tx_fixed_payload := pl1; |
| 2051 | flow[1].fmtp := fmtp1; |
| 2052 | f_flow_create(RTPEM[1], ep, call_id, "sendrecv", flow[1]); |
| 2053 | |
Philipp Maier | 9ff0f8a | 2019-10-01 13:21:28 +0200 | [diff] [blame] | 2054 | /* Send RTP packets to connection #0, receive on connection #1 */ |
| 2055 | f_rtpem_mode(RTPEM[1], RTPEM_MODE_RXONLY); |
| 2056 | f_sleep(0.5); |
| 2057 | f_rtpem_mode(RTPEM[0], RTPEM_MODE_TXONLY); |
Philipp Maier | 4f764ce | 2019-03-07 10:54:10 +0100 | [diff] [blame] | 2058 | f_sleep(1.0); |
Philipp Maier | 9ff0f8a | 2019-10-01 13:21:28 +0200 | [diff] [blame] | 2059 | f_rtpem_mode(RTPEM[0], RTPEM_MODE_NONE); |
| 2060 | f_sleep(0.5); |
| 2061 | f_rtpem_mode(RTPEM[1], RTPEM_MODE_NONE); |
Philipp Maier | 4f764ce | 2019-03-07 10:54:10 +0100 | [diff] [blame] | 2062 | |
Philipp Maier | 9ff0f8a | 2019-10-01 13:21:28 +0200 | [diff] [blame] | 2063 | /* Send RTP packets to connection #1, receive on connection #0 */ |
| 2064 | f_rtpem_mode(RTPEM[0], RTPEM_MODE_RXONLY); |
| 2065 | f_sleep(0.5); |
| 2066 | f_rtpem_mode(RTPEM[1], RTPEM_MODE_TXONLY); |
| 2067 | f_sleep(1.0); |
| 2068 | f_rtpem_mode(RTPEM[1], RTPEM_MODE_NONE); |
| 2069 | f_sleep(0.5); |
| 2070 | f_rtpem_mode(RTPEM[0], RTPEM_MODE_NONE); |
| 2071 | |
| 2072 | /* Remove RTP flows and check statistics */ |
Philipp Maier | 4f764ce | 2019-03-07 10:54:10 +0100 | [diff] [blame] | 2073 | f_flow_delete(RTPEM[0]); |
| 2074 | f_flow_delete(RTPEM[1], ep, call_id); |
| 2075 | |
Philipp Maier | 9ff0f8a | 2019-10-01 13:21:28 +0200 | [diff] [blame] | 2076 | /* Check for errors */ |
Philipp Maier | 4f764ce | 2019-03-07 10:54:10 +0100 | [diff] [blame] | 2077 | stats[0] := f_rtpem_stats_get(RTPEM[0]); |
| 2078 | stats[1] := f_rtpem_stats_get(RTPEM[1]); |
Philipp Maier | 4f764ce | 2019-03-07 10:54:10 +0100 | [diff] [blame] | 2079 | f_rtpem_stats_err_check(stats[0]); |
| 2080 | f_rtpem_stats_err_check(stats[1]); |
| 2081 | |
| 2082 | setverdict(pass); |
| 2083 | } |
| 2084 | |
Philipp Maier | 882843d | 2020-05-25 15:33:13 +0200 | [diff] [blame] | 2085 | /* Note: The hexstrings used with the f_TC_amr_x_x_rtp_conversion test |
| 2086 | * functions are real world AMR RTP payloads including AMR header. The |
| 2087 | * payloads were extracted from a trace with known good payloads. */ |
| 2088 | |
Philipp Maier | 4f764ce | 2019-03-07 10:54:10 +0100 | [diff] [blame] | 2089 | testcase TC_amr_oa_bwe_rtp_conversion() runs on dummy_CT { |
Philipp Maier | 882843d | 2020-05-25 15:33:13 +0200 | [diff] [blame] | 2090 | f_TC_amr_x_x_rtp_conversion('2014e959f35fdfe5e9667ffbc088818088'O, '217a567cd7f7f97a599ffef022206022'O, "octet-align=1", "octet-align=0"); |
Philipp Maier | 4f764ce | 2019-03-07 10:54:10 +0100 | [diff] [blame] | 2091 | } |
| 2092 | |
| 2093 | testcase TC_amr_oa_oa_rtp_conversion() runs on dummy_CT { |
| 2094 | f_TC_amr_x_x_rtp_conversion('100c4e9ba850e30d5d53d04de41e7c'O, '100c4e9ba850e30d5d53d04de41e7c'O, "octet-align=1", "octet-align=1"); |
| 2095 | } |
| 2096 | |
| 2097 | testcase TC_amr_bwe_bwe_rtp_conversion() runs on dummy_CT { |
| 2098 | f_TC_amr_x_x_rtp_conversion('10d3a6ea1438c35754f41379079f'O, '10d3a6ea1438c35754f41379079f'O, "octet-align=0", "octet-align=0"); |
| 2099 | } |
Philipp Maier | 6d4e094 | 2019-02-21 17:35:01 +0100 | [diff] [blame] | 2100 | |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 2101 | /* TODO: Double-DLCX (no retransmission) */ |
| 2102 | |
| 2103 | |
| 2104 | |
| 2105 | /* TODO: AUEP (various) */ |
| 2106 | /* TODO: RSIP (various) */ |
| 2107 | /* TODO: RQNT (various) */ |
| 2108 | /* TODO: EPCF (various) */ |
| 2109 | /* TODO: AUCX (various) */ |
| 2110 | /* TODO: invalid verb (various) */ |
| 2111 | |
Oliver Smith | 021141e | 2019-06-25 12:09:01 +0200 | [diff] [blame] | 2112 | |
| 2113 | testcase TC_conn_timeout() runs on dummy_CT { |
| 2114 | var RtpFlowData flow; |
| 2115 | var MgcpEndpoint ep := c_mgw_ep_rtpbridge & "1@" & c_mgw_domain; |
| 2116 | var MgcpCallId call_id := '1225'H; |
| 2117 | var MGCP_RecvFrom mrf; |
| 2118 | |
| 2119 | f_init(ep); |
| 2120 | log("Setting conn-timeout to 1s"); |
| 2121 | f_vty_config(MGWVTY, "mgcp", "conn-timeout 1"); /* reset in f_init_vty() */ |
| 2122 | |
| 2123 | log("Sending RTP data for 1.5s"); |
| 2124 | flow := valueof(t_RtpFlow(mp_local_ip, mp_remote_ip, 111, "GSM-HR-08/8000/1")); |
| 2125 | flow.em.portnr := 10000; |
| 2126 | f_flow_create(RTPEM[0], ep, call_id, "loopback", flow); |
| 2127 | f_rtpem_mode(RTPEM[0], RTPEM_MODE_BIDIR); |
| 2128 | f_sleep(1.5); |
| 2129 | |
| 2130 | log("Stopping for 0.5s and resuming"); |
| 2131 | f_rtpem_mode(RTPEM[0], RTPEM_MODE_NONE); |
| 2132 | f_sleep(0.5); |
| 2133 | f_rtpem_mode(RTPEM[0], RTPEM_MODE_BIDIR); |
| 2134 | f_sleep(0.1); |
| 2135 | |
| 2136 | log("Stopping for 1.5s, expecting to run into timeout"); |
| 2137 | f_rtpem_mode(RTPEM[0], RTPEM_MODE_NONE); |
| 2138 | f_sleep(1.5); |
| 2139 | |
| 2140 | log("Resuming should fail now"); |
| 2141 | f_rtpem_conn_refuse_expect(RTPEM[0]); |
| 2142 | f_rtpem_mode(RTPEM[0], RTPEM_MODE_BIDIR); |
| 2143 | f_sleep(0.2); |
| 2144 | f_rtpem_conn_refuse_verify(RTPEM[0]); |
| 2145 | |
| 2146 | setverdict(pass); |
| 2147 | } |
| 2148 | |
Harald Welte | 00a067f | 2017-09-13 23:27:17 +0200 | [diff] [blame] | 2149 | control { |
| 2150 | execute(TC_selftest()); |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 2151 | execute(TC_crcx()); |
Philipp Maier | 45635f4 | 2018-06-05 17:28:02 +0200 | [diff] [blame] | 2152 | execute(TC_crcx_no_lco()); |
Philipp Maier | bb7a01c | 2018-02-01 12:32:57 +0100 | [diff] [blame] | 2153 | execute(TC_crcx_noprefix()); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 2154 | execute(TC_crcx_unsupp_mode()); |
| 2155 | execute(TC_crcx_early_bidir_mode()); |
| 2156 | execute(TC_crcx_unsupp_param()); |
| 2157 | execute(TC_crcx_missing_callid()); |
| 2158 | execute(TC_crcx_missing_mode()); |
| 2159 | execute(TC_crcx_unsupp_packet_intv()); |
| 2160 | execute(TC_crcx_illegal_double_lco()); |
| 2161 | execute(TC_crcx_sdp()); |
Philipp Maier | 5e06cee | 2018-02-01 18:28:08 +0100 | [diff] [blame] | 2162 | execute(TC_crcx_wildcarded()); |
| 2163 | execute(TC_crcx_wildcarded_exhaust()); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 2164 | execute(TC_mdcx_without_crcx()); |
| 2165 | execute(TC_dlcx_without_crcx()); |
Philipp Maier | 8a3dc92 | 2018-02-02 14:55:12 +0100 | [diff] [blame] | 2166 | execute(TC_mdcx_wildcarded()); |
| 2167 | execute(TC_dlcx_wildcarded()); |
Harald Welte | 79181ff | 2017-11-18 19:26:11 +0100 | [diff] [blame] | 2168 | execute(TC_crcx_and_dlcx_ep_callid_connid()); |
| 2169 | execute(TC_crcx_and_dlcx_ep_callid()); |
| 2170 | execute(TC_crcx_and_dlcx_ep()); |
Harald Welte | 6d167f8 | 2017-11-18 19:41:35 +0100 | [diff] [blame] | 2171 | execute(TC_crcx_and_dlcx_ep_callid_inval()); |
| 2172 | execute(TC_crcx_and_dlcx_ep_callid_connid_inval()); |
Harald Welte | f53f164 | 2017-11-18 19:57:11 +0100 | [diff] [blame] | 2173 | execute(TC_crcx_and_dlcx_retrans()); |
Harald Welte | 33d8216 | 2017-12-28 03:21:57 +0100 | [diff] [blame] | 2174 | |
Pau Espin Pedrol | b2c6b38 | 2019-05-14 13:40:49 +0200 | [diff] [blame] | 2175 | execute(TC_crcx_osmux_wildcard()); |
| 2176 | execute(TC_crcx_osmux_fixed()); |
| 2177 | execute(TC_crcx_osmux_fixed_twice()); |
| 2178 | execute(TC_one_crcx_receive_only_osmux()); |
| 2179 | execute(TC_one_crcx_loopback_osmux()); |
| 2180 | execute(TC_two_crcx_and_rtp_osmux()); |
| 2181 | execute(TC_two_crcx_and_rtp_osmux_bidir()); |
| 2182 | execute(TC_two_crcx_mdcx_and_rtp_osmux_wildcard()); |
| 2183 | execute(TC_two_crcx_mdcx_and_rtp_osmux_fixed()); |
| 2184 | |
Harald Welte | 33d8216 | 2017-12-28 03:21:57 +0100 | [diff] [blame] | 2185 | execute(TC_crcx_dlcx_30ep()); |
Harald Welte | bb7523b | 2018-03-29 08:52:01 +0200 | [diff] [blame] | 2186 | |
| 2187 | execute(TC_rtpem_selftest()); |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 2188 | |
| 2189 | execute(TC_one_crcx_receive_only_rtp()); |
| 2190 | execute(TC_one_crcx_loopback_rtp()); |
Harald Welte | bb7523b | 2018-03-29 08:52:01 +0200 | [diff] [blame] | 2191 | execute(TC_two_crcx_and_rtp()); |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 2192 | execute(TC_two_crcx_and_rtp_bidir()); |
Philipp Maier | 7df85f6 | 2018-07-25 10:26:09 +0200 | [diff] [blame] | 2193 | execute(TC_two_crcx_diff_pt_and_rtp()); |
| 2194 | execute(TC_two_crcx_diff_pt_and_rtp_bidir()); |
Philipp Maier | 2321ef9 | 2018-06-27 17:52:04 +0200 | [diff] [blame] | 2195 | execute(TC_two_crcx_mdcx_and_rtp()); |
| 2196 | execute(TC_two_crcx_and_unsolicited_rtp()); |
| 2197 | execute(TC_two_crcx_and_one_mdcx_rtp_ho()); |
Philipp Maier | 6d4e094 | 2019-02-21 17:35:01 +0100 | [diff] [blame] | 2198 | execute(TC_ts101318_rfc5993_rtp_conversion()); |
Philipp Maier | 4f764ce | 2019-03-07 10:54:10 +0100 | [diff] [blame] | 2199 | execute(TC_amr_oa_bwe_rtp_conversion()); |
| 2200 | execute(TC_amr_oa_oa_rtp_conversion()); |
| 2201 | execute(TC_amr_bwe_bwe_rtp_conversion()); |
Oliver Smith | 021141e | 2019-06-25 12:09:01 +0200 | [diff] [blame] | 2202 | |
Pau Espin Pedrol | d19ba6d | 2020-01-03 20:01:48 +0100 | [diff] [blame] | 2203 | execute(TC_conn_timeout()); |
Harald Welte | 00a067f | 2017-09-13 23:27:17 +0200 | [diff] [blame] | 2204 | } |
| 2205 | } |