blob: df07bd0a3154c48961c863eb2f2b21e0ea3bc698 [file] [log] [blame]
Harald Welte00a067f2017-09-13 23:27:17 +02001module MGCP_Test {
Harald Weltef07c2862017-11-18 17:16:24 +01002 import from Osmocom_Types all;
Harald Welte00a067f2017-09-13 23:27:17 +02003 import from MGCP_Types all;
Harald Welte3c6ebb92017-09-16 00:56:57 +08004 import from SDP_Types all;
5 import from MGCP_CodecPort all;
6 import from MGCP_CodecPort_CtrlFunct all;
Harald Weltef07c2862017-11-18 17:16:24 +01007 import from RTP_CodecPort all;
8 import from RTP_CodecPort_CtrlFunct all;
9 import from RTP_Endpoint all;
Harald Welte3c6ebb92017-09-16 00:56:57 +080010 import from IPL4asp_Types all;
Harald Welte00a067f2017-09-13 23:27:17 +020011
Harald Welte21ba5572017-09-19 17:55:05 +080012 /* any variables declared in the component will be available to
13 * all functions that 'run on' the named component, similar to
14 * class members in C++ */
Harald Welte00a067f2017-09-13 23:27:17 +020015 type component dummy_CT {
Harald Welte3c6ebb92017-09-16 00:56:57 +080016 port MGCP_CODEC_PT MGCP;
Harald Weltef07c2862017-11-18 17:16:24 +010017 port RTP_CODEC_PT RTP;
Harald Welte3c6ebb92017-09-16 00:56:57 +080018 var boolean initialized := false;
Harald Welte55015362017-11-18 16:02:42 +010019 var ConnectionId g_mgcp_conn_id := -1;
Harald Weltee1e18c52017-09-17 16:23:07 +080020 var integer g_trans_id;
Harald Weltef07c2862017-11-18 17:16:24 +010021
22 var RtpEndpoint g_rtp_ep[2];
Harald Welte00a067f2017-09-13 23:27:17 +020023 };
24
Harald Weltee1e18c52017-09-17 16:23:07 +080025 function get_next_trans_id() runs on dummy_CT return MgcpTransId {
26 var MgcpTransId tid := int2str(g_trans_id);
27 g_trans_id := g_trans_id + 1;
28 return tid;
29 }
30
Harald Welte21ba5572017-09-19 17:55:05 +080031 /* all parameters declared here can be modified / overridden by
32 * the config file in the [MODULE_PARAMETERS] section. If no
33 * config file is used or the file doesn't specify them, the
34 * default values assigned below are used */
Harald Welte3c6ebb92017-09-16 00:56:57 +080035 modulepar {
36 PortNumber mp_local_udp_port := 2727;
37 charstring mp_local_ip := "127.0.0.1";
38 PortNumber mp_remote_udp_port := 2427;
39 charstring mp_remote_ip := "127.0.0.1";
Harald Weltef07c2862017-11-18 17:16:24 +010040 PortNumber mp_local_rtp_port_base := 10000;
Harald Welte3c6ebb92017-09-16 00:56:57 +080041 }
42
Harald Welte21ba5572017-09-19 17:55:05 +080043 /* initialization function, called by each test case at the
44 * beginning, but 'initialized' variable ensures its body is
45 * only executed once */
Harald Welteedc45c12017-11-18 19:15:05 +010046 private function f_init(template MgcpEndpoint ep := omit) runs on dummy_CT {
Harald Welte3c6ebb92017-09-16 00:56:57 +080047 var Result res;
Harald Weltef07c2862017-11-18 17:16:24 +010048 var uint32_t ssrc;
Harald Welteedc45c12017-11-18 19:15:05 +010049 if (initialized == false) {
50 initialized := true;
51
52 /* some random number for the initial transaction id */
53 g_trans_id := float2int(rnd()*65535.0);
54 map(self:MGCP, system:MGCP_CODEC_PT);
55 /* connect the MGCP test port using the given
56 * source/destionation ip/port and store the connection id in g_mgcp_conn_id
57 * */
58 res := MGCP_CodecPort_CtrlFunct.f_IPL4_connect(MGCP, mp_remote_ip, mp_remote_udp_port, mp_local_ip, mp_local_udp_port, 0, { udp := {} });
59 g_mgcp_conn_id := res.connId;
60
61 map(self:RTP, system:RTP_CODEC_PT);
62 ssrc := float2int(rnd()*4294967296.0);
63 rtp_endpoint_init(g_rtp_ep[0], mp_local_ip, mp_local_rtp_port_base, ssrc);
64 rtp_endpoint_bind(RTP, g_rtp_ep[0]);
65 rtp_endpoint_init(g_rtp_ep[1], mp_local_ip, mp_local_rtp_port_base+2, ssrc);
66 rtp_endpoint_bind(RTP, g_rtp_ep[1]);
Harald Welte3c6ebb92017-09-16 00:56:57 +080067 }
Harald Welte3c6ebb92017-09-16 00:56:57 +080068
Harald Welteedc45c12017-11-18 19:15:05 +010069 if (isvalue(ep)) {
70 /* do a DLCX on all connections of the EP */
71 f_dlcx_ignore(valueof(ep));
72 }
Harald Welte3c6ebb92017-09-16 00:56:57 +080073 }
74
75 /* 3.2.2.6 Connection Mode (sendonly, recvonly, sendrecv, confrnce, inactive, loopback,
76 * conttest, netwloop, netwtest) */
77 template MgcpParameter t_MgcpParConnMode(template MgcpConnectionMode mode) := { "M", mode };
78
79 /* 3.2.2.2 CallId: maximum 32 hex chars */
80 template MgcpParameter ts_MgcpParCallId(MgcpCallId cid) := {
81 code := "C",
82 val := hex2str(cid)
83 };
84
85 /* 3.2.2.18 RequestIdentifier: Maximum 32 hex chars */
86 template MgcpParameter ts_MgcpParReqId(MgcpRequestId rid) := {
87 code := "X",
88 val := hex2str(rid)
89 };
90
91 /* 3.2.2.10: LocalConnectionOptions (codec, packetization, bandwidth, ToS, eco, gain, silence, ...) */
92 template MgcpParameter t_MgcpParLocConnOpt(template charstring lco) := { "L", lco };
93
94 /* 3.2.2.5: ConnectionId: maximum 32 hex chars */
95 template MgcpParameter ts_MgcpParConnectionId(MgcpConnectionId cid) := {
96 code := "I",
97 val := hex2str(cid)
98 };
99
100 /* osmo-bsc_mgcp implements L/C/M/X only, osmo-mgw adds 'I' */
101 /* SDP: osmo-bsc_mgcp implements Tx of v,o,s,c,t,m,a */
102
Harald Weltee636afd2017-09-17 16:24:09 +0800103 template MgcpResponse tr_MgcpResp_Err(template MgcpResponseCode code) := {
104 line := {
105 code := code,
106 trans_id := ?,
107 string := ?
108 },
109 params := {},
110 sdp := omit
111 }
112
Harald Welte3c6ebb92017-09-16 00:56:57 +0800113 template MgcpCommandLine t_MgcpCmdLine(template charstring verb, template MgcpTransId trans_id, template charstring ep) := {
114 verb := verb,
115 trans_id := trans_id,
116 ep := ep,
117 ver := "1.0"
118 };
119
120 template MgcpCommand ts_CRCX(MgcpTransId trans_id, charstring ep, MgcpConnectionMode mode, MgcpCallId call_id, template SDP_Message sdp := omit) := {
121 line := t_MgcpCmdLine("CRCX", trans_id, ep),
122 params := {
123 t_MgcpParConnMode(mode),
124 ts_MgcpParCallId(call_id),
125 //t_MgcpParReqId(omit),
126 t_MgcpParLocConnOpt("p: 20")
127 },
128 sdp := sdp
129 }
130
Harald Welte9988d282017-11-18 19:22:00 +0100131 template MgcpResponse tr_CRCX_ACK := {
132 line := {
133 code := "200",
134 string := "OK"
135 },
136 params:= { { "I", ? }, *},
137 sdp := ?
138 }
139
Harald Weltee636afd2017-09-17 16:24:09 +0800140 template MgcpCommand ts_MDCX(MgcpTransId trans_id, charstring ep, MgcpConnectionMode mode, MgcpCallId call_id, template SDP_Message sdp := omit) := {
141 line := t_MgcpCmdLine("MDCX", trans_id, ep),
142 params := {
143 t_MgcpParConnMode(mode),
144 ts_MgcpParCallId(call_id),
145 //t_MgcpParReqId(omit),
146 t_MgcpParLocConnOpt("p: 20")
147 },
148 sdp := sdp
149 }
150
Harald Weltec40e0c32017-11-18 19:08:22 +0100151 /* have a function that generates a template, rather than a template in order to handle
152 * optional parameters */
153 function ts_DLCX(MgcpTransId trans_id, charstring ep, template MgcpCallId call_id := omit,
154 template MgcpConnectionId conn_id := omit) return template MgcpCommand {
155 var template MgcpCommand cmd;
156 cmd.line := t_MgcpCmdLine("DLCX", trans_id, ep);
157 cmd.params := {};
158 cmd.sdp := omit;
159 if (isvalue(call_id)) {
160 f_mgcp_par_append(cmd.params, ts_MgcpParCallId(valueof(call_id)));
161 if (isvalue(conn_id)) {
162 f_mgcp_par_append(cmd.params, ts_MgcpParConnectionId(valueof(conn_id)));
163 }
164 }
165 return cmd;
Harald Weltee636afd2017-09-17 16:24:09 +0800166 }
167
168 /* SDP Templates */
169 template SDP_Origin ts_SDP_origin(charstring addr, charstring session_id,
170 charstring session_version := "1",
171 charstring addr_type := "IP4",
172 charstring user_name := "-") := {
173 user_name := user_name,
174 session_id := session_id,
175 session_version := session_version,
176 net_type := "IN",
177 addr_type := addr_type,
178 addr := addr
179 }
180
181 template SDP_connection ts_SDP_connection_IP(charstring addr, charstring addr_type := "IP4",
182 template integer ttl := omit,
183 template integer num_of_addr := omit) :={
184 net_type := "IN",
185 addr_type := addr_type,
186 conn_addr := {
187 addr := addr,
188 ttl := ttl,
189 num_of_addr := num_of_addr
190 }
191 }
192
193 template SDP_time ts_SDP_time(charstring beg, charstring end) := {
194 time_field := {
195 start_time := beg,
196 stop_time := end
197 },
198 time_repeat := omit
199 }
200
201 template SDP_media_desc ts_SDP_media_desc(integer port_number, SDP_fmt_list fmts,
202 SDP_attribute_list attributes) := {
203 media_field := {
204 media := "audio",
205 ports := {
206 port_number := port_number,
207 num_of_ports := omit
208 },
209 transport := "ARTP/AVP",
210 fmts := fmts
211 },
212 information := omit,
213 connections := omit,
214 bandwidth := omit,
215 key := omit,
216 attributes := attributes
217 }
218
Harald Welte21ba5572017-09-19 17:55:05 +0800219 /* master template for generating SDP based in template arguments */
Harald Weltee636afd2017-09-17 16:24:09 +0800220 template SDP_Message ts_SDP(charstring local_addr, charstring remote_addr,
221 charstring session_id, charstring session_version,
222 integer rtp_port, SDP_fmt_list fmts,
223 SDP_attribute_list attributes) := {
224 protocol_version := 0,
225 origin := ts_SDP_origin(local_addr, session_id, session_version),
226 session_name := "-",
227 information := omit,
228 uri := omit,
229 emails := omit,
230 phone_numbers := omit,
231 connection := ts_SDP_connection_IP(remote_addr),
232 bandwidth := omit,
233 times := { ts_SDP_time("0","0") },
234 timezone_adjustments := omit,
235 key := omit,
236 attributes := omit,
237 media_list := { ts_SDP_media_desc(rtp_port, fmts, attributes) }
238 }
239
240 template SDP_attribute ts_SDP_rtpmap(integer fmt, charstring val) := {
241 rtpmap := {
242 attr_value := int2str(fmt) & " " & val
243 }
244 }
245 template SDP_attribute ts_SDP_ptime(integer p) := {
246 ptime := {
247 attr_value := int2str(p)
248 }
249 }
250
Harald Welte00a067f2017-09-13 23:27:17 +0200251 testcase TC_selftest() runs on dummy_CT {
252 const charstring c_auep := "AUEP 158663169 ds/e1-1/2@172.16.6.66 MGCP 1.0\r\n";
253 const charstring c_mdcx3 := "MDCX 18983215 1@mgw MGCP 1.0\r\n";
254 const charstring c_mdcx3_ret := "200 18983215 OK\r\n" &
255 "I: 1\n" &
256 "\n" &
257 "v=0\r\n" &
258 "o=- 1 23 IN IP4 0.0.0.0\r\n" &
259 "s=-\r\n" &
260 "c=IN IP4 0.0.0.0\r\n" &
261 "t=0 0\r\n" &
262 "m=audio 0 RTP/AVP 126\r\n" &
263 "a=rtpmap:126 AMR/8000\r\n" &
264 "a=ptime:20\r\n";
265 const charstring c_mdcx4 := "MDCX 18983216 1@mgw MGCP 1.0\r\n" &
266 "M: sendrecv\r" &
267 "C: 2\r\n" &
268 "I: 1\r\n" &
269 "L: p:20, a:AMR, nt:IN\r\n" &
270 "\n" &
271 "v=0\r\n" &
272 "o=- 1 23 IN IP4 0.0.0.0\r\n" &
Harald Welte2871d0b2017-09-14 22:42:12 +0800273 "s=-\r\n" &
Harald Welte00a067f2017-09-13 23:27:17 +0200274 "c=IN IP4 0.0.0.0\r\n" &
275 "t=0 0\r\n" &
276 "m=audio 4441 RTP/AVP 99\r\n" &
277 "a=rtpmap:99 AMR/8000\r\n" &
278 "a=ptime:40\r\n";
Harald Welte3c6ebb92017-09-16 00:56:57 +0800279 const charstring c_crcx510_ret := "510 23 FAIL\r\n"
Harald Welte00a067f2017-09-13 23:27:17 +0200280
281 log(c_auep);
282 log(dec_MgcpCommand(c_auep));
283
284 log(c_mdcx3);
285 log(dec_MgcpCommand(c_mdcx3));
286
287 log(c_mdcx3_ret);
288 log(dec_MgcpResponse(c_mdcx3_ret));
289
290 log(c_mdcx4);
291 log(dec_MgcpCommand(c_mdcx4));
Harald Welte3c6ebb92017-09-16 00:56:57 +0800292
293 log(ts_CRCX("23", "42@mgw", "sendrecv", '1234'H));
294 log(enc_MgcpCommand(valueof(ts_CRCX("23", "42@mgw", "sendrecv", '1234'H))));
295
296 log(c_crcx510_ret);
297 log(dec_MgcpResponse(c_crcx510_ret));
298 log(dec_MgcpMessage(c_crcx510_ret));
299 }
300
Harald Weltee636afd2017-09-17 16:24:09 +0800301 /* CRCX test ideas:
302 * - without mandatory CallId
303 * - without mandatory ConnectionId
304 * - with forbidden parameters (e.g. Capabilities, PackageList, ...
305 * - CRCX with remote session description and without
306 *
307 * general ideas:
308 * - packetization != 20ms
309 * - invalid mode
310 * x unsupported mode (517)
311 * x bidirectional mode before RemoteConnDesc: 527
312 * - invalid codec
313 * - retransmission of same transaction
314 * - unsupported LocalConnectionOptions ("b", "a", "e", "gc", "s", "r", "k", ..)
315 */
316
Harald Welte21ba5572017-09-19 17:55:05 +0800317 /* build a receive template for receiving a MGCP message. You
318 * pass the MGCP response template in, and it will generate an
319 * MGCP_RecvFrom template that can match the primitives arriving on the
320 * MGCP_CodecPort */
Harald Weltee636afd2017-09-17 16:24:09 +0800321 function tr_MGCP_RecvFrom_R(template MgcpResponse resp) runs on dummy_CT return template MGCP_RecvFrom {
322 var template MGCP_RecvFrom mrf := {
Harald Welte55015362017-11-18 16:02:42 +0100323 connId := g_mgcp_conn_id,
Harald Weltee636afd2017-09-17 16:24:09 +0800324 remName := mp_remote_ip,
325 remPort := mp_remote_udp_port,
326 locName := mp_local_ip,
327 locPort := mp_local_udp_port,
328 msg := { response := resp }
329 }
330 return mrf;
331 }
332
333 /* Send a MGCP request + receive a (matching!) response */
334 function mgcp_transceive_mgw(template MgcpCommand cmd, template MgcpResponse resp := ?) runs on dummy_CT return MgcpResponse {
335 var MgcpMessage msg := { command := valueof(cmd) };
336 resp.line.trans_id := cmd.line.trans_id;
337 var template MGCP_RecvFrom mrt := tr_MGCP_RecvFrom_R(resp);
Harald Welte3c6ebb92017-09-16 00:56:57 +0800338 var MGCP_RecvFrom mrf;
339 timer T := 5.0;
340
Harald Welte55015362017-11-18 16:02:42 +0100341 MGCP.send(t_MGCP_Send(g_mgcp_conn_id, msg));
Harald Welte3c6ebb92017-09-16 00:56:57 +0800342 T.start;
343 alt {
Harald Weltee636afd2017-09-17 16:24:09 +0800344 [] MGCP.receive(mrt) -> value mrf { }
345 [] MGCP.receive(tr_MGCP_RecvFrom_R(?)) { setverdict(fail); }
Harald Welte3c6ebb92017-09-16 00:56:57 +0800346 [] MGCP.receive { repeat; }
347 [] T.timeout { setverdict(fail); }
348 }
349 T.stop;
Harald Weltee636afd2017-09-17 16:24:09 +0800350
351 if (isbound(mrf) and isbound(mrf.msg) and ischosen(mrf.msg.response)) {
352 return mrf.msg.response;
353 } else {
354 var MgcpResponse r := { line := { code := "999", trans_id := valueof(cmd.line.trans_id) } };
355 return r;
356 }
Harald Welte00a067f2017-09-13 23:27:17 +0200357 }
358
Harald Welteba62c8c2017-11-18 18:26:49 +0100359 function extract_conn_id(MgcpResponse resp) return MgcpConnectionId {
360 var integer i;
361 for (i := 0; i < lengthof(resp.params); i := i + 1) {
362 var MgcpParameter par := resp.params[i];
363 if (par.code == "I") {
364 return str2hex(par.val);
365 }
366 }
367 setverdict(fail);
368 return '00000000'H;
369 }
370
Harald Welte10889c12017-11-18 19:40:31 +0100371 function f_dlcx(MgcpEndpoint ep, template MgcpResponseCode ret_code, template charstring ret_val,
372 template MgcpCallId call_id := omit,
373 template MgcpConnectionId conn_id := omit) runs on dummy_CT {
Harald Welteba62c8c2017-11-18 18:26:49 +0100374 var template MgcpCommand cmd;
375 var MgcpResponse resp;
376 var template MgcpResponse rtmpl := {
377 line := {
Harald Welte10889c12017-11-18 19:40:31 +0100378 code := ret_code,
379 string := ret_val
Harald Welteba62c8c2017-11-18 18:26:49 +0100380 },
381 params := *,
382 sdp := *
383 };
Harald Weltec40e0c32017-11-18 19:08:22 +0100384 cmd := ts_DLCX(get_next_trans_id(), ep, call_id, conn_id);
Harald Welteba62c8c2017-11-18 18:26:49 +0100385 resp := mgcp_transceive_mgw(cmd, rtmpl);
386 }
387
Harald Welte10889c12017-11-18 19:40:31 +0100388 /* Send DLCX and expect OK response */
389 function f_dlcx_ok(MgcpEndpoint ep, template MgcpCallId call_id := omit,
390 template MgcpConnectionId conn_id := omit) runs on dummy_CT {
391 f_dlcx(ep, "200", "OK", call_id, conn_id);
392 }
393
Harald Welteba62c8c2017-11-18 18:26:49 +0100394 /* Send DLCX and accept any response */
Harald Weltec40e0c32017-11-18 19:08:22 +0100395 function f_dlcx_ignore(MgcpEndpoint ep, template MgcpCallId call_id := omit,
Harald Welteba62c8c2017-11-18 18:26:49 +0100396 template MgcpConnectionId conn_id := omit) runs on dummy_CT {
Harald Welte10889c12017-11-18 19:40:31 +0100397 f_dlcx(ep, ?, *, call_id, conn_id);
Harald Welteba62c8c2017-11-18 18:26:49 +0100398 }
399
Harald Weltee636afd2017-09-17 16:24:09 +0800400 /* test valid CRCX without SDP */
401 testcase TC_crcx() runs on dummy_CT {
402 var template MgcpCommand cmd;
403 var MgcpResponse resp;
Harald Welteba62c8c2017-11-18 18:26:49 +0100404 var MgcpEndpoint ep := "2@mgw";
405 var MgcpCallId call_id := '1234'H;
Harald Weltee636afd2017-09-17 16:24:09 +0800406
Harald Welteedc45c12017-11-18 19:15:05 +0100407 f_init(ep);
Harald Weltee636afd2017-09-17 16:24:09 +0800408
Harald Welteba62c8c2017-11-18 18:26:49 +0100409 /* create the connection on the MGW */
410 cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id);
Harald Welte9988d282017-11-18 19:22:00 +0100411 resp := mgcp_transceive_mgw(cmd, tr_CRCX_ACK);
Harald Welteba62c8c2017-11-18 18:26:49 +0100412 extract_conn_id(resp);
413
414 /* clean-up */
415 f_dlcx_ok(ep, call_id);
416
Harald Weltee636afd2017-09-17 16:24:09 +0800417 setverdict(pass);
418 }
419
420 /* test CRCX with unsupported mode, expect 517 */
421 testcase TC_crcx_unsupp_mode() runs on dummy_CT {
422 var template MgcpCommand cmd;
423 var MgcpResponse resp;
Harald Welteba62c8c2017-11-18 18:26:49 +0100424 var MgcpEndpoint ep := "2@mgw";
425 var MgcpCallId call_id := '1233'H;
Harald Weltee636afd2017-09-17 16:24:09 +0800426 var template MgcpResponse rtmpl := tr_MgcpResp_Err("517");
427
Harald Welteedc45c12017-11-18 19:15:05 +0100428 f_init(ep);
Harald Weltee636afd2017-09-17 16:24:09 +0800429
Harald Welteba62c8c2017-11-18 18:26:49 +0100430 cmd := ts_CRCX(get_next_trans_id(), ep, "netwtest", call_id);
Harald Weltee636afd2017-09-17 16:24:09 +0800431 resp := mgcp_transceive_mgw(cmd, rtmpl);
432 setverdict(pass);
433 }
434
Harald Welte21ba5572017-09-19 17:55:05 +0800435 /* test CRCX with early bi-directional mode, expect 527 as
436 * bi-diretional media can only be established once both local and
437 * remote side are specified, see MGCP RFC */
Harald Weltee636afd2017-09-17 16:24:09 +0800438 testcase TC_crcx_early_bidir_mode() runs on dummy_CT {
439 var template MgcpCommand cmd;
440 var MgcpResponse resp;
Harald Welteba62c8c2017-11-18 18:26:49 +0100441 var MgcpEndpoint ep := "2@mgw";
442 var MgcpCallId call_id := '1232'H;
Harald Weltee636afd2017-09-17 16:24:09 +0800443 var template MgcpResponse rtmpl := tr_MgcpResp_Err("527");
444
Harald Welteedc45c12017-11-18 19:15:05 +0100445 f_init(ep);
Harald Weltee636afd2017-09-17 16:24:09 +0800446
Harald Welteba62c8c2017-11-18 18:26:49 +0100447 cmd := ts_CRCX(get_next_trans_id(), ep, "sendrecv", call_id);
Harald Weltee636afd2017-09-17 16:24:09 +0800448 resp := mgcp_transceive_mgw(cmd, rtmpl);
449 setverdict(pass);
450 }
451
Harald Weltea01e38d2017-11-18 18:40:01 +0100452 function f_mgcp_par_append(inout template MgcpParameterList list, template MgcpParameter par) {
453 var integer len := lengthof(list);
454 list[len] := par;
455 }
456
Harald Weltee636afd2017-09-17 16:24:09 +0800457 /* test CRCX with unsupported Parameters */
458 testcase TC_crcx_unsupp_param() runs on dummy_CT {
459 var template MgcpCommand cmd;
460 var MgcpResponse resp;
Harald Welteba62c8c2017-11-18 18:26:49 +0100461 var MgcpEndpoint ep := "2@mgw";
462 var MgcpCallId call_id := '1231'H;
Harald Weltee636afd2017-09-17 16:24:09 +0800463 var template MgcpResponse rtmpl := tr_MgcpResp_Err("539");
464
Harald Welteedc45c12017-11-18 19:15:05 +0100465 f_init(ep);
Harald Weltee636afd2017-09-17 16:24:09 +0800466
Harald Welteba62c8c2017-11-18 18:26:49 +0100467 cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id);
Harald Weltea01e38d2017-11-18 18:40:01 +0100468 /* osmo-bsc_mgcp/mgw doesn't implement notifications */
469 f_mgcp_par_append(cmd.params, MgcpParameter:{ "N", "foobar" });
470
Harald Weltee636afd2017-09-17 16:24:09 +0800471 resp := mgcp_transceive_mgw(cmd, rtmpl);
472 setverdict(pass);
473 }
474
475 /* test CRCX with missing CallId */
476 testcase TC_crcx_missing_callid() runs on dummy_CT {
477 var template MgcpCommand cmd;
478 var MgcpResponse resp;
Harald Welteba62c8c2017-11-18 18:26:49 +0100479 var MgcpEndpoint ep := "2@mgw";
Harald Weltee636afd2017-09-17 16:24:09 +0800480 var template MgcpResponse rtmpl := tr_MgcpResp_Err("400");
481
Harald Welteedc45c12017-11-18 19:15:05 +0100482 f_init(ep);
Harald Weltee636afd2017-09-17 16:24:09 +0800483
Harald Welteba62c8c2017-11-18 18:26:49 +0100484 cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", '1230'H);
Harald Weltee636afd2017-09-17 16:24:09 +0800485 cmd.params := {
486 t_MgcpParConnMode("recvonly"),
487 t_MgcpParLocConnOpt("p:20")
488 }
489 resp := mgcp_transceive_mgw(cmd, rtmpl);
490 setverdict(pass);
Harald Welteba62c8c2017-11-18 18:26:49 +0100491
Harald Weltee636afd2017-09-17 16:24:09 +0800492 }
493
494 /* test CRCX with missing Mode */
495 testcase TC_crcx_missing_mode() runs on dummy_CT {
496 var template MgcpCommand cmd;
497 var MgcpResponse resp;
Harald Welteba62c8c2017-11-18 18:26:49 +0100498 var MgcpEndpoint ep := "2@mgw";
499 var MgcpCallId call_id := '1229'H;
Harald Weltee636afd2017-09-17 16:24:09 +0800500 var template MgcpResponse rtmpl := tr_MgcpResp_Err("400");
501
Harald Welteedc45c12017-11-18 19:15:05 +0100502 f_init(ep);
Harald Weltee636afd2017-09-17 16:24:09 +0800503
Harald Welteba62c8c2017-11-18 18:26:49 +0100504 cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id);
Harald Weltee636afd2017-09-17 16:24:09 +0800505 cmd.params := {
Harald Welteba62c8c2017-11-18 18:26:49 +0100506 ts_MgcpParCallId(call_id),
Harald Weltee636afd2017-09-17 16:24:09 +0800507 t_MgcpParLocConnOpt("p:20")
508 }
509 resp := mgcp_transceive_mgw(cmd, rtmpl);
510 setverdict(pass);
511 }
512
513 /* test CRCX with unsupported packetization interval */
514 testcase TC_crcx_unsupp_packet_intv() runs on dummy_CT {
515 var template MgcpCommand cmd;
516 var MgcpResponse resp;
Harald Welteba62c8c2017-11-18 18:26:49 +0100517 var MgcpEndpoint ep := "2@mgw";
518 var MgcpCallId call_id := '1228'H;
Harald Weltee636afd2017-09-17 16:24:09 +0800519 var template MgcpResponse rtmpl := tr_MgcpResp_Err("532");
520
Harald Welteedc45c12017-11-18 19:15:05 +0100521 f_init(ep);
Harald Weltee636afd2017-09-17 16:24:09 +0800522
Harald Welteba62c8c2017-11-18 18:26:49 +0100523 cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id);
Harald Weltea01e38d2017-11-18 18:40:01 +0100524 cmd.params[2] := t_MgcpParLocConnOpt("p:111");
Harald Weltee636afd2017-09-17 16:24:09 +0800525 resp := mgcp_transceive_mgw(cmd, rtmpl);
526 setverdict(pass);
527 }
528
529 /* test CRCX with illegal double presence of local connection option */
530 testcase TC_crcx_illegal_double_lco() runs on dummy_CT {
531 var template MgcpCommand cmd;
532 var MgcpResponse resp;
Harald Welteba62c8c2017-11-18 18:26:49 +0100533 var MgcpEndpoint ep := "2@mgw";
534 var MgcpCallId call_id := '1227'H;
Harald Weltee636afd2017-09-17 16:24:09 +0800535 var template MgcpResponse rtmpl := tr_MgcpResp_Err("524");
536
Harald Welteedc45c12017-11-18 19:15:05 +0100537 f_init(ep);
Harald Weltee636afd2017-09-17 16:24:09 +0800538
Harald Welteba62c8c2017-11-18 18:26:49 +0100539 cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id);
Harald Weltea01e38d2017-11-18 18:40:01 +0100540 /* p:20 is permitted only once and not twice! */
541 cmd.params[2] := t_MgcpParLocConnOpt("p:20, a:AMR, p:20");
Harald Weltee636afd2017-09-17 16:24:09 +0800542 resp := mgcp_transceive_mgw(cmd, rtmpl);
543 setverdict(pass);
544 }
545
546 /* test valid CRCX with valid SDP */
547 testcase TC_crcx_sdp() runs on dummy_CT {
548 var template MgcpCommand cmd;
549 var MgcpResponse resp;
Harald Welteba62c8c2017-11-18 18:26:49 +0100550 var MgcpEndpoint ep := "2@mgw";
551 var MgcpCallId call_id := '1226'H;
Harald Weltee636afd2017-09-17 16:24:09 +0800552
Harald Welteedc45c12017-11-18 19:15:05 +0100553 f_init(ep);
Harald Weltee636afd2017-09-17 16:24:09 +0800554
Harald Welteba62c8c2017-11-18 18:26:49 +0100555 cmd := ts_CRCX(get_next_trans_id(), ep, "sendrecv", call_id);
Harald Weltee636afd2017-09-17 16:24:09 +0800556 cmd.sdp := ts_SDP("127.0.0.1", "127.0.0.2", "23", "42", 2344, { "98" },
557 { valueof(ts_SDP_rtpmap(98, "AMR/8000")),
558 valueof(ts_SDP_ptime(20)) });
Harald Welte9988d282017-11-18 19:22:00 +0100559 resp := mgcp_transceive_mgw(cmd, tr_CRCX_ACK);
Harald Weltee636afd2017-09-17 16:24:09 +0800560 setverdict(pass);
561 }
562
563 /* TODO: various SDP related bits */
564
565
566 /* TODO: CRCX with X-Osmux */
567 /* TODO: double CRCX without force_realloc */
568
569 /* TODO: MDCX (various) */
570
571 /* TODO: MDCX without CRCX first */
572 testcase TC_mdcx_without_crcx() runs on dummy_CT {
573 var template MgcpCommand cmd;
574 var MgcpResponse resp;
Harald Welteba62c8c2017-11-18 18:26:49 +0100575 var MgcpEndpoint ep := "3@mgw";
576 var MgcpCallId call_id := '1225'H;
Harald Weltee636afd2017-09-17 16:24:09 +0800577 var template MgcpResponse rtmpl := {
578 line := {
579 /* TODO: accept/enforce better error? */
580 code := "400",
581 string := ?
582 },
583 params:= { },
584 sdp := omit
585 };
586
Harald Welteedc45c12017-11-18 19:15:05 +0100587 f_init(ep);
Harald Weltee636afd2017-09-17 16:24:09 +0800588
Harald Welteba62c8c2017-11-18 18:26:49 +0100589 cmd := ts_MDCX(get_next_trans_id(), ep, "sendrecv", call_id);
Harald Weltee636afd2017-09-17 16:24:09 +0800590 cmd.sdp := ts_SDP("127.0.0.1", "127.0.0.2", "23", "42", 2344, { "98" },
591 { valueof(ts_SDP_rtpmap(98, "AMR/8000")),
592 valueof(ts_SDP_ptime(20)) });
593 resp := mgcp_transceive_mgw(cmd, rtmpl);
594 setverdict(pass);
595 }
596
597 /* DLCX without CRCX first */
598 testcase TC_dlcx_without_crcx() runs on dummy_CT {
599 var template MgcpCommand cmd;
600 var MgcpResponse resp;
Harald Welteedc45c12017-11-18 19:15:05 +0100601 var MgcpEndpoint ep := "4@mgw";
Harald Weltee636afd2017-09-17 16:24:09 +0800602 var template MgcpResponse rtmpl := {
603 line := {
604 /* TODO: accept/enforce better error? */
605 code := "400",
606 string := ?
607 },
608 params:= { },
609 sdp := omit
610 };
611
Harald Welteedc45c12017-11-18 19:15:05 +0100612 f_init(ep);
Harald Weltee636afd2017-09-17 16:24:09 +0800613
Harald Welteedc45c12017-11-18 19:15:05 +0100614 cmd := ts_DLCX(get_next_trans_id(), ep, '41234'H);
Harald Weltee636afd2017-09-17 16:24:09 +0800615 resp := mgcp_transceive_mgw(cmd, rtmpl);
616 setverdict(pass);
617 }
618
Harald Welte79181ff2017-11-18 19:26:11 +0100619 /* Test (valid) CRCX followed by (valid) DLCX containig EP+CallId+ConnId */
620 testcase TC_crcx_and_dlcx_ep_callid_connid() runs on dummy_CT {
621 var template MgcpCommand cmd;
622 var MgcpResponse resp;
623 var MgcpEndpoint ep := "5@mgw";
624 var MgcpCallId call_id := '51234'H;
625
626 f_init(ep);
627
628 cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id);
629 resp := mgcp_transceive_mgw(cmd, tr_CRCX_ACK);
630
631 f_dlcx_ok(ep, call_id, extract_conn_id(resp));
632
633 setverdict(pass);
634 }
635
636 /* Test (valid) CRCX followed by (valid) DLCX containing EP+CallId */
637 testcase TC_crcx_and_dlcx_ep_callid() runs on dummy_CT {
Harald Welte5b4c44e2017-09-17 16:35:27 +0800638 var template MgcpCommand cmd;
639 var MgcpResponse resp;
Harald Welteba62c8c2017-11-18 18:26:49 +0100640 var MgcpEndpoint ep := "5@mgw";
641 var MgcpCallId call_id := '51234'H;
Harald Welte5b4c44e2017-09-17 16:35:27 +0800642
Harald Welteedc45c12017-11-18 19:15:05 +0100643 f_init(ep);
Harald Welte5b4c44e2017-09-17 16:35:27 +0800644
Harald Welteba62c8c2017-11-18 18:26:49 +0100645 cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id);
Harald Welte9988d282017-11-18 19:22:00 +0100646 resp := mgcp_transceive_mgw(cmd, tr_CRCX_ACK);
Harald Welte5b4c44e2017-09-17 16:35:27 +0800647
Harald Welteba62c8c2017-11-18 18:26:49 +0100648 f_dlcx_ok(ep, call_id);
Harald Welte5b4c44e2017-09-17 16:35:27 +0800649
650 setverdict(pass);
651 }
652
Harald Welte79181ff2017-11-18 19:26:11 +0100653 /* Test (valid) CRCX followed by (valid) DLCX containing EP */
654 testcase TC_crcx_and_dlcx_ep() runs on dummy_CT {
655 var template MgcpCommand cmd;
656 var MgcpResponse resp;
657 var MgcpEndpoint ep := "5@mgw";
658 var MgcpCallId call_id := '51234'H;
659
660 f_init(ep);
661
662 cmd := ts_CRCX(get_next_trans_id(), ep, "recvonly", call_id);
663 resp := mgcp_transceive_mgw(cmd, tr_CRCX_ACK);
664
665 f_dlcx_ok(ep);
666
667 setverdict(pass);
668 }
669
670
Harald Weltee636afd2017-09-17 16:24:09 +0800671 /* TODO: DLCX of valid endpoint but invalid call-id */
672 /* TODO: Double-DLCX (retransmission) */
673 /* TODO: Double-DLCX (no retransmission) */
674
675
676
677 /* TODO: AUEP (various) */
678 /* TODO: RSIP (various) */
679 /* TODO: RQNT (various) */
680 /* TODO: EPCF (various) */
681 /* TODO: AUCX (various) */
682 /* TODO: invalid verb (various) */
683
Harald Welte00a067f2017-09-13 23:27:17 +0200684 control {
685 execute(TC_selftest());
Harald Welte3c6ebb92017-09-16 00:56:57 +0800686 execute(TC_crcx());
Harald Weltee636afd2017-09-17 16:24:09 +0800687 execute(TC_crcx_unsupp_mode());
688 execute(TC_crcx_early_bidir_mode());
689 execute(TC_crcx_unsupp_param());
690 execute(TC_crcx_missing_callid());
691 execute(TC_crcx_missing_mode());
692 execute(TC_crcx_unsupp_packet_intv());
693 execute(TC_crcx_illegal_double_lco());
694 execute(TC_crcx_sdp());
695 execute(TC_mdcx_without_crcx());
696 execute(TC_dlcx_without_crcx());
Harald Welte79181ff2017-11-18 19:26:11 +0100697 execute(TC_crcx_and_dlcx_ep_callid_connid());
698 execute(TC_crcx_and_dlcx_ep_callid());
699 execute(TC_crcx_and_dlcx_ep());
Harald Welte00a067f2017-09-13 23:27:17 +0200700 }
701}