blob: dd8d25b7a476dafe7a6a222f2e6ab349a3e9a3d6 [file] [log] [blame]
Harald Welte00a067f2017-09-13 23:27:17 +02001module MGCP_Test {
2 import from MGCP_Types all;
Harald Welte3c6ebb92017-09-16 00:56:57 +08003 import from SDP_Types all;
4 import from MGCP_CodecPort all;
5 import from MGCP_CodecPort_CtrlFunct all;
6 import from IPL4asp_Types all;
Harald Welte00a067f2017-09-13 23:27:17 +02007
8 type component dummy_CT {
Harald Welte3c6ebb92017-09-16 00:56:57 +08009 port MGCP_CODEC_PT MGCP;
10 var boolean initialized := false;
11 var ConnectionId g_conn_id := -1;
Harald Welte00a067f2017-09-13 23:27:17 +020012 };
13
Harald Welte3c6ebb92017-09-16 00:56:57 +080014 modulepar {
15 PortNumber mp_local_udp_port := 2727;
16 charstring mp_local_ip := "127.0.0.1";
17 PortNumber mp_remote_udp_port := 2427;
18 charstring mp_remote_ip := "127.0.0.1";
19 }
20
21 private function f_init()runs on dummy_CT {
22 var Result res;
23 if (initialized == true) {
24 return;
25 }
26 initialized := true;
27
28 map(self:MGCP, system:MGCP_CODEC_PT);
29 res := f_IPL4_connect(MGCP, mp_remote_ip, mp_remote_udp_port, mp_local_ip, mp_local_udp_port, 0, { udp := {} });
30 g_conn_id := res.connId;
31 }
32
33 /* 3.2.2.6 Connection Mode (sendonly, recvonly, sendrecv, confrnce, inactive, loopback,
34 * conttest, netwloop, netwtest) */
35 template MgcpParameter t_MgcpParConnMode(template MgcpConnectionMode mode) := { "M", mode };
36
37 /* 3.2.2.2 CallId: maximum 32 hex chars */
38 template MgcpParameter ts_MgcpParCallId(MgcpCallId cid) := {
39 code := "C",
40 val := hex2str(cid)
41 };
42
43 /* 3.2.2.18 RequestIdentifier: Maximum 32 hex chars */
44 template MgcpParameter ts_MgcpParReqId(MgcpRequestId rid) := {
45 code := "X",
46 val := hex2str(rid)
47 };
48
49 /* 3.2.2.10: LocalConnectionOptions (codec, packetization, bandwidth, ToS, eco, gain, silence, ...) */
50 template MgcpParameter t_MgcpParLocConnOpt(template charstring lco) := { "L", lco };
51
52 /* 3.2.2.5: ConnectionId: maximum 32 hex chars */
53 template MgcpParameter ts_MgcpParConnectionId(MgcpConnectionId cid) := {
54 code := "I",
55 val := hex2str(cid)
56 };
57
58 /* osmo-bsc_mgcp implements L/C/M/X only, osmo-mgw adds 'I' */
59 /* SDP: osmo-bsc_mgcp implements Tx of v,o,s,c,t,m,a */
60
61 template MgcpCommandLine t_MgcpCmdLine(template charstring verb, template MgcpTransId trans_id, template charstring ep) := {
62 verb := verb,
63 trans_id := trans_id,
64 ep := ep,
65 ver := "1.0"
66 };
67
68 template MgcpCommand ts_CRCX(MgcpTransId trans_id, charstring ep, MgcpConnectionMode mode, MgcpCallId call_id, template SDP_Message sdp := omit) := {
69 line := t_MgcpCmdLine("CRCX", trans_id, ep),
70 params := {
71 t_MgcpParConnMode(mode),
72 ts_MgcpParCallId(call_id),
73 //t_MgcpParReqId(omit),
74 t_MgcpParLocConnOpt("p: 20")
75 },
76 sdp := sdp
77 }
78
Harald Welte00a067f2017-09-13 23:27:17 +020079 testcase TC_selftest() runs on dummy_CT {
80 const charstring c_auep := "AUEP 158663169 ds/e1-1/2@172.16.6.66 MGCP 1.0\r\n";
81 const charstring c_mdcx3 := "MDCX 18983215 1@mgw MGCP 1.0\r\n";
82 const charstring c_mdcx3_ret := "200 18983215 OK\r\n" &
83 "I: 1\n" &
84 "\n" &
85 "v=0\r\n" &
86 "o=- 1 23 IN IP4 0.0.0.0\r\n" &
87 "s=-\r\n" &
88 "c=IN IP4 0.0.0.0\r\n" &
89 "t=0 0\r\n" &
90 "m=audio 0 RTP/AVP 126\r\n" &
91 "a=rtpmap:126 AMR/8000\r\n" &
92 "a=ptime:20\r\n";
93 const charstring c_mdcx4 := "MDCX 18983216 1@mgw MGCP 1.0\r\n" &
94 "M: sendrecv\r" &
95 "C: 2\r\n" &
96 "I: 1\r\n" &
97 "L: p:20, a:AMR, nt:IN\r\n" &
98 "\n" &
99 "v=0\r\n" &
100 "o=- 1 23 IN IP4 0.0.0.0\r\n" &
Harald Welte2871d0b2017-09-14 22:42:12 +0800101 "s=-\r\n" &
Harald Welte00a067f2017-09-13 23:27:17 +0200102 "c=IN IP4 0.0.0.0\r\n" &
103 "t=0 0\r\n" &
104 "m=audio 4441 RTP/AVP 99\r\n" &
105 "a=rtpmap:99 AMR/8000\r\n" &
106 "a=ptime:40\r\n";
Harald Welte3c6ebb92017-09-16 00:56:57 +0800107 const charstring c_crcx510_ret := "510 23 FAIL\r\n"
Harald Welte00a067f2017-09-13 23:27:17 +0200108
109 log(c_auep);
110 log(dec_MgcpCommand(c_auep));
111
112 log(c_mdcx3);
113 log(dec_MgcpCommand(c_mdcx3));
114
115 log(c_mdcx3_ret);
116 log(dec_MgcpResponse(c_mdcx3_ret));
117
118 log(c_mdcx4);
119 log(dec_MgcpCommand(c_mdcx4));
Harald Welte3c6ebb92017-09-16 00:56:57 +0800120
121 log(ts_CRCX("23", "42@mgw", "sendrecv", '1234'H));
122 log(enc_MgcpCommand(valueof(ts_CRCX("23", "42@mgw", "sendrecv", '1234'H))));
123
124 log(c_crcx510_ret);
125 log(dec_MgcpResponse(c_crcx510_ret));
126 log(dec_MgcpMessage(c_crcx510_ret));
127 }
128
129 testcase TC_crcx() runs on dummy_CT {
130 var MGCP_RecvFrom mrf;
131 timer T := 5.0;
132
133 f_init();
134
135 var MgcpMessage msg := { command := valueof(ts_CRCX("23", "42@mgw", "sendrecv", '1234'H)) };
136 MGCP.send(t_MGCP_Send(g_conn_id, msg));
137 T.start;
138 alt {
139 [] MGCP.receive(MGCP_RecvFrom:?) -> value mrf { log(mrf); }
140 [] MGCP.receive { repeat; }
141 [] T.timeout { setverdict(fail); }
142 }
143 T.stop;
Harald Welte00a067f2017-09-13 23:27:17 +0200144 }
145
146 control {
147 execute(TC_selftest());
Harald Welte3c6ebb92017-09-16 00:56:57 +0800148 execute(TC_crcx());
Harald Welte00a067f2017-09-13 23:27:17 +0200149 }
150}