blob: 478c688cc8b930042dfa2af9703fa2b394de3c59 [file] [log] [blame]
Harald Weltef09d1ba2017-11-25 02:20:13 +01001module MGCP_Adapter {
2
Harald Welte34b5a952019-05-27 11:54:11 +02003/* MGCP Adapter for bsc-nat tests in TTCN-3
4 * (C) 2017 Harald Welte <laforge@gnumonks.org>
5 * All rights reserved.
6 *
7 * Released under the terms of GNU General Public License, Version 2 or
8 * (at your option) any later version.
9 *
10 * SPDX-License-Identifier: GPL-2.0-or-later
11 */
12
Harald Weltef09d1ba2017-11-25 02:20:13 +010013import from IPL4asp_Types all;
14
15import from MGCP_Types all;
16import from MGCP_CodecPort all;
17import from MGCP_CodecPort_CtrlFunct all;
18
19import from IPA_Emulation all;
20
21
22type component MGCP_Adapter_CT {
23 /* MGCP Codec Port for MGCP-over-UDP */
24 port MGCP_CODEC_PT MGCP_UDP;
25 port IPA_MGCP_PT MGCP;
26 var integer g_mgcp_conn_id := -1;
27}
28
29modulepar {
30 charstring mp_callagent_ip := "127.0.0.1";
31 PortNumber mp_callagent_udp_port := 2727;
32 charstring mp_mgw_ip := "127.0.0.1";
33 PortNumber mp_mgw_udp_port := 2427;
34}
35
36/* build a receive template for receiving a MGCP message. You
37 * pass the MGCP response template in, and it will generate an
38 * MGCP_RecvFrom template that can match the primitives arriving on the
39 * MGCP_CodecPort */
40function tr_MGCP_RecvFrom_R(template MgcpResponse resp)
41runs on MGCP_Adapter_CT return template MGCP_RecvFrom {
42 var template MGCP_RecvFrom mrf := {
43 connId := g_mgcp_conn_id,
44 remName := mp_mgw_ip,
45 remPort := mp_mgw_udp_port,
46 locName := mp_callagent_ip,
47 locPort := mp_callagent_udp_port,
48 msg := { response := resp }
49 }
50 return mrf;
51}
52
53
54function main() runs on MGCP_Adapter_CT {
55 var Result res;
56 map(self:MGCP_UDP, system:MGCP_CODEC_PT);
57 res := MGCP_CodecPort_CtrlFunct.f_IPL4_connect(MGCP_UDP, mp_mgw_ip, mp_mgw_udp_port,
58 mp_callagent_ip, mp_callagent_udp_port,
59 0, { udp:={} });
Harald Welte9220f632018-05-23 20:27:02 +020060 if (not ispresent(res.connId)) {
61 setverdict(fail, "Could not connect MGCP, check your configuration");
62 self.stop;
63 }
Harald Weltef09d1ba2017-11-25 02:20:13 +010064 g_mgcp_conn_id := res.connId;
65
66 while (true) {
67 var MgcpCommand mgcp_cmd;
68 var MGCP_RecvFrom mrf;
69
70 alt {
71 /* From BSC/MGW via UDP up to MSC / Call Agent */
72 [] MGCP_UDP.receive(tr_MGCP_RecvFrom_R(?)) -> value mrf {
73 MGCP.send(mrf.msg.response);
74 }
75
76 /* From MSC / Call Agent down to BSC/MGW */
77 [] MGCP.receive(MgcpCommand:?) -> value mgcp_cmd {
78 var MgcpMessage msg := { command := mgcp_cmd };
79 MGCP_UDP.send(t_MGCP_Send(g_mgcp_conn_id, msg));
80 }
81
82 }
83 }
84}
85
86}