Harald Welte | 00a067f | 2017-09-13 23:27:17 +0200 | [diff] [blame] | 1 | module MGCP_Test { |
Harald Welte | f07c286 | 2017-11-18 17:16:24 +0100 | [diff] [blame] | 2 | import from Osmocom_Types all; |
Harald Welte | 00a067f | 2017-09-13 23:27:17 +0200 | [diff] [blame] | 3 | import from MGCP_Types all; |
Harald Welte | 4029e8c | 2017-11-23 22:00:42 +0100 | [diff] [blame] | 4 | import from MGCP_Templates all; |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 5 | import from SDP_Types all; |
| 6 | import from MGCP_CodecPort all; |
| 7 | import from MGCP_CodecPort_CtrlFunct all; |
Harald Welte | f07c286 | 2017-11-18 17:16:24 +0100 | [diff] [blame] | 8 | import from RTP_CodecPort all; |
| 9 | import from RTP_CodecPort_CtrlFunct all; |
| 10 | import from RTP_Endpoint all; |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 11 | import from IPL4asp_Types all; |
Harald Welte | 00a067f | 2017-09-13 23:27:17 +0200 | [diff] [blame] | 12 | |
Harald Welte | 21ba557 | 2017-09-19 17:55:05 +0800 | [diff] [blame] | 13 | /* any variables declared in the component will be available to |
| 14 | * all functions that 'run on' the named component, similar to |
| 15 | * class members in C++ */ |
Harald Welte | 00a067f | 2017-09-13 23:27:17 +0200 | [diff] [blame] | 16 | type component dummy_CT { |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 17 | port MGCP_CODEC_PT MGCP; |
Harald Welte | f07c286 | 2017-11-18 17:16:24 +0100 | [diff] [blame] | 18 | port RTP_CODEC_PT RTP; |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 19 | var boolean initialized := false; |
Harald Welte | 5501536 | 2017-11-18 16:02:42 +0100 | [diff] [blame] | 20 | var ConnectionId g_mgcp_conn_id := -1; |
Harald Welte | e1e18c5 | 2017-09-17 16:23:07 +0800 | [diff] [blame] | 21 | var integer g_trans_id; |
Harald Welte | f07c286 | 2017-11-18 17:16:24 +0100 | [diff] [blame] | 22 | |
| 23 | var RtpEndpoint g_rtp_ep[2]; |
Harald Welte | 00a067f | 2017-09-13 23:27:17 +0200 | [diff] [blame] | 24 | }; |
| 25 | |
Harald Welte | e1e18c5 | 2017-09-17 16:23:07 +0800 | [diff] [blame] | 26 | function get_next_trans_id() runs on dummy_CT return MgcpTransId { |
| 27 | var MgcpTransId tid := int2str(g_trans_id); |
| 28 | g_trans_id := g_trans_id + 1; |
| 29 | return tid; |
| 30 | } |
| 31 | |
Harald Welte | 21ba557 | 2017-09-19 17:55:05 +0800 | [diff] [blame] | 32 | /* all parameters declared here can be modified / overridden by |
| 33 | * the config file in the [MODULE_PARAMETERS] section. If no |
| 34 | * config file is used or the file doesn't specify them, the |
| 35 | * default values assigned below are used */ |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 36 | modulepar { |
| 37 | PortNumber mp_local_udp_port := 2727; |
| 38 | charstring mp_local_ip := "127.0.0.1"; |
| 39 | PortNumber mp_remote_udp_port := 2427; |
| 40 | charstring mp_remote_ip := "127.0.0.1"; |
Harald Welte | f07c286 | 2017-11-18 17:16:24 +0100 | [diff] [blame] | 41 | PortNumber mp_local_rtp_port_base := 10000; |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 42 | } |
| 43 | |
Harald Welte | 21ba557 | 2017-09-19 17:55:05 +0800 | [diff] [blame] | 44 | /* initialization function, called by each test case at the |
| 45 | * beginning, but 'initialized' variable ensures its body is |
| 46 | * only executed once */ |
Harald Welte | edc45c1 | 2017-11-18 19:15:05 +0100 | [diff] [blame] | 47 | private function f_init(template MgcpEndpoint ep := omit) runs on dummy_CT { |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 48 | var Result res; |
Harald Welte | f07c286 | 2017-11-18 17:16:24 +0100 | [diff] [blame] | 49 | var uint32_t ssrc; |
Harald Welte | edc45c1 | 2017-11-18 19:15:05 +0100 | [diff] [blame] | 50 | if (initialized == false) { |
| 51 | initialized := true; |
| 52 | |
| 53 | /* some random number for the initial transaction id */ |
| 54 | g_trans_id := float2int(rnd()*65535.0); |
| 55 | map(self:MGCP, system:MGCP_CODEC_PT); |
| 56 | /* connect the MGCP test port using the given |
| 57 | * source/destionation ip/port and store the connection id in g_mgcp_conn_id |
| 58 | * */ |
| 59 | res := MGCP_CodecPort_CtrlFunct.f_IPL4_connect(MGCP, mp_remote_ip, mp_remote_udp_port, mp_local_ip, mp_local_udp_port, 0, { udp := {} }); |
| 60 | g_mgcp_conn_id := res.connId; |
| 61 | |
| 62 | map(self:RTP, system:RTP_CODEC_PT); |
| 63 | ssrc := float2int(rnd()*4294967296.0); |
| 64 | rtp_endpoint_init(g_rtp_ep[0], mp_local_ip, mp_local_rtp_port_base, ssrc); |
| 65 | rtp_endpoint_bind(RTP, g_rtp_ep[0]); |
| 66 | rtp_endpoint_init(g_rtp_ep[1], mp_local_ip, mp_local_rtp_port_base+2, ssrc); |
| 67 | rtp_endpoint_bind(RTP, g_rtp_ep[1]); |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 68 | } |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 69 | |
Harald Welte | edc45c1 | 2017-11-18 19:15:05 +0100 | [diff] [blame] | 70 | if (isvalue(ep)) { |
| 71 | /* do a DLCX on all connections of the EP */ |
| 72 | f_dlcx_ignore(valueof(ep)); |
| 73 | } |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 74 | } |
| 75 | |
Harald Welte | 00a067f | 2017-09-13 23:27:17 +0200 | [diff] [blame] | 76 | testcase TC_selftest() runs on dummy_CT { |
| 77 | const charstring c_auep := "AUEP 158663169 ds/e1-1/2@172.16.6.66 MGCP 1.0\r\n"; |
| 78 | const charstring c_mdcx3 := "MDCX 18983215 1@mgw MGCP 1.0\r\n"; |
| 79 | const charstring c_mdcx3_ret := "200 18983215 OK\r\n" & |
| 80 | "I: 1\n" & |
| 81 | "\n" & |
| 82 | "v=0\r\n" & |
| 83 | "o=- 1 23 IN IP4 0.0.0.0\r\n" & |
| 84 | "s=-\r\n" & |
| 85 | "c=IN IP4 0.0.0.0\r\n" & |
| 86 | "t=0 0\r\n" & |
| 87 | "m=audio 0 RTP/AVP 126\r\n" & |
| 88 | "a=rtpmap:126 AMR/8000\r\n" & |
| 89 | "a=ptime:20\r\n"; |
| 90 | const charstring c_mdcx4 := "MDCX 18983216 1@mgw MGCP 1.0\r\n" & |
| 91 | "M: sendrecv\r" & |
| 92 | "C: 2\r\n" & |
| 93 | "I: 1\r\n" & |
| 94 | "L: p:20, a:AMR, nt:IN\r\n" & |
| 95 | "\n" & |
| 96 | "v=0\r\n" & |
| 97 | "o=- 1 23 IN IP4 0.0.0.0\r\n" & |
Harald Welte | 2871d0b | 2017-09-14 22:42:12 +0800 | [diff] [blame] | 98 | "s=-\r\n" & |
Harald Welte | 00a067f | 2017-09-13 23:27:17 +0200 | [diff] [blame] | 99 | "c=IN IP4 0.0.0.0\r\n" & |
| 100 | "t=0 0\r\n" & |
| 101 | "m=audio 4441 RTP/AVP 99\r\n" & |
| 102 | "a=rtpmap:99 AMR/8000\r\n" & |
| 103 | "a=ptime:40\r\n"; |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 104 | const charstring c_crcx510_ret := "510 23 FAIL\r\n" |
Harald Welte | 00a067f | 2017-09-13 23:27:17 +0200 | [diff] [blame] | 105 | |
| 106 | log(c_auep); |
| 107 | log(dec_MgcpCommand(c_auep)); |
| 108 | |
| 109 | log(c_mdcx3); |
| 110 | log(dec_MgcpCommand(c_mdcx3)); |
| 111 | |
| 112 | log(c_mdcx3_ret); |
| 113 | log(dec_MgcpResponse(c_mdcx3_ret)); |
| 114 | |
| 115 | log(c_mdcx4); |
| 116 | log(dec_MgcpCommand(c_mdcx4)); |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 117 | |
| 118 | log(ts_CRCX("23", "42@mgw", "sendrecv", '1234'H)); |
| 119 | log(enc_MgcpCommand(valueof(ts_CRCX("23", "42@mgw", "sendrecv", '1234'H)))); |
| 120 | |
| 121 | log(c_crcx510_ret); |
| 122 | log(dec_MgcpResponse(c_crcx510_ret)); |
| 123 | log(dec_MgcpMessage(c_crcx510_ret)); |
| 124 | } |
| 125 | |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 126 | /* CRCX test ideas: |
Harald Welte | e0b331f | 2017-11-18 20:34:33 +0100 | [diff] [blame] | 127 | * x without mandatory CallId |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 128 | * - with forbidden parameters (e.g. Capabilities, PackageList, ... |
| 129 | * - CRCX with remote session description and without |
| 130 | * |
| 131 | * general ideas: |
Harald Welte | e0b331f | 2017-11-18 20:34:33 +0100 | [diff] [blame] | 132 | * x packetization != 20ms |
| 133 | * x invalid mode |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 134 | * x unsupported mode (517) |
| 135 | * x bidirectional mode before RemoteConnDesc: 527 |
| 136 | * - invalid codec |
Harald Welte | e0b331f | 2017-11-18 20:34:33 +0100 | [diff] [blame] | 137 | * x retransmission of same transaction |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 138 | * - unsupported LocalConnectionOptions ("b", "a", "e", "gc", "s", "r", "k", ..) |
| 139 | */ |
| 140 | |
Harald Welte | 21ba557 | 2017-09-19 17:55:05 +0800 | [diff] [blame] | 141 | /* build a receive template for receiving a MGCP message. You |
| 142 | * pass the MGCP response template in, and it will generate an |
| 143 | * MGCP_RecvFrom template that can match the primitives arriving on the |
| 144 | * MGCP_CodecPort */ |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 145 | function tr_MGCP_RecvFrom_R(template MgcpResponse resp) runs on dummy_CT return template MGCP_RecvFrom { |
| 146 | var template MGCP_RecvFrom mrf := { |
Harald Welte | 5501536 | 2017-11-18 16:02:42 +0100 | [diff] [blame] | 147 | connId := g_mgcp_conn_id, |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 148 | remName := mp_remote_ip, |
| 149 | remPort := mp_remote_udp_port, |
| 150 | locName := mp_local_ip, |
| 151 | locPort := mp_local_udp_port, |
| 152 | msg := { response := resp } |
| 153 | } |
| 154 | return mrf; |
| 155 | } |
| 156 | |
| 157 | /* Send a MGCP request + receive a (matching!) response */ |
| 158 | function mgcp_transceive_mgw(template MgcpCommand cmd, template MgcpResponse resp := ?) runs on dummy_CT return MgcpResponse { |
| 159 | var MgcpMessage msg := { command := valueof(cmd) }; |
| 160 | resp.line.trans_id := cmd.line.trans_id; |
| 161 | var template MGCP_RecvFrom mrt := tr_MGCP_RecvFrom_R(resp); |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 162 | var MGCP_RecvFrom mrf; |
| 163 | timer T := 5.0; |
| 164 | |
Harald Welte | 5501536 | 2017-11-18 16:02:42 +0100 | [diff] [blame] | 165 | MGCP.send(t_MGCP_Send(g_mgcp_conn_id, msg)); |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 166 | T.start; |
| 167 | alt { |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 168 | [] MGCP.receive(mrt) -> value mrf { } |
| 169 | [] MGCP.receive(tr_MGCP_RecvFrom_R(?)) { setverdict(fail); } |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 170 | [] MGCP.receive { repeat; } |
| 171 | [] T.timeout { setverdict(fail); } |
| 172 | } |
| 173 | T.stop; |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 174 | |
| 175 | if (isbound(mrf) and isbound(mrf.msg) and ischosen(mrf.msg.response)) { |
| 176 | return mrf.msg.response; |
| 177 | } else { |
| 178 | var MgcpResponse r := { line := { code := "999", trans_id := valueof(cmd.line.trans_id) } }; |
| 179 | return r; |
| 180 | } |
Harald Welte | 00a067f | 2017-09-13 23:27:17 +0200 | [diff] [blame] | 181 | } |
| 182 | |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 183 | function extract_conn_id(MgcpResponse resp) return MgcpConnectionId { |
| 184 | var integer i; |
| 185 | for (i := 0; i < lengthof(resp.params); i := i + 1) { |
| 186 | var MgcpParameter par := resp.params[i]; |
| 187 | if (par.code == "I") { |
| 188 | return str2hex(par.val); |
| 189 | } |
| 190 | } |
| 191 | setverdict(fail); |
| 192 | return '00000000'H; |
| 193 | } |
| 194 | |
Harald Welte | 10889c1 | 2017-11-18 19:40:31 +0100 | [diff] [blame] | 195 | function f_dlcx(MgcpEndpoint ep, template MgcpResponseCode ret_code, template charstring ret_val, |
| 196 | template MgcpCallId call_id := omit, |
| 197 | template MgcpConnectionId conn_id := omit) runs on dummy_CT { |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 198 | var template MgcpCommand cmd; |
| 199 | var MgcpResponse resp; |
| 200 | var template MgcpResponse rtmpl := { |
| 201 | line := { |
Harald Welte | 10889c1 | 2017-11-18 19:40:31 +0100 | [diff] [blame] | 202 | code := ret_code, |
| 203 | string := ret_val |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 204 | }, |
| 205 | params := *, |
| 206 | sdp := * |
| 207 | }; |
Harald Welte | c40e0c3 | 2017-11-18 19:08:22 +0100 | [diff] [blame] | 208 | cmd := ts_DLCX(get_next_trans_id(), ep, call_id, conn_id); |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 209 | resp := mgcp_transceive_mgw(cmd, rtmpl); |
| 210 | } |
| 211 | |
Harald Welte | 10889c1 | 2017-11-18 19:40:31 +0100 | [diff] [blame] | 212 | /* Send DLCX and expect OK response */ |
| 213 | function f_dlcx_ok(MgcpEndpoint ep, template MgcpCallId call_id := omit, |
| 214 | template MgcpConnectionId conn_id := omit) runs on dummy_CT { |
| 215 | f_dlcx(ep, "200", "OK", call_id, conn_id); |
| 216 | } |
| 217 | |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 218 | /* Send DLCX and accept any response */ |
Harald Welte | c40e0c3 | 2017-11-18 19:08:22 +0100 | [diff] [blame] | 219 | function f_dlcx_ignore(MgcpEndpoint ep, template MgcpCallId call_id := omit, |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 220 | template MgcpConnectionId conn_id := omit) runs on dummy_CT { |
Harald Welte | 10889c1 | 2017-11-18 19:40:31 +0100 | [diff] [blame] | 221 | f_dlcx(ep, ?, *, call_id, conn_id); |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 222 | } |
| 223 | |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 224 | /* test valid CRCX without SDP */ |
| 225 | testcase TC_crcx() runs on dummy_CT { |
| 226 | var template MgcpCommand cmd; |
| 227 | var MgcpResponse resp; |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 228 | var MgcpEndpoint ep := "2@mgw"; |
| 229 | var MgcpCallId call_id := '1234'H; |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 230 | |
Harald Welte | edc45c1 | 2017-11-18 19:15:05 +0100 | [diff] [blame] | 231 | f_init(ep); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 232 | |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 233 | /* create the connection on the MGW */ |
| 234 | cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id); |
Harald Welte | 9988d28 | 2017-11-18 19:22:00 +0100 | [diff] [blame] | 235 | resp := mgcp_transceive_mgw(cmd, tr_CRCX_ACK); |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 236 | extract_conn_id(resp); |
| 237 | |
| 238 | /* clean-up */ |
| 239 | f_dlcx_ok(ep, call_id); |
| 240 | |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 241 | setverdict(pass); |
| 242 | } |
| 243 | |
| 244 | /* test CRCX with unsupported mode, expect 517 */ |
| 245 | testcase TC_crcx_unsupp_mode() runs on dummy_CT { |
| 246 | var template MgcpCommand cmd; |
| 247 | var MgcpResponse resp; |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 248 | var MgcpEndpoint ep := "2@mgw"; |
| 249 | var MgcpCallId call_id := '1233'H; |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 250 | var template MgcpResponse rtmpl := tr_MgcpResp_Err("517"); |
| 251 | |
Harald Welte | edc45c1 | 2017-11-18 19:15:05 +0100 | [diff] [blame] | 252 | f_init(ep); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 253 | |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 254 | cmd := ts_CRCX(get_next_trans_id(), ep, "netwtest", call_id); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 255 | resp := mgcp_transceive_mgw(cmd, rtmpl); |
| 256 | setverdict(pass); |
| 257 | } |
| 258 | |
Harald Welte | 21ba557 | 2017-09-19 17:55:05 +0800 | [diff] [blame] | 259 | /* test CRCX with early bi-directional mode, expect 527 as |
| 260 | * bi-diretional media can only be established once both local and |
| 261 | * remote side are specified, see MGCP RFC */ |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 262 | testcase TC_crcx_early_bidir_mode() runs on dummy_CT { |
| 263 | var template MgcpCommand cmd; |
| 264 | var MgcpResponse resp; |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 265 | var MgcpEndpoint ep := "2@mgw"; |
| 266 | var MgcpCallId call_id := '1232'H; |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 267 | var template MgcpResponse rtmpl := tr_MgcpResp_Err("527"); |
| 268 | |
Harald Welte | edc45c1 | 2017-11-18 19:15:05 +0100 | [diff] [blame] | 269 | f_init(ep); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 270 | |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 271 | cmd := ts_CRCX(get_next_trans_id(), ep, "sendrecv", call_id); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 272 | resp := mgcp_transceive_mgw(cmd, rtmpl); |
| 273 | setverdict(pass); |
| 274 | } |
| 275 | |
| 276 | /* test CRCX with unsupported Parameters */ |
| 277 | testcase TC_crcx_unsupp_param() runs on dummy_CT { |
| 278 | var template MgcpCommand cmd; |
| 279 | var MgcpResponse resp; |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 280 | var MgcpEndpoint ep := "2@mgw"; |
| 281 | var MgcpCallId call_id := '1231'H; |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 282 | var template MgcpResponse rtmpl := tr_MgcpResp_Err("539"); |
| 283 | |
Harald Welte | edc45c1 | 2017-11-18 19:15:05 +0100 | [diff] [blame] | 284 | f_init(ep); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 285 | |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 286 | cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id); |
Harald Welte | a01e38d | 2017-11-18 18:40:01 +0100 | [diff] [blame] | 287 | /* osmo-bsc_mgcp/mgw doesn't implement notifications */ |
| 288 | f_mgcp_par_append(cmd.params, MgcpParameter:{ "N", "foobar" }); |
| 289 | |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 290 | resp := mgcp_transceive_mgw(cmd, rtmpl); |
| 291 | setverdict(pass); |
| 292 | } |
| 293 | |
| 294 | /* test CRCX with missing CallId */ |
| 295 | testcase TC_crcx_missing_callid() runs on dummy_CT { |
| 296 | var template MgcpCommand cmd; |
| 297 | var MgcpResponse resp; |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 298 | var MgcpEndpoint ep := "2@mgw"; |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 299 | var template MgcpResponse rtmpl := tr_MgcpResp_Err("400"); |
| 300 | |
Harald Welte | edc45c1 | 2017-11-18 19:15:05 +0100 | [diff] [blame] | 301 | f_init(ep); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 302 | |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 303 | cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", '1230'H); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 304 | cmd.params := { |
| 305 | t_MgcpParConnMode("recvonly"), |
| 306 | t_MgcpParLocConnOpt("p:20") |
| 307 | } |
| 308 | resp := mgcp_transceive_mgw(cmd, rtmpl); |
| 309 | setverdict(pass); |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 310 | |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | /* test CRCX with missing Mode */ |
| 314 | testcase TC_crcx_missing_mode() runs on dummy_CT { |
| 315 | var template MgcpCommand cmd; |
| 316 | var MgcpResponse resp; |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 317 | var MgcpEndpoint ep := "2@mgw"; |
| 318 | var MgcpCallId call_id := '1229'H; |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 319 | var template MgcpResponse rtmpl := tr_MgcpResp_Err("400"); |
| 320 | |
Harald Welte | edc45c1 | 2017-11-18 19:15:05 +0100 | [diff] [blame] | 321 | f_init(ep); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 322 | |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 323 | cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 324 | cmd.params := { |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 325 | ts_MgcpParCallId(call_id), |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 326 | t_MgcpParLocConnOpt("p:20") |
| 327 | } |
| 328 | resp := mgcp_transceive_mgw(cmd, rtmpl); |
| 329 | setverdict(pass); |
| 330 | } |
| 331 | |
| 332 | /* test CRCX with unsupported packetization interval */ |
| 333 | testcase TC_crcx_unsupp_packet_intv() runs on dummy_CT { |
| 334 | var template MgcpCommand cmd; |
| 335 | var MgcpResponse resp; |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 336 | var MgcpEndpoint ep := "2@mgw"; |
| 337 | var MgcpCallId call_id := '1228'H; |
Harald Welte | 0d19861 | 2017-11-18 19:58:31 +0100 | [diff] [blame] | 338 | var template MgcpResponse rtmpl := tr_MgcpResp_Err("535"); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 339 | |
Harald Welte | edc45c1 | 2017-11-18 19:15:05 +0100 | [diff] [blame] | 340 | f_init(ep); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 341 | |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 342 | cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id); |
Harald Welte | a01e38d | 2017-11-18 18:40:01 +0100 | [diff] [blame] | 343 | cmd.params[2] := t_MgcpParLocConnOpt("p:111"); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 344 | resp := mgcp_transceive_mgw(cmd, rtmpl); |
| 345 | setverdict(pass); |
| 346 | } |
| 347 | |
| 348 | /* test CRCX with illegal double presence of local connection option */ |
| 349 | testcase TC_crcx_illegal_double_lco() runs on dummy_CT { |
| 350 | var template MgcpCommand cmd; |
| 351 | var MgcpResponse resp; |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 352 | var MgcpEndpoint ep := "2@mgw"; |
| 353 | var MgcpCallId call_id := '1227'H; |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 354 | var template MgcpResponse rtmpl := tr_MgcpResp_Err("524"); |
| 355 | |
Harald Welte | edc45c1 | 2017-11-18 19:15:05 +0100 | [diff] [blame] | 356 | f_init(ep); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 357 | |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 358 | cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id); |
Harald Welte | a01e38d | 2017-11-18 18:40:01 +0100 | [diff] [blame] | 359 | /* p:20 is permitted only once and not twice! */ |
| 360 | cmd.params[2] := t_MgcpParLocConnOpt("p:20, a:AMR, p:20"); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 361 | resp := mgcp_transceive_mgw(cmd, rtmpl); |
| 362 | setverdict(pass); |
| 363 | } |
| 364 | |
| 365 | /* test valid CRCX with valid SDP */ |
| 366 | testcase TC_crcx_sdp() runs on dummy_CT { |
| 367 | var template MgcpCommand cmd; |
| 368 | var MgcpResponse resp; |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 369 | var MgcpEndpoint ep := "2@mgw"; |
| 370 | var MgcpCallId call_id := '1226'H; |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 371 | |
Harald Welte | edc45c1 | 2017-11-18 19:15:05 +0100 | [diff] [blame] | 372 | f_init(ep); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 373 | |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 374 | cmd := ts_CRCX(get_next_trans_id(), ep, "sendrecv", call_id); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 375 | cmd.sdp := ts_SDP("127.0.0.1", "127.0.0.2", "23", "42", 2344, { "98" }, |
| 376 | { valueof(ts_SDP_rtpmap(98, "AMR/8000")), |
| 377 | valueof(ts_SDP_ptime(20)) }); |
Harald Welte | 9988d28 | 2017-11-18 19:22:00 +0100 | [diff] [blame] | 378 | resp := mgcp_transceive_mgw(cmd, tr_CRCX_ACK); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 379 | setverdict(pass); |
| 380 | } |
| 381 | |
| 382 | /* TODO: various SDP related bits */ |
| 383 | |
| 384 | |
| 385 | /* TODO: CRCX with X-Osmux */ |
| 386 | /* TODO: double CRCX without force_realloc */ |
| 387 | |
| 388 | /* TODO: MDCX (various) */ |
| 389 | |
| 390 | /* TODO: MDCX without CRCX first */ |
| 391 | testcase TC_mdcx_without_crcx() runs on dummy_CT { |
| 392 | var template MgcpCommand cmd; |
| 393 | var MgcpResponse resp; |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 394 | var MgcpEndpoint ep := "3@mgw"; |
| 395 | var MgcpCallId call_id := '1225'H; |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 396 | var template MgcpResponse rtmpl := { |
| 397 | line := { |
| 398 | /* TODO: accept/enforce better error? */ |
| 399 | code := "400", |
| 400 | string := ? |
| 401 | }, |
| 402 | params:= { }, |
| 403 | sdp := omit |
| 404 | }; |
| 405 | |
Harald Welte | edc45c1 | 2017-11-18 19:15:05 +0100 | [diff] [blame] | 406 | f_init(ep); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 407 | |
Harald Welte | 2bcfd3a | 2017-11-18 22:14:35 +0100 | [diff] [blame] | 408 | 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] | 409 | cmd.sdp := ts_SDP("127.0.0.1", "127.0.0.2", "23", "42", 2344, { "98" }, |
| 410 | { valueof(ts_SDP_rtpmap(98, "AMR/8000")), |
| 411 | valueof(ts_SDP_ptime(20)) }); |
| 412 | resp := mgcp_transceive_mgw(cmd, rtmpl); |
| 413 | setverdict(pass); |
| 414 | } |
| 415 | |
| 416 | /* DLCX without CRCX first */ |
| 417 | testcase TC_dlcx_without_crcx() runs on dummy_CT { |
| 418 | var template MgcpCommand cmd; |
| 419 | var MgcpResponse resp; |
Harald Welte | edc45c1 | 2017-11-18 19:15:05 +0100 | [diff] [blame] | 420 | var MgcpEndpoint ep := "4@mgw"; |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 421 | var template MgcpResponse rtmpl := { |
| 422 | line := { |
| 423 | /* TODO: accept/enforce better error? */ |
| 424 | code := "400", |
| 425 | string := ? |
| 426 | }, |
| 427 | params:= { }, |
| 428 | sdp := omit |
| 429 | }; |
| 430 | |
Harald Welte | edc45c1 | 2017-11-18 19:15:05 +0100 | [diff] [blame] | 431 | f_init(ep); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 432 | |
Harald Welte | edc45c1 | 2017-11-18 19:15:05 +0100 | [diff] [blame] | 433 | cmd := ts_DLCX(get_next_trans_id(), ep, '41234'H); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 434 | resp := mgcp_transceive_mgw(cmd, rtmpl); |
| 435 | setverdict(pass); |
| 436 | } |
| 437 | |
Harald Welte | 79181ff | 2017-11-18 19:26:11 +0100 | [diff] [blame] | 438 | /* Test (valid) CRCX followed by (valid) DLCX containig EP+CallId+ConnId */ |
| 439 | testcase TC_crcx_and_dlcx_ep_callid_connid() runs on dummy_CT { |
| 440 | var template MgcpCommand cmd; |
| 441 | var MgcpResponse resp; |
| 442 | var MgcpEndpoint ep := "5@mgw"; |
| 443 | var MgcpCallId call_id := '51234'H; |
| 444 | |
| 445 | f_init(ep); |
| 446 | |
| 447 | cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id); |
| 448 | resp := mgcp_transceive_mgw(cmd, tr_CRCX_ACK); |
| 449 | |
| 450 | f_dlcx_ok(ep, call_id, extract_conn_id(resp)); |
| 451 | |
| 452 | setverdict(pass); |
| 453 | } |
| 454 | |
| 455 | /* Test (valid) CRCX followed by (valid) DLCX containing EP+CallId */ |
| 456 | testcase TC_crcx_and_dlcx_ep_callid() runs on dummy_CT { |
Harald Welte | 5b4c44e | 2017-09-17 16:35:27 +0800 | [diff] [blame] | 457 | var template MgcpCommand cmd; |
| 458 | var MgcpResponse resp; |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 459 | var MgcpEndpoint ep := "5@mgw"; |
Harald Welte | 6d167f8 | 2017-11-18 19:41:35 +0100 | [diff] [blame] | 460 | var MgcpCallId call_id := '51233'H; |
Harald Welte | 5b4c44e | 2017-09-17 16:35:27 +0800 | [diff] [blame] | 461 | |
Harald Welte | edc45c1 | 2017-11-18 19:15:05 +0100 | [diff] [blame] | 462 | f_init(ep); |
Harald Welte | 5b4c44e | 2017-09-17 16:35:27 +0800 | [diff] [blame] | 463 | |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 464 | cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id); |
Harald Welte | 9988d28 | 2017-11-18 19:22:00 +0100 | [diff] [blame] | 465 | resp := mgcp_transceive_mgw(cmd, tr_CRCX_ACK); |
Harald Welte | 5b4c44e | 2017-09-17 16:35:27 +0800 | [diff] [blame] | 466 | |
Harald Welte | ba62c8c | 2017-11-18 18:26:49 +0100 | [diff] [blame] | 467 | f_dlcx_ok(ep, call_id); |
Harald Welte | 5b4c44e | 2017-09-17 16:35:27 +0800 | [diff] [blame] | 468 | |
| 469 | setverdict(pass); |
| 470 | } |
| 471 | |
Harald Welte | 79181ff | 2017-11-18 19:26:11 +0100 | [diff] [blame] | 472 | /* Test (valid) CRCX followed by (valid) DLCX containing EP */ |
| 473 | testcase TC_crcx_and_dlcx_ep() runs on dummy_CT { |
| 474 | var template MgcpCommand cmd; |
| 475 | var MgcpResponse resp; |
| 476 | var MgcpEndpoint ep := "5@mgw"; |
Harald Welte | 6d167f8 | 2017-11-18 19:41:35 +0100 | [diff] [blame] | 477 | var MgcpCallId call_id := '51232'H; |
Harald Welte | 79181ff | 2017-11-18 19:26:11 +0100 | [diff] [blame] | 478 | |
| 479 | f_init(ep); |
| 480 | |
| 481 | cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id); |
| 482 | resp := mgcp_transceive_mgw(cmd, tr_CRCX_ACK); |
| 483 | |
| 484 | f_dlcx_ok(ep); |
| 485 | |
| 486 | setverdict(pass); |
| 487 | } |
| 488 | |
| 489 | |
Harald Welte | 6d167f8 | 2017-11-18 19:41:35 +0100 | [diff] [blame] | 490 | /* CRCX + DLCX of valid endpoint but invalid call-id */ |
| 491 | testcase TC_crcx_and_dlcx_ep_callid_inval() runs on dummy_CT { |
| 492 | var template MgcpCommand cmd; |
| 493 | var MgcpResponse resp; |
| 494 | var MgcpEndpoint ep := "5@mgw"; |
| 495 | var MgcpCallId call_id := '51231'H; |
| 496 | |
| 497 | f_init(ep); |
| 498 | |
| 499 | cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id); |
| 500 | resp := mgcp_transceive_mgw(cmd, tr_CRCX_ACK); |
| 501 | |
| 502 | f_dlcx(ep, "516", *, 'ffff'H); |
| 503 | |
| 504 | setverdict(pass); |
| 505 | } |
| 506 | |
| 507 | |
| 508 | /* CRCX + DLCX of valid endpoint and call-id but invalid conn-id */ |
| 509 | testcase TC_crcx_and_dlcx_ep_callid_connid_inval() runs on dummy_CT { |
| 510 | var template MgcpCommand cmd; |
| 511 | var MgcpResponse resp; |
| 512 | var MgcpEndpoint ep := "5@mgw"; |
| 513 | var MgcpCallId call_id := '51230'H; |
| 514 | |
| 515 | f_init(ep); |
| 516 | |
| 517 | cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id); |
| 518 | resp := mgcp_transceive_mgw(cmd, tr_CRCX_ACK); |
| 519 | |
| 520 | f_dlcx(ep, "515", *, call_id, 'ffff'H); |
| 521 | |
| 522 | setverdict(pass); |
| 523 | } |
| 524 | |
| 525 | |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 526 | /* TODO: Double-DLCX (retransmission) */ |
Harald Welte | f53f164 | 2017-11-18 19:57:11 +0100 | [diff] [blame] | 527 | testcase TC_crcx_and_dlcx_retrans() runs on dummy_CT { |
| 528 | var template MgcpCommand cmd; |
| 529 | var MgcpResponse resp; |
| 530 | var MgcpEndpoint ep := "5@mgw"; |
| 531 | var MgcpCallId call_id := '51229'H; |
| 532 | var template MgcpResponse rtmpl := { |
| 533 | line := { |
| 534 | code := "200", |
| 535 | string := "OK" |
| 536 | }, |
| 537 | params:= { }, |
| 538 | sdp := omit |
| 539 | }; |
| 540 | |
| 541 | f_init(ep); |
| 542 | |
| 543 | cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id); |
| 544 | resp := mgcp_transceive_mgw(cmd, tr_CRCX_ACK); |
| 545 | |
| 546 | cmd := ts_DLCX(get_next_trans_id(), ep, call_id); |
| 547 | resp := mgcp_transceive_mgw(cmd, rtmpl); |
| 548 | resp := mgcp_transceive_mgw(cmd, rtmpl); |
| 549 | |
| 550 | setverdict(pass); |
| 551 | } |
| 552 | |
| 553 | |
| 554 | |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 555 | /* TODO: Double-DLCX (no retransmission) */ |
| 556 | |
| 557 | |
| 558 | |
| 559 | /* TODO: AUEP (various) */ |
| 560 | /* TODO: RSIP (various) */ |
| 561 | /* TODO: RQNT (various) */ |
| 562 | /* TODO: EPCF (various) */ |
| 563 | /* TODO: AUCX (various) */ |
| 564 | /* TODO: invalid verb (various) */ |
| 565 | |
Harald Welte | 00a067f | 2017-09-13 23:27:17 +0200 | [diff] [blame] | 566 | control { |
| 567 | execute(TC_selftest()); |
Harald Welte | 3c6ebb9 | 2017-09-16 00:56:57 +0800 | [diff] [blame] | 568 | execute(TC_crcx()); |
Harald Welte | e636afd | 2017-09-17 16:24:09 +0800 | [diff] [blame] | 569 | execute(TC_crcx_unsupp_mode()); |
| 570 | execute(TC_crcx_early_bidir_mode()); |
| 571 | execute(TC_crcx_unsupp_param()); |
| 572 | execute(TC_crcx_missing_callid()); |
| 573 | execute(TC_crcx_missing_mode()); |
| 574 | execute(TC_crcx_unsupp_packet_intv()); |
| 575 | execute(TC_crcx_illegal_double_lco()); |
| 576 | execute(TC_crcx_sdp()); |
| 577 | execute(TC_mdcx_without_crcx()); |
| 578 | execute(TC_dlcx_without_crcx()); |
Harald Welte | 79181ff | 2017-11-18 19:26:11 +0100 | [diff] [blame] | 579 | execute(TC_crcx_and_dlcx_ep_callid_connid()); |
| 580 | execute(TC_crcx_and_dlcx_ep_callid()); |
| 581 | execute(TC_crcx_and_dlcx_ep()); |
Harald Welte | 6d167f8 | 2017-11-18 19:41:35 +0100 | [diff] [blame] | 582 | execute(TC_crcx_and_dlcx_ep_callid_inval()); |
| 583 | execute(TC_crcx_and_dlcx_ep_callid_connid_inval()); |
Harald Welte | f53f164 | 2017-11-18 19:57:11 +0100 | [diff] [blame] | 584 | execute(TC_crcx_and_dlcx_retrans()); |
Harald Welte | 00a067f | 2017-09-13 23:27:17 +0200 | [diff] [blame] | 585 | } |
| 586 | } |